@@ -55,7 +55,7 @@ pub trait Direction {
55
55
body : & mir:: Body < ' tcx > ,
56
56
exit_state : & mut A :: Domain ,
57
57
block : ( BasicBlock , & ' _ mir:: BasicBlockData < ' tcx > ) ,
58
- propagate : impl FnMut ( BasicBlock , & A :: Domain ) ,
58
+ propagate : impl FnMut ( & mut A , BasicBlock , & A :: Domain ) ,
59
59
) where
60
60
A : Analysis < ' tcx > ;
61
61
}
@@ -221,7 +221,7 @@ impl Direction for Backward {
221
221
body : & mir:: Body < ' tcx > ,
222
222
exit_state : & mut A :: Domain ,
223
223
( bb, _bb_data) : ( BasicBlock , & ' _ mir:: BasicBlockData < ' tcx > ) ,
224
- mut propagate : impl FnMut ( BasicBlock , & A :: Domain ) ,
224
+ mut propagate : impl FnMut ( & mut A , BasicBlock , & A :: Domain ) ,
225
225
) where
226
226
A : Analysis < ' tcx > ,
227
227
{
@@ -237,7 +237,7 @@ impl Direction for Backward {
237
237
pred,
238
238
CallReturnPlaces :: Call ( destination) ,
239
239
) ;
240
- propagate ( pred, & tmp) ;
240
+ propagate ( analysis , pred, & tmp) ;
241
241
}
242
242
243
243
mir:: TerminatorKind :: InlineAsm {
@@ -249,13 +249,13 @@ impl Direction for Backward {
249
249
pred,
250
250
CallReturnPlaces :: InlineAsm ( operands) ,
251
251
) ;
252
- propagate ( pred, & tmp) ;
252
+ propagate ( analysis , pred, & tmp) ;
253
253
}
254
254
255
255
mir:: TerminatorKind :: Yield { resume, resume_arg, .. } if resume == bb => {
256
256
let mut tmp = exit_state. clone ( ) ;
257
257
analysis. apply_yield_resume_effect ( & mut tmp, resume, resume_arg) ;
258
- propagate ( pred, & tmp) ;
258
+ propagate ( analysis , pred, & tmp) ;
259
259
}
260
260
261
261
mir:: TerminatorKind :: SwitchInt { targets : _, ref discr } => {
@@ -271,11 +271,11 @@ impl Direction for Backward {
271
271
analysis. apply_switch_int_edge_effects ( pred, discr, & mut applier) ;
272
272
273
273
if !applier. effects_applied {
274
- propagate ( pred, exit_state)
274
+ propagate ( analysis , pred, exit_state)
275
275
}
276
276
}
277
277
278
- _ => propagate ( pred, exit_state) ,
278
+ _ => propagate ( analysis , pred, exit_state) ,
279
279
}
280
280
}
281
281
}
@@ -290,12 +290,17 @@ struct BackwardSwitchIntEdgeEffectsApplier<'a, 'tcx, D, F> {
290
290
effects_applied : bool ,
291
291
}
292
292
293
- impl < D , F > super :: SwitchIntEdgeEffects < D > for BackwardSwitchIntEdgeEffectsApplier < ' _ , ' _ , D , F >
293
+ impl < ' tcx , A , F > super :: SwitchIntEdgeEffects < ' tcx , A >
294
+ for BackwardSwitchIntEdgeEffectsApplier < ' _ , ' _ , A :: Domain , F >
294
295
where
295
- D : Clone ,
296
- F : FnMut ( BasicBlock , & D ) ,
296
+ A : Analysis < ' tcx > ,
297
+ F : FnMut ( & mut A , BasicBlock , & A :: Domain ) ,
297
298
{
298
- fn apply ( & mut self , mut apply_edge_effect : impl FnMut ( & mut D , SwitchIntTarget ) ) {
299
+ fn apply (
300
+ & mut self ,
301
+ analysis : & mut A ,
302
+ mut apply_edge_effect : impl FnMut ( & mut A , & mut A :: Domain , SwitchIntTarget ) ,
303
+ ) {
299
304
assert ! ( !self . effects_applied) ;
300
305
301
306
let values = & self . body . basic_blocks . switch_sources ( ) [ & ( self . bb , self . pred ) ] ;
@@ -304,8 +309,8 @@ where
304
309
let mut tmp = None ;
305
310
for target in targets {
306
311
let tmp = opt_clone_from_or_clone ( & mut tmp, self . exit_state ) ;
307
- apply_edge_effect ( tmp, target) ;
308
- ( self . propagate ) ( self . pred , tmp) ;
312
+ apply_edge_effect ( analysis , tmp, target) ;
313
+ ( self . propagate ) ( analysis , self . pred , tmp) ;
309
314
}
310
315
311
316
self . effects_applied = true ;
@@ -468,43 +473,43 @@ impl Direction for Forward {
468
473
_body : & mir:: Body < ' tcx > ,
469
474
exit_state : & mut A :: Domain ,
470
475
( bb, bb_data) : ( BasicBlock , & ' _ mir:: BasicBlockData < ' tcx > ) ,
471
- mut propagate : impl FnMut ( BasicBlock , & A :: Domain ) ,
476
+ mut propagate : impl FnMut ( & mut A , BasicBlock , & A :: Domain ) ,
472
477
) where
473
478
A : Analysis < ' tcx > ,
474
479
{
475
480
use mir:: TerminatorKind :: * ;
476
481
match bb_data. terminator ( ) . kind {
477
482
Return | Resume | Terminate | GeneratorDrop | Unreachable => { }
478
483
479
- Goto { target } => propagate ( target, exit_state) ,
484
+ Goto { target } => propagate ( analysis , target, exit_state) ,
480
485
481
486
Assert { target, unwind, expected : _, msg : _, cond : _ }
482
487
| Drop { target, unwind, place : _, replace : _ }
483
488
| FalseUnwind { real_target : target, unwind } => {
484
489
if let UnwindAction :: Cleanup ( unwind) = unwind {
485
- propagate ( unwind, exit_state) ;
490
+ propagate ( analysis , unwind, exit_state) ;
486
491
}
487
492
488
- propagate ( target, exit_state) ;
493
+ propagate ( analysis , target, exit_state) ;
489
494
}
490
495
491
496
FalseEdge { real_target, imaginary_target } => {
492
- propagate ( real_target, exit_state) ;
493
- propagate ( imaginary_target, exit_state) ;
497
+ propagate ( analysis , real_target, exit_state) ;
498
+ propagate ( analysis , imaginary_target, exit_state) ;
494
499
}
495
500
496
501
Yield { resume : target, drop, resume_arg, value : _ } => {
497
502
if let Some ( drop) = drop {
498
- propagate ( drop, exit_state) ;
503
+ propagate ( analysis , drop, exit_state) ;
499
504
}
500
505
501
506
analysis. apply_yield_resume_effect ( exit_state, target, resume_arg) ;
502
- propagate ( target, exit_state) ;
507
+ propagate ( analysis , target, exit_state) ;
503
508
}
504
509
505
510
Call { unwind, destination, target, func : _, args : _, call_source : _, fn_span : _ } => {
506
511
if let UnwindAction :: Cleanup ( unwind) = unwind {
507
- propagate ( unwind, exit_state) ;
512
+ propagate ( analysis , unwind, exit_state) ;
508
513
}
509
514
510
515
if let Some ( target) = target {
@@ -515,7 +520,7 @@ impl Direction for Forward {
515
520
bb,
516
521
CallReturnPlaces :: Call ( destination) ,
517
522
) ;
518
- propagate ( target, exit_state) ;
523
+ propagate ( analysis , target, exit_state) ;
519
524
}
520
525
}
521
526
@@ -528,7 +533,7 @@ impl Direction for Forward {
528
533
unwind,
529
534
} => {
530
535
if let UnwindAction :: Cleanup ( unwind) = unwind {
531
- propagate ( unwind, exit_state) ;
536
+ propagate ( analysis , unwind, exit_state) ;
532
537
}
533
538
534
539
if let Some ( target) = destination {
@@ -539,7 +544,7 @@ impl Direction for Forward {
539
544
bb,
540
545
CallReturnPlaces :: InlineAsm ( operands) ,
541
546
) ;
542
- propagate ( target, exit_state) ;
547
+ propagate ( analysis , target, exit_state) ;
543
548
}
544
549
}
545
550
@@ -562,7 +567,7 @@ impl Direction for Forward {
562
567
563
568
if !effects_applied {
564
569
for target in targets. all_targets ( ) {
565
- propagate ( * target, exit_state) ;
570
+ propagate ( analysis , * target, exit_state) ;
566
571
}
567
572
}
568
573
}
@@ -578,26 +583,35 @@ struct ForwardSwitchIntEdgeEffectsApplier<'a, D, F> {
578
583
effects_applied : bool ,
579
584
}
580
585
581
- impl < D , F > super :: SwitchIntEdgeEffects < D > for ForwardSwitchIntEdgeEffectsApplier < ' _ , D , F >
586
+ impl < ' tcx , A , F > super :: SwitchIntEdgeEffects < ' tcx , A >
587
+ for ForwardSwitchIntEdgeEffectsApplier < ' _ , A :: Domain , F >
582
588
where
583
- D : Clone ,
584
- F : FnMut ( BasicBlock , & D ) ,
589
+ A : Analysis < ' tcx > ,
590
+ F : FnMut ( & mut A , BasicBlock , & A :: Domain ) ,
585
591
{
586
- fn apply ( & mut self , mut apply_edge_effect : impl FnMut ( & mut D , SwitchIntTarget ) ) {
592
+ fn apply (
593
+ & mut self ,
594
+ analysis : & mut A ,
595
+ mut apply_edge_effect : impl FnMut ( & mut A , & mut A :: Domain , SwitchIntTarget ) ,
596
+ ) {
587
597
assert ! ( !self . effects_applied) ;
588
598
589
599
let mut tmp = None ;
590
600
for ( value, target) in self . targets . iter ( ) {
591
601
let tmp = opt_clone_from_or_clone ( & mut tmp, self . exit_state ) ;
592
- apply_edge_effect ( tmp, SwitchIntTarget { value : Some ( value) , target } ) ;
593
- ( self . propagate ) ( target, tmp) ;
602
+ apply_edge_effect ( analysis , tmp, SwitchIntTarget { value : Some ( value) , target } ) ;
603
+ ( self . propagate ) ( analysis , target, tmp) ;
594
604
}
595
605
596
606
// Once we get to the final, "otherwise" branch, there is no need to preserve `exit_state`,
597
607
// so pass it directly to `apply_edge_effect` to save a clone of the dataflow state.
598
608
let otherwise = self . targets . otherwise ( ) ;
599
- apply_edge_effect ( self . exit_state , SwitchIntTarget { value : None , target : otherwise } ) ;
600
- ( self . propagate ) ( otherwise, self . exit_state ) ;
609
+ apply_edge_effect (
610
+ analysis,
611
+ self . exit_state ,
612
+ SwitchIntTarget { value : None , target : otherwise } ,
613
+ ) ;
614
+ ( self . propagate ) ( analysis, otherwise, self . exit_state ) ;
601
615
602
616
self . effects_applied = true ;
603
617
}
0 commit comments