Skip to content

DO NOT REVIEW - WIP - 05 vec macroed #108150

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 118 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
118 commits
Select commit Hold shift + click to select a range
619198d
START CoAlloc API
peter-lyons-kehl Jan 21, 2023
0b47315
CoAlloc: RawVec + compiler 'tests'
peter-lyons-kehl Jan 21, 2023
53028b7
CoAlloc: GlobalAlloc API
peter-lyons-kehl Dec 10, 2022
5539899
CoAlloc: Alloc API
peter-lyons-kehl Jan 21, 2023
0625fae
CoAlloc: RawVec includes GlobalCoAllocMeta based on allocator; relate…
peter-lyons-kehl Jan 21, 2023
4ddafb9
CoAlloc: VecDeque (PROBABLY NOT COMPILING, standard error)
peter-lyons-kehl Jan 21, 2023
4d3b575
CoAlloc: RawVec + Vec with COOP_PREFERRED. PROBABLY NOT COMPILING, bu…
peter-lyons-kehl Jan 22, 2023
c96efc4
VecDeque with COOP_PREFERRED. PROBABLY NOT COMPILING, but no ICE.
peter-lyons-kehl Jan 22, 2023
fb1e72f
CoAlloc: RawVec, Vec, Box uses bounds. ICE
peter-lyons-kehl Jan 22, 2023
7450192
CoAlloc: BinaryHeap now uses bounds. (Probably needs to go together w…
peter-lyons-kehl Jan 22, 2023
3fb632e
CoAlloc: VecDeque now uses bounds. ICE
peter-lyons-kehl Jan 22, 2023
01599b9
CoAlloc: VecDeque. Probably ICE.
peter-lyons-kehl Jan 22, 2023
7e858bd
CoAlloc: Vec + Slice. ICE
peter-lyons-kehl Jan 22, 2023
8b1fbce
CoAlloc: VecDeque. ICE
peter-lyons-kehl Jan 22, 2023
0ec3f92
CoAlloc: Minor
peter-lyons-kehl Jan 22, 2023
8fb1196
CoAlloc: Vec + its use cases. ICE
peter-lyons-kehl Jan 22, 2023
215a2b4
CoAlloc: VecDeque minor. ICE
peter-lyons-kehl Jan 22, 2023
9a2c01a
CoAlloc: Vec, Alloc, GlobalAlloc: x test tidy --bless. ICE
peter-lyons-kehl Jan 22, 2023
bd4357b
CoAlloc: VecDeque + BinaryHeap: x test tidy --bless. ICE
peter-lyons-kehl Jan 22, 2023
b8de090
CoAlloc: VecDeque. ICE
peter-lyons-kehl Jan 22, 2023
5a70368
CoAlloc: VecDeque. ICE
peter-lyons-kehl Jan 22, 2023
fb970ff
CoAlloc: Alloc docs. ICE
peter-lyons-kehl Jan 22, 2023
5a97df4
CoAlloc: Vec + BinaryHeap. ICE
peter-lyons-kehl Dec 14, 2022
9704c3c
CoAlloc: WeVec. ICE
peter-lyons-kehl Jan 22, 2023
9beba9a
CoAlloc: Vec + Alloc. Moved co_alloc_metadata_num_slots_with_preferen…
peter-lyons-kehl Jan 22, 2023
5569b1f
CoAlloc: BinaryHeap. ICE
peter-lyons-kehl Jan 22, 2023
19d643c
CoAlloc: Vec: Renamed ::core::alloc::co_alloc_metadata_num_slots_with…
peter-lyons-kehl Jan 22, 2023
e081c51
CoAlloc: VecDeque: Renamed ::core::alloc::co_alloc_metadata_num_slots…
peter-lyons-kehl Jan 22, 2023
c84a040
CoAlloc: Minor VecDeque. ICE
peter-lyons-kehl Jan 22, 2023
81d49a7
CoAlloc: Vec: Tidy. ICE
peter-lyons-kehl Jan 22, 2023
7ed4a60
CoAlloc: Vec: Working around ICE rust-lang/rust issue #106473 ICE. WIP
peter-lyons-kehl Jan 22, 2023
3f84cef
CoAlloc: Vec (NOT String): Working around ICE rust-lang/rust issue #1…
peter-lyons-kehl Jan 22, 2023
63e0602
CoAlloc: BinaryHeap: Working around ICE rust-lang/rust issue #106473 …
peter-lyons-kehl Jan 22, 2023
40b204f
CoAlloc: Vec + related + FFI (NOT String-related): Macros instead of …
peter-lyons-kehl Jan 22, 2023
71080ba
CoAlloc: VecDeque: Macros instead of const for global COOP defaults (…
peter-lyons-kehl Jan 22, 2023
ee2b873
CoAlloc: BinaryHeap: Macros instead of const for global COOP defaults…
peter-lyons-kehl Jan 22, 2023
68b924b
CoAlloc: TODO replace co_alloc_metadata_num_slots_with_preference_glo…
peter-lyons-kehl Jan 22, 2023
362e27a
CoAlloc: Vec + core: Renamed co_alloc_metadata_num_slots_with_prefere…
peter-lyons-kehl Jan 23, 2023
ad036e1
CoAlloc: VecDeque: Renamed co_alloc_metadata_num_slots_with_preferenc…
peter-lyons-kehl Jan 23, 2023
7e059a3
CoAlloc: Vec + Box + Rc: Fixing COOP_PREFERRED (and similar).
peter-lyons-kehl Jan 23, 2023
bd32743
CoAlloc: VecDeque: Fixing COOP_PREFERRED (and similar).
peter-lyons-kehl Jan 23, 2023
3d98537
CoAlloc: BinaryHeap: Fixing COOP_PREFERRED (and similar).
peter-lyons-kehl Jan 23, 2023
01f915e
CoAlloc: Vec + Box: Fixing COOP_PREFERRED.
peter-lyons-kehl Jan 23, 2023
efa9f7b
CoAlloc: VecDeque: Fixing COOP_PREFERRED.
peter-lyons-kehl Jan 23, 2023
66199e3
CoAlloc: Vec: Fixing COOP_PREFERRED.
peter-lyons-kehl Jan 23, 2023
a0497c5
CoAlloc: VecDeque: Fixing COOP_PREFERRED.
peter-lyons-kehl Jan 23, 2023
d3e561f
CoAlloc: VecDeque: Fixing COOP_PREFERRED
peter-lyons-kehl Jan 23, 2023
f5efcd5
CoAlloc: Slice: Fixing COOP_PREFERRED
peter-lyons-kehl Jan 23, 2023
246424f
CoAlloc: Vec: Fixing COOP_PREFERRED
peter-lyons-kehl Jan 23, 2023
d540eef
CoAlloc: minor cleanup
peter-lyons-kehl Jan 23, 2023
ecae4ef
CoAlloc: Vec: COOP_PREFERRED
peter-lyons-kehl Jan 23, 2023
1a8ded6
CoAlloc: Vec: COOP_PREFERRED
peter-lyons-kehl Jan 23, 2023
22a782c
CoAlloc: VecDeque: COOP_PREFERRED
peter-lyons-kehl Jan 23, 2023
3bf7d99
CoAlloc: library/alloc: minor cleanup
peter-lyons-kehl Jan 23, 2023
e970674
CoAlloc: library/alloc: Re-added a closing curly bracket in mod test_…
peter-lyons-kehl Jan 23, 2023
22cacd4
CoAlloc: Vec + slice: COOP_PREFERRED
peter-lyons-kehl Jan 23, 2023
6e52828
CoAlloc: library/alloc/src/ffi: minor
peter-lyons-kehl Jan 23, 2023
823b8bf
CoAlloc: VecDeque: minor
peter-lyons-kehl Jan 23, 2023
a742846
CoAlloc: Vec: COOP_PREFERRED
peter-lyons-kehl Jan 23, 2023
2845276
CoAlloc: Vec + Box: COOP_PREFERRED for various traits
peter-lyons-kehl Jan 23, 2023
895f042
CoAlloc: VecDeque: minor cleanup
peter-lyons-kehl Jan 23, 2023
450e2f0
CoVec, PlVec, DefVec, WeVec. Cleanup.
peter-lyons-kehl Jan 13, 2023
f697061
CoAlloc: Vec: added new_co()
peter-lyons-kehl Jan 23, 2023
bce2757
CoAlloc: std/src/lib.rs: minor
peter-lyons-kehl Jan 23, 2023
8d5728e
CoAlloc: FFI: minor
peter-lyons-kehl Jan 23, 2023
57aaf50
CoAlloc: VecDeque (io::Read + io::Write for VecDeque): minor
peter-lyons-kehl Jan 23, 2023
69db430
CoAlloc: sys ... thread dtor: minor
peter-lyons-kehl Jan 23, 2023
2eb987f
CoAlloc: alloc: minor
peter-lyons-kehl Jan 23, 2023
7108ea6
CoAlloc: library/core: tidy
peter-lyons-kehl Jan 23, 2023
9eb2879
CoAlloc: library/proc_macro: tidy
peter-lyons-kehl Jan 23, 2023
eb87740
CoAlloc: Vec, Box + related slice.rs: tidy
peter-lyons-kehl Jan 23, 2023
b08c97f
CoAlloc: std: minor tidy
peter-lyons-kehl Jan 23, 2023
48ebfec
CoAlloc: VecDeque: tidy
peter-lyons-kehl Jan 23, 2023
3768ee2
CoAlloc: BinaryHeap: tidy
peter-lyons-kehl Jan 23, 2023
54729da
CoAlloc: slice.rs: Cleanup (of old code already commented out)
peter-lyons-kehl Jan 23, 2023
66e6dde
CoAlloc: Uncommenting assert of BorrowType::TRAVERSAL_PERMIT. TODO Un…
peter-lyons-kehl Jan 13, 2023
661318c
CoAlloc: Vec + related: cleanup. Now library/alloc compiles, but std/…
peter-lyons-kehl Jan 24, 2023
786c443
CoAlloc: Vec, related + vec! macro: Separated co-alloc-aware function…
peter-lyons-kehl Jan 24, 2023
40661d3
CoAlloc: library/proc_macro (+related library/alloc): Experimenting w…
peter-lyons-kehl Jan 24, 2023
27c4c3e
CoAlloc: Renamed feature global_co_alloc_def to global_co_alloc_defau…
peter-lyons-kehl Jan 25, 2023
71b8f3d
CoAlloc: Removed co_alloc_metadata_num_slots(). Added docs.
peter-lyons-kehl Jan 25, 2023
ddb3a41
CoAlloc: Move + rename macros DEFAULT_COOP_PREF + meta_num_slots* mac…
peter-lyons-kehl Jan 26, 2023
327596a
CoAlloc: Using the new macros (not everywhere yet).
peter-lyons-kehl Jan 26, 2023
af76916
CoAlloc: Renamed IS_CO_ALLOCATOR -> CO_ALLOCATES_WITH_META. Added All…
peter-lyons-kehl Jan 26, 2023
c5e76a3
CoAlloc: Moved CoAllocMeta to both Allocator and GlobalAlloc.
peter-lyons-kehl Jan 26, 2023
e8d7dbd
CoAlloc: meta_num_slots... macros- WIP
peter-lyons-kehl Jan 26, 2023
37c55a3
CoAlloc: meta_num_slots... macros- WIP..
peter-lyons-kehl Jan 27, 2023
4a996e6
CoAlloc: renamed macro DEFAULT_COOP_PREF -> CO_ALLOC_PREF_DEFAULT
peter-lyons-kehl Jan 27, 2023
9ca4c8e
CoAlloc: minor tidy
peter-lyons-kehl Jan 27, 2023
7392c80
CoAlloc: Preference/config types in ::alloc::co_alloc. Config value m…
peter-lyons-kehl Jan 28, 2023
268e6e3
CoAlloc: Renaming to use new value/config + transformation macros.
peter-lyons-kehl Jan 29, 2023
4aea4f9
CoAlloc: Using config + transformation macros in ::alloc. ICE!
peter-lyons-kehl Jan 29, 2023
cbe6035
CoAlloc: co_alloc_pref changed to 0usize - and (at least now) no ICE.
peter-lyons-kehl Jan 30, 2023
826786a
CoAlloc: library/alloc now uses macros, and no ICE. But meta_num_slot…
peter-lyons-kehl Jan 30, 2023
16f13bb
CoAlloc: Using macros for config + transformations. WIP
peter-lyons-kehl Jan 31, 2023
6afb0d6
CoAlloc: (Some) Separation of co-alloc-aware traits & methods.
peter-lyons-kehl Jan 31, 2023
b20534f
CoAlloc: Undoing generalizations + splitting. WIP
peter-lyons-kehl Feb 1, 2023
b231c87
CoAlloc: slice::to_vec_co, slice::to_vec_in_co.
peter-lyons-kehl Feb 1, 2023
b1c8971
CoAlloc: Separated Vec::from_raw_parts_co and similar (and also in Ve…
peter-lyons-kehl Feb 1, 2023
053a4b9
CoAlloc: tidy
peter-lyons-kehl Feb 1, 2023
68dc9e4
CoAlloc: Fixed my buggy rebase. Added slice::SpecCloneIntoVecCo and f…
peter-lyons-kehl Feb 2, 2023
819d4e1
CoAlloc: Default for Vec - both coallocation-aware (default fn), and …
peter-lyons-kehl Feb 2, 2023
bd1f71b
CoAlloc: VecDeque: new_co, with_capacity_co, made default() coallocat…
peter-lyons-kehl Feb 2, 2023
20eded1
CoAlloc: tidy
peter-lyons-kehl Feb 2, 2023
fd11520
CoAlloc: Fixed previous sick result of: tidy --bless
peter-lyons-kehl Feb 2, 2023
43d25dd
CoAlloc: slice::into_vec_co - for vec![...].
peter-lyons-kehl Feb 2, 2023
b76c63d
CoAlloc: compiler/rustc_arena: specialization; using Allocator::CoAll…
peter-lyons-kehl Feb 3, 2023
896f3dc
CoAlloc: Unspecialized and specialized Box<[T]>::from(Vec) and Vec::f…
peter-lyons-kehl Feb 4, 2023
388ba85
CoAlloc: Fixed specializations
peter-lyons-kehl Feb 14, 2023
b9f350c
CoAlloc: Fixes
peter-lyons-kehl Feb 15, 2023
08e675a
Limited working around rust-lang/rust issue #106473.
peter-lyons-kehl Feb 15, 2023
319b888
CoAlloc: tidy
peter-lyons-kehl Feb 15, 2023
8caa109
CoAlloc: bless
peter-lyons-kehl Feb 15, 2023
9fc9cd9
CoAlloc: Working around a fmt bug
peter-lyons-kehl Feb 15, 2023
18d9361
CoAlloc: Removed/split CO_ALLOC_PREF. Fixed tests
peter-lyons-kehl Feb 17, 2023
5bbf264
CoAlloc: FIXME: raw_vec::assert_alignment()
peter-lyons-kehl Feb 17, 2023
a84b78c
CoAlloc: tidy
peter-lyons-kehl Feb 18, 2023
1d47474
CoAlloc: Added CO_ALLOC_PREF to two Guard structs inside vec_deque::i…
peter-lyons-kehl Feb 19, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion compiler/rustc_arena/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
25 changes: 13 additions & 12 deletions compiler/rustc_ast/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,11 @@ 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};

/// A "Label" is an identifier of some point in sources,
/// e.g. in the following code:
///
Expand Down Expand Up @@ -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);
static_assert_size!(Expr, 72);
static_assert_size!(ExprKind, 40);
static_assert_size!(Fn, 184);
static_assert_size!(Block, 48 + mem::size_of::<<Global as Allocator>::CoAllocMeta>());
static_assert_size!(Expr, 72 + mem::size_of::<<Global as Allocator>::CoAllocMeta>());
static_assert_size!(ExprKind, 40 + mem::size_of::<<Global as Allocator>::CoAllocMeta>());
static_assert_size!(Fn, 184 + 2 * mem::size_of::<<Global as Allocator>::CoAllocMeta>());
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::<<Global as Allocator>::CoAllocMeta>());
static_assert_size!(Generics, 72 + 2 * mem::size_of::<<Global as Allocator>::CoAllocMeta>());
static_assert_size!(Impl, 184 + 3 * mem::size_of::<<Global as Allocator>::CoAllocMeta>());
static_assert_size!(Item, 184 + 3 * mem::size_of::<<Global as Allocator>::CoAllocMeta>());
static_assert_size!(ItemKind, 112 + 3 * mem::size_of::<<Global as Allocator>::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);
static_assert_size!(Pat, 88 + mem::size_of::<<Global as Allocator>::CoAllocMeta>());
static_assert_size!(Path, 24);
static_assert_size!(PathSegment, 24);
static_assert_size!(PatKind, 64);
static_assert_size!(PatKind, 64 + mem::size_of::<<Global as Allocator>::CoAllocMeta>());
static_assert_size!(Stmt, 32);
static_assert_size!(StmtKind, 16);
static_assert_size!(Ty, 64);
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_ast/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
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)]
#![feature(const_trait_impl)]
#![feature(global_co_alloc_meta)]
#![feature(if_let_guard)]
#![feature(let_chains)]
#![feature(min_specialization)]
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_middle/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_middle/src/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,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;
Expand Down Expand Up @@ -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::<GlobalCoAllocMeta>());
static_assert_size!(LocalDecl<'_>, 56);
static_assert_size!(Statement<'_>, 32);
static_assert_size!(StatementKind<'_>, 16);
Expand Down
4 changes: 3 additions & 1 deletion compiler/rustc_middle/src/mir/syntax.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
//! 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 crate::mir::coverage::{CodeRegion, CoverageKind};
use crate::traits::Reveal;
Expand Down Expand Up @@ -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::<GlobalCoAllocMeta>());
// tidy-alphabetical-end
}
1 change: 1 addition & 0 deletions compiler/rustc_parse/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
4 changes: 3 additions & 1 deletion compiler/rustc_parse/src/parser/attr_wrapper.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use super::{Capturing, FlatToken, ForceCollect, Parser, ReplaceRange, TokenCursor, TrailingToken};
use core::alloc::GlobalCoAllocMeta;
use core::mem;
use rustc_ast::token::{self, Delimiter, Token, TokenKind};
use rustc_ast::tokenstream::{AttrTokenStream, AttributesData, ToAttrTokenStream};
use rustc_ast::tokenstream::{AttrTokenTree, DelimSpan, LazyAttrTokenStream, Spacing};
Expand Down Expand Up @@ -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::<GlobalCoAllocMeta>());
// tidy-alphabetical-end
}
6 changes: 5 additions & 1 deletion compiler/rustc_parse/src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ mod ty;

