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:
2026-06-11 04:51:07 +09:00
parent 14b33993c2
commit 64f0ddf01b
8 changed files with 312 additions and 38 deletions

View File

@@ -365,6 +365,25 @@ collide_run(const char *bin)
return rc;
}
/* modfn_run — `ww_ww run <fixture>` and assert exit 6 (#30): the wwstage
* runtime twin of 910's modfn_run. The fixture's main returns `aa() +
* aa.helper()` = 1 + 5; the bare fn must resolve to 1 and the qualified
* module member to 5, so a mis-resolution that still compiled runs to a
* different code. Pins the resolved TARGETS on the wwstage driver. */
static int
modfn_run(const char *bin, const char *fixture, const char *what)
{
char cmd[4096];
snprintf(cmd, sizeof cmd, "%s/ww_ww run %s > /dev/null 2>&1", bin, fixture);
int rc = runwait(cmd);
if (rc != 6) {
fprintf(stderr, "997 FAIL: ww_ww run %s exited %d (expected 6 — bare "
"fn + qualified module resolution)\n", what, rc);
return 1;
}
return 0;
}
int
main(void)
{
@@ -396,11 +415,30 @@ main(void)
"cross-package same-name") != 0) return 1;
if (accept_byteid(bin, "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. wwstage now PROMOTES the same-leaf
* collision in place (use_alias=1), mirroring cstage exactly, so byte-id
* proves the resolved call targets match. Both decl orders are pinned:
* use-before-value promotes via installtop's value-arm, value-before-use
* via installdecl's N_USE arm — both reach the identical single-sym end
* state, so cstage and wwstage agree on every source order. The bare
* `aa()` and qualified `aa.helper()` both resolve, else the compile
* fails. */
if (accept_byteid(bin, "test/wcc/data/modfn_coexist_ok.ww",
"fn named like imported module (use-before-value)") != 0) return 1;
if (accept_byteid(bin, "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 on the wwstage driver,
* pinning that the promoted sym resolves bare fn=1 + module member=5. */
if (modfn_run(bin, "test/wcc/data/modfn_coexist_ok.ww",
"use-before-value") != 0) return 1;
if (modfn_run(bin, "test/wcc/data/modfn_coexist_vbu_ok.ww",
"value-before-use") != 0) return 1;
if (collide_run(bin) != 0) return 1;
printf("@test -T (ww_ww): run ok + cs/ww byte-id + rejects + "
"non-T @test drop cs/ww byte-id + checked-body (#6) + "
"dup fn/type/def/let reject + xpkg/builtin-redecl byte-id + "
"fn-run collision (#23)\n");
"modfn coexist byte-id (#30) + fn-run collision (#23)\n");
return 0;
}