File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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
515520ConstraintSystem::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 ();
Original file line number Diff line number Diff line change @@ -37,7 +37,14 @@ using namespace constraints;
3737ConstraintGraph::ConstraintGraph (ConstraintSystem &cs) : CS(cs) { }
3838
3939ConstraintGraph::~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
414421ConstraintGraphScope::~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" );
You can’t perform that action at this time.
0 commit comments