@@ -177,7 +177,9 @@ void ConstraintGraphNode::removeConstraint(Constraint *constraint) {
177
177
Constraints.pop_back ();
178
178
}
179
179
180
- void ConstraintGraphNode::notifyReferencingVars () const {
180
+ void ConstraintGraphNode::notifyReferencingVars (
181
+ llvm::function_ref<void (ConstraintGraphNode &,
182
+ Constraint *)> notification) const {
181
183
SmallVector<TypeVariableType *, 4 > stack;
182
184
183
185
stack.push_back (TypeVar);
@@ -199,7 +201,7 @@ void ConstraintGraphNode::notifyReferencingVars() const {
199
201
affectedVar->getImpl ().getRepresentative (/* record=*/ nullptr );
200
202
201
203
if (!repr->getImpl ().getFixedType (/* record=*/ nullptr ))
202
- CG[repr]. reintroduceToInference ( constraint);
204
+ notification ( CG[repr], constraint);
203
205
}
204
206
}
205
207
};
@@ -236,7 +238,7 @@ void ConstraintGraphNode::notifyReferencingVars() const {
236
238
}
237
239
238
240
void ConstraintGraphNode::notifyReferencedVars (
239
- llvm::function_ref<void (ConstraintGraphNode &)> notification) {
241
+ llvm::function_ref<void (ConstraintGraphNode &)> notification) const {
240
242
for (auto *fixedBinding : getReferencedVars ()) {
241
243
notification (CG[fixedBinding]);
242
244
}
@@ -265,7 +267,14 @@ void ConstraintGraphNode::addToEquivalenceClass(
265
267
});
266
268
}
267
269
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
+ });
269
278
}
270
279
}
271
280
}
@@ -343,10 +352,6 @@ void ConstraintGraphNode::retractFromInference(Constraint *constraint) {
343
352
}
344
353
}
345
354
346
- void ConstraintGraphNode::reintroduceToInference (Constraint *constraint) {
347
- retractFromInference (constraint);
348
- introduceToInference (constraint);
349
- }
350
355
351
356
void ConstraintGraphNode::introduceToInference (Type fixedType) {
352
357
// Notify all of the type variables that reference this one.
@@ -355,7 +360,11 @@ void ConstraintGraphNode::introduceToInference(Type fixedType) {
355
360
// all of the concrete types that reference it are going to change,
356
361
// which means that all of the not-yet-attempted bindings should
357
362
// change as well.
358
- notifyReferencingVars ();
363
+ notifyReferencingVars (
364
+ [&](ConstraintGraphNode &node, Constraint *constraint) {
365
+ node.retractFromInference (constraint);
366
+ node.introduceToInference (constraint);
367
+ });
359
368
360
369
if (!fixedType->hasTypeVariable ())
361
370
return ;
@@ -370,8 +379,10 @@ void ConstraintGraphNode::introduceToInference(Type fixedType) {
370
379
// with this type variable since they are now going to be used in
371
380
// all of the constraints that reference bound type variable.
372
381
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
+ }
375
386
}
376
387
}
377
388
}
0 commit comments