Files
ww/test/wcc/944_alias_cgen_b5_run.c
Hojun-Cho e36af4fe7e cgen: B5-c2 #73 graduation — the 6 tripwired field gates chase, tripwire deleted
Close-by-construction replacing containment — the designed graduation
path from F1-c1's commit body. The 6 fld_alias_tripwire call sites
(indexed-elem field store/read, heap struct-lit field fill, tuple-elem
read, ptr-chain field read, static struct-lit emit) chase their fu
through type_chase_named; the 6 tripwire calls AND the helper itself
(incl. its :447 peel) are DELETED. Raw `->under` in cgen.c 69→62.
#73 CLOSES.

TRAIN INVARIANT holds: cs-only; w6c_ww/ww_ww bit-identical to the
bcd948d baseline md5s (28ad889042bad8006f1997cbcec94805 /
4e9ca8741f19e1f68219ff799a5e5a14). ZERO new corpus movers vs the c1
tip (kb*/kna corpus + five mains byte-NEUTRAL — the chased gates only
fire on 2+-level alias aggregate fields, none in corpus).

Gate-arm graduations (pre = loud "#73" fatal on cs, ww ok/0; post =
0/0 BYTE-ID): slice/str/tagged arms at the indexed STORE gate
(g73_idxstore/g73_strfield/g73_tagfield), slice arm at the indexed
READ / ptr-chain READ / tuple-elem READ gates (g73_idxread/g73_ptrread/
g73_tupread), nested-struct arm at the static emit gate
(g73_static_struct). The existing 944_alias_accept_run tripwire bound
row graduates K_BUILDERR_CS → K_RUN.

Two arms cannot pin the full 0/0 byte-id cell — documented, not silent:
  - heap fill (g73_heapfill, COMPILE-only pin): bare /tmp programs
    never link malloc (both stages, pre-existing infra) and ww's
    deref-field READ carries the #24-kin field(SB) leak; the chased
    FILL bytes verified byte-id by hand against the plain (non-alias)
    control — divergence shape identical, all of it in the pre-existing
    read sites.
  - str-field static emit (g73_static_str): the #73 fatal gave way to
    the pre-existing #129 A.2 foldability loud on cs — now both-loud
    twin texts (fill0 class), pinned as K_BUILDERR.
  - struct-copy arm: NO runnable repro reaches these gates — indexed
    whole-struct field reads take the (already chased, byte-id) address
    spine, and tuple-of-struct louds upstream on BOTH stages (#54-kin
    "aggregate init from unhandled rhs shape"). The arm's only carrier
    was the heap gate, covered by the compile pin above.

944_alias_cgen_b5_run grows 16→25 rows (65 checks); all 944-family
suites green; sizelint 0.
2026-06-06 02:19:39 +09:00

731 lines
26 KiB
C

