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) {...@@ -2147,9 +2147,11 @@ pub const Key = union(enum) {
2147 };2147 };
2148 };2148 };
21492149
2150 pub const SpirvType = struct {2150 pub const SpirvType = extern struct {
2151 /// A `spirv_reify` instruction.2151 /// A `spirv_reify` instruction.
2152 zir_index: TrackedInst.Index,2152 zir_index: TrackedInst.Index,
2153 /// Always 0.
2154 padding: u32 = 0,
2153 /// A hash of this type's attributes generated by Sema.2155 /// A hash of this type's attributes generated by Sema.
2154 type_hash: u64,2156 type_hash: u64,
2155 };2157 };
...@@ -2591,7 +2593,6 @@ pub const Key = union(enum) {...@@ -2591,7 +2593,6 @@ pub const Key = union(enum) {
2591 const KeyTag = @typeInfo(Key).@"union".tag_type.?;2593 const KeyTag = @typeInfo(Key).@"union".tag_type.?;
2592 const seed = @intFromEnum(@as(KeyTag, key));2594 const seed = @intFromEnum(@as(KeyTag, key));
2593 return switch (key) {2595 return switch (key) {
2594 // TODO: assert no padding in these types
2595 inline .ptr_type,2596 inline .ptr_type,
2596 .array_type,2597 .array_type,
2597 .vector_type,2598 .vector_type,
...@@ -2608,7 +2609,11 @@ pub const Key = union(enum) {...@@ -2608,7 +2609,11 @@ pub const Key = union(enum) {
2608 .enum_tag,2609 .enum_tag,
2609 .inferred_error_set_type,2610 .inferred_error_set_type,
2610 .un,2611 .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
2613 .int_type => |x| Hash.hash(seed + @intFromEnum(x.signedness), asBytes(&x.bits)),2618 .int_type => |x| Hash.hash(seed + @intFromEnum(x.signedness), asBytes(&x.bits)),
26142619