Every surviving carrier now owns its artifacts: checked mkdir/mkdtemp/ fopen acquisition, one all-exit cleanup funnel per carrier, ENOENT- tolerant checked unlinks, exact-path deletion (rm -rf only for an owned pid-keyed dir or a .sepwork beneath one), and cleanup failure fails a passing carrier without overwriting its diagnostic. In the same pass the carriers adapt to the driver contract this branch lands: --sep and WW_PKGCACHE are gone, -S and the /tmp/ww_run_<pid> scratch contract are asserted, and rows whose runtime or reject coverage moved to test/wcc/data fixtures or test/lang @test owners are trimmed to the byte/artifact/diagnostic observations only they can make. Repair and adaptation ride together because most files interleave both in the same hunks; splitting would manufacture intermediate carrier states that never existed and cannot run against either driver.
216 lines
7.3 KiB
C
216 lines
7.3 KiB
C
/*
|
|
* 795_xmod_valglobal_run — project #1 close, the cgen residual of #55.
|
|
* Assembly byte-id net for the cross-module bare value-GLOBAL load
|
|
* miscompile. Sibling of the CHECKER test 794_xmod_ident_prefer,
|
|
* which deliberately omitted a byte-id assertion because THIS cgen bug
|
|
* would diverge the asm independently (see 794's NOTE). With #1 fixed,
|
|
* the byte-id now holds and is asserted here.
|
|
*
|
|
* THE BUG (cgen-only, both stages emit IDENTICAL wrong asm → byte-id
|
|
* was BLIND to it): a bare cross-module value-global load mangled its
|
|
* symbol via a NON-preferring leaf lookup (cstage masym->mod_mangle->
|
|
* mod_lookup first-match; wwstage emitsymname->modlookup). With
|
|
* package aa; export let v: i32 = 7; fn getv() = { return v; }
|
|
* package main; import aa; let v: i32 = 99; main = { return aa.getv(); }
|
|
* the bare `v` inside aa.getv resolved to main.v, and aa.v's DATA slot
|
|
* was ALSO labeled main.v (collision) — so aa.getv() returned 99, not 7.
|
|
* Functions were already correct (they thread a cur_mod hint via mafn/
|
|
* emitfnname); value globals did not.
|
|
*
|
|
* THE FIX (#1): reference-site mangle uses the resolved module (curmod-
|
|
* prefer for bare idents); definition-site mangle uses the decl's OWN
|
|
* module — threaded per-site the way fns already do (cstage mahint with
|
|
* c->cur_mod / d->module; wwstage emitsymnamehint with c.curmod /
|
|
* d.nmod). The value lookup mangles ONLY on an exact (name, module)
|
|
* match and otherwise leaves the name BARE — no first-leaf fallback —
|
|
* because exported value globals are export-skipped from the module map
|
|
* (they keep their bare-name data ABI), and a first-match fallback would
|
|
* mis-mangle an exported `v` onto another module's private `v`. So the
|
|
* exported aa.v stays `v`, the private main.v stays `main.v`, no
|
|
* collision.
|
|
*
|
|
* Runtime ownership moved to the matching r795_* fixtures. This carrier
|
|
* retains the w6c vs w6c_ww `.s` comparison required by rule 10.
|
|
*
|
|
* Single-file multi-package form (like 953): `package aa; ... package
|
|
* main; import aa; ...` in one source, so w6c/w6c_ww see the cross-
|
|
* module reference without -I path plumbing, and the build is self-
|
|
* contained (no selfhost traversal → no .combined.ww fixture race, so
|
|
* this lives in the parallel phase, not the 990-997 skip-set).
|
|
*
|
|
* GATE POLARITY: must stay GREEN. A wrong exit means the value-global
|
|
* mangle regressed (collision returned); a byte-id FAIL means the stages
|
|
* diverged on the mangle (rule-10 violation).
|
|
*
|
|
* SCOPE NOTE: str/slice/array value-globals are intentionally NOT rowed
|
|
* here — `len(str-global)` and indexed-global reads trip a SEPARATE,
|
|
* still-open cs!=ww divergence in the load body (the N_DOT-base / index
|
|
* sibling tracked as #229), orthogonal to this symbol-mangle fix.
|
|
*/
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <unistd.h>
|
|
#include <sys/stat.h>
|
|
#include <sys/wait.h>
|
|
|
|
static int
|
|
runwait(const char *cmd)
|
|
{
|
|
int rc = system(cmd);
|
|
if (rc == -1) return -1;
|
|
if (WIFEXITED(rc)) return WEXITSTATUS(rc);
|
|
return -1;
|
|
}
|
|
|
|
struct row { const char *label; const char *src; int want_exit; };
|
|
|
|
static const struct row rows[] = {
|
|
/* canonical #1: exported aa.v (7) vs private main.v (99); aa.getv()
|
|
* must read aa's v, not collide onto main.v. Pre-fix: 99. */
|
|
{ "i32_let_export_vs_private",
|
|
"package aa;\n"
|
|
"export let v: i32 = 7;\n"
|
|
"export fn getv() i32 = { return v; };\n"
|
|
"package main;\n"
|
|
"import aa;\n"
|
|
"let v: i32 = 99;\n"
|
|
"export fn main() i32 = { return aa.getv(); };\n", 7 },
|
|
/* def-constant flavour: exported def vs private def, same leaf. */
|
|
{ "def_export_vs_private",
|
|
"package aa;\n"
|
|
"export def K: i32 = 5;\n"
|
|
"export fn getk() i32 = { return K; };\n"
|
|
"package main;\n"
|
|
"import aa;\n"
|
|
"def K: i32 = 88;\n"
|
|
"export fn main() i32 = { return aa.getk(); };\n", 5 },
|
|
/* float flavour: exercises the LEAQ+MOVSD load arm and the
|
|
* emit_floatlit_data DATA label. aa.getf() == 2.5 -> i32 2. */
|
|
{ "f64_let_export_vs_private",
|
|
"package aa;\n"
|
|
"export let f: f64 = 2.5;\n"
|
|
"export fn getf() f64 = { return f; };\n"
|
|
"package main;\n"
|
|
"import aa;\n"
|
|
"let f: f64 = 9.9;\n"
|
|
"export fn main() i32 = { return aa.getf(): i32; };\n", 2 },
|
|
{ NULL, NULL, 0 }
|
|
};
|
|
|
|
static int
|
|
slurp_eq(const char *a, const char *b)
|
|
{
|
|
FILE *fa = fopen(a, "rb");
|
|
FILE *fb = fopen(b, "rb");
|
|
if (!fa || !fb) { if (fa) fclose(fa); if (fb) fclose(fb); return -1; }
|
|
int rc = 0;
|
|
for (;;) {
|
|
int ca = fgetc(fa);
|
|
int cb = fgetc(fb);
|
|
if (ca != cb) { rc = -1; break; }
|
|
if (ca == EOF) break;
|
|
}
|
|
fclose(fa); fclose(fb);
|
|
return rc;
|
|
}
|
|
|
|
int
|
|
main(void)
|
|
{
|
|
const char *bin = getenv("BIN");
|
|
if (!bin) bin = "out/bin";
|
|
char absbin[1024];
|
|
if (bin[0] != '/') {
|
|
char cwd[1024];
|
|
if (getcwd(cwd, sizeof cwd) == NULL) return 1;
|
|
snprintf(absbin, sizeof absbin, "%s/%s", cwd, bin);
|
|
bin = absbin;
|
|
}
|
|
|
|
char w6c[1100], w6c_ww[1100];
|
|
snprintf(w6c, sizeof w6c, "%s/w6c", bin);
|
|
snprintf(w6c_ww, sizeof w6c_ww, "%s/w6c_ww", bin);
|
|
if (access(w6c_ww, X_OK) != 0) {
|
|
fprintf(stderr, "xmod_valglobal: w6c_ww missing — cannot run the "
|
|
"cs==ww byte-id gate\n");
|
|
return 1;
|
|
}
|
|
|
|
int n = 0, fail = 0;
|
|
for (int i = 0; rows[i].src; i++, n++) {
|
|
/* src + binary + both .s land under one tmpdir so the
|
|
* compiler's .sepwork scratch stays inside it; a single
|
|
* rm -rf at the end reclaims everything. */
|
|
char tmpdir[64];
|
|
snprintf(tmpdir, sizeof tmpdir, "/tmp/wwxmv_%d_d_%d", getpid(), i);
|
|
/* an unowned dir must never be rm -rf'd below */
|
|
if (mkdir(tmpdir, 0755) != 0) {
|
|
perror(tmpdir);
|
|
fail++;
|
|
continue;
|
|
}
|
|
|
|
char src[128], rmcmd[160];
|
|
snprintf(src, sizeof src, "%s/wwxmv_%d_%d.ww", tmpdir, getpid(), i);
|
|
snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir);
|
|
|
|
FILE *f = fopen(src, "wb");
|
|
if (f == NULL) {
|
|
fail++;
|
|
if (runwait(rmcmd) != 0)
|
|
fprintf(stderr, "row[%s]: cleanup failed: %s\n",
|
|
rows[i].label, rmcmd);
|
|
continue;
|
|
}
|
|
fputs(rows[i].src, f);
|
|
fclose(f);
|
|
|
|
char cmd[2048];
|
|
/* Runtime ownership is r79_xmod_valglobal_*; retain byte-id. */
|
|
char cs_s[128], ws_s[128];
|
|
snprintf(cs_s, sizeof cs_s, "%s/wwxmv_%d_%d_cs.s", tmpdir, getpid(), i);
|
|
snprintf(ws_s, sizeof ws_s, "%s/wwxmv_%d_%d_ww.s", tmpdir, getpid(), i);
|
|
|
|
snprintf(cmd, sizeof cmd, "%s -o %s %s 2>/dev/null", w6c, cs_s, src);
|
|
if (runwait(cmd) != 0) {
|
|
fprintf(stderr, "row[%s]: w6c failed\n", rows[i].label);
|
|
fail++;
|
|
if (runwait(rmcmd) != 0)
|
|
fprintf(stderr, "row[%s]: cleanup failed: %s\n",
|
|
rows[i].label, rmcmd);
|
|
continue;
|
|
}
|
|
snprintf(cmd, sizeof cmd, "%s -o %s %s 2>/dev/null",
|
|
w6c_ww, ws_s, src);
|
|
if (runwait(cmd) != 0) {
|
|
fprintf(stderr, "row[%s]: w6c_ww failed\n", rows[i].label);
|
|
fail++;
|
|
if (runwait(rmcmd) != 0)
|
|
fprintf(stderr, "row[%s]: cleanup failed: %s\n",
|
|
rows[i].label, rmcmd);
|
|
continue;
|
|
}
|
|
int rowdiff = slurp_eq(cs_s, ws_s) != 0;
|
|
if (rowdiff) {
|
|
fprintf(stderr, "row[%s]: cstage/wwstage .s DIFFER "
|
|
"(rule-10 byte-id violation)\n", rows[i].label);
|
|
fail++;
|
|
}
|
|
/* a leaked tmpdir fails an otherwise-green row without
|
|
* masking the byte-id verdict. */
|
|
if (runwait(rmcmd) != 0) {
|
|
fprintf(stderr, "row[%s]: cleanup failed: %s\n",
|
|
rows[i].label, rmcmd);
|
|
if (!rowdiff)
|
|
fail++;
|
|
}
|
|
}
|
|
|
|
if (fail) {
|
|
fprintf(stderr, "%d/%d xmod value-global tests failed\n", fail, n);
|
|
return 1;
|
|
}
|
|
printf("xmod_valglobal: %d/%d ok (cs==ww byte-id)\n", n, n);
|
|
return 0;
|
|
}
|