ffi checkpoint: step 2a typed pack indexing done
Logs the two step-2a commits (223ec3dlock-in,cd36784fix): pack-fn bodies' `args[<int_literal>]` now substitutes the i-th call-site argument's lowered value directly, propagating the concrete type through field access and typed coercion. Out-of-scope follow-ups noted: non-literal comptime indices, type-position `$args[$i]` (step 3), per-mono mangling, and the pre-existing nested-comptime-call scope bug (a pack-fn body calling `print(...)` AND containing `return X;` trips "unresolved 'result'" — same shape as the issue-0045 family, worth filing separately if a later slice needs it).
This commit is contained in:
@@ -6,6 +6,57 @@ add a test and make it pass — that's two commits).
|
||||
|
||||
## Last completed step
|
||||
|
||||
**M5.A.next.2a.B — pack typed indexing: `args[$i]` substitutes call arg**
|
||||
(commit `cd36784`, lock-in `223ec3d`).
|
||||
|
||||
Step 2 first slice of the pack feature. Pack-fn bodies that
|
||||
index the pack via `args[<int_literal>]` now resolve to the
|
||||
i-th call-site argument's lowered value directly, propagating
|
||||
the call arg's concrete type instead of the boxed `Any` that
|
||||
the `[]Any` slice path returns. Lets bodies do field access /
|
||||
typed assignments / further indexing on pack elements without
|
||||
manual unboxing.
|
||||
|
||||
New plumbing in `src/ir/lower.zig`:
|
||||
|
||||
- `pack_arg_nodes: ?StringHashMap([]const *const Node)` on
|
||||
Lowering — maps pack param name to the slice of call-site
|
||||
arg AST nodes.
|
||||
- `lowerComptimeCall` populates the map when the variadic
|
||||
param is heterogeneous (`is_variadic AND is_comptime` —
|
||||
i.e. `..$args`). Plain `args: ..Any` skips registration so
|
||||
stdlib's `format`/`print` continue boxing through Any.
|
||||
Saved/restored across nested calls.
|
||||
- `packArgNodeAt(ie)` returns the call-arg node when an
|
||||
index_expr matches `<pack_name>[<comptime_int_literal>]`
|
||||
with the index in range.
|
||||
- `lowerIndexExpr` and `inferExprType`'s index_expr arm both
|
||||
check `packArgNodeAt` first so the concrete type flows
|
||||
through field access and typed-assignment paths.
|
||||
|
||||
`examples/156-pack-typed-index.sx` flips from "field 'x' not
|
||||
found on type 'Any'" to `7` — `args[0].x` on a struct-typed
|
||||
call arg resolves through Point.x correctly.
|
||||
|
||||
Out of scope:
|
||||
- Non-literal comptime indices (`args[$i]` where `$i` is a
|
||||
comptime expression with binding).
|
||||
- `$args[$i]` in type positions (step 3).
|
||||
- Per-mono mangling (monomorphisation stays inline-only).
|
||||
- Nested comptime calls bug surfaces here too: a pack-fn body
|
||||
that calls `print(...)` AND has a `return X;` trips
|
||||
"unresolved 'result'" because nested comptime inlining
|
||||
loses the scope where stdlib's `#insert build_format`
|
||||
declared `result`. Same class as the
|
||||
`helper :: ($x: s32) -> s64 { print(...); return 42; }`
|
||||
pattern; pre-dates step 2. Worth filing if step 2's later
|
||||
slices need it; today's typed-indexing test exercises only
|
||||
field access and arithmetic, no nested print.
|
||||
|
||||
195/195 example tests + `zig build test` green.
|
||||
|
||||
---
|
||||
|
||||
**issue-0045 fix — inline-return slot for comptime-call bodies**
|
||||
(commit `9e78790`, lock-in `3d32ab0`).
|
||||
|
||||
@@ -433,9 +484,10 @@ plus 2 codegen fixes surfaced along the way.**
|
||||
|
||||
## Current state
|
||||
|
||||
- 194/194 example tests pass; `zig build test` green.
|
||||
- 195/195 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 2a done — typed `args[$i]` at literal indices (cd36784).
|
||||
- issue-0045 (comptime-fn-with-return verifier crash) fixed (9e78790).
|
||||
- Chess on macOS / iOS-sim / Android all build and run.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user