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