Pass alignments through the shim as Alignment (not usize)
We're using `Layout` on both sides, so might as well skip the transmutes back and forth to `usize`. The mir-opt test shows that doing so allows simplifying the boxed-slice drop slightly, for example.
This commit is contained in:
parent
f403dee04e
commit
774268afc1
11 changed files with 41 additions and 70 deletions
|
|
@ -5,7 +5,7 @@
|
|||
#[stable(feature = "alloc_module", since = "1.28.0")]
|
||||
#[doc(inline)]
|
||||
pub use core::alloc::*;
|
||||
use core::ptr::{self, NonNull};
|
||||
use core::ptr::{self, Alignment, NonNull};
|
||||
use core::{cmp, hint};
|
||||
|
||||
unsafe extern "Rust" {
|
||||
|
|
@ -18,19 +18,19 @@ unsafe extern "Rust" {
|
|||
#[rustc_nounwind]
|
||||
#[rustc_std_internal_symbol]
|
||||
#[rustc_allocator_zeroed_variant = "__rust_alloc_zeroed"]
|
||||
fn __rust_alloc(size: usize, align: usize) -> *mut u8;
|
||||
fn __rust_alloc(size: usize, align: Alignment) -> *mut u8;
|
||||
#[rustc_deallocator]
|
||||
#[rustc_nounwind]
|
||||
#[rustc_std_internal_symbol]
|
||||
fn __rust_dealloc(ptr: *mut u8, size: usize, align: usize);
|
||||
fn __rust_dealloc(ptr: *mut u8, size: usize, align: Alignment);
|
||||
#[rustc_reallocator]
|
||||
#[rustc_nounwind]
|
||||
#[rustc_std_internal_symbol]
|
||||
fn __rust_realloc(ptr: *mut u8, old_size: usize, align: usize, new_size: usize) -> *mut u8;
|
||||
fn __rust_realloc(ptr: *mut u8, old_size: usize, align: Alignment, new_size: usize) -> *mut u8;
|
||||
#[rustc_allocator_zeroed]
|
||||
#[rustc_nounwind]
|
||||
#[rustc_std_internal_symbol]
|
||||
fn __rust_alloc_zeroed(size: usize, align: usize) -> *mut u8;
|
||||
fn __rust_alloc_zeroed(size: usize, align: Alignment) -> *mut u8;
|
||||
|
||||
#[rustc_nounwind]
|
||||
#[rustc_std_internal_symbol]
|
||||
|
|
@ -92,7 +92,7 @@ pub unsafe fn alloc(layout: Layout) -> *mut u8 {
|
|||
// stable code until it is actually stabilized.
|
||||
__rust_no_alloc_shim_is_unstable_v2();
|
||||
|
||||
__rust_alloc(layout.size(), layout.align())
|
||||
__rust_alloc(layout.size(), layout.alignment())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -112,7 +112,7 @@ pub unsafe fn alloc(layout: Layout) -> *mut u8 {
|
|||
#[inline]
|
||||
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
|
||||
pub unsafe fn dealloc(ptr: *mut u8, layout: Layout) {
|
||||
unsafe { __rust_dealloc(ptr, layout.size(), layout.align()) }
|
||||
unsafe { __rust_dealloc(ptr, layout.size(), layout.alignment()) }
|
||||
}
|
||||
|
||||
/// Reallocates memory with the global allocator.
|
||||
|
|
@ -132,7 +132,7 @@ pub unsafe fn dealloc(ptr: *mut u8, layout: Layout) {
|
|||
#[inline]
|
||||
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
|
||||
pub unsafe fn realloc(ptr: *mut u8, layout: Layout, new_size: usize) -> *mut u8 {
|
||||
unsafe { __rust_realloc(ptr, layout.size(), layout.align(), new_size) }
|
||||
unsafe { __rust_realloc(ptr, layout.size(), layout.alignment(), new_size) }
|
||||
}
|
||||
|
||||
/// Allocates zero-initialized memory with the global allocator.
|
||||
|
|
@ -175,7 +175,7 @@ pub unsafe fn alloc_zeroed(layout: Layout) -> *mut u8 {
|
|||
// stable code until it is actually stabilized.
|
||||
__rust_no_alloc_shim_is_unstable_v2();
|
||||
|
||||
__rust_alloc_zeroed(layout.size(), layout.align())
|
||||
__rust_alloc_zeroed(layout.size(), layout.alignment())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1777,7 +1777,7 @@ pub(crate) mod builtin {
|
|||
///
|
||||
/// See also [`std::alloc::GlobalAlloc`](../../../std/alloc/trait.GlobalAlloc.html).
|
||||
#[stable(feature = "global_allocator", since = "1.28.0")]
|
||||
#[allow_internal_unstable(rustc_attrs)]
|
||||
#[allow_internal_unstable(rustc_attrs, ptr_alignment_type)]
|
||||
#[rustc_builtin_macro]
|
||||
pub macro global_allocator($item:item) {
|
||||
/* compiler built-in */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue