@@ -549,25 +549,22 @@ void ConstraintGraph::retractBindings(TypeVariableType *typeVar,
549549// /
550550// / \param cg The constraint graph.
551551// / \param typeVar The type variable we're searching from.
552- // / \param preVisitNode Called before traversing a node. Must return \c
553- // / false when the node has already been visited.
554- // / \param visitConstraint Called before considering a constraint. If it
555- // / returns \c false, that constraint will be skipped.
552+ // / \param visitConstraint Called before considering a constraint.
556553// / \param visitedConstraints Set of already-visited constraints, used
557554// / internally to avoid duplicated work.
558555static void depthFirstSearch (
559556 ConstraintGraph &cg,
560557 TypeVariableType *typeVar,
561- llvm::function_ref<bool (TypeVariableType *)> preVisitNode ,
562- llvm::function_ref<bool(Constraint *)> visitConstraint ,
558+ llvm::function_ref<void (Constraint *)> visitConstraint ,
559+ llvm::SmallPtrSet<TypeVariableType *, 4> &typeVars ,
563560 llvm::SmallPtrSet<Constraint *, 8> &visitedConstraints) {
564561 // If we're not looking at this type variable right now because we're
565562 // solving a conjunction element, don't consider its adjacencies.
566563 if (!cg.getConstraintSystem ().isActiveTypeVariable (typeVar))
567564 return ;
568565
569566 // Visit this node. If we've already seen it, bail out.
570- if (!preVisitNode (typeVar))
567+ if (!typeVars. insert (typeVar). second )
571568 return ;
572569
573570 // Local function to visit adjacent type variables.
@@ -577,21 +574,18 @@ static void depthFirstSearch(
577574 continue ;
578575
579576 // Recurse into this node.
580- depthFirstSearch (cg, adj, preVisitNode, visitConstraint,
581- visitedConstraints);
577+ depthFirstSearch (cg, adj, visitConstraint, typeVars, visitedConstraints);
582578 }
583579 };
584580
585- // Walk all of the constraints associated with this node to find related
586- // nodes.
581+ // Walk all of the constraints associated with this node.
587582 auto &node = cg[typeVar];
588583 for (auto constraint : node.getConstraints ()) {
589584 // If we've already seen this constraint, skip it.
590585 if (!visitedConstraints.insert (constraint).second )
591586 continue ;
592587
593- if (visitConstraint (constraint))
594- visitAdjacencies (constraint->getTypeVariables ());
588+ visitConstraint (constraint);
595589 }
596590
597591 // Visit all of the other nodes in the equivalence class.
@@ -622,17 +616,11 @@ llvm::TinyPtrVector<Constraint *> ConstraintGraph::gatherConstraints(
622616 // constraints involving both it and its fixed bindings.
623617 depthFirstSearch (
624618 *this , typeVar,
625- [&](TypeVariableType *typeVar) {
626- return typeVars.insert (typeVar).second ;
627- },
628619 [&](Constraint *constraint) {
629620 if (acceptConstraintFn (constraint))
630621 constraints.push_back (constraint);
631-
632- // Don't recurse into the constraint's type variables.
633- return false ;
634622 },
635- visitedConstraints);
623+ typeVars, visitedConstraints);
636624 return constraints;
637625 }
638626
0 commit comments