1
Fork 0

refactor NLL MIR dump entry point

This commit is contained in:
Rémy Rakic 2024-08-28 18:12:16 +00:00
parent 92e1046502
commit f3f5b4dcf2
3 changed files with 23 additions and 15 deletions

View file

@ -229,7 +229,7 @@ fn do_mir_borrowck<'tcx>(
// Dump MIR results into a file, if that is enabled. This let us // Dump MIR results into a file, if that is enabled. This let us
// write unit-tests, as well as helping with debugging. // write unit-tests, as well as helping with debugging.
nll::dump_mir_results(&infcx, body, &regioncx, &opt_closure_req); nll::dump_nll_mir(&infcx, body, &regioncx, &opt_closure_req);
// We also have a `#[rustc_regions]` annotation that causes us to dump // We also have a `#[rustc_regions]` annotation that causes us to dump
// information. // information.

View file

@ -210,13 +210,23 @@ pub(crate) fn compute_regions<'cx, 'tcx>(
} }
} }
pub(super) fn dump_mir_results<'tcx>( /// `-Zdump-mir=nll` dumps MIR annotated with NLL specific information:
/// - free regions
/// - inferred region values
/// - region liveness
/// - inference constraints and their causes
///
/// As well as graphviz `.dot` visualizations of:
/// - the region constraints graph
/// - the region SCC graph
pub(super) fn dump_nll_mir<'tcx>(
infcx: &BorrowckInferCtxt<'tcx>, infcx: &BorrowckInferCtxt<'tcx>,
body: &Body<'tcx>, body: &Body<'tcx>,
regioncx: &RegionInferenceContext<'tcx>, regioncx: &RegionInferenceContext<'tcx>,
closure_region_requirements: &Option<ClosureRegionRequirements<'tcx>>, closure_region_requirements: &Option<ClosureRegionRequirements<'tcx>>,
) { ) {
if !dump_enabled(infcx.tcx, "nll", body.source.def_id()) { let tcx = infcx.tcx;
if !dump_enabled(tcx, "nll", body.source.def_id()) {
return; return;
} }
@ -230,7 +240,7 @@ pub(super) fn dump_mir_results<'tcx>(
), ),
}; };
dump_mir_with_options( dump_mir_with_options(
infcx.tcx, tcx,
false, false,
"nll", "nll",
&0, &0,
@ -239,16 +249,14 @@ pub(super) fn dump_mir_results<'tcx>(
match pass_where { match pass_where {
// Before the CFG, dump out the values for each region variable. // Before the CFG, dump out the values for each region variable.
PassWhere::BeforeCFG => { PassWhere::BeforeCFG => {
regioncx.dump_mir(infcx.tcx, out)?; regioncx.dump_mir(tcx, out)?;
writeln!(out, "|")?; writeln!(out, "|")?;
if let Some(closure_region_requirements) = closure_region_requirements { if let Some(closure_region_requirements) = closure_region_requirements {
writeln!(out, "| Free Region Constraints")?; writeln!(out, "| Free Region Constraints")?;
for_each_region_constraint( for_each_region_constraint(tcx, closure_region_requirements, &mut |msg| {
infcx.tcx, writeln!(out, "| {msg}")
closure_region_requirements, })?;
&mut |msg| writeln!(out, "| {msg}"),
)?;
writeln!(out, "|")?; writeln!(out, "|")?;
} }
} }
@ -264,15 +272,15 @@ pub(super) fn dump_mir_results<'tcx>(
options, options,
); );
// Also dump the inference graph constraints as a graphviz file. // Also dump the region constraint graph as a graphviz file.
let _: io::Result<()> = try { let _: io::Result<()> = try {
let mut file = create_dump_file(infcx.tcx, "regioncx.all.dot", false, "nll", &0, body)?; let mut file = create_dump_file(tcx, "regioncx.all.dot", false, "nll", &0, body)?;
regioncx.dump_graphviz_raw_constraints(&mut file)?; regioncx.dump_graphviz_raw_constraints(&mut file)?;
}; };
// Also dump the inference graph constraints as a graphviz file. // Also dump the region constraint SCC graph as a graphviz file.
let _: io::Result<()> = try { let _: io::Result<()> = try {
let mut file = create_dump_file(infcx.tcx, "regioncx.scc.dot", false, "nll", &0, body)?; let mut file = create_dump_file(tcx, "regioncx.scc.dot", false, "nll", &0, body)?;
regioncx.dump_graphviz_scc_constraints(&mut file)?; regioncx.dump_graphviz_scc_constraints(&mut file)?;
}; };
} }

View file

@ -46,7 +46,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
dot::render(&RawConstraints { regioncx: self }, &mut w) dot::render(&RawConstraints { regioncx: self }, &mut w)
} }
/// Write out the region constraint graph. /// Write out the region constraint SCC graph.
pub(crate) fn dump_graphviz_scc_constraints(&self, mut w: &mut dyn Write) -> io::Result<()> { pub(crate) fn dump_graphviz_scc_constraints(&self, mut w: &mut dyn Write) -> io::Result<()> {
let mut nodes_per_scc: IndexVec<ConstraintSccIndex, _> = let mut nodes_per_scc: IndexVec<ConstraintSccIndex, _> =
self.constraint_sccs.all_sccs().map(|_| Vec::new()).collect(); self.constraint_sccs.all_sccs().map(|_| Vec::new()).collect();