comptime-API: strip the byte-weld; pivot to a flat-memory comptime VM

The byte-weld (sx structs whose layout was validated to mirror the
compiler's Zig records) plus the serialization/marshaling bridge was the
wrong direction: it bolted a parallel layout regime and hand-built
byte-copies onto a comptime value model that fundamentally isn't bytes.

Strip the struct-weld machinery:
- compiler_lib.zig loses the type registry (weldStruct / bound_types /
  BoundType / FieldLayout / findType / SxField / LayoutMismatch /
  validateStructLayout); it is now just the intern/text_of function
  host-call bridge (kept as the Phase-3 compiler-call seed).
- nominal.zig loses validateWeldedStruct / weldedFieldOrderStr + the
  sd.abi == .zig validation call.
- Remove the struct-weld unit tests and examples 0625/0627 (welded
  structs) + 1183/1186 (weld-layout diagnostics).
- The #library / abi / extern syntax stays.

Record the new direction: a bytecode VM over flat, byte-addressable
memory so comptime values are native bytes (no weld/validation/marshal),
target-aware (preserves cross-compilation) and sandboxed. See
current/PLAN-COMPILER-VM.md (Phase 0 strip -> Phase 1 flat-memory value
model -> Phase 2 bytecode -> Phase 3 compiler-API on flat memory).
design/comptime-compiler-api.md gets a SUPERSEDED banner. Also drop the
"~500 lines / split the step" rule from CLAUDE.md.
This commit is contained in:
agra
2026-06-17 19:29:36 +03:00
parent 40d075ca98
commit 18af8eb845
23 changed files with 505 additions and 498 deletions

View File

@@ -1,24 +0,0 @@
// Comptime compiler API — a layout-welded struct binding.
//
// `Field :: struct abi(.zig) extern compiler { … }` binds the sx struct to the
// compiler's real internal Zig type (`StructInfo.Field`, two u32s) via the
// `compiler` library. The compiler validates the sx declaration against the
// welded type's layout at registration time (the sx side is a header checked
// against the implementation) — a faithful declaration validates clean and the
// struct is otherwise ordinary data. The `compiler` library is the comptime-only
// internal surface, so `#library "compiler"` is NOT dlopen'd.
//
// Phase 1 (foundation): the weld is layout-validated; field offsets coincide with
// the natural layout for `Field` (two u32s). Welded host-call functions land in a
// later phase.
#import "modules/std.sx";
compiler :: #library "compiler";
Field :: struct abi(.zig) extern compiler { name: u32; ty: u32; }
main :: () {
f := Field.{ name = 7, ty = 3 };
print("name={} ty={}\n", f.name, f.ty);
}

View File

@@ -1,30 +0,0 @@
// Comptime compiler API — a welded struct mirrors the compiler's real Zig type
// byte-for-byte by declaring its fields in the compiler type's MEMORY order.
//
// `StructInfo` is the real `types.TypeInfo.StructInfo`, which Zig reorders from
// source order to (fields, name, nominal_id, is_protocol). The sx header declares
// the fields in that memory order; the compiler reflects the bound Zig type
// (@offsetOf/@sizeOf) and validates the header matches — so the struct is laid
// out identically and a pointer to it can be cast to the compiler's own type and
// dereferenced. Nothing is maintained by hand: a types.zig change re-reflects.
#import "modules/std.sx";
compiler :: #library "compiler";
Field :: struct abi(.zig) extern compiler { name: u32; ty: u32; }
StructInfo :: struct abi(.zig) extern compiler {
fields: []Field;
name: u32;
nominal_id: u32;
is_protocol: bool;
}
main :: () {
si : StructInfo = ---;
si.name = 42;
si.nominal_id = 7;
si.is_protocol = true;
print("name={} nominal={} proto={}\n", si.name, si.nominal_id, si.is_protocol);
}

View File

@@ -1,17 +0,0 @@
// Diagnostic: a layout-welded struct whose sx declaration does NOT faithfully
// mirror the compiler's real Zig type is a build error — the sx side is a header
// checked against the implementation, not a free reinterpretation.
//
// `Field` is two u32s (`name`, `ty`) in the compiler library; declaring it with a
// single field must be rejected at registration with a clear field-count message.
#import "modules/std.sx";
compiler :: #library "compiler";
Field :: struct abi(.zig) extern compiler { name: u32; }
main :: () {
f := Field.{ name = 1 };
print("{}\n", f.name);
}

View File

@@ -1,20 +0,0 @@
// Diagnostic: a welded struct whose fields are NOT in the compiler type's memory
// order is a loud build error — the sx header must mirror the real Zig layout so
// the two are byte-identical. The message names the offending position and shows
// the expected memory order. (Declaring StructInfo in source order trips this:
// Zig reorders it to fields-first.)
#import "modules/std.sx";
compiler :: #library "compiler";
Field :: struct abi(.zig) extern compiler { name: u32; ty: u32; }
StructInfo :: struct abi(.zig) extern compiler {
name: u32;
fields: []Field;
is_protocol: bool;
nominal_id: u32;
}
main :: () { print("unreached\n"); }

View File

@@ -1 +0,0 @@
name=7 ty=3

View File

@@ -1 +0,0 @@
name=42 nominal=7 proto=true

View File

@@ -1,5 +0,0 @@
error: welded type 'Field': the compiler type has 2 field(s) but the declaration has 1 — declare them in memory order: name, ty
--> examples/1183-diagnostics-weld-struct-field-count.sx:12:51
|
12 | Field :: struct abi(.zig) extern compiler { name: u32; }
| ^^^

View File

@@ -1,5 +0,0 @@
error: welded type 'StructInfo': wrong field order at position 0 — found 'name', the compiler type has 'fields' here (memory order: fields, name, nominal_id, is_protocol)
--> examples/1186-diagnostics-weld-struct-wrong-order.sx:14:11
|
14 | name: u32;
| ^^^