use crate::lexer::UnmatchedBrace;
pub use attr_wrapper::AttrWrapper;
use core::alloc::GlobalCoAllocMeta;
pub use diagnostics::AttemptLocalParseRecovery;
pub(crate) use item::FnParseMode;
pub use pat::{CommaRecoveryMode, RecoverColon, RecoverComma};
Expand Down Expand Up @@ -167,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);
rustc_data_structures::static_assert_size!(
Parser<'_>,
312 + 4 * mem::size_of::<GlobalCoAllocMeta>()
);

/// Stores span information about a closure.
#[derive(Clone)]
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_trait_selection/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
5 changes: 4 additions & 1 deletion compiler/rustc_trait_selection/src/traits/fulfill.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -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::<GlobalCoAllocMeta>());

impl<'a, 'tcx> FulfillmentContext<'tcx> {
/// Creates a new fulfillment context.
Expand Down
66 changes: 53 additions & 13 deletions library/alloc/src/boxed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -641,7 +642,10 @@ impl<T> Box<[T]> {
#[unstable(feature = "new_uninit", issue = "63291")]
#[must_use]
pub fn new_uninit_slice(len: usize) -> Box<[mem::MaybeUninit<T>]> {
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::<T, Global, { CO_ALLOC_PREF_META_NO!() }>::with_capacity(len).into_box(len)
}
}

