@@ -10,7 +10,7 @@ use rustc_data_structures::sorted_map::SortedMap;
1010use rustc_target:: abi:: { Align , HasDataLayout , Size } ;
1111
1212use 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#[ derive( Clone , Debug , Eq , PartialEq , PartialOrd , Ord , Hash , RustcEncodable , RustcDecodable ) ]
@@ -25,7 +25,7 @@ pub struct Allocation<Tag = (), Extra = ()> {
2525 /// at the given offset.
2626 relocations : Relocations < Tag > ,
2727 /// Denotes which part of this allocation is initialized.
28- undef_mask : UndefMask ,
28+ init_mask : InitMask ,
2929 /// The size of the allocation. Currently, must always equal `bytes.len()`.
3030 pub size : Size ,
3131 /// The alignment of the allocation to detect unaligned reads.
@@ -92,7 +92,7 @@ impl<Tag> Allocation<Tag> {
9292 Self {
9393 bytes,
9494 relocations : Relocations :: new ( ) ,
95- undef_mask : UndefMask :: new ( size, true ) ,
95+ init_mask : InitMask :: new ( size, true ) ,
9696 size,
9797 align,
9898 mutability : Mutability :: Not ,
@@ -108,7 +108,7 @@ impl<Tag> Allocation<Tag> {
108108 Allocation {
109109 bytes : vec ! [ 0 ; size. bytes_usize( ) ] ,
110110 relocations : Relocations :: new ( ) ,
111- undef_mask : UndefMask :: new ( size, false ) ,
111+ init_mask : InitMask :: new ( size, false ) ,
112112 size,
113113 align,
114114 mutability : Mutability :: Mut ,
@@ -138,7 +138,7 @@ impl Allocation<(), ()> {
138138 } )
139139 . collect ( ) ,
140140 ) ,
141- undef_mask : self . undef_mask ,
141+ init_mask : self . init_mask ,
142142 align : self . align ,
143143 mutability : self . mutability ,
144144 extra,
@@ -160,9 +160,9 @@ impl<Tag, Extra> Allocation<Tag, Extra> {
160160 & self . bytes [ range]
161161 }
162162
163- /// Returns the undef mask.
164- pub fn undef_mask ( & self ) -> & UndefMask {
165- & self . undef_mask
163+ /// Returns the mask indicating which bytes are initialized .
164+ pub fn init_mask ( & self ) -> & InitMask {
165+ & self . init_mask
166166 }
167167
168168 /// Returns the relocation list.
@@ -358,15 +358,15 @@ impl<'tcx, Tag: Copy, Extra: AllocationExtra<Tag>> Allocation<Tag, Extra> {
358358 cx : & impl HasDataLayout ,
359359 ptr : Pointer < Tag > ,
360360 size : Size ,
361- ) -> InterpResult < ' tcx , ScalarMaybeUndef < Tag > > {
361+ ) -> InterpResult < ' tcx , ScalarMaybeUninit < Tag > > {
362362 // `get_bytes_unchecked` tests relocation edges.
363363 let bytes = self . get_bytes_with_undef_and_ptr ( cx, ptr, size) ?;
364- // Undef check happens *after* we established that the alignment is correct.
364+ // Uninit check happens *after* we established that the alignment is correct.
365365 // We must not return `Ok()` for unaligned pointers!
366366 if self . is_defined ( ptr, size) . is_err ( ) {
367- // This inflates undefined bytes to the entire scalar, even if only a few
368- // bytes are undefined .
369- return Ok ( ScalarMaybeUndef :: Undef ) ;
367+ // This inflates uninitialized bytes to the entire scalar, even if only a few
368+ // bytes are uninitialized .
369+ return Ok ( ScalarMaybeUninit :: Uninit ) ;
370370 }
371371 // Now we do the actual reading.
372372 let bits = read_target_uint ( cx. data_layout ( ) . endian , bytes) . unwrap ( ) ;
@@ -377,11 +377,11 @@ impl<'tcx, Tag: Copy, Extra: AllocationExtra<Tag>> Allocation<Tag, Extra> {
377377 } else {
378378 if let Some ( & ( tag, alloc_id) ) = self . relocations . get ( & ptr. offset ) {
379379 let ptr = Pointer :: new_with_tag ( alloc_id, Size :: from_bytes ( bits) , tag) ;
380- return Ok ( ScalarMaybeUndef :: Scalar ( ptr. into ( ) ) ) ;
380+ return Ok ( ScalarMaybeUninit :: Scalar ( ptr. into ( ) ) ) ;
381381 }
382382 }
383383 // We don't. Just return the bits.
384- Ok ( ScalarMaybeUndef :: Scalar ( Scalar :: from_uint ( bits, size) ) )
384+ Ok ( ScalarMaybeUninit :: Scalar ( Scalar :: from_uint ( bits, size) ) )
385385 }
386386
387387 /// Reads a pointer-sized scalar.
@@ -392,7 +392,7 @@ impl<'tcx, Tag: Copy, Extra: AllocationExtra<Tag>> Allocation<Tag, Extra> {
392392 & self ,
393393 cx : & impl HasDataLayout ,
394394 ptr : Pointer < Tag > ,
395- ) -> InterpResult < ' tcx , ScalarMaybeUndef < Tag > > {
395+ ) -> InterpResult < ' tcx , ScalarMaybeUninit < Tag > > {
396396 self . read_scalar ( cx, ptr, cx. data_layout ( ) . pointer_size )
397397 }
398398
@@ -409,12 +409,12 @@ impl<'tcx, Tag: Copy, Extra: AllocationExtra<Tag>> Allocation<Tag, Extra> {
409409 & mut self ,
410410 cx : & impl HasDataLayout ,
411411 ptr : Pointer < Tag > ,
412- val : ScalarMaybeUndef < Tag > ,
412+ val : ScalarMaybeUninit < Tag > ,
413413 type_size : Size ,
414414 ) -> InterpResult < ' tcx > {
415415 let val = match val {
416- ScalarMaybeUndef :: Scalar ( scalar) => scalar,
417- ScalarMaybeUndef :: Undef => {
416+ ScalarMaybeUninit :: Scalar ( scalar) => scalar,
417+ ScalarMaybeUninit :: Uninit => {
418418 self . mark_definedness ( ptr, type_size, false ) ;
419419 return Ok ( ( ) ) ;
420420 }
@@ -445,7 +445,7 @@ impl<'tcx, Tag: Copy, Extra: AllocationExtra<Tag>> Allocation<Tag, Extra> {
445445 & mut self ,
446446 cx : & impl HasDataLayout ,
447447 ptr : Pointer < Tag > ,
448- val : ScalarMaybeUndef < Tag > ,
448+ val : ScalarMaybeUninit < Tag > ,
449449 ) -> InterpResult < ' tcx > {
450450 let ptr_size = cx. data_layout ( ) . pointer_size ;
451451 self . write_scalar ( cx, ptr, val, ptr_size)
@@ -514,10 +514,10 @@ impl<'tcx, Tag: Copy, Extra> Allocation<Tag, Extra> {
514514 // Mark parts of the outermost relocations as undefined if they partially fall outside the
515515 // given range.
516516 if first < start {
517- self . undef_mask . set_range ( first, start, false ) ;
517+ self . init_mask . set_range ( first, start, false ) ;
518518 }
519519 if last > end {
520- self . undef_mask . set_range ( end, last, false ) ;
520+ self . init_mask . set_range ( end, last, false ) ;
521521 }
522522
523523 // Forget all the relocations.
@@ -548,21 +548,21 @@ impl<'tcx, Tag: Copy, Extra> Allocation<Tag, Extra> {
548548 /// Returns `Ok(())` if it's defined. Otherwise returns the index of the byte
549549 /// at which the first undefined access begins.
550550 fn is_defined ( & self , ptr : Pointer < Tag > , size : Size ) -> Result < ( ) , Size > {
551- self . undef_mask . is_range_defined ( ptr. offset , ptr. offset + size) // `Size` addition
551+ self . init_mask . is_range_initialized ( ptr. offset , ptr. offset + size) // `Size` addition
552552 }
553553
554554 /// Checks that a range of bytes is defined. If not, returns the `ReadUndefBytes`
555555 /// error which will report the first byte which is undefined.
556556 fn check_defined ( & self , ptr : Pointer < Tag > , size : Size ) -> InterpResult < ' tcx > {
557557 self . is_defined ( ptr, size)
558- . or_else ( |idx| throw_ub ! ( InvalidUndefBytes ( Some ( Pointer :: new( ptr. alloc_id, idx) ) ) ) )
558+ . or_else ( |idx| throw_ub ! ( InvalidUninitBytes ( Some ( Pointer :: new( ptr. alloc_id, idx) ) ) ) )
559559 }
560560
561561 pub fn mark_definedness ( & mut self , ptr : Pointer < Tag > , size : Size , new_state : bool ) {
562562 if size. bytes ( ) == 0 {
563563 return ;
564564 }
565- self . undef_mask . set_range ( ptr. offset , ptr. offset + size, new_state) ;
565+ self . init_mask . set_range ( ptr. offset , ptr. offset + size, new_state) ;
566566 }
567567}
568568
@@ -601,13 +601,13 @@ impl<Tag, Extra> Allocation<Tag, Extra> {
601601 // where each element toggles the state.
602602
603603 let mut ranges = smallvec:: SmallVec :: < [ u64 ; 1 ] > :: new ( ) ;
604- let initial = self . undef_mask . get ( src. offset ) ;
604+ let initial = self . init_mask . get ( src. offset ) ;
605605 let mut cur_len = 1 ;
606606 let mut cur = initial;
607607
608608 for i in 1 ..size. bytes ( ) {
609609 // FIXME: optimize to bitshift the current undef block's bits and read the top bit.
610- if self . undef_mask . get ( src. offset + Size :: from_bytes ( i) ) == cur {
610+ if self . init_mask . get ( src. offset + Size :: from_bytes ( i) ) == cur {
611611 cur_len += 1 ;
612612 } else {
613613 ranges. push ( cur_len) ;
@@ -632,7 +632,7 @@ impl<Tag, Extra> Allocation<Tag, Extra> {
632632 // An optimization where we can just overwrite an entire range of definedness bits if
633633 // they are going to be uniformly `1` or `0`.
634634 if defined. ranges . len ( ) <= 1 {
635- self . undef_mask . set_range_inbounds (
635+ self . init_mask . set_range_inbounds (
636636 dest. offset ,
637637 dest. offset + size * repeat, // `Size` operations
638638 defined. initial ,
@@ -647,7 +647,7 @@ impl<Tag, Extra> Allocation<Tag, Extra> {
647647 for range in & defined. ranges {
648648 let old_j = j;
649649 j += range;
650- self . undef_mask . set_range_inbounds (
650+ self . init_mask . set_range_inbounds (
651651 Size :: from_bytes ( old_j) ,
652652 Size :: from_bytes ( j) ,
653653 cur,
@@ -739,29 +739,29 @@ impl<Tag: Copy, Extra> Allocation<Tag, Extra> {
739739type Block = u64 ;
740740
741741/// A bitmask where each bit refers to the byte with the same index. If the bit is `true`, the byte
742- /// is defined . If it is `false` the byte is undefined .
742+ /// is initialized . If it is `false` the byte is uninitialized .
743743#[ derive( Clone , Debug , Eq , PartialEq , PartialOrd , Ord , Hash , RustcEncodable , RustcDecodable ) ]
744744#[ derive( HashStable ) ]
745- pub struct UndefMask {
745+ pub struct InitMask {
746746 blocks : Vec < Block > ,
747747 len : Size ,
748748}
749749
750- impl UndefMask {
750+ impl InitMask {
751751 pub const BLOCK_SIZE : u64 = 64 ;
752752
753753 pub fn new ( size : Size , state : bool ) -> Self {
754- let mut m = UndefMask { blocks : vec ! [ ] , len : Size :: ZERO } ;
754+ let mut m = InitMask { blocks : vec ! [ ] , len : Size :: ZERO } ;
755755 m. grow ( size, state) ;
756756 m
757757 }
758758
759- /// Checks whether the range `start..end` (end-exclusive) is entirely defined .
759+ /// Checks whether the range `start..end` (end-exclusive) is entirely initialized .
760760 ///
761- /// Returns `Ok(())` if it's defined . Otherwise returns the index of the byte
762- /// at which the first undefined access begins.
761+ /// Returns `Ok(())` if it's initialized . Otherwise returns the index of the byte
762+ /// at which the first uninitialized access begins.
763763 #[ inline]
764- pub fn is_range_defined ( & self , start : Size , end : Size ) -> Result < ( ) , Size > {
764+ pub fn is_range_initialized ( & self , start : Size , end : Size ) -> Result < ( ) , Size > {
765765 if end > self . len {
766766 return Err ( self . len ) ;
767767 }
@@ -870,7 +870,7 @@ impl UndefMask {
870870#[ inline]
871871fn bit_index ( bits : Size ) -> ( usize , usize ) {
872872 let bits = bits. bytes ( ) ;
873- let a = bits / UndefMask :: BLOCK_SIZE ;
874- let b = bits % UndefMask :: BLOCK_SIZE ;
873+ let a = bits / InitMask :: BLOCK_SIZE ;
874+ let b = bits % InitMask :: BLOCK_SIZE ;
875875 ( usize:: try_from ( a) . unwrap ( ) , usize:: try_from ( b) . unwrap ( ) )
876876}
0 commit comments