diff options
| author | mlugg <mlugg@mlugg.co.uk> | 2024-02-17 01:18:54 +0000 |
|---|---|---|
| committer | mlugg <mlugg@mlugg.co.uk> | 2024-03-06 21:26:37 +0000 |
| commit | 975b859377dee450418ae9ed572ec9d3c0b77312 (patch) | |
| tree | 08a86de7c929deb2a86deb5b587f35bb980ca500 /src/codegen/spirv.zig | |
| parent | a6ca20b9a1dfc7b6e8d004cb166c0714bb8db2db (diff) | |
| download | zig-975b859377dee450418ae9ed572ec9d3c0b77312.tar.gz zig-975b859377dee450418ae9ed572ec9d3c0b77312.zip | |
InternPool: create specialized functions for loading namespace types
Namespace types (`struct`, `enum`, `union`, `opaque`) do not use
structural equality - equivalence is based on their Decl index (and soon
will change to AST node + captures). However, we previously stored all
other information in the corresponding `InternPool.Key` anyway. For
logical consistency, it makes sense to have the key only be the true key
(that is, the Decl index) and to load all other data through another
function. This introduces those functions, by the name of
`loadStructType` etc. It's a big diff, but most of it is no-brainer
changes.
In future, it might be nice to eliminate a bunch of the loaded state in
favour of accessor functions on the `LoadedXyzType` types (like how we
have `LoadedUnionType.size()`), but that can be explored at a later
date.
Diffstat (limited to 'src/codegen/spirv.zig')
| -rw-r--r-- | src/codegen/spirv.zig | 20 |
1 files changed, 9 insertions, 11 deletions
diff --git a/src/codegen/spirv.zig b/src/codegen/spirv.zig index 59cbb9d2d3..e95ffee5c1 100644 --- a/src/codegen/spirv.zig +++ b/src/codegen/spirv.zig @@ -1528,7 +1528,7 @@ const DeclGen = struct { try self.type_map.put(self.gpa, ty.toIntern(), .{ .ty_ref = ty_ref }); return ty_ref; }, - .struct_type => |struct_type| struct_type, + .struct_type => ip.loadStructType(ty.toIntern()), else => unreachable, }; @@ -3633,7 +3633,8 @@ const DeclGen = struct { index += 1; } }, - .struct_type => |struct_type| { + .struct_type => { + const struct_type = ip.loadStructType(result_ty.toIntern()); var it = struct_type.iterateRuntimeOrder(ip); for (elements, 0..) |element, i| { const field_index = it.next().?; @@ -3901,36 +3902,33 @@ const DeclGen = struct { const mod = self.module; const ip = &mod.intern_pool; const union_ty = mod.typeToUnion(ty).?; + const tag_ty = Type.fromInterned(union_ty.enum_tag_ty); if (union_ty.getLayout(ip) == .Packed) { unreachable; // TODO } - const maybe_tag_ty = ty.unionTagTypeSafety(mod); const layout = self.unionLayout(ty); const tag_int = if (layout.tag_size != 0) blk: { - const tag_ty = maybe_tag_ty.?; - const union_field_name = union_ty.field_names.get(ip)[active_field]; - const enum_field_index = tag_ty.enumFieldIndex(union_field_name, mod).?; - const tag_val = try mod.enumValueFieldIndex(tag_ty, enum_field_index); + const tag_val = try mod.enumValueFieldIndex(tag_ty, active_field); const tag_int_val = try tag_val.intFromEnum(tag_ty, mod); break :blk tag_int_val.toUnsignedInt(mod); } else 0; if (!layout.has_payload) { - const tag_ty_ref = try self.resolveType(maybe_tag_ty.?, .direct); + const tag_ty_ref = try self.resolveType(tag_ty, .direct); return try self.constInt(tag_ty_ref, tag_int); } const tmp_id = try self.alloc(ty, .{ .storage_class = .Function }); if (layout.tag_size != 0) { - const tag_ty_ref = try self.resolveType(maybe_tag_ty.?, .direct); - const tag_ptr_ty_ref = try self.ptrType(maybe_tag_ty.?, .Function); + const tag_ty_ref = try self.resolveType(tag_ty, .direct); + const tag_ptr_ty_ref = try self.ptrType(tag_ty, .Function); const ptr_id = try self.accessChain(tag_ptr_ty_ref, tmp_id, &.{@as(u32, @intCast(layout.tag_index))}); const tag_id = try self.constInt(tag_ty_ref, tag_int); - try self.store(maybe_tag_ty.?, ptr_id, tag_id, .{}); + try self.store(tag_ty, ptr_id, tag_id, .{}); } const payload_ty = Type.fromInterned(union_ty.field_types.get(ip)[active_field]); |
