Skip to content

Commit 3293a0b

Browse files
committed
Introduce MirDumper and MirWriter.
MIR dumping is a mess. There are lots of functions and entry points, e.g. `dump_mir`, `dump_mir_with_options`, `dump_polonius_mir`, `dump_mir_to_writer`. Also, it's crucial that `create_dump_file` is never called without `dump_enabled` first being checked, but there is no mechanism for ensuring this and it's hard to tell if it is satisfied on all paths. (`dump_enabled` is checked twice on some paths, however!) This commit introduces `MirWriter`, which controls the MIR writing, and encapsulates the `extra_data` closure and `options`. Two existing functions are now methods of this type. It sets reasonable defaults, allowing the removal of many `|_, _| Ok(())` closures. The commit also introduces `MirDumper`, which is layered on top of `MirWriter`, and which manages the creation of the dump files, encapsulating pass names, disambiguators, etc. Four existing functions are now methods of this type. - `MirDumper::new` will only succeed if dumps are enabled, and will return `None` otherwise, which makes it impossible to dump when you shouldn't. - It also sets reasonable defaults for various things like disambiguators, which means you no longer need to specify them in many cases. When they do need to be specified, it's now done via setter methods. - It avoids some repetition. E.g. `dump_nll_mir` previously specifed the pass name `"nll"` four times and the disambiguator `&0` three times; now it specifies them just once, to put them in the `MirDumper`. - For Polonius, the `extra_data` closure can now be specified earlier, which avoids having to pass some arguments through some functions.
1 parent b494d3e commit 3293a0b

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

src/base.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,8 @@ pub(crate) fn codegen_fn<'tcx>(
4444
let _mir_guard = crate::PrintOnPanic(|| {
4545
let mut buf = Vec::new();
4646
with_no_trimmed_paths!({
47-
use rustc_middle::mir::pretty;
48-
let options = pretty::PrettyPrintMirOptions::from_cli(tcx);
49-
pretty::write_mir_fn(tcx, mir, &|_, _| Ok(()), &mut buf, options).unwrap();
47+
let writer = pretty::MirWriter::new(tcx);
48+
writer.write_mir_fn(mir, &mut buf).unwrap();
5049
});
5150
String::from_utf8_lossy(&buf).into_owned()
5251
});

0 commit comments

Comments
 (0)