diff --git a/cmd/w6c/cgen.c b/cmd/w6c/cgen.c index 6cba67ff..8cbcc59e 100644 --- a/cmd/w6c/cgen.c +++ b/cmd/w6c/cgen.c @@ -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; diff --git a/selfhost/cmd/w6c/main.combined.ww b/selfhost/cmd/w6c/main.combined.ww index 6c628d1f..48a28919 100644 --- a/selfhost/cmd/w6c/main.combined.ww +++ b/selfhost/cmd/w6c/main.combined.ww @@ -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); diff --git a/selfhost/cmd/wcc/cgenutil.ww b/selfhost/cmd/wcc/cgenutil.ww index 5d69602d..1dd09dda 100644 --- a/selfhost/cmd/wcc/cgenutil.ww +++ b/selfhost/cmd/wcc/cgenutil.ww @@ -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); diff --git a/selfhost/cmd/wwdump/main.combined.ww b/selfhost/cmd/wwdump/main.combined.ww index df74e2c0..56741412 100644 --- a/selfhost/cmd/wwdump/main.combined.ww +++ b/selfhost/cmd/wwdump/main.combined.ww @@ -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);