Skip to content

Commit 6a85650

Browse files
committed
[ConstraintSystem] Don't attempt to rollback state and scope from incorrect state
1 parent f83c719 commit 6a85650

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

Diff for: lib/Sema/CSSolver.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,11 @@ ConstraintSystem::SolverState::~SolverState() {
422422
"Expected constraint system to have this solver state!");
423423
CS.solverState = nullptr;
424424

425+
// If constraint system ended up being in an invalid state
426+
// let's just drop the state without attempting to rollback.
427+
if (CS.inInvalidState())
428+
return;
429+
425430
// Make sure that all of the retired constraints have been returned
426431
// to constraint system.
427432
assert(!hasRetiredConstraints());
@@ -513,6 +518,10 @@ ConstraintSystem::SolverScope::SolverScope(ConstraintSystem &cs)
513518
}
514519

515520
ConstraintSystem::SolverScope::~SolverScope() {
521+
// Don't attempt to rollback from an incorrect state.
522+
if (cs.inInvalidState())
523+
return;
524+
516525
// Erase the end of various lists.
517526
while (cs.TypeVariables.size() > numTypeVariables)
518527
cs.TypeVariables.pop_back();

Diff for: lib/Sema/ConstraintGraph.cpp

+13-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,14 @@ using namespace constraints;
3737
ConstraintGraph::ConstraintGraph(ConstraintSystem &cs) : CS(cs) { }
3838

3939
ConstraintGraph::~ConstraintGraph() {
40-
assert(Changes.empty() && "Scope stack corrupted");
40+
#ifndef NDEBUG
41+
// If constraint system is in an invalid state, it's
42+
// possible that constraint graph is corrupted as well
43+
// so let's not attempt to check change log.
44+
if (!CS.inInvalidState())
45+
assert(Changes.empty() && "Scope stack corrupted");
46+
#endif
47+
4148
for (unsigned i = 0, n = TypeVariables.size(); i != n; ++i) {
4249
auto &impl = TypeVariables[i]->getImpl();
4350
delete impl.getGraphNode();
@@ -412,6 +419,11 @@ ConstraintGraphScope::ConstraintGraphScope(ConstraintGraph &CG)
412419
}
413420

414421
ConstraintGraphScope::~ConstraintGraphScope() {
422+
// Don't attempt to rollback if constraint system ended up
423+
// in an invalid state.
424+
if (CG.CS.inInvalidState())
425+
return;
426+
415427
// Pop changes off the stack until we hit the change could we had prior to
416428
// introducing this scope.
417429
assert(CG.Changes.size() >= NumChanges && "Scope stack corrupted");

0 commit comments

Comments
 (0)