Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3830,7 +3830,6 @@ dependencies = [
"rustc_metadata",
"rustc_middle",
"rustc_mir_build",
"rustc_mir_transform",
"rustc_parse",
"rustc_public",
"rustc_resolve",
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_driver_impl/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ rustc_macros = { path = "../rustc_macros" }
rustc_metadata = { path = "../rustc_metadata" }
rustc_middle = { path = "../rustc_middle" }
rustc_mir_build = { path = "../rustc_mir_build" }
rustc_mir_transform = { path = "../rustc_mir_transform" }
rustc_parse = { path = "../rustc_parse" }
rustc_public = { path = "../rustc_public", features = ["rustc_internal"] }
rustc_resolve = { path = "../rustc_resolve" }
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_driver_impl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
// tidy-alphabetical-start
#![feature(decl_macro)]
#![feature(file_buffered)]
#![feature(panic_backtrace_config)]
#![feature(panic_update_hook)]
#![feature(trim_prefix_suffix)]
Expand Down Expand Up @@ -333,7 +334,7 @@ pub fn run_compiler(at_args: &[String], callbacks: &mut (dyn Callbacks + Send))
}

if tcx.sess.opts.output_types.contains_key(&OutputType::Mir) {
if let Err(error) = rustc_mir_transform::dump_mir::emit_mir(tcx) {
if let Err(error) = pretty::emit_mir(tcx) {
tcx.dcx().emit_fatal(CantEmitMIR { error });
}
}
Expand Down
22 changes: 21 additions & 1 deletion compiler/rustc_driver_impl/src/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

use std::cell::Cell;
use std::fmt::Write;
use std::fs::File;
use std::io;

use rustc_ast as ast;
use rustc_ast_pretty::pprust as pprust_ast;
Expand All @@ -12,7 +14,7 @@ use rustc_middle::ty::{self, TyCtxt};
use rustc_mir_build::thir::print::{thir_flat, thir_tree};
use rustc_public::rustc_internal::pretty::write_smir_pretty;
use rustc_session::Session;
use rustc_session::config::{OutFileName, PpHirMode, PpMode, PpSourceMode};
use rustc_session::config::{OutFileName, OutputType, PpHirMode, PpMode, PpSourceMode};
use rustc_span::{FileName, Ident};
use tracing::debug;

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

write_or_print(&out, sess);
}

/// Implementation of `--emit=mir`.
pub(crate) fn emit_mir(tcx: TyCtxt<'_>) -> io::Result<()> {
match tcx.output_filenames(()).path(OutputType::Mir) {
OutFileName::Stdout => {
let mut f = io::stdout();
write_mir_pretty(tcx, None, &mut f)?;
}
OutFileName::Real(path) => {
let mut f = File::create_buffered(&path)?;
write_mir_pretty(tcx, None, &mut f)?;
if tcx.sess.opts.json_artifact_notifications {
tcx.dcx().emit_artifact_notification(&path, "mir");
}
}
}
Ok(())
}
39 changes: 0 additions & 39 deletions compiler/rustc_mir_transform/src/dump_mir.rs

This file was deleted.

10 changes: 4 additions & 6 deletions compiler/rustc_mir_transform/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#![feature(box_patterns)]
#![feature(const_type_name)]
#![feature(cow_is_borrowed)]
#![feature(file_buffered)]
#![feature(impl_trait_in_assoc_type)]
#![feature(iterator_try_collect)]
#![feature(try_blocks)]
Expand Down Expand Up @@ -91,8 +90,6 @@ macro_rules! declare_passes {

static PASS_NAMES: LazyLock<FxIndexSet<&str>> = LazyLock::new(|| {
let mut set = FxIndexSet::default();
// Fake marker pass
set.insert("PreCodegen");
$(
$(
set.extend(pass_names!($mod_name : $pass_name $( { $($ident),* } )? ));
Expand Down Expand Up @@ -145,7 +142,6 @@ declare_passes! {
};
mod deref_separator : Derefer;
mod dest_prop : DestinationPropagation;
pub mod dump_mir : Marker;
mod early_otherwise_branch : EarlyOtherwiseBranch;
mod erase_deref_temps : EraseDerefTemps;
mod elaborate_box_derefs : ElaborateBoxDerefs;
Expand All @@ -162,6 +158,7 @@ declare_passes! {
mod large_enums : EnumSizeOpt;
mod lower_intrinsics : LowerIntrinsics;
mod lower_slice_len : LowerSliceLenCalls;
mod marker : PreCodegen;
mod match_branches : MatchBranchSimplification;
mod mentioned_items : MentionedItems;
mod multiple_return_terminators : MultipleReturnTerminators;
Expand Down Expand Up @@ -771,8 +768,9 @@ pub(crate) fn run_optimization_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'
// Cleanup for human readability, off by default.
&prettify::ReorderBasicBlocks,
&prettify::ReorderLocals,
// Dump the end result for testing and debugging purposes.
&dump_mir::Marker("PreCodegen"),
// Dummy pass to allow dumping the final pre-codegen MIR for testing/debugging.
// This must be the final pass!
&marker::PreCodegen,
],
Some(MirPhase::Runtime(RuntimePhase::Optimized)),
optimizations,
Expand Down
20 changes: 20 additions & 0 deletions compiler/rustc_mir_transform/src/marker.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
use rustc_middle::mir::Body;
use rustc_middle::ty::TyCtxt;

/// Dummy pass that does nothing, to be used as the final pass.
///
/// Its existence allows `-Zdump-mir` and mir-opt tests to easily dump
/// the final MIR just before codegen, by dumping the input or output
/// of the `PreCodegen` pass.
pub(super) struct PreCodegen;

impl<'tcx> crate::MirPass<'tcx> for PreCodegen {
fn run_pass(&self, _tcx: TyCtxt<'tcx>, _body: &mut Body<'tcx>) {
// This is a dummy pass, so the pass itself doesn't do anything.
// Dumping is performed by the normal `-Zdump-mir` machinery.
}

fn is_required(&self) -> bool {
false
}
}
Loading