@@ -87,11 +87,11 @@ impl<'tcx> ConstValue<'tcx> {
8787 RustcEncodable , RustcDecodable , Hash , HashStable ) ]
8888pub enum Scalar < Tag =( ) , Id =AllocId > {
8989 /// 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.
9292 /// Do not try to read less or more bytes than that. The remaining bytes must be 0.
93+ data : u128 ,
9394 size : u8 ,
94- bits : u128 ,
9595 } ,
9696
9797 /// 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> {
108108 match self {
109109 Scalar :: Ptr ( ptr) =>
110110 write ! ( f, "{:?}" , ptr) ,
111- & Scalar :: Bits { bits , size } => {
111+ & Scalar :: Raw { data , size } => {
112112 if size == 0 {
113- assert_eq ! ( bits , 0 , "ZST value must be 0" ) ;
113+ assert_eq ! ( data , 0 , "ZST value must be 0" ) ;
114114 write ! ( f, "<ZST>" )
115115 } 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) ;
118118 // 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 )
121121 }
122122 }
123123 }
@@ -128,7 +128,7 @@ impl<Tag> fmt::Display for Scalar<Tag> {
128128 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
129129 match self {
130130 Scalar :: Ptr ( _) => write ! ( f, "a pointer" ) ,
131- Scalar :: Bits { bits , .. } => write ! ( f, "{}" , bits ) ,
131+ Scalar :: Raw { data , .. } => write ! ( f, "{}" , data ) ,
132132 }
133133 }
134134}
@@ -138,7 +138,7 @@ impl<'tcx> Scalar<()> {
138138 pub fn with_tag < Tag > ( self , new_tag : Tag ) -> Scalar < Tag > {
139139 match self {
140140 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 } ,
142142 }
143143 }
144144
@@ -155,31 +155,31 @@ impl<'tcx, Tag> Scalar<Tag> {
155155 pub fn erase_tag ( self ) -> Scalar {
156156 match self {
157157 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 } ,
159159 }
160160 }
161161
162162 #[ inline]
163163 pub fn ptr_null ( cx : & impl HasDataLayout ) -> Self {
164- Scalar :: Bits {
165- bits : 0 ,
164+ Scalar :: Raw {
165+ data : 0 ,
166166 size : cx. data_layout ( ) . pointer_size . bytes ( ) as u8 ,
167167 }
168168 }
169169
170170 #[ inline]
171171 pub fn zst ( ) -> Self {
172- Scalar :: Bits { bits : 0 , size : 0 }
172+ Scalar :: Raw { data : 0 , size : 0 }
173173 }
174174
175175 #[ inline]
176176 pub fn ptr_offset ( self , i : Size , cx : & impl HasDataLayout ) -> EvalResult < ' tcx , Self > {
177177 let dl = cx. data_layout ( ) ;
178178 match self {
179- Scalar :: Bits { bits , size } => {
179+ Scalar :: Raw { data , size } => {
180180 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 ,
183183 size,
184184 } )
185185 }
@@ -191,10 +191,10 @@ impl<'tcx, Tag> Scalar<Tag> {
191191 pub fn ptr_wrapping_offset ( self , i : Size , cx : & impl HasDataLayout ) -> Self {
192192 let dl = cx. data_layout ( ) ;
193193 match self {
194- Scalar :: Bits { bits , size } => {
194+ Scalar :: Raw { data , size } => {
195195 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 ,
198198 size,
199199 }
200200 }
@@ -206,10 +206,10 @@ impl<'tcx, Tag> Scalar<Tag> {
206206 pub fn ptr_signed_offset ( self , i : i64 , cx : & impl HasDataLayout ) -> EvalResult < ' tcx , Self > {
207207 let dl = cx. data_layout ( ) ;
208208 match self {
209- Scalar :: Bits { bits , size } => {
209+ Scalar :: Raw { data , size } => {
210210 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 ,
213213 size,
214214 } )
215215 }
@@ -221,10 +221,10 @@ impl<'tcx, Tag> Scalar<Tag> {
221221 pub fn ptr_wrapping_signed_offset ( self , i : i64 , cx : & impl HasDataLayout ) -> Self {
222222 let dl = cx. data_layout ( ) ;
223223 match self {
224- Scalar :: Bits { bits , size } => {
224+ Scalar :: Raw { data , size } => {
225225 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 ,
228228 size,
229229 }
230230 }
@@ -237,9 +237,9 @@ impl<'tcx, Tag> Scalar<Tag> {
237237 #[ inline]
238238 pub fn get_ptr_offset ( self , cx : & impl HasDataLayout ) -> Size {
239239 match self {
240- Scalar :: Bits { bits , size } => {
240+ Scalar :: Raw { data , size } => {
241241 assert_eq ! ( size as u64 , cx. pointer_size( ) . bytes( ) ) ;
242- Size :: from_bytes ( bits as u64 )
242+ Size :: from_bytes ( data as u64 )
243243 }
244244 Scalar :: Ptr ( ptr) => ptr. offset ,
245245 }
@@ -248,30 +248,30 @@ impl<'tcx, Tag> Scalar<Tag> {
248248 #[ inline]
249249 pub fn is_null_ptr ( self , cx : & impl HasDataLayout ) -> bool {
250250 match self {
251- Scalar :: Bits { bits , size } => {
251+ Scalar :: Raw { data , size } => {
252252 assert_eq ! ( size as u64 , cx. data_layout( ) . pointer_size. bytes( ) ) ;
253- bits == 0
253+ data == 0
254254 } ,
255255 Scalar :: Ptr ( _) => false ,
256256 }
257257 }
258258
259259 #[ inline]
260260 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 }
262262 }
263263
264264 #[ inline]
265265 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 }
267267 }
268268
269269 #[ inline]
270270 pub fn from_uint ( i : impl Into < u128 > , size : Size ) -> Self {
271271 let i = i. into ( ) ;
272272 debug_assert_eq ! ( truncate( i, size) , i,
273273 "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 }
275275 }
276276
277277 #[ inline]
@@ -281,26 +281,26 @@ impl<'tcx, Tag> Scalar<Tag> {
281281 let truncated = truncate ( i as u128 , size) ;
282282 debug_assert_eq ! ( sign_extend( truncated, size) as i128 , i,
283283 "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 }
285285 }
286286
287287 #[ inline]
288288 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 }
290290 }
291291
292292 #[ inline]
293293 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 }
295295 }
296296
297297 #[ inline]
298298 pub fn to_bits ( self , target_size : Size ) -> EvalResult < ' tcx , u128 > {
299299 match self {
300- Scalar :: Bits { bits , size } => {
300+ Scalar :: Raw { data , size } => {
301301 assert_eq ! ( target_size. bytes( ) , size as u64 ) ;
302302 assert_ne ! ( size, 0 , "to_bits cannot be used with zsts" ) ;
303- Ok ( bits )
303+ Ok ( data )
304304 }
305305 Scalar :: Ptr ( _) => err ! ( ReadPointerAsBytes ) ,
306306 }
@@ -309,16 +309,16 @@ impl<'tcx, Tag> Scalar<Tag> {
309309 #[ inline]
310310 pub fn to_ptr ( self ) -> EvalResult < ' tcx , Pointer < Tag > > {
311311 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 ) ,
314314 Scalar :: Ptr ( p) => Ok ( p) ,
315315 }
316316 }
317317
318318 #[ inline]
319319 pub fn is_bits ( self ) -> bool {
320320 match self {
321- Scalar :: Bits { .. } => true ,
321+ Scalar :: Raw { .. } => true ,
322322 _ => false ,
323323 }
324324 }
@@ -333,8 +333,8 @@ impl<'tcx, Tag> Scalar<Tag> {
333333
334334 pub fn to_bool ( self ) -> EvalResult < ' tcx , bool > {
335335 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 ) ,
338338 _ => err ! ( InvalidBool ) ,
339339 }
340340 }
0 commit comments