Skip to content

Commit cd4b123

Browse files
committed
Renamed "undef" -> "uninit"
1. InvalidUndefBytes -> InvalidUninitBytes 2. ScalarMaybeUndef -> ScalarMaybeUninit 3. UndefMask -> UninitMask Resolves #71193
1 parent 20fc02f commit cd4b123

File tree

10 files changed

+79
-79
lines changed

10 files changed

+79
-79
lines changed

src/librustc_middle/mir/interpret/allocation.rs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use rustc_data_structures::sorted_map::SortedMap;
1010
use rustc_target::abi::{Align, HasDataLayout, Size};
1111

1212
use super::{
13-
read_target_uint, write_target_uint, AllocId, InterpResult, Pointer, Scalar, ScalarMaybeUndef,
13+
read_target_uint, write_target_uint, AllocId, InterpResult, Pointer, Scalar, ScalarMaybeUninit,
1414
};
1515

1616
// NOTE: When adding new fields, make sure to adjust the `Snapshot` impl in
@@ -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: UndefMask,
30+
undef_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: UndefMask::new(size, true),
97+
undef_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: UndefMask::new(size, false),
113+
undef_mask: UninitMask::new(size, false),
114114
size,
115115
align,
116116
mutability: Mutability::Mut,
@@ -163,7 +163,7 @@ impl<Tag, Extra> Allocation<Tag, Extra> {
163163
}
164164

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

@@ -360,15 +360,15 @@ impl<'tcx, Tag: Copy, Extra: AllocationExtra<Tag>> Allocation<Tag, Extra> {
360360
cx: &impl HasDataLayout,
361361
ptr: Pointer<Tag>,
362362
size: Size,
363-
) -> InterpResult<'tcx, ScalarMaybeUndef<Tag>> {
363+
) -> InterpResult<'tcx, ScalarMaybeUninit<Tag>> {
364364
// `get_bytes_unchecked` tests relocation edges.
365365
let bytes = self.get_bytes_with_undef_and_ptr(cx, ptr, size)?;
366366
// Undef 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() {
369369
// This inflates undefined bytes to the entire scalar, even if only a few
370370
// bytes are undefined.
371-
return Ok(ScalarMaybeUndef::Undef);
371+
return Ok(ScalarMaybeUninit::Undef);
372372
}
373373
// Now we do the actual reading.
374374
let bits = read_target_uint(cx.data_layout().endian, bytes).unwrap();
@@ -379,11 +379,11 @@ impl<'tcx, Tag: Copy, Extra: AllocationExtra<Tag>> Allocation<Tag, Extra> {
379379
} else {
380380
if let Some(&(tag, alloc_id)) = self.relocations.get(&ptr.offset) {
381381
let ptr = Pointer::new_with_tag(alloc_id, Size::from_bytes(bits), tag);
382-
return Ok(ScalarMaybeUndef::Scalar(ptr.into()));
382+
return Ok(ScalarMaybeUninit::Scalar(ptr.into()));
383383
}
384384
}
385385
// We don't. Just return the bits.
386-
Ok(ScalarMaybeUndef::Scalar(Scalar::from_uint(bits, size)))
386+
Ok(ScalarMaybeUninit::Scalar(Scalar::from_uint(bits, size)))
387387
}
388388

389389
/// Reads a pointer-sized scalar.
@@ -394,7 +394,7 @@ impl<'tcx, Tag: Copy, Extra: AllocationExtra<Tag>> Allocation<Tag, Extra> {
394394
&self,
395395
cx: &impl HasDataLayout,
396396
ptr: Pointer<Tag>,
397-
) -> InterpResult<'tcx, ScalarMaybeUndef<Tag>> {
397+
) -> InterpResult<'tcx, ScalarMaybeUninit<Tag>> {
398398
self.read_scalar(cx, ptr, cx.data_layout().pointer_size)
399399
}
400400

