| ... | ... | @@ -16,9 +16,7 @@ air_instructions: std.MultiArrayList(Air.Inst) = .{}, |
| 16 | 16 | air_extra: std.ArrayListUnmanaged(u32) = .{}, |
| 17 | 17 | /// Maps ZIR to AIR. |
| 18 | 18 | inst_map: InstMap = .{}, |
| 19 | | /// When analyzing an inline function call, owner_decl is the Decl of the caller |
| 20 | | /// and `src_decl` of `Block` is the `Decl` of the callee. |
| 21 | | /// This `Decl` owns the arena memory of this `Sema`. |
| 19 | /// When analyzing an inline function call, owner_decl is the Decl of the caller. |
| 22 | 20 | owner_decl: *Decl, |
| 23 | 21 | owner_decl_index: InternPool.DeclIndex, |
| 24 | 22 | /// For an inline or comptime function call, this will be the root parent function |
| ... | ... | @@ -342,7 +340,6 @@ pub const Block = struct { |
| 342 | 340 | /// Shared among all child blocks. |
| 343 | 341 | sema: *Sema, |
| 344 | 342 | /// The namespace to use for lookups from this source block |
| 345 | | /// When analyzing fields, this is different from src_decl.src_namespace. |
| 346 | 343 | namespace: InternPool.NamespaceIndex, |
| 347 | 344 | /// The AIR instructions generated for this block. |
| 348 | 345 | instructions: std.ArrayListUnmanaged(Air.Inst.Index), |
| ... | ... | @@ -360,10 +357,6 @@ pub const Block = struct { |
| 360 | 357 | /// If runtime_index is not 0 then one of these is guaranteed to be non null. |
| 361 | 358 | runtime_cond: ?LazySrcLoc = null, |
| 362 | 359 | runtime_loop: ?LazySrcLoc = null, |
| 363 | | /// This Decl is the Decl according to the Zig source code corresponding to this Block. |
| 364 | | /// This can vary during inline or comptime function calls. See `Sema.owner_decl` |
| 365 | | /// for the one that will be the same for all Block instances. |
| 366 | | src_decl: InternPool.DeclIndex, |
| 367 | 360 | /// Non zero if a non-inline loop or a runtime conditional have been encountered. |
| 368 | 361 | /// Stores to comptime variables are only allowed when var.runtime_index <= runtime_index. |
| 369 | 362 | runtime_index: Value.RuntimeIndex = .zero, |
| ... | ... | @@ -396,6 +389,12 @@ pub const Block = struct { |
| 396 | 389 | /// treated as relative to the AST node of this ZIR instruction. |
| 397 | 390 | src_base_inst: InternPool.TrackedInst.Index, |
| 398 | 391 | |
| 392 | /// The name of the current "context" for naming namespace types. |
| 393 | /// The interpretation of this depends on the name strategy in ZIR, but the name |
| 394 | /// is always incorporated into the type name somehow. |
| 395 | /// See `Sema.createAnonymousDeclTypeNamed`. |
| 396 | type_name_ctx: InternPool.NullTerminatedString, |
| 397 | |
| 399 | 398 | /// Create a `LazySrcLoc` based on an `Offset` from the code being analyzed in this block. |
| 400 | 399 | /// Specifically, the given `Offset` is treated as relative to `block.src_base_inst`. |
| 401 | 400 | pub fn src(block: Block, offset: LazySrcLoc.Offset) LazySrcLoc { |
| ... | ... | @@ -516,7 +515,6 @@ pub const Block = struct { |
| 516 | 515 | return .{ |
| 517 | 516 | .parent = parent, |
| 518 | 517 | .sema = parent.sema, |
| 519 | | .src_decl = parent.src_decl, |
| 520 | 518 | .namespace = parent.namespace, |
| 521 | 519 | .instructions = .{}, |
| 522 | 520 | .label = null, |
| ... | ... | @@ -533,6 +531,7 @@ pub const Block = struct { |
| 533 | 531 | .error_return_trace_index = parent.error_return_trace_index, |
| 534 | 532 | .need_debug_scope = parent.need_debug_scope, |
| 535 | 533 | .src_base_inst = parent.src_base_inst, |
| 534 | .type_name_ctx = parent.type_name_ctx, |
| 536 | 535 | }; |
| 537 | 536 | } |
| 538 | 537 | |
| ... | ... | @@ -993,9 +992,11 @@ fn analyzeBodyInner( |
| 993 | 992 | while (true) { |
| 994 | 993 | crash_info.setBodyIndex(i); |
| 995 | 994 | const inst = body[i]; |
| 996 | | std.log.scoped(.sema_zir).debug("sema ZIR {s} %{d}", .{ |
| 997 | | mod.namespacePtr(mod.declPtr(block.src_decl).src_namespace).file_scope.sub_file_path, inst, |
| 998 | | }); |
| 995 | std.log.scoped(.sema_zir).debug("sema ZIR {s} %{d}", .{ sub_file_path: { |
| 996 | const path_digest = block.src_base_inst.resolveFull(&mod.intern_pool).path_digest; |
| 997 | const index = mod.path_digest_map.getIndex(path_digest).?; |
| 998 | break :sub_file_path mod.import_table.values()[index].sub_file_path; |
| 999 | }, inst }); |
| 999 | 1000 | const air_inst: Air.Inst.Ref = switch (tags[@intFromEnum(inst)]) { |
| 1000 | 1001 | // zig fmt: off |
| 1001 | 1002 | .alloc => try sema.zirAlloc(block, inst), |
| ... | ... | @@ -2821,6 +2822,7 @@ fn zirStructDecl( |
| 2821 | 2822 | small.name_strategy, |
| 2822 | 2823 | "struct", |
| 2823 | 2824 | inst, |
| 2825 | extra.data.src_line, |
| 2824 | 2826 | ); |
| 2825 | 2827 | mod.declPtr(new_decl_index).owns_tv = true; |
| 2826 | 2828 | errdefer mod.abortAnonDecl(new_decl_index); |
| ... | ... | @@ -2857,20 +2859,19 @@ fn createAnonymousDeclTypeNamed( |
| 2857 | 2859 | name_strategy: Zir.Inst.NameStrategy, |
| 2858 | 2860 | anon_prefix: []const u8, |
| 2859 | 2861 | inst: ?Zir.Inst.Index, |
| 2862 | src_line: u32, |
| 2860 | 2863 | ) !InternPool.DeclIndex { |
| 2861 | 2864 | const zcu = sema.mod; |
| 2862 | 2865 | const ip = &zcu.intern_pool; |
| 2863 | 2866 | const gpa = sema.gpa; |
| 2864 | 2867 | const namespace = block.namespace; |
| 2865 | | const src_decl = zcu.declPtr(block.src_decl); |
| 2866 | 2868 | const new_decl_index = try zcu.allocateNewDecl(namespace); |
| 2867 | 2869 | errdefer zcu.destroyDecl(new_decl_index); |
| 2868 | 2870 | |
| 2869 | 2871 | switch (name_strategy) { |
| 2870 | 2872 | .anon => {}, // handled after switch |
| 2871 | 2873 | .parent => { |
| 2872 | | const name = zcu.declPtr(block.src_decl).name; |
| 2873 | | try zcu.initNewAnonDecl(new_decl_index, src_decl.src_line, val, name); |
| 2874 | try zcu.initNewAnonDecl(new_decl_index, src_line, val, block.type_name_ctx); |
| 2874 | 2875 | return new_decl_index; |
| 2875 | 2876 | }, |
| 2876 | 2877 | .func => func_strat: { |
| ... | ... | @@ -2881,7 +2882,7 @@ fn createAnonymousDeclTypeNamed( |
| 2881 | 2882 | defer buf.deinit(); |
| 2882 | 2883 | |
| 2883 | 2884 | const writer = buf.writer(); |
| 2884 | | try writer.print("{}(", .{zcu.declPtr(block.src_decl).name.fmt(ip)}); |
| 2885 | try writer.print("{}(", .{block.type_name_ctx.fmt(ip)}); |
| 2885 | 2886 | |
| 2886 | 2887 | var arg_i: usize = 0; |
| 2887 | 2888 | for (fn_info.param_body) |zir_inst| switch (zir_tags[@intFromEnum(zir_inst)]) { |
| ... | ... | @@ -2915,7 +2916,7 @@ fn createAnonymousDeclTypeNamed( |
| 2915 | 2916 | |
| 2916 | 2917 | try writer.writeByte(')'); |
| 2917 | 2918 | const name = try ip.getOrPutString(gpa, buf.items, .no_embedded_nulls); |
| 2918 | | try zcu.initNewAnonDecl(new_decl_index, src_decl.src_line, val, name); |
| 2919 | try zcu.initNewAnonDecl(new_decl_index, src_line, val, name); |
| 2919 | 2920 | return new_decl_index; |
| 2920 | 2921 | }, |
| 2921 | 2922 | .dbg_var => { |
| ... | ... | @@ -2927,9 +2928,9 @@ fn createAnonymousDeclTypeNamed( |
| 2927 | 2928 | if (zir_data[i].str_op.operand != ref) continue; |
| 2928 | 2929 | |
| 2929 | 2930 | const name = try ip.getOrPutStringFmt(gpa, "{}.{s}", .{ |
| 2930 | | src_decl.name.fmt(ip), zir_data[i].str_op.getStr(sema.code), |
| 2931 | block.type_name_ctx.fmt(ip), zir_data[i].str_op.getStr(sema.code), |
| 2931 | 2932 | }, .no_embedded_nulls); |
| 2932 | | try zcu.initNewAnonDecl(new_decl_index, src_decl.src_line, val, name); |
| 2933 | try zcu.initNewAnonDecl(new_decl_index, src_line, val, name); |
| 2933 | 2934 | return new_decl_index; |
| 2934 | 2935 | }, |
| 2935 | 2936 | else => {}, |
| ... | ... | @@ -2948,9 +2949,9 @@ fn createAnonymousDeclTypeNamed( |
| 2948 | 2949 | // renamed. |
| 2949 | 2950 | |
| 2950 | 2951 | const name = ip.getOrPutStringFmt(gpa, "{}__{s}_{d}", .{ |
| 2951 | | src_decl.name.fmt(ip), anon_prefix, @intFromEnum(new_decl_index), |
| 2952 | block.type_name_ctx.fmt(ip), anon_prefix, @intFromEnum(new_decl_index), |
| 2952 | 2953 | }, .no_embedded_nulls) catch unreachable; |
| 2953 | | try zcu.initNewAnonDecl(new_decl_index, src_decl.src_line, val, name); |
| 2954 | try zcu.initNewAnonDecl(new_decl_index, src_line, val, name); |
| 2954 | 2955 | return new_decl_index; |
| 2955 | 2956 | } |
| 2956 | 2957 | |
| ... | ... | @@ -3056,6 +3057,7 @@ fn zirEnumDecl( |
| 3056 | 3057 | small.name_strategy, |
| 3057 | 3058 | "enum", |
| 3058 | 3059 | inst, |
| 3060 | extra.data.src_line, |
| 3059 | 3061 | ); |
| 3060 | 3062 | const new_decl = mod.declPtr(new_decl_index); |
| 3061 | 3063 | new_decl.owns_tv = true; |
| ... | ... | @@ -3112,12 +3114,12 @@ fn zirEnumDecl( |
| 3112 | 3114 | var enum_block: Block = .{ |
| 3113 | 3115 | .parent = null, |
| 3114 | 3116 | .sema = sema, |
| 3115 | | .src_decl = new_decl_index, |
| 3116 | 3117 | .namespace = new_namespace_index.unwrap() orelse block.namespace, |
| 3117 | 3118 | .instructions = .{}, |
| 3118 | 3119 | .inlining = null, |
| 3119 | 3120 | .is_comptime = true, |
| 3120 | 3121 | .src_base_inst = tracked_inst, |
| 3122 | .type_name_ctx = new_decl.name, |
| 3121 | 3123 | }; |
| 3122 | 3124 | defer enum_block.instructions.deinit(sema.gpa); |
| 3123 | 3125 | |
| ... | ... | @@ -3323,6 +3325,7 @@ fn zirUnionDecl( |
| 3323 | 3325 | small.name_strategy, |
| 3324 | 3326 | "union", |
| 3325 | 3327 | inst, |
| 3328 | extra.data.src_line, |
| 3326 | 3329 | ); |
| 3327 | 3330 | mod.declPtr(new_decl_index).owns_tv = true; |
| 3328 | 3331 | errdefer mod.abortAnonDecl(new_decl_index); |
| ... | ... | @@ -3411,6 +3414,7 @@ fn zirOpaqueDecl( |
| 3411 | 3414 | small.name_strategy, |
| 3412 | 3415 | "opaque", |
| 3413 | 3416 | inst, |
| 3417 | extra.data.src_line, |
| 3414 | 3418 | ); |
| 3415 | 3419 | mod.declPtr(new_decl_index).owns_tv = true; |
| 3416 | 3420 | errdefer mod.abortAnonDecl(new_decl_index); |
| ... | ... | @@ -5942,7 +5946,6 @@ fn zirCImport(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileEr |
| 5942 | 5946 | var child_block: Block = .{ |
| 5943 | 5947 | .parent = parent_block, |
| 5944 | 5948 | .sema = sema, |
| 5945 | | .src_decl = parent_block.src_decl, |
| 5946 | 5949 | .namespace = parent_block.namespace, |
| 5947 | 5950 | .instructions = .{}, |
| 5948 | 5951 | .inlining = parent_block.inlining, |
| ... | ... | @@ -5953,6 +5956,7 @@ fn zirCImport(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileEr |
| 5953 | 5956 | .runtime_loop = parent_block.runtime_loop, |
| 5954 | 5957 | .runtime_index = parent_block.runtime_index, |
| 5955 | 5958 | .src_base_inst = parent_block.src_base_inst, |
| 5959 | .type_name_ctx = parent_block.type_name_ctx, |
| 5956 | 5960 | }; |
| 5957 | 5961 | defer child_block.instructions.deinit(gpa); |
| 5958 | 5962 | |
| ... | ... | @@ -6063,7 +6067,6 @@ fn zirBlock(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index, force_compt |
| 6063 | 6067 | var child_block: Block = .{ |
| 6064 | 6068 | .parent = parent_block, |
| 6065 | 6069 | .sema = sema, |
| 6066 | | .src_decl = parent_block.src_decl, |
| 6067 | 6070 | .namespace = parent_block.namespace, |
| 6068 | 6071 | .instructions = .{}, |
| 6069 | 6072 | .label = &label, |
| ... | ... | @@ -6079,6 +6082,7 @@ fn zirBlock(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index, force_compt |
| 6079 | 6082 | .runtime_index = parent_block.runtime_index, |
| 6080 | 6083 | .error_return_trace_index = parent_block.error_return_trace_index, |
| 6081 | 6084 | .src_base_inst = parent_block.src_base_inst, |
| 6085 | .type_name_ctx = parent_block.type_name_ctx, |
| 6082 | 6086 | }; |
| 6083 | 6087 | |
| 6084 | 6088 | defer child_block.instructions.deinit(gpa); |
| ... | ... | @@ -6726,7 +6730,7 @@ fn zirDeclRef(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 6726 | 6730 | .no_embedded_nulls, |
| 6727 | 6731 | ); |
| 6728 | 6732 | const decl_index = try sema.lookupIdentifier(block, src, decl_name); |
| 6729 | | try sema.addReferencedBy(block, src, decl_index); |
| 6733 | try sema.addReferencedBy(src, decl_index); |
| 6730 | 6734 | return sema.analyzeDeclRef(decl_index); |
| 6731 | 6735 | } |
| 6732 | 6736 | |
| ... | ... | @@ -7695,7 +7699,6 @@ fn analyzeCall( |
| 7695 | 7699 | var child_block: Block = .{ |
| 7696 | 7700 | .parent = null, |
| 7697 | 7701 | .sema = sema, |
| 7698 | | .src_decl = module_fn.owner_decl, |
| 7699 | 7702 | .namespace = fn_owner_decl.src_namespace, |
| 7700 | 7703 | .instructions = .{}, |
| 7701 | 7704 | .label = null, |
| ... | ... | @@ -7708,6 +7711,7 @@ fn analyzeCall( |
| 7708 | 7711 | .runtime_loop = block.runtime_loop, |
| 7709 | 7712 | .runtime_index = block.runtime_index, |
| 7710 | 7713 | .src_base_inst = fn_owner_decl.zir_decl_index.unwrap().?, |
| 7714 | .type_name_ctx = fn_owner_decl.name, |
| 7711 | 7715 | }; |
| 7712 | 7716 | |
| 7713 | 7717 | const merges = &child_block.inlining.?.merges; |
| ... | ... | @@ -8217,12 +8221,12 @@ fn instantiateGenericCall( |
| 8217 | 8221 | var child_block: Block = .{ |
| 8218 | 8222 | .parent = null, |
| 8219 | 8223 | .sema = &child_sema, |
| 8220 | | .src_decl = generic_owner_func.owner_decl, |
| 8221 | 8224 | .namespace = namespace_index, |
| 8222 | 8225 | .instructions = .{}, |
| 8223 | 8226 | .inlining = null, |
| 8224 | 8227 | .is_comptime = true, |
| 8225 | 8228 | .src_base_inst = fn_owner_decl.zir_decl_index.unwrap().?, |
| 8229 | .type_name_ctx = fn_owner_decl.name, |
| 8226 | 8230 | }; |
| 8227 | 8231 | defer child_block.instructions.deinit(gpa); |
| 8228 | 8232 | |
| ... | ... | @@ -8366,7 +8370,7 @@ fn instantiateGenericCall( |
| 8366 | 8370 | const callee = mod.funcInfo(callee_index); |
| 8367 | 8371 | callee.branchQuota(ip).* = @max(callee.branchQuota(ip).*, sema.branch_quota); |
| 8368 | 8372 | |
| 8369 | | try sema.addReferencedBy(block, call_src, callee.owner_decl); |
| 8373 | try sema.addReferencedBy(call_src, callee.owner_decl); |
| 8370 | 8374 | |
| 8371 | 8375 | // Make a runtime call to the new function, making sure to omit the comptime args. |
| 8372 | 8376 | const func_ty = Type.fromInterned(callee.ty); |
| ... | ... | @@ -9346,7 +9350,7 @@ fn zirFunc( |
| 9346 | 9350 | // If this instruction has a body it means it's the type of the `owner_decl` |
| 9347 | 9351 | // otherwise it's a function type without a `callconv` attribute and should |
| 9348 | 9352 | // never be `.C`. |
| 9349 | | const cc: std.builtin.CallingConvention = if (has_body and mod.declPtr(block.src_decl).is_exported) |
| 9353 | const cc: std.builtin.CallingConvention = if (has_body and mod.declPtr(sema.owner_decl_index).is_exported) |
| 9350 | 9354 | .C |
| 9351 | 9355 | else |
| 9352 | 9356 | .Unspecified; |
| ... | ... | @@ -11595,7 +11599,6 @@ fn zirSwitchBlockErrUnion(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp |
| 11595 | 11599 | var child_block: Block = .{ |
| 11596 | 11600 | .parent = block, |
| 11597 | 11601 | .sema = sema, |
| 11598 | | .src_decl = block.src_decl, |
| 11599 | 11602 | .namespace = block.namespace, |
| 11600 | 11603 | .instructions = .{}, |
| 11601 | 11604 | .label = &label, |
| ... | ... | @@ -11610,6 +11613,7 @@ fn zirSwitchBlockErrUnion(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp |
| 11610 | 11613 | .error_return_trace_index = block.error_return_trace_index, |
| 11611 | 11614 | .want_safety = block.want_safety, |
| 11612 | 11615 | .src_base_inst = block.src_base_inst, |
| 11616 | .type_name_ctx = block.type_name_ctx, |
| 11613 | 11617 | }; |
| 11614 | 11618 | const merges = &child_block.label.?.merges; |
| 11615 | 11619 | defer child_block.instructions.deinit(gpa); |
| ... | ... | @@ -12327,7 +12331,6 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 12327 | 12331 | var child_block: Block = .{ |
| 12328 | 12332 | .parent = block, |
| 12329 | 12333 | .sema = sema, |
| 12330 | | .src_decl = block.src_decl, |
| 12331 | 12334 | .namespace = block.namespace, |
| 12332 | 12335 | .instructions = .{}, |
| 12333 | 12336 | .label = &label, |
| ... | ... | @@ -12342,6 +12345,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 12342 | 12345 | .want_safety = block.want_safety, |
| 12343 | 12346 | .error_return_trace_index = block.error_return_trace_index, |
| 12344 | 12347 | .src_base_inst = block.src_base_inst, |
| 12348 | .type_name_ctx = block.type_name_ctx, |
| 12345 | 12349 | }; |
| 12346 | 12350 | const merges = &child_block.label.?.merges; |
| 12347 | 12351 | defer child_block.instructions.deinit(gpa); |
| ... | ... | @@ -18843,7 +18847,6 @@ fn zirTypeofBuiltin(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr |
| 18843 | 18847 | var child_block: Block = .{ |
| 18844 | 18848 | .parent = block, |
| 18845 | 18849 | .sema = sema, |
| 18846 | | .src_decl = block.src_decl, |
| 18847 | 18850 | .namespace = block.namespace, |
| 18848 | 18851 | .instructions = .{}, |
| 18849 | 18852 | .inlining = block.inlining, |
| ... | ... | @@ -18852,6 +18855,7 @@ fn zirTypeofBuiltin(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr |
| 18852 | 18855 | .want_safety = false, |
| 18853 | 18856 | .error_return_trace_index = block.error_return_trace_index, |
| 18854 | 18857 | .src_base_inst = block.src_base_inst, |
| 18858 | .type_name_ctx = block.type_name_ctx, |
| 18855 | 18859 | }; |
| 18856 | 18860 | defer child_block.instructions.deinit(sema.gpa); |
| 18857 | 18861 | |
| ... | ... | @@ -18922,7 +18926,6 @@ fn zirTypeofPeer( |
| 18922 | 18926 | var child_block: Block = .{ |
| 18923 | 18927 | .parent = block, |
| 18924 | 18928 | .sema = sema, |
| 18925 | | .src_decl = block.src_decl, |
| 18926 | 18929 | .namespace = block.namespace, |
| 18927 | 18930 | .instructions = .{}, |
| 18928 | 18931 | .inlining = block.inlining, |
| ... | ... | @@ -18932,6 +18935,7 @@ fn zirTypeofPeer( |
| 18932 | 18935 | .runtime_loop = block.runtime_loop, |
| 18933 | 18936 | .runtime_index = block.runtime_index, |
| 18934 | 18937 | .src_base_inst = block.src_base_inst, |
| 18938 | .type_name_ctx = block.type_name_ctx, |
| 18935 | 18939 | }; |
| 18936 | 18940 | defer child_block.instructions.deinit(sema.gpa); |
| 18937 | 18941 | // Ignore the result, we only care about the instructions in `args`. |
| ... | ... | @@ -19398,13 +19402,13 @@ fn ensurePostHoc(sema: *Sema, block: *Block, dest_block: Zir.Inst.Index) !*Label |
| 19398 | 19402 | .block = .{ |
| 19399 | 19403 | .parent = block, |
| 19400 | 19404 | .sema = sema, |
| 19401 | | .src_decl = block.src_decl, |
| 19402 | 19405 | .namespace = block.namespace, |
| 19403 | 19406 | .instructions = .{}, |
| 19404 | 19407 | .label = &labeled_block.label, |
| 19405 | 19408 | .inlining = block.inlining, |
| 19406 | 19409 | .is_comptime = block.is_comptime, |
| 19407 | 19410 | .src_base_inst = block.src_base_inst, |
| 19411 | .type_name_ctx = block.type_name_ctx, |
| 19408 | 19412 | }, |
| 19409 | 19413 | }; |
| 19410 | 19414 | sema.post_hoc_blocks.putAssumeCapacityNoClobber(new_block_inst, labeled_block); |
| ... | ... | @@ -21201,7 +21205,7 @@ fn zirReify( |
| 21201 | 21205 | const gpa = sema.gpa; |
| 21202 | 21206 | const ip = &mod.intern_pool; |
| 21203 | 21207 | const name_strategy: Zir.Inst.NameStrategy = @enumFromInt(extended.small); |
| 21204 | | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; |
| 21208 | const extra = sema.code.extraData(Zir.Inst.Reify, extended.operand).data; |
| 21205 | 21209 | const src = block.nodeOffset(extra.node); |
| 21206 | 21210 | const type_info_ty = try sema.getBuiltinType("Type"); |
| 21207 | 21211 | const uncasted_operand = try sema.resolveInst(extra.operand); |
| ... | ... | @@ -21521,7 +21525,7 @@ fn zirReify( |
| 21521 | 21525 | .needed_comptime_reason = "struct fields must be comptime-known", |
| 21522 | 21526 | }); |
| 21523 | 21527 | |
| 21524 | | return try sema.reifyStruct(block, inst, src, layout, backing_integer_val, fields_arr, name_strategy, is_tuple_val.toBool()); |
| 21528 | return try sema.reifyStruct(block, inst, src, layout, backing_integer_val, fields_arr, name_strategy, is_tuple_val.toBool(), extra.src_line); |
| 21525 | 21529 | }, |
| 21526 | 21530 | .Enum => { |
| 21527 | 21531 | const struct_type = ip.loadStructType(ip.typeOf(union_val.val)); |
| ... | ... | @@ -21550,7 +21554,7 @@ fn zirReify( |
| 21550 | 21554 | .needed_comptime_reason = "enum fields must be comptime-known", |
| 21551 | 21555 | }); |
| 21552 | 21556 | |
| 21553 | | return sema.reifyEnum(block, inst, src, tag_type_val.toType(), is_exhaustive_val.toBool(), fields_arr, name_strategy); |
| 21557 | return sema.reifyEnum(block, inst, src, tag_type_val.toType(), is_exhaustive_val.toBool(), fields_arr, name_strategy, extra.src_line); |
| 21554 | 21558 | }, |
| 21555 | 21559 | .Opaque => { |
| 21556 | 21560 | const struct_type = ip.loadStructType(ip.typeOf(union_val.val)); |
| ... | ... | @@ -21581,6 +21585,7 @@ fn zirReify( |
| 21581 | 21585 | name_strategy, |
| 21582 | 21586 | "opaque", |
| 21583 | 21587 | inst, |
| 21588 | extra.src_line, |
| 21584 | 21589 | ); |
| 21585 | 21590 | mod.declPtr(new_decl_index).owns_tv = true; |
| 21586 | 21591 | errdefer mod.abortAnonDecl(new_decl_index); |
| ... | ... | @@ -21617,7 +21622,7 @@ fn zirReify( |
| 21617 | 21622 | .needed_comptime_reason = "union fields must be comptime-known", |
| 21618 | 21623 | }); |
| 21619 | 21624 | |
| 21620 | | return sema.reifyUnion(block, inst, src, layout, tag_type_val, fields_arr, name_strategy); |
| 21625 | return sema.reifyUnion(block, inst, src, layout, tag_type_val, fields_arr, name_strategy, extra.src_line); |
| 21621 | 21626 | }, |
| 21622 | 21627 | .Fn => { |
| 21623 | 21628 | const struct_type = ip.loadStructType(ip.typeOf(union_val.val)); |
| ... | ... | @@ -21719,6 +21724,7 @@ fn reifyEnum( |
| 21719 | 21724 | is_exhaustive: bool, |
| 21720 | 21725 | fields_val: Value, |
| 21721 | 21726 | name_strategy: Zir.Inst.NameStrategy, |
| 21727 | src_line: u32, |
| 21722 | 21728 | ) CompileError!Air.Inst.Ref { |
| 21723 | 21729 | const mod = sema.mod; |
| 21724 | 21730 | const gpa = sema.gpa; |
| ... | ... | @@ -21780,6 +21786,7 @@ fn reifyEnum( |
| 21780 | 21786 | name_strategy, |
| 21781 | 21787 | "enum", |
| 21782 | 21788 | inst, |
| 21789 | src_line, |
| 21783 | 21790 | ); |
| 21784 | 21791 | mod.declPtr(new_decl_index).owns_tv = true; |
| 21785 | 21792 | errdefer mod.abortAnonDecl(new_decl_index); |
| ... | ... | @@ -21843,6 +21850,7 @@ fn reifyUnion( |
| 21843 | 21850 | opt_tag_type_val: Value, |
| 21844 | 21851 | fields_val: Value, |
| 21845 | 21852 | name_strategy: Zir.Inst.NameStrategy, |
| 21853 | src_line: u32, |
| 21846 | 21854 | ) CompileError!Air.Inst.Ref { |
| 21847 | 21855 | const mod = sema.mod; |
| 21848 | 21856 | const gpa = sema.gpa; |
| ... | ... | @@ -21926,6 +21934,7 @@ fn reifyUnion( |
| 21926 | 21934 | name_strategy, |
| 21927 | 21935 | "union", |
| 21928 | 21936 | inst, |
| 21937 | src_line, |
| 21929 | 21938 | ); |
| 21930 | 21939 | mod.declPtr(new_decl_index).owns_tv = true; |
| 21931 | 21940 | errdefer mod.abortAnonDecl(new_decl_index); |
| ... | ... | @@ -22021,7 +22030,7 @@ fn reifyUnion( |
| 22021 | 22030 | } |
| 22022 | 22031 | } |
| 22023 | 22032 | |
| 22024 | | const enum_tag_ty = try sema.generateUnionTagTypeSimple(block, field_names.keys(), mod.declPtr(new_decl_index)); |
| 22033 | const enum_tag_ty = try sema.generateUnionTagTypeSimple(block, field_names.keys(), mod.declPtr(new_decl_index), src_line); |
| 22025 | 22034 | break :tag_ty .{ enum_tag_ty, false }; |
| 22026 | 22035 | }; |
| 22027 | 22036 | errdefer if (!has_explicit_tag) ip.remove(enum_tag_ty); // remove generated tag type on error |
| ... | ... | @@ -22082,6 +22091,7 @@ fn reifyStruct( |
| 22082 | 22091 | fields_val: Value, |
| 22083 | 22092 | name_strategy: Zir.Inst.NameStrategy, |
| 22084 | 22093 | is_tuple: bool, |
| 22094 | src_line: u32, |
| 22085 | 22095 | ) CompileError!Air.Inst.Ref { |
| 22086 | 22096 | const mod = sema.mod; |
| 22087 | 22097 | const gpa = sema.gpa; |
| ... | ... | @@ -22182,6 +22192,7 @@ fn reifyStruct( |
| 22182 | 22192 | name_strategy, |
| 22183 | 22193 | "struct", |
| 22184 | 22194 | inst, |
| 22195 | src_line, |
| 22185 | 22196 | ); |
| 22186 | 22197 | mod.declPtr(new_decl_index).owns_tv = true; |
| 22187 | 22198 | errdefer mod.abortAnonDecl(new_decl_index); |
| ... | ... | @@ -26903,12 +26914,12 @@ fn addSafetyCheck( |
| 26903 | 26914 | var fail_block: Block = .{ |
| 26904 | 26915 | .parent = parent_block, |
| 26905 | 26916 | .sema = sema, |
| 26906 | | .src_decl = parent_block.src_decl, |
| 26907 | 26917 | .namespace = parent_block.namespace, |
| 26908 | 26918 | .instructions = .{}, |
| 26909 | 26919 | .inlining = parent_block.inlining, |
| 26910 | 26920 | .is_comptime = false, |
| 26911 | 26921 | .src_base_inst = parent_block.src_base_inst, |
| 26922 | .type_name_ctx = parent_block.type_name_ctx, |
| 26912 | 26923 | }; |
| 26913 | 26924 | |
| 26914 | 26925 | defer fail_block.instructions.deinit(gpa); |
| ... | ... | @@ -27012,12 +27023,12 @@ fn panicUnwrapError( |
| 27012 | 27023 | var fail_block: Block = .{ |
| 27013 | 27024 | .parent = parent_block, |
| 27014 | 27025 | .sema = sema, |
| 27015 | | .src_decl = parent_block.src_decl, |
| 27016 | 27026 | .namespace = parent_block.namespace, |
| 27017 | 27027 | .instructions = .{}, |
| 27018 | 27028 | .inlining = parent_block.inlining, |
| 27019 | 27029 | .is_comptime = false, |
| 27020 | 27030 | .src_base_inst = parent_block.src_base_inst, |
| 27031 | .type_name_ctx = parent_block.type_name_ctx, |
| 27021 | 27032 | }; |
| 27022 | 27033 | |
| 27023 | 27034 | defer fail_block.instructions.deinit(gpa); |
| ... | ... | @@ -27129,12 +27140,12 @@ fn safetyCheckFormatted( |
| 27129 | 27140 | var fail_block: Block = .{ |
| 27130 | 27141 | .parent = parent_block, |
| 27131 | 27142 | .sema = sema, |
| 27132 | | .src_decl = parent_block.src_decl, |
| 27133 | 27143 | .namespace = parent_block.namespace, |
| 27134 | 27144 | .instructions = .{}, |
| 27135 | 27145 | .inlining = parent_block.inlining, |
| 27136 | 27146 | .is_comptime = false, |
| 27137 | 27147 | .src_base_inst = parent_block.src_base_inst, |
| 27148 | .type_name_ctx = parent_block.type_name_ctx, |
| 27138 | 27149 | }; |
| 27139 | 27150 | |
| 27140 | 27151 | defer fail_block.instructions.deinit(gpa); |
| ... | ... | @@ -27682,7 +27693,7 @@ fn fieldCallBind( |
| 27682 | 27693 | const decl_idx = (try sema.namespaceLookup(block, src, namespace, field_name)) orelse |
| 27683 | 27694 | break :found_decl null; |
| 27684 | 27695 | |
| 27685 | | try sema.addReferencedBy(block, src, decl_idx); |
| 27696 | try sema.addReferencedBy(src, decl_idx); |
| 27686 | 27697 | const decl_val = try sema.analyzeDeclVal(block, src, decl_idx); |
| 27687 | 27698 | const decl_type = sema.typeOf(decl_val); |
| 27688 | 27699 | if (mod.typeToFunc(decl_type)) |func_type| f: { |
| ... | ... | @@ -27838,7 +27849,7 @@ fn namespaceLookupRef( |
| 27838 | 27849 | decl_name: InternPool.NullTerminatedString, |
| 27839 | 27850 | ) CompileError!?Air.Inst.Ref { |
| 27840 | 27851 | const decl = (try sema.namespaceLookup(block, src, opt_namespace, decl_name)) orelse return null; |
| 27841 | | try sema.addReferencedBy(block, src, decl); |
| 27852 | try sema.addReferencedBy(src, decl); |
| 27842 | 27853 | return try sema.analyzeDeclRef(decl); |
| 27843 | 27854 | } |
| 27844 | 27855 | |
| ... | ... | @@ -31757,7 +31768,7 @@ fn analyzeDeclVal( |
| 31757 | 31768 | src: LazySrcLoc, |
| 31758 | 31769 | decl_index: InternPool.DeclIndex, |
| 31759 | 31770 | ) CompileError!Air.Inst.Ref { |
| 31760 | | try sema.addReferencedBy(block, src, decl_index); |
| 31771 | try sema.addReferencedBy(src, decl_index); |
| 31761 | 31772 | if (sema.decl_val_table.get(decl_index)) |result| { |
| 31762 | 31773 | return result; |
| 31763 | 31774 | } |
| ... | ... | @@ -31773,13 +31784,14 @@ fn analyzeDeclVal( |
| 31773 | 31784 | |
| 31774 | 31785 | fn addReferencedBy( |
| 31775 | 31786 | sema: *Sema, |
| 31776 | | block: *Block, |
| 31777 | 31787 | src: LazySrcLoc, |
| 31778 | 31788 | decl_index: InternPool.DeclIndex, |
| 31779 | 31789 | ) !void { |
| 31780 | 31790 | if (sema.mod.comp.reference_trace == 0) return; |
| 31781 | 31791 | try sema.mod.reference_table.put(sema.gpa, decl_index, .{ |
| 31782 | | .referencer = block.src_decl, |
| 31792 | // TODO: this can make the reference trace suboptimal. This will be fixed |
| 31793 | // once the reference table is reworked for incremental compilation. |
| 31794 | .referencer = sema.owner_decl_index, |
| 31783 | 31795 | .src = src, |
| 31784 | 31796 | }); |
| 31785 | 31797 | } |
| ... | ... | @@ -35181,12 +35193,12 @@ fn semaBackingIntType(mod: *Module, struct_type: InternPool.LoadedStructType) Co |
| 35181 | 35193 | var block: Block = .{ |
| 35182 | 35194 | .parent = null, |
| 35183 | 35195 | .sema = &sema, |
| 35184 | | .src_decl = decl_index, |
| 35185 | 35196 | .namespace = struct_type.namespace.unwrap() orelse decl.src_namespace, |
| 35186 | 35197 | .instructions = .{}, |
| 35187 | 35198 | .inlining = null, |
| 35188 | 35199 | .is_comptime = true, |
| 35189 | 35200 | .src_base_inst = struct_type.zir_index.unwrap().?, |
| 35201 | .type_name_ctx = decl.name, |
| 35190 | 35202 | }; |
| 35191 | 35203 | defer assert(block.instructions.items.len == 0); |
| 35192 | 35204 | |
| ... | ... | @@ -36036,12 +36048,12 @@ fn semaStructFields( |
| 36036 | 36048 | var block_scope: Block = .{ |
| 36037 | 36049 | .parent = null, |
| 36038 | 36050 | .sema = &sema, |
| 36039 | | .src_decl = decl_index, |
| 36040 | 36051 | .namespace = namespace_index, |
| 36041 | 36052 | .instructions = .{}, |
| 36042 | 36053 | .inlining = null, |
| 36043 | 36054 | .is_comptime = true, |
| 36044 | 36055 | .src_base_inst = struct_type.zir_index.unwrap().?, |
| 36056 | .type_name_ctx = decl.name, |
| 36045 | 36057 | }; |
| 36046 | 36058 | defer assert(block_scope.instructions.items.len == 0); |
| 36047 | 36059 | |
| ... | ... | @@ -36247,12 +36259,12 @@ fn semaStructFieldInits( |
| 36247 | 36259 | var block_scope: Block = .{ |
| 36248 | 36260 | .parent = null, |
| 36249 | 36261 | .sema = &sema, |
| 36250 | | .src_decl = decl_index, |
| 36251 | 36262 | .namespace = namespace_index, |
| 36252 | 36263 | .instructions = .{}, |
| 36253 | 36264 | .inlining = null, |
| 36254 | 36265 | .is_comptime = true, |
| 36255 | 36266 | .src_base_inst = struct_type.zir_index.unwrap().?, |
| 36267 | .type_name_ctx = decl.name, |
| 36256 | 36268 | }; |
| 36257 | 36269 | defer assert(block_scope.instructions.items.len == 0); |
| 36258 | 36270 | |
| ... | ... | @@ -36359,7 +36371,8 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded |
| 36359 | 36371 | const extended = zir.instructions.items(.data)[@intFromEnum(zir_index)].extended; |
| 36360 | 36372 | assert(extended.opcode == .union_decl); |
| 36361 | 36373 | const small: Zir.Inst.UnionDecl.Small = @bitCast(extended.small); |
| 36362 | | var extra_index: usize = extended.operand + @typeInfo(Zir.Inst.UnionDecl).Struct.fields.len; |
| 36374 | const extra = zir.extraData(Zir.Inst.UnionDecl, extended.operand); |
| 36375 | var extra_index: usize = extra.end; |
| 36363 | 36376 | |
| 36364 | 36377 | const tag_type_ref: Zir.Inst.Ref = if (small.has_tag_type) blk: { |
| 36365 | 36378 | const ty_ref: Zir.Inst.Ref = @enumFromInt(zir.extra[extra_index]); |
| ... | ... | @@ -36421,12 +36434,12 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded |
| 36421 | 36434 | var block_scope: Block = .{ |
| 36422 | 36435 | .parent = null, |
| 36423 | 36436 | .sema = &sema, |
| 36424 | | .src_decl = decl_index, |
| 36425 | 36437 | .namespace = union_type.namespace.unwrap().?, |
| 36426 | 36438 | .instructions = .{}, |
| 36427 | 36439 | .inlining = null, |
| 36428 | 36440 | .is_comptime = true, |
| 36429 | 36441 | .src_base_inst = union_type.zir_index, |
| 36442 | .type_name_ctx = decl.name, |
| 36430 | 36443 | }; |
| 36431 | 36444 | defer assert(block_scope.instructions.items.len == 0); |
| 36432 | 36445 | |
| ... | ... | @@ -36711,10 +36724,10 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded |
| 36711 | 36724 | return sema.failWithOwnedErrorMsg(&block_scope, msg); |
| 36712 | 36725 | } |
| 36713 | 36726 | } else if (enum_field_vals.count() > 0) { |
| 36714 | | const enum_ty = try sema.generateUnionTagTypeNumbered(&block_scope, enum_field_names, enum_field_vals.keys(), mod.declPtr(union_type.decl)); |
| 36727 | const enum_ty = try sema.generateUnionTagTypeNumbered(&block_scope, enum_field_names, enum_field_vals.keys(), mod.declPtr(union_type.decl), extra.data.src_line); |
| 36715 | 36728 | union_type.tagTypePtr(ip).* = enum_ty; |
| 36716 | 36729 | } else { |
| 36717 | | const enum_ty = try sema.generateUnionTagTypeSimple(&block_scope, enum_field_names, mod.declPtr(union_type.decl)); |
| 36730 | const enum_ty = try sema.generateUnionTagTypeSimple(&block_scope, enum_field_names, mod.declPtr(union_type.decl), extra.data.src_line); |
| 36718 | 36731 | union_type.tagTypePtr(ip).* = enum_ty; |
| 36719 | 36732 | } |
| 36720 | 36733 | } |
| ... | ... | @@ -36732,12 +36745,12 @@ fn generateUnionTagTypeNumbered( |
| 36732 | 36745 | enum_field_names: []const InternPool.NullTerminatedString, |
| 36733 | 36746 | enum_field_vals: []const InternPool.Index, |
| 36734 | 36747 | union_owner_decl: *Module.Decl, |
| 36748 | src_line: u32, |
| 36735 | 36749 | ) !InternPool.Index { |
| 36736 | 36750 | const mod = sema.mod; |
| 36737 | 36751 | const gpa = sema.gpa; |
| 36738 | 36752 | const ip = &mod.intern_pool; |
| 36739 | 36753 | |
| 36740 | | const src_decl = mod.declPtr(block.src_decl); |
| 36741 | 36754 | const new_decl_index = try mod.allocateNewDecl(block.namespace); |
| 36742 | 36755 | errdefer mod.destroyDecl(new_decl_index); |
| 36743 | 36756 | const fqn = try union_owner_decl.fullyQualifiedName(mod); |
| ... | ... | @@ -36749,7 +36762,7 @@ fn generateUnionTagTypeNumbered( |
| 36749 | 36762 | ); |
| 36750 | 36763 | try mod.initNewAnonDecl( |
| 36751 | 36764 | new_decl_index, |
| 36752 | | src_decl.src_line, |
| 36765 | src_line, |
| 36753 | 36766 | Value.@"unreachable", |
| 36754 | 36767 | name, |
| 36755 | 36768 | ); |
| ... | ... | @@ -36782,6 +36795,7 @@ fn generateUnionTagTypeSimple( |
| 36782 | 36795 | block: *Block, |
| 36783 | 36796 | enum_field_names: []const InternPool.NullTerminatedString, |
| 36784 | 36797 | union_owner_decl: *Module.Decl, |
| 36798 | src_line: u32, |
| 36785 | 36799 | ) !InternPool.Index { |
| 36786 | 36800 | const mod = sema.mod; |
| 36787 | 36801 | const ip = &mod.intern_pool; |
| ... | ... | @@ -36789,7 +36803,6 @@ fn generateUnionTagTypeSimple( |
| 36789 | 36803 | |
| 36790 | 36804 | const new_decl_index = new_decl_index: { |
| 36791 | 36805 | const fqn = try union_owner_decl.fullyQualifiedName(mod); |
| 36792 | | const src_decl = mod.declPtr(block.src_decl); |
| 36793 | 36806 | const new_decl_index = try mod.allocateNewDecl(block.namespace); |
| 36794 | 36807 | errdefer mod.destroyDecl(new_decl_index); |
| 36795 | 36808 | const name = try ip.getOrPutStringFmt( |
| ... | ... | @@ -36800,7 +36813,7 @@ fn generateUnionTagTypeSimple( |
| 36800 | 36813 | ); |
| 36801 | 36814 | try mod.initNewAnonDecl( |
| 36802 | 36815 | new_decl_index, |
| 36803 | | src_decl.src_line, |
| 36816 | src_line, |
| 36804 | 36817 | Value.@"unreachable", |
| 36805 | 36818 | name, |
| 36806 | 36819 | ); |
| ... | ... | @@ -36835,7 +36848,6 @@ fn getBuiltin(sema: *Sema, name: []const u8) CompileError!Air.Inst.Ref { |
| 36835 | 36848 | var block: Block = .{ |
| 36836 | 36849 | .parent = null, |
| 36837 | 36850 | .sema = sema, |
| 36838 | | .src_decl = sema.owner_decl_index, |
| 36839 | 36851 | .namespace = sema.owner_decl.src_namespace, |
| 36840 | 36852 | .instructions = .{}, |
| 36841 | 36853 | .inlining = null, |
| ... | ... | @@ -36853,6 +36865,7 @@ fn getBuiltin(sema: *Sema, name: []const u8) CompileError!Air.Inst.Ref { |
| 36853 | 36865 | else => unreachable, |
| 36854 | 36866 | } |
| 36855 | 36867 | }, |
| 36868 | .type_name_ctx = sema.owner_decl.name, |
| 36856 | 36869 | }; |
| 36857 | 36870 | defer block.instructions.deinit(sema.gpa); |
| 36858 | 36871 | |
| ... | ... | @@ -36898,7 +36911,6 @@ fn getBuiltinType(sema: *Sema, name: []const u8) CompileError!Type { |
| 36898 | 36911 | var block: Block = .{ |
| 36899 | 36912 | .parent = null, |
| 36900 | 36913 | .sema = sema, |
| 36901 | | .src_decl = sema.owner_decl_index, |
| 36902 | 36914 | .namespace = sema.owner_decl.src_namespace, |
| 36903 | 36915 | .instructions = .{}, |
| 36904 | 36916 | .inlining = null, |
| ... | ... | @@ -36916,6 +36928,7 @@ fn getBuiltinType(sema: *Sema, name: []const u8) CompileError!Type { |
| 36916 | 36928 | else => unreachable, |
| 36917 | 36929 | } |
| 36918 | 36930 | }, |
| 36931 | .type_name_ctx = sema.owner_decl.name, |
| 36919 | 36932 | }; |
| 36920 | 36933 | defer block.instructions.deinit(sema.gpa); |
| 36921 | 36934 | |