Skip to content

Commit 2074013

Browse files
committed
Only store the LocalDefId instead of the whole instance.
1 parent 8a35c7a commit 2074013

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

compiler/rustc_middle/src/query/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1284,7 +1284,7 @@ rustc_queries! {
12841284
}
12851285

12861286
/// Return the set of (transitive) callees that may result in a recursive call to `key`.
1287-
query mir_callgraph_cyclic(key: LocalDefId) -> &'tcx UnordSet<ty::Instance<'tcx>> {
1287+
query mir_callgraph_cyclic(key: LocalDefId) -> &'tcx UnordSet<LocalDefId> {
12881288
fatal_cycle
12891289
arena_cache
12901290
desc { |tcx|

compiler/rustc_mir_transform/src/inline.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -770,14 +770,15 @@ fn check_mir_is_available<'tcx, I: Inliner<'tcx>>(
770770
return Ok(());
771771
}
772772

773-
if callee_def_id.is_local()
773+
if let Some(callee_def_id) = callee_def_id.as_local()
774774
&& !inliner
775775
.tcx()
776776
.is_lang_item(inliner.tcx().parent(caller_def_id), rustc_hir::LangItem::FnOnce)
777777
{
778778
// If we know for sure that the function we're calling will itself try to
779779
// call us, then we avoid inlining that function.
780-
if inliner.tcx().mir_callgraph_cyclic(caller_def_id.expect_local()).contains(&callee) {
780+
if inliner.tcx().mir_callgraph_cyclic(caller_def_id.expect_local()).contains(&callee_def_id)
781+
{
781782
debug!("query cycle avoidance");
782783
return Err("caller might be reachable from callee");
783784
}

compiler/rustc_mir_transform/src/inline/cycle.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use rustc_session::Limit;
88
use rustc_span::sym;
99
use tracing::{instrument, trace};
1010

11+
#[instrument(level = "debug", skip(tcx), ret)]
1112
fn 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>(
135139
pub(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

Comments
 (0)