selfhost/cmd/wcc: type-key tagged variant match (#66, Phase-N step 3)
The user-ruled B-full semantic change: flip tagged-union variant matching from surface-NAME to TYPE-identity (typeeq over tinfo.params), mirroring cstage cg_variant_match (cmd/w6c/cgen.c:451). A cross-module `a.T` != `b.T` and `type linerr=!str` != str are now distinguished by the per-decl TY_NAMED pointer (Phase-N #64). ww has no type_assignable, so the untyped/loose arm keeps the str/slice shape fallback (rule-10 align-down). The 5 helpers (flatvariantidx, flatslicevariantidx, taggedvariantindex, cgtagvariantidx, cgmatch dispatch) flip; nomem propagation (NAMED-name scan, no source value) and the f64 widen arm (float-kind classification, no pattern node) are not arm-by-value discrimination and stay name/kind-keyed. The flip requires value nodes to carry nominal identity. exprtype's N_STRUCTLIT arm stamped the flattened body, so `overflow{}` (overflow=!void) got TY_VOID and missed its variant -- fixed to stamp the per-decl NAMED (mktname(lhs.str) -> tinfofornode reuses the #64 NAMED build/cache, same ptr the union variant resolved to), mirroring the N_CAST/N_IDENT arms + cstage. Returns the body node unchanged (only e.type_ rides NAMED); struct-lit layout is unaffected -- cgstructlitfill is structlookup(name)-keyed, never reads NAMED.fields. The fix now hits all `T{}` stamps, kept byte-id by the #63/#65 structural-walker peels. 931_variant_typekey_run: table-driven, both stages, /tmp-isolated. Two rows widen an alias-FIRST variant from a call (no surface name): `(linerr|str)` str-via-call -> idx 1, `(ec|i32)` i32-via-call -> idx 1. Empirically discriminating: FAILS pre-flip (wwstage falls to the leading-shape variant, exit 10; cstage exit 0) and PASSES post-flip -- locking in the capability byte-id can't reach (the corpus has no name-key/type-key-disagreeing co-variant, which is why name-keying survived). make test 134/134 (byte-id 990-997 green; 995 self-rebuild green).
This commit is contained in:
@@ -2128,7 +2128,26 @@ fn exprtype(c: *checker, e: *node, hint: *node) *node = {
|
||||
if (ms != nil) { if (ms.skind == skind.SK_TYPE) { if (ms.decl != nil) {
|
||||
let tn: *node = ms.decl.lhs;
|
||||
if (tn != nil) {
|
||||
e.type_ = tinfofornode(c, tn): *void;
|
||||
// #66 Phase-N step 3: stamp e.type_ to the NOMINAL
|
||||
// per-decl NAMED, not the flattened body. `overflow{}`
|
||||
// where `type overflow = !void` must carry
|
||||
// NAMED(overflow) so the typeeq variant match
|
||||
// (cgenutil flatvariantidx) selects the overflow arm
|
||||
// instead of falling to the scalar shape fallback;
|
||||
// stamping tinfofornode(tn) gave the body (TY_VOID)
|
||||
// and lost nominal identity. Resolve through a
|
||||
// synthesized TNAME to reuse tinfofornode's TY_NAMED
|
||||
// build/cache (check.ww:1157) — the SAME NAMED ptr
|
||||
// the union variant resolved to. Mirrors cstage
|
||||
// resolving overflow{} to the overflow Type, and ww's
|
||||
// own N_CAST / N_IDENT arms which already stamp NAMED.
|
||||
// Return the body node tn unchanged: byte-id rides
|
||||
// e.type_ (cgen), while the checker's AST-level
|
||||
// assign/return checks keep their prior input.
|
||||
let tnm: *node = mktname(c, e.lhs.str);
|
||||
let nti: *tinfo = tinfofornode(c, tnm);
|
||||
if (nti != nil) { e.type_ = nti: *void; }
|
||||
else { e.type_ = tinfofornode(c, tn): *void; };
|
||||
return tn;
|
||||
};
|
||||
}; }; };
|
||||
|
||||
Reference in New Issue
Block a user