From 619198d4c40b03068e74268a545e8f2c172a5d42 Mon Sep 17 00:00:00 2001 From: Peter Kehl Date: Sat, 21 Jan 2023 15:37:26 -0800 Subject: [PATCH 001/118] START CoAlloc API --- Cargo.lock | 123 +++++++++++-------------------- library/core/src/alloc/global.rs | 56 +++++++++++++- library/core/src/alloc/mod.rs | 10 +++ 3 files changed, 109 insertions(+), 80 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d02cab38ae8f3..3febb21410c79 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -179,7 +179,7 @@ dependencies = [ "quote", "serde", "syn", - "toml 0.5.7", + "toml", ] [[package]] @@ -291,7 +291,7 @@ dependencies = [ "serde_json", "sha2", "tar", - "toml 0.5.7", + "toml", ] [[package]] @@ -307,7 +307,7 @@ dependencies = [ "indexmap", "serde", "serde_json", - "toml 0.5.7", + "toml", ] [[package]] @@ -408,13 +408,12 @@ dependencies = [ "tempfile", "termcolor", "time 0.3.17", - "toml 0.7.2", "toml_edit", "unicode-width", "unicode-xid", "url", "walkdir", - "windows-sys 0.45.0", + "winapi", ] [[package]] @@ -443,7 +442,7 @@ name = "cargo-credential-wincred" version = "0.2.0" dependencies = [ "cargo-credential", - "windows-sys 0.45.0", + "winapi", ] [[package]] @@ -501,9 +500,9 @@ dependencies = [ "tar", "termcolor", "time 0.3.17", - "toml 0.7.2", + "toml_edit", "url", - "windows-sys 0.45.0", + "winapi", ] [[package]] @@ -523,7 +522,7 @@ dependencies = [ "shell-escape", "tempfile", "walkdir", - "windows-sys 0.45.0", + "winapi", ] [[package]] @@ -756,7 +755,7 @@ dependencies = [ "termize", "tester", "tokio", - "toml 0.5.7", + "toml", "walkdir", ] @@ -790,7 +789,7 @@ dependencies = [ "serde", "serde_json", "tempfile", - "toml 0.5.7", + "toml", "unicode-normalization", "unicode-script", "url", @@ -854,6 +853,16 @@ dependencies = [ "winapi", ] +[[package]] +name = "combine" +version = "4.6.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "35ed6e9d84f0b51a7f52daf1c7d71dd136fd7a3f41a8462b8cdb8c78d920fad4" +dependencies = [ + "bytes", + "memchr", +] + [[package]] name = "commoncrypto" version = "0.2.0" @@ -2215,7 +2224,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "46112a93252b123d31a119a8d1a1ac19deac4fac6e0e8b0df58f0d4e5870e63c" dependencies = [ "libc", - "windows-sys 0.42.0", + "windows-sys", ] [[package]] @@ -2227,7 +2236,7 @@ dependencies = [ "hermit-abi 0.2.6", "io-lifetimes", "rustix", - "windows-sys 0.42.0", + "windows-sys", ] [[package]] @@ -2312,6 +2321,15 @@ dependencies = [ "serde_json", ] +[[package]] +name = "kstring" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec3066350882a1cd6d950d055997f379ac37fd39f81cd4d8ed186032eb3c5747" +dependencies = [ + "static_assertions", +] + [[package]] name = "lazy_static" version = "1.4.0" @@ -2561,7 +2579,7 @@ dependencies = [ "serde_json", "shlex", "tempfile", - "toml 0.5.7", + "toml", "topological-sort", ] @@ -2659,7 +2677,7 @@ version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "52ffbca2f655e33c08be35d87278e5b18b89550a37dbd598c20db92f6a471123" dependencies = [ - "windows-sys 0.42.0", + "windows-sys", ] [[package]] @@ -2707,15 +2725,6 @@ dependencies = [ "version_check", ] -[[package]] -name = "nom8" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae01545c9c7fc4486ab7debaf2aad7003ac19431791868fb2e8066df97fad2f8" -dependencies = [ - "memchr", -] - [[package]] name = "normalize-line-endings" version = "0.3.0" @@ -2985,7 +2994,7 @@ dependencies = [ "libc", "redox_syscall", "smallvec", - "windows-sys 0.42.0", + "windows-sys", ] [[package]] @@ -4897,7 +4906,7 @@ dependencies = [ "serde_json", "term", "thiserror", - "toml 0.5.7", + "toml", "unicode-segmentation", "unicode-width", "unicode_categories", @@ -4914,7 +4923,7 @@ dependencies = [ "io-lifetimes", "libc", "linux-raw-sys", - "windows-sys 0.42.0", + "windows-sys", ] [[package]] @@ -5063,15 +5072,6 @@ dependencies = [ "serde", ] -[[package]] -name = "serde_spanned" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0efd8caf556a6cebd3b285caf480045fcc1ac04f6bd786b09a6f11af30c4fcf4" -dependencies = [ - "serde", -] - [[package]] name = "sha1" version = "0.10.5" @@ -5453,7 +5453,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cb20089a8ba2b69debd491f8d2d023761cbf196e999218c591fa1e7e15a21907" dependencies = [ "rustix", - "windows-sys 0.42.0", + "windows-sys", ] [[package]] @@ -5648,37 +5648,26 @@ dependencies = [ "serde", ] -[[package]] -name = "toml" -version = "0.7.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7afcae9e3f0fe2c370fd4657108972cbb2fa9db1b9f84849cefd80741b01cb6" -dependencies = [ - "serde", - "serde_spanned", - "toml_datetime", - "toml_edit", -] - [[package]] name = "toml_datetime" -version = "0.6.1" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3ab8ed2edee10b50132aed5f331333428b011c99402b5a534154ed15746f9622" +checksum = "4553f467ac8e3d374bc9a177a26801e5d0f9b211aa1673fb137a403afd1c9cf5" dependencies = [ "serde", ] [[package]] name = "toml_edit" -version = "0.19.3" +version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e6a7712b49e1775fb9a7b998de6635b299237f48b404dde71704f2e0e7f37e5" +checksum = "b1541ba70885967e662f69d31ab3aeca7b1aaecfcd58679590b893e9239c3646" dependencies = [ + "combine", "indexmap", - "nom8", + "itertools", + "kstring", "serde", - "serde_spanned", "toml_datetime", ] @@ -6228,30 +6217,6 @@ dependencies = [ "windows_x86_64_msvc", ] -[[package]] -name = "windows-sys" -version = "0.45.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0" -dependencies = [ - "windows-targets", -] - -[[package]] -name = "windows-targets" -version = "0.42.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e2522491fbfcd58cc84d47aeb2958948c4b8982e9a2d8a2a35bbaed431390e7" -dependencies = [ - "windows_aarch64_gnullvm", - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_gnullvm", - "windows_x86_64_msvc", -] - [[package]] name = "windows_aarch64_gnullvm" version = "0.42.1" diff --git a/library/core/src/alloc/global.rs b/library/core/src/alloc/global.rs index 18da70451f299..584343e7faf76 100644 --- a/library/core/src/alloc/global.rs +++ b/library/core/src/alloc/global.rs @@ -1,6 +1,15 @@ use crate::alloc::Layout; use crate::cmp; use crate::ptr; +use crate::alloc::GlobalCoAllocMeta; + +#[unstable(feature = "global_co_alloc_meta", issue = "none")] +#[allow(missing_debug_implementations)] +/// Used for parameters and results (to/from `GlobalCoAllocator`'s functions, where applicable). +pub struct PtrAndMeta { + pub ptr: *mut u8, + pub meta: GlobalCoAllocMeta, +} /// A memory allocator that can be registered as the standard library’s default /// through the `#[global_allocator]` attribute. @@ -156,6 +165,9 @@ pub unsafe trait GlobalAlloc { #[stable(feature = "global_alloc", since = "1.28.0")] unsafe fn alloc(&self, layout: Layout) -> *mut u8; + #[unstable(feature = "global_co_alloc", issue = "none")] + unsafe fn co_alloc(&self, _layout: Layout, mut _result: &mut PtrAndMeta) {panic!("TODO")} + /// Deallocate the block of memory at the given `ptr` pointer with the given `layout`. /// /// # Safety @@ -171,6 +183,9 @@ pub unsafe trait GlobalAlloc { #[stable(feature = "global_alloc", since = "1.28.0")] unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout); + #[unstable(feature = "global_co_alloc", issue = "none")] + unsafe fn co_dealloc(&self, _ptr_and_meta: PtrAndMeta, _layout: Layout) {panic!("TODO")} + /// Behaves like `alloc`, but also ensures that the contents /// are set to zero before being returned. /// @@ -198,11 +213,23 @@ pub unsafe trait GlobalAlloc { if !ptr.is_null() { // SAFETY: as allocation succeeded, the region from `ptr` // of size `size` is guaranteed to be valid for writes. - unsafe { ptr::write_bytes(ptr, 0, size) }; + unsafe { ptr::write_bytes(ptr, 0u8, size) }; } ptr } + #[unstable(feature = "global_co_alloc", issue = "none")] + unsafe fn co_alloc_zeroed(&self, layout: Layout, mut result: &mut PtrAndMeta) { + let size = layout.size(); + // SAFETY: the safety contract for `alloc` must be upheld by the caller. + unsafe { self.co_alloc(layout, &mut result) }; + if !result.ptr.is_null() { + // SAFETY: as allocation succeeded, the region from `ptr_and_meta.ptr` of size `size` is + // guaranteed to be valid for writes. + unsafe { ptr::write_bytes(result.ptr, 0u8, size) }; + } + } + /// Shrink or grow a block of memory to the given `new_size` in bytes. /// The block is described by the given `ptr` pointer and `layout`. /// @@ -275,4 +302,31 @@ pub unsafe trait GlobalAlloc { } new_ptr } + + #[unstable(feature = "global_co_alloc", issue = "none")] + unsafe fn co_realloc( + &self, + ptr_and_meta: PtrAndMeta, + layout: Layout, + new_size: usize, + mut result: &mut PtrAndMeta + ) { + // SAFETY: the caller must ensure that the `new_size` does not overflow. + // `layout.align()` comes from a `Layout` and is thus guaranteed to be valid. + let new_layout = unsafe { Layout::from_size_align_unchecked(new_size, layout.align()) }; + // SAFETY: the caller must ensure that `new_layout` is greater than zero. + unsafe { self.co_alloc(new_layout, &mut result) }; + if !result.ptr.is_null() { + // SAFETY: the previously allocated block cannot overlap the newly allocated block. + // The safety contract for `dealloc` must be upheld by the caller. + unsafe { + ptr::copy_nonoverlapping( + ptr_and_meta.ptr, + result.ptr, + cmp::min(layout.size(), new_size), + ); + self.co_dealloc(ptr_and_meta, layout); + } + } + } } diff --git a/library/core/src/alloc/mod.rs b/library/core/src/alloc/mod.rs index a6082455fac8d..6e7b54ffb8612 100644 --- a/library/core/src/alloc/mod.rs +++ b/library/core/src/alloc/mod.rs @@ -25,6 +25,16 @@ use crate::error::Error; use crate::fmt; use crate::ptr::{self, NonNull}; +// @TODO Make this target-specific +#[unstable(feature = "global_co_alloc_meta", issue = "none")] +#[allow(missing_debug_implementations)] +pub struct GlobalCoAllocMeta { + //pub one: usize, + /*pub two: usize, + pub three: usize, + pub four: usize,*/ +} + /// The `AllocError` error indicates an allocation failure /// that may be due to resource exhaustion or to /// something wrong when combining the given input arguments with this From 0b47315f9d925e5b336b6cc1cd367a7127dabc1c Mon Sep 17 00:00:00 2001 From: Peter Kehl Date: Sat, 21 Jan 2023 15:39:15 -0800 Subject: [PATCH 002/118] CoAlloc: RawVec + compiler 'tests' --- compiler/rustc_ast/src/ast.rs | 24 +++++++++---------- compiler/rustc_ast/src/lib.rs | 1 + compiler/rustc_middle/src/lib.rs | 1 + compiler/rustc_middle/src/mir/mod.rs | 3 ++- compiler/rustc_middle/src/mir/syntax.rs | 4 +++- compiler/rustc_parse/src/lib.rs | 1 + .../rustc_parse/src/parser/attr_wrapper.rs | 4 +++- compiler/rustc_parse/src/parser/mod.rs | 3 ++- compiler/rustc_trait_selection/src/lib.rs | 1 + .../src/traits/fulfill.rs | 5 +++- library/alloc/src/lib.rs | 2 ++ library/alloc/src/raw_vec.rs | 19 ++++++++++++--- src/librustdoc/clean/types.rs | 10 ++++---- src/librustdoc/html/render/context.rs | 4 +++- src/librustdoc/lib.rs | 1 + 15 files changed, 58 insertions(+), 25 deletions(-) diff --git a/compiler/rustc_ast/src/ast.rs b/compiler/rustc_ast/src/ast.rs index f2258fecfeafc..aa3bec7297785 100644 --- a/compiler/rustc_ast/src/ast.rs +++ b/compiler/rustc_ast/src/ast.rs @@ -26,6 +26,7 @@ pub use UnsafeSource::*; use crate::ptr::P; use crate::token::{self, CommentKind, Delimiter}; use crate::tokenstream::{DelimSpan, LazyAttrTokenStream, TokenStream}; +use core::alloc::GlobalCoAllocMeta; use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; use rustc_data_structures::stack::ensure_sufficient_stack; use rustc_data_structures::sync::Lrc; @@ -37,7 +38,6 @@ use rustc_span::{Span, DUMMY_SP}; use std::fmt; use std::mem; use thin_vec::{thin_vec, ThinVec}; - /// A "Label" is an identifier of some point in sources, /// e.g. in the following code: /// @@ -3112,26 +3112,26 @@ mod size_asserts { static_assert_size!(AssocItem, 104); static_assert_size!(AssocItemKind, 32); static_assert_size!(Attribute, 32); - static_assert_size!(Block, 48); - static_assert_size!(Expr, 72); - static_assert_size!(ExprKind, 40); - static_assert_size!(Fn, 184); + static_assert_size!(Block, 48 + mem::size_of::()); + static_assert_size!(Expr, 72 + mem::size_of::()); + static_assert_size!(ExprKind, 40 + mem::size_of::()); + static_assert_size!(Fn, 184 + 2 * mem::size_of::()); static_assert_size!(ForeignItem, 96); static_assert_size!(ForeignItemKind, 24); static_assert_size!(GenericArg, 24); - static_assert_size!(GenericBound, 72); - static_assert_size!(Generics, 72); - static_assert_size!(Impl, 184); - static_assert_size!(Item, 184); - static_assert_size!(ItemKind, 112); + static_assert_size!(GenericBound, 72 + mem::size_of::()); + static_assert_size!(Generics, 72 + 2 * mem::size_of::()); + static_assert_size!(Impl, 184 + 3 * mem::size_of::()); + static_assert_size!(Item, 184 + 3 * mem::size_of::()); + static_assert_size!(ItemKind, 112 + 3 * mem::size_of::()); static_assert_size!(LitKind, 24); static_assert_size!(Local, 72); static_assert_size!(MetaItemLit, 40); static_assert_size!(Param, 40); - static_assert_size!(Pat, 88); + static_assert_size!(Pat, 88 + mem::size_of::()); static_assert_size!(Path, 24); static_assert_size!(PathSegment, 24); - static_assert_size!(PatKind, 64); + static_assert_size!(PatKind, 64 + mem::size_of::()); static_assert_size!(Stmt, 32); static_assert_size!(StmtKind, 16); static_assert_size!(Ty, 64); diff --git a/compiler/rustc_ast/src/lib.rs b/compiler/rustc_ast/src/lib.rs index 23c32fa96ca44..225ad76802188 100644 --- a/compiler/rustc_ast/src/lib.rs +++ b/compiler/rustc_ast/src/lib.rs @@ -12,6 +12,7 @@ #![feature(box_patterns)] #![feature(const_default_impls)] #![feature(const_trait_impl)] +#![feature(global_co_alloc_meta)] #![feature(if_let_guard)] #![feature(let_chains)] #![feature(min_specialization)] diff --git a/compiler/rustc_middle/src/lib.rs b/compiler/rustc_middle/src/lib.rs index e6cd38c0f1584..14c059d9db9a6 100644 --- a/compiler/rustc_middle/src/lib.rs +++ b/compiler/rustc_middle/src/lib.rs @@ -32,6 +32,7 @@ #![feature(exhaustive_patterns)] #![feature(generators)] #![feature(get_mut_unchecked)] +#![feature(global_co_alloc_meta)] #![feature(if_let_guard)] #![feature(iter_from_generator)] #![feature(local_key_cell_methods)] diff --git a/compiler/rustc_middle/src/mir/mod.rs b/compiler/rustc_middle/src/mir/mod.rs index 46184cddd51f5..cc02a3eb97158 100644 --- a/compiler/rustc_middle/src/mir/mod.rs +++ b/compiler/rustc_middle/src/mir/mod.rs @@ -2,6 +2,7 @@ //! //! [rustc dev guide]: https://rustc-dev-guide.rust-lang.org/mir/index.html +use core::alloc::GlobalCoAllocMeta; use crate::mir::interpret::{ AllocRange, ConstAllocation, ConstValue, ErrorHandled, GlobalAlloc, LitToConstInput, Scalar, }; @@ -3077,7 +3078,7 @@ mod size_asserts { use super::*; use rustc_data_structures::static_assert_size; // tidy-alphabetical-start - static_assert_size!(BasicBlockData<'_>, 144); + static_assert_size!(BasicBlockData<'_>, 144 + mem::size_of::()); static_assert_size!(LocalDecl<'_>, 56); static_assert_size!(Statement<'_>, 32); static_assert_size!(StatementKind<'_>, 16); diff --git a/compiler/rustc_middle/src/mir/syntax.rs b/compiler/rustc_middle/src/mir/syntax.rs index 66ee68187896f..26ac845194fe5 100644 --- a/compiler/rustc_middle/src/mir/syntax.rs +++ b/compiler/rustc_middle/src/mir/syntax.rs @@ -3,6 +3,8 @@ //! This is in a dedicated file so that changes to this file can be reviewed more carefully. //! The intention is that this file only contains datatype declarations, no code. +use core::alloc::GlobalCoAllocMeta; +use core::mem; use super::{BasicBlock, Constant, Field, Local, SwitchTargets, UserTypeProjection}; use crate::mir::coverage::{CodeRegion, CoverageKind}; @@ -1282,6 +1284,6 @@ mod size_asserts { static_assert_size!(Operand<'_>, 24); static_assert_size!(Place<'_>, 16); static_assert_size!(PlaceElem<'_>, 24); - static_assert_size!(Rvalue<'_>, 40); + static_assert_size!(Rvalue<'_>, 40 + mem::size_of::()); // tidy-alphabetical-end } diff --git a/compiler/rustc_parse/src/lib.rs b/compiler/rustc_parse/src/lib.rs index b49a01d75ed54..1ba1049b0bc80 100644 --- a/compiler/rustc_parse/src/lib.rs +++ b/compiler/rustc_parse/src/lib.rs @@ -2,6 +2,7 @@ #![feature(array_windows)] #![feature(box_patterns)] +#![feature(global_co_alloc_meta)] #![feature(if_let_guard)] #![feature(iter_intersperse)] #![feature(let_chains)] diff --git a/compiler/rustc_parse/src/parser/attr_wrapper.rs b/compiler/rustc_parse/src/parser/attr_wrapper.rs index dbd3b76786f42..15833cdf268d7 100644 --- a/compiler/rustc_parse/src/parser/attr_wrapper.rs +++ b/compiler/rustc_parse/src/parser/attr_wrapper.rs @@ -1,3 +1,5 @@ +use core::alloc::GlobalCoAllocMeta; +use core::mem; use super::{Capturing, FlatToken, ForceCollect, Parser, ReplaceRange, TokenCursor, TrailingToken}; use rustc_ast::token::{self, Delimiter, Token, TokenKind}; use rustc_ast::tokenstream::{AttrTokenStream, AttributesData, ToAttrTokenStream}; @@ -469,6 +471,6 @@ mod size_asserts { use rustc_data_structures::static_assert_size; // tidy-alphabetical-start static_assert_size!(AttrWrapper, 16); - static_assert_size!(LazyAttrTokenStreamImpl, 120); + static_assert_size!(LazyAttrTokenStreamImpl, 120 + mem::size_of::()); // tidy-alphabetical-end } diff --git a/compiler/rustc_parse/src/parser/mod.rs b/compiler/rustc_parse/src/parser/mod.rs index a74f408d77412..f058907f188ea 100644 --- a/compiler/rustc_parse/src/parser/mod.rs +++ b/compiler/rustc_parse/src/parser/mod.rs @@ -11,6 +11,7 @@ mod stmt; mod ty; use crate::lexer::UnmatchedBrace; +use core::alloc::GlobalCoAllocMeta; pub use attr_wrapper::AttrWrapper; pub use diagnostics::AttemptLocalParseRecovery; pub(crate) use item::FnParseMode; @@ -167,7 +168,7 @@ pub struct Parser<'a> { // This type is used a lot, e.g. it's cloned when matching many declarative macro rules with nonterminals. Make sure // it doesn't unintentionally get bigger. #[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))] -rustc_data_structures::static_assert_size!(Parser<'_>, 312); +rustc_data_structures::static_assert_size!(Parser<'_>, 312 + 4 * mem::size_of::()); /// Stores span information about a closure. #[derive(Clone)] diff --git a/compiler/rustc_trait_selection/src/lib.rs b/compiler/rustc_trait_selection/src/lib.rs index 6fa0941036390..d35cf93347b6e 100644 --- a/compiler/rustc_trait_selection/src/lib.rs +++ b/compiler/rustc_trait_selection/src/lib.rs @@ -15,6 +15,7 @@ #![feature(box_patterns)] #![feature(control_flow_enum)] #![feature(drain_filter)] +#![feature(global_co_alloc_meta)] #![feature(hash_drain_filter)] #![feature(let_chains)] #![feature(if_let_guard)] diff --git a/compiler/rustc_trait_selection/src/traits/fulfill.rs b/compiler/rustc_trait_selection/src/traits/fulfill.rs index deeed930e50e2..3f85de7d7e446 100644 --- a/compiler/rustc_trait_selection/src/traits/fulfill.rs +++ b/compiler/rustc_trait_selection/src/traits/fulfill.rs @@ -1,4 +1,7 @@ use crate::infer::{InferCtxt, TyOrConstInferVar}; +use core::alloc::GlobalCoAllocMeta; +use core::mem; +// use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::obligation_forest::ProcessResult; use rustc_data_structures::obligation_forest::{Error, ForestObligation, Outcome}; use rustc_data_structures::obligation_forest::{ObligationForest, ObligationProcessor}; @@ -77,7 +80,7 @@ pub struct PendingPredicateObligation<'tcx> { // `PendingPredicateObligation` is used a lot. Make sure it doesn't unintentionally get bigger. #[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))] -static_assert_size!(PendingPredicateObligation<'_>, 72); +static_assert_size!(PendingPredicateObligation<'_>, 72 + mem::size_of::()); impl<'a, 'tcx> FulfillmentContext<'tcx> { /// Creates a new fulfillment context. diff --git a/library/alloc/src/lib.rs b/library/alloc/src/lib.rs index e9cc3875f683b..fbbed4f636315 100644 --- a/library/alloc/src/lib.rs +++ b/library/alloc/src/lib.rs @@ -123,6 +123,7 @@ #![feature(extend_one)] #![feature(fmt_internals)] #![feature(fn_traits)] +#![feature(global_co_alloc_meta)] #![feature(hasher_prefixfree_extras)] #![feature(inline_const)] #![feature(inplace_iteration)] @@ -178,6 +179,7 @@ #![feature(exclusive_range_pattern)] #![feature(fundamental)] #![cfg_attr(not(test), feature(generator_trait))] +#![feature(global_co_alloc)] #![feature(hashmap_internals)] #![feature(lang_items)] #![feature(min_specialization)] diff --git a/library/alloc/src/raw_vec.rs b/library/alloc/src/raw_vec.rs index 3751f2a245456..af2813abd1ddb 100644 --- a/library/alloc/src/raw_vec.rs +++ b/library/alloc/src/raw_vec.rs @@ -1,6 +1,6 @@ #![unstable(feature = "raw_vec_internals", reason = "unstable const warnings", issue = "none")] -use core::alloc::LayoutError; +use core::alloc::{LayoutError, GlobalCoAllocMeta}; use core::cmp; use core::intrinsics; use core::mem::{self, ManuallyDrop, MaybeUninit, SizedTypeProperties}; @@ -53,6 +53,8 @@ pub(crate) struct RawVec { ptr: Unique, cap: usize, alloc: A, + #[allow(dead_code)] + pub(crate) meta: GlobalCoAllocMeta, } impl RawVec { @@ -120,7 +122,7 @@ impl RawVec { /// the returned `RawVec`. pub const fn new_in(alloc: A) -> Self { // `cap: 0` means "unallocated". zero-sized types are ignored. - Self { ptr: Unique::dangling(), cap: 0, alloc } + Self { ptr: Unique::dangling(), cap: 0, alloc, meta: GlobalCoAllocMeta {/*one: 1*/ /* , two: 2, three: 3, four: 4*/} } } /// Like `with_capacity`, but parameterized over the choice of @@ -197,6 +199,7 @@ impl RawVec { ptr: unsafe { Unique::new_unchecked(ptr.cast().as_ptr()) }, cap: capacity, alloc, + meta: GlobalCoAllocMeta {/*one: 1*/ /*, two: 2, three: 3, four: 4*/} } } } @@ -213,7 +216,7 @@ impl RawVec { /// guaranteed. #[inline] pub unsafe fn from_raw_parts_in(ptr: *mut T, capacity: usize, alloc: A) -> Self { - Self { ptr: unsafe { Unique::new_unchecked(ptr) }, cap: capacity, alloc } + Self { ptr: unsafe { Unique::new_unchecked(ptr) }, cap: capacity, alloc, meta: GlobalCoAllocMeta {/*one: 1*/ /*, two: 2, three: 3, four: 4*/} } } /// Gets a raw pointer to the start of the allocation. Note that this is @@ -480,8 +483,18 @@ where } unsafe impl<#[may_dangle] T, A: Allocator> Drop for RawVec { + /// Frees the memory owned by the `RawVec` *without* trying to drop its contents. + default fn drop(&mut self) { + if let Some((ptr, layout)) = self.current_memory() { + unsafe { self.alloc.deallocate(ptr, layout) } + } + } +} + +unsafe impl<#[may_dangle] T> Drop for RawVec { /// Frees the memory owned by the `RawVec` *without* trying to drop its contents. fn drop(&mut self) { + // @TODO if let Some((ptr, layout)) = self.current_memory() { unsafe { self.alloc.deallocate(ptr, layout) } } diff --git a/src/librustdoc/clean/types.rs b/src/librustdoc/clean/types.rs index fc1396e86f6b1..092fc9b167012 100644 --- a/src/librustdoc/clean/types.rs +++ b/src/librustdoc/clean/types.rs @@ -1,6 +1,8 @@ +use std::alloc::GlobalCoAllocMeta; use std::cell::RefCell; use std::default::Default; use std::hash::Hash; +use std::mem; use std::path::PathBuf; use std::rc::Rc; use std::sync::Arc; @@ -2400,13 +2402,13 @@ mod size_asserts { // tidy-alphabetical-start static_assert_size!(Crate, 64); // frequently moved by-value static_assert_size!(DocFragment, 32); - static_assert_size!(GenericArg, 32); + static_assert_size!(GenericArg, 32 + mem::size_of::()); static_assert_size!(GenericArgs, 32); - static_assert_size!(GenericParamDef, 56); + static_assert_size!(GenericParamDef, 56 + mem::size_of::()); static_assert_size!(Generics, 16); static_assert_size!(Item, 56); - static_assert_size!(ItemKind, 64); + static_assert_size!(ItemKind, 64 + mem::size_of::()); static_assert_size!(PathSegment, 40); - static_assert_size!(Type, 32); + static_assert_size!(Type, 32 + mem::size_of::()); // tidy-alphabetical-end } diff --git a/src/librustdoc/html/render/context.rs b/src/librustdoc/html/render/context.rs index 5e4a595627b4a..504938fef733b 100644 --- a/src/librustdoc/html/render/context.rs +++ b/src/librustdoc/html/render/context.rs @@ -1,6 +1,8 @@ +use std::alloc::GlobalCoAllocMeta; use std::cell::RefCell; use std::collections::BTreeMap; use std::io; +use std::mem; use std::path::{Path, PathBuf}; use std::rc::Rc; use std::sync::mpsc::{channel, Receiver}; @@ -75,7 +77,7 @@ pub(crate) struct Context<'tcx> { // `Context` is cloned a lot, so we don't want the size to grow unexpectedly. #[cfg(all(not(windows), target_arch = "x86_64", target_pointer_width = "64"))] -rustc_data_structures::static_assert_size!(Context<'_>, 160); +rustc_data_structures::static_assert_size!(Context<'_>, 160 + 2 * mem::size_of::()); /// Shared mutable state used in [`Context`] and elsewhere. pub(crate) struct SharedContext<'tcx> { diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index 910a7190b5842..52c494de75372 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -7,6 +7,7 @@ #![feature(assert_matches)] #![feature(box_patterns)] #![feature(drain_filter)] +#![feature(global_co_alloc_meta)] #![feature(is_terminal)] #![feature(let_chains)] #![feature(test)] From 53028b7c5a12a839038091e21c4996565344c5ce Mon Sep 17 00:00:00 2001 From: Peter Kehl Date: Sat, 10 Dec 2022 10:44:27 -0800 Subject: [PATCH 003/118] CoAlloc: GlobalAlloc API --- library/core/src/alloc/global.rs | 12 +-- library/core/src/alloc/mod.rs | 129 +++++++++++++++++++++++++++++++ 2 files changed, 135 insertions(+), 6 deletions(-) diff --git a/library/core/src/alloc/global.rs b/library/core/src/alloc/global.rs index 584343e7faf76..26308e63a7bad 100644 --- a/library/core/src/alloc/global.rs +++ b/library/core/src/alloc/global.rs @@ -6,7 +6,7 @@ use crate::alloc::GlobalCoAllocMeta; #[unstable(feature = "global_co_alloc_meta", issue = "none")] #[allow(missing_debug_implementations)] /// Used for parameters and results (to/from `GlobalCoAllocator`'s functions, where applicable). -pub struct PtrAndMeta { +pub struct RawAndMeta { pub ptr: *mut u8, pub meta: GlobalCoAllocMeta, } @@ -166,7 +166,7 @@ pub unsafe trait GlobalAlloc { unsafe fn alloc(&self, layout: Layout) -> *mut u8; #[unstable(feature = "global_co_alloc", issue = "none")] - unsafe fn co_alloc(&self, _layout: Layout, mut _result: &mut PtrAndMeta) {panic!("TODO")} + unsafe fn co_alloc(&self, _layout: Layout, mut _result: &mut RawAndMeta) {panic!("TODO")} /// Deallocate the block of memory at the given `ptr` pointer with the given `layout`. /// @@ -184,7 +184,7 @@ pub unsafe trait GlobalAlloc { unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout); #[unstable(feature = "global_co_alloc", issue = "none")] - unsafe fn co_dealloc(&self, _ptr_and_meta: PtrAndMeta, _layout: Layout) {panic!("TODO")} + unsafe fn co_dealloc(&self, _ptr_and_meta: RawAndMeta, _layout: Layout) {panic!("TODO")} /// Behaves like `alloc`, but also ensures that the contents /// are set to zero before being returned. @@ -219,7 +219,7 @@ pub unsafe trait GlobalAlloc { } #[unstable(feature = "global_co_alloc", issue = "none")] - unsafe fn co_alloc_zeroed(&self, layout: Layout, mut result: &mut PtrAndMeta) { + unsafe fn co_alloc_zeroed(&self, layout: Layout, mut result: &mut RawAndMeta) { let size = layout.size(); // SAFETY: the safety contract for `alloc` must be upheld by the caller. unsafe { self.co_alloc(layout, &mut result) }; @@ -306,10 +306,10 @@ pub unsafe trait GlobalAlloc { #[unstable(feature = "global_co_alloc", issue = "none")] unsafe fn co_realloc( &self, - ptr_and_meta: PtrAndMeta, + ptr_and_meta: RawAndMeta, layout: Layout, new_size: usize, - mut result: &mut PtrAndMeta + mut result: &mut RawAndMeta ) { // SAFETY: the caller must ensure that the `new_size` does not overflow. // `layout.align()` comes from a `Layout` and is thus guaranteed to be valid. diff --git a/library/core/src/alloc/mod.rs b/library/core/src/alloc/mod.rs index 6e7b54ffb8612..53be91801e0cf 100644 --- a/library/core/src/alloc/mod.rs +++ b/library/core/src/alloc/mod.rs @@ -58,6 +58,25 @@ impl fmt::Display for AllocError { } } +#[unstable(feature = "global_co_alloc_meta", issue = "none")] +#[allow(missing_debug_implementations)] +pub struct PtrAndMeta { + pub ptr: NonNull, + pub meta: GlobalCoAllocMeta, +} + +#[unstable(feature = "global_co_alloc_meta", issue = "none")] +#[allow(missing_debug_implementations)] +/// Used for results (from `CoAllocator`'s functions, where applicable). +pub struct SliceAndMeta { + pub slice: NonNull<[u8]>, + pub meta: GlobalCoAllocMeta, +} + +#[unstable(feature = "global_co_alloc_meta", issue = "none")] +#[allow(missing_debug_implementations)] +pub type SliceAndMetaResult = Result; + /// An implementation of `Allocator` can allocate, grow, shrink, and deallocate arbitrary blocks of /// data described via [`Layout`][]. /// @@ -139,6 +158,8 @@ pub unsafe trait Allocator { /// [`handle_alloc_error`]: ../../alloc/alloc/fn.handle_alloc_error.html fn allocate(&self, layout: Layout) -> Result, AllocError>; + fn co_allocate(&self, _layout: Layout, _result: &mut SliceAndMetaResult) {panic!("TODO")} + /// Behaves like `allocate`, but also ensures that the returned memory is zero-initialized. /// /// # Errors @@ -161,6 +182,19 @@ pub unsafe trait Allocator { Ok(ptr) } + fn co_allocate_zeroed(&self, layout: Layout, mut result: &mut SliceAndMetaResult) { + self.co_allocate(layout, &mut result); + if let Ok(SliceAndMeta{slice, ..}) = result { + // SAFETY: `alloc` returns a valid memory block + unsafe { + slice + .as_non_null_ptr() + .as_ptr() + .write_bytes(0, slice.len()) + } + } + } + /// Deallocates the memory referenced by `ptr`. /// /// # Safety @@ -172,6 +206,8 @@ pub unsafe trait Allocator { /// [*fit*]: #memory-fitting unsafe fn deallocate(&self, ptr: NonNull, layout: Layout); + unsafe fn co_deallocate(&self, _ptr_and_meta: PtrAndMeta, _layout: Layout) {panic!("TODO")} + /// Attempts to extend the memory block. /// /// Returns a new [`NonNull<[u8]>`][NonNull] containing a pointer and the actual size of the allocated @@ -236,6 +272,37 @@ pub unsafe trait Allocator { Ok(new_ptr) } + unsafe fn co_grow( + &self, + ptr_and_meta: PtrAndMeta, + old_layout: Layout, + new_layout: Layout, + mut result: &mut SliceAndMetaResult + ) { + debug_assert!( + new_layout.size() >= old_layout.size(), + "`new_layout.size()` must be greater than or equal to `old_layout.size()`" + ); + + self.co_allocate(new_layout, &mut result); + + if let Ok(SliceAndMeta {slice, ..}) = result { + // SAFETY: because `new_layout.size()` must be greater than or equal to + // `old_layout.size()`, both the old and new memory allocation are valid for reads and + // writes for `old_layout.size()` bytes. Also, because the old allocation wasn't yet + // deallocated, it cannot overlap `new_slice_and_meta.slice`. Thus, the call to `copy_nonoverlapping` is + // safe. The safety contract for `dealloc` must be upheld by the caller. + unsafe { + ptr::copy_nonoverlapping( + ptr_and_meta.ptr.as_ptr(), + slice.as_mut_ptr(), + old_layout.size(), + ); + self.co_deallocate(ptr_and_meta, old_layout); + } + } + } + /// Behaves like `grow`, but also ensures that the new contents are set to zero before being /// returned. /// @@ -299,6 +366,37 @@ pub unsafe trait Allocator { Ok(new_ptr) } + unsafe fn co_grow_zeroed( + &self, + ptr_and_meta: PtrAndMeta, + old_layout: Layout, + new_layout: Layout, + mut result: &mut SliceAndMetaResult + ) { + debug_assert!( + new_layout.size() >= old_layout.size(), + "`new_layout.size()` must be greater than or equal to `old_layout.size()`" + ); + + self.co_allocate_zeroed(new_layout, &mut result); + + if let Ok(SliceAndMeta{ slice, ..}) = result { + // SAFETY: because `new_layout.size()` must be greater than or equal to + // `old_layout.size()`, both the old and new memory allocation are valid for reads and + // writes for `old_layout.size()` bytes. Also, because the old allocation wasn't yet + // deallocated, it cannot overlap `new_slice_and_meta.slice`. Thus, the call to `copy_nonoverlapping` is + // safe. The safety contract for `dealloc` must be upheld by the caller. + unsafe { + ptr::copy_nonoverlapping( + ptr_and_meta.ptr.as_ptr(), + slice.as_mut_ptr(), + old_layout.size(), + ); + self.co_deallocate(ptr_and_meta, old_layout); + } + } + } + /// Attempts to shrink the memory block. /// /// Returns a new [`NonNull<[u8]>`][NonNull] containing a pointer and the actual size of the allocated @@ -363,6 +461,37 @@ pub unsafe trait Allocator { Ok(new_ptr) } + unsafe fn co_shrink( + &self, + ptr_and_meta: PtrAndMeta, + old_layout: Layout, + new_layout: Layout, + mut result: &mut SliceAndMetaResult + ) { + debug_assert!( + new_layout.size() <= old_layout.size(), + "`new_layout.size()` must be smaller than or equal to `old_layout.size()`" + ); + + self.co_allocate(new_layout, &mut result); + + if let Ok(SliceAndMeta{ slice, ..}) = result { + // SAFETY: because `new_layout.size()` must be lower than or equal to + // `old_layout.size()`, both the old and new memory allocation are valid for reads and + // writes for `new_layout.size()` bytes. Also, because the old allocation wasn't yet + // deallocated, it cannot overlap `new_slice_and_meta.slice`. Thus, the call to `copy_nonoverlapping` is + // safe. The safety contract for `dealloc` must be upheld by the caller. + unsafe { + ptr::copy_nonoverlapping( + ptr_and_meta.ptr.as_ptr(), + slice.as_mut_ptr(), + new_layout.size(), + ); + self.co_deallocate(ptr_and_meta, old_layout); + } + } + } + /// Creates a "by reference" adapter for this instance of `Allocator`. /// /// The returned adapter also implements `Allocator` and will simply borrow this. From 55398995ef25ca8ae1eda7543eb642d5e44152cf Mon Sep 17 00:00:00 2001 From: Peter Kehl Date: Sat, 21 Jan 2023 15:55:48 -0800 Subject: [PATCH 004/118] CoAlloc: Alloc API --- library/core/src/alloc/mod.rs | 13 +++++++++++++ library/core/src/lib.rs | 1 + library/std/src/alloc.rs | 3 +++ 3 files changed, 17 insertions(+) diff --git a/library/core/src/alloc/mod.rs b/library/core/src/alloc/mod.rs index 53be91801e0cf..23bfdc732557e 100644 --- a/library/core/src/alloc/mod.rs +++ b/library/core/src/alloc/mod.rs @@ -77,6 +77,11 @@ pub struct SliceAndMeta { #[allow(missing_debug_implementations)] pub type SliceAndMetaResult = Result; +#[unstable(feature = "global_co_alloc", issue = "none")] +pub const fn co_alloc_metadata_num_slots() -> usize { + if A::IS_CO_ALLOCATOR { 1 } else { 0 } +} + /// An implementation of `Allocator` can allocate, grow, shrink, and deallocate arbitrary blocks of /// data described via [`Layout`][]. /// @@ -136,6 +141,13 @@ pub type SliceAndMetaResult = Result; #[unstable(feature = "allocator_api", issue = "32838")] #[const_trait] pub unsafe trait Allocator { + //const fn is_co_allocator() -> bool {false} + // Can't have: const type Xyz; + /// If this is any type with non-zero size, then the actual `Allocator` implementation supports cooperative functions (`co_*`) as first class citizens. + //type IsCoAllocator = (); + // It applies to the global (default) allocator only. And/or System allocator?! TODO + const IS_CO_ALLOCATOR: bool = true; + /// Attempts to allocate a block of memory. /// /// On success, returns a [`NonNull<[u8]>`][NonNull] meeting the size and alignment guarantees of `layout`. @@ -504,6 +516,7 @@ pub unsafe trait Allocator { } } +// @TODO #[unstable(feature = "allocator_api", issue = "32838")] unsafe impl Allocator for &A where diff --git a/library/core/src/lib.rs b/library/core/src/lib.rs index dc0702c467a4e..ba4a2ca02d844 100644 --- a/library/core/src/lib.rs +++ b/library/core/src/lib.rs @@ -98,6 +98,7 @@ #![cfg_attr(not(bootstrap), warn(multiple_supertrait_upcastable))] // // Library features: +#![feature(associated_type_defaults)] #![feature(const_align_offset)] #![feature(const_align_of_val)] #![feature(const_align_of_val_raw)] diff --git a/library/std/src/alloc.rs b/library/std/src/alloc.rs index c5a5991cc81c4..bee6edbc40731 100644 --- a/library/std/src/alloc.rs +++ b/library/std/src/alloc.rs @@ -197,10 +197,13 @@ impl System { } } +// @TODO // The Allocator impl checks the layout size to be non-zero and forwards to the GlobalAlloc impl, // which is in `std::sys::*::alloc`. #[unstable(feature = "allocator_api", issue = "32838")] unsafe impl Allocator for System { + const IS_CO_ALLOCATOR: bool = false; + #[inline] fn allocate(&self, layout: Layout) -> Result, AllocError> { self.alloc_impl(layout, false) From 0625faeada51dedcbc35121d565c5af669c7f3a1 Mon Sep 17 00:00:00 2001 From: Peter Kehl Date: Sat, 21 Jan 2023 15:58:34 -0800 Subject: [PATCH 005/118] CoAlloc: RawVec includes GlobalCoAllocMeta based on allocator; related bounds - NOT COMPILING (no ICE, but standard compiler error) --- library/alloc/src/lib.rs | 2 + library/alloc/src/raw_vec.rs | 44 +++++++++++++++------- library/alloc/src/slice.rs | 25 +++++++++---- library/alloc/src/vec/mod.rs | 72 ++++++++++++++++++++++++++---------- library/alloc/tests/boxed.rs | 1 + 5 files changed, 104 insertions(+), 40 deletions(-) diff --git a/library/alloc/src/lib.rs b/library/alloc/src/lib.rs index fbbed4f636315..0de19c44fb5de 100644 --- a/library/alloc/src/lib.rs +++ b/library/alloc/src/lib.rs @@ -86,6 +86,7 @@ #![warn(deprecated_in_future)] #![warn(missing_debug_implementations)] #![warn(missing_docs)] +#![allow(incomplete_features)] #![allow(explicit_outlives_requirements)] #![cfg_attr(not(bootstrap), warn(multiple_supertrait_upcastable))] // @@ -123,6 +124,7 @@ #![feature(extend_one)] #![feature(fmt_internals)] #![feature(fn_traits)] +#![feature(generic_const_exprs)] #![feature(global_co_alloc_meta)] #![feature(hasher_prefixfree_extras)] #![feature(inline_const)] diff --git a/library/alloc/src/raw_vec.rs b/library/alloc/src/raw_vec.rs index af2813abd1ddb..7b98fadc713de 100644 --- a/library/alloc/src/raw_vec.rs +++ b/library/alloc/src/raw_vec.rs @@ -1,6 +1,6 @@ #![unstable(feature = "raw_vec_internals", reason = "unstable const warnings", issue = "none")] -use core::alloc::{LayoutError, GlobalCoAllocMeta}; +use core::alloc::{self, LayoutError, GlobalCoAllocMeta}; use core::cmp; use core::intrinsics; use core::mem::{self, ManuallyDrop, MaybeUninit, SizedTypeProperties}; @@ -49,12 +49,19 @@ enum AllocInit { /// `usize::MAX`. This means that you need to be careful when round-tripping this type with a /// `Box<[T]>`, since `capacity()` won't yield the length. #[allow(missing_debug_implementations)] -pub(crate) struct RawVec { +// @TODO +// 1. make const generic _coop come from the target specification +// 2. apply `_coop` with logical && to `A::IsCoAllocator` +pub(crate) struct RawVec +where [(); alloc::co_alloc_metadata_num_slots::()]: +{ ptr: Unique, cap: usize, alloc: A, - #[allow(dead_code)] - pub(crate) meta: GlobalCoAllocMeta, + // As of v1.67.0, `cmp` for `TypeId` is not `const`, unfortunately: + //pub(crate) meta: [GlobalCoAllocMeta; {if core::any::TypeId::of::()==core::any::TypeId::of::() {1} else {0}}], + //pub(crate) meta: [GlobalCoAllocMeta; mem::size_of::()], + pub(crate) meta: [GlobalCoAllocMeta; alloc::co_alloc_metadata_num_slots::()], } impl RawVec { @@ -104,7 +111,9 @@ impl RawVec { } } -impl RawVec { +impl RawVec +where [(); alloc::co_alloc_metadata_num_slots::()]: +{ // Tiny Vecs are dumb. Skip to: // - 8 if the element size is 1, because any heap allocators is likely // to round up a request of less than 8 bytes to at least 8 bytes. @@ -289,7 +298,9 @@ impl RawVec { slf: &mut RawVec, len: usize, additional: usize, - ) { + ) + where [(); alloc::co_alloc_metadata_num_slots::()]: + { handle_reserve(slf.grow_amortized(len, additional)); } @@ -362,14 +373,18 @@ impl RawVec { } } -impl RawVec { +impl RawVec +where [(); alloc::co_alloc_metadata_num_slots::()]: +{ /// Returns if the buffer needs to grow to fulfill the needed extra capacity. /// Mainly used to make inlining reserve-calls possible without inlining `grow`. - fn needs_to_grow(&self, len: usize, additional: usize) -> bool { + fn needs_to_grow(&self, len: usize, additional: usize) -> bool + { additional > self.capacity().wrapping_sub(len) } - fn set_ptr_and_cap(&mut self, ptr: NonNull<[u8]>, cap: usize) { + fn set_ptr_and_cap(&mut self, ptr: NonNull<[u8]>, cap: usize) + { // Allocators currently return a `NonNull<[u8]>` whose length matches // the size requested. If that ever changes, the capacity here should // change to `ptr.len() / mem::size_of::()`. @@ -482,16 +497,19 @@ where memory.map_err(|_| AllocError { layout: new_layout, non_exhaustive: () }.into()) } -unsafe impl<#[may_dangle] T, A: Allocator> Drop for RawVec { +unsafe impl<#[may_dangle] T, A: Allocator> Drop for RawVec +where [(); alloc::co_alloc_metadata_num_slots::()]: +{ /// Frees the memory owned by the `RawVec` *without* trying to drop its contents. default fn drop(&mut self) { if let Some((ptr, layout)) = self.current_memory() { - unsafe { self.alloc.deallocate(ptr, layout) } + unsafe { self.alloc.co_deallocate(ptr, layout) } } } } -unsafe impl<#[may_dangle] T> Drop for RawVec { +// @TODO Custom +/*unsafe impl<#[may_dangle] T> Drop for RawVec { /// Frees the memory owned by the `RawVec` *without* trying to drop its contents. fn drop(&mut self) { // @TODO @@ -499,7 +517,7 @@ unsafe impl<#[may_dangle] T> Drop for RawVec { unsafe { self.alloc.deallocate(ptr, layout) } } } -} +}*/ // Central function for reserve error handling. #[cfg(not(no_global_oom_handling))] diff --git a/library/alloc/src/slice.rs b/library/alloc/src/slice.rs index 093dcbbe8bf77..6d77615f359b6 100644 --- a/library/alloc/src/slice.rs +++ b/library/alloc/src/slice.rs @@ -97,7 +97,8 @@ pub(crate) mod hack { // We shouldn't add inline attribute to this since this is used in // `vec!` macro mostly and causes perf regression. See #71204 for // discussion and perf results. - pub fn into_vec(b: Box<[T], A>) -> Vec { + pub fn into_vec(b: Box<[T], A>) -> Vec + where [(); core::alloc::co_alloc_metadata_num_slots::()]: { unsafe { let len = b.len(); let (b, alloc) = Box::into_raw_with_allocator(b); @@ -107,7 +108,8 @@ pub(crate) mod hack { #[cfg(not(no_global_oom_handling))] #[inline] - pub fn to_vec(s: &[T], alloc: A) -> Vec { + pub fn to_vec(s: &[T], alloc: A) -> Vec + where [(); core::alloc::co_alloc_metadata_num_slots::()]: { T::to_vec(s, alloc) } @@ -115,13 +117,15 @@ pub(crate) mod hack { pub trait ConvertVec { fn to_vec(s: &[Self], alloc: A) -> Vec where - Self: Sized; + Self: Sized, + [(); core::alloc::co_alloc_metadata_num_slots::()]:; } #[cfg(not(no_global_oom_handling))] impl ConvertVec for T { #[inline] - default fn to_vec(s: &[Self], alloc: A) -> Vec { + default fn to_vec(s: &[Self], alloc: A) -> Vec + where [(); core::alloc::co_alloc_metadata_num_slots::()]: { struct DropGuard<'a, T, A: Allocator> { vec: &'a mut Vec, num_init: usize, @@ -158,7 +162,8 @@ pub(crate) mod hack { #[cfg(not(no_global_oom_handling))] impl ConvertVec for T { #[inline] - fn to_vec(s: &[Self], alloc: A) -> Vec { + fn to_vec(s: &[Self], alloc: A) -> Vec + where [(); core::alloc::co_alloc_metadata_num_slots::()]: { let mut v = Vec::with_capacity_in(s.len(), alloc); // SAFETY: // allocated above with the capacity of `s`, and initialize to `s.len()` in @@ -436,6 +441,7 @@ impl [T] { pub fn to_vec_in(&self, alloc: A) -> Vec where T: Clone, + [(); core::alloc::co_alloc_metadata_num_slots::()]: { // N.B., see the `hack` module in this file for more details. hack::to_vec(self, alloc) @@ -458,7 +464,8 @@ impl [T] { #[rustc_allow_incoherent_impl] #[stable(feature = "rust1", since = "1.0.0")] #[inline] - pub fn into_vec(self: Box) -> Vec { + pub fn into_vec(self: Box) -> Vec + where [(); core::alloc::co_alloc_metadata_num_slots::()]: { // N.B., see the `hack` module in this file for more details. hack::into_vec(self) } @@ -769,14 +776,16 @@ impl> Join<&[T]> for [V] { //////////////////////////////////////////////////////////////////////////////// #[stable(feature = "rust1", since = "1.0.0")] -impl Borrow<[T]> for Vec { +impl Borrow<[T]> for Vec +where [(); core::alloc::co_alloc_metadata_num_slots::()]: { fn borrow(&self) -> &[T] { &self[..] } } #[stable(feature = "rust1", since = "1.0.0")] -impl BorrowMut<[T]> for Vec { +impl BorrowMut<[T]> for Vec +where [(); core::alloc::co_alloc_metadata_num_slots::()]: { fn borrow_mut(&mut self) -> &mut [T] { &mut self[..] } diff --git a/library/alloc/src/vec/mod.rs b/library/alloc/src/vec/mod.rs index a07f3da78d33e..cf1251d13dfd5 100644 --- a/library/alloc/src/vec/mod.rs +++ b/library/alloc/src/vec/mod.rs @@ -397,11 +397,27 @@ mod spec_extend; #[stable(feature = "rust1", since = "1.0.0")] #[cfg_attr(not(test), rustc_diagnostic_item = "Vec")] #[rustc_insignificant_dtor] -pub struct Vec { - buf: RawVec, +// @TODO _coop +pub struct Vec +where [(); core::alloc::co_alloc_metadata_num_slots::()]: +{ + buf: RawVec, len: usize, } +#[unstable(feature = "global_co_alloc_vec", issue = "none")] +pub type CoVec = Vec; + +/// "Plain" Vec. +#[unstable(feature = "global_co_alloc_vec", issue = "none")] +pub type PlVec = Vec; + +/// "Weighted" Vec. +/// weight means how much it wants to cooperate. 0 = always pack; u8::MAX = always coop (if `Global` supports it). +/// @TODO Weighing on the side of Allocator - const fn. +#[unstable(feature = "global_co_alloc_vec", issue = "none")] +pub type WeVec = Vec1}>; + //////////////////////////////////////////////////////////////////////////////// // Inherent methods //////////////////////////////////////////////////////////////////////////////// @@ -593,7 +609,8 @@ impl Vec { } } -impl Vec { +impl Vec +where [(); core::alloc::co_alloc_metadata_num_slots::()]: { /// Constructs a new, empty `Vec`. /// /// The vector will not allocate until elements are pushed onto it. @@ -1606,14 +1623,16 @@ impl Vec { // This drop guard will be invoked when predicate or `drop` of element panicked. // It shifts unchecked elements to cover holes and `set_len` to the correct length. // In cases when predicate and `drop` never panick, it will be optimized out. - struct BackshiftOnDrop<'a, T, A: Allocator> { + struct BackshiftOnDrop<'a, T, A: Allocator> + where [(); core::alloc::co_alloc_metadata_num_slots::()]: { v: &'a mut Vec, processed_len: usize, deleted_cnt: usize, original_len: usize, } - impl Drop for BackshiftOnDrop<'_, T, A> { + impl Drop for BackshiftOnDrop<'_, T, A> + where [(); core::alloc::co_alloc_metadata_num_slots::()]: { fn drop(&mut self) { if self.deleted_cnt > 0 { // SAFETY: Trailing unchecked items must be valid since we never touch them. @@ -1640,6 +1659,7 @@ impl Vec { g: &mut BackshiftOnDrop<'_, T, A>, ) where F: FnMut(&mut T) -> bool, + [(); core::alloc::co_alloc_metadata_num_slots::()]: { while g.processed_len != original_len { // SAFETY: Unchecked element must be valid. @@ -1732,7 +1752,8 @@ impl Vec { } /* INVARIANT: vec.len() > read >= write > write-1 >= 0 */ - struct FillGapOnDrop<'a, T, A: core::alloc::Allocator> { + struct FillGapOnDrop<'a, T, A: core::alloc::Allocator> + where [(); core::alloc::co_alloc_metadata_num_slots::()]: { /* Offset of the element we want to check if it is duplicate */ read: usize, @@ -1744,7 +1765,8 @@ impl Vec { vec: &'a mut Vec, } - impl<'a, T, A: core::alloc::Allocator> Drop for FillGapOnDrop<'a, T, A> { + impl<'a, T, A: core::alloc::Allocator> Drop for FillGapOnDrop<'a, T, A> + where [(); core::alloc::co_alloc_metadata_num_slots::()]: { fn drop(&mut self) { /* This code gets executed when `same_bucket` panics */ @@ -2337,7 +2359,8 @@ impl Vec { } } -impl Vec { +impl Vec +where [(); core::alloc::co_alloc_metadata_num_slots::()]: { /// Resizes the `Vec` in-place so that `len` is equal to `new_len`. /// /// If `new_len` is greater than `len`, the `Vec` is extended by the @@ -2436,7 +2459,8 @@ impl Vec { } } -impl Vec<[T; N], A> { +impl Vec<[T; N], A> +where [(); core::alloc::co_alloc_metadata_num_slots::()]: { /// Takes a `Vec<[T; N]>` and flattens it into a `Vec`. /// /// # Panics @@ -2497,7 +2521,8 @@ impl ExtendWith for ExtendElement { } } -impl Vec { +impl Vec +where [(); core::alloc::co_alloc_metadata_num_slots::()]: { #[cfg(not(no_global_oom_handling))] /// Extend the vector by `n` values, using the given generator. fn extend_with>(&mut self, n: usize, mut value: E) { @@ -2529,7 +2554,8 @@ impl Vec { } } -impl Vec { +impl Vec +where [(); core::alloc::co_alloc_metadata_num_slots::()]: { /// Removes consecutive repeated elements in the vector according to the /// [`PartialEq`] trait implementation. /// @@ -2565,7 +2591,8 @@ pub fn from_elem(elem: T, n: usize) -> Vec { #[doc(hidden)] #[cfg(not(no_global_oom_handling))] #[unstable(feature = "allocator_api", issue = "32838")] -pub fn from_elem_in(elem: T, n: usize, alloc: A) -> Vec { +pub fn from_elem_in(elem: T, n: usize, alloc: A) -> Vec +where [(); core::alloc::co_alloc_metadata_num_slots::()]: { ::from_elem(elem, n, alloc) } @@ -2577,7 +2604,8 @@ trait ExtendFromWithinSpec { unsafe fn spec_extend_from_within(&mut self, src: Range); } -impl ExtendFromWithinSpec for Vec { +impl ExtendFromWithinSpec for Vec +where [(); core::alloc::co_alloc_metadata_num_slots::()]: { default unsafe fn spec_extend_from_within(&mut self, src: Range) { // SAFETY: // - len is increased only after initializing elements @@ -2596,7 +2624,8 @@ impl ExtendFromWithinSpec for Vec { } } -impl ExtendFromWithinSpec for Vec { +impl ExtendFromWithinSpec for Vec +where [(); core::alloc::co_alloc_metadata_num_slots::()]: { unsafe fn spec_extend_from_within(&mut self, src: Range) { let count = src.len(); { @@ -2629,7 +2658,8 @@ impl ExtendFromWithinSpec for Vec { //////////////////////////////////////////////////////////////////////////////// #[stable(feature = "rust1", since = "1.0.0")] -impl ops::Deref for Vec { +impl ops::Deref for Vec +where [(); core::alloc::co_alloc_metadata_num_slots::()]: { type Target = [T]; #[inline] @@ -2639,7 +2669,8 @@ impl ops::Deref for Vec { } #[stable(feature = "rust1", since = "1.0.0")] -impl ops::DerefMut for Vec { +impl ops::DerefMut for Vec +where [(); core::alloc::co_alloc_metadata_num_slots::()]: { #[inline] fn deref_mut(&mut self) -> &mut [T] { unsafe { slice::from_raw_parts_mut(self.as_mut_ptr(), self.len) } @@ -2648,7 +2679,8 @@ impl ops::DerefMut for Vec { #[cfg(not(no_global_oom_handling))] #[stable(feature = "rust1", since = "1.0.0")] -impl Clone for Vec { +impl Clone for Vec +where [(); core::alloc::co_alloc_metadata_num_slots::()]: { #[cfg(not(test))] fn clone(&self) -> Self { let alloc = self.allocator().clone(); @@ -2683,7 +2715,8 @@ impl Clone for Vec { /// assert_eq!(b.hash_one(v), b.hash_one(s)); /// ``` #[stable(feature = "rust1", since = "1.0.0")] -impl Hash for Vec { +impl Hash for Vec +where [(); core::alloc::co_alloc_metadata_num_slots::()]: { #[inline] fn hash(&self, state: &mut H) { Hash::hash(&**self, state) @@ -2695,7 +2728,8 @@ impl Hash for Vec { message = "vector indices are of type `usize` or ranges of `usize`", label = "vector indices are of type `usize` or ranges of `usize`" )] -impl, A: Allocator> Index for Vec { +impl, A: Allocator> Index for Vec +where [(); core::alloc::co_alloc_metadata_num_slots::()]: { type Output = I::Output; #[inline] diff --git a/library/alloc/tests/boxed.rs b/library/alloc/tests/boxed.rs index af49826ff30a3..c34e7a558061d 100644 --- a/library/alloc/tests/boxed.rs +++ b/library/alloc/tests/boxed.rs @@ -61,6 +61,7 @@ fn box_deref_lval() { pub struct ConstAllocator; +//@TODO unsafe impl const Allocator for ConstAllocator { fn allocate(&self, layout: Layout) -> Result, AllocError> { match layout.size() { From 4ddafb95b677ae7b6c3b8e129625bc9435e98c15 Mon Sep 17 00:00:00 2001 From: Peter Kehl Date: Sat, 21 Jan 2023 15:59:10 -0800 Subject: [PATCH 006/118] CoAlloc: VecDeque (PROBABLY NOT COMPILING, standard error) --- .../alloc/src/collections/vec_deque/macros.rs | 1 + .../alloc/src/collections/vec_deque/mod.rs | 72 +++++++++++++------ 2 files changed, 50 insertions(+), 23 deletions(-) diff --git a/library/alloc/src/collections/vec_deque/macros.rs b/library/alloc/src/collections/vec_deque/macros.rs index 5c7913073fe87..f7768f54c6225 100644 --- a/library/alloc/src/collections/vec_deque/macros.rs +++ b/library/alloc/src/collections/vec_deque/macros.rs @@ -4,6 +4,7 @@ macro_rules! __impl_slice_eq1 { impl PartialEq<$rhs> for $lhs where T: PartialEq, + [(); core::alloc::co_alloc_metadata_num_slots::()]:, $($constraints)* { fn eq(&self, other: &$rhs) -> bool { diff --git a/library/alloc/src/collections/vec_deque/mod.rs b/library/alloc/src/collections/vec_deque/mod.rs index 1573b3d77dc16..8bdb1a27278ab 100644 --- a/library/alloc/src/collections/vec_deque/mod.rs +++ b/library/alloc/src/collections/vec_deque/mod.rs @@ -5,8 +5,10 @@ //! are not required to be copyable, and the queue will be sendable if the //! contained type is sendable. -#![stable(feature = "rust1", since = "1.0.0")] +#![feature(global_co_alloc)] +#![stable(feature = "rust1", since = "1.0.0")] +use core::alloc; use core::cmp::{self, Ordering}; use core::fmt; use core::hash::{Hash, Hasher}; @@ -91,10 +93,13 @@ mod tests; #[cfg_attr(not(test), rustc_diagnostic_item = "VecDeque")] #[stable(feature = "rust1", since = "1.0.0")] #[rustc_insignificant_dtor] +// @TODO pub struct VecDeque< T, #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global, -> { +> +where [(); alloc::co_alloc_metadata_num_slots::()]: +{ // `self[0]`, if it exists, is `buf[head]`. // `head < buf.capacity()`, unless `buf.capacity() == 0` when `head == 0`. head: usize, @@ -106,7 +111,8 @@ pub struct VecDeque< } #[stable(feature = "rust1", since = "1.0.0")] -impl Clone for VecDeque { +impl Clone for VecDeque +where [(); alloc::co_alloc_metadata_num_slots::()]: { fn clone(&self) -> Self { let mut deq = Self::with_capacity_in(self.len(), self.allocator().clone()); deq.extend(self.iter().cloned()); @@ -120,7 +126,8 @@ impl Clone for VecDeque { } #[stable(feature = "rust1", since = "1.0.0")] -unsafe impl<#[may_dangle] T, A: Allocator> Drop for VecDeque { +unsafe impl<#[may_dangle] T, A: Allocator> Drop for VecDeque +where [(); alloc::co_alloc_metadata_num_slots::()]: { fn drop(&mut self) { /// Runs the destructor for all items in the slice when it gets dropped (normally or /// during unwinding). @@ -153,7 +160,8 @@ impl Default for VecDeque { } } -impl VecDeque { +impl VecDeque +where [(); alloc::co_alloc_metadata_num_slots::()]: { /// Marginally more convenient #[inline] fn ptr(&self) -> *mut T { @@ -442,7 +450,8 @@ impl VecDeque { mut iter: impl Iterator, len: usize, ) -> usize { - struct Guard<'a, T, A: Allocator> { + struct Guard<'a, T, A: Allocator> + where [(); alloc::co_alloc_metadata_num_slots::()]: { deque: &'a mut VecDeque, written: usize, } @@ -561,7 +570,8 @@ impl VecDeque { } } -impl VecDeque { +impl VecDeque +where [(); alloc::co_alloc_metadata_num_slots::()]: { /// Creates an empty deque. /// /// # Examples @@ -2596,7 +2606,8 @@ impl VecDeque { } } -impl VecDeque { +impl VecDeque +where [(); alloc::co_alloc_metadata_num_slots::()]: { /// Modifies the deque in-place so that `len()` is equal to new_len, /// either by removing excess elements from the back or by appending clones of `value` /// to the back. @@ -2641,7 +2652,8 @@ fn wrap_index(logical_index: usize, capacity: usize) -> usize { } #[stable(feature = "rust1", since = "1.0.0")] -impl PartialEq for VecDeque { +impl PartialEq for VecDeque +where [(); alloc::co_alloc_metadata_num_slots::()]: { fn eq(&self, other: &Self) -> bool { if self.len != other.len() { return false; @@ -2680,7 +2692,8 @@ impl PartialEq for VecDeque { } #[stable(feature = "rust1", since = "1.0.0")] -impl Eq for VecDeque {} +impl Eq for VecDeque +where [(); alloc::co_alloc_metadata_num_slots::()]: {} __impl_slice_eq1! { [] VecDeque, Vec, } __impl_slice_eq1! { [] VecDeque, &[U], } @@ -2690,14 +2703,16 @@ __impl_slice_eq1! { [const N: usize] VecDeque, &[U; N], } __impl_slice_eq1! { [const N: usize] VecDeque, &mut [U; N], } #[stable(feature = "rust1", since = "1.0.0")] -impl PartialOrd for VecDeque { +impl PartialOrd for VecDeque +where [(); alloc::co_alloc_metadata_num_slots::()]: { fn partial_cmp(&self, other: &Self) -> Option { self.iter().partial_cmp(other.iter()) } } #[stable(feature = "rust1", since = "1.0.0")] -impl Ord for VecDeque { +impl Ord for VecDeque +where [(); alloc::co_alloc_metadata_num_slots::()]: { #[inline] fn cmp(&self, other: &Self) -> Ordering { self.iter().cmp(other.iter()) @@ -2705,7 +2720,8 @@ impl Ord for VecDeque { } #[stable(feature = "rust1", since = "1.0.0")] -impl Hash for VecDeque { +impl Hash for VecDeque +where [(); alloc::co_alloc_metadata_num_slots::()]: { fn hash(&self, state: &mut H) { state.write_length_prefix(self.len); // It's not possible to use Hash::hash_slice on slices @@ -2719,7 +2735,8 @@ impl Hash for VecDeque { } #[stable(feature = "rust1", since = "1.0.0")] -impl Index for VecDeque { +impl Index for VecDeque +where [(); alloc::co_alloc_metadata_num_slots::()]: { type Output = T; #[inline] @@ -2729,7 +2746,8 @@ impl Index for VecDeque { } #[stable(feature = "rust1", since = "1.0.0")] -impl IndexMut for VecDeque { +impl IndexMut for VecDeque +where [(); alloc::co_alloc_metadata_num_slots::()]: { #[inline] fn index_mut(&mut self, index: usize) -> &mut T { self.get_mut(index).expect("Out of bounds access") @@ -2744,7 +2762,8 @@ impl FromIterator for VecDeque { } #[stable(feature = "rust1", since = "1.0.0")] -impl IntoIterator for VecDeque { +impl IntoIterator for VecDeque +where [(); alloc::co_alloc_metadata_num_slots::()]: { type Item = T; type IntoIter = IntoIter; @@ -2756,7 +2775,8 @@ impl IntoIterator for VecDeque { } #[stable(feature = "rust1", since = "1.0.0")] -impl<'a, T, A: Allocator> IntoIterator for &'a VecDeque { +impl<'a, T, A: Allocator> IntoIterator for &'a VecDeque +where [(); alloc::co_alloc_metadata_num_slots::()]: { type Item = &'a T; type IntoIter = Iter<'a, T>; @@ -2766,7 +2786,8 @@ impl<'a, T, A: Allocator> IntoIterator for &'a VecDeque { } #[stable(feature = "rust1", since = "1.0.0")] -impl<'a, T, A: Allocator> IntoIterator for &'a mut VecDeque { +impl<'a, T, A: Allocator> IntoIterator for &'a mut VecDeque +where [(); alloc::co_alloc_metadata_num_slots::()]: { type Item = &'a mut T; type IntoIter = IterMut<'a, T>; @@ -2776,7 +2797,8 @@ impl<'a, T, A: Allocator> IntoIterator for &'a mut VecDeque { } #[stable(feature = "rust1", since = "1.0.0")] -impl Extend for VecDeque { +impl Extend for VecDeque +where [(); alloc::co_alloc_metadata_num_slots::()]: { fn extend>(&mut self, iter: I) { >::spec_extend(self, iter.into_iter()); } @@ -2793,7 +2815,8 @@ impl Extend for VecDeque { } #[stable(feature = "extend_ref", since = "1.2.0")] -impl<'a, T: 'a + Copy, A: Allocator> Extend<&'a T> for VecDeque { +impl<'a, T: 'a + Copy, A: Allocator> Extend<&'a T> for VecDeque +where [(); alloc::co_alloc_metadata_num_slots::()]: { fn extend>(&mut self, iter: I) { self.spec_extend(iter.into_iter()); } @@ -2810,14 +2833,16 @@ impl<'a, T: 'a + Copy, A: Allocator> Extend<&'a T> for VecDeque { } #[stable(feature = "rust1", since = "1.0.0")] -impl fmt::Debug for VecDeque { +impl fmt::Debug for VecDeque +where [(); alloc::co_alloc_metadata_num_slots::()]: { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_list().entries(self.iter()).finish() } } #[stable(feature = "vecdeque_vec_conversions", since = "1.10.0")] -impl From> for VecDeque { +impl From> for VecDeque +where [(); alloc::co_alloc_metadata_num_slots::()]: { /// Turn a [`Vec`] into a [`VecDeque`]. /// /// [`Vec`]: crate::vec::Vec @@ -2834,7 +2859,8 @@ impl From> for VecDeque { } #[stable(feature = "vecdeque_vec_conversions", since = "1.10.0")] -impl From> for Vec { +impl From> for Vec +where [(); alloc::co_alloc_metadata_num_slots::()]: { /// Turn a [`VecDeque`] into a [`Vec`]. /// /// [`Vec`]: crate::vec::Vec From 4d3b575f9b8fd0f4d38504cf4ddbb973c4b0bdad Mon Sep 17 00:00:00 2001 From: Peter Kehl Date: Sat, 21 Jan 2023 16:01:50 -0800 Subject: [PATCH 007/118] CoAlloc: RawVec + Vec with COOP_PREFERRED. PROBABLY NOT COMPILING, but no ICE. --- library/alloc/src/lib.rs | 7 ++- library/alloc/src/slice.rs | 6 ++- library/alloc/src/vec/drain.rs | 44 ++++++++++++------- library/alloc/src/vec/drain_filter.rs | 9 +++- library/alloc/src/vec/into_iter.rs | 58 ++++++++++++++++--------- library/alloc/src/vec/mod.rs | 57 ++++++++++++++++-------- library/alloc/src/vec/partial_eq.rs | 1 + library/alloc/src/vec/spec_extend.rs | 8 +++- library/alloc/src/vec/spec_from_elem.rs | 16 ++++--- library/alloc/src/vec/splice.rs | 19 +++++--- 10 files changed, 154 insertions(+), 71 deletions(-) diff --git a/library/alloc/src/lib.rs b/library/alloc/src/lib.rs index 0de19c44fb5de..3f3ab5a65d715 100644 --- a/library/alloc/src/lib.rs +++ b/library/alloc/src/lib.rs @@ -184,7 +184,12 @@ #![feature(global_co_alloc)] #![feature(hashmap_internals)] #![feature(lang_items)] -#![feature(min_specialization)] +// When we used min_specialization instead of specialization, library/alloc/src/vec/mod.rs was failing with: +// - cannot specialize on predicate `the constant `core::alloc::co_alloc_metadata_num_slots::()` can be evaluated` +// - cannot specialize on predicate `[(); _] well-formed` +// - cannot specialize on predicate `the constant `core::alloc::co_alloc_metadata_num_slots::()` can be evaluated` +//#![feature(min_specialization)] +#![feature(specialization)] #![feature(negative_impls)] #![feature(never_type)] #![feature(rustc_allow_const_fn_unstable)] diff --git a/library/alloc/src/slice.rs b/library/alloc/src/slice.rs index 6d77615f359b6..edcf4baa528b3 100644 --- a/library/alloc/src/slice.rs +++ b/library/alloc/src/slice.rs @@ -126,11 +126,13 @@ pub(crate) mod hack { #[inline] default fn to_vec(s: &[Self], alloc: A) -> Vec where [(); core::alloc::co_alloc_metadata_num_slots::()]: { - struct DropGuard<'a, T, A: Allocator> { + struct DropGuard<'a, T, A: Allocator> + where [(); core::alloc::co_alloc_metadata_num_slots::()]: { vec: &'a mut Vec, num_init: usize, } - impl<'a, T, A: Allocator> Drop for DropGuard<'a, T, A> { + impl<'a, T, A: Allocator> Drop for DropGuard<'a, T, A> + where [(); core::alloc::co_alloc_metadata_num_slots::()]: { #[inline] fn drop(&mut self) { // SAFETY: diff --git a/library/alloc/src/vec/drain.rs b/library/alloc/src/vec/drain.rs index 2b1a787cc5499..279488fd03450 100644 --- a/library/alloc/src/vec/drain.rs +++ b/library/alloc/src/vec/drain.rs @@ -3,7 +3,7 @@ use core::fmt; use core::iter::{FusedIterator, TrustedLen}; use core::mem::{self, ManuallyDrop, SizedTypeProperties}; use core::ptr::{self, NonNull}; -use core::slice::{self}; +use core::{alloc, slice}; use super::Vec; @@ -23,7 +23,8 @@ pub struct Drain< 'a, T: 'a, #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator + 'a = Global, -> { +> +where [(); alloc::co_alloc_metadata_num_slots::()]: { /// Index of tail to preserve pub(super) tail_start: usize, /// Length of tail @@ -34,13 +35,15 @@ pub struct Drain< } #[stable(feature = "collection_debug", since = "1.17.0")] -impl fmt::Debug for Drain<'_, T, A> { +impl fmt::Debug for Drain<'_, T, A> +where [(); alloc::co_alloc_metadata_num_slots::()]: { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_tuple("Drain").field(&self.iter.as_slice()).finish() } } -impl<'a, T, A: Allocator> Drain<'a, T, A> { +impl<'a, T, A: Allocator> Drain<'a, T, A> +where [(); alloc::co_alloc_metadata_num_slots::()]: { /// Returns the remaining items of this iterator as a slice. /// /// # Examples @@ -139,19 +142,23 @@ impl<'a, T, A: Allocator> Drain<'a, T, A> { } #[stable(feature = "vec_drain_as_slice", since = "1.46.0")] -impl<'a, T, A: Allocator> AsRef<[T]> for Drain<'a, T, A> { +impl<'a, T, A: Allocator> AsRef<[T]> for Drain<'a, T, A> +where [(); alloc::co_alloc_metadata_num_slots::()]: { fn as_ref(&self) -> &[T] { self.as_slice() } } #[stable(feature = "drain", since = "1.6.0")] -unsafe impl Sync for Drain<'_, T, A> {} +unsafe impl Sync for Drain<'_, T, A> +where [(); alloc::co_alloc_metadata_num_slots::()]: {} #[stable(feature = "drain", since = "1.6.0")] -unsafe impl Send for Drain<'_, T, A> {} +unsafe impl Send for Drain<'_, T, A> +where [(); alloc::co_alloc_metadata_num_slots::()]: {} #[stable(feature = "drain", since = "1.6.0")] -impl Iterator for Drain<'_, T, A> { +impl Iterator for Drain<'_, T, A> +where [(); alloc::co_alloc_metadata_num_slots::()]: { type Item = T; #[inline] @@ -165,7 +172,8 @@ impl Iterator for Drain<'_, T, A> { } #[stable(feature = "drain", since = "1.6.0")] -impl DoubleEndedIterator for Drain<'_, T, A> { +impl DoubleEndedIterator for Drain<'_, T, A> +where [(); alloc::co_alloc_metadata_num_slots::()]: { #[inline] fn next_back(&mut self) -> Option { self.iter.next_back().map(|elt| unsafe { ptr::read(elt as *const _) }) @@ -173,12 +181,15 @@ impl DoubleEndedIterator for Drain<'_, T, A> { } #[stable(feature = "drain", since = "1.6.0")] -impl Drop for Drain<'_, T, A> { +impl Drop for Drain<'_, T, A> +where [(); alloc::co_alloc_metadata_num_slots::()]: { fn drop(&mut self) { /// Moves back the un-`Drain`ed elements to restore the original `Vec`. - struct DropGuard<'r, 'a, T, A: Allocator>(&'r mut Drain<'a, T, A>); + struct DropGuard<'r, 'a, T, A: Allocator>(&'r mut Drain<'a, T, A>) + where [(); alloc::co_alloc_metadata_num_slots::()]: ; - impl<'r, 'a, T, A: Allocator> Drop for DropGuard<'r, 'a, T, A> { + impl<'r, 'a, T, A: Allocator> Drop for DropGuard<'r, 'a, T, A> + where [(); alloc::co_alloc_metadata_num_slots::()]: { fn drop(&mut self) { if self.0.tail_len > 0 { unsafe { @@ -242,14 +253,17 @@ impl Drop for Drain<'_, T, A> { } #[stable(feature = "drain", since = "1.6.0")] -impl ExactSizeIterator for Drain<'_, T, A> { +impl ExactSizeIterator for Drain<'_, T, A> +where [(); alloc::co_alloc_metadata_num_slots::()]: { fn is_empty(&self) -> bool { self.iter.is_empty() } } #[unstable(feature = "trusted_len", issue = "37572")] -unsafe impl TrustedLen for Drain<'_, T, A> {} +unsafe impl TrustedLen for Drain<'_, T, A> +where [(); alloc::co_alloc_metadata_num_slots::()]: {} #[stable(feature = "fused", since = "1.26.0")] -impl FusedIterator for Drain<'_, T, A> {} +impl FusedIterator for Drain<'_, T, A> +where [(); alloc::co_alloc_metadata_num_slots::()]: {} diff --git a/library/alloc/src/vec/drain_filter.rs b/library/alloc/src/vec/drain_filter.rs index 8c03f1692d940..d78a81b647d5b 100644 --- a/library/alloc/src/vec/drain_filter.rs +++ b/library/alloc/src/vec/drain_filter.rs @@ -1,7 +1,6 @@ use crate::alloc::{Allocator, Global}; use core::mem::{self, ManuallyDrop}; -use core::ptr; -use core::slice; +use core::{alloc, ptr, slice}; use super::Vec; @@ -27,6 +26,7 @@ pub struct DrainFilter< #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global, > where F: FnMut(&mut T) -> bool, + [(); alloc::co_alloc_metadata_num_slots::()]: { pub(super) vec: &'a mut Vec, /// The index of the item that will be inspected by the next call to `next`. @@ -48,6 +48,7 @@ pub struct DrainFilter< impl DrainFilter<'_, T, F, A> where F: FnMut(&mut T) -> bool, + [(); alloc::co_alloc_metadata_num_slots::()]: { /// Returns a reference to the underlying allocator. #[unstable(feature = "allocator_api", issue = "32838")] @@ -116,6 +117,7 @@ where impl Iterator for DrainFilter<'_, T, F, A> where F: FnMut(&mut T) -> bool, + [(); alloc::co_alloc_metadata_num_slots::()]: { type Item = T; @@ -154,11 +156,13 @@ where impl Drop for DrainFilter<'_, T, F, A> where F: FnMut(&mut T) -> bool, + [(); alloc::co_alloc_metadata_num_slots::()]: { fn drop(&mut self) { struct BackshiftOnDrop<'a, 'b, T, F, A: Allocator> where F: FnMut(&mut T) -> bool, + [(); alloc::co_alloc_metadata_num_slots::()]: { drain: &'b mut DrainFilter<'a, T, F, A>, } @@ -166,6 +170,7 @@ where impl<'a, 'b, T, F, A: Allocator> Drop for BackshiftOnDrop<'a, 'b, T, F, A> where F: FnMut(&mut T) -> bool, + [(); alloc::co_alloc_metadata_num_slots::()]: { fn drop(&mut self) { unsafe { diff --git a/library/alloc/src/vec/into_iter.rs b/library/alloc/src/vec/into_iter.rs index 37966007eb7e4..6c43afd3aeb0e 100644 --- a/library/alloc/src/vec/into_iter.rs +++ b/library/alloc/src/vec/into_iter.rs @@ -4,8 +4,7 @@ use crate::alloc::{Allocator, Global}; #[cfg(not(no_global_oom_handling))] use crate::collections::VecDeque; use crate::raw_vec::RawVec; -use core::array; -use core::fmt; +use core::{alloc, array, fmt}; use core::iter::{ FusedIterator, InPlaceIterable, SourceIter, TrustedLen, TrustedRandomAccessNoCoerce, }; @@ -32,7 +31,8 @@ use core::slice::{self}; pub struct IntoIter< T, #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global, -> { +> +where [(); alloc::co_alloc_metadata_num_slots::()]: { pub(super) buf: NonNull, pub(super) phantom: PhantomData, pub(super) cap: usize, @@ -46,13 +46,15 @@ pub struct IntoIter< } #[stable(feature = "vec_intoiter_debug", since = "1.13.0")] -impl fmt::Debug for IntoIter { +impl fmt::Debug for IntoIter +where [(); alloc::co_alloc_metadata_num_slots::()]: { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_tuple("IntoIter").field(&self.as_slice()).finish() } } -impl IntoIter { +impl IntoIter +where [(); alloc::co_alloc_metadata_num_slots::()]: { /// Returns the remaining items of this iterator as a slice. /// /// # Examples @@ -141,7 +143,8 @@ impl IntoIter { #[cfg(not(no_global_oom_handling))] #[inline] - pub(crate) fn into_vecdeque(self) -> VecDeque { + pub(crate) fn into_vecdeque(self) -> VecDeque + where [(); alloc::co_alloc_metadata_num_slots::()]: { // Keep our `Drop` impl from dropping the elements and the allocator let mut this = ManuallyDrop::new(self); @@ -168,19 +171,23 @@ impl IntoIter { } #[stable(feature = "vec_intoiter_as_ref", since = "1.46.0")] -impl AsRef<[T]> for IntoIter { +impl AsRef<[T]> for IntoIter +where [(); alloc::co_alloc_metadata_num_slots::()]: { fn as_ref(&self) -> &[T] { self.as_slice() } } #[stable(feature = "rust1", since = "1.0.0")] -unsafe impl Send for IntoIter {} +unsafe impl Send for IntoIter +where [(); alloc::co_alloc_metadata_num_slots::()]: {} #[stable(feature = "rust1", since = "1.0.0")] -unsafe impl Sync for IntoIter {} +unsafe impl Sync for IntoIter +where [(); alloc::co_alloc_metadata_num_slots::()]: {} #[stable(feature = "rust1", since = "1.0.0")] -impl Iterator for IntoIter { +impl Iterator for IntoIter +where [(); alloc::co_alloc_metadata_num_slots::()]: { type Item = T; #[inline] @@ -294,7 +301,8 @@ impl Iterator for IntoIter { } #[stable(feature = "rust1", since = "1.0.0")] -impl DoubleEndedIterator for IntoIter { +impl DoubleEndedIterator for IntoIter +where [(); alloc::co_alloc_metadata_num_slots::()]: { #[inline] fn next_back(&mut self) -> Option { if self.end == self.ptr { @@ -335,17 +343,20 @@ impl DoubleEndedIterator for IntoIter { } #[stable(feature = "rust1", since = "1.0.0")] -impl ExactSizeIterator for IntoIter { +impl ExactSizeIterator for IntoIter +where [(); alloc::co_alloc_metadata_num_slots::()]: { fn is_empty(&self) -> bool { self.ptr == self.end } } #[stable(feature = "fused", since = "1.26.0")] -impl FusedIterator for IntoIter {} +impl FusedIterator for IntoIter +where [(); alloc::co_alloc_metadata_num_slots::()]: {} #[unstable(feature = "trusted_len", issue = "37572")] -unsafe impl TrustedLen for IntoIter {} +unsafe impl TrustedLen for IntoIter +where [(); alloc::co_alloc_metadata_num_slots::()]: {} #[doc(hidden)] #[unstable(issue = "none", feature = "std_internals")] @@ -364,13 +375,15 @@ impl NonDrop for T {} unsafe impl TrustedRandomAccessNoCoerce for IntoIter where T: NonDrop, + [(); alloc::co_alloc_metadata_num_slots::()]: { const MAY_HAVE_SIDE_EFFECT: bool = false; } #[cfg(not(no_global_oom_handling))] #[stable(feature = "vec_into_iter_clone", since = "1.8.0")] -impl Clone for IntoIter { +impl Clone for IntoIter +where [(); alloc::co_alloc_metadata_num_slots::()]: { #[cfg(not(test))] fn clone(&self) -> Self { self.as_slice().to_vec_in(self.alloc.deref().clone()).into_iter() @@ -382,11 +395,14 @@ impl Clone for IntoIter { } #[stable(feature = "rust1", since = "1.0.0")] -unsafe impl<#[may_dangle] T, A: Allocator> Drop for IntoIter { +unsafe impl<#[may_dangle] T, A: Allocator> Drop for IntoIter +where [(); alloc::co_alloc_metadata_num_slots::()]: { fn drop(&mut self) { - struct DropGuard<'a, T, A: Allocator>(&'a mut IntoIter); + struct DropGuard<'a, T, A: Allocator>(&'a mut IntoIter) + where [(); alloc::co_alloc_metadata_num_slots::()]: ; - impl Drop for DropGuard<'_, T, A> { + impl Drop for DropGuard<'_, T, A> + where [(); alloc::co_alloc_metadata_num_slots::()]: { fn drop(&mut self) { unsafe { // `IntoIter::alloc` is not used anymore after this and will be dropped by RawVec @@ -410,11 +426,13 @@ unsafe impl<#[may_dangle] T, A: Allocator> Drop for IntoIter { // also refer to the vec::in_place_collect module documentation to get an overview #[unstable(issue = "none", feature = "inplace_iteration")] #[doc(hidden)] -unsafe impl InPlaceIterable for IntoIter {} +unsafe impl InPlaceIterable for IntoIter +where [(); alloc::co_alloc_metadata_num_slots::()]: {} #[unstable(issue = "none", feature = "inplace_iteration")] #[doc(hidden)] -unsafe impl SourceIter for IntoIter { +unsafe impl SourceIter for IntoIter +where [(); alloc::co_alloc_metadata_num_slots::()]: { type Source = Self; #[inline] diff --git a/library/alloc/src/vec/mod.rs b/library/alloc/src/vec/mod.rs index cf1251d13dfd5..970f5b902ef90 100644 --- a/library/alloc/src/vec/mod.rs +++ b/library/alloc/src/vec/mod.rs @@ -2743,7 +2743,8 @@ where [(); core::alloc::co_alloc_metadata_num_slots::()]: { message = "vector indices are of type `usize` or ranges of `usize`", label = "vector indices are of type `usize` or ranges of `usize`" )] -impl, A: Allocator> IndexMut for Vec { +impl, A: Allocator> IndexMut for Vec +where [(); core::alloc::co_alloc_metadata_num_slots::()]: { #[inline] fn index_mut(&mut self, index: I) -> &mut Self::Output { IndexMut::index_mut(&mut **self, index) @@ -2760,7 +2761,8 @@ impl FromIterator for Vec { } #[stable(feature = "rust1", since = "1.0.0")] -impl IntoIterator for Vec { +impl IntoIterator for Vec +where [(); core::alloc::co_alloc_metadata_num_slots::()]: { type Item = T; type IntoIter = IntoIter; @@ -2805,7 +2807,8 @@ impl IntoIterator for Vec { } #[stable(feature = "rust1", since = "1.0.0")] -impl<'a, T, A: Allocator> IntoIterator for &'a Vec { +impl<'a, T, A: Allocator> IntoIterator for &'a Vec +where [(); core::alloc::co_alloc_metadata_num_slots::()]: { type Item = &'a T; type IntoIter = slice::Iter<'a, T>; @@ -2815,7 +2818,8 @@ impl<'a, T, A: Allocator> IntoIterator for &'a Vec { } #[stable(feature = "rust1", since = "1.0.0")] -impl<'a, T, A: Allocator> IntoIterator for &'a mut Vec { +impl<'a, T, A: Allocator> IntoIterator for &'a mut Vec +where [(); core::alloc::co_alloc_metadata_num_slots::()]: { type Item = &'a mut T; type IntoIter = slice::IterMut<'a, T>; @@ -2826,7 +2830,8 @@ impl<'a, T, A: Allocator> IntoIterator for &'a mut Vec { #[cfg(not(no_global_oom_handling))] #[stable(feature = "rust1", since = "1.0.0")] -impl Extend for Vec { +impl Extend for Vec +where [(); core::alloc::co_alloc_metadata_num_slots::()]: { #[inline] fn extend>(&mut self, iter: I) { >::spec_extend(self, iter.into_iter()) @@ -2843,7 +2848,8 @@ impl Extend for Vec { } } -impl Vec { +impl Vec +where [(); core::alloc::co_alloc_metadata_num_slots::()]: { // leaf method to which various SpecFrom/SpecExtend implementations delegate when // they have no further optimizations to apply #[cfg(not(no_global_oom_handling))] @@ -3017,7 +3023,8 @@ impl Vec { /// [`copy_from_slice`]: slice::copy_from_slice #[cfg(not(no_global_oom_handling))] #[stable(feature = "extend_ref", since = "1.2.0")] -impl<'a, T: Copy + 'a, A: Allocator + 'a> Extend<&'a T> for Vec { +impl<'a, T: Copy + 'a, A: Allocator + 'a> Extend<&'a T> for Vec +where [(); core::alloc::co_alloc_metadata_num_slots::()]: { fn extend>(&mut self, iter: I) { self.spec_extend(iter.into_iter()) } @@ -3035,7 +3042,8 @@ impl<'a, T: Copy + 'a, A: Allocator + 'a> Extend<&'a T> for Vec { /// Implements comparison of vectors, [lexicographically](core::cmp::Ord#lexicographical-comparison). #[stable(feature = "rust1", since = "1.0.0")] -impl PartialOrd for Vec { +impl PartialOrd for Vec +where [(); core::alloc::co_alloc_metadata_num_slots::()]: { #[inline] fn partial_cmp(&self, other: &Self) -> Option { PartialOrd::partial_cmp(&**self, &**other) @@ -3043,11 +3051,13 @@ impl PartialOrd for Vec { } #[stable(feature = "rust1", since = "1.0.0")] -impl Eq for Vec {} +impl Eq for Vec +where [(); core::alloc::co_alloc_metadata_num_slots::()]: {} /// Implements ordering of vectors, [lexicographically](core::cmp::Ord#lexicographical-comparison). #[stable(feature = "rust1", since = "1.0.0")] -impl Ord for Vec { +impl Ord for Vec +where [(); core::alloc::co_alloc_metadata_num_slots::()]: { #[inline] fn cmp(&self, other: &Self) -> Ordering { Ord::cmp(&**self, &**other) @@ -3055,7 +3065,8 @@ impl Ord for Vec { } #[stable(feature = "rust1", since = "1.0.0")] -unsafe impl<#[may_dangle] T, A: Allocator> Drop for Vec { +unsafe impl<#[may_dangle] T, A: Allocator> Drop for Vec +where [(); core::alloc::co_alloc_metadata_num_slots::()]: { fn drop(&mut self) { unsafe { // use drop for [T] @@ -3079,35 +3090,40 @@ impl const Default for Vec { } #[stable(feature = "rust1", since = "1.0.0")] -impl fmt::Debug for Vec { +impl fmt::Debug for Vec +where [(); core::alloc::co_alloc_metadata_num_slots::()]: { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fmt::Debug::fmt(&**self, f) } } #[stable(feature = "rust1", since = "1.0.0")] -impl AsRef> for Vec { +impl AsRef> for Vec +where [(); core::alloc::co_alloc_metadata_num_slots::()]: { fn as_ref(&self) -> &Vec { self } } #[stable(feature = "vec_as_mut", since = "1.5.0")] -impl AsMut> for Vec { +impl AsMut> for Vec +where [(); core::alloc::co_alloc_metadata_num_slots::()]: { fn as_mut(&mut self) -> &mut Vec { self } } #[stable(feature = "rust1", since = "1.0.0")] -impl AsRef<[T]> for Vec { +impl AsRef<[T]> for Vec +where [(); core::alloc::co_alloc_metadata_num_slots::()]: { fn as_ref(&self) -> &[T] { self } } #[stable(feature = "vec_as_mut", since = "1.5.0")] -impl AsMut<[T]> for Vec { +impl AsMut<[T]> for Vec +where [(); core::alloc::co_alloc_metadata_num_slots::()]: { fn as_mut(&mut self) -> &mut [T] { self } @@ -3204,7 +3220,8 @@ where // note: test pulls in std, which causes errors here #[cfg(not(test))] #[stable(feature = "vec_from_box", since = "1.18.0")] -impl From> for Vec { +impl From> for Vec +where [(); core::alloc::co_alloc_metadata_num_slots::()]: { /// Convert a boxed slice into a vector by transferring ownership of /// the existing heap allocation. /// @@ -3223,7 +3240,8 @@ impl From> for Vec { #[cfg(not(no_global_oom_handling))] #[cfg(not(test))] #[stable(feature = "box_from_vec", since = "1.20.0")] -impl From> for Box<[T], A> { +impl From> for Box<[T], A> +where [(); core::alloc::co_alloc_metadata_num_slots::()]: { /// Convert a vector into a boxed slice. /// /// If `v` has excess capacity, its items will be moved into a @@ -3263,7 +3281,8 @@ impl From<&str> for Vec { } #[stable(feature = "array_try_from_vec", since = "1.48.0")] -impl TryFrom> for [T; N] { +impl TryFrom> for [T; N] +where [(); core::alloc::co_alloc_metadata_num_slots::()]: { type Error = Vec; /// Gets the entire contents of the `Vec` as an array, diff --git a/library/alloc/src/vec/partial_eq.rs b/library/alloc/src/vec/partial_eq.rs index b0cf72577a1be..b50b9673e1560 100644 --- a/library/alloc/src/vec/partial_eq.rs +++ b/library/alloc/src/vec/partial_eq.rs @@ -1,3 +1,4 @@ +//use core::alloc; use crate::alloc::Allocator; #[cfg(not(no_global_oom_handling))] use crate::borrow::Cow; diff --git a/library/alloc/src/vec/spec_extend.rs b/library/alloc/src/vec/spec_extend.rs index 56065ce565bfc..81245a394b22e 100644 --- a/library/alloc/src/vec/spec_extend.rs +++ b/library/alloc/src/vec/spec_extend.rs @@ -1,3 +1,4 @@ +use core::alloc; use crate::alloc::Allocator; use core::iter::TrustedLen; use core::slice::{self}; @@ -12,6 +13,7 @@ pub(super) trait SpecExtend { impl SpecExtend for Vec where I: Iterator, + [(); alloc::co_alloc_metadata_num_slots::()]: { default fn spec_extend(&mut self, iter: I) { self.extend_desugared(iter) @@ -21,13 +23,15 @@ where impl SpecExtend for Vec where I: TrustedLen, + [(); alloc::co_alloc_metadata_num_slots::()]: { default fn spec_extend(&mut self, iterator: I) { self.extend_trusted(iterator) } } -impl SpecExtend> for Vec { +impl SpecExtend> for Vec +where [(); alloc::co_alloc_metadata_num_slots::()]: { fn spec_extend(&mut self, mut iterator: IntoIter) { unsafe { self.append_elements(iterator.as_slice() as _); @@ -40,6 +44,7 @@ impl<'a, T: 'a, I, A: Allocator + 'a> SpecExtend<&'a T, I> for Vec where I: Iterator, T: Clone, + [(); alloc::co_alloc_metadata_num_slots::()]: { default fn spec_extend(&mut self, iterator: I) { self.spec_extend(iterator.cloned()) @@ -49,6 +54,7 @@ where impl<'a, T: 'a, A: Allocator + 'a> SpecExtend<&'a T, slice::Iter<'a, T>> for Vec where T: Copy, + [(); alloc::co_alloc_metadata_num_slots::()]: { fn spec_extend(&mut self, iterator: slice::Iter<'a, T>) { let slice = iterator.as_slice(); diff --git a/library/alloc/src/vec/spec_from_elem.rs b/library/alloc/src/vec/spec_from_elem.rs index ff364c033ee98..7f95539b12d96 100644 --- a/library/alloc/src/vec/spec_from_elem.rs +++ b/library/alloc/src/vec/spec_from_elem.rs @@ -1,5 +1,6 @@ use core::ptr; +use core::alloc; use crate::alloc::Allocator; use crate::raw_vec::RawVec; @@ -7,11 +8,13 @@ use super::{ExtendElement, IsZero, Vec}; // Specialization trait used for Vec::from_elem pub(super) trait SpecFromElem: Sized { - fn from_elem(elem: Self, n: usize, alloc: A) -> Vec; + fn from_elem(elem: Self, n: usize, alloc: A) -> Vec + where [(); alloc::co_alloc_metadata_num_slots::()]: ; } impl SpecFromElem for T { - default fn from_elem(elem: Self, n: usize, alloc: A) -> Vec { + default fn from_elem(elem: Self, n: usize, alloc: A) -> Vec + where [(); alloc::co_alloc_metadata_num_slots::()]: { let mut v = Vec::with_capacity_in(n, alloc); v.extend_with(n, ExtendElement(elem)); v @@ -20,7 +23,8 @@ impl SpecFromElem for T { impl SpecFromElem for T { #[inline] - default fn from_elem(elem: T, n: usize, alloc: A) -> Vec { + default fn from_elem(elem: T, n: usize, alloc: A) -> Vec + where [(); alloc::co_alloc_metadata_num_slots::()]: { if elem.is_zero() { return Vec { buf: RawVec::with_capacity_zeroed_in(n, alloc), len: n }; } @@ -32,7 +36,8 @@ impl SpecFromElem for T { impl SpecFromElem for i8 { #[inline] - fn from_elem(elem: i8, n: usize, alloc: A) -> Vec { + fn from_elem(elem: i8, n: usize, alloc: A) -> Vec + where [(); alloc::co_alloc_metadata_num_slots::()]: { if elem == 0 { return Vec { buf: RawVec::with_capacity_zeroed_in(n, alloc), len: n }; } @@ -47,7 +52,8 @@ impl SpecFromElem for i8 { impl SpecFromElem for u8 { #[inline] - fn from_elem(elem: u8, n: usize, alloc: A) -> Vec { + fn from_elem(elem: u8, n: usize, alloc: A) -> Vec + where [(); alloc::co_alloc_metadata_num_slots::()]: { if elem == 0 { return Vec { buf: RawVec::with_capacity_zeroed_in(n, alloc), len: n }; } diff --git a/library/alloc/src/vec/splice.rs b/library/alloc/src/vec/splice.rs index 1861147fe72fb..631d9d5e3aa60 100644 --- a/library/alloc/src/vec/splice.rs +++ b/library/alloc/src/vec/splice.rs @@ -1,3 +1,4 @@ +use core::alloc; use crate::alloc::{Allocator, Global}; use core::ptr::{self}; use core::slice::{self}; @@ -22,13 +23,15 @@ pub struct Splice< 'a, I: Iterator + 'a, #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator + 'a = Global, -> { +> +where [(); core::alloc::co_alloc_metadata_num_slots::()]: { pub(super) drain: Drain<'a, I::Item, A>, pub(super) replace_with: I, } #[stable(feature = "vec_splice", since = "1.21.0")] -impl Iterator for Splice<'_, I, A> { +impl Iterator for Splice<'_, I, A> +where [(); core::alloc::co_alloc_metadata_num_slots::()]: { type Item = I::Item; fn next(&mut self) -> Option { @@ -41,17 +44,20 @@ impl Iterator for Splice<'_, I, A> { } #[stable(feature = "vec_splice", since = "1.21.0")] -impl DoubleEndedIterator for Splice<'_, I, A> { +impl DoubleEndedIterator for Splice<'_, I, A> +where [(); alloc::co_alloc_metadata_num_slots::()]: { fn next_back(&mut self) -> Option { self.drain.next_back() } } #[stable(feature = "vec_splice", since = "1.21.0")] -impl ExactSizeIterator for Splice<'_, I, A> {} +impl ExactSizeIterator for Splice<'_, I, A> +where [(); alloc::co_alloc_metadata_num_slots::()]: {} #[stable(feature = "vec_splice", since = "1.21.0")] -impl Drop for Splice<'_, I, A> { +impl Drop for Splice<'_, I, A> +where [(); alloc::co_alloc_metadata_num_slots::()]: { fn drop(&mut self) { self.drain.by_ref().for_each(drop); // At this point draining is done and the only remaining tasks are splicing @@ -98,7 +104,8 @@ impl Drop for Splice<'_, I, A> { } /// Private helper methods for `Splice::drop` -impl Drain<'_, T, A> { +impl Drain<'_, T, A> +where [(); alloc::co_alloc_metadata_num_slots::()]: { /// The range from `self.vec.len` to `self.tail_start` contains elements /// that have been moved out. /// Fill that range as much as possible with new elements from the `replace_with` iterator. From c96efc40fee3ceb745f327e0eacd93723a4e62ca Mon Sep 17 00:00:00 2001 From: Peter Kehl Date: Sat, 21 Jan 2023 16:03:01 -0800 Subject: [PATCH 008/118] VecDeque with COOP_PREFERRED. PROBABLY NOT COMPILING, but no ICE. --- .../alloc/src/collections/vec_deque/drain.rs | 38 ++++++++++++------- .../src/collections/vec_deque/into_iter.rs | 26 ++++++++----- .../alloc/src/collections/vec_deque/mod.rs | 3 +- .../src/collections/vec_deque/spec_extend.rs | 13 ++++++- 4 files changed, 55 insertions(+), 25 deletions(-) diff --git a/library/alloc/src/collections/vec_deque/drain.rs b/library/alloc/src/collections/vec_deque/drain.rs index 89feb361ddc11..e4f2f80892504 100644 --- a/library/alloc/src/collections/vec_deque/drain.rs +++ b/library/alloc/src/collections/vec_deque/drain.rs @@ -2,7 +2,7 @@ use core::iter::FusedIterator; use core::marker::PhantomData; use core::mem::{self, SizedTypeProperties}; use core::ptr::NonNull; -use core::{fmt, ptr}; +use core::{alloc, fmt, ptr}; use crate::alloc::{Allocator, Global}; @@ -19,7 +19,8 @@ pub struct Drain< 'a, T: 'a, #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global, -> { +> +where [(); alloc::co_alloc_metadata_num_slots::()]: { // We can't just use a &mut VecDeque, as that would make Drain invariant over T // and we want it to be covariant instead deque: NonNull>, @@ -34,7 +35,8 @@ pub struct Drain< _marker: PhantomData<&'a T>, } -impl<'a, T, A: Allocator> Drain<'a, T, A> { +impl<'a, T, A: Allocator> Drain<'a, T, A> +where [(); alloc::co_alloc_metadata_num_slots::()]: { pub(super) unsafe fn new( deque: &'a mut VecDeque, drain_start: usize, @@ -88,7 +90,8 @@ impl<'a, T, A: Allocator> Drain<'a, T, A> { } #[stable(feature = "collection_debug", since = "1.17.0")] -impl fmt::Debug for Drain<'_, T, A> { +impl fmt::Debug for Drain<'_, T, A> +where [(); alloc::co_alloc_metadata_num_slots::()]: { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_tuple("Drain") .field(&self.drain_len) @@ -100,16 +103,21 @@ impl fmt::Debug for Drain<'_, T, A> { } #[stable(feature = "drain", since = "1.6.0")] -unsafe impl Sync for Drain<'_, T, A> {} +unsafe impl Sync for Drain<'_, T, A> +where [(); alloc::co_alloc_metadata_num_slots::()]: {} #[stable(feature = "drain", since = "1.6.0")] -unsafe impl Send for Drain<'_, T, A> {} +unsafe impl Send for Drain<'_, T, A> +where [(); alloc::co_alloc_metadata_num_slots::()]: {} #[stable(feature = "drain", since = "1.6.0")] -impl Drop for Drain<'_, T, A> { +impl Drop for Drain<'_, T, A> +where [(); alloc::co_alloc_metadata_num_slots::()]: { fn drop(&mut self) { - struct DropGuard<'r, 'a, T, A: Allocator>(&'r mut Drain<'a, T, A>); + struct DropGuard<'r, 'a, T, A: Allocator> (&'r mut Drain<'a, T, A>) + where [(); alloc::co_alloc_metadata_num_slots::()]:; - impl<'r, 'a, T, A: Allocator> Drop for DropGuard<'r, 'a, T, A> { + impl<'r, 'a, T, A: Allocator> Drop for DropGuard<'r, 'a, T, A> + where [(); alloc::co_alloc_metadata_num_slots::()]: { fn drop(&mut self) { if self.0.remaining != 0 { unsafe { @@ -190,7 +198,8 @@ impl Drop for Drain<'_, T, A> { } #[stable(feature = "drain", since = "1.6.0")] -impl Iterator for Drain<'_, T, A> { +impl Iterator for Drain<'_, T, A> +where [(); alloc::co_alloc_metadata_num_slots::()]: { type Item = T; #[inline] @@ -212,7 +221,8 @@ impl Iterator for Drain<'_, T, A> { } #[stable(feature = "drain", since = "1.6.0")] -impl DoubleEndedIterator for Drain<'_, T, A> { +impl DoubleEndedIterator for Drain<'_, T, A> +where [(); alloc::co_alloc_metadata_num_slots::()]: { #[inline] fn next_back(&mut self) -> Option { if self.remaining == 0 { @@ -225,7 +235,9 @@ impl DoubleEndedIterator for Drain<'_, T, A> { } #[stable(feature = "drain", since = "1.6.0")] -impl ExactSizeIterator for Drain<'_, T, A> {} +impl ExactSizeIterator for Drain<'_, T, A> +where [(); alloc::co_alloc_metadata_num_slots::()]: {} #[stable(feature = "fused", since = "1.26.0")] -impl FusedIterator for Drain<'_, T, A> {} +impl FusedIterator for Drain<'_, T, A> +where [(); alloc::co_alloc_metadata_num_slots::()]: {} diff --git a/library/alloc/src/collections/vec_deque/into_iter.rs b/library/alloc/src/collections/vec_deque/into_iter.rs index 34bc0ce9177c4..c5c1d17bc62dd 100644 --- a/library/alloc/src/collections/vec_deque/into_iter.rs +++ b/library/alloc/src/collections/vec_deque/into_iter.rs @@ -1,5 +1,5 @@ use core::iter::{FusedIterator, TrustedLen}; -use core::{array, fmt, mem::MaybeUninit, ops::Try, ptr}; +use core::{alloc, array, fmt, mem::MaybeUninit, ops::Try, ptr}; use crate::alloc::{Allocator, Global}; @@ -17,11 +17,13 @@ use super::VecDeque; pub struct IntoIter< T, #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global, -> { +> +where [(); alloc::co_alloc_metadata_num_slots::()]: { inner: VecDeque, } -impl IntoIter { +impl IntoIter +where [(); alloc::co_alloc_metadata_num_slots::()]: { pub(super) fn new(inner: VecDeque) -> Self { IntoIter { inner } } @@ -32,14 +34,16 @@ impl IntoIter { } #[stable(feature = "collection_debug", since = "1.17.0")] -impl fmt::Debug for IntoIter { +impl fmt::Debug for IntoIter +where [(); alloc::co_alloc_metadata_num_slots::()]: { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_tuple("IntoIter").field(&self.inner).finish() } } #[stable(feature = "rust1", since = "1.0.0")] -impl Iterator for IntoIter { +impl Iterator for IntoIter +where [(); alloc::co_alloc_metadata_num_slots::()]: { type Item = T; #[inline] @@ -175,7 +179,8 @@ impl Iterator for IntoIter { } #[stable(feature = "rust1", since = "1.0.0")] -impl DoubleEndedIterator for IntoIter { +impl DoubleEndedIterator for IntoIter +where [(); alloc::co_alloc_metadata_num_slots::()]: { #[inline] fn next_back(&mut self) -> Option { self.inner.pop_back() @@ -245,7 +250,8 @@ impl DoubleEndedIterator for IntoIter { } #[stable(feature = "rust1", since = "1.0.0")] -impl ExactSizeIterator for IntoIter { +impl ExactSizeIterator for IntoIter +where [(); alloc::co_alloc_metadata_num_slots::()]: { #[inline] fn is_empty(&self) -> bool { self.inner.is_empty() @@ -253,7 +259,9 @@ impl ExactSizeIterator for IntoIter { } #[stable(feature = "fused", since = "1.26.0")] -impl FusedIterator for IntoIter {} +impl FusedIterator for IntoIter +where [(); alloc::co_alloc_metadata_num_slots::()]: {} #[unstable(feature = "trusted_len", issue = "37572")] -unsafe impl TrustedLen for IntoIter {} +unsafe impl TrustedLen for IntoIter +where [(); alloc::co_alloc_metadata_num_slots::()]: {} diff --git a/library/alloc/src/collections/vec_deque/mod.rs b/library/alloc/src/collections/vec_deque/mod.rs index 8bdb1a27278ab..d8f821a9048d6 100644 --- a/library/alloc/src/collections/vec_deque/mod.rs +++ b/library/alloc/src/collections/vec_deque/mod.rs @@ -456,7 +456,8 @@ where [(); alloc::co_alloc_metadata_num_slots::()]: { written: usize, } - impl<'a, T, A: Allocator> Drop for Guard<'a, T, A> { + impl<'a, T, A: Allocator> Drop for Guard<'a, T, A> + where [(); alloc::co_alloc_metadata_num_slots::()]: { fn drop(&mut self) { self.deque.len += self.written; } diff --git a/library/alloc/src/collections/vec_deque/spec_extend.rs b/library/alloc/src/collections/vec_deque/spec_extend.rs index dccf40ccb38aa..f6d957fdc03ba 100644 --- a/library/alloc/src/collections/vec_deque/spec_extend.rs +++ b/library/alloc/src/collections/vec_deque/spec_extend.rs @@ -1,5 +1,8 @@ +#![feature(min_specialization)] + use crate::alloc::Allocator; use crate::vec; +use core::alloc; use core::iter::TrustedLen; use core::slice; @@ -13,6 +16,7 @@ pub(super) trait SpecExtend { impl SpecExtend for VecDeque where I: Iterator, + [(); alloc::co_alloc_metadata_num_slots::()]: { default fn spec_extend(&mut self, mut iter: I) { // This function should be the moral equivalent of: @@ -22,7 +26,8 @@ where // } // May only be called if `deque.len() < deque.capacity()` - unsafe fn push_unchecked(deque: &mut VecDeque, element: T) { + unsafe fn push_unchecked(deque: &mut VecDeque, element: T) + where [(); alloc::co_alloc_metadata_num_slots::()]: { // SAFETY: Because of the precondition, it's guaranteed that there is space // in the logical array after the last element. unsafe { deque.buffer_write(deque.to_physical_idx(deque.len), element) }; @@ -52,6 +57,7 @@ where impl SpecExtend for VecDeque where I: TrustedLen, + [(); alloc::co_alloc_metadata_num_slots::()]: { default fn spec_extend(&mut self, iter: I) { // This is the case for a TrustedLen iterator. @@ -84,7 +90,8 @@ where } } -impl SpecExtend> for VecDeque { +impl SpecExtend> for VecDeque +where [(); alloc::co_alloc_metadata_num_slots::()]: { fn spec_extend(&mut self, mut iterator: vec::IntoIter) { let slice = iterator.as_slice(); self.reserve(slice.len()); @@ -101,6 +108,7 @@ impl<'a, T: 'a, I, A: Allocator> SpecExtend<&'a T, I> for VecDeque where I: Iterator, T: Copy, + [(); alloc::co_alloc_metadata_num_slots::()]: { default fn spec_extend(&mut self, iterator: I) { self.spec_extend(iterator.copied()) @@ -110,6 +118,7 @@ where impl<'a, T: 'a, A: Allocator> SpecExtend<&'a T, slice::Iter<'a, T>> for VecDeque where T: Copy, + [(); alloc::co_alloc_metadata_num_slots::()]: { fn spec_extend(&mut self, iterator: slice::Iter<'a, T>) { let slice = iterator.as_slice(); From fb1e72f9b8005463dcb2c85fc8ea9834c819089f Mon Sep 17 00:00:00 2001 From: Peter Kehl Date: Sat, 21 Jan 2023 16:12:17 -0800 Subject: [PATCH 009/118] CoAlloc: RawVec, Vec, Box uses bounds. ICE --- library/alloc/src/boxed.rs | 15 ++- library/alloc/src/lib.rs | 1 + library/alloc/src/raw_vec.rs | 49 ++++---- library/alloc/src/slice.rs | 8 +- library/alloc/src/vec/drain.rs | 55 ++++----- library/alloc/src/vec/drain_filter.rs | 27 +++-- library/alloc/src/vec/into_iter.rs | 76 ++++++------ library/alloc/src/vec/mod.rs | 166 +++++++++++++------------- library/alloc/src/vec/partial_eq.rs | 28 ++--- library/core/src/alloc/mod.rs | 11 ++ 10 files changed, 229 insertions(+), 207 deletions(-) diff --git a/library/alloc/src/boxed.rs b/library/alloc/src/boxed.rs index a563b2587236c..9dc695559a80e 100644 --- a/library/alloc/src/boxed.rs +++ b/library/alloc/src/boxed.rs @@ -146,6 +146,7 @@ #![stable(feature = "rust1", since = "1.0.0")] +use core::alloc; use core::any::Any; use core::async_iter::AsyncIterator; use core::borrow; @@ -698,7 +699,7 @@ impl Box<[T]> { Err(_) => return Err(AllocError), }; let ptr = Global.allocate(layout)?; - Ok(RawVec::from_raw_parts_in(ptr.as_mut_ptr() as *mut _, len, Global).into_box(len)) + Ok(RawVec::::from_raw_parts_in(ptr.as_mut_ptr() as *mut _, len, Global).into_box(len)) } } @@ -730,12 +731,13 @@ impl Box<[T]> { Err(_) => return Err(AllocError), }; let ptr = Global.allocate_zeroed(layout)?; - Ok(RawVec::from_raw_parts_in(ptr.as_mut_ptr() as *mut _, len, Global).into_box(len)) + Ok(RawVec::::from_raw_parts_in(ptr.as_mut_ptr() as *mut _, len, Global).into_box(len)) } } } -impl Box<[T], A> { +impl Box<[T], A> +where [(); core::alloc::co_alloc_metadata_num_slots::()]: { /// Constructs a new boxed slice with uninitialized contents in the provided allocator. /// /// # Examples @@ -763,7 +765,7 @@ impl Box<[T], A> { // #[unstable(feature = "new_uninit", issue = "63291")] #[must_use] pub fn new_uninit_slice_in(len: usize, alloc: A) -> Box<[mem::MaybeUninit], A> { - unsafe { RawVec::with_capacity_in(len, alloc).into_box(len) } + unsafe { RawVec::::with_capacity_in(len, alloc).into_box(len) } } /// Constructs a new boxed slice with uninitialized contents in the provided allocator, @@ -791,7 +793,7 @@ impl Box<[T], A> { // #[unstable(feature = "new_uninit", issue = "63291")] #[must_use] pub fn new_zeroed_slice_in(len: usize, alloc: A) -> Box<[mem::MaybeUninit], A> { - unsafe { RawVec::with_capacity_zeroed_in(len, alloc).into_box(len) } + unsafe { RawVec::::with_capacity_zeroed_in(len, alloc).into_box(len) } } } @@ -2019,7 +2021,8 @@ impl FromIterator for Box<[I]> { #[cfg(not(no_global_oom_handling))] #[stable(feature = "box_slice_clone", since = "1.3.0")] -impl Clone for Box<[T], A> { +impl Clone for Box<[T], A> +where [(); core::alloc::co_alloc_metadata_num_slots::()]: { fn clone(&self) -> Self { let alloc = Box::allocator(self).clone(); self.to_vec_in(alloc).into_boxed_slice() diff --git a/library/alloc/src/lib.rs b/library/alloc/src/lib.rs index 3f3ab5a65d715..64c4d7fb4ee6f 100644 --- a/library/alloc/src/lib.rs +++ b/library/alloc/src/lib.rs @@ -182,6 +182,7 @@ #![feature(fundamental)] #![cfg_attr(not(test), feature(generator_trait))] #![feature(global_co_alloc)] +#![feature(global_co_alloc_short_term_pref)] #![feature(hashmap_internals)] #![feature(lang_items)] // When we used min_specialization instead of specialization, library/alloc/src/vec/mod.rs was failing with: diff --git a/library/alloc/src/raw_vec.rs b/library/alloc/src/raw_vec.rs index 7b98fadc713de..cdbd688bcd5a6 100644 --- a/library/alloc/src/raw_vec.rs +++ b/library/alloc/src/raw_vec.rs @@ -1,6 +1,6 @@ #![unstable(feature = "raw_vec_internals", reason = "unstable const warnings", issue = "none")] -use core::alloc::{self, LayoutError, GlobalCoAllocMeta}; +use core::alloc::{self, LayoutError, GlobalCoAllocMeta, PtrAndMeta}; use core::cmp; use core::intrinsics; use core::mem::{self, ManuallyDrop, MaybeUninit, SizedTypeProperties}; @@ -49,11 +49,9 @@ enum AllocInit { /// `usize::MAX`. This means that you need to be careful when round-tripping this type with a /// `Box<[T]>`, since `capacity()` won't yield the length. #[allow(missing_debug_implementations)] -// @TODO -// 1. make const generic _coop come from the target specification -// 2. apply `_coop` with logical && to `A::IsCoAllocator` -pub(crate) struct RawVec -where [(); alloc::co_alloc_metadata_num_slots::()]: +// @TODO apply `_coop` with logical && to `A::IsCoAllocator` +pub(crate) struct RawVec +where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { ptr: Unique, cap: usize, @@ -61,7 +59,7 @@ where [(); alloc::co_alloc_metadata_num_slots::()]: // As of v1.67.0, `cmp` for `TypeId` is not `const`, unfortunately: //pub(crate) meta: [GlobalCoAllocMeta; {if core::any::TypeId::of::()==core::any::TypeId::of::() {1} else {0}}], //pub(crate) meta: [GlobalCoAllocMeta; mem::size_of::()], - pub(crate) meta: [GlobalCoAllocMeta; alloc::co_alloc_metadata_num_slots::()], + pub(crate) metas: [GlobalCoAllocMeta; alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)], } impl RawVec { @@ -111,8 +109,8 @@ impl RawVec { } } -impl RawVec -where [(); alloc::co_alloc_metadata_num_slots::()]: +impl RawVec +where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { // Tiny Vecs are dumb. Skip to: // - 8 if the element size is 1, because any heap allocators is likely @@ -131,7 +129,8 @@ where [(); alloc::co_alloc_metadata_num_slots::()]: /// the returned `RawVec`. pub const fn new_in(alloc: A) -> Self { // `cap: 0` means "unallocated". zero-sized types are ignored. - Self { ptr: Unique::dangling(), cap: 0, alloc, meta: GlobalCoAllocMeta {/*one: 1*/ /* , two: 2, three: 3, four: 4*/} } + Self { ptr: Unique::dangling(), cap: 0, alloc, + metas: [GlobalCoAllocMeta {/*one: 1*/ /* , two: 2, three: 3, four: 4*/}; alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)] } } /// Like `with_capacity`, but parameterized over the choice of @@ -208,7 +207,7 @@ where [(); alloc::co_alloc_metadata_num_slots::()]: ptr: unsafe { Unique::new_unchecked(ptr.cast().as_ptr()) }, cap: capacity, alloc, - meta: GlobalCoAllocMeta {/*one: 1*/ /*, two: 2, three: 3, four: 4*/} + metas: [GlobalCoAllocMeta {/*one: 1*/ /*, two: 2, three: 3, four: 4*/}; alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)] } } } @@ -225,7 +224,7 @@ where [(); alloc::co_alloc_metadata_num_slots::()]: /// guaranteed. #[inline] pub unsafe fn from_raw_parts_in(ptr: *mut T, capacity: usize, alloc: A) -> Self { - Self { ptr: unsafe { Unique::new_unchecked(ptr) }, cap: capacity, alloc, meta: GlobalCoAllocMeta {/*one: 1*/ /*, two: 2, three: 3, four: 4*/} } + Self { ptr: unsafe { Unique::new_unchecked(ptr) }, cap: capacity, alloc, metas: [GlobalCoAllocMeta {/*one: 1*/ /*, two: 2, three: 3, four: 4*/}; alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)] } } /// Gets a raw pointer to the start of the allocation. Note that this is @@ -294,12 +293,12 @@ where [(); alloc::co_alloc_metadata_num_slots::()]: // handle_reserve behind a call, while making sure that this function is likely to be // inlined as just a comparison and a call if the comparison fails. #[cold] - fn do_reserve_and_handle( - slf: &mut RawVec, + fn do_reserve_and_handle( + slf: &mut RawVec, len: usize, additional: usize, ) - where [(); alloc::co_alloc_metadata_num_slots::()]: + where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { handle_reserve(slf.grow_amortized(len, additional)); } @@ -373,8 +372,8 @@ where [(); alloc::co_alloc_metadata_num_slots::()]: } } -impl RawVec -where [(); alloc::co_alloc_metadata_num_slots::()]: +impl RawVec +where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { /// Returns if the buffer needs to grow to fulfill the needed extra capacity. /// Mainly used to make inlining reserve-calls possible without inlining `grow`. @@ -497,19 +496,25 @@ where memory.map_err(|_| AllocError { layout: new_layout, non_exhaustive: () }.into()) } -unsafe impl<#[may_dangle] T, A: Allocator> Drop for RawVec -where [(); alloc::co_alloc_metadata_num_slots::()]: +unsafe impl<#[may_dangle] T, A: Allocator, const COOP_PREFERRED: bool> Drop for RawVec +where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { /// Frees the memory owned by the `RawVec` *without* trying to drop its contents. default fn drop(&mut self) { if let Some((ptr, layout)) = self.current_memory() { - unsafe { self.alloc.co_deallocate(ptr, layout) } + if A::IS_CO_ALLOCATOR && COOP_PREFERRED { + let meta = self.metas[0]; + unsafe { self.alloc.co_deallocate(PtrAndMeta {ptr, meta}, layout) } + } else { + unsafe { self.alloc.deallocate(ptr, layout) } + } } } } // @TODO Custom -/*unsafe impl<#[may_dangle] T> Drop for RawVec { +unsafe impl<#[may_dangle] T, const COOP_PREFERRED: bool> Drop for RawVec +where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { /// Frees the memory owned by the `RawVec` *without* trying to drop its contents. fn drop(&mut self) { // @TODO @@ -517,7 +522,7 @@ where [(); alloc::co_alloc_metadata_num_slots::()]: unsafe { self.alloc.deallocate(ptr, layout) } } } -}*/ +} // Central function for reserve error handling. #[cfg(not(no_global_oom_handling))] diff --git a/library/alloc/src/slice.rs b/library/alloc/src/slice.rs index edcf4baa528b3..c93246c67abaa 100644 --- a/library/alloc/src/slice.rs +++ b/library/alloc/src/slice.rs @@ -778,16 +778,16 @@ impl> Join<&[T]> for [V] { //////////////////////////////////////////////////////////////////////////////// #[stable(feature = "rust1", since = "1.0.0")] -impl Borrow<[T]> for Vec -where [(); core::alloc::co_alloc_metadata_num_slots::()]: { +impl Borrow<[T]> for Vec +where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { fn borrow(&self) -> &[T] { &self[..] } } #[stable(feature = "rust1", since = "1.0.0")] -impl BorrowMut<[T]> for Vec -where [(); core::alloc::co_alloc_metadata_num_slots::()]: { +impl BorrowMut<[T]> for Vec +where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { fn borrow_mut(&mut self) -> &mut [T] { &mut self[..] } diff --git a/library/alloc/src/vec/drain.rs b/library/alloc/src/vec/drain.rs index 279488fd03450..6372333bda81d 100644 --- a/library/alloc/src/vec/drain.rs +++ b/library/alloc/src/vec/drain.rs @@ -23,8 +23,9 @@ pub struct Drain< 'a, T: 'a, #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator + 'a = Global, + const COOP_PREFERRED: bool = {alloc::SHORT_TERM_VEC_PREFERS_COOP} > -where [(); alloc::co_alloc_metadata_num_slots::()]: { +where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { /// Index of tail to preserve pub(super) tail_start: usize, /// Length of tail @@ -35,15 +36,15 @@ where [(); alloc::co_alloc_metadata_num_slots::()]: { } #[stable(feature = "collection_debug", since = "1.17.0")] -impl fmt::Debug for Drain<'_, T, A> -where [(); alloc::co_alloc_metadata_num_slots::()]: { +impl fmt::Debug for Drain<'_, T, A, COOP_PREFERRED> +where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_tuple("Drain").field(&self.iter.as_slice()).finish() } } -impl<'a, T, A: Allocator> Drain<'a, T, A> -where [(); alloc::co_alloc_metadata_num_slots::()]: { +impl<'a, T, A: Allocator, const COOP_PREFERRED: bool> Drain<'a, T, A, COOP_PREFERRED> +where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { /// Returns the remaining items of this iterator as a slice. /// /// # Examples @@ -142,23 +143,23 @@ where [(); alloc::co_alloc_metadata_num_slots::()]: { } #[stable(feature = "vec_drain_as_slice", since = "1.46.0")] -impl<'a, T, A: Allocator> AsRef<[T]> for Drain<'a, T, A> -where [(); alloc::co_alloc_metadata_num_slots::()]: { +impl<'a, T, A: Allocator, const COOP_PREFERRED: bool> AsRef<[T]> for Drain<'a, T, A, COOP_PREFERRED> +where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { fn as_ref(&self) -> &[T] { self.as_slice() } } #[stable(feature = "drain", since = "1.6.0")] -unsafe impl Sync for Drain<'_, T, A> -where [(); alloc::co_alloc_metadata_num_slots::()]: {} +unsafe impl Sync for Drain<'_, T, A, COOP_PREFERRED> +where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: {} #[stable(feature = "drain", since = "1.6.0")] -unsafe impl Send for Drain<'_, T, A> -where [(); alloc::co_alloc_metadata_num_slots::()]: {} +unsafe impl Send for Drain<'_, T, A, COOP_PREFERRED> +where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: {} #[stable(feature = "drain", since = "1.6.0")] -impl Iterator for Drain<'_, T, A> -where [(); alloc::co_alloc_metadata_num_slots::()]: { +impl Iterator for Drain<'_, T, A, COOP_PREFERRED> +where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { type Item = T; #[inline] @@ -172,8 +173,8 @@ where [(); alloc::co_alloc_metadata_num_slots::()]: { } #[stable(feature = "drain", since = "1.6.0")] -impl DoubleEndedIterator for Drain<'_, T, A> -where [(); alloc::co_alloc_metadata_num_slots::()]: { +impl DoubleEndedIterator for Drain<'_, T, A, COOP_PREFERRED> +where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { #[inline] fn next_back(&mut self) -> Option { self.iter.next_back().map(|elt| unsafe { ptr::read(elt as *const _) }) @@ -181,15 +182,15 @@ where [(); alloc::co_alloc_metadata_num_slots::()]: { } #[stable(feature = "drain", since = "1.6.0")] -impl Drop for Drain<'_, T, A> -where [(); alloc::co_alloc_metadata_num_slots::()]: { +impl Drop for Drain<'_, T, A, COOP_PREFERRED> +where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { fn drop(&mut self) { /// Moves back the un-`Drain`ed elements to restore the original `Vec`. - struct DropGuard<'r, 'a, T, A: Allocator>(&'r mut Drain<'a, T, A>) - where [(); alloc::co_alloc_metadata_num_slots::()]: ; + struct DropGuard<'r, 'a, T, A: Allocator, const COOP_PREFERRED: bool>(&'r mut Drain<'a, T, A, COOP_PREFERRED>) + where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: ; - impl<'r, 'a, T, A: Allocator> Drop for DropGuard<'r, 'a, T, A> - where [(); alloc::co_alloc_metadata_num_slots::()]: { + impl<'r, 'a, T, A: Allocator, const COOP_PREFERRED: bool> Drop for DropGuard<'r, 'a, T, A, COOP_PREFERRED> + where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { fn drop(&mut self) { if self.0.tail_len > 0 { unsafe { @@ -253,17 +254,17 @@ where [(); alloc::co_alloc_metadata_num_slots::()]: { } #[stable(feature = "drain", since = "1.6.0")] -impl ExactSizeIterator for Drain<'_, T, A> -where [(); alloc::co_alloc_metadata_num_slots::()]: { +impl ExactSizeIterator for Drain<'_, T, A, COOP_PREFERRED> +where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { fn is_empty(&self) -> bool { self.iter.is_empty() } } #[unstable(feature = "trusted_len", issue = "37572")] -unsafe impl TrustedLen for Drain<'_, T, A> -where [(); alloc::co_alloc_metadata_num_slots::()]: {} +unsafe impl TrustedLen for Drain<'_, T, A, COOP_PREFERRED> +where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: {} #[stable(feature = "fused", since = "1.26.0")] -impl FusedIterator for Drain<'_, T, A> -where [(); alloc::co_alloc_metadata_num_slots::()]: {} +impl FusedIterator for Drain<'_, T, A, COOP_PREFERRED> +where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: {} diff --git a/library/alloc/src/vec/drain_filter.rs b/library/alloc/src/vec/drain_filter.rs index d78a81b647d5b..7be4abacbec96 100644 --- a/library/alloc/src/vec/drain_filter.rs +++ b/library/alloc/src/vec/drain_filter.rs @@ -24,11 +24,12 @@ pub struct DrainFilter< T, F, #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global, + const COOP_PREFERRED: bool = true > where F: FnMut(&mut T) -> bool, - [(); alloc::co_alloc_metadata_num_slots::()]: + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { - pub(super) vec: &'a mut Vec, + pub(super) vec: &'a mut Vec, /// The index of the item that will be inspected by the next call to `next`. pub(super) idx: usize, /// The number of items that have been drained (removed) thus far. @@ -45,10 +46,10 @@ pub struct DrainFilter< pub(super) panic_flag: bool, } -impl DrainFilter<'_, T, F, A> +impl DrainFilter<'_, T, F, A, COOP_PREFERRED> where F: FnMut(&mut T) -> bool, - [(); alloc::co_alloc_metadata_num_slots::()]: + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { /// Returns a reference to the underlying allocator. #[unstable(feature = "allocator_api", issue = "32838")] @@ -114,10 +115,10 @@ where } #[unstable(feature = "drain_filter", reason = "recently added", issue = "43244")] -impl Iterator for DrainFilter<'_, T, F, A> +impl Iterator for DrainFilter<'_, T, F, A, COOP_PREFERRED> where F: FnMut(&mut T) -> bool, - [(); alloc::co_alloc_metadata_num_slots::()]: + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { type Item = T; @@ -153,24 +154,24 @@ where } #[unstable(feature = "drain_filter", reason = "recently added", issue = "43244")] -impl Drop for DrainFilter<'_, T, F, A> +impl Drop for DrainFilter<'_, T, F, A, COOP_PREFERRED> where F: FnMut(&mut T) -> bool, - [(); alloc::co_alloc_metadata_num_slots::()]: + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { fn drop(&mut self) { - struct BackshiftOnDrop<'a, 'b, T, F, A: Allocator> + struct BackshiftOnDrop<'a, 'b, T, F, A: Allocator, const COOP_PREFERRED: bool> where F: FnMut(&mut T) -> bool, - [(); alloc::co_alloc_metadata_num_slots::()]: + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { - drain: &'b mut DrainFilter<'a, T, F, A>, + drain: &'b mut DrainFilter<'a, T, F, A, COOP_PREFERRED>, } - impl<'a, 'b, T, F, A: Allocator> Drop for BackshiftOnDrop<'a, 'b, T, F, A> + impl<'a, 'b, T, F, A: Allocator, const COOP_PREFERRED: bool> Drop for BackshiftOnDrop<'a, 'b, T, F, A, COOP_PREFERRED> where F: FnMut(&mut T) -> bool, - [(); alloc::co_alloc_metadata_num_slots::()]: + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { fn drop(&mut self) { unsafe { diff --git a/library/alloc/src/vec/into_iter.rs b/library/alloc/src/vec/into_iter.rs index 6c43afd3aeb0e..fdad67de09716 100644 --- a/library/alloc/src/vec/into_iter.rs +++ b/library/alloc/src/vec/into_iter.rs @@ -31,8 +31,9 @@ use core::slice::{self}; pub struct IntoIter< T, #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global, + const COOP_PREFERRED: bool = {alloc::SHORT_TERM_VEC_PREFERS_COOP} > -where [(); alloc::co_alloc_metadata_num_slots::()]: { +where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { pub(super) buf: NonNull, pub(super) phantom: PhantomData, pub(super) cap: usize, @@ -46,15 +47,15 @@ where [(); alloc::co_alloc_metadata_num_slots::()]: { } #[stable(feature = "vec_intoiter_debug", since = "1.13.0")] -impl fmt::Debug for IntoIter -where [(); alloc::co_alloc_metadata_num_slots::()]: { +impl fmt::Debug for IntoIter +where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_tuple("IntoIter").field(&self.as_slice()).finish() } } -impl IntoIter -where [(); alloc::co_alloc_metadata_num_slots::()]: { +impl IntoIter +where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { /// Returns the remaining items of this iterator as a slice. /// /// # Examples @@ -143,8 +144,7 @@ where [(); alloc::co_alloc_metadata_num_slots::()]: { #[cfg(not(no_global_oom_handling))] #[inline] - pub(crate) fn into_vecdeque(self) -> VecDeque - where [(); alloc::co_alloc_metadata_num_slots::()]: { + pub(crate) fn into_vecdeque(self) -> VecDeque { // Keep our `Drop` impl from dropping the elements and the allocator let mut this = ManuallyDrop::new(self); @@ -171,23 +171,23 @@ where [(); alloc::co_alloc_metadata_num_slots::()]: { } #[stable(feature = "vec_intoiter_as_ref", since = "1.46.0")] -impl AsRef<[T]> for IntoIter -where [(); alloc::co_alloc_metadata_num_slots::()]: { +impl AsRef<[T]> for IntoIter +where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { fn as_ref(&self) -> &[T] { self.as_slice() } } #[stable(feature = "rust1", since = "1.0.0")] -unsafe impl Send for IntoIter -where [(); alloc::co_alloc_metadata_num_slots::()]: {} +unsafe impl Send for IntoIter +where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: {} #[stable(feature = "rust1", since = "1.0.0")] -unsafe impl Sync for IntoIter -where [(); alloc::co_alloc_metadata_num_slots::()]: {} +unsafe impl Sync for IntoIter +where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: {} #[stable(feature = "rust1", since = "1.0.0")] -impl Iterator for IntoIter -where [(); alloc::co_alloc_metadata_num_slots::()]: { +impl Iterator for IntoIter +where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { type Item = T; #[inline] @@ -301,8 +301,8 @@ where [(); alloc::co_alloc_metadata_num_slots::()]: { } #[stable(feature = "rust1", since = "1.0.0")] -impl DoubleEndedIterator for IntoIter -where [(); alloc::co_alloc_metadata_num_slots::()]: { +impl DoubleEndedIterator for IntoIter +where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { #[inline] fn next_back(&mut self) -> Option { if self.end == self.ptr { @@ -343,20 +343,20 @@ where [(); alloc::co_alloc_metadata_num_slots::()]: { } #[stable(feature = "rust1", since = "1.0.0")] -impl ExactSizeIterator for IntoIter -where [(); alloc::co_alloc_metadata_num_slots::()]: { +impl ExactSizeIterator for IntoIter +where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { fn is_empty(&self) -> bool { self.ptr == self.end } } #[stable(feature = "fused", since = "1.26.0")] -impl FusedIterator for IntoIter -where [(); alloc::co_alloc_metadata_num_slots::()]: {} +impl FusedIterator for IntoIter +where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: {} #[unstable(feature = "trusted_len", issue = "37572")] -unsafe impl TrustedLen for IntoIter -where [(); alloc::co_alloc_metadata_num_slots::()]: {} +unsafe impl TrustedLen for IntoIter +where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: {} #[doc(hidden)] #[unstable(issue = "none", feature = "std_internals")] @@ -372,18 +372,18 @@ impl NonDrop for T {} #[unstable(issue = "none", feature = "std_internals")] // TrustedRandomAccess (without NoCoerce) must not be implemented because // subtypes/supertypes of `T` might not be `NonDrop` -unsafe impl TrustedRandomAccessNoCoerce for IntoIter +unsafe impl TrustedRandomAccessNoCoerce for IntoIter where T: NonDrop, - [(); alloc::co_alloc_metadata_num_slots::()]: + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { const MAY_HAVE_SIDE_EFFECT: bool = false; } #[cfg(not(no_global_oom_handling))] #[stable(feature = "vec_into_iter_clone", since = "1.8.0")] -impl Clone for IntoIter -where [(); alloc::co_alloc_metadata_num_slots::()]: { +impl Clone for IntoIter +where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { #[cfg(not(test))] fn clone(&self) -> Self { self.as_slice().to_vec_in(self.alloc.deref().clone()).into_iter() @@ -395,20 +395,20 @@ where [(); alloc::co_alloc_metadata_num_slots::()]: { } #[stable(feature = "rust1", since = "1.0.0")] -unsafe impl<#[may_dangle] T, A: Allocator> Drop for IntoIter -where [(); alloc::co_alloc_metadata_num_slots::()]: { +unsafe impl<#[may_dangle] T, A: Allocator, const COOP_PREFERRED: bool> Drop for IntoIter +where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { fn drop(&mut self) { - struct DropGuard<'a, T, A: Allocator>(&'a mut IntoIter) - where [(); alloc::co_alloc_metadata_num_slots::()]: ; + struct DropGuard<'a, T, A: Allocator, const COOP_PREFERRED: bool>(&'a mut IntoIter) + where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: ; - impl Drop for DropGuard<'_, T, A> - where [(); alloc::co_alloc_metadata_num_slots::()]: { + impl Drop for DropGuard<'_, T, A, COOP_PREFERRED> + where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { fn drop(&mut self) { unsafe { // `IntoIter::alloc` is not used anymore after this and will be dropped by RawVec let alloc = ManuallyDrop::take(&mut self.0.alloc); // RawVec handles deallocation - let _ = RawVec::from_raw_parts_in(self.0.buf.as_ptr(), self.0.cap, alloc); + let _ = RawVec::::from_raw_parts_in(self.0.buf.as_ptr(), self.0.cap, alloc); } } } @@ -426,13 +426,13 @@ where [(); alloc::co_alloc_metadata_num_slots::()]: { // also refer to the vec::in_place_collect module documentation to get an overview #[unstable(issue = "none", feature = "inplace_iteration")] #[doc(hidden)] -unsafe impl InPlaceIterable for IntoIter -where [(); alloc::co_alloc_metadata_num_slots::()]: {} +unsafe impl InPlaceIterable for IntoIter +where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: {} #[unstable(issue = "none", feature = "inplace_iteration")] #[doc(hidden)] -unsafe impl SourceIter for IntoIter -where [(); alloc::co_alloc_metadata_num_slots::()]: { +unsafe impl SourceIter for IntoIter +where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { type Source = Self; #[inline] diff --git a/library/alloc/src/vec/mod.rs b/library/alloc/src/vec/mod.rs index 970f5b902ef90..63e75fef0face 100644 --- a/library/alloc/src/vec/mod.rs +++ b/library/alloc/src/vec/mod.rs @@ -398,10 +398,10 @@ mod spec_extend; #[cfg_attr(not(test), rustc_diagnostic_item = "Vec")] #[rustc_insignificant_dtor] // @TODO _coop -pub struct Vec -where [(); core::alloc::co_alloc_metadata_num_slots::()]: +pub struct Vec +where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { - buf: RawVec, + buf: RawVec, len: usize, } @@ -609,8 +609,8 @@ impl Vec { } } -impl Vec -where [(); core::alloc::co_alloc_metadata_num_slots::()]: { +impl Vec +where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { /// Constructs a new, empty `Vec`. /// /// The vector will not allocate until elements are pushed onto it. @@ -1623,16 +1623,16 @@ where [(); core::alloc::co_alloc_metadata_num_slots::()]: { // This drop guard will be invoked when predicate or `drop` of element panicked. // It shifts unchecked elements to cover holes and `set_len` to the correct length. // In cases when predicate and `drop` never panick, it will be optimized out. - struct BackshiftOnDrop<'a, T, A: Allocator> - where [(); core::alloc::co_alloc_metadata_num_slots::()]: { - v: &'a mut Vec, + struct BackshiftOnDrop<'a, T, A: Allocator, const VEC_IS_COOP: bool=true> + where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(VEC_IS_COOP)]: { + v: &'a mut Vec, processed_len: usize, deleted_cnt: usize, original_len: usize, } - impl Drop for BackshiftOnDrop<'_, T, A> - where [(); core::alloc::co_alloc_metadata_num_slots::()]: { + impl Drop for BackshiftOnDrop<'_, T, A, VEC_IS_COOP> + where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(VEC_IS_COOP)]: { fn drop(&mut self) { if self.deleted_cnt > 0 { // SAFETY: Trailing unchecked items must be valid since we never touch them. @@ -1651,15 +1651,15 @@ where [(); core::alloc::co_alloc_metadata_num_slots::()]: { } } - let mut g = BackshiftOnDrop { v: self, processed_len: 0, deleted_cnt: 0, original_len }; + let mut g = BackshiftOnDrop:: { v: self, processed_len: 0, deleted_cnt: 0, original_len }; - fn process_loop( + fn process_loop( original_len: usize, f: &mut F, - g: &mut BackshiftOnDrop<'_, T, A>, + g: &mut BackshiftOnDrop<'_, T, A, VEC_IS_COOP>, ) where F: FnMut(&mut T) -> bool, - [(); core::alloc::co_alloc_metadata_num_slots::()]: + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(VEC_IS_COOP)]: { while g.processed_len != original_len { // SAFETY: Unchecked element must be valid. @@ -1690,10 +1690,10 @@ where [(); core::alloc::co_alloc_metadata_num_slots::()]: { } // Stage 1: Nothing was deleted. - process_loop::(original_len, &mut f, &mut g); + process_loop::(original_len, &mut f, &mut g); // Stage 2: Some elements were deleted. - process_loop::(original_len, &mut f, &mut g); + process_loop::(original_len, &mut f, &mut g); // All item are processed. This can be optimized to `set_len` by LLVM. drop(g); @@ -1752,8 +1752,8 @@ where [(); core::alloc::co_alloc_metadata_num_slots::()]: { } /* INVARIANT: vec.len() > read >= write > write-1 >= 0 */ - struct FillGapOnDrop<'a, T, A: core::alloc::Allocator> - where [(); core::alloc::co_alloc_metadata_num_slots::()]: { + struct FillGapOnDrop<'a, T, A: core::alloc::Allocator, const COOP_PREFERRED: bool> + where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { /* Offset of the element we want to check if it is duplicate */ read: usize, @@ -1762,11 +1762,11 @@ where [(); core::alloc::co_alloc_metadata_num_slots::()]: { write: usize, /* The Vec that would need correction if `same_bucket` panicked */ - vec: &'a mut Vec, + vec: &'a mut Vec, } - impl<'a, T, A: core::alloc::Allocator> Drop for FillGapOnDrop<'a, T, A> - where [(); core::alloc::co_alloc_metadata_num_slots::()]: { + impl<'a, T, A: core::alloc::Allocator, const COOP_PREFERRED: bool> Drop for FillGapOnDrop<'a, T, A, COOP_PREFERRED> + where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { fn drop(&mut self) { /* This code gets executed when `same_bucket` panics */ @@ -2359,8 +2359,8 @@ where [(); core::alloc::co_alloc_metadata_num_slots::()]: { } } -impl Vec -where [(); core::alloc::co_alloc_metadata_num_slots::()]: { +impl Vec +where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { /// Resizes the `Vec` in-place so that `len` is equal to `new_len`. /// /// If `new_len` is greater than `len`, the `Vec` is extended by the @@ -2459,8 +2459,8 @@ where [(); core::alloc::co_alloc_metadata_num_slots::()]: { } } -impl Vec<[T; N], A> -where [(); core::alloc::co_alloc_metadata_num_slots::()]: { +impl Vec<[T; N], A, COOP_PREFERRED> +where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { /// Takes a `Vec<[T; N]>` and flattens it into a `Vec`. /// /// # Panics @@ -2521,8 +2521,8 @@ impl ExtendWith for ExtendElement { } } -impl Vec -where [(); core::alloc::co_alloc_metadata_num_slots::()]: { +impl Vec +where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { #[cfg(not(no_global_oom_handling))] /// Extend the vector by `n` values, using the given generator. fn extend_with>(&mut self, n: usize, mut value: E) { @@ -2554,8 +2554,8 @@ where [(); core::alloc::co_alloc_metadata_num_slots::()]: { } } -impl Vec -where [(); core::alloc::co_alloc_metadata_num_slots::()]: { +impl Vec +where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { /// Removes consecutive repeated elements in the vector according to the /// [`PartialEq`] trait implementation. /// @@ -2591,8 +2591,8 @@ pub fn from_elem(elem: T, n: usize) -> Vec { #[doc(hidden)] #[cfg(not(no_global_oom_handling))] #[unstable(feature = "allocator_api", issue = "32838")] -pub fn from_elem_in(elem: T, n: usize, alloc: A) -> Vec -where [(); core::alloc::co_alloc_metadata_num_slots::()]: { +pub fn from_elem_in(elem: T, n: usize, alloc: A) -> Vec +where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { ::from_elem(elem, n, alloc) } @@ -2604,8 +2604,8 @@ trait ExtendFromWithinSpec { unsafe fn spec_extend_from_within(&mut self, src: Range); } -impl ExtendFromWithinSpec for Vec -where [(); core::alloc::co_alloc_metadata_num_slots::()]: { +impl ExtendFromWithinSpec for Vec +where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { default unsafe fn spec_extend_from_within(&mut self, src: Range) { // SAFETY: // - len is increased only after initializing elements @@ -2624,8 +2624,8 @@ where [(); core::alloc::co_alloc_metadata_num_slots::()]: { } } -impl ExtendFromWithinSpec for Vec -where [(); core::alloc::co_alloc_metadata_num_slots::()]: { +impl ExtendFromWithinSpec for Vec +where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { unsafe fn spec_extend_from_within(&mut self, src: Range) { let count = src.len(); { @@ -2658,8 +2658,8 @@ where [(); core::alloc::co_alloc_metadata_num_slots::()]: { //////////////////////////////////////////////////////////////////////////////// #[stable(feature = "rust1", since = "1.0.0")] -impl ops::Deref for Vec -where [(); core::alloc::co_alloc_metadata_num_slots::()]: { +impl ops::Deref for Vec +where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { type Target = [T]; #[inline] @@ -2669,8 +2669,8 @@ where [(); core::alloc::co_alloc_metadata_num_slots::()]: { } #[stable(feature = "rust1", since = "1.0.0")] -impl ops::DerefMut for Vec -where [(); core::alloc::co_alloc_metadata_num_slots::()]: { +impl ops::DerefMut for Vec +where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { #[inline] fn deref_mut(&mut self) -> &mut [T] { unsafe { slice::from_raw_parts_mut(self.as_mut_ptr(), self.len) } @@ -2679,8 +2679,8 @@ where [(); core::alloc::co_alloc_metadata_num_slots::()]: { #[cfg(not(no_global_oom_handling))] #[stable(feature = "rust1", since = "1.0.0")] -impl Clone for Vec -where [(); core::alloc::co_alloc_metadata_num_slots::()]: { +impl Clone for Vec +where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { #[cfg(not(test))] fn clone(&self) -> Self { let alloc = self.allocator().clone(); @@ -2715,8 +2715,8 @@ where [(); core::alloc::co_alloc_metadata_num_slots::()]: { /// assert_eq!(b.hash_one(v), b.hash_one(s)); /// ``` #[stable(feature = "rust1", since = "1.0.0")] -impl Hash for Vec -where [(); core::alloc::co_alloc_metadata_num_slots::()]: { +impl Hash for Vec +where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { #[inline] fn hash(&self, state: &mut H) { Hash::hash(&**self, state) @@ -2728,8 +2728,8 @@ where [(); core::alloc::co_alloc_metadata_num_slots::()]: { message = "vector indices are of type `usize` or ranges of `usize`", label = "vector indices are of type `usize` or ranges of `usize`" )] -impl, A: Allocator> Index for Vec -where [(); core::alloc::co_alloc_metadata_num_slots::()]: { +impl, A: Allocator, const COOP_PREFERRED: bool> Index for Vec +where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { type Output = I::Output; #[inline] @@ -2743,8 +2743,8 @@ where [(); core::alloc::co_alloc_metadata_num_slots::()]: { message = "vector indices are of type `usize` or ranges of `usize`", label = "vector indices are of type `usize` or ranges of `usize`" )] -impl, A: Allocator> IndexMut for Vec -where [(); core::alloc::co_alloc_metadata_num_slots::()]: { +impl, A: Allocator, const COOP_PREFERRED: bool> IndexMut for Vec +where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { #[inline] fn index_mut(&mut self, index: I) -> &mut Self::Output { IndexMut::index_mut(&mut **self, index) @@ -2761,8 +2761,8 @@ impl FromIterator for Vec { } #[stable(feature = "rust1", since = "1.0.0")] -impl IntoIterator for Vec -where [(); core::alloc::co_alloc_metadata_num_slots::()]: { +impl IntoIterator for Vec +where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { type Item = T; type IntoIter = IntoIter; @@ -2807,8 +2807,8 @@ where [(); core::alloc::co_alloc_metadata_num_slots::()]: { } #[stable(feature = "rust1", since = "1.0.0")] -impl<'a, T, A: Allocator> IntoIterator for &'a Vec -where [(); core::alloc::co_alloc_metadata_num_slots::()]: { +impl<'a, T, A: Allocator, const COOP_PREFERRED: bool> IntoIterator for &'a Vec +where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { type Item = &'a T; type IntoIter = slice::Iter<'a, T>; @@ -2818,8 +2818,8 @@ where [(); core::alloc::co_alloc_metadata_num_slots::()]: { } #[stable(feature = "rust1", since = "1.0.0")] -impl<'a, T, A: Allocator> IntoIterator for &'a mut Vec -where [(); core::alloc::co_alloc_metadata_num_slots::()]: { +impl<'a, T, A: Allocator, const COOP_PREFERRED: bool> IntoIterator for &'a mut Vec +where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { type Item = &'a mut T; type IntoIter = slice::IterMut<'a, T>; @@ -2830,8 +2830,8 @@ where [(); core::alloc::co_alloc_metadata_num_slots::()]: { #[cfg(not(no_global_oom_handling))] #[stable(feature = "rust1", since = "1.0.0")] -impl Extend for Vec -where [(); core::alloc::co_alloc_metadata_num_slots::()]: { +impl Extend for Vec +where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { #[inline] fn extend>(&mut self, iter: I) { >::spec_extend(self, iter.into_iter()) @@ -2848,8 +2848,8 @@ where [(); core::alloc::co_alloc_metadata_num_slots::()]: { } } -impl Vec -where [(); core::alloc::co_alloc_metadata_num_slots::()]: { +impl Vec +where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { // leaf method to which various SpecFrom/SpecExtend implementations delegate when // they have no further optimizations to apply #[cfg(not(no_global_oom_handling))] @@ -3023,8 +3023,8 @@ where [(); core::alloc::co_alloc_metadata_num_slots::()]: { /// [`copy_from_slice`]: slice::copy_from_slice #[cfg(not(no_global_oom_handling))] #[stable(feature = "extend_ref", since = "1.2.0")] -impl<'a, T: Copy + 'a, A: Allocator + 'a> Extend<&'a T> for Vec -where [(); core::alloc::co_alloc_metadata_num_slots::()]: { +impl<'a, T: Copy + 'a, A: Allocator + 'a, const COOP_PREFERRED: bool> Extend<&'a T> for Vec +where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { fn extend>(&mut self, iter: I) { self.spec_extend(iter.into_iter()) } @@ -3042,8 +3042,8 @@ where [(); core::alloc::co_alloc_metadata_num_slots::()]: { /// Implements comparison of vectors, [lexicographically](core::cmp::Ord#lexicographical-comparison). #[stable(feature = "rust1", since = "1.0.0")] -impl PartialOrd for Vec -where [(); core::alloc::co_alloc_metadata_num_slots::()]: { +impl PartialOrd for Vec +where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { #[inline] fn partial_cmp(&self, other: &Self) -> Option { PartialOrd::partial_cmp(&**self, &**other) @@ -3051,13 +3051,13 @@ where [(); core::alloc::co_alloc_metadata_num_slots::()]: { } #[stable(feature = "rust1", since = "1.0.0")] -impl Eq for Vec -where [(); core::alloc::co_alloc_metadata_num_slots::()]: {} +impl Eq for Vec +where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: {} /// Implements ordering of vectors, [lexicographically](core::cmp::Ord#lexicographical-comparison). #[stable(feature = "rust1", since = "1.0.0")] -impl Ord for Vec -where [(); core::alloc::co_alloc_metadata_num_slots::()]: { +impl Ord for Vec +where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { #[inline] fn cmp(&self, other: &Self) -> Ordering { Ord::cmp(&**self, &**other) @@ -3065,8 +3065,8 @@ where [(); core::alloc::co_alloc_metadata_num_slots::()]: { } #[stable(feature = "rust1", since = "1.0.0")] -unsafe impl<#[may_dangle] T, A: Allocator> Drop for Vec -where [(); core::alloc::co_alloc_metadata_num_slots::()]: { +unsafe impl<#[may_dangle] T, A: Allocator, const COOP_PREFERRED: bool> Drop for Vec +where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { fn drop(&mut self) { unsafe { // use drop for [T] @@ -3090,40 +3090,40 @@ impl const Default for Vec { } #[stable(feature = "rust1", since = "1.0.0")] -impl fmt::Debug for Vec -where [(); core::alloc::co_alloc_metadata_num_slots::()]: { +impl fmt::Debug for Vec +where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fmt::Debug::fmt(&**self, f) } } #[stable(feature = "rust1", since = "1.0.0")] -impl AsRef> for Vec -where [(); core::alloc::co_alloc_metadata_num_slots::()]: { +impl AsRef> for Vec +where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { fn as_ref(&self) -> &Vec { self } } #[stable(feature = "vec_as_mut", since = "1.5.0")] -impl AsMut> for Vec -where [(); core::alloc::co_alloc_metadata_num_slots::()]: { +impl AsMut> for Vec +where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { fn as_mut(&mut self) -> &mut Vec { self } } #[stable(feature = "rust1", since = "1.0.0")] -impl AsRef<[T]> for Vec -where [(); core::alloc::co_alloc_metadata_num_slots::()]: { +impl AsRef<[T]> for Vec +where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { fn as_ref(&self) -> &[T] { self } } #[stable(feature = "vec_as_mut", since = "1.5.0")] -impl AsMut<[T]> for Vec -where [(); core::alloc::co_alloc_metadata_num_slots::()]: { +impl AsMut<[T]> for Vec +where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { fn as_mut(&mut self) -> &mut [T] { self } @@ -3220,8 +3220,8 @@ where // note: test pulls in std, which causes errors here #[cfg(not(test))] #[stable(feature = "vec_from_box", since = "1.18.0")] -impl From> for Vec -where [(); core::alloc::co_alloc_metadata_num_slots::()]: { +impl From> for Vec +where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { /// Convert a boxed slice into a vector by transferring ownership of /// the existing heap allocation. /// @@ -3240,8 +3240,8 @@ where [(); core::alloc::co_alloc_metadata_num_slots::()]: { #[cfg(not(no_global_oom_handling))] #[cfg(not(test))] #[stable(feature = "box_from_vec", since = "1.20.0")] -impl From> for Box<[T], A> -where [(); core::alloc::co_alloc_metadata_num_slots::()]: { +impl From> for Box<[T], A> +where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { /// Convert a vector into a boxed slice. /// /// If `v` has excess capacity, its items will be moved into a @@ -3281,8 +3281,8 @@ impl From<&str> for Vec { } #[stable(feature = "array_try_from_vec", since = "1.48.0")] -impl TryFrom> for [T; N] -where [(); core::alloc::co_alloc_metadata_num_slots::()]: { +impl TryFrom> for [T; N] +where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { type Error = Vec; /// Gets the entire contents of the `Vec` as an array, diff --git a/library/alloc/src/vec/partial_eq.rs b/library/alloc/src/vec/partial_eq.rs index b50b9673e1560..bcf52b7333218 100644 --- a/library/alloc/src/vec/partial_eq.rs +++ b/library/alloc/src/vec/partial_eq.rs @@ -6,12 +6,12 @@ use crate::borrow::Cow; use super::Vec; macro_rules! __impl_slice_eq1 { - ([$($vars:tt)*] $lhs:ty, $rhs:ty $(where $ty:ty: $bound:ident)?, #[$stability:meta]) => { + ([$($vars:tt)*] $lhs:ty, $rhs:ty, #[$stability:meta], $($constraints:tt)*) => { #[$stability] impl PartialEq<$rhs> for $lhs where T: PartialEq, - $($ty: $bound)? + $($constraints)* { #[inline] fn eq(&self, other: &$rhs) -> bool { self[..] == other[..] } @@ -21,21 +21,21 @@ macro_rules! __impl_slice_eq1 { } } -__impl_slice_eq1! { [A1: Allocator, A2: Allocator] Vec, Vec, #[stable(feature = "rust1", since = "1.0.0")] } -__impl_slice_eq1! { [A: Allocator] Vec, &[U], #[stable(feature = "rust1", since = "1.0.0")] } -__impl_slice_eq1! { [A: Allocator] Vec, &mut [U], #[stable(feature = "rust1", since = "1.0.0")] } -__impl_slice_eq1! { [A: Allocator] &[T], Vec, #[stable(feature = "partialeq_vec_for_ref_slice", since = "1.46.0")] } -__impl_slice_eq1! { [A: Allocator] &mut [T], Vec, #[stable(feature = "partialeq_vec_for_ref_slice", since = "1.46.0")] } -__impl_slice_eq1! { [A: Allocator] Vec, [U], #[stable(feature = "partialeq_vec_for_slice", since = "1.48.0")] } -__impl_slice_eq1! { [A: Allocator] [T], Vec, #[stable(feature = "partialeq_vec_for_slice", since = "1.48.0")] } +__impl_slice_eq1! { [A1: Allocator, A2: Allocator, const COOP_PREFERRED1: bool, const COOP_PREFERRED2: bool] Vec, Vec, #[stable(feature = "rust1", since = "1.0.0")], [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED1)]:, [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED2)]: } +__impl_slice_eq1! { [A: Allocator, const COOP_PREFERRED: bool] Vec, &[U], #[stable(feature = "rust1", since = "1.0.0")], [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: } +__impl_slice_eq1! { [A: Allocator, const COOP_PREFERRED: bool] Vec, &mut [U], #[stable(feature = "rust1", since = "1.0.0")], [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: } +__impl_slice_eq1! { [A: Allocator, const COOP_PREFERRED: bool] &[T], Vec, #[stable(feature = "partialeq_vec_for_ref_slice", since = "1.46.0")], [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: } +__impl_slice_eq1! { [A: Allocator, const COOP_PREFERRED: bool] &mut [T], Vec, #[stable(feature = "partialeq_vec_for_ref_slice", since = "1.46.0")], [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: } +__impl_slice_eq1! { [A: Allocator, const COOP_PREFERRED: bool] Vec, [U], #[stable(feature = "partialeq_vec_for_slice", since = "1.48.0")], [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: } +__impl_slice_eq1! { [A: Allocator, const COOP_PREFERRED: bool] [T], Vec, #[stable(feature = "partialeq_vec_for_slice", since = "1.48.0")], [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: } #[cfg(not(no_global_oom_handling))] -__impl_slice_eq1! { [A: Allocator] Cow<'_, [T]>, Vec where T: Clone, #[stable(feature = "rust1", since = "1.0.0")] } +__impl_slice_eq1! { [A: Allocator, const COOP_PREFERRED: bool] Cow<'_, [T]>, Vec, #[stable(feature = "rust1", since = "1.0.0")], T: Clone, [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: } #[cfg(not(no_global_oom_handling))] -__impl_slice_eq1! { [] Cow<'_, [T]>, &[U] where T: Clone, #[stable(feature = "rust1", since = "1.0.0")] } +__impl_slice_eq1! { [] Cow<'_, [T]>, &[U], #[stable(feature = "rust1", since = "1.0.0")], T: Clone } #[cfg(not(no_global_oom_handling))] -__impl_slice_eq1! { [] Cow<'_, [T]>, &mut [U] where T: Clone, #[stable(feature = "rust1", since = "1.0.0")] } -__impl_slice_eq1! { [A: Allocator, const N: usize] Vec, [U; N], #[stable(feature = "rust1", since = "1.0.0")] } -__impl_slice_eq1! { [A: Allocator, const N: usize] Vec, &[U; N], #[stable(feature = "rust1", since = "1.0.0")] } +__impl_slice_eq1! { [] Cow<'_, [T]>, &mut [U], #[stable(feature = "rust1", since = "1.0.0")], T: Clone } +__impl_slice_eq1! { [A: Allocator, const COOP_PREFERRED: bool, const N: usize] Vec, [U; N], #[stable(feature = "rust1", since = "1.0.0")], [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: } +__impl_slice_eq1! { [A: Allocator, const COOP_PREFERRED: bool, const N: usize] Vec, &[U; N], #[stable(feature = "rust1", since = "1.0.0")], [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: } // NOTE: some less important impls are omitted to reduce code bloat // FIXME(Centril): Reconsider this? diff --git a/library/core/src/alloc/mod.rs b/library/core/src/alloc/mod.rs index 23bfdc732557e..9359273ca0a3a 100644 --- a/library/core/src/alloc/mod.rs +++ b/library/core/src/alloc/mod.rs @@ -28,6 +28,7 @@ use crate::ptr::{self, NonNull}; // @TODO Make this target-specific #[unstable(feature = "global_co_alloc_meta", issue = "none")] #[allow(missing_debug_implementations)] +#[derive(Clone, Copy)] pub struct GlobalCoAllocMeta { //pub one: usize, /*pub two: usize, @@ -73,6 +74,9 @@ pub struct SliceAndMeta { pub meta: GlobalCoAllocMeta, } +#[unstable(feature = "global_co_alloc_short_term_pref", issue = "none")] +pub const SHORT_TERM_VEC_PREFERS_COOP: bool = true; + #[unstable(feature = "global_co_alloc_meta", issue = "none")] #[allow(missing_debug_implementations)] pub type SliceAndMetaResult = Result; @@ -82,6 +86,13 @@ pub const fn co_alloc_metadata_num_slots() -> usize { if A::IS_CO_ALLOCATOR { 1 } else { 0 } } +#[unstable(feature = "global_co_alloc", issue = "none")] +/// Param `coop_preferred` - if false, then this returns `0`, regardless of +/// whether allocator `A` is cooperative. +pub const fn co_alloc_metadata_num_slots_with_preference(coop_preferred: bool) -> usize { + if A::IS_CO_ALLOCATOR && coop_preferred { 1 } else { 0 } +} + /// An implementation of `Allocator` can allocate, grow, shrink, and deallocate arbitrary blocks of /// data described via [`Layout`][]. /// From 74501929704eec6932ea7e66c925c90b8655e472 Mon Sep 17 00:00:00 2001 From: Peter Kehl Date: Sat, 21 Jan 2023 16:14:15 -0800 Subject: [PATCH 010/118] CoAlloc: BinaryHeap now uses bounds. (Probably needs to go together with Vec). ICE --- .../alloc/src/collections/binary_heap/mod.rs | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/library/alloc/src/collections/binary_heap/mod.rs b/library/alloc/src/collections/binary_heap/mod.rs index 0b73b1af4eb35..7c6b0bb6e6c75 100644 --- a/library/alloc/src/collections/binary_heap/mod.rs +++ b/library/alloc/src/collections/binary_heap/mod.rs @@ -143,13 +143,15 @@ #![allow(missing_docs)] #![stable(feature = "rust1", since = "1.0.0")] -use core::fmt; +use core::{alloc, fmt}; use core::iter::{FromIterator, FusedIterator, InPlaceIterable, SourceIter, TrustedLen}; use core::mem::{self, swap, ManuallyDrop}; use core::num::NonZeroUsize; use core::ops::{Deref, DerefMut}; use core::ptr; +use crate::alloc::Global; + use crate::collections::TryReserveError; use crate::slice; use crate::vec::{self, AsVecIntoIter, Vec}; @@ -1241,7 +1243,7 @@ impl BinaryHeap { /// ``` #[inline] #[stable(feature = "drain", since = "1.6.0")] - pub fn drain(&mut self) -> Drain<'_, T> { + pub fn drain(&mut self) -> Drain<'_, T, {alloc::SHORT_TERM_VEC_PREFERS_COOP}> { Drain { iter: self.data.drain(..) } } @@ -1521,12 +1523,14 @@ unsafe impl TrustedLen for IntoIterSorted {} /// [`drain`]: BinaryHeap::drain #[stable(feature = "drain", since = "1.6.0")] #[derive(Debug)] -pub struct Drain<'a, T: 'a> { - iter: vec::Drain<'a, T>, +pub struct Drain<'a, T: 'a, const COOP_PREFERRED: bool> +where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { + iter: vec::Drain<'a, T, Global, COOP_PREFERRED>, } #[stable(feature = "drain", since = "1.6.0")] -impl Iterator for Drain<'_, T> { +impl Iterator for Drain<'_, T, COOP_PREFERRED> +where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { type Item = T; #[inline] @@ -1541,7 +1545,7 @@ impl Iterator for Drain<'_, T> { } #[stable(feature = "drain", since = "1.6.0")] -impl DoubleEndedIterator for Drain<'_, T> { +impl DoubleEndedIterator for Drain<'_, T, COOP_PREFERRED> { #[inline] fn next_back(&mut self) -> Option { self.iter.next_back() @@ -1549,14 +1553,14 @@ impl DoubleEndedIterator for Drain<'_, T> { } #[stable(feature = "drain", since = "1.6.0")] -impl ExactSizeIterator for Drain<'_, T> { +impl ExactSizeIterator for Drain<'_, T, COOP_PREFERRED> { fn is_empty(&self) -> bool { self.iter.is_empty() } } #[stable(feature = "fused", since = "1.26.0")] -impl FusedIterator for Drain<'_, T> {} +impl FusedIterator for Drain<'_, T, COOP_PREFERRED> {} /// A draining iterator over the elements of a `BinaryHeap`. /// From 3fb632efb3a95d65bacaf4931cc8cc7339143293 Mon Sep 17 00:00:00 2001 From: Peter Kehl Date: Sat, 21 Jan 2023 16:15:28 -0800 Subject: [PATCH 011/118] CoAlloc: VecDeque now uses bounds. ICE --- .../alloc/src/collections/vec_deque/drain.rs | 51 +++++---- .../alloc/src/collections/vec_deque/macros.rs | 4 +- .../alloc/src/collections/vec_deque/mod.rs | 107 +++++++++--------- .../src/collections/vec_deque/spec_extend.rs | 24 ++-- 4 files changed, 94 insertions(+), 92 deletions(-) diff --git a/library/alloc/src/collections/vec_deque/drain.rs b/library/alloc/src/collections/vec_deque/drain.rs index e4f2f80892504..bab4919eb6032 100644 --- a/library/alloc/src/collections/vec_deque/drain.rs +++ b/library/alloc/src/collections/vec_deque/drain.rs @@ -19,11 +19,12 @@ pub struct Drain< 'a, T: 'a, #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global, + const COOP_PREFERRED: bool = {alloc::SHORT_TERM_VEC_PREFERS_COOP} > -where [(); alloc::co_alloc_metadata_num_slots::()]: { +where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { // We can't just use a &mut VecDeque, as that would make Drain invariant over T // and we want it to be covariant instead - deque: NonNull>, + deque: NonNull>, // drain_start is stored in deque.len drain_len: usize, // index into the logical array, not the physical one (always lies in [0..deque.len)) @@ -35,10 +36,10 @@ where [(); alloc::co_alloc_metadata_num_slots::()]: { _marker: PhantomData<&'a T>, } -impl<'a, T, A: Allocator> Drain<'a, T, A> -where [(); alloc::co_alloc_metadata_num_slots::()]: { +impl<'a, T, A: Allocator, const COOP_PREFERRED: bool> Drain<'a, T, A, COOP_PREFERRED> +where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { pub(super) unsafe fn new( - deque: &'a mut VecDeque, + deque: &'a mut VecDeque, drain_start: usize, drain_len: usize, ) -> Self { @@ -90,8 +91,8 @@ where [(); alloc::co_alloc_metadata_num_slots::()]: { } #[stable(feature = "collection_debug", since = "1.17.0")] -impl fmt::Debug for Drain<'_, T, A> -where [(); alloc::co_alloc_metadata_num_slots::()]: { +impl fmt::Debug for Drain<'_, T, A, COOP_PREFERRED> +where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_tuple("Drain") .field(&self.drain_len) @@ -103,21 +104,21 @@ where [(); alloc::co_alloc_metadata_num_slots::()]: { } #[stable(feature = "drain", since = "1.6.0")] -unsafe impl Sync for Drain<'_, T, A> -where [(); alloc::co_alloc_metadata_num_slots::()]: {} +unsafe impl Sync for Drain<'_, T, A, COOP_PREFERRED> +where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: {} #[stable(feature = "drain", since = "1.6.0")] -unsafe impl Send for Drain<'_, T, A> -where [(); alloc::co_alloc_metadata_num_slots::()]: {} +unsafe impl Send for Drain<'_, T, A, COOP_PREFERRED> +where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: {} #[stable(feature = "drain", since = "1.6.0")] -impl Drop for Drain<'_, T, A> -where [(); alloc::co_alloc_metadata_num_slots::()]: { +impl Drop for Drain<'_, T, A, COOP_PREFERRED> +where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { fn drop(&mut self) { - struct DropGuard<'r, 'a, T, A: Allocator> (&'r mut Drain<'a, T, A>) - where [(); alloc::co_alloc_metadata_num_slots::()]:; + struct DropGuard<'r, 'a, T, A: Allocator, const COOP_PREFERRED: bool> (&'r mut Drain<'a, T, A, COOP_PREFERRED>) + where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:; - impl<'r, 'a, T, A: Allocator> Drop for DropGuard<'r, 'a, T, A> - where [(); alloc::co_alloc_metadata_num_slots::()]: { + impl<'r, 'a, T, A: Allocator, const COOP_PREFERRED: bool> Drop for DropGuard<'r, 'a, T, A, COOP_PREFERRED> + where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { fn drop(&mut self) { if self.0.remaining != 0 { unsafe { @@ -198,8 +199,8 @@ where [(); alloc::co_alloc_metadata_num_slots::()]: { } #[stable(feature = "drain", since = "1.6.0")] -impl Iterator for Drain<'_, T, A> -where [(); alloc::co_alloc_metadata_num_slots::()]: { +impl Iterator for Drain<'_, T, A, COOP_PREFERRED> +where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { type Item = T; #[inline] @@ -221,8 +222,8 @@ where [(); alloc::co_alloc_metadata_num_slots::()]: { } #[stable(feature = "drain", since = "1.6.0")] -impl DoubleEndedIterator for Drain<'_, T, A> -where [(); alloc::co_alloc_metadata_num_slots::()]: { +impl DoubleEndedIterator for Drain<'_, T, A, COOP_PREFERRED> +where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { #[inline] fn next_back(&mut self) -> Option { if self.remaining == 0 { @@ -235,9 +236,9 @@ where [(); alloc::co_alloc_metadata_num_slots::()]: { } #[stable(feature = "drain", since = "1.6.0")] -impl ExactSizeIterator for Drain<'_, T, A> -where [(); alloc::co_alloc_metadata_num_slots::()]: {} +impl ExactSizeIterator for Drain<'_, T, A, COOP_PREFERRED> +where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: {} #[stable(feature = "fused", since = "1.26.0")] -impl FusedIterator for Drain<'_, T, A> -where [(); alloc::co_alloc_metadata_num_slots::()]: {} +impl FusedIterator for Drain<'_, T, A, COOP_PREFERRED> +where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: {} diff --git a/library/alloc/src/collections/vec_deque/macros.rs b/library/alloc/src/collections/vec_deque/macros.rs index f7768f54c6225..68ee43152b5b5 100644 --- a/library/alloc/src/collections/vec_deque/macros.rs +++ b/library/alloc/src/collections/vec_deque/macros.rs @@ -1,10 +1,10 @@ macro_rules! __impl_slice_eq1 { ([$($vars:tt)*] $lhs:ty, $rhs:ty, $($constraints:tt)*) => { #[stable(feature = "vec_deque_partial_eq_slice", since = "1.17.0")] - impl PartialEq<$rhs> for $lhs + impl PartialEq<$rhs> for $lhs where T: PartialEq, - [(); core::alloc::co_alloc_metadata_num_slots::()]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, $($constraints)* { fn eq(&self, other: &$rhs) -> bool { diff --git a/library/alloc/src/collections/vec_deque/mod.rs b/library/alloc/src/collections/vec_deque/mod.rs index d8f821a9048d6..c5d0f6527c8c8 100644 --- a/library/alloc/src/collections/vec_deque/mod.rs +++ b/library/alloc/src/collections/vec_deque/mod.rs @@ -97,8 +97,9 @@ mod tests; pub struct VecDeque< T, #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global, + const COOP_PREFERRED: bool = true > -where [(); alloc::co_alloc_metadata_num_slots::()]: +where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { // `self[0]`, if it exists, is `buf[head]`. // `head < buf.capacity()`, unless `buf.capacity() == 0` when `head == 0`. @@ -107,12 +108,12 @@ where [(); alloc::co_alloc_metadata_num_slots::()]: // if `len == 0`, the exact value of `head` is unimportant. // if `T` is zero-Sized, then `self.len <= usize::MAX`, otherwise `self.len <= isize::MAX as usize`. len: usize, - buf: RawVec, + buf: RawVec, } #[stable(feature = "rust1", since = "1.0.0")] -impl Clone for VecDeque -where [(); alloc::co_alloc_metadata_num_slots::()]: { +impl Clone for VecDeque +where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { fn clone(&self) -> Self { let mut deq = Self::with_capacity_in(self.len(), self.allocator().clone()); deq.extend(self.iter().cloned()); @@ -126,8 +127,8 @@ where [(); alloc::co_alloc_metadata_num_slots::()]: { } #[stable(feature = "rust1", since = "1.0.0")] -unsafe impl<#[may_dangle] T, A: Allocator> Drop for VecDeque -where [(); alloc::co_alloc_metadata_num_slots::()]: { +unsafe impl<#[may_dangle] T, A: Allocator, const COOP_PREFERRED: bool> Drop for VecDeque +where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { fn drop(&mut self) { /// Runs the destructor for all items in the slice when it gets dropped (normally or /// during unwinding). @@ -160,8 +161,8 @@ impl Default for VecDeque { } } -impl VecDeque -where [(); alloc::co_alloc_metadata_num_slots::()]: { +impl VecDeque +where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { /// Marginally more convenient #[inline] fn ptr(&self) -> *mut T { @@ -450,14 +451,14 @@ where [(); alloc::co_alloc_metadata_num_slots::()]: { mut iter: impl Iterator, len: usize, ) -> usize { - struct Guard<'a, T, A: Allocator> - where [(); alloc::co_alloc_metadata_num_slots::()]: { - deque: &'a mut VecDeque, + struct Guard<'a, T, A: Allocator, const COOP_PREFERRED: bool> + where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { + deque: &'a mut VecDeque, written: usize, } - impl<'a, T, A: Allocator> Drop for Guard<'a, T, A> - where [(); alloc::co_alloc_metadata_num_slots::()]: { + impl<'a, T, A: Allocator, const COOP_PREFERRED: bool> Drop for Guard<'a, T, A, COOP_PREFERRED> + where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { fn drop(&mut self) { self.deque.len += self.written; } @@ -571,8 +572,8 @@ impl VecDeque { } } -impl VecDeque -where [(); alloc::co_alloc_metadata_num_slots::()]: { +impl VecDeque +where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { /// Creates an empty deque. /// /// # Examples @@ -2607,8 +2608,8 @@ where [(); alloc::co_alloc_metadata_num_slots::()]: { } } -impl VecDeque -where [(); alloc::co_alloc_metadata_num_slots::()]: { +impl VecDeque +where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { /// Modifies the deque in-place so that `len()` is equal to new_len, /// either by removing excess elements from the back or by appending clones of `value` /// to the back. @@ -2653,8 +2654,8 @@ fn wrap_index(logical_index: usize, capacity: usize) -> usize { } #[stable(feature = "rust1", since = "1.0.0")] -impl PartialEq for VecDeque -where [(); alloc::co_alloc_metadata_num_slots::()]: { +impl PartialEq for VecDeque +where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { fn eq(&self, other: &Self) -> bool { if self.len != other.len() { return false; @@ -2693,27 +2694,27 @@ where [(); alloc::co_alloc_metadata_num_slots::()]: { } #[stable(feature = "rust1", since = "1.0.0")] -impl Eq for VecDeque -where [(); alloc::co_alloc_metadata_num_slots::()]: {} +impl Eq for VecDeque +where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: {} -__impl_slice_eq1! { [] VecDeque, Vec, } -__impl_slice_eq1! { [] VecDeque, &[U], } -__impl_slice_eq1! { [] VecDeque, &mut [U], } -__impl_slice_eq1! { [const N: usize] VecDeque, [U; N], } -__impl_slice_eq1! { [const N: usize] VecDeque, &[U; N], } -__impl_slice_eq1! { [const N: usize] VecDeque, &mut [U; N], } +__impl_slice_eq1! { [] VecDeque, Vec, } +__impl_slice_eq1! { [] VecDeque, &[U], } +__impl_slice_eq1! { [] VecDeque, &mut [U], } +__impl_slice_eq1! { [const N: usize] VecDeque, [U; N], } +__impl_slice_eq1! { [const N: usize] VecDeque, &[U; N], } +__impl_slice_eq1! { [const N: usize] VecDeque, &mut [U; N], } #[stable(feature = "rust1", since = "1.0.0")] -impl PartialOrd for VecDeque -where [(); alloc::co_alloc_metadata_num_slots::()]: { +impl PartialOrd for VecDeque +where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { fn partial_cmp(&self, other: &Self) -> Option { self.iter().partial_cmp(other.iter()) } } #[stable(feature = "rust1", since = "1.0.0")] -impl Ord for VecDeque -where [(); alloc::co_alloc_metadata_num_slots::()]: { +impl Ord for VecDeque +where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { #[inline] fn cmp(&self, other: &Self) -> Ordering { self.iter().cmp(other.iter()) @@ -2721,8 +2722,8 @@ where [(); alloc::co_alloc_metadata_num_slots::()]: { } #[stable(feature = "rust1", since = "1.0.0")] -impl Hash for VecDeque -where [(); alloc::co_alloc_metadata_num_slots::()]: { +impl Hash for VecDeque +where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { fn hash(&self, state: &mut H) { state.write_length_prefix(self.len); // It's not possible to use Hash::hash_slice on slices @@ -2736,8 +2737,8 @@ where [(); alloc::co_alloc_metadata_num_slots::()]: { } #[stable(feature = "rust1", since = "1.0.0")] -impl Index for VecDeque -where [(); alloc::co_alloc_metadata_num_slots::()]: { +impl Index for VecDeque +where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { type Output = T; #[inline] @@ -2747,8 +2748,8 @@ where [(); alloc::co_alloc_metadata_num_slots::()]: { } #[stable(feature = "rust1", since = "1.0.0")] -impl IndexMut for VecDeque -where [(); alloc::co_alloc_metadata_num_slots::()]: { +impl IndexMut for VecDeque +where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { #[inline] fn index_mut(&mut self, index: usize) -> &mut T { self.get_mut(index).expect("Out of bounds access") @@ -2763,8 +2764,8 @@ impl FromIterator for VecDeque { } #[stable(feature = "rust1", since = "1.0.0")] -impl IntoIterator for VecDeque -where [(); alloc::co_alloc_metadata_num_slots::()]: { +impl IntoIterator for VecDeque +where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { type Item = T; type IntoIter = IntoIter; @@ -2776,8 +2777,8 @@ where [(); alloc::co_alloc_metadata_num_slots::()]: { } #[stable(feature = "rust1", since = "1.0.0")] -impl<'a, T, A: Allocator> IntoIterator for &'a VecDeque -where [(); alloc::co_alloc_metadata_num_slots::()]: { +impl<'a, T, A: Allocator, const COOP_PREFERRED: bool> IntoIterator for &'a VecDeque +where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { type Item = &'a T; type IntoIter = Iter<'a, T>; @@ -2787,8 +2788,8 @@ where [(); alloc::co_alloc_metadata_num_slots::()]: { } #[stable(feature = "rust1", since = "1.0.0")] -impl<'a, T, A: Allocator> IntoIterator for &'a mut VecDeque -where [(); alloc::co_alloc_metadata_num_slots::()]: { +impl<'a, T, A: Allocator, const COOP_PREFERRED: bool> IntoIterator for &'a mut VecDeque +where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { type Item = &'a mut T; type IntoIter = IterMut<'a, T>; @@ -2798,8 +2799,8 @@ where [(); alloc::co_alloc_metadata_num_slots::()]: { } #[stable(feature = "rust1", since = "1.0.0")] -impl Extend for VecDeque -where [(); alloc::co_alloc_metadata_num_slots::()]: { +impl Extend for VecDeque +where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { fn extend>(&mut self, iter: I) { >::spec_extend(self, iter.into_iter()); } @@ -2816,8 +2817,8 @@ where [(); alloc::co_alloc_metadata_num_slots::()]: { } #[stable(feature = "extend_ref", since = "1.2.0")] -impl<'a, T: 'a + Copy, A: Allocator> Extend<&'a T> for VecDeque -where [(); alloc::co_alloc_metadata_num_slots::()]: { +impl<'a, T: 'a + Copy, A: Allocator, const COOP_PREFERRED: bool> Extend<&'a T> for VecDeque +where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { fn extend>(&mut self, iter: I) { self.spec_extend(iter.into_iter()); } @@ -2834,16 +2835,16 @@ where [(); alloc::co_alloc_metadata_num_slots::()]: { } #[stable(feature = "rust1", since = "1.0.0")] -impl fmt::Debug for VecDeque -where [(); alloc::co_alloc_metadata_num_slots::()]: { +impl fmt::Debug for VecDeque +where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_list().entries(self.iter()).finish() } } #[stable(feature = "vecdeque_vec_conversions", since = "1.10.0")] -impl From> for VecDeque -where [(); alloc::co_alloc_metadata_num_slots::()]: { +impl From> for VecDeque +where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { /// Turn a [`Vec`] into a [`VecDeque`]. /// /// [`Vec`]: crate::vec::Vec @@ -2860,8 +2861,8 @@ where [(); alloc::co_alloc_metadata_num_slots::()]: { } #[stable(feature = "vecdeque_vec_conversions", since = "1.10.0")] -impl From> for Vec -where [(); alloc::co_alloc_metadata_num_slots::()]: { +impl From> for Vec +where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { /// Turn a [`VecDeque`] into a [`Vec`]. /// /// [`Vec`]: crate::vec::Vec diff --git a/library/alloc/src/collections/vec_deque/spec_extend.rs b/library/alloc/src/collections/vec_deque/spec_extend.rs index f6d957fdc03ba..cdeda1a57bed5 100644 --- a/library/alloc/src/collections/vec_deque/spec_extend.rs +++ b/library/alloc/src/collections/vec_deque/spec_extend.rs @@ -13,10 +13,10 @@ pub(super) trait SpecExtend { fn spec_extend(&mut self, iter: I); } -impl SpecExtend for VecDeque +impl SpecExtend for VecDeque where I: Iterator, - [(); alloc::co_alloc_metadata_num_slots::()]: + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { default fn spec_extend(&mut self, mut iter: I) { // This function should be the moral equivalent of: @@ -26,8 +26,8 @@ where // } // May only be called if `deque.len() < deque.capacity()` - unsafe fn push_unchecked(deque: &mut VecDeque, element: T) - where [(); alloc::co_alloc_metadata_num_slots::()]: { + unsafe fn push_unchecked(deque: &mut VecDeque, element: T) + where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { // SAFETY: Because of the precondition, it's guaranteed that there is space // in the logical array after the last element. unsafe { deque.buffer_write(deque.to_physical_idx(deque.len), element) }; @@ -54,10 +54,10 @@ where } } -impl SpecExtend for VecDeque +impl SpecExtend for VecDeque where I: TrustedLen, - [(); alloc::co_alloc_metadata_num_slots::()]: + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { default fn spec_extend(&mut self, iter: I) { // This is the case for a TrustedLen iterator. @@ -90,8 +90,8 @@ where } } -impl SpecExtend> for VecDeque -where [(); alloc::co_alloc_metadata_num_slots::()]: { +impl SpecExtend> for VecDeque +where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { fn spec_extend(&mut self, mut iterator: vec::IntoIter) { let slice = iterator.as_slice(); self.reserve(slice.len()); @@ -104,21 +104,21 @@ where [(); alloc::co_alloc_metadata_num_slots::()]: { } } -impl<'a, T: 'a, I, A: Allocator> SpecExtend<&'a T, I> for VecDeque +impl<'a, T: 'a, I, A: Allocator, const COOP_PREFERRED: bool> SpecExtend<&'a T, I> for VecDeque where I: Iterator, T: Copy, - [(); alloc::co_alloc_metadata_num_slots::()]: + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { default fn spec_extend(&mut self, iterator: I) { self.spec_extend(iterator.copied()) } } -impl<'a, T: 'a, A: Allocator> SpecExtend<&'a T, slice::Iter<'a, T>> for VecDeque +impl<'a, T: 'a, A: Allocator, const COOP_PREFERRED: bool> SpecExtend<&'a T, slice::Iter<'a, T>> for VecDeque where T: Copy, - [(); alloc::co_alloc_metadata_num_slots::()]: + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { fn spec_extend(&mut self, iterator: slice::Iter<'a, T>) { let slice = iterator.as_slice(); From 01599b989f987244780be8ceca7532bd4983b5d9 Mon Sep 17 00:00:00 2001 From: Peter Kehl Date: Sat, 21 Jan 2023 21:50:46 -0800 Subject: [PATCH 012/118] CoAlloc: VecDeque. Probably ICE. --- .../src/collections/vec_deque/into_iter.rs | 11 ++++++----- library/alloc/src/collections/vec_deque/mod.rs | 18 ++++++++++-------- library/std/src/io/impls.rs | 6 ++++-- 3 files changed, 20 insertions(+), 15 deletions(-) diff --git a/library/alloc/src/collections/vec_deque/into_iter.rs b/library/alloc/src/collections/vec_deque/into_iter.rs index c5c1d17bc62dd..81267b8c278b0 100644 --- a/library/alloc/src/collections/vec_deque/into_iter.rs +++ b/library/alloc/src/collections/vec_deque/into_iter.rs @@ -17,18 +17,19 @@ use super::VecDeque; pub struct IntoIter< T, #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global, + const COOP_PREFERRED: bool = true > -where [(); alloc::co_alloc_metadata_num_slots::()]: { - inner: VecDeque, +where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { + inner: VecDeque, } -impl IntoIter +impl IntoIter where [(); alloc::co_alloc_metadata_num_slots::()]: { - pub(super) fn new(inner: VecDeque) -> Self { + pub(super) fn new(inner: VecDeque) -> Self { IntoIter { inner } } - pub(super) fn into_vecdeque(self) -> VecDeque { + pub(super) fn into_vecdeque(self) -> VecDeque { self.inner } } diff --git a/library/alloc/src/collections/vec_deque/mod.rs b/library/alloc/src/collections/vec_deque/mod.rs index c5d0f6527c8c8..694a3d2624106 100644 --- a/library/alloc/src/collections/vec_deque/mod.rs +++ b/library/alloc/src/collections/vec_deque/mod.rs @@ -153,10 +153,10 @@ where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRE } #[stable(feature = "rust1", since = "1.0.0")] -impl Default for VecDeque { +impl Default for VecDeque { /// Creates an empty deque. #[inline] - fn default() -> VecDeque { + fn default() -> VecDeque { VecDeque::new() } } @@ -536,7 +536,8 @@ where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRE } } -impl VecDeque { +impl VecDeque +where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { /// Creates an empty deque. /// /// # Examples @@ -550,7 +551,7 @@ impl VecDeque { #[stable(feature = "rust1", since = "1.0.0")] #[rustc_const_stable(feature = "const_vec_deque_new", since = "1.68.0")] #[must_use] - pub const fn new() -> VecDeque { + pub const fn new() -> VecDeque { // FIXME: This should just be `VecDeque::new_in(Global)` once that hits stable. VecDeque { head: 0, len: 0, buf: RawVec::NEW } } @@ -567,7 +568,7 @@ impl VecDeque { #[inline] #[stable(feature = "rust1", since = "1.0.0")] #[must_use] - pub fn with_capacity(capacity: usize) -> VecDeque { + pub fn with_capacity(capacity: usize) -> VecDeque { Self::with_capacity_in(capacity, Global) } } @@ -585,7 +586,7 @@ where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRE /// ``` #[inline] #[unstable(feature = "allocator_api", issue = "32838")] - pub const fn new_in(alloc: A) -> VecDeque { + pub const fn new_in(alloc: A) -> VecDeque { VecDeque { head: 0, len: 0, buf: RawVec::new_in(alloc) } } @@ -599,7 +600,7 @@ where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRE /// let deque: VecDeque = VecDeque::with_capacity(10); /// ``` #[unstable(feature = "allocator_api", issue = "32838")] - pub fn with_capacity_in(capacity: usize, alloc: A) -> VecDeque { + pub fn with_capacity_in(capacity: usize, alloc: A) -> VecDeque { VecDeque { head: 0, len: 0, buf: RawVec::with_capacity_in(capacity, alloc) } } @@ -2892,7 +2893,7 @@ where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRE /// assert_eq!(vec, [8, 9, 1, 2, 3, 4]); /// assert_eq!(vec.as_ptr(), ptr); /// ``` - fn from(mut other: VecDeque) -> Self { + fn from(mut other: VecDeque) -> Self { other.make_contiguous(); unsafe { @@ -2905,6 +2906,7 @@ where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRE if other.head != 0 { ptr::copy(buf.add(other.head), buf, len); } + // @TODO: Vec::from_raw_parts_in(buf, len, cap, alloc) } } diff --git a/library/std/src/io/impls.rs b/library/std/src/io/impls.rs index e5048dcc8acd9..d575d9fa3f990 100644 --- a/library/std/src/io/impls.rs +++ b/library/std/src/io/impls.rs @@ -414,7 +414,8 @@ impl Write for Vec { /// Read is implemented for `VecDeque` by consuming bytes from the front of the `VecDeque`. #[stable(feature = "vecdeque_read_write", since = "1.63.0")] -impl Read for VecDeque { +impl Read for VecDeque +where [(); co_alloc_metadata_num_slots_with_preference::(_COOP_PREFERRED)]: { /// Fill `buf` with the contents of the "front" slice as returned by /// [`as_slices`][`VecDeque::as_slices`]. If the contained byte slices of the `VecDeque` are /// discontiguous, multiple calls to `read` will be needed to read the entire content. @@ -438,7 +439,8 @@ impl Read for VecDeque { /// Write is implemented for `VecDeque` by appending to the `VecDeque`, growing it as needed. #[stable(feature = "vecdeque_read_write", since = "1.63.0")] -impl Write for VecDeque { +impl Write for VecDeque +where [(); co_alloc_metadata_num_slots_with_preference::(_COOP_PREFERRED)]: { #[inline] fn write(&mut self, buf: &[u8]) -> io::Result { self.extend(buf); From 7e858bdcadd4e6725f279c8a593779ba702972cc Mon Sep 17 00:00:00 2001 From: Peter Kehl Date: Sat, 21 Jan 2023 21:53:16 -0800 Subject: [PATCH 013/118] CoAlloc: Vec + Slice. ICE --- library/alloc/src/raw_vec.rs | 3 ++- library/alloc/src/slice.rs | 30 ++++++++++++------------- library/alloc/src/vec/drain.rs | 2 +- library/alloc/src/vec/into_iter.rs | 2 +- library/alloc/src/vec/mod.rs | 16 ++++++------- library/alloc/src/vec/spec_extend.rs | 20 ++++++++--------- library/alloc/src/vec/spec_from_elem.rs | 20 ++++++++--------- 7 files changed, 47 insertions(+), 46 deletions(-) diff --git a/library/alloc/src/raw_vec.rs b/library/alloc/src/raw_vec.rs index cdbd688bcd5a6..36ef3bf13661a 100644 --- a/library/alloc/src/raw_vec.rs +++ b/library/alloc/src/raw_vec.rs @@ -62,7 +62,8 @@ where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRE pub(crate) metas: [GlobalCoAllocMeta; alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)], } -impl RawVec { +impl RawVec +where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { /// HACK(Centril): This exists because stable `const fn` can only call stable `const fn`, so /// they cannot call `Self::new()`. /// diff --git a/library/alloc/src/slice.rs b/library/alloc/src/slice.rs index c93246c67abaa..2c9860ab66644 100644 --- a/library/alloc/src/slice.rs +++ b/library/alloc/src/slice.rs @@ -97,8 +97,8 @@ pub(crate) mod hack { // We shouldn't add inline attribute to this since this is used in // `vec!` macro mostly and causes perf regression. See #71204 for // discussion and perf results. - pub fn into_vec(b: Box<[T], A>) -> Vec - where [(); core::alloc::co_alloc_metadata_num_slots::()]: { + pub fn into_vec(b: Box<[T], A>) -> Vec + where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { unsafe { let len = b.len(); let (b, alloc) = Box::into_raw_with_allocator(b); @@ -108,31 +108,31 @@ pub(crate) mod hack { #[cfg(not(no_global_oom_handling))] #[inline] - pub fn to_vec(s: &[T], alloc: A) -> Vec - where [(); core::alloc::co_alloc_metadata_num_slots::()]: { + pub fn to_vec(s: &[T], alloc: A) -> Vec + where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { T::to_vec(s, alloc) } #[cfg(not(no_global_oom_handling))] pub trait ConvertVec { - fn to_vec(s: &[Self], alloc: A) -> Vec + fn to_vec(s: &[Self], alloc: A) -> Vec where Self: Sized, - [(); core::alloc::co_alloc_metadata_num_slots::()]:; + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:; } #[cfg(not(no_global_oom_handling))] impl ConvertVec for T { #[inline] - default fn to_vec(s: &[Self], alloc: A) -> Vec - where [(); core::alloc::co_alloc_metadata_num_slots::()]: { - struct DropGuard<'a, T, A: Allocator> - where [(); core::alloc::co_alloc_metadata_num_slots::()]: { - vec: &'a mut Vec, + default fn to_vec(s: &[Self], alloc: A) -> Vec + where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { + struct DropGuard<'a, T, A: Allocator, const COOP_PREFERRED: bool> + where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { + vec: &'a mut Vec, num_init: usize, } - impl<'a, T, A: Allocator> Drop for DropGuard<'a, T, A> - where [(); core::alloc::co_alloc_metadata_num_slots::()]: { + impl<'a, T, A: Allocator, const COOP_PREFERRED: bool> Drop for DropGuard<'a, T, A, COOP_PREFERRED> + where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { #[inline] fn drop(&mut self) { // SAFETY: @@ -164,8 +164,8 @@ pub(crate) mod hack { #[cfg(not(no_global_oom_handling))] impl ConvertVec for T { #[inline] - fn to_vec(s: &[Self], alloc: A) -> Vec - where [(); core::alloc::co_alloc_metadata_num_slots::()]: { + fn to_vec(s: &[Self], alloc: A) -> Vec + where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { let mut v = Vec::with_capacity_in(s.len(), alloc); // SAFETY: // allocated above with the capacity of `s`, and initialize to `s.len()` in diff --git a/library/alloc/src/vec/drain.rs b/library/alloc/src/vec/drain.rs index 6372333bda81d..e0dc758b87b59 100644 --- a/library/alloc/src/vec/drain.rs +++ b/library/alloc/src/vec/drain.rs @@ -32,7 +32,7 @@ where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRE pub(super) tail_len: usize, /// Current remaining range to remove pub(super) iter: slice::Iter<'a, T>, - pub(super) vec: NonNull>, + pub(super) vec: NonNull>, } #[stable(feature = "collection_debug", since = "1.17.0")] diff --git a/library/alloc/src/vec/into_iter.rs b/library/alloc/src/vec/into_iter.rs index fdad67de09716..d07aad4724ccd 100644 --- a/library/alloc/src/vec/into_iter.rs +++ b/library/alloc/src/vec/into_iter.rs @@ -144,7 +144,7 @@ where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRE #[cfg(not(no_global_oom_handling))] #[inline] - pub(crate) fn into_vecdeque(self) -> VecDeque { + pub(crate) fn into_vecdeque(self) -> VecDeque { // Keep our `Drop` impl from dropping the elements and the allocator let mut this = ManuallyDrop::new(self); diff --git a/library/alloc/src/vec/mod.rs b/library/alloc/src/vec/mod.rs index 63e75fef0face..567feb3903f67 100644 --- a/library/alloc/src/vec/mod.rs +++ b/library/alloc/src/vec/mod.rs @@ -2483,7 +2483,7 @@ where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PR /// assert_eq!(flattened.pop(), Some(6)); /// ``` #[unstable(feature = "slice_flatten", issue = "95629")] - pub fn into_flattened(self) -> Vec { + pub fn into_flattened(self) -> Vec { let (ptr, len, cap, alloc) = self.into_raw_parts_with_alloc(); let (new_len, new_cap) = if T::IS_ZST { (len.checked_mul(N).expect("vec len overflow"), usize::MAX) @@ -3098,17 +3098,17 @@ where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PR } #[stable(feature = "rust1", since = "1.0.0")] -impl AsRef> for Vec +impl AsRef> for Vec where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { - fn as_ref(&self) -> &Vec { + fn as_ref(&self) -> &Vec { self } } #[stable(feature = "vec_as_mut", since = "1.5.0")] -impl AsMut> for Vec +impl AsMut> for Vec where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { - fn as_mut(&mut self) -> &mut Vec { + fn as_mut(&mut self) -> &mut Vec { self } } @@ -3260,7 +3260,7 @@ where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PR /// /// assert_eq!(Box::from(vec), vec![1, 2, 3].into_boxed_slice()); /// ``` - fn from(v: Vec) -> Self { + fn from(v: Vec) -> Self { v.into_boxed_slice() } } @@ -3283,7 +3283,7 @@ impl From<&str> for Vec { #[stable(feature = "array_try_from_vec", since = "1.48.0")] impl TryFrom> for [T; N] where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { - type Error = Vec; + type Error = Vec; /// Gets the entire contents of the `Vec` as an array, /// if its size exactly matches that of the requested array. @@ -3311,7 +3311,7 @@ where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PR /// assert_eq!(a, b' '); /// assert_eq!(b, b'd'); /// ``` - fn try_from(mut vec: Vec) -> Result<[T; N], Vec> { + fn try_from(mut vec: Vec) -> Result<[T; N], Vec> { if vec.len() != N { return Err(vec); } diff --git a/library/alloc/src/vec/spec_extend.rs b/library/alloc/src/vec/spec_extend.rs index 81245a394b22e..87bdb3aaab7a5 100644 --- a/library/alloc/src/vec/spec_extend.rs +++ b/library/alloc/src/vec/spec_extend.rs @@ -10,28 +10,28 @@ pub(super) trait SpecExtend { fn spec_extend(&mut self, iter: I); } -impl SpecExtend for Vec +impl SpecExtend for Vec where I: Iterator, - [(); alloc::co_alloc_metadata_num_slots::()]: + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { default fn spec_extend(&mut self, iter: I) { self.extend_desugared(iter) } } -impl SpecExtend for Vec +impl SpecExtend for Vec where I: TrustedLen, - [(); alloc::co_alloc_metadata_num_slots::()]: + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { default fn spec_extend(&mut self, iterator: I) { self.extend_trusted(iterator) } } -impl SpecExtend> for Vec -where [(); alloc::co_alloc_metadata_num_slots::()]: { +impl SpecExtend> for Vec +where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { fn spec_extend(&mut self, mut iterator: IntoIter) { unsafe { self.append_elements(iterator.as_slice() as _); @@ -40,21 +40,21 @@ where [(); alloc::co_alloc_metadata_num_slots::()]: { } } -impl<'a, T: 'a, I, A: Allocator + 'a> SpecExtend<&'a T, I> for Vec +impl<'a, T: 'a, I, A: Allocator + 'a, const COOP_PREFERRED: bool> SpecExtend<&'a T, I> for Vec where I: Iterator, T: Clone, - [(); alloc::co_alloc_metadata_num_slots::()]: + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { default fn spec_extend(&mut self, iterator: I) { self.spec_extend(iterator.cloned()) } } -impl<'a, T: 'a, A: Allocator + 'a> SpecExtend<&'a T, slice::Iter<'a, T>> for Vec +impl<'a, T: 'a, A: Allocator + 'a, const COOP_PREFERRED: bool> SpecExtend<&'a T, slice::Iter<'a, T>> for Vec where T: Copy, - [(); alloc::co_alloc_metadata_num_slots::()]: + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { fn spec_extend(&mut self, iterator: slice::Iter<'a, T>) { let slice = iterator.as_slice(); diff --git a/library/alloc/src/vec/spec_from_elem.rs b/library/alloc/src/vec/spec_from_elem.rs index 7f95539b12d96..682375a607837 100644 --- a/library/alloc/src/vec/spec_from_elem.rs +++ b/library/alloc/src/vec/spec_from_elem.rs @@ -8,13 +8,13 @@ use super::{ExtendElement, IsZero, Vec}; // Specialization trait used for Vec::from_elem pub(super) trait SpecFromElem: Sized { - fn from_elem(elem: Self, n: usize, alloc: A) -> Vec - where [(); alloc::co_alloc_metadata_num_slots::()]: ; + fn from_elem(elem: Self, n: usize, alloc: A) -> Vec + where [(); alloc::co_alloc_metadata_num_slots::(COOP_PREFERRED)]: ; } impl SpecFromElem for T { - default fn from_elem(elem: Self, n: usize, alloc: A) -> Vec - where [(); alloc::co_alloc_metadata_num_slots::()]: { + default fn from_elem(elem: Self, n: usize, alloc: A) -> Vec + where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { let mut v = Vec::with_capacity_in(n, alloc); v.extend_with(n, ExtendElement(elem)); v @@ -23,8 +23,8 @@ impl SpecFromElem for T { impl SpecFromElem for T { #[inline] - default fn from_elem(elem: T, n: usize, alloc: A) -> Vec - where [(); alloc::co_alloc_metadata_num_slots::()]: { + default fn from_elem(elem: T, n: usize, alloc: A) -> Vec + where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { if elem.is_zero() { return Vec { buf: RawVec::with_capacity_zeroed_in(n, alloc), len: n }; } @@ -36,8 +36,8 @@ impl SpecFromElem for T { impl SpecFromElem for i8 { #[inline] - fn from_elem(elem: i8, n: usize, alloc: A) -> Vec - where [(); alloc::co_alloc_metadata_num_slots::()]: { + fn from_elem(elem: i8, n: usize, alloc: A) -> Vec + where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { if elem == 0 { return Vec { buf: RawVec::with_capacity_zeroed_in(n, alloc), len: n }; } @@ -52,8 +52,8 @@ impl SpecFromElem for i8 { impl SpecFromElem for u8 { #[inline] - fn from_elem(elem: u8, n: usize, alloc: A) -> Vec - where [(); alloc::co_alloc_metadata_num_slots::()]: { + fn from_elem(elem: u8, n: usize, alloc: A) -> Vec + where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { if elem == 0 { return Vec { buf: RawVec::with_capacity_zeroed_in(n, alloc), len: n }; } From 8b1fbce739d935c712285db831263ed0f9e64769 Mon Sep 17 00:00:00 2001 From: Peter Kehl Date: Sat, 21 Jan 2023 21:53:30 -0800 Subject: [PATCH 014/118] CoAlloc: VecDeque. ICE --- library/alloc/src/collections/vec_deque/mod.rs | 13 ++++++++----- .../src/collections/vec_deque/spec_from_iter.rs | 11 ++++++++--- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/library/alloc/src/collections/vec_deque/mod.rs b/library/alloc/src/collections/vec_deque/mod.rs index 694a3d2624106..276c3f3f5967b 100644 --- a/library/alloc/src/collections/vec_deque/mod.rs +++ b/library/alloc/src/collections/vec_deque/mod.rs @@ -8,7 +8,7 @@ #![feature(global_co_alloc)] #![stable(feature = "rust1", since = "1.0.0")] -use core::alloc; +use core::alloc::{self, GlobalAlloc}; use core::cmp::{self, Ordering}; use core::fmt; use core::hash::{Hash, Hasher}; @@ -2758,8 +2758,9 @@ where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRE } #[stable(feature = "rust1", since = "1.0.0")] -impl FromIterator for VecDeque { - fn from_iter>(iter: I) -> VecDeque { +impl FromIterator for VecDeque +where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { + fn from_iter>(iter: I) -> VecDeque { SpecFromIter::spec_from_iter(iter.into_iter()) } } @@ -2855,7 +2856,8 @@ where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRE /// and to not re-allocate the `Vec`'s buffer or allocate /// any additional memory. #[inline] - fn from(other: Vec) -> Self { + fn from(other: Vec) -> Self + where [(); alloc::co_alloc_metadata_num_slots_with_preference::(OTHER_COOP_PREFERRED)]: { let (ptr, len, cap, alloc) = other.into_raw_parts_with_alloc(); Self { head: 0, len, buf: unsafe { RawVec::from_raw_parts_in(ptr, cap, alloc) } } } @@ -2913,7 +2915,8 @@ where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRE } #[stable(feature = "std_collections_from_array", since = "1.56.0")] -impl From<[T; N]> for VecDeque { +impl From<[T; N]> for VecDeque +where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { /// Converts a `[T; N]` into a `VecDeque`. /// /// ``` diff --git a/library/alloc/src/collections/vec_deque/spec_from_iter.rs b/library/alloc/src/collections/vec_deque/spec_from_iter.rs index 7650492ebdad1..b9641ef156c88 100644 --- a/library/alloc/src/collections/vec_deque/spec_from_iter.rs +++ b/library/alloc/src/collections/vec_deque/spec_from_iter.rs @@ -1,13 +1,16 @@ use super::{IntoIter, VecDeque}; +use crate::alloc::Allocator; +use core::alloc; /// Specialization trait used for `VecDeque::from_iter` pub(super) trait SpecFromIter { fn spec_from_iter(iter: I) -> Self; } -impl SpecFromIter for VecDeque +impl SpecFromIter for VecDeque where I: Iterator, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { default fn spec_from_iter(iterator: I) -> Self { // Since converting is O(1) now, just re-use the `Vec` logic for @@ -18,14 +21,16 @@ where } } -impl SpecFromIter> for VecDeque { +impl SpecFromIter> for VecDeque +where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { #[inline] fn spec_from_iter(iterator: crate::vec::IntoIter) -> Self { iterator.into_vecdeque() } } -impl SpecFromIter> for VecDeque { +impl SpecFromIter> for VecDeque +where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { #[inline] fn spec_from_iter(iterator: IntoIter) -> Self { iterator.into_vecdeque() From 0ec3f924fd70a88ac3989cf52e4485aeb0729a9e Mon Sep 17 00:00:00 2001 From: Peter Kehl Date: Sat, 21 Jan 2023 21:59:55 -0800 Subject: [PATCH 015/118] CoAlloc: Minor --- library/core/src/alloc/global.rs | 4 ++-- library/core/src/alloc/mod.rs | 11 ++++++----- library/std/src/alloc.rs | 2 +- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/library/core/src/alloc/global.rs b/library/core/src/alloc/global.rs index 26308e63a7bad..31d9ab6c8d04e 100644 --- a/library/core/src/alloc/global.rs +++ b/library/core/src/alloc/global.rs @@ -166,7 +166,7 @@ pub unsafe trait GlobalAlloc { unsafe fn alloc(&self, layout: Layout) -> *mut u8; #[unstable(feature = "global_co_alloc", issue = "none")] - unsafe fn co_alloc(&self, _layout: Layout, mut _result: &mut RawAndMeta) {panic!("TODO")} + unsafe fn co_alloc(&self, _layout: Layout, mut _result: &mut RawAndMeta) {panic!("@FIXME")} /// Deallocate the block of memory at the given `ptr` pointer with the given `layout`. /// @@ -184,7 +184,7 @@ pub unsafe trait GlobalAlloc { unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout); #[unstable(feature = "global_co_alloc", issue = "none")] - unsafe fn co_dealloc(&self, _ptr_and_meta: RawAndMeta, _layout: Layout) {panic!("TODO")} + unsafe fn co_dealloc(&self, _ptr_and_meta: RawAndMeta, _layout: Layout) {panic!("@FIXME")} /// Behaves like `alloc`, but also ensures that the contents /// are set to zero before being returned. diff --git a/library/core/src/alloc/mod.rs b/library/core/src/alloc/mod.rs index 9359273ca0a3a..7993e8e546d89 100644 --- a/library/core/src/alloc/mod.rs +++ b/library/core/src/alloc/mod.rs @@ -25,7 +25,7 @@ use crate::error::Error; use crate::fmt; use crate::ptr::{self, NonNull}; -// @TODO Make this target-specific +// @FIXME Make this target-specific #[unstable(feature = "global_co_alloc_meta", issue = "none")] #[allow(missing_debug_implementations)] #[derive(Clone, Copy)] @@ -156,7 +156,8 @@ pub unsafe trait Allocator { // Can't have: const type Xyz; /// If this is any type with non-zero size, then the actual `Allocator` implementation supports cooperative functions (`co_*`) as first class citizens. //type IsCoAllocator = (); - // It applies to the global (default) allocator only. And/or System allocator?! TODO + // It applies to the global (default) allocator only. And/or System allocator?! @FIXME + // @FIXME make false by default const IS_CO_ALLOCATOR: bool = true; /// Attempts to allocate a block of memory. @@ -181,7 +182,7 @@ pub unsafe trait Allocator { /// [`handle_alloc_error`]: ../../alloc/alloc/fn.handle_alloc_error.html fn allocate(&self, layout: Layout) -> Result, AllocError>; - fn co_allocate(&self, _layout: Layout, _result: &mut SliceAndMetaResult) {panic!("TODO")} + fn co_allocate(&self, _layout: Layout, _result: &mut SliceAndMetaResult) {panic!("FIXME")} /// Behaves like `allocate`, but also ensures that the returned memory is zero-initialized. /// @@ -229,7 +230,7 @@ pub unsafe trait Allocator { /// [*fit*]: #memory-fitting unsafe fn deallocate(&self, ptr: NonNull, layout: Layout); - unsafe fn co_deallocate(&self, _ptr_and_meta: PtrAndMeta, _layout: Layout) {panic!("TODO")} + unsafe fn co_deallocate(&self, _ptr_and_meta: PtrAndMeta, _layout: Layout) {panic!("FIXME")} /// Attempts to extend the memory block. /// @@ -527,7 +528,7 @@ pub unsafe trait Allocator { } } -// @TODO +// @FIXME #[unstable(feature = "allocator_api", issue = "32838")] unsafe impl Allocator for &A where diff --git a/library/std/src/alloc.rs b/library/std/src/alloc.rs index bee6edbc40731..6969c7d81dd5e 100644 --- a/library/std/src/alloc.rs +++ b/library/std/src/alloc.rs @@ -197,7 +197,7 @@ impl System { } } -// @TODO +// @FIXME // The Allocator impl checks the layout size to be non-zero and forwards to the GlobalAlloc impl, // which is in `std::sys::*::alloc`. #[unstable(feature = "allocator_api", issue = "32838")] From 8fb11961db5aae2ee5e96192afd8210b808b3030 Mon Sep 17 00:00:00 2001 From: Peter Kehl Date: Sat, 21 Jan 2023 22:00:15 -0800 Subject: [PATCH 016/118] CoAlloc: Vec + its use cases. ICE --- library/alloc/src/raw_vec.rs | 8 ++--- library/alloc/src/vec/mod.rs | 30 ++++++++++++------- library/std/src/io/cursor.rs | 25 ++++++++++------ library/std/src/io/impls.rs | 3 +- .../std/src/sys/hermit/thread_local_dtor.rs | 4 ++- .../std/src/sys/solid/thread_local_dtor.rs | 6 ++-- library/std/src/sys/unix/thread_local_dtor.rs | 5 +++- .../std/src/sys/windows/thread_local_dtor.rs | 5 +++- 8 files changed, 57 insertions(+), 29 deletions(-) diff --git a/library/alloc/src/raw_vec.rs b/library/alloc/src/raw_vec.rs index 36ef3bf13661a..a8e32387bed41 100644 --- a/library/alloc/src/raw_vec.rs +++ b/library/alloc/src/raw_vec.rs @@ -14,6 +14,7 @@ use crate::alloc::{Allocator, Global, Layout}; use crate::boxed::Box; use crate::collections::TryReserveError; use crate::collections::TryReserveErrorKind::*; +use crate::vec::DEFAULT_COOP_PREFERRED; #[cfg(test)] mod tests; @@ -49,8 +50,7 @@ enum AllocInit { /// `usize::MAX`. This means that you need to be careful when round-tripping this type with a /// `Box<[T]>`, since `capacity()` won't yield the length. #[allow(missing_debug_implementations)] -// @TODO apply `_coop` with logical && to `A::IsCoAllocator` -pub(crate) struct RawVec +pub(crate) struct RawVec where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { ptr: Unique, @@ -513,12 +513,12 @@ where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRE } } -// @TODO Custom +// @FIXME Custom unsafe impl<#[may_dangle] T, const COOP_PREFERRED: bool> Drop for RawVec where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { /// Frees the memory owned by the `RawVec` *without* trying to drop its contents. fn drop(&mut self) { - // @TODO + // @TOFIXMEDO if let Some((ptr, layout)) = self.current_memory() { unsafe { self.alloc.deallocate(ptr, layout) } } diff --git a/library/alloc/src/vec/mod.rs b/library/alloc/src/vec/mod.rs index 567feb3903f67..10af6f6a8f364 100644 --- a/library/alloc/src/vec/mod.rs +++ b/library/alloc/src/vec/mod.rs @@ -397,24 +397,34 @@ mod spec_extend; #[stable(feature = "rust1", since = "1.0.0")] #[cfg_attr(not(test), rustc_diagnostic_item = "Vec")] #[rustc_insignificant_dtor] -// @TODO _coop -pub struct Vec +pub struct Vec where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { buf: RawVec, len: usize, } -#[unstable(feature = "global_co_alloc_vec", issue = "none")] -pub type CoVec = Vec; +#[unstable(feature = "global_co_alloc_covec", issue = "none")] +pub type CoVec = Vec; + +/// "Plain" Vec. Not "cooperative" - not carrying extra data to assist the allocator. +#[unstable(feature = "global_co_alloc_plvec", issue = "none")] +pub type PlVec = Vec; + +/// Default `Vec`, `DefVec`, `DecVeque`, `DefDecVeq` "cooperation" (`COOP_PREFERRED`) generic parameter. +#[unstable(feature = "global_co_alloc_def", issue = "none")] +pub const DEFAULT_COOP_PREFERRED: bool = true; + +/// "Default" Vec. Either "cooperative" or not - as specified by `DEFAULT_COOP_PREFERRED`. The +/// difference to `Vec` (used without specifying `COOP_PREFERRED`): `DefVec` indicates that the +/// author considered using `CoVec` or `PlVec`, but left it to default instead. +#[unstable(feature = "global_co_alloc_defvec", issue = "none")] +pub type DefVec = Vec; -/// "Plain" Vec. -#[unstable(feature = "global_co_alloc_vec", issue = "none")] -pub type PlVec = Vec; -/// "Weighted" Vec. -/// weight means how much it wants to cooperate. 0 = always pack; u8::MAX = always coop (if `Global` supports it). -/// @TODO Weighing on the side of Allocator - const fn. +/// "Weighted cooperative" Vec. Weight means how much it wants to cooperate (with the allocator). 0 +/// = always pack; u8::MAX = always cooperate (if `Global` supports it). +/// @FIXME A `pub const` threshold. #[unstable(feature = "global_co_alloc_vec", issue = "none")] pub type WeVec = Vec1}>; diff --git a/library/std/src/io/cursor.rs b/library/std/src/io/cursor.rs index d98ab021cadb1..33d1ee065de2a 100644 --- a/library/std/src/io/cursor.rs +++ b/library/std/src/io/cursor.rs @@ -6,6 +6,7 @@ use crate::io::prelude::*; use crate::alloc::Allocator; use crate::cmp; use crate::io::{self, BorrowedCursor, ErrorKind, IoSlice, IoSliceMut, SeekFrom}; +use core::alloc; /// A `Cursor` wraps an in-memory buffer and provides it with a /// [`Seek`] implementation. @@ -397,11 +398,12 @@ fn slice_write_vectored( } /// Reserves the required space, and pads the vec with 0s if necessary. -fn reserve_and_pad( +fn reserve_and_pad( pos_mut: &mut u64, - vec: &mut Vec, + vec: &mut Vec, buf_len: usize, -) -> io::Result { +) -> io::Result +where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { let pos: usize = (*pos_mut).try_into().map_err(|_| { io::const_io_error!( ErrorKind::InvalidInput, @@ -440,9 +442,10 @@ fn reserve_and_pad( /// Writes the slice to the vec without allocating /// # Safety: vec must have buf.len() spare capacity -unsafe fn vec_write_unchecked(pos: usize, vec: &mut Vec, buf: &[u8]) -> usize +unsafe fn vec_write_unchecked(pos: usize, vec: &mut Vec, buf: &[u8]) -> usize where A: Allocator, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { debug_assert!(vec.capacity() >= pos + buf.len()); vec.as_mut_ptr().add(pos).copy_from(buf.as_ptr(), buf.len()); @@ -458,9 +461,10 @@ where /// This also allows for the vec body to be empty, but with a position of N. /// This means that [`Write`] will pad the vec with 0 initially, /// before writing anything from that point -fn vec_write(pos_mut: &mut u64, vec: &mut Vec, buf: &[u8]) -> io::Result +fn vec_write(pos_mut: &mut u64, vec: &mut Vec, buf: &[u8]) -> io::Result where A: Allocator, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { let buf_len = buf.len(); let mut pos = reserve_and_pad(pos_mut, vec, buf_len)?; @@ -489,13 +493,14 @@ where /// This also allows for the vec body to be empty, but with a position of N. /// This means that [`Write`] will pad the vec with 0 initially, /// before writing anything from that point -fn vec_write_vectored( +fn vec_write_vectored( pos_mut: &mut u64, - vec: &mut Vec, + vec: &mut Vec, bufs: &[IoSlice<'_>], ) -> io::Result where A: Allocator, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { // For safety reasons, we don't want this sum to overflow ever. // If this saturates, the reserve should panic to avoid any unsound writing. @@ -543,9 +548,10 @@ impl Write for Cursor<&mut [u8]> { } #[stable(feature = "cursor_mut_vec", since = "1.25.0")] -impl Write for Cursor<&mut Vec> +impl Write for Cursor<&mut Vec> where A: Allocator, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { fn write(&mut self, buf: &[u8]) -> io::Result { vec_write(&mut self.pos, self.inner, buf) @@ -567,9 +573,10 @@ where } #[stable(feature = "rust1", since = "1.0.0")] -impl Write for Cursor> +impl Write for Cursor> where A: Allocator, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { fn write(&mut self, buf: &[u8]) -> io::Result { vec_write(&mut self.pos, &mut self.inner, buf) diff --git a/library/std/src/io/impls.rs b/library/std/src/io/impls.rs index d575d9fa3f990..ec3394e0b16c1 100644 --- a/library/std/src/io/impls.rs +++ b/library/std/src/io/impls.rs @@ -378,7 +378,8 @@ impl Write for &mut [u8] { /// Write is implemented for `Vec` by appending to the vector. /// The vector will grow as needed. #[stable(feature = "rust1", since = "1.0.0")] -impl Write for Vec { +impl Write for Vec +where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { #[inline] fn write(&mut self, buf: &[u8]) -> io::Result { self.extend_from_slice(buf); diff --git a/library/std/src/sys/hermit/thread_local_dtor.rs b/library/std/src/sys/hermit/thread_local_dtor.rs index 613266b9530a8..9816a7f200b6f 100644 --- a/library/std/src/sys/hermit/thread_local_dtor.rs +++ b/library/std/src/sys/hermit/thread_local_dtor.rs @@ -1,14 +1,16 @@ #![cfg(target_thread_local)] #![unstable(feature = "thread_local_internals", issue = "none")] +#![feature(global_co_alloc_plvec)] // Simplify dtor registration by using a list of destructors. // The this solution works like the implementation of macOS and // doesn't additional OS support +use core::alloc::PlVec; use crate::mem; #[thread_local] -static mut DTORS: Vec<(*mut u8, unsafe extern "C" fn(*mut u8))> = Vec::new(); +static mut DTORS: PlVec<(*mut u8, unsafe extern "C" fn(*mut u8))> = PlVec::new(); pub unsafe fn register_dtor(t: *mut u8, dtor: unsafe extern "C" fn(*mut u8)) { let list = &mut DTORS; diff --git a/library/std/src/sys/solid/thread_local_dtor.rs b/library/std/src/sys/solid/thread_local_dtor.rs index bad14bb37f720..5468264393b55 100644 --- a/library/std/src/sys/solid/thread_local_dtor.rs +++ b/library/std/src/sys/solid/thread_local_dtor.rs @@ -1,17 +1,19 @@ #![cfg(target_thread_local)] -#![unstable(feature = "thread_local_internals", issue = "none")] +#![unstable(feature = "thread_local_internals", issue = "none")]#![feature(global_co_alloc_plvec)] +#![feature(global_co_alloc_plvec)] // Simplify dtor registration by using a list of destructors. use super::{abi, itron::task}; use crate::cell::Cell; use crate::mem; +use core::alloc::PlVec; #[thread_local] static REGISTERED: Cell = Cell::new(false); #[thread_local] -static mut DTORS: Vec<(*mut u8, unsafe extern "C" fn(*mut u8))> = Vec::new(); +static mut DTORS: PlVec<(*mut u8, unsafe extern "C" fn(*mut u8))> = PlVec::new(); pub unsafe fn register_dtor(t: *mut u8, dtor: unsafe extern "C" fn(*mut u8)) { if !REGISTERED.get() { diff --git a/library/std/src/sys/unix/thread_local_dtor.rs b/library/std/src/sys/unix/thread_local_dtor.rs index 236d2f2ee2928..1929c1be317b7 100644 --- a/library/std/src/sys/unix/thread_local_dtor.rs +++ b/library/std/src/sys/unix/thread_local_dtor.rs @@ -1,5 +1,8 @@ #![cfg(target_thread_local)] #![unstable(feature = "thread_local_internals", issue = "none")] +#![feature(global_co_alloc_plvec)] + +use core::alloc::PlVec; //! Provides thread-local destructors without an associated "key", which //! can be more efficient. @@ -58,7 +61,7 @@ pub unsafe fn register_dtor(t: *mut u8, dtor: unsafe extern "C" fn(*mut u8)) { static REGISTERED: Cell = Cell::new(false); #[thread_local] - static mut DTORS: Vec<(*mut u8, unsafe extern "C" fn(*mut u8))> = Vec::new(); + static mut DTORS: PlVec<(*mut u8, unsafe extern "C" fn(*mut u8))> = PlVec::new(); if !REGISTERED.get() { _tlv_atexit(run_dtors, ptr::null_mut()); diff --git a/library/std/src/sys/windows/thread_local_dtor.rs b/library/std/src/sys/windows/thread_local_dtor.rs index 9707a95dff21b..cbadd2dd23aea 100644 --- a/library/std/src/sys/windows/thread_local_dtor.rs +++ b/library/std/src/sys/windows/thread_local_dtor.rs @@ -3,10 +3,13 @@ #![unstable(feature = "thread_local_internals", issue = "none")] #![cfg(target_thread_local)] +#![feature(global_co_alloc_plvec)] + +use core::alloc::PlVec; // Using a per-thread list avoids the problems in synchronizing global state. #[thread_local] -static mut DESTRUCTORS: Vec<(*mut u8, unsafe extern "C" fn(*mut u8))> = Vec::new(); +static mut DESTRUCTORS: PlVec<(*mut u8, unsafe extern "C" fn(*mut u8))> = Vec::new(); // Ensure this can never be inlined because otherwise this may break in dylibs. // See #44391. From 215a2b4933ea012ddcfb11684d20e22ca7ca1fa3 Mon Sep 17 00:00:00 2001 From: Peter Kehl Date: Sat, 21 Jan 2023 22:00:42 -0800 Subject: [PATCH 017/118] CoAlloc: VecDeque minor. ICE --- library/alloc/src/collections/vec_deque/mod.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/library/alloc/src/collections/vec_deque/mod.rs b/library/alloc/src/collections/vec_deque/mod.rs index 276c3f3f5967b..a7ac80269bd90 100644 --- a/library/alloc/src/collections/vec_deque/mod.rs +++ b/library/alloc/src/collections/vec_deque/mod.rs @@ -9,6 +9,7 @@ #![stable(feature = "rust1", since = "1.0.0")] use core::alloc::{self, GlobalAlloc}; +use crate::vec::DEFAULT_COOP_PREFERRED; use core::cmp::{self, Ordering}; use core::fmt; use core::hash::{Hash, Hasher}; @@ -93,11 +94,10 @@ mod tests; #[cfg_attr(not(test), rustc_diagnostic_item = "VecDeque")] #[stable(feature = "rust1", since = "1.0.0")] #[rustc_insignificant_dtor] -// @TODO pub struct VecDeque< T, #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global, - const COOP_PREFERRED: bool = true + const COOP_PREFERRED: bool = DEFAULT_COOP_PREFERRED > where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { @@ -2908,7 +2908,7 @@ where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRE if other.head != 0 { ptr::copy(buf.add(other.head), buf, len); } - // @TODO: + // @FIXME: COOP Vec::from_raw_parts_in(buf, len, cap, alloc) } } From 9a2c01a8af40d6f9574865513eb89bc51a8ae278 Mon Sep 17 00:00:00 2001 From: Peter Kehl Date: Sat, 21 Jan 2023 22:06:08 -0800 Subject: [PATCH 018/118] CoAlloc: Vec, Alloc, GlobalAlloc: x test tidy --bless. ICE --- compiler/rustc_middle/src/mir/mod.rs | 2 +- compiler/rustc_middle/src/mir/syntax.rs | 2 +- .../rustc_parse/src/parser/attr_wrapper.rs | 2 +- compiler/rustc_parse/src/parser/mod.rs | 2 +- library/alloc/src/boxed.rs | 34 ++- library/alloc/src/raw_vec.rs | 65 +++-- library/alloc/src/slice.rs | 62 +++-- library/alloc/src/vec/drain.rs | 90 +++++-- library/alloc/src/vec/drain_filter.rs | 23 +- library/alloc/src/vec/into_iter.rs | 123 +++++++--- library/alloc/src/vec/mod.rs | 222 +++++++++++++----- library/alloc/src/vec/spec_extend.rs | 23 +- library/alloc/src/vec/spec_from_elem.rs | 51 +++- library/alloc/src/vec/splice.rs | 29 ++- library/alloc/tests/boxed.rs | 2 +- library/core/src/alloc/global.rs | 12 +- library/core/src/alloc/mod.rs | 33 +-- library/std/src/io/cursor.rs | 26 +- library/std/src/io/impls.rs | 12 +- library/std/src/sys/unix/thread_local_dtor.rs | 4 +- src/librustdoc/html/render/context.rs | 5 +- 21 files changed, 582 insertions(+), 242 deletions(-) diff --git a/compiler/rustc_middle/src/mir/mod.rs b/compiler/rustc_middle/src/mir/mod.rs index cc02a3eb97158..c09fd09f1ae86 100644 --- a/compiler/rustc_middle/src/mir/mod.rs +++ b/compiler/rustc_middle/src/mir/mod.rs @@ -2,7 +2,6 @@ //! //! [rustc dev guide]: https://rustc-dev-guide.rust-lang.org/mir/index.html -use core::alloc::GlobalCoAllocMeta; use crate::mir::interpret::{ AllocRange, ConstAllocation, ConstValue, ErrorHandled, GlobalAlloc, LitToConstInput, Scalar, }; @@ -14,6 +13,7 @@ use crate::ty::visit::{TypeVisitable, TypeVisitor}; use crate::ty::{self, ir, DefIdTree, List, Ty, TyCtxt}; use crate::ty::{AdtDef, InstanceDef, ScalarInt, UserTypeAnnotationIndex}; use crate::ty::{GenericArg, InternalSubsts, SubstsRef}; +use core::alloc::GlobalCoAllocMeta; use rustc_data_structures::captures::Captures; use rustc_errors::ErrorGuaranteed; diff --git a/compiler/rustc_middle/src/mir/syntax.rs b/compiler/rustc_middle/src/mir/syntax.rs index 26ac845194fe5..0b6304364b505 100644 --- a/compiler/rustc_middle/src/mir/syntax.rs +++ b/compiler/rustc_middle/src/mir/syntax.rs @@ -3,9 +3,9 @@ //! This is in a dedicated file so that changes to this file can be reviewed more carefully. //! The intention is that this file only contains datatype declarations, no code. +use super::{BasicBlock, Constant, Field, Local, SwitchTargets, UserTypeProjection}; use core::alloc::GlobalCoAllocMeta; use core::mem; -use super::{BasicBlock, Constant, Field, Local, SwitchTargets, UserTypeProjection}; use crate::mir::coverage::{CodeRegion, CoverageKind}; use crate::traits::Reveal; diff --git a/compiler/rustc_parse/src/parser/attr_wrapper.rs b/compiler/rustc_parse/src/parser/attr_wrapper.rs index 15833cdf268d7..3d541cad22cf5 100644 --- a/compiler/rustc_parse/src/parser/attr_wrapper.rs +++ b/compiler/rustc_parse/src/parser/attr_wrapper.rs @@ -1,6 +1,6 @@ +use super::{Capturing, FlatToken, ForceCollect, Parser, ReplaceRange, TokenCursor, TrailingToken}; use core::alloc::GlobalCoAllocMeta; use core::mem; -use super::{Capturing, FlatToken, ForceCollect, Parser, ReplaceRange, TokenCursor, TrailingToken}; use rustc_ast::token::{self, Delimiter, Token, TokenKind}; use rustc_ast::tokenstream::{AttrTokenStream, AttributesData, ToAttrTokenStream}; use rustc_ast::tokenstream::{AttrTokenTree, DelimSpan, LazyAttrTokenStream, Spacing}; diff --git a/compiler/rustc_parse/src/parser/mod.rs b/compiler/rustc_parse/src/parser/mod.rs index f058907f188ea..7fb4e60f8a14f 100644 --- a/compiler/rustc_parse/src/parser/mod.rs +++ b/compiler/rustc_parse/src/parser/mod.rs @@ -11,8 +11,8 @@ mod stmt; mod ty; use crate::lexer::UnmatchedBrace; -use core::alloc::GlobalCoAllocMeta; pub use attr_wrapper::AttrWrapper; +use core::alloc::GlobalCoAllocMeta; pub use diagnostics::AttemptLocalParseRecovery; pub(crate) use item::FnParseMode; pub use pat::{CommaRecoveryMode, RecoverColon, RecoverComma}; diff --git a/library/alloc/src/boxed.rs b/library/alloc/src/boxed.rs index 9dc695559a80e..021f36e6770bd 100644 --- a/library/alloc/src/boxed.rs +++ b/library/alloc/src/boxed.rs @@ -699,7 +699,12 @@ impl Box<[T]> { Err(_) => return Err(AllocError), }; let ptr = Global.allocate(layout)?; - Ok(RawVec::::from_raw_parts_in(ptr.as_mut_ptr() as *mut _, len, Global).into_box(len)) + Ok(RawVec::::from_raw_parts_in( + ptr.as_mut_ptr() as *mut _, + len, + Global, + ) + .into_box(len)) } } @@ -731,13 +736,20 @@ impl Box<[T]> { Err(_) => return Err(AllocError), }; let ptr = Global.allocate_zeroed(layout)?; - Ok(RawVec::::from_raw_parts_in(ptr.as_mut_ptr() as *mut _, len, Global).into_box(len)) + Ok(RawVec::::from_raw_parts_in( + ptr.as_mut_ptr() as *mut _, + len, + Global, + ) + .into_box(len)) } } } impl Box<[T], A> -where [(); core::alloc::co_alloc_metadata_num_slots::()]: { +where + [(); core::alloc::co_alloc_metadata_num_slots::()]:, +{ /// Constructs a new boxed slice with uninitialized contents in the provided allocator. /// /// # Examples @@ -765,7 +777,10 @@ where [(); core::alloc::co_alloc_metadata_num_slots::()]: { // #[unstable(feature = "new_uninit", issue = "63291")] #[must_use] pub fn new_uninit_slice_in(len: usize, alloc: A) -> Box<[mem::MaybeUninit], A> { - unsafe { RawVec::::with_capacity_in(len, alloc).into_box(len) } + unsafe { + RawVec::::with_capacity_in(len, alloc) + .into_box(len) + } } /// Constructs a new boxed slice with uninitialized contents in the provided allocator, @@ -793,7 +808,12 @@ where [(); core::alloc::co_alloc_metadata_num_slots::()]: { // #[unstable(feature = "new_uninit", issue = "63291")] #[must_use] pub fn new_zeroed_slice_in(len: usize, alloc: A) -> Box<[mem::MaybeUninit], A> { - unsafe { RawVec::::with_capacity_zeroed_in(len, alloc).into_box(len) } + unsafe { + RawVec::::with_capacity_zeroed_in( + len, alloc, + ) + .into_box(len) + } } } @@ -2022,7 +2042,9 @@ impl FromIterator for Box<[I]> { #[cfg(not(no_global_oom_handling))] #[stable(feature = "box_slice_clone", since = "1.3.0")] impl Clone for Box<[T], A> -where [(); core::alloc::co_alloc_metadata_num_slots::()]: { +where + [(); core::alloc::co_alloc_metadata_num_slots::()]:, +{ fn clone(&self) -> Self { let alloc = Box::allocator(self).clone(); self.to_vec_in(alloc).into_boxed_slice() diff --git a/library/alloc/src/raw_vec.rs b/library/alloc/src/raw_vec.rs index a8e32387bed41..ddca063387d57 100644 --- a/library/alloc/src/raw_vec.rs +++ b/library/alloc/src/raw_vec.rs @@ -1,6 +1,6 @@ #![unstable(feature = "raw_vec_internals", reason = "unstable const warnings", issue = "none")] -use core::alloc::{self, LayoutError, GlobalCoAllocMeta, PtrAndMeta}; +use core::alloc::{self, GlobalCoAllocMeta, LayoutError, PtrAndMeta}; use core::cmp; use core::intrinsics; use core::mem::{self, ManuallyDrop, MaybeUninit, SizedTypeProperties}; @@ -50,8 +50,12 @@ enum AllocInit { /// `usize::MAX`. This means that you need to be careful when round-tripping this type with a /// `Box<[T]>`, since `capacity()` won't yield the length. #[allow(missing_debug_implementations)] -pub(crate) struct RawVec -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: +pub(crate) struct RawVec< + T, + A: Allocator = Global, + const COOP_PREFERRED: bool = DEFAULT_COOP_PREFERRED, +> where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { ptr: Unique, cap: usize, @@ -59,11 +63,14 @@ where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRE // As of v1.67.0, `cmp` for `TypeId` is not `const`, unfortunately: //pub(crate) meta: [GlobalCoAllocMeta; {if core::any::TypeId::of::()==core::any::TypeId::of::() {1} else {0}}], //pub(crate) meta: [GlobalCoAllocMeta; mem::size_of::()], - pub(crate) metas: [GlobalCoAllocMeta; alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)], + pub(crate) metas: [GlobalCoAllocMeta; + alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)], } impl RawVec -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ /// HACK(Centril): This exists because stable `const fn` can only call stable `const fn`, so /// they cannot call `Self::new()`. /// @@ -111,7 +118,8 @@ where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PRE } impl RawVec -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: +where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { // Tiny Vecs are dumb. Skip to: // - 8 if the element size is 1, because any heap allocators is likely @@ -130,8 +138,13 @@ where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRE /// the returned `RawVec`. pub const fn new_in(alloc: A) -> Self { // `cap: 0` means "unallocated". zero-sized types are ignored. - Self { ptr: Unique::dangling(), cap: 0, alloc, - metas: [GlobalCoAllocMeta {/*one: 1*/ /* , two: 2, three: 3, four: 4*/}; alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)] } + Self { + ptr: Unique::dangling(), + cap: 0, + alloc, + metas: [GlobalCoAllocMeta {/*one: 1*/ /* , two: 2, three: 3, four: 4*/}; + alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)], + } } /// Like `with_capacity`, but parameterized over the choice of @@ -208,7 +221,8 @@ where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRE ptr: unsafe { Unique::new_unchecked(ptr.cast().as_ptr()) }, cap: capacity, alloc, - metas: [GlobalCoAllocMeta {/*one: 1*/ /*, two: 2, three: 3, four: 4*/}; alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)] + metas: [GlobalCoAllocMeta {/*one: 1*/ /*, two: 2, three: 3, four: 4*/}; + alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)], } } } @@ -225,7 +239,13 @@ where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRE /// guaranteed. #[inline] pub unsafe fn from_raw_parts_in(ptr: *mut T, capacity: usize, alloc: A) -> Self { - Self { ptr: unsafe { Unique::new_unchecked(ptr) }, cap: capacity, alloc, metas: [GlobalCoAllocMeta {/*one: 1*/ /*, two: 2, three: 3, four: 4*/}; alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)] } + Self { + ptr: unsafe { Unique::new_unchecked(ptr) }, + cap: capacity, + alloc, + metas: [GlobalCoAllocMeta {/*one: 1*/ /*, two: 2, three: 3, four: 4*/}; + alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)], + } } /// Gets a raw pointer to the start of the allocation. Note that this is @@ -298,8 +318,8 @@ where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRE slf: &mut RawVec, len: usize, additional: usize, - ) - where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: + ) where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { handle_reserve(slf.grow_amortized(len, additional)); } @@ -374,17 +394,16 @@ where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRE } impl RawVec -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: +where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { /// Returns if the buffer needs to grow to fulfill the needed extra capacity. /// Mainly used to make inlining reserve-calls possible without inlining `grow`. - fn needs_to_grow(&self, len: usize, additional: usize) -> bool - { + fn needs_to_grow(&self, len: usize, additional: usize) -> bool { additional > self.capacity().wrapping_sub(len) } - fn set_ptr_and_cap(&mut self, ptr: NonNull<[u8]>, cap: usize) - { + fn set_ptr_and_cap(&mut self, ptr: NonNull<[u8]>, cap: usize) { // Allocators currently return a `NonNull<[u8]>` whose length matches // the size requested. If that ever changes, the capacity here should // change to `ptr.len() / mem::size_of::()`. @@ -497,15 +516,17 @@ where memory.map_err(|_| AllocError { layout: new_layout, non_exhaustive: () }.into()) } -unsafe impl<#[may_dangle] T, A: Allocator, const COOP_PREFERRED: bool> Drop for RawVec -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: +unsafe impl<#[may_dangle] T, A: Allocator, const COOP_PREFERRED: bool> Drop + for RawVec +where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { /// Frees the memory owned by the `RawVec` *without* trying to drop its contents. default fn drop(&mut self) { if let Some((ptr, layout)) = self.current_memory() { if A::IS_CO_ALLOCATOR && COOP_PREFERRED { let meta = self.metas[0]; - unsafe { self.alloc.co_deallocate(PtrAndMeta {ptr, meta}, layout) } + unsafe { self.alloc.co_deallocate(PtrAndMeta { ptr, meta }, layout) } } else { unsafe { self.alloc.deallocate(ptr, layout) } } @@ -515,7 +536,9 @@ where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRE // @FIXME Custom unsafe impl<#[may_dangle] T, const COOP_PREFERRED: bool> Drop for RawVec -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ /// Frees the memory owned by the `RawVec` *without* trying to drop its contents. fn drop(&mut self) { // @TOFIXMEDO diff --git a/library/alloc/src/slice.rs b/library/alloc/src/slice.rs index 2c9860ab66644..f0c90874d1d0d 100644 --- a/library/alloc/src/slice.rs +++ b/library/alloc/src/slice.rs @@ -97,8 +97,12 @@ pub(crate) mod hack { // We shouldn't add inline attribute to this since this is used in // `vec!` macro mostly and causes perf regression. See #71204 for // discussion and perf results. - pub fn into_vec(b: Box<[T], A>) -> Vec - where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { + pub fn into_vec( + b: Box<[T], A>, + ) -> Vec + where + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + { unsafe { let len = b.len(); let (b, alloc) = Box::into_raw_with_allocator(b); @@ -108,14 +112,22 @@ pub(crate) mod hack { #[cfg(not(no_global_oom_handling))] #[inline] - pub fn to_vec(s: &[T], alloc: A) -> Vec - where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { + pub fn to_vec( + s: &[T], + alloc: A, + ) -> Vec + where + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + { T::to_vec(s, alloc) } #[cfg(not(no_global_oom_handling))] pub trait ConvertVec { - fn to_vec(s: &[Self], alloc: A) -> Vec + fn to_vec( + s: &[Self], + alloc: A, + ) -> Vec where Self: Sized, [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:; @@ -124,15 +136,24 @@ pub(crate) mod hack { #[cfg(not(no_global_oom_handling))] impl ConvertVec for T { #[inline] - default fn to_vec(s: &[Self], alloc: A) -> Vec - where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { + default fn to_vec( + s: &[Self], + alloc: A, + ) -> Vec + where + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + { struct DropGuard<'a, T, A: Allocator, const COOP_PREFERRED: bool> - where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { + where + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + { vec: &'a mut Vec, num_init: usize, } impl<'a, T, A: Allocator, const COOP_PREFERRED: bool> Drop for DropGuard<'a, T, A, COOP_PREFERRED> - where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { + where + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + { #[inline] fn drop(&mut self) { // SAFETY: @@ -164,8 +185,13 @@ pub(crate) mod hack { #[cfg(not(no_global_oom_handling))] impl ConvertVec for T { #[inline] - fn to_vec(s: &[Self], alloc: A) -> Vec - where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { + fn to_vec( + s: &[Self], + alloc: A, + ) -> Vec + where + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + { let mut v = Vec::with_capacity_in(s.len(), alloc); // SAFETY: // allocated above with the capacity of `s`, and initialize to `s.len()` in @@ -443,7 +469,7 @@ impl [T] { pub fn to_vec_in(&self, alloc: A) -> Vec where T: Clone, - [(); core::alloc::co_alloc_metadata_num_slots::()]: + [(); core::alloc::co_alloc_metadata_num_slots::()]:, { // N.B., see the `hack` module in this file for more details. hack::to_vec(self, alloc) @@ -467,7 +493,9 @@ impl [T] { #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn into_vec(self: Box) -> Vec - where [(); core::alloc::co_alloc_metadata_num_slots::()]: { + where + [(); core::alloc::co_alloc_metadata_num_slots::()]:, + { // N.B., see the `hack` module in this file for more details. hack::into_vec(self) } @@ -779,7 +807,9 @@ impl> Join<&[T]> for [V] { #[stable(feature = "rust1", since = "1.0.0")] impl Borrow<[T]> for Vec -where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +where + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ fn borrow(&self) -> &[T] { &self[..] } @@ -787,7 +817,9 @@ where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PR #[stable(feature = "rust1", since = "1.0.0")] impl BorrowMut<[T]> for Vec -where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +where + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ fn borrow_mut(&mut self) -> &mut [T] { &mut self[..] } diff --git a/library/alloc/src/vec/drain.rs b/library/alloc/src/vec/drain.rs index e0dc758b87b59..d7f7292e4f1cf 100644 --- a/library/alloc/src/vec/drain.rs +++ b/library/alloc/src/vec/drain.rs @@ -23,9 +23,10 @@ pub struct Drain< 'a, T: 'a, #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator + 'a = Global, - const COOP_PREFERRED: bool = {alloc::SHORT_TERM_VEC_PREFERS_COOP} -> -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { + const COOP_PREFERRED: bool = { alloc::SHORT_TERM_VEC_PREFERS_COOP }, +> where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ /// Index of tail to preserve pub(super) tail_start: usize, /// Length of tail @@ -36,15 +37,20 @@ where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRE } #[stable(feature = "collection_debug", since = "1.17.0")] -impl fmt::Debug for Drain<'_, T, A, COOP_PREFERRED> -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +impl fmt::Debug + for Drain<'_, T, A, COOP_PREFERRED> +where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_tuple("Drain").field(&self.iter.as_slice()).finish() } } impl<'a, T, A: Allocator, const COOP_PREFERRED: bool> Drain<'a, T, A, COOP_PREFERRED> -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ /// Returns the remaining items of this iterator as a slice. /// /// # Examples @@ -144,22 +150,34 @@ where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRE #[stable(feature = "vec_drain_as_slice", since = "1.46.0")] impl<'a, T, A: Allocator, const COOP_PREFERRED: bool> AsRef<[T]> for Drain<'a, T, A, COOP_PREFERRED> -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ fn as_ref(&self) -> &[T] { self.as_slice() } } #[stable(feature = "drain", since = "1.6.0")] -unsafe impl Sync for Drain<'_, T, A, COOP_PREFERRED> -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: {} +unsafe impl Sync + for Drain<'_, T, A, COOP_PREFERRED> +where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ +} #[stable(feature = "drain", since = "1.6.0")] -unsafe impl Send for Drain<'_, T, A, COOP_PREFERRED> -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: {} +unsafe impl Send + for Drain<'_, T, A, COOP_PREFERRED> +where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ +} #[stable(feature = "drain", since = "1.6.0")] impl Iterator for Drain<'_, T, A, COOP_PREFERRED> -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ type Item = T; #[inline] @@ -173,8 +191,11 @@ where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRE } #[stable(feature = "drain", since = "1.6.0")] -impl DoubleEndedIterator for Drain<'_, T, A, COOP_PREFERRED> -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +impl DoubleEndedIterator + for Drain<'_, T, A, COOP_PREFERRED> +where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ #[inline] fn next_back(&mut self) -> Option { self.iter.next_back().map(|elt| unsafe { ptr::read(elt as *const _) }) @@ -183,14 +204,22 @@ where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRE #[stable(feature = "drain", since = "1.6.0")] impl Drop for Drain<'_, T, A, COOP_PREFERRED> -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ fn drop(&mut self) { /// Moves back the un-`Drain`ed elements to restore the original `Vec`. - struct DropGuard<'r, 'a, T, A: Allocator, const COOP_PREFERRED: bool>(&'r mut Drain<'a, T, A, COOP_PREFERRED>) - where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: ; - - impl<'r, 'a, T, A: Allocator, const COOP_PREFERRED: bool> Drop for DropGuard<'r, 'a, T, A, COOP_PREFERRED> - where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { + struct DropGuard<'r, 'a, T, A: Allocator, const COOP_PREFERRED: bool>( + &'r mut Drain<'a, T, A, COOP_PREFERRED>, + ) + where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:; + + impl<'r, 'a, T, A: Allocator, const COOP_PREFERRED: bool> Drop + for DropGuard<'r, 'a, T, A, COOP_PREFERRED> + where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + { fn drop(&mut self) { if self.0.tail_len > 0 { unsafe { @@ -254,17 +283,26 @@ where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRE } #[stable(feature = "drain", since = "1.6.0")] -impl ExactSizeIterator for Drain<'_, T, A, COOP_PREFERRED> -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +impl ExactSizeIterator + for Drain<'_, T, A, COOP_PREFERRED> +where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ fn is_empty(&self) -> bool { self.iter.is_empty() } } #[unstable(feature = "trusted_len", issue = "37572")] -unsafe impl TrustedLen for Drain<'_, T, A, COOP_PREFERRED> -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: {} +unsafe impl TrustedLen + for Drain<'_, T, A, COOP_PREFERRED> +where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ +} #[stable(feature = "fused", since = "1.26.0")] -impl FusedIterator for Drain<'_, T, A, COOP_PREFERRED> -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: {} +impl FusedIterator for Drain<'_, T, A, COOP_PREFERRED> where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: +{ +} diff --git a/library/alloc/src/vec/drain_filter.rs b/library/alloc/src/vec/drain_filter.rs index 7be4abacbec96..89baafca46729 100644 --- a/library/alloc/src/vec/drain_filter.rs +++ b/library/alloc/src/vec/drain_filter.rs @@ -24,10 +24,10 @@ pub struct DrainFilter< T, F, #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global, - const COOP_PREFERRED: bool = true + const COOP_PREFERRED: bool = true, > where F: FnMut(&mut T) -> bool, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { pub(super) vec: &'a mut Vec, /// The index of the item that will be inspected by the next call to `next`. @@ -49,7 +49,7 @@ pub struct DrainFilter< impl DrainFilter<'_, T, F, A, COOP_PREFERRED> where F: FnMut(&mut T) -> bool, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { /// Returns a reference to the underlying allocator. #[unstable(feature = "allocator_api", issue = "32838")] @@ -115,10 +115,11 @@ where } #[unstable(feature = "drain_filter", reason = "recently added", issue = "43244")] -impl Iterator for DrainFilter<'_, T, F, A, COOP_PREFERRED> +impl Iterator + for DrainFilter<'_, T, F, A, COOP_PREFERRED> where F: FnMut(&mut T) -> bool, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { type Item = T; @@ -154,24 +155,26 @@ where } #[unstable(feature = "drain_filter", reason = "recently added", issue = "43244")] -impl Drop for DrainFilter<'_, T, F, A, COOP_PREFERRED> +impl Drop + for DrainFilter<'_, T, F, A, COOP_PREFERRED> where F: FnMut(&mut T) -> bool, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { fn drop(&mut self) { struct BackshiftOnDrop<'a, 'b, T, F, A: Allocator, const COOP_PREFERRED: bool> where F: FnMut(&mut T) -> bool, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { drain: &'b mut DrainFilter<'a, T, F, A, COOP_PREFERRED>, } - impl<'a, 'b, T, F, A: Allocator, const COOP_PREFERRED: bool> Drop for BackshiftOnDrop<'a, 'b, T, F, A, COOP_PREFERRED> + impl<'a, 'b, T, F, A: Allocator, const COOP_PREFERRED: bool> Drop + for BackshiftOnDrop<'a, 'b, T, F, A, COOP_PREFERRED> where F: FnMut(&mut T) -> bool, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { fn drop(&mut self) { unsafe { diff --git a/library/alloc/src/vec/into_iter.rs b/library/alloc/src/vec/into_iter.rs index d07aad4724ccd..790e6323f514e 100644 --- a/library/alloc/src/vec/into_iter.rs +++ b/library/alloc/src/vec/into_iter.rs @@ -4,7 +4,6 @@ use crate::alloc::{Allocator, Global}; #[cfg(not(no_global_oom_handling))] use crate::collections::VecDeque; use crate::raw_vec::RawVec; -use core::{alloc, array, fmt}; use core::iter::{ FusedIterator, InPlaceIterable, SourceIter, TrustedLen, TrustedRandomAccessNoCoerce, }; @@ -14,6 +13,7 @@ use core::mem::{self, ManuallyDrop, MaybeUninit, SizedTypeProperties}; use core::ops::Deref; use core::ptr::{self, NonNull}; use core::slice::{self}; +use core::{alloc, array, fmt}; /// An iterator that moves out of a vector. /// @@ -31,9 +31,10 @@ use core::slice::{self}; pub struct IntoIter< T, #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global, - const COOP_PREFERRED: bool = {alloc::SHORT_TERM_VEC_PREFERS_COOP} -> -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { + const COOP_PREFERRED: bool = { alloc::SHORT_TERM_VEC_PREFERS_COOP }, +> where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ pub(super) buf: NonNull, pub(super) phantom: PhantomData, pub(super) cap: usize, @@ -47,15 +48,20 @@ where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRE } #[stable(feature = "vec_intoiter_debug", since = "1.13.0")] -impl fmt::Debug for IntoIter -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +impl fmt::Debug + for IntoIter +where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_tuple("IntoIter").field(&self.as_slice()).finish() } } impl IntoIter -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ /// Returns the remaining items of this iterator as a slice. /// /// # Examples @@ -172,22 +178,34 @@ where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRE #[stable(feature = "vec_intoiter_as_ref", since = "1.46.0")] impl AsRef<[T]> for IntoIter -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ fn as_ref(&self) -> &[T] { self.as_slice() } } #[stable(feature = "rust1", since = "1.0.0")] -unsafe impl Send for IntoIter -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: {} +unsafe impl Send + for IntoIter +where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ +} #[stable(feature = "rust1", since = "1.0.0")] -unsafe impl Sync for IntoIter -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: {} +unsafe impl Sync + for IntoIter +where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ +} #[stable(feature = "rust1", since = "1.0.0")] impl Iterator for IntoIter -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ type Item = T; #[inline] @@ -301,8 +319,11 @@ where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRE } #[stable(feature = "rust1", since = "1.0.0")] -impl DoubleEndedIterator for IntoIter -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +impl DoubleEndedIterator + for IntoIter +where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ #[inline] fn next_back(&mut self) -> Option { if self.end == self.ptr { @@ -343,20 +364,29 @@ where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRE } #[stable(feature = "rust1", since = "1.0.0")] -impl ExactSizeIterator for IntoIter -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +impl ExactSizeIterator + for IntoIter +where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ fn is_empty(&self) -> bool { self.ptr == self.end } } #[stable(feature = "fused", since = "1.26.0")] -impl FusedIterator for IntoIter -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: {} +impl FusedIterator for IntoIter where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: +{ +} #[unstable(feature = "trusted_len", issue = "37572")] -unsafe impl TrustedLen for IntoIter -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: {} +unsafe impl TrustedLen + for IntoIter +where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ +} #[doc(hidden)] #[unstable(issue = "none", feature = "std_internals")] @@ -372,18 +402,22 @@ impl NonDrop for T {} #[unstable(issue = "none", feature = "std_internals")] // TrustedRandomAccess (without NoCoerce) must not be implemented because // subtypes/supertypes of `T` might not be `NonDrop` -unsafe impl TrustedRandomAccessNoCoerce for IntoIter +unsafe impl TrustedRandomAccessNoCoerce + for IntoIter where T: NonDrop, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { const MAY_HAVE_SIDE_EFFECT: bool = false; } #[cfg(not(no_global_oom_handling))] #[stable(feature = "vec_into_iter_clone", since = "1.8.0")] -impl Clone for IntoIter -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +impl Clone + for IntoIter +where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ #[cfg(not(test))] fn clone(&self) -> Self { self.as_slice().to_vec_in(self.alloc.deref().clone()).into_iter() @@ -395,20 +429,32 @@ where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRE } #[stable(feature = "rust1", since = "1.0.0")] -unsafe impl<#[may_dangle] T, A: Allocator, const COOP_PREFERRED: bool> Drop for IntoIter -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +unsafe impl<#[may_dangle] T, A: Allocator, const COOP_PREFERRED: bool> Drop + for IntoIter +where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ fn drop(&mut self) { - struct DropGuard<'a, T, A: Allocator, const COOP_PREFERRED: bool>(&'a mut IntoIter) - where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: ; + struct DropGuard<'a, T, A: Allocator, const COOP_PREFERRED: bool>( + &'a mut IntoIter, + ) + where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:; impl Drop for DropGuard<'_, T, A, COOP_PREFERRED> - where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { + where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + { fn drop(&mut self) { unsafe { // `IntoIter::alloc` is not used anymore after this and will be dropped by RawVec let alloc = ManuallyDrop::take(&mut self.0.alloc); // RawVec handles deallocation - let _ = RawVec::::from_raw_parts_in(self.0.buf.as_ptr(), self.0.cap, alloc); + let _ = RawVec::::from_raw_parts_in( + self.0.buf.as_ptr(), + self.0.cap, + alloc, + ); } } } @@ -426,13 +472,20 @@ where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRE // also refer to the vec::in_place_collect module documentation to get an overview #[unstable(issue = "none", feature = "inplace_iteration")] #[doc(hidden)] -unsafe impl InPlaceIterable for IntoIter -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: {} +unsafe impl InPlaceIterable + for IntoIter +where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ +} #[unstable(issue = "none", feature = "inplace_iteration")] #[doc(hidden)] -unsafe impl SourceIter for IntoIter -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +unsafe impl SourceIter + for IntoIter +where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ type Source = Self; #[inline] diff --git a/library/alloc/src/vec/mod.rs b/library/alloc/src/vec/mod.rs index 10af6f6a8f364..12cc862e70b7a 100644 --- a/library/alloc/src/vec/mod.rs +++ b/library/alloc/src/vec/mod.rs @@ -397,19 +397,25 @@ mod spec_extend; #[stable(feature = "rust1", since = "1.0.0")] #[cfg_attr(not(test), rustc_diagnostic_item = "Vec")] #[rustc_insignificant_dtor] -pub struct Vec -where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: +pub struct Vec< + T, + #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global, + const COOP_PREFERRED: bool = DEFAULT_COOP_PREFERRED, +> where + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { buf: RawVec, len: usize, } #[unstable(feature = "global_co_alloc_covec", issue = "none")] -pub type CoVec = Vec; +pub type CoVec = + Vec; /// "Plain" Vec. Not "cooperative" - not carrying extra data to assist the allocator. #[unstable(feature = "global_co_alloc_plvec", issue = "none")] -pub type PlVec = Vec; +pub type PlVec = + Vec; /// Default `Vec`, `DefVec`, `DecVeque`, `DefDecVeq` "cooperation" (`COOP_PREFERRED`) generic parameter. #[unstable(feature = "global_co_alloc_def", issue = "none")] @@ -419,14 +425,14 @@ pub const DEFAULT_COOP_PREFERRED: bool = true; /// difference to `Vec` (used without specifying `COOP_PREFERRED`): `DefVec` indicates that the /// author considered using `CoVec` or `PlVec`, but left it to default instead. #[unstable(feature = "global_co_alloc_defvec", issue = "none")] -pub type DefVec = Vec; - +pub type DefVec = + Vec; /// "Weighted cooperative" Vec. Weight means how much it wants to cooperate (with the allocator). 0 /// = always pack; u8::MAX = always cooperate (if `Global` supports it). /// @FIXME A `pub const` threshold. #[unstable(feature = "global_co_alloc_vec", issue = "none")] -pub type WeVec = Vec1}>; +pub type WeVec = Vec 1 }>; //////////////////////////////////////////////////////////////////////////////// // Inherent methods @@ -620,7 +626,9 @@ impl Vec { } impl Vec -where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +where + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ /// Constructs a new, empty `Vec`. /// /// The vector will not allocate until elements are pushed onto it. @@ -1633,8 +1641,10 @@ where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PR // This drop guard will be invoked when predicate or `drop` of element panicked. // It shifts unchecked elements to cover holes and `set_len` to the correct length. // In cases when predicate and `drop` never panick, it will be optimized out. - struct BackshiftOnDrop<'a, T, A: Allocator, const VEC_IS_COOP: bool=true> - where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(VEC_IS_COOP)]: { + struct BackshiftOnDrop<'a, T, A: Allocator, const VEC_IS_COOP: bool = true> + where + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(VEC_IS_COOP)]:, + { v: &'a mut Vec, processed_len: usize, deleted_cnt: usize, @@ -1642,7 +1652,9 @@ where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PR } impl Drop for BackshiftOnDrop<'_, T, A, VEC_IS_COOP> - where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(VEC_IS_COOP)]: { + where + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(VEC_IS_COOP)]:, + { fn drop(&mut self) { if self.deleted_cnt > 0 { // SAFETY: Trailing unchecked items must be valid since we never touch them. @@ -1661,7 +1673,12 @@ where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PR } } - let mut g = BackshiftOnDrop:: { v: self, processed_len: 0, deleted_cnt: 0, original_len }; + let mut g = BackshiftOnDrop:: { + v: self, + processed_len: 0, + deleted_cnt: 0, + original_len, + }; fn process_loop( original_len: usize, @@ -1669,7 +1686,7 @@ where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PR g: &mut BackshiftOnDrop<'_, T, A, VEC_IS_COOP>, ) where F: FnMut(&mut T) -> bool, - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(VEC_IS_COOP)]: + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(VEC_IS_COOP)]:, { while g.processed_len != original_len { // SAFETY: Unchecked element must be valid. @@ -1763,7 +1780,9 @@ where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PR /* INVARIANT: vec.len() > read >= write > write-1 >= 0 */ struct FillGapOnDrop<'a, T, A: core::alloc::Allocator, const COOP_PREFERRED: bool> - where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { + where + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + { /* Offset of the element we want to check if it is duplicate */ read: usize, @@ -1775,8 +1794,11 @@ where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PR vec: &'a mut Vec, } - impl<'a, T, A: core::alloc::Allocator, const COOP_PREFERRED: bool> Drop for FillGapOnDrop<'a, T, A, COOP_PREFERRED> - where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { + impl<'a, T, A: core::alloc::Allocator, const COOP_PREFERRED: bool> Drop + for FillGapOnDrop<'a, T, A, COOP_PREFERRED> + where + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + { fn drop(&mut self) { /* This code gets executed when `same_bucket` panics */ @@ -2370,7 +2392,9 @@ where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PR } impl Vec -where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +where + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ /// Resizes the `Vec` in-place so that `len` is equal to `new_len`. /// /// If `new_len` is greater than `len`, the `Vec` is extended by the @@ -2470,7 +2494,9 @@ where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PR } impl Vec<[T; N], A, COOP_PREFERRED> -where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +where + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ /// Takes a `Vec<[T; N]>` and flattens it into a `Vec`. /// /// # Panics @@ -2532,7 +2558,9 @@ impl ExtendWith for ExtendElement { } impl Vec -where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +where + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ #[cfg(not(no_global_oom_handling))] /// Extend the vector by `n` values, using the given generator. fn extend_with>(&mut self, n: usize, mut value: E) { @@ -2565,7 +2593,9 @@ where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PR } impl Vec -where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +where + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ /// Removes consecutive repeated elements in the vector according to the /// [`PartialEq`] trait implementation. /// @@ -2601,8 +2631,14 @@ pub fn from_elem(elem: T, n: usize) -> Vec { #[doc(hidden)] #[cfg(not(no_global_oom_handling))] #[unstable(feature = "allocator_api", issue = "32838")] -pub fn from_elem_in(elem: T, n: usize, alloc: A) -> Vec -where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +pub fn from_elem_in( + elem: T, + n: usize, + alloc: A, +) -> Vec +where + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ ::from_elem(elem, n, alloc) } @@ -2614,8 +2650,11 @@ trait ExtendFromWithinSpec { unsafe fn spec_extend_from_within(&mut self, src: Range); } -impl ExtendFromWithinSpec for Vec -where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +impl ExtendFromWithinSpec + for Vec +where + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ default unsafe fn spec_extend_from_within(&mut self, src: Range) { // SAFETY: // - len is increased only after initializing elements @@ -2634,8 +2673,11 @@ where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PR } } -impl ExtendFromWithinSpec for Vec -where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +impl ExtendFromWithinSpec + for Vec +where + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ unsafe fn spec_extend_from_within(&mut self, src: Range) { let count = src.len(); { @@ -2669,7 +2711,9 @@ where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PR #[stable(feature = "rust1", since = "1.0.0")] impl ops::Deref for Vec -where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +where + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ type Target = [T]; #[inline] @@ -2680,7 +2724,9 @@ where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PR #[stable(feature = "rust1", since = "1.0.0")] impl ops::DerefMut for Vec -where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +where + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ #[inline] fn deref_mut(&mut self) -> &mut [T] { unsafe { slice::from_raw_parts_mut(self.as_mut_ptr(), self.len) } @@ -2690,7 +2736,9 @@ where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PR #[cfg(not(no_global_oom_handling))] #[stable(feature = "rust1", since = "1.0.0")] impl Clone for Vec -where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +where + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ #[cfg(not(test))] fn clone(&self) -> Self { let alloc = self.allocator().clone(); @@ -2726,7 +2774,9 @@ where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PR /// ``` #[stable(feature = "rust1", since = "1.0.0")] impl Hash for Vec -where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +where + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ #[inline] fn hash(&self, state: &mut H) { Hash::hash(&**self, state) @@ -2738,8 +2788,11 @@ where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PR message = "vector indices are of type `usize` or ranges of `usize`", label = "vector indices are of type `usize` or ranges of `usize`" )] -impl, A: Allocator, const COOP_PREFERRED: bool> Index for Vec -where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +impl, A: Allocator, const COOP_PREFERRED: bool> Index + for Vec +where + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ type Output = I::Output; #[inline] @@ -2753,8 +2806,11 @@ where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PR message = "vector indices are of type `usize` or ranges of `usize`", label = "vector indices are of type `usize` or ranges of `usize`" )] -impl, A: Allocator, const COOP_PREFERRED: bool> IndexMut for Vec -where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +impl, A: Allocator, const COOP_PREFERRED: bool> IndexMut + for Vec +where + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ #[inline] fn index_mut(&mut self, index: I) -> &mut Self::Output { IndexMut::index_mut(&mut **self, index) @@ -2772,7 +2828,9 @@ impl FromIterator for Vec { #[stable(feature = "rust1", since = "1.0.0")] impl IntoIterator for Vec -where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +where + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ type Item = T; type IntoIter = IntoIter; @@ -2818,7 +2876,9 @@ where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PR #[stable(feature = "rust1", since = "1.0.0")] impl<'a, T, A: Allocator, const COOP_PREFERRED: bool> IntoIterator for &'a Vec -where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +where + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ type Item = &'a T; type IntoIter = slice::Iter<'a, T>; @@ -2828,8 +2888,11 @@ where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PR } #[stable(feature = "rust1", since = "1.0.0")] -impl<'a, T, A: Allocator, const COOP_PREFERRED: bool> IntoIterator for &'a mut Vec -where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +impl<'a, T, A: Allocator, const COOP_PREFERRED: bool> IntoIterator + for &'a mut Vec +where + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ type Item = &'a mut T; type IntoIter = slice::IterMut<'a, T>; @@ -2841,7 +2904,9 @@ where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PR #[cfg(not(no_global_oom_handling))] #[stable(feature = "rust1", since = "1.0.0")] impl Extend for Vec -where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +where + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ #[inline] fn extend>(&mut self, iter: I) { >::spec_extend(self, iter.into_iter()) @@ -2859,7 +2924,9 @@ where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PR } impl Vec -where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +where + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ // leaf method to which various SpecFrom/SpecExtend implementations delegate when // they have no further optimizations to apply #[cfg(not(no_global_oom_handling))] @@ -3033,8 +3100,11 @@ where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PR /// [`copy_from_slice`]: slice::copy_from_slice #[cfg(not(no_global_oom_handling))] #[stable(feature = "extend_ref", since = "1.2.0")] -impl<'a, T: Copy + 'a, A: Allocator + 'a, const COOP_PREFERRED: bool> Extend<&'a T> for Vec -where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +impl<'a, T: Copy + 'a, A: Allocator + 'a, const COOP_PREFERRED: bool> Extend<&'a T> + for Vec +where + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ fn extend>(&mut self, iter: I) { self.spec_extend(iter.into_iter()) } @@ -3052,8 +3122,11 @@ where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PR /// Implements comparison of vectors, [lexicographically](core::cmp::Ord#lexicographical-comparison). #[stable(feature = "rust1", since = "1.0.0")] -impl PartialOrd for Vec -where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +impl PartialOrd + for Vec +where + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ #[inline] fn partial_cmp(&self, other: &Self) -> Option { PartialOrd::partial_cmp(&**self, &**other) @@ -3061,13 +3134,17 @@ where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PR } #[stable(feature = "rust1", since = "1.0.0")] -impl Eq for Vec -where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: {} +impl Eq for Vec where + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: +{ +} /// Implements ordering of vectors, [lexicographically](core::cmp::Ord#lexicographical-comparison). #[stable(feature = "rust1", since = "1.0.0")] impl Ord for Vec -where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +where + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ #[inline] fn cmp(&self, other: &Self) -> Ordering { Ord::cmp(&**self, &**other) @@ -3075,8 +3152,11 @@ where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PR } #[stable(feature = "rust1", since = "1.0.0")] -unsafe impl<#[may_dangle] T, A: Allocator, const COOP_PREFERRED: bool> Drop for Vec -where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +unsafe impl<#[may_dangle] T, A: Allocator, const COOP_PREFERRED: bool> Drop + for Vec +where + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ fn drop(&mut self) { unsafe { // use drop for [T] @@ -3100,24 +3180,33 @@ impl const Default for Vec { } #[stable(feature = "rust1", since = "1.0.0")] -impl fmt::Debug for Vec -where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +impl fmt::Debug + for Vec +where + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fmt::Debug::fmt(&**self, f) } } #[stable(feature = "rust1", since = "1.0.0")] -impl AsRef> for Vec -where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +impl AsRef> + for Vec +where + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ fn as_ref(&self) -> &Vec { self } } #[stable(feature = "vec_as_mut", since = "1.5.0")] -impl AsMut> for Vec -where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +impl AsMut> + for Vec +where + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ fn as_mut(&mut self) -> &mut Vec { self } @@ -3125,7 +3214,9 @@ where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PR #[stable(feature = "rust1", since = "1.0.0")] impl AsRef<[T]> for Vec -where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +where + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ fn as_ref(&self) -> &[T] { self } @@ -3133,7 +3224,9 @@ where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PR #[stable(feature = "vec_as_mut", since = "1.5.0")] impl AsMut<[T]> for Vec -where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +where + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ fn as_mut(&mut self) -> &mut [T] { self } @@ -3231,7 +3324,9 @@ where #[cfg(not(test))] #[stable(feature = "vec_from_box", since = "1.18.0")] impl From> for Vec -where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +where + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ /// Convert a boxed slice into a vector by transferring ownership of /// the existing heap allocation. /// @@ -3251,7 +3346,9 @@ where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PR #[cfg(not(test))] #[stable(feature = "box_from_vec", since = "1.20.0")] impl From> for Box<[T], A> -where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +where + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ /// Convert a vector into a boxed slice. /// /// If `v` has excess capacity, its items will be moved into a @@ -3291,8 +3388,11 @@ impl From<&str> for Vec { } #[stable(feature = "array_try_from_vec", since = "1.48.0")] -impl TryFrom> for [T; N] -where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +impl TryFrom> + for [T; N] +where + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ type Error = Vec; /// Gets the entire contents of the `Vec` as an array, diff --git a/library/alloc/src/vec/spec_extend.rs b/library/alloc/src/vec/spec_extend.rs index 87bdb3aaab7a5..73cf325889290 100644 --- a/library/alloc/src/vec/spec_extend.rs +++ b/library/alloc/src/vec/spec_extend.rs @@ -1,5 +1,5 @@ -use core::alloc; use crate::alloc::Allocator; +use core::alloc; use core::iter::TrustedLen; use core::slice::{self}; @@ -13,7 +13,7 @@ pub(super) trait SpecExtend { impl SpecExtend for Vec where I: Iterator, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { default fn spec_extend(&mut self, iter: I) { self.extend_desugared(iter) @@ -23,15 +23,18 @@ where impl SpecExtend for Vec where I: TrustedLen, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { default fn spec_extend(&mut self, iterator: I) { self.extend_trusted(iterator) } } -impl SpecExtend> for Vec -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +impl SpecExtend> + for Vec +where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ fn spec_extend(&mut self, mut iterator: IntoIter) { unsafe { self.append_elements(iterator.as_slice() as _); @@ -40,21 +43,23 @@ where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRE } } -impl<'a, T: 'a, I, A: Allocator + 'a, const COOP_PREFERRED: bool> SpecExtend<&'a T, I> for Vec +impl<'a, T: 'a, I, A: Allocator + 'a, const COOP_PREFERRED: bool> SpecExtend<&'a T, I> + for Vec where I: Iterator, T: Clone, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { default fn spec_extend(&mut self, iterator: I) { self.spec_extend(iterator.cloned()) } } -impl<'a, T: 'a, A: Allocator + 'a, const COOP_PREFERRED: bool> SpecExtend<&'a T, slice::Iter<'a, T>> for Vec +impl<'a, T: 'a, A: Allocator + 'a, const COOP_PREFERRED: bool> SpecExtend<&'a T, slice::Iter<'a, T>> + for Vec where T: Copy, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { fn spec_extend(&mut self, iterator: slice::Iter<'a, T>) { let slice = iterator.as_slice(); diff --git a/library/alloc/src/vec/spec_from_elem.rs b/library/alloc/src/vec/spec_from_elem.rs index 682375a607837..3766f6de061bb 100644 --- a/library/alloc/src/vec/spec_from_elem.rs +++ b/library/alloc/src/vec/spec_from_elem.rs @@ -1,20 +1,31 @@ use core::ptr; -use core::alloc; use crate::alloc::Allocator; use crate::raw_vec::RawVec; +use core::alloc; use super::{ExtendElement, IsZero, Vec}; // Specialization trait used for Vec::from_elem pub(super) trait SpecFromElem: Sized { - fn from_elem(elem: Self, n: usize, alloc: A) -> Vec - where [(); alloc::co_alloc_metadata_num_slots::(COOP_PREFERRED)]: ; + fn from_elem( + elem: Self, + n: usize, + alloc: A, + ) -> Vec + where + [(); alloc::co_alloc_metadata_num_slots::(COOP_PREFERRED)]:; } impl SpecFromElem for T { - default fn from_elem(elem: Self, n: usize, alloc: A) -> Vec - where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { + default fn from_elem( + elem: Self, + n: usize, + alloc: A, + ) -> Vec + where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + { let mut v = Vec::with_capacity_in(n, alloc); v.extend_with(n, ExtendElement(elem)); v @@ -23,8 +34,14 @@ impl SpecFromElem for T { impl SpecFromElem for T { #[inline] - default fn from_elem(elem: T, n: usize, alloc: A) -> Vec - where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { + default fn from_elem( + elem: T, + n: usize, + alloc: A, + ) -> Vec + where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + { if elem.is_zero() { return Vec { buf: RawVec::with_capacity_zeroed_in(n, alloc), len: n }; } @@ -36,8 +53,14 @@ impl SpecFromElem for T { impl SpecFromElem for i8 { #[inline] - fn from_elem(elem: i8, n: usize, alloc: A) -> Vec - where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { + fn from_elem( + elem: i8, + n: usize, + alloc: A, + ) -> Vec + where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + { if elem == 0 { return Vec { buf: RawVec::with_capacity_zeroed_in(n, alloc), len: n }; } @@ -52,8 +75,14 @@ impl SpecFromElem for i8 { impl SpecFromElem for u8 { #[inline] - fn from_elem(elem: u8, n: usize, alloc: A) -> Vec - where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { + fn from_elem( + elem: u8, + n: usize, + alloc: A, + ) -> Vec + where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + { if elem == 0 { return Vec { buf: RawVec::with_capacity_zeroed_in(n, alloc), len: n }; } diff --git a/library/alloc/src/vec/splice.rs b/library/alloc/src/vec/splice.rs index 631d9d5e3aa60..d8569a6e89c62 100644 --- a/library/alloc/src/vec/splice.rs +++ b/library/alloc/src/vec/splice.rs @@ -1,5 +1,5 @@ -use core::alloc; use crate::alloc::{Allocator, Global}; +use core::alloc; use core::ptr::{self}; use core::slice::{self}; @@ -23,15 +23,18 @@ pub struct Splice< 'a, I: Iterator + 'a, #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator + 'a = Global, -> -where [(); core::alloc::co_alloc_metadata_num_slots::()]: { +> where + [(); core::alloc::co_alloc_metadata_num_slots::()]:, +{ pub(super) drain: Drain<'a, I::Item, A>, pub(super) replace_with: I, } #[stable(feature = "vec_splice", since = "1.21.0")] impl Iterator for Splice<'_, I, A> -where [(); core::alloc::co_alloc_metadata_num_slots::()]: { +where + [(); core::alloc::co_alloc_metadata_num_slots::()]:, +{ type Item = I::Item; fn next(&mut self) -> Option { @@ -45,19 +48,25 @@ where [(); core::alloc::co_alloc_metadata_num_slots::()]: { #[stable(feature = "vec_splice", since = "1.21.0")] impl DoubleEndedIterator for Splice<'_, I, A> -where [(); alloc::co_alloc_metadata_num_slots::()]: { +where + [(); alloc::co_alloc_metadata_num_slots::()]:, +{ fn next_back(&mut self) -> Option { self.drain.next_back() } } #[stable(feature = "vec_splice", since = "1.21.0")] -impl ExactSizeIterator for Splice<'_, I, A> -where [(); alloc::co_alloc_metadata_num_slots::()]: {} +impl ExactSizeIterator for Splice<'_, I, A> where + [(); alloc::co_alloc_metadata_num_slots::()]: +{ +} #[stable(feature = "vec_splice", since = "1.21.0")] impl Drop for Splice<'_, I, A> -where [(); alloc::co_alloc_metadata_num_slots::()]: { +where + [(); alloc::co_alloc_metadata_num_slots::()]:, +{ fn drop(&mut self) { self.drain.by_ref().for_each(drop); // At this point draining is done and the only remaining tasks are splicing @@ -105,7 +114,9 @@ where [(); alloc::co_alloc_metadata_num_slots::()]: { /// Private helper methods for `Splice::drop` impl Drain<'_, T, A> -where [(); alloc::co_alloc_metadata_num_slots::()]: { +where + [(); alloc::co_alloc_metadata_num_slots::()]:, +{ /// The range from `self.vec.len` to `self.tail_start` contains elements /// that have been moved out. /// Fill that range as much as possible with new elements from the `replace_with` iterator. diff --git a/library/alloc/tests/boxed.rs b/library/alloc/tests/boxed.rs index c34e7a558061d..656e079f9c61c 100644 --- a/library/alloc/tests/boxed.rs +++ b/library/alloc/tests/boxed.rs @@ -61,7 +61,7 @@ fn box_deref_lval() { pub struct ConstAllocator; -//@TODO +//@FIXME unsafe impl const Allocator for ConstAllocator { fn allocate(&self, layout: Layout) -> Result, AllocError> { match layout.size() { diff --git a/library/core/src/alloc/global.rs b/library/core/src/alloc/global.rs index 31d9ab6c8d04e..e048c01d34bce 100644 --- a/library/core/src/alloc/global.rs +++ b/library/core/src/alloc/global.rs @@ -1,7 +1,7 @@ +use crate::alloc::GlobalCoAllocMeta; use crate::alloc::Layout; use crate::cmp; use crate::ptr; -use crate::alloc::GlobalCoAllocMeta; #[unstable(feature = "global_co_alloc_meta", issue = "none")] #[allow(missing_debug_implementations)] @@ -166,7 +166,9 @@ pub unsafe trait GlobalAlloc { unsafe fn alloc(&self, layout: Layout) -> *mut u8; #[unstable(feature = "global_co_alloc", issue = "none")] - unsafe fn co_alloc(&self, _layout: Layout, mut _result: &mut RawAndMeta) {panic!("@FIXME")} + unsafe fn co_alloc(&self, _layout: Layout, mut _result: &mut RawAndMeta) { + panic!("@FIXME") + } /// Deallocate the block of memory at the given `ptr` pointer with the given `layout`. /// @@ -184,7 +186,9 @@ pub unsafe trait GlobalAlloc { unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout); #[unstable(feature = "global_co_alloc", issue = "none")] - unsafe fn co_dealloc(&self, _ptr_and_meta: RawAndMeta, _layout: Layout) {panic!("@FIXME")} + unsafe fn co_dealloc(&self, _ptr_and_meta: RawAndMeta, _layout: Layout) { + panic!("@FIXME") + } /// Behaves like `alloc`, but also ensures that the contents /// are set to zero before being returned. @@ -309,7 +313,7 @@ pub unsafe trait GlobalAlloc { ptr_and_meta: RawAndMeta, layout: Layout, new_size: usize, - mut result: &mut RawAndMeta + mut result: &mut RawAndMeta, ) { // SAFETY: the caller must ensure that the `new_size` does not overflow. // `layout.align()` comes from a `Layout` and is thus guaranteed to be valid. diff --git a/library/core/src/alloc/mod.rs b/library/core/src/alloc/mod.rs index 7993e8e546d89..cc55c15db6268 100644 --- a/library/core/src/alloc/mod.rs +++ b/library/core/src/alloc/mod.rs @@ -89,7 +89,9 @@ pub const fn co_alloc_metadata_num_slots() -> usize { #[unstable(feature = "global_co_alloc", issue = "none")] /// Param `coop_preferred` - if false, then this returns `0`, regardless of /// whether allocator `A` is cooperative. -pub const fn co_alloc_metadata_num_slots_with_preference(coop_preferred: bool) -> usize { +pub const fn co_alloc_metadata_num_slots_with_preference( + coop_preferred: bool, +) -> usize { if A::IS_CO_ALLOCATOR && coop_preferred { 1 } else { 0 } } @@ -182,7 +184,9 @@ pub unsafe trait Allocator { /// [`handle_alloc_error`]: ../../alloc/alloc/fn.handle_alloc_error.html fn allocate(&self, layout: Layout) -> Result, AllocError>; - fn co_allocate(&self, _layout: Layout, _result: &mut SliceAndMetaResult) {panic!("FIXME")} + fn co_allocate(&self, _layout: Layout, _result: &mut SliceAndMetaResult) { + panic!("FIXME") + } /// Behaves like `allocate`, but also ensures that the returned memory is zero-initialized. /// @@ -208,14 +212,9 @@ pub unsafe trait Allocator { fn co_allocate_zeroed(&self, layout: Layout, mut result: &mut SliceAndMetaResult) { self.co_allocate(layout, &mut result); - if let Ok(SliceAndMeta{slice, ..}) = result { + if let Ok(SliceAndMeta { slice, .. }) = result { // SAFETY: `alloc` returns a valid memory block - unsafe { - slice - .as_non_null_ptr() - .as_ptr() - .write_bytes(0, slice.len()) - } + unsafe { slice.as_non_null_ptr().as_ptr().write_bytes(0, slice.len()) } } } @@ -230,7 +229,9 @@ pub unsafe trait Allocator { /// [*fit*]: #memory-fitting unsafe fn deallocate(&self, ptr: NonNull, layout: Layout); - unsafe fn co_deallocate(&self, _ptr_and_meta: PtrAndMeta, _layout: Layout) {panic!("FIXME")} + unsafe fn co_deallocate(&self, _ptr_and_meta: PtrAndMeta, _layout: Layout) { + panic!("FIXME") + } /// Attempts to extend the memory block. /// @@ -301,7 +302,7 @@ pub unsafe trait Allocator { ptr_and_meta: PtrAndMeta, old_layout: Layout, new_layout: Layout, - mut result: &mut SliceAndMetaResult + mut result: &mut SliceAndMetaResult, ) { debug_assert!( new_layout.size() >= old_layout.size(), @@ -310,7 +311,7 @@ pub unsafe trait Allocator { self.co_allocate(new_layout, &mut result); - if let Ok(SliceAndMeta {slice, ..}) = result { + if let Ok(SliceAndMeta { slice, .. }) = result { // SAFETY: because `new_layout.size()` must be greater than or equal to // `old_layout.size()`, both the old and new memory allocation are valid for reads and // writes for `old_layout.size()` bytes. Also, because the old allocation wasn't yet @@ -395,7 +396,7 @@ pub unsafe trait Allocator { ptr_and_meta: PtrAndMeta, old_layout: Layout, new_layout: Layout, - mut result: &mut SliceAndMetaResult + mut result: &mut SliceAndMetaResult, ) { debug_assert!( new_layout.size() >= old_layout.size(), @@ -404,7 +405,7 @@ pub unsafe trait Allocator { self.co_allocate_zeroed(new_layout, &mut result); - if let Ok(SliceAndMeta{ slice, ..}) = result { + if let Ok(SliceAndMeta { slice, .. }) = result { // SAFETY: because `new_layout.size()` must be greater than or equal to // `old_layout.size()`, both the old and new memory allocation are valid for reads and // writes for `old_layout.size()` bytes. Also, because the old allocation wasn't yet @@ -490,7 +491,7 @@ pub unsafe trait Allocator { ptr_and_meta: PtrAndMeta, old_layout: Layout, new_layout: Layout, - mut result: &mut SliceAndMetaResult + mut result: &mut SliceAndMetaResult, ) { debug_assert!( new_layout.size() <= old_layout.size(), @@ -499,7 +500,7 @@ pub unsafe trait Allocator { self.co_allocate(new_layout, &mut result); - if let Ok(SliceAndMeta{ slice, ..}) = result { + if let Ok(SliceAndMeta { slice, .. }) = result { // SAFETY: because `new_layout.size()` must be lower than or equal to // `old_layout.size()`, both the old and new memory allocation are valid for reads and // writes for `new_layout.size()` bytes. Also, because the old allocation wasn't yet diff --git a/library/std/src/io/cursor.rs b/library/std/src/io/cursor.rs index 33d1ee065de2a..63045ebcb8157 100644 --- a/library/std/src/io/cursor.rs +++ b/library/std/src/io/cursor.rs @@ -403,7 +403,9 @@ fn reserve_and_pad( vec: &mut Vec, buf_len: usize, ) -> io::Result -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ let pos: usize = (*pos_mut).try_into().map_err(|_| { io::const_io_error!( ErrorKind::InvalidInput, @@ -442,10 +444,14 @@ where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRE /// Writes the slice to the vec without allocating /// # Safety: vec must have buf.len() spare capacity -unsafe fn vec_write_unchecked(pos: usize, vec: &mut Vec, buf: &[u8]) -> usize +unsafe fn vec_write_unchecked( + pos: usize, + vec: &mut Vec, + buf: &[u8], +) -> usize where A: Allocator, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { debug_assert!(vec.capacity() >= pos + buf.len()); vec.as_mut_ptr().add(pos).copy_from(buf.as_ptr(), buf.len()); @@ -461,10 +467,14 @@ where /// This also allows for the vec body to be empty, but with a position of N. /// This means that [`Write`] will pad the vec with 0 initially, /// before writing anything from that point -fn vec_write(pos_mut: &mut u64, vec: &mut Vec, buf: &[u8]) -> io::Result +fn vec_write( + pos_mut: &mut u64, + vec: &mut Vec, + buf: &[u8], +) -> io::Result where A: Allocator, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { let buf_len = buf.len(); let mut pos = reserve_and_pad(pos_mut, vec, buf_len)?; @@ -500,7 +510,7 @@ fn vec_write_vectored( ) -> io::Result where A: Allocator, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { // For safety reasons, we don't want this sum to overflow ever. // If this saturates, the reserve should panic to avoid any unsound writing. @@ -551,7 +561,7 @@ impl Write for Cursor<&mut [u8]> { impl Write for Cursor<&mut Vec> where A: Allocator, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { fn write(&mut self, buf: &[u8]) -> io::Result { vec_write(&mut self.pos, self.inner, buf) @@ -576,7 +586,7 @@ where impl Write for Cursor> where A: Allocator, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { fn write(&mut self, buf: &[u8]) -> io::Result { vec_write(&mut self.pos, &mut self.inner, buf) diff --git a/library/std/src/io/impls.rs b/library/std/src/io/impls.rs index ec3394e0b16c1..8671ebf5c8141 100644 --- a/library/std/src/io/impls.rs +++ b/library/std/src/io/impls.rs @@ -379,7 +379,9 @@ impl Write for &mut [u8] { /// The vector will grow as needed. #[stable(feature = "rust1", since = "1.0.0")] impl Write for Vec -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ #[inline] fn write(&mut self, buf: &[u8]) -> io::Result { self.extend_from_slice(buf); @@ -416,7 +418,9 @@ where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRE /// Read is implemented for `VecDeque` by consuming bytes from the front of the `VecDeque`. #[stable(feature = "vecdeque_read_write", since = "1.63.0")] impl Read for VecDeque -where [(); co_alloc_metadata_num_slots_with_preference::(_COOP_PREFERRED)]: { +where + [(); co_alloc_metadata_num_slots_with_preference::(_COOP_PREFERRED)]:, +{ /// Fill `buf` with the contents of the "front" slice as returned by /// [`as_slices`][`VecDeque::as_slices`]. If the contained byte slices of the `VecDeque` are /// discontiguous, multiple calls to `read` will be needed to read the entire content. @@ -441,7 +445,9 @@ where [(); co_alloc_metadata_num_slots_with_preference::(_COOP_PREFERRED)]: { /// Write is implemented for `VecDeque` by appending to the `VecDeque`, growing it as needed. #[stable(feature = "vecdeque_read_write", since = "1.63.0")] impl Write for VecDeque -where [(); co_alloc_metadata_num_slots_with_preference::(_COOP_PREFERRED)]: { +where + [(); co_alloc_metadata_num_slots_with_preference::(_COOP_PREFERRED)]:, +{ #[inline] fn write(&mut self, buf: &[u8]) -> io::Result { self.extend(buf); diff --git a/library/std/src/sys/unix/thread_local_dtor.rs b/library/std/src/sys/unix/thread_local_dtor.rs index 1929c1be317b7..a3ba63834060f 100644 --- a/library/std/src/sys/unix/thread_local_dtor.rs +++ b/library/std/src/sys/unix/thread_local_dtor.rs @@ -2,11 +2,11 @@ #![unstable(feature = "thread_local_internals", issue = "none")] #![feature(global_co_alloc_plvec)] -use core::alloc::PlVec; - //! Provides thread-local destructors without an associated "key", which //! can be more efficient. +use core::alloc::PlVec; + // Since what appears to be glibc 2.18 this symbol has been shipped which // GCC and clang both use to invoke destructors in thread_local globals, so // let's do the same! diff --git a/src/librustdoc/html/render/context.rs b/src/librustdoc/html/render/context.rs index 504938fef733b..d201fa6dd9a40 100644 --- a/src/librustdoc/html/render/context.rs +++ b/src/librustdoc/html/render/context.rs @@ -77,7 +77,10 @@ pub(crate) struct Context<'tcx> { // `Context` is cloned a lot, so we don't want the size to grow unexpectedly. #[cfg(all(not(windows), target_arch = "x86_64", target_pointer_width = "64"))] -rustc_data_structures::static_assert_size!(Context<'_>, 160 + 2 * mem::size_of::()); +rustc_data_structures::static_assert_size!( + Context<'_>, + 160 + 2 * mem::size_of::() +); /// Shared mutable state used in [`Context`] and elsewhere. pub(crate) struct SharedContext<'tcx> { From bd4357b4d21b0198fa2a54b82f588df69bec7fff Mon Sep 17 00:00:00 2001 From: Peter Kehl Date: Sat, 21 Jan 2023 22:06:34 -0800 Subject: [PATCH 019/118] CoAlloc: VecDeque + BinaryHeap: x test tidy --bless. ICE --- .../alloc/src/collections/binary_heap/mod.rs | 12 +- .../alloc/src/collections/vec_deque/drain.rs | 77 ++++++--- .../src/collections/vec_deque/into_iter.rs | 35 ++-- .../alloc/src/collections/vec_deque/mod.rs | 154 +++++++++++++----- .../src/collections/vec_deque/spec_extend.rs | 35 ++-- .../collections/vec_deque/spec_from_iter.rs | 19 ++- 6 files changed, 232 insertions(+), 100 deletions(-) diff --git a/library/alloc/src/collections/binary_heap/mod.rs b/library/alloc/src/collections/binary_heap/mod.rs index 7c6b0bb6e6c75..3d10072ce43b4 100644 --- a/library/alloc/src/collections/binary_heap/mod.rs +++ b/library/alloc/src/collections/binary_heap/mod.rs @@ -143,12 +143,12 @@ #![allow(missing_docs)] #![stable(feature = "rust1", since = "1.0.0")] -use core::{alloc, fmt}; use core::iter::{FromIterator, FusedIterator, InPlaceIterable, SourceIter, TrustedLen}; use core::mem::{self, swap, ManuallyDrop}; use core::num::NonZeroUsize; use core::ops::{Deref, DerefMut}; use core::ptr; +use core::{alloc, fmt}; use crate::alloc::Global; @@ -1243,7 +1243,7 @@ impl BinaryHeap { /// ``` #[inline] #[stable(feature = "drain", since = "1.6.0")] - pub fn drain(&mut self) -> Drain<'_, T, {alloc::SHORT_TERM_VEC_PREFERS_COOP}> { + pub fn drain(&mut self) -> Drain<'_, T, { alloc::SHORT_TERM_VEC_PREFERS_COOP }> { Drain { iter: self.data.drain(..) } } @@ -1524,13 +1524,17 @@ unsafe impl TrustedLen for IntoIterSorted {} #[stable(feature = "drain", since = "1.6.0")] #[derive(Debug)] pub struct Drain<'a, T: 'a, const COOP_PREFERRED: bool> -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ iter: vec::Drain<'a, T, Global, COOP_PREFERRED>, } #[stable(feature = "drain", since = "1.6.0")] impl Iterator for Drain<'_, T, COOP_PREFERRED> -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ type Item = T; #[inline] diff --git a/library/alloc/src/collections/vec_deque/drain.rs b/library/alloc/src/collections/vec_deque/drain.rs index bab4919eb6032..0bcf82e3ceff5 100644 --- a/library/alloc/src/collections/vec_deque/drain.rs +++ b/library/alloc/src/collections/vec_deque/drain.rs @@ -19,9 +19,10 @@ pub struct Drain< 'a, T: 'a, #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global, - const COOP_PREFERRED: bool = {alloc::SHORT_TERM_VEC_PREFERS_COOP} -> -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { + const COOP_PREFERRED: bool = { alloc::SHORT_TERM_VEC_PREFERS_COOP }, +> where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ // We can't just use a &mut VecDeque, as that would make Drain invariant over T // and we want it to be covariant instead deque: NonNull>, @@ -37,7 +38,9 @@ where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRE } impl<'a, T, A: Allocator, const COOP_PREFERRED: bool> Drain<'a, T, A, COOP_PREFERRED> -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ pub(super) unsafe fn new( deque: &'a mut VecDeque, drain_start: usize, @@ -91,8 +94,11 @@ where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRE } #[stable(feature = "collection_debug", since = "1.17.0")] -impl fmt::Debug for Drain<'_, T, A, COOP_PREFERRED> -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +impl fmt::Debug + for Drain<'_, T, A, COOP_PREFERRED> +where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_tuple("Drain") .field(&self.drain_len) @@ -104,21 +110,37 @@ where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRE } #[stable(feature = "drain", since = "1.6.0")] -unsafe impl Sync for Drain<'_, T, A, COOP_PREFERRED> -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: {} +unsafe impl Sync + for Drain<'_, T, A, COOP_PREFERRED> +where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ +} #[stable(feature = "drain", since = "1.6.0")] -unsafe impl Send for Drain<'_, T, A, COOP_PREFERRED> -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: {} +unsafe impl Send + for Drain<'_, T, A, COOP_PREFERRED> +where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ +} #[stable(feature = "drain", since = "1.6.0")] impl Drop for Drain<'_, T, A, COOP_PREFERRED> -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ fn drop(&mut self) { - struct DropGuard<'r, 'a, T, A: Allocator, const COOP_PREFERRED: bool> (&'r mut Drain<'a, T, A, COOP_PREFERRED>) - where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:; + struct DropGuard<'r, 'a, T, A: Allocator, const COOP_PREFERRED: bool>( + &'r mut Drain<'a, T, A, COOP_PREFERRED>, + ) + where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:; - impl<'r, 'a, T, A: Allocator, const COOP_PREFERRED: bool> Drop for DropGuard<'r, 'a, T, A, COOP_PREFERRED> - where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { + impl<'r, 'a, T, A: Allocator, const COOP_PREFERRED: bool> Drop + for DropGuard<'r, 'a, T, A, COOP_PREFERRED> + where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + { fn drop(&mut self) { if self.0.remaining != 0 { unsafe { @@ -200,7 +222,9 @@ where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRE #[stable(feature = "drain", since = "1.6.0")] impl Iterator for Drain<'_, T, A, COOP_PREFERRED> -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ type Item = T; #[inline] @@ -222,8 +246,11 @@ where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRE } #[stable(feature = "drain", since = "1.6.0")] -impl DoubleEndedIterator for Drain<'_, T, A, COOP_PREFERRED> -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +impl DoubleEndedIterator + for Drain<'_, T, A, COOP_PREFERRED> +where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ #[inline] fn next_back(&mut self) -> Option { if self.remaining == 0 { @@ -236,9 +263,15 @@ where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRE } #[stable(feature = "drain", since = "1.6.0")] -impl ExactSizeIterator for Drain<'_, T, A, COOP_PREFERRED> -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: {} +impl ExactSizeIterator + for Drain<'_, T, A, COOP_PREFERRED> +where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ +} #[stable(feature = "fused", since = "1.26.0")] -impl FusedIterator for Drain<'_, T, A, COOP_PREFERRED> -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: {} +impl FusedIterator for Drain<'_, T, A, COOP_PREFERRED> where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: +{ +} diff --git a/library/alloc/src/collections/vec_deque/into_iter.rs b/library/alloc/src/collections/vec_deque/into_iter.rs index 81267b8c278b0..751be6ec8846d 100644 --- a/library/alloc/src/collections/vec_deque/into_iter.rs +++ b/library/alloc/src/collections/vec_deque/into_iter.rs @@ -17,14 +17,17 @@ use super::VecDeque; pub struct IntoIter< T, #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global, - const COOP_PREFERRED: bool = true -> -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { + const COOP_PREFERRED: bool = true, +> where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ inner: VecDeque, } impl IntoIter -where [(); alloc::co_alloc_metadata_num_slots::()]: { +where + [(); alloc::co_alloc_metadata_num_slots::()]:, +{ pub(super) fn new(inner: VecDeque) -> Self { IntoIter { inner } } @@ -36,7 +39,9 @@ where [(); alloc::co_alloc_metadata_num_slots::()]: { #[stable(feature = "collection_debug", since = "1.17.0")] impl fmt::Debug for IntoIter -where [(); alloc::co_alloc_metadata_num_slots::()]: { +where + [(); alloc::co_alloc_metadata_num_slots::()]:, +{ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_tuple("IntoIter").field(&self.inner).finish() } @@ -44,7 +49,9 @@ where [(); alloc::co_alloc_metadata_num_slots::()]: { #[stable(feature = "rust1", since = "1.0.0")] impl Iterator for IntoIter -where [(); alloc::co_alloc_metadata_num_slots::()]: { +where + [(); alloc::co_alloc_metadata_num_slots::()]:, +{ type Item = T; #[inline] @@ -181,7 +188,9 @@ where [(); alloc::co_alloc_metadata_num_slots::()]: { #[stable(feature = "rust1", since = "1.0.0")] impl DoubleEndedIterator for IntoIter -where [(); alloc::co_alloc_metadata_num_slots::()]: { +where + [(); alloc::co_alloc_metadata_num_slots::()]:, +{ #[inline] fn next_back(&mut self) -> Option { self.inner.pop_back() @@ -260,9 +269,13 @@ where [(); alloc::co_alloc_metadata_num_slots::()]: { } #[stable(feature = "fused", since = "1.26.0")] -impl FusedIterator for IntoIter -where [(); alloc::co_alloc_metadata_num_slots::()]: {} +impl FusedIterator for IntoIter where + [(); alloc::co_alloc_metadata_num_slots::()]: +{ +} #[unstable(feature = "trusted_len", issue = "37572")] -unsafe impl TrustedLen for IntoIter -where [(); alloc::co_alloc_metadata_num_slots::()]: {} +unsafe impl TrustedLen for IntoIter where + [(); alloc::co_alloc_metadata_num_slots::()]: +{ +} diff --git a/library/alloc/src/collections/vec_deque/mod.rs b/library/alloc/src/collections/vec_deque/mod.rs index a7ac80269bd90..0be13ed61ea7d 100644 --- a/library/alloc/src/collections/vec_deque/mod.rs +++ b/library/alloc/src/collections/vec_deque/mod.rs @@ -6,10 +6,9 @@ //! contained type is sendable. #![feature(global_co_alloc)] - #![stable(feature = "rust1", since = "1.0.0")] -use core::alloc::{self, GlobalAlloc}; use crate::vec::DEFAULT_COOP_PREFERRED; +use core::alloc::{self, GlobalAlloc}; use core::cmp::{self, Ordering}; use core::fmt; use core::hash::{Hash, Hasher}; @@ -97,9 +96,9 @@ mod tests; pub struct VecDeque< T, #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global, - const COOP_PREFERRED: bool = DEFAULT_COOP_PREFERRED -> -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: + const COOP_PREFERRED: bool = DEFAULT_COOP_PREFERRED, +> where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { // `self[0]`, if it exists, is `buf[head]`. // `head < buf.capacity()`, unless `buf.capacity() == 0` when `head == 0`. @@ -112,8 +111,11 @@ where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRE } #[stable(feature = "rust1", since = "1.0.0")] -impl Clone for VecDeque -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +impl Clone + for VecDeque +where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ fn clone(&self) -> Self { let mut deq = Self::with_capacity_in(self.len(), self.allocator().clone()); deq.extend(self.iter().cloned()); @@ -127,8 +129,11 @@ where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRE } #[stable(feature = "rust1", since = "1.0.0")] -unsafe impl<#[may_dangle] T, A: Allocator, const COOP_PREFERRED: bool> Drop for VecDeque -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +unsafe impl<#[may_dangle] T, A: Allocator, const COOP_PREFERRED: bool> Drop + for VecDeque +where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ fn drop(&mut self) { /// Runs the destructor for all items in the slice when it gets dropped (normally or /// during unwinding). @@ -162,7 +167,9 @@ impl Default for VecDeque VecDeque -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ /// Marginally more convenient #[inline] fn ptr(&self) -> *mut T { @@ -452,13 +459,17 @@ where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRE len: usize, ) -> usize { struct Guard<'a, T, A: Allocator, const COOP_PREFERRED: bool> - where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { + where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + { deque: &'a mut VecDeque, written: usize, } impl<'a, T, A: Allocator, const COOP_PREFERRED: bool> Drop for Guard<'a, T, A, COOP_PREFERRED> - where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { + where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + { fn drop(&mut self) { self.deque.len += self.written; } @@ -536,8 +547,10 @@ where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRE } } -impl VecDeque -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +impl VecDeque +where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ /// Creates an empty deque. /// /// # Examples @@ -574,7 +587,9 @@ where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRE } impl VecDeque -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ /// Creates an empty deque. /// /// # Examples @@ -2610,7 +2625,9 @@ where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRE } impl VecDeque -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ /// Modifies the deque in-place so that `len()` is equal to new_len, /// either by removing excess elements from the back or by appending clones of `value` /// to the back. @@ -2655,8 +2672,11 @@ fn wrap_index(logical_index: usize, capacity: usize) -> usize { } #[stable(feature = "rust1", since = "1.0.0")] -impl PartialEq for VecDeque -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +impl PartialEq + for VecDeque +where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ fn eq(&self, other: &Self) -> bool { if self.len != other.len() { return false; @@ -2695,8 +2715,10 @@ where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRE } #[stable(feature = "rust1", since = "1.0.0")] -impl Eq for VecDeque -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: {} +impl Eq for VecDeque where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: +{ +} __impl_slice_eq1! { [] VecDeque, Vec, } __impl_slice_eq1! { [] VecDeque, &[U], } @@ -2706,8 +2728,11 @@ __impl_slice_eq1! { [const N: usize] VecDeque, &[U; N], } __impl_slice_eq1! { [const N: usize] VecDeque, &mut [U; N], } #[stable(feature = "rust1", since = "1.0.0")] -impl PartialOrd for VecDeque -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +impl PartialOrd + for VecDeque +where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ fn partial_cmp(&self, other: &Self) -> Option { self.iter().partial_cmp(other.iter()) } @@ -2715,7 +2740,9 @@ where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRE #[stable(feature = "rust1", since = "1.0.0")] impl Ord for VecDeque -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ #[inline] fn cmp(&self, other: &Self) -> Ordering { self.iter().cmp(other.iter()) @@ -2724,7 +2751,9 @@ where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRE #[stable(feature = "rust1", since = "1.0.0")] impl Hash for VecDeque -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ fn hash(&self, state: &mut H) { state.write_length_prefix(self.len); // It's not possible to use Hash::hash_slice on slices @@ -2739,7 +2768,9 @@ where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRE #[stable(feature = "rust1", since = "1.0.0")] impl Index for VecDeque -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ type Output = T; #[inline] @@ -2750,7 +2781,9 @@ where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRE #[stable(feature = "rust1", since = "1.0.0")] impl IndexMut for VecDeque -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ #[inline] fn index_mut(&mut self, index: usize) -> &mut T { self.get_mut(index).expect("Out of bounds access") @@ -2759,7 +2792,9 @@ where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRE #[stable(feature = "rust1", since = "1.0.0")] impl FromIterator for VecDeque -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ fn from_iter>(iter: I) -> VecDeque { SpecFromIter::spec_from_iter(iter.into_iter()) } @@ -2767,7 +2802,9 @@ where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRE #[stable(feature = "rust1", since = "1.0.0")] impl IntoIterator for VecDeque -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ type Item = T; type IntoIter = IntoIter; @@ -2779,8 +2816,11 @@ where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRE } #[stable(feature = "rust1", since = "1.0.0")] -impl<'a, T, A: Allocator, const COOP_PREFERRED: bool> IntoIterator for &'a VecDeque -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +impl<'a, T, A: Allocator, const COOP_PREFERRED: bool> IntoIterator + for &'a VecDeque +where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ type Item = &'a T; type IntoIter = Iter<'a, T>; @@ -2790,8 +2830,11 @@ where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRE } #[stable(feature = "rust1", since = "1.0.0")] -impl<'a, T, A: Allocator, const COOP_PREFERRED: bool> IntoIterator for &'a mut VecDeque -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +impl<'a, T, A: Allocator, const COOP_PREFERRED: bool> IntoIterator + for &'a mut VecDeque +where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ type Item = &'a mut T; type IntoIter = IterMut<'a, T>; @@ -2802,7 +2845,9 @@ where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRE #[stable(feature = "rust1", since = "1.0.0")] impl Extend for VecDeque -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ fn extend>(&mut self, iter: I) { >::spec_extend(self, iter.into_iter()); } @@ -2819,8 +2864,11 @@ where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRE } #[stable(feature = "extend_ref", since = "1.2.0")] -impl<'a, T: 'a + Copy, A: Allocator, const COOP_PREFERRED: bool> Extend<&'a T> for VecDeque -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +impl<'a, T: 'a + Copy, A: Allocator, const COOP_PREFERRED: bool> Extend<&'a T> + for VecDeque +where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ fn extend>(&mut self, iter: I) { self.spec_extend(iter.into_iter()); } @@ -2837,16 +2885,22 @@ where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRE } #[stable(feature = "rust1", since = "1.0.0")] -impl fmt::Debug for VecDeque -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +impl fmt::Debug + for VecDeque +where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_list().entries(self.iter()).finish() } } #[stable(feature = "vecdeque_vec_conversions", since = "1.10.0")] -impl From> for VecDeque -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +impl From> + for VecDeque +where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ /// Turn a [`Vec`] into a [`VecDeque`]. /// /// [`Vec`]: crate::vec::Vec @@ -2857,15 +2911,20 @@ where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRE /// any additional memory. #[inline] fn from(other: Vec) -> Self - where [(); alloc::co_alloc_metadata_num_slots_with_preference::(OTHER_COOP_PREFERRED)]: { + where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(OTHER_COOP_PREFERRED)]:, + { let (ptr, len, cap, alloc) = other.into_raw_parts_with_alloc(); Self { head: 0, len, buf: unsafe { RawVec::from_raw_parts_in(ptr, cap, alloc) } } } } #[stable(feature = "vecdeque_vec_conversions", since = "1.10.0")] -impl From> for Vec -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +impl From> + for Vec +where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ /// Turn a [`VecDeque`] into a [`Vec`]. /// /// [`Vec`]: crate::vec::Vec @@ -2895,7 +2954,9 @@ where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRE /// assert_eq!(vec, [8, 9, 1, 2, 3, 4]); /// assert_eq!(vec.as_ptr(), ptr); /// ``` - fn from(mut other: VecDeque) -> Self { + fn from( + mut other: VecDeque, + ) -> Self { other.make_contiguous(); unsafe { @@ -2915,8 +2976,11 @@ where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRE } #[stable(feature = "std_collections_from_array", since = "1.56.0")] -impl From<[T; N]> for VecDeque -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +impl From<[T; N]> + for VecDeque +where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ /// Converts a `[T; N]` into a `VecDeque`. /// /// ``` diff --git a/library/alloc/src/collections/vec_deque/spec_extend.rs b/library/alloc/src/collections/vec_deque/spec_extend.rs index cdeda1a57bed5..b1a9d23fd4a99 100644 --- a/library/alloc/src/collections/vec_deque/spec_extend.rs +++ b/library/alloc/src/collections/vec_deque/spec_extend.rs @@ -13,10 +13,11 @@ pub(super) trait SpecExtend { fn spec_extend(&mut self, iter: I); } -impl SpecExtend for VecDeque +impl SpecExtend + for VecDeque where I: Iterator, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { default fn spec_extend(&mut self, mut iter: I) { // This function should be the moral equivalent of: @@ -26,8 +27,12 @@ where // } // May only be called if `deque.len() < deque.capacity()` - unsafe fn push_unchecked(deque: &mut VecDeque, element: T) - where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { + unsafe fn push_unchecked( + deque: &mut VecDeque, + element: T, + ) where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + { // SAFETY: Because of the precondition, it's guaranteed that there is space // in the logical array after the last element. unsafe { deque.buffer_write(deque.to_physical_idx(deque.len), element) }; @@ -54,10 +59,11 @@ where } } -impl SpecExtend for VecDeque +impl SpecExtend + for VecDeque where I: TrustedLen, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { default fn spec_extend(&mut self, iter: I) { // This is the case for a TrustedLen iterator. @@ -90,8 +96,11 @@ where } } -impl SpecExtend> for VecDeque -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +impl SpecExtend> + for VecDeque +where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ fn spec_extend(&mut self, mut iterator: vec::IntoIter) { let slice = iterator.as_slice(); self.reserve(slice.len()); @@ -104,21 +113,23 @@ where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRE } } -impl<'a, T: 'a, I, A: Allocator, const COOP_PREFERRED: bool> SpecExtend<&'a T, I> for VecDeque +impl<'a, T: 'a, I, A: Allocator, const COOP_PREFERRED: bool> SpecExtend<&'a T, I> + for VecDeque where I: Iterator, T: Copy, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { default fn spec_extend(&mut self, iterator: I) { self.spec_extend(iterator.copied()) } } -impl<'a, T: 'a, A: Allocator, const COOP_PREFERRED: bool> SpecExtend<&'a T, slice::Iter<'a, T>> for VecDeque +impl<'a, T: 'a, A: Allocator, const COOP_PREFERRED: bool> SpecExtend<&'a T, slice::Iter<'a, T>> + for VecDeque where T: Copy, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { fn spec_extend(&mut self, iterator: slice::Iter<'a, T>) { let slice = iterator.as_slice(); diff --git a/library/alloc/src/collections/vec_deque/spec_from_iter.rs b/library/alloc/src/collections/vec_deque/spec_from_iter.rs index b9641ef156c88..85dd756337350 100644 --- a/library/alloc/src/collections/vec_deque/spec_from_iter.rs +++ b/library/alloc/src/collections/vec_deque/spec_from_iter.rs @@ -7,10 +7,11 @@ pub(super) trait SpecFromIter { fn spec_from_iter(iter: I) -> Self; } -impl SpecFromIter for VecDeque +impl SpecFromIter + for VecDeque where I: Iterator, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { default fn spec_from_iter(iterator: I) -> Self { // Since converting is O(1) now, just re-use the `Vec` logic for @@ -21,16 +22,22 @@ where } } -impl SpecFromIter> for VecDeque -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +impl SpecFromIter> + for VecDeque +where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ #[inline] fn spec_from_iter(iterator: crate::vec::IntoIter) -> Self { iterator.into_vecdeque() } } -impl SpecFromIter> for VecDeque -where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { +impl SpecFromIter> + for VecDeque +where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ #[inline] fn spec_from_iter(iterator: IntoIter) -> Self { iterator.into_vecdeque() From b8de09010ebdd151cdb50483c6922cae9ee81f31 Mon Sep 17 00:00:00 2001 From: Peter Kehl Date: Sat, 21 Jan 2023 22:07:51 -0800 Subject: [PATCH 020/118] CoAlloc: VecDeque. ICE --- library/alloc/src/collections/vec_deque/mod.rs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/library/alloc/src/collections/vec_deque/mod.rs b/library/alloc/src/collections/vec_deque/mod.rs index 0be13ed61ea7d..604fcd0c9daec 100644 --- a/library/alloc/src/collections/vec_deque/mod.rs +++ b/library/alloc/src/collections/vec_deque/mod.rs @@ -158,7 +158,7 @@ where } #[stable(feature = "rust1", since = "1.0.0")] -impl Default for VecDeque { +impl Default for VecDeque { /// Creates an empty deque. #[inline] fn default() -> VecDeque { @@ -547,7 +547,7 @@ where } } -impl VecDeque +impl VecDeque where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { @@ -581,7 +581,7 @@ where #[inline] #[stable(feature = "rust1", since = "1.0.0")] #[must_use] - pub fn with_capacity(capacity: usize) -> VecDeque { + pub fn with_capacity(capacity: usize) -> VecDeque { Self::with_capacity_in(capacity, Global) } } @@ -2791,7 +2791,7 @@ where } #[stable(feature = "rust1", since = "1.0.0")] -impl FromIterator for VecDeque +impl FromIterator for VecDeque where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { @@ -2976,8 +2976,8 @@ where } #[stable(feature = "std_collections_from_array", since = "1.56.0")] -impl From<[T; N]> - for VecDeque +impl + From<[T; N]> for VecDeque where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { @@ -2996,6 +2996,7 @@ where if !::IS_ZST { // SAFETY: VecDeque::with_capacity ensures that there is enough capacity. unsafe { + // @FIXME for COOP_PREFERRED: ptr::copy_nonoverlapping(arr.as_ptr(), deq.ptr(), N); } } From 5a70368507747cbded9b6a6e99dca3949e689c72 Mon Sep 17 00:00:00 2001 From: Peter Kehl Date: Sat, 21 Jan 2023 22:08:35 -0800 Subject: [PATCH 021/118] CoAlloc: VecDeque. ICE --- library/alloc/src/collections/vec_deque/mod.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/library/alloc/src/collections/vec_deque/mod.rs b/library/alloc/src/collections/vec_deque/mod.rs index 604fcd0c9daec..fca22a10e5987 100644 --- a/library/alloc/src/collections/vec_deque/mod.rs +++ b/library/alloc/src/collections/vec_deque/mod.rs @@ -8,7 +8,7 @@ #![feature(global_co_alloc)] #![stable(feature = "rust1", since = "1.0.0")] use crate::vec::DEFAULT_COOP_PREFERRED; -use core::alloc::{self, GlobalAlloc}; +use core::alloc; use core::cmp::{self, Ordering}; use core::fmt; use core::hash::{Hash, Hasher}; @@ -158,10 +158,10 @@ where } #[stable(feature = "rust1", since = "1.0.0")] -impl Default for VecDeque { +impl Default for VecDeque { /// Creates an empty deque. #[inline] - fn default() -> VecDeque { + fn default() -> VecDeque { VecDeque::new() } } @@ -2976,8 +2976,8 @@ where } #[stable(feature = "std_collections_from_array", since = "1.56.0")] -impl - From<[T; N]> for VecDeque +impl From<[T; N]> + for VecDeque where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { From fb970ff6e8768ee37fa2931c1315b62c620f2be7 Mon Sep 17 00:00:00 2001 From: Peter Kehl Date: Sat, 21 Jan 2023 22:09:19 -0800 Subject: [PATCH 022/118] CoAlloc: Alloc docs. ICE --- library/core/src/alloc/mod.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/library/core/src/alloc/mod.rs b/library/core/src/alloc/mod.rs index cc55c15db6268..d80f6dc17055a 100644 --- a/library/core/src/alloc/mod.rs +++ b/library/core/src/alloc/mod.rs @@ -26,6 +26,12 @@ use crate::fmt; use crate::ptr::{self, NonNull}; // @FIXME Make this target-specific +/// Metadata for `Vec/VecDeque/RawVec` to assist the allocator. Make sure its +/// alignment is not bigger than alignment of `usize`. Otherwise, even if (a +/// particular) `Vec/VecDeque/RawVec` generic instance doesn't use cooperation, +/// it would increase size of that `Vec/VecDeque/RawVec` because of alignment +/// rules! @FIXME compile time test that `GlobalCoAllocMeta` alignment <= +/// `usize` alignment. #[unstable(feature = "global_co_alloc_meta", issue = "none")] #[allow(missing_debug_implementations)] #[derive(Clone, Copy)] @@ -83,6 +89,9 @@ pub type SliceAndMetaResult = Result; #[unstable(feature = "global_co_alloc", issue = "none")] pub const fn co_alloc_metadata_num_slots() -> usize { + if true { + panic!("FIXME - consider removing co_alloc_metadata_num_slots()"); + } if A::IS_CO_ALLOCATOR { 1 } else { 0 } } From 5a97df486ba048ef5095c67fecbbac52173d3191 Mon Sep 17 00:00:00 2001 From: Peter Kehl Date: Wed, 14 Dec 2022 13:27:35 -0800 Subject: [PATCH 023/118] CoAlloc: Vec + BinaryHeap. ICE --- library/alloc/src/boxed.rs | 10 +++++++--- .../alloc/src/collections/binary_heap/mod.rs | 4 ++-- library/alloc/src/raw_vec.rs | 16 +--------------- library/alloc/src/rc.rs | 12 ++++++++++-- library/alloc/src/slice.rs | 18 +++++++++++++----- library/alloc/src/str.rs | 8 +++++++- library/alloc/src/vec/mod.rs | 8 ++++---- library/core/src/alloc/mod.rs | 13 +++++++++++++ .../std/src/sys_common/thread_local_dtor.rs | 4 +++- 9 files changed, 60 insertions(+), 33 deletions(-) diff --git a/library/alloc/src/boxed.rs b/library/alloc/src/boxed.rs index 021f36e6770bd..65baed0056619 100644 --- a/library/alloc/src/boxed.rs +++ b/library/alloc/src/boxed.rs @@ -1683,8 +1683,12 @@ impl TryFrom> for Box<[T; N]> { #[cfg(not(no_global_oom_handling))] #[stable(feature = "boxed_array_try_from_vec", since = "1.66.0")] -impl TryFrom> for Box<[T; N]> { - type Error = Vec; +impl TryFrom> + for Box<[T; N]> +where + [(); alloc::co_alloc_metadata_num_slots_with_preference_global(COOP_PREFERRED)]:, +{ + type Error = Vec; /// Attempts to convert a `Vec` into a `Box<[T; N]>`. /// @@ -1704,7 +1708,7 @@ impl TryFrom> for Box<[T; N]> { /// let state: Box<[f32; 100]> = vec![1.0; 100].try_into().unwrap(); /// assert_eq!(state.len(), 100); /// ``` - fn try_from(vec: Vec) -> Result { + fn try_from(vec: Vec) -> Result { if vec.len() == N { let boxed_slice = vec.into_boxed_slice(); Ok(unsafe { boxed_slice_as_array_unchecked(boxed_slice) }) diff --git a/library/alloc/src/collections/binary_heap/mod.rs b/library/alloc/src/collections/binary_heap/mod.rs index 3d10072ce43b4..8409954c5dbc8 100644 --- a/library/alloc/src/collections/binary_heap/mod.rs +++ b/library/alloc/src/collections/binary_heap/mod.rs @@ -1525,7 +1525,7 @@ unsafe impl TrustedLen for IntoIterSorted {} #[derive(Debug)] pub struct Drain<'a, T: 'a, const COOP_PREFERRED: bool> where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference_global(COOP_PREFERRED)]:, { iter: vec::Drain<'a, T, Global, COOP_PREFERRED>, } @@ -1533,7 +1533,7 @@ where #[stable(feature = "drain", since = "1.6.0")] impl Iterator for Drain<'_, T, COOP_PREFERRED> where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference_global(COOP_PREFERRED)]:, { type Item = T; diff --git a/library/alloc/src/raw_vec.rs b/library/alloc/src/raw_vec.rs index ddca063387d57..4d14e182e6a9e 100644 --- a/library/alloc/src/raw_vec.rs +++ b/library/alloc/src/raw_vec.rs @@ -69,7 +69,7 @@ pub(crate) struct RawVec< impl RawVec where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference_global(COOP_PREFERRED)]:, { /// HACK(Centril): This exists because stable `const fn` can only call stable `const fn`, so /// they cannot call `Self::new()`. @@ -534,20 +534,6 @@ where } } -// @FIXME Custom -unsafe impl<#[may_dangle] T, const COOP_PREFERRED: bool> Drop for RawVec -where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, -{ - /// Frees the memory owned by the `RawVec` *without* trying to drop its contents. - fn drop(&mut self) { - // @TOFIXMEDO - if let Some((ptr, layout)) = self.current_memory() { - unsafe { self.alloc.deallocate(ptr, layout) } - } - } -} - // Central function for reserve error handling. #[cfg(not(no_global_oom_handling))] #[inline] diff --git a/library/alloc/src/rc.rs b/library/alloc/src/rc.rs index fd1e3e0f75b09..c181a3bb598be 100644 --- a/library/alloc/src/rc.rs +++ b/library/alloc/src/rc.rs @@ -247,6 +247,7 @@ use crate::boxed::Box; #[cfg(test)] use std::boxed::Box; +use crate::alloc; use core::any::Any; use core::borrow; use core::cell::Cell; @@ -1987,7 +1988,10 @@ impl From> for Rc { #[cfg(not(no_global_oom_handling))] #[stable(feature = "shared_from_slice", since = "1.21.0")] -impl From> for Rc<[T]> { +impl From> for Rc<[T]> +where + [(); alloc::co_alloc_metadata_num_slots_with_preference_global(COOP_PREFERRED)]:, +{ /// Allocate a reference-counted slice and move `v`'s items into it. /// /// # Example @@ -1999,7 +2003,10 @@ impl From> for Rc<[T]> { /// assert_eq!(vec![1, 2, 3], *shared); /// ``` #[inline] - fn from(mut v: Vec) -> Rc<[T]> { + fn from(mut v: Vec) -> Rc<[T]> + where + [(); alloc::co_alloc_metadata_num_slots_with_preference_global(COOP_PREFERRED)]:, + { unsafe { let rc = Rc::copy_from_slice(&v); // Allow the Vec to free its memory, but not destroy its contents @@ -2120,6 +2127,7 @@ trait ToRcSlice: Iterator + Sized { fn to_rc_slice(self) -> Rc<[T]>; } +// COOP_NOT_POSSIBLE #[cfg(not(no_global_oom_handling))] impl> ToRcSlice for I { default fn to_rc_slice(self) -> Rc<[T]> { diff --git a/library/alloc/src/slice.rs b/library/alloc/src/slice.rs index f0c90874d1d0d..406f0a9e6fb8b 100644 --- a/library/alloc/src/slice.rs +++ b/library/alloc/src/slice.rs @@ -466,10 +466,13 @@ impl [T] { #[rustc_allow_incoherent_impl] #[inline] #[unstable(feature = "allocator_api", issue = "32838")] - pub fn to_vec_in(&self, alloc: A) -> Vec + pub fn to_vec_in( + &self, + alloc: A, + ) -> Vec where T: Clone, - [(); core::alloc::co_alloc_metadata_num_slots::()]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { // N.B., see the `hack` module in this file for more details. hack::to_vec(self, alloc) @@ -492,9 +495,11 @@ impl [T] { #[rustc_allow_incoherent_impl] #[stable(feature = "rust1", since = "1.0.0")] #[inline] - pub fn into_vec(self: Box) -> Vec + pub fn into_vec( + self: Box, + ) -> Vec where - [(); core::alloc::co_alloc_metadata_num_slots::()]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { // N.B., see the `hack` module in this file for more details. hack::into_vec(self) @@ -739,6 +744,7 @@ pub trait Join { fn join(slice: &Self, sep: Separator) -> Self::Output; } +// COOP_NOT_POSSIBLE #[cfg(not(no_global_oom_handling))] #[unstable(feature = "slice_concat_ext", issue = "27747")] impl> Concat for [V] { @@ -754,6 +760,7 @@ impl> Concat for [V] { } } +// COOP_NOT_POSSIBLE #[cfg(not(no_global_oom_handling))] #[unstable(feature = "slice_concat_ext", issue = "27747")] impl> Join<&T> for [V] { @@ -777,10 +784,11 @@ impl> Join<&T> for [V] { } } +// COOP_NOT_POSSIBLE #[cfg(not(no_global_oom_handling))] #[unstable(feature = "slice_concat_ext", issue = "27747")] impl> Join<&[T]> for [V] { - type Output = Vec; + type Output = Vec; fn join(slice: &Self, sep: &[T]) -> Vec { let mut iter = slice.iter(); diff --git a/library/alloc/src/str.rs b/library/alloc/src/str.rs index afbe5cfaf8ef9..eedf856f5d253 100644 --- a/library/alloc/src/str.rs +++ b/library/alloc/src/str.rs @@ -14,6 +14,8 @@ use core::ptr; use core::str::pattern::{DoubleEndedSearcher, Pattern, ReverseSearcher, Searcher}; use core::unicode::conversions; +use crate::alloc; +use crate::alloc::Global; use crate::borrow::ToOwned; use crate::boxed::Box; use crate::slice::{Concat, Join, SliceIndex}; @@ -126,11 +128,15 @@ macro_rules! copy_slice_and_advance { // [T] and str both impl AsRef<[T]> for some T // => s.borrow().as_ref() and we always have slices #[cfg(not(no_global_oom_handling))] -fn join_generic_copy(slice: &[S], sep: &[T]) -> Vec +fn join_generic_copy( + slice: &[S], + sep: &[T], +) -> Vec where T: Copy, B: AsRef<[T]> + ?Sized, S: Borrow, + [(); alloc::co_alloc_metadata_num_slots_with_preference_global(COOP_PREFERRED)]:, { let sep_len = sep.len(); let mut iter = slice.iter(); diff --git a/library/alloc/src/vec/mod.rs b/library/alloc/src/vec/mod.rs index 12cc862e70b7a..ec0b4100a4ba8 100644 --- a/library/alloc/src/vec/mod.rs +++ b/library/alloc/src/vec/mod.rs @@ -408,6 +408,10 @@ pub struct Vec< len: usize, } +/// Default `Vec`, `DefVec`, `DecVeque`, `DefDecVeq` "cooperation" (`COOP_PREFERRED`) generic parameter. +#[unstable(feature = "global_co_alloc_def", issue = "none")] +pub const DEFAULT_COOP_PREFERRED: bool = true; + #[unstable(feature = "global_co_alloc_covec", issue = "none")] pub type CoVec = Vec; @@ -417,10 +421,6 @@ pub type CoVec = Vec; -/// Default `Vec`, `DefVec`, `DecVeque`, `DefDecVeq` "cooperation" (`COOP_PREFERRED`) generic parameter. -#[unstable(feature = "global_co_alloc_def", issue = "none")] -pub const DEFAULT_COOP_PREFERRED: bool = true; - /// "Default" Vec. Either "cooperative" or not - as specified by `DEFAULT_COOP_PREFERRED`. The /// difference to `Vec` (used without specifying `COOP_PREFERRED`): `DefVec` indicates that the /// author considered using `CoVec` or `PlVec`, but left it to default instead. diff --git a/library/core/src/alloc/mod.rs b/library/core/src/alloc/mod.rs index d80f6dc17055a..4a61a9e5215be 100644 --- a/library/core/src/alloc/mod.rs +++ b/library/core/src/alloc/mod.rs @@ -104,6 +104,19 @@ pub const fn co_alloc_metadata_num_slots_with_preference( if A::IS_CO_ALLOCATOR && coop_preferred { 1 } else { 0 } } +#[unstable(feature = "global_co_alloc", issue = "none")] +/// Param `coop_preferred` - if false, then this returns `0`, regardless of +/// whether allocator `A` is cooperative. +pub const fn co_alloc_metadata_num_slots_with_preference_global(_coop_preferred: bool) -> usize { + if true { + panic!("FIXME"); + } + // @FIXME Move these functions to :alloc instead. + // Then: + 0 + //if Global::IS_CO_ALLOCATOR && coop_preferred { 1 } else { 0 } +} + /// An implementation of `Allocator` can allocate, grow, shrink, and deallocate arbitrary blocks of /// data described via [`Layout`][]. /// diff --git a/library/std/src/sys_common/thread_local_dtor.rs b/library/std/src/sys_common/thread_local_dtor.rs index 844946eda031f..43b7b0bb00468 100644 --- a/library/std/src/sys_common/thread_local_dtor.rs +++ b/library/std/src/sys_common/thread_local_dtor.rs @@ -12,9 +12,11 @@ #![unstable(feature = "thread_local_internals", issue = "none")] #![allow(dead_code)] +#![feature(global_co_alloc_plvec)] use crate::ptr; use crate::sys_common::thread_local_key::StaticKey; +use alloc::vec::PlVec; pub unsafe fn register_dtor_fallback(t: *mut u8, dtor: unsafe extern "C" fn(*mut u8)) { // The fallback implementation uses a vanilla OS-based TLS key to track @@ -28,7 +30,7 @@ pub unsafe fn register_dtor_fallback(t: *mut u8, dtor: unsafe extern "C" fn(*mut // flagged for destruction. static DTORS: StaticKey = StaticKey::new(Some(run_dtors)); - type List = Vec<(*mut u8, unsafe extern "C" fn(*mut u8))>; + type List = PlVec<(*mut u8, unsafe extern "C" fn(*mut u8))>; if DTORS.get().is_null() { let v: Box = Box::new(Vec::new()); DTORS.set(Box::into_raw(v) as *mut u8); From 9704c3cd47091f996895aaa928fe15316f6ac55a Mon Sep 17 00:00:00 2001 From: Peter Kehl Date: Sat, 21 Jan 2023 22:12:07 -0800 Subject: [PATCH 024/118] CoAlloc: WeVec. ICE --- library/alloc/src/vec/mod.rs | 2 +- library/std/src/sys/windows/mod.rs | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/library/alloc/src/vec/mod.rs b/library/alloc/src/vec/mod.rs index ec0b4100a4ba8..ee36b83d90beb 100644 --- a/library/alloc/src/vec/mod.rs +++ b/library/alloc/src/vec/mod.rs @@ -432,7 +432,7 @@ pub type DefVec = Vec 1 }>; +pub type WeVec = Vec 127 }>; //////////////////////////////////////////////////////////////////////////////// // Inherent methods diff --git a/library/std/src/sys/windows/mod.rs b/library/std/src/sys/windows/mod.rs index 77359abe42995..0296c2dab5552 100644 --- a/library/std/src/sys/windows/mod.rs +++ b/library/std/src/sys/windows/mod.rs @@ -204,6 +204,7 @@ where // incorrect size hints for some short paths: // https://github.com/dylni/normpath/issues/5 let mut stack_buf: [MaybeUninit; 512] = MaybeUninit::uninit_array(); + // @FIXME Use CoVec? let mut heap_buf: Vec> = Vec::new(); unsafe { let mut n = stack_buf.len(); From 9beba9a96596dc6c14c5cd5e905a366b646e3b17 Mon Sep 17 00:00:00 2001 From: Peter Kehl Date: Sat, 21 Jan 2023 22:15:44 -0800 Subject: [PATCH 025/118] CoAlloc: Vec + Alloc. Moved co_alloc_metadata_num_slots_with_preference_global from ::core::alloc to ::alloc. ICE --- library/alloc/src/boxed.rs | 2 +- library/alloc/src/lib.rs | 7 +++++++ library/alloc/src/raw_vec.rs | 2 +- library/alloc/src/rc.rs | 5 ++--- library/alloc/src/vec/mod.rs | 1 + library/core/src/alloc/mod.rs | 13 ------------- 6 files changed, 12 insertions(+), 18 deletions(-) diff --git a/library/alloc/src/boxed.rs b/library/alloc/src/boxed.rs index 65baed0056619..615744a2d60a3 100644 --- a/library/alloc/src/boxed.rs +++ b/library/alloc/src/boxed.rs @@ -1686,7 +1686,7 @@ impl TryFrom> for Box<[T; N]> { impl TryFrom> for Box<[T; N]> where - [(); alloc::co_alloc_metadata_num_slots_with_preference_global(COOP_PREFERRED)]:, + [(); crate::co_alloc_metadata_num_slots_with_preference_global(COOP_PREFERRED)]:, { type Error = Vec; diff --git a/library/alloc/src/lib.rs b/library/alloc/src/lib.rs index 64c4d7fb4ee6f..47eb67a5b10af 100644 --- a/library/alloc/src/lib.rs +++ b/library/alloc/src/lib.rs @@ -285,4 +285,11 @@ pub(crate) mod test_helpers { let seed: [u8; 16] = seed_vec.as_slice().try_into().unwrap(); rand::SeedableRng::from_seed(seed) } + +use crate::alloc::Global; + +/// See also `core::alloc::co_alloc_metadata_num_slots_with_preference`. +#[unstable(feature = "global_co_alloc", issue = "none")] +pub const fn co_alloc_metadata_num_slots_with_preference_global(coop_preferred: bool) -> usize { + if Global::IS_CO_ALLOCATOR && coop_preferred { 1 } else { 0 } } diff --git a/library/alloc/src/raw_vec.rs b/library/alloc/src/raw_vec.rs index 4d14e182e6a9e..8b61917144aa5 100644 --- a/library/alloc/src/raw_vec.rs +++ b/library/alloc/src/raw_vec.rs @@ -69,7 +69,7 @@ pub(crate) struct RawVec< impl RawVec where - [(); alloc::co_alloc_metadata_num_slots_with_preference_global(COOP_PREFERRED)]:, + [(); crate::co_alloc_metadata_num_slots_with_preference_global(COOP_PREFERRED)]:, { /// HACK(Centril): This exists because stable `const fn` can only call stable `const fn`, so /// they cannot call `Self::new()`. diff --git a/library/alloc/src/rc.rs b/library/alloc/src/rc.rs index c181a3bb598be..8bdc67a35af5f 100644 --- a/library/alloc/src/rc.rs +++ b/library/alloc/src/rc.rs @@ -247,7 +247,6 @@ use crate::boxed::Box; #[cfg(test)] use std::boxed::Box; -use crate::alloc; use core::any::Any; use core::borrow; use core::cell::Cell; @@ -1990,7 +1989,7 @@ impl From> for Rc { #[stable(feature = "shared_from_slice", since = "1.21.0")] impl From> for Rc<[T]> where - [(); alloc::co_alloc_metadata_num_slots_with_preference_global(COOP_PREFERRED)]:, + [(); crate::co_alloc_metadata_num_slots_with_preference_global(COOP_PREFERRED)]:, { /// Allocate a reference-counted slice and move `v`'s items into it. /// @@ -2005,7 +2004,7 @@ where #[inline] fn from(mut v: Vec) -> Rc<[T]> where - [(); alloc::co_alloc_metadata_num_slots_with_preference_global(COOP_PREFERRED)]:, + [(); crate::co_alloc_metadata_num_slots_with_preference_global(COOP_PREFERRED)]:, { unsafe { let rc = Rc::copy_from_slice(&v); diff --git a/library/alloc/src/vec/mod.rs b/library/alloc/src/vec/mod.rs index ee36b83d90beb..d444b3c25ba91 100644 --- a/library/alloc/src/vec/mod.rs +++ b/library/alloc/src/vec/mod.rs @@ -400,6 +400,7 @@ mod spec_extend; pub struct Vec< T, #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global, + //@FIXME: #[unstable(feature ="global_co_alloc_vec", issue="none")] const COOP_PREFERRED: bool = DEFAULT_COOP_PREFERRED, > where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, diff --git a/library/core/src/alloc/mod.rs b/library/core/src/alloc/mod.rs index 4a61a9e5215be..d80f6dc17055a 100644 --- a/library/core/src/alloc/mod.rs +++ b/library/core/src/alloc/mod.rs @@ -104,19 +104,6 @@ pub const fn co_alloc_metadata_num_slots_with_preference( if A::IS_CO_ALLOCATOR && coop_preferred { 1 } else { 0 } } -#[unstable(feature = "global_co_alloc", issue = "none")] -/// Param `coop_preferred` - if false, then this returns `0`, regardless of -/// whether allocator `A` is cooperative. -pub const fn co_alloc_metadata_num_slots_with_preference_global(_coop_preferred: bool) -> usize { - if true { - panic!("FIXME"); - } - // @FIXME Move these functions to :alloc instead. - // Then: - 0 - //if Global::IS_CO_ALLOCATOR && coop_preferred { 1 } else { 0 } -} - /// An implementation of `Allocator` can allocate, grow, shrink, and deallocate arbitrary blocks of /// data described via [`Layout`][]. /// From 5569b1f426e55a9d9b3a0000817045d35582c7c0 Mon Sep 17 00:00:00 2001 From: Peter Kehl Date: Sat, 21 Jan 2023 22:16:10 -0800 Subject: [PATCH 026/118] CoAlloc: BinaryHeap. ICE --- library/alloc/src/collections/binary_heap/mod.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library/alloc/src/collections/binary_heap/mod.rs b/library/alloc/src/collections/binary_heap/mod.rs index 8409954c5dbc8..f1b0cc4a72424 100644 --- a/library/alloc/src/collections/binary_heap/mod.rs +++ b/library/alloc/src/collections/binary_heap/mod.rs @@ -1525,7 +1525,7 @@ unsafe impl TrustedLen for IntoIterSorted {} #[derive(Debug)] pub struct Drain<'a, T: 'a, const COOP_PREFERRED: bool> where - [(); alloc::co_alloc_metadata_num_slots_with_preference_global(COOP_PREFERRED)]:, + [(); crate::co_alloc_metadata_num_slots_with_preference_global(COOP_PREFERRED)]:, { iter: vec::Drain<'a, T, Global, COOP_PREFERRED>, } @@ -1533,7 +1533,7 @@ where #[stable(feature = "drain", since = "1.6.0")] impl Iterator for Drain<'_, T, COOP_PREFERRED> where - [(); alloc::co_alloc_metadata_num_slots_with_preference_global(COOP_PREFERRED)]:, + [(); crate::co_alloc_metadata_num_slots_with_preference_global(COOP_PREFERRED)]:, { type Item = T; From 19d643c44c2f9792f1551697a55336bd9ab58aab Mon Sep 17 00:00:00 2001 From: Peter Kehl Date: Sun, 22 Jan 2023 07:41:26 -0800 Subject: [PATCH 027/118] CoAlloc: Vec: Renamed ::core::alloc::co_alloc_metadata_num_slots_with_preference to ::core::alloc::co_alloc_metadata_num_slots_with_preference_specific. ICE --- library/alloc/src/raw_vec.rs | 20 ++--- library/alloc/src/slice.rs | 40 +++++++--- library/alloc/src/vec/drain.rs | 28 +++---- library/alloc/src/vec/drain_filter.rs | 12 +-- library/alloc/src/vec/into_iter.rs | 36 ++++----- library/alloc/src/vec/mod.rs | 98 +++++++++++++++---------- library/alloc/src/vec/partial_eq.rs | 20 ++--- library/alloc/src/vec/spec_extend.rs | 10 +-- library/alloc/src/vec/spec_from_elem.rs | 8 +- library/core/src/alloc/mod.rs | 2 +- library/std/src/io/cursor.rs | 12 +-- 11 files changed, 164 insertions(+), 122 deletions(-) diff --git a/library/alloc/src/raw_vec.rs b/library/alloc/src/raw_vec.rs index 8b61917144aa5..a6a4b4f4c9b56 100644 --- a/library/alloc/src/raw_vec.rs +++ b/library/alloc/src/raw_vec.rs @@ -55,7 +55,7 @@ pub(crate) struct RawVec< A: Allocator = Global, const COOP_PREFERRED: bool = DEFAULT_COOP_PREFERRED, > where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, { ptr: Unique, cap: usize, @@ -64,7 +64,7 @@ pub(crate) struct RawVec< //pub(crate) meta: [GlobalCoAllocMeta; {if core::any::TypeId::of::()==core::any::TypeId::of::() {1} else {0}}], //pub(crate) meta: [GlobalCoAllocMeta; mem::size_of::()], pub(crate) metas: [GlobalCoAllocMeta; - alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)], + alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)], } impl RawVec @@ -119,7 +119,7 @@ where impl RawVec where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, { // Tiny Vecs are dumb. Skip to: // - 8 if the element size is 1, because any heap allocators is likely @@ -143,7 +143,7 @@ where cap: 0, alloc, metas: [GlobalCoAllocMeta {/*one: 1*/ /* , two: 2, three: 3, four: 4*/}; - alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)], + alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)], } } @@ -222,7 +222,9 @@ where cap: capacity, alloc, metas: [GlobalCoAllocMeta {/*one: 1*/ /*, two: 2, three: 3, four: 4*/}; - alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)], + alloc::co_alloc_metadata_num_slots_with_preference_specific::( + COOP_PREFERRED, + )], } } } @@ -244,7 +246,7 @@ where cap: capacity, alloc, metas: [GlobalCoAllocMeta {/*one: 1*/ /*, two: 2, three: 3, four: 4*/}; - alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)], + alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)], } } @@ -319,7 +321,7 @@ where len: usize, additional: usize, ) where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, { handle_reserve(slf.grow_amortized(len, additional)); } @@ -395,7 +397,7 @@ where impl RawVec where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, { /// Returns if the buffer needs to grow to fulfill the needed extra capacity. /// Mainly used to make inlining reserve-calls possible without inlining `grow`. @@ -519,7 +521,7 @@ where unsafe impl<#[may_dangle] T, A: Allocator, const COOP_PREFERRED: bool> Drop for RawVec where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, { /// Frees the memory owned by the `RawVec` *without* trying to drop its contents. default fn drop(&mut self) { diff --git a/library/alloc/src/slice.rs b/library/alloc/src/slice.rs index 406f0a9e6fb8b..b3118ce23f028 100644 --- a/library/alloc/src/slice.rs +++ b/library/alloc/src/slice.rs @@ -101,7 +101,9 @@ pub(crate) mod hack { b: Box<[T], A>, ) -> Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference_specific::( + COOP_PREFERRED, + )]:, { unsafe { let len = b.len(); @@ -117,7 +119,9 @@ pub(crate) mod hack { alloc: A, ) -> Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference_specific::( + COOP_PREFERRED, + )]:, { T::to_vec(s, alloc) } @@ -130,7 +134,9 @@ pub(crate) mod hack { ) -> Vec where Self: Sized, - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:; + [(); core::alloc::co_alloc_metadata_num_slots_with_preference_specific::( + COOP_PREFERRED, + )]:; } #[cfg(not(no_global_oom_handling))] @@ -141,18 +147,24 @@ pub(crate) mod hack { alloc: A, ) -> Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference_specific::( + COOP_PREFERRED, + )]:, { struct DropGuard<'a, T, A: Allocator, const COOP_PREFERRED: bool> where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference_specific::( + COOP_PREFERRED, + )]:, { vec: &'a mut Vec, num_init: usize, } impl<'a, T, A: Allocator, const COOP_PREFERRED: bool> Drop for DropGuard<'a, T, A, COOP_PREFERRED> where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference_specific::( + COOP_PREFERRED, + )]:, { #[inline] fn drop(&mut self) { @@ -190,7 +202,9 @@ pub(crate) mod hack { alloc: A, ) -> Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference_specific::( + COOP_PREFERRED, + )]:, { let mut v = Vec::with_capacity_in(s.len(), alloc); // SAFETY: @@ -472,7 +486,9 @@ impl [T] { ) -> Vec where T: Clone, - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference_specific::( + COOP_PREFERRED, + )]:, { // N.B., see the `hack` module in this file for more details. hack::to_vec(self, alloc) @@ -499,7 +515,9 @@ impl [T] { self: Box, ) -> Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference_specific::( + COOP_PREFERRED, + )]:, { // N.B., see the `hack` module in this file for more details. hack::into_vec(self) @@ -816,7 +834,7 @@ impl> Join<&[T]> for [V] { #[stable(feature = "rust1", since = "1.0.0")] impl Borrow<[T]> for Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, { fn borrow(&self) -> &[T] { &self[..] @@ -826,7 +844,7 @@ where #[stable(feature = "rust1", since = "1.0.0")] impl BorrowMut<[T]> for Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, { fn borrow_mut(&mut self) -> &mut [T] { &mut self[..] diff --git a/library/alloc/src/vec/drain.rs b/library/alloc/src/vec/drain.rs index d7f7292e4f1cf..2159edc7b1a23 100644 --- a/library/alloc/src/vec/drain.rs +++ b/library/alloc/src/vec/drain.rs @@ -25,7 +25,7 @@ pub struct Drain< #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator + 'a = Global, const COOP_PREFERRED: bool = { alloc::SHORT_TERM_VEC_PREFERS_COOP }, > where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, { /// Index of tail to preserve pub(super) tail_start: usize, @@ -40,7 +40,7 @@ pub struct Drain< impl fmt::Debug for Drain<'_, T, A, COOP_PREFERRED> where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_tuple("Drain").field(&self.iter.as_slice()).finish() @@ -49,7 +49,7 @@ where impl<'a, T, A: Allocator, const COOP_PREFERRED: bool> Drain<'a, T, A, COOP_PREFERRED> where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, { /// Returns the remaining items of this iterator as a slice. /// @@ -151,7 +151,7 @@ where #[stable(feature = "vec_drain_as_slice", since = "1.46.0")] impl<'a, T, A: Allocator, const COOP_PREFERRED: bool> AsRef<[T]> for Drain<'a, T, A, COOP_PREFERRED> where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, { fn as_ref(&self) -> &[T] { self.as_slice() @@ -162,21 +162,21 @@ where unsafe impl Sync for Drain<'_, T, A, COOP_PREFERRED> where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, { } #[stable(feature = "drain", since = "1.6.0")] unsafe impl Send for Drain<'_, T, A, COOP_PREFERRED> where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, { } #[stable(feature = "drain", since = "1.6.0")] impl Iterator for Drain<'_, T, A, COOP_PREFERRED> where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, { type Item = T; @@ -194,7 +194,7 @@ where impl DoubleEndedIterator for Drain<'_, T, A, COOP_PREFERRED> where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, { #[inline] fn next_back(&mut self) -> Option { @@ -205,7 +205,7 @@ where #[stable(feature = "drain", since = "1.6.0")] impl Drop for Drain<'_, T, A, COOP_PREFERRED> where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, { fn drop(&mut self) { /// Moves back the un-`Drain`ed elements to restore the original `Vec`. @@ -213,12 +213,12 @@ where &'r mut Drain<'a, T, A, COOP_PREFERRED>, ) where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:; + [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:; impl<'r, 'a, T, A: Allocator, const COOP_PREFERRED: bool> Drop for DropGuard<'r, 'a, T, A, COOP_PREFERRED> where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, { fn drop(&mut self) { if self.0.tail_len > 0 { @@ -286,7 +286,7 @@ where impl ExactSizeIterator for Drain<'_, T, A, COOP_PREFERRED> where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, { fn is_empty(&self) -> bool { self.iter.is_empty() @@ -297,12 +297,12 @@ where unsafe impl TrustedLen for Drain<'_, T, A, COOP_PREFERRED> where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, { } #[stable(feature = "fused", since = "1.26.0")] impl FusedIterator for Drain<'_, T, A, COOP_PREFERRED> where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: + [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]: { } diff --git a/library/alloc/src/vec/drain_filter.rs b/library/alloc/src/vec/drain_filter.rs index 89baafca46729..29cf29e2532d9 100644 --- a/library/alloc/src/vec/drain_filter.rs +++ b/library/alloc/src/vec/drain_filter.rs @@ -27,7 +27,7 @@ pub struct DrainFilter< const COOP_PREFERRED: bool = true, > where F: FnMut(&mut T) -> bool, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, { pub(super) vec: &'a mut Vec, /// The index of the item that will be inspected by the next call to `next`. @@ -49,7 +49,7 @@ pub struct DrainFilter< impl DrainFilter<'_, T, F, A, COOP_PREFERRED> where F: FnMut(&mut T) -> bool, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, { /// Returns a reference to the underlying allocator. #[unstable(feature = "allocator_api", issue = "32838")] @@ -119,7 +119,7 @@ impl Iterator for DrainFilter<'_, T, F, A, COOP_PREFERRED> where F: FnMut(&mut T) -> bool, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, { type Item = T; @@ -159,13 +159,13 @@ impl Drop for DrainFilter<'_, T, F, A, COOP_PREFERRED> where F: FnMut(&mut T) -> bool, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, { fn drop(&mut self) { struct BackshiftOnDrop<'a, 'b, T, F, A: Allocator, const COOP_PREFERRED: bool> where F: FnMut(&mut T) -> bool, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, { drain: &'b mut DrainFilter<'a, T, F, A, COOP_PREFERRED>, } @@ -174,7 +174,7 @@ where for BackshiftOnDrop<'a, 'b, T, F, A, COOP_PREFERRED> where F: FnMut(&mut T) -> bool, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, { fn drop(&mut self) { unsafe { diff --git a/library/alloc/src/vec/into_iter.rs b/library/alloc/src/vec/into_iter.rs index 790e6323f514e..98b7a7cda6731 100644 --- a/library/alloc/src/vec/into_iter.rs +++ b/library/alloc/src/vec/into_iter.rs @@ -33,7 +33,7 @@ pub struct IntoIter< #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global, const COOP_PREFERRED: bool = { alloc::SHORT_TERM_VEC_PREFERS_COOP }, > where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, { pub(super) buf: NonNull, pub(super) phantom: PhantomData, @@ -51,7 +51,7 @@ pub struct IntoIter< impl fmt::Debug for IntoIter where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_tuple("IntoIter").field(&self.as_slice()).finish() @@ -60,7 +60,7 @@ where impl IntoIter where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, { /// Returns the remaining items of this iterator as a slice. /// @@ -179,7 +179,7 @@ where #[stable(feature = "vec_intoiter_as_ref", since = "1.46.0")] impl AsRef<[T]> for IntoIter where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, { fn as_ref(&self) -> &[T] { self.as_slice() @@ -190,21 +190,21 @@ where unsafe impl Send for IntoIter where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, { } #[stable(feature = "rust1", since = "1.0.0")] unsafe impl Sync for IntoIter where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, { } #[stable(feature = "rust1", since = "1.0.0")] impl Iterator for IntoIter where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, { type Item = T; @@ -322,7 +322,7 @@ where impl DoubleEndedIterator for IntoIter where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, { #[inline] fn next_back(&mut self) -> Option { @@ -367,7 +367,7 @@ where impl ExactSizeIterator for IntoIter where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, { fn is_empty(&self) -> bool { self.ptr == self.end @@ -376,7 +376,7 @@ where #[stable(feature = "fused", since = "1.26.0")] impl FusedIterator for IntoIter where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: + [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]: { } @@ -384,7 +384,7 @@ impl FusedIterator for IntoIter TrustedLen for IntoIter where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, { } @@ -406,7 +406,7 @@ unsafe impl TrustedRandomAccessNoCo for IntoIter where T: NonDrop, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, { const MAY_HAVE_SIDE_EFFECT: bool = false; } @@ -416,7 +416,7 @@ where impl Clone for IntoIter where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, { #[cfg(not(test))] fn clone(&self) -> Self { @@ -432,18 +432,18 @@ where unsafe impl<#[may_dangle] T, A: Allocator, const COOP_PREFERRED: bool> Drop for IntoIter where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, { fn drop(&mut self) { struct DropGuard<'a, T, A: Allocator, const COOP_PREFERRED: bool>( &'a mut IntoIter, ) where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:; + [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:; impl Drop for DropGuard<'_, T, A, COOP_PREFERRED> where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, { fn drop(&mut self) { unsafe { @@ -475,7 +475,7 @@ where unsafe impl InPlaceIterable for IntoIter where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, { } @@ -484,7 +484,7 @@ where unsafe impl SourceIter for IntoIter where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, { type Source = Self; diff --git a/library/alloc/src/vec/mod.rs b/library/alloc/src/vec/mod.rs index d444b3c25ba91..8c1025f6b2261 100644 --- a/library/alloc/src/vec/mod.rs +++ b/library/alloc/src/vec/mod.rs @@ -403,7 +403,7 @@ pub struct Vec< //@FIXME: #[unstable(feature ="global_co_alloc_vec", issue="none")] const COOP_PREFERRED: bool = DEFAULT_COOP_PREFERRED, > where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, { buf: RawVec, len: usize, @@ -628,7 +628,7 @@ impl Vec { impl Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, { /// Constructs a new, empty `Vec`. /// @@ -1644,7 +1644,9 @@ where // In cases when predicate and `drop` never panick, it will be optimized out. struct BackshiftOnDrop<'a, T, A: Allocator, const VEC_IS_COOP: bool = true> where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(VEC_IS_COOP)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference_specific::( + VEC_IS_COOP, + )]:, { v: &'a mut Vec, processed_len: usize, @@ -1654,7 +1656,9 @@ where impl Drop for BackshiftOnDrop<'_, T, A, VEC_IS_COOP> where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(VEC_IS_COOP)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference_specific::( + VEC_IS_COOP, + )]:, { fn drop(&mut self) { if self.deleted_cnt > 0 { @@ -1687,7 +1691,9 @@ where g: &mut BackshiftOnDrop<'_, T, A, VEC_IS_COOP>, ) where F: FnMut(&mut T) -> bool, - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(VEC_IS_COOP)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference_specific::( + VEC_IS_COOP, + )]:, { while g.processed_len != original_len { // SAFETY: Unchecked element must be valid. @@ -1782,7 +1788,9 @@ where /* INVARIANT: vec.len() > read >= write > write-1 >= 0 */ struct FillGapOnDrop<'a, T, A: core::alloc::Allocator, const COOP_PREFERRED: bool> where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference_specific::( + COOP_PREFERRED, + )]:, { /* Offset of the element we want to check if it is duplicate */ read: usize, @@ -1798,7 +1806,9 @@ where impl<'a, T, A: core::alloc::Allocator, const COOP_PREFERRED: bool> Drop for FillGapOnDrop<'a, T, A, COOP_PREFERRED> where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference_specific::( + COOP_PREFERRED, + )]:, { fn drop(&mut self) { /* This code gets executed when `same_bucket` panics */ @@ -2394,7 +2404,7 @@ where impl Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, { /// Resizes the `Vec` in-place so that `len` is equal to `new_len`. /// @@ -2496,7 +2506,7 @@ where impl Vec<[T; N], A, COOP_PREFERRED> where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, { /// Takes a `Vec<[T; N]>` and flattens it into a `Vec`. /// @@ -2560,7 +2570,7 @@ impl ExtendWith for ExtendElement { impl Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, { #[cfg(not(no_global_oom_handling))] /// Extend the vector by `n` values, using the given generator. @@ -2595,7 +2605,7 @@ where impl Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, { /// Removes consecutive repeated elements in the vector according to the /// [`PartialEq`] trait implementation. @@ -2638,7 +2648,7 @@ pub fn from_elem_in( alloc: A, ) -> Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, { ::from_elem(elem, n, alloc) } @@ -2654,7 +2664,7 @@ trait ExtendFromWithinSpec { impl ExtendFromWithinSpec for Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, { default unsafe fn spec_extend_from_within(&mut self, src: Range) { // SAFETY: @@ -2677,7 +2687,7 @@ where impl ExtendFromWithinSpec for Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, { unsafe fn spec_extend_from_within(&mut self, src: Range) { let count = src.len(); @@ -2713,7 +2723,7 @@ where #[stable(feature = "rust1", since = "1.0.0")] impl ops::Deref for Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, { type Target = [T]; @@ -2726,7 +2736,7 @@ where #[stable(feature = "rust1", since = "1.0.0")] impl ops::DerefMut for Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, { #[inline] fn deref_mut(&mut self) -> &mut [T] { @@ -2735,10 +2745,22 @@ where } #[cfg(not(no_global_oom_handling))] +impl SpecCloneFrom for Vec +where + [(); core::alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, +{ + fn clone_from(this: &mut Self, other: &Self) { + this.clear(); + this.extend_from_slice(other); + } +} + +#[cfg(not(no_global_oom_handling))] +>>>>>>> 72db464d2e0 (CoAlloc: Vec: Renamed ::core::alloc::co_alloc_metadata_num_slots_with_preference to ::core::alloc::co_alloc_metadata_num_slots_with_preference_specific. ICE) #[stable(feature = "rust1", since = "1.0.0")] impl Clone for Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, { #[cfg(not(test))] fn clone(&self) -> Self { @@ -2776,7 +2798,7 @@ where #[stable(feature = "rust1", since = "1.0.0")] impl Hash for Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, { #[inline] fn hash(&self, state: &mut H) { @@ -2792,7 +2814,7 @@ where impl, A: Allocator, const COOP_PREFERRED: bool> Index for Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, { type Output = I::Output; @@ -2810,7 +2832,7 @@ where impl, A: Allocator, const COOP_PREFERRED: bool> IndexMut for Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, { #[inline] fn index_mut(&mut self, index: I) -> &mut Self::Output { @@ -2830,7 +2852,7 @@ impl FromIterator for Vec { #[stable(feature = "rust1", since = "1.0.0")] impl IntoIterator for Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, { type Item = T; type IntoIter = IntoIter; @@ -2878,7 +2900,7 @@ where #[stable(feature = "rust1", since = "1.0.0")] impl<'a, T, A: Allocator, const COOP_PREFERRED: bool> IntoIterator for &'a Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, { type Item = &'a T; type IntoIter = slice::Iter<'a, T>; @@ -2892,7 +2914,7 @@ where impl<'a, T, A: Allocator, const COOP_PREFERRED: bool> IntoIterator for &'a mut Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, { type Item = &'a mut T; type IntoIter = slice::IterMut<'a, T>; @@ -2906,7 +2928,7 @@ where #[stable(feature = "rust1", since = "1.0.0")] impl Extend for Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, { #[inline] fn extend>(&mut self, iter: I) { @@ -2926,7 +2948,7 @@ where impl Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, { // leaf method to which various SpecFrom/SpecExtend implementations delegate when // they have no further optimizations to apply @@ -3104,7 +3126,7 @@ where impl<'a, T: Copy + 'a, A: Allocator + 'a, const COOP_PREFERRED: bool> Extend<&'a T> for Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, { fn extend>(&mut self, iter: I) { self.spec_extend(iter.into_iter()) @@ -3126,7 +3148,7 @@ where impl PartialOrd for Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, { #[inline] fn partial_cmp(&self, other: &Self) -> Option { @@ -3136,7 +3158,7 @@ where #[stable(feature = "rust1", since = "1.0.0")] impl Eq for Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: + [(); core::alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]: { } @@ -3144,7 +3166,7 @@ impl Eq for Vec Ord for Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, { #[inline] fn cmp(&self, other: &Self) -> Ordering { @@ -3156,7 +3178,7 @@ where unsafe impl<#[may_dangle] T, A: Allocator, const COOP_PREFERRED: bool> Drop for Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, { fn drop(&mut self) { unsafe { @@ -3184,7 +3206,7 @@ impl const Default for Vec { impl fmt::Debug for Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fmt::Debug::fmt(&**self, f) @@ -3195,7 +3217,7 @@ where impl AsRef> for Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, { fn as_ref(&self) -> &Vec { self @@ -3206,7 +3228,7 @@ where impl AsMut> for Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, { fn as_mut(&mut self) -> &mut Vec { self @@ -3216,7 +3238,7 @@ where #[stable(feature = "rust1", since = "1.0.0")] impl AsRef<[T]> for Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, { fn as_ref(&self) -> &[T] { self @@ -3226,7 +3248,7 @@ where #[stable(feature = "vec_as_mut", since = "1.5.0")] impl AsMut<[T]> for Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, { fn as_mut(&mut self) -> &mut [T] { self @@ -3326,7 +3348,7 @@ where #[stable(feature = "vec_from_box", since = "1.18.0")] impl From> for Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, { /// Convert a boxed slice into a vector by transferring ownership of /// the existing heap allocation. @@ -3348,7 +3370,7 @@ where #[stable(feature = "box_from_vec", since = "1.20.0")] impl From> for Box<[T], A> where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, { /// Convert a vector into a boxed slice. /// @@ -3392,7 +3414,7 @@ impl From<&str> for Vec { impl TryFrom> for [T; N] where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, { type Error = Vec; diff --git a/library/alloc/src/vec/partial_eq.rs b/library/alloc/src/vec/partial_eq.rs index bcf52b7333218..7b364e8d4bacd 100644 --- a/library/alloc/src/vec/partial_eq.rs +++ b/library/alloc/src/vec/partial_eq.rs @@ -21,21 +21,21 @@ macro_rules! __impl_slice_eq1 { } } -__impl_slice_eq1! { [A1: Allocator, A2: Allocator, const COOP_PREFERRED1: bool, const COOP_PREFERRED2: bool] Vec, Vec, #[stable(feature = "rust1", since = "1.0.0")], [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED1)]:, [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED2)]: } -__impl_slice_eq1! { [A: Allocator, const COOP_PREFERRED: bool] Vec, &[U], #[stable(feature = "rust1", since = "1.0.0")], [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: } -__impl_slice_eq1! { [A: Allocator, const COOP_PREFERRED: bool] Vec, &mut [U], #[stable(feature = "rust1", since = "1.0.0")], [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: } -__impl_slice_eq1! { [A: Allocator, const COOP_PREFERRED: bool] &[T], Vec, #[stable(feature = "partialeq_vec_for_ref_slice", since = "1.46.0")], [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: } -__impl_slice_eq1! { [A: Allocator, const COOP_PREFERRED: bool] &mut [T], Vec, #[stable(feature = "partialeq_vec_for_ref_slice", since = "1.46.0")], [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: } -__impl_slice_eq1! { [A: Allocator, const COOP_PREFERRED: bool] Vec, [U], #[stable(feature = "partialeq_vec_for_slice", since = "1.48.0")], [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: } -__impl_slice_eq1! { [A: Allocator, const COOP_PREFERRED: bool] [T], Vec, #[stable(feature = "partialeq_vec_for_slice", since = "1.48.0")], [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: } +__impl_slice_eq1! { [A1: Allocator, A2: Allocator, const COOP_PREFERRED1: bool, const COOP_PREFERRED2: bool] Vec, Vec, #[stable(feature = "rust1", since = "1.0.0")], [(); core::alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED1)]:, [(); core::alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED2)]: } +__impl_slice_eq1! { [A: Allocator, const COOP_PREFERRED: bool] Vec, &[U], #[stable(feature = "rust1", since = "1.0.0")], [(); core::alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]: } +__impl_slice_eq1! { [A: Allocator, const COOP_PREFERRED: bool] Vec, &mut [U], #[stable(feature = "rust1", since = "1.0.0")], [(); core::alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]: } +__impl_slice_eq1! { [A: Allocator, const COOP_PREFERRED: bool] &[T], Vec, #[stable(feature = "partialeq_vec_for_ref_slice", since = "1.46.0")], [(); core::alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]: } +__impl_slice_eq1! { [A: Allocator, const COOP_PREFERRED: bool] &mut [T], Vec, #[stable(feature = "partialeq_vec_for_ref_slice", since = "1.46.0")], [(); core::alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]: } +__impl_slice_eq1! { [A: Allocator, const COOP_PREFERRED: bool] Vec, [U], #[stable(feature = "partialeq_vec_for_slice", since = "1.48.0")], [(); core::alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]: } +__impl_slice_eq1! { [A: Allocator, const COOP_PREFERRED: bool] [T], Vec, #[stable(feature = "partialeq_vec_for_slice", since = "1.48.0")], [(); core::alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]: } #[cfg(not(no_global_oom_handling))] -__impl_slice_eq1! { [A: Allocator, const COOP_PREFERRED: bool] Cow<'_, [T]>, Vec, #[stable(feature = "rust1", since = "1.0.0")], T: Clone, [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: } +__impl_slice_eq1! { [A: Allocator, const COOP_PREFERRED: bool] Cow<'_, [T]>, Vec, #[stable(feature = "rust1", since = "1.0.0")], T: Clone, [(); core::alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]: } #[cfg(not(no_global_oom_handling))] __impl_slice_eq1! { [] Cow<'_, [T]>, &[U], #[stable(feature = "rust1", since = "1.0.0")], T: Clone } #[cfg(not(no_global_oom_handling))] __impl_slice_eq1! { [] Cow<'_, [T]>, &mut [U], #[stable(feature = "rust1", since = "1.0.0")], T: Clone } -__impl_slice_eq1! { [A: Allocator, const COOP_PREFERRED: bool, const N: usize] Vec, [U; N], #[stable(feature = "rust1", since = "1.0.0")], [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: } -__impl_slice_eq1! { [A: Allocator, const COOP_PREFERRED: bool, const N: usize] Vec, &[U; N], #[stable(feature = "rust1", since = "1.0.0")], [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: } +__impl_slice_eq1! { [A: Allocator, const COOP_PREFERRED: bool, const N: usize] Vec, [U; N], #[stable(feature = "rust1", since = "1.0.0")], [(); core::alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]: } +__impl_slice_eq1! { [A: Allocator, const COOP_PREFERRED: bool, const N: usize] Vec, &[U; N], #[stable(feature = "rust1", since = "1.0.0")], [(); core::alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]: } // NOTE: some less important impls are omitted to reduce code bloat // FIXME(Centril): Reconsider this? diff --git a/library/alloc/src/vec/spec_extend.rs b/library/alloc/src/vec/spec_extend.rs index 73cf325889290..ea91491f62558 100644 --- a/library/alloc/src/vec/spec_extend.rs +++ b/library/alloc/src/vec/spec_extend.rs @@ -13,7 +13,7 @@ pub(super) trait SpecExtend { impl SpecExtend for Vec where I: Iterator, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, { default fn spec_extend(&mut self, iter: I) { self.extend_desugared(iter) @@ -23,7 +23,7 @@ where impl SpecExtend for Vec where I: TrustedLen, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, { default fn spec_extend(&mut self, iterator: I) { self.extend_trusted(iterator) @@ -33,7 +33,7 @@ where impl SpecExtend> for Vec where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, { fn spec_extend(&mut self, mut iterator: IntoIter) { unsafe { @@ -48,7 +48,7 @@ impl<'a, T: 'a, I, A: Allocator + 'a, const COOP_PREFERRED: bool> SpecExtend<&'a where I: Iterator, T: Clone, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, { default fn spec_extend(&mut self, iterator: I) { self.spec_extend(iterator.cloned()) @@ -59,7 +59,7 @@ impl<'a, T: 'a, A: Allocator + 'a, const COOP_PREFERRED: bool> SpecExtend<&'a T, for Vec where T: Copy, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, { fn spec_extend(&mut self, iterator: slice::Iter<'a, T>) { let slice = iterator.as_slice(); diff --git a/library/alloc/src/vec/spec_from_elem.rs b/library/alloc/src/vec/spec_from_elem.rs index 3766f6de061bb..4c29f6184c149 100644 --- a/library/alloc/src/vec/spec_from_elem.rs +++ b/library/alloc/src/vec/spec_from_elem.rs @@ -24,7 +24,7 @@ impl SpecFromElem for T { alloc: A, ) -> Vec where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, { let mut v = Vec::with_capacity_in(n, alloc); v.extend_with(n, ExtendElement(elem)); @@ -40,7 +40,7 @@ impl SpecFromElem for T { alloc: A, ) -> Vec where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, { if elem.is_zero() { return Vec { buf: RawVec::with_capacity_zeroed_in(n, alloc), len: n }; @@ -59,7 +59,7 @@ impl SpecFromElem for i8 { alloc: A, ) -> Vec where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, { if elem == 0 { return Vec { buf: RawVec::with_capacity_zeroed_in(n, alloc), len: n }; @@ -81,7 +81,7 @@ impl SpecFromElem for u8 { alloc: A, ) -> Vec where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, { if elem == 0 { return Vec { buf: RawVec::with_capacity_zeroed_in(n, alloc), len: n }; diff --git a/library/core/src/alloc/mod.rs b/library/core/src/alloc/mod.rs index d80f6dc17055a..eb7edf1600ef7 100644 --- a/library/core/src/alloc/mod.rs +++ b/library/core/src/alloc/mod.rs @@ -98,7 +98,7 @@ pub const fn co_alloc_metadata_num_slots() -> usize { #[unstable(feature = "global_co_alloc", issue = "none")] /// Param `coop_preferred` - if false, then this returns `0`, regardless of /// whether allocator `A` is cooperative. -pub const fn co_alloc_metadata_num_slots_with_preference( +pub const fn co_alloc_metadata_num_slots_with_preference_specific( coop_preferred: bool, ) -> usize { if A::IS_CO_ALLOCATOR && coop_preferred { 1 } else { 0 } diff --git a/library/std/src/io/cursor.rs b/library/std/src/io/cursor.rs index 63045ebcb8157..f8d2ca1d3e74c 100644 --- a/library/std/src/io/cursor.rs +++ b/library/std/src/io/cursor.rs @@ -404,7 +404,7 @@ fn reserve_and_pad( buf_len: usize, ) -> io::Result where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, { let pos: usize = (*pos_mut).try_into().map_err(|_| { io::const_io_error!( @@ -451,7 +451,7 @@ unsafe fn vec_write_unchecked( ) -> usize where A: Allocator, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, { debug_assert!(vec.capacity() >= pos + buf.len()); vec.as_mut_ptr().add(pos).copy_from(buf.as_ptr(), buf.len()); @@ -474,7 +474,7 @@ fn vec_write( ) -> io::Result where A: Allocator, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, { let buf_len = buf.len(); let mut pos = reserve_and_pad(pos_mut, vec, buf_len)?; @@ -510,7 +510,7 @@ fn vec_write_vectored( ) -> io::Result where A: Allocator, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, { // For safety reasons, we don't want this sum to overflow ever. // If this saturates, the reserve should panic to avoid any unsound writing. @@ -561,7 +561,7 @@ impl Write for Cursor<&mut [u8]> { impl Write for Cursor<&mut Vec> where A: Allocator, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, { fn write(&mut self, buf: &[u8]) -> io::Result { vec_write(&mut self.pos, self.inner, buf) @@ -586,7 +586,7 @@ where impl Write for Cursor> where A: Allocator, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, { fn write(&mut self, buf: &[u8]) -> io::Result { vec_write(&mut self.pos, &mut self.inner, buf) From e081c518dfd2293bf264eefadecd557ee96fc0ff Mon Sep 17 00:00:00 2001 From: Peter Kehl Date: Sun, 22 Jan 2023 07:41:35 -0800 Subject: [PATCH 028/118] CoAlloc: VecDeque: Renamed ::core::alloc::co_alloc_metadata_num_slots_with_preference to ::core::alloc::co_alloc_metadata_num_slots_with_preference_specific. ICE --- .../alloc/src/collections/vec_deque/drain.rs | 24 ++++---- .../src/collections/vec_deque/into_iter.rs | 2 +- .../alloc/src/collections/vec_deque/macros.rs | 2 +- .../alloc/src/collections/vec_deque/mod.rs | 56 ++++++++++--------- .../src/collections/vec_deque/spec_extend.rs | 12 ++-- .../collections/vec_deque/spec_from_iter.rs | 6 +- 6 files changed, 52 insertions(+), 50 deletions(-) diff --git a/library/alloc/src/collections/vec_deque/drain.rs b/library/alloc/src/collections/vec_deque/drain.rs index 0bcf82e3ceff5..2004060c4bb96 100644 --- a/library/alloc/src/collections/vec_deque/drain.rs +++ b/library/alloc/src/collections/vec_deque/drain.rs @@ -21,7 +21,7 @@ pub struct Drain< #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global, const COOP_PREFERRED: bool = { alloc::SHORT_TERM_VEC_PREFERS_COOP }, > where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, { // We can't just use a &mut VecDeque, as that would make Drain invariant over T // and we want it to be covariant instead @@ -39,7 +39,7 @@ pub struct Drain< impl<'a, T, A: Allocator, const COOP_PREFERRED: bool> Drain<'a, T, A, COOP_PREFERRED> where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, { pub(super) unsafe fn new( deque: &'a mut VecDeque, @@ -97,7 +97,7 @@ where impl fmt::Debug for Drain<'_, T, A, COOP_PREFERRED> where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_tuple("Drain") @@ -113,33 +113,33 @@ where unsafe impl Sync for Drain<'_, T, A, COOP_PREFERRED> where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, { } #[stable(feature = "drain", since = "1.6.0")] unsafe impl Send for Drain<'_, T, A, COOP_PREFERRED> where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, { } #[stable(feature = "drain", since = "1.6.0")] impl Drop for Drain<'_, T, A, COOP_PREFERRED> where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, { fn drop(&mut self) { struct DropGuard<'r, 'a, T, A: Allocator, const COOP_PREFERRED: bool>( &'r mut Drain<'a, T, A, COOP_PREFERRED>, ) where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:; + [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:; impl<'r, 'a, T, A: Allocator, const COOP_PREFERRED: bool> Drop for DropGuard<'r, 'a, T, A, COOP_PREFERRED> where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, { fn drop(&mut self) { if self.0.remaining != 0 { @@ -223,7 +223,7 @@ where #[stable(feature = "drain", since = "1.6.0")] impl Iterator for Drain<'_, T, A, COOP_PREFERRED> where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, { type Item = T; @@ -249,7 +249,7 @@ where impl DoubleEndedIterator for Drain<'_, T, A, COOP_PREFERRED> where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, { #[inline] fn next_back(&mut self) -> Option { @@ -266,12 +266,12 @@ where impl ExactSizeIterator for Drain<'_, T, A, COOP_PREFERRED> where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, { } #[stable(feature = "fused", since = "1.26.0")] impl FusedIterator for Drain<'_, T, A, COOP_PREFERRED> where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: + [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]: { } diff --git a/library/alloc/src/collections/vec_deque/into_iter.rs b/library/alloc/src/collections/vec_deque/into_iter.rs index 751be6ec8846d..765b55e2b51b1 100644 --- a/library/alloc/src/collections/vec_deque/into_iter.rs +++ b/library/alloc/src/collections/vec_deque/into_iter.rs @@ -19,7 +19,7 @@ pub struct IntoIter< #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global, const COOP_PREFERRED: bool = true, > where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, { inner: VecDeque, } diff --git a/library/alloc/src/collections/vec_deque/macros.rs b/library/alloc/src/collections/vec_deque/macros.rs index 68ee43152b5b5..77885e6811a3b 100644 --- a/library/alloc/src/collections/vec_deque/macros.rs +++ b/library/alloc/src/collections/vec_deque/macros.rs @@ -4,7 +4,7 @@ macro_rules! __impl_slice_eq1 { impl PartialEq<$rhs> for $lhs where T: PartialEq, - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, $($constraints)* { fn eq(&self, other: &$rhs) -> bool { diff --git a/library/alloc/src/collections/vec_deque/mod.rs b/library/alloc/src/collections/vec_deque/mod.rs index fca22a10e5987..b7b9d58f5dfe9 100644 --- a/library/alloc/src/collections/vec_deque/mod.rs +++ b/library/alloc/src/collections/vec_deque/mod.rs @@ -98,7 +98,7 @@ pub struct VecDeque< #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global, const COOP_PREFERRED: bool = DEFAULT_COOP_PREFERRED, > where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, { // `self[0]`, if it exists, is `buf[head]`. // `head < buf.capacity()`, unless `buf.capacity() == 0` when `head == 0`. @@ -114,7 +114,7 @@ pub struct VecDeque< impl Clone for VecDeque where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, { fn clone(&self) -> Self { let mut deq = Self::with_capacity_in(self.len(), self.allocator().clone()); @@ -132,7 +132,7 @@ where unsafe impl<#[may_dangle] T, A: Allocator, const COOP_PREFERRED: bool> Drop for VecDeque where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, { fn drop(&mut self) { /// Runs the destructor for all items in the slice when it gets dropped (normally or @@ -168,7 +168,7 @@ impl Default for VecDeque VecDeque where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, { /// Marginally more convenient #[inline] @@ -460,7 +460,7 @@ where ) -> usize { struct Guard<'a, T, A: Allocator, const COOP_PREFERRED: bool> where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, { deque: &'a mut VecDeque, written: usize, @@ -468,7 +468,7 @@ where impl<'a, T, A: Allocator, const COOP_PREFERRED: bool> Drop for Guard<'a, T, A, COOP_PREFERRED> where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, { fn drop(&mut self) { self.deque.len += self.written; @@ -549,7 +549,7 @@ where impl VecDeque where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, { /// Creates an empty deque. /// @@ -588,7 +588,7 @@ where impl VecDeque where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, { /// Creates an empty deque. /// @@ -2626,7 +2626,7 @@ where impl VecDeque where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, { /// Modifies the deque in-place so that `len()` is equal to new_len, /// either by removing excess elements from the back or by appending clones of `value` @@ -2675,7 +2675,7 @@ fn wrap_index(logical_index: usize, capacity: usize) -> usize { impl PartialEq for VecDeque where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, { fn eq(&self, other: &Self) -> bool { if self.len != other.len() { @@ -2716,7 +2716,7 @@ where #[stable(feature = "rust1", since = "1.0.0")] impl Eq for VecDeque where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: + [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]: { } @@ -2731,7 +2731,7 @@ __impl_slice_eq1! { [const N: usize] VecDeque, &mut [U; N] impl PartialOrd for VecDeque where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, { fn partial_cmp(&self, other: &Self) -> Option { self.iter().partial_cmp(other.iter()) @@ -2741,7 +2741,7 @@ where #[stable(feature = "rust1", since = "1.0.0")] impl Ord for VecDeque where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, { #[inline] fn cmp(&self, other: &Self) -> Ordering { @@ -2752,7 +2752,7 @@ where #[stable(feature = "rust1", since = "1.0.0")] impl Hash for VecDeque where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, { fn hash(&self, state: &mut H) { state.write_length_prefix(self.len); @@ -2769,7 +2769,7 @@ where #[stable(feature = "rust1", since = "1.0.0")] impl Index for VecDeque where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, { type Output = T; @@ -2782,7 +2782,7 @@ where #[stable(feature = "rust1", since = "1.0.0")] impl IndexMut for VecDeque where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, { #[inline] fn index_mut(&mut self, index: usize) -> &mut T { @@ -2793,7 +2793,7 @@ where #[stable(feature = "rust1", since = "1.0.0")] impl FromIterator for VecDeque where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, { fn from_iter>(iter: I) -> VecDeque { SpecFromIter::spec_from_iter(iter.into_iter()) @@ -2803,7 +2803,7 @@ where #[stable(feature = "rust1", since = "1.0.0")] impl IntoIterator for VecDeque where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, { type Item = T; type IntoIter = IntoIter; @@ -2819,7 +2819,7 @@ where impl<'a, T, A: Allocator, const COOP_PREFERRED: bool> IntoIterator for &'a VecDeque where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, { type Item = &'a T; type IntoIter = Iter<'a, T>; @@ -2833,7 +2833,7 @@ where impl<'a, T, A: Allocator, const COOP_PREFERRED: bool> IntoIterator for &'a mut VecDeque where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, { type Item = &'a mut T; type IntoIter = IterMut<'a, T>; @@ -2846,7 +2846,7 @@ where #[stable(feature = "rust1", since = "1.0.0")] impl Extend for VecDeque where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, { fn extend>(&mut self, iter: I) { >::spec_extend(self, iter.into_iter()); @@ -2867,7 +2867,7 @@ where impl<'a, T: 'a + Copy, A: Allocator, const COOP_PREFERRED: bool> Extend<&'a T> for VecDeque where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, { fn extend>(&mut self, iter: I) { self.spec_extend(iter.into_iter()); @@ -2888,7 +2888,7 @@ where impl fmt::Debug for VecDeque where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_list().entries(self.iter()).finish() @@ -2899,7 +2899,7 @@ where impl From> for VecDeque where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, { /// Turn a [`Vec`] into a [`VecDeque`]. /// @@ -2912,7 +2912,9 @@ where #[inline] fn from(other: Vec) -> Self where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(OTHER_COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::( + OTHER_COOP_PREFERRED, + )]:, { let (ptr, len, cap, alloc) = other.into_raw_parts_with_alloc(); Self { head: 0, len, buf: unsafe { RawVec::from_raw_parts_in(ptr, cap, alloc) } } @@ -2923,7 +2925,7 @@ where impl From> for Vec where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, { /// Turn a [`VecDeque`] into a [`Vec`]. /// @@ -2979,7 +2981,7 @@ where impl From<[T; N]> for VecDeque where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, { /// Converts a `[T; N]` into a `VecDeque`. /// diff --git a/library/alloc/src/collections/vec_deque/spec_extend.rs b/library/alloc/src/collections/vec_deque/spec_extend.rs index b1a9d23fd4a99..973de88ffb172 100644 --- a/library/alloc/src/collections/vec_deque/spec_extend.rs +++ b/library/alloc/src/collections/vec_deque/spec_extend.rs @@ -17,7 +17,7 @@ impl SpecExtend for VecDeque where I: Iterator, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, { default fn spec_extend(&mut self, mut iter: I) { // This function should be the moral equivalent of: @@ -31,7 +31,7 @@ where deque: &mut VecDeque, element: T, ) where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, { // SAFETY: Because of the precondition, it's guaranteed that there is space // in the logical array after the last element. @@ -63,7 +63,7 @@ impl SpecExtend for VecDeque where I: TrustedLen, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, { default fn spec_extend(&mut self, iter: I) { // This is the case for a TrustedLen iterator. @@ -99,7 +99,7 @@ where impl SpecExtend> for VecDeque where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, { fn spec_extend(&mut self, mut iterator: vec::IntoIter) { let slice = iterator.as_slice(); @@ -118,7 +118,7 @@ impl<'a, T: 'a, I, A: Allocator, const COOP_PREFERRED: bool> SpecExtend<&'a T, I where I: Iterator, T: Copy, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, { default fn spec_extend(&mut self, iterator: I) { self.spec_extend(iterator.copied()) @@ -129,7 +129,7 @@ impl<'a, T: 'a, A: Allocator, const COOP_PREFERRED: bool> SpecExtend<&'a T, slic for VecDeque where T: Copy, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, { fn spec_extend(&mut self, iterator: slice::Iter<'a, T>) { let slice = iterator.as_slice(); diff --git a/library/alloc/src/collections/vec_deque/spec_from_iter.rs b/library/alloc/src/collections/vec_deque/spec_from_iter.rs index 85dd756337350..086a1fa74566c 100644 --- a/library/alloc/src/collections/vec_deque/spec_from_iter.rs +++ b/library/alloc/src/collections/vec_deque/spec_from_iter.rs @@ -11,7 +11,7 @@ impl SpecFromIter for VecDeque where I: Iterator, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, { default fn spec_from_iter(iterator: I) -> Self { // Since converting is O(1) now, just re-use the `Vec` logic for @@ -25,7 +25,7 @@ where impl SpecFromIter> for VecDeque where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, { #[inline] fn spec_from_iter(iterator: crate::vec::IntoIter) -> Self { @@ -36,7 +36,7 @@ where impl SpecFromIter> for VecDeque where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, { #[inline] fn spec_from_iter(iterator: IntoIter) -> Self { From c84a040a71eae06703b2cff6abeca024a9459659 Mon Sep 17 00:00:00 2001 From: Peter Kehl Date: Sun, 22 Jan 2023 07:42:04 -0800 Subject: [PATCH 029/118] CoAlloc: Minor VecDeque. ICE --- library/alloc/src/collections/vec_deque/mod.rs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/library/alloc/src/collections/vec_deque/mod.rs b/library/alloc/src/collections/vec_deque/mod.rs index b7b9d58f5dfe9..7c5cfd1e5fe2e 100644 --- a/library/alloc/src/collections/vec_deque/mod.rs +++ b/library/alloc/src/collections/vec_deque/mod.rs @@ -158,10 +158,13 @@ where } #[stable(feature = "rust1", since = "1.0.0")] -impl Default for VecDeque { +impl Default for VecDeque +where + [(); crate::co_alloc_metadata_num_slots_with_preference_global(COOP_PREFERRED)]:, +{ /// Creates an empty deque. #[inline] - fn default() -> VecDeque { + fn default() -> VecDeque { VecDeque::new() } } @@ -2978,10 +2981,10 @@ where } #[stable(feature = "std_collections_from_array", since = "1.56.0")] -impl From<[T; N]> - for VecDeque +impl From<[T; N]> + for VecDeque where - [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, + [(); crate::co_alloc_metadata_num_slots_with_preference_global(COOP_PREFERRED)]:, { /// Converts a `[T; N]` into a `VecDeque`. /// From 81d49a740b207d857af7021e5137eea1a32a81b8 Mon Sep 17 00:00:00 2001 From: Peter Kehl Date: Sun, 22 Jan 2023 07:42:40 -0800 Subject: [PATCH 030/118] CoAlloc: Vec: Tidy. ICE --- library/alloc/src/vec/mod.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/library/alloc/src/vec/mod.rs b/library/alloc/src/vec/mod.rs index 8c1025f6b2261..0c89bb54e4375 100644 --- a/library/alloc/src/vec/mod.rs +++ b/library/alloc/src/vec/mod.rs @@ -439,7 +439,10 @@ pub type WeVec = Vec 127 }>; // Inherent methods //////////////////////////////////////////////////////////////////////////////// -impl Vec { +impl Vec +where + [(); crate::co_alloc_metadata_num_slots_with_preference_global(COOP_PREFERRED)]:, +{ /// Constructs a new, empty `Vec`. /// /// The vector will not allocate until elements are pushed onto it. @@ -3193,11 +3196,14 @@ where #[stable(feature = "rust1", since = "1.0.0")] #[rustc_const_unstable(feature = "const_default_impls", issue = "87864")] -impl const Default for Vec { +impl const Default for Vec +where + [(); crate::co_alloc_metadata_num_slots_with_preference_global(COOP_PREFERRED)]:, +{ /// Creates an empty `Vec`. /// /// The vector will not allocate until elements are pushed onto it. - fn default() -> Vec { + fn default() -> Vec { Vec::new() } } From 7ed4a609dc265b95469c35bb26095fb8f7fef570 Mon Sep 17 00:00:00 2001 From: Peter Kehl Date: Sun, 22 Jan 2023 07:45:22 -0800 Subject: [PATCH 031/118] CoAlloc: Vec: Working around ICE rust-lang/rust issue #106473 ICE. WIP --- library/alloc/src/vec/in_place_collect.rs | 2 +- library/alloc/src/vec/mod.rs | 12 ++++++------ library/alloc/src/vec/spec_from_iter.rs | 4 ++-- library/alloc/src/vec/spec_from_iter_nested.rs | 4 ++-- library/proc_macro/src/bridge/mod.rs | 4 ++-- library/proc_macro/src/bridge/rpc.rs | 4 ++-- library/proc_macro/src/diagnostic.rs | 2 +- 7 files changed, 16 insertions(+), 16 deletions(-) diff --git a/library/alloc/src/vec/in_place_collect.rs b/library/alloc/src/vec/in_place_collect.rs index 87d61deb1eb2f..cdaf3c43e824d 100644 --- a/library/alloc/src/vec/in_place_collect.rs +++ b/library/alloc/src/vec/in_place_collect.rs @@ -150,7 +150,7 @@ pub(super) trait InPlaceIterableMarker {} impl InPlaceIterableMarker for T where T: InPlaceIterable {} -impl SpecFromIter for Vec +impl SpecFromIter for Vec where I: Iterator + SourceIter + InPlaceIterableMarker, { diff --git a/library/alloc/src/vec/mod.rs b/library/alloc/src/vec/mod.rs index 0c89bb54e4375..3014da2f01bfd 100644 --- a/library/alloc/src/vec/mod.rs +++ b/library/alloc/src/vec/mod.rs @@ -2845,7 +2845,7 @@ where #[cfg(not(no_global_oom_handling))] #[stable(feature = "rust1", since = "1.0.0")] -impl FromIterator for Vec { +impl FromIterator for Vec { #[inline] fn from_iter>(iter: I) -> Vec { >::from_iter(iter.into_iter()) @@ -3263,7 +3263,7 @@ where #[cfg(not(no_global_oom_handling))] #[stable(feature = "rust1", since = "1.0.0")] -impl From<&[T]> for Vec { +impl From<&[T]> for Vec { /// Allocate a `Vec` and fill it by cloning `s`'s items. /// /// # Examples @@ -3283,7 +3283,7 @@ impl From<&[T]> for Vec { #[cfg(not(no_global_oom_handling))] #[stable(feature = "vec_from_mut", since = "1.19.0")] -impl From<&mut [T]> for Vec { +impl From<&mut [T]> for Vec { /// Allocate a `Vec` and fill it by cloning `s`'s items. /// /// # Examples @@ -3303,7 +3303,7 @@ impl From<&mut [T]> for Vec { #[cfg(not(no_global_oom_handling))] #[stable(feature = "vec_from_array", since = "1.44.0")] -impl From<[T; N]> for Vec { +impl From<[T; N]> for Vec { /// Allocate a `Vec` and move `s`'s items into it. /// /// # Examples @@ -3326,7 +3326,7 @@ impl From<[T; N]> for Vec { } #[stable(feature = "vec_from_cow_slice", since = "1.14.0")] -impl<'a, T> From> for Vec +impl<'a, T> From> for Vec where [T]: ToOwned>, { @@ -3403,7 +3403,7 @@ where #[cfg(not(no_global_oom_handling))] #[stable(feature = "rust1", since = "1.0.0")] -impl From<&str> for Vec { +impl From<&str> for Vec { /// Allocate a `Vec` and fill it with a UTF-8 string. /// /// # Examples diff --git a/library/alloc/src/vec/spec_from_iter.rs b/library/alloc/src/vec/spec_from_iter.rs index efa6868473e49..7db120f1ff6c2 100644 --- a/library/alloc/src/vec/spec_from_iter.rs +++ b/library/alloc/src/vec/spec_from_iter.rs @@ -25,7 +25,7 @@ pub(super) trait SpecFromIter { fn from_iter(iter: I) -> Self; } -impl SpecFromIter for Vec +impl SpecFromIter for Vec where I: Iterator, { @@ -34,7 +34,7 @@ where } } -impl SpecFromIter> for Vec { +impl SpecFromIter> for Vec { fn from_iter(iterator: IntoIter) -> Self { // A common case is passing a vector into a function which immediately // re-collects into a vector. We can short circuit this if the IntoIter diff --git a/library/alloc/src/vec/spec_from_iter_nested.rs b/library/alloc/src/vec/spec_from_iter_nested.rs index f915ebb86e5a5..9453f2dcd9828 100644 --- a/library/alloc/src/vec/spec_from_iter_nested.rs +++ b/library/alloc/src/vec/spec_from_iter_nested.rs @@ -13,7 +13,7 @@ pub(super) trait SpecFromIterNested { fn from_iter(iter: I) -> Self; } -impl SpecFromIterNested for Vec +impl SpecFromIterNested for Vec where I: Iterator, { @@ -45,7 +45,7 @@ where } } -impl SpecFromIterNested for Vec +impl SpecFromIterNested for Vec where I: TrustedLen, { diff --git a/library/proc_macro/src/bridge/mod.rs b/library/proc_macro/src/bridge/mod.rs index 4c1e196b5ad16..aae141dc2a118 100644 --- a/library/proc_macro/src/bridge/mod.rs +++ b/library/proc_macro/src/bridge/mod.rs @@ -252,14 +252,14 @@ impl<'a, T, M> Unmark for &'a mut Marked { } } -impl Mark for Vec { +impl Mark for Vec { type Unmarked = Vec; fn mark(unmarked: Self::Unmarked) -> Self { // Should be a no-op due to std's in-place collect optimizations. unmarked.into_iter().map(T::mark).collect() } } -impl Unmark for Vec { +impl Unmark for Vec { type Unmarked = Vec; fn unmark(self) -> Self::Unmarked { // Should be a no-op due to std's in-place collect optimizations. diff --git a/library/proc_macro/src/bridge/rpc.rs b/library/proc_macro/src/bridge/rpc.rs index 5b1bfb30983b2..3d57bfd21ac7b 100644 --- a/library/proc_macro/src/bridge/rpc.rs +++ b/library/proc_macro/src/bridge/rpc.rs @@ -224,7 +224,7 @@ impl DecodeMut<'_, '_, S> for String { } } -impl> Encode for Vec { +impl> Encode for Vec { fn encode(self, w: &mut Writer, s: &mut S) { self.len().encode(w, s); for x in self { @@ -233,7 +233,7 @@ impl> Encode for Vec { } } -impl<'a, S, T: for<'s> DecodeMut<'a, 's, S>> DecodeMut<'a, '_, S> for Vec { +impl<'a, S, T: for<'s> DecodeMut<'a, 's, S>> DecodeMut<'a, '_, S> for Vec { fn decode(r: &mut Reader<'a>, s: &mut S) -> Self { let len = usize::decode(r, s); let mut vec = Vec::with_capacity(len); diff --git a/library/proc_macro/src/diagnostic.rs b/library/proc_macro/src/diagnostic.rs index 5a209f7c7aa18..41a11b1003b84 100644 --- a/library/proc_macro/src/diagnostic.rs +++ b/library/proc_macro/src/diagnostic.rs @@ -30,7 +30,7 @@ impl MultiSpan for Span { } #[unstable(feature = "proc_macro_diagnostic", issue = "54140")] -impl MultiSpan for Vec { +impl MultiSpan for Vec { fn into_spans(self) -> Vec { self } From 3f84cef31ebfb3df8dbe87d075b94d3ea55e73c5 Mon Sep 17 00:00:00 2001 From: Peter Kehl Date: Sun, 22 Jan 2023 07:46:38 -0800 Subject: [PATCH 032/118] CoAlloc: Vec (NOT String): Working around ICE rust-lang/rust issue #106473 ICE. WIP --- library/alloc/src/ffi/c_str.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/alloc/src/ffi/c_str.rs b/library/alloc/src/ffi/c_str.rs index f99395c72aa03..fef8404055373 100644 --- a/library/alloc/src/ffi/c_str.rs +++ b/library/alloc/src/ffi/c_str.rs @@ -723,7 +723,7 @@ impl fmt::Debug for CString { } #[stable(feature = "cstring_into", since = "1.7.0")] -impl From for Vec { +impl From for Vec { /// Converts a [`CString`] into a [Vec]<[u8]>. /// /// The conversion consumes the [`CString`], and removes the terminating NUL byte. From 63e060260d93b49592b5ff1b0cac59ca261d237c Mon Sep 17 00:00:00 2001 From: Peter Kehl Date: Sun, 22 Jan 2023 07:46:57 -0800 Subject: [PATCH 033/118] CoAlloc: BinaryHeap: Working around ICE rust-lang/rust issue #106473 ICE. WIP --- library/alloc/src/collections/binary_heap/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/alloc/src/collections/binary_heap/mod.rs b/library/alloc/src/collections/binary_heap/mod.rs index f1b0cc4a72424..0a4a52e25c48f 100644 --- a/library/alloc/src/collections/binary_heap/mod.rs +++ b/library/alloc/src/collections/binary_heap/mod.rs @@ -1652,7 +1652,7 @@ impl From<[T; N]> for BinaryHeap { } #[stable(feature = "binary_heap_extras_15", since = "1.5.0")] -impl From> for Vec { +impl From> for Vec { /// Converts a `BinaryHeap` into a `Vec`. /// /// This conversion requires no data movement or allocation, and has From 40b204f4e691004e6f7bd668bec389c7bb2de29f Mon Sep 17 00:00:00 2001 From: Peter Kehl Date: Sun, 22 Jan 2023 07:50:52 -0800 Subject: [PATCH 034/118] CoAlloc: Vec + related + FFI (NOT String-related): Macros instead of const for global COOP defaults (working around ICE). --- library/alloc/src/boxed.rs | 7 ++-- library/alloc/src/ffi/c_str.rs | 5 ++- library/alloc/src/lib.rs | 1 + library/alloc/src/raw_vec.rs | 5 +-- library/alloc/src/vec/drain.rs | 3 +- library/alloc/src/vec/in_place_collect.rs | 6 +++- library/alloc/src/vec/into_iter.rs | 3 +- library/alloc/src/vec/mod.rs | 36 ++++++++++++------- library/alloc/src/vec/spec_from_iter.rs | 8 +++-- .../alloc/src/vec/spec_from_iter_nested.rs | 8 +++-- library/core/src/alloc/mod.rs | 6 +++- 11 files changed, 62 insertions(+), 26 deletions(-) diff --git a/library/alloc/src/boxed.rs b/library/alloc/src/boxed.rs index 615744a2d60a3..86e9c96c5f42f 100644 --- a/library/alloc/src/boxed.rs +++ b/library/alloc/src/boxed.rs @@ -146,7 +146,6 @@ #![stable(feature = "rust1", since = "1.0.0")] -use core::alloc; use core::any::Any; use core::async_iter::AsyncIterator; use core::borrow; @@ -776,9 +775,10 @@ where #[unstable(feature = "allocator_api", issue = "32838")] // #[unstable(feature = "new_uninit", issue = "63291")] #[must_use] + #[allow(unused_braces)] pub fn new_uninit_slice_in(len: usize, alloc: A) -> Box<[mem::MaybeUninit], A> { unsafe { - RawVec::::with_capacity_in(len, alloc) + RawVec::::with_capacity_in(len, alloc) .into_box(len) } } @@ -807,9 +807,10 @@ where #[unstable(feature = "allocator_api", issue = "32838")] // #[unstable(feature = "new_uninit", issue = "63291")] #[must_use] + #[allow(unused_braces)] pub fn new_zeroed_slice_in(len: usize, alloc: A) -> Box<[mem::MaybeUninit], A> { unsafe { - RawVec::::with_capacity_zeroed_in( + RawVec::::with_capacity_zeroed_in( len, alloc, ) .into_box(len) diff --git a/library/alloc/src/ffi/c_str.rs b/library/alloc/src/ffi/c_str.rs index fef8404055373..bdf94524decc0 100644 --- a/library/alloc/src/ffi/c_str.rs +++ b/library/alloc/src/ffi/c_str.rs @@ -17,6 +17,8 @@ use core::ptr; use core::slice; use core::slice::memchr; use core::str::{self, Utf8Error}; +use crate::Global; +use crate::DEFAULT_COOP_PREFERRED; #[cfg(target_has_atomic = "ptr")] use crate::sync::Arc; @@ -723,7 +725,8 @@ impl fmt::Debug for CString { } #[stable(feature = "cstring_into", since = "1.7.0")] -impl From for Vec { +#[allow(unused_braces)] +impl From for Vec { /// Converts a [`CString`] into a [Vec]<[u8]>. /// /// The conversion consumes the [`CString`], and removes the terminating NUL byte. diff --git a/library/alloc/src/lib.rs b/library/alloc/src/lib.rs index 47eb67a5b10af..251d4b3fec200 100644 --- a/library/alloc/src/lib.rs +++ b/library/alloc/src/lib.rs @@ -185,6 +185,7 @@ #![feature(global_co_alloc_short_term_pref)] #![feature(hashmap_internals)] #![feature(lang_items)] +#![feature(global_co_alloc_def)] // When we used min_specialization instead of specialization, library/alloc/src/vec/mod.rs was failing with: // - cannot specialize on predicate `the constant `core::alloc::co_alloc_metadata_num_slots::()` can be evaluated` // - cannot specialize on predicate `[(); _] well-formed` diff --git a/library/alloc/src/raw_vec.rs b/library/alloc/src/raw_vec.rs index a6a4b4f4c9b56..408f3a023fda8 100644 --- a/library/alloc/src/raw_vec.rs +++ b/library/alloc/src/raw_vec.rs @@ -14,7 +14,7 @@ use crate::alloc::{Allocator, Global, Layout}; use crate::boxed::Box; use crate::collections::TryReserveError; use crate::collections::TryReserveErrorKind::*; -use crate::vec::DEFAULT_COOP_PREFERRED; +use crate::DEFAULT_COOP_PREFERRED; #[cfg(test)] mod tests; @@ -50,10 +50,11 @@ enum AllocInit { /// `usize::MAX`. This means that you need to be careful when round-tripping this type with a /// `Box<[T]>`, since `capacity()` won't yield the length. #[allow(missing_debug_implementations)] +#[allow(unused_braces)] pub(crate) struct RawVec< T, A: Allocator = Global, - const COOP_PREFERRED: bool = DEFAULT_COOP_PREFERRED, + const COOP_PREFERRED: bool = {DEFAULT_COOP_PREFERRED!()}, > where [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, { diff --git a/library/alloc/src/vec/drain.rs b/library/alloc/src/vec/drain.rs index 2159edc7b1a23..72153029287bd 100644 --- a/library/alloc/src/vec/drain.rs +++ b/library/alloc/src/vec/drain.rs @@ -19,11 +19,12 @@ use super::Vec; /// let iter: std::vec::Drain<_> = v.drain(..); /// ``` #[stable(feature = "drain", since = "1.6.0")] +#[allow(unused_braces)] pub struct Drain< 'a, T: 'a, #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator + 'a = Global, - const COOP_PREFERRED: bool = { alloc::SHORT_TERM_VEC_PREFERS_COOP }, + const COOP_PREFERRED: bool = { SHORT_TERM_VEC_PREFERS_COOP!() }, > where [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, { diff --git a/library/alloc/src/vec/in_place_collect.rs b/library/alloc/src/vec/in_place_collect.rs index cdaf3c43e824d..6f3c44a8aa8b6 100644 --- a/library/alloc/src/vec/in_place_collect.rs +++ b/library/alloc/src/vec/in_place_collect.rs @@ -141,6 +141,9 @@ use core::iter::{InPlaceIterable, SourceIter, TrustedRandomAccessNoCoerce}; use core::mem::{self, ManuallyDrop, SizedTypeProperties}; use core::ptr::{self}; +use crate::Global; +use crate::DEFAULT_COOP_PREFERRED; + use super::{InPlaceDrop, InPlaceDstBufDrop, SpecFromIter, SpecFromIterNested, Vec}; /// Specialization marker for collecting an iterator pipeline into a Vec while reusing the @@ -150,7 +153,8 @@ pub(super) trait InPlaceIterableMarker {} impl InPlaceIterableMarker for T where T: InPlaceIterable {} -impl SpecFromIter for Vec +#[allow(unused_braces)] +impl SpecFromIter for Vec where I: Iterator + SourceIter + InPlaceIterableMarker, { diff --git a/library/alloc/src/vec/into_iter.rs b/library/alloc/src/vec/into_iter.rs index 98b7a7cda6731..7ca48fba02f06 100644 --- a/library/alloc/src/vec/into_iter.rs +++ b/library/alloc/src/vec/into_iter.rs @@ -28,10 +28,11 @@ use core::{alloc, array, fmt}; /// ``` #[stable(feature = "rust1", since = "1.0.0")] #[rustc_insignificant_dtor] +#[allow(unused_braces)] pub struct IntoIter< T, #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global, - const COOP_PREFERRED: bool = { alloc::SHORT_TERM_VEC_PREFERS_COOP }, + const COOP_PREFERRED: bool = { SHORT_TERM_VEC_PREFERS_COOP!() }, > where [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, { diff --git a/library/alloc/src/vec/mod.rs b/library/alloc/src/vec/mod.rs index 3014da2f01bfd..0ae11ad01a1c9 100644 --- a/library/alloc/src/vec/mod.rs +++ b/library/alloc/src/vec/mod.rs @@ -148,6 +148,14 @@ use self::spec_extend::SpecExtend; #[cfg(not(no_global_oom_handling))] mod spec_extend; +/// Default `Vec`, `DefVec`, `DecVeque`, `DefDecVeq` "cooperation" (`COOP_PREFERRED`) generic parameter. +#[unstable(feature = "global_co_alloc_def", issue = "none")] +// pub const DEFAULT_COOP_PREFERRED: bool = true; +#[macro_export] +macro_rules! DEFAULT_COOP_PREFERRED { + () => {true} +} + /// A contiguous growable array type, written as `Vec`, short for 'vector'. /// /// # Examples @@ -397,11 +405,12 @@ mod spec_extend; #[stable(feature = "rust1", since = "1.0.0")] #[cfg_attr(not(test), rustc_diagnostic_item = "Vec")] #[rustc_insignificant_dtor] +#[allow(unused_braces)] pub struct Vec< T, #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global, //@FIXME: #[unstable(feature ="global_co_alloc_vec", issue="none")] - const COOP_PREFERRED: bool = DEFAULT_COOP_PREFERRED, + const COOP_PREFERRED: bool = {DEFAULT_COOP_PREFERRED!()}, > where [(); core::alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, { @@ -409,10 +418,6 @@ pub struct Vec< len: usize, } -/// Default `Vec`, `DefVec`, `DecVeque`, `DefDecVeq` "cooperation" (`COOP_PREFERRED`) generic parameter. -#[unstable(feature = "global_co_alloc_def", issue = "none")] -pub const DEFAULT_COOP_PREFERRED: bool = true; - #[unstable(feature = "global_co_alloc_covec", issue = "none")] pub type CoVec = Vec; @@ -426,8 +431,9 @@ pub type PlVec = - Vec; + Vec; /// "Weighted cooperative" Vec. Weight means how much it wants to cooperate (with the allocator). 0 /// = always pack; u8::MAX = always cooperate (if `Global` supports it). @@ -2845,7 +2851,8 @@ where #[cfg(not(no_global_oom_handling))] #[stable(feature = "rust1", since = "1.0.0")] -impl FromIterator for Vec { +#[allow(unused_braces)] +impl FromIterator for Vec { #[inline] fn from_iter>(iter: I) -> Vec { >::from_iter(iter.into_iter()) @@ -3263,7 +3270,8 @@ where #[cfg(not(no_global_oom_handling))] #[stable(feature = "rust1", since = "1.0.0")] -impl From<&[T]> for Vec { +#[allow(unused_braces)] +impl From<&[T]> for Vec { /// Allocate a `Vec` and fill it by cloning `s`'s items. /// /// # Examples @@ -3283,7 +3291,8 @@ impl From<&[T]> for Vec { #[cfg(not(no_global_oom_handling))] #[stable(feature = "vec_from_mut", since = "1.19.0")] -impl From<&mut [T]> for Vec { +#[allow(unused_braces)] +impl From<&mut [T]> for Vec { /// Allocate a `Vec` and fill it by cloning `s`'s items. /// /// # Examples @@ -3303,7 +3312,8 @@ impl From<&mut [T]> for Vec { #[cfg(not(no_global_oom_handling))] #[stable(feature = "vec_from_array", since = "1.44.0")] -impl From<[T; N]> for Vec { +#[allow(unused_braces)] +impl From<[T; N]> for Vec { /// Allocate a `Vec` and move `s`'s items into it. /// /// # Examples @@ -3326,7 +3336,8 @@ impl From<[T; N]> for Vec } #[stable(feature = "vec_from_cow_slice", since = "1.14.0")] -impl<'a, T> From> for Vec +#[allow(unused_braces)] +impl<'a, T> From> for Vec where [T]: ToOwned>, { @@ -3403,7 +3414,8 @@ where #[cfg(not(no_global_oom_handling))] #[stable(feature = "rust1", since = "1.0.0")] -impl From<&str> for Vec { +#[allow(unused_braces)] +impl From<&str> for Vec { /// Allocate a `Vec` and fill it with a UTF-8 string. /// /// # Examples diff --git a/library/alloc/src/vec/spec_from_iter.rs b/library/alloc/src/vec/spec_from_iter.rs index 7db120f1ff6c2..06da451fe3932 100644 --- a/library/alloc/src/vec/spec_from_iter.rs +++ b/library/alloc/src/vec/spec_from_iter.rs @@ -1,5 +1,7 @@ use core::mem::ManuallyDrop; use core::ptr::{self}; +use crate::Global; +use crate::DEFAULT_COOP_PREFERRED; use super::{IntoIter, SpecExtend, SpecFromIterNested, Vec}; @@ -25,7 +27,8 @@ pub(super) trait SpecFromIter { fn from_iter(iter: I) -> Self; } -impl SpecFromIter for Vec +#[allow(unused_braces)] +impl SpecFromIter for Vec where I: Iterator, { @@ -34,7 +37,8 @@ where } } -impl SpecFromIter> for Vec { +#[allow(unused_braces)] +impl SpecFromIter> for Vec { fn from_iter(iterator: IntoIter) -> Self { // A common case is passing a vector into a function which immediately // re-collects into a vector. We can short circuit this if the IntoIter diff --git a/library/alloc/src/vec/spec_from_iter_nested.rs b/library/alloc/src/vec/spec_from_iter_nested.rs index 9453f2dcd9828..7408155ff870a 100644 --- a/library/alloc/src/vec/spec_from_iter_nested.rs +++ b/library/alloc/src/vec/spec_from_iter_nested.rs @@ -3,6 +3,8 @@ use core::iter::TrustedLen; use core::ptr; use crate::raw_vec::RawVec; +use crate::Global; +use crate::DEFAULT_COOP_PREFERRED; use super::{SpecExtend, Vec}; @@ -13,7 +15,8 @@ pub(super) trait SpecFromIterNested { fn from_iter(iter: I) -> Self; } -impl SpecFromIterNested for Vec +#[allow(unused_braces)] +impl SpecFromIterNested for Vec where I: Iterator, { @@ -45,7 +48,8 @@ where } } -impl SpecFromIterNested for Vec +#[allow(unused_braces)] +impl SpecFromIterNested for Vec where I: TrustedLen, { diff --git a/library/core/src/alloc/mod.rs b/library/core/src/alloc/mod.rs index eb7edf1600ef7..bcdc8292ff8c1 100644 --- a/library/core/src/alloc/mod.rs +++ b/library/core/src/alloc/mod.rs @@ -81,7 +81,11 @@ pub struct SliceAndMeta { } #[unstable(feature = "global_co_alloc_short_term_pref", issue = "none")] -pub const SHORT_TERM_VEC_PREFERS_COOP: bool = true; +//pub const SHORT_TERM_VEC_PREFERS_COOP: bool = true; +#[macro_export] +macro_rules! SHORT_TERM_VEC_PREFERS_COOP { + () => {true} +} #[unstable(feature = "global_co_alloc_meta", issue = "none")] #[allow(missing_debug_implementations)] From 71080bab7cbc811ab89f6d5dd594bc7c4e86c931 Mon Sep 17 00:00:00 2001 From: Peter Kehl Date: Sun, 22 Jan 2023 07:51:52 -0800 Subject: [PATCH 035/118] CoAlloc: VecDeque: Macros instead of const for global COOP defaults (working around ICE). --- library/alloc/src/collections/vec_deque/drain.rs | 3 ++- library/alloc/src/collections/vec_deque/mod.rs | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/library/alloc/src/collections/vec_deque/drain.rs b/library/alloc/src/collections/vec_deque/drain.rs index 2004060c4bb96..1bfeaf5a5d3fc 100644 --- a/library/alloc/src/collections/vec_deque/drain.rs +++ b/library/alloc/src/collections/vec_deque/drain.rs @@ -15,11 +15,12 @@ use super::VecDeque; /// /// [`drain`]: VecDeque::drain #[stable(feature = "drain", since = "1.6.0")] +#[allow(unused_braces)] pub struct Drain< 'a, T: 'a, #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global, - const COOP_PREFERRED: bool = { alloc::SHORT_TERM_VEC_PREFERS_COOP }, + const COOP_PREFERRED: bool = { SHORT_TERM_VEC_PREFERS_COOP!() }, > where [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, { diff --git a/library/alloc/src/collections/vec_deque/mod.rs b/library/alloc/src/collections/vec_deque/mod.rs index 7c5cfd1e5fe2e..c14a0bb12763b 100644 --- a/library/alloc/src/collections/vec_deque/mod.rs +++ b/library/alloc/src/collections/vec_deque/mod.rs @@ -7,7 +7,7 @@ #![feature(global_co_alloc)] #![stable(feature = "rust1", since = "1.0.0")] -use crate::vec::DEFAULT_COOP_PREFERRED; +use crate::DEFAULT_COOP_PREFERRED; use core::alloc; use core::cmp::{self, Ordering}; use core::fmt; @@ -93,10 +93,11 @@ mod tests; #[cfg_attr(not(test), rustc_diagnostic_item = "VecDeque")] #[stable(feature = "rust1", since = "1.0.0")] #[rustc_insignificant_dtor] +#[allow(unused_braces)] pub struct VecDeque< T, #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global, - const COOP_PREFERRED: bool = DEFAULT_COOP_PREFERRED, + const COOP_PREFERRED: bool = {DEFAULT_COOP_PREFERRED!()}, > where [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, { From ee2b8738d3b66c37432765c0d5c223c1e6c92c06 Mon Sep 17 00:00:00 2001 From: Peter Kehl Date: Sun, 22 Jan 2023 07:52:07 -0800 Subject: [PATCH 036/118] CoAlloc: BinaryHeap: Macros instead of const for global COOP defaults (working around ICE). --- library/alloc/src/collections/binary_heap/mod.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/library/alloc/src/collections/binary_heap/mod.rs b/library/alloc/src/collections/binary_heap/mod.rs index 0a4a52e25c48f..bc08a604b8cd0 100644 --- a/library/alloc/src/collections/binary_heap/mod.rs +++ b/library/alloc/src/collections/binary_heap/mod.rs @@ -148,13 +148,14 @@ use core::mem::{self, swap, ManuallyDrop}; use core::num::NonZeroUsize; use core::ops::{Deref, DerefMut}; use core::ptr; -use core::{alloc, fmt}; +use core::fmt; use crate::alloc::Global; use crate::collections::TryReserveError; use crate::slice; use crate::vec::{self, AsVecIntoIter, Vec}; +use crate::DEFAULT_COOP_PREFERRED; use super::SpecExtend; @@ -1243,7 +1244,8 @@ impl BinaryHeap { /// ``` #[inline] #[stable(feature = "drain", since = "1.6.0")] - pub fn drain(&mut self) -> Drain<'_, T, { alloc::SHORT_TERM_VEC_PREFERS_COOP }> { + #[allow(unused_braces)] + pub fn drain(&mut self) -> Drain<'_, T, { SHORT_TERM_VEC_PREFERS_COOP!() }> { Drain { iter: self.data.drain(..) } } @@ -1652,7 +1654,8 @@ impl From<[T; N]> for BinaryHeap { } #[stable(feature = "binary_heap_extras_15", since = "1.5.0")] -impl From> for Vec { +#[allow(unused_braces)] +impl From> for Vec { /// Converts a `BinaryHeap` into a `Vec`. /// /// This conversion requires no data movement or allocation, and has From 68b924be7023b1047a1a2bbfbc7019c5e68a4c16 Mon Sep 17 00:00:00 2001 From: Peter Kehl Date: Sun, 22 Jan 2023 07:53:22 -0800 Subject: [PATCH 037/118] CoAlloc: TODO replace co_alloc_metadata_num_slots_with_preference_global(...) --- library/alloc/src/lib.rs | 3 ++- library/alloc/src/raw_vec.rs | 2 +- library/core/src/alloc/mod.rs | 5 +++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/library/alloc/src/lib.rs b/library/alloc/src/lib.rs index 251d4b3fec200..9187c24af35b1 100644 --- a/library/alloc/src/lib.rs +++ b/library/alloc/src/lib.rs @@ -292,5 +292,6 @@ use crate::alloc::Global; /// See also `core::alloc::co_alloc_metadata_num_slots_with_preference`. #[unstable(feature = "global_co_alloc", issue = "none")] pub const fn co_alloc_metadata_num_slots_with_preference_global(coop_preferred: bool) -> usize { - if Global::IS_CO_ALLOCATOR && coop_preferred { 1 } else { 0 } + // FIXME or replace any calls with core::alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED). Then rename co_alloc_metadata_num_slots_with_preference_specific to co_alloc_metadata_num_slots_with_preference. See raw_vec.rs. + if /*Global::IS_CO_ALLOCATOR*/ true && coop_preferred { 1 } else { 0 } } diff --git a/library/alloc/src/raw_vec.rs b/library/alloc/src/raw_vec.rs index 408f3a023fda8..6b3ecd07ade80 100644 --- a/library/alloc/src/raw_vec.rs +++ b/library/alloc/src/raw_vec.rs @@ -70,7 +70,7 @@ pub(crate) struct RawVec< impl RawVec where - [(); crate::co_alloc_metadata_num_slots_with_preference_global(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, { /// HACK(Centril): This exists because stable `const fn` can only call stable `const fn`, so /// they cannot call `Self::new()`. diff --git a/library/core/src/alloc/mod.rs b/library/core/src/alloc/mod.rs index bcdc8292ff8c1..0599b79a99417 100644 --- a/library/core/src/alloc/mod.rs +++ b/library/core/src/alloc/mod.rs @@ -93,8 +93,9 @@ pub type SliceAndMetaResult = Result; #[unstable(feature = "global_co_alloc", issue = "none")] pub const fn co_alloc_metadata_num_slots() -> usize { - if true { - panic!("FIXME - consider removing co_alloc_metadata_num_slots()"); + // @FIXME later + if false { + panic!("FIXME - consider replacing co_alloc_metadata_num_slots() with co_alloc_metadata_num_slots_with_preference_specific(bool), and adding const flags as appropriate."); } if A::IS_CO_ALLOCATOR { 1 } else { 0 } } From 362e27abaaeee97b7fc5a0a0a97e99f846cc1935 Mon Sep 17 00:00:00 2001 From: Peter Kehl Date: Sun, 22 Jan 2023 20:54:42 -0800 Subject: [PATCH 038/118] CoAlloc: Vec + core: Renamed co_alloc_metadata_num_slots_with_preference_specific(...) to co_alloc_metadata_num_slots_with_preference(...) --- library/alloc/src/raw_vec.rs | 20 +++--- library/alloc/src/slice.rs | 22 +++---- library/alloc/src/vec/drain.rs | 28 ++++---- library/alloc/src/vec/drain_filter.rs | 12 ++-- library/alloc/src/vec/into_iter.rs | 36 +++++----- library/alloc/src/vec/mod.rs | 88 +++++++++++-------------- library/alloc/src/vec/partial_eq.rs | 20 +++--- library/alloc/src/vec/spec_extend.rs | 10 +-- library/alloc/src/vec/spec_from_elem.rs | 8 +-- library/core/src/alloc/mod.rs | 2 +- library/std/src/io/cursor.rs | 12 ++-- 11 files changed, 123 insertions(+), 135 deletions(-) diff --git a/library/alloc/src/raw_vec.rs b/library/alloc/src/raw_vec.rs index 6b3ecd07ade80..6da9570922947 100644 --- a/library/alloc/src/raw_vec.rs +++ b/library/alloc/src/raw_vec.rs @@ -56,7 +56,7 @@ pub(crate) struct RawVec< A: Allocator = Global, const COOP_PREFERRED: bool = {DEFAULT_COOP_PREFERRED!()}, > where - [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { ptr: Unique, cap: usize, @@ -65,12 +65,12 @@ pub(crate) struct RawVec< //pub(crate) meta: [GlobalCoAllocMeta; {if core::any::TypeId::of::()==core::any::TypeId::of::() {1} else {0}}], //pub(crate) meta: [GlobalCoAllocMeta; mem::size_of::()], pub(crate) metas: [GlobalCoAllocMeta; - alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)], + alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)], } impl RawVec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { /// HACK(Centril): This exists because stable `const fn` can only call stable `const fn`, so /// they cannot call `Self::new()`. @@ -120,7 +120,7 @@ where impl RawVec where - [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { // Tiny Vecs are dumb. Skip to: // - 8 if the element size is 1, because any heap allocators is likely @@ -144,7 +144,7 @@ where cap: 0, alloc, metas: [GlobalCoAllocMeta {/*one: 1*/ /* , two: 2, three: 3, four: 4*/}; - alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)], + alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)], } } @@ -223,7 +223,7 @@ where cap: capacity, alloc, metas: [GlobalCoAllocMeta {/*one: 1*/ /*, two: 2, three: 3, four: 4*/}; - alloc::co_alloc_metadata_num_slots_with_preference_specific::( + alloc::co_alloc_metadata_num_slots_with_preference::( COOP_PREFERRED, )], } @@ -247,7 +247,7 @@ where cap: capacity, alloc, metas: [GlobalCoAllocMeta {/*one: 1*/ /*, two: 2, three: 3, four: 4*/}; - alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)], + alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)], } } @@ -322,7 +322,7 @@ where len: usize, additional: usize, ) where - [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { handle_reserve(slf.grow_amortized(len, additional)); } @@ -398,7 +398,7 @@ where impl RawVec where - [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { /// Returns if the buffer needs to grow to fulfill the needed extra capacity. /// Mainly used to make inlining reserve-calls possible without inlining `grow`. @@ -522,7 +522,7 @@ where unsafe impl<#[may_dangle] T, A: Allocator, const COOP_PREFERRED: bool> Drop for RawVec where - [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { /// Frees the memory owned by the `RawVec` *without* trying to drop its contents. default fn drop(&mut self) { diff --git a/library/alloc/src/slice.rs b/library/alloc/src/slice.rs index b3118ce23f028..48d218ea28602 100644 --- a/library/alloc/src/slice.rs +++ b/library/alloc/src/slice.rs @@ -101,7 +101,7 @@ pub(crate) mod hack { b: Box<[T], A>, ) -> Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference_specific::( + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::( COOP_PREFERRED, )]:, { @@ -119,7 +119,7 @@ pub(crate) mod hack { alloc: A, ) -> Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference_specific::( + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::( COOP_PREFERRED, )]:, { @@ -134,7 +134,7 @@ pub(crate) mod hack { ) -> Vec where Self: Sized, - [(); core::alloc::co_alloc_metadata_num_slots_with_preference_specific::( + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::( COOP_PREFERRED, )]:; } @@ -147,13 +147,13 @@ pub(crate) mod hack { alloc: A, ) -> Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference_specific::( + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::( COOP_PREFERRED, )]:, { struct DropGuard<'a, T, A: Allocator, const COOP_PREFERRED: bool> where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference_specific::( + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::( COOP_PREFERRED, )]:, { @@ -162,7 +162,7 @@ pub(crate) mod hack { } impl<'a, T, A: Allocator, const COOP_PREFERRED: bool> Drop for DropGuard<'a, T, A, COOP_PREFERRED> where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference_specific::( + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::( COOP_PREFERRED, )]:, { @@ -202,7 +202,7 @@ pub(crate) mod hack { alloc: A, ) -> Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference_specific::( + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::( COOP_PREFERRED, )]:, { @@ -486,7 +486,7 @@ impl [T] { ) -> Vec where T: Clone, - [(); core::alloc::co_alloc_metadata_num_slots_with_preference_specific::( + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::( COOP_PREFERRED, )]:, { @@ -515,7 +515,7 @@ impl [T] { self: Box, ) -> Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference_specific::( + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::( COOP_PREFERRED, )]:, { @@ -834,7 +834,7 @@ impl> Join<&[T]> for [V] { #[stable(feature = "rust1", since = "1.0.0")] impl Borrow<[T]> for Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { fn borrow(&self) -> &[T] { &self[..] @@ -844,7 +844,7 @@ where #[stable(feature = "rust1", since = "1.0.0")] impl BorrowMut<[T]> for Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { fn borrow_mut(&mut self) -> &mut [T] { &mut self[..] diff --git a/library/alloc/src/vec/drain.rs b/library/alloc/src/vec/drain.rs index 72153029287bd..05fee754beec8 100644 --- a/library/alloc/src/vec/drain.rs +++ b/library/alloc/src/vec/drain.rs @@ -26,7 +26,7 @@ pub struct Drain< #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator + 'a = Global, const COOP_PREFERRED: bool = { SHORT_TERM_VEC_PREFERS_COOP!() }, > where - [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { /// Index of tail to preserve pub(super) tail_start: usize, @@ -41,7 +41,7 @@ pub struct Drain< impl fmt::Debug for Drain<'_, T, A, COOP_PREFERRED> where - [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_tuple("Drain").field(&self.iter.as_slice()).finish() @@ -50,7 +50,7 @@ where impl<'a, T, A: Allocator, const COOP_PREFERRED: bool> Drain<'a, T, A, COOP_PREFERRED> where - [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { /// Returns the remaining items of this iterator as a slice. /// @@ -152,7 +152,7 @@ where #[stable(feature = "vec_drain_as_slice", since = "1.46.0")] impl<'a, T, A: Allocator, const COOP_PREFERRED: bool> AsRef<[T]> for Drain<'a, T, A, COOP_PREFERRED> where - [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { fn as_ref(&self) -> &[T] { self.as_slice() @@ -163,21 +163,21 @@ where unsafe impl Sync for Drain<'_, T, A, COOP_PREFERRED> where - [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { } #[stable(feature = "drain", since = "1.6.0")] unsafe impl Send for Drain<'_, T, A, COOP_PREFERRED> where - [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { } #[stable(feature = "drain", since = "1.6.0")] impl Iterator for Drain<'_, T, A, COOP_PREFERRED> where - [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { type Item = T; @@ -195,7 +195,7 @@ where impl DoubleEndedIterator for Drain<'_, T, A, COOP_PREFERRED> where - [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { #[inline] fn next_back(&mut self) -> Option { @@ -206,7 +206,7 @@ where #[stable(feature = "drain", since = "1.6.0")] impl Drop for Drain<'_, T, A, COOP_PREFERRED> where - [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { fn drop(&mut self) { /// Moves back the un-`Drain`ed elements to restore the original `Vec`. @@ -214,12 +214,12 @@ where &'r mut Drain<'a, T, A, COOP_PREFERRED>, ) where - [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:; + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:; impl<'r, 'a, T, A: Allocator, const COOP_PREFERRED: bool> Drop for DropGuard<'r, 'a, T, A, COOP_PREFERRED> where - [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { fn drop(&mut self) { if self.0.tail_len > 0 { @@ -287,7 +287,7 @@ where impl ExactSizeIterator for Drain<'_, T, A, COOP_PREFERRED> where - [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { fn is_empty(&self) -> bool { self.iter.is_empty() @@ -298,12 +298,12 @@ where unsafe impl TrustedLen for Drain<'_, T, A, COOP_PREFERRED> where - [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { } #[stable(feature = "fused", since = "1.26.0")] impl FusedIterator for Drain<'_, T, A, COOP_PREFERRED> where - [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]: + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { } diff --git a/library/alloc/src/vec/drain_filter.rs b/library/alloc/src/vec/drain_filter.rs index 29cf29e2532d9..89baafca46729 100644 --- a/library/alloc/src/vec/drain_filter.rs +++ b/library/alloc/src/vec/drain_filter.rs @@ -27,7 +27,7 @@ pub struct DrainFilter< const COOP_PREFERRED: bool = true, > where F: FnMut(&mut T) -> bool, - [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { pub(super) vec: &'a mut Vec, /// The index of the item that will be inspected by the next call to `next`. @@ -49,7 +49,7 @@ pub struct DrainFilter< impl DrainFilter<'_, T, F, A, COOP_PREFERRED> where F: FnMut(&mut T) -> bool, - [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { /// Returns a reference to the underlying allocator. #[unstable(feature = "allocator_api", issue = "32838")] @@ -119,7 +119,7 @@ impl Iterator for DrainFilter<'_, T, F, A, COOP_PREFERRED> where F: FnMut(&mut T) -> bool, - [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { type Item = T; @@ -159,13 +159,13 @@ impl Drop for DrainFilter<'_, T, F, A, COOP_PREFERRED> where F: FnMut(&mut T) -> bool, - [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { fn drop(&mut self) { struct BackshiftOnDrop<'a, 'b, T, F, A: Allocator, const COOP_PREFERRED: bool> where F: FnMut(&mut T) -> bool, - [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { drain: &'b mut DrainFilter<'a, T, F, A, COOP_PREFERRED>, } @@ -174,7 +174,7 @@ where for BackshiftOnDrop<'a, 'b, T, F, A, COOP_PREFERRED> where F: FnMut(&mut T) -> bool, - [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { fn drop(&mut self) { unsafe { diff --git a/library/alloc/src/vec/into_iter.rs b/library/alloc/src/vec/into_iter.rs index 7ca48fba02f06..5afb11ee7ba24 100644 --- a/library/alloc/src/vec/into_iter.rs +++ b/library/alloc/src/vec/into_iter.rs @@ -34,7 +34,7 @@ pub struct IntoIter< #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global, const COOP_PREFERRED: bool = { SHORT_TERM_VEC_PREFERS_COOP!() }, > where - [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { pub(super) buf: NonNull, pub(super) phantom: PhantomData, @@ -52,7 +52,7 @@ pub struct IntoIter< impl fmt::Debug for IntoIter where - [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_tuple("IntoIter").field(&self.as_slice()).finish() @@ -61,7 +61,7 @@ where impl IntoIter where - [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { /// Returns the remaining items of this iterator as a slice. /// @@ -180,7 +180,7 @@ where #[stable(feature = "vec_intoiter_as_ref", since = "1.46.0")] impl AsRef<[T]> for IntoIter where - [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { fn as_ref(&self) -> &[T] { self.as_slice() @@ -191,21 +191,21 @@ where unsafe impl Send for IntoIter where - [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { } #[stable(feature = "rust1", since = "1.0.0")] unsafe impl Sync for IntoIter where - [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { } #[stable(feature = "rust1", since = "1.0.0")] impl Iterator for IntoIter where - [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { type Item = T; @@ -323,7 +323,7 @@ where impl DoubleEndedIterator for IntoIter where - [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { #[inline] fn next_back(&mut self) -> Option { @@ -368,7 +368,7 @@ where impl ExactSizeIterator for IntoIter where - [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { fn is_empty(&self) -> bool { self.ptr == self.end @@ -377,7 +377,7 @@ where #[stable(feature = "fused", since = "1.26.0")] impl FusedIterator for IntoIter where - [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]: + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { } @@ -385,7 +385,7 @@ impl FusedIterator for IntoIter TrustedLen for IntoIter where - [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { } @@ -407,7 +407,7 @@ unsafe impl TrustedRandomAccessNoCo for IntoIter where T: NonDrop, - [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { const MAY_HAVE_SIDE_EFFECT: bool = false; } @@ -417,7 +417,7 @@ where impl Clone for IntoIter where - [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { #[cfg(not(test))] fn clone(&self) -> Self { @@ -433,18 +433,18 @@ where unsafe impl<#[may_dangle] T, A: Allocator, const COOP_PREFERRED: bool> Drop for IntoIter where - [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { fn drop(&mut self) { struct DropGuard<'a, T, A: Allocator, const COOP_PREFERRED: bool>( &'a mut IntoIter, ) where - [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:; + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:; impl Drop for DropGuard<'_, T, A, COOP_PREFERRED> where - [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { fn drop(&mut self) { unsafe { @@ -476,7 +476,7 @@ where unsafe impl InPlaceIterable for IntoIter where - [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { } @@ -485,7 +485,7 @@ where unsafe impl SourceIter for IntoIter where - [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { type Source = Self; diff --git a/library/alloc/src/vec/mod.rs b/library/alloc/src/vec/mod.rs index 0ae11ad01a1c9..14b72d53a8457 100644 --- a/library/alloc/src/vec/mod.rs +++ b/library/alloc/src/vec/mod.rs @@ -412,7 +412,7 @@ pub struct Vec< //@FIXME: #[unstable(feature ="global_co_alloc_vec", issue="none")] const COOP_PREFERRED: bool = {DEFAULT_COOP_PREFERRED!()}, > where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { buf: RawVec, len: usize, @@ -637,7 +637,7 @@ where impl Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { /// Constructs a new, empty `Vec`. /// @@ -1653,7 +1653,7 @@ where // In cases when predicate and `drop` never panick, it will be optimized out. struct BackshiftOnDrop<'a, T, A: Allocator, const VEC_IS_COOP: bool = true> where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference_specific::( + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::( VEC_IS_COOP, )]:, { @@ -1665,7 +1665,7 @@ where impl Drop for BackshiftOnDrop<'_, T, A, VEC_IS_COOP> where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference_specific::( + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::( VEC_IS_COOP, )]:, { @@ -1700,7 +1700,7 @@ where g: &mut BackshiftOnDrop<'_, T, A, VEC_IS_COOP>, ) where F: FnMut(&mut T) -> bool, - [(); core::alloc::co_alloc_metadata_num_slots_with_preference_specific::( + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::( VEC_IS_COOP, )]:, { @@ -1797,7 +1797,7 @@ where /* INVARIANT: vec.len() > read >= write > write-1 >= 0 */ struct FillGapOnDrop<'a, T, A: core::alloc::Allocator, const COOP_PREFERRED: bool> where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference_specific::( + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::( COOP_PREFERRED, )]:, { @@ -1815,7 +1815,7 @@ where impl<'a, T, A: core::alloc::Allocator, const COOP_PREFERRED: bool> Drop for FillGapOnDrop<'a, T, A, COOP_PREFERRED> where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference_specific::( + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::( COOP_PREFERRED, )]:, { @@ -2413,7 +2413,7 @@ where impl Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { /// Resizes the `Vec` in-place so that `len` is equal to `new_len`. /// @@ -2515,7 +2515,7 @@ where impl Vec<[T; N], A, COOP_PREFERRED> where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { /// Takes a `Vec<[T; N]>` and flattens it into a `Vec`. /// @@ -2579,7 +2579,7 @@ impl ExtendWith for ExtendElement { impl Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { #[cfg(not(no_global_oom_handling))] /// Extend the vector by `n` values, using the given generator. @@ -2614,7 +2614,7 @@ where impl Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { /// Removes consecutive repeated elements in the vector according to the /// [`PartialEq`] trait implementation. @@ -2657,7 +2657,7 @@ pub fn from_elem_in( alloc: A, ) -> Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { ::from_elem(elem, n, alloc) } @@ -2673,7 +2673,7 @@ trait ExtendFromWithinSpec { impl ExtendFromWithinSpec for Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { default unsafe fn spec_extend_from_within(&mut self, src: Range) { // SAFETY: @@ -2696,7 +2696,7 @@ where impl ExtendFromWithinSpec for Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { unsafe fn spec_extend_from_within(&mut self, src: Range) { let count = src.len(); @@ -2732,7 +2732,7 @@ where #[stable(feature = "rust1", since = "1.0.0")] impl ops::Deref for Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { type Target = [T]; @@ -2745,7 +2745,7 @@ where #[stable(feature = "rust1", since = "1.0.0")] impl ops::DerefMut for Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { #[inline] fn deref_mut(&mut self) -> &mut [T] { @@ -2754,22 +2754,10 @@ where } #[cfg(not(no_global_oom_handling))] -impl SpecCloneFrom for Vec -where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, -{ - fn clone_from(this: &mut Self, other: &Self) { - this.clear(); - this.extend_from_slice(other); - } -} - -#[cfg(not(no_global_oom_handling))] ->>>>>>> 72db464d2e0 (CoAlloc: Vec: Renamed ::core::alloc::co_alloc_metadata_num_slots_with_preference to ::core::alloc::co_alloc_metadata_num_slots_with_preference_specific. ICE) #[stable(feature = "rust1", since = "1.0.0")] impl Clone for Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { #[cfg(not(test))] fn clone(&self) -> Self { @@ -2807,7 +2795,7 @@ where #[stable(feature = "rust1", since = "1.0.0")] impl Hash for Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { #[inline] fn hash(&self, state: &mut H) { @@ -2823,7 +2811,7 @@ where impl, A: Allocator, const COOP_PREFERRED: bool> Index for Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { type Output = I::Output; @@ -2841,7 +2829,7 @@ where impl, A: Allocator, const COOP_PREFERRED: bool> IndexMut for Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { #[inline] fn index_mut(&mut self, index: I) -> &mut Self::Output { @@ -2862,7 +2850,7 @@ impl FromIterator for Vec { #[stable(feature = "rust1", since = "1.0.0")] impl IntoIterator for Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { type Item = T; type IntoIter = IntoIter; @@ -2910,7 +2898,7 @@ where #[stable(feature = "rust1", since = "1.0.0")] impl<'a, T, A: Allocator, const COOP_PREFERRED: bool> IntoIterator for &'a Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { type Item = &'a T; type IntoIter = slice::Iter<'a, T>; @@ -2924,7 +2912,7 @@ where impl<'a, T, A: Allocator, const COOP_PREFERRED: bool> IntoIterator for &'a mut Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { type Item = &'a mut T; type IntoIter = slice::IterMut<'a, T>; @@ -2938,7 +2926,7 @@ where #[stable(feature = "rust1", since = "1.0.0")] impl Extend for Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { #[inline] fn extend>(&mut self, iter: I) { @@ -2958,7 +2946,7 @@ where impl Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { // leaf method to which various SpecFrom/SpecExtend implementations delegate when // they have no further optimizations to apply @@ -3136,7 +3124,7 @@ where impl<'a, T: Copy + 'a, A: Allocator + 'a, const COOP_PREFERRED: bool> Extend<&'a T> for Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { fn extend>(&mut self, iter: I) { self.spec_extend(iter.into_iter()) @@ -3158,7 +3146,7 @@ where impl PartialOrd for Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { #[inline] fn partial_cmp(&self, other: &Self) -> Option { @@ -3168,7 +3156,7 @@ where #[stable(feature = "rust1", since = "1.0.0")] impl Eq for Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]: + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { } @@ -3176,7 +3164,7 @@ impl Eq for Vec Ord for Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { #[inline] fn cmp(&self, other: &Self) -> Ordering { @@ -3188,7 +3176,7 @@ where unsafe impl<#[may_dangle] T, A: Allocator, const COOP_PREFERRED: bool> Drop for Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { fn drop(&mut self) { unsafe { @@ -3219,7 +3207,7 @@ where impl fmt::Debug for Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fmt::Debug::fmt(&**self, f) @@ -3230,7 +3218,7 @@ where impl AsRef> for Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { fn as_ref(&self) -> &Vec { self @@ -3241,7 +3229,7 @@ where impl AsMut> for Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { fn as_mut(&mut self) -> &mut Vec { self @@ -3251,7 +3239,7 @@ where #[stable(feature = "rust1", since = "1.0.0")] impl AsRef<[T]> for Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { fn as_ref(&self) -> &[T] { self @@ -3261,7 +3249,7 @@ where #[stable(feature = "vec_as_mut", since = "1.5.0")] impl AsMut<[T]> for Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { fn as_mut(&mut self) -> &mut [T] { self @@ -3365,7 +3353,7 @@ where #[stable(feature = "vec_from_box", since = "1.18.0")] impl From> for Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { /// Convert a boxed slice into a vector by transferring ownership of /// the existing heap allocation. @@ -3387,7 +3375,7 @@ where #[stable(feature = "box_from_vec", since = "1.20.0")] impl From> for Box<[T], A> where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { /// Convert a vector into a boxed slice. /// @@ -3432,7 +3420,7 @@ impl From<&str> for Vec { impl TryFrom> for [T; N] where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { type Error = Vec; diff --git a/library/alloc/src/vec/partial_eq.rs b/library/alloc/src/vec/partial_eq.rs index 7b364e8d4bacd..bcf52b7333218 100644 --- a/library/alloc/src/vec/partial_eq.rs +++ b/library/alloc/src/vec/partial_eq.rs @@ -21,21 +21,21 @@ macro_rules! __impl_slice_eq1 { } } -__impl_slice_eq1! { [A1: Allocator, A2: Allocator, const COOP_PREFERRED1: bool, const COOP_PREFERRED2: bool] Vec, Vec, #[stable(feature = "rust1", since = "1.0.0")], [(); core::alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED1)]:, [(); core::alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED2)]: } -__impl_slice_eq1! { [A: Allocator, const COOP_PREFERRED: bool] Vec, &[U], #[stable(feature = "rust1", since = "1.0.0")], [(); core::alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]: } -__impl_slice_eq1! { [A: Allocator, const COOP_PREFERRED: bool] Vec, &mut [U], #[stable(feature = "rust1", since = "1.0.0")], [(); core::alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]: } -__impl_slice_eq1! { [A: Allocator, const COOP_PREFERRED: bool] &[T], Vec, #[stable(feature = "partialeq_vec_for_ref_slice", since = "1.46.0")], [(); core::alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]: } -__impl_slice_eq1! { [A: Allocator, const COOP_PREFERRED: bool] &mut [T], Vec, #[stable(feature = "partialeq_vec_for_ref_slice", since = "1.46.0")], [(); core::alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]: } -__impl_slice_eq1! { [A: Allocator, const COOP_PREFERRED: bool] Vec, [U], #[stable(feature = "partialeq_vec_for_slice", since = "1.48.0")], [(); core::alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]: } -__impl_slice_eq1! { [A: Allocator, const COOP_PREFERRED: bool] [T], Vec, #[stable(feature = "partialeq_vec_for_slice", since = "1.48.0")], [(); core::alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]: } +__impl_slice_eq1! { [A1: Allocator, A2: Allocator, const COOP_PREFERRED1: bool, const COOP_PREFERRED2: bool] Vec, Vec, #[stable(feature = "rust1", since = "1.0.0")], [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED1)]:, [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED2)]: } +__impl_slice_eq1! { [A: Allocator, const COOP_PREFERRED: bool] Vec, &[U], #[stable(feature = "rust1", since = "1.0.0")], [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: } +__impl_slice_eq1! { [A: Allocator, const COOP_PREFERRED: bool] Vec, &mut [U], #[stable(feature = "rust1", since = "1.0.0")], [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: } +__impl_slice_eq1! { [A: Allocator, const COOP_PREFERRED: bool] &[T], Vec, #[stable(feature = "partialeq_vec_for_ref_slice", since = "1.46.0")], [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: } +__impl_slice_eq1! { [A: Allocator, const COOP_PREFERRED: bool] &mut [T], Vec, #[stable(feature = "partialeq_vec_for_ref_slice", since = "1.46.0")], [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: } +__impl_slice_eq1! { [A: Allocator, const COOP_PREFERRED: bool] Vec, [U], #[stable(feature = "partialeq_vec_for_slice", since = "1.48.0")], [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: } +__impl_slice_eq1! { [A: Allocator, const COOP_PREFERRED: bool] [T], Vec, #[stable(feature = "partialeq_vec_for_slice", since = "1.48.0")], [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: } #[cfg(not(no_global_oom_handling))] -__impl_slice_eq1! { [A: Allocator, const COOP_PREFERRED: bool] Cow<'_, [T]>, Vec, #[stable(feature = "rust1", since = "1.0.0")], T: Clone, [(); core::alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]: } +__impl_slice_eq1! { [A: Allocator, const COOP_PREFERRED: bool] Cow<'_, [T]>, Vec, #[stable(feature = "rust1", since = "1.0.0")], T: Clone, [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: } #[cfg(not(no_global_oom_handling))] __impl_slice_eq1! { [] Cow<'_, [T]>, &[U], #[stable(feature = "rust1", since = "1.0.0")], T: Clone } #[cfg(not(no_global_oom_handling))] __impl_slice_eq1! { [] Cow<'_, [T]>, &mut [U], #[stable(feature = "rust1", since = "1.0.0")], T: Clone } -__impl_slice_eq1! { [A: Allocator, const COOP_PREFERRED: bool, const N: usize] Vec, [U; N], #[stable(feature = "rust1", since = "1.0.0")], [(); core::alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]: } -__impl_slice_eq1! { [A: Allocator, const COOP_PREFERRED: bool, const N: usize] Vec, &[U; N], #[stable(feature = "rust1", since = "1.0.0")], [(); core::alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]: } +__impl_slice_eq1! { [A: Allocator, const COOP_PREFERRED: bool, const N: usize] Vec, [U; N], #[stable(feature = "rust1", since = "1.0.0")], [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: } +__impl_slice_eq1! { [A: Allocator, const COOP_PREFERRED: bool, const N: usize] Vec, &[U; N], #[stable(feature = "rust1", since = "1.0.0")], [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: } // NOTE: some less important impls are omitted to reduce code bloat // FIXME(Centril): Reconsider this? diff --git a/library/alloc/src/vec/spec_extend.rs b/library/alloc/src/vec/spec_extend.rs index ea91491f62558..73cf325889290 100644 --- a/library/alloc/src/vec/spec_extend.rs +++ b/library/alloc/src/vec/spec_extend.rs @@ -13,7 +13,7 @@ pub(super) trait SpecExtend { impl SpecExtend for Vec where I: Iterator, - [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { default fn spec_extend(&mut self, iter: I) { self.extend_desugared(iter) @@ -23,7 +23,7 @@ where impl SpecExtend for Vec where I: TrustedLen, - [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { default fn spec_extend(&mut self, iterator: I) { self.extend_trusted(iterator) @@ -33,7 +33,7 @@ where impl SpecExtend> for Vec where - [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { fn spec_extend(&mut self, mut iterator: IntoIter) { unsafe { @@ -48,7 +48,7 @@ impl<'a, T: 'a, I, A: Allocator + 'a, const COOP_PREFERRED: bool> SpecExtend<&'a where I: Iterator, T: Clone, - [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { default fn spec_extend(&mut self, iterator: I) { self.spec_extend(iterator.cloned()) @@ -59,7 +59,7 @@ impl<'a, T: 'a, A: Allocator + 'a, const COOP_PREFERRED: bool> SpecExtend<&'a T, for Vec where T: Copy, - [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { fn spec_extend(&mut self, iterator: slice::Iter<'a, T>) { let slice = iterator.as_slice(); diff --git a/library/alloc/src/vec/spec_from_elem.rs b/library/alloc/src/vec/spec_from_elem.rs index 4c29f6184c149..3766f6de061bb 100644 --- a/library/alloc/src/vec/spec_from_elem.rs +++ b/library/alloc/src/vec/spec_from_elem.rs @@ -24,7 +24,7 @@ impl SpecFromElem for T { alloc: A, ) -> Vec where - [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { let mut v = Vec::with_capacity_in(n, alloc); v.extend_with(n, ExtendElement(elem)); @@ -40,7 +40,7 @@ impl SpecFromElem for T { alloc: A, ) -> Vec where - [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { if elem.is_zero() { return Vec { buf: RawVec::with_capacity_zeroed_in(n, alloc), len: n }; @@ -59,7 +59,7 @@ impl SpecFromElem for i8 { alloc: A, ) -> Vec where - [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { if elem == 0 { return Vec { buf: RawVec::with_capacity_zeroed_in(n, alloc), len: n }; @@ -81,7 +81,7 @@ impl SpecFromElem for u8 { alloc: A, ) -> Vec where - [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { if elem == 0 { return Vec { buf: RawVec::with_capacity_zeroed_in(n, alloc), len: n }; diff --git a/library/core/src/alloc/mod.rs b/library/core/src/alloc/mod.rs index 0599b79a99417..7be3f9cd24b3b 100644 --- a/library/core/src/alloc/mod.rs +++ b/library/core/src/alloc/mod.rs @@ -103,7 +103,7 @@ pub const fn co_alloc_metadata_num_slots() -> usize { #[unstable(feature = "global_co_alloc", issue = "none")] /// Param `coop_preferred` - if false, then this returns `0`, regardless of /// whether allocator `A` is cooperative. -pub const fn co_alloc_metadata_num_slots_with_preference_specific( +pub const fn co_alloc_metadata_num_slots_with_preference( coop_preferred: bool, ) -> usize { if A::IS_CO_ALLOCATOR && coop_preferred { 1 } else { 0 } diff --git a/library/std/src/io/cursor.rs b/library/std/src/io/cursor.rs index f8d2ca1d3e74c..63045ebcb8157 100644 --- a/library/std/src/io/cursor.rs +++ b/library/std/src/io/cursor.rs @@ -404,7 +404,7 @@ fn reserve_and_pad( buf_len: usize, ) -> io::Result where - [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { let pos: usize = (*pos_mut).try_into().map_err(|_| { io::const_io_error!( @@ -451,7 +451,7 @@ unsafe fn vec_write_unchecked( ) -> usize where A: Allocator, - [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { debug_assert!(vec.capacity() >= pos + buf.len()); vec.as_mut_ptr().add(pos).copy_from(buf.as_ptr(), buf.len()); @@ -474,7 +474,7 @@ fn vec_write( ) -> io::Result where A: Allocator, - [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { let buf_len = buf.len(); let mut pos = reserve_and_pad(pos_mut, vec, buf_len)?; @@ -510,7 +510,7 @@ fn vec_write_vectored( ) -> io::Result where A: Allocator, - [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { // For safety reasons, we don't want this sum to overflow ever. // If this saturates, the reserve should panic to avoid any unsound writing. @@ -561,7 +561,7 @@ impl Write for Cursor<&mut [u8]> { impl Write for Cursor<&mut Vec> where A: Allocator, - [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { fn write(&mut self, buf: &[u8]) -> io::Result { vec_write(&mut self.pos, self.inner, buf) @@ -586,7 +586,7 @@ where impl Write for Cursor> where A: Allocator, - [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { fn write(&mut self, buf: &[u8]) -> io::Result { vec_write(&mut self.pos, &mut self.inner, buf) From ad036e14cbed7fdae26bc5a13a9890f30804d77b Mon Sep 17 00:00:00 2001 From: Peter Kehl Date: Sun, 22 Jan 2023 20:54:59 -0800 Subject: [PATCH 039/118] CoAlloc: VecDeque: Renamed co_alloc_metadata_num_slots_with_preference_specific(...) to co_alloc_metadata_num_slots_with_preference(...) --- .../alloc/src/collections/vec_deque/drain.rs | 24 ++++----- .../src/collections/vec_deque/into_iter.rs | 2 +- .../alloc/src/collections/vec_deque/mod.rs | 52 +++++++++---------- .../src/collections/vec_deque/spec_extend.rs | 12 ++--- .../collections/vec_deque/spec_from_iter.rs | 6 +-- 5 files changed, 48 insertions(+), 48 deletions(-) diff --git a/library/alloc/src/collections/vec_deque/drain.rs b/library/alloc/src/collections/vec_deque/drain.rs index 1bfeaf5a5d3fc..cd0e6caace3f4 100644 --- a/library/alloc/src/collections/vec_deque/drain.rs +++ b/library/alloc/src/collections/vec_deque/drain.rs @@ -22,7 +22,7 @@ pub struct Drain< #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global, const COOP_PREFERRED: bool = { SHORT_TERM_VEC_PREFERS_COOP!() }, > where - [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { // We can't just use a &mut VecDeque, as that would make Drain invariant over T // and we want it to be covariant instead @@ -40,7 +40,7 @@ pub struct Drain< impl<'a, T, A: Allocator, const COOP_PREFERRED: bool> Drain<'a, T, A, COOP_PREFERRED> where - [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { pub(super) unsafe fn new( deque: &'a mut VecDeque, @@ -98,7 +98,7 @@ where impl fmt::Debug for Drain<'_, T, A, COOP_PREFERRED> where - [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_tuple("Drain") @@ -114,33 +114,33 @@ where unsafe impl Sync for Drain<'_, T, A, COOP_PREFERRED> where - [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { } #[stable(feature = "drain", since = "1.6.0")] unsafe impl Send for Drain<'_, T, A, COOP_PREFERRED> where - [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { } #[stable(feature = "drain", since = "1.6.0")] impl Drop for Drain<'_, T, A, COOP_PREFERRED> where - [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { fn drop(&mut self) { struct DropGuard<'r, 'a, T, A: Allocator, const COOP_PREFERRED: bool>( &'r mut Drain<'a, T, A, COOP_PREFERRED>, ) where - [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:; + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:; impl<'r, 'a, T, A: Allocator, const COOP_PREFERRED: bool> Drop for DropGuard<'r, 'a, T, A, COOP_PREFERRED> where - [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { fn drop(&mut self) { if self.0.remaining != 0 { @@ -224,7 +224,7 @@ where #[stable(feature = "drain", since = "1.6.0")] impl Iterator for Drain<'_, T, A, COOP_PREFERRED> where - [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { type Item = T; @@ -250,7 +250,7 @@ where impl DoubleEndedIterator for Drain<'_, T, A, COOP_PREFERRED> where - [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { #[inline] fn next_back(&mut self) -> Option { @@ -267,12 +267,12 @@ where impl ExactSizeIterator for Drain<'_, T, A, COOP_PREFERRED> where - [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { } #[stable(feature = "fused", since = "1.26.0")] impl FusedIterator for Drain<'_, T, A, COOP_PREFERRED> where - [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]: + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { } diff --git a/library/alloc/src/collections/vec_deque/into_iter.rs b/library/alloc/src/collections/vec_deque/into_iter.rs index 765b55e2b51b1..751be6ec8846d 100644 --- a/library/alloc/src/collections/vec_deque/into_iter.rs +++ b/library/alloc/src/collections/vec_deque/into_iter.rs @@ -19,7 +19,7 @@ pub struct IntoIter< #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global, const COOP_PREFERRED: bool = true, > where - [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { inner: VecDeque, } diff --git a/library/alloc/src/collections/vec_deque/mod.rs b/library/alloc/src/collections/vec_deque/mod.rs index c14a0bb12763b..2b6f14be0f52d 100644 --- a/library/alloc/src/collections/vec_deque/mod.rs +++ b/library/alloc/src/collections/vec_deque/mod.rs @@ -99,7 +99,7 @@ pub struct VecDeque< #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global, const COOP_PREFERRED: bool = {DEFAULT_COOP_PREFERRED!()}, > where - [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { // `self[0]`, if it exists, is `buf[head]`. // `head < buf.capacity()`, unless `buf.capacity() == 0` when `head == 0`. @@ -115,7 +115,7 @@ pub struct VecDeque< impl Clone for VecDeque where - [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { fn clone(&self) -> Self { let mut deq = Self::with_capacity_in(self.len(), self.allocator().clone()); @@ -133,7 +133,7 @@ where unsafe impl<#[may_dangle] T, A: Allocator, const COOP_PREFERRED: bool> Drop for VecDeque where - [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { fn drop(&mut self) { /// Runs the destructor for all items in the slice when it gets dropped (normally or @@ -172,7 +172,7 @@ where impl VecDeque where - [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { /// Marginally more convenient #[inline] @@ -464,7 +464,7 @@ where ) -> usize { struct Guard<'a, T, A: Allocator, const COOP_PREFERRED: bool> where - [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { deque: &'a mut VecDeque, written: usize, @@ -472,7 +472,7 @@ where impl<'a, T, A: Allocator, const COOP_PREFERRED: bool> Drop for Guard<'a, T, A, COOP_PREFERRED> where - [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { fn drop(&mut self) { self.deque.len += self.written; @@ -553,7 +553,7 @@ where impl VecDeque where - [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { /// Creates an empty deque. /// @@ -592,7 +592,7 @@ where impl VecDeque where - [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { /// Creates an empty deque. /// @@ -2630,7 +2630,7 @@ where impl VecDeque where - [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { /// Modifies the deque in-place so that `len()` is equal to new_len, /// either by removing excess elements from the back or by appending clones of `value` @@ -2679,7 +2679,7 @@ fn wrap_index(logical_index: usize, capacity: usize) -> usize { impl PartialEq for VecDeque where - [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { fn eq(&self, other: &Self) -> bool { if self.len != other.len() { @@ -2720,7 +2720,7 @@ where #[stable(feature = "rust1", since = "1.0.0")] impl Eq for VecDeque where - [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]: + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { } @@ -2735,7 +2735,7 @@ __impl_slice_eq1! { [const N: usize] VecDeque, &mut [U; N] impl PartialOrd for VecDeque where - [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { fn partial_cmp(&self, other: &Self) -> Option { self.iter().partial_cmp(other.iter()) @@ -2745,7 +2745,7 @@ where #[stable(feature = "rust1", since = "1.0.0")] impl Ord for VecDeque where - [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { #[inline] fn cmp(&self, other: &Self) -> Ordering { @@ -2756,7 +2756,7 @@ where #[stable(feature = "rust1", since = "1.0.0")] impl Hash for VecDeque where - [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { fn hash(&self, state: &mut H) { state.write_length_prefix(self.len); @@ -2773,7 +2773,7 @@ where #[stable(feature = "rust1", since = "1.0.0")] impl Index for VecDeque where - [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { type Output = T; @@ -2786,7 +2786,7 @@ where #[stable(feature = "rust1", since = "1.0.0")] impl IndexMut for VecDeque where - [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { #[inline] fn index_mut(&mut self, index: usize) -> &mut T { @@ -2797,7 +2797,7 @@ where #[stable(feature = "rust1", since = "1.0.0")] impl FromIterator for VecDeque where - [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { fn from_iter>(iter: I) -> VecDeque { SpecFromIter::spec_from_iter(iter.into_iter()) @@ -2807,7 +2807,7 @@ where #[stable(feature = "rust1", since = "1.0.0")] impl IntoIterator for VecDeque where - [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { type Item = T; type IntoIter = IntoIter; @@ -2823,7 +2823,7 @@ where impl<'a, T, A: Allocator, const COOP_PREFERRED: bool> IntoIterator for &'a VecDeque where - [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { type Item = &'a T; type IntoIter = Iter<'a, T>; @@ -2837,7 +2837,7 @@ where impl<'a, T, A: Allocator, const COOP_PREFERRED: bool> IntoIterator for &'a mut VecDeque where - [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { type Item = &'a mut T; type IntoIter = IterMut<'a, T>; @@ -2850,7 +2850,7 @@ where #[stable(feature = "rust1", since = "1.0.0")] impl Extend for VecDeque where - [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { fn extend>(&mut self, iter: I) { >::spec_extend(self, iter.into_iter()); @@ -2871,7 +2871,7 @@ where impl<'a, T: 'a + Copy, A: Allocator, const COOP_PREFERRED: bool> Extend<&'a T> for VecDeque where - [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { fn extend>(&mut self, iter: I) { self.spec_extend(iter.into_iter()); @@ -2892,7 +2892,7 @@ where impl fmt::Debug for VecDeque where - [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_list().entries(self.iter()).finish() @@ -2903,7 +2903,7 @@ where impl From> for VecDeque where - [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { /// Turn a [`Vec`] into a [`VecDeque`]. /// @@ -2916,7 +2916,7 @@ where #[inline] fn from(other: Vec) -> Self where - [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::( + [(); alloc::co_alloc_metadata_num_slots_with_preference::( OTHER_COOP_PREFERRED, )]:, { @@ -2929,7 +2929,7 @@ where impl From> for Vec where - [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { /// Turn a [`VecDeque`] into a [`Vec`]. /// diff --git a/library/alloc/src/collections/vec_deque/spec_extend.rs b/library/alloc/src/collections/vec_deque/spec_extend.rs index 973de88ffb172..b1a9d23fd4a99 100644 --- a/library/alloc/src/collections/vec_deque/spec_extend.rs +++ b/library/alloc/src/collections/vec_deque/spec_extend.rs @@ -17,7 +17,7 @@ impl SpecExtend for VecDeque where I: Iterator, - [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { default fn spec_extend(&mut self, mut iter: I) { // This function should be the moral equivalent of: @@ -31,7 +31,7 @@ where deque: &mut VecDeque, element: T, ) where - [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { // SAFETY: Because of the precondition, it's guaranteed that there is space // in the logical array after the last element. @@ -63,7 +63,7 @@ impl SpecExtend for VecDeque where I: TrustedLen, - [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { default fn spec_extend(&mut self, iter: I) { // This is the case for a TrustedLen iterator. @@ -99,7 +99,7 @@ where impl SpecExtend> for VecDeque where - [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { fn spec_extend(&mut self, mut iterator: vec::IntoIter) { let slice = iterator.as_slice(); @@ -118,7 +118,7 @@ impl<'a, T: 'a, I, A: Allocator, const COOP_PREFERRED: bool> SpecExtend<&'a T, I where I: Iterator, T: Copy, - [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { default fn spec_extend(&mut self, iterator: I) { self.spec_extend(iterator.copied()) @@ -129,7 +129,7 @@ impl<'a, T: 'a, A: Allocator, const COOP_PREFERRED: bool> SpecExtend<&'a T, slic for VecDeque where T: Copy, - [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { fn spec_extend(&mut self, iterator: slice::Iter<'a, T>) { let slice = iterator.as_slice(); diff --git a/library/alloc/src/collections/vec_deque/spec_from_iter.rs b/library/alloc/src/collections/vec_deque/spec_from_iter.rs index 086a1fa74566c..85dd756337350 100644 --- a/library/alloc/src/collections/vec_deque/spec_from_iter.rs +++ b/library/alloc/src/collections/vec_deque/spec_from_iter.rs @@ -11,7 +11,7 @@ impl SpecFromIter for VecDeque where I: Iterator, - [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { default fn spec_from_iter(iterator: I) -> Self { // Since converting is O(1) now, just re-use the `Vec` logic for @@ -25,7 +25,7 @@ where impl SpecFromIter> for VecDeque where - [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { #[inline] fn spec_from_iter(iterator: crate::vec::IntoIter) -> Self { @@ -36,7 +36,7 @@ where impl SpecFromIter> for VecDeque where - [(); alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { #[inline] fn spec_from_iter(iterator: IntoIter) -> Self { From 7e059a3c74d91e1bd70ee40ab152712a90673bb2 Mon Sep 17 00:00:00 2001 From: Peter Kehl Date: Sun, 22 Jan 2023 20:58:47 -0800 Subject: [PATCH 040/118] CoAlloc: Vec + Box + Rc: Fixing COOP_PREFERRED (and similar). --- library/alloc/src/boxed.rs | 8 +++++--- library/alloc/src/lib.rs | 2 +- library/alloc/src/rc.rs | 4 ++-- library/alloc/src/vec/drain.rs | 2 +- library/alloc/src/vec/in_place_drop.rs | 3 ++- library/alloc/src/vec/into_iter.rs | 3 ++- library/alloc/src/vec/mod.rs | 20 +++++++++++++------- library/alloc/src/vec/spec_from_elem.rs | 2 +- library/alloc/src/vec/splice.rs | 24 +++++++++++++----------- library/core/src/alloc/mod.rs | 2 +- 10 files changed, 41 insertions(+), 29 deletions(-) diff --git a/library/alloc/src/boxed.rs b/library/alloc/src/boxed.rs index 86e9c96c5f42f..9d455b0568364 100644 --- a/library/alloc/src/boxed.rs +++ b/library/alloc/src/boxed.rs @@ -641,7 +641,8 @@ impl Box<[T]> { #[unstable(feature = "new_uninit", issue = "63291")] #[must_use] pub fn new_uninit_slice(len: usize) -> Box<[mem::MaybeUninit]> { - unsafe { RawVec::with_capacity(len).into_box(len) } + // false = no need for co-alloc metadata, since it would get lost once converted to Box. + unsafe { RawVec::::with_capacity(len).into_box(len) } } /// Constructs a new boxed slice with uninitialized contents, with the memory @@ -666,7 +667,8 @@ impl Box<[T]> { #[unstable(feature = "new_uninit", issue = "63291")] #[must_use] pub fn new_zeroed_slice(len: usize) -> Box<[mem::MaybeUninit]> { - unsafe { RawVec::with_capacity_zeroed(len).into_box(len) } + // false = no need for co-alloc metadata, since it would get lost once converted to Box. + unsafe { RawVec::::with_capacity_zeroed(len).into_box(len) } } /// Constructs a new boxed slice with uninitialized contents. Returns an error if @@ -1687,7 +1689,7 @@ impl TryFrom> for Box<[T; N]> { impl TryFrom> for Box<[T; N]> where - [(); crate::co_alloc_metadata_num_slots_with_preference_global(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { type Error = Vec; diff --git a/library/alloc/src/lib.rs b/library/alloc/src/lib.rs index 9187c24af35b1..3a23176bb7ac4 100644 --- a/library/alloc/src/lib.rs +++ b/library/alloc/src/lib.rs @@ -292,6 +292,6 @@ use crate::alloc::Global; /// See also `core::alloc::co_alloc_metadata_num_slots_with_preference`. #[unstable(feature = "global_co_alloc", issue = "none")] pub const fn co_alloc_metadata_num_slots_with_preference_global(coop_preferred: bool) -> usize { - // FIXME or replace any calls with core::alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED). Then rename co_alloc_metadata_num_slots_with_preference_specific to co_alloc_metadata_num_slots_with_preference. See raw_vec.rs. + // FIXME or replace any calls with core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED). See raw_vec.rs. if /*Global::IS_CO_ALLOCATOR*/ true && coop_preferred { 1 } else { 0 } } diff --git a/library/alloc/src/rc.rs b/library/alloc/src/rc.rs index 8bdc67a35af5f..a14e15549d5be 100644 --- a/library/alloc/src/rc.rs +++ b/library/alloc/src/rc.rs @@ -1989,7 +1989,7 @@ impl From> for Rc { #[stable(feature = "shared_from_slice", since = "1.21.0")] impl From> for Rc<[T]> where - [(); crate::co_alloc_metadata_num_slots_with_preference_global(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { /// Allocate a reference-counted slice and move `v`'s items into it. /// @@ -2004,7 +2004,7 @@ where #[inline] fn from(mut v: Vec) -> Rc<[T]> where - [(); crate::co_alloc_metadata_num_slots_with_preference_global(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { unsafe { let rc = Rc::copy_from_slice(&v); diff --git a/library/alloc/src/vec/drain.rs b/library/alloc/src/vec/drain.rs index 05fee754beec8..a219ca302d4c4 100644 --- a/library/alloc/src/vec/drain.rs +++ b/library/alloc/src/vec/drain.rs @@ -26,7 +26,7 @@ pub struct Drain< #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator + 'a = Global, const COOP_PREFERRED: bool = { SHORT_TERM_VEC_PREFERS_COOP!() }, > where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { /// Index of tail to preserve pub(super) tail_start: usize, diff --git a/library/alloc/src/vec/in_place_drop.rs b/library/alloc/src/vec/in_place_drop.rs index 25ca33c6a7bf0..6788b59f3a020 100644 --- a/library/alloc/src/vec/in_place_drop.rs +++ b/library/alloc/src/vec/in_place_drop.rs @@ -34,6 +34,7 @@ pub(super) struct InPlaceDstBufDrop { impl Drop for InPlaceDstBufDrop { #[inline] fn drop(&mut self) { - unsafe { super::Vec::from_raw_parts(self.ptr, self.len, self.cap) }; + // false = no need for co-alloc metadata, since it would get lost once converted to Box. + unsafe { super::Vec::::from_raw_parts(self.ptr, self.len, self.cap) }; } } diff --git a/library/alloc/src/vec/into_iter.rs b/library/alloc/src/vec/into_iter.rs index 5afb11ee7ba24..569cc61635296 100644 --- a/library/alloc/src/vec/into_iter.rs +++ b/library/alloc/src/vec/into_iter.rs @@ -451,7 +451,8 @@ where // `IntoIter::alloc` is not used anymore after this and will be dropped by RawVec let alloc = ManuallyDrop::take(&mut self.0.alloc); // RawVec handles deallocation - let _ = RawVec::::from_raw_parts_in( + // @FIXME pass true instead of COOP_PREFERRED - use e.g.: if COOP_PREFERRED {let _ = RawVec::::from_raw_parts_in(..) } else { let _ = from_raw_parts_in_coop(...)} } + let _ = RawVec::::from_raw_parts_in( self.0.buf.as_ptr(), self.0.cap, alloc, diff --git a/library/alloc/src/vec/mod.rs b/library/alloc/src/vec/mod.rs index 14b72d53a8457..3d6daca0d3ecf 100644 --- a/library/alloc/src/vec/mod.rs +++ b/library/alloc/src/vec/mod.rs @@ -447,7 +447,7 @@ pub type WeVec = Vec 127 }>; impl Vec where - [(); crate::co_alloc_metadata_num_slots_with_preference_global(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { /// Constructs a new, empty `Vec`. /// @@ -2060,9 +2060,11 @@ where /// assert_eq!(v, &[]); /// ``` #[stable(feature = "drain", since = "1.6.0")] - pub fn drain(&mut self, range: R) -> Drain<'_, T, A> + pub fn drain(&mut self, range: R) -> Drain<'_, T, A, COOP_PREFERRED> where R: RangeBounds, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(SHORT_TERM_VEC_PREFERS_COOP!())]:, + { // Memory safety // @@ -2557,7 +2559,7 @@ where // - `new_cap` refers to the same sized allocation as `cap` because // `new_cap * size_of::()` == `cap * size_of::<[T; N]>()` // - `len` <= `cap`, so `len * N` <= `cap * N`. - unsafe { Vec::::from_raw_parts_in(ptr.cast(), new_len, new_cap, alloc) } + unsafe { Vec::::from_raw_parts_in(ptr.cast(), new_len, new_cap, alloc) } } } @@ -2851,9 +2853,11 @@ impl FromIterator for Vec { impl IntoIterator for Vec where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(SHORT_TERM_VEC_PREFERS_COOP!())]:, + { type Item = T; - type IntoIter = IntoIter; + type IntoIter = IntoIter; /// Creates a consuming iterator, that is, one that moves each value out of /// the vector (from start to end). The vector cannot be used after calling @@ -3045,10 +3049,11 @@ where #[cfg(not(no_global_oom_handling))] #[inline] #[stable(feature = "vec_splice", since = "1.21.0")] - pub fn splice(&mut self, range: R, replace_with: I) -> Splice<'_, I::IntoIter, A> + pub fn splice(&mut self, range: R, replace_with: I) -> Splice<'_, I::IntoIter, A, COOP_PREFERRED> where R: RangeBounds, I: IntoIterator, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(true)]:, { Splice { drain: self.drain(range), replace_with: replace_with.into_iter() } } @@ -3098,9 +3103,10 @@ where /// assert_eq!(odds, vec![1, 3, 5, 9, 11, 13, 15]); /// ``` #[unstable(feature = "drain_filter", reason = "recently added", issue = "43244")] - pub fn drain_filter(&mut self, filter: F) -> DrainFilter<'_, T, F, A> + pub fn drain_filter(&mut self, filter: F) -> DrainFilter<'_, T, F, A, COOP_PREFERRED> where F: FnMut(&mut T) -> bool, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(true)]:, { let old_len = self.len(); @@ -3193,7 +3199,7 @@ where #[rustc_const_unstable(feature = "const_default_impls", issue = "87864")] impl const Default for Vec where - [(); crate::co_alloc_metadata_num_slots_with_preference_global(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { /// Creates an empty `Vec`. /// diff --git a/library/alloc/src/vec/spec_from_elem.rs b/library/alloc/src/vec/spec_from_elem.rs index 3766f6de061bb..bc4169a24f0b2 100644 --- a/library/alloc/src/vec/spec_from_elem.rs +++ b/library/alloc/src/vec/spec_from_elem.rs @@ -14,7 +14,7 @@ pub(super) trait SpecFromElem: Sized { alloc: A, ) -> Vec where - [(); alloc::co_alloc_metadata_num_slots::(COOP_PREFERRED)]:; + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:; } impl SpecFromElem for T { diff --git a/library/alloc/src/vec/splice.rs b/library/alloc/src/vec/splice.rs index d8569a6e89c62..185f09be55287 100644 --- a/library/alloc/src/vec/splice.rs +++ b/library/alloc/src/vec/splice.rs @@ -23,17 +23,19 @@ pub struct Splice< 'a, I: Iterator + 'a, #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator + 'a = Global, + const COOP_PREFERRED: bool = false > where - [(); core::alloc::co_alloc_metadata_num_slots::()]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + //FIXME: If using SHORT_TERM_VEC_PREFERS_COOP!() instead of true, and the same for `drain` below, then this failed with: `derive` cannot be used on item swith type macros { - pub(super) drain: Drain<'a, I::Item, A>, + pub(super) drain: Drain<'a, I::Item, A, COOP_PREFERRED>, pub(super) replace_with: I, } #[stable(feature = "vec_splice", since = "1.21.0")] -impl Iterator for Splice<'_, I, A> +impl Iterator for Splice<'_, I, A, COOP_PREFERRED> where - [(); core::alloc::co_alloc_metadata_num_slots::()]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { type Item = I::Item; @@ -47,9 +49,9 @@ where } #[stable(feature = "vec_splice", since = "1.21.0")] -impl DoubleEndedIterator for Splice<'_, I, A> +impl DoubleEndedIterator for Splice<'_, I, A, COOP_PREFERRED> where - [(); alloc::co_alloc_metadata_num_slots::()]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { fn next_back(&mut self) -> Option { self.drain.next_back() @@ -57,15 +59,15 @@ where } #[stable(feature = "vec_splice", since = "1.21.0")] -impl ExactSizeIterator for Splice<'_, I, A> where - [(); alloc::co_alloc_metadata_num_slots::()]: +impl ExactSizeIterator for Splice<'_, I, A, COOP_PREFERRED> where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { } #[stable(feature = "vec_splice", since = "1.21.0")] -impl Drop for Splice<'_, I, A> +impl Drop for Splice<'_, I, A, COOP_PREFERRED> where - [(); alloc::co_alloc_metadata_num_slots::()]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { fn drop(&mut self) { self.drain.by_ref().for_each(drop); @@ -115,7 +117,7 @@ where /// Private helper methods for `Splice::drop` impl Drain<'_, T, A> where - [(); alloc::co_alloc_metadata_num_slots::()]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(true)]:, { /// The range from `self.vec.len` to `self.tail_start` contains elements /// that have been moved out. diff --git a/library/core/src/alloc/mod.rs b/library/core/src/alloc/mod.rs index 7be3f9cd24b3b..ae4bad73a98ae 100644 --- a/library/core/src/alloc/mod.rs +++ b/library/core/src/alloc/mod.rs @@ -95,7 +95,7 @@ pub type SliceAndMetaResult = Result; pub const fn co_alloc_metadata_num_slots() -> usize { // @FIXME later if false { - panic!("FIXME - consider replacing co_alloc_metadata_num_slots() with co_alloc_metadata_num_slots_with_preference_specific(bool), and adding const flags as appropriate."); + panic!("FIXME - consider replacing co_alloc_metadata_num_slots() with co_alloc_metadata_num_slots_with_preference(bool), and adding const flags as appropriate."); } if A::IS_CO_ALLOCATOR { 1 } else { 0 } } From bd32743aefda3d5ea9ac04a94fb2b0f3b86d63e7 Mon Sep 17 00:00:00 2001 From: Peter Kehl Date: Sun, 22 Jan 2023 20:59:38 -0800 Subject: [PATCH 041/118] CoAlloc: VecDeque: Fixing COOP_PREFERRED (and similar). --- Cargo.lock | 123 +++++++++++------- .../src/collections/vec_deque/into_iter.rs | 30 +++-- .../alloc/src/collections/vec_deque/macros.rs | 2 +- .../alloc/src/collections/vec_deque/mod.rs | 38 +++--- 4 files changed, 119 insertions(+), 74 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3febb21410c79..d02cab38ae8f3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -179,7 +179,7 @@ dependencies = [ "quote", "serde", "syn", - "toml", + "toml 0.5.7", ] [[package]] @@ -291,7 +291,7 @@ dependencies = [ "serde_json", "sha2", "tar", - "toml", + "toml 0.5.7", ] [[package]] @@ -307,7 +307,7 @@ dependencies = [ "indexmap", "serde", "serde_json", - "toml", + "toml 0.5.7", ] [[package]] @@ -408,12 +408,13 @@ dependencies = [ "tempfile", "termcolor", "time 0.3.17", + "toml 0.7.2", "toml_edit", "unicode-width", "unicode-xid", "url", "walkdir", - "winapi", + "windows-sys 0.45.0", ] [[package]] @@ -442,7 +443,7 @@ name = "cargo-credential-wincred" version = "0.2.0" dependencies = [ "cargo-credential", - "winapi", + "windows-sys 0.45.0", ] [[package]] @@ -500,9 +501,9 @@ dependencies = [ "tar", "termcolor", "time 0.3.17", - "toml_edit", + "toml 0.7.2", "url", - "winapi", + "windows-sys 0.45.0", ] [[package]] @@ -522,7 +523,7 @@ dependencies = [ "shell-escape", "tempfile", "walkdir", - "winapi", + "windows-sys 0.45.0", ] [[package]] @@ -755,7 +756,7 @@ dependencies = [ "termize", "tester", "tokio", - "toml", + "toml 0.5.7", "walkdir", ] @@ -789,7 +790,7 @@ dependencies = [ "serde", "serde_json", "tempfile", - "toml", + "toml 0.5.7", "unicode-normalization", "unicode-script", "url", @@ -853,16 +854,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "combine" -version = "4.6.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "35ed6e9d84f0b51a7f52daf1c7d71dd136fd7a3f41a8462b8cdb8c78d920fad4" -dependencies = [ - "bytes", - "memchr", -] - [[package]] name = "commoncrypto" version = "0.2.0" @@ -2224,7 +2215,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "46112a93252b123d31a119a8d1a1ac19deac4fac6e0e8b0df58f0d4e5870e63c" dependencies = [ "libc", - "windows-sys", + "windows-sys 0.42.0", ] [[package]] @@ -2236,7 +2227,7 @@ dependencies = [ "hermit-abi 0.2.6", "io-lifetimes", "rustix", - "windows-sys", + "windows-sys 0.42.0", ] [[package]] @@ -2321,15 +2312,6 @@ dependencies = [ "serde_json", ] -[[package]] -name = "kstring" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec3066350882a1cd6d950d055997f379ac37fd39f81cd4d8ed186032eb3c5747" -dependencies = [ - "static_assertions", -] - [[package]] name = "lazy_static" version = "1.4.0" @@ -2579,7 +2561,7 @@ dependencies = [ "serde_json", "shlex", "tempfile", - "toml", + "toml 0.5.7", "topological-sort", ] @@ -2677,7 +2659,7 @@ version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "52ffbca2f655e33c08be35d87278e5b18b89550a37dbd598c20db92f6a471123" dependencies = [ - "windows-sys", + "windows-sys 0.42.0", ] [[package]] @@ -2725,6 +2707,15 @@ dependencies = [ "version_check", ] +[[package]] +name = "nom8" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae01545c9c7fc4486ab7debaf2aad7003ac19431791868fb2e8066df97fad2f8" +dependencies = [ + "memchr", +] + [[package]] name = "normalize-line-endings" version = "0.3.0" @@ -2994,7 +2985,7 @@ dependencies = [ "libc", "redox_syscall", "smallvec", - "windows-sys", + "windows-sys 0.42.0", ] [[package]] @@ -4906,7 +4897,7 @@ dependencies = [ "serde_json", "term", "thiserror", - "toml", + "toml 0.5.7", "unicode-segmentation", "unicode-width", "unicode_categories", @@ -4923,7 +4914,7 @@ dependencies = [ "io-lifetimes", "libc", "linux-raw-sys", - "windows-sys", + "windows-sys 0.42.0", ] [[package]] @@ -5072,6 +5063,15 @@ dependencies = [ "serde", ] +[[package]] +name = "serde_spanned" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0efd8caf556a6cebd3b285caf480045fcc1ac04f6bd786b09a6f11af30c4fcf4" +dependencies = [ + "serde", +] + [[package]] name = "sha1" version = "0.10.5" @@ -5453,7 +5453,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cb20089a8ba2b69debd491f8d2d023761cbf196e999218c591fa1e7e15a21907" dependencies = [ "rustix", - "windows-sys", + "windows-sys 0.42.0", ] [[package]] @@ -5648,26 +5648,37 @@ dependencies = [ "serde", ] +[[package]] +name = "toml" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7afcae9e3f0fe2c370fd4657108972cbb2fa9db1b9f84849cefd80741b01cb6" +dependencies = [ + "serde", + "serde_spanned", + "toml_datetime", + "toml_edit", +] + [[package]] name = "toml_datetime" -version = "0.5.1" +version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4553f467ac8e3d374bc9a177a26801e5d0f9b211aa1673fb137a403afd1c9cf5" +checksum = "3ab8ed2edee10b50132aed5f331333428b011c99402b5a534154ed15746f9622" dependencies = [ "serde", ] [[package]] name = "toml_edit" -version = "0.15.0" +version = "0.19.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1541ba70885967e662f69d31ab3aeca7b1aaecfcd58679590b893e9239c3646" +checksum = "5e6a7712b49e1775fb9a7b998de6635b299237f48b404dde71704f2e0e7f37e5" dependencies = [ - "combine", "indexmap", - "itertools", - "kstring", + "nom8", "serde", + "serde_spanned", "toml_datetime", ] @@ -6217,6 +6228,30 @@ dependencies = [ "windows_x86_64_msvc", ] +[[package]] +name = "windows-sys" +version = "0.45.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +version = "0.42.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e2522491fbfcd58cc84d47aeb2958948c4b8982e9a2d8a2a35bbaed431390e7" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + [[package]] name = "windows_aarch64_gnullvm" version = "0.42.1" diff --git a/library/alloc/src/collections/vec_deque/into_iter.rs b/library/alloc/src/collections/vec_deque/into_iter.rs index 751be6ec8846d..ce01e81f6b71c 100644 --- a/library/alloc/src/collections/vec_deque/into_iter.rs +++ b/library/alloc/src/collections/vec_deque/into_iter.rs @@ -26,7 +26,7 @@ pub struct IntoIter< impl IntoIter where - [(); alloc::co_alloc_metadata_num_slots::()]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { pub(super) fn new(inner: VecDeque) -> Self { IntoIter { inner } @@ -38,9 +38,9 @@ where } #[stable(feature = "collection_debug", since = "1.17.0")] -impl fmt::Debug for IntoIter +impl fmt::Debug for IntoIter where - [(); alloc::co_alloc_metadata_num_slots::()]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_tuple("IntoIter").field(&self.inner).finish() @@ -48,9 +48,9 @@ where } #[stable(feature = "rust1", since = "1.0.0")] -impl Iterator for IntoIter +impl Iterator for IntoIter where - [(); alloc::co_alloc_metadata_num_slots::()]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { type Item = T; @@ -187,9 +187,9 @@ where } #[stable(feature = "rust1", since = "1.0.0")] -impl DoubleEndedIterator for IntoIter +impl DoubleEndedIterator for IntoIter where - [(); alloc::co_alloc_metadata_num_slots::()]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { #[inline] fn next_back(&mut self) -> Option { @@ -260,8 +260,10 @@ where } #[stable(feature = "rust1", since = "1.0.0")] -impl ExactSizeIterator for IntoIter -where [(); alloc::co_alloc_metadata_num_slots::()]: { +impl ExactSizeIterator for IntoIter +where + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ #[inline] fn is_empty(&self) -> bool { self.inner.is_empty() @@ -269,13 +271,15 @@ where [(); alloc::co_alloc_metadata_num_slots::()]: { } #[stable(feature = "fused", since = "1.26.0")] -impl FusedIterator for IntoIter where - [(); alloc::co_alloc_metadata_num_slots::()]: +impl FusedIterator for IntoIter +where + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { } #[unstable(feature = "trusted_len", issue = "37572")] -unsafe impl TrustedLen for IntoIter where - [(); alloc::co_alloc_metadata_num_slots::()]: +unsafe impl TrustedLen for IntoIter +where + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { } diff --git a/library/alloc/src/collections/vec_deque/macros.rs b/library/alloc/src/collections/vec_deque/macros.rs index 77885e6811a3b..68ee43152b5b5 100644 --- a/library/alloc/src/collections/vec_deque/macros.rs +++ b/library/alloc/src/collections/vec_deque/macros.rs @@ -4,7 +4,7 @@ macro_rules! __impl_slice_eq1 { impl PartialEq<$rhs> for $lhs where T: PartialEq, - [(); core::alloc::co_alloc_metadata_num_slots_with_preference_specific::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, $($constraints)* { fn eq(&self, other: &$rhs) -> bool { diff --git a/library/alloc/src/collections/vec_deque/mod.rs b/library/alloc/src/collections/vec_deque/mod.rs index 2b6f14be0f52d..01b49efcab4a4 100644 --- a/library/alloc/src/collections/vec_deque/mod.rs +++ b/library/alloc/src/collections/vec_deque/mod.rs @@ -161,7 +161,7 @@ where #[stable(feature = "rust1", since = "1.0.0")] impl Default for VecDeque where - [(); crate::co_alloc_metadata_num_slots_with_preference_global(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { /// Creates an empty deque. #[inline] @@ -568,7 +568,9 @@ where #[stable(feature = "rust1", since = "1.0.0")] #[rustc_const_stable(feature = "const_vec_deque_new", since = "1.68.0")] #[must_use] - pub const fn new() -> VecDeque { + pub const fn new() -> VecDeque + where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + { // FIXME: This should just be `VecDeque::new_in(Global)` once that hits stable. VecDeque { head: 0, len: 0, buf: RawVec::NEW } } @@ -1403,6 +1405,7 @@ where pub fn drain(&mut self, range: R) -> Drain<'_, T, A> where R: RangeBounds, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(SHORT_TERM_VEC_PREFERS_COOP!())]:, { // Memory safety // @@ -2799,7 +2802,7 @@ impl FromIterator for VecDeque(COOP_PREFERRED)]:, { - fn from_iter>(iter: I) -> VecDeque { + fn from_iter>(iter: I) -> VecDeque { SpecFromIter::spec_from_iter(iter.into_iter()) } } @@ -2810,11 +2813,11 @@ where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { type Item = T; - type IntoIter = IntoIter; + type IntoIter = IntoIter; /// Consumes the deque into a front-to-back iterator yielding elements by /// value. - fn into_iter(self) -> IntoIter { + fn into_iter(self) -> IntoIter { IntoIter::new(self) } } @@ -2900,10 +2903,13 @@ where } #[stable(feature = "vecdeque_vec_conversions", since = "1.10.0")] -impl From> +impl From> for VecDeque where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::( + OTHER_COOP_PREFERRED, + )]:, { /// Turn a [`Vec`] into a [`VecDeque`]. /// @@ -2914,11 +2920,7 @@ where /// and to not re-allocate the `Vec`'s buffer or allocate /// any additional memory. #[inline] - fn from(other: Vec) -> Self - where - [(); alloc::co_alloc_metadata_num_slots_with_preference::( - OTHER_COOP_PREFERRED, - )]:, + fn from(other: Vec) -> Self { let (ptr, len, cap, alloc) = other.into_raw_parts_with_alloc(); Self { head: 0, len, buf: unsafe { RawVec::from_raw_parts_in(ptr, cap, alloc) } } @@ -2926,10 +2928,11 @@ where } #[stable(feature = "vecdeque_vec_conversions", since = "1.10.0")] -impl From> +impl From> for Vec where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(VECDEQUE_COOP_PREFERRED)]:, { /// Turn a [`VecDeque`] into a [`Vec`]. /// @@ -2960,9 +2963,12 @@ where /// assert_eq!(vec, [8, 9, 1, 2, 3, 4]); /// assert_eq!(vec.as_ptr(), ptr); /// ``` - fn from( - mut other: VecDeque, - ) -> Self { + fn from( + mut other: VecDeque, + ) -> Self + where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(VECDEQUE_COOP_PREFERRED)]:, + { other.make_contiguous(); unsafe { @@ -2985,7 +2991,7 @@ where impl From<[T; N]> for VecDeque where - [(); crate::co_alloc_metadata_num_slots_with_preference_global(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { /// Converts a `[T; N]` into a `VecDeque`. /// From 3d985378079d8c8b2c5f93d61f8c63c6a451a8ea Mon Sep 17 00:00:00 2001 From: Peter Kehl Date: Sun, 22 Jan 2023 21:00:01 -0800 Subject: [PATCH 042/118] CoAlloc: BinaryHeap: Fixing COOP_PREFERRED (and similar). --- .../alloc/src/collections/binary_heap/mod.rs | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/library/alloc/src/collections/binary_heap/mod.rs b/library/alloc/src/collections/binary_heap/mod.rs index bc08a604b8cd0..1290a449facd2 100644 --- a/library/alloc/src/collections/binary_heap/mod.rs +++ b/library/alloc/src/collections/binary_heap/mod.rs @@ -1527,7 +1527,7 @@ unsafe impl TrustedLen for IntoIterSorted {} #[derive(Debug)] pub struct Drain<'a, T: 'a, const COOP_PREFERRED: bool> where - [(); crate::co_alloc_metadata_num_slots_with_preference_global(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { iter: vec::Drain<'a, T, Global, COOP_PREFERRED>, } @@ -1535,7 +1535,7 @@ where #[stable(feature = "drain", since = "1.6.0")] impl Iterator for Drain<'_, T, COOP_PREFERRED> where - [(); crate::co_alloc_metadata_num_slots_with_preference_global(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { type Item = T; @@ -1551,7 +1551,10 @@ where } #[stable(feature = "drain", since = "1.6.0")] -impl DoubleEndedIterator for Drain<'_, T, COOP_PREFERRED> { +impl DoubleEndedIterator for Drain<'_, T, COOP_PREFERRED> +where + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ #[inline] fn next_back(&mut self) -> Option { self.iter.next_back() @@ -1559,14 +1562,20 @@ impl DoubleEndedIterator for Drain<'_, T, COOP_PR } #[stable(feature = "drain", since = "1.6.0")] -impl ExactSizeIterator for Drain<'_, T, COOP_PREFERRED> { +impl ExactSizeIterator for Drain<'_, T, COOP_PREFERRED> +where + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ fn is_empty(&self) -> bool { self.iter.is_empty() } } #[stable(feature = "fused", since = "1.26.0")] -impl FusedIterator for Drain<'_, T, COOP_PREFERRED> {} +impl FusedIterator for Drain<'_, T, COOP_PREFERRED> +where + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{} /// A draining iterator over the elements of a `BinaryHeap`. /// From 01f915ed06f30ce3e7ebbe033856613a81fb329d Mon Sep 17 00:00:00 2001 From: Peter Kehl Date: Sun, 22 Jan 2023 21:02:00 -0800 Subject: [PATCH 043/118] CoAlloc: Vec + Box: Fixing COOP_PREFERRED. --- library/alloc/src/boxed.rs | 18 +++++++++++++----- library/alloc/src/vec/in_place_drop.rs | 1 + library/alloc/src/vec/mod.rs | 8 ++++++-- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/library/alloc/src/boxed.rs b/library/alloc/src/boxed.rs index 9d455b0568364..32277063ac0b0 100644 --- a/library/alloc/src/boxed.rs +++ b/library/alloc/src/boxed.rs @@ -778,7 +778,10 @@ where // #[unstable(feature = "new_uninit", issue = "63291")] #[must_use] #[allow(unused_braces)] - pub fn new_uninit_slice_in(len: usize, alloc: A) -> Box<[mem::MaybeUninit], A> { + pub fn new_uninit_slice_in(len: usize, alloc: A) -> Box<[mem::MaybeUninit], A> + where + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(SHORT_TERM_VEC_PREFERS_COOP!())]:, + { unsafe { RawVec::::with_capacity_in(len, alloc) .into_box(len) @@ -810,7 +813,10 @@ where // #[unstable(feature = "new_uninit", issue = "63291")] #[must_use] #[allow(unused_braces)] - pub fn new_zeroed_slice_in(len: usize, alloc: A) -> Box<[mem::MaybeUninit], A> { + pub fn new_zeroed_slice_in(len: usize, alloc: A) -> Box<[mem::MaybeUninit], A> + where + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(SHORT_TERM_VEC_PREFERS_COOP!())]:, + { unsafe { RawVec::::with_capacity_zeroed_in( len, alloc, @@ -1521,7 +1527,8 @@ impl From<&[T]> for Box<[T]> { /// ``` fn from(slice: &[T]) -> Box<[T]> { let len = slice.len(); - let buf = RawVec::with_capacity(len); + // false = no need for co-alloc metadata, since it would get lost once converted to Box. + let buf = RawVec::::with_capacity(len); unsafe { ptr::copy_nonoverlapping(slice.as_ptr(), buf.ptr(), len); buf.into_box(slice.len()).assume_init() @@ -2050,11 +2057,12 @@ impl FromIterator for Box<[I]> { #[stable(feature = "box_slice_clone", since = "1.3.0")] impl Clone for Box<[T], A> where - [(); core::alloc::co_alloc_metadata_num_slots::()]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(false)]:, { fn clone(&self) -> Self { let alloc = Box::allocator(self).clone(); - self.to_vec_in(alloc).into_boxed_slice() + // false = no need for co-alloc metadata, since it would get lost once converted to the boxed slice. + self.to_vec_in::(alloc).into_boxed_slice() } fn clone_from(&mut self, other: &Self) { diff --git a/library/alloc/src/vec/in_place_drop.rs b/library/alloc/src/vec/in_place_drop.rs index 6788b59f3a020..871fd08b1f6b1 100644 --- a/library/alloc/src/vec/in_place_drop.rs +++ b/library/alloc/src/vec/in_place_drop.rs @@ -1,5 +1,6 @@ use core::ptr::{self}; use core::slice::{self}; +use crate::alloc::Global; // A helper struct for in-place iteration that drops the destination slice of iteration, // i.e. the head. The source slice (the tail) is dropped by IntoIter. diff --git a/library/alloc/src/vec/mod.rs b/library/alloc/src/vec/mod.rs index 3d6daca0d3ecf..9923bc298f3c7 100644 --- a/library/alloc/src/vec/mod.rs +++ b/library/alloc/src/vec/mod.rs @@ -54,6 +54,7 @@ #![stable(feature = "rust1", since = "1.0.0")] #[cfg(not(no_global_oom_handling))] +use core::alloc; use core::cmp; use core::cmp::Ordering; use core::convert::TryFrom; @@ -2842,9 +2843,12 @@ where #[cfg(not(no_global_oom_handling))] #[stable(feature = "rust1", since = "1.0.0")] #[allow(unused_braces)] -impl FromIterator for Vec { +impl FromIterator for Vec +where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + { #[inline] - fn from_iter>(iter: I) -> Vec { + fn from_iter>(iter: I) -> Vec { >::from_iter(iter.into_iter()) } } From efa9f7b2c500e7bfbf3ef659b661f0e9393e329c Mon Sep 17 00:00:00 2001 From: Peter Kehl Date: Sun, 22 Jan 2023 21:02:46 -0800 Subject: [PATCH 044/118] CoAlloc: VecDeque: Fixing COOP_PREFERRED. --- library/alloc/src/collections/vec_deque/spec_from_iter.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/alloc/src/collections/vec_deque/spec_from_iter.rs b/library/alloc/src/collections/vec_deque/spec_from_iter.rs index 85dd756337350..b9f77ffa07503 100644 --- a/library/alloc/src/collections/vec_deque/spec_from_iter.rs +++ b/library/alloc/src/collections/vec_deque/spec_from_iter.rs @@ -18,7 +18,7 @@ where // anything where we can't do something extra-special for `VecDeque`, // especially as that could save us some monomorphiziation work // if one uses the same iterators (like slice ones) with both. - crate::vec::Vec::from_iter(iterator).into() + crate::vec::Vec::::from_iter(iterator).into() } } From 66199e3ef777a166139c0a5da9fa118f32679832 Mon Sep 17 00:00:00 2001 From: Peter Kehl Date: Sun, 22 Jan 2023 21:03:37 -0800 Subject: [PATCH 045/118] CoAlloc: Vec: Fixing COOP_PREFERRED. --- library/alloc/src/vec/in_place_collect.rs | 8 ++++---- library/alloc/src/vec/spec_from_iter.rs | 11 +++++++---- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/library/alloc/src/vec/in_place_collect.rs b/library/alloc/src/vec/in_place_collect.rs index 6f3c44a8aa8b6..6d9e3b825c376 100644 --- a/library/alloc/src/vec/in_place_collect.rs +++ b/library/alloc/src/vec/in_place_collect.rs @@ -137,13 +137,11 @@ //! } //! vec.truncate(write_idx); //! ``` +use core::alloc::{self, Allocator}; use core::iter::{InPlaceIterable, SourceIter, TrustedRandomAccessNoCoerce}; use core::mem::{self, ManuallyDrop, SizedTypeProperties}; use core::ptr::{self}; -use crate::Global; -use crate::DEFAULT_COOP_PREFERRED; - use super::{InPlaceDrop, InPlaceDstBufDrop, SpecFromIter, SpecFromIterNested, Vec}; /// Specialization marker for collecting an iterator pipeline into a Vec while reusing the @@ -154,9 +152,11 @@ pub(super) trait InPlaceIterableMarker {} impl InPlaceIterableMarker for T where T: InPlaceIterable {} #[allow(unused_braces)] -impl SpecFromIter for Vec +impl SpecFromIter for Vec where I: Iterator + SourceIter + InPlaceIterableMarker, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + { default fn from_iter(mut iterator: I) -> Self { // See "Layout constraints" section in the module documentation. We rely on const diff --git a/library/alloc/src/vec/spec_from_iter.rs b/library/alloc/src/vec/spec_from_iter.rs index 06da451fe3932..9ed63aceb77a0 100644 --- a/library/alloc/src/vec/spec_from_iter.rs +++ b/library/alloc/src/vec/spec_from_iter.rs @@ -1,7 +1,6 @@ +use core::alloc::{self, Allocator}; use core::mem::ManuallyDrop; use core::ptr::{self}; -use crate::Global; -use crate::DEFAULT_COOP_PREFERRED; use super::{IntoIter, SpecExtend, SpecFromIterNested, Vec}; @@ -28,9 +27,10 @@ pub(super) trait SpecFromIter { } #[allow(unused_braces)] -impl SpecFromIter for Vec +impl SpecFromIter for Vec where I: Iterator, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { default fn from_iter(iterator: I) -> Self { SpecFromIterNested::from_iter(iterator) @@ -38,7 +38,10 @@ where } #[allow(unused_braces)] -impl SpecFromIter> for Vec { +impl SpecFromIter> for Vec +where +[(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ fn from_iter(iterator: IntoIter) -> Self { // A common case is passing a vector into a function which immediately // re-collects into a vector. We can short circuit this if the IntoIter From a0497c5f467de4dbcbefa43ea2869b5c61adecd0 Mon Sep 17 00:00:00 2001 From: Peter Kehl Date: Sun, 22 Jan 2023 21:04:21 -0800 Subject: [PATCH 046/118] CoAlloc: VecDeque: Fixing COOP_PREFERRED. --- library/alloc/src/collections/vec_deque/spec_from_iter.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/library/alloc/src/collections/vec_deque/spec_from_iter.rs b/library/alloc/src/collections/vec_deque/spec_from_iter.rs index b9f77ffa07503..fe5a1f169f56f 100644 --- a/library/alloc/src/collections/vec_deque/spec_from_iter.rs +++ b/library/alloc/src/collections/vec_deque/spec_from_iter.rs @@ -22,18 +22,18 @@ where } } -impl SpecFromIter> +impl SpecFromIter> for VecDeque where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { #[inline] - fn spec_from_iter(iterator: crate::vec::IntoIter) -> Self { + fn spec_from_iter(iterator: crate::vec::IntoIter) -> Self { iterator.into_vecdeque() } } -impl SpecFromIter> +impl SpecFromIter> for VecDeque where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, From d3e561f278970194b83b31121960654c455375c2 Mon Sep 17 00:00:00 2001 From: Peter Kehl Date: Sun, 22 Jan 2023 21:06:06 -0800 Subject: [PATCH 047/118] CoAlloc: VecDeque: Fixing COOP_PREFERRED --- library/alloc/src/collections/vec_deque/mod.rs | 15 ++++++++------- .../src/collections/vec_deque/spec_from_iter.rs | 2 +- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/library/alloc/src/collections/vec_deque/mod.rs b/library/alloc/src/collections/vec_deque/mod.rs index 01b49efcab4a4..bef0dcf986f4a 100644 --- a/library/alloc/src/collections/vec_deque/mod.rs +++ b/library/alloc/src/collections/vec_deque/mod.rs @@ -166,7 +166,7 @@ where /// Creates an empty deque. #[inline] fn default() -> VecDeque { - VecDeque::new() + VecDeque::::new() } } @@ -554,6 +554,7 @@ where impl VecDeque where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { /// Creates an empty deque. /// @@ -587,8 +588,8 @@ where #[inline] #[stable(feature = "rust1", since = "1.0.0")] #[must_use] - pub fn with_capacity(capacity: usize) -> VecDeque { - Self::with_capacity_in(capacity, Global) + pub fn with_capacity(capacity: usize) -> VecDeque { + VecDeque::::with_capacity_in(capacity, Global) } } @@ -1402,7 +1403,7 @@ where /// ``` #[inline] #[stable(feature = "drain", since = "1.6.0")] - pub fn drain(&mut self, range: R) -> Drain<'_, T, A> + pub fn drain(&mut self, range: R) -> Drain<'_, T, A, COOP_PREFERRED> where R: RangeBounds, [(); alloc::co_alloc_metadata_num_slots_with_preference::(SHORT_TERM_VEC_PREFERS_COOP!())]:, @@ -2923,7 +2924,7 @@ where fn from(other: Vec) -> Self { let (ptr, len, cap, alloc) = other.into_raw_parts_with_alloc(); - Self { head: 0, len, buf: unsafe { RawVec::from_raw_parts_in(ptr, cap, alloc) } } + Self { head: 0, len, buf: unsafe { RawVec::::from_raw_parts_in(ptr, cap, alloc) } } } } @@ -2982,7 +2983,7 @@ where ptr::copy(buf.add(other.head), buf, len); } // @FIXME: COOP - Vec::from_raw_parts_in(buf, len, cap, alloc) + Vec::::from_raw_parts_in(buf, len, cap, alloc) } } } @@ -3003,7 +3004,7 @@ where /// assert_eq!(deq1, deq2); /// ``` fn from(arr: [T; N]) -> Self { - let mut deq = VecDeque::with_capacity(N); + let mut deq = VecDeque::::with_capacity(N); let arr = ManuallyDrop::new(arr); if !::IS_ZST { // SAFETY: VecDeque::with_capacity ensures that there is enough capacity. diff --git a/library/alloc/src/collections/vec_deque/spec_from_iter.rs b/library/alloc/src/collections/vec_deque/spec_from_iter.rs index fe5a1f169f56f..450a64b792c5b 100644 --- a/library/alloc/src/collections/vec_deque/spec_from_iter.rs +++ b/library/alloc/src/collections/vec_deque/spec_from_iter.rs @@ -39,7 +39,7 @@ where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { #[inline] - fn spec_from_iter(iterator: IntoIter) -> Self { + fn spec_from_iter(iterator: IntoIter) -> Self { iterator.into_vecdeque() } } From f5efcd5096ed44feda00d4cf65f0fb6fb929646d Mon Sep 17 00:00:00 2001 From: Peter Kehl Date: Sun, 22 Jan 2023 21:06:57 -0800 Subject: [PATCH 048/118] CoAlloc: Slice: Fixing COOP_PREFERRED --- library/alloc/src/slice.rs | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/library/alloc/src/slice.rs b/library/alloc/src/slice.rs index 48d218ea28602..28e9a464e9733 100644 --- a/library/alloc/src/slice.rs +++ b/library/alloc/src/slice.rs @@ -933,12 +933,48 @@ where } }; +//<<<<<<< HEAD let run_alloc_fn = |len: usize| -> *mut sort::TimSortRun { // SAFETY: Creating the layout is safe as long as merge_sort never calls this with an // obscene length or 0. unsafe { alloc::alloc(alloc::Layout::array::(len).unwrap_unchecked()) as *mut sort::TimSortRun +/*======= + // Allocate a buffer to use as scratch memory. We keep the length 0 so we can keep in it + // shallow copies of the contents of `v` without risking the dtors running on copies if + // `is_less` panics. When merging two sorted runs, this buffer holds a copy of the shorter run, + // which will always have length at most `len / 2`. + // `buf` is temporary = not passed around too much => using COOP_PREFERRED=true. + // @FIXME move definitions of `buf` and `runs` down, after while end > 0 {...}, just before they are used. Then benchmark if it makes (cache-related) difference. + let mut buf = Vec::::with_capacity(len / 2); + + // In order to identify natural runs in `v`, we traverse it backwards. That might seem like a + // strange decision, but consider the fact that merges more often go in the opposite direction + // (forwards). According to benchmarks, merging forwards is slightly faster than merging + // backwards. To conclude, identifying runs by traversing backwards improves performance. + // `runs` is temporary = not passed around too much => using COOP_PREFERRED=true. + let mut runs: Vec<_, Global, true> = vec![]; + let mut end = len; + while end > 0 { + // Find the next natural run, and reverse it if it's strictly descending. + let mut start = end - 1; + if start > 0 { + start -= 1; + unsafe { + if is_less(v.get_unchecked(start + 1), v.get_unchecked(start)) { + while start > 0 && is_less(v.get_unchecked(start), v.get_unchecked(start - 1)) { + start -= 1; + } + v[start..end].reverse(); + } else { + while start > 0 && !is_less(v.get_unchecked(start), v.get_unchecked(start - 1)) + { + start -= 1; + } + } + } +>>>>>>> 6bd68177557 (CoAlloc: Slice: Fixing COOP_PREFERRED)*/ } }; From 246424fca4d9da82ea51a641fa1c32aa77683774 Mon Sep 17 00:00:00 2001 From: Peter Kehl Date: Sun, 22 Jan 2023 21:08:03 -0800 Subject: [PATCH 049/118] CoAlloc: Vec: Fixing COOP_PREFERRED --- library/alloc/src/vec/mod.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/library/alloc/src/vec/mod.rs b/library/alloc/src/vec/mod.rs index 9923bc298f3c7..ae9380205c59c 100644 --- a/library/alloc/src/vec/mod.rs +++ b/library/alloc/src/vec/mod.rs @@ -424,6 +424,7 @@ pub type CoVec; /// "Plain" Vec. Not "cooperative" - not carrying extra data to assist the allocator. +/// FIXME after cleanup, see if we still use this in core:: and/or alloc:: #[unstable(feature = "global_co_alloc_plvec", issue = "none")] pub type PlVec = Vec; From d540eef53d9ae5b666983c044ba7596d51f7006a Mon Sep 17 00:00:00 2001 From: Peter Kehl Date: Sun, 22 Jan 2023 21:09:48 -0800 Subject: [PATCH 050/118] CoAlloc: minor cleanup --- library/alloc/src/lib.rs | 6 ------ 1 file changed, 6 deletions(-) diff --git a/library/alloc/src/lib.rs b/library/alloc/src/lib.rs index 3a23176bb7ac4..9474166ab0234 100644 --- a/library/alloc/src/lib.rs +++ b/library/alloc/src/lib.rs @@ -289,9 +289,3 @@ pub(crate) mod test_helpers { use crate::alloc::Global; -/// See also `core::alloc::co_alloc_metadata_num_slots_with_preference`. -#[unstable(feature = "global_co_alloc", issue = "none")] -pub const fn co_alloc_metadata_num_slots_with_preference_global(coop_preferred: bool) -> usize { - // FIXME or replace any calls with core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED). See raw_vec.rs. - if /*Global::IS_CO_ALLOCATOR*/ true && coop_preferred { 1 } else { 0 } -} From ecae4ef668306bb4faae2a1c5b2761a01f2ac546 Mon Sep 17 00:00:00 2001 From: Peter Kehl Date: Sun, 22 Jan 2023 21:10:07 -0800 Subject: [PATCH 051/118] CoAlloc: Vec: COOP_PREFERRED --- library/alloc/src/vec/spec_from_iter.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/library/alloc/src/vec/spec_from_iter.rs b/library/alloc/src/vec/spec_from_iter.rs index 9ed63aceb77a0..2da172c8ea499 100644 --- a/library/alloc/src/vec/spec_from_iter.rs +++ b/library/alloc/src/vec/spec_from_iter.rs @@ -1,4 +1,5 @@ use core::alloc::{self, Allocator}; +use crate::alloc::Global; use core::mem::ManuallyDrop; use core::ptr::{self}; @@ -38,9 +39,9 @@ where } #[allow(unused_braces)] -impl SpecFromIter> for Vec +impl SpecFromIter> for Vec where -[(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +[(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { fn from_iter(iterator: IntoIter) -> Self { // A common case is passing a vector into a function which immediately @@ -62,7 +63,7 @@ where } } - let mut vec = Vec::new(); + let mut vec = Vec::::new(); // must delegate to spec_extend() since extend() itself delegates // to spec_from for empty Vecs vec.spec_extend(iterator); From 1a8ded6f74961b4ffce6e56a18f69dc6102105d7 Mon Sep 17 00:00:00 2001 From: Peter Kehl Date: Sun, 22 Jan 2023 21:11:33 -0800 Subject: [PATCH 052/118] CoAlloc: Vec: COOP_PREFERRED --- library/alloc/src/vec/in_place_collect.rs | 7 ++++--- library/alloc/src/vec/into_iter.rs | 2 +- library/alloc/src/vec/mod.rs | 6 +++--- library/alloc/src/vec/spec_from_iter.rs | 6 +++--- library/alloc/src/vec/spec_from_iter_nested.rs | 6 ++++-- 5 files changed, 15 insertions(+), 12 deletions(-) diff --git a/library/alloc/src/vec/in_place_collect.rs b/library/alloc/src/vec/in_place_collect.rs index 6d9e3b825c376..69f8ea9a61d3b 100644 --- a/library/alloc/src/vec/in_place_collect.rs +++ b/library/alloc/src/vec/in_place_collect.rs @@ -137,7 +137,8 @@ //! } //! vec.truncate(write_idx); //! ``` -use core::alloc::{self, Allocator}; +use core::alloc; +use crate::alloc::Global; use core::iter::{InPlaceIterable, SourceIter, TrustedRandomAccessNoCoerce}; use core::mem::{self, ManuallyDrop, SizedTypeProperties}; use core::ptr::{self}; @@ -152,10 +153,10 @@ pub(super) trait InPlaceIterableMarker {} impl InPlaceIterableMarker for T where T: InPlaceIterable {} #[allow(unused_braces)] -impl SpecFromIter for Vec +impl SpecFromIter for Vec where I: Iterator + SourceIter + InPlaceIterableMarker, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { default fn from_iter(mut iterator: I) -> Self { diff --git a/library/alloc/src/vec/into_iter.rs b/library/alloc/src/vec/into_iter.rs index 569cc61635296..9e54f6db5d34b 100644 --- a/library/alloc/src/vec/into_iter.rs +++ b/library/alloc/src/vec/into_iter.rs @@ -421,7 +421,7 @@ where { #[cfg(not(test))] fn clone(&self) -> Self { - self.as_slice().to_vec_in(self.alloc.deref().clone()).into_iter() + self.as_slice().to_vec_in::(self.alloc.deref().clone()).into_iter() } #[cfg(test)] fn clone(&self) -> Self { diff --git a/library/alloc/src/vec/mod.rs b/library/alloc/src/vec/mod.rs index ae9380205c59c..2c4d5012c3282 100644 --- a/library/alloc/src/vec/mod.rs +++ b/library/alloc/src/vec/mod.rs @@ -2844,12 +2844,12 @@ where #[cfg(not(no_global_oom_handling))] #[stable(feature = "rust1", since = "1.0.0")] #[allow(unused_braces)] -impl FromIterator for Vec +impl FromIterator for Vec where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { #[inline] - fn from_iter>(iter: I) -> Vec { + fn from_iter>(iter: I) -> Vec { >::from_iter(iter.into_iter()) } } diff --git a/library/alloc/src/vec/spec_from_iter.rs b/library/alloc/src/vec/spec_from_iter.rs index 2da172c8ea499..6f414082ab292 100644 --- a/library/alloc/src/vec/spec_from_iter.rs +++ b/library/alloc/src/vec/spec_from_iter.rs @@ -1,4 +1,4 @@ -use core::alloc::{self, Allocator}; +use core::alloc; use crate::alloc::Global; use core::mem::ManuallyDrop; use core::ptr::{self}; @@ -28,10 +28,10 @@ pub(super) trait SpecFromIter { } #[allow(unused_braces)] -impl SpecFromIter for Vec +impl SpecFromIter for Vec where I: Iterator, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { default fn from_iter(iterator: I) -> Self { SpecFromIterNested::from_iter(iterator) diff --git a/library/alloc/src/vec/spec_from_iter_nested.rs b/library/alloc/src/vec/spec_from_iter_nested.rs index 7408155ff870a..bbfb9605a6d00 100644 --- a/library/alloc/src/vec/spec_from_iter_nested.rs +++ b/library/alloc/src/vec/spec_from_iter_nested.rs @@ -1,3 +1,4 @@ +use core::alloc; use core::cmp; use core::iter::TrustedLen; use core::ptr; @@ -16,9 +17,10 @@ pub(super) trait SpecFromIterNested { } #[allow(unused_braces)] -impl SpecFromIterNested for Vec +impl SpecFromIterNested for Vec where I: Iterator, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { default fn from_iter(mut iterator: I) -> Self { // Unroll the first iteration, as the vector is going to be @@ -43,7 +45,7 @@ where }; // must delegate to spec_extend() since extend() itself delegates // to spec_from for empty Vecs - as SpecExtend>::spec_extend(&mut vector, iterator); + as SpecExtend>::spec_extend(&mut vector, iterator); vector } } From 22a782c3bcf0694589f3ad7cdbe05110c55e1147 Mon Sep 17 00:00:00 2001 From: Peter Kehl Date: Sun, 22 Jan 2023 21:11:42 -0800 Subject: [PATCH 053/118] CoAlloc: VecDeque: COOP_PREFERRED --- .../alloc/src/collections/vec_deque/mod.rs | 6 ++--- .../collections/vec_deque/spec_from_iter.rs | 26 +++++++++---------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/library/alloc/src/collections/vec_deque/mod.rs b/library/alloc/src/collections/vec_deque/mod.rs index bef0dcf986f4a..d1e63ee155fa9 100644 --- a/library/alloc/src/collections/vec_deque/mod.rs +++ b/library/alloc/src/collections/vec_deque/mod.rs @@ -2799,11 +2799,11 @@ where } #[stable(feature = "rust1", since = "1.0.0")] -impl FromIterator for VecDeque +impl FromIterator for VecDeque where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { - fn from_iter>(iter: I) -> VecDeque { + fn from_iter>(iter: I) -> VecDeque { SpecFromIter::spec_from_iter(iter.into_iter()) } } diff --git a/library/alloc/src/collections/vec_deque/spec_from_iter.rs b/library/alloc/src/collections/vec_deque/spec_from_iter.rs index 450a64b792c5b..ecfe79799aa91 100644 --- a/library/alloc/src/collections/vec_deque/spec_from_iter.rs +++ b/library/alloc/src/collections/vec_deque/spec_from_iter.rs @@ -1,5 +1,5 @@ use super::{IntoIter, VecDeque}; -use crate::alloc::Allocator; +use crate::Global; use core::alloc; /// Specialization trait used for `VecDeque::from_iter` @@ -7,39 +7,39 @@ pub(super) trait SpecFromIter { fn spec_from_iter(iter: I) -> Self; } -impl SpecFromIter - for VecDeque +impl SpecFromIter + for VecDeque where I: Iterator, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { default fn spec_from_iter(iterator: I) -> Self { // Since converting is O(1) now, just re-use the `Vec` logic for // anything where we can't do something extra-special for `VecDeque`, // especially as that could save us some monomorphiziation work // if one uses the same iterators (like slice ones) with both. - crate::vec::Vec::::from_iter(iterator).into() + crate::vec::Vec::::from_iter(iterator).into() } } -impl SpecFromIter> - for VecDeque +impl SpecFromIter> + for VecDeque where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { #[inline] - fn spec_from_iter(iterator: crate::vec::IntoIter) -> Self { + fn spec_from_iter(iterator: crate::vec::IntoIter) -> Self { iterator.into_vecdeque() } } -impl SpecFromIter> - for VecDeque +impl SpecFromIter> + for VecDeque where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { #[inline] - fn spec_from_iter(iterator: IntoIter) -> Self { + fn spec_from_iter(iterator: IntoIter) -> Self { iterator.into_vecdeque() } } From 3bf7d99dbb6aac8952e1ce02c69f09ddbea2ea7b Mon Sep 17 00:00:00 2001 From: Peter Kehl Date: Sun, 22 Jan 2023 21:12:32 -0800 Subject: [PATCH 054/118] CoAlloc: library/alloc: minor cleanup --- library/alloc/src/lib.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/library/alloc/src/lib.rs b/library/alloc/src/lib.rs index 9474166ab0234..1138d6f566d11 100644 --- a/library/alloc/src/lib.rs +++ b/library/alloc/src/lib.rs @@ -287,5 +287,4 @@ pub(crate) mod test_helpers { rand::SeedableRng::from_seed(seed) } -use crate::alloc::Global; From e970674b3954286ae6182e860084d007e8f96d79 Mon Sep 17 00:00:00 2001 From: Peter Kehl Date: Sun, 22 Jan 2023 21:13:28 -0800 Subject: [PATCH 055/118] CoAlloc: library/alloc: Re-added a closing curly bracket in mod test_helpers = Fixing my earlier merge mess up. --- library/alloc/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/alloc/src/lib.rs b/library/alloc/src/lib.rs index 1138d6f566d11..44c862d7e6485 100644 --- a/library/alloc/src/lib.rs +++ b/library/alloc/src/lib.rs @@ -286,5 +286,5 @@ pub(crate) mod test_helpers { let seed: [u8; 16] = seed_vec.as_slice().try_into().unwrap(); rand::SeedableRng::from_seed(seed) } - +} From 22cacd4c580c190bf4fc156822bd96a2b1300c42 Mon Sep 17 00:00:00 2001 From: Peter Kehl Date: Sun, 22 Jan 2023 21:24:22 -0800 Subject: [PATCH 056/118] CoAlloc: Vec + slice: COOP_PREFERRED --- library/alloc/src/slice.rs | 7 +++++-- library/alloc/src/vec/spec_from_iter_nested.rs | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/library/alloc/src/slice.rs b/library/alloc/src/slice.rs index 28e9a464e9733..d07564d40bccc 100644 --- a/library/alloc/src/slice.rs +++ b/library/alloc/src/slice.rs @@ -456,11 +456,14 @@ impl [T] { #[rustc_conversion_suggestion] #[stable(feature = "rust1", since = "1.0.0")] #[inline] - pub fn to_vec(&self) -> Vec + pub fn to_vec(&self) -> Vec where T: Clone, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::( + COOP_PREFERRED, + )]:, { - self.to_vec_in(Global) + self.to_vec_in::(Global) } /// Copies `self` into a new `Vec` with an allocator. diff --git a/library/alloc/src/vec/spec_from_iter_nested.rs b/library/alloc/src/vec/spec_from_iter_nested.rs index bbfb9605a6d00..3ccd2da20df49 100644 --- a/library/alloc/src/vec/spec_from_iter_nested.rs +++ b/library/alloc/src/vec/spec_from_iter_nested.rs @@ -4,7 +4,7 @@ use core::iter::TrustedLen; use core::ptr; use crate::raw_vec::RawVec; -use crate::Global; +use crate::alloc::Global; use crate::DEFAULT_COOP_PREFERRED; use super::{SpecExtend, Vec}; From 6e528286355f48464c0a7d531be3aad10513e3be Mon Sep 17 00:00:00 2001 From: Peter Kehl Date: Sun, 22 Jan 2023 21:25:06 -0800 Subject: [PATCH 057/118] CoAlloc: library/alloc/src/ffi: minor --- library/alloc/src/ffi/c_str.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/alloc/src/ffi/c_str.rs b/library/alloc/src/ffi/c_str.rs index bdf94524decc0..20c5f6b634e57 100644 --- a/library/alloc/src/ffi/c_str.rs +++ b/library/alloc/src/ffi/c_str.rs @@ -17,7 +17,7 @@ use core::ptr; use core::slice; use core::slice::memchr; use core::str::{self, Utf8Error}; -use crate::Global; +use crate::alloc::Global; use crate::DEFAULT_COOP_PREFERRED; #[cfg(target_has_atomic = "ptr")] From 823b8bf655fc92c68de6176d43beebfd60c2e862 Mon Sep 17 00:00:00 2001 From: Peter Kehl Date: Sun, 22 Jan 2023 21:25:35 -0800 Subject: [PATCH 058/118] CoAlloc: VecDeque: minor --- library/alloc/src/collections/vec_deque/spec_from_iter.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/alloc/src/collections/vec_deque/spec_from_iter.rs b/library/alloc/src/collections/vec_deque/spec_from_iter.rs index ecfe79799aa91..5da3faaabe2c6 100644 --- a/library/alloc/src/collections/vec_deque/spec_from_iter.rs +++ b/library/alloc/src/collections/vec_deque/spec_from_iter.rs @@ -1,5 +1,5 @@ use super::{IntoIter, VecDeque}; -use crate::Global; +use crate::alloc::Global; use core::alloc; /// Specialization trait used for `VecDeque::from_iter` From a742846de6c6251db5101fd012c3a117f3b52a42 Mon Sep 17 00:00:00 2001 From: Peter Kehl Date: Sun, 22 Jan 2023 21:26:41 -0800 Subject: [PATCH 059/118] CoAlloc: Vec: COOP_PREFERRED --- library/alloc/src/vec/into_iter.rs | 12 +++++++++++- library/alloc/src/vec/splice.rs | 4 ++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/library/alloc/src/vec/into_iter.rs b/library/alloc/src/vec/into_iter.rs index 9e54f6db5d34b..2ec439748f68a 100644 --- a/library/alloc/src/vec/into_iter.rs +++ b/library/alloc/src/vec/into_iter.rs @@ -131,7 +131,17 @@ where // struct and then overwriting &mut self. // this creates less assembly self.cap = 0; - self.buf = unsafe { NonNull::new_unchecked(RawVec::NEW.ptr()) }; + self.buf = unsafe { + // @FIXME The below if COOP_PREFERRED {..} else {..} + // branching exists, because the following fails. Otherwise we'd have a snowball effect of wide spread of where...Global... + // + // NonNull::new_unchecked(RawVec::::NEW.ptr()) + if COOP_PREFERRED { + NonNull::new_unchecked(RawVec::::NEW.ptr()) + } else { + NonNull::new_unchecked(RawVec::::NEW.ptr()) + } + }; self.ptr = self.buf.as_ptr(); self.end = self.buf.as_ptr(); diff --git a/library/alloc/src/vec/splice.rs b/library/alloc/src/vec/splice.rs index 185f09be55287..96ca11edaf6a1 100644 --- a/library/alloc/src/vec/splice.rs +++ b/library/alloc/src/vec/splice.rs @@ -115,9 +115,9 @@ where } /// Private helper methods for `Splice::drop` -impl Drain<'_, T, A> +impl Drain<'_, T, A, COOP_PREFERRED> where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(true)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { /// The range from `self.vec.len` to `self.tail_start` contains elements /// that have been moved out. From 2845276588270eb1834e13f918b01db02633d9bf Mon Sep 17 00:00:00 2001 From: Peter Kehl Date: Sun, 22 Jan 2023 21:40:29 -0800 Subject: [PATCH 060/118] CoAlloc: Vec + Box: COOP_PREFERRED for various traits --- library/alloc/src/boxed.rs | 10 ++++++---- library/alloc/src/vec/into_iter.rs | 8 +++++++- library/alloc/src/vec/mod.rs | 4 ---- library/alloc/src/vec/splice.rs | 1 - 4 files changed, 13 insertions(+), 10 deletions(-) diff --git a/library/alloc/src/boxed.rs b/library/alloc/src/boxed.rs index 32277063ac0b0..3806d42973c86 100644 --- a/library/alloc/src/boxed.rs +++ b/library/alloc/src/boxed.rs @@ -780,10 +780,11 @@ where #[allow(unused_braces)] pub fn new_uninit_slice_in(len: usize, alloc: A) -> Box<[mem::MaybeUninit], A> where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(SHORT_TERM_VEC_PREFERS_COOP!())]:, + // false = no need for co-alloc metadata, since it would get lost once converted to Box. + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(false)]:, { unsafe { - RawVec::::with_capacity_in(len, alloc) + RawVec::::with_capacity_in(len, alloc) .into_box(len) } } @@ -815,10 +816,11 @@ where #[allow(unused_braces)] pub fn new_zeroed_slice_in(len: usize, alloc: A) -> Box<[mem::MaybeUninit], A> where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(SHORT_TERM_VEC_PREFERS_COOP!())]:, + // false = no need for co-alloc metadata, since it would get lost once converted to Box. + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(false)]:, { unsafe { - RawVec::::with_capacity_zeroed_in( + RawVec::::with_capacity_zeroed_in( len, alloc, ) .into_box(len) diff --git a/library/alloc/src/vec/into_iter.rs b/library/alloc/src/vec/into_iter.rs index 2ec439748f68a..f4d5676f01e55 100644 --- a/library/alloc/src/vec/into_iter.rs +++ b/library/alloc/src/vec/into_iter.rs @@ -431,7 +431,13 @@ where { #[cfg(not(test))] fn clone(&self) -> Self { - self.as_slice().to_vec_in::(self.alloc.deref().clone()).into_iter() + // @FIXME Remove the following extras - used for type checks only + let slice = self.as_slice(); + let vec: crate::vec::Vec = slice.to_vec_in::(self.alloc.deref().clone()); + let _iter: IntoIter = vec.into_iter(); + + //self.as_slice().to_vec_in::(self.alloc.deref().clone()).into_iter() + loop {} } #[cfg(test)] fn clone(&self) -> Self { diff --git a/library/alloc/src/vec/mod.rs b/library/alloc/src/vec/mod.rs index 2c4d5012c3282..c8652645b4a77 100644 --- a/library/alloc/src/vec/mod.rs +++ b/library/alloc/src/vec/mod.rs @@ -2065,8 +2065,6 @@ where pub fn drain(&mut self, range: R) -> Drain<'_, T, A, COOP_PREFERRED> where R: RangeBounds, - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(SHORT_TERM_VEC_PREFERS_COOP!())]:, - { // Memory safety // @@ -2858,8 +2856,6 @@ where impl IntoIterator for Vec where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(SHORT_TERM_VEC_PREFERS_COOP!())]:, - { type Item = T; type IntoIter = IntoIter; diff --git a/library/alloc/src/vec/splice.rs b/library/alloc/src/vec/splice.rs index 96ca11edaf6a1..92fcaf4382dca 100644 --- a/library/alloc/src/vec/splice.rs +++ b/library/alloc/src/vec/splice.rs @@ -26,7 +26,6 @@ pub struct Splice< const COOP_PREFERRED: bool = false > where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, - //FIXME: If using SHORT_TERM_VEC_PREFERS_COOP!() instead of true, and the same for `drain` below, then this failed with: `derive` cannot be used on item swith type macros { pub(super) drain: Drain<'a, I::Item, A, COOP_PREFERRED>, pub(super) replace_with: I, From 895f042817697e9856b6017ef35a339b42a4fa44 Mon Sep 17 00:00:00 2001 From: Peter Kehl Date: Sun, 22 Jan 2023 21:41:00 -0800 Subject: [PATCH 061/118] CoAlloc: VecDeque: minor cleanup --- library/alloc/src/collections/vec_deque/mod.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/library/alloc/src/collections/vec_deque/mod.rs b/library/alloc/src/collections/vec_deque/mod.rs index d1e63ee155fa9..038506648ce4b 100644 --- a/library/alloc/src/collections/vec_deque/mod.rs +++ b/library/alloc/src/collections/vec_deque/mod.rs @@ -1406,7 +1406,6 @@ where pub fn drain(&mut self, range: R) -> Drain<'_, T, A, COOP_PREFERRED> where R: RangeBounds, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(SHORT_TERM_VEC_PREFERS_COOP!())]:, { // Memory safety // From 450e2f012c13bd8eb4254d8f42091b992007521b Mon Sep 17 00:00:00 2001 From: Peter Kehl Date: Thu, 12 Jan 2023 17:35:21 -0800 Subject: [PATCH 062/118] CoVec, PlVec, DefVec, WeVec. Cleanup. --- library/alloc/src/vec/mod.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/library/alloc/src/vec/mod.rs b/library/alloc/src/vec/mod.rs index c8652645b4a77..86cd92944f13b 100644 --- a/library/alloc/src/vec/mod.rs +++ b/library/alloc/src/vec/mod.rs @@ -419,14 +419,15 @@ pub struct Vec< len: usize, } +/// "Cooperative" Vector. Preferring co-alloc API (if Global alloc supports it). #[unstable(feature = "global_co_alloc_covec", issue = "none")] -pub type CoVec = +pub type CoVec = Vec; /// "Plain" Vec. Not "cooperative" - not carrying extra data to assist the allocator. /// FIXME after cleanup, see if we still use this in core:: and/or alloc:: #[unstable(feature = "global_co_alloc_plvec", issue = "none")] -pub type PlVec = +pub type PlVec = Vec; /// "Default" Vec. Either "cooperative" or not - as specified by `DEFAULT_COOP_PREFERRED`. The @@ -434,14 +435,14 @@ pub type PlVec = +pub type DefVec = Vec; /// "Weighted cooperative" Vec. Weight means how much it wants to cooperate (with the allocator). 0 /// = always pack; u8::MAX = always cooperate (if `Global` supports it). /// @FIXME A `pub const` threshold. #[unstable(feature = "global_co_alloc_vec", issue = "none")] -pub type WeVec = Vec 127 }>; +pub type WeVec = Vec 127 }>; //////////////////////////////////////////////////////////////////////////////// // Inherent methods From f697061bf6d34de572638b833a8ca6c518a6727e Mon Sep 17 00:00:00 2001 From: Peter Kehl Date: Sun, 22 Jan 2023 21:46:08 -0800 Subject: [PATCH 063/118] CoAlloc: Vec: added new_co() --- library/alloc/src/macros.rs | 2 +- library/alloc/src/vec/mod.rs | 30 +++++++++++++------ library/alloc/src/vec/spec_from_iter.rs | 2 +- .../alloc/src/vec/spec_from_iter_nested.rs | 2 +- 4 files changed, 24 insertions(+), 12 deletions(-) diff --git a/library/alloc/src/macros.rs b/library/alloc/src/macros.rs index 5198bf297d925..c2f1e9df41c11 100644 --- a/library/alloc/src/macros.rs +++ b/library/alloc/src/macros.rs @@ -41,7 +41,7 @@ #[allow_internal_unstable(rustc_attrs, liballoc_internals)] macro_rules! vec { () => ( - $crate::__rust_force_expr!($crate::vec::Vec::new()) + $crate::__rust_force_expr!($crate::vec::Vec::new_co()) ); ($elem:expr; $n:expr) => ( $crate::__rust_force_expr!($crate::vec::from_elem($elem, $n)) diff --git a/library/alloc/src/vec/mod.rs b/library/alloc/src/vec/mod.rs index 86cd92944f13b..a71399685e147 100644 --- a/library/alloc/src/vec/mod.rs +++ b/library/alloc/src/vec/mod.rs @@ -444,14 +444,7 @@ pub type DefVec = #[unstable(feature = "global_co_alloc_vec", issue = "none")] pub type WeVec = Vec 127 }>; -//////////////////////////////////////////////////////////////////////////////// -// Inherent methods -//////////////////////////////////////////////////////////////////////////////// - -impl Vec -where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, -{ +impl Vec { /// Constructs a new, empty `Vec`. /// /// The vector will not allocate until elements are pushed onto it. @@ -467,6 +460,25 @@ where #[stable(feature = "rust1", since = "1.0.0")] #[must_use] pub const fn new() -> Self { + #[allow(unused_braces)] + Vec::::new_co() + } +} + +//////////////////////////////////////////////////////////////////////////////// +// Inherent methods +//////////////////////////////////////////////////////////////////////////////// + +impl Vec +where + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{ + /// Like new(), but it respects COOP_PREFERRED. + #[inline] + #[rustc_const_stable(feature = "const_vec_new_co", since = "1.60.0")] //@FIXME This is `rustc_const_stable`, so that String::new() can be const and can call this. + #[unstable(feature = "vec_new_co", reason = "confirm_or_fix_the_function_name", issue = "none")] + #[must_use] + pub const fn new_co() -> Self { Vec { buf: RawVec::NEW, len: 0 } } @@ -3207,7 +3219,7 @@ where /// /// The vector will not allocate until elements are pushed onto it. fn default() -> Vec { - Vec::new() + Vec::new_co() } } diff --git a/library/alloc/src/vec/spec_from_iter.rs b/library/alloc/src/vec/spec_from_iter.rs index 6f414082ab292..e0befdb22962d 100644 --- a/library/alloc/src/vec/spec_from_iter.rs +++ b/library/alloc/src/vec/spec_from_iter.rs @@ -63,7 +63,7 @@ where } } - let mut vec = Vec::::new(); + let mut vec = Vec::::new_co(); // must delegate to spec_extend() since extend() itself delegates // to spec_from for empty Vecs vec.spec_extend(iterator); diff --git a/library/alloc/src/vec/spec_from_iter_nested.rs b/library/alloc/src/vec/spec_from_iter_nested.rs index 3ccd2da20df49..ff774e4534bf7 100644 --- a/library/alloc/src/vec/spec_from_iter_nested.rs +++ b/library/alloc/src/vec/spec_from_iter_nested.rs @@ -29,7 +29,7 @@ where // vector being full in the few subsequent loop iterations. // So we get better branch prediction. let mut vector = match iterator.next() { - None => return Vec::new(), + None => return Vec::new_co(), Some(element) => { let (lower, _) = iterator.size_hint(); let initial_capacity = From bce2757473f34dfc88a7b5a6883dc42fc69ad0e8 Mon Sep 17 00:00:00 2001 From: Peter Kehl Date: Mon, 23 Jan 2023 07:28:43 -0800 Subject: [PATCH 064/118] CoAlloc: std/src/lib.rs: minor --- library/std/src/lib.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/library/std/src/lib.rs b/library/std/src/lib.rs index 363a266717467..311795fbd9bf3 100644 --- a/library/std/src/lib.rs +++ b/library/std/src/lib.rs @@ -214,6 +214,10 @@ #![needs_panic_runtime] // // Lints: +#![allow(incomplete_features)] +#![feature(generic_const_exprs)] +#![feature(global_co_alloc)] +#![feature(global_co_alloc_plvec)] #![warn(deprecated_in_future)] #![warn(missing_docs)] #![warn(missing_debug_implementations)] From 8d5728e0b1e2aeb45e91a10aca3d27ca89541635 Mon Sep 17 00:00:00 2001 From: Peter Kehl Date: Mon, 23 Jan 2023 07:31:07 -0800 Subject: [PATCH 065/118] CoAlloc: FFI: minor --- library/std/src/ffi/os_str.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/library/std/src/ffi/os_str.rs b/library/std/src/ffi/os_str.rs index 80ed34157e6dc..6ab6323e19c83 100644 --- a/library/std/src/ffi/os_str.rs +++ b/library/std/src/ffi/os_str.rs @@ -1,6 +1,7 @@ #[cfg(test)] mod tests; +use crate::alloc::Global; use crate::borrow::{Borrow, Cow}; use crate::cmp; use crate::collections::TryReserveError; From 57aaf5079fd47d65ba77a9a51981bbf7c42676b9 Mon Sep 17 00:00:00 2001 From: Peter Kehl Date: Mon, 23 Jan 2023 07:31:32 -0800 Subject: [PATCH 066/118] CoAlloc: VecDeque (io::Read + io::Write for VecDeque): minor --- library/std/src/io/impls.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/library/std/src/io/impls.rs b/library/std/src/io/impls.rs index 8671ebf5c8141..64efd793b8c20 100644 --- a/library/std/src/io/impls.rs +++ b/library/std/src/io/impls.rs @@ -1,7 +1,7 @@ #[cfg(test)] mod tests; -use crate::alloc::Allocator; +use crate::alloc::{Allocator, self}; use crate::cmp; use crate::collections::VecDeque; use crate::fmt; @@ -419,7 +419,7 @@ where #[stable(feature = "vecdeque_read_write", since = "1.63.0")] impl Read for VecDeque where - [(); co_alloc_metadata_num_slots_with_preference::(_COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(_COOP_PREFERRED)]:, { /// Fill `buf` with the contents of the "front" slice as returned by /// [`as_slices`][`VecDeque::as_slices`]. If the contained byte slices of the `VecDeque` are @@ -446,7 +446,7 @@ where #[stable(feature = "vecdeque_read_write", since = "1.63.0")] impl Write for VecDeque where - [(); co_alloc_metadata_num_slots_with_preference::(_COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(_COOP_PREFERRED)]:, { #[inline] fn write(&mut self, buf: &[u8]) -> io::Result { From 69db430f2cadfe47d3c3ecdc2bc5f052fafdbe97 Mon Sep 17 00:00:00 2001 From: Peter Kehl Date: Mon, 23 Jan 2023 07:32:16 -0800 Subject: [PATCH 067/118] CoAlloc: sys ... thread dtor: minor --- library/std/src/sys/unix/thread_local_dtor.rs | 12 +++++++++--- library/std/src/sys_common/thread_local_dtor.rs | 1 - 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/library/std/src/sys/unix/thread_local_dtor.rs b/library/std/src/sys/unix/thread_local_dtor.rs index a3ba63834060f..16f237fa6a61b 100644 --- a/library/std/src/sys/unix/thread_local_dtor.rs +++ b/library/std/src/sys/unix/thread_local_dtor.rs @@ -1,12 +1,9 @@ #![cfg(target_thread_local)] #![unstable(feature = "thread_local_internals", issue = "none")] -#![feature(global_co_alloc_plvec)] //! Provides thread-local destructors without an associated "key", which //! can be more efficient. -use core::alloc::PlVec; - // Since what appears to be glibc 2.18 this symbol has been shipped which // GCC and clang both use to invoke destructors in thread_local globals, so // let's do the same! @@ -68,6 +65,15 @@ pub unsafe fn register_dtor(t: *mut u8, dtor: unsafe extern "C" fn(*mut u8)) { REGISTERED.set(true); } + type List = alloc::vec::PlVec<(*mut u8, unsafe extern "C" fn(*mut u8))>; + + #[thread_local] + static DTORS: Cell<*mut List> = Cell::new(ptr::null_mut()); + if DTORS.get().is_null() { + let v: Box = box Vec::new(); + DTORS.set(Box::into_raw(v)); + } + extern "C" { fn _tlv_atexit(dtor: unsafe extern "C" fn(*mut u8), arg: *mut u8); } diff --git a/library/std/src/sys_common/thread_local_dtor.rs b/library/std/src/sys_common/thread_local_dtor.rs index 43b7b0bb00468..6ec2f3cd11601 100644 --- a/library/std/src/sys_common/thread_local_dtor.rs +++ b/library/std/src/sys_common/thread_local_dtor.rs @@ -12,7 +12,6 @@ #![unstable(feature = "thread_local_internals", issue = "none")] #![allow(dead_code)] -#![feature(global_co_alloc_plvec)] use crate::ptr; use crate::sys_common::thread_local_key::StaticKey; From 2eb987fae84845dc50c4eb1a29440f36dbe8c7de Mon Sep 17 00:00:00 2001 From: Peter Kehl Date: Mon, 23 Jan 2023 07:33:36 -0800 Subject: [PATCH 068/118] CoAlloc: alloc: minor --- library/alloc/src/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/library/alloc/src/lib.rs b/library/alloc/src/lib.rs index 44c862d7e6485..c701ac2d0d6ab 100644 --- a/library/alloc/src/lib.rs +++ b/library/alloc/src/lib.rs @@ -191,6 +191,7 @@ // - cannot specialize on predicate `[(); _] well-formed` // - cannot specialize on predicate `the constant `core::alloc::co_alloc_metadata_num_slots::()` can be evaluated` //#![feature(min_specialization)] +#![feature(associated_type_defaults)] #![feature(specialization)] #![feature(negative_impls)] #![feature(never_type)] From 7108ea6ade5b96bd35ac56fc197162395515a53c Mon Sep 17 00:00:00 2001 From: Peter Kehl Date: Mon, 23 Jan 2023 10:02:48 -0800 Subject: [PATCH 069/118] CoAlloc: library/core: tidy --- library/core/src/alloc/mod.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/library/core/src/alloc/mod.rs b/library/core/src/alloc/mod.rs index ae4bad73a98ae..c0d2af6098378 100644 --- a/library/core/src/alloc/mod.rs +++ b/library/core/src/alloc/mod.rs @@ -84,7 +84,9 @@ pub struct SliceAndMeta { //pub const SHORT_TERM_VEC_PREFERS_COOP: bool = true; #[macro_export] macro_rules! SHORT_TERM_VEC_PREFERS_COOP { - () => {true} + () => { + true + }; } #[unstable(feature = "global_co_alloc_meta", issue = "none")] @@ -95,7 +97,9 @@ pub type SliceAndMetaResult = Result; pub const fn co_alloc_metadata_num_slots() -> usize { // @FIXME later if false { - panic!("FIXME - consider replacing co_alloc_metadata_num_slots() with co_alloc_metadata_num_slots_with_preference(bool), and adding const flags as appropriate."); + panic!( + "FIXME - consider replacing co_alloc_metadata_num_slots() with co_alloc_metadata_num_slots_with_preference(bool), and adding const flags as appropriate." + ); } if A::IS_CO_ALLOCATOR { 1 } else { 0 } } From 9eb28794106f67090b69d43643b72a217ed6a402 Mon Sep 17 00:00:00 2001 From: Peter Kehl Date: Mon, 23 Jan 2023 10:03:51 -0800 Subject: [PATCH 070/118] CoAlloc: library/proc_macro: tidy --- library/proc_macro/src/bridge/rpc.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/library/proc_macro/src/bridge/rpc.rs b/library/proc_macro/src/bridge/rpc.rs index 3d57bfd21ac7b..b48a98903bdb4 100644 --- a/library/proc_macro/src/bridge/rpc.rs +++ b/library/proc_macro/src/bridge/rpc.rs @@ -233,7 +233,9 @@ impl> Encode for Vec { } } -impl<'a, S, T: for<'s> DecodeMut<'a, 's, S>> DecodeMut<'a, '_, S> for Vec { +impl<'a, S, T: for<'s> DecodeMut<'a, 's, S>> DecodeMut<'a, '_, S> + for Vec +{ fn decode(r: &mut Reader<'a>, s: &mut S) -> Self { let len = usize::decode(r, s); let mut vec = Vec::with_capacity(len); From eb877405371d889f5763b501748f76edb78c6382 Mon Sep 17 00:00:00 2001 From: Peter Kehl Date: Mon, 23 Jan 2023 11:05:50 -0800 Subject: [PATCH 071/118] CoAlloc: Vec, Box + related slice.rs: tidy --- library/alloc/src/boxed.rs | 20 +--- library/alloc/src/lib.rs | 1 - library/alloc/src/raw_vec.rs | 6 +- library/alloc/src/slice.rs | 110 +++++++----------- library/alloc/src/vec/in_place_collect.rs | 3 +- library/alloc/src/vec/in_place_drop.rs | 2 +- library/alloc/src/vec/into_iter.rs | 3 +- library/alloc/src/vec/mod.rs | 59 +++++----- library/alloc/src/vec/spec_from_iter.rs | 4 +- .../alloc/src/vec/spec_from_iter_nested.rs | 4 +- library/alloc/src/vec/splice.rs | 17 ++- 11 files changed, 99 insertions(+), 130 deletions(-) diff --git a/library/alloc/src/boxed.rs b/library/alloc/src/boxed.rs index 3806d42973c86..1daba5600696a 100644 --- a/library/alloc/src/boxed.rs +++ b/library/alloc/src/boxed.rs @@ -780,13 +780,10 @@ where #[allow(unused_braces)] pub fn new_uninit_slice_in(len: usize, alloc: A) -> Box<[mem::MaybeUninit], A> where - // false = no need for co-alloc metadata, since it would get lost once converted to Box. - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(false)]:, + // false = no need for co-alloc metadata, since it would get lost once converted to Box. + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(false)]:, { - unsafe { - RawVec::::with_capacity_in(len, alloc) - .into_box(len) - } + unsafe { RawVec::::with_capacity_in(len, alloc).into_box(len) } } /// Constructs a new boxed slice with uninitialized contents in the provided allocator, @@ -816,15 +813,10 @@ where #[allow(unused_braces)] pub fn new_zeroed_slice_in(len: usize, alloc: A) -> Box<[mem::MaybeUninit], A> where - // false = no need for co-alloc metadata, since it would get lost once converted to Box. - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(false)]:, + // false = no need for co-alloc metadata, since it would get lost once converted to Box. + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(false)]:, { - unsafe { - RawVec::::with_capacity_zeroed_in( - len, alloc, - ) - .into_box(len) - } + unsafe { RawVec::::with_capacity_zeroed_in(len, alloc).into_box(len) } } } diff --git a/library/alloc/src/lib.rs b/library/alloc/src/lib.rs index c701ac2d0d6ab..6edfaf9bf4c03 100644 --- a/library/alloc/src/lib.rs +++ b/library/alloc/src/lib.rs @@ -288,4 +288,3 @@ pub(crate) mod test_helpers { rand::SeedableRng::from_seed(seed) } } - diff --git a/library/alloc/src/raw_vec.rs b/library/alloc/src/raw_vec.rs index 6da9570922947..c7a9606b65c86 100644 --- a/library/alloc/src/raw_vec.rs +++ b/library/alloc/src/raw_vec.rs @@ -54,7 +54,7 @@ enum AllocInit { pub(crate) struct RawVec< T, A: Allocator = Global, - const COOP_PREFERRED: bool = {DEFAULT_COOP_PREFERRED!()}, + const COOP_PREFERRED: bool = { DEFAULT_COOP_PREFERRED!() }, > where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { @@ -223,9 +223,7 @@ where cap: capacity, alloc, metas: [GlobalCoAllocMeta {/*one: 1*/ /*, two: 2, three: 3, four: 4*/}; - alloc::co_alloc_metadata_num_slots_with_preference::( - COOP_PREFERRED, - )], + alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)], } } } diff --git a/library/alloc/src/slice.rs b/library/alloc/src/slice.rs index d07564d40bccc..b62f910c05196 100644 --- a/library/alloc/src/slice.rs +++ b/library/alloc/src/slice.rs @@ -101,9 +101,7 @@ pub(crate) mod hack { b: Box<[T], A>, ) -> Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::( - COOP_PREFERRED, - )]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { unsafe { let len = b.len(); @@ -119,9 +117,7 @@ pub(crate) mod hack { alloc: A, ) -> Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::( - COOP_PREFERRED, - )]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { T::to_vec(s, alloc) } @@ -134,9 +130,7 @@ pub(crate) mod hack { ) -> Vec where Self: Sized, - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::( - COOP_PREFERRED, - )]:; + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:; } #[cfg(not(no_global_oom_handling))] @@ -147,24 +141,18 @@ pub(crate) mod hack { alloc: A, ) -> Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::( - COOP_PREFERRED, - )]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { struct DropGuard<'a, T, A: Allocator, const COOP_PREFERRED: bool> where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::( - COOP_PREFERRED, - )]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { vec: &'a mut Vec, num_init: usize, } impl<'a, T, A: Allocator, const COOP_PREFERRED: bool> Drop for DropGuard<'a, T, A, COOP_PREFERRED> where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::( - COOP_PREFERRED, - )]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { #[inline] fn drop(&mut self) { @@ -202,9 +190,7 @@ pub(crate) mod hack { alloc: A, ) -> Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::( - COOP_PREFERRED, - )]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { let mut v = Vec::with_capacity_in(s.len(), alloc); // SAFETY: @@ -459,9 +445,7 @@ impl [T] { pub fn to_vec(&self) -> Vec where T: Clone, - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::( - COOP_PREFERRED, - )]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { self.to_vec_in::(Global) } @@ -489,9 +473,7 @@ impl [T] { ) -> Vec where T: Clone, - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::( - COOP_PREFERRED, - )]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { // N.B., see the `hack` module in this file for more details. hack::to_vec(self, alloc) @@ -518,9 +500,7 @@ impl [T] { self: Box, ) -> Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::( - COOP_PREFERRED, - )]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { // N.B., see the `hack` module in this file for more details. hack::into_vec(self) @@ -936,48 +916,48 @@ where } }; -//<<<<<<< HEAD + //<<<<<<< HEAD let run_alloc_fn = |len: usize| -> *mut sort::TimSortRun { // SAFETY: Creating the layout is safe as long as merge_sort never calls this with an // obscene length or 0. unsafe { alloc::alloc(alloc::Layout::array::(len).unwrap_unchecked()) as *mut sort::TimSortRun -/*======= - // Allocate a buffer to use as scratch memory. We keep the length 0 so we can keep in it - // shallow copies of the contents of `v` without risking the dtors running on copies if - // `is_less` panics. When merging two sorted runs, this buffer holds a copy of the shorter run, - // which will always have length at most `len / 2`. - // `buf` is temporary = not passed around too much => using COOP_PREFERRED=true. - // @FIXME move definitions of `buf` and `runs` down, after while end > 0 {...}, just before they are used. Then benchmark if it makes (cache-related) difference. - let mut buf = Vec::::with_capacity(len / 2); - - // In order to identify natural runs in `v`, we traverse it backwards. That might seem like a - // strange decision, but consider the fact that merges more often go in the opposite direction - // (forwards). According to benchmarks, merging forwards is slightly faster than merging - // backwards. To conclude, identifying runs by traversing backwards improves performance. - // `runs` is temporary = not passed around too much => using COOP_PREFERRED=true. - let mut runs: Vec<_, Global, true> = vec![]; - let mut end = len; - while end > 0 { - // Find the next natural run, and reverse it if it's strictly descending. - let mut start = end - 1; - if start > 0 { - start -= 1; - unsafe { - if is_less(v.get_unchecked(start + 1), v.get_unchecked(start)) { - while start > 0 && is_less(v.get_unchecked(start), v.get_unchecked(start - 1)) { - start -= 1; - } - v[start..end].reverse(); - } else { - while start > 0 && !is_less(v.get_unchecked(start), v.get_unchecked(start - 1)) - { + /*======= + // Allocate a buffer to use as scratch memory. We keep the length 0 so we can keep in it + // shallow copies of the contents of `v` without risking the dtors running on copies if + // `is_less` panics. When merging two sorted runs, this buffer holds a copy of the shorter run, + // which will always have length at most `len / 2`. + // `buf` is temporary = not passed around too much => using COOP_PREFERRED=true. + // @FIXME move definitions of `buf` and `runs` down, after while end > 0 {...}, just before they are used. Then benchmark if it makes (cache-related) difference. + let mut buf = Vec::::with_capacity(len / 2); + + // In order to identify natural runs in `v`, we traverse it backwards. That might seem like a + // strange decision, but consider the fact that merges more often go in the opposite direction + // (forwards). According to benchmarks, merging forwards is slightly faster than merging + // backwards. To conclude, identifying runs by traversing backwards improves performance. + // `runs` is temporary = not passed around too much => using COOP_PREFERRED=true. + let mut runs: Vec<_, Global, true> = vec![]; + let mut end = len; + while end > 0 { + // Find the next natural run, and reverse it if it's strictly descending. + let mut start = end - 1; + if start > 0 { start -= 1; - } - } - } ->>>>>>> 6bd68177557 (CoAlloc: Slice: Fixing COOP_PREFERRED)*/ + unsafe { + if is_less(v.get_unchecked(start + 1), v.get_unchecked(start)) { + while start > 0 && is_less(v.get_unchecked(start), v.get_unchecked(start - 1)) { + start -= 1; + } + v[start..end].reverse(); + } else { + while start > 0 && !is_less(v.get_unchecked(start), v.get_unchecked(start - 1)) + { + start -= 1; + } + } + } + >>>>>>> 6bd68177557 (CoAlloc: Slice: Fixing COOP_PREFERRED)*/ } }; diff --git a/library/alloc/src/vec/in_place_collect.rs b/library/alloc/src/vec/in_place_collect.rs index 69f8ea9a61d3b..3afbc754061c0 100644 --- a/library/alloc/src/vec/in_place_collect.rs +++ b/library/alloc/src/vec/in_place_collect.rs @@ -137,8 +137,8 @@ //! } //! vec.truncate(write_idx); //! ``` -use core::alloc; use crate::alloc::Global; +use core::alloc; use core::iter::{InPlaceIterable, SourceIter, TrustedRandomAccessNoCoerce}; use core::mem::{self, ManuallyDrop, SizedTypeProperties}; use core::ptr::{self}; @@ -157,7 +157,6 @@ impl SpecFromIter for Vec + SourceIter + InPlaceIterableMarker, [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, - { default fn from_iter(mut iterator: I) -> Self { // See "Layout constraints" section in the module documentation. We rely on const diff --git a/library/alloc/src/vec/in_place_drop.rs b/library/alloc/src/vec/in_place_drop.rs index 871fd08b1f6b1..bf2d004e9db39 100644 --- a/library/alloc/src/vec/in_place_drop.rs +++ b/library/alloc/src/vec/in_place_drop.rs @@ -1,6 +1,6 @@ +use crate::alloc::Global; use core::ptr::{self}; use core::slice::{self}; -use crate::alloc::Global; // A helper struct for in-place iteration that drops the destination slice of iteration, // i.e. the head. The source slice (the tail) is dropped by IntoIter. diff --git a/library/alloc/src/vec/into_iter.rs b/library/alloc/src/vec/into_iter.rs index f4d5676f01e55..3555c64af9f8e 100644 --- a/library/alloc/src/vec/into_iter.rs +++ b/library/alloc/src/vec/into_iter.rs @@ -433,7 +433,8 @@ where fn clone(&self) -> Self { // @FIXME Remove the following extras - used for type checks only let slice = self.as_slice(); - let vec: crate::vec::Vec = slice.to_vec_in::(self.alloc.deref().clone()); + let vec: crate::vec::Vec = + slice.to_vec_in::(self.alloc.deref().clone()); let _iter: IntoIter = vec.into_iter(); //self.as_slice().to_vec_in::(self.alloc.deref().clone()).into_iter() diff --git a/library/alloc/src/vec/mod.rs b/library/alloc/src/vec/mod.rs index a71399685e147..966a113769dec 100644 --- a/library/alloc/src/vec/mod.rs +++ b/library/alloc/src/vec/mod.rs @@ -154,7 +154,9 @@ mod spec_extend; // pub const DEFAULT_COOP_PREFERRED: bool = true; #[macro_export] macro_rules! DEFAULT_COOP_PREFERRED { - () => {true} + () => { + true + }; } /// A contiguous growable array type, written as `Vec`, short for 'vector'. @@ -411,7 +413,7 @@ pub struct Vec< T, #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global, //@FIXME: #[unstable(feature ="global_co_alloc_vec", issue="none")] - const COOP_PREFERRED: bool = {DEFAULT_COOP_PREFERRED!()}, + const COOP_PREFERRED: bool = { DEFAULT_COOP_PREFERRED!() }, > where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { @@ -421,22 +423,19 @@ pub struct Vec< /// "Cooperative" Vector. Preferring co-alloc API (if Global alloc supports it). #[unstable(feature = "global_co_alloc_covec", issue = "none")] -pub type CoVec = - Vec; +pub type CoVec = Vec; /// "Plain" Vec. Not "cooperative" - not carrying extra data to assist the allocator. /// FIXME after cleanup, see if we still use this in core:: and/or alloc:: #[unstable(feature = "global_co_alloc_plvec", issue = "none")] -pub type PlVec = - Vec; +pub type PlVec = Vec; /// "Default" Vec. Either "cooperative" or not - as specified by `DEFAULT_COOP_PREFERRED`. The /// difference to `Vec` (used without specifying `COOP_PREFERRED`): `DefVec` indicates that the /// author considered using `CoVec` or `PlVec`, but left it to default instead. #[unstable(feature = "global_co_alloc_defvec", issue = "none")] #[allow(unused_braces)] -pub type DefVec = - Vec; +pub type DefVec = Vec; /// "Weighted cooperative" Vec. Weight means how much it wants to cooperate (with the allocator). 0 /// = always pack; u8::MAX = always cooperate (if `Global` supports it). @@ -461,7 +460,7 @@ impl Vec { #[must_use] pub const fn new() -> Self { #[allow(unused_braces)] - Vec::::new_co() + Vec::::new_co() } } @@ -1668,9 +1667,7 @@ where // In cases when predicate and `drop` never panick, it will be optimized out. struct BackshiftOnDrop<'a, T, A: Allocator, const VEC_IS_COOP: bool = true> where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::( - VEC_IS_COOP, - )]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(VEC_IS_COOP)]:, { v: &'a mut Vec, processed_len: usize, @@ -1680,9 +1677,7 @@ where impl Drop for BackshiftOnDrop<'_, T, A, VEC_IS_COOP> where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::( - VEC_IS_COOP, - )]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(VEC_IS_COOP)]:, { fn drop(&mut self) { if self.deleted_cnt > 0 { @@ -1715,9 +1710,7 @@ where g: &mut BackshiftOnDrop<'_, T, A, VEC_IS_COOP>, ) where F: FnMut(&mut T) -> bool, - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::( - VEC_IS_COOP, - )]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(VEC_IS_COOP)]:, { while g.processed_len != original_len { // SAFETY: Unchecked element must be valid. @@ -1812,9 +1805,7 @@ where /* INVARIANT: vec.len() > read >= write > write-1 >= 0 */ struct FillGapOnDrop<'a, T, A: core::alloc::Allocator, const COOP_PREFERRED: bool> where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::( - COOP_PREFERRED, - )]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { /* Offset of the element we want to check if it is duplicate */ read: usize, @@ -1830,9 +1821,7 @@ where impl<'a, T, A: core::alloc::Allocator, const COOP_PREFERRED: bool> Drop for FillGapOnDrop<'a, T, A, COOP_PREFERRED> where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::( - COOP_PREFERRED, - )]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { fn drop(&mut self) { /* This code gets executed when `same_bucket` panics */ @@ -2572,7 +2561,9 @@ where // - `new_cap` refers to the same sized allocation as `cap` because // `new_cap * size_of::()` == `cap * size_of::<[T; N]>()` // - `len` <= `cap`, so `len * N` <= `cap * N`. - unsafe { Vec::::from_raw_parts_in(ptr.cast(), new_len, new_cap, alloc) } + unsafe { + Vec::::from_raw_parts_in(ptr.cast(), new_len, new_cap, alloc) + } } } @@ -2858,7 +2849,7 @@ where impl FromIterator for Vec where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, - { +{ #[inline] fn from_iter>(iter: I) -> Vec { >::from_iter(iter.into_iter()) @@ -3063,7 +3054,11 @@ where #[cfg(not(no_global_oom_handling))] #[inline] #[stable(feature = "vec_splice", since = "1.21.0")] - pub fn splice(&mut self, range: R, replace_with: I) -> Splice<'_, I::IntoIter, A, COOP_PREFERRED> + pub fn splice( + &mut self, + range: R, + replace_with: I, + ) -> Splice<'_, I::IntoIter, A, COOP_PREFERRED> where R: RangeBounds, I: IntoIterator, @@ -3279,7 +3274,7 @@ where #[cfg(not(no_global_oom_handling))] #[stable(feature = "rust1", since = "1.0.0")] #[allow(unused_braces)] -impl From<&[T]> for Vec { +impl From<&[T]> for Vec { /// Allocate a `Vec` and fill it by cloning `s`'s items. /// /// # Examples @@ -3300,7 +3295,7 @@ impl From<&[T]> for Vec { #[cfg(not(no_global_oom_handling))] #[stable(feature = "vec_from_mut", since = "1.19.0")] #[allow(unused_braces)] -impl From<&mut [T]> for Vec { +impl From<&mut [T]> for Vec { /// Allocate a `Vec` and fill it by cloning `s`'s items. /// /// # Examples @@ -3321,7 +3316,7 @@ impl From<&mut [T]> for Vec { #[cfg(not(no_global_oom_handling))] #[stable(feature = "vec_from_array", since = "1.44.0")] #[allow(unused_braces)] -impl From<[T; N]> for Vec { +impl From<[T; N]> for Vec { /// Allocate a `Vec` and move `s`'s items into it. /// /// # Examples @@ -3345,7 +3340,7 @@ impl From<[T; N]> for Vec From> for Vec +impl<'a, T> From> for Vec where [T]: ToOwned>, { @@ -3423,7 +3418,7 @@ where #[cfg(not(no_global_oom_handling))] #[stable(feature = "rust1", since = "1.0.0")] #[allow(unused_braces)] -impl From<&str> for Vec { +impl From<&str> for Vec { /// Allocate a `Vec` and fill it with a UTF-8 string. /// /// # Examples diff --git a/library/alloc/src/vec/spec_from_iter.rs b/library/alloc/src/vec/spec_from_iter.rs index e0befdb22962d..e5d790878aabb 100644 --- a/library/alloc/src/vec/spec_from_iter.rs +++ b/library/alloc/src/vec/spec_from_iter.rs @@ -1,5 +1,5 @@ -use core::alloc; use crate::alloc::Global; +use core::alloc; use core::mem::ManuallyDrop; use core::ptr::{self}; @@ -41,7 +41,7 @@ where #[allow(unused_braces)] impl SpecFromIter> for Vec where -[(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { fn from_iter(iterator: IntoIter) -> Self { // A common case is passing a vector into a function which immediately diff --git a/library/alloc/src/vec/spec_from_iter_nested.rs b/library/alloc/src/vec/spec_from_iter_nested.rs index ff774e4534bf7..b71e86e83ba5a 100644 --- a/library/alloc/src/vec/spec_from_iter_nested.rs +++ b/library/alloc/src/vec/spec_from_iter_nested.rs @@ -3,8 +3,8 @@ use core::cmp; use core::iter::TrustedLen; use core::ptr; -use crate::raw_vec::RawVec; use crate::alloc::Global; +use crate::raw_vec::RawVec; use crate::DEFAULT_COOP_PREFERRED; use super::{SpecExtend, Vec}; @@ -51,7 +51,7 @@ where } #[allow(unused_braces)] -impl SpecFromIterNested for Vec +impl SpecFromIterNested for Vec where I: TrustedLen, { diff --git a/library/alloc/src/vec/splice.rs b/library/alloc/src/vec/splice.rs index 92fcaf4382dca..acf5553c9cfb4 100644 --- a/library/alloc/src/vec/splice.rs +++ b/library/alloc/src/vec/splice.rs @@ -23,7 +23,7 @@ pub struct Splice< 'a, I: Iterator + 'a, #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator + 'a = Global, - const COOP_PREFERRED: bool = false + const COOP_PREFERRED: bool = false, > where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { @@ -32,7 +32,8 @@ pub struct Splice< } #[stable(feature = "vec_splice", since = "1.21.0")] -impl Iterator for Splice<'_, I, A, COOP_PREFERRED> +impl Iterator + for Splice<'_, I, A, COOP_PREFERRED> where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { @@ -48,7 +49,8 @@ where } #[stable(feature = "vec_splice", since = "1.21.0")] -impl DoubleEndedIterator for Splice<'_, I, A, COOP_PREFERRED> +impl DoubleEndedIterator + for Splice<'_, I, A, COOP_PREFERRED> where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { @@ -58,13 +60,16 @@ where } #[stable(feature = "vec_splice", since = "1.21.0")] -impl ExactSizeIterator for Splice<'_, I, A, COOP_PREFERRED> where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: +impl ExactSizeIterator + for Splice<'_, I, A, COOP_PREFERRED> +where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { } #[stable(feature = "vec_splice", since = "1.21.0")] -impl Drop for Splice<'_, I, A, COOP_PREFERRED> +impl Drop + for Splice<'_, I, A, COOP_PREFERRED> where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { From b08c97f5d238182edae354892fb471dccf36d884 Mon Sep 17 00:00:00 2001 From: Peter Kehl Date: Mon, 23 Jan 2023 12:22:54 -0800 Subject: [PATCH 072/118] CoAlloc: std: minor tidy --- library/std/src/io/impls.rs | 2 +- library/std/src/sys/hermit/thread_local_dtor.rs | 2 +- library/std/src/sys/solid/thread_local_dtor.rs | 3 ++- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/library/std/src/io/impls.rs b/library/std/src/io/impls.rs index 64efd793b8c20..02cd7aa0d2cc0 100644 --- a/library/std/src/io/impls.rs +++ b/library/std/src/io/impls.rs @@ -1,7 +1,7 @@ #[cfg(test)] mod tests; -use crate::alloc::{Allocator, self}; +use crate::alloc::{self, Allocator}; use crate::cmp; use crate::collections::VecDeque; use crate::fmt; diff --git a/library/std/src/sys/hermit/thread_local_dtor.rs b/library/std/src/sys/hermit/thread_local_dtor.rs index 9816a7f200b6f..09b2df46a0f29 100644 --- a/library/std/src/sys/hermit/thread_local_dtor.rs +++ b/library/std/src/sys/hermit/thread_local_dtor.rs @@ -6,8 +6,8 @@ // The this solution works like the implementation of macOS and // doesn't additional OS support -use core::alloc::PlVec; use crate::mem; +use core::alloc::PlVec; #[thread_local] static mut DTORS: PlVec<(*mut u8, unsafe extern "C" fn(*mut u8))> = PlVec::new(); diff --git a/library/std/src/sys/solid/thread_local_dtor.rs b/library/std/src/sys/solid/thread_local_dtor.rs index 5468264393b55..59263cd41c761 100644 --- a/library/std/src/sys/solid/thread_local_dtor.rs +++ b/library/std/src/sys/solid/thread_local_dtor.rs @@ -1,5 +1,6 @@ #![cfg(target_thread_local)] -#![unstable(feature = "thread_local_internals", issue = "none")]#![feature(global_co_alloc_plvec)] +#![unstable(feature = "thread_local_internals", issue = "none")] +#![feature(global_co_alloc_plvec)] #![feature(global_co_alloc_plvec)] // Simplify dtor registration by using a list of destructors. From 48ebfec0409e50254d0cb7d950dff9700ab4e73f Mon Sep 17 00:00:00 2001 From: Peter Kehl Date: Mon, 23 Jan 2023 12:23:11 -0800 Subject: [PATCH 073/118] CoAlloc: VecDeque: tidy --- .../src/collections/vec_deque/into_iter.rs | 17 ++++++---- .../alloc/src/collections/vec_deque/mod.rs | 32 +++++++++---------- .../collections/vec_deque/spec_from_iter.rs | 3 +- 3 files changed, 27 insertions(+), 25 deletions(-) diff --git a/library/alloc/src/collections/vec_deque/into_iter.rs b/library/alloc/src/collections/vec_deque/into_iter.rs index ce01e81f6b71c..f3f50e3048bc6 100644 --- a/library/alloc/src/collections/vec_deque/into_iter.rs +++ b/library/alloc/src/collections/vec_deque/into_iter.rs @@ -38,7 +38,8 @@ where } #[stable(feature = "collection_debug", since = "1.17.0")] -impl fmt::Debug for IntoIter +impl fmt::Debug + for IntoIter where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { @@ -187,7 +188,8 @@ where } #[stable(feature = "rust1", since = "1.0.0")] -impl DoubleEndedIterator for IntoIter +impl DoubleEndedIterator + for IntoIter where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { @@ -260,7 +262,8 @@ where } #[stable(feature = "rust1", since = "1.0.0")] -impl ExactSizeIterator for IntoIter +impl ExactSizeIterator + for IntoIter where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { @@ -271,14 +274,14 @@ where } #[stable(feature = "fused", since = "1.26.0")] -impl FusedIterator for IntoIter -where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +impl FusedIterator for IntoIter where + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: { } #[unstable(feature = "trusted_len", issue = "37572")] -unsafe impl TrustedLen for IntoIter +unsafe impl TrustedLen + for IntoIter where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { diff --git a/library/alloc/src/collections/vec_deque/mod.rs b/library/alloc/src/collections/vec_deque/mod.rs index 038506648ce4b..e98087ea9ad93 100644 --- a/library/alloc/src/collections/vec_deque/mod.rs +++ b/library/alloc/src/collections/vec_deque/mod.rs @@ -97,7 +97,7 @@ mod tests; pub struct VecDeque< T, #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global, - const COOP_PREFERRED: bool = {DEFAULT_COOP_PREFERRED!()}, + const COOP_PREFERRED: bool = { DEFAULT_COOP_PREFERRED!() }, > where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { @@ -570,7 +570,8 @@ where #[rustc_const_stable(feature = "const_vec_deque_new", since = "1.68.0")] #[must_use] pub const fn new() -> VecDeque - where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { // FIXME: This should just be `VecDeque::new_in(Global)` once that hits stable. VecDeque { head: 0, len: 0, buf: RawVec::NEW } @@ -2903,13 +2904,11 @@ where } #[stable(feature = "vecdeque_vec_conversions", since = "1.10.0")] -impl From> - for VecDeque +impl + From> for VecDeque where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, - [(); alloc::co_alloc_metadata_num_slots_with_preference::( - OTHER_COOP_PREFERRED, - )]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(OTHER_COOP_PREFERRED)]:, { /// Turn a [`Vec`] into a [`VecDeque`]. /// @@ -2920,16 +2919,19 @@ where /// and to not re-allocate the `Vec`'s buffer or allocate /// any additional memory. #[inline] - fn from(other: Vec) -> Self - { + fn from(other: Vec) -> Self { let (ptr, len, cap, alloc) = other.into_raw_parts_with_alloc(); - Self { head: 0, len, buf: unsafe { RawVec::::from_raw_parts_in(ptr, cap, alloc) } } + Self { + head: 0, + len, + buf: unsafe { RawVec::::from_raw_parts_in(ptr, cap, alloc) }, + } } } #[stable(feature = "vecdeque_vec_conversions", since = "1.10.0")] -impl From> - for Vec +impl + From> for Vec where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, [(); alloc::co_alloc_metadata_num_slots_with_preference::(VECDEQUE_COOP_PREFERRED)]:, @@ -2963,11 +2965,9 @@ where /// assert_eq!(vec, [8, 9, 1, 2, 3, 4]); /// assert_eq!(vec.as_ptr(), ptr); /// ``` - fn from( - mut other: VecDeque, - ) -> Self + fn from(mut other: VecDeque) -> Self where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(VECDEQUE_COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(VECDEQUE_COOP_PREFERRED)]:, { other.make_contiguous(); diff --git a/library/alloc/src/collections/vec_deque/spec_from_iter.rs b/library/alloc/src/collections/vec_deque/spec_from_iter.rs index 5da3faaabe2c6..b0380260fcc44 100644 --- a/library/alloc/src/collections/vec_deque/spec_from_iter.rs +++ b/library/alloc/src/collections/vec_deque/spec_from_iter.rs @@ -7,8 +7,7 @@ pub(super) trait SpecFromIter { fn spec_from_iter(iter: I) -> Self; } -impl SpecFromIter - for VecDeque +impl SpecFromIter for VecDeque where I: Iterator, [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, From 3768ee246c1ec16b3fa3bb35381b97f034453d97 Mon Sep 17 00:00:00 2001 From: Peter Kehl Date: Mon, 23 Jan 2023 12:23:23 -0800 Subject: [PATCH 074/118] CoAlloc: BinaryHeap: tidy --- library/alloc/src/collections/binary_heap/mod.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/library/alloc/src/collections/binary_heap/mod.rs b/library/alloc/src/collections/binary_heap/mod.rs index 1290a449facd2..05dfaa92f385b 100644 --- a/library/alloc/src/collections/binary_heap/mod.rs +++ b/library/alloc/src/collections/binary_heap/mod.rs @@ -143,12 +143,12 @@ #![allow(missing_docs)] #![stable(feature = "rust1", since = "1.0.0")] +use core::fmt; use core::iter::{FromIterator, FusedIterator, InPlaceIterable, SourceIter, TrustedLen}; use core::mem::{self, swap, ManuallyDrop}; use core::num::NonZeroUsize; use core::ops::{Deref, DerefMut}; use core::ptr; -use core::fmt; use crate::alloc::Global; @@ -1572,10 +1572,10 @@ where } #[stable(feature = "fused", since = "1.26.0")] -impl FusedIterator for Drain<'_, T, COOP_PREFERRED> -where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, -{} +impl FusedIterator for Drain<'_, T, COOP_PREFERRED> where + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: +{ +} /// A draining iterator over the elements of a `BinaryHeap`. /// @@ -1664,7 +1664,7 @@ impl From<[T; N]> for BinaryHeap { #[stable(feature = "binary_heap_extras_15", since = "1.5.0")] #[allow(unused_braces)] -impl From> for Vec { +impl From> for Vec { /// Converts a `BinaryHeap` into a `Vec`. /// /// This conversion requires no data movement or allocation, and has From 54729da0c06823ab2d9c60413dd63fdccae6a2d3 Mon Sep 17 00:00:00 2001 From: Peter Kehl Date: Mon, 23 Jan 2023 12:34:08 -0800 Subject: [PATCH 075/118] CoAlloc: slice.rs: Cleanup (of old code already commented out) --- library/alloc/src/slice.rs | 36 ------------------------------------ 1 file changed, 36 deletions(-) diff --git a/library/alloc/src/slice.rs b/library/alloc/src/slice.rs index b62f910c05196..f2b4596c53a7d 100644 --- a/library/alloc/src/slice.rs +++ b/library/alloc/src/slice.rs @@ -916,48 +916,12 @@ where } }; - //<<<<<<< HEAD let run_alloc_fn = |len: usize| -> *mut sort::TimSortRun { // SAFETY: Creating the layout is safe as long as merge_sort never calls this with an // obscene length or 0. unsafe { alloc::alloc(alloc::Layout::array::(len).unwrap_unchecked()) as *mut sort::TimSortRun - /*======= - // Allocate a buffer to use as scratch memory. We keep the length 0 so we can keep in it - // shallow copies of the contents of `v` without risking the dtors running on copies if - // `is_less` panics. When merging two sorted runs, this buffer holds a copy of the shorter run, - // which will always have length at most `len / 2`. - // `buf` is temporary = not passed around too much => using COOP_PREFERRED=true. - // @FIXME move definitions of `buf` and `runs` down, after while end > 0 {...}, just before they are used. Then benchmark if it makes (cache-related) difference. - let mut buf = Vec::::with_capacity(len / 2); - - // In order to identify natural runs in `v`, we traverse it backwards. That might seem like a - // strange decision, but consider the fact that merges more often go in the opposite direction - // (forwards). According to benchmarks, merging forwards is slightly faster than merging - // backwards. To conclude, identifying runs by traversing backwards improves performance. - // `runs` is temporary = not passed around too much => using COOP_PREFERRED=true. - let mut runs: Vec<_, Global, true> = vec![]; - let mut end = len; - while end > 0 { - // Find the next natural run, and reverse it if it's strictly descending. - let mut start = end - 1; - if start > 0 { - start -= 1; - unsafe { - if is_less(v.get_unchecked(start + 1), v.get_unchecked(start)) { - while start > 0 && is_less(v.get_unchecked(start), v.get_unchecked(start - 1)) { - start -= 1; - } - v[start..end].reverse(); - } else { - while start > 0 && !is_less(v.get_unchecked(start), v.get_unchecked(start - 1)) - { - start -= 1; - } - } - } - >>>>>>> 6bd68177557 (CoAlloc: Slice: Fixing COOP_PREFERRED)*/ } }; From 66e6dde770d8d220645204a9c57644bf6a23e84b Mon Sep 17 00:00:00 2001 From: Peter Kehl Date: Thu, 12 Jan 2023 23:16:40 -0800 Subject: [PATCH 076/118] CoAlloc: Uncommenting assert of BorrowType::TRAVERSAL_PERMIT. TODO Undo once compilable, FIXME --- library/alloc/src/collections/btree/node.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/library/alloc/src/collections/btree/node.rs b/library/alloc/src/collections/btree/node.rs index 3233a575ecf25..2e43ce937f06d 100644 --- a/library/alloc/src/collections/btree/node.rs +++ b/library/alloc/src/collections/btree/node.rs @@ -319,7 +319,8 @@ impl NodeRef self, ) -> Result, marker::Edge>, Self> { const { - assert!(BorrowType::TRAVERSAL_PERMIT); + //@FIXME uncomment once compilable + //assert!(BorrowType::TRAVERSAL_PERMIT); } // We need to use raw pointers to nodes because, if BorrowType is marker::ValMut, @@ -1063,7 +1064,8 @@ impl /// both, upon success, do nothing. pub fn descend(self) -> NodeRef { const { - assert!(BorrowType::TRAVERSAL_PERMIT); + // @FIXME uncomment once compilable + //assert!(BorrowType::TRAVERSAL_PERMIT); } // We need to use raw pointers to nodes because, if BorrowType is From 661318c0219dc4c209eb15978db3702fc812484a Mon Sep 17 00:00:00 2001 From: Peter Kehl Date: Mon, 23 Jan 2023 16:35:42 -0800 Subject: [PATCH 077/118] CoAlloc: Vec + related: cleanup. Now library/alloc compiles, but std/ does NOT. --- library/alloc/src/str.rs | 2 +- library/std/src/ffi/os_str.rs | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/library/alloc/src/str.rs b/library/alloc/src/str.rs index eedf856f5d253..2a011103cecd0 100644 --- a/library/alloc/src/str.rs +++ b/library/alloc/src/str.rs @@ -136,7 +136,7 @@ where T: Copy, B: AsRef<[T]> + ?Sized, S: Borrow, - [(); alloc::co_alloc_metadata_num_slots_with_preference_global(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, { let sep_len = sep.len(); let mut iter = slice.iter(); diff --git a/library/std/src/ffi/os_str.rs b/library/std/src/ffi/os_str.rs index 6ab6323e19c83..80ed34157e6dc 100644 --- a/library/std/src/ffi/os_str.rs +++ b/library/std/src/ffi/os_str.rs @@ -1,7 +1,6 @@ #[cfg(test)] mod tests; -use crate::alloc::Global; use crate::borrow::{Borrow, Cow}; use crate::cmp; use crate::collections::TryReserveError; From 786c443b714b787a4c8b482e6776c8130804e647 Mon Sep 17 00:00:00 2001 From: Peter Kehl Date: Tue, 24 Jan 2023 11:45:12 -0800 Subject: [PATCH 078/118] CoAlloc: Vec, related + vec! macro: Separated co-alloc-aware functions to have unique names, so we have no conflicts, but source code backward-compatibility. --- library/alloc/src/macros.rs | 2 +- library/alloc/src/str.rs | 4 +- library/alloc/src/vec/mod.rs | 69 ++++++++++++++++++- .../alloc/src/vec/spec_from_iter_nested.rs | 2 +- library/std/src/lib.rs | 1 + .../std/src/sys_common/thread_local_dtor.rs | 2 +- 6 files changed, 73 insertions(+), 7 deletions(-) diff --git a/library/alloc/src/macros.rs b/library/alloc/src/macros.rs index c2f1e9df41c11..5198bf297d925 100644 --- a/library/alloc/src/macros.rs +++ b/library/alloc/src/macros.rs @@ -41,7 +41,7 @@ #[allow_internal_unstable(rustc_attrs, liballoc_internals)] macro_rules! vec { () => ( - $crate::__rust_force_expr!($crate::vec::Vec::new_co()) + $crate::__rust_force_expr!($crate::vec::Vec::new()) ); ($elem:expr; $n:expr) => ( $crate::__rust_force_expr!($crate::vec::from_elem($elem, $n)) diff --git a/library/alloc/src/str.rs b/library/alloc/src/str.rs index 2a011103cecd0..b95ef1c5933f8 100644 --- a/library/alloc/src/str.rs +++ b/library/alloc/src/str.rs @@ -144,7 +144,7 @@ where // the first slice is the only one without a separator preceding it let first = match iter.next() { Some(first) => first, - None => return vec![], + None => return Vec::new_co(), }; // compute the exact total length of the joined Vec @@ -159,7 +159,7 @@ where .expect("attempt to join into collection with len > usize::MAX"); // prepare an uninitialized buffer - let mut result = Vec::with_capacity(reserved_len); + let mut result = Vec::with_capacity_co(reserved_len); debug_assert!(result.capacity() >= reserved_len); result.extend_from_slice(first.borrow().as_ref()); diff --git a/library/alloc/src/vec/mod.rs b/library/alloc/src/vec/mod.rs index 966a113769dec..5793bf13f349f 100644 --- a/library/alloc/src/vec/mod.rs +++ b/library/alloc/src/vec/mod.rs @@ -444,6 +444,10 @@ pub type DefVec = Vec; pub type WeVec = Vec 127 }>; impl Vec { +/*impl Vec +where + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, +{*/ /// Constructs a new, empty `Vec`. /// /// The vector will not allocate until elements are pushed onto it. @@ -461,13 +465,73 @@ impl Vec { pub const fn new() -> Self { #[allow(unused_braces)] Vec::::new_co() + //Self::new_co() + } + + /// Constructs a new, empty `Vec` with at least the specified capacity. + /// + /// The vector will be able to hold at least `capacity` elements without + /// reallocating. This method is allowed to allocate for more elements than + /// `capacity`. If `capacity` is 0, the vector will not allocate. + /// + /// It is important to note that although the returned vector has the + /// minimum *capacity* specified, the vector will have a zero *length*. For + /// an explanation of the difference between length and capacity, see + /// *[Capacity and reallocation]*. + /// + /// If it is important to know the exact allocated capacity of a `Vec`, + /// always use the [`capacity`] method after construction. + /// + /// For `Vec` where `T` is a zero-sized type, there will be no allocation + /// and the capacity will always be `usize::MAX`. + /// + /// [Capacity and reallocation]: #capacity-and-reallocation + /// [`capacity`]: Vec::capacity + /// + /// # Panics + /// + /// Panics if the new capacity exceeds `isize::MAX` bytes. + /// + /// # Examples + /// + /// ``` + /// let mut vec = Vec::with_capacity(10); + /// + /// // The vector contains no items, even though it has capacity for more + /// assert_eq!(vec.len(), 0); + /// assert!(vec.capacity() >= 10); + /// + /// // These are all done without reallocating... + /// for i in 0..10 { + /// vec.push(i); + /// } + /// assert_eq!(vec.len(), 10); + /// assert!(vec.capacity() >= 10); + /// + /// // ...but this may make the vector reallocate + /// vec.push(11); + /// assert_eq!(vec.len(), 11); + /// assert!(vec.capacity() >= 11); + /// + /// // A vector of a zero-sized type will always over-allocate, since no + /// // allocation is necessary + /// let vec_units = Vec::<()>::with_capacity(10); + /// assert_eq!(vec_units.capacity(), usize::MAX); + /// ``` #[cfg(not(no_global_oom_handling))] + #[inline] + #[stable(feature = "rust1", since = "1.0.0")] + #[must_use] + pub fn with_capacity(capacity: usize) -> Self { + Self::with_capacity_in(capacity, Global) } + } //////////////////////////////////////////////////////////////////////////////// // Inherent methods //////////////////////////////////////////////////////////////////////////////// +/**/ impl Vec where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, @@ -481,6 +545,7 @@ where Vec { buf: RawVec::NEW, len: 0 } } + // TODO @FIXME document co-allocation /// Constructs a new, empty `Vec` with at least the specified capacity. /// /// The vector will be able to hold at least `capacity` elements without @@ -533,9 +598,9 @@ where /// ``` #[cfg(not(no_global_oom_handling))] #[inline] - #[stable(feature = "rust1", since = "1.0.0")] + #[unstable(feature = "vec_new_co", reason = "confirm_or_fix_the_function_name", issue = "none")] #[must_use] - pub fn with_capacity(capacity: usize) -> Self { + pub fn with_capacity_co(capacity: usize) -> Self { Self::with_capacity_in(capacity, Global) } diff --git a/library/alloc/src/vec/spec_from_iter_nested.rs b/library/alloc/src/vec/spec_from_iter_nested.rs index b71e86e83ba5a..358c1b5a25f55 100644 --- a/library/alloc/src/vec/spec_from_iter_nested.rs +++ b/library/alloc/src/vec/spec_from_iter_nested.rs @@ -34,7 +34,7 @@ where let (lower, _) = iterator.size_hint(); let initial_capacity = cmp::max(RawVec::::MIN_NON_ZERO_CAP, lower.saturating_add(1)); - let mut vector = Vec::with_capacity(initial_capacity); + let mut vector = Vec::with_capacity_co(initial_capacity); unsafe { // SAFETY: We requested capacity at least 1 ptr::write(vector.as_mut_ptr(), element); diff --git a/library/std/src/lib.rs b/library/std/src/lib.rs index 311795fbd9bf3..5999b12f3b5d7 100644 --- a/library/std/src/lib.rs +++ b/library/std/src/lib.rs @@ -324,6 +324,7 @@ #![feature(try_reserve_kind)] #![feature(vec_into_raw_parts)] #![feature(slice_concat_trait)] +#![feature(vec_new_co)] // // Library features (unwind): #![feature(panic_unwind)] diff --git a/library/std/src/sys_common/thread_local_dtor.rs b/library/std/src/sys_common/thread_local_dtor.rs index 6ec2f3cd11601..dcab8a89e7f53 100644 --- a/library/std/src/sys_common/thread_local_dtor.rs +++ b/library/std/src/sys_common/thread_local_dtor.rs @@ -31,7 +31,7 @@ pub unsafe fn register_dtor_fallback(t: *mut u8, dtor: unsafe extern "C" fn(*mut static DTORS: StaticKey = StaticKey::new(Some(run_dtors)); type List = PlVec<(*mut u8, unsafe extern "C" fn(*mut u8))>; if DTORS.get().is_null() { - let v: Box = Box::new(Vec::new()); + let v: Box = Box::new(Vec::new_co()); DTORS.set(Box::into_raw(v) as *mut u8); } let list: &mut List = &mut *(DTORS.get() as *mut List); From 40661d329b159e437e1cefa386545960f8d0b231 Mon Sep 17 00:00:00 2001 From: Peter Kehl Date: Tue, 24 Jan 2023 11:58:53 -0800 Subject: [PATCH 079/118] CoAlloc: library/proc_macro (+related library/alloc): Experimenting with importing DEFAULT_COOP_PREFERRED --- library/alloc/src/vec/mod.rs | 1 + library/proc_macro/src/bridge/rpc.rs | 5 ++++- library/proc_macro/src/lib.rs | 1 + 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/library/alloc/src/vec/mod.rs b/library/alloc/src/vec/mod.rs index 5793bf13f349f..885c0e0683c09 100644 --- a/library/alloc/src/vec/mod.rs +++ b/library/alloc/src/vec/mod.rs @@ -150,6 +150,7 @@ use self::spec_extend::SpecExtend; mod spec_extend; /// Default `Vec`, `DefVec`, `DecVeque`, `DefDecVeq` "cooperation" (`COOP_PREFERRED`) generic parameter. +/// NOT for public use. It's exported only so that library/proc_macro (and other internals) can use this. TODO FIXME. #[unstable(feature = "global_co_alloc_def", issue = "none")] // pub const DEFAULT_COOP_PREFERRED: bool = true; #[macro_export] diff --git a/library/proc_macro/src/bridge/rpc.rs b/library/proc_macro/src/bridge/rpc.rs index b48a98903bdb4..8f8d612f06f6d 100644 --- a/library/proc_macro/src/bridge/rpc.rs +++ b/library/proc_macro/src/bridge/rpc.rs @@ -4,6 +4,9 @@ use std::any::Any; use std::io::Write; use std::num::NonZeroU32; use std::str; +//use std::alloc::Global; +use alloc::DEFAULT_COOP_PREFERRED; +use alloc::alloc::Global; pub(super) type Writer = super::buffer::Buffer; @@ -224,7 +227,7 @@ impl DecodeMut<'_, '_, S> for String { } } -impl> Encode for Vec { +impl> Encode for Vec { fn encode(self, w: &mut Writer, s: &mut S) { self.len().encode(w, s); for x in self { diff --git a/library/proc_macro/src/lib.rs b/library/proc_macro/src/lib.rs index 938935771d64e..4d252266b89e1 100644 --- a/library/proc_macro/src/lib.rs +++ b/library/proc_macro/src/lib.rs @@ -33,6 +33,7 @@ #![feature(min_specialization)] #![feature(strict_provenance)] #![recursion_limit = "256"] +#![feature(global_co_alloc_def)] #[unstable(feature = "proc_macro_internals", issue = "27812")] #[doc(hidden)] From 27c4c3e41636d203ae02beaa4a9e1a76036510c0 Mon Sep 17 00:00:00 2001 From: Peter Kehl Date: Wed, 25 Jan 2023 12:08:29 -0800 Subject: [PATCH 080/118] CoAlloc: Renamed feature global_co_alloc_def to global_co_alloc_default. tidy --- library/alloc/src/ffi/c_str.rs | 6 +++--- library/alloc/src/lib.rs | 2 +- library/alloc/src/vec/mod.rs | 15 +++++++-------- library/proc_macro/src/bridge/rpc.rs | 2 +- library/proc_macro/src/lib.rs | 2 +- 5 files changed, 13 insertions(+), 14 deletions(-) diff --git a/library/alloc/src/ffi/c_str.rs b/library/alloc/src/ffi/c_str.rs index 20c5f6b634e57..4def86777bef4 100644 --- a/library/alloc/src/ffi/c_str.rs +++ b/library/alloc/src/ffi/c_str.rs @@ -1,12 +1,14 @@ #[cfg(test)] mod tests; +use crate::alloc::Global; use crate::borrow::{Cow, ToOwned}; use crate::boxed::Box; use crate::rc::Rc; use crate::slice::hack::into_vec; use crate::string::String; use crate::vec::Vec; +use crate::DEFAULT_COOP_PREFERRED; use core::borrow::Borrow; use core::ffi::{c_char, CStr}; use core::fmt; @@ -17,8 +19,6 @@ use core::ptr; use core::slice; use core::slice::memchr; use core::str::{self, Utf8Error}; -use crate::alloc::Global; -use crate::DEFAULT_COOP_PREFERRED; #[cfg(target_has_atomic = "ptr")] use crate::sync::Arc; @@ -726,7 +726,7 @@ impl fmt::Debug for CString { #[stable(feature = "cstring_into", since = "1.7.0")] #[allow(unused_braces)] -impl From for Vec { +impl From for Vec { /// Converts a [`CString`] into a [Vec]<[u8]>. /// /// The conversion consumes the [`CString`], and removes the terminating NUL byte. diff --git a/library/alloc/src/lib.rs b/library/alloc/src/lib.rs index 6edfaf9bf4c03..348de3322186d 100644 --- a/library/alloc/src/lib.rs +++ b/library/alloc/src/lib.rs @@ -185,7 +185,7 @@ #![feature(global_co_alloc_short_term_pref)] #![feature(hashmap_internals)] #![feature(lang_items)] -#![feature(global_co_alloc_def)] +#![feature(global_co_alloc_default)] // When we used min_specialization instead of specialization, library/alloc/src/vec/mod.rs was failing with: // - cannot specialize on predicate `the constant `core::alloc::co_alloc_metadata_num_slots::()` can be evaluated` // - cannot specialize on predicate `[(); _] well-formed` diff --git a/library/alloc/src/vec/mod.rs b/library/alloc/src/vec/mod.rs index 885c0e0683c09..619dd958db1be 100644 --- a/library/alloc/src/vec/mod.rs +++ b/library/alloc/src/vec/mod.rs @@ -150,8 +150,8 @@ use self::spec_extend::SpecExtend; mod spec_extend; /// Default `Vec`, `DefVec`, `DecVeque`, `DefDecVeq` "cooperation" (`COOP_PREFERRED`) generic parameter. -/// NOT for public use. It's exported only so that library/proc_macro (and other internals) can use this. TODO FIXME. -#[unstable(feature = "global_co_alloc_def", issue = "none")] +/// NOT for public use. It's exported only so that library/proc_macro (and other internals) can use this. FIXME. +#[unstable(feature = "global_co_alloc_default", issue = "none")] // pub const DEFAULT_COOP_PREFERRED: bool = true; #[macro_export] macro_rules! DEFAULT_COOP_PREFERRED { @@ -445,10 +445,10 @@ pub type DefVec = Vec; pub type WeVec = Vec 127 }>; impl Vec { -/*impl Vec -where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, -{*/ + /*impl Vec + where + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + {*/ /// Constructs a new, empty `Vec`. /// /// The vector will not allocate until elements are pushed onto it. @@ -525,7 +525,6 @@ where pub fn with_capacity(capacity: usize) -> Self { Self::with_capacity_in(capacity, Global) } - } //////////////////////////////////////////////////////////////////////////////// @@ -546,7 +545,7 @@ where Vec { buf: RawVec::NEW, len: 0 } } - // TODO @FIXME document co-allocation + // @FIXME document co-allocation /// Constructs a new, empty `Vec` with at least the specified capacity. /// /// The vector will be able to hold at least `capacity` elements without diff --git a/library/proc_macro/src/bridge/rpc.rs b/library/proc_macro/src/bridge/rpc.rs index 8f8d612f06f6d..8e5e17598b0be 100644 --- a/library/proc_macro/src/bridge/rpc.rs +++ b/library/proc_macro/src/bridge/rpc.rs @@ -5,8 +5,8 @@ use std::io::Write; use std::num::NonZeroU32; use std::str; //use std::alloc::Global; -use alloc::DEFAULT_COOP_PREFERRED; use alloc::alloc::Global; +use alloc::DEFAULT_COOP_PREFERRED; pub(super) type Writer = super::buffer::Buffer; diff --git a/library/proc_macro/src/lib.rs b/library/proc_macro/src/lib.rs index 4d252266b89e1..72e9cfea99508 100644 --- a/library/proc_macro/src/lib.rs +++ b/library/proc_macro/src/lib.rs @@ -33,7 +33,7 @@ #![feature(min_specialization)] #![feature(strict_provenance)] #![recursion_limit = "256"] -#![feature(global_co_alloc_def)] +#![feature(global_co_alloc_default)] #[unstable(feature = "proc_macro_internals", issue = "27812")] #[doc(hidden)] From 71b8f3d78725561b87aa47721db3110b2e6ba03c Mon Sep 17 00:00:00 2001 From: Peter Kehl Date: Wed, 25 Jan 2023 12:54:01 -0800 Subject: [PATCH 081/118] CoAlloc: Removed co_alloc_metadata_num_slots(). Added docs. --- library/alloc/src/boxed.rs | 14 +++----------- library/core/src/alloc/mod.rs | 17 +++++------------ 2 files changed, 8 insertions(+), 23 deletions(-) diff --git a/library/alloc/src/boxed.rs b/library/alloc/src/boxed.rs index 1daba5600696a..a2bc62c5bdc2f 100644 --- a/library/alloc/src/boxed.rs +++ b/library/alloc/src/boxed.rs @@ -749,7 +749,7 @@ impl Box<[T]> { impl Box<[T], A> where - [(); core::alloc::co_alloc_metadata_num_slots::()]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(false)]:, { /// Constructs a new boxed slice with uninitialized contents in the provided allocator. /// @@ -778,11 +778,7 @@ where // #[unstable(feature = "new_uninit", issue = "63291")] #[must_use] #[allow(unused_braces)] - pub fn new_uninit_slice_in(len: usize, alloc: A) -> Box<[mem::MaybeUninit], A> - where - // false = no need for co-alloc metadata, since it would get lost once converted to Box. - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(false)]:, - { + pub fn new_uninit_slice_in(len: usize, alloc: A) -> Box<[mem::MaybeUninit], A> { unsafe { RawVec::::with_capacity_in(len, alloc).into_box(len) } } @@ -811,11 +807,7 @@ where // #[unstable(feature = "new_uninit", issue = "63291")] #[must_use] #[allow(unused_braces)] - pub fn new_zeroed_slice_in(len: usize, alloc: A) -> Box<[mem::MaybeUninit], A> - where - // false = no need for co-alloc metadata, since it would get lost once converted to Box. - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(false)]:, - { + pub fn new_zeroed_slice_in(len: usize, alloc: A) -> Box<[mem::MaybeUninit], A> { unsafe { RawVec::::with_capacity_zeroed_in(len, alloc).into_box(len) } } } diff --git a/library/core/src/alloc/mod.rs b/library/core/src/alloc/mod.rs index c0d2af6098378..b2474072af3e4 100644 --- a/library/core/src/alloc/mod.rs +++ b/library/core/src/alloc/mod.rs @@ -65,6 +65,7 @@ impl fmt::Display for AllocError { } } +/// (Non-Null) Pointer and coallocation metadata. #[unstable(feature = "global_co_alloc_meta", issue = "none")] #[allow(missing_debug_implementations)] pub struct PtrAndMeta { @@ -72,6 +73,7 @@ pub struct PtrAndMeta { pub meta: GlobalCoAllocMeta, } +/// (NonNull) Slice and coallocation metadata. #[unstable(feature = "global_co_alloc_meta", issue = "none")] #[allow(missing_debug_implementations)] /// Used for results (from `CoAllocator`'s functions, where applicable). @@ -89,24 +91,15 @@ macro_rules! SHORT_TERM_VEC_PREFERS_COOP { }; } +/// `Result` of `SliceAndMeta` or `AllocError`. #[unstable(feature = "global_co_alloc_meta", issue = "none")] #[allow(missing_debug_implementations)] pub type SliceAndMetaResult = Result; -#[unstable(feature = "global_co_alloc", issue = "none")] -pub const fn co_alloc_metadata_num_slots() -> usize { - // @FIXME later - if false { - panic!( - "FIXME - consider replacing co_alloc_metadata_num_slots() with co_alloc_metadata_num_slots_with_preference(bool), and adding const flags as appropriate." - ); - } - if A::IS_CO_ALLOCATOR { 1 } else { 0 } -} - -#[unstable(feature = "global_co_alloc", issue = "none")] +/// Return 0 or 1, indicating whether to use coallocation metadata or not. /// Param `coop_preferred` - if false, then this returns `0`, regardless of /// whether allocator `A` is cooperative. +#[unstable(feature = "global_co_alloc", issue = "none")] pub const fn co_alloc_metadata_num_slots_with_preference( coop_preferred: bool, ) -> usize { From ddb3a415f563e570a52ca720783eeec50db21195 Mon Sep 17 00:00:00 2001 From: Peter Kehl Date: Wed, 25 Jan 2023 16:37:20 -0800 Subject: [PATCH 082/118] CoAlloc: Move + rename macros DEFAULT_COOP_PREF + meta_num_slots* macros to ::alloc --- library/alloc/src/macros.rs | 139 ++++++++++++++++++++++++++++-------- 1 file changed, 109 insertions(+), 30 deletions(-) diff --git a/library/alloc/src/macros.rs b/library/alloc/src/macros.rs index 5198bf297d925..5fd5ed021e8a4 100644 --- a/library/alloc/src/macros.rs +++ b/library/alloc/src/macros.rs @@ -1,7 +1,7 @@ /// Creates a [`Vec`] containing the arguments. /// -/// `vec!` allows `Vec`s to be defined with the same syntax as array expressions. -/// There are two forms of this macro: +/// `vec!` allows `Vec`s to be defined with the same syntax as array expressions. There are two +/// forms of this macro: /// /// - Create a [`Vec`] containing a given list of elements: /// @@ -19,19 +19,17 @@ /// assert_eq!(v, [1, 1, 1]); /// ``` /// -/// Note that unlike array expressions this syntax supports all elements -/// which implement [`Clone`] and the number of elements doesn't have to be -/// a constant. +/// Note that unlike array expressions this syntax supports all elements which implement [`Clone`] +/// and the number of elements doesn't have to be a constant. /// -/// This will use `clone` to duplicate an expression, so one should be careful -/// using this with types having a nonstandard `Clone` implementation. For -/// example, `vec![Rc::new(1); 5]` will create a vector of five references -/// to the same boxed integer value, not five references pointing to independently -/// boxed integers. +/// This will use `clone` to duplicate an expression, so one should be careful using this with types +/// having a nonstandard `Clone` implementation. For example, `vec![Rc::new(1); 5]` will create a +/// vector of five references to the same boxed integer value, not five references pointing to +/// independently boxed integers. /// -/// Also, note that `vec![expr; 0]` is allowed, and produces an empty vector. -/// This will still evaluate `expr`, however, and immediately drop the resulting value, so -/// be mindful of side effects. +/// Also, note that `vec![expr; 0]` is allowed, and produces an empty vector. This will still +/// evaluate `expr`, however, and immediately drop the resulting value, so be mindful of side +/// effects. /// /// [`Vec`]: crate::vec::Vec #[cfg(all(not(no_global_oom_handling), not(test)))] @@ -54,10 +52,9 @@ macro_rules! vec { ); } -// HACK(japaric): with cfg(test) the inherent `[T]::into_vec` method, which is -// required for this macro definition, is not available. Instead use the -// `slice::into_vec` function which is only available with cfg(test) -// NB see the slice::hack module in slice.rs for more information +// HACK(japaric): with cfg(test) the inherent `[T]::into_vec` method, which is required for this +// macro definition, is not available. Instead use the `slice::into_vec` function which is only +// available with cfg(test) NB see the slice::hack module in slice.rs for more information #[cfg(all(not(no_global_oom_handling), test))] #[allow(unused_macro_rules)] macro_rules! vec { @@ -75,19 +72,18 @@ macro_rules! vec { /// Creates a `String` using interpolation of runtime expressions. /// -/// The first argument `format!` receives is a format string. This must be a string -/// literal. The power of the formatting string is in the `{}`s contained. +/// The first argument `format!` receives is a format string. This must be a string literal. The +/// power of the formatting string is in the `{}`s contained. /// -/// Additional parameters passed to `format!` replace the `{}`s within the -/// formatting string in the order given unless named or positional parameters -/// are used; see [`std::fmt`] for more information. +/// Additional parameters passed to `format!` replace the `{}`s within the formatting string in the +/// order given unless named or positional parameters are used; see [`std::fmt`] for more +/// information. /// -/// A common use for `format!` is concatenation and interpolation of strings. -/// The same convention is used with [`print!`] and [`write!`] macros, -/// depending on the intended destination of the string. +/// A common use for `format!` is concatenation and interpolation of strings. The same convention is +/// used with [`print!`] and [`write!`] macros, depending on the intended destination of the string. /// -/// To convert a single value to a string, use the [`to_string`] method. This -/// will use the [`Display`] formatting trait. +/// To convert a single value to a string, use the [`to_string`] method. This will use the +/// [`Display`] formatting trait. /// /// [`std::fmt`]: ../std/fmt/index.html /// [`print!`]: ../std/macro.print.html @@ -97,9 +93,8 @@ macro_rules! vec { /// /// # Panics /// -/// `format!` panics if a formatting trait implementation returns an error. -/// This indicates an incorrect implementation -/// since `fmt::Write for String` never returns an error itself. +/// `format!` panics if a formatting trait implementation returns an error. This indicates an +/// incorrect implementation since `fmt::Write for String` never returns an error itself. /// /// # Examples /// @@ -129,3 +124,87 @@ macro_rules! __rust_force_expr { $e }; } + +/// Default coallocation "cooperation" (`COOP_PREF`) generic parameter. +/// +/// NOT for public use. It's exported only so that library/proc_macro (and other internals) can use +/// this. +/// +// FIXME replace with a `const` (or some kind of compile time preference) once a related ICE is +// fixed. Then move the const to a submodule, for example alloc::co_alloc. +#[unstable(feature = "global_co_alloc_default", issue = "none")] +#[macro_export] +macro_rules! DEFAULT_COOP_PREF { + () => { + true + }; +} +// -\---> replace with something like: pub const DEFAULT_COOP_PREF: bool = true; + +/// Return 0 or 1, indicating whether to use coallocation metadata (or not) with the given allocator +/// type `alloc` and cooperation preference `coop_pref`. +/// +/// NOT for public use. Param `coop_pref` - can override the allocator's default preference for +/// cooperation, or can make the type not cooperative, regardless of whether allocator `A` is +/// cooperative. +// FIXME replace the macro with an (updated version of the below) `const` function). Only once +// generic_const_exprs is stable (that is, when consumer crates don't need to declare +// generic_const_exprs feature anymore). Then move the function to a submodule, for example +// ::alloc::co_alloc. +#[unstable(feature = "global_co_alloc", issue = "none")] +#[macro_export] +macro_rules! meta_num_slots { + ($alloc:ty, $coop_pref:expr) => { + if ($alloc::IS_CO_ALLOCATOR) && ($coop_pref) { 1 } else { 0 } + }; +} +// -\---> replace with something like: +/* +#[unstable(feature = "global_co_alloc", issue = "none")] +pub const fn meta_num_slots( + COOP_PREF: bool, +) -> usize { + if A::IS_CO_ALLOCATOR && COOP_PREF { 1 } else { 0 } +} +*/ + +/// Like `meta_num_slots`, but for the default coallocation preference (`DEFAULT_COOP_PREF`). +/// +/// Return 0 or 1, indicating whether to use coallocation metadata (or not) with the given allocator +/// type `alloc` and the default cooperation preference (`DEFAULT_COOP_PREF()!`). +/// +/// NOT for public use. +// FIXME replace the macro with a `const` function. Only once generic_const_exprs is stable (that +// is, when consumer crates don't need to declare generic_const_exprs feature anymore). Then move +// the function to a submodule, for example ::alloc::co_alloc. +#[unstable(feature = "global_co_alloc", issue = "none")] +#[macro_export] +macro_rules! meta_num_slots_default { + ($alloc:ty) => { + if ($alloc::IS_CO_ALLOCATOR) && (DEFAULT_COOP_PREF!()) { 1 } else { 0 } + }; +} + +/// NOT for public use. +// See above. +#[unstable(feature = "global_co_alloc", issue = "none")] +#[macro_export] +macro_rules! meta_num_slots_global { + ($coop_pref:expr) => { + if ::alloc::alloc::Global::IS_CO_ALLOCATOR && ($coop_pref) { 1 } else { 0 } + }; +} + +/// Like `meta_num_slots`, but for Global allocator and default coallocation preference +/// (`DEFAULT_COOP_PREF`). +/// +/// NOT for public use. +// @FIXME once generic_const_exprs is stable, replace this with a `const` function. Then move the +// function to a submodule, for example alloc::co_alloc. See above. +#[unstable(feature = "global_co_alloc", issue = "none")] +#[macro_export] +macro_rules! meta_num_slots_default_global { + () => { + if ::alloc::alloc::Global::IS_CO_ALLOCATOR && (DEFAULT_COOP_PREF!()) { 1 } else { 0 } + }; +} From 327596ae58f0d3265f1ce4aa2c4b79f75f251559 Mon Sep 17 00:00:00 2001 From: Peter Kehl Date: Wed, 25 Jan 2023 16:40:27 -0800 Subject: [PATCH 083/118] CoAlloc: Using the new macros (not everywhere yet). --- library/alloc/src/boxed.rs | 8 +- .../alloc/src/collections/binary_heap/mod.rs | 26 +- .../alloc/src/collections/vec_deque/drain.rs | 66 ++--- .../src/collections/vec_deque/into_iter.rs | 46 ++-- .../alloc/src/collections/vec_deque/macros.rs | 4 +- .../alloc/src/collections/vec_deque/mod.rs | 192 +++++++------- .../src/collections/vec_deque/spec_extend.rs | 36 +-- .../collections/vec_deque/spec_from_iter.rs | 22 +- library/alloc/src/ffi/c_str.rs | 4 +- library/alloc/src/raw_vec.rs | 40 +-- library/alloc/src/rc.rs | 8 +- library/alloc/src/slice.rs | 66 ++--- library/alloc/src/str.rs | 6 +- library/alloc/src/vec/drain.rs | 74 +++--- library/alloc/src/vec/drain_filter.rs | 34 +-- library/alloc/src/vec/in_place_collect.rs | 4 +- library/alloc/src/vec/into_iter.rs | 116 ++++---- library/alloc/src/vec/mod.rs | 249 +++++++++--------- library/alloc/src/vec/partial_eq.rs | 20 +- library/alloc/src/vec/spec_extend.rs | 26 +- library/alloc/src/vec/spec_from_elem.rs | 30 +-- library/alloc/src/vec/spec_from_iter.rs | 10 +- .../alloc/src/vec/spec_from_iter_nested.rs | 10 +- library/alloc/src/vec/splice.rs | 34 +-- library/proc_macro/src/bridge/mod.rs | 4 +- library/proc_macro/src/bridge/rpc.rs | 6 +- library/proc_macro/src/diagnostic.rs | 2 +- library/std/src/io/cursor.rs | 32 +-- library/std/src/io/impls.rs | 12 +- 29 files changed, 588 insertions(+), 599 deletions(-) diff --git a/library/alloc/src/boxed.rs b/library/alloc/src/boxed.rs index a2bc62c5bdc2f..e70bb2fad17fc 100644 --- a/library/alloc/src/boxed.rs +++ b/library/alloc/src/boxed.rs @@ -1679,12 +1679,12 @@ impl TryFrom> for Box<[T; N]> { #[cfg(not(no_global_oom_handling))] #[stable(feature = "boxed_array_try_from_vec", since = "1.66.0")] -impl TryFrom> +impl TryFrom> for Box<[T; N]> where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { - type Error = Vec; + type Error = Vec; /// Attempts to convert a `Vec` into a `Box<[T; N]>`. /// @@ -1704,7 +1704,7 @@ where /// let state: Box<[f32; 100]> = vec![1.0; 100].try_into().unwrap(); /// assert_eq!(state.len(), 100); /// ``` - fn try_from(vec: Vec) -> Result { + fn try_from(vec: Vec) -> Result { if vec.len() == N { let boxed_slice = vec.into_boxed_slice(); Ok(unsafe { boxed_slice_as_array_unchecked(boxed_slice) }) diff --git a/library/alloc/src/collections/binary_heap/mod.rs b/library/alloc/src/collections/binary_heap/mod.rs index 05dfaa92f385b..4c07cc01a1576 100644 --- a/library/alloc/src/collections/binary_heap/mod.rs +++ b/library/alloc/src/collections/binary_heap/mod.rs @@ -155,7 +155,7 @@ use crate::alloc::Global; use crate::collections::TryReserveError; use crate::slice; use crate::vec::{self, AsVecIntoIter, Vec}; -use crate::DEFAULT_COOP_PREFERRED; +use crate::DEFAULT_COOP_PREF; use super::SpecExtend; @@ -1525,17 +1525,17 @@ unsafe impl TrustedLen for IntoIterSorted {} /// [`drain`]: BinaryHeap::drain #[stable(feature = "drain", since = "1.6.0")] #[derive(Debug)] -pub struct Drain<'a, T: 'a, const COOP_PREFERRED: bool> +pub struct Drain<'a, T: 'a, const COOP_PREF: bool> where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { - iter: vec::Drain<'a, T, Global, COOP_PREFERRED>, + iter: vec::Drain<'a, T, Global, COOP_PREF>, } #[stable(feature = "drain", since = "1.6.0")] -impl Iterator for Drain<'_, T, COOP_PREFERRED> +impl Iterator for Drain<'_, T, COOP_PREF> where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { type Item = T; @@ -1551,9 +1551,9 @@ where } #[stable(feature = "drain", since = "1.6.0")] -impl DoubleEndedIterator for Drain<'_, T, COOP_PREFERRED> +impl DoubleEndedIterator for Drain<'_, T, COOP_PREF> where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { #[inline] fn next_back(&mut self) -> Option { @@ -1562,9 +1562,9 @@ where } #[stable(feature = "drain", since = "1.6.0")] -impl ExactSizeIterator for Drain<'_, T, COOP_PREFERRED> +impl ExactSizeIterator for Drain<'_, T, COOP_PREF> where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { fn is_empty(&self) -> bool { self.iter.is_empty() @@ -1572,8 +1572,8 @@ where } #[stable(feature = "fused", since = "1.26.0")] -impl FusedIterator for Drain<'_, T, COOP_PREFERRED> where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: +impl FusedIterator for Drain<'_, T, COOP_PREF> where + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]: { } @@ -1664,7 +1664,7 @@ impl From<[T; N]> for BinaryHeap { #[stable(feature = "binary_heap_extras_15", since = "1.5.0")] #[allow(unused_braces)] -impl From> for Vec { +impl From> for Vec { /// Converts a `BinaryHeap` into a `Vec`. /// /// This conversion requires no data movement or allocation, and has diff --git a/library/alloc/src/collections/vec_deque/drain.rs b/library/alloc/src/collections/vec_deque/drain.rs index cd0e6caace3f4..70521a580d653 100644 --- a/library/alloc/src/collections/vec_deque/drain.rs +++ b/library/alloc/src/collections/vec_deque/drain.rs @@ -20,13 +20,13 @@ pub struct Drain< 'a, T: 'a, #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global, - const COOP_PREFERRED: bool = { SHORT_TERM_VEC_PREFERS_COOP!() }, + const COOP_PREF: bool = { SHORT_TERM_VEC_PREFERS_COOP!() }, > where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { // We can't just use a &mut VecDeque, as that would make Drain invariant over T // and we want it to be covariant instead - deque: NonNull>, + deque: NonNull>, // drain_start is stored in deque.len drain_len: usize, // index into the logical array, not the physical one (always lies in [0..deque.len)) @@ -38,12 +38,12 @@ pub struct Drain< _marker: PhantomData<&'a T>, } -impl<'a, T, A: Allocator, const COOP_PREFERRED: bool> Drain<'a, T, A, COOP_PREFERRED> +impl<'a, T, A: Allocator, const COOP_PREF: bool> Drain<'a, T, A, COOP_PREF> where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { pub(super) unsafe fn new( - deque: &'a mut VecDeque, + deque: &'a mut VecDeque, drain_start: usize, drain_len: usize, ) -> Self { @@ -95,10 +95,10 @@ where } #[stable(feature = "collection_debug", since = "1.17.0")] -impl fmt::Debug - for Drain<'_, T, A, COOP_PREFERRED> +impl fmt::Debug + for Drain<'_, T, A, COOP_PREF> where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_tuple("Drain") @@ -111,36 +111,36 @@ where } #[stable(feature = "drain", since = "1.6.0")] -unsafe impl Sync - for Drain<'_, T, A, COOP_PREFERRED> +unsafe impl Sync + for Drain<'_, T, A, COOP_PREF> where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { } #[stable(feature = "drain", since = "1.6.0")] -unsafe impl Send - for Drain<'_, T, A, COOP_PREFERRED> +unsafe impl Send + for Drain<'_, T, A, COOP_PREF> where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { } #[stable(feature = "drain", since = "1.6.0")] -impl Drop for Drain<'_, T, A, COOP_PREFERRED> +impl Drop for Drain<'_, T, A, COOP_PREF> where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { fn drop(&mut self) { - struct DropGuard<'r, 'a, T, A: Allocator, const COOP_PREFERRED: bool>( - &'r mut Drain<'a, T, A, COOP_PREFERRED>, + struct DropGuard<'r, 'a, T, A: Allocator, const COOP_PREF: bool>( + &'r mut Drain<'a, T, A, COOP_PREF>, ) where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:; + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:; - impl<'r, 'a, T, A: Allocator, const COOP_PREFERRED: bool> Drop - for DropGuard<'r, 'a, T, A, COOP_PREFERRED> + impl<'r, 'a, T, A: Allocator, const COOP_PREF: bool> Drop + for DropGuard<'r, 'a, T, A, COOP_PREF> where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { fn drop(&mut self) { if self.0.remaining != 0 { @@ -222,9 +222,9 @@ where } #[stable(feature = "drain", since = "1.6.0")] -impl Iterator for Drain<'_, T, A, COOP_PREFERRED> +impl Iterator for Drain<'_, T, A, COOP_PREF> where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { type Item = T; @@ -247,10 +247,10 @@ where } #[stable(feature = "drain", since = "1.6.0")] -impl DoubleEndedIterator - for Drain<'_, T, A, COOP_PREFERRED> +impl DoubleEndedIterator + for Drain<'_, T, A, COOP_PREF> where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { #[inline] fn next_back(&mut self) -> Option { @@ -264,15 +264,15 @@ where } #[stable(feature = "drain", since = "1.6.0")] -impl ExactSizeIterator - for Drain<'_, T, A, COOP_PREFERRED> +impl ExactSizeIterator + for Drain<'_, T, A, COOP_PREF> where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { } #[stable(feature = "fused", since = "1.26.0")] -impl FusedIterator for Drain<'_, T, A, COOP_PREFERRED> where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: +impl FusedIterator for Drain<'_, T, A, COOP_PREF> where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]: { } diff --git a/library/alloc/src/collections/vec_deque/into_iter.rs b/library/alloc/src/collections/vec_deque/into_iter.rs index f3f50e3048bc6..83e9c35bd40bc 100644 --- a/library/alloc/src/collections/vec_deque/into_iter.rs +++ b/library/alloc/src/collections/vec_deque/into_iter.rs @@ -17,31 +17,31 @@ use super::VecDeque; pub struct IntoIter< T, #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global, - const COOP_PREFERRED: bool = true, + const COOP_PREF: bool = true, > where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { - inner: VecDeque, + inner: VecDeque, } -impl IntoIter +impl IntoIter where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { - pub(super) fn new(inner: VecDeque) -> Self { + pub(super) fn new(inner: VecDeque) -> Self { IntoIter { inner } } - pub(super) fn into_vecdeque(self) -> VecDeque { + pub(super) fn into_vecdeque(self) -> VecDeque { self.inner } } #[stable(feature = "collection_debug", since = "1.17.0")] -impl fmt::Debug - for IntoIter +impl fmt::Debug + for IntoIter where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_tuple("IntoIter").field(&self.inner).finish() @@ -49,9 +49,9 @@ where } #[stable(feature = "rust1", since = "1.0.0")] -impl Iterator for IntoIter +impl Iterator for IntoIter where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { type Item = T; @@ -188,10 +188,10 @@ where } #[stable(feature = "rust1", since = "1.0.0")] -impl DoubleEndedIterator - for IntoIter +impl DoubleEndedIterator + for IntoIter where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { #[inline] fn next_back(&mut self) -> Option { @@ -262,10 +262,10 @@ where } #[stable(feature = "rust1", since = "1.0.0")] -impl ExactSizeIterator - for IntoIter +impl ExactSizeIterator + for IntoIter where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { #[inline] fn is_empty(&self) -> bool { @@ -274,15 +274,15 @@ where } #[stable(feature = "fused", since = "1.26.0")] -impl FusedIterator for IntoIter where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: +impl FusedIterator for IntoIter where + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]: { } #[unstable(feature = "trusted_len", issue = "37572")] -unsafe impl TrustedLen - for IntoIter +unsafe impl TrustedLen + for IntoIter where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { } diff --git a/library/alloc/src/collections/vec_deque/macros.rs b/library/alloc/src/collections/vec_deque/macros.rs index 68ee43152b5b5..c31a89a7df337 100644 --- a/library/alloc/src/collections/vec_deque/macros.rs +++ b/library/alloc/src/collections/vec_deque/macros.rs @@ -1,10 +1,10 @@ macro_rules! __impl_slice_eq1 { ([$($vars:tt)*] $lhs:ty, $rhs:ty, $($constraints:tt)*) => { #[stable(feature = "vec_deque_partial_eq_slice", since = "1.17.0")] - impl PartialEq<$rhs> for $lhs + impl PartialEq<$rhs> for $lhs where T: PartialEq, - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, $($constraints)* { fn eq(&self, other: &$rhs) -> bool { diff --git a/library/alloc/src/collections/vec_deque/mod.rs b/library/alloc/src/collections/vec_deque/mod.rs index e98087ea9ad93..8e5331f88c25d 100644 --- a/library/alloc/src/collections/vec_deque/mod.rs +++ b/library/alloc/src/collections/vec_deque/mod.rs @@ -7,7 +7,7 @@ #![feature(global_co_alloc)] #![stable(feature = "rust1", since = "1.0.0")] -use crate::DEFAULT_COOP_PREFERRED; +use crate::DEFAULT_COOP_PREF; use core::alloc; use core::cmp::{self, Ordering}; use core::fmt; @@ -97,9 +97,9 @@ mod tests; pub struct VecDeque< T, #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global, - const COOP_PREFERRED: bool = { DEFAULT_COOP_PREFERRED!() }, + const COOP_PREF: bool = { DEFAULT_COOP_PREF!() }, > where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { // `self[0]`, if it exists, is `buf[head]`. // `head < buf.capacity()`, unless `buf.capacity() == 0` when `head == 0`. @@ -108,14 +108,14 @@ pub struct VecDeque< // if `len == 0`, the exact value of `head` is unimportant. // if `T` is zero-Sized, then `self.len <= usize::MAX`, otherwise `self.len <= isize::MAX as usize`. len: usize, - buf: RawVec, + buf: RawVec, } #[stable(feature = "rust1", since = "1.0.0")] -impl Clone - for VecDeque +impl Clone + for VecDeque where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { fn clone(&self) -> Self { let mut deq = Self::with_capacity_in(self.len(), self.allocator().clone()); @@ -130,10 +130,10 @@ where } #[stable(feature = "rust1", since = "1.0.0")] -unsafe impl<#[may_dangle] T, A: Allocator, const COOP_PREFERRED: bool> Drop - for VecDeque +unsafe impl<#[may_dangle] T, A: Allocator, const COOP_PREF: bool> Drop + for VecDeque where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { fn drop(&mut self) { /// Runs the destructor for all items in the slice when it gets dropped (normally or @@ -159,20 +159,20 @@ where } #[stable(feature = "rust1", since = "1.0.0")] -impl Default for VecDeque +impl Default for VecDeque where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { /// Creates an empty deque. #[inline] - fn default() -> VecDeque { - VecDeque::::new() + fn default() -> VecDeque { + VecDeque::::new() } } -impl VecDeque +impl VecDeque where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { /// Marginally more convenient #[inline] @@ -462,17 +462,17 @@ where mut iter: impl Iterator, len: usize, ) -> usize { - struct Guard<'a, T, A: Allocator, const COOP_PREFERRED: bool> + struct Guard<'a, T, A: Allocator, const COOP_PREF: bool> where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { - deque: &'a mut VecDeque, + deque: &'a mut VecDeque, written: usize, } - impl<'a, T, A: Allocator, const COOP_PREFERRED: bool> Drop for Guard<'a, T, A, COOP_PREFERRED> + impl<'a, T, A: Allocator, const COOP_PREF: bool> Drop for Guard<'a, T, A, COOP_PREF> where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { fn drop(&mut self) { self.deque.len += self.written; @@ -551,10 +551,10 @@ where } } -impl VecDeque +impl VecDeque where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { /// Creates an empty deque. /// @@ -569,9 +569,9 @@ where #[stable(feature = "rust1", since = "1.0.0")] #[rustc_const_stable(feature = "const_vec_deque_new", since = "1.68.0")] #[must_use] - pub const fn new() -> VecDeque + pub const fn new() -> VecDeque where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { // FIXME: This should just be `VecDeque::new_in(Global)` once that hits stable. VecDeque { head: 0, len: 0, buf: RawVec::NEW } @@ -589,14 +589,14 @@ where #[inline] #[stable(feature = "rust1", since = "1.0.0")] #[must_use] - pub fn with_capacity(capacity: usize) -> VecDeque { - VecDeque::::with_capacity_in(capacity, Global) + pub fn with_capacity(capacity: usize) -> VecDeque { + VecDeque::::with_capacity_in(capacity, Global) } } -impl VecDeque +impl VecDeque where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { /// Creates an empty deque. /// @@ -609,7 +609,7 @@ where /// ``` #[inline] #[unstable(feature = "allocator_api", issue = "32838")] - pub const fn new_in(alloc: A) -> VecDeque { + pub const fn new_in(alloc: A) -> VecDeque { VecDeque { head: 0, len: 0, buf: RawVec::new_in(alloc) } } @@ -623,7 +623,7 @@ where /// let deque: VecDeque = VecDeque::with_capacity(10); /// ``` #[unstable(feature = "allocator_api", issue = "32838")] - pub fn with_capacity_in(capacity: usize, alloc: A) -> VecDeque { + pub fn with_capacity_in(capacity: usize, alloc: A) -> VecDeque { VecDeque { head: 0, len: 0, buf: RawVec::with_capacity_in(capacity, alloc) } } @@ -1404,7 +1404,7 @@ where /// ``` #[inline] #[stable(feature = "drain", since = "1.6.0")] - pub fn drain(&mut self, range: R) -> Drain<'_, T, A, COOP_PREFERRED> + pub fn drain(&mut self, range: R) -> Drain<'_, T, A, COOP_PREF> where R: RangeBounds, { @@ -2632,9 +2632,9 @@ where } } -impl VecDeque +impl VecDeque where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { /// Modifies the deque in-place so that `len()` is equal to new_len, /// either by removing excess elements from the back or by appending clones of `value` @@ -2680,10 +2680,10 @@ fn wrap_index(logical_index: usize, capacity: usize) -> usize { } #[stable(feature = "rust1", since = "1.0.0")] -impl PartialEq - for VecDeque +impl PartialEq + for VecDeque where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { fn eq(&self, other: &Self) -> bool { if self.len != other.len() { @@ -2723,23 +2723,23 @@ where } #[stable(feature = "rust1", since = "1.0.0")] -impl Eq for VecDeque where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: +impl Eq for VecDeque where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]: { } -__impl_slice_eq1! { [] VecDeque, Vec, } -__impl_slice_eq1! { [] VecDeque, &[U], } -__impl_slice_eq1! { [] VecDeque, &mut [U], } -__impl_slice_eq1! { [const N: usize] VecDeque, [U; N], } -__impl_slice_eq1! { [const N: usize] VecDeque, &[U; N], } -__impl_slice_eq1! { [const N: usize] VecDeque, &mut [U; N], } +__impl_slice_eq1! { [] VecDeque, Vec, } +__impl_slice_eq1! { [] VecDeque, &[U], } +__impl_slice_eq1! { [] VecDeque, &mut [U], } +__impl_slice_eq1! { [const N: usize] VecDeque, [U; N], } +__impl_slice_eq1! { [const N: usize] VecDeque, &[U; N], } +__impl_slice_eq1! { [const N: usize] VecDeque, &mut [U; N], } #[stable(feature = "rust1", since = "1.0.0")] -impl PartialOrd - for VecDeque +impl PartialOrd + for VecDeque where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { fn partial_cmp(&self, other: &Self) -> Option { self.iter().partial_cmp(other.iter()) @@ -2747,9 +2747,9 @@ where } #[stable(feature = "rust1", since = "1.0.0")] -impl Ord for VecDeque +impl Ord for VecDeque where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { #[inline] fn cmp(&self, other: &Self) -> Ordering { @@ -2758,9 +2758,9 @@ where } #[stable(feature = "rust1", since = "1.0.0")] -impl Hash for VecDeque +impl Hash for VecDeque where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { fn hash(&self, state: &mut H) { state.write_length_prefix(self.len); @@ -2775,9 +2775,9 @@ where } #[stable(feature = "rust1", since = "1.0.0")] -impl Index for VecDeque +impl Index for VecDeque where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { type Output = T; @@ -2788,9 +2788,9 @@ where } #[stable(feature = "rust1", since = "1.0.0")] -impl IndexMut for VecDeque +impl IndexMut for VecDeque where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { #[inline] fn index_mut(&mut self, index: usize) -> &mut T { @@ -2799,35 +2799,35 @@ where } #[stable(feature = "rust1", since = "1.0.0")] -impl FromIterator for VecDeque +impl FromIterator for VecDeque where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { - fn from_iter>(iter: I) -> VecDeque { + fn from_iter>(iter: I) -> VecDeque { SpecFromIter::spec_from_iter(iter.into_iter()) } } #[stable(feature = "rust1", since = "1.0.0")] -impl IntoIterator for VecDeque +impl IntoIterator for VecDeque where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { type Item = T; - type IntoIter = IntoIter; + type IntoIter = IntoIter; /// Consumes the deque into a front-to-back iterator yielding elements by /// value. - fn into_iter(self) -> IntoIter { + fn into_iter(self) -> IntoIter { IntoIter::new(self) } } #[stable(feature = "rust1", since = "1.0.0")] -impl<'a, T, A: Allocator, const COOP_PREFERRED: bool> IntoIterator - for &'a VecDeque +impl<'a, T, A: Allocator, const COOP_PREF: bool> IntoIterator + for &'a VecDeque where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { type Item = &'a T; type IntoIter = Iter<'a, T>; @@ -2838,10 +2838,10 @@ where } #[stable(feature = "rust1", since = "1.0.0")] -impl<'a, T, A: Allocator, const COOP_PREFERRED: bool> IntoIterator - for &'a mut VecDeque +impl<'a, T, A: Allocator, const COOP_PREF: bool> IntoIterator + for &'a mut VecDeque where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { type Item = &'a mut T; type IntoIter = IterMut<'a, T>; @@ -2852,9 +2852,9 @@ where } #[stable(feature = "rust1", since = "1.0.0")] -impl Extend for VecDeque +impl Extend for VecDeque where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { fn extend>(&mut self, iter: I) { >::spec_extend(self, iter.into_iter()); @@ -2872,10 +2872,10 @@ where } #[stable(feature = "extend_ref", since = "1.2.0")] -impl<'a, T: 'a + Copy, A: Allocator, const COOP_PREFERRED: bool> Extend<&'a T> - for VecDeque +impl<'a, T: 'a + Copy, A: Allocator, const COOP_PREF: bool> Extend<&'a T> + for VecDeque where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { fn extend>(&mut self, iter: I) { self.spec_extend(iter.into_iter()); @@ -2893,10 +2893,10 @@ where } #[stable(feature = "rust1", since = "1.0.0")] -impl fmt::Debug - for VecDeque +impl fmt::Debug + for VecDeque where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_list().entries(self.iter()).finish() @@ -2904,11 +2904,11 @@ where } #[stable(feature = "vecdeque_vec_conversions", since = "1.10.0")] -impl - From> for VecDeque +impl + From> for VecDeque where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(OTHER_COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(OTHER_COOP_PREF)]:, { /// Turn a [`Vec`] into a [`VecDeque`]. /// @@ -2919,22 +2919,22 @@ where /// and to not re-allocate the `Vec`'s buffer or allocate /// any additional memory. #[inline] - fn from(other: Vec) -> Self { + fn from(other: Vec) -> Self { let (ptr, len, cap, alloc) = other.into_raw_parts_with_alloc(); Self { head: 0, len, - buf: unsafe { RawVec::::from_raw_parts_in(ptr, cap, alloc) }, + buf: unsafe { RawVec::::from_raw_parts_in(ptr, cap, alloc) }, } } } #[stable(feature = "vecdeque_vec_conversions", since = "1.10.0")] -impl - From> for Vec +impl + From> for Vec where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(VECDEQUE_COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(VECDEQUE_COOP_PREF)]:, { /// Turn a [`VecDeque`] into a [`Vec`]. /// @@ -2965,9 +2965,9 @@ where /// assert_eq!(vec, [8, 9, 1, 2, 3, 4]); /// assert_eq!(vec.as_ptr(), ptr); /// ``` - fn from(mut other: VecDeque) -> Self + fn from(mut other: VecDeque) -> Self where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(VECDEQUE_COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(VECDEQUE_COOP_PREF)]:, { other.make_contiguous(); @@ -2982,16 +2982,16 @@ where ptr::copy(buf.add(other.head), buf, len); } // @FIXME: COOP - Vec::::from_raw_parts_in(buf, len, cap, alloc) + Vec::::from_raw_parts_in(buf, len, cap, alloc) } } } #[stable(feature = "std_collections_from_array", since = "1.56.0")] -impl From<[T; N]> - for VecDeque +impl From<[T; N]> + for VecDeque where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { /// Converts a `[T; N]` into a `VecDeque`. /// @@ -3003,12 +3003,12 @@ where /// assert_eq!(deq1, deq2); /// ``` fn from(arr: [T; N]) -> Self { - let mut deq = VecDeque::::with_capacity(N); + let mut deq = VecDeque::::with_capacity(N); let arr = ManuallyDrop::new(arr); if !::IS_ZST { // SAFETY: VecDeque::with_capacity ensures that there is enough capacity. unsafe { - // @FIXME for COOP_PREFERRED: + // @FIXME for COOP_PREF: ptr::copy_nonoverlapping(arr.as_ptr(), deq.ptr(), N); } } diff --git a/library/alloc/src/collections/vec_deque/spec_extend.rs b/library/alloc/src/collections/vec_deque/spec_extend.rs index b1a9d23fd4a99..f4e6ff195bed2 100644 --- a/library/alloc/src/collections/vec_deque/spec_extend.rs +++ b/library/alloc/src/collections/vec_deque/spec_extend.rs @@ -13,11 +13,11 @@ pub(super) trait SpecExtend { fn spec_extend(&mut self, iter: I); } -impl SpecExtend - for VecDeque +impl SpecExtend + for VecDeque where I: Iterator, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { default fn spec_extend(&mut self, mut iter: I) { // This function should be the moral equivalent of: @@ -27,11 +27,11 @@ where // } // May only be called if `deque.len() < deque.capacity()` - unsafe fn push_unchecked( - deque: &mut VecDeque, + unsafe fn push_unchecked( + deque: &mut VecDeque, element: T, ) where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { // SAFETY: Because of the precondition, it's guaranteed that there is space // in the logical array after the last element. @@ -59,11 +59,11 @@ where } } -impl SpecExtend - for VecDeque +impl SpecExtend + for VecDeque where I: TrustedLen, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { default fn spec_extend(&mut self, iter: I) { // This is the case for a TrustedLen iterator. @@ -96,10 +96,10 @@ where } } -impl SpecExtend> - for VecDeque +impl SpecExtend> + for VecDeque where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { fn spec_extend(&mut self, mut iterator: vec::IntoIter) { let slice = iterator.as_slice(); @@ -113,23 +113,23 @@ where } } -impl<'a, T: 'a, I, A: Allocator, const COOP_PREFERRED: bool> SpecExtend<&'a T, I> - for VecDeque +impl<'a, T: 'a, I, A: Allocator, const COOP_PREF: bool> SpecExtend<&'a T, I> + for VecDeque where I: Iterator, T: Copy, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { default fn spec_extend(&mut self, iterator: I) { self.spec_extend(iterator.copied()) } } -impl<'a, T: 'a, A: Allocator, const COOP_PREFERRED: bool> SpecExtend<&'a T, slice::Iter<'a, T>> - for VecDeque +impl<'a, T: 'a, A: Allocator, const COOP_PREF: bool> SpecExtend<&'a T, slice::Iter<'a, T>> + for VecDeque where T: Copy, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { fn spec_extend(&mut self, iterator: slice::Iter<'a, T>) { let slice = iterator.as_slice(); diff --git a/library/alloc/src/collections/vec_deque/spec_from_iter.rs b/library/alloc/src/collections/vec_deque/spec_from_iter.rs index b0380260fcc44..b846ce37e7338 100644 --- a/library/alloc/src/collections/vec_deque/spec_from_iter.rs +++ b/library/alloc/src/collections/vec_deque/spec_from_iter.rs @@ -7,38 +7,38 @@ pub(super) trait SpecFromIter { fn spec_from_iter(iter: I) -> Self; } -impl SpecFromIter for VecDeque +impl SpecFromIter for VecDeque where I: Iterator, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { default fn spec_from_iter(iterator: I) -> Self { // Since converting is O(1) now, just re-use the `Vec` logic for // anything where we can't do something extra-special for `VecDeque`, // especially as that could save us some monomorphiziation work // if one uses the same iterators (like slice ones) with both. - crate::vec::Vec::::from_iter(iterator).into() + crate::vec::Vec::::from_iter(iterator).into() } } -impl SpecFromIter> - for VecDeque +impl SpecFromIter> + for VecDeque where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { #[inline] - fn spec_from_iter(iterator: crate::vec::IntoIter) -> Self { + fn spec_from_iter(iterator: crate::vec::IntoIter) -> Self { iterator.into_vecdeque() } } -impl SpecFromIter> - for VecDeque +impl SpecFromIter> + for VecDeque where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { #[inline] - fn spec_from_iter(iterator: IntoIter) -> Self { + fn spec_from_iter(iterator: IntoIter) -> Self { iterator.into_vecdeque() } } diff --git a/library/alloc/src/ffi/c_str.rs b/library/alloc/src/ffi/c_str.rs index 4def86777bef4..97d19f03828d7 100644 --- a/library/alloc/src/ffi/c_str.rs +++ b/library/alloc/src/ffi/c_str.rs @@ -8,7 +8,7 @@ use crate::rc::Rc; use crate::slice::hack::into_vec; use crate::string::String; use crate::vec::Vec; -use crate::DEFAULT_COOP_PREFERRED; +use crate::DEFAULT_COOP_PREF; use core::borrow::Borrow; use core::ffi::{c_char, CStr}; use core::fmt; @@ -726,7 +726,7 @@ impl fmt::Debug for CString { #[stable(feature = "cstring_into", since = "1.7.0")] #[allow(unused_braces)] -impl From for Vec { +impl From for Vec { /// Converts a [`CString`] into a [Vec]<[u8]>. /// /// The conversion consumes the [`CString`], and removes the terminating NUL byte. diff --git a/library/alloc/src/raw_vec.rs b/library/alloc/src/raw_vec.rs index c7a9606b65c86..3398ff40cda06 100644 --- a/library/alloc/src/raw_vec.rs +++ b/library/alloc/src/raw_vec.rs @@ -14,7 +14,7 @@ use crate::alloc::{Allocator, Global, Layout}; use crate::boxed::Box; use crate::collections::TryReserveError; use crate::collections::TryReserveErrorKind::*; -use crate::DEFAULT_COOP_PREFERRED; +use crate::DEFAULT_COOP_PREF; #[cfg(test)] mod tests; @@ -54,9 +54,9 @@ enum AllocInit { pub(crate) struct RawVec< T, A: Allocator = Global, - const COOP_PREFERRED: bool = { DEFAULT_COOP_PREFERRED!() }, + const COOP_PREF: bool = { DEFAULT_COOP_PREF!() }, > where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { ptr: Unique, cap: usize, @@ -65,12 +65,12 @@ pub(crate) struct RawVec< //pub(crate) meta: [GlobalCoAllocMeta; {if core::any::TypeId::of::()==core::any::TypeId::of::() {1} else {0}}], //pub(crate) meta: [GlobalCoAllocMeta; mem::size_of::()], pub(crate) metas: [GlobalCoAllocMeta; - alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)], + alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)], } -impl RawVec +impl RawVec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { /// HACK(Centril): This exists because stable `const fn` can only call stable `const fn`, so /// they cannot call `Self::new()`. @@ -118,9 +118,9 @@ where } } -impl RawVec +impl RawVec where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { // Tiny Vecs are dumb. Skip to: // - 8 if the element size is 1, because any heap allocators is likely @@ -144,7 +144,7 @@ where cap: 0, alloc, metas: [GlobalCoAllocMeta {/*one: 1*/ /* , two: 2, three: 3, four: 4*/}; - alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)], + alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)], } } @@ -223,7 +223,7 @@ where cap: capacity, alloc, metas: [GlobalCoAllocMeta {/*one: 1*/ /*, two: 2, three: 3, four: 4*/}; - alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)], + alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)], } } } @@ -245,7 +245,7 @@ where cap: capacity, alloc, metas: [GlobalCoAllocMeta {/*one: 1*/ /*, two: 2, three: 3, four: 4*/}; - alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)], + alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)], } } @@ -315,12 +315,12 @@ where // handle_reserve behind a call, while making sure that this function is likely to be // inlined as just a comparison and a call if the comparison fails. #[cold] - fn do_reserve_and_handle( - slf: &mut RawVec, + fn do_reserve_and_handle( + slf: &mut RawVec, len: usize, additional: usize, ) where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { handle_reserve(slf.grow_amortized(len, additional)); } @@ -394,9 +394,9 @@ where } } -impl RawVec +impl RawVec where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { /// Returns if the buffer needs to grow to fulfill the needed extra capacity. /// Mainly used to make inlining reserve-calls possible without inlining `grow`. @@ -517,15 +517,15 @@ where memory.map_err(|_| AllocError { layout: new_layout, non_exhaustive: () }.into()) } -unsafe impl<#[may_dangle] T, A: Allocator, const COOP_PREFERRED: bool> Drop - for RawVec +unsafe impl<#[may_dangle] T, A: Allocator, const COOP_PREF: bool> Drop + for RawVec where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { /// Frees the memory owned by the `RawVec` *without* trying to drop its contents. default fn drop(&mut self) { if let Some((ptr, layout)) = self.current_memory() { - if A::IS_CO_ALLOCATOR && COOP_PREFERRED { + if A::IS_CO_ALLOCATOR && COOP_PREF { let meta = self.metas[0]; unsafe { self.alloc.co_deallocate(PtrAndMeta { ptr, meta }, layout) } } else { diff --git a/library/alloc/src/rc.rs b/library/alloc/src/rc.rs index a14e15549d5be..b3533ae719612 100644 --- a/library/alloc/src/rc.rs +++ b/library/alloc/src/rc.rs @@ -1987,9 +1987,9 @@ impl From> for Rc { #[cfg(not(no_global_oom_handling))] #[stable(feature = "shared_from_slice", since = "1.21.0")] -impl From> for Rc<[T]> +impl From> for Rc<[T]> where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { /// Allocate a reference-counted slice and move `v`'s items into it. /// @@ -2002,9 +2002,9 @@ where /// assert_eq!(vec![1, 2, 3], *shared); /// ``` #[inline] - fn from(mut v: Vec) -> Rc<[T]> + fn from(mut v: Vec) -> Rc<[T]> where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { unsafe { let rc = Rc::copy_from_slice(&v); diff --git a/library/alloc/src/slice.rs b/library/alloc/src/slice.rs index f2b4596c53a7d..78762f9ec58fc 100644 --- a/library/alloc/src/slice.rs +++ b/library/alloc/src/slice.rs @@ -97,11 +97,11 @@ pub(crate) mod hack { // We shouldn't add inline attribute to this since this is used in // `vec!` macro mostly and causes perf regression. See #71204 for // discussion and perf results. - pub fn into_vec( + pub fn into_vec( b: Box<[T], A>, - ) -> Vec + ) -> Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { unsafe { let len = b.len(); @@ -112,47 +112,47 @@ pub(crate) mod hack { #[cfg(not(no_global_oom_handling))] #[inline] - pub fn to_vec( + pub fn to_vec( s: &[T], alloc: A, - ) -> Vec + ) -> Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { T::to_vec(s, alloc) } #[cfg(not(no_global_oom_handling))] pub trait ConvertVec { - fn to_vec( + fn to_vec( s: &[Self], alloc: A, - ) -> Vec + ) -> Vec where Self: Sized, - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:; + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:; } #[cfg(not(no_global_oom_handling))] impl ConvertVec for T { #[inline] - default fn to_vec( + default fn to_vec( s: &[Self], alloc: A, - ) -> Vec + ) -> Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { - struct DropGuard<'a, T, A: Allocator, const COOP_PREFERRED: bool> + struct DropGuard<'a, T, A: Allocator, const COOP_PREF: bool> where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { - vec: &'a mut Vec, + vec: &'a mut Vec, num_init: usize, } - impl<'a, T, A: Allocator, const COOP_PREFERRED: bool> Drop for DropGuard<'a, T, A, COOP_PREFERRED> + impl<'a, T, A: Allocator, const COOP_PREF: bool> Drop for DropGuard<'a, T, A, COOP_PREF> where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { #[inline] fn drop(&mut self) { @@ -185,12 +185,12 @@ pub(crate) mod hack { #[cfg(not(no_global_oom_handling))] impl ConvertVec for T { #[inline] - fn to_vec( + fn to_vec( s: &[Self], alloc: A, - ) -> Vec + ) -> Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { let mut v = Vec::with_capacity_in(s.len(), alloc); // SAFETY: @@ -442,12 +442,12 @@ impl [T] { #[rustc_conversion_suggestion] #[stable(feature = "rust1", since = "1.0.0")] #[inline] - pub fn to_vec(&self) -> Vec + pub fn to_vec(&self) -> Vec where T: Clone, - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { - self.to_vec_in::(Global) + self.to_vec_in::(Global) } /// Copies `self` into a new `Vec` with an allocator. @@ -467,13 +467,13 @@ impl [T] { #[rustc_allow_incoherent_impl] #[inline] #[unstable(feature = "allocator_api", issue = "32838")] - pub fn to_vec_in( + pub fn to_vec_in( &self, alloc: A, - ) -> Vec + ) -> Vec where T: Clone, - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { // N.B., see the `hack` module in this file for more details. hack::to_vec(self, alloc) @@ -496,11 +496,11 @@ impl [T] { #[rustc_allow_incoherent_impl] #[stable(feature = "rust1", since = "1.0.0")] #[inline] - pub fn into_vec( + pub fn into_vec( self: Box, - ) -> Vec + ) -> Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { // N.B., see the `hack` module in this file for more details. hack::into_vec(self) @@ -815,9 +815,9 @@ impl> Join<&[T]> for [V] { //////////////////////////////////////////////////////////////////////////////// #[stable(feature = "rust1", since = "1.0.0")] -impl Borrow<[T]> for Vec +impl Borrow<[T]> for Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { fn borrow(&self) -> &[T] { &self[..] @@ -825,9 +825,9 @@ where } #[stable(feature = "rust1", since = "1.0.0")] -impl BorrowMut<[T]> for Vec +impl BorrowMut<[T]> for Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { fn borrow_mut(&mut self) -> &mut [T] { &mut self[..] diff --git a/library/alloc/src/str.rs b/library/alloc/src/str.rs index b95ef1c5933f8..c3f722d9e3711 100644 --- a/library/alloc/src/str.rs +++ b/library/alloc/src/str.rs @@ -128,15 +128,15 @@ macro_rules! copy_slice_and_advance { // [T] and str both impl AsRef<[T]> for some T // => s.borrow().as_ref() and we always have slices #[cfg(not(no_global_oom_handling))] -fn join_generic_copy( +fn join_generic_copy( slice: &[S], sep: &[T], -) -> Vec +) -> Vec where T: Copy, B: AsRef<[T]> + ?Sized, S: Borrow, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { let sep_len = sep.len(); let mut iter = slice.iter(); diff --git a/library/alloc/src/vec/drain.rs b/library/alloc/src/vec/drain.rs index a219ca302d4c4..78a0d963ee5da 100644 --- a/library/alloc/src/vec/drain.rs +++ b/library/alloc/src/vec/drain.rs @@ -24,9 +24,9 @@ pub struct Drain< 'a, T: 'a, #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator + 'a = Global, - const COOP_PREFERRED: bool = { SHORT_TERM_VEC_PREFERS_COOP!() }, + const COOP_PREF: bool = { SHORT_TERM_VEC_PREFERS_COOP!() }, > where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { /// Index of tail to preserve pub(super) tail_start: usize, @@ -34,23 +34,23 @@ pub struct Drain< pub(super) tail_len: usize, /// Current remaining range to remove pub(super) iter: slice::Iter<'a, T>, - pub(super) vec: NonNull>, + pub(super) vec: NonNull>, } #[stable(feature = "collection_debug", since = "1.17.0")] -impl fmt::Debug - for Drain<'_, T, A, COOP_PREFERRED> +impl fmt::Debug + for Drain<'_, T, A, COOP_PREF> where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_tuple("Drain").field(&self.iter.as_slice()).finish() } } -impl<'a, T, A: Allocator, const COOP_PREFERRED: bool> Drain<'a, T, A, COOP_PREFERRED> +impl<'a, T, A: Allocator, const COOP_PREF: bool> Drain<'a, T, A, COOP_PREF> where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { /// Returns the remaining items of this iterator as a slice. /// @@ -150,9 +150,9 @@ where } #[stable(feature = "vec_drain_as_slice", since = "1.46.0")] -impl<'a, T, A: Allocator, const COOP_PREFERRED: bool> AsRef<[T]> for Drain<'a, T, A, COOP_PREFERRED> +impl<'a, T, A: Allocator, const COOP_PREF: bool> AsRef<[T]> for Drain<'a, T, A, COOP_PREF> where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { fn as_ref(&self) -> &[T] { self.as_slice() @@ -160,24 +160,24 @@ where } #[stable(feature = "drain", since = "1.6.0")] -unsafe impl Sync - for Drain<'_, T, A, COOP_PREFERRED> +unsafe impl Sync + for Drain<'_, T, A, COOP_PREF> where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { } #[stable(feature = "drain", since = "1.6.0")] -unsafe impl Send - for Drain<'_, T, A, COOP_PREFERRED> +unsafe impl Send + for Drain<'_, T, A, COOP_PREF> where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { } #[stable(feature = "drain", since = "1.6.0")] -impl Iterator for Drain<'_, T, A, COOP_PREFERRED> +impl Iterator for Drain<'_, T, A, COOP_PREF> where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { type Item = T; @@ -192,10 +192,10 @@ where } #[stable(feature = "drain", since = "1.6.0")] -impl DoubleEndedIterator - for Drain<'_, T, A, COOP_PREFERRED> +impl DoubleEndedIterator + for Drain<'_, T, A, COOP_PREF> where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { #[inline] fn next_back(&mut self) -> Option { @@ -204,22 +204,22 @@ where } #[stable(feature = "drain", since = "1.6.0")] -impl Drop for Drain<'_, T, A, COOP_PREFERRED> +impl Drop for Drain<'_, T, A, COOP_PREF> where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { fn drop(&mut self) { /// Moves back the un-`Drain`ed elements to restore the original `Vec`. - struct DropGuard<'r, 'a, T, A: Allocator, const COOP_PREFERRED: bool>( - &'r mut Drain<'a, T, A, COOP_PREFERRED>, + struct DropGuard<'r, 'a, T, A: Allocator, const COOP_PREF: bool>( + &'r mut Drain<'a, T, A, COOP_PREF>, ) where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:; + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:; - impl<'r, 'a, T, A: Allocator, const COOP_PREFERRED: bool> Drop - for DropGuard<'r, 'a, T, A, COOP_PREFERRED> + impl<'r, 'a, T, A: Allocator, const COOP_PREF: bool> Drop + for DropGuard<'r, 'a, T, A, COOP_PREF> where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { fn drop(&mut self) { if self.0.tail_len > 0 { @@ -284,10 +284,10 @@ where } #[stable(feature = "drain", since = "1.6.0")] -impl ExactSizeIterator - for Drain<'_, T, A, COOP_PREFERRED> +impl ExactSizeIterator + for Drain<'_, T, A, COOP_PREF> where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { fn is_empty(&self) -> bool { self.iter.is_empty() @@ -295,15 +295,15 @@ where } #[unstable(feature = "trusted_len", issue = "37572")] -unsafe impl TrustedLen - for Drain<'_, T, A, COOP_PREFERRED> +unsafe impl TrustedLen + for Drain<'_, T, A, COOP_PREF> where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { } #[stable(feature = "fused", since = "1.26.0")] -impl FusedIterator for Drain<'_, T, A, COOP_PREFERRED> where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: +impl FusedIterator for Drain<'_, T, A, COOP_PREF> where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]: { } diff --git a/library/alloc/src/vec/drain_filter.rs b/library/alloc/src/vec/drain_filter.rs index 89baafca46729..58a6ce6ca054b 100644 --- a/library/alloc/src/vec/drain_filter.rs +++ b/library/alloc/src/vec/drain_filter.rs @@ -24,12 +24,12 @@ pub struct DrainFilter< T, F, #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global, - const COOP_PREFERRED: bool = true, + const COOP_PREF: bool = true, > where F: FnMut(&mut T) -> bool, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { - pub(super) vec: &'a mut Vec, + pub(super) vec: &'a mut Vec, /// The index of the item that will be inspected by the next call to `next`. pub(super) idx: usize, /// The number of items that have been drained (removed) thus far. @@ -46,10 +46,10 @@ pub struct DrainFilter< pub(super) panic_flag: bool, } -impl DrainFilter<'_, T, F, A, COOP_PREFERRED> +impl DrainFilter<'_, T, F, A, COOP_PREF> where F: FnMut(&mut T) -> bool, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { /// Returns a reference to the underlying allocator. #[unstable(feature = "allocator_api", issue = "32838")] @@ -115,11 +115,11 @@ where } #[unstable(feature = "drain_filter", reason = "recently added", issue = "43244")] -impl Iterator - for DrainFilter<'_, T, F, A, COOP_PREFERRED> +impl Iterator + for DrainFilter<'_, T, F, A, COOP_PREF> where F: FnMut(&mut T) -> bool, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { type Item = T; @@ -155,26 +155,26 @@ where } #[unstable(feature = "drain_filter", reason = "recently added", issue = "43244")] -impl Drop - for DrainFilter<'_, T, F, A, COOP_PREFERRED> +impl Drop + for DrainFilter<'_, T, F, A, COOP_PREF> where F: FnMut(&mut T) -> bool, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { fn drop(&mut self) { - struct BackshiftOnDrop<'a, 'b, T, F, A: Allocator, const COOP_PREFERRED: bool> + struct BackshiftOnDrop<'a, 'b, T, F, A: Allocator, const COOP_PREF: bool> where F: FnMut(&mut T) -> bool, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { - drain: &'b mut DrainFilter<'a, T, F, A, COOP_PREFERRED>, + drain: &'b mut DrainFilter<'a, T, F, A, COOP_PREF>, } - impl<'a, 'b, T, F, A: Allocator, const COOP_PREFERRED: bool> Drop - for BackshiftOnDrop<'a, 'b, T, F, A, COOP_PREFERRED> + impl<'a, 'b, T, F, A: Allocator, const COOP_PREF: bool> Drop + for BackshiftOnDrop<'a, 'b, T, F, A, COOP_PREF> where F: FnMut(&mut T) -> bool, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { fn drop(&mut self) { unsafe { diff --git a/library/alloc/src/vec/in_place_collect.rs b/library/alloc/src/vec/in_place_collect.rs index 3afbc754061c0..56e912d53e6f6 100644 --- a/library/alloc/src/vec/in_place_collect.rs +++ b/library/alloc/src/vec/in_place_collect.rs @@ -153,10 +153,10 @@ pub(super) trait InPlaceIterableMarker {} impl InPlaceIterableMarker for T where T: InPlaceIterable {} #[allow(unused_braces)] -impl SpecFromIter for Vec +impl SpecFromIter for Vec where I: Iterator + SourceIter + InPlaceIterableMarker, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { default fn from_iter(mut iterator: I) -> Self { // See "Layout constraints" section in the module documentation. We rely on const diff --git a/library/alloc/src/vec/into_iter.rs b/library/alloc/src/vec/into_iter.rs index 3555c64af9f8e..fb37e19ec8c54 100644 --- a/library/alloc/src/vec/into_iter.rs +++ b/library/alloc/src/vec/into_iter.rs @@ -32,9 +32,9 @@ use core::{alloc, array, fmt}; pub struct IntoIter< T, #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global, - const COOP_PREFERRED: bool = { SHORT_TERM_VEC_PREFERS_COOP!() }, + const COOP_PREF: bool = { SHORT_TERM_VEC_PREFERS_COOP!() }, > where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { pub(super) buf: NonNull, pub(super) phantom: PhantomData, @@ -49,19 +49,19 @@ pub struct IntoIter< } #[stable(feature = "vec_intoiter_debug", since = "1.13.0")] -impl fmt::Debug - for IntoIter +impl fmt::Debug + for IntoIter where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_tuple("IntoIter").field(&self.as_slice()).finish() } } -impl IntoIter +impl IntoIter where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { /// Returns the remaining items of this iterator as a slice. /// @@ -132,11 +132,11 @@ where // this creates less assembly self.cap = 0; self.buf = unsafe { - // @FIXME The below if COOP_PREFERRED {..} else {..} + // @FIXME The below if COOP_PREF {..} else {..} // branching exists, because the following fails. Otherwise we'd have a snowball effect of wide spread of where...Global... // - // NonNull::new_unchecked(RawVec::::NEW.ptr()) - if COOP_PREFERRED { + // NonNull::new_unchecked(RawVec::::NEW.ptr()) + if COOP_PREF { NonNull::new_unchecked(RawVec::::NEW.ptr()) } else { NonNull::new_unchecked(RawVec::::NEW.ptr()) @@ -161,7 +161,7 @@ where #[cfg(not(no_global_oom_handling))] #[inline] - pub(crate) fn into_vecdeque(self) -> VecDeque { + pub(crate) fn into_vecdeque(self) -> VecDeque { // Keep our `Drop` impl from dropping the elements and the allocator let mut this = ManuallyDrop::new(self); @@ -188,9 +188,9 @@ where } #[stable(feature = "vec_intoiter_as_ref", since = "1.46.0")] -impl AsRef<[T]> for IntoIter +impl AsRef<[T]> for IntoIter where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { fn as_ref(&self) -> &[T] { self.as_slice() @@ -198,24 +198,24 @@ where } #[stable(feature = "rust1", since = "1.0.0")] -unsafe impl Send - for IntoIter +unsafe impl Send + for IntoIter where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { } #[stable(feature = "rust1", since = "1.0.0")] -unsafe impl Sync - for IntoIter +unsafe impl Sync + for IntoIter where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { } #[stable(feature = "rust1", since = "1.0.0")] -impl Iterator for IntoIter +impl Iterator for IntoIter where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { type Item = T; @@ -330,10 +330,10 @@ where } #[stable(feature = "rust1", since = "1.0.0")] -impl DoubleEndedIterator - for IntoIter +impl DoubleEndedIterator + for IntoIter where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { #[inline] fn next_back(&mut self) -> Option { @@ -375,10 +375,10 @@ where } #[stable(feature = "rust1", since = "1.0.0")] -impl ExactSizeIterator - for IntoIter +impl ExactSizeIterator + for IntoIter where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { fn is_empty(&self) -> bool { self.ptr == self.end @@ -386,16 +386,16 @@ where } #[stable(feature = "fused", since = "1.26.0")] -impl FusedIterator for IntoIter where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: +impl FusedIterator for IntoIter where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]: { } #[unstable(feature = "trusted_len", issue = "37572")] -unsafe impl TrustedLen - for IntoIter +unsafe impl TrustedLen + for IntoIter where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { } @@ -413,31 +413,31 @@ impl NonDrop for T {} #[unstable(issue = "none", feature = "std_internals")] // TrustedRandomAccess (without NoCoerce) must not be implemented because // subtypes/supertypes of `T` might not be `NonDrop` -unsafe impl TrustedRandomAccessNoCoerce - for IntoIter +unsafe impl TrustedRandomAccessNoCoerce + for IntoIter where T: NonDrop, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { const MAY_HAVE_SIDE_EFFECT: bool = false; } #[cfg(not(no_global_oom_handling))] #[stable(feature = "vec_into_iter_clone", since = "1.8.0")] -impl Clone - for IntoIter +impl Clone + for IntoIter where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { #[cfg(not(test))] fn clone(&self) -> Self { // @FIXME Remove the following extras - used for type checks only let slice = self.as_slice(); - let vec: crate::vec::Vec = - slice.to_vec_in::(self.alloc.deref().clone()); - let _iter: IntoIter = vec.into_iter(); + let vec: crate::vec::Vec = + slice.to_vec_in::(self.alloc.deref().clone()); + let _iter: IntoIter = vec.into_iter(); - //self.as_slice().to_vec_in::(self.alloc.deref().clone()).into_iter() + //self.as_slice().to_vec_in::(self.alloc.deref().clone()).into_iter() loop {} } #[cfg(test)] @@ -447,29 +447,29 @@ where } #[stable(feature = "rust1", since = "1.0.0")] -unsafe impl<#[may_dangle] T, A: Allocator, const COOP_PREFERRED: bool> Drop - for IntoIter +unsafe impl<#[may_dangle] T, A: Allocator, const COOP_PREF: bool> Drop + for IntoIter where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { fn drop(&mut self) { - struct DropGuard<'a, T, A: Allocator, const COOP_PREFERRED: bool>( - &'a mut IntoIter, + struct DropGuard<'a, T, A: Allocator, const COOP_PREF: bool>( + &'a mut IntoIter, ) where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:; + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:; - impl Drop for DropGuard<'_, T, A, COOP_PREFERRED> + impl Drop for DropGuard<'_, T, A, COOP_PREF> where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { fn drop(&mut self) { unsafe { // `IntoIter::alloc` is not used anymore after this and will be dropped by RawVec let alloc = ManuallyDrop::take(&mut self.0.alloc); // RawVec handles deallocation - // @FIXME pass true instead of COOP_PREFERRED - use e.g.: if COOP_PREFERRED {let _ = RawVec::::from_raw_parts_in(..) } else { let _ = from_raw_parts_in_coop(...)} } - let _ = RawVec::::from_raw_parts_in( + // @FIXME pass true instead of COOP_PREF - use e.g.: if COOP_PREF {let _ = RawVec::::from_raw_parts_in(..) } else { let _ = from_raw_parts_in_coop(...)} } + let _ = RawVec::::from_raw_parts_in( self.0.buf.as_ptr(), self.0.cap, alloc, @@ -491,19 +491,19 @@ where // also refer to the vec::in_place_collect module documentation to get an overview #[unstable(issue = "none", feature = "inplace_iteration")] #[doc(hidden)] -unsafe impl InPlaceIterable - for IntoIter +unsafe impl InPlaceIterable + for IntoIter where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { } #[unstable(issue = "none", feature = "inplace_iteration")] #[doc(hidden)] -unsafe impl SourceIter - for IntoIter +unsafe impl SourceIter + for IntoIter where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { type Source = Self; diff --git a/library/alloc/src/vec/mod.rs b/library/alloc/src/vec/mod.rs index 619dd958db1be..2174e49e0c015 100644 --- a/library/alloc/src/vec/mod.rs +++ b/library/alloc/src/vec/mod.rs @@ -149,17 +149,6 @@ use self::spec_extend::SpecExtend; #[cfg(not(no_global_oom_handling))] mod spec_extend; -/// Default `Vec`, `DefVec`, `DecVeque`, `DefDecVeq` "cooperation" (`COOP_PREFERRED`) generic parameter. -/// NOT for public use. It's exported only so that library/proc_macro (and other internals) can use this. FIXME. -#[unstable(feature = "global_co_alloc_default", issue = "none")] -// pub const DEFAULT_COOP_PREFERRED: bool = true; -#[macro_export] -macro_rules! DEFAULT_COOP_PREFERRED { - () => { - true - }; -} - /// A contiguous growable array type, written as `Vec`, short for 'vector'. /// /// # Examples @@ -414,11 +403,11 @@ pub struct Vec< T, #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global, //@FIXME: #[unstable(feature ="global_co_alloc_vec", issue="none")] - const COOP_PREFERRED: bool = { DEFAULT_COOP_PREFERRED!() }, + const COOP_PREF: bool = { DEFAULT_COOP_PREF!() }, > where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { - buf: RawVec, + buf: RawVec, len: usize, } @@ -431,12 +420,12 @@ pub type CoVec = Vec; #[unstable(feature = "global_co_alloc_plvec", issue = "none")] pub type PlVec = Vec; -/// "Default" Vec. Either "cooperative" or not - as specified by `DEFAULT_COOP_PREFERRED`. The -/// difference to `Vec` (used without specifying `COOP_PREFERRED`): `DefVec` indicates that the +/// "Default" Vec. Either "cooperative" or not - as specified by `DEFAULT_COOP_PREF`. The +/// difference to `Vec` (used without specifying `COOP_PREF`): `DefVec` indicates that the /// author considered using `CoVec` or `PlVec`, but left it to default instead. #[unstable(feature = "global_co_alloc_defvec", issue = "none")] #[allow(unused_braces)] -pub type DefVec = Vec; +pub type DefVec = Vec; /// "Weighted cooperative" Vec. Weight means how much it wants to cooperate (with the allocator). 0 /// = always pack; u8::MAX = always cooperate (if `Global` supports it). @@ -445,9 +434,9 @@ pub type DefVec = Vec; pub type WeVec = Vec 127 }>; impl Vec { - /*impl Vec + /*impl Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, {*/ /// Constructs a new, empty `Vec`. /// @@ -465,7 +454,7 @@ impl Vec { #[must_use] pub const fn new() -> Self { #[allow(unused_braces)] - Vec::::new_co() + Vec::::new_co() //Self::new_co() } @@ -532,11 +521,11 @@ impl Vec { //////////////////////////////////////////////////////////////////////////////// /**/ -impl Vec +impl Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { - /// Like new(), but it respects COOP_PREFERRED. + /// Like new(), but it respects COOP_PREF. #[inline] #[rustc_const_stable(feature = "const_vec_new_co", since = "1.60.0")] //@FIXME This is `rustc_const_stable`, so that String::new() can be const and can call this. #[unstable(feature = "vec_new_co", reason = "confirm_or_fix_the_function_name", issue = "none")] @@ -714,9 +703,9 @@ where } } -impl Vec +impl Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { /// Constructs a new, empty `Vec`. /// @@ -1762,7 +1751,7 @@ where } } - let mut g = BackshiftOnDrop:: { + let mut g = BackshiftOnDrop:: { v: self, processed_len: 0, deleted_cnt: 0, @@ -1806,10 +1795,10 @@ where } // Stage 1: Nothing was deleted. - process_loop::(original_len, &mut f, &mut g); + process_loop::(original_len, &mut f, &mut g); // Stage 2: Some elements were deleted. - process_loop::(original_len, &mut f, &mut g); + process_loop::(original_len, &mut f, &mut g); // All item are processed. This can be optimized to `set_len` by LLVM. drop(g); @@ -1868,9 +1857,9 @@ where } /* INVARIANT: vec.len() > read >= write > write-1 >= 0 */ - struct FillGapOnDrop<'a, T, A: core::alloc::Allocator, const COOP_PREFERRED: bool> + struct FillGapOnDrop<'a, T, A: core::alloc::Allocator, const COOP_PREF: bool> where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { /* Offset of the element we want to check if it is duplicate */ read: usize, @@ -1880,13 +1869,13 @@ where write: usize, /* The Vec that would need correction if `same_bucket` panicked */ - vec: &'a mut Vec, + vec: &'a mut Vec, } - impl<'a, T, A: core::alloc::Allocator, const COOP_PREFERRED: bool> Drop - for FillGapOnDrop<'a, T, A, COOP_PREFERRED> + impl<'a, T, A: core::alloc::Allocator, const COOP_PREF: bool> Drop + for FillGapOnDrop<'a, T, A, COOP_PREF> where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { fn drop(&mut self) { /* This code gets executed when `same_bucket` panics */ @@ -2129,7 +2118,7 @@ where /// assert_eq!(v, &[]); /// ``` #[stable(feature = "drain", since = "1.6.0")] - pub fn drain(&mut self, range: R) -> Drain<'_, T, A, COOP_PREFERRED> + pub fn drain(&mut self, range: R) -> Drain<'_, T, A, COOP_PREF> where R: RangeBounds, { @@ -2480,9 +2469,9 @@ where } } -impl Vec +impl Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { /// Resizes the `Vec` in-place so that `len` is equal to `new_len`. /// @@ -2582,9 +2571,9 @@ where } } -impl Vec<[T; N], A, COOP_PREFERRED> +impl Vec<[T; N], A, COOP_PREF> where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { /// Takes a `Vec<[T; N]>` and flattens it into a `Vec`. /// @@ -2608,7 +2597,7 @@ where /// assert_eq!(flattened.pop(), Some(6)); /// ``` #[unstable(feature = "slice_flatten", issue = "95629")] - pub fn into_flattened(self) -> Vec { + pub fn into_flattened(self) -> Vec { let (ptr, len, cap, alloc) = self.into_raw_parts_with_alloc(); let (new_len, new_cap) = if T::IS_ZST { (len.checked_mul(N).expect("vec len overflow"), usize::MAX) @@ -2627,7 +2616,7 @@ where // `new_cap * size_of::()` == `cap * size_of::<[T; N]>()` // - `len` <= `cap`, so `len * N` <= `cap * N`. unsafe { - Vec::::from_raw_parts_in(ptr.cast(), new_len, new_cap, alloc) + Vec::::from_raw_parts_in(ptr.cast(), new_len, new_cap, alloc) } } } @@ -2648,9 +2637,9 @@ impl ExtendWith for ExtendElement { } } -impl Vec +impl Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { #[cfg(not(no_global_oom_handling))] /// Extend the vector by `n` values, using the given generator. @@ -2683,9 +2672,9 @@ where } } -impl Vec +impl Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { /// Removes consecutive repeated elements in the vector according to the /// [`PartialEq`] trait implementation. @@ -2722,13 +2711,13 @@ pub fn from_elem(elem: T, n: usize) -> Vec { #[doc(hidden)] #[cfg(not(no_global_oom_handling))] #[unstable(feature = "allocator_api", issue = "32838")] -pub fn from_elem_in( +pub fn from_elem_in( elem: T, n: usize, alloc: A, -) -> Vec +) -> Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { ::from_elem(elem, n, alloc) } @@ -2741,10 +2730,10 @@ trait ExtendFromWithinSpec { unsafe fn spec_extend_from_within(&mut self, src: Range); } -impl ExtendFromWithinSpec - for Vec +impl ExtendFromWithinSpec + for Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { default unsafe fn spec_extend_from_within(&mut self, src: Range) { // SAFETY: @@ -2764,10 +2753,10 @@ where } } -impl ExtendFromWithinSpec - for Vec +impl ExtendFromWithinSpec + for Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { unsafe fn spec_extend_from_within(&mut self, src: Range) { let count = src.len(); @@ -2801,9 +2790,9 @@ where //////////////////////////////////////////////////////////////////////////////// #[stable(feature = "rust1", since = "1.0.0")] -impl ops::Deref for Vec +impl ops::Deref for Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { type Target = [T]; @@ -2814,9 +2803,9 @@ where } #[stable(feature = "rust1", since = "1.0.0")] -impl ops::DerefMut for Vec +impl ops::DerefMut for Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { #[inline] fn deref_mut(&mut self) -> &mut [T] { @@ -2826,9 +2815,9 @@ where #[cfg(not(no_global_oom_handling))] #[stable(feature = "rust1", since = "1.0.0")] -impl Clone for Vec +impl Clone for Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { #[cfg(not(test))] fn clone(&self) -> Self { @@ -2864,9 +2853,9 @@ where /// assert_eq!(b.hash_one(v), b.hash_one(s)); /// ``` #[stable(feature = "rust1", since = "1.0.0")] -impl Hash for Vec +impl Hash for Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { #[inline] fn hash(&self, state: &mut H) { @@ -2879,10 +2868,10 @@ where message = "vector indices are of type `usize` or ranges of `usize`", label = "vector indices are of type `usize` or ranges of `usize`" )] -impl, A: Allocator, const COOP_PREFERRED: bool> Index - for Vec +impl, A: Allocator, const COOP_PREF: bool> Index + for Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { type Output = I::Output; @@ -2897,10 +2886,10 @@ where message = "vector indices are of type `usize` or ranges of `usize`", label = "vector indices are of type `usize` or ranges of `usize`" )] -impl, A: Allocator, const COOP_PREFERRED: bool> IndexMut - for Vec +impl, A: Allocator, const COOP_PREF: bool> IndexMut + for Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { #[inline] fn index_mut(&mut self, index: I) -> &mut Self::Output { @@ -2911,23 +2900,23 @@ where #[cfg(not(no_global_oom_handling))] #[stable(feature = "rust1", since = "1.0.0")] #[allow(unused_braces)] -impl FromIterator for Vec +impl FromIterator for Vec where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { #[inline] - fn from_iter>(iter: I) -> Vec { + fn from_iter>(iter: I) -> Vec { >::from_iter(iter.into_iter()) } } #[stable(feature = "rust1", since = "1.0.0")] -impl IntoIterator for Vec +impl IntoIterator for Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { type Item = T; - type IntoIter = IntoIter; + type IntoIter = IntoIter; /// Creates a consuming iterator, that is, one that moves each value out of /// the vector (from start to end). The vector cannot be used after calling @@ -2970,9 +2959,9 @@ where } #[stable(feature = "rust1", since = "1.0.0")] -impl<'a, T, A: Allocator, const COOP_PREFERRED: bool> IntoIterator for &'a Vec +impl<'a, T, A: Allocator, const COOP_PREF: bool> IntoIterator for &'a Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { type Item = &'a T; type IntoIter = slice::Iter<'a, T>; @@ -2983,10 +2972,10 @@ where } #[stable(feature = "rust1", since = "1.0.0")] -impl<'a, T, A: Allocator, const COOP_PREFERRED: bool> IntoIterator - for &'a mut Vec +impl<'a, T, A: Allocator, const COOP_PREF: bool> IntoIterator + for &'a mut Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { type Item = &'a mut T; type IntoIter = slice::IterMut<'a, T>; @@ -2998,9 +2987,9 @@ where #[cfg(not(no_global_oom_handling))] #[stable(feature = "rust1", since = "1.0.0")] -impl Extend for Vec +impl Extend for Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { #[inline] fn extend>(&mut self, iter: I) { @@ -3018,9 +3007,9 @@ where } } -impl Vec +impl Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { // leaf method to which various SpecFrom/SpecExtend implementations delegate when // they have no further optimizations to apply @@ -3123,7 +3112,7 @@ where &mut self, range: R, replace_with: I, - ) -> Splice<'_, I::IntoIter, A, COOP_PREFERRED> + ) -> Splice<'_, I::IntoIter, A, COOP_PREF> where R: RangeBounds, I: IntoIterator, @@ -3177,7 +3166,7 @@ where /// assert_eq!(odds, vec![1, 3, 5, 9, 11, 13, 15]); /// ``` #[unstable(feature = "drain_filter", reason = "recently added", issue = "43244")] - pub fn drain_filter(&mut self, filter: F) -> DrainFilter<'_, T, F, A, COOP_PREFERRED> + pub fn drain_filter(&mut self, filter: F) -> DrainFilter<'_, T, F, A, COOP_PREF> where F: FnMut(&mut T) -> bool, [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(true)]:, @@ -3201,10 +3190,10 @@ where /// [`copy_from_slice`]: slice::copy_from_slice #[cfg(not(no_global_oom_handling))] #[stable(feature = "extend_ref", since = "1.2.0")] -impl<'a, T: Copy + 'a, A: Allocator + 'a, const COOP_PREFERRED: bool> Extend<&'a T> - for Vec +impl<'a, T: Copy + 'a, A: Allocator + 'a, const COOP_PREF: bool> Extend<&'a T> + for Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { fn extend>(&mut self, iter: I) { self.spec_extend(iter.into_iter()) @@ -3223,10 +3212,10 @@ where /// Implements comparison of vectors, [lexicographically](core::cmp::Ord#lexicographical-comparison). #[stable(feature = "rust1", since = "1.0.0")] -impl PartialOrd - for Vec +impl PartialOrd + for Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { #[inline] fn partial_cmp(&self, other: &Self) -> Option { @@ -3235,16 +3224,16 @@ where } #[stable(feature = "rust1", since = "1.0.0")] -impl Eq for Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: +impl Eq for Vec where + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]: { } /// Implements ordering of vectors, [lexicographically](core::cmp::Ord#lexicographical-comparison). #[stable(feature = "rust1", since = "1.0.0")] -impl Ord for Vec +impl Ord for Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { #[inline] fn cmp(&self, other: &Self) -> Ordering { @@ -3253,10 +3242,10 @@ where } #[stable(feature = "rust1", since = "1.0.0")] -unsafe impl<#[may_dangle] T, A: Allocator, const COOP_PREFERRED: bool> Drop - for Vec +unsafe impl<#[may_dangle] T, A: Allocator, const COOP_PREF: bool> Drop + for Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { fn drop(&mut self) { unsafe { @@ -3271,23 +3260,23 @@ where #[stable(feature = "rust1", since = "1.0.0")] #[rustc_const_unstable(feature = "const_default_impls", issue = "87864")] -impl const Default for Vec +impl const Default for Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { /// Creates an empty `Vec`. /// /// The vector will not allocate until elements are pushed onto it. - fn default() -> Vec { + fn default() -> Vec { Vec::new_co() } } #[stable(feature = "rust1", since = "1.0.0")] -impl fmt::Debug - for Vec +impl fmt::Debug + for Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fmt::Debug::fmt(&**self, f) @@ -3295,31 +3284,31 @@ where } #[stable(feature = "rust1", since = "1.0.0")] -impl AsRef> - for Vec +impl AsRef> + for Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { - fn as_ref(&self) -> &Vec { + fn as_ref(&self) -> &Vec { self } } #[stable(feature = "vec_as_mut", since = "1.5.0")] -impl AsMut> - for Vec +impl AsMut> + for Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { - fn as_mut(&mut self) -> &mut Vec { + fn as_mut(&mut self) -> &mut Vec { self } } #[stable(feature = "rust1", since = "1.0.0")] -impl AsRef<[T]> for Vec +impl AsRef<[T]> for Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { fn as_ref(&self) -> &[T] { self @@ -3327,9 +3316,9 @@ where } #[stable(feature = "vec_as_mut", since = "1.5.0")] -impl AsMut<[T]> for Vec +impl AsMut<[T]> for Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { fn as_mut(&mut self) -> &mut [T] { self @@ -3339,7 +3328,7 @@ where #[cfg(not(no_global_oom_handling))] #[stable(feature = "rust1", since = "1.0.0")] #[allow(unused_braces)] -impl From<&[T]> for Vec { +impl From<&[T]> for Vec { /// Allocate a `Vec` and fill it by cloning `s`'s items. /// /// # Examples @@ -3360,7 +3349,7 @@ impl From<&[T]> for Vec { #[cfg(not(no_global_oom_handling))] #[stable(feature = "vec_from_mut", since = "1.19.0")] #[allow(unused_braces)] -impl From<&mut [T]> for Vec { +impl From<&mut [T]> for Vec { /// Allocate a `Vec` and fill it by cloning `s`'s items. /// /// # Examples @@ -3381,7 +3370,7 @@ impl From<&mut [T]> for Vec #[cfg(not(no_global_oom_handling))] #[stable(feature = "vec_from_array", since = "1.44.0")] #[allow(unused_braces)] -impl From<[T; N]> for Vec { +impl From<[T; N]> for Vec { /// Allocate a `Vec` and move `s`'s items into it. /// /// # Examples @@ -3405,7 +3394,7 @@ impl From<[T; N]> for Vec From> for Vec +impl<'a, T> From> for Vec where [T]: ToOwned>, { @@ -3431,9 +3420,9 @@ where // note: test pulls in std, which causes errors here #[cfg(not(test))] #[stable(feature = "vec_from_box", since = "1.18.0")] -impl From> for Vec +impl From> for Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { /// Convert a boxed slice into a vector by transferring ownership of /// the existing heap allocation. @@ -3453,9 +3442,9 @@ where #[cfg(not(no_global_oom_handling))] #[cfg(not(test))] #[stable(feature = "box_from_vec", since = "1.20.0")] -impl From> for Box<[T], A> +impl From> for Box<[T], A> where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { /// Convert a vector into a boxed slice. /// @@ -3475,7 +3464,7 @@ where /// /// assert_eq!(Box::from(vec), vec![1, 2, 3].into_boxed_slice()); /// ``` - fn from(v: Vec) -> Self { + fn from(v: Vec) -> Self { v.into_boxed_slice() } } @@ -3483,7 +3472,7 @@ where #[cfg(not(no_global_oom_handling))] #[stable(feature = "rust1", since = "1.0.0")] #[allow(unused_braces)] -impl From<&str> for Vec { +impl From<&str> for Vec { /// Allocate a `Vec` and fill it with a UTF-8 string. /// /// # Examples @@ -3497,12 +3486,12 @@ impl From<&str> for Vec { } #[stable(feature = "array_try_from_vec", since = "1.48.0")] -impl TryFrom> +impl TryFrom> for [T; N] where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { - type Error = Vec; + type Error = Vec; /// Gets the entire contents of the `Vec` as an array, /// if its size exactly matches that of the requested array. @@ -3530,7 +3519,7 @@ where /// assert_eq!(a, b' '); /// assert_eq!(b, b'd'); /// ``` - fn try_from(mut vec: Vec) -> Result<[T; N], Vec> { + fn try_from(mut vec: Vec) -> Result<[T; N], Vec> { if vec.len() != N { return Err(vec); } diff --git a/library/alloc/src/vec/partial_eq.rs b/library/alloc/src/vec/partial_eq.rs index bcf52b7333218..9abfbfd075b25 100644 --- a/library/alloc/src/vec/partial_eq.rs +++ b/library/alloc/src/vec/partial_eq.rs @@ -21,21 +21,21 @@ macro_rules! __impl_slice_eq1 { } } -__impl_slice_eq1! { [A1: Allocator, A2: Allocator, const COOP_PREFERRED1: bool, const COOP_PREFERRED2: bool] Vec, Vec, #[stable(feature = "rust1", since = "1.0.0")], [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED1)]:, [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED2)]: } -__impl_slice_eq1! { [A: Allocator, const COOP_PREFERRED: bool] Vec, &[U], #[stable(feature = "rust1", since = "1.0.0")], [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: } -__impl_slice_eq1! { [A: Allocator, const COOP_PREFERRED: bool] Vec, &mut [U], #[stable(feature = "rust1", since = "1.0.0")], [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: } -__impl_slice_eq1! { [A: Allocator, const COOP_PREFERRED: bool] &[T], Vec, #[stable(feature = "partialeq_vec_for_ref_slice", since = "1.46.0")], [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: } -__impl_slice_eq1! { [A: Allocator, const COOP_PREFERRED: bool] &mut [T], Vec, #[stable(feature = "partialeq_vec_for_ref_slice", since = "1.46.0")], [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: } -__impl_slice_eq1! { [A: Allocator, const COOP_PREFERRED: bool] Vec, [U], #[stable(feature = "partialeq_vec_for_slice", since = "1.48.0")], [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: } -__impl_slice_eq1! { [A: Allocator, const COOP_PREFERRED: bool] [T], Vec, #[stable(feature = "partialeq_vec_for_slice", since = "1.48.0")], [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: } +__impl_slice_eq1! { [A1: Allocator, A2: Allocator, const COOP_PREF1: bool, const COOP_PREF2: bool] Vec, Vec, #[stable(feature = "rust1", since = "1.0.0")], [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF1)]:, [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF2)]: } +__impl_slice_eq1! { [A: Allocator, const COOP_PREF: bool] Vec, &[U], #[stable(feature = "rust1", since = "1.0.0")], [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]: } +__impl_slice_eq1! { [A: Allocator, const COOP_PREF: bool] Vec, &mut [U], #[stable(feature = "rust1", since = "1.0.0")], [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]: } +__impl_slice_eq1! { [A: Allocator, const COOP_PREF: bool] &[T], Vec, #[stable(feature = "partialeq_vec_for_ref_slice", since = "1.46.0")], [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]: } +__impl_slice_eq1! { [A: Allocator, const COOP_PREF: bool] &mut [T], Vec, #[stable(feature = "partialeq_vec_for_ref_slice", since = "1.46.0")], [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]: } +__impl_slice_eq1! { [A: Allocator, const COOP_PREF: bool] Vec, [U], #[stable(feature = "partialeq_vec_for_slice", since = "1.48.0")], [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]: } +__impl_slice_eq1! { [A: Allocator, const COOP_PREF: bool] [T], Vec, #[stable(feature = "partialeq_vec_for_slice", since = "1.48.0")], [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]: } #[cfg(not(no_global_oom_handling))] -__impl_slice_eq1! { [A: Allocator, const COOP_PREFERRED: bool] Cow<'_, [T]>, Vec, #[stable(feature = "rust1", since = "1.0.0")], T: Clone, [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: } +__impl_slice_eq1! { [A: Allocator, const COOP_PREF: bool] Cow<'_, [T]>, Vec, #[stable(feature = "rust1", since = "1.0.0")], T: Clone, [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]: } #[cfg(not(no_global_oom_handling))] __impl_slice_eq1! { [] Cow<'_, [T]>, &[U], #[stable(feature = "rust1", since = "1.0.0")], T: Clone } #[cfg(not(no_global_oom_handling))] __impl_slice_eq1! { [] Cow<'_, [T]>, &mut [U], #[stable(feature = "rust1", since = "1.0.0")], T: Clone } -__impl_slice_eq1! { [A: Allocator, const COOP_PREFERRED: bool, const N: usize] Vec, [U; N], #[stable(feature = "rust1", since = "1.0.0")], [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: } -__impl_slice_eq1! { [A: Allocator, const COOP_PREFERRED: bool, const N: usize] Vec, &[U; N], #[stable(feature = "rust1", since = "1.0.0")], [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]: } +__impl_slice_eq1! { [A: Allocator, const COOP_PREF: bool, const N: usize] Vec, [U; N], #[stable(feature = "rust1", since = "1.0.0")], [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]: } +__impl_slice_eq1! { [A: Allocator, const COOP_PREF: bool, const N: usize] Vec, &[U; N], #[stable(feature = "rust1", since = "1.0.0")], [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]: } // NOTE: some less important impls are omitted to reduce code bloat // FIXME(Centril): Reconsider this? diff --git a/library/alloc/src/vec/spec_extend.rs b/library/alloc/src/vec/spec_extend.rs index 73cf325889290..0d5b6160f7b9f 100644 --- a/library/alloc/src/vec/spec_extend.rs +++ b/library/alloc/src/vec/spec_extend.rs @@ -10,30 +10,30 @@ pub(super) trait SpecExtend { fn spec_extend(&mut self, iter: I); } -impl SpecExtend for Vec +impl SpecExtend for Vec where I: Iterator, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { default fn spec_extend(&mut self, iter: I) { self.extend_desugared(iter) } } -impl SpecExtend for Vec +impl SpecExtend for Vec where I: TrustedLen, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { default fn spec_extend(&mut self, iterator: I) { self.extend_trusted(iterator) } } -impl SpecExtend> - for Vec +impl SpecExtend> + for Vec where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { fn spec_extend(&mut self, mut iterator: IntoIter) { unsafe { @@ -43,23 +43,23 @@ where } } -impl<'a, T: 'a, I, A: Allocator + 'a, const COOP_PREFERRED: bool> SpecExtend<&'a T, I> - for Vec +impl<'a, T: 'a, I, A: Allocator + 'a, const COOP_PREF: bool> SpecExtend<&'a T, I> + for Vec where I: Iterator, T: Clone, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { default fn spec_extend(&mut self, iterator: I) { self.spec_extend(iterator.cloned()) } } -impl<'a, T: 'a, A: Allocator + 'a, const COOP_PREFERRED: bool> SpecExtend<&'a T, slice::Iter<'a, T>> - for Vec +impl<'a, T: 'a, A: Allocator + 'a, const COOP_PREF: bool> SpecExtend<&'a T, slice::Iter<'a, T>> + for Vec where T: Copy, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { fn spec_extend(&mut self, iterator: slice::Iter<'a, T>) { let slice = iterator.as_slice(); diff --git a/library/alloc/src/vec/spec_from_elem.rs b/library/alloc/src/vec/spec_from_elem.rs index bc4169a24f0b2..9ec9463160ed5 100644 --- a/library/alloc/src/vec/spec_from_elem.rs +++ b/library/alloc/src/vec/spec_from_elem.rs @@ -8,23 +8,23 @@ use super::{ExtendElement, IsZero, Vec}; // Specialization trait used for Vec::from_elem pub(super) trait SpecFromElem: Sized { - fn from_elem( + fn from_elem( elem: Self, n: usize, alloc: A, - ) -> Vec + ) -> Vec where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:; + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:; } impl SpecFromElem for T { - default fn from_elem( + default fn from_elem( elem: Self, n: usize, alloc: A, - ) -> Vec + ) -> Vec where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { let mut v = Vec::with_capacity_in(n, alloc); v.extend_with(n, ExtendElement(elem)); @@ -34,13 +34,13 @@ impl SpecFromElem for T { impl SpecFromElem for T { #[inline] - default fn from_elem( + default fn from_elem( elem: T, n: usize, alloc: A, - ) -> Vec + ) -> Vec where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { if elem.is_zero() { return Vec { buf: RawVec::with_capacity_zeroed_in(n, alloc), len: n }; @@ -53,13 +53,13 @@ impl SpecFromElem for T { impl SpecFromElem for i8 { #[inline] - fn from_elem( + fn from_elem( elem: i8, n: usize, alloc: A, - ) -> Vec + ) -> Vec where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { if elem == 0 { return Vec { buf: RawVec::with_capacity_zeroed_in(n, alloc), len: n }; @@ -75,13 +75,13 @@ impl SpecFromElem for i8 { impl SpecFromElem for u8 { #[inline] - fn from_elem( + fn from_elem( elem: u8, n: usize, alloc: A, - ) -> Vec + ) -> Vec where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { if elem == 0 { return Vec { buf: RawVec::with_capacity_zeroed_in(n, alloc), len: n }; diff --git a/library/alloc/src/vec/spec_from_iter.rs b/library/alloc/src/vec/spec_from_iter.rs index e5d790878aabb..7b8ec9c0bc347 100644 --- a/library/alloc/src/vec/spec_from_iter.rs +++ b/library/alloc/src/vec/spec_from_iter.rs @@ -28,10 +28,10 @@ pub(super) trait SpecFromIter { } #[allow(unused_braces)] -impl SpecFromIter for Vec +impl SpecFromIter for Vec where I: Iterator, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { default fn from_iter(iterator: I) -> Self { SpecFromIterNested::from_iter(iterator) @@ -39,9 +39,9 @@ where } #[allow(unused_braces)] -impl SpecFromIter> for Vec +impl SpecFromIter> for Vec where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { fn from_iter(iterator: IntoIter) -> Self { // A common case is passing a vector into a function which immediately @@ -63,7 +63,7 @@ where } } - let mut vec = Vec::::new_co(); + let mut vec = Vec::::new_co(); // must delegate to spec_extend() since extend() itself delegates // to spec_from for empty Vecs vec.spec_extend(iterator); diff --git a/library/alloc/src/vec/spec_from_iter_nested.rs b/library/alloc/src/vec/spec_from_iter_nested.rs index 358c1b5a25f55..80d1f4a81d0c4 100644 --- a/library/alloc/src/vec/spec_from_iter_nested.rs +++ b/library/alloc/src/vec/spec_from_iter_nested.rs @@ -5,7 +5,7 @@ use core::ptr; use crate::alloc::Global; use crate::raw_vec::RawVec; -use crate::DEFAULT_COOP_PREFERRED; +use crate::DEFAULT_COOP_PREF; use super::{SpecExtend, Vec}; @@ -17,10 +17,10 @@ pub(super) trait SpecFromIterNested { } #[allow(unused_braces)] -impl SpecFromIterNested for Vec +impl SpecFromIterNested for Vec where I: Iterator, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { default fn from_iter(mut iterator: I) -> Self { // Unroll the first iteration, as the vector is going to be @@ -45,13 +45,13 @@ where }; // must delegate to spec_extend() since extend() itself delegates // to spec_from for empty Vecs - as SpecExtend>::spec_extend(&mut vector, iterator); + as SpecExtend>::spec_extend(&mut vector, iterator); vector } } #[allow(unused_braces)] -impl SpecFromIterNested for Vec +impl SpecFromIterNested for Vec where I: TrustedLen, { diff --git a/library/alloc/src/vec/splice.rs b/library/alloc/src/vec/splice.rs index acf5553c9cfb4..765b39221ce80 100644 --- a/library/alloc/src/vec/splice.rs +++ b/library/alloc/src/vec/splice.rs @@ -23,19 +23,19 @@ pub struct Splice< 'a, I: Iterator + 'a, #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator + 'a = Global, - const COOP_PREFERRED: bool = false, + const COOP_PREF: bool = false, > where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { - pub(super) drain: Drain<'a, I::Item, A, COOP_PREFERRED>, + pub(super) drain: Drain<'a, I::Item, A, COOP_PREF>, pub(super) replace_with: I, } #[stable(feature = "vec_splice", since = "1.21.0")] -impl Iterator - for Splice<'_, I, A, COOP_PREFERRED> +impl Iterator + for Splice<'_, I, A, COOP_PREF> where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { type Item = I::Item; @@ -49,10 +49,10 @@ where } #[stable(feature = "vec_splice", since = "1.21.0")] -impl DoubleEndedIterator - for Splice<'_, I, A, COOP_PREFERRED> +impl DoubleEndedIterator + for Splice<'_, I, A, COOP_PREF> where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { fn next_back(&mut self) -> Option { self.drain.next_back() @@ -60,18 +60,18 @@ where } #[stable(feature = "vec_splice", since = "1.21.0")] -impl ExactSizeIterator - for Splice<'_, I, A, COOP_PREFERRED> +impl ExactSizeIterator + for Splice<'_, I, A, COOP_PREF> where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { } #[stable(feature = "vec_splice", since = "1.21.0")] -impl Drop - for Splice<'_, I, A, COOP_PREFERRED> +impl Drop + for Splice<'_, I, A, COOP_PREF> where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { fn drop(&mut self) { self.drain.by_ref().for_each(drop); @@ -119,9 +119,9 @@ where } /// Private helper methods for `Splice::drop` -impl Drain<'_, T, A, COOP_PREFERRED> +impl Drain<'_, T, A, COOP_PREF> where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { /// The range from `self.vec.len` to `self.tail_start` contains elements /// that have been moved out. diff --git a/library/proc_macro/src/bridge/mod.rs b/library/proc_macro/src/bridge/mod.rs index aae141dc2a118..3020be3cb08cd 100644 --- a/library/proc_macro/src/bridge/mod.rs +++ b/library/proc_macro/src/bridge/mod.rs @@ -252,14 +252,14 @@ impl<'a, T, M> Unmark for &'a mut Marked { } } -impl Mark for Vec { +impl Mark for Vec { type Unmarked = Vec; fn mark(unmarked: Self::Unmarked) -> Self { // Should be a no-op due to std's in-place collect optimizations. unmarked.into_iter().map(T::mark).collect() } } -impl Unmark for Vec { +impl Unmark for Vec { type Unmarked = Vec; fn unmark(self) -> Self::Unmarked { // Should be a no-op due to std's in-place collect optimizations. diff --git a/library/proc_macro/src/bridge/rpc.rs b/library/proc_macro/src/bridge/rpc.rs index 8e5e17598b0be..aef89f5f94bf6 100644 --- a/library/proc_macro/src/bridge/rpc.rs +++ b/library/proc_macro/src/bridge/rpc.rs @@ -6,7 +6,7 @@ use std::num::NonZeroU32; use std::str; //use std::alloc::Global; use alloc::alloc::Global; -use alloc::DEFAULT_COOP_PREFERRED; +use alloc::DEFAULT_COOP_PREF; pub(super) type Writer = super::buffer::Buffer; @@ -227,7 +227,7 @@ impl DecodeMut<'_, '_, S> for String { } } -impl> Encode for Vec { +impl> Encode for Vec { fn encode(self, w: &mut Writer, s: &mut S) { self.len().encode(w, s); for x in self { @@ -237,7 +237,7 @@ impl> Encode for Vec { } impl<'a, S, T: for<'s> DecodeMut<'a, 's, S>> DecodeMut<'a, '_, S> - for Vec + for Vec { fn decode(r: &mut Reader<'a>, s: &mut S) -> Self { let len = usize::decode(r, s); diff --git a/library/proc_macro/src/diagnostic.rs b/library/proc_macro/src/diagnostic.rs index 41a11b1003b84..96796757c895d 100644 --- a/library/proc_macro/src/diagnostic.rs +++ b/library/proc_macro/src/diagnostic.rs @@ -30,7 +30,7 @@ impl MultiSpan for Span { } #[unstable(feature = "proc_macro_diagnostic", issue = "54140")] -impl MultiSpan for Vec { +impl MultiSpan for Vec { fn into_spans(self) -> Vec { self } diff --git a/library/std/src/io/cursor.rs b/library/std/src/io/cursor.rs index 63045ebcb8157..76da93d547f0e 100644 --- a/library/std/src/io/cursor.rs +++ b/library/std/src/io/cursor.rs @@ -398,13 +398,13 @@ fn slice_write_vectored( } /// Reserves the required space, and pads the vec with 0s if necessary. -fn reserve_and_pad( +fn reserve_and_pad( pos_mut: &mut u64, - vec: &mut Vec, + vec: &mut Vec, buf_len: usize, ) -> io::Result where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { let pos: usize = (*pos_mut).try_into().map_err(|_| { io::const_io_error!( @@ -444,14 +444,14 @@ where /// Writes the slice to the vec without allocating /// # Safety: vec must have buf.len() spare capacity -unsafe fn vec_write_unchecked( +unsafe fn vec_write_unchecked( pos: usize, - vec: &mut Vec, + vec: &mut Vec, buf: &[u8], ) -> usize where A: Allocator, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { debug_assert!(vec.capacity() >= pos + buf.len()); vec.as_mut_ptr().add(pos).copy_from(buf.as_ptr(), buf.len()); @@ -467,14 +467,14 @@ where /// This also allows for the vec body to be empty, but with a position of N. /// This means that [`Write`] will pad the vec with 0 initially, /// before writing anything from that point -fn vec_write( +fn vec_write( pos_mut: &mut u64, - vec: &mut Vec, + vec: &mut Vec, buf: &[u8], ) -> io::Result where A: Allocator, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { let buf_len = buf.len(); let mut pos = reserve_and_pad(pos_mut, vec, buf_len)?; @@ -503,14 +503,14 @@ where /// This also allows for the vec body to be empty, but with a position of N. /// This means that [`Write`] will pad the vec with 0 initially, /// before writing anything from that point -fn vec_write_vectored( +fn vec_write_vectored( pos_mut: &mut u64, - vec: &mut Vec, + vec: &mut Vec, bufs: &[IoSlice<'_>], ) -> io::Result where A: Allocator, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { // For safety reasons, we don't want this sum to overflow ever. // If this saturates, the reserve should panic to avoid any unsound writing. @@ -558,10 +558,10 @@ impl Write for Cursor<&mut [u8]> { } #[stable(feature = "cursor_mut_vec", since = "1.25.0")] -impl Write for Cursor<&mut Vec> +impl Write for Cursor<&mut Vec> where A: Allocator, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { fn write(&mut self, buf: &[u8]) -> io::Result { vec_write(&mut self.pos, self.inner, buf) @@ -583,10 +583,10 @@ where } #[stable(feature = "rust1", since = "1.0.0")] -impl Write for Cursor> +impl Write for Cursor> where A: Allocator, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { fn write(&mut self, buf: &[u8]) -> io::Result { vec_write(&mut self.pos, &mut self.inner, buf) diff --git a/library/std/src/io/impls.rs b/library/std/src/io/impls.rs index 02cd7aa0d2cc0..f027b24e43789 100644 --- a/library/std/src/io/impls.rs +++ b/library/std/src/io/impls.rs @@ -378,9 +378,9 @@ impl Write for &mut [u8] { /// Write is implemented for `Vec` by appending to the vector. /// The vector will grow as needed. #[stable(feature = "rust1", since = "1.0.0")] -impl Write for Vec +impl Write for Vec where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { #[inline] fn write(&mut self, buf: &[u8]) -> io::Result { @@ -417,9 +417,9 @@ where /// Read is implemented for `VecDeque` by consuming bytes from the front of the `VecDeque`. #[stable(feature = "vecdeque_read_write", since = "1.63.0")] -impl Read for VecDeque +impl Read for VecDeque where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(_COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(_COOP_PREF)]:, { /// Fill `buf` with the contents of the "front" slice as returned by /// [`as_slices`][`VecDeque::as_slices`]. If the contained byte slices of the `VecDeque` are @@ -444,9 +444,9 @@ where /// Write is implemented for `VecDeque` by appending to the `VecDeque`, growing it as needed. #[stable(feature = "vecdeque_read_write", since = "1.63.0")] -impl Write for VecDeque +impl Write for VecDeque where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(_COOP_PREFERRED)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(_COOP_PREF)]:, { #[inline] fn write(&mut self, buf: &[u8]) -> io::Result { From af769164d2f6d8808f8b5fb40e706a20ca44632d Mon Sep 17 00:00:00 2001 From: Peter Kehl Date: Wed, 25 Jan 2023 18:55:48 -0800 Subject: [PATCH 084/118] CoAlloc: Renamed IS_CO_ALLOCATOR -> CO_ALLOCATES_WITH_META. Added Allocator::CoAllocMeta, but not using it yet. Tidy --- library/alloc/src/boxed.rs | 3 +- .../alloc/src/collections/vec_deque/drain.rs | 27 ++++-------- .../src/collections/vec_deque/into_iter.rs | 15 +++---- .../alloc/src/collections/vec_deque/mod.rs | 24 ++++------- .../src/collections/vec_deque/spec_extend.rs | 6 +-- library/alloc/src/macros.rs | 10 ++--- library/alloc/src/raw_vec.rs | 16 +++---- library/alloc/src/slice.rs | 13 ++---- library/alloc/src/vec/drain.rs | 30 +++++-------- library/alloc/src/vec/drain_filter.rs | 6 +-- library/alloc/src/vec/into_iter.rs | 42 +++++++------------ library/alloc/src/vec/mod.rs | 31 +++++--------- library/alloc/src/vec/spec_extend.rs | 3 +- library/alloc/src/vec/splice.rs | 6 +-- library/core/src/alloc/mod.rs | 7 ++-- library/std/src/alloc.rs | 2 - 16 files changed, 82 insertions(+), 159 deletions(-) diff --git a/library/alloc/src/boxed.rs b/library/alloc/src/boxed.rs index e70bb2fad17fc..1027898f8b8a5 100644 --- a/library/alloc/src/boxed.rs +++ b/library/alloc/src/boxed.rs @@ -1679,8 +1679,7 @@ impl TryFrom> for Box<[T; N]> { #[cfg(not(no_global_oom_handling))] #[stable(feature = "boxed_array_try_from_vec", since = "1.66.0")] -impl TryFrom> - for Box<[T; N]> +impl TryFrom> for Box<[T; N]> where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { diff --git a/library/alloc/src/collections/vec_deque/drain.rs b/library/alloc/src/collections/vec_deque/drain.rs index 70521a580d653..699c2ea631467 100644 --- a/library/alloc/src/collections/vec_deque/drain.rs +++ b/library/alloc/src/collections/vec_deque/drain.rs @@ -95,8 +95,7 @@ where } #[stable(feature = "collection_debug", since = "1.17.0")] -impl fmt::Debug - for Drain<'_, T, A, COOP_PREF> +impl fmt::Debug for Drain<'_, T, A, COOP_PREF> where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { @@ -111,17 +110,13 @@ where } #[stable(feature = "drain", since = "1.6.0")] -unsafe impl Sync - for Drain<'_, T, A, COOP_PREF> -where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, +unsafe impl Sync for Drain<'_, T, A, COOP_PREF> where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]: { } #[stable(feature = "drain", since = "1.6.0")] -unsafe impl Send - for Drain<'_, T, A, COOP_PREF> -where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, +unsafe impl Send for Drain<'_, T, A, COOP_PREF> where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]: { } @@ -137,8 +132,7 @@ where where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:; - impl<'r, 'a, T, A: Allocator, const COOP_PREF: bool> Drop - for DropGuard<'r, 'a, T, A, COOP_PREF> + impl<'r, 'a, T, A: Allocator, const COOP_PREF: bool> Drop for DropGuard<'r, 'a, T, A, COOP_PREF> where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { @@ -247,8 +241,7 @@ where } #[stable(feature = "drain", since = "1.6.0")] -impl DoubleEndedIterator - for Drain<'_, T, A, COOP_PREF> +impl DoubleEndedIterator for Drain<'_, T, A, COOP_PREF> where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { @@ -264,10 +257,8 @@ where } #[stable(feature = "drain", since = "1.6.0")] -impl ExactSizeIterator - for Drain<'_, T, A, COOP_PREF> -where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, +impl ExactSizeIterator for Drain<'_, T, A, COOP_PREF> where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]: { } diff --git a/library/alloc/src/collections/vec_deque/into_iter.rs b/library/alloc/src/collections/vec_deque/into_iter.rs index 83e9c35bd40bc..dd4694c892a36 100644 --- a/library/alloc/src/collections/vec_deque/into_iter.rs +++ b/library/alloc/src/collections/vec_deque/into_iter.rs @@ -38,8 +38,7 @@ where } #[stable(feature = "collection_debug", since = "1.17.0")] -impl fmt::Debug - for IntoIter +impl fmt::Debug for IntoIter where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { @@ -188,8 +187,7 @@ where } #[stable(feature = "rust1", since = "1.0.0")] -impl DoubleEndedIterator - for IntoIter +impl DoubleEndedIterator for IntoIter where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { @@ -262,8 +260,7 @@ where } #[stable(feature = "rust1", since = "1.0.0")] -impl ExactSizeIterator - for IntoIter +impl ExactSizeIterator for IntoIter where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { @@ -280,9 +277,7 @@ impl FusedIterator for IntoIter TrustedLen - for IntoIter -where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, +unsafe impl TrustedLen for IntoIter where + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]: { } diff --git a/library/alloc/src/collections/vec_deque/mod.rs b/library/alloc/src/collections/vec_deque/mod.rs index 8e5331f88c25d..bb2c8ab0870a5 100644 --- a/library/alloc/src/collections/vec_deque/mod.rs +++ b/library/alloc/src/collections/vec_deque/mod.rs @@ -112,8 +112,7 @@ pub struct VecDeque< } #[stable(feature = "rust1", since = "1.0.0")] -impl Clone - for VecDeque +impl Clone for VecDeque where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { @@ -130,8 +129,7 @@ where } #[stable(feature = "rust1", since = "1.0.0")] -unsafe impl<#[may_dangle] T, A: Allocator, const COOP_PREF: bool> Drop - for VecDeque +unsafe impl<#[may_dangle] T, A: Allocator, const COOP_PREF: bool> Drop for VecDeque where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { @@ -2680,8 +2678,7 @@ fn wrap_index(logical_index: usize, capacity: usize) -> usize { } #[stable(feature = "rust1", since = "1.0.0")] -impl PartialEq - for VecDeque +impl PartialEq for VecDeque where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { @@ -2736,8 +2733,7 @@ __impl_slice_eq1! { [const N: usize] VecDeque, &[U; N], } __impl_slice_eq1! { [const N: usize] VecDeque, &mut [U; N], } #[stable(feature = "rust1", since = "1.0.0")] -impl PartialOrd - for VecDeque +impl PartialOrd for VecDeque where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { @@ -2824,8 +2820,7 @@ where } #[stable(feature = "rust1", since = "1.0.0")] -impl<'a, T, A: Allocator, const COOP_PREF: bool> IntoIterator - for &'a VecDeque +impl<'a, T, A: Allocator, const COOP_PREF: bool> IntoIterator for &'a VecDeque where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { @@ -2838,8 +2833,7 @@ where } #[stable(feature = "rust1", since = "1.0.0")] -impl<'a, T, A: Allocator, const COOP_PREF: bool> IntoIterator - for &'a mut VecDeque +impl<'a, T, A: Allocator, const COOP_PREF: bool> IntoIterator for &'a mut VecDeque where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { @@ -2893,8 +2887,7 @@ where } #[stable(feature = "rust1", since = "1.0.0")] -impl fmt::Debug - for VecDeque +impl fmt::Debug for VecDeque where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { @@ -2988,8 +2981,7 @@ where } #[stable(feature = "std_collections_from_array", since = "1.56.0")] -impl From<[T; N]> - for VecDeque +impl From<[T; N]> for VecDeque where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { diff --git a/library/alloc/src/collections/vec_deque/spec_extend.rs b/library/alloc/src/collections/vec_deque/spec_extend.rs index f4e6ff195bed2..c17be75f0e2fe 100644 --- a/library/alloc/src/collections/vec_deque/spec_extend.rs +++ b/library/alloc/src/collections/vec_deque/spec_extend.rs @@ -13,8 +13,7 @@ pub(super) trait SpecExtend { fn spec_extend(&mut self, iter: I); } -impl SpecExtend - for VecDeque +impl SpecExtend for VecDeque where I: Iterator, [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, @@ -59,8 +58,7 @@ where } } -impl SpecExtend - for VecDeque +impl SpecExtend for VecDeque where I: TrustedLen, [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, diff --git a/library/alloc/src/macros.rs b/library/alloc/src/macros.rs index 5fd5ed021e8a4..635b774a40e81 100644 --- a/library/alloc/src/macros.rs +++ b/library/alloc/src/macros.rs @@ -155,7 +155,7 @@ macro_rules! DEFAULT_COOP_PREF { #[macro_export] macro_rules! meta_num_slots { ($alloc:ty, $coop_pref:expr) => { - if ($alloc::IS_CO_ALLOCATOR) && ($coop_pref) { 1 } else { 0 } + if ($alloc::CO_ALLOCATES_WITH_META) && ($coop_pref) { 1 } else { 0 } }; } // -\---> replace with something like: @@ -164,7 +164,7 @@ macro_rules! meta_num_slots { pub const fn meta_num_slots( COOP_PREF: bool, ) -> usize { - if A::IS_CO_ALLOCATOR && COOP_PREF { 1 } else { 0 } + if A::CO_ALLOCATES_WITH_META && COOP_PREF { 1 } else { 0 } } */ @@ -181,7 +181,7 @@ pub const fn meta_num_slots( #[macro_export] macro_rules! meta_num_slots_default { ($alloc:ty) => { - if ($alloc::IS_CO_ALLOCATOR) && (DEFAULT_COOP_PREF!()) { 1 } else { 0 } + if ($alloc::CO_ALLOCATES_WITH_META) && (DEFAULT_COOP_PREF!()) { 1 } else { 0 } }; } @@ -191,7 +191,7 @@ macro_rules! meta_num_slots_default { #[macro_export] macro_rules! meta_num_slots_global { ($coop_pref:expr) => { - if ::alloc::alloc::Global::IS_CO_ALLOCATOR && ($coop_pref) { 1 } else { 0 } + if ::alloc::alloc::Global::CO_ALLOCATES_WITH_META && ($coop_pref) { 1 } else { 0 } }; } @@ -205,6 +205,6 @@ macro_rules! meta_num_slots_global { #[macro_export] macro_rules! meta_num_slots_default_global { () => { - if ::alloc::alloc::Global::IS_CO_ALLOCATOR && (DEFAULT_COOP_PREF!()) { 1 } else { 0 } + if ::alloc::alloc::Global::CO_ALLOCATES_WITH_META && (DEFAULT_COOP_PREF!()) { 1 } else { 0 } }; } diff --git a/library/alloc/src/raw_vec.rs b/library/alloc/src/raw_vec.rs index 3398ff40cda06..3678678ebb3b7 100644 --- a/library/alloc/src/raw_vec.rs +++ b/library/alloc/src/raw_vec.rs @@ -51,11 +51,8 @@ enum AllocInit { /// `Box<[T]>`, since `capacity()` won't yield the length. #[allow(missing_debug_implementations)] #[allow(unused_braces)] -pub(crate) struct RawVec< - T, - A: Allocator = Global, - const COOP_PREF: bool = { DEFAULT_COOP_PREF!() }, -> where +pub(crate) struct RawVec +where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { ptr: Unique, @@ -64,8 +61,8 @@ pub(crate) struct RawVec< // As of v1.67.0, `cmp` for `TypeId` is not `const`, unfortunately: //pub(crate) meta: [GlobalCoAllocMeta; {if core::any::TypeId::of::()==core::any::TypeId::of::() {1} else {0}}], //pub(crate) meta: [GlobalCoAllocMeta; mem::size_of::()], - pub(crate) metas: [GlobalCoAllocMeta; - alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)], + pub(crate) metas: + [GlobalCoAllocMeta; alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)], } impl RawVec @@ -517,15 +514,14 @@ where memory.map_err(|_| AllocError { layout: new_layout, non_exhaustive: () }.into()) } -unsafe impl<#[may_dangle] T, A: Allocator, const COOP_PREF: bool> Drop - for RawVec +unsafe impl<#[may_dangle] T, A: Allocator, const COOP_PREF: bool> Drop for RawVec where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { /// Frees the memory owned by the `RawVec` *without* trying to drop its contents. default fn drop(&mut self) { if let Some((ptr, layout)) = self.current_memory() { - if A::IS_CO_ALLOCATOR && COOP_PREF { + if A::CO_ALLOCATES_WITH_META && COOP_PREF { let meta = self.metas[0]; unsafe { self.alloc.co_deallocate(PtrAndMeta { ptr, meta }, layout) } } else { diff --git a/library/alloc/src/slice.rs b/library/alloc/src/slice.rs index 78762f9ec58fc..c6f581637cdad 100644 --- a/library/alloc/src/slice.rs +++ b/library/alloc/src/slice.rs @@ -97,9 +97,7 @@ pub(crate) mod hack { // We shouldn't add inline attribute to this since this is used in // `vec!` macro mostly and causes perf regression. See #71204 for // discussion and perf results. - pub fn into_vec( - b: Box<[T], A>, - ) -> Vec + pub fn into_vec(b: Box<[T], A>) -> Vec where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { @@ -467,10 +465,7 @@ impl [T] { #[rustc_allow_incoherent_impl] #[inline] #[unstable(feature = "allocator_api", issue = "32838")] - pub fn to_vec_in( - &self, - alloc: A, - ) -> Vec + pub fn to_vec_in(&self, alloc: A) -> Vec where T: Clone, [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, @@ -496,9 +491,7 @@ impl [T] { #[rustc_allow_incoherent_impl] #[stable(feature = "rust1", since = "1.0.0")] #[inline] - pub fn into_vec( - self: Box, - ) -> Vec + pub fn into_vec(self: Box) -> Vec where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { diff --git a/library/alloc/src/vec/drain.rs b/library/alloc/src/vec/drain.rs index 78a0d963ee5da..2fdc752ad2488 100644 --- a/library/alloc/src/vec/drain.rs +++ b/library/alloc/src/vec/drain.rs @@ -38,8 +38,7 @@ pub struct Drain< } #[stable(feature = "collection_debug", since = "1.17.0")] -impl fmt::Debug - for Drain<'_, T, A, COOP_PREF> +impl fmt::Debug for Drain<'_, T, A, COOP_PREF> where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { @@ -160,17 +159,13 @@ where } #[stable(feature = "drain", since = "1.6.0")] -unsafe impl Sync - for Drain<'_, T, A, COOP_PREF> -where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, +unsafe impl Sync for Drain<'_, T, A, COOP_PREF> where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]: { } #[stable(feature = "drain", since = "1.6.0")] -unsafe impl Send - for Drain<'_, T, A, COOP_PREF> -where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, +unsafe impl Send for Drain<'_, T, A, COOP_PREF> where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]: { } @@ -192,8 +187,7 @@ where } #[stable(feature = "drain", since = "1.6.0")] -impl DoubleEndedIterator - for Drain<'_, T, A, COOP_PREF> +impl DoubleEndedIterator for Drain<'_, T, A, COOP_PREF> where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { @@ -216,8 +210,7 @@ where where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:; - impl<'r, 'a, T, A: Allocator, const COOP_PREF: bool> Drop - for DropGuard<'r, 'a, T, A, COOP_PREF> + impl<'r, 'a, T, A: Allocator, const COOP_PREF: bool> Drop for DropGuard<'r, 'a, T, A, COOP_PREF> where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { @@ -284,8 +277,7 @@ where } #[stable(feature = "drain", since = "1.6.0")] -impl ExactSizeIterator - for Drain<'_, T, A, COOP_PREF> +impl ExactSizeIterator for Drain<'_, T, A, COOP_PREF> where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { @@ -295,10 +287,8 @@ where } #[unstable(feature = "trusted_len", issue = "37572")] -unsafe impl TrustedLen - for Drain<'_, T, A, COOP_PREF> -where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, +unsafe impl TrustedLen for Drain<'_, T, A, COOP_PREF> where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]: { } diff --git a/library/alloc/src/vec/drain_filter.rs b/library/alloc/src/vec/drain_filter.rs index 58a6ce6ca054b..82b302745a4f8 100644 --- a/library/alloc/src/vec/drain_filter.rs +++ b/library/alloc/src/vec/drain_filter.rs @@ -115,8 +115,7 @@ where } #[unstable(feature = "drain_filter", reason = "recently added", issue = "43244")] -impl Iterator - for DrainFilter<'_, T, F, A, COOP_PREF> +impl Iterator for DrainFilter<'_, T, F, A, COOP_PREF> where F: FnMut(&mut T) -> bool, [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, @@ -155,8 +154,7 @@ where } #[unstable(feature = "drain_filter", reason = "recently added", issue = "43244")] -impl Drop - for DrainFilter<'_, T, F, A, COOP_PREF> +impl Drop for DrainFilter<'_, T, F, A, COOP_PREF> where F: FnMut(&mut T) -> bool, [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, diff --git a/library/alloc/src/vec/into_iter.rs b/library/alloc/src/vec/into_iter.rs index fb37e19ec8c54..6c08acba77706 100644 --- a/library/alloc/src/vec/into_iter.rs +++ b/library/alloc/src/vec/into_iter.rs @@ -49,8 +49,7 @@ pub struct IntoIter< } #[stable(feature = "vec_intoiter_debug", since = "1.13.0")] -impl fmt::Debug - for IntoIter +impl fmt::Debug for IntoIter where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { @@ -198,17 +197,13 @@ where } #[stable(feature = "rust1", since = "1.0.0")] -unsafe impl Send - for IntoIter -where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, +unsafe impl Send for IntoIter where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]: { } #[stable(feature = "rust1", since = "1.0.0")] -unsafe impl Sync - for IntoIter -where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, +unsafe impl Sync for IntoIter where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]: { } @@ -330,8 +325,7 @@ where } #[stable(feature = "rust1", since = "1.0.0")] -impl DoubleEndedIterator - for IntoIter +impl DoubleEndedIterator for IntoIter where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { @@ -375,8 +369,7 @@ where } #[stable(feature = "rust1", since = "1.0.0")] -impl ExactSizeIterator - for IntoIter +impl ExactSizeIterator for IntoIter where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { @@ -392,10 +385,8 @@ impl FusedIterator for IntoIter TrustedLen - for IntoIter -where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, +unsafe impl TrustedLen for IntoIter where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]: { } @@ -424,8 +415,7 @@ where #[cfg(not(no_global_oom_handling))] #[stable(feature = "vec_into_iter_clone", since = "1.8.0")] -impl Clone - for IntoIter +impl Clone for IntoIter where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { @@ -447,8 +437,7 @@ where } #[stable(feature = "rust1", since = "1.0.0")] -unsafe impl<#[may_dangle] T, A: Allocator, const COOP_PREF: bool> Drop - for IntoIter +unsafe impl<#[may_dangle] T, A: Allocator, const COOP_PREF: bool> Drop for IntoIter where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { @@ -491,17 +480,14 @@ where // also refer to the vec::in_place_collect module documentation to get an overview #[unstable(issue = "none", feature = "inplace_iteration")] #[doc(hidden)] -unsafe impl InPlaceIterable - for IntoIter -where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, +unsafe impl InPlaceIterable for IntoIter where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]: { } #[unstable(issue = "none", feature = "inplace_iteration")] #[doc(hidden)] -unsafe impl SourceIter - for IntoIter +unsafe impl SourceIter for IntoIter where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { diff --git a/library/alloc/src/vec/mod.rs b/library/alloc/src/vec/mod.rs index 2174e49e0c015..44c1707331133 100644 --- a/library/alloc/src/vec/mod.rs +++ b/library/alloc/src/vec/mod.rs @@ -2615,9 +2615,7 @@ where // - `new_cap` refers to the same sized allocation as `cap` because // `new_cap * size_of::()` == `cap * size_of::<[T; N]>()` // - `len` <= `cap`, so `len * N` <= `cap * N`. - unsafe { - Vec::::from_raw_parts_in(ptr.cast(), new_len, new_cap, alloc) - } + unsafe { Vec::::from_raw_parts_in(ptr.cast(), new_len, new_cap, alloc) } } } @@ -2730,8 +2728,7 @@ trait ExtendFromWithinSpec { unsafe fn spec_extend_from_within(&mut self, src: Range); } -impl ExtendFromWithinSpec - for Vec +impl ExtendFromWithinSpec for Vec where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { @@ -2753,8 +2750,7 @@ where } } -impl ExtendFromWithinSpec - for Vec +impl ExtendFromWithinSpec for Vec where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { @@ -2868,8 +2864,7 @@ where message = "vector indices are of type `usize` or ranges of `usize`", label = "vector indices are of type `usize` or ranges of `usize`" )] -impl, A: Allocator, const COOP_PREF: bool> Index - for Vec +impl, A: Allocator, const COOP_PREF: bool> Index for Vec where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { @@ -2972,8 +2967,7 @@ where } #[stable(feature = "rust1", since = "1.0.0")] -impl<'a, T, A: Allocator, const COOP_PREF: bool> IntoIterator - for &'a mut Vec +impl<'a, T, A: Allocator, const COOP_PREF: bool> IntoIterator for &'a mut Vec where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { @@ -3212,8 +3206,7 @@ where /// Implements comparison of vectors, [lexicographically](core::cmp::Ord#lexicographical-comparison). #[stable(feature = "rust1", since = "1.0.0")] -impl PartialOrd - for Vec +impl PartialOrd for Vec where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { @@ -3242,8 +3235,7 @@ where } #[stable(feature = "rust1", since = "1.0.0")] -unsafe impl<#[may_dangle] T, A: Allocator, const COOP_PREF: bool> Drop - for Vec +unsafe impl<#[may_dangle] T, A: Allocator, const COOP_PREF: bool> Drop for Vec where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { @@ -3273,8 +3265,7 @@ where } #[stable(feature = "rust1", since = "1.0.0")] -impl fmt::Debug - for Vec +impl fmt::Debug for Vec where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { @@ -3284,8 +3275,7 @@ where } #[stable(feature = "rust1", since = "1.0.0")] -impl AsRef> - for Vec +impl AsRef> for Vec where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { @@ -3295,8 +3285,7 @@ where } #[stable(feature = "vec_as_mut", since = "1.5.0")] -impl AsMut> - for Vec +impl AsMut> for Vec where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { diff --git a/library/alloc/src/vec/spec_extend.rs b/library/alloc/src/vec/spec_extend.rs index 0d5b6160f7b9f..99d96bcca97c1 100644 --- a/library/alloc/src/vec/spec_extend.rs +++ b/library/alloc/src/vec/spec_extend.rs @@ -30,8 +30,7 @@ where } } -impl SpecExtend> - for Vec +impl SpecExtend> for Vec where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { diff --git a/library/alloc/src/vec/splice.rs b/library/alloc/src/vec/splice.rs index 765b39221ce80..c2cbff33e4b51 100644 --- a/library/alloc/src/vec/splice.rs +++ b/library/alloc/src/vec/splice.rs @@ -32,8 +32,7 @@ pub struct Splice< } #[stable(feature = "vec_splice", since = "1.21.0")] -impl Iterator - for Splice<'_, I, A, COOP_PREF> +impl Iterator for Splice<'_, I, A, COOP_PREF> where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { @@ -68,8 +67,7 @@ where } #[stable(feature = "vec_splice", since = "1.21.0")] -impl Drop - for Splice<'_, I, A, COOP_PREF> +impl Drop for Splice<'_, I, A, COOP_PREF> where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { diff --git a/library/core/src/alloc/mod.rs b/library/core/src/alloc/mod.rs index b2474072af3e4..eb2b94d5f6c59 100644 --- a/library/core/src/alloc/mod.rs +++ b/library/core/src/alloc/mod.rs @@ -103,7 +103,7 @@ pub type SliceAndMetaResult = Result; pub const fn co_alloc_metadata_num_slots_with_preference( coop_preferred: bool, ) -> usize { - if A::IS_CO_ALLOCATOR && coop_preferred { 1 } else { 0 } + if A::CO_ALLOCATES_WITH_META && coop_preferred { 1 } else { 0 } } /// An implementation of `Allocator` can allocate, grow, shrink, and deallocate arbitrary blocks of @@ -170,8 +170,9 @@ pub unsafe trait Allocator { /// If this is any type with non-zero size, then the actual `Allocator` implementation supports cooperative functions (`co_*`) as first class citizens. //type IsCoAllocator = (); // It applies to the global (default) allocator only. And/or System allocator?! @FIXME - // @FIXME make false by default - const IS_CO_ALLOCATOR: bool = true; + const CO_ALLOCATES_WITH_META: bool = false; + + type CoAllocMeta: Clone + Copy = (); /// Attempts to allocate a block of memory. /// diff --git a/library/std/src/alloc.rs b/library/std/src/alloc.rs index 6969c7d81dd5e..a2dcb9d5b78a1 100644 --- a/library/std/src/alloc.rs +++ b/library/std/src/alloc.rs @@ -202,8 +202,6 @@ impl System { // which is in `std::sys::*::alloc`. #[unstable(feature = "allocator_api", issue = "32838")] unsafe impl Allocator for System { - const IS_CO_ALLOCATOR: bool = false; - #[inline] fn allocate(&self, layout: Layout) -> Result, AllocError> { self.alloc_impl(layout, false) From c5e76a3175b840cbc2a052c75bcff958d0009d6e Mon Sep 17 00:00:00 2001 From: Peter Kehl Date: Wed, 25 Jan 2023 20:43:09 -0800 Subject: [PATCH 085/118] CoAlloc: Moved CoAllocMeta to both Allocator and GlobalAlloc. --- library/alloc/src/raw_vec.rs | 13 +++++--- library/core/src/alloc/global.rs | 24 +++++++++----- library/core/src/alloc/mod.rs | 54 ++++++++++++++------------------ 3 files changed, 47 insertions(+), 44 deletions(-) diff --git a/library/alloc/src/raw_vec.rs b/library/alloc/src/raw_vec.rs index 3678678ebb3b7..d47b07c38b2b0 100644 --- a/library/alloc/src/raw_vec.rs +++ b/library/alloc/src/raw_vec.rs @@ -1,6 +1,6 @@ #![unstable(feature = "raw_vec_internals", reason = "unstable const warnings", issue = "none")] -use core::alloc::{self, GlobalCoAllocMeta, LayoutError, PtrAndMeta}; +use core::alloc::{self, LayoutError, PtrAndMeta}; use core::cmp; use core::intrinsics; use core::mem::{self, ManuallyDrop, MaybeUninit, SizedTypeProperties}; @@ -62,7 +62,7 @@ where //pub(crate) meta: [GlobalCoAllocMeta; {if core::any::TypeId::of::()==core::any::TypeId::of::() {1} else {0}}], //pub(crate) meta: [GlobalCoAllocMeta; mem::size_of::()], pub(crate) metas: - [GlobalCoAllocMeta; alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)], + [A::CoAllocMeta; alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)], } impl RawVec @@ -136,11 +136,12 @@ where /// the returned `RawVec`. pub const fn new_in(alloc: A) -> Self { // `cap: 0` means "unallocated". zero-sized types are ignored. + #[allow(unreachable_code)] // @FIXME CoAlloc Self { ptr: Unique::dangling(), cap: 0, alloc, - metas: [GlobalCoAllocMeta {/*one: 1*/ /* , two: 2, three: 3, four: 4*/}; + metas: [loop {}; // @FIXME CoAlloc alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)], } } @@ -215,11 +216,12 @@ where // Allocators currently return a `NonNull<[u8]>` whose length // matches the size requested. If that ever changes, the capacity // here should change to `ptr.len() / mem::size_of::()`. + #[allow(unreachable_code)] // @FIXME CoAlloc Self { ptr: unsafe { Unique::new_unchecked(ptr.cast().as_ptr()) }, cap: capacity, alloc, - metas: [GlobalCoAllocMeta {/*one: 1*/ /*, two: 2, three: 3, four: 4*/}; + metas: [loop {}; // @FIXME CoAlloc alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)], } } @@ -237,11 +239,12 @@ where /// guaranteed. #[inline] pub unsafe fn from_raw_parts_in(ptr: *mut T, capacity: usize, alloc: A) -> Self { + #[allow(unreachable_code)] //@FIXME CoAlloc Self { ptr: unsafe { Unique::new_unchecked(ptr) }, cap: capacity, alloc, - metas: [GlobalCoAllocMeta {/*one: 1*/ /*, two: 2, three: 3, four: 4*/}; + metas: [loop {}; //@FIXME CoAlloc alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)], } } diff --git a/library/core/src/alloc/global.rs b/library/core/src/alloc/global.rs index e048c01d34bce..a6c9c6f12ded8 100644 --- a/library/core/src/alloc/global.rs +++ b/library/core/src/alloc/global.rs @@ -1,4 +1,3 @@ -use crate::alloc::GlobalCoAllocMeta; use crate::alloc::Layout; use crate::cmp; use crate::ptr; @@ -6,9 +5,9 @@ use crate::ptr; #[unstable(feature = "global_co_alloc_meta", issue = "none")] #[allow(missing_debug_implementations)] /// Used for parameters and results (to/from `GlobalCoAllocator`'s functions, where applicable). -pub struct RawAndMeta { +pub struct RawAndMeta { pub ptr: *mut u8, - pub meta: GlobalCoAllocMeta, + pub meta: M, } /// A memory allocator that can be registered as the standard library’s default @@ -130,6 +129,11 @@ pub struct RawAndMeta { /// having side effects. #[stable(feature = "global_alloc", since = "1.28.0")] pub unsafe trait GlobalAlloc { + /// @FIXME Validate (preferrable at compile time, otherwise as a test) that this type's + /// alignment <= `usize` alignment. + #[unstable(feature = "global_co_alloc_meta", issue = "none")] + type CoAllocMeta: Clone + Copy = (); + /// Allocate memory as described by the given `layout`. /// /// Returns a pointer to newly-allocated memory, @@ -166,7 +170,7 @@ pub unsafe trait GlobalAlloc { unsafe fn alloc(&self, layout: Layout) -> *mut u8; #[unstable(feature = "global_co_alloc", issue = "none")] - unsafe fn co_alloc(&self, _layout: Layout, mut _result: &mut RawAndMeta) { + unsafe fn co_alloc(&self, _layout: Layout, mut _result: &mut RawAndMeta) { panic!("@FIXME") } @@ -186,7 +190,7 @@ pub unsafe trait GlobalAlloc { unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout); #[unstable(feature = "global_co_alloc", issue = "none")] - unsafe fn co_dealloc(&self, _ptr_and_meta: RawAndMeta, _layout: Layout) { + unsafe fn co_dealloc(&self, _ptr_and_meta: RawAndMeta, _layout: Layout) { panic!("@FIXME") } @@ -223,7 +227,11 @@ pub unsafe trait GlobalAlloc { } #[unstable(feature = "global_co_alloc", issue = "none")] - unsafe fn co_alloc_zeroed(&self, layout: Layout, mut result: &mut RawAndMeta) { + unsafe fn co_alloc_zeroed( + &self, + layout: Layout, + mut result: &mut RawAndMeta, + ) { let size = layout.size(); // SAFETY: the safety contract for `alloc` must be upheld by the caller. unsafe { self.co_alloc(layout, &mut result) }; @@ -310,10 +318,10 @@ pub unsafe trait GlobalAlloc { #[unstable(feature = "global_co_alloc", issue = "none")] unsafe fn co_realloc( &self, - ptr_and_meta: RawAndMeta, + ptr_and_meta: RawAndMeta, layout: Layout, new_size: usize, - mut result: &mut RawAndMeta, + mut result: &mut RawAndMeta, ) { // SAFETY: the caller must ensure that the `new_size` does not overflow. // `layout.align()` comes from a `Layout` and is thus guaranteed to be valid. diff --git a/library/core/src/alloc/mod.rs b/library/core/src/alloc/mod.rs index eb2b94d5f6c59..7c14e2c55a62c 100644 --- a/library/core/src/alloc/mod.rs +++ b/library/core/src/alloc/mod.rs @@ -25,23 +25,6 @@ use crate::error::Error; use crate::fmt; use crate::ptr::{self, NonNull}; -// @FIXME Make this target-specific -/// Metadata for `Vec/VecDeque/RawVec` to assist the allocator. Make sure its -/// alignment is not bigger than alignment of `usize`. Otherwise, even if (a -/// particular) `Vec/VecDeque/RawVec` generic instance doesn't use cooperation, -/// it would increase size of that `Vec/VecDeque/RawVec` because of alignment -/// rules! @FIXME compile time test that `GlobalCoAllocMeta` alignment <= -/// `usize` alignment. -#[unstable(feature = "global_co_alloc_meta", issue = "none")] -#[allow(missing_debug_implementations)] -#[derive(Clone, Copy)] -pub struct GlobalCoAllocMeta { - //pub one: usize, - /*pub two: usize, - pub three: usize, - pub four: usize,*/ -} - /// The `AllocError` error indicates an allocation failure /// that may be due to resource exhaustion or to /// something wrong when combining the given input arguments with this @@ -68,18 +51,20 @@ impl fmt::Display for AllocError { /// (Non-Null) Pointer and coallocation metadata. #[unstable(feature = "global_co_alloc_meta", issue = "none")] #[allow(missing_debug_implementations)] -pub struct PtrAndMeta { +#[derive(Clone, Copy)] +pub struct PtrAndMeta { pub ptr: NonNull, - pub meta: GlobalCoAllocMeta, + pub meta: M, } /// (NonNull) Slice and coallocation metadata. #[unstable(feature = "global_co_alloc_meta", issue = "none")] #[allow(missing_debug_implementations)] +#[derive(Clone, Copy)] /// Used for results (from `CoAllocator`'s functions, where applicable). -pub struct SliceAndMeta { +pub struct SliceAndMeta { pub slice: NonNull<[u8]>, - pub meta: GlobalCoAllocMeta, + pub meta: M, } #[unstable(feature = "global_co_alloc_short_term_pref", issue = "none")] @@ -94,8 +79,9 @@ macro_rules! SHORT_TERM_VEC_PREFERS_COOP { /// `Result` of `SliceAndMeta` or `AllocError`. #[unstable(feature = "global_co_alloc_meta", issue = "none")] #[allow(missing_debug_implementations)] -pub type SliceAndMetaResult = Result; +pub type SliceAndMetaResult = Result, AllocError>; +// @FIXME REMOVE /// Return 0 or 1, indicating whether to use coallocation metadata or not. /// Param `coop_preferred` - if false, then this returns `0`, regardless of /// whether allocator `A` is cooperative. @@ -172,6 +158,8 @@ pub unsafe trait Allocator { // It applies to the global (default) allocator only. And/or System allocator?! @FIXME const CO_ALLOCATES_WITH_META: bool = false; + /// @FIXME Validate (preferrable at compile time, otherwise as a test) that this type's + /// alignment <= `usize` alignment. type CoAllocMeta: Clone + Copy = (); /// Attempts to allocate a block of memory. @@ -196,7 +184,7 @@ pub unsafe trait Allocator { /// [`handle_alloc_error`]: ../../alloc/alloc/fn.handle_alloc_error.html fn allocate(&self, layout: Layout) -> Result, AllocError>; - fn co_allocate(&self, _layout: Layout, _result: &mut SliceAndMetaResult) { + fn co_allocate(&self, _layout: Layout, _result: &mut SliceAndMetaResult) { panic!("FIXME") } @@ -222,7 +210,11 @@ pub unsafe trait Allocator { Ok(ptr) } - fn co_allocate_zeroed(&self, layout: Layout, mut result: &mut SliceAndMetaResult) { + fn co_allocate_zeroed( + &self, + layout: Layout, + mut result: &mut SliceAndMetaResult, + ) { self.co_allocate(layout, &mut result); if let Ok(SliceAndMeta { slice, .. }) = result { // SAFETY: `alloc` returns a valid memory block @@ -241,7 +233,7 @@ pub unsafe trait Allocator { /// [*fit*]: #memory-fitting unsafe fn deallocate(&self, ptr: NonNull, layout: Layout); - unsafe fn co_deallocate(&self, _ptr_and_meta: PtrAndMeta, _layout: Layout) { + unsafe fn co_deallocate(&self, _ptr_and_meta: PtrAndMeta, _layout: Layout) { panic!("FIXME") } @@ -311,10 +303,10 @@ pub unsafe trait Allocator { unsafe fn co_grow( &self, - ptr_and_meta: PtrAndMeta, + ptr_and_meta: PtrAndMeta, old_layout: Layout, new_layout: Layout, - mut result: &mut SliceAndMetaResult, + mut result: &mut SliceAndMetaResult, ) { debug_assert!( new_layout.size() >= old_layout.size(), @@ -405,10 +397,10 @@ pub unsafe trait Allocator { unsafe fn co_grow_zeroed( &self, - ptr_and_meta: PtrAndMeta, + ptr_and_meta: PtrAndMeta, old_layout: Layout, new_layout: Layout, - mut result: &mut SliceAndMetaResult, + mut result: &mut SliceAndMetaResult, ) { debug_assert!( new_layout.size() >= old_layout.size(), @@ -500,10 +492,10 @@ pub unsafe trait Allocator { unsafe fn co_shrink( &self, - ptr_and_meta: PtrAndMeta, + ptr_and_meta: PtrAndMeta, old_layout: Layout, new_layout: Layout, - mut result: &mut SliceAndMetaResult, + mut result: &mut SliceAndMetaResult, ) { debug_assert!( new_layout.size() <= old_layout.size(), From e8d7dbd431f7f7cf63fcd0aa827ad592be48fe05 Mon Sep 17 00:00:00 2001 From: Peter Kehl Date: Thu, 26 Jan 2023 00:13:27 -0800 Subject: [PATCH 086/118] CoAlloc: meta_num_slots... macros- WIP --- library/alloc/src/raw_vec.rs | 8 +++---- library/core/src/alloc/global.rs | 9 +++++--- library/core/src/alloc/mod.rs | 36 +++++++++++++++++++++++++------- 3 files changed, 38 insertions(+), 15 deletions(-) diff --git a/library/alloc/src/raw_vec.rs b/library/alloc/src/raw_vec.rs index d47b07c38b2b0..120dc42f3b59f 100644 --- a/library/alloc/src/raw_vec.rs +++ b/library/alloc/src/raw_vec.rs @@ -7,6 +7,7 @@ use core::mem::{self, ManuallyDrop, MaybeUninit, SizedTypeProperties}; use core::ops::Drop; use core::ptr::{self, NonNull, Unique}; use core::slice; +use core::alloc::CoAllocMetaBase; #[cfg(not(no_global_oom_handling))] use crate::alloc::handle_alloc_error; @@ -136,12 +137,11 @@ where /// the returned `RawVec`. pub const fn new_in(alloc: A) -> Self { // `cap: 0` means "unallocated". zero-sized types are ignored. - #[allow(unreachable_code)] // @FIXME CoAlloc Self { ptr: Unique::dangling(), cap: 0, alloc, - metas: [loop {}; // @FIXME CoAlloc + metas: [A::CoAllocMeta::new_plain(); // @FIXME CoAlloc alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)], } } @@ -221,7 +221,7 @@ where ptr: unsafe { Unique::new_unchecked(ptr.cast().as_ptr()) }, cap: capacity, alloc, - metas: [loop {}; // @FIXME CoAlloc + metas: [A::CoAllocMeta::new_plain(); // @FIXME CoAlloc alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)], } } @@ -244,7 +244,7 @@ where ptr: unsafe { Unique::new_unchecked(ptr) }, cap: capacity, alloc, - metas: [loop {}; //@FIXME CoAlloc + metas: [A::CoAllocMeta::new_plain(); //@FIXME CoAlloc alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)], } } diff --git a/library/core/src/alloc/global.rs b/library/core/src/alloc/global.rs index a6c9c6f12ded8..ffb350a3294e9 100644 --- a/library/core/src/alloc/global.rs +++ b/library/core/src/alloc/global.rs @@ -1,11 +1,12 @@ use crate::alloc::Layout; +use crate::alloc::{CoAllocMetaBase, CoAllocMetaPlain}; use crate::cmp; use crate::ptr; #[unstable(feature = "global_co_alloc_meta", issue = "none")] -#[allow(missing_debug_implementations)] +#[derive(Debug)] /// Used for parameters and results (to/from `GlobalCoAllocator`'s functions, where applicable). -pub struct RawAndMeta { +pub struct RawAndMeta { pub ptr: *mut u8, pub meta: M, } @@ -129,10 +130,12 @@ pub struct RawAndMeta { /// having side effects. #[stable(feature = "global_alloc", since = "1.28.0")] pub unsafe trait GlobalAlloc { + /// NOT for public use. The default value MAY be REMOVED or CHANGED. + /// /// @FIXME Validate (preferrable at compile time, otherwise as a test) that this type's /// alignment <= `usize` alignment. #[unstable(feature = "global_co_alloc_meta", issue = "none")] - type CoAllocMeta: Clone + Copy = (); + type CoAllocMeta: CoAllocMetaBase = CoAllocMetaPlain; /// Allocate memory as described by the given `layout`. /// diff --git a/library/core/src/alloc/mod.rs b/library/core/src/alloc/mod.rs index 7c14e2c55a62c..5a2422719e472 100644 --- a/library/core/src/alloc/mod.rs +++ b/library/core/src/alloc/mod.rs @@ -50,19 +50,17 @@ impl fmt::Display for AllocError { /// (Non-Null) Pointer and coallocation metadata. #[unstable(feature = "global_co_alloc_meta", issue = "none")] -#[allow(missing_debug_implementations)] -#[derive(Clone, Copy)] -pub struct PtrAndMeta { +#[derive(Clone, Copy, Debug)] +pub struct PtrAndMeta { pub ptr: NonNull, pub meta: M, } /// (NonNull) Slice and coallocation metadata. #[unstable(feature = "global_co_alloc_meta", issue = "none")] -#[allow(missing_debug_implementations)] -#[derive(Clone, Copy)] +#[derive(Clone, Copy, Debug)] /// Used for results (from `CoAllocator`'s functions, where applicable). -pub struct SliceAndMeta { +pub struct SliceAndMeta { pub slice: NonNull<[u8]>, pub meta: M, } @@ -78,7 +76,6 @@ macro_rules! SHORT_TERM_VEC_PREFERS_COOP { /// `Result` of `SliceAndMeta` or `AllocError`. #[unstable(feature = "global_co_alloc_meta", issue = "none")] -#[allow(missing_debug_implementations)] pub type SliceAndMetaResult = Result, AllocError>; // @FIXME REMOVE @@ -158,9 +155,11 @@ pub unsafe trait Allocator { // It applies to the global (default) allocator only. And/or System allocator?! @FIXME const CO_ALLOCATES_WITH_META: bool = false; + /// NOT for public use. The default value MAY be REMOVED or CHANGED. + /// /// @FIXME Validate (preferrable at compile time, otherwise as a test) that this type's /// alignment <= `usize` alignment. - type CoAllocMeta: Clone + Copy = (); + type CoAllocMeta: CoAllocMetaBase = CoAllocMetaPlain; /// Attempts to allocate a block of memory. /// @@ -588,3 +587,24 @@ where unsafe { (**self).shrink(ptr, old_layout, new_layout) } } } + +#[unstable(feature = "global_co_alloc_meta", issue = "none")] +pub trait CoAllocMetaBase: Clone + Copy { + /// NOT for public use. This MAY BE REMOVED or CHANGED. + /// + /// For EXPERIMENTATION only. + fn new_plain() -> Self; +} + +#[unstable(feature = "global_co_alloc_meta", issue = "none")] +#[derive(Clone, Copy, Debug)] +pub struct CoAllocMetaPlain {} + +static CO_ALLOC_META_PLAIN: CoAllocMetaPlain = CoAllocMetaPlain {}; + +#[unstable(feature = "global_co_alloc_meta", issue = "none")] +impl CoAllocMetaBase for CoAllocMetaPlain { + fn new_plain() -> Self { + CO_ALLOC_META_PLAIN + } +} \ No newline at end of file From 37c55a37a8cadc38c2dbc1e4a28f401096b84239 Mon Sep 17 00:00:00 2001 From: Peter Kehl Date: Thu, 26 Jan 2023 22:08:21 -0800 Subject: [PATCH 087/118] CoAlloc: meta_num_slots... macros- WIP.. --- library/alloc/src/macros.rs | 12 ++-- library/alloc/src/raw_vec.rs | 5 ++ library/core/src/alloc/mod.rs | 108 +++++++++++++++++++++++++++++----- 3 files changed, 106 insertions(+), 19 deletions(-) diff --git a/library/alloc/src/macros.rs b/library/alloc/src/macros.rs index 635b774a40e81..9596af21b2e52 100644 --- a/library/alloc/src/macros.rs +++ b/library/alloc/src/macros.rs @@ -155,7 +155,7 @@ macro_rules! DEFAULT_COOP_PREF { #[macro_export] macro_rules! meta_num_slots { ($alloc:ty, $coop_pref:expr) => { - if ($alloc::CO_ALLOCATES_WITH_META) && ($coop_pref) { 1 } else { 0 } + if ($alloc::CO_ALLOC_META_NUM_SLOTS) && ($coop_pref) { 1 } else { 0 } }; } // -\---> replace with something like: @@ -164,7 +164,7 @@ macro_rules! meta_num_slots { pub const fn meta_num_slots( COOP_PREF: bool, ) -> usize { - if A::CO_ALLOCATES_WITH_META && COOP_PREF { 1 } else { 0 } + if A::CO_ALLOC_META_NUM_SLOTS && COOP_PREF { 1 } else { 0 } } */ @@ -180,8 +180,10 @@ pub const fn meta_num_slots( #[unstable(feature = "global_co_alloc", issue = "none")] #[macro_export] macro_rules! meta_num_slots_default { + // Can't generate if ... {1} else {0} + // because it's "overly complex generic constant". ($alloc:ty) => { - if ($alloc::CO_ALLOCATES_WITH_META) && (DEFAULT_COOP_PREF!()) { 1 } else { 0 } + if (<$alloc>::CO_ALLOC_META_NUM_SLOTS) && (DEFAULT_COOP_PREF!()) { 1 } else { 0 } }; } @@ -191,7 +193,7 @@ macro_rules! meta_num_slots_default { #[macro_export] macro_rules! meta_num_slots_global { ($coop_pref:expr) => { - if ::alloc::alloc::Global::CO_ALLOCATES_WITH_META && ($coop_pref) { 1 } else { 0 } + if ::alloc::alloc::Global::CO_ALLOC_META_NUM_SLOTS && ($coop_pref) { 1 } else { 0 } }; } @@ -205,6 +207,6 @@ macro_rules! meta_num_slots_global { #[macro_export] macro_rules! meta_num_slots_default_global { () => { - if ::alloc::alloc::Global::CO_ALLOCATES_WITH_META && (DEFAULT_COOP_PREF!()) { 1 } else { 0 } + if ::alloc::alloc::Global::CO_ALLOC_META_NUM_SLOTS && (DEFAULT_COOP_PREF!()) { 1 } else { 0 } }; } diff --git a/library/alloc/src/raw_vec.rs b/library/alloc/src/raw_vec.rs index 120dc42f3b59f..cee70f1c67d2d 100644 --- a/library/alloc/src/raw_vec.rs +++ b/library/alloc/src/raw_vec.rs @@ -1,5 +1,6 @@ #![unstable(feature = "raw_vec_internals", reason = "unstable const warnings", issue = "none")] +use crate::meta_num_slots_default; use core::alloc::{self, LayoutError, PtrAndMeta}; use core::cmp; use core::intrinsics; @@ -120,6 +121,10 @@ impl RawVec where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { + const fn new_plain_metas() -> [A::CoAllocMeta; {meta_num_slots_default!(A)}] { + loop {} + } + // Tiny Vecs are dumb. Skip to: // - 8 if the element size is 1, because any heap allocators is likely // to round up a request of less than 8 bytes to at least 8 bytes. diff --git a/library/core/src/alloc/mod.rs b/library/core/src/alloc/mod.rs index 5a2422719e472..911cc5e042024 100644 --- a/library/core/src/alloc/mod.rs +++ b/library/core/src/alloc/mod.rs @@ -48,6 +48,75 @@ impl fmt::Display for AllocError { } } +/// `CoAllocPref` values indicate a type's preference for coallocation (in either user space, or +/// `std` space). Used as a `const` generic parameter type (usually called `CO_ALLOC_PREF`). +/// +/// The actual value may be overriden by the allocator. See also `CoAllocMetaNumSlotsPref` and +/// `co_alloc_pref` macro . +/// +/// This type WILL CHANGE (once ``#![feature(generic_const_exprs)]` and +/// `#![feature(adt_const_params)]` are stable) to a dedicated struct/enum. Hence: +/// - DO NOT construct instances, but use `co_alloc_pref` macro together with constants +/// `CO_ALLOC_PREF_YES` and `CO_ALLOC_PREF_NO`; +/// - DO NOT hard code any values; and +/// - DO NOT mix this/cast this with/to `usize` (nor any other integers). +/// +/// @FIXME CO_ALLOC_PREF_DEFAULT - as a separate constant, or a "keyword" recognized by +/// `co_alloc_pref` macro? +#[unstable(feature = "global_co_alloc_meta", issue = "none")] +pub type CoAllocPref = usize; + +/// `CoAllocMetaNumSlotsPref` values indicate a type prefers to coallocate by carrying metadata, or +/// not. (In either user space, or `std` space). Used as an argument to macro call of +/// `co_alloc_pref`, which generates a `CoAllocPref` value. +/// +/// Currently this indicates only the (preferred) number of `CoAllocMetaBase` slots being used +/// (either 1 = coallocation, or 0 = no coallocation). However, in the future this type may have +/// other properties (serving as extra hints to the allocator). +/// +/// The actual value may be overriden by the allocator. For example, if the allocator doesn't +/// support coallocation, then whether this value prefers to coallocate or not makes no difference. +/// +/// This type WILL CHANGE (once ``#![feature(generic_const_exprs)]` and +/// `#![feature(adt_const_params)]` are stable) to a dedicated struct/enum. Hence: +/// - DO NOT mix this/cast this with/to `isize` (nor any other integers); and +/// - DO NOT hard code any values, but use `CO_ALLOC_PREF_YES` and `CO_ALLOC_PREF_NO`. +/// +/// Currently this type is intentionally not `usize`. Why? This helps to prevent mistakes when one +/// would use `CO_ALLOC_PREF_YES` or `CO_ALLOC_PREF_NO` in place of `CoAllocPref` vales. +#[unstable(feature = "global_co_alloc_meta", issue = "none")] +pub type CoAllocMetaNumSlotsPref = isize; + +/// "Yes" as a type's preference for coallocation (in either user space, or `std` space). +/// +/// It may be overriden by the allocator. For example, if the allocator doesn't support +/// coallocation, then this value makes no difference. +/// +/// This constant and its type WILL CHANGE (once ``#![feature(generic_const_exprs)]` and +/// `#![feature(adt_const_params)]` are stable) to a dedicated struct/enum. Hence DO NOT hard +/// code/replace/mix this any other values/parameters. +#[unstable(feature = "global_co_alloc_meta", issue = "none")] +pub const CO_ALLOC_PREF_YES: CoAllocMetaNumSlotsPref = 1; + +/// "No" as a type's preference for coallocation (in either user space, or `std` space). +/// +/// Any allocator is required to respect this. Even if the allocator does support coallocation, it +/// will not coallocate types that use this value. +/// +/// This constant and its type WILL CHANGE (once ``#![feature(generic_const_exprs)]` and +/// `#![feature(adt_const_params)]` are stable) to a dedicated struct/enum. Hence DO NOT hard +/// code/replace/mix this any other values/parameters. +#[unstable(feature = "global_co_alloc_meta", issue = "none")] +pub const CO_ALLOC_PREF_NO: CoAllocMetaNumSlotsPref = 0; + +#[unstable(feature = "global_co_alloc_meta", issue = "none")] +#[macro_export] +macro_rules! co_alloc_pref { + ($coop_pref:expr) => { + if ::alloc::alloc::Global::CO_ALLOC_META_NUM_SLOTS && ($coop_pref) { 1 } else { 0 } + }; +} + /// (Non-Null) Pointer and coallocation metadata. #[unstable(feature = "global_co_alloc_meta", issue = "none")] #[derive(Clone, Copy, Debug)] @@ -79,14 +148,13 @@ macro_rules! SHORT_TERM_VEC_PREFERS_COOP { pub type SliceAndMetaResult = Result, AllocError>; // @FIXME REMOVE -/// Return 0 or 1, indicating whether to use coallocation metadata or not. -/// Param `coop_preferred` - if false, then this returns `0`, regardless of -/// whether allocator `A` is cooperative. +/// Return 0 or 1, indicating whether to use coallocation metadata or not. Param `coop_preferred` - +/// if false, then this returns `0`, regardless of whether allocator `A` is cooperative. #[unstable(feature = "global_co_alloc", issue = "none")] pub const fn co_alloc_metadata_num_slots_with_preference( coop_preferred: bool, ) -> usize { - if A::CO_ALLOCATES_WITH_META && coop_preferred { 1 } else { 0 } + if coop_preferred { A::CO_ALLOC_META_NUM_SLOTS } else { 0 } } /// An implementation of `Allocator` can allocate, grow, shrink, and deallocate arbitrary blocks of @@ -148,15 +216,18 @@ pub const fn co_alloc_metadata_num_slots_with_preference( #[unstable(feature = "allocator_api", issue = "32838")] #[const_trait] pub unsafe trait Allocator { - //const fn is_co_allocator() -> bool {false} - // Can't have: const type Xyz; - /// If this is any type with non-zero size, then the actual `Allocator` implementation supports cooperative functions (`co_*`) as first class citizens. - //type IsCoAllocator = (); - // It applies to the global (default) allocator only. And/or System allocator?! @FIXME - const CO_ALLOCATES_WITH_META: bool = false; + //const fn is_co_allocator() -> bool {false} Can't have: const type Xyz; + /// If this is any type with non-zero size, then the actual `Allocator` implementation supports + /// cooperative functions (`co_*`) as first class citizens. + //type IsCoAllocator = (); It applies to the global (default) allocator only. And/or System + // allocator?! @FIXME + /// NOT for public use. MAY CHANGE. + /// + /// Either 0 or 1. + const CO_ALLOC_META_NUM_SLOTS: usize = 0; /// NOT for public use. The default value MAY be REMOVED or CHANGED. - /// + /// /// @FIXME Validate (preferrable at compile time, otherwise as a test) that this type's /// alignment <= `usize` alignment. type CoAllocMeta: CoAllocMetaBase = CoAllocMetaPlain; @@ -591,7 +662,13 @@ where #[unstable(feature = "global_co_alloc_meta", issue = "none")] pub trait CoAllocMetaBase: Clone + Copy { /// NOT for public use. This MAY BE REMOVED or CHANGED. - /// + /// + /// For EXPERIMENTATION only. + const ZERO_METAS: [Self; 0]; + const ONE_METAS: [Self; 1]; + + /// NOT for public use. This MAY BE REMOVED or CHANGED. + /// /// For EXPERIMENTATION only. fn new_plain() -> Self; } @@ -600,11 +677,14 @@ pub trait CoAllocMetaBase: Clone + Copy { #[derive(Clone, Copy, Debug)] pub struct CoAllocMetaPlain {} -static CO_ALLOC_META_PLAIN: CoAllocMetaPlain = CoAllocMetaPlain {}; +const CO_ALLOC_META_PLAIN: CoAllocMetaPlain = CoAllocMetaPlain {}; #[unstable(feature = "global_co_alloc_meta", issue = "none")] impl CoAllocMetaBase for CoAllocMetaPlain { + const ZERO_METAS: [Self; 0] = []; + const ONE_METAS: [Self; 1] = [CO_ALLOC_META_PLAIN]; + fn new_plain() -> Self { CO_ALLOC_META_PLAIN } -} \ No newline at end of file +} From 4a996e64efb90f3701147978d269d35db18d06f3 Mon Sep 17 00:00:00 2001 From: Peter Kehl Date: Fri, 27 Jan 2023 06:39:04 -0800 Subject: [PATCH 088/118] CoAlloc: renamed macro DEFAULT_COOP_PREF -> CO_ALLOC_PREF_DEFAULT --- library/alloc/src/collections/binary_heap/mod.rs | 4 ++-- library/alloc/src/collections/vec_deque/mod.rs | 4 ++-- library/alloc/src/ffi/c_str.rs | 4 ++-- library/alloc/src/macros.rs | 2 +- library/alloc/src/raw_vec.rs | 6 +++--- library/alloc/src/vec/mod.rs | 16 ++++++++-------- library/alloc/src/vec/spec_from_iter_nested.rs | 4 ++-- 7 files changed, 20 insertions(+), 20 deletions(-) diff --git a/library/alloc/src/collections/binary_heap/mod.rs b/library/alloc/src/collections/binary_heap/mod.rs index 4c07cc01a1576..1808195e6fbd7 100644 --- a/library/alloc/src/collections/binary_heap/mod.rs +++ b/library/alloc/src/collections/binary_heap/mod.rs @@ -155,7 +155,7 @@ use crate::alloc::Global; use crate::collections::TryReserveError; use crate::slice; use crate::vec::{self, AsVecIntoIter, Vec}; -use crate::DEFAULT_COOP_PREF; +use crate::CO_ALLOC_PREF_DEFAULT; use super::SpecExtend; @@ -1664,7 +1664,7 @@ impl From<[T; N]> for BinaryHeap { #[stable(feature = "binary_heap_extras_15", since = "1.5.0")] #[allow(unused_braces)] -impl From> for Vec { +impl From> for Vec { /// Converts a `BinaryHeap` into a `Vec`. /// /// This conversion requires no data movement or allocation, and has diff --git a/library/alloc/src/collections/vec_deque/mod.rs b/library/alloc/src/collections/vec_deque/mod.rs index bb2c8ab0870a5..19b147b4a9b2f 100644 --- a/library/alloc/src/collections/vec_deque/mod.rs +++ b/library/alloc/src/collections/vec_deque/mod.rs @@ -7,7 +7,7 @@ #![feature(global_co_alloc)] #![stable(feature = "rust1", since = "1.0.0")] -use crate::DEFAULT_COOP_PREF; +use crate::CO_ALLOC_PREF_DEFAULT; use core::alloc; use core::cmp::{self, Ordering}; use core::fmt; @@ -97,7 +97,7 @@ mod tests; pub struct VecDeque< T, #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global, - const COOP_PREF: bool = { DEFAULT_COOP_PREF!() }, + const COOP_PREF: bool = { CO_ALLOC_PREF_DEFAULT!() }, > where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { diff --git a/library/alloc/src/ffi/c_str.rs b/library/alloc/src/ffi/c_str.rs index 97d19f03828d7..9d7321270d834 100644 --- a/library/alloc/src/ffi/c_str.rs +++ b/library/alloc/src/ffi/c_str.rs @@ -8,7 +8,7 @@ use crate::rc::Rc; use crate::slice::hack::into_vec; use crate::string::String; use crate::vec::Vec; -use crate::DEFAULT_COOP_PREF; +use crate::CO_ALLOC_PREF_DEFAULT; use core::borrow::Borrow; use core::ffi::{c_char, CStr}; use core::fmt; @@ -726,7 +726,7 @@ impl fmt::Debug for CString { #[stable(feature = "cstring_into", since = "1.7.0")] #[allow(unused_braces)] -impl From for Vec { +impl From for Vec { /// Converts a [`CString`] into a [Vec]<[u8]>. /// /// The conversion consumes the [`CString`], and removes the terminating NUL byte. diff --git a/library/alloc/src/macros.rs b/library/alloc/src/macros.rs index 9596af21b2e52..70a7987715cdd 100644 --- a/library/alloc/src/macros.rs +++ b/library/alloc/src/macros.rs @@ -134,7 +134,7 @@ macro_rules! __rust_force_expr { // fixed. Then move the const to a submodule, for example alloc::co_alloc. #[unstable(feature = "global_co_alloc_default", issue = "none")] #[macro_export] -macro_rules! DEFAULT_COOP_PREF { +macro_rules! CO_ALLOC_PREF_DEFAULT { () => { true }; diff --git a/library/alloc/src/raw_vec.rs b/library/alloc/src/raw_vec.rs index cee70f1c67d2d..340242677ebb8 100644 --- a/library/alloc/src/raw_vec.rs +++ b/library/alloc/src/raw_vec.rs @@ -16,7 +16,7 @@ use crate::alloc::{Allocator, Global, Layout}; use crate::boxed::Box; use crate::collections::TryReserveError; use crate::collections::TryReserveErrorKind::*; -use crate::DEFAULT_COOP_PREF; +use crate::CO_ALLOC_PREF_DEFAULT; #[cfg(test)] mod tests; @@ -52,8 +52,8 @@ enum AllocInit { /// `usize::MAX`. This means that you need to be careful when round-tripping this type with a /// `Box<[T]>`, since `capacity()` won't yield the length. #[allow(missing_debug_implementations)] -#[allow(unused_braces)] -pub(crate) struct RawVec +#[allow(unused_braces)] //@FIXME remove #[allow(unused_braces)] once that false positive warning fix is included on stable +pub(crate) struct RawVec where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { diff --git a/library/alloc/src/vec/mod.rs b/library/alloc/src/vec/mod.rs index 44c1707331133..967f4333482d8 100644 --- a/library/alloc/src/vec/mod.rs +++ b/library/alloc/src/vec/mod.rs @@ -403,7 +403,7 @@ pub struct Vec< T, #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global, //@FIXME: #[unstable(feature ="global_co_alloc_vec", issue="none")] - const COOP_PREF: bool = { DEFAULT_COOP_PREF!() }, + const COOP_PREF: bool = { CO_ALLOC_PREF_DEFAULT!() }, > where [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { @@ -425,7 +425,7 @@ pub type PlVec = Vec; /// author considered using `CoVec` or `PlVec`, but left it to default instead. #[unstable(feature = "global_co_alloc_defvec", issue = "none")] #[allow(unused_braces)] -pub type DefVec = Vec; +pub type DefVec = Vec; /// "Weighted cooperative" Vec. Weight means how much it wants to cooperate (with the allocator). 0 /// = always pack; u8::MAX = always cooperate (if `Global` supports it). @@ -454,7 +454,7 @@ impl Vec { #[must_use] pub const fn new() -> Self { #[allow(unused_braces)] - Vec::::new_co() + Vec::::new_co() //Self::new_co() } @@ -3317,7 +3317,7 @@ where #[cfg(not(no_global_oom_handling))] #[stable(feature = "rust1", since = "1.0.0")] #[allow(unused_braces)] -impl From<&[T]> for Vec { +impl From<&[T]> for Vec { /// Allocate a `Vec` and fill it by cloning `s`'s items. /// /// # Examples @@ -3338,7 +3338,7 @@ impl From<&[T]> for Vec { #[cfg(not(no_global_oom_handling))] #[stable(feature = "vec_from_mut", since = "1.19.0")] #[allow(unused_braces)] -impl From<&mut [T]> for Vec { +impl From<&mut [T]> for Vec { /// Allocate a `Vec` and fill it by cloning `s`'s items. /// /// # Examples @@ -3359,7 +3359,7 @@ impl From<&mut [T]> for Vec { #[cfg(not(no_global_oom_handling))] #[stable(feature = "vec_from_array", since = "1.44.0")] #[allow(unused_braces)] -impl From<[T; N]> for Vec { +impl From<[T; N]> for Vec { /// Allocate a `Vec` and move `s`'s items into it. /// /// # Examples @@ -3383,7 +3383,7 @@ impl From<[T; N]> for Vec From> for Vec +impl<'a, T> From> for Vec where [T]: ToOwned>, { @@ -3461,7 +3461,7 @@ where #[cfg(not(no_global_oom_handling))] #[stable(feature = "rust1", since = "1.0.0")] #[allow(unused_braces)] -impl From<&str> for Vec { +impl From<&str> for Vec { /// Allocate a `Vec` and fill it with a UTF-8 string. /// /// # Examples diff --git a/library/alloc/src/vec/spec_from_iter_nested.rs b/library/alloc/src/vec/spec_from_iter_nested.rs index 80d1f4a81d0c4..ea96e23025fd1 100644 --- a/library/alloc/src/vec/spec_from_iter_nested.rs +++ b/library/alloc/src/vec/spec_from_iter_nested.rs @@ -5,7 +5,7 @@ use core::ptr; use crate::alloc::Global; use crate::raw_vec::RawVec; -use crate::DEFAULT_COOP_PREF; +use crate::CO_ALLOC_PREF_DEFAULT; use super::{SpecExtend, Vec}; @@ -51,7 +51,7 @@ where } #[allow(unused_braces)] -impl SpecFromIterNested for Vec +impl SpecFromIterNested for Vec where I: TrustedLen, { From 9ca4c8eaf1cba836b799b0439bbaa277075c0676 Mon Sep 17 00:00:00 2001 From: Peter Kehl Date: Fri, 27 Jan 2023 06:39:20 -0800 Subject: [PATCH 089/118] CoAlloc: minor tidy --- library/alloc/src/macros.rs | 6 +++++- library/alloc/src/raw_vec.rs | 11 +++++++---- library/core/src/alloc/global.rs | 2 +- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/library/alloc/src/macros.rs b/library/alloc/src/macros.rs index 70a7987715cdd..b493f1c64b11d 100644 --- a/library/alloc/src/macros.rs +++ b/library/alloc/src/macros.rs @@ -207,6 +207,10 @@ macro_rules! meta_num_slots_global { #[macro_export] macro_rules! meta_num_slots_default_global { () => { - if ::alloc::alloc::Global::CO_ALLOC_META_NUM_SLOTS && (DEFAULT_COOP_PREF!()) { 1 } else { 0 } + if ::alloc::alloc::Global::CO_ALLOC_META_NUM_SLOTS && (DEFAULT_COOP_PREF!()) { + 1 + } else { + 0 + } }; } diff --git a/library/alloc/src/raw_vec.rs b/library/alloc/src/raw_vec.rs index 340242677ebb8..fb1defeaacf82 100644 --- a/library/alloc/src/raw_vec.rs +++ b/library/alloc/src/raw_vec.rs @@ -1,6 +1,7 @@ #![unstable(feature = "raw_vec_internals", reason = "unstable const warnings", issue = "none")] use crate::meta_num_slots_default; +use core::alloc::CoAllocMetaBase; use core::alloc::{self, LayoutError, PtrAndMeta}; use core::cmp; use core::intrinsics; @@ -8,7 +9,6 @@ use core::mem::{self, ManuallyDrop, MaybeUninit, SizedTypeProperties}; use core::ops::Drop; use core::ptr::{self, NonNull, Unique}; use core::slice; -use core::alloc::CoAllocMetaBase; #[cfg(not(no_global_oom_handling))] use crate::alloc::handle_alloc_error; @@ -53,8 +53,11 @@ enum AllocInit { /// `Box<[T]>`, since `capacity()` won't yield the length. #[allow(missing_debug_implementations)] #[allow(unused_braces)] //@FIXME remove #[allow(unused_braces)] once that false positive warning fix is included on stable -pub(crate) struct RawVec -where +pub(crate) struct RawVec< + T, + A: Allocator = Global, + const COOP_PREF: bool = { CO_ALLOC_PREF_DEFAULT!() }, +> where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { ptr: Unique, @@ -121,7 +124,7 @@ impl RawVec where [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, { - const fn new_plain_metas() -> [A::CoAllocMeta; {meta_num_slots_default!(A)}] { + const fn new_plain_metas() -> [A::CoAllocMeta; { meta_num_slots_default!(A) }] { loop {} } diff --git a/library/core/src/alloc/global.rs b/library/core/src/alloc/global.rs index ffb350a3294e9..081858e2fb512 100644 --- a/library/core/src/alloc/global.rs +++ b/library/core/src/alloc/global.rs @@ -131,7 +131,7 @@ pub struct RawAndMeta { #[stable(feature = "global_alloc", since = "1.28.0")] pub unsafe trait GlobalAlloc { /// NOT for public use. The default value MAY be REMOVED or CHANGED. - /// + /// /// @FIXME Validate (preferrable at compile time, otherwise as a test) that this type's /// alignment <= `usize` alignment. #[unstable(feature = "global_co_alloc_meta", issue = "none")] From 7392c80af7cd2094f8f1ea0f342a51ac8a2511a9 Mon Sep 17 00:00:00 2001 From: Peter Kehl Date: Fri, 27 Jan 2023 16:53:46 -0800 Subject: [PATCH 090/118] CoAlloc: Preference/config types in ::alloc::co_alloc. Config value macros + transformation macros in ::alloc. WIP (won't compile). --- library/alloc/src/co_alloc.rs | 47 ++++++++++ library/alloc/src/lib.rs | 2 + library/alloc/src/macros.rs | 142 +++++++++++++++++++++------- library/core/src/alloc/mod.rs | 168 ++++++++++++---------------------- 4 files changed, 216 insertions(+), 143 deletions(-) create mode 100644 library/alloc/src/co_alloc.rs diff --git a/library/alloc/src/co_alloc.rs b/library/alloc/src/co_alloc.rs new file mode 100644 index 0000000000000..7a854d1bbb23a --- /dev/null +++ b/library/alloc/src/co_alloc.rs @@ -0,0 +1,47 @@ +//! CoAlloction-specific types that only apply in heap-based applications (hence not a part of +//! [::core]). +//! +//! Types here have names with `CoAlloc` prefix. Yes, when using a q ualified path (like +//! ::alloc::co_alloc::CoAllocPref), that involves "stuttering", which is not recommended. +//! +//! However, as per Rust Book the common practice is to import type names fully and access them just +//! with their name (except for cases of conflict). And we don't want the type names any shorter +//! (such `Pref`), because thoe would be vague/confusing. + +/// `CoAllocPref` values indicate a type's preference for coallocation (in either user space, or +/// `std` space). Used as a `const` generic parameter type (usually called `CO_ALLOC_PREF`). +/// +/// The actual value may be overriden by the allocator. See also `CoAllocMetaNumSlotsPref` and +/// `co_alloc_pref` macro . +/// +/// This type WILL CHANGE (once ``#![feature(generic_const_exprs)]` and +/// `#![feature(adt_const_params)]` are stable) to a dedicated struct/enum. Hence: +/// - DO NOT construct instances, but use `co_alloc_pref` macro together with constants +/// `CO_ALLOC_PREF_META_YES` and `CO_ALLOC_PREF_META_NO`; +/// - DO NOT hard code any values; and +/// - DO NOT mix this/cast this with/to `u8`, `u16`, `usize` (nor any other integer). +#[unstable(feature = "global_co_alloc_meta", issue = "none")] +pub type CoAllocPref = u8; + +/// `CoAllocMetaNumSlotsPref` values indicate a type (but not an allocator) prefers to coallocate by +/// carrying metadata, or not. (In either user space, or `std` space). Used as an argument to macro +/// call of `co_alloc_pref`, which generates a `CoAllocPref` value. +/// +/// Currently this indicates only the (preferred) number of `CoAllocMetaBase` slots being used +/// (either 1 = coallocation, or 0 = no coallocation). However, in the future this type may have +/// other properties (serving as extra hints to the allocator). +/// +/// The actual value may be overriden by the allocator. For example, if the allocator doesn't +/// support coallocation, then whether this value prefers to coallocate or not makes no difference. +/// +/// This type WILL CHANGE (once ``#![feature(generic_const_exprs)]` and +/// `#![feature(adt_const_params)]` are stable) to a dedicated struct/enum. Hence: +/// - DO NOT mix this/cast this with/to `u8`, `u16`, (nor any other integer); and +/// - DO NOT hard code any values, but use `CO_ALLOC_PREF_META_YES` and `CO_ALLOC_PREF_META_NO`. +/// +/// This type is intentionally not `u16`, `u32`, nor `usize`. Why? This helps to prevent mistakes +/// when one would use `CO_ALLOC_PREF_META_YES` or `CO_ALLOC_PREF_META_NO` in place of `CoAllocPref` +/// vales, or in place of a result of `meta_num_slots` macro. That also prevents mixing up with +/// [core::alloc::CoAllocatorMetaNumSlots]. +#[unstable(feature = "global_co_alloc_meta", issue = "none")] +pub type CoAllocMetaNumSlotsPref = u16; \ No newline at end of file diff --git a/library/alloc/src/lib.rs b/library/alloc/src/lib.rs index 348de3322186d..921850754cb3e 100644 --- a/library/alloc/src/lib.rs +++ b/library/alloc/src/lib.rs @@ -249,6 +249,8 @@ mod boxed { pub use std::boxed::Box; } pub mod borrow; +#[unstable(feature = "global_co_alloc", issue = "none")] +pub mod co_alloc; pub mod collections; #[cfg(all(not(no_rc), not(no_sync), not(no_global_oom_handling)))] pub mod ffi; diff --git a/library/alloc/src/macros.rs b/library/alloc/src/macros.rs index b493f1c64b11d..f719158e24ed7 100644 --- a/library/alloc/src/macros.rs +++ b/library/alloc/src/macros.rs @@ -125,37 +125,113 @@ macro_rules! __rust_force_expr { }; } -/// Default coallocation "cooperation" (`COOP_PREF`) generic parameter. +// ----- CoAlloc constant-like macros: +/// "Yes" as a type's preference for coallocation (in either user space, or `std` space). /// -/// NOT for public use. It's exported only so that library/proc_macro (and other internals) can use -/// this. +/// It may be overriden by the allocator. For example, if the allocator doesn't support +/// coallocation, then this value makes no difference. /// -// FIXME replace with a `const` (or some kind of compile time preference) once a related ICE is -// fixed. Then move the const to a submodule, for example alloc::co_alloc. +/// This constant and its type WILL CHANGE (once ``#![feature(generic_const_exprs)]` and +/// `#![feature(adt_const_params)]` are stable) to a dedicated struct/enum. Hence DO NOT hard +/// code/replace/mix this any other values/parameters. +#[unstable(feature = "global_co_alloc_meta", issue = "none")] +#[macro_export] +macro_rules! CO_ALLOC_PREF_META_YES { + () => { + (1 as $crate::co_alloc::CoAllocMetaNumSlotsPref) + }; +} + +/// "No" as a type's preference for coallocation (in either user space, or `std` space). +/// +/// Any allocator is required to respect this. Even if the allocator does support coallocation, it +/// will not coallocate types that use this value. +/// +/// This constant and its type WILL CHANGE (once ``#![feature(generic_const_exprs)]` and +/// `#![feature(adt_const_params)]` are stable) to a dedicated struct/enum. Hence DO NOT hard +/// code/replace/mix this any other values/parameters. +#[unstable(feature = "global_co_alloc_meta", issue = "none")] +#[macro_export] +macro_rules! CO_ALLOC_PREF_META_NO { + () => { + (0 as $crate::co_alloc::CoAllocMetaNumSlotsPref) + }; +} + +/// Default preference for coallocation (in either user space, or `std` space). +/// +/// Possible values are only: `CO_ALLOC_PREF_META_YES` and `CO_ALLOC_PREF_META_NO`. See their +/// documentation. +/// +/// This value and its type WILL CHANGE (once ``#![feature(generic_const_exprs)]` and +/// `#![feature(adt_const_params)]` are stable) to a dedicated struct/enum. Hence DO NOT hard +/// code/replace/mix this any other values/parameters. +/// +/// (@FIXME) This WILL BE BECOME OBSOLETE and it WILL BE REPLACED with a `const` (and/or some kind +/// of compile time preference) once a related ICE is fixed (@FIXME add the ICE link here). Then +/// consider moving such a `const` to a submodule, for example `::alloc::co_alloc`. #[unstable(feature = "global_co_alloc_default", issue = "none")] #[macro_export] -macro_rules! CO_ALLOC_PREF_DEFAULT { +macro_rules! CO_ALLOC_PREF_META_DEFAULT { () => { - true + (0 as $crate::co_alloc::CoAllocMetaNumSlotsPref) + }; +} + +/// Default [::alloc::CoAllocPref] value/config, based on `CO_ALLOC_PREF_META_DEFAULT`. +#[unstable(feature = "global_co_alloc_meta", issue = "none")] +#[macro_export] +macro_rules! CO_ALLOC_PREF_DEFAULT { + () => { $crate::co_alloc_pref!($crate::CO_ALLOC_PREF_META_DEFAULT!()) }; +} + +// ------ CoAlloc preference/config conversion macros: +/// Create a `CoAllocPref` value based on the given parameter(s). For now, only one parameter is +/// supported, and it's required: `meta_pref`. +/// +/// @param `meta_pref` is one of: `CO_ALLOC_PREF_META_YES, CO_ALLOC_PREF_META_NO, +/// CO_ALLOC_PREF_META_DEFAULT`. +/// +/// @return `CoAllocPref` value +#[unstable(feature = "global_co_alloc_meta", issue = "none")] +#[macro_export] +macro_rules! co_alloc_pref { + // ($meta_pref + (0 as CoAllocMetaNumSlotsPref)) ensures that $meta_pref is of type + // `CoAllocMetaNumSlotsPref`. Otherwise the casting of the result to `CoAllocPref` would not + // report the incorrect type of $meta_pref (if $meta_pref were some other integer, casting would + // compile, and we would not be notified). + ($meta_pref:expr) => { + (($meta_pref + (0 as $crate::co_alloc::CoAllocMetaNumSlotsPref)) as $crate::co_alloc::CoAllocPref) }; } -// -\---> replace with something like: pub const DEFAULT_COOP_PREF: bool = true; /// Return 0 or 1, indicating whether to use coallocation metadata (or not) with the given allocator -/// type `alloc` and cooperation preference `coop_pref`. +/// type `alloc` and cooperation preference `co_alloc_pref`. /// -/// NOT for public use. Param `coop_pref` - can override the allocator's default preference for +/// NOT for public use. Param `co_alloc_pref` - can override the allocator's default preference for /// cooperation, or can make the type not cooperative, regardless of whether allocator `A` is /// cooperative. +/// +/// @param `alloc` Allocator (implementation) type. @param `co_alloc_pref` The heap-based type's +/// preference for coallocation, as an [::alloc::CoAllocPref] value. +/// +/// The type of second parameter `co_alloc_pref` WILL CHANGE. DO NOT hardcode/cast/mix that type. +/// Instead, use [::alloc::CoAllocPref]. +/// // FIXME replace the macro with an (updated version of the below) `const` function). Only once // generic_const_exprs is stable (that is, when consumer crates don't need to declare -// generic_const_exprs feature anymore). Then move the function to a submodule, for example -// ::alloc::co_alloc. +// generic_const_exprs feature anymore). Then consider moving the function to a submodule, for +// example ::alloc::co_alloc. #[unstable(feature = "global_co_alloc", issue = "none")] #[macro_export] macro_rules! meta_num_slots { - ($alloc:ty, $coop_pref:expr) => { - if ($alloc::CO_ALLOC_META_NUM_SLOTS) && ($coop_pref) { 1 } else { 0 } + // This "validates" types of both params - to prevent mix ups. + ($alloc:ty, $co_alloc_pref:expr) => { + ( + ((<$alloc>::CO_ALLOC_META_NUM_SLOTS + (0 as ::core::alloc::CoAllocatorMetaNumSlots)) + as $crate::co_alloc::CoAllocPref) + * ($co_alloc_pref + (0 as $crate::co_alloc::CoAllocPref)) + as usize) }; } // -\---> replace with something like: @@ -171,46 +247,46 @@ pub const fn meta_num_slots( /// Like `meta_num_slots`, but for the default coallocation preference (`DEFAULT_COOP_PREF`). /// /// Return 0 or 1, indicating whether to use coallocation metadata (or not) with the given allocator -/// type `alloc` and the default cooperation preference (`DEFAULT_COOP_PREF()!`). +/// type `alloc` and the default coallocation preference (`DEFAULT_COOP_PREF()!`). /// -/// NOT for public use. // FIXME replace the macro with a `const` function. Only once generic_const_exprs is stable (that -// is, when consumer crates don't need to declare generic_const_exprs feature anymore). Then move -// the function to a submodule, for example ::alloc::co_alloc. +// is, when consumer crates don't need to declare generic_const_exprs feature anymore). Then +// consider moving the function to a submodule, for example ::alloc::co_alloc. #[unstable(feature = "global_co_alloc", issue = "none")] #[macro_export] macro_rules! meta_num_slots_default { // Can't generate if ... {1} else {0} // because it's "overly complex generic constant". ($alloc:ty) => { - if (<$alloc>::CO_ALLOC_META_NUM_SLOTS) && (DEFAULT_COOP_PREF!()) { 1 } else { 0 } + $crate::meta_num_slots!( $alloc, $crate::CO_ALLOC_PREF_DEFAULT!() ) }; } -/// NOT for public use. -// See above. +/// Like `meta_num_slots`, but for the default coallocation preference (`DEFAULT_COOP_PREF`). +/// +/// Return 0 or 1, indicating whether to use coallocation metadata (or not) with the global allocator +/// type `alloc` and the given coallocation preference `co_alloc_`. +/// +// FIXME replace the macro with a `const` function. Only once generic_const_exprs is stable (that +// is, when consumer crates don't need to declare `generic_const_exprs` feature anymore). Then +// consider moving the function to a submodule, for example ::alloc::co_alloc. See above. #[unstable(feature = "global_co_alloc", issue = "none")] #[macro_export] macro_rules! meta_num_slots_global { - ($coop_pref:expr) => { - if ::alloc::alloc::Global::CO_ALLOC_META_NUM_SLOTS && ($coop_pref) { 1 } else { 0 } + ($co_alloc_pref:expr) => { + $crate::meta_num_slots!( $crate::alloc::Global, $co_alloc_pref) }; } -/// Like `meta_num_slots`, but for Global allocator and default coallocation preference -/// (`DEFAULT_COOP_PREF`). +/// Like `meta_num_slots`, but for `Global allocator and default coallocation preference +/// (`CO_ALLOC_PREF_DEFAULT`). /// -/// NOT for public use. -// @FIXME once generic_const_exprs is stable, replace this with a `const` function. Then move the -// function to a submodule, for example alloc::co_alloc. See above. +// @FIXME once generic_const_exprs is stable, replace this with a `const` function. Then consider +// moving the function to a submodule, for example alloc::co_alloc. See above. #[unstable(feature = "global_co_alloc", issue = "none")] #[macro_export] macro_rules! meta_num_slots_default_global { () => { - if ::alloc::alloc::Global::CO_ALLOC_META_NUM_SLOTS && (DEFAULT_COOP_PREF!()) { - 1 - } else { - 0 - } + $crate::meta_num_slots!( $crate::alloc::Global, $crate::CO_ALLOC_PREF_DEFAULT!()) }; } diff --git a/library/core/src/alloc/mod.rs b/library/core/src/alloc/mod.rs index 911cc5e042024..fab6c29583496 100644 --- a/library/core/src/alloc/mod.rs +++ b/library/core/src/alloc/mod.rs @@ -48,75 +48,6 @@ impl fmt::Display for AllocError { } } -/// `CoAllocPref` values indicate a type's preference for coallocation (in either user space, or -/// `std` space). Used as a `const` generic parameter type (usually called `CO_ALLOC_PREF`). -/// -/// The actual value may be overriden by the allocator. See also `CoAllocMetaNumSlotsPref` and -/// `co_alloc_pref` macro . -/// -/// This type WILL CHANGE (once ``#![feature(generic_const_exprs)]` and -/// `#![feature(adt_const_params)]` are stable) to a dedicated struct/enum. Hence: -/// - DO NOT construct instances, but use `co_alloc_pref` macro together with constants -/// `CO_ALLOC_PREF_YES` and `CO_ALLOC_PREF_NO`; -/// - DO NOT hard code any values; and -/// - DO NOT mix this/cast this with/to `usize` (nor any other integers). -/// -/// @FIXME CO_ALLOC_PREF_DEFAULT - as a separate constant, or a "keyword" recognized by -/// `co_alloc_pref` macro? -#[unstable(feature = "global_co_alloc_meta", issue = "none")] -pub type CoAllocPref = usize; - -/// `CoAllocMetaNumSlotsPref` values indicate a type prefers to coallocate by carrying metadata, or -/// not. (In either user space, or `std` space). Used as an argument to macro call of -/// `co_alloc_pref`, which generates a `CoAllocPref` value. -/// -/// Currently this indicates only the (preferred) number of `CoAllocMetaBase` slots being used -/// (either 1 = coallocation, or 0 = no coallocation). However, in the future this type may have -/// other properties (serving as extra hints to the allocator). -/// -/// The actual value may be overriden by the allocator. For example, if the allocator doesn't -/// support coallocation, then whether this value prefers to coallocate or not makes no difference. -/// -/// This type WILL CHANGE (once ``#![feature(generic_const_exprs)]` and -/// `#![feature(adt_const_params)]` are stable) to a dedicated struct/enum. Hence: -/// - DO NOT mix this/cast this with/to `isize` (nor any other integers); and -/// - DO NOT hard code any values, but use `CO_ALLOC_PREF_YES` and `CO_ALLOC_PREF_NO`. -/// -/// Currently this type is intentionally not `usize`. Why? This helps to prevent mistakes when one -/// would use `CO_ALLOC_PREF_YES` or `CO_ALLOC_PREF_NO` in place of `CoAllocPref` vales. -#[unstable(feature = "global_co_alloc_meta", issue = "none")] -pub type CoAllocMetaNumSlotsPref = isize; - -/// "Yes" as a type's preference for coallocation (in either user space, or `std` space). -/// -/// It may be overriden by the allocator. For example, if the allocator doesn't support -/// coallocation, then this value makes no difference. -/// -/// This constant and its type WILL CHANGE (once ``#![feature(generic_const_exprs)]` and -/// `#![feature(adt_const_params)]` are stable) to a dedicated struct/enum. Hence DO NOT hard -/// code/replace/mix this any other values/parameters. -#[unstable(feature = "global_co_alloc_meta", issue = "none")] -pub const CO_ALLOC_PREF_YES: CoAllocMetaNumSlotsPref = 1; - -/// "No" as a type's preference for coallocation (in either user space, or `std` space). -/// -/// Any allocator is required to respect this. Even if the allocator does support coallocation, it -/// will not coallocate types that use this value. -/// -/// This constant and its type WILL CHANGE (once ``#![feature(generic_const_exprs)]` and -/// `#![feature(adt_const_params)]` are stable) to a dedicated struct/enum. Hence DO NOT hard -/// code/replace/mix this any other values/parameters. -#[unstable(feature = "global_co_alloc_meta", issue = "none")] -pub const CO_ALLOC_PREF_NO: CoAllocMetaNumSlotsPref = 0; - -#[unstable(feature = "global_co_alloc_meta", issue = "none")] -#[macro_export] -macro_rules! co_alloc_pref { - ($coop_pref:expr) => { - if ::alloc::alloc::Global::CO_ALLOC_META_NUM_SLOTS && ($coop_pref) { 1 } else { 0 } - }; -} - /// (Non-Null) Pointer and coallocation metadata. #[unstable(feature = "global_co_alloc_meta", issue = "none")] #[derive(Clone, Copy, Debug)] @@ -134,6 +65,7 @@ pub struct SliceAndMeta { pub meta: M, } +// @FIXME Move to library/alloc - if possible: #[unstable(feature = "global_co_alloc_short_term_pref", issue = "none")] //pub const SHORT_TERM_VEC_PREFERS_COOP: bool = true; #[macro_export] @@ -154,9 +86,57 @@ pub type SliceAndMetaResult = Result, AllocError>; pub const fn co_alloc_metadata_num_slots_with_preference( coop_preferred: bool, ) -> usize { - if coop_preferred { A::CO_ALLOC_META_NUM_SLOTS } else { 0 } + if coop_preferred { A::CO_ALLOC_META_NUM_SLOTS as usize } else { 0 } +} + +#[unstable(feature = "global_co_alloc_meta", issue = "none")] +pub trait CoAllocMetaBase: Clone + Copy { + /// NOT for public use. This MAY BE REMOVED or CHANGED. + /// + /// For EXPERIMENTATION only. + const ZERO_METAS: [Self; 0]; + const ONE_METAS: [Self; 1]; + + /// NOT for public use. This MAY BE REMOVED or CHANGED. + /// + /// For EXPERIMENTATION only. + fn new_plain() -> Self; } +#[unstable(feature = "global_co_alloc_meta", issue = "none")] +#[derive(Clone, Copy, Debug)] +pub struct CoAllocMetaPlain {} + +const CO_ALLOC_META_PLAIN: CoAllocMetaPlain = CoAllocMetaPlain {}; + +#[unstable(feature = "global_co_alloc_meta", issue = "none")] +impl CoAllocMetaBase for CoAllocMetaPlain { + const ZERO_METAS: [Self; 0] = []; + const ONE_METAS: [Self; 1] = [CO_ALLOC_META_PLAIN]; + + fn new_plain() -> Self { + CO_ALLOC_META_PLAIN + } +} + +/// Whether an `Allocator` implementation supports coallocation. +/// +/// This type WILL CHANGE (once ``#![feature(generic_const_exprs)]` and +/// `#![feature(adt_const_params)]` are stable) to a dedicated struct/enum. Hence: +/// - DO NOT mix this/cast this with/to `u8`, `u16`, (nor any other integer); and +/// - DO NOT hard code any values, but use `CO_ALLOCATOR_SUPPORTS_META_YES` and `CO_ALLOCATOR_SUPPORTS_META_NO`. +/// +#[unstable(feature = "global_co_alloc_meta", issue = "none")] +pub type CoAllocatorMetaNumSlots = u32; + +/// Indicating that an Allocator supports coallocation (if a type of the allocated instances supports it, too). +#[unstable(feature = "global_co_alloc_meta", issue = "none")] +pub const CO_ALLOCATOR_SUPPORTS_META_YES: CoAllocatorMetaNumSlots = 1; + +/// Indicating that an Allocator does not support coallocation. +#[unstable(feature = "global_co_alloc_meta", issue = "none")] +pub const CO_ALLOCATOR_SUPPORTS_META_NO: CoAllocatorMetaNumSlots = 0; + /// An implementation of `Allocator` can allocate, grow, shrink, and deallocate arbitrary blocks of /// data described via [`Layout`][]. /// @@ -216,17 +196,15 @@ pub const fn co_alloc_metadata_num_slots_with_preference( #[unstable(feature = "allocator_api", issue = "32838")] #[const_trait] pub unsafe trait Allocator { - //const fn is_co_allocator() -> bool {false} Can't have: const type Xyz; - /// If this is any type with non-zero size, then the actual `Allocator` implementation supports - /// cooperative functions (`co_*`) as first class citizens. - //type IsCoAllocator = (); It applies to the global (default) allocator only. And/or System - // allocator?! @FIXME /// NOT for public use. MAY CHANGE. - /// - /// Either 0 or 1. - const CO_ALLOC_META_NUM_SLOTS: usize = 0; + const CO_ALLOC_META_NUM_SLOTS: CoAllocatorMetaNumSlots = CO_ALLOCATOR_SUPPORTS_META_NO; - /// NOT for public use. The default value MAY be REMOVED or CHANGED. + /// Type to store coallocation metadata (if both the allocator and the heap-based type support + /// coallocation, and if coallocation is used). + /// + /// If this is any type with non-zero size, then the actual `Allocator` implementation supports + /// cooperative functions (`co_*`) as first class citizens. NOT for public use. The default + /// value MAY be REMOVED or CHANGED. /// /// @FIXME Validate (preferrable at compile time, otherwise as a test) that this type's /// alignment <= `usize` alignment. @@ -657,34 +635,4 @@ where // SAFETY: the safety contract must be upheld by the caller unsafe { (**self).shrink(ptr, old_layout, new_layout) } } -} - -#[unstable(feature = "global_co_alloc_meta", issue = "none")] -pub trait CoAllocMetaBase: Clone + Copy { - /// NOT for public use. This MAY BE REMOVED or CHANGED. - /// - /// For EXPERIMENTATION only. - const ZERO_METAS: [Self; 0]; - const ONE_METAS: [Self; 1]; - - /// NOT for public use. This MAY BE REMOVED or CHANGED. - /// - /// For EXPERIMENTATION only. - fn new_plain() -> Self; -} - -#[unstable(feature = "global_co_alloc_meta", issue = "none")] -#[derive(Clone, Copy, Debug)] -pub struct CoAllocMetaPlain {} - -const CO_ALLOC_META_PLAIN: CoAllocMetaPlain = CoAllocMetaPlain {}; - -#[unstable(feature = "global_co_alloc_meta", issue = "none")] -impl CoAllocMetaBase for CoAllocMetaPlain { - const ZERO_METAS: [Self; 0] = []; - const ONE_METAS: [Self; 1] = [CO_ALLOC_META_PLAIN]; - - fn new_plain() -> Self { - CO_ALLOC_META_PLAIN - } -} +} \ No newline at end of file From 268e6e3310b5f79de0ea94c087a10fdf1123a0a5 Mon Sep 17 00:00:00 2001 From: Peter Kehl Date: Sat, 28 Jan 2023 20:27:23 -0800 Subject: [PATCH 091/118] CoAlloc: Renaming to use new value/config + transformation macros. --- library/alloc/src/boxed.rs | 13 +- .../alloc/src/collections/binary_heap/mod.rs | 23 +- .../alloc/src/collections/vec_deque/drain.rs | 55 +++-- .../src/collections/vec_deque/into_iter.rs | 40 +-- .../alloc/src/collections/vec_deque/macros.rs | 4 +- .../alloc/src/collections/vec_deque/mod.rs | 175 ++++++------- .../src/collections/vec_deque/spec_extend.rs | 33 +-- .../collections/vec_deque/spec_from_iter.rs | 23 +- library/alloc/src/macros.rs | 65 +++-- library/alloc/src/raw_vec.rs | 37 +-- library/alloc/src/rc.rs | 8 +- library/alloc/src/slice.rs | 61 ++--- library/alloc/src/str.rs | 6 +- library/alloc/src/vec/drain.rs | 61 ++--- library/alloc/src/vec/drain_filter.rs | 31 +-- library/alloc/src/vec/in_place_collect.rs | 4 +- library/alloc/src/vec/into_iter.rs | 97 ++++---- library/alloc/src/vec/mod.rs | 233 +++++++++--------- library/alloc/src/vec/partial_eq.rs | 21 +- library/alloc/src/vec/spec_extend.rs | 25 +- library/alloc/src/vec/spec_from_elem.rs | 31 +-- library/alloc/src/vec/spec_from_iter.rs | 11 +- .../alloc/src/vec/spec_from_iter_nested.rs | 6 +- library/alloc/src/vec/splice.rs | 31 +-- library/core/src/alloc/mod.rs | 10 - library/proc_macro/src/bridge/mod.rs | 4 +- library/proc_macro/src/bridge/rpc.rs | 6 +- library/proc_macro/src/diagnostic.rs | 2 +- library/std/src/io/cursor.rs | 32 +-- library/std/src/io/impls.rs | 12 +- 30 files changed, 595 insertions(+), 565 deletions(-) diff --git a/library/alloc/src/boxed.rs b/library/alloc/src/boxed.rs index 1027898f8b8a5..1128b21b24735 100644 --- a/library/alloc/src/boxed.rs +++ b/library/alloc/src/boxed.rs @@ -167,6 +167,7 @@ use core::ops::{ use core::pin::Pin; use core::ptr::{self, Unique}; use core::task::{Context, Poll}; +use crate::co_alloc::CoAllocPref; #[cfg(not(no_global_oom_handling))] use crate::alloc::{handle_alloc_error, WriteCloneIntoRaw}; @@ -749,7 +750,7 @@ impl Box<[T]> { impl Box<[T], A> where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(false)]:, + [(); {crate::meta_num_slots!(A, crate::CO_ALLOC_PREF_META_NO!())}]:, { /// Constructs a new boxed slice with uninitialized contents in the provided allocator. /// @@ -1679,11 +1680,11 @@ impl TryFrom> for Box<[T; N]> { #[cfg(not(no_global_oom_handling))] #[stable(feature = "boxed_array_try_from_vec", since = "1.66.0")] -impl TryFrom> for Box<[T; N]> +impl TryFrom> for Box<[T; N]> where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); {meta_num_slots_global!(CO_ALLOC_PREF)}]:, { - type Error = Vec; + type Error = Vec; /// Attempts to convert a `Vec` into a `Box<[T; N]>`. /// @@ -1703,7 +1704,7 @@ where /// let state: Box<[f32; 100]> = vec![1.0; 100].try_into().unwrap(); /// assert_eq!(state.len(), 100); /// ``` - fn try_from(vec: Vec) -> Result { + fn try_from(vec: Vec) -> Result { if vec.len() == N { let boxed_slice = vec.into_boxed_slice(); Ok(unsafe { boxed_slice_as_array_unchecked(boxed_slice) }) @@ -2042,7 +2043,7 @@ impl FromIterator for Box<[I]> { #[stable(feature = "box_slice_clone", since = "1.3.0")] impl Clone for Box<[T], A> where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(false)]:, + [(); {crate::meta_num_slots!(A, crate::CO_ALLOC_PREF_META_NO!())}]:, { fn clone(&self) -> Self { let alloc = Box::allocator(self).clone(); diff --git a/library/alloc/src/collections/binary_heap/mod.rs b/library/alloc/src/collections/binary_heap/mod.rs index 1808195e6fbd7..183d9df60cc5f 100644 --- a/library/alloc/src/collections/binary_heap/mod.rs +++ b/library/alloc/src/collections/binary_heap/mod.rs @@ -145,6 +145,7 @@ use core::fmt; use core::iter::{FromIterator, FusedIterator, InPlaceIterable, SourceIter, TrustedLen}; +use crate::co_alloc::CoAllocPref; use core::mem::{self, swap, ManuallyDrop}; use core::num::NonZeroUsize; use core::ops::{Deref, DerefMut}; @@ -1525,17 +1526,17 @@ unsafe impl TrustedLen for IntoIterSorted {} /// [`drain`]: BinaryHeap::drain #[stable(feature = "drain", since = "1.6.0")] #[derive(Debug)] -pub struct Drain<'a, T: 'a, const COOP_PREF: bool> +pub struct Drain<'a, T: 'a, const CO_ALLOC_PREF: CoAllocPref> where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); {meta_num_slots_global!(CO_ALLOC_PREF)}]:, { - iter: vec::Drain<'a, T, Global, COOP_PREF>, + iter: vec::Drain<'a, T, Global, CO_ALLOC_PREF>, } #[stable(feature = "drain", since = "1.6.0")] -impl Iterator for Drain<'_, T, COOP_PREF> +impl Iterator for Drain<'_, T, CO_ALLOC_PREF> where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); {meta_num_slots_global!(CO_ALLOC_PREF)}]:, { type Item = T; @@ -1551,9 +1552,9 @@ where } #[stable(feature = "drain", since = "1.6.0")] -impl DoubleEndedIterator for Drain<'_, T, COOP_PREF> +impl DoubleEndedIterator for Drain<'_, T, CO_ALLOC_PREF> where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); {meta_num_slots_global!(CO_ALLOC_PREF)}]:, { #[inline] fn next_back(&mut self) -> Option { @@ -1562,9 +1563,9 @@ where } #[stable(feature = "drain", since = "1.6.0")] -impl ExactSizeIterator for Drain<'_, T, COOP_PREF> +impl ExactSizeIterator for Drain<'_, T, CO_ALLOC_PREF> where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); {meta_num_slots_global!(CO_ALLOC_PREF)}]:, { fn is_empty(&self) -> bool { self.iter.is_empty() @@ -1572,8 +1573,8 @@ where } #[stable(feature = "fused", since = "1.26.0")] -impl FusedIterator for Drain<'_, T, COOP_PREF> where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]: +impl FusedIterator for Drain<'_, T, CO_ALLOC_PREF> where + [(); {meta_num_slots_global!(CO_ALLOC_PREF)}]: { } diff --git a/library/alloc/src/collections/vec_deque/drain.rs b/library/alloc/src/collections/vec_deque/drain.rs index 699c2ea631467..356668dff8ffc 100644 --- a/library/alloc/src/collections/vec_deque/drain.rs +++ b/library/alloc/src/collections/vec_deque/drain.rs @@ -1,4 +1,5 @@ use core::iter::FusedIterator; +use crate::co_alloc::CoAllocPref; use core::marker::PhantomData; use core::mem::{self, SizedTypeProperties}; use core::ptr::NonNull; @@ -20,13 +21,13 @@ pub struct Drain< 'a, T: 'a, #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global, - const COOP_PREF: bool = { SHORT_TERM_VEC_PREFERS_COOP!() }, + const CO_ALLOC_PREF: CoAllocPref = { SHORT_TERM_VEC_PREFERS_COOP!() }, > where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, { // We can't just use a &mut VecDeque, as that would make Drain invariant over T // and we want it to be covariant instead - deque: NonNull>, + deque: NonNull>, // drain_start is stored in deque.len drain_len: usize, // index into the logical array, not the physical one (always lies in [0..deque.len)) @@ -38,12 +39,12 @@ pub struct Drain< _marker: PhantomData<&'a T>, } -impl<'a, T, A: Allocator, const COOP_PREF: bool> Drain<'a, T, A, COOP_PREF> +impl<'a, T, A: Allocator, const CO_ALLOC_PREF: CoAllocPref> Drain<'a, T, A, CO_ALLOC_PREF> where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, { pub(super) unsafe fn new( - deque: &'a mut VecDeque, + deque: &'a mut VecDeque, drain_start: usize, drain_len: usize, ) -> Self { @@ -95,9 +96,9 @@ where } #[stable(feature = "collection_debug", since = "1.17.0")] -impl fmt::Debug for Drain<'_, T, A, COOP_PREF> +impl fmt::Debug for Drain<'_, T, A, CO_ALLOC_PREF> where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_tuple("Drain") @@ -110,31 +111,31 @@ where } #[stable(feature = "drain", since = "1.6.0")] -unsafe impl Sync for Drain<'_, T, A, COOP_PREF> where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]: +unsafe impl Sync for Drain<'_, T, A, CO_ALLOC_PREF> where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]: { } #[stable(feature = "drain", since = "1.6.0")] -unsafe impl Send for Drain<'_, T, A, COOP_PREF> where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]: +unsafe impl Send for Drain<'_, T, A, CO_ALLOC_PREF> where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]: { } #[stable(feature = "drain", since = "1.6.0")] -impl Drop for Drain<'_, T, A, COOP_PREF> +impl Drop for Drain<'_, T, A, CO_ALLOC_PREF> where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, { fn drop(&mut self) { - struct DropGuard<'r, 'a, T, A: Allocator, const COOP_PREF: bool>( - &'r mut Drain<'a, T, A, COOP_PREF>, + struct DropGuard<'r, 'a, T, A: Allocator, const CO_ALLOC_PREF: CoAllocPref>( + &'r mut Drain<'a, T, A, CO_ALLOC_PREF>, ) where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:; + [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:; - impl<'r, 'a, T, A: Allocator, const COOP_PREF: bool> Drop for DropGuard<'r, 'a, T, A, COOP_PREF> + impl<'r, 'a, T, A: Allocator, const CO_ALLOC_PREF: CoAllocPref> Drop for DropGuard<'r, 'a, T, A, CO_ALLOC_PREF> where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, { fn drop(&mut self) { if self.0.remaining != 0 { @@ -216,9 +217,9 @@ where } #[stable(feature = "drain", since = "1.6.0")] -impl Iterator for Drain<'_, T, A, COOP_PREF> +impl Iterator for Drain<'_, T, A, CO_ALLOC_PREF> where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, { type Item = T; @@ -241,9 +242,9 @@ where } #[stable(feature = "drain", since = "1.6.0")] -impl DoubleEndedIterator for Drain<'_, T, A, COOP_PREF> +impl DoubleEndedIterator for Drain<'_, T, A, CO_ALLOC_PREF> where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, { #[inline] fn next_back(&mut self) -> Option { @@ -257,13 +258,13 @@ where } #[stable(feature = "drain", since = "1.6.0")] -impl ExactSizeIterator for Drain<'_, T, A, COOP_PREF> where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]: +impl ExactSizeIterator for Drain<'_, T, A, CO_ALLOC_PREF> where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]: { } #[stable(feature = "fused", since = "1.26.0")] -impl FusedIterator for Drain<'_, T, A, COOP_PREF> where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]: +impl FusedIterator for Drain<'_, T, A, CO_ALLOC_PREF> where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]: { } diff --git a/library/alloc/src/collections/vec_deque/into_iter.rs b/library/alloc/src/collections/vec_deque/into_iter.rs index dd4694c892a36..99b73054ff9db 100644 --- a/library/alloc/src/collections/vec_deque/into_iter.rs +++ b/library/alloc/src/collections/vec_deque/into_iter.rs @@ -1,6 +1,6 @@ use core::iter::{FusedIterator, TrustedLen}; use core::{alloc, array, fmt, mem::MaybeUninit, ops::Try, ptr}; - +use crate::co_alloc::CoAllocPref; use crate::alloc::{Allocator, Global}; use super::VecDeque; @@ -17,30 +17,30 @@ use super::VecDeque; pub struct IntoIter< T, #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global, - const COOP_PREF: bool = true, + const CO_ALLOC_PREF: CoAllocPref = true, > where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, { - inner: VecDeque, + inner: VecDeque, } -impl IntoIter +impl IntoIter where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, { - pub(super) fn new(inner: VecDeque) -> Self { + pub(super) fn new(inner: VecDeque) -> Self { IntoIter { inner } } - pub(super) fn into_vecdeque(self) -> VecDeque { + pub(super) fn into_vecdeque(self) -> VecDeque { self.inner } } #[stable(feature = "collection_debug", since = "1.17.0")] -impl fmt::Debug for IntoIter +impl fmt::Debug for IntoIter where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_tuple("IntoIter").field(&self.inner).finish() @@ -48,9 +48,9 @@ where } #[stable(feature = "rust1", since = "1.0.0")] -impl Iterator for IntoIter +impl Iterator for IntoIter where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, { type Item = T; @@ -187,9 +187,9 @@ where } #[stable(feature = "rust1", since = "1.0.0")] -impl DoubleEndedIterator for IntoIter +impl DoubleEndedIterator for IntoIter where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, { #[inline] fn next_back(&mut self) -> Option { @@ -260,9 +260,9 @@ where } #[stable(feature = "rust1", since = "1.0.0")] -impl ExactSizeIterator for IntoIter +impl ExactSizeIterator for IntoIter where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, { #[inline] fn is_empty(&self) -> bool { @@ -271,13 +271,13 @@ where } #[stable(feature = "fused", since = "1.26.0")] -impl FusedIterator for IntoIter where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]: +impl FusedIterator for IntoIter where + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]: { } #[unstable(feature = "trusted_len", issue = "37572")] -unsafe impl TrustedLen for IntoIter where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]: +unsafe impl TrustedLen for IntoIter where + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]: { } diff --git a/library/alloc/src/collections/vec_deque/macros.rs b/library/alloc/src/collections/vec_deque/macros.rs index c31a89a7df337..e92fc6a8fa3b4 100644 --- a/library/alloc/src/collections/vec_deque/macros.rs +++ b/library/alloc/src/collections/vec_deque/macros.rs @@ -1,10 +1,10 @@ macro_rules! __impl_slice_eq1 { ([$($vars:tt)*] $lhs:ty, $rhs:ty, $($constraints:tt)*) => { #[stable(feature = "vec_deque_partial_eq_slice", since = "1.17.0")] - impl PartialEq<$rhs> for $lhs + impl PartialEq<$rhs> for $lhs where T: PartialEq, - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, $($constraints)* { fn eq(&self, other: &$rhs) -> bool { diff --git a/library/alloc/src/collections/vec_deque/mod.rs b/library/alloc/src/collections/vec_deque/mod.rs index 19b147b4a9b2f..e130d3da49665 100644 --- a/library/alloc/src/collections/vec_deque/mod.rs +++ b/library/alloc/src/collections/vec_deque/mod.rs @@ -12,6 +12,7 @@ use core::alloc; use core::cmp::{self, Ordering}; use core::fmt; use core::hash::{Hash, Hasher}; +use crate::co_alloc::CoAllocPref; use core::iter::{repeat_n, repeat_with, ByRefSized, FromIterator}; use core::mem::{ManuallyDrop, SizedTypeProperties}; use core::ops::{Index, IndexMut, Range, RangeBounds}; @@ -97,9 +98,9 @@ mod tests; pub struct VecDeque< T, #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global, - const COOP_PREF: bool = { CO_ALLOC_PREF_DEFAULT!() }, + const CO_ALLOC_PREF: CoAllocPref = { CO_ALLOC_PREF_DEFAULT!() }, > where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, { // `self[0]`, if it exists, is `buf[head]`. // `head < buf.capacity()`, unless `buf.capacity() == 0` when `head == 0`. @@ -108,13 +109,13 @@ pub struct VecDeque< // if `len == 0`, the exact value of `head` is unimportant. // if `T` is zero-Sized, then `self.len <= usize::MAX`, otherwise `self.len <= isize::MAX as usize`. len: usize, - buf: RawVec, + buf: RawVec, } #[stable(feature = "rust1", since = "1.0.0")] -impl Clone for VecDeque +impl Clone for VecDeque where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, { fn clone(&self) -> Self { let mut deq = Self::with_capacity_in(self.len(), self.allocator().clone()); @@ -129,9 +130,9 @@ where } #[stable(feature = "rust1", since = "1.0.0")] -unsafe impl<#[may_dangle] T, A: Allocator, const COOP_PREF: bool> Drop for VecDeque +unsafe impl<#[may_dangle] T, A: Allocator, const CO_ALLOC_PREF: CoAllocPref> Drop for VecDeque where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, { fn drop(&mut self) { /// Runs the destructor for all items in the slice when it gets dropped (normally or @@ -157,20 +158,20 @@ where } #[stable(feature = "rust1", since = "1.0.0")] -impl Default for VecDeque +impl Default for VecDeque where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); {meta_num_slots_global!(CO_ALLOC_PREF)}]:, { /// Creates an empty deque. #[inline] - fn default() -> VecDeque { - VecDeque::::new() + fn default() -> VecDeque { + VecDeque::::new() } } -impl VecDeque +impl VecDeque where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, { /// Marginally more convenient #[inline] @@ -460,17 +461,17 @@ where mut iter: impl Iterator, len: usize, ) -> usize { - struct Guard<'a, T, A: Allocator, const COOP_PREF: bool> + struct Guard<'a, T, A: Allocator, const CO_ALLOC_PREF: CoAllocPref> where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, { - deque: &'a mut VecDeque, + deque: &'a mut VecDeque, written: usize, } - impl<'a, T, A: Allocator, const COOP_PREF: bool> Drop for Guard<'a, T, A, COOP_PREF> + impl<'a, T, A: Allocator, const CO_ALLOC_PREF: CoAllocPref> Drop for Guard<'a, T, A, CO_ALLOC_PREF> where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, { fn drop(&mut self) { self.deque.len += self.written; @@ -549,10 +550,10 @@ where } } -impl VecDeque +impl VecDeque where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, { /// Creates an empty deque. /// @@ -567,9 +568,9 @@ where #[stable(feature = "rust1", since = "1.0.0")] #[rustc_const_stable(feature = "const_vec_deque_new", since = "1.68.0")] #[must_use] - pub const fn new() -> VecDeque + pub const fn new() -> VecDeque where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, { // FIXME: This should just be `VecDeque::new_in(Global)` once that hits stable. VecDeque { head: 0, len: 0, buf: RawVec::NEW } @@ -587,14 +588,14 @@ where #[inline] #[stable(feature = "rust1", since = "1.0.0")] #[must_use] - pub fn with_capacity(capacity: usize) -> VecDeque { - VecDeque::::with_capacity_in(capacity, Global) + pub fn with_capacity(capacity: usize) -> VecDeque { + VecDeque::::with_capacity_in(capacity, Global) } } -impl VecDeque +impl VecDeque where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, { /// Creates an empty deque. /// @@ -607,7 +608,7 @@ where /// ``` #[inline] #[unstable(feature = "allocator_api", issue = "32838")] - pub const fn new_in(alloc: A) -> VecDeque { + pub const fn new_in(alloc: A) -> VecDeque { VecDeque { head: 0, len: 0, buf: RawVec::new_in(alloc) } } @@ -621,7 +622,7 @@ where /// let deque: VecDeque = VecDeque::with_capacity(10); /// ``` #[unstable(feature = "allocator_api", issue = "32838")] - pub fn with_capacity_in(capacity: usize, alloc: A) -> VecDeque { + pub fn with_capacity_in(capacity: usize, alloc: A) -> VecDeque { VecDeque { head: 0, len: 0, buf: RawVec::with_capacity_in(capacity, alloc) } } @@ -1402,7 +1403,7 @@ where /// ``` #[inline] #[stable(feature = "drain", since = "1.6.0")] - pub fn drain(&mut self, range: R) -> Drain<'_, T, A, COOP_PREF> + pub fn drain(&mut self, range: R) -> Drain<'_, T, A, CO_ALLOC_PREF> where R: RangeBounds, { @@ -2630,9 +2631,9 @@ where } } -impl VecDeque +impl VecDeque where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, { /// Modifies the deque in-place so that `len()` is equal to new_len, /// either by removing excess elements from the back or by appending clones of `value` @@ -2678,9 +2679,9 @@ fn wrap_index(logical_index: usize, capacity: usize) -> usize { } #[stable(feature = "rust1", since = "1.0.0")] -impl PartialEq for VecDeque +impl PartialEq for VecDeque where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, { fn eq(&self, other: &Self) -> bool { if self.len != other.len() { @@ -2720,22 +2721,22 @@ where } #[stable(feature = "rust1", since = "1.0.0")] -impl Eq for VecDeque where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]: +impl Eq for VecDeque where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]: { } -__impl_slice_eq1! { [] VecDeque, Vec, } -__impl_slice_eq1! { [] VecDeque, &[U], } -__impl_slice_eq1! { [] VecDeque, &mut [U], } -__impl_slice_eq1! { [const N: usize] VecDeque, [U; N], } -__impl_slice_eq1! { [const N: usize] VecDeque, &[U; N], } -__impl_slice_eq1! { [const N: usize] VecDeque, &mut [U; N], } +__impl_slice_eq1! { [] VecDeque, Vec, } +__impl_slice_eq1! { [] VecDeque, &[U], } +__impl_slice_eq1! { [] VecDeque, &mut [U], } +__impl_slice_eq1! { [const N: usize] VecDeque, [U; N], } +__impl_slice_eq1! { [const N: usize] VecDeque, &[U; N], } +__impl_slice_eq1! { [const N: usize] VecDeque, &mut [U; N], } #[stable(feature = "rust1", since = "1.0.0")] -impl PartialOrd for VecDeque +impl PartialOrd for VecDeque where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, { fn partial_cmp(&self, other: &Self) -> Option { self.iter().partial_cmp(other.iter()) @@ -2743,9 +2744,9 @@ where } #[stable(feature = "rust1", since = "1.0.0")] -impl Ord for VecDeque +impl Ord for VecDeque where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, { #[inline] fn cmp(&self, other: &Self) -> Ordering { @@ -2754,9 +2755,9 @@ where } #[stable(feature = "rust1", since = "1.0.0")] -impl Hash for VecDeque +impl Hash for VecDeque where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, { fn hash(&self, state: &mut H) { state.write_length_prefix(self.len); @@ -2771,9 +2772,9 @@ where } #[stable(feature = "rust1", since = "1.0.0")] -impl Index for VecDeque +impl Index for VecDeque where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, { type Output = T; @@ -2784,9 +2785,9 @@ where } #[stable(feature = "rust1", since = "1.0.0")] -impl IndexMut for VecDeque +impl IndexMut for VecDeque where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, { #[inline] fn index_mut(&mut self, index: usize) -> &mut T { @@ -2795,34 +2796,34 @@ where } #[stable(feature = "rust1", since = "1.0.0")] -impl FromIterator for VecDeque +impl FromIterator for VecDeque where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, { - fn from_iter>(iter: I) -> VecDeque { + fn from_iter>(iter: I) -> VecDeque { SpecFromIter::spec_from_iter(iter.into_iter()) } } #[stable(feature = "rust1", since = "1.0.0")] -impl IntoIterator for VecDeque +impl IntoIterator for VecDeque where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, { type Item = T; - type IntoIter = IntoIter; + type IntoIter = IntoIter; /// Consumes the deque into a front-to-back iterator yielding elements by /// value. - fn into_iter(self) -> IntoIter { + fn into_iter(self) -> IntoIter { IntoIter::new(self) } } #[stable(feature = "rust1", since = "1.0.0")] -impl<'a, T, A: Allocator, const COOP_PREF: bool> IntoIterator for &'a VecDeque +impl<'a, T, A: Allocator, const CO_ALLOC_PREF: CoAllocPref> IntoIterator for &'a VecDeque where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, { type Item = &'a T; type IntoIter = Iter<'a, T>; @@ -2833,9 +2834,9 @@ where } #[stable(feature = "rust1", since = "1.0.0")] -impl<'a, T, A: Allocator, const COOP_PREF: bool> IntoIterator for &'a mut VecDeque +impl<'a, T, A: Allocator, const CO_ALLOC_PREF: CoAllocPref> IntoIterator for &'a mut VecDeque where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, { type Item = &'a mut T; type IntoIter = IterMut<'a, T>; @@ -2846,9 +2847,9 @@ where } #[stable(feature = "rust1", since = "1.0.0")] -impl Extend for VecDeque +impl Extend for VecDeque where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, { fn extend>(&mut self, iter: I) { >::spec_extend(self, iter.into_iter()); @@ -2866,10 +2867,10 @@ where } #[stable(feature = "extend_ref", since = "1.2.0")] -impl<'a, T: 'a + Copy, A: Allocator, const COOP_PREF: bool> Extend<&'a T> - for VecDeque +impl<'a, T: 'a + Copy, A: Allocator, const CO_ALLOC_PREF: CoAllocPref> Extend<&'a T> + for VecDeque where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, { fn extend>(&mut self, iter: I) { self.spec_extend(iter.into_iter()); @@ -2887,9 +2888,9 @@ where } #[stable(feature = "rust1", since = "1.0.0")] -impl fmt::Debug for VecDeque +impl fmt::Debug for VecDeque where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_list().entries(self.iter()).finish() @@ -2897,11 +2898,11 @@ where } #[stable(feature = "vecdeque_vec_conversions", since = "1.10.0")] -impl - From> for VecDeque +impl + From> for VecDeque where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(OTHER_COOP_PREF)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(OTHER_CO_ALLOC_PREF)]:, { /// Turn a [`Vec`] into a [`VecDeque`]. /// @@ -2912,22 +2913,22 @@ where /// and to not re-allocate the `Vec`'s buffer or allocate /// any additional memory. #[inline] - fn from(other: Vec) -> Self { + fn from(other: Vec) -> Self { let (ptr, len, cap, alloc) = other.into_raw_parts_with_alloc(); Self { head: 0, len, - buf: unsafe { RawVec::::from_raw_parts_in(ptr, cap, alloc) }, + buf: unsafe { RawVec::::from_raw_parts_in(ptr, cap, alloc) }, } } } #[stable(feature = "vecdeque_vec_conversions", since = "1.10.0")] -impl - From> for Vec +impl + From> for Vec where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(VECDEQUE_COOP_PREF)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(VECDEQUE_CO_ALLOC_PREF)]:, { /// Turn a [`VecDeque`] into a [`Vec`]. /// @@ -2958,9 +2959,9 @@ where /// assert_eq!(vec, [8, 9, 1, 2, 3, 4]); /// assert_eq!(vec.as_ptr(), ptr); /// ``` - fn from(mut other: VecDeque) -> Self + fn from(mut other: VecDeque) -> Self where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(VECDEQUE_COOP_PREF)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(VECDEQUE_CO_ALLOC_PREF)]:, { other.make_contiguous(); @@ -2975,15 +2976,15 @@ where ptr::copy(buf.add(other.head), buf, len); } // @FIXME: COOP - Vec::::from_raw_parts_in(buf, len, cap, alloc) + Vec::::from_raw_parts_in(buf, len, cap, alloc) } } } #[stable(feature = "std_collections_from_array", since = "1.56.0")] -impl From<[T; N]> for VecDeque +impl From<[T; N]> for VecDeque where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); {meta_num_slots_global!(CO_ALLOC_PREF)}]:, { /// Converts a `[T; N]` into a `VecDeque`. /// @@ -2995,12 +2996,12 @@ where /// assert_eq!(deq1, deq2); /// ``` fn from(arr: [T; N]) -> Self { - let mut deq = VecDeque::::with_capacity(N); + let mut deq = VecDeque::::with_capacity(N); let arr = ManuallyDrop::new(arr); if !::IS_ZST { // SAFETY: VecDeque::with_capacity ensures that there is enough capacity. unsafe { - // @FIXME for COOP_PREF: + // @FIXME for CO_ALLOC_PREF: ptr::copy_nonoverlapping(arr.as_ptr(), deq.ptr(), N); } } diff --git a/library/alloc/src/collections/vec_deque/spec_extend.rs b/library/alloc/src/collections/vec_deque/spec_extend.rs index c17be75f0e2fe..d4abb73048834 100644 --- a/library/alloc/src/collections/vec_deque/spec_extend.rs +++ b/library/alloc/src/collections/vec_deque/spec_extend.rs @@ -1,6 +1,7 @@ #![feature(min_specialization)] use crate::alloc::Allocator; +use crate::co_alloc::CoAllocPref; use crate::vec; use core::alloc; use core::iter::TrustedLen; @@ -13,10 +14,10 @@ pub(super) trait SpecExtend { fn spec_extend(&mut self, iter: I); } -impl SpecExtend for VecDeque +impl SpecExtend for VecDeque where I: Iterator, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, { default fn spec_extend(&mut self, mut iter: I) { // This function should be the moral equivalent of: @@ -26,11 +27,11 @@ where // } // May only be called if `deque.len() < deque.capacity()` - unsafe fn push_unchecked( - deque: &mut VecDeque, + unsafe fn push_unchecked( + deque: &mut VecDeque, element: T, ) where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, { // SAFETY: Because of the precondition, it's guaranteed that there is space // in the logical array after the last element. @@ -58,10 +59,10 @@ where } } -impl SpecExtend for VecDeque +impl SpecExtend for VecDeque where I: TrustedLen, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, { default fn spec_extend(&mut self, iter: I) { // This is the case for a TrustedLen iterator. @@ -94,10 +95,10 @@ where } } -impl SpecExtend> - for VecDeque +impl SpecExtend> + for VecDeque where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, { fn spec_extend(&mut self, mut iterator: vec::IntoIter) { let slice = iterator.as_slice(); @@ -111,23 +112,23 @@ where } } -impl<'a, T: 'a, I, A: Allocator, const COOP_PREF: bool> SpecExtend<&'a T, I> - for VecDeque +impl<'a, T: 'a, I, A: Allocator, const CO_ALLOC_PREF: CoAllocPref> SpecExtend<&'a T, I> + for VecDeque where I: Iterator, T: Copy, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, { default fn spec_extend(&mut self, iterator: I) { self.spec_extend(iterator.copied()) } } -impl<'a, T: 'a, A: Allocator, const COOP_PREF: bool> SpecExtend<&'a T, slice::Iter<'a, T>> - for VecDeque +impl<'a, T: 'a, A: Allocator, const CO_ALLOC_PREF: CoAllocPref> SpecExtend<&'a T, slice::Iter<'a, T>> + for VecDeque where T: Copy, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, { fn spec_extend(&mut self, iterator: slice::Iter<'a, T>) { let slice = iterator.as_slice(); diff --git a/library/alloc/src/collections/vec_deque/spec_from_iter.rs b/library/alloc/src/collections/vec_deque/spec_from_iter.rs index b846ce37e7338..5bd9043df34c7 100644 --- a/library/alloc/src/collections/vec_deque/spec_from_iter.rs +++ b/library/alloc/src/collections/vec_deque/spec_from_iter.rs @@ -1,5 +1,6 @@ use super::{IntoIter, VecDeque}; use crate::alloc::Global; +use crate::co_alloc::CoAllocPref; use core::alloc; /// Specialization trait used for `VecDeque::from_iter` @@ -7,38 +8,38 @@ pub(super) trait SpecFromIter { fn spec_from_iter(iter: I) -> Self; } -impl SpecFromIter for VecDeque +impl SpecFromIter for VecDeque where I: Iterator, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, { default fn spec_from_iter(iterator: I) -> Self { // Since converting is O(1) now, just re-use the `Vec` logic for // anything where we can't do something extra-special for `VecDeque`, // especially as that could save us some monomorphiziation work // if one uses the same iterators (like slice ones) with both. - crate::vec::Vec::::from_iter(iterator).into() + crate::vec::Vec::::from_iter(iterator).into() } } -impl SpecFromIter> - for VecDeque +impl SpecFromIter> + for VecDeque where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, { #[inline] - fn spec_from_iter(iterator: crate::vec::IntoIter) -> Self { + fn spec_from_iter(iterator: crate::vec::IntoIter) -> Self { iterator.into_vecdeque() } } -impl SpecFromIter> - for VecDeque +impl SpecFromIter> + for VecDeque where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, { #[inline] - fn spec_from_iter(iterator: IntoIter) -> Self { + fn spec_from_iter(iterator: IntoIter) -> Self { iterator.into_vecdeque() } } diff --git a/library/alloc/src/macros.rs b/library/alloc/src/macros.rs index f719158e24ed7..f2c19eced02d0 100644 --- a/library/alloc/src/macros.rs +++ b/library/alloc/src/macros.rs @@ -126,7 +126,36 @@ macro_rules! __rust_force_expr { } // ----- CoAlloc constant-like macros: -/// "Yes" as a type's preference for coallocation (in either user space, or `std` space). + +// @FIXME Docs +#[unstable(feature = "global_co_alloc_meta", issue = "none")] +#[macro_export] +macro_rules! CO_ALLOC_PREF_NUM_META_SLOTS_ONE { + () => { + (1 as $crate::co_alloc::CoAllocMetaNumSlotsPref) + }; +} + +// @FIXME Docs +#[unstable(feature = "global_co_alloc_meta", issue = "none")] +#[macro_export] +macro_rules! CO_ALLOC_PREF_NUM_META_SLOTS_ZERO { + () => { + (0 as $crate::co_alloc::CoAllocMetaNumSlotsPref) + }; +} + +// @FIXME Docs +#[unstable(feature = "global_co_alloc_meta", issue = "none")] +#[macro_export] +macro_rules! CO_ALLOC_PREF_NUM_META_SLOTS_DEFAULT { + () => { + (0 as $crate::co_alloc::CoAllocMetaNumSlotsPref) + }; +} + +/// "Yes" as a type's preference for coallocation using metadata (in either user space, or `alloc` +/// or `std` space). /// /// It may be overriden by the allocator. For example, if the allocator doesn't support /// coallocation, then this value makes no difference. @@ -138,11 +167,12 @@ macro_rules! __rust_force_expr { #[macro_export] macro_rules! CO_ALLOC_PREF_META_YES { () => { - (1 as $crate::co_alloc::CoAllocMetaNumSlotsPref) + $crate::co_alloc_pref!($crate::CO_ALLOC_PREF_NUM_META_SLOTS_ONE!()) }; } -/// "No" as a type's preference for coallocation (in either user space, or `std` space). +/// "No" as a type's preference for coallocation using metadata (in either user space, or `alloc` or +/// `std` space). /// /// Any allocator is required to respect this. Even if the allocator does support coallocation, it /// will not coallocate types that use this value. @@ -154,15 +184,13 @@ macro_rules! CO_ALLOC_PREF_META_YES { #[macro_export] macro_rules! CO_ALLOC_PREF_META_NO { () => { - (0 as $crate::co_alloc::CoAllocMetaNumSlotsPref) + $crate::co_alloc_pref!($crate::CO_ALLOC_PREF_NUM_META_SLOTS_ZERO!()) }; } -/// Default preference for coallocation (in either user space, or `std` space). +/// "Default" as a type's preference for coallocation using metadata (in either user space, or +/// `alloc` or `std` space). /// -/// Possible values are only: `CO_ALLOC_PREF_META_YES` and `CO_ALLOC_PREF_META_NO`. See their -/// documentation. -/// /// This value and its type WILL CHANGE (once ``#![feature(generic_const_exprs)]` and /// `#![feature(adt_const_params)]` are stable) to a dedicated struct/enum. Hence DO NOT hard /// code/replace/mix this any other values/parameters. @@ -174,7 +202,7 @@ macro_rules! CO_ALLOC_PREF_META_NO { #[macro_export] macro_rules! CO_ALLOC_PREF_META_DEFAULT { () => { - (0 as $crate::co_alloc::CoAllocMetaNumSlotsPref) + $crate::co_alloc_pref!($crate::CO_ALLOC_PREF_NUM_META_SLOTS_DEFAULT!()) }; } @@ -182,15 +210,16 @@ macro_rules! CO_ALLOC_PREF_META_DEFAULT { #[unstable(feature = "global_co_alloc_meta", issue = "none")] #[macro_export] macro_rules! CO_ALLOC_PREF_DEFAULT { - () => { $crate::co_alloc_pref!($crate::CO_ALLOC_PREF_META_DEFAULT!()) }; + () => { $crate::CO_ALLOC_PREF_META_DEFAULT!() }; } // ------ CoAlloc preference/config conversion macros: + /// Create a `CoAllocPref` value based on the given parameter(s). For now, only one parameter is /// supported, and it's required: `meta_pref`. /// -/// @param `meta_pref` is one of: `CO_ALLOC_PREF_META_YES, CO_ALLOC_PREF_META_NO, -/// CO_ALLOC_PREF_META_DEFAULT`. +/// @param `meta_pref` is one of: `CO_ALLOC_PREF_META_YES, CO_ALLOC_PREF_META_NO`, or +/// `CO_ALLOC_PREF_META_DEFAULT`. /// /// @return `CoAllocPref` value #[unstable(feature = "global_co_alloc_meta", issue = "none")] @@ -229,7 +258,7 @@ macro_rules! meta_num_slots { ($alloc:ty, $co_alloc_pref:expr) => { ( ((<$alloc>::CO_ALLOC_META_NUM_SLOTS + (0 as ::core::alloc::CoAllocatorMetaNumSlots)) - as $crate::co_alloc::CoAllocPref) + as usize) * ($co_alloc_pref + (0 as $crate::co_alloc::CoAllocPref)) as usize) }; @@ -238,16 +267,16 @@ macro_rules! meta_num_slots { /* #[unstable(feature = "global_co_alloc", issue = "none")] pub const fn meta_num_slots( - COOP_PREF: bool, + CO_ALLOC_PREF: bool, ) -> usize { - if A::CO_ALLOC_META_NUM_SLOTS && COOP_PREF { 1 } else { 0 } + if A::CO_ALLOC_META_NUM_SLOTS && CO_ALLOC_PREF { 1 } else { 0 } } */ -/// Like `meta_num_slots`, but for the default coallocation preference (`DEFAULT_COOP_PREF`). +/// Like `meta_num_slots`, but for the default coallocation preference (`DEFAULT_CO_ALLOC_PREF`). /// /// Return 0 or 1, indicating whether to use coallocation metadata (or not) with the given allocator -/// type `alloc` and the default coallocation preference (`DEFAULT_COOP_PREF()!`). +/// type `alloc` and the default coallocation preference (`DEFAULT_CO_ALLOC_PREF()!`). /// // FIXME replace the macro with a `const` function. Only once generic_const_exprs is stable (that // is, when consumer crates don't need to declare generic_const_exprs feature anymore). Then @@ -262,7 +291,7 @@ macro_rules! meta_num_slots_default { }; } -/// Like `meta_num_slots`, but for the default coallocation preference (`DEFAULT_COOP_PREF`). +/// Like `meta_num_slots`, but for the default coallocation preference (`DEFAULT_CO_ALLOC_PREF`). /// /// Return 0 or 1, indicating whether to use coallocation metadata (or not) with the global allocator /// type `alloc` and the given coallocation preference `co_alloc_`. diff --git a/library/alloc/src/raw_vec.rs b/library/alloc/src/raw_vec.rs index fb1defeaacf82..0265b446af9fc 100644 --- a/library/alloc/src/raw_vec.rs +++ b/library/alloc/src/raw_vec.rs @@ -1,5 +1,6 @@ #![unstable(feature = "raw_vec_internals", reason = "unstable const warnings", issue = "none")] +use crate::co_alloc::CoAllocPref; use crate::meta_num_slots_default; use core::alloc::CoAllocMetaBase; use core::alloc::{self, LayoutError, PtrAndMeta}; @@ -56,9 +57,9 @@ enum AllocInit { pub(crate) struct RawVec< T, A: Allocator = Global, - const COOP_PREF: bool = { CO_ALLOC_PREF_DEFAULT!() }, + const CO_ALLOC_PREF: CoAllocPref = { CO_ALLOC_PREF_DEFAULT!() }, > where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); {meta_num_slots!(A, CO_ALLOC_PREF)}]:, { ptr: Unique, cap: usize, @@ -67,12 +68,12 @@ pub(crate) struct RawVec< //pub(crate) meta: [GlobalCoAllocMeta; {if core::any::TypeId::of::()==core::any::TypeId::of::() {1} else {0}}], //pub(crate) meta: [GlobalCoAllocMeta; mem::size_of::()], pub(crate) metas: - [A::CoAllocMeta; alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)], + [A::CoAllocMeta; alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)], } -impl RawVec +impl RawVec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); {meta_num_slots_global!(CO_ALLOC_PREF)}]:, { /// HACK(Centril): This exists because stable `const fn` can only call stable `const fn`, so /// they cannot call `Self::new()`. @@ -120,9 +121,9 @@ where } } -impl RawVec +impl RawVec where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, { const fn new_plain_metas() -> [A::CoAllocMeta; { meta_num_slots_default!(A) }] { loop {} @@ -150,7 +151,7 @@ where cap: 0, alloc, metas: [A::CoAllocMeta::new_plain(); // @FIXME CoAlloc - alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)], + alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)], } } @@ -230,7 +231,7 @@ where cap: capacity, alloc, metas: [A::CoAllocMeta::new_plain(); // @FIXME CoAlloc - alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)], + alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)], } } } @@ -253,7 +254,7 @@ where cap: capacity, alloc, metas: [A::CoAllocMeta::new_plain(); //@FIXME CoAlloc - alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)], + alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)], } } @@ -323,12 +324,12 @@ where // handle_reserve behind a call, while making sure that this function is likely to be // inlined as just a comparison and a call if the comparison fails. #[cold] - fn do_reserve_and_handle( - slf: &mut RawVec, + fn do_reserve_and_handle( + slf: &mut RawVec, len: usize, additional: usize, ) where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, { handle_reserve(slf.grow_amortized(len, additional)); } @@ -402,9 +403,9 @@ where } } -impl RawVec +impl RawVec where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, { /// Returns if the buffer needs to grow to fulfill the needed extra capacity. /// Mainly used to make inlining reserve-calls possible without inlining `grow`. @@ -525,14 +526,14 @@ where memory.map_err(|_| AllocError { layout: new_layout, non_exhaustive: () }.into()) } -unsafe impl<#[may_dangle] T, A: Allocator, const COOP_PREF: bool> Drop for RawVec +unsafe impl<#[may_dangle] T, A: Allocator, const CO_ALLOC_PREF: CoAllocPref> Drop for RawVec where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, { /// Frees the memory owned by the `RawVec` *without* trying to drop its contents. default fn drop(&mut self) { if let Some((ptr, layout)) = self.current_memory() { - if A::CO_ALLOCATES_WITH_META && COOP_PREF { + if A::CO_ALLOCATES_WITH_META && CO_ALLOC_PREF { let meta = self.metas[0]; unsafe { self.alloc.co_deallocate(PtrAndMeta { ptr, meta }, layout) } } else { diff --git a/library/alloc/src/rc.rs b/library/alloc/src/rc.rs index b3533ae719612..fe8f1d350a00a 100644 --- a/library/alloc/src/rc.rs +++ b/library/alloc/src/rc.rs @@ -1987,9 +1987,9 @@ impl From> for Rc { #[cfg(not(no_global_oom_handling))] #[stable(feature = "shared_from_slice", since = "1.21.0")] -impl From> for Rc<[T]> +impl From> for Rc<[T]> where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); {meta_num_slots_global!(CO_ALLOC_PREF)}]:, { /// Allocate a reference-counted slice and move `v`'s items into it. /// @@ -2002,9 +2002,9 @@ where /// assert_eq!(vec![1, 2, 3], *shared); /// ``` #[inline] - fn from(mut v: Vec) -> Rc<[T]> + fn from(mut v: Vec) -> Rc<[T]> where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); {meta_num_slots_global!(CO_ALLOC_PREF)}]:, { unsafe { let rc = Rc::copy_from_slice(&v); diff --git a/library/alloc/src/slice.rs b/library/alloc/src/slice.rs index c6f581637cdad..c0b26521bf9c7 100644 --- a/library/alloc/src/slice.rs +++ b/library/alloc/src/slice.rs @@ -29,6 +29,7 @@ use crate::alloc::{self, Global}; use crate::borrow::ToOwned; use crate::boxed::Box; use crate::vec::Vec; +use crate::co_alloc::CoAllocPref; #[cfg(test)] mod tests; @@ -97,9 +98,9 @@ pub(crate) mod hack { // We shouldn't add inline attribute to this since this is used in // `vec!` macro mostly and causes perf regression. See #71204 for // discussion and perf results. - pub fn into_vec(b: Box<[T], A>) -> Vec + pub fn into_vec(b: Box<[T], A>) -> Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, { unsafe { let len = b.len(); @@ -110,47 +111,47 @@ pub(crate) mod hack { #[cfg(not(no_global_oom_handling))] #[inline] - pub fn to_vec( + pub fn to_vec( s: &[T], alloc: A, - ) -> Vec + ) -> Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, { T::to_vec(s, alloc) } #[cfg(not(no_global_oom_handling))] pub trait ConvertVec { - fn to_vec( + fn to_vec( s: &[Self], alloc: A, - ) -> Vec + ) -> Vec where Self: Sized, - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:; + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:; } #[cfg(not(no_global_oom_handling))] impl ConvertVec for T { #[inline] - default fn to_vec( + default fn to_vec( s: &[Self], alloc: A, - ) -> Vec + ) -> Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, { - struct DropGuard<'a, T, A: Allocator, const COOP_PREF: bool> + struct DropGuard<'a, T, A: Allocator, const CO_ALLOC_PREF: CoAllocPref> where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, { - vec: &'a mut Vec, + vec: &'a mut Vec, num_init: usize, } - impl<'a, T, A: Allocator, const COOP_PREF: bool> Drop for DropGuard<'a, T, A, COOP_PREF> + impl<'a, T, A: Allocator, const CO_ALLOC_PREF: CoAllocPref> Drop for DropGuard<'a, T, A, CO_ALLOC_PREF> where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, { #[inline] fn drop(&mut self) { @@ -183,12 +184,12 @@ pub(crate) mod hack { #[cfg(not(no_global_oom_handling))] impl ConvertVec for T { #[inline] - fn to_vec( + fn to_vec( s: &[Self], alloc: A, - ) -> Vec + ) -> Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, { let mut v = Vec::with_capacity_in(s.len(), alloc); // SAFETY: @@ -440,12 +441,12 @@ impl [T] { #[rustc_conversion_suggestion] #[stable(feature = "rust1", since = "1.0.0")] #[inline] - pub fn to_vec(&self) -> Vec + pub fn to_vec(&self) -> Vec where T: Clone, - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); {meta_num_slots_global!(CO_ALLOC_PREF)}]:, { - self.to_vec_in::(Global) + self.to_vec_in::(Global) } /// Copies `self` into a new `Vec` with an allocator. @@ -465,10 +466,10 @@ impl [T] { #[rustc_allow_incoherent_impl] #[inline] #[unstable(feature = "allocator_api", issue = "32838")] - pub fn to_vec_in(&self, alloc: A) -> Vec + pub fn to_vec_in(&self, alloc: A) -> Vec where T: Clone, - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, { // N.B., see the `hack` module in this file for more details. hack::to_vec(self, alloc) @@ -491,9 +492,9 @@ impl [T] { #[rustc_allow_incoherent_impl] #[stable(feature = "rust1", since = "1.0.0")] #[inline] - pub fn into_vec(self: Box) -> Vec + pub fn into_vec(self: Box) -> Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, { // N.B., see the `hack` module in this file for more details. hack::into_vec(self) @@ -808,9 +809,9 @@ impl> Join<&[T]> for [V] { //////////////////////////////////////////////////////////////////////////////// #[stable(feature = "rust1", since = "1.0.0")] -impl Borrow<[T]> for Vec +impl Borrow<[T]> for Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, { fn borrow(&self) -> &[T] { &self[..] @@ -818,9 +819,9 @@ where } #[stable(feature = "rust1", since = "1.0.0")] -impl BorrowMut<[T]> for Vec +impl BorrowMut<[T]> for Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, { fn borrow_mut(&mut self) -> &mut [T] { &mut self[..] diff --git a/library/alloc/src/str.rs b/library/alloc/src/str.rs index c3f722d9e3711..8b9c2fed4a3fa 100644 --- a/library/alloc/src/str.rs +++ b/library/alloc/src/str.rs @@ -128,15 +128,15 @@ macro_rules! copy_slice_and_advance { // [T] and str both impl AsRef<[T]> for some T // => s.borrow().as_ref() and we always have slices #[cfg(not(no_global_oom_handling))] -fn join_generic_copy( +fn join_generic_copy( slice: &[S], sep: &[T], -) -> Vec +) -> Vec where T: Copy, B: AsRef<[T]> + ?Sized, S: Borrow, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, { let sep_len = sep.len(); let mut iter = slice.iter(); diff --git a/library/alloc/src/vec/drain.rs b/library/alloc/src/vec/drain.rs index 2fdc752ad2488..a3cddcb9f76d0 100644 --- a/library/alloc/src/vec/drain.rs +++ b/library/alloc/src/vec/drain.rs @@ -1,5 +1,6 @@ use crate::alloc::{Allocator, Global}; use core::fmt; +use crate::co_alloc::CoAllocPref; use core::iter::{FusedIterator, TrustedLen}; use core::mem::{self, ManuallyDrop, SizedTypeProperties}; use core::ptr::{self, NonNull}; @@ -24,9 +25,9 @@ pub struct Drain< 'a, T: 'a, #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator + 'a = Global, - const COOP_PREF: bool = { SHORT_TERM_VEC_PREFERS_COOP!() }, + const CO_ALLOC_PREF: CoAllocPref = { SHORT_TERM_VEC_PREFERS_COOP!() }, > where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, { /// Index of tail to preserve pub(super) tail_start: usize, @@ -34,22 +35,22 @@ pub struct Drain< pub(super) tail_len: usize, /// Current remaining range to remove pub(super) iter: slice::Iter<'a, T>, - pub(super) vec: NonNull>, + pub(super) vec: NonNull>, } #[stable(feature = "collection_debug", since = "1.17.0")] -impl fmt::Debug for Drain<'_, T, A, COOP_PREF> +impl fmt::Debug for Drain<'_, T, A, CO_ALLOC_PREF> where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_tuple("Drain").field(&self.iter.as_slice()).finish() } } -impl<'a, T, A: Allocator, const COOP_PREF: bool> Drain<'a, T, A, COOP_PREF> +impl<'a, T, A: Allocator, const CO_ALLOC_PREF: CoAllocPref> Drain<'a, T, A, CO_ALLOC_PREF> where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, { /// Returns the remaining items of this iterator as a slice. /// @@ -149,9 +150,9 @@ where } #[stable(feature = "vec_drain_as_slice", since = "1.46.0")] -impl<'a, T, A: Allocator, const COOP_PREF: bool> AsRef<[T]> for Drain<'a, T, A, COOP_PREF> +impl<'a, T, A: Allocator, const CO_ALLOC_PREF: CoAllocPref> AsRef<[T]> for Drain<'a, T, A, CO_ALLOC_PREF> where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, { fn as_ref(&self) -> &[T] { self.as_slice() @@ -159,20 +160,20 @@ where } #[stable(feature = "drain", since = "1.6.0")] -unsafe impl Sync for Drain<'_, T, A, COOP_PREF> where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]: +unsafe impl Sync for Drain<'_, T, A, CO_ALLOC_PREF> where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]: { } #[stable(feature = "drain", since = "1.6.0")] -unsafe impl Send for Drain<'_, T, A, COOP_PREF> where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]: +unsafe impl Send for Drain<'_, T, A, CO_ALLOC_PREF> where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]: { } #[stable(feature = "drain", since = "1.6.0")] -impl Iterator for Drain<'_, T, A, COOP_PREF> +impl Iterator for Drain<'_, T, A, CO_ALLOC_PREF> where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, { type Item = T; @@ -187,9 +188,9 @@ where } #[stable(feature = "drain", since = "1.6.0")] -impl DoubleEndedIterator for Drain<'_, T, A, COOP_PREF> +impl DoubleEndedIterator for Drain<'_, T, A, CO_ALLOC_PREF> where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, { #[inline] fn next_back(&mut self) -> Option { @@ -198,21 +199,21 @@ where } #[stable(feature = "drain", since = "1.6.0")] -impl Drop for Drain<'_, T, A, COOP_PREF> +impl Drop for Drain<'_, T, A, CO_ALLOC_PREF> where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, { fn drop(&mut self) { /// Moves back the un-`Drain`ed elements to restore the original `Vec`. - struct DropGuard<'r, 'a, T, A: Allocator, const COOP_PREF: bool>( - &'r mut Drain<'a, T, A, COOP_PREF>, + struct DropGuard<'r, 'a, T, A: Allocator, const CO_ALLOC_PREF: CoAllocPref>( + &'r mut Drain<'a, T, A, CO_ALLOC_PREF>, ) where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:; + [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:; - impl<'r, 'a, T, A: Allocator, const COOP_PREF: bool> Drop for DropGuard<'r, 'a, T, A, COOP_PREF> + impl<'r, 'a, T, A: Allocator, const CO_ALLOC_PREF: CoAllocPref> Drop for DropGuard<'r, 'a, T, A, CO_ALLOC_PREF> where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, { fn drop(&mut self) { if self.0.tail_len > 0 { @@ -277,9 +278,9 @@ where } #[stable(feature = "drain", since = "1.6.0")] -impl ExactSizeIterator for Drain<'_, T, A, COOP_PREF> +impl ExactSizeIterator for Drain<'_, T, A, CO_ALLOC_PREF> where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, { fn is_empty(&self) -> bool { self.iter.is_empty() @@ -287,13 +288,13 @@ where } #[unstable(feature = "trusted_len", issue = "37572")] -unsafe impl TrustedLen for Drain<'_, T, A, COOP_PREF> where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]: +unsafe impl TrustedLen for Drain<'_, T, A, CO_ALLOC_PREF> where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]: { } #[stable(feature = "fused", since = "1.26.0")] -impl FusedIterator for Drain<'_, T, A, COOP_PREF> where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]: +impl FusedIterator for Drain<'_, T, A, CO_ALLOC_PREF> where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]: { } diff --git a/library/alloc/src/vec/drain_filter.rs b/library/alloc/src/vec/drain_filter.rs index 82b302745a4f8..449a779554916 100644 --- a/library/alloc/src/vec/drain_filter.rs +++ b/library/alloc/src/vec/drain_filter.rs @@ -1,4 +1,5 @@ use crate::alloc::{Allocator, Global}; +use crate::co_alloc::CoAllocPref; use core::mem::{self, ManuallyDrop}; use core::{alloc, ptr, slice}; @@ -24,12 +25,12 @@ pub struct DrainFilter< T, F, #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global, - const COOP_PREF: bool = true, + const CO_ALLOC_PREF: CoAllocPref = true, > where F: FnMut(&mut T) -> bool, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, { - pub(super) vec: &'a mut Vec, + pub(super) vec: &'a mut Vec, /// The index of the item that will be inspected by the next call to `next`. pub(super) idx: usize, /// The number of items that have been drained (removed) thus far. @@ -46,10 +47,10 @@ pub struct DrainFilter< pub(super) panic_flag: bool, } -impl DrainFilter<'_, T, F, A, COOP_PREF> +impl DrainFilter<'_, T, F, A, CO_ALLOC_PREF> where F: FnMut(&mut T) -> bool, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, { /// Returns a reference to the underlying allocator. #[unstable(feature = "allocator_api", issue = "32838")] @@ -115,10 +116,10 @@ where } #[unstable(feature = "drain_filter", reason = "recently added", issue = "43244")] -impl Iterator for DrainFilter<'_, T, F, A, COOP_PREF> +impl Iterator for DrainFilter<'_, T, F, A, CO_ALLOC_PREF> where F: FnMut(&mut T) -> bool, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, { type Item = T; @@ -154,25 +155,25 @@ where } #[unstable(feature = "drain_filter", reason = "recently added", issue = "43244")] -impl Drop for DrainFilter<'_, T, F, A, COOP_PREF> +impl Drop for DrainFilter<'_, T, F, A, CO_ALLOC_PREF> where F: FnMut(&mut T) -> bool, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, { fn drop(&mut self) { - struct BackshiftOnDrop<'a, 'b, T, F, A: Allocator, const COOP_PREF: bool> + struct BackshiftOnDrop<'a, 'b, T, F, A: Allocator, const CO_ALLOC_PREF: CoAllocPref> where F: FnMut(&mut T) -> bool, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, { - drain: &'b mut DrainFilter<'a, T, F, A, COOP_PREF>, + drain: &'b mut DrainFilter<'a, T, F, A, CO_ALLOC_PREF>, } - impl<'a, 'b, T, F, A: Allocator, const COOP_PREF: bool> Drop - for BackshiftOnDrop<'a, 'b, T, F, A, COOP_PREF> + impl<'a, 'b, T, F, A: Allocator, const CO_ALLOC_PREF: CoAllocPref> Drop + for BackshiftOnDrop<'a, 'b, T, F, A, CO_ALLOC_PREF> where F: FnMut(&mut T) -> bool, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, { fn drop(&mut self) { unsafe { diff --git a/library/alloc/src/vec/in_place_collect.rs b/library/alloc/src/vec/in_place_collect.rs index 56e912d53e6f6..93187df2d11d9 100644 --- a/library/alloc/src/vec/in_place_collect.rs +++ b/library/alloc/src/vec/in_place_collect.rs @@ -153,10 +153,10 @@ pub(super) trait InPlaceIterableMarker {} impl InPlaceIterableMarker for T where T: InPlaceIterable {} #[allow(unused_braces)] -impl SpecFromIter for Vec +impl SpecFromIter for Vec where I: Iterator + SourceIter + InPlaceIterableMarker, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, { default fn from_iter(mut iterator: I) -> Self { // See "Layout constraints" section in the module documentation. We rely on const diff --git a/library/alloc/src/vec/into_iter.rs b/library/alloc/src/vec/into_iter.rs index 6c08acba77706..67f7943040d65 100644 --- a/library/alloc/src/vec/into_iter.rs +++ b/library/alloc/src/vec/into_iter.rs @@ -3,6 +3,7 @@ use super::AsVecIntoIter; use crate::alloc::{Allocator, Global}; #[cfg(not(no_global_oom_handling))] use crate::collections::VecDeque; +use crate::co_alloc::CoAllocPref; use crate::raw_vec::RawVec; use core::iter::{ FusedIterator, InPlaceIterable, SourceIter, TrustedLen, TrustedRandomAccessNoCoerce, @@ -32,9 +33,9 @@ use core::{alloc, array, fmt}; pub struct IntoIter< T, #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global, - const COOP_PREF: bool = { SHORT_TERM_VEC_PREFERS_COOP!() }, + const CO_ALLOC_PREF: CoAllocPref = { SHORT_TERM_VEC_PREFERS_COOP!() }, > where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, { pub(super) buf: NonNull, pub(super) phantom: PhantomData, @@ -49,18 +50,18 @@ pub struct IntoIter< } #[stable(feature = "vec_intoiter_debug", since = "1.13.0")] -impl fmt::Debug for IntoIter +impl fmt::Debug for IntoIter where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_tuple("IntoIter").field(&self.as_slice()).finish() } } -impl IntoIter +impl IntoIter where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, { /// Returns the remaining items of this iterator as a slice. /// @@ -131,11 +132,11 @@ where // this creates less assembly self.cap = 0; self.buf = unsafe { - // @FIXME The below if COOP_PREF {..} else {..} + // @FIXME The below if CO_ALLOC_PREF {..} else {..} // branching exists, because the following fails. Otherwise we'd have a snowball effect of wide spread of where...Global... // - // NonNull::new_unchecked(RawVec::::NEW.ptr()) - if COOP_PREF { + // NonNull::new_unchecked(RawVec::::NEW.ptr()) + if CO_ALLOC_PREF { NonNull::new_unchecked(RawVec::::NEW.ptr()) } else { NonNull::new_unchecked(RawVec::::NEW.ptr()) @@ -160,7 +161,7 @@ where #[cfg(not(no_global_oom_handling))] #[inline] - pub(crate) fn into_vecdeque(self) -> VecDeque { + pub(crate) fn into_vecdeque(self) -> VecDeque { // Keep our `Drop` impl from dropping the elements and the allocator let mut this = ManuallyDrop::new(self); @@ -187,9 +188,9 @@ where } #[stable(feature = "vec_intoiter_as_ref", since = "1.46.0")] -impl AsRef<[T]> for IntoIter +impl AsRef<[T]> for IntoIter where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, { fn as_ref(&self) -> &[T] { self.as_slice() @@ -197,20 +198,20 @@ where } #[stable(feature = "rust1", since = "1.0.0")] -unsafe impl Send for IntoIter where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]: +unsafe impl Send for IntoIter where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]: { } #[stable(feature = "rust1", since = "1.0.0")] -unsafe impl Sync for IntoIter where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]: +unsafe impl Sync for IntoIter where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]: { } #[stable(feature = "rust1", since = "1.0.0")] -impl Iterator for IntoIter +impl Iterator for IntoIter where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, { type Item = T; @@ -325,9 +326,9 @@ where } #[stable(feature = "rust1", since = "1.0.0")] -impl DoubleEndedIterator for IntoIter +impl DoubleEndedIterator for IntoIter where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, { #[inline] fn next_back(&mut self) -> Option { @@ -369,9 +370,9 @@ where } #[stable(feature = "rust1", since = "1.0.0")] -impl ExactSizeIterator for IntoIter +impl ExactSizeIterator for IntoIter where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, { fn is_empty(&self) -> bool { self.ptr == self.end @@ -379,14 +380,14 @@ where } #[stable(feature = "fused", since = "1.26.0")] -impl FusedIterator for IntoIter where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]: +impl FusedIterator for IntoIter where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]: { } #[unstable(feature = "trusted_len", issue = "37572")] -unsafe impl TrustedLen for IntoIter where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]: +unsafe impl TrustedLen for IntoIter where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]: { } @@ -404,30 +405,30 @@ impl NonDrop for T {} #[unstable(issue = "none", feature = "std_internals")] // TrustedRandomAccess (without NoCoerce) must not be implemented because // subtypes/supertypes of `T` might not be `NonDrop` -unsafe impl TrustedRandomAccessNoCoerce - for IntoIter +unsafe impl TrustedRandomAccessNoCoerce + for IntoIter where T: NonDrop, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, { const MAY_HAVE_SIDE_EFFECT: bool = false; } #[cfg(not(no_global_oom_handling))] #[stable(feature = "vec_into_iter_clone", since = "1.8.0")] -impl Clone for IntoIter +impl Clone for IntoIter where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, { #[cfg(not(test))] fn clone(&self) -> Self { // @FIXME Remove the following extras - used for type checks only let slice = self.as_slice(); - let vec: crate::vec::Vec = - slice.to_vec_in::(self.alloc.deref().clone()); - let _iter: IntoIter = vec.into_iter(); + let vec: crate::vec::Vec = + slice.to_vec_in::(self.alloc.deref().clone()); + let _iter: IntoIter = vec.into_iter(); - //self.as_slice().to_vec_in::(self.alloc.deref().clone()).into_iter() + //self.as_slice().to_vec_in::(self.alloc.deref().clone()).into_iter() loop {} } #[cfg(test)] @@ -437,28 +438,28 @@ where } #[stable(feature = "rust1", since = "1.0.0")] -unsafe impl<#[may_dangle] T, A: Allocator, const COOP_PREF: bool> Drop for IntoIter +unsafe impl<#[may_dangle] T, A: Allocator, const CO_ALLOC_PREF: CoAllocPref> Drop for IntoIter where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, { fn drop(&mut self) { - struct DropGuard<'a, T, A: Allocator, const COOP_PREF: bool>( - &'a mut IntoIter, + struct DropGuard<'a, T, A: Allocator, const CO_ALLOC_PREF: CoAllocPref>( + &'a mut IntoIter, ) where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:; + [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:; - impl Drop for DropGuard<'_, T, A, COOP_PREF> + impl Drop for DropGuard<'_, T, A, CO_ALLOC_PREF> where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, { fn drop(&mut self) { unsafe { // `IntoIter::alloc` is not used anymore after this and will be dropped by RawVec let alloc = ManuallyDrop::take(&mut self.0.alloc); // RawVec handles deallocation - // @FIXME pass true instead of COOP_PREF - use e.g.: if COOP_PREF {let _ = RawVec::::from_raw_parts_in(..) } else { let _ = from_raw_parts_in_coop(...)} } - let _ = RawVec::::from_raw_parts_in( + // @FIXME pass true instead of CO_ALLOC_PREF - use e.g.: if CO_ALLOC_PREF {let _ = RawVec::::from_raw_parts_in(..) } else { let _ = from_raw_parts_in_coop(...)} } + let _ = RawVec::::from_raw_parts_in( self.0.buf.as_ptr(), self.0.cap, alloc, @@ -480,16 +481,16 @@ where // also refer to the vec::in_place_collect module documentation to get an overview #[unstable(issue = "none", feature = "inplace_iteration")] #[doc(hidden)] -unsafe impl InPlaceIterable for IntoIter where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]: +unsafe impl InPlaceIterable for IntoIter where + [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]: { } #[unstable(issue = "none", feature = "inplace_iteration")] #[doc(hidden)] -unsafe impl SourceIter for IntoIter +unsafe impl SourceIter for IntoIter where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, { type Source = Self; diff --git a/library/alloc/src/vec/mod.rs b/library/alloc/src/vec/mod.rs index 967f4333482d8..38177f5707227 100644 --- a/library/alloc/src/vec/mod.rs +++ b/library/alloc/src/vec/mod.rs @@ -73,6 +73,7 @@ use core::slice::{self, SliceIndex}; use crate::alloc::{Allocator, Global}; use crate::borrow::{Cow, ToOwned}; use crate::boxed::Box; +use crate::co_alloc::CoAllocPref; use crate::collections::TryReserveError; use crate::raw_vec::RawVec; @@ -403,11 +404,11 @@ pub struct Vec< T, #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global, //@FIXME: #[unstable(feature ="global_co_alloc_vec", issue="none")] - const COOP_PREF: bool = { CO_ALLOC_PREF_DEFAULT!() }, + const CO_ALLOC_PREF: CoAllocPref = { CO_ALLOC_PREF_DEFAULT!() }, > where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, { - buf: RawVec, + buf: RawVec, len: usize, } @@ -420,23 +421,17 @@ pub type CoVec = Vec; #[unstable(feature = "global_co_alloc_plvec", issue = "none")] pub type PlVec = Vec; -/// "Default" Vec. Either "cooperative" or not - as specified by `DEFAULT_COOP_PREF`. The -/// difference to `Vec` (used without specifying `COOP_PREF`): `DefVec` indicates that the +/// "Default" Vec. Either "cooperative" or not - as specified by `DEFAULT_CO_ALLOC_PREF`. The +/// difference to `Vec` (used without specifying `CO_ALLOC_PREF`): `DefVec` indicates that the /// author considered using `CoVec` or `PlVec`, but left it to default instead. #[unstable(feature = "global_co_alloc_defvec", issue = "none")] #[allow(unused_braces)] pub type DefVec = Vec; -/// "Weighted cooperative" Vec. Weight means how much it wants to cooperate (with the allocator). 0 -/// = always pack; u8::MAX = always cooperate (if `Global` supports it). -/// @FIXME A `pub const` threshold. -#[unstable(feature = "global_co_alloc_vec", issue = "none")] -pub type WeVec = Vec 127 }>; - impl Vec { - /*impl Vec + /*impl Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); {meta_num_slots_global!(CO_ALLOC_PREF)}]:, {*/ /// Constructs a new, empty `Vec`. /// @@ -521,11 +516,11 @@ impl Vec { //////////////////////////////////////////////////////////////////////////////// /**/ -impl Vec +impl Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); {meta_num_slots_global!(CO_ALLOC_PREF)}]:, { - /// Like new(), but it respects COOP_PREF. + /// Like new(), but it respects CO_ALLOC_PREF. #[inline] #[rustc_const_stable(feature = "const_vec_new_co", since = "1.60.0")] //@FIXME This is `rustc_const_stable`, so that String::new() can be const and can call this. #[unstable(feature = "vec_new_co", reason = "confirm_or_fix_the_function_name", issue = "none")] @@ -703,9 +698,9 @@ where } } -impl Vec +impl Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, { /// Constructs a new, empty `Vec`. /// @@ -1719,19 +1714,19 @@ where // This drop guard will be invoked when predicate or `drop` of element panicked. // It shifts unchecked elements to cover holes and `set_len` to the correct length. // In cases when predicate and `drop` never panick, it will be optimized out. - struct BackshiftOnDrop<'a, T, A: Allocator, const VEC_IS_COOP: bool = true> + struct BackshiftOnDrop<'a, T, A: Allocator, const VEC_CO_ALLOC_PREF: CoAllocPref = {CO_ALLOC_PREF_META_DEFAULT!()}> where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(VEC_IS_COOP)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(VEC_CO_ALLOC_PREF)]:, { - v: &'a mut Vec, + v: &'a mut Vec, processed_len: usize, deleted_cnt: usize, original_len: usize, } - impl Drop for BackshiftOnDrop<'_, T, A, VEC_IS_COOP> + impl Drop for BackshiftOnDrop<'_, T, A, VEC_CO_ALLOC_PREF> where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(VEC_IS_COOP)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(VEC_CO_ALLOC_PREF)]:, { fn drop(&mut self) { if self.deleted_cnt > 0 { @@ -1751,20 +1746,20 @@ where } } - let mut g = BackshiftOnDrop:: { + let mut g = BackshiftOnDrop:: { v: self, processed_len: 0, deleted_cnt: 0, original_len, }; - fn process_loop( + fn process_loop( original_len: usize, f: &mut F, - g: &mut BackshiftOnDrop<'_, T, A, VEC_IS_COOP>, + g: &mut BackshiftOnDrop<'_, T, A, VEC_CO_ALLOC_PREF>, ) where F: FnMut(&mut T) -> bool, - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(VEC_IS_COOP)]:, + [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(VEC_CO_ALLOC_PREF)]:, { while g.processed_len != original_len { // SAFETY: Unchecked element must be valid. @@ -1795,10 +1790,10 @@ where } // Stage 1: Nothing was deleted. - process_loop::(original_len, &mut f, &mut g); + process_loop::(original_len, &mut f, &mut g); // Stage 2: Some elements were deleted. - process_loop::(original_len, &mut f, &mut g); + process_loop::(original_len, &mut f, &mut g); // All item are processed. This can be optimized to `set_len` by LLVM. drop(g); @@ -1857,9 +1852,9 @@ where } /* INVARIANT: vec.len() > read >= write > write-1 >= 0 */ - struct FillGapOnDrop<'a, T, A: core::alloc::Allocator, const COOP_PREF: bool> + struct FillGapOnDrop<'a, T, A: core::alloc::Allocator, const CO_ALLOC_PREF: CoAllocPref> where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, { /* Offset of the element we want to check if it is duplicate */ read: usize, @@ -1869,13 +1864,13 @@ where write: usize, /* The Vec that would need correction if `same_bucket` panicked */ - vec: &'a mut Vec, + vec: &'a mut Vec, } - impl<'a, T, A: core::alloc::Allocator, const COOP_PREF: bool> Drop - for FillGapOnDrop<'a, T, A, COOP_PREF> + impl<'a, T, A: core::alloc::Allocator, const CO_ALLOC_PREF: CoAllocPref> Drop + for FillGapOnDrop<'a, T, A, CO_ALLOC_PREF> where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, { fn drop(&mut self) { /* This code gets executed when `same_bucket` panics */ @@ -2118,7 +2113,7 @@ where /// assert_eq!(v, &[]); /// ``` #[stable(feature = "drain", since = "1.6.0")] - pub fn drain(&mut self, range: R) -> Drain<'_, T, A, COOP_PREF> + pub fn drain(&mut self, range: R) -> Drain<'_, T, A, CO_ALLOC_PREF> where R: RangeBounds, { @@ -2469,9 +2464,9 @@ where } } -impl Vec +impl Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, { /// Resizes the `Vec` in-place so that `len` is equal to `new_len`. /// @@ -2571,9 +2566,9 @@ where } } -impl Vec<[T; N], A, COOP_PREF> +impl Vec<[T; N], A, CO_ALLOC_PREF> where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, { /// Takes a `Vec<[T; N]>` and flattens it into a `Vec`. /// @@ -2597,7 +2592,7 @@ where /// assert_eq!(flattened.pop(), Some(6)); /// ``` #[unstable(feature = "slice_flatten", issue = "95629")] - pub fn into_flattened(self) -> Vec { + pub fn into_flattened(self) -> Vec { let (ptr, len, cap, alloc) = self.into_raw_parts_with_alloc(); let (new_len, new_cap) = if T::IS_ZST { (len.checked_mul(N).expect("vec len overflow"), usize::MAX) @@ -2615,7 +2610,7 @@ where // - `new_cap` refers to the same sized allocation as `cap` because // `new_cap * size_of::()` == `cap * size_of::<[T; N]>()` // - `len` <= `cap`, so `len * N` <= `cap * N`. - unsafe { Vec::::from_raw_parts_in(ptr.cast(), new_len, new_cap, alloc) } + unsafe { Vec::::from_raw_parts_in(ptr.cast(), new_len, new_cap, alloc) } } } @@ -2635,9 +2630,9 @@ impl ExtendWith for ExtendElement { } } -impl Vec +impl Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, { #[cfg(not(no_global_oom_handling))] /// Extend the vector by `n` values, using the given generator. @@ -2670,9 +2665,9 @@ where } } -impl Vec +impl Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, { /// Removes consecutive repeated elements in the vector according to the /// [`PartialEq`] trait implementation. @@ -2709,13 +2704,13 @@ pub fn from_elem(elem: T, n: usize) -> Vec { #[doc(hidden)] #[cfg(not(no_global_oom_handling))] #[unstable(feature = "allocator_api", issue = "32838")] -pub fn from_elem_in( +pub fn from_elem_in( elem: T, n: usize, alloc: A, -) -> Vec +) -> Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, { ::from_elem(elem, n, alloc) } @@ -2728,9 +2723,9 @@ trait ExtendFromWithinSpec { unsafe fn spec_extend_from_within(&mut self, src: Range); } -impl ExtendFromWithinSpec for Vec +impl ExtendFromWithinSpec for Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, { default unsafe fn spec_extend_from_within(&mut self, src: Range) { // SAFETY: @@ -2750,9 +2745,9 @@ where } } -impl ExtendFromWithinSpec for Vec +impl ExtendFromWithinSpec for Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, { unsafe fn spec_extend_from_within(&mut self, src: Range) { let count = src.len(); @@ -2786,9 +2781,9 @@ where //////////////////////////////////////////////////////////////////////////////// #[stable(feature = "rust1", since = "1.0.0")] -impl ops::Deref for Vec +impl ops::Deref for Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, { type Target = [T]; @@ -2799,9 +2794,9 @@ where } #[stable(feature = "rust1", since = "1.0.0")] -impl ops::DerefMut for Vec +impl ops::DerefMut for Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, { #[inline] fn deref_mut(&mut self) -> &mut [T] { @@ -2811,9 +2806,9 @@ where #[cfg(not(no_global_oom_handling))] #[stable(feature = "rust1", since = "1.0.0")] -impl Clone for Vec +impl Clone for Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, { #[cfg(not(test))] fn clone(&self) -> Self { @@ -2849,9 +2844,9 @@ where /// assert_eq!(b.hash_one(v), b.hash_one(s)); /// ``` #[stable(feature = "rust1", since = "1.0.0")] -impl Hash for Vec +impl Hash for Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, { #[inline] fn hash(&self, state: &mut H) { @@ -2864,9 +2859,9 @@ where message = "vector indices are of type `usize` or ranges of `usize`", label = "vector indices are of type `usize` or ranges of `usize`" )] -impl, A: Allocator, const COOP_PREF: bool> Index for Vec +impl, A: Allocator, const CO_ALLOC_PREF: CoAllocPref> Index for Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, { type Output = I::Output; @@ -2881,10 +2876,10 @@ where message = "vector indices are of type `usize` or ranges of `usize`", label = "vector indices are of type `usize` or ranges of `usize`" )] -impl, A: Allocator, const COOP_PREF: bool> IndexMut - for Vec +impl, A: Allocator, const CO_ALLOC_PREF: CoAllocPref> IndexMut + for Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, { #[inline] fn index_mut(&mut self, index: I) -> &mut Self::Output { @@ -2895,23 +2890,23 @@ where #[cfg(not(no_global_oom_handling))] #[stable(feature = "rust1", since = "1.0.0")] #[allow(unused_braces)] -impl FromIterator for Vec +impl FromIterator for Vec where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, { #[inline] - fn from_iter>(iter: I) -> Vec { + fn from_iter>(iter: I) -> Vec { >::from_iter(iter.into_iter()) } } #[stable(feature = "rust1", since = "1.0.0")] -impl IntoIterator for Vec +impl IntoIterator for Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, { type Item = T; - type IntoIter = IntoIter; + type IntoIter = IntoIter; /// Creates a consuming iterator, that is, one that moves each value out of /// the vector (from start to end). The vector cannot be used after calling @@ -2954,9 +2949,9 @@ where } #[stable(feature = "rust1", since = "1.0.0")] -impl<'a, T, A: Allocator, const COOP_PREF: bool> IntoIterator for &'a Vec +impl<'a, T, A: Allocator, const CO_ALLOC_PREF: CoAllocPref> IntoIterator for &'a Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, { type Item = &'a T; type IntoIter = slice::Iter<'a, T>; @@ -2967,9 +2962,9 @@ where } #[stable(feature = "rust1", since = "1.0.0")] -impl<'a, T, A: Allocator, const COOP_PREF: bool> IntoIterator for &'a mut Vec +impl<'a, T, A: Allocator, const CO_ALLOC_PREF: CoAllocPref> IntoIterator for &'a mut Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, { type Item = &'a mut T; type IntoIter = slice::IterMut<'a, T>; @@ -2981,9 +2976,9 @@ where #[cfg(not(no_global_oom_handling))] #[stable(feature = "rust1", since = "1.0.0")] -impl Extend for Vec +impl Extend for Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, { #[inline] fn extend>(&mut self, iter: I) { @@ -3001,9 +2996,9 @@ where } } -impl Vec +impl Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, { // leaf method to which various SpecFrom/SpecExtend implementations delegate when // they have no further optimizations to apply @@ -3106,11 +3101,11 @@ where &mut self, range: R, replace_with: I, - ) -> Splice<'_, I::IntoIter, A, COOP_PREF> + ) -> Splice<'_, I::IntoIter, A, CO_ALLOC_PREF> where R: RangeBounds, I: IntoIterator, - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(true)]:, + [(); {crate::meta_num_slots!(A, crate::CO_ALLOC_PREF_META_YES!())}]:, { Splice { drain: self.drain(range), replace_with: replace_with.into_iter() } } @@ -3160,10 +3155,10 @@ where /// assert_eq!(odds, vec![1, 3, 5, 9, 11, 13, 15]); /// ``` #[unstable(feature = "drain_filter", reason = "recently added", issue = "43244")] - pub fn drain_filter(&mut self, filter: F) -> DrainFilter<'_, T, F, A, COOP_PREF> + pub fn drain_filter(&mut self, filter: F) -> DrainFilter<'_, T, F, A, CO_ALLOC_PREF> where F: FnMut(&mut T) -> bool, - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(true)]:, + [(); {crate::meta_num_slots!(A, crate::CO_ALLOC_PREF_META_YES!())}]:, { let old_len = self.len(); @@ -3184,10 +3179,10 @@ where /// [`copy_from_slice`]: slice::copy_from_slice #[cfg(not(no_global_oom_handling))] #[stable(feature = "extend_ref", since = "1.2.0")] -impl<'a, T: Copy + 'a, A: Allocator + 'a, const COOP_PREF: bool> Extend<&'a T> - for Vec +impl<'a, T: Copy + 'a, A: Allocator + 'a, const CO_ALLOC_PREF: CoAllocPref> Extend<&'a T> + for Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, { fn extend>(&mut self, iter: I) { self.spec_extend(iter.into_iter()) @@ -3206,9 +3201,9 @@ where /// Implements comparison of vectors, [lexicographically](core::cmp::Ord#lexicographical-comparison). #[stable(feature = "rust1", since = "1.0.0")] -impl PartialOrd for Vec +impl PartialOrd for Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, { #[inline] fn partial_cmp(&self, other: &Self) -> Option { @@ -3217,16 +3212,16 @@ where } #[stable(feature = "rust1", since = "1.0.0")] -impl Eq for Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]: +impl Eq for Vec where + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]: { } /// Implements ordering of vectors, [lexicographically](core::cmp::Ord#lexicographical-comparison). #[stable(feature = "rust1", since = "1.0.0")] -impl Ord for Vec +impl Ord for Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, { #[inline] fn cmp(&self, other: &Self) -> Ordering { @@ -3235,9 +3230,9 @@ where } #[stable(feature = "rust1", since = "1.0.0")] -unsafe impl<#[may_dangle] T, A: Allocator, const COOP_PREF: bool> Drop for Vec +unsafe impl<#[may_dangle] T, A: Allocator, const CO_ALLOC_PREF: CoAllocPref> Drop for Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, { fn drop(&mut self) { unsafe { @@ -3252,22 +3247,22 @@ where #[stable(feature = "rust1", since = "1.0.0")] #[rustc_const_unstable(feature = "const_default_impls", issue = "87864")] -impl const Default for Vec +impl const Default for Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); {meta_num_slots_global!(CO_ALLOC_PREF)}]:, { /// Creates an empty `Vec`. /// /// The vector will not allocate until elements are pushed onto it. - fn default() -> Vec { + fn default() -> Vec { Vec::new_co() } } #[stable(feature = "rust1", since = "1.0.0")] -impl fmt::Debug for Vec +impl fmt::Debug for Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fmt::Debug::fmt(&**self, f) @@ -3275,29 +3270,29 @@ where } #[stable(feature = "rust1", since = "1.0.0")] -impl AsRef> for Vec +impl AsRef> for Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, { - fn as_ref(&self) -> &Vec { + fn as_ref(&self) -> &Vec { self } } #[stable(feature = "vec_as_mut", since = "1.5.0")] -impl AsMut> for Vec +impl AsMut> for Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, { - fn as_mut(&mut self) -> &mut Vec { + fn as_mut(&mut self) -> &mut Vec { self } } #[stable(feature = "rust1", since = "1.0.0")] -impl AsRef<[T]> for Vec +impl AsRef<[T]> for Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, { fn as_ref(&self) -> &[T] { self @@ -3305,9 +3300,9 @@ where } #[stable(feature = "vec_as_mut", since = "1.5.0")] -impl AsMut<[T]> for Vec +impl AsMut<[T]> for Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, { fn as_mut(&mut self) -> &mut [T] { self @@ -3409,9 +3404,9 @@ where // note: test pulls in std, which causes errors here #[cfg(not(test))] #[stable(feature = "vec_from_box", since = "1.18.0")] -impl From> for Vec +impl From> for Vec where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, { /// Convert a boxed slice into a vector by transferring ownership of /// the existing heap allocation. @@ -3431,9 +3426,9 @@ where #[cfg(not(no_global_oom_handling))] #[cfg(not(test))] #[stable(feature = "box_from_vec", since = "1.20.0")] -impl From> for Box<[T], A> +impl From> for Box<[T], A> where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, { /// Convert a vector into a boxed slice. /// @@ -3453,7 +3448,7 @@ where /// /// assert_eq!(Box::from(vec), vec![1, 2, 3].into_boxed_slice()); /// ``` - fn from(v: Vec) -> Self { + fn from(v: Vec) -> Self { v.into_boxed_slice() } } @@ -3475,12 +3470,12 @@ impl From<&str> for Vec { } #[stable(feature = "array_try_from_vec", since = "1.48.0")] -impl TryFrom> +impl TryFrom> for [T; N] where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, { - type Error = Vec; + type Error = Vec; /// Gets the entire contents of the `Vec` as an array, /// if its size exactly matches that of the requested array. @@ -3508,7 +3503,7 @@ where /// assert_eq!(a, b' '); /// assert_eq!(b, b'd'); /// ``` - fn try_from(mut vec: Vec) -> Result<[T; N], Vec> { + fn try_from(mut vec: Vec) -> Result<[T; N], Vec> { if vec.len() != N { return Err(vec); } diff --git a/library/alloc/src/vec/partial_eq.rs b/library/alloc/src/vec/partial_eq.rs index 9abfbfd075b25..7bf6a023bc8d3 100644 --- a/library/alloc/src/vec/partial_eq.rs +++ b/library/alloc/src/vec/partial_eq.rs @@ -2,6 +2,7 @@ use crate::alloc::Allocator; #[cfg(not(no_global_oom_handling))] use crate::borrow::Cow; +use crate::co_alloc::CoAllocPref; use super::Vec; @@ -21,21 +22,21 @@ macro_rules! __impl_slice_eq1 { } } -__impl_slice_eq1! { [A1: Allocator, A2: Allocator, const COOP_PREF1: bool, const COOP_PREF2: bool] Vec, Vec, #[stable(feature = "rust1", since = "1.0.0")], [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF1)]:, [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF2)]: } -__impl_slice_eq1! { [A: Allocator, const COOP_PREF: bool] Vec, &[U], #[stable(feature = "rust1", since = "1.0.0")], [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]: } -__impl_slice_eq1! { [A: Allocator, const COOP_PREF: bool] Vec, &mut [U], #[stable(feature = "rust1", since = "1.0.0")], [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]: } -__impl_slice_eq1! { [A: Allocator, const COOP_PREF: bool] &[T], Vec, #[stable(feature = "partialeq_vec_for_ref_slice", since = "1.46.0")], [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]: } -__impl_slice_eq1! { [A: Allocator, const COOP_PREF: bool] &mut [T], Vec, #[stable(feature = "partialeq_vec_for_ref_slice", since = "1.46.0")], [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]: } -__impl_slice_eq1! { [A: Allocator, const COOP_PREF: bool] Vec, [U], #[stable(feature = "partialeq_vec_for_slice", since = "1.48.0")], [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]: } -__impl_slice_eq1! { [A: Allocator, const COOP_PREF: bool] [T], Vec, #[stable(feature = "partialeq_vec_for_slice", since = "1.48.0")], [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]: } +__impl_slice_eq1! { [A1: Allocator, A2: Allocator, const CO_ALLOC_PREF1: bool, const CO_ALLOC_PREF2: bool] Vec, Vec, #[stable(feature = "rust1", since = "1.0.0")], [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF1)]:, [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF2)]: } +__impl_slice_eq1! { [A: Allocator, const CO_ALLOC_PREF: CoAllocPref] Vec, &[U], #[stable(feature = "rust1", since = "1.0.0")], [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]: } +__impl_slice_eq1! { [A: Allocator, const CO_ALLOC_PREF: CoAllocPref] Vec, &mut [U], #[stable(feature = "rust1", since = "1.0.0")], [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]: } +__impl_slice_eq1! { [A: Allocator, const CO_ALLOC_PREF: CoAllocPref] &[T], Vec, #[stable(feature = "partialeq_vec_for_ref_slice", since = "1.46.0")], [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]: } +__impl_slice_eq1! { [A: Allocator, const CO_ALLOC_PREF: CoAllocPref] &mut [T], Vec, #[stable(feature = "partialeq_vec_for_ref_slice", since = "1.46.0")], [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]: } +__impl_slice_eq1! { [A: Allocator, const CO_ALLOC_PREF: CoAllocPref] Vec, [U], #[stable(feature = "partialeq_vec_for_slice", since = "1.48.0")], [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]: } +__impl_slice_eq1! { [A: Allocator, const CO_ALLOC_PREF: CoAllocPref] [T], Vec, #[stable(feature = "partialeq_vec_for_slice", since = "1.48.0")], [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]: } #[cfg(not(no_global_oom_handling))] -__impl_slice_eq1! { [A: Allocator, const COOP_PREF: bool] Cow<'_, [T]>, Vec, #[stable(feature = "rust1", since = "1.0.0")], T: Clone, [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]: } +__impl_slice_eq1! { [A: Allocator, const CO_ALLOC_PREF: CoAllocPref] Cow<'_, [T]>, Vec, #[stable(feature = "rust1", since = "1.0.0")], T: Clone, [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]: } #[cfg(not(no_global_oom_handling))] __impl_slice_eq1! { [] Cow<'_, [T]>, &[U], #[stable(feature = "rust1", since = "1.0.0")], T: Clone } #[cfg(not(no_global_oom_handling))] __impl_slice_eq1! { [] Cow<'_, [T]>, &mut [U], #[stable(feature = "rust1", since = "1.0.0")], T: Clone } -__impl_slice_eq1! { [A: Allocator, const COOP_PREF: bool, const N: usize] Vec, [U; N], #[stable(feature = "rust1", since = "1.0.0")], [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]: } -__impl_slice_eq1! { [A: Allocator, const COOP_PREF: bool, const N: usize] Vec, &[U; N], #[stable(feature = "rust1", since = "1.0.0")], [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]: } +__impl_slice_eq1! { [A: Allocator, const CO_ALLOC_PREF: CoAllocPref, const N: usize] Vec, [U; N], #[stable(feature = "rust1", since = "1.0.0")], [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]: } +__impl_slice_eq1! { [A: Allocator, const CO_ALLOC_PREF: CoAllocPref, const N: usize] Vec, &[U; N], #[stable(feature = "rust1", since = "1.0.0")], [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]: } // NOTE: some less important impls are omitted to reduce code bloat // FIXME(Centril): Reconsider this? diff --git a/library/alloc/src/vec/spec_extend.rs b/library/alloc/src/vec/spec_extend.rs index 99d96bcca97c1..909fd43aedff4 100644 --- a/library/alloc/src/vec/spec_extend.rs +++ b/library/alloc/src/vec/spec_extend.rs @@ -1,5 +1,6 @@ use crate::alloc::Allocator; use core::alloc; +use crate::co_alloc::CoAllocPref; use core::iter::TrustedLen; use core::slice::{self}; @@ -10,29 +11,29 @@ pub(super) trait SpecExtend { fn spec_extend(&mut self, iter: I); } -impl SpecExtend for Vec +impl SpecExtend for Vec where I: Iterator, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, { default fn spec_extend(&mut self, iter: I) { self.extend_desugared(iter) } } -impl SpecExtend for Vec +impl SpecExtend for Vec where I: TrustedLen, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, { default fn spec_extend(&mut self, iterator: I) { self.extend_trusted(iterator) } } -impl SpecExtend> for Vec +impl SpecExtend> for Vec where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, { fn spec_extend(&mut self, mut iterator: IntoIter) { unsafe { @@ -42,23 +43,23 @@ where } } -impl<'a, T: 'a, I, A: Allocator + 'a, const COOP_PREF: bool> SpecExtend<&'a T, I> - for Vec +impl<'a, T: 'a, I, A: Allocator + 'a, const CO_ALLOC_PREF: CoAllocPref> SpecExtend<&'a T, I> + for Vec where I: Iterator, T: Clone, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, { default fn spec_extend(&mut self, iterator: I) { self.spec_extend(iterator.cloned()) } } -impl<'a, T: 'a, A: Allocator + 'a, const COOP_PREF: bool> SpecExtend<&'a T, slice::Iter<'a, T>> - for Vec +impl<'a, T: 'a, A: Allocator + 'a, const CO_ALLOC_PREF: CoAllocPref> SpecExtend<&'a T, slice::Iter<'a, T>> + for Vec where T: Copy, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, { fn spec_extend(&mut self, iterator: slice::Iter<'a, T>) { let slice = iterator.as_slice(); diff --git a/library/alloc/src/vec/spec_from_elem.rs b/library/alloc/src/vec/spec_from_elem.rs index 9ec9463160ed5..ce10137bf9ccc 100644 --- a/library/alloc/src/vec/spec_from_elem.rs +++ b/library/alloc/src/vec/spec_from_elem.rs @@ -1,6 +1,7 @@ use core::ptr; use crate::alloc::Allocator; +use crate::co_alloc::CoAllocPref; use crate::raw_vec::RawVec; use core::alloc; @@ -8,23 +9,23 @@ use super::{ExtendElement, IsZero, Vec}; // Specialization trait used for Vec::from_elem pub(super) trait SpecFromElem: Sized { - fn from_elem( + fn from_elem( elem: Self, n: usize, alloc: A, - ) -> Vec + ) -> Vec where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:; + [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:; } impl SpecFromElem for T { - default fn from_elem( + default fn from_elem( elem: Self, n: usize, alloc: A, - ) -> Vec + ) -> Vec where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, { let mut v = Vec::with_capacity_in(n, alloc); v.extend_with(n, ExtendElement(elem)); @@ -34,13 +35,13 @@ impl SpecFromElem for T { impl SpecFromElem for T { #[inline] - default fn from_elem( + default fn from_elem( elem: T, n: usize, alloc: A, - ) -> Vec + ) -> Vec where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, { if elem.is_zero() { return Vec { buf: RawVec::with_capacity_zeroed_in(n, alloc), len: n }; @@ -53,13 +54,13 @@ impl SpecFromElem for T { impl SpecFromElem for i8 { #[inline] - fn from_elem( + fn from_elem( elem: i8, n: usize, alloc: A, - ) -> Vec + ) -> Vec where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, { if elem == 0 { return Vec { buf: RawVec::with_capacity_zeroed_in(n, alloc), len: n }; @@ -75,13 +76,13 @@ impl SpecFromElem for i8 { impl SpecFromElem for u8 { #[inline] - fn from_elem( + fn from_elem( elem: u8, n: usize, alloc: A, - ) -> Vec + ) -> Vec where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, { if elem == 0 { return Vec { buf: RawVec::with_capacity_zeroed_in(n, alloc), len: n }; diff --git a/library/alloc/src/vec/spec_from_iter.rs b/library/alloc/src/vec/spec_from_iter.rs index 7b8ec9c0bc347..ae4fe914f8d53 100644 --- a/library/alloc/src/vec/spec_from_iter.rs +++ b/library/alloc/src/vec/spec_from_iter.rs @@ -1,4 +1,5 @@ use crate::alloc::Global; +use crate::co_alloc::CoAllocPref; use core::alloc; use core::mem::ManuallyDrop; use core::ptr::{self}; @@ -28,10 +29,10 @@ pub(super) trait SpecFromIter { } #[allow(unused_braces)] -impl SpecFromIter for Vec +impl SpecFromIter for Vec where I: Iterator, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, { default fn from_iter(iterator: I) -> Self { SpecFromIterNested::from_iter(iterator) @@ -39,9 +40,9 @@ where } #[allow(unused_braces)] -impl SpecFromIter> for Vec +impl SpecFromIter> for Vec where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, { fn from_iter(iterator: IntoIter) -> Self { // A common case is passing a vector into a function which immediately @@ -63,7 +64,7 @@ where } } - let mut vec = Vec::::new_co(); + let mut vec = Vec::::new_co(); // must delegate to spec_extend() since extend() itself delegates // to spec_from for empty Vecs vec.spec_extend(iterator); diff --git a/library/alloc/src/vec/spec_from_iter_nested.rs b/library/alloc/src/vec/spec_from_iter_nested.rs index ea96e23025fd1..8ad562a854163 100644 --- a/library/alloc/src/vec/spec_from_iter_nested.rs +++ b/library/alloc/src/vec/spec_from_iter_nested.rs @@ -17,10 +17,10 @@ pub(super) trait SpecFromIterNested { } #[allow(unused_braces)] -impl SpecFromIterNested for Vec +impl SpecFromIterNested for Vec where I: Iterator, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, { default fn from_iter(mut iterator: I) -> Self { // Unroll the first iteration, as the vector is going to be @@ -45,7 +45,7 @@ where }; // must delegate to spec_extend() since extend() itself delegates // to spec_from for empty Vecs - as SpecExtend>::spec_extend(&mut vector, iterator); + as SpecExtend>::spec_extend(&mut vector, iterator); vector } } diff --git a/library/alloc/src/vec/splice.rs b/library/alloc/src/vec/splice.rs index c2cbff33e4b51..e61f0d91ea4ac 100644 --- a/library/alloc/src/vec/splice.rs +++ b/library/alloc/src/vec/splice.rs @@ -1,5 +1,6 @@ use crate::alloc::{Allocator, Global}; use core::alloc; +use crate::co_alloc::CoAllocPref; use core::ptr::{self}; use core::slice::{self}; @@ -23,18 +24,18 @@ pub struct Splice< 'a, I: Iterator + 'a, #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator + 'a = Global, - const COOP_PREF: bool = false, + const CO_ALLOC_PREF: CoAllocPref = false, > where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, { - pub(super) drain: Drain<'a, I::Item, A, COOP_PREF>, + pub(super) drain: Drain<'a, I::Item, A, CO_ALLOC_PREF>, pub(super) replace_with: I, } #[stable(feature = "vec_splice", since = "1.21.0")] -impl Iterator for Splice<'_, I, A, COOP_PREF> +impl Iterator for Splice<'_, I, A, CO_ALLOC_PREF> where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, { type Item = I::Item; @@ -48,10 +49,10 @@ where } #[stable(feature = "vec_splice", since = "1.21.0")] -impl DoubleEndedIterator - for Splice<'_, I, A, COOP_PREF> +impl DoubleEndedIterator + for Splice<'_, I, A, CO_ALLOC_PREF> where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, { fn next_back(&mut self) -> Option { self.drain.next_back() @@ -59,17 +60,17 @@ where } #[stable(feature = "vec_splice", since = "1.21.0")] -impl ExactSizeIterator - for Splice<'_, I, A, COOP_PREF> +impl ExactSizeIterator + for Splice<'_, I, A, CO_ALLOC_PREF> where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, { } #[stable(feature = "vec_splice", since = "1.21.0")] -impl Drop for Splice<'_, I, A, COOP_PREF> +impl Drop for Splice<'_, I, A, CO_ALLOC_PREF> where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, { fn drop(&mut self) { self.drain.by_ref().for_each(drop); @@ -117,9 +118,9 @@ where } /// Private helper methods for `Splice::drop` -impl Drain<'_, T, A, COOP_PREF> +impl Drain<'_, T, A, CO_ALLOC_PREF> where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, { /// The range from `self.vec.len` to `self.tail_start` contains elements /// that have been moved out. diff --git a/library/core/src/alloc/mod.rs b/library/core/src/alloc/mod.rs index fab6c29583496..5930b72fa0fa8 100644 --- a/library/core/src/alloc/mod.rs +++ b/library/core/src/alloc/mod.rs @@ -79,16 +79,6 @@ macro_rules! SHORT_TERM_VEC_PREFERS_COOP { #[unstable(feature = "global_co_alloc_meta", issue = "none")] pub type SliceAndMetaResult = Result, AllocError>; -// @FIXME REMOVE -/// Return 0 or 1, indicating whether to use coallocation metadata or not. Param `coop_preferred` - -/// if false, then this returns `0`, regardless of whether allocator `A` is cooperative. -#[unstable(feature = "global_co_alloc", issue = "none")] -pub const fn co_alloc_metadata_num_slots_with_preference( - coop_preferred: bool, -) -> usize { - if coop_preferred { A::CO_ALLOC_META_NUM_SLOTS as usize } else { 0 } -} - #[unstable(feature = "global_co_alloc_meta", issue = "none")] pub trait CoAllocMetaBase: Clone + Copy { /// NOT for public use. This MAY BE REMOVED or CHANGED. diff --git a/library/proc_macro/src/bridge/mod.rs b/library/proc_macro/src/bridge/mod.rs index 3020be3cb08cd..a20467d90b3a9 100644 --- a/library/proc_macro/src/bridge/mod.rs +++ b/library/proc_macro/src/bridge/mod.rs @@ -252,14 +252,14 @@ impl<'a, T, M> Unmark for &'a mut Marked { } } -impl Mark for Vec { +impl Mark for Vec { type Unmarked = Vec; fn mark(unmarked: Self::Unmarked) -> Self { // Should be a no-op due to std's in-place collect optimizations. unmarked.into_iter().map(T::mark).collect() } } -impl Unmark for Vec { +impl Unmark for Vec { type Unmarked = Vec; fn unmark(self) -> Self::Unmarked { // Should be a no-op due to std's in-place collect optimizations. diff --git a/library/proc_macro/src/bridge/rpc.rs b/library/proc_macro/src/bridge/rpc.rs index aef89f5f94bf6..90be2a9ed26c4 100644 --- a/library/proc_macro/src/bridge/rpc.rs +++ b/library/proc_macro/src/bridge/rpc.rs @@ -6,7 +6,7 @@ use std::num::NonZeroU32; use std::str; //use std::alloc::Global; use alloc::alloc::Global; -use alloc::DEFAULT_COOP_PREF; +use alloc::DEFAULT_CO_ALLOC_PREF; pub(super) type Writer = super::buffer::Buffer; @@ -227,7 +227,7 @@ impl DecodeMut<'_, '_, S> for String { } } -impl> Encode for Vec { +impl> Encode for Vec { fn encode(self, w: &mut Writer, s: &mut S) { self.len().encode(w, s); for x in self { @@ -237,7 +237,7 @@ impl> Encode for Vec { } impl<'a, S, T: for<'s> DecodeMut<'a, 's, S>> DecodeMut<'a, '_, S> - for Vec + for Vec { fn decode(r: &mut Reader<'a>, s: &mut S) -> Self { let len = usize::decode(r, s); diff --git a/library/proc_macro/src/diagnostic.rs b/library/proc_macro/src/diagnostic.rs index 96796757c895d..5738938937cc3 100644 --- a/library/proc_macro/src/diagnostic.rs +++ b/library/proc_macro/src/diagnostic.rs @@ -30,7 +30,7 @@ impl MultiSpan for Span { } #[unstable(feature = "proc_macro_diagnostic", issue = "54140")] -impl MultiSpan for Vec { +impl MultiSpan for Vec { fn into_spans(self) -> Vec { self } diff --git a/library/std/src/io/cursor.rs b/library/std/src/io/cursor.rs index 76da93d547f0e..d7aee680d1186 100644 --- a/library/std/src/io/cursor.rs +++ b/library/std/src/io/cursor.rs @@ -398,13 +398,13 @@ fn slice_write_vectored( } /// Reserves the required space, and pads the vec with 0s if necessary. -fn reserve_and_pad( +fn reserve_and_pad( pos_mut: &mut u64, - vec: &mut Vec, + vec: &mut Vec, buf_len: usize, ) -> io::Result where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, { let pos: usize = (*pos_mut).try_into().map_err(|_| { io::const_io_error!( @@ -444,14 +444,14 @@ where /// Writes the slice to the vec without allocating /// # Safety: vec must have buf.len() spare capacity -unsafe fn vec_write_unchecked( +unsafe fn vec_write_unchecked( pos: usize, - vec: &mut Vec, + vec: &mut Vec, buf: &[u8], ) -> usize where A: Allocator, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, { debug_assert!(vec.capacity() >= pos + buf.len()); vec.as_mut_ptr().add(pos).copy_from(buf.as_ptr(), buf.len()); @@ -467,14 +467,14 @@ where /// This also allows for the vec body to be empty, but with a position of N. /// This means that [`Write`] will pad the vec with 0 initially, /// before writing anything from that point -fn vec_write( +fn vec_write( pos_mut: &mut u64, - vec: &mut Vec, + vec: &mut Vec, buf: &[u8], ) -> io::Result where A: Allocator, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, { let buf_len = buf.len(); let mut pos = reserve_and_pad(pos_mut, vec, buf_len)?; @@ -503,14 +503,14 @@ where /// This also allows for the vec body to be empty, but with a position of N. /// This means that [`Write`] will pad the vec with 0 initially, /// before writing anything from that point -fn vec_write_vectored( +fn vec_write_vectored( pos_mut: &mut u64, - vec: &mut Vec, + vec: &mut Vec, bufs: &[IoSlice<'_>], ) -> io::Result where A: Allocator, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, { // For safety reasons, we don't want this sum to overflow ever. // If this saturates, the reserve should panic to avoid any unsound writing. @@ -558,10 +558,10 @@ impl Write for Cursor<&mut [u8]> { } #[stable(feature = "cursor_mut_vec", since = "1.25.0")] -impl Write for Cursor<&mut Vec> +impl Write for Cursor<&mut Vec> where A: Allocator, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, { fn write(&mut self, buf: &[u8]) -> io::Result { vec_write(&mut self.pos, self.inner, buf) @@ -583,10 +583,10 @@ where } #[stable(feature = "rust1", since = "1.0.0")] -impl Write for Cursor> +impl Write for Cursor> where A: Allocator, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, { fn write(&mut self, buf: &[u8]) -> io::Result { vec_write(&mut self.pos, &mut self.inner, buf) diff --git a/library/std/src/io/impls.rs b/library/std/src/io/impls.rs index f027b24e43789..6e07869e3d075 100644 --- a/library/std/src/io/impls.rs +++ b/library/std/src/io/impls.rs @@ -378,9 +378,9 @@ impl Write for &mut [u8] { /// Write is implemented for `Vec` by appending to the vector. /// The vector will grow as needed. #[stable(feature = "rust1", since = "1.0.0")] -impl Write for Vec +impl Write for Vec where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(COOP_PREF)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, { #[inline] fn write(&mut self, buf: &[u8]) -> io::Result { @@ -417,9 +417,9 @@ where /// Read is implemented for `VecDeque` by consuming bytes from the front of the `VecDeque`. #[stable(feature = "vecdeque_read_write", since = "1.63.0")] -impl Read for VecDeque +impl Read for VecDeque where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(_COOP_PREF)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(_CO_ALLOC_PREF)]:, { /// Fill `buf` with the contents of the "front" slice as returned by /// [`as_slices`][`VecDeque::as_slices`]. If the contained byte slices of the `VecDeque` are @@ -444,9 +444,9 @@ where /// Write is implemented for `VecDeque` by appending to the `VecDeque`, growing it as needed. #[stable(feature = "vecdeque_read_write", since = "1.63.0")] -impl Write for VecDeque +impl Write for VecDeque where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(_COOP_PREF)]:, + [(); alloc::co_alloc_metadata_num_slots_with_preference::(_CO_ALLOC_PREF)]:, { #[inline] fn write(&mut self, buf: &[u8]) -> io::Result { From 4aea4f9d0ed021785e9d25e19c8074a812d887f5 Mon Sep 17 00:00:00 2001 From: Peter Kehl Date: Sun, 29 Jan 2023 12:32:58 -0800 Subject: [PATCH 092/118] CoAlloc: Using config + transformation macros in ::alloc. ICE! --- library/alloc/src/boxed.rs | 3 + .../alloc/src/collections/binary_heap/mod.rs | 7 +- .../alloc/src/collections/vec_deque/drain.rs | 37 +++++--- .../src/collections/vec_deque/into_iter.rs | 12 ++- .../alloc/src/collections/vec_deque/mod.rs | 90 ++++++++++++------- .../src/collections/vec_deque/spec_extend.rs | 18 ++-- .../collections/vec_deque/spec_from_iter.rs | 10 ++- library/alloc/src/lib.rs | 1 - library/alloc/src/macros.rs | 12 ++- library/alloc/src/raw_vec.rs | 23 +++-- library/alloc/src/rc.rs | 3 + library/alloc/src/slice.rs | 15 +++- library/alloc/src/str.rs | 4 +- library/alloc/src/vec/drain.rs | 42 +++++---- library/alloc/src/vec/drain_filter.rs | 22 +++-- library/alloc/src/vec/in_place_collect.rs | 4 +- library/alloc/src/vec/into_iter.rs | 55 +++++++----- library/alloc/src/vec/mod.rs | 49 ++++++++-- library/alloc/src/vec/partial_eq.rs | 3 +- library/alloc/src/vec/spec_extend.rs | 16 ++-- library/alloc/src/vec/spec_from_elem.rs | 16 ++-- library/alloc/src/vec/spec_from_iter.rs | 5 +- .../alloc/src/vec/spec_from_iter_nested.rs | 4 +- library/alloc/src/vec/splice.rs | 15 ++-- library/core/src/alloc/mod.rs | 10 --- 25 files changed, 317 insertions(+), 159 deletions(-) diff --git a/library/alloc/src/boxed.rs b/library/alloc/src/boxed.rs index 1128b21b24735..6f6919d56c63c 100644 --- a/library/alloc/src/boxed.rs +++ b/library/alloc/src/boxed.rs @@ -748,6 +748,7 @@ impl Box<[T]> { } } +#[allow(unused_braces)] impl Box<[T], A> where [(); {crate::meta_num_slots!(A, crate::CO_ALLOC_PREF_META_NO!())}]:, @@ -1680,6 +1681,7 @@ impl TryFrom> for Box<[T; N]> { #[cfg(not(no_global_oom_handling))] #[stable(feature = "boxed_array_try_from_vec", since = "1.66.0")] +#[allow(unused_braces)] impl TryFrom> for Box<[T; N]> where [(); {meta_num_slots_global!(CO_ALLOC_PREF)}]:, @@ -2041,6 +2043,7 @@ impl FromIterator for Box<[I]> { #[cfg(not(no_global_oom_handling))] #[stable(feature = "box_slice_clone", since = "1.3.0")] +#[allow(unused_braces)] impl Clone for Box<[T], A> where [(); {crate::meta_num_slots!(A, crate::CO_ALLOC_PREF_META_NO!())}]:, diff --git a/library/alloc/src/collections/binary_heap/mod.rs b/library/alloc/src/collections/binary_heap/mod.rs index 183d9df60cc5f..23b029219ffe3 100644 --- a/library/alloc/src/collections/binary_heap/mod.rs +++ b/library/alloc/src/collections/binary_heap/mod.rs @@ -1246,7 +1246,7 @@ impl BinaryHeap { #[inline] #[stable(feature = "drain", since = "1.6.0")] #[allow(unused_braces)] - pub fn drain(&mut self) -> Drain<'_, T, { SHORT_TERM_VEC_PREFERS_COOP!() }> { + pub fn drain(&mut self) -> Drain<'_, T, { SHORT_TERM_VEC_CO_ALLOC_PREF!() }> { Drain { iter: self.data.drain(..) } } @@ -1526,6 +1526,7 @@ unsafe impl TrustedLen for IntoIterSorted {} /// [`drain`]: BinaryHeap::drain #[stable(feature = "drain", since = "1.6.0")] #[derive(Debug)] +#[allow(unused_braces)] pub struct Drain<'a, T: 'a, const CO_ALLOC_PREF: CoAllocPref> where [(); {meta_num_slots_global!(CO_ALLOC_PREF)}]:, @@ -1534,6 +1535,7 @@ where } #[stable(feature = "drain", since = "1.6.0")] +#[allow(unused_braces)] impl Iterator for Drain<'_, T, CO_ALLOC_PREF> where [(); {meta_num_slots_global!(CO_ALLOC_PREF)}]:, @@ -1552,6 +1554,7 @@ where } #[stable(feature = "drain", since = "1.6.0")] +#[allow(unused_braces)] impl DoubleEndedIterator for Drain<'_, T, CO_ALLOC_PREF> where [(); {meta_num_slots_global!(CO_ALLOC_PREF)}]:, @@ -1563,6 +1566,7 @@ where } #[stable(feature = "drain", since = "1.6.0")] +#[allow(unused_braces)] impl ExactSizeIterator for Drain<'_, T, CO_ALLOC_PREF> where [(); {meta_num_slots_global!(CO_ALLOC_PREF)}]:, @@ -1573,6 +1577,7 @@ where } #[stable(feature = "fused", since = "1.26.0")] +#[allow(unused_braces)] impl FusedIterator for Drain<'_, T, CO_ALLOC_PREF> where [(); {meta_num_slots_global!(CO_ALLOC_PREF)}]: { diff --git a/library/alloc/src/collections/vec_deque/drain.rs b/library/alloc/src/collections/vec_deque/drain.rs index 356668dff8ffc..dd05aa0422506 100644 --- a/library/alloc/src/collections/vec_deque/drain.rs +++ b/library/alloc/src/collections/vec_deque/drain.rs @@ -3,7 +3,7 @@ use crate::co_alloc::CoAllocPref; use core::marker::PhantomData; use core::mem::{self, SizedTypeProperties}; use core::ptr::NonNull; -use core::{alloc, fmt, ptr}; +use core::{fmt, ptr}; use crate::alloc::{Allocator, Global}; @@ -21,9 +21,9 @@ pub struct Drain< 'a, T: 'a, #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global, - const CO_ALLOC_PREF: CoAllocPref = { SHORT_TERM_VEC_PREFERS_COOP!() }, + const CO_ALLOC_PREF: CoAllocPref = { SHORT_TERM_VEC_CO_ALLOC_PREF!() }, > where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, { // We can't just use a &mut VecDeque, as that would make Drain invariant over T // and we want it to be covariant instead @@ -39,9 +39,10 @@ pub struct Drain< _marker: PhantomData<&'a T>, } +#[allow(unused_braces)] impl<'a, T, A: Allocator, const CO_ALLOC_PREF: CoAllocPref> Drain<'a, T, A, CO_ALLOC_PREF> where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, { pub(super) unsafe fn new( deque: &'a mut VecDeque, @@ -96,9 +97,10 @@ where } #[stable(feature = "collection_debug", since = "1.17.0")] +#[allow(unused_braces)] impl fmt::Debug for Drain<'_, T, A, CO_ALLOC_PREF> where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_tuple("Drain") @@ -111,31 +113,34 @@ where } #[stable(feature = "drain", since = "1.6.0")] +#[allow(unused_braces)] unsafe impl Sync for Drain<'_, T, A, CO_ALLOC_PREF> where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]: + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]: { } #[stable(feature = "drain", since = "1.6.0")] +#[allow(unused_braces)] unsafe impl Send for Drain<'_, T, A, CO_ALLOC_PREF> where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]: + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]: { } #[stable(feature = "drain", since = "1.6.0")] +#[allow(unused_braces)] impl Drop for Drain<'_, T, A, CO_ALLOC_PREF> where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, { fn drop(&mut self) { struct DropGuard<'r, 'a, T, A: Allocator, const CO_ALLOC_PREF: CoAllocPref>( &'r mut Drain<'a, T, A, CO_ALLOC_PREF>, ) where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:; + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:; impl<'r, 'a, T, A: Allocator, const CO_ALLOC_PREF: CoAllocPref> Drop for DropGuard<'r, 'a, T, A, CO_ALLOC_PREF> where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, { fn drop(&mut self) { if self.0.remaining != 0 { @@ -217,9 +222,10 @@ where } #[stable(feature = "drain", since = "1.6.0")] +#[allow(unused_braces)] impl Iterator for Drain<'_, T, A, CO_ALLOC_PREF> where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, { type Item = T; @@ -242,9 +248,10 @@ where } #[stable(feature = "drain", since = "1.6.0")] +#[allow(unused_braces)] impl DoubleEndedIterator for Drain<'_, T, A, CO_ALLOC_PREF> where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, { #[inline] fn next_back(&mut self) -> Option { @@ -258,13 +265,15 @@ where } #[stable(feature = "drain", since = "1.6.0")] +#[allow(unused_braces)] impl ExactSizeIterator for Drain<'_, T, A, CO_ALLOC_PREF> where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]: + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]: { } #[stable(feature = "fused", since = "1.26.0")] +#[allow(unused_braces)] impl FusedIterator for Drain<'_, T, A, CO_ALLOC_PREF> where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]: + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]: { } diff --git a/library/alloc/src/collections/vec_deque/into_iter.rs b/library/alloc/src/collections/vec_deque/into_iter.rs index 99b73054ff9db..3b6d037c95576 100644 --- a/library/alloc/src/collections/vec_deque/into_iter.rs +++ b/library/alloc/src/collections/vec_deque/into_iter.rs @@ -14,16 +14,18 @@ use super::VecDeque; /// [`IntoIterator`]: core::iter::IntoIterator #[derive(Clone)] #[stable(feature = "rust1", since = "1.0.0")] +#[allow(unused_braces)] pub struct IntoIter< T, #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global, - const CO_ALLOC_PREF: CoAllocPref = true, + const CO_ALLOC_PREF: CoAllocPref = {CO_ALLOC_PREF_DEFAULT!()}, > where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, { inner: VecDeque, } +#[allow(unused_braces)] impl IntoIter where [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, @@ -38,6 +40,7 @@ where } #[stable(feature = "collection_debug", since = "1.17.0")] +#[allow(unused_braces)] impl fmt::Debug for IntoIter where [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, @@ -48,6 +51,7 @@ where } #[stable(feature = "rust1", since = "1.0.0")] +#[allow(unused_braces)] impl Iterator for IntoIter where [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, @@ -187,6 +191,7 @@ where } #[stable(feature = "rust1", since = "1.0.0")] +#[allow(unused_braces)] impl DoubleEndedIterator for IntoIter where [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, @@ -260,6 +265,7 @@ where } #[stable(feature = "rust1", since = "1.0.0")] +#[allow(unused_braces)] impl ExactSizeIterator for IntoIter where [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, @@ -271,12 +277,14 @@ where } #[stable(feature = "fused", since = "1.26.0")] +#[allow(unused_braces)] impl FusedIterator for IntoIter where [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]: { } #[unstable(feature = "trusted_len", issue = "37572")] +#[allow(unused_braces)] unsafe impl TrustedLen for IntoIter where [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]: { diff --git a/library/alloc/src/collections/vec_deque/mod.rs b/library/alloc/src/collections/vec_deque/mod.rs index e130d3da49665..229c3261f63d9 100644 --- a/library/alloc/src/collections/vec_deque/mod.rs +++ b/library/alloc/src/collections/vec_deque/mod.rs @@ -8,7 +8,6 @@ #![feature(global_co_alloc)] #![stable(feature = "rust1", since = "1.0.0")] use crate::CO_ALLOC_PREF_DEFAULT; -use core::alloc; use core::cmp::{self, Ordering}; use core::fmt; use core::hash::{Hash, Hasher}; @@ -100,7 +99,7 @@ pub struct VecDeque< #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global, const CO_ALLOC_PREF: CoAllocPref = { CO_ALLOC_PREF_DEFAULT!() }, > where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, { // `self[0]`, if it exists, is `buf[head]`. // `head < buf.capacity()`, unless `buf.capacity() == 0` when `head == 0`. @@ -113,9 +112,10 @@ pub struct VecDeque< } #[stable(feature = "rust1", since = "1.0.0")] +#[allow(unused_braces)] impl Clone for VecDeque where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, { fn clone(&self) -> Self { let mut deq = Self::with_capacity_in(self.len(), self.allocator().clone()); @@ -130,9 +130,10 @@ where } #[stable(feature = "rust1", since = "1.0.0")] +#[allow(unused_braces)] unsafe impl<#[may_dangle] T, A: Allocator, const CO_ALLOC_PREF: CoAllocPref> Drop for VecDeque where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, { fn drop(&mut self) { /// Runs the destructor for all items in the slice when it gets dropped (normally or @@ -158,6 +159,7 @@ where } #[stable(feature = "rust1", since = "1.0.0")] +#[allow(unused_braces)] impl Default for VecDeque where [(); {meta_num_slots_global!(CO_ALLOC_PREF)}]:, @@ -169,9 +171,10 @@ where } } +#[allow(unused_braces)] impl VecDeque where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, { /// Marginally more convenient #[inline] @@ -463,15 +466,16 @@ where ) -> usize { struct Guard<'a, T, A: Allocator, const CO_ALLOC_PREF: CoAllocPref> where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, { deque: &'a mut VecDeque, written: usize, } + #[allow(unused_braces)] impl<'a, T, A: Allocator, const CO_ALLOC_PREF: CoAllocPref> Drop for Guard<'a, T, A, CO_ALLOC_PREF> where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, { fn drop(&mut self) { self.deque.len += self.written; @@ -550,10 +554,11 @@ where } } +#[allow(unused_braces)] impl VecDeque where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, + [(); {crate::meta_num_slots_global!(CO_ALLOC_PREF)}]:, { /// Creates an empty deque. /// @@ -570,7 +575,7 @@ where #[must_use] pub const fn new() -> VecDeque where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, + [(); {crate::meta_num_slots_global!(CO_ALLOC_PREF)}]:, { // FIXME: This should just be `VecDeque::new_in(Global)` once that hits stable. VecDeque { head: 0, len: 0, buf: RawVec::NEW } @@ -593,9 +598,10 @@ where } } +#[allow(unused_braces)] impl VecDeque where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, { /// Creates an empty deque. /// @@ -2631,9 +2637,10 @@ where } } +#[allow(unused_braces)] impl VecDeque where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, { /// Modifies the deque in-place so that `len()` is equal to new_len, /// either by removing excess elements from the back or by appending clones of `value` @@ -2678,10 +2685,11 @@ fn wrap_index(logical_index: usize, capacity: usize) -> usize { if logical_index >= capacity { logical_index - capacity } else { logical_index } } +#[allow(unused_braces)] #[stable(feature = "rust1", since = "1.0.0")] impl PartialEq for VecDeque where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, { fn eq(&self, other: &Self) -> bool { if self.len != other.len() { @@ -2720,9 +2728,10 @@ where } } +#[allow(unused_braces)] #[stable(feature = "rust1", since = "1.0.0")] impl Eq for VecDeque where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]: + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]: { } @@ -2734,9 +2743,10 @@ __impl_slice_eq1! { [const N: usize] VecDeque, &[U; N], } __impl_slice_eq1! { [const N: usize] VecDeque, &mut [U; N], } #[stable(feature = "rust1", since = "1.0.0")] +#[allow(unused_braces)] impl PartialOrd for VecDeque where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, { fn partial_cmp(&self, other: &Self) -> Option { self.iter().partial_cmp(other.iter()) @@ -2744,9 +2754,10 @@ where } #[stable(feature = "rust1", since = "1.0.0")] +#[allow(unused_braces)] impl Ord for VecDeque where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, { #[inline] fn cmp(&self, other: &Self) -> Ordering { @@ -2755,9 +2766,10 @@ where } #[stable(feature = "rust1", since = "1.0.0")] +#[allow(unused_braces)] impl Hash for VecDeque where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, { fn hash(&self, state: &mut H) { state.write_length_prefix(self.len); @@ -2772,9 +2784,10 @@ where } #[stable(feature = "rust1", since = "1.0.0")] +#[allow(unused_braces)] impl Index for VecDeque where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, { type Output = T; @@ -2785,9 +2798,10 @@ where } #[stable(feature = "rust1", since = "1.0.0")] +#[allow(unused_braces)] impl IndexMut for VecDeque where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, { #[inline] fn index_mut(&mut self, index: usize) -> &mut T { @@ -2796,9 +2810,10 @@ where } #[stable(feature = "rust1", since = "1.0.0")] +#[allow(unused_braces)] impl FromIterator for VecDeque where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, + [(); {crate::meta_num_slots_global!(CO_ALLOC_PREF)}]:, { fn from_iter>(iter: I) -> VecDeque { SpecFromIter::spec_from_iter(iter.into_iter()) @@ -2806,9 +2821,10 @@ where } #[stable(feature = "rust1", since = "1.0.0")] +#[allow(unused_braces)] impl IntoIterator for VecDeque where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, { type Item = T; type IntoIter = IntoIter; @@ -2821,9 +2837,10 @@ where } #[stable(feature = "rust1", since = "1.0.0")] +#[allow(unused_braces)] impl<'a, T, A: Allocator, const CO_ALLOC_PREF: CoAllocPref> IntoIterator for &'a VecDeque where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, { type Item = &'a T; type IntoIter = Iter<'a, T>; @@ -2834,9 +2851,10 @@ where } #[stable(feature = "rust1", since = "1.0.0")] +#[allow(unused_braces)] impl<'a, T, A: Allocator, const CO_ALLOC_PREF: CoAllocPref> IntoIterator for &'a mut VecDeque where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, { type Item = &'a mut T; type IntoIter = IterMut<'a, T>; @@ -2847,9 +2865,10 @@ where } #[stable(feature = "rust1", since = "1.0.0")] +#[allow(unused_braces)] impl Extend for VecDeque where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, { fn extend>(&mut self, iter: I) { >::spec_extend(self, iter.into_iter()); @@ -2867,10 +2886,11 @@ where } #[stable(feature = "extend_ref", since = "1.2.0")] +#[allow(unused_braces)] impl<'a, T: 'a + Copy, A: Allocator, const CO_ALLOC_PREF: CoAllocPref> Extend<&'a T> for VecDeque where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, { fn extend>(&mut self, iter: I) { self.spec_extend(iter.into_iter()); @@ -2888,9 +2908,10 @@ where } #[stable(feature = "rust1", since = "1.0.0")] +#[allow(unused_braces)] impl fmt::Debug for VecDeque where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_list().entries(self.iter()).finish() @@ -2898,11 +2919,12 @@ where } #[stable(feature = "vecdeque_vec_conversions", since = "1.10.0")] -impl +#[allow(unused_braces)] +impl From> for VecDeque where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(OTHER_CO_ALLOC_PREF)]:, + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, + [(); {crate::meta_num_slots!(A, OTHER_CO_ALLOC_PREF)}]:, { /// Turn a [`Vec`] into a [`VecDeque`]. /// @@ -2924,11 +2946,12 @@ where } #[stable(feature = "vecdeque_vec_conversions", since = "1.10.0")] -impl +#[allow(unused_braces)] +impl From> for Vec where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(VECDEQUE_CO_ALLOC_PREF)]:, + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, + [(); {crate::meta_num_slots!(A, VECDEQUE_CO_ALLOC_PREF)}]:, { /// Turn a [`VecDeque`] into a [`Vec`]. /// @@ -2961,7 +2984,7 @@ where /// ``` fn from(mut other: VecDeque) -> Self where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(VECDEQUE_CO_ALLOC_PREF)]:, + [(); {crate::meta_num_slots!(A, VECDEQUE_CO_ALLOC_PREF)}]:, { other.make_contiguous(); @@ -2982,6 +3005,7 @@ where } #[stable(feature = "std_collections_from_array", since = "1.56.0")] +#[allow(unused_braces)] impl From<[T; N]> for VecDeque where [(); {meta_num_slots_global!(CO_ALLOC_PREF)}]:, diff --git a/library/alloc/src/collections/vec_deque/spec_extend.rs b/library/alloc/src/collections/vec_deque/spec_extend.rs index d4abb73048834..424e7cb4dd646 100644 --- a/library/alloc/src/collections/vec_deque/spec_extend.rs +++ b/library/alloc/src/collections/vec_deque/spec_extend.rs @@ -3,7 +3,6 @@ use crate::alloc::Allocator; use crate::co_alloc::CoAllocPref; use crate::vec; -use core::alloc; use core::iter::TrustedLen; use core::slice; @@ -14,10 +13,11 @@ pub(super) trait SpecExtend { fn spec_extend(&mut self, iter: I); } +#[allow(unused_braces)] impl SpecExtend for VecDeque where I: Iterator, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, { default fn spec_extend(&mut self, mut iter: I) { // This function should be the moral equivalent of: @@ -31,7 +31,7 @@ where deque: &mut VecDeque, element: T, ) where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, { // SAFETY: Because of the precondition, it's guaranteed that there is space // in the logical array after the last element. @@ -59,10 +59,11 @@ where } } +#[allow(unused_braces)] impl SpecExtend for VecDeque where I: TrustedLen, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, { default fn spec_extend(&mut self, iter: I) { // This is the case for a TrustedLen iterator. @@ -95,10 +96,11 @@ where } } +#[allow(unused_braces)] impl SpecExtend> for VecDeque where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, { fn spec_extend(&mut self, mut iterator: vec::IntoIter) { let slice = iterator.as_slice(); @@ -112,23 +114,25 @@ where } } +#[allow(unused_braces)] impl<'a, T: 'a, I, A: Allocator, const CO_ALLOC_PREF: CoAllocPref> SpecExtend<&'a T, I> for VecDeque where I: Iterator, T: Copy, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, { default fn spec_extend(&mut self, iterator: I) { self.spec_extend(iterator.copied()) } } +#[allow(unused_braces)] impl<'a, T: 'a, A: Allocator, const CO_ALLOC_PREF: CoAllocPref> SpecExtend<&'a T, slice::Iter<'a, T>> for VecDeque where T: Copy, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, { fn spec_extend(&mut self, iterator: slice::Iter<'a, T>) { let slice = iterator.as_slice(); diff --git a/library/alloc/src/collections/vec_deque/spec_from_iter.rs b/library/alloc/src/collections/vec_deque/spec_from_iter.rs index 5bd9043df34c7..b85aaa20da8fb 100644 --- a/library/alloc/src/collections/vec_deque/spec_from_iter.rs +++ b/library/alloc/src/collections/vec_deque/spec_from_iter.rs @@ -1,17 +1,17 @@ use super::{IntoIter, VecDeque}; use crate::alloc::Global; use crate::co_alloc::CoAllocPref; -use core::alloc; /// Specialization trait used for `VecDeque::from_iter` pub(super) trait SpecFromIter { fn spec_from_iter(iter: I) -> Self; } +#[allow(unused_braces)] impl SpecFromIter for VecDeque where I: Iterator, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, + [(); {crate::meta_num_slots_global!(CO_ALLOC_PREF)}]:, { default fn spec_from_iter(iterator: I) -> Self { // Since converting is O(1) now, just re-use the `Vec` logic for @@ -22,10 +22,11 @@ where } } +#[allow(unused_braces)] impl SpecFromIter> for VecDeque where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, + [(); {crate::meta_num_slots_global!(CO_ALLOC_PREF)}]:, { #[inline] fn spec_from_iter(iterator: crate::vec::IntoIter) -> Self { @@ -33,10 +34,11 @@ where } } +#[allow(unused_braces)] impl SpecFromIter> for VecDeque where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, + [(); {crate::meta_num_slots_global!(CO_ALLOC_PREF)}]:, { #[inline] fn spec_from_iter(iterator: IntoIter) -> Self { diff --git a/library/alloc/src/lib.rs b/library/alloc/src/lib.rs index 921850754cb3e..cb11c6f6d9826 100644 --- a/library/alloc/src/lib.rs +++ b/library/alloc/src/lib.rs @@ -182,7 +182,6 @@ #![feature(fundamental)] #![cfg_attr(not(test), feature(generator_trait))] #![feature(global_co_alloc)] -#![feature(global_co_alloc_short_term_pref)] #![feature(hashmap_internals)] #![feature(lang_items)] #![feature(global_co_alloc_default)] diff --git a/library/alloc/src/macros.rs b/library/alloc/src/macros.rs index f2c19eced02d0..0dac1e452c6a5 100644 --- a/library/alloc/src/macros.rs +++ b/library/alloc/src/macros.rs @@ -213,6 +213,14 @@ macro_rules! CO_ALLOC_PREF_DEFAULT { () => { $crate::CO_ALLOC_PREF_META_DEFAULT!() }; } +// @FIXME Move to library/alloc - if possible: +#[unstable(feature = "global_co_alloc", issue = "none")] +//pub const SHORT_TERM_VEC_CO_ALLOC_PREF: bool = true; +#[macro_export] +macro_rules! SHORT_TERM_VEC_CO_ALLOC_PREF { + () => { $crate::CO_ALLOC_PREF_META_NO!() }; +} + // ------ CoAlloc preference/config conversion macros: /// Create a `CoAllocPref` value based on the given parameter(s). For now, only one parameter is @@ -255,9 +263,11 @@ macro_rules! co_alloc_pref { #[macro_export] macro_rules! meta_num_slots { // This "validates" types of both params - to prevent mix ups. + // @FIXME remove this comment line: Removing/commenting out the part: <$alloc as ::core::alloc::Allocator>::CO_ALLOC_META_NUM_SLOTS + + // does NOT fix the ICE (unless there are multiple ICE's). ($alloc:ty, $co_alloc_pref:expr) => { ( - ((<$alloc>::CO_ALLOC_META_NUM_SLOTS + (0 as ::core::alloc::CoAllocatorMetaNumSlots)) + ((<$alloc as ::core::alloc::Allocator>::CO_ALLOC_META_NUM_SLOTS + (0 as ::core::alloc::CoAllocatorMetaNumSlots))0 as usize) * ($co_alloc_pref + (0 as $crate::co_alloc::CoAllocPref)) as usize) diff --git a/library/alloc/src/raw_vec.rs b/library/alloc/src/raw_vec.rs index 0265b446af9fc..d20e42013a706 100644 --- a/library/alloc/src/raw_vec.rs +++ b/library/alloc/src/raw_vec.rs @@ -3,7 +3,7 @@ use crate::co_alloc::CoAllocPref; use crate::meta_num_slots_default; use core::alloc::CoAllocMetaBase; -use core::alloc::{self, LayoutError, PtrAndMeta}; +use core::alloc::{LayoutError, PtrAndMeta}; use core::cmp; use core::intrinsics; use core::mem::{self, ManuallyDrop, MaybeUninit, SizedTypeProperties}; @@ -68,9 +68,10 @@ pub(crate) struct RawVec< //pub(crate) meta: [GlobalCoAllocMeta; {if core::any::TypeId::of::()==core::any::TypeId::of::() {1} else {0}}], //pub(crate) meta: [GlobalCoAllocMeta; mem::size_of::()], pub(crate) metas: - [A::CoAllocMeta; alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)], + [A::CoAllocMeta; {crate::meta_num_slots!(A, CO_ALLOC_PREF)}], } +#[allow(unused_braces)] impl RawVec where [(); {meta_num_slots_global!(CO_ALLOC_PREF)}]:, @@ -121,9 +122,10 @@ where } } +#[allow(unused_braces)] impl RawVec where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, { const fn new_plain_metas() -> [A::CoAllocMeta; { meta_num_slots_default!(A) }] { loop {} @@ -151,7 +153,7 @@ where cap: 0, alloc, metas: [A::CoAllocMeta::new_plain(); // @FIXME CoAlloc - alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)], + {crate::meta_num_slots!(A, CO_ALLOC_PREF)}], } } @@ -231,7 +233,7 @@ where cap: capacity, alloc, metas: [A::CoAllocMeta::new_plain(); // @FIXME CoAlloc - alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)], + {crate::meta_num_slots!(A, CO_ALLOC_PREF)}], } } } @@ -254,7 +256,7 @@ where cap: capacity, alloc, metas: [A::CoAllocMeta::new_plain(); //@FIXME CoAlloc - alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)], + {crate::meta_num_slots!(A, CO_ALLOC_PREF)}], } } @@ -318,6 +320,7 @@ where /// Aborts on OOM. #[cfg(not(no_global_oom_handling))] #[inline] + #[allow(unused_braces)] pub fn reserve(&mut self, len: usize, additional: usize) { // Callers expect this function to be very cheap when there is already sufficient capacity. // Therefore, we move all the resizing and error-handling logic from grow_amortized and @@ -329,7 +332,7 @@ where len: usize, additional: usize, ) where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, { handle_reserve(slf.grow_amortized(len, additional)); } @@ -403,9 +406,10 @@ where } } +#[allow(unused_braces)] impl RawVec where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, { /// Returns if the buffer needs to grow to fulfill the needed extra capacity. /// Mainly used to make inlining reserve-calls possible without inlining `grow`. @@ -526,9 +530,10 @@ where memory.map_err(|_| AllocError { layout: new_layout, non_exhaustive: () }.into()) } +#[allow(unused_braces)] unsafe impl<#[may_dangle] T, A: Allocator, const CO_ALLOC_PREF: CoAllocPref> Drop for RawVec where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, { /// Frees the memory owned by the `RawVec` *without* trying to drop its contents. default fn drop(&mut self) { diff --git a/library/alloc/src/rc.rs b/library/alloc/src/rc.rs index fe8f1d350a00a..1b1bd8c8864fe 100644 --- a/library/alloc/src/rc.rs +++ b/library/alloc/src/rc.rs @@ -275,6 +275,7 @@ use crate::alloc::handle_alloc_error; use crate::alloc::{box_free, WriteCloneIntoRaw}; use crate::alloc::{AllocError, Allocator, Global, Layout}; use crate::borrow::{Cow, ToOwned}; +use crate::co_alloc::CoAllocPref; #[cfg(not(no_global_oom_handling))] use crate::string::String; #[cfg(not(no_global_oom_handling))] @@ -1987,6 +1988,7 @@ impl From> for Rc { #[cfg(not(no_global_oom_handling))] #[stable(feature = "shared_from_slice", since = "1.21.0")] +#[allow(unused_braces)] impl From> for Rc<[T]> where [(); {meta_num_slots_global!(CO_ALLOC_PREF)}]:, @@ -2002,6 +2004,7 @@ where /// assert_eq!(vec![1, 2, 3], *shared); /// ``` #[inline] + #[allow(unused_braces)] fn from(mut v: Vec) -> Rc<[T]> where [(); {meta_num_slots_global!(CO_ALLOC_PREF)}]:, diff --git a/library/alloc/src/slice.rs b/library/alloc/src/slice.rs index c0b26521bf9c7..acd453fbb4803 100644 --- a/library/alloc/src/slice.rs +++ b/library/alloc/src/slice.rs @@ -28,8 +28,8 @@ use crate::alloc::{self, Global}; #[cfg(not(no_global_oom_handling))] use crate::borrow::ToOwned; use crate::boxed::Box; -use crate::vec::Vec; use crate::co_alloc::CoAllocPref; +use crate::vec::Vec; #[cfg(test)] mod tests; @@ -93,11 +93,13 @@ pub(crate) mod hack { use core::alloc::Allocator; use crate::boxed::Box; + use crate::co_alloc::CoAllocPref; use crate::vec::Vec; // We shouldn't add inline attribute to this since this is used in // `vec!` macro mostly and causes perf regression. See #71204 for // discussion and perf results. + #[allow(unused_braces)] pub fn into_vec(b: Box<[T], A>) -> Vec where [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, @@ -111,6 +113,7 @@ pub(crate) mod hack { #[cfg(not(no_global_oom_handling))] #[inline] + #[allow(unused_braces)] pub fn to_vec( s: &[T], alloc: A, @@ -122,6 +125,7 @@ pub(crate) mod hack { } #[cfg(not(no_global_oom_handling))] + #[allow(unused_braces)] pub trait ConvertVec { fn to_vec( s: &[Self], @@ -133,8 +137,10 @@ pub(crate) mod hack { } #[cfg(not(no_global_oom_handling))] + #[allow(unused_braces)] impl ConvertVec for T { #[inline] + #[allow(unused_braces)] default fn to_vec( s: &[Self], alloc: A, @@ -142,6 +148,7 @@ pub(crate) mod hack { where [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, { + #[allow(unused_braces)] struct DropGuard<'a, T, A: Allocator, const CO_ALLOC_PREF: CoAllocPref> where [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, @@ -184,6 +191,7 @@ pub(crate) mod hack { #[cfg(not(no_global_oom_handling))] impl ConvertVec for T { #[inline] + #[allow(unused_braces)] fn to_vec( s: &[Self], alloc: A, @@ -438,6 +446,7 @@ impl [T] { /// ``` #[cfg(not(no_global_oom_handling))] #[rustc_allow_incoherent_impl] + #[allow(unused_braces)] #[rustc_conversion_suggestion] #[stable(feature = "rust1", since = "1.0.0")] #[inline] @@ -466,6 +475,7 @@ impl [T] { #[rustc_allow_incoherent_impl] #[inline] #[unstable(feature = "allocator_api", issue = "32838")] + #[allow(unused_braces)] pub fn to_vec_in(&self, alloc: A) -> Vec where T: Clone, @@ -492,6 +502,7 @@ impl [T] { #[rustc_allow_incoherent_impl] #[stable(feature = "rust1", since = "1.0.0")] #[inline] + #[allow(unused_braces)] pub fn into_vec(self: Box) -> Vec where [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, @@ -809,6 +820,7 @@ impl> Join<&[T]> for [V] { //////////////////////////////////////////////////////////////////////////////// #[stable(feature = "rust1", since = "1.0.0")] +#[allow(unused_braces)] impl Borrow<[T]> for Vec where [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, @@ -819,6 +831,7 @@ where } #[stable(feature = "rust1", since = "1.0.0")] +#[allow(unused_braces)] impl BorrowMut<[T]> for Vec where [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, diff --git a/library/alloc/src/str.rs b/library/alloc/src/str.rs index 8b9c2fed4a3fa..ee13404a3eb98 100644 --- a/library/alloc/src/str.rs +++ b/library/alloc/src/str.rs @@ -18,6 +18,7 @@ use crate::alloc; use crate::alloc::Global; use crate::borrow::ToOwned; use crate::boxed::Box; +use crate::co_alloc::CoAllocPref; use crate::slice::{Concat, Join, SliceIndex}; use crate::string::String; use crate::vec::Vec; @@ -128,6 +129,7 @@ macro_rules! copy_slice_and_advance { // [T] and str both impl AsRef<[T]> for some T // => s.borrow().as_ref() and we always have slices #[cfg(not(no_global_oom_handling))] +#[allow(unused_braces)] fn join_generic_copy( slice: &[S], sep: &[T], @@ -136,7 +138,7 @@ where T: Copy, B: AsRef<[T]> + ?Sized, S: Borrow, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, + [(); {crate::meta_num_slots_global!(CO_ALLOC_PREF)}]:, { let sep_len = sep.len(); let mut iter = slice.iter(); diff --git a/library/alloc/src/vec/drain.rs b/library/alloc/src/vec/drain.rs index a3cddcb9f76d0..66ce729956c23 100644 --- a/library/alloc/src/vec/drain.rs +++ b/library/alloc/src/vec/drain.rs @@ -4,7 +4,7 @@ use crate::co_alloc::CoAllocPref; use core::iter::{FusedIterator, TrustedLen}; use core::mem::{self, ManuallyDrop, SizedTypeProperties}; use core::ptr::{self, NonNull}; -use core::{alloc, slice}; +use core::slice; use super::Vec; @@ -25,7 +25,7 @@ pub struct Drain< 'a, T: 'a, #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator + 'a = Global, - const CO_ALLOC_PREF: CoAllocPref = { SHORT_TERM_VEC_PREFERS_COOP!() }, + const CO_ALLOC_PREF: CoAllocPref = { SHORT_TERM_VEC_CO_ALLOC_PREF!() }, > where [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, { @@ -39,18 +39,20 @@ pub struct Drain< } #[stable(feature = "collection_debug", since = "1.17.0")] +#[allow(unused_braces)] impl fmt::Debug for Drain<'_, T, A, CO_ALLOC_PREF> where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_tuple("Drain").field(&self.iter.as_slice()).finish() } } +#[allow(unused_braces)] impl<'a, T, A: Allocator, const CO_ALLOC_PREF: CoAllocPref> Drain<'a, T, A, CO_ALLOC_PREF> where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, { /// Returns the remaining items of this iterator as a slice. /// @@ -150,9 +152,10 @@ where } #[stable(feature = "vec_drain_as_slice", since = "1.46.0")] +#[allow(unused_braces)] impl<'a, T, A: Allocator, const CO_ALLOC_PREF: CoAllocPref> AsRef<[T]> for Drain<'a, T, A, CO_ALLOC_PREF> where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, { fn as_ref(&self) -> &[T] { self.as_slice() @@ -160,20 +163,23 @@ where } #[stable(feature = "drain", since = "1.6.0")] +#[allow(unused_braces)] unsafe impl Sync for Drain<'_, T, A, CO_ALLOC_PREF> where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]: + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]: { } #[stable(feature = "drain", since = "1.6.0")] +#[allow(unused_braces)] unsafe impl Send for Drain<'_, T, A, CO_ALLOC_PREF> where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]: + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]: { } #[stable(feature = "drain", since = "1.6.0")] +#[allow(unused_braces)] impl Iterator for Drain<'_, T, A, CO_ALLOC_PREF> where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, { type Item = T; @@ -188,9 +194,10 @@ where } #[stable(feature = "drain", since = "1.6.0")] +#[allow(unused_braces)] impl DoubleEndedIterator for Drain<'_, T, A, CO_ALLOC_PREF> where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, { #[inline] fn next_back(&mut self) -> Option { @@ -199,21 +206,23 @@ where } #[stable(feature = "drain", since = "1.6.0")] +#[allow(unused_braces)] impl Drop for Drain<'_, T, A, CO_ALLOC_PREF> where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, { fn drop(&mut self) { /// Moves back the un-`Drain`ed elements to restore the original `Vec`. + #[allow(unused_braces)] struct DropGuard<'r, 'a, T, A: Allocator, const CO_ALLOC_PREF: CoAllocPref>( &'r mut Drain<'a, T, A, CO_ALLOC_PREF>, ) where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:; + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:; impl<'r, 'a, T, A: Allocator, const CO_ALLOC_PREF: CoAllocPref> Drop for DropGuard<'r, 'a, T, A, CO_ALLOC_PREF> where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, { fn drop(&mut self) { if self.0.tail_len > 0 { @@ -278,9 +287,10 @@ where } #[stable(feature = "drain", since = "1.6.0")] +#[allow(unused_braces)] impl ExactSizeIterator for Drain<'_, T, A, CO_ALLOC_PREF> where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, { fn is_empty(&self) -> bool { self.iter.is_empty() @@ -288,13 +298,15 @@ where } #[unstable(feature = "trusted_len", issue = "37572")] +#[allow(unused_braces)] unsafe impl TrustedLen for Drain<'_, T, A, CO_ALLOC_PREF> where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]: + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]: { } #[stable(feature = "fused", since = "1.26.0")] +#[allow(unused_braces)] impl FusedIterator for Drain<'_, T, A, CO_ALLOC_PREF> where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]: + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]: { } diff --git a/library/alloc/src/vec/drain_filter.rs b/library/alloc/src/vec/drain_filter.rs index 449a779554916..4ca2c6f2a7f34 100644 --- a/library/alloc/src/vec/drain_filter.rs +++ b/library/alloc/src/vec/drain_filter.rs @@ -1,7 +1,7 @@ use crate::alloc::{Allocator, Global}; use crate::co_alloc::CoAllocPref; use core::mem::{self, ManuallyDrop}; -use core::{alloc, ptr, slice}; +use core::{ptr, slice}; use super::Vec; @@ -20,15 +20,16 @@ use super::Vec; /// ``` #[unstable(feature = "drain_filter", reason = "recently added", issue = "43244")] #[derive(Debug)] +#[allow(unused_braces)] pub struct DrainFilter< 'a, T, F, #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global, - const CO_ALLOC_PREF: CoAllocPref = true, + const CO_ALLOC_PREF: CoAllocPref = {CO_ALLOC_PREF_DEFAULT!()}, > where F: FnMut(&mut T) -> bool, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, { pub(super) vec: &'a mut Vec, /// The index of the item that will be inspected by the next call to `next`. @@ -47,10 +48,11 @@ pub struct DrainFilter< pub(super) panic_flag: bool, } +#[allow(unused_braces)] impl DrainFilter<'_, T, F, A, CO_ALLOC_PREF> where F: FnMut(&mut T) -> bool, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, { /// Returns a reference to the underlying allocator. #[unstable(feature = "allocator_api", issue = "32838")] @@ -116,10 +118,11 @@ where } #[unstable(feature = "drain_filter", reason = "recently added", issue = "43244")] +#[allow(unused_braces)] impl Iterator for DrainFilter<'_, T, F, A, CO_ALLOC_PREF> where F: FnMut(&mut T) -> bool, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, { type Item = T; @@ -155,25 +158,28 @@ where } #[unstable(feature = "drain_filter", reason = "recently added", issue = "43244")] +#[allow(unused_braces)] impl Drop for DrainFilter<'_, T, F, A, CO_ALLOC_PREF> where F: FnMut(&mut T) -> bool, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, { + #[allow(unused_braces)] fn drop(&mut self) { struct BackshiftOnDrop<'a, 'b, T, F, A: Allocator, const CO_ALLOC_PREF: CoAllocPref> where F: FnMut(&mut T) -> bool, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, { drain: &'b mut DrainFilter<'a, T, F, A, CO_ALLOC_PREF>, } + #[allow(unused_braces)] impl<'a, 'b, T, F, A: Allocator, const CO_ALLOC_PREF: CoAllocPref> Drop for BackshiftOnDrop<'a, 'b, T, F, A, CO_ALLOC_PREF> where F: FnMut(&mut T) -> bool, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, { fn drop(&mut self) { unsafe { diff --git a/library/alloc/src/vec/in_place_collect.rs b/library/alloc/src/vec/in_place_collect.rs index 93187df2d11d9..b5d7588b26d63 100644 --- a/library/alloc/src/vec/in_place_collect.rs +++ b/library/alloc/src/vec/in_place_collect.rs @@ -138,7 +138,7 @@ //! vec.truncate(write_idx); //! ``` use crate::alloc::Global; -use core::alloc; +use crate::co_alloc::CoAllocPref; use core::iter::{InPlaceIterable, SourceIter, TrustedRandomAccessNoCoerce}; use core::mem::{self, ManuallyDrop, SizedTypeProperties}; use core::ptr::{self}; @@ -156,7 +156,7 @@ impl InPlaceIterableMarker for T where T: InPlaceIterable {} impl SpecFromIter for Vec where I: Iterator + SourceIter + InPlaceIterableMarker, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, + [(); {crate::meta_num_slots_global!(CO_ALLOC_PREF)}]:, { default fn from_iter(mut iterator: I) -> Self { // See "Layout constraints" section in the module documentation. We rely on const diff --git a/library/alloc/src/vec/into_iter.rs b/library/alloc/src/vec/into_iter.rs index 67f7943040d65..022c32f79febc 100644 --- a/library/alloc/src/vec/into_iter.rs +++ b/library/alloc/src/vec/into_iter.rs @@ -14,7 +14,7 @@ use core::mem::{self, ManuallyDrop, MaybeUninit, SizedTypeProperties}; use core::ops::Deref; use core::ptr::{self, NonNull}; use core::slice::{self}; -use core::{alloc, array, fmt}; +use core::{ array, fmt}; /// An iterator that moves out of a vector. /// @@ -33,9 +33,9 @@ use core::{alloc, array, fmt}; pub struct IntoIter< T, #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global, - const CO_ALLOC_PREF: CoAllocPref = { SHORT_TERM_VEC_PREFERS_COOP!() }, + const CO_ALLOC_PREF: CoAllocPref = { SHORT_TERM_VEC_CO_ALLOC_PREF!() }, > where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, { pub(super) buf: NonNull, pub(super) phantom: PhantomData, @@ -50,18 +50,20 @@ pub struct IntoIter< } #[stable(feature = "vec_intoiter_debug", since = "1.13.0")] +#[allow(unused_braces)] impl fmt::Debug for IntoIter where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_tuple("IntoIter").field(&self.as_slice()).finish() } } +#[allow(unused_braces)] impl IntoIter where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, { /// Returns the remaining items of this iterator as a slice. /// @@ -188,9 +190,10 @@ where } #[stable(feature = "vec_intoiter_as_ref", since = "1.46.0")] +#[allow(unused_braces)] impl AsRef<[T]> for IntoIter where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, { fn as_ref(&self) -> &[T] { self.as_slice() @@ -198,20 +201,23 @@ where } #[stable(feature = "rust1", since = "1.0.0")] +#[allow(unused_braces)] unsafe impl Send for IntoIter where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]: + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]: { } #[stable(feature = "rust1", since = "1.0.0")] +#[allow(unused_braces)] unsafe impl Sync for IntoIter where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]: + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]: { } #[stable(feature = "rust1", since = "1.0.0")] +#[allow(unused_braces)] impl Iterator for IntoIter where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, { type Item = T; @@ -326,9 +332,10 @@ where } #[stable(feature = "rust1", since = "1.0.0")] +#[allow(unused_braces)] impl DoubleEndedIterator for IntoIter where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, { #[inline] fn next_back(&mut self) -> Option { @@ -370,9 +377,10 @@ where } #[stable(feature = "rust1", since = "1.0.0")] +#[allow(unused_braces)] impl ExactSizeIterator for IntoIter where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, { fn is_empty(&self) -> bool { self.ptr == self.end @@ -380,14 +388,16 @@ where } #[stable(feature = "fused", since = "1.26.0")] +#[allow(unused_braces)] impl FusedIterator for IntoIter where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]: + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]: { } #[unstable(feature = "trusted_len", issue = "37572")] +#[allow(unused_braces)] unsafe impl TrustedLen for IntoIter where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]: + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]: { } @@ -403,22 +413,24 @@ impl NonDrop for T {} #[doc(hidden)] #[unstable(issue = "none", feature = "std_internals")] +#[allow(unused_braces)] // TrustedRandomAccess (without NoCoerce) must not be implemented because // subtypes/supertypes of `T` might not be `NonDrop` unsafe impl TrustedRandomAccessNoCoerce for IntoIter where T: NonDrop, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, { const MAY_HAVE_SIDE_EFFECT: bool = false; } #[cfg(not(no_global_oom_handling))] #[stable(feature = "vec_into_iter_clone", since = "1.8.0")] +#[allow(unused_braces)] impl Clone for IntoIter where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, { #[cfg(not(test))] fn clone(&self) -> Self { @@ -438,20 +450,21 @@ where } #[stable(feature = "rust1", since = "1.0.0")] +#[allow(unused_braces)] unsafe impl<#[may_dangle] T, A: Allocator, const CO_ALLOC_PREF: CoAllocPref> Drop for IntoIter where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, { fn drop(&mut self) { struct DropGuard<'a, T, A: Allocator, const CO_ALLOC_PREF: CoAllocPref>( &'a mut IntoIter, ) where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:; + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:; impl Drop for DropGuard<'_, T, A, CO_ALLOC_PREF> where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, { fn drop(&mut self) { unsafe { @@ -481,16 +494,18 @@ where // also refer to the vec::in_place_collect module documentation to get an overview #[unstable(issue = "none", feature = "inplace_iteration")] #[doc(hidden)] +#[allow(unused_braces)] unsafe impl InPlaceIterable for IntoIter where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]: + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]: { } #[unstable(issue = "none", feature = "inplace_iteration")] #[doc(hidden)] +#[allow(unused_braces)] unsafe impl SourceIter for IntoIter where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, { type Source = Self; diff --git a/library/alloc/src/vec/mod.rs b/library/alloc/src/vec/mod.rs index 38177f5707227..8dc14d89c5141 100644 --- a/library/alloc/src/vec/mod.rs +++ b/library/alloc/src/vec/mod.rs @@ -54,7 +54,6 @@ #![stable(feature = "rust1", since = "1.0.0")] #[cfg(not(no_global_oom_handling))] -use core::alloc; use core::cmp; use core::cmp::Ordering; use core::convert::TryFrom; @@ -414,12 +413,12 @@ pub struct Vec< /// "Cooperative" Vector. Preferring co-alloc API (if Global alloc supports it). #[unstable(feature = "global_co_alloc_covec", issue = "none")] -pub type CoVec = Vec; +pub type CoVec = Vec; /// "Plain" Vec. Not "cooperative" - not carrying extra data to assist the allocator. /// FIXME after cleanup, see if we still use this in core:: and/or alloc:: #[unstable(feature = "global_co_alloc_plvec", issue = "none")] -pub type PlVec = Vec; +pub type PlVec = Vec; /// "Default" Vec. Either "cooperative" or not - as specified by `DEFAULT_CO_ALLOC_PREF`. The /// difference to `Vec` (used without specifying `CO_ALLOC_PREF`): `DefVec` indicates that the @@ -516,6 +515,7 @@ impl Vec { //////////////////////////////////////////////////////////////////////////////// /**/ +#[allow(unused_braces)] impl Vec where [(); {meta_num_slots_global!(CO_ALLOC_PREF)}]:, @@ -698,6 +698,7 @@ where } } +#[allow(unused_braces)] impl Vec where [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, @@ -1716,7 +1717,7 @@ where // In cases when predicate and `drop` never panick, it will be optimized out. struct BackshiftOnDrop<'a, T, A: Allocator, const VEC_CO_ALLOC_PREF: CoAllocPref = {CO_ALLOC_PREF_META_DEFAULT!()}> where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(VEC_CO_ALLOC_PREF)]:, + [(); {crate::meta_num_slots!(A, VEC_CO_ALLOC_PREF)}]:, { v: &'a mut Vec, processed_len: usize, @@ -1724,9 +1725,10 @@ where original_len: usize, } + #[allow(unused_braces)] impl Drop for BackshiftOnDrop<'_, T, A, VEC_CO_ALLOC_PREF> where - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(VEC_CO_ALLOC_PREF)]:, + [(); {crate::meta_num_slots!(A, VEC_CO_ALLOC_PREF)}]:, { fn drop(&mut self) { if self.deleted_cnt > 0 { @@ -1759,7 +1761,7 @@ where g: &mut BackshiftOnDrop<'_, T, A, VEC_CO_ALLOC_PREF>, ) where F: FnMut(&mut T) -> bool, - [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(VEC_CO_ALLOC_PREF)]:, + [(); {crate::meta_num_slots!(A, VEC_CO_ALLOC_PREF)}]:, { while g.processed_len != original_len { // SAFETY: Unchecked element must be valid. @@ -1867,6 +1869,7 @@ where vec: &'a mut Vec, } + #[allow(unused_braces)] impl<'a, T, A: core::alloc::Allocator, const CO_ALLOC_PREF: CoAllocPref> Drop for FillGapOnDrop<'a, T, A, CO_ALLOC_PREF> where @@ -2464,6 +2467,7 @@ where } } +#[allow(unused_braces)] impl Vec where [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, @@ -2566,6 +2570,7 @@ where } } +#[allow(unused_braces)] impl Vec<[T; N], A, CO_ALLOC_PREF> where [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, @@ -2630,6 +2635,7 @@ impl ExtendWith for ExtendElement { } } +#[allow(unused_braces)] impl Vec where [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, @@ -2665,6 +2671,7 @@ where } } +#[allow(unused_braces)] impl Vec where [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, @@ -2704,6 +2711,7 @@ pub fn from_elem(elem: T, n: usize) -> Vec { #[doc(hidden)] #[cfg(not(no_global_oom_handling))] #[unstable(feature = "allocator_api", issue = "32838")] +#[allow(unused_braces)] pub fn from_elem_in( elem: T, n: usize, @@ -2723,6 +2731,7 @@ trait ExtendFromWithinSpec { unsafe fn spec_extend_from_within(&mut self, src: Range); } +#[allow(unused_braces)] impl ExtendFromWithinSpec for Vec where [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, @@ -2745,6 +2754,7 @@ where } } +#[allow(unused_braces)] impl ExtendFromWithinSpec for Vec where [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, @@ -2781,6 +2791,7 @@ where //////////////////////////////////////////////////////////////////////////////// #[stable(feature = "rust1", since = "1.0.0")] +#[allow(unused_braces)] impl ops::Deref for Vec where [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, @@ -2794,6 +2805,7 @@ where } #[stable(feature = "rust1", since = "1.0.0")] +#[allow(unused_braces)] impl ops::DerefMut for Vec where [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, @@ -2806,6 +2818,7 @@ where #[cfg(not(no_global_oom_handling))] #[stable(feature = "rust1", since = "1.0.0")] +#[allow(unused_braces)] impl Clone for Vec where [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, @@ -2844,6 +2857,7 @@ where /// assert_eq!(b.hash_one(v), b.hash_one(s)); /// ``` #[stable(feature = "rust1", since = "1.0.0")] +#[allow(unused_braces)] impl Hash for Vec where [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, @@ -2859,6 +2873,7 @@ where message = "vector indices are of type `usize` or ranges of `usize`", label = "vector indices are of type `usize` or ranges of `usize`" )] +#[allow(unused_braces)] impl, A: Allocator, const CO_ALLOC_PREF: CoAllocPref> Index for Vec where [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, @@ -2876,6 +2891,7 @@ where message = "vector indices are of type `usize` or ranges of `usize`", label = "vector indices are of type `usize` or ranges of `usize`" )] +#[allow(unused_braces)] impl, A: Allocator, const CO_ALLOC_PREF: CoAllocPref> IndexMut for Vec where @@ -2892,7 +2908,7 @@ where #[allow(unused_braces)] impl FromIterator for Vec where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, + [(); {crate::meta_num_slots_global!(CO_ALLOC_PREF)}]:, { #[inline] fn from_iter>(iter: I) -> Vec { @@ -2901,6 +2917,7 @@ where } #[stable(feature = "rust1", since = "1.0.0")] +#[allow(unused_braces)] impl IntoIterator for Vec where [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, @@ -2949,6 +2966,7 @@ where } #[stable(feature = "rust1", since = "1.0.0")] +#[allow(unused_braces)] impl<'a, T, A: Allocator, const CO_ALLOC_PREF: CoAllocPref> IntoIterator for &'a Vec where [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, @@ -2962,6 +2980,7 @@ where } #[stable(feature = "rust1", since = "1.0.0")] +#[allow(unused_braces)] impl<'a, T, A: Allocator, const CO_ALLOC_PREF: CoAllocPref> IntoIterator for &'a mut Vec where [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, @@ -2976,6 +2995,7 @@ where #[cfg(not(no_global_oom_handling))] #[stable(feature = "rust1", since = "1.0.0")] +#[allow(unused_braces)] impl Extend for Vec where [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, @@ -2996,6 +3016,7 @@ where } } +#[allow(unused_braces)] impl Vec where [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, @@ -3179,6 +3200,7 @@ where /// [`copy_from_slice`]: slice::copy_from_slice #[cfg(not(no_global_oom_handling))] #[stable(feature = "extend_ref", since = "1.2.0")] +#[allow(unused_braces)] impl<'a, T: Copy + 'a, A: Allocator + 'a, const CO_ALLOC_PREF: CoAllocPref> Extend<&'a T> for Vec where @@ -3201,6 +3223,7 @@ where /// Implements comparison of vectors, [lexicographically](core::cmp::Ord#lexicographical-comparison). #[stable(feature = "rust1", since = "1.0.0")] +#[allow(unused_braces)] impl PartialOrd for Vec where [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, @@ -3212,6 +3235,7 @@ where } #[stable(feature = "rust1", since = "1.0.0")] +#[allow(unused_braces)] impl Eq for Vec where [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]: { @@ -3219,6 +3243,7 @@ impl Eq for Vec Ord for Vec where [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, @@ -3230,6 +3255,7 @@ where } #[stable(feature = "rust1", since = "1.0.0")] +#[allow(unused_braces)] unsafe impl<#[may_dangle] T, A: Allocator, const CO_ALLOC_PREF: CoAllocPref> Drop for Vec where [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, @@ -3247,6 +3273,7 @@ where #[stable(feature = "rust1", since = "1.0.0")] #[rustc_const_unstable(feature = "const_default_impls", issue = "87864")] +#[allow(unused_braces)] impl const Default for Vec where [(); {meta_num_slots_global!(CO_ALLOC_PREF)}]:, @@ -3260,6 +3287,7 @@ where } #[stable(feature = "rust1", since = "1.0.0")] +#[allow(unused_braces)] impl fmt::Debug for Vec where [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, @@ -3270,6 +3298,7 @@ where } #[stable(feature = "rust1", since = "1.0.0")] +#[allow(unused_braces)] impl AsRef> for Vec where [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, @@ -3280,6 +3309,7 @@ where } #[stable(feature = "vec_as_mut", since = "1.5.0")] +#[allow(unused_braces)] impl AsMut> for Vec where [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, @@ -3290,6 +3320,7 @@ where } #[stable(feature = "rust1", since = "1.0.0")] +#[allow(unused_braces)] impl AsRef<[T]> for Vec where [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, @@ -3300,6 +3331,7 @@ where } #[stable(feature = "vec_as_mut", since = "1.5.0")] +#[allow(unused_braces)] impl AsMut<[T]> for Vec where [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, @@ -3404,6 +3436,7 @@ where // note: test pulls in std, which causes errors here #[cfg(not(test))] #[stable(feature = "vec_from_box", since = "1.18.0")] +#[allow(unused_braces)] impl From> for Vec where [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, @@ -3426,6 +3459,7 @@ where #[cfg(not(no_global_oom_handling))] #[cfg(not(test))] #[stable(feature = "box_from_vec", since = "1.20.0")] +#[allow(unused_braces)] impl From> for Box<[T], A> where [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, @@ -3470,6 +3504,7 @@ impl From<&str> for Vec { } #[stable(feature = "array_try_from_vec", since = "1.48.0")] +#[allow(unused_braces)] impl TryFrom> for [T; N] where diff --git a/library/alloc/src/vec/partial_eq.rs b/library/alloc/src/vec/partial_eq.rs index 7bf6a023bc8d3..a4fb19794b4db 100644 --- a/library/alloc/src/vec/partial_eq.rs +++ b/library/alloc/src/vec/partial_eq.rs @@ -9,6 +9,7 @@ use super::Vec; macro_rules! __impl_slice_eq1 { ([$($vars:tt)*] $lhs:ty, $rhs:ty, #[$stability:meta], $($constraints:tt)*) => { #[$stability] + #[allow(unused_braces)] impl PartialEq<$rhs> for $lhs where T: PartialEq, @@ -22,7 +23,7 @@ macro_rules! __impl_slice_eq1 { } } -__impl_slice_eq1! { [A1: Allocator, A2: Allocator, const CO_ALLOC_PREF1: bool, const CO_ALLOC_PREF2: bool] Vec, Vec, #[stable(feature = "rust1", since = "1.0.0")], [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF1)]:, [(); core::alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF2)]: } +__impl_slice_eq1! { [A1: Allocator, A2: Allocator, const CO_ALLOC_PREF1: crate::co_alloc::CoAllocPref, const CO_ALLOC_PREF2: crate::co_alloc::CoAllocPref] Vec, Vec, #[stable(feature = "rust1", since = "1.0.0")], [(); {crate::meta_num_slots!(A1, CO_ALLOC_PREF1)}]:, [(); {crate::meta_num_slots!(A2, CO_ALLOC_PREF2)}]: } __impl_slice_eq1! { [A: Allocator, const CO_ALLOC_PREF: CoAllocPref] Vec, &[U], #[stable(feature = "rust1", since = "1.0.0")], [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]: } __impl_slice_eq1! { [A: Allocator, const CO_ALLOC_PREF: CoAllocPref] Vec, &mut [U], #[stable(feature = "rust1", since = "1.0.0")], [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]: } __impl_slice_eq1! { [A: Allocator, const CO_ALLOC_PREF: CoAllocPref] &[T], Vec, #[stable(feature = "partialeq_vec_for_ref_slice", since = "1.46.0")], [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]: } diff --git a/library/alloc/src/vec/spec_extend.rs b/library/alloc/src/vec/spec_extend.rs index 909fd43aedff4..2fcc24131f0cb 100644 --- a/library/alloc/src/vec/spec_extend.rs +++ b/library/alloc/src/vec/spec_extend.rs @@ -1,5 +1,4 @@ use crate::alloc::Allocator; -use core::alloc; use crate::co_alloc::CoAllocPref; use core::iter::TrustedLen; use core::slice::{self}; @@ -11,29 +10,32 @@ pub(super) trait SpecExtend { fn spec_extend(&mut self, iter: I); } +#[allow(unused_braces)] impl SpecExtend for Vec where I: Iterator, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, { default fn spec_extend(&mut self, iter: I) { self.extend_desugared(iter) } } +#[allow(unused_braces)] impl SpecExtend for Vec where I: TrustedLen, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, { default fn spec_extend(&mut self, iterator: I) { self.extend_trusted(iterator) } } +#[allow(unused_braces)] impl SpecExtend> for Vec where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, { fn spec_extend(&mut self, mut iterator: IntoIter) { unsafe { @@ -43,23 +45,25 @@ where } } +#[allow(unused_braces)] impl<'a, T: 'a, I, A: Allocator + 'a, const CO_ALLOC_PREF: CoAllocPref> SpecExtend<&'a T, I> for Vec where I: Iterator, T: Clone, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, { default fn spec_extend(&mut self, iterator: I) { self.spec_extend(iterator.cloned()) } } +#[allow(unused_braces)] impl<'a, T: 'a, A: Allocator + 'a, const CO_ALLOC_PREF: CoAllocPref> SpecExtend<&'a T, slice::Iter<'a, T>> for Vec where T: Copy, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, { fn spec_extend(&mut self, iterator: slice::Iter<'a, T>) { let slice = iterator.as_slice(); diff --git a/library/alloc/src/vec/spec_from_elem.rs b/library/alloc/src/vec/spec_from_elem.rs index ce10137bf9ccc..b926a6c2d0e0f 100644 --- a/library/alloc/src/vec/spec_from_elem.rs +++ b/library/alloc/src/vec/spec_from_elem.rs @@ -3,21 +3,22 @@ use core::ptr; use crate::alloc::Allocator; use crate::co_alloc::CoAllocPref; use crate::raw_vec::RawVec; -use core::alloc; use super::{ExtendElement, IsZero, Vec}; // Specialization trait used for Vec::from_elem pub(super) trait SpecFromElem: Sized { + #[allow(unused_braces)] fn from_elem( elem: Self, n: usize, alloc: A, ) -> Vec where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:; + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:; } +#[allow(unused_braces)] impl SpecFromElem for T { default fn from_elem( elem: Self, @@ -25,7 +26,7 @@ impl SpecFromElem for T { alloc: A, ) -> Vec where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, { let mut v = Vec::with_capacity_in(n, alloc); v.extend_with(n, ExtendElement(elem)); @@ -33,6 +34,7 @@ impl SpecFromElem for T { } } +#[allow(unused_braces)] impl SpecFromElem for T { #[inline] default fn from_elem( @@ -41,7 +43,7 @@ impl SpecFromElem for T { alloc: A, ) -> Vec where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, { if elem.is_zero() { return Vec { buf: RawVec::with_capacity_zeroed_in(n, alloc), len: n }; @@ -54,13 +56,14 @@ impl SpecFromElem for T { impl SpecFromElem for i8 { #[inline] + #[allow(unused_braces)] fn from_elem( elem: i8, n: usize, alloc: A, ) -> Vec where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, { if elem == 0 { return Vec { buf: RawVec::with_capacity_zeroed_in(n, alloc), len: n }; @@ -76,13 +79,14 @@ impl SpecFromElem for i8 { impl SpecFromElem for u8 { #[inline] + #[allow(unused_braces)] fn from_elem( elem: u8, n: usize, alloc: A, ) -> Vec where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, { if elem == 0 { return Vec { buf: RawVec::with_capacity_zeroed_in(n, alloc), len: n }; diff --git a/library/alloc/src/vec/spec_from_iter.rs b/library/alloc/src/vec/spec_from_iter.rs index ae4fe914f8d53..a8383808e4210 100644 --- a/library/alloc/src/vec/spec_from_iter.rs +++ b/library/alloc/src/vec/spec_from_iter.rs @@ -1,6 +1,5 @@ use crate::alloc::Global; use crate::co_alloc::CoAllocPref; -use core::alloc; use core::mem::ManuallyDrop; use core::ptr::{self}; @@ -32,7 +31,7 @@ pub(super) trait SpecFromIter { impl SpecFromIter for Vec where I: Iterator, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, + [(); {crate::meta_num_slots_global!(CO_ALLOC_PREF)}]:, { default fn from_iter(iterator: I) -> Self { SpecFromIterNested::from_iter(iterator) @@ -42,7 +41,7 @@ where #[allow(unused_braces)] impl SpecFromIter> for Vec where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, + [(); {crate::meta_num_slots_global!(CO_ALLOC_PREF)}]:, { fn from_iter(iterator: IntoIter) -> Self { // A common case is passing a vector into a function which immediately diff --git a/library/alloc/src/vec/spec_from_iter_nested.rs b/library/alloc/src/vec/spec_from_iter_nested.rs index 8ad562a854163..f103842f2d884 100644 --- a/library/alloc/src/vec/spec_from_iter_nested.rs +++ b/library/alloc/src/vec/spec_from_iter_nested.rs @@ -1,9 +1,9 @@ -use core::alloc; use core::cmp; use core::iter::TrustedLen; use core::ptr; use crate::alloc::Global; +use crate::co_alloc::CoAllocPref; use crate::raw_vec::RawVec; use crate::CO_ALLOC_PREF_DEFAULT; @@ -20,7 +20,7 @@ pub(super) trait SpecFromIterNested { impl SpecFromIterNested for Vec where I: Iterator, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, + [(); {crate::meta_num_slots_global!(CO_ALLOC_PREF)}]:, { default fn from_iter(mut iterator: I) -> Self { // Unroll the first iteration, as the vector is going to be diff --git a/library/alloc/src/vec/splice.rs b/library/alloc/src/vec/splice.rs index e61f0d91ea4ac..cba2057be95a3 100644 --- a/library/alloc/src/vec/splice.rs +++ b/library/alloc/src/vec/splice.rs @@ -1,5 +1,4 @@ use crate::alloc::{Allocator, Global}; -use core::alloc; use crate::co_alloc::CoAllocPref; use core::ptr::{self}; use core::slice::{self}; @@ -20,11 +19,12 @@ use super::{Drain, Vec}; /// ``` #[derive(Debug)] #[stable(feature = "vec_splice", since = "1.21.0")] +#[allow(unused_braces)] pub struct Splice< 'a, I: Iterator + 'a, #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator + 'a = Global, - const CO_ALLOC_PREF: CoAllocPref = false, + const CO_ALLOC_PREF: CoAllocPref = {CO_ALLOC_PREF_DEFAULT!()}, > where [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, { @@ -33,6 +33,7 @@ pub struct Splice< } #[stable(feature = "vec_splice", since = "1.21.0")] +#[allow(unused_braces)] impl Iterator for Splice<'_, I, A, CO_ALLOC_PREF> where [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, @@ -49,10 +50,11 @@ where } #[stable(feature = "vec_splice", since = "1.21.0")] +#[allow(unused_braces)] impl DoubleEndedIterator for Splice<'_, I, A, CO_ALLOC_PREF> where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, { fn next_back(&mut self) -> Option { self.drain.next_back() @@ -60,14 +62,16 @@ where } #[stable(feature = "vec_splice", since = "1.21.0")] +#[allow(unused_braces)] impl ExactSizeIterator for Splice<'_, I, A, CO_ALLOC_PREF> where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, { } #[stable(feature = "vec_splice", since = "1.21.0")] +#[allow(unused_braces)] impl Drop for Splice<'_, I, A, CO_ALLOC_PREF> where [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, @@ -118,9 +122,10 @@ where } /// Private helper methods for `Splice::drop` +#[allow(unused_braces)] impl Drain<'_, T, A, CO_ALLOC_PREF> where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, { /// The range from `self.vec.len` to `self.tail_start` contains elements /// that have been moved out. diff --git a/library/core/src/alloc/mod.rs b/library/core/src/alloc/mod.rs index 5930b72fa0fa8..a973cc18ab947 100644 --- a/library/core/src/alloc/mod.rs +++ b/library/core/src/alloc/mod.rs @@ -65,16 +65,6 @@ pub struct SliceAndMeta { pub meta: M, } -// @FIXME Move to library/alloc - if possible: -#[unstable(feature = "global_co_alloc_short_term_pref", issue = "none")] -//pub const SHORT_TERM_VEC_PREFERS_COOP: bool = true; -#[macro_export] -macro_rules! SHORT_TERM_VEC_PREFERS_COOP { - () => { - true - }; -} - /// `Result` of `SliceAndMeta` or `AllocError`. #[unstable(feature = "global_co_alloc_meta", issue = "none")] pub type SliceAndMetaResult = Result, AllocError>; From cbe603511afac560c94383bc7805c486413de013 Mon Sep 17 00:00:00 2001 From: Peter Kehl Date: Sun, 29 Jan 2023 20:06:17 -0800 Subject: [PATCH 093/118] CoAlloc: co_alloc_pref changed to 0usize - and (at least now) no ICE. --- library/alloc/src/macros.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/library/alloc/src/macros.rs b/library/alloc/src/macros.rs index 0dac1e452c6a5..cc5262394f599 100644 --- a/library/alloc/src/macros.rs +++ b/library/alloc/src/macros.rs @@ -262,15 +262,17 @@ macro_rules! co_alloc_pref { #[unstable(feature = "global_co_alloc", issue = "none")] #[macro_export] macro_rules! meta_num_slots { + // Generating, for example, (0 as usize), here, triggers an ICE. + // This "validates" types of both params - to prevent mix ups. // @FIXME remove this comment line: Removing/commenting out the part: <$alloc as ::core::alloc::Allocator>::CO_ALLOC_META_NUM_SLOTS + // does NOT fix the ICE (unless there are multiple ICE's). ($alloc:ty, $co_alloc_pref:expr) => { - ( + /*( ((<$alloc as ::core::alloc::Allocator>::CO_ALLOC_META_NUM_SLOTS + (0 as ::core::alloc::CoAllocatorMetaNumSlots))0 as usize) * ($co_alloc_pref + (0 as $crate::co_alloc::CoAllocPref)) - as usize) + as usize)*/0usize }; } // -\---> replace with something like: From 826786a7bdbd88ba5c4cc3d28c6be578207ff9a2 Mon Sep 17 00:00:00 2001 From: Peter Kehl Date: Sun, 29 Jan 2023 20:50:28 -0800 Subject: [PATCH 094/118] CoAlloc: library/alloc now uses macros, and no ICE. But meta_num_slots macro is hardcoded - TO FIX. --- library/alloc/src/boxed.rs | 16 ++++++++-------- library/alloc/src/macros.rs | 8 ++++---- library/alloc/src/raw_vec.rs | 5 ++++- library/alloc/src/vec/in_place_drop.rs | 2 +- library/alloc/src/vec/into_iter.rs | 14 ++++++++------ library/core/src/alloc/mod.rs | 9 +++++---- 6 files changed, 30 insertions(+), 24 deletions(-) diff --git a/library/alloc/src/boxed.rs b/library/alloc/src/boxed.rs index 6f6919d56c63c..7d91fc8bdeb12 100644 --- a/library/alloc/src/boxed.rs +++ b/library/alloc/src/boxed.rs @@ -643,7 +643,7 @@ impl Box<[T]> { #[must_use] pub fn new_uninit_slice(len: usize) -> Box<[mem::MaybeUninit]> { // false = no need for co-alloc metadata, since it would get lost once converted to Box. - unsafe { RawVec::::with_capacity(len).into_box(len) } + unsafe { RawVec::::with_capacity(len).into_box(len) } } /// Constructs a new boxed slice with uninitialized contents, with the memory @@ -669,7 +669,7 @@ impl Box<[T]> { #[must_use] pub fn new_zeroed_slice(len: usize) -> Box<[mem::MaybeUninit]> { // false = no need for co-alloc metadata, since it would get lost once converted to Box. - unsafe { RawVec::::with_capacity_zeroed(len).into_box(len) } + unsafe { RawVec::::with_capacity_zeroed(len).into_box(len) } } /// Constructs a new boxed slice with uninitialized contents. Returns an error if @@ -701,7 +701,7 @@ impl Box<[T]> { Err(_) => return Err(AllocError), }; let ptr = Global.allocate(layout)?; - Ok(RawVec::::from_raw_parts_in( + Ok(RawVec::::from_raw_parts_in( ptr.as_mut_ptr() as *mut _, len, Global, @@ -738,7 +738,7 @@ impl Box<[T]> { Err(_) => return Err(AllocError), }; let ptr = Global.allocate_zeroed(layout)?; - Ok(RawVec::::from_raw_parts_in( + Ok(RawVec::::from_raw_parts_in( ptr.as_mut_ptr() as *mut _, len, Global, @@ -781,7 +781,7 @@ where #[must_use] #[allow(unused_braces)] pub fn new_uninit_slice_in(len: usize, alloc: A) -> Box<[mem::MaybeUninit], A> { - unsafe { RawVec::::with_capacity_in(len, alloc).into_box(len) } + unsafe { RawVec::::with_capacity_in(len, alloc).into_box(len) } } /// Constructs a new boxed slice with uninitialized contents in the provided allocator, @@ -810,7 +810,7 @@ where #[must_use] #[allow(unused_braces)] pub fn new_zeroed_slice_in(len: usize, alloc: A) -> Box<[mem::MaybeUninit], A> { - unsafe { RawVec::::with_capacity_zeroed_in(len, alloc).into_box(len) } + unsafe { RawVec::::with_capacity_zeroed_in(len, alloc).into_box(len) } } } @@ -1516,7 +1516,7 @@ impl From<&[T]> for Box<[T]> { fn from(slice: &[T]) -> Box<[T]> { let len = slice.len(); // false = no need for co-alloc metadata, since it would get lost once converted to Box. - let buf = RawVec::::with_capacity(len); + let buf = RawVec::::with_capacity(len); unsafe { ptr::copy_nonoverlapping(slice.as_ptr(), buf.ptr(), len); buf.into_box(slice.len()).assume_init() @@ -2051,7 +2051,7 @@ where fn clone(&self) -> Self { let alloc = Box::allocator(self).clone(); // false = no need for co-alloc metadata, since it would get lost once converted to the boxed slice. - self.to_vec_in::(alloc).into_boxed_slice() + self.to_vec_in::(alloc).into_boxed_slice() } fn clone_from(&mut self, other: &Self) { diff --git a/library/alloc/src/macros.rs b/library/alloc/src/macros.rs index cc5262394f599..a2a62d676bed1 100644 --- a/library/alloc/src/macros.rs +++ b/library/alloc/src/macros.rs @@ -127,7 +127,7 @@ macro_rules! __rust_force_expr { // ----- CoAlloc constant-like macros: -// @FIXME Docs +/// Coallocation option/parameter about using metadata that does prefer to use meta data. This is of type [::alloc::co_alloc::CoAllocMetaNumSlotsPref] (but not a whole []::alloc::co_alloc::CoAllocPref]). #[unstable(feature = "global_co_alloc_meta", issue = "none")] #[macro_export] macro_rules! CO_ALLOC_PREF_NUM_META_SLOTS_ONE { @@ -136,7 +136,7 @@ macro_rules! CO_ALLOC_PREF_NUM_META_SLOTS_ONE { }; } -// @FIXME Docs +/// Coallocation option/parameter about using metadata that prefers NOT to use meta data. This is of type [::alloc::co_alloc::CoAllocMetaNumSlotsPref] (but not a whole []::alloc::co_alloc::CoAllocPref]). #[unstable(feature = "global_co_alloc_meta", issue = "none")] #[macro_export] macro_rules! CO_ALLOC_PREF_NUM_META_SLOTS_ZERO { @@ -145,7 +145,7 @@ macro_rules! CO_ALLOC_PREF_NUM_META_SLOTS_ZERO { }; } -// @FIXME Docs +/// Default coallocation option/parameter about using metadata (whether to use meta data, or not). This is of type [::alloc::co_alloc::CoAllocMetaNumSlotsPref] (but not a whole []::alloc::co_alloc::CoAllocPref]). #[unstable(feature = "global_co_alloc_meta", issue = "none")] #[macro_export] macro_rules! CO_ALLOC_PREF_NUM_META_SLOTS_DEFAULT { @@ -213,7 +213,7 @@ macro_rules! CO_ALLOC_PREF_DEFAULT { () => { $crate::CO_ALLOC_PREF_META_DEFAULT!() }; } -// @FIXME Move to library/alloc - if possible: +/// Coallocation preference for (internal) short term vectors. #[unstable(feature = "global_co_alloc", issue = "none")] //pub const SHORT_TERM_VEC_CO_ALLOC_PREF: bool = true; #[macro_export] diff --git a/library/alloc/src/raw_vec.rs b/library/alloc/src/raw_vec.rs index d20e42013a706..5f401448c12b2 100644 --- a/library/alloc/src/raw_vec.rs +++ b/library/alloc/src/raw_vec.rs @@ -127,6 +127,7 @@ impl RawVec [A::CoAllocMeta; { meta_num_slots_default!(A) }] { loop {} } @@ -538,7 +539,9 @@ where /// Frees the memory owned by the `RawVec` *without* trying to drop its contents. default fn drop(&mut self) { if let Some((ptr, layout)) = self.current_memory() { - if A::CO_ALLOCATES_WITH_META && CO_ALLOC_PREF { + let meta_num_slots = crate::meta_num_slots!(A, CO_ALLOC_PREF); + if meta_num_slots!=0 { + debug_assert!(meta_num_slots==1, "Number of coallocation meta slots can be only 0 or 1, but it is {}!", meta_num_slots); let meta = self.metas[0]; unsafe { self.alloc.co_deallocate(PtrAndMeta { ptr, meta }, layout) } } else { diff --git a/library/alloc/src/vec/in_place_drop.rs b/library/alloc/src/vec/in_place_drop.rs index bf2d004e9db39..c61d81b37ecb8 100644 --- a/library/alloc/src/vec/in_place_drop.rs +++ b/library/alloc/src/vec/in_place_drop.rs @@ -36,6 +36,6 @@ impl Drop for InPlaceDstBufDrop { #[inline] fn drop(&mut self) { // false = no need for co-alloc metadata, since it would get lost once converted to Box. - unsafe { super::Vec::::from_raw_parts(self.ptr, self.len, self.cap) }; + unsafe { super::Vec::::from_raw_parts(self.ptr, self.len, self.cap) }; } } diff --git a/library/alloc/src/vec/into_iter.rs b/library/alloc/src/vec/into_iter.rs index 022c32f79febc..0d4d073122cc0 100644 --- a/library/alloc/src/vec/into_iter.rs +++ b/library/alloc/src/vec/into_iter.rs @@ -134,14 +134,16 @@ where // this creates less assembly self.cap = 0; self.buf = unsafe { - // @FIXME The below if CO_ALLOC_PREF {..} else {..} - // branching exists, because the following fails. Otherwise we'd have a snowball effect of wide spread of where...Global... + // @FIXME The below if .. {..} else {..} + // branching exists, because the following fails. Otherwise we'd have a snowball effect of wide spread of where...Global... bounds. // - // NonNull::new_unchecked(RawVec::::NEW.ptr()) - if CO_ALLOC_PREF { - NonNull::new_unchecked(RawVec::::NEW.ptr()) + //NonNull::new_unchecked(RawVec::::NEW.ptr()); + let meta_num_slots = crate::meta_num_slots!(A, CO_ALLOC_PREF); + if meta_num_slots>0 { + debug_assert!(meta_num_slots==1, "Number of coallocation meta slots can be only 0 or 1, but it is {}!", meta_num_slots); + NonNull::new_unchecked(RawVec::::NEW.ptr()) } else { - NonNull::new_unchecked(RawVec::::NEW.ptr()) + NonNull::new_unchecked(RawVec::::NEW.ptr()) } }; self.ptr = self.buf.as_ptr(); diff --git a/library/core/src/alloc/mod.rs b/library/core/src/alloc/mod.rs index a973cc18ab947..d763a666c3a75 100644 --- a/library/core/src/alloc/mod.rs +++ b/library/core/src/alloc/mod.rs @@ -51,7 +51,7 @@ impl fmt::Display for AllocError { /// (Non-Null) Pointer and coallocation metadata. #[unstable(feature = "global_co_alloc_meta", issue = "none")] #[derive(Clone, Copy, Debug)] -pub struct PtrAndMeta { +pub struct PtrAndMeta { pub ptr: NonNull, pub meta: M, } @@ -60,7 +60,7 @@ pub struct PtrAndMeta { #[unstable(feature = "global_co_alloc_meta", issue = "none")] #[derive(Clone, Copy, Debug)] /// Used for results (from `CoAllocator`'s functions, where applicable). -pub struct SliceAndMeta { +pub struct SliceAndMeta { pub slice: NonNull<[u8]>, pub meta: M, } @@ -70,6 +70,7 @@ pub struct SliceAndMeta { pub type SliceAndMetaResult = Result, AllocError>; #[unstable(feature = "global_co_alloc_meta", issue = "none")] +#[const_trait] pub trait CoAllocMetaBase: Clone + Copy { /// NOT for public use. This MAY BE REMOVED or CHANGED. /// @@ -90,7 +91,7 @@ pub struct CoAllocMetaPlain {} const CO_ALLOC_META_PLAIN: CoAllocMetaPlain = CoAllocMetaPlain {}; #[unstable(feature = "global_co_alloc_meta", issue = "none")] -impl CoAllocMetaBase for CoAllocMetaPlain { +impl const CoAllocMetaBase for CoAllocMetaPlain { const ZERO_METAS: [Self; 0] = []; const ONE_METAS: [Self; 1] = [CO_ALLOC_META_PLAIN]; @@ -188,7 +189,7 @@ pub unsafe trait Allocator { /// /// @FIXME Validate (preferrable at compile time, otherwise as a test) that this type's /// alignment <= `usize` alignment. - type CoAllocMeta: CoAllocMetaBase = CoAllocMetaPlain; + type CoAllocMeta: ~const CoAllocMetaBase = CoAllocMetaPlain; /// Attempts to allocate a block of memory. /// From 16f13bb209098372e6f8e376b1ac8e6fb1e5a666 Mon Sep 17 00:00:00 2001 From: Peter Kehl Date: Tue, 31 Jan 2023 13:23:57 -0800 Subject: [PATCH 095/118] CoAlloc: Using macros for config + transformations. WIP --- library/alloc/src/lib.rs | 1 + library/proc_macro/src/bridge/mod.rs | 5 +++-- library/proc_macro/src/bridge/rpc.rs | 10 +++++----- library/proc_macro/src/diagnostic.rs | 3 ++- library/proc_macro/src/lib.rs | 3 +++ library/std/src/io/cursor.rs | 20 +++++++++++++------- library/std/src/io/impls.rs | 16 ++++++++++------ library/std/src/lib.rs | 7 +++++++ library/test/src/lib.rs | 4 +++- 9 files changed, 47 insertions(+), 22 deletions(-) diff --git a/library/alloc/src/lib.rs b/library/alloc/src/lib.rs index cb11c6f6d9826..ad0e529f53eab 100644 --- a/library/alloc/src/lib.rs +++ b/library/alloc/src/lib.rs @@ -248,6 +248,7 @@ mod boxed { pub use std::boxed::Box; } pub mod borrow; +#[macro_use] #[unstable(feature = "global_co_alloc", issue = "none")] pub mod co_alloc; pub mod collections; diff --git a/library/proc_macro/src/bridge/mod.rs b/library/proc_macro/src/bridge/mod.rs index a20467d90b3a9..c3aff25e68eae 100644 --- a/library/proc_macro/src/bridge/mod.rs +++ b/library/proc_macro/src/bridge/mod.rs @@ -9,6 +9,7 @@ #![deny(unsafe_code)] use crate::{Delimiter, Level, LineColumn, Spacing}; +use std::alloc::Global; use std::fmt; use std::hash::Hash; use std::marker; @@ -252,14 +253,14 @@ impl<'a, T, M> Unmark for &'a mut Marked { } } -impl Mark for Vec { +impl Mark for Vec { type Unmarked = Vec; fn mark(unmarked: Self::Unmarked) -> Self { // Should be a no-op due to std's in-place collect optimizations. unmarked.into_iter().map(T::mark).collect() } } -impl Unmark for Vec { +impl Unmark for Vec { type Unmarked = Vec; fn unmark(self) -> Self::Unmarked { // Should be a no-op due to std's in-place collect optimizations. diff --git a/library/proc_macro/src/bridge/rpc.rs b/library/proc_macro/src/bridge/rpc.rs index 90be2a9ed26c4..fc856b98b2c33 100644 --- a/library/proc_macro/src/bridge/rpc.rs +++ b/library/proc_macro/src/bridge/rpc.rs @@ -4,9 +4,9 @@ use std::any::Any; use std::io::Write; use std::num::NonZeroU32; use std::str; -//use std::alloc::Global; -use alloc::alloc::Global; -use alloc::DEFAULT_CO_ALLOC_PREF; +use std::alloc::Global; +//use alloc::alloc::Global; +//use std::CO_ALLOC_PREF_DEFAULT; pub(super) type Writer = super::buffer::Buffer; @@ -227,7 +227,7 @@ impl DecodeMut<'_, '_, S> for String { } } -impl> Encode for Vec { +impl> Encode for Vec { fn encode(self, w: &mut Writer, s: &mut S) { self.len().encode(w, s); for x in self { @@ -237,7 +237,7 @@ impl> Encode for Vec { } impl<'a, S, T: for<'s> DecodeMut<'a, 's, S>> DecodeMut<'a, '_, S> - for Vec + for Vec { fn decode(r: &mut Reader<'a>, s: &mut S) -> Self { let len = usize::decode(r, s); diff --git a/library/proc_macro/src/diagnostic.rs b/library/proc_macro/src/diagnostic.rs index 5738938937cc3..13bd91286dad0 100644 --- a/library/proc_macro/src/diagnostic.rs +++ b/library/proc_macro/src/diagnostic.rs @@ -1,4 +1,5 @@ use crate::Span; +use std::alloc::Global; /// An enum representing a diagnostic level. #[unstable(feature = "proc_macro_diagnostic", issue = "54140")] @@ -30,7 +31,7 @@ impl MultiSpan for Span { } #[unstable(feature = "proc_macro_diagnostic", issue = "54140")] -impl MultiSpan for Vec { +impl MultiSpan for Vec { fn into_spans(self) -> Vec { self } diff --git a/library/proc_macro/src/lib.rs b/library/proc_macro/src/lib.rs index 72e9cfea99508..5e6be69bf8102 100644 --- a/library/proc_macro/src/lib.rs +++ b/library/proc_macro/src/lib.rs @@ -22,6 +22,7 @@ // to make it compile with rust-analyzer on stable. #![feature(rustc_allow_const_fn_unstable)] #![feature(staged_api)] +#![feature(allocator_api)] #![feature(allow_internal_unstable)] #![feature(decl_macro)] #![feature(local_key_cell_methods)] @@ -33,7 +34,9 @@ #![feature(min_specialization)] #![feature(strict_provenance)] #![recursion_limit = "256"] +#![feature(global_co_alloc)] #![feature(global_co_alloc_default)] +#![feature(global_co_alloc_meta)] #[unstable(feature = "proc_macro_internals", issue = "27812")] #[doc(hidden)] diff --git a/library/std/src/io/cursor.rs b/library/std/src/io/cursor.rs index d7aee680d1186..5eb5cba4531df 100644 --- a/library/std/src/io/cursor.rs +++ b/library/std/src/io/cursor.rs @@ -6,7 +6,7 @@ use crate::io::prelude::*; use crate::alloc::Allocator; use crate::cmp; use crate::io::{self, BorrowedCursor, ErrorKind, IoSlice, IoSliceMut, SeekFrom}; -use core::alloc; +use ::alloc::{co_alloc::CoAllocPref, meta_num_slots}; /// A `Cursor` wraps an in-memory buffer and provides it with a /// [`Seek`] implementation. @@ -398,13 +398,14 @@ fn slice_write_vectored( } /// Reserves the required space, and pads the vec with 0s if necessary. +#[allow(unused_braces)] fn reserve_and_pad( pos_mut: &mut u64, vec: &mut Vec, buf_len: usize, ) -> io::Result where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, + [(); {meta_num_slots!(A, CO_ALLOC_PREF)}]:, { let pos: usize = (*pos_mut).try_into().map_err(|_| { io::const_io_error!( @@ -444,6 +445,7 @@ where /// Writes the slice to the vec without allocating /// # Safety: vec must have buf.len() spare capacity +#[allow(unused_braces)] unsafe fn vec_write_unchecked( pos: usize, vec: &mut Vec, @@ -451,7 +453,7 @@ unsafe fn vec_write_unchecked( ) -> usize where A: Allocator, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, + [(); {meta_num_slots!(A, CO_ALLOC_PREF)}]:, { debug_assert!(vec.capacity() >= pos + buf.len()); vec.as_mut_ptr().add(pos).copy_from(buf.as_ptr(), buf.len()); @@ -467,6 +469,7 @@ where /// This also allows for the vec body to be empty, but with a position of N. /// This means that [`Write`] will pad the vec with 0 initially, /// before writing anything from that point +#[allow(unused_braces)] fn vec_write( pos_mut: &mut u64, vec: &mut Vec, @@ -474,7 +477,7 @@ fn vec_write( ) -> io::Result where A: Allocator, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, + [(); {meta_num_slots!(A, CO_ALLOC_PREF)}]:, { let buf_len = buf.len(); let mut pos = reserve_and_pad(pos_mut, vec, buf_len)?; @@ -503,6 +506,7 @@ where /// This also allows for the vec body to be empty, but with a position of N. /// This means that [`Write`] will pad the vec with 0 initially, /// before writing anything from that point +#[allow(unused_braces)] fn vec_write_vectored( pos_mut: &mut u64, vec: &mut Vec, @@ -510,7 +514,7 @@ fn vec_write_vectored( ) -> io::Result where A: Allocator, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, + [(); {meta_num_slots!(A, CO_ALLOC_PREF)}]:, { // For safety reasons, we don't want this sum to overflow ever. // If this saturates, the reserve should panic to avoid any unsound writing. @@ -558,10 +562,11 @@ impl Write for Cursor<&mut [u8]> { } #[stable(feature = "cursor_mut_vec", since = "1.25.0")] +#[allow(unused_braces)] impl Write for Cursor<&mut Vec> where A: Allocator, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, + [(); {meta_num_slots!(A, CO_ALLOC_PREF)}]:, { fn write(&mut self, buf: &[u8]) -> io::Result { vec_write(&mut self.pos, self.inner, buf) @@ -583,10 +588,11 @@ where } #[stable(feature = "rust1", since = "1.0.0")] +#[allow(unused_braces)] impl Write for Cursor> where A: Allocator, - [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, + [(); {meta_num_slots!(A, CO_ALLOC_PREF)}]:, { fn write(&mut self, buf: &[u8]) -> io::Result { vec_write(&mut self.pos, &mut self.inner, buf) diff --git a/library/std/src/io/impls.rs b/library/std/src/io/impls.rs index 6e07869e3d075..284c11374e8c1 100644 --- a/library/std/src/io/impls.rs +++ b/library/std/src/io/impls.rs @@ -1,7 +1,7 @@ #[cfg(test)] mod tests; -use crate::alloc::{self, Allocator}; +use crate::alloc::Allocator; use crate::cmp; use crate::collections::VecDeque; use crate::fmt; @@ -9,6 +9,7 @@ use crate::io::{ self, BorrowedCursor, BufRead, ErrorKind, IoSlice, IoSliceMut, Read, Seek, SeekFrom, Write, }; use crate::mem; +use ::alloc::{co_alloc::CoAllocPref, meta_num_slots}; // ============================================================================= // Forwarding implementations @@ -378,9 +379,10 @@ impl Write for &mut [u8] { /// Write is implemented for `Vec` by appending to the vector. /// The vector will grow as needed. #[stable(feature = "rust1", since = "1.0.0")] +#[allow(unused_braces)] impl Write for Vec where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(CO_ALLOC_PREF)]:, + [(); {meta_num_slots!(A, CO_ALLOC_PREF)}]:, { #[inline] fn write(&mut self, buf: &[u8]) -> io::Result { @@ -417,9 +419,10 @@ where /// Read is implemented for `VecDeque` by consuming bytes from the front of the `VecDeque`. #[stable(feature = "vecdeque_read_write", since = "1.63.0")] -impl Read for VecDeque +#[allow(unused_braces)] +impl Read for VecDeque where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(_CO_ALLOC_PREF)]:, + [(); {meta_num_slots!(A, CO_ALLOC_PREF)}]:, { /// Fill `buf` with the contents of the "front" slice as returned by /// [`as_slices`][`VecDeque::as_slices`]. If the contained byte slices of the `VecDeque` are @@ -444,9 +447,10 @@ where /// Write is implemented for `VecDeque` by appending to the `VecDeque`, growing it as needed. #[stable(feature = "vecdeque_read_write", since = "1.63.0")] -impl Write for VecDeque +#[allow(unused_braces)] +impl Write for VecDeque where - [(); alloc::co_alloc_metadata_num_slots_with_preference::(_CO_ALLOC_PREF)]:, + [(); {meta_num_slots!(A, CO_ALLOC_PREF)}]:, { #[inline] fn write(&mut self, buf: &[u8]) -> io::Result { diff --git a/library/std/src/lib.rs b/library/std/src/lib.rs index 5999b12f3b5d7..ba7c216aedee7 100644 --- a/library/std/src/lib.rs +++ b/library/std/src/lib.rs @@ -217,7 +217,9 @@ #![allow(incomplete_features)] #![feature(generic_const_exprs)] #![feature(global_co_alloc)] +#![feature(global_co_alloc_default)] #![feature(global_co_alloc_plvec)] +#![feature(global_co_alloc_meta)] #![warn(deprecated_in_future)] #![warn(missing_docs)] #![warn(missing_debug_implementations)] @@ -415,6 +417,11 @@ pub mod prelude; pub use alloc_crate::borrow; #[stable(feature = "rust1", since = "1.0.0")] pub use alloc_crate::boxed; +#[unstable(feature = "global_co_alloc", issue = "none")] +pub use alloc_crate::co_alloc; +// @FIXME ugly - someone move this to a better place, please +#[unstable(feature = "global_co_alloc", issue = "none")] +pub use alloc_crate::{CO_ALLOC_PREF_DEFAULT}; #[stable(feature = "rust1", since = "1.0.0")] pub use alloc_crate::fmt; #[stable(feature = "rust1", since = "1.0.0")] diff --git a/library/test/src/lib.rs b/library/test/src/lib.rs index 69fb529d7f563..4dc5f01b87aec 100644 --- a/library/test/src/lib.rs +++ b/library/test/src/lib.rs @@ -16,6 +16,7 @@ #![unstable(feature = "test", issue = "50297")] #![doc(test(attr(deny(warnings))))] +#![feature(allocator_api)] #![feature(internal_output_capture)] #![feature(is_terminal)] #![feature(staged_api)] @@ -52,6 +53,7 @@ pub mod test { } use std::{ + alloc::Global, collections::VecDeque, env, io, io::prelude::Write, @@ -346,7 +348,7 @@ where }; let mut running_tests: TestMap = HashMap::default(); - let mut timeout_queue: VecDeque = VecDeque::new(); + let mut timeout_queue: VecDeque = VecDeque::new(); fn get_timed_out_tests( running_tests: &TestMap, From 6afb0d6c5803d5fccbde3726db6f014db7b7fd99 Mon Sep 17 00:00:00 2001 From: Peter Kehl Date: Tue, 31 Jan 2023 13:51:11 -0800 Subject: [PATCH 096/118] CoAlloc: (Some) Separation of co-alloc-aware traits & methods. --- .../alloc/src/collections/vec_deque/mod.rs | 33 +++++++------------ library/std/src/lib.rs | 2 +- library/test/src/lib.rs | 3 ++ library/test/src/stats.rs | 2 +- 4 files changed, 17 insertions(+), 23 deletions(-) diff --git a/library/alloc/src/collections/vec_deque/mod.rs b/library/alloc/src/collections/vec_deque/mod.rs index 229c3261f63d9..3ec9ef80c435c 100644 --- a/library/alloc/src/collections/vec_deque/mod.rs +++ b/library/alloc/src/collections/vec_deque/mod.rs @@ -160,14 +160,12 @@ where #[stable(feature = "rust1", since = "1.0.0")] #[allow(unused_braces)] -impl Default for VecDeque -where - [(); {meta_num_slots_global!(CO_ALLOC_PREF)}]:, +impl Default for VecDeque { /// Creates an empty deque. #[inline] - fn default() -> VecDeque { - VecDeque::::new() + fn default() -> VecDeque { + VecDeque::::new() } } @@ -554,12 +552,7 @@ where } } -#[allow(unused_braces)] -impl VecDeque -where - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, - [(); {crate::meta_num_slots_global!(CO_ALLOC_PREF)}]:, -{ +impl VecDeque { /// Creates an empty deque. /// /// # Examples @@ -573,14 +566,13 @@ where #[stable(feature = "rust1", since = "1.0.0")] #[rustc_const_stable(feature = "const_vec_deque_new", since = "1.68.0")] #[must_use] - pub const fn new() -> VecDeque - where - [(); {crate::meta_num_slots_global!(CO_ALLOC_PREF)}]:, + #[allow(unused_braces)] + pub const fn new() -> VecDeque { // FIXME: This should just be `VecDeque::new_in(Global)` once that hits stable. VecDeque { head: 0, len: 0, buf: RawVec::NEW } } - + /// Creates an empty deque with space for at least `capacity` elements. /// /// # Examples @@ -593,8 +585,9 @@ where #[inline] #[stable(feature = "rust1", since = "1.0.0")] #[must_use] - pub fn with_capacity(capacity: usize) -> VecDeque { - VecDeque::::with_capacity_in(capacity, Global) + #[allow(unused_braces)] + pub fn with_capacity(capacity: usize) -> VecDeque { + VecDeque::::with_capacity_in(capacity, Global) } } @@ -3006,9 +2999,7 @@ where #[stable(feature = "std_collections_from_array", since = "1.56.0")] #[allow(unused_braces)] -impl From<[T; N]> for VecDeque -where - [(); {meta_num_slots_global!(CO_ALLOC_PREF)}]:, +impl From<[T; N]> for VecDeque { /// Converts a `[T; N]` into a `VecDeque`. /// @@ -3020,7 +3011,7 @@ where /// assert_eq!(deq1, deq2); /// ``` fn from(arr: [T; N]) -> Self { - let mut deq = VecDeque::::with_capacity(N); + let mut deq = VecDeque::::with_capacity(N); let arr = ManuallyDrop::new(arr); if !::IS_ZST { // SAFETY: VecDeque::with_capacity ensures that there is enough capacity. diff --git a/library/std/src/lib.rs b/library/std/src/lib.rs index ba7c216aedee7..c05ea98f3b41a 100644 --- a/library/std/src/lib.rs +++ b/library/std/src/lib.rs @@ -421,7 +421,7 @@ pub use alloc_crate::boxed; pub use alloc_crate::co_alloc; // @FIXME ugly - someone move this to a better place, please #[unstable(feature = "global_co_alloc", issue = "none")] -pub use alloc_crate::{CO_ALLOC_PREF_DEFAULT}; +pub use alloc_crate::{CO_ALLOC_PREF_DEFAULT, SHORT_TERM_VEC_CO_ALLOC_PREF}; #[stable(feature = "rust1", since = "1.0.0")] pub use alloc_crate::fmt; #[stable(feature = "rust1", since = "1.0.0")] diff --git a/library/test/src/lib.rs b/library/test/src/lib.rs index 4dc5f01b87aec..bf28cde1bf033 100644 --- a/library/test/src/lib.rs +++ b/library/test/src/lib.rs @@ -17,6 +17,8 @@ #![unstable(feature = "test", issue = "50297")] #![doc(test(attr(deny(warnings))))] #![feature(allocator_api)] +#![feature(global_co_alloc)] +#![feature(global_co_alloc_meta)] #![feature(internal_output_capture)] #![feature(is_terminal)] #![feature(staged_api)] @@ -348,6 +350,7 @@ where }; let mut running_tests: TestMap = HashMap::default(); + // @FIXME See if we can remove `Global` generic param: let mut timeout_queue: VecDeque = VecDeque::new(); fn get_timed_out_tests( diff --git a/library/test/src/stats.rs b/library/test/src/stats.rs index b33b080126131..78711b2e928b5 100644 --- a/library/test/src/stats.rs +++ b/library/test/src/stats.rs @@ -232,7 +232,7 @@ impl Stats for [f64] { } fn percentile(&self, pct: f64) -> f64 { - let mut tmp = self.to_vec(); + let mut tmp = self.to_vec::<{std::SHORT_TERM_VEC_CO_ALLOC_PREF!()}>(); local_sort(&mut tmp); percentile_of_sorted(&tmp, pct) } From b20534f7c899d29bc71a9e655e432569b95713b4 Mon Sep 17 00:00:00 2001 From: Peter Kehl Date: Tue, 31 Jan 2023 16:49:42 -0800 Subject: [PATCH 097/118] CoAlloc: Undoing generalizations + splitting. WIP --- library/alloc/src/boxed.rs | 2 +- library/alloc/src/slice.rs | 135 ++++++++++++++++++++++++++--- library/alloc/src/vec/into_iter.rs | 2 +- library/alloc/src/vec/mod.rs | 2 +- library/test/src/stats.rs | 5 +- 5 files changed, 130 insertions(+), 16 deletions(-) diff --git a/library/alloc/src/boxed.rs b/library/alloc/src/boxed.rs index 7d91fc8bdeb12..23c7cab817f68 100644 --- a/library/alloc/src/boxed.rs +++ b/library/alloc/src/boxed.rs @@ -2051,7 +2051,7 @@ where fn clone(&self) -> Self { let alloc = Box::allocator(self).clone(); // false = no need for co-alloc metadata, since it would get lost once converted to the boxed slice. - self.to_vec_in::(alloc).into_boxed_slice() + self.to_vec_in_co::(alloc).into_boxed_slice() } fn clone_from(&mut self, other: &Self) { diff --git a/library/alloc/src/slice.rs b/library/alloc/src/slice.rs index acd453fbb4803..56f5575b1dff4 100644 --- a/library/alloc/src/slice.rs +++ b/library/alloc/src/slice.rs @@ -114,20 +114,44 @@ pub(crate) mod hack { #[cfg(not(no_global_oom_handling))] #[inline] #[allow(unused_braces)] - pub fn to_vec( + pub fn to_vec( + s: &[T], + alloc: A, + ) -> Vec + where + [(); {crate::meta_num_slots_default!(A)}]:, + { + T::to_vec(s, alloc) + } + + #[cfg(not(no_global_oom_handling))] + #[inline] + #[allow(unused_braces)] + pub fn to_vec_co( s: &[T], alloc: A, ) -> Vec where [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, { - T::to_vec(s, alloc) + T::to_vec_co(s, alloc) } #[cfg(not(no_global_oom_handling))] #[allow(unused_braces)] pub trait ConvertVec { - fn to_vec( + fn to_vec( + s: &[Self], + alloc: A, + ) -> Vec + where + Self: Sized, + [(); {crate::meta_num_slots_default!(A)}]:; + } + + #[allow(unused_braces)] + pub trait ConvertVecCo { + fn to_vec_co( s: &[Self], alloc: A, ) -> Vec @@ -141,7 +165,82 @@ pub(crate) mod hack { impl ConvertVec for T { #[inline] #[allow(unused_braces)] - default fn to_vec( + default fn to_vec( + s: &[Self], + alloc: A, + ) -> Vec + where + [(); {crate::meta_num_slots_default!(A)}]:, + { + #[allow(unused_braces)] + struct DropGuard<'a, T, A: Allocator> + where + [(); {crate::meta_num_slots_default!(A)}]:, + { + vec: &'a mut Vec, + num_init: usize, + } + impl<'a, T, A: Allocator> Drop for DropGuard<'a, T, A> + where + [(); {crate::meta_num_slots_default!(A)}]:, + { + #[inline] + fn drop(&mut self) { + // SAFETY: + // items were marked initialized in the loop below + unsafe { + self.vec.set_len(self.num_init); + } + } + } + let mut vec = Vec::with_capacity_in(s.len(), alloc); + let mut guard = DropGuard { vec: &mut vec, num_init: 0 }; + let slots = guard.vec.spare_capacity_mut(); + // .take(slots.len()) is necessary for LLVM to remove bounds checks + // and has better codegen than zip. + for (i, b) in s.iter().enumerate().take(slots.len()) { + guard.num_init = i; + slots[i].write(b.clone()); + } + core::mem::forget(guard); + // SAFETY: + // the vec was allocated and initialized above to at least this length. + unsafe { + vec.set_len(s.len()); + } + vec + } + } + + #[cfg(not(no_global_oom_handling))] + impl ConvertVec for T { + #[inline] + #[allow(unused_braces)] + fn to_vec( + s: &[Self], + alloc: A, + ) -> Vec + where + [(); {crate::meta_num_slots_default!(A)}]:, + { + let mut v = Vec::with_capacity_in(s.len(), alloc); + // SAFETY: + // allocated above with the capacity of `s`, and initialize to `s.len()` in + // ptr::copy_to_non_overlapping below. + unsafe { + s.as_ptr().copy_to_nonoverlapping(v.as_mut_ptr(), s.len()); + v.set_len(s.len()); + } + v + } + } + + #[cfg(not(no_global_oom_handling))] + #[allow(unused_braces)] + impl ConvertVecCo for T { + #[inline] + #[allow(unused_braces)] + default fn to_vec_co( s: &[Self], alloc: A, ) -> Vec @@ -189,10 +288,10 @@ pub(crate) mod hack { } #[cfg(not(no_global_oom_handling))] - impl ConvertVec for T { + impl ConvertVecCo for T { #[inline] #[allow(unused_braces)] - fn to_vec( + fn to_vec_co( s: &[Self], alloc: A, ) -> Vec @@ -209,8 +308,7 @@ pub(crate) mod hack { } v } - } -} + }} #[cfg(not(test))] impl [T] { @@ -455,7 +553,7 @@ impl [T] { T: Clone, [(); {meta_num_slots_global!(CO_ALLOC_PREF)}]:, { - self.to_vec_in::(Global) + self.to_vec_in_co::(Global) } /// Copies `self` into a new `Vec` with an allocator. @@ -476,15 +574,30 @@ impl [T] { #[inline] #[unstable(feature = "allocator_api", issue = "32838")] #[allow(unused_braces)] - pub fn to_vec_in(&self, alloc: A) -> Vec + pub fn to_vec_in(&self, alloc: A) -> Vec where T: Clone, - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, + [(); {crate::meta_num_slots_default!(A)}]:, { // N.B., see the `hack` module in this file for more details. hack::to_vec(self, alloc) } + /// Coallocation-aware version of `to_vec_in`. + #[cfg(not(no_global_oom_handling))] + #[rustc_allow_incoherent_impl] + #[inline] + #[unstable(feature = "allocator_api", issue = "32838")] + #[allow(unused_braces)] + pub fn to_vec_in_co(&self, alloc: A) -> Vec + where + T: Clone, + [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, + { + // N.B., see the `hack` module in this file for more details. + hack::to_vec_co(self, alloc) + } + /// Converts `self` into a vector without clones or allocation. /// /// The resulting vector can be converted back into a box via diff --git a/library/alloc/src/vec/into_iter.rs b/library/alloc/src/vec/into_iter.rs index 0d4d073122cc0..97d1f51b2eeb2 100644 --- a/library/alloc/src/vec/into_iter.rs +++ b/library/alloc/src/vec/into_iter.rs @@ -439,7 +439,7 @@ where // @FIXME Remove the following extras - used for type checks only let slice = self.as_slice(); let vec: crate::vec::Vec = - slice.to_vec_in::(self.alloc.deref().clone()); + slice.to_vec_in_co::(self.alloc.deref().clone()); let _iter: IntoIter = vec.into_iter(); //self.as_slice().to_vec_in::(self.alloc.deref().clone()).into_iter() diff --git a/library/alloc/src/vec/mod.rs b/library/alloc/src/vec/mod.rs index 8dc14d89c5141..5ebc3484bd90b 100644 --- a/library/alloc/src/vec/mod.rs +++ b/library/alloc/src/vec/mod.rs @@ -2826,7 +2826,7 @@ where #[cfg(not(test))] fn clone(&self) -> Self { let alloc = self.allocator().clone(); - <[T]>::to_vec_in(&**self, alloc) + <[T]>::to_vec_in_co(&**self, alloc) } // HACK(japaric): with cfg(test) the inherent `[T]::to_vec` method, which is diff --git a/library/test/src/stats.rs b/library/test/src/stats.rs index 78711b2e928b5..59a669c6f91e6 100644 --- a/library/test/src/stats.rs +++ b/library/test/src/stats.rs @@ -1,6 +1,7 @@ #![allow(missing_docs)] use std::mem; +use std::SHORT_TERM_VEC_CO_ALLOC_PREF; #[cfg(test)] mod tests; @@ -232,13 +233,13 @@ impl Stats for [f64] { } fn percentile(&self, pct: f64) -> f64 { - let mut tmp = self.to_vec::<{std::SHORT_TERM_VEC_CO_ALLOC_PREF!()}>(); + let mut tmp = self.to_vec_co::<{SHORT_TERM_VEC_CO_ALLOC_PREF!()}>(); local_sort(&mut tmp); percentile_of_sorted(&tmp, pct) } fn quartiles(&self) -> (f64, f64, f64) { - let mut tmp = self.to_vec(); + let mut tmp = self.to_vec_co::<{SHORT_TERM_VEC_CO_ALLOC_PREF!()}>(); local_sort(&mut tmp); let first = 25_f64; let a = percentile_of_sorted(&tmp, first); From b231c87ffa1d90c2d834a9c261e58bf8d05c3bcb Mon Sep 17 00:00:00 2001 From: Peter Kehl Date: Tue, 31 Jan 2023 22:10:59 -0800 Subject: [PATCH 098/118] CoAlloc: slice::to_vec_co, slice::to_vec_in_co. --- library/alloc/src/slice.rs | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/library/alloc/src/slice.rs b/library/alloc/src/slice.rs index 56f5575b1dff4..aea33283a0c67 100644 --- a/library/alloc/src/slice.rs +++ b/library/alloc/src/slice.rs @@ -85,6 +85,9 @@ pub use hack::into_vec; #[cfg(test)] pub use hack::to_vec; +#[cfg(test)] +pub use hack::to_vec_co; + // HACK(japaric): With cfg(test) `impl [T]` is not available, these three // functions are actually methods that are in `impl [T]` but not in // `core::slice::SliceExt` - we need to supply these functions for the @@ -548,7 +551,20 @@ impl [T] { #[rustc_conversion_suggestion] #[stable(feature = "rust1", since = "1.0.0")] #[inline] - pub fn to_vec(&self) -> Vec + pub fn to_vec(&self) -> Vec + where T:Clone + { + self.to_vec_in::(Global) + } + + /// Coallocation-aware alternative to `to_vec`. + #[cfg(not(no_global_oom_handling))] + #[rustc_allow_incoherent_impl] + #[allow(unused_braces)] + #[rustc_conversion_suggestion] + #[unstable(feature = "global_co_alloc", issue = "none")] + #[inline] + pub fn to_vec_co(&self) -> Vec where T: Clone, [(); {meta_num_slots_global!(CO_ALLOC_PREF)}]:, @@ -587,7 +603,7 @@ impl [T] { #[cfg(not(no_global_oom_handling))] #[rustc_allow_incoherent_impl] #[inline] - #[unstable(feature = "allocator_api", issue = "32838")] + #[unstable(feature = "global_co_alloc", issue = "none")] #[allow(unused_braces)] pub fn to_vec_in_co(&self, alloc: A) -> Vec where From b1c8971b379dd775092fd0f9708047523de27ae8 Mon Sep 17 00:00:00 2001 From: Peter Kehl Date: Wed, 1 Feb 2023 14:02:41 -0800 Subject: [PATCH 099/118] CoAlloc: Separated Vec::from_raw_parts_co and similar (and also in VecDeque). Mostly compiling. --- .../alloc/src/collections/vec_deque/mod.rs | 33 ++++++++++- .../collections/vec_deque/spec_from_iter.rs | 56 ++++++++++++++++--- library/alloc/src/vec/in_place_collect.rs | 2 +- library/alloc/src/vec/mod.rs | 27 ++++++++- library/alloc/src/vec/spec_from_iter.rs | 2 +- 5 files changed, 105 insertions(+), 15 deletions(-) diff --git a/library/alloc/src/collections/vec_deque/mod.rs b/library/alloc/src/collections/vec_deque/mod.rs index 3ec9ef80c435c..bfa1475053cb3 100644 --- a/library/alloc/src/collections/vec_deque/mod.rs +++ b/library/alloc/src/collections/vec_deque/mod.rs @@ -57,7 +57,7 @@ use self::spec_extend::SpecExtend; mod spec_extend; -use self::spec_from_iter::SpecFromIter; +use self::spec_from_iter::SpecFromIterCo; mod spec_from_iter; @@ -2809,7 +2809,7 @@ where [(); {crate::meta_num_slots_global!(CO_ALLOC_PREF)}]:, { fn from_iter>(iter: I) -> VecDeque { - SpecFromIter::spec_from_iter(iter.into_iter()) + SpecFromIterCo::spec_from_iter_co(iter.into_iter()) } } @@ -2911,6 +2911,33 @@ where } } +#[stable(feature = "vecdeque_vec_conversions", since = "1.10.0")] +#[allow(unused_braces)] +impl + From> for VecDeque//, CO_ALLOC_PREF> +where + //[(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, + [(); {crate::meta_num_slots!(A, OTHER_CO_ALLOC_PREF)}]:, +{ + /// Turn a [`Vec`] into a [`VecDeque`]. + /// + /// [`Vec`]: crate::vec::Vec + /// [`VecDeque`]: crate::collections::VecDeque + /// + /// This conversion is guaranteed to run in *O*(1) time + /// and to not re-allocate the `Vec`'s buffer or allocate + /// any additional memory. + #[inline] + default fn from(other: Vec) -> Self { + let (ptr, len, cap, alloc) = other.into_raw_parts_with_alloc(); + Self { + head: 0, + len, + buf: unsafe { RawVec::::from_raw_parts_in(ptr, cap, alloc) }, + } + } +} + #[stable(feature = "vecdeque_vec_conversions", since = "1.10.0")] #[allow(unused_braces)] impl @@ -2928,7 +2955,7 @@ where /// and to not re-allocate the `Vec`'s buffer or allocate /// any additional memory. #[inline] - fn from(other: Vec) -> Self { + default fn from(other: Vec) -> Self { let (ptr, len, cap, alloc) = other.into_raw_parts_with_alloc(); Self { head: 0, diff --git a/library/alloc/src/collections/vec_deque/spec_from_iter.rs b/library/alloc/src/collections/vec_deque/spec_from_iter.rs index b85aaa20da8fb..54cbe40ea692a 100644 --- a/library/alloc/src/collections/vec_deque/spec_from_iter.rs +++ b/library/alloc/src/collections/vec_deque/spec_from_iter.rs @@ -7,41 +7,81 @@ pub(super) trait SpecFromIter { fn spec_from_iter(iter: I) -> Self; } +/// Specialization trait used for `VecDeque::from_iter_co` +pub(super) trait SpecFromIterCo { + fn spec_from_iter_co(iter: I) -> Self; +} + #[allow(unused_braces)] -impl SpecFromIter for VecDeque +impl SpecFromIter for VecDeque where I: Iterator, - [(); {crate::meta_num_slots_global!(CO_ALLOC_PREF)}]:, { default fn spec_from_iter(iterator: I) -> Self { // Since converting is O(1) now, just re-use the `Vec` logic for // anything where we can't do something extra-special for `VecDeque`, // especially as that could save us some monomorphiziation work // if one uses the same iterators (like slice ones) with both. - crate::vec::Vec::::from_iter(iterator).into() + crate::vec::Vec::from_iter(iterator).into() + } +} + +#[allow(unused_braces)] +impl SpecFromIter> + for VecDeque +{ + #[inline] + fn spec_from_iter(iterator: crate::vec::IntoIter) -> Self { + iterator.into_vecdeque() + } +} + +#[allow(unused_braces)] +impl SpecFromIter> + for VecDeque +{ + #[inline] + fn spec_from_iter(iterator: IntoIter) -> Self { + iterator.into_vecdeque() + } +} +// ---- + +#[allow(unused_braces)] +impl SpecFromIterCo for VecDeque +where + I: Iterator, + [(); {crate::meta_num_slots_global!(CO_ALLOC_PREF)}]:, +{ + default fn spec_from_iter_co(iterator: I) -> Self { + // Since converting is O(1) now, just re-use the `Vec` logic for + // anything where we can't do something extra-special for `VecDeque`, + // especially as that could save us some monomorphiziation work + // if one uses the same iterators (like slice ones) with both. + crate::vec::Vec::::from_iter_co(iterator).into() } } #[allow(unused_braces)] -impl SpecFromIter> +impl SpecFromIterCo> for VecDeque where [(); {crate::meta_num_slots_global!(CO_ALLOC_PREF)}]:, { #[inline] - fn spec_from_iter(iterator: crate::vec::IntoIter) -> Self { + fn spec_from_iter_co(iterator: crate::vec::IntoIter) -> Self { iterator.into_vecdeque() } } #[allow(unused_braces)] -impl SpecFromIter> +impl SpecFromIterCo> for VecDeque where [(); {crate::meta_num_slots_global!(CO_ALLOC_PREF)}]:, { #[inline] - fn spec_from_iter(iterator: IntoIter) -> Self { + fn spec_from_iter_co(iterator: IntoIter) -> Self { iterator.into_vecdeque() } -} +} \ No newline at end of file diff --git a/library/alloc/src/vec/in_place_collect.rs b/library/alloc/src/vec/in_place_collect.rs index b5d7588b26d63..2e51f655d2bcf 100644 --- a/library/alloc/src/vec/in_place_collect.rs +++ b/library/alloc/src/vec/in_place_collect.rs @@ -210,7 +210,7 @@ where src.forget_allocation_drop_remaining(); mem::forget(dst_guard); - let vec = unsafe { Vec::from_raw_parts(dst_buf, len, cap) }; + let vec = unsafe { Vec::from_raw_parts_co(dst_buf, len, cap) }; vec } diff --git a/library/alloc/src/vec/mod.rs b/library/alloc/src/vec/mod.rs index 5ebc3484bd90b..dabd0cff0fdef 100644 --- a/library/alloc/src/vec/mod.rs +++ b/library/alloc/src/vec/mod.rs @@ -588,6 +588,17 @@ where Self::with_capacity_in(capacity, Global) } + /// Coallocation-aware alternative to `from_row_parts`. + #[inline] + #[unstable(feature = "global_co_alloc", issue = "none")] + pub unsafe fn from_raw_parts_co(ptr: *mut T, length: usize, capacity: usize) -> Self { + unsafe { Self::from_raw_parts_in(ptr, length, capacity, Global) } + } + +} + +impl Vec +{ /// Creates a `Vec` directly from a pointer, a capacity, and a length. /// /// # Safety @@ -2906,12 +2917,24 @@ where #[cfg(not(no_global_oom_handling))] #[stable(feature = "rust1", since = "1.0.0")] #[allow(unused_braces)] -impl FromIterator for Vec +impl FromIterator for Vec +{ + #[inline] + fn from_iter>(iter: I) -> Vec { + >::from_iter(iter.into_iter()) + } +} + +#[cfg(not(no_global_oom_handling))] +#[unstable(feature = "global_co_alloc", issue="none")] +#[allow(unused_braces)] +impl Vec where [(); {crate::meta_num_slots_global!(CO_ALLOC_PREF)}]:, { + /// Coallocation-aware alternative to `from_iter`. #[inline] - fn from_iter>(iter: I) -> Vec { + pub fn from_iter_co>(iter: I) -> Vec { >::from_iter(iter.into_iter()) } } diff --git a/library/alloc/src/vec/spec_from_iter.rs b/library/alloc/src/vec/spec_from_iter.rs index a8383808e4210..be46209748e9b 100644 --- a/library/alloc/src/vec/spec_from_iter.rs +++ b/library/alloc/src/vec/spec_from_iter.rs @@ -59,7 +59,7 @@ where if has_advanced { ptr::copy(it.ptr, it.buf.as_ptr(), it.len()); } - return Vec::from_raw_parts(it.buf.as_ptr(), it.len(), it.cap); + return Vec::from_raw_parts_co(it.buf.as_ptr(), it.len(), it.cap); } } From 053a4b9164517f348ac4f9c80f6242c30495fdce Mon Sep 17 00:00:00 2001 From: Peter Kehl Date: Wed, 1 Feb 2023 14:05:55 -0800 Subject: [PATCH 100/118] CoAlloc: tidy --- library/alloc/src/boxed.rs | 37 ++-- library/alloc/src/co_alloc.rs | 6 +- .../alloc/src/collections/binary_heap/mod.rs | 12 +- .../alloc/src/collections/vec_deque/drain.rs | 53 +++--- .../src/collections/vec_deque/into_iter.rs | 36 ++-- .../alloc/src/collections/vec_deque/mod.rs | 119 ++++++------ .../src/collections/vec_deque/spec_extend.rs | 22 +-- .../collections/vec_deque/spec_from_iter.rs | 22 ++- library/alloc/src/macros.rs | 31 ++-- library/alloc/src/raw_vec.rs | 26 +-- library/alloc/src/rc.rs | 4 +- library/alloc/src/slice.rs | 80 ++++----- library/alloc/src/str.rs | 2 +- library/alloc/src/vec/drain.rs | 61 ++++--- library/alloc/src/vec/drain_filter.rs | 20 ++- library/alloc/src/vec/in_place_collect.rs | 2 +- library/alloc/src/vec/in_place_drop.rs | 6 +- library/alloc/src/vec/into_iter.rs | 92 ++++++---- library/alloc/src/vec/mod.rs | 169 ++++++++++-------- library/alloc/src/vec/spec_extend.rs | 23 +-- library/alloc/src/vec/spec_from_elem.rs | 10 +- library/alloc/src/vec/spec_from_iter.rs | 7 +- .../alloc/src/vec/spec_from_iter_nested.rs | 5 +- library/alloc/src/vec/splice.rs | 20 ++- library/core/src/alloc/mod.rs | 8 +- library/proc_macro/src/bridge/mod.rs | 4 +- library/proc_macro/src/bridge/rpc.rs | 6 +- library/proc_macro/src/diagnostic.rs | 2 +- library/std/src/io/cursor.rs | 12 +- library/std/src/io/impls.rs | 6 +- library/std/src/lib.rs | 4 +- library/test/src/stats.rs | 4 +- 32 files changed, 516 insertions(+), 395 deletions(-) diff --git a/library/alloc/src/boxed.rs b/library/alloc/src/boxed.rs index 23c7cab817f68..439e2a8001678 100644 --- a/library/alloc/src/boxed.rs +++ b/library/alloc/src/boxed.rs @@ -146,6 +146,7 @@ #![stable(feature = "rust1", since = "1.0.0")] +use crate::co_alloc::CoAllocPref; use core::any::Any; use core::async_iter::AsyncIterator; use core::borrow; @@ -167,7 +168,6 @@ use core::ops::{ use core::pin::Pin; use core::ptr::{self, Unique}; use core::task::{Context, Poll}; -use crate::co_alloc::CoAllocPref; #[cfg(not(no_global_oom_handling))] use crate::alloc::{handle_alloc_error, WriteCloneIntoRaw}; @@ -643,7 +643,9 @@ impl Box<[T]> { #[must_use] pub fn new_uninit_slice(len: usize) -> Box<[mem::MaybeUninit]> { // false = no need for co-alloc metadata, since it would get lost once converted to Box. - unsafe { RawVec::::with_capacity(len).into_box(len) } + unsafe { + RawVec::::with_capacity(len).into_box(len) + } } /// Constructs a new boxed slice with uninitialized contents, with the memory @@ -669,7 +671,10 @@ impl Box<[T]> { #[must_use] pub fn new_zeroed_slice(len: usize) -> Box<[mem::MaybeUninit]> { // false = no need for co-alloc metadata, since it would get lost once converted to Box. - unsafe { RawVec::::with_capacity_zeroed(len).into_box(len) } + unsafe { + RawVec::::with_capacity_zeroed(len) + .into_box(len) + } } /// Constructs a new boxed slice with uninitialized contents. Returns an error if @@ -701,7 +706,7 @@ impl Box<[T]> { Err(_) => return Err(AllocError), }; let ptr = Global.allocate(layout)?; - Ok(RawVec::::from_raw_parts_in( + Ok(RawVec::::from_raw_parts_in( ptr.as_mut_ptr() as *mut _, len, Global, @@ -738,7 +743,7 @@ impl Box<[T]> { Err(_) => return Err(AllocError), }; let ptr = Global.allocate_zeroed(layout)?; - Ok(RawVec::::from_raw_parts_in( + Ok(RawVec::::from_raw_parts_in( ptr.as_mut_ptr() as *mut _, len, Global, @@ -751,7 +756,7 @@ impl Box<[T]> { #[allow(unused_braces)] impl Box<[T], A> where - [(); {crate::meta_num_slots!(A, crate::CO_ALLOC_PREF_META_NO!())}]:, + [(); { crate::meta_num_slots!(A, crate::CO_ALLOC_PREF_META_NO!()) }]:, { /// Constructs a new boxed slice with uninitialized contents in the provided allocator. /// @@ -781,7 +786,9 @@ where #[must_use] #[allow(unused_braces)] pub fn new_uninit_slice_in(len: usize, alloc: A) -> Box<[mem::MaybeUninit], A> { - unsafe { RawVec::::with_capacity_in(len, alloc).into_box(len) } + unsafe { + RawVec::::with_capacity_in(len, alloc).into_box(len) + } } /// Constructs a new boxed slice with uninitialized contents in the provided allocator, @@ -810,7 +817,10 @@ where #[must_use] #[allow(unused_braces)] pub fn new_zeroed_slice_in(len: usize, alloc: A) -> Box<[mem::MaybeUninit], A> { - unsafe { RawVec::::with_capacity_zeroed_in(len, alloc).into_box(len) } + unsafe { + RawVec::::with_capacity_zeroed_in(len, alloc) + .into_box(len) + } } } @@ -1516,7 +1526,7 @@ impl From<&[T]> for Box<[T]> { fn from(slice: &[T]) -> Box<[T]> { let len = slice.len(); // false = no need for co-alloc metadata, since it would get lost once converted to Box. - let buf = RawVec::::with_capacity(len); + let buf = RawVec::::with_capacity(len); unsafe { ptr::copy_nonoverlapping(slice.as_ptr(), buf.ptr(), len); buf.into_box(slice.len()).assume_init() @@ -1682,9 +1692,10 @@ impl TryFrom> for Box<[T; N]> { #[cfg(not(no_global_oom_handling))] #[stable(feature = "boxed_array_try_from_vec", since = "1.66.0")] #[allow(unused_braces)] -impl TryFrom> for Box<[T; N]> +impl TryFrom> + for Box<[T; N]> where - [(); {meta_num_slots_global!(CO_ALLOC_PREF)}]:, + [(); { meta_num_slots_global!(CO_ALLOC_PREF) }]:, { type Error = Vec; @@ -2046,12 +2057,12 @@ impl FromIterator for Box<[I]> { #[allow(unused_braces)] impl Clone for Box<[T], A> where - [(); {crate::meta_num_slots!(A, crate::CO_ALLOC_PREF_META_NO!())}]:, + [(); { crate::meta_num_slots!(A, crate::CO_ALLOC_PREF_META_NO!()) }]:, { fn clone(&self) -> Self { let alloc = Box::allocator(self).clone(); // false = no need for co-alloc metadata, since it would get lost once converted to the boxed slice. - self.to_vec_in_co::(alloc).into_boxed_slice() + self.to_vec_in_co::(alloc).into_boxed_slice() } fn clone_from(&mut self, other: &Self) { diff --git a/library/alloc/src/co_alloc.rs b/library/alloc/src/co_alloc.rs index 7a854d1bbb23a..d71fb4b2640b5 100644 --- a/library/alloc/src/co_alloc.rs +++ b/library/alloc/src/co_alloc.rs @@ -1,9 +1,9 @@ //! CoAlloction-specific types that only apply in heap-based applications (hence not a part of //! [::core]). -//! +//! //! Types here have names with `CoAlloc` prefix. Yes, when using a q ualified path (like //! ::alloc::co_alloc::CoAllocPref), that involves "stuttering", which is not recommended. -//! +//! //! However, as per Rust Book the common practice is to import type names fully and access them just //! with their name (except for cases of conflict). And we don't want the type names any shorter //! (such `Pref`), because thoe would be vague/confusing. @@ -44,4 +44,4 @@ pub type CoAllocPref = u8; /// vales, or in place of a result of `meta_num_slots` macro. That also prevents mixing up with /// [core::alloc::CoAllocatorMetaNumSlots]. #[unstable(feature = "global_co_alloc_meta", issue = "none")] -pub type CoAllocMetaNumSlotsPref = u16; \ No newline at end of file +pub type CoAllocMetaNumSlotsPref = u16; diff --git a/library/alloc/src/collections/binary_heap/mod.rs b/library/alloc/src/collections/binary_heap/mod.rs index 23b029219ffe3..3f08c31fb6733 100644 --- a/library/alloc/src/collections/binary_heap/mod.rs +++ b/library/alloc/src/collections/binary_heap/mod.rs @@ -143,9 +143,9 @@ #![allow(missing_docs)] #![stable(feature = "rust1", since = "1.0.0")] +use crate::co_alloc::CoAllocPref; use core::fmt; use core::iter::{FromIterator, FusedIterator, InPlaceIterable, SourceIter, TrustedLen}; -use crate::co_alloc::CoAllocPref; use core::mem::{self, swap, ManuallyDrop}; use core::num::NonZeroUsize; use core::ops::{Deref, DerefMut}; @@ -1529,7 +1529,7 @@ unsafe impl TrustedLen for IntoIterSorted {} #[allow(unused_braces)] pub struct Drain<'a, T: 'a, const CO_ALLOC_PREF: CoAllocPref> where - [(); {meta_num_slots_global!(CO_ALLOC_PREF)}]:, + [(); { meta_num_slots_global!(CO_ALLOC_PREF) }]:, { iter: vec::Drain<'a, T, Global, CO_ALLOC_PREF>, } @@ -1538,7 +1538,7 @@ where #[allow(unused_braces)] impl Iterator for Drain<'_, T, CO_ALLOC_PREF> where - [(); {meta_num_slots_global!(CO_ALLOC_PREF)}]:, + [(); { meta_num_slots_global!(CO_ALLOC_PREF) }]:, { type Item = T; @@ -1557,7 +1557,7 @@ where #[allow(unused_braces)] impl DoubleEndedIterator for Drain<'_, T, CO_ALLOC_PREF> where - [(); {meta_num_slots_global!(CO_ALLOC_PREF)}]:, + [(); { meta_num_slots_global!(CO_ALLOC_PREF) }]:, { #[inline] fn next_back(&mut self) -> Option { @@ -1569,7 +1569,7 @@ where #[allow(unused_braces)] impl ExactSizeIterator for Drain<'_, T, CO_ALLOC_PREF> where - [(); {meta_num_slots_global!(CO_ALLOC_PREF)}]:, + [(); { meta_num_slots_global!(CO_ALLOC_PREF) }]:, { fn is_empty(&self) -> bool { self.iter.is_empty() @@ -1579,7 +1579,7 @@ where #[stable(feature = "fused", since = "1.26.0")] #[allow(unused_braces)] impl FusedIterator for Drain<'_, T, CO_ALLOC_PREF> where - [(); {meta_num_slots_global!(CO_ALLOC_PREF)}]: + [(); { meta_num_slots_global!(CO_ALLOC_PREF) }]: { } diff --git a/library/alloc/src/collections/vec_deque/drain.rs b/library/alloc/src/collections/vec_deque/drain.rs index dd05aa0422506..4dd85edac6eaa 100644 --- a/library/alloc/src/collections/vec_deque/drain.rs +++ b/library/alloc/src/collections/vec_deque/drain.rs @@ -1,5 +1,5 @@ -use core::iter::FusedIterator; use crate::co_alloc::CoAllocPref; +use core::iter::FusedIterator; use core::marker::PhantomData; use core::mem::{self, SizedTypeProperties}; use core::ptr::NonNull; @@ -23,10 +23,8 @@ pub struct Drain< #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global, const CO_ALLOC_PREF: CoAllocPref = { SHORT_TERM_VEC_CO_ALLOC_PREF!() }, > where - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { - // We can't just use a &mut VecDeque, as that would make Drain invariant over T - // and we want it to be covariant instead deque: NonNull>, // drain_start is stored in deque.len drain_len: usize, @@ -42,7 +40,7 @@ pub struct Drain< #[allow(unused_braces)] impl<'a, T, A: Allocator, const CO_ALLOC_PREF: CoAllocPref> Drain<'a, T, A, CO_ALLOC_PREF> where - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { pub(super) unsafe fn new( deque: &'a mut VecDeque, @@ -98,9 +96,10 @@ where #[stable(feature = "collection_debug", since = "1.17.0")] #[allow(unused_braces)] -impl fmt::Debug for Drain<'_, T, A, CO_ALLOC_PREF> +impl fmt::Debug + for Drain<'_, T, A, CO_ALLOC_PREF> where - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_tuple("Drain") @@ -114,14 +113,18 @@ where #[stable(feature = "drain", since = "1.6.0")] #[allow(unused_braces)] -unsafe impl Sync for Drain<'_, T, A, CO_ALLOC_PREF> where - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]: +unsafe impl Sync + for Drain<'_, T, A, CO_ALLOC_PREF> +where + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { } #[stable(feature = "drain", since = "1.6.0")] #[allow(unused_braces)] -unsafe impl Send for Drain<'_, T, A, CO_ALLOC_PREF> where - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]: +unsafe impl Send + for Drain<'_, T, A, CO_ALLOC_PREF> +where + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { } @@ -129,18 +132,19 @@ unsafe impl Send #[allow(unused_braces)] impl Drop for Drain<'_, T, A, CO_ALLOC_PREF> where - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { fn drop(&mut self) { struct DropGuard<'r, 'a, T, A: Allocator, const CO_ALLOC_PREF: CoAllocPref>( &'r mut Drain<'a, T, A, CO_ALLOC_PREF>, ) where - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:; + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:; - impl<'r, 'a, T, A: Allocator, const CO_ALLOC_PREF: CoAllocPref> Drop for DropGuard<'r, 'a, T, A, CO_ALLOC_PREF> + impl<'r, 'a, T, A: Allocator, const CO_ALLOC_PREF: CoAllocPref> Drop + for DropGuard<'r, 'a, T, A, CO_ALLOC_PREF> where - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { fn drop(&mut self) { if self.0.remaining != 0 { @@ -225,7 +229,7 @@ where #[allow(unused_braces)] impl Iterator for Drain<'_, T, A, CO_ALLOC_PREF> where - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { type Item = T; @@ -249,9 +253,10 @@ where #[stable(feature = "drain", since = "1.6.0")] #[allow(unused_braces)] -impl DoubleEndedIterator for Drain<'_, T, A, CO_ALLOC_PREF> +impl DoubleEndedIterator + for Drain<'_, T, A, CO_ALLOC_PREF> where - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { #[inline] fn next_back(&mut self) -> Option { @@ -266,14 +271,18 @@ where #[stable(feature = "drain", since = "1.6.0")] #[allow(unused_braces)] -impl ExactSizeIterator for Drain<'_, T, A, CO_ALLOC_PREF> where - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]: +impl ExactSizeIterator + for Drain<'_, T, A, CO_ALLOC_PREF> +where + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { } #[stable(feature = "fused", since = "1.26.0")] #[allow(unused_braces)] -impl FusedIterator for Drain<'_, T, A, CO_ALLOC_PREF> where - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]: +impl FusedIterator + for Drain<'_, T, A, CO_ALLOC_PREF> +where + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { } diff --git a/library/alloc/src/collections/vec_deque/into_iter.rs b/library/alloc/src/collections/vec_deque/into_iter.rs index 3b6d037c95576..f043ba9c82a4c 100644 --- a/library/alloc/src/collections/vec_deque/into_iter.rs +++ b/library/alloc/src/collections/vec_deque/into_iter.rs @@ -1,6 +1,7 @@ use core::iter::{FusedIterator, TrustedLen}; use core::{alloc, array, fmt, mem::MaybeUninit, ops::Try, ptr}; use crate::co_alloc::CoAllocPref; + use crate::alloc::{Allocator, Global}; use super::VecDeque; @@ -18,9 +19,9 @@ use super::VecDeque; pub struct IntoIter< T, #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global, - const CO_ALLOC_PREF: CoAllocPref = {CO_ALLOC_PREF_DEFAULT!()}, + const CO_ALLOC_PREF: CoAllocPref = { CO_ALLOC_PREF_DEFAULT!() }, > where - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { inner: VecDeque, } @@ -28,7 +29,7 @@ pub struct IntoIter< #[allow(unused_braces)] impl IntoIter where - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { pub(super) fn new(inner: VecDeque) -> Self { IntoIter { inner } @@ -41,9 +42,10 @@ where #[stable(feature = "collection_debug", since = "1.17.0")] #[allow(unused_braces)] -impl fmt::Debug for IntoIter +impl fmt::Debug + for IntoIter where - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_tuple("IntoIter").field(&self.inner).finish() @@ -54,7 +56,7 @@ where #[allow(unused_braces)] impl Iterator for IntoIter where - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { type Item = T; @@ -192,9 +194,10 @@ where #[stable(feature = "rust1", since = "1.0.0")] #[allow(unused_braces)] -impl DoubleEndedIterator for IntoIter +impl DoubleEndedIterator + for IntoIter where - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { #[inline] fn next_back(&mut self) -> Option { @@ -266,9 +269,10 @@ where #[stable(feature = "rust1", since = "1.0.0")] #[allow(unused_braces)] -impl ExactSizeIterator for IntoIter +impl ExactSizeIterator + for IntoIter where - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { #[inline] fn is_empty(&self) -> bool { @@ -278,14 +282,18 @@ where #[stable(feature = "fused", since = "1.26.0")] #[allow(unused_braces)] -impl FusedIterator for IntoIter where - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]: +impl FusedIterator + for IntoIter +where + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { } #[unstable(feature = "trusted_len", issue = "37572")] #[allow(unused_braces)] -unsafe impl TrustedLen for IntoIter where - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]: +unsafe impl TrustedLen + for IntoIter +where + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { } diff --git a/library/alloc/src/collections/vec_deque/mod.rs b/library/alloc/src/collections/vec_deque/mod.rs index bfa1475053cb3..bcc42e53654e3 100644 --- a/library/alloc/src/collections/vec_deque/mod.rs +++ b/library/alloc/src/collections/vec_deque/mod.rs @@ -7,11 +7,11 @@ #![feature(global_co_alloc)] #![stable(feature = "rust1", since = "1.0.0")] +use crate::co_alloc::CoAllocPref; use crate::CO_ALLOC_PREF_DEFAULT; use core::cmp::{self, Ordering}; use core::fmt; use core::hash::{Hash, Hasher}; -use crate::co_alloc::CoAllocPref; use core::iter::{repeat_n, repeat_with, ByRefSized, FromIterator}; use core::mem::{ManuallyDrop, SizedTypeProperties}; use core::ops::{Index, IndexMut, Range, RangeBounds}; @@ -99,10 +99,8 @@ pub struct VecDeque< #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global, const CO_ALLOC_PREF: CoAllocPref = { CO_ALLOC_PREF_DEFAULT!() }, > where - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { - // `self[0]`, if it exists, is `buf[head]`. - // `head < buf.capacity()`, unless `buf.capacity() == 0` when `head == 0`. head: usize, // the number of initialized elements, starting from the one at `head` and potentially wrapping around. // if `len == 0`, the exact value of `head` is unimportant. @@ -113,9 +111,10 @@ pub struct VecDeque< #[stable(feature = "rust1", since = "1.0.0")] #[allow(unused_braces)] -impl Clone for VecDeque +impl Clone + for VecDeque where - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { fn clone(&self) -> Self { let mut deq = Self::with_capacity_in(self.len(), self.allocator().clone()); @@ -131,9 +130,10 @@ where #[stable(feature = "rust1", since = "1.0.0")] #[allow(unused_braces)] -unsafe impl<#[may_dangle] T, A: Allocator, const CO_ALLOC_PREF: CoAllocPref> Drop for VecDeque +unsafe impl<#[may_dangle] T, A: Allocator, const CO_ALLOC_PREF: CoAllocPref> Drop + for VecDeque where - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { fn drop(&mut self) { /// Runs the destructor for all items in the slice when it gets dropped (normally or @@ -160,8 +160,7 @@ where #[stable(feature = "rust1", since = "1.0.0")] #[allow(unused_braces)] -impl Default for VecDeque -{ +impl Default for VecDeque { /// Creates an empty deque. #[inline] fn default() -> VecDeque { @@ -172,7 +171,7 @@ impl Default for VecDeque #[allow(unused_braces)] impl VecDeque where - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { /// Marginally more convenient #[inline] @@ -464,7 +463,7 @@ where ) -> usize { struct Guard<'a, T, A: Allocator, const CO_ALLOC_PREF: CoAllocPref> where - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { deque: &'a mut VecDeque, written: usize, @@ -473,7 +472,7 @@ where #[allow(unused_braces)] impl<'a, T, A: Allocator, const CO_ALLOC_PREF: CoAllocPref> Drop for Guard<'a, T, A, CO_ALLOC_PREF> where - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { fn drop(&mut self) { self.deque.len += self.written; @@ -552,7 +551,7 @@ where } } -impl VecDeque { +impl VecDeque { /// Creates an empty deque. /// /// # Examples @@ -567,12 +566,11 @@ impl VecDeque { #[rustc_const_stable(feature = "const_vec_deque_new", since = "1.68.0")] #[must_use] #[allow(unused_braces)] - pub const fn new() -> VecDeque - { + pub const fn new() -> VecDeque { // FIXME: This should just be `VecDeque::new_in(Global)` once that hits stable. VecDeque { head: 0, len: 0, buf: RawVec::NEW } } - + /// Creates an empty deque with space for at least `capacity` elements. /// /// # Examples @@ -586,15 +584,15 @@ impl VecDeque { #[stable(feature = "rust1", since = "1.0.0")] #[must_use] #[allow(unused_braces)] - pub fn with_capacity(capacity: usize) -> VecDeque { - VecDeque::::with_capacity_in(capacity, Global) + pub fn with_capacity(capacity: usize) -> VecDeque { + VecDeque::::with_capacity_in(capacity, Global) } } #[allow(unused_braces)] impl VecDeque where - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { /// Creates an empty deque. /// @@ -2633,7 +2631,7 @@ where #[allow(unused_braces)] impl VecDeque where - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { /// Modifies the deque in-place so that `len()` is equal to new_len, /// either by removing excess elements from the back or by appending clones of `value` @@ -2680,9 +2678,10 @@ fn wrap_index(logical_index: usize, capacity: usize) -> usize { #[allow(unused_braces)] #[stable(feature = "rust1", since = "1.0.0")] -impl PartialEq for VecDeque +impl PartialEq + for VecDeque where - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { fn eq(&self, other: &Self) -> bool { if self.len != other.len() { @@ -2724,7 +2723,7 @@ where #[allow(unused_braces)] #[stable(feature = "rust1", since = "1.0.0")] impl Eq for VecDeque where - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]: + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]: { } @@ -2737,9 +2736,10 @@ __impl_slice_eq1! { [const N: usize] VecDeque, &mut [U; N], #[stable(feature = "rust1", since = "1.0.0")] #[allow(unused_braces)] -impl PartialOrd for VecDeque +impl PartialOrd + for VecDeque where - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { fn partial_cmp(&self, other: &Self) -> Option { self.iter().partial_cmp(other.iter()) @@ -2750,7 +2750,7 @@ where #[allow(unused_braces)] impl Ord for VecDeque where - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { #[inline] fn cmp(&self, other: &Self) -> Ordering { @@ -2762,7 +2762,7 @@ where #[allow(unused_braces)] impl Hash for VecDeque where - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { fn hash(&self, state: &mut H) { state.write_length_prefix(self.len); @@ -2778,9 +2778,10 @@ where #[stable(feature = "rust1", since = "1.0.0")] #[allow(unused_braces)] -impl Index for VecDeque +impl Index + for VecDeque where - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { type Output = T; @@ -2792,9 +2793,10 @@ where #[stable(feature = "rust1", since = "1.0.0")] #[allow(unused_braces)] -impl IndexMut for VecDeque +impl IndexMut + for VecDeque where - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { #[inline] fn index_mut(&mut self, index: usize) -> &mut T { @@ -2806,7 +2808,7 @@ where #[allow(unused_braces)] impl FromIterator for VecDeque where - [(); {crate::meta_num_slots_global!(CO_ALLOC_PREF)}]:, + [(); { crate::meta_num_slots_global!(CO_ALLOC_PREF) }]:, { fn from_iter>(iter: I) -> VecDeque { SpecFromIterCo::spec_from_iter_co(iter.into_iter()) @@ -2815,9 +2817,10 @@ where #[stable(feature = "rust1", since = "1.0.0")] #[allow(unused_braces)] -impl IntoIterator for VecDeque +impl IntoIterator + for VecDeque where - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { type Item = T; type IntoIter = IntoIter; @@ -2831,9 +2834,10 @@ where #[stable(feature = "rust1", since = "1.0.0")] #[allow(unused_braces)] -impl<'a, T, A: Allocator, const CO_ALLOC_PREF: CoAllocPref> IntoIterator for &'a VecDeque +impl<'a, T, A: Allocator, const CO_ALLOC_PREF: CoAllocPref> IntoIterator + for &'a VecDeque where - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { type Item = &'a T; type IntoIter = Iter<'a, T>; @@ -2845,9 +2849,10 @@ where #[stable(feature = "rust1", since = "1.0.0")] #[allow(unused_braces)] -impl<'a, T, A: Allocator, const CO_ALLOC_PREF: CoAllocPref> IntoIterator for &'a mut VecDeque +impl<'a, T, A: Allocator, const CO_ALLOC_PREF: CoAllocPref> IntoIterator + for &'a mut VecDeque where - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { type Item = &'a mut T; type IntoIter = IterMut<'a, T>; @@ -2861,7 +2866,7 @@ where #[allow(unused_braces)] impl Extend for VecDeque where - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { fn extend>(&mut self, iter: I) { >::spec_extend(self, iter.into_iter()); @@ -2883,7 +2888,7 @@ where impl<'a, T: 'a + Copy, A: Allocator, const CO_ALLOC_PREF: CoAllocPref> Extend<&'a T> for VecDeque where - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { fn extend>(&mut self, iter: I) { self.spec_extend(iter.into_iter()); @@ -2902,9 +2907,10 @@ where #[stable(feature = "rust1", since = "1.0.0")] #[allow(unused_braces)] -impl fmt::Debug for VecDeque +impl fmt::Debug + for VecDeque where - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_list().entries(self.iter()).finish() @@ -2913,11 +2919,15 @@ where #[stable(feature = "vecdeque_vec_conversions", since = "1.10.0")] #[allow(unused_braces)] -impl - From> for VecDeque//, CO_ALLOC_PREF> +impl< + T, + A: Allocator, + /*const CO_ALLOC_PREF: CoAllocPref,*/ const OTHER_CO_ALLOC_PREF: CoAllocPref, +> From> for VecDeque +//, CO_ALLOC_PREF> where //[(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, - [(); {crate::meta_num_slots!(A, OTHER_CO_ALLOC_PREF)}]:, + [(); { crate::meta_num_slots!(A, OTHER_CO_ALLOC_PREF) }]:, { /// Turn a [`Vec`] into a [`VecDeque`]. /// @@ -2933,7 +2943,9 @@ where Self { head: 0, len, - buf: unsafe { RawVec::::from_raw_parts_in(ptr, cap, alloc) }, + buf: unsafe { + RawVec::::from_raw_parts_in(ptr, cap, alloc) + }, } } } @@ -2943,8 +2955,8 @@ where impl From> for VecDeque where - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, - [(); {crate::meta_num_slots!(A, OTHER_CO_ALLOC_PREF)}]:, + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, + [(); { crate::meta_num_slots!(A, OTHER_CO_ALLOC_PREF) }]:, { /// Turn a [`Vec`] into a [`VecDeque`]. /// @@ -2970,8 +2982,8 @@ where impl From> for Vec where - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, - [(); {crate::meta_num_slots!(A, VECDEQUE_CO_ALLOC_PREF)}]:, + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, + [(); { crate::meta_num_slots!(A, VECDEQUE_CO_ALLOC_PREF) }]:, { /// Turn a [`VecDeque`] into a [`Vec`]. /// @@ -3004,7 +3016,7 @@ where /// ``` fn from(mut other: VecDeque) -> Self where - [(); {crate::meta_num_slots!(A, VECDEQUE_CO_ALLOC_PREF)}]:, + [(); { crate::meta_num_slots!(A, VECDEQUE_CO_ALLOC_PREF) }]:, { other.make_contiguous(); @@ -3026,8 +3038,7 @@ where #[stable(feature = "std_collections_from_array", since = "1.56.0")] #[allow(unused_braces)] -impl From<[T; N]> for VecDeque -{ +impl From<[T; N]> for VecDeque { /// Converts a `[T; N]` into a `VecDeque`. /// /// ``` diff --git a/library/alloc/src/collections/vec_deque/spec_extend.rs b/library/alloc/src/collections/vec_deque/spec_extend.rs index 424e7cb4dd646..0c5d9cf7a5378 100644 --- a/library/alloc/src/collections/vec_deque/spec_extend.rs +++ b/library/alloc/src/collections/vec_deque/spec_extend.rs @@ -14,10 +14,11 @@ pub(super) trait SpecExtend { } #[allow(unused_braces)] -impl SpecExtend for VecDeque +impl SpecExtend + for VecDeque where I: Iterator, - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { default fn spec_extend(&mut self, mut iter: I) { // This function should be the moral equivalent of: @@ -31,7 +32,7 @@ where deque: &mut VecDeque, element: T, ) where - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { // SAFETY: Because of the precondition, it's guaranteed that there is space // in the logical array after the last element. @@ -60,10 +61,11 @@ where } #[allow(unused_braces)] -impl SpecExtend for VecDeque +impl SpecExtend + for VecDeque where I: TrustedLen, - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { default fn spec_extend(&mut self, iter: I) { // This is the case for a TrustedLen iterator. @@ -100,7 +102,7 @@ where impl SpecExtend> for VecDeque where - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { fn spec_extend(&mut self, mut iterator: vec::IntoIter) { let slice = iterator.as_slice(); @@ -120,7 +122,7 @@ impl<'a, T: 'a, I, A: Allocator, const CO_ALLOC_PREF: CoAllocPref> SpecExtend<&' where I: Iterator, T: Copy, - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { default fn spec_extend(&mut self, iterator: I) { self.spec_extend(iterator.copied()) @@ -128,11 +130,11 @@ where } #[allow(unused_braces)] -impl<'a, T: 'a, A: Allocator, const CO_ALLOC_PREF: CoAllocPref> SpecExtend<&'a T, slice::Iter<'a, T>> - for VecDeque +impl<'a, T: 'a, A: Allocator, const CO_ALLOC_PREF: CoAllocPref> + SpecExtend<&'a T, slice::Iter<'a, T>> for VecDeque where T: Copy, - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { fn spec_extend(&mut self, iterator: slice::Iter<'a, T>) { let slice = iterator.as_slice(); diff --git a/library/alloc/src/collections/vec_deque/spec_from_iter.rs b/library/alloc/src/collections/vec_deque/spec_from_iter.rs index 54cbe40ea692a..5d21203b5d7b3 100644 --- a/library/alloc/src/collections/vec_deque/spec_from_iter.rs +++ b/library/alloc/src/collections/vec_deque/spec_from_iter.rs @@ -27,9 +27,7 @@ where } #[allow(unused_braces)] -impl SpecFromIter> - for VecDeque -{ +impl SpecFromIter> for VecDeque { #[inline] fn spec_from_iter(iterator: crate::vec::IntoIter) -> Self { iterator.into_vecdeque() @@ -37,9 +35,7 @@ impl SpecFromIter> } #[allow(unused_braces)] -impl SpecFromIter> - for VecDeque -{ +impl SpecFromIter> for VecDeque { #[inline] fn spec_from_iter(iterator: IntoIter) -> Self { iterator.into_vecdeque() @@ -48,10 +44,11 @@ impl SpecFromIter> // ---- #[allow(unused_braces)] -impl SpecFromIterCo for VecDeque +impl SpecFromIterCo + for VecDeque where I: Iterator, - [(); {crate::meta_num_slots_global!(CO_ALLOC_PREF)}]:, + [(); { crate::meta_num_slots_global!(CO_ALLOC_PREF) }]:, { default fn spec_from_iter_co(iterator: I) -> Self { // Since converting is O(1) now, just re-use the `Vec` logic for @@ -63,10 +60,11 @@ where } #[allow(unused_braces)] -impl SpecFromIterCo> +impl + SpecFromIterCo> for VecDeque where - [(); {crate::meta_num_slots_global!(CO_ALLOC_PREF)}]:, + [(); { crate::meta_num_slots_global!(CO_ALLOC_PREF) }]:, { #[inline] fn spec_from_iter_co(iterator: crate::vec::IntoIter) -> Self { @@ -78,10 +76,10 @@ where impl SpecFromIterCo> for VecDeque where - [(); {crate::meta_num_slots_global!(CO_ALLOC_PREF)}]:, + [(); { crate::meta_num_slots_global!(CO_ALLOC_PREF) }]:, { #[inline] fn spec_from_iter_co(iterator: IntoIter) -> Self { iterator.into_vecdeque() } -} \ No newline at end of file +} diff --git a/library/alloc/src/macros.rs b/library/alloc/src/macros.rs index a2a62d676bed1..247e7efb00688 100644 --- a/library/alloc/src/macros.rs +++ b/library/alloc/src/macros.rs @@ -190,11 +190,11 @@ macro_rules! CO_ALLOC_PREF_META_NO { /// "Default" as a type's preference for coallocation using metadata (in either user space, or /// `alloc` or `std` space). -/// +/// /// This value and its type WILL CHANGE (once ``#![feature(generic_const_exprs)]` and /// `#![feature(adt_const_params)]` are stable) to a dedicated struct/enum. Hence DO NOT hard /// code/replace/mix this any other values/parameters. -/// +/// /// (@FIXME) This WILL BE BECOME OBSOLETE and it WILL BE REPLACED with a `const` (and/or some kind /// of compile time preference) once a related ICE is fixed (@FIXME add the ICE link here). Then /// consider moving such a `const` to a submodule, for example `::alloc::co_alloc`. @@ -210,7 +210,9 @@ macro_rules! CO_ALLOC_PREF_META_DEFAULT { #[unstable(feature = "global_co_alloc_meta", issue = "none")] #[macro_export] macro_rules! CO_ALLOC_PREF_DEFAULT { - () => { $crate::CO_ALLOC_PREF_META_DEFAULT!() }; + () => { + $crate::CO_ALLOC_PREF_META_DEFAULT!() + }; } /// Coallocation preference for (internal) short term vectors. @@ -218,17 +220,19 @@ macro_rules! CO_ALLOC_PREF_DEFAULT { //pub const SHORT_TERM_VEC_CO_ALLOC_PREF: bool = true; #[macro_export] macro_rules! SHORT_TERM_VEC_CO_ALLOC_PREF { - () => { $crate::CO_ALLOC_PREF_META_NO!() }; + () => { + $crate::CO_ALLOC_PREF_META_NO!() + }; } // ------ CoAlloc preference/config conversion macros: /// Create a `CoAllocPref` value based on the given parameter(s). For now, only one parameter is /// supported, and it's required: `meta_pref`. -/// +/// /// @param `meta_pref` is one of: `CO_ALLOC_PREF_META_YES, CO_ALLOC_PREF_META_NO`, or /// `CO_ALLOC_PREF_META_DEFAULT`. -/// +/// /// @return `CoAllocPref` value #[unstable(feature = "global_co_alloc_meta", issue = "none")] #[macro_export] @@ -238,7 +242,8 @@ macro_rules! co_alloc_pref { // report the incorrect type of $meta_pref (if $meta_pref were some other integer, casting would // compile, and we would not be notified). ($meta_pref:expr) => { - (($meta_pref + (0 as $crate::co_alloc::CoAllocMetaNumSlotsPref)) as $crate::co_alloc::CoAllocPref) + (($meta_pref + (0 as $crate::co_alloc::CoAllocMetaNumSlotsPref)) + as $crate::co_alloc::CoAllocPref) }; } @@ -248,13 +253,13 @@ macro_rules! co_alloc_pref { /// NOT for public use. Param `co_alloc_pref` - can override the allocator's default preference for /// cooperation, or can make the type not cooperative, regardless of whether allocator `A` is /// cooperative. -/// +/// /// @param `alloc` Allocator (implementation) type. @param `co_alloc_pref` The heap-based type's /// preference for coallocation, as an [::alloc::CoAllocPref] value. -/// +/// /// The type of second parameter `co_alloc_pref` WILL CHANGE. DO NOT hardcode/cast/mix that type. /// Instead, use [::alloc::CoAllocPref]. -/// +/// // FIXME replace the macro with an (updated version of the below) `const` function). Only once // generic_const_exprs is stable (that is, when consumer crates don't need to declare // generic_const_exprs feature anymore). Then consider moving the function to a submodule, for @@ -299,7 +304,7 @@ macro_rules! meta_num_slots_default { // Can't generate if ... {1} else {0} // because it's "overly complex generic constant". ($alloc:ty) => { - $crate::meta_num_slots!( $alloc, $crate::CO_ALLOC_PREF_DEFAULT!() ) + $crate::meta_num_slots!($alloc, $crate::CO_ALLOC_PREF_DEFAULT!()) }; } @@ -315,7 +320,7 @@ macro_rules! meta_num_slots_default { #[macro_export] macro_rules! meta_num_slots_global { ($co_alloc_pref:expr) => { - $crate::meta_num_slots!( $crate::alloc::Global, $co_alloc_pref) + $crate::meta_num_slots!($crate::alloc::Global, $co_alloc_pref) }; } @@ -328,6 +333,6 @@ macro_rules! meta_num_slots_global { #[macro_export] macro_rules! meta_num_slots_default_global { () => { - $crate::meta_num_slots!( $crate::alloc::Global, $crate::CO_ALLOC_PREF_DEFAULT!()) + $crate::meta_num_slots!($crate::alloc::Global, $crate::CO_ALLOC_PREF_DEFAULT!()) }; } diff --git a/library/alloc/src/raw_vec.rs b/library/alloc/src/raw_vec.rs index 5f401448c12b2..1f4e74d2f70e9 100644 --- a/library/alloc/src/raw_vec.rs +++ b/library/alloc/src/raw_vec.rs @@ -59,7 +59,7 @@ pub(crate) struct RawVec< A: Allocator = Global, const CO_ALLOC_PREF: CoAllocPref = { CO_ALLOC_PREF_DEFAULT!() }, > where - [(); {meta_num_slots!(A, CO_ALLOC_PREF)}]:, + [(); { meta_num_slots!(A, CO_ALLOC_PREF) }]:, { ptr: Unique, cap: usize, @@ -67,14 +67,13 @@ pub(crate) struct RawVec< // As of v1.67.0, `cmp` for `TypeId` is not `const`, unfortunately: //pub(crate) meta: [GlobalCoAllocMeta; {if core::any::TypeId::of::()==core::any::TypeId::of::() {1} else {0}}], //pub(crate) meta: [GlobalCoAllocMeta; mem::size_of::()], - pub(crate) metas: - [A::CoAllocMeta; {crate::meta_num_slots!(A, CO_ALLOC_PREF)}], + pub(crate) metas: [A::CoAllocMeta; { crate::meta_num_slots!(A, CO_ALLOC_PREF) }], } #[allow(unused_braces)] impl RawVec where - [(); {meta_num_slots_global!(CO_ALLOC_PREF)}]:, + [(); { meta_num_slots_global!(CO_ALLOC_PREF) }]:, { /// HACK(Centril): This exists because stable `const fn` can only call stable `const fn`, so /// they cannot call `Self::new()`. @@ -125,7 +124,7 @@ where #[allow(unused_braces)] impl RawVec where - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { #[allow(dead_code)] const fn new_plain_metas() -> [A::CoAllocMeta; { meta_num_slots_default!(A) }] { @@ -333,7 +332,7 @@ where len: usize, additional: usize, ) where - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { handle_reserve(slf.grow_amortized(len, additional)); } @@ -410,7 +409,7 @@ where #[allow(unused_braces)] impl RawVec where - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { /// Returns if the buffer needs to grow to fulfill the needed extra capacity. /// Mainly used to make inlining reserve-calls possible without inlining `grow`. @@ -532,16 +531,21 @@ where } #[allow(unused_braces)] -unsafe impl<#[may_dangle] T, A: Allocator, const CO_ALLOC_PREF: CoAllocPref> Drop for RawVec +unsafe impl<#[may_dangle] T, A: Allocator, const CO_ALLOC_PREF: CoAllocPref> Drop + for RawVec where - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { /// Frees the memory owned by the `RawVec` *without* trying to drop its contents. default fn drop(&mut self) { if let Some((ptr, layout)) = self.current_memory() { let meta_num_slots = crate::meta_num_slots!(A, CO_ALLOC_PREF); - if meta_num_slots!=0 { - debug_assert!(meta_num_slots==1, "Number of coallocation meta slots can be only 0 or 1, but it is {}!", meta_num_slots); + if meta_num_slots != 0 { + debug_assert!( + meta_num_slots == 1, + "Number of coallocation meta slots can be only 0 or 1, but it is {}!", + meta_num_slots + ); let meta = self.metas[0]; unsafe { self.alloc.co_deallocate(PtrAndMeta { ptr, meta }, layout) } } else { diff --git a/library/alloc/src/rc.rs b/library/alloc/src/rc.rs index 1b1bd8c8864fe..52af085bc470a 100644 --- a/library/alloc/src/rc.rs +++ b/library/alloc/src/rc.rs @@ -1991,7 +1991,7 @@ impl From> for Rc { #[allow(unused_braces)] impl From> for Rc<[T]> where - [(); {meta_num_slots_global!(CO_ALLOC_PREF)}]:, + [(); { meta_num_slots_global!(CO_ALLOC_PREF) }]:, { /// Allocate a reference-counted slice and move `v`'s items into it. /// @@ -2007,7 +2007,7 @@ where #[allow(unused_braces)] fn from(mut v: Vec) -> Rc<[T]> where - [(); {meta_num_slots_global!(CO_ALLOC_PREF)}]:, + [(); { meta_num_slots_global!(CO_ALLOC_PREF) }]:, { unsafe { let rc = Rc::copy_from_slice(&v); diff --git a/library/alloc/src/slice.rs b/library/alloc/src/slice.rs index aea33283a0c67..d3fd1b9839538 100644 --- a/library/alloc/src/slice.rs +++ b/library/alloc/src/slice.rs @@ -103,9 +103,11 @@ pub(crate) mod hack { // `vec!` macro mostly and causes perf regression. See #71204 for // discussion and perf results. #[allow(unused_braces)] - pub fn into_vec(b: Box<[T], A>) -> Vec + pub fn into_vec( + b: Box<[T], A>, + ) -> Vec where - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { unsafe { let len = b.len(); @@ -117,12 +119,9 @@ pub(crate) mod hack { #[cfg(not(no_global_oom_handling))] #[inline] #[allow(unused_braces)] - pub fn to_vec( - s: &[T], - alloc: A, - ) -> Vec + pub fn to_vec(s: &[T], alloc: A) -> Vec where - [(); {crate::meta_num_slots_default!(A)}]:, + [(); { crate::meta_num_slots_default!(A) }]:, { T::to_vec(s, alloc) } @@ -135,7 +134,7 @@ pub(crate) mod hack { alloc: A, ) -> Vec where - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { T::to_vec_co(s, alloc) } @@ -143,13 +142,10 @@ pub(crate) mod hack { #[cfg(not(no_global_oom_handling))] #[allow(unused_braces)] pub trait ConvertVec { - fn to_vec( - s: &[Self], - alloc: A, - ) -> Vec + fn to_vec(s: &[Self], alloc: A) -> Vec where Self: Sized, - [(); {crate::meta_num_slots_default!(A)}]:; + [(); { crate::meta_num_slots_default!(A) }]:; } #[allow(unused_braces)] @@ -160,7 +156,7 @@ pub(crate) mod hack { ) -> Vec where Self: Sized, - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:; + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:; } #[cfg(not(no_global_oom_handling))] @@ -168,24 +164,21 @@ pub(crate) mod hack { impl ConvertVec for T { #[inline] #[allow(unused_braces)] - default fn to_vec( - s: &[Self], - alloc: A, - ) -> Vec + default fn to_vec(s: &[Self], alloc: A) -> Vec where - [(); {crate::meta_num_slots_default!(A)}]:, + [(); { crate::meta_num_slots_default!(A) }]:, { #[allow(unused_braces)] struct DropGuard<'a, T, A: Allocator> where - [(); {crate::meta_num_slots_default!(A)}]:, + [(); { crate::meta_num_slots_default!(A) }]:, { vec: &'a mut Vec, num_init: usize, } impl<'a, T, A: Allocator> Drop for DropGuard<'a, T, A> where - [(); {crate::meta_num_slots_default!(A)}]:, + [(); { crate::meta_num_slots_default!(A) }]:, { #[inline] fn drop(&mut self) { @@ -219,12 +212,9 @@ pub(crate) mod hack { impl ConvertVec for T { #[inline] #[allow(unused_braces)] - fn to_vec( - s: &[Self], - alloc: A, - ) -> Vec + fn to_vec(s: &[Self], alloc: A) -> Vec where - [(); {crate::meta_num_slots_default!(A)}]:, + [(); { crate::meta_num_slots_default!(A) }]:, { let mut v = Vec::with_capacity_in(s.len(), alloc); // SAFETY: @@ -248,19 +238,20 @@ pub(crate) mod hack { alloc: A, ) -> Vec where - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { #[allow(unused_braces)] struct DropGuard<'a, T, A: Allocator, const CO_ALLOC_PREF: CoAllocPref> where - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { vec: &'a mut Vec, num_init: usize, } - impl<'a, T, A: Allocator, const CO_ALLOC_PREF: CoAllocPref> Drop for DropGuard<'a, T, A, CO_ALLOC_PREF> + impl<'a, T, A: Allocator, const CO_ALLOC_PREF: CoAllocPref> Drop + for DropGuard<'a, T, A, CO_ALLOC_PREF> where - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { #[inline] fn drop(&mut self) { @@ -299,7 +290,7 @@ pub(crate) mod hack { alloc: A, ) -> Vec where - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { let mut v = Vec::with_capacity_in(s.len(), alloc); // SAFETY: @@ -311,7 +302,8 @@ pub(crate) mod hack { } v } - }} + } +} #[cfg(not(test))] impl [T] { @@ -552,7 +544,8 @@ impl [T] { #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn to_vec(&self) -> Vec - where T:Clone + where + T: Clone, { self.to_vec_in::(Global) } @@ -567,7 +560,7 @@ impl [T] { pub fn to_vec_co(&self) -> Vec where T: Clone, - [(); {meta_num_slots_global!(CO_ALLOC_PREF)}]:, + [(); { meta_num_slots_global!(CO_ALLOC_PREF) }]:, { self.to_vec_in_co::(Global) } @@ -593,7 +586,7 @@ impl [T] { pub fn to_vec_in(&self, alloc: A) -> Vec where T: Clone, - [(); {crate::meta_num_slots_default!(A)}]:, + [(); { crate::meta_num_slots_default!(A) }]:, { // N.B., see the `hack` module in this file for more details. hack::to_vec(self, alloc) @@ -605,10 +598,13 @@ impl [T] { #[inline] #[unstable(feature = "global_co_alloc", issue = "none")] #[allow(unused_braces)] - pub fn to_vec_in_co(&self, alloc: A) -> Vec + pub fn to_vec_in_co( + &self, + alloc: A, + ) -> Vec where T: Clone, - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { // N.B., see the `hack` module in this file for more details. hack::to_vec_co(self, alloc) @@ -632,9 +628,11 @@ impl [T] { #[stable(feature = "rust1", since = "1.0.0")] #[inline] #[allow(unused_braces)] - pub fn into_vec(self: Box) -> Vec + pub fn into_vec( + self: Box, + ) -> Vec where - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { // N.B., see the `hack` module in this file for more details. hack::into_vec(self) @@ -952,7 +950,7 @@ impl> Join<&[T]> for [V] { #[allow(unused_braces)] impl Borrow<[T]> for Vec where - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { fn borrow(&self) -> &[T] { &self[..] @@ -963,7 +961,7 @@ where #[allow(unused_braces)] impl BorrowMut<[T]> for Vec where - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { fn borrow_mut(&mut self) -> &mut [T] { &mut self[..] diff --git a/library/alloc/src/str.rs b/library/alloc/src/str.rs index ee13404a3eb98..3c900c1164536 100644 --- a/library/alloc/src/str.rs +++ b/library/alloc/src/str.rs @@ -138,7 +138,7 @@ where T: Copy, B: AsRef<[T]> + ?Sized, S: Borrow, - [(); {crate::meta_num_slots_global!(CO_ALLOC_PREF)}]:, + [(); { crate::meta_num_slots_global!(CO_ALLOC_PREF) }]:, { let sep_len = sep.len(); let mut iter = slice.iter(); diff --git a/library/alloc/src/vec/drain.rs b/library/alloc/src/vec/drain.rs index 66ce729956c23..eaea943baecd0 100644 --- a/library/alloc/src/vec/drain.rs +++ b/library/alloc/src/vec/drain.rs @@ -1,6 +1,6 @@ use crate::alloc::{Allocator, Global}; -use core::fmt; use crate::co_alloc::CoAllocPref; +use core::fmt; use core::iter::{FusedIterator, TrustedLen}; use core::mem::{self, ManuallyDrop, SizedTypeProperties}; use core::ptr::{self, NonNull}; @@ -27,7 +27,7 @@ pub struct Drain< #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator + 'a = Global, const CO_ALLOC_PREF: CoAllocPref = { SHORT_TERM_VEC_CO_ALLOC_PREF!() }, > where - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { /// Index of tail to preserve pub(super) tail_start: usize, @@ -40,9 +40,10 @@ pub struct Drain< #[stable(feature = "collection_debug", since = "1.17.0")] #[allow(unused_braces)] -impl fmt::Debug for Drain<'_, T, A, CO_ALLOC_PREF> +impl fmt::Debug + for Drain<'_, T, A, CO_ALLOC_PREF> where - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_tuple("Drain").field(&self.iter.as_slice()).finish() @@ -52,7 +53,7 @@ where #[allow(unused_braces)] impl<'a, T, A: Allocator, const CO_ALLOC_PREF: CoAllocPref> Drain<'a, T, A, CO_ALLOC_PREF> where - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { /// Returns the remaining items of this iterator as a slice. /// @@ -153,9 +154,10 @@ where #[stable(feature = "vec_drain_as_slice", since = "1.46.0")] #[allow(unused_braces)] -impl<'a, T, A: Allocator, const CO_ALLOC_PREF: CoAllocPref> AsRef<[T]> for Drain<'a, T, A, CO_ALLOC_PREF> +impl<'a, T, A: Allocator, const CO_ALLOC_PREF: CoAllocPref> AsRef<[T]> + for Drain<'a, T, A, CO_ALLOC_PREF> where - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { fn as_ref(&self) -> &[T] { self.as_slice() @@ -164,14 +166,18 @@ where #[stable(feature = "drain", since = "1.6.0")] #[allow(unused_braces)] -unsafe impl Sync for Drain<'_, T, A, CO_ALLOC_PREF> where - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]: +unsafe impl Sync + for Drain<'_, T, A, CO_ALLOC_PREF> +where + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { } #[stable(feature = "drain", since = "1.6.0")] #[allow(unused_braces)] -unsafe impl Send for Drain<'_, T, A, CO_ALLOC_PREF> where - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]: +unsafe impl Send + for Drain<'_, T, A, CO_ALLOC_PREF> +where + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { } @@ -179,7 +185,7 @@ unsafe impl Send #[allow(unused_braces)] impl Iterator for Drain<'_, T, A, CO_ALLOC_PREF> where - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { type Item = T; @@ -195,9 +201,10 @@ where #[stable(feature = "drain", since = "1.6.0")] #[allow(unused_braces)] -impl DoubleEndedIterator for Drain<'_, T, A, CO_ALLOC_PREF> +impl DoubleEndedIterator + for Drain<'_, T, A, CO_ALLOC_PREF> where - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { #[inline] fn next_back(&mut self) -> Option { @@ -209,7 +216,7 @@ where #[allow(unused_braces)] impl Drop for Drain<'_, T, A, CO_ALLOC_PREF> where - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { fn drop(&mut self) { /// Moves back the un-`Drain`ed elements to restore the original `Vec`. @@ -218,11 +225,12 @@ where &'r mut Drain<'a, T, A, CO_ALLOC_PREF>, ) where - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:; + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:; - impl<'r, 'a, T, A: Allocator, const CO_ALLOC_PREF: CoAllocPref> Drop for DropGuard<'r, 'a, T, A, CO_ALLOC_PREF> + impl<'r, 'a, T, A: Allocator, const CO_ALLOC_PREF: CoAllocPref> Drop + for DropGuard<'r, 'a, T, A, CO_ALLOC_PREF> where - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { fn drop(&mut self) { if self.0.tail_len > 0 { @@ -288,9 +296,10 @@ where #[stable(feature = "drain", since = "1.6.0")] #[allow(unused_braces)] -impl ExactSizeIterator for Drain<'_, T, A, CO_ALLOC_PREF> +impl ExactSizeIterator + for Drain<'_, T, A, CO_ALLOC_PREF> where - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { fn is_empty(&self) -> bool { self.iter.is_empty() @@ -299,14 +308,18 @@ where #[unstable(feature = "trusted_len", issue = "37572")] #[allow(unused_braces)] -unsafe impl TrustedLen for Drain<'_, T, A, CO_ALLOC_PREF> where - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]: +unsafe impl TrustedLen + for Drain<'_, T, A, CO_ALLOC_PREF> +where + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { } #[stable(feature = "fused", since = "1.26.0")] #[allow(unused_braces)] -impl FusedIterator for Drain<'_, T, A, CO_ALLOC_PREF> where - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]: +impl FusedIterator + for Drain<'_, T, A, CO_ALLOC_PREF> +where + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { } diff --git a/library/alloc/src/vec/drain_filter.rs b/library/alloc/src/vec/drain_filter.rs index 4ca2c6f2a7f34..c47d21733cd94 100644 --- a/library/alloc/src/vec/drain_filter.rs +++ b/library/alloc/src/vec/drain_filter.rs @@ -26,10 +26,10 @@ pub struct DrainFilter< T, F, #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global, - const CO_ALLOC_PREF: CoAllocPref = {CO_ALLOC_PREF_DEFAULT!()}, + const CO_ALLOC_PREF: CoAllocPref = { CO_ALLOC_PREF_DEFAULT!() }, > where F: FnMut(&mut T) -> bool, - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { pub(super) vec: &'a mut Vec, /// The index of the item that will be inspected by the next call to `next`. @@ -52,7 +52,7 @@ pub struct DrainFilter< impl DrainFilter<'_, T, F, A, CO_ALLOC_PREF> where F: FnMut(&mut T) -> bool, - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { /// Returns a reference to the underlying allocator. #[unstable(feature = "allocator_api", issue = "32838")] @@ -119,10 +119,11 @@ where #[unstable(feature = "drain_filter", reason = "recently added", issue = "43244")] #[allow(unused_braces)] -impl Iterator for DrainFilter<'_, T, F, A, CO_ALLOC_PREF> +impl Iterator + for DrainFilter<'_, T, F, A, CO_ALLOC_PREF> where F: FnMut(&mut T) -> bool, - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { type Item = T; @@ -159,17 +160,18 @@ where #[unstable(feature = "drain_filter", reason = "recently added", issue = "43244")] #[allow(unused_braces)] -impl Drop for DrainFilter<'_, T, F, A, CO_ALLOC_PREF> +impl Drop + for DrainFilter<'_, T, F, A, CO_ALLOC_PREF> where F: FnMut(&mut T) -> bool, - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { #[allow(unused_braces)] fn drop(&mut self) { struct BackshiftOnDrop<'a, 'b, T, F, A: Allocator, const CO_ALLOC_PREF: CoAllocPref> where F: FnMut(&mut T) -> bool, - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { drain: &'b mut DrainFilter<'a, T, F, A, CO_ALLOC_PREF>, } @@ -179,7 +181,7 @@ where for BackshiftOnDrop<'a, 'b, T, F, A, CO_ALLOC_PREF> where F: FnMut(&mut T) -> bool, - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { fn drop(&mut self) { unsafe { diff --git a/library/alloc/src/vec/in_place_collect.rs b/library/alloc/src/vec/in_place_collect.rs index 2e51f655d2bcf..f2d9579c20276 100644 --- a/library/alloc/src/vec/in_place_collect.rs +++ b/library/alloc/src/vec/in_place_collect.rs @@ -156,7 +156,7 @@ impl InPlaceIterableMarker for T where T: InPlaceIterable {} impl SpecFromIter for Vec where I: Iterator + SourceIter + InPlaceIterableMarker, - [(); {crate::meta_num_slots_global!(CO_ALLOC_PREF)}]:, + [(); { crate::meta_num_slots_global!(CO_ALLOC_PREF) }]:, { default fn from_iter(mut iterator: I) -> Self { // See "Layout constraints" section in the module documentation. We rely on const diff --git a/library/alloc/src/vec/in_place_drop.rs b/library/alloc/src/vec/in_place_drop.rs index c61d81b37ecb8..42ebb6ca395d7 100644 --- a/library/alloc/src/vec/in_place_drop.rs +++ b/library/alloc/src/vec/in_place_drop.rs @@ -36,6 +36,10 @@ impl Drop for InPlaceDstBufDrop { #[inline] fn drop(&mut self) { // false = no need for co-alloc metadata, since it would get lost once converted to Box. - unsafe { super::Vec::::from_raw_parts(self.ptr, self.len, self.cap) }; + unsafe { + super::Vec::::from_raw_parts( + self.ptr, self.len, self.cap, + ) + }; } } diff --git a/library/alloc/src/vec/into_iter.rs b/library/alloc/src/vec/into_iter.rs index 97d1f51b2eeb2..011794ea2e99d 100644 --- a/library/alloc/src/vec/into_iter.rs +++ b/library/alloc/src/vec/into_iter.rs @@ -1,9 +1,9 @@ #[cfg(not(no_global_oom_handling))] use super::AsVecIntoIter; use crate::alloc::{Allocator, Global}; +use crate::co_alloc::CoAllocPref; #[cfg(not(no_global_oom_handling))] use crate::collections::VecDeque; -use crate::co_alloc::CoAllocPref; use crate::raw_vec::RawVec; use core::iter::{ FusedIterator, InPlaceIterable, SourceIter, TrustedLen, TrustedRandomAccessNoCoerce, @@ -14,7 +14,7 @@ use core::mem::{self, ManuallyDrop, MaybeUninit, SizedTypeProperties}; use core::ops::Deref; use core::ptr::{self, NonNull}; use core::slice::{self}; -use core::{ array, fmt}; +use core::{array, fmt}; /// An iterator that moves out of a vector. /// @@ -35,7 +35,7 @@ pub struct IntoIter< #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global, const CO_ALLOC_PREF: CoAllocPref = { SHORT_TERM_VEC_CO_ALLOC_PREF!() }, > where - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { pub(super) buf: NonNull, pub(super) phantom: PhantomData, @@ -51,9 +51,10 @@ pub struct IntoIter< #[stable(feature = "vec_intoiter_debug", since = "1.13.0")] #[allow(unused_braces)] -impl fmt::Debug for IntoIter +impl fmt::Debug + for IntoIter where - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_tuple("IntoIter").field(&self.as_slice()).finish() @@ -63,7 +64,7 @@ where #[allow(unused_braces)] impl IntoIter where - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { /// Returns the remaining items of this iterator as a slice. /// @@ -139,11 +140,17 @@ where // //NonNull::new_unchecked(RawVec::::NEW.ptr()); let meta_num_slots = crate::meta_num_slots!(A, CO_ALLOC_PREF); - if meta_num_slots>0 { - debug_assert!(meta_num_slots==1, "Number of coallocation meta slots can be only 0 or 1, but it is {}!", meta_num_slots); - NonNull::new_unchecked(RawVec::::NEW.ptr()) + if meta_num_slots > 0 { + debug_assert!( + meta_num_slots == 1, + "Number of coallocation meta slots can be only 0 or 1, but it is {}!", + meta_num_slots + ); + NonNull::new_unchecked( + RawVec::::NEW.ptr(), + ) } else { - NonNull::new_unchecked(RawVec::::NEW.ptr()) + NonNull::new_unchecked(RawVec::::NEW.ptr()) } }; self.ptr = self.buf.as_ptr(); @@ -195,7 +202,7 @@ where #[allow(unused_braces)] impl AsRef<[T]> for IntoIter where - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { fn as_ref(&self) -> &[T] { self.as_slice() @@ -204,14 +211,18 @@ where #[stable(feature = "rust1", since = "1.0.0")] #[allow(unused_braces)] -unsafe impl Send for IntoIter where - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]: +unsafe impl Send + for IntoIter +where + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { } #[stable(feature = "rust1", since = "1.0.0")] #[allow(unused_braces)] -unsafe impl Sync for IntoIter where - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]: +unsafe impl Sync + for IntoIter +where + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { } @@ -219,7 +230,7 @@ unsafe impl Sync #[allow(unused_braces)] impl Iterator for IntoIter where - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { type Item = T; @@ -335,9 +346,10 @@ where #[stable(feature = "rust1", since = "1.0.0")] #[allow(unused_braces)] -impl DoubleEndedIterator for IntoIter +impl DoubleEndedIterator + for IntoIter where - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { #[inline] fn next_back(&mut self) -> Option { @@ -380,9 +392,10 @@ where #[stable(feature = "rust1", since = "1.0.0")] #[allow(unused_braces)] -impl ExactSizeIterator for IntoIter +impl ExactSizeIterator + for IntoIter where - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { fn is_empty(&self) -> bool { self.ptr == self.end @@ -391,15 +404,19 @@ where #[stable(feature = "fused", since = "1.26.0")] #[allow(unused_braces)] -impl FusedIterator for IntoIter where - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]: +impl FusedIterator + for IntoIter +where + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { } #[unstable(feature = "trusted_len", issue = "37572")] #[allow(unused_braces)] -unsafe impl TrustedLen for IntoIter where - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]: +unsafe impl TrustedLen + for IntoIter +where + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { } @@ -422,7 +439,7 @@ unsafe impl TrustedRandomAcce for IntoIter where T: NonDrop, - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { const MAY_HAVE_SIDE_EFFECT: bool = false; } @@ -430,9 +447,10 @@ where #[cfg(not(no_global_oom_handling))] #[stable(feature = "vec_into_iter_clone", since = "1.8.0")] #[allow(unused_braces)] -impl Clone for IntoIter +impl Clone + for IntoIter where - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { #[cfg(not(test))] fn clone(&self) -> Self { @@ -453,20 +471,21 @@ where #[stable(feature = "rust1", since = "1.0.0")] #[allow(unused_braces)] -unsafe impl<#[may_dangle] T, A: Allocator, const CO_ALLOC_PREF: CoAllocPref> Drop for IntoIter +unsafe impl<#[may_dangle] T, A: Allocator, const CO_ALLOC_PREF: CoAllocPref> Drop + for IntoIter where - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { fn drop(&mut self) { struct DropGuard<'a, T, A: Allocator, const CO_ALLOC_PREF: CoAllocPref>( &'a mut IntoIter, ) where - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:; + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:; impl Drop for DropGuard<'_, T, A, CO_ALLOC_PREF> where - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { fn drop(&mut self) { unsafe { @@ -497,17 +516,20 @@ where #[unstable(issue = "none", feature = "inplace_iteration")] #[doc(hidden)] #[allow(unused_braces)] -unsafe impl InPlaceIterable for IntoIter where - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]: +unsafe impl InPlaceIterable + for IntoIter +where + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { } #[unstable(issue = "none", feature = "inplace_iteration")] #[doc(hidden)] #[allow(unused_braces)] -unsafe impl SourceIter for IntoIter +unsafe impl SourceIter + for IntoIter where - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { type Source = Self; diff --git a/library/alloc/src/vec/mod.rs b/library/alloc/src/vec/mod.rs index dabd0cff0fdef..a6d1da35c89d1 100644 --- a/library/alloc/src/vec/mod.rs +++ b/library/alloc/src/vec/mod.rs @@ -405,7 +405,7 @@ pub struct Vec< //@FIXME: #[unstable(feature ="global_co_alloc_vec", issue="none")] const CO_ALLOC_PREF: CoAllocPref = { CO_ALLOC_PREF_DEFAULT!() }, > where - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { buf: RawVec, len: usize, @@ -413,12 +413,12 @@ pub struct Vec< /// "Cooperative" Vector. Preferring co-alloc API (if Global alloc supports it). #[unstable(feature = "global_co_alloc_covec", issue = "none")] -pub type CoVec = Vec; +pub type CoVec = Vec; /// "Plain" Vec. Not "cooperative" - not carrying extra data to assist the allocator. /// FIXME after cleanup, see if we still use this in core:: and/or alloc:: #[unstable(feature = "global_co_alloc_plvec", issue = "none")] -pub type PlVec = Vec; +pub type PlVec = Vec; /// "Default" Vec. Either "cooperative" or not - as specified by `DEFAULT_CO_ALLOC_PREF`. The /// difference to `Vec` (used without specifying `CO_ALLOC_PREF`): `DefVec` indicates that the @@ -518,7 +518,7 @@ impl Vec { #[allow(unused_braces)] impl Vec where - [(); {meta_num_slots_global!(CO_ALLOC_PREF)}]:, + [(); { meta_num_slots_global!(CO_ALLOC_PREF) }]:, { /// Like new(), but it respects CO_ALLOC_PREF. #[inline] @@ -594,11 +594,9 @@ where pub unsafe fn from_raw_parts_co(ptr: *mut T, length: usize, capacity: usize) -> Self { unsafe { Self::from_raw_parts_in(ptr, length, capacity, Global) } } - } -impl Vec -{ +impl Vec { /// Creates a `Vec` directly from a pointer, a capacity, and a length. /// /// # Safety @@ -712,7 +710,7 @@ impl Vec #[allow(unused_braces)] impl Vec where - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { /// Constructs a new, empty `Vec`. /// @@ -1726,9 +1724,14 @@ where // This drop guard will be invoked when predicate or `drop` of element panicked. // It shifts unchecked elements to cover holes and `set_len` to the correct length. // In cases when predicate and `drop` never panick, it will be optimized out. - struct BackshiftOnDrop<'a, T, A: Allocator, const VEC_CO_ALLOC_PREF: CoAllocPref = {CO_ALLOC_PREF_META_DEFAULT!()}> + struct BackshiftOnDrop< + 'a, + T, + A: Allocator, + const VEC_CO_ALLOC_PREF: CoAllocPref = { CO_ALLOC_PREF_META_DEFAULT!() }, + > where - [(); {crate::meta_num_slots!(A, VEC_CO_ALLOC_PREF)}]:, + [(); { crate::meta_num_slots!(A, VEC_CO_ALLOC_PREF) }]:, { v: &'a mut Vec, processed_len: usize, @@ -1737,9 +1740,10 @@ where } #[allow(unused_braces)] - impl Drop for BackshiftOnDrop<'_, T, A, VEC_CO_ALLOC_PREF> + impl Drop + for BackshiftOnDrop<'_, T, A, VEC_CO_ALLOC_PREF> where - [(); {crate::meta_num_slots!(A, VEC_CO_ALLOC_PREF)}]:, + [(); { crate::meta_num_slots!(A, VEC_CO_ALLOC_PREF) }]:, { fn drop(&mut self) { if self.deleted_cnt > 0 { @@ -1766,13 +1770,19 @@ where original_len, }; - fn process_loop( + fn process_loop< + F, + T, + A: Allocator, + const DELETED: bool, + const VEC_CO_ALLOC_PREF: CoAllocPref, + >( original_len: usize, f: &mut F, g: &mut BackshiftOnDrop<'_, T, A, VEC_CO_ALLOC_PREF>, ) where F: FnMut(&mut T) -> bool, - [(); {crate::meta_num_slots!(A, VEC_CO_ALLOC_PREF)}]:, + [(); { crate::meta_num_slots!(A, VEC_CO_ALLOC_PREF) }]:, { while g.processed_len != original_len { // SAFETY: Unchecked element must be valid. @@ -1867,8 +1877,10 @@ where /* INVARIANT: vec.len() > read >= write > write-1 >= 0 */ struct FillGapOnDrop<'a, T, A: core::alloc::Allocator, const CO_ALLOC_PREF: CoAllocPref> where - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { + crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, + { /* Offset of the element we want to check if it is duplicate */ read: usize, @@ -1884,7 +1896,7 @@ where impl<'a, T, A: core::alloc::Allocator, const CO_ALLOC_PREF: CoAllocPref> Drop for FillGapOnDrop<'a, T, A, CO_ALLOC_PREF> where - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { fn drop(&mut self) { /* This code gets executed when `same_bucket` panics */ @@ -2481,7 +2493,7 @@ where #[allow(unused_braces)] impl Vec where - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { /// Resizes the `Vec` in-place so that `len` is equal to `new_len`. /// @@ -2582,9 +2594,10 @@ where } #[allow(unused_braces)] -impl Vec<[T; N], A, CO_ALLOC_PREF> +impl + Vec<[T; N], A, CO_ALLOC_PREF> where - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { /// Takes a `Vec<[T; N]>` and flattens it into a `Vec`. /// @@ -2626,7 +2639,9 @@ where // - `new_cap` refers to the same sized allocation as `cap` because // `new_cap * size_of::()` == `cap * size_of::<[T; N]>()` // - `len` <= `cap`, so `len * N` <= `cap * N`. - unsafe { Vec::::from_raw_parts_in(ptr.cast(), new_len, new_cap, alloc) } + unsafe { + Vec::::from_raw_parts_in(ptr.cast(), new_len, new_cap, alloc) + } } } @@ -2649,7 +2664,7 @@ impl ExtendWith for ExtendElement { #[allow(unused_braces)] impl Vec where - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { #[cfg(not(no_global_oom_handling))] /// Extend the vector by `n` values, using the given generator. @@ -2685,7 +2700,7 @@ where #[allow(unused_braces)] impl Vec where - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { /// Removes consecutive repeated elements in the vector according to the /// [`PartialEq`] trait implementation. @@ -2729,7 +2744,7 @@ pub fn from_elem_in( alloc: A, ) -> Vec where - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { ::from_elem(elem, n, alloc) } @@ -2743,9 +2758,10 @@ trait ExtendFromWithinSpec { } #[allow(unused_braces)] -impl ExtendFromWithinSpec for Vec +impl ExtendFromWithinSpec + for Vec where - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { default unsafe fn spec_extend_from_within(&mut self, src: Range) { // SAFETY: @@ -2766,9 +2782,10 @@ where } #[allow(unused_braces)] -impl ExtendFromWithinSpec for Vec +impl ExtendFromWithinSpec + for Vec where - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { unsafe fn spec_extend_from_within(&mut self, src: Range) { let count = src.len(); @@ -2805,7 +2822,7 @@ where #[allow(unused_braces)] impl ops::Deref for Vec where - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { type Target = [T]; @@ -2819,7 +2836,7 @@ where #[allow(unused_braces)] impl ops::DerefMut for Vec where - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { #[inline] fn deref_mut(&mut self) -> &mut [T] { @@ -2830,9 +2847,10 @@ where #[cfg(not(no_global_oom_handling))] #[stable(feature = "rust1", since = "1.0.0")] #[allow(unused_braces)] -impl Clone for Vec +impl Clone + for Vec where - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { #[cfg(not(test))] fn clone(&self) -> Self { @@ -2871,7 +2889,7 @@ where #[allow(unused_braces)] impl Hash for Vec where - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { #[inline] fn hash(&self, state: &mut H) { @@ -2885,9 +2903,10 @@ where label = "vector indices are of type `usize` or ranges of `usize`" )] #[allow(unused_braces)] -impl, A: Allocator, const CO_ALLOC_PREF: CoAllocPref> Index for Vec +impl, A: Allocator, const CO_ALLOC_PREF: CoAllocPref> Index + for Vec where - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { type Output = I::Output; @@ -2906,7 +2925,7 @@ where impl, A: Allocator, const CO_ALLOC_PREF: CoAllocPref> IndexMut for Vec where - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { #[inline] fn index_mut(&mut self, index: I) -> &mut Self::Output { @@ -2917,8 +2936,7 @@ where #[cfg(not(no_global_oom_handling))] #[stable(feature = "rust1", since = "1.0.0")] #[allow(unused_braces)] -impl FromIterator for Vec -{ +impl FromIterator for Vec { #[inline] fn from_iter>(iter: I) -> Vec { >::from_iter(iter.into_iter()) @@ -2926,11 +2944,11 @@ impl FromIterator for Vec } #[cfg(not(no_global_oom_handling))] -#[unstable(feature = "global_co_alloc", issue="none")] +#[unstable(feature = "global_co_alloc", issue = "none")] #[allow(unused_braces)] impl Vec where - [(); {crate::meta_num_slots_global!(CO_ALLOC_PREF)}]:, + [(); { crate::meta_num_slots_global!(CO_ALLOC_PREF) }]:, { /// Coallocation-aware alternative to `from_iter`. #[inline] @@ -2943,7 +2961,7 @@ where #[allow(unused_braces)] impl IntoIterator for Vec where - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { type Item = T; type IntoIter = IntoIter; @@ -2990,9 +3008,10 @@ where #[stable(feature = "rust1", since = "1.0.0")] #[allow(unused_braces)] -impl<'a, T, A: Allocator, const CO_ALLOC_PREF: CoAllocPref> IntoIterator for &'a Vec +impl<'a, T, A: Allocator, const CO_ALLOC_PREF: CoAllocPref> IntoIterator + for &'a Vec where - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { type Item = &'a T; type IntoIter = slice::Iter<'a, T>; @@ -3004,9 +3023,10 @@ where #[stable(feature = "rust1", since = "1.0.0")] #[allow(unused_braces)] -impl<'a, T, A: Allocator, const CO_ALLOC_PREF: CoAllocPref> IntoIterator for &'a mut Vec +impl<'a, T, A: Allocator, const CO_ALLOC_PREF: CoAllocPref> IntoIterator + for &'a mut Vec where - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { type Item = &'a mut T; type IntoIter = slice::IterMut<'a, T>; @@ -3021,7 +3041,7 @@ where #[allow(unused_braces)] impl Extend for Vec where - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { #[inline] fn extend>(&mut self, iter: I) { @@ -3042,7 +3062,7 @@ where #[allow(unused_braces)] impl Vec where - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { // leaf method to which various SpecFrom/SpecExtend implementations delegate when // they have no further optimizations to apply @@ -3149,7 +3169,7 @@ where where R: RangeBounds, I: IntoIterator, - [(); {crate::meta_num_slots!(A, crate::CO_ALLOC_PREF_META_YES!())}]:, + [(); { crate::meta_num_slots!(A, crate::CO_ALLOC_PREF_META_YES!()) }]:, { Splice { drain: self.drain(range), replace_with: replace_with.into_iter() } } @@ -3202,7 +3222,7 @@ where pub fn drain_filter(&mut self, filter: F) -> DrainFilter<'_, T, F, A, CO_ALLOC_PREF> where F: FnMut(&mut T) -> bool, - [(); {crate::meta_num_slots!(A, crate::CO_ALLOC_PREF_META_YES!())}]:, + [(); { crate::meta_num_slots!(A, crate::CO_ALLOC_PREF_META_YES!()) }]:, { let old_len = self.len(); @@ -3227,7 +3247,7 @@ where impl<'a, T: Copy + 'a, A: Allocator + 'a, const CO_ALLOC_PREF: CoAllocPref> Extend<&'a T> for Vec where - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { fn extend>(&mut self, iter: I) { self.spec_extend(iter.into_iter()) @@ -3247,9 +3267,10 @@ where /// Implements comparison of vectors, [lexicographically](core::cmp::Ord#lexicographical-comparison). #[stable(feature = "rust1", since = "1.0.0")] #[allow(unused_braces)] -impl PartialOrd for Vec +impl PartialOrd + for Vec where - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { #[inline] fn partial_cmp(&self, other: &Self) -> Option { @@ -3260,7 +3281,7 @@ where #[stable(feature = "rust1", since = "1.0.0")] #[allow(unused_braces)] impl Eq for Vec where - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]: + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]: { } @@ -3269,7 +3290,7 @@ impl Eq for Vec Ord for Vec where - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { #[inline] fn cmp(&self, other: &Self) -> Ordering { @@ -3279,9 +3300,10 @@ where #[stable(feature = "rust1", since = "1.0.0")] #[allow(unused_braces)] -unsafe impl<#[may_dangle] T, A: Allocator, const CO_ALLOC_PREF: CoAllocPref> Drop for Vec +unsafe impl<#[may_dangle] T, A: Allocator, const CO_ALLOC_PREF: CoAllocPref> Drop + for Vec where - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { fn drop(&mut self) { unsafe { @@ -3299,7 +3321,7 @@ where #[allow(unused_braces)] impl const Default for Vec where - [(); {meta_num_slots_global!(CO_ALLOC_PREF)}]:, + [(); { meta_num_slots_global!(CO_ALLOC_PREF) }]:, { /// Creates an empty `Vec`. /// @@ -3311,9 +3333,10 @@ where #[stable(feature = "rust1", since = "1.0.0")] #[allow(unused_braces)] -impl fmt::Debug for Vec +impl fmt::Debug + for Vec where - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fmt::Debug::fmt(&**self, f) @@ -3322,9 +3345,10 @@ where #[stable(feature = "rust1", since = "1.0.0")] #[allow(unused_braces)] -impl AsRef> for Vec +impl AsRef> + for Vec where - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { fn as_ref(&self) -> &Vec { self @@ -3333,9 +3357,10 @@ where #[stable(feature = "vec_as_mut", since = "1.5.0")] #[allow(unused_braces)] -impl AsMut> for Vec +impl AsMut> + for Vec where - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { fn as_mut(&mut self) -> &mut Vec { self @@ -3346,7 +3371,7 @@ where #[allow(unused_braces)] impl AsRef<[T]> for Vec where - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { fn as_ref(&self) -> &[T] { self @@ -3357,7 +3382,7 @@ where #[allow(unused_braces)] impl AsMut<[T]> for Vec where - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { fn as_mut(&mut self) -> &mut [T] { self @@ -3460,9 +3485,10 @@ where #[cfg(not(test))] #[stable(feature = "vec_from_box", since = "1.18.0")] #[allow(unused_braces)] -impl From> for Vec +impl From> + for Vec where - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { /// Convert a boxed slice into a vector by transferring ownership of /// the existing heap allocation. @@ -3483,9 +3509,10 @@ where #[cfg(not(test))] #[stable(feature = "box_from_vec", since = "1.20.0")] #[allow(unused_braces)] -impl From> for Box<[T], A> +impl From> + for Box<[T], A> where - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { /// Convert a vector into a boxed slice. /// @@ -3528,10 +3555,10 @@ impl From<&str> for Vec { #[stable(feature = "array_try_from_vec", since = "1.48.0")] #[allow(unused_braces)] -impl TryFrom> - for [T; N] +impl + TryFrom> for [T; N] where - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { type Error = Vec; diff --git a/library/alloc/src/vec/spec_extend.rs b/library/alloc/src/vec/spec_extend.rs index 2fcc24131f0cb..546e2c0e0ae77 100644 --- a/library/alloc/src/vec/spec_extend.rs +++ b/library/alloc/src/vec/spec_extend.rs @@ -11,10 +11,11 @@ pub(super) trait SpecExtend { } #[allow(unused_braces)] -impl SpecExtend for Vec +impl SpecExtend + for Vec where I: Iterator, - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { default fn spec_extend(&mut self, iter: I) { self.extend_desugared(iter) @@ -22,10 +23,11 @@ where } #[allow(unused_braces)] -impl SpecExtend for Vec +impl SpecExtend + for Vec where I: TrustedLen, - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { default fn spec_extend(&mut self, iterator: I) { self.extend_trusted(iterator) @@ -33,9 +35,10 @@ where } #[allow(unused_braces)] -impl SpecExtend> for Vec +impl SpecExtend> + for Vec where - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { fn spec_extend(&mut self, mut iterator: IntoIter) { unsafe { @@ -51,7 +54,7 @@ impl<'a, T: 'a, I, A: Allocator + 'a, const CO_ALLOC_PREF: CoAllocPref> SpecExte where I: Iterator, T: Clone, - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { default fn spec_extend(&mut self, iterator: I) { self.spec_extend(iterator.cloned()) @@ -59,11 +62,11 @@ where } #[allow(unused_braces)] -impl<'a, T: 'a, A: Allocator + 'a, const CO_ALLOC_PREF: CoAllocPref> SpecExtend<&'a T, slice::Iter<'a, T>> - for Vec +impl<'a, T: 'a, A: Allocator + 'a, const CO_ALLOC_PREF: CoAllocPref> + SpecExtend<&'a T, slice::Iter<'a, T>> for Vec where T: Copy, - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { fn spec_extend(&mut self, iterator: slice::Iter<'a, T>) { let slice = iterator.as_slice(); diff --git a/library/alloc/src/vec/spec_from_elem.rs b/library/alloc/src/vec/spec_from_elem.rs index b926a6c2d0e0f..f6ddf0a6ef22e 100644 --- a/library/alloc/src/vec/spec_from_elem.rs +++ b/library/alloc/src/vec/spec_from_elem.rs @@ -15,7 +15,7 @@ pub(super) trait SpecFromElem: Sized { alloc: A, ) -> Vec where - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:; + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:; } #[allow(unused_braces)] @@ -26,7 +26,7 @@ impl SpecFromElem for T { alloc: A, ) -> Vec where - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { let mut v = Vec::with_capacity_in(n, alloc); v.extend_with(n, ExtendElement(elem)); @@ -43,7 +43,7 @@ impl SpecFromElem for T { alloc: A, ) -> Vec where - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { if elem.is_zero() { return Vec { buf: RawVec::with_capacity_zeroed_in(n, alloc), len: n }; @@ -63,7 +63,7 @@ impl SpecFromElem for i8 { alloc: A, ) -> Vec where - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { if elem == 0 { return Vec { buf: RawVec::with_capacity_zeroed_in(n, alloc), len: n }; @@ -86,7 +86,7 @@ impl SpecFromElem for u8 { alloc: A, ) -> Vec where - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { if elem == 0 { return Vec { buf: RawVec::with_capacity_zeroed_in(n, alloc), len: n }; diff --git a/library/alloc/src/vec/spec_from_iter.rs b/library/alloc/src/vec/spec_from_iter.rs index be46209748e9b..cde02b319bef6 100644 --- a/library/alloc/src/vec/spec_from_iter.rs +++ b/library/alloc/src/vec/spec_from_iter.rs @@ -31,7 +31,7 @@ pub(super) trait SpecFromIter { impl SpecFromIter for Vec where I: Iterator, - [(); {crate::meta_num_slots_global!(CO_ALLOC_PREF)}]:, + [(); { crate::meta_num_slots_global!(CO_ALLOC_PREF) }]:, { default fn from_iter(iterator: I) -> Self { SpecFromIterNested::from_iter(iterator) @@ -39,9 +39,10 @@ where } #[allow(unused_braces)] -impl SpecFromIter> for Vec +impl SpecFromIter> + for Vec where - [(); {crate::meta_num_slots_global!(CO_ALLOC_PREF)}]:, + [(); { crate::meta_num_slots_global!(CO_ALLOC_PREF) }]:, { fn from_iter(iterator: IntoIter) -> Self { // A common case is passing a vector into a function which immediately diff --git a/library/alloc/src/vec/spec_from_iter_nested.rs b/library/alloc/src/vec/spec_from_iter_nested.rs index f103842f2d884..e567d3697fd28 100644 --- a/library/alloc/src/vec/spec_from_iter_nested.rs +++ b/library/alloc/src/vec/spec_from_iter_nested.rs @@ -17,10 +17,11 @@ pub(super) trait SpecFromIterNested { } #[allow(unused_braces)] -impl SpecFromIterNested for Vec +impl SpecFromIterNested + for Vec where I: Iterator, - [(); {crate::meta_num_slots_global!(CO_ALLOC_PREF)}]:, + [(); { crate::meta_num_slots_global!(CO_ALLOC_PREF) }]:, { default fn from_iter(mut iterator: I) -> Self { // Unroll the first iteration, as the vector is going to be diff --git a/library/alloc/src/vec/splice.rs b/library/alloc/src/vec/splice.rs index cba2057be95a3..b48e021e522f0 100644 --- a/library/alloc/src/vec/splice.rs +++ b/library/alloc/src/vec/splice.rs @@ -24,9 +24,9 @@ pub struct Splice< 'a, I: Iterator + 'a, #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator + 'a = Global, - const CO_ALLOC_PREF: CoAllocPref = {CO_ALLOC_PREF_DEFAULT!()}, + const CO_ALLOC_PREF: CoAllocPref = { CO_ALLOC_PREF_DEFAULT!() }, > where - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { pub(super) drain: Drain<'a, I::Item, A, CO_ALLOC_PREF>, pub(super) replace_with: I, @@ -34,9 +34,10 @@ pub struct Splice< #[stable(feature = "vec_splice", since = "1.21.0")] #[allow(unused_braces)] -impl Iterator for Splice<'_, I, A, CO_ALLOC_PREF> +impl Iterator + for Splice<'_, I, A, CO_ALLOC_PREF> where - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { type Item = I::Item; @@ -54,7 +55,7 @@ where impl DoubleEndedIterator for Splice<'_, I, A, CO_ALLOC_PREF> where - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { fn next_back(&mut self) -> Option { self.drain.next_back() @@ -66,15 +67,16 @@ where impl ExactSizeIterator for Splice<'_, I, A, CO_ALLOC_PREF> where - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { } #[stable(feature = "vec_splice", since = "1.21.0")] #[allow(unused_braces)] -impl Drop for Splice<'_, I, A, CO_ALLOC_PREF> +impl Drop + for Splice<'_, I, A, CO_ALLOC_PREF> where - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { fn drop(&mut self) { self.drain.by_ref().for_each(drop); @@ -125,7 +127,7 @@ where #[allow(unused_braces)] impl Drain<'_, T, A, CO_ALLOC_PREF> where - [(); {crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { /// The range from `self.vec.len` to `self.tail_start` contains elements /// that have been moved out. diff --git a/library/core/src/alloc/mod.rs b/library/core/src/alloc/mod.rs index d763a666c3a75..6ab7e4a87c16f 100644 --- a/library/core/src/alloc/mod.rs +++ b/library/core/src/alloc/mod.rs @@ -101,12 +101,12 @@ impl const CoAllocMetaBase for CoAllocMetaPlain { } /// Whether an `Allocator` implementation supports coallocation. -/// +/// /// This type WILL CHANGE (once ``#![feature(generic_const_exprs)]` and /// `#![feature(adt_const_params)]` are stable) to a dedicated struct/enum. Hence: /// - DO NOT mix this/cast this with/to `u8`, `u16`, (nor any other integer); and /// - DO NOT hard code any values, but use `CO_ALLOCATOR_SUPPORTS_META_YES` and `CO_ALLOCATOR_SUPPORTS_META_NO`. -/// +/// #[unstable(feature = "global_co_alloc_meta", issue = "none")] pub type CoAllocatorMetaNumSlots = u32; @@ -182,7 +182,7 @@ pub unsafe trait Allocator { /// Type to store coallocation metadata (if both the allocator and the heap-based type support /// coallocation, and if coallocation is used). - /// + /// /// If this is any type with non-zero size, then the actual `Allocator` implementation supports /// cooperative functions (`co_*`) as first class citizens. NOT for public use. The default /// value MAY be REMOVED or CHANGED. @@ -616,4 +616,4 @@ where // SAFETY: the safety contract must be upheld by the caller unsafe { (**self).shrink(ptr, old_layout, new_layout) } } -} \ No newline at end of file +} diff --git a/library/proc_macro/src/bridge/mod.rs b/library/proc_macro/src/bridge/mod.rs index c3aff25e68eae..e7980d44fd498 100644 --- a/library/proc_macro/src/bridge/mod.rs +++ b/library/proc_macro/src/bridge/mod.rs @@ -253,14 +253,14 @@ impl<'a, T, M> Unmark for &'a mut Marked { } } -impl Mark for Vec { +impl Mark for Vec { type Unmarked = Vec; fn mark(unmarked: Self::Unmarked) -> Self { // Should be a no-op due to std's in-place collect optimizations. unmarked.into_iter().map(T::mark).collect() } } -impl Unmark for Vec { +impl Unmark for Vec { type Unmarked = Vec; fn unmark(self) -> Self::Unmarked { // Should be a no-op due to std's in-place collect optimizations. diff --git a/library/proc_macro/src/bridge/rpc.rs b/library/proc_macro/src/bridge/rpc.rs index fc856b98b2c33..e116a54b7e73f 100644 --- a/library/proc_macro/src/bridge/rpc.rs +++ b/library/proc_macro/src/bridge/rpc.rs @@ -1,10 +1,10 @@ //! Serialization for client-server communication. +use std::alloc::Global; use std::any::Any; use std::io::Write; use std::num::NonZeroU32; use std::str; -use std::alloc::Global; //use alloc::alloc::Global; //use std::CO_ALLOC_PREF_DEFAULT; @@ -227,7 +227,7 @@ impl DecodeMut<'_, '_, S> for String { } } -impl> Encode for Vec { +impl> Encode for Vec { fn encode(self, w: &mut Writer, s: &mut S) { self.len().encode(w, s); for x in self { @@ -237,7 +237,7 @@ impl> Encode for Vec { } impl<'a, S, T: for<'s> DecodeMut<'a, 's, S>> DecodeMut<'a, '_, S> - for Vec + for Vec { fn decode(r: &mut Reader<'a>, s: &mut S) -> Self { let len = usize::decode(r, s); diff --git a/library/proc_macro/src/diagnostic.rs b/library/proc_macro/src/diagnostic.rs index 13bd91286dad0..9a81e60061141 100644 --- a/library/proc_macro/src/diagnostic.rs +++ b/library/proc_macro/src/diagnostic.rs @@ -31,7 +31,7 @@ impl MultiSpan for Span { } #[unstable(feature = "proc_macro_diagnostic", issue = "54140")] -impl MultiSpan for Vec { +impl MultiSpan for Vec { fn into_spans(self) -> Vec { self } diff --git a/library/std/src/io/cursor.rs b/library/std/src/io/cursor.rs index 5eb5cba4531df..2a95ad4ceb2d2 100644 --- a/library/std/src/io/cursor.rs +++ b/library/std/src/io/cursor.rs @@ -405,7 +405,7 @@ fn reserve_and_pad( buf_len: usize, ) -> io::Result where - [(); {meta_num_slots!(A, CO_ALLOC_PREF)}]:, + [(); { meta_num_slots!(A, CO_ALLOC_PREF) }]:, { let pos: usize = (*pos_mut).try_into().map_err(|_| { io::const_io_error!( @@ -453,7 +453,7 @@ unsafe fn vec_write_unchecked( ) -> usize where A: Allocator, - [(); {meta_num_slots!(A, CO_ALLOC_PREF)}]:, + [(); { meta_num_slots!(A, CO_ALLOC_PREF) }]:, { debug_assert!(vec.capacity() >= pos + buf.len()); vec.as_mut_ptr().add(pos).copy_from(buf.as_ptr(), buf.len()); @@ -477,7 +477,7 @@ fn vec_write( ) -> io::Result where A: Allocator, - [(); {meta_num_slots!(A, CO_ALLOC_PREF)}]:, + [(); { meta_num_slots!(A, CO_ALLOC_PREF) }]:, { let buf_len = buf.len(); let mut pos = reserve_and_pad(pos_mut, vec, buf_len)?; @@ -514,7 +514,7 @@ fn vec_write_vectored( ) -> io::Result where A: Allocator, - [(); {meta_num_slots!(A, CO_ALLOC_PREF)}]:, + [(); { meta_num_slots!(A, CO_ALLOC_PREF) }]:, { // For safety reasons, we don't want this sum to overflow ever. // If this saturates, the reserve should panic to avoid any unsound writing. @@ -566,7 +566,7 @@ impl Write for Cursor<&mut [u8]> { impl Write for Cursor<&mut Vec> where A: Allocator, - [(); {meta_num_slots!(A, CO_ALLOC_PREF)}]:, + [(); { meta_num_slots!(A, CO_ALLOC_PREF) }]:, { fn write(&mut self, buf: &[u8]) -> io::Result { vec_write(&mut self.pos, self.inner, buf) @@ -592,7 +592,7 @@ where impl Write for Cursor> where A: Allocator, - [(); {meta_num_slots!(A, CO_ALLOC_PREF)}]:, + [(); { meta_num_slots!(A, CO_ALLOC_PREF) }]:, { fn write(&mut self, buf: &[u8]) -> io::Result { vec_write(&mut self.pos, &mut self.inner, buf) diff --git a/library/std/src/io/impls.rs b/library/std/src/io/impls.rs index 284c11374e8c1..561ec13038ee5 100644 --- a/library/std/src/io/impls.rs +++ b/library/std/src/io/impls.rs @@ -382,7 +382,7 @@ impl Write for &mut [u8] { #[allow(unused_braces)] impl Write for Vec where - [(); {meta_num_slots!(A, CO_ALLOC_PREF)}]:, + [(); { meta_num_slots!(A, CO_ALLOC_PREF) }]:, { #[inline] fn write(&mut self, buf: &[u8]) -> io::Result { @@ -422,7 +422,7 @@ where #[allow(unused_braces)] impl Read for VecDeque where - [(); {meta_num_slots!(A, CO_ALLOC_PREF)}]:, + [(); { meta_num_slots!(A, CO_ALLOC_PREF) }]:, { /// Fill `buf` with the contents of the "front" slice as returned by /// [`as_slices`][`VecDeque::as_slices`]. If the contained byte slices of the `VecDeque` are @@ -450,7 +450,7 @@ where #[allow(unused_braces)] impl Write for VecDeque where - [(); {meta_num_slots!(A, CO_ALLOC_PREF)}]:, + [(); { meta_num_slots!(A, CO_ALLOC_PREF) }]:, { #[inline] fn write(&mut self, buf: &[u8]) -> io::Result { diff --git a/library/std/src/lib.rs b/library/std/src/lib.rs index c05ea98f3b41a..7ffb41a32d731 100644 --- a/library/std/src/lib.rs +++ b/library/std/src/lib.rs @@ -420,8 +420,6 @@ pub use alloc_crate::boxed; #[unstable(feature = "global_co_alloc", issue = "none")] pub use alloc_crate::co_alloc; // @FIXME ugly - someone move this to a better place, please -#[unstable(feature = "global_co_alloc", issue = "none")] -pub use alloc_crate::{CO_ALLOC_PREF_DEFAULT, SHORT_TERM_VEC_CO_ALLOC_PREF}; #[stable(feature = "rust1", since = "1.0.0")] pub use alloc_crate::fmt; #[stable(feature = "rust1", since = "1.0.0")] @@ -436,6 +434,8 @@ pub use alloc_crate::str; pub use alloc_crate::string; #[stable(feature = "rust1", since = "1.0.0")] pub use alloc_crate::vec; +#[unstable(feature = "global_co_alloc", issue = "none")] +pub use alloc_crate::{CO_ALLOC_PREF_DEFAULT, SHORT_TERM_VEC_CO_ALLOC_PREF}; #[stable(feature = "rust1", since = "1.0.0")] pub use core::any; #[stable(feature = "core_array", since = "1.36.0")] diff --git a/library/test/src/stats.rs b/library/test/src/stats.rs index 59a669c6f91e6..bc892745d75a3 100644 --- a/library/test/src/stats.rs +++ b/library/test/src/stats.rs @@ -233,13 +233,13 @@ impl Stats for [f64] { } fn percentile(&self, pct: f64) -> f64 { - let mut tmp = self.to_vec_co::<{SHORT_TERM_VEC_CO_ALLOC_PREF!()}>(); + let mut tmp = self.to_vec_co::<{ SHORT_TERM_VEC_CO_ALLOC_PREF!() }>(); local_sort(&mut tmp); percentile_of_sorted(&tmp, pct) } fn quartiles(&self) -> (f64, f64, f64) { - let mut tmp = self.to_vec_co::<{SHORT_TERM_VEC_CO_ALLOC_PREF!()}>(); + let mut tmp = self.to_vec_co::<{ SHORT_TERM_VEC_CO_ALLOC_PREF!() }>(); local_sort(&mut tmp); let first = 25_f64; let a = percentile_of_sorted(&tmp, first); From 68dc9e4f80127b76b1285b707a55c84a0c49248e Mon Sep 17 00:00:00 2001 From: Peter Kehl Date: Wed, 1 Feb 2023 20:57:57 -0800 Subject: [PATCH 101/118] CoAlloc: Fixed my buggy rebase. Added slice::SpecCloneIntoVecCo and fixed Vec::clone_from. --- library/alloc/src/slice.rs | 38 ++++++++++++++++++++++++++++++++++++ library/alloc/src/vec/mod.rs | 4 +--- 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/library/alloc/src/slice.rs b/library/alloc/src/slice.rs index d3fd1b9839538..4f3600752b2b9 100644 --- a/library/alloc/src/slice.rs +++ b/library/alloc/src/slice.rs @@ -1000,6 +1000,44 @@ impl SpecCloneIntoVec for [T] { } } +/// Coallocation-aware version of `SpecCloneIntoVec`. +#[cfg(not(no_global_oom_handling))] +#[allow(unused_braces)] +pub(crate) trait SpecCloneIntoVecCo +where [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, + { + fn clone_into_co(&self, target: &mut Vec); +} + +#[cfg(not(no_global_oom_handling))] +#[allow(unused_braces)] +impl SpecCloneIntoVecCo for [T] +where [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { + default fn clone_into_co(&self, target: &mut Vec) { + // drop anything in target that will not be overwritten + target.truncate(self.len()); + + // target.len <= self.len due to the truncate above, so the + // slices here are always in-bounds. + let (init, tail) = self.split_at(target.len()); + + // reuse the contained values' allocations/resources. + target.clone_from_slice(init); + target.extend_from_slice(tail); + } +} + +#[cfg(not(no_global_oom_handling))] +#[allow(unused_braces)] +impl SpecCloneIntoVecCo for [T] +where [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { + fn clone_into_co(&self, target: &mut Vec) { + target.clear(); + target.extend_from_slice(self); + } +} + + #[cfg(not(no_global_oom_handling))] #[stable(feature = "rust1", since = "1.0.0")] impl ToOwned for [T] { diff --git a/library/alloc/src/vec/mod.rs b/library/alloc/src/vec/mod.rs index a6d1da35c89d1..e8839417f3fce 100644 --- a/library/alloc/src/vec/mod.rs +++ b/library/alloc/src/vec/mod.rs @@ -1879,8 +1879,6 @@ where where [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { - crate::meta_num_slots!(A, CO_ALLOC_PREF)}]:, - { /* Offset of the element we want to check if it is duplicate */ read: usize, @@ -2869,7 +2867,7 @@ where } fn clone_from(&mut self, other: &Self) { - crate::slice::SpecCloneIntoVec::clone_into(other.as_slice(), self); + crate::slice::SpecCloneIntoVecCo::clone_into_co(other.as_slice(), self); } } From 819d4e1a27eeb4e17f00fb89ed080cde23c814b0 Mon Sep 17 00:00:00 2001 From: Peter Kehl Date: Wed, 1 Feb 2023 21:11:22 -0800 Subject: [PATCH 102/118] CoAlloc: Default for Vec - both coallocation-aware (default fn), and 'standard'. --- library/alloc/src/vec/mod.rs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/library/alloc/src/vec/mod.rs b/library/alloc/src/vec/mod.rs index e8839417f3fce..aa4a3a7394f93 100644 --- a/library/alloc/src/vec/mod.rs +++ b/library/alloc/src/vec/mod.rs @@ -3324,7 +3324,20 @@ where /// Creates an empty `Vec`. /// /// The vector will not allocate until elements are pushed onto it. - fn default() -> Vec { + default fn default() -> Vec { + Vec::new_co() + } +} + +#[stable(feature = "rust1", since = "1.0.0")] +#[rustc_const_unstable(feature = "const_default_impls", issue = "87864")] +#[allow(unused_braces)] +impl const Default for Vec +{ + /// Creates an empty `Vec`. + /// + /// The vector will not allocate until elements are pushed onto it. + fn default() -> Vec { Vec::new_co() } } From bd1f71ba506aa9d462dad0c72181347d8e670d06 Mon Sep 17 00:00:00 2001 From: Peter Kehl Date: Wed, 1 Feb 2023 21:22:55 -0800 Subject: [PATCH 103/118] CoAlloc: VecDeque: new_co, with_capacity_co, made default() coallocation-friendly. --- .../alloc/src/collections/vec_deque/mod.rs | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/library/alloc/src/collections/vec_deque/mod.rs b/library/alloc/src/collections/vec_deque/mod.rs index bcc42e53654e3..dd71eb0a37999 100644 --- a/library/alloc/src/collections/vec_deque/mod.rs +++ b/library/alloc/src/collections/vec_deque/mod.rs @@ -158,6 +158,19 @@ where } } +#[stable(feature = "rust1", since = "1.0.0")] +#[allow(unused_braces)] +impl Default for VecDeque +where + [(); { meta_num_slots_global!(CO_ALLOC_PREF) }]:, +{ + /// Creates an empty deque. + #[inline] + default fn default() -> VecDeque { + VecDeque::::new_co() + } +} + #[stable(feature = "rust1", since = "1.0.0")] #[allow(unused_braces)] impl Default for VecDeque { @@ -589,6 +602,32 @@ impl VecDeque { } } +#[allow(unused_braces)] +impl VecDeque +where + [(); { crate::meta_num_slots_global!(CO_ALLOC_PREF) }]:, +{ + /// Coallocation-aware version of `new`. + #[inline] + #[unstable(feature = "co_alloc_global", issue="none")] + #[must_use] + #[allow(unused_braces)] + pub const fn new_co() -> VecDeque + { + // FIXME: This should just be `VecDeque::new_in(Global)` once that hits stable. + VecDeque { head: 0, len: 0, buf: RawVec::NEW } + } + + /// Coallocation-aware version of `with_capacity`. + #[inline] + #[stable(feature = "rust1", since = "1.0.0")] + #[must_use] + #[allow(unused_braces)] + pub fn with_capacity_co(capacity: usize) -> VecDeque { + VecDeque::::with_capacity_in(capacity, Global) + } +} + #[allow(unused_braces)] impl VecDeque where From 20eded133195d0932680bbbcdd13cf600cbd97fe Mon Sep 17 00:00:00 2001 From: Peter Kehl Date: Thu, 2 Feb 2023 11:20:11 -0800 Subject: [PATCH 104/118] CoAlloc: tidy --- .../alloc/src/collections/vec_deque/mod.rs | 5 ++--- library/alloc/src/slice.rs | 20 ++++++++++++------- library/alloc/src/vec/mod.rs | 5 +++-- 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/library/alloc/src/collections/vec_deque/mod.rs b/library/alloc/src/collections/vec_deque/mod.rs index dd71eb0a37999..974e721bbf51d 100644 --- a/library/alloc/src/collections/vec_deque/mod.rs +++ b/library/alloc/src/collections/vec_deque/mod.rs @@ -609,11 +609,10 @@ where { /// Coallocation-aware version of `new`. #[inline] - #[unstable(feature = "co_alloc_global", issue="none")] + #[unstable(feature = "co_alloc_global", issue = "none")] #[must_use] #[allow(unused_braces)] - pub const fn new_co() -> VecDeque - { + pub const fn new_co() -> VecDeque { // FIXME: This should just be `VecDeque::new_in(Global)` once that hits stable. VecDeque { head: 0, len: 0, buf: RawVec::NEW } } diff --git a/library/alloc/src/slice.rs b/library/alloc/src/slice.rs index 4f3600752b2b9..b7ae79edc37e5 100644 --- a/library/alloc/src/slice.rs +++ b/library/alloc/src/slice.rs @@ -1004,15 +1004,19 @@ impl SpecCloneIntoVec for [T] { #[cfg(not(no_global_oom_handling))] #[allow(unused_braces)] pub(crate) trait SpecCloneIntoVecCo -where [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, - { +where + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, +{ fn clone_into_co(&self, target: &mut Vec); } #[cfg(not(no_global_oom_handling))] #[allow(unused_braces)] -impl SpecCloneIntoVecCo for [T] -where [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { +impl + SpecCloneIntoVecCo for [T] +where + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, +{ default fn clone_into_co(&self, target: &mut Vec) { // drop anything in target that will not be overwritten target.truncate(self.len()); @@ -1029,15 +1033,17 @@ where [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { #[cfg(not(no_global_oom_handling))] #[allow(unused_braces)] -impl SpecCloneIntoVecCo for [T] -where [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { +impl + SpecCloneIntoVecCo for [T] +where + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, +{ fn clone_into_co(&self, target: &mut Vec) { target.clear(); target.extend_from_slice(self); } } - #[cfg(not(no_global_oom_handling))] #[stable(feature = "rust1", since = "1.0.0")] impl ToOwned for [T] { diff --git a/library/alloc/src/vec/mod.rs b/library/alloc/src/vec/mod.rs index aa4a3a7394f93..122b699c08d09 100644 --- a/library/alloc/src/vec/mod.rs +++ b/library/alloc/src/vec/mod.rs @@ -1879,6 +1879,8 @@ where where [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { + crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, + { /* Offset of the element we want to check if it is duplicate */ read: usize, @@ -3332,8 +3334,7 @@ where #[stable(feature = "rust1", since = "1.0.0")] #[rustc_const_unstable(feature = "const_default_impls", issue = "87864")] #[allow(unused_braces)] -impl const Default for Vec -{ +impl const Default for Vec { /// Creates an empty `Vec`. /// /// The vector will not allocate until elements are pushed onto it. From fd1152098c6ea966c6fed750ee6d5a659c1b4755 Mon Sep 17 00:00:00 2001 From: Peter Kehl Date: Thu, 2 Feb 2023 12:10:53 -0800 Subject: [PATCH 105/118] CoAlloc: Fixed previous sick result of: tidy --bless --- library/alloc/src/vec/mod.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/library/alloc/src/vec/mod.rs b/library/alloc/src/vec/mod.rs index 122b699c08d09..9d78818fdb5ce 100644 --- a/library/alloc/src/vec/mod.rs +++ b/library/alloc/src/vec/mod.rs @@ -1875,12 +1875,11 @@ where } /* INVARIANT: vec.len() > read >= write > write-1 >= 0 */ + #[allow(unused_braces)] struct FillGapOnDrop<'a, T, A: core::alloc::Allocator, const CO_ALLOC_PREF: CoAllocPref> where [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { - crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, - { /* Offset of the element we want to check if it is duplicate */ read: usize, @@ -3333,7 +3332,6 @@ where #[stable(feature = "rust1", since = "1.0.0")] #[rustc_const_unstable(feature = "const_default_impls", issue = "87864")] -#[allow(unused_braces)] impl const Default for Vec { /// Creates an empty `Vec`. /// From 43d25dd6f1bf87013d88f0c0363fb5d37dfd2af3 Mon Sep 17 00:00:00 2001 From: Peter Kehl Date: Thu, 2 Feb 2023 15:07:28 -0800 Subject: [PATCH 106/118] CoAlloc: slice::into_vec_co - for vec![...]. --- library/alloc/src/slice.rs | 11 ++++++++++- library/alloc/src/vec/mod.rs | 2 +- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/library/alloc/src/slice.rs b/library/alloc/src/slice.rs index b7ae79edc37e5..3fa3b886983ff 100644 --- a/library/alloc/src/slice.rs +++ b/library/alloc/src/slice.rs @@ -627,8 +627,17 @@ impl [T] { #[rustc_allow_incoherent_impl] #[stable(feature = "rust1", since = "1.0.0")] #[inline] + pub fn into_vec(self: Box) -> Vec { + // N.B., see the `hack` module in this file for more details. + hack::into_vec(self) + } + + /// Coallocation-aware version of [into_vec]. + #[rustc_allow_incoherent_impl] + #[unstable(feature = "global_co_alloc", issue = "none")] + #[inline] #[allow(unused_braces)] - pub fn into_vec( + pub fn into_vec_co( self: Box, ) -> Vec where diff --git a/library/alloc/src/vec/mod.rs b/library/alloc/src/vec/mod.rs index 9d78818fdb5ce..c100abcb8f7f9 100644 --- a/library/alloc/src/vec/mod.rs +++ b/library/alloc/src/vec/mod.rs @@ -3510,7 +3510,7 @@ where /// assert_eq!(Vec::from(b), vec![1, 2, 3]); /// ``` fn from(s: Box<[T], A>) -> Self { - s.into_vec() + s.into_vec_co() } } From b76c63dd3719a5ce39232e529a1935f1fa7e1f53 Mon Sep 17 00:00:00 2001 From: Peter Kehl Date: Thu, 2 Feb 2023 16:41:55 -0800 Subject: [PATCH 107/118] CoAlloc: compiler/rustc_arena: specialization; using Allocator::CoAllocMeta in rustc validations. --- compiler/rustc_arena/src/lib.rs | 4 +++- compiler/rustc_ast/src/ast.rs | 25 +++++++++++++------------ compiler/rustc_ast/src/lib.rs | 1 + 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/compiler/rustc_arena/src/lib.rs b/compiler/rustc_arena/src/lib.rs index 4fae5ef845f7d..ecd254cb4da22 100644 --- a/compiler/rustc_arena/src/lib.rs +++ b/compiler/rustc_arena/src/lib.rs @@ -11,10 +11,12 @@ html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/", test(no_crate_inject, attr(deny(warnings))) )] +#![allow(incomplete_features)] #![feature(dropck_eyepatch)] #![feature(new_uninit)] #![feature(maybe_uninit_slice)] -#![feature(min_specialization)] +//#![feature(min_specialization)] +#![feature(specialization)] #![feature(decl_macro)] #![feature(pointer_byte_offsets)] #![feature(rustc_attrs)] diff --git a/compiler/rustc_ast/src/ast.rs b/compiler/rustc_ast/src/ast.rs index aa3bec7297785..aecb0bf24b862 100644 --- a/compiler/rustc_ast/src/ast.rs +++ b/compiler/rustc_ast/src/ast.rs @@ -26,7 +26,6 @@ pub use UnsafeSource::*; use crate::ptr::P; use crate::token::{self, CommentKind, Delimiter}; use crate::tokenstream::{DelimSpan, LazyAttrTokenStream, TokenStream}; -use core::alloc::GlobalCoAllocMeta; use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; use rustc_data_structures::stack::ensure_sufficient_stack; use rustc_data_structures::sync::Lrc; @@ -35,6 +34,8 @@ use rustc_serialize::{Decodable, Decoder, Encodable, Encoder}; use rustc_span::source_map::{respan, Spanned}; use rustc_span::symbol::{kw, sym, Ident, Symbol}; use rustc_span::{Span, DUMMY_SP}; +use std::alloc::Allocator; +use std::alloc::Global; use std::fmt; use std::mem; use thin_vec::{thin_vec, ThinVec}; @@ -3112,26 +3113,26 @@ mod size_asserts { static_assert_size!(AssocItem, 104); static_assert_size!(AssocItemKind, 32); static_assert_size!(Attribute, 32); - static_assert_size!(Block, 48 + mem::size_of::()); - static_assert_size!(Expr, 72 + mem::size_of::()); - static_assert_size!(ExprKind, 40 + mem::size_of::()); - static_assert_size!(Fn, 184 + 2 * mem::size_of::()); + static_assert_size!(Block, 48 + mem::size_of::<::CoAllocMeta>()); + static_assert_size!(Expr, 72 + mem::size_of::<::CoAllocMeta>()); + static_assert_size!(ExprKind, 40 + mem::size_of::<::CoAllocMeta>()); + static_assert_size!(Fn, 184 + 2 * mem::size_of::<::CoAllocMeta>()); static_assert_size!(ForeignItem, 96); static_assert_size!(ForeignItemKind, 24); static_assert_size!(GenericArg, 24); - static_assert_size!(GenericBound, 72 + mem::size_of::()); - static_assert_size!(Generics, 72 + 2 * mem::size_of::()); - static_assert_size!(Impl, 184 + 3 * mem::size_of::()); - static_assert_size!(Item, 184 + 3 * mem::size_of::()); - static_assert_size!(ItemKind, 112 + 3 * mem::size_of::()); + static_assert_size!(GenericBound, 72 + mem::size_of::<::CoAllocMeta>()); + static_assert_size!(Generics, 72 + 2 * mem::size_of::<::CoAllocMeta>()); + static_assert_size!(Impl, 184 + 3 * mem::size_of::<::CoAllocMeta>()); + static_assert_size!(Item, 184 + 3 * mem::size_of::<::CoAllocMeta>()); + static_assert_size!(ItemKind, 112 + 3 * mem::size_of::<::CoAllocMeta>()); static_assert_size!(LitKind, 24); static_assert_size!(Local, 72); static_assert_size!(MetaItemLit, 40); static_assert_size!(Param, 40); - static_assert_size!(Pat, 88 + mem::size_of::()); + static_assert_size!(Pat, 88 + mem::size_of::<::CoAllocMeta>()); static_assert_size!(Path, 24); static_assert_size!(PathSegment, 24); - static_assert_size!(PatKind, 64 + mem::size_of::()); + static_assert_size!(PatKind, 64 + mem::size_of::<::CoAllocMeta>()); static_assert_size!(Stmt, 32); static_assert_size!(StmtKind, 16); static_assert_size!(Ty, 64); diff --git a/compiler/rustc_ast/src/lib.rs b/compiler/rustc_ast/src/lib.rs index 225ad76802188..3baaf2c9b63b4 100644 --- a/compiler/rustc_ast/src/lib.rs +++ b/compiler/rustc_ast/src/lib.rs @@ -8,6 +8,7 @@ html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/", test(attr(deny(warnings))) )] +#![feature(allocator_api)] #![feature(associated_type_bounds)] #![feature(box_patterns)] #![feature(const_default_impls)] From 896f3dccb0bcd80a6c1ee4930f5360a0c2dfe19d Mon Sep 17 00:00:00 2001 From: Peter Kehl Date: Sat, 4 Feb 2023 10:22:06 -0800 Subject: [PATCH 108/118] CoAlloc: Unspecialized and specialized Box<[T]>::from(Vec) and Vec::from(Box<[T>]), so it works with legacy code. --- library/alloc/src/vec/mod.rs | 41 ++++++++++++++++++++++++++++++------ 1 file changed, 35 insertions(+), 6 deletions(-) diff --git a/library/alloc/src/vec/mod.rs b/library/alloc/src/vec/mod.rs index c100abcb8f7f9..42d6e142a7a55 100644 --- a/library/alloc/src/vec/mod.rs +++ b/library/alloc/src/vec/mod.rs @@ -3491,14 +3491,28 @@ where } } -// note: test pulls in std, which causes errors here +// @FIXME unsure about test #[cfg(not(test))] -#[stable(feature = "vec_from_box", since = "1.18.0")] +#[allow(ineffective_unstable_trait_impl)] //@FIXME What/why is #[unstable(...)] ignored here? +#[unstable(feature = "global_co_alloc", issue="none")] #[allow(unused_braces)] impl From> for Vec where [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, +{ + default fn from(s: Box<[T], A>) -> Self { + s.into_vec_co() + } +} + +#[cfg(not(test))] +#[stable(feature = "vec_from_box", since = "1.18.0")] +#[allow(unused_braces)] +impl From> + for Vec +where + [(); { crate::meta_num_slots_default!(A) }]:, { /// Convert a boxed slice into a vector by transferring ownership of /// the existing heap allocation. @@ -3510,19 +3524,34 @@ where /// assert_eq!(Vec::from(b), vec![1, 2, 3]); /// ``` fn from(s: Box<[T], A>) -> Self { - s.into_vec_co() + s.into_vec() } } -// note: test pulls in std, which causes errors here #[cfg(not(no_global_oom_handling))] +// @FIXME Can this apply to test? #[cfg(not(test))] -#[stable(feature = "box_from_vec", since = "1.20.0")] +#[allow(ineffective_unstable_trait_impl)] //@FIXME What/why is #[unstable(...)] ignored here? +#[unstable(feature = "global_co_alloc", issue="none")] #[allow(unused_braces)] impl From> for Box<[T], A> where [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, +{ + default fn from(v: Vec) -> Self { + v.into_boxed_slice() + } +} +// note: test pulls in std, which causes errors here +#[cfg(not(no_global_oom_handling))] +#[cfg(not(test))] +#[stable(feature = "box_from_vec", since = "1.20.0")] +#[allow(unused_braces)] +impl From> + for Box<[T], A> +where + [(); { crate::meta_num_slots_default!(A) }]:, { /// Convert a vector into a boxed slice. /// @@ -3542,7 +3571,7 @@ where /// /// assert_eq!(Box::from(vec), vec![1, 2, 3].into_boxed_slice()); /// ``` - fn from(v: Vec) -> Self { + fn from(v: Vec) -> Self { v.into_boxed_slice() } } From 388ba856cd701f2a47c50fa9c592eab46d117535 Mon Sep 17 00:00:00 2001 From: Peter Kehl Date: Tue, 14 Feb 2023 15:23:50 -0800 Subject: [PATCH 109/118] CoAlloc: Fixed specializations --- library/alloc/src/co_alloc.rs | 8 ++++---- .../collections/vec_deque/spec_from_iter.rs | 3 --- library/alloc/src/slice.rs | 20 +++++++++++++++---- library/core/src/alloc/mod.rs | 5 +++-- 4 files changed, 23 insertions(+), 13 deletions(-) diff --git a/library/alloc/src/co_alloc.rs b/library/alloc/src/co_alloc.rs index d71fb4b2640b5..23b0598cf4ee1 100644 --- a/library/alloc/src/co_alloc.rs +++ b/library/alloc/src/co_alloc.rs @@ -21,11 +21,11 @@ /// - DO NOT hard code any values; and /// - DO NOT mix this/cast this with/to `u8`, `u16`, `usize` (nor any other integer). #[unstable(feature = "global_co_alloc_meta", issue = "none")] -pub type CoAllocPref = u8; +pub type CoAllocPref = usize; //u8; -/// `CoAllocMetaNumSlotsPref` values indicate a type (but not an allocator) prefers to coallocate by -/// carrying metadata, or not. (In either user space, or `std` space). Used as an argument to macro -/// call of `co_alloc_pref`, which generates a `CoAllocPref` value. +/// `CoAllocMetaNumSlotsPref` values indicate that a type (but not necessarily an allocator) prefers +/// to coallocate by carrying metadata, or not. (In either user space, or `std` or `alloc` space). +/// Used as an argument to macro call of `co_alloc_pref`, which generates a `CoAllocPref` value. /// /// Currently this indicates only the (preferred) number of `CoAllocMetaBase` slots being used /// (either 1 = coallocation, or 0 = no coallocation). However, in the future this type may have diff --git a/library/alloc/src/collections/vec_deque/spec_from_iter.rs b/library/alloc/src/collections/vec_deque/spec_from_iter.rs index 5d21203b5d7b3..1ef5150dda3b4 100644 --- a/library/alloc/src/collections/vec_deque/spec_from_iter.rs +++ b/library/alloc/src/collections/vec_deque/spec_from_iter.rs @@ -12,7 +12,6 @@ pub(super) trait SpecFromIterCo { fn spec_from_iter_co(iter: I) -> Self; } -#[allow(unused_braces)] impl SpecFromIter for VecDeque where I: Iterator, @@ -26,7 +25,6 @@ where } } -#[allow(unused_braces)] impl SpecFromIter> for VecDeque { #[inline] fn spec_from_iter(iterator: crate::vec::IntoIter) -> Self { @@ -34,7 +32,6 @@ impl SpecFromIter> for VecDeque { } } -#[allow(unused_braces)] impl SpecFromIter> for VecDeque { #[inline] fn spec_from_iter(iterator: IntoIter) -> Self { diff --git a/library/alloc/src/slice.rs b/library/alloc/src/slice.rs index 3fa3b886983ff..ffb250c56d008 100644 --- a/library/alloc/src/slice.rs +++ b/library/alloc/src/slice.rs @@ -627,7 +627,10 @@ impl [T] { #[rustc_allow_incoherent_impl] #[stable(feature = "rust1", since = "1.0.0")] #[inline] - pub fn into_vec(self: Box) -> Vec { + #[allow(unused_braces)] + pub fn into_vec(self: Box) -> Vec + where [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]: + { // N.B., see the `hack` module in this file for more details. hack::into_vec(self) } @@ -981,12 +984,18 @@ where // public in the crate and has the Allocator parameter so that // vec::clone_from use it too. #[cfg(not(no_global_oom_handling))] -pub(crate) trait SpecCloneIntoVec { +#[allow(unused_braces)] +pub(crate) trait SpecCloneIntoVec +where [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]: +{ fn clone_into(&self, target: &mut Vec); } #[cfg(not(no_global_oom_handling))] -impl SpecCloneIntoVec for [T] { +#[allow(unused_braces)] +impl SpecCloneIntoVec for [T] +where [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]: +{ default fn clone_into(&self, target: &mut Vec) { // drop anything in target that will not be overwritten target.truncate(self.len()); @@ -1002,7 +1011,10 @@ impl SpecCloneIntoVec for [T] { } #[cfg(not(no_global_oom_handling))] -impl SpecCloneIntoVec for [T] { +#[allow(unused_braces)] +impl SpecCloneIntoVec for [T] +where [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]: +{ fn clone_into(&self, target: &mut Vec) { target.clear(); target.extend_from_slice(self); diff --git a/library/core/src/alloc/mod.rs b/library/core/src/alloc/mod.rs index 6ab7e4a87c16f..609cbedda3410 100644 --- a/library/core/src/alloc/mod.rs +++ b/library/core/src/alloc/mod.rs @@ -106,9 +106,10 @@ impl const CoAllocMetaBase for CoAllocMetaPlain { /// `#![feature(adt_const_params)]` are stable) to a dedicated struct/enum. Hence: /// - DO NOT mix this/cast this with/to `u8`, `u16`, (nor any other integer); and /// - DO NOT hard code any values, but use `CO_ALLOCATOR_SUPPORTS_META_YES` and `CO_ALLOCATOR_SUPPORTS_META_NO`. -/// +// @FIXME Once ICE is fixed: Change to `u32` (or any other unused unsinged integer type, and other +// than `usize`, so we can't mix it up with `usize`). #[unstable(feature = "global_co_alloc_meta", issue = "none")] -pub type CoAllocatorMetaNumSlots = u32; +pub type CoAllocatorMetaNumSlots = usize; /// Indicating that an Allocator supports coallocation (if a type of the allocated instances supports it, too). #[unstable(feature = "global_co_alloc_meta", issue = "none")] From b9f350cc70097fe048c1a8141a92a2412d9ab300 Mon Sep 17 00:00:00 2001 From: Peter Kehl Date: Tue, 14 Feb 2023 18:03:38 -0800 Subject: [PATCH 110/118] CoAlloc: Fixes --- library/alloc/src/slice.rs | 8 ++++---- library/std/src/io/impls.rs | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/library/alloc/src/slice.rs b/library/alloc/src/slice.rs index ffb250c56d008..145f4ec998232 100644 --- a/library/alloc/src/slice.rs +++ b/library/alloc/src/slice.rs @@ -629,7 +629,7 @@ impl [T] { #[inline] #[allow(unused_braces)] pub fn into_vec(self: Box) -> Vec - where [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]: + where [(); { crate::meta_num_slots_default!(A) }]: { // N.B., see the `hack` module in this file for more details. hack::into_vec(self) @@ -986,7 +986,7 @@ where #[cfg(not(no_global_oom_handling))] #[allow(unused_braces)] pub(crate) trait SpecCloneIntoVec -where [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]: +where [(); { crate::meta_num_slots_default!(A) }]: { fn clone_into(&self, target: &mut Vec); } @@ -994,7 +994,7 @@ where [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]: #[cfg(not(no_global_oom_handling))] #[allow(unused_braces)] impl SpecCloneIntoVec for [T] -where [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]: +where [(); { crate::meta_num_slots_default!(A) }]: { default fn clone_into(&self, target: &mut Vec) { // drop anything in target that will not be overwritten @@ -1013,7 +1013,7 @@ where [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]: #[cfg(not(no_global_oom_handling))] #[allow(unused_braces)] impl SpecCloneIntoVec for [T] -where [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]: +where [(); { crate::meta_num_slots_default!(A) }]: { fn clone_into(&self, target: &mut Vec) { target.clear(); diff --git a/library/std/src/io/impls.rs b/library/std/src/io/impls.rs index 561ec13038ee5..541f882d84ccf 100644 --- a/library/std/src/io/impls.rs +++ b/library/std/src/io/impls.rs @@ -420,7 +420,7 @@ where /// Read is implemented for `VecDeque` by consuming bytes from the front of the `VecDeque`. #[stable(feature = "vecdeque_read_write", since = "1.63.0")] #[allow(unused_braces)] -impl Read for VecDeque +impl Read for VecDeque where [(); { meta_num_slots!(A, CO_ALLOC_PREF) }]:, { @@ -448,7 +448,7 @@ where /// Write is implemented for `VecDeque` by appending to the `VecDeque`, growing it as needed. #[stable(feature = "vecdeque_read_write", since = "1.63.0")] #[allow(unused_braces)] -impl Write for VecDeque +impl Write for VecDeque where [(); { meta_num_slots!(A, CO_ALLOC_PREF) }]:, { From 08e675af8c54d2e04647daa2c63a584c007bfb40 Mon Sep 17 00:00:00 2001 From: Peter Kehl Date: Tue, 14 Feb 2023 18:05:57 -0800 Subject: [PATCH 111/118] Limited working around rust-lang/rust issue #106473. --- library/alloc/src/macros.rs | 77 ++++++++++++++++++++++++++++--------- 1 file changed, 59 insertions(+), 18 deletions(-) diff --git a/library/alloc/src/macros.rs b/library/alloc/src/macros.rs index 247e7efb00688..9acc68c1d691d 100644 --- a/library/alloc/src/macros.rs +++ b/library/alloc/src/macros.rs @@ -125,14 +125,32 @@ macro_rules! __rust_force_expr { }; } -// ----- CoAlloc constant-like macros: +// ----- CoAlloc ICE workaround macro: +/// This "validates" type of a given `const` expression, and it casts it. That helps to prevent mix ups with macros/integer constant values. +#[doc(hidden)] +#[macro_export] +#[unstable(feature = "global_co_alloc_meta", issue = "none")]macro_rules! check_type_and_cast { + // Use the following for compile-time/build check only. And use it + // with a hard-coded `0` version of `meta_num_slots` - otherwise you get an ICE. + // + /*($e:expr, $t_check:ty, $t_cast:ty) => { + ($e + 0 as $t_check) as $t_cast + }*/ + // Use the following to build for testing/using, while rustc causes an ICE with the above and + // with a full version of `meta_num_slots`. + ($e:expr, $t_check:ty, $t_cast:ty) => { + $e + } +} +// ----- CoAlloc constant-like macros: /// Coallocation option/parameter about using metadata that does prefer to use meta data. This is of type [::alloc::co_alloc::CoAllocMetaNumSlotsPref] (but not a whole []::alloc::co_alloc::CoAllocPref]). +#[doc(hidden)] #[unstable(feature = "global_co_alloc_meta", issue = "none")] #[macro_export] macro_rules! CO_ALLOC_PREF_NUM_META_SLOTS_ONE { () => { - (1 as $crate::co_alloc::CoAllocMetaNumSlotsPref) + $crate::check_type_and_cast!(1, i32, $crate::co_alloc::CoAllocMetaNumSlotsPref) }; } @@ -141,7 +159,7 @@ macro_rules! CO_ALLOC_PREF_NUM_META_SLOTS_ONE { #[macro_export] macro_rules! CO_ALLOC_PREF_NUM_META_SLOTS_ZERO { () => { - (0 as $crate::co_alloc::CoAllocMetaNumSlotsPref) + $crate::check_type_and_cast!(0, i32, $crate::co_alloc::CoAllocMetaNumSlotsPref) }; } @@ -150,7 +168,7 @@ macro_rules! CO_ALLOC_PREF_NUM_META_SLOTS_ZERO { #[macro_export] macro_rules! CO_ALLOC_PREF_NUM_META_SLOTS_DEFAULT { () => { - (0 as $crate::co_alloc::CoAllocMetaNumSlotsPref) + $crate::check_type_and_cast!(0, i32, $crate::co_alloc::CoAllocMetaNumSlotsPref) }; } @@ -167,6 +185,7 @@ macro_rules! CO_ALLOC_PREF_NUM_META_SLOTS_DEFAULT { #[macro_export] macro_rules! CO_ALLOC_PREF_META_YES { () => { + //1usize $crate::co_alloc_pref!($crate::CO_ALLOC_PREF_NUM_META_SLOTS_ONE!()) }; } @@ -184,6 +203,7 @@ macro_rules! CO_ALLOC_PREF_META_YES { #[macro_export] macro_rules! CO_ALLOC_PREF_META_NO { () => { + //0usize $crate::co_alloc_pref!($crate::CO_ALLOC_PREF_NUM_META_SLOTS_ZERO!()) }; } @@ -202,6 +222,7 @@ macro_rules! CO_ALLOC_PREF_META_NO { #[macro_export] macro_rules! CO_ALLOC_PREF_META_DEFAULT { () => { + //0usize $crate::co_alloc_pref!($crate::CO_ALLOC_PREF_NUM_META_SLOTS_DEFAULT!()) }; } @@ -211,6 +232,7 @@ macro_rules! CO_ALLOC_PREF_META_DEFAULT { #[macro_export] macro_rules! CO_ALLOC_PREF_DEFAULT { () => { + //0usize $crate::CO_ALLOC_PREF_META_DEFAULT!() }; } @@ -221,6 +243,7 @@ macro_rules! CO_ALLOC_PREF_DEFAULT { #[macro_export] macro_rules! SHORT_TERM_VEC_CO_ALLOC_PREF { () => { + //0usize $crate::CO_ALLOC_PREF_META_NO!() }; } @@ -242,8 +265,8 @@ macro_rules! co_alloc_pref { // report the incorrect type of $meta_pref (if $meta_pref were some other integer, casting would // compile, and we would not be notified). ($meta_pref:expr) => { - (($meta_pref + (0 as $crate::co_alloc::CoAllocMetaNumSlotsPref)) - as $crate::co_alloc::CoAllocPref) + $crate::check_type_and_cast!($meta_pref,$crate::co_alloc::CoAllocMetaNumSlotsPref, + $crate::co_alloc::CoAllocPref) }; } @@ -267,18 +290,29 @@ macro_rules! co_alloc_pref { #[unstable(feature = "global_co_alloc", issue = "none")] #[macro_export] macro_rules! meta_num_slots { - // Generating, for example, (0 as usize), here, triggers an ICE. - - // This "validates" types of both params - to prevent mix ups. - // @FIXME remove this comment line: Removing/commenting out the part: <$alloc as ::core::alloc::Allocator>::CO_ALLOC_META_NUM_SLOTS + - // does NOT fix the ICE (unless there are multiple ICE's). + // @FIXME Use this only + // - once the ICE gets fixed, or + // - (until the ICE is fixed) with a related change in `check_type_and_cast` that makes it pass + // the given expression (parameter) unchecked & uncast. + /*($alloc:ty, $co_alloc_pref:expr) => { + $crate::check_type_and_cast!(<$alloc as ::core::alloc::Allocator>::CO_ALLOC_META_NUM_SLOTS,::core::alloc::CoAllocatorMetaNumSlots, + usize) * + $crate::check_type_and_cast!($co_alloc_pref, $crate::co_alloc::CoAllocPref, usize) + };*/ + // Use for testing & production, until ICE gets fixed. (Regardless of $co_alloc_pref.) + // + // Why still ICE?! ($alloc:ty, $co_alloc_pref:expr) => { - /*( - ((<$alloc as ::core::alloc::Allocator>::CO_ALLOC_META_NUM_SLOTS + (0 as ::core::alloc::CoAllocatorMetaNumSlots))0 - as usize) - * ($co_alloc_pref + (0 as $crate::co_alloc::CoAllocPref)) - as usize)*/0usize - }; + // The following fails here - even if not used from meta_num_slots_default nor from meta_num_slots_global! + //<$alloc as ::core::alloc::Allocator>::CO_ALLOC_META_NUM_SLOTS + //<$crate::alloc::Global as ::core::alloc::Allocator>::CO_ALLOC_META_NUM_SLOTS + //1usize + $co_alloc_pref + } + // Use for testing & production as enforcing no meta. + /*($alloc:ty, $co_alloc_pref:expr) => { + 0usize // compiles + }*/ } // -\---> replace with something like: /* @@ -304,7 +338,10 @@ macro_rules! meta_num_slots_default { // Can't generate if ... {1} else {0} // because it's "overly complex generic constant". ($alloc:ty) => { + // EITHER of the following are OK here $crate::meta_num_slots!($alloc, $crate::CO_ALLOC_PREF_DEFAULT!()) + //<$alloc as ::core::alloc::Allocator>::CO_ALLOC_META_NUM_SLOTS + //<$crate::alloc::Global as ::core::alloc::Allocator>::CO_ALLOC_META_NUM_SLOTS }; } @@ -320,10 +357,13 @@ macro_rules! meta_num_slots_default { #[macro_export] macro_rules! meta_num_slots_global { ($co_alloc_pref:expr) => { + // EITHER of the following are OK here $crate::meta_num_slots!($crate::alloc::Global, $co_alloc_pref) + // The following is OK here: + //<$crate::alloc::Global as ::core::alloc::Allocator>::CO_ALLOC_META_NUM_SLOTS }; } - +/* /// Like `meta_num_slots`, but for `Global allocator and default coallocation preference /// (`CO_ALLOC_PREF_DEFAULT`). /// @@ -336,3 +376,4 @@ macro_rules! meta_num_slots_default_global { $crate::meta_num_slots!($crate::alloc::Global, $crate::CO_ALLOC_PREF_DEFAULT!()) }; } +*/ \ No newline at end of file From 319b888f99de9609c66cc6357f54ba5ba2c49b7f Mon Sep 17 00:00:00 2001 From: Peter Kehl Date: Tue, 14 Feb 2023 18:28:39 -0800 Subject: [PATCH 112/118] CoAlloc: tidy --- library/alloc/src/macros.rs | 28 +++++++++------------------- library/alloc/src/slice.rs | 12 ++++++++---- library/alloc/src/vec/mod.rs | 12 ++++++------ 3 files changed, 23 insertions(+), 29 deletions(-) diff --git a/library/alloc/src/macros.rs b/library/alloc/src/macros.rs index 9acc68c1d691d..29ec2799d47a7 100644 --- a/library/alloc/src/macros.rs +++ b/library/alloc/src/macros.rs @@ -129,10 +129,11 @@ macro_rules! __rust_force_expr { /// This "validates" type of a given `const` expression, and it casts it. That helps to prevent mix ups with macros/integer constant values. #[doc(hidden)] #[macro_export] -#[unstable(feature = "global_co_alloc_meta", issue = "none")]macro_rules! check_type_and_cast { +#[unstable(feature = "global_co_alloc_meta", issue = "none")] +macro_rules! check_type_and_cast { // Use the following for compile-time/build check only. And use it // with a hard-coded `0` version of `meta_num_slots` - otherwise you get an ICE. - // + // /*($e:expr, $t_check:ty, $t_cast:ty) => { ($e + 0 as $t_check) as $t_cast }*/ @@ -140,7 +141,7 @@ macro_rules! __rust_force_expr { // with a full version of `meta_num_slots`. ($e:expr, $t_check:ty, $t_cast:ty) => { $e - } + }; } // ----- CoAlloc constant-like macros: @@ -265,8 +266,11 @@ macro_rules! co_alloc_pref { // report the incorrect type of $meta_pref (if $meta_pref were some other integer, casting would // compile, and we would not be notified). ($meta_pref:expr) => { - $crate::check_type_and_cast!($meta_pref,$crate::co_alloc::CoAllocMetaNumSlotsPref, - $crate::co_alloc::CoAllocPref) + $crate::check_type_and_cast!( + $meta_pref, + $crate::co_alloc::CoAllocMetaNumSlotsPref, + $crate::co_alloc::CoAllocPref + ) }; } @@ -363,17 +367,3 @@ macro_rules! meta_num_slots_global { //<$crate::alloc::Global as ::core::alloc::Allocator>::CO_ALLOC_META_NUM_SLOTS }; } -/* -/// Like `meta_num_slots`, but for `Global allocator and default coallocation preference -/// (`CO_ALLOC_PREF_DEFAULT`). -/// -// @FIXME once generic_const_exprs is stable, replace this with a `const` function. Then consider -// moving the function to a submodule, for example alloc::co_alloc. See above. -#[unstable(feature = "global_co_alloc", issue = "none")] -#[macro_export] -macro_rules! meta_num_slots_default_global { - () => { - $crate::meta_num_slots!($crate::alloc::Global, $crate::CO_ALLOC_PREF_DEFAULT!()) - }; -} -*/ \ No newline at end of file diff --git a/library/alloc/src/slice.rs b/library/alloc/src/slice.rs index 145f4ec998232..ba353f9d0a1be 100644 --- a/library/alloc/src/slice.rs +++ b/library/alloc/src/slice.rs @@ -629,7 +629,8 @@ impl [T] { #[inline] #[allow(unused_braces)] pub fn into_vec(self: Box) -> Vec - where [(); { crate::meta_num_slots_default!(A) }]: + where + [(); { crate::meta_num_slots_default!(A) }]:, { // N.B., see the `hack` module in this file for more details. hack::into_vec(self) @@ -986,7 +987,8 @@ where #[cfg(not(no_global_oom_handling))] #[allow(unused_braces)] pub(crate) trait SpecCloneIntoVec -where [(); { crate::meta_num_slots_default!(A) }]: +where + [(); { crate::meta_num_slots_default!(A) }]:, { fn clone_into(&self, target: &mut Vec); } @@ -994,7 +996,8 @@ where [(); { crate::meta_num_slots_default!(A) }]: #[cfg(not(no_global_oom_handling))] #[allow(unused_braces)] impl SpecCloneIntoVec for [T] -where [(); { crate::meta_num_slots_default!(A) }]: +where + [(); { crate::meta_num_slots_default!(A) }]:, { default fn clone_into(&self, target: &mut Vec) { // drop anything in target that will not be overwritten @@ -1013,7 +1016,8 @@ where [(); { crate::meta_num_slots_default!(A) }]: #[cfg(not(no_global_oom_handling))] #[allow(unused_braces)] impl SpecCloneIntoVec for [T] -where [(); { crate::meta_num_slots_default!(A) }]: +where + [(); { crate::meta_num_slots_default!(A) }]:, { fn clone_into(&self, target: &mut Vec) { target.clear(); diff --git a/library/alloc/src/vec/mod.rs b/library/alloc/src/vec/mod.rs index 42d6e142a7a55..b853f50061977 100644 --- a/library/alloc/src/vec/mod.rs +++ b/library/alloc/src/vec/mod.rs @@ -1880,6 +1880,8 @@ where where [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { + crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, + { /* Offset of the element we want to check if it is duplicate */ read: usize, @@ -3494,7 +3496,7 @@ where // @FIXME unsure about test #[cfg(not(test))] #[allow(ineffective_unstable_trait_impl)] //@FIXME What/why is #[unstable(...)] ignored here? -#[unstable(feature = "global_co_alloc", issue="none")] +#[unstable(feature = "global_co_alloc", issue = "none")] #[allow(unused_braces)] impl From> for Vec @@ -3509,8 +3511,7 @@ where #[cfg(not(test))] #[stable(feature = "vec_from_box", since = "1.18.0")] #[allow(unused_braces)] -impl From> - for Vec +impl From> for Vec where [(); { crate::meta_num_slots_default!(A) }]:, { @@ -3532,7 +3533,7 @@ where // @FIXME Can this apply to test? #[cfg(not(test))] #[allow(ineffective_unstable_trait_impl)] //@FIXME What/why is #[unstable(...)] ignored here? -#[unstable(feature = "global_co_alloc", issue="none")] +#[unstable(feature = "global_co_alloc", issue = "none")] #[allow(unused_braces)] impl From> for Box<[T], A> @@ -3548,8 +3549,7 @@ where #[cfg(not(test))] #[stable(feature = "box_from_vec", since = "1.20.0")] #[allow(unused_braces)] -impl From> - for Box<[T], A> +impl From> for Box<[T], A> where [(); { crate::meta_num_slots_default!(A) }]:, { From 8caa109e868e4475f1e2e603eda774b13129e876 Mon Sep 17 00:00:00 2001 From: Peter Kehl Date: Wed, 15 Feb 2023 09:54:19 -0800 Subject: [PATCH 113/118] CoAlloc: bless --- compiler/rustc_parse/src/parser/mod.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_parse/src/parser/mod.rs b/compiler/rustc_parse/src/parser/mod.rs index 7fb4e60f8a14f..373f392899bf5 100644 --- a/compiler/rustc_parse/src/parser/mod.rs +++ b/compiler/rustc_parse/src/parser/mod.rs @@ -168,7 +168,10 @@ pub struct Parser<'a> { // This type is used a lot, e.g. it's cloned when matching many declarative macro rules with nonterminals. Make sure // it doesn't unintentionally get bigger. #[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))] -rustc_data_structures::static_assert_size!(Parser<'_>, 312 + 4 * mem::size_of::()); +rustc_data_structures::static_assert_size!( + Parser<'_>, + 312 + 4 * mem::size_of::() +); /// Stores span information about a closure. #[derive(Clone)] From 9fc9cd938059f673135c21931b6d475cd9f3ec47 Mon Sep 17 00:00:00 2001 From: Peter Kehl Date: Wed, 15 Feb 2023 10:56:41 -0800 Subject: [PATCH 114/118] CoAlloc: Working around a fmt bug --- library/alloc/src/vec/mod.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/library/alloc/src/vec/mod.rs b/library/alloc/src/vec/mod.rs index b853f50061977..60f91264ef7be 100644 --- a/library/alloc/src/vec/mod.rs +++ b/library/alloc/src/vec/mod.rs @@ -1880,8 +1880,6 @@ where where [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { - crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, - { /* Offset of the element we want to check if it is duplicate */ read: usize, From 18d936166e8cca70cb448ffd36614e49a30e3956 Mon Sep 17 00:00:00 2001 From: Peter Kehl Date: Fri, 17 Feb 2023 12:54:05 -0800 Subject: [PATCH 115/118] CoAlloc: Removed/split CO_ALLOC_PREF. Fixed tests --- library/alloc/src/collections/binary_heap/tests.rs | 6 +++++- library/alloc/src/collections/vec_deque/mod.rs | 14 ++++++++++++-- library/alloc/src/raw_vec.rs | 11 +++++++++-- library/alloc/src/slice.rs | 14 ++++++++++++-- library/alloc/src/vec/into_iter.rs | 2 +- library/alloc/src/vec/mod.rs | 2 +- library/alloc/tests/autotraits.rs | 9 ++++++++- library/alloc/tests/lib.rs | 1 + 8 files changed, 49 insertions(+), 10 deletions(-) diff --git a/library/alloc/src/collections/binary_heap/tests.rs b/library/alloc/src/collections/binary_heap/tests.rs index ffbb6c80ac018..35a844c738ca3 100644 --- a/library/alloc/src/collections/binary_heap/tests.rs +++ b/library/alloc/src/collections/binary_heap/tests.rs @@ -1,5 +1,6 @@ use super::*; use crate::boxed::Box; +use crate::{CO_ALLOC_PREF_META_YES, CO_ALLOC_PREF_META_NO}; use crate::testing::crash_test::{CrashTestDummy, Panic}; use core::mem; use std::iter::TrustedLen; @@ -448,7 +449,10 @@ fn test_extend_specialization() { #[allow(dead_code)] fn assert_covariance() { - fn drain<'new>(d: Drain<'static, &'static str>) -> Drain<'new, &'new str> { + fn drain<'new>(d: Drain<'static, &'static str, {CO_ALLOC_PREF_META_NO!()}>) -> Drain<'new, &'new str, {CO_ALLOC_PREF_META_NO!()}> { + d + } + fn drain_co<'new>(d: Drain<'static, &'static str, {CO_ALLOC_PREF_META_YES!()}>) -> Drain<'new, &'new str, {CO_ALLOC_PREF_META_YES!()}> { d } } diff --git a/library/alloc/src/collections/vec_deque/mod.rs b/library/alloc/src/collections/vec_deque/mod.rs index 974e721bbf51d..d6991b31368b1 100644 --- a/library/alloc/src/collections/vec_deque/mod.rs +++ b/library/alloc/src/collections/vec_deque/mod.rs @@ -2844,11 +2844,21 @@ where #[stable(feature = "rust1", since = "1.0.0")] #[allow(unused_braces)] -impl FromIterator for VecDeque +impl FromIterator for VecDeque +{ + fn from_iter>(iter: I) -> VecDeque { + SpecFromIterCo::spec_from_iter_co(iter.into_iter()) + } +} + +#[unstable(feature = "global_co_alloc", issue = "none")] +#[allow(unused_braces)] +impl VecDeque where [(); { crate::meta_num_slots_global!(CO_ALLOC_PREF) }]:, { - fn from_iter>(iter: I) -> VecDeque { + /// Like [from_iter], but coallocation-aware. + pub fn from_iter_co>(iter: I) -> VecDeque { SpecFromIterCo::spec_from_iter_co(iter.into_iter()) } } diff --git a/library/alloc/src/raw_vec.rs b/library/alloc/src/raw_vec.rs index 1f4e74d2f70e9..4b5345f0912f3 100644 --- a/library/alloc/src/raw_vec.rs +++ b/library/alloc/src/raw_vec.rs @@ -281,6 +281,11 @@ where &self.alloc } + #[inline] + const fn assert_alignment() { + assert!(mem::size_of::() % mem::align_of::() == 0); + } + fn current_memory(&self) -> Option<(NonNull, Layout)> { if T::IS_ZST || self.cap == 0 { None @@ -289,7 +294,8 @@ where // and could hypothetically handle differences between stride and size, but this memory // has already been allocated so we know it can't overflow and currently rust does not // support such types. So we can do better by skipping some checks and avoid an unwrap. - let _: () = const { assert!(mem::size_of::() % mem::align_of::() == 0) }; + let _: () = Self::assert_alignment(); + //let _: () = const { assert!(mem::size_of::() % mem::align_of::() == 0) }; unsafe { let align = mem::align_of::(); let size = mem::size_of::().unchecked_mul(self.cap); @@ -483,7 +489,8 @@ where let (ptr, layout) = if let Some(mem) = self.current_memory() { mem } else { return Ok(()) }; // See current_memory() why this assert is here - let _: () = const { assert!(mem::size_of::() % mem::align_of::() == 0) }; + let _: () = Self::assert_alignment(); + //let _: () = const { assert!(mem::size_of::() % mem::align_of::() == 0) }; let ptr = unsafe { // `Layout::array` cannot overflow here because it would have // overflowed earlier when capacity was larger. diff --git a/library/alloc/src/slice.rs b/library/alloc/src/slice.rs index ba353f9d0a1be..e6a2d869468b4 100644 --- a/library/alloc/src/slice.rs +++ b/library/alloc/src/slice.rs @@ -103,7 +103,17 @@ pub(crate) mod hack { // `vec!` macro mostly and causes perf regression. See #71204 for // discussion and perf results. #[allow(unused_braces)] - pub fn into_vec( + pub fn into_vec( + b: Box<[T], A>, + ) -> Vec + where + [(); { crate::meta_num_slots_default!(A) }]:, + { + into_vec_co::(b) + } + + #[allow(unused_braces)] + pub fn into_vec_co( b: Box<[T], A>, ) -> Vec where @@ -648,7 +658,7 @@ impl [T] { [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, { // N.B., see the `hack` module in this file for more details. - hack::into_vec(self) + hack::into_vec_co(self) } /// Creates a vector by copying a slice `n` times. diff --git a/library/alloc/src/vec/into_iter.rs b/library/alloc/src/vec/into_iter.rs index 011794ea2e99d..9bba9b992e601 100644 --- a/library/alloc/src/vec/into_iter.rs +++ b/library/alloc/src/vec/into_iter.rs @@ -465,7 +465,7 @@ where } #[cfg(test)] fn clone(&self) -> Self { - crate::slice::to_vec(self.as_slice(), self.alloc.deref().clone()).into_iter() + crate::slice::to_vec_co(self.as_slice(), self.alloc.deref().clone()).into_iter() } } diff --git a/library/alloc/src/vec/mod.rs b/library/alloc/src/vec/mod.rs index 60f91264ef7be..a5a31bfd70913 100644 --- a/library/alloc/src/vec/mod.rs +++ b/library/alloc/src/vec/mod.rs @@ -2864,7 +2864,7 @@ where #[cfg(test)] fn clone(&self) -> Self { let alloc = self.allocator().clone(); - crate::slice::to_vec(&**self, alloc) + crate::slice::to_vec_co(&**self, alloc) } fn clone_from(&mut self, other: &Self) { diff --git a/library/alloc/tests/autotraits.rs b/library/alloc/tests/autotraits.rs index 879e32b3fa309..0a14b165a74f3 100644 --- a/library/alloc/tests/autotraits.rs +++ b/library/alloc/tests/autotraits.rs @@ -1,3 +1,5 @@ +use alloc::{CO_ALLOC_PREF_META_YES, CO_ALLOC_PREF_META_NO}; + fn require_sync(_: T) {} fn require_send_sync(_: T) {} @@ -192,7 +194,12 @@ fn test_binary_heap() { }); require_send_sync(async { - let _v = None::>; + let _v = None::>; + async {}.await; + }); + + require_send_sync(async { + let _v = None::>; async {}.await; }); diff --git a/library/alloc/tests/lib.rs b/library/alloc/tests/lib.rs index 2a93a242d5174..1a435018e0b17 100644 --- a/library/alloc/tests/lib.rs +++ b/library/alloc/tests/lib.rs @@ -2,6 +2,7 @@ #![feature(alloc_layout_extra)] #![feature(assert_matches)] #![feature(btree_drain_filter)] +#![feature(global_co_alloc_meta)] #![feature(cow_is_borrowed)] #![feature(const_box)] #![feature(const_convert)] From 5bbf264fafd8bb3b88ed2c385c89bea456c966ba Mon Sep 17 00:00:00 2001 From: Peter Kehl Date: Fri, 17 Feb 2023 12:54:30 -0800 Subject: [PATCH 116/118] CoAlloc: FIXME: raw_vec::assert_alignment() --- library/alloc/src/raw_vec.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/library/alloc/src/raw_vec.rs b/library/alloc/src/raw_vec.rs index 4b5345f0912f3..39827052b75c1 100644 --- a/library/alloc/src/raw_vec.rs +++ b/library/alloc/src/raw_vec.rs @@ -281,6 +281,7 @@ where &self.alloc } + // @FIXME #[inline] const fn assert_alignment() { assert!(mem::size_of::() % mem::align_of::() == 0); From a84b78ce995e76f5cef1fa1eb9782d6d23299b8c Mon Sep 17 00:00:00 2001 From: Peter Kehl Date: Sat, 18 Feb 2023 15:06:52 -0800 Subject: [PATCH 117/118] CoAlloc: tidy --- library/alloc/src/collections/binary_heap/tests.rs | 10 +++++++--- library/alloc/src/collections/vec_deque/mod.rs | 3 +-- library/alloc/src/slice.rs | 6 ++---- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/library/alloc/src/collections/binary_heap/tests.rs b/library/alloc/src/collections/binary_heap/tests.rs index 35a844c738ca3..4f46bc5385aa4 100644 --- a/library/alloc/src/collections/binary_heap/tests.rs +++ b/library/alloc/src/collections/binary_heap/tests.rs @@ -1,7 +1,7 @@ use super::*; use crate::boxed::Box; -use crate::{CO_ALLOC_PREF_META_YES, CO_ALLOC_PREF_META_NO}; use crate::testing::crash_test::{CrashTestDummy, Panic}; +use crate::{CO_ALLOC_PREF_META_NO, CO_ALLOC_PREF_META_YES}; use core::mem; use std::iter::TrustedLen; use std::panic::{catch_unwind, AssertUnwindSafe}; @@ -449,10 +449,14 @@ fn test_extend_specialization() { #[allow(dead_code)] fn assert_covariance() { - fn drain<'new>(d: Drain<'static, &'static str, {CO_ALLOC_PREF_META_NO!()}>) -> Drain<'new, &'new str, {CO_ALLOC_PREF_META_NO!()}> { + fn drain<'new>( + d: Drain<'static, &'static str, { CO_ALLOC_PREF_META_NO!() }>, + ) -> Drain<'new, &'new str, { CO_ALLOC_PREF_META_NO!() }> { d } - fn drain_co<'new>(d: Drain<'static, &'static str, {CO_ALLOC_PREF_META_YES!()}>) -> Drain<'new, &'new str, {CO_ALLOC_PREF_META_YES!()}> { + fn drain_co<'new>( + d: Drain<'static, &'static str, { CO_ALLOC_PREF_META_YES!() }>, + ) -> Drain<'new, &'new str, { CO_ALLOC_PREF_META_YES!() }> { d } } diff --git a/library/alloc/src/collections/vec_deque/mod.rs b/library/alloc/src/collections/vec_deque/mod.rs index d6991b31368b1..eb5229d484aa2 100644 --- a/library/alloc/src/collections/vec_deque/mod.rs +++ b/library/alloc/src/collections/vec_deque/mod.rs @@ -2844,8 +2844,7 @@ where #[stable(feature = "rust1", since = "1.0.0")] #[allow(unused_braces)] -impl FromIterator for VecDeque -{ +impl FromIterator for VecDeque { fn from_iter>(iter: I) -> VecDeque { SpecFromIterCo::spec_from_iter_co(iter.into_iter()) } diff --git a/library/alloc/src/slice.rs b/library/alloc/src/slice.rs index e6a2d869468b4..0fecde66d9f11 100644 --- a/library/alloc/src/slice.rs +++ b/library/alloc/src/slice.rs @@ -103,13 +103,11 @@ pub(crate) mod hack { // `vec!` macro mostly and causes perf regression. See #71204 for // discussion and perf results. #[allow(unused_braces)] - pub fn into_vec( - b: Box<[T], A>, - ) -> Vec + pub fn into_vec(b: Box<[T], A>) -> Vec where [(); { crate::meta_num_slots_default!(A) }]:, { - into_vec_co::(b) + into_vec_co::(b) } #[allow(unused_braces)] From 1d474742d378430d2999e59609cf75cb9a7b4a93 Mon Sep 17 00:00:00 2001 From: Peter Kehl Date: Sat, 18 Feb 2023 21:15:46 -0800 Subject: [PATCH 118/118] CoAlloc: Added CO_ALLOC_PREF to two Guard structs inside vec_deque::into_iter --- .../src/collections/vec_deque/into_iter.rs | 28 +++++++++++++------ 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/library/alloc/src/collections/vec_deque/into_iter.rs b/library/alloc/src/collections/vec_deque/into_iter.rs index f043ba9c82a4c..0615290f7a56d 100644 --- a/library/alloc/src/collections/vec_deque/into_iter.rs +++ b/library/alloc/src/collections/vec_deque/into_iter.rs @@ -1,6 +1,6 @@ -use core::iter::{FusedIterator, TrustedLen}; -use core::{alloc, array, fmt, mem::MaybeUninit, ops::Try, ptr}; use crate::co_alloc::CoAllocPref; +use core::iter::{FusedIterator, TrustedLen}; +use core::{array, fmt, mem::MaybeUninit, ops::Try, ptr}; use crate::alloc::{Allocator, Global}; @@ -93,13 +93,19 @@ where F: FnMut(B, Self::Item) -> R, R: Try, { - struct Guard<'a, T, A: Allocator> { - deque: &'a mut VecDeque, + struct Guard<'a, T, A: Allocator, const CO_ALLOC_PREF: CoAllocPref> + where + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, + { + deque: &'a mut VecDeque, // `consumed <= deque.len` always holds. consumed: usize, } - impl<'a, T, A: Allocator> Drop for Guard<'a, T, A> { + impl<'a, T, A: Allocator, const CO_ALLOC_PREF: CoAllocPref> Drop for Guard<'a, T, A, CO_ALLOC_PREF> + where + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, + { fn drop(&mut self) { self.deque.len -= self.consumed; self.deque.head = self.deque.to_physical_idx(self.consumed); @@ -221,13 +227,19 @@ where F: FnMut(B, Self::Item) -> R, R: Try, { - struct Guard<'a, T, A: Allocator> { - deque: &'a mut VecDeque, + struct Guard<'a, T, A: Allocator, const CO_ALLOC_PREF: CoAllocPref> + where + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, + { + deque: &'a mut VecDeque, // `consumed <= deque.len` always holds. consumed: usize, } - impl<'a, T, A: Allocator> Drop for Guard<'a, T, A> { + impl<'a, T, A: Allocator, const CO_ALLOC_PREF: CoAllocPref> Drop for Guard<'a, T, A, CO_ALLOC_PREF> + where + [(); { crate::meta_num_slots!(A, CO_ALLOC_PREF) }]:, + { fn drop(&mut self) { self.deque.len -= self.consumed; }