Re-land the value-const analog of the E1-E4 type work, reconciled onto the
current source-keyed resolver and hardened. A same-name VALUE const declared in
multiple flat-imported modules is now resolved per declaring source, not the
global last-wins `module_const_map`.
- imports.zig: `isPerSourceDecl` retains every non-function `const_decl`
per-source (value consts + type aliases), so each same-name author reaches
registration as a distinct author of its own module. Functions and var_decls
keep first-wins.
- lower.zig:
* `selectModuleConst` over `module_consts_by_source` — own-wins; exactly one
flat-visible resolves; >=2 flat-visible bare -> loud ambiguous (consistent
with the 0755 type / 0724 fn / 0782 generic ambiguities). Rewires every
consumer: `comptimeIntNamed`, the runtime-id read, the global-init read,
and the float-name path (`lookupFloatName` / `nameIsFloatTyped`).
* `SourceConstCtx` + `foldSourceConstInt`/`Float` + `sourceConstIsFloatTyped`
fold a selected const's RHS with nested same-name leaves re-selected in
their own author source, so VALUE and array-DIMENSION results are coherent.
* `pinConstAuthorSource` pins each fold level to the SELECTED const's author
(F1), including multi-level cross-module chains.
* cycle guard keyed on (name, author-source), not name alone (F3), so
same-name nested consts across modules do not trip a false cycle.
* `emitModuleConst` takes the author source and pins while folding/lowering.
Registration-time struct/inline-type field dimensions route through the now
source-aware stateful reader; the type-alias dimension path resolves each
alias against its own author's consts.
- program_index.zig: expose `isFloatConstType` / `isCountableConstType` for the
source-aware folds.
examples: 0786 own-wins, 0787 ambiguous (exit 1), 0788 expr-chain value+dim
coherent, 0789 leaf-author-pin, 0790 cross-module cycle-guard (F3), 0791
multi-level cross-module chain, 0792 struct-field registration-time dim.
Single-author corpus byte-identical (524 prior markers green); 531 total.
20 lines
1014 B
Plaintext
20 lines
1014 B
Plaintext
// issue 0105 / F1 / R1 — a MULTI-LEVEL cross-module const chain pins EACH fold
|
|
// level to its own author. `a.sx` declares `M :: 1`, `K :: M + 1` (= 2). `b.sx`
|
|
// declares a full same-name shadow `M :: 10`, `K :: M + 1` (= 11). `c.sx`
|
|
// flat-imports `a.sx` only and declares `BIG :: K + 100` — its `K` is A's, so
|
|
// `BIG` = 102. `main` flat-imports `b.sx` and `c.sx`.
|
|
//
|
|
// Reading `BIG` walks BIG (c) → K (a) → M (a): each level resolves in its OWN
|
|
// author's context, so `BIG` folds A's chain (= 102) even though `main` itself
|
|
// sees only B's `K` (= 11) bare. If any level leaked to the reader's view, `BIG`
|
|
// would fold B's `K` (→ 111). `#import` is non-transitive, so `K` bare in `main`
|
|
// is B's (A is reachable only through C) → bk=11. Output: big=102 bk=11.
|
|
#import "modules/std.sx";
|
|
#import "0791-modules-same-name-const-multi-level-cross-module/b.sx";
|
|
#import "0791-modules-same-name-const-multi-level-cross-module/c.sx";
|
|
|
|
main :: () -> s32 {
|
|
print("big={} bk={}\n", BIG, K);
|
|
0
|
|
}
|