selfhost/cmd/wcc: collapse signedness predicates onto n.type_ (A.6.3a, #45)

The node-keyed signedness helpers (typenodeisunsigned,
typenodeisunsignedc, elemissigned, elemissignedc, fieldissignedc) each
re-walked TBANG / TENUM / TNAME chains and re-consulted alias / enum
registries — duplicating cstage's type_isunsigned (cmd/wcc/type.c:178)
and fld_issigned (cmd/w6c/cgen.c:240) at the AST level. After A.6.2
every type-AST kind we read here is tinfo-stamped at check.ww L426-436,
so the predicates collapse to a single tinfo read.

Two new arms close the wwstage divergence from cstage: typeisunsigned
gains TY_RUNE and TY_ENUM (recurse on .sub), matching type.c:178
verbatim. typeissigned is added as the cgen-facing predicate per
fld_issigned semantics (TY_BOOL excluded for sub-word storage —
0/1 → MOVZBQ — so it's not just !typeisunsigned). Rule 9 carve-out:
the helper exists in cstage; harec keeps the same pair.

elemissigned was fully dead (no callers); deleted. typenameissigned
was internal-only and dead post-collapse; deleted. typenameisunsigned
survives — two call sites (typenodeprimresolved, exprprimresolved)
hold only a raw `str` (TNAME.str / INTLIT.tsuffix). paramissigned in
cgenstmt.ww unchanged. Both deferrals close in A.6.3c (#47).

Byte-identity (994/995) is the behavior gate for the alias/enum
sites — full `make test` green at 133/133 confirms.
This commit is contained in:
2026-05-22 05:24:49 +09:00
parent 045c49e398
commit 03e4718199
5 changed files with 180 additions and 312 deletions

View File

@@ -3615,7 +3615,10 @@ fn cgassign(c: *cgen, n: *node) void = {
// arm. Pre-fix the default branch silently stored
// rhs into *p (combineop = MOVQ shape).
if (n.op == tkind.TK_SLASHEQ || n.op == tkind.TK_PERCENTEQ) {
let unsignd: bool = typenodeisunsignedc(c, pe);
let unsignd: bool = false;
if (pe != nil) {
unsignd = typeisunsigned(pe.type_: *tinfo);
};
if (!unsignd) {
unsignd = nodeisunsigned(c, n.rhs);
};
@@ -5500,7 +5503,10 @@ fn cgassign(c: *cgen, n: *node) void = {
// ferry AX or DX back to BX for the shared
// store-BX tail below.
else { if (n.op == tkind.TK_SLASHEQ || n.op == tkind.TK_PERCENTEQ) {
let unsignd: bool = typenodeisunsignedc(c, lvftn);
let unsignd: bool = false;
if (lvftn != nil) {
unsignd = typeisunsigned(lvftn.type_: *tinfo);
};
if (!unsignd) {
unsignd = nodeisunsigned(c, n.rhs);
};
@@ -5783,7 +5789,9 @@ fn cgassign(c: *cgen, n: *node) void = {
if (n.op == tkind.TK_SLASHEQ || n.op == tkind.TK_PERCENTEQ) {
let unsignd: bool = false;
if (lcn != nil) {
unsignd = typenodeisunsignedc(c, lcn.tnode);
if (lcn.tnode != nil) {
unsignd = typeisunsigned(lcn.tnode.type_: *tinfo);
};
};
if (!unsignd) {
unsignd = nodeisunsigned(c, n.rhs);