Skip to content

Commit c978cbe

Browse files
Rollup merge of rust-lang#156524 - Zalathar:no-pre-codegen, r=oli-obk
Remove the dummy `PreCodegen` mir-opt pass, and use `runtime-optimized` instead - Alternative to rust-lang#156358. The `PreCodegen` pass doesn't do anything on its own; it was only serving as a marker to allow `-Zdump-mir` and mir-opt tests to easily dump the final MIR just before codegen. However, rust-lang#156358 (comment) pointed out that the `runtime-optimized` phase transition should dump the same MIR, so there shouldn't be any need for a separate *PreCodegen* pass. --- r? oli-obk (or compiler)
2 parents 91b85f6 + 281ccf8 commit c978cbe

185 files changed

Lines changed: 243 additions & 269 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Cargo.lock

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3922,7 +3922,6 @@ dependencies = [
39223922
"rustc_metadata",
39233923
"rustc_middle",
39243924
"rustc_mir_build",
3925-
"rustc_mir_transform",
39263925
"rustc_parse",
39273926
"rustc_public",
39283927
"rustc_resolve",

compiler/rustc_driver_impl/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ rustc_macros = { path = "../rustc_macros" }
2727
rustc_metadata = { path = "../rustc_metadata" }
2828
rustc_middle = { path = "../rustc_middle" }
2929
rustc_mir_build = { path = "../rustc_mir_build" }
30-
rustc_mir_transform = { path = "../rustc_mir_transform" }
3130
rustc_parse = { path = "../rustc_parse" }
3231
rustc_public = { path = "../rustc_public", features = ["rustc_internal"] }
3332
rustc_resolve = { path = "../rustc_resolve" }

compiler/rustc_driver_impl/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
77
// tidy-alphabetical-start
88
#![feature(decl_macro)]
9+
#![feature(file_buffered)]
910
#![feature(panic_backtrace_config)]
1011
#![feature(panic_update_hook)]
1112
#![feature(trim_prefix_suffix)]
@@ -333,7 +334,7 @@ pub fn run_compiler(at_args: &[String], callbacks: &mut (dyn Callbacks + Send))
333334
}
334335

335336
if tcx.sess.opts.output_types.contains_key(&OutputType::Mir) {
336-
if let Err(error) = rustc_mir_transform::dump_mir::emit_mir(tcx) {
337+
if let Err(error) = pretty::emit_mir(tcx) {
337338
tcx.dcx().emit_fatal(CantEmitMIR { error });
338339
}
339340
}

compiler/rustc_driver_impl/src/pretty.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
33
use std::cell::Cell;
44
use std::fmt::Write;
5+
use std::fs::File;
6+
use std::io;
57

68
use rustc_ast as ast;
79
use rustc_ast_pretty::pprust as pprust_ast;
@@ -12,7 +14,7 @@ use rustc_middle::ty::{self, TyCtxt};
1214
use rustc_mir_build::thir::print::{thir_flat, thir_tree};
1315
use rustc_public::rustc_internal::pretty::write_smir_pretty;
1416
use rustc_session::Session;
15-
use rustc_session::config::{OutFileName, PpHirMode, PpMode, PpSourceMode};
17+
use rustc_session::config::{OutFileName, OutputType, PpHirMode, PpMode, PpSourceMode};
1618
use rustc_span::{FileName, Ident};
1719
use tracing::debug;
1820

@@ -340,3 +342,21 @@ pub fn print<'tcx>(sess: &Session, ppm: PpMode, ex: PrintExtra<'tcx>) {
340342

341343
write_or_print(&out, sess);
342344
}
345+
346+
/// Implementation of `--emit=mir`.
347+
pub fn emit_mir(tcx: TyCtxt<'_>) -> io::Result<()> {
348+
match tcx.output_filenames(()).path(OutputType::Mir) {
349+
OutFileName::Stdout => {
350+
let mut f = io::stdout();
351+
write_mir_pretty(tcx, &mut f)?;
352+
}
353+
OutFileName::Real(path) => {
354+
let mut f = File::create_buffered(&path)?;
355+
write_mir_pretty(tcx, &mut f)?;
356+
if tcx.sess.opts.json_artifact_notifications {
357+
tcx.dcx().emit_artifact_notification(&path, "mir");
358+
}
359+
}
360+
}
361+
Ok(())
362+
}

