@@ -473,7 +473,6 @@ llvm::TinyPtrVector<Constraint *> ConstraintGraph::gatherConstraints(
473
473
TypeVariableType *typeVar, GatheringKind kind,
474
474
llvm::function_ref<bool (Constraint *)> acceptConstraintFn) {
475
475
llvm::TinyPtrVector<Constraint *> constraints;
476
-
477
476
// Whether we should consider this constraint at all.
478
477
auto rep = CS.getRepresentative (typeVar);
479
478
auto shouldConsiderConstraint = [&](Constraint *constraint) {
@@ -505,19 +504,29 @@ llvm::TinyPtrVector<Constraint *> ConstraintGraph::gatherConstraints(
505
504
506
505
// Add constraints for the given adjacent type variable.
507
506
llvm::SmallPtrSet<TypeVariableType *, 4 > typeVars;
507
+
508
+ // Local function to add constraints
508
509
llvm::SmallPtrSet<Constraint *, 4 > visitedConstraints;
509
- auto addAdjacentConstraints = [&](TypeVariableType *adjTypeVar) {
510
- auto adjTypeVarsToVisit =
511
- (*this )[CS.getRepresentative (adjTypeVar)].getEquivalenceClass ();
510
+ auto addConstraintsOfAdjacency = [&](TypeVariableType *adjTypeVar) {
511
+ ArrayRef<TypeVariableType *> adjTypeVarsToVisit;
512
+ switch (kind) {
513
+ case GatheringKind::EquivalenceClass:
514
+ adjTypeVarsToVisit = adjTypeVar;
515
+ break ;
516
+
517
+ case GatheringKind::AllMentions:
518
+ adjTypeVarsToVisit
519
+ = (*this )[CS.getRepresentative (adjTypeVar)].getEquivalenceClass ();
520
+ break ;
521
+ }
522
+
512
523
for (auto adjTypeVarEquiv : adjTypeVarsToVisit) {
513
524
if (!typeVars.insert (adjTypeVarEquiv).second )
514
525
continue ;
515
526
516
527
for (auto constraint : (*this )[adjTypeVarEquiv].getConstraints ()) {
517
- if (!visitedConstraints.insert (constraint).second )
518
- continue ;
519
-
520
- if (acceptConstraint (constraint))
528
+ if (visitedConstraints.insert (constraint).second &&
529
+ acceptConstraint (constraint))
521
530
constraints.push_back (constraint);
522
531
}
523
532
}
@@ -526,29 +535,34 @@ llvm::TinyPtrVector<Constraint *> ConstraintGraph::gatherConstraints(
526
535
auto &reprNode = (*this )[CS.getRepresentative (typeVar)];
527
536
auto equivClass = reprNode.getEquivalenceClass ();
528
537
for (auto typeVar : equivClass) {
529
- auto &node = (*this )[typeVar];
530
- for (auto constraint : node.getConstraints ()) {
538
+ if (!typeVars.insert (typeVar).second )
539
+ continue ;
540
+
541
+ for (auto constraint : (*this )[typeVar].getConstraints ()) {
531
542
if (visitedConstraints.insert (constraint).second &&
532
543
acceptConstraint (constraint))
533
544
constraints.push_back (constraint);
545
+ }
534
546
535
- // If we want all mentions, visit type variables within each of our
536
- // constraints.
537
- if (kind == GatheringKind::AllMentions) {
538
- if (!shouldConsiderConstraint (constraint))
539
- continue ;
547
+ auto &node = (*this )[typeVar];
540
548
541
- for (auto adjTypeVar : constraint->getTypeVariables ()) {
542
- addAdjacentConstraints (adjTypeVar);
543
- }
544
- }
549
+ for (auto adjTypeVar : node.getFixedBindings ()) {
550
+ addConstraintsOfAdjacency (adjTypeVar);
545
551
}
546
552
547
- // For any type variable mentioned in a fixed binding, add adjacent
548
- // constraints.
549
- for (auto adjTypeVar : node.getFixedBindings ()) {
550
- addAdjacentConstraints (adjTypeVar);
553
+ switch (kind) {
554
+ case GatheringKind::EquivalenceClass:
555
+ break ;
556
+
557
+ case GatheringKind::AllMentions:
558
+ // Retrieve the constraints from adjacent bindings.
559
+ for (auto adjTypeVar : node.getAdjacencies ()) {
560
+ addConstraintsOfAdjacency (adjTypeVar);
561
+ }
562
+
563
+ break ;
551
564
}
565
+
552
566
}
553
567
554
568
return constraints;
0 commit comments