@@ -8,6 +8,7 @@ use rustc_session::Limit;
8
8
use rustc_span:: sym;
9
9
use tracing:: { instrument, trace} ;
10
10
11
+ #[ instrument( level = "debug" , skip( tcx) , ret) ]
11
12
fn should_recurse < ' tcx > ( tcx : TyCtxt < ' tcx > , callee : ty:: Instance < ' tcx > ) -> bool {
12
13
match callee. def {
13
14
// If there is no MIR available (either because it was not in metadata or
@@ -64,7 +65,7 @@ fn process<'tcx>(
64
65
caller : ty:: Instance < ' tcx > ,
65
66
target : LocalDefId ,
66
67
seen : & mut FxHashSet < ty:: Instance < ' tcx > > ,
67
- involved : & mut FxHashSet < ty :: Instance < ' tcx > > ,
68
+ involved : & mut FxHashSet < LocalDefId > ,
68
69
recursion_limiter : & mut FxHashMap < DefId , usize > ,
69
70
recursion_limit : Limit ,
70
71
) -> bool {
@@ -122,7 +123,10 @@ fn process<'tcx>(
122
123
true
123
124
} ;
124
125
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
+ }
126
130
cycle_found = true ;
127
131
}
128
132
}
@@ -135,7 +139,7 @@ fn process<'tcx>(
135
139
pub ( crate ) fn mir_callgraph_cyclic < ' tcx > (
136
140
tcx : TyCtxt < ' tcx > ,
137
141
root : LocalDefId ,
138
- ) -> UnordSet < ty :: Instance < ' tcx > > {
142
+ ) -> UnordSet < LocalDefId > {
139
143
assert ! (
140
144
!tcx. is_constructor( root. to_def_id( ) ) ,
141
145
"you should not call `mir_callgraph_reachable` on enum/struct constructor functions"
0 commit comments