Skip to content

Commit af76916

Browse files
CoAlloc: Renamed IS_CO_ALLOCATOR -> CO_ALLOCATES_WITH_META. Added Allocator::CoAllocMeta, but not using it yet. Tidy
1 parent 327596a commit af76916

File tree

16 files changed

+82
-159
lines changed

16 files changed

+82
-159
lines changed

library/alloc/src/boxed.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1679,8 +1679,7 @@ impl<T, const N: usize> TryFrom<Box<[T]>> for Box<[T; N]> {
16791679

16801680
#[cfg(not(no_global_oom_handling))]
16811681
#[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>>
1683-
for Box<[T; N]>
1682+
impl<T, const N: usize, const COOP_PREF: bool> TryFrom<Vec<T, Global, COOP_PREF>> for Box<[T; N]>
16841683
where
16851684
[(); core::alloc::co_alloc_metadata_num_slots_with_preference::<Global>(COOP_PREF)]:,
16861685
{

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

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,7 @@ where
9595
}
9696

9797
#[stable(feature = "collection_debug", since = "1.17.0")]
98-
impl<T: fmt::Debug, A: Allocator, const COOP_PREF: bool> fmt::Debug
99-
for Drain<'_, T, A, COOP_PREF>
98+
impl<T: fmt::Debug, A: Allocator, const COOP_PREF: bool> fmt::Debug for Drain<'_, T, A, COOP_PREF>
10099
where
101100
[(); alloc::co_alloc_metadata_num_slots_with_preference::<A>(COOP_PREF)]:,
102101
{
@@ -111,17 +110,13 @@ where
111110
}
112111

113112
#[stable(feature = "drain", since = "1.6.0")]
114-
unsafe impl<T: Sync, A: Allocator + Sync, const COOP_PREF: bool> Sync
115-
for Drain<'_, T, A, COOP_PREF>
116-
where
117-
[(); alloc::co_alloc_metadata_num_slots_with_preference::<A>(COOP_PREF)]:,
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)]:
118115
{
119116
}
120117
#[stable(feature = "drain", since = "1.6.0")]
121-
unsafe impl<T: Send, A: Allocator + Send, const COOP_PREF: bool> Send
122-
for Drain<'_, T, A, COOP_PREF>
123-
where
124-
[(); alloc::co_alloc_metadata_num_slots_with_preference::<A>(COOP_PREF)]:,
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)]:
125120
{
126121
}
127122

@@ -137,8 +132,7 @@ where
137132
where
138133
[(); alloc::co_alloc_metadata_num_slots_with_preference::<A>(COOP_PREF)]:;
139134

140-
impl<'r, 'a, T, A: Allocator, const COOP_PREF: bool> Drop
141-
for DropGuard<'r, 'a, T, A, COOP_PREF>
135+
impl<'r, 'a, T, A: Allocator, const COOP_PREF: bool> Drop for DropGuard<'r, 'a, T, A, COOP_PREF>
142136
where
143137
[(); alloc::co_alloc_metadata_num_slots_with_preference::<A>(COOP_PREF)]:,
144138
{
@@ -247,8 +241,7 @@ where
247241
}
248242

249243
#[stable(feature = "drain", since = "1.6.0")]
250-
impl<T, A: Allocator, const COOP_PREF: bool> DoubleEndedIterator
251-
for Drain<'_, T, A, COOP_PREF>
244+
impl<T, A: Allocator, const COOP_PREF: bool> DoubleEndedIterator for Drain<'_, T, A, COOP_PREF>
252245
where
253246
[(); alloc::co_alloc_metadata_num_slots_with_preference::<A>(COOP_PREF)]:,
254247
{
@@ -264,10 +257,8 @@ where
264257
}
265258

266259
#[stable(feature = "drain", since = "1.6.0")]
267-
impl<T, A: Allocator, const COOP_PREF: bool> ExactSizeIterator
268-
for Drain<'_, T, A, COOP_PREF>
269-
where
270-
[(); alloc::co_alloc_metadata_num_slots_with_preference::<A>(COOP_PREF)]:,
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)]:
271262
{
272263
}
273264

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

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ where
3838
}
3939