@@ -411,12 +411,12 @@ impl<'tcx, Tag: Copy, Extra: AllocationExtra<Tag>> Allocation<Tag, Extra> {
411411
&mut self,
412412
cx: &impl HasDataLayout,
413413
ptr: Pointer<Tag>,
414-
val: ScalarMaybeUndef<Tag>,
414+
val: ScalarMaybeUninit<Tag>,
415415
type_size: Size,
416416
) -> InterpResult<'tcx> {
417417
let val = match val {
418-
ScalarMaybeUndef::Scalar(scalar) => scalar,
419-
ScalarMaybeUndef::Undef => {
418+
ScalarMaybeUninit::Scalar(scalar) => scalar,
419+
ScalarMaybeUninit::Undef => {
420420
self.mark_definedness(ptr, type_size, false);
421421
return Ok(());
422422
}
@@ -447,7 +447,7 @@ impl<'tcx, Tag: Copy, Extra: AllocationExtra<Tag>> Allocation<Tag, Extra> {
447447
&mut self,
448448
cx: &impl HasDataLayout,
449449
ptr: Pointer<Tag>,
450-
val: ScalarMaybeUndef<Tag>,
450+
val: ScalarMaybeUninit<Tag>,
451451
) -> InterpResult<'tcx> {
452452
let ptr_size = cx.data_layout().pointer_size;
453453
self.write_scalar(cx, ptr, val, ptr_size)
@@ -557,7 +557,7 @@ impl<'tcx, Tag: Copy, Extra> Allocation<Tag, Extra> {
557557
/// error which will report the first byte which is undefined.
558558
fn check_defined(&self, ptr: Pointer<Tag>, size: Size) -> InterpResult<'tcx> {
559559
self.is_defined(ptr, size)
560-
.or_else(|idx| throw_ub!(InvalidUndefBytes(Some(Pointer::new(ptr.alloc_id, idx)))))
560+
.or_else(|idx| throw_ub!(InvalidUninitBytes(Some(Pointer::new(ptr.alloc_id, idx)))))
561561
}
562562

