fix(ir): route every comptime-int through the shared evaluator (0083)
Attempts 1–4 fixed the array-dimension paths but the same length-0 fabrication class survived on every other site that resolves a compile-time integer. Unify them all on the single shared `program_index.evalConstIntExpr` so they cannot diverge: - All three Vector lane resolvers (resolveTypeCallWithBindings, resolveParameterizedWithBindings, resolveArrayLiteralType) and both generic value-param binders (instantiateGenericStruct, instantiateTypeFunction) hand-rolled an `else => 0` switch. A module-const lane `Vector(N, f32)` fabricated a 0-lane `<0 x float>` (LLVM "huge alignment" abort); a value-param `Vec(N, f32)` fabricated a 0 binding / wrong mangled name. They now fold through the shared evaluator and emit a clean diagnostic + `.unresolved` on a non-const operand (resolveVectorLane / resolveValueParamArg) — never 0. - evalComptimeInt (inline-for bounds) delegated to the shared evaluator, so `inline for 0..M` / `0..(M+1)` fold like array dims. The `<pack>.len` leaf moved into the shared folder via a new `ctx.lookupPackLen`. - The unknown-type semantic checker no longer walks a value-param position (`Vector(N, …)` / `Vec(N, …)`) as a type name (was reporting "unknown type 'N'"). - The parameterized-type-arg parser and the function-body lookahead (hasFnBodyAfterArrow) accept a const-EXPRESSION in a value position, so `Vector(M + 1, f32)` and `[M + 1]T` parse as a return type too (the latter a pre-existing array-dim sibling that the same heuristic broke). Regressions: examples/1501 (named-const + const-expr lane, direct + alias, 3/4-lane reads), 1502 (runtime lane clean-halts, exit 1, no LLVM crash), 0207 (Vec(N)/Vec(M+1) == Vec(3) instantiation), 0610 (inline-for const bounds). Shared-evaluator unit test extended with the pack-len arm. zig build && zig build test && bash tests/run_examples.sh: 395 passed, 0 failed.
This commit is contained in:
@@ -72,6 +72,37 @@
|
||||
> alias, scalar / string / struct element types); `1129` re-pointed at a genuinely
|
||||
> non-const dimension (`[get()]s64`, a runtime call) so it still proves the
|
||||
> stateless clean-halt.
|
||||
>
|
||||
> **Unified comptime-int evaluator (attempt 5).** Attempts 1–4 fixed the array
|
||||
> *dimension* paths but the SAME length-0 fabrication class survived on the
|
||||
> siblings that resolve a comptime integer elsewhere: the three Vector lane
|
||||
> resolvers (`resolveTypeCallWithBindings`, `resolveParameterizedWithBindings`,
|
||||
> `resolveArrayLiteralType`) and the two generic value-param binders
|
||||
> (`instantiateGenericStruct`, `instantiateTypeFunction`) each hand-rolled an
|
||||
> `else => 0` switch, so `Vector(N, f32)` / `Vec(N, f32)` (N a module const)
|
||||
> fabricated a 0-lane `<0 x float>` (LLVM "huge alignment" abort) or a 0 binding
|
||||
> under a wrong mangled name; and the `inline for` bound folder (`evalComptimeInt`)
|
||||
> only knew literals / comptime cursors / `<pack>.len`, so `inline for 0..M` failed
|
||||
> outright. Fix: every one of those sites now routes through the single shared
|
||||
> `program_index.evalConstIntExpr` — `evalComptimeInt` delegates to it (the pack
|
||||
> `.len` leaf moved into the shared folder via a new `ctx.lookupPackLen`); the
|
||||
> Vector lane and value-param resolvers fold through it and emit a clean diagnostic
|
||||
> + `.unresolved` (never `else => 0`) on a non-const operand. Two enabling fixes
|
||||
> upstream of resolution: the unknown-type semantic checker no longer walks a
|
||||
> value-param position (`Vector(N, …)` / `Vec(N, …)`) as a type name (it was
|
||||
> reporting "unknown type 'N'"); and both the parameterized-type-arg parser and
|
||||
> the function-body-detection lookahead (`hasFnBodyAfterArrow`) accept a
|
||||
> const-EXPRESSION in a value position, so `Vector(M + 1, f32)` and `[M + 1]T`
|
||||
> parse as a return type too (the latter a pre-existing attempt-4 sibling miss).
|
||||
> Files: `src/ir/program_index.zig` (+`.test.zig`), `src/ir/lower.zig`,
|
||||
> `src/ir/type_bridge.zig`, `src/ir/semantic_diagnostics.zig`, `src/parser.zig`.
|
||||
> Regressions: `examples/1501-vectors-const-lane.sx` (named-const + const-expr
|
||||
> lane, direct + alias, 3- and 4-lane reads), `examples/1502-vectors-runtime-lane-
|
||||
> not-const.sx` (a runtime lane clean-halts, exit 1, no LLVM crash),
|
||||
> `examples/0207-generics-value-param-const.sx` (`Vec(N,f32)` / `Vec(M+1,f32)`
|
||||
> resolve to the same instantiation as `Vec(3,f32)`),
|
||||
> `examples/0610-comptime-inline-for-const-bound.sx` (`inline for 0..M` and
|
||||
> `0..(M+1)` unroll).
|
||||
|
||||
## Symptom
|
||||
A fixed array whose dimension is a module-global integer constant (`N :: 16;
|
||||
|
||||
Reference in New Issue
Block a user