@@ -328,17 +328,17 @@ void ConstraintGraphNode::retractFromInference(Constraint *constraint) {
328
328
}
329
329
}
330
330
331
- void ConstraintGraphNode::retractFromInference (Type fixedType) {
331
+ void ConstraintGraphNode::updateFixedType (
332
+ Type fixedType,
333
+ llvm::function_ref<void (ConstraintGraphNode &,
334
+ Constraint *)> notification) const {
332
335
// Notify all of the type variables that reference this one.
333
336
//
334
337
// Since this type variable has been replaced with a fixed type
335
338
// all of the concrete types that reference it are going to change,
336
339
// which means that all of the not-yet-attempted bindings should
337
340
// change as well.
338
- notifyReferencingVars (
339
- [&](ConstraintGraphNode &node, Constraint *constraint) {
340
- node.retractFromInference (constraint);
341
- });
341
+ notifyReferencingVars (notification);
342
342
343
343
if (!fixedType->hasTypeVariable ())
344
344
return ;
@@ -354,41 +354,25 @@ void ConstraintGraphNode::retractFromInference(Type fixedType) {
354
354
// all of the constraints that reference bound type variable.
355
355
for (auto *constraint : getConstraints ()) {
356
356
if (isUsefulForReferencedVars (constraint))
357
- node. retractFromInference ( constraint);
357
+ notification (node, constraint);
358
358
}
359
359
}
360
360
}
361
361
362
- void ConstraintGraphNode::introduceToInference (Type fixedType) {
363
- // Notify all of the type variables that reference this one.
364
- //
365
- // Since this type variable has been replaced with a fixed type
366
- // all of the concrete types that reference it are going to change,
367
- // which means that all of the not-yet-attempted bindings should
368
- // change as well.
369
- notifyReferencingVars (
370
- [&](ConstraintGraphNode &node, Constraint *constraint) {
371
- node.introduceToInference (constraint);
372
- });
373
-
374
- if (!fixedType->hasTypeVariable ())
375
- return ;
376
-
377
- SmallPtrSet<TypeVariableType *, 4 > referencedVars;
378
- fixedType->getTypeVariables (referencedVars);
379
-
380
- for (auto *referencedVar : referencedVars) {
381
- auto &node = CG[referencedVar];
362
+ void ConstraintGraphNode::retractFromInference (Type fixedType) {
363
+ return updateFixedType (
364
+ fixedType,
365
+ [](ConstraintGraphNode &node, Constraint *constraint) {
366
+ node.retractFromInference (constraint);
367
+ });
368
+ }
382
369
383
- // Newly referred vars need to re-introduce all constraints associated
384
- // with this type variable since they are now going to be used in
385
- // all of the constraints that reference bound type variable.
386
- for (auto *constraint : getConstraints ()) {
387
- if (isUsefulForReferencedVars (constraint)) {
370
+ void ConstraintGraphNode::introduceToInference (Type fixedType) {
371
+ return updateFixedType (
372
+ fixedType,
373
+ [](ConstraintGraphNode &node, Constraint *constraint) {
388
374
node.introduceToInference (constraint);
389
- }
390
- }
391
- }
375
+ });
392
376
}
393
377
394
378
#pragma mark Graph mutation
0 commit comments