The wcc test drivers ran `ww build <bare-/tmp src>` with no -o, so the compiler's <stem>.sepwork scratch landed beside the source and was never cleaned: unbounded /tmp growth (2195 stale dirs observed) that fills tmpfs and fabricates phantom test failures + silent harness aborts, and for in-repo fixture builds leaked .sepwork into the tracked tree. Each leaking build now writes its source + output inside a per-invocation tmpdir, passes -o <tmpdir>/<stem> so the .sepwork lands inside it, and rm -rf's the tmpdir on every exit path -- including fopen-fail and the expected-fail reject builds (scratch is mkdir'd before the build can fail). `ww run` and explicit-`-o`/byte-id helpers are left as-is; the 990/993 byte-id comparison logic is byte-for-byte unchanged. Two items filed separately (this commit holds the no-Makefile / no-main.c rail): - #13: a stale <src>.s byte-id readback (749) silently no-ops since separate-compile emits .s to <ostem>.sepwork/__root.s; documented inline. - #14: build-system Makefile recipes build selfhost/cmd/*/main.ww with no -o and leak main.sepwork in-tree (bounded, gitignored; own commit). One concern -- sepwork leak hygiene -- across 228 drivers; uniform transform applied per-file and two-round reviewed. make test: all 402 passed, zero net-new /tmp scratch, zero test-driven in-repo .sepwork.
690 lines
26 KiB
C
690 lines
26 KiB
C
/*
|
|
* 944_alias_cgen_b6_run — #5 alias arc F2b (B6 train): the cgen.c
|
|
* cgexpr/cgstmt INLINE single-peel sweep through type_chase_named, by
|
|
* consumer family — c1 assign/reassign (9 lines), c2 call-arg (8),
|
|
* c3 addr-of/field-walk/index spine (14), c4 cast/is/try (10),
|
|
* c5 reads/len/globals (8). 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 B6 first-position oracle probes
|
|
* (/tmp/ken_b5/src/kb6_*, .ai/ken-b6-oracle.md, matrix at 4cac1cb).
|
|
*
|
|
* row | shape (oracle row) | cs/ww
|
|
* --------------------+-------------------------------------+------
|
|
* ---- c1 (assign/reassign: :6359 :6403/:6405 :6460/:6462 -------
|
|
* :6518 + cgstmt :11696 :12047 :13625) -------------------
|
|
* streassign_2lvl | kb6_streassign: 2-lvl alias str |
|
|
* | reassign `b = a` — cs copied WORD0 |
|
|
* | (ptr) ONLY, len/cap stale (silent |
|
|
* | exit 1); the :6518 lu gate fell to |
|
|
* | the scalar default. LIVE graduation | 0/0
|
|
* wstore_a (B5 file) | kb5_wstore_a graduates K_RUN_NOID → |
|
|
* | K_RUN in 944_alias_cgen_b5_run.c — |
|
|
* | the ident-lhs N_ASSIGN tagged gate |
|
|
* | (:6359) was the divergence (ken |
|
|
* | C1-CORR-2, he owns the flip) | 0/0
|
|
* sreassign_2lvl | kb6_sreassign: whole-struct alias |
|
|
* | reassign — latent control | 0/0
|
|
* dassign_2lvl | kb6_dassign: (*p).f= over alias ptr |
|
|
* | — latent control | 0/0
|
|
* ---- c2 (call-arg: :8402 :8435 :8561/:8563/:8577/:8579 --------
|
|
* + LOUD-PRESERVING :8829 :8934) ------------------------
|
|
* fsarg0_loud_ctl | kb6_fsarg0: PLAIN float-struct from |
|
|
* | a non-ident source — #271/#165 loud |
|
|
* | BOTH stages (control, twin texts) | err/err
|
|
* fsarg2_bound | kb6_fsarg2: 1-alias-level respell — |
|
|
* | pre-c2 the :8829 single-peel let |
|
|
* | the alias DODGE the fatal; cs GP- |
|
|
* | passed by self-consistent luck. |
|
|
* | DESIGNED NARROWING: cs now louds |
|
|
* | with the pinned #271/#165 text |
|
|
* | ("widen what the gate SEES, never |
|
|
* | what it ACCEPTS"). ww's loud is its |
|
|
* | own alias-return bound (#272/#277 |
|
|
* | class, experr_ww) — per-stage texts | err/err
|
|
* fsarg_ident_ctl | kb6_fsarg: IDENT-source alias twin |
|
|
* | — ident domain out of the :8829 |
|
|
* | gate, latent control | 0/0
|
|
* sarg_2lvl | kb6_sarg: >16B alias struct arg — |
|
|
* | latent (B5 helper chases carry the |
|
|
* | type layer) | 0/0
|
|
* strarg_2lvl | kb6_strarg: alias str arg — latent | 0/0
|
|
* (:8934 tuple loud is WATCH-ONLY: alias spellings are |
|
|
* checker-blocked upstream (#86/#99) — the pin is the b5 |
|
|
* suite's tuparg_cast_bound99 two-key cells, which must |
|
|
* not move.) |
|
|
* ---- c3 (addr-of/field-walk/index spine: :3949 :4006 ---------
|
|
* :4124/:4128 :5029/:5035/:5052 :5937 :10953/:10956 -----
|
|
* :11046/:11052/:11067 :11285, numbering at 4cac1cb) ----
|
|
* idxf_2lvl / | kb6_idxf (indexed-elem struct field |
|
|
* ampf_2lvl | write+read) / kb6_ampf (&p.b over |
|
|
* | alias ptr): the c3 chase moved cs |
|
|
* | onto the PLAIN-canonical dedicated |
|
|
* | shape (cs_alias == ww_PLAIN, bit- |
|
|
* | proven, ken c3-STOP addendum) — and |
|
|
* | WWSTAGE was the alias-blind side at |
|
|
* | these two sites (generic-but-correct |
|
|
* | routes). GRADUATED to full byte-id |
|
|
* | by the W2 ww fold, task #102 (the |
|
|
* | two gates now chase the alias chain |
|
|
* | via structlookupchain). ampf's |
|
|
* | pre-c3 byte-id was both-on-generic |
|
|
* | identity, not latency (oracle |
|
|
* | self-correction) | 0/0
|
|
* idxf_plain_ctl / | plain no-alias twins — pin the |
|
|
* ampf_plain_ctl | canonical dedicated shape byte-id |
|
|
* | BOTH stages (the convergence target |
|
|
* | the NOID rows graduate onto) | 0/0
|
|
* ampv_2lvl / | W2-review-found #102 sibling: &x.f |
|
|
* ampv_plain_ctl | over an alias-NAMED VALUE struct — |
|
|
* | the leg one below the &p.f gate had |
|
|
* | the same alias-blind bare lookup |
|
|
* | (ww_alias != ww_plain; cs_alias == |
|
|
* | ww_plain, same bit-proven mechanism).|
|
|
* | Chased in the W2 review amendment | 0/0
|
|
* chdot_2lvl | kb6_chdot: chained dot over alias |
|
|
* | hops — latent control | 0/0
|
|
* esub_2lvl | kb6_esub: [3]my32b narrow-elem index |
|
|
* | (#61/#101-kin at the INDEX sites) — |
|
|
* | latent control | 0/0
|
|
* ---- c4 (cast/is/try: :9422 :9598 :9674 :9718 :9819 ----------
|
|
* :9986/:9991 :10103/:10105 :10131, numbering at 4cac1cb) -
|
|
* strcast_2lvl | kb6_strcast: str→[]u8 over 2-lvl |
|
|
* | alias — was both-correct divergent; |
|
|
* | the :10103/:10105 tu/fu chase FLIPS |
|
|
* | it (cs → ww's unchanged asm, #263 |
|
|
* | polarity; alias == plain shape) | 0/0
|
|
* idcast_2lvl | kb6_idcast: identity cast over alias |
|
|
* | union (Family-C peel) — latent | 0/0
|
|
* is_2lvl | kb6_is: `is` over alias union — |
|
|
* | latent control | 0/0
|
|
* try_loud_38b | kb6_try: `?` on a >48B sret-class |
|
|
* | call result — the #38b loud is |
|
|
* | ALIAS-INDEPENDENT (documented bound);|
|
|
* | :9819's chase is loud-preserving |
|
|
* | ONLY — twin texts, shared experr | err/err
|
|
* ---- c5 (reads/len/globals: :3820 :7201 :7807 :7900 :9944 ----
|
|
* :10224 :10750 :10873, numbering at 4cac1cb) ------------
|
|
* tfread_2lvl | kb6_tfread: tagged-union field load |
|
|
* | direct + through-ptr over alias |
|
|
* | struct — was both-correct divergent; |
|
|
* | the :10750/:10873 tag_fu chases FLIP |
|
|
* | it (cs → ww's unchanged asm, #263 |
|
|
* | polarity; alias == plain shape) | 0/0
|
|
* len_2lvl | kb6_len: str+array len over 2-lvl |
|
|
* | alias — latent control | 0/0
|
|
* gref_2lvl | kb6_gref: alias scalar global value- |
|
|
* | ref — latent control | 0/0
|
|
* memread_40b | kb6_memread: 40B union, the :9944 |
|
|
* | #37 cap-watch row — the `is` chase |
|
|
* | keys the cap test on the CHASED size |
|
|
* | (mirrors ww taggedmemread); byte- |
|
|
* | NEUTRALITY here is the regression net| 0/0
|
|
*
|
|
* K_RUN rows build+run BOTH drivers (cs exit==cswant, ww exit==wwwant)
|
|
* and assert cstage/wwstage asm byte-id. K_BUILDERR rows must FAIL
|
|
* with experr on BOTH drivers; experr_ww overrides the ww-side text
|
|
* when the two stages loud at DIFFERENT sites (per-stage texts).
|
|
* 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;
|
|
* experr_ww overrides the ww-side text */
|
|
#define K_RUN_NOID 2 /* build+run BOTH, exits==wants, byte-id
|
|
* SKIPPED — cite the blocking task */
|
|
|
|
struct row { const char *label; const char *src;
|
|
int cswant; int wwwant; int kind;
|
|
const char *experr; const char *experr_ww; };
|
|
|
|
/* 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: assign/reassign family */
|
|
/* LIVE c1 graduation: the :6518 reassign gate single-peeled the
|
|
* 2-level alias str lhs, missed the TY_STR kind test, and fell
|
|
* to the scalar default — ONE MOVQ stored the ptr word, len/cap
|
|
* kept the dead value's header (cs silent exit 1, ww correct:
|
|
* full 3-word {ptr,len,cap} store, Hare value semantics). */
|
|
{ "streassign_2lvl",
|
|
"package main;\n"
|
|
"type ms0 = str;\n"
|
|
"type ms = ms0;\n"
|
|
"export fn main() i32 = {\n"
|
|
" let a: ms = \"hello\";\n"
|
|
" let b: ms = \"x\";\n"
|
|
" b = a;\n"
|
|
" if (len(b) != 5) { return 1; };\n"
|
|
" return 0;\n"
|
|
"};\n", 0, 0, K_RUN, NULL, NULL },
|
|
{ "sreassign_2lvl",
|
|
"package main;\n"
|
|
"type st0 = struct { a: i64, b: i64, c: i64 };\n"
|
|
"type st = st0;\n"
|
|
"export fn main() i32 = {\n"
|
|
" let x: st; x.a = 1; x.b = 2; x.c = 3;\n"
|
|
" let y: st; y.a = 0; y.b = 0; y.c = 0;\n"
|
|
" y = x;\n"
|
|
" if (y.c != 3 || y.b != 2) { return 1; };\n"
|
|
" return 0;\n"
|
|
"};\n", 0, 0, K_RUN, NULL, NULL },
|
|
{ "dassign_2lvl",
|
|
"package main;\n"
|
|
"type st0 = struct { a: i64, b: i64 };\n"
|
|
"type st = st0;\n"
|
|
"export fn main() i32 = {\n"
|
|
" let x: st; x.a = 1; x.b = 2;\n"
|
|
" let p: *st = &x;\n"
|
|
" (*p).b = 9;\n"
|
|
" if (x.b != 9) { return 1; };\n"
|
|
" return 0;\n"
|
|
"};\n", 0, 0, K_RUN, NULL, NULL },
|
|
/* ---- c2: call-arg family */
|
|
{ "fsarg0_loud_ctl",
|
|
"package main;\n"
|
|
"type fs0 = struct { x: f64 };\n"
|
|
"fn mk() fs0 = {\n"
|
|
" let s: fs0; s.x = 2.5;\n"
|
|
" return s;\n"
|
|
"};\n"
|
|
"fn g(p: fs0) f64 = { return p.x; };\n"
|
|
"export fn main() i32 = {\n"
|
|
" if (g(mk()) != 2.5) { return 1; };\n"
|
|
" return 0;\n"
|
|
"};\n", 0, 0, K_BUILDERR,
|
|
"#271/#165: float-bearing struct arg from a non-ident source",
|
|
NULL },
|
|
/* DESIGNED ACCEPTANCE NARROWING (B6-c2): pre-c2 cs accepted and
|
|
* GP-passed this float struct correct-by-self-consistent-luck
|
|
* (caller+callee agreed on the wrong transport) — the :8829
|
|
* single peel let a 1-level alias dodge the rule-7 fatal. The
|
|
* chase widens what the gate SEES; the loud stays loud for the
|
|
* shapes it guards. ww's cell was ALREADY loud at its own
|
|
* alias-return bound (#272/#276/#277 class) — different site,
|
|
* per-stage experr. */
|
|
{ "fsarg2_bound",
|
|
"package main;\n"
|
|
"type fs0 = struct { x: f64 };\n"
|
|
"type fs = fs0;\n"
|
|
"fn mk() fs = {\n"
|
|
" let s: fs; s.x = 2.5;\n"
|
|
" return s;\n"
|
|
"};\n"
|
|
"fn g(p: fs) f64 = { return p.x; };\n"
|
|
"export fn main() i32 = {\n"
|
|
" if (g(mk()) != 2.5) { return 1; };\n"
|
|
" return 0;\n"
|
|
"};\n", 0, 0, K_BUILDERR,
|
|
"#271/#165: float-bearing struct arg from a non-ident source",
|
|
"#272/#276/#277: aggregate return reaches scalar default" },
|
|
{ "fsarg_ident_ctl",
|
|
"package main;\n"
|
|
"type fs0 = struct { x: f64 };\n"
|
|
"type fs = fs0;\n"
|
|
"fn mk() fs0 = {\n"
|
|
" let s: fs0; s.x = 2.5;\n"
|
|
" return s;\n"
|
|
"};\n"
|
|
"fn g(p: fs) f64 = { return p.x; };\n"
|
|
"export fn main() i32 = {\n"
|
|
" let v: fs = mk();\n"
|
|
" if (g(v) != 2.5) { return 1; };\n"
|
|
" return 0;\n"
|
|
"};\n", 0, 0, K_RUN, NULL, NULL },
|
|
{ "sarg_2lvl",
|
|
"package main;\n"
|
|
"type big0 = struct { a: i64, b: i64, c: i64 };\n"
|
|
"type big = big0;\n"
|
|
"fn g(p: big) i64 = { return p.a + p.c; };\n"
|
|
"export fn main() i32 = {\n"
|
|
" let s: big; s.a = 4; s.b = 5; s.c = 9;\n"
|
|
" if (g(s) != 13) { return 1; };\n"
|
|
" return 0;\n"
|
|
"};\n", 0, 0, K_RUN, NULL, NULL },
|
|
{ "strarg_2lvl",
|
|
"package main;\n"
|
|
"type ms0 = str;\n"
|
|
"type ms = ms0;\n"
|
|
"fn g(s: ms) i64 = { return len(s): i64; };\n"
|
|
"export fn main() i32 = {\n"
|
|
" let a: ms = \"hello\";\n"
|
|
" if (g(a) != 5) { return 1; };\n"
|
|
" return 0;\n"
|
|
"};\n", 0, 0, K_RUN, NULL, NULL },
|
|
/* ---- c3: addr-of/field-walk/index spine */
|
|
/* The c3 chase put cs on the PLAIN-canonical dedicated shape
|
|
* (cs_alias == ww_PLAIN, bit-proven — ken c3-STOP addendum);
|
|
* WWSTAGE was the alias-blind side here: its indexed-elem
|
|
* struct-field store gate fell to a generic-but-correct route
|
|
* on alias bases. GRADUATED: the W2 ww fold (task #102) chases
|
|
* the alias chain (structlookupchain), restoring full byte-id —
|
|
* idxf_plain_ctl pins the canonical shape both rows now share. */
|
|
{ "idxf_2lvl",
|
|
"package main;\n"
|
|
"type el0 = struct { a: i64, b: i64 };\n"
|
|
"type el = el0;\n"
|
|
"export fn main() i32 = {\n"
|
|
" let xs: [2]el;\n"
|
|
" xs[0].a = 1; xs[0].b = 2;\n"
|
|
" xs[1].a = 3; xs[1].b = 4;\n"
|
|
" if (xs[1].b != 4 || xs[0].b != 2) { return 1; };\n"
|
|
" return 0;\n"
|
|
"};\n", 0, 0, K_RUN, NULL, NULL }, /* graduated: #102 (W2) */
|
|
{ "idxf_plain_ctl",
|
|
"package main;\n"
|
|
"type el0 = struct { a: i64, b: i64 };\n"
|
|
"export fn main() i32 = {\n"
|
|
" let xs: [2]el0;\n"
|
|
" xs[0].a = 1; xs[0].b = 2;\n"
|
|
" xs[1].a = 3; xs[1].b = 4;\n"
|
|
" if (xs[1].b != 4 || xs[0].b != 2) { return 1; };\n"
|
|
" return 0;\n"
|
|
"};\n", 0, 0, K_RUN, NULL, NULL },
|
|
/* &p.b ptr-field fallback twin of the same re-attribution: the
|
|
* pre-c3 byte-id here was BOTH stages on the generic spine
|
|
* (gate-blind identity, not M5 latency — oracle self-correction
|
|
* banked in ken's c3-STOP addendum). GRADUATED with #102 (W2). */
|
|
{ "ampf_2lvl",
|
|
"package main;\n"
|
|
"type st0 = struct { a: i64, b: i64 };\n"
|
|
"type st = st0;\n"
|
|
"export fn main() i32 = {\n"
|
|
" let x: st; x.a = 1; x.b = 2;\n"
|
|
" let p: *st = &x;\n"
|
|
" let q: *i64 = &p.b;\n"
|
|
" *q = 9;\n"
|
|
" if (x.b != 9) { return 1; };\n"
|
|
" return 0;\n"
|
|
"};\n", 0, 0, K_RUN, NULL, NULL }, /* graduated: #102 (W2) */
|
|
{ "ampf_plain_ctl",
|
|
"package main;\n"
|
|
"type st0 = struct { a: i64, b: i64 };\n"
|
|
"export fn main() i32 = {\n"
|
|
" let x: st0; x.a = 1; x.b = 2;\n"
|
|
" let p: *st0 = &x;\n"
|
|
" let q: *i64 = &p.b;\n"
|
|
" *q = 9;\n"
|
|
" if (x.b != 9) { return 1; };\n"
|
|
" return 0;\n"
|
|
"};\n", 0, 0, K_RUN, NULL, NULL },
|
|
/* W2-review-found #102 sibling: the value-struct &x.f leg sits
|
|
* one leg below the &p.f gate in the same cgun single-DOT arm
|
|
* and had the same alias-blind bare structlookup (ww_alias !=
|
|
* ww_plain, cs_alias == ww_plain — the c3-STOP bit-test
|
|
* mechanism verbatim). Chased in the W2 review amendment. */
|
|
{ "ampv_2lvl",
|
|
"package main;\n"
|
|
"type st0 = struct { a: i64, b: i64 };\n"
|
|
"type st = st0;\n"
|
|
"export fn main() i32 = {\n"
|
|
" let x: st; x.a = 1; x.b = 2;\n"
|
|
" let q: *i64 = &x.b;\n"
|
|
" *q = 9;\n"
|
|
" if (x.b != 9) { return 1; };\n"
|
|
" return 0;\n"
|
|
"};\n", 0, 0, K_RUN, NULL, NULL }, /* amendment: #102 (W2) */
|
|
{ "ampv_plain_ctl",
|
|
"package main;\n"
|
|
"type st0 = struct { a: i64, b: i64 };\n"
|
|
"export fn main() i32 = {\n"
|
|
" let x: st0; x.a = 1; x.b = 2;\n"
|
|
" let q: *i64 = &x.b;\n"
|
|
" *q = 9;\n"
|
|
" if (x.b != 9) { return 1; };\n"
|
|
" return 0;\n"
|
|
"};\n", 0, 0, K_RUN, NULL, NULL },
|
|
{ "chdot_2lvl",
|
|
"package main;\n"
|
|
"type in0 = struct { v: i64 };\n"
|
|
"type in1 = in0;\n"
|
|
"type out0 = struct { inner: in1, n: i64 };\n"
|
|
"type out1 = out0;\n"
|
|
"export fn main() i32 = {\n"
|
|
" let s: out1; s.inner.v = 7; s.n = 3;\n"
|
|
" let p: *out1 = &s;\n"
|
|
" if (p.inner.v != 7) { return 1; };\n"
|
|
" return 0;\n"
|
|
"};\n", 0, 0, K_RUN, NULL, NULL },
|
|
{ "esub_2lvl",
|
|
"package main;\n"
|
|
"type my32 = u32;\n"
|
|
"type my32b = my32;\n"
|
|
"export fn main() i32 = {\n"
|
|
" let xs: [3]my32b;\n"
|
|
" xs[0] = 5; xs[1] = 6; xs[2] = 7;\n"
|
|
" if (xs[0]: i64 + xs[1]: i64 + xs[2]: i64 != 18) { return 1; };\n"
|
|
" return 0;\n"
|
|
"};\n", 0, 0, K_RUN, NULL, NULL },
|
|
/* #101: NARROW-alias struct-FILL stride (the cgstructlitfill
|
|
* :4791 leg, twin of esub_2lvl's INDEX leg). Pre-fold ww sized
|
|
* the [3]my32 element off primsize("my32")=0 → 8B-default stride,
|
|
* so the fill stored at -24/-16/-8 and field n collided with
|
|
* arr[2] (run exit 1); cs chased my32→u32→4 (MOVL stride-4). The
|
|
* aliasprimsize route aligns ww UP — kw1_101 was the SOLE corpus
|
|
* mover (cs0/ww1 byteid-NO → byteid-YES + run 0). */
|
|
{ "kw1_101",
|
|
"package main;\n"
|
|
"type my32 = u32;\n"
|
|
"type S = struct { arr: [3]my32, n: int };\n"
|
|
"export fn main() i32 = {\n"
|
|
" let s = S { arr = [10u32, 20u32, 30u32], n = 4 };\n"
|
|
" if (s.arr[0] + s.arr[1] + s.arr[2] != 60u32) { return 1; };\n"
|
|
" if (s.n != 4) { return 1; };\n"
|
|
" return 0;\n"
|
|
"};\n", 0, 0, K_RUN, NULL, NULL },
|
|
/* #101 control: a DIFFERENT narrow width (u16, stride-2 MOVW)
|
|
* proves the routed esz is width-general, not a 4-only patch.
|
|
* fld n must survive the fill untouched. */
|
|
{ "kw1_ctl16",
|
|
"package main;\n"
|
|
"type my16 = u16;\n"
|
|
"type S2 = struct { arr: [4]my16, n: int };\n"
|
|
"export fn main() i32 = {\n"
|
|
" let s = S2 { arr = [1u16, 2u16, 3u16, 4u16], n = 9 };\n"
|
|
" if (s.arr[0] + s.arr[1] + s.arr[2] + s.arr[3] != 10u16) { return 1; };\n"
|
|
" if (s.n != 9) { return 1; };\n"
|
|
" return 0;\n"
|
|
"};\n", 0, 0, K_RUN, NULL, NULL },
|
|
/* ---- c4: cast/is/try family */
|
|
{ "strcast_2lvl",
|
|
"package main;\n"
|
|
"type ms0 = str;\n"
|
|
"type ms = ms0;\n"
|
|
"export fn main() i32 = {\n"
|
|
" let a: ms = \"hey\";\n"
|
|
" let b: []u8 = a: []u8;\n"
|
|
" if (len(b) != 3) { return 1; };\n"
|
|
" if (b[0] != 'h') { return 2; };\n"
|
|
" return 0;\n"
|
|
"};\n", 0, 0, K_RUN, NULL, NULL },
|
|
{ "idcast_2lvl",
|
|
"package main;\n"
|
|
"type u0 = (void | i64);\n"
|
|
"type u = u0;\n"
|
|
"export fn main() i32 = {\n"
|
|
" let v: u = 42i64;\n"
|
|
" let w: u = (v: u);\n"
|
|
" match (w) {\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, NULL },
|
|
{ "is_2lvl",
|
|
"package main;\n"
|
|
"type u0 = (void | i64);\n"
|
|
"type u = u0;\n"
|
|
"export fn main() i32 = {\n"
|
|
" let v: u = 42i64;\n"
|
|
" if (!(v is i64)) { return 1; };\n"
|
|
" if (v is void) { return 2; };\n"
|
|
" return 0;\n"
|
|
"};\n", 0, 0, K_RUN, NULL, NULL },
|
|
/* ALIAS-INDEPENDENT #38b bound (ken's row is >48B sret-class):
|
|
* the :9819 chase must stay loud-preserving — this pins the
|
|
* fatal so a future chase can't silently green it. */
|
|
{ "try_loud_38b",
|
|
"package main;\n"
|
|
"type e0 = !i64;\n"
|
|
"type big = struct { a: i64, b: i64, c: i64, d: i64, e: i64, f: i64, g: i64 };\n"
|
|
"type r0 = (big | e0);\n"
|
|
"type r = r0;\n"
|
|
"fn w() r = {\n"
|
|
" let s: big;\n"
|
|
" s.a = 1; s.b = 2; s.c = 3; s.d = 4; s.e = 5; s.f = 6; s.g = 77;\n"
|
|
" return s;\n"
|
|
"};\n"
|
|
"fn outer() (i64 | e0) = {\n"
|
|
" let v = w()?;\n"
|
|
" return v.g;\n"
|
|
"};\n"
|
|
"export fn main() i32 = {\n"
|
|
" match (outer()) {\n"
|
|
" case let n: i64 => { if (n != 77) { return 1; }; };\n"
|
|
" case e0 => { return 2; };\n"
|
|
" };\n"
|
|
" return 0;\n"
|
|
"};\n", 0, 0, K_BUILDERR,
|
|
"#38b: `?`/`!` on an sret-class call result unwired", NULL },
|
|
/* ---- c5: reads/len/globals family */
|
|
{ "tfread_2lvl",
|
|
"package main;\n"
|
|
"type u0 = (void | i64);\n"
|
|
"type u = u0;\n"
|
|
"type st0 = struct { f: u, n: i64 };\n"
|
|
"type st = st0;\n"
|
|
"export fn main() i32 = {\n"
|
|
" let s: st;\n"
|
|
" s.f = 42i64;\n"
|
|
" s.n = 3;\n"
|
|
" if (!(s.f is i64)) { return 1; };\n"
|
|
" let p: *st = &s;\n"
|
|
" if (!(p.f is i64)) { return 2; };\n"
|
|
" return 0;\n"
|
|
"};\n", 0, 0, K_RUN, NULL, NULL },
|
|
{ "len_2lvl",
|
|
"package main;\n"
|
|
"type ms0 = str;\n"
|
|
"type ms = ms0;\n"
|
|
"type ar0 = [4]i64;\n"
|
|
"type ar = ar0;\n"
|
|
"export fn main() i32 = {\n"
|
|
" let a: ms = \"hello\";\n"
|
|
" if (len(a) != 5) { return 1; };\n"
|
|
" let xs: ar = [1, 2, 3, 4];\n"
|
|
" if (len(xs) != 4) { return 2; };\n"
|
|
" return 0;\n"
|
|
"};\n", 0, 0, K_RUN, NULL, NULL },
|
|
{ "gref_2lvl",
|
|
"package main;\n"
|
|
"type my64 = i64;\n"
|
|
"type my64b = my64;\n"
|
|
"let G: my64b = 7;\n"
|
|
"export fn main() i32 = {\n"
|
|
" if (G != 7) { return 1; };\n"
|
|
" return 0;\n"
|
|
"};\n", 0, 0, K_RUN, NULL, NULL },
|
|
/* :9944 #37 cap-watch: the `is` site's >32B mem-read predicate
|
|
* must key the CHASED size — byte-neutrality of this 40B-union
|
|
* row across the c5 chase is the regression net. */
|
|
{ "memread_40b",
|
|
"package main;\n"
|
|
"type big = struct { a: i64, b: i64, c: i64, d: i64, e: i64 };\n"
|
|
"type m0 = (void | big);\n"
|
|
"type m = m0;\n"
|
|
"export fn main() i32 = {\n"
|
|
" let s: big;\n"
|
|
" s.a = 1; s.b = 2; s.c = 3; s.d = 4; s.e = 55;\n"
|
|
" let v: m = s;\n"
|
|
" if (!(v is big)) { return 1; };\n"
|
|
" match (v) {\n"
|
|
" case let w: big => { if (w.e != 55) { return 2; }; };\n"
|
|
" case void => { return 3; };\n"
|
|
" };\n"
|
|
" return 0;\n"
|
|
"};\n", 0, 0, K_RUN, NULL, NULL },
|
|
};
|
|
|
|
static int
|
|
run_driver(const char *driver, const struct row *r, int i, int expect_err,
|
|
int want, const char *experr)
|
|
{
|
|
char tmpdir[96], src[128], outbin[128], errf[128], rmcmd[160];
|
|
char cmd[1024];
|
|
snprintf(tmpdir, sizeof tmpdir, "/tmp/ab6_%d_d_%d", getpid(), i);
|
|
mkdir(tmpdir, 0755);
|
|
snprintf(src, sizeof src, "%s/ab6_%d_%d.ww", tmpdir, getpid(), i);
|
|
snprintf(outbin, sizeof outbin, "%s/ab6_%d_%d", tmpdir, getpid(), i);
|
|
snprintf(errf, sizeof errf, "%s/err", tmpdir);
|
|
snprintf(rmcmd, sizeof rmcmd, "rm -rf %s", tmpdir);
|
|
|
|
FILE *f = fopen(src, "wb");
|
|
if (!f) { runwait(rmcmd); return -1; }
|
|
fputs(r->src, f);
|
|
fclose(f);
|
|
|
|
snprintf(cmd, sizeof cmd,
|
|
"timeout 20 %s build -o %s %s >/dev/null 2>%s",
|
|
driver, outbin, src, errf);
|
|
int brc = runwait(cmd);
|
|
if (expect_err) {
|
|
int ok = (brc != 0)
|
|
&& (experr == NULL || errlog_has(errf, experr));
|
|
if (!ok)
|
|
fprintf(stderr, "row[%s]: %s expected loud builderr "
|
|
"\"%s\" (brc=%d)\n", r->label, driver,
|
|
experr ? experr : "", brc);
|
|
runwait(rmcmd);
|
|
return ok ? 0 : 1;
|
|
}
|
|
if (brc != 0) {
|
|
fprintf(stderr, "row[%s]: build via %s failed\n",
|
|
r->label, driver);
|
|
runwait(rmcmd);
|
|
return -1;
|
|
}
|
|
|
|
int got = runwait(outbin);
|
|
|
|
runwait(rmcmd);
|
|
if (got != want) {
|
|
fprintf(stderr, "row[%s]: %s exit %d, want %d\n",
|
|
r->label, driver, got, want);
|
|
return 1;
|
|
}
|
|
return 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/ab6_asm_%d_%d.ww", getpid(), i);
|
|
snprintf(cs, sizeof cs, "/tmp/ab6_asm_%d_%d_c.s", getpid(), i);
|
|
snprintf(ws, sizeof ws, "/tmp/ab6_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++;
|
|
int cs_err = rows[i].kind == K_BUILDERR;
|
|
if (run_driver(cdrv, &rows[i], i, cs_err,
|
|
rows[i].cswant, rows[i].experr) != 0) fail++;
|
|
}
|
|
if (access(wdrv, X_OK) == 0) {
|
|
for (int i = 0; i < n; i++) {
|
|
total++;
|
|
int ww_err = rows[i].kind == K_BUILDERR;
|
|
const char *we = rows[i].experr_ww
|
|
? rows[i].experr_ww : rows[i].experr;
|
|
if (run_driver(wdrv, &rows[i], i, ww_err,
|
|
rows[i].wwwant, we) != 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_b6: %d/%d checks failed\n",
|
|
fail, total);
|
|
return 1;
|
|
}
|
|
printf("alias_cgen_b6: %d/%d ok\n", total, total);
|
|
return 0;
|
|
}
|