cgen: fold str tagged-variant payload store onto slice arm (both stages)

Phase 2 step 4. The str and slice tagged-union payload stores were
byte-identical adjacent arms (3-word ptr/len/cap @ slot+8/+16/+24 +
tag) since #1 made str a 24B {ptr,len,cap}. Delete the dedicated str
arm and widen the slice arm's gate to accept str (cstage type_isstr,
wwstage nodeisstr). One site, both stages. Byte-id-neutral: str now
flows the identical slice arm; full test incl 990-997 green.
This commit is contained in:
2026-05-24 09:00:53 +09:00
parent a5ca21ddba
commit b416e7114e
4 changed files with 21 additions and 96 deletions

View File

@@ -13176,32 +13176,11 @@ fn cgwidentaggedstorebp(c: *cgen, dst: *tinfo, src: *node, slot_off: i32, slot_s
return;
};
};
// str IS []u8: AX=ptr, BX=len, CX=cap from cgexpr. Slot layout
// tag@+0, ptr@+8, len@+16, cap@+24 — same 32B shape as the slice
// payload below (#1/Phase 3).
if (nodeisstr(c, src)) {
cgexpr(c, src);
emitline("\tMOVQ\tAX, ");
emitoff((slot_off + 8): i64);
emitline("(BP)\n");
emitline("\tMOVQ\tBX, ");
emitoff((slot_off + 16): i64);
emitline("(BP)\n");
emitline("\tMOVQ\tCX, ");
emitoff((slot_off + 24): i64);
emitline("(BP)\n");
let tag: i32 = taggedvariantindext(c, dt, src);
if (tag < 0) { tag = 0; };
emitline("\tMOVQ\t$");
emitint(tag: i64);
emitline(", ");
emitoff(slot_off: i64);
emitline("(BP)\n");
return;
};
// Slice payload (24B): cgexpr leaves (AX=ptr, BX=len, CX=cap).
// Slot layout: [+0]=tag, [+8]=ptr, [+16]=len, [+24]=cap.
if (nodeisslice(c, src)) {
// str IS []u8 — same 32B payload as a slice: cgexpr leaves
// (AX=ptr, BX=len, CX=cap); slot layout [+0]=tag, [+8]=ptr,
// [+16]=len, [+24]=cap. str folds onto the slice arm (#1/Phase 3
// collapse; cite cstage cg_widen_tagged_store).
if (nodeisslice(c, src) || nodeisstr(c, src)) {
cgexpr(c, src);
emitline("\tMOVQ\tAX, ");
emitoff((slot_off + 8): i64);

View File

@@ -2616,32 +2616,11 @@ fn cgwidentaggedstorebp(c: *cgen, dst: *tinfo, src: *node, slot_off: i32, slot_s
return;
};
};
// str IS []u8: AX=ptr, BX=len, CX=cap from cgexpr. Slot layout
// tag@+0, ptr@+8, len@+16, cap@+24 — same 32B shape as the slice
// payload below (#1/Phase 3).
if (nodeisstr(c, src)) {
cgexpr(c, src);
emitline("\tMOVQ\tAX, ");
emitoff((slot_off + 8): i64);
emitline("(BP)\n");
emitline("\tMOVQ\tBX, ");
emitoff((slot_off + 16): i64);
emitline("(BP)\n");
emitline("\tMOVQ\tCX, ");
emitoff((slot_off + 24): i64);
emitline("(BP)\n");
let tag: i32 = taggedvariantindext(c, dt, src);
if (tag < 0) { tag = 0; };
emitline("\tMOVQ\t$");
emitint(tag: i64);
emitline(", ");
emitoff(slot_off: i64);
emitline("(BP)\n");
return;
};
// Slice payload (24B): cgexpr leaves (AX=ptr, BX=len, CX=cap).
// Slot layout: [+0]=tag, [+8]=ptr, [+16]=len, [+24]=cap.
if (nodeisslice(c, src)) {
// str IS []u8 — same 32B payload as a slice: cgexpr leaves
// (AX=ptr, BX=len, CX=cap); slot layout [+0]=tag, [+8]=ptr,
// [+16]=len, [+24]=cap. str folds onto the slice arm (#1/Phase 3
// collapse; cite cstage cg_widen_tagged_store).
if (nodeisslice(c, src) || nodeisstr(c, src)) {
cgexpr(c, src);
emitline("\tMOVQ\tAX, ");
emitoff((slot_off + 8): i64);

View File

@@ -13176,32 +13176,11 @@ fn cgwidentaggedstorebp(c: *cgen, dst: *tinfo, src: *node, slot_off: i32, slot_s
return;
};
};
// str IS []u8: AX=ptr, BX=len, CX=cap from cgexpr. Slot layout
// tag@+0, ptr@+8, len@+16, cap@+24 — same 32B shape as the slice
// payload below (#1/Phase 3).
if (nodeisstr(c, src)) {
cgexpr(c, src);
emitline("\tMOVQ\tAX, ");
emitoff((slot_off + 8): i64);
emitline("(BP)\n");
emitline("\tMOVQ\tBX, ");
emitoff((slot_off + 16): i64);
emitline("(BP)\n");
emitline("\tMOVQ\tCX, ");
emitoff((slot_off + 24): i64);
emitline("(BP)\n");
let tag: i32 = taggedvariantindext(c, dt, src);
if (tag < 0) { tag = 0; };
emitline("\tMOVQ\t$");
emitint(tag: i64);
emitline(", ");
emitoff(slot_off: i64);
emitline("(BP)\n");
return;
};
// Slice payload (24B): cgexpr leaves (AX=ptr, BX=len, CX=cap).
// Slot layout: [+0]=tag, [+8]=ptr, [+16]=len, [+24]=cap.
if (nodeisslice(c, src)) {
// str IS []u8 — same 32B payload as a slice: cgexpr leaves
// (AX=ptr, BX=len, CX=cap); slot layout [+0]=tag, [+8]=ptr,
// [+16]=len, [+24]=cap. str folds onto the slice arm (#1/Phase 3
// collapse; cite cstage cg_widen_tagged_store).
if (nodeisslice(c, src) || nodeisstr(c, src)) {
cgexpr(c, src);
emitline("\tMOVQ\tAX, ");
emitoff((slot_off + 8): i64);