4040
#[stable(feature = "collection_debug", since = "1.17.0")]
41-
impl<T: fmt::Debug, A: Allocator, const COOP_PREF: bool> fmt::Debug
42-
for IntoIter<T, A, COOP_PREF>
41+
impl<T: fmt::Debug, A: Allocator, const COOP_PREF: bool> fmt::Debug for IntoIter<T, A, COOP_PREF>
4342
where
4443
[(); core::alloc::co_alloc_metadata_num_slots_with_preference::<A>(COOP_PREF)]:,
4544
{
@@ -188,8 +187,7 @@ where
188187
}
189188

190189
#[stable(feature = "rust1", since = "1.0.0")]
191-
impl<T, A: Allocator, const COOP_PREF: bool> DoubleEndedIterator
192-
for IntoIter<T, A, COOP_PREF>
190+
impl<T, A: Allocator, const COOP_PREF: bool> DoubleEndedIterator for IntoIter<T, A, COOP_PREF>
193191
where
194192
[(); core::alloc::co_alloc_metadata_num_slots_with_preference::<A>(COOP_PREF)]:,
195193
{
@@ -262,8 +260,7 @@ where
262260
}
263261

264262
#[stable(feature = "rust1", since = "1.0.0")]
265-
impl<T, A: Allocator, const COOP_PREF: bool> ExactSizeIterator
266-
for IntoIter<T, A, COOP_PREF>
263+
impl<T, A: Allocator, const COOP_PREF: bool> ExactSizeIterator for IntoIter<T, A, COOP_PREF>
267264
where
268265
[(); core::alloc::co_alloc_metadata_num_slots_with_preference::<A>(COOP_PREF)]:,
269266
{
@@ -280,9 +277,7 @@ impl<T, A: Allocator, const COOP_PREF: bool> FusedIterator for IntoIter<T, A, CO
280277
}
281278

282279
#[unstable(feature = "trusted_len", issue = "37572")]
283-
unsafe impl<T, A: Allocator, const COOP_PREF: bool> TrustedLen
284-
for IntoIter<T, A, COOP_PREF>
285-
where
286-
[(); core::alloc::co_alloc_metadata_num_slots_with_preference::<A>(COOP_PREF)]:,
280+
unsafe impl<T, A: Allocator, const COOP_PREF: bool> TrustedLen for IntoIter<T, A, COOP_PREF> where
281+
[(); core::alloc::co_alloc_metadata_num_slots_with_preference::<A>(COOP_PREF)]:
287282
{
288283
}

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

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,7 @@ pub struct VecDeque<
112112
}
113113

114114
#[stable(feature = "rust1", since = "1.0.0")]
115-
impl<T: Clone, A: Allocator + Clone, const COOP_PREF: bool> Clone
116-
for VecDeque<T, A, COOP_PREF>
115+
impl<T: Clone, A: Allocator + Clone, const COOP_PREF: bool> Clone for VecDeque<T, A, COOP_PREF>
117116
where
118117
[(); alloc::co_alloc_metadata_num_slots_with_preference::<A>(COOP_PREF)]:,
119118
{
@@ -130,8 +129,7 @@ where
130129
}
131130

