@@ -2,9 +2,7 @@ use std::io;
2
2
3
3
use rustc_data_structures:: fx:: { FxHashSet , FxIndexMap , FxIndexSet } ;
4
4
use rustc_index:: IndexVec ;
5
- use rustc_middle:: mir:: pretty:: {
6
- PassWhere , PrettyPrintMirOptions , create_dump_file, dump_enabled, dump_mir_to_writer,
7
- } ;
5
+ use rustc_middle:: mir:: pretty:: { MirDumper , PassWhere , PrettyPrintMirOptions } ;
8
6
use rustc_middle:: mir:: { Body , Location } ;
9
7
use rustc_middle:: ty:: { RegionVid , TyCtxt } ;
10
8
use rustc_mir_dataflow:: points:: PointIndex ;
@@ -33,22 +31,41 @@ pub(crate) fn dump_polonius_mir<'tcx>(
33
31
return ;
34
32
}
35
33
36
- if !dump_enabled ( tcx, "polonius" , body. source . def_id ( ) ) {
37
- return ;
38
- }
34
+ let Some ( dumper) = MirDumper :: new ( tcx, "polonius" , body) else { return } ;
39
35
40
36
let polonius_diagnostics =
41
37
polonius_diagnostics. expect ( "missing diagnostics context with `-Zpolonius=next`" ) ;
42
38
39
+ let extra_data = & |pass_where, out : & mut dyn io:: Write | {
40
+ emit_polonius_mir (
41
+ tcx,
42
+ regioncx,
43
+ closure_region_requirements,
44
+ borrow_set,
45
+ & polonius_diagnostics. localized_outlives_constraints ,
46
+ pass_where,
47
+ out,
48
+ )
49
+ } ;
50
+ // We want the NLL extra comments printed by default in NLL MIR dumps. Specifying `-Z
51
+ // mir-include-spans` on the CLI still has priority.
52
+ let options = PrettyPrintMirOptions {
53
+ include_extra_comments : matches ! (
54
+ tcx. sess. opts. unstable_opts. mir_include_spans,
55
+ MirIncludeSpans :: On | MirIncludeSpans :: Nll
56
+ ) ,
57
+ } ;
58
+
59
+ let dumper = dumper. set_extra_data ( extra_data) . set_options ( options) ;
60
+
43
61
let _: io:: Result < ( ) > = try {
44
- let mut file = create_dump_file ( tcx , "html" , false , "polonius" , & 0 , body) ?;
62
+ let mut file = dumper . create_dump_file ( "html" , body) ?;
45
63
emit_polonius_dump (
46
- tcx ,
64
+ & dumper ,
47
65
body,
48
66
regioncx,
49
67
borrow_set,
50
68
& polonius_diagnostics. localized_outlives_constraints ,
51
- closure_region_requirements,
52
69
& mut file,
53
70
) ?;
54
71
} ;
@@ -61,12 +78,11 @@ pub(crate) fn dump_polonius_mir<'tcx>(
61
78
/// - a mermaid graph of the NLL regions and the constraints between them
62
79
/// - a mermaid graph of the NLL SCCs and the constraints between them
63
80
fn emit_polonius_dump < ' tcx > (
64
- tcx : TyCtxt < ' tcx > ,
81
+ dumper : & MirDumper < ' _ , ' _ , ' tcx > ,
65
82
body : & Body < ' tcx > ,
66
83
regioncx : & RegionInferenceContext < ' tcx > ,
67
84
borrow_set : & BorrowSet < ' tcx > ,
68
85
localized_outlives_constraints : & LocalizedOutlivesConstraintSet ,
69
- closure_region_requirements : & Option < ClosureRegionRequirements < ' tcx > > ,
70
86
out : & mut dyn io:: Write ,
71
87
) -> io:: Result < ( ) > {
72
88
// Prepare the HTML dump file prologue.
@@ -79,15 +95,7 @@ fn emit_polonius_dump<'tcx>(
79
95
writeln ! ( out, "<div>" ) ?;
80
96
writeln ! ( out, "Raw MIR dump" ) ?;
81
97
writeln ! ( out, "<pre><code>" ) ?;
82
- emit_html_mir (
83
- tcx,
84
- body,
85
- regioncx,
86
- borrow_set,
87
- & localized_outlives_constraints,
88
- closure_region_requirements,
89
- out,
90
- ) ?;
98
+ emit_html_mir ( dumper, body, out) ?;
91
99
writeln ! ( out, "</code></pre>" ) ?;
92
100
writeln ! ( out, "</div>" ) ?;
93
101
@@ -116,15 +124,15 @@ fn emit_polonius_dump<'tcx>(
116
124
writeln ! ( out, "<div>" ) ?;
117
125
writeln ! ( out, "NLL regions" ) ?;
118
126
writeln ! ( out, "<pre class='mermaid'>" ) ?;
119
- emit_mermaid_nll_regions ( tcx, regioncx, out) ?;
127
+ emit_mermaid_nll_regions ( dumper . tcx ( ) , regioncx, out) ?;
120
128
writeln ! ( out, "</pre>" ) ?;
121
129
writeln ! ( out, "</div>" ) ?;
122
130
123
131
// Section 5: mermaid visualization of the NLL SCC graph.
124
132
writeln ! ( out, "<div>" ) ?;
125
133
writeln ! ( out, "NLL SCCs" ) ?;
126
134
writeln ! ( out, "<pre class='mermaid'>" ) ?;
127
- emit_mermaid_nll_sccs ( tcx, regioncx, out) ?;
135
+ emit_mermaid_nll_sccs ( dumper . tcx ( ) , regioncx, out) ?;
128
136
writeln ! ( out, "</pre>" ) ?;
129
137
writeln ! ( out, "</div>" ) ?;
130
138
@@ -149,45 +157,14 @@ fn emit_polonius_dump<'tcx>(
149
157
150
158
/// Emits the polonius MIR, as escaped HTML.
151
159
fn emit_html_mir < ' tcx > (
152
- tcx : TyCtxt < ' tcx > ,
160
+ dumper : & MirDumper < ' _ , ' _ , ' tcx > ,
153
161
body : & Body < ' tcx > ,
154
- regioncx : & RegionInferenceContext < ' tcx > ,
155
- borrow_set : & BorrowSet < ' tcx > ,
156
- localized_outlives_constraints : & LocalizedOutlivesConstraintSet ,
157
- closure_region_requirements : & Option < ClosureRegionRequirements < ' tcx > > ,
158
162
out : & mut dyn io:: Write ,
159
163
) -> io:: Result < ( ) > {
160
164
// Buffer the regular MIR dump to be able to escape it.
161
165
let mut buffer = Vec :: new ( ) ;
162
166
163
- // We want the NLL extra comments printed by default in NLL MIR dumps. Specifying `-Z
164
- // mir-include-spans` on the CLI still has priority.
165
- let options = PrettyPrintMirOptions {
166
- include_extra_comments : matches ! (
167
- tcx. sess. opts. unstable_opts. mir_include_spans,
168
- MirIncludeSpans :: On | MirIncludeSpans :: Nll
169
- ) ,
170
- } ;
171
-
172
- dump_mir_to_writer (
173
- tcx,
174
- "polonius" ,
175
- & 0 ,
176
- body,
177
- & mut buffer,
178
- |pass_where, out| {
179
- emit_polonius_mir (
180
- tcx,
181
- regioncx,
182
- closure_region_requirements,
183
- borrow_set,
184
- localized_outlives_constraints,
185
- pass_where,
186
- out,
187
- )
188
- } ,
189
- options,
190
- ) ?;
167
+ dumper. dump_mir_to_writer ( body, & mut buffer) ?;
191
168
192
169
// Escape the handful of characters that need it. We don't need to be particularly efficient:
193
170
// we're actually writing into a buffered writer already. Note that MIR dumps are valid UTF-8.
0 commit comments