wcc/ww: promote module-name SK_USE to value kind (use_alias), aligned to cstage
A primary-package top-level decl whose leaf also names a bundled module (`type sym` vs `import sym`; the lib/test->fnmatch->ascii -T floor's `ascii` module vs a `@test fn ascii`) collided in the flat scope: #23's installtop dup-check false-fired "duplicate fn/type" where cstage coexists. cstage keys the module name out of the value namespace by PROMOTING the same-leaf SK_USE in place to the value kind with use_alias=1 (cmd/wcc/check.c:2831/2848/2871/2907/2928/2951), so one correctly-kinded sym serves bare refs (call/structlit/var) while `name.member` still resolves the module via the `kind==SK_USE || use_alias` N_DOT guards (check.c:87/1337). This REVERSES wwstage's documented two-sym coexistence design (lib/ww/sym.ww scopelookupuselocal): keeping the SK_USE as a separate coexisting sym ripples into every bare-reference resolver (~25 scopelookup sites), and a missed site is a byte-id-consistent-but-wrong cat-A risk the gate cannot prove away — the same failure mode retired with the name-keyed variant-match cluster. The promote model is correct by construction: one sym of the right kind, identical to cstage. sym gains a use_alias field; the three N_DOT/N_CALL module-qualified guards honor use_alias. cstage installs every SK_USE in a dedicated first pass, so its value-arm promote is order-INDEPENDENT; wwstage installs in source order, so BOTH directions of the collision are promoted to reach cstage's identical single-sym end state: - use-before-value (`import aa` then `fn aa`): installtop promotes the pre-installed SK_USE to the value kind (use_alias=1). - value-before-use (`fn aa` then `import aa`): installdecl's N_USE arm promotes the pre-installed value sym in place (set use_alias=1, no coexisting SK_USE), mirroring cstage's self-import N_USE arm (check.c:2823-2834 `if (prev) prev->use_alias = 1`). Both orders compile + are cs/ww byte-identical AND byte-identical to each other. Cannot split: promote without the guards leaves `name.member` red on the promoted sym; the guards without promote are inert (no use_alias is ever set) — no bisect-clean intermediate. (#30) Pins (910/997): modfn_coexist_ok (use-before-value) AND modfn_coexist_vbu_ok (value-before-use) both accept on cstage + are cs/ww byte-id + run to exit 6 (bare fn and qualified module both resolve); the dup_fn row still rejects both stages (regression). fnmatch byte-id holds. The order-dependence is exactly what regresses silently, so both orders are pinned.
This commit is contained in:
@@ -317,6 +317,25 @@ collide_run(const char *bin, const char *comp, const char *drv)
|
||||
return rc;
|
||||
}
|
||||
|
||||
/* modfn_run — `<drv> run <fixture>` and assert exit 6 (#30). The fixture's
|
||||
* main returns `aa() + aa.helper()` = 1 + 5: the bare `aa()` must resolve to
|
||||
* the fn (1) and the qualified `aa.helper()` to the module member (5). A
|
||||
* mis-resolution that still compiled would run to a different code; this
|
||||
* pins the resolved TARGETS, not just acceptance. */
|
||||
static int
|
||||
modfn_run(const char *bin, const char *drv, const char *fixture, const char *what)
|
||||
{
|
||||
char cmd[4096];
|
||||
snprintf(cmd, sizeof cmd, "%s/%s run %s > /dev/null 2>&1", bin, drv, fixture);
|
||||
int rc = runwait(cmd);
|
||||
if (rc != 6) {
|
||||
fprintf(stderr, "910 FAIL: %s run %s exited %d (expected 6 — bare fn "
|
||||
"+ qualified module resolution)\n", drv, what, rc);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
@@ -347,11 +366,29 @@ main(void)
|
||||
"cross-package same-name") != 0) return 1;
|
||||
if (accept(bin, "w6c", "test/wcc/data/builtin_redecl_ok.ww",
|
||||
"builtin nomem redecl (carve-out)") != 0) return 1;
|
||||
/* #30 — a top-level fn whose leaf matches an imported module name
|
||||
* coexists with the module bareword (different namespaces). Accept
|
||||
* proves both the bare `aa()` (fn) and qualified `aa.helper()`
|
||||
* (module) resolve; a mis-resolution would fail to compile. Both
|
||||
* decl orders are pinned (use-before-value AND value-before-use): the
|
||||
* order-dependence is exactly what regresses silently — cstage is
|
||||
* order-independent, wwstage closes both directions via the symmetric
|
||||
* promotes in installtop + installdecl's N_USE arm. */
|
||||
if (accept(bin, "w6c", "test/wcc/data/modfn_coexist_ok.ww",
|
||||
"fn named like imported module (use-before-value)") != 0) return 1;
|
||||
if (accept(bin, "w6c", "test/wcc/data/modfn_coexist_vbu_ok.ww",
|
||||
"fn named like imported module (value-before-use)") != 0) return 1;
|
||||
/* runtime-resolve: both orders run to exit 6 (bare fn=1 + module
|
||||
* member=5), pinning the resolved targets on the cstage driver. */
|
||||
if (modfn_run(bin, "ww", "test/wcc/data/modfn_coexist_ok.ww",
|
||||
"use-before-value") != 0) return 1;
|
||||
if (modfn_run(bin, "ww", "test/wcc/data/modfn_coexist_vbu_ok.ww",
|
||||
"value-before-use") != 0) return 1;
|
||||
if (collide_run(bin, "w6c", "ww") != 0) return 1;
|
||||
|
||||
printf("@test -T: run ok + user-main and bad-signature rejected + "
|
||||
"non-T @test drop + checked-body + dangling-call link-fail (#6) + "
|
||||
"dup fn/type/def/let reject + xpkg + builtin-redecl accept + "
|
||||
"fn-run collision (#23)\n");
|
||||
"modfn coexist (#30) + fn-run collision (#23)\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user