@@ -107,7 +107,14 @@ void ConstraintGraphNode::addConstraint(Constraint *constraint) {
107107 assert (ConstraintIndex.count (constraint) == 0 && " Constraint re-insertion" );
108108 ConstraintIndex[constraint] = Constraints.size ();
109109 Constraints.push_back (constraint);
110- introduceToInference (constraint, /* notifyFixedBindings=*/ true );
110+
111+ {
112+ introduceToInference (constraint);
113+
114+ notifyReferencedVars ([&](ConstraintGraphNode &referencedVar) {
115+ referencedVar.introduceToInference (constraint);
116+ });
117+ }
111118}
112119
113120void ConstraintGraphNode::removeConstraint (Constraint *constraint) {
@@ -119,8 +126,13 @@ void ConstraintGraphNode::removeConstraint(Constraint *constraint) {
119126 ConstraintIndex.erase (pos);
120127 assert (Constraints[index] == constraint && " Mismatched constraint" );
121128
122- retractFromInference (constraint,
123- /* notifyFixedBindings=*/ true );
129+ {
130+ retractFromInference (constraint);
131+
132+ notifyReferencedVars ([&](ConstraintGraphNode &referencedVar) {
133+ referencedVar.retractFromInference (constraint);
134+ });
135+ }
124136
125137 // If this is the last constraint, just pop it off the list and we're done.
126138 unsigned lastIndex = Constraints.size ()-1 ;
@@ -160,8 +172,7 @@ void ConstraintGraphNode::notifyReferencingVars() const {
160172 affectedVar->getImpl ().getRepresentative (/* record=*/ nullptr );
161173
162174 if (!repr->getImpl ().getFixedType (/* record=*/ nullptr ))
163- CG[repr].reintroduceToInference (constraint,
164- /* notifyReferencedVars=*/ false );
175+ CG[repr].reintroduceToInference (constraint);
165176 }
166177 }
167178 };
@@ -197,6 +208,13 @@ void ConstraintGraphNode::notifyReferencingVars() const {
197208 }
198209}
199210
211+ void ConstraintGraphNode::notifyReferencedVars (
212+ llvm::function_ref<void (ConstraintGraphNode &)> notification) {
213+ for (auto *fixedBinding : getReferencedVars ()) {
214+ notification (CG[fixedBinding]);
215+ }
216+ }
217+
200218void ConstraintGraphNode::addToEquivalenceClass (
201219 ArrayRef<TypeVariableType *> typeVars) {
202220 assert (forRepresentativeVar () &&
@@ -210,7 +228,11 @@ void ConstraintGraphNode::addToEquivalenceClass(
210228 auto &node = CG[newMember];
211229
212230 for (auto *constraint : node.getConstraints ()) {
213- introduceToInference (constraint, /* notifyReferencedVars=*/ true );
231+ introduceToInference (constraint);
232+
233+ notifyReferencedVars ([&](ConstraintGraphNode &referencedVar) {
234+ referencedVar.introduceToInference (constraint);
235+ });
214236 }
215237
216238 node.notifyReferencingVars ();
@@ -289,52 +311,51 @@ static bool isUsefulForReferencedVars(Constraint *constraint) {
289311 }
290312}
291313
292- void ConstraintGraphNode::introduceToInference (Constraint *constraint,
293- bool notifyReferencedVars) {
314+ void ConstraintGraphNode::introduceToInference (Constraint *constraint) {
294315 if (forRepresentativeVar ()) {
295316 auto fixedType = TypeVar->getImpl ().getFixedType (/* record=*/ nullptr );
296317 if (!fixedType)
297318 getCurrentBindings ().infer (constraint);
298319 } else {
299320 auto *repr =
300321 getTypeVariable ()->getImpl ().getRepresentative (/* record=*/ nullptr );
301- CG[repr].introduceToInference (constraint, /* notifyReferencedVars= */ false );
322+ CG[repr].introduceToInference (constraint);
302323 }
303324
325+ /*
304326 if (!notifyReferencedVars || !isUsefulForReferencedVars(constraint))
305327 return;
306328
307- for ( auto *fixedBinding : getReferencedVars () ) {
308- CG[fixedBinding] .introduceToInference (constraint,
309- /* notifyReferencedVars= */ false );
310- }
329+ this->notifyReferencedVars([&](ConstraintGraphNode &referencedVar ) {
330+ referencedVar .introduceToInference(constraint);
331+ } );
332+ */
311333}
312334
313- void ConstraintGraphNode::retractFromInference (Constraint *constraint,
314- bool notifyReferencedVars) {
335+ void ConstraintGraphNode::retractFromInference (Constraint *constraint) {
315336 if (forRepresentativeVar ()) {
316337 auto fixedType = TypeVar->getImpl ().getFixedType (/* record=*/ nullptr );
317338 if (!fixedType)
318339 getCurrentBindings ().retract (constraint);
319340 } else {
320341 auto *repr =
321342 getTypeVariable ()->getImpl ().getRepresentative (/* record=*/ nullptr );
322- CG[repr].retractFromInference (constraint, /* notifyReferencedVars= */ false );
343+ CG[repr].retractFromInference (constraint);
323344 }
324345
346+ /*
325347 if (!notifyReferencedVars || !isUsefulForReferencedVars(constraint))
326348 return;
327349
328- for ( auto *fixedBinding : getReferencedVars () ) {
329- CG[fixedBinding] .retractFromInference (constraint,
330- /* notifyReferencedVars= */ false );
331- }
350+ this->notifyReferencedVars([&](ConstraintGraphNode &referencedVar ) {
351+ referencedVar .retractFromInference(constraint);
352+ } );
353+ */
332354}
333355
334- void ConstraintGraphNode::reintroduceToInference (Constraint *constraint,
335- bool notifyReferencedVars) {
336- retractFromInference (constraint, notifyReferencedVars);
337- introduceToInference (constraint, notifyReferencedVars);
356+ void ConstraintGraphNode::reintroduceToInference (Constraint *constraint) {
357+ retractFromInference (constraint);
358+ introduceToInference (constraint);
338359}
339360
340361void ConstraintGraphNode::introduceToInference (Type fixedType) {
@@ -360,8 +381,7 @@ void ConstraintGraphNode::introduceToInference(Type fixedType) {
360381 // all of the constraints that reference bound type variable.
361382 for (auto *constraint : getConstraints ()) {
362383 if (isUsefulForReferencedVars (constraint))
363- node.reintroduceToInference (constraint,
364- /* notifyReferencedVars=*/ false );
384+ node.reintroduceToInference (constraint);
365385 }
366386 }
367387}
0 commit comments