/// Constructs a new boxed slice with uninitialized contents, with the memory
Expand All @@ -666,7 +670,11 @@ impl<T> Box<[T]> {
#[unstable(feature = "new_uninit", issue = "63291")]
#[must_use]
pub fn new_zeroed_slice(len: usize) -> Box<[mem::MaybeUninit<T>]> {
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::<T, Global, { CO_ALLOC_PREF_META_NO!() }>::with_capacity_zeroed(len)
.into_box(len)
}
}

/// Constructs a new boxed slice with uninitialized contents. Returns an error if
Expand Down Expand Up @@ -698,7 +706,12 @@ impl<T> 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::<T, Global, { CO_ALLOC_PREF_META_NO!() }>::from_raw_parts_in(
ptr.as_mut_ptr() as *mut _,
len,
Global,
)
.into_box(len))
}
}

Expand Down Expand Up @@ -730,12 +743,21 @@ impl<T> 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::<T, Global, { CO_ALLOC_PREF_META_NO!() }>::from_raw_parts_in(
ptr.as_mut_ptr() as *mut _,
len,
Global,
)
.into_box(len))
}
}
}

impl<T, A: Allocator> Box<[T], A> {
#[allow(unused_braces)]
impl<T, A: Allocator> Box<[T], A>
where
[(); { crate::meta_num_slots!(A, crate::CO_ALLOC_PREF_META_NO!()) }]:,
{
/// Constructs a new boxed slice with uninitialized contents in the provided allocator.
///
/// # Examples
Expand All @@ -762,8 +784,11 @@ impl<T, A: Allocator> Box<[T], A> {
#[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<T>], A> {
unsafe { RawVec::with_capacity_in(len, alloc).into_box(len) }
unsafe {
RawVec::<T, A, { CO_ALLOC_PREF_META_NO!() }>::with_capacity_in(len, alloc).into_box(len)
}
}

/// Constructs a new boxed slice with uninitialized contents in the provided allocator,
Expand All @@ -790,8 +815,12 @@ impl<T, A: Allocator> Box<[T], A> {
#[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<T>], A> {
unsafe { RawVec::with_capacity_zeroed_in(len, alloc).into_box(len) }
unsafe {
RawVec::<T, A, { CO_ALLOC_PREF_META_NO!() }>::with_capacity_zeroed_in(len, alloc)
.into_box(len)
}
}
}

Expand Down Expand Up @@ -1496,7 +1525,8 @@ impl<T: Copy> 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::<T, Global, { CO_ALLOC_PREF_META_NO!() }>::with_capacity(len);
unsafe {
ptr::copy_nonoverlapping(slice.as_ptr(), buf.ptr(), len);
buf.into_box(slice.len()).assume_init()
Expand Down Expand Up @@ -1661,8 +1691,13 @@ impl<T, const N: usize> TryFrom<Box<[T]>> for Box<[T; N]> {

#[cfg(not(no_global_oom_handling))]
#[stable(feature = "boxed_array_try_from_vec", since = "1.66.0")]
impl<T, const N: usize> TryFrom<Vec<T>> for Box<[T; N]> {
type Error = Vec<T>;
#[allow(unused_braces)]
impl<T, const N: usize, const CO_ALLOC_PREF: CoAllocPref> TryFrom<Vec<T, Global, CO_ALLOC_PREF>>
for Box<[T; N]>
where
[(); { meta_num_slots_global!(CO_ALLOC_PREF) }]:,
{
type Error = Vec<T, Global, CO_ALLOC_PREF>;

/// Attempts to convert a `Vec<T>` into a `Box<[T; N]>`.
///
Expand All @@ -1682,7 +1717,7 @@ impl<T, const N: usize> TryFrom<Vec<T>> 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<T>) -> Result<Self, Self::Error> {
fn try_from(vec: Vec<T, Global, CO_ALLOC_PREF>) -> Result<Self, Self::Error> {
if vec.len() == N {
let boxed_slice = vec.into_boxed_slice();
Ok(unsafe { boxed_slice_as_array_unchecked(boxed_slice) })
Expand Down Expand Up @@ -2019,10 +2054,15 @@ impl<I> FromIterator<I> for Box<[I]> {

#[cfg(not(no_global_oom_handling))]
#[stable(feature = "box_slice_clone", since = "1.3.0")]
impl<T: Clone, A: Allocator + Clone> Clone for Box<[T], A> {
#[allow(unused_braces)]
impl<T: Clone, A: Allocator + Clone> Clone for Box<[T], A>
where
[(); { crate::meta_num_slots!(A, crate::CO_ALLOC_PREF_META_NO!()) }]:,
{
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_co::<A, { CO_ALLOC_PREF_META_NO!() }>(alloc).into_boxed_slice()
}

fn clone_from(&mut self, other: &Self) {
Expand Down
47 changes: 47 additions & 0 deletions library/alloc/src/co_alloc.rs
Original file line number Diff line number Diff line change
@@ -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 = usize; //u8;

/// `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
/// 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;
Loading