cgen: #49 aggregate-ASSIGN word0-only family — one mem-to-mem funnel (cg_aggcopy), both stages

Whole-aggregate reassignment `b = a` fell to the N_ASSIGN scalar tail
and copied ONE MOVQ — word 0 of any struct/array/tuple — in BOTH
stages, byte-identical, gate-blind (ken f49_min asm proof; latent
because lib style is let-init, whose #265/#268 copy is full-width).
Same class at three more positions: struct-lit FIELD init from an
ident source (`outer{.., r = r}`, the #38 non-tagged half), the deref
place `*p = s` (#31-A), and the module-let global `g = a` / `g = pt{..}`.

Fix: extract the C1.25 assign-resolver word-copy tail verbatim into
cg_aggcopy/aggcopy — the ONE place-resolved (SI)->(BX) aggregate copy
— and wire it at the N_ASSIGN ident-aggregate arm (local + global),
the deref-place divert into the existing resolver aggregate arm, and
the structlit-fill aggregate-field arm, all fed by aggarg_srcaddr
(the closed #265/#268 dispatch). The new arms key on the FULL alias
chase (type_chase_named / chased stamped tinfo, the #22 precedent) in
BOTH stages — the region's single-peel `lu`/`fu` would miss
`type b = a; type a = struct` on cstage while the wwstage twin fired
(ken R1, gA3b: master cs ran the word0 corruption, exit 2; now 0).
Non-addressable aggregate rhs (tuple-lit, unhandled call shapes) dies
LOUD (rule 7) instead of silently truncating: #31-E `*p = (3,4)` and
#31-G's deref flavor `*p = mk()` are now loud both stages (the INDEX
flavor `a[i] = mk()` stays in the legacy INDEX arm — receive
machinery, not this funnel; still filed under #31). #31-B rides: the
cstage-only <=24B gate before cg_structlit_fill_bp is lifted (the
wwstage twin never gated — a >24B literal reassign was
cs-zero/ww-filled, rule-10 break). Global structlit reassign rides
the existing DST_GLOBAL fill machinery.

Unsplit (rule 11): the assign arm, fill arm and deref divert all
route through the one new funnel (cg_aggcopy + aggarg_srcaddr) in
both stages; splitting by site or by stage would ship a transient
cs!=ww (gate-red) or a funnel with no consumer.

941 t2_reject_chain_arg: the row's tuple-LITERAL field fill now louds
at the #49 fill arm before reaching the pinned ARG-site reject; the
fill switches to an ident source (newly working via the fill arm) so
the original arg-site pin still fires.

test/wcc/812_agg_assign_width.c: 17 runtime-readback rows (the only
oracle for a gate-blind class) + per-row asm byte-id; every row fails
at 7545bf7 (ken matrix f49_min/f49b/f49c/fA_16b/f38b + gA3b/gA6 +
impl-A probes; reviewer-A re-probed 5 rows + the gA2 12B shape at a
master git-archive scratch). Alias rows use FIELD-WISE init: the
struct-LIT spelling louds earlier at the pre-existing task-#7
aggregate-let bound on wwstage (the #5 alias-arc's hole, not this
funnel's). Reviewer-A amendment (test-only, K5 self-certify): add
the ken-gA2 odd-size row (12B {u32,u32,u32}, maxalign 4 — pins the
MOVL tail; master both stages exit 3) and gA4's neighbor guards on
the deref row, completing ken's validated matrix in the committed
suite.
This commit is contained in:
2026-06-05 05:51:02 +09:00
parent 7545bf7dcd
commit 4c46d3afde
8 changed files with 1425 additions and 194 deletions

View File

@@ -2568,6 +2568,20 @@ fn istaggedtype(c: *cgen, t: *node) bool = {
return typeistagged(t.type_: *tinfo);
};
// tnodeisagg — struct/array/tuple kind off the checker-STAMPED tinfo
// (the #49 funnel predicate; #209/#211 discipline — never tnode
// names). Mirror of cstage's chase-then-kind test at the fill /
// assign aggregate arms.
fn tnodeisagg(t: *node) bool = {
if (t == nil) { return false; };
let u: *tinfo = t.type_: *tinfo;
for (u != nil && u.kind == tykind.TY_NAMED) { u = u.under; };
if (u == nil) { return false; };
if (u.kind == tykind.TY_STRUCT) { return true; };
if (u.kind == tykind.TY_ARRAY) { return true; };
return u.kind == tykind.TY_TUPLE;
};
// isfloattype — f32 / f64 / untyped_float (alias-aware). Cite cstage
// cgen.c:117 `cg_isfloat`. Dispatches MOVSS/MOVSD-shaped paths across
// cglet, cgident, cgassign, cgbin, cgcast, cgcall, cgreturn, fn-
@@ -4496,6 +4510,59 @@ fn cgstructlitfill(c: *cgen, si: *structinfo, lit: *node,
};
};
fi = nil;
} else if (tnodeisagg(fi.tnode)) {
// #49 (f38b/x5f-h): an aggregate (struct/array/
// tuple) field from an ADDRESSABLE source expr —
// `outer{.., r = r}` — fell to the scalar tail
// below and stored word0 only. Funnel: source
// address via aggargsrcaddr (SI), field address
// via LEAQ/ADDQ (BX — loaded AFTER the source
// walk, which clobbers BX/AX), then aggcopy.
// Width = the checker-STAMPED tinfo size (the
// cstage fl->type->size SSoT; fi.fsz is the
// slot-padded extent and skews on maxalign<8).
// Non-addressable aggregate sources (tuple-lit,
// >24B/odd-tail call) die loud — pre-#49 the
// same silent word0 (rule 7). Mirror of cstage
// cg_structlit_fill #49 arm.
if (!aggargsrcaddr(c, fieldnode.lhs, "SI")) {
let m49g: str = "structlit fill: aggregate field '";
os.write(2, m49g.ptr, m49g.len: u64);
os.write(2, fname.ptr, fname.len: u64);
let m49h: str = "' from a non-addressable source unwired (task #49/rule-7)\n";
os.write(2, m49h.ptr, m49h.len: u64);
os.exit(1);
};
if (mode == 0) {
emitline("\tLEAQ\t");
emitoff((disp + fi.foff): i64);
emitline("(BP), BX\n");
} else {
if (mode == 1) {
emitline("\tMOVQ\t");
emitoff(srcoff: i64);
emitline("(BP), BX\n");
} else {
emitline("\tLEAQ\t");
emitsymname(c, srcname);
emitline("(SB), BX\n");
};
if (disp + fi.foff != 0) {
emitline("\tADDQ\t$");
emitint((disp + fi.foff): i64);
emitline(", BX\n");
};
};
let agsz49: i32 = 0;
if (fi.tnode != nil) {
let agti49: *tinfo = fi.tnode.type_: *tinfo;
for (agti49 != nil && agti49.kind == tykind.TY_NAMED) {
agti49 = agti49.under;
};
if (agti49 != nil) { agsz49 = agti49.size: i32; };
};
aggcopy(c, agsz49);
fi = nil;
} else {
cgexpr(c, fieldnode.lhs);
// For non-BP modes, cgexpr just clobbered