authorgravatar for mason@gamesbymason.comMason Remaley <mason@gamesbymason.com> 2026-06-23 23:13:43-07:00
committergravatar for mason@gamesbymason.comMason Remaley <mason@gamesbymason.com> 2026-06-24 22:11:49-07:00
loge4f46e7e7ac63d87319189f130629074e366164d
treed2b13b05687ea74e242ec1d60e3f9b52ef15d2cc
parentf3544a707941269ec3ed9145ee1432df5a01a10a

Asserts InternPool keys have unique representations

I also asserted that these types are extern compatible, so as to guarantee stability across compilations. `SpirvType` was failing both of these assertions. I resolved this by making it extern, and adding explicitly zeroed padding. I didn't yet add test coverage that type equality works on reified SPIRV types, as `zirReifySpirvType` returns unique values for each type regardless of the hash. I will file a followup issue for this after posting this PR.

1 files changed, 8 insertions(+), 3 deletions(-)

src/InternPool.zig+8-3
......@@ -2147,9 +2147,11 @@ pub const Key = union(enum) {
21472147 };
21482148 };
21492149
2150 pub const SpirvType = struct {
2150 pub const SpirvType = extern struct {
21512151 /// A `spirv_reify` instruction.
21522152 zir_index: TrackedInst.Index,
2153 /// Always 0.
2154 padding: u32 = 0,
21532155 /// A hash of this type's attributes generated by Sema.
21542156 type_hash: u64,
21552157 };
......@@ -2591,7 +2593,6 @@ pub const Key = union(enum) {
25912593 const KeyTag = @typeInfo(Key).@"union".tag_type.?;
25922594 const seed = @intFromEnum(@as(KeyTag, key));
25932595 return switch (key) {
2594 // TODO: assert no padding in these types
25952596 inline .ptr_type,
25962597 .array_type,
25972598 .vector_type,
......@@ -2608,7 +2609,11 @@ pub const Key = union(enum) {
26082609 .enum_tag,
26092610 .inferred_error_set_type,
26102611 .un,
2611 => |x| Hash.hash(seed, asBytes(&x)),
2612 => |x| {
2613 _ = extern struct { is_extern: @TypeOf(x) };
2614 comptime assert(std.meta.hasUniqueRepresentation(@TypeOf(x)));
2615 return Hash.hash(seed, asBytes(&x));
2616 },
26122617
26132618 .int_type => |x| Hash.hash(seed + @intFromEnum(x.signedness), asBytes(&x.bits)),
26142619