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