authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-05-05 18:34:05-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-06-10 20:42:28-07:00
log3e6dd0da7a9aae1e6e3d3e0d897a2b3a28bfc043
tree553b6f64983871e8483228d008aa540498c334c5
parentce3cffbd5a00a6ae44ec3f2c6550de1c52c293c4

stage2: add tmp_hack_arena for the InternPool transition

Temporarily used for some unfortunate allocations made by backends that need to construct pointer types that can't be represented by the InternPool. Once all types are migrated to be stored in the InternPool, this can be removed.

3 files changed, 22 insertions(+), 0 deletions(-)

src/Compilation.zig+1
......@@ -1316,6 +1316,7 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {
13161316 .local_zir_cache = local_zir_cache,
13171317 .emit_h = emit_h,
13181318 .error_name_list = .{},
1319 .tmp_hack_arena = std.heap.ArenaAllocator.init(gpa),
13191320 };
13201321 try module.init();
13211322
src/InternPool.zig+1
......@@ -1040,6 +1040,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {
10401040 });
10411041 },
10421042 .ptr_type => |ptr_type| {
1043 assert(ptr_type.elem_type != .none);
10431044 // TODO introduce more pointer encodings
10441045 ip.items.appendAssumeCapacity(.{
10451046 .tag = .type_pointer,
src/Module.zig+20
......@@ -98,6 +98,10 @@ string_literal_bytes: ArrayListUnmanaged(u8) = .{},
9898
9999/// Stores all Type and Value objects; periodically garbage collected.
100100intern_pool: InternPool = .{},
101/// Temporarily used for some unfortunate allocations made by backends that need to construct
102/// pointer types that can't be represented by the InternPool. Once all types are migrated
103/// to be stored in the InternPool, this can be removed.
104tmp_hack_arena: std.heap.ArenaAllocator,
101105
102106/// The set of all the generic function instantiations. This is used so that when a generic
103107/// function is called twice with the same comptime parameter arguments, both calls dispatch
......@@ -3552,6 +3556,7 @@ pub fn deinit(mod: *Module) void {
35523556 mod.string_literal_bytes.deinit(gpa);
35533557
35543558 mod.intern_pool.deinit(gpa);
3559 mod.tmp_hack_arena.deinit();
35553560}
35563561
35573562pub fn destroyDecl(mod: *Module, decl_index: Decl.Index) void {
......@@ -6848,10 +6853,25 @@ pub fn ptrType(mod: *Module, info: InternPool.Key.PtrType) Allocator.Error!Type
68486853}
68496854
68506855pub fn singleMutPtrType(mod: *Module, child_type: Type) Allocator.Error!Type {
6856 if (child_type.ip_index == .none) {
6857 // TODO remove this after all types can be represented via the InternPool
6858 return Type.Tag.pointer.create(mod.tmp_hack_arena.allocator(), .{
6859 .pointee_type = child_type,
6860 .@"addrspace" = .generic,
6861 });
6862 }
68516863 return ptrType(mod, .{ .elem_type = child_type.ip_index });
68526864}
68536865
68546866pub fn singleConstPtrType(mod: *Module, child_type: Type) Allocator.Error!Type {
6867 if (child_type.ip_index == .none) {
6868 // TODO remove this after all types can be represented via the InternPool
6869 return Type.Tag.pointer.create(mod.tmp_hack_arena.allocator(), .{
6870 .pointee_type = child_type,
6871 .mutable = false,
6872 .@"addrspace" = .generic,
6873 });
6874 }
68556875 return ptrType(mod, .{ .elem_type = child_type.ip_index, .is_const = true });
68566876}
68576877