Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add -Z dump-mir-dataflow flag for dumping dataflow results visualization #70511

Merged
merged 4 commits into from
Apr 1, 2020
Merged
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
2 changes: 2 additions & 0 deletions src/librustc_interface/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,8 @@ fn test_debugging_options_tracking_hash() {
assert_eq!(reference.dep_tracking_hash(), opts.dep_tracking_hash());
opts.debugging_opts.dump_mir_graphviz = true;
assert_eq!(reference.dep_tracking_hash(), opts.dep_tracking_hash());
opts.debugging_opts.dump_mir_dataflow = true;
assert_eq!(reference.dep_tracking_hash(), opts.dep_tracking_hash());

// Make sure changing a [TRACKED] option changes the hash
opts = reference.clone();
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/borrow_check/nll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ pub(super) fn dump_mir_results<'a, 'tcx>(
regioncx: &RegionInferenceContext<'_>,
closure_region_requirements: &Option<ClosureRegionRequirements<'_>>,
) {
if !mir_util::dump_enabled(infcx.tcx, "nll", source) {
if !mir_util::dump_enabled(infcx.tcx, "nll", source.def_id()) {
return;
}

Expand Down
21 changes: 20 additions & 1 deletion src/librustc_mir/dataflow/framework/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use rustc_span::symbol::{sym, Symbol};

use super::graphviz;
use super::{Analysis, GenKillAnalysis, GenKillSet, Results};
use crate::util::pretty::dump_enabled;

/// A solver for dataflow problems.
pub struct Engine<'a, 'tcx, A>
Expand Down Expand Up @@ -400,12 +401,25 @@ where
let attrs = match RustcMirAttrs::parse(tcx, def_id) {
Ok(attrs) => attrs,

// Invalid `rustc_mir` attrs will be reported using `span_err`.
// Invalid `rustc_mir` attrs are reported in `RustcMirAttrs::parse`
Err(()) => return Ok(()),
};

let path = match attrs.output_path(A::NAME) {
Some(path) => path,

None if tcx.sess.opts.debugging_opts.dump_mir_dataflow
&& dump_enabled(tcx, A::NAME, def_id) =>
{
let mut path = PathBuf::from(&tcx.sess.opts.debugging_opts.dump_mir_dir);

let item_name = ty::print::with_forced_impl_filename_line(|| {
tcx.def_path(def_id).to_filename_friendly_no_crate()
});
path.push(format!("rustc.{}.{}.dot", item_name, A::NAME));
path
}

None => return Ok(()),
};

Expand All @@ -430,7 +444,12 @@ where

let graphviz = graphviz::Formatter::new(body, def_id, results, &mut *formatter);
dot::render_opts(&graphviz, &mut buf, &[dot::RenderOption::Monospace])?;

if let Some(parent) = path.parent() {
fs::create_dir_all(parent)?;
}
fs::write(&path, buf)?;

Ok(())
}

Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/transform/dump_mir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pub fn on_mir_pass<'tcx>(
body: &Body<'tcx>,
is_after: bool,
) {
if mir_util::dump_enabled(tcx, pass_name, source) {
if mir_util::dump_enabled(tcx, pass_name, source.def_id()) {
mir_util::dump_mir(
tcx,
Some(pass_num),
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/util/liveness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ pub fn dump_mir<'tcx>(
body: &Body<'tcx>,
result: &LivenessResult,
) {
if !dump_enabled(tcx, pass_name, source) {
if !dump_enabled(tcx, pass_name, source.def_id()) {
return;
}
let node_path = ty::print::with_forced_impl_filename_line(|| {
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_mir/util/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,21 +76,21 @@ pub fn dump_mir<'tcx, F>(
) where
F: FnMut(PassWhere, &mut dyn Write) -> io::Result<()>,
{
if !dump_enabled(tcx, pass_name, source) {
if !dump_enabled(tcx, pass_name, source.def_id()) {
return;
}

dump_matched_mir_node(tcx, pass_num, pass_name, disambiguator, source, body, extra_data);
}

pub fn dump_enabled<'tcx>(tcx: TyCtxt<'tcx>, pass_name: &str, source: MirSource<'tcx>) -> bool {
pub fn dump_enabled<'tcx>(tcx: TyCtxt<'tcx>, pass_name: &str, def_id: DefId) -> bool {
let filters = match tcx.sess.opts.debugging_opts.dump_mir {
None => return false,
Some(ref filters) => filters,
};
let node_path = ty::print::with_forced_impl_filename_line(|| {
// see notes on #41697 below
tcx.def_path_str(source.def_id())
tcx.def_path_str(def_id)
});
filters.split('|').any(|or_filter| {
or_filter.split('&').all(|and_filter| {
Expand Down
2 changes: 2 additions & 0 deletions src/librustc_session/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -837,6 +837,8 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
"the directory the MIR is dumped into"),
dump_mir_graphviz: bool = (false, parse_bool, [UNTRACKED],
"in addition to `.mir` files, create graphviz `.dot` files"),
dump_mir_dataflow: bool = (false, parse_bool, [UNTRACKED],
"in addition to `.mir` files, create graphviz `.dot` files with dataflow results"),
dump_mir_exclude_pass_number: bool = (false, parse_bool, [UNTRACKED],
"if set, exclude the pass number when dumping MIR (used in tests)"),
mir_emit_retag: bool = (false, parse_bool, [TRACKED],
Expand Down