Add TypeId.type_value (slot 19) + matching TypeInfo.type_value variant: an 8-byte type handle, distinct from the 16-byte boxed .any. All types.zig layout handlers wired (size/align 8, display "Type", hash/eql); toLLVMTypeInfo -> i64. Reserve builtin headroom: first_user 19 -> 100 (slots 20-99 padded with the unresolved tripwire) so future builtins don't renumber user TypeIds / churn sx ir snapshots. 22 IR snapshots regenerated (pure renumber to 100-base). type_resolver still returns .any for "Type" — nothing produces .type_value yet, so no behavior change. 697/0 both gates.
55 KiB
CHECKPOINT-COMPILER-API — comptime compiler library (#library "compiler" + abi(.zig) extern)
Companion to the design-of-record ../design/comptime-compiler-api.md (the plan
- phased build order live there). This stream supersedes the metatype
declare/define/type_info#builtins and the#compilerstruct attribute with ONE welded mechanism. Branch:reify(offmaster). Update after every step.
⏯ Resume (fresh session)
⚠ DIRECTION CHANGED (2026-06-17). The active plan is now
PLAN-COMPILER-VM.md, NOT the weld. The byte-weld + serialization/marshaling approach is the wrong direction and is being stripped. New foundation: a bytecode VM over flat, byte-addressable memory so comptime values are native bytes; then the compiler-API rides on it with direct memory access (no weld, no validation, no marshaling). Everything below this banner describes the now-superseded weld state (committed onreifythrough40d075c) and is kept only to scope the Phase 0 strip. ReadPLAN-COMPILER-VM.mdfirst.Why the pivot: the comptime evaluator (
src/ir/interp.zig) represents values as taggedValueunions, NOT native bytes — so a comptime@ptrCast(*StructInfo)reads theValueunion's memory, not a struct. The weld tried to bridge that with hand-marshaling — exactly what the design set out to kill. Flat memory makes comptime values real bytes, so the bridge disappears. (JIT-native comptime was rejected: it breaks cross-compilation — host vs target layout — and loses the sandbox. A flat-memory VM keeps both while getting native bytes + speed.)Next action (2026-06-18) — PAUSED at a clean boundary; next step decided. Phase 3 READ and WRITE sides are DONE, and the VM is now WIRED at the lowering-time comptime site (hardened, with legacy fallback). The first HANDLED lowering-time type-fn is gated on a dedicated
Typebuiltin TypeId — that is the next focused effort (see "THE WALL" below).Done so far in Phase 3:
- READ side (7 readers, dual-path):
find_type/type_kind/type_field_count/type_nominal_name/type_field_name/type_field_type/type_field_value, each backed by aTypeTablequery both the legacy handler and the VM call (no drift). Examples 0628–0630.- WRITE side (P3.3, legacy-only at lowering time):
declare_type+pointer_to+ ONE kind-branchingregister_type(subsumesdefine's per-kind dispatch; codes matchtype_kind: 1 struct · 2 actual.@"enum"· 3 tagged_union · 4 tuple). Idempotent re-fill (two-edge import). Plus two fixes (issue 0142): all-void enum → real.@"enum"(was a verifySizes panic); bareEnumType.variantqualified construction. Examples 0631–0635, 0187.- Lowering-time VM (P3.4): hardened the VM against malformed lowering-time IR (
refTy, bailingaggType, bounds-checked branch targets — bails, never panics); wiredtryEvalintorunComptimeTypeFuncbehind the flag with legacy fallback; materialized a zeroed lowering-timeContext(the global isn't built yet at lowering). All measured green.THE WALL (next step): a
Typevalue is an 8-byte tid, but.any(the boxed-any) is a 16-byte{tag,value}— and they share one TypeId (.any). So aTypein an aggregate (Member.ty/EnumVariant.payload) is sized 16B while the value is 8B → every lowering-time type-fn bails atconst_type/ the Member-array build. Can't makekindOf(.any)a word: at EMIT time.anyreally is a 16B box (variadic any, 0603), so that would silently corrupt it. The correct fix is a dedicatedTypebuiltin TypeId (8B), distinct from.any— measured at ~123.anyreferences across ~25 files (pack.zig has 30), a ~100-touch-point cross-cutting change → its own focused session (USER CHOSE to pause rather than rush it). Rejected alternatives: a scoped "lowering-mode treats.anyas a word" flag (silent-wrong on a real Any box in a reflection type-fn); scalar-only Type-fns (safe but no real corpus type-fn is scalar-only — they all build a Member/variant aggregate).Decisions recorded:
find_typereturns a non-optionalTypeIdusingunresolved(0), NOT?Type; reader names use thetype_*family (avoid colliding with stdfield_name/type_name); the write side is a single kind-branchingregister_type; the write side stays LEGACY-only until the VM runs at lowering time (needs theTypeTypeId). End-state guarantee: ONE evaluator —interp.zigdeleted; dual-path + fallback are transitional (see PLAN end state). Build/verify:zig build && zig build test(697, gate OFF). Run the corpus ON the VM:zig build test -Dcomptime-flatOR envSX_COMPTIME_FLAT=1. Coverage trace:SX_COMPTIME_FLAT_TRACE=1(now also prints lowering-timetype-fnHANDLED/fallback lines).
(superseded) prior weld resume
Phase 1 done; Phase 2 welded structs were working via reflection + memory-order
validation (the computeWeldPlan/byte-blob "GEP engine" was explored + DROPPED even
earlier). A welded Name :: struct abi(.zig) extern compiler { … } declared fields in
the compiler type's MEMORY order; the compiler reflected the bound Zig type and
VALIDATED the header. This whole mechanism is now being stripped — see the banner.
⚠ Snapshot workflow: use
-Dname=examples/NNNN-foo.sx[,…] -Dupdate-goldensto regenerate ONLY the named example(s) — a full-Dupdate-goldensre-runs all ~690 and a flaky/host-divergent example (AOT/cross-arch) can clobber good snapshots. See CLAUDE.md → Snapshot integrity.
Last completed step
Phase 2 — welded structs by reflection + memory-order validation (byte-identical,
no GEP engine). A welded struct abi(.zig) extern compiler { … } now works
end-to-end as a byte-identical mirror of the bound Zig type.
Design (locked, supersedes the byte-layout-override plan):
- The sx header declares fields in the compiler type's MEMORY order. The compiler
REFLECTS the bound Zig type — field names from
@typeInfo, offsets from@offsetOf, size from@sizeOf— and validates the header matches. Nothing is maintained by hand; atypes.zigchange re-reflects on the next compiler build. - On pass it's an ORDINARY struct whose natural layout already equals the Zig
layout →
@ptrCastto the compiler type + deref is byte-identical. No byte-blob, no index/remap tables, no reorder, no special LLVM path. - Loud, precise diagnostics on any drift: field not found (+ memory order), wrong field order at position N (+ expected memory order), type layout mismatch (field size), layout mismatch (total size / count).
What changed from the dropped plan:
compiler_lib.zig:weldStructnow REFLECTS field names (@typeInfo) and bakesbound_typesfields in ascending-OFFSET (memory) order — no hand-listed names. DeletedcomputeWeldPlan/WeldPlan/WeldElement.validateStructLayoutchecks the sx header against the memory-ordered registry.nominal.zigvalidateWeldedStruct: renders the precise diagnostics (+weldedFieldOrderStr).- Examples:
0627(StructInfo in memory order, byte-identical, usable);1186(source-order StructInfo → wrong-field-order diagnostic).1183message refreshed. zig build+zig build testgreen (692 corpus, unit tests pass).
Earlier — Phase 2.1 (weld-plan layout math, now removed)
The weld-plan offset math + StructInfo registered. Was the core of the
byte-layout-override engine; superseded by the reflection+validation design above.
Decision (locked 2026-06-17): full byte-layout weld — a welded sx struct is
laid out byte-identically to the bound Zig type (Zig's @offsetOf, reordering +
padding included), so it passes to a Zig handler as raw memory with zero
marshalling. (The alternative — handlers reading interp Value aggregates
logically, no layout override — was rejected; welded types must also be usable as
runtime data, and the design wants the literal byte weld.)
- Measured: Zig reorders
StructInfotofields@0,name@16,nominal_id@20,is_protocol@24, size 32 — vs sx-naturalname@0,fields@8, … So the override is genuinely required (Field's two-u32 natural layout was the easy case). compiler_lib.zig: registeredStructInfo(weldStruct, the secondbound_typesentry). AddedWeldElement/WeldPlan+computeWeldPlan(alloc, fields, total)— pure: orders fields by ascending byte offset, inserts padding elements for gaps + the alignment tail, and builds the sx-field → LLVM-element remap. This is what the LLVM type builder + struct-GEP sites will consume.- Unit-tested (
compiler_lib.test.zig):Field→ identity plan (2 elems, no pad);StructInfo→ 5 elems[fields@0, name@16, nominal_id@20, is_protocol@24, pad@25..32], remap[1,0,3,2]. zig build+zig build testgreen.
Earlier — Phase 1 polish (comptime-only enforcement)
A RUNTIME call to a fn abi(.zig) extern compiler is a clean build-gating error
instead of an undefined-symbol link failure.
emitCall(src/backend/llvm/ops.zig): when the callee iscompiler_weldedAND the ENCLOSING function is notis_comptime(i.e. genuine runtime code, not a#run/::initializer wrapper whose LLVM body is dead), print a clear "comptime-only … cannot be called at runtime" error and setcomptime_failed(the driver halts before object/JIT emission). The enclosingis_comptimeguard is what keeps the legitimate#runuse (example 0626) green.- Corpus:
examples/1185-diagnostics-weld-fn-runtime-call.sx(runtimeintern(…)→ clean error, exit 1, no link failure). zig build+zig build testgreen (458 unit + 690 corpus).
Earlier — fifth sub-step (host-call bridge)
A fn abi(.zig) extern compiler dispatches, under the comptime interpreter, to
its registered Zig handler instead of dlsym.
compiler_lib.zig: function registry —BoundFn { sx_name, handler },bound_fns=intern(string)->StringId+text_of(StringId)->string(the string-pool round-trip),findFn, andFnHandler(*Interpreter, []Value -> Value).internmutates viainterp.mint orelse @constCast(&module.types)(the same mutable-table access the metatype mint path uses);text_ofreads the const pool. Importsinterp.zig(the compiler_hooks↔interp cycle pattern).- IR
Functiongainedcompiler_welded: bool.declareFunction(src/ir/lower/decl.zig) sets it viaweldedCompilerFn, which also VALIDATES: the bound lib must becompilerand the name must be on the function-export list — else a build-gating.err(no silent fall-through to dlsym). interp.call(): before the dlsym/extern path, acompiler_weldedfunction routes tocompiler_lib.findFn(name).handler(self, args)(clean bail off the export list).- Corpus:
examples/0626-comptime-weld-fn-intern-text-of.sx(#run text_of(intern("hello, compiler"))folds to a string constant → prints it);examples/1184-diagnostics-weld-fn-unexported.sx(unexported welded-fn name → build error).findFnlookup unit-tested. - Runtime-call rejection is NOT yet clean — welded fns are comptime-only; a
RUNTIME call would emit a reference to a non-existent extern symbol → a loud
LINK error (not silent, but not a tidy diagnostic). The examples call welded fns
only inside
#run. A dedicated "comptime-only symbol" emit diagnostic is the immediate follow-up. zig build+zig build testgreen (458 unit tests + 689 corpus).
Earlier — fourth sub-step (welded-struct layout validation)
A struct abi(.zig) extern compiler { … } is validated against the binding
registry as a header checked against the implementation.
compiler_lib.zig:validateStructLayout(bt, sx_fields, total)— pure, returns the firstLayoutMismatch(field count / name / size / total) or null. Pluslib_name = "compiler"andSxField. Unit-tested (faithfulFieldpasses; each drift flagged as the right variant).registerStructDecl(src/ir/lower/nominal.zig): forsd.abi == .zig,validateWeldedStructchecks the bound lib iscompiler, the name is on the export list (findType), and the sx layout (field names +typeSizeBytes+ total) matches the welded type — emitting a build-gating.err(good span into the struct body) on any failure. No silent reinterpretation.#library "compiler"is the comptime-only internal surface, NOT a dylib —src/main.zig's dlopen walker skips it (was emitting a spuriouslibcompiler.soload warning).- Corpus:
examples/0625-comptime-weld-struct-field.sx(faithfulFieldwelds, validates, usable as data →name=7 ty=3);examples/1183-diagnostics-weld- struct-field-count.sx(one-fieldField→ build-gating field-count diagnostic). - Offset-override / GEP emission for non-natural Zig layouts is NOT here — it
isn't exercised by
Field(two u32s = natural layout coincides with the weld). It arrives withStructInfoin Phase 2 (slices/reordering), where the bound offsets actually differ from the sx-natural ones. The validation already checks per-field size + total, so a layout drift is caught even before the override engine exists. zig build+zig build testgreen (456 unit tests + 687 corpus).
Earlier — third sub-step (binding registry)
The binding registry (welded-type lookup, layout baked from the real Zig type).
- New
src/ir/compiler_lib.zig— thecompilerlibrary's binding registry, the curated safety boundary.BoundType { sx_name, size, alignment, fields: []FieldLayout{name, offset, size} };weldStructbakes the layout from a real Zig struct via@sizeOf/@alignOf/@offsetOfat compiler-build time (a sx-field-count mismatch is a@compileError, never a silent truncation).bound_typesexportsField(welded totypes.TypeInfo.StructInfo.Field— twou32s);findType(sx_name) ?*const BoundTypeis the lookup the welded-decl resolution path will consult (returns null off the export list — clean boundary, no silent default). - Registered in the barrel (
src/ir/ir.zig):compiler_lib+compiler_lib_tests. - Tests (
src/ir/compiler_lib.test.zig):findType("Field")equals the realStructInfo.Field@sizeOf/@alignOf/@offsetOf(8 bytes, two u32s at 0/4); an unexported name returns null. Break-verified (a wrong size → suite red, namedir.compiler_lib.test...). zig build+zig build testgreen (454 unit tests).
Earlier — second sub-step (struct-decl parse)
abi(.zig) extern <lib> PARSES on a STRUCT decl (parse-only, no semantics).
ast.StructDeclgainedabi: ABI+extern_lib: ?[]const u8binding fields.parseStructDecl(src/parser.zig): afterstruct(and the#compilercheck), parse an optionalabi(...)then optionalextern <lib>— same slot order as fn decls — and thread them onto the node. Ordinary structs are unperturbed (parseOptionalAbi/parseOptionalExternExportno-op when absent).- Parser unit tests (
src/parser.test.zig):Field :: struct abi(.zig) extern compiler { name: StringId; ty: Type; }parses withabi == .zig,extern_lib == "compiler", field list intact; a plain struct leavesabi == .default/extern_lib == null. Break-verified (a wrong-sentinel assert turns the suite red, confirming the test runs). zig build+zig build testgreen.
Earlier — first sub-step (fn decls) + the syntax pivot
abi(.zig) extern <lib> PARSES on a fn decl (parse-only). Plus the syntax
pivot it required.
Syntax decision (locked 2026-06-17, supersedes the doc's original
extern(.zig) <lib> single-qualifier form): the ABI/layout selector and the
linkage keyword are two orthogonal annotations.
abi(.x)— ABI / calling-convention annotation in the slot beforeextern/export. Unified replacement forcallconv(...), which is removed.ABI = { default, c, zig, pure }:.c(C ABI),.zig(Zig-layout weld → thecompilerlibrary),.pure(naked asm),.default(unannotated). Can appear standalone (no extern) on any fn / fn-type / lambda.extern <lib>— linkage keyword + binding source (named library).
So a welded binding is text_of :: (id: StringId) -> string abi(.zig) extern compiler;.
What landed:
- AST (
src/ast.zig):CallingConvention→ABI { default, c, zig, pure }; thecall_convfield →abi: ABIonFnDecl/Lambda/FunctionTypeExpr. - Lexer/token (
src/token.zig,src/lexer.zig):kw_callconv→kw_abi, keyword string"callconv"→"abi". - Parser (
src/parser.zig):parseOptionalCallConv→parseOptionalAbi(parsesabi(.c|.zig|.pure)); wired in the fn-decl postfix slot (beforeextern/export), the function-type-expr slot, and the lambda slot;isFunctionDef/hasFnBodyAfterArrowrecognisekw_abi. - AST→IR map (
src/ir/type_resolver.zig,src/ir/lower/decl.zig,sema.zig,closure.zig): the AST.abi == .creads kept their C-ABI meaning; the function-type resolver maps.zig/.pure→ IR.default(no fn-pointer-type CC for those decl-level ABIs; neither occurs in a function-TYPE position yet). - CC-mismatch diagnostic (
src/ir/lower/expr.zig,src/sema.zig): the user-facing textcallconv(.c)→abi(.c). - sx migration: 52
.sxfilescallconv(→abi((all were function-type callback annotations — none in the fn-decl postfix slot, so no reordering). - Docs:
readme.md,specs.md, the design doc, snapshots (0114 / 1104 / 1200) regenerated for the rename. - Tests: parser unit tests in
src/parser.test.zig—abi(.zig) extern <lib>on a fn decl (assertsabi == .zig,extern_export == .extern_,extern_lib == "compiler"); bareexternleavesabi == .default; standaloneabi(.c)/abi(.pure). lexer/sema tests updated.
zig build + zig build test green (450/450 unit + 685 corpus).
Current state
Pivoted — see the banner +
PLAN-COMPILER-VM.md. The items below are the weld machinery as it stands onreifyHEAD (40d075c); they are the strip list for Phase 0, not the forward direction. The#library/abi/externsyntax stays; the weld semantics (layout reflection/validation, marshaling dispatch) go.
compiler :: #library "compiler";parses + is recognised as the comptime-only internal surface (never dlopen'd).abi(.zig) extern compilerSTRUCTS: layout-validated against the registry (faithful → ok; drift → build-gating diagnostic).Fieldwelds + usable.abi(.zig) extern compilerFUNCTIONS: dispatched under the comptime interp to their registered Zig handler (intern/text_ofround-trip works); unexported names rejected at declaration. Comptime-only.- A RUNTIME call to a welded fn is a clean build-gating error (comptime-only
enforcement at
emitCall); the legitimate#run/::use stays green. - The whole Phase 1 foundation (parse → registry → struct-layout validation →
function host-call bridge → comptime-only enforcement) is in place for the
two-u32
Fieldcase + the two string readers. - Deferred: offset-override / LLVM byte-offset GEP for non-natural layouts
(needed by
StructInfo's slice field, Phase 2).
Next step — execute PLAN-COMPILER-VM.md
The weld is being stripped. The next step is Phase 0 of
PLAN-COMPILER-VM.md— remove the weld / serialize / marshal machinery (compiler_lib.zigreflection+validation,nominal.zigvalidateWeldedStruct, thecompiler_weldeddispatch, the weld examples/diagnostics 0625/0627/1183/1184/1185/1186), keeping the#library/abi/externsyntax. Then Phase 1 (flat-memory value model). The weld-era "next step" below is obsolete — kept only as a record of what the weld surface was about to do.
(obsolete) weld-era next step
Welded structs were byte-identical mirrors, so the API surface was set to grow:
- Bind
register_struct/find_typeover the host-call bridge (compiler_lib.zigbound_fns, likeintern/text_of).register_structtakes a weldedStructInfoand mints a realTypeId(guarded: dup field names, kind well-formedness — the checksdefinedoes today). Because the weldedStructInfois byte-identical, the handler can read it as the real Zig*StructInfo(cast + deref) rather than marshalling aValuefield-by-field — the payoff of the byte-weld.find_type(StringId) -> ?Typereads the table. Prove: build a struct programmatically + round-trip a source one. - Re-express
type_info/define(struct) as sx overregister_struct/find_type; migrateexamples/0622; delete the bespoke struct interp arms (defineStruct/ thereflectTypeInfostruct path).
Then Phase 3+: widen the welded types to EnumInfo/TaggedUnionInfo/TupleInfo
(optional fields → sentinels) — each just needs an sx header in the compiler
type's memory order + the matching register_* fn. Finally migrate BuildOptions
to abi(.zig) extern compiler (re-home the #compiler registry) and delete
#compiler.
Note: a welded struct with an ?T / union(enum) field (e.g. EnumInfo's
backing_type: ?TypeId, explicit_values: ?[]const i64) is the next layout
wrinkle — the sx header must mirror Zig's optional/union representation. Handle
when reached (sentinels or accessor fns; see the design doc Risks).
Known issues
- None for this stream. (Metatype's deferred enhancement is issue 0141 — comptime
Listgrowth; orthogonal, seecurrent/CHECKPOINT-METATYPE.md.)
Log
- Phase 3 P3.4 step 2 (VM plan) — dedicated
Typebuiltin TypeId: FOUNDATION landed (dead/additive) (2026-06-18). AddedTypeId.type_value(slot 19) + a matchingTypeInfo.type_valuevariant + the builtins init entry — an 8-byte type handle distinct from the 16-byte boxed.any(THE WALL). Alltypes.ziglayout handlers wired:sizeOf/typeSizeBytes→ 8,typeAlignBytes→ 8,typeName→ "Type",hashTypeInfo/typeInfoEqlno-payload arms. Only ONE exhaustive switch needed a new arm (backend/llvm/types.zigtoLLVMTypeInfo→cached_i64); every otherswitch(TypeInfo)site has anelse(audited when the resolver flips).first_user19 → 100 (per the user): slots 20–99 are RESERVED builtin headroom (infos padded with theunresolvedtripwire), so future builtins don't renumber user TypeIds / churnsx irsnapshots. Cost: ~80 default entries in each binary's per-type reflection arrays (user opted in). Still dead:type_resolver.zig:64STILL returns.anyfor "Type" — nothing produces.type_valueyet, so NO behavior change. Regenerated 22 IR snapshots (pure TypeId renumber to 100-base;git diff --name-onlyconfirmed ONLY.irfiles + the 2 source files changed — no stdout/stderr/exit). 697/0 both gates (OFF and-Dcomptime-flat). Next: fliptype_resolver:64→.type_value, then migrate the.anyrefs that mean "a Type value" (const_type result / reflection returns / metatypeTypeparams /.type_tagchecks) — leave the real boxed-Any refs — file-by-file with a build after each. - Phase 3 P3.4 step 1 (VM plan) — lowering-time default context; first blocker cleared (2026-06-18).
materializeDefaultContextnow falls back to a ZEROEDContext(found by name) when the__sx_default_contextglobal is absent — i.e. at LOWERING time, where the global isn't emitted yet. A type-fn that never touches the allocator now runs past context setup; one that allocates reads a nullalloc_fn(zeroed) →call_indirecton the null func-ref bails → legacy fallback (a REAL lowering-time context with the CAllocator thunk func-refs, so allocating type-fns also run on the VM, is a follow-up). Measurement: the bail moved deeper — metatypemake_enumnow bails atconst_type(theType-literal op, unported);register_typetype-fns bail at the welded write call (declare_type/register_type aren't incallCompilerFn). No table mutation happens before either bail (the write fns bail before minting), so parity holds: both gates 697/0, no crashes. Next blockers (the "model Type" chunk): (a) theconst_typeop → a word =TypeId.index(); (b) the Type-return bridge (regToValuefor aType/.anyword →.type_tag); (c) the VM-native write side (declare_type/register_type/pointer_to incallCompilerFn) + a real lowering-time context. Only once those land does a type-fn actually run end-to-end on the VM (a HANDLED case). - Phase 3 P3.4 (VM plan) — wire the VM at the LOWERING-time site + measure (2026-06-18).
Routed
runComptimeTypeFunc(the type-fn fold — the THIRD comptime call site) throughcomptime_vm.tryEvalbehind-Dcomptime-flat/SX_COMPTIME_FLATwith legacy fallback, mirroring the two emit-time folds. Extracted the shared post-check (checkComptimeTypeResult— the declared-but-never-defined zero-field guard) so both paths use it. Measurement (SX_COMPTIME_FLAT_TRACE): every metatype/compiler-API type-fn currently bails CLEANLY withno __sx_default_context global to materialize the implicit context— at lowering time the default-context global doesn't exist yet (it's built at emit time), so the VM bails at context materialization, BEFORE running the body (no partial mint, no crash → legacy mints). The hardening holds: no crashes across the corpus on the VM lowering-time path. Both gates 697/0. So the FIRST lowering-time blocker is the implicit context, notTypemodeling — the VM needs a way to materialize/skip the default context at lowering time (most type-fns get an implicit ctx for potentialList-growth alloc; many don't use it). Next: materialize a lowering-time default context for the VM (or pass a null ctx + bail only if the allocator is actually used), THEN modelTypevalues + the VM-native write side. This is near-pure fallback today — permanent scaffolding that lights up as those land. - Phase 3 P3.4-prep (VM plan) — harden the VM against malformed lowering-time IR (2026-06-18).
Prerequisite for wiring the VM at the LOWERING-time comptime site (
runComptimeTypeFunc), where IR can be malformed (an unresolved name lowers to a dangling /Ref.noneoperand — the 0737 crash). Closed the remaining panic vectors so the VM BAILS (→ legacy fallback) instead of aborting: (1) a checkedVm.refTy(ref_types, r)replaces every rawref_types[ref.index()]inexec(the type-side companion toFrame.get'sbad_refvalue-side guard); (2)aggTypeis now a bailing method (Error!TypeId) usingrefTy; (3) the block-dispatch loop bounds-checks the branch target before indexingfunc.blocks.items.global_getwas already guarded. No behavior change — gate OFF and ON both 697/0; unit test added (acmp_ltwith aRef.noneoperand bails, not panics). Next: wiretryEvalintorunComptimeTypeFuncbehind the flag with legacy fallback and measure (most minting type-fns will still bail at the welded-write call /Type-result conversion until the VM modelsTypevalues + the VM-native write side land — those are the steps that actually move lowering-time comptime onto the VM, toward deleting legacy). - Phase 3 P3.3 (VM plan) — WRITE side: declare_type + pointer_to + ONE kind-branching register_type (2026-06-18).
The mutating compiler-API:
declare_type(name) -> Type(forward handle),pointer_to(t) -> Type(build*T), andregister_type(handle, kind, members: []Member) -> Typewhich branches onkindIN THE COMPILER (subsuming define's per-kind dispatch). Take/return realTypevalues (matching meta.sx declare/define). Timing (per user): mint LAZILY at lowering time, single pass (the existingrunComptimeTypeFunc), so the write side is legacy-only (compiler_libhandlers) — the VM isn't wired at lowering time, no VM mirror needed; readers stay dual-path. A non-generic-> Typebuilder is now flaggedis_comptime(decl.zig) so its dead body permits the welded calls. Graph: forward handles +pointer_toexpress mutually-recursive A↔B (*A,*B, B-by-value);register_typeis idempotent (re-fill a nominal slot reached via two import edges —nominalIdent).kindcodes matchtype_kind(1 struct · 2 actual.@"enum"· 3 tagged_union · 4 tuple). Fixed two bugs (issue 0142): (a) a fully payloadless minted enum was an all-void tagged_union → verifySizes panic; now a real.@"enum"(register_type kind 2 AND metatypedefineEnum); (b) bareEnumType.variantpayloadless qualified construction wasn't supported (failed for hand-written enums too) — added inlowerFieldAccess(isPayloadlessVariant). Examples 0631 (graph + actual enum + reflection), 0632 (make_enum all-void), 0633/0634/0635 (namespaced / bare / multi-edge import of a minted type), 0187 (qualified variant construction). Parity 697/697 (gate ON and OFF); unit tests added. Next (P3.4): re-express declare/define/type_info as sx over the compiler-API + delete the bespoke interp arms (needs the VM hardened for lowering-time IR, or the metatype migrated onto the legacy compiler-API calls). - Phase 3 P3.2b (VM plan) — kind + enum-value readers:
type_kind+type_field_value; READ side complete (2026-06-18). The last two read-only readers the metatype'stype_info(T)needs (added tocompiler_lib.bound_fnsANDVm.callCompilerFn, each backed by aTypeTablequery both call):type_kind(t) -> i64(kindCode— a stable, compiler-owned discriminant: 0 other · 1 struct · 2 enum · 3 tagged_union · 4 tuple · 5 union · 6 array · 7 vector · 8 error_set; TOTAL, never bails) andtype_field_value(t, idx) -> i64(memberValue— an enum variant's explicit value or ordinal; mirrors thefield_value_intbuiltin; loud-bail for non-enum / out-of-range). Example0630-comptime-compiler-type-kindreflectsColor/WindowFlags(flags) /Point. The READ side is now COMPLETE —find_type+type_kind+type_field_count+type_field_name/type_field_type/type_nominal_name+type_field_valuecover everythingreflectTypeInforeads. VM unit test added. Parity 691/691 (gate ON and OFF). Revised forward direction (per the user): the WRITE side is ONEregister_type(info)fn that branches on the kind IN THE COMPILER (subsumingdefine's per-kind dispatch), not a per-kindregister_struct. - Phase 3 P3.2 (VM plan) — field-level reflection readers:
type_nominal_name+type_field_name+type_field_type(2026-06-18). Three morecompiler-library readers on the sameTypeId-handle shape (added tocompiler_lib.bound_fnsANDVm.callCompilerFn), each backed by a newTypeTablequery BOTH paths call (no drift):nominalName(a named type's own name handle; loud-bail for unnamed types likei64/pointers),memberName(struct/union/tagged-union field, enum variant, named-tuple element),memberType(struct/tuple/array/vector member type). All loud-bail on out-of-range idx / no-member (no silent default). First MULTI-ARG compiler fns —callCompilerFnreads arg 1 = idx; addedVm.argHandle/argTypeId(range-checked u32/TypeId arg reads) and refactoredfind_type/type_field_countonto them. Namedtype_*to avoid clashing with the std metatype builtins (field_name/type_nameexist in core.sx);nominalName(the TypeTable method) is distinct from the existingtypeName(id) []const u8display-string renderer. Example0629-comptime-compiler-field-reflectreflectsPair { lo: Point; hi: Point }— each field name + the nominal name of a field's type, all#run-folded, all VM-HANDLED natively. VM unit test added (type_field_name → "hi"; type_nominal_name(type_field_type(Pair,0)) → "Point"). Parity 690/690 (gate ON and OFF). - Phase 3 P3.1 (VM plan) — first read-only reflection readers:
find_type+type_field_count(2026-06-18). Two morecompiler-library fns, bound the same way as theintern/text_ofseed (added tocompiler_lib.bound_fnsfor the legacy handler + the welded-decl export check, AND toVm.callCompilerFnfor the native flat-memory path — NO marshaling). A type handle is a plainu32TypeId(likeStringId), so both keep the seed's clean scalar shape:find_type(name: StringId) -> TypeId(TypeTable.findByName,unresolved/0 if absent) andtype_field_count(t: TypeId) -> i64(a NEWTypeTable.memberCountquery — struct/union/ tagged-union fields, enum variants, array/vector length — called by BOTH paths so they can't drift; bails loudly, never a silent 0). New example0628-comptime-compiler-find-typechainsintern → find_type → type_field_count(and a not-found lookup → 0), both folded at#run, both VM-HANDLED natively (trace confirms no fallback). VM unit test added (find_type+type_field_count, struct found → 3 fields, missing →unresolved). Parity 689/689 (gate ON and OFF). Decision (resolves the plan'sfind_type → ?Typesketch): return a NON-optionalTypeIdwith theunresolved(0) sentinel for not-found, NOT?Type— aTypevalue resolves to.any(which the flat-memory VM doesn't represent) and an optional can't cross the legacy↔VM eval boundary;unresolvedis the project-blessed unmistakable "no type" marker. Forward (P3.2): more readers on the same handle shape (type_name/field_name/field_type/kind), thenregister_struct(first mutating fn). - VM robustness —
Framebounds-check; lowering-time#insertwiring explored + reverted (2026-06-18). Explored wiring the VM at the LOWERING-time comptime site (evalComptimeString, the#insertstring fold). 12/13#insertexamples ran on the VM with parity, but0737(an#insertof an unresolvedsecret()) CRASHED the VM (SIGABRT): lowering-time IR can be malformed (aret Ref.nonefrom the unresolved name) andFrame.getpanicked on the out-of-range index. Decision: reverted the lowering-time wiring — unlike the emit-time folds (fully lowered IR), lowering-time IR can be erroneous, and hardening the VM against ALL malformed IR (everyref_types[...]/aggTypeaccess, not justFrame) is out of scope here. The emit-time sites already give full corpus coverage. KEPT the defensive fix regardless (CLAUDE.md "never crash"):Frame.get/setnow bounds-check and flip abad_refflag; therunloop bails (badRef) instead of panicking. Unit test added (malformedret Ref.none→ bail, not crash). Parity 688/688 both ways. - Phase 3 SEED (VM plan) — compiler-call path:
intern/text_ofnative on the VM (2026-06-18).invokenow dispatches a weldedcompiler-library fn (gated oncompiler_welded) toVm.callCompilerFn, serviced NATIVELY on flat memory (no legacyInterpreter):intern(string)->StringIdreads the flat-memory string bytes andinternStrings into the const-cast table (pool-only — doesn't touch type layout, so cached sizes stay valid);text_of(StringId)->stringmaterializes the pooled text back into flat memory. Unlocked0626; the ONLY remaining const-init fallback is now the inline-asm global (1654). Parity 688/688 (gate ON and OFF); unit test added. This is the mechanism Phase 3 grows — the next compiler fns (find_type,register_struct, reflection readers) bind the same way (flat-memory pointer in, handle/pointer out, no marshaling). - Phase 1.final step 9 (VM plan) —
-Dcomptime-flatbuild flag (the "swap behind a build flag" step) (2026-06-18). Added the-Dcomptime-flatbuild option (build.zig → abuild_optsoptions module onmod;emit_llvm.initreadsbuild_opts.comptime_flat or SX_COMPTIME_FLAT env). This is the plan's "reach parity → swap behind a build flag → delete the old path" mechanism.zig build test -Dcomptime-flatruns the FULL corpus on the VM (688/0). Verified the flag toggles the binary: flag-builtsxreports VM HANDLED with no env var; default-built does not. Default OFF —zig build testunchanged (688/0). Env var still works for ad-hoc runs. Next (forward): Phase 2 (bytecode) / Phase 3 (compiler-API on flat memory); eventual default-flip + legacy deletion. - Phase 1.final step 8 (VM plan) — wire the
#runside-effect path + trace-clear-on-fallback (2026-06-18). Wired the SECOND comptime call site (runComptimeSideEffects, top-level#run <expr>;) throughtryEvalwith legacy fallback, mirroring the const-init fold.tryEvalnow handles void/noreturn entries (→.void_val) so a void side-effect doesn't bail at the result conversion. Fixed a trace-corruption the new site exposed (1035): a side-effect that pushes return-trace frames and then bails (e.g. onprint) had the legacy re-run DOUBLE-push them (sx_trace_pushis a side effect on the shared buffer). Both wiring sites nowsx_trace_clear()right before the legacy fallback, discarding the VM's partial pushes. Parity 688/688 (gate ON and OFF). Most side-effects still bail (print/global_addr/call_builtin) → legacy, but the path is now uniform. All comptime evaluation routes through the VM-with-fallback. - Phase 1.final step 7 (VM plan) — is_comptime + failable/error cluster + signed-load fix; coverage 31→36 (2026-06-18).
is_comptime→ 1 (unlocked1030). Ported the failable/error-channel cluster (1037escape,1038handled):kindOf(error_set)→word,regToValuebridges TUPLES (the failable(value…,tag)shapecheckComptimeFailablereads),trace_framepacks(func_id<<32|span.start)from a newcall_stack(pushed by invoke/runEntry), andsx_trace_push/sx_trace_clearserviced NATIVELY (the VM calls the real sx_trace.c functions linked into the compiler, so the return-trace buffer is populated identically to legacy). raise/catch/or now run on the VM. Surfaced + fixed a real GENERAL bug:readFieldwas ZERO-extending signed sub-64-bit loads, so a storedi32 -1reloaded as0xFFFFFFFF(+4.29e9) and< 0was false — silently hidingraise error.Bad; now SIGN-extendsi8/i16/i32/isize(gate-ON parity confirms it's a strict fix; unit test added). VM HANDLES 36 corpus const-inits (was 31); parity 688/688 (gate ON and OFF). Only 2 fallbacks remain, both principled:intern(0626, welded compiler-API fn — Phase 3) + inline-asm global (1654). Forward work: Phase 2 (bytecode), Phase 3 (compiler-API on flat memory). - Phase 1.final step 6 (VM plan) — real default context + call_indirect + func_ref + global_get; coverage 27→31 (2026-06-17).
Per the user's direction ("the VM can set up a default context"),
runEntrynow materializes the REAL default context instead of a zeroed one. The implicit-ctx param is an opaque*void, somaterializeDefaultContextfinds the__sx_default_contextglobal and lays its initializer ({ {null, alloc_fn, dealloc_fn}, null }, the CAllocator thunk func-refs) into flat memory via a new recursivelayoutConst. Withfunc_ref(function value encodedFuncId.index()+1, reserving word 0 for the null fn-ptr) andcall_indirect(decode word → FuncId → dispatch; 0 → bail) ported, the whole allocator protocol runs on the VM:context.allocator.alloc_bytes→ call_indirect → thunk →CAllocator.alloc_bytes→libc_malloc→ native flat malloc. Unlocked0606(string global). Also:global_getlazily evaluates a comptime global'scomptime_func(memoized) — unlockedCT_CHAIN; field access (fieldOffset/struct_get) handles string/slice{ptr@0,len@8}fat pointers (needed byalloc_string);regToValuemaps function-typed words →.func_ref(kept1128's rejection byte-identical). Nativemallocis still required (the thunk bottoms out at it; a host pointer can't be used with flat-memory load/store). VM HANDLES 31 corpus const-inits (was 27); parity 688/688 (gate ON and OFF). Unit tests: global_get, func_ref+call_indirect. Remaining fallbacks (7):.unsupportedaggregates (3× —1037/1038), extern/builtinintern+asm (2×),trace_frame,is_comptime. - Phase 1.final step 5 cont. (VM plan) — libc memory builtins + f32 fix; coverage 16→27 (2026-06-17).
Identified the dominant fallback (
call to extern/builtin) as 11×malloc(0604) + 1×intern. Modeled a curated set of libc MEMORY builtins natively on flat memory (Vm.callMemBuiltin):malloc/calloc→allocBytes(16-aligned, 256-MiB cap → bail),free→ no-op,memcpy/memmove/memseton flat bytes — sandboxed (no host heap/dlsym), target-aware; the computed result is byte-identical to legacy (which calls real libc). This surfaced a real latent f32 bug: float registers hold f64 bits, but f32 MEMORY is the 4-byte single —readField/writeFieldwere truncating the f64 bits (writing zeros for1.0); now they@floatCaston f32 load/store (mirrors legacystoreAtRawPtr). Result: VM HANDLES 27 corpus const-inits (was 16); parity 688/688 (gate ON and OFF). Unit tests added (f32 round-trip; malloc → usable flat memory). Next: thekindOf.unsupportedaggregates (3×),global_get(2×), the rest. - Phase 1.final step 5 (VM plan) — implicit-context materialization; coverage 0→16 (2026-06-17).
tryEvalnow MATERIALIZES the implicit ctx instead of skipping it: ahas_implicit_ctxcomptime entry (sole param*Context) gets a zeroedContextof the right size/align in flat memory, its address passed as arg 0. Const bodies that ignore the ctx run; a body that uses the allocator hits unportedcall_indirect→ bails → legacy. No func-ref materialization needed (handled bodies don't read ctx contents; parity is the guard). Fixed a real bug surfaced by the coverage pass: storing anullnon-pointer optional (thenull_addrsentinel) into an aggregate slot OOB-bailed —writeFieldnow ZEROES the destination for anull_addraggregate source (= none/empty); unit-test regression added. Result: VM HANDLES 16 corpus const-inits (was 0); parity 688/688 both gate ON and OFF. Next: port the ops the trace names —call_builtin/compiler_call/ extern (13×, via the bridge),kindOf.unsupportedaggregates (3×),global_get(2×), func_ref / call_indirect / trace_frame / is_comptime. - Phase 1.final steps 1–4 (VM plan) — host wiring landed; coverage measured (2026-06-17).
(1) Hardening:
Machine.readWord/writeWord/bytesnow returnerror.OutOfBounds(null / out-of-range / oversized / overflow-safe) instead ofassert-panicking;OutOfBoundsadded toVm.Error;trythreaded through every helper + exec arm + the bridge. New unit tests (accessor OOB returns; null-deref →tryEvalnull, not a crash). (2) Implicit context:tryEvalreturns null forhas_implicit_ctxfuncs (legacy fallback) — conservative; full ctx materialization deferred to step 5. (3) Wiring: const-init fold inemit_llvm.zigemitGlobalsis(if comptime_flat) tryEval else null) orelse interp.call(...), gated by envSX_COMPTIME_FLAT(read once intoLLVMEmitter.comptime_flat). Default OFF. (4) Parity + coverage: gate ON → full corpus byte-identical (688, 0 failed) + manual 0605/0606/0607 byte-identical. Finding: 0 of 37 measured corpus const-inits are VM-handled — ALL arehas_implicit_ctx-gated. Added a coverage-trace facility (comptime_vm.last_bail_reason- env
SX_COMPTIME_FLAT_TRACE). Next: step 5 = implicit-context materialization (the unblocker), then port the deferred ops. 688 corpus green (gate OFF).
- env
- Phase 1.final start (VM plan) — wiring entry point
tryEval(2026-06-17).comptime_vm.tryEval(gpa, module, func_id) ?Valueruns a comptime function entirely on the VM, returns a legacyValue(deep-copied togpa) ornullto fall back. Unit-tested (pure 6*7 → 42; unbox_any → null). NOT yet routed into the host: needs (1) panic→error hardening ofMachineaccessors so arbitrary funcs bail instead of crashing, (2) implicit-ctx handling, (3) wiring atemit_llvmconst-init behindSX_COMPTIME_FLAT, (4) corpus parity run. SeePLAN-COMPILER-VM.mdPhase 1.final. 688 corpus green. - Phase 1 sub-step 1.5b (VM plan) — Reg↔Value boundary bridge (2026-06-17).
Builtin/compiler_call/extern handlers are coupled to the legacy
Interpreter, so the wiring will use WHOLE-FUNCTION fallback (VM runs pure functions; bail → legacy re-runs the whole eval). Built the boundary bridge that enables it:valueToReg(Value arg → Reg, aggregates into flat memory) +regToValue(VM result → Value, deep-copied). Covers scalars/strings/structs; other shapes bail. Transitional. Round-trip unit-tested. 688 corpus green. Next: the wiring (flag + route a comptime entry through the VM with legacy fallback). - Phase 1 sub-step 1.5 (VM plan) — direct
call+ stack-lifetime change (2026-06-17).Vmgainedmodule(callee resolution) +depth/max_depthguard.callmarshals arg Refs → Reg and recursively runs the callee; aggregates pass as Addrs over shared flat memory.Frameno longer reclaims the machine on exit (else a returned aggregate Addr dangles) — allocations live toVm.deinit. Extern/builtin callees bail (1.5b). Unit-tested: direct call (142), recursion sum(0..n) (15/55). 688 corpus green. Next: 1.5b (call_builtin/compiler_call/extern), then hybrid wiring. - Phase 1 sub-step 4d (VM plan) — deref/addr_of; pivot decision (2026-06-17).
Ported
addr_of(pass-through) +deref(readField through pointer), unit-tested (deref *i64 → 77, addr_of struct + field → 80). DECIDED to stop porting rarer ops (tagged-union payload/any/closures) blind — their byte semantics are ambiguous without real call sites — and pivot to CALLS (sub-step 1.5:call, then builtin/compiler) + HYBRID WIRING (-Dcomptime-flat→ VM with legacy fallback onerror.Unsupported), so the VM runs the real corpus and surfaces exactly what's needed. Key design point for calls: aggregate-return lifetime → drop per-frame stack reclaim (let a comptime eval's allocations live toVm.deinit). 688 corpus green. SeePLAN-COMPILER-VM.mddecision block. - Phase 1 sub-step 4c (VM plan) — optionals + payloadless enums (2026-06-17).
kindOf: enum → word;?T→ word (pointer-child, null==0) or{T@0,i1@sizeof(T)}aggregate. Ported optional_wrap/unwrap/has_value/coalesce (optChildIsPtr/optHas; const_null reads as none) + payloadless enum_init/enum_tag. Unit-tested (?i64 → 91, ?*i64 null==0 → 99, enum tag → 11). 688 corpus green. Next: 4d (tagged unions, any, closures). - Phase 1 sub-step 4b (VM plan) — slices + strings on flat memory (2026-06-17).
{ptr@0(pointer_size), len@8(i64)}fat pointers (kindOf: string/slice → aggregate). Portedconst_string(text+NUL + fat pointer in flat memory),length/data_ptr,array_to_slice,subslice, index-through-slice (elemAddrloads.ptr), andstr_eq/str_ne(memcmp). Unit-tested (str length+eq/ne, array→slice index sum=23, subslice sum=43). 688 corpus green. Next: 4c (optionals/enums/any/closures). - Phase 1 sub-step 4a (VM plan) — tuples + arrays on flat memory (2026-06-17).
kindOfwidened (tuple/array → aggregate). Portedtuple_init/tuple_get(tupleFieldOffset),index_get/index_gep(elemAddr= base + idx*elem_size over array/pointer/many_pointer; slice/string bases bail),lengthon array values. Unit-tested (mixed tuple, [3]i64 index sum=42, length=3). 688 corpus green. Next: sub-step 4b (slices/strings, then optionals/enums/any/closures). - Phase 1 sub-step 3 (VM plan) — memory + structs on flat memory (2026-06-17).
Vmgained optionaltable: *const TypeTable(target-aware layout). Portedalloca/load/store+struct_init/struct_get/struct_gep, laying structs out at the table's natural offsets. Value model: scalar/pointer → register word; struct → lives in flat memory, its value IS its address (read→addr, write→memcpy), so nested structs compose andstruct_gep= base+offset.kindOfbails loudly on not-yet-ported types. Addr-based values survive allocator realloc. Unit-tested (struct round-trip, alloca+gep+store+load, nested struct). 688 corpus green. Next: sub-step 4 (arrays/slices/strings/optionals/enums/tuples/any/closures, then calls). - Phase 1 sub-step 2 (VM plan) — flat-memory executor: scalars + control flow
(2026-06-17). Added
Vmtocomptime_vm.zig: walks the same IRInstover flat-memory frames (registerReg= scalar bits orAddr), mirroring the legacy interp's scalar semantics (i64 wrapping/signed, f64). Ported constants, arithmetic, comparison, logical, conversions, terminators (br/cond_br/ret/ret_void) andblock_param; every other op bails loudly (error.Unsupported+ op name indetail). Unit-tested on hand-built tiny IR (Fbbuilder): int add, f64 arithmetic, cond_br selection, a block-param loop, div-by-zero + unsupported-op bails. Corpus untouched (688 green). Next: sub-step 3 (memory + aggregates on flat memory, where target-aware layout enters). - Phase 1 sub-step 1 (VM plan) — flat-memory machine substrate (2026-06-17).
New
src/ir/comptime_vm.zig:Machine(linear byte memory + bump/stack allocator withmark/reset, scalarreadWord/writeWord1/2/4/8 LE,bytesviews, addr 0 reserved asnull_addr) +Frame(Ref-indexed register file, stack reclamation on deinit).Reg= raw u64 (immediate scalar ORAddr). Unit-tested (comptime_vm.test.zig), registered in the barrel; standalone — the legacy interpreter stays live, corpus untouched (688 green). Next: sub-step 2 (executor + scalar/branch ops over the same IR). Also removed the "~500 lines / split step" rule from CLAUDE.md per request. - Phase 0 (VM plan) — struct-weld stripped;
intern/text_ofbridge kept (2026-06-17). Removed the struct-weld registry fromcompiler_lib.zig(weldStruct/bound_types/BoundType/FieldLayout/findType/SxField/LayoutMismatch/validateStructLayout),validateWeldedStruct/weldedFieldOrderStr- the
sd.abi == .zigcall fromnominal.zig, the struct-weld unit tests, and examples0625/0627/1183/1186. KEPT (decision) theintern/text_offunction host-call bridge — a clean scalar dispatch, not weld/serialize/marshal, the Phase-3 compiler-call seed — soweldedCompilerFn, thecompiler_weldeddispatch, theemitCallcomptime-only gate, the#library/abi/externsyntax, and examples0626/1184/1185remain.zig build testgreen (688 corpus, 0 failed). Next: Phase 1 (flat-memory value model) perPLAN-COMPILER-VM.md.
- the
- DIRECTION CHANGE — pivot off the byte-weld to a flat-memory bytecode VM
(2026-06-17). Decided the weld + serialization/marshaling bridge is the wrong
direction (it hand-marshals onto a comptime value model that isn't bytes — exactly
what the design set out to kill). New foundation: a bytecode VM over flat memory so
comptime values are native bytes; the compiler-API then rides on it via direct memory
(no weld/validation/marshaling). JIT-native comptime was weighed and rejected (breaks
cross-compilation, loses the sandbox). Wrote
current/PLAN-COMPILER-VM.md(Phase 0 strip → Phase 1 flat-memory value model → Phase 2 bytecode → Phase 3 compiler-API on flat memory). Banner added todesign/comptime-compiler-api.md(superseded). Reverted the session's uncommittedregister_struct/find_typemarshaling experiment back toreifyHEAD (40d075c). No code stripped yet — Phase 0 is the next action. - Phase 2 — welded structs by reflection + memory-order validation. Dropped
the byte-layout-override engine (computeWeldPlan / offset-ordered LLVM struct /
byte-blob — all explored, all unnecessary). Instead: the sx header declares
fields in the compiler type's memory order; the compiler reflects the bound Zig
type (
@typeInfo/@offsetOf/@sizeOf) and validates the header matches with loud diagnostics (field-not-found, wrong-order+expected-order, size mismatch). On pass it's an ordinary byte-identical struct — cast + deref just works. Examples 0627 (usable) / 1186 (wrong-order diagnostic). Suite green (692). - Phase 2.1 — weld-plan layout math (REMOVED). The byte-layout-override math; superseded by the reflection+validation design and deleted.
- Phase 1 polish — comptime-only enforcement. A runtime call to a welded fn is
a clean build-gating error (
emitCallgate, guarded by enclosing-is_comptimeso#run/::uses stay green), not a link failure. Example 1185. Build + suite green (458 unit, 690 corpus). - Phase 1.1 fifth sub-step — host-call bridge (welded functions).
compiler_libfunction registry (intern/text_of) +findFn; IRFunctioncompiler_weldedflag set/validated indeclareFunction(weldedCompilerFn);interp.call()dispatches welded calls to the Zig handler. Examples 0626 (round- trip) + 1184 (unexported-fn diagnostic);findFnunit-tested. Runtime-call clean rejection deferred (loud link error today). Build + suite green (458 unit, 689 corpus). - Phase 1.1 fourth sub-step — welded-struct layout validation.
validateStructLayout(pure, unit-tested) +validateWeldedStructwired intoregisterStructDecl: astruct abi(.zig) extern compileris validated against the registry (lib == compiler, name exported, layout matches) with build-gating diagnostics.#library "compiler"no longer dlopen'd. Examples 0625 (faithful Field) + 1183 (field-count mismatch diagnostic). Offset-override/GEP deferred to Phase 2 (not exercised by Field's natural layout). Build + suite green (456 unit, 687 corpus). - Phase 1.1 third sub-step — binding registry. New
src/ir/compiler_lib.zig: thecompilerlib's welded-type registry;Fieldwelded toStructInfo.Fieldwith layout baked from the real Zig type (@offsetOf/@sizeOf/@alignOf);findTypelookup proven by unit test (+ null off the export list). Standalone island — not yet consumed by lowering. Build + suite green (454 unit tests). Break-verified. - Phase 1.1 second sub-step — struct-decl binding parses.
ast.StructDeclgainedabi+extern_lib;parseStructDeclparsesabi(.zig) extern <lib>afterstruct. Parser unit tests (weldedField+ plain struct), break-verified. Build + suite green. Parse-only sub-step (fns + structs) of Phase 1.1 complete. - Phase 1.1 first sub-step +
callconv→abiunification. Parsedabi(.zig) extern <lib>on fn decls; unifiedcallconvintoabi(.c|.zig|.pure)(removed thecallconvkeyword), migrated 52 sx files + compiler diagnostics + docs + snapshots. Build + suite green. The original design'sextern(.zig)single qualifier was split intoabi(.zig)(ABI/layout, before extern) +extern <lib>(linkage + source) — recorded in the design doc's syntax-decision note.