@@ -335,34 +335,9 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
335
335
}
336
336
337
337
fn get_const ( & self , local : Local ) -> Option < Const < ' tcx > > {
338
- let l = & self . ecx . frame ( ) . locals [ local] ;
339
-
340
- // If the local is `Unitialized` or `Dead` then we haven't propagated a value into it.
341
- //
342
- // `InterpCx::access_local()` mostly takes care of this for us however, for ZSTs,
343
- // it will synthesize a value for us. In doing so, that will cause the
344
- // `get_const(l).is_empty()` assert right before we call `set_const()` in `visit_statement`
345
- // to fail.
346
- if let LocalValue :: Uninitialized | LocalValue :: Dead = l. value {
347
- return None ;
348
- }
349
-
350
338
self . ecx . access_local ( self . ecx . frame ( ) , local, None ) . ok ( )
351
339
}
352
340
353
- fn set_const ( & mut self , local : Local , c : Const < ' tcx > ) {
354
- let frame = self . ecx . frame_mut ( ) ;
355
-
356
- if let Some ( layout) = frame. locals [ local] . layout . get ( ) {
357
- debug_assert_eq ! ( c. layout, layout) ;
358
- }
359
-
360
- frame. locals [ local] = LocalState {
361
- value : LocalValue :: Live ( * c) ,
362
- layout : Cell :: new ( Some ( c. layout ) ) ,
363
- } ;
364
- }
365
-
366
341
fn remove_const ( & mut self , local : Local ) {
367
342
self . ecx . frame_mut ( ) . locals [ local] = LocalState {
368
343
value : LocalValue :: Uninitialized ,
@@ -735,10 +710,8 @@ impl<'mir, 'tcx> MutVisitor<'tcx> for ConstPropagator<'mir, 'tcx> {
735
710
place) {
736
711
trace ! ( "checking whether {:?} can be stored to {:?}" , value, local) ;
737
712
if self . can_const_prop [ local] {
738
- trace ! ( "storing {:?} to {:?}" , value, local) ;
739
- assert ! ( self . get_const( local) . is_none( ) ||
740
- self . get_const( local) == Some ( value) ) ;
741
- self . set_const ( local, value) ;
713
+ trace ! ( "stored {:?} to {:?}" , value, local) ;
714
+ assert_eq ! ( self . get_const( local) , Some ( value) ) ;
742
715
743
716
if self . should_const_prop ( ) {
744
717
self . replace_with_const (
@@ -747,6 +720,9 @@ impl<'mir, 'tcx> MutVisitor<'tcx> for ConstPropagator<'mir, 'tcx> {
747
720
statement. source_info ,
748
721
) ;
749
722
}
723
+ } else {
724
+ trace ! ( "can't propagate {:?} to {:?}" , value, local) ;
725
+ self . remove_const ( local) ;
750
726
}
751
727
}
752
728
}
0 commit comments