Skip to content

Commit ee93ce9

Browse files
committed
extract main NLL MIR dump function
this will allow calling from polonius MIR
1 parent e7fb93b commit ee93ce9

File tree

2 files changed

+47
-34
lines changed

2 files changed

+47
-34
lines changed

compiler/rustc_borrowck/src/nll.rs

+46-34
Original file line numberDiff line numberDiff line change
@@ -232,40 +232,7 @@ pub(super) fn dump_nll_mir<'tcx>(
232232
&0,
233233
body,
234234
|pass_where, out| {
235-
match pass_where {
236-
// Before the CFG, dump out the values for each region variable.
237-
PassWhere::BeforeCFG => {
238-
regioncx.dump_mir(tcx, out)?;
239-
writeln!(out, "|")?;
240-
241-
if let Some(closure_region_requirements) = closure_region_requirements {
242-
writeln!(out, "| Free Region Constraints")?;
243-
for_each_region_constraint(tcx, closure_region_requirements, &mut |msg| {
244-
writeln!(out, "| {msg}")
245-
})?;
246-
writeln!(out, "|")?;
247-
}
248-
249-
if borrow_set.len() > 0 {
250-
writeln!(out, "| Borrows")?;
251-
for (borrow_idx, borrow_data) in borrow_set.iter_enumerated() {
252-
writeln!(
253-
out,
254-
"| {:?}: issued at {:?} in {:?}",
255-
borrow_idx, borrow_data.reserve_location, borrow_data.region
256-
)?;
257-
}
258-
writeln!(out, "|")?;
259-
}
260-
}
261-
262-
PassWhere::BeforeLocation(_) => {}
263-
264-
PassWhere::AfterTerminator(_) => {}
265-
266-
PassWhere::BeforeBlock(_) | PassWhere::AfterLocation(_) | PassWhere::AfterCFG => {}
267-
}
268-
Ok(())
235+
emit_nll_mir(tcx, regioncx, closure_region_requirements, borrow_set, pass_where, out)
269236
},
270237
options,
271238
);
@@ -283,6 +250,51 @@ pub(super) fn dump_nll_mir<'tcx>(
283250
};
284251
}
285252

253+
/// Produces the actual NLL MIR sections to emit during the dumping process.
254+
pub(crate) fn emit_nll_mir<'tcx>(
255+
tcx: TyCtxt<'tcx>,
256+
regioncx: &RegionInferenceContext<'tcx>,
257+
closure_region_requirements: &Option<ClosureRegionRequirements<'tcx>>,
258+
borrow_set: &BorrowSet<'tcx>,
259+
pass_where: PassWhere,
260+
out: &mut dyn io::Write,
261+
) -> io::Result<()> {
262+
match pass_where {
263+
// Before the CFG, dump out the values for each region variable.
264+
PassWhere::BeforeCFG => {
265+
regioncx.dump_mir(tcx, out)?;
266+
writeln!(out, "|")?;
267+
268+
if let Some(closure_region_requirements) = closure_region_requirements {
269+
writeln!(out, "| Free Region Constraints")?;
270+
for_each_region_constraint(tcx, closure_region_requirements, &mut |msg| {
271+
writeln!(out, "| {msg}")
272+
})?;
273+
writeln!(out, "|")?;
274+
}
275+
276+
if borrow_set.len() > 0 {
277+
writeln!(out, "| Borrows")?;
278+
for (borrow_idx, borrow_data) in borrow_set.iter_enumerated() {
279+
writeln!(
280+
out,
281+
"| {:?}: issued at {:?} in {:?}",
282+
borrow_idx, borrow_data.reserve_location, borrow_data.region
283+
)?;
284+
}
285+
writeln!(out, "|")?;
286+
}
287+
}
288+
289+
PassWhere::BeforeLocation(_) => {}
290+
291+
PassWhere::AfterTerminator(_) => {}
292+
293+
PassWhere::BeforeBlock(_) | PassWhere::AfterLocation(_) | PassWhere::AfterCFG => {}
294+
}
295+
Ok(())
296+
}
297+
286298
#[allow(rustc::diagnostic_outside_of_impl)]
287299
#[allow(rustc::untranslatable_diagnostic)]
288300
pub(super) fn dump_annotation<'tcx, 'infcx>(

compiler/rustc_middle/src/mir/pretty.rs

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ pub(crate) const ALIGN: usize = 40;
2323

2424
/// An indication of where we are in the control flow graph. Used for printing
2525
/// extra information in `dump_mir`
26+
#[derive(Clone)]
2627
pub enum PassWhere {
2728
/// We have not started dumping the control flow graph, but we are about to.
2829
BeforeCFG,

0 commit comments

Comments
 (0)