Scalar K vs array K in two modules: minimal repro panics (unresolved-type LLVM tripwire), the std-tail topology silently clobbers (0786 family reads hash.sx's SHA table as its own K). Blocks the PLAN-STDLIB full-tail follow-up; co-blockers (eager global emission, 0601 comptime-meta, error-int shifts) noted in the issue.
4.6 KiB
0115 — same-name consts of different shapes collide across modules (panic / silent clobber)
Symptom. When two modules in one program declare a same-named module
const with DIFFERENT shapes (scalar K : s64 : 4 vs array
K : [4]s64 : .[...]), resolution conflates them instead of selecting
per-author:
- Observed (minimal repro below): compiler PANIC —
unresolved type reached LLVM emission(src/backend/llvm/types.zig:175, the.unresolvedsentinel tripwire). - Observed (full std-tail topology): SILENT WRONG VALUES — a module's
own scalar
Kreads as the other module's array global (prints the array's address or the whole array). Seen corpus-wide whenhash :: #import "modules/std/hash.sx"(hash.sx declares the SHA-256K : [64]s64table) is added to the std.sx namespace tail: examples 0786/0787/0788/0789/0791/0793/0794 (same-name-const family), 0162, 0168 all read hash'sKinstead of their own. - Expected: own-wins / per-author const selection (the documented F2 semantics — readme "Own-wins holds at every one of those sites") applies regardless of the consts' shapes; no cross-shape leakage, no panic.
This blocks the PLAN-STDLIB "full tail" follow-up: fs/process/socket/ json/cli/hash/test cannot join the std.sx namespace tail until same-name consts are robust across every module pulled into every program.
Reproduction (panic variant — minimal, standalone)
// h.sx
K : [4]s64 : .[11, 22, 33, 44];
use_k :: () -> s64 { K[2] }
// main.sx
#import "modules/std.sx";
h :: #import "h.sx";
K : s64 : 4;
main :: () { print("K={} h.use_k={}\n", K, h.use_k()); }
Run main.sx → panic unresolved type reached LLVM emission.
Expected: prints K=4 h.use_k=33.
Reproduction (silent-clobber variant — full topology)
Add the full tail to library/modules/std.sx after the existing
mem/xml/log lines:
fs :: #import "modules/std/fs.sx";
process :: #import "modules/std/process.sx";
socket :: #import "modules/std/socket.sx";
json :: #import "modules/std/json.sx";
cli :: #import "modules/std/cli.sx";
hash :: #import "modules/std/hash.sx";
test :: #import "modules/std/test.sx";
Run bash tests/run_examples.sh → ~50 failures. The const-family
failures (0786 prints a=4318334368 b=4318334368, 0162 prints the whole
64-entry array for K=...) are this bug. (A flat-importing main + a
namespaced array-K module WITHOUT the tail topology resolves correctly —
the silent variant needs the tail's shape, where hash.sx itself
flat-imports std.sx. The panic variant above is the minimal entry point.)
Co-blockers observed in the same experiment (note, possibly separate issues)
- Eager emission bloat: with the tail in place, every program emits
hash's 64-entry
@Ktable plus@OS/@ARCH/@POINTER_SIZEglobals even when unused (visible in every pinned.irsnapshot). Tail modules' globals should emit lazily (only when referenced). - 0601-comptime-meta prints nothing (comptime meta machinery breaks
with the tail in place — root cause unknown, possibly same-name
generic/comptime fn last-wins:
isPlainFreeFnexcludes generic / comptime authors from own-wins rerouting). - 1055/1056 errors-enum-value: user-visible error ints shift when tail modules' error sets join the global error-tag registry (numbering coupling, arguably inherent; snapshot fragility at minimum).
Investigation prompt
Same-name module consts are selected own-wins via selectModuleConst
(F2, src/ir/lower/expr.zig ~1641) over module_const_map — but ARRAY
consts lower as GLOBALS (@K = internal global [4 x s64]), registered in
a different, still last-wins registry (find it: grep the lowering for
where a top-level array const becomes a module global — likely
lowerGlobalDecl / the global-var map in src/ir/lower/decl.zig). The
panic happens because the scalar K's type resolution reads the OTHER
author's array shape (or vice versa) and poisons to .unresolved.
The fix likely needs:
- Source-aware selection for the globals registry, mirroring
selectModuleConst(own-wins, ≥2 flat-visible authors → loud ambiguity) — including the MIXED scalar/array case where the two authors live in different registries today. - The 0786-family examples already pin scalar/scalar own-wins; add a scalar-vs-array pin (the minimal repro above) once fixed.
Verification: run the panic repro (expect K=4 h.use_k=33), then add the
full tail to std.sx and run bash tests/run_examples.sh — the const
family (0786/0787/0788/0789/0791/0793/0794, 0162, 0168) must pass; the
remaining tail failures decompose into co-blockers 1-3 above (file
separately if they persist).