563563
pub fn mark_definedness(&mut self, ptr: Pointer<Tag>, size: Size, new_state: bool) {
@@ -744,16 +744,16 @@ type Block = u64;
744744
/// is defined. If it is `false` the byte is undefined.
745745
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Ord, Hash, RustcEncodable, RustcDecodable)]
746746
#[derive(HashStable)]
747-
pub struct UndefMask {
747+
pub struct UninitMask {
748748
blocks: Vec<Block>,
749749
len: Size,
750750
}
751751

752-
impl UndefMask {
752+
impl UninitMask {
753753
pub const BLOCK_SIZE: u64 = 64;
754754

755755
pub fn new(size: Size, state: bool) -> Self {
756-
let mut m = UndefMask { blocks: vec![], len: Size::ZERO };
756+
let mut m = UninitMask { blocks: vec![], len: Size::ZERO };
757757
m.grow(size, state);
758758
m
759759
}
@@ -872,7 +872,7 @@ impl UndefMask {
872872
#[inline]
873873
fn bit_index(bits: Size) -> (usize, usize) {
874874
let bits = bits.bytes();
875-
let a = bits / UndefMask::BLOCK_SIZE;
876-
let b = bits % UndefMask::BLOCK_SIZE;
875+
let a = bits / UninitMask::BLOCK_SIZE;
876+
let b = bits % UninitMask::BLOCK_SIZE;
877877
(usize::try_from(a).unwrap(), usize::try_from(b).unwrap())
878878
}

src/librustc_middle/mir/interpret/error.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use super::{AllocId, CheckInAllocMsg, Pointer, RawConst, ScalarMaybeUndef};
1+
use super::{AllocId, CheckInAllocMsg, Pointer, RawConst, ScalarMaybeUninit};
22

33
use crate::mir::interpret::ConstValue;
44
use crate::ty::layout::LayoutError;
@@ -312,7 +312,7 @@ pub enum UndefinedBehaviorInfo {
312312
/// Unreachable code was executed.
313313
Unreachable,
314314
/// An enum discriminant was set to a value which was outside the range of valid values.
315-
InvalidDiscriminant(ScalarMaybeUndef),
315+
InvalidDiscriminant(ScalarMaybeUninit),
316316
/// A slice/array index projection went out-of-bounds.
317317
BoundsCheckFailed {
318318
len: u64,
@@ -358,7 +358,7 @@ pub enum UndefinedBehaviorInfo {
358358
/// Using a non-character `u32` as character.
359359
InvalidChar(u32),
360360
/// Using uninitialized data where it is not allowed.
361-
InvalidUndefBytes(Option<Pointer>),
361+
InvalidUninitBytes(Option<Pointer>),
362362
/// Working with a local that is not currently live.
363363
DeadLocal,
364364
/// Trying to read from the return place of a function.
@@ -414,12 +414,12 @@ impl fmt::Debug for UndefinedBehaviorInfo {
414414
ValidationFailure(ref err) => write!(f, "type validation failed: {}", err),
415415
InvalidBool(b) => write!(f, "interpreting an invalid 8-bit value as a bool: {}", b),
416416
InvalidChar(c) => write!(f, "interpreting an invalid 32-bit value as a char: {}", c),
417-
InvalidUndefBytes(Some(p)) => write!(
417+
InvalidUninitBytes(Some(p)) => write!(
418418
f,
419419
"reading uninitialized memory at {:?}, but this operation requires initialized memory",
420420
p
421421
),
422-
InvalidUndefBytes(None) => write!(
422+
InvalidUninitBytes(None) => write!(
423423
f,
424424
"using uninitialized data, but this operation requires initialized memory"
425425
),

src/librustc_middle/mir/interpret/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,9 @@ pub use self::error::{
122122
ResourceExhaustionInfo, UndefinedBehaviorInfo, UnsupportedOpInfo,
123123
};
124124

125-
pub use self::value::{get_slice_bytes, ConstValue, RawConst, Scalar, ScalarMaybeUndef};
125+
pub use self::value::{get_slice_bytes, ConstValue, RawConst, Scalar, ScalarMaybeUninit};
126126

127-
pub use self::allocation::{Allocation, AllocationExtra, Relocations, UndefMask};
127+
pub use self::allocation::{Allocation, AllocationExtra, Relocations, UninitMask};
128128

129129
pub use self::pointer::{CheckInAllocMsg, Pointer, PointerArithmetic};
130130

src/librustc_middle/mir/interpret/value.rs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -535,60 +535,60 @@ impl<Tag> From<Pointer<Tag>> for Scalar<Tag> {
535535
}
536536

537537
#[derive(Clone, Copy, Eq, PartialEq, RustcEncodable, RustcDecodable, HashStable, Hash)]
538-
pub enum ScalarMaybeUndef<Tag = (), Id = AllocId> {
538+
pub enum ScalarMaybeUninit<Tag = (), Id = AllocId> {
539539
Scalar(Scalar<Tag, Id>),
540540
Undef,
541541
}
542542

543-
impl<Tag> From<Scalar<Tag>> for ScalarMaybeUndef<Tag> {
543+
impl<Tag> From<Scalar<Tag>> for ScalarMaybeUninit<Tag> {
544544
#[inline(always)]
545545
fn from(s: Scalar<Tag>) -> Self {
546-
ScalarMaybeUndef::Scalar(s)
546+
ScalarMaybeUninit::Scalar(s)
547547
}
548548
}
549549

550-
impl<Tag> From<Pointer<Tag>> for ScalarMaybeUndef<Tag> {
550+
impl<Tag> From<Pointer<Tag>> for ScalarMaybeUninit<Tag> {
551551
#[inline(always)]
552552
fn from(s: Pointer<Tag>) -> Self {
553-
ScalarMaybeUndef::Scalar(s.into())
553+
ScalarMaybeUninit::Scalar(s.into())
554554
}
555555
}
556556

557-
impl<Tag: fmt::Debug, Id: fmt::Debug> fmt::Debug for ScalarMaybeUndef<Tag, Id> {
557+
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-
ScalarMaybeUndef::Undef => write!(f, "Undef"),
561-
ScalarMaybeUndef::Scalar(s) => write!(f, "{:?}", s),
560+
ScalarMaybeUninit::Undef => write!(f, "Undef"),
561+
ScalarMaybeUninit::Scalar(s) => write!(f, "{:?}", s),
562562
}
563563
}
564564
}
565565

566-
impl<Tag> fmt::Display for ScalarMaybeUndef<Tag> {
566+
impl<Tag> fmt::Display for ScalarMaybeUninit<Tag> {
567567
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
568568
match self {
569-
ScalarMaybeUndef::Undef => write!(f, "uninitialized bytes"),
570-
ScalarMaybeUndef::Scalar(s) => write!(f, "{}", s),
569+
ScalarMaybeUninit::Undef => write!(f, "uninitialized bytes"),
570+
ScalarMaybeUninit::Scalar(s) => write!(f, "{}", s),
571571
}
572572
}
573573
}
574574

575-
impl<'tcx, Tag> ScalarMaybeUndef<Tag> {
575+
impl<'tcx, Tag> ScalarMaybeUninit<Tag> {
576576
/// Erase the tag from the scalar, if any.
577577
///
578578
/// Used by error reporting code to avoid having the error type depend on `Tag`.
579579
#[inline]
580-
pub fn erase_tag(self) -> ScalarMaybeUndef {
580+
pub fn erase_tag(self) -> ScalarMaybeUninit {
581581
match self {
582-
ScalarMaybeUndef::Scalar(s) => ScalarMaybeUndef::Scalar(s.erase_tag()),
583-
ScalarMaybeUndef::Undef => ScalarMaybeUndef::Undef,
582+
ScalarMaybeUninit::Scalar(s) => ScalarMaybeUninit::Scalar(s.erase_tag()),
583+
ScalarMaybeUninit::Undef => ScalarMaybeUninit::Undef,
584584
}
585585
}
586586

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

src/librustc_mir/const_eval/eval_queries.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use crate::interpret::eval_nullary_intrinsic;
33
use crate::interpret::{
44
intern_const_alloc_recursive, Allocation, ConstValue, GlobalId, Immediate, InternKind,
55
InterpCx, InterpResult, MPlaceTy, MemoryKind, OpTy, RawConst, RefTracking, Scalar,
6-
ScalarMaybeUndef, StackPopCleanup,
6+
ScalarMaybeUninit, StackPopCleanup,
77
};
88
use rustc_hir::def::DefKind;
99
use rustc_middle::mir;
@@ -102,7 +102,7 @@ pub(super) fn op_to_const<'tcx>(
102102
// Only scalars and slices, since they are very common.
103103
// Note that further down we turn scalars of undefined bits back to `ByRef`. These can result
104104
// from scalar unions that are initialized with one of their zero sized variants. We could
105-
// instead allow `ConstValue::Scalar` to store `ScalarMaybeUndef`, but that would affect all
105+
// 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
107107
// `Undef` situation.
108108
let try_as_immediate = match op.layout.abi {
@@ -149,8 +149,8 @@ pub(super) fn op_to_const<'tcx>(
149149
// see comment on `let try_as_immediate` above
150150
Err(imm) => match *imm {
151151
Immediate::Scalar(x) => match x {
152-
ScalarMaybeUndef::Scalar(s) => ConstValue::Scalar(s),
153-
ScalarMaybeUndef::Undef => to_const_value(op.assert_mem_place(ecx)),
152+
ScalarMaybeUninit::Scalar(s) => ConstValue::Scalar(s),
153+
ScalarMaybeUninit::Undef => 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/eval_context.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use rustc_target::abi::{Align, HasDataLayout, LayoutOf, Size, TargetDataLayout};
2222

2323
use super::{
2424
Immediate, MPlaceTy, Machine, MemPlace, MemPlaceMeta, Memory, OpTy, Operand, Place, PlaceTy,
25-
ScalarMaybeUndef, StackPopJump,
25+
ScalarMaybeUninit, StackPopJump,
2626
};
2727
use crate::util::storage::AlwaysLiveLocals;
2828

@@ -928,16 +928,16 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
928928
},
929929
LocalValue::Live(Operand::Immediate(Immediate::Scalar(val))) => {
930930
write!(msg, " {:?}", val).unwrap();
931-
if let ScalarMaybeUndef::Scalar(Scalar::Ptr(ptr)) = val {
931+
if let ScalarMaybeUninit::Scalar(Scalar::Ptr(ptr)) = val {
932932
allocs.push(ptr.alloc_id);
933933
}
934934
}
935935
LocalValue::Live(Operand::Immediate(Immediate::ScalarPair(val1, val2))) => {
936936
write!(msg, " ({:?}, {:?})", val1, val2).unwrap();
937-
if let ScalarMaybeUndef::Scalar(Scalar::Ptr(ptr)) = val1 {
937+
if let ScalarMaybeUninit::Scalar(Scalar::Ptr(ptr)) = val1 {
938938
allocs.push(ptr.alloc_id);
939939
}
940-
if let ScalarMaybeUndef::Scalar(Scalar::Ptr(ptr)) = val2 {
940+
if let ScalarMaybeUninit::Scalar(Scalar::Ptr(ptr)) = val2 {
941941
allocs.push(ptr.alloc_id);
942942
}
943943
}

0 commit comments

Comments
 (0)