compiler/rustc_mir_transform/src/dump_mir.rs

Lines changed: 0 additions & 39 deletions
This file was deleted.

compiler/rustc_mir_transform/src/lib.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
#![feature(box_patterns)]
33
#![feature(const_type_name)]
44
#![feature(cow_is_borrowed)]
5-
#![feature(file_buffered)]
65
#![feature(impl_trait_in_assoc_type)]
76
#![feature(iterator_try_collect)]
87
#![feature(try_blocks)]
@@ -91,8 +90,6 @@ macro_rules! declare_passes {
9190

9291
static PASS_NAMES: LazyLock<FxIndexSet<&str>> = LazyLock::new(|| {
9392
let mut set = FxIndexSet::default();
94-
// Fake marker pass
95-
set.insert("PreCodegen");
9693
$(
9794
$(
9895
set.extend(pass_names!($mod_name : $pass_name $( { $($ident),* } )? ));
@@ -145,7 +142,6 @@ declare_passes! {
145142
};
146143
mod deref_separator : Derefer;
147144
mod dest_prop : DestinationPropagation;
148-
pub mod dump_mir : Marker;
149145
mod early_otherwise_branch : EarlyOtherwiseBranch;
150146
mod erase_deref_temps : EraseDerefTemps;
151147
mod elaborate_box_derefs : ElaborateBoxDerefs;
@@ -771,8 +767,6 @@ pub(crate) fn run_optimization_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'
771767
// Cleanup for human readability, off by default.
772768
&prettify::ReorderBasicBlocks,
773769
&prettify::ReorderLocals,
774-
// Dump the end result for testing and debugging purposes.
775-
&dump_mir::Marker("PreCodegen"),
776770
],
777771
Some(MirPhase::Runtime(RuntimePhase::Optimized)),
778772
optimizations,

tests/mir-opt/building/match/deref-patterns/string.foo.PreCodegen.after.mir renamed to tests/mir-opt/building/match/deref-patterns/string.foo.runtime-optimized.after.mir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// MIR for `foo` after PreCodegen
1+
// MIR for `foo` after runtime-optimized
22

33
fn foo(_1: Option<String>) -> i32 {
44
debug s => _1;

tests/mir-opt/building/match/deref-patterns/string.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#![feature(deref_patterns)]
55
#![crate_type = "lib"]
66

7-
// EMIT_MIR string.foo.PreCodegen.after.mir
7+
// EMIT_MIR string.foo.runtime-optimized.after.mir
88
pub fn foo(s: Option<String>) -> i32 {
99
match s {
1010
Some("a") => 1234,

tests/mir-opt/building/while_storage.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ fn get_bool(c: bool) -> bool {
77
c
88
}
99

10-
// EMIT_MIR while_storage.while_loop.PreCodegen.after.mir
10+
// EMIT_MIR while_storage.while_loop.runtime-optimized.after.mir
1111
fn while_loop(c: bool) {
1212
// CHECK-LABEL: fn while_loop(
1313
// CHECK: bb0: {

tests/mir-opt/building/while_storage.while_loop.PreCodegen.after.panic-abort.mir renamed to tests/mir-opt/building/while_storage.while_loop.runtime-optimized.after.panic-abort.mir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// MIR for `while_loop` after PreCodegen
1+
// MIR for `while_loop` after runtime-optimized
22

33
fn while_loop(_1: bool) -> () {
44
debug c => _1;

0 commit comments

Comments
 (0)