From 4d85f3e671ee850f5e71d2eb794c173d5996645a Mon Sep 17 00:00:00 2001 From: Ben Kimock Date: Fri, 25 Oct 2024 13:11:48 -0400 Subject: [PATCH] Remove the new MIR phase, because codegen_mir may return normal instance_mir --- compiler/rustc_middle/src/mir/mod.rs | 1 - compiler/rustc_middle/src/mir/syntax.rs | 2 -- compiler/rustc_mir_transform/src/lib.rs | 10 ++-------- compiler/rustc_mir_transform/src/pass_manager.rs | 5 +---- compiler/rustc_mir_transform/src/validate.rs | 2 +- tests/ui/mir/validate/critical-edge.rs | 2 +- tests/ui/recursion_limit/zero-overflow.rs | 2 +- tests/ui/recursion_limit/zero-overflow.stderr | 2 +- 8 files changed, 7 insertions(+), 19 deletions(-) diff --git a/compiler/rustc_middle/src/mir/mod.rs b/compiler/rustc_middle/src/mir/mod.rs index c251a3ae8ce56..cd148aef29ba8 100644 --- a/compiler/rustc_middle/src/mir/mod.rs +++ b/compiler/rustc_middle/src/mir/mod.rs @@ -159,7 +159,6 @@ impl RuntimePhase { "initial" => Self::Initial, "post_cleanup" | "post-cleanup" | "postcleanup" => Self::PostCleanup, "optimized" => Self::Optimized, - "codegen" => Self::Codegen, _ => bug!("Unknown runtime phase: '{}'", phase), } } diff --git a/compiler/rustc_middle/src/mir/syntax.rs b/compiler/rustc_middle/src/mir/syntax.rs index e71b6b140a2dc..c610fac80f68f 100644 --- a/compiler/rustc_middle/src/mir/syntax.rs +++ b/compiler/rustc_middle/src/mir/syntax.rs @@ -99,7 +99,6 @@ impl MirPhase { MirPhase::Runtime(RuntimePhase::Initial) => "runtime", MirPhase::Runtime(RuntimePhase::PostCleanup) => "runtime-post-cleanup", MirPhase::Runtime(RuntimePhase::Optimized) => "runtime-optimized", - MirPhase::Runtime(RuntimePhase::Codegen) => "codegen", } } @@ -154,7 +153,6 @@ pub enum RuntimePhase { /// * [`ProjectionElem::Deref`] of `Box` PostCleanup = 1, Optimized = 2, - Codegen = 3, } /////////////////////////////////////////////////////////////////////////// diff --git a/compiler/rustc_mir_transform/src/lib.rs b/compiler/rustc_mir_transform/src/lib.rs index 69c62105151fb..d7ddd8e19435c 100644 --- a/compiler/rustc_mir_transform/src/lib.rs +++ b/compiler/rustc_mir_transform/src/lib.rs @@ -743,17 +743,11 @@ pub fn build_codegen_mir<'tcx>(tcx: TyCtxt<'tcx>, instance: Instance<'tcx>) -> B let body = clone_mir(body); let mut body = monomorphize_mir(tcx, instance, body); - pm::run_passes( + pm::run_passes_no_validate( tcx, ty::ParamEnv::reveal_all(), &mut body, &[ - // Validation calls layout::fn_can_unwind to figure out if a function can unwind, which - // always returns false if the current crate is compiled with -Cpanic=abort. So when - // a crate with panic=abort compiles MIR from a panic=unwind crate, we get validation - // failures. So we rely on the fact that validation only runs after passes? It's - // probably better to just delete that validation check. - &abort_unwinding_calls::AbortUnwindingCalls, &gvn::GVN::PostMono, // FIXME: Enabling this InstSimplify is required to fix the MIR from the // unreachable_unchecked precondition check that UnreachablePropagation creates, but @@ -764,7 +758,7 @@ pub fn build_codegen_mir<'tcx>(tcx: TyCtxt<'tcx>, instance: Instance<'tcx>) -> B &o1(simplify::SimplifyCfg::PostMono), &add_call_guards::CriticalCallEdges, ], - Some(MirPhase::Runtime(RuntimePhase::Codegen)), + None, ); body } diff --git a/compiler/rustc_mir_transform/src/pass_manager.rs b/compiler/rustc_mir_transform/src/pass_manager.rs index b603b30f20398..fc77e72ac47b2 100644 --- a/compiler/rustc_mir_transform/src/pass_manager.rs +++ b/compiler/rustc_mir_transform/src/pass_manager.rs @@ -255,10 +255,7 @@ fn run_passes_inner<'tcx>( let validate = (validate_each & tcx.sess.opts.unstable_opts.validate_mir & !body.should_skip()) - || matches!( - new_phase, - MirPhase::Runtime(RuntimePhase::Optimized | RuntimePhase::Codegen) - ); + || matches!(new_phase, MirPhase::Runtime(RuntimePhase::Optimized)); let lint = tcx.sess.opts.unstable_opts.lint_mir & !body.should_skip(); if validate { validate_body( diff --git a/compiler/rustc_mir_transform/src/validate.rs b/compiler/rustc_mir_transform/src/validate.rs index 603cec8fc2f35..88c5fd1d7e6d3 100644 --- a/compiler/rustc_mir_transform/src/validate.rs +++ b/compiler/rustc_mir_transform/src/validate.rs @@ -395,7 +395,7 @@ impl<'a, 'tcx> Visitor<'tcx> for CfgChecker<'a, 'tcx> { // the return edge from the call. FIXME(tmiasko): Since this is a strictly code // generation concern, the code generation should be responsible for handling // it. - if self.mir_phase >= MirPhase::Runtime(RuntimePhase::Codegen) + if self.mir_phase >= MirPhase::Runtime(RuntimePhase::Optimized) && self.is_critical_call_edge(target, unwind) { self.fail( diff --git a/tests/ui/mir/validate/critical-edge.rs b/tests/ui/mir/validate/critical-edge.rs index 36b9779bc9d18..4d756599e6af2 100644 --- a/tests/ui/mir/validate/critical-edge.rs +++ b/tests/ui/mir/validate/critical-edge.rs @@ -9,7 +9,7 @@ #![feature(custom_mir, core_intrinsics)] use std::intrinsics::mir::*; -#[custom_mir(dialect = "runtime", phase = "codegen")] +#[custom_mir(dialect = "runtime", phase = "optimized")] #[inline(never)] // Force codegen so we go through codegen MIR validation pub fn f(a: u32) -> u32 { mir! { diff --git a/tests/ui/recursion_limit/zero-overflow.rs b/tests/ui/recursion_limit/zero-overflow.rs index 6b9ed5b2c5ee7..3887972a51623 100644 --- a/tests/ui/recursion_limit/zero-overflow.rs +++ b/tests/ui/recursion_limit/zero-overflow.rs @@ -1,4 +1,4 @@ -//~ ERROR overflow evaluating the requirement `{closure@rt::lang_start<()>::{closure#0}}: Unsize i32 + Sync + RefUnwindSafe>` +//~ ERROR overflow evaluating the requirement `&mut Self: DispatchFromDyn<&mut RustaceansAreAwesome> //~| HELP consider increasing the recursion limit //@ build-fail diff --git a/tests/ui/recursion_limit/zero-overflow.stderr b/tests/ui/recursion_limit/zero-overflow.stderr index 913803a8b34cf..fc03cc5b604b7 100644 --- a/tests/ui/recursion_limit/zero-overflow.stderr +++ b/tests/ui/recursion_limit/zero-overflow.stderr @@ -1,4 +1,4 @@ -error[E0275]: overflow evaluating the requirement `{closure@rt::lang_start<()>::{closure#0}}: Unsize i32 + Sync + RefUnwindSafe>` +error[E0275]: overflow evaluating the requirement `&mut Self: DispatchFromDyn<&mut RustaceansAreAwesome>` | = help: consider increasing the recursion limit by adding a `#![recursion_limit = "2"]` attribute to your crate (`zero_overflow`)