Skip to content

Commit 6b5869a

Browse files
committed
Add new -Z dump-mir-spanview option
Similar to `-Z dump-mir-graphviz`, this adds the option to write HTML+CSS files that allow users to analyze the spans associated with MIR elements (by individual statement, just terminator, or overall basic block). This PR was split out from PR rust-lang#76004, and exposes an API for spanview HTML+CSS files that is also used to analyze code regions chosen for coverage instrumentation (in a follow-on PR). Rust compiler MCP rust-lang/compiler-team#278 Relevant issue: rust-lang#34701 - Implement support for LLVMs code coverage instrumentation
1 parent 445f34b commit 6b5869a

11 files changed

+739
-0
lines changed

compiler/rustc_mir/src/util/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ mod alignment;
99
pub mod collect_writes;
1010
mod graphviz;
1111
pub(crate) mod pretty;
12+
pub(crate) mod spanview;
1213

1314
pub use self::aggregate::expand_aggregate;
1415
pub use self::alignment::is_disaligned;

compiler/rustc_mir/src/util/pretty.rs

+11
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use std::io::{self, Write};
66
use std::path::{Path, PathBuf};
77

88
use super::graphviz::write_mir_fn_graphviz;
9+
use super::spanview::write_mir_fn_spanview;
910
use crate::transform::MirSource;
1011
use either::Either;
1112
use rustc_data_structures::fx::FxHashMap;
@@ -147,6 +148,16 @@ fn dump_matched_mir_node<'tcx, F>(
147148
write_mir_fn_graphviz(tcx, source.def_id(), body, false, &mut file)?;
148149
};
149150
}
151+
152+
if let Some(spanview) = tcx.sess.opts.debugging_opts.dump_mir_spanview {
153+
let _: io::Result<()> = try {
154+
let mut file =
155+
create_dump_file(tcx, "html", pass_num, pass_name, disambiguator, source)?;
156+
if source.def_id().is_local() {
157+
write_mir_fn_spanview(tcx, source.def_id(), body, spanview, &mut file)?;
158+
}
159+
};
160+
}
150161
}
151162

152163
/// Returns the path to the filename where we should dump a given MIR.

0 commit comments

Comments
 (0)