@@ -177,7 +177,9 @@ void ConstraintGraphNode::removeConstraint(Constraint *constraint) {
177177 Constraints.pop_back ();
178178}
179179
180- void ConstraintGraphNode::notifyReferencingVars () const {
180+ void ConstraintGraphNode::notifyReferencingVars (
181+ llvm::function_ref<void (ConstraintGraphNode &,
182+ Constraint *)> notification) const {
181183 SmallVector<TypeVariableType *, 4 > stack;
182184
183185 stack.push_back (TypeVar);
@@ -199,7 +201,7 @@ void ConstraintGraphNode::notifyReferencingVars() const {
199201 affectedVar->getImpl ().getRepresentative (/* record=*/ nullptr );
200202
201203 if (!repr->getImpl ().getFixedType (/* record=*/ nullptr ))
202- CG[repr]. reintroduceToInference ( constraint);
204+ notification ( CG[repr], constraint);
203205 }
204206 }
205207 };
@@ -236,7 +238,7 @@ void ConstraintGraphNode::notifyReferencingVars() const {
236238}
237239
238240void ConstraintGraphNode::notifyReferencedVars (
239- llvm::function_ref<void (ConstraintGraphNode &)> notification) {
241+ llvm::function_ref<void (ConstraintGraphNode &)> notification) const {
240242 for (auto *fixedBinding : getReferencedVars ()) {
241243 notification (CG[fixedBinding]);
242244 }
@@ -265,7 +267,14 @@ void ConstraintGraphNode::addToEquivalenceClass(
265267 });
266268 }
267269
268- node.notifyReferencingVars ();
270+ // FIXME: Perhaps this also needs to be split up into two stages,
271+ // where the first stage runs before we merge the equivalence
272+ // classes
273+ node.notifyReferencingVars (
274+ [&](ConstraintGraphNode &node, Constraint *constraint) {
275+ node.retractFromInference (constraint);
276+ node.introduceToInference (constraint);
277+ });
269278 }
270279 }
271280}
@@ -343,10 +352,6 @@ void ConstraintGraphNode::retractFromInference(Constraint *constraint) {
343352 }
344353}
345354
346- void ConstraintGraphNode::reintroduceToInference (Constraint *constraint) {
347- retractFromInference (constraint);
348- introduceToInference (constraint);
349- }
350355
351356void ConstraintGraphNode::introduceToInference (Type fixedType) {
352357 // Notify all of the type variables that reference this one.
@@ -355,7 +360,11 @@ void ConstraintGraphNode::introduceToInference(Type fixedType) {
355360 // all of the concrete types that reference it are going to change,
356361 // which means that all of the not-yet-attempted bindings should
357362 // change as well.
358- notifyReferencingVars ();
363+ notifyReferencingVars (
364+ [&](ConstraintGraphNode &node, Constraint *constraint) {
365+ node.retractFromInference (constraint);
366+ node.introduceToInference (constraint);
367+ });
359368
360369 if (!fixedType->hasTypeVariable ())
361370 return ;
@@ -370,8 +379,10 @@ void ConstraintGraphNode::introduceToInference(Type fixedType) {
370379 // with this type variable since they are now going to be used in
371380 // all of the constraints that reference bound type variable.
372381 for (auto *constraint : getConstraints ()) {
373- if (isUsefulForReferencedVars (constraint))
374- node.reintroduceToInference (constraint);
382+ if (isUsefulForReferencedVars (constraint)) {
383+ node.retractFromInference (constraint);
384+ node.introduceToInference (constraint);
385+ }
375386 }
376387 }
377388}
0 commit comments