WP48: 32-bit references for linked classes
State: In progress · Done: 4 of 9 · Design note: docs/wp48-ref32-classes.md
Stages
- Designed and measured: a compact class keeps its instances in one reserved range, 4-byte aligned, and a field of that class's type is an
i32offset; prototyped on the generated IR,bench/goose/tree.tsat n = 24 takes 0.50x the memory and 0.61x the time, and a pointer-chasing loop in cache pays up to a quarter more for the decode - Stage 1: the arena on a reserved range, switched on only by a compact class, with no IR moved for any program
- Stage 2a:
implements Compactfromnish:compact, thei32layout of a compact class's links in any class, the encode and decode in field loads and stores (no operator takes a link, so no compound assignment reaches one), the 4-rounding allocation through@nish_alloc_ref, and the refusals (C and N-API surfaces,declare class, aSecretfield, a generic class), each with its code; wasm32, host page modules and ASAN builds stay uncompressed - Stage 2b: TBAA for an offset field, its debug info, and debugger pretty-printers that show a link as the object it names
- Stage 2c: the opaque C header, so a compact class can cross
--emit-header - Stage 3: the compiler picks compact classes by itself (a native executable, a link field, a byte saving, made in a loop or recursion), with
implements Wideand--compact offto refuse; gated on the corpus showing no program slower. Prepared:nish --explain-layoutreports which classes the rule picks, and changes no IR - Stage 4: the
bench/goosetree programs,bench/wp48-refs/sibling.tsand the guide's memory page - Stage 5: inside Nish: which of the compiler's and
std/'s own classes the rule picks, measured on a self-build and thestd/benches, withimplements CompactorWidewhere the measurement disagrees with the rule (insrc/only after the release that ships the markers) - Stage 6: a class pointer field on wasm32 laid out in 4 bytes, not 8 (found by the survey, independent of stages 1 to 5); a class's size, alignment and field offsets on wasm32 are LLVM's, and native IR does not move
Next
Stage 2b, TBAA, debug info and pretty-printers for an offset field: §3.2.
Not planned
A whole-program 32-bit mode, compressing locals, parameters, returns, Map keys or generic T, a compact class on the stack, a compact field in a declare class.

