Skip to content

Commit 482411a

Browse files
committed
More renames
1. Rename ScalarMaybeUninit's Undef to Uninit 2. Renamed variables from `undef_mask` to `uninit_mask` More will come...
1 parent cd4b123 commit 482411a

File tree

13 files changed

+61
-61
lines changed

13 files changed

+61
-61
lines changed

src/librustc_middle/mir/interpret/allocation.rs

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ pub struct Allocation<Tag = (), Extra = ()> {
2727
/// at the given offset.
2828
relocations: Relocations<Tag>,
2929
/// Denotes which part of this allocation is initialized.
30-
undef_mask: UninitMask,
30+
uninit_mask: UninitMask,
3131
/// The size of the allocation. Currently, must always equal `bytes.len()`.
3232
pub size: Size,
3333
/// The alignment of the allocation to detect unaligned reads.
@@ -94,7 +94,7 @@ impl<Tag> Allocation<Tag> {
9494
Self {
9595
bytes,
9696
relocations: Relocations::new(),
97-
undef_mask: UninitMask::new(size, true),
97+
uninit_mask: UninitMask::new(size, true),
9898
size,
9999
align,
100100
mutability: Mutability::Not,
@@ -110,7 +110,7 @@ impl<Tag> Allocation<Tag> {
110110
Allocation {
111111
bytes: vec![0; size.bytes_usize()],
112112
relocations: Relocations::new(),
113-
undef_mask: UninitMask::new(size, false),
113+
uninit_mask: UninitMask::new(size, false),
114114
size,
115115
align,
116116
mutability: Mutability::Mut,
@@ -140,7 +140,7 @@ impl Allocation<(), ()> {
140140
})
141141
.collect(),
142142
),
143-
undef_mask: self.undef_mask,
143+
uninit_mask: self.uninit_mask,
144144
align: self.align,
145145
mutability: self.mutability,
146146
extra,
@@ -163,8 +163,8 @@ impl<Tag, Extra> Allocation<Tag, Extra> {
163163
}
164164

165165
/// Returns the undef mask.
166-
pub fn undef_mask(&self) -> &UninitMask {
167-
&self.undef_mask
166+
pub fn uninit_mask(&self) -> &UninitMask {
167+
&self.uninit_mask
168168
}
169169

170170
/// Returns the relocation list.
@@ -363,12 +363,12 @@ impl<'tcx, Tag: Copy, Extra: AllocationExtra<Tag>> Allocation<Tag, Extra> {
363363
) -> InterpResult<'tcx, ScalarMaybeUninit<Tag>> {
364364
// `get_bytes_unchecked` tests relocation edges.
365365
let bytes = self.get_bytes_with_undef_and_ptr(cx, ptr, size)?;
366-
// Undef check happens *after* we established that the alignment is correct.
366+
// Uninit check happens *after* we established that the alignment is correct.
367367
// We must not return `Ok()` for unaligned pointers!
368368
if self.is_defined(ptr, size).is_err() {
369-
// This inflates undefined bytes to the entire scalar, even if only a few
370-
// bytes are undefined.
371-
return Ok(ScalarMaybeUninit::Undef);
369+
// This inflates uninitialized bytes to the entire scalar, even if only a few
370+
// bytes are uninitialized.
371+
return Ok(ScalarMaybeUninit::Uninit);
372372
}
373373
// Now we do the actual reading.
374374
let bits = read_target_uint(cx.data_layout().endian, bytes).unwrap();
@@ -416,7 +416,7 @@ impl<'tcx, Tag: Copy, Extra: AllocationExtra<Tag>> Allocation<Tag, Extra> {
416416
) -> InterpResult<'tcx> {
417417
let val = match val {
418418
ScalarMaybeUninit::Scalar(scalar) => scalar,
419-
ScalarMaybeUninit::Undef => {
419+
ScalarMaybeUninit::Uninit => {
420420
self.mark_definedness(ptr, type_size, false);
421421
return Ok(());
422422
}
@@ -516,10 +516,10 @@ impl<'tcx, Tag: Copy, Extra> Allocation<Tag, Extra> {
516516
// Mark parts of the outermost relocations as undefined if they partially fall outside the
517517
// given range.
518518
if first < start {
519-
self.undef_mask.set_range(first, start, false);
519+
self.uninit_mask.set_range(first, start, false);
520520
}
521521
if last > end {
522-
self.undef_mask.set_range(end, last, false);
522+
self.uninit_mask.set_range(end, last, false);
523523
}
524524

525525
// Forget all the relocations.
@@ -550,7 +550,7 @@ impl<'tcx, Tag: Copy, Extra> Allocation<Tag, Extra> {
550550
/// Returns `Ok(())` if it's defined. Otherwise returns the index of the byte
551551
/// at which the first undefined access begins.
552552
fn is_defined(&self, ptr: Pointer<Tag>, size: Size) -> Result<(), Size> {
553-
self.undef_mask.is_range_defined(ptr.offset, ptr.offset + size) // `Size` addition
553+
self.uninit_mask.is_range_defined(ptr.offset, ptr.offset + size) // `Size` addition
554554
}
555555

556556
/// Checks that a range of bytes is defined. If not, returns the `ReadUndefBytes`
@@ -564,7 +564,7 @@ impl<'tcx, Tag: Copy, Extra> Allocation<Tag, Extra> {
564564
if size.bytes() == 0 {
565565
return;
566566
}
567-
self.undef_mask.set_range(ptr.offset, ptr.offset + size, new_state);
567+
self.uninit_mask.set_range(ptr.offset, ptr.offset + size, new_state);
568568
}
569569
}
570570

@@ -603,13 +603,13 @@ impl<Tag, Extra> Allocation<Tag, Extra> {
603603
// where each element toggles the state.
604604

605605
let mut ranges = smallvec::SmallVec::<[u64; 1]>::new();
606-
let initial = self.undef_mask.get(src.offset);
606+
let initial = self.uninit_mask.get(src.offset);
607607
let mut cur_len = 1;
608608
let mut cur = initial;
609609

610610
for i in 1..size.bytes() {
611611
// FIXME: optimize to bitshift the current undef block's bits and read the top bit.
612-
if self.undef_mask.get(src.offset + Size::from_bytes(i)) == cur {
612+
if self.uninit_mask.get(src.offset + Size::from_bytes(i)) == cur {
613613
cur_len += 1;
614614
} else {
615615
ranges.push(cur_len);
@@ -634,7 +634,7 @@ impl<Tag, Extra> Allocation<Tag, Extra> {
634634
// An optimization where we can just overwrite an entire range of definedness bits if
635635
// they are going to be uniformly `1` or `0`.
636636
if defined.ranges.len() <= 1 {
637-
self.undef_mask.set_range_inbounds(
637+
self.uninit_mask.set_range_inbounds(
638638
dest.offset,
639639
dest.offset + size * repeat, // `Size` operations
640640
defined.initial,
@@ -649,7 +649,7 @@ impl<Tag, Extra> Allocation<Tag, Extra> {
649649
for range in &defined.ranges {
650650
let old_j = j;
651651
j += range;
652-
self.undef_mask.set_range_inbounds(
652+
self.uninit_mask.set_range_inbounds(
653653
Size::from_bytes(old_j),
654654
Size::from_bytes(j),
655655
cur,
@@ -741,7 +741,7 @@ impl<Tag: Copy, Extra> Allocation<Tag, Extra> {
741741
type Block = u64;
742742

743743
/// A bitmask where each bit refers to the byte with the same index. If the bit is `true`, the byte
744-
/// is defined. If it is `false` the byte is undefined.
744+
/// is initialized. If it is `false` the byte is uninitialized.
745745
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Ord, Hash, RustcEncodable, RustcDecodable)]
746746
#[derive(HashStable)]
747747
pub struct UninitMask {
@@ -758,10 +758,10 @@ impl UninitMask {
758758
m
759759
}
760760

761-
/// Checks whether the range `start..end` (end-exclusive) is entirely defined.
761+
/// Checks whether the range `start..end` (end-exclusive) is entirely initialized.
762762
///
763-
/// Returns `Ok(())` if it's defined. Otherwise returns the index of the byte
764-
/// at which the first undefined access begins.
763+
/// Returns `Ok(())` if it's initialized. Otherwise returns the index of the byte
764+
/// at which the first uninitialized access begins.
765765
#[inline]
766766
pub fn is_range_defined(&self, start: Size, end: Size) -> Result<(), Size> {
767767
if end > self.len {

src/librustc_middle/mir/interpret/value.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ pub struct RawConst<'tcx> {
2828
pub enum ConstValue<'tcx> {
2929
/// Used only for types with `layout::abi::Scalar` ABI and ZSTs.
3030
///
31-
/// Not using the enum `Value` to encode that this must not be `Undef`.
31+
/// Not using the enum `Value` to encode that this must not be `Uninit`.
3232
Scalar(Scalar),
3333

3434
/// Used only for `&[u8]` and `&str`
@@ -537,7 +537,7 @@ impl<Tag> From<Pointer<Tag>> for Scalar<Tag> {
537537
#[derive(Clone, Copy, Eq, PartialEq, RustcEncodable, RustcDecodable, HashStable, Hash)]
538538
pub enum ScalarMaybeUninit<Tag = (), Id = AllocId> {
539539
Scalar(Scalar<Tag, Id>),
540-
Undef,
540+
Uninit,
541541
}
542542

543543
impl<Tag> From<Scalar<Tag>> for ScalarMaybeUninit<Tag> {
@@ -557,7 +557,7 @@ impl<Tag> From<Pointer<Tag>> for ScalarMaybeUninit<Tag> {
557557
impl<Tag: fmt::Debug, Id: fmt::Debug> fmt::Debug for ScalarMaybeUninit<Tag, Id> {
558558
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
559559
match self {
560-
ScalarMaybeUninit::Undef => write!(f, "Undef"),
560+
ScalarMaybeUninit::Uninit => write!(f, "Uninit"),
561561
ScalarMaybeUninit::Scalar(s) => write!(f, "{:?}", s),
562562
}
563563
}
@@ -566,7 +566,7 @@ impl<Tag: fmt::Debug, Id: fmt::Debug> fmt::Debug for ScalarMaybeUninit<Tag, Id>
566566
impl<Tag> fmt::Display for ScalarMaybeUninit<Tag> {
567567
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
568568
match self {
569-
ScalarMaybeUninit::Undef => write!(f, "uninitialized bytes"),
569+
ScalarMaybeUninit::Uninit => write!(f, "uninitialized bytes"),
570570
ScalarMaybeUninit::Scalar(s) => write!(f, "{}", s),
571571
}
572572
}
@@ -580,15 +580,15 @@ impl<'tcx, Tag> ScalarMaybeUninit<Tag> {
580580
pub fn erase_tag(self) -> ScalarMaybeUninit {
581581
match self {
582582
ScalarMaybeUninit::Scalar(s) => ScalarMaybeUninit::Scalar(s.erase_tag()),
583-
ScalarMaybeUninit::Undef => ScalarMaybeUninit::Undef,
583+
ScalarMaybeUninit::Uninit => ScalarMaybeUninit::Uninit,
584584
}
585585
}
586586

587587
#[inline]
588588
pub fn not_undef(self) -> InterpResult<'static, Scalar<Tag>> {
589589
match self {
590590
ScalarMaybeUninit::Scalar(scalar) => Ok(scalar),
591-
ScalarMaybeUninit::Undef => throw_ub!(InvalidUninitBytes(None)),
591+
ScalarMaybeUninit::Uninit => throw_ub!(InvalidUninitBytes(None)),
592592
}
593593
}
594594

src/librustc_mir/const_eval/eval_queries.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ pub(super) fn op_to_const<'tcx>(
100100
) -> ConstValue<'tcx> {
101101
// We do not have value optimizations for everything.
102102
// Only scalars and slices, since they are very common.
103-
// Note that further down we turn scalars of undefined bits back to `ByRef`. These can result
103+
// Note that further down we turn scalars of uninitialized bits back to `ByRef`. These can result
104104
// from scalar unions that are initialized with one of their zero sized variants. We could
105105
// instead allow `ConstValue::Scalar` to store `ScalarMaybeUninit`, but that would affect all
106106
// the usual cases of extracting e.g. a `usize`, without there being a real use case for the
@@ -150,7 +150,7 @@ pub(super) fn op_to_const<'tcx>(
150150
Err(imm) => match *imm {
151151
Immediate::Scalar(x) => match x {
152152
ScalarMaybeUninit::Scalar(s) => ConstValue::Scalar(s),
153-
ScalarMaybeUninit::Undef => to_const_value(op.assert_mem_place(ecx)),
153+
ScalarMaybeUninit::Uninit => to_const_value(op.assert_mem_place(ecx)),
154154
},
155155
Immediate::ScalarPair(a, b) => {
156156
let (data, start) = match a.not_undef().unwrap() {

src/librustc_mir/interpret/operand.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ impl<Tag: Copy> std::fmt::Display for ImmTy<'tcx, Tag> {
104104
ScalarMaybeUninit::Scalar(s) => {
105105
cx.pretty_print_const_scalar(s.erase_tag(), ty, true)
106106
}
107-
ScalarMaybeUninit::Undef => cx.typed_value(
107+
ScalarMaybeUninit::Uninit => cx.typed_value(
108108
|mut this| {
109109
this.write_str("{undef ")?;
110110
Ok(this)
@@ -646,7 +646,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
646646
let variants_end = niche_variants.end().as_u32();
647647
let raw_discr = raw_discr
648648
.not_undef()
649-
.map_err(|_| err_ub!(InvalidDiscriminant(ScalarMaybeUninit::Undef)))?;
649+
.map_err(|_| err_ub!(InvalidDiscriminant(ScalarMaybeUninit::Uninit)))?;
650650
match raw_discr.to_bits_or_ptr(discr_val.layout.size, self) {
651651
Err(ptr) => {
652652
// The niche must be just 0 (which an inbounds pointer value never is)

src/librustc_mir/interpret/place.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -743,7 +743,7 @@ where
743743
"Size mismatch when writing bits"
744744
)
745745
}
746-
Immediate::Scalar(ScalarMaybeUninit::Undef) => {} // undef can have any size
746+
Immediate::Scalar(ScalarMaybeUninit::Uninit) => {} // undef can have any size
747747
Immediate::ScalarPair(_, _) => {
748748
// FIXME: Can we check anything here?
749749
}

src/librustc_mir/util/pretty.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -767,7 +767,7 @@ fn write_allocation_bytes<Tag, Extra>(
767767
ascii.push('╼');
768768
i += ptr_size;
769769
}
770-
} else if alloc.undef_mask().is_range_defined(i, i + Size::from_bytes(1)).is_ok() {
770+
} else if alloc.uninit_mask().is_range_defined(i, i + Size::from_bytes(1)).is_ok() {
771771
let j = i.bytes_usize();
772772

773773
// Checked definedness (and thus range) and relocations. This access also doesn't

src/test/mir-opt/const_prop/control-flow-simplification/rustc.hello.ConstProp.diff

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,10 @@
5151
// + literal: Const { ty: fn(&str) -> ! {std::rt::begin_panic::<&str>}, val: Value(Scalar(<ZST>)) }
5252
// ty::Const
5353
// + ty: &str
54-
// + val: Value(Slice { data: Allocation { bytes: [101, 120, 112, 108, 105, 99, 105, 116, 32, 112, 97, 110, 105, 99], relocations: Relocations(SortedMap { data: [] }), undef_mask: UndefMask { blocks: [16383], len: Size { raw: 14 } }, size: Size { raw: 14 }, align: Align { pow2: 0 }, mutability: Not, extra: () }, start: 0, end: 14 })
54+
// + val: Value(Slice { data: Allocation { bytes: [101, 120, 112, 108, 105, 99, 105, 116, 32, 112, 97, 110, 105, 99], relocations: Relocations(SortedMap { data: [] }), uninit_mask: UninitMask { blocks: [16383], len: Size { raw: 14 } }, size: Size { raw: 14 }, align: Align { pow2: 0 }, mutability: Not, extra: () }, start: 0, end: 14 })
5555
// mir::Constant
5656
// + span: $SRC_DIR/libstd/macros.rs:LL:COL
57-
// + literal: Const { ty: &str, val: Value(Slice { data: Allocation { bytes: [101, 120, 112, 108, 105, 99, 105, 116, 32, 112, 97, 110, 105, 99], relocations: Relocations(SortedMap { data: [] }), undef_mask: UndefMask { blocks: [16383], len: Size { raw: 14 } }, size: Size { raw: 14 }, align: Align { pow2: 0 }, mutability: Not, extra: () }, start: 0, end: 14 }) }
57+
// + literal: Const { ty: &str, val: Value(Slice { data: Allocation { bytes: [101, 120, 112, 108, 105, 99, 105, 116, 32, 112, 97, 110, 105, 99], relocations: Relocations(SortedMap { data: [] }), uninit_mask: UninitMask { blocks: [16383], len: Size { raw: 14 } }, size: Size { raw: 14 }, align: Align { pow2: 0 }, mutability: Not, extra: () }, start: 0, end: 14 }) }
5858
}
5959
}
6060

src/test/mir-opt/inline/inline-into-box-place/64bit/rustc.main.Inline.diff

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
- // + ty: fn() -> std::vec::Vec<u32> {std::vec::Vec::<u32>::new}
2525
- // + val: Value(Scalar(<ZST>))
2626
+ // + ty: alloc::raw_vec::RawVec<u32>
27-
+ // + val: Value(ByRef { alloc: Allocation { bytes: [4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], relocations: Relocations(SortedMap { data: [] }), undef_mask: UndefMask { blocks: [65535], len: Size { raw: 16 } }, size: Size { raw: 16 }, align: Align { pow2: 3 }, mutability: Not, extra: () }, offset: Size { raw: 0 } })
27+
+ // + val: Value(ByRef { alloc: Allocation { bytes: [4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], relocations: Relocations(SortedMap { data: [] }), uninit_mask: UninitMask { blocks: [65535], len: Size { raw: 16 } }, size: Size { raw: 16 }, align: Align { pow2: 3 }, mutability: Not, extra: () }, offset: Size { raw: 0 } })
2828
// mir::Constant
2929
- // + span: $DIR/inline-into-box-place.rs:8:33: 8:41
3030
- // + user_ty: UserType(1)
@@ -41,7 +41,7 @@
4141
- _0 = const (); // bb2[2]: scope 0 at $DIR/inline-into-box-place.rs:7:11: 9:2
4242
+ // + span: $SRC_DIR/liballoc/vec.rs:LL:COL
4343
+ // + user_ty: UserType(0)
44-
+ // + literal: Const { ty: alloc::raw_vec::RawVec<u32>, val: Value(ByRef { alloc: Allocation { bytes: [4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], relocations: Relocations(SortedMap { data: [] }), undef_mask: UndefMask { blocks: [65535], len: Size { raw: 16 } }, size: Size { raw: 16 }, align: Align { pow2: 3 }, mutability: Not, extra: () }, offset: Size { raw: 0 } }) }
44+
+ // + literal: Const { ty: alloc::raw_vec::RawVec<u32>, val: Value(ByRef { alloc: Allocation { bytes: [4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], relocations: Relocations(SortedMap { data: [] }), uninit_mask: UninitMask { blocks: [65535], len: Size { raw: 16 } }, size: Size { raw: 16 }, align: Align { pow2: 3 }, mutability: Not, extra: () }, offset: Size { raw: 0 } }) }
4545
+ ((*_4).1: usize) = const 0usize; // bb0[5]: scope 2 at $SRC_DIR/liballoc/vec.rs:LL:COL
4646
// ty::Const
4747
+ // + ty: usize

src/test/mir-opt/no-drop-for-inactive-variant/rustc.unwrap.SimplifyCfg-elaborate-drops.after.mir

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ fn unwrap(_1: std::option::Option<T>) -> T {
3232
// + literal: Const { ty: fn(&str) -> ! {std::rt::begin_panic::<&str>}, val: Value(Scalar(<ZST>)) }
3333
// ty::Const
3434
// + ty: &str
35-
// + val: Value(Slice { data: Allocation { bytes: [101, 120, 112, 108, 105, 99, 105, 116, 32, 112, 97, 110, 105, 99], relocations: Relocations(SortedMap { data: [] }), undef_mask: UndefMask { blocks: [16383], len: Size { raw: 14 } }, size: Size { raw: 14 }, align: Align { pow2: 0 }, mutability: Not, extra: () }, start: 0, end: 14 })
35+
// + val: Value(Slice { data: Allocation { bytes: [101, 120, 112, 108, 105, 99, 105, 116, 32, 112, 97, 110, 105, 99], relocations: Relocations(SortedMap { data: [] }), uninit_mask: UninitMask { blocks: [16383], len: Size { raw: 14 } }, size: Size { raw: 14 }, align: Align { pow2: 0 }, mutability: Not, extra: () }, start: 0, end: 14 })
3636
// mir::Constant
3737
// + span: $SRC_DIR/libstd/macros.rs:LL:COL
38-
// + literal: Const { ty: &str, val: Value(Slice { data: Allocation { bytes: [101, 120, 112, 108, 105, 99, 105, 116, 32, 112, 97, 110, 105, 99], relocations: Relocations(SortedMap { data: [] }), undef_mask: UndefMask { blocks: [16383], len: Size { raw: 14 } }, size: Size { raw: 14 }, align: Align { pow2: 0 }, mutability: Not, extra: () }, start: 0, end: 14 }) }
38+
// + literal: Const { ty: &str, val: Value(Slice { data: Allocation { bytes: [101, 120, 112, 108, 105, 99, 105, 116, 32, 112, 97, 110, 105, 99], relocations: Relocations(SortedMap { data: [] }), uninit_mask: UninitMask { blocks: [16383], len: Size { raw: 14 } }, size: Size { raw: 14 }, align: Align { pow2: 0 }, mutability: Not, extra: () }, start: 0, end: 14 }) }
3939
}
4040

4141
bb3: {

0 commit comments

Comments
 (0)