From 9d898d0affc1a32146c41962ec219a0aec4dea85 Mon Sep 17 00:00:00 2001 From: Chris Tate Date: Wed, 21 Oct 2026 09:25:11 -0500 Subject: [PATCH] Name the stored header size for compact instances --- packages/compiler/src/backend/llvm/classes.ts | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/packages/compiler/src/backend/llvm/classes.ts b/packages/compiler/src/backend/llvm/classes.ts index 1634f1f9e..9963fad5b 100644 --- a/packages/compiler/src/backend/llvm/classes.ts +++ b/packages/compiler/src/backend/llvm/classes.ts @@ -569,6 +569,16 @@ export const COMPACT_HEADER_TAG = 0x70000000; export const COMPACT_PUBLISHED = 0x80000000; export const COMPACT_ID_MASK = 0x0fffffff; +/** The leading bytes of a new instance that its allocation function stores + * right after allocating it (emitObjectAlloc's `stored`), which a recycled + * block therefore need not clear: a compact instance's 4-byte header word + * (its fields start at offset 4), the 8-byte rc word, or the rc word and + * the vtable word of a hierarchy member that keeps its class in a vtable. */ +export function storedHeaderBytes(meta: LlClassMeta): number { + if (meta.compact) return 4; + return meta.hierarchy && !meta.idInRc ? 16 : 8; +} + /** The header word a compact instance is created with. */ export function compactHeaderWord(meta: LlClassMeta): number { return COMPACT_HEADER_TAG | (meta.hierarchy ? meta.pre + 1 : 0); @@ -1098,9 +1108,7 @@ export function emitClassShapes( host, sizeOf, traced && !lifetime ? { type: cycType } : null, - // The words stored next: a compact instance's 4-byte header, the - // rc word, or the rc word and the vtable word. - meta.compact ? 4 : meta.hierarchy && !meta.idInRc ? 16 : 8, + storedHeaderBytes(meta), ), ); if (meta.compact && !meta.hierarchy)