@@ -549,25 +549,22 @@ void ConstraintGraph::retractBindings(TypeVariableType *typeVar,
549
549
// /
550
550
// / \param cg The constraint graph.
551
551
// / \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.
556
553
// / \param visitedConstraints Set of already-visited constraints, used
557
554
// / internally to avoid duplicated work.
558
555
static void depthFirstSearch (
559
556
ConstraintGraph &cg,
560
557
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 ,
563
560
llvm::SmallPtrSet<Constraint *, 8> &visitedConstraints) {
564
561
// If we're not looking at this type variable right now because we're
565
562
// solving a conjunction element, don't consider its adjacencies.
566
563
if (!cg.getConstraintSystem ().isActiveTypeVariable (typeVar))
567
564
return ;
568
565
569
566
// Visit this node. If we've already seen it, bail out.
570
- if (!preVisitNode (typeVar))
567
+ if (!typeVars. insert (typeVar). second )
571
568
return ;
572
569
573
570
// Local function to visit adjacent type variables.
@@ -577,21 +574,18 @@ static void depthFirstSearch(
577
574
continue ;
578
575
579
576
// Recurse into this node.
580
- depthFirstSearch (cg, adj, preVisitNode, visitConstraint,
581
- visitedConstraints);
577
+ depthFirstSearch (cg, adj, visitConstraint, typeVars, visitedConstraints);
582
578
}
583
579
};
584
580
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.
587
582
auto &node = cg[typeVar];
588
583
for (auto constraint : node.getConstraints ()) {
589
584
// If we've already seen this constraint, skip it.
590
585
if (!visitedConstraints.insert (constraint).second )
591
586
continue ;
592
587
593
- if (visitConstraint (constraint))
594
- visitAdjacencies (constraint->getTypeVariables ());
588
+ visitConstraint (constraint);
595
589
}
596
590
597
591
// Visit all of the other nodes in the equivalence class.
@@ -622,17 +616,11 @@ llvm::TinyPtrVector<Constraint *> ConstraintGraph::gatherConstraints(
622
616
// constraints involving both it and its fixed bindings.
623
617
depthFirstSearch (
624
618
*this , typeVar,
625
- [&](TypeVariableType *typeVar) {
626
- return typeVars.insert (typeVar).second ;
627
- },
628
619
[&](Constraint *constraint) {
629
620
if (acceptConstraintFn (constraint))
630
621
constraints.push_back (constraint);
631
-
632
- // Don't recurse into the constraint's type variables.
633
- return false ;
634
622
},
635
- visitedConstraints);
623
+ typeVars, visitedConstraints);
636
624
return constraints;
637
625
}
638
626
0 commit comments