authorgravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2023-05-31 20:24:12-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-06-10 20:47:58-07:00
log08ae212772c38d6149464274edc07282e5418570
tree8684d87abdcc9b7f722830e0d3d93faa877aeffb
parentc82a04d35f529c7dc8301059a0fe0b204f111145

InternPool: fix key for empty array with sentinel


1 files changed, 14 insertions(+), 6 deletions(-)

src/InternPool.zig+14-6
......@@ -2899,7 +2899,17 @@ pub fn indexToKey(ip: *const InternPool, index: Index) Key {
28992899 const ty = @intToEnum(Index, data);
29002900 const ty_item = ip.items.get(@enumToInt(ty));
29012901 return switch (ty_item.tag) {
2902 .type_array_big, .type_array_small, .type_vector => .{ .aggregate = .{
2902 .type_array_big => {
2903 const sentinel = @ptrCast(
2904 *const [1]Index,
2905 &ip.extra.items[ty_item.data + std.meta.fieldIndex(Array, "sentinel").?],
2906 );
2907 return .{ .aggregate = .{
2908 .ty = ty,
2909 .storage = .{ .elems = sentinel[0..@boolToInt(sentinel[0] != .none)] },
2910 } };
2911 },
2912 .type_array_small, .type_vector => .{ .aggregate = .{
29032913 .ty = ty,
29042914 .storage = .{ .elems = &.{} },
29052915 } },
......@@ -4799,11 +4809,9 @@ pub fn isAggregateType(ip: *const InternPool, ty: Index) bool {
47994809
48004810/// The is only legal because the initializer is not part of the hash.
48014811pub fn mutateVarInit(ip: *InternPool, index: Index, init_index: Index) void {
4802 assert(ip.items.items(.tag)[@enumToInt(index)] == .variable);
4803 const field_index = inline for (@typeInfo(Tag.Variable).Struct.fields, 0..) |field, field_index| {
4804 if (comptime std.mem.eql(u8, field.name, "init")) break field_index;
4805 } else unreachable;
4806 ip.extra.items[ip.items.items(.data)[@enumToInt(index)] + field_index] = @enumToInt(init_index);
4812 const item = ip.items.get(@enumToInt(index));
4813 assert(item.tag == .variable);
4814 ip.extra.items[item.data + std.meta.fieldIndex(Tag.Variable, "init").?] = @enumToInt(init_index);
48074815}
48084816
48094817pub fn dump(ip: *const InternPool) void {