Skip to content

Commit 187a2cc

Browse files
CoAlloc: RawVec + compiler 'tests'
1 parent 33a20e6 commit 187a2cc

File tree

15 files changed

+58
-25
lines changed

15 files changed

+58
-25
lines changed

compiler/rustc_ast/src/ast.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ pub use UnsafeSource::*;
2626
use crate::ptr::P;
2727
use crate::token::{self, CommentKind, Delimiter};
2828
use crate::tokenstream::{DelimSpan, LazyAttrTokenStream, TokenStream};
29+
use core::alloc::GlobalCoAllocMeta;
2930
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
3031
use rustc_data_structures::stack::ensure_sufficient_stack;
3132
use rustc_data_structures::sync::Lrc;
@@ -37,7 +38,6 @@ use rustc_span::{Span, DUMMY_SP};
3738
use std::fmt;
3839
use std::mem;
3940
use thin_vec::{thin_vec, ThinVec};
40-
4141
/// A "Label" is an identifier of some point in sources,
4242
/// e.g. in the following code:
4343
///
@@ -3112,26 +3112,26 @@ mod size_asserts {
31123112
static_assert_size!(AssocItem, 104);
31133113
static_assert_size!(AssocItemKind, 32);
31143114
static_assert_size!(Attribute, 32);
3115-
static_assert_size!(Block, 48);
3116-
static_assert_size!(Expr, 72);
3117-
static_assert_size!(ExprKind, 40);
3118-
static_assert_size!(Fn, 184);
3115+
static_assert_size!(Block, 48 + mem::size_of::<GlobalCoAllocMeta>());
3116+
static_assert_size!(Expr, 72 + mem::size_of::<GlobalCoAllocMeta>());
3117+
static_assert_size!(ExprKind, 40 + mem::size_of::<GlobalCoAllocMeta>());
3118+
static_assert_size!(Fn, 184 + 2 * mem::size_of::<GlobalCoAllocMeta>());
31193119
static_assert_size!(ForeignItem, 96);
31203120
static_assert_size!(ForeignItemKind, 24);
31213121
static_assert_size!(GenericArg, 24);
3122-
static_assert_size!(GenericBound, 72);
3123-
static_assert_size!(Generics, 72);
3124-
static_assert_size!(Impl, 184);
3125-
static_assert_size!(Item, 184);
3126-
static_assert_size!(ItemKind, 112);
3122+
static_assert_size!(GenericBound, 72 + mem::size_of::<GlobalCoAllocMeta>());
3123+
static_assert_size!(Generics, 72 + 2 * mem::size_of::<GlobalCoAllocMeta>());
3124+
static_assert_size!(Impl, 184 + 3 * mem::size_of::<GlobalCoAllocMeta>());
3125+
static_assert_size!(Item, 184 + 3 * mem::size_of::<GlobalCoAllocMeta>());
3126+
static_assert_size!(ItemKind, 112 + 3 * mem::size_of::<GlobalCoAllocMeta>());
31273127
static_assert_size!(LitKind, 24);
31283128
static_assert_size!(Local, 72);
31293129
static_assert_size!(MetaItemLit, 40);
31303130
static_assert_size!(Param, 40);
3131-
static_assert_size!(Pat, 88);
3131+
static_assert_size!(Pat, 88 + mem::size_of::<GlobalCoAllocMeta>());
31323132
static_assert_size!(Path, 24);
31333133
static_assert_size!(PathSegment, 24);
3134-
static_assert_size!(PatKind, 64);
3134+
static_assert_size!(PatKind, 64 + mem::size_of::<GlobalCoAllocMeta>());
31353135
static_assert_size!(Stmt, 32);
31363136
static_assert_size!(StmtKind, 16);
31373137
static_assert_size!(Ty, 64);

compiler/rustc_ast/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#![feature(box_patterns)]
1313
#![feature(const_default_impls)]
1414
#![feature(const_trait_impl)]
15+
#![feature(global_co_alloc_meta)]
1516
#![feature(if_let_guard)]
1617
#![feature(let_chains)]
1718
#![feature(min_specialization)]

compiler/rustc_middle/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#![feature(exhaustive_patterns)]
3333
#![feature(generators)]
3434
#![feature(get_mut_unchecked)]
35+
#![feature(global_co_alloc_meta)]
3536
#![feature(if_let_guard)]
3637
#![feature(iter_from_generator)]
3738
#![feature(local_key_cell_methods)]

compiler/rustc_middle/src/mir/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
//!
33
//! [rustc dev guide]: https://rustc-dev-guide.rust-lang.org/mir/index.html
44
5+
use core::alloc::GlobalCoAllocMeta;
56
use crate::mir::interpret::{
67
AllocRange, ConstAllocation, ConstValue, ErrorHandled, GlobalAlloc, LitToConstInput, Scalar,
78
};
@@ -3077,7 +3078,7 @@ mod size_asserts {
30773078
use super::*;
30783079
use rustc_data_structures::static_assert_size;
30793080
// tidy-alphabetical-start
3080-
static_assert_size!(BasicBlockData<'_>, 144);
3081+
static_assert_size!(BasicBlockData<'_>, 144 + mem::size_of::<GlobalCoAllocMeta>());
30813082
static_assert_size!(LocalDecl<'_>, 56);
30823083
static_assert_size!(Statement<'_>, 32);
30833084
static_assert_size!(StatementKind<'_>, 16);

compiler/rustc_middle/src/mir/syntax.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
//! This is in a dedicated file so that changes to this file can be reviewed more carefully.
44
//! The intention is that this file only contains datatype declarations, no code.
55
6+
use core::alloc::GlobalCoAllocMeta;
7+
use core::mem;
68
use super::{BasicBlock, Constant, Field, Local, SwitchTargets, UserTypeProjection};
79

810
use crate::mir::coverage::{CodeRegion, CoverageKind};
@@ -1284,6 +1286,6 @@ mod size_asserts {
12841286
static_assert_size!(Operand<'_>, 24);
12851287
static_assert_size!(Place<'_>, 16);
12861288
static_assert_size!(PlaceElem<'_>, 24);
1287-
static_assert_size!(Rvalue<'_>, 40);
1289+
static_assert_size!(Rvalue<'_>, 40 + mem::size_of::<GlobalCoAllocMeta>());
12881290
// tidy-alphabetical-end
12891291
}

compiler/rustc_parse/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
33
#![feature(array_windows)]
44
#![feature(box_patterns)]
5+
#![feature(global_co_alloc_meta)]
56
#![feature(if_let_guard)]
67
#![feature(iter_intersperse)]
78
#![feature(let_chains)]

compiler/rustc_parse/src/parser/attr_wrapper.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use core::alloc::GlobalCoAllocMeta;
2+
use core::mem;
13
use super::{Capturing, FlatToken, ForceCollect, Parser, ReplaceRange, TokenCursor, TrailingToken};
24
use rustc_ast::token::{self, Delimiter, Token, TokenKind};
35
use rustc_ast::tokenstream::{AttrTokenStream, AttributesData, ToAttrTokenStream};
@@ -469,6 +471,6 @@ mod size_asserts {
469471
use rustc_data_structures::static_assert_size;
470472
// tidy-alphabetical-start
471473
static_assert_size!(AttrWrapper, 16);
472-
static_assert_size!(LazyAttrTokenStreamImpl, 120);
474+
static_assert_size!(LazyAttrTokenStreamImpl, 120 + mem::size_of::<GlobalCoAllocMeta>());
473475
// tidy-alphabetical-end
474476
}

compiler/rustc_parse/src/parser/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ mod stmt;
1111
mod ty;
1212

1313
use crate::lexer::UnmatchedBrace;
14+
use core::alloc::GlobalCoAllocMeta;
1415
pub use attr_wrapper::AttrWrapper;
1516
pub use diagnostics::AttemptLocalParseRecovery;
1617
pub(crate) use item::FnParseMode;
@@ -167,7 +168,7 @@ pub struct Parser<'a> {
167168
// This type is used a lot, e.g. it's cloned when matching many declarative macro rules with nonterminals. Make sure
168169
// it doesn't unintentionally get bigger.
169170
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
170-
rustc_data_structures::static_assert_size!(Parser<'_>, 312);
171+
rustc_data_structures::static_assert_size!(Parser<'_>, 312 + 4 * mem::size_of::<GlobalCoAllocMeta>());
171172

172173
/// Stores span information about a closure.
173174
#[derive(Clone)]

compiler/rustc_trait_selection/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#![feature(box_patterns)]
1616
#![feature(control_flow_enum)]
1717
#![feature(drain_filter)]
18+
#![feature(global_co_alloc_meta)]
1819
#![feature(hash_drain_filter)]
1920
#![feature(let_chains)]
2021
#![feature(if_let_guard)]

compiler/rustc_trait_selection/src/traits/fulfill.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
use crate::infer::{InferCtxt, TyOrConstInferVar};
2+
use core::alloc::GlobalCoAllocMeta;
3+
use core::mem;
4+
// use rustc_data_structures::fx::FxHashMap;
25
use rustc_data_structures::obligation_forest::ProcessResult;
36
use rustc_data_structures::obligation_forest::{Error, ForestObligation, Outcome};
47
use rustc_data_structures::obligation_forest::{ObligationForest, ObligationProcessor};
@@ -77,7 +80,7 @@ pub struct PendingPredicateObligation<'tcx> {
7780

7881
// `PendingPredicateObligation` is used a lot. Make sure it doesn't unintentionally get bigger.
7982
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
80-
static_assert_size!(PendingPredicateObligation<'_>, 72);
83+
static_assert_size!(PendingPredicateObligation<'_>, 72 + mem::size_of::<GlobalCoAllocMeta>());
8184

8285
impl<'a, 'tcx> FulfillmentContext<'tcx> {
8386
/// Creates a new fulfillment context.

library/alloc/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@
123123
#![feature(extend_one)]
124124
#![feature(fmt_internals)]
125125
#![feature(fn_traits)]
126+
#![feature(global_co_alloc_meta)]
126127
#![feature(hasher_prefixfree_extras)]
127128
#![feature(inline_const)]
128129
#![feature(inplace_iteration)]
@@ -178,6 +179,7 @@
178179
#![feature(exclusive_range_pattern)]
179180
#![feature(fundamental)]
180181
#![cfg_attr(not(test), feature(generator_trait))]
182+
#![feature(global_co_alloc)]
181183
#![feature(hashmap_internals)]
182184
#![feature(lang_items)]
183185
#![feature(min_specialization)]

library/alloc/src/raw_vec.rs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#![unstable(feature = "raw_vec_internals", reason = "unstable const warnings", issue = "none")]
22

3-
use core::alloc::LayoutError;
3+
use core::alloc::{LayoutError, GlobalCoAllocMeta};
44
use core::cmp;
55
use core::intrinsics;
66
use core::mem::{self, ManuallyDrop, MaybeUninit, SizedTypeProperties};
@@ -53,6 +53,8 @@ pub(crate) struct RawVec<T, A: Allocator = Global> {
5353
ptr: Unique<T>,
5454
cap: usize,
5555
alloc: A,
56+
#[allow(dead_code)]
57+
pub(crate) meta: GlobalCoAllocMeta,
5658
}
5759

5860
impl<T> RawVec<T, Global> {
@@ -120,7 +122,7 @@ impl<T, A: Allocator> RawVec<T, A> {
120122
/// the returned `RawVec`.
121123
pub const fn new_in(alloc: A) -> Self {
122124
// `cap: 0` means "unallocated". zero-sized types are ignored.
123-
Self { ptr: Unique::dangling(), cap: 0, alloc }
125+
Self { ptr: Unique::dangling(), cap: 0, alloc, meta: GlobalCoAllocMeta {/*one: 1*/ /* , two: 2, three: 3, four: 4*/} }
124126
}
125127

126128
/// Like `with_capacity`, but parameterized over the choice of
@@ -197,6 +199,7 @@ impl<T, A: Allocator> RawVec<T, A> {
197199
ptr: unsafe { Unique::new_unchecked(ptr.cast().as_ptr()) },
198200
cap: capacity,
199201
alloc,
202+
meta: GlobalCoAllocMeta {/*one: 1*/ /*, two: 2, three: 3, four: 4*/}
200203
}
201204
}
202205
}
@@ -213,7 +216,7 @@ impl<T, A: Allocator> RawVec<T, A> {
213216
/// guaranteed.
214217
#[inline]
215218
pub unsafe fn from_raw_parts_in(ptr: *mut T, capacity: usize, alloc: A) -> Self {
216-
Self { ptr: unsafe { Unique::new_unchecked(ptr) }, cap: capacity, alloc }
219+
Self { ptr: unsafe { Unique::new_unchecked(ptr) }, cap: capacity, alloc, meta: GlobalCoAllocMeta {/*one: 1*/ /*, two: 2, three: 3, four: 4*/} }
217220
}
218221

219222
/// Gets a raw pointer to the start of the allocation. Note that this is
@@ -480,8 +483,18 @@ where
480483
}
481484

482485
unsafe impl<#[may_dangle] T, A: Allocator> Drop for RawVec<T, A> {
486+
/// Frees the memory owned by the `RawVec` *without* trying to drop its contents.
487+
default fn drop(&mut self) {
488+
if let Some((ptr, layout)) = self.current_memory() {
489+
unsafe { self.alloc.deallocate(ptr, layout) }
490+
}
491+
}
492+
}
493+
494+
unsafe impl<#[may_dangle] T> Drop for RawVec<T, Global> {
483495
/// Frees the memory owned by the `RawVec` *without* trying to drop its contents.
484496
fn drop(&mut self) {
497+
// @TODO
485498
if let Some((ptr, layout)) = self.current_memory() {
486499
unsafe { self.alloc.deallocate(ptr, layout) }
487500
}

src/librustdoc/clean/types.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
use std::alloc::GlobalCoAllocMeta;
12
use std::cell::RefCell;
23
use std::default::Default;
34
use std::hash::Hash;
5+
use std::mem;
46
use std::path::PathBuf;
57
use std::rc::Rc;
68
use std::sync::Arc;
@@ -2400,13 +2402,13 @@ mod size_asserts {
24002402
// tidy-alphabetical-start
24012403
static_assert_size!(Crate, 64); // frequently moved by-value
24022404
static_assert_size!(DocFragment, 32);
2403-
static_assert_size!(GenericArg, 32);
2405+
static_assert_size!(GenericArg, 32 + mem::size_of::<GlobalCoAllocMeta>());
24042406
static_assert_size!(GenericArgs, 32);
2405-
static_assert_size!(GenericParamDef, 56);
2407+
static_assert_size!(GenericParamDef, 56 + mem::size_of::<GlobalCoAllocMeta>());
24062408
static_assert_size!(Generics, 16);
24072409
static_assert_size!(Item, 56);
2408-
static_assert_size!(ItemKind, 64);
2410+
static_assert_size!(ItemKind, 64 + mem::size_of::<GlobalCoAllocMeta>());
24092411
static_assert_size!(PathSegment, 40);
2410-
static_assert_size!(Type, 32);
2412+
static_assert_size!(Type, 32 + mem::size_of::<GlobalCoAllocMeta>());
24112413
// tidy-alphabetical-end
24122414
}

src/librustdoc/html/render/context.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
use std::alloc::GlobalCoAllocMeta;
12
use std::cell::RefCell;
23
use std::collections::BTreeMap;
34
use std::io;
5+
use std::mem;
46
use std::path::{Path, PathBuf};
57
use std::rc::Rc;
68
use std::sync::mpsc::{channel, Receiver};
@@ -75,7 +77,7 @@ pub(crate) struct Context<'tcx> {
7577

7678
// `Context` is cloned a lot, so we don't want the size to grow unexpectedly.
7779
#[cfg(all(not(windows), target_arch = "x86_64", target_pointer_width = "64"))]
78-
rustc_data_structures::static_assert_size!(Context<'_>, 160);
80+
rustc_data_structures::static_assert_size!(Context<'_>, 160 + 2 * mem::size_of::<GlobalCoAllocMeta>());
7981

8082
/// Shared mutable state used in [`Context`] and elsewhere.
8183
pub(crate) struct SharedContext<'tcx> {

src/librustdoc/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#![feature(assert_matches)]
88
#![feature(box_patterns)]
99
#![feature(drain_filter)]
10+
#![feature(global_co_alloc_meta)]
1011
#![feature(is_terminal)]
1112
#![feature(let_chains)]
1213
#![feature(test)]

0 commit comments

Comments
 (0)