@@ -571,20 +571,17 @@ void ConstraintGraph::retractBindings(TypeVariableType *typeVar,
571571// /
572572// / \param cg The constraint graph.
573573// / \param typeVar The type variable we're searching from.
574- // / \param preVisitNode Called before traversing a node. Must return \c
575- // / false when the node has already been visited.
576- // / \param visitConstraint Called before considering a constraint. If it
577- // / returns \c false, that constraint will be skipped.
574+ // / \param visitConstraint Called before considering a constraint.
578575// / \param visitedConstraints Set of already-visited constraints, used
579576// / internally to avoid duplicated work.
580577static void depthFirstSearch (
581578 ConstraintGraph &cg,
582579 TypeVariableType *typeVar,
583- llvm::function_ref<bool (TypeVariableType *)> preVisitNode ,
584- llvm::function_ref<bool(Constraint *)> visitConstraint ,
580+ llvm::function_ref<void (Constraint *)> visitConstraint ,
581+ llvm::SmallPtrSet<TypeVariableType *, 4> &typeVars ,
585582 llvm::SmallPtrSet<Constraint *, 8> &visitedConstraints) {
586583 // Visit this node. If we've already seen it, bail out.
587- if (!preVisitNode (typeVar))
584+ if (!typeVars. insert (typeVar). second )
588585 return ;
589586
590587 // Local function to visit adjacent type variables.
@@ -594,21 +591,18 @@ static void depthFirstSearch(
594591 continue ;
595592
596593 // Recurse into this node.
597- depthFirstSearch (cg, adj, preVisitNode, visitConstraint,
598- visitedConstraints);
594+ depthFirstSearch (cg, adj, visitConstraint, typeVars, visitedConstraints);
599595 }
600596 };
601597
602- // Walk all of the constraints associated with this node to find related
603- // nodes.
598+ // Walk all of the constraints associated with this node.
604599 auto &node = cg[typeVar];
605600 for (auto constraint : node.getConstraints ()) {
606601 // If we've already seen this constraint, skip it.
607602 if (!visitedConstraints.insert (constraint).second )
608603 continue ;
609604
610- if (visitConstraint (constraint))
611- visitAdjacencies (constraint->getTypeVariables ());
605+ visitConstraint (constraint);
612606 }
613607
614608 // Visit all of the other nodes in the equivalence class.
@@ -639,17 +633,11 @@ llvm::TinyPtrVector<Constraint *> ConstraintGraph::gatherConstraints(
639633 // constraints involving both it and its fixed bindings.
640634 depthFirstSearch (
641635 *this , typeVar,
642- [&](TypeVariableType *typeVar) {
643- return typeVars.insert (typeVar).second ;
644- },
645636 [&](Constraint *constraint) {
646637 if (acceptConstraintFn (constraint))
647638 constraints.push_back (constraint);
648-
649- // Don't recurse into the constraint's type variables.
650- return false ;
651639 },
652- visitedConstraints);
640+ typeVars, visitedConstraints);
653641 return constraints;
654642 }
655643
0 commit comments