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 {...@@ -2415,9 +2415,11 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {
2415 assert(ptr_type.elem_type != .none);2415 assert(ptr_type.elem_type != .none);
24162416
2417 if (ptr_type.size == .Slice) {2417 if (ptr_type.size == .Slice) {
2418 _ = ip.map.pop();
2418 var new_key = key;2419 var new_key = key;
2419 new_key.ptr_type.size = .Many;2420 new_key.ptr_type.size = .Many;
2420 const ptr_type_index = try get(ip, gpa, new_key);2421 const ptr_type_index = try get(ip, gpa, new_key);
2422 assert(!(try ip.map.getOrPutAdapted(gpa, key, adapter)).found_existing);
2421 try ip.items.ensureUnusedCapacity(gpa, 1);2423 try ip.items.ensureUnusedCapacity(gpa, 1);
2422 ip.items.appendAssumeCapacity(.{2424 ip.items.appendAssumeCapacity(.{
2423 .tag = .type_slice,2425 .tag = .type_slice,
...@@ -2737,10 +2739,12 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {...@@ -2737,10 +2739,12 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {
2737 }),2739 }),
2738 }),2740 }),
2739 .elem, .field => |base_index| {2741 .elem, .field => |base_index| {
2742 _ = ip.map.pop();
2740 const index_index = try get(ip, gpa, .{ .int = .{2743 const index_index = try get(ip, gpa, .{ .int = .{
2741 .ty = .usize_type,2744 .ty = .usize_type,
2742 .storage = .{ .u64 = base_index.index },2745 .storage = .{ .u64 = base_index.index },
2743 } });2746 } });
2747 assert(!(try ip.map.getOrPutAdapted(gpa, key, adapter)).found_existing);
2744 try ip.items.ensureUnusedCapacity(gpa, 1);2748 try ip.items.ensureUnusedCapacity(gpa, 1);
2745 ip.items.appendAssumeCapacity(.{2749 ip.items.appendAssumeCapacity(.{
2746 .tag = .ptr_elem,2750 .tag = .ptr_elem,
...@@ -2755,11 +2759,13 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {...@@ -2755,11 +2759,13 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {
2755 },2759 },
2756 else => {2760 else => {
2757 assert(ptr_type.size == .Slice);2761 assert(ptr_type.size == .Slice);
2762 _ = ip.map.pop();
2758 var new_key = key;2763 var new_key = key;
2759 new_key.ptr.ty = ip.slicePtrType(ptr.ty);2764 new_key.ptr.ty = ip.slicePtrType(ptr.ty);
2760 new_key.ptr.len = .none;2765 new_key.ptr.len = .none;
2761 assert(ip.indexToKey(new_key.ptr.ty).ptr_type.size == .Many);2766 assert(ip.indexToKey(new_key.ptr.ty).ptr_type.size == .Many);
2762 const ptr_index = try get(ip, gpa, new_key);2767 const ptr_index = try get(ip, gpa, new_key);
2768 assert(!(try ip.map.getOrPutAdapted(gpa, key, adapter)).found_existing);
2763 try ip.items.ensureUnusedCapacity(gpa, 1);2769 try ip.items.ensureUnusedCapacity(gpa, 1);
2764 ip.items.appendAssumeCapacity(.{2770 ip.items.appendAssumeCapacity(.{
2765 .tag = .ptr_slice,2771 .tag = .ptr_slice,
...@@ -3148,7 +3154,6 @@ pub fn getIncompleteEnum(...@@ -3148,7 +3154,6 @@ pub fn getIncompleteEnum(
3148 gpa: Allocator,3154 gpa: Allocator,
3149 enum_type: Key.IncompleteEnumType,3155 enum_type: Key.IncompleteEnumType,
3150) Allocator.Error!InternPool.IncompleteEnumType {3156) Allocator.Error!InternPool.IncompleteEnumType {
3151 try ip.items.ensureUnusedCapacity(gpa, 1);
3152 switch (enum_type.tag_mode) {3157 switch (enum_type.tag_mode) {
3153 .auto => return getIncompleteEnumAuto(ip, gpa, enum_type),3158 .auto => return getIncompleteEnumAuto(ip, gpa, enum_type),
3154 .explicit => return getIncompleteEnumExplicit(ip, gpa, enum_type, .type_enum_explicit),3159 .explicit => return getIncompleteEnumExplicit(ip, gpa, enum_type, .type_enum_explicit),
...@@ -3180,6 +3185,7 @@ pub fn getIncompleteEnumAuto(...@@ -3180,6 +3185,7 @@ pub fn getIncompleteEnumAuto(
31803185
3181 const extra_fields_len: u32 = @typeInfo(EnumAuto).Struct.fields.len;3186 const extra_fields_len: u32 = @typeInfo(EnumAuto).Struct.fields.len;
3182 try ip.extra.ensureUnusedCapacity(gpa, extra_fields_len + enum_type.fields_len);3187 try ip.extra.ensureUnusedCapacity(gpa, extra_fields_len + enum_type.fields_len);
3188 try ip.items.ensureUnusedCapacity(gpa, 1);
31833189
3184 const extra_index = ip.addExtraAssumeCapacity(EnumAuto{3190 const extra_index = ip.addExtraAssumeCapacity(EnumAuto{
3185 .decl = enum_type.decl,3191 .decl = enum_type.decl,
...@@ -3227,6 +3233,7 @@ fn getIncompleteEnumExplicit(...@@ -3227,6 +3233,7 @@ fn getIncompleteEnumExplicit(
32273233
3228 const extra_fields_len: u32 = @typeInfo(EnumExplicit).Struct.fields.len;3234 const extra_fields_len: u32 = @typeInfo(EnumExplicit).Struct.fields.len;
3229 try ip.extra.ensureUnusedCapacity(gpa, extra_fields_len + reserved_len);3235 try ip.extra.ensureUnusedCapacity(gpa, extra_fields_len + reserved_len);
3236 try ip.items.ensureUnusedCapacity(gpa, 1);
32303237
3231 const extra_index = ip.addExtraAssumeCapacity(EnumExplicit{3238 const extra_index = ip.addExtraAssumeCapacity(EnumExplicit{
3232 .decl = enum_type.decl,3239 .decl = enum_type.decl,