fix(ir): unify named-const array-dim resolution + kill length-0 fabrication (0083)
A type alias whose dimension is a named const (`Arr :: [N]T`) resolves its dimension eagerly during scanDecls pass 1, on the stateless registration path, which can only read `module_const_map`. Typed consts (`N : s64 : 16`) register only in pass 2 and a forward-declared untyped const had not registered yet, so the stateless resolver saw an empty table, printed a non-fatal warning, fabricated length 0, and continued — yielding a 0-byte alloca, garbage reads, and a segfault for slice/struct elements. - scanDecls pass 0 pre-registers every integer-valued module const before any type alias resolves, so typed, untyped, and forward-referenced consts all resolve identically. - Both dim resolvers now share `program_index.moduleConstInt`, so the stateful body-lowering path and the stateless registration path cannot diverge. - `resolveArrayLen` returns `?u32`; `resolveCompound` yields `.unresolved` on null instead of a 0-length array. The stateful path emits a diagnostic; the alias-registration path surfaces an unresolved alias as a clean compile error that aborts the build. The Vector lane-count `else => 0` is fixed the same way. Regressions: examples/0143 (typed-const dim direct + via alias for s64/string/ struct, forward-ref alias, nested) and examples/1129 (an unresolvable computed dim halts with a clean diagnostic + non-zero exit). Both fail on the pre-fix compiler (garbage/segfault; warning+exit0) and pass after.
This commit is contained in:
@@ -25,6 +25,30 @@
|
||||
> `src/ir/type_bridge.zig`. Regression: `examples/0140-types-named-const-array-dim.sx`
|
||||
> (direct + type-alias + nested `[N][M]T` + union-field dims, s64 / string /
|
||||
> struct element types).
|
||||
>
|
||||
> **Root-cause close-out (attempt 3).** Attempt 2 threaded the const map into
|
||||
> `type_bridge` but the map wasn't fully populated when an alias resolved its
|
||||
> dimension: type aliases (`Arr :: [N]T`) resolve EAGERLY in scanDecls pass 1,
|
||||
> while TYPED consts (`N : s64 : 16`) register only in pass 2 and a
|
||||
> forward-declared untyped const (`Arr :: [N]T; N :: 16`) hadn't registered yet
|
||||
> either — so the stateless resolver saw an empty table, printed a non-fatal
|
||||
> warning, fabricated length 0, and CONTINUED to garbage / a segfault. Three
|
||||
> coordinated fixes: (1) a scanDecls **pass 0** pre-registers every integer-valued
|
||||
> module const into `module_const_map` BEFORE any alias resolves, so typed,
|
||||
> untyped, and forward-referenced consts all resolve identically; (2) both the
|
||||
> stateful and stateless dim resolvers now share one routine
|
||||
> (`program_index.moduleConstInt`) so they cannot disagree again; (3) the length-0
|
||||
> fabrications are GONE — `resolveArrayLen` returns `?u32`, `resolveCompound`
|
||||
> yields the `.unresolved` sentinel on null (never a 0-byte array), the stateful
|
||||
> path emits a diagnostic, and the registration path surfaces an unresolved alias
|
||||
> as a clean compile error that aborts the build (the `type_bridge.zig:270`
|
||||
> Vector-lane `else => 0` is fixed the same way). Files:
|
||||
> `src/ir/program_index.zig`, `src/ir/lower.zig`, `src/ir/type_bridge.zig`,
|
||||
> `src/ir/type_resolver.zig`. Regressions:
|
||||
> `examples/0143-types-typed-const-array-dim.sx` (typed-const dim direct + via
|
||||
> alias for s64/string/struct, forward-ref alias, nested) and
|
||||
> `examples/1129-diagnostics-array-dim-not-const.sx` (an unresolvable computed dim
|
||||
> halts with a clean diagnostic + non-zero exit, not a fabricated 0-length array).
|
||||
|
||||
## Symptom
|
||||
A fixed array whose dimension is a module-global integer constant (`N :: 16;
|
||||
|
||||
Reference in New Issue
Block a user