From 209889ddc1d51c125c7fded26e51cd259129b699 Mon Sep 17 00:00:00 2001 From: oli Date: Mon, 11 Jan 2021 11:21:24 +0000 Subject: [PATCH] Leave some notes for future changes to the MIR opt level of mir inlining --- compiler/rustc_mir/src/transform/inline.rs | 3 +++ compiler/rustc_mir/src/transform/mod.rs | 7 ++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_mir/src/transform/inline.rs b/compiler/rustc_mir/src/transform/inline.rs index e157ef9c6826..dd9a514466d4 100644 --- a/compiler/rustc_mir/src/transform/inline.rs +++ b/compiler/rustc_mir/src/transform/inline.rs @@ -39,6 +39,9 @@ struct CallSite<'tcx> { impl<'tcx> MirPass<'tcx> for Inline { fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { + // If you change this optimization level, also change the level in + // `mir_drops_elaborated_and_const_checked` for the call to `mir_inliner_callees`. + // Otherwise you will get an ICE about stolen MIR. if tcx.sess.opts.debugging_opts.mir_opt_level < 2 { return; } diff --git a/compiler/rustc_mir/src/transform/mod.rs b/compiler/rustc_mir/src/transform/mod.rs index ea62f9a8f956..2786127513d3 100644 --- a/compiler/rustc_mir/src/transform/mod.rs +++ b/compiler/rustc_mir/src/transform/mod.rs @@ -425,7 +425,12 @@ fn mir_drops_elaborated_and_const_checked<'tcx>( if is_fn_like { let did = def.did.to_def_id(); let def = ty::WithOptConstParam::unknown(did); - let _ = tcx.mir_inliner_callees(ty::InstanceDef::Item(def)); + + // Do not compute the mir call graph without said call graph actually being used. + // Keep this in sync with the mir inliner's optimization level. + if tcx.sess.opts.debugging_opts.mir_opt_level >= 2 { + let _ = tcx.mir_inliner_callees(ty::InstanceDef::Item(def)); + } } let (body, _) = tcx.mir_promoted(def);