Skip to content

Commit 72c21dd

Browse files
committed
Hashes node, elements, types, and names for reified
1 parent 2989d07 commit 72c21dd

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

src/Sema/LowerZon.zig

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,10 @@ fn lowerExprAnonResTy(self: *LowerZon, node: Zoir.Node.Index) CompileError!Inter
127127
},
128128
.struct_literal => |init| {
129129
const elems = try self.sema.arena.alloc(InternPool.Index, init.names.len);
130+
const types = try self.sema.arena.alloc(InternPool.Index, init.names.len);
130131
for (0..init.names.len) |i| {
131132
elems[i] = try self.lowerExprAnonResTy(init.vals.at(@intCast(i)));
133+
types[i] = Value.fromInterned(elems[i]).typeOf(pt.zcu).toIntern();
132134
}
133135
const struct_ty = switch (try ip.getStructType(
134136
gpa,
@@ -144,7 +146,14 @@ fn lowerExprAnonResTy(self: *LowerZon, node: Zoir.Node.Index) CompileError!Inter
144146
.any_aligned_fields = false,
145147
.key = .{ .reified = .{
146148
.zir_index = self.base_node_inst,
147-
.type_hash = @intFromEnum(node),
149+
.type_hash = hash: {
150+
var hasher: std.hash.Wyhash = .init(0);
151+
hasher.update(std.mem.asBytes(&node));
152+
hasher.update(std.mem.sliceAsBytes(elems));
153+
hasher.update(std.mem.sliceAsBytes(types));
154+
hasher.update(std.mem.sliceAsBytes(init.names));
155+
break :hash hasher.final();
156+
},
148157
} },
149158
},
150159
false,
@@ -173,10 +182,7 @@ fn lowerExprAnonResTy(self: *LowerZon, node: Zoir.Node.Index) CompileError!Inter
173182
}
174183

175184
@memcpy(struct_type.field_inits.get(ip), elems);
176-
const types = struct_type.field_types.get(ip);
177-
for (0..init.names.len) |i| {
178-
types[i] = Value.fromInterned(elems[i]).typeOf(pt.zcu).toIntern();
179-
}
185+
@memcpy(struct_type.field_types.get(ip), types);
180186

181187
const new_namespace_index = try pt.createNamespace(.{
182188
.parent = self.block.namespace.toOptional(),

0 commit comments

Comments
 (0)