@@ -87,11 +87,11 @@ impl<'tcx> ConstValue<'tcx> {
87
87
RustcEncodable , RustcDecodable , Hash , HashStable ) ]
88
88
pub enum Scalar < Tag =( ) , Id =AllocId > {
89
89
/// The raw bytes of a simple value.
90
- Bits {
91
- /// The first `size` bytes are the value.
90
+ Raw {
91
+ /// The first `size` bytes of `data` are the value.
92
92
/// Do not try to read less or more bytes than that. The remaining bytes must be 0.
93
+ data : u128 ,
93
94
size : u8 ,
94
- bits : u128 ,
95
95
} ,
96
96
97
97
/// A pointer into an `Allocation`. An `Allocation` in the `memory` module has a list of
@@ -108,16 +108,16 @@ impl<Tag: fmt::Debug, Id: fmt::Debug> fmt::Debug for Scalar<Tag, Id> {
108
108
match self {
109
109
Scalar :: Ptr ( ptr) =>
110
110
write ! ( f, "{:?}" , ptr) ,
111
- & Scalar :: Bits { bits , size } => {
111
+ & Scalar :: Raw { data , size } => {
112
112
if size == 0 {
113
- assert_eq ! ( bits , 0 , "ZST value must be 0" ) ;
113
+ assert_eq ! ( data , 0 , "ZST value must be 0" ) ;
114
114
write ! ( f, "<ZST>" )
115
115
} else {
116
- assert_eq ! ( truncate( bits , Size :: from_bytes( size as u64 ) ) , bits ,
117
- "Scalar value {:#x} exceeds size of {} bytes" , bits , size) ;
116
+ assert_eq ! ( truncate( data , Size :: from_bytes( size as u64 ) ) , data ,
117
+ "Scalar value {:#x} exceeds size of {} bytes" , data , size) ;
118
118
// Format as hex number wide enough to fit any value of the given `size`.
119
- // So bits =20, size=1 will be "0x14", but with size=4 it'll be "0x00000014".
120
- write ! ( f, "0x{:>0width$x}" , bits , width=( size* 2 ) as usize )
119
+ // So data =20, size=1 will be "0x14", but with size=4 it'll be "0x00000014".
120
+ write ! ( f, "0x{:>0width$x}" , data , width=( size* 2 ) as usize )
121
121
}
122
122
}
123
123
}
@@ -128,7 +128,7 @@ impl<Tag> fmt::Display for Scalar<Tag> {
128
128
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
129
129
match self {
130
130
Scalar :: Ptr ( _) => write ! ( f, "a pointer" ) ,
131
- Scalar :: Bits { bits , .. } => write ! ( f, "{}" , bits ) ,
131
+ Scalar :: Raw { data , .. } => write ! ( f, "{}" , data ) ,
132
132
}
133
133
}
134
134
}
@@ -138,7 +138,7 @@ impl<'tcx> Scalar<()> {
138
138
pub fn with_tag < Tag > ( self , new_tag : Tag ) -> Scalar < Tag > {
139
139
match self {
140
140
Scalar :: Ptr ( ptr) => Scalar :: Ptr ( ptr. with_tag ( new_tag) ) ,
141
- Scalar :: Bits { bits , size } => Scalar :: Bits { bits , size } ,
141
+ Scalar :: Raw { data , size } => Scalar :: Raw { data , size } ,
142
142
}
143
143
}
144
144
@@ -155,31 +155,31 @@ impl<'tcx, Tag> Scalar<Tag> {
155
155
pub fn erase_tag ( self ) -> Scalar {
156
156
match self {
157
157
Scalar :: Ptr ( ptr) => Scalar :: Ptr ( ptr. erase_tag ( ) ) ,
158
- Scalar :: Bits { bits , size } => Scalar :: Bits { bits , size } ,
158
+ Scalar :: Raw { data , size } => Scalar :: Raw { data , size } ,
159
159
}
160
160
}
161
161
162
162
#[ inline]
163
163
pub fn ptr_null ( cx : & impl HasDataLayout ) -> Self {
164
- Scalar :: Bits {
165
- bits : 0 ,
164
+ Scalar :: Raw {
165
+ data : 0 ,
166
166
size : cx. data_layout ( ) . pointer_size . bytes ( ) as u8 ,
167
167
}
168
168
}
169
169
170
170
#[ inline]
171
171
pub fn zst ( ) -> Self {
172
- Scalar :: Bits { bits : 0 , size : 0 }
172
+ Scalar :: Raw { data : 0 , size : 0 }
173
173
}
174
174
175
175
#[ inline]
176
176
pub fn ptr_offset ( self , i : Size , cx : & impl HasDataLayout ) -> EvalResult < ' tcx , Self > {
177
177
let dl = cx. data_layout ( ) ;
178
178
match self {
179
- Scalar :: Bits { bits , size } => {
179
+ Scalar :: Raw { data , size } => {
180
180
assert_eq ! ( size as u64 , dl. pointer_size. bytes( ) ) ;
181
- Ok ( Scalar :: Bits {
182
- bits : dl. offset ( bits as u64 , i. bytes ( ) ) ? as u128 ,
181
+ Ok ( Scalar :: Raw {
182
+ data : dl. offset ( data as u64 , i. bytes ( ) ) ? as u128 ,
183
183
size,
184
184
} )
185
185
}
@@ -191,10 +191,10 @@ impl<'tcx, Tag> Scalar<Tag> {
191
191
pub fn ptr_wrapping_offset ( self , i : Size , cx : & impl HasDataLayout ) -> Self {
192
192
let dl = cx. data_layout ( ) ;
193
193
match self {
194
- Scalar :: Bits { bits , size } => {
194
+ Scalar :: Raw { data , size } => {
195
195
assert_eq ! ( size as u64 , dl. pointer_size. bytes( ) ) ;
196
- Scalar :: Bits {
197
- bits : dl. overflowing_offset ( bits as u64 , i. bytes ( ) ) . 0 as u128 ,
196
+ Scalar :: Raw {
197
+ data : dl. overflowing_offset ( data as u64 , i. bytes ( ) ) . 0 as u128 ,
198
198
size,
199
199
}
200
200
}
@@ -206,10 +206,10 @@ impl<'tcx, Tag> Scalar<Tag> {
206
206
pub fn ptr_signed_offset ( self , i : i64 , cx : & impl HasDataLayout ) -> EvalResult < ' tcx , Self > {
207
207
let dl = cx. data_layout ( ) ;
208
208
match self {
209
- Scalar :: Bits { bits , size } => {
209
+ Scalar :: Raw { data , size } => {
210
210
assert_eq ! ( size as u64 , dl. pointer_size( ) . bytes( ) ) ;
211
- Ok ( Scalar :: Bits {
212
- bits : dl. signed_offset ( bits as u64 , i) ? as u128 ,
211
+ Ok ( Scalar :: Raw {
212
+ data : dl. signed_offset ( data as u64 , i) ? as u128 ,
213
213
size,
214
214
} )
215
215
}
@@ -221,10 +221,10 @@ impl<'tcx, Tag> Scalar<Tag> {
221
221
pub fn ptr_wrapping_signed_offset ( self , i : i64 , cx : & impl HasDataLayout ) -> Self {
222
222
let dl = cx. data_layout ( ) ;
223
223
match self {
224
- Scalar :: Bits { bits , size } => {
224
+ Scalar :: Raw { data , size } => {
225
225
assert_eq ! ( size as u64 , dl. pointer_size. bytes( ) ) ;
226
- Scalar :: Bits {
227
- bits : dl. overflowing_signed_offset ( bits as u64 , i128:: from ( i) ) . 0 as u128 ,
226
+ Scalar :: Raw {
227
+ data : dl. overflowing_signed_offset ( data as u64 , i128:: from ( i) ) . 0 as u128 ,
228
228
size,
229
229
}
230
230
}
@@ -237,9 +237,9 @@ impl<'tcx, Tag> Scalar<Tag> {
237
237
#[ inline]
238
238
pub fn get_ptr_offset ( self , cx : & impl HasDataLayout ) -> Size {
239
239
match self {
240
- Scalar :: Bits { bits , size } => {
240
+ Scalar :: Raw { data , size } => {
241
241
assert_eq ! ( size as u64 , cx. pointer_size( ) . bytes( ) ) ;
242
- Size :: from_bytes ( bits as u64 )
242
+ Size :: from_bytes ( data as u64 )
243
243
}
244
244
Scalar :: Ptr ( ptr) => ptr. offset ,
245
245
}
@@ -248,30 +248,30 @@ impl<'tcx, Tag> Scalar<Tag> {
248
248
#[ inline]
249
249
pub fn is_null_ptr ( self , cx : & impl HasDataLayout ) -> bool {
250
250
match self {
251
- Scalar :: Bits { bits , size } => {
251
+ Scalar :: Raw { data , size } => {
252
252
assert_eq ! ( size as u64 , cx. data_layout( ) . pointer_size. bytes( ) ) ;
253
- bits == 0
253
+ data == 0
254
254
} ,
255
255
Scalar :: Ptr ( _) => false ,
256
256
}
257
257
}
258
258
259
259
#[ inline]
260
260
pub fn from_bool ( b : bool ) -> Self {
261
- Scalar :: Bits { bits : b as u128 , size : 1 }
261
+ Scalar :: Raw { data : b as u128 , size : 1 }
262
262
}
263
263
264
264
#[ inline]
265
265
pub fn from_char ( c : char ) -> Self {
266
- Scalar :: Bits { bits : c as u128 , size : 4 }
266
+ Scalar :: Raw { data : c as u128 , size : 4 }
267
267
}
268
268
269
269
#[ inline]
270
270
pub fn from_uint ( i : impl Into < u128 > , size : Size ) -> Self {
271
271
let i = i. into ( ) ;
272
272
debug_assert_eq ! ( truncate( i, size) , i,
273
273
"Unsigned value {} does not fit in {} bits" , i, size. bits( ) ) ;
274
- Scalar :: Bits { bits : i, size : size. bytes ( ) as u8 }
274
+ Scalar :: Raw { data : i, size : size. bytes ( ) as u8 }
275
275
}
276
276
277
277
#[ inline]
@@ -281,26 +281,26 @@ impl<'tcx, Tag> Scalar<Tag> {
281
281
let truncated = truncate ( i as u128 , size) ;
282
282
debug_assert_eq ! ( sign_extend( truncated, size) as i128 , i,
283
283
"Signed value {} does not fit in {} bits" , i, size. bits( ) ) ;
284
- Scalar :: Bits { bits : truncated, size : size. bytes ( ) as u8 }
284
+ Scalar :: Raw { data : truncated, size : size. bytes ( ) as u8 }
285
285
}
286
286
287
287
#[ inline]
288
288
pub fn from_f32 ( f : f32 ) -> Self {
289
- Scalar :: Bits { bits : f. to_bits ( ) as u128 , size : 4 }
289
+ Scalar :: Raw { data : f. to_bits ( ) as u128 , size : 4 }
290
290
}
291
291
292
292
#[ inline]
293
293
pub fn from_f64 ( f : f64 ) -> Self {
294
- Scalar :: Bits { bits : f. to_bits ( ) as u128 , size : 8 }
294
+ Scalar :: Raw { data : f. to_bits ( ) as u128 , size : 8 }
295
295
}
296
296
297
297
#[ inline]
298
298
pub fn to_bits ( self , target_size : Size ) -> EvalResult < ' tcx , u128 > {
299
299
match self {
300
- Scalar :: Bits { bits , size } => {
300
+ Scalar :: Raw { data , size } => {
301
301
assert_eq ! ( target_size. bytes( ) , size as u64 ) ;
302
302
assert_ne ! ( size, 0 , "to_bits cannot be used with zsts" ) ;
303
- Ok ( bits )
303
+ Ok ( data )
304
304
}
305
305
Scalar :: Ptr ( _) => err ! ( ReadPointerAsBytes ) ,
306
306
}
@@ -309,16 +309,16 @@ impl<'tcx, Tag> Scalar<Tag> {
309
309
#[ inline]
310
310
pub fn to_ptr ( self ) -> EvalResult < ' tcx , Pointer < Tag > > {
311
311
match self {
312
- Scalar :: Bits { bits : 0 , .. } => err ! ( InvalidNullPointerUsage ) ,
313
- Scalar :: Bits { .. } => err ! ( ReadBytesAsPointer ) ,
312
+ Scalar :: Raw { data : 0 , .. } => err ! ( InvalidNullPointerUsage ) ,
313
+ Scalar :: Raw { .. } => err ! ( ReadBytesAsPointer ) ,
314
314
Scalar :: Ptr ( p) => Ok ( p) ,
315
315
}
316
316
}
317
317
318
318
#[ inline]
319
319
pub fn is_bits ( self ) -> bool {
320
320
match self {
321
- Scalar :: Bits { .. } => true ,
321
+ Scalar :: Raw { .. } => true ,
322
322
_ => false ,
323
323
}
324
324
}
@@ -333,8 +333,8 @@ impl<'tcx, Tag> Scalar<Tag> {
333
333
334
334
pub fn to_bool ( self ) -> EvalResult < ' tcx , bool > {
335
335
match self {
336
- Scalar :: Bits { bits : 0 , size : 1 } => Ok ( false ) ,
337
- Scalar :: Bits { bits : 1 , size : 1 } => Ok ( true ) ,
336
+ Scalar :: Raw { data : 0 , size : 1 } => Ok ( false ) ,
337
+ Scalar :: Raw { data : 1 , size : 1 } => Ok ( true ) ,
338
338
_ => err ! ( InvalidBool ) ,
339
339
}
340
340
}
0 commit comments