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:
1
examples/expected/0207-generics-value-param-const.exit
Normal file
1
examples/expected/0207-generics-value-param-const.exit
Normal file
@@ -0,0 +1 @@
|
||||
0
|
||||
1
examples/expected/0207-generics-value-param-const.stderr
Normal file
1
examples/expected/0207-generics-value-param-const.stderr
Normal file
@@ -0,0 +1 @@
|
||||
|
||||
3
examples/expected/0207-generics-value-param-const.stdout
Normal file
3
examples/expected/0207-generics-value-param-const.stdout
Normal file
@@ -0,0 +1,3 @@
|
||||
named: len=3 a0=10.000000 a2=30.000000
|
||||
expr: len=3 e2=9.000000
|
||||
copy: len=3 b2=30.000000
|
||||
@@ -0,0 +1 @@
|
||||
0
|
||||
@@ -0,0 +1 @@
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
sum 0..M = 3
|
||||
sum 0..(M+1) = 6
|
||||
1
examples/expected/1501-vectors-const-lane.exit
Normal file
1
examples/expected/1501-vectors-const-lane.exit
Normal file
@@ -0,0 +1 @@
|
||||
0
|
||||
1
examples/expected/1501-vectors-const-lane.stderr
Normal file
1
examples/expected/1501-vectors-const-lane.stderr
Normal file
@@ -0,0 +1 @@
|
||||
|
||||
4
examples/expected/1501-vectors-const-lane.stdout
Normal file
4
examples/expected/1501-vectors-const-lane.stdout
Normal file
@@ -0,0 +1,4 @@
|
||||
direct3: 1.000000 2.000000 3.000000
|
||||
direct4: 1.000000 2.000000 3.000000 4.000000
|
||||
alias3: 7.000000
|
||||
alias4: 8.000000
|
||||
@@ -0,0 +1 @@
|
||||
1
|
||||
11
examples/expected/1502-vectors-runtime-lane-not-const.stderr
Normal file
11
examples/expected/1502-vectors-runtime-lane-not-const.stderr
Normal file
@@ -0,0 +1,11 @@
|
||||
error: Vector lane count must be a positive compile-time integer constant
|
||||
--> examples/1502-vectors-runtime-lane-not-const.sx:14:16
|
||||
|
|
||||
14 | v : Vector(lanes(), f32) = ---;
|
||||
| ^^^^^^^
|
||||
|
||||
error: field 'x' not found on type 'unresolved'
|
||||
--> examples/1502-vectors-runtime-lane-not-const.sx:15:32
|
||||
|
|
||||
15 | print("unreachable: {}\n", v.x);
|
||||
| ^^^
|
||||
@@ -0,0 +1 @@
|
||||
|
||||
Reference in New Issue
Block a user