@@ -2,9 +2,7 @@ use std::io;
22
33use  rustc_data_structures:: fx:: { FxHashSet ,  FxIndexMap ,  FxIndexSet } ; 
44use  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 } ; 
86use  rustc_middle:: mir:: { Body ,  Location } ; 
97use  rustc_middle:: ty:: { RegionVid ,  TyCtxt } ; 
108use  rustc_mir_dataflow:: points:: PointIndex ; 
@@ -33,22 +31,41 @@ pub(crate) fn dump_polonius_mir<'tcx>(
3331        return ; 
3432    } 
3533
36-     if  !dump_enabled ( tcx,  "polonius" ,  body. source . def_id ( ) )  { 
37-         return ; 
38-     } 
34+     let  Some ( dumper)  = MirDumper :: new ( tcx,  "polonius" ,  body)  else  {  return  } ; 
3935
4036    let  polonius_diagnostics =
4137        polonius_diagnostics. expect ( "missing diagnostics context with `-Zpolonius=next`" ) ; 
4238
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+ 
4361    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) ?; 
4563        emit_polonius_dump ( 
46-             tcx , 
64+             & dumper , 
4765            body, 
4866            regioncx, 
4967            borrow_set, 
5068            & polonius_diagnostics. localized_outlives_constraints , 
51-             closure_region_requirements, 
5269            & mut  file, 
5370        ) ?; 
5471    } ; 
@@ -61,12 +78,11 @@ pub(crate) fn dump_polonius_mir<'tcx>(
6178/// - a mermaid graph of the NLL regions and the constraints between them 
6279/// - a mermaid graph of the NLL SCCs and the constraints between them 
6380fn  emit_polonius_dump < ' tcx > ( 
64-     tcx :   TyCtxt < ' tcx > , 
81+     dumper :   & MirDumper < ' _ ,   ' _ ,   ' tcx > , 
6582    body :  & Body < ' tcx > , 
6683    regioncx :  & RegionInferenceContext < ' tcx > , 
6784    borrow_set :  & BorrowSet < ' tcx > , 
6885    localized_outlives_constraints :  & LocalizedOutlivesConstraintSet , 
69-     closure_region_requirements :  & Option < ClosureRegionRequirements < ' tcx > > , 
7086    out :  & mut  dyn  io:: Write , 
7187)  -> io:: Result < ( ) >  { 
7288    // Prepare the HTML dump file prologue. 
@@ -79,15 +95,7 @@ fn emit_polonius_dump<'tcx>(
7995    writeln ! ( out,  "<div>" ) ?; 
8096    writeln ! ( out,  "Raw MIR dump" ) ?; 
8197    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) ?; 
9199    writeln ! ( out,  "</code></pre>" ) ?; 
92100    writeln ! ( out,  "</div>" ) ?; 
93101
@@ -116,15 +124,15 @@ fn emit_polonius_dump<'tcx>(
116124    writeln ! ( out,  "<div>" ) ?; 
117125    writeln ! ( out,  "NLL regions" ) ?; 
118126    writeln ! ( out,  "<pre class='mermaid'>" ) ?; 
119-     emit_mermaid_nll_regions ( tcx,  regioncx,  out) ?; 
127+     emit_mermaid_nll_regions ( dumper . tcx ( ) ,  regioncx,  out) ?; 
120128    writeln ! ( out,  "</pre>" ) ?; 
121129    writeln ! ( out,  "</div>" ) ?; 
122130
123131    // Section 5: mermaid visualization of the NLL SCC graph. 
124132    writeln ! ( out,  "<div>" ) ?; 
125133    writeln ! ( out,  "NLL SCCs" ) ?; 
126134    writeln ! ( out,  "<pre class='mermaid'>" ) ?; 
127-     emit_mermaid_nll_sccs ( tcx,  regioncx,  out) ?; 
135+     emit_mermaid_nll_sccs ( dumper . tcx ( ) ,  regioncx,  out) ?; 
128136    writeln ! ( out,  "</pre>" ) ?; 
129137    writeln ! ( out,  "</div>" ) ?; 
130138
@@ -149,45 +157,14 @@ fn emit_polonius_dump<'tcx>(
149157
150158/// Emits the polonius MIR, as escaped HTML. 
151159fn  emit_html_mir < ' tcx > ( 
152-     tcx :   TyCtxt < ' tcx > , 
160+     dumper :   & MirDumper < ' _ ,   ' _ ,   ' tcx > , 
153161    body :  & Body < ' tcx > , 
154-     regioncx :  & RegionInferenceContext < ' tcx > , 
155-     borrow_set :  & BorrowSet < ' tcx > , 
156-     localized_outlives_constraints :  & LocalizedOutlivesConstraintSet , 
157-     closure_region_requirements :  & Option < ClosureRegionRequirements < ' tcx > > , 
158162    out :  & mut  dyn  io:: Write , 
159163)  -> io:: Result < ( ) >  { 
160164    // Buffer the regular MIR dump to be able to escape it. 
161165    let  mut  buffer = Vec :: new ( ) ; 
162166
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) ?; 
191168
192169    // Escape the handful of characters that need it. We don't need to be particularly efficient: 
193170    // we're actually writing into a buffered writer already. Note that MIR dumps are valid UTF-8. 
0 commit comments