Skip to content

D30 implementation: retire the internal runtime ABI — runtime compiles in-unit; rt objects only a keyed cache; boundaries speak C #761

Closed

Description

@ehartford

Symptom

A compiler binary linked against stage2-built out/lib rt objects panics Vec index out of bounds compiling anything (garbage sig index = ASCII 'WITH' from the version-stamp string). Binaries linked against seed-built bootstrap rt work. Which rt a build links depends on whether out/lib is populated, so identical commands produce working or broken binaries depending on build-tree state. The release binary links out/lib rt, so the whole :test battery (191 behavior tests) and the debug-alloc lane failed on 747-flip.

Root cause (instruction-level)

The codegen-emitted str intrinsics (with_str_eq/slice/concat/byte_at/... — the 'keep their ABI' set from #747 step 1) are declared pub fn f(a: str, b: str) in rt/rt_core.w. The emitter's contract for these symbols is caller-owns (extern bit-copy doctrine, caller side). Compiled by the SEED (str=Copy) the bodies free nothing — contract accidentally satisfied. Compiled by the FLIPPED compiler, plain consuming-str params get callee-epilogue drops: flip-built with_str_eq spills both str headers and calls with_str_free_drop_origin on each (verified by disassembly of out/lib/rt_core.o; 42 str-family functions differ the same way vs out/bootstrap-lib/rt_core.o). Every string comparison frees both operands' buffers → heap corruption.

Bisected by object swapping: seed-built rt_core.o alone heals the probe; flip-built rt_core.o alone poisons it. Pre-existing at 8f1354b (predates the exec-family and concat fixes).

Why the campaign never saw it

Every validated binary (stage1, stage2, probes) carries seed-built bootstrap rt; flip-built out/lib rt was never exercised until the battery's release link.

Interim (landed on 747-flip)

build.w builds all out/lib rt objects with the seed (mirroring out/bootstrap-lib) so every linked binary matches the caller-owns contract. Loud comment marks it interim.

Real fix (needs a ruling)

Extend the extern bit-copy doctrine (§16.3d / D-record, currently caller-side only: SemaCheck.extern_param_is_bit_copy) to the DEFINITION side of the with_* runtime ABI: when compiling the body of a runtime-ABI function, an undeclared-effect str/aggregate param is a bit-copy view — no callee-side drop is scheduled — unless pinned @[effect(x: consume)]. Symmetric with the caller rule; makes rt sources both-worlds honest without interim shims; required before the flipped compiler can self-host its own runtime (post-reseed).

Activity

  1. changed the title [-]Flip-built rt objects free caller-owned str operands: definition-side extern bit-copy doctrine is missing[/-] [+]Retire the internal runtime ABI; remaining boundaries speak C (str illegal in extern/c_export signatures)[/+] on Aug 10, 2026
  2. ehartford commented on Aug 10, 2026

    @ehartford
    ContributorAuthor

    Ruling (Eric, 2026-08-09) — supersedes the definition-side-doctrine framing

    A. Retire the internal runtime ABI. The with_* seam is a C-era fossil plus build economy, not a semantic necessity. rt/*.w joins the compilation the way the embedded stdlib already does; codegen lowers ++/print/alloc to ordinary module functions (body visible, effects inferred, inlinable). Pre-compiled runtime objects survive only as a cache keyed by (compiler version, target) — a cache hit must be byte-identical to what the same compiler would produce in-unit. Objects as cache: allowed. Objects as boundary: retired. This makes the #761 defect class (and the which-rt-did-you-link lottery) unrepresentable rather than checked.

    B. Remaining boundaries speak C. After A, every surviving ABI surface faces a side that cannot see With types: extern fn (syscalls/libc/C libraries), @[c_export], c_import decls. Signatures there admit only C-representable types; str and &str are hard compile errors (Zig's stance — zig/src/Sema.zig:8615; not Rust's improper_ctypes lint), with a fix-it naming the §16.3c modeled path or explicit ptr+len parts.

    C. Call sites speak With (the load-bearing luxury). §16.3c is unchanged and cited by B's ruling: str auto-coerces to *const c_char arguments wherever the binding models the contract (call-scoped NUL-terminated temporary, freed on return; retains: parameters refuse str and name to_cstring; interior NUL loud). B never costs ergonomics because C carries them.

    Sequencing: the seed-built out/lib interim (ad053be) bridges until A lands post-merge/reseed. The earlier definition-side-doctrine options (tier default, per-fn pins, FnAbi ownership PassMode) are superseded — they regulated a seam this ruling deletes. Spec wording for A/B lands only as Eric's blessed text (D20).

  3. ehartford commented on Aug 10, 2026

    @ehartford
    ContributorAuthor

    Release-lane evidence for the retirement (battery 2026-08-10 on 747-flip @6d8e9be4): build ✓ fixpoint ✓, but the release binary SEGVs (exit 139, silent) on every c_import behavior test while the SAME tests are green under the dev stage1. Crash: str_byte_at_ref reads a str whose data pointer is the key text itself (address 0x2f73726573552f22 = '"/Users/' little-endian) — the c_import fs-cache KEY string's text bit-reinterpreted as its header, inside with_str_byte_at_ref(&str).

    The matrix, confirmed in-tree:

    • out/lib rt objects are SEED-built (build.w #691 str flip: str buffers free on drop; Copy-with-str sites de-Copy (D28 ruling 1) #747 INTERIM pin at rt-core-object): seed &str ABI ≠ flip &str ABI → flip-codegen callers (release binary emits with_str_byte_at_ref/with_str_eq_ref) into seed-built rt bodies mismarshal → tonight's SEGV class.
    • Flipping the pin to stage1-built rt re-opens the 04h corruption: codegen still references BOTH surfaces (grep: with_str_concat ×4 non-ref; trim/upper/lower/starts_with/replace/repeat/index_of/ends_with in both shapes), and flip-built OWNED-str rt fns free operands their bit-copy callers still own.
    • stage1's own link (out/bootstrap-lib, seed-built) is coherent — that's why the stage1 lane is green.

    So the interim options are: (a) complete the _ref emission migration so codegen only observes, then tier the pins (seed rt for stage1, stage1-built rt for stage2+/embedded); or (b) the full D30 in-unit retirement, which deletes the boundary. Either way this is the sequenced post-merge campaign; the release-lane c_import class stays red until it lands.

  4. ehartford commented on Aug 12, 2026

    @ehartford
    ContributorAuthor

    SEQUENCING CORRECTION (supersedes the handoff's 'merge → reseed → D30'): the reseed must come AFTER this retirement, not before. After :update-seed the seed IS flip-built, so build.w's interim pin (rt-core-object compiler="seed") silently flips out/lib rt to flip-built — the recorded 04h world (flip-built rt_core.o's with_str_eq frees both operands; ~191-test breakage), tree-wide rather than the current 13-test c_import class. Merge landed on main (99995a6, battery: build/fixpoint/move/drop/da all green); the seed stays pre-flip until either (a) codegen emits ONLY observing ref forms at the with_str* boundary (grep today: with_str_concat ×4 plus trim/upper/lower/starts_with/replace/repeat/index_of/ends_with in consuming shapes), making rt generation irrelevant to ownership at those calls, or (b) full D30 in-unit compilation, which deletes the boundary. (a) is the minimal reseed-unblocker and heals this issue's 13 release-lane tests; (b) is the ruled end state.

  5. ehartford commented on Aug 12, 2026

    @ehartford
    ContributorAuthor

    Release-lane dig narrowed (post-8163b3fa _ref migration + ee33341 tracked-capture moves — both landed, battery green, but the class persists):

    • The SEGV is a UAF read in tracked_input_str_compare (lr-based localization; bt is 1-frame — unwind broken at the crash): a Vec[str] element slot holds quoted-path TEXT ('"/Users/…', c_import_absolute_quoted_path content) where a str header belongs — the vec buffer is recycled memory of a freed path string.
    • Repro: ANY single c_import of a 1-line header (fixpoint-analysis/single_tiny.w), release binary only; seed-compiled stage1 reads the same dangling views from never-freed memory and passes. WITH_TRACE_C_IMPORT_CACHE perturbs nothing (still 139 unpiped).
    • The obvious owner (Frontend.tracked_input_paths unspelled captures) is FIXED (ee33341) and was a real instance-C bug — but not this one: the crash survives, and the isolated pattern (move-capture field → consume+rebuild → store back, 4 iterations) runs CLEAN under the release binary with --debug-alloc (uaf_min.w).
    • Next: lldb breakpoint on tracked_input_insert_unique logging the paths vec header per call to catch the generation where the buffer address goes stale, then WITH_DEBUG_ALLOC_TRAP_FREE learn/trap (docs/debug-allocator.md) on that buffer's free to name the freeing site. Suspect the receiver-projection depth (record_frontend_tracked_input's mut-self blank through the embedding struct) or a second owner feeding merge_unique.
  6. ehartford commented on Aug 12, 2026

    @ehartford
    ContributorAuthor

    Release-lane c_import class ROOT-CAUSED to the exact instruction: #771 (MIR drops a loop-body statement temp at the join; zero iterations → frees the uninitialized stack slot, which holds the previous call's sret Vec header = the tracked-input vec's live buffer). Full lldb/allocator proof chain on #771. The class is NOT a boundary/ABI defect — the _ref migration (8163b3f) stands on its own merits and stays. Reseed order becomes: fix #771 (isolated audited batch) → release lane green → reseed → D30.

  7. ehartford commented on Aug 13, 2026

    @ehartford
    ContributorAuthor

    #771 (the zero-iteration loop temp drop) is FIXED and blessed (c1f4985+dd664268; battery: fixpoint/move/drop/da all green, da 65 PASS). Release lane progress: offsetof + the tiny/stdint minimal repros healed. Remaining reds (12): behav_c_import_{auto_constructor,nullable_ptr_none,sdk_header}, imported_alias_struct_field, raw_ptr_arithmetic, issue44, issue114, issue59_demo_* (5).

    Next instances, with the established protocol (lldb x30 → time-bisect → hardware watchpoint on the block header → WITH_ALLOC_NO_REUSE discriminator):

    1. auto_constructor SEGV: str_byte_at_ref reading a freed header; caller cimport_deps_sorted_unique_paths+176 — the deps-manifest &str param or an element view dangles (suspect the c_import_included_files() rvalue temp's lifetime across the call, or out-vec reassign interplay).
    2. issue114: 'panic: str to C string conversion: interior NUL byte' — a corrupted str (bad len) reaching to_cstr; likely the same freed-header class surfacing through the §16.3c coercion path instead of byte_at.
      Reseed still blocked until this lane is green.
  8. 37 remaining items

  9. ehartford commented on Oct 25, 2026

    @ehartford
    ContributorAuthor

    Triage 2026-10-25, with v0.15.3.0 (main a261b65): done: D30 landed in four steps (2026-10-20): the runtime is a bundle compiled as one unit per compiler generation and target, embedded in the compiler's rt slots; a runtime that is not the linking compiler's own generation is never linked (D132); the .w-derived runtime objects and WITH_RT_IN_UNIT are gone (#2486, #2488, #2492, #2498, #2500). The one residue CLAUDE.md records, the seed-built out/bootstrap-lib objects that serve stage1, retires with the post-flip seeds now pinned.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions