Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve size assertions. #100003

Merged
merged 1 commit into from
Aug 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 24 additions & 13 deletions compiler/rustc_ast/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1111,10 +1111,6 @@ pub struct Expr {
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 {
/// Returns `true` if this expression would be valid somewhere that expects a value;
/// for example, an `if` condition.
Expand Down Expand Up @@ -2883,9 +2879,6 @@ pub enum ItemKind {
MacroDef(MacroDef),
}

#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
rustc_data_structures::static_assert_size!(ItemKind, 112);

impl ItemKind {
pub fn article(&self) -> &str {
use ItemKind::*;
Expand Down Expand Up @@ -2957,9 +2950,6 @@ pub enum AssocItemKind {
MacCall(MacCall),
}

#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
rustc_data_structures::static_assert_size!(AssocItemKind, 72);

impl AssocItemKind {
pub fn defaultness(&self) -> Defaultness {
match *self {
Expand Down Expand Up @@ -3009,9 +2999,6 @@ pub enum ForeignItemKind {
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 {
fn from(foreign_item_kind: ForeignItemKind) -> ItemKind {
match foreign_item_kind {
Expand All @@ -3038,3 +3025,27 @@ impl TryFrom<ItemKind> for 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);
}
23 changes: 11 additions & 12 deletions compiler/rustc_const_eval/src/interpret/operand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ pub enum Immediate<Prov: Provenance = AllocId> {
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> {
#[inline(always)]
fn from(val: ScalarMaybeUninit<Prov>) -> Self {
Expand Down Expand Up @@ -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<Prov: Provenance> 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
Expand Down Expand Up @@ -187,9 +181,6 @@ pub enum Operand<Prov: Provenance = AllocId> {
Indirect(MemPlace<Prov>),
}

#[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<Prov>, // Keep this private; it helps enforce invariants.
Expand All @@ -204,9 +195,6 @@ pub struct OpTy<'tcx, Prov: Provenance = AllocId> {
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> {
type Target = Operand<Prov>;
#[inline(always)]
Expand Down Expand Up @@ -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);
}
27 changes: 12 additions & 15 deletions compiler/rustc_const_eval/src/interpret/place.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ pub enum MemPlaceMeta<Prov: Provenance = AllocId> {
None,
}

#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
rustc_data_structures::static_assert_size!(MemPlaceMeta, 24);

impl<Prov: Provenance> MemPlaceMeta<Prov> {
pub fn unwrap_meta(self) -> Scalar<Prov> {
match self {
Expand Down Expand Up @@ -56,9 +53,6 @@ pub struct MemPlace<Prov: Provenance = AllocId> {
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.
#[derive(Copy, Clone, Hash, Eq, PartialEq, Debug)]
pub struct MPlaceTy<'tcx, Prov: Provenance = AllocId> {
Expand All @@ -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<Prov: Provenance = AllocId> {
/// A place referring to a value allocated in the `Memory` system.
Expand All @@ -84,9 +75,6 @@ pub enum Place<Prov: Provenance = AllocId> {
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<Prov>, // Keep this private; it helps enforce invariants.
Expand All @@ -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<Prov>;
#[inline(always)]
Expand Down Expand Up @@ -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);
}
27 changes: 14 additions & 13 deletions compiler/rustc_hir/src/hir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3489,17 +3489,18 @@ impl<'hir> Node<'hir> {
// 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 {
rustc_data_structures::static_assert_size!(super::Block<'static>, 48);
rustc_data_structures::static_assert_size!(super::Expr<'static>, 56);
rustc_data_structures::static_assert_size!(super::Pat<'static>, 88);
rustc_data_structures::static_assert_size!(super::QPath<'static>, 24);
rustc_data_structures::static_assert_size!(super::Ty<'static>, 72);
rustc_data_structures::static_assert_size!(super::GenericBound<'_>, 48);
rustc_data_structures::static_assert_size!(super::Generics<'static>, 56);
rustc_data_structures::static_assert_size!(super::Impl<'static>, 80);

rustc_data_structures::static_assert_size!(super::Item<'static>, 80);
rustc_data_structures::static_assert_size!(super::TraitItem<'static>, 88);
rustc_data_structures::static_assert_size!(super::ImplItem<'static>, 80);
rustc_data_structures::static_assert_size!(super::ForeignItem<'static>, 72);
use super::*;
// These are in alphabetical order, which is easy to maintain.
rustc_data_structures::static_assert_size!(Block<'static>, 48);
rustc_data_structures::static_assert_size!(Expr<'static>, 56);
rustc_data_structures::static_assert_size!(ForeignItem<'static>, 72);
rustc_data_structures::static_assert_size!(GenericBound<'_>, 48);
rustc_data_structures::static_assert_size!(Generics<'static>, 56);
rustc_data_structures::static_assert_size!(ImplItem<'static>, 80);
rustc_data_structures::static_assert_size!(Impl<'static>, 80);
rustc_data_structures::static_assert_size!(Item<'static>, 80);
rustc_data_structures::static_assert_size!(Pat<'static>, 88);
rustc_data_structures::static_assert_size!(QPath<'static>, 24);
rustc_data_structures::static_assert_size!(TraitItem<'static>, 88);
rustc_data_structures::static_assert_size!(Ty<'static>, 72);
}
29 changes: 12 additions & 17 deletions compiler/rustc_middle/src/mir/syntax.rs
Original file line number Diff line number Diff line change
Expand Up @@ -796,9 +796,6 @@ pub struct Place<'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(TyEncodable, TyDecodable, HashStable)]
pub enum ProjectionElem<V, T> {
Expand Down Expand Up @@ -862,11 +859,6 @@ pub enum ProjectionElem<V, T> {
/// and the index is a local.
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

Expand Down Expand Up @@ -909,9 +901,6 @@ pub enum Operand<'tcx> {
Constant(Box<Constant<'tcx>>),
}

#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
static_assert_size!(Operand<'_>, 24);

///////////////////////////////////////////////////////////////////////////
// Rvalues

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
15 changes: 11 additions & 4 deletions compiler/rustc_middle/src/thir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
Loading