@@ -438,6 +438,16 @@ void ConstraintGraph::addConstraint(Constraint *constraint) {
438
438
CS.recordChange (SolverTrail::Change::addedConstraint (typeVar, constraint));
439
439
440
440
addConstraint (typeVar, constraint);
441
+
442
+ auto &node = (*this )[typeVar];
443
+
444
+ node.introduceToInference (constraint);
445
+
446
+ if (isUsefulForReferencedVars (constraint)) {
447
+ node.notifyReferencedVars ([&](ConstraintGraphNode &referencedVar) {
448
+ referencedVar.introduceToInference (constraint);
449
+ });
450
+ }
441
451
}
442
452
443
453
// If the constraint doesn't reference any type variables, it's orphaned;
@@ -454,20 +464,7 @@ void ConstraintGraph::addConstraint(Constraint *constraint) {
454
464
void ConstraintGraph::addConstraint (TypeVariableType *typeVar,
455
465
Constraint *constraint) {
456
466
if (typeVar) {
457
- // Find the node for this type variable.
458
- auto &node = (*this )[typeVar];
459
-
460
- // Note the constraint within the node for that type variable.
461
- node.addConstraint (constraint);
462
-
463
- node.introduceToInference (constraint);
464
-
465
- if (isUsefulForReferencedVars (constraint)) {
466
- node.notifyReferencedVars ([&](ConstraintGraphNode &referencedVar) {
467
- referencedVar.introduceToInference (constraint);
468
- });
469
- }
470
-
467
+ (*this )[typeVar].addConstraint (constraint);
471
468
return ;
472
469
}
473
470
@@ -480,6 +477,17 @@ void ConstraintGraph::removeConstraint(Constraint *constraint) {
480
477
// For the nodes corresponding to each type variable...
481
478
auto referencedTypeVars = constraint->getTypeVariables ();
482
479
for (auto typeVar : referencedTypeVars) {
480
+ // Find the node for this type variable.
481
+ auto &node = (*this )[typeVar];
482
+
483
+ node.retractFromInference (constraint);
484
+
485
+ if (isUsefulForReferencedVars (constraint)) {
486
+ node.notifyReferencedVars ([&](ConstraintGraphNode &referencedVar) {
487
+ referencedVar.retractFromInference (constraint);
488
+ });
489
+ }
490
+
483
491
// Record the change, if there are active scopes.
484
492
if (CS.isRecordingChanges ())
485
493
CS.recordChange (SolverTrail::Change::removedConstraint (typeVar, constraint));
@@ -500,20 +508,7 @@ void ConstraintGraph::removeConstraint(Constraint *constraint) {
500
508
void ConstraintGraph::removeConstraint (TypeVariableType *typeVar,
501
509
Constraint *constraint) {
502
510
if (typeVar) {
503
- // Find the node for this type variable.
504
- auto &node = (*this )[typeVar];
505
-
506
- node.retractFromInference (constraint);
507
-
508
- if (isUsefulForReferencedVars (constraint)) {
509
- node.notifyReferencedVars ([&](ConstraintGraphNode &referencedVar) {
510
- referencedVar.retractFromInference (constraint);
511
- });
512
- }
513
-
514
- // Remove the constraint.
515
- node.removeConstraint (constraint);
516
-
511
+ (*this )[typeVar].removeConstraint (constraint);
517
512
return ;
518
513
}
519
514
0 commit comments