Skip to content

Commit 3631c15

Browse files
committed
use more explicit MIR dumping process
1 parent 492d985 commit 3631c15

File tree

1 file changed

+36
-4
lines changed
  • compiler/rustc_borrowck/src/polonius

1 file changed

+36
-4
lines changed

compiler/rustc_borrowck/src/polonius/dump.rs

+36-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
use std::io;
22

3-
use rustc_middle::mir::pretty::{PrettyPrintMirOptions, dump_mir_with_options};
3+
use rustc_middle::mir::pretty::{
4+
PrettyPrintMirOptions, create_dump_file, dump_enabled, dump_mir_to_writer,
5+
};
46
use rustc_middle::mir::{Body, ClosureRegionRequirements, PassWhere};
57
use rustc_middle::ty::TyCtxt;
68
use rustc_session::config::MirIncludeSpans;
@@ -26,9 +28,39 @@ pub(crate) fn dump_polonius_mir<'tcx>(
2628
return;
2729
}
2830

31+
if !dump_enabled(tcx, "polonius", body.source.def_id()) {
32+
return;
33+
}
34+
2935
let localized_outlives_constraints = localized_outlives_constraints
3036
.expect("missing localized constraints with `-Zpolonius=next`");
3137

38+
let _: io::Result<()> = try {
39+
let mut file = create_dump_file(tcx, "mir", false, "polonius", &0, body)?;
40+
emit_polonius_dump(
41+
tcx,
42+
body,
43+
regioncx,
44+
borrow_set,
45+
localized_outlives_constraints,
46+
closure_region_requirements,
47+
&mut file,
48+
)?;
49+
};
50+
}
51+
52+
/// The polonius dump consists of:
53+
/// - the NLL MIR
54+
/// - the list of polonius localized constraints
55+
fn emit_polonius_dump<'tcx>(
56+
tcx: TyCtxt<'tcx>,
57+
body: &Body<'tcx>,
58+
regioncx: &RegionInferenceContext<'tcx>,
59+
borrow_set: &BorrowSet<'tcx>,
60+
localized_outlives_constraints: LocalizedOutlivesConstraintSet,
61+
closure_region_requirements: &Option<ClosureRegionRequirements<'tcx>>,
62+
out: &mut dyn io::Write,
63+
) -> io::Result<()> {
3264
// We want the NLL extra comments printed by default in NLL MIR dumps (they were removed in
3365
// #112346). Specifying `-Z mir-include-spans` on the CLI still has priority: for example,
3466
// they're always disabled in mir-opt tests to make working with blessed dumps easier.
@@ -39,12 +71,12 @@ pub(crate) fn dump_polonius_mir<'tcx>(
3971
),
4072
};
4173

42-
dump_mir_with_options(
74+
dump_mir_to_writer(
4375
tcx,
44-
false,
4576
"polonius",
4677
&0,
4778
body,
79+
out,
4880
|pass_where, out| {
4981
emit_polonius_mir(
5082
tcx,
@@ -57,7 +89,7 @@ pub(crate) fn dump_polonius_mir<'tcx>(
5789
)
5890
},
5991
options,
60-
);
92+
)
6193
}
6294

6395
/// Produces the actual NLL + Polonius MIR sections to emit during the dumping process.

0 commit comments

Comments
 (0)