@@ -101,15 +101,24 @@ impl<'tcx> From<ImmTy<'tcx>> for Value<'tcx> {
101
101
}
102
102
103
103
impl < ' tcx > Value < ' tcx > {
104
- fn project ( & self , proj : impl Iterator < Item = Option < PlaceElem < ' tcx > > > ) -> Option < & Value < ' tcx > > {
104
+ fn project (
105
+ & self ,
106
+ proj : & [ PlaceElem < ' tcx > ] ,
107
+ prop : & ConstPropagator < ' _ , ' tcx > ,
108
+ ) -> Option < & Value < ' tcx > > {
105
109
let mut this = self ;
106
110
for proj in proj {
107
- this = match ( proj? , this) {
108
- ( ProjectionElem :: Field ( idx, _) , Value :: Aggregate { fields, .. } ) => {
111
+ this = match ( * proj, this) {
112
+ ( PlaceElem :: Field ( idx, _) , Value :: Aggregate { fields, .. } ) => {
109
113
fields. get ( idx) . unwrap_or ( & Value :: Uninit )
110
114
}
115
+ ( PlaceElem :: Index ( idx) , Value :: Aggregate { fields, .. } ) => {
116
+ let idx = prop. get_const ( idx. into ( ) ) ?. immediate ( ) ?;
117
+ let idx = prop. ecx . read_target_usize ( idx) . ok ( ) ?;
118
+ fields. get ( FieldIdx :: from_u32 ( idx. try_into ( ) . ok ( ) ?) ) . unwrap_or ( & Value :: Uninit )
119
+ }
111
120
(
112
- ProjectionElem :: ConstantIndex { offset, min_length : 1 , from_end : false } ,
121
+ PlaceElem :: ConstantIndex { offset, min_length : 1 , from_end : false } ,
113
122
Value :: Aggregate { fields, .. } ,
114
123
) => fields
115
124
. get ( FieldIdx :: from_u32 ( offset. try_into ( ) . ok ( ) ?) )
@@ -204,8 +213,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
204
213
}
205
214
206
215
fn get_const ( & self , place : Place < ' tcx > ) -> Option < & Value < ' tcx > > {
207
- self . locals [ place. local ]
208
- . project ( place. projection . iter ( ) . map ( |proj| self . try_eval_index_offset ( proj) ) )
216
+ self . locals [ place. local ] . project ( & place. projection , self )
209
217
}
210
218
211
219
/// Remove `local` from the pool of `Locals`. Allows writing to them,
@@ -696,21 +704,6 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
696
704
697
705
Some ( ( ) )
698
706
}
699
-
700
- fn try_eval_index_offset ( & self , proj : PlaceElem < ' tcx > ) -> Option < PlaceElem < ' tcx > > {
701
- Some ( match proj {
702
- ProjectionElem :: Index ( local) => {
703
- let val = self . get_const ( local. into ( ) ) ?;
704
- let op = val. immediate ( ) ?;
705
- ProjectionElem :: ConstantIndex {
706
- offset : self . ecx . read_target_usize ( op) . ok ( ) ?,
707
- min_length : 1 ,
708
- from_end : false ,
709
- }
710
- }
711
- other => other,
712
- } )
713
- }
714
707
}
715
708
716
709
impl < ' tcx > Visitor < ' tcx > for ConstPropagator < ' _ , ' tcx > {
0 commit comments