Skip to content

Commit 082da0c

Browse files
committed
rename Scalar::Bits to Scalar::Raw and bits field to data
1 parent 572892c commit 082da0c

File tree

17 files changed

+93
-107
lines changed

17 files changed

+93
-107
lines changed

src/librustc/mir/interpret/allocation.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -388,11 +388,11 @@ impl<'tcx, Tag: Copy, Extra: AllocationExtra<Tag>> Allocation<Tag, Extra> {
388388
val.offset.bytes() as u128
389389
}
390390

391-
Scalar::Bits { bits, size } => {
391+
Scalar::Raw { data, size } => {
392392
assert_eq!(size as u64, type_size.bytes());
393-
debug_assert_eq!(truncate(bits, Size::from_bytes(size.into())), bits,
393+
debug_assert_eq!(truncate(data, Size::from_bytes(size.into())), data,
394394
"Unexpected value of size {} when writing to memory", size);
395-
bits
395+
data
396396
},
397397
};
398398

src/librustc/mir/interpret/value.rs

Lines changed: 44 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,11 @@ impl<'tcx> ConstValue<'tcx> {
8787
RustcEncodable, RustcDecodable, Hash, HashStable)]
8888
pub 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
}

src/librustc/mir/mod.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1669,10 +1669,7 @@ impl<'tcx> TerminatorKind<'tcx> {
16691669
.map(|&u| {
16701670
tcx.mk_const(ty::Const {
16711671
val: ConstValue::Scalar(
1672-
Scalar::Bits {
1673-
bits: u,
1674-
size: size.bytes() as u8,
1675-
}.into(),
1672+
Scalar::from_uint(u, size).into(),
16761673
),
16771674
ty: switch_ty,
16781675
}).to_string().into()

src/librustc/ty/context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1001,7 +1001,7 @@ impl<'tcx> CommonConsts<'tcx> {
10011001

10021002
CommonConsts {
10031003
err: mk_const(ty::Const {
1004-
val: ConstValue::Scalar(Scalar::Bits { bits: 0, size: 0 }),
1004+
val: ConstValue::Scalar(Scalar::zst()),
10051005
ty: types.err,
10061006
}),
10071007
}

src/librustc/ty/print/pretty.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -845,34 +845,34 @@ pub trait PrettyPrinter<'gcx: 'tcx, 'tcx>:
845845
p!(write("{}", name));
846846
return Ok(self);
847847
}
848-
if let ConstValue::Scalar(Scalar::Bits { bits, .. }) = ct.val {
848+
if let ConstValue::Scalar(Scalar::Raw { data, .. }) = ct.val {
849849
match ct.ty.sty {
850850
ty::Bool => {
851-
p!(write("{}", if bits == 0 { "false" } else { "true" }));
851+
p!(write("{}", if data == 0 { "false" } else { "true" }));
852852
return Ok(self);
853853
},
854854
ty::Float(ast::FloatTy::F32) => {
855-
p!(write("{}f32", Single::from_bits(bits)));
855+
p!(write("{}f32", Single::from_bits(data)));
856856
return Ok(self);
857857
},
858858
ty::Float(ast::FloatTy::F64) => {
859-
p!(write("{}f64", Double::from_bits(bits)));
859+
p!(write("{}f64", Double::from_bits(data)));
860860
return Ok(self);
861861
},
862862
ty::Uint(ui) => {
863-
p!(write("{}{}", bits, ui));
863+
p!(write("{}{}", data, ui));
864864
return Ok(self);
865865
},
866866
ty::Int(i) =>{
867867
let ty = self.tcx().lift_to_global(&ct.ty).unwrap();
868868
let size = self.tcx().layout_of(ty::ParamEnv::empty().and(ty))
869869
.unwrap()
870870
.size;
871-
p!(write("{}{}", sign_extend(bits, size) as i128, i));
871+
p!(write("{}{}", sign_extend(data, size) as i128, i));
872872
return Ok(self);
873873
},
874874
ty::Char => {
875-
p!(write("{:?}", ::std::char::from_u32(bits as u32).unwrap()));
875+
p!(write("{:?}", ::std::char::from_u32(data as u32).unwrap()));
876876
return Ok(self);
877877
}
878878
_ => {},

src/librustc/ty/relate.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,7 @@ where
613613
(ConstValue::Placeholder(p1), ConstValue::Placeholder(p2)) if p1 == p2 => {
614614
Ok(a)
615615
}
616-
(ConstValue::Scalar(Scalar::Bits { .. }), _) if a == b => {
616+
(ConstValue::Scalar(Scalar::Raw { .. }), _) if a == b => {
617617
Ok(a)
618618
}
619619
(ConstValue::ByRef(..), _) => {

src/librustc/ty/sty.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use crate::hir;
44
use crate::hir::def_id::DefId;
55
use crate::infer::canonical::Canonical;
6-
use crate::mir::interpret::{ConstValue, truncate};
6+
use crate::mir::interpret::ConstValue;
77
use crate::middle::region;
88
use polonius_engine::Atom;
99
use rustc_data_structures::indexed_vec::Idx;
@@ -2232,14 +2232,12 @@ impl<'tcx> Const<'tcx> {
22322232
let size = tcx.layout_of(ty).unwrap_or_else(|e| {
22332233
panic!("could not compute layout for {:?}: {:?}", ty, e)
22342234
}).size;
2235-
let truncated = truncate(bits, size);
2236-
assert_eq!(truncated, bits, "from_bits called with untruncated value");
2237-
Self::from_scalar(tcx, Scalar::Bits { bits, size: size.bytes() as u8 }, ty.value)
2235+
Self::from_scalar(tcx, Scalar::from_uint(bits, size), ty.value)
22382236
}
22392237

22402238
#[inline]
22412239
pub fn zero_sized(tcx: TyCtxt<'_, '_, 'tcx>, ty: Ty<'tcx>) -> &'tcx Self {
2242-
Self::from_scalar(tcx, Scalar::Bits { bits: 0, size: 0 }, ty)
2240+
Self::from_scalar(tcx, Scalar::zst(), ty)
22432241
}
22442242

22452243
#[inline]

src/librustc_codegen_llvm/common.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -294,13 +294,13 @@ impl ConstMethods<'tcx> for CodegenCx<'ll, 'tcx> {
294294
) -> &'ll Value {
295295
let bitsize = if layout.is_bool() { 1 } else { layout.value.size(self).bits() };
296296
match cv {
297-
Scalar::Bits { size: 0, .. } => {
297+
Scalar::Raw { size: 0, .. } => {
298298
assert_eq!(0, layout.value.size(self).bytes());
299299
self.const_undef(self.type_ix(0))
300300
},
301-
Scalar::Bits { bits, size } => {
301+
Scalar::Raw { data, size } => {
302302
assert_eq!(size as u64, layout.value.size(self).bytes());
303-
let llval = self.const_uint_big(self.type_ix(bitsize), bits);
303+
let llval = self.const_uint_big(self.type_ix(bitsize), data);
304304
if layout.value == layout::Pointer {
305305
unsafe { llvm::LLVMConstIntToPtr(llval, llty) }
306306
} else {

src/librustc_mir/const_eval.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ fn op_to_const<'tcx>(
115115
ecx.tcx.alloc_map.lock().unwrap_memory(ptr.alloc_id),
116116
ptr.offset.bytes(),
117117
),
118-
Scalar::Bits { .. } => (
118+
Scalar::Raw { .. } => (
119119
ecx.tcx.intern_const_alloc(Allocation::from_byte_aligned_bytes(b"", ())),
120120
0,
121121
),

0 commit comments

Comments
 (0)