From 1e07c1955c9a263d9d5f40c0c8f66f91989282d3 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Sat, 3 Aug 2024 14:11:31 -0400 Subject: [PATCH] Make validate_mir pull optimized/ctfe MIR for all bodies --- compiler/rustc_interface/src/passes.rs | 13 +++++++++++++ tests/crashes/121127.rs | 2 +- tests/crashes/122909.rs | 2 +- tests/crashes/126896.rs | 2 +- 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/compiler/rustc_interface/src/passes.rs b/compiler/rustc_interface/src/passes.rs index 8c99b1f444766..96a6f52d60b6c 100644 --- a/compiler/rustc_interface/src/passes.rs +++ b/compiler/rustc_interface/src/passes.rs @@ -818,6 +818,19 @@ fn run_required_analyses(tcx: TyCtxt<'_>) { }); sess.time("layout_testing", || layout_test::test_layout(tcx)); sess.time("abi_testing", || abi_test::test_abi(tcx)); + + // If `-Zvalidate-mir` is set, we also want to compute the final MIR for each item + // (either its `mir_for_ctfe` or `optimized_mir`) since that helps uncover any bugs + // in MIR optimizations that may only be reachable through codegen, or other codepaths + // that requires the optimized/ctfe MIR, such as polymorphization, coroutine bodies, + // or evaluating consts. + if tcx.sess.opts.unstable_opts.validate_mir { + sess.time("ensuring_final_MIR_is_computable", || { + tcx.hir().par_body_owners(|def_id| { + tcx.instance_mir(ty::InstanceKind::Item(def_id.into())); + }); + }); + } } /// Runs the type-checking, region checking and other miscellaneous analysis diff --git a/tests/crashes/121127.rs b/tests/crashes/121127.rs index 2e64bf68b82fb..e50dc7763fc65 100644 --- a/tests/crashes/121127.rs +++ b/tests/crashes/121127.rs @@ -1,5 +1,5 @@ //@ known-bug: #121127 -//@ compile-flags: -Zpolymorphize=on -Zinline-mir=yes -C debuginfo=2 +//@ compile-flags: -Zvalidate-mir -Zinline-mir=yes -C debuginfo=2 // Note that as of PR#123949 this only crashes with debuginfo enabled #![feature(specialization)] diff --git a/tests/crashes/122909.rs b/tests/crashes/122909.rs index 90bba772b915e..9d17ed83ea99b 100644 --- a/tests/crashes/122909.rs +++ b/tests/crashes/122909.rs @@ -1,4 +1,4 @@ -//@ compile-flags: -Zpolymorphize=on -Zinline-mir=yes +//@ compile-flags: -Zvalidate-mir -Zinline-mir=yes //@ known-bug: #122909 diff --git a/tests/crashes/126896.rs b/tests/crashes/126896.rs index 35bf9d5207ac1..49c539d7acc8a 100644 --- a/tests/crashes/126896.rs +++ b/tests/crashes/126896.rs @@ -1,5 +1,5 @@ //@ known-bug: rust-lang/rust#126896 -//@ compile-flags: -Zpolymorphize=on -Zinline-mir=yes +//@ compile-flags: -Zvalidate-mir -Zinline-mir=yes #![feature(type_alias_impl_trait)] type Two<'a, 'b> = impl std::fmt::Debug;