@@ -352,6 +352,36 @@ void ConstraintGraphNode::retractFromInference(Constraint *constraint) {
352
352
}
353
353
}
354
354
355
+ void ConstraintGraphNode::retractFromInference (Type fixedType) {
356
+ // Notify all of the type variables that reference this one.
357
+ //
358
+ // Since this type variable has been replaced with a fixed type
359
+ // all of the concrete types that reference it are going to change,
360
+ // which means that all of the not-yet-attempted bindings should
361
+ // change as well.
362
+ notifyReferencingVars (
363
+ [&](ConstraintGraphNode &node, Constraint *constraint) {
364
+ node.retractFromInference (constraint);
365
+ });
366
+
367
+ if (!fixedType->hasTypeVariable ())
368
+ return ;
369
+
370
+ SmallPtrSet<TypeVariableType *, 4 > referencedVars;
371
+ fixedType->getTypeVariables (referencedVars);
372
+
373
+ for (auto *referencedVar : referencedVars) {
374
+ auto &node = CG[referencedVar];
375
+
376
+ // Newly referred vars need to re-introduce all constraints associated
377
+ // with this type variable since they are now going to be used in
378
+ // all of the constraints that reference bound type variable.
379
+ for (auto *constraint : getConstraints ()) {
380
+ if (isUsefulForReferencedVars (constraint))
381
+ node.retractFromInference (constraint);
382
+ }
383
+ }
384
+ }
355
385
356
386
void ConstraintGraphNode::introduceToInference (Type fixedType) {
357
387
// Notify all of the type variables that reference this one.
@@ -362,7 +392,6 @@ void ConstraintGraphNode::introduceToInference(Type fixedType) {
362
392
// change as well.
363
393
notifyReferencingVars (
364
394
[&](ConstraintGraphNode &node, Constraint *constraint) {
365
- node.retractFromInference (constraint);
366
395
node.introduceToInference (constraint);
367
396
});
368
397
@@ -380,7 +409,6 @@ void ConstraintGraphNode::introduceToInference(Type fixedType) {
380
409
// all of the constraints that reference bound type variable.
381
410
for (auto *constraint : getConstraints ()) {
382
411
if (isUsefulForReferencedVars (constraint)) {
383
- node.retractFromInference (constraint);
384
412
node.introduceToInference (constraint);
385
413
}
386
414
}
@@ -548,6 +576,10 @@ void ConstraintGraph::bindTypeVariable(TypeVariableType *typeVar, Type fixed) {
548
576
}
549
577
}
550
578
579
+ void ConstraintGraph::retractFromInference (TypeVariableType *typeVar, Type fixed) {
580
+ (*this )[typeVar].retractFromInference (fixed);
581
+ }
582
+
551
583
void ConstraintGraph::introduceToInference (TypeVariableType *typeVar, Type fixed) {
552
584
(*this )[typeVar].introduceToInference (fixed);
553
585
}
0 commit comments