Skip to content

Commit 6110693

Browse files
CoAlloc: x86_64-only compiler node size asserts. Tidy.
1 parent 21ca3e8 commit 6110693

File tree

10 files changed

+21
-27
lines changed

10 files changed

+21
-27
lines changed

compiler/rustc_ast/src/ast.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@ use rustc_serialize::{Decodable, Decoder, Encodable, Encoder};
3434
use rustc_span::source_map::{respan, Spanned};
3535
use rustc_span::symbol::{kw, sym, Ident, Symbol};
3636
use rustc_span::{Span, DUMMY_SP};
37-
use std::alloc::Allocator;
38-
use std::alloc::Global;
3937
use std::fmt;
4038
use std::mem;
4139
use thin_vec::{thin_vec, ThinVec};
@@ -3114,6 +3112,7 @@ pub type ForeignItem = Item<ForeignItemKind>;
31143112
mod size_asserts {
31153113
use super::*;
31163114
use rustc_data_structures::static_assert_size;
3115+
use std::alloc::{Allocator, Global};
31173116
// tidy-alphabetical-start
31183117
static_assert_size!(AssocItem, 104);
31193118
static_assert_size!(AssocItemKind, 32);

compiler/rustc_middle/src/mir/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ use rustc_span::{Span, DUMMY_SP};
3434

3535
use either::Either;
3636

37-
use std::alloc::{Allocator, Global};
3837
use std::borrow::Cow;
3938
use std::fmt::{self, Debug, Display, Formatter, Write};
4039
use std::ops::{ControlFlow, Index, IndexMut};
@@ -3084,7 +3083,7 @@ mod size_asserts {
30843083
// tidy-alphabetical-start
30853084
static_assert_size!(
30863085
BasicBlockData<'_>,
3087-
144 + mem::size_of::<<Global as Allocator>::CoAllocMeta>()
3086+
144 + mem::size_of::<<std::alloc::Global as std::alloc::Allocator>::CoAllocMeta>()
30883087
);
30893088
static_assert_size!(LocalDecl<'_>, 40);
30903089
static_assert_size!(Statement<'_>, 32);

compiler/rustc_middle/src/mir/syntax.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
//! The intention is that this file only contains datatype declarations, no code.
55
66
use super::{BasicBlock, Constant, Field, Local, SwitchTargets, UserTypeProjection};
7-
use core::mem;
87

98
use crate::mir::coverage::{CodeRegion, CoverageKind};
109
use crate::traits::Reveal;
@@ -25,8 +24,6 @@ use rustc_span::symbol::Symbol;
2524
use rustc_span::Span;
2625
use rustc_target::asm::InlineAsmRegOrRegClass;
2726

28-
use std::alloc::{Allocator, Global};
29-
3027
/// Represents the "flavors" of MIR.
3128
///
3229
/// All flavors of MIR use the same data structure, but there are some important differences. These
@@ -1254,6 +1251,9 @@ mod size_asserts {
12541251
static_assert_size!(Operand<'_>, 24);
12551252
static_assert_size!(Place<'_>, 16);
12561253
static_assert_size!(PlaceElem<'_>, 24);
1257-
static_assert_size!(Rvalue<'_>, 40 + mem::size_of::<<Global as Allocator>::CoAllocMeta>());
1254+
static_assert_size!(
1255+
Rvalue<'_>,
1256+
40 + std::mem::size_of::<<std::alloc::Global as std::alloc::Allocator>::CoAllocMeta>()
1257+
);
12581258
// tidy-alphabetical-end
12591259
}

compiler/rustc_parse/src/parser/attr_wrapper.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use super::{Capturing, FlatToken, ForceCollect, Parser, ReplaceRange, TokenCursor, TrailingToken};
2-
use core::mem;
32
use rustc_ast::token::{self, Delimiter, Token, TokenKind};
43
use rustc_ast::tokenstream::{AttrTokenStream, AttributesData, ToAttrTokenStream};
54
use rustc_ast::tokenstream::{AttrTokenTree, DelimSpan, LazyAttrTokenStream, Spacing};
@@ -9,7 +8,6 @@ use rustc_errors::PResult;
98
use rustc_session::parse::ParseSess;
109
use rustc_span::{sym, Span, DUMMY_SP};
1110

12-
use std::alloc::{Allocator, Global};
1311
use std::ops::Range;
1412

1513
/// A wrapper type to ensure that the parser handles outer attributes correctly.
@@ -469,11 +467,12 @@ fn make_token_stream(
469467
mod size_asserts {
470468
use super::*;
471469
use rustc_data_structures::static_assert_size;
470+
use std::alloc::{Allocator, Global};
472471
// tidy-alphabetical-start
473472
static_assert_size!(AttrWrapper, 16);
474473
static_assert_size!(
475474
LazyAttrTokenStreamImpl,
476-
120 + mem::size_of::<<Global as Allocator>::CoAllocMeta>()
475+
120 + std::mem::size_of::<<Global as Allocator>::CoAllocMeta>()
477476
);
478477
// tidy-alphabetical-end
479478
}

compiler/rustc_parse/src/parser/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ use rustc_errors::{
3636
use rustc_session::parse::ParseSess;
3737
use rustc_span::source_map::{Span, DUMMY_SP};
3838
use rustc_span::symbol::{kw, sym, Ident, Symbol};
39-
use std::alloc::{Allocator, Global};
4039
use std::ops::Range;
4140
use std::{cmp, mem, slice};
4241
use thin_vec::ThinVec;
@@ -168,7 +167,7 @@ pub struct Parser<'a> {
168167
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
169168
rustc_data_structures::static_assert_size!(
170169
Parser<'_>,
171-
288 + 4 * mem::size_of::<<Global as Allocator>::CoAllocMeta>()
170+
288 + 4 * mem::size_of::<<std::alloc::Global as std::alloc::Allocator>::CoAllocMeta>()
172171
);
173172

174173
/// Stores span information about a closure.

compiler/rustc_trait_selection/src/traits/fulfill.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use crate::infer::{InferCtxt, TyOrConstInferVar};
2-
use core::mem;
32
// use rustc_data_structures::fx::FxHashMap;
43
use rustc_data_structures::obligation_forest::ProcessResult;
54
use rustc_data_structures::obligation_forest::{Error, ForestObligation, Outcome};
@@ -12,7 +11,6 @@ use rustc_middle::ty::abstract_const::NotConstEvaluatable;
1211
use rustc_middle::ty::error::{ExpectedFound, TypeError};
1312
use rustc_middle::ty::subst::SubstsRef;
1413
use rustc_middle::ty::{self, Binder, Const, TypeVisitableExt};
15-
use std::alloc::{Allocator, Global};
1614
use std::marker::PhantomData;
1715

1816
use super::const_evaluatable;
@@ -83,7 +81,7 @@ pub struct PendingPredicateObligation<'tcx> {
8381
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
8482
static_assert_size!(
8583
PendingPredicateObligation<'_>,
86-
72 + mem::size_of::<<Global as Allocator>::CoAllocMeta>()
84+
72 + std::mem::size_of::<<std::alloc::Global as std::alloc::Allocator>::CoAllocMeta>()
8785
);
8886

8987
impl<'a, 'tcx> FulfillmentContext<'tcx> {

library/alloc/src/collections/btree/node.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ struct LeafNode<K, V> {
8080
}
8181

8282
/// @FIXME Remove once we remove leaf_node_capacity!() workaround for https://github.com/rust-lang/rust/issues/108751
83-
#[test]
83+
/// This should be in #[test], but that would mean having it in a separate file (as per `x test tidy --bless`) - too complicated for this workaround.
8484
#[allow(dead_code)]
8585
fn assert_leaf_node_capacity() {
8686
fn leaf_node() -> LeafNode<char, bool> {
@@ -130,7 +130,7 @@ struct InternalNode<K, V> {
130130
}
131131

132132
/// @FIXME Remove once we remove internal_node_capacity!() workaround for https://github.com/rust-lang/rust/issues/108751
133-
#[test]
133+
/// This should be in #[test], but that would mean having it in a separate file (as per `x test tidy --bless`) - too complicated for this workaround.
134134
#[allow(dead_code)]
135135
fn assert_internal_node_capacity() {
136136
fn internal_node() -> InternalNode<char, bool> {

src/librustdoc/clean/types.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
use std::alloc::GlobalCoAllocMeta;
21
use std::cell::RefCell;
32
use std::default::Default;
43
use std::hash::Hash;
5-
use std::mem;
64
use std::path::PathBuf;
75
use std::rc::Rc;
86
use std::sync::Arc;
@@ -2399,16 +2397,19 @@ impl SubstParam {
23992397
mod size_asserts {
24002398
use super::*;
24012399
use rustc_data_structures::static_assert_size;
2400+
#[allow(dead_code)]
2401+
const GLOBAL_CO_ALLOC_META_SIZE: usize =
2402+
std::mem::size_of::<<std::alloc::Global as std::alloc::Allocator>::CoAllocMeta>();
24022403
// tidy-alphabetical-start
24032404
static_assert_size!(Crate, 64); // frequently moved by-value
24042405
static_assert_size!(DocFragment, 32);
2405-
static_assert_size!(GenericArg, 32 + mem::size_of::<GlobalCoAllocMeta>());
2406+
static_assert_size!(GenericArg, 32 + GLOBAL_CO_ALLOC_META_SIZE);
24062407
static_assert_size!(GenericArgs, 32);
2407-
static_assert_size!(GenericParamDef, 56 + mem::size_of::<GlobalCoAllocMeta>());
2408+
static_assert_size!(GenericParamDef, 56 + GLOBAL_CO_ALLOC_META_SIZE);
24082409
static_assert_size!(Generics, 16);
24092410
static_assert_size!(Item, 56);
2410-
static_assert_size!(ItemKind, 64 + mem::size_of::<GlobalCoAllocMeta>());
2411+
static_assert_size!(ItemKind, 64 + GLOBAL_CO_ALLOC_META_SIZE);
24112412
static_assert_size!(PathSegment, 40);
2412-
static_assert_size!(Type, 32 + mem::size_of::<GlobalCoAllocMeta>());
2413+
static_assert_size!(Type, 32 + GLOBAL_CO_ALLOC_META_SIZE);
24132414
// tidy-alphabetical-end
24142415
}

src/librustdoc/html/render/context.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
use std::alloc::GlobalCoAllocMeta;
21
use std::cell::RefCell;
32
use std::collections::BTreeMap;
43
use std::io;
5-
use std::mem;
64
use std::path::{Path, PathBuf};
75
use std::rc::Rc;
86
use std::sync::mpsc::{channel, Receiver};
@@ -81,7 +79,7 @@ pub(crate) struct Context<'tcx> {
8179
#[cfg(all(not(windows), target_arch = "x86_64", target_pointer_width = "64"))]
8280
rustc_data_structures::static_assert_size!(
8381
Context<'_>,
84-
160 + 2 * mem::size_of::<GlobalCoAllocMeta>()
82+
160 + 2 * std::mem::size_of::<<std::alloc::Global as std::alloc::Allocator>::CoAllocMeta>()
8583
);
8684

8785
/// Shared mutable state used in [`Context`] and elsewhere.

src/librustdoc/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
html_root_url = "https://doc.rust-lang.org/nightly/",
33
html_playground_url = "https://play.rust-lang.org/"
44
)]
5+
#![feature(allocator_api)]
56
#![feature(rustc_private)]
67
#![feature(array_methods)]
78
#![feature(assert_matches)]

0 commit comments

Comments
 (0)