comptime VM: model .type_value natively (word); harden struct_init vs arrays

kindOf(.type_value) -> .word; new const_type exec arm -> word = TypeId.index();
regToValue maps a .type_value word back to a .type_tag Value at the legacy
boundary. The VM now runs comptime evals involving Type values instead of
bailing.

This reached a latent VM panic: struct_init assumed a .@"struct" result type and
union-access-panicked on an array literal (EnumVariant.[...]). It is the generic
aggregate-literal op, so it now dispatches on the result kind (struct/array/
tuple) and bails loudly on anything else — never panics (CLAUDE.md no-panic).

697/0 both gates (make_enum type-fns run further on the VM, then bail cleanly at
the define call_builtin -> legacy mints; no mutation before bail). VM unit test
added (const_type -> word -> regToValue -> .type_tag).
This commit is contained in:
agra
2026-06-18 14:05:16 +03:00
parent 94f60c51c0
commit 554871ba0b
3 changed files with 66 additions and 5 deletions

View File

@@ -589,6 +589,29 @@ test "comptime_vm exec: payloadless enum_init + enum_tag" {
try std.testing.expectEqual(@as(i64, 11), toI64(try v.run(&fb.func, &.{})));
}
test "comptime_vm exec: const_type yields a Type-value word; regToValue bridges it to .type_tag" {
const alloc = std.testing.allocator;
var table = types.TypeTable.init(alloc);
defer table.deinit();
// return <Type value u32> → a `.type_value`-typed entry whose word is u32.index()
var fb = Fb.init(alloc, &.{}, .type_value);
defer fb.deinit();
const b0 = fb.block(&.{});
const ct = fb.add(b0, inst(.{ .const_type = .u32 }, .type_value));
_ = fb.add(b0, inst(.{ .ret = .{ .operand = ref(ct) } }, .void));
var v = vm.Vm.init(alloc);
v.table = &table;
defer v.deinit();
const word = try v.run(&fb.func, &.{});
try std.testing.expectEqual(@as(u64, types.TypeId.u32.index()), word);
// The legacy boundary maps the word back to a first-class `.type_tag` Value.
const val = try v.regToValue(alloc, &table, word, .type_value);
try std.testing.expectEqual(types.TypeId.u32, val.type_tag);
}
test "comptime_vm exec: deref a pointer; addr_of passes through a struct address" {
const alloc = std.testing.allocator;
var table = types.TypeTable.init(alloc);