| ... | @@ -92,6 +92,14 @@ no_partial_func_ty: bool = false, | ... | @@ -92,6 +92,14 @@ no_partial_func_ty: bool = false, |
| 92 | /// here so the values can be dropped without any cleanup. | 92 | /// here so the values can be dropped without any cleanup. |
| 93 | unresolved_inferred_allocs: std.AutoHashMapUnmanaged(Air.Inst.Index, InferredAlloc) = .{}, | 93 | unresolved_inferred_allocs: std.AutoHashMapUnmanaged(Air.Inst.Index, InferredAlloc) = .{}, |
| 94 | | 94 | |
| | 95 | /// Indices of comptime-mutable decls created by this Sema. These decls' values |
| | 96 | /// should be interned after analysis completes, as they may refer to memory in |
| | 97 | /// the Sema arena. |
| | 98 | /// TODO: this is a workaround for memory bugs triggered by the removal of |
| | 99 | /// Decl.value_arena. A better solution needs to be found. Probably this will |
| | 100 | /// involve transitioning comptime-mutable memory away from using Decls at all. |
| | 101 | comptime_mutable_decls: *std.ArrayList(Decl.Index), |
| | 102 | |
| 95 | const std = @import("std"); | 103 | const std = @import("std"); |
| 96 | const math = std.math; | 104 | const math = std.math; |
| 97 | const mem = std.mem; | 105 | const mem = std.mem; |
| ... | @@ -2545,6 +2553,7 @@ fn zirCoerceResultPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE | ... | @@ -2545,6 +2553,7 @@ fn zirCoerceResultPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE |
| 2545 | }, | 2553 | }, |
| 2546 | }); | 2554 | }); |
| 2547 | try sema.maybeQueueFuncBodyAnalysis(decl_index); | 2555 | try sema.maybeQueueFuncBodyAnalysis(decl_index); |
| | 2556 | try sema.comptime_mutable_decls.append(decl_index); |
| 2548 | return sema.addConstant(ptr_ty, (try mod.intern(.{ .ptr = .{ | 2557 | return sema.addConstant(ptr_ty, (try mod.intern(.{ .ptr = .{ |
| 2549 | .ty = ptr_ty.toIntern(), | 2558 | .ty = ptr_ty.toIntern(), |
| 2550 | .addr = .{ .mut_decl = .{ | 2559 | .addr = .{ .mut_decl = .{ |
| ... | @@ -7761,6 +7770,7 @@ fn resolveGenericInstantiationType( | ... | @@ -7761,6 +7770,7 @@ fn resolveGenericInstantiationType( |
| 7761 | .is_generic_instantiation = true, | 7770 | .is_generic_instantiation = true, |
| 7762 | .branch_quota = sema.branch_quota, | 7771 | .branch_quota = sema.branch_quota, |
| 7763 | .branch_count = sema.branch_count, | 7772 | .branch_count = sema.branch_count, |
| | 7773 | .comptime_mutable_decls = sema.comptime_mutable_decls, |
| 7764 | }; | 7774 | }; |
| 7765 | defer child_sema.deinit(); | 7775 | defer child_sema.deinit(); |
| 7766 | | 7776 | |
| ... | @@ -31863,7 +31873,24 @@ fn semaBackingIntType(mod: *Module, struct_obj: *Module.Struct) CompileError!voi | ... | @@ -31863,7 +31873,24 @@ fn semaBackingIntType(mod: *Module, struct_obj: *Module.Struct) CompileError!voi |
| 31863 | var analysis_arena = std.heap.ArenaAllocator.init(gpa); | 31873 | var analysis_arena = std.heap.ArenaAllocator.init(gpa); |
| 31864 | defer analysis_arena.deinit(); | 31874 | defer analysis_arena.deinit(); |
| 31865 | | 31875 | |
| 31866 | var sema: Sema = .{ .mod = mod, .gpa = gpa, .arena = analysis_arena.allocator(), .perm_arena = decl_arena_allocator, .code = zir, .owner_decl = decl, .owner_decl_index = decl_index, .func = null, .func_index = .none, .fn_ret_ty = Type.void, .owner_func = null, .owner_func_index = .none }; | 31876 | var comptime_mutable_decls = std.ArrayList(Decl.Index).init(gpa); |
| | 31877 | defer comptime_mutable_decls.deinit(); |
| | 31878 | |
| | 31879 | var sema: Sema = .{ |
| | 31880 | .mod = mod, |
| | 31881 | .gpa = gpa, |
| | 31882 | .arena = analysis_arena.allocator(), |
| | 31883 | .perm_arena = decl_arena_allocator, |
| | 31884 | .code = zir, |
| | 31885 | .owner_decl = decl, |
| | 31886 | .owner_decl_index = decl_index, |
| | 31887 | .func = null, |
| | 31888 | .func_index = .none, |
| | 31889 | .fn_ret_ty = Type.void, |
| | 31890 | .owner_func = null, |
| | 31891 | .owner_func_index = .none, |
| | 31892 | .comptime_mutable_decls = &comptime_mutable_decls, |
| | 31893 | }; |
| 31867 | defer sema.deinit(); | 31894 | defer sema.deinit(); |
| 31868 | | 31895 | |
| 31869 | var wip_captures = try WipCaptureScope.init(gpa, decl.src_scope); | 31896 | var wip_captures = try WipCaptureScope.init(gpa, decl.src_scope); |
| ... | @@ -31899,6 +31926,10 @@ fn semaBackingIntType(mod: *Module, struct_obj: *Module.Struct) CompileError!voi | ... | @@ -31899,6 +31926,10 @@ fn semaBackingIntType(mod: *Module, struct_obj: *Module.Struct) CompileError!voi |
| 31899 | try sema.checkBackingIntType(&block, backing_int_src, backing_int_ty, fields_bit_sum); | 31926 | try sema.checkBackingIntType(&block, backing_int_src, backing_int_ty, fields_bit_sum); |
| 31900 | struct_obj.backing_int_ty = backing_int_ty; | 31927 | struct_obj.backing_int_ty = backing_int_ty; |
| 31901 | try wip_captures.finalize(); | 31928 | try wip_captures.finalize(); |
| | 31929 | for (comptime_mutable_decls.items) |ct_decl_index| { |
| | 31930 | const ct_decl = mod.declPtr(ct_decl_index); |
| | 31931 | try ct_decl.intern(mod); |
| | 31932 | } |
| 31902 | } else { | 31933 | } else { |
| 31903 | if (fields_bit_sum > std.math.maxInt(u16)) { | 31934 | if (fields_bit_sum > std.math.maxInt(u16)) { |
| 31904 | var sema: Sema = .{ | 31935 | var sema: Sema = .{ |
| ... | @@ -31914,6 +31945,7 @@ fn semaBackingIntType(mod: *Module, struct_obj: *Module.Struct) CompileError!voi | ... | @@ -31914,6 +31945,7 @@ fn semaBackingIntType(mod: *Module, struct_obj: *Module.Struct) CompileError!voi |
| 31914 | .fn_ret_ty = Type.void, | 31945 | .fn_ret_ty = Type.void, |
| 31915 | .owner_func = null, | 31946 | .owner_func = null, |
| 31916 | .owner_func_index = .none, | 31947 | .owner_func_index = .none, |
| | 31948 | .comptime_mutable_decls = undefined, |
| 31917 | }; | 31949 | }; |
| 31918 | defer sema.deinit(); | 31950 | defer sema.deinit(); |
| 31919 | | 31951 | |
| ... | @@ -32603,6 +32635,9 @@ fn semaStructFields(mod: *Module, struct_obj: *Module.Struct) CompileError!void | ... | @@ -32603,6 +32635,9 @@ fn semaStructFields(mod: *Module, struct_obj: *Module.Struct) CompileError!void |
| 32603 | var analysis_arena = std.heap.ArenaAllocator.init(gpa); | 32635 | var analysis_arena = std.heap.ArenaAllocator.init(gpa); |
| 32604 | defer analysis_arena.deinit(); | 32636 | defer analysis_arena.deinit(); |
| 32605 | | 32637 | |
| | 32638 | var comptime_mutable_decls = std.ArrayList(Decl.Index).init(gpa); |
| | 32639 | defer comptime_mutable_decls.deinit(); |
| | 32640 | |
| 32606 | var sema: Sema = .{ | 32641 | var sema: Sema = .{ |
| 32607 | .mod = mod, | 32642 | .mod = mod, |
| 32608 | .gpa = gpa, | 32643 | .gpa = gpa, |
| ... | @@ -32616,6 +32651,7 @@ fn semaStructFields(mod: *Module, struct_obj: *Module.Struct) CompileError!void | ... | @@ -32616,6 +32651,7 @@ fn semaStructFields(mod: *Module, struct_obj: *Module.Struct) CompileError!void |
| 32616 | .fn_ret_ty = Type.void, | 32651 | .fn_ret_ty = Type.void, |
| 32617 | .owner_func = null, | 32652 | .owner_func = null, |
| 32618 | .owner_func_index = .none, | 32653 | .owner_func_index = .none, |
| | 32654 | .comptime_mutable_decls = &comptime_mutable_decls, |
| 32619 | }; | 32655 | }; |
| 32620 | defer sema.deinit(); | 32656 | defer sema.deinit(); |
| 32621 | | 32657 | |
| ... | @@ -32886,6 +32922,10 @@ fn semaStructFields(mod: *Module, struct_obj: *Module.Struct) CompileError!void | ... | @@ -32886,6 +32922,10 @@ fn semaStructFields(mod: *Module, struct_obj: *Module.Struct) CompileError!void |
| 32886 | } | 32922 | } |
| 32887 | } | 32923 | } |
| 32888 | try wip_captures.finalize(); | 32924 | try wip_captures.finalize(); |
| | 32925 | for (comptime_mutable_decls.items) |ct_decl_index| { |
| | 32926 | const ct_decl = mod.declPtr(ct_decl_index); |
| | 32927 | try ct_decl.intern(mod); |
| | 32928 | } |
| 32889 | | 32929 | |
| 32890 | struct_obj.have_field_inits = true; | 32930 | struct_obj.have_field_inits = true; |
| 32891 | } | 32931 | } |
| ... | @@ -32945,6 +32985,9 @@ fn semaUnionFields(mod: *Module, union_obj: *Module.Union) CompileError!void { | ... | @@ -32945,6 +32985,9 @@ fn semaUnionFields(mod: *Module, union_obj: *Module.Union) CompileError!void { |
| 32945 | var analysis_arena = std.heap.ArenaAllocator.init(gpa); | 32985 | var analysis_arena = std.heap.ArenaAllocator.init(gpa); |
| 32946 | defer analysis_arena.deinit(); | 32986 | defer analysis_arena.deinit(); |
| 32947 | | 32987 | |
| | 32988 | var comptime_mutable_decls = std.ArrayList(Decl.Index).init(gpa); |
| | 32989 | defer comptime_mutable_decls.deinit(); |
| | 32990 | |
| 32948 | var sema: Sema = .{ | 32991 | var sema: Sema = .{ |
| 32949 | .mod = mod, | 32992 | .mod = mod, |
| 32950 | .gpa = gpa, | 32993 | .gpa = gpa, |
| ... | @@ -32958,6 +33001,7 @@ fn semaUnionFields(mod: *Module, union_obj: *Module.Union) CompileError!void { | ... | @@ -32958,6 +33001,7 @@ fn semaUnionFields(mod: *Module, union_obj: *Module.Union) CompileError!void { |
| 32958 | .fn_ret_ty = Type.void, | 33001 | .fn_ret_ty = Type.void, |
| 32959 | .owner_func = null, | 33002 | .owner_func = null, |
| 32960 | .owner_func_index = .none, | 33003 | .owner_func_index = .none, |
| | 33004 | .comptime_mutable_decls = &comptime_mutable_decls, |
| 32961 | }; | 33005 | }; |
| 32962 | defer sema.deinit(); | 33006 | defer sema.deinit(); |
| 32963 | | 33007 | |
| ... | @@ -32984,6 +33028,10 @@ fn semaUnionFields(mod: *Module, union_obj: *Module.Union) CompileError!void { | ... | @@ -32984,6 +33028,10 @@ fn semaUnionFields(mod: *Module, union_obj: *Module.Union) CompileError!void { |
| 32984 | } | 33028 | } |
| 32985 | | 33029 | |
| 32986 | try wip_captures.finalize(); | 33030 | try wip_captures.finalize(); |
| | 33031 | for (comptime_mutable_decls.items) |ct_decl_index| { |
| | 33032 | const ct_decl = mod.declPtr(ct_decl_index); |
| | 33033 | try ct_decl.intern(mod); |
| | 33034 | } |
| 32987 | | 33035 | |
| 32988 | try union_obj.fields.ensureTotalCapacity(decl_arena_allocator, fields_len); | 33036 | try union_obj.fields.ensureTotalCapacity(decl_arena_allocator, fields_len); |
| 32989 | | 33037 | |
| ... | @@ -33821,6 +33869,7 @@ fn analyzeComptimeAlloc( | ... | @@ -33821,6 +33869,7 @@ fn analyzeComptimeAlloc( |
| 33821 | const decl = sema.mod.declPtr(decl_index); | 33869 | const decl = sema.mod.declPtr(decl_index); |
| 33822 | decl.@"align" = alignment; | 33870 | decl.@"align" = alignment; |
| 33823 | | 33871 | |
| | 33872 | try sema.comptime_mutable_decls.append(decl_index); |
| 33824 | try sema.mod.declareDeclDependency(sema.owner_decl_index, decl_index); | 33873 | try sema.mod.declareDeclDependency(sema.owner_decl_index, decl_index); |
| 33825 | return sema.addConstant(ptr_type, (try sema.mod.intern(.{ .ptr = .{ | 33874 | return sema.addConstant(ptr_type, (try sema.mod.intern(.{ .ptr = .{ |
| 33826 | .ty = ptr_type.toIntern(), | 33875 | .ty = ptr_type.toIntern(), |