cgen: str index-stride via type table, not literal 1 (both stages)

Phase 2 step 2. The N_INDEX element-stride for str hardcoded esz=1;
route it through the type table (cstage ty_u8->size, wwstage
primtypesize("u8")) so str's element width tracks the u8 SSoT. When
the TY_STR collapse (Phase 2 step 5) folds str onto the slice-of-u8
path, these sites need no second edit. Byte-id-neutral: u8 size is 1,
so emitted stride is unchanged; full test (incl 990-997 byte-id
gates) green.
This commit is contained in:
2026-05-24 09:00:36 +09:00
parent 1140a590bf
commit a5ca21ddba
4 changed files with 19 additions and 5 deletions

View File

@@ -872,7 +872,10 @@ fn elemsizeof(t: *node) i32 = {
if (k == nkind.N_TARRAY) { elem = t.lhs; };
if (k == nkind.N_TNAME) {
let nm: str = t.str;
if (streq(nm, "str")) { return 1; };
// 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`.
if (streq(nm, "str")) { return primtypesize("u8"): i32; };
// Indexing a primitive name (rare): element size = the prim.
let ps: i32 = primsize(nm);
if (ps > 0) { return ps; };