@@ -79,9 +79,12 @@ ConstraintGraph::lookupNode(TypeVariableType *typeVar) {
7979 // Record this type variable.
8080 TypeVariables.push_back (typeVar);
8181
82- // Record the change, if there are active scopes.
82+ // Record the change, if there are active scopes. Note that we specifically
83+ // check CS.solverState and not CS.isRecordingChanges(), because we want
84+ // recordChange() to assert if there's an active undo. It is not valid to
85+ // create new nodes during an undo.
8386 if (CS.solverState )
84- CS.solverState -> recordChange (SolverTrail::Change::addedTypeVariable (typeVar));
87+ CS.recordChange (SolverTrail::Change::addedTypeVariable (typeVar));
8588
8689 // If this type variable is not the representative of its equivalence class,
8790 // add it to its representative's set of equivalences.
@@ -475,8 +478,8 @@ void ConstraintGraph::addConstraint(Constraint *constraint) {
475478 }
476479
477480 // Record the change, if there are active scopes.
478- if (CS.solverState )
479- CS.solverState -> recordChange (SolverTrail::Change::addedConstraint (constraint));
481+ if (CS.isRecordingChanges () )
482+ CS.recordChange (SolverTrail::Change::addedConstraint (constraint));
480483}
481484
482485void ConstraintGraph::removeConstraint (Constraint *constraint) {
@@ -501,8 +504,8 @@ void ConstraintGraph::removeConstraint(Constraint *constraint) {
501504 }
502505
503506 // Record the change, if there are active scopes.
504- if (CS.solverState )
505- CS.solverState -> recordChange (SolverTrail::Change::removedConstraint (constraint));
507+ if (CS.isRecordingChanges () )
508+ CS.recordChange (SolverTrail::Change::removedConstraint (constraint));
506509}
507510
508511void ConstraintGraph::mergeNodes (TypeVariableType *typeVar1,
@@ -520,8 +523,8 @@ void ConstraintGraph::mergeNodes(TypeVariableType *typeVar1,
520523 auto typeVarNonRep = typeVar1 == typeVarRep? typeVar2 : typeVar1;
521524
522525 // Record the change, if there are active scopes.
523- if (CS.solverState ) {
524- CS.solverState -> recordChange (
526+ if (CS.isRecordingChanges () ) {
527+ CS.recordChange (
525528 SolverTrail::Change::extendedEquivalenceClass (
526529 typeVarRep,
527530 repNode.getEquivalenceClass ().size ()));
@@ -536,12 +539,6 @@ void ConstraintGraph::bindTypeVariable(TypeVariableType *typeVar, Type fixed) {
536539 assert (!fixed->is <TypeVariableType>() &&
537540 " Cannot bind to type variable; merge equivalence classes instead" );
538541
539- // Record the change, if there are active scopes.
540- if (CS.solverState ) {
541- CS.solverState ->recordChange (
542- SolverTrail::Change::boundTypeVariable (typeVar, fixed));
543- }
544-
545542 auto &node = (*this )[typeVar];
546543
547544 llvm::SmallPtrSet<TypeVariableType *, 4 > referencedVars;
@@ -556,6 +553,10 @@ void ConstraintGraph::bindTypeVariable(TypeVariableType *typeVar, Type fixed) {
556553 otherNode.addReferencedBy (typeVar);
557554 node.addReferencedVar (otherTypeVar);
558555 }
556+
557+ // Record the change, if there are active scopes.
558+ if (CS.isRecordingChanges ())
559+ CS.recordChange (SolverTrail::Change::boundTypeVariable (typeVar, fixed));
559560}
560561
561562void ConstraintGraph::unbindTypeVariable (TypeVariableType *typeVar, Type fixed) {
0 commit comments