extract main NLL MIR dump function
this will allow calling from polonius MIR
This commit is contained in:
parent
e7fb93bf9b
commit
ee93ce9c61
2 changed files with 47 additions and 34 deletions
|
@ -232,40 +232,7 @@ pub(super) fn dump_nll_mir<'tcx>(
|
||||||
&0,
|
&0,
|
||||||
body,
|
body,
|
||||||
|pass_where, out| {
|
|pass_where, out| {
|
||||||
match pass_where {
|
emit_nll_mir(tcx, regioncx, closure_region_requirements, borrow_set, pass_where, out)
|
||||||
// Before the CFG, dump out the values for each region variable.
|
|
||||||
PassWhere::BeforeCFG => {
|
|
||||||
regioncx.dump_mir(tcx, out)?;
|
|
||||||
writeln!(out, "|")?;
|
|
||||||
|
|
||||||
if let Some(closure_region_requirements) = closure_region_requirements {
|
|
||||||
writeln!(out, "| Free Region Constraints")?;
|
|
||||||
for_each_region_constraint(tcx, closure_region_requirements, &mut |msg| {
|
|
||||||
writeln!(out, "| {msg}")
|
|
||||||
})?;
|
|
||||||
writeln!(out, "|")?;
|
|
||||||
}
|
|
||||||
|
|
||||||
if borrow_set.len() > 0 {
|
|
||||||
writeln!(out, "| Borrows")?;
|
|
||||||
for (borrow_idx, borrow_data) in borrow_set.iter_enumerated() {
|
|
||||||
writeln!(
|
|
||||||
out,
|
|
||||||
"| {:?}: issued at {:?} in {:?}",
|
|
||||||
borrow_idx, borrow_data.reserve_location, borrow_data.region
|
|
||||||
)?;
|
|
||||||
}
|
|
||||||
writeln!(out, "|")?;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
PassWhere::BeforeLocation(_) => {}
|
|
||||||
|
|
||||||
PassWhere::AfterTerminator(_) => {}
|
|
||||||
|
|
||||||
PassWhere::BeforeBlock(_) | PassWhere::AfterLocation(_) | PassWhere::AfterCFG => {}
|
|
||||||
}
|
|
||||||
Ok(())
|
|
||||||
},
|
},
|
||||||
options,
|
options,
|
||||||
);
|
);
|
||||||
|
@ -283,6 +250,51 @@ pub(super) fn dump_nll_mir<'tcx>(
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Produces the actual NLL MIR sections to emit during the dumping process.
|
||||||
|
pub(crate) fn emit_nll_mir<'tcx>(
|
||||||
|
tcx: TyCtxt<'tcx>,
|
||||||
|
regioncx: &RegionInferenceContext<'tcx>,
|
||||||
|
closure_region_requirements: &Option<ClosureRegionRequirements<'tcx>>,
|
||||||
|
borrow_set: &BorrowSet<'tcx>,
|
||||||
|
pass_where: PassWhere,
|
||||||
|
out: &mut dyn io::Write,
|
||||||
|
) -> io::Result<()> {
|
||||||
|
match pass_where {
|
||||||
|
// Before the CFG, dump out the values for each region variable.
|
||||||
|
PassWhere::BeforeCFG => {
|
||||||
|
regioncx.dump_mir(tcx, out)?;
|
||||||
|
writeln!(out, "|")?;
|
||||||
|
|
||||||
|
if let Some(closure_region_requirements) = closure_region_requirements {
|
||||||
|
writeln!(out, "| Free Region Constraints")?;
|
||||||
|
for_each_region_constraint(tcx, closure_region_requirements, &mut |msg| {
|
||||||
|
writeln!(out, "| {msg}")
|
||||||
|
})?;
|
||||||
|
writeln!(out, "|")?;
|
||||||
|
}
|
||||||
|
|
||||||
|
if borrow_set.len() > 0 {
|
||||||
|
writeln!(out, "| Borrows")?;
|
||||||
|
for (borrow_idx, borrow_data) in borrow_set.iter_enumerated() {
|
||||||
|
writeln!(
|
||||||
|
out,
|
||||||
|
"| {:?}: issued at {:?} in {:?}",
|
||||||
|
borrow_idx, borrow_data.reserve_location, borrow_data.region
|
||||||
|
)?;
|
||||||
|
}
|
||||||
|
writeln!(out, "|")?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
PassWhere::BeforeLocation(_) => {}
|
||||||
|
|
||||||
|
PassWhere::AfterTerminator(_) => {}
|
||||||
|
|
||||||
|
PassWhere::BeforeBlock(_) | PassWhere::AfterLocation(_) | PassWhere::AfterCFG => {}
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
#[allow(rustc::diagnostic_outside_of_impl)]
|
#[allow(rustc::diagnostic_outside_of_impl)]
|
||||||
#[allow(rustc::untranslatable_diagnostic)]
|
#[allow(rustc::untranslatable_diagnostic)]
|
||||||
pub(super) fn dump_annotation<'tcx, 'infcx>(
|
pub(super) fn dump_annotation<'tcx, 'infcx>(
|
||||||
|
|
|
@ -23,6 +23,7 @@ pub(crate) const ALIGN: usize = 40;
|
||||||
|
|
||||||
/// An indication of where we are in the control flow graph. Used for printing
|
/// An indication of where we are in the control flow graph. Used for printing
|
||||||
/// extra information in `dump_mir`
|
/// extra information in `dump_mir`
|
||||||
|
#[derive(Clone)]
|
||||||
pub enum PassWhere {
|
pub enum PassWhere {
|
||||||
/// We have not started dumping the control flow graph, but we are about to.
|
/// We have not started dumping the control flow graph, but we are about to.
|
||||||
BeforeCFG,
|
BeforeCFG,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue