Skip to content

Commit 0f5e8b0

Browse files
CoAlloc: Renaming to use new value/config + transformation macros.
1 parent 687a318 commit 0f5e8b0

30 files changed

+595
-564
lines changed

library/alloc/src/boxed.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ use core::ops::{
167167
use core::pin::Pin;
168168
use core::ptr::{self, Unique};
169169
use core::task::{Context, Poll};
170+
use crate::co_alloc::CoAllocPref;
170171

171172
#[cfg(not(no_global_oom_handling))]
172173
use crate::alloc::{handle_alloc_error, WriteCloneIntoRaw};
@@ -749,7 +750,7 @@ impl<T> Box<[T]> {
749750

750751
impl<T, A: Allocator> Box<[T], A>
751752
where
752-
[(); core::alloc::co_alloc_metadata_num_slots_with_preference::<A>(false)]:,
753+
[(); {crate::meta_num_slots!(A, crate::CO_ALLOC_PREF_META_NO!())}]:,
753754
{
754755
/// Constructs a new boxed slice with uninitialized contents in the provided allocator.
755756
///
@@ -1679,11 +1680,11 @@ impl<T, const N: usize> TryFrom<Box<[T]>> for Box<[T; N]> {
16791680

16801681
#[cfg(not(no_global_oom_handling))]
16811682
#[stable(feature = "boxed_array_try_from_vec", since = "1.66.0")]
1682-
impl<T, const N: usize, const COOP_PREF: bool> TryFrom<Vec<T, Global, COOP_PREF>> for Box<[T; N]>
1683+
impl<T, const N: usize, const CO_ALLOC_PREF: CoAllocPref> TryFrom<Vec<T, Global, CO_ALLOC_PREF>> for Box<[T; N]>
16831684
where
1684-
[(); core::alloc::co_alloc_metadata_num_slots_with_preference::<Global>(COOP_PREF)]:,
1685+
[(); {meta_num_slots_global!(CO_ALLOC_PREF)}]:,
16851686
{
1686-
type Error = Vec<T, Global, COOP_PREF>;
1687+
type Error = Vec<T, Global, CO_ALLOC_PREF>;
16871688

16881689
/// Attempts to convert a `Vec<T>` into a `Box<[T; N]>`.
16891690
///
@@ -1703,7 +1704,7 @@ where
17031704
/// let state: Box<[f32; 100]> = vec![1.0; 100].try_into().unwrap();
17041705
/// assert_eq!(state.len(), 100);
17051706
/// ```
1706-
fn try_from(vec: Vec<T, Global, COOP_PREF>) -> Result<Self, Self::Error> {
1707+
fn try_from(vec: Vec<T, Global, CO_ALLOC_PREF>) -> Result<Self, Self::Error> {
17071708
if vec.len() == N {
17081709
let boxed_slice = vec.into_boxed_slice();
17091710
Ok(unsafe { boxed_slice_as_array_unchecked(boxed_slice) })
@@ -2042,7 +2043,7 @@ impl<I> FromIterator<I> for Box<[I]> {
20422043
#[stable(feature = "box_slice_clone", since = "1.3.0")]
20432044
impl<T: Clone, A: Allocator + Clone> Clone for Box<[T], A>
20442045
where
2045-
[(); core::alloc::co_alloc_metadata_num_slots_with_preference::<A>(false)]:,
2046+
[(); {crate::meta_num_slots!(A, crate::CO_ALLOC_PREF_META_NO!())}]:,
20462047
{
20472048
fn clone(&self) -> Self {
20482049
let alloc = Box::allocator(self).clone();

library/alloc/src/collections/binary_heap/mod.rs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@
145145

146146
use core::fmt;
147147
use core::iter::{FromIterator, FusedIterator, InPlaceIterable, SourceIter, TrustedLen};
148+
use crate::co_alloc::CoAllocPref;
148149
use core::mem::{self, swap, ManuallyDrop};
149150
use core::num::NonZeroUsize;
150151
use core::ops::{Deref, DerefMut};
@@ -1525,17 +1526,17 @@ unsafe impl<T: Ord> TrustedLen for IntoIterSorted<T> {}
15251526
/// [`drain`]: BinaryHeap::drain
15261527
#[stable(feature = "drain", since = "1.6.0")]
15271528
#[derive(Debug)]
1528-
pub struct Drain<'a, T: 'a, const COOP_PREF: bool>
1529+
pub struct Drain<'a, T: 'a, const CO_ALLOC_PREF: CoAllocPref>
15291530
where
1530-
[(); core::alloc::co_alloc_metadata_num_slots_with_preference::<Global>(COOP_PREF)]:,
1531+
[(); {meta_num_slots_global!(CO_ALLOC_PREF)}]:,
15311532
{
1532-
iter: vec::Drain<'a, T, Global, COOP_PREF>,
1533+
iter: vec::Drain<'a, T, Global, CO_ALLOC_PREF>,
15331534
}
15341535

15351536
#[stable(feature = "drain", since = "1.6.0")]
1536-
impl<T, const COOP_PREF: bool> Iterator for Drain<'_, T, COOP_PREF>
1537+
impl<T, const CO_ALLOC_PREF: CoAllocPref> Iterator for Drain<'_, T, CO_ALLOC_PREF>
15371538
where
1538-
[(); core::alloc::co_alloc_metadata_num_slots_with_preference::<Global>(COOP_PREF)]:,
1539+
[(); {meta_num_slots_global!(CO_ALLOC_PREF)}]:,
15391540
{
15401541
type Item = T;
15411542

@@ -1551,9 +1552,9 @@ where
15511552
}
15521553

15531554
#[stable(feature = "drain", since = "1.6.0")]
1554-
impl<T, const COOP_PREF: bool> DoubleEndedIterator for Drain<'_, T, COOP_PREF>
1555+
impl<T, const CO_ALLOC_PREF: CoAllocPref> DoubleEndedIterator for Drain<'_, T, CO_ALLOC_PREF>
15551556
where
1556-
[(); core::alloc::co_alloc_metadata_num_slots_with_preference::<Global>(COOP_PREF)]:,
1557+
[(); {meta_num_slots_global!(CO_ALLOC_PREF)}]:,
15571558
{
15581559
#[inline]
15591560
fn next_back(&mut self) -> Option<T> {
@@ -1562,18 +1563,18 @@ where
15621563
}
15631564

15641565
#[stable(feature = "drain", since = "1.6.0")]
1565-
impl<T, const COOP_PREF: bool> ExactSizeIterator for Drain<'_, T, COOP_PREF>
1566+
impl<T, const CO_ALLOC_PREF: CoAllocPref> ExactSizeIterator for Drain<'_, T, CO_ALLOC_PREF>
15661567
where
1567-
[(); core::alloc::co_alloc_metadata_num_slots_with_preference::<Global>(COOP_PREF)]:,
1568+
[(); {meta_num_slots_global!(CO_ALLOC_PREF)}]:,
15681569
{
15691570
fn is_empty(&self) -> bool {
15701571
self.iter.is_empty()
15711572
}
15721573
}
15731574

15741575
#[stable(feature = "fused", since = "1.26.0")]
1575-
impl<T, const COOP_PREF: bool> FusedIterator for Drain<'_, T, COOP_PREF> where
1576-
[(); core::alloc::co_alloc_metadata_num_slots_with_preference::<Global>(COOP_PREF)]:
1576+
impl<T, const CO_ALLOC_PREF: CoAllocPref> FusedIterator for Drain<'_, T, CO_ALLOC_PREF> where
1577+
[(); {meta_num_slots_global!(CO_ALLOC_PREF)}]:
15771578
{
15781579
}
15791580

library/alloc/src/collections/vec_deque/drain.rs

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use core::iter::FusedIterator;
2+
use crate::co_alloc::CoAllocPref;
23
use core::marker::PhantomData;
34
use core::mem::{self, SizedTypeProperties};
45
use core::ptr::NonNull;
@@ -20,13 +21,13 @@ pub struct Drain<
2021
'a,
2122
T: 'a,
2223
#[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global,
23-
const COOP_PREF: bool = { SHORT_TERM_VEC_PREFERS_COOP!() },
24+
const CO_ALLOC_PREF: CoAllocPref = { SHORT_TERM_VEC_PREFERS_COOP!() },
2425
> where
25-
[(); alloc::co_alloc_metadata_num_slots_with_preference::<A>(COOP_PREF)]:,
26+
[(); alloc::co_alloc_metadata_num_slots_with_preference::<A>(CO_ALLOC_PREF)]:,
2627
{
2728
// We can't just use a &mut VecDeque<T, A>, as that would make Drain invariant over T
2829
// and we want it to be covariant instead
29-
deque: NonNull<VecDeque<T, A, COOP_PREF>>,
30+
deque: NonNull<VecDeque<T, A, CO_ALLOC_PREF>>,
3031
// drain_start is stored in deque.len
3132
drain_len: usize,
3233
// index into the logical array, not the physical one (always lies in [0..deque.len))
@@ -38,12 +39,12 @@ pub struct Drain<
3839
_marker: PhantomData<&'a T>,
3940
}
4041

41-
impl<'a, T, A: Allocator, const COOP_PREF: bool> Drain<'a, T, A, COOP_PREF>
42+
impl<'a, T, A: Allocator, const CO_ALLOC_PREF: CoAllocPref> Drain<'a, T, A, CO_ALLOC_PREF>
4243
where
43-
[(); alloc::co_alloc_metadata_num_slots_with_preference::<A>(COOP_PREF)]:,
44+
[(); alloc::co_alloc_metadata_num_slots_with_preference::<A>(CO_ALLOC_PREF)]:,
4445
{
4546
pub(super) unsafe fn new(
46-
deque: &'a mut VecDeque<T, A, COOP_PREF>,
47+
deque: &'a mut VecDeque<T, A, CO_ALLOC_PREF>,
4748
drain_start: usize,
4849
drain_len: usize,
4950
) -> Self {
@@ -95,9 +96,9 @@ where
9596
}
9697

9798
#[stable(feature = "collection_debug", since = "1.17.0")]
98-
impl<T: fmt::Debug, A: Allocator, const COOP_PREF: bool> fmt::Debug for Drain<'_, T, A, COOP_PREF>
99+
impl<T: fmt::Debug, A: Allocator, const CO_ALLOC_PREF: CoAllocPref> fmt::Debug for Drain<'_, T, A, CO_ALLOC_PREF>
99100
where
100-
[(); alloc::co_alloc_metadata_num_slots_with_preference::<A>(COOP_PREF)]:,
101+
[(); alloc::co_alloc_metadata_num_slots_with_preference::<A>(CO_ALLOC_PREF)]:,
101102
{
102103
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
103104
f.debug_tuple("Drain")
@@ -110,31 +111,31 @@ where
110111
}
111112

112113
#[stable(feature = "drain", since = "1.6.0")]
113-
unsafe impl<T: Sync, A: Allocator + Sync, const COOP_PREF: bool> Sync for Drain<'_, T, A, COOP_PREF> where
114-
[(); alloc::co_alloc_metadata_num_slots_with_preference::<A>(COOP_PREF)]:
114+
unsafe impl<T: Sync, A: Allocator + Sync, const CO_ALLOC_PREF: CoAllocPref> Sync for Drain<'_, T, A, CO_ALLOC_PREF> where
115+
[(); alloc::co_alloc_metadata_num_slots_with_preference::<A>(CO_ALLOC_PREF)]:
115116
{
116117
}
117118
#[stable(feature = "drain", since = "1.6.0")]
118-
unsafe impl<T: Send, A: Allocator + Send, const COOP_PREF: bool> Send for Drain<'_, T, A, COOP_PREF> where
119-
[(); alloc::co_alloc_metadata_num_slots_with_preference::<A>(COOP_PREF)]:
119+
unsafe impl<T: Send, A: Allocator + Send, const CO_ALLOC_PREF: CoAllocPref> Send for Drain<'_, T, A, CO_ALLOC_PREF> where
120+
[(); alloc::co_alloc_metadata_num_slots_with_preference::<A>(CO_ALLOC_PREF)]:
120121
{
121122
}
122123

123124
#[stable(feature = "drain", since = "1.6.0")]
124-
impl<T, A: Allocator, const COOP_PREF: bool> Drop for Drain<'_, T, A, COOP_PREF>
125+
impl<T, A: Allocator, const CO_ALLOC_PREF: CoAllocPref> Drop for Drain<'_, T, A, CO_ALLOC_PREF>
125126
where
126-
[(); alloc::co_alloc_metadata_num_slots_with_preference::<A>(COOP_PREF)]:,
127+
[(); alloc::co_alloc_metadata_num_slots_with_preference::<A>(CO_ALLOC_PREF)]:,
127128
{
128129
fn drop(&mut self) {
129-
struct DropGuard<'r, 'a, T, A: Allocator, const COOP_PREF: bool>(
130-
&'r mut Drain<'a, T, A, COOP_PREF>,
130+
struct DropGuard<'r, 'a, T, A: Allocator, const CO_ALLOC_PREF: CoAllocPref>(
131+
&'r mut Drain<'a, T, A, CO_ALLOC_PREF>,
131132
)
132133
where
133-
[(); alloc::co_alloc_metadata_num_slots_with_preference::<A>(COOP_PREF)]:;
134+
[(); alloc::co_alloc_metadata_num_slots_with_preference::<A>(CO_ALLOC_PREF)]:;
134135

135-
impl<'r, 'a, T, A: Allocator, const COOP_PREF: bool> Drop for DropGuard<'r, 'a, T, A, COOP_PREF>
136+
impl<'r, 'a, T, A: Allocator, const CO_ALLOC_PREF: CoAllocPref> Drop for DropGuard<'r, 'a, T, A, CO_ALLOC_PREF>
136137
where
137-
[(); alloc::co_alloc_metadata_num_slots_with_preference::<A>(COOP_PREF)]:,
138+
[(); alloc::co_alloc_metadata_num_slots_with_preference::<A>(CO_ALLOC_PREF)]:,
138139
{
139140
fn drop(&mut self) {
140141
if self.0.remaining != 0 {
@@ -216,9 +217,9 @@ where
216217
}
217218

218219
#[stable(feature = "drain", since = "1.6.0")]
219-
impl<T, A: Allocator, const COOP_PREF: bool> Iterator for Drain<'_, T, A, COOP_PREF>
220+
impl<T, A: Allocator, const CO_ALLOC_PREF: CoAllocPref> Iterator for Drain<'_, T, A, CO_ALLOC_PREF>
220221
where
221-
[(); alloc::co_alloc_metadata_num_slots_with_preference::<A>(COOP_PREF)]:,
222+
[(); alloc::co_alloc_metadata_num_slots_with_preference::<A>(CO_ALLOC_PREF)]:,
222223
{
223224
type Item = T;
224225

@@ -241,9 +242,9 @@ where
241242
}
242243

243244
#[stable(feature = "drain", since = "1.6.0")]
244-
impl<T, A: Allocator, const COOP_PREF: bool> DoubleEndedIterator for Drain<'_, T, A, COOP_PREF>
245+
impl<T, A: Allocator, const CO_ALLOC_PREF: CoAllocPref> DoubleEndedIterator for Drain<'_, T, A, CO_ALLOC_PREF>
245246
where
246-
[(); alloc::co_alloc_metadata_num_slots_with_preference::<A>(COOP_PREF)]:,
247+
[(); alloc::co_alloc_metadata_num_slots_with_preference::<A>(CO_ALLOC_PREF)]:,
247248
{
248249
#[inline]
249250
fn next_back(&mut self) -> Option<T> {
@@ -257,13 +258,13 @@ where
257258
}
258259

259260
#[stable(feature = "drain", since = "1.6.0")]
260-
impl<T, A: Allocator, const COOP_PREF: bool> ExactSizeIterator for Drain<'_, T, A, COOP_PREF> where
261-
[(); alloc::co_alloc_metadata_num_slots_with_preference::<A>(COOP_PREF)]:
261+
impl<T, A: Allocator, const CO_ALLOC_PREF: CoAllocPref> ExactSizeIterator for Drain<'_, T, A, CO_ALLOC_PREF> where
262+
[(); alloc::co_alloc_metadata_num_slots_with_preference::<A>(CO_ALLOC_PREF)]:
262263
{
263264
}
264265

265266
#[stable(feature = "fused", since = "1.26.0")]
266-
impl<T, A: Allocator, const COOP_PREF: bool> FusedIterator for Drain<'_, T, A, COOP_PREF> where
267-
[(); alloc::co_alloc_metadata_num_slots_with_preference::<A>(COOP_PREF)]:
267+
impl<T, A: Allocator, const CO_ALLOC_PREF: CoAllocPref> FusedIterator for Drain<'_, T, A, CO_ALLOC_PREF> where
268+
[(); alloc::co_alloc_metadata_num_slots_with_preference::<A>(CO_ALLOC_PREF)]:
268269
{
269270
}

library/alloc/src/collections/vec_deque/into_iter.rs

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use core::iter::{FusedIterator, TrustedLen};
22
use core::{alloc, fmt};
3+
use crate::co_alloc::CoAllocPref;
34

45
use crate::alloc::{Allocator, Global};
56

@@ -17,40 +18,40 @@ use super::VecDeque;
1718
pub struct IntoIter<
1819
T,
1920
#[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global,
20-
const COOP_PREF: bool = true,
21+
const CO_ALLOC_PREF: CoAllocPref = true,
2122
> where
22-
[(); alloc::co_alloc_metadata_num_slots_with_preference::<A>(COOP_PREF)]:,
23+
[(); alloc::co_alloc_metadata_num_slots_with_preference::<A>(CO_ALLOC_PREF)]:,
2324
{
24-
inner: VecDeque<T, A, COOP_PREF>,
25+
inner: VecDeque<T, A, CO_ALLOC_PREF>,
2526
}
2627

27-
impl<T, A: Allocator, const COOP_PREF: bool> IntoIter<T, A, COOP_PREF>
28+
impl<T, A: Allocator, const CO_ALLOC_PREF: CoAllocPref> IntoIter<T, A, CO_ALLOC_PREF>
2829
where
29-
[(); core::alloc::co_alloc_metadata_num_slots_with_preference::<A>(COOP_PREF)]:,
30+
[(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:,
3031
{
31-
pub(super) fn new(inner: VecDeque<T, A, COOP_PREF>) -> Self {
32+
pub(super) fn new(inner: VecDeque<T, A, CO_ALLOC_PREF>) -> Self {
3233
IntoIter { inner }
3334
}
3435

35-
pub(super) fn into_vecdeque(self) -> VecDeque<T, A, COOP_PREF> {
36+
pub(super) fn into_vecdeque(self) -> VecDeque<T, A, CO_ALLOC_PREF> {
3637
self.inner
3738
}
3839
}
3940

4041
#[stable(feature = "collection_debug", since = "1.17.0")]
41-
impl<T: fmt::Debug, A: Allocator, const COOP_PREF: bool> fmt::Debug for IntoIter<T, A, COOP_PREF>
42+
impl<T: fmt::Debug, A: Allocator, const CO_ALLOC_PREF: CoAllocPref> fmt::Debug for IntoIter<T, A, CO_ALLOC_PREF>
4243
where
43-
[(); core::alloc::co_alloc_metadata_num_slots_with_preference::<A>(COOP_PREF)]:,
44+
[(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:,
4445
{
4546
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
4647
f.debug_tuple("IntoIter").field(&self.inner).finish()
4748
}
4849
}
4950

5051
#[stable(feature = "rust1", since = "1.0.0")]
51-
impl<T, A: Allocator, const COOP_PREF: bool> Iterator for IntoIter<T, A, COOP_PREF>
52+
impl<T, A: Allocator, const CO_ALLOC_PREF: CoAllocPref> Iterator for IntoIter<T, A, CO_ALLOC_PREF>
5253
where
53-
[(); core::alloc::co_alloc_metadata_num_slots_with_preference::<A>(COOP_PREF)]:,
54+
[(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:,
5455
{
5556
type Item = T;
5657

@@ -67,9 +68,9 @@ where
6768
}
6869

6970
#[stable(feature = "rust1", since = "1.0.0")]
70-
impl<T, A: Allocator, const COOP_PREF: bool> DoubleEndedIterator for IntoIter<T, A, COOP_PREF>
71+
impl<T, A: Allocator, const CO_ALLOC_PREF: CoAllocPref> DoubleEndedIterator for IntoIter<T, A, CO_ALLOC_PREF>
7172
where
72-
[(); core::alloc::co_alloc_metadata_num_slots_with_preference::<A>(COOP_PREF)]:,
73+
[(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:,
7374
{
7475
#[inline]
7576
fn next_back(&mut self) -> Option<T> {
@@ -78,23 +79,23 @@ where
7879
}
7980

8081
#[stable(feature = "rust1", since = "1.0.0")]
81-
impl<T, A: Allocator, const COOP_PREF: bool> ExactSizeIterator for IntoIter<T, A, COOP_PREF>
82+
impl<T, A: Allocator, const CO_ALLOC_PREF: CoAllocPref> ExactSizeIterator for IntoIter<T, A, CO_ALLOC_PREF>
8283
where
83-
[(); core::alloc::co_alloc_metadata_num_slots_with_preference::<A>(COOP_PREF)]:,
84+
[(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:,
8485
{
8586
fn is_empty(&self) -> bool {
8687
self.inner.is_empty()
8788
}
8889
}
8990

9091
#[stable(feature = "fused", since = "1.26.0")]
91-
impl<T, A: Allocator, const COOP_PREF: bool> FusedIterator for IntoIter<T, A, COOP_PREF> where
92-
[(); core::alloc::co_alloc_metadata_num_slots_with_preference::<A>(COOP_PREF)]:
92+
impl<T, A: Allocator, const CO_ALLOC_PREF: CoAllocPref> FusedIterator for IntoIter<T, A, CO_ALLOC_PREF> where
93+
[(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:
9394
{
9495
}
9596

9697
#[unstable(feature = "trusted_len", issue = "37572")]
97-
unsafe impl<T, A: Allocator, const COOP_PREF: bool> TrustedLen for IntoIter<T, A, COOP_PREF> where
98-
[(); core::alloc::co_alloc_metadata_num_slots_with_preference::<A>(COOP_PREF)]:
98+
unsafe impl<T, A: Allocator, const CO_ALLOC_PREF: CoAllocPref> TrustedLen for IntoIter<T, A, CO_ALLOC_PREF> where
99+
[(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:
99100
{
100101
}

library/alloc/src/collections/vec_deque/macros.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
macro_rules! __impl_slice_eq1 {
22
([$($vars:tt)*] $lhs:ty, $rhs:ty, $($constraints:tt)*) => {
33
#[stable(feature = "vec_deque_partial_eq_slice", since = "1.17.0")]
4-
impl<T, U, A: Allocator, const COOP_PREF: bool, $($vars)*> PartialEq<$rhs> for $lhs
4+
impl<T, U, A: Allocator, const CO_ALLOC_PREF: CoAllocPref, $($vars)*> PartialEq<$rhs> for $lhs
55
where
66
T: PartialEq<U>,
7-
[(); core::alloc::co_alloc_metadata_num_slots_with_preference::<A>(COOP_PREF)]:,
7+
[(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:,
88
$($constraints)*
99
{
1010
fn eq(&self, other: &$rhs) -> bool {

0 commit comments

Comments
 (0)