address review comments; fix CI
This commit is contained in:
parent
3982d3e706
commit
47864e80cb
9 changed files with 77 additions and 74 deletions
|
|
@ -374,12 +374,8 @@ impl Global {
|
|||
let raw_ptr = core::intrinsics::const_allocate(layout.size(), layout.align());
|
||||
let ptr = NonNull::new(raw_ptr).ok_or(AllocError)?;
|
||||
if zeroed {
|
||||
let mut offset = 0;
|
||||
while offset < size {
|
||||
offset += 1;
|
||||
// SAFETY: the pointer returned by `const_allocate` is valid to write to.
|
||||
ptr.add(offset).write(0)
|
||||
}
|
||||
// SAFETY: the pointer returned by `const_allocate` is valid to write to.
|
||||
ptr.write_bytes(0, size);
|
||||
}
|
||||
Ok(NonNull::slice_from_raw_parts(ptr, size))
|
||||
},
|
||||
|
|
|
|||
|
|
@ -124,6 +124,7 @@
|
|||
#![feature(fmt_internals)]
|
||||
#![feature(fn_traits)]
|
||||
#![feature(formatting_options)]
|
||||
#![feature(freeze)]
|
||||
#![feature(generic_atomic)]
|
||||
#![feature(hasher_prefixfree_extras)]
|
||||
#![feature(inplace_iteration)]
|
||||
|
|
|
|||
|
|
@ -83,7 +83,7 @@ use core::hash::{Hash, Hasher};
|
|||
use core::iter;
|
||||
#[cfg(not(no_global_oom_handling))]
|
||||
use core::marker::Destruct;
|
||||
use core::marker::PhantomData;
|
||||
use core::marker::{Freeze, PhantomData};
|
||||
use core::mem::{self, Assume, ManuallyDrop, MaybeUninit, SizedTypeProperties, TransmuteFrom};
|
||||
use core::ops::{self, Index, IndexMut, Range, RangeBounds};
|
||||
use core::ptr::{self, NonNull};
|
||||
|
|
@ -885,11 +885,17 @@ impl<T> Vec<T> {
|
|||
(unsafe { NonNull::new_unchecked(ptr) }, len, capacity)
|
||||
}
|
||||
|
||||
/// Leaks the `Vec<T>` to be interned statically. This mut be done for all
|
||||
/// `Vec<T>` created during compile time.
|
||||
/// Interns the `Vec<T>`, making the underlying memory read-only. This method should be
|
||||
/// called during compile time. (This is a no-op if called during runtime)
|
||||
///
|
||||
/// This method must be called if the memory used by `Vec` needs to appear in the final
|
||||
/// values of constants.
|
||||
#[unstable(feature = "const_heap", issue = "79597")]
|
||||
#[rustc_const_unstable(feature = "const_heap", issue = "79597")]
|
||||
pub const fn const_leak(mut self) -> &'static [T] {
|
||||
pub const fn const_make_global(mut self) -> &'static [T]
|
||||
where
|
||||
T: Freeze,
|
||||
{
|
||||
unsafe { core::intrinsics::const_make_global(self.as_mut_ptr().cast()) };
|
||||
let me = ManuallyDrop::new(self);
|
||||
unsafe { slice::from_raw_parts(me.as_ptr(), me.len) }
|
||||
|
|
|
|||
|
|
@ -2760,7 +2760,7 @@ fn const_heap() {
|
|||
x *= 2;
|
||||
}
|
||||
assert!(v.len() == 6);
|
||||
v.const_leak()
|
||||
v.const_make_global()
|
||||
};
|
||||
|
||||
assert_eq!([1, 2, 4, 8, 16, 32], X);
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ pub fn foo2() -> Box<dyn TestTrait2> {
|
|||
//~ MONO_ITEM fn <TestStruct2 as TestTrait2>::test_func2
|
||||
//~ MONO_ITEM fn alloc::alloc::exchange_malloc
|
||||
//~ MONO_ITEM fn foo2
|
||||
//~ MONO_ITEM fn std::alloc::Global::alloc_impl
|
||||
//~ MONO_ITEM fn std::alloc::Global::alloc_impl_runtime
|
||||
//~ MONO_ITEM fn std::boxed::Box::<TestStruct2>::new
|
||||
//~ MONO_ITEM fn std::alloc::Layout::from_size_align_unchecked::precondition_check
|
||||
//~ MONO_ITEM fn std::ptr::Alignment::new_unchecked::precondition_check
|
||||
|
|
|
|||
|
|
@ -25,17 +25,21 @@ fn generic_in_place(_1: *mut Box<[T]>) -> () {
|
|||
}
|
||||
}
|
||||
scope 18 (inlined <std::alloc::Global as Allocator>::deallocate) {
|
||||
let mut _9: *mut u8;
|
||||
scope 19 (inlined Layout::size) {
|
||||
}
|
||||
scope 20 (inlined NonNull::<u8>::as_ptr) {
|
||||
}
|
||||
scope 21 (inlined std::alloc::dealloc) {
|
||||
let mut _10: usize;
|
||||
scope 22 (inlined Layout::size) {
|
||||
}
|
||||
scope 23 (inlined Layout::align) {
|
||||
scope 24 (inlined std::ptr::Alignment::as_usize) {
|
||||
scope 19 (inlined std::alloc::Global::deallocate_impl) {
|
||||
scope 20 (inlined std::alloc::Global::deallocate_impl_runtime) {
|
||||
let mut _9: *mut u8;
|
||||
scope 21 (inlined Layout::size) {
|
||||
}
|
||||
scope 22 (inlined NonNull::<u8>::as_ptr) {
|
||||
}
|
||||
scope 23 (inlined std::alloc::dealloc) {
|
||||
let mut _10: usize;
|
||||
scope 24 (inlined Layout::size) {
|
||||
}
|
||||
scope 25 (inlined Layout::align) {
|
||||
scope 26 (inlined std::ptr::Alignment::as_usize) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,17 +25,21 @@ fn generic_in_place(_1: *mut Box<[T]>) -> () {
|
|||
}
|
||||
}
|
||||
scope 18 (inlined <std::alloc::Global as Allocator>::deallocate) {
|
||||
let mut _9: *mut u8;
|
||||
scope 19 (inlined Layout::size) {
|
||||
}
|
||||
scope 20 (inlined NonNull::<u8>::as_ptr) {
|
||||
}
|
||||
scope 21 (inlined std::alloc::dealloc) {
|
||||
let mut _10: usize;
|
||||
scope 22 (inlined Layout::size) {
|
||||
}
|
||||
scope 23 (inlined Layout::align) {
|
||||
scope 24 (inlined std::ptr::Alignment::as_usize) {
|
||||
scope 19 (inlined std::alloc::Global::deallocate_impl) {
|
||||
scope 20 (inlined std::alloc::Global::deallocate_impl_runtime) {
|
||||
let mut _9: *mut u8;
|
||||
scope 21 (inlined Layout::size) {
|
||||
}
|
||||
scope 22 (inlined NonNull::<u8>::as_ptr) {
|
||||
}
|
||||
scope 23 (inlined std::alloc::dealloc) {
|
||||
let mut _10: usize;
|
||||
scope 24 (inlined Layout::size) {
|
||||
}
|
||||
scope 25 (inlined Layout::align) {
|
||||
scope 26 (inlined std::ptr::Alignment::as_usize) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,22 +9,22 @@
|
|||
let mut _4: *mut [u8];
|
||||
let mut _5: std::ptr::NonNull<[u8]>;
|
||||
let mut _6: std::result::Result<std::ptr::NonNull<[u8]>, std::alloc::AllocError>;
|
||||
let mut _7: &std::alloc::Global;
|
||||
let mut _8: std::alloc::Layout;
|
||||
let mut _7: std::alloc::Layout;
|
||||
scope 1 {
|
||||
debug layout => _1;
|
||||
let mut _9: &std::alloc::Global;
|
||||
scope 2 {
|
||||
debug ptr => _3;
|
||||
}
|
||||
scope 5 (inlined <std::alloc::Global as Allocator>::allocate) {
|
||||
scope 6 (inlined std::alloc::Global::alloc_impl) {
|
||||
}
|
||||
}
|
||||
scope 6 (inlined NonNull::<[u8]>::as_ptr) {
|
||||
scope 7 (inlined NonNull::<[u8]>::as_ptr) {
|
||||
}
|
||||
}
|
||||
scope 3 (inlined #[track_caller] Option::<Layout>::unwrap) {
|
||||
let mut _10: isize;
|
||||
let mut _11: !;
|
||||
let mut _8: isize;
|
||||
let mut _9: !;
|
||||
scope 4 {
|
||||
}
|
||||
}
|
||||
|
|
@ -35,10 +35,10 @@
|
|||
StorageLive(_2);
|
||||
- _2 = Option::<Layout>::None;
|
||||
+ _2 = const Option::<Layout>::None;
|
||||
StorageLive(_10);
|
||||
- _10 = discriminant(_2);
|
||||
- switchInt(move _10) -> [0: bb3, 1: bb4, otherwise: bb2];
|
||||
+ _10 = const 0_isize;
|
||||
StorageLive(_8);
|
||||
- _8 = discriminant(_2);
|
||||
- switchInt(move _8) -> [0: bb3, 1: bb4, otherwise: bb2];
|
||||
+ _8 = const 0_isize;
|
||||
+ switchInt(const 0_isize) -> [0: bb3, 1: bb4, otherwise: bb2];
|
||||
}
|
||||
|
||||
|
|
@ -59,30 +59,26 @@
|
|||
}
|
||||
|
||||
bb3: {
|
||||
_11 = option::unwrap_failed() -> unwind continue;
|
||||
_9 = option::unwrap_failed() -> unwind continue;
|
||||
}
|
||||
|
||||
bb4: {
|
||||
- _1 = move ((_2 as Some).0: std::alloc::Layout);
|
||||
+ _1 = const Layout {{ size: Indirect { alloc_id: ALLOC0, offset: Size(4 bytes) }: usize, align: std::ptr::Alignment(Scalar(0x00000000): std::ptr::alignment::AlignmentEnum) }};
|
||||
StorageDead(_10);
|
||||
StorageDead(_8);
|
||||
StorageDead(_2);
|
||||
StorageLive(_3);
|
||||
StorageLive(_4);
|
||||
StorageLive(_5);
|
||||
StorageLive(_6);
|
||||
StorageLive(_7);
|
||||
_9 = const main::promoted[0];
|
||||
_7 = copy _9;
|
||||
StorageLive(_8);
|
||||
- _8 = copy _1;
|
||||
- _6 = std::alloc::Global::alloc_impl(move _7, move _8, const false) -> [return: bb5, unwind continue];
|
||||
+ _8 = const Layout {{ size: Indirect { alloc_id: ALLOC0, offset: Size(4 bytes) }: usize, align: std::ptr::Alignment(Scalar(0x00000000): std::ptr::alignment::AlignmentEnum) }};
|
||||
+ _6 = std::alloc::Global::alloc_impl(copy _9, const Layout {{ size: Indirect { alloc_id: ALLOC0, offset: Size(4 bytes) }: usize, align: std::ptr::Alignment(Scalar(0x00000000): std::ptr::alignment::AlignmentEnum) }}, const false) -> [return: bb5, unwind continue];
|
||||
- _7 = copy _1;
|
||||
- _6 = std::alloc::Global::alloc_impl_runtime(move _7, const false) -> [return: bb5, unwind continue];
|
||||
+ _7 = const Layout {{ size: Indirect { alloc_id: ALLOC0, offset: Size(4 bytes) }: usize, align: std::ptr::Alignment(Scalar(0x00000000): std::ptr::alignment::AlignmentEnum) }};
|
||||
+ _6 = std::alloc::Global::alloc_impl_runtime(const Layout {{ size: Indirect { alloc_id: ALLOC0, offset: Size(4 bytes) }: usize, align: std::ptr::Alignment(Scalar(0x00000000): std::ptr::alignment::AlignmentEnum) }}, const false) -> [return: bb5, unwind continue];
|
||||
}
|
||||
|
||||
bb5: {
|
||||
StorageDead(_8);
|
||||
StorageDead(_7);
|
||||
_5 = Result::<NonNull<[u8]>, std::alloc::AllocError>::unwrap(move _6) -> [return: bb1, unwind continue];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,22 +9,22 @@
|
|||
let mut _4: *mut [u8];
|
||||
let mut _5: std::ptr::NonNull<[u8]>;
|
||||
let mut _6: std::result::Result<std::ptr::NonNull<[u8]>, std::alloc::AllocError>;
|
||||
let mut _7: &std::alloc::Global;
|
||||
let mut _8: std::alloc::Layout;
|
||||
let mut _7: std::alloc::Layout;
|
||||
scope 1 {
|
||||
debug layout => _1;
|
||||
let mut _9: &std::alloc::Global;
|
||||
scope 2 {
|
||||
debug ptr => _3;
|
||||
}
|
||||
scope 5 (inlined <std::alloc::Global as Allocator>::allocate) {
|
||||
scope 6 (inlined std::alloc::Global::alloc_impl) {
|
||||
}
|
||||
}
|
||||
scope 6 (inlined NonNull::<[u8]>::as_ptr) {
|
||||
scope 7 (inlined NonNull::<[u8]>::as_ptr) {
|
||||
}
|
||||
}
|
||||
scope 3 (inlined #[track_caller] Option::<Layout>::unwrap) {
|
||||
let mut _10: isize;
|
||||
let mut _11: !;
|
||||
let mut _8: isize;
|
||||
let mut _9: !;
|
||||
scope 4 {
|
||||
}
|
||||
}
|
||||
|
|
@ -35,10 +35,10 @@
|
|||
StorageLive(_2);
|
||||
- _2 = Option::<Layout>::None;
|
||||
+ _2 = const Option::<Layout>::None;
|
||||
StorageLive(_10);
|
||||
- _10 = discriminant(_2);
|
||||
- switchInt(move _10) -> [0: bb3, 1: bb4, otherwise: bb2];
|
||||
+ _10 = const 0_isize;
|
||||
StorageLive(_8);
|
||||
- _8 = discriminant(_2);
|
||||
- switchInt(move _8) -> [0: bb3, 1: bb4, otherwise: bb2];
|
||||
+ _8 = const 0_isize;
|
||||
+ switchInt(const 0_isize) -> [0: bb3, 1: bb4, otherwise: bb2];
|
||||
}
|
||||
|
||||
|
|
@ -59,30 +59,26 @@
|
|||
}
|
||||
|
||||
bb3: {
|
||||
_11 = option::unwrap_failed() -> unwind continue;
|
||||
_9 = option::unwrap_failed() -> unwind continue;
|
||||
}
|
||||
|
||||
bb4: {
|
||||
- _1 = move ((_2 as Some).0: std::alloc::Layout);
|
||||
+ _1 = const Layout {{ size: Indirect { alloc_id: ALLOC0, offset: Size(8 bytes) }: usize, align: std::ptr::Alignment(Scalar(0x0000000000000000): std::ptr::alignment::AlignmentEnum) }};
|
||||
StorageDead(_10);
|
||||
StorageDead(_8);
|
||||
StorageDead(_2);
|
||||
StorageLive(_3);
|
||||
StorageLive(_4);
|
||||
StorageLive(_5);
|
||||
StorageLive(_6);
|
||||
StorageLive(_7);
|
||||
_9 = const main::promoted[0];
|
||||
_7 = copy _9;
|
||||
StorageLive(_8);
|
||||
- _8 = copy _1;
|
||||
- _6 = std::alloc::Global::alloc_impl(move _7, move _8, const false) -> [return: bb5, unwind continue];
|
||||
+ _8 = const Layout {{ size: Indirect { alloc_id: ALLOC0, offset: Size(8 bytes) }: usize, align: std::ptr::Alignment(Scalar(0x0000000000000000): std::ptr::alignment::AlignmentEnum) }};
|
||||
+ _6 = std::alloc::Global::alloc_impl(copy _9, const Layout {{ size: Indirect { alloc_id: ALLOC0, offset: Size(8 bytes) }: usize, align: std::ptr::Alignment(Scalar(0x0000000000000000): std::ptr::alignment::AlignmentEnum) }}, const false) -> [return: bb5, unwind continue];
|
||||
- _7 = copy _1;
|
||||
- _6 = std::alloc::Global::alloc_impl_runtime(move _7, const false) -> [return: bb5, unwind continue];
|
||||
+ _7 = const Layout {{ size: Indirect { alloc_id: ALLOC0, offset: Size(8 bytes) }: usize, align: std::ptr::Alignment(Scalar(0x0000000000000000): std::ptr::alignment::AlignmentEnum) }};
|
||||
+ _6 = std::alloc::Global::alloc_impl_runtime(const Layout {{ size: Indirect { alloc_id: ALLOC0, offset: Size(8 bytes) }: usize, align: std::ptr::Alignment(Scalar(0x0000000000000000): std::ptr::alignment::AlignmentEnum) }}, const false) -> [return: bb5, unwind continue];
|
||||
}
|
||||
|
||||
bb5: {
|
||||
StorageDead(_8);
|
||||
StorageDead(_7);
|
||||
_5 = Result::<NonNull<[u8]>, std::alloc::AllocError>::unwrap(move _6) -> [return: bb1, unwind continue];
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue