@@ -522,75 +522,70 @@ impl<'tcx> Visitor<'tcx> for ConstPropagator<'_, 'tcx> {
522
522
trace ! ( "visit_statement: {:?}" , statement) ;
523
523
let source_info = statement. source_info ;
524
524
self . source_info = Some ( source_info) ;
525
- if let StatementKind :: Assign ( box ( place, ref rval) ) = statement. kind {
526
- let can_const_prop = self . ecx . machine . can_const_prop [ place. local ] ;
527
- if let Some ( ( ) ) = self . const_prop ( rval, source_info, place) {
528
- match can_const_prop {
529
- ConstPropMode :: OnlyInsideOwnBlock => {
530
- trace ! (
531
- "found local restricted to its block. \
525
+ match statement. kind {
526
+ StatementKind :: Assign ( box ( place, ref rval) ) => {
527
+ let can_const_prop = self . ecx . machine . can_const_prop [ place. local ] ;
528
+ if let Some ( ( ) ) = self . const_prop ( rval, source_info, place) {
529
+ match can_const_prop {
530
+ ConstPropMode :: OnlyInsideOwnBlock => {
531
+ trace ! (
532
+ "found local restricted to its block. \
532
533
Will remove it from const-prop after block is finished. Local: {:?}",
533
- place. local
534
- ) ;
535
- }
536
- ConstPropMode :: OnlyPropagateInto | ConstPropMode :: NoPropagation => {
537
- trace ! ( "can't propagate into {:?}" , place) ;
538
- if place. local != RETURN_PLACE {
539
- Self :: remove_const ( & mut self . ecx , place. local ) ;
534
+ place. local
535
+ ) ;
540
536
}
541
- }
542
- ConstPropMode :: FullConstProp => { }
543
- }
544
- } else {
545
- // Const prop failed, so erase the destination, ensuring that whatever happens
546
- // from here on, does not know about the previous value.
547
- // This is important in case we have
548
- // ```rust
549
- // let mut x = 42;
550
- // x = SOME_MUTABLE_STATIC;
551
- // // x must now be uninit
552
- // ```
553
- // FIXME: we overzealously erase the entire local, because that's easier to
554
- // implement.
555
- trace ! (
556
- "propagation into {:?} failed.
557
- Nuking the entire site from orbit, it's the only way to be sure" ,
558
- place,
559
- ) ;
560
- Self :: remove_const ( & mut self . ecx , place. local ) ;
561
- }
562
- } else {
563
- match statement. kind {
564
- StatementKind :: SetDiscriminant { ref place, .. } => {
565
- match self . ecx . machine . can_const_prop [ place. local ] {
566
- ConstPropMode :: FullConstProp | ConstPropMode :: OnlyInsideOwnBlock => {
567
- if self
568
- . use_ecx ( source_info, |this| this. ecx . statement ( statement) )
569
- . is_some ( )
570
- {
571
- trace ! ( "propped discriminant into {:?}" , place) ;
572
- } else {
537
+ ConstPropMode :: OnlyPropagateInto | ConstPropMode :: NoPropagation => {
538
+ trace ! ( "can't propagate into {:?}" , place) ;
539
+ if place. local != RETURN_PLACE {
573
540
Self :: remove_const ( & mut self . ecx , place. local ) ;
574
541
}
575
542
}
576
- ConstPropMode :: OnlyPropagateInto | ConstPropMode :: NoPropagation => {
577
- Self :: remove_const ( & mut self . ecx , place. local ) ;
578
- }
543
+ ConstPropMode :: FullConstProp => { }
579
544
}
545
+ } else {
546
+ // Const prop failed, so erase the destination, ensuring that whatever happens
547
+ // from here on, does not know about the previous value.
548
+ // This is important in case we have
549
+ // ```rust
550
+ // let mut x = 42;
551
+ // x = SOME_MUTABLE_STATIC;
552
+ // // x must now be uninit
553
+ // ```
554
+ // FIXME: we overzealously erase the entire local, because that's easier to
555
+ // implement.
556
+ trace ! (
557
+ "propagation into {:?} failed.
558
+ Nuking the entire site from orbit, it's the only way to be sure" ,
559
+ place,
560
+ ) ;
561
+ Self :: remove_const ( & mut self . ecx , place. local ) ;
580
562
}
581
- StatementKind :: StorageLive ( local ) | StatementKind :: StorageDead ( local ) => {
582
- let frame = self . ecx . frame_mut ( ) ;
583
- frame . locals [ local] . value =
584
- if let StatementKind :: StorageLive ( _ ) = statement . kind {
585
- LocalValue :: Live ( interpret :: Operand :: Immediate (
586
- interpret :: Immediate :: Uninit ,
587
- ) )
563
+ }
564
+ StatementKind :: SetDiscriminant { ref place , .. } => {
565
+ match self . ecx . machine . can_const_prop [ place . local ] {
566
+ ConstPropMode :: FullConstProp | ConstPropMode :: OnlyInsideOwnBlock => {
567
+ if self . use_ecx ( source_info , |this| this . ecx . statement ( statement ) ) . is_some ( )
568
+ {
569
+ trace ! ( "propped discriminant into {:?}" , place ) ;
588
570
} else {
589
- LocalValue :: Dead
590
- } ;
571
+ Self :: remove_const ( & mut self . ecx , place. local ) ;
572
+ }
573
+ }
574
+ ConstPropMode :: OnlyPropagateInto | ConstPropMode :: NoPropagation => {
575
+ Self :: remove_const ( & mut self . ecx , place. local ) ;
576
+ }
591
577
}
592
- _ => { }
593
578
}
579
+ StatementKind :: StorageLive ( local) => {
580
+ let frame = self . ecx . frame_mut ( ) ;
581
+ frame. locals [ local] . value =
582
+ LocalValue :: Live ( interpret:: Operand :: Immediate ( interpret:: Immediate :: Uninit ) ) ;
583
+ }
584
+ StatementKind :: StorageDead ( local) => {
585
+ let frame = self . ecx . frame_mut ( ) ;
586
+ frame. locals [ local] . value = LocalValue :: Dead ;
587
+ }
588
+ _ => { }
594
589
}
595
590
596
591
self . super_statement ( statement, location) ;
0 commit comments