mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 14:55:26 +00:00
Rollup merge of #116896 - cjgillot:single-inline, r=oli-obk
Only check in a single place if a pass is enabled. Fixes https://github.com/rust-lang/rust/issues/116294
This commit is contained in:
commit
096943a534
@ -383,7 +383,7 @@ fn mir_drops_elaborated_and_const_checked(tcx: TyCtxt<'_>, def: LocalDefId) -> &
|
||||
let is_fn_like = tcx.def_kind(def).is_fn_like();
|
||||
if is_fn_like {
|
||||
// Do not compute the mir call graph without said call graph actually being used.
|
||||
if inline::Inline.is_enabled(&tcx.sess) {
|
||||
if pm::should_run_pass(tcx, &inline::Inline) {
|
||||
tcx.ensure_with_value().mir_inliner_callees(ty::InstanceDef::Item(def.to_def_id()));
|
||||
}
|
||||
}
|
||||
|
@ -83,6 +83,25 @@ pub fn run_passes<'tcx>(
|
||||
run_passes_inner(tcx, body, passes, phase_change, true);
|
||||
}
|
||||
|
||||
pub fn should_run_pass<'tcx, P>(tcx: TyCtxt<'tcx>, pass: &P) -> bool
|
||||
where
|
||||
P: MirPass<'tcx> + ?Sized,
|
||||
{
|
||||
let name = pass.name();
|
||||
|
||||
let overridden_passes = &tcx.sess.opts.unstable_opts.mir_enable_passes;
|
||||
let overridden =
|
||||
overridden_passes.iter().rev().find(|(s, _)| s == &*name).map(|(_name, polarity)| {
|
||||
trace!(
|
||||
pass = %name,
|
||||
"{} as requested by flag",
|
||||
if *polarity { "Running" } else { "Not running" },
|
||||
);
|
||||
*polarity
|
||||
});
|
||||
overridden.unwrap_or_else(|| pass.is_enabled(&tcx.sess))
|
||||
}
|
||||
|
||||
fn run_passes_inner<'tcx>(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
body: &mut Body<'tcx>,
|
||||
@ -100,19 +119,9 @@ fn run_passes_inner<'tcx>(
|
||||
for pass in passes {
|
||||
let name = pass.name();
|
||||
|
||||
let overridden = overridden_passes.iter().rev().find(|(s, _)| s == &*name).map(
|
||||
|(_name, polarity)| {
|
||||
trace!(
|
||||
pass = %name,
|
||||
"{} as requested by flag",
|
||||
if *polarity { "Running" } else { "Not running" },
|
||||
);
|
||||
*polarity
|
||||
},
|
||||
);
|
||||
if !overridden.unwrap_or_else(|| pass.is_enabled(&tcx.sess)) {
|
||||
if !should_run_pass(tcx, *pass) {
|
||||
continue;
|
||||
}
|
||||
};
|
||||
|
||||
let dump_enabled = pass.is_mir_dump_enabled();
|
||||
|
||||
|
19
tests/mir-opt/inline/unit_test.rs
Normal file
19
tests/mir-opt/inline/unit_test.rs
Normal file
@ -0,0 +1,19 @@
|
||||
// Check that `-Zmir-enable-passes=+Inline` does not ICE because of stolen MIR.
|
||||
// unit-test: Inline
|
||||
// skip-filecheck
|
||||
#![crate_type = "lib"]
|
||||
|
||||
// Randomize `def_path_hash` by defining them under a module with different names
|
||||
macro_rules! emit {
|
||||
($($m:ident)*) => {$(
|
||||
pub mod $m {
|
||||
pub fn main() {
|
||||
let func = || 123u8;
|
||||
func();
|
||||
}
|
||||
}
|
||||
)*};
|
||||
}
|
||||
|
||||
// Increase the chance of triggering the bug
|
||||
emit!(m00 m01 m02 m03 m04 m05 m06 m07 m08 m09 m10 m11 m12 m13 m14 m15 m16 m17 m18 m19);
|
Loading…
Reference in New Issue
Block a user