comptime VM: flip Type to .type_value; migrate the .any refs that mean a Type value

type_resolver "Type" -> .type_value; const_type result + emitConstType now a
bare 8-byte i64 handle (not a 16-byte Any box). Migrated every .any ref meaning
"a Type value", leaving real boxed-Any refs:

- "Any holds a Type" meta-marker tag .any -> .type_value at all 4 consumers
  (reflectArgTypeId, reflectTypeId, the comptime type_tag-as-struct path,
  resolveTypeCategoryTags "type").
- reflection-builtin return types (type_of/declare/define) -> .type_value;
  runtime type_of(any) reads the tag as a .type_value (no re-box).
- expr_typer: a bare type-name expr is .type_value (backtick is_raw exempt).
- reflectionArgIsType accepts .type_value OR .any (a reflection arg can be a
  bare Type or a boxed Any).
- comptime switch_br accepts a .type_tag discriminant (type-category match).
- a bare function name in a Type slot -> const_type(its function type), not a
  func-ref (fixes a JIT crash); old string-box kept only for genuine Any params.
- field-not-found diagnostic + formatTypeName render .type_value as "Type".

Fixed 3 unit tests asserting the old .any behavior. 697/0 both gates (gate ON
bails cleanly to legacy since the VM doesn't model Type values yet) + 494 unit
tests. 24 snapshots regenerated (22 .ir const_type shape; 2 .stderr Any->Type).
This commit is contained in:
agra
2026-06-18 13:54:56 +03:00
parent 6844fb90e7
commit 94f60c51c0
37 changed files with 48941 additions and 48226 deletions

View File

@@ -812,7 +812,10 @@ test "comptime: type_eq builtin on type_tag values" {
// `av : Any = 6` (`{ tag = i64, value = 6 }`) must resolve to `i64`, NOT
// `types[6]` (`u8`).
test "reflect: reflectTypeId branches on the Any tag" {
const any_idx: i64 = @intCast(TypeId.any.index());
// The "Any holds a Type" meta-marker tag is `.type_value` (an Any boxing a
// Type value carries `{ tag = .type_value, value = tid }`), distinct from a
// boxed runtime value whose tag is the held value's own type.
const type_marker: i64 = @intCast(TypeId.type_value.index());
// Native first-class Type value → the held TypeId directly.
try std.testing.expectEqual(@as(?TypeId, .u64), (Value{ .type_tag = .u64 }).reflectTypeId());
@@ -827,13 +830,13 @@ test "reflect: reflectTypeId branches on the Any tag" {
try std.testing.expectEqual(@as(?TypeId, .u32), (Value{ .aggregate = &held_u32 }).reflectTypeId());
// Any holding a TYPE value (the `type_of(x)` / `const_type` shape):
// `{ tag = .any, value = u64 }` → u64 (the payload). Payload as a plain
// `{ tag = .type_value, value = u64 }` → u64 (the payload). Payload as a plain
// int (the runtime box shape) ...
var held_type_int = [_]Value{ .{ .int = any_idx }, .{ .int = @intCast(TypeId.u64.index()) } };
var held_type_int = [_]Value{ .{ .int = type_marker }, .{ .int = @intCast(TypeId.u64.index()) } };
try std.testing.expectEqual(@as(?TypeId, .u64), (Value{ .aggregate = &held_type_int }).reflectTypeId());
// ... and payload as a `.type_tag` (the comptime box shape) → same result.
var held_type_tag = [_]Value{ .{ .int = any_idx }, .{ .type_tag = .u64 } };
var held_type_tag = [_]Value{ .{ .int = type_marker }, .{ .type_tag = .u64 } };
try std.testing.expectEqual(@as(?TypeId, .u64), (Value{ .aggregate = &held_type_tag }).reflectTypeId());
// Neither shape → null (the caller bails loudly, never guesses a TypeId).