wcc: name-bind the size type in type position (#85 fold-2)

Resolve `size` -> TY_SIZE at the type-name resolver (C lookup_builtin /
ww tinfofornode's N_TNAME chain), mirroring uintptr, both stages. This
makes `size` writable as a type (`let x: size`, struct field, etc.),
the prerequisite for lib/types SIZE_MAX.

Twins every NAME-keyed uintptr arm in the wwstage so it behaves like
the cstage's kind-keyed Type switches (already TY_SIZE-aware from
fold-1): primtypesize + astalign (8B/8-align), primsize + letscalarprim
(8B scalar slot), isinttypeast + isnumerictname (int/numeric). rule-10
symmetric; dead on the size-free selfhost corpus so 990-997 stay byte-id.

Coexists with the size(T) size-of operator (separate c.top SK_FN seed +
N_CALL fold, NOT a type path) and `.size` field access (N_DOT); neither
touched. No c.top SK_TYPE "size" seed (would collide with the operator
seed at check.ww:96). Regenerates w6c/wwdump combined.ww (checker
embedded). New probe 957_size_type_run exercises type-position `size`
and the operator in one scope.
This commit is contained in:
2026-05-26 01:55:54 +09:00
parent bd7181ae1f
commit 9a265a31f5
8 changed files with 164 additions and 6 deletions

View File

@@ -7836,7 +7836,7 @@ fn primtypesize(nm: str) i64 = {
if (streq(nm, "i16") || streq(nm, "u16")) { return 2i64; };
if (streq(nm, "i32") || streq(nm, "u32") || streq(nm, "f32") || streq(nm, "rune")) { return 4i64; };
if (streq(nm, "i64") || streq(nm, "u64") || streq(nm, "f64")) { return 8i64; };
if (streq(nm, "int") || streq(nm, "uint") || streq(nm, "uintptr")) { return 8i64; };
if (streq(nm, "int") || streq(nm, "uint") || streq(nm, "uintptr") || streq(nm, "size")) { return 8i64; };
// str IS []u8: 24B, sourced from the slice header SSoT so str and
// []u8 can never drift; no second hardcoded 24 (#1/Phase 3).
if (streq(nm, "str")) { return tyslicesize(); };
@@ -7895,7 +7895,7 @@ fn astalign(c: *checker, t: *node) i64 = {
if (streq(nm, "void") || streq(nm, "bool") || streq(nm, "i8") || streq(nm, "u8")) { return 1i64; };
if (streq(nm, "i16") || streq(nm, "u16")) { return 2i64; };
if (streq(nm, "i32") || streq(nm, "u32") || streq(nm, "f32") || streq(nm, "rune")) { return 4i64; };
if (streq(nm, "i64") || streq(nm, "u64") || streq(nm, "f64") || streq(nm, "int") || streq(nm, "uint") || streq(nm, "uintptr") || streq(nm, "str")) { return 8i64; };
if (streq(nm, "i64") || streq(nm, "u64") || streq(nm, "f64") || streq(nm, "int") || streq(nm, "uint") || streq(nm, "uintptr") || streq(nm, "size") || streq(nm, "str")) { return 8i64; };
let resolved: *node = resolvealias(c, t);
if (resolved != nil && resolved != t) {
return astalign(c, resolved);
@@ -8421,6 +8421,7 @@ fn tinfofornode(c: *checker, n: *node) *tinfo = {
if (streq(nm, "int")) { r = c.tc.tyint; };
if (streq(nm, "uint")) { r = c.tc.tyuint; };
if (streq(nm, "uintptr")) { r = c.tc.tyuintptr; };
if (streq(nm, "size")) { r = c.tc.tysize; }; // #85 fold-2
if (streq(nm, "f32")) { r = c.tc.tyf32; };
if (streq(nm, "f64")) { r = c.tc.tyf64; };
if (streq(nm, "str")) { r = c.tc.tystr; };
@@ -9713,6 +9714,7 @@ fn isinttypeast(t: *node) bool = {
if (streq(s, "int")) { return true; };
if (streq(s, "uint")) { return true; };
if (streq(s, "uintptr")) { return true; };
if (streq(s, "size")) { return true; };
if (streq(s, "rune")) { return true; };
return false;
};
@@ -9732,6 +9734,7 @@ fn isnumerictname(t: *node) bool = {
if (streq(s, "int")) { return true; };
if (streq(s, "uint")) { return true; };
if (streq(s, "uintptr")) { return true; };
if (streq(s, "size")) { return true; };
if (streq(s, "rune")) { return true; };
if (streq(s, "f32")) { return true; };
if (streq(s, "f64")) { return true; };
@@ -11986,6 +11989,7 @@ fn primsize(name: str) i32 = {
if (streq(name, "uint")) { return 8; };
if (streq(name, "int")) { return 8; };
if (streq(name, "uintptr")) { return 8; };
if (streq(name, "size")) { return 8; };
if (streq(name, "f64")) { return 8; };
if (streq(name, "rune")) { return 4; };
if (streq(name, "void")) { return 0; };
@@ -23454,6 +23458,7 @@ fn letscalarprim(nm: str) bool = {
if (streq(nm, "int")) { return true; };
if (streq(nm, "uint")) { return true; };
if (streq(nm, "uintptr")) { return true; };
if (streq(nm, "size")) { return true; };
return false;
};

View File

@@ -904,6 +904,7 @@ fn letscalarprim(nm: str) bool = {
if (streq(nm, "int")) { return true; };
if (streq(nm, "uint")) { return true; };
if (streq(nm, "uintptr")) { return true; };
if (streq(nm, "size")) { return true; };
return false;
};

View File

@@ -1248,6 +1248,7 @@ fn primsize(name: str) i32 = {
if (streq(name, "uint")) { return 8; };
if (streq(name, "int")) { return 8; };
if (streq(name, "uintptr")) { return 8; };
if (streq(name, "size")) { return 8; };
if (streq(name, "f64")) { return 8; };
if (streq(name, "rune")) { return 4; };
if (streq(name, "void")) { return 0; };

View File

@@ -713,7 +713,7 @@ fn primtypesize(nm: str) i64 = {
if (streq(nm, "i16") || streq(nm, "u16")) { return 2i64; };
if (streq(nm, "i32") || streq(nm, "u32") || streq(nm, "f32") || streq(nm, "rune")) { return 4i64; };
if (streq(nm, "i64") || streq(nm, "u64") || streq(nm, "f64")) { return 8i64; };
if (streq(nm, "int") || streq(nm, "uint") || streq(nm, "uintptr")) { return 8i64; };
if (streq(nm, "int") || streq(nm, "uint") || streq(nm, "uintptr") || streq(nm, "size")) { return 8i64; };
// str IS []u8: 24B, sourced from the slice header SSoT so str and
// []u8 can never drift; no second hardcoded 24 (#1/Phase 3).
if (streq(nm, "str")) { return tyslicesize(); };
@@ -772,7 +772,7 @@ fn astalign(c: *checker, t: *node) i64 = {
if (streq(nm, "void") || streq(nm, "bool") || streq(nm, "i8") || streq(nm, "u8")) { return 1i64; };
if (streq(nm, "i16") || streq(nm, "u16")) { return 2i64; };
if (streq(nm, "i32") || streq(nm, "u32") || streq(nm, "f32") || streq(nm, "rune")) { return 4i64; };
if (streq(nm, "i64") || streq(nm, "u64") || streq(nm, "f64") || streq(nm, "int") || streq(nm, "uint") || streq(nm, "uintptr") || streq(nm, "str")) { return 8i64; };
if (streq(nm, "i64") || streq(nm, "u64") || streq(nm, "f64") || streq(nm, "int") || streq(nm, "uint") || streq(nm, "uintptr") || streq(nm, "size") || streq(nm, "str")) { return 8i64; };
let resolved: *node = resolvealias(c, t);
if (resolved != nil && resolved != t) {
return astalign(c, resolved);
@@ -1298,6 +1298,7 @@ fn tinfofornode(c: *checker, n: *node) *tinfo = {
if (streq(nm, "int")) { r = c.tc.tyint; };
if (streq(nm, "uint")) { r = c.tc.tyuint; };
if (streq(nm, "uintptr")) { r = c.tc.tyuintptr; };
if (streq(nm, "size")) { r = c.tc.tysize; }; // #85 fold-2
if (streq(nm, "f32")) { r = c.tc.tyf32; };
if (streq(nm, "f64")) { r = c.tc.tyf64; };
if (streq(nm, "str")) { r = c.tc.tystr; };
@@ -2590,6 +2591,7 @@ fn isinttypeast(t: *node) bool = {
if (streq(s, "int")) { return true; };
if (streq(s, "uint")) { return true; };
if (streq(s, "uintptr")) { return true; };
if (streq(s, "size")) { return true; };
if (streq(s, "rune")) { return true; };
return false;
};
@@ -2609,6 +2611,7 @@ fn isnumerictname(t: *node) bool = {
if (streq(s, "int")) { return true; };
if (streq(s, "uint")) { return true; };
if (streq(s, "uintptr")) { return true; };
if (streq(s, "size")) { return true; };
if (streq(s, "rune")) { return true; };
if (streq(s, "f32")) { return true; };
if (streq(s, "f64")) { return true; };

View File

@@ -7836,7 +7836,7 @@ fn primtypesize(nm: str) i64 = {
if (streq(nm, "i16") || streq(nm, "u16")) { return 2i64; };
if (streq(nm, "i32") || streq(nm, "u32") || streq(nm, "f32") || streq(nm, "rune")) { return 4i64; };
if (streq(nm, "i64") || streq(nm, "u64") || streq(nm, "f64")) { return 8i64; };
if (streq(nm, "int") || streq(nm, "uint") || streq(nm, "uintptr")) { return 8i64; };
if (streq(nm, "int") || streq(nm, "uint") || streq(nm, "uintptr") || streq(nm, "size")) { return 8i64; };
// str IS []u8: 24B, sourced from the slice header SSoT so str and
// []u8 can never drift; no second hardcoded 24 (#1/Phase 3).
if (streq(nm, "str")) { return tyslicesize(); };
@@ -7895,7 +7895,7 @@ fn astalign(c: *checker, t: *node) i64 = {
if (streq(nm, "void") || streq(nm, "bool") || streq(nm, "i8") || streq(nm, "u8")) { return 1i64; };
if (streq(nm, "i16") || streq(nm, "u16")) { return 2i64; };
if (streq(nm, "i32") || streq(nm, "u32") || streq(nm, "f32") || streq(nm, "rune")) { return 4i64; };
if (streq(nm, "i64") || streq(nm, "u64") || streq(nm, "f64") || streq(nm, "int") || streq(nm, "uint") || streq(nm, "uintptr") || streq(nm, "str")) { return 8i64; };
if (streq(nm, "i64") || streq(nm, "u64") || streq(nm, "f64") || streq(nm, "int") || streq(nm, "uint") || streq(nm, "uintptr") || streq(nm, "size") || streq(nm, "str")) { return 8i64; };
let resolved: *node = resolvealias(c, t);
if (resolved != nil && resolved != t) {
return astalign(c, resolved);
@@ -8421,6 +8421,7 @@ fn tinfofornode(c: *checker, n: *node) *tinfo = {
if (streq(nm, "int")) { r = c.tc.tyint; };
if (streq(nm, "uint")) { r = c.tc.tyuint; };
if (streq(nm, "uintptr")) { r = c.tc.tyuintptr; };
if (streq(nm, "size")) { r = c.tc.tysize; }; // #85 fold-2
if (streq(nm, "f32")) { r = c.tc.tyf32; };
if (streq(nm, "f64")) { r = c.tc.tyf64; };
if (streq(nm, "str")) { r = c.tc.tystr; };
@@ -9713,6 +9714,7 @@ fn isinttypeast(t: *node) bool = {
if (streq(s, "int")) { return true; };
if (streq(s, "uint")) { return true; };
if (streq(s, "uintptr")) { return true; };
if (streq(s, "size")) { return true; };
if (streq(s, "rune")) { return true; };
return false;
};
@@ -9732,6 +9734,7 @@ fn isnumerictname(t: *node) bool = {
if (streq(s, "int")) { return true; };
if (streq(s, "uint")) { return true; };
if (streq(s, "uintptr")) { return true; };
if (streq(s, "size")) { return true; };
if (streq(s, "rune")) { return true; };
if (streq(s, "f32")) { return true; };
if (streq(s, "f64")) { return true; };
@@ -11986,6 +11989,7 @@ fn primsize(name: str) i32 = {
if (streq(name, "uint")) { return 8; };
if (streq(name, "int")) { return 8; };
if (streq(name, "uintptr")) { return 8; };
if (streq(name, "size")) { return 8; };
if (streq(name, "f64")) { return 8; };
if (streq(name, "rune")) { return 4; };
if (streq(name, "void")) { return 0; };
@@ -23454,6 +23458,7 @@ fn letscalarprim(nm: str) bool = {
if (streq(nm, "int")) { return true; };
if (streq(nm, "uint")) { return true; };
if (streq(nm, "uintptr")) { return true; };
if (streq(nm, "size")) { return true; };
return false;
};