@@ -917,84 +917,80 @@ impl<'tcx> MutVisitor<'tcx> for ConstPropagator<'_, 'tcx> {
917917 trace ! ( "visit_statement: {:?}" , statement) ;
918918 let source_info = statement. source_info ;
919919 self . source_info = Some ( source_info) ;
920- if let StatementKind :: Assign ( box ( place, ref mut rval) ) = statement. kind {
921- let can_const_prop = self . ecx . machine . can_const_prop [ place. local ] ;
922- if let Some ( ( ) ) = self . const_prop ( rval, place) {
923- // This will return None if the above `const_prop` invocation only "wrote" a
924- // type whose creation requires no write. E.g. a generator whose initial state
925- // consists solely of uninitialized memory (so it doesn't capture any locals).
926- if let Some ( ref value) = self . get_const ( place) && self . should_const_prop ( value) {
927- trace ! ( "replacing {:?} with {:?}" , rval, value) ;
928- self . replace_with_const ( rval, value, source_info) ;
929- if can_const_prop == ConstPropMode :: FullConstProp
930- || can_const_prop == ConstPropMode :: OnlyInsideOwnBlock
931- {
932- trace ! ( "propagated into {:?}" , place) ;
920+ match statement. kind {
921+ StatementKind :: Assign ( box ( place, ref mut rval) ) => {
922+ let can_const_prop = self . ecx . machine . can_const_prop [ place. local ] ;
923+ if let Some ( ( ) ) = self . const_prop ( rval, place) {
924+ // This will return None if the above `const_prop` invocation only "wrote" a
925+ // type whose creation requires no write. E.g. a generator whose initial state
926+ // consists solely of uninitialized memory (so it doesn't capture any locals).
927+ if let Some ( ref value) = self . get_const ( place) && self . should_const_prop ( value) {
928+ trace ! ( "replacing {:?} with {:?}" , rval, value) ;
929+ self . replace_with_const ( rval, value, source_info) ;
930+ if can_const_prop == ConstPropMode :: FullConstProp
931+ || can_const_prop == ConstPropMode :: OnlyInsideOwnBlock
932+ {
933+ trace ! ( "propagated into {:?}" , place) ;
934+ }
933935 }
934- }
935- match can_const_prop {
936- ConstPropMode :: OnlyInsideOwnBlock => {
937- trace ! (
938- "found local restricted to its block. \
936+ match can_const_prop {
937+ ConstPropMode :: OnlyInsideOwnBlock => {
938+ trace ! (
939+ "found local restricted to its block. \
939940 Will remove it from const-prop after block is finished. Local: {:?}",
940- place. local
941- ) ;
942- }
943- ConstPropMode :: OnlyPropagateInto | ConstPropMode :: NoPropagation => {
944- trace ! ( "can't propagate into {:?}" , place) ;
945- if place. local != RETURN_PLACE {
946- Self :: remove_const ( & mut self . ecx , place. local ) ;
941+ place. local
942+ ) ;
947943 }
948- }
949- ConstPropMode :: FullConstProp => { }
950- }
951- } else {
952- // Const prop failed, so erase the destination, ensuring that whatever happens
953- // from here on, does not know about the previous value.
954- // This is important in case we have
955- // ```rust
956- // let mut x = 42;
957- // x = SOME_MUTABLE_STATIC;
958- // // x must now be uninit
959- // ```
960- // FIXME: we overzealously erase the entire local, because that's easier to
961- // implement.
962- trace ! (
963- "propagation into {:?} failed.
964- Nuking the entire site from orbit, it's the only way to be sure" ,
965- place,
966- ) ;
967- Self :: remove_const ( & mut self . ecx , place. local ) ;
968- }
969- } else {
970- match statement. kind {
971- StatementKind :: SetDiscriminant { ref place, .. } => {
972- match self . ecx . machine . can_const_prop [ place. local ] {
973- ConstPropMode :: FullConstProp | ConstPropMode :: OnlyInsideOwnBlock => {
974- if self . use_ecx ( |this| this. ecx . statement ( statement) ) . is_some ( ) {
975- trace ! ( "propped discriminant into {:?}" , place) ;
976- } else {
944+ ConstPropMode :: OnlyPropagateInto | ConstPropMode :: NoPropagation => {
945+ trace ! ( "can't propagate into {:?}" , place) ;
946+ if place. local != RETURN_PLACE {
977947 Self :: remove_const ( & mut self . ecx , place. local ) ;
978948 }
979949 }
980- ConstPropMode :: OnlyPropagateInto | ConstPropMode :: NoPropagation => {
981- Self :: remove_const ( & mut self . ecx , place. local ) ;
982- }
950+ ConstPropMode :: FullConstProp => { }
983951 }
952+ } else {
953+ // Const prop failed, so erase the destination, ensuring that whatever happens
954+ // from here on, does not know about the previous value.
955+ // This is important in case we have
956+ // ```rust
957+ // let mut x = 42;
958+ // x = SOME_MUTABLE_STATIC;
959+ // // x must now be uninit
960+ // ```
961+ // FIXME: we overzealously erase the entire local, because that's easier to
962+ // implement.
963+ trace ! (
964+ "propagation into {:?} failed.
965+ Nuking the entire site from orbit, it's the only way to be sure" ,
966+ place,
967+ ) ;
968+ Self :: remove_const ( & mut self . ecx , place. local ) ;
984969 }
985- StatementKind :: StorageLive ( local) | StatementKind :: StorageDead ( local) => {
986- let frame = self . ecx . frame_mut ( ) ;
987- frame. locals [ local] . value =
988- if let StatementKind :: StorageLive ( _) = statement. kind {
989- LocalValue :: Live ( interpret:: Operand :: Immediate (
990- interpret:: Immediate :: Uninit ,
991- ) )
970+ }
971+ StatementKind :: SetDiscriminant { ref place, .. } => {
972+ match self . ecx . machine . can_const_prop [ place. local ] {
973+ ConstPropMode :: FullConstProp | ConstPropMode :: OnlyInsideOwnBlock => {
974+ if self . use_ecx ( |this| this. ecx . statement ( statement) ) . is_some ( ) {
975+ trace ! ( "propped discriminant into {:?}" , place) ;
992976 } else {
993- LocalValue :: Dead
994- } ;
977+ Self :: remove_const ( & mut self . ecx , place. local ) ;
978+ }
979+ }
980+ ConstPropMode :: OnlyPropagateInto | ConstPropMode :: NoPropagation => {
981+ Self :: remove_const ( & mut self . ecx , place. local ) ;
982+ }
995983 }
996- _ => { }
997984 }
985+ StatementKind :: StorageLive ( local) | StatementKind :: StorageDead ( local) => {
986+ let frame = self . ecx . frame_mut ( ) ;
987+ frame. locals [ local] . value = if let StatementKind :: StorageLive ( _) = statement. kind {
988+ LocalValue :: Live ( interpret:: Operand :: Immediate ( interpret:: Immediate :: Uninit ) )
989+ } else {
990+ LocalValue :: Dead
991+ } ;
992+ }
993+ _ => { }
998994 }
999995
1000996 self . super_statement ( statement, location) ;
0 commit comments