Skip to content

Commit d7a750b

Browse files
author
Michael Benfield
committed
Use niche-filling optimization even when multiple variants have data.
Fixes rust-lang#46213
1 parent 1a08b96 commit d7a750b

File tree

13 files changed

+339
-159
lines changed

13 files changed

+339
-159
lines changed

compiler/rustc_ast/src/ast.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -3075,7 +3075,8 @@ mod size_asserts {
30753075
static_assert_size!(Block, 48);
30763076
static_assert_size!(Expr, 104);
30773077
static_assert_size!(ExprKind, 72);
3078-
static_assert_size!(Fn, 192);
3078+
#[cfg(not(bootstrap))]
3079+
static_assert_size!(Fn, 184);
30793080
static_assert_size!(ForeignItem, 96);
30803081
static_assert_size!(ForeignItemKind, 24);
30813082
static_assert_size!(GenericArg, 24);

compiler/rustc_const_eval/src/interpret/operand.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -780,13 +780,13 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
780780
}
781781

782782
// Some nodes are used a lot. Make sure they don't unintentionally get bigger.
783-
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
783+
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64", not(bootstrap)))]
784784
mod size_asserts {
785785
use super::*;
786786
use rustc_data_structures::static_assert_size;
787787
// These are in alphabetical order, which is easy to maintain.
788-
static_assert_size!(Immediate, 56);
789-
static_assert_size!(ImmTy<'_>, 72);
790-
static_assert_size!(Operand, 64);
791-
static_assert_size!(OpTy<'_>, 88);
788+
static_assert_size!(Immediate, 48);
789+
static_assert_size!(ImmTy<'_>, 64);
790+
static_assert_size!(Operand, 56);
791+
static_assert_size!(OpTy<'_>, 80);
792792
}

compiler/rustc_const_eval/src/interpret/place.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -890,6 +890,8 @@ mod size_asserts {
890890
static_assert_size!(MemPlaceMeta, 24);
891891
static_assert_size!(MemPlace, 40);
892892
static_assert_size!(MPlaceTy<'_>, 64);
893-
static_assert_size!(Place, 48);
894-
static_assert_size!(PlaceTy<'_>, 72);
893+
#[cfg(not(bootstrap))]
894+
static_assert_size!(Place, 40);
895+
#[cfg(not(bootstrap))]
896+
static_assert_size!(PlaceTy<'_>, 64);
895897
}

compiler/rustc_data_structures/src/obligation_forest/mod.rs

+4
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,10 @@ pub trait ObligationProcessor {
117117
}
118118

119119
/// The result type used by `process_obligation`.
120+
// `repr(C)` to inhibit the niche filling optimization. Otherwise, the `match` appearing
121+
// in `process_obligations` is significantly slower, which can substantially affect
122+
// benchmarks like `rustc-perf`'s inflate and keccak.
123+
#[repr(C)]
120124
#[derive(Debug)]
121125
pub enum ProcessResult<O, E> {
122126
Unchanged,

compiler/rustc_errors/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ pub type PResult<'a, T> = Result<T, DiagnosticBuilder<'a, ErrorGuaranteed>>;
6969
// (See also the comment on `DiagnosticBuilder`'s `diagnostic` field.)
7070
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
7171
rustc_data_structures::static_assert_size!(PResult<'_, ()>, 16);
72-
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
73-
rustc_data_structures::static_assert_size!(PResult<'_, bool>, 24);
72+
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64", not(bootstrap)))]
73+
rustc_data_structures::static_assert_size!(PResult<'_, bool>, 16);
7474

7575
#[derive(Debug, PartialEq, Eq, Clone, Copy, Hash, Encodable, Decodable)]
7676
pub enum SuggestionStyle {

compiler/rustc_hir/src/hir.rs

+10-5
Original file line numberDiff line numberDiff line change
@@ -3473,12 +3473,15 @@ mod size_asserts {
34733473
static_assert_size!(FnDecl<'_>, 40);
34743474
static_assert_size!(ForeignItem<'_>, 72);
34753475
static_assert_size!(ForeignItemKind<'_>, 40);
3476-
static_assert_size!(GenericArg<'_>, 40);
3476+
#[cfg(not(bootstrap))]
3477+
static_assert_size!(GenericArg<'_>, 32);
34773478
static_assert_size!(GenericBound<'_>, 48);
34783479
static_assert_size!(Generics<'_>, 56);
34793480
static_assert_size!(Impl<'_>, 80);
3480-
static_assert_size!(ImplItem<'_>, 88);
3481-
static_assert_size!(ImplItemKind<'_>, 40);
3481+
#[cfg(not(bootstrap))]
3482+
static_assert_size!(ImplItem<'_>, 80);
3483+
#[cfg(not(bootstrap))]
3484+
static_assert_size!(ImplItemKind<'_>, 32);
34823485
static_assert_size!(Item<'_>, 80);
34833486
static_assert_size!(ItemKind<'_>, 48);
34843487
static_assert_size!(Local<'_>, 64);
@@ -3490,8 +3493,10 @@ mod size_asserts {
34903493
static_assert_size!(QPath<'_>, 24);
34913494
static_assert_size!(Stmt<'_>, 32);
34923495
static_assert_size!(StmtKind<'_>, 16);
3493-
static_assert_size!(TraitItem<'_>, 96);
3494-
static_assert_size!(TraitItemKind<'_>, 56);
3496+
#[cfg(not(bootstrap))]
3497+
static_assert_size!(TraitItem<'static>, 88);
3498+
#[cfg(not(bootstrap))]
3499+
static_assert_size!(TraitItemKind<'_>, 48);
34953500
static_assert_size!(Ty<'_>, 72);
34963501
static_assert_size!(TyKind<'_>, 56);
34973502
}

compiler/rustc_middle/src/mir/syntax.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1231,7 +1231,8 @@ pub enum BinOp {
12311231
mod size_asserts {
12321232
use super::*;
12331233
// These are in alphabetical order, which is easy to maintain.
1234-
static_assert_size!(AggregateKind<'_>, 48);
1234+
#[cfg(not(bootstrap))]
1235+
static_assert_size!(AggregateKind<'_>, 40);
12351236
static_assert_size!(Operand<'_>, 24);
12361237
static_assert_size!(Place<'_>, 16);
12371238
static_assert_size!(PlaceElem<'_>, 24);

compiler/rustc_middle/src/thir.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -825,8 +825,12 @@ mod size_asserts {
825825
static_assert_size!(Block, 56);
826826
static_assert_size!(Expr<'_>, 64);
827827
static_assert_size!(ExprKind<'_>, 40);
828-
static_assert_size!(Pat<'_>, 72);
829-
static_assert_size!(PatKind<'_>, 56);
830-
static_assert_size!(Stmt<'_>, 56);
831-
static_assert_size!(StmtKind<'_>, 48);
828+
#[cfg(not(bootstrap))]
829+
static_assert_size!(Pat<'_>, 64);
830+
#[cfg(not(bootstrap))]
831+
static_assert_size!(PatKind<'_>, 48);
832+
#[cfg(not(bootstrap))]
833+
static_assert_size!(Stmt<'_>, 48);
834+
#[cfg(not(bootstrap))]
835+
static_assert_size!(StmtKind<'_>, 40);
832836
}

0 commit comments

Comments
 (0)