From 9037ebba0c243e5415879a2ef20736b71a453fa6 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Sun, 31 Jul 2022 06:57:53 +1000 Subject: 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. --- src/librustdoc/clean/types.rs | 55 +++++++++++++------------------------------ 1 file changed, 16 insertions(+), 39 deletions(-) (limited to 'src') diff --git a/src/librustdoc/clean/types.rs b/src/librustdoc/clean/types.rs index d022ce9696a..1a46d077f1b 100644 --- a/src/librustdoc/clean/types.rs +++ b/src/librustdoc/clean/types.rs @@ -122,10 +122,6 @@ pub(crate) struct Crate { pub(crate) external_traits: Rc>>, } -// `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 { pub(crate) fn name(&self, tcx: TyCtxt<'_>) -> Symbol { 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 { Span::new(def_id.as_local().map_or_else( || tcx.def_span(def_id), @@ -771,10 +763,6 @@ pub(crate) enum ItemKind { 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 { /// Some items contain others such as structs (for their fields) and Enums /// (for their variants). This method returns those contained items. @@ -994,10 +982,6 @@ pub(crate) struct DocFragment { 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)] pub(crate) enum DocFragmentKind { /// A doc fragment created from a `///` or `//!` doc comment. @@ -1382,10 +1366,6 @@ pub(crate) struct GenericParamDef { 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 { pub(crate) fn is_synthetic_type_param(&self) -> bool { match self.kind { @@ -1590,10 +1570,6 @@ pub(crate) enum Type { ImplTrait(Vec), } -// `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 { /// When comparing types for equality, it can help to ignore `&` wrapping. pub(crate) fn without_borrowed_ref(&self) -> &Type { @@ -2230,33 +2206,18 @@ pub(crate) enum GenericArg { 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)] pub(crate) enum GenericArgs { AngleBracketed { args: Box<[GenericArg]>, bindings: ThinVec }, Parenthesized { inputs: Box<[Type]>, output: Option> }, } -// `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)] pub(crate) struct PathSegment { pub(crate) name: Symbol, 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)] pub(crate) struct Typedef { pub(crate) type_: Type, @@ -2527,3 +2488,19 @@ impl SubstParam { 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); +} -- cgit 1.4.1-3-g733a5