From 747279c0294f06444158b79297374c942b9d8521 Mon Sep 17 00:00:00 2001 From: Hojun-Cho Date: Fri, 22 May 2026 23:44:31 +0900 Subject: [PATCH] selfhost/cmd/wcc: collapse typenameisunsigned onto tinfo (#52, A.6.3c-cast) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A.6.3a (#45) deferred typenameisunsigned because its two callers — typenodeprimresolved and exprprimresolved — consumed a raw str: TNAME.str / INTLIT.tsuffix. #51 (1ce0f63) stamped tsuffix-typed N_INTLIT.type_ via tinfofornode; together with check.ww L426-436 type-AST stamping, both call sites now read a stamped n.type_ instead of a raw name. typenodeprimresolved L1583 swaps typenameisunsigned(nm) for typeisunsigned(cur.type_: *tinfo). cur is the walked N_TNAME; its type_ is stamped at check time. exprprimresolved L1620 swaps typenameisunsigned(s) for typeisunsigned (n.type_: *tinfo). n is the N_INTLIT whose tsuffix is s; type_ is stamped by the #51 arm. primsize(s) > 0 IS the tsuffix-resolves-to- builtin gate, so the stamp is guaranteed at the read site. typenameisunsigned (cgenutil.ww L850-866) deleted: -17 LOC of body + WHY block. Net change is three files (cgenutil.ww + two .combined.ww bundler regens, same -17 each). Mirrors cstage cmd/wcc/type.c:178 type_isunsigned plus cmd/w6c/cgen.c castsrcprim routing INTLIT.tsuffix through n->type, then type_isunsigned. Aligned, not richer. Byte-identity (994/995) is the behavior gate; full make test green at 133/133 confirms. --- selfhost/cmd/w6c/main.combined.ww | 21 ++------------------- selfhost/cmd/wcc/cgenutil.ww | 21 ++------------------- selfhost/cmd/wwdump/main.combined.ww | 21 ++------------------- 3 files changed, 6 insertions(+), 57 deletions(-) diff --git a/selfhost/cmd/w6c/main.combined.ww b/selfhost/cmd/w6c/main.combined.ww index fa6ea27c..d8ad8c56 100644 --- a/selfhost/cmd/w6c/main.combined.ww +++ b/selfhost/cmd/w6c/main.combined.ww @@ -11221,23 +11221,6 @@ fn nodeisstr(c: *cgen, n: *node) bool = { return false; }; -// typenameisunsigned — primitive-name unsigned check. Kept because -// two call sites (typenodeprimresolved L1729, exprprimresolved L1766) -// have only a raw `str` in scope (TNAME.str / INTLIT.tsuffix), not a -// stamped *node — the typed-AST path doesn't reach them yet (#47 -// A.6.3c). The node-keyed predicates collapsed onto -// typeisunsigned(n.type_: *tinfo) per A.6.3a (#45). -fn typenameisunsigned(nm: str) bool = { - if (streq(nm, "u8")) { return true; }; - if (streq(nm, "u16")) { return true; }; - if (streq(nm, "u32")) { return true; }; - if (streq(nm, "u64")) { return true; }; - if (streq(nm, "uint")) { return true; }; - if (streq(nm, "uintptr")) { return true; }; - if (streq(nm, "rune")) { return true; }; - return false; -}; - // typeis8byteprimitive — does this type take exactly one 8-byte // slot rather than a wider aggregate? One-liner via typeis8byteprim // (cstage N_LET sz==8 ladder SSoT). t.type_ is stamped at check.ww @@ -11969,7 +11952,7 @@ export fn typenodeprimresolved(c: *cgen, t: *node, let ps: i32 = primsize(nm); if (ps > 0) { *sz_out = ps; - *unsigned_out = typenameisunsigned(nm); + *unsigned_out = typeisunsigned(cur.type_: *tinfo); return; }; let al: *node = aliaslookup(c, nm); @@ -12006,7 +11989,7 @@ export fn exprprimresolved(c: *cgen, n: *node, let ps: i32 = primsize(s); if (ps > 0) { *sz_out = ps; - *unsigned_out = typenameisunsigned(s); + *unsigned_out = typeisunsigned(n.type_: *tinfo); }; }; return; diff --git a/selfhost/cmd/wcc/cgenutil.ww b/selfhost/cmd/wcc/cgenutil.ww index 470b8333..ec169e98 100644 --- a/selfhost/cmd/wcc/cgenutil.ww +++ b/selfhost/cmd/wcc/cgenutil.ww @@ -849,23 +849,6 @@ fn nodeisstr(c: *cgen, n: *node) bool = { return false; }; -// typenameisunsigned — primitive-name unsigned check. Kept because -// two call sites (typenodeprimresolved L1729, exprprimresolved L1766) -// have only a raw `str` in scope (TNAME.str / INTLIT.tsuffix), not a -// stamped *node — the typed-AST path doesn't reach them yet (#47 -// A.6.3c). The node-keyed predicates collapsed onto -// typeisunsigned(n.type_: *tinfo) per A.6.3a (#45). -fn typenameisunsigned(nm: str) bool = { - if (streq(nm, "u8")) { return true; }; - if (streq(nm, "u16")) { return true; }; - if (streq(nm, "u32")) { return true; }; - if (streq(nm, "u64")) { return true; }; - if (streq(nm, "uint")) { return true; }; - if (streq(nm, "uintptr")) { return true; }; - if (streq(nm, "rune")) { return true; }; - return false; -}; - // typeis8byteprimitive — does this type take exactly one 8-byte // slot rather than a wider aggregate? One-liner via typeis8byteprim // (cstage N_LET sz==8 ladder SSoT). t.type_ is stamped at check.ww @@ -1597,7 +1580,7 @@ export fn typenodeprimresolved(c: *cgen, t: *node, let ps: i32 = primsize(nm); if (ps > 0) { *sz_out = ps; - *unsigned_out = typenameisunsigned(nm); + *unsigned_out = typeisunsigned(cur.type_: *tinfo); return; }; let al: *node = aliaslookup(c, nm); @@ -1634,7 +1617,7 @@ export fn exprprimresolved(c: *cgen, n: *node, let ps: i32 = primsize(s); if (ps > 0) { *sz_out = ps; - *unsigned_out = typenameisunsigned(s); + *unsigned_out = typeisunsigned(n.type_: *tinfo); }; }; return; diff --git a/selfhost/cmd/wwdump/main.combined.ww b/selfhost/cmd/wwdump/main.combined.ww index 31455ace..69b84bb6 100644 --- a/selfhost/cmd/wwdump/main.combined.ww +++ b/selfhost/cmd/wwdump/main.combined.ww @@ -11221,23 +11221,6 @@ fn nodeisstr(c: *cgen, n: *node) bool = { return false; }; -// typenameisunsigned — primitive-name unsigned check. Kept because -// two call sites (typenodeprimresolved L1729, exprprimresolved L1766) -// have only a raw `str` in scope (TNAME.str / INTLIT.tsuffix), not a -// stamped *node — the typed-AST path doesn't reach them yet (#47 -// A.6.3c). The node-keyed predicates collapsed onto -// typeisunsigned(n.type_: *tinfo) per A.6.3a (#45). -fn typenameisunsigned(nm: str) bool = { - if (streq(nm, "u8")) { return true; }; - if (streq(nm, "u16")) { return true; }; - if (streq(nm, "u32")) { return true; }; - if (streq(nm, "u64")) { return true; }; - if (streq(nm, "uint")) { return true; }; - if (streq(nm, "uintptr")) { return true; }; - if (streq(nm, "rune")) { return true; }; - return false; -}; - // typeis8byteprimitive — does this type take exactly one 8-byte // slot rather than a wider aggregate? One-liner via typeis8byteprim // (cstage N_LET sz==8 ladder SSoT). t.type_ is stamped at check.ww @@ -11969,7 +11952,7 @@ export fn typenodeprimresolved(c: *cgen, t: *node, let ps: i32 = primsize(nm); if (ps > 0) { *sz_out = ps; - *unsigned_out = typenameisunsigned(nm); + *unsigned_out = typeisunsigned(cur.type_: *tinfo); return; }; let al: *node = aliaslookup(c, nm); @@ -12006,7 +11989,7 @@ export fn exprprimresolved(c: *cgen, n: *node, let ps: i32 = primsize(s); if (ps > 0) { *sz_out = ps; - *unsigned_out = typenameisunsigned(s); + *unsigned_out = typeisunsigned(n.type_: *tinfo); }; }; return;