/*
* 944_alias_cgen_b5_run — #5 alias arc F2b (B5 train): cstage cgen
* helper + funnel internalization through type_chase_named (c1), the
* #73 tripwire graduation (c2), the #89 cgreturn return-position widen
* (c3) and the #93 deref-index pointee chase (c4). All cs-only: every
* graduation is a DIVERGE→byte-id flip (cs aligns UP to ww's already-
* chasing asm); zero selfhost/lib bytes move across the train, so the
* _ww binaries stay bit-identical (the crossing detector).
*
* Row sources are ken's B5 oracle probes (/tmp/ken_b5/src,
* .ai/ken-b5-oracle.md + its c1-BOUNDARY ADDENDUM) and the c3/c4
* seeds (/tmp/ken_na, kb4).
*
* row | shape (oracle row) | cs/ww
* --------------------+-------------------------------------+------
* signed_ctl | kb5_signed: 2-lvl alias i8 field |
* | load (fld_issigned) — classifiers |
* | recurse, NO-mover control | 0/0
* targ_2lvl | kb5_targ: 2-lvl alias (void|i64) |
* | param ≤48B (tagged_arg_size) — was |
* | cs LIVE exit-1, c1 graduation | 0/0
* tmem_2lvl | kb5_tmem: >48B memarg twin |
* | (tagged_memarg_size) — graduation | 0/0
* wpush_2lvl | kb5_wpush: call-site widen, literal |
* | arg (:2905 du) — divergence flip | 0/0
* wstore_2lvl/_1lvl | kb5_wstore/wstore1: let-route |
* | controls (du arrives chased |
* | upstream — ken FLAG-1), NEUTRAL | 0/0
* wstore_a_bound_b6 | kb5_wstore_a: ASSIGN-route re-store |
* | — both-correct divergent; the |
* | ident-lhs N_ASSIGN gates in the |
* | cgexpr INLINE set (B6), NOT the |
* | :2456 funnel (C1-CORR-2, corrects |
* | rob R2) — byte-id waived until B6 | 0/0
* succ_bound_c3 | kb5_succ: `?`-success remap over |
* | 2-lvl alias result — both-correct |
* | divergent at RETURN positions only |
* | (:12278/:12318/:12322 family, |
* | C1-CORR-1) — joins c3's graduation |
* | set; byte-id waived until c3 | 0/0
* null_2lvl | kb5_null: nullable fold + deref |
* | (type_isnullable/nullable_ptr_tag) |
* | — divergence flip | 0/0
* f32p_2lvl | kb5_f32p: nested 2-lvl-alias f64 |
* | field struct param |
* | (struct_float_class) — flip | 0/0
* fill0_ctl | kb5_fill0: named-struct array elem |
* | in struct lit — LOUD both stages |
* | (twin texts share the experr) | err/err
* fill2_bound100 | kb5_fill2: 1-alias-lvl elem — was |
* | both-wrong-IDENTICAL gate-blind; c1 |
* | :3195 chase flips cs LOUD, ww stays |
* | silent-wrong exit 1. DESIGNED |
* | DIVERGENCE until the ww twin gate |
* | (task #100) lands — dual-cell pin | err/1
* tuparg_bound99 / | kb5_tuparg(1): literal named-tuple |
* tuparg1_bound99 | arg — cs checker-rejects (#86-kin), |
* | WW RUNS WRONG exit 1 (task #99, |
* | metric-1 ww side). Dual-cell pin | err/1
* tuparg_cast_bound99 | kb5_tuparg_c: cast spelling dodges |
* | the cs checker; the :249 chase made |
* | cs run CORRECT (LIVE c1 graduation, |
* | C1-CORR-3 — corrects rob R3 + ken |
* | FLAG-2); ww still WRONG exit 1 |
* | (#99). Two-key pin: cs-0 earned + |
* | ww-1 pinned-wrong; byte-id waived |
* | until #99 re-pins to full byte-id | 0/1
* tupglobal_bound86 | kb5_tupglobal: alias-tuple global — |
* | cs checker-dead (#86), ww runs 0. |
* | #85 type_unwrap close is SITE- |
* | closure with zero live graduations |
* | — this row pins the bound | err/0
* ---- c2 (#73 graduation: tripwire deleted, 6 fu gates chased) --
* g73_idxstore / | slice / str / tagged 2-lvl alias |
* g73_strfield / | field at the indexed-elem STORE |
* g73_tagfield | gate — pre = loud "#73" fatal | 0/0
* g73_idxread / | slice arm at the indexed-elem READ, |
* g73_ptrread / | ptr-chain READ and tuple-elem READ |
* g73_tupread | gates — pre = loud "#73" fatal | 0/0
* g73_static_struct | nested-struct arm at the static |
* | struct-lit emit gate — pre = "#73" | 0/0
* g73_heapfill | str arm at the heap struct-lit fill |
* | gate — COMPILE-only pin: bare /tmp |
* | programs never link malloc (both |
* | stages, pre-existing infra) and the |
* | ww deref-field READ carries the |
* | #24-kin field(SB) leak, so run + |
* | byte-id cells are unavailable; the |
* | FILL bytes themselves verified |
* | byte-id by hand (= plain control) | asm
* g73_static_str | str-field static emit: the #73 |
* | fatal gave way to the #129 A.2 |
* | foldability loud — now fill0-class |
* | both-loud (twin texts) | err/err
*
* K_RUN rows build+run BOTH drivers (cs exit==cswant, ww exit==wwwant)
* and assert cstage/wwstage asm byte-id. K_RUN_NOID asserts both run
* cells but waives byte-id — cite the blocking task/commit at the row.
* K_CSERR_WWRUN is the dual-cell bound kind (the inverse of
* 944_alias_accept_run's K_RUN_CS_WWERR): the cstage build must FAIL
* with experr AND the wwstage build+run must exit wwwant — both cells
* asserted so neither the cs loudness nor the ww behavior can drift
* silently while the cited task is parked. NNN<950, self-contained
* /tmp sources, no imports (944 precedent).
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.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;
}
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), cb = fgetc(fb);
if (ca != cb) { rc = -1; break; }
if (ca == EOF) break;
}
fclose(fa); fclose(fb);
return rc;
}
#define K_RUN 0 /* build+run BOTH, exits==wants, + byte-id */
#define K_BUILDERR 1 /* build FAILS with experr on BOTH drivers */
#define K_RUN_NOID 2 /* build+run BOTH, exits==wants, byte-id
* SKIPPED — cite the blocking task */
#define K_CSERR_WWRUN 3 /* dual-cell bound row: cstage build must
* FAIL with experr; wwstage build+run,
* exit==wwwant — cite the blocking task */
#define K_COMPILES 4 /* w6c AND w6c_ww must COMPILE (no run, no
* byte-id) — cite why the other cells are
* unavailable at the row */
struct row { const char *label; const char *src;
int cswant; int wwwant; int kind; const char *experr; };
/* errlog_has — a builderr cell must fail WITH its diagnostic; any other
* failure (parse error, crash, hang-kill) is a vacuous reject (940
* precedent). */
static int
errlog_has(const char *path, const char *needle)
{
FILE *f = fopen(path, "rb");
if (!f) return 0;
char buf[8192];
size_t got = fread(buf, 1, sizeof buf - 1, f);
fclose(f);
buf[got] = '\0';
return strstr(buf, needle) != NULL;
}
static const struct row rows[] = {
/* ---- c1: helper + funnel internalization (the F2c-cs fuse) */
{ "signed_ctl",
"package main;\n"
"type s0 = i8;\n"
"type s1 = s0;\n"
"type st = struct { f: s1, g: s1 };\n"
"export fn main() i32 = {\n"
" let x: st;\n"
" x.f = -5;\n"
" x.g = 3;\n"
" if (x.f >= 0) { return 1; };\n"
" let w: i64 = x.f: i64;\n"
" if (w != -5) { return 2; };\n"
" return 0;\n"
"};\n", 0, 0, K_RUN, NULL },
/* LIVE c1 graduation: tagged_arg_size single-peeled the 2-level
* alias union param to 0 → wrong arg path (cs exit 1 SILENT, ww
* correct). */
{ "targ_2lvl",
"package main;\n"
"type u0 = (void | i64);\n"
"type u = u0;\n"
"fn h(v: u) i32 = {\n"
" match (v) {\n"
" case let n: i64 => { if (n != 42) { return 1; }; return 0; };\n"
" case void => { return 2; };\n"
" };\n"
"};\n"
"export fn main() i32 = {\n"
" let x: u = 42i64;\n"
" return h(x);\n"
"};\n", 0, 0, K_RUN, NULL },
/* LIVE c1 graduation: the >48B MEMORY-class twin
* (tagged_memarg_size). LAST payload word checked. */
{ "tmem_2lvl",
"package main;\n"
"type big = struct { a: i64, b: i64, c: i64, d: i64, e: i64, f: i64, g: i64 };\n"
"type m0 = (void | big);\n"
"type m = m0;\n"
"fn h(v: m) i32 = {\n"
" match (v) {\n"
" case let s: big => { if (s.g != 77) { return 1; }; return 0; };\n"
" case void => { return 2; };\n"
" };\n"
"};\n"
"export fn main() i32 = {\n"
" let s: big;\n"
" s.a = 11; s.b = 22; s.c = 33; s.d = 44; s.e = 55; s.f = 66; s.g = 77;\n"
" let x: m = s;\n"
" return h(x);\n"
"};\n", 0, 0, K_RUN, NULL },
{ "wpush_2lvl",
"package main;\n"
"type u0 = (void | i64);\n"
"type u = u0;\n"
"fn h(v: u) i32 = {\n"
" match (v) {\n"
" case let n: i64 => { if (n != 42) { return 1; }; return 0; };\n"
" case void => { return 2; };\n"
" };\n"
"};\n"
"export fn main() i32 = {\n"
" return h(42i64);\n"
"};\n", 0, 0, K_RUN, NULL },
{ "wstore_2lvl",
"package main;\n"
"type u0 = (void | i64);\n"
"type u = u0;\n"
"export fn main() i32 = {\n"
" let v: u = 42i64;\n"
" match (v) {\n"
" case let n: i64 => { if (n != 42) { return 1; }; };\n"
" case void => { return 2; };\n"
" };\n"
" return 0;\n"
"};\n", 0, 0, K_RUN, NULL },
{ "wstore_1lvl",
"package main;\n"
"type u = (void | i64);\n"
"export fn main() i32 = {\n"
" let v: u = 42i64;\n"
" match (v) {\n"
" case let n: i64 => { if (n != 42) { return 1; }; };\n"
" case void => { return 2; };\n"
" };\n"
" return 0;\n"
"};\n", 0, 0, K_RUN, NULL },
/* C1-CORR-2 (ken c1-boundary addendum): the assign-route
* divergence does NOT close in this train — the ident-lhs
* N_ASSIGN tagged store gates in the cgexpr INLINE set (B6),
* never reaching the :2456 funnel. Both stages runtime-correct;
* byte-id rides B6. */
{ "wstore_a_bound_b6",
"package main;\n"
"type u0 = (void | i64);\n"
"type u = u0;\n"
"export fn main() i32 = {\n"
" let v: u = void;\n"
" v = 42i64;\n"
" match (v) {\n"
" case let n: i64 => { if (n != 42) { return 1; }; };\n"
" case void => { return 2; };\n"
" };\n"
" return 0;\n"
"};\n", 0, 0, K_RUN_NOID, NULL }, /* byte-id: B6 */
/* C1-CORR-1: the residual divergence is exactly three paired
* return-position tag syntheses — the cgreturn return-route
* family (:12278/:12318/:12322). Joins c3's graduation set
* (pins-follow-the-layer); flips to K_RUN there. */
{ "succ_bound_c3",
"package main;\n"
"type e0 = !i64;\n"
"type r0 = (i64 | e0);\n"
"type r = r0;\n"
"fn w(bad: bool) r = {\n"
" if (bad) { return 7: e0; };\n"
" return 42;\n"
"};\n"
"fn outer() r = {\n"
" let v = w(false)?;\n"
" return v + 1;\n"
"};\n"
"export fn main() i32 = {\n"
" match (outer()) {\n"
" case let n: i64 => { if (n != 43) { return 1; }; };\n"
" case e0 => { return 2; };\n"
" };\n"
" return 0;\n"
"};\n", 0, 0, K_RUN_NOID, NULL }, /* byte-id: c3 */
{ "null_2lvl",
"package main;\n"
"type np0 = (*i64 | void);\n"
"type np = np0;\n"
"export fn main() i32 = {\n"
" let n: i64 = 31;\n"
" let p: np = &n;\n"
" match (p) {\n"
" case let q: *i64 => { if (*q != 31) { return 1; }; };\n"
" case void => { return 2; };\n"
" };\n"
" return 0;\n"
"};\n", 0, 0, K_RUN, NULL },
{ "f32p_2lvl",
"package main;\n"
"type in0 = struct { a: f64 };\n"
"type in1 = in0;\n"
"type pt = struct { x: in1, y: f64 };\n"
"fn g(p: pt) f64 = { return p.x.a + p.y; };\n"
"export fn main() i32 = {\n"
" let p: pt;\n"
" p.x.a = 2.5;\n"
" p.y = 1.5;\n"
" if (g(p) != 4.0) { return 1; };\n"
" return 0;\n"
"};\n", 0, 0, K_RUN, NULL },
/* fill loudness control: named-struct array elem louds on BOTH
* stages with twin texts — the experr substring is shared. */
{ "fill0_ctl",
"package main;\n"
"type el0 = struct { a: i64 };\n"
"type S = struct { arr: [2]el0, n: i64 };\n"
"export fn main() i32 = {\n"
" let s = S { arr = [el0 { a = 5 }, el0 { a = 6 }], n = 3 };\n"
" if (s.arr[0].a + s.arr[1].a + s.n != 14) { return 1; };\n"
" return 0;\n"
"};\n", 0, 0, K_BUILDERR,
"has a str/slice/struct/tagged element" },
/* DESIGNED IN-TRAIN ACCEPTANCE DIVERGENCE (B5 re-rule R4, task
* #100): pre-c1 this was both-wrong-IDENTICAL-silent (gate-blind
* #263 class — both stages accepted and ran exit 1 byte-id). The
* cs-only :3195 chase flips cs to the fill0 fatal; ww's own
* alias-blind twin gate (checkarrlitfits kin) stays silent-wrong
* until #100 lands — then this row graduates to a both-loud
* fill0-class pair. Both cells asserted. */
{ "fill2_bound100",
"package main;\n"
"type el0 = struct { a: i64 };\n"
"type el = el0;\n"
"type S = struct { arr: [2]el, n: i64 };\n"
"export fn main() i32 = {\n"
" let s = S { arr = [el0 { a = 5 }, el0 { a = 6 }], n = 3 };\n"
" if (s.arr[0].a + s.arr[1].a + s.n != 14) { return 1; };\n"
" return 0;\n"
"};\n", 0, 1, K_CSERR_WWRUN,
"has a str/slice/struct/tagged element" }, /* ww: task #100 */
/* node_tuplearg:249 pin (ken FLAG-2): the LITERAL spelling has
* NO GREEN TARGET — cs checker-rejects even at 1 level (#86-kin)
* while WW ACCEPTS AND RUNS WRONG (exit 1, task #99 metric-1
* ww-side). Cells pinned as observed. */
{ "tuparg_bound99",
"package main;\n"
"type tp0 = (i64, i64);\n"
"type tp = tp0;\n"
"fn f(t: tp) i64 = { return t.0 + t.1; };\n"
"export fn main() i32 = {\n"
" let t: tp = (4, 9);\n"
" if (f(t) != 13) { return 1; };\n"
" return 0;\n"
"};\n", 0, 1, K_CSERR_WWRUN,
"not assignable" }, /* ww: task #99 */
{ "tuparg1_bound99", /* 1-LEVEL identical — not alias-depth */
"package main;\n"
"type tp = (i64, i64);\n"
"fn f(t: tp) i64 = { return t.0 + t.1; };\n"
"export fn main() i32 = {\n"
" let t: tp = (4, 9);\n"
" if (f(t) != 13) { return 1; };\n"
" return 0;\n"
"};\n", 0, 1, K_CSERR_WWRUN,
"not assignable" }, /* ww: task #99 */
/* C1-CORR-3 (corrects rob R3 + ken FLAG-2): the CAST spelling
* dodges the cs checker, and the :249 chase gave it a LIVE cs
* graduation — cs now classifies the alias-tuple arg and runs
* CORRECT. ww still runs WRONG (#99). Two-key pin: cs-0 earned
* + ww-1 pinned OBSERVED-WRONG; byte-id waived — when #99's ww
* fix lands, the ww cell reds and forces the re-pin to full 0/0
* byte-id (the designed graduation path). */
{ "tuparg_cast_bound99",
"package main;\n"
"type tp0 = (i64, i64);\n"
"type tp = tp0;\n"
"fn f(t: tp) i64 = { return t.0 + t.1; };\n"
"export fn main() i32 = {\n"
" let t: tp = (4, 9): tp;\n"
" if (f(t) != 13) { return 1; };\n"
" return 0;\n"
"};\n", 0, 1, K_RUN_NOID, NULL }, /* ww+byte-id: task #99 */
/* #85 SITE-closure bound: type_unwrap's consumers (:14716/:14907
* tuple-global layout walks) are checker-DEAD on cs for alias
* tuples (#86 upstream) — the c1 chase graduates NOTHING live
* here; ww runs the global correctly. */
{ "tupglobal_bound86",
"package main;\n"
"type tp0 = (i64, i64);\n"
"type tp = tp0;\n"
"let G: tp = (4, 9);\n"
"export fn main() i32 = {\n"
" if (G.0 + G.1 != 13) { return 1; };\n"
" return 0;\n"
"};\n", 0, 0, K_CSERR_WWRUN,
"not assignable" }, /* cs: task #86 */
/* ---- c2: #73 graduation — the F1 tripwire's containment
* replaced by the designed chase (close-by-construction). Each
* row was the loud "#73" fatal on cs at the c1 tip (ww ok/0);
* post-c2 the gates read the chased field type and every
* runnable arm lands 0/0 byte-id. Values exceed 255 / use the
* LAST element so a word0 tail can't pass by prefix-luck;
* noise() clobbers BX/CX on the read rows. */
{ "g73_idxstore",
"package main;\n"
"type sl = []int;\n"
"type sl2 = sl;\n"
"type box = struct { s: sl2, n: int };\n"
"export fn main() i32 = {\n"
" let a: [3]int = [700: int, 800: int, 900: int];\n"
" let xs: [2]box;\n"
" xs[0].s = a[0:3];\n"
" if (xs[0].s.len != 3) { return 1; };\n"
" return 0;\n"
"};\n", 0, 0, K_RUN, NULL },
{ "g73_strfield",
"package main;\n"
"type s1t = str;\n"
"type s2t = s1t;\n"
"type box = struct { s: s2t, n: int };\n"
"fn noise(x: int) int = { return x * 7 + 3; };\n"
"export fn main() i32 = {\n"
" let xs: [2]box;\n"
" xs[1].s = \"hello\";\n"
" xs[1].n = 4;\n"
" let k = noise(9);\n"
" if (k != 66) { return 9; };\n"
" let w = xs[1].s;\n"
" if (w.len != 5) { return 1; };\n"
" return 0;\n"
"};\n", 0, 0, K_RUN, NULL },
{ "g73_tagfield",
"package main;\n"
"type tu0 = (void | i64);\n"
"type tu = tu0;\n"
"type box = struct { u: tu, n: int };\n"
"export fn main() i32 = {\n"
" let xs: [2]box;\n"
" xs[0].n = 5;\n"
" xs[0].u = 42i64;\n"
" if (xs[0].n != 5) { return 1; };\n"
" match (xs[0].u) {\n"
" case let v: i64 => { if (v != 42) { return 2; }; };\n"
" case void => { return 3; };\n"
" };\n"
" return 0;\n"
"};\n", 0, 0, K_RUN, NULL },
/* store rides the (F1-chased) single-dot via-ptr route so the
* indexed-elem READ gate fires in isolation. */
{ "g73_idxread",
"package main;\n"
"type sl = []int;\n"
"type sl2 = sl;\n"
"type box = struct { s: sl2, n: int };\n"
"fn noise(x: int) int = { return x * 7 + 3; };\n"
"export fn main() i32 = {\n"
" let a: [3]int = [700: int, 800: int, 900: int];\n"
" let xs: [2]box;\n"
" let p = &xs[1];\n"
" p.s = a[0:3];\n"
" p.n = 4;\n"
" let k = noise(9);\n"
" if (k != 66) { return 9; };\n"
" let w = xs[1].s;\n"
" if (w.len != 3) { return 1; };\n"
" if (w[2] != 900) { return 2; };\n"
" return 0;\n"
"};\n", 0, 0, K_RUN, NULL },
{ "g73_ptrread",
"package main;\n"
"type sl = []int;\n"
"type sl2 = sl;\n"
"type inner = struct { s: sl2, n: int };\n"
"type outer = struct { pi: *inner };\n"
"fn noise(x: int) int = { return x * 7 + 3; };\n"
"export fn main() i32 = {\n"
" let a: [3]int = [700: int, 800: int, 900: int];\n"
" let i: inner;\n"
" i.s = a[0:3];\n"
" i.n = 1;\n"
" let v: outer;\n"
" v.pi = &i;\n"
" let k = noise(9);\n"
" if (k != 66) { return 9; };\n"
" let w = v.pi.s;\n"
" if (w.len != 3) { return 1; };\n"
" if (w[2] != 900) { return 2; };\n"
" return 0;\n"
"};\n", 0, 0, K_RUN, NULL },
{ "g73_tupread",
"package main;\n"
"type sl = []int;\n"
"type sl2 = sl;\n"
"export fn main() i32 = {\n"
" let a: [3]int = [700: int, 800: int, 900: int];\n"
" let t: (sl2, int) = (a[0:3], 5);\n"
" let s = t.0;\n"
" if (s.len != 3) { return 1; };\n"
" if (t.1 != 5) { return 2; };\n"
" return 0;\n"
"};\n", 0, 0, K_RUN, NULL },
{ "g73_static_struct",
"package main;\n"
"type in0 = struct { a: i64, b: i64 };\n"
"type in1 = in0;\n"
"type box = struct { i: in1, n: i64 };\n"
"let g: box = box { i = in0 { a = 4, b = 9 }, n = 5 };\n"
"export fn main() i32 = {\n"
" if (g.n != 5) { return 1; };\n"
" if (g.i.b != 9) { return 2; };\n"
" return 0;\n"
"};\n", 0, 0, K_RUN, NULL },
/* COMPILE-only pin: bare /tmp programs never link malloc (both
* stages, pre-existing infra) and the ww deref-field READ
* carries the #24-kin field(SB) leak — run + byte-id cells are
* unavailable. The chased FILL bytes were verified byte-id by
* hand against the plain control (/tmp/b5/work). Pre-c2 the cs
* cell was the "#73" fatal — this row pins its absence. */
{ "g73_heapfill",
"package main;\n"
"type s1t = str;\n"
"type s2t = s1t;\n"
"type box = struct { s: s2t, n: int };\n"
"export fn main() i32 = {\n"
" let p = alloc(box { s = \"hello\", n = 5 })!;\n"
" if (p.n != 5) { return 1; };\n"
" if (p.s.len != 5) { return 2; };\n"
" return 0;\n"
"};\n", 0, 0, K_COMPILES, NULL },
/* str-field static emit: the #73 fatal gave way to the
* pre-existing #129 A.2 foldability loud — both-loud twin texts
* now (the fill0 class), pinned so neither side regresses to a
* silent emit. */
{ "g73_static_str",
"package main;\n"
"type s1t = str;\n"
"type s2t = s1t;\n"
"type box = struct { s: s2t, n: int };\n"
"let g: box = box { s = \"hello\", n = 5: int };\n"
"export fn main() i32 = {\n"
" if (g.n != 5) { return 1; };\n"
" if (g.s.len != 5) { return 2; };\n"
" return 0;\n"
"};\n", 0, 0, K_BUILDERR,
"#129 A.2 scope" },
};
static int
run_driver(const char *driver, const struct row *r, int i, int expect_err,
int want)
{
char src[96], tmpdir[96], errf[96], cmd[1024];
snprintf(src, sizeof src, "/tmp/ab5_%d_%d.ww", getpid(), i);
snprintf(tmpdir, sizeof tmpdir, "/tmp/ab5_%d_d_%d", getpid(), i);
snprintf(errf, sizeof errf, "/tmp/ab5_%d_e_%d", getpid(), i);
FILE *f = fopen(src, "wb");
if (!f) return -1;
fputs(r->src, f);
fclose(f);
mkdir(tmpdir, 0755);
snprintf(cmd, sizeof cmd,
"cd %s && timeout 20 %s build %s >/dev/null 2>%s",
tmpdir, driver, src, errf);
int brc = runwait(cmd);
if (expect_err) {
int ok = (brc != 0)
&& (r->experr == NULL || errlog_has(errf, r->experr));
if (!ok)
fprintf(stderr, "row[%s]: %s expected loud builderr "
"\"%s\" (brc=%d)\n", r->label, driver,
r->experr ? r->experr : "", brc);
unlink(src); unlink(errf); rmdir(tmpdir);
return ok ? 0 : 1;
}
if (brc != 0) {
fprintf(stderr, "row[%s]: build via %s failed\n",
r->label, driver);
unlink(src); unlink(errf); rmdir(tmpdir);
return -1;
}
const char *base = strrchr(src, '/');
base = base ? base + 1 : src;
char outbin[256];
snprintf(outbin, sizeof outbin, "%s/%s", tmpdir, base);
char *dot = strrchr(outbin, '.');
if (dot && strcmp(dot, ".ww") == 0) *dot = '\0';
int got = runwait(outbin);
unlink(src); unlink(outbin); unlink(errf); rmdir(tmpdir);
if (got != want) {
fprintf(stderr, "row[%s]: %s exit %d, want %d\n",
r->label, driver, got, want);
return 1;
}
return 0;
}
/* asm_compiles — K_COMPILES cell: the named stage compiler must emit
* asm without a fatal. */
static int
asm_compiles(const char *bin, const char *cc, const struct row *r, int i)
{
char src[96], outs[96], cmd[1024];
snprintf(src, sizeof src, "/tmp/ab5_cmp_%d_%d.ww", getpid(), i);
snprintf(outs, sizeof outs, "/tmp/ab5_cmp_%d_%d.s", getpid(), i);
FILE *f = fopen(src, "wb");
if (!f) return -1;
fputs(r->src, f);
fclose(f);
snprintf(cmd, sizeof cmd, "%s/%s -o %s %s 2>/dev/null",
bin, cc, outs, src);
int rc = runwait(cmd);
if (rc != 0)
fprintf(stderr, "row[%s]: %s failed to compile\n",
r->label, cc);
unlink(src); unlink(outs);
return rc != 0;
}
static int
asm_byte_identical(const char *bin, const struct row *r, int i)
{
char src[96], cs[96], ws[96], cmd[1024];
snprintf(src, sizeof src, "/tmp/ab5_asm_%d_%d.ww", getpid(), i);
snprintf(cs, sizeof cs, "/tmp/ab5_asm_%d_%d_c.s", getpid(), i);
snprintf(ws, sizeof ws, "/tmp/ab5_asm_%d_%d_w.s", getpid(), i);
FILE *f = fopen(src, "wb");
if (!f) return -1;
fputs(r->src, f);
fclose(f);
snprintf(cmd, sizeof cmd, "%s/w6c -o %s %s 2>/dev/null", bin, cs, src);
if (runwait(cmd) != 0) {
fprintf(stderr, "row[%s]: w6c errored\n", r->label);
unlink(src);
return -1;
}
snprintf(cmd, sizeof cmd, "%s/w6c_ww -o %s %s 2>/dev/null",
bin, ws, src);
if (runwait(cmd) != 0) {
fprintf(stderr, "row[%s]: w6c_ww errored\n", r->label);
unlink(src); unlink(cs);
return -1;
}
int rc = slurp_eq(cs, ws);
if (rc != 0)
fprintf(stderr, "row[%s]: cstage vs wwstage asm differs\n",
r->label);
unlink(src); unlink(cs); unlink(ws);
return rc;
}
int
main(void)
{
const char *bin = getenv("BIN");
if (!bin) bin = "out/bin";
char absbin[2080];
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 cdrv[2120], wdrv[2120];
snprintf(cdrv, sizeof cdrv, "%s/ww", bin);
snprintf(wdrv, sizeof wdrv, "%s/ww_ww", bin);
int n = (int)(sizeof rows / sizeof rows[0]);
int total = 0, fail = 0;
for (int i = 0; i < n; i++) {
total++;
if (rows[i].kind == K_COMPILES) {
if (asm_compiles(bin, "w6c", &rows[i], i) != 0)
fail++;
continue;
}
int cs_err = rows[i].kind == K_BUILDERR
|| rows[i].kind == K_CSERR_WWRUN;
if (run_driver(cdrv, &rows[i], i, cs_err,
rows[i].cswant) != 0) fail++;
}
if (access(wdrv, X_OK) == 0) {
for (int i = 0; i < n; i++) {
total++;
if (rows[i].kind == K_COMPILES) {
if (asm_compiles(bin, "w6c_ww",
&rows[i], i) != 0) fail++;
continue;
}
int ww_err = rows[i].kind == K_BUILDERR;
if (run_driver(wdrv, &rows[i], i, ww_err,
rows[i].wwwant) != 0) fail++;
}
for (int i = 0; i < n; i++) {
if (rows[i].kind != K_RUN)
continue;
total++;
if (asm_byte_identical(bin, &rows[i], i) != 0) fail++;
}
}
if (fail) {
fprintf(stderr, "alias_cgen_b5: %d/%d checks failed\n",
fail, total);
return 1;
}
printf("alias_cgen_b5: %d/%d ok\n", total, total);
return 0;
}