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 {...@@ -1316,6 +1316,7 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {
1316 .local_zir_cache = local_zir_cache,1316 .local_zir_cache = local_zir_cache,
1317 .emit_h = emit_h,1317 .emit_h = emit_h,
1318 .error_name_list = .{},1318 .error_name_list = .{},
1319 .tmp_hack_arena = std.heap.ArenaAllocator.init(gpa),
1319 };1320 };
1320 try module.init();1321 try module.init();
13211322
src/InternPool.zig+1
...@@ -1040,6 +1040,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {...@@ -1040,6 +1040,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {
1040 });1040 });
1041 },1041 },
1042 .ptr_type => |ptr_type| {1042 .ptr_type => |ptr_type| {
1043 assert(ptr_type.elem_type != .none);
1043 // TODO introduce more pointer encodings1044 // TODO introduce more pointer encodings
1044 ip.items.appendAssumeCapacity(.{1045 ip.items.appendAssumeCapacity(.{
1045 .tag = .type_pointer,1046 .tag = .type_pointer,
src/Module.zig+20
...@@ -98,6 +98,10 @@ string_literal_bytes: ArrayListUnmanaged(u8) = .{},...@@ -98,6 +98,10 @@ string_literal_bytes: ArrayListUnmanaged(u8) = .{},
9898
99/// Stores all Type and Value objects; periodically garbage collected.99/// Stores all Type and Value objects; periodically garbage collected.
100intern_pool: InternPool = .{},100intern_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
102/// The set of all the generic function instantiations. This is used so that when a generic106/// The set of all the generic function instantiations. This is used so that when a generic
103/// function is called twice with the same comptime parameter arguments, both calls dispatch107/// function is called twice with the same comptime parameter arguments, both calls dispatch
...@@ -3552,6 +3556,7 @@ pub fn deinit(mod: *Module) void {...@@ -3552,6 +3556,7 @@ pub fn deinit(mod: *Module) void {
3552 mod.string_literal_bytes.deinit(gpa);3556 mod.string_literal_bytes.deinit(gpa);
35533557
3554 mod.intern_pool.deinit(gpa);3558 mod.intern_pool.deinit(gpa);
3559 mod.tmp_hack_arena.deinit();
3555}3560}
35563561
3557pub fn destroyDecl(mod: *Module, decl_index: Decl.Index) void {3562pub 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...@@ -6848,10 +6853,25 @@ pub fn ptrType(mod: *Module, info: InternPool.Key.PtrType) Allocator.Error!Type
6848}6853}
68496854
6850pub fn singleMutPtrType(mod: *Module, child_type: Type) Allocator.Error!Type {6855pub 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 }
6851 return ptrType(mod, .{ .elem_type = child_type.ip_index });6863 return ptrType(mod, .{ .elem_type = child_type.ip_index });
6852}6864}
68536865
6854pub fn singleConstPtrType(mod: *Module, child_type: Type) Allocator.Error!Type {6866pub 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 }
6855 return ptrType(mod, .{ .elem_type = child_type.ip_index, .is_const = true });6875 return ptrType(mod, .{ .elem_type = child_type.ip_index, .is_const = true });
6856}6876}
68576877