@@ -814,19 +814,29 @@ namespace {
814
814
}
815
815
816
816
// / Perform a depth-first search to produce a from the given type variable,
817
- // / notifying the function object \c postVisit after each reachable
818
- // / type variable has been visited.
817
+ // / notifying the function object.
818
+ // /
819
+ // / \param getAdjacencies Called to retrieve the set of type variables
820
+ // / that are adjacent to the given type variable.
821
+ // /
822
+ // / \param preVisit Called before visiting the adjacencies of the given
823
+ // / type variable. When it returns \c true, the adjacencies of this type
824
+ // / variable will be visited. When \c false, the adjacencies will not be
825
+ // / visited and \c postVisit will not be called.
826
+ // /
827
+ // / \param postVisit Called after visiting the adjacencies of the given
828
+ // / type variable.
819
829
static void postorderDepthFirstSearchRec (
820
830
TypeVariableType *typeVar,
821
831
llvm::function_ref<
822
832
ArrayRef<TypeVariableType *>(TypeVariableType *)> getAdjacencies,
823
- llvm::function_ref<void (TypeVariableType *)> postVisit ,
824
- SmallPtrSet< TypeVariableType *, 4> &visited ) {
825
- if (!visited. insert (typeVar). second )
833
+ llvm::function_ref<bool (TypeVariableType *)> preVisit ,
834
+ llvm::function_ref<void( TypeVariableType *)> postVisit ) {
835
+ if (!preVisit (typeVar))
826
836
return ;
827
837
828
838
for (auto adj : getAdjacencies (typeVar)) {
829
- postorderDepthFirstSearchRec (adj, getAdjacencies, postVisit, visited );
839
+ postorderDepthFirstSearchRec (adj, getAdjacencies, preVisit, postVisit );
830
840
}
831
841
832
842
postVisit (typeVar);
@@ -855,14 +865,16 @@ namespace {
855
865
856
866
return oneWayComponent->second .inAdjacencies ;
857
867
},
868
+ [&](TypeVariableType *typeVar) {
869
+ return visited.insert (typeVar).second ;
870
+ },
858
871
[&](TypeVariableType *dependsOn) {
859
872
// Don't record dependency on ourselves.
860
873
if (dependsOn == inAdj)
861
874
return ;
862
875
863
876
indirectlyReachable.insert (dependsOn);
864
- },
865
- visited);
877
+ });
866
878
867
879
// Remove any in-adjacency of this component that is indirectly
868
880
// reachable.
@@ -922,13 +934,15 @@ namespace {
922
934
923
935
return oneWayComponent->second .outAdjacencies ;
924
936
},
937
+ [&](TypeVariableType *typeVar) {
938
+ return visited.insert (typeVar).second ;
939
+ },
925
940
[&](TypeVariableType *typeVar) {
926
941
// Record this type variable, if it's one of the representative
927
942
// type variables.
928
943
if (validComponents.count (typeVar) > 0 )
929
944
orderedReps.push_back (typeVar);
930
- },
931
- visited);
945
+ });
932
946
}
933
947
934
948
assert (orderedReps.size () == representativeTypeVars.size ());
0 commit comments