Skip to content

Commit 6afb0d6

Browse files
CoAlloc: (Some) Separation of co-alloc-aware traits & methods.
1 parent 16f13bb commit 6afb0d6

File tree

4 files changed

+17
-23
lines changed

4 files changed

+17
-23
lines changed

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

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -160,14 +160,12 @@ where
160160

161161
#[stable(feature = "rust1", since = "1.0.0")]
162162
#[allow(unused_braces)]
163-
impl<T, const CO_ALLOC_PREF: CoAllocPref> Default for VecDeque<T, Global, CO_ALLOC_PREF>
164-
where
165-
[(); {meta_num_slots_global!(CO_ALLOC_PREF)}]:,
163+
impl<T> Default for VecDeque<T>
166164
{
167165
/// Creates an empty deque.
168166
#[inline]
169-
fn default() -> VecDeque<T, Global, CO_ALLOC_PREF> {
170-
VecDeque::<T, Global, CO_ALLOC_PREF>::new()
167+
fn default() -> VecDeque<T> {
168+
VecDeque::<T>::new()
171169
}
172170
}
173171

@@ -554,12 +552,7 @@ where
554552
}
555553
}
556554

557-
#[allow(unused_braces)]
558-
impl<T, A: Allocator, const CO_ALLOC_PREF: CoAllocPref> VecDeque<T, A, CO_ALLOC_PREF>
559-
where
560-
[(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:,
561-
[(); {crate::meta_num_slots_global!(CO_ALLOC_PREF)}]:,
562-
{
555+
impl <T> VecDeque<T> {
563556
/// Creates an empty deque.
564557
///
565558
/// # Examples
@@ -573,14 +566,13 @@ where
573566
#[stable(feature = "rust1", since = "1.0.0")]
574567
#[rustc_const_stable(feature = "const_vec_deque_new", since = "1.68.0")]
575568
#[must_use]
576-
pub const fn new() -> VecDeque<T, Global, CO_ALLOC_PREF>
577-
where
578-
[(); {crate::meta_num_slots_global!(CO_ALLOC_PREF)}]:,
569+
#[allow(unused_braces)]
570+
pub const fn new() -> VecDeque<T, Global, {CO_ALLOC_PREF_DEFAULT!()}>
579571
{
580572
// FIXME: This should just be `VecDeque::new_in(Global)` once that hits stable.
581573
VecDeque { head: 0, len: 0, buf: RawVec::NEW }
582574
}
583-
575+
584576
/// Creates an empty deque with space for at least `capacity` elements.
585577
///
586578
/// # Examples
@@ -593,8 +585,9 @@ where
593585
#[inline]
594586
#[stable(feature = "rust1", since = "1.0.0")]
595587
#[must_use]
596-
pub fn with_capacity(capacity: usize) -> VecDeque<T, Global, CO_ALLOC_PREF> {
597-
VecDeque::<T, Global, CO_ALLOC_PREF>::with_capacity_in(capacity, Global)
588+
#[allow(unused_braces)]
589+
pub fn with_capacity(capacity: usize) -> VecDeque<T, Global, {CO_ALLOC_PREF_DEFAULT!()}> {
590+
VecDeque::<T, Global, {CO_ALLOC_PREF_DEFAULT!()}>::with_capacity_in(capacity, Global)
598591
}
599592
}
600593

@@ -3006,9 +2999,7 @@ where
30062999

30073000
#[stable(feature = "std_collections_from_array", since = "1.56.0")]
30083001
#[allow(unused_braces)]
3009-
impl<T, const N: usize, const CO_ALLOC_PREF: CoAllocPref> From<[T; N]> for VecDeque<T, Global, CO_ALLOC_PREF>
3010-
where
3011-
[(); {meta_num_slots_global!(CO_ALLOC_PREF)}]:,
3002+
impl<T, const N: usize> From<[T; N]> for VecDeque<T>
30123003
{
30133004
/// Converts a `[T; N]` into a `VecDeque<T>`.
30143005
///
@@ -3020,7 +3011,7 @@ where
30203011
/// assert_eq!(deq1, deq2);
30213012
/// ```
30223013
fn from(arr: [T; N]) -> Self {
3023-
let mut deq = VecDeque::<T, Global, CO_ALLOC_PREF>::with_capacity(N);
3014+
let mut deq = VecDeque::<T>::with_capacity(N);
30243015
let arr = ManuallyDrop::new(arr);
30253016
if !<T>::IS_ZST {
30263017
// SAFETY: VecDeque::with_capacity ensures that there is enough capacity.

library/std/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ pub use alloc_crate::boxed;
421421
pub use alloc_crate::co_alloc;
422422
// @FIXME ugly - someone move this to a better place, please
423423
#[unstable(feature = "global_co_alloc", issue = "none")]
424-
pub use alloc_crate::{CO_ALLOC_PREF_DEFAULT};
424+
pub use alloc_crate::{CO_ALLOC_PREF_DEFAULT, SHORT_TERM_VEC_CO_ALLOC_PREF};
425425
#[stable(feature = "rust1", since = "1.0.0")]
426426
pub use alloc_crate::fmt;
427427
#[stable(feature = "rust1", since = "1.0.0")]

library/test/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
#![unstable(feature = "test", issue = "50297")]
1818
#![doc(test(attr(deny(warnings))))]
1919
#![feature(allocator_api)]
20+
#![feature(global_co_alloc)]
21+
#![feature(global_co_alloc_meta)]
2022
#![feature(internal_output_capture)]
2123
#![feature(is_terminal)]
2224
#![feature(staged_api)]
@@ -348,6 +350,7 @@ where
348350
};
349351

350352
let mut running_tests: TestMap = HashMap::default();
353+
// @FIXME See if we can remove `Global` generic param:
351354
let mut timeout_queue: VecDeque<TimeoutEntry, Global> = VecDeque::new();
352355

353356
fn get_timed_out_tests(

library/test/src/stats.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ impl Stats for [f64] {
232232
}
233233

234234
fn percentile(&self, pct: f64) -> f64 {
235-
let mut tmp = self.to_vec();
235+
let mut tmp = self.to_vec::<{std::SHORT_TERM_VEC_CO_ALLOC_PREF!()}>();
236236
local_sort(&mut tmp);
237237
percentile_of_sorted(&tmp, pct)
238238
}

0 commit comments

Comments
 (0)