@@ -552,31 +552,26 @@ void ConstraintGraph::retractBindings(TypeVariableType *typeVar,
552
552
553
553
#pragma mark Algorithms
554
554
555
- // / Perform a depth-first search.
556
- // /
557
- // / \param cg The constraint graph.
558
- // / \param typeVar The type variable we're searching from.
559
- // / \param visitConstraint Called before considering a constraint.
560
- // / \param visitedConstraints Set of already-visited constraints, used
561
- // / internally to avoid duplicated work.
562
555
static void depthFirstSearch (
563
556
ConstraintGraph &cg,
564
557
TypeVariableType *typeVar,
565
- llvm::function_ref<void (Constraint *)> visitConstraint,
566
558
llvm::SmallPtrSet<TypeVariableType *, 4 > &typeVars,
559
+ llvm::TinyPtrVector<Constraint *> &constraints,
567
560
llvm::SmallPtrSet<Constraint *, 8 > &visitedConstraints) {
561
+ // If we're not looking at this type variable right now because we're
562
+ // solving a conjunction element, don't consider its adjacencies.
563
+ if (!cg.getConstraintSystem ().isActiveTypeVariable (typeVar))
564
+ return ;
565
+
568
566
// Visit this node. If we've already seen it, bail out.
569
567
if (!typeVars.insert (typeVar).second )
570
568
return ;
571
569
572
570
// Local function to visit adjacent type variables.
573
571
auto visitAdjacencies = [&](ArrayRef<TypeVariableType *> adjTypeVars) {
574
572
for (auto adj : adjTypeVars) {
575
- if (adj == typeVar)
576
- continue ;
577
-
578
- // Recurse into this node.
579
- depthFirstSearch (cg, adj, visitConstraint, typeVars, visitedConstraints);
573
+ if (adj != typeVar)
574
+ depthFirstSearch (cg, adj, typeVars, constraints, visitedConstraints);
580
575
}
581
576
};
582
577
@@ -587,7 +582,7 @@ static void depthFirstSearch(
587
582
if (!visitedConstraints.insert (constraint).second )
588
583
continue ;
589
584
590
- visitConstraint (constraint);
585
+ constraints. push_back (constraint);
591
586
}
592
587
593
588
// Visit all of the other nodes in the equivalence class.
@@ -606,28 +601,22 @@ static void depthFirstSearch(
606
601
visitAdjacencies (node.getReferencedVars ());
607
602
}
608
603
609
- llvm::TinyPtrVector<Constraint *> ConstraintGraph::gatherConstraints (
610
- TypeVariableType *typeVar, GatheringKind kind,
611
- llvm::function_ref<bool (Constraint *)> acceptConstraintFn) {
604
+ llvm::TinyPtrVector<Constraint *> ConstraintGraph::gatherAllConstraints (
605
+ TypeVariableType *typeVar) {
612
606
llvm::TinyPtrVector<Constraint *> constraints;
613
607
llvm::SmallPtrSet<TypeVariableType *, 4 > typeVars;
614
608
llvm::SmallPtrSet<Constraint *, 8 > visitedConstraints;
615
609
616
- if (kind == GatheringKind::AllMentions) {
617
- // If we've been asked for "all mentions" of a type variable, search for
618
- // constraints involving both it and its fixed bindings.
619
- depthFirstSearch (
620
- *this , typeVar,
621
- [&](Constraint *constraint) {
622
- if (acceptConstraintFn (constraint))
623
- constraints.push_back (constraint);
624
- },
625
- typeVars, visitedConstraints);
626
- return constraints;
627
- }
610
+ depthFirstSearch (*this , typeVar, typeVars, constraints, visitedConstraints);
611
+ return constraints;
612
+ }
628
613
629
- // Otherwise only search in the type var's equivalence class and immediate
630
- // fixed bindings.
614
+ llvm::TinyPtrVector<Constraint *> ConstraintGraph::gatherNearbyConstraints (
615
+ TypeVariableType *typeVar,
616
+ llvm::function_ref<bool (Constraint *)> acceptConstraintFn) {
617
+ llvm::TinyPtrVector<Constraint *> constraints;
618
+ llvm::SmallPtrSet<TypeVariableType *, 4 > typeVars;
619
+ llvm::SmallPtrSet<Constraint *, 8 > visitedConstraints;
631
620
632
621
// Local function to add constraints.
633
622
auto addTypeVarConstraints = [&](TypeVariableType *adjTypeVar) {
0 commit comments