Improve size assertions.

- For any file with four or more size assertions, move them into a
  separate module (as is already done for `hir.rs`).
- Add some more for AST nodes and THIR nodes.
- Put the `hir.rs` ones in alphabetical order.
This commit is contained in:
Nicholas Nethercote 2022-07-31 06:57:53 +10:00
parent 038f9e6bef
commit 9037ebba0c
7 changed files with 100 additions and 113 deletions

View File

@ -1111,10 +1111,6 @@ pub struct Expr {
pub tokens: Option<LazyTokenStream>, pub tokens: Option<LazyTokenStream>,
} }
// `Expr` is used a lot. Make sure it doesn't unintentionally get bigger.
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
rustc_data_structures::static_assert_size!(Expr, 104);
impl Expr { impl Expr {
/// Returns `true` if this expression would be valid somewhere that expects a value; /// Returns `true` if this expression would be valid somewhere that expects a value;
/// for example, an `if` condition. /// for example, an `if` condition.
@ -2883,9 +2879,6 @@ pub enum ItemKind {
MacroDef(MacroDef), MacroDef(MacroDef),
} }
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
rustc_data_structures::static_assert_size!(ItemKind, 112);
impl ItemKind { impl ItemKind {
pub fn article(&self) -> &str { pub fn article(&self) -> &str {
use ItemKind::*; use ItemKind::*;
@ -2957,9 +2950,6 @@ pub enum AssocItemKind {
MacCall(MacCall), MacCall(MacCall),
} }
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
rustc_data_structures::static_assert_size!(AssocItemKind, 72);
impl AssocItemKind { impl AssocItemKind {
pub fn defaultness(&self) -> Defaultness { pub fn defaultness(&self) -> Defaultness {
match *self { match *self {
@ -3009,9 +2999,6 @@ pub enum ForeignItemKind {
MacCall(MacCall), MacCall(MacCall),
} }
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
rustc_data_structures::static_assert_size!(ForeignItemKind, 72);
impl From<ForeignItemKind> for ItemKind { impl From<ForeignItemKind> for ItemKind {
fn from(foreign_item_kind: ForeignItemKind) -> ItemKind { fn from(foreign_item_kind: ForeignItemKind) -> ItemKind {
match foreign_item_kind { match foreign_item_kind {
@ -3038,3 +3025,27 @@ impl TryFrom<ItemKind> for ForeignItemKind {
} }
pub type ForeignItem = Item<ForeignItemKind>; pub type ForeignItem = Item<ForeignItemKind>;
// Some nodes are used a lot. Make sure they don't unintentionally get bigger.
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
mod size_asserts {
use super::*;
// These are in alphabetical order, which is easy to maintain.
rustc_data_structures::static_assert_size!(AssocItemKind, 72);
rustc_data_structures::static_assert_size!(Attribute, 152);
rustc_data_structures::static_assert_size!(Block, 48);
rustc_data_structures::static_assert_size!(Expr, 104);
rustc_data_structures::static_assert_size!(Fn, 192);
rustc_data_structures::static_assert_size!(ForeignItemKind, 72);
rustc_data_structures::static_assert_size!(GenericBound, 88);
rustc_data_structures::static_assert_size!(Generics, 72);
rustc_data_structures::static_assert_size!(Impl, 200);
rustc_data_structures::static_assert_size!(Item, 200);
rustc_data_structures::static_assert_size!(ItemKind, 112);
rustc_data_structures::static_assert_size!(Lit, 48);
rustc_data_structures::static_assert_size!(Pat, 120);
rustc_data_structures::static_assert_size!(Path, 40);
rustc_data_structures::static_assert_size!(PathSegment, 24);
rustc_data_structures::static_assert_size!(Stmt, 32);
rustc_data_structures::static_assert_size!(Ty, 96);
}

View File

@ -37,9 +37,6 @@ pub enum Immediate<Prov: Provenance = AllocId> {
Uninit, Uninit,
} }
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
rustc_data_structures::static_assert_size!(Immediate, 56);
impl<Prov: Provenance> From<ScalarMaybeUninit<Prov>> for Immediate<Prov> { impl<Prov: Provenance> From<ScalarMaybeUninit<Prov>> for Immediate<Prov> {
#[inline(always)] #[inline(always)]
fn from(val: ScalarMaybeUninit<Prov>) -> Self { fn from(val: ScalarMaybeUninit<Prov>) -> Self {
@ -117,9 +114,6 @@ pub struct ImmTy<'tcx, Prov: Provenance = AllocId> {
pub layout: TyAndLayout<'tcx>, pub layout: TyAndLayout<'tcx>,
} }
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
rustc_data_structures::static_assert_size!(ImmTy<'_>, 72);
impl<Prov: Provenance> std::fmt::Display for ImmTy<'_, Prov> { impl<Prov: Provenance> std::fmt::Display for ImmTy<'_, Prov> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
/// Helper function for printing a scalar to a FmtPrinter /// Helper function for printing a scalar to a FmtPrinter
@ -187,9 +181,6 @@ pub enum Operand<Prov: Provenance = AllocId> {
Indirect(MemPlace<Prov>), Indirect(MemPlace<Prov>),
} }
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
rustc_data_structures::static_assert_size!(Operand, 64);
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub struct OpTy<'tcx, Prov: Provenance = AllocId> { pub struct OpTy<'tcx, Prov: Provenance = AllocId> {
op: Operand<Prov>, // Keep this private; it helps enforce invariants. op: Operand<Prov>, // Keep this private; it helps enforce invariants.
@ -204,9 +195,6 @@ pub struct OpTy<'tcx, Prov: Provenance = AllocId> {
pub align: Option<Align>, pub align: Option<Align>,
} }
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
rustc_data_structures::static_assert_size!(OpTy<'_>, 88);
impl<'tcx, Prov: Provenance> std::ops::Deref for OpTy<'tcx, Prov> { impl<'tcx, Prov: Provenance> std::ops::Deref for OpTy<'tcx, Prov> {
type Target = Operand<Prov>; type Target = Operand<Prov>;
#[inline(always)] #[inline(always)]
@ -830,3 +818,14 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
}) })
} }
} }
// Some nodes are used a lot. Make sure they don't unintentionally get bigger.
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
mod size_asserts {
use super::*;
// These are in alphabetical order, which is easy to maintain.
rustc_data_structures::static_assert_size!(Immediate, 56);
rustc_data_structures::static_assert_size!(ImmTy<'_>, 72);
rustc_data_structures::static_assert_size!(Operand, 64);
rustc_data_structures::static_assert_size!(OpTy<'_>, 88);
}

View File

@ -25,9 +25,6 @@ pub enum MemPlaceMeta<Prov: Provenance = AllocId> {
None, None,
} }
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
rustc_data_structures::static_assert_size!(MemPlaceMeta, 24);
impl<Prov: Provenance> MemPlaceMeta<Prov> { impl<Prov: Provenance> MemPlaceMeta<Prov> {
pub fn unwrap_meta(self) -> Scalar<Prov> { pub fn unwrap_meta(self) -> Scalar<Prov> {
match self { match self {
@ -56,9 +53,6 @@ pub struct MemPlace<Prov: Provenance = AllocId> {
pub meta: MemPlaceMeta<Prov>, pub meta: MemPlaceMeta<Prov>,
} }
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
rustc_data_structures::static_assert_size!(MemPlace, 40);
/// A MemPlace with its layout. Constructing it is only possible in this module. /// A MemPlace with its layout. Constructing it is only possible in this module.
#[derive(Copy, Clone, Hash, Eq, PartialEq, Debug)] #[derive(Copy, Clone, Hash, Eq, PartialEq, Debug)]
pub struct MPlaceTy<'tcx, Prov: Provenance = AllocId> { pub struct MPlaceTy<'tcx, Prov: Provenance = AllocId> {
@ -71,9 +65,6 @@ pub struct MPlaceTy<'tcx, Prov: Provenance = AllocId> {
pub align: Align, pub align: Align,
} }
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
rustc_data_structures::static_assert_size!(MPlaceTy<'_>, 64);
#[derive(Copy, Clone, Debug)] #[derive(Copy, Clone, Debug)]
pub enum Place<Prov: Provenance = AllocId> { pub enum Place<Prov: Provenance = AllocId> {
/// A place referring to a value allocated in the `Memory` system. /// A place referring to a value allocated in the `Memory` system.
@ -84,9 +75,6 @@ pub enum Place<Prov: Provenance = AllocId> {
Local { frame: usize, local: mir::Local }, Local { frame: usize, local: mir::Local },
} }
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
rustc_data_structures::static_assert_size!(Place, 48);
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub struct PlaceTy<'tcx, Prov: Provenance = AllocId> { pub struct PlaceTy<'tcx, Prov: Provenance = AllocId> {
place: Place<Prov>, // Keep this private; it helps enforce invariants. place: Place<Prov>, // Keep this private; it helps enforce invariants.
@ -98,9 +86,6 @@ pub struct PlaceTy<'tcx, Prov: Provenance = AllocId> {
pub align: Align, pub align: Align,
} }
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
rustc_data_structures::static_assert_size!(PlaceTy<'_>, 72);
impl<'tcx, Prov: Provenance> std::ops::Deref for PlaceTy<'tcx, Prov> { impl<'tcx, Prov: Provenance> std::ops::Deref for PlaceTy<'tcx, Prov> {
type Target = Place<Prov>; type Target = Place<Prov>;
#[inline(always)] #[inline(always)]
@ -901,3 +886,15 @@ where
Ok(mplace) Ok(mplace)
} }
} }
// Some nodes are used a lot. Make sure they don't unintentionally get bigger.
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
mod size_asserts {
use super::*;
// These are in alphabetical order, which is easy to maintain.
rustc_data_structures::static_assert_size!(MemPlaceMeta, 24);
rustc_data_structures::static_assert_size!(MemPlace, 40);
rustc_data_structures::static_assert_size!(MPlaceTy<'_>, 64);
rustc_data_structures::static_assert_size!(Place, 48);
rustc_data_structures::static_assert_size!(PlaceTy<'_>, 72);
}

View File

@ -3489,17 +3489,18 @@ impl<'hir> Node<'hir> {
// Some nodes are used a lot. Make sure they don't unintentionally get bigger. // Some nodes are used a lot. Make sure they don't unintentionally get bigger.
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))] #[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
mod size_asserts { mod size_asserts {
rustc_data_structures::static_assert_size!(super::Block<'static>, 48); use super::*;
rustc_data_structures::static_assert_size!(super::Expr<'static>, 56); // These are in alphabetical order, which is easy to maintain.
rustc_data_structures::static_assert_size!(super::Pat<'static>, 88); rustc_data_structures::static_assert_size!(Block<'static>, 48);
rustc_data_structures::static_assert_size!(super::QPath<'static>, 24); rustc_data_structures::static_assert_size!(Expr<'static>, 56);
rustc_data_structures::static_assert_size!(super::Ty<'static>, 72); rustc_data_structures::static_assert_size!(ForeignItem<'static>, 72);
rustc_data_structures::static_assert_size!(super::GenericBound<'_>, 48); rustc_data_structures::static_assert_size!(GenericBound<'_>, 48);
rustc_data_structures::static_assert_size!(super::Generics<'static>, 56); rustc_data_structures::static_assert_size!(Generics<'static>, 56);
rustc_data_structures::static_assert_size!(super::Impl<'static>, 80); rustc_data_structures::static_assert_size!(ImplItem<'static>, 80);
rustc_data_structures::static_assert_size!(Impl<'static>, 80);
rustc_data_structures::static_assert_size!(super::Item<'static>, 80); rustc_data_structures::static_assert_size!(Item<'static>, 80);
rustc_data_structures::static_assert_size!(super::TraitItem<'static>, 88); rustc_data_structures::static_assert_size!(Pat<'static>, 88);
rustc_data_structures::static_assert_size!(super::ImplItem<'static>, 80); rustc_data_structures::static_assert_size!(QPath<'static>, 24);
rustc_data_structures::static_assert_size!(super::ForeignItem<'static>, 72); rustc_data_structures::static_assert_size!(TraitItem<'static>, 88);
rustc_data_structures::static_assert_size!(Ty<'static>, 72);
} }

View File

@ -796,9 +796,6 @@ pub struct Place<'tcx> {
pub projection: &'tcx List<PlaceElem<'tcx>>, pub projection: &'tcx List<PlaceElem<'tcx>>,
} }
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
static_assert_size!(Place<'_>, 16);
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] #[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[derive(TyEncodable, TyDecodable, HashStable)] #[derive(TyEncodable, TyDecodable, HashStable)]
pub enum ProjectionElem<V, T> { pub enum ProjectionElem<V, T> {
@ -862,11 +859,6 @@ pub enum ProjectionElem<V, T> {
/// and the index is a local. /// and the index is a local.
pub type PlaceElem<'tcx> = ProjectionElem<Local, Ty<'tcx>>; pub type PlaceElem<'tcx> = ProjectionElem<Local, Ty<'tcx>>;
// This type is fairly frequently used, so we shouldn't unintentionally increase
// its size.
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
static_assert_size!(PlaceElem<'_>, 24);
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
// Operands // Operands
@ -909,9 +901,6 @@ pub enum Operand<'tcx> {
Constant(Box<Constant<'tcx>>), Constant(Box<Constant<'tcx>>),
} }
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
static_assert_size!(Operand<'_>, 24);
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
// Rvalues // Rvalues
@ -1063,9 +1052,6 @@ pub enum Rvalue<'tcx> {
CopyForDeref(Place<'tcx>), CopyForDeref(Place<'tcx>),
} }
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
static_assert_size!(Rvalue<'_>, 40);
#[derive(Clone, Copy, Debug, PartialEq, Eq, TyEncodable, TyDecodable, Hash, HashStable)] #[derive(Clone, Copy, Debug, PartialEq, Eq, TyEncodable, TyDecodable, Hash, HashStable)]
pub enum CastKind { pub enum CastKind {
/// An exposing pointer to address cast. A cast between a pointer and an integer type, or /// An exposing pointer to address cast. A cast between a pointer and an integer type, or
@ -1099,9 +1085,6 @@ pub enum AggregateKind<'tcx> {
Generator(DefId, SubstsRef<'tcx>, hir::Movability), Generator(DefId, SubstsRef<'tcx>, hir::Movability),
} }
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
static_assert_size!(AggregateKind<'_>, 48);
#[derive(Copy, Clone, Debug, PartialEq, Eq, TyEncodable, TyDecodable, Hash, HashStable)] #[derive(Copy, Clone, Debug, PartialEq, Eq, TyEncodable, TyDecodable, Hash, HashStable)]
pub enum NullOp { pub enum NullOp {
/// Returns the size of a value of that type /// Returns the size of a value of that type
@ -1165,3 +1148,15 @@ pub enum BinOp {
/// The `ptr.offset` operator /// The `ptr.offset` operator
Offset, Offset,
} }
// Some nodes are used a lot. Make sure they don't unintentionally get bigger.
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
mod size_asserts {
use super::*;
// These are in alphabetical order, which is easy to maintain.
static_assert_size!(AggregateKind<'_>, 48);
static_assert_size!(Operand<'_>, 24);
static_assert_size!(Place<'_>, 16);
static_assert_size!(PlaceElem<'_>, 24);
static_assert_size!(Rvalue<'_>, 40);
}

View File

@ -189,10 +189,6 @@ pub enum StmtKind<'tcx> {
}, },
} }
// `Expr` is used a lot. Make sure it doesn't unintentionally get bigger.
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
rustc_data_structures::static_assert_size!(Expr<'_>, 104);
#[derive(Clone, Debug, Copy, PartialEq, Eq, Hash, HashStable, TyEncodable, TyDecodable)] #[derive(Clone, Debug, Copy, PartialEq, Eq, Hash, HashStable, TyEncodable, TyDecodable)]
#[derive(TypeFoldable, TypeVisitable)] #[derive(TypeFoldable, TypeVisitable)]
pub struct LocalVarId(pub hir::HirId); pub struct LocalVarId(pub hir::HirId);
@ -811,3 +807,14 @@ impl<'tcx> fmt::Display for Pat<'tcx> {
} }
} }
} }
// Some nodes are used a lot. Make sure they don't unintentionally get bigger.
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
mod size_asserts {
use super::*;
// These are in alphabetical order, which is easy to maintain.
rustc_data_structures::static_assert_size!(Block, 56);
rustc_data_structures::static_assert_size!(Expr<'_>, 104);
rustc_data_structures::static_assert_size!(Pat<'_>, 24);
rustc_data_structures::static_assert_size!(Stmt<'_>, 120);
}

View File

@ -122,10 +122,6 @@ pub(crate) struct Crate {
pub(crate) external_traits: Rc<RefCell<FxHashMap<DefId, TraitWithExtraInfo>>>, pub(crate) external_traits: Rc<RefCell<FxHashMap<DefId, TraitWithExtraInfo>>>,
} }
// `Crate` is frequently moved by-value. Make sure it doesn't unintentionally get bigger.
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
rustc_data_structures::static_assert_size!(Crate, 72);
impl Crate { impl Crate {
pub(crate) fn name(&self, tcx: TyCtxt<'_>) -> Symbol { pub(crate) fn name(&self, tcx: TyCtxt<'_>) -> Symbol {
ExternalCrate::LOCAL.name(tcx) ExternalCrate::LOCAL.name(tcx)
@ -389,10 +385,6 @@ impl fmt::Debug for Item {
} }
} }
// `Item` is used a lot. Make sure it doesn't unintentionally get bigger.
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
rustc_data_structures::static_assert_size!(Item, 56);
pub(crate) fn rustc_span(def_id: DefId, tcx: TyCtxt<'_>) -> Span { pub(crate) fn rustc_span(def_id: DefId, tcx: TyCtxt<'_>) -> Span {
Span::new(def_id.as_local().map_or_else( Span::new(def_id.as_local().map_or_else(
|| tcx.def_span(def_id), || tcx.def_span(def_id),
@ -771,10 +763,6 @@ pub(crate) enum ItemKind {
KeywordItem, KeywordItem,
} }
// `ItemKind` is an enum and large variants can bloat up memory usage even for smaller ones
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
rustc_data_structures::static_assert_size!(ItemKind, 112);
impl ItemKind { impl ItemKind {
/// Some items contain others such as structs (for their fields) and Enums /// Some items contain others such as structs (for their fields) and Enums
/// (for their variants). This method returns those contained items. /// (for their variants). This method returns those contained items.
@ -994,10 +982,6 @@ pub(crate) struct DocFragment {
pub(crate) indent: usize, pub(crate) indent: usize,
} }
// `DocFragment` is used a lot. Make sure it doesn't unintentionally get bigger.
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
rustc_data_structures::static_assert_size!(DocFragment, 32);
#[derive(Clone, Copy, PartialEq, Eq, Debug)] #[derive(Clone, Copy, PartialEq, Eq, Debug)]
pub(crate) enum DocFragmentKind { pub(crate) enum DocFragmentKind {
/// A doc fragment created from a `///` or `//!` doc comment. /// A doc fragment created from a `///` or `//!` doc comment.
@ -1382,10 +1366,6 @@ pub(crate) struct GenericParamDef {
pub(crate) kind: GenericParamDefKind, pub(crate) kind: GenericParamDefKind,
} }
// `GenericParamDef` is used in many places. Make sure it doesn't unintentionally get bigger.
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
rustc_data_structures::static_assert_size!(GenericParamDef, 56);
impl GenericParamDef { impl GenericParamDef {
pub(crate) fn is_synthetic_type_param(&self) -> bool { pub(crate) fn is_synthetic_type_param(&self) -> bool {
match self.kind { match self.kind {
@ -1590,10 +1570,6 @@ pub(crate) enum Type {
ImplTrait(Vec<GenericBound>), ImplTrait(Vec<GenericBound>),
} }
// `Type` is used a lot. Make sure it doesn't unintentionally get bigger.
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
rustc_data_structures::static_assert_size!(Type, 72);
impl Type { impl Type {
/// When comparing types for equality, it can help to ignore `&` wrapping. /// When comparing types for equality, it can help to ignore `&` wrapping.
pub(crate) fn without_borrowed_ref(&self) -> &Type { pub(crate) fn without_borrowed_ref(&self) -> &Type {
@ -2230,33 +2206,18 @@ pub(crate) enum GenericArg {
Infer, Infer,
} }
// `GenericArg` can occur many times in a single `Path`, so make sure it
// doesn't increase in size unexpectedly.
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
rustc_data_structures::static_assert_size!(GenericArg, 80);
#[derive(Clone, PartialEq, Eq, Debug, Hash)] #[derive(Clone, PartialEq, Eq, Debug, Hash)]
pub(crate) enum GenericArgs { pub(crate) enum GenericArgs {
AngleBracketed { args: Box<[GenericArg]>, bindings: ThinVec<TypeBinding> }, AngleBracketed { args: Box<[GenericArg]>, bindings: ThinVec<TypeBinding> },
Parenthesized { inputs: Box<[Type]>, output: Option<Box<Type>> }, Parenthesized { inputs: Box<[Type]>, output: Option<Box<Type>> },
} }
// `GenericArgs` is in every `PathSegment`, so its size can significantly
// affect rustdoc's memory usage.
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
rustc_data_structures::static_assert_size!(GenericArgs, 32);
#[derive(Clone, PartialEq, Eq, Debug, Hash)] #[derive(Clone, PartialEq, Eq, Debug, Hash)]
pub(crate) struct PathSegment { pub(crate) struct PathSegment {
pub(crate) name: Symbol, pub(crate) name: Symbol,
pub(crate) args: GenericArgs, pub(crate) args: GenericArgs,
} }
// `PathSegment` usually occurs multiple times in every `Path`, so its size can
// significantly affect rustdoc's memory usage.
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
rustc_data_structures::static_assert_size!(PathSegment, 40);
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub(crate) struct Typedef { pub(crate) struct Typedef {
pub(crate) type_: Type, pub(crate) type_: Type,
@ -2527,3 +2488,19 @@ impl SubstParam {
if let Self::Lifetime(lt) = self { Some(lt) } else { None } if let Self::Lifetime(lt) = self { Some(lt) } else { None }
} }
} }
// Some nodes are used a lot. Make sure they don't unintentionally get bigger.
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
mod size_asserts {
use super::*;
// These are in alphabetical order, which is easy to maintain.
rustc_data_structures::static_assert_size!(Crate, 72); // frequently moved by-value
rustc_data_structures::static_assert_size!(DocFragment, 32);
rustc_data_structures::static_assert_size!(GenericArg, 80);
rustc_data_structures::static_assert_size!(GenericArgs, 32);
rustc_data_structures::static_assert_size!(GenericParamDef, 56);
rustc_data_structures::static_assert_size!(Item, 56);
rustc_data_structures::static_assert_size!(ItemKind, 112);
rustc_data_structures::static_assert_size!(PathSegment, 40);
rustc_data_structures::static_assert_size!(Type, 72);
}