@@ -545,18 +545,11 @@ void ConstraintGraph::retractBindings(TypeVariableType *typeVar,
545545
546546#pragma mark Algorithms
547547
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.
555548static void depthFirstSearch (
556549 ConstraintGraph &cg,
557550 TypeVariableType *typeVar,
558- llvm::function_ref<void (Constraint *)> visitConstraint,
559551 llvm::SmallPtrSet<TypeVariableType *, 4 > &typeVars,
552+ llvm::TinyPtrVector<Constraint *> &constraints,
560553 llvm::SmallPtrSet<Constraint *, 8 > &visitedConstraints) {
561554 // If we're not looking at this type variable right now because we're
562555 // solving a conjunction element, don't consider its adjacencies.
@@ -570,11 +563,8 @@ static void depthFirstSearch(
570563 // Local function to visit adjacent type variables.
571564 auto visitAdjacencies = [&](ArrayRef<TypeVariableType *> adjTypeVars) {
572565 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);
578568 }
579569 };
580570
@@ -585,7 +575,7 @@ static void depthFirstSearch(
585575 if (!visitedConstraints.insert (constraint).second )
586576 continue ;
587577
588- visitConstraint (constraint);
578+ constraints. push_back (constraint);
589579 }
590580
591581 // Visit all of the other nodes in the equivalence class.
@@ -604,28 +594,22 @@ static void depthFirstSearch(
604594 visitAdjacencies (node.getReferencedVars ());
605595}
606596
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) {
610599 llvm::TinyPtrVector<Constraint *> constraints;
611600 llvm::SmallPtrSet<TypeVariableType *, 4 > typeVars;
612601 llvm::SmallPtrSet<Constraint *, 8 > visitedConstraints;
613602
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+ }
626606
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;
629613
630614 // Local function to add constraints.
631615 auto addTypeVarConstraints = [&](TypeVariableType *adjTypeVar) {
0 commit comments