@@ -111,23 +111,24 @@ pub(super) fn op_to_const<'tcx>(
111
111
ecx : & CompileTimeEvalContext < ' _ , ' tcx > ,
112
112
op : & OpTy < ' tcx > ,
113
113
) -> ConstValue < ' tcx > {
114
+ let tcx = * ecx. tcx ;
114
115
// Handle ZST consistently and early.
115
116
if op. layout . is_zst ( ) {
116
- return ConstValue :: ZeroSized ;
117
+ return ConstValue :: zero_sized ( tcx ) ;
117
118
}
118
119
119
- // All scalar types should be stored as `ConstValue ::Scalar`. This is needed to make
120
- // `ConstValue ::try_to_scalar` efficient; we want that to work for *all* constants of scalar
120
+ // All scalar types should be stored as `ConstValueKind ::Scalar`. This is needed to make
121
+ // `ConstValueKind ::try_to_scalar` efficient; we want that to work for *all* constants of scalar
121
122
// type (it's used throughout the compiler and having it work just on literals is not enough)
122
123
// and we want it to be fast (i.e., don't go to an `Allocation` and reconstruct the `Scalar`
123
124
// from its byte-serialized form).
124
125
let force_as_immediate = match op. layout . abi {
125
126
Abi :: Scalar ( abi:: Scalar :: Initialized { .. } ) => true ,
126
- // We don't *force* `ConstValue ::Slice` for `ScalarPair`. This has the advantage that if the
127
+ // We don't *force* `ConstValueKind ::Slice` for `ScalarPair`. This has the advantage that if the
127
128
// input `op` is a place, then turning it into a `ConstValue` and back into a `OpTy` will
128
129
// not have to generate any duplicate allocations (we preserve the original `AllocId` in
129
- // `ConstValue ::Indirect`). It means accessing the contents of a slice can be slow (since
130
- // they can be stored as `ConstValue ::Indirect`), but that's not relevant since we barely
130
+ // `ConstValueKind ::Indirect`). It means accessing the contents of a slice can be slow (since
131
+ // they can be stored as `ConstValueKind ::Indirect`), but that's not relevant since we barely
131
132
// ever have to do this. (`try_get_slice_bytes_for_diagnostics` exists to provide this
132
133
// functionality.)
133
134
_ => false ,
@@ -145,26 +146,26 @@ pub(super) fn op_to_const<'tcx>(
145
146
// We know `offset` is relative to the allocation, so we can use `into_parts`.
146
147
let ( alloc_id, offset) = mplace. ptr ( ) . into_parts ( ) ;
147
148
let alloc_id = alloc_id. expect ( "cannot have `fake` place fot non-ZST type" ) ;
148
- ConstValue :: Indirect { alloc_id, offset }
149
+ ConstValue :: from_memory ( tcx , alloc_id, offset)
149
150
}
150
151
// see comment on `let force_as_immediate` above
151
152
Right ( imm) => match * imm {
152
- Immediate :: Scalar ( x) => ConstValue :: Scalar ( x) ,
153
+ Immediate :: Scalar ( x) => ConstValue :: from_scalar ( tcx , x) ,
153
154
Immediate :: ScalarPair ( a, b) => {
154
155
debug ! ( "ScalarPair(a: {:?}, b: {:?})" , a, b) ;
155
156
// FIXME: assert that this has an appropriate type.
156
157
// Currently we actually get here for non-[u8] slices during valtree construction!
157
158
let msg = "`op_to_const` on an immediate scalar pair must only be used on slice references to actually allocated memory" ;
158
159
// We know `offset` is relative to the allocation, so we can use `into_parts`.
159
- // We use `ConstValue ::Slice` so that we don't have to generate an allocation for
160
- // `ConstValue ::Indirect` here.
160
+ // We use `ConstValueKind ::Slice` so that we don't have to generate an allocation for
161
+ // `ConstValueKind ::Indirect` here.
161
162
let ( alloc_id, offset) = a. to_pointer ( ecx) . expect ( msg) . into_parts ( ) ;
162
163
let alloc_id = alloc_id. expect ( msg) ;
163
164
let data = ecx. tcx . global_alloc ( alloc_id) . unwrap_memory ( ) ;
164
165
let start = offset. bytes_usize ( ) ;
165
166
let len = b. to_target_usize ( ecx) . expect ( msg) ;
166
167
let len: usize = len. try_into ( ) . unwrap ( ) ;
167
- ConstValue :: Slice { data, start, end : start + len }
168
+ ConstValue :: from_slice ( tcx , data, start, start + len)
168
169
}
169
170
Immediate :: Uninit => bug ! ( "`Uninit` is not a valid value for {}" , op. layout. ty) ,
170
171
} ,
0 commit comments