@@ -486,51 +486,43 @@ void ConstraintGraph::gatherConstraints(
486
486
auto &reprNode = (*this )[CS.getRepresentative (typeVar)];
487
487
auto equivClass = reprNode.getEquivalenceClass ();
488
488
llvm::SmallPtrSet<TypeVariableType *, 4 > typeVars;
489
- for (auto typeVar : equivClass) {
490
- if (!typeVars.insert (typeVar).second )
491
- continue ;
492
-
493
- for (auto constraint : (*this )[typeVar].getConstraints ()) {
494
- if (acceptConstraint (constraint))
495
- constraints.insert (constraint);
496
- }
497
-
498
- auto &node = (*this )[typeVar];
499
489
500
- // Retrieve the constraints from adjacent bindings.
501
- for (auto adjTypeVar : node.getAdjacencies ()) {
502
- switch (kind) {
503
- case GatheringKind::EquivalenceClass:
504
- if (!node.getAdjacency (adjTypeVar).FixedBinding )
505
- continue ;
506
- break ;
507
-
508
- case GatheringKind::AllMentions:
509
- break ;
510
- }
511
490
512
- ArrayRef<TypeVariableType *> adjTypeVarsToVisit;
513
- switch (kind) {
514
- case GatheringKind::EquivalenceClass:
515
- adjTypeVarsToVisit = adjTypeVar;
516
- break ;
491
+ // / Add constraints for the given adjacent type variable.
492
+ auto addAdjacentConstraints = [&](TypeVariableType *adjTypeVar) {
493
+ auto adjTypeVarsToVisit =
494
+ (*this )[CS.getRepresentative (adjTypeVar)].getEquivalenceClass ();
495
+ for (auto adjTypeVarEquiv : adjTypeVarsToVisit) {
496
+ if (!typeVars.insert (adjTypeVarEquiv).second )
497
+ continue ;
517
498
518
- case GatheringKind::AllMentions:
519
- adjTypeVarsToVisit
520
- = (*this )[CS.getRepresentative (adjTypeVar)].getEquivalenceClass ();
521
- break ;
499
+ for (auto constraint : (*this )[adjTypeVarEquiv].getConstraints ()) {
500
+ if (acceptConstraint (constraint))
501
+ constraints.insert (constraint);
522
502
}
503
+ }
504
+ };
523
505
524
- for (auto adjTypeVarEquiv : adjTypeVarsToVisit) {
525
- if (!typeVars.insert (adjTypeVarEquiv).second )
526
- continue ;
506
+ for (auto typeVar : equivClass) {
507
+ auto &node = (*this )[typeVar];
508
+ for (auto constraint : node.getConstraints ()) {
509
+ if (acceptConstraint (constraint))
510
+ constraints.insert (constraint);
527
511
528
- for (auto constraint : (*this )[adjTypeVarEquiv].getConstraints ()) {
529
- if (acceptConstraint (constraint))
530
- constraints.insert (constraint);
512
+ // If we want all mentions, visit type variables within each of our
513
+ // constraints.
514
+ if (kind == GatheringKind::AllMentions) {
515
+ for (auto adjTypeVar : constraint->getTypeVariables ()) {
516
+ addAdjacentConstraints (adjTypeVar);
531
517
}
532
518
}
533
519
}
520
+
521
+ // For any type variable mentioned in a fixed binding, add adjacent
522
+ // constraints.
523
+ for (auto adjTypeVar : node.getFixedAdjacencies ()) {
524
+ addAdjacentConstraints (adjTypeVar);
525
+ }
534
526
}
535
527
}
536
528
0 commit comments