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. --- compiler/rustc_middle/src/mir/syntax.rs | 29 ++++++++++++----------------- compiler/rustc_middle/src/thir.rs | 15 +++++++++++---- 2 files changed, 23 insertions(+), 21 deletions(-) (limited to 'compiler/rustc_middle/src') diff --git a/compiler/rustc_middle/src/mir/syntax.rs b/compiler/rustc_middle/src/mir/syntax.rs index 510316c778b..edc072aac8e 100644 --- a/compiler/rustc_middle/src/mir/syntax.rs +++ b/compiler/rustc_middle/src/mir/syntax.rs @@ -796,9 +796,6 @@ pub struct Place<'tcx> { pub projection: &'tcx List>, } -#[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(TyEncodable, TyDecodable, HashStable)] pub enum ProjectionElem { @@ -862,11 +859,6 @@ pub enum ProjectionElem { /// and the index is a local. pub type PlaceElem<'tcx> = ProjectionElem>; -// 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 @@ -909,9 +901,6 @@ pub enum Operand<'tcx> { Constant(Box>), } -#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))] -static_assert_size!(Operand<'_>, 24); - /////////////////////////////////////////////////////////////////////////// // Rvalues @@ -1063,9 +1052,6 @@ pub enum Rvalue<'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)] pub enum CastKind { /// 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), } -#[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)] pub enum NullOp { /// Returns the size of a value of that type @@ -1165,3 +1148,15 @@ pub enum BinOp { /// The `ptr.offset` operator 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); +} diff --git a/compiler/rustc_middle/src/thir.rs b/compiler/rustc_middle/src/thir.rs index 36db8d04918..617ec078dcb 100644 --- a/compiler/rustc_middle/src/thir.rs +++ b/compiler/rustc_middle/src/thir.rs @@ -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(TypeFoldable, TypeVisitable)] 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); +} -- cgit 1.4.1-3-g733a5