132131
#[stable(feature = "rust1", since = "1.0.0")]
133-
unsafe impl<#[may_dangle] T, A: Allocator, const COOP_PREF: bool> Drop
134-
for VecDeque<T, A, COOP_PREF>
132+
unsafe impl<#[may_dangle] T, A: Allocator, const COOP_PREF: bool> Drop for VecDeque<T, A, COOP_PREF>
135133
where
136134
[(); alloc::co_alloc_metadata_num_slots_with_preference::<A>(COOP_PREF)]:,
137135
{
@@ -2680,8 +2678,7 @@ fn wrap_index(logical_index: usize, capacity: usize) -> usize {
26802678
}
26812679

26822680
#[stable(feature = "rust1", since = "1.0.0")]
2683-
impl<T: PartialEq, A: Allocator, const COOP_PREF: bool> PartialEq
2684-
for VecDeque<T, A, COOP_PREF>
2681+
impl<T: PartialEq, A: Allocator, const COOP_PREF: bool> PartialEq for VecDeque<T, A, COOP_PREF>
26852682
where
26862683
[(); alloc::co_alloc_metadata_num_slots_with_preference::<A>(COOP_PREF)]:,
26872684
{
@@ -2736,8 +2733,7 @@ __impl_slice_eq1! { [const N: usize] VecDeque<T, A, COOP_PREF>, &[U; N], }
27362733
__impl_slice_eq1! { [const N: usize] VecDeque<T, A, COOP_PREF>, &mut [U; N], }
27372734

27382735
#[stable(feature = "rust1", since = "1.0.0")]
2739-
impl<T: PartialOrd, A: Allocator, const COOP_PREF: bool> PartialOrd
2740-
for VecDeque<T, A, COOP_PREF>
2736+
impl<T: PartialOrd, A: Allocator, const COOP_PREF: bool> PartialOrd for VecDeque<T, A, COOP_PREF>
27412737
where
27422738
[(); alloc::co_alloc_metadata_num_slots_with_preference::<A>(COOP_PREF)]:,
27432739
{
@@ -2824,8 +2820,7 @@ where
28242820
}
28252821

28262822
#[stable(feature = "rust1", since = "1.0.0")]
2827-
impl<'a, T, A: Allocator, const COOP_PREF: bool> IntoIterator
2828-
for &'a VecDeque<T, A, COOP_PREF>
2823+
impl<'a, T, A: Allocator, const COOP_PREF: bool> IntoIterator for &'a VecDeque<T, A, COOP_PREF>
28292824
where
28302825
[(); alloc::co_alloc_metadata_num_slots_with_preference::<A>(COOP_PREF)]:,
28312826
{
@@ -2838,8 +2833,7 @@ where
28382833
}
28392834

28402835
#[stable(feature = "rust1", since = "1.0.0")]
2841-
impl<'a, T, A: Allocator, const COOP_PREF: bool> IntoIterator
2842-
for &'a mut VecDeque<T, A, COOP_PREF>
2836+
impl<'a, T, A: Allocator, const COOP_PREF: bool> IntoIterator for &'a mut VecDeque<T, A, COOP_PREF>
28432837
where
28442838
[(); alloc::co_alloc_metadata_num_slots_with_preference::<A>(COOP_PREF)]:,
28452839
{
@@ -2893,8 +2887,7 @@ where
28932887
}
28942888

28952889
#[stable(feature = "rust1", since = "1.0.0")]
2896-
impl<T: fmt::Debug, A: Allocator, const COOP_PREF: bool> fmt::Debug
2897-
for VecDeque<T, A, COOP_PREF>
2890+
impl<T: fmt::Debug, A: Allocator, const COOP_PREF: bool> fmt::Debug for VecDeque<T, A, COOP_PREF>
28982891
where
28992892
[(); alloc::co_alloc_metadata_num_slots_with_preference::<A>(COOP_PREF)]:,
29002893
{
@@ -2988,8 +2981,7 @@ where
29882981
}
29892982

29902983
#[stable(feature = "std_collections_from_array", since = "1.56.0")]
2991-
impl<T, const N: usize, const COOP_PREF: bool> From<[T; N]>
2992-
for VecDeque<T, Global, COOP_PREF>
2984+
impl<T, const N: usize, const COOP_PREF: bool> From<[T; N]> for VecDeque<T, Global, COOP_PREF>
29932985
where
29942986
[(); core::alloc::co_alloc_metadata_num_slots_with_preference::<Global>(COOP_PREF)]:,
29952987
{

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ pub(super) trait SpecExtend<T, I> {
1313
fn spec_extend(&mut self, iter: I);
1414
}
1515

16-
impl<T, I, A: Allocator, const COOP_PREF: bool> SpecExtend<T, I>
17-
for VecDeque<T, A, COOP_PREF>
16+
impl<T, I, A: Allocator, const COOP_PREF: bool> SpecExtend<T, I> for VecDeque<T, A, COOP_PREF>
1817
where
1918
I: Iterator<Item = T>,
2019
[(); alloc::co_alloc_metadata_num_slots_with_preference::<A>(COOP_PREF)]:,
@@ -59,8 +58,7 @@ where
5958
}
6059
}
6160

62-
impl<T, I, A: Allocator, const COOP_PREF: bool> SpecExtend<T, I>
63-
for VecDeque<T, A, COOP_PREF>
61+
impl<T, I, A: Allocator, const COOP_PREF: bool> SpecExtend<T, I> for VecDeque<T, A, COOP_PREF>
6462
where
6563
I: TrustedLen<Item = T>,
6664
[(); alloc::co_alloc_metadata_num_slots_with_preference::<A>(COOP_PREF)]:,

library/alloc/src/macros.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ macro_rules! DEFAULT_COOP_PREF {
155155
#[macro_export]
156156
macro_rules! meta_num_slots {
157157
($alloc:ty, $coop_pref:expr) => {
158-
if ($alloc::IS_CO_ALLOCATOR) && ($coop_pref) { 1 } else { 0 }
158+
if ($alloc::CO_ALLOCATES_WITH_META) && ($coop_pref) { 1 } else { 0 }
159159
};
160160
}
161161
// -\---> replace with something like:
@@ -164,7 +164,7 @@ macro_rules! meta_num_slots {
164164
pub const fn meta_num_slots<A: Allocator>(
165165
COOP_PREF: bool,
166166
) -> usize {
167-
if A::IS_CO_ALLOCATOR && COOP_PREF { 1 } else { 0 }
167+
if A::CO_ALLOCATES_WITH_META && COOP_PREF { 1 } else { 0 }
168168
}
169169
*/
170170

@@ -181,7 +181,7 @@ pub const fn meta_num_slots<A: Allocator>(
181181
#[macro_export]
182182
macro_rules! meta_num_slots_default {
183183
($alloc:ty) => {
184-
if ($alloc::IS_CO_ALLOCATOR) && (DEFAULT_COOP_PREF!()) { 1 } else { 0 }
184+
if ($alloc::CO_ALLOCATES_WITH_META) && (DEFAULT_COOP_PREF!()) { 1 } else { 0 }
185185
};
186186
}
187187

@@ -191,7 +191,7 @@ macro_rules! meta_num_slots_default {
191191
#[macro_export]
192192
macro_rules! meta_num_slots_global {
193193
($coop_pref:expr) => {
194-
if ::alloc::alloc::Global::IS_CO_ALLOCATOR && ($coop_pref) { 1 } else { 0 }
194+
if ::alloc::alloc::Global::CO_ALLOCATES_WITH_META && ($coop_pref) { 1 } else { 0 }
195195
};
196196
}
197197

@@ -205,6 +205,6 @@ macro_rules! meta_num_slots_global {
205205
#[macro_export]
206206
macro_rules! meta_num_slots_default_global {
207207
() => {
208-
if ::alloc::alloc::Global::IS_CO_ALLOCATOR && (DEFAULT_COOP_PREF!()) { 1 } else { 0 }
208+
if ::alloc::alloc::Global::CO_ALLOCATES_WITH_META && (DEFAULT_COOP_PREF!()) { 1 } else { 0 }
209209
};
210210
}

library/alloc/src/raw_vec.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,8 @@ enum AllocInit {
5151
/// `Box<[T]>`, since `capacity()` won't yield the length.
5252
#[allow(missing_debug_implementations)]
5353
#[allow(unused_braces)]
54-
pub(crate) struct RawVec<
55-
T,
56-
A: Allocator = Global,
57-
const COOP_PREF: bool = { DEFAULT_COOP_PREF!() },
58-
> where
54+
pub(crate) struct RawVec<T, A: Allocator = Global, const COOP_PREF: bool = { DEFAULT_COOP_PREF!() }>
55+
where
5956
[(); alloc::co_alloc_metadata_num_slots_with_preference::<A>(COOP_PREF)]:,
6057
{
6158
ptr: Unique<T>,
@@ -64,8 +61,8 @@ pub(crate) struct RawVec<
6461
// As of v1.67.0, `cmp` for `TypeId` is not `const`, unfortunately:
6562
//pub(crate) meta: [GlobalCoAllocMeta; {if core::any::TypeId::of::<A>()==core::any::TypeId::of::<Global>() {1} else {0}}],
6663
//pub(crate) meta: [GlobalCoAllocMeta; mem::size_of::<A::IsCoAllocator>()],
67-
pub(crate) metas: [GlobalCoAllocMeta;
68-
alloc::co_alloc_metadata_num_slots_with_preference::<A>(COOP_PREF)],
64+
pub(crate) metas:
65+
[GlobalCoAllocMeta; alloc::co_alloc_metadata_num_slots_with_preference::<A>(COOP_PREF)],
6966
}
7067

7168
impl<T, const COOP_PREF: bool> RawVec<T, Global, COOP_PREF>
@@ -517,15 +514,14 @@ where
517514
memory.map_err(|_| AllocError { layout: new_layout, non_exhaustive: () }.into())
518515
}
519516

520-
unsafe impl<#[may_dangle] T, A: Allocator, const COOP_PREF: bool> Drop
521-
for RawVec<T, A, COOP_PREF>
517+
unsafe impl<#[may_dangle] T, A: Allocator, const COOP_PREF: bool> Drop for RawVec<T, A, COOP_PREF>
522518
where
523519
[(); alloc::co_alloc_metadata_num_slots_with_preference::<A>(COOP_PREF)]:,
524520
{
525521
/// Frees the memory owned by the `RawVec` *without* trying to drop its contents.
526522
default fn drop(&mut self) {
527523
if let Some((ptr, layout)) = self.current_memory() {
528-
if A::IS_CO_ALLOCATOR && COOP_PREF {
524+
if A::CO_ALLOCATES_WITH_META && COOP_PREF {
529525
let meta = self.metas[0];
530526
unsafe { self.alloc.co_deallocate(PtrAndMeta { ptr, meta }, layout) }
531527
} else {

library/alloc/src/slice.rs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,7 @@ pub(crate) mod hack {
9797
// We shouldn't add inline attribute to this since this is used in
9898
// `vec!` macro mostly and causes perf regression. See #71204 for
9999
// discussion and perf results.
100-
pub fn into_vec<T, A: Allocator, const COOP_PREF: bool>(
101-
b: Box<[T], A>,
102-
) -> Vec<T, A, COOP_PREF>
100+
pub fn into_vec<T, A: Allocator, const COOP_PREF: bool>(b: Box<[T], A>) -> Vec<T, A, COOP_PREF>
103101
where
104102
[(); core::alloc::co_alloc_metadata_num_slots_with_preference::<A>(COOP_PREF)]:,
105103
{
@@ -467,10 +465,7 @@ impl<T> [T] {
467465
#[rustc_allow_incoherent_impl]
468466
#[inline]
469467
#[unstable(feature = "allocator_api", issue = "32838")]
470-
pub fn to_vec_in<A: Allocator, const COOP_PREF: bool>(
471-
&self,
472-
alloc: A,
473-
) -> Vec<T, A, COOP_PREF>
468+
pub fn to_vec_in<A: Allocator, const COOP_PREF: bool>(&self, alloc: A) -> Vec<T, A, COOP_PREF>
474469
where
475470
T: Clone,
476471
[(); core::alloc::co_alloc_metadata_num_slots_with_preference::<A>(COOP_PREF)]:,
@@ -496,9 +491,7 @@ impl<T> [T] {
496491
#[rustc_allow_incoherent_impl]
497492
#[stable(feature = "rust1", since = "1.0.0")]
498493
#[inline]
499-
pub fn into_vec<A: Allocator, const COOP_PREF: bool>(
500-
self: Box<Self, A>,
501-
) -> Vec<T, A, COOP_PREF>
494+
pub fn into_vec<A: Allocator, const COOP_PREF: bool>(self: Box<Self, A>) -> Vec<T, A, COOP_PREF>
502495
where
503496
[(); core::alloc::co_alloc_metadata_num_slots_with_preference::<A>(COOP_PREF)]:,
504497
{

0 commit comments

Comments
 (0)