authorgravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2023-05-21 00:43:19-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-06-10 20:47:54-07:00
log9584feae5f27a8b987975d8fe8242e2169098a75
treec0803dbd82b6a7c7be41042cae75447b837ba16b
parentdfd91abfe15e653cba7b61fef73340ea07c6e3e9

InternPool: fix logic bugs


1 files changed, 8 insertions(+), 1 deletions(-)

src/InternPool.zig+8-1
......@@ -2415,9 +2415,11 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {
24152415 assert(ptr_type.elem_type != .none);
24162416
24172417 if (ptr_type.size == .Slice) {
2418 _ = ip.map.pop();
24182419 var new_key = key;
24192420 new_key.ptr_type.size = .Many;
24202421 const ptr_type_index = try get(ip, gpa, new_key);
2422 assert(!(try ip.map.getOrPutAdapted(gpa, key, adapter)).found_existing);
24212423 try ip.items.ensureUnusedCapacity(gpa, 1);
24222424 ip.items.appendAssumeCapacity(.{
24232425 .tag = .type_slice,
......@@ -2737,10 +2739,12 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {
27372739 }),
27382740 }),
27392741 .elem, .field => |base_index| {
2742 _ = ip.map.pop();
27402743 const index_index = try get(ip, gpa, .{ .int = .{
27412744 .ty = .usize_type,
27422745 .storage = .{ .u64 = base_index.index },
27432746 } });
2747 assert(!(try ip.map.getOrPutAdapted(gpa, key, adapter)).found_existing);
27442748 try ip.items.ensureUnusedCapacity(gpa, 1);
27452749 ip.items.appendAssumeCapacity(.{
27462750 .tag = .ptr_elem,
......@@ -2755,11 +2759,13 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {
27552759 },
27562760 else => {
27572761 assert(ptr_type.size == .Slice);
2762 _ = ip.map.pop();
27582763 var new_key = key;
27592764 new_key.ptr.ty = ip.slicePtrType(ptr.ty);
27602765 new_key.ptr.len = .none;
27612766 assert(ip.indexToKey(new_key.ptr.ty).ptr_type.size == .Many);
27622767 const ptr_index = try get(ip, gpa, new_key);
2768 assert(!(try ip.map.getOrPutAdapted(gpa, key, adapter)).found_existing);
27632769 try ip.items.ensureUnusedCapacity(gpa, 1);
27642770 ip.items.appendAssumeCapacity(.{
27652771 .tag = .ptr_slice,
......@@ -3148,7 +3154,6 @@ pub fn getIncompleteEnum(
31483154 gpa: Allocator,
31493155 enum_type: Key.IncompleteEnumType,
31503156) Allocator.Error!InternPool.IncompleteEnumType {
3151 try ip.items.ensureUnusedCapacity(gpa, 1);
31523157 switch (enum_type.tag_mode) {
31533158 .auto => return getIncompleteEnumAuto(ip, gpa, enum_type),
31543159 .explicit => return getIncompleteEnumExplicit(ip, gpa, enum_type, .type_enum_explicit),
......@@ -3180,6 +3185,7 @@ pub fn getIncompleteEnumAuto(
31803185
31813186 const extra_fields_len: u32 = @typeInfo(EnumAuto).Struct.fields.len;
31823187 try ip.extra.ensureUnusedCapacity(gpa, extra_fields_len + enum_type.fields_len);
3188 try ip.items.ensureUnusedCapacity(gpa, 1);
31833189
31843190 const extra_index = ip.addExtraAssumeCapacity(EnumAuto{
31853191 .decl = enum_type.decl,
......@@ -3227,6 +3233,7 @@ fn getIncompleteEnumExplicit(
32273233
32283234 const extra_fields_len: u32 = @typeInfo(EnumExplicit).Struct.fields.len;
32293235 try ip.extra.ensureUnusedCapacity(gpa, extra_fields_len + reserved_len);
3236 try ip.items.ensureUnusedCapacity(gpa, 1);
32303237
32313238 const extra_index = ip.addExtraAssumeCapacity(EnumExplicit{
32323239 .decl = enum_type.decl,