wcc/cgen: #87 plain tagged-union module-global DATA + match SB-resolution (both-stage)
A PLAIN (non-alias) module-level tagged-union global SEGV'd on BOTH
stages: no static DATA was emitted (let_emit_size/letemitsize returned 0
for TY_TAGGED) so the global was never registered, and the match
scrutinee resolved it as a frame-local at offset 0 — reading saved BP as
the tag. Two sub-sites, one route (neither half ships alone — DATA
without SB-resolution still SEGVs; SB-resolution without DATA reads
nothing):
(a) DATA-emitter — a non-nullable TY_TAGGED arm emits the box that
byte-MIRRORS a runtime LOCAL of the same type: tag word at +0 (the
const-selected variant index via cg_tag_for_variant / taggedvariant-
index), payload at +8, zero-padded to the union box size. int and
str/slice literal variants are wired (str carries a DATAR ptr patch
at +8); any other variant payload loud-stops (rule 7). emit_tagged_
data + emittaggeddata are the per-stage twins; let_pre_intern/
letpreintern gain the matching str-variant intern. Nullable stays 0
so the (*T|void) one-word fold keeps the 8B scalar arm.
(b) match-scrutinee global resolution — the PLAIN-tagged twin of #78:
a global tagged ident scrutinee LEAQs name(SB) and copies the box
into an @match_spill slot the dispatch indexes off BP.
DATA target (mirror of the local box, verified byte-for-byte): for
(i32|str)=42 the 32B box is tag0 | 42@8 | zero-pad; for ="x" it is
tag1 | ptr0@8(DATAR _S_n) | len@16 | cap@24. cs and ww emit byte-
identical asm.
Pins (rob §3, dual-stage 910 cstage + 997 wwstage, attest_pass.ww): the
tagged global-vs-local byte-identity pin (match over the GLOBAL gives the
same arm/value as over a LOCAL — was SEGV both stages) and the str-
variant tag-1 pin, plus the #86 tuple global-vs-local lock-pin guarding
the already-correct emitter path.
929 fail_global_src graduates: a >48B tagged GLOBAL by-value arg now
resolves through the cgplaceaddr MEMORY-class arm (LEAQ g(SB) + blit)
instead of the #38b loud-stop, and runs correctly (uninit zero box ->
first variant); the row becomes a positive run pin. The struct-variant
>48B init still loud-stops via the data emitter.
The first-class-VALUE copy of a tagged ident (`let q = g`) stays a
pre-existing silent #49/#46 sibling (local and global identically),
filed separately — out of this fold's two sub-sites.
This commit is contained in:
@@ -6,6 +6,17 @@ import rt; // #3/B': check_empty_alloc_annotated calls alloc → rt_malloc.
|
||||
|
||||
type point = struct { x: i32, y: i32 };
|
||||
|
||||
// #87: a PLAIN (non-alias) module-level tagged-union global SEGV'd BOTH
|
||||
// stages — no static DATA emitted (read as a frame-local at BP) + the
|
||||
// match scrutinee read saved BP as the tag. Fix: emit the 32B box that
|
||||
// byte-MIRRORS a runtime LOCAL (tag@0 | payload@8 | zero-pad) + resolve
|
||||
// the match scrutinee via LEAQ name(SB). These globals back the rob §3
|
||||
// global-vs-local byte-identity PIN below; the tuple global locks the
|
||||
// already-correct #86 path against any emitter regression.
|
||||
let g87_int: (i32 | str) = 42;
|
||||
let g87_str: (i32 | str) = "x";
|
||||
let g86_tup: (u32, u32) = (1u32, 2u32);
|
||||
|
||||
@test fn check_add() void = {
|
||||
let a: i32 = 2;
|
||||
let b: i32 = 3;
|
||||
@@ -127,3 +138,41 @@ type point = struct { x: i32, y: i32 };
|
||||
let _: i32 = 1 / 0;
|
||||
};
|
||||
};
|
||||
|
||||
// #87 PIN (rob §3, tagged kind): a module-GLOBAL tagged scrutinee must
|
||||
// match to the SAME arm/value as a LOCAL of the same type — both stages.
|
||||
// Pre-fix the global match SEGV'd (saved-BP-as-tag) on cs AND ww.
|
||||
@test fn check_tagged_global_int() void = {
|
||||
let l: (i32 | str) = 42; // the known-correct runtime box
|
||||
let gv: i32 = match (g87_int) {
|
||||
case let n: i32 => yield n;
|
||||
case let s: str => yield 0;
|
||||
};
|
||||
let lv: i32 = match (l) {
|
||||
case let n: i32 => yield n;
|
||||
case let s: str => yield 0;
|
||||
};
|
||||
if (gv != 42) { let _: i32 = 1 / 0; };
|
||||
if (gv != lv) { let _: i32 = 1 / 0; }; // global == local
|
||||
};
|
||||
|
||||
// #87 PIN: the str variant (tag 1) exercises the DATAR ptr patch + the
|
||||
// 24B {ptr,len,cap} payload at +8.
|
||||
@test fn check_tagged_global_str() void = {
|
||||
let n: i32 = match (g87_str) {
|
||||
case let v: i32 => yield v;
|
||||
case let s: str => yield s.len: i32;
|
||||
};
|
||||
if (n != 1) { let _: i32 = 1 / 0; }; // "x".len, via tag-1 arm
|
||||
};
|
||||
|
||||
// #86 LOCK PIN (tuple kind): the already-correct tuple-global emitter
|
||||
// must keep byte-mirroring a local — guards the working path against any
|
||||
// regression from the #87 tagged arm sharing emitletdataw.
|
||||
@test fn check_tuple_global_lock() void = {
|
||||
let l: (u32, u32) = (1u32, 2u32);
|
||||
if (g86_tup.0 != 1) { let _: i32 = 1 / 0; };
|
||||
if (g86_tup.1 != 2) { let _: i32 = 1 / 0; };
|
||||
if (g86_tup.0 != l.0) { let _: i32 = 1 / 0; };
|
||||
if (g86_tup.1 != l.1) { let _: i32 = 1 / 0; };
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user