authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-09-14 19:59:58-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-09-15 00:55:07-07:00
log8592c5cdac41e4e04034e4f9a0fd8cb51e8c4257
treec7c69a498e603d5038c23ca1f925be53788b672d
parent4f952c7e0e36dab15f9359f55eb8714f8fe92bcf

compiler: rework capture scopes in-memory layout

* Use 32-bit integers instead of pointers for compactness and serialization friendliness. * Use a separate hash map for runtime and comptime capture scopes, avoiding the 1-bit union tag. * Use a compact array representation instead of a tree of hash maps. * Eliminate the only instance of ref-counting in the compiler, instead relying on garbage collection (not implemented yet but is the plan for almost all long-lived objects related to incremental compilation). Because a code modification may need to access capture scope data, this makes capture scope data long-lived state. My goal is to get incremental compilation state serialization down to a single pwritev syscall, by unifying the on-disk representation with the in-memory representation. This commit eliminates the last remaining pointer field of `Module.Decl`.

2 files changed, 97 insertions(+), 228 deletions(-)

src/Module.zig+37-94
...@@ -92,6 +92,17 @@ embed_table: std.StringHashMapUnmanaged(*EmbedFile) = .{},...@@ -92,6 +92,17 @@ embed_table: std.StringHashMapUnmanaged(*EmbedFile) = .{},
92/// is not yet implemented.92/// is not yet implemented.
93intern_pool: InternPool = .{},93intern_pool: InternPool = .{},
9494
95/// The index type for this array is `CaptureScope.Index` and the elements here are
96/// the indexes of the parent capture scopes.
97/// Memory is owned by gpa; garbage collected.
98capture_scope_parents: std.ArrayListUnmanaged(CaptureScope.Index) = .{},
99/// Value is index of type
100/// Memory is owned by gpa; garbage collected.
101runtime_capture_scopes: std.AutoArrayHashMapUnmanaged(CaptureScope.Key, InternPool.Index) = .{},
102/// Value is index of value
103/// Memory is owned by gpa; garbage collected.
104comptime_capture_scopes: std.AutoArrayHashMapUnmanaged(CaptureScope.Key, InternPool.Index) = .{},
105
95/// To be eliminated in a future commit by moving more data into InternPool.106/// To be eliminated in a future commit by moving more data into InternPool.
96/// Current uses that must be eliminated:107/// Current uses that must be eliminated:
97/// * Struct comptime_args108/// * Struct comptime_args
...@@ -272,83 +283,26 @@ pub const Export = struct {...@@ -272,83 +283,26 @@ pub const Export = struct {
272};283};
273284
274pub const CaptureScope = struct {285pub const CaptureScope = struct {
275 refs: u32,286 pub const Key = extern struct {
276 parent: ?*CaptureScope,287 zir_index: Zir.Inst.Index,
277288 index: Index,
278 /// Values from this decl's evaluation that will be closed over in
279 /// child decls. This map is backed by the gpa, and deinited when
280 /// the refcount reaches 0.
281 captures: std.AutoHashMapUnmanaged(Zir.Inst.Index, Capture) = .{},
282
283 pub const Capture = union(enum) {
284 comptime_val: InternPool.Index, // index of value
285 runtime_val: InternPool.Index, // index of type
286 };289 };
287290
288 pub fn failed(noalias self: *const CaptureScope) bool {291 /// Index into `capture_scope_parents` which uniquely identifies a capture scope.
289 return self.captures.available == 0 and self.captures.size == std.math.maxInt(u32);292 pub const Index = enum(u32) {
290 }293 none = std.math.maxInt(u32),
291294 _,
292 pub fn fail(noalias self: *CaptureScope, gpa: Allocator) void {
293 self.captures.deinit(gpa);
294 self.captures.available = 0;
295 self.captures.size = std.math.maxInt(u32);
296 }
297
298 pub fn incRef(self: *CaptureScope) void {
299 // TODO: wtf is reference counting doing in my beautiful codebase? 😠
300 // seriously though, let's change this to rely on InternPool garbage
301 // collection instead.
302 self.refs += 1;
303 }
304295
305 pub fn decRef(self: *CaptureScope, gpa: Allocator) void {296 pub fn parent(i: Index, mod: *Module) Index {
306 self.refs -= 1;297 return mod.capture_scope_parents.items[@intFromEnum(i)];
307 if (self.refs > 0) return;
308 if (self.parent) |p| p.decRef(gpa);
309 if (!self.failed()) {
310 self.captures.deinit(gpa);
311 }298 }
312 gpa.destroy(self);299 };
313 }
314};300};
315301
316pub const WipCaptureScope = struct {302pub fn createCaptureScope(mod: *Module, parent: CaptureScope.Index) error{OutOfMemory}!CaptureScope.Index {
317 scope: *CaptureScope,303 try mod.capture_scope_parents.append(mod.gpa, parent);
318 finalized: bool,304 return @enumFromInt(mod.capture_scope_parents.items.len - 1);
319 gpa: Allocator,305}
320
321 pub fn init(gpa: Allocator, parent: ?*CaptureScope) !WipCaptureScope {
322 const scope = try gpa.create(CaptureScope);
323 if (parent) |p| p.incRef();
324 scope.* = .{ .refs = 1, .parent = parent };
325 return .{
326 .scope = scope,
327 .finalized = false,
328 .gpa = gpa,
329 };
330 }
331
332 pub fn finalize(noalias self: *WipCaptureScope) !void {
333 self.finalized = true;
334 }
335
336 pub fn reset(noalias self: *WipCaptureScope, parent: ?*CaptureScope) !void {
337 self.scope.decRef(self.gpa);
338 self.scope = try self.gpa.create(CaptureScope);
339 if (parent) |p| p.incRef();
340 self.scope.* = .{ .refs = 1, .parent = parent };
341 }
342
343 pub fn deinit(noalias self: *WipCaptureScope) void {
344 if (self.finalized) {
345 self.scope.decRef(self.gpa);
346 } else {
347 self.scope.fail(self.gpa);
348 }
349 self.* = undefined;
350 }
351};
352306
353const ValueArena = struct {307const ValueArena = struct {
354 state: std.heap.ArenaAllocator.State,308 state: std.heap.ArenaAllocator.State,
...@@ -413,7 +367,7 @@ pub const Decl = struct {...@@ -413,7 +367,7 @@ pub const Decl = struct {
413 /// The scope which lexically contains this decl. A decl must depend367 /// The scope which lexically contains this decl. A decl must depend
414 /// on its lexical parent, in order to ensure that this pointer is valid.368 /// on its lexical parent, in order to ensure that this pointer is valid.
415 /// This scope is allocated out of the arena of the parent decl.369 /// This scope is allocated out of the arena of the parent decl.
416 src_scope: ?*CaptureScope,370 src_scope: CaptureScope.Index,
417371
418 /// An integer that can be checked against the corresponding incrementing372 /// An integer that can be checked against the corresponding incrementing
419 /// generation field of Module. This is used to determine whether `complete` status373 /// generation field of Module. This is used to determine whether `complete` status
...@@ -2893,6 +2847,10 @@ pub fn deinit(mod: *Module) void {...@@ -2893,6 +2847,10 @@ pub fn deinit(mod: *Module) void {
2893 mod.memoized_decls.deinit(gpa);2847 mod.memoized_decls.deinit(gpa);
2894 mod.intern_pool.deinit(gpa);2848 mod.intern_pool.deinit(gpa);
2895 mod.tmp_hack_arena.deinit();2849 mod.tmp_hack_arena.deinit();
2850
2851 mod.capture_scope_parents.deinit(gpa);
2852 mod.runtime_capture_scopes.deinit(gpa);
2853 mod.comptime_capture_scopes.deinit(gpa);
2896}2854}
28972855
2898pub fn destroyDecl(mod: *Module, decl_index: Decl.Index) void {2856pub fn destroyDecl(mod: *Module, decl_index: Decl.Index) void {
...@@ -2914,7 +2872,6 @@ pub fn destroyDecl(mod: *Module, decl_index: Decl.Index) void {...@@ -2914,7 +2872,6 @@ pub fn destroyDecl(mod: *Module, decl_index: Decl.Index) void {
2914 mod.destroyNamespace(i);2872 mod.destroyNamespace(i);
2915 }2873 }
2916 }2874 }
2917 if (decl.src_scope) |scope| scope.decRef(gpa);
2918 decl.dependants.deinit(gpa);2875 decl.dependants.deinit(gpa);
2919 decl.dependencies.deinit(gpa);2876 decl.dependencies.deinit(gpa);
2920 }2877 }
...@@ -3909,7 +3866,7 @@ pub fn semaFile(mod: *Module, file: *File) SemaError!void {...@@ -3909,7 +3866,7 @@ pub fn semaFile(mod: *Module, file: *File) SemaError!void {
3909 const new_namespace = mod.namespacePtr(new_namespace_index);3866 const new_namespace = mod.namespacePtr(new_namespace_index);
3910 errdefer mod.destroyNamespace(new_namespace_index);3867 errdefer mod.destroyNamespace(new_namespace_index);
39113868
3912 const new_decl_index = try mod.allocateNewDecl(new_namespace_index, 0, null);3869 const new_decl_index = try mod.allocateNewDecl(new_namespace_index, 0, .none);
3913 const new_decl = mod.declPtr(new_decl_index);3870 const new_decl = mod.declPtr(new_decl_index);
3914 errdefer @panic("TODO error handling");3871 errdefer @panic("TODO error handling");
39153872
...@@ -3984,11 +3941,7 @@ pub fn semaFile(mod: *Module, file: *File) SemaError!void {...@@ -3984,11 +3941,7 @@ pub fn semaFile(mod: *Module, file: *File) SemaError!void {
3984 };3941 };
3985 defer sema.deinit();3942 defer sema.deinit();
39863943
3987 var wip_captures = try WipCaptureScope.init(gpa, null);
3988 defer wip_captures.deinit();
3989
3990 if (sema.analyzeStructDecl(new_decl, main_struct_inst, struct_index)) |_| {3944 if (sema.analyzeStructDecl(new_decl, main_struct_inst, struct_index)) |_| {
3991 try wip_captures.finalize();
3992 for (comptime_mutable_decls.items) |decl_index| {3945 for (comptime_mutable_decls.items) |decl_index| {
3993 const decl = mod.declPtr(decl_index);3946 const decl = mod.declPtr(decl_index);
3994 _ = try decl.internValue(mod);3947 _ = try decl.internValue(mod);
...@@ -4115,15 +4068,12 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !bool {...@@ -4115,15 +4068,12 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !bool {
4115 return false;4068 return false;
4116 }4069 }
41174070
4118 var wip_captures = try WipCaptureScope.init(gpa, decl.src_scope);
4119 defer wip_captures.deinit();
4120
4121 var block_scope: Sema.Block = .{4071 var block_scope: Sema.Block = .{
4122 .parent = null,4072 .parent = null,
4123 .sema = &sema,4073 .sema = &sema,
4124 .src_decl = decl_index,4074 .src_decl = decl_index,
4125 .namespace = decl.src_namespace,4075 .namespace = decl.src_namespace,
4126 .wip_capture_scope = wip_captures.scope,4076 .wip_capture_scope = try mod.createCaptureScope(decl.src_scope),
4127 .instructions = .{},4077 .instructions = .{},
4128 .inlining = null,4078 .inlining = null,
4129 .is_comptime = true,4079 .is_comptime = true,
...@@ -4137,7 +4087,6 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !bool {...@@ -4137,7 +4087,6 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !bool {
4137 const result_ref = (try sema.analyzeBodyBreak(&block_scope, body)).?.operand;4087 const result_ref = (try sema.analyzeBodyBreak(&block_scope, body)).?.operand;
4138 // We'll do some other bits with the Sema. Clear the type target index just in case they analyze any type.4088 // We'll do some other bits with the Sema. Clear the type target index just in case they analyze any type.
4139 sema.builtin_type_target_index = .none;4089 sema.builtin_type_target_index = .none;
4140 try wip_captures.finalize();
4141 for (comptime_mutable_decls.items) |ct_decl_index| {4090 for (comptime_mutable_decls.items) |ct_decl_index| {
4142 const ct_decl = mod.declPtr(ct_decl_index);4091 const ct_decl = mod.declPtr(ct_decl_index);
4143 _ = try ct_decl.internValue(mod);4092 _ = try ct_decl.internValue(mod);
...@@ -5069,15 +5018,12 @@ pub fn analyzeFnBody(mod: *Module, func_index: InternPool.Index, arena: Allocato...@@ -5069,15 +5018,12 @@ pub fn analyzeFnBody(mod: *Module, func_index: InternPool.Index, arena: Allocato
5069 try sema.air_extra.ensureTotalCapacity(gpa, reserved_count);5018 try sema.air_extra.ensureTotalCapacity(gpa, reserved_count);
5070 sema.air_extra.items.len += reserved_count;5019 sema.air_extra.items.len += reserved_count;
50715020
5072 var wip_captures = try WipCaptureScope.init(gpa, decl.src_scope);
5073 defer wip_captures.deinit();
5074
5075 var inner_block: Sema.Block = .{5021 var inner_block: Sema.Block = .{
5076 .parent = null,5022 .parent = null,
5077 .sema = &sema,5023 .sema = &sema,
5078 .src_decl = decl_index,5024 .src_decl = decl_index,
5079 .namespace = decl.src_namespace,5025 .namespace = decl.src_namespace,
5080 .wip_capture_scope = wip_captures.scope,5026 .wip_capture_scope = try mod.createCaptureScope(decl.src_scope),
5081 .instructions = .{},5027 .instructions = .{},
5082 .inlining = null,5028 .inlining = null,
5083 .is_comptime = false,5029 .is_comptime = false,
...@@ -5189,7 +5135,6 @@ pub fn analyzeFnBody(mod: *Module, func_index: InternPool.Index, arena: Allocato...@@ -5189,7 +5135,6 @@ pub fn analyzeFnBody(mod: *Module, func_index: InternPool.Index, arena: Allocato
5189 };5135 };
5190 }5136 }
51915137
5192 try wip_captures.finalize();
5193 for (comptime_mutable_decls.items) |ct_decl_index| {5138 for (comptime_mutable_decls.items) |ct_decl_index| {
5194 const ct_decl = mod.declPtr(ct_decl_index);5139 const ct_decl = mod.declPtr(ct_decl_index);
5195 _ = try ct_decl.internValue(mod);5140 _ = try ct_decl.internValue(mod);
...@@ -5308,7 +5253,7 @@ pub fn allocateNewDecl(...@@ -5308,7 +5253,7 @@ pub fn allocateNewDecl(
5308 mod: *Module,5253 mod: *Module,
5309 namespace: Namespace.Index,5254 namespace: Namespace.Index,
5310 src_node: Ast.Node.Index,5255 src_node: Ast.Node.Index,
5311 src_scope: ?*CaptureScope,5256 src_scope: CaptureScope.Index,
5312) !Decl.Index {5257) !Decl.Index {
5313 const ip = &mod.intern_pool;5258 const ip = &mod.intern_pool;
5314 const gpa = mod.gpa;5259 const gpa = mod.gpa;
...@@ -5344,8 +5289,6 @@ pub fn allocateNewDecl(...@@ -5344,8 +5289,6 @@ pub fn allocateNewDecl(
5344 }5289 }
5345 }5290 }
53465291
5347 if (src_scope) |scope| scope.incRef();
5348
5349 return decl_index;5292 return decl_index;
5350}5293}
53515294
...@@ -5374,7 +5317,7 @@ pub fn createAnonymousDeclFromDecl(...@@ -5374,7 +5317,7 @@ pub fn createAnonymousDeclFromDecl(
5374 mod: *Module,5317 mod: *Module,
5375 src_decl: *Decl,5318 src_decl: *Decl,
5376 namespace: Namespace.Index,5319 namespace: Namespace.Index,
5377 src_scope: ?*CaptureScope,5320 src_scope: CaptureScope.Index,
5378 tv: TypedValue,5321 tv: TypedValue,
5379) !Decl.Index {5322) !Decl.Index {
5380 const new_decl_index = try mod.allocateNewDecl(namespace, src_decl.src_node, src_scope);5323 const new_decl_index = try mod.allocateNewDecl(namespace, src_decl.src_node, src_scope);
...@@ -5968,7 +5911,7 @@ pub fn populateTestFunctions(...@@ -5968,7 +5911,7 @@ pub fn populateTestFunctions(
5968 .len = test_decl_name.len,5911 .len = test_decl_name.len,
5969 .child = .u8_type,5912 .child = .u8_type,
5970 });5913 });
5971 const test_name_decl_index = try mod.createAnonymousDeclFromDecl(decl, decl.src_namespace, null, .{5914 const test_name_decl_index = try mod.createAnonymousDeclFromDecl(decl, decl.src_namespace, .none, .{
5972 .ty = test_name_decl_ty,5915 .ty = test_name_decl_ty,
5973 .val = (try mod.intern(.{ .aggregate = .{5916 .val = (try mod.intern(.{ .aggregate = .{
5974 .ty = test_name_decl_ty.toIntern(),5917 .ty = test_name_decl_ty.toIntern(),
...@@ -6015,7 +5958,7 @@ pub fn populateTestFunctions(...@@ -6015,7 +5958,7 @@ pub fn populateTestFunctions(
6015 .child = test_fn_ty.toIntern(),5958 .child = test_fn_ty.toIntern(),
6016 .sentinel = .none,5959 .sentinel = .none,
6017 });5960 });
6018 const array_decl_index = try mod.createAnonymousDeclFromDecl(decl, decl.src_namespace, null, .{5961 const array_decl_index = try mod.createAnonymousDeclFromDecl(decl, decl.src_namespace, .none, .{
6019 .ty = array_decl_ty,5962 .ty = array_decl_ty,
6020 .val = (try mod.intern(.{ .aggregate = .{5963 .val = (try mod.intern(.{ .aggregate = .{
6021 .ty = array_decl_ty.toIntern(),5964 .ty = array_decl_ty.toIntern(),
src/Sema.zig+60-134
...@@ -131,7 +131,6 @@ const CompileError = Module.CompileError;...@@ -131,7 +131,6 @@ const CompileError = Module.CompileError;
131const SemaError = Module.SemaError;131const SemaError = Module.SemaError;
132const Decl = Module.Decl;132const Decl = Module.Decl;
133const CaptureScope = Module.CaptureScope;133const CaptureScope = Module.CaptureScope;
134const WipCaptureScope = Module.WipCaptureScope;
135const LazySrcLoc = Module.LazySrcLoc;134const LazySrcLoc = Module.LazySrcLoc;
136const RangeSet = @import("RangeSet.zig");135const RangeSet = @import("RangeSet.zig");
137const target_util = @import("target.zig");136const target_util = @import("target.zig");
...@@ -308,7 +307,7 @@ pub const Block = struct {...@@ -308,7 +307,7 @@ pub const Block = struct {
308 /// used to add a `func_instance` into the `InternPool`.307 /// used to add a `func_instance` into the `InternPool`.
309 params: std.MultiArrayList(Param) = .{},308 params: std.MultiArrayList(Param) = .{},
310309
311 wip_capture_scope: *CaptureScope,310 wip_capture_scope: CaptureScope.Index,
312311
313 label: ?*Label = null,312 label: ?*Label = null,
314 inlining: ?*Inlining,313 inlining: ?*Inlining,
...@@ -951,21 +950,12 @@ fn analyzeBodyInner(...@@ -951,21 +950,12 @@ fn analyzeBodyInner(
951 // different values for the same Zir.Inst.Index, so in those cases, we will950 // different values for the same Zir.Inst.Index, so in those cases, we will
952 // have to create nested capture scopes; see the `.repeat` case below.951 // have to create nested capture scopes; see the `.repeat` case below.
953 const parent_capture_scope = block.wip_capture_scope;952 const parent_capture_scope = block.wip_capture_scope;
954 parent_capture_scope.incRef();
955 var wip_captures: WipCaptureScope = .{
956 .scope = parent_capture_scope,
957 .gpa = sema.gpa,
958 .finalized = true, // don't finalize the parent scope
959 };
960 defer wip_captures.deinit();
961953
962 const mod = sema.mod;954 const mod = sema.mod;
963 const map = &sema.inst_map;955 const map = &sema.inst_map;
964 const tags = sema.code.instructions.items(.tag);956 const tags = sema.code.instructions.items(.tag);
965 const datas = sema.code.instructions.items(.data);957 const datas = sema.code.instructions.items(.data);
966958
967 var orig_captures: usize = parent_capture_scope.captures.count();
968
969 var crash_info = crash_report.prepAnalyzeBody(sema, block, body);959 var crash_info = crash_report.prepAnalyzeBody(sema, block, body);
970 crash_info.push();960 crash_info.push();
971 defer crash_info.pop();961 defer crash_info.pop();
...@@ -1500,16 +1490,11 @@ fn analyzeBodyInner(...@@ -1500,16 +1490,11 @@ fn analyzeBodyInner(
1500 // Send comptime control flow back to the beginning of this block.1490 // Send comptime control flow back to the beginning of this block.
1501 const src = LazySrcLoc.nodeOffset(datas[inst].node);1491 const src = LazySrcLoc.nodeOffset(datas[inst].node);
1502 try sema.emitBackwardBranch(block, src);1492 try sema.emitBackwardBranch(block, src);
1503 if (wip_captures.scope.captures.count() != orig_captures) {1493
1504 // We need to construct new capture scopes for the next loop iteration so it1494 // We need to construct new capture scopes for the next loop iteration so it
1505 // can capture values without clobbering the earlier iteration's captures.1495 // can capture values without clobbering the earlier iteration's captures.
1506 // At first, we reused the parent capture scope as an optimization, but for1496 block.wip_capture_scope = try mod.createCaptureScope(parent_capture_scope);
1507 // successive scopes we have to create new ones as children of the parent1497
1508 // scope.
1509 try wip_captures.reset(parent_capture_scope);
1510 block.wip_capture_scope = wip_captures.scope;
1511 orig_captures = 0;
1512 }
1513 i = 0;1498 i = 0;
1514 continue;1499 continue;
1515 } else {1500 } else {
...@@ -1520,16 +1505,11 @@ fn analyzeBodyInner(...@@ -1520,16 +1505,11 @@ fn analyzeBodyInner(
1520 // Send comptime control flow back to the beginning of this block.1505 // Send comptime control flow back to the beginning of this block.
1521 const src = LazySrcLoc.nodeOffset(datas[inst].node);1506 const src = LazySrcLoc.nodeOffset(datas[inst].node);
1522 try sema.emitBackwardBranch(block, src);1507 try sema.emitBackwardBranch(block, src);
1523 if (wip_captures.scope.captures.count() != orig_captures) {1508
1524 // We need to construct new capture scopes for the next loop iteration so it1509 // We need to construct new capture scopes for the next loop iteration so it
1525 // can capture values without clobbering the earlier iteration's captures.1510 // can capture values without clobbering the earlier iteration's captures.
1526 // At first, we reused the parent capture scope as an optimization, but for1511 block.wip_capture_scope = try mod.createCaptureScope(parent_capture_scope);
1527 // successive scopes we have to create new ones as children of the parent1512
1528 // scope.
1529 try wip_captures.reset(parent_capture_scope);
1530 block.wip_capture_scope = wip_captures.scope;
1531 orig_captures = 0;
1532 }
1533 i = 0;1513 i = 0;
1534 continue;1514 continue;
1535 },1515 },
...@@ -1803,12 +1783,9 @@ fn analyzeBodyInner(...@@ -1803,12 +1783,9 @@ fn analyzeBodyInner(
1803 }1783 }
1804 if (noreturn_inst) |some| try block.instructions.append(sema.gpa, some);1784 if (noreturn_inst) |some| try block.instructions.append(sema.gpa, some);
18051785
1806 if (!wip_captures.finalized) {1786 // We may have overwritten the capture scope due to a `repeat` instruction where
1807 // We've updated the capture scope due to a `repeat` instruction where1787 // the body had a capture; restore it now.
1808 // the body had a capture; finalize our child scope and reset1788 block.wip_capture_scope = parent_capture_scope;
1809 try wip_captures.finalize();
1810 block.wip_capture_scope = parent_capture_scope;
1811 }
18121789
1813 return result;1790 return result;
1814}1791}
...@@ -3157,15 +3134,12 @@ fn zirEnumDecl(...@@ -3157,15 +3134,12 @@ fn zirEnumDecl(
3157 sema.func_index = .none;3134 sema.func_index = .none;
3158 defer sema.func_index = prev_func_index;3135 defer sema.func_index = prev_func_index;
31593136
3160 var wip_captures = try WipCaptureScope.init(gpa, new_decl.src_scope);
3161 defer wip_captures.deinit();
3162
3163 var enum_block: Block = .{3137 var enum_block: Block = .{
3164 .parent = null,3138 .parent = null,
3165 .sema = sema,3139 .sema = sema,
3166 .src_decl = new_decl_index,3140 .src_decl = new_decl_index,
3167 .namespace = new_namespace_index,3141 .namespace = new_namespace_index,
3168 .wip_capture_scope = wip_captures.scope,3142 .wip_capture_scope = try mod.createCaptureScope(new_decl.src_scope),
3169 .instructions = .{},3143 .instructions = .{},
3170 .inlining = null,3144 .inlining = null,
3171 .is_comptime = true,3145 .is_comptime = true,
...@@ -3176,8 +3150,6 @@ fn zirEnumDecl(...@@ -3176,8 +3150,6 @@ fn zirEnumDecl(
3176 try sema.analyzeBody(&enum_block, body);3150 try sema.analyzeBody(&enum_block, body);
3177 }3151 }
31783152
3179 try wip_captures.finalize();
3180
3181 if (tag_type_ref != .none) {3153 if (tag_type_ref != .none) {
3182 const ty = try sema.resolveType(block, tag_ty_src, tag_type_ref);3154 const ty = try sema.resolveType(block, tag_ty_src, tag_type_ref);
3183 if (ty.zigTypeTag(mod) != .Int and ty.zigTypeTag(mod) != .ComptimeInt) {3155 if (ty.zigTypeTag(mod) != .Int and ty.zigTypeTag(mod) != .ComptimeInt) {
...@@ -7298,15 +7270,12 @@ fn analyzeCall(...@@ -7298,15 +7270,12 @@ fn analyzeCall(
72987270
7299 try mod.declareDeclDependencyType(ics.callee().owner_decl_index, module_fn.owner_decl, .function_body);7271 try mod.declareDeclDependencyType(ics.callee().owner_decl_index, module_fn.owner_decl, .function_body);
73007272
7301 var wip_captures = try WipCaptureScope.init(gpa, fn_owner_decl.src_scope);
7302 defer wip_captures.deinit();
7303
7304 var child_block: Block = .{7273 var child_block: Block = .{
7305 .parent = null,7274 .parent = null,
7306 .sema = sema,7275 .sema = sema,
7307 .src_decl = module_fn.owner_decl,7276 .src_decl = module_fn.owner_decl,
7308 .namespace = fn_owner_decl.src_namespace,7277 .namespace = fn_owner_decl.src_namespace,
7309 .wip_capture_scope = wip_captures.scope,7278 .wip_capture_scope = try mod.createCaptureScope(fn_owner_decl.src_scope),
7310 .instructions = .{},7279 .instructions = .{},
7311 .label = null,7280 .label = null,
7312 .inlining = &inlining,7281 .inlining = &inlining,
...@@ -7514,8 +7483,6 @@ fn analyzeCall(...@@ -7514,8 +7483,6 @@ fn analyzeCall(
7514 break :res2 result;7483 break :res2 result;
7515 };7484 };
75167485
7517 try wip_captures.finalize();
7518
7519 break :res res2;7486 break :res res2;
7520 } else res: {7487 } else res: {
7521 assert(!func_ty_info.is_generic);7488 assert(!func_ty_info.is_generic);
...@@ -7840,15 +7807,12 @@ fn instantiateGenericCall(...@@ -7840,15 +7807,12 @@ fn instantiateGenericCall(
7840 };7807 };
7841 defer child_sema.deinit();7808 defer child_sema.deinit();
78427809
7843 var wip_captures = try WipCaptureScope.init(gpa, sema.owner_decl.src_scope);
7844 defer wip_captures.deinit();
7845
7846 var child_block: Block = .{7810 var child_block: Block = .{
7847 .parent = null,7811 .parent = null,
7848 .sema = &child_sema,7812 .sema = &child_sema,
7849 .src_decl = generic_owner_func.owner_decl,7813 .src_decl = generic_owner_func.owner_decl,
7850 .namespace = namespace_index,7814 .namespace = namespace_index,
7851 .wip_capture_scope = wip_captures.scope,7815 .wip_capture_scope = try mod.createCaptureScope(sema.owner_decl.src_scope),
7852 .instructions = .{},7816 .instructions = .{},
7853 .inlining = null,7817 .inlining = null,
7854 .is_comptime = true,7818 .is_comptime = true,
...@@ -8000,8 +7964,6 @@ fn instantiateGenericCall(...@@ -8000,8 +7964,6 @@ fn instantiateGenericCall(
8000 const func_ty = callee.ty.toType();7964 const func_ty = callee.ty.toType();
8001 const func_ty_info = mod.typeToFunc(func_ty).?;7965 const func_ty_info = mod.typeToFunc(func_ty).?;
80027966
8003 try wip_captures.finalize();
8004
8005 // If the call evaluated to a return type that requires comptime, never mind7967 // If the call evaluated to a return type that requires comptime, never mind
8006 // our generic instantiation. Instead we need to perform a comptime call.7968 // our generic instantiation. Instead we need to perform a comptime call.
8007 if (try sema.typeRequiresComptime(func_ty_info.return_type.toType())) {7969 if (try sema.typeRequiresComptime(func_ty_info.return_type.toType())) {
...@@ -11897,11 +11859,8 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r...@@ -11897,11 +11859,8 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
11897 const body = sema.code.extra[extra_index..][0..info.body_len];11859 const body = sema.code.extra[extra_index..][0..info.body_len];
11898 extra_index += info.body_len;11860 extra_index += info.body_len;
1189911861
11900 var wip_captures = try WipCaptureScope.init(gpa, child_block.wip_capture_scope);
11901 defer wip_captures.deinit();
11902
11903 case_block.instructions.shrinkRetainingCapacity(0);11862 case_block.instructions.shrinkRetainingCapacity(0);
11904 case_block.wip_capture_scope = wip_captures.scope;11863 case_block.wip_capture_scope = try mod.createCaptureScope(child_block.wip_capture_scope);
1190511864
11906 const item = case_vals.items[scalar_i];11865 const item = case_vals.items[scalar_i];
11907 // `item` is already guaranteed to be constant known.11866 // `item` is already guaranteed to be constant known.
...@@ -11929,8 +11888,6 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r...@@ -11929,8 +11888,6 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
11929 _ = try case_block.addNoOp(.unreach);11888 _ = try case_block.addNoOp(.unreach);
11930 }11889 }
1193111890
11932 try wip_captures.finalize();
11933
11934 try cases_extra.ensureUnusedCapacity(gpa, 3 + case_block.instructions.items.len);11891 try cases_extra.ensureUnusedCapacity(gpa, 3 + case_block.instructions.items.len);
11935 cases_extra.appendAssumeCapacity(1); // items_len11892 cases_extra.appendAssumeCapacity(1); // items_len
11936 cases_extra.appendAssumeCapacity(@intCast(case_block.instructions.items.len));11893 cases_extra.appendAssumeCapacity(@intCast(case_block.instructions.items.len));
...@@ -12177,11 +12134,8 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r...@@ -12177,11 +12134,8 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
12177 var cond_body = try case_block.instructions.toOwnedSlice(gpa);12134 var cond_body = try case_block.instructions.toOwnedSlice(gpa);
12178 defer gpa.free(cond_body);12135 defer gpa.free(cond_body);
1217912136
12180 var wip_captures = try WipCaptureScope.init(gpa, child_block.wip_capture_scope);
12181 defer wip_captures.deinit();
12182
12183 case_block.instructions.shrinkRetainingCapacity(0);12137 case_block.instructions.shrinkRetainingCapacity(0);
12184 case_block.wip_capture_scope = wip_captures.scope;12138 case_block.wip_capture_scope = try mod.createCaptureScope(child_block.wip_capture_scope);
1218512139
12186 const body = sema.code.extra[extra_index..][0..info.body_len];12140 const body = sema.code.extra[extra_index..][0..info.body_len];
12187 extra_index += info.body_len;12141 extra_index += info.body_len;
...@@ -12200,8 +12154,6 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r...@@ -12200,8 +12154,6 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
12200 );12154 );
12201 }12155 }
1220212156
12203 try wip_captures.finalize();
12204
12205 if (is_first) {12157 if (is_first) {
12206 is_first = false;12158 is_first = false;
12207 first_else_body = cond_body;12159 first_else_body = cond_body;
...@@ -12407,11 +12359,8 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r...@@ -12407,11 +12359,8 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
12407 }),12359 }),
12408 };12360 };
1240912361
12410 var wip_captures = try WipCaptureScope.init(gpa, child_block.wip_capture_scope);
12411 defer wip_captures.deinit();
12412
12413 case_block.instructions.shrinkRetainingCapacity(0);12362 case_block.instructions.shrinkRetainingCapacity(0);
12414 case_block.wip_capture_scope = wip_captures.scope;12363 case_block.wip_capture_scope = try mod.createCaptureScope(child_block.wip_capture_scope);
1241512364
12416 if (mod.backendSupportsFeature(.is_named_enum_value) and special.body.len != 0 and block.wantSafety() and12365 if (mod.backendSupportsFeature(.is_named_enum_value) and special.body.len != 0 and block.wantSafety() and
12417 operand_ty.zigTypeTag(mod) == .Enum and (!operand_ty.isNonexhaustiveEnum(mod) or union_originally))12366 operand_ty.zigTypeTag(mod) == .Enum and (!operand_ty.isNonexhaustiveEnum(mod) or union_originally))
...@@ -12456,8 +12405,6 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r...@@ -12456,8 +12405,6 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
12456 }12405 }
12457 }12406 }
1245812407
12459 try wip_captures.finalize();
12460
12461 if (is_first) {12408 if (is_first) {
12462 final_else_body = case_block.instructions.items;12409 final_else_body = case_block.instructions.items;
12463 } else {12410 } else {
...@@ -16557,51 +16504,53 @@ fn zirThis(...@@ -16557,51 +16504,53 @@ fn zirThis(
16557}16504}
1655816505
16559fn zirClosureCapture(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void {16506fn zirClosureCapture(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void {
16507 const mod = sema.mod;
16508 const gpa = sema.gpa;
16560 const inst_data = sema.code.instructions.items(.data)[inst].un_tok;16509 const inst_data = sema.code.instructions.items(.data)[inst].un_tok;
16561 // Closures are not necessarily constant values. For example, the16510 // Closures are not necessarily constant values. For example, the
16562 // code might do something like this:16511 // code might do something like this:
16563 // fn foo(x: anytype) void { const S = struct {field: @TypeOf(x)}; }16512 // fn foo(x: anytype) void { const S = struct {field: @TypeOf(x)}; }
16564 // ...in which case the closure_capture instruction has access to a runtime16513 // ...in which case the closure_capture instruction has access to a runtime
16565 // value only. In such case we preserve the type and use a dummy runtime value.16514 // value only. In such case only the type is saved into the scope.
16566 const operand = try sema.resolveInst(inst_data.operand);16515 const operand = try sema.resolveInst(inst_data.operand);
16567 const ty = sema.typeOf(operand);16516 const ty = sema.typeOf(operand);
16568 const capture: CaptureScope.Capture = blk: {16517 const key: CaptureScope.Key = .{
16569 if (try sema.resolveMaybeUndefValAllowVariables(operand)) |val| {16518 .zir_index = inst,
16570 const ip_index = try val.intern(ty, sema.mod);16519 .index = block.wip_capture_scope,
16571 break :blk .{ .comptime_val = ip_index };
16572 }
16573 break :blk .{ .runtime_val = ty.toIntern() };
16574 };16520 };
16575 try block.wip_capture_scope.captures.putNoClobber(sema.gpa, inst, capture);16521 if (try sema.resolveMaybeUndefValAllowVariables(operand)) |val| {
16522 try mod.comptime_capture_scopes.put(gpa, key, try val.intern(ty, mod));
16523 } else {
16524 try mod.runtime_capture_scopes.put(gpa, key, ty.toIntern());
16525 }
16576}16526}
1657716527
16578fn zirClosureGet(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {16528fn zirClosureGet(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
16579 const mod = sema.mod;16529 const mod = sema.mod;
16580 const ip = &mod.intern_pool;16530 //const ip = &mod.intern_pool;
16581 const inst_data = sema.code.instructions.items(.data)[inst].inst_node;16531 const inst_data = sema.code.instructions.items(.data)[inst].inst_node;
16582 var scope: *CaptureScope = mod.declPtr(block.src_decl).src_scope.?;16532 var scope: CaptureScope.Index = mod.declPtr(block.src_decl).src_scope;
16533 assert(scope != .none);
16583 // Note: The target closure must be in this scope list.16534 // Note: The target closure must be in this scope list.
16584 // If it's not here, the zir is invalid, or the list is broken.16535 // If it's not here, the zir is invalid, or the list is broken.
16585 const capture = while (true) {16536 const capture_ty = while (true) {
16586 // Note: We don't need to add a dependency here, because16537 // Note: We don't need to add a dependency here, because
16587 // decls always depend on their lexical parents.16538 // decls always depend on their lexical parents.
1658816539 const key: CaptureScope.Key = .{
16589 // Fail this decl if a scope it depended on failed.16540 .zir_index = inst_data.inst,
16590 if (scope.failed()) {16541 .index = scope,
16591 if (sema.owner_func_index != .none) {16542 };
16592 ip.funcAnalysis(sema.owner_func_index).state = .dependency_failure;16543 if (mod.comptime_capture_scopes.get(key)) |val|
16593 } else {16544 return Air.internedToRef(val);
16594 sema.owner_decl.analysis = .dependency_failure;16545 if (mod.runtime_capture_scopes.get(key)) |ty|
16595 }16546 break ty;
16596 return error.AnalysisFail;16547 scope = scope.parent(mod);
16597 }16548 assert(scope != .none);
16598 if (scope.captures.get(inst_data.inst)) |capture| {
16599 break capture;
16600 }
16601 scope = scope.parent.?;
16602 };16549 };
1660316550
16604 if (capture == .runtime_val and !block.is_typeof and sema.func_index == .none) {16551 // The comptime case is handled already above. Runtime case below.
16552
16553 if (!block.is_typeof and sema.func_index == .none) {
16605 const msg = msg: {16554 const msg = msg: {
16606 const name = name: {16555 const name = name: {
16607 const file = sema.owner_decl.getFileScope(mod);16556 const file = sema.owner_decl.getFileScope(mod);
...@@ -16629,7 +16578,7 @@ fn zirClosureGet(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!...@@ -16629,7 +16578,7 @@ fn zirClosureGet(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
16629 return sema.failWithOwnedErrorMsg(block, msg);16578 return sema.failWithOwnedErrorMsg(block, msg);
16630 }16579 }
1663116580
16632 if (capture == .runtime_val and !block.is_typeof and !block.is_comptime and sema.func_index != .none) {16581 if (!block.is_typeof and !block.is_comptime and sema.func_index != .none) {
16633 const msg = msg: {16582 const msg = msg: {
16634 const name = name: {16583 const name = name: {
16635 const file = sema.owner_decl.getFileScope(mod);16584 const file = sema.owner_decl.getFileScope(mod);
...@@ -16659,16 +16608,9 @@ fn zirClosureGet(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!...@@ -16659,16 +16608,9 @@ fn zirClosureGet(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
16659 return sema.failWithOwnedErrorMsg(block, msg);16608 return sema.failWithOwnedErrorMsg(block, msg);
16660 }16609 }
1666116610
16662 switch (capture) {16611 assert(block.is_typeof);
16663 .runtime_val => |ty_ip_index| {16612 // We need a dummy runtime instruction with the correct type.
16664 assert(block.is_typeof);16613 return block.addTy(.alloc, capture_ty.toType());
16665 // We need a dummy runtime instruction with the correct type.
16666 return block.addTy(.alloc, ty_ip_index.toType());
16667 },
16668 .comptime_val => |val_ip_index| {
16669 return Air.internedToRef(val_ip_index);
16670 },
16671 }
16672}16614}
1667316615
16674fn zirRetAddr(16616fn zirRetAddr(
...@@ -24988,7 +24930,7 @@ fn zirBuiltinExtern(...@@ -24988,7 +24930,7 @@ fn zirBuiltinExtern(
2498824930
24989 // TODO check duplicate extern24931 // TODO check duplicate extern
2499024932
24991 const new_decl_index = try mod.allocateNewDecl(sema.owner_decl.src_namespace, sema.owner_decl.src_node, null);24933 const new_decl_index = try mod.allocateNewDecl(sema.owner_decl.src_namespace, sema.owner_decl.src_node, .none);
24992 errdefer mod.destroyDecl(new_decl_index);24934 errdefer mod.destroyDecl(new_decl_index);
24993 const new_decl = mod.declPtr(new_decl_index);24935 const new_decl = mod.declPtr(new_decl_index);
24994 new_decl.name = options.name;24936 new_decl.name = options.name;
...@@ -34327,15 +34269,12 @@ fn semaBackingIntType(mod: *Module, struct_obj: *Module.Struct) CompileError!voi...@@ -34327,15 +34269,12 @@ fn semaBackingIntType(mod: *Module, struct_obj: *Module.Struct) CompileError!voi
34327 };34269 };
34328 defer sema.deinit();34270 defer sema.deinit();
3432934271
34330 var wip_captures = try WipCaptureScope.init(gpa, decl.src_scope);
34331 defer wip_captures.deinit();
34332
34333 var block: Block = .{34272 var block: Block = .{
34334 .parent = null,34273 .parent = null,
34335 .sema = &sema,34274 .sema = &sema,
34336 .src_decl = decl_index,34275 .src_decl = decl_index,
34337 .namespace = struct_obj.namespace,34276 .namespace = struct_obj.namespace,
34338 .wip_capture_scope = wip_captures.scope,34277 .wip_capture_scope = try mod.createCaptureScope(decl.src_scope),
34339 .instructions = .{},34278 .instructions = .{},
34340 .inlining = null,34279 .inlining = null,
34341 .is_comptime = true,34280 .is_comptime = true,
...@@ -34356,7 +34295,6 @@ fn semaBackingIntType(mod: *Module, struct_obj: *Module.Struct) CompileError!voi...@@ -34356,7 +34295,6 @@ fn semaBackingIntType(mod: *Module, struct_obj: *Module.Struct) CompileError!voi
3435634295
34357 try sema.checkBackingIntType(&block, backing_int_src, backing_int_ty, fields_bit_sum);34296 try sema.checkBackingIntType(&block, backing_int_src, backing_int_ty, fields_bit_sum);
34358 struct_obj.backing_int_ty = backing_int_ty;34297 struct_obj.backing_int_ty = backing_int_ty;
34359 try wip_captures.finalize();
34360 for (comptime_mutable_decls.items) |ct_decl_index| {34298 for (comptime_mutable_decls.items) |ct_decl_index| {
34361 const ct_decl = mod.declPtr(ct_decl_index);34299 const ct_decl = mod.declPtr(ct_decl_index);
34362 _ = try ct_decl.internValue(mod);34300 _ = try ct_decl.internValue(mod);
...@@ -35018,15 +34956,12 @@ fn semaStructFields(mod: *Module, struct_obj: *Module.Struct) CompileError!void...@@ -35018,15 +34956,12 @@ fn semaStructFields(mod: *Module, struct_obj: *Module.Struct) CompileError!void
35018 };34956 };
35019 defer sema.deinit();34957 defer sema.deinit();
3502034958
35021 var wip_captures = try WipCaptureScope.init(gpa, decl.src_scope);
35022 defer wip_captures.deinit();
35023
35024 var block_scope: Block = .{34959 var block_scope: Block = .{
35025 .parent = null,34960 .parent = null,
35026 .sema = &sema,34961 .sema = &sema,
35027 .src_decl = decl_index,34962 .src_decl = decl_index,
35028 .namespace = struct_obj.namespace,34963 .namespace = struct_obj.namespace,
35029 .wip_capture_scope = wip_captures.scope,34964 .wip_capture_scope = try mod.createCaptureScope(decl.src_scope),
35030 .instructions = .{},34965 .instructions = .{},
35031 .inlining = null,34966 .inlining = null,
35032 .is_comptime = true,34967 .is_comptime = true,
...@@ -35283,7 +35218,6 @@ fn semaStructFields(mod: *Module, struct_obj: *Module.Struct) CompileError!void...@@ -35283,7 +35218,6 @@ fn semaStructFields(mod: *Module, struct_obj: *Module.Struct) CompileError!void
35283 }35218 }
35284 }35219 }
35285 }35220 }
35286 try wip_captures.finalize();
35287 for (comptime_mutable_decls.items) |ct_decl_index| {35221 for (comptime_mutable_decls.items) |ct_decl_index| {
35288 const ct_decl = mod.declPtr(ct_decl_index);35222 const ct_decl = mod.declPtr(ct_decl_index);
35289 _ = try ct_decl.internValue(mod);35223 _ = try ct_decl.internValue(mod);
...@@ -35361,15 +35295,12 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Key.Un...@@ -35361,15 +35295,12 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Key.Un
35361 };35295 };
35362 defer sema.deinit();35296 defer sema.deinit();
3536335297
35364 var wip_captures = try WipCaptureScope.init(gpa, decl.src_scope);
35365 defer wip_captures.deinit();
35366
35367 var block_scope: Block = .{35298 var block_scope: Block = .{
35368 .parent = null,35299 .parent = null,
35369 .sema = &sema,35300 .sema = &sema,
35370 .src_decl = decl_index,35301 .src_decl = decl_index,
35371 .namespace = union_type.namespace,35302 .namespace = union_type.namespace,
35372 .wip_capture_scope = wip_captures.scope,35303 .wip_capture_scope = try mod.createCaptureScope(decl.src_scope),
35373 .instructions = .{},35304 .instructions = .{},
35374 .inlining = null,35305 .inlining = null,
35375 .is_comptime = true,35306 .is_comptime = true,
...@@ -35380,7 +35311,6 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Key.Un...@@ -35380,7 +35311,6 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Key.Un
35380 try sema.analyzeBody(&block_scope, body);35311 try sema.analyzeBody(&block_scope, body);
35381 }35312 }
3538235313
35383 try wip_captures.finalize();
35384 for (comptime_mutable_decls.items) |ct_decl_index| {35314 for (comptime_mutable_decls.items) |ct_decl_index| {
35385 const ct_decl = mod.declPtr(ct_decl_index);35315 const ct_decl = mod.declPtr(ct_decl_index);
35386 _ = try ct_decl.internValue(mod);35316 _ = try ct_decl.internValue(mod);
...@@ -35823,18 +35753,16 @@ fn generateUnionTagTypeSimple(...@@ -35823,18 +35753,16 @@ fn generateUnionTagTypeSimple(
35823}35753}
3582435754
35825fn getBuiltin(sema: *Sema, name: []const u8) CompileError!Air.Inst.Ref {35755fn getBuiltin(sema: *Sema, name: []const u8) CompileError!Air.Inst.Ref {
35756 const mod = sema.mod;
35826 const gpa = sema.gpa;35757 const gpa = sema.gpa;
35827 const src = LazySrcLoc.nodeOffset(0);35758 const src = LazySrcLoc.nodeOffset(0);
3582835759
35829 var wip_captures = try WipCaptureScope.init(gpa, sema.owner_decl.src_scope);
35830 defer wip_captures.deinit();
35831
35832 var block: Block = .{35760 var block: Block = .{
35833 .parent = null,35761 .parent = null,
35834 .sema = sema,35762 .sema = sema,
35835 .src_decl = sema.owner_decl_index,35763 .src_decl = sema.owner_decl_index,
35836 .namespace = sema.owner_decl.src_namespace,35764 .namespace = sema.owner_decl.src_namespace,
35837 .wip_capture_scope = wip_captures.scope,35765 .wip_capture_scope = try mod.createCaptureScope(sema.owner_decl.src_scope),
35838 .instructions = .{},35766 .instructions = .{},
35839 .inlining = null,35767 .inlining = null,
35840 .is_comptime = true,35768 .is_comptime = true,
...@@ -35875,17 +35803,15 @@ fn getBuiltinDecl(sema: *Sema, block: *Block, name: []const u8) CompileError!Mod...@@ -35875,17 +35803,15 @@ fn getBuiltinDecl(sema: *Sema, block: *Block, name: []const u8) CompileError!Mod
35875}35803}
3587635804
35877fn getBuiltinType(sema: *Sema, name: []const u8) CompileError!Type {35805fn getBuiltinType(sema: *Sema, name: []const u8) CompileError!Type {
35806 const mod = sema.mod;
35878 const ty_inst = try sema.getBuiltin(name);35807 const ty_inst = try sema.getBuiltin(name);
3587935808
35880 var wip_captures = try WipCaptureScope.init(sema.gpa, sema.owner_decl.src_scope);
35881 defer wip_captures.deinit();
35882
35883 var block: Block = .{35809 var block: Block = .{
35884 .parent = null,35810 .parent = null,
35885 .sema = sema,35811 .sema = sema,
35886 .src_decl = sema.owner_decl_index,35812 .src_decl = sema.owner_decl_index,
35887 .namespace = sema.owner_decl.src_namespace,35813 .namespace = sema.owner_decl.src_namespace,
35888 .wip_capture_scope = wip_captures.scope,35814 .wip_capture_scope = try mod.createCaptureScope(sema.owner_decl.src_scope),
35889 .instructions = .{},35815 .instructions = .{},
35890 .inlining = null,35816 .inlining = null,
35891 .is_comptime = true,35817 .is_comptime = true,