revert(stdlib): narrow E2 to the 0105 type/alias close; defer value consts to E5 [stdlib E2 attempt-6]
Scope-narrowing revert of the value-const same-name sub-area (attempts 3-5),
per PO/Agra ruling. The 0105 type/alias close (per-source nominal struct
identity, source-keyed type aliases, F1 self/mutual refs, anon-struct
regression) is kept intact; cross-module same-name VALUE consts move to step E5.
- imports.zig: narrow `isPerSourceDecl` so a `const_decl` is retained
per-source ONLY when its RHS introduces a TYPE (alias / inline type decl).
VALUE consts (literal / value-expression RHS) and functions keep the pre-E2
first-wins name-merge. Restores value-const reads to exactly the
wt-stdlib-base (pre-E2) first-wins behavior.
- lower.zig / program_index.zig: restored to the pre-value-const state
(66d10c0) — removes selectModuleConst / SourceConstCtx / pinConstAuthorSource
/ SelectedConst and the rewired comptimeIntNamed / float / runtime /
global-init const reads; value-const reads return to the global path.
- examples: drop 0759-0762 (value-const own-wins / ambiguous / expr-chain-dim
/ leaf-author-pin) — they move to E5.
Kept green: 0752-0758 (same-name structs distinct + own-wins + ambiguous + self
/mutual ref), 0756 (alias per-source), 0170 (anon-struct field distinct).
Gate: zig build + zig build test (423/423, LSP sweep 513 no-crash) +
run_examples (496/0, prior markers byte-identical) + m3te ios-sim build exit 0.
This commit is contained in:
@@ -1,16 +0,0 @@
|
||||
// issue 0105 / F2 — same-name VALUE const, own-wins. Two flat-imported modules
|
||||
// each declare a top-level `K` with a different value and a function that reads
|
||||
// `K` bare. Each function's OWN reference must bind ITS OWN module's `K`
|
||||
// (own-wins), exactly as same-name structs (0754) and functions (0722) do —
|
||||
// NOT the global last-wins author. Pre-fix both `a_k` and `b_k` returned B's
|
||||
// `K` (the const READ path read the global last-wins `module_const_map`); now
|
||||
// `a_k` returns 1 and `b_k` returns 2, resolved by the source-aware const
|
||||
// author selector (`selectModuleConst`).
|
||||
#import "modules/std.sx";
|
||||
#import "0759-modules-same-name-const-own/a.sx";
|
||||
#import "0759-modules-same-name-const-own/b.sx";
|
||||
|
||||
main :: () -> s32 {
|
||||
print("a={} b={}\n", a_k(), b_k());
|
||||
0
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
// Module A authors its OWN value const `K` (1) and reads it bare.
|
||||
K :: 1;
|
||||
a_k :: () -> s64 { return K; }
|
||||
@@ -1,5 +0,0 @@
|
||||
// Module B authors a DIFFERENT same-name value const `K` (2) — a shadow of A's
|
||||
// `K`. Pre-fix the two collapsed last-wins in the global const map, so A's `a_k`
|
||||
// read B's value; now each `K` is selected per declaring source.
|
||||
K :: 2;
|
||||
b_k :: () -> s64 { return K; }
|
||||
@@ -1,14 +0,0 @@
|
||||
// issue 0105 / F2 — same-name VALUE const, two-flat-visible → AMBIGUOUS. `main`
|
||||
// flat-imports two modules that each author a same-name `K` and authors none
|
||||
// itself. A bare `K` reference can't be disambiguated, so the compiler emits a
|
||||
// LOUD diagnostic (consistent with the type ambiguity at 0755 and the function
|
||||
// ambiguity at 0724) and poisons the result — never a silent first-/last-wins
|
||||
// pick.
|
||||
#import "modules/std.sx";
|
||||
#import "0760-modules-same-name-const-ambiguous/a.sx";
|
||||
#import "0760-modules-same-name-const-ambiguous/b.sx";
|
||||
|
||||
main :: () -> s32 {
|
||||
print("K={}\n", K);
|
||||
0
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
// One of two flat authors of value const `K`. A consumer that flat-imports BOTH
|
||||
// and reads `K` bare cannot pick between them.
|
||||
K :: 1;
|
||||
@@ -1,2 +0,0 @@
|
||||
// The second flat author of value const `K`.
|
||||
K :: 2;
|
||||
@@ -1,19 +0,0 @@
|
||||
// issue 0105 / F2 — same-name const EXPRESSION CHAIN, coherent across a value
|
||||
// read AND an array dimension. Two flat-imported modules each declare a same-name
|
||||
// `M` and a same-name `K :: M + 1` that reads `M`. Each module uses ITS OWN `K`
|
||||
// both as a runtime value (`return K`) and as an array dimension (`[K]u8`).
|
||||
//
|
||||
// The fold of a SELECTED const's RHS must resolve nested same-name leaves (the
|
||||
// `M` inside `K :: M + 1`) in the SELECTED author's source context, not through
|
||||
// the global last-wins `module_const_map`. Pre-fix (72f06a1) the dimension fold
|
||||
// recursed through the global map, so `a_len` read B's `M` (= 11) while `a_val`
|
||||
// correctly read A's chain (= 2) — an INCOHERENCE for the same const `K`. Now
|
||||
// both observables agree per module: a_len=2 a_val=2, b_len=11 b_val=11.
|
||||
#import "modules/std.sx";
|
||||
#import "0761-modules-same-name-const-expr-chain-dim/a.sx";
|
||||
#import "0761-modules-same-name-const-expr-chain-dim/b.sx";
|
||||
|
||||
main :: () -> s32 {
|
||||
print("a_len={} a_val={} b_len={} b_val={}\n", a_len(), a_val(), b_len(), b_val());
|
||||
0
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
// Module A authors its OWN chain: `M :: 1`, `K :: M + 1` (= 2). Both the value
|
||||
// read and the array dimension must resolve `K` through A's `M`.
|
||||
M :: 1;
|
||||
K :: M + 1;
|
||||
a_val :: () -> s64 { return K; }
|
||||
a_len :: () -> s64 {
|
||||
arr : [K]u8 = ---;
|
||||
return arr.len;
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
// Module B authors a DIFFERENT same-name chain: `M :: 10`, `K :: M + 1` (= 11).
|
||||
// A shadow of A's `M`/`K`. Pre-fix the dimension fold collapsed to B's `M` for
|
||||
// BOTH modules via the global last-wins map; now each `K`'s RHS leaf resolves to
|
||||
// its own source's `M`.
|
||||
M :: 10;
|
||||
K :: M + 1;
|
||||
b_val :: () -> s64 { return K; }
|
||||
b_len :: () -> s64 {
|
||||
arr : [K]u8 = ---;
|
||||
return arr.len;
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
// issue 0105 / F1 — a UNIQUE expression const's nested leaf folds against the
|
||||
// const's AUTHOR source, not the reading module's. `a.sx` declares `M :: 1` and
|
||||
// `K :: M + 1` (= 2); `b.sx` declares a DIFFERENT same-name `M :: 10` (no `K`).
|
||||
// `main` flat-imports both, so the reader sees two `M`s — but it reads only `K`,
|
||||
// which is unique to `a.sx`. Folding `K`'s RHS must pin `M` to A's source (→ 1),
|
||||
// giving `K = 2`, coherently whether `K` is read as a runtime VALUE (`print K`)
|
||||
// or used as an array DIMENSION (`[K]u8`).
|
||||
//
|
||||
// Pre-fix (8518b66) the nested leaf re-selected `M` from the CALLER's source:
|
||||
// `main` flat-imports two `M`s → `'M' is ambiguous` (value read) / "array
|
||||
// dimension must be a compile-time integer constant" (dimension). Now the fold
|
||||
// pins each level to its selected author's source → val=2 len=2.
|
||||
#import "modules/std.sx";
|
||||
#import "0762-modules-same-name-const-leaf-author-pin/a.sx";
|
||||
#import "0762-modules-same-name-const-leaf-author-pin/b.sx";
|
||||
|
||||
read_dim :: () -> s64 {
|
||||
arr : [K]u8 = ---;
|
||||
return arr.len;
|
||||
}
|
||||
|
||||
main :: () -> s32 {
|
||||
print("val={} len={}\n", K, read_dim());
|
||||
0
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
// Module A authors `M :: 1` and the EXPRESSION const `K :: M + 1` (= 2). `K` is
|
||||
// unique across the program; only A defines it. Its RHS leaf `M` must always
|
||||
// fold against A's `M` (= 1), no matter which module reads `K`.
|
||||
M :: 1;
|
||||
K :: M + 1;
|
||||
@@ -1,5 +0,0 @@
|
||||
// Module B authors only a DIFFERENT same-name `M :: 10` — a shadow of A's `M`,
|
||||
// with NO `K`. When `main` flat-imports both A and B, the reading module sees
|
||||
// two `M`s; folding A's `K :: M + 1` must NOT use this `M` (which would make `M`
|
||||
// ambiguous from the reader's view) — it must pin to A's `M`.
|
||||
M :: 10;
|
||||
@@ -1 +0,0 @@
|
||||
0
|
||||
@@ -1 +0,0 @@
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
a=1 b=2
|
||||
@@ -1 +0,0 @@
|
||||
1
|
||||
@@ -1,5 +0,0 @@
|
||||
error: 'K' is ambiguous: it is declared in multiple flat-imported modules; qualify the reference or remove the duplicate import
|
||||
--> examples/0760-modules-same-name-const-ambiguous.sx:12:21
|
||||
|
|
||||
12 | print("K={}\n", K);
|
||||
| ^
|
||||
@@ -1 +0,0 @@
|
||||
0
|
||||
@@ -1 +0,0 @@
|
||||
a_len=2 a_val=2 b_len=11 b_val=11
|
||||
@@ -1 +0,0 @@
|
||||
0
|
||||
@@ -1 +0,0 @@
|
||||
val=2 len=2
|
||||
Reference in New Issue
Block a user