test: migrate Fam8 tuple value tests to @test + reject carriers (#5-C2)

fold-2 chunk C2 (drew's Fam8-13 plan): 14 tuple value-row C drivers migrate to
15 test/lang/*_test.ww @test row-tables (the +1 is 954_tuprecv, slimmed not
deleted -- its value rows split out while the asserttyped-stamp dimension stays
as a carrier-split C pin, mutation-proven non-vacuous). Reject rows move to 32
test/wcc/data/*/case.ww //ww:error carriers (runww asserts the substring in
BOTH stages). The test-lang byte-id (LANGBYTEID) gate gives cs==ww automatically
and is strictly more sensitive than re-running the wwstage leg; floor 59->74.
Tuple surfaced zero cs!=ww as the plan predicted -- no value-only carve. The 945
trio folds in here; 940_global_sret / 940_str_forrange / 926_tagscr untouched
(routed to drew per-file). Test count 402->388 = the 14 retired drivers.
This commit is contained in:
2026-06-24 01:44:13 +09:00
parent 47c7dbc2c8
commit 07b3c74ab0
63 changed files with 3005 additions and 6577 deletions

View File

@@ -1,43 +1,20 @@
/*
* 954_tuprecv_run — runtime + byte-id regression net for #102: the 16B
* whole-tuple-from-call receive (`let t = mk()`, then field reads t.0 /
* t.1).
* 954_tuprecv_run — carrier-split residue of #102 (16B whole-tuple-from-call
* receive). The VALUE rows and the cs==ww .s byte-id dimension migrated to the
* fold-2 row-table test/lang/tuprecv_test.ww (cstage run via test-lang + cs==ww
* via test-lang-byteid). What CANNOT ride a value/byte-id @test is the third
* dimension the old driver also carried: a tool-OUTPUT assertion that w6c_ww
* emits NO `asserttyped:` diagnostic on the un-annotated float-destructure
* binding `let (f, i) = mk()` — the #121 A-narrow stamp net. That is the same
* category as the Class-A asm-presence twins the Fam-7 commit deliberately KEPT
* (a diagnostic-observer grep, not a value or byte-id check), so it stays here
* as a minimal retained pin rather than being silently dropped (drew ruling,
* #5-C2).
*
* Root: wwstage's cglet had NO 16B tuple-from-call receive branch, so a
* `let t = call()` whose callee returns a 2-eightbyte (16B) tuple fell
* through to the generic single-word store (`MOVQ AX, off(BP)`) and
* never spilled word1 (the DX eightbyte) — silent loss of t.1. cstage
* has the branch (cmd/w6c/cgen.c:6652: spill AX -> off+0 AND DX ->
* off+8). The fix mirrors it in cglet.
*
* NOTE on the diagnosis: this is NOT a tupstore cursor off-by-one, and
* it is NOT f64-specific. The destructure form `let (a,b) = mk()`
* (cgmlet + tupstore cursor) was already byte-id; only the whole-tuple
* N_LET receive dropped word1. An f64 element only made it visible
* first, but the all-integer (i64,i64) receive dropped DX too — so the
* "all-integer control" row below is ALSO a fix row (it diverges on
* master 60c3e51, byte-id after the fix), not a pure no-op control.
*
* THIS TEST MUST CATCH A WWSTAGE-ONLY DIVERGENCE. cstage is correct
* before and after, so a cstage-only probe is gate-blind. Each row
* carries BOTH dimensions (modelled on 953_f64crossmod_run):
* (a) cstage `ww build` + run, asserting the exit code — pins the asm
* both stages converge on as runtime-correct.
* (b) w6c vs w6c_ww `.s` cmp — FAILS if the stages diverge. On master
* 60c3e51 (pre-fix) the three scalar-pair single-var rows each
* diverge by exactly one dropped `MOVQ DX, -8(BP)`; post-fix all
* are byte-identical.
*
* Three CONTROL rows pin that the fix touches nothing else: the
* destructure form `let (a,b) = mk()` (cgmlet + tupstore cursor), a
* 32B wide/str-element single-var tuple, and a 16B struct{i64,i64}
* single-var receive — all stay byte-id both pre- and post-fix. The fix
* is in cglet/N_LET, gated on sz==16 AND rettupleof != nil; the struct
* row is the over-catch guard: sz IS 16 but rettupleof returns nil for a
* non-tuple return, so the new branch must NOT hijack the struct's
* generic store. Without that guard a struct receive would route through
* the AX/DX tuple spill and miscompile any struct whose layout differs
* from {word0,word1}.
* Non-vacuous: pre-stamp (HEAD before #121) w6c_ww fired `asserttyped` on the
* f64 binding ident (nil n.type_); post-fix the binder carries the checker
* stamp and the diagnostic is absent. wwstage-only — cstage's check.c has no ww
* asserttyped walker, so the pin invokes w6c_ww directly.
*/
#include <stdio.h>
#include <stdlib.h>
@@ -54,100 +31,14 @@ runwait(const char *cmd)
return -1;
}
struct row { const char *label; const char *src; int want_exit; int chk_stamped; };
static const struct row rows[] = {
/* mixed (f64, i64): f=2.5 -> i32 2, i=7 -> i32 7, 2+7 = 9. The
* f64 element rides its eightbyte in AX at receive and is re-read
* from X0 at field-read; the i64 (t.1) rides DX — the dropped
* word. */
{ "f64_i64",
"package main;\n"
"fn mk() (f64, i64) = { return (2.5, 7); };\n"
"export fn main() i32 = {\n"
"\tlet t = mk();\n"
"\tlet f: f64 = t.0;\n"
"\tlet i: i64 = t.1;\n"
"\treturn (f: i32) + (i: i32);\n"
"};\n", 9 },
/* order-swap (i64, f64): f64 in the 2nd slot. i=7, f=2.5 -> 2,
* 7+2 = 9. Confirms the spill is position-agnostic (both words go
* over the integer cursor regardless of which holds the f64). */
{ "i64_f64",
"package main;\n"
"fn mk() (i64, f64) = { return (7, 2.5); };\n"
"export fn main() i32 = {\n"
"\tlet t = mk();\n"
"\tlet i: i64 = t.0;\n"
"\tlet f: f64 = t.1;\n"
"\treturn (i: i32) + (f: i32);\n"
"};\n", 9 },
/* all-integer (i64, i64): a=5, b=7, 5+7 = 12. NOT a no-op control
* — pre-fix wwstage dropped DX here too (proves the fix is not
* f64-gated). */
{ "i64_i64",
"package main;\n"
"fn mk() (i64, i64) = { return (5, 7); };\n"
"export fn main() i32 = {\n"
"\tlet t = mk();\n"
"\tlet a: i64 = t.0;\n"
"\tlet b: i64 = t.1;\n"
"\treturn (a: i32) + (b: i32);\n"
"};\n", 12 },
/* CONTROL — destructure form `let (f,i) = mk()` (cgmlet + tupstore
* cursor, a different and already-correct path; bootstrap relies on
* it, which is why 990-997 pass). The fix is in cglet/N_LET only, so
* this stays byte-id pre- and post-fix. f=2.5->2, i=7, 2+7 = 9. */
{ "ctl_destr",
"package main;\n"
"fn mk() (f64, i64) = { return (2.5, 7); };\n"
"export fn main() i32 = {\n"
"\tlet (f, i) = mk();\n"
"\treturn (f: i32) + (i: i32);\n"
"};\n", 9, 1 },
/* CONTROL — wide/str element single-var (i64, str) is a 32B tuple
* handled by the separate 32B receive branch; the fix's sz==16 gate
* excludes it, so it stays byte-id pre- and post-fix. t.0 = 7. */
{ "ctl_str",
"package main;\n"
"fn mk() (i64, str) = { return (7, \"hi\"); };\n"
"export fn main() i32 = {\n"
"\tlet t: (i64, str) = mk();\n"
"\treturn t.0: i32;\n"
"};\n", 7 },
/* CONTROL — over-catch guard. A 16B struct{i64,i64} from-call receive
* is sz==16 like the bug rows, but rettupleof returns nil for a
* non-tuple return, so the fix's new branch must NOT hijack it; it
* stays on the generic struct store and byte-id pre- and post-fix.
* Pins that the fix's tuple/struct discrimination (#102) holds. a=5,
* b=7, 5+7 = 12. */
{ "ctl_struct",
"package main;\n"
"type pair = struct { a: i64, b: i64 };\n"
"fn mk() pair = { return pair { a = 5, b = 7 }; };\n"
"export fn main() i32 = {\n"
"\tlet t = mk();\n"
"\treturn (t.a: i32) + (t.b: i32);\n"
"};\n", 12 },
{ 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;
}
/* the ctl_destr construct: an un-annotated float-destructure binding. */
static const char *src =
"package main;\n"
"fn mk() (f64, i64) = { return (2.5, 7); };\n"
"export fn main() i32 = {\n"
"\tlet (f, i) = mk();\n"
"\treturn (f: i32) + (i: i32);\n"
"};\n";
int
main(void)
@@ -162,116 +53,44 @@ main(void)
bin = absbin;
}
char w6c[1100], w6c_ww[1100];
snprintf(w6c, sizeof w6c, "%s/w6c", bin);
char w6c_ww[1100];
snprintf(w6c_ww, sizeof w6c_ww, "%s/w6c_ww", bin);
if (access(w6c_ww, X_OK) != 0) {
fprintf(stderr, "tuprecv: w6c_ww missing — cannot run the "
"cs==ww byte-id gate (the whole point of this test)\n");
"asserttyped-absence pin\n");
return 1;
}
int n = 0, fail = 0;
for (int i = 0; rows[i].src; i++, n++) {
/* src reused across the build-phase (a) AND the w6c/w6c_ww
* byte-id phase (b)/(c); keep src, outbin and both .s under one
* tmpdir and defer a single rm -rf to the end so the compiler's
* .sepwork scratch (derived from the source path) lands in
* tmpdir, not bare /tmp. */
char tmpdir[64], rmcmd[160];
snprintf(tmpdir, sizeof tmpdir, "/tmp/wwtup_%d_d_%d",
getpid(), i);
mkdir(tmpdir, 0755);
snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir);
char tmpdir[64], rmcmd[160], srcp[128], errf[128], cmd[2048];
snprintf(tmpdir, sizeof tmpdir, "/tmp/wwtuprecv_%d", getpid());
mkdir(tmpdir, 0755);
snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir);
snprintf(srcp, sizeof srcp, "%s/ctl_destr.ww", tmpdir);
snprintf(errf, sizeof errf, "%s/err.txt", tmpdir);
char src[128];
snprintf(src, sizeof src, "%s/wwtup_%d_%d.ww",
tmpdir, getpid(), i);
FILE *f = fopen(src, "wb");
if (f == NULL) { fail++; runwait(rmcmd); continue; }
fputs(rows[i].src, f);
fclose(f);
FILE *f = fopen(srcp, "wb");
if (f == NULL) { runwait(rmcmd); return 1; }
fputs(src, f);
fclose(f);
/* (a) cstage build + run; -o pins the binary into tmpdir. */
char outbin[128];
snprintf(outbin, sizeof outbin, "%s/wwtup_%d_%d",
tmpdir, getpid(), i);
int fail = 0;
char cmd[2048];
snprintf(cmd, sizeof cmd, "%s/ww build -o %s %s",
bin, outbin, src);
if (runwait(cmd) != 0) {
fprintf(stderr, "row[%s]: cstage build failed\n",
rows[i].label);
fail++;
runwait(rmcmd);
continue;
}
int got = runwait(outbin);
if (got != rows[i].want_exit) {
fprintf(stderr, "row[%s]: cstage exit %d, want %d\n",
rows[i].label, got, rows[i].want_exit);
fail++;
}
/* (b) cs==ww byte-id gate: emit .s from both stages, cmp.
* FAILS on the pre-fix wwstage divergence (dropped MOVQ DX). */
char cs_s[128], ws_s[128];
snprintf(cs_s, sizeof cs_s, "%s/wwtup_%d_%d_cs.s",
tmpdir, getpid(), i);
snprintf(ws_s, sizeof ws_s, "%s/wwtup_%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++; runwait(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++; runwait(rmcmd); continue;
}
if (slurp_eq(cs_s, ws_s) != 0) {
fprintf(stderr,
"row[%s]: cstage/wwstage .s DIFFER (rule-10 "
"byte-id violation)\n", rows[i].label);
fail++;
}
/* (c) #121 A-narrow stamp gate: the un-annotated float-
* destructure binding must now carry a checker type stamp, so
* w6c_ww emits no `asserttyped:` diagnostic. Non-vacuous —
* pre-stamp (HEAD) w6c_ww fires asserttyped on the f64 binding
* ident (nil n.type_). */
if (rows[i].chk_stamped) {
char errf[128];
snprintf(errf, sizeof errf,
"%s/wwtup_%d_%d_err.txt", tmpdir, getpid(), i);
snprintf(cmd, sizeof cmd,
"%s -o /dev/null %s 2>%s", w6c_ww, src, errf);
runwait(cmd);
snprintf(cmd, sizeof cmd,
"grep -q asserttyped %s", errf);
if (runwait(cmd) == 0) {
fprintf(stderr, "row[%s]: w6c_ww emitted "
"asserttyped (destructure binding "
"unstamped)\n", rows[i].label);
fail++;
}
}
runwait(rmcmd);
/* w6c_ww must compile the construct cleanly AND emit no asserttyped. */
snprintf(cmd, sizeof cmd, "%s -o /dev/null %s 2>%s", w6c_ww, srcp, errf);
if (runwait(cmd) != 0) {
fprintf(stderr, "tuprecv: w6c_ww failed to compile the "
"float-destructure construct\n");
fail++;
}
snprintf(cmd, sizeof cmd, "grep -q asserttyped %s", errf);
if (runwait(cmd) == 0) {
fprintf(stderr, "tuprecv: w6c_ww emitted asserttyped on the "
"un-annotated float destructure binding (#121 stamp net)\n");
fail++;
}
if (fail) {
fprintf(stderr, "%d/%d tuple-receive tests failed\n",
fail, n);
return 1;
}
printf("tuprecv: %d/%d ok (cstage run + cs==ww byte-id)\n", n, n);
runwait(rmcmd);
if (fail) return 1;
printf("tuprecv: asserttyped-absence pin ok (#121)\n");
return 0;
}