@@ -8,6 +8,7 @@ use rustc_session::Limit;
88use rustc_span:: sym;
99use tracing:: { instrument, trace} ;
1010
11+ #[ instrument( level = "debug" , skip( tcx) , ret) ]
1112fn should_recurse < ' tcx > ( tcx : TyCtxt < ' tcx > , callee : ty:: Instance < ' tcx > ) -> bool {
1213 match callee. def {
1314 // If there is no MIR available (either because it was not in metadata or
@@ -64,7 +65,7 @@ fn process<'tcx>(
6465 caller : ty:: Instance < ' tcx > ,
6566 target : LocalDefId ,
6667 seen : & mut FxHashSet < ty:: Instance < ' tcx > > ,
67- involved : & mut FxHashSet < ty :: Instance < ' tcx > > ,
68+ involved : & mut FxHashSet < LocalDefId > ,
6869 recursion_limiter : & mut FxHashMap < DefId , usize > ,
6970 recursion_limit : Limit ,
7071) -> bool {
@@ -122,7 +123,10 @@ fn process<'tcx>(
122123 true
123124 } ;
124125 if found_recursion {
125- involved. insert ( callee) ;
126+ if let Some ( callee) = callee. def_id ( ) . as_local ( ) {
127+ // Calling `optimized_mir` of a non-local definition cannot cycle.
128+ involved. insert ( callee) ;
129+ }
126130 cycle_found = true ;
127131 }
128132 }
@@ -135,7 +139,7 @@ fn process<'tcx>(
135139pub ( crate ) fn mir_callgraph_cyclic < ' tcx > (
136140 tcx : TyCtxt < ' tcx > ,
137141 root : LocalDefId ,
138- ) -> UnordSet < ty :: Instance < ' tcx > > {
142+ ) -> UnordSet < LocalDefId > {
139143 assert ! (
140144 !tcx. is_constructor( root. to_def_id( ) ) ,
141145 "you should not call `mir_callgraph_reachable` on enum/struct constructor functions"
0 commit comments