Skip to content

Commit bf2363d

Browse files
CoAlloc: Removed co_alloc_metadata_num_slots(). Added docs.
1 parent 35b828d commit bf2363d

File tree

2 files changed

+8
-23
lines changed

2 files changed

+8
-23
lines changed

library/alloc/src/boxed.rs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -749,7 +749,7 @@ impl<T> Box<[T]> {
749749

750750
impl<T, A: Allocator> Box<[T], A>
751751
where
752-
[(); core::alloc::co_alloc_metadata_num_slots::<A>()]:,
752+
[(); core::alloc::co_alloc_metadata_num_slots_with_preference::<A>(false)]:,
753753
{
754754
/// Constructs a new boxed slice with uninitialized contents in the provided allocator.
755755
///
@@ -778,11 +778,7 @@ where
778778
// #[unstable(feature = "new_uninit", issue = "63291")]
779779
#[must_use]
780780
#[allow(unused_braces)]
781-
pub fn new_uninit_slice_in(len: usize, alloc: A) -> Box<[mem::MaybeUninit<T>], A>
782-
where
783-
// false = no need for co-alloc metadata, since it would get lost once converted to Box.
784-
[(); core::alloc::co_alloc_metadata_num_slots_with_preference::<A>(false)]:,
785-
{
781+
pub fn new_uninit_slice_in(len: usize, alloc: A) -> Box<[mem::MaybeUninit<T>], A> {
786782
unsafe { RawVec::<T, A, false>::with_capacity_in(len, alloc).into_box(len) }
787783
}
788784

@@ -811,11 +807,7 @@ where
811807
// #[unstable(feature = "new_uninit", issue = "63291")]
812808
#[must_use]
813809
#[allow(unused_braces)]
814-
pub fn new_zeroed_slice_in(len: usize, alloc: A) -> Box<[mem::MaybeUninit<T>], A>
815-
where
816-
// false = no need for co-alloc metadata, since it would get lost once converted to Box.
817-
[(); core::alloc::co_alloc_metadata_num_slots_with_preference::<A>(false)]:,
818-
{
810+
pub fn new_zeroed_slice_in(len: usize, alloc: A) -> Box<[mem::MaybeUninit<T>], A> {
819811
unsafe { RawVec::<T, A, false>::with_capacity_zeroed_in(len, alloc).into_box(len) }
820812
}
821813
}

library/core/src/alloc/mod.rs

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,15 @@ impl fmt::Display for AllocError {
6565
}
6666
}
6767

68+
/// (Non-Null) Pointer and coallocation metadata.
6869
#[unstable(feature = "global_co_alloc_meta", issue = "none")]
6970
#[allow(missing_debug_implementations)]
7071
pub struct PtrAndMeta {
7172
pub ptr: NonNull<u8>,
7273
pub meta: GlobalCoAllocMeta,
7374
}
7475

76+
/// (NonNull) Slice and coallocation metadata.
7577
#[unstable(feature = "global_co_alloc_meta", issue = "none")]
7678
#[allow(missing_debug_implementations)]
7779
/// Used for results (from `CoAllocator`'s functions, where applicable).
@@ -89,24 +91,15 @@ macro_rules! SHORT_TERM_VEC_PREFERS_COOP {
8991
};
9092
}
9193

94+
/// `Result` of `SliceAndMeta` or `AllocError`.
9295
#[unstable(feature = "global_co_alloc_meta", issue = "none")]
9396
#[allow(missing_debug_implementations)]
9497
pub type SliceAndMetaResult = Result<SliceAndMeta, AllocError>;
9598

96-
#[unstable(feature = "global_co_alloc", issue = "none")]
97-
pub const fn co_alloc_metadata_num_slots<A: Allocator>() -> usize {
98-
// @FIXME later
99-
if false {
100-
panic!(
101-
"FIXME - consider replacing co_alloc_metadata_num_slots() with co_alloc_metadata_num_slots_with_preference(bool), and adding const flags as appropriate."
102-
);
103-
}
104-
if A::IS_CO_ALLOCATOR { 1 } else { 0 }
105-
}
106-
107-
#[unstable(feature = "global_co_alloc", issue = "none")]
99+
/// Return 0 or 1, indicating whether to use coallocation metadata or not.
108100
/// Param `coop_preferred` - if false, then this returns `0`, regardless of
109101
/// whether allocator `A` is cooperative.
102+
#[unstable(feature = "global_co_alloc", issue = "none")]
110103
pub const fn co_alloc_metadata_num_slots_with_preference<A: Allocator>(
111104
coop_preferred: bool,
112105
) -> usize {

0 commit comments

Comments
 (0)