test/wcc: c6 dual-path sep==combined soak gate (#46)

Make the sep-compile == combined-compile output equivalence a standing
regression test — the last criterion before M4 can delete the combined.ww
embedding model.

989_c6soak_run (phase-1): Tier-A/B + same-leaf collision soak. Two real
roots (utf8: encoding.utf8 dotted-path + strings; collide: strings.contains
+ bytes.contains) built both ways with isolated cold WW_PKGCACHE; asserts
combined-run-exit == sep-run-exit on both drivers, cs==ww per-pkg .s/.wwi,
and two distinct collision labels.

994_w6c_ww (phase-2): Tier-C folded into the existing w6c byte-id oracle.
A sep-built w6c emits byte-identical .s to a combined-built w6c on all five
bootstrap targets (w6c/wwdump/w6a/w6l/ww .combined.ww); .wwi is in the
compare set. The tool binaries themselves differ by a benign constant
link-layout delta — the oracle is tool OUTPUT, not tool-binary identity.

Test-only; the five wwstage binary pins are unchanged.
This commit is contained in:
2026-06-17 00:17:25 +09:00
parent 75a03a7d69
commit 4ae29d6949
3 changed files with 514 additions and 2 deletions

324
test/wcc/989_c6soak_run.c Normal file
View File

@@ -0,0 +1,324 @@
/*
* 989_c6soak_run — M3-tail commit-6 dual-path soak gate, phase-1 leg
* (#46 c6, rob-c6-spec.md Tier-A/B + §3 collision).
*
* The STANDING regression-gate for M4: separate-compilation must be
* behaviorally equivalent to the combined (embed-everything) build on
* real, multi-package code. The oracle is OBSERVABLE OUTPUT, not binary
* identity — a sep-linked binary and a combined-linked binary differ in
* symbol order/layout (rob-c6-spec §2 ★), so we run both and compare
* exit codes, never `cmp` the executables.
*
* Targets (real lib chains, cheap → phase-1):
* - utf8 : encoding.utf8 (DOTTED-path #57) + strings → decode + count
* runes ("héllo" = 5). Exercises the multi-component import
* the combined build resolves by leaf and sep must resolve
* by the full dotted path.
* - collide: strings.contains AND bytes.contains — the SAME leaf `contains`
* exported by two packages (rob-c6-spec §3, the #48/#49 class
* on real code). sep path-qualifies them to DISTINCT symbols;
* the program prints both correct results; the §3 non-vacuity
* check below greps the per-pkg .s to prove the two labels are
* genuinely distinct (disambiguation is real, not luck).
*
* Asserts per target (all COLD — fresh per-stage WW_PKGCACHE, scratch
* wiped each run):
* 1. DUAL-PATH OUTPUT EQUIVALENCE (the teeth): combined-build run-exit ==
* sep-build run-exit == expected, for BOTH driver stages. This is the
* M4 behavioral proof: sep emits a program that behaves identically to
* the combined one.
* 2. cs==ww (rule 10): the cstage `ww` and wwstage `ww_ww` sep-drivers emit
* byte-identical per-package .s and .wwi (the .wwi enters the compare
* set — rob-c6-spec). Both also link to a binary that runs to `expect`.
* 3. §3 NON-VACUITY (collide only): the per-package strings.s defines
* `TEXT strings.contains` and bytes.s defines `TEXT bytes.contains` —
* two DISTINCT symbols. The w6l dup-gate stays silent (no collision);
* both resolve; the program returns 7.
*
* The heavy Tier-C capstone (real tool w6c/wwdump self-compile output
* equivalence) is FOLDED into the 990-997 bootstrap oracle (994_w6c_ww),
* not bolted on here (rob-c6-spec §2 / amendment-B).
*
* Light wwstage-driver test (CLAUDE.md rule 14): all intermediates are
* `-o`-redirected to /tmp, so it is phase-1 parallel-safe. Models
* 989_sepbuild_run.c / 989_sepdotpath_run.c conventions; 989 prefix per
* the sep-gate precedent.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/wait.h>
#include <sys/stat.h>
#include <dirent.h>
static int
runwait(const char *cmd)
{
int rc = system(cmd);
if (rc == -1) return -1;
if (WIFEXITED(rc)) return WEXITSTATUS(rc);
return 1;
}
static const char *
absbin(void)
{
const char *b = getenv("BIN");
if (!b) b = "out/bin";
if (b[0] == '/') return b;
static char buf[2048];
char cwd[1024];
if (getcwd(cwd, sizeof cwd) == NULL) return NULL;
snprintf(buf, sizeof buf, "%s/%s", cwd, b);
return buf;
}
static int
slurp(const char *path, char **outbuf, size_t *outlen)
{
FILE *f = fopen(path, "rb");
if (!f) return -1;
fseek(f, 0, SEEK_END);
long n = ftell(f);
fseek(f, 0, SEEK_SET);
if (n < 0) { fclose(f); return -1; }
char *b = malloc((size_t)n + 1);
if (!b) { fclose(f); return -1; }
if (fread(b, 1, (size_t)n, f) != (size_t)n) { free(b); fclose(f); return -1; }
b[n] = '\0';
fclose(f);
*outbuf = b;
*outlen = (size_t)n;
return 0;
}
static int
files_eq(const char *a, const char *b)
{
char *ba = NULL, *bb = NULL;
size_t na = 0, nb = 0;
if (slurp(a, &ba, &na) < 0 || slurp(b, &bb, &nb) < 0) {
free(ba); free(bb);
return -1;
}
int eq = (na == nb && memcmp(ba, bb, na) == 0);
free(ba); free(bb);
return eq ? 0 : 1;
}
/* 0 if `needle` occurs in the file at `path`, 1 if absent, -1 on read err. */
static int
file_contains(const char *path, const char *needle)
{
char *b = NULL;
size_t n = 0;
if (slurp(path, &b, &n) < 0) return -1;
int found = (strstr(b, needle) != NULL);
free(b);
return found ? 0 : 1;
}
static int
write_file(const char *path, const char *body)
{
FILE *f = fopen(path, "wb");
if (!f) return -1;
fputs(body, f);
fclose(f);
return 0;
}
/* cs==ww over a sep-build's per-package output: every .s/.wwi the cstage
* driver produced in `csdir` must be byte-identical to the wwstage
* driver's same-named file in `wwdir`. Returns the count of mismatches. */
static int
cmp_sepwork(const char *csdir, const char *wwdir, const char *label)
{
DIR *d = opendir(csdir);
if (!d) {
fprintf(stderr, "c6soak FAIL: %s — no cs sepwork %s\n", label, csdir);
return 1;
}
int bad = 0, seen = 0;
struct dirent *ent;
while ((ent = readdir(d)) != NULL) {
const char *nm = ent->d_name;
size_t nl = strlen(nm);
int is_s = (nl > 2 && strcmp(nm + nl - 2, ".s") == 0);
int is_wwi = (nl > 4 && strcmp(nm + nl - 4, ".wwi") == 0);
if (!is_s && !is_wwi) continue;
seen++;
char a[2048], b[2048];
snprintf(a, sizeof a, "%s/%s", csdir, nm);
snprintf(b, sizeof b, "%s/%s", wwdir, nm);
if (files_eq(a, b) != 0) {
fprintf(stderr, "c6soak FAIL: %s — cs!=ww for %s (rule 10)\n",
label, nm);
bad++;
}
}
closedir(d);
/* An existing-but-empty sepwork would pass the cs==ww loop vacuously
* (no per-pkg .s/.wwi to compare); the utf8 root has no other cs==ww
* anchor, so demand at least one compared file. */
if (seen == 0) {
fprintf(stderr, "c6soak FAIL: %s — no .s/.wwi in %s\n", label, csdir);
bad++;
}
return bad;
}
struct root {
const char *label;
const char *src;
int expect;
int collide; /* run the §3 distinct-label non-vacuity check */
};
static struct root roots[] = {
{ "utf8",
"package main;\n"
"import encoding.utf8;\n"
"import strings;\n"
"fn main() i32 = {\n"
" let d = utf8.decode(strings.toutf8(\"h\303\251llo\"));\n"
" let n: i32 = 0;\n"
" for (true) {\n"
" match (utf8.next(&d)) {\n"
" case rune => n += 1;\n"
" case => break;\n"
" };\n"
" };\n"
" return n;\n"
"};\n", 5, 0 },
{ "collide",
"package main;\n"
"import strings;\n"
"import bytes;\n"
"fn main() i32 = {\n"
" let s = strings.contains(\"hello\", \"ell\");\n"
" let b = bytes.contains(strings.toutf8(\"hello\"), strings.toutf8(\"ell\"));\n"
" if (s && b) { return 7; };\n"
" return 1;\n"
"};\n", 7, 1 },
{ NULL, NULL, 0, 0 },
};
int
main(void)
{
const char *bin = absbin();
if (!bin) return 1;
char cwd[1024];
if (getcwd(cwd, sizeof cwd) == NULL) return 1;
/* The real include set the sep producer needs to resolve the lib +
* frontend package graph (verified live; the bare default path grabs
* the in-tree *test.combined.ww fixtures and collides on `main`). */
char inc[4096];
snprintf(inc, sizeof inc, "-I %s/lib -I %s/lib/ww -I %s/selfhost/cmd/wcc",
cwd, cwd, cwd);
char td[64], cmd[8192];
int fail = 0;
snprintf(td, sizeof td, "/tmp/wwc6soak_%d", getpid());
snprintf(cmd, sizeof cmd, "rm -rf %s", td);
runwait(cmd);
mkdir(td, 0755);
for (int i = 0; roots[i].label; i++) {
struct root *r = &roots[i];
char rootww[1024];
snprintf(rootww, sizeof rootww, "%s/%s.ww", td, r->label);
if (write_file(rootww, r->src)) { fail++; continue; }
/* 1. combined build (cstage driver) → run. */
char comb[1024];
snprintf(comb, sizeof comb, "%s/%s.comb", td, r->label);
snprintf(cmd, sizeof cmd,
"timeout 240 %s/ww build %s -o %s %s >/dev/null 2>&1",
bin, inc, comb, rootww);
if (runwait(cmd) != 0) {
fprintf(stderr, "c6soak FAIL: %s combined build\n", r->label);
fail++;
continue;
}
int comb_rc = runwait(comb);
/* sep build both stages, fresh per-stage WW_PKGCACHE so every
* package compiles COLD (a warm shared cache would skip the
* per-pkg .s/.wwi this gate inspects — mirrors 989_pkgcache). */
struct { const char *drv, *tag; char prog[1024]; int rc; }
stg[] = { { "ww", "cs", {0}, -1 }, { "ww_ww", "ww", {0}, -1 } };
int built = 1;
for (int s = 0; s < 2; s++) {
/* `.bin` infix keeps the stage-`ww` output distinct from the
* `<label>.ww` SOURCE (else the build clobbers its own input). */
snprintf(stg[s].prog, sizeof stg[s].prog, "%s/%s.%s.bin",
td, r->label, stg[s].tag);
/* Cache keyed per (root,stage): a cache shared across roots
* would warm-hit a common package (strings) from an earlier
* root and skip emitting its .s into THIS root's sepwork. */
snprintf(cmd, sizeof cmd,
"WW_PKGCACHE='%s/cache.%s.%s' timeout 240 %s/%s build --sep "
"%s -o %s %s >/dev/null 2>&1",
td, r->label, stg[s].tag, bin, stg[s].drv, inc,
stg[s].prog, rootww);
if (runwait(cmd) != 0) {
fprintf(stderr, "c6soak FAIL: %s %s build --sep\n",
r->label, stg[s].drv);
fail++;
built = 0;
continue;
}
stg[s].rc = runwait(stg[s].prog);
}
if (!built) continue;
/* 1. dual-path OUTPUT equivalence: combined == sep (both stages). */
if (comb_rc != r->expect || stg[0].rc != r->expect ||
stg[1].rc != r->expect) {
fprintf(stderr, "c6soak FAIL: %s exits comb=%d sep-cs=%d "
"sep-ww=%d (expected %d)\n", r->label, comb_rc,
stg[0].rc, stg[1].rc, r->expect);
fail++;
}
/* 2. cs==ww (rule 10): per-package .s/.wwi byte-identical. */
char csdir[1024], wwdir[1024];
snprintf(csdir, sizeof csdir, "%s/%s.cs.bin.sepwork", td, r->label);
snprintf(wwdir, sizeof wwdir, "%s/%s.ww.bin.sepwork", td, r->label);
fail += cmp_sepwork(csdir, wwdir, r->label);
/* 3. §3 non-vacuity: distinct same-leaf labels in distinct .s. */
if (r->collide) {
char ss[2048], bs[2048];
snprintf(ss, sizeof ss, "%s/strings.s", csdir);
snprintf(bs, sizeof bs, "%s/bytes.s", csdir);
if (file_contains(ss, "TEXT strings.contains") != 0) {
fprintf(stderr, "c6soak FAIL: %s — strings.s lacks "
"`TEXT strings.contains` (§3 disambiguation)\n",
r->label);
fail++;
}
if (file_contains(bs, "TEXT bytes.contains") != 0) {
fprintf(stderr, "c6soak FAIL: %s — bytes.s lacks "
"`TEXT bytes.contains` (§3 disambiguation)\n",
r->label);
fail++;
}
}
}
snprintf(cmd, sizeof cmd, "rm -rf %s", td);
runwait(cmd);
if (fail) {
fprintf(stderr, "c6soak: %d check(s) failed\n", fail);
return 1;
}
printf("c6soak: dual-path combined==sep run-equivalence on real chains "
"(encoding.utf8 dotted + strings/bytes same-leaf `contains`) — "
"cs==ww per-pkg .s/.wwi + §3 distinct labels\n");
return 0;
}

View File

@@ -17,6 +17,7 @@
#include <string.h>
#include <unistd.h>
#include <sys/wait.h>
#include <dirent.h>
static int
runwait(const char *cmd)
@@ -105,6 +106,94 @@ write_file(const char *path, const char *content)
return 0;
}
static int
files_eq(const char *a, const char *b)
{
char *ba = NULL, *bb = NULL;
size_t na = 0, nb = 0;
if (slurp(a, &ba, &na) < 0 || slurp(b, &bb, &nb) < 0) {
free(ba); free(bb);
return -1;
}
int eq = (na == nb && memcmp(ba, bb, na) == 0);
free(ba); free(bb);
return eq ? 0 : 1;
}
/* Tier-C oracle helper (rob-c6-spec §2 / amendment-B): a sep-built w6c at
* `sepw6c` must EMIT byte-identical asm to the combined-built `w6c_ww` on
* `target`. (We assert OUTPUT equivalence, never `cmp` the tool binaries —
* sep vs combined differ by a constant link-layout delta.) Returns 0 on
* byte-identical .s, non-zero otherwise. */
static int
emit_eq(const char *sepw6c, const char *w6c_ww, const char *target,
const char *label)
{
char a[64], b[64], cmd[4096];
snprintf(a, sizeof a, "/tmp/wwc6tc_%d_sep.s", getpid());
snprintf(b, sizeof b, "/tmp/wwc6tc_%d_comb.s", getpid());
snprintf(cmd, sizeof cmd, "timeout 240 %s -o %s %s 2>/dev/null",
sepw6c, a, target);
if (runwait(cmd) != 0) {
fprintf(stderr, "Tier-C FAIL: sep-w6c emit errored on %s\n", label);
unlink(a);
return 1;
}
snprintf(cmd, sizeof cmd, "timeout 240 %s -o %s %s 2>/dev/null",
w6c_ww, b, target);
if (runwait(cmd) != 0) {
fprintf(stderr, "Tier-C FAIL: combined-w6c_ww emit errored on %s\n",
label);
unlink(a); unlink(b);
return 1;
}
int rc = files_eq(a, b);
if (rc != 0)
fprintf(stderr, "Tier-C FAIL: %s — sep-out != combined-out "
"(M4 output-equivalence broken)\n", label);
unlink(a); unlink(b);
return rc == 0 ? 0 : 1;
}
/* cs==ww over a sep-build's per-package artifacts: every .s/.o/.wwi the
* cstage driver produced in `csdir` must be byte-identical to the wwstage
* driver's same-named file in `wwdir` (rule 10; the .wwi interface files
* enter the compare set per rob-c6-spec §2). Returns the mismatch count
* (≥1 also on an unreadable / empty cs sepwork). */
static int
cmp_sepwork(const char *csdir, const char *wwdir)
{
DIR *d = opendir(csdir);
if (!d) {
fprintf(stderr, "Tier-C FAIL: no cs sepwork %s\n", csdir);
return 1;
}
int bad = 0, seen = 0;
struct dirent *ent;
while ((ent = readdir(d)) != NULL) {
const char *nm = ent->d_name;
size_t nl = strlen(nm);
int is_s = (nl > 2 && strcmp(nm + nl - 2, ".s") == 0);
int is_o = (nl > 2 && strcmp(nm + nl - 2, ".o") == 0);
int is_wwi = (nl > 4 && strcmp(nm + nl - 4, ".wwi") == 0);
if (!is_s && !is_o && !is_wwi) continue;
seen++;
char a[2048], b[2048];
snprintf(a, sizeof a, "%s/%s", csdir, nm);
snprintf(b, sizeof b, "%s/%s", wwdir, nm);
if (files_eq(a, b) != 0) {
fprintf(stderr, "Tier-C FAIL: cs!=ww for %s (rule 10)\n", nm);
bad++;
}
}
closedir(d);
if (seen == 0) {
fprintf(stderr, "Tier-C FAIL: no .s/.o/.wwi in %s\n", csdir);
bad++;
}
return bad;
}
int
main(void)
{
@@ -287,11 +376,91 @@ main(void)
n++;
}
/* ---- Tier-C capstone (#46 c6, rob-c6-spec §2 / amendment-B) ----------
* Fold the dual-path soak into this bootstrap oracle: a w6c built by
* SEPARATE compilation must EMIT byte-identical .s to the combined-built
* w6c_ww on every real bootstrap input, and both driver stages must
* sep-produce byte-identical per-package .s/.o/.wwi (cs==ww on the real
* tool's sep artifacts). This is the load-bearing M4 proof — the
* combined-out==sep-out leg the bootstrap fixed point alone cannot reach.
* We assert OBSERVABLE OUTPUT, never `cmp` the tool binaries (sep vs
* combined differ by a constant link-layout delta). COLD (pid-keyed
* scratch, wiped); heavy (≈ one bootstrap leg) → this gate is phase-2. */
{
char inc[4096], cmd[16384];
snprintf(inc, sizeof inc,
"-I %s/lib -I %s/lib/ww -I %s/selfhost/cmd/wcc", cwd, cwd, cwd);
char w6c_ww[2048], root[2048];
snprintf(w6c_ww, sizeof w6c_ww, "%s/w6c_ww", bin);
snprintf(root, sizeof root, "%s/selfhost/cmd/w6c/main.ww", cwd);
struct { const char *drv, *tag; char prog[2048]; int ok; }
stg[] = { { "ww", "cs", {0}, 0 }, { "ww_ww", "ww", {0}, 0 } };
for (int s = 0; s < 2; s++) {
snprintf(stg[s].prog, sizeof stg[s].prog,
"/tmp/wwc6tc_%d_%s", getpid(), stg[s].tag);
/* Isolated per-(pid,stage) WW_PKGCACHE → COLD + race-free
* (rob-c6-spec §4): the default out/.pkgcache is shared with
* the other phase-2 gates' `ww build`s and would both perturb
* this gate and corrupt under concurrent writes. */
snprintf(cmd, sizeof cmd,
"WW_PKGCACHE='%s.cache' timeout 600 %s/%s build --sep "
"%s -o %s %s >/dev/null 2>&1",
stg[s].prog, bin, stg[s].drv, inc, stg[s].prog, root);
if (runwait(cmd) != 0) {
fprintf(stderr, "Tier-C FAIL: %s build --sep w6c\n",
stg[s].drv);
fail++;
} else stg[s].ok = 1;
n++;
}
/* OUTPUT equivalence on every real bootstrap input: each built
* sep-w6c vs the combined w6c_ww (the M4 combined-out==sep-out bar;
* cs==ww follows since both sep stages match the same reference). */
const char *targ[] = {
"selfhost/cmd/w6c/main.combined.ww",
"selfhost/cmd/wwdump/main.combined.ww",
"selfhost/cmd/w6a/main.combined.ww",
"selfhost/cmd/w6l/main.combined.ww",
"selfhost/cmd/ww/main.combined.ww",
NULL,
};
for (int s = 0; s < 2; s++) {
if (!stg[s].ok) continue;
for (int i = 0; targ[i]; i++) {
char t[2048], label[256];
snprintf(t, sizeof t, "%s/%s", cwd, targ[i]);
snprintf(label, sizeof label, "sep-%s emit %s",
stg[s].tag, targ[i]);
if (emit_eq(stg[s].prog, w6c_ww, t, label) != 0) fail++;
n++;
}
}
/* cs==ww on the real tool's sep .s/.o/.wwi (rule 10). */
if (stg[0].ok && stg[1].ok) {
char csdir[2176], wwdir[2176];
snprintf(csdir, sizeof csdir, "%s.sepwork", stg[0].prog);
snprintf(wwdir, sizeof wwdir, "%s.sepwork", stg[1].prog);
fail += cmp_sepwork(csdir, wwdir);
n++;
}
for (int s = 0; s < 2; s++) {
snprintf(cmd, sizeof cmd, "rm -rf %s %s.sepwork %s.cache",
stg[s].prog, stg[s].prog, stg[s].prog);
runwait(cmd);
}
}
if (fail) {
fprintf(stderr, "w6c_ww: %d/%d diff(s) failed\n", fail, n);
return 1;
}
printf("w6c_ww: byte-identical to wwdump_ww -c on %d corpus inputs "
"(in-source + selfhost combined.ww)\n", n);
"(in-source + selfhost combined.ww) + Tier-C: sep-built w6c emits "
"== combined w6c_ww on all bootstrap inputs, cs==ww sep .s/.o/.wwi\n",
n);
return 0;
}