test: migrate Fam13 misc checker/coercion value tests to @test (#5-C6)

Final fold-2 chunk. The 12 Fam13 single-file value drivers move from
test/wcc/*_run.c into in-language @test row-tables under test/lang/:

- value rows -> test/lang/*_test.ww (12 files)
- reject rows -> runww //ww:error carriers (13, dual-stage non-vacuous)
- nullable abort rows -> runww //ww:run-exit 1 carriers (3)
- 953_globalslice_arg -> _runonly (cs!=ww checker divergence, #28)
- 788 value_not_type_neg + 953_arrlit_slice reject_assign kept as slim
  rc-only .c pins (divergent-diag dual-reject, mutation-gated); 788 #29

Coverage parity verified row-by-row vs each retired driver; advisor-
ratified carve taxonomy; two-round reviewed. Floor ratchet follows.
This commit is contained in:
2026-06-24 22:59:32 +09:00
parent 246e5bb90e
commit 132ea4ee60
41 changed files with 950 additions and 3160 deletions

View File

@@ -1,43 +1,27 @@
/*
* 953_arrlit_slice_run — runtime + byte-id + reject net for #25/#31: a
* one-step array-LITERAL initialiser for a SLICE local (`let xs:[]T=[..]`).
* 953_arrlit_slice_run -- SLIMMED to the one irreducible asymmetric row.
*
* #31 (silent miscompile, cs!=ww): the #258 arrayslice borrow wrapped the
* un-addressable N_ARRLIT directly as the N_SLICE base; cgen never spilled
* the literal to a stack slot, so .ptr pointed at garbage (`let xs:[]i32=
* [10,20,30]; xs[1]` returned 1; []u8/[]str segfaulted). #25 (over-strict
* reject): a slice target fell through to the exact-element type_eq borrow
* gate, so bare-int-width ([]u8=[1,2,3]) and str elements rejected.
* The #25/#31 array-literal-slice corpus migrated to fold-2 homes (#5-C6): the
* value rows -> test/lang/arrlit_slice_test.ww (@test + T2 byte-id); the
* reject_oob / reject_call / reject_ret rows -> test/wcc/data/arrlit_slice_*
* runww //ww:error carriers (strong shared substrings, both stages).
*
* Fix (re-stamp + per-borrow scratch, both stages symmetric, NO new codegen
* shape): the checker re-stamps the slice arrlit as [count]T (per-element
* coercion + range-check, #25); cgen materialises the borrow base into a
* FRESH per-borrow @slicescr stack slot (distinct slot per borrow — a
* borrow's backing outlives the lowering, so it can't share a cached slot;
* two live borrows would otherwise alias one backing), filled via the shared
* array-init element store (#31). Supported ONLY at a `let` init — in
* call-arg / return / assign position there is no addressable backing, so
* both stages LOUD-REJECT ("bind it to a `let` first"), aligning cstage DOWN
* to wwstage per rule-10; full non-let support is deferred (#33).
* reject_assign CANNOT move to a runww //ww:error carrier: both stages REJECT an
* array-LITERAL assigned to a slice, but at DIFFERENT diagnostic LAYERS -- cstage
* at assignability ("cannot assign [3]int to []i32") and wwstage at the borrow
* gate ("array literal cannot borrow as a slice here; bind it to a `let` first").
* BOTH reject CORRECTLY (the borrow is supported only at a `let` init, #31/#33) --
* this is a benign diag-LAYER divergence, NOT a miscompile, so NO bug ticket. No
* honest shared substring exists for a #20-non-vacuity carrier, and a build-reject
* emits no .s (no byte-id surface). It stays a slim C pin asserting rc!=0 BOTH
* stages -- the position the stages diverge, most worth pinning.
*
* Accept rows (cstage `ww build` + run for exit code, then w6c vs w6c_ww .s
* cmp for the rule-10 byte-id gate):
* - i32_sum let xs:[]i32=[10,20,30]; xs[0]+xs[1]+xs[2] → 60
* - i32_idx xs[1] (the #31 pin: was 1, want 20) → 20
* - u8_coerce let zs:[]u8=[1,2,3]; bare-int→u8 width (#25) → 6
* - u8_typed let xs:[]u8=[10u8,20u8,30u8]; xs[2] → 30
* - i64_stride let xs:[]i64=[7i64,42i64]; xs[1] (8B stride) → 42
* - str_read let ys:[]str=["ab","c"]; ys[0].len*10+ys[1].len → 21
* - len_read let xs:[]i32=[10,20,30]; xs.len → 3
* - multi_live let xs=[1,2,3]; let ys=[4,5]; xs[0]+ys[0] → 5
* (SOUNDNESS PIN: fresh-per-borrow; a shared slot → 4+4=8)
* - borrow_mut xs[1]=99 through the borrow, read back → 99
*
* Reject rows (cs==ww symmetric loud-reject, both w6c and w6c_ww non-zero):
* - reject_oob let q:[]u8=[256,1] → out-of-range element (#25)
* - reject_call sum([1,2,3]) → non-let borrow (#31/#33)
* - reject_ret return [1,2,3] → non-let borrow
* - reject_assign s = [1,2,3] → non-let borrow
* Non-vacuity self-check (the pin CAN go RED): `valid_src` assigns a NAMED array
* (an addressable backing), which the #258 borrow ACCEPTS on both stages (rc==0);
* it proves the pin discriminates the array-LITERAL reject from a legitimate
* array-to-slice assign, not "all builds error". Mutation-checked: binding the
* literal to a `let` first (`let t=[1,2,3]; s=t;`) flips both stages to accept ->
* the reject leg goes RED (verified).
*/
#include <stdio.h>
#include <stdlib.h>
@@ -54,120 +38,57 @@ runwait(const char *cmd)
return -1;
}
/* reject_assign: an array LITERAL in assign position has no addressable backing
* -- both stages reject (cstage assignability, wwstage borrow gate). */
static const char *reject_src =
"package main;\n"
"export fn main() i32 = {\n"
" let s: []i32 = [0, 0];\n"
" s = [1, 2, 3];\n"
" return s[0];\n"
"};\n";
/* Vacuity control: a NAMED array assigned as a slice borrow (#258) -- both
* stages accept. Proves the pin distinguishes accept from reject. */
static const char *valid_src =
"package main;\n"
"export fn main() i32 = {\n"
" let a: [3]i32 = [1, 2, 3];\n"
" let s: []i32 = a[0:1];\n"
" s = a;\n"
" return s[0];\n"
"};\n";
/* build_only -- write `src`, build via `driver` (no run). Returns the build
* exit code (0 = accepted, nonzero = rejected). */
static int
slurp_eq(const char *a, const char *b)
build_only(const char *driver, const char *src, int seq)
{
FILE *fa = fopen(a, "rb"), *fb = fopen(b, "rb");
if (fa == NULL || fb == NULL) {
if (fa) fclose(fa);
if (fb) fclose(fb);
return -1;
}
int ca, cb, eq = 0;
do {
ca = fgetc(fa);
cb = fgetc(fb);
if (ca != cb) { eq = -1; break; }
} while (ca != EOF);
fclose(fa);
fclose(fb);
return eq;
char tmpdir[96], srcp[128], outbin[128], rmcmd[160], cmd[1024];
snprintf(tmpdir, sizeof tmpdir, "/tmp/as_%d_%d", getpid(), seq);
mkdir(tmpdir, 0755);
snprintf(srcp, sizeof srcp, "%s/c.ww", tmpdir);
snprintf(outbin, sizeof outbin, "%s/c", tmpdir);
snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir);
FILE *f = fopen(srcp, "wb");
if (!f) { runwait(rmcmd); return -1; }
fputs(src, f);
fclose(f);
snprintf(cmd, sizeof cmd, "timeout 20 %s build -o %s %s >/dev/null 2>&1",
driver, outbin, srcp);
int brc = runwait(cmd);
runwait(rmcmd);
return brc;
}
struct row { const char *label; const char *src; int want_exit; int reject; };
static const struct row rows[] = {
{ "i32_sum",
"package main;\n"
"export fn main() i32 = {\n"
" let xs: []i32 = [10, 20, 30];\n"
" return xs[0] + xs[1] + xs[2];\n"
"};\n", 60, 0 },
{ "i32_idx",
"package main;\n"
"export fn main() i32 = {\n"
" let xs: []i32 = [10, 20, 30];\n"
" return xs[1];\n"
"};\n", 20, 0 },
{ "u8_coerce",
"package main;\n"
"export fn main() i32 = {\n"
" let zs: []u8 = [1, 2, 3];\n"
" return zs[0]: i32 + zs[1]: i32 + zs[2]: i32;\n"
"};\n", 6, 0 },
{ "u8_typed",
"package main;\n"
"export fn main() i32 = {\n"
" let xs: []u8 = [10u8, 20u8, 30u8];\n"
" return xs[2]: i32;\n"
"};\n", 30, 0 },
{ "i64_stride",
"package main;\n"
"export fn main() i32 = {\n"
" let xs: []i64 = [7i64, 42i64];\n"
" return xs[1]: i32;\n"
"};\n", 42, 0 },
{ "str_read",
"package main;\n"
"export fn main() i32 = {\n"
" let ys: []str = [\"ab\", \"c\"];\n"
" return ys[0].len: i32 * 10 + ys[1].len: i32;\n"
"};\n", 21, 0 },
{ "len_read",
"package main;\n"
"export fn main() i32 = {\n"
" let xs: []i32 = [10, 20, 30];\n"
" return xs.len: i32;\n"
"};\n", 3, 0 },
{ "multi_live",
"package main;\n"
"export fn main() i32 = {\n"
" let xs: []i32 = [1, 2, 3];\n"
" let ys: []i32 = [4, 5];\n"
" return xs[0] + ys[0];\n"
"};\n", 5, 0 },
{ "borrow_mut",
"package main;\n"
"export fn main() i32 = {\n"
" let xs: []i32 = [1, 2, 3];\n"
" xs[1] = 99;\n"
" return xs[1];\n"
"};\n", 99, 0 },
/* Reject rows: out-of-range element + the three non-let contexts. */
{ "reject_oob",
"package main;\n"
"export fn main() i32 = {\n"
" let q: []u8 = [256, 1];\n"
" return q[0]: i32;\n"
"};\n", 0, 1 },
{ "reject_call",
"package main;\n"
"fn sum(s: []i32) i32 = { return s[0]; };\n"
"export fn main() i32 = {\n"
" return sum([1, 2, 3]);\n"
"};\n", 0, 1 },
{ "reject_ret",
"package main;\n"
"fn mk() []i32 = { return [1, 2, 3]; };\n"
"export fn main() i32 = {\n"
" return mk()[0];\n"
"};\n", 0, 1 },
{ "reject_assign",
"package main;\n"
"export fn main() i32 = {\n"
" let s: []i32 = [0, 0];\n"
" s = [1, 2, 3];\n"
" return s[0];\n"
"};\n", 0, 1 },
{ NULL, NULL, 0, 0 },
};
int
main(void)
{
const char *bin = getenv("BIN");
if (!bin) bin = "out/bin";
char absbin[1024];
char absbin[2080];
if (bin[0] != '/') {
char cwd[1024];
if (getcwd(cwd, sizeof cwd) == NULL) return 1;
@@ -175,108 +96,37 @@ main(void)
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, "arrlit_slice: w6c_ww missing — cannot run the "
"cs==ww byte-id gate (the whole point of this test)\n");
return 1;
char cdrv[2120], wdrv[2120];
snprintf(cdrv, sizeof cdrv, "%s/ww", bin);
snprintf(wdrv, sizeof wdrv, "%s/ww_ww", bin);
int wwpresent = (access(wdrv, X_OK) == 0);
int fail = 0, seq = 0;
/* reject leg: both stages must REJECT (rc!=0). */
if (build_only(cdrv, reject_src, seq++) == 0) {
fprintf(stderr, "arrlit_slice[cs]: reject_assign ACCEPTED (want reject)\n");
fail++;
}
if (wwpresent && build_only(wdrv, reject_src, seq++) == 0) {
fprintf(stderr, "arrlit_slice[ww]: reject_assign ACCEPTED (want reject)\n");
fail++;
}
int n = 0, fail = 0;
for (int i = 0; rows[i].src; i++, n++) {
/* src + outbin + cs.s + ws.s all under one tmpdir so the
* compiler's source-derived .sepwork scratch stays inside it;
* single rm -rf deferred to the end of the row. */
char tmpdir[64], rmcmd[160];
snprintf(tmpdir, sizeof tmpdir, "/tmp/wwas_%d_d_%d",
getpid(), i);
mkdir(tmpdir, 0755);
snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir);
char src[128], outbin[128];
snprintf(src, sizeof src, "%s/wwas_%d_%d.ww", tmpdir,
getpid(), i);
snprintf(outbin, sizeof outbin, "%s/wwas_%d_%d", tmpdir,
getpid(), i);
FILE *f = fopen(src, "wb");
if (f == NULL) { runwait(rmcmd); fail++; continue; }
fputs(rows[i].src, f);
fclose(f);
char cs_s[128], ws_s[128];
snprintf(cs_s, sizeof cs_s, "%s/wwas_%d_%d_cs.s", tmpdir,
getpid(), i);
snprintf(ws_s, sizeof ws_s, "%s/wwas_%d_%d_ww.s", tmpdir,
getpid(), i);
char cmd[2048];
if (rows[i].reject) {
/* Both stages must refuse (non-zero). */
snprintf(cmd, sizeof cmd, "%s -o %s %s 2>/dev/null",
w6c, cs_s, src);
if (runwait(cmd) == 0) {
fprintf(stderr, "row[%s]: w6c ACCEPTED a row that "
"must reject\n", rows[i].label);
fail++;
}
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 ACCEPTED a row "
"that must reject\n", rows[i].label);
fail++;
}
runwait(rmcmd);
continue;
}
/* Positive row: cstage build + run for exit code. */
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++;
}
/* rule-10 byte-id: w6c vs w6c_ww .s. */
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++;
}
runwait(rmcmd);
/* vacuity control: both stages must ACCEPT (rc==0). */
if (build_only(cdrv, valid_src, seq++) != 0) {
fprintf(stderr, "arrlit_slice[cs]: vacuity control REJECTED (pin may be vacuous)\n");
fail++;
}
if (wwpresent && build_only(wdrv, valid_src, seq++) != 0) {
fprintf(stderr, "arrlit_slice[ww]: vacuity control REJECTED (pin may be vacuous)\n");
fail++;
}
if (fail) {
fprintf(stderr, "%d/%d arrlit-slice tests failed\n", fail, n);
fprintf(stderr, "arrlit_slice: %d checks failed\n", fail);
return 1;
}
printf("arrlit_slice: %d/%d ok (cstage run + cs==ww byte-id + "
"reject)\n", n, n);
printf("arrlit_slice: reject_assign pin ok\n");
return 0;
}