[ConstraintGraph] Extract logic to notify referenced variable into a dedicated method

This commit is contained in:
Pavel Yaskevich
2021-06-07 14:18:51 -07:00
parent c139bb4a1c
commit d4cb7564a3
2 changed files with 19 additions and 8 deletions

View File

@@ -197,6 +197,13 @@ void ConstraintGraphNode::notifyReferencingVars() const {
}
}
void ConstraintGraphNode::notifyReferencedVars(
llvm::function_ref<void(ConstraintGraphNode &)> notification) {
for (auto *fixedBinding : getReferencedVars()) {
notification(CG[fixedBinding]);
}
}
void ConstraintGraphNode::addToEquivalenceClass(
ArrayRef<TypeVariableType *> typeVars) {
assert(forRepresentativeVar() &&
@@ -304,10 +311,10 @@ void ConstraintGraphNode::introduceToInference(Constraint *constraint,
if (!notifyReferencedVars || !isUsefulForReferencedVars(constraint))
return;
for (auto *fixedBinding : getReferencedVars()) {
CG[fixedBinding].introduceToInference(constraint,
/*notifyReferencedVars=*/false);
}
this->notifyReferencedVars([&](ConstraintGraphNode &referencedVar) {
referencedVar.introduceToInference(constraint,
/*notifyReferencedVars=*/false);
});
}
void ConstraintGraphNode::retractFromInference(Constraint *constraint,
@@ -325,10 +332,10 @@ void ConstraintGraphNode::retractFromInference(Constraint *constraint,
if (!notifyReferencedVars || !isUsefulForReferencedVars(constraint))
return;
for (auto *fixedBinding : getReferencedVars()) {
CG[fixedBinding].retractFromInference(constraint,
/*notifyReferencedVars=*/false);
}
this->notifyReferencedVars([&](ConstraintGraphNode &referencedVar) {
referencedVar.retractFromInference(constraint,
/*notifyReferencedVars=*/false);
});
}
void ConstraintGraphNode::reintroduceToInference(Constraint *constraint,