4
4
use std:: fmt:: Debug ;
5
5
6
6
use rustc_const_eval:: interpret:: { ImmTy , Projectable } ;
7
- use rustc_const_eval:: interpret:: { InterpCx , InterpResult , OpTy , Scalar } ;
7
+ use rustc_const_eval:: interpret:: { InterpCx , InterpResult , Scalar } ;
8
8
use rustc_data_structures:: fx:: FxHashSet ;
9
9
use rustc_hir:: def:: DefKind ;
10
10
use rustc_hir:: HirId ;
@@ -83,20 +83,14 @@ struct ConstPropagator<'mir, 'tcx> {
83
83
84
84
#[ derive( Debug , Clone ) ]
85
85
enum Value < ' tcx > {
86
- Immediate ( OpTy < ' tcx > ) ,
86
+ Immediate ( ImmTy < ' tcx > ) ,
87
87
Aggregate { variant : VariantIdx , fields : IndexVec < FieldIdx , Value < ' tcx > > } ,
88
88
Uninit ,
89
89
}
90
90
91
- impl < ' tcx > From < OpTy < ' tcx > > for Value < ' tcx > {
92
- fn from ( v : OpTy < ' tcx > ) -> Self {
93
- Self :: Immediate ( v)
94
- }
95
- }
96
-
97
91
impl < ' tcx > From < ImmTy < ' tcx > > for Value < ' tcx > {
98
92
fn from ( v : ImmTy < ' tcx > ) -> Self {
99
- Self :: Immediate ( v. into ( ) )
93
+ Self :: Immediate ( v)
100
94
}
101
95
}
102
96
@@ -149,7 +143,7 @@ impl<'tcx> Value<'tcx> {
149
143
Some ( this)
150
144
}
151
145
152
- fn immediate ( & self ) -> Option < & OpTy < ' tcx > > {
146
+ fn immediate ( & self ) -> Option < & ImmTy < ' tcx > > {
153
147
match self {
154
148
Value :: Immediate ( op) => Some ( op) ,
155
149
_ => None ,
@@ -260,7 +254,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
260
254
}
261
255
262
256
/// Returns the value, if any, of evaluating `c`.
263
- fn eval_constant ( & mut self , c : & ConstOperand < ' tcx > ) -> Option < OpTy < ' tcx > > {
257
+ fn eval_constant ( & mut self , c : & ConstOperand < ' tcx > ) -> Option < ImmTy < ' tcx > > {
264
258
// FIXME we need to revisit this for #67176
265
259
if c. has_param ( ) {
266
260
return None ;
@@ -274,22 +268,24 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
274
268
// manually normalized.
275
269
let val = self . tcx . try_normalize_erasing_regions ( self . param_env , c. const_ ) . ok ( ) ?;
276
270
277
- self . use_ecx ( |this| this. ecx . eval_mir_constant ( & val, Some ( c. span ) , None ) )
271
+ self . use_ecx ( |this| this. ecx . eval_mir_constant ( & val, Some ( c. span ) , None ) ) ?
272
+ . as_mplace_or_imm ( )
273
+ . right ( )
278
274
}
279
275
280
276
/// Returns the value, if any, of evaluating `place`.
281
277
#[ instrument( level = "trace" , skip( self ) , ret) ]
282
- fn eval_place ( & mut self , place : Place < ' tcx > ) -> Option < OpTy < ' tcx > > {
278
+ fn eval_place ( & mut self , place : Place < ' tcx > ) -> Option < ImmTy < ' tcx > > {
283
279
match self . get_const ( place) ? {
284
- Value :: Immediate ( op ) => Some ( op . clone ( ) ) ,
280
+ Value :: Immediate ( imm ) => Some ( imm . clone ( ) ) ,
285
281
Value :: Aggregate { .. } => None ,
286
282
Value :: Uninit => None ,
287
283
}
288
284
}
289
285
290
286
/// Returns the value, if any, of evaluating `op`. Calls upon `eval_constant`
291
287
/// or `eval_place`, depending on the variant of `Operand` used.
292
- fn eval_operand ( & mut self , op : & Operand < ' tcx > ) -> Option < OpTy < ' tcx > > {
288
+ fn eval_operand ( & mut self , op : & Operand < ' tcx > ) -> Option < ImmTy < ' tcx > > {
293
289
match * op {
294
290
Operand :: Constant ( ref c) => self . eval_constant ( c) ,
295
291
Operand :: Move ( place) | Operand :: Copy ( place) => self . eval_place ( place) ,
@@ -668,13 +664,12 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
668
664
let to = self . ecx . layout_of ( to) . ok ( ) ?;
669
665
// `offset` for immediates only supports scalar/scalar-pair ABIs,
670
666
// so bail out if the target is not one.
671
- if value. as_mplace_or_imm ( ) . is_right ( ) {
672
- match ( value. layout . abi , to. abi ) {
673
- ( Abi :: Scalar ( ..) , Abi :: Scalar ( ..) ) => { }
674
- ( Abi :: ScalarPair ( ..) , Abi :: ScalarPair ( ..) ) => { }
675
- _ => return None ,
676
- }
667
+ match ( value. layout . abi , to. abi ) {
668
+ ( Abi :: Scalar ( ..) , Abi :: Scalar ( ..) ) => { }
669
+ ( Abi :: ScalarPair ( ..) , Abi :: ScalarPair ( ..) ) => { }
670
+ _ => return None ,
677
671
}
672
+
678
673
value. offset ( Size :: ZERO , to, & self . ecx ) . ok ( ) ?. into ( )
679
674
}
680
675
_ => return None ,
0 commit comments