| author | |
| committer | |
| log | 5826a8a0640d79de83be131434ec91315e75087b |
| tree | 662d00213cd9b993e2a56dab7675db725d49ace3 |
| parent | a60308f87c658a210e9b3bd619e908368db6f24e |
| signature |
Making Type.Ref an unbounded enum rather than a simple integer
ensures that we don't accidently confuse this token for another type.3 files changed, 5 insertions(+), 5 deletions(-)
src/codegen/spirv/Assembler.zig+1-1| ... | ... | @@ -753,7 +753,7 @@ fn parseContextDependentNumber(self: *Assembler) !void { |
| 753 | 753 | |
| 754 | 754 | const tok = self.currentToken(); |
| 755 | 755 | const result_type_ref = try self.resolveTypeRef(self.inst.operands.items[0].ref_id); |
| 756 | const result_type = self.spv.type_cache.keys()[result_type_ref]; | |
| 756 | const result_type = self.spv.type_cache.keys()[@enumToInt(result_type_ref)]; | |
| 757 | 757 | switch (result_type.tag()) { |
| 758 | 758 | .int => { |
| 759 | 759 | const int = result_type.castTag(.int).?; |
src/codegen/spirv/Module.zig+3-3| ... | ... | @@ -216,7 +216,7 @@ pub fn resolveType(self: *Module, ty: Type) !Type.Ref { |
| 216 | 216 | result.value_ptr.* = try self.emitType(ty); |
| 217 | 217 | } |
| 218 | 218 | |
| 219 | return result.index; | |
| 219 | return @intToEnum(Type.Ref, result.index); | |
| 220 | 220 | } |
| 221 | 221 | |
| 222 | 222 | pub fn resolveTypeId(self: *Module, ty: Type) !IdRef { |
| ... | ... | @@ -226,12 +226,12 @@ pub fn resolveTypeId(self: *Module, ty: Type) !IdRef { |
| 226 | 226 | |
| 227 | 227 | /// Get the result-id of a particular type, by reference. Asserts type_ref is valid. |
| 228 | 228 | pub fn typeResultId(self: Module, type_ref: Type.Ref) IdResultType { |
| 229 | return self.type_cache.values()[type_ref]; | |
| 229 | return self.type_cache.values()[@enumToInt(type_ref)]; | |
| 230 | 230 | } |
| 231 | 231 | |
| 232 | 232 | /// Get the result-id of a particular type as IdRef, by Type.Ref. Asserts type_ref is valid. |
| 233 | 233 | pub fn typeRefId(self: Module, type_ref: Type.Ref) IdRef { |
| 234 | return self.type_cache.values()[type_ref].toRef(); | |
| 234 | return self.type_cache.values()[@enumToInt(type_ref)].toRef(); | |
| 235 | 235 | } |
| 236 | 236 | |
| 237 | 237 | /// Unconditionally emit a spir-v type into the appropriate section. |
src/codegen/spirv/type.zig+1-1| ... | ... | @@ -11,7 +11,7 @@ pub const Type = extern union { |
| 11 | 11 | ptr_otherwise: *Payload, |
| 12 | 12 | |
| 13 | 13 | /// A reference to another SPIR-V type. |
| 14 | pub const Ref = usize; | |
| 14 | pub const Ref = enum(u32) { _ }; | |
| 15 | 15 | |
| 16 | 16 | pub fn initTag(comptime small_tag: Tag) Type { |
| 17 | 17 | comptime assert(@enumToInt(small_tag) < Tag.no_payload_count); |