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:
@@ -314,9 +314,9 @@ pub const ResolvedModule = struct {
|
||||
try self.scope.put(name, {});
|
||||
if (seen_list.contains(name)) {
|
||||
// A cross-module name collision: drop from the global list
|
||||
// (first-wins) UNLESS this is a per-source decl (type / alias /
|
||||
// const), which must reach registration as a distinct author of
|
||||
// its own module (issues 0104/0105).
|
||||
// (first-wins) UNLESS this is a per-source decl (a named type or
|
||||
// a type-alias const), which must reach registration as a
|
||||
// distinct author of its own module (issues 0104/0105).
|
||||
append_to_global = isPerSourceDecl(decl);
|
||||
} else {
|
||||
try seen_list.put(name, {});
|
||||
@@ -352,12 +352,14 @@ pub const ResolvedModule = struct {
|
||||
if (decl.data.declName()) |name| {
|
||||
if (seen_list.contains(name)) {
|
||||
// First-wins on a cross-module name collision — EXCEPT a
|
||||
// per-source decl (type / alias / const), each of which must
|
||||
// reach registration as a distinct same-name author of its own
|
||||
// module (issues 0104/0105). Only FUNCTIONS keep first-wins
|
||||
// (issue 0102 — the shadowed author stays reachable via its
|
||||
// qualified name / SelectedFunc). Node identity (above) still
|
||||
// de-dups a diamond import of the SAME decl.
|
||||
// per-source decl (a named type or a type-alias const), each
|
||||
// of which must reach registration as a distinct same-name
|
||||
// author of its own module (issues 0104/0105). FUNCTIONS and
|
||||
// VALUE consts keep first-wins (issue 0102 — the shadowed
|
||||
// function stays reachable via its qualified name /
|
||||
// SelectedFunc; same-name value consts are deferred to step
|
||||
// E5). Node identity (above) still de-dups a diamond import of
|
||||
// the SAME decl.
|
||||
if (!isPerSourceDecl(decl)) continue;
|
||||
} else {
|
||||
try seen_list.put(name, {});
|
||||
@@ -370,18 +372,43 @@ pub const ResolvedModule = struct {
|
||||
|
||||
/// A decl that must register PER-SOURCE: each same-name author across modules
|
||||
/// registers against its OWN module rather than collapsing to a single
|
||||
/// first-wins winner. NAMED types and non-function `const_decl`s (type
|
||||
/// aliases + value consts, source-keyed via the alias/const caches) are
|
||||
/// per-source — that is what closes issues 0104/0105. Everything else keeps
|
||||
/// the first-wins name-merge: FUNCTIONS (issue 0102 — the shadowed author
|
||||
/// stays reachable via its qualified name / SelectedFunc), and crucially
|
||||
/// `var_decl`s, including a `#foreign` extern global declared in two files
|
||||
/// (e.g. `__stdinp : *void #foreign;`) that MUST resolve to the ONE libSystem
|
||||
/// symbol, not split into a duplicate `__stdinp.1`.
|
||||
/// first-wins winner. NAMED types and TYPE-introducing `const_decl`s (type
|
||||
/// aliases + inline type decls, source-keyed via the alias cache) are
|
||||
/// per-source — that is what closes issues 0104/0105 for types and aliases.
|
||||
/// Everything else keeps the first-wins name-merge:
|
||||
/// - FUNCTIONS (issue 0102 — the shadowed author stays reachable via its
|
||||
/// qualified name / SelectedFunc),
|
||||
/// - VALUE `const_decl`s (literal / value-expression RHS): a same-name
|
||||
/// value const keeps the pre-E2 first-wins read; cross-module same-name
|
||||
/// value-const support is a separate concern (step E5), NOT part of the
|
||||
/// 0105 type close,
|
||||
/// - and `var_decl`s, including a `#foreign` extern global declared in two
|
||||
/// files (e.g. `__stdinp : *void #foreign;`) that MUST resolve to the ONE
|
||||
/// libSystem symbol, not split into a duplicate `__stdinp.1`.
|
||||
fn isPerSourceDecl(decl: *const Node) bool {
|
||||
return switch (decl.data) {
|
||||
.struct_decl, .enum_decl, .union_decl, .error_set_decl, .protocol_decl, .foreign_class_decl => true,
|
||||
.const_decl => |cd| cd.value.data != .fn_decl,
|
||||
// A `const_decl` is per-source ONLY when its RHS introduces a TYPE
|
||||
// (alias / inline type decl). A VALUE const — literal or value
|
||||
// expression — and a function const keep the first-wins merge.
|
||||
.const_decl => |cd| switch (cd.value.data) {
|
||||
.fn_decl,
|
||||
.int_literal,
|
||||
.float_literal,
|
||||
.bool_literal,
|
||||
.string_literal,
|
||||
.null_literal,
|
||||
.undef_literal,
|
||||
.enum_literal,
|
||||
.struct_literal,
|
||||
.array_literal,
|
||||
.tuple_literal,
|
||||
.binary_op,
|
||||
.unary_op,
|
||||
.chained_comparison,
|
||||
=> false,
|
||||
else => true,
|
||||
},
|
||||
else => false,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user