cgen: collapse redundant TY_STR esz special-cases onto str.sub -- Phase 2 step-3 Fold 2

F1 set str.sub = u8; the str-element-size readers no longer need a TY_STR special-case. cstage: delete the two 'if (kind==TY_STR) esz = ty_u8->size' blocks -- the general 'esz = sub->size' path already yields 1 for str (str.sub=u8), as the third index site (which never had the special-case) proves. Provably byte-id-NEUTRAL for ALL inputs: ty_str is the sole TY_STR instance and str.sub==ty_u8, so sub->size==ty_u8->size==1 in every case. No kind-gate (type_isstr/isstrtype arm-selectors) touched.

wwstage elemsizeof (cgenutil.ww) is COMMENT-ONLY: it names primtypesize("u8") directly because it operates on a raw type node with no stamped tinfo at the ident-base index path (str.sub lives on .type_.sub, unstamped here -- cf. cgforrange's 'if sti != nil'); that IS the str.sub-equivalent value, identical asm. Added the WHY + retargeted the citation to the surviving cstage path. The structural collapse there is blocked on tinfo-stamping, not intent -- filed (task #24); byte-id 990-997 guards the residual coupling.

Zero asm change both stages (cstage/wwstage .s byte-identical pre/post and cross-stage). main.combined.ww regenerated via the canonical make path (comment propagation only).
This commit is contained in:
2026-05-24 18:01:32 +09:00
parent 3d7c707bd2
commit 3637993bb2
4 changed files with 24 additions and 16 deletions

View File

@@ -2118,10 +2118,6 @@ cgexpr(Cg *c, Node *n, Local *locals)
? bt->under : bt;
int esz = (bu && bu->sub)
? (int)bu->sub->size : 1;
/* str element is u8 — size via the type table
* so #1's TY_STR collapse needs no second edit. */
if (bu && bu->kind == TY_STR)
esz = (int)ty_u8->size;
cgexpr(c, idx, locals); /* idx → AX */
if (esz > 1) {
ins2(c, A_MOVQ, aimm(esz),
@@ -6254,9 +6250,6 @@ cgexpr(Cg *c, Node *n, Local *locals)
Type *eff = idx_eff(bt);
int esz = 1;
if (eff && eff->sub) esz = (int)eff->sub->size;
/* str element is u8 — size via the type table so #1's
* TY_STR collapse needs no second edit. */
if (u && u->kind == TY_STR) esz = (int)ty_u8->size;
Type *esub = eff ? eff->sub : NULL;
Type *esubu = (esub && esub->kind == TY_NAMED)
? esub->under : esub;

View File

@@ -11433,9 +11433,14 @@ fn elemsizeof(t: *node) i32 = {
if (k == nkind.N_TARRAY) { elem = t.lhs; };
if (k == nkind.N_TNAME) {
let nm: str = t.str;
// str element is u8 — size via the type table so #1's
// TY_STR collapse needs no second edit. Cite cstage cgen.c
// N_INDEX `esz = ty_u8->size`.
// str's element is u8 (F1: tystr.sub = tyu8), named directly
// rather than read off str.sub because elemsizeof gets a raw
// N_TNAME at the ident-base index path with no checker-stamped
// tinfo — str.sub lives on .type_.sub, unstamped at this site
// (cf. cgforrange's `if (sti != nil)` guard). This IS the
// str.sub-equivalent; the structural collapse onto str.sub is
// blocked on tinfo-stamping here, not intent (#24). cstage twin
// reads eff->sub->size (cmd/w6c/cgen.c N_INDEX).
if (streq(nm, "str")) { return primtypesize("u8"): i32; };
// Indexing a primitive name (rare): element size = the prim.
let ps: i32 = primsize(nm);

View File

@@ -872,9 +872,14 @@ fn elemsizeof(t: *node) i32 = {
if (k == nkind.N_TARRAY) { elem = t.lhs; };
if (k == nkind.N_TNAME) {
let nm: str = t.str;
// str element is u8 — size via the type table so #1's
// TY_STR collapse needs no second edit. Cite cstage cgen.c
// N_INDEX `esz = ty_u8->size`.
// str's element is u8 (F1: tystr.sub = tyu8), named directly
// rather than read off str.sub because elemsizeof gets a raw
// N_TNAME at the ident-base index path with no checker-stamped
// tinfo — str.sub lives on .type_.sub, unstamped at this site
// (cf. cgforrange's `if (sti != nil)` guard). This IS the
// str.sub-equivalent; the structural collapse onto str.sub is
// blocked on tinfo-stamping here, not intent (#24). cstage twin
// reads eff->sub->size (cmd/w6c/cgen.c N_INDEX).
if (streq(nm, "str")) { return primtypesize("u8"): i32; };
// Indexing a primitive name (rare): element size = the prim.
let ps: i32 = primsize(nm);

View File

@@ -11433,9 +11433,14 @@ fn elemsizeof(t: *node) i32 = {
if (k == nkind.N_TARRAY) { elem = t.lhs; };
if (k == nkind.N_TNAME) {
let nm: str = t.str;
// str element is u8 — size via the type table so #1's
// TY_STR collapse needs no second edit. Cite cstage cgen.c
// N_INDEX `esz = ty_u8->size`.
// str's element is u8 (F1: tystr.sub = tyu8), named directly
// rather than read off str.sub because elemsizeof gets a raw
// N_TNAME at the ident-base index path with no checker-stamped
// tinfo — str.sub lives on .type_.sub, unstamped at this site
// (cf. cgforrange's `if (sti != nil)` guard). This IS the
// str.sub-equivalent; the structural collapse onto str.sub is
// blocked on tinfo-stamping here, not intent (#24). cstage twin
// reads eff->sub->size (cmd/w6c/cgen.c N_INDEX).
if (streq(nm, "str")) { return primtypesize("u8"): i32; };
// Indexing a primitive name (rare): element size = the prim.
let ps: i32 = primsize(nm);