@@ -56,7 +56,7 @@ pub trait Direction {
56
56
exit_state : & mut A :: Domain ,
57
57
block : BasicBlock ,
58
58
edges : TerminatorEdges < ' _ , ' tcx > ,
59
- propagate : impl FnMut ( BasicBlock , & A :: Domain ) ,
59
+ propagate : impl FnMut ( & mut A , BasicBlock , & A :: Domain ) ,
60
60
) where
61
61
A : Analysis < ' tcx > ;
62
62
}
@@ -223,7 +223,7 @@ impl Direction for Backward {
223
223
exit_state : & mut A :: Domain ,
224
224
bb : BasicBlock ,
225
225
_edges : TerminatorEdges < ' _ , ' tcx > ,
226
- mut propagate : impl FnMut ( BasicBlock , & A :: Domain ) ,
226
+ mut propagate : impl FnMut ( & mut A , BasicBlock , & A :: Domain ) ,
227
227
) where
228
228
A : Analysis < ' tcx > ,
229
229
{
@@ -239,7 +239,7 @@ impl Direction for Backward {
239
239
pred,
240
240
CallReturnPlaces :: Call ( destination) ,
241
241
) ;
242
- propagate ( pred, & tmp) ;
242
+ propagate ( analysis , pred, & tmp) ;
243
243
}
244
244
245
245
mir:: TerminatorKind :: InlineAsm {
@@ -251,7 +251,7 @@ impl Direction for Backward {
251
251
pred,
252
252
CallReturnPlaces :: InlineAsm ( operands) ,
253
253
) ;
254
- propagate ( pred, & tmp) ;
254
+ propagate ( analysis , pred, & tmp) ;
255
255
}
256
256
257
257
mir:: TerminatorKind :: Yield { resume, resume_arg, .. } if resume == bb => {
@@ -261,7 +261,7 @@ impl Direction for Backward {
261
261
resume,
262
262
CallReturnPlaces :: Yield ( resume_arg) ,
263
263
) ;
264
- propagate ( pred, & tmp) ;
264
+ propagate ( analysis , pred, & tmp) ;
265
265
}
266
266
267
267
mir:: TerminatorKind :: SwitchInt { targets : _, ref discr } => {
@@ -277,11 +277,11 @@ impl Direction for Backward {
277
277
analysis. apply_switch_int_edge_effects ( pred, discr, & mut applier) ;
278
278
279
279
if !applier. effects_applied {
280
- propagate ( pred, exit_state)
280
+ propagate ( analysis , pred, exit_state)
281
281
}
282
282
}
283
283
284
- _ => propagate ( pred, exit_state) ,
284
+ _ => propagate ( analysis , pred, exit_state) ,
285
285
}
286
286
}
287
287
}
@@ -296,12 +296,17 @@ struct BackwardSwitchIntEdgeEffectsApplier<'mir, 'tcx, D, F> {
296
296
effects_applied : bool ,
297
297
}
298
298
299
- impl < D , F > super :: SwitchIntEdgeEffects < D > for BackwardSwitchIntEdgeEffectsApplier < ' _ , ' _ , D , F >
299
+ impl < ' tcx , A , F > super :: SwitchIntEdgeEffects < ' tcx , A >
300
+ for BackwardSwitchIntEdgeEffectsApplier < ' _ , ' _ , A :: Domain , F >
300
301
where
301
- D : Clone ,
302
- F : FnMut ( BasicBlock , & D ) ,
302
+ A : Analysis < ' tcx > ,
303
+ F : FnMut ( & mut A , BasicBlock , & A :: Domain ) ,
303
304
{
304
- fn apply ( & mut self , mut apply_edge_effect : impl FnMut ( & mut D , SwitchIntTarget ) ) {
305
+ fn apply (
306
+ & mut self ,
307
+ analysis : & mut A ,
308
+ mut apply_edge_effect : impl FnMut ( & mut A , & mut A :: Domain , SwitchIntTarget ) ,
309
+ ) {
305
310
assert ! ( !self . effects_applied) ;
306
311
307
312
let values = & self . body . basic_blocks . switch_sources ( ) [ & ( self . bb , self . pred ) ] ;
@@ -310,8 +315,8 @@ where
310
315
let mut tmp = None ;
311
316
for target in targets {
312
317
let tmp = opt_clone_from_or_clone ( & mut tmp, self . exit_state ) ;
313
- apply_edge_effect ( tmp, target) ;
314
- ( self . propagate ) ( self . pred , tmp) ;
318
+ apply_edge_effect ( analysis , tmp, target) ;
319
+ ( self . propagate ) ( analysis , self . pred , tmp) ;
315
320
}
316
321
317
322
self . effects_applied = true ;
@@ -475,25 +480,25 @@ impl Direction for Forward {
475
480
exit_state : & mut A :: Domain ,
476
481
bb : BasicBlock ,
477
482
edges : TerminatorEdges < ' _ , ' tcx > ,
478
- mut propagate : impl FnMut ( BasicBlock , & A :: Domain ) ,
483
+ mut propagate : impl FnMut ( & mut A , BasicBlock , & A :: Domain ) ,
479
484
) where
480
485
A : Analysis < ' tcx > ,
481
486
{
482
487
match edges {
483
488
TerminatorEdges :: None => { }
484
- TerminatorEdges :: Single ( target) => propagate ( target, exit_state) ,
489
+ TerminatorEdges :: Single ( target) => propagate ( analysis , target, exit_state) ,
485
490
TerminatorEdges :: Double ( target, unwind) => {
486
- propagate ( target, exit_state) ;
487
- propagate ( unwind, exit_state) ;
491
+ propagate ( analysis , target, exit_state) ;
492
+ propagate ( analysis , unwind, exit_state) ;
488
493
}
489
494
TerminatorEdges :: AssignOnReturn { return_, cleanup, place } => {
490
495
// This must be done *first*, otherwise the unwind path will see the assignments.
491
496
if let Some ( cleanup) = cleanup {
492
- propagate ( cleanup, exit_state) ;
497
+ propagate ( analysis , cleanup, exit_state) ;
493
498
}
494
499
if let Some ( return_) = return_ {
495
500
analysis. apply_call_return_effect ( exit_state, bb, place) ;
496
- propagate ( return_, exit_state) ;
501
+ propagate ( analysis , return_, exit_state) ;
497
502
}
498
503
}
499
504
TerminatorEdges :: SwitchInt { targets, discr } => {
@@ -515,7 +520,7 @@ impl Direction for Forward {
515
520
516
521
if !effects_applied {
517
522
for target in targets. all_targets ( ) {
518
- propagate ( * target, exit_state) ;
523
+ propagate ( analysis , * target, exit_state) ;
519
524
}
520
525
}
521
526
}
@@ -531,26 +536,35 @@ struct ForwardSwitchIntEdgeEffectsApplier<'mir, D, F> {
531
536
effects_applied : bool ,
532
537
}
533
538
534
- impl < D , F > super :: SwitchIntEdgeEffects < D > for ForwardSwitchIntEdgeEffectsApplier < ' _ , D , F >
539
+ impl < ' tcx , A , F > super :: SwitchIntEdgeEffects < ' tcx , A >
540
+ for ForwardSwitchIntEdgeEffectsApplier < ' _ , A :: Domain , F >
535
541
where
536
- D : Clone ,
537
- F : FnMut ( BasicBlock , & D ) ,
542
+ A : Analysis < ' tcx > ,
543
+ F : FnMut ( & mut A , BasicBlock , & A :: Domain ) ,
538
544
{
539
- fn apply ( & mut self , mut apply_edge_effect : impl FnMut ( & mut D , SwitchIntTarget ) ) {
545
+ fn apply (
546
+ & mut self ,
547
+ analysis : & mut A ,
548
+ mut apply_edge_effect : impl FnMut ( & mut A , & mut A :: Domain , SwitchIntTarget ) ,
549
+ ) {
540
550
assert ! ( !self . effects_applied) ;
541
551
542
552
let mut tmp = None ;
543
553
for ( value, target) in self . targets . iter ( ) {
544
554
let tmp = opt_clone_from_or_clone ( & mut tmp, self . exit_state ) ;
545
- apply_edge_effect ( tmp, SwitchIntTarget { value : Some ( value) , target } ) ;
546
- ( self . propagate ) ( target, tmp) ;
555
+ apply_edge_effect ( analysis , tmp, SwitchIntTarget { value : Some ( value) , target } ) ;
556
+ ( self . propagate ) ( analysis , target, tmp) ;
547
557
}
548
558
549
559
// Once we get to the final, "otherwise" branch, there is no need to preserve `exit_state`,
550
560
// so pass it directly to `apply_edge_effect` to save a clone of the dataflow state.
551
561
let otherwise = self . targets . otherwise ( ) ;
552
- apply_edge_effect ( self . exit_state , SwitchIntTarget { value : None , target : otherwise } ) ;
553
- ( self . propagate ) ( otherwise, self . exit_state ) ;
562
+ apply_edge_effect (
563
+ analysis,
564
+ self . exit_state ,
565
+ SwitchIntTarget { value : None , target : otherwise } ,
566
+ ) ;
567
+ ( self . propagate ) ( analysis, otherwise, self . exit_state ) ;
554
568
555
569
self . effects_applied = true ;
556
570
}
0 commit comments