Skip to content

Commit e6bb00f

Browse files
authored
Rollup merge of #100003 - nnethercote:improve-size-assertions, r=lqd
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. r? `@lqd`
2 parents 1fa02dd + 9037ebb commit e6bb00f

File tree

7 files changed

+100
-113
lines changed

7 files changed

+100
-113
lines changed

compiler/rustc_ast/src/ast.rs

+24-13
Original file line numberDiff line numberDiff line change
@@ -1111,10 +1111,6 @@ pub struct Expr {
11111111
pub tokens: Option<LazyTokenStream>,
11121112
}
11131113

1114-
// `Expr` is used a lot. Make sure it doesn't unintentionally get bigger.
1115-
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
1116-
rustc_data_structures::static_assert_size!(Expr, 104);
1117-
11181114
impl Expr {
11191115
/// Returns `true` if this expression would be valid somewhere that expects a value;
11201116
/// for example, an `if` condition.
@@ -2883,9 +2879,6 @@ pub enum ItemKind {
28832879
MacroDef(MacroDef),
28842880
}
28852881

2886-
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
2887-
rustc_data_structures::static_assert_size!(ItemKind, 112);
2888-
28892882
impl ItemKind {
28902883
pub fn article(&self) -> &str {
28912884
use ItemKind::*;
@@ -2957,9 +2950,6 @@ pub enum AssocItemKind {
29572950
MacCall(MacCall),
29582951
}
29592952

2960-
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
2961-
rustc_data_structures::static_assert_size!(AssocItemKind, 72);
2962-
29632953
impl AssocItemKind {
29642954
pub fn defaultness(&self) -> Defaultness {
29652955
match *self {
@@ -3009,9 +2999,6 @@ pub enum ForeignItemKind {
30092999
MacCall(MacCall),
30103000
}
30113001

3012-
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
3013-
rustc_data_structures::static_assert_size!(ForeignItemKind, 72);
3014-
30153002
impl From<ForeignItemKind> for ItemKind {
30163003
fn from(foreign_item_kind: ForeignItemKind) -> ItemKind {
30173004
match foreign_item_kind {
@@ -3038,3 +3025,27 @@ impl TryFrom<ItemKind> for ForeignItemKind {
30383025
}
30393026

30403027
pub type ForeignItem = Item<ForeignItemKind>;
3028+
3029+
// Some nodes are used a lot. Make sure they don't unintentionally get bigger.
3030+
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
3031+
mod size_asserts {
3032+
use super::*;
3033+
// These are in alphabetical order, which is easy to maintain.
3034+
rustc_data_structures::static_assert_size!(AssocItemKind, 72);
3035+
rustc_data_structures::static_assert_size!(Attribute, 152);
3036+
rustc_data_structures::static_assert_size!(Block, 48);
3037+
rustc_data_structures::static_assert_size!(Expr, 104);
3038+
rustc_data_structures::static_assert_size!(Fn, 192);
3039+
rustc_data_structures::static_assert_size!(ForeignItemKind, 72);
3040+
rustc_data_structures::static_assert_size!(GenericBound, 88);
3041+
rustc_data_structures::static_assert_size!(Generics, 72);
3042+
rustc_data_structures::static_assert_size!(Impl, 200);
3043+
rustc_data_structures::static_assert_size!(Item, 200);
3044+
rustc_data_structures::static_assert_size!(ItemKind, 112);
3045+
rustc_data_structures::static_assert_size!(Lit, 48);
3046+
rustc_data_structures::static_assert_size!(Pat, 120);
3047+
rustc_data_structures::static_assert_size!(Path, 40);
3048+
rustc_data_structures::static_assert_size!(PathSegment, 24);
3049+
rustc_data_structures::static_assert_size!(Stmt, 32);
3050+
rustc_data_structures::static_assert_size!(Ty, 96);
3051+
}

compiler/rustc_const_eval/src/interpret/operand.rs

+11-12
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,6 @@ pub enum Immediate<Prov: Provenance = AllocId> {
3737
Uninit,
3838
}
3939

40-
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
41-
rustc_data_structures::static_assert_size!(Immediate, 56);
42-
4340
impl<Prov: Provenance> From<ScalarMaybeUninit<Prov>> for Immediate<Prov> {
4441
#[inline(always)]
4542
fn from(val: ScalarMaybeUninit<Prov>) -> Self {
@@ -117,9 +114,6 @@ pub struct ImmTy<'tcx, Prov: Provenance = AllocId> {
117114
pub layout: TyAndLayout<'tcx>,
118115
}
119116

120-
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
121-
rustc_data_structures::static_assert_size!(ImmTy<'_>, 72);
122-
123117
impl<Prov: Provenance> std::fmt::Display for ImmTy<'_, Prov> {
124118
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
125119
/// Helper function for printing a scalar to a FmtPrinter
@@ -187,9 +181,6 @@ pub enum Operand<Prov: Provenance = AllocId> {
187181
Indirect(MemPlace<Prov>),
188182
}
189183

190-
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
191-
rustc_data_structures::static_assert_size!(Operand, 64);
192-
193184
#[derive(Clone, Debug)]
194185
pub struct OpTy<'tcx, Prov: Provenance = AllocId> {
195186
op: Operand<Prov>, // Keep this private; it helps enforce invariants.
@@ -204,9 +195,6 @@ pub struct OpTy<'tcx, Prov: Provenance = AllocId> {
204195
pub align: Option<Align>,
205196
}
206197

207-
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
208-
rustc_data_structures::static_assert_size!(OpTy<'_>, 88);
209-
210198
impl<'tcx, Prov: Provenance> std::ops::Deref for OpTy<'tcx, Prov> {
211199
type Target = Operand<Prov>;
212200
#[inline(always)]
@@ -830,3 +818,14 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
830818
})
831819
}
832820
}
821+
822+
// Some nodes are used a lot. Make sure they don't unintentionally get bigger.
823+
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
824+
mod size_asserts {
825+
use super::*;
826+
// These are in alphabetical order, which is easy to maintain.
827+
rustc_data_structures::static_assert_size!(Immediate, 56);
828+
rustc_data_structures::static_assert_size!(ImmTy<'_>, 72);
829+
rustc_data_structures::static_assert_size!(Operand, 64);
830+
rustc_data_structures::static_assert_size!(OpTy<'_>, 88);
831+
}

compiler/rustc_const_eval/src/interpret/place.rs

+12-15
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,6 @@ pub enum MemPlaceMeta<Prov: Provenance = AllocId> {
2525
None,
2626
}
2727

28-
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
29-
rustc_data_structures::static_assert_size!(MemPlaceMeta, 24);
30-
3128
impl<Prov: Provenance> MemPlaceMeta<Prov> {
3229
pub fn unwrap_meta(self) -> Scalar<Prov> {
3330
match self {
@@ -56,9 +53,6 @@ pub struct MemPlace<Prov: Provenance = AllocId> {
5653
pub meta: MemPlaceMeta<Prov>,
5754
}
5855

59-
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
60-
rustc_data_structures::static_assert_size!(MemPlace, 40);
61-
6256
/// A MemPlace with its layout. Constructing it is only possible in this module.
6357
#[derive(Copy, Clone, Hash, Eq, PartialEq, Debug)]
6458
pub struct MPlaceTy<'tcx, Prov: Provenance = AllocId> {
@@ -71,9 +65,6 @@ pub struct MPlaceTy<'tcx, Prov: Provenance = AllocId> {
7165
pub align: Align,
7266
}
7367

74-
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
75-
rustc_data_structures::static_assert_size!(MPlaceTy<'_>, 64);
76-
7768
#[derive(Copy, Clone, Debug)]
7869
pub enum Place<Prov: Provenance = AllocId> {
7970
/// A place referring to a value allocated in the `Memory` system.
@@ -84,9 +75,6 @@ pub enum Place<Prov: Provenance = AllocId> {
8475
Local { frame: usize, local: mir::Local },
8576
}
8677

87-
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
88-
rustc_data_structures::static_assert_size!(Place, 48);
89-
9078
#[derive(Clone, Debug)]
9179
pub struct PlaceTy<'tcx, Prov: Provenance = AllocId> {
9280
place: Place<Prov>, // Keep this private; it helps enforce invariants.
@@ -98,9 +86,6 @@ pub struct PlaceTy<'tcx, Prov: Provenance = AllocId> {
9886
pub align: Align,
9987
}
10088

101-
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
102-
rustc_data_structures::static_assert_size!(PlaceTy<'_>, 72);
103-
10489
impl<'tcx, Prov: Provenance> std::ops::Deref for PlaceTy<'tcx, Prov> {
10590
type Target = Place<Prov>;
10691
#[inline(always)]
@@ -901,3 +886,15 @@ where
901886
Ok(mplace)
902887
}
903888
}
889+
890+
// Some nodes are used a lot. Make sure they don't unintentionally get bigger.
891+
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
892+
mod size_asserts {
893+
use super::*;
894+
// These are in alphabetical order, which is easy to maintain.
895+
rustc_data_structures::static_assert_size!(MemPlaceMeta, 24);
896+
rustc_data_structures::static_assert_size!(MemPlace, 40);
897+
rustc_data_structures::static_assert_size!(MPlaceTy<'_>, 64);
898+
rustc_data_structures::static_assert_size!(Place, 48);
899+
rustc_data_structures::static_assert_size!(PlaceTy<'_>, 72);
900+
}

compiler/rustc_hir/src/hir.rs

+14-13
Original file line numberDiff line numberDiff line change
@@ -3489,17 +3489,18 @@ impl<'hir> Node<'hir> {
34893489
// Some nodes are used a lot. Make sure they don't unintentionally get bigger.
34903490
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
34913491
mod size_asserts {
3492-
rustc_data_structures::static_assert_size!(super::Block<'static>, 48);
3493-
rustc_data_structures::static_assert_size!(super::Expr<'static>, 56);
3494-
rustc_data_structures::static_assert_size!(super::Pat<'static>, 88);
3495-
rustc_data_structures::static_assert_size!(super::QPath<'static>, 24);
3496-
rustc_data_structures::static_assert_size!(super::Ty<'static>, 72);
3497-
rustc_data_structures::static_assert_size!(super::GenericBound<'_>, 48);
3498-
rustc_data_structures::static_assert_size!(super::Generics<'static>, 56);
3499-
rustc_data_structures::static_assert_size!(super::Impl<'static>, 80);
3500-
3501-
rustc_data_structures::static_assert_size!(super::Item<'static>, 80);
3502-
rustc_data_structures::static_assert_size!(super::TraitItem<'static>, 88);
3503-
rustc_data_structures::static_assert_size!(super::ImplItem<'static>, 80);
3504-
rustc_data_structures::static_assert_size!(super::ForeignItem<'static>, 72);
3492+
use super::*;
3493+
// These are in alphabetical order, which is easy to maintain.
3494+
rustc_data_structures::static_assert_size!(Block<'static>, 48);
3495+
rustc_data_structures::static_assert_size!(Expr<'static>, 56);
3496+
rustc_data_structures::static_assert_size!(ForeignItem<'static>, 72);
3497+
rustc_data_structures::static_assert_size!(GenericBound<'_>, 48);
3498+
rustc_data_structures::static_assert_size!(Generics<'static>, 56);
3499+
rustc_data_structures::static_assert_size!(ImplItem<'static>, 80);
3500+
rustc_data_structures::static_assert_size!(Impl<'static>, 80);
3501+
rustc_data_structures::static_assert_size!(Item<'static>, 80);
3502+
rustc_data_structures::static_assert_size!(Pat<'static>, 88);
3503+
rustc_data_structures::static_assert_size!(QPath<'static>, 24);
3504+
rustc_data_structures::static_assert_size!(TraitItem<'static>, 88);
3505+
rustc_data_structures::static_assert_size!(Ty<'static>, 72);
35053506
}

compiler/rustc_middle/src/mir/syntax.rs

+12-17
Original file line numberDiff line numberDiff line change
@@ -800,9 +800,6 @@ pub struct Place<'tcx> {
800800
pub projection: &'tcx List<PlaceElem<'tcx>>,
801801
}
802802

803-
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
804-
static_assert_size!(Place<'_>, 16);
805-
806803
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
807804
#[derive(TyEncodable, TyDecodable, HashStable)]
808805
pub enum ProjectionElem<V, T> {
@@ -866,11 +863,6 @@ pub enum ProjectionElem<V, T> {
866863
/// and the index is a local.
867864
pub type PlaceElem<'tcx> = ProjectionElem<Local, Ty<'tcx>>;
868865

869-
// This type is fairly frequently used, so we shouldn't unintentionally increase
870-
// its size.
871-
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
872-
static_assert_size!(PlaceElem<'_>, 24);
873-
874866
///////////////////////////////////////////////////////////////////////////
875867
// Operands
876868

@@ -913,9 +905,6 @@ pub enum Operand<'tcx> {
913905
Constant(Box<Constant<'tcx>>),
914906
}
915907

916-
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
917-
static_assert_size!(Operand<'_>, 24);
918-
919908
///////////////////////////////////////////////////////////////////////////
920909
// Rvalues
921910

@@ -1067,9 +1056,6 @@ pub enum Rvalue<'tcx> {
10671056
CopyForDeref(Place<'tcx>),
10681057
}
10691058

1070-
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
1071-
static_assert_size!(Rvalue<'_>, 40);
1072-
10731059
#[derive(Clone, Copy, Debug, PartialEq, Eq, TyEncodable, TyDecodable, Hash, HashStable)]
10741060
pub enum CastKind {
10751061
/// An exposing pointer to address cast. A cast between a pointer and an integer type, or
@@ -1105,9 +1091,6 @@ pub enum AggregateKind<'tcx> {
11051091
Generator(LocalDefId, SubstsRef<'tcx>, hir::Movability),
11061092
}
11071093

1108-
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
1109-
static_assert_size!(AggregateKind<'_>, 48);
1110-
11111094
#[derive(Copy, Clone, Debug, PartialEq, Eq, TyEncodable, TyDecodable, Hash, HashStable)]
11121095
pub enum NullOp {
11131096
/// Returns the size of a value of that type
@@ -1171,3 +1154,15 @@ pub enum BinOp {
11711154
/// The `ptr.offset` operator
11721155
Offset,
11731156
}
1157+
1158+
// Some nodes are used a lot. Make sure they don't unintentionally get bigger.
1159+
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
1160+
mod size_asserts {
1161+
use super::*;
1162+
// These are in alphabetical order, which is easy to maintain.
1163+
static_assert_size!(AggregateKind<'_>, 48);
1164+
static_assert_size!(Operand<'_>, 24);
1165+
static_assert_size!(Place<'_>, 16);
1166+
static_assert_size!(PlaceElem<'_>, 24);
1167+
static_assert_size!(Rvalue<'_>, 40);
1168+
}

compiler/rustc_middle/src/thir.rs

+11-4
Original file line numberDiff line numberDiff line change
@@ -190,10 +190,6 @@ pub enum StmtKind<'tcx> {
190190
},
191191
}
192192

193-
// `Expr` is used a lot. Make sure it doesn't unintentionally get bigger.
194-
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
195-
rustc_data_structures::static_assert_size!(Expr<'_>, 104);
196-
197193
#[derive(Clone, Debug, Copy, PartialEq, Eq, Hash, HashStable, TyEncodable, TyDecodable)]
198194
#[derive(TypeFoldable, TypeVisitable)]
199195
pub struct LocalVarId(pub hir::HirId);
@@ -812,3 +808,14 @@ impl<'tcx> fmt::Display for Pat<'tcx> {
812808
}
813809
}
814810
}
811+
812+
// Some nodes are used a lot. Make sure they don't unintentionally get bigger.
813+
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
814+
mod size_asserts {
815+
use super::*;
816+
// These are in alphabetical order, which is easy to maintain.
817+
rustc_data_structures::static_assert_size!(Block, 56);
818+
rustc_data_structures::static_assert_size!(Expr<'_>, 104);
819+
rustc_data_structures::static_assert_size!(Pat<'_>, 24);
820+
rustc_data_structures::static_assert_size!(Stmt<'_>, 120);
821+
}

0 commit comments

Comments
 (0)