w6c+w6c_ww: over-cap (sret) tuple returns carry tagged elements — MEMORY-class box copy (#22b)
The over-cap SEND gains a per-element tagged arm: a declared-TAGGED element copies its whole box mem-to-mem through the sret pointer (@sretarg reloaded into DX, eslot/8 AX-bounced word pairs) from its ident-local slot — cgexpr can't source it (tagged ident load is word0-only; the AX/DX/CX/R8 box cursor would collide with the DX dest-base reload). Non-ident/widening sources stay loud (call-source is task #41 per rob's loud+filed ruling, widening #23/#40). The receive legs were already eslot-generic from #22a except the wwstage MASSIGN sret copy-out, whose wide=(str||slice) key dropped a tagged element to the scalar 8B branch — re-keyed to the accessor's eslot>8. The over-cap DECISION now rides cg_sret_retsize/sretretsize on the DECLARED return type — the same SSoT the prologue @sretarg wiring and the caller use. The old expr-shape count disagreed with the classifier for declared-tagged elements with unwidened-payload exprs: the emit took the register path against an sret-reading caller — built clean, ran garbage, BOTH stages, byte-id, gate-blind (941 b22_reject_widen_ skew). A rule-7 net behind the branch catches any future inverse skew. The same classify/emit class on the LET side: wwstage's cgexpr cursor materialiser counts a void literal elem as 0 words, so a void-bearing over-cap literal init slipped its loud and fell past every store arm to NOTHING (cs louded via the ken-R1 net; ww ran silent-wrong) — wwstage gains the same net. foff advances ride tuple_eslot/tupeslotn (THE accessor): ken's K4 proved the old wide?esz:8 void-elem 8-advance was a LIVE silent miscompile at base (declared-void-elem over-cap return, send wrote +8 where every receive walks the 0-slot). The unwiring also made >32B boxes transportable, exposing the t.N tagged read's unbounded k<eslot/8 cursor walk: cstage OOB-indexed tuple_rseq[4] (invalid asm), wwstage tupreg-clamped k>=3 to R8 (silent payload-word-3 drop). Bounded loud both stages; the mem-based box read is #37's fold (transport itself is size-generic and correct — 941 b22_big_box_mlet). One commit by the #61 route-sharing precedent: unwiring the send is the only thing that makes the ww massign arm, both skew nets, and the >32B read reachable — the one split order that avoids a transient silent-wrong build (send last) lands those arms DEAD, unexercisable by any test until the unwiring commit, so a defect in them would bisect to the wrong commit; fused, every arm lands with the 941 rows that pin it, preserving the #22a exit invariant (zero silent tagged-tuple paths: correct-via-accessor or LOUD with a task cite; proof-greps in-tree — tuple_ebytes/tupebytes 0 hits, all remaining tuple_rseq/tupreg walks cap-validated upstream). Driver: regex fold-5b parse_repetition ((void|size),(void|size),size) = 5 GP eightbytes > TUPLE_GPCAP — pinned end-to-end (construct, send, let/MLET/MASSIGN receive, t.N is/as, destructure) plus head/mid/tail, str+tagged and SSE-over-cap mixes, `_` skip, and the reject pins: 941 165/165 (15 new rows), test-unit 281/281. ken runtime-oracle PASS x2 (independent hand-math layout audit, K1-K5 probes); reviewer-22b amendments (test-only): ken-K5 32B-exact box-at-cap row, both-tagged 2-elem row, chained-sret row, #37-family cite pinned in the big-box experr. Residuals filed: #39 return-forward divergence, #41 call-source tripwire, #37 mem-based box read.
This commit is contained in:
@@ -23170,6 +23170,20 @@ fn cgdot(c: *cgen, n: *node) void = {
|
||||
// tagged arm.
|
||||
if (istaggedtype(c, tpt)) {
|
||||
let eslot: i32 = tupeslotn(tpt);
|
||||
// #22b (rule 7): a >32B box
|
||||
// overruns the 4-reg cursor —
|
||||
// pre-bound tupreg clamped k>=3
|
||||
// to R8 (silent payload drop)
|
||||
// while cstage emitted invalid
|
||||
// asm. Reachable only since the
|
||||
// over-cap sret send unwired;
|
||||
// the mem-based box read is the
|
||||
// #37 family. Mirrors cstage.
|
||||
if (eslot > TUPLE_GPCAP * 8) {
|
||||
let m37: str = "tagged tuple element read exceeds the AX/DX/CX/R8 box cursor (mem-based read is the #37 family; rule 7)\n";
|
||||
os.write(2, m37.ptr, m37.len: u64);
|
||||
os.exit(1);
|
||||
};
|
||||
let k: i32 = 0;
|
||||
for (k < eslot / 8) {
|
||||
emitline("\tMOVQ\t");
|
||||
@@ -31320,8 +31334,8 @@ fn tuplitgpwords(c: *cgen, e: *node) i32 = {
|
||||
// tagged element loads its box words straight from its local slot —
|
||||
// cgexpr's ident load is word0-only for tagged (every tagged consumer
|
||||
// reads memory), so the cursor fill must too; any other tagged source
|
||||
// shape is loud (rule 7; the cursor-receive arm for call results is
|
||||
// with #22b's tupstore work, widening literals with #23). Mirror of
|
||||
// shape is loud (rule 7; the cursor-receive arm for call results
|
||||
// rides the #35 non-ident-source family, widening literals #23). Mirror of
|
||||
// cstage tuple_lit_push_elem — count (tuplitgpwords) and push live or
|
||||
// die together.
|
||||
fn tuplitpushelem(c: *cgen, e: *node) void = {
|
||||
@@ -31332,7 +31346,7 @@ fn tuplitpushelem(c: *cgen, e: *node) void = {
|
||||
let eoff: i32 = 0;
|
||||
if (e.kind == nkind.N_IDENT) { eoff = localfind(c, e.str); };
|
||||
if (eoff == 0) {
|
||||
let m22: str = "#22a: tagged tuple element from a non-local source shape unwired (ident locals only; rule 7, #22b/#23 follow-ups)\n";
|
||||
let m22: str = "#22a: tagged tuple element from a non-local source shape unwired (ident locals only; rule 7; call-source is task #41, widening #23, deref/cast #35)\n";
|
||||
os.write(2, m22.ptr, m22.len: u64);
|
||||
os.exit(1);
|
||||
};
|
||||
@@ -31569,24 +31583,21 @@ fn cgreturn(c: *cgen, n: *node) void = {
|
||||
};
|
||||
e = e.next;
|
||||
};
|
||||
if (gptotal > TUPLE_GPCAP || ssecount > ssecap) {
|
||||
// #22a (rule 7): a tagged element's box can't
|
||||
// ride the scalar/wide store arms below — the
|
||||
// MEMORY-class tagged element store is #22b
|
||||
// (task #28); pre-guard it silently stored
|
||||
// word0 of the box.
|
||||
let gq: *node = nil;
|
||||
if (c.fnret != nil) { gq = c.fnret.list; };
|
||||
for (gq != nil) {
|
||||
let gqt: *tinfo = gq.lhs.type_: *tinfo;
|
||||
for (gqt != nil && gqt.kind == tykind.TY_NAMED) { gqt = gqt.under; };
|
||||
if (gqt != nil && gqt.kind == tykind.TY_TAGGED) {
|
||||
let m22b: str = "#22b: tagged element in an over-cap (sret) tuple return unwired (rule 7)\n";
|
||||
os.write(2, m22b.ptr, m22b.len: u64);
|
||||
os.exit(1);
|
||||
};
|
||||
gq = gq.next;
|
||||
};
|
||||
// #22b: classify and emit MUST agree (the #10 SSoT note
|
||||
// at TUPLE_GPCAP). The over-cap DECISION rides
|
||||
// sretretsize on the DECLARED return type — the same
|
||||
// predicate the prologue (@sretarg) and the caller key
|
||||
// on. The expr-shape count above only pairs the in-cap
|
||||
// push/pop: a declared-tagged element whose expr is the
|
||||
// unwidened payload counts 1 word here vs 2+ declared
|
||||
// eightbytes, so the emit took the register path against
|
||||
// an sret-classified caller — silent garbage, both
|
||||
// stages, gate-blind (probe /tmp/i22b/p2).
|
||||
let overcap: bool = gptotal > TUPLE_GPCAP || ssecount > ssecap;
|
||||
if (c.fnret != nil) {
|
||||
overcap = sretretsize(c, c.fnret) > 0;
|
||||
};
|
||||
if (overcap) {
|
||||
// #10 Fold A: over-cap tuple returns via sret. The
|
||||
// prologue wired @sretarg (sretretsize agrees on the
|
||||
// caps — TUPLE_GPCAP/TUPLE_SSECAP, the shared SSoT),
|
||||
@@ -31607,6 +31618,55 @@ fn cgreturn(c: *cgen, n: *node) void = {
|
||||
let we: *node = rhs.list;
|
||||
let foff: i32 = 0;
|
||||
for (we != nil) {
|
||||
let dt: *tinfo = nil;
|
||||
if (pt != nil) { dt = pt.lhs.type_: *tinfo; };
|
||||
for (dt != nil && dt.kind == tykind.TY_NAMED) { dt = dt.under; };
|
||||
if (dt != nil && dt.kind == tykind.TY_TAGGED) {
|
||||
// #22b (task #28): MEMORY-class tagged
|
||||
// element — the whole box copies through
|
||||
// the sret pointer mem-to-mem from the
|
||||
// element's local slot. cgexpr can't
|
||||
// source it: the tagged ident load is
|
||||
// word0-only (every tagged consumer
|
||||
// reads memory) and the AX/DX/CX/R8 box
|
||||
// cursor would collide with the DX
|
||||
// dest-base reload. Ident-only,
|
||||
// mirroring tuplitpushelem; widening /
|
||||
// non-ident sources stay loud (#23/#40
|
||||
// follow-ups). Mirror of cstage cgen.c
|
||||
// N_RETURN over-cap tagged arm.
|
||||
let eslot: i32 = tupeslotn(pt.lhs);
|
||||
let eu: *tinfo = we.type_: *tinfo;
|
||||
for (eu != nil && eu.kind == tykind.TY_NAMED) { eu = eu.under; };
|
||||
let eoff: i32 = 0;
|
||||
if (we.kind == nkind.N_IDENT && eu != nil) {
|
||||
if (eu.kind == tykind.TY_TAGGED && tupeslotn(we) == eslot) {
|
||||
eoff = localfind(c, we.str);
|
||||
};
|
||||
};
|
||||
if (eoff == 0) {
|
||||
let m22b: str = "#22b: tagged element in an over-cap (sret) tuple return from a non-ident or widening source unwired (ident locals only; rule 7; call-source is task #41, widening #23/#40)\n";
|
||||
os.write(2, m22b.ptr, m22b.len: u64);
|
||||
os.exit(1);
|
||||
};
|
||||
emitline("\tMOVQ\t");
|
||||
emitoff(saoff: i64);
|
||||
emitline("(BP), DX\n");
|
||||
let bk: i32 = 0;
|
||||
for (bk < eslot) {
|
||||
emitline("\tMOVQ\t");
|
||||
emitoff((eoff + bk): i64);
|
||||
emitline("(BP), AX\n");
|
||||
emitline("\tMOVQ\tAX, ");
|
||||
emitdispreg((foff + bk): i64, "DX");
|
||||
emitline("\n");
|
||||
bk += 8;
|
||||
};
|
||||
foff += eslot;
|
||||
we = we.next;
|
||||
if (pt != nil) { pt = pt.next; };
|
||||
continue;
|
||||
};
|
||||
let isflt: bool = isfloattype(c, we);
|
||||
let wide: bool = nodeisstr(c, we) || nodeisslice(c, we);
|
||||
let esz: i32 = 8;
|
||||
@@ -31646,12 +31706,17 @@ fn cgreturn(c: *cgen, n: *node) void = {
|
||||
emitline("\n");
|
||||
};
|
||||
};
|
||||
// C-t0: the sret buffer is slot-laid like
|
||||
// C-t0/#22: the sret buffer is slot-laid like
|
||||
// every tuple home (checker size, t.N
|
||||
// reader, mlet receive agree); esz keeps
|
||||
// the store WIDTH natural. Mirrors cstage
|
||||
// cgen.c N_RETURN over-cap arm.
|
||||
if (wide) { foff += esz; } else { foff += 8; };
|
||||
// reader, mlet receive agree) — the stride
|
||||
// is THE accessor's (a declared void
|
||||
// element's 0-slot included; the old
|
||||
// wide?esz:8 advanced 8 where every receive
|
||||
// walks 0). esz keeps the store WIDTH
|
||||
// natural. Mirrors cstage cgen.c N_RETURN
|
||||
// over-cap arm.
|
||||
if (pt != nil) { foff += tupeslotn(pt.lhs); }
|
||||
else { foff += tupeslotn(we); };
|
||||
we = we.next;
|
||||
if (pt != nil) { pt = pt.next; };
|
||||
};
|
||||
@@ -31664,6 +31729,16 @@ fn cgreturn(c: *cgen, n: *node) void = {
|
||||
c.lastwasreturn = 1;
|
||||
return;
|
||||
};
|
||||
// rule-7 net: register-classified by the declared type
|
||||
// but the expr-shape count overflows the cursor — the
|
||||
// pops below would index past tupreg. Unreachable while
|
||||
// expr counts never exceed declared counts; loud, not
|
||||
// OOB, if a future shape breaks that. Mirrors cstage.
|
||||
if (gptotal > TUPLE_GPCAP || ssecount > ssecap) {
|
||||
let mskew: str = "register-classified tuple return exceeds the cursor (classify/emit skew; rule 7, #22b)\n";
|
||||
os.write(2, mskew.ptr, mskew.len: u64);
|
||||
os.exit(1);
|
||||
};
|
||||
let fscr: i32 = 0;
|
||||
if (ssecount > 0) {
|
||||
fscr = localadd(c, "@tupfscr", ssecap * 8, nil);
|
||||
@@ -33140,6 +33215,24 @@ fn cglet(c: *cgen, n: *node) void = {
|
||||
c.lastwasreturn = 0;
|
||||
return;
|
||||
};
|
||||
// #22a (rule 7, ken R1) wwstage half: an OVER-CAP tuple
|
||||
// init whose rhs is not a CALL has no store path — only
|
||||
// the CALL shape rides the sret receive below; every
|
||||
// other rhs fell past ALL the store arms to NOTHING
|
||||
// (silent uninitialized-frame reads). cgexpr's cursor
|
||||
// materialisers loud most shapes, but their EXPR-shape
|
||||
// counts let a declared-tagged element's unwidened
|
||||
// payload (or a void literal) slip through in-cap
|
||||
// (probe /tmp/i22b/p7) — the let-twin of the #22b
|
||||
// classify/emit skew. Mirrors cstage cgen.c N_LET net.
|
||||
if (ttup.kind == nkind.N_TTUPLE
|
||||
&& rhs.kind != nkind.N_CALL
|
||||
&& sretretsize(c, ttup) > 0) {
|
||||
cgexpr(c, rhs);
|
||||
let mnet: str = "over-cap tuple initialiser from a non-call source unwired (see #10/#22b)\n";
|
||||
os.write(2, mnet.ptr, mnet.len: u64);
|
||||
os.exit(1);
|
||||
};
|
||||
};
|
||||
// Array literal init: `let xs: [N]T = [a, b, c];` (or [_]T).
|
||||
// Walk elements in declaration order, store each at off + i*esz
|
||||
@@ -33932,7 +34025,14 @@ fn cgmassign(c: *cgen, n: *node) void = {
|
||||
let tn: *node = nil;
|
||||
if (pt2 != nil) { tn = pt2.lhs; };
|
||||
let isflt: bool = isfloattype(c, tn);
|
||||
let wide: bool = isstrtype(c, tn) || isslicetype(c, tn);
|
||||
// #22b: the >8B copy-out keys on the ACCESSOR's slot
|
||||
// (str/slice header AND tagged box), not a str/slice
|
||||
// kind test — the tagged element took the scalar arm
|
||||
// (8B silent truncation; unreachable while the SEND
|
||||
// louded, live once #22b unwires it). Byte-id for
|
||||
// str/slice (esz == eslot == 24). Mirrors the cstage
|
||||
// N_MASSIGN sret arm + the R-1 all-three-routings lesson.
|
||||
let eslot: i32 = tupeslotn(tn);
|
||||
let esz: i32 = 8;
|
||||
if (pt2 != nil) {
|
||||
let eti: *tinfo = pt2.lhs.type_: *tinfo;
|
||||
@@ -33951,9 +34051,9 @@ fn cgmassign(c: *cgen, n: *node) void = {
|
||||
emitline("\tX0, ");
|
||||
emitoff(off: i64); emitline("(BP)\n");
|
||||
} else {
|
||||
if (wide) {
|
||||
if (eslot > 8) {
|
||||
let k: i32 = 0;
|
||||
for (k < esz) {
|
||||
for (k < eslot) {
|
||||
emitline("\tMOVQ\t");
|
||||
emitoff((scr + foff + k): i64);
|
||||
emitline("(BP), AX\n");
|
||||
|
||||
@@ -2703,6 +2703,20 @@ fn cgdot(c: *cgen, n: *node) void = {
|
||||
// tagged arm.
|
||||
if (istaggedtype(c, tpt)) {
|
||||
let eslot: i32 = tupeslotn(tpt);
|
||||
// #22b (rule 7): a >32B box
|
||||
// overruns the 4-reg cursor —
|
||||
// pre-bound tupreg clamped k>=3
|
||||
// to R8 (silent payload drop)
|
||||
// while cstage emitted invalid
|
||||
// asm. Reachable only since the
|
||||
// over-cap sret send unwired;
|
||||
// the mem-based box read is the
|
||||
// #37 family. Mirrors cstage.
|
||||
if (eslot > TUPLE_GPCAP * 8) {
|
||||
let m37: str = "tagged tuple element read exceeds the AX/DX/CX/R8 box cursor (mem-based read is the #37 family; rule 7)\n";
|
||||
os.write(2, m37.ptr, m37.len: u64);
|
||||
os.exit(1);
|
||||
};
|
||||
let k: i32 = 0;
|
||||
for (k < eslot / 8) {
|
||||
emitline("\tMOVQ\t");
|
||||
|
||||
@@ -325,8 +325,8 @@ fn tuplitgpwords(c: *cgen, e: *node) i32 = {
|
||||
// tagged element loads its box words straight from its local slot —
|
||||
// cgexpr's ident load is word0-only for tagged (every tagged consumer
|
||||
// reads memory), so the cursor fill must too; any other tagged source
|
||||
// shape is loud (rule 7; the cursor-receive arm for call results is
|
||||
// with #22b's tupstore work, widening literals with #23). Mirror of
|
||||
// shape is loud (rule 7; the cursor-receive arm for call results
|
||||
// rides the #35 non-ident-source family, widening literals #23). Mirror of
|
||||
// cstage tuple_lit_push_elem — count (tuplitgpwords) and push live or
|
||||
// die together.
|
||||
fn tuplitpushelem(c: *cgen, e: *node) void = {
|
||||
@@ -337,7 +337,7 @@ fn tuplitpushelem(c: *cgen, e: *node) void = {
|
||||
let eoff: i32 = 0;
|
||||
if (e.kind == nkind.N_IDENT) { eoff = localfind(c, e.str); };
|
||||
if (eoff == 0) {
|
||||
let m22: str = "#22a: tagged tuple element from a non-local source shape unwired (ident locals only; rule 7, #22b/#23 follow-ups)\n";
|
||||
let m22: str = "#22a: tagged tuple element from a non-local source shape unwired (ident locals only; rule 7; call-source is task #41, widening #23, deref/cast #35)\n";
|
||||
os.write(2, m22.ptr, m22.len: u64);
|
||||
os.exit(1);
|
||||
};
|
||||
@@ -574,24 +574,21 @@ fn cgreturn(c: *cgen, n: *node) void = {
|
||||
};
|
||||
e = e.next;
|
||||
};
|
||||
if (gptotal > TUPLE_GPCAP || ssecount > ssecap) {
|
||||
// #22a (rule 7): a tagged element's box can't
|
||||
// ride the scalar/wide store arms below — the
|
||||
// MEMORY-class tagged element store is #22b
|
||||
// (task #28); pre-guard it silently stored
|
||||
// word0 of the box.
|
||||
let gq: *node = nil;
|
||||
if (c.fnret != nil) { gq = c.fnret.list; };
|
||||
for (gq != nil) {
|
||||
let gqt: *tinfo = gq.lhs.type_: *tinfo;
|
||||
for (gqt != nil && gqt.kind == tykind.TY_NAMED) { gqt = gqt.under; };
|
||||
if (gqt != nil && gqt.kind == tykind.TY_TAGGED) {
|
||||
let m22b: str = "#22b: tagged element in an over-cap (sret) tuple return unwired (rule 7)\n";
|
||||
os.write(2, m22b.ptr, m22b.len: u64);
|
||||
os.exit(1);
|
||||
};
|
||||
gq = gq.next;
|
||||
};
|
||||
// #22b: classify and emit MUST agree (the #10 SSoT note
|
||||
// at TUPLE_GPCAP). The over-cap DECISION rides
|
||||
// sretretsize on the DECLARED return type — the same
|
||||
// predicate the prologue (@sretarg) and the caller key
|
||||
// on. The expr-shape count above only pairs the in-cap
|
||||
// push/pop: a declared-tagged element whose expr is the
|
||||
// unwidened payload counts 1 word here vs 2+ declared
|
||||
// eightbytes, so the emit took the register path against
|
||||
// an sret-classified caller — silent garbage, both
|
||||
// stages, gate-blind (probe /tmp/i22b/p2).
|
||||
let overcap: bool = gptotal > TUPLE_GPCAP || ssecount > ssecap;
|
||||
if (c.fnret != nil) {
|
||||
overcap = sretretsize(c, c.fnret) > 0;
|
||||
};
|
||||
if (overcap) {
|
||||
// #10 Fold A: over-cap tuple returns via sret. The
|
||||
// prologue wired @sretarg (sretretsize agrees on the
|
||||
// caps — TUPLE_GPCAP/TUPLE_SSECAP, the shared SSoT),
|
||||
@@ -612,6 +609,55 @@ fn cgreturn(c: *cgen, n: *node) void = {
|
||||
let we: *node = rhs.list;
|
||||
let foff: i32 = 0;
|
||||
for (we != nil) {
|
||||
let dt: *tinfo = nil;
|
||||
if (pt != nil) { dt = pt.lhs.type_: *tinfo; };
|
||||
for (dt != nil && dt.kind == tykind.TY_NAMED) { dt = dt.under; };
|
||||
if (dt != nil && dt.kind == tykind.TY_TAGGED) {
|
||||
// #22b (task #28): MEMORY-class tagged
|
||||
// element — the whole box copies through
|
||||
// the sret pointer mem-to-mem from the
|
||||
// element's local slot. cgexpr can't
|
||||
// source it: the tagged ident load is
|
||||
// word0-only (every tagged consumer
|
||||
// reads memory) and the AX/DX/CX/R8 box
|
||||
// cursor would collide with the DX
|
||||
// dest-base reload. Ident-only,
|
||||
// mirroring tuplitpushelem; widening /
|
||||
// non-ident sources stay loud (#23/#40
|
||||
// follow-ups). Mirror of cstage cgen.c
|
||||
// N_RETURN over-cap tagged arm.
|
||||
let eslot: i32 = tupeslotn(pt.lhs);
|
||||
let eu: *tinfo = we.type_: *tinfo;
|
||||
for (eu != nil && eu.kind == tykind.TY_NAMED) { eu = eu.under; };
|
||||
let eoff: i32 = 0;
|
||||
if (we.kind == nkind.N_IDENT && eu != nil) {
|
||||
if (eu.kind == tykind.TY_TAGGED && tupeslotn(we) == eslot) {
|
||||
eoff = localfind(c, we.str);
|
||||
};
|
||||
};
|
||||
if (eoff == 0) {
|
||||
let m22b: str = "#22b: tagged element in an over-cap (sret) tuple return from a non-ident or widening source unwired (ident locals only; rule 7; call-source is task #41, widening #23/#40)\n";
|
||||
os.write(2, m22b.ptr, m22b.len: u64);
|
||||
os.exit(1);
|
||||
};
|
||||
emitline("\tMOVQ\t");
|
||||
emitoff(saoff: i64);
|
||||
emitline("(BP), DX\n");
|
||||
let bk: i32 = 0;
|
||||
for (bk < eslot) {
|
||||
emitline("\tMOVQ\t");
|
||||
emitoff((eoff + bk): i64);
|
||||
emitline("(BP), AX\n");
|
||||
emitline("\tMOVQ\tAX, ");
|
||||
emitdispreg((foff + bk): i64, "DX");
|
||||
emitline("\n");
|
||||
bk += 8;
|
||||
};
|
||||
foff += eslot;
|
||||
we = we.next;
|
||||
if (pt != nil) { pt = pt.next; };
|
||||
continue;
|
||||
};
|
||||
let isflt: bool = isfloattype(c, we);
|
||||
let wide: bool = nodeisstr(c, we) || nodeisslice(c, we);
|
||||
let esz: i32 = 8;
|
||||
@@ -651,12 +697,17 @@ fn cgreturn(c: *cgen, n: *node) void = {
|
||||
emitline("\n");
|
||||
};
|
||||
};
|
||||
// C-t0: the sret buffer is slot-laid like
|
||||
// C-t0/#22: the sret buffer is slot-laid like
|
||||
// every tuple home (checker size, t.N
|
||||
// reader, mlet receive agree); esz keeps
|
||||
// the store WIDTH natural. Mirrors cstage
|
||||
// cgen.c N_RETURN over-cap arm.
|
||||
if (wide) { foff += esz; } else { foff += 8; };
|
||||
// reader, mlet receive agree) — the stride
|
||||
// is THE accessor's (a declared void
|
||||
// element's 0-slot included; the old
|
||||
// wide?esz:8 advanced 8 where every receive
|
||||
// walks 0). esz keeps the store WIDTH
|
||||
// natural. Mirrors cstage cgen.c N_RETURN
|
||||
// over-cap arm.
|
||||
if (pt != nil) { foff += tupeslotn(pt.lhs); }
|
||||
else { foff += tupeslotn(we); };
|
||||
we = we.next;
|
||||
if (pt != nil) { pt = pt.next; };
|
||||
};
|
||||
@@ -669,6 +720,16 @@ fn cgreturn(c: *cgen, n: *node) void = {
|
||||
c.lastwasreturn = 1;
|
||||
return;
|
||||
};
|
||||
// rule-7 net: register-classified by the declared type
|
||||
// but the expr-shape count overflows the cursor — the
|
||||
// pops below would index past tupreg. Unreachable while
|
||||
// expr counts never exceed declared counts; loud, not
|
||||
// OOB, if a future shape breaks that. Mirrors cstage.
|
||||
if (gptotal > TUPLE_GPCAP || ssecount > ssecap) {
|
||||
let mskew: str = "register-classified tuple return exceeds the cursor (classify/emit skew; rule 7, #22b)\n";
|
||||
os.write(2, mskew.ptr, mskew.len: u64);
|
||||
os.exit(1);
|
||||
};
|
||||
let fscr: i32 = 0;
|
||||
if (ssecount > 0) {
|
||||
fscr = localadd(c, "@tupfscr", ssecap * 8, nil);
|
||||
@@ -2145,6 +2206,24 @@ fn cglet(c: *cgen, n: *node) void = {
|
||||
c.lastwasreturn = 0;
|
||||
return;
|
||||
};
|
||||
// #22a (rule 7, ken R1) wwstage half: an OVER-CAP tuple
|
||||
// init whose rhs is not a CALL has no store path — only
|
||||
// the CALL shape rides the sret receive below; every
|
||||
// other rhs fell past ALL the store arms to NOTHING
|
||||
// (silent uninitialized-frame reads). cgexpr's cursor
|
||||
// materialisers loud most shapes, but their EXPR-shape
|
||||
// counts let a declared-tagged element's unwidened
|
||||
// payload (or a void literal) slip through in-cap
|
||||
// (probe /tmp/i22b/p7) — the let-twin of the #22b
|
||||
// classify/emit skew. Mirrors cstage cgen.c N_LET net.
|
||||
if (ttup.kind == nkind.N_TTUPLE
|
||||
&& rhs.kind != nkind.N_CALL
|
||||
&& sretretsize(c, ttup) > 0) {
|
||||
cgexpr(c, rhs);
|
||||
let mnet: str = "over-cap tuple initialiser from a non-call source unwired (see #10/#22b)\n";
|
||||
os.write(2, mnet.ptr, mnet.len: u64);
|
||||
os.exit(1);
|
||||
};
|
||||
};
|
||||
// Array literal init: `let xs: [N]T = [a, b, c];` (or [_]T).
|
||||
// Walk elements in declaration order, store each at off + i*esz
|
||||
@@ -2937,7 +3016,14 @@ fn cgmassign(c: *cgen, n: *node) void = {
|
||||
let tn: *node = nil;
|
||||
if (pt2 != nil) { tn = pt2.lhs; };
|
||||
let isflt: bool = isfloattype(c, tn);
|
||||
let wide: bool = isstrtype(c, tn) || isslicetype(c, tn);
|
||||
// #22b: the >8B copy-out keys on the ACCESSOR's slot
|
||||
// (str/slice header AND tagged box), not a str/slice
|
||||
// kind test — the tagged element took the scalar arm
|
||||
// (8B silent truncation; unreachable while the SEND
|
||||
// louded, live once #22b unwires it). Byte-id for
|
||||
// str/slice (esz == eslot == 24). Mirrors the cstage
|
||||
// N_MASSIGN sret arm + the R-1 all-three-routings lesson.
|
||||
let eslot: i32 = tupeslotn(tn);
|
||||
let esz: i32 = 8;
|
||||
if (pt2 != nil) {
|
||||
let eti: *tinfo = pt2.lhs.type_: *tinfo;
|
||||
@@ -2956,9 +3042,9 @@ fn cgmassign(c: *cgen, n: *node) void = {
|
||||
emitline("\tX0, ");
|
||||
emitoff(off: i64); emitline("(BP)\n");
|
||||
} else {
|
||||
if (wide) {
|
||||
if (eslot > 8) {
|
||||
let k: i32 = 0;
|
||||
for (k < esz) {
|
||||
for (k < eslot) {
|
||||
emitline("\tMOVQ\t");
|
||||
emitoff((scr + foff + k): i64);
|
||||
emitline("(BP), AX\n");
|
||||
|
||||
@@ -23170,6 +23170,20 @@ fn cgdot(c: *cgen, n: *node) void = {
|
||||
// tagged arm.
|
||||
if (istaggedtype(c, tpt)) {
|
||||
let eslot: i32 = tupeslotn(tpt);
|
||||
// #22b (rule 7): a >32B box
|
||||
// overruns the 4-reg cursor —
|
||||
// pre-bound tupreg clamped k>=3
|
||||
// to R8 (silent payload drop)
|
||||
// while cstage emitted invalid
|
||||
// asm. Reachable only since the
|
||||
// over-cap sret send unwired;
|
||||
// the mem-based box read is the
|
||||
// #37 family. Mirrors cstage.
|
||||
if (eslot > TUPLE_GPCAP * 8) {
|
||||
let m37: str = "tagged tuple element read exceeds the AX/DX/CX/R8 box cursor (mem-based read is the #37 family; rule 7)\n";
|
||||
os.write(2, m37.ptr, m37.len: u64);
|
||||
os.exit(1);
|
||||
};
|
||||
let k: i32 = 0;
|
||||
for (k < eslot / 8) {
|
||||
emitline("\tMOVQ\t");
|
||||
@@ -31320,8 +31334,8 @@ fn tuplitgpwords(c: *cgen, e: *node) i32 = {
|
||||
// tagged element loads its box words straight from its local slot —
|
||||
// cgexpr's ident load is word0-only for tagged (every tagged consumer
|
||||
// reads memory), so the cursor fill must too; any other tagged source
|
||||
// shape is loud (rule 7; the cursor-receive arm for call results is
|
||||
// with #22b's tupstore work, widening literals with #23). Mirror of
|
||||
// shape is loud (rule 7; the cursor-receive arm for call results
|
||||
// rides the #35 non-ident-source family, widening literals #23). Mirror of
|
||||
// cstage tuple_lit_push_elem — count (tuplitgpwords) and push live or
|
||||
// die together.
|
||||
fn tuplitpushelem(c: *cgen, e: *node) void = {
|
||||
@@ -31332,7 +31346,7 @@ fn tuplitpushelem(c: *cgen, e: *node) void = {
|
||||
let eoff: i32 = 0;
|
||||
if (e.kind == nkind.N_IDENT) { eoff = localfind(c, e.str); };
|
||||
if (eoff == 0) {
|
||||
let m22: str = "#22a: tagged tuple element from a non-local source shape unwired (ident locals only; rule 7, #22b/#23 follow-ups)\n";
|
||||
let m22: str = "#22a: tagged tuple element from a non-local source shape unwired (ident locals only; rule 7; call-source is task #41, widening #23, deref/cast #35)\n";
|
||||
os.write(2, m22.ptr, m22.len: u64);
|
||||
os.exit(1);
|
||||
};
|
||||
@@ -31569,24 +31583,21 @@ fn cgreturn(c: *cgen, n: *node) void = {
|
||||
};
|
||||
e = e.next;
|
||||
};
|
||||
if (gptotal > TUPLE_GPCAP || ssecount > ssecap) {
|
||||
// #22a (rule 7): a tagged element's box can't
|
||||
// ride the scalar/wide store arms below — the
|
||||
// MEMORY-class tagged element store is #22b
|
||||
// (task #28); pre-guard it silently stored
|
||||
// word0 of the box.
|
||||
let gq: *node = nil;
|
||||
if (c.fnret != nil) { gq = c.fnret.list; };
|
||||
for (gq != nil) {
|
||||
let gqt: *tinfo = gq.lhs.type_: *tinfo;
|
||||
for (gqt != nil && gqt.kind == tykind.TY_NAMED) { gqt = gqt.under; };
|
||||
if (gqt != nil && gqt.kind == tykind.TY_TAGGED) {
|
||||
let m22b: str = "#22b: tagged element in an over-cap (sret) tuple return unwired (rule 7)\n";
|
||||
os.write(2, m22b.ptr, m22b.len: u64);
|
||||
os.exit(1);
|
||||
};
|
||||
gq = gq.next;
|
||||
};
|
||||
// #22b: classify and emit MUST agree (the #10 SSoT note
|
||||
// at TUPLE_GPCAP). The over-cap DECISION rides
|
||||
// sretretsize on the DECLARED return type — the same
|
||||
// predicate the prologue (@sretarg) and the caller key
|
||||
// on. The expr-shape count above only pairs the in-cap
|
||||
// push/pop: a declared-tagged element whose expr is the
|
||||
// unwidened payload counts 1 word here vs 2+ declared
|
||||
// eightbytes, so the emit took the register path against
|
||||
// an sret-classified caller — silent garbage, both
|
||||
// stages, gate-blind (probe /tmp/i22b/p2).
|
||||
let overcap: bool = gptotal > TUPLE_GPCAP || ssecount > ssecap;
|
||||
if (c.fnret != nil) {
|
||||
overcap = sretretsize(c, c.fnret) > 0;
|
||||
};
|
||||
if (overcap) {
|
||||
// #10 Fold A: over-cap tuple returns via sret. The
|
||||
// prologue wired @sretarg (sretretsize agrees on the
|
||||
// caps — TUPLE_GPCAP/TUPLE_SSECAP, the shared SSoT),
|
||||
@@ -31607,6 +31618,55 @@ fn cgreturn(c: *cgen, n: *node) void = {
|
||||
let we: *node = rhs.list;
|
||||
let foff: i32 = 0;
|
||||
for (we != nil) {
|
||||
let dt: *tinfo = nil;
|
||||
if (pt != nil) { dt = pt.lhs.type_: *tinfo; };
|
||||
for (dt != nil && dt.kind == tykind.TY_NAMED) { dt = dt.under; };
|
||||
if (dt != nil && dt.kind == tykind.TY_TAGGED) {
|
||||
// #22b (task #28): MEMORY-class tagged
|
||||
// element — the whole box copies through
|
||||
// the sret pointer mem-to-mem from the
|
||||
// element's local slot. cgexpr can't
|
||||
// source it: the tagged ident load is
|
||||
// word0-only (every tagged consumer
|
||||
// reads memory) and the AX/DX/CX/R8 box
|
||||
// cursor would collide with the DX
|
||||
// dest-base reload. Ident-only,
|
||||
// mirroring tuplitpushelem; widening /
|
||||
// non-ident sources stay loud (#23/#40
|
||||
// follow-ups). Mirror of cstage cgen.c
|
||||
// N_RETURN over-cap tagged arm.
|
||||
let eslot: i32 = tupeslotn(pt.lhs);
|
||||
let eu: *tinfo = we.type_: *tinfo;
|
||||
for (eu != nil && eu.kind == tykind.TY_NAMED) { eu = eu.under; };
|
||||
let eoff: i32 = 0;
|
||||
if (we.kind == nkind.N_IDENT && eu != nil) {
|
||||
if (eu.kind == tykind.TY_TAGGED && tupeslotn(we) == eslot) {
|
||||
eoff = localfind(c, we.str);
|
||||
};
|
||||
};
|
||||
if (eoff == 0) {
|
||||
let m22b: str = "#22b: tagged element in an over-cap (sret) tuple return from a non-ident or widening source unwired (ident locals only; rule 7; call-source is task #41, widening #23/#40)\n";
|
||||
os.write(2, m22b.ptr, m22b.len: u64);
|
||||
os.exit(1);
|
||||
};
|
||||
emitline("\tMOVQ\t");
|
||||
emitoff(saoff: i64);
|
||||
emitline("(BP), DX\n");
|
||||
let bk: i32 = 0;
|
||||
for (bk < eslot) {
|
||||
emitline("\tMOVQ\t");
|
||||
emitoff((eoff + bk): i64);
|
||||
emitline("(BP), AX\n");
|
||||
emitline("\tMOVQ\tAX, ");
|
||||
emitdispreg((foff + bk): i64, "DX");
|
||||
emitline("\n");
|
||||
bk += 8;
|
||||
};
|
||||
foff += eslot;
|
||||
we = we.next;
|
||||
if (pt != nil) { pt = pt.next; };
|
||||
continue;
|
||||
};
|
||||
let isflt: bool = isfloattype(c, we);
|
||||
let wide: bool = nodeisstr(c, we) || nodeisslice(c, we);
|
||||
let esz: i32 = 8;
|
||||
@@ -31646,12 +31706,17 @@ fn cgreturn(c: *cgen, n: *node) void = {
|
||||
emitline("\n");
|
||||
};
|
||||
};
|
||||
// C-t0: the sret buffer is slot-laid like
|
||||
// C-t0/#22: the sret buffer is slot-laid like
|
||||
// every tuple home (checker size, t.N
|
||||
// reader, mlet receive agree); esz keeps
|
||||
// the store WIDTH natural. Mirrors cstage
|
||||
// cgen.c N_RETURN over-cap arm.
|
||||
if (wide) { foff += esz; } else { foff += 8; };
|
||||
// reader, mlet receive agree) — the stride
|
||||
// is THE accessor's (a declared void
|
||||
// element's 0-slot included; the old
|
||||
// wide?esz:8 advanced 8 where every receive
|
||||
// walks 0). esz keeps the store WIDTH
|
||||
// natural. Mirrors cstage cgen.c N_RETURN
|
||||
// over-cap arm.
|
||||
if (pt != nil) { foff += tupeslotn(pt.lhs); }
|
||||
else { foff += tupeslotn(we); };
|
||||
we = we.next;
|
||||
if (pt != nil) { pt = pt.next; };
|
||||
};
|
||||
@@ -31664,6 +31729,16 @@ fn cgreturn(c: *cgen, n: *node) void = {
|
||||
c.lastwasreturn = 1;
|
||||
return;
|
||||
};
|
||||
// rule-7 net: register-classified by the declared type
|
||||
// but the expr-shape count overflows the cursor — the
|
||||
// pops below would index past tupreg. Unreachable while
|
||||
// expr counts never exceed declared counts; loud, not
|
||||
// OOB, if a future shape breaks that. Mirrors cstage.
|
||||
if (gptotal > TUPLE_GPCAP || ssecount > ssecap) {
|
||||
let mskew: str = "register-classified tuple return exceeds the cursor (classify/emit skew; rule 7, #22b)\n";
|
||||
os.write(2, mskew.ptr, mskew.len: u64);
|
||||
os.exit(1);
|
||||
};
|
||||
let fscr: i32 = 0;
|
||||
if (ssecount > 0) {
|
||||
fscr = localadd(c, "@tupfscr", ssecap * 8, nil);
|
||||
@@ -33140,6 +33215,24 @@ fn cglet(c: *cgen, n: *node) void = {
|
||||
c.lastwasreturn = 0;
|
||||
return;
|
||||
};
|
||||
// #22a (rule 7, ken R1) wwstage half: an OVER-CAP tuple
|
||||
// init whose rhs is not a CALL has no store path — only
|
||||
// the CALL shape rides the sret receive below; every
|
||||
// other rhs fell past ALL the store arms to NOTHING
|
||||
// (silent uninitialized-frame reads). cgexpr's cursor
|
||||
// materialisers loud most shapes, but their EXPR-shape
|
||||
// counts let a declared-tagged element's unwidened
|
||||
// payload (or a void literal) slip through in-cap
|
||||
// (probe /tmp/i22b/p7) — the let-twin of the #22b
|
||||
// classify/emit skew. Mirrors cstage cgen.c N_LET net.
|
||||
if (ttup.kind == nkind.N_TTUPLE
|
||||
&& rhs.kind != nkind.N_CALL
|
||||
&& sretretsize(c, ttup) > 0) {
|
||||
cgexpr(c, rhs);
|
||||
let mnet: str = "over-cap tuple initialiser from a non-call source unwired (see #10/#22b)\n";
|
||||
os.write(2, mnet.ptr, mnet.len: u64);
|
||||
os.exit(1);
|
||||
};
|
||||
};
|
||||
// Array literal init: `let xs: [N]T = [a, b, c];` (or [_]T).
|
||||
// Walk elements in declaration order, store each at off + i*esz
|
||||
@@ -33932,7 +34025,14 @@ fn cgmassign(c: *cgen, n: *node) void = {
|
||||
let tn: *node = nil;
|
||||
if (pt2 != nil) { tn = pt2.lhs; };
|
||||
let isflt: bool = isfloattype(c, tn);
|
||||
let wide: bool = isstrtype(c, tn) || isslicetype(c, tn);
|
||||
// #22b: the >8B copy-out keys on the ACCESSOR's slot
|
||||
// (str/slice header AND tagged box), not a str/slice
|
||||
// kind test — the tagged element took the scalar arm
|
||||
// (8B silent truncation; unreachable while the SEND
|
||||
// louded, live once #22b unwires it). Byte-id for
|
||||
// str/slice (esz == eslot == 24). Mirrors the cstage
|
||||
// N_MASSIGN sret arm + the R-1 all-three-routings lesson.
|
||||
let eslot: i32 = tupeslotn(tn);
|
||||
let esz: i32 = 8;
|
||||
if (pt2 != nil) {
|
||||
let eti: *tinfo = pt2.lhs.type_: *tinfo;
|
||||
@@ -33951,9 +34051,9 @@ fn cgmassign(c: *cgen, n: *node) void = {
|
||||
emitline("\tX0, ");
|
||||
emitoff(off: i64); emitline("(BP)\n");
|
||||
} else {
|
||||
if (wide) {
|
||||
if (eslot > 8) {
|
||||
let k: i32 = 0;
|
||||
for (k < esz) {
|
||||
for (k < eslot) {
|
||||
emitline("\tMOVQ\t");
|
||||
emitoff((scr + foff + k): i64);
|
||||
emitline("(BP), AX\n");
|
||||
|
||||
Reference in New Issue
Block a user