@@ -252,6 +252,11 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for ConstPropMachine<'mir, 'tcx>
252
252
throw_machine_stop_str ! ( "tried to write to a local that is marked as not propagatable" )
253
253
}
254
254
if frame == 0 && ecx. machine . only_propagate_inside_block_locals . contains ( local) {
255
+ trace ! (
256
+ "mutating local {:?} which is restricted to its block. \
257
+ Will remove it from const-prop after block is finished.",
258
+ local
259
+ ) ;
255
260
ecx. machine . written_only_inside_own_block_locals . insert ( local) ;
256
261
}
257
262
ecx. machine . stack [ frame] . locals [ local] . access_mut ( )
@@ -427,6 +432,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
427
432
match f ( self ) {
428
433
Ok ( val) => Some ( val) ,
429
434
Err ( error) => {
435
+ trace ! ( "InterpCx operation failed: {:?}" , error) ;
430
436
// Some errors shouldn't come up because creating them causes
431
437
// an allocation, which we should avoid. When that happens,
432
438
// dedicated error variants should be introduced instead.
@@ -969,10 +975,10 @@ impl<'tcx> Visitor<'tcx> for CanConstProp {
969
975
ConstPropMode :: OnlyPropagateInto => { }
970
976
other @ ConstPropMode :: FullConstProp => {
971
977
trace ! (
972
- "local {:?} can't be propagated because of multiple assignments" ,
973
- local,
978
+ "local {:?} can't be propagated because of multiple assignments. Previous state: {:?} " ,
979
+ local, other ,
974
980
) ;
975
- * other = ConstPropMode :: OnlyPropagateInto ;
981
+ * other = ConstPropMode :: OnlyInsideOwnBlock ;
976
982
}
977
983
}
978
984
}
@@ -1089,6 +1095,20 @@ impl<'mir, 'tcx> MutVisitor<'tcx> for ConstPropagator<'mir, 'tcx> {
1089
1095
}
1090
1096
} else {
1091
1097
match statement. kind {
1098
+ StatementKind :: SetDiscriminant { ref place, .. } => {
1099
+ match self . ecx . machine . can_const_prop [ place. local ] {
1100
+ ConstPropMode :: FullConstProp | ConstPropMode :: OnlyInsideOwnBlock => {
1101
+ if self . use_ecx ( |this| this. ecx . statement ( statement) ) . is_some ( ) {
1102
+ trace ! ( "propped discriminant into {:?}" , place) ;
1103
+ } else {
1104
+ Self :: remove_const ( & mut self . ecx , place. local ) ;
1105
+ }
1106
+ }
1107
+ ConstPropMode :: OnlyPropagateInto | ConstPropMode :: NoPropagation => {
1108
+ Self :: remove_const ( & mut self . ecx , place. local ) ;
1109
+ }
1110
+ }
1111
+ }
1092
1112
StatementKind :: StorageLive ( local) | StatementKind :: StorageDead ( local) => {
1093
1113
let frame = self . ecx . frame_mut ( ) ;
1094
1114
frame. locals [ local] . value =
0 commit comments