diff options
| author | mlugg <mlugg@mlugg.co.uk> | 2024-02-13 01:54:57 +0000 |
|---|---|---|
| committer | mlugg <mlugg@mlugg.co.uk> | 2024-02-16 11:26:33 +0000 |
| commit | 434537213e406191959818f573b24ca45c1b0e45 (patch) | |
| tree | 5892fc8f71a48ef1188cee96112a5d7a5706c14f /src/Sema.zig | |
| parent | aba29f9789aff0c1ace2a1d0031818ec2c04070c (diff) | |
| download | zig-434537213e406191959818f573b24ca45c1b0e45.tar.gz zig-434537213e406191959818f573b24ca45c1b0e45.zip | |
Sema: eliminate `src` field
`sema.src` is a failed experiment. It introduces complexity, and makes
often unwarranted assumptions about the existence of instructions
providing source locations, requiring an unreasonable amount of caution
in AstGen for correctness. Eliminating it simplifies the whole frontend.
This required adding source locations to a few instructions, but the
cost in ZIR bytes should be counteracted by the other work on this
branch.
Diffstat (limited to 'src/Sema.zig')
| -rw-r--r-- | src/Sema.zig | 157 |
1 files changed, 71 insertions, 86 deletions
diff --git a/src/Sema.zig b/src/Sema.zig index 874c83ae0c..e0ff94ec83 100644 --- a/src/Sema.zig +++ b/src/Sema.zig @@ -50,11 +50,6 @@ branch_count: u32 = 0, /// Populated when returning `error.ComptimeBreak`. Used to communicate the /// break instruction up the stack to find the corresponding Block. comptime_break_inst: Zir.Inst.Index = undefined, -/// This field is updated when a new source location becomes active, so that -/// instructions which do not have explicitly mapped source locations still have -/// access to the source location set by the previous instruction which did -/// contain a mapped source location. -src: LazySrcLoc = .{ .token_offset = 0 }, decl_val_table: std.AutoHashMapUnmanaged(InternPool.DeclIndex, Air.Inst.Ref) = .{}, /// When doing a generic function instantiation, this array collects a value /// for each parameter of the generic owner. `none` for non-comptime parameters. @@ -1006,10 +1001,10 @@ fn analyzeBodyInner( const air_inst: Air.Inst.Ref = switch (tags[@intFromEnum(inst)]) { // zig fmt: off .alloc => try sema.zirAlloc(block, inst), - .alloc_inferred => try sema.zirAllocInferred(block, inst, true), - .alloc_inferred_mut => try sema.zirAllocInferred(block, inst, false), - .alloc_inferred_comptime => try sema.zirAllocInferredComptime(inst, true), - .alloc_inferred_comptime_mut => try sema.zirAllocInferredComptime(inst, false), + .alloc_inferred => try sema.zirAllocInferred(block, true), + .alloc_inferred_mut => try sema.zirAllocInferred(block, false), + .alloc_inferred_comptime => try sema.zirAllocInferredComptime(true), + .alloc_inferred_comptime_mut => try sema.zirAllocInferredComptime(false), .alloc_mut => try sema.zirAllocMut(block, inst), .alloc_comptime_mut => try sema.zirAllocComptime(block, inst), .make_ptr_const => try sema.zirMakePtrConst(block, inst), @@ -1308,6 +1303,11 @@ fn analyzeBodyInner( i += 1; continue; }, + .restore_err_ret_index => { + try sema.zirRestoreErrRetIndex(block, extended); + i += 1; + continue; + }, .value_placeholder => unreachable, // never appears in a body }; }, @@ -1369,11 +1369,6 @@ fn analyzeBodyInner( i += 1; continue; }, - .store => { - try sema.zirStore(block, inst); - i += 1; - continue; - }, .store_node => { try sema.zirStoreNode(block, inst); i += 1; @@ -1518,8 +1513,15 @@ fn analyzeBodyInner( i += 1; continue; }, - .restore_err_ret_index => { - try sema.zirRestoreErrRetIndex(block, inst); + .restore_err_ret_index_unconditional => { + const un_node = datas[@intFromEnum(inst)].un_node; + try sema.restoreErrRetIndex(block, un_node.src(), un_node.operand, .none); + i += 1; + continue; + }, + .restore_err_ret_index_fn_entry => { + const un_node = datas[@intFromEnum(inst)].un_node; + try sema.restoreErrRetIndex(block, un_node.src(), .none, un_node.operand); i += 1; continue; }, @@ -2779,7 +2781,7 @@ fn zirStructDecl( const src: LazySrcLoc = if (small.has_src_node) blk: { const node_offset: i32 = @bitCast(sema.code.extra[extended.operand + @typeInfo(Zir.Inst.StructDecl).Struct.fields.len]); break :blk LazySrcLoc.nodeOffset(node_offset); - } else sema.src; + } else unreachable; // MLUGG TODO // Because these three things each reference each other, `undefined` // placeholders are used before being set after the struct type gains an @@ -2945,7 +2947,7 @@ fn zirEnumDecl( const node_offset: i32 = @bitCast(sema.code.extra[extra_index]); extra_index += 1; break :blk LazySrcLoc.nodeOffset(node_offset); - } else sema.src; + } else unreachable; // MLUGG TODO const tag_ty_src: LazySrcLoc = .{ .node_offset_container_tag = src.node_offset.x }; const tag_type_ref = if (small.has_tag_type) blk: { @@ -3218,7 +3220,7 @@ fn zirUnionDecl( const node_offset: i32 = @bitCast(sema.code.extra[extra_index]); extra_index += 1; break :blk LazySrcLoc.nodeOffset(node_offset); - } else sema.src; + } else unreachable; // MLUGG TODO extra_index += @intFromBool(small.has_tag_type); extra_index += @intFromBool(small.has_body_len); @@ -3327,7 +3329,7 @@ fn zirOpaqueDecl( const node_offset: i32 = @bitCast(sema.code.extra[extra_index]); extra_index += 1; break :blk LazySrcLoc.nodeOffset(node_offset); - } else sema.src; + } else unreachable; // MLUGG TODO const decls_len = if (small.has_decls_len) blk: { const decls_len = sema.code.extra[extra_index]; @@ -3977,13 +3979,9 @@ fn makePtrConst(sema: *Sema, block: *Block, alloc: Air.Inst.Ref) CompileError!Ai fn zirAllocInferredComptime( sema: *Sema, - inst: Zir.Inst.Index, is_const: bool, ) CompileError!Air.Inst.Ref { const gpa = sema.gpa; - const src_node = sema.code.instructions.items(.data)[@intFromEnum(inst)].node; - const src = LazySrcLoc.nodeOffset(src_node); - sema.src = src; try sema.air_instructions.append(gpa, .{ .tag = .inferred_alloc_comptime, @@ -4042,16 +4040,12 @@ fn zirAllocMut(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai fn zirAllocInferred( sema: *Sema, block: *Block, - inst: Zir.Inst.Index, is_const: bool, ) CompileError!Air.Inst.Ref { const tracy = trace(@src()); defer tracy.end(); const gpa = sema.gpa; - const src_node = sema.code.instructions.items(.data)[@intFromEnum(inst)].node; - const src = LazySrcLoc.nodeOffset(src_node); - sema.src = src; if (block.is_comptime) { try sema.air_instructions.append(gpa, .{ @@ -5428,10 +5422,11 @@ fn zirStoreToInferredPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compi const tracy = trace(@src()); defer tracy.end(); - const src: LazySrcLoc = sema.src; - const bin_inst = sema.code.instructions.items(.data)[@intFromEnum(inst)].bin; - const ptr = try sema.resolveInst(bin_inst.lhs); - const operand = try sema.resolveInst(bin_inst.rhs); + const pl_node = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; + const src = pl_node.src(); + const bin = sema.code.extraData(Zir.Inst.Bin, pl_node.payload_index).data; + const ptr = try sema.resolveInst(bin.lhs); + const operand = try sema.resolveInst(bin.rhs); const ptr_inst = ptr.toIndex().?; const air_datas = sema.air_instructions.items(.data); @@ -5496,16 +5491,6 @@ fn zirSetEvalBranchQuota(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compi sema.branch_quota = @max(sema.branch_quota, quota); } -fn zirStore(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void { - const tracy = trace(@src()); - defer tracy.end(); - - const bin_inst = sema.code.instructions.items(.data)[@intFromEnum(inst)].bin; - const ptr = try sema.resolveInst(bin_inst.lhs); - const value = try sema.resolveInst(bin_inst.rhs); - return sema.storePtr(block, sema.src, ptr, value); -} - fn zirStoreNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void { const tracy = trace(@src()); defer tracy.end(); @@ -5709,7 +5694,6 @@ fn zirPanic(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Zir.I fn zirTrap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Zir.Inst.Index { const src_node = sema.code.instructions.items(.data)[@intFromEnum(inst)].node; const src = LazySrcLoc.nodeOffset(src_node); - sema.src = src; if (block.is_comptime) return sema.fail(block, src, "encountered @trap at comptime", .{}); _ = try block.addNoOp(.trap); @@ -6384,10 +6368,6 @@ fn zirBreak(sema: *Sema, start_block: *Block, inst: Zir.Inst.Index) CompileError } fn zirDbgStmt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void { - // We do not set sema.src here because dbg_stmt instructions are only emitted for - // ZIR code that possibly will need to generate runtime code. So error messages - // and other source locations must not rely on sema.src being set from dbg_stmt - // instructions. if (block.is_comptime or block.ownerModule().strip) return; const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].dbg_stmt; @@ -6632,7 +6612,6 @@ fn funcDeclSrc(sema: *Sema, func_inst: Air.Inst.Ref) !?*Decl { pub fn analyzeSaveErrRetIndex(sema: *Sema, block: *Block) SemaError!Air.Inst.Ref { const mod = sema.mod; const gpa = sema.gpa; - const src = sema.src; if (block.is_comptime or block.is_typeof) { const index_val = try mod.intValue_u64(Type.usize, sema.comptime_err_ret_trace.items.len); @@ -6650,9 +6629,10 @@ pub fn analyzeSaveErrRetIndex(sema: *Sema, block: *Block) SemaError!Air.Inst.Ref else => |e| return e, }; const field_name = try mod.intern_pool.getOrPutString(gpa, "index"); - const field_index = sema.structFieldIndex(block, stack_trace_ty, field_name, src) catch |err| switch (err) { - error.NeededSourceLocation, error.GenericPoison, error.ComptimeReturn, error.ComptimeBreak => unreachable, - else => |e| return e, + const field_index = sema.structFieldIndex(block, stack_trace_ty, field_name, .unneeded) catch |err| switch (err) { + error.AnalysisFail, error.NeededSourceLocation => @panic("std.builtin.StackTrace is corrupt"), + error.GenericPoison, error.ComptimeReturn, error.ComptimeBreak => unreachable, + error.OutOfMemory => |e| return e, }; return try block.addInst(.{ @@ -9900,7 +9880,6 @@ fn zirAsNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; const src = inst_data.src(); const extra = sema.code.extraData(Zir.Inst.As, inst_data.payload_index).data; - sema.src = src; return sema.analyzeAs(block, src, extra.dest_type, extra.operand, false); } @@ -10855,7 +10834,7 @@ const SwitchProngAnalysis = struct { .address_space = operand_ptr_ty.ptrAddressSpace(mod), }, }); - if (try sema.resolveDefinedValue(block, sema.src, spa.operand_ptr)) |union_ptr| { + if (try sema.resolveDefinedValue(block, operand_src, spa.operand_ptr)) |union_ptr| { return Air.internedToRef((try mod.intern(.{ .ptr = .{ .ty = ptr_field_ty.toIntern(), .addr = .{ .field = .{ @@ -10866,7 +10845,7 @@ const SwitchProngAnalysis = struct { } return block.addStructFieldPtr(spa.operand_ptr, field_index, ptr_field_ty); } else { - if (try sema.resolveDefinedValue(block, sema.src, spa.operand)) |union_val| { + if (try sema.resolveDefinedValue(block, operand_src, spa.operand)) |union_val| { const tag_and_val = ip.indexToKey(union_val.toIntern()).un; return Air.internedToRef(tag_and_val.val); } @@ -13191,6 +13170,7 @@ fn validateErrSetSwitch( // else => |e| return e, // even if all the possible errors were already handled. const tags = sema.code.instructions.items(.tag); + const datas = sema.code.instructions.items(.data); for (else_case.body) |else_inst| switch (tags[@intFromEnum(else_inst)]) { .dbg_block_begin, .dbg_block_end, @@ -13205,11 +13185,16 @@ fn validateErrSetSwitch( .err_union_code, .ret_err_value_code, .save_err_ret_index, - .restore_err_ret_index, + .restore_err_ret_index_unconditional, + .restore_err_ret_index_fn_entry, .is_non_err, .ret_is_non_err, .condbr, => {}, + .extended => switch (datas[@intFromEnum(else_inst)].extended.opcode) { + .restore_err_ret_index => {}, + else => break, + }, else => break, } else break :else_validation; @@ -13707,7 +13692,6 @@ fn zirShl( const mod = sema.mod; const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; const src = inst_data.src(); - sema.src = src; const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node }; const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node }; const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; @@ -13878,7 +13862,6 @@ fn zirShr( const mod = sema.mod; const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; const src = inst_data.src(); - sema.src = src; const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node }; const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node }; const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; @@ -14014,7 +13997,6 @@ fn zirBitwise( const mod = sema.mod; const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node }; - sema.src = src; const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node }; const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node }; const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; @@ -14795,21 +14777,20 @@ fn zirArithmetic( defer tracy.end(); const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; - sema.src = .{ .node_offset_bin_op = inst_data.src_node }; + const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node }; const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node }; const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node }; const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; const lhs = try sema.resolveInst(extra.lhs); const rhs = try sema.resolveInst(extra.rhs); - return sema.analyzeArithmetic(block, zir_tag, lhs, rhs, sema.src, lhs_src, rhs_src, safety); + return sema.analyzeArithmetic(block, zir_tag, lhs, rhs, src, lhs_src, rhs_src, safety); } fn zirDiv(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { const mod = sema.mod; const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node }; - sema.src = src; const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node }; const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node }; const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; @@ -14975,7 +14956,6 @@ fn zirDivExact(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai const mod = sema.mod; const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node }; - sema.src = src; const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node }; const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node }; const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; @@ -15141,7 +15121,6 @@ fn zirDivFloor(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai const mod = sema.mod; const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node }; - sema.src = src; const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node }; const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node }; const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; @@ -15252,7 +15231,6 @@ fn zirDivTrunc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai const mod = sema.mod; const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node }; - sema.src = src; const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node }; const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node }; const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; @@ -15494,7 +15472,6 @@ fn zirModRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. const mod = sema.mod; const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node }; - sema.src = src; const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node }; const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node }; const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; @@ -15679,7 +15656,6 @@ fn zirMod(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins const mod = sema.mod; const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node }; - sema.src = src; const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node }; const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node }; const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; @@ -15775,7 +15751,6 @@ fn zirRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins const mod = sema.mod; const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node }; - sema.src = src; const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node }; const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node }; const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; @@ -18741,13 +18716,16 @@ fn zirBoolBr( defer tracy.end(); const mod = sema.mod; + const gpa = sema.gpa; + const datas = sema.code.instructions.items(.data); - const inst_data = datas[@intFromEnum(inst)].bool_br; - const lhs = try sema.resolveInst(inst_data.lhs); - const lhs_src = sema.src; - const extra = sema.code.extraData(Zir.Inst.Block, inst_data.payload_index); + const inst_data = datas[@intFromEnum(inst)].pl_node; + const extra = sema.code.extraData(Zir.Inst.BoolBr, inst_data.payload_index); + + const lhs = try sema.resolveInst(extra.data.lhs); const body = sema.code.bodySlice(extra.end, extra.data.body_len); - const gpa = sema.gpa; + const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node }; + const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node }; if (try sema.resolveDefinedValue(parent_block, lhs_src, lhs)) |lhs_val| { if (is_bool_or and lhs_val.toBool()) { @@ -18795,7 +18773,7 @@ fn zirBoolBr( const result = sema.finishCondBr(parent_block, &child_block, &then_block, &else_block, lhs, block_inst); if (!sema.typeOf(rhs_result).isNoReturn(mod)) { - if (try sema.resolveDefinedValue(rhs_block, sema.src, rhs_result)) |rhs_val| { + if (try sema.resolveDefinedValue(rhs_block, rhs_src, rhs_result)) |rhs_val| { if (is_bool_or and rhs_val.toBool()) { return .bool_true; } else if (!is_bool_or and !rhs_val.toBool()) { @@ -19375,17 +19353,21 @@ fn zirSaveErrRetIndex(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE block.error_return_trace_index = try sema.analyzeSaveErrRetIndex(block); } -fn zirRestoreErrRetIndex(sema: *Sema, start_block: *Block, inst: Zir.Inst.Index) CompileError!void { - const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].restore_err_ret_index; - const src = sema.src; // TODO - - const mod = sema.mod; - const ip = &mod.intern_pool; +fn zirRestoreErrRetIndex(sema: *Sema, start_block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!void { + const extra = sema.code.extraData(Zir.Inst.RestoreErrRetIndex, extended.operand).data; + return sema.restoreErrRetIndex(start_block, extra.src(), extra.block, extra.operand); +} +/// If `operand` is non-error (or is `none`), restores the error return trace to +/// its state at the point `block` was reached (or, if `block` is `none`, the +/// point this function began execution). +fn restoreErrRetIndex(sema: *Sema, start_block: *Block, src: LazySrcLoc, target_block: Zir.Inst.Ref, operand_zir: Zir.Inst.Ref) CompileError!void { const tracy = trace(@src()); defer tracy.end(); - const saved_index = if (inst_data.block.toIndexAllowNone()) |zir_block| b: { + const mod = sema.mod; + + const saved_index = if (target_block.toIndexAllowNone()) |zir_block| b: { var block = start_block; while (true) { if (block.label) |label| { @@ -19409,7 +19391,7 @@ fn zirRestoreErrRetIndex(sema: *Sema, start_block: *Block, inst: Zir.Inst.Index) return; // No need to restore }; - const operand = try sema.resolveInstAllowNone(inst_data.operand); + const operand = try sema.resolveInstAllowNone(operand_zir); if (start_block.is_comptime or start_block.is_typeof) { const is_non_error = if (operand != .none) blk: { @@ -19427,7 +19409,7 @@ fn zirRestoreErrRetIndex(sema: *Sema, start_block: *Block, inst: Zir.Inst.Index) return; } - if (!ip.funcAnalysis(sema.owner_func_index).calls_or_awaits_errorable_fn) return; + if (!mod.intern_pool.funcAnalysis(sema.owner_func_index).calls_or_awaits_errorable_fn) return; if (!start_block.ownerModule().error_tracing) return; assert(saved_index != .none); // The .error_return_trace_index field was dropped somewhere @@ -23161,7 +23143,6 @@ fn zirOffsetOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai fn bitOffsetOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!u64 { const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node }; - sema.src = src; const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node }; const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node }; const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; @@ -26416,12 +26397,16 @@ fn preparePanicId(sema: *Sema, block: *Block, panic_id: Module.PanicId) !InternP try sema.prepareSimplePanic(block); const panic_messages_ty = try sema.getBuiltinType("panic_messages"); - const msg_decl_index = (try sema.namespaceLookup( + const msg_decl_index = (sema.namespaceLookup( block, - sema.src, + .unneeded, panic_messages_ty.getNamespaceIndex(mod).unwrap().?, try mod.intern_pool.getOrPutString(gpa, @tagName(panic_id)), - )).?; + ) catch |err| switch (err) { + error.AnalysisFail, error.NeededSourceLocation => @panic("std.builtin.panic_messages is corrupt"), + error.GenericPoison, error.ComptimeReturn, error.ComptimeBreak => unreachable, + error.OutOfMemory => |e| return e, + }).?; try sema.ensureDeclAnalyzed(msg_decl_index); mod.panic_messages[@intFromEnum(panic_id)] = msg_decl_index.toOptional(); return msg_decl_index; |
