Files
ww/test/wcc/956_tuprecv_f64_run.c
Hojun-Cho a95a7a316b test/wcc: carrier ownership repair and driver-contract adaptation
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.
2026-08-07 23:21:04 +09:00

248 lines
7.4 KiB
C

/*
* 956_tuprecv_f64_run (SLIM PIN, #5-C4) — the #121 A-narrow asserttyped stamp
* dimension for the f64 tuple-receive DESTRUCTURE bindings. The runtime VALUE
* rows + cs==ww byte-id migrated to test/lang/tuprecv_f64_test.ww; what stays
* here is the one dimension test-lang has no channel for: a wwstage-STDERR grep
* that w6c_ww emits NO `asserttyped:` diagnostic on the un-annotated float
* destructure binding (the binding must carry a checker type stamp so cgen's
* class-aware spill fires). cstage has no ww asserttyped pass, so this is
* w6c_ww-only by construction (project memory: audit the *_ww binary).
*
* NON-VACUITY (drew C4 mutation gate): the grep is LIVE — pre-stamp HEAD w6c_ww
* fires `asserttyped` on the f64 binding ident (nil n.type_), and the grep
* mechanically fires on a synthetic `asserttyped:` line (self-checked below at
* startup; a broken grep FAILS the test before any row runs).
*
* Slim sibling of the C2 precedent (954 ctl_destr's asserttyped sub-dimension,
* test/lang/tuprecv_test.ww). The 6 rows are the chk_stamped subset of the
* original 956 driver; non-float / control rows carry no stamp dimension and
* live only in the @test file.
*/
#include <stdio.h>
#include <stdlib.h>
#include <errno.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; };
static const struct row rows[] = {
{ "destr_f64_i64_br",
"package main;\n"
"fn issub(n: f64) bool = { return false; };\n"
"fn norm(n: f64) (f64, i64) = {\n"
"\tif (issub(n)) { return (n*2.0, -52); };\n"
"\treturn (n, 0);\n"
"};\n"
"export fn main() i32 = {\n"
"\tlet (m, i) = norm(16.0);\n"
"\tif (m != 16.0) { return 1; };\n"
"\tif (i != 0) { return 2; };\n"
"\treturn 0;\n"
"};\n" },
{ "destr_i64_f64_br",
"package main;\n"
"fn issub(n: f64) bool = { return false; };\n"
"fn norm(n: f64) (i64, f64) = {\n"
"\tif (issub(n)) { return (-52, n*2.0); };\n"
"\treturn (0, n);\n"
"};\n"
"export fn main() i32 = {\n"
"\tlet (i, m) = norm(16.0);\n"
"\tif (m != 16.0) { return 1; };\n"
"\tif (i != 0) { return 2; };\n"
"\treturn 0;\n"
"};\n" },
{ "f64f64_destr_br",
"package main;\n"
"fn issub(n: f64) bool = { return false; };\n"
"fn pair(a: f64, b: f64) (f64, f64) = {\n"
"\tif (issub(a)) { return (a*2.0, b*2.0); };\n"
"\treturn (a, b);\n"
"};\n"
"export fn main() i32 = {\n"
"\tlet (x, y) = pair(3.0, 5.0);\n"
"\tif (x != 3.0) { return 1; };\n"
"\tif (y != 5.0) { return 2; };\n"
"\treturn 0;\n"
"};\n" },
{ "i64_f64_i64_destr",
"package main;\n"
"fn issub(n: i64) bool = { return false; };\n"
"fn tri(a: i64, b: f64, c: i64) (i64, f64, i64) = {\n"
"\tif (issub(a)) { return (a*2, b*2.0, c*2); };\n"
"\treturn (a, b, c);\n"
"};\n"
"export fn main() i32 = {\n"
"\tlet (x, y, z) = tri(3, 2.0, 7);\n"
"\tif (x != 3) { return 1; };\n"
"\tif (y != 2.0) { return 2; };\n"
"\tif (z != 7) { return 3; };\n"
"\treturn 0;\n"
"};\n" },
{ "f64_str_destr",
"package main;\n"
"fn issub(n: f64) bool = { return false; };\n"
"fn fs(n: f64) (f64, str) = {\n"
"\tif (issub(n)) { return (n*2.0, \"x\"); };\n"
"\treturn (n, \"hello\");\n"
"};\n"
"export fn main() i32 = {\n"
"\tlet (f, s) = fs(4.0);\n"
"\tif (f != 4.0) { return 1; };\n"
"\tif (s.len != 5) { return 2; };\n"
"\treturn 0;\n"
"};\n" },
{ "str_f64_destr",
"package main;\n"
"fn issub(n: f64) bool = { return false; };\n"
"fn sf(n: f64) (str, f64) = {\n"
"\tif (issub(n)) { return (\"x\", n*2.0); };\n"
"\treturn (\"hello\", n);\n"
"};\n"
"export fn main() i32 = {\n"
"\tlet (s, f) = sf(4.0);\n"
"\tif (s.len != 5) { return 1; };\n"
"\tif (f != 4.0) { return 2; };\n"
"\treturn 0;\n"
"};\n" },
{ NULL, NULL }
};
/* The asserttyped diagnostic only appears in w6c_ww (the wwstage checker audit);
* an absent w6c_ww means the gate cannot run — fail loud. */
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_ww[1100];
snprintf(w6c_ww, sizeof w6c_ww, "%s/w6c_ww", bin);
if (access(w6c_ww, X_OK) != 0) {
fprintf(stderr, "tuprecv_f64: w6c_ww missing — cannot run the "
"asserttyped stamp gate (the whole point of this pin)\n");
return 1;
}
int n = 0, fail = 0;
/* NON-VACUITY self-check: the grep must FIRE on a literal asserttyped
* line. A grep that never matches would pass every row vacuously. */
{
char probedir[] = "/tmp/wwtupf_probe_XXXXXX";
if (mkdtemp(probedir) == NULL) {
fprintf(stderr, "tuprecv_f64: probe mkdtemp failed\n");
return 1;
}
char probe[128], cmd[256];
snprintf(probe, sizeof probe, "%s/probe.txt", probedir);
int probe_fail = 0;
FILE *p = fopen(probe, "wb");
if (!p) {
fprintf(stderr, "tuprecv_f64: probe open failed\n");
probe_fail = 1;
} else {
int writefail =
fputs("error: asserttyped: e.type_ nil\n", p) == EOF;
if (fclose(p) != 0) writefail = 1;
if (writefail) {
fprintf(stderr, "tuprecv_f64: probe write failed\n");
probe_fail = 1;
} else {
snprintf(cmd, sizeof cmd, "grep -q asserttyped %s", probe);
if (runwait(cmd) != 0) {
fprintf(stderr, "tuprecv_f64: grep self-check FAILED — the "
"asserttyped gate is vacuous\n");
probe_fail = 1;
}
}
}
int cleanfail = 0;
if (unlink(probe) != 0 && errno != ENOENT) cleanfail = 1;
if (rmdir(probedir) != 0) cleanfail = 1;
if (cleanfail)
fprintf(stderr, "tuprecv_f64: probe cleanup failed\n");
if (probe_fail || cleanfail) return 1;
}
for (int i = 0; rows[i].src; i++, n++) {
char tmpdir[] = "/tmp/wwtupf_XXXXXX";
if (mkdtemp(tmpdir) == NULL) {
fprintf(stderr, "row[%s]: mkdtemp failed\n", rows[i].label);
fail++;
continue;
}
char src[128], errf[128], cmd[2048];
snprintf(src, sizeof src, "%s/case.ww", tmpdir);
snprintf(errf, sizeof errf, "%s/err", tmpdir);
FILE *f = fopen(src, "wb");
if (f == NULL) {
fprintf(stderr, "row[%s]: source open failed\n", rows[i].label);
fail++;
goto row_cleanup;
}
int writefail = fputs(rows[i].src, f) == EOF;
if (fclose(f) != 0) writefail = 1;
if (writefail) {
fprintf(stderr, "row[%s]: source write failed\n", rows[i].label);
fail++;
goto row_cleanup;
}
snprintf(cmd, sizeof cmd, "%s -o /dev/null %s 2>%s",
w6c_ww, src, errf);
if (runwait(cmd) != 0) {
fprintf(stderr, "row[%s]: w6c_ww stamp probe failed\n",
rows[i].label);
fail++;
}
snprintf(cmd, sizeof cmd, "grep -q asserttyped %s", errf);
if (runwait(cmd) == 0) {
fprintf(stderr, "row[%s]: w6c_ww emitted asserttyped "
"(destructure float binding unstamped)\n",
rows[i].label);
fail++;
}
row_cleanup:
{
int cleanfail = 0;
if (unlink(errf) != 0 && errno != ENOENT) cleanfail = 1;
if (unlink(src) != 0 && errno != ENOENT) cleanfail = 1;
if (rmdir(tmpdir) != 0) cleanfail = 1;
if (cleanfail) {
fprintf(stderr, "row[%s]: temporary cleanup failed\n",
rows[i].label);
fail++;
}
}
}
if (fail) {
fprintf(stderr, "%d/%d tuprecv_f64 asserttyped-stamp rows failed\n",
fail, n);
return 1;
}
printf("tuprecv_f64: %d/%d ok (asserttyped stamp pin, w6c_ww)\n", n, n);
return 0;
}