authorgravatar for robin@voetter.nlRobin Voetter <robin@voetter.nl> 2022-11-26 01:05:37+01:00
committergravatar for robin@voetter.nlRobin Voetter <robin@voetter.nl> 2023-04-09 01:51:48+02:00
log5826a8a0640d79de83be131434ec91315e75087b
tree662d00213cd9b993e2a56dab7675db725d49ace3
parenta60308f87c658a210e9b3bd619e908368db6f24e
signaturelock-open Commit is signed but in an unrecognized format.

spirv: make Type.Ref stronger

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 {
753753
754754 const tok = self.currentToken();
755755 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)];
757757 switch (result_type.tag()) {
758758 .int => {
759759 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 {
216216 result.value_ptr.* = try self.emitType(ty);
217217 }
218218
219 return result.index;
219 return @intToEnum(Type.Ref, result.index);
220220}
221221
222222pub fn resolveTypeId(self: *Module, ty: Type) !IdRef {
......@@ -226,12 +226,12 @@ pub fn resolveTypeId(self: *Module, ty: Type) !IdRef {
226226
227227/// Get the result-id of a particular type, by reference. Asserts type_ref is valid.
228228pub 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)];
230230}
231231
232232/// Get the result-id of a particular type as IdRef, by Type.Ref. Asserts type_ref is valid.
233233pub 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();
235235}
236236
237237/// 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 {
1111 ptr_otherwise: *Payload,
1212
1313 /// A reference to another SPIR-V type.
14 pub const Ref = usize;
14 pub const Ref = enum(u32) { _ };
1515
1616 pub fn initTag(comptime small_tag: Tag) Type {
1717 comptime assert(@enumToInt(small_tag) < Tag.no_payload_count);