wcc/ww: reject duplicate top-level decls, aligned to cstage

installdecl routes all four kinds (fn/type/def/let) through installtop,
which turns scopedefineinmodule's nil return into cstage's exact
"duplicate <kind> <name>" reject, keyed (name,mod) so cross-package
same-leaf decls coexist. Builtin redecls are dropped, not dup-errored:
cstage never scopes builtins (lookup_builtin first, check.c:69), so a
user redecl is dead there — wwstage mirrors via scopesamekeysym +
no-source-decl test. -T synth __wwtests installs direct, mirroring
check.c:3079. Closes the silent dup-fn hole (user fn run vs lib/test
run built a broken test binary with no diagnostic). Per-kind reject
rows + cross-package/builtin accept byte-id rows + -T collision parity
row in 910/997. (#23-team, category-A addendum closed)
This commit is contained in:
2026-06-11 00:57:43 +09:00
parent 16c83e70d3
commit 19e9535ef4
13 changed files with 448 additions and 50 deletions

View File

@@ -288,6 +288,83 @@ reject_plain(const char *bin, const char *fixture, const char *what)
return 0;
}
/* accept_byteid — a #23 legal-accept control: `<fixture>` must COMPILE on
* BOTH stages (no false dup reject) AND be cs/ww byte-identical (rule 10).
* Used for the cross-package same-leaf control (keying is (name, mod), so
* distinct-package leaves coexist) and the builtin-redecl carve-out (the
* one structural point where wwstage seeds builtins and cstage does not —
* byte-id proves the drop-the-redecl mirror is exact). */
static int
accept_byteid(const char *bin, const char *fixture, const char *what)
{
int pid = getpid();
char cs[256], ws[256], cmd[4096];
snprintf(cs, sizeof cs, "/tmp/at997ab_c_%d.s", pid);
snprintf(ws, sizeof ws, "/tmp/at997ab_w_%d.s", pid);
snprintf(cmd, sizeof cmd,
"%s/w6c %s -o %s 2>/dev/null", bin, fixture, cs);
if (runwait(cmd) != 0) {
fprintf(stderr, "997 FAIL: w6c rejected %s\n", what);
return 1;
}
snprintf(cmd, sizeof cmd,
"%s/w6c_ww %s -o %s 2>/dev/null", bin, fixture, ws);
if (runwait(cmd) != 0) {
fprintf(stderr, "997 FAIL: w6c_ww rejected %s\n", what);
return 1;
}
char *bc = NULL, *bw = NULL;
size_t nc = 0, nw = 0;
int rc = 0;
if (slurp(cs, &bc, &nc) < 0 || slurp(ws, &bw, &nw) < 0) {
fprintf(stderr, "997 FAIL: slurp %s asm\n", what);
rc = 1;
} else if (nc != nw || memcmp(bc, bw, nc) != 0) {
fprintf(stderr, "997 FAIL: %s asm differs (cs %zu, ww %zu)\n",
what, nc, nw);
rc = 1;
}
free(bc); free(bw);
unlink(cs); unlink(ws);
return rc;
}
/* collide_run — a @test unit defining a user `fn run` collides with
* lib/test's bound runner once `ww test -c` bundles it; `w6c_ww -T` of the
* combined must loud-reject the duplicate (#23). Pre-fix wwstage built a
* binary that called the user run and silently skipped every @test. */
static int
collide_run(const char *bin)
{
int pid = getpid();
char stem[256], comb[300], cmd[4096];
snprintf(stem, sizeof stem, "/tmp/at997cr_%d", pid);
snprintf(comb, sizeof comb, "%s.combined.ww", stem);
snprintf(cmd, sizeof cmd,
"%s/ww test -c -o %s test/wcc/data/attest_userrun.ww > /dev/null 2>&1",
bin, stem);
runwait(cmd);
if (access(comb, 0) != 0) {
fprintf(stderr, "997 FAIL: ww build produced no %s\n", comb);
return 1;
}
snprintf(cmd, sizeof cmd, "%s/w6c_ww -T %s -o /dev/null 2>/dev/null",
bin, comb);
int rc = 0;
if (runwait(cmd) == 0) {
fprintf(stderr, "997 FAIL: w6c_ww -T accepted user `fn run` collision "
"(expected duplicate-fn reject)\n");
rc = 1;
}
unlink(comb);
char tmp[320];
snprintf(tmp, sizeof tmp, "%s.s", stem); unlink(tmp);
snprintf(tmp, sizeof tmp, "%s.o", stem); unlink(tmp);
unlink(stem);
return rc;
}
int
main(void)
{
@@ -303,7 +380,27 @@ main(void)
if (reject_plain(bin, "test/wcc/data/attest_undefbody.ww",
"undefined symbol in @test body") != 0) return 1;
/* #23 — wwstage top-level duplicate-decl reject (one row per kind:
* all four route through installtop) + legal cross-package control
* (byte-id) + the builtin-redecl carve-out (byte-id) + the -T
* `fn run` collision parity row. */
if (reject_plain(bin, "test/wcc/data/dup_fn.ww",
"same-module duplicate fn") != 0) return 1;
if (reject_plain(bin, "test/wcc/data/dup_type.ww",
"same-module duplicate type") != 0) return 1;
if (reject_plain(bin, "test/wcc/data/dup_def.ww",
"same-module duplicate def") != 0) return 1;
if (reject_plain(bin, "test/wcc/data/dup_let.ww",
"same-module duplicate let") != 0) return 1;
if (accept_byteid(bin, "test/wcc/data/dup_xpkg_ok.ww",
"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;
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)\n");
"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");
return 0;
}