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_const_eval/src/interpret/operand.rs | 23 +++++++++--------- compiler/rustc_const_eval/src/interpret/place.rs | 27 ++++++++++------------ 2 files changed, 23 insertions(+), 27 deletions(-) (limited to 'compiler/rustc_const_eval/src') diff --git a/compiler/rustc_const_eval/src/interpret/operand.rs b/compiler/rustc_const_eval/src/interpret/operand.rs index de284bd3bae..94ba62c160c 100644 --- a/compiler/rustc_const_eval/src/interpret/operand.rs +++ b/compiler/rustc_const_eval/src/interpret/operand.rs @@ -37,9 +37,6 @@ pub enum Immediate { Uninit, } -#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))] -rustc_data_structures::static_assert_size!(Immediate, 56); - impl From> for Immediate { #[inline(always)] fn from(val: ScalarMaybeUninit) -> Self { @@ -117,9 +114,6 @@ pub struct ImmTy<'tcx, Prov: Provenance = AllocId> { pub layout: TyAndLayout<'tcx>, } -#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))] -rustc_data_structures::static_assert_size!(ImmTy<'_>, 72); - impl std::fmt::Display for ImmTy<'_, Prov> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { /// Helper function for printing a scalar to a FmtPrinter @@ -187,9 +181,6 @@ pub enum Operand { Indirect(MemPlace), } -#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))] -rustc_data_structures::static_assert_size!(Operand, 64); - #[derive(Clone, Debug)] pub struct OpTy<'tcx, Prov: Provenance = AllocId> { op: Operand, // Keep this private; it helps enforce invariants. @@ -204,9 +195,6 @@ pub struct OpTy<'tcx, Prov: Provenance = AllocId> { pub align: Option, } -#[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> { type Target = Operand; #[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); +} diff --git a/compiler/rustc_const_eval/src/interpret/place.rs b/compiler/rustc_const_eval/src/interpret/place.rs index 473da71a0ab..f4571a1ca3d 100644 --- a/compiler/rustc_const_eval/src/interpret/place.rs +++ b/compiler/rustc_const_eval/src/interpret/place.rs @@ -25,9 +25,6 @@ pub enum MemPlaceMeta { None, } -#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))] -rustc_data_structures::static_assert_size!(MemPlaceMeta, 24); - impl MemPlaceMeta { pub fn unwrap_meta(self) -> Scalar { match self { @@ -56,9 +53,6 @@ pub struct MemPlace { pub meta: MemPlaceMeta, } -#[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. #[derive(Copy, Clone, Hash, Eq, PartialEq, Debug)] pub struct MPlaceTy<'tcx, Prov: Provenance = AllocId> { @@ -71,9 +65,6 @@ pub struct MPlaceTy<'tcx, Prov: Provenance = AllocId> { 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)] pub enum Place { /// A place referring to a value allocated in the `Memory` system. @@ -84,9 +75,6 @@ pub enum Place { 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)] pub struct PlaceTy<'tcx, Prov: Provenance = AllocId> { place: Place, // Keep this private; it helps enforce invariants. @@ -98,9 +86,6 @@ pub struct PlaceTy<'tcx, Prov: Provenance = AllocId> { 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> { type Target = Place; #[inline(always)] @@ -901,3 +886,15 @@ where 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); +} -- cgit 1.4.1-3-g733a5