@@ -32,23 +32,16 @@ pub use init_mask::{InitChunk, InitChunkIter};
3232pub trait AllocBytes :
3333 Clone + fmt:: Debug + Eq + PartialEq + Hash + Deref < Target = [ u8 ] > + DerefMut < Target = [ u8 ] >
3434{
35- /// Adjust the bytes to the specified alignment -- by default, this is a no-op.
36- fn adjust_to_align ( self , _align : Align ) -> Self ;
37-
3835 /// Create an `AllocBytes` from a slice of `u8`.
3936 fn from_bytes < ' a > ( slice : impl Into < Cow < ' a , [ u8 ] > > , _align : Align ) -> Self ;
4037
41- /// Create a zeroed `AllocBytes` of the specified size and alignment;
42- /// call the callback error handler if there is an error in allocating the memory .
38+ /// Create a zeroed `AllocBytes` of the specified size and alignment.
39+ /// Returns `None` if we ran out of memory on the host .
4340 fn zeroed ( size : Size , _align : Align ) -> Option < Self > ;
4441}
4542
4643// Default `bytes` for `Allocation` is a `Box<[u8]>`.
4744impl AllocBytes for Box < [ u8 ] > {
48- fn adjust_to_align ( self , _align : Align ) -> Self {
49- self
50- }
51-
5245 fn from_bytes < ' a > ( slice : impl Into < Cow < ' a , [ u8 ] > > , _align : Align ) -> Self {
5346 Box :: < [ u8 ] > :: from ( slice. into ( ) )
5447 }
@@ -299,6 +292,7 @@ impl<Prov: Provenance, Bytes: AllocBytes> Allocation<Prov, (), Bytes> {
299292 }
300293
301294 fn uninit_inner < R > ( size : Size , align : Align , fail : impl FnOnce ( ) -> R ) -> Result < Self , R > {
295+ // We raise an error if we cannot create the allocation on the host.
302296 // This results in an error that can happen non-deterministically, since the memory
303297 // available to the compiler can change between runs. Normally queries are always
304298 // deterministic. However, we can be non-deterministic here because all uses of const
@@ -351,10 +345,8 @@ impl<Bytes: AllocBytes> Allocation<AllocId, (), Bytes> {
351345 extra : Extra ,
352346 mut adjust_ptr : impl FnMut ( Pointer < AllocId > ) -> Result < Pointer < Prov > , Err > ,
353347 ) -> Result < Allocation < Prov , Extra , Bytes > , Err > {
354- // Compute new pointer provenance, which also adjusts the bytes, and realign the pointer if
355- // necessary.
356- let mut bytes = self . bytes . adjust_to_align ( self . align ) ;
357-
348+ let mut bytes = self . bytes ;
349+ // Adjust provenance of pointers stored in this allocation.
358350 let mut new_provenance = Vec :: with_capacity ( self . provenance . ptrs ( ) . len ( ) ) ;
359351 let ptr_size = cx. data_layout ( ) . pointer_size . bytes_usize ( ) ;
360352 let endian = cx. data_layout ( ) . endian ;
0 commit comments