Skip to content

Commit c46ee87

Browse files
committed
Sema: Simplify ConstraintGraph::addConstraint() and ::removeConstraint()
1 parent 2caf2e0 commit c46ee87

File tree

1 file changed

+23
-28
lines changed

1 file changed

+23
-28
lines changed

lib/Sema/ConstraintGraph.cpp

+23-28
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,16 @@ void ConstraintGraph::addConstraint(Constraint *constraint) {
438438
CS.recordChange(SolverTrail::Change::addedConstraint(typeVar, constraint));
439439

440440
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+
}
441451
}
442452

443453
// If the constraint doesn't reference any type variables, it's orphaned;
@@ -454,20 +464,7 @@ void ConstraintGraph::addConstraint(Constraint *constraint) {
454464
void ConstraintGraph::addConstraint(TypeVariableType *typeVar,
455465
Constraint *constraint) {
456466
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);
471468
return;
472469
}
473470

@@ -480,6 +477,17 @@ void ConstraintGraph::removeConstraint(Constraint *constraint) {
480477
// For the nodes corresponding to each type variable...
481478
auto referencedTypeVars = constraint->getTypeVariables();
482479
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+
483491
// Record the change, if there are active scopes.
484492
if (CS.isRecordingChanges())
485493
CS.recordChange(SolverTrail::Change::removedConstraint(typeVar, constraint));
@@ -500,20 +508,7 @@ void ConstraintGraph::removeConstraint(Constraint *constraint) {
500508
void ConstraintGraph::removeConstraint(TypeVariableType *typeVar,
501509
Constraint *constraint) {
502510
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);
517512
return;
518513
}
519514

0 commit comments

Comments
 (0)