1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
//! DeepPerf L-3: guard the size of `vyre::ir::Expr` against silent
//! bloat. The `Expr` enum is the hottest IR node on the compiler hot
//! path — every program holds thousands of them, every CSE pass
//! rehashes them, every visitor walks them. A new variant that
//! pushes the enum past a cache-line boundary or adds unused padding
//! to every live `Expr` is an internet-scale regression.
//!
//! This test locks in the current size. If a PR legitimately needs
//! to grow `Expr`, the test must be bumped *with justification in
//! the PR description*, and the larger variant should probably be
//! boxed. If a PR accidentally grows `Expr`, this test fails loudly.
/// Hard ceiling. Current measured `size_of::<Expr>()` on x86_64 is
/// well below this; the ceiling allows headroom for one small
/// field addition but rejects a variant that adds an inline
/// `Vec<_>` (24 bytes) or `String` (24 bytes) without boxing.
const EXPR_SIZE_CEILING_BYTES: usize = 72;
#[test]
fn expr_size_stays_under_ceiling() {
let observed = std::mem::size_of::<vyre::ir::Expr>();
assert!(
observed <= EXPR_SIZE_CEILING_BYTES,
"vyre::ir::Expr grew to {observed} bytes; ceiling is {EXPR_SIZE_CEILING_BYTES}. \
Fix: box the variant that pushed it over (inline Vec / String / Box<LargeStruct>), \
or — if the growth is justified — bump EXPR_SIZE_CEILING_BYTES with a PR note."
);
}
#[test]
fn expr_size_is_reported_for_audit() {
// Not an assertion — prints the actual size so `cargo test
// expr_size_is_reported_for_audit -- --nocapture` gives the
// auditor the current measurement without grepping.
let size = std::mem::size_of::<vyre::ir::Expr>();
let align = std::mem::align_of::<vyre::ir::Expr>();
eprintln!("vyre::ir::Expr: size={size} bytes, align={align} bytes");
}