Files
ww/test/wcc/941_tuple_slot_layout_run.c
Hojun-Cho 66991585d6 wcc+w6c+w6c_ww: tagged tuple elements take their full slot — tuple_eslot accessor (#22a)
slot = roundup8(size(elem)) — 8B is a FLOOR, not a ceiling (user-
ratified 2026-06-04; the #237 fieldslotsize precedent; (str,str)=48B
predates this — tagged was the one truncated >8B kind). Pre-fix the
checkers truncated a tagged element to one 8B slot and every cgen
transport walk strode wide=(STR||SLICE)-else-8: cstage read the
NEIGHBOR slot, wwstage read ZEROS — both-wrong-differently, so the
byte-id gates were blind (prober-9 PG1, /tmp/p9).

One stride accessor per stage — tuple_eslot (cgen.c) / tupeslot
(cgenstmt.ww) — now feeds every tuple walk; the per-site predicates
are deleted as absorbed. Sizer: check.c N_TTUPLE + check.ww
tupleelemslot gain the TY_TAGGED arm (astsize already rides the type
table since commit 0). Routes flipped to the accessor, both stages
symmetric: cursor producers (lit/slot-to-cursor; tagged ident
elements load their box from the slot — cgexpr's tagged ident load
is word0-only), let-receive (tuple_store/tupstore generalized to
eslot/8 words), N_RETURN send, by-value param receive, arg
restage/drain (tagged stays loud per C-t2), destructure
(MLET/MASSIGN, ident + sret + in-cap), t.N read + len(t.N) +
global-g.N offset walks (t.N gains the tagged box load: AX=tag,
DX/CX/R8=payload — the is/as spill cursor), sret classifier, DATA
emit. wwstage cgtagvariantidx gains the #67 stamped-carrier arm
(flatvariantidxt on .type_) — its AST-only key silently clamped
't.0 is size' to tag 0; fused here because the tuple-element read
this commit wires is its only exercisable consumer.

Exit invariant: zero silent tagged-tuple paths — in-cap shapes
(<=4 GP eightbytes) are correct end-to-end; everything else is LOUD:
over-cap sret return (#22b, task #28), call-arg (C-t2 #32),
non-local literal element sources (#22b/#23), tuple-in-union payload
(#242/#22b), global static-init, element write (pre-existing).
Closure proof-grep at HEAD: 'tuple_ebytes|tupebytes' -> 0 hits;
'wide.*=.*(TY_SLICE|TY_STR)' tuple-walk survivors are all behind
tagged loud-guards (cgen.c:2535/2568/12013 widen-store + over-cap
send; cgenutil.ww:3527 twin).

Latent cross-checks closed by the accessor: wwstage MLET-sret strode
esz (4 for i32) vs cstage 8; wwstage param-receive strode slotsize
(composite slotsize) vs cstage 8; both now the accessor's floor-8.
Tagged inits in pins use the CAST form (5: size) — the bare
untyped-int widen-store mis-tag is pre-existing at master and filed
(task #33).

941 gains 13 rows: t22_* size/align folds (+ void-elem 0-slot pin),
the full runtime round-trip (read, is/as, both element orders, void
variant, destructure, literal-let), two-tagged-elem in-cap and
float+tagged in BOTH orders (ken k1/k2 regression-pinned as rows),
t.N-as-call-arg, 5 loud pins (arg, over-cap return, call-source
element, global init, element write), and the sret_narrow_mix_*
triple below. Runtime rows exit-checked under both drivers +
byte-id. 129/129; unit tests green; sizelint clean.

ken R1 (re-validation fix): an OVER-CAP tuple init whose rhs is not a
CALL fell past every cstage N_LET store arm to NOTHING — silent
uninitialized-frame reads — while wwstage loud-rejected the same
shape. Pre-existing for (str,str) literals; the #22a tagged slots
routed >16B-box tagged shapes into it (k5b/k5c/k5d, base-correct
because base truncated them in-cap). cstage now routes the rhs
through cgexpr (the cursor materialisers carry the exact wwstage
loud texts) with a trailing fatal as the net; 941 pins both the
tagged and the (str,str) spellings of the hole.

reviewer-22 (review fixes, folded): the MLET-receive slot flip above
landed ALONE on the wwstage over-cap sret family — the ww RETURN-send
and MASSIGN-receive still strode packed esz (4 for u32), so
`let (a,b,c) = f()` over (str,u32,str) read c at slot offset 32 while
ww's send wrote it packed at 28: a ww runtime REGRESSION vs base
(base was packed-consistent on both sides — ran right, byte-diff).
Both walks now stride the slot (send mirrors cstage's
`wide ? esz : 8`; MASSIGN strides tupeslotn) — closing, in the same
stroke, the pre-existing base skews: ww `let t = f()` over-cap
narrow-mix read (reader slot-laid vs send packed, runtime-wrong at
base) and the cs≠ww asm on all three routings. Second find: t.N
tagged element as a CALL ARG — cstage rides its generic
node_istaggedarg cursor push, but wwstage's kind-gated aistagged
missed N_DOT and mis-routed the box into the widening branch
(taggedvariantindex -1 clamped to 0: callee read variant 0, silent,
ww-only). cgenutil.ww gains the N_DOT arm (aistagged + pushargsrev),
the #67 stamped-carrier twin of the N_INDEX (#12) arm. The N_DOT arm
was a LIVE wwstage stdlib miscompile: hextest's import graph carried
two t.N tagged-arg sites (base .s diff = exactly the clamped-tag
PUSHQ pair) — the 989 lib-byteid ratchet caught the convergence and
#59.4 graduates to M_ID (runtime-correct per 979_hex_run). Probes:
/tmp/r22. Residual filed: tagged arg from deref/cast/unwrap sources
is a word0-only read on BOTH stages (pre-existing, base-confirmed) —
generalizing wwstage's kind gate to cstage's type-keyed check rides
that task.
2026-06-05 01:37:35 +09:00

925 lines
31 KiB
C

/*
* 941_tuple_slot_layout_run — tuple arc C-t0: SLOT layout is the tuple
* SSoT (user-ratified). The checker's TY_TUPLE size counts the stride
* cgen's cursor transport actually writes — a str/slice its 24B header,
* everything else (narrow scalars included) one 8B eightbyte — and the
* t.N read walks stride the same slots.
*
* Pre-C-t0 there were TWO answers: the checker summed PACKED element
* sizes ((u32,u32) = 8B) while every cursor transport site strode 8B
* slots (16B). The 16B shapes were blind to the split (slot == packed);
* the packed shapes hit it everywhere:
* - `let t: (u32,u32) = f()` — cstage's receive keys on the checker
* size (16/32), so sz=8 fell to the generic single-word store
* (word 1 DROPPED) and the packed read walk then read the wrong
* offsets. wwstage (slot-keyed throughout) was runtime-CORRECT
* here — inverted polarity vs the 16B #33 map, gate-blind.
* - a (u32,u32) by-value param: cgfn's receive walk spilled
* 8B/element into a local sized from the PACKED checker size (8B)
* — word 1 landed on the saved-BP slot, frame corruption, SIGSEGV.
* - a mixed (u32,f64)/(u32,str) tuple: packed sz (12/28) missed the
* 16/32 receive arms entirely — silent drop on both stages.
*
* The send-side ABI skew (#32, C-t2) and the wwstage literal-let
* receive (#33, C-t1) are SEPARATE bugs pinned by their own commits;
* this test pins the layout unification only:
*
* row | shape | want
* ---------------------+--------------------------------------+-----
* letcall_packed | let t:(u32,u32)=f(); t.0/t.1 | 0
* letcall_float_packed | (u32,f64) from call, X0 element | 0
* letcall_signed_packed| (i32,i32) negatives — MOVSXD reads | 0
* letcall_mixed_packed | (u32,str): 28B packed missed the 32B |
* | arm; len(t.1) strides a full slot | 0
* len_elem_packed | len(t.1) of (u32,str) — #235 arm's |
* | slot stride (was BP+4+8) | (in mixed row)
* letcall_16_neutral | (i64,i64) — slot==packed, anchor | 0
* letcall_32_neutral | (i64,str) — 32B arm, anchor | 0
* mlet_packed_neutral | let (a,b) = f() packed — per-element |
* | locals, layout-independent anchor | 0
*
* Every row also asserts cstage/wwstage asm byte-id.
* NNN<950, self-contained (/tmp, no imports) — rule-14's
* selfhost-sibling race does not apply (903/940/945 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 drivers, exit==want, + cs==ww byte-id */
#define K_BUILDERR 1 /* build must FAIL with experr on BOTH drivers (rule 7) */
struct row { const char *label; const char *src; int want;
int kind; const char *experr; };
/* errlog_has — a BUILDERR row must fail WITH its diagnostic; any other
* failure (parse error, crash) 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[] = {
{ "letcall_packed",
"package main;\n"
"fn f() (u32, u32) = {\n"
" return (3, 4);\n"
"};\n"
"export fn main() i32 = {\n"
" let t: (u32, u32) = f();\n"
" if (t.0 != 3) { return 1; };\n"
" if (t.1 != 4) { return 2; };\n"
" return 0;\n"
"};\n", 0, K_RUN, NULL },
{ "letcall_float_packed",
"package main;\n"
"fn f() (u32, f64) = {\n"
" let a: u32 = 9;\n"
" let x: f64 = 2.5;\n"
" return (a, x);\n"
"};\n"
"export fn main() i32 = {\n"
" let t: (u32, f64) = f();\n"
" if (t.0 != 9) { return 1; };\n"
" if (t.1 != 2.5) { return 2; };\n"
" return 0;\n"
"};\n", 0, K_RUN, NULL },
{ "letcall_signed_packed",
"package main;\n"
"fn f() (i32, i32) = {\n"
" let a: i32 = -5;\n"
" let b: i32 = -6;\n"
" return (a, b);\n"
"};\n"
"export fn main() i32 = {\n"
" let t: (i32, i32) = f();\n"
" if (t.0 != -5) { return 1; };\n"
" if (t.1 != -6) { return 2; };\n"
" if (t.0 + t.1 != -11) { return 3; };\n"
" return 0;\n"
"};\n", 0, K_RUN, NULL },
{ "letcall_mixed_packed",
"package main;\n"
"fn f() (u32, str) = {\n"
" let a: u32 = 7;\n"
" let s: str = \"hello\";\n"
" return (a, s);\n"
"};\n"
"export fn main() i32 = {\n"
" let t: (u32, str) = f();\n"
" if (t.0 != 7) { return 1; };\n"
" if (len(t.1) != 5) { return 2; };\n"
" return 0;\n"
"};\n", 0, K_RUN, NULL },
{ "letcall_16_neutral",
"package main;\n"
"fn f() (i64, i64) = {\n"
" return (41, 17);\n"
"};\n"
"export fn main() i32 = {\n"
" let t: (i64, i64) = f();\n"
" if (t.0 != 41) { return 1; };\n"
" if (t.1 != 17) { return 2; };\n"
" return 0;\n"
"};\n", 0, K_RUN, NULL },
{ "letcall_32_neutral",
"package main;\n"
"fn f() (i64, str) = {\n"
" let a: i64 = 12;\n"
" let s: str = \"wxyz\";\n"
" return (a, s);\n"
"};\n"
"export fn main() i32 = {\n"
" let t: (i64, str) = f();\n"
" if (t.0 != 12) { return 1; };\n"
" if (len(t.1) != 4) { return 2; };\n"
" return 0;\n"
"};\n", 0, K_RUN, NULL },
{ "mlet_packed_neutral",
"package main;\n"
"fn f() (u32, u32) = {\n"
" return (3, 4);\n"
"};\n"
"export fn main() i32 = {\n"
" let (a, b) = f();\n"
" if (a != 3) { return 1; };\n"
" if (b != 4) { return 2; };\n"
" return 0;\n"
"};\n", 0, K_RUN, NULL },
/* ---- #22 commit 0: the wwstage size()/align() fold (astsize)
* summed PACKED element sizes for N_TTUPLE — a C-t0 escape. The
* type table (tupleelemslot) and cstage both said slot-sum;
* size((u32,u32)) folded to 16 on cstage and 8 on wwstage —
* silent cs≠ww in any folded constant. astsize now reads the
* tuple tinfo, so the slot SSoT has ONE wwstage answer. The
* recursive escapes (tuple inside struct/array sizing) ride the
* same arm. ---- */
{ "c0_sizefold_slot",
"package main;\n"
"export fn main() i32 = {\n"
" if (size((u32, u32)) != 16) { return 1; };\n"
" if (size((size, size)) != 16) { return 2; };\n"
" if (size((u32, str)) != 32) { return 3; };\n"
" if (size((str, str)) != 48) { return 4; };\n"
" if (align((u32, u32)) != 4) { return 5; };\n"
" return 0;\n"
"};\n", 0, K_RUN, NULL },
{ "c0_sizefold_recursive",
"package main;\n"
"type holder = struct { t: (u32, u32), x: i64 };\n"
"export fn main() i32 = {\n"
" if (size(holder) != 24) { return 1; };\n"
" if (size([4](u32, u32)) != 64) { return 2; };\n"
" return 0;\n"
"};\n", 0, K_RUN, NULL },
/* ---- #22a: TAGGED elements in tuples. slot = roundup8(size(elem))
* — 8B is a FLOOR, not a ceiling (user-ratified 2026-06-04).
* Pre-#22a the checker truncated a tagged element to one 8B slot
* (cstage SIZE 16 vs wwstage astsize 24, cs≠ww) and every cgen
* transport walk strode wide=(STR||SLICE)-else-8 — cstage read the
* NEIGHBOR slot, wwstage read ZEROS (both-wrong-differently,
* byte-cmp-blind). tuple_eslot/tupeslot is now the one stride
* accessor. In-cap shapes work end-to-end; over-cap (>4 GP
* eightbytes — the fold-5b 3-elem shape) stays LOUD until #22b.
* Tagged inits use the CAST form (`5: size`): the bare untyped-int
* widen-store mis-tag is a separate pre-existing bug (task #33). */
{ "t22_sizefold_tagged",
"package main;\n"
"export fn main() i32 = {\n"
" if (size(((void | size), size)) != 24) { return 1; };\n"
" if (size((size, (void | size))) != 24) { return 2; };\n"
" if (size(((void | size), (void | size), size)) != 40) { return 3; };\n"
" if (align(((void | size), size)) != 8) { return 4; };\n"
" if (size((u64, void)) != 8) { return 5; };\n"
" return 0;\n"
"};\n", 0, K_RUN, NULL },
{ "t22_roundtrip",
"package main;\n"
"fn mk() ((void | size), size) = {\n"
" let mn: (void | size) = 5: size;\n"
" return (mn, 4);\n"
"};\n"
"fn mk2() (size, (void | size)) = {\n"
" let mx: (void | size) = 7: size;\n"
" return (9, mx);\n"
"};\n"
"fn mkv() ((void | size), size) = {\n"
" let mn: (void | size) = void;\n"
" return (mn, 3);\n"
"};\n"
"export fn main() i32 = {\n"
" let t = mk();\n"
" if (!(t.0 is size)) { return 1; };\n"
" if (t.0 as size != 5) { return 2; };\n"
" if (t.1 != 4) { return 3; };\n"
" let u = mk2();\n"
" if (u.0 != 9) { return 4; };\n"
" if (!(u.1 is size)) { return 5; };\n"
" if (u.1 as size != 7) { return 6; };\n"
" let v = mkv();\n"
" if (!(v.0 is void)) { return 7; };\n"
" if (v.1 != 3) { return 8; };\n"
" let (a, b) = mk();\n"
" if (!(a is size)) { return 9; };\n"
" if (a as size != 5) { return 10; };\n"
" if (b != 4) { return 11; };\n"
" let mn: (void | size) = 6: size;\n"
" let w: ((void | size), size) = (mn, 2);\n"
" if (!(w.0 is size)) { return 12; };\n"
" if (w.0 as size != 6) { return 13; };\n"
" if (w.1 != 2) { return 14; };\n"
" return 0;\n"
"};\n", 0, K_RUN, NULL },
/* mixed SSE/GP with a tagged box: the f64 rides X0 on the SSE
* counter while the tagged element takes 2 consecutive GP
* eightbytes (GP total 3, in-cap) — pins the independent-counter
* interplay the scalar-only rows can't. */
{ "t22_float_mix",
"package main;\n"
"fn mk() (f64, (void | size), i64) = {\n"
" let mn: (void | size) = 6: size;\n"
" return (2.5, mn, 9);\n"
"};\n"
"export fn main() i32 = {\n"
" let t = mk();\n"
" if (t.0 != 2.5) { return 1; };\n"
" if (!(t.1 is size)) { return 2; };\n"
" if (t.1 as size != 6) { return 3; };\n"
" if (t.2 != 9) { return 4; };\n"
" let (x, y, z) = mk();\n"
" if (x != 2.5) { return 5; };\n"
" if (!(y is size)) { return 6; };\n"
" if (y as size != 6) { return 7; };\n"
" if (z != 9) { return 8; };\n"
" return 0;\n"
"};\n", 0, K_RUN, NULL },
/* TWO tagged elements in-cap (2+2 GP eightbytes == TUPLE_GPCAP):
* narrow u32 payload, negative i64 payload, void variant —
* regression-pins ken's k1 probe (probes evaporate, rows don't). */
{ "t22_two_tagged",
"package main;\n"
"fn mk() ((void | u32), (void | i64)) = {\n"
" let a: (void | u32) = 9: u32;\n"
" let b: (void | i64) = -5: i64;\n"
" return (a, b);\n"
"};\n"
"fn mkv() ((void | u32), (void | i64)) = {\n"
" let a: (void | u32) = void;\n"
" let b: (void | i64) = -41: i64;\n"
" return (a, b);\n"
"};\n"
"export fn main() i32 = {\n"
" let t = mk();\n"
" if (!(t.0 is u32)) { return 1; };\n"
" if (t.0 as u32 != 9) { return 2; };\n"
" if (!(t.1 is i64)) { return 3; };\n"
" if (t.1 as i64 != -5) { return 4; };\n"
" let v = mkv();\n"
" if (!(v.0 is void)) { return 5; };\n"
" if (v.1 as i64 != -41) { return 6; };\n"
" let (a, b) = mk();\n"
" if (a as u32 != 9) { return 7; };\n"
" if (b as i64 != -5) { return 8; };\n"
" return 0;\n"
"};\n", 0, K_RUN, NULL },
/* tagged FIRST, float second — the SSE/GP counter interplay in the
* other element order (t22_float_mix covers float-first; ken k2
* proved both orders, this pins the reverse). */
{ "t22_float_mix_rev",
"package main;\n"
"fn mk() ((void | size), f64) = {\n"
" let mn: (void | size) = 6: size;\n"
" return (mn, 0.25);\n"
"};\n"
"export fn main() i32 = {\n"
" let t = mk();\n"
" if (!(t.0 is size)) { return 1; };\n"
" if (t.0 as size != 6) { return 2; };\n"
" if (t.1 != 0.25) { return 3; };\n"
" let (y, z) = mk();\n"
" if (y as size != 6) { return 4; };\n"
" if (z != 0.25) { return 5; };\n"
" return 0;\n"
"};\n", 0, K_RUN, NULL },
/* tagged tuple element as a CALL ARG — the call-boundary SEND of
* the ruled condition-(c) matrix. cstage rides its generic
* node_istaggedarg cursor push; wwstage's kind-gated aistagged
* missed N_DOT and mis-routed t.0 into the widening branch
* (clamped tag 0 — callee read `void`, silent). reviewer-22 fix:
* cgenutil.ww N_DOT arm (aistagged + pushargsrev). */
{ "t22_elem_arg",
"package main;\n"
"fn takes(v: (void | size)) size = {\n"
" if (v is size) { return v as size; };\n"
" return 0;\n"
"};\n"
"export fn main() i32 = {\n"
" let mn: (void | size) = 5: size;\n"
" let t: ((void | size), size) = (mn, 4);\n"
" if (takes(t.0) != 5) { return 1; };\n"
" if (takes(t.0) + t.1 != 9) { return 2; };\n"
" return 0;\n"
"};\n", 0, K_RUN, NULL },
/* rule-7 louds: every tagged-tuple route that is not
* correct-via-accessor must die LOUD (the #22a exit invariant). */
{ "t22_reject_arg",
"package main;\n"
"fn send(t: ((void | size), size)) size = { return t.1; };\n"
"export fn main() i32 = {\n"
" let mn: (void | size) = 5: size;\n"
" let t: ((void | size), size) = (mn, 4);\n"
" return send(t): i32;\n"
"};\n", 0,
K_BUILDERR, "tuple arg element kind unsupported" },
{ "t22_reject_overcap_return",
"package main;\n"
"fn pr() ((void | size), (void | size), size) = {\n"
" let a: (void | size) = 1: size;\n"
" let b: (void | size) = 2: size;\n"
" return (a, b, 7);\n"
"};\n"
"export fn main() i32 = {\n"
" let t = pr();\n"
" return t.2: i32;\n"
"};\n", 0,
K_BUILDERR, "#22b: tagged element in an over-cap (sret) tuple "
"return unwired" },
/* ken R1: an OVER-CAP tuple literal init (a tagged box >16B pushes
* the shape past TUPLE_GPCAP) fell past every cstage N_LET store
* arm to NOTHING — silent uninitialized-frame reads — while
* wwstage loud-rejected. Pre-existing for (str,str) literals; the
* #22a tagged slots routed tagged shapes into it. Both pins. */
{ "t22_reject_overcap_lit_tagged",
"package main;\n"
"export fn main() i32 = {\n"
" let e: (void | u32 | str) = \"abc\";\n"
" let t: (u64, (void | u32 | str)) = (7u64, e);\n"
" if (t.0 != 7u64) { return 1; };\n"
" return 0;\n"
"};\n", 0,
K_BUILDERR, "tuple literal exceeds register-return ABI capacity" },
{ "t22_reject_overcap_lit_strs",
"package main;\n"
"export fn main() i32 = {\n"
" let t: (str, str) = (\"ab\", \"cde\");\n"
" if (t.0.len != 2) { return 1; };\n"
" return 0;\n"
"};\n", 0,
K_BUILDERR, "tuple literal exceeds register-return ABI capacity" },
{ "t22_reject_lit_call_elem",
"package main;\n"
"fn g() (void | size) = { return 5: size; };\n"
"fn mk() ((void | size), size) = { return (g(), 4); };\n"
"export fn main() i32 = {\n"
" let t = mk();\n"
" return t.1: i32;\n"
"};\n", 0,
K_BUILDERR, "tagged tuple element from a non-local source shape "
"unwired" },
{ "t22_reject_global_init",
"package main;\n"
"let g: ((void | size), i64) = (5, 4);\n"
"export fn main() i32 = { return g.1: i32; };\n", 0,
K_BUILDERR, "unsupported element init (int/str literals only; "
"rule 7)" },
/* pre-existing loud (no-regress pin): tuple element WRITE. */
{ "t22_reject_elem_write",
"package main;\n"
"export fn main() i32 = {\n"
" let mn: (void | size) = 5: size;\n"
" let t: ((void | size), size) = (mn, 4);\n"
" t.1 = 9;\n"
" return t.1: i32;\n"
"};\n", 0,
K_BUILDERR, "unsupported assign target shape" },
/* ---- over-cap (sret) NARROW-scalar stride: the sret buffer is
* slot-laid (C-t0) on EVERY side — send, let-receive, MLET, and
* MASSIGN copy-out. Pre-review the wwstage SEND and MASSIGN
* receive strode packed esz (4 for u32): self-consistent at base
* (ran right, byte-diff), but #22a's MLET-receive slot flip alone
* made ww read c at 32 while its send wrote 28 — a ww runtime
* REGRESSION the suite had no row for (reviewer-22). (str,u32,str)
* = 7 GP words, over-cap. ---- */
{ "sret_narrow_mix_let",
"package main;\n"
"fn f() (str, u32, str) = {\n"
" let a: str = \"abc\";\n"
" let b: u32 = 7;\n"
" let c: str = \"wxyz\";\n"
" return (a, b, c);\n"
"};\n"
"export fn main() i32 = {\n"
" let t = f();\n"
" if (len(t.0) != 3) { return 1; };\n"
" if (t.1 != 7) { return 2; };\n"
" if (len(t.2) != 4) { return 3; };\n"
" return 0;\n"
"};\n", 0, K_RUN, NULL },
{ "sret_narrow_mix_mlet",
"package main;\n"
"fn f() (str, u32, str) = {\n"
" let a: str = \"abc\";\n"
" let b: u32 = 7;\n"
" let c: str = \"wxyz\";\n"
" return (a, b, c);\n"
"};\n"
"export fn main() i32 = {\n"
" let (a, b, c) = f();\n"
" if (len(a) != 3) { return 1; };\n"
" if (b != 7) { return 2; };\n"
" if (len(c) != 4) { return 3; };\n"
" return 0;\n"
"};\n", 0, K_RUN, NULL },
{ "sret_narrow_mix_massign",
"package main;\n"
"fn f() (str, u32, str) = {\n"
" let a: str = \"abc\";\n"
" let b: u32 = 7;\n"
" let c: str = \"wxyz\";\n"
" return (a, b, c);\n"
"};\n"
"export fn main() i32 = {\n"
" let a: str = \"\";\n"
" let b: u32 = 0;\n"
" let c: str = \"\";\n"
" a, b, c = f();\n"
" if (len(a) != 3) { return 1; };\n"
" if (b != 7) { return 2; };\n"
" if (len(c) != 4) { return 3; };\n"
" return 0;\n"
"};\n", 0, K_RUN, NULL },
/* ---- C-t1 (#33): the let RECEIVE re-keyed onto the declared
* type's register classify. Pre-C-t1 wwstage keyed on producer
* SHAPE (mixed-str syntactic / rettupleof N_CALL) so a
* scalar-scalar LITERAL matched neither and dropped word 1;
* cstage keyed on sz==16/32 so 24B 3-scalar shapes dropped words
* on BOTH sources. ---- */
{ "t1_lit_packed",
"package main;\n"
"fn second() u32 = {\n"
" let t: (u32, u32) = (3, 4);\n"
" if (t.0 != 3) { return 99; };\n"
" return t.1;\n"
"};\n"
"export fn main() i32 = {\n"
" if (second() != 4) { return 1; };\n"
" return 0;\n"
"};\n", 0, K_RUN, NULL },
{ "t1_lit_16",
"package main;\n"
"export fn main() i32 = {\n"
" let t: (i64, i64) = (3, 4);\n"
" if (t.0 != 3) { return 1; };\n"
" if (t.1 != 4) { return 2; };\n"
" return 0;\n"
"};\n", 0, K_RUN, NULL },
{ "t1_lit_mixed",
"package main;\n"
"export fn main() i32 = {\n"
" let t: (i64, str) = (12, \"wxyz\");\n"
" if (t.0 != 12) { return 1; };\n"
" if (len(t.1) != 4) { return 2; };\n"
" return 0;\n"
"};\n", 0, K_RUN, NULL },
{ "t1_lit_3scalar",
"package main;\n"
"fn second() i64 = {\n"
" let t: (i64, i64, i64) = (3, 4, 5);\n"
" if (t.0 != 3) { return -1; };\n"
" if (t.1 != 4) { return -2; };\n"
" return t.2;\n"
"};\n"
"export fn main() i32 = {\n"
" if (second() != 5) { return 1; };\n"
" return 0;\n"
"};\n", 0, K_RUN, NULL },
{ "t1_call_3scalar",
"package main;\n"
"fn f() (i64, i64, i64) = {\n"
" return (7, 8, 9);\n"
"};\n"
"export fn main() i32 = {\n"
" let t: (i64, i64, i64) = f();\n"
" if (t.0 != 7) { return 1; };\n"
" if (t.1 != 8) { return 2; };\n"
" if (t.2 != 9) { return 3; };\n"
" return 0;\n"
"};\n", 0, K_RUN, NULL },
{ "t1_call_noannot_neutral",
"package main;\n"
"fn f() (i64, i64) = {\n"
" return (3, 4);\n"
"};\n"
"export fn main() i32 = {\n"
" let t = f();\n"
" if (t.0 != 3) { return 1; };\n"
" if (t.1 != 4) { return 2; };\n"
" return 0;\n"
"};\n", 0, K_RUN, NULL },
/* ---- C-t2 (#32): the by-value tuple ARG send. node_tuplearg
* was N_CALL-scoped (and its comment FALSELY claimed the rest
* loud-stop): a tuple ident/literal/unwrap arg fell to the
* scalar single-PUSHQ default, skewing every later arg register
* — the callee read garbage word 2 (packed shapes SIGSEGV'd
* pre-C-t0). Now every cursor-filling producer rides the #163
* @tupargscr restage; any other tuple-typed source loud-stops. ---- */
{ "t2_param_packed",
"package main;\n"
"fn pick(t: (u32, u32), k: i32) u32 = {\n"
" if (k == 0) { return t.0; };\n"
" return t.1;\n"
"};\n"
"export fn main() i32 = {\n"
" let t: (u32, u32) = (41, 17);\n"
" if (pick(t, 0) != 41) { return 1; };\n"
" if (pick(t, 1) != 17) { return 2; };\n"
" return 0;\n"
"};\n", 0, K_RUN, NULL },
{ "t2_param_16",
"package main;\n"
"fn pick(t: (i64, i64), k: i32) i64 = {\n"
" if (k == 0) { return t.0; };\n"
" return t.1;\n"
"};\n"
"export fn main() i32 = {\n"
" let t: (i64, i64) = (41, 17);\n"
" if (pick(t, 0) != 41) { return 1; };\n"
" if (pick(t, 1) != 17) { return 2; };\n"
" return 0;\n"
"};\n", 0, K_RUN, NULL },
{ "t2_mixed_order",
"package main;\n"
"fn g(a: i64, t: (u32, u32), b: i64) i64 = {\n"
" return a*1000 + (t.0: i64)*100 + (t.1: i64)*10 + b;\n"
"};\n"
"fn h(t: (i64, i64), s: str, k: i64) i64 = {\n"
" return t.0 + t.1 + (len(s): i64) + k;\n"
"};\n"
"export fn main() i32 = {\n"
" let t: (u32, u32) = (3, 4);\n"
" if (g(1, t, 2) != 1342) { return 1; };\n"
" let u: (i64, i64) = (10, 20);\n"
" if (h(u, \"abc\", 7) != 40) { return 2; };\n"
" return 0;\n"
"};\n", 0, K_RUN, NULL },
{ "t2_lit_arg",
"package main;\n"
"fn pick(t: (i64, i64), k: i32) i64 = {\n"
" if (k == 0) { return t.0; };\n"
" return t.1;\n"
"};\n"
"export fn main() i32 = {\n"
" if (pick((41, 17), 0) != 41) { return 1; };\n"
" if (pick((41, 17), 1) != 17) { return 2; };\n"
" return 0;\n"
"};\n", 0, K_RUN, NULL },
{ "t2_float_param",
"package main;\n"
"fn fsum(t: (f64, i64)) f64 = {\n"
" return t.0 + (t.1: f64);\n"
"};\n"
"export fn main() i32 = {\n"
" let t: (f64, i64) = (2.5, 4);\n"
" if (fsum(t) != 6.5) { return 1; };\n"
" return 0;\n"
"};\n", 0, K_RUN, NULL },
{ "t2_unwrap_arg",
"package main;\n"
"fn mk() ((i64, i64) | nomem) = {\n"
" let a: i64 = 5;\n"
" let b: i64 = 6;\n"
" return (a, b);\n"
"};\n"
"fn sum(t: (i64, i64)) i64 = {\n"
" return t.0 + t.1;\n"
"};\n"
"export fn main() i32 = {\n"
" if (sum(mk()!) != 11) { return 1; };\n"
" return 0;\n"
"};\n", 0, K_RUN, NULL },
/* ken's >6-GP-pressure stress: 4 leading scalars + the 2-word
* tuple + a 7th GP word — the restage drain fills the INTEGER
* cursor past the tuple and the 7th word must still land in the
* stack arg class, not be eaten or shifted by the tuple's pops. */
{ "t2_gp_pressure",
"package main;\n"
"fn f(a: i64, b: i64, c: i64, d: i64, t: (i64, i64), e: i64) i64 = {\n"
" if (e != 60) { return -1; };\n"
" if (a != 1 || b != 2 || c != 3 || d != 4) { return -2; };\n"
" return t.0 * 100 + t.1;\n"
"};\n"
"export fn main() i32 = {\n"
" let t: (i64, i64) = (7, 9);\n"
" if (f(1, 2, 3, 4, t, 60) != 709) { return 1; };\n"
" return 0;\n"
"};\n", 0, K_RUN, NULL },
/* a tuple arg mixed with a VARIADIC tail rides the same restage —
* positive pin of the variadic interaction (ken demand 2). */
{ "t2_variadic_after_tuple",
"package main;\n"
"fn g(t: (i64, i64), xs: i64...) i64 = {\n"
" let s: i64 = t.0 + t.1;\n"
" for (let x .. xs) { s += x; };\n"
" return s;\n"
"};\n"
"export fn main() i32 = {\n"
" let t: (i64, i64) = (3, 4);\n"
" if (g(t, 1, 2) != 10) { return 1; };\n"
" return 0;\n"
"};\n", 0, K_RUN, NULL },
/* rule-7 (ken demand 1): a NESTED composite element (tuple-in-
* tuple here) occupies more than the one GP word the restage walk
* counts — pre-guard the checker accepted it and it ran WRONG
* (inner words skewed; wwstage SIGSEGV'd). Loud until a consumer
* motivates the wiring. */
{ "t2_reject_nested_elem_arg",
"package main;\n"
"fn f(t: ((i64, i64), i64)) i64 = {\n"
" return t.1;\n"
"};\n"
"export fn main() i32 = {\n"
" let inner: (i64, i64) = (1, 2);\n"
" let t: ((i64, i64), i64) = (inner, 9);\n"
" if (f(t) != 9) { return 1; };\n"
" return 0;\n"
"};\n", 0,
K_BUILDERR, "tuple arg element kind unsupported" },
/* variadic-of-tuples ((i64,i64)...) stays LOUD via the
* tuple-in-slice read surface — bounded, not silent (demand 2). */
{ "t2_reject_variadic_of_tuples",
"package main;\n"
"fn first(ts: (i64, i64)...) i64 = {\n"
" if (len(ts) == 0) { return -1; };\n"
" return ts[0].0;\n"
"};\n"
"export fn main() i32 = {\n"
" let t: (i64, i64) = (3, 4);\n"
" if (first(t) != 3) { return 1; };\n"
" return 0;\n"
"};\n", 0,
K_BUILDERR, "unsupported field-read shape" },
/* rule-7: a tuple arg from a source whose cgexpr does NOT fill
* the cursor (here a struct-field chain) dies loud — pre-C-t2
* it fell to the scalar single-PUSHQ default silently. */
{ "t2_reject_chain_arg",
"package main;\n"
"type holder = struct { t: (i64, i64) };\n"
"fn sum(t: (i64, i64)) i64 = {\n"
" return t.0 + t.1;\n"
"};\n"
"export fn main() i32 = {\n"
" let h: holder = holder{ t = (1, 2) };\n"
" if (sum(h.t) != 3) { return 1; };\n"
" return 0;\n"
"};\n", 0,
K_BUILDERR, "tuple arg from unsupported source shape" },
/* rule-7: an over-cap tuple ident arg louds at the slot-to-cursor
* cap (the #10 sret follow-up), never a partial push. */
{ "t2_reject_overcap_ident_arg",
"package main;\n"
"fn f(t: (str, str)) i64 = {\n"
" return (len(t.0) + len(t.1)): i64;\n"
"};\n"
"fn g() (str, str) = {\n"
" return (\"ab\", \"cde\");\n"
"};\n"
"export fn main() i32 = {\n"
" let t: (str, str) = g();\n"
" if (f(t) != 5) { return 1; };\n"
" return 0;\n"
"};\n", 0,
K_BUILDERR, "tuple ident exceeds register-return ABI capacity" },
/* fold-4 substrate pin (charset_range_item = [](u32,u32)): the
* tuple-in-slice consumer shape is LOUD today, both stages —
* wiring it is fold-4's prerequisite work, not a silent gap. */
{ "charset_slice_append_reject",
"package main;\n"
"export fn main() i32 = {\n"
" let s: [](u32, u32) = [];\n"
" append(s, (1, 2));\n"
" if (len(s) != 1) { return 1; };\n"
" return 0;\n"
"};\n", 0,
K_BUILDERR, "element kind unsupported" },
/* ---- C-t3 (#48): GLOBAL tuples. Pre-C-t3 the definition was
* SILENTLY skipped (let_emit_size 0 → no DATA, no diagnostic);
* cstage element reads then read BP-frame garbage (localfind→0)
* and wwstage mis-emitted the field index as a symbol
* (`MOVQ 0(SB), AX`). Now: slot-laid DATAW (+ DATAR str-element
* ptr patches), element reads + len(g.N) via LEAQ sym(SB);
* unsupported element inits and the whole-tuple-as-value shape
* die LOUD. ---- */
{ "t3_global_elem",
"package main;\n"
"let g: (str, i64) = (\"hello\", 9);\n"
"let h: (u32, u32) = (5, 6);\n"
"export fn main() i32 = {\n"
" if (len(g.0) != 5) { return 1; };\n"
" if (g.1 != 9) { return 2; };\n"
" if (h.0 != 5) { return 3; };\n"
" if (h.1 != 6) { return 4; };\n"
" return 0;\n"
"};\n", 0, K_RUN, NULL },
{ "t3_reject_float_global",
"package main;\n"
"let g: (f64, i64) = (2.5, 4);\n"
"export fn main() i32 = {\n"
" if (g.1 != 4) { return 1; };\n"
" return 0;\n"
"};\n", 0,
K_BUILDERR, "unsupported element init (int/str literals only; rule 7)" },
{ "t3_reject_whole_value",
"package main;\n"
"let g: (i64, i64) = (3, 4);\n"
"export fn main() i32 = {\n"
" let q: (i64, i64) = g;\n"
" if (q.0 != 3) { return 1; };\n"
" return 0;\n"
"};\n", 0,
K_BUILDERR, "global tuple as a first-class value unwired" },
/* pre-existing loud (no-regress pin): global tuple element WRITE. */
{ "t3_reject_global_write",
"package main;\n"
"let g: (i64, i64) = (3, 4);\n"
"export fn main() i32 = {\n"
" g.0 = 7;\n"
" return 0;\n"
"};\n", 0,
K_BUILDERR, "unsupported assign target shape" },
};
/* build+run via a driver (ww / ww_ww); returns 0 pass, nonzero fail. */
static int
run_driver(const char *driver, const struct row *r, int i)
{
char src[96], tmpdir[96], errf[96], cmd[1024];
snprintf(src, sizeof src, "/tmp/tsl_%d_%d.ww", getpid(), i);
snprintf(tmpdir, sizeof tmpdir, "/tmp/tsl_%d_d_%d", getpid(), i);
snprintf(errf, sizeof errf, "/tmp/tsl_%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 && %s build %s >/dev/null 2>%s",
tmpdir, driver, src, errf);
int brc = runwait(cmd);
if (r->kind == K_BUILDERR) {
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 != r->want) {
fprintf(stderr, "row[%s]: %s exit %d, want %d\n",
r->label, driver, got, r->want);
return 1;
}
return 0;
}
/* cs==ww .s byte-id (rule 10). */
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/tsl_asm_%d_%d.ww", getpid(), i);
snprintf(cs, sizeof cs, "/tmp/tsl_asm_%d_%d_c.s", getpid(), i);
snprintf(ws, sizeof ws, "/tmp/tsl_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 (run_driver(cdrv, &rows[i], i) != 0) fail++;
}
if (access(wdrv, X_OK) == 0) {
for (int i = 0; i < n; i++) {
total++;
if (run_driver(wdrv, &rows[i], i) != 0) fail++;
}
for (int i = 0; i < n; i++) {
if (rows[i].kind == K_BUILDERR)
continue;
total++;
if (asm_byte_identical(bin, &rows[i], i) != 0) fail++;
}
}
if (fail) {
fprintf(stderr, "tuple_slot_layout: %d/%d checks failed\n",
fail, total);
return 1;
}
printf("tuple_slot_layout: %d/%d ok\n", total, total);
return 0;
}