wcc: add the opaque abstract type (kind + UNDEFINED sentinel + name-binding) (#108)

#108 sub-fold (a): TY_OPAQUE exists, is name-bindable, and carries an
UNDEFINED size sentinel. Mirrors the #85 `size` fold pattern at every
site, both stages (rule-10).

opaque is abstract + UNSIZED: prim()'d with size=align=SIZE_UNDEFINED
(NOT 0 — a 0 would let a bare `let x: opaque` fabricate a 0-byte local),
mirroring harec builtin_type_opaque (ref/harec/src/types.c:1446). ww had
no incomplete-size sentinel, so this fold ADDS one: cstage
`#define SIZE_UNDEFINED ((u64)-1)` (== harec types.h:58 (size_t)-1) and
wwstage `def SIZE_UNDEFINED: u64 = 18446744073709551615`.

Legal only behind indirection: `*opaque` (8B ptr) and `[]opaque` (24B
slice header) construct correctly because type_ptr/type_slice (and the
wwstage typeptr/typeslice) size themselves independent of the element.
opaque is deliberately absent from is-int/unsigned/num/float and from
the size-classification switches (let_emit_size / tupleelemslot /
fieldslotsize) on both stages — it only reaches those as TY_PTR/TY_SLICE.

The use-restriction GUARDS (reject bare opaque / size(opaque) / opaque
field / [N]opaque / []opaque-indexing), assignability, and cgen-verify
are the separate sub-folds (b)/(c)/(d) — NOT here.

opaque is unused by the bootstrap, so 990-997 stay byte-identical
(inert, like #85). Regenerates the w6c/wwdump combined.ww (typ.ww +
check.ww embedded). New probe 960_opaque_decl_run exercises `*opaque`
and `[]opaque` (.len/.ptr) behind indirection.
This commit is contained in:
2026-05-26 09:02:08 +09:00
parent d9cfb91cb9
commit 3a18d2cfe6
9 changed files with 209 additions and 1 deletions

View File

@@ -391,11 +391,19 @@ typedef enum {
* lib/ww/typ.ww mirrors them as explicit `def` numbers. */
TY_ENUM, /* `enum [storage] { ... }`. sub=storage,
* fields=member list (Tfield.offset = u64 value). */
TY_SIZE /* platform-width unsigned int; mirrors TY_UINTPTR
TY_SIZE, /* platform-width unsigned int; mirrors TY_UINTPTR
* (8/8 on amd64). Hare: `size`, SIZE_MAX=U64_MAX
* (ref/hare/types/arch+x86_64.ha:17,20). #85 fold-1. */
TY_OPAQUE /* abstract + unsized; legal only behind indirection
* (`*opaque`, `[]opaque`). size=align=SIZE_UNDEFINED.
* Hare: `opaque` (ref/harec/src/types.c:1446). #108(a). */
} TypeKind;
/* Unsized sentinel for abstract types (Type.size / Type.align). Mirrors
* harec's SIZE_UNDEFINED = (size_t)-1 (ref/harec/include/types.h:58);
* chosen over 0 so a 0-byte local can never silently slip through. */
#define SIZE_UNDEFINED ((u64)-1)
typedef struct Tfield Tfield;
struct Tfield {
const char *name;
@@ -444,6 +452,7 @@ extern Type *ty_f32, *ty_f64, *ty_str;
extern Type *ty_err;
extern Type *ty_never;
extern Type *ty_nomem; /* task #29: predeclared `!void` alias */
extern Type *ty_opaque; /* #108(a): abstract unsized; behind indirection only */
extern Type *ty_untyped_int, *ty_untyped_float, *ty_untyped_str;
extern Type *ty_untyped_rune, *ty_untyped_bool, *ty_untyped_nil;