fix(ir): converge the comptime-int count surface (0083)

Three adjacent cells of the shared count surface still diverged from the
rest; all now route through the same leaf+fold+narrow+diagnose path.

1. Aliased integer constraint bypassed the value-param range gate — only
   builtin constraint names matched intTypeRange, so Box(5_000_000_000)
   with `$K: Count` (Count :: u32) compiled and bound a truncated value.
   resolveValueParamArg (shared by both the struct AND type-fn binder) now
   resolves the constraint to its underlying builtin via
   canonicalIntConstraintName (Count -> u32, Small -> s8) before
   range-checking, so an aliased integer constraint behaves exactly like
   the builtin it names.

2. A named const with an expression RHS (M :: 2; N :: M + 1) did not fold
   as a count — moduleConstInt read only a literal RHS node. It now folds
   every const's RHS through the shared evalConstIntExpr, cycle-guarded
   (mutual / self cycles fold to null, not a stack overflow), and pass-0
   pre-registers expression-RHS consts. N :: M + 1 == 3 at every consumer:
   dim (direct + alias), Vector lane, value-param (struct + type-fn),
   inline for.

3. Stateful resolveArrayLen still fabricated length 0 after a failed fold;
   it now returns null -> the .unresolved sentinel (no fabrication). The
   binding's lowering never reaches sizeOf (alloca defers it; hasErrors
   aborts first) and a field access on an already-diagnosed .unresolved
   value is poison-suppressed (emitFieldError), so a failed-fold dim emits
   ONE clean diagnostic with no panic.

Regressions: examples/0146 (full positive matrix — every consumer x leaf
form), 1135 (aliased u32 + s8 overflow), 1136 (direct non-const dim halts
cleanly). The cascade cleanup also tightened 1502/1503 to one diagnostic.
Unit test added for moduleConstInt expression-folding + cycle detection.
This commit is contained in:
agra
2026-06-04 14:09:46 +03:00
parent e03c087e5a
commit a821323c3c
18 changed files with 328 additions and 33 deletions

View File

@@ -0,0 +1 @@
0

View File

@@ -0,0 +1 @@

View File

@@ -0,0 +1,13 @@
dim.direct.expr: len=3 a0=7 a2=9
dim.direct.float: len=4 f3=40
dim.alias.expr: len=3 aa2=99
dim.alias.float: len=4
dim.alias.typed: len=5
lane.expr3: 1.000000 2.000000 3.000000
lane.float4: 4.000000
vp.struct.expr: len=3 v=30
vp.struct.alias.u32: len=3 v=31
vp.struct.alias.s8: len=4 v=32
vp.typefn.expr: len=3 v=33
for.expr: 3
for.float: 6

View File

@@ -0,0 +1,11 @@
error: value 5000000000 does not fit in u32 parameter K
--> examples/1135-diagnostics-value-param-alias-constraint-overflow.sx:20:13
|
20 | b : Box(5000000000) = ---;
| ^^^^^^^^^^
error: value 300 does not fit in s8 parameter K
--> examples/1135-diagnostics-value-param-alias-constraint-overflow.sx:21:14
|
21 | t : Tiny(300) = ---;
| ^^^

View File

@@ -0,0 +1,5 @@
error: array dimension must be a compile-time integer constant
--> examples/1136-diagnostics-array-dim-nonconst-direct-no-crash.sx:19:10
|
19 | a : [get()]s64 = ---;
| ^^^^^

View File

@@ -3,9 +3,3 @@ error: Vector lane count must be a positive compile-time integer constant
|
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);
| ^^^

View File

@@ -3,9 +3,3 @@ error: Vector lane count 5000000000 does not fit in u32
|
13 | v : Vector(5000000000, f32) = ---;
| ^^^^^^^^^^
error: field 'x' not found on type 'unresolved'
--> examples/1503-vectors-oversized-lane-not-u32.sx:14:32
|
14 | print("unreachable: {}\n", v.x);
| ^^^