@@ -32,23 +32,16 @@ pub use init_mask::{InitChunk, InitChunkIter};
32
32
pub trait AllocBytes :
33
33
Clone + fmt:: Debug + Eq + PartialEq + Hash + Deref < Target = [ u8 ] > + DerefMut < Target = [ u8 ] >
34
34
{
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
-
38
35
/// Create an `AllocBytes` from a slice of `u8`.
39
36
fn from_bytes < ' a > ( slice : impl Into < Cow < ' a , [ u8 ] > > , _align : Align ) -> Self ;
40
37
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 .
43
40
fn zeroed ( size : Size , _align : Align ) -> Option < Self > ;
44
41
}
45
42
46
43
// Default `bytes` for `Allocation` is a `Box<[u8]>`.
47
44
impl AllocBytes for Box < [ u8 ] > {
48
- fn adjust_to_align ( self , _align : Align ) -> Self {
49
- self
50
- }
51
-
52
45
fn from_bytes < ' a > ( slice : impl Into < Cow < ' a , [ u8 ] > > , _align : Align ) -> Self {
53
46
Box :: < [ u8 ] > :: from ( slice. into ( ) )
54
47
}
@@ -299,6 +292,7 @@ impl<Prov: Provenance, Bytes: AllocBytes> Allocation<Prov, (), Bytes> {
299
292
}
300
293
301
294
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.
302
296
// This results in an error that can happen non-deterministically, since the memory
303
297
// available to the compiler can change between runs. Normally queries are always
304
298
// deterministic. However, we can be non-deterministic here because all uses of const
@@ -351,10 +345,8 @@ impl<Bytes: AllocBytes> Allocation<AllocId, (), Bytes> {
351
345
extra : Extra ,
352
346
mut adjust_ptr : impl FnMut ( Pointer < AllocId > ) -> Result < Pointer < Prov > , Err > ,
353
347
) -> 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.
358
350
let mut new_provenance = Vec :: with_capacity ( self . provenance . ptrs ( ) . len ( ) ) ;
359
351
let ptr_size = cx. data_layout ( ) . pointer_size . bytes_usize ( ) ;
360
352
let endian = cx. data_layout ( ) . endian ;
0 commit comments