w6c+wwstage: construct + bind tuple-in-union payload (#242)
A mixed-scalar tuple WRAPPED IN A TAGGED UNION (the (neg, n) shape Hare's
strconv parseint returns, ((bool,u64)|invalid|overflow)) miscompiled three
ways, all gate-blind (no bootstrap tuple-in-union):
(a) cstage CONSTRUCTION: a tuple variant fell through the N_RETURN scalar
shuffle, which ZEROED tag + payload — the operands were never packed.
Route the tuple variant through the scratch-slot widen path; add a
TY_TUPLE arm to cg_widen_tagged_store that packs each element into the
union payload at the register-ABI 8B stride + sets the variant tag.
(b) wwstage CHECKER: `let (a,b)=t` over a plain tuple ident (the match-
bound union payload) left the un-annotated binders UNTYPED, so the bin
node reading them was untyped -> asserttyped abort. The element-type
distribution only fired for an N_CALL rhs. Consume the rhs tuple type
for ANY rhs (mirror cstage check.c:2017).
(c) BOTH stages DESTRUCTURE: the register-cursor receive assumes the rhs
left every element in AX/DX/CX (a call's tuple-return ABI). For a tuple
IDENT cgexpr loads only word0->AX, so the 2nd binder read a STALE DX.
Copy each element from the ident's slot at the 8B stride.
Construction is correct at ANY variant position (the resolved tag, not a
default 0); wwstage resolves it via the typeeq core (flatvariantidxt), not
taggedvariantindext whose str/slice shape-fallback would mask a mismatch.
Two rule-7 loud-stops cover shapes this slotted packing can't yet handle,
on BOTH stages, so neither silently miscompiles:
- a tuple with a SysV-eightbyte-sharing narrow pair (e.g. (i32,i32,u64)),
caught by the 8+payload > slot-size guard (the eightbyte tuple
classification is #243);
- a tuple built from a BARE LITERAL element (`true`/`false`, suffix-less
`7`). cstage's cg_tag_for_variant can't type the literal (#241), returns
-1, and loud-stops. wwstage types `true` as bool and `7` as untyped_int,
so flatvariantidxt WOULD resolve the variant — a program cstage rejects
but wwstage accepts is the cs!=ww divergence rule 10 forbids. wwstage
mirrors cstage's CONDITION (a bare-literal element), not its -1
mechanism, with an explicit guard that aligns the richer side DOWN. Lift
BOTH guards together when #241 lands cstage literal typing -> symmetric
accept.
Test 940_tuple_in_union: 4 K_RUN rows (variant 0, void arm, tuple at
variant 1 two ways) x cstage-run + wwstage-run + cs==ww byte-id, plus 2
K_BUILDERR rows (eightbyte-share, bare-literal) asserting a loud stop with
the #242 diagnostic on BOTH drivers = 16 ok.
This commit is contained in:
@@ -471,14 +471,19 @@ fn resolvewalk(c: *checker, n: *node) void = {
|
||||
if (k == nkind.N_MLET) {
|
||||
if (n.rhs != nil) { resolvewalk(c, n.rhs); };
|
||||
let pt: *node = nil;
|
||||
if (n.rhs != nil) { if (n.rhs.kind == nkind.N_CALL) {
|
||||
// #242: consume the rhs's tuple type for ANY rhs, not just an
|
||||
// N_CALL — `let (a,b) = t` over a plain tuple ident (e.g. a
|
||||
// match-bound union payload) must stamp its bindings too, or
|
||||
// the un-annotated binder stays untyped and asserttyped aborts.
|
||||
// Mirrors cstage check.c:2017 (cexpr(rhs), unconditional).
|
||||
if (n.rhs != nil) {
|
||||
// `rt` would shadow the imported lib/rt module
|
||||
// (checkmoduleshadow errors); `rty` avoids it.
|
||||
let rty: *node = exprtype(c, n.rhs, nil);
|
||||
if (rty != nil) { if (rty.kind == nkind.N_TTUPLE) {
|
||||
pt = rty.list;
|
||||
}; };
|
||||
}; };
|
||||
};
|
||||
stamptuplebinds(c, n.list, pt, true, "let");
|
||||
return;
|
||||
};
|
||||
@@ -493,12 +498,13 @@ fn resolvewalk(c: *checker, n: *node) void = {
|
||||
if (k == nkind.N_MASSIGN) {
|
||||
if (n.rhs != nil) { resolvewalk(c, n.rhs); };
|
||||
let pt: *node = nil;
|
||||
if (n.rhs != nil) { if (n.rhs.kind == nkind.N_CALL) {
|
||||
// #242: consume the rhs tuple type for ANY rhs (see N_MLET).
|
||||
if (n.rhs != nil) {
|
||||
let rty: *node = exprtype(c, n.rhs, nil);
|
||||
if (rty != nil) { if (rty.kind == nkind.N_TTUPLE) {
|
||||
pt = rty.list;
|
||||
}; };
|
||||
}; };
|
||||
};
|
||||
let l: *node = n.list;
|
||||
for (l != nil) { resolvewalk(c, l); l = l.next; };
|
||||
stamptuplebinds(c, n.list, pt, false, "");
|
||||
|
||||
Reference in New Issue
Block a user