@@ -201,11 +201,12 @@ struct Formatter<'mir, 'tcx, A>
201
201
where
202
202
A : Analysis < ' tcx > ,
203
203
{
204
+ body : & ' mir Body < ' tcx > ,
204
205
// The `RefCell` is used because `<Formatter as Labeller>::node_label`
205
- // takes `&self`, but it needs to modify the cursor . This is also the
206
+ // takes `&self`, but it needs to modify the results . This is also the
206
207
// reason for the `Formatter`/`BlockFormatter` split; `BlockFormatter` has
207
208
// the operations that involve the mutation, i.e. within the `borrow_mut`.
208
- cursor : RefCell < ResultsCursor < ' mir , ' tcx , A > > ,
209
+ results : RefCell < & ' mir mut Results < ' tcx , A > > ,
209
210
style : OutputStyle ,
210
211
reachable : DenseBitSet < BasicBlock > ,
211
212
}
@@ -220,11 +221,7 @@ where
220
221
style : OutputStyle ,
221
222
) -> Self {
222
223
let reachable = traversal:: reachable_as_bitset ( body) ;
223
- Formatter { cursor : results. as_results_cursor ( body) . into ( ) , style, reachable }
224
- }
225
-
226
- fn body ( & self ) -> & ' mir Body < ' tcx > {
227
- self . cursor . borrow ( ) . body ( )
224
+ Formatter { body, results : results. into ( ) , style, reachable }
228
225
}
229
226
}
230
227
@@ -253,7 +250,7 @@ where
253
250
type Edge = CfgEdge ;
254
251
255
252
fn graph_id ( & self ) -> dot:: Id < ' _ > {
256
- let name = graphviz_safe_def_name ( self . body ( ) . source . def_id ( ) ) ;
253
+ let name = graphviz_safe_def_name ( self . body . source . def_id ( ) ) ;
257
254
dot:: Id :: new ( format ! ( "graph_for_def_id_{name}" ) ) . unwrap ( )
258
255
}
259
256
@@ -262,9 +259,12 @@ where
262
259
}
263
260
264
261
fn node_label ( & self , block : & Self :: Node ) -> dot:: LabelText < ' _ > {
265
- let mut cursor = self . cursor . borrow_mut ( ) ;
266
- let mut fmt =
267
- BlockFormatter { cursor : & mut cursor, style : self . style , bg : Background :: Light } ;
262
+ let mut results = self . results . borrow_mut ( ) ;
263
+ let mut fmt = BlockFormatter {
264
+ cursor : results. as_results_cursor ( self . body ) ,
265
+ style : self . style ,
266
+ bg : Background :: Light ,
267
+ } ;
268
268
let label = fmt. write_node_label ( * block) . unwrap ( ) ;
269
269
270
270
dot:: LabelText :: html ( String :: from_utf8 ( label) . unwrap ( ) )
@@ -275,7 +275,7 @@ where
275
275
}
276
276
277
277
fn edge_label ( & self , e : & Self :: Edge ) -> dot:: LabelText < ' _ > {
278
- let label = & self . body ( ) [ e. source ] . terminator ( ) . kind . fmt_successor_labels ( ) [ e. index ] ;
278
+ let label = & self . body [ e. source ] . terminator ( ) . kind . fmt_successor_labels ( ) [ e. index ] ;
279
279
dot:: LabelText :: label ( label. clone ( ) )
280
280
}
281
281
}
@@ -288,7 +288,7 @@ where
288
288
type Edge = CfgEdge ;
289
289
290
290
fn nodes ( & self ) -> dot:: Nodes < ' _ , Self :: Node > {
291
- self . body ( )
291
+ self . body
292
292
. basic_blocks
293
293
. indices ( )
294
294
. filter ( |& idx| self . reachable . contains ( idx) )
@@ -297,10 +297,10 @@ where
297
297
}
298
298
299
299
fn edges ( & self ) -> dot:: Edges < ' _ , Self :: Edge > {
300
- let body = self . body ( ) ;
301
- body . basic_blocks
300
+ self . body
301
+ . basic_blocks
302
302
. indices ( )
303
- . flat_map ( |bb| dataflow_successors ( body, bb) )
303
+ . flat_map ( |bb| dataflow_successors ( self . body , bb) )
304
304
. collect :: < Vec < _ > > ( )
305
305
. into ( )
306
306
}
@@ -310,20 +310,20 @@ where
310
310
}
311
311
312
312
fn target ( & self , edge : & Self :: Edge ) -> Self :: Node {
313
- self . body ( ) [ edge. source ] . terminator ( ) . successors ( ) . nth ( edge. index ) . unwrap ( )
313
+ self . body [ edge. source ] . terminator ( ) . successors ( ) . nth ( edge. index ) . unwrap ( )
314
314
}
315
315
}
316
316
317
- struct BlockFormatter < ' a , ' mir , ' tcx , A >
317
+ struct BlockFormatter < ' mir , ' tcx , A >
318
318
where
319
319
A : Analysis < ' tcx > ,
320
320
{
321
- cursor : & ' a mut ResultsCursor < ' mir , ' tcx , A > ,
321
+ cursor : ResultsCursor < ' mir , ' tcx , A > ,
322
322
bg : Background ,
323
323
style : OutputStyle ,
324
324
}
325
325
326
- impl < ' tcx , A > BlockFormatter < ' _ , ' _ , ' tcx , A >
326
+ impl < ' tcx , A > BlockFormatter < ' _ , ' tcx , A >
327
327
where
328
328
A : Analysis < ' tcx > ,
329
329
A :: Domain : DebugWithContext < A > ,
0 commit comments