cstage+test: SK_USE→SK_X promotion sets use_alias
In cmd/wcc/check.c the pass-1.5 SK_USE→SK_DEF/SK_FN/SK_VAR promotion sites forgot to set prev->use_alias = 1 when the imported module's top-level decl shadowed the SK_USE leaf in flat scope. Downstream dot-prefixed lookups (resolve_typename L77, N_DOT L709) gate the module-head walk on (SK_USE || use_alias), so `mod.flag` resolution fell through to "unknown type". The SK_TYPE precedent at L1660 had the line; the three sister sites at L1709/L1722/L1736 now do too, in the same one-line shape and field-set order. The wwstage selfhost/cmd/wcc/check.ww uses coexistence rather than in-place promotion: SK_USE and same-leaf SK_TYPE/FN/DEF/VAR live as separate entries differentiated by sym.mod, and scopelookupinmodule's mod-filter already disambiguates dotted lookups — no use_alias flag needed, so the cstage bug is structurally non-reachable there. An architectural note at installdecl documents this divergence-by-design and warns against porting the flag (adding a field to `sym` changes its size and risks the wwstage cgen amalloc-undersize trap). Audit covered every SK_USE→SK_X promotion path in check.c (4 sites: SK_TYPE already-correct as precedent, SK_DEF/SK_FN/SK_VAR fixed). The surfacing case was lib/fnmatch: `fn fnmatch(...)` shadows the SK_USE leaf, so `fnmatch.flag` failed in worker-fnmatch's WIP — that test (972_fnmatch_run) now flips PASS as live integration proof. test/wcc/699_use_promote_alias.c pins all four rows with a single table-driven driver (type/fn/def/var → use mod; let m: mod.flag = mod.flag.A; return m: i32, expecting exit 42 per row). 995_self_rebuild byte-identity holds.
This commit is contained in:
13
test/wcc/data/usepromote/defmod/defmod.ww
Normal file
13
test/wcc/data/usepromote/defmod/defmod.ww
Normal file
@@ -0,0 +1,13 @@
|
||||
// usepromote/defmod — exports a `def defmod` with the same leaf as
|
||||
// the module name. Paired with pos_def.ww to exercise the SK_USE→
|
||||
// SK_DEF promotion (cmd/wcc/check.c L1709). Mirrors the SK_FN bug
|
||||
// shape: without `use_alias = 1`, the consumer's `defmod.flag` lookup
|
||||
// fails because the promoted-in-place SK_DEF leaf no longer advertises
|
||||
// itself as a module head.
|
||||
|
||||
export def defmod: i32 = 0i32;
|
||||
|
||||
export type flag = enum i32 {
|
||||
NONE = 0,
|
||||
A = 42,
|
||||
};
|
||||
17
test/wcc/data/usepromote/fnmod/fnmod.ww
Normal file
17
test/wcc/data/usepromote/fnmod/fnmod.ww
Normal file
@@ -0,0 +1,17 @@
|
||||
// usepromote/fnmod — exports a `fn fnmod()` with the same leaf as the
|
||||
// module name. Paired with pos_fn.ww to exercise the bug fix at
|
||||
// cmd/wcc/check.c L1722 (SK_USE→SK_FN promotion was missing the
|
||||
// `use_alias = 1` line, so the consumer's `fnmod.flag` lookup walked
|
||||
// resolve_typename's dot branch, found head `fnmod` as SK_FN, and
|
||||
// skipped the module-filtered leaf path → "unknown type fnmod.flag".
|
||||
//
|
||||
// lib/fnmatch is the real-world instance that surfaced this.
|
||||
|
||||
export type flag = enum i32 {
|
||||
NONE = 0,
|
||||
A = 42,
|
||||
};
|
||||
|
||||
export fn fnmod() i32 = {
|
||||
return 0i32;
|
||||
};
|
||||
12
test/wcc/data/usepromote/pos_def.ww
Normal file
12
test/wcc/data/usepromote/pos_def.ww
Normal file
@@ -0,0 +1,12 @@
|
||||
// SK_USE→SK_DEF promotion. Same shape as pos_fn.ww but the imported
|
||||
// module exports `def defmod: i32 = 0` instead of `fn defmod()`.
|
||||
// Pass-1.5 N_DEF case (check.c L1709) promotes the SK_USE leaf to
|
||||
// SK_DEF. Pre-fix it forgot use_alias=1, so `defmod.flag` resolution
|
||||
// failed. Post-fix the build succeeds and exit code = flag.A = 42.
|
||||
|
||||
use defmod;
|
||||
|
||||
fn main() i32 = {
|
||||
let m: defmod.flag = defmod.flag.A;
|
||||
return m: i32;
|
||||
};
|
||||
15
test/wcc/data/usepromote/pos_fn.ww
Normal file
15
test/wcc/data/usepromote/pos_fn.ww
Normal file
@@ -0,0 +1,15 @@
|
||||
// SK_USE→SK_FN promotion (the bug). fnmod exports `fn fnmod()` and
|
||||
// `type flag = enum`. Pass-1 installs SK_TYPE("flag", mod="fnmod") and
|
||||
// SK_USE("fnmod") (the `fn fnmod` isn't installed in pass-1; pass-1
|
||||
// only handles N_USE + N_TYPEDECL). Pass-1.5 then sees the N_FNDECL
|
||||
// "fnmod", finds the SK_USE local, and promotes in place to SK_FN.
|
||||
// Pre-fix that promotion forgot `use_alias = 1`, so `fnmod.flag`
|
||||
// resolution failed with "unknown type fnmod.flag". Post-fix the
|
||||
// build succeeds and exit code = flag.A = 42.
|
||||
|
||||
use fnmod;
|
||||
|
||||
fn main() i32 = {
|
||||
let m: fnmod.flag = fnmod.flag.A;
|
||||
return m: i32;
|
||||
};
|
||||
14
test/wcc/data/usepromote/pos_type.ww
Normal file
14
test/wcc/data/usepromote/pos_type.ww
Normal file
@@ -0,0 +1,14 @@
|
||||
// SK_USE→SK_TYPE regression pin. typmod exports `type typmod = ...`
|
||||
// AND `type flag = enum`. Driver concatenation puts imported decls
|
||||
// first, so pass-1 installs SK_TYPE("typmod") first; the primary's
|
||||
// `use typmod` then hits the self-import branch (check.c L1660) and
|
||||
// sets use_alias=1 on the SK_TYPE entry. We rely on use_alias=1 here
|
||||
// so the dot-prefixed `typmod.flag` lookup resolves to mod="typmod"'s
|
||||
// flag entry. Exit code = flag.A = 42 verifies end-to-end.
|
||||
|
||||
use typmod;
|
||||
|
||||
fn main() i32 = {
|
||||
let m: typmod.flag = typmod.flag.A;
|
||||
return m: i32;
|
||||
};
|
||||
12
test/wcc/data/usepromote/pos_var.ww
Normal file
12
test/wcc/data/usepromote/pos_var.ww
Normal file
@@ -0,0 +1,12 @@
|
||||
// SK_USE→SK_VAR promotion. Imported module exports a top-level
|
||||
// `let varmod: i32 = 0`. Pass-1.5 N_LET case (check.c L1736) promotes
|
||||
// the SK_USE leaf to SK_VAR. Pre-fix it forgot use_alias=1, so
|
||||
// `varmod.flag` resolution failed. Post-fix the build succeeds and
|
||||
// exit code = flag.A = 42.
|
||||
|
||||
use varmod;
|
||||
|
||||
fn main() i32 = {
|
||||
let m: varmod.flag = varmod.flag.A;
|
||||
return m: i32;
|
||||
};
|
||||
17
test/wcc/data/usepromote/typmod/typmod.ww
Normal file
17
test/wcc/data/usepromote/typmod/typmod.ww
Normal file
@@ -0,0 +1,17 @@
|
||||
// usepromote/typmod — exports a `type typmod` with the same leaf as
|
||||
// the module name. Paired with pos_type.ww to pin the SK_USE→SK_TYPE
|
||||
// promotion's use_alias=1 behaviour (cmd/wcc/check.c L1660 / L1677):
|
||||
// the consumer's `typmod.flag` lookup must walk through the alias
|
||||
// even though the leaf sym is SK_TYPE, not SK_USE.
|
||||
//
|
||||
// random.random in lib/ is the canonical real-world instance of this
|
||||
// shape; this fixture replays it as a regression pin.
|
||||
|
||||
export type typmod = struct {
|
||||
x: i32,
|
||||
};
|
||||
|
||||
export type flag = enum i32 {
|
||||
NONE = 0,
|
||||
A = 42,
|
||||
};
|
||||
12
test/wcc/data/usepromote/varmod/varmod.ww
Normal file
12
test/wcc/data/usepromote/varmod/varmod.ww
Normal file
@@ -0,0 +1,12 @@
|
||||
// usepromote/varmod — exports a top-level `let varmod` with the same
|
||||
// leaf as the module name. Paired with pos_var.ww to exercise the
|
||||
// SK_USE→SK_VAR promotion at cmd/wcc/check.c L1736. Same shape as
|
||||
// SK_DEF / SK_FN — without `use_alias = 1`, the consumer's
|
||||
// `varmod.flag` lookup fails.
|
||||
|
||||
export let varmod: i32 = 0i32;
|
||||
|
||||
export type flag = enum i32 {
|
||||
NONE = 0,
|
||||
A = 42,
|
||||
};
|
||||
Reference in New Issue
Block a user