@@ -79,9 +79,12 @@ ConstraintGraph::lookupNode(TypeVariableType *typeVar) {
79
79
// Record this type variable.
80
80
TypeVariables.push_back (typeVar);
81
81
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.
83
86
if (CS.solverState )
84
- CS.solverState -> recordChange (SolverTrail::Change::addedTypeVariable (typeVar));
87
+ CS.recordChange (SolverTrail::Change::addedTypeVariable (typeVar));
85
88
86
89
// If this type variable is not the representative of its equivalence class,
87
90
// add it to its representative's set of equivalences.
@@ -475,8 +478,8 @@ void ConstraintGraph::addConstraint(Constraint *constraint) {
475
478
}
476
479
477
480
// 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));
480
483
}
481
484
482
485
void ConstraintGraph::removeConstraint (Constraint *constraint) {
@@ -501,8 +504,8 @@ void ConstraintGraph::removeConstraint(Constraint *constraint) {
501
504
}
502
505
503
506
// 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));
506
509
}
507
510
508
511
void ConstraintGraph::mergeNodes (TypeVariableType *typeVar1,
@@ -520,8 +523,8 @@ void ConstraintGraph::mergeNodes(TypeVariableType *typeVar1,
520
523
auto typeVarNonRep = typeVar1 == typeVarRep? typeVar2 : typeVar1;
521
524
522
525
// Record the change, if there are active scopes.
523
- if (CS.solverState ) {
524
- CS.solverState -> recordChange (
526
+ if (CS.isRecordingChanges () ) {
527
+ CS.recordChange (
525
528
SolverTrail::Change::extendedEquivalenceClass (
526
529
typeVarRep,
527
530
repNode.getEquivalenceClass ().size ()));
@@ -536,12 +539,6 @@ void ConstraintGraph::bindTypeVariable(TypeVariableType *typeVar, Type fixed) {
536
539
assert (!fixed->is <TypeVariableType>() &&
537
540
" Cannot bind to type variable; merge equivalence classes instead" );
538
541
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
-
545
542
auto &node = (*this )[typeVar];
546
543
547
544
llvm::SmallPtrSet<TypeVariableType *, 4 > referencedVars;
@@ -556,6 +553,10 @@ void ConstraintGraph::bindTypeVariable(TypeVariableType *typeVar, Type fixed) {
556
553
otherNode.addReferencedBy (typeVar);
557
554
node.addReferencedVar (otherTypeVar);
558
555
}
556
+
557
+ // Record the change, if there are active scopes.
558
+ if (CS.isRecordingChanges ())
559
+ CS.recordChange (SolverTrail::Change::boundTypeVariable (typeVar, fixed));
559
560
}
560
561
561
562
void ConstraintGraph::unbindTypeVariable (TypeVariableType *typeVar, Type fixed) {
0 commit comments