From c7854bd537092e9fcedf49437c66547f47d74a7e Mon Sep 17 00:00:00 2001 From: agra Date: Wed, 27 May 2026 16:49:04 +0300 Subject: [PATCH] ffi checkpoint: step-2 follow-ups all landed (generic $R / bare args / runtime idx / mixed) Logs all four step-2 follow-up commits (c917f92, 2e0b97a, d30d566, 159f898 + their lock-ins). Pack-fns are functionally complete on the mono path. Test count: 203/203. Step 6 (stdlib print/format refactor) is now unblocked from the type-system side; step 5 (generic Into(Block) impl) still needs step 3 (type-position $args[$i]) before its trampoline body can be parametric. iOS-sim chess regression-verified post-step-2b. Outstanding (not blocking step 3): issue-0046, non-literal comptime arg mangling. --- current/CHECKPOINT-FFI.md | 68 ++++++++++++++++++++++++++++++++------- 1 file changed, 56 insertions(+), 12 deletions(-) diff --git a/current/CHECKPOINT-FFI.md b/current/CHECKPOINT-FFI.md index 9358b00..b1158d3 100644 --- a/current/CHECKPOINT-FFI.md +++ b/current/CHECKPOINT-FFI.md @@ -6,6 +6,44 @@ add a test and make it pass — that's two commits). ## Last completed step +**M5.A.next.2b.fu1–fu4 — all four step-2b follow-ups landed** +(commits `c917f92`, `2e0b97a`, `d30d566`, `159f898` + lock-ins). + +The four deferred follow-ups from step 2b's initial landing are +now closed. Pack-fns are functionally complete on the mono +path; the only remaining gaps are issue-0046 (nested comptime +calls) and step 3+ work (type-position `$args[$i]` for the +stdlib payoff). + +| FU | Commit | What it does | +|---|---|---| +| #2 generic `$R` | `c917f92` + `2e0b97a` | `monomorphizePackFn` infers ret_ty from the body's tail expression / first explicit return when the declared type is generic. New `pack_arg_types` map gives `inferExprType` direct access to per-position pack arg types (avoids the synthesized-ident detour). New `diagPackIndexOOB` emits "pack index N out of bounds: 'pack' has M elements" instead of the misleading "unresolved 'args'" fall-through. | +| #3 bare `args` | `d30d566` | `materialisePackSlice` builds an `[]Any` slice value for the pack name inside the mono — each pack param boxed via `boxAny`, stored in a stack [N x Any] array. Bare `args` resolves as a runtime slice for forwarding to `[]Any`-typed helpers. Per-position type info is lost via Any boxing; literal-indexed access still routes through `packArgNodeAt` and keeps concrete types. | +| #4 runtime indexing | `d30d566` (shared) | `args[]` lowers through the standard slice path against the materialised `[]Any`. Element type `Any` — inherent to runtime indexing into a heterogeneous pack. | +| #1 mixed comptime+pack | `159f898` | `isPackFn` relaxed to "trailing pack + any non-pack comptime params". `lowerPackFnCall` folds comptime VALUES into the mangle (`__ct_` segment per non-pack comptime); `monomorphizePackFn` binds each comptime non-pack param both as a `comptime_param_nodes` entry AND as a runtime local. `appendComptimeValueMangle` hashes strings, formats int/bool/float for stable mangles. | + +New tests: +- `examples/159-pack-generic-ret.sx` — basic generic `$R`. +- `examples/160-pack-hetero-ret.sx` — `args[2]` with mixed-type + pack returns the third arg's concrete type ("hello"). +- `examples/161-pack-index-oob.sx` — OOB pack index emits a + focused diagnostic. +- `examples/162-pack-bare-args.sx` — bare `args` forwarded to + `log_count(items: []Any)`. +- `examples/163-pack-runtime-index.sx` — `while i < args.len + { args[i] }` over a 4-arg pack. +- `examples/164-pack-mixed-comptime.sx` — `tagged($tag: s32, + ..$args)` called with different `tag` values gets distinct + monos (`tagged__ct_7__pack_*`, `tagged__ct_9__pack`). + +203/203 example tests + `zig build test` green. Step 6's +stdlib `print` / `format` refactor is now unblocked from the +type-system side (mixed comptime+pack works); step 5 still +needs step 3's `$args[$i]` in type positions for the generic +`Into(Block)` impl body. + +--- + **M5.A.next.2b — per-call-shape monomorphisation for pack-fns** (commit `7989618`). @@ -583,22 +621,29 @@ plus 2 codegen fixes surfaced along the way.** ## Current state -- 197/197 example tests pass; `zig build test` green. +- 203/203 example tests pass; `zig build test` green. - Phase 3.0/3.1/3.2 + M1.0–M1.3 + M2.1–M2.3 + M3 + M4.0 + M4.A all landed. - Pack feature step 1 done (1c.A → 1d.B; commits bb6eca6 → 08feb60). - Pack feature step 2 done — typed `args[$i]` at literal indices (cd36784) + CFG terminator fix (e6d6903) + per-call-shape mono (7989618). +- Pack feature step-2 follow-ups all landed: generic `$R` + (c917f92, 2e0b97a), bare `args` + runtime indexing (d30d566), + mixed comptime+pack (159f898). Pack-fns are functionally + complete on the mono path. - issue-0045 (comptime-fn-with-return verifier crash) fixed (9e78790). - issue-0046 (nested-comptime-call + return) FILED, not blocking next slices since builders run inside `#insert`, not inside public pack-fn bodies. +- iOS-sim chess running end-to-end (verified post-step-2b screencap). - Chess on macOS / iOS-sim / Android all build and run. ## Pack feature — next slice options -Step 2 done. Pack-fns monomorphise per call shape; typed -indexing + arity work end-to-end. +Step 2 + all four follow-ups done. Pack-fns are functionally +complete on the mono path: typed indexing, generic returns, +heterogeneous picks, OOB diagnostics, bare/runtime `args` +access, mixed comptime+pack — all work. Step 3 ("Type-reflection intrinsics") is the natural next: - `$args[$i]` in TYPE positions (param types, return types, @@ -612,16 +657,15 @@ Step 4 (`#insert` pack passthrough + `compile_error`) is a parser/interp tweak letting builders raise build-time diagnostics from inside `#insert` bodies. -Steps 5 and 6 are stdlib refactors gated on step 3's -type-position substitution landing. +Step 5 (generic `Into(Block)` impl) and step 6 (stdlib +`print`/`format` refactor) are the visible payoff slices, +gated on step 3 (and partially step 4). -Pack feature follow-ups (deferred): -- Mixed `$fmt + ..$args` shapes through the mono path. -- Generic `$R` return type binding. -- Bare `args` reference (materialise an `[]Any` slice on demand - inside the mono). -- `args[]` non-literal indexing. -- issue-0046 fix (nested-comptime-call + return). +Outstanding items not blocking step 3: +- issue-0046 (nested-comptime-call + return). +- Non-literal comptime args in mixed-mode pack-fns (degrades + to a `?` mangle segment today — would need comptime + evaluation for proper handling). **M4.0 — context.allocator threading** (4 commits this session): - `__sx_allocator: Allocator` prepended at field index 0 of every