Auto merge of #77581 - ecstatic-morse:dataflow-dump-mir-graphviz, r=davidtwco
Use `pretty::create_dump_file` for dumping dataflow results The old code wasn't incorporating promoteds into the path, meaning other `dot` files could get clobbered. Use the MIR dump infrastructure to generate paths so that this doesn't occur in the future.
This commit is contained in:
commit
382848989f
1 changed files with 24 additions and 24 deletions
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
use std::borrow::BorrowMut;
|
use std::borrow::BorrowMut;
|
||||||
use std::ffi::OsString;
|
use std::ffi::OsString;
|
||||||
use std::fs;
|
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
use rustc_ast as ast;
|
use rustc_ast as ast;
|
||||||
|
@ -12,7 +11,7 @@ use rustc_hir::def_id::DefId;
|
||||||
use rustc_index::bit_set::BitSet;
|
use rustc_index::bit_set::BitSet;
|
||||||
use rustc_index::vec::{Idx, IndexVec};
|
use rustc_index::vec::{Idx, IndexVec};
|
||||||
use rustc_middle::mir::{self, traversal, BasicBlock};
|
use rustc_middle::mir::{self, traversal, BasicBlock};
|
||||||
use rustc_middle::ty::{self, TyCtxt};
|
use rustc_middle::ty::TyCtxt;
|
||||||
use rustc_span::symbol::{sym, Symbol};
|
use rustc_span::symbol::{sym, Symbol};
|
||||||
|
|
||||||
use super::fmt::DebugWithContext;
|
use super::fmt::DebugWithContext;
|
||||||
|
@ -21,7 +20,7 @@ use super::{
|
||||||
visit_results, Analysis, Direction, GenKill, GenKillAnalysis, GenKillSet, JoinSemiLattice,
|
visit_results, Analysis, Direction, GenKill, GenKillAnalysis, GenKillSet, JoinSemiLattice,
|
||||||
ResultsCursor, ResultsVisitor,
|
ResultsCursor, ResultsVisitor,
|
||||||
};
|
};
|
||||||
use crate::util::pretty::dump_enabled;
|
use crate::util::pretty::{create_dump_file, dump_enabled};
|
||||||
|
|
||||||
/// A dataflow analysis that has converged to fixpoint.
|
/// A dataflow analysis that has converged to fixpoint.
|
||||||
pub struct Results<'tcx, A>
|
pub struct Results<'tcx, A>
|
||||||
|
@ -249,7 +248,7 @@ where
|
||||||
|
|
||||||
let res = write_graphviz_results(tcx, &body, &results, pass_name);
|
let res = write_graphviz_results(tcx, &body, &results, pass_name);
|
||||||
if let Err(e) = res {
|
if let Err(e) = res {
|
||||||
warn!("Failed to write graphviz dataflow results: {}", e);
|
error!("Failed to write graphviz dataflow results: {}", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
results
|
results
|
||||||
|
@ -270,6 +269,9 @@ where
|
||||||
A: Analysis<'tcx>,
|
A: Analysis<'tcx>,
|
||||||
A::Domain: DebugWithContext<A>,
|
A::Domain: DebugWithContext<A>,
|
||||||
{
|
{
|
||||||
|
use std::fs;
|
||||||
|
use std::io::{self, Write};
|
||||||
|
|
||||||
let def_id = body.source.def_id();
|
let def_id = body.source.def_id();
|
||||||
let attrs = match RustcMirAttrs::parse(tcx, def_id) {
|
let attrs = match RustcMirAttrs::parse(tcx, def_id) {
|
||||||
Ok(attrs) => attrs,
|
Ok(attrs) => attrs,
|
||||||
|
@ -278,27 +280,29 @@ where
|
||||||
Err(()) => return Ok(()),
|
Err(()) => return Ok(()),
|
||||||
};
|
};
|
||||||
|
|
||||||
let path = match attrs.output_path(A::NAME) {
|
let mut file = match attrs.output_path(A::NAME) {
|
||||||
Some(path) => path,
|
Some(path) => {
|
||||||
|
debug!("printing dataflow results for {:?} to {}", def_id, path.display());
|
||||||
|
if let Some(parent) = path.parent() {
|
||||||
|
fs::create_dir_all(parent)?;
|
||||||
|
}
|
||||||
|
io::BufWriter::new(fs::File::create(&path)?)
|
||||||
|
}
|
||||||
|
|
||||||
None if tcx.sess.opts.debugging_opts.dump_mir_dataflow
|
None if tcx.sess.opts.debugging_opts.dump_mir_dataflow
|
||||||
&& dump_enabled(tcx, A::NAME, def_id) =>
|
&& dump_enabled(tcx, A::NAME, def_id) =>
|
||||||
{
|
{
|
||||||
// FIXME: Use some variant of `pretty::dump_path` for this
|
create_dump_file(
|
||||||
let mut path = PathBuf::from(&tcx.sess.opts.debugging_opts.dump_mir_dir);
|
tcx,
|
||||||
|
".dot",
|
||||||
let crate_name = tcx.crate_name(def_id.krate);
|
None,
|
||||||
let item_name = ty::print::with_forced_impl_filename_line(|| {
|
A::NAME,
|
||||||
tcx.def_path(def_id).to_filename_friendly_no_crate()
|
&pass_name.unwrap_or("-----"),
|
||||||
});
|
body.source,
|
||||||
|
)?
|
||||||
let pass_name = pass_name.map(|s| format!(".{}", s)).unwrap_or_default();
|
|
||||||
|
|
||||||
path.push(format!("{}.{}.{}{}.dot", crate_name, item_name, A::NAME, pass_name));
|
|
||||||
path
|
|
||||||
}
|
}
|
||||||
|
|
||||||
None => return Ok(()),
|
_ => return Ok(()),
|
||||||
};
|
};
|
||||||
|
|
||||||
let style = match attrs.formatter {
|
let style = match attrs.formatter {
|
||||||
|
@ -306,7 +310,6 @@ where
|
||||||
_ => graphviz::OutputStyle::AfterOnly,
|
_ => graphviz::OutputStyle::AfterOnly,
|
||||||
};
|
};
|
||||||
|
|
||||||
debug!("printing dataflow results for {:?} to {}", def_id, path.display());
|
|
||||||
let mut buf = Vec::new();
|
let mut buf = Vec::new();
|
||||||
|
|
||||||
let graphviz = graphviz::Formatter::new(body, results, style);
|
let graphviz = graphviz::Formatter::new(body, results, style);
|
||||||
|
@ -317,10 +320,7 @@ where
|
||||||
}
|
}
|
||||||
dot::render_opts(&graphviz, &mut buf, &render_opts)?;
|
dot::render_opts(&graphviz, &mut buf, &render_opts)?;
|
||||||
|
|
||||||
if let Some(parent) = path.parent() {
|
file.write_all(&buf)?;
|
||||||
fs::create_dir_all(parent)?;
|
|
||||||
}
|
|
||||||
fs::write(&path, buf)?;
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue