cgen: B5-c1 helper+funnel single peels fold into type_chase_named — 19 sites, cs-only
The exact F2b c1 set (rob next-arc spec + B5 re-rule): node_tuplearg:249, fld_issigned:409, castsrcprim:501/:531, struct_float_class:598, tagged_arg_size:640, tagged_memarg_size:661, type_isnullable:740, nullable_ptr_tag:750, cg_tagged_success_tag:860, cg_variant_is_error:876, cg_tag_for_variant:899, type_istagged:953, type_unwrap:1269 + the widen/ fill funnel entries cg_widen_tagged_store:2456/:2480/:2483, cg_widen_tagged_push:2905, cg_structlit_fill:3195. Raw `->under` in cgen.c 88→69. Riding per re-rule R1: peel-ok-#218 annotations at cg_variant_match/cg_variant_struct_match (citing ken's b5 oracle §4 — chasing those four peels graduates zero v2_struct rows; the real fix is a both-stage NAMED-source arm, task #95) and the :755 peel-ok annotation mirroring ww cgenutil.ww:2758 (probe-cleared,018ef66). :447 untouched (c2's grant). TRAIN INVARIANT: cs-only — zero selfhost/ or lib/ bytes move; w6c_ww/ ww_ww/w6a_ww/w6l_ww bit-identical to thebcd948dbaselines (md5 28ad889042bad8006f1997cbcec94805 / 4e9ca8741f19e1f68219ff799a5e5a14). cs movers bounded to exactly: kb5_targ, kb5_tmem, kb5_wpush, kb5_null, kb5_f32p, kb5_fill2, kb5_tuparg_c; five selfhost mains + the rest of the kb2/kb3/kb4/kb5/kna corpus byte-NEUTRAL both stages. LIVE graduations: kb5_targ (tagged_arg_size sized a 2-level alias union param 0 → wrong arg path, cs silent exit 1) and kb5_tmem (>48B memarg twin) → 0/0 byte-id. Divergence flips to byte-id: wpush/null/f32p. #85 CLOSES as SITE-CLOSURE with ZERO live graduations: type_unwrap's two consumers (:14716/:14907, both tuple-global layout walks that want the chased view) are checker-DEAD on cs for alias tuples (#86 upstream) — correctness there is by-construction, pinned by tupglobal_bound86. DESIGNED DIVERGENCE (re-rule R4, task #100): the :3195 chase flips kb5_fill2 from both-wrong-IDENTICAL-silent (gate-blind, both stages accepted and ran wrong byte-identically) to cs-LOUD / ww-silent-wrong. A loud, disclosed, pinned divergence over a silent miscompile; rejected programs emit no asm so the byte-id gates hold. Dual-cell pin (fill2_bound100): cs experr + ww run-exit-1 both asserted; fill0 both-loud control holds. #100 (the ww twin gate) fires immediately after B5 so the window is one train wide. Oracle corrections at the c1 boundary (ken c1-BOUNDARY ADDENDUM, verified on his independent scratch build; rob ack'd, scope unchanged): C1-CORR-1: kb5_succ does NOT flip here — its residual divergence is exactly three paired return-position tag syntheses, the cgreturn return-route family (:12278/:12318/:12322). Joins c3's graduation set; pinned succ_bound_c3 K_RUN_NOID until then. C1-CORR-2 (corrects re-rule R2): kb5_wstore_a does NOT flip — the ident-lhs N_ASSIGN tagged store gates in the cgexpr INLINE set (B6), never reaching the :2456 funnel; cs byte-neutral here. Pinned wstore_a_bound_b6 K_RUN_NOID; byte-id rides B6. C1-CORR-3 (corrects re-rule R3 + ken FLAG-2): the :249 chase is NOT purely latent — the CAST spelling (kb5_tuparg_c) earned a LIVE cs graduation (cs ok/1 → ok/0, correct tuple-arg classify); ww still runs wrong (task #99). Two-key pin tuparg_cast_bound99: cs-0 earned + ww-1 pinned observed-wrong; byte-id re-pins to full 0/0 when #99's ww fix lands. New 944_alias_cgen_b5_run row table (16 rows, 40 checks): controls signed/wstore/wstore1 byte-NEUTRAL as predicted (kind-keyed tests are the only behavior-visible peels — type.c classifiers already recurse); literal tuparg spellings stay dual-cell bounds (#99/#86). All 944-family suites green; sizelint 0.
This commit is contained in:
@@ -246,7 +246,7 @@ node_tuplearg(Node *n)
|
||||
&& n->kind != N_TRYUNW && n->kind != N_TRYPROP)
|
||||
return NULL;
|
||||
Type *t = n->type;
|
||||
Type *u = (t && t->kind == TY_NAMED) ? t->under : t;
|
||||
Type *u = type_chase_named(t);
|
||||
return (u && u->kind == TY_TUPLE) ? u : NULL;
|
||||
}
|
||||
|
||||
@@ -406,7 +406,7 @@ cg_sret_retsize(Type *rt)
|
||||
static int
|
||||
fld_issigned(Type *t)
|
||||
{
|
||||
Type *u = (t && t->kind == TY_NAMED) ? t->under : t;
|
||||
Type *u = type_chase_named(t);
|
||||
if (u == NULL) return 0;
|
||||
if (u->kind == TY_BOOL) return 0;
|
||||
if (type_isunsigned(u)) return 0;
|
||||
@@ -497,8 +497,7 @@ castsrcprim(Node *n, int *sz, int *unsignd)
|
||||
* TY_UNTYPED_INT — we conservatively skip those (wwstage
|
||||
* matches: no tsuffix → sz=0). */
|
||||
if (n->tsuffix && n->type) {
|
||||
Type *u = (n->type->kind == TY_NAMED)
|
||||
? n->type->under : n->type;
|
||||
Type *u = type_chase_named(n->type);
|
||||
if (u && u->kind != TY_UNTYPED_INT
|
||||
&& u->kind != TY_UNTYPED_RUNE
|
||||
&& type_isint(u)) {
|
||||
@@ -528,7 +527,7 @@ castsrcprim(Node *n, int *sz, int *unsignd)
|
||||
default:
|
||||
break;
|
||||
}
|
||||
Type *u = (t && t->kind == TY_NAMED) ? t->under : t;
|
||||
Type *u = type_chase_named(t);
|
||||
if (u && type_isint(u)) {
|
||||
*sz = (int)u->size;
|
||||
*unsignd = type_isunsigned(u);
|
||||
@@ -594,8 +593,7 @@ struct_float_class(Type *t, int *cls)
|
||||
int nflt[2], nint[2];
|
||||
nflt[0] = nflt[1] = nint[0] = nint[1] = 0;
|
||||
for (Tfield *f = t->fields; f; f = f->next) {
|
||||
Type *fu = (f->type && f->type->kind == TY_NAMED)
|
||||
? f->type->under : f->type;
|
||||
Type *fu = type_chase_named(f->type);
|
||||
if (fu == NULL) return 0;
|
||||
int foff = (int)f->offset;
|
||||
int fsz = (int)fu->size;
|
||||
@@ -637,7 +635,7 @@ static int
|
||||
tagged_arg_size(Type *t)
|
||||
{
|
||||
if (t == NULL) return 0;
|
||||
if (t->kind == TY_NAMED) t = t->under;
|
||||
t = type_chase_named(t);
|
||||
if (t == NULL || t->kind != TY_TAGGED) return 0;
|
||||
/* Param/let/struct contexts have 6 int regs (DI..R9) so a 48B
|
||||
* tagged union (6 words) still fits in registers. Return values
|
||||
@@ -658,7 +656,7 @@ static int
|
||||
tagged_memarg_size(Type *t)
|
||||
{
|
||||
if (t == NULL) return 0;
|
||||
if (t->kind == TY_NAMED) t = t->under;
|
||||
t = type_chase_named(t);
|
||||
if (t == NULL || t->kind != TY_TAGGED || t->nullable) return 0;
|
||||
if (t->size <= 48) return 0;
|
||||
return (int)t->size;
|
||||
@@ -737,7 +735,7 @@ static int
|
||||
type_isnullable(Type *t)
|
||||
{
|
||||
if (t == NULL) return 0;
|
||||
if (t->kind == TY_NAMED) t = t->under;
|
||||
t = type_chase_named(t);
|
||||
return t && t->kind == TY_TAGGED && t->nullable;
|
||||
}
|
||||
|
||||
@@ -747,10 +745,14 @@ static int
|
||||
nullable_ptr_tag(Type *t)
|
||||
{
|
||||
if (t == NULL) return 0;
|
||||
if (t->kind == TY_NAMED) t = t->under;
|
||||
t = type_chase_named(t);
|
||||
if (t == NULL || t->kind != TY_TAGGED) return 0;
|
||||
int i = 0;
|
||||
for (Tparam *p = t->params; p; p = p->next, i++) {
|
||||
/* peel-ok: single peel PROBE-CLEARED (batch-2 c3-B2,
|
||||
* 018ef66) — constructible variant params never carry
|
||||
* 2+-level NAMED at this scan; ww twin cgenutil.ww:2758
|
||||
* carries the identical annotated peel. */
|
||||
Type *pu = (p->type && p->type->kind == TY_NAMED)
|
||||
? p->type->under : p->type;
|
||||
if (pu && pu->kind == TY_PTR) return i;
|
||||
@@ -825,7 +827,15 @@ cg_variant_match(Type *vt, Type *src)
|
||||
* unions so the outer widen tag (cg_tag_for_variant) computes.
|
||||
* Sound only while the model is nominal-lossy; the collision
|
||||
* guard at the widen site (cg_widen_tagged_store) enforces the
|
||||
* invariant for when #199b/B-full lands true nominal layout. */
|
||||
* invariant for when #199b/B-full lands true nominal layout.
|
||||
* peel-ok (#218, B5-c1): these single peels serve ONLY the
|
||||
* both-TAGGED structural fallback — a NAMED struct source vs
|
||||
* a NAMED variant falls through every arm at ANY depth
|
||||
* (.ai/ken-b5-oracle.md §4: kb5_v2s1i both-wrong-identical
|
||||
* at depth ONE, gate-blind; kb5_v2sE2 pointer-id exact-match
|
||||
* works). Chasing here graduates zero rows; the real fix is
|
||||
* a NEW NAMED-source structural arm under the >=2-candidate
|
||||
* guard, BOTH stages — task #95. */
|
||||
Type *vu = (vt->kind == TY_NAMED) ? vt->under : vt;
|
||||
Type *su = (src->kind == TY_NAMED) ? src->under : src;
|
||||
if (vu && su && vu->kind == TY_TAGGED && su->kind == TY_TAGGED)
|
||||
@@ -844,6 +854,9 @@ cg_variant_match(Type *vt, Type *src)
|
||||
static int
|
||||
cg_variant_struct_match(Type *vt, Type *src)
|
||||
{
|
||||
/* peel-ok (#218, B5-c1): shape-only collision count for the
|
||||
* both-TAGGED fallback above — same probe record, task #95
|
||||
* (.ai/ken-b5-oracle.md §4). */
|
||||
Type *vu = (vt && vt->kind == TY_NAMED) ? vt->under : vt;
|
||||
Type *su = (src && src->kind == TY_NAMED) ? src->under : src;
|
||||
if (vu == NULL || su == NULL) return 0;
|
||||
@@ -857,7 +870,7 @@ static int
|
||||
cg_tagged_success_tag(Type *t)
|
||||
{
|
||||
if (t == NULL) return 0;
|
||||
if (t->kind == TY_NAMED) t = t->under;
|
||||
t = type_chase_named(t);
|
||||
if (t == NULL || t->kind != TY_TAGGED) return 0;
|
||||
int has_err = 0;
|
||||
for (Tparam *p = t->params; p; p = p->next)
|
||||
@@ -873,7 +886,7 @@ static int
|
||||
cg_variant_is_error(Type *t, int idx)
|
||||
{
|
||||
if (t == NULL) return 0;
|
||||
if (t->kind == TY_NAMED) t = t->under;
|
||||
t = type_chase_named(t);
|
||||
if (t == NULL || t->kind != TY_TAGGED) return 0;
|
||||
int has_err = 0;
|
||||
for (Tparam *p = t->params; p; p = p->next)
|
||||
@@ -896,7 +909,7 @@ static int
|
||||
cg_tag_for_variant(Type *t, Type *vt)
|
||||
{
|
||||
if (t == NULL || vt == NULL) return -1;
|
||||
if (t->kind == TY_NAMED) t = t->under;
|
||||
t = type_chase_named(t);
|
||||
if (t == NULL || t->kind != TY_TAGGED) return -1;
|
||||
/* Pass 1: exact match (NAMED-vs-NAMED pointer-id, tagged-vs-tagged,
|
||||
* bare type_eq). Exact matches take precedence and need no guard —
|
||||
@@ -950,7 +963,7 @@ static int
|
||||
type_istagged(Type *t)
|
||||
{
|
||||
if (t == NULL) return 0;
|
||||
if (t->kind == TY_NAMED) t = t->under;
|
||||
t = type_chase_named(t);
|
||||
return t && t->kind == TY_TAGGED;
|
||||
}
|
||||
|
||||
@@ -1266,7 +1279,7 @@ static Type *
|
||||
type_unwrap(Type *t)
|
||||
{
|
||||
if (t == NULL) return NULL;
|
||||
return (t->kind == TY_NAMED) ? t->under : t;
|
||||
return type_chase_named(t);
|
||||
}
|
||||
|
||||
/* Element-effective type for indexing. For `*[N]T` we drill through
|
||||
@@ -2453,7 +2466,7 @@ cg_widen_tagged_store(Cg *c, Local **locals_p, Type *dst, Node *src,
|
||||
ins2(c, A_MOVQ, areg(D_AX),
|
||||
amem(D_BP, write_off + k));
|
||||
}
|
||||
Type *du = (dst && dst->kind == TY_NAMED) ? dst->under : dst;
|
||||
Type *du = type_chase_named(dst);
|
||||
if (du == NULL || du->kind != TY_TAGGED) return;
|
||||
if (du->nullable) {
|
||||
cgexpr(c, src, *locals_p);
|
||||
@@ -2476,11 +2489,9 @@ cg_widen_tagged_store(Cg *c, Local **locals_p, Type *dst, Node *src,
|
||||
* lookup and fall through to the matching branch. */
|
||||
if (src && src->kind == N_CAST && src->lhs) {
|
||||
Type *castt = src->type;
|
||||
Type *castu = (castt && castt->kind == TY_NAMED)
|
||||
? castt->under : castt;
|
||||
Type *castu = type_chase_named(castt);
|
||||
Type *innert = src->lhs->type;
|
||||
Type *innu = (innert && innert->kind == TY_NAMED)
|
||||
? innert->under : innert;
|
||||
Type *innu = type_chase_named(innert);
|
||||
int cast_is_widen = (castu == du) ||
|
||||
(castu && castu->kind == TY_TAGGED && type_eq(castt, dst));
|
||||
int inner_is_tagged = innu && innu->kind == TY_TAGGED;
|
||||
@@ -2902,7 +2913,7 @@ copy_out:
|
||||
static void
|
||||
cg_widen_tagged_push(Cg *c, Local **locals_p, Type *dst, Node *src, int sz)
|
||||
{
|
||||
Type *du = (dst && dst->kind == TY_NAMED) ? dst->under : dst;
|
||||
Type *du = type_chase_named(dst);
|
||||
if (du && du->nullable) {
|
||||
/* Single 8B slot: just push the pointer/null. */
|
||||
cgexpr(c, src, *locals_p);
|
||||
@@ -3191,8 +3202,7 @@ cg_structlit_fill(Cg *c, Local **locals_p, Type *lu, Node *lit,
|
||||
if (fu && fu->kind == TY_ARRAY
|
||||
&& f->lhs && f->lhs->kind == N_ARRLIT) {
|
||||
Type *esub = fu->sub;
|
||||
Type *esubu = (esub && esub->kind == TY_NAMED)
|
||||
? esub->under : esub;
|
||||
Type *esubu = type_chase_named(esub);
|
||||
int esz = esub ? (int)esub->size : 1;
|
||||
int al_isf32 = 0;
|
||||
int is_float_el = fld_isfloat(esub, &al_isf32);
|
||||
|
||||
Reference in New Issue
Block a user