@@ -985,84 +985,80 @@ impl<'tcx> MutVisitor<'tcx> for ConstPropagator<'_, 'tcx> {
985985 trace ! ( "visit_statement: {:?}" , statement) ;
986986 let source_info = statement. source_info ;
987987 self . source_info = Some ( source_info) ;
988- if let StatementKind :: Assign ( box ( place, ref mut rval) ) = statement. kind {
989- let can_const_prop = self . ecx . machine . can_const_prop [ place. local ] ;
990- if let Some ( ( ) ) = self . const_prop ( rval, place) {
991- // This will return None if the above `const_prop` invocation only "wrote" a
992- // type whose creation requires no write. E.g. a generator whose initial state
993- // consists solely of uninitialized memory (so it doesn't capture any locals).
994- if let Some ( ref value) = self . get_const ( place) && self . should_const_prop ( value) {
995- trace ! ( "replacing {:?} with {:?}" , rval, value) ;
996- self . replace_with_const ( rval, value, source_info) ;
997- if can_const_prop == ConstPropMode :: FullConstProp
998- || can_const_prop == ConstPropMode :: OnlyInsideOwnBlock
999- {
1000- trace ! ( "propagated into {:?}" , place) ;
988+ match statement. kind {
989+ StatementKind :: Assign ( box ( place, ref mut rval) ) => {
990+ let can_const_prop = self . ecx . machine . can_const_prop [ place. local ] ;
991+ if let Some ( ( ) ) = self . const_prop ( rval, place) {
992+ // This will return None if the above `const_prop` invocation only "wrote" a
993+ // type whose creation requires no write. E.g. a generator whose initial state
994+ // consists solely of uninitialized memory (so it doesn't capture any locals).
995+ if let Some ( ref value) = self . get_const ( place) && self . should_const_prop ( value) {
996+ trace ! ( "replacing {:?} with {:?}" , rval, value) ;
997+ self . replace_with_const ( rval, value, source_info) ;
998+ if can_const_prop == ConstPropMode :: FullConstProp
999+ || can_const_prop == ConstPropMode :: OnlyInsideOwnBlock
1000+ {
1001+ trace ! ( "propagated into {:?}" , place) ;
1002+ }
10011003 }
1002- }
1003- match can_const_prop {
1004- ConstPropMode :: OnlyInsideOwnBlock => {
1005- trace ! (
1006- "found local restricted to its block. \
1004+ match can_const_prop {
1005+ ConstPropMode :: OnlyInsideOwnBlock => {
1006+ trace ! (
1007+ "found local restricted to its block. \
10071008 Will remove it from const-prop after block is finished. Local: {:?}",
1008- place. local
1009- ) ;
1010- }
1011- ConstPropMode :: OnlyPropagateInto | ConstPropMode :: NoPropagation => {
1012- trace ! ( "can't propagate into {:?}" , place) ;
1013- if place. local != RETURN_PLACE {
1014- Self :: remove_const ( & mut self . ecx , place. local ) ;
1009+ place. local
1010+ ) ;
10151011 }
1016- }
1017- ConstPropMode :: FullConstProp => { }
1018- }
1019- } else {
1020- // Const prop failed, so erase the destination, ensuring that whatever happens
1021- // from here on, does not know about the previous value.
1022- // This is important in case we have
1023- // ```rust
1024- // let mut x = 42;
1025- // x = SOME_MUTABLE_STATIC;
1026- // // x must now be uninit
1027- // ```
1028- // FIXME: we overzealously erase the entire local, because that's easier to
1029- // implement.
1030- trace ! (
1031- "propagation into {:?} failed.
1032- Nuking the entire site from orbit, it's the only way to be sure" ,
1033- place,
1034- ) ;
1035- Self :: remove_const ( & mut self . ecx , place. local ) ;
1036- }
1037- } else {
1038- match statement. kind {
1039- StatementKind :: SetDiscriminant { ref place, .. } => {
1040- match self . ecx . machine . can_const_prop [ place. local ] {
1041- ConstPropMode :: FullConstProp | ConstPropMode :: OnlyInsideOwnBlock => {
1042- if self . use_ecx ( |this| this. ecx . statement ( statement) ) . is_some ( ) {
1043- trace ! ( "propped discriminant into {:?}" , place) ;
1044- } else {
1012+ ConstPropMode :: OnlyPropagateInto | ConstPropMode :: NoPropagation => {
1013+ trace ! ( "can't propagate into {:?}" , place) ;
1014+ if place. local != RETURN_PLACE {
10451015 Self :: remove_const ( & mut self . ecx , place. local ) ;
10461016 }
10471017 }
1048- ConstPropMode :: OnlyPropagateInto | ConstPropMode :: NoPropagation => {
1049- Self :: remove_const ( & mut self . ecx , place. local ) ;
1050- }
1018+ ConstPropMode :: FullConstProp => { }
10511019 }
1020+ } else {
1021+ // Const prop failed, so erase the destination, ensuring that whatever happens
1022+ // from here on, does not know about the previous value.
1023+ // This is important in case we have
1024+ // ```rust
1025+ // let mut x = 42;
1026+ // x = SOME_MUTABLE_STATIC;
1027+ // // x must now be uninit
1028+ // ```
1029+ // FIXME: we overzealously erase the entire local, because that's easier to
1030+ // implement.
1031+ trace ! (
1032+ "propagation into {:?} failed.
1033+ Nuking the entire site from orbit, it's the only way to be sure" ,
1034+ place,
1035+ ) ;
1036+ Self :: remove_const ( & mut self . ecx , place. local ) ;
10521037 }
1053- StatementKind :: StorageLive ( local) | StatementKind :: StorageDead ( local) => {
1054- let frame = self . ecx . frame_mut ( ) ;
1055- frame. locals [ local] . value =
1056- if let StatementKind :: StorageLive ( _) = statement. kind {
1057- LocalValue :: Live ( interpret:: Operand :: Immediate (
1058- interpret:: Immediate :: Uninit ,
1059- ) )
1038+ }
1039+ StatementKind :: SetDiscriminant { ref place, .. } => {
1040+ match self . ecx . machine . can_const_prop [ place. local ] {
1041+ ConstPropMode :: FullConstProp | ConstPropMode :: OnlyInsideOwnBlock => {
1042+ if self . use_ecx ( |this| this. ecx . statement ( statement) ) . is_some ( ) {
1043+ trace ! ( "propped discriminant into {:?}" , place) ;
10601044 } else {
1061- LocalValue :: Dead
1062- } ;
1045+ Self :: remove_const ( & mut self . ecx , place. local ) ;
1046+ }
1047+ }
1048+ ConstPropMode :: OnlyPropagateInto | ConstPropMode :: NoPropagation => {
1049+ Self :: remove_const ( & mut self . ecx , place. local ) ;
1050+ }
10631051 }
1064- _ => { }
10651052 }
1053+ StatementKind :: StorageLive ( local) | StatementKind :: StorageDead ( local) => {
1054+ let frame = self . ecx . frame_mut ( ) ;
1055+ frame. locals [ local] . value = if let StatementKind :: StorageLive ( _) = statement. kind {
1056+ LocalValue :: Live ( interpret:: Operand :: Immediate ( interpret:: Immediate :: Uninit ) )
1057+ } else {
1058+ LocalValue :: Dead
1059+ } ;
1060+ }
1061+ _ => { }
10661062 }
10671063
10681064 self . super_statement ( statement, location) ;
0 commit comments