@@ -105,7 +105,7 @@ impl<Tag> Allocation<Tag> {
105105 Allocation :: from_bytes ( slice, Align :: from_bytes ( 1 ) . unwrap ( ) )
106106 }
107107
108- pub fn undef ( size : Size , align : Align ) -> Self {
108+ pub fn uninit ( size : Size , align : Align ) -> Self {
109109 Allocation {
110110 bytes : vec ! [ 0 ; size. bytes_usize( ) ] ,
111111 relocations : Relocations :: new ( ) ,
@@ -153,7 +153,7 @@ impl<Tag, Extra> Allocation<Tag, Extra> {
153153 self . size . bytes_usize ( )
154154 }
155155
156- /// Looks at a slice which may describe undefined bytes or describe a relocation. This differs
156+ /// Looks at a slice which may describe uninitialized bytes or describe a relocation. This differs
157157 /// from `get_bytes_with_undef_and_ptr` in that it does no relocation checks (even on the
158158 /// edges) at all. It further ignores `AllocationExtra` callbacks.
159159 /// This must not be used for reads affecting the interpreter execution.
@@ -192,7 +192,7 @@ impl<'tcx, Tag: Copy, Extra: AllocationExtra<Tag>> Allocation<Tag, Extra> {
192192 offset. bytes_usize ( ) ..end
193193 }
194194
195- /// The last argument controls whether we error out when there are undefined
195+ /// The last argument controls whether we error out when there are uninitialized
196196 /// or pointer bytes. You should never call this, call `get_bytes` or
197197 /// `get_bytes_with_undef_and_ptr` instead,
198198 ///
@@ -206,12 +206,12 @@ impl<'tcx, Tag: Copy, Extra: AllocationExtra<Tag>> Allocation<Tag, Extra> {
206206 cx : & impl HasDataLayout ,
207207 ptr : Pointer < Tag > ,
208208 size : Size ,
209- check_defined_and_ptr : bool ,
209+ check_init_and_ptr : bool ,
210210 ) -> InterpResult < ' tcx , & [ u8 ] > {
211211 let range = self . check_bounds ( ptr. offset , size) ;
212212
213- if check_defined_and_ptr {
214- self . check_defined ( ptr, size) ?;
213+ if check_init_and_ptr {
214+ self . check_init ( ptr, size) ?;
215215 self . check_relocations ( cx, ptr, size) ?;
216216 } else {
217217 // We still don't want relocations on the *edges*.
@@ -239,7 +239,7 @@ impl<'tcx, Tag: Copy, Extra: AllocationExtra<Tag>> Allocation<Tag, Extra> {
239239 self . get_bytes_internal ( cx, ptr, size, true )
240240 }
241241
242- /// It is the caller's responsibility to handle undefined and pointer bytes.
242+ /// It is the caller's responsibility to handle uninitialized and pointer bytes.
243243 /// However, this still checks that there are no relocations on the *edges*.
244244 ///
245245 /// It is the caller's responsibility to check bounds and alignment beforehand.
@@ -267,7 +267,7 @@ impl<'tcx, Tag: Copy, Extra: AllocationExtra<Tag>> Allocation<Tag, Extra> {
267267 ) -> InterpResult < ' tcx , & mut [ u8 ] > {
268268 let range = self . check_bounds ( ptr. offset , size) ;
269269
270- self . mark_definedness ( ptr, size, true ) ;
270+ self . mark_init ( ptr, size, true ) ;
271271 self . clear_relocations ( cx, ptr, size) ?;
272272
273273 AllocationExtra :: memory_written ( self , ptr, size) ?;
@@ -303,7 +303,7 @@ impl<'tcx, Tag: Copy, Extra: AllocationExtra<Tag>> Allocation<Tag, Extra> {
303303
304304 /// Validates that `ptr.offset` and `ptr.offset + size` do not point to the middle of a
305305 /// relocation. If `allow_ptr_and_undef` is `false`, also enforces that the memory in the
306- /// given range contains neither relocations nor undef bytes.
306+ /// given range contains neither relocations nor uninitialized bytes.
307307 pub fn check_bytes (
308308 & self ,
309309 cx : & impl HasDataLayout ,
@@ -313,9 +313,9 @@ impl<'tcx, Tag: Copy, Extra: AllocationExtra<Tag>> Allocation<Tag, Extra> {
313313 ) -> InterpResult < ' tcx > {
314314 // Check bounds and relocations on the edges.
315315 self . get_bytes_with_undef_and_ptr ( cx, ptr, size) ?;
316- // Check undef and ptr.
316+ // Check uninit and ptr.
317317 if !allow_ptr_and_undef {
318- self . check_defined ( ptr, size) ?;
318+ self . check_init ( ptr, size) ?;
319319 self . check_relocations ( cx, ptr, size) ?;
320320 }
321321 Ok ( ( ) )
@@ -364,7 +364,7 @@ impl<'tcx, Tag: Copy, Extra: AllocationExtra<Tag>> Allocation<Tag, Extra> {
364364 let bytes = self . get_bytes_with_undef_and_ptr ( cx, ptr, size) ?;
365365 // Uninit check happens *after* we established that the alignment is correct.
366366 // We must not return `Ok()` for unaligned pointers!
367- if self . is_defined ( ptr, size) . is_err ( ) {
367+ if self . is_init ( ptr, size) . is_err ( ) {
368368 // This inflates uninitialized bytes to the entire scalar, even if only a few
369369 // bytes are uninitialized.
370370 return Ok ( ScalarMaybeUninit :: Uninit ) ;
@@ -416,7 +416,7 @@ impl<'tcx, Tag: Copy, Extra: AllocationExtra<Tag>> Allocation<Tag, Extra> {
416416 let val = match val {
417417 ScalarMaybeUninit :: Scalar ( scalar) => scalar,
418418 ScalarMaybeUninit :: Uninit => {
419- self . mark_definedness ( ptr, type_size, false ) ;
419+ self . mark_init ( ptr, type_size, false ) ;
420420 return Ok ( ( ) ) ;
421421 }
422422 } ;
@@ -512,7 +512,7 @@ impl<'tcx, Tag: Copy, Extra> Allocation<Tag, Extra> {
512512 let start = ptr. offset ;
513513 let end = start + size; // `Size` addition
514514
515- // Mark parts of the outermost relocations as undefined if they partially fall outside the
515+ // Mark parts of the outermost relocations as uninitialized if they partially fall outside the
516516 // given range.
517517 if first < start {
518518 self . init_mask . set_range ( first, start, false ) ;
@@ -542,20 +542,20 @@ impl<'tcx, Tag: Copy, Extra> Allocation<Tag, Extra> {
542542 }
543543}
544544
545- /// Undefined bytes.
545+ /// Uninitialized bytes.
546546impl < ' tcx , Tag : Copy , Extra > Allocation < Tag , Extra > {
547- /// Checks whether the given range is entirely defined .
547+ /// Checks whether the given range is entirely initialized .
548548 ///
549- /// Returns `Ok(())` if it's defined . Otherwise returns the range of byte
550- /// indexes of the first contiguous undefined access.
551- fn is_defined ( & self , ptr : Pointer < Tag > , size : Size ) -> Result < ( ) , Range < Size > > {
549+ /// Returns `Ok(())` if it's initialized . Otherwise returns the range of byte
550+ /// indexes of the first contiguous uninitialized access.
551+ fn is_init ( & self , ptr : Pointer < Tag > , size : Size ) -> Result < ( ) , Range < Size > > {
552552 self . init_mask . is_range_initialized ( ptr. offset , ptr. offset + size) // `Size` addition
553553 }
554554
555- /// Checks that a range of bytes is defined . If not, returns the `InvalidUndefBytes `
556- /// error which will report the first range of bytes which is undefined .
557- fn check_defined ( & self , ptr : Pointer < Tag > , size : Size ) -> InterpResult < ' tcx > {
558- self . is_defined ( ptr, size) . or_else ( |idx_range| {
555+ /// Checks that a range of bytes is initialized . If not, returns the `InvalidUninitBytes `
556+ /// error which will report the first range of bytes which is uninitialized .
557+ fn check_init ( & self , ptr : Pointer < Tag > , size : Size ) -> InterpResult < ' tcx > {
558+ self . is_init ( ptr, size) . or_else ( |idx_range| {
559559 throw_ub ! ( InvalidUninitBytes ( Some ( Box :: new( UninitBytesAccess {
560560 access_ptr: ptr. erase_tag( ) ,
561561 access_size: size,
@@ -565,44 +565,44 @@ impl<'tcx, Tag: Copy, Extra> Allocation<Tag, Extra> {
565565 } )
566566 }
567567
568- pub fn mark_definedness ( & mut self , ptr : Pointer < Tag > , size : Size , new_state : bool ) {
568+ pub fn mark_init ( & mut self , ptr : Pointer < Tag > , size : Size , is_init : bool ) {
569569 if size. bytes ( ) == 0 {
570570 return ;
571571 }
572- self . init_mask . set_range ( ptr. offset , ptr. offset + size, new_state ) ;
572+ self . init_mask . set_range ( ptr. offset , ptr. offset + size, is_init ) ;
573573 }
574574}
575575
576- /// Run-length encoding of the undef mask.
576+ /// Run-length encoding of the uninit mask.
577577/// Used to copy parts of a mask multiple times to another allocation.
578- pub struct AllocationDefinedness {
579- /// The definedness of the first range.
578+ pub struct InitMaskCompressed {
579+ /// Whether the first range is initialized .
580580 initial : bool ,
581581 /// The lengths of ranges that are run-length encoded.
582- /// The definedness of the ranges alternate starting with `initial`.
582+ /// The initialization state of the ranges alternate starting with `initial`.
583583 ranges : smallvec:: SmallVec < [ u64 ; 1 ] > ,
584584}
585585
586- impl AllocationDefinedness {
587- pub fn all_bytes_undef ( & self ) -> bool {
588- // The `ranges` are run-length encoded and of alternating definedness .
589- // So if `ranges.len() > 1` then the second block is a range of defined .
586+ impl InitMaskCompressed {
587+ pub fn no_bytes_init ( & self ) -> bool {
588+ // The `ranges` are run-length encoded and of alternating initialization state .
589+ // So if `ranges.len() > 1` then the second block is an initialized range .
590590 !self . initial && self . ranges . len ( ) == 1
591591 }
592592}
593593
594- /// Transferring the definedness mask to other allocations.
594+ /// Transferring the initialization mask to other allocations.
595595impl < Tag , Extra > Allocation < Tag , Extra > {
596- /// Creates a run-length encoding of the undef mask.
597- pub fn compress_undef_range ( & self , src : Pointer < Tag > , size : Size ) -> AllocationDefinedness {
596+ /// Creates a run-length encoding of the initialization mask.
597+ pub fn compress_undef_range ( & self , src : Pointer < Tag > , size : Size ) -> InitMaskCompressed {
598598 // Since we are copying `size` bytes from `src` to `dest + i * size` (`for i in 0..repeat`),
599- // a naive undef mask copying algorithm would repeatedly have to read the undef mask from
599+ // a naive initialization mask copying algorithm would repeatedly have to read the initialization mask from
600600 // the source and write it to the destination. Even if we optimized the memory accesses,
601601 // we'd be doing all of this `repeat` times.
602- // Therefore we precompute a compressed version of the undef mask of the source value and
602+ // Therefore we precompute a compressed version of the initialization mask of the source value and
603603 // then write it back `repeat` times without computing any more information from the source.
604604
605- // A precomputed cache for ranges of defined/undefined bits
605+ // A precomputed cache for ranges of initialized / uninitialized bits
606606 // 0000010010001110 will become
607607 // `[5, 1, 2, 1, 3, 3, 1]`,
608608 // where each element toggles the state.
@@ -613,7 +613,7 @@ impl<Tag, Extra> Allocation<Tag, Extra> {
613613 let mut cur = initial;
614614
615615 for i in 1 ..size. bytes ( ) {
616- // FIXME: optimize to bitshift the current undef block's bits and read the top bit.
616+ // FIXME: optimize to bitshift the current uninitialized block's bits and read the top bit.
617617 if self . init_mask . get ( src. offset + Size :: from_bytes ( i) ) == cur {
618618 cur_len += 1 ;
619619 } else {
@@ -625,13 +625,13 @@ impl<Tag, Extra> Allocation<Tag, Extra> {
625625
626626 ranges. push ( cur_len) ;
627627
628- AllocationDefinedness { ranges, initial }
628+ InitMaskCompressed { ranges, initial }
629629 }
630630
631- /// Applies multiple instances of the run-length encoding to the undef mask.
632- pub fn mark_compressed_undef_range (
631+ /// Applies multiple instances of the run-length encoding to the initialization mask.
632+ pub fn mark_compressed_init_range (
633633 & mut self ,
634- defined : & AllocationDefinedness ,
634+ defined : & InitMaskCompressed ,
635635 dest : Pointer < Tag > ,
636636 size : Size ,
637637 repeat : u64 ,
@@ -740,7 +740,7 @@ impl<Tag: Copy, Extra> Allocation<Tag, Extra> {
740740}
741741
742742////////////////////////////////////////////////////////////////////////////////
743- // Undefined byte tracking
743+ // Uninitialized byte tracking
744744////////////////////////////////////////////////////////////////////////////////
745745
746746type Block = u64 ;
@@ -778,11 +778,11 @@ impl InitMask {
778778
779779 match idx {
780780 Some ( idx) => {
781- let undef_end = ( idx. bytes ( ) ..end. bytes ( ) )
781+ let uninit_end = ( idx. bytes ( ) ..end. bytes ( ) )
782782 . map ( Size :: from_bytes)
783783 . find ( |& i| self . get ( i) )
784784 . unwrap_or ( end) ;
785- Err ( idx..undef_end )
785+ Err ( idx..uninit_end )
786786 }
787787 None => Ok ( ( ) ) ,
788788 }
0 commit comments