| ... | @@ -34,7 +34,7 @@ func_index: InternPool.Index, | ... | @@ -34,7 +34,7 @@ func_index: InternPool.Index, |
| 34 | func_is_naked: bool, | 34 | func_is_naked: bool, |
| 35 | /// Used to restore the error return trace when returning a non-error from a function. | 35 | /// Used to restore the error return trace when returning a non-error from a function. |
| 36 | error_return_trace_index_on_fn_entry: Air.Inst.Ref = .none, | 36 | error_return_trace_index_on_fn_entry: Air.Inst.Ref = .none, |
| 37 | comptime_err_ret_trace: *std.ArrayList(Module.SrcLoc), | 37 | comptime_err_ret_trace: *std.ArrayList(LazySrcLoc), |
| 38 | /// When semantic analysis needs to know the return type of the function whose body | 38 | /// When semantic analysis needs to know the return type of the function whose body |
| 39 | /// is being analyzed, this `Type` should be used instead of going through `func`. | 39 | /// is being analyzed, this `Type` should be used instead of going through `func`. |
| 40 | /// This will correctly handle the case of a comptime/inline function call of a | 40 | /// This will correctly handle the case of a comptime/inline function call of a |
| ... | @@ -65,9 +65,7 @@ generic_owner: InternPool.Index = .none, | ... | @@ -65,9 +65,7 @@ generic_owner: InternPool.Index = .none, |
| 65 | /// instantiation callsite so that compile errors on the parameter types of the | 65 | /// instantiation callsite so that compile errors on the parameter types of the |
| 66 | /// instantiation can point back to the instantiation site in addition to the | 66 | /// instantiation can point back to the instantiation site in addition to the |
| 67 | /// declaration site. | 67 | /// declaration site. |
| 68 | generic_call_src: LazySrcLoc = .unneeded, | 68 | generic_call_src: LazySrcLoc = LazySrcLoc.unneeded, |
| 69 | /// Corresponds to `generic_call_src`. | | |
| 70 | generic_call_decl: InternPool.OptionalDeclIndex = .none, | | |
| 71 | /// The key is types that must be fully resolved prior to machine code | 69 | /// The key is types that must be fully resolved prior to machine code |
| 72 | /// generation pass. Types are added to this set when resolving them | 70 | /// generation pass. Types are added to this set when resolving them |
| 73 | /// immediately could cause a dependency loop, but they do need to be resolved | 71 | /// immediately could cause a dependency loop, but they do need to be resolved |
| ... | @@ -131,7 +129,6 @@ const MaybeComptimeAlloc = struct { | ... | @@ -131,7 +129,6 @@ const MaybeComptimeAlloc = struct { |
| 131 | /// If the instruction is one of these three tags, `src` may be `.unneeded`. | 129 | /// If the instruction is one of these three tags, `src` may be `.unneeded`. |
| 132 | stores: std.MultiArrayList(struct { | 130 | stores: std.MultiArrayList(struct { |
| 133 | inst: Air.Inst.Index, | 131 | inst: Air.Inst.Index, |
| 134 | src_decl: InternPool.DeclIndex, | | |
| 135 | src: LazySrcLoc, | 132 | src: LazySrcLoc, |
| 136 | }) = .{}, | 133 | }) = .{}, |
| 137 | }; | 134 | }; |
| ... | @@ -361,8 +358,8 @@ pub const Block = struct { | ... | @@ -361,8 +358,8 @@ pub const Block = struct { |
| 361 | label: ?*Label = null, | 358 | label: ?*Label = null, |
| 362 | inlining: ?*Inlining, | 359 | inlining: ?*Inlining, |
| 363 | /// If runtime_index is not 0 then one of these is guaranteed to be non null. | 360 | /// If runtime_index is not 0 then one of these is guaranteed to be non null. |
| 364 | runtime_cond: ?Module.SrcLoc = null, | 361 | runtime_cond: ?LazySrcLoc = null, |
| 365 | runtime_loop: ?Module.SrcLoc = null, | 362 | runtime_loop: ?LazySrcLoc = null, |
| 366 | /// This Decl is the Decl according to the Zig source code corresponding to this Block. | 363 | /// This Decl is the Decl according to the Zig source code corresponding to this Block. |
| 367 | /// This can vary during inline or comptime function calls. See `Sema.owner_decl` | 364 | /// This can vary during inline or comptime function calls. See `Sema.owner_decl` |
| 368 | /// for the one that will be the same for all Block instances. | 365 | /// for the one that will be the same for all Block instances. |
| ... | @@ -395,25 +392,39 @@ pub const Block = struct { | ... | @@ -395,25 +392,39 @@ pub const Block = struct { |
| 395 | /// `block` in order for codegen to match lexical scoping for debug vars. | 392 | /// `block` in order for codegen to match lexical scoping for debug vars. |
| 396 | need_debug_scope: ?*bool = null, | 393 | need_debug_scope: ?*bool = null, |
| 397 | | 394 | |
| 398 | // These functions will be less stupid soon! | 395 | /// Relative source locations encountered while traversing this block should be |
| | 396 | /// treated as relative to the AST node of this ZIR instruction. |
| | 397 | src_base_inst: InternPool.TrackedInst.Index, |
| | 398 | |
| | 399 | /// 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`. |
| | 401 | pub fn src(block: Block, offset: LazySrcLoc.Offset) LazySrcLoc { |
| | 402 | return .{ |
| | 403 | .base_node_inst = block.src_base_inst, |
| | 404 | .offset = offset, |
| | 405 | }; |
| | 406 | } |
| | 407 | |
| | 408 | fn builtinCallArgSrc(block: *Block, builtin_call_node: i32, arg_index: u32) LazySrcLoc { |
| | 409 | return block.src(.{ .node_offset_builtin_call_arg = .{ |
| | 410 | .builtin_call_node = builtin_call_node, |
| | 411 | .arg_index = arg_index, |
| | 412 | } }); |
| | 413 | } |
| 399 | | 414 | |
| 400 | fn nodeOffset(block: Block, node_offset: i32) LazySrcLoc { | 415 | fn nodeOffset(block: Block, node_offset: i32) LazySrcLoc { |
| 401 | _ = block; | 416 | return block.src(LazySrcLoc.Offset.nodeOffset(node_offset)); |
| 402 | return LazySrcLoc.nodeOffset(node_offset); | | |
| 403 | } | 417 | } |
| 404 | | 418 | |
| 405 | fn tokenOffset(block: Block, tok_offset: u32) LazySrcLoc { | 419 | fn tokenOffset(block: Block, tok_offset: u32) LazySrcLoc { |
| 406 | _ = block; | 420 | return block.src(.{ .token_offset = tok_offset }); |
| 407 | return .{ .token_offset = tok_offset }; | | |
| 408 | } | 421 | } |
| 409 | | 422 | |
| 410 | const ComptimeReason = union(enum) { | 423 | const ComptimeReason = union(enum) { |
| 411 | c_import: struct { | 424 | c_import: struct { |
| 412 | block: *Block, | | |
| 413 | src: LazySrcLoc, | 425 | src: LazySrcLoc, |
| 414 | }, | 426 | }, |
| 415 | comptime_ret_ty: struct { | 427 | comptime_ret_ty: struct { |
| 416 | block: *Block, | | |
| 417 | func: Air.Inst.Ref, | 428 | func: Air.Inst.Ref, |
| 418 | func_src: LazySrcLoc, | 429 | func_src: LazySrcLoc, |
| 419 | return_ty: Type, | 430 | return_ty: Type, |
| ... | @@ -425,27 +436,23 @@ pub const Block = struct { | ... | @@ -425,27 +436,23 @@ pub const Block = struct { |
| 425 | const prefix = "expression is evaluated at comptime because "; | 436 | const prefix = "expression is evaluated at comptime because "; |
| 426 | switch (cr) { | 437 | switch (cr) { |
| 427 | .c_import => |ci| { | 438 | .c_import => |ci| { |
| 428 | try sema.errNote(ci.block, ci.src, parent, prefix ++ "it is inside a @cImport", .{}); | 439 | try sema.errNote(ci.src, parent, prefix ++ "it is inside a @cImport", .{}); |
| 429 | }, | 440 | }, |
| 430 | .comptime_ret_ty => |rt| { | 441 | .comptime_ret_ty => |rt| { |
| 431 | const src_loc = if (try sema.funcDeclSrc(rt.func)) |fn_decl| blk: { | 442 | const ret_ty_src: LazySrcLoc = if (try sema.funcDeclSrc(rt.func)) |fn_decl| .{ |
| 432 | var src_loc = fn_decl.srcLoc(mod); | 443 | .base_node_inst = fn_decl.zir_decl_index.unwrap().?, |
| 433 | src_loc.lazy = .{ .node_offset_fn_type_ret_ty = 0 }; | 444 | .offset = .{ .node_offset_fn_type_ret_ty = 0 }, |
| 434 | break :blk src_loc; | 445 | } else rt.func_src; |
| 435 | } else blk: { | | |
| 436 | const src_decl = mod.declPtr(rt.block.src_decl); | | |
| 437 | break :blk src_decl.toSrcLoc(rt.func_src, mod); | | |
| 438 | }; | | |
| 439 | if (rt.return_ty.isGenericPoison()) { | 446 | if (rt.return_ty.isGenericPoison()) { |
| 440 | return mod.errNoteNonLazy(src_loc, parent, prefix ++ "the generic function was instantiated with a comptime-only return type", .{}); | 447 | return sema.errNote(ret_ty_src, parent, prefix ++ "the generic function was instantiated with a comptime-only return type", .{}); |
| 441 | } | 448 | } |
| 442 | try mod.errNoteNonLazy( | 449 | try sema.errNote( |
| 443 | src_loc, | 450 | ret_ty_src, |
| 444 | parent, | 451 | parent, |
| 445 | prefix ++ "the function returns a comptime-only type '{}'", | 452 | prefix ++ "the function returns a comptime-only type '{}'", |
| 446 | .{rt.return_ty.fmt(mod)}, | 453 | .{rt.return_ty.fmt(mod)}, |
| 447 | ); | 454 | ); |
| 448 | try sema.explainWhyTypeIsComptime(parent, src_loc, rt.return_ty); | 455 | try sema.explainWhyTypeIsComptime(parent, ret_ty_src, rt.return_ty); |
| 449 | }, | 456 | }, |
| 450 | } | 457 | } |
| 451 | } | 458 | } |
| ... | @@ -525,6 +532,7 @@ pub const Block = struct { | ... | @@ -525,6 +532,7 @@ pub const Block = struct { |
| 525 | .c_import_buf = parent.c_import_buf, | 532 | .c_import_buf = parent.c_import_buf, |
| 526 | .error_return_trace_index = parent.error_return_trace_index, | 533 | .error_return_trace_index = parent.error_return_trace_index, |
| 527 | .need_debug_scope = parent.need_debug_scope, | 534 | .need_debug_scope = parent.need_debug_scope, |
| | 535 | .src_base_inst = parent.src_base_inst, |
| 528 | }; | 536 | }; |
| 529 | } | 537 | } |
| 530 | | 538 | |
| ... | @@ -815,14 +823,6 @@ pub const Block = struct { | ... | @@ -815,14 +823,6 @@ pub const Block = struct { |
| 815 | return result_index; | 823 | return result_index; |
| 816 | } | 824 | } |
| 817 | | 825 | |
| 818 | fn addUnreachable(block: *Block, src: LazySrcLoc, safety_check: bool) !void { | | |
| 819 | if (safety_check and block.wantSafety()) { | | |
| 820 | try block.sema.safetyPanic(block, src, .unreach); | | |
| 821 | } else { | | |
| 822 | _ = try block.addNoOp(.unreach); | | |
| 823 | } | | |
| 824 | } | | |
| 825 | | | |
| 826 | pub fn ownerModule(block: Block) *Package.Module { | 826 | pub fn ownerModule(block: Block) *Package.Module { |
| 827 | const zcu = block.sema.mod; | 827 | const zcu = block.sema.mod; |
| 828 | return zcu.namespacePtr(block.namespace).file_scope.mod; | 828 | return zcu.namespacePtr(block.namespace).file_scope.mod; |
| ... | @@ -1237,7 +1237,7 @@ fn analyzeBodyInner( | ... | @@ -1237,7 +1237,7 @@ fn analyzeBodyInner( |
| 1237 | .@"asm" => try sema.zirAsm( block, extended, false), | 1237 | .@"asm" => try sema.zirAsm( block, extended, false), |
| 1238 | .asm_expr => try sema.zirAsm( block, extended, true), | 1238 | .asm_expr => try sema.zirAsm( block, extended, true), |
| 1239 | .typeof_peer => try sema.zirTypeofPeer( block, extended, inst), | 1239 | .typeof_peer => try sema.zirTypeofPeer( block, extended, inst), |
| 1240 | .compile_log => try sema.zirCompileLog( extended), | 1240 | .compile_log => try sema.zirCompileLog( block, extended), |
| 1241 | .min_multi => try sema.zirMinMaxMulti( block, extended, .min), | 1241 | .min_multi => try sema.zirMinMaxMulti( block, extended, .min), |
| 1242 | .max_multi => try sema.zirMinMaxMulti( block, extended, .max), | 1242 | .max_multi => try sema.zirMinMaxMulti( block, extended, .max), |
| 1243 | .add_with_overflow => try sema.zirOverflowArithmetic(block, extended, extended.opcode), | 1243 | .add_with_overflow => try sema.zirOverflowArithmetic(block, extended, extended.opcode), |
| ... | @@ -1475,10 +1475,9 @@ fn analyzeBodyInner( | ... | @@ -1475,10 +1475,9 @@ fn analyzeBodyInner( |
| 1475 | if (@intFromEnum(target_runtime_index) < @intFromEnum(block.runtime_index)) { | 1475 | if (@intFromEnum(target_runtime_index) < @intFromEnum(block.runtime_index)) { |
| 1476 | const runtime_src = block.runtime_cond orelse block.runtime_loop.?; | 1476 | const runtime_src = block.runtime_cond orelse block.runtime_loop.?; |
| 1477 | const msg = msg: { | 1477 | const msg = msg: { |
| 1478 | const msg = try sema.errMsg(block, src, "comptime control flow inside runtime block", .{}); | 1478 | const msg = try sema.errMsg(src, "comptime control flow inside runtime block", .{}); |
| 1479 | errdefer msg.destroy(sema.gpa); | 1479 | errdefer msg.destroy(sema.gpa); |
| 1480 | | 1480 | try sema.errNote(runtime_src, msg, "runtime control flow here", .{}); |
| 1481 | try mod.errNoteNonLazy(runtime_src, msg, "runtime control flow here", .{}); | | |
| 1482 | break :msg msg; | 1481 | break :msg msg; |
| 1483 | }; | 1482 | }; |
| 1484 | return sema.failWithOwnedErrorMsg(block, msg); | 1483 | return sema.failWithOwnedErrorMsg(block, msg); |
| ... | @@ -1522,7 +1521,7 @@ fn analyzeBodyInner( | ... | @@ -1522,7 +1521,7 @@ fn analyzeBodyInner( |
| 1522 | .repeat => { | 1521 | .repeat => { |
| 1523 | if (block.is_comptime) { | 1522 | if (block.is_comptime) { |
| 1524 | // Send comptime control flow back to the beginning of this block. | 1523 | // Send comptime control flow back to the beginning of this block. |
| 1525 | const src = LazySrcLoc.nodeOffset(datas[@intFromEnum(inst)].node); | 1524 | const src = block.nodeOffset(datas[@intFromEnum(inst)].node); |
| 1526 | try sema.emitBackwardBranch(block, src); | 1525 | try sema.emitBackwardBranch(block, src); |
| 1527 | i = 0; | 1526 | i = 0; |
| 1528 | continue; | 1527 | continue; |
| ... | @@ -1535,7 +1534,7 @@ fn analyzeBodyInner( | ... | @@ -1535,7 +1534,7 @@ fn analyzeBodyInner( |
| 1535 | }, | 1534 | }, |
| 1536 | .repeat_inline => { | 1535 | .repeat_inline => { |
| 1537 | // Send comptime control flow back to the beginning of this block. | 1536 | // Send comptime control flow back to the beginning of this block. |
| 1538 | const src = LazySrcLoc.nodeOffset(datas[@intFromEnum(inst)].node); | 1537 | const src = block.nodeOffset(datas[@intFromEnum(inst)].node); |
| 1539 | try sema.emitBackwardBranch(block, src); | 1538 | try sema.emitBackwardBranch(block, src); |
| 1540 | i = 0; | 1539 | i = 0; |
| 1541 | continue; | 1540 | continue; |
| ... | @@ -1705,7 +1704,7 @@ fn analyzeBodyInner( | ... | @@ -1705,7 +1704,7 @@ fn analyzeBodyInner( |
| 1705 | } | 1704 | } |
| 1706 | // Same as condbr_inline. TODO https://github.com/ziglang/zig/issues/8220 | 1705 | // Same as condbr_inline. TODO https://github.com/ziglang/zig/issues/8220 |
| 1707 | const inst_data = datas[@intFromEnum(inst)].pl_node; | 1706 | const inst_data = datas[@intFromEnum(inst)].pl_node; |
| 1708 | const cond_src: LazySrcLoc = .{ .node_offset_if_cond = inst_data.src_node }; | 1707 | const cond_src = block.src(.{ .node_offset_if_cond = inst_data.src_node }); |
| 1709 | const extra = sema.code.extraData(Zir.Inst.CondBr, inst_data.payload_index); | 1708 | const extra = sema.code.extraData(Zir.Inst.CondBr, inst_data.payload_index); |
| 1710 | const then_body = sema.code.bodySlice(extra.end, extra.data.then_body_len); | 1709 | const then_body = sema.code.bodySlice(extra.end, extra.data.then_body_len); |
| 1711 | const else_body = sema.code.bodySlice( | 1710 | const else_body = sema.code.bodySlice( |
| ... | @@ -1725,7 +1724,7 @@ fn analyzeBodyInner( | ... | @@ -1725,7 +1724,7 @@ fn analyzeBodyInner( |
| 1725 | }, | 1724 | }, |
| 1726 | .condbr_inline => blk: { | 1725 | .condbr_inline => blk: { |
| 1727 | const inst_data = datas[@intFromEnum(inst)].pl_node; | 1726 | const inst_data = datas[@intFromEnum(inst)].pl_node; |
| 1728 | const cond_src: LazySrcLoc = .{ .node_offset_if_cond = inst_data.src_node }; | 1727 | const cond_src = block.src(.{ .node_offset_if_cond = inst_data.src_node }); |
| 1729 | const extra = sema.code.extraData(Zir.Inst.CondBr, inst_data.payload_index); | 1728 | const extra = sema.code.extraData(Zir.Inst.CondBr, inst_data.payload_index); |
| 1730 | const then_body = sema.code.bodySlice(extra.end, extra.data.then_body_len); | 1729 | const then_body = sema.code.bodySlice(extra.end, extra.data.then_body_len); |
| 1731 | const else_body = sema.code.bodySlice( | 1730 | const else_body = sema.code.bodySlice( |
| ... | @@ -1749,7 +1748,7 @@ fn analyzeBodyInner( | ... | @@ -1749,7 +1748,7 @@ fn analyzeBodyInner( |
| 1749 | if (!block.is_comptime) break :blk try sema.zirTry(block, inst); | 1748 | if (!block.is_comptime) break :blk try sema.zirTry(block, inst); |
| 1750 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 1749 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 1751 | const src = block.nodeOffset(inst_data.src_node); | 1750 | const src = block.nodeOffset(inst_data.src_node); |
| 1752 | const operand_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node }; | 1751 | const operand_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node }); |
| 1753 | const extra = sema.code.extraData(Zir.Inst.Try, inst_data.payload_index); | 1752 | const extra = sema.code.extraData(Zir.Inst.Try, inst_data.payload_index); |
| 1754 | const inline_body = sema.code.bodySlice(extra.end, extra.data.body_len); | 1753 | const inline_body = sema.code.bodySlice(extra.end, extra.data.body_len); |
| 1755 | const err_union = try sema.resolveInst(extra.data.operand); | 1754 | const err_union = try sema.resolveInst(extra.data.operand); |
| ... | @@ -1775,7 +1774,7 @@ fn analyzeBodyInner( | ... | @@ -1775,7 +1774,7 @@ fn analyzeBodyInner( |
| 1775 | if (!block.is_comptime) break :blk try sema.zirTryPtr(block, inst); | 1774 | if (!block.is_comptime) break :blk try sema.zirTryPtr(block, inst); |
| 1776 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 1775 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 1777 | const src = block.nodeOffset(inst_data.src_node); | 1776 | const src = block.nodeOffset(inst_data.src_node); |
| 1778 | const operand_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node }; | 1777 | const operand_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node }); |
| 1779 | const extra = sema.code.extraData(Zir.Inst.Try, inst_data.payload_index); | 1778 | const extra = sema.code.extraData(Zir.Inst.Try, inst_data.payload_index); |
| 1780 | const inline_body = sema.code.bodySlice(extra.end, extra.data.body_len); | 1779 | const inline_body = sema.code.bodySlice(extra.end, extra.data.body_len); |
| 1781 | const operand = try sema.resolveInst(extra.data.operand); | 1780 | const operand = try sema.resolveInst(extra.data.operand); |
| ... | @@ -1939,14 +1938,14 @@ fn resolveDestType( | ... | @@ -1939,14 +1938,14 @@ fn resolveDestType( |
| 1939 | // Cast builtins use their result type as the destination type, but | 1938 | // Cast builtins use their result type as the destination type, but |
| 1940 | // it could be an anytype argument, which we can't catch in AstGen. | 1939 | // it could be an anytype argument, which we can't catch in AstGen. |
| 1941 | const msg = msg: { | 1940 | const msg = msg: { |
| 1942 | const msg = try sema.errMsg(block, src, "{s} must have a known result type", .{builtin_name}); | 1941 | const msg = try sema.errMsg(src, "{s} must have a known result type", .{builtin_name}); |
| 1943 | errdefer msg.destroy(sema.gpa); | 1942 | errdefer msg.destroy(sema.gpa); |
| 1944 | switch (sema.genericPoisonReason(block, zir_ref)) { | 1943 | switch (sema.genericPoisonReason(block, zir_ref)) { |
| 1945 | .anytype_param => |call_src| try sema.errNote(block, call_src, msg, "result type is unknown due to anytype parameter", .{}), | 1944 | .anytype_param => |call_src| try sema.errNote(call_src, msg, "result type is unknown due to anytype parameter", .{}), |
| 1946 | .anyopaque_ptr => |ptr_src| try sema.errNote(block, ptr_src, msg, "result type is unknown due to opaque pointer type", .{}), | 1945 | .anyopaque_ptr => |ptr_src| try sema.errNote(ptr_src, msg, "result type is unknown due to opaque pointer type", .{}), |
| 1947 | .unknown => {}, | 1946 | .unknown => {}, |
| 1948 | } | 1947 | } |
| 1949 | try sema.errNote(block, src, msg, "use @as to provide explicit result type", .{}); | 1948 | try sema.errNote(src, msg, "use @as to provide explicit result type", .{}); |
| 1950 | break :msg msg; | 1949 | break :msg msg; |
| 1951 | }; | 1950 | }; |
| 1952 | return sema.failWithOwnedErrorMsg(block, msg); | 1951 | return sema.failWithOwnedErrorMsg(block, msg); |
| ... | @@ -2051,7 +2050,7 @@ pub fn setupErrorReturnTrace(sema: *Sema, block: *Block, last_arg_index: usize) | ... | @@ -2051,7 +2050,7 @@ pub fn setupErrorReturnTrace(sema: *Sema, block: *Block, last_arg_index: usize) |
| 2051 | var err_trace_block = block.makeSubBlock(); | 2050 | var err_trace_block = block.makeSubBlock(); |
| 2052 | defer err_trace_block.instructions.deinit(gpa); | 2051 | defer err_trace_block.instructions.deinit(gpa); |
| 2053 | | 2052 | |
| 2054 | const src: LazySrcLoc = .unneeded; | 2053 | const src: LazySrcLoc = LazySrcLoc.unneeded; |
| 2055 | | 2054 | |
| 2056 | // var addrs: [err_return_trace_addr_count]usize = undefined; | 2055 | // var addrs: [err_return_trace_addr_count]usize = undefined; |
| 2057 | const err_return_trace_addr_count = 32; | 2056 | const err_return_trace_addr_count = 32; |
| ... | @@ -2212,9 +2211,9 @@ pub fn resolveFinalDeclValue( | ... | @@ -2212,9 +2211,9 @@ pub fn resolveFinalDeclValue( |
| 2212 | | 2211 | |
| 2213 | fn failWithNeededComptime(sema: *Sema, block: *Block, src: LazySrcLoc, reason: NeededComptimeReason) CompileError { | 2212 | fn failWithNeededComptime(sema: *Sema, block: *Block, src: LazySrcLoc, reason: NeededComptimeReason) CompileError { |
| 2214 | const msg = msg: { | 2213 | const msg = msg: { |
| 2215 | const msg = try sema.errMsg(block, src, "unable to resolve comptime value", .{}); | 2214 | const msg = try sema.errMsg(src, "unable to resolve comptime value", .{}); |
| 2216 | errdefer msg.destroy(sema.gpa); | 2215 | errdefer msg.destroy(sema.gpa); |
| 2217 | try sema.errNote(block, src, msg, "{s}", .{reason.needed_comptime_reason}); | 2216 | try sema.errNote(src, msg, "{s}", .{reason.needed_comptime_reason}); |
| 2218 | | 2217 | |
| 2219 | if (reason.block_comptime_reason) |block_comptime_reason| { | 2218 | if (reason.block_comptime_reason) |block_comptime_reason| { |
| 2220 | try block_comptime_reason.explain(sema, msg); | 2219 | try block_comptime_reason.explain(sema, msg); |
| ... | @@ -2241,12 +2240,12 @@ fn failWithModRemNegative(sema: *Sema, block: *Block, src: LazySrcLoc, lhs_ty: T | ... | @@ -2241,12 +2240,12 @@ fn failWithModRemNegative(sema: *Sema, block: *Block, src: LazySrcLoc, lhs_ty: T |
| 2241 | fn failWithExpectedOptionalType(sema: *Sema, block: *Block, src: LazySrcLoc, non_optional_ty: Type) CompileError { | 2240 | fn failWithExpectedOptionalType(sema: *Sema, block: *Block, src: LazySrcLoc, non_optional_ty: Type) CompileError { |
| 2242 | const mod = sema.mod; | 2241 | const mod = sema.mod; |
| 2243 | const msg = msg: { | 2242 | const msg = msg: { |
| 2244 | const msg = try sema.errMsg(block, src, "expected optional type, found '{}'", .{ | 2243 | const msg = try sema.errMsg(src, "expected optional type, found '{}'", .{ |
| 2245 | non_optional_ty.fmt(mod), | 2244 | non_optional_ty.fmt(mod), |
| 2246 | }); | 2245 | }); |
| 2247 | errdefer msg.destroy(sema.gpa); | 2246 | errdefer msg.destroy(sema.gpa); |
| 2248 | if (non_optional_ty.zigTypeTag(mod) == .ErrorUnion) { | 2247 | if (non_optional_ty.zigTypeTag(mod) == .ErrorUnion) { |
| 2249 | try sema.errNote(block, src, msg, "consider using 'try', 'catch', or 'if'", .{}); | 2248 | try sema.errNote(src, msg, "consider using 'try', 'catch', or 'if'", .{}); |
| 2250 | } | 2249 | } |
| 2251 | try addDeclaredHereNote(sema, msg, non_optional_ty); | 2250 | try addDeclaredHereNote(sema, msg, non_optional_ty); |
| 2252 | break :msg msg; | 2251 | break :msg msg; |
| ... | @@ -2257,12 +2256,12 @@ fn failWithExpectedOptionalType(sema: *Sema, block: *Block, src: LazySrcLoc, non | ... | @@ -2257,12 +2256,12 @@ fn failWithExpectedOptionalType(sema: *Sema, block: *Block, src: LazySrcLoc, non |
| 2257 | fn failWithArrayInitNotSupported(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) CompileError { | 2256 | fn failWithArrayInitNotSupported(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) CompileError { |
| 2258 | const mod = sema.mod; | 2257 | const mod = sema.mod; |
| 2259 | const msg = msg: { | 2258 | const msg = msg: { |
| 2260 | const msg = try sema.errMsg(block, src, "type '{}' does not support array initialization syntax", .{ | 2259 | const msg = try sema.errMsg(src, "type '{}' does not support array initialization syntax", .{ |
| 2261 | ty.fmt(mod), | 2260 | ty.fmt(mod), |
| 2262 | }); | 2261 | }); |
| 2263 | errdefer msg.destroy(sema.gpa); | 2262 | errdefer msg.destroy(sema.gpa); |
| 2264 | if (ty.isSlice(mod)) { | 2263 | if (ty.isSlice(mod)) { |
| 2265 | try sema.errNote(block, src, msg, "inferred array length is specified with an underscore: '[_]{}'", .{ty.elemType2(mod).fmt(mod)}); | 2264 | try sema.errNote(src, msg, "inferred array length is specified with an underscore: '[_]{}'", .{ty.elemType2(mod).fmt(mod)}); |
| 2266 | } | 2265 | } |
| 2267 | break :msg msg; | 2266 | break :msg msg; |
| 2268 | }; | 2267 | }; |
| ... | @@ -2291,11 +2290,11 @@ fn failWithIntegerOverflow(sema: *Sema, block: *Block, src: LazySrcLoc, int_ty: | ... | @@ -2291,11 +2290,11 @@ fn failWithIntegerOverflow(sema: *Sema, block: *Block, src: LazySrcLoc, int_ty: |
| 2291 | const zcu = sema.mod; | 2290 | const zcu = sema.mod; |
| 2292 | if (int_ty.zigTypeTag(zcu) == .Vector) { | 2291 | if (int_ty.zigTypeTag(zcu) == .Vector) { |
| 2293 | const msg = msg: { | 2292 | const msg = msg: { |
| 2294 | const msg = try sema.errMsg(block, src, "overflow of vector type '{}' with value '{}'", .{ | 2293 | const msg = try sema.errMsg(src, "overflow of vector type '{}' with value '{}'", .{ |
| 2295 | int_ty.fmt(zcu), val.fmtValue(zcu, sema), | 2294 | int_ty.fmt(zcu), val.fmtValue(zcu, sema), |
| 2296 | }); | 2295 | }); |
| 2297 | errdefer msg.destroy(sema.gpa); | 2296 | errdefer msg.destroy(sema.gpa); |
| 2298 | try sema.errNote(block, src, msg, "when computing vector element at index '{d}'", .{vector_index}); | 2297 | try sema.errNote(src, msg, "when computing vector element at index '{d}'", .{vector_index}); |
| 2299 | break :msg msg; | 2298 | break :msg msg; |
| 2300 | }; | 2299 | }; |
| 2301 | return sema.failWithOwnedErrorMsg(block, msg); | 2300 | return sema.failWithOwnedErrorMsg(block, msg); |
| ... | @@ -2308,15 +2307,14 @@ fn failWithIntegerOverflow(sema: *Sema, block: *Block, src: LazySrcLoc, int_ty: | ... | @@ -2308,15 +2307,14 @@ fn failWithIntegerOverflow(sema: *Sema, block: *Block, src: LazySrcLoc, int_ty: |
| 2308 | fn failWithInvalidComptimeFieldStore(sema: *Sema, block: *Block, init_src: LazySrcLoc, container_ty: Type, field_index: usize) CompileError { | 2307 | fn failWithInvalidComptimeFieldStore(sema: *Sema, block: *Block, init_src: LazySrcLoc, container_ty: Type, field_index: usize) CompileError { |
| 2309 | const mod = sema.mod; | 2308 | const mod = sema.mod; |
| 2310 | const msg = msg: { | 2309 | const msg = msg: { |
| 2311 | const msg = try sema.errMsg(block, init_src, "value stored in comptime field does not match the default value of the field", .{}); | 2310 | const msg = try sema.errMsg(init_src, "value stored in comptime field does not match the default value of the field", .{}); |
| 2312 | errdefer msg.destroy(sema.gpa); | 2311 | errdefer msg.destroy(sema.gpa); |
| 2313 | | 2312 | |
| 2314 | const struct_type = mod.typeToStruct(container_ty) orelse break :msg msg; | 2313 | const struct_type = mod.typeToStruct(container_ty) orelse break :msg msg; |
| 2315 | const default_value_src = mod.fieldSrcLoc(struct_type.decl.unwrap().?, .{ | 2314 | try sema.errNote(.{ |
| 2316 | .index = field_index, | 2315 | .base_node_inst = struct_type.zir_index.unwrap().?, |
| 2317 | .range = .value, | 2316 | .offset = .{ .container_field_value = @intCast(field_index) }, |
| 2318 | }); | 2317 | }, msg, "default value set here", .{}); |
| 2319 | try mod.errNoteNonLazy(default_value_src, msg, "default value set here", .{}); | | |
| 2320 | break :msg msg; | 2318 | break :msg msg; |
| 2321 | }; | 2319 | }; |
| 2322 | return sema.failWithOwnedErrorMsg(block, msg); | 2320 | return sema.failWithOwnedErrorMsg(block, msg); |
| ... | @@ -2324,7 +2322,7 @@ fn failWithInvalidComptimeFieldStore(sema: *Sema, block: *Block, init_src: LazyS | ... | @@ -2324,7 +2322,7 @@ fn failWithInvalidComptimeFieldStore(sema: *Sema, block: *Block, init_src: LazyS |
| 2324 | | 2322 | |
| 2325 | fn failWithUseOfAsync(sema: *Sema, block: *Block, src: LazySrcLoc) CompileError { | 2323 | fn failWithUseOfAsync(sema: *Sema, block: *Block, src: LazySrcLoc) CompileError { |
| 2326 | const msg = msg: { | 2324 | const msg = msg: { |
| 2327 | const msg = try sema.errMsg(block, src, "async has not been implemented in the self-hosted compiler yet", .{}); | 2325 | const msg = try sema.errMsg(src, "async has not been implemented in the self-hosted compiler yet", .{}); |
| 2328 | errdefer msg.destroy(sema.gpa); | 2326 | errdefer msg.destroy(sema.gpa); |
| 2329 | break :msg msg; | 2327 | break :msg msg; |
| 2330 | }; | 2328 | }; |
| ... | @@ -2345,9 +2343,9 @@ fn failWithInvalidFieldAccess( | ... | @@ -2345,9 +2343,9 @@ fn failWithInvalidFieldAccess( |
| 2345 | const child_ty = inner_ty.optionalChild(mod); | 2343 | const child_ty = inner_ty.optionalChild(mod); |
| 2346 | if (!typeSupportsFieldAccess(mod, child_ty, field_name)) break :opt; | 2344 | if (!typeSupportsFieldAccess(mod, child_ty, field_name)) break :opt; |
| 2347 | const msg = msg: { | 2345 | const msg = msg: { |
| 2348 | const msg = try sema.errMsg(block, src, "optional type '{}' does not support field access", .{object_ty.fmt(sema.mod)}); | 2346 | const msg = try sema.errMsg(src, "optional type '{}' does not support field access", .{object_ty.fmt(sema.mod)}); |
| 2349 | errdefer msg.destroy(sema.gpa); | 2347 | errdefer msg.destroy(sema.gpa); |
| 2350 | try sema.errNote(block, src, msg, "consider using '.?', 'orelse', or 'if'", .{}); | 2348 | try sema.errNote(src, msg, "consider using '.?', 'orelse', or 'if'", .{}); |
| 2351 | break :msg msg; | 2349 | break :msg msg; |
| 2352 | }; | 2350 | }; |
| 2353 | return sema.failWithOwnedErrorMsg(block, msg); | 2351 | return sema.failWithOwnedErrorMsg(block, msg); |
| ... | @@ -2355,9 +2353,9 @@ fn failWithInvalidFieldAccess( | ... | @@ -2355,9 +2353,9 @@ fn failWithInvalidFieldAccess( |
| 2355 | const child_ty = inner_ty.errorUnionPayload(mod); | 2353 | const child_ty = inner_ty.errorUnionPayload(mod); |
| 2356 | if (!typeSupportsFieldAccess(mod, child_ty, field_name)) break :err; | 2354 | if (!typeSupportsFieldAccess(mod, child_ty, field_name)) break :err; |
| 2357 | const msg = msg: { | 2355 | const msg = msg: { |
| 2358 | const msg = try sema.errMsg(block, src, "error union type '{}' does not support field access", .{object_ty.fmt(sema.mod)}); | 2356 | const msg = try sema.errMsg(src, "error union type '{}' does not support field access", .{object_ty.fmt(sema.mod)}); |
| 2359 | errdefer msg.destroy(sema.gpa); | 2357 | errdefer msg.destroy(sema.gpa); |
| 2360 | try sema.errNote(block, src, msg, "consider using 'try', 'catch', or 'if'", .{}); | 2358 | try sema.errNote(src, msg, "consider using 'try', 'catch', or 'if'", .{}); |
| 2361 | break :msg msg; | 2359 | break :msg msg; |
| 2362 | }; | 2360 | }; |
| 2363 | return sema.failWithOwnedErrorMsg(block, msg); | 2361 | return sema.failWithOwnedErrorMsg(block, msg); |
| ... | @@ -2390,11 +2388,11 @@ fn failWithComptimeErrorRetTrace( | ... | @@ -2390,11 +2388,11 @@ fn failWithComptimeErrorRetTrace( |
| 2390 | ) CompileError { | 2388 | ) CompileError { |
| 2391 | const mod = sema.mod; | 2389 | const mod = sema.mod; |
| 2392 | const msg = msg: { | 2390 | const msg = msg: { |
| 2393 | const msg = try sema.errMsg(block, src, "caught unexpected error '{}'", .{name.fmt(&mod.intern_pool)}); | 2391 | const msg = try sema.errMsg(src, "caught unexpected error '{}'", .{name.fmt(&mod.intern_pool)}); |
| 2394 | errdefer msg.destroy(sema.gpa); | 2392 | errdefer msg.destroy(sema.gpa); |
| 2395 | | 2393 | |
| 2396 | for (sema.comptime_err_ret_trace.items) |src_loc| { | 2394 | for (sema.comptime_err_ret_trace.items) |src_loc| { |
| 2397 | try mod.errNoteNonLazy(src_loc, msg, "error returned here", .{}); | 2395 | try sema.errNote(src_loc, msg, "error returned here", .{}); |
| 2398 | } | 2396 | } |
| 2399 | break :msg msg; | 2397 | break :msg msg; |
| 2400 | }; | 2398 | }; |
| ... | @@ -2403,17 +2401,15 @@ fn failWithComptimeErrorRetTrace( | ... | @@ -2403,17 +2401,15 @@ fn failWithComptimeErrorRetTrace( |
| 2403 | | 2401 | |
| 2404 | /// We don't return a pointer to the new error note because the pointer | 2402 | /// We don't return a pointer to the new error note because the pointer |
| 2405 | /// becomes invalid when you add another one. | 2403 | /// becomes invalid when you add another one. |
| 2406 | fn errNote( | 2404 | pub fn errNote( |
| 2407 | sema: *Sema, | 2405 | sema: *Sema, |
| 2408 | block: *Block, | | |
| 2409 | src: LazySrcLoc, | 2406 | src: LazySrcLoc, |
| 2410 | parent: *Module.ErrorMsg, | 2407 | parent: *Module.ErrorMsg, |
| 2411 | comptime format: []const u8, | 2408 | comptime format: []const u8, |
| 2412 | args: anytype, | 2409 | args: anytype, |
| 2413 | ) error{OutOfMemory}!void { | 2410 | ) error{OutOfMemory}!void { |
| 2414 | const mod = sema.mod; | 2411 | const zcu = sema.mod; |
| 2415 | const src_decl = mod.declPtr(block.src_decl); | 2412 | return zcu.errNoteNonLazy(src.upgrade(zcu), parent, format, args); |
| 2416 | return mod.errNoteNonLazy(src_decl.toSrcLoc(src, mod), parent, format, args); | | |
| 2417 | } | 2413 | } |
| 2418 | | 2414 | |
| 2419 | fn addFieldErrNote( | 2415 | fn addFieldErrNote( |
| ... | @@ -2425,52 +2421,23 @@ fn addFieldErrNote( | ... | @@ -2425,52 +2421,23 @@ fn addFieldErrNote( |
| 2425 | args: anytype, | 2421 | args: anytype, |
| 2426 | ) !void { | 2422 | ) !void { |
| 2427 | @setCold(true); | 2423 | @setCold(true); |
| 2428 | const mod = sema.mod; | 2424 | const zcu = sema.mod; |
| 2429 | const decl_index = container_ty.getOwnerDecl(mod); | 2425 | const type_src = container_ty.srcLocOrNull(zcu) orelse return; |
| 2430 | const decl = mod.declPtr(decl_index); | 2426 | const field_src: LazySrcLoc = .{ |
| 2431 | | 2427 | .base_node_inst = type_src.base_node_inst, |
| 2432 | const field_src = blk: { | 2428 | .offset = .{ .container_field_name = @intCast(field_index) }, |
| 2433 | const tree = decl.getFileScope(mod).getTree(sema.gpa) catch |err| { | | |
| 2434 | log.err("unable to load AST to report compile error: {s}", .{@errorName(err)}); | | |
| 2435 | break :blk decl.srcLoc(mod); | | |
| 2436 | }; | | |
| 2437 | | | |
| 2438 | const container_node = decl.relativeToNodeIndex(0); | | |
| 2439 | const node_tags = tree.nodes.items(.tag); | | |
| 2440 | var buf: [2]std.zig.Ast.Node.Index = undefined; | | |
| 2441 | const container_decl = tree.fullContainerDecl(&buf, container_node) orelse break :blk decl.srcLoc(mod); | | |
| 2442 | | | |
| 2443 | var it_index: usize = 0; | | |
| 2444 | for (container_decl.ast.members) |member_node| { | | |
| 2445 | switch (node_tags[member_node]) { | | |
| 2446 | .container_field_init, | | |
| 2447 | .container_field_align, | | |
| 2448 | .container_field, | | |
| 2449 | => { | | |
| 2450 | if (it_index == field_index) { | | |
| 2451 | break :blk decl.nodeOffsetSrcLoc(decl.nodeIndexToRelative(member_node), mod); | | |
| 2452 | } | | |
| 2453 | it_index += 1; | | |
| 2454 | }, | | |
| 2455 | else => continue, | | |
| 2456 | } | | |
| 2457 | } | | |
| 2458 | unreachable; | | |
| 2459 | }; | 2429 | }; |
| 2460 | try mod.errNoteNonLazy(field_src, parent, format, args); | 2430 | try sema.errNote(field_src, parent, format, args); |
| 2461 | } | 2431 | } |
| 2462 | | 2432 | |
| 2463 | pub fn errMsg( | 2433 | pub fn errMsg( |
| 2464 | sema: *Sema, | 2434 | sema: *Sema, |
| 2465 | block: *Block, | | |
| 2466 | src: LazySrcLoc, | 2435 | src: LazySrcLoc, |
| 2467 | comptime format: []const u8, | 2436 | comptime format: []const u8, |
| 2468 | args: anytype, | 2437 | args: anytype, |
| 2469 | ) error{ NeededSourceLocation, OutOfMemory }!*Module.ErrorMsg { | 2438 | ) Allocator.Error!*Module.ErrorMsg { |
| 2470 | const mod = sema.mod; | 2439 | assert(src.offset != .unneeded); |
| 2471 | if (src == .unneeded) return error.NeededSourceLocation; | 2440 | return Module.ErrorMsg.create(sema.gpa, src.upgrade(sema.mod), format, args); |
| 2472 | const src_decl = mod.declPtr(block.src_decl); | | |
| 2473 | return Module.ErrorMsg.create(sema.gpa, src_decl.toSrcLoc(src, mod), format, args); | | |
| 2474 | } | 2441 | } |
| 2475 | | 2442 | |
| 2476 | pub fn fail( | 2443 | pub fn fail( |
| ... | @@ -2480,7 +2447,7 @@ pub fn fail( | ... | @@ -2480,7 +2447,7 @@ pub fn fail( |
| 2480 | comptime format: []const u8, | 2447 | comptime format: []const u8, |
| 2481 | args: anytype, | 2448 | args: anytype, |
| 2482 | ) CompileError { | 2449 | ) CompileError { |
| 2483 | const err_msg = try sema.errMsg(block, src, format, args); | 2450 | const err_msg = try sema.errMsg(src, format, args); |
| 2484 | inline for (args) |arg| { | 2451 | inline for (args) |arg| { |
| 2485 | if (@TypeOf(arg) == Type.Formatter) { | 2452 | if (@TypeOf(arg) == Type.Formatter) { |
| 2486 | try addDeclaredHereNote(sema, err_msg, arg.data.ty); | 2453 | try addDeclaredHereNote(sema, err_msg, arg.data.ty); |
| ... | @@ -2514,7 +2481,6 @@ pub fn failWithOwnedErrorMsg(sema: *Sema, block: ?*Block, err_msg: *Module.Error | ... | @@ -2514,7 +2481,6 @@ pub fn failWithOwnedErrorMsg(sema: *Sema, block: ?*Block, err_msg: *Module.Error |
| 2514 | var block_it = start_block; | 2481 | var block_it = start_block; |
| 2515 | while (block_it.inlining) |inlining| { | 2482 | while (block_it.inlining) |inlining| { |
| 2516 | try sema.errNote( | 2483 | try sema.errNote( |
| 2517 | inlining.call_block, | | |
| 2518 | inlining.call_src, | 2484 | inlining.call_src, |
| 2519 | err_msg, | 2485 | err_msg, |
| 2520 | "called from here", | 2486 | "called from here", |
| ... | @@ -2548,7 +2514,7 @@ pub fn failWithOwnedErrorMsg(sema: *Sema, block: ?*Block, err_msg: *Module.Error | ... | @@ -2548,7 +2514,7 @@ pub fn failWithOwnedErrorMsg(sema: *Sema, block: ?*Block, err_msg: *Module.Error |
| 2548 | const decl = mod.declPtr(ref.referencer); | 2514 | const decl = mod.declPtr(ref.referencer); |
| 2549 | try reference_stack.append(.{ | 2515 | try reference_stack.append(.{ |
| 2550 | .decl = decl.name, | 2516 | .decl = decl.name, |
| 2551 | .src_loc = decl.toSrcLoc(ref.src, mod), | 2517 | .src_loc = ref.src.upgrade(mod), |
| 2552 | }); | 2518 | }); |
| 2553 | } | 2519 | } |
| 2554 | referenced_by = ref.referencer; | 2520 | referenced_by = ref.referencer; |
| ... | @@ -2583,15 +2549,13 @@ pub fn failWithOwnedErrorMsg(sema: *Sema, block: ?*Block, err_msg: *Module.Error | ... | @@ -2583,15 +2549,13 @@ pub fn failWithOwnedErrorMsg(sema: *Sema, block: ?*Block, err_msg: *Module.Error |
| 2583 | /// Reference trace is preserved. | 2549 | /// Reference trace is preserved. |
| 2584 | fn reparentOwnedErrorMsg( | 2550 | fn reparentOwnedErrorMsg( |
| 2585 | sema: *Sema, | 2551 | sema: *Sema, |
| 2586 | block: *Block, | | |
| 2587 | src: LazySrcLoc, | 2552 | src: LazySrcLoc, |
| 2588 | msg: *Module.ErrorMsg, | 2553 | msg: *Module.ErrorMsg, |
| 2589 | comptime format: []const u8, | 2554 | comptime format: []const u8, |
| 2590 | args: anytype, | 2555 | args: anytype, |
| 2591 | ) !void { | 2556 | ) !void { |
| 2592 | const mod = sema.mod; | 2557 | const mod = sema.mod; |
| 2593 | const src_decl = mod.declPtr(block.src_decl); | 2558 | const resolved_src = src.upgrade(mod); |
| 2594 | const resolved_src = src_decl.toSrcLoc(src, mod); | | |
| 2595 | const msg_str = try std.fmt.allocPrint(mod.gpa, format, args); | 2559 | const msg_str = try std.fmt.allocPrint(mod.gpa, format, args); |
| 2596 | | 2560 | |
| 2597 | const orig_notes = msg.notes.len; | 2561 | const orig_notes = msg.notes.len; |
| ... | @@ -2728,7 +2692,7 @@ fn getCaptures(sema: *Sema, block: *Block, type_src: LazySrcLoc, extra_index: us | ... | @@ -2728,7 +2692,7 @@ fn getCaptures(sema: *Sema, block: *Block, type_src: LazySrcLoc, extra_index: us |
| 2728 | sema.code.nullTerminatedString(str), | 2692 | sema.code.nullTerminatedString(str), |
| 2729 | .no_embedded_nulls, | 2693 | .no_embedded_nulls, |
| 2730 | ); | 2694 | ); |
| 2731 | const decl = try sema.lookupIdentifier(block, .unneeded, decl_name); // TODO: could we need this src loc? | 2695 | const decl = try sema.lookupIdentifier(block, LazySrcLoc.unneeded, decl_name); // TODO: could we need this src loc? |
| 2732 | break :capture InternPool.CaptureValue.wrap(.{ .decl_val = decl }); | 2696 | break :capture InternPool.CaptureValue.wrap(.{ .decl_val = decl }); |
| 2733 | }, | 2697 | }, |
| 2734 | .decl_ref => |str| capture: { | 2698 | .decl_ref => |str| capture: { |
| ... | @@ -2737,7 +2701,7 @@ fn getCaptures(sema: *Sema, block: *Block, type_src: LazySrcLoc, extra_index: us | ... | @@ -2737,7 +2701,7 @@ fn getCaptures(sema: *Sema, block: *Block, type_src: LazySrcLoc, extra_index: us |
| 2737 | sema.code.nullTerminatedString(str), | 2701 | sema.code.nullTerminatedString(str), |
| 2738 | .no_embedded_nulls, | 2702 | .no_embedded_nulls, |
| 2739 | ); | 2703 | ); |
| 2740 | const decl = try sema.lookupIdentifier(block, .unneeded, decl_name); // TODO: could we need this src loc? | 2704 | const decl = try sema.lookupIdentifier(block, LazySrcLoc.unneeded, decl_name); // TODO: could we need this src loc? |
| 2741 | break :capture InternPool.CaptureValue.wrap(.{ .decl_ref = decl }); | 2705 | break :capture InternPool.CaptureValue.wrap(.{ .decl_ref = decl }); |
| 2742 | }, | 2706 | }, |
| 2743 | }; | 2707 | }; |
| ... | @@ -2788,7 +2752,13 @@ fn zirStructDecl( | ... | @@ -2788,7 +2752,13 @@ fn zirStructDecl( |
| 2788 | const ip = &mod.intern_pool; | 2752 | const ip = &mod.intern_pool; |
| 2789 | const small: Zir.Inst.StructDecl.Small = @bitCast(extended.small); | 2753 | const small: Zir.Inst.StructDecl.Small = @bitCast(extended.small); |
| 2790 | const extra = sema.code.extraData(Zir.Inst.StructDecl, extended.operand); | 2754 | const extra = sema.code.extraData(Zir.Inst.StructDecl, extended.operand); |
| 2791 | const src: LazySrcLoc = .{ .node_abs = extra.data.src_node }; | 2755 | |
| | 2756 | const tracked_inst = try ip.trackZir(gpa, block.getFileScope(mod), inst); |
| | 2757 | const src: LazySrcLoc = .{ |
| | 2758 | .base_node_inst = tracked_inst, |
| | 2759 | .offset = LazySrcLoc.Offset.nodeOffset(0), |
| | 2760 | }; |
| | 2761 | |
| 2792 | var extra_index = extra.end; | 2762 | var extra_index = extra.end; |
| 2793 | | 2763 | |
| 2794 | const captures_len = if (small.has_captures_len) blk: { | 2764 | const captures_len = if (small.has_captures_len) blk: { |
| ... | @@ -2832,7 +2802,7 @@ fn zirStructDecl( | ... | @@ -2832,7 +2802,7 @@ fn zirStructDecl( |
| 2832 | .any_aligned_fields = small.any_aligned_fields, | 2802 | .any_aligned_fields = small.any_aligned_fields, |
| 2833 | .has_namespace = true or decls_len > 0, // TODO: see below | 2803 | .has_namespace = true or decls_len > 0, // TODO: see below |
| 2834 | .key = .{ .declared = .{ | 2804 | .key = .{ .declared = .{ |
| 2835 | .zir_index = try ip.trackZir(gpa, block.getFileScope(mod), inst), | 2805 | .zir_index = tracked_inst, |
| 2836 | .captures = captures, | 2806 | .captures = captures, |
| 2837 | } }, | 2807 | } }, |
| 2838 | }; | 2808 | }; |
| ... | @@ -2847,7 +2817,6 @@ fn zirStructDecl( | ... | @@ -2847,7 +2817,6 @@ fn zirStructDecl( |
| 2847 | | 2817 | |
| 2848 | const new_decl_index = try sema.createAnonymousDeclTypeNamed( | 2818 | const new_decl_index = try sema.createAnonymousDeclTypeNamed( |
| 2849 | block, | 2819 | block, |
| 2850 | extra.data.src_node, | | |
| 2851 | Value.fromInterned(wip_ty.index), | 2820 | Value.fromInterned(wip_ty.index), |
| 2852 | small.name_strategy, | 2821 | small.name_strategy, |
| 2853 | "struct", | 2822 | "struct", |
| ... | @@ -2884,7 +2853,6 @@ fn zirStructDecl( | ... | @@ -2884,7 +2853,6 @@ fn zirStructDecl( |
| 2884 | fn createAnonymousDeclTypeNamed( | 2853 | fn createAnonymousDeclTypeNamed( |
| 2885 | sema: *Sema, | 2854 | sema: *Sema, |
| 2886 | block: *Block, | 2855 | block: *Block, |
| 2887 | src_node: std.zig.Ast.Node.Index, | | |
| 2888 | val: Value, | 2856 | val: Value, |
| 2889 | name_strategy: Zir.Inst.NameStrategy, | 2857 | name_strategy: Zir.Inst.NameStrategy, |
| 2890 | anon_prefix: []const u8, | 2858 | anon_prefix: []const u8, |
| ... | @@ -2895,7 +2863,7 @@ fn createAnonymousDeclTypeNamed( | ... | @@ -2895,7 +2863,7 @@ fn createAnonymousDeclTypeNamed( |
| 2895 | const gpa = sema.gpa; | 2863 | const gpa = sema.gpa; |
| 2896 | const namespace = block.namespace; | 2864 | const namespace = block.namespace; |
| 2897 | const src_decl = zcu.declPtr(block.src_decl); | 2865 | const src_decl = zcu.declPtr(block.src_decl); |
| 2898 | const new_decl_index = try zcu.allocateNewDecl(namespace, src_node); | 2866 | const new_decl_index = try zcu.allocateNewDecl(namespace); |
| 2899 | errdefer zcu.destroyDecl(new_decl_index); | 2867 | errdefer zcu.destroyDecl(new_decl_index); |
| 2900 | | 2868 | |
| 2901 | switch (name_strategy) { | 2869 | switch (name_strategy) { |
| ... | @@ -2924,8 +2892,7 @@ fn createAnonymousDeclTypeNamed( | ... | @@ -2924,8 +2892,7 @@ fn createAnonymousDeclTypeNamed( |
| 2924 | // If not then this is a struct type being returned from a non-generic | 2892 | // If not then this is a struct type being returned from a non-generic |
| 2925 | // function and the name doesn't matter since it will later | 2893 | // function and the name doesn't matter since it will later |
| 2926 | // result in a compile error. | 2894 | // result in a compile error. |
| 2927 | const arg_val = sema.resolveConstValue(block, .unneeded, arg, undefined) catch | 2895 | const arg_val = try sema.resolveValue(arg) orelse break :func_strat; // fall through to anon strat |
| 2928 | break :func_strat; // fall through to anon strat | | |
| 2929 | | 2896 | |
| 2930 | if (arg_i != 0) try writer.writeByte(','); | 2897 | if (arg_i != 0) try writer.writeByte(','); |
| 2931 | | 2898 | |
| ... | @@ -3003,7 +2970,9 @@ fn zirEnumDecl( | ... | @@ -3003,7 +2970,9 @@ fn zirEnumDecl( |
| 3003 | const extra = sema.code.extraData(Zir.Inst.EnumDecl, extended.operand); | 2970 | const extra = sema.code.extraData(Zir.Inst.EnumDecl, extended.operand); |
| 3004 | var extra_index: usize = extra.end; | 2971 | var extra_index: usize = extra.end; |
| 3005 | | 2972 | |
| 3006 | const src: LazySrcLoc = .{ .node_abs = extra.data.src_node }; | 2973 | const tracked_inst = try ip.trackZir(gpa, block.getFileScope(mod), inst); |
| | 2974 | const src: LazySrcLoc = .{ .base_node_inst = tracked_inst, .offset = LazySrcLoc.Offset.nodeOffset(0) }; |
| | 2975 | const tag_ty_src: LazySrcLoc = .{ .base_node_inst = tracked_inst, .offset = .{ .node_offset_container_tag = 0 } }; |
| 3007 | | 2976 | |
| 3008 | const tag_type_ref = if (small.has_tag_type) blk: { | 2977 | const tag_type_ref = if (small.has_tag_type) blk: { |
| 3009 | const tag_type_ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_index]); | 2978 | const tag_type_ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_index]); |
| ... | @@ -3063,7 +3032,7 @@ fn zirEnumDecl( | ... | @@ -3063,7 +3032,7 @@ fn zirEnumDecl( |
| 3063 | .explicit, | 3032 | .explicit, |
| 3064 | .fields_len = fields_len, | 3033 | .fields_len = fields_len, |
| 3065 | .key = .{ .declared = .{ | 3034 | .key = .{ .declared = .{ |
| 3066 | .zir_index = try mod.intern_pool.trackZir(sema.gpa, block.getFileScope(mod), inst), | 3035 | .zir_index = tracked_inst, |
| 3067 | .captures = captures, | 3036 | .captures = captures, |
| 3068 | } }, | 3037 | } }, |
| 3069 | }; | 3038 | }; |
| ... | @@ -3083,7 +3052,6 @@ fn zirEnumDecl( | ... | @@ -3083,7 +3052,6 @@ fn zirEnumDecl( |
| 3083 | | 3052 | |
| 3084 | const new_decl_index = try sema.createAnonymousDeclTypeNamed( | 3053 | const new_decl_index = try sema.createAnonymousDeclTypeNamed( |
| 3085 | block, | 3054 | block, |
| 3086 | extra.data.src_node, | | |
| 3087 | Value.fromInterned(wip_ty.index), | 3055 | Value.fromInterned(wip_ty.index), |
| 3088 | small.name_strategy, | 3056 | small.name_strategy, |
| 3089 | "enum", | 3057 | "enum", |
| ... | @@ -3149,12 +3117,10 @@ fn zirEnumDecl( | ... | @@ -3149,12 +3117,10 @@ fn zirEnumDecl( |
| 3149 | .instructions = .{}, | 3117 | .instructions = .{}, |
| 3150 | .inlining = null, | 3118 | .inlining = null, |
| 3151 | .is_comptime = true, | 3119 | .is_comptime = true, |
| | 3120 | .src_base_inst = tracked_inst, |
| 3152 | }; | 3121 | }; |
| 3153 | defer enum_block.instructions.deinit(sema.gpa); | 3122 | defer enum_block.instructions.deinit(sema.gpa); |
| 3154 | | 3123 | |
| 3155 | // This source location applies in the context of `enum_block`. | | |
| 3156 | const tag_ty_src: LazySrcLoc = .{ .node_offset_container_tag = 0 }; | | |
| 3157 | | | |
| 3158 | if (body.len != 0) { | 3124 | if (body.len != 0) { |
| 3159 | _ = try sema.analyzeInlineBody(&enum_block, body, inst); | 3125 | _ = try sema.analyzeInlineBody(&enum_block, body, inst); |
| 3160 | } | 3126 | } |
| ... | @@ -3199,36 +3165,33 @@ fn zirEnumDecl( | ... | @@ -3199,36 +3165,33 @@ fn zirEnumDecl( |
| 3199 | | 3165 | |
| 3200 | const field_name = try mod.intern_pool.getOrPutString(gpa, field_name_zir, .no_embedded_nulls); | 3166 | const field_name = try mod.intern_pool.getOrPutString(gpa, field_name_zir, .no_embedded_nulls); |
| 3201 | | 3167 | |
| | 3168 | const value_src: LazySrcLoc = .{ |
| | 3169 | .base_node_inst = tracked_inst, |
| | 3170 | .offset = .{ .container_field_value = field_i }, |
| | 3171 | }; |
| | 3172 | |
| 3202 | const tag_overflow = if (has_tag_value) overflow: { | 3173 | const tag_overflow = if (has_tag_value) overflow: { |
| 3203 | const tag_val_ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_index]); | 3174 | const tag_val_ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_index]); |
| 3204 | extra_index += 1; | 3175 | extra_index += 1; |
| 3205 | const tag_inst = try sema.resolveInst(tag_val_ref); | 3176 | const tag_inst = try sema.resolveInst(tag_val_ref); |
| 3206 | last_tag_val = sema.resolveConstDefinedValue(block, .unneeded, tag_inst, undefined) catch |err| switch (err) { | 3177 | last_tag_val = try sema.resolveConstDefinedValue(block, .{ |
| 3207 | error.NeededSourceLocation => { | 3178 | .base_node_inst = tracked_inst, |
| 3208 | const value_src = mod.fieldSrcLoc(new_decl_index, .{ | 3179 | .offset = .{ .container_field_name = field_i }, |
| 3209 | .index = field_i, | 3180 | }, tag_inst, .{ |
| 3210 | .range = .value, | 3181 | .needed_comptime_reason = "enum tag value must be comptime-known", |
| 3211 | }).lazy; | 3182 | }); |
| 3212 | _ = try sema.resolveConstDefinedValue(block, value_src, tag_inst, .{ | | |
| 3213 | .needed_comptime_reason = "enum tag value must be comptime-known", | | |
| 3214 | }); | | |
| 3215 | unreachable; | | |
| 3216 | }, | | |
| 3217 | else => |e| return e, | | |
| 3218 | }; | | |
| 3219 | if (!(try sema.intFitsInType(last_tag_val.?, int_tag_ty, null))) break :overflow true; | 3183 | if (!(try sema.intFitsInType(last_tag_val.?, int_tag_ty, null))) break :overflow true; |
| 3220 | last_tag_val = try mod.getCoerced(last_tag_val.?, int_tag_ty); | 3184 | last_tag_val = try mod.getCoerced(last_tag_val.?, int_tag_ty); |
| 3221 | if (wip_ty.nextField(&mod.intern_pool, field_name, last_tag_val.?.toIntern())) |conflict| { | 3185 | if (wip_ty.nextField(&mod.intern_pool, field_name, last_tag_val.?.toIntern())) |conflict| { |
| 3222 | assert(conflict.kind == .value); // AstGen validated names are unique | 3186 | assert(conflict.kind == .value); // AstGen validated names are unique |
| 3223 | const value_src = mod.fieldSrcLoc(new_decl_index, .{ | 3187 | const other_field_src: LazySrcLoc = .{ |
| 3224 | .index = field_i, | 3188 | .base_node_inst = tracked_inst, |
| 3225 | .range = .value, | 3189 | .offset = .{ .container_field_value = conflict.prev_field_idx }, |
| 3226 | }).lazy; | 3190 | }; |
| 3227 | const other_field_src = mod.fieldSrcLoc(new_decl_index, .{ .index = conflict.prev_field_idx }).lazy; | | |
| 3228 | const msg = msg: { | 3191 | const msg = msg: { |
| 3229 | const msg = try sema.errMsg(block, value_src, "enum tag value {} already taken", .{last_tag_val.?.fmtValue(sema.mod, sema)}); | 3192 | const msg = try sema.errMsg(value_src, "enum tag value {} already taken", .{last_tag_val.?.fmtValue(sema.mod, sema)}); |
| 3230 | errdefer msg.destroy(gpa); | 3193 | errdefer msg.destroy(gpa); |
| 3231 | try sema.errNote(block, other_field_src, msg, "other occurrence here", .{}); | 3194 | try sema.errNote(other_field_src, msg, "other occurrence here", .{}); |
| 3232 | break :msg msg; | 3195 | break :msg msg; |
| 3233 | }; | 3196 | }; |
| 3234 | return sema.failWithOwnedErrorMsg(block, msg); | 3197 | return sema.failWithOwnedErrorMsg(block, msg); |
| ... | @@ -3243,12 +3206,14 @@ fn zirEnumDecl( | ... | @@ -3243,12 +3206,14 @@ fn zirEnumDecl( |
| 3243 | if (overflow != null) break :overflow true; | 3206 | if (overflow != null) break :overflow true; |
| 3244 | if (wip_ty.nextField(&mod.intern_pool, field_name, last_tag_val.?.toIntern())) |conflict| { | 3207 | if (wip_ty.nextField(&mod.intern_pool, field_name, last_tag_val.?.toIntern())) |conflict| { |
| 3245 | assert(conflict.kind == .value); // AstGen validated names are unique | 3208 | assert(conflict.kind == .value); // AstGen validated names are unique |
| 3246 | const field_src = mod.fieldSrcLoc(new_decl_index, .{ .index = field_i }).lazy; | 3209 | const other_field_src: LazySrcLoc = .{ |
| 3247 | const other_field_src = mod.fieldSrcLoc(new_decl_index, .{ .index = conflict.prev_field_idx }).lazy; | 3210 | .base_node_inst = tracked_inst, |
| | 3211 | .offset = .{ .container_field_value = conflict.prev_field_idx }, |
| | 3212 | }; |
| 3248 | const msg = msg: { | 3213 | const msg = msg: { |
| 3249 | const msg = try sema.errMsg(block, field_src, "enum tag value {} already taken", .{last_tag_val.?.fmtValue(sema.mod, sema)}); | 3214 | const msg = try sema.errMsg(value_src, "enum tag value {} already taken", .{last_tag_val.?.fmtValue(sema.mod, sema)}); |
| 3250 | errdefer msg.destroy(gpa); | 3215 | errdefer msg.destroy(gpa); |
| 3251 | try sema.errNote(block, other_field_src, msg, "other occurrence here", .{}); | 3216 | try sema.errNote(other_field_src, msg, "other occurrence here", .{}); |
| 3252 | break :msg msg; | 3217 | break :msg msg; |
| 3253 | }; | 3218 | }; |
| 3254 | return sema.failWithOwnedErrorMsg(block, msg); | 3219 | return sema.failWithOwnedErrorMsg(block, msg); |
| ... | @@ -3263,11 +3228,7 @@ fn zirEnumDecl( | ... | @@ -3263,11 +3228,7 @@ fn zirEnumDecl( |
| 3263 | }; | 3228 | }; |
| 3264 | | 3229 | |
| 3265 | if (tag_overflow) { | 3230 | if (tag_overflow) { |
| 3266 | const value_src = mod.fieldSrcLoc(new_decl_index, .{ | 3231 | const msg = try sema.errMsg(value_src, "enumeration value '{}' too large for type '{}'", .{ |
| 3267 | .index = field_i, | | |
| 3268 | .range = if (has_tag_value) .value else .name, | | |
| 3269 | }).lazy; | | |
| 3270 | const msg = try sema.errMsg(block, value_src, "enumeration value '{}' too large for type '{}'", .{ | | |
| 3271 | last_tag_val.?.fmtValue(mod, sema), int_tag_ty.fmt(mod), | 3232 | last_tag_val.?.fmtValue(mod, sema), int_tag_ty.fmt(mod), |
| 3272 | }); | 3233 | }); |
| 3273 | return sema.failWithOwnedErrorMsg(block, msg); | 3234 | return sema.failWithOwnedErrorMsg(block, msg); |
| ... | @@ -3294,7 +3255,8 @@ fn zirUnionDecl( | ... | @@ -3294,7 +3255,8 @@ fn zirUnionDecl( |
| 3294 | const extra = sema.code.extraData(Zir.Inst.UnionDecl, extended.operand); | 3255 | const extra = sema.code.extraData(Zir.Inst.UnionDecl, extended.operand); |
| 3295 | var extra_index: usize = extra.end; | 3256 | var extra_index: usize = extra.end; |
| 3296 | | 3257 | |
| 3297 | const src: LazySrcLoc = .{ .node_abs = extra.data.src_node }; | 3258 | const tracked_inst = try ip.trackZir(gpa, block.getFileScope(mod), inst); |
| | 3259 | const src: LazySrcLoc = .{ .base_node_inst = tracked_inst, .offset = LazySrcLoc.Offset.nodeOffset(0) }; |
| 3298 | | 3260 | |
| 3299 | extra_index += @intFromBool(small.has_tag_type); | 3261 | extra_index += @intFromBool(small.has_tag_type); |
| 3300 | const captures_len = if (small.has_captures_len) blk: { | 3262 | const captures_len = if (small.has_captures_len) blk: { |
| ... | @@ -3342,7 +3304,7 @@ fn zirUnionDecl( | ... | @@ -3342,7 +3304,7 @@ fn zirUnionDecl( |
| 3342 | .field_types = &.{}, // set later | 3304 | .field_types = &.{}, // set later |
| 3343 | .field_aligns = &.{}, // set later | 3305 | .field_aligns = &.{}, // set later |
| 3344 | .key = .{ .declared = .{ | 3306 | .key = .{ .declared = .{ |
| 3345 | .zir_index = try ip.trackZir(gpa, block.getFileScope(mod), inst), | 3307 | .zir_index = tracked_inst, |
| 3346 | .captures = captures, | 3308 | .captures = captures, |
| 3347 | } }, | 3309 | } }, |
| 3348 | }; | 3310 | }; |
| ... | @@ -3357,7 +3319,6 @@ fn zirUnionDecl( | ... | @@ -3357,7 +3319,6 @@ fn zirUnionDecl( |
| 3357 | | 3319 | |
| 3358 | const new_decl_index = try sema.createAnonymousDeclTypeNamed( | 3320 | const new_decl_index = try sema.createAnonymousDeclTypeNamed( |
| 3359 | block, | 3321 | block, |
| 3360 | extra.data.src_node, | | |
| 3361 | Value.fromInterned(wip_ty.index), | 3322 | Value.fromInterned(wip_ty.index), |
| 3362 | small.name_strategy, | 3323 | small.name_strategy, |
| 3363 | "union", | 3324 | "union", |
| ... | @@ -3409,7 +3370,8 @@ fn zirOpaqueDecl( | ... | @@ -3409,7 +3370,8 @@ fn zirOpaqueDecl( |
| 3409 | const extra = sema.code.extraData(Zir.Inst.OpaqueDecl, extended.operand); | 3370 | const extra = sema.code.extraData(Zir.Inst.OpaqueDecl, extended.operand); |
| 3410 | var extra_index: usize = extra.end; | 3371 | var extra_index: usize = extra.end; |
| 3411 | | 3372 | |
| 3412 | const src: LazySrcLoc = .{ .node_abs = extra.data.src_node }; | 3373 | const tracked_inst = try ip.trackZir(gpa, block.getFileScope(mod), inst); |
| | 3374 | const src: LazySrcLoc = .{ .base_node_inst = tracked_inst, .offset = LazySrcLoc.Offset.nodeOffset(0) }; |
| 3413 | | 3375 | |
| 3414 | const captures_len = if (small.has_captures_len) blk: { | 3376 | const captures_len = if (small.has_captures_len) blk: { |
| 3415 | const captures_len = sema.code.extra[extra_index]; | 3377 | const captures_len = sema.code.extra[extra_index]; |
| ... | @@ -3429,7 +3391,7 @@ fn zirOpaqueDecl( | ... | @@ -3429,7 +3391,7 @@ fn zirOpaqueDecl( |
| 3429 | const opaque_init: InternPool.OpaqueTypeInit = .{ | 3391 | const opaque_init: InternPool.OpaqueTypeInit = .{ |
| 3430 | .has_namespace = decls_len != 0, | 3392 | .has_namespace = decls_len != 0, |
| 3431 | .key = .{ .declared = .{ | 3393 | .key = .{ .declared = .{ |
| 3432 | .zir_index = try ip.trackZir(gpa, block.getFileScope(mod), inst), | 3394 | .zir_index = tracked_inst, |
| 3433 | .captures = captures, | 3395 | .captures = captures, |
| 3434 | } }, | 3396 | } }, |
| 3435 | }; | 3397 | }; |
| ... | @@ -3445,7 +3407,6 @@ fn zirOpaqueDecl( | ... | @@ -3445,7 +3407,6 @@ fn zirOpaqueDecl( |
| 3445 | | 3407 | |
| 3446 | const new_decl_index = try sema.createAnonymousDeclTypeNamed( | 3408 | const new_decl_index = try sema.createAnonymousDeclTypeNamed( |
| 3447 | block, | 3409 | block, |
| 3448 | extra.data.src_node, | | |
| 3449 | Value.fromInterned(wip_ty.index), | 3410 | Value.fromInterned(wip_ty.index), |
| 3450 | small.name_strategy, | 3411 | small.name_strategy, |
| 3451 | "opaque", | 3412 | "opaque", |
| ... | @@ -3566,19 +3527,19 @@ fn ensureResultUsed( | ... | @@ -3566,19 +3527,19 @@ fn ensureResultUsed( |
| 3566 | .ErrorSet => return sema.fail(block, src, "error set is ignored", .{}), | 3527 | .ErrorSet => return sema.fail(block, src, "error set is ignored", .{}), |
| 3567 | .ErrorUnion => { | 3528 | .ErrorUnion => { |
| 3568 | const msg = msg: { | 3529 | const msg = msg: { |
| 3569 | const msg = try sema.errMsg(block, src, "error union is ignored", .{}); | 3530 | const msg = try sema.errMsg(src, "error union is ignored", .{}); |
| 3570 | errdefer msg.destroy(sema.gpa); | 3531 | errdefer msg.destroy(sema.gpa); |
| 3571 | try sema.errNote(block, src, msg, "consider using 'try', 'catch', or 'if'", .{}); | 3532 | try sema.errNote(src, msg, "consider using 'try', 'catch', or 'if'", .{}); |
| 3572 | break :msg msg; | 3533 | break :msg msg; |
| 3573 | }; | 3534 | }; |
| 3574 | return sema.failWithOwnedErrorMsg(block, msg); | 3535 | return sema.failWithOwnedErrorMsg(block, msg); |
| 3575 | }, | 3536 | }, |
| 3576 | else => { | 3537 | else => { |
| 3577 | const msg = msg: { | 3538 | const msg = msg: { |
| 3578 | const msg = try sema.errMsg(block, src, "value of type '{}' ignored", .{ty.fmt(sema.mod)}); | 3539 | const msg = try sema.errMsg(src, "value of type '{}' ignored", .{ty.fmt(sema.mod)}); |
| 3579 | errdefer msg.destroy(sema.gpa); | 3540 | errdefer msg.destroy(sema.gpa); |
| 3580 | try sema.errNote(block, src, msg, "all non-void values must be used", .{}); | 3541 | try sema.errNote(src, msg, "all non-void values must be used", .{}); |
| 3581 | try sema.errNote(block, src, msg, "to discard the value, assign it to '_'", .{}); | 3542 | try sema.errNote(src, msg, "to discard the value, assign it to '_'", .{}); |
| 3582 | break :msg msg; | 3543 | break :msg msg; |
| 3583 | }; | 3544 | }; |
| 3584 | return sema.failWithOwnedErrorMsg(block, msg); | 3545 | return sema.failWithOwnedErrorMsg(block, msg); |
| ... | @@ -3599,9 +3560,9 @@ fn zirEnsureResultNonError(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com | ... | @@ -3599,9 +3560,9 @@ fn zirEnsureResultNonError(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com |
| 3599 | .ErrorSet => return sema.fail(block, src, "error set is discarded", .{}), | 3560 | .ErrorSet => return sema.fail(block, src, "error set is discarded", .{}), |
| 3600 | .ErrorUnion => { | 3561 | .ErrorUnion => { |
| 3601 | const msg = msg: { | 3562 | const msg = msg: { |
| 3602 | const msg = try sema.errMsg(block, src, "error union is discarded", .{}); | 3563 | const msg = try sema.errMsg(src, "error union is discarded", .{}); |
| 3603 | errdefer msg.destroy(sema.gpa); | 3564 | errdefer msg.destroy(sema.gpa); |
| 3604 | try sema.errNote(block, src, msg, "consider using 'try', 'catch', or 'if'", .{}); | 3565 | try sema.errNote(src, msg, "consider using 'try', 'catch', or 'if'", .{}); |
| 3605 | break :msg msg; | 3566 | break :msg msg; |
| 3606 | }; | 3567 | }; |
| 3607 | return sema.failWithOwnedErrorMsg(block, msg); | 3568 | return sema.failWithOwnedErrorMsg(block, msg); |
| ... | @@ -3627,9 +3588,9 @@ fn zirEnsureErrUnionPayloadVoid(sema: *Sema, block: *Block, inst: Zir.Inst.Index | ... | @@ -3627,9 +3588,9 @@ fn zirEnsureErrUnionPayloadVoid(sema: *Sema, block: *Block, inst: Zir.Inst.Index |
| 3627 | const payload_ty = err_union_ty.errorUnionPayload(mod).zigTypeTag(mod); | 3588 | const payload_ty = err_union_ty.errorUnionPayload(mod).zigTypeTag(mod); |
| 3628 | if (payload_ty != .Void and payload_ty != .NoReturn) { | 3589 | if (payload_ty != .Void and payload_ty != .NoReturn) { |
| 3629 | const msg = msg: { | 3590 | const msg = msg: { |
| 3630 | const msg = try sema.errMsg(block, src, "error union payload is ignored", .{}); | 3591 | const msg = try sema.errMsg(src, "error union payload is ignored", .{}); |
| 3631 | errdefer msg.destroy(sema.gpa); | 3592 | errdefer msg.destroy(sema.gpa); |
| 3632 | try sema.errNote(block, src, msg, "payload value can be explicitly ignored with '|_|'", .{}); | 3593 | try sema.errNote(src, msg, "payload value can be explicitly ignored with '|_|'", .{}); |
| 3633 | break :msg msg; | 3594 | break :msg msg; |
| 3634 | }; | 3595 | }; |
| 3635 | return sema.failWithOwnedErrorMsg(block, msg); | 3596 | return sema.failWithOwnedErrorMsg(block, msg); |
| ... | @@ -3683,8 +3644,8 @@ fn zirAllocExtended( | ... | @@ -3683,8 +3644,8 @@ fn zirAllocExtended( |
| 3683 | ) CompileError!Air.Inst.Ref { | 3644 | ) CompileError!Air.Inst.Ref { |
| 3684 | const gpa = sema.gpa; | 3645 | const gpa = sema.gpa; |
| 3685 | const extra = sema.code.extraData(Zir.Inst.AllocExtended, extended.operand); | 3646 | const extra = sema.code.extraData(Zir.Inst.AllocExtended, extended.operand); |
| 3686 | const ty_src: LazySrcLoc = .{ .node_offset_var_decl_ty = extra.data.src_node }; | 3647 | const ty_src = block.src(.{ .node_offset_var_decl_ty = extra.data.src_node }); |
| 3687 | const align_src: LazySrcLoc = .{ .node_offset_var_decl_align = extra.data.src_node }; | 3648 | const align_src = block.src(.{ .node_offset_var_decl_align = extra.data.src_node }); |
| 3688 | const small: Zir.Inst.AllocExtended.Small = @bitCast(extended.small); | 3649 | const small: Zir.Inst.AllocExtended.Small = @bitCast(extended.small); |
| 3689 | | 3650 | |
| 3690 | var extra_index: usize = extra.end; | 3651 | var extra_index: usize = extra.end; |
| ... | @@ -3760,7 +3721,7 @@ fn zirAllocComptime(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr | ... | @@ -3760,7 +3721,7 @@ fn zirAllocComptime(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr |
| 3760 | defer tracy.end(); | 3721 | defer tracy.end(); |
| 3761 | | 3722 | |
| 3762 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; | 3723 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 3763 | const ty_src: LazySrcLoc = .{ .node_offset_var_decl_ty = inst_data.src_node }; | 3724 | const ty_src = block.src(.{ .node_offset_var_decl_ty = inst_data.src_node }); |
| 3764 | const var_ty = try sema.resolveType(block, ty_src, inst_data.operand); | 3725 | const var_ty = try sema.resolveType(block, ty_src, inst_data.operand); |
| 3765 | return sema.analyzeComptimeAlloc(block, var_ty, .none); | 3726 | return sema.analyzeComptimeAlloc(block, var_ty, .none); |
| 3766 | } | 3727 | } |
| ... | @@ -3826,7 +3787,7 @@ fn zirMakePtrConst(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro | ... | @@ -3826,7 +3787,7 @@ fn zirMakePtrConst(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro |
| 3826 | if (try sema.typeRequiresComptime(elem_ty)) { | 3787 | if (try sema.typeRequiresComptime(elem_ty)) { |
| 3827 | // The value was initialized through RLS, so we didn't detect the runtime condition earlier. | 3788 | // The value was initialized through RLS, so we didn't detect the runtime condition earlier. |
| 3828 | // TODO: source location of runtime control flow | 3789 | // TODO: source location of runtime control flow |
| 3829 | const init_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node }; | 3790 | const init_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node }); |
| 3830 | return sema.fail(block, init_src, "value with comptime-only type '{}' depends on runtime control flow", .{elem_ty.fmt(mod)}); | 3791 | return sema.fail(block, init_src, "value with comptime-only type '{}' depends on runtime control flow", .{elem_ty.fmt(mod)}); |
| 3831 | } | 3792 | } |
| 3832 | | 3793 | |
| ... | @@ -3995,7 +3956,7 @@ fn resolveComptimeKnownAllocPtr(sema: *Sema, block: *Block, alloc: Air.Inst.Ref, | ... | @@ -3995,7 +3956,7 @@ fn resolveComptimeKnownAllocPtr(sema: *Sema, block: *Block, alloc: Air.Inst.Ref, |
| 3995 | .ty = opt_ty.toIntern(), | 3956 | .ty = opt_ty.toIntern(), |
| 3996 | .val = payload_val.toIntern(), | 3957 | .val = payload_val.toIntern(), |
| 3997 | } }); | 3958 | } }); |
| 3998 | try sema.storePtrVal(block, .unneeded, Value.fromInterned(decl_parent_ptr), Value.fromInterned(opt_val), opt_ty); | 3959 | try sema.storePtrVal(block, LazySrcLoc.unneeded, Value.fromInterned(decl_parent_ptr), Value.fromInterned(opt_val), opt_ty); |
| 3999 | break :ptr (try Value.fromInterned(decl_parent_ptr).ptrOptPayload(sema)).toIntern(); | 3960 | break :ptr (try Value.fromInterned(decl_parent_ptr).ptrOptPayload(sema)).toIntern(); |
| 4000 | }, | 3961 | }, |
| 4001 | .eu_payload => ptr: { | 3962 | .eu_payload => ptr: { |
| ... | @@ -4008,7 +3969,7 @@ fn resolveComptimeKnownAllocPtr(sema: *Sema, block: *Block, alloc: Air.Inst.Ref, | ... | @@ -4008,7 +3969,7 @@ fn resolveComptimeKnownAllocPtr(sema: *Sema, block: *Block, alloc: Air.Inst.Ref, |
| 4008 | .ty = eu_ty.toIntern(), | 3969 | .ty = eu_ty.toIntern(), |
| 4009 | .val = .{ .payload = payload_val.toIntern() }, | 3970 | .val = .{ .payload = payload_val.toIntern() }, |
| 4010 | } }); | 3971 | } }); |
| 4011 | try sema.storePtrVal(block, .unneeded, Value.fromInterned(decl_parent_ptr), Value.fromInterned(eu_val), eu_ty); | 3972 | try sema.storePtrVal(block, LazySrcLoc.unneeded, Value.fromInterned(decl_parent_ptr), Value.fromInterned(eu_val), eu_ty); |
| 4012 | break :ptr (try Value.fromInterned(decl_parent_ptr).ptrEuPayload(sema)).toIntern(); | 3973 | break :ptr (try Value.fromInterned(decl_parent_ptr).ptrEuPayload(sema)).toIntern(); |
| 4013 | }, | 3974 | }, |
| 4014 | .field => |idx| ptr: { | 3975 | .field => |idx| ptr: { |
| ... | @@ -4021,7 +3982,7 @@ fn resolveComptimeKnownAllocPtr(sema: *Sema, block: *Block, alloc: Air.Inst.Ref, | ... | @@ -4021,7 +3982,7 @@ fn resolveComptimeKnownAllocPtr(sema: *Sema, block: *Block, alloc: Air.Inst.Ref, |
| 4021 | const payload_val = try sema.typeHasOnePossibleValue(payload_ty) orelse try zcu.undefValue(payload_ty); | 3982 | const payload_val = try sema.typeHasOnePossibleValue(payload_ty) orelse try zcu.undefValue(payload_ty); |
| 4022 | const tag_val = try zcu.enumValueFieldIndex(Type.fromInterned(union_obj.enum_tag_ty), idx); | 3983 | const tag_val = try zcu.enumValueFieldIndex(Type.fromInterned(union_obj.enum_tag_ty), idx); |
| 4023 | const store_val = try zcu.unionValue(maybe_union_ty, tag_val, payload_val); | 3984 | const store_val = try zcu.unionValue(maybe_union_ty, tag_val, payload_val); |
| 4024 | try sema.storePtrVal(block, .unneeded, Value.fromInterned(decl_parent_ptr), store_val, maybe_union_ty); | 3985 | try sema.storePtrVal(block, LazySrcLoc.unneeded, Value.fromInterned(decl_parent_ptr), store_val, maybe_union_ty); |
| 4025 | } | 3986 | } |
| 4026 | break :ptr (try Value.fromInterned(decl_parent_ptr).ptrField(idx, sema)).toIntern(); | 3987 | break :ptr (try Value.fromInterned(decl_parent_ptr).ptrField(idx, sema)).toIntern(); |
| 4027 | }, | 3988 | }, |
| ... | @@ -4043,14 +4004,14 @@ fn resolveComptimeKnownAllocPtr(sema: *Sema, block: *Block, alloc: Air.Inst.Ref, | ... | @@ -4043,14 +4004,14 @@ fn resolveComptimeKnownAllocPtr(sema: *Sema, block: *Block, alloc: Air.Inst.Ref, |
| 4043 | const air_ptr_inst = store_inst.data.bin_op.lhs.toIndex().?; | 4004 | const air_ptr_inst = store_inst.data.bin_op.lhs.toIndex().?; |
| 4044 | const store_val = (try sema.resolveValue(store_inst.data.bin_op.rhs)).?; | 4005 | const store_val = (try sema.resolveValue(store_inst.data.bin_op.rhs)).?; |
| 4045 | const new_ptr = ptr_mapping.get(air_ptr_inst).?; | 4006 | const new_ptr = ptr_mapping.get(air_ptr_inst).?; |
| 4046 | try sema.storePtrVal(block, .unneeded, Value.fromInterned(new_ptr), store_val, Type.fromInterned(zcu.intern_pool.typeOf(store_val.toIntern()))); | 4007 | try sema.storePtrVal(block, LazySrcLoc.unneeded, Value.fromInterned(new_ptr), store_val, Type.fromInterned(zcu.intern_pool.typeOf(store_val.toIntern()))); |
| 4047 | }, | 4008 | }, |
| 4048 | else => unreachable, | 4009 | else => unreachable, |
| 4049 | } | 4010 | } |
| 4050 | } | 4011 | } |
| 4051 | | 4012 | |
| 4052 | // The value is finalized - load it! | 4013 | // The value is finalized - load it! |
| 4053 | const val = (try sema.pointerDeref(block, .unneeded, Value.fromInterned(alloc_ptr), alloc_ty)).?.toIntern(); | 4014 | const val = (try sema.pointerDeref(block, LazySrcLoc.unneeded, Value.fromInterned(alloc_ptr), alloc_ty)).?.toIntern(); |
| 4054 | return sema.finishResolveComptimeKnownAllocPtr(block, alloc_ty, val, ct_alloc, alloc_inst, comptime_info.value); | 4015 | return sema.finishResolveComptimeKnownAllocPtr(block, alloc_ty, val, ct_alloc, alloc_inst, comptime_info.value); |
| 4055 | } | 4016 | } |
| 4056 | | 4017 | |
| ... | @@ -4153,7 +4114,7 @@ fn zirAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.I | ... | @@ -4153,7 +4114,7 @@ fn zirAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.I |
| 4153 | defer tracy.end(); | 4114 | defer tracy.end(); |
| 4154 | | 4115 | |
| 4155 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; | 4116 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 4156 | const ty_src: LazySrcLoc = .{ .node_offset_var_decl_ty = inst_data.src_node }; | 4117 | const ty_src = block.src(.{ .node_offset_var_decl_ty = inst_data.src_node }); |
| 4157 | const var_ty = try sema.resolveType(block, ty_src, inst_data.operand); | 4118 | const var_ty = try sema.resolveType(block, ty_src, inst_data.operand); |
| 4158 | if (block.is_comptime) { | 4119 | if (block.is_comptime) { |
| 4159 | return sema.analyzeComptimeAlloc(block, var_ty, .none); | 4120 | return sema.analyzeComptimeAlloc(block, var_ty, .none); |
| ... | @@ -4176,7 +4137,7 @@ fn zirAllocMut(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -4176,7 +4137,7 @@ fn zirAllocMut(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 4176 | defer tracy.end(); | 4137 | defer tracy.end(); |
| 4177 | | 4138 | |
| 4178 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; | 4139 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 4179 | const ty_src: LazySrcLoc = .{ .node_offset_var_decl_ty = inst_data.src_node }; | 4140 | const ty_src = block.src(.{ .node_offset_var_decl_ty = inst_data.src_node }); |
| 4180 | const var_ty = try sema.resolveType(block, ty_src, inst_data.operand); | 4141 | const var_ty = try sema.resolveType(block, ty_src, inst_data.operand); |
| 4181 | if (block.is_comptime) { | 4142 | if (block.is_comptime) { |
| 4182 | return sema.analyzeComptimeAlloc(block, var_ty, .none); | 4143 | return sema.analyzeComptimeAlloc(block, var_ty, .none); |
| ... | @@ -4236,7 +4197,7 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com | ... | @@ -4236,7 +4197,7 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com |
| 4236 | const gpa = sema.gpa; | 4197 | const gpa = sema.gpa; |
| 4237 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; | 4198 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 4238 | const src = block.nodeOffset(inst_data.src_node); | 4199 | const src = block.nodeOffset(inst_data.src_node); |
| 4239 | const ty_src: LazySrcLoc = .{ .node_offset_var_decl_ty = inst_data.src_node }; | 4200 | const ty_src = block.src(.{ .node_offset_var_decl_ty = inst_data.src_node }); |
| 4240 | const ptr = try sema.resolveInst(inst_data.operand); | 4201 | const ptr = try sema.resolveInst(inst_data.operand); |
| 4241 | const ptr_inst = ptr.toIndex().?; | 4202 | const ptr_inst = ptr.toIndex().?; |
| 4242 | const target = mod.getTarget(); | 4203 | const target = mod.getTarget(); |
| ... | @@ -4399,20 +4360,20 @@ fn zirForLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. | ... | @@ -4399,20 +4360,20 @@ fn zirForLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. |
| 4399 | .Int, .ComptimeInt => true, | 4360 | .Int, .ComptimeInt => true, |
| 4400 | else => false, | 4361 | else => false, |
| 4401 | }; | 4362 | }; |
| 4402 | const arg_src: LazySrcLoc = .{ .for_input = .{ | 4363 | const arg_src = block.src(.{ .for_input = .{ |
| 4403 | .for_node_offset = inst_data.src_node, | 4364 | .for_node_offset = inst_data.src_node, |
| 4404 | .input_index = i, | 4365 | .input_index = i, |
| 4405 | } }; | 4366 | } }); |
| 4406 | const arg_len_uncoerced = if (is_int) object else l: { | 4367 | const arg_len_uncoerced = if (is_int) object else l: { |
| 4407 | if (!object_ty.isIndexable(mod)) { | 4368 | if (!object_ty.isIndexable(mod)) { |
| 4408 | // Instead of using checkIndexable we customize this error. | 4369 | // Instead of using checkIndexable we customize this error. |
| 4409 | const msg = msg: { | 4370 | const msg = msg: { |
| 4410 | const msg = try sema.errMsg(block, arg_src, "type '{}' is not indexable and not a range", .{object_ty.fmt(sema.mod)}); | 4371 | const msg = try sema.errMsg(arg_src, "type '{}' is not indexable and not a range", .{object_ty.fmt(sema.mod)}); |
| 4411 | errdefer msg.destroy(sema.gpa); | 4372 | errdefer msg.destroy(sema.gpa); |
| 4412 | try sema.errNote(block, arg_src, msg, "for loop operand must be a range, array, slice, tuple, or vector", .{}); | 4373 | try sema.errNote(arg_src, msg, "for loop operand must be a range, array, slice, tuple, or vector", .{}); |
| 4413 | | 4374 | |
| 4414 | if (object_ty.zigTypeTag(mod) == .ErrorUnion) { | 4375 | if (object_ty.zigTypeTag(mod) == .ErrorUnion) { |
| 4415 | try sema.errNote(block, arg_src, msg, "consider using 'try', 'catch', or 'if'", .{}); | 4376 | try sema.errNote(arg_src, msg, "consider using 'try', 'catch', or 'if'", .{}); |
| 4416 | } | 4377 | } |
| 4417 | | 4378 | |
| 4418 | break :msg msg; | 4379 | break :msg msg; |
| ... | @@ -4432,16 +4393,16 @@ fn zirForLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. | ... | @@ -4432,16 +4393,16 @@ fn zirForLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. |
| 4432 | if (len_val) |v| { | 4393 | if (len_val) |v| { |
| 4433 | if (!(try sema.valuesEqual(arg_val, v, Type.usize))) { | 4394 | if (!(try sema.valuesEqual(arg_val, v, Type.usize))) { |
| 4434 | const msg = msg: { | 4395 | const msg = msg: { |
| 4435 | const msg = try sema.errMsg(block, src, "non-matching for loop lengths", .{}); | 4396 | const msg = try sema.errMsg(src, "non-matching for loop lengths", .{}); |
| 4436 | errdefer msg.destroy(gpa); | 4397 | errdefer msg.destroy(gpa); |
| 4437 | const a_src: LazySrcLoc = .{ .for_input = .{ | 4398 | const a_src = block.src(.{ .for_input = .{ |
| 4438 | .for_node_offset = inst_data.src_node, | 4399 | .for_node_offset = inst_data.src_node, |
| 4439 | .input_index = len_idx, | 4400 | .input_index = len_idx, |
| 4440 | } }; | 4401 | } }); |
| 4441 | try sema.errNote(block, a_src, msg, "length {} here", .{ | 4402 | try sema.errNote(a_src, msg, "length {} here", .{ |
| 4442 | v.fmtValue(sema.mod, sema), | 4403 | v.fmtValue(sema.mod, sema), |
| 4443 | }); | 4404 | }); |
| 4444 | try sema.errNote(block, arg_src, msg, "length {} here", .{ | 4405 | try sema.errNote(arg_src, msg, "length {} here", .{ |
| 4445 | arg_val.fmtValue(sema.mod, sema), | 4406 | arg_val.fmtValue(sema.mod, sema), |
| 4446 | }); | 4407 | }); |
| 4447 | break :msg msg; | 4408 | break :msg msg; |
| ... | @@ -4461,7 +4422,7 @@ fn zirForLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. | ... | @@ -4461,7 +4422,7 @@ fn zirForLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. |
| 4461 | | 4422 | |
| 4462 | if (len == .none) { | 4423 | if (len == .none) { |
| 4463 | const msg = msg: { | 4424 | const msg = msg: { |
| 4464 | const msg = try sema.errMsg(block, src, "unbounded for loop", .{}); | 4425 | const msg = try sema.errMsg(src, "unbounded for loop", .{}); |
| 4465 | errdefer msg.destroy(gpa); | 4426 | errdefer msg.destroy(gpa); |
| 4466 | for (args, 0..) |zir_arg, i_usize| { | 4427 | for (args, 0..) |zir_arg, i_usize| { |
| 4467 | const i: u32 = @intCast(i_usize); | 4428 | const i: u32 = @intCast(i_usize); |
| ... | @@ -4474,11 +4435,11 @@ fn zirForLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. | ... | @@ -4474,11 +4435,11 @@ fn zirForLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. |
| 4474 | .Int, .ComptimeInt => continue, | 4435 | .Int, .ComptimeInt => continue, |
| 4475 | else => {}, | 4436 | else => {}, |
| 4476 | } | 4437 | } |
| 4477 | const arg_src: LazySrcLoc = .{ .for_input = .{ | 4438 | const arg_src = block.src(.{ .for_input = .{ |
| 4478 | .for_node_offset = inst_data.src_node, | 4439 | .for_node_offset = inst_data.src_node, |
| 4479 | .input_index = i, | 4440 | .input_index = i, |
| 4480 | } }; | 4441 | } }); |
| 4481 | try sema.errNote(block, arg_src, msg, "type '{}' has no upper bound", .{ | 4442 | try sema.errNote(arg_src, msg, "type '{}' has no upper bound", .{ |
| 4482 | object_ty.fmt(sema.mod), | 4443 | object_ty.fmt(sema.mod), |
| 4483 | }); | 4444 | }); |
| 4484 | } | 4445 | } |
| ... | @@ -4528,7 +4489,7 @@ fn zirCoercePtrElemTy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE | ... | @@ -4528,7 +4489,7 @@ fn zirCoercePtrElemTy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE |
| 4528 | const src = block.nodeOffset(pl_node.src_node); | 4489 | const src = block.nodeOffset(pl_node.src_node); |
| 4529 | const extra = sema.code.extraData(Zir.Inst.Bin, pl_node.payload_index).data; | 4490 | const extra = sema.code.extraData(Zir.Inst.Bin, pl_node.payload_index).data; |
| 4530 | const uncoerced_val = try sema.resolveInst(extra.rhs); | 4491 | const uncoerced_val = try sema.resolveInst(extra.rhs); |
| 4531 | const maybe_wrapped_ptr_ty = sema.resolveType(block, .unneeded, extra.lhs) catch |err| switch (err) { | 4492 | const maybe_wrapped_ptr_ty = sema.resolveType(block, LazySrcLoc.unneeded, extra.lhs) catch |err| switch (err) { |
| 4532 | error.GenericPoison => return uncoerced_val, | 4493 | error.GenericPoison => return uncoerced_val, |
| 4533 | else => |e| return e, | 4494 | else => |e| return e, |
| 4534 | }; | 4495 | }; |
| ... | @@ -4590,9 +4551,9 @@ fn zirValidateRefTy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr | ... | @@ -4590,9 +4551,9 @@ fn zirValidateRefTy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr |
| 4590 | if (ty_operand.isGenericPoison()) return; | 4551 | if (ty_operand.isGenericPoison()) return; |
| 4591 | if (ty_operand.optEuBaseType(mod).zigTypeTag(mod) != .Pointer) { | 4552 | if (ty_operand.optEuBaseType(mod).zigTypeTag(mod) != .Pointer) { |
| 4592 | return sema.failWithOwnedErrorMsg(block, msg: { | 4553 | return sema.failWithOwnedErrorMsg(block, msg: { |
| 4593 | const msg = try sema.errMsg(block, src, "expected type '{}', found pointer", .{ty_operand.fmt(mod)}); | 4554 | const msg = try sema.errMsg(src, "expected type '{}', found pointer", .{ty_operand.fmt(mod)}); |
| 4594 | errdefer msg.destroy(sema.gpa); | 4555 | errdefer msg.destroy(sema.gpa); |
| 4595 | try sema.errNote(block, src, msg, "address-of operator always returns a pointer", .{}); | 4556 | try sema.errNote(src, msg, "address-of operator always returns a pointer", .{}); |
| 4596 | break :msg msg; | 4557 | break :msg msg; |
| 4597 | }); | 4558 | }); |
| 4598 | } | 4559 | } |
| ... | @@ -4607,7 +4568,7 @@ fn zirValidateArrayInitRefTy( | ... | @@ -4607,7 +4568,7 @@ fn zirValidateArrayInitRefTy( |
| 4607 | const pl_node = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 4568 | const pl_node = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 4608 | const src = block.nodeOffset(pl_node.src_node); | 4569 | const src = block.nodeOffset(pl_node.src_node); |
| 4609 | const extra = sema.code.extraData(Zir.Inst.ArrayInitRefTy, pl_node.payload_index).data; | 4570 | const extra = sema.code.extraData(Zir.Inst.ArrayInitRefTy, pl_node.payload_index).data; |
| 4610 | const maybe_wrapped_ptr_ty = sema.resolveType(block, .unneeded, extra.ptr_ty) catch |err| switch (err) { | 4571 | const maybe_wrapped_ptr_ty = sema.resolveType(block, LazySrcLoc.unneeded, extra.ptr_ty) catch |err| switch (err) { |
| 4611 | error.GenericPoison => return .generic_poison_type, | 4572 | error.GenericPoison => return .generic_poison_type, |
| 4612 | else => |e| return e, | 4573 | else => |e| return e, |
| 4613 | }; | 4574 | }; |
| ... | @@ -4648,7 +4609,7 @@ fn zirValidateArrayInitTy( | ... | @@ -4648,7 +4609,7 @@ fn zirValidateArrayInitTy( |
| 4648 | const mod = sema.mod; | 4609 | const mod = sema.mod; |
| 4649 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 4610 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 4650 | const src = block.nodeOffset(inst_data.src_node); | 4611 | const src = block.nodeOffset(inst_data.src_node); |
| 4651 | const ty_src: LazySrcLoc = if (is_result_ty) src else .{ .node_offset_init_ty = inst_data.src_node }; | 4612 | const ty_src: LazySrcLoc = if (is_result_ty) src else block.src(.{ .node_offset_init_ty = inst_data.src_node }); |
| 4652 | const extra = sema.code.extraData(Zir.Inst.ArrayInit, inst_data.payload_index).data; | 4613 | const extra = sema.code.extraData(Zir.Inst.ArrayInit, inst_data.payload_index).data; |
| 4653 | const ty = sema.resolveType(block, ty_src, extra.ty) catch |err| switch (err) { | 4614 | const ty = sema.resolveType(block, ty_src, extra.ty) catch |err| switch (err) { |
| 4654 | // It's okay for the type to be unknown: this will result in an anonymous array init. | 4615 | // It's okay for the type to be unknown: this will result in an anonymous array init. |
| ... | @@ -4774,7 +4735,6 @@ fn validateUnionInit( | ... | @@ -4774,7 +4735,6 @@ fn validateUnionInit( |
| 4774 | if (instrs.len != 1) { | 4735 | if (instrs.len != 1) { |
| 4775 | const msg = msg: { | 4736 | const msg = msg: { |
| 4776 | const msg = try sema.errMsg( | 4737 | const msg = try sema.errMsg( |
| 4777 | block, | | |
| 4778 | init_src, | 4738 | init_src, |
| 4779 | "cannot initialize multiple union fields at once; unions can only have one active field", | 4739 | "cannot initialize multiple union fields at once; unions can only have one active field", |
| 4780 | .{}, | 4740 | .{}, |
| ... | @@ -4783,8 +4743,8 @@ fn validateUnionInit( | ... | @@ -4783,8 +4743,8 @@ fn validateUnionInit( |
| 4783 | | 4743 | |
| 4784 | for (instrs[1..]) |inst| { | 4744 | for (instrs[1..]) |inst| { |
| 4785 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 4745 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 4786 | const inst_src: LazySrcLoc = .{ .node_offset_initializer = inst_data.src_node }; | 4746 | const inst_src = block.src(.{ .node_offset_initializer = inst_data.src_node }); |
| 4787 | try sema.errNote(block, inst_src, msg, "additional initializer here", .{}); | 4747 | try sema.errNote(inst_src, msg, "additional initializer here", .{}); |
| 4788 | } | 4748 | } |
| 4789 | try sema.addDeclaredHereNote(msg, union_ty); | 4749 | try sema.addDeclaredHereNote(msg, union_ty); |
| 4790 | break :msg msg; | 4750 | break :msg msg; |
| ... | @@ -4801,7 +4761,7 @@ fn validateUnionInit( | ... | @@ -4801,7 +4761,7 @@ fn validateUnionInit( |
| 4801 | | 4761 | |
| 4802 | const field_ptr = instrs[0]; | 4762 | const field_ptr = instrs[0]; |
| 4803 | const field_ptr_data = sema.code.instructions.items(.data)[@intFromEnum(field_ptr)].pl_node; | 4763 | const field_ptr_data = sema.code.instructions.items(.data)[@intFromEnum(field_ptr)].pl_node; |
| 4804 | const field_src: LazySrcLoc = .{ .node_offset_initializer = field_ptr_data.src_node }; | 4764 | const field_src = block.src(.{ .node_offset_initializer = field_ptr_data.src_node }); |
| 4805 | const field_ptr_extra = sema.code.extraData(Zir.Inst.Field, field_ptr_data.payload_index).data; | 4765 | const field_ptr_extra = sema.code.extraData(Zir.Inst.Field, field_ptr_data.payload_index).data; |
| 4806 | const field_name = try mod.intern_pool.getOrPutString( | 4766 | const field_name = try mod.intern_pool.getOrPutString( |
| 4807 | gpa, | 4767 | gpa, |
| ... | @@ -4918,7 +4878,7 @@ fn validateUnionInit( | ... | @@ -4918,7 +4878,7 @@ fn validateUnionInit( |
| 4918 | | 4878 | |
| 4919 | const new_tag = Air.internedToRef(tag_val.toIntern()); | 4879 | const new_tag = Air.internedToRef(tag_val.toIntern()); |
| 4920 | const set_tag_inst = try block.addBinOp(.set_union_tag, union_ptr, new_tag); | 4880 | const set_tag_inst = try block.addBinOp(.set_union_tag, union_ptr, new_tag); |
| 4921 | try sema.checkComptimeKnownStore(block, set_tag_inst, .unneeded); // `unneeded` since this isn't a "proper" store | 4881 | try sema.checkComptimeKnownStore(block, set_tag_inst, LazySrcLoc.unneeded); // `unneeded` since this isn't a "proper" store |
| 4922 | } | 4882 | } |
| 4923 | | 4883 | |
| 4924 | fn validateStructInit( | 4884 | fn validateStructInit( |
| ... | @@ -4944,7 +4904,7 @@ fn validateStructInit( | ... | @@ -4944,7 +4904,7 @@ fn validateStructInit( |
| 4944 | | 4904 | |
| 4945 | for (instrs, field_indices) |field_ptr, *field_index| { | 4905 | for (instrs, field_indices) |field_ptr, *field_index| { |
| 4946 | const field_ptr_data = sema.code.instructions.items(.data)[@intFromEnum(field_ptr)].pl_node; | 4906 | const field_ptr_data = sema.code.instructions.items(.data)[@intFromEnum(field_ptr)].pl_node; |
| 4947 | const field_src: LazySrcLoc = .{ .node_offset_initializer = field_ptr_data.src_node }; | 4907 | const field_src = block.src(.{ .node_offset_initializer = field_ptr_data.src_node }); |
| 4948 | const field_ptr_extra = sema.code.extraData(Zir.Inst.Field, field_ptr_data.payload_index).data; | 4908 | const field_ptr_extra = sema.code.extraData(Zir.Inst.Field, field_ptr_data.payload_index).data; |
| 4949 | struct_ptr_zir_ref = field_ptr_extra.lhs; | 4909 | struct_ptr_zir_ref = field_ptr_extra.lhs; |
| 4950 | const field_name = try ip.getOrPutString( | 4910 | const field_name = try ip.getOrPutString( |
| ... | @@ -4981,18 +4941,18 @@ fn validateStructInit( | ... | @@ -4981,18 +4941,18 @@ fn validateStructInit( |
| 4981 | const field_name = struct_ty.structFieldName(i, mod).unwrap() orelse { | 4941 | const field_name = struct_ty.structFieldName(i, mod).unwrap() orelse { |
| 4982 | const template = "missing tuple field with index {d}"; | 4942 | const template = "missing tuple field with index {d}"; |
| 4983 | if (root_msg) |msg| { | 4943 | if (root_msg) |msg| { |
| 4984 | try sema.errNote(block, init_src, msg, template, .{i}); | 4944 | try sema.errNote(init_src, msg, template, .{i}); |
| 4985 | } else { | 4945 | } else { |
| 4986 | root_msg = try sema.errMsg(block, init_src, template, .{i}); | 4946 | root_msg = try sema.errMsg(init_src, template, .{i}); |
| 4987 | } | 4947 | } |
| 4988 | continue; | 4948 | continue; |
| 4989 | }; | 4949 | }; |
| 4990 | const template = "missing struct field: {}"; | 4950 | const template = "missing struct field: {}"; |
| 4991 | const args = .{field_name.fmt(ip)}; | 4951 | const args = .{field_name.fmt(ip)}; |
| 4992 | if (root_msg) |msg| { | 4952 | if (root_msg) |msg| { |
| 4993 | try sema.errNote(block, init_src, msg, template, args); | 4953 | try sema.errNote(init_src, msg, template, args); |
| 4994 | } else { | 4954 | } else { |
| 4995 | root_msg = try sema.errMsg(block, init_src, template, args); | 4955 | root_msg = try sema.errMsg(init_src, template, args); |
| 4996 | } | 4956 | } |
| 4997 | continue; | 4957 | continue; |
| 4998 | } | 4958 | } |
| ... | @@ -5007,16 +4967,7 @@ fn validateStructInit( | ... | @@ -5007,16 +4967,7 @@ fn validateStructInit( |
| 5007 | } | 4967 | } |
| 5008 | | 4968 | |
| 5009 | if (root_msg) |msg| { | 4969 | if (root_msg) |msg| { |
| 5010 | if (mod.typeToStruct(struct_ty)) |struct_type| { | 4970 | try sema.addDeclaredHereNote(msg, struct_ty); |
| 5011 | const decl = mod.declPtr(struct_type.decl.unwrap().?); | | |
| 5012 | const fqn = try decl.fullyQualifiedName(mod); | | |
| 5013 | try mod.errNoteNonLazy( | | |
| 5014 | decl.srcLoc(mod), | | |
| 5015 | msg, | | |
| 5016 | "struct '{}' declared here", | | |
| 5017 | .{fqn.fmt(ip)}, | | |
| 5018 | ); | | |
| 5019 | } | | |
| 5020 | root_msg = null; | 4971 | root_msg = null; |
| 5021 | return sema.failWithOwnedErrorMsg(block, msg); | 4972 | return sema.failWithOwnedErrorMsg(block, msg); |
| 5022 | } | 4973 | } |
| ... | @@ -5118,18 +5069,18 @@ fn validateStructInit( | ... | @@ -5118,18 +5069,18 @@ fn validateStructInit( |
| 5118 | const field_name = struct_ty.structFieldName(i, mod).unwrap() orelse { | 5069 | const field_name = struct_ty.structFieldName(i, mod).unwrap() orelse { |
| 5119 | const template = "missing tuple field with index {d}"; | 5070 | const template = "missing tuple field with index {d}"; |
| 5120 | if (root_msg) |msg| { | 5071 | if (root_msg) |msg| { |
| 5121 | try sema.errNote(block, init_src, msg, template, .{i}); | 5072 | try sema.errNote(init_src, msg, template, .{i}); |
| 5122 | } else { | 5073 | } else { |
| 5123 | root_msg = try sema.errMsg(block, init_src, template, .{i}); | 5074 | root_msg = try sema.errMsg(init_src, template, .{i}); |
| 5124 | } | 5075 | } |
| 5125 | continue; | 5076 | continue; |
| 5126 | }; | 5077 | }; |
| 5127 | const template = "missing struct field: {}"; | 5078 | const template = "missing struct field: {}"; |
| 5128 | const args = .{field_name.fmt(ip)}; | 5079 | const args = .{field_name.fmt(ip)}; |
| 5129 | if (root_msg) |msg| { | 5080 | if (root_msg) |msg| { |
| 5130 | try sema.errNote(block, init_src, msg, template, args); | 5081 | try sema.errNote(init_src, msg, template, args); |
| 5131 | } else { | 5082 | } else { |
| 5132 | root_msg = try sema.errMsg(block, init_src, template, args); | 5083 | root_msg = try sema.errMsg(init_src, template, args); |
| 5133 | } | 5084 | } |
| 5134 | continue; | 5085 | continue; |
| 5135 | } | 5086 | } |
| ... | @@ -5137,21 +5088,12 @@ fn validateStructInit( | ... | @@ -5137,21 +5088,12 @@ fn validateStructInit( |
| 5137 | } | 5088 | } |
| 5138 | | 5089 | |
| 5139 | if (!struct_is_comptime and !fields_allow_runtime and root_msg == null) { | 5090 | if (!struct_is_comptime and !fields_allow_runtime and root_msg == null) { |
| 5140 | root_msg = try sema.errMsg(block, init_src, "runtime value contains reference to comptime var", .{}); | 5091 | root_msg = try sema.errMsg(init_src, "runtime value contains reference to comptime var", .{}); |
| 5141 | try sema.errNote(block, init_src, root_msg.?, "comptime var pointers are not available at runtime", .{}); | 5092 | try sema.errNote(init_src, root_msg.?, "comptime var pointers are not available at runtime", .{}); |
| 5142 | } | 5093 | } |
| 5143 | | 5094 | |
| 5144 | if (root_msg) |msg| { | 5095 | if (root_msg) |msg| { |
| 5145 | if (mod.typeToStruct(struct_ty)) |struct_type| { | 5096 | try sema.addDeclaredHereNote(msg, struct_ty); |
| 5146 | const decl = mod.declPtr(struct_type.decl.unwrap().?); | | |
| 5147 | const fqn = try decl.fullyQualifiedName(mod); | | |
| 5148 | try mod.errNoteNonLazy( | | |
| 5149 | decl.srcLoc(mod), | | |
| 5150 | msg, | | |
| 5151 | "struct '{}' declared here", | | |
| 5152 | .{fqn.fmt(ip)}, | | |
| 5153 | ); | | |
| 5154 | } | | |
| 5155 | root_msg = null; | 5097 | root_msg = null; |
| 5156 | return sema.failWithOwnedErrorMsg(block, msg); | 5098 | return sema.failWithOwnedErrorMsg(block, msg); |
| 5157 | } | 5099 | } |
| ... | @@ -5253,9 +5195,9 @@ fn zirValidatePtrArrayInit( | ... | @@ -5253,9 +5195,9 @@ fn zirValidatePtrArrayInit( |
| 5253 | if (default_val == .unreachable_value) { | 5195 | if (default_val == .unreachable_value) { |
| 5254 | const template = "missing tuple field with index {d}"; | 5196 | const template = "missing tuple field with index {d}"; |
| 5255 | if (root_msg) |msg| { | 5197 | if (root_msg) |msg| { |
| 5256 | try sema.errNote(block, init_src, msg, template, .{i}); | 5198 | try sema.errNote(init_src, msg, template, .{i}); |
| 5257 | } else { | 5199 | } else { |
| 5258 | root_msg = try sema.errMsg(block, init_src, template, .{i}); | 5200 | root_msg = try sema.errMsg(init_src, template, .{i}); |
| 5259 | } | 5201 | } |
| 5260 | continue; | 5202 | continue; |
| 5261 | } | 5203 | } |
| ... | @@ -5455,15 +5397,13 @@ fn zirValidateDeref(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr | ... | @@ -5455,15 +5397,13 @@ fn zirValidateDeref(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr |
| 5455 | } else if (try sema.typeRequiresComptime(elem_ty)) { | 5397 | } else if (try sema.typeRequiresComptime(elem_ty)) { |
| 5456 | const msg = msg: { | 5398 | const msg = msg: { |
| 5457 | const msg = try sema.errMsg( | 5399 | const msg = try sema.errMsg( |
| 5458 | block, | | |
| 5459 | src, | 5400 | src, |
| 5460 | "values of type '{}' must be comptime-known, but operand value is runtime-known", | 5401 | "values of type '{}' must be comptime-known, but operand value is runtime-known", |
| 5461 | .{elem_ty.fmt(mod)}, | 5402 | .{elem_ty.fmt(mod)}, |
| 5462 | ); | 5403 | ); |
| 5463 | errdefer msg.destroy(sema.gpa); | 5404 | errdefer msg.destroy(sema.gpa); |
| 5464 | | 5405 | |
| 5465 | const src_decl = mod.declPtr(block.src_decl); | 5406 | try sema.explainWhyTypeIsComptime(msg, src, elem_ty); |
| 5466 | try sema.explainWhyTypeIsComptime(msg, src_decl.toSrcLoc(src, mod), elem_ty); | | |
| 5467 | break :msg msg; | 5407 | break :msg msg; |
| 5468 | }; | 5408 | }; |
| 5469 | return sema.failWithOwnedErrorMsg(block, msg); | 5409 | return sema.failWithOwnedErrorMsg(block, msg); |
| ... | @@ -5475,7 +5415,7 @@ fn zirValidateDestructure(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp | ... | @@ -5475,7 +5415,7 @@ fn zirValidateDestructure(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp |
| 5475 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 5415 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 5476 | const extra = sema.code.extraData(Zir.Inst.ValidateDestructure, inst_data.payload_index).data; | 5416 | const extra = sema.code.extraData(Zir.Inst.ValidateDestructure, inst_data.payload_index).data; |
| 5477 | const src = block.nodeOffset(inst_data.src_node); | 5417 | const src = block.nodeOffset(inst_data.src_node); |
| 5478 | const destructure_src = LazySrcLoc.nodeOffset(extra.destructure_node); | 5418 | const destructure_src = block.nodeOffset(extra.destructure_node); |
| 5479 | const operand = try sema.resolveInst(extra.operand); | 5419 | const operand = try sema.resolveInst(extra.operand); |
| 5480 | const operand_ty = sema.typeOf(operand); | 5420 | const operand_ty = sema.typeOf(operand); |
| 5481 | | 5421 | |
| ... | @@ -5487,21 +5427,21 @@ fn zirValidateDestructure(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp | ... | @@ -5487,21 +5427,21 @@ fn zirValidateDestructure(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp |
| 5487 | | 5427 | |
| 5488 | if (!can_destructure) { | 5428 | if (!can_destructure) { |
| 5489 | return sema.failWithOwnedErrorMsg(block, msg: { | 5429 | return sema.failWithOwnedErrorMsg(block, msg: { |
| 5490 | const msg = try sema.errMsg(block, src, "type '{}' cannot be destructured", .{operand_ty.fmt(mod)}); | 5430 | const msg = try sema.errMsg(src, "type '{}' cannot be destructured", .{operand_ty.fmt(mod)}); |
| 5491 | errdefer msg.destroy(sema.gpa); | 5431 | errdefer msg.destroy(sema.gpa); |
| 5492 | try sema.errNote(block, destructure_src, msg, "result destructured here", .{}); | 5432 | try sema.errNote(destructure_src, msg, "result destructured here", .{}); |
| 5493 | break :msg msg; | 5433 | break :msg msg; |
| 5494 | }); | 5434 | }); |
| 5495 | } | 5435 | } |
| 5496 | | 5436 | |
| 5497 | if (operand_ty.arrayLen(mod) != extra.expect_len) { | 5437 | if (operand_ty.arrayLen(mod) != extra.expect_len) { |
| 5498 | return sema.failWithOwnedErrorMsg(block, msg: { | 5438 | return sema.failWithOwnedErrorMsg(block, msg: { |
| 5499 | const msg = try sema.errMsg(block, src, "expected {} elements for destructure, found {}", .{ | 5439 | const msg = try sema.errMsg(src, "expected {} elements for destructure, found {}", .{ |
| 5500 | extra.expect_len, | 5440 | extra.expect_len, |
| 5501 | operand_ty.arrayLen(mod), | 5441 | operand_ty.arrayLen(mod), |
| 5502 | }); | 5442 | }); |
| 5503 | errdefer msg.destroy(sema.gpa); | 5443 | errdefer msg.destroy(sema.gpa); |
| 5504 | try sema.errNote(block, destructure_src, msg, "result destructured here", .{}); | 5444 | try sema.errNote(destructure_src, msg, "result destructured here", .{}); |
| 5505 | break :msg msg; | 5445 | break :msg msg; |
| 5506 | }); | 5446 | }); |
| 5507 | } | 5447 | } |
| ... | @@ -5536,24 +5476,24 @@ fn failWithBadMemberAccess( | ... | @@ -5536,24 +5476,24 @@ fn failWithBadMemberAccess( |
| 5536 | fn failWithBadStructFieldAccess( | 5476 | fn failWithBadStructFieldAccess( |
| 5537 | sema: *Sema, | 5477 | sema: *Sema, |
| 5538 | block: *Block, | 5478 | block: *Block, |
| | 5479 | struct_ty: Type, |
| 5539 | struct_type: InternPool.LoadedStructType, | 5480 | struct_type: InternPool.LoadedStructType, |
| 5540 | field_src: LazySrcLoc, | 5481 | field_src: LazySrcLoc, |
| 5541 | field_name: InternPool.NullTerminatedString, | 5482 | field_name: InternPool.NullTerminatedString, |
| 5542 | ) CompileError { | 5483 | ) CompileError { |
| 5543 | const mod = sema.mod; | 5484 | const zcu = sema.mod; |
| 5544 | const gpa = sema.gpa; | 5485 | const gpa = sema.gpa; |
| 5545 | const decl = mod.declPtr(struct_type.decl.unwrap().?); | 5486 | const decl = zcu.declPtr(struct_type.decl.unwrap().?); |
| 5546 | const fqn = try decl.fullyQualifiedName(mod); | 5487 | const fqn = try decl.fullyQualifiedName(zcu); |
| 5547 | | 5488 | |
| 5548 | const msg = msg: { | 5489 | const msg = msg: { |
| 5549 | const msg = try sema.errMsg( | 5490 | const msg = try sema.errMsg( |
| 5550 | block, | | |
| 5551 | field_src, | 5491 | field_src, |
| 5552 | "no field named '{}' in struct '{}'", | 5492 | "no field named '{}' in struct '{}'", |
| 5553 | .{ field_name.fmt(&mod.intern_pool), fqn.fmt(&mod.intern_pool) }, | 5493 | .{ field_name.fmt(&zcu.intern_pool), fqn.fmt(&zcu.intern_pool) }, |
| 5554 | ); | 5494 | ); |
| 5555 | errdefer msg.destroy(gpa); | 5495 | errdefer msg.destroy(gpa); |
| 5556 | try mod.errNoteNonLazy(decl.srcLoc(mod), msg, "struct declared here", .{}); | 5496 | try sema.errNote(struct_ty.srcLoc(zcu), msg, "struct declared here", .{}); |
| 5557 | break :msg msg; | 5497 | break :msg msg; |
| 5558 | }; | 5498 | }; |
| 5559 | return sema.failWithOwnedErrorMsg(block, msg); | 5499 | return sema.failWithOwnedErrorMsg(block, msg); |
| ... | @@ -5562,25 +5502,25 @@ fn failWithBadStructFieldAccess( | ... | @@ -5562,25 +5502,25 @@ fn failWithBadStructFieldAccess( |
| 5562 | fn failWithBadUnionFieldAccess( | 5502 | fn failWithBadUnionFieldAccess( |
| 5563 | sema: *Sema, | 5503 | sema: *Sema, |
| 5564 | block: *Block, | 5504 | block: *Block, |
| | 5505 | union_ty: Type, |
| 5565 | union_obj: InternPool.LoadedUnionType, | 5506 | union_obj: InternPool.LoadedUnionType, |
| 5566 | field_src: LazySrcLoc, | 5507 | field_src: LazySrcLoc, |
| 5567 | field_name: InternPool.NullTerminatedString, | 5508 | field_name: InternPool.NullTerminatedString, |
| 5568 | ) CompileError { | 5509 | ) CompileError { |
| 5569 | const mod = sema.mod; | 5510 | const zcu = sema.mod; |
| 5570 | const gpa = sema.gpa; | 5511 | const gpa = sema.gpa; |
| 5571 | | 5512 | |
| 5572 | const decl = mod.declPtr(union_obj.decl); | 5513 | const decl = zcu.declPtr(union_obj.decl); |
| 5573 | const fqn = try decl.fullyQualifiedName(mod); | 5514 | const fqn = try decl.fullyQualifiedName(zcu); |
| 5574 | | 5515 | |
| 5575 | const msg = msg: { | 5516 | const msg = msg: { |
| 5576 | const msg = try sema.errMsg( | 5517 | const msg = try sema.errMsg( |
| 5577 | block, | | |
| 5578 | field_src, | 5518 | field_src, |
| 5579 | "no field named '{}' in union '{}'", | 5519 | "no field named '{}' in union '{}'", |
| 5580 | .{ field_name.fmt(&mod.intern_pool), fqn.fmt(&mod.intern_pool) }, | 5520 | .{ field_name.fmt(&zcu.intern_pool), fqn.fmt(&zcu.intern_pool) }, |
| 5581 | ); | 5521 | ); |
| 5582 | errdefer msg.destroy(gpa); | 5522 | errdefer msg.destroy(gpa); |
| 5583 | try mod.errNoteNonLazy(decl.srcLoc(mod), msg, "union declared here", .{}); | 5523 | try sema.errNote(union_ty.srcLoc(zcu), msg, "union declared here", .{}); |
| 5584 | break :msg msg; | 5524 | break :msg msg; |
| 5585 | }; | 5525 | }; |
| 5586 | return sema.failWithOwnedErrorMsg(block, msg); | 5526 | return sema.failWithOwnedErrorMsg(block, msg); |
| ... | @@ -5588,16 +5528,15 @@ fn failWithBadUnionFieldAccess( | ... | @@ -5588,16 +5528,15 @@ fn failWithBadUnionFieldAccess( |
| 5588 | | 5528 | |
| 5589 | fn addDeclaredHereNote(sema: *Sema, parent: *Module.ErrorMsg, decl_ty: Type) !void { | 5529 | fn addDeclaredHereNote(sema: *Sema, parent: *Module.ErrorMsg, decl_ty: Type) !void { |
| 5590 | const mod = sema.mod; | 5530 | const mod = sema.mod; |
| 5591 | const src_loc = decl_ty.declSrcLocOrNull(mod) orelse return; | 5531 | const src_loc = decl_ty.srcLocOrNull(mod) orelse return; |
| 5592 | const category = switch (decl_ty.zigTypeTag(mod)) { | 5532 | const category = switch (decl_ty.zigTypeTag(mod)) { |
| 5593 | .Union => "union", | 5533 | .Union => "union", |
| 5594 | .Struct => "struct", | 5534 | .Struct => "struct", |
| 5595 | .Enum => "enum", | 5535 | .Enum => "enum", |
| 5596 | .Opaque => "opaque", | 5536 | .Opaque => "opaque", |
| 5597 | .ErrorSet => "error set", | | |
| 5598 | else => unreachable, | 5537 | else => unreachable, |
| 5599 | }; | 5538 | }; |
| 5600 | try mod.errNoteNonLazy(src_loc, parent, "{s} declared here", .{category}); | 5539 | try sema.errNote(src_loc, parent, "{s} declared here", .{category}); |
| 5601 | } | 5540 | } |
| 5602 | | 5541 | |
| 5603 | fn zirStoreToInferredPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void { | 5542 | fn zirStoreToInferredPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void { |
| ... | @@ -5722,8 +5661,8 @@ fn zirStoreNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!v | ... | @@ -5722,8 +5661,8 @@ fn zirStoreNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!v |
| 5722 | else => {}, | 5661 | else => {}, |
| 5723 | }; | 5662 | }; |
| 5724 | | 5663 | |
| 5725 | const ptr_src: LazySrcLoc = .{ .node_offset_store_ptr = inst_data.src_node }; | 5664 | const ptr_src = block.src(.{ .node_offset_store_ptr = inst_data.src_node }); |
| 5726 | const operand_src: LazySrcLoc = .{ .node_offset_store_operand = inst_data.src_node }; | 5665 | const operand_src = block.src(.{ .node_offset_store_operand = inst_data.src_node }); |
| 5727 | const air_tag: Air.Inst.Tag = if (is_ret) | 5666 | const air_tag: Air.Inst.Tag = if (is_ret) |
| 5728 | .ret_ptr | 5667 | .ret_ptr |
| 5729 | else if (block.wantSafety()) | 5668 | else if (block.wantSafety()) |
| ... | @@ -5837,7 +5776,7 @@ fn zirCompileError(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro | ... | @@ -5837,7 +5776,7 @@ fn zirCompileError(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro |
| 5837 | | 5776 | |
| 5838 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; | 5777 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 5839 | const src = block.nodeOffset(inst_data.src_node); | 5778 | const src = block.nodeOffset(inst_data.src_node); |
| 5840 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 5779 | const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0); |
| 5841 | const msg = try sema.resolveConstString(block, operand_src, inst_data.operand, .{ | 5780 | const msg = try sema.resolveConstString(block, operand_src, inst_data.operand, .{ |
| 5842 | .needed_comptime_reason = "compile error string must be comptime-known", | 5781 | .needed_comptime_reason = "compile error string must be comptime-known", |
| 5843 | }); | 5782 | }); |
| ... | @@ -5846,6 +5785,7 @@ fn zirCompileError(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro | ... | @@ -5846,6 +5785,7 @@ fn zirCompileError(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro |
| 5846 | | 5785 | |
| 5847 | fn zirCompileLog( | 5786 | fn zirCompileLog( |
| 5848 | sema: *Sema, | 5787 | sema: *Sema, |
| | 5788 | block: *Block, |
| 5849 | extended: Zir.Inst.Extended.InstData, | 5789 | extended: Zir.Inst.Extended.InstData, |
| 5850 | ) CompileError!Air.Inst.Ref { | 5790 | ) CompileError!Air.Inst.Ref { |
| 5851 | const mod = sema.mod; | 5791 | const mod = sema.mod; |
| ... | @@ -5878,9 +5818,10 @@ fn zirCompileLog( | ... | @@ -5878,9 +5818,10 @@ fn zirCompileLog( |
| 5878 | else | 5818 | else |
| 5879 | sema.owner_decl_index; | 5819 | sema.owner_decl_index; |
| 5880 | const gop = try mod.compile_log_decls.getOrPut(sema.gpa, decl_index); | 5820 | const gop = try mod.compile_log_decls.getOrPut(sema.gpa, decl_index); |
| 5881 | if (!gop.found_existing) { | 5821 | if (!gop.found_existing) gop.value_ptr.* = .{ |
| 5882 | gop.value_ptr.* = src_node; | 5822 | .base_node_inst = block.src_base_inst, |
| 5883 | } | 5823 | .node_offset = src_node, |
| | 5824 | }; |
| 5884 | return .void_value; | 5825 | return .void_value; |
| 5885 | } | 5826 | } |
| 5886 | | 5827 | |
| ... | @@ -5891,7 +5832,7 @@ fn zirPanic(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void | ... | @@ -5891,7 +5832,7 @@ fn zirPanic(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void |
| 5891 | | 5832 | |
| 5892 | // `panicWithMsg` would perform this coercion for us, but we can get a better | 5833 | // `panicWithMsg` would perform this coercion for us, but we can get a better |
| 5893 | // source location if we do it here. | 5834 | // source location if we do it here. |
| 5894 | const coerced_msg = try sema.coerce(block, Type.slice_const_u8, msg_inst, .{ .node_offset_builtin_call_arg0 = inst_data.src_node }); | 5835 | const coerced_msg = try sema.coerce(block, Type.slice_const_u8, msg_inst, block.builtinCallArgSrc(inst_data.src_node, 0)); |
| 5895 | | 5836 | |
| 5896 | if (block.is_comptime) { | 5837 | if (block.is_comptime) { |
| 5897 | return sema.fail(block, src, "encountered @panic at comptime", .{}); | 5838 | return sema.fail(block, src, "encountered @panic at comptime", .{}); |
| ... | @@ -5901,7 +5842,7 @@ fn zirPanic(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void | ... | @@ -5901,7 +5842,7 @@ fn zirPanic(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void |
| 5901 | | 5842 | |
| 5902 | fn zirTrap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void { | 5843 | fn zirTrap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void { |
| 5903 | const src_node = sema.code.instructions.items(.data)[@intFromEnum(inst)].node; | 5844 | const src_node = sema.code.instructions.items(.data)[@intFromEnum(inst)].node; |
| 5904 | const src = LazySrcLoc.nodeOffset(src_node); | 5845 | const src = block.nodeOffset(src_node); |
| 5905 | if (block.is_comptime) | 5846 | if (block.is_comptime) |
| 5906 | return sema.fail(block, src, "encountered @trap at comptime", .{}); | 5847 | return sema.fail(block, src, "encountered @trap at comptime", .{}); |
| 5907 | _ = try block.addNoOp(.trap); | 5848 | _ = try block.addNoOp(.trap); |
| ... | @@ -5948,7 +5889,7 @@ fn zirLoop(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError | ... | @@ -5948,7 +5889,7 @@ fn zirLoop(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError |
| 5948 | var child_block = parent_block.makeSubBlock(); | 5889 | var child_block = parent_block.makeSubBlock(); |
| 5949 | child_block.label = &label; | 5890 | child_block.label = &label; |
| 5950 | child_block.runtime_cond = null; | 5891 | child_block.runtime_cond = null; |
| 5951 | child_block.runtime_loop = mod.declPtr(child_block.src_decl).toSrcLoc(src, mod); | 5892 | child_block.runtime_loop = src; |
| 5952 | child_block.runtime_index.increment(); | 5893 | child_block.runtime_index.increment(); |
| 5953 | const merges = &child_block.label.?.merges; | 5894 | const merges = &child_block.label.?.merges; |
| 5954 | | 5895 | |
| ... | @@ -5997,10 +5938,7 @@ fn zirCImport(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileEr | ... | @@ -5997,10 +5938,7 @@ fn zirCImport(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileEr |
| 5997 | var c_import_buf = std.ArrayList(u8).init(gpa); | 5938 | var c_import_buf = std.ArrayList(u8).init(gpa); |
| 5998 | defer c_import_buf.deinit(); | 5939 | defer c_import_buf.deinit(); |
| 5999 | | 5940 | |
| 6000 | var comptime_reason: Block.ComptimeReason = .{ .c_import = .{ | 5941 | const comptime_reason: Block.ComptimeReason = .{ .c_import = .{ .src = src } }; |
| 6001 | .block = parent_block, | | |
| 6002 | .src = src, | | |
| 6003 | } }; | | |
| 6004 | var child_block: Block = .{ | 5942 | var child_block: Block = .{ |
| 6005 | .parent = parent_block, | 5943 | .parent = parent_block, |
| 6006 | .sema = sema, | 5944 | .sema = sema, |
| ... | @@ -6014,6 +5952,7 @@ fn zirCImport(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileEr | ... | @@ -6014,6 +5952,7 @@ fn zirCImport(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileEr |
| 6014 | .runtime_cond = parent_block.runtime_cond, | 5952 | .runtime_cond = parent_block.runtime_cond, |
| 6015 | .runtime_loop = parent_block.runtime_loop, | 5953 | .runtime_loop = parent_block.runtime_loop, |
| 6016 | .runtime_index = parent_block.runtime_index, | 5954 | .runtime_index = parent_block.runtime_index, |
| | 5955 | .src_base_inst = parent_block.src_base_inst, |
| 6017 | }; | 5956 | }; |
| 6018 | defer child_block.instructions.deinit(gpa); | 5957 | defer child_block.instructions.deinit(gpa); |
| 6019 | | 5958 | |
| ... | @@ -6025,11 +5964,11 @@ fn zirCImport(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileEr | ... | @@ -6025,11 +5964,11 @@ fn zirCImport(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileEr |
| 6025 | | 5964 | |
| 6026 | if (c_import_res.errors.errorMessageCount() != 0) { | 5965 | if (c_import_res.errors.errorMessageCount() != 0) { |
| 6027 | const msg = msg: { | 5966 | const msg = msg: { |
| 6028 | const msg = try sema.errMsg(&child_block, src, "C import failed", .{}); | 5967 | const msg = try sema.errMsg(src, "C import failed", .{}); |
| 6029 | errdefer msg.destroy(gpa); | 5968 | errdefer msg.destroy(gpa); |
| 6030 | | 5969 | |
| 6031 | if (!comp.config.link_libc) | 5970 | if (!comp.config.link_libc) |
| 6032 | try sema.errNote(&child_block, src, msg, "libc headers not available; compilation does not link against libc", .{}); | 5971 | try sema.errNote(src, msg, "libc headers not available; compilation does not link against libc", .{}); |
| 6033 | | 5972 | |
| 6034 | const gop = try mod.cimport_errors.getOrPut(gpa, sema.owner_decl_index); | 5973 | const gop = try mod.cimport_errors.getOrPut(gpa, sema.owner_decl_index); |
| 6035 | if (!gop.found_existing) { | 5974 | if (!gop.found_existing) { |
| ... | @@ -6139,6 +6078,7 @@ fn zirBlock(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index, force_compt | ... | @@ -6139,6 +6078,7 @@ fn zirBlock(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index, force_compt |
| 6139 | .runtime_loop = parent_block.runtime_loop, | 6078 | .runtime_loop = parent_block.runtime_loop, |
| 6140 | .runtime_index = parent_block.runtime_index, | 6079 | .runtime_index = parent_block.runtime_index, |
| 6141 | .error_return_trace_index = parent_block.error_return_trace_index, | 6080 | .error_return_trace_index = parent_block.error_return_trace_index, |
| | 6081 | .src_base_inst = parent_block.src_base_inst, |
| 6142 | }; | 6082 | }; |
| 6143 | | 6083 | |
| 6144 | defer child_block.instructions.deinit(gpa); | 6084 | defer child_block.instructions.deinit(gpa); |
| ... | @@ -6333,14 +6273,13 @@ fn resolveAnalyzedBlock( | ... | @@ -6333,14 +6273,13 @@ fn resolveAnalyzedBlock( |
| 6333 | const type_src = src; // TODO: better source location | 6273 | const type_src = src; // TODO: better source location |
| 6334 | if (try sema.typeRequiresComptime(resolved_ty)) { | 6274 | if (try sema.typeRequiresComptime(resolved_ty)) { |
| 6335 | const msg = msg: { | 6275 | const msg = msg: { |
| 6336 | const msg = try sema.errMsg(child_block, type_src, "value with comptime-only type '{}' depends on runtime control flow", .{resolved_ty.fmt(mod)}); | 6276 | const msg = try sema.errMsg(type_src, "value with comptime-only type '{}' depends on runtime control flow", .{resolved_ty.fmt(mod)}); |
| 6337 | errdefer msg.destroy(sema.gpa); | 6277 | errdefer msg.destroy(sema.gpa); |
| 6338 | | 6278 | |
| 6339 | const runtime_src = child_block.runtime_cond orelse child_block.runtime_loop.?; | 6279 | const runtime_src = child_block.runtime_cond orelse child_block.runtime_loop.?; |
| 6340 | try mod.errNoteNonLazy(runtime_src, msg, "runtime control flow here", .{}); | 6280 | try sema.errNote(runtime_src, msg, "runtime control flow here", .{}); |
| 6341 | | 6281 | |
| 6342 | const child_src_decl = mod.declPtr(child_block.src_decl); | 6282 | try sema.explainWhyTypeIsComptime(msg, type_src, resolved_ty); |
| 6343 | try sema.explainWhyTypeIsComptime(msg, child_src_decl.toSrcLoc(type_src, mod), resolved_ty); | | |
| 6344 | | 6283 | |
| 6345 | break :msg msg; | 6284 | break :msg msg; |
| 6346 | }; | 6285 | }; |
| ... | @@ -6433,8 +6372,8 @@ fn zirExport(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void | ... | @@ -6433,8 +6372,8 @@ fn zirExport(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void |
| 6433 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 6372 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 6434 | const extra = sema.code.extraData(Zir.Inst.Export, inst_data.payload_index).data; | 6373 | const extra = sema.code.extraData(Zir.Inst.Export, inst_data.payload_index).data; |
| 6435 | const src = block.nodeOffset(inst_data.src_node); | 6374 | const src = block.nodeOffset(inst_data.src_node); |
| 6436 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 6375 | const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0); |
| 6437 | const options_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; | 6376 | const options_src = block.builtinCallArgSrc(inst_data.src_node, 1); |
| 6438 | const decl_name = try mod.intern_pool.getOrPutString( | 6377 | const decl_name = try mod.intern_pool.getOrPutString( |
| 6439 | mod.gpa, | 6378 | mod.gpa, |
| 6440 | sema.code.nullTerminatedString(extra.decl_name), | 6379 | sema.code.nullTerminatedString(extra.decl_name), |
| ... | @@ -6448,13 +6387,7 @@ fn zirExport(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void | ... | @@ -6448,13 +6387,7 @@ fn zirExport(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void |
| 6448 | break :index_blk maybe_index orelse | 6387 | break :index_blk maybe_index orelse |
| 6449 | return sema.failWithBadMemberAccess(block, container_ty, operand_src, decl_name); | 6388 | return sema.failWithBadMemberAccess(block, container_ty, operand_src, decl_name); |
| 6450 | } else try sema.lookupIdentifier(block, operand_src, decl_name); | 6389 | } else try sema.lookupIdentifier(block, operand_src, decl_name); |
| 6451 | const options = sema.resolveExportOptions(block, .unneeded, extra.options) catch |err| switch (err) { | 6390 | const options = try sema.resolveExportOptions(block, options_src, extra.options); |
| 6452 | error.NeededSourceLocation => { | | |
| 6453 | _ = try sema.resolveExportOptions(block, options_src, extra.options); | | |
| 6454 | unreachable; | | |
| 6455 | }, | | |
| 6456 | else => |e| return e, | | |
| 6457 | }; | | |
| 6458 | { | 6391 | { |
| 6459 | try sema.ensureDeclAnalyzed(decl_index); | 6392 | try sema.ensureDeclAnalyzed(decl_index); |
| 6460 | const exported_decl = mod.declPtr(decl_index); | 6393 | const exported_decl = mod.declPtr(decl_index); |
| ... | @@ -6473,8 +6406,8 @@ fn zirExportValue(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError | ... | @@ -6473,8 +6406,8 @@ fn zirExportValue(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 6473 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 6406 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 6474 | const extra = sema.code.extraData(Zir.Inst.ExportValue, inst_data.payload_index).data; | 6407 | const extra = sema.code.extraData(Zir.Inst.ExportValue, inst_data.payload_index).data; |
| 6475 | const src = block.nodeOffset(inst_data.src_node); | 6408 | const src = block.nodeOffset(inst_data.src_node); |
| 6476 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 6409 | const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0); |
| 6477 | const options_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; | 6410 | const options_src = block.builtinCallArgSrc(inst_data.src_node, 1); |
| 6478 | const operand = try sema.resolveInstConst(block, operand_src, extra.operand, .{ | 6411 | const operand = try sema.resolveInstConst(block, operand_src, extra.operand, .{ |
| 6479 | .needed_comptime_reason = "export target must be comptime-known", | 6412 | .needed_comptime_reason = "export target must be comptime-known", |
| 6480 | }); | 6413 | }); |
| ... | @@ -6490,7 +6423,6 @@ fn zirExportValue(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError | ... | @@ -6490,7 +6423,6 @@ fn zirExportValue(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 6490 | .opts = options, | 6423 | .opts = options, |
| 6491 | .src = src, | 6424 | .src = src, |
| 6492 | .owner_decl = sema.owner_decl_index, | 6425 | .owner_decl = sema.owner_decl_index, |
| 6493 | .src_decl = block.src_decl, | | |
| 6494 | .exported = .{ .value = operand.toIntern() }, | 6426 | .exported = .{ .value = operand.toIntern() }, |
| 6495 | .status = .in_progress, | 6427 | .status = .in_progress, |
| 6496 | }); | 6428 | }); |
| ... | @@ -6515,11 +6447,10 @@ pub fn analyzeExport( | ... | @@ -6515,11 +6447,10 @@ pub fn analyzeExport( |
| 6515 | | 6447 | |
| 6516 | if (!try sema.validateExternType(export_ty, .other)) { | 6448 | if (!try sema.validateExternType(export_ty, .other)) { |
| 6517 | const msg = msg: { | 6449 | const msg = msg: { |
| 6518 | const msg = try sema.errMsg(block, src, "unable to export type '{}'", .{export_ty.fmt(mod)}); | 6450 | const msg = try sema.errMsg(src, "unable to export type '{}'", .{export_ty.fmt(mod)}); |
| 6519 | errdefer msg.destroy(gpa); | 6451 | errdefer msg.destroy(gpa); |
| 6520 | | 6452 | |
| 6521 | const src_decl = mod.declPtr(block.src_decl); | 6453 | try sema.explainWhyTypeIsNotExtern(msg, src, export_ty, .other); |
| 6522 | try sema.explainWhyTypeIsNotExtern(msg, src_decl.toSrcLoc(src, mod), export_ty, .other); | | |
| 6523 | | 6454 | |
| 6524 | try sema.addDeclaredHereNote(msg, export_ty); | 6455 | try sema.addDeclaredHereNote(msg, export_ty); |
| 6525 | break :msg msg; | 6456 | break :msg msg; |
| ... | @@ -6538,7 +6469,6 @@ pub fn analyzeExport( | ... | @@ -6538,7 +6469,6 @@ pub fn analyzeExport( |
| 6538 | .opts = options, | 6469 | .opts = options, |
| 6539 | .src = src, | 6470 | .src = src, |
| 6540 | .owner_decl = sema.owner_decl_index, | 6471 | .owner_decl = sema.owner_decl_index, |
| 6541 | .src_decl = block.src_decl, | | |
| 6542 | .exported = .{ .decl_index = exported_decl_index }, | 6472 | .exported = .{ .decl_index = exported_decl_index }, |
| 6543 | .status = .in_progress, | 6473 | .status = .in_progress, |
| 6544 | }); | 6474 | }); |
| ... | @@ -6578,8 +6508,8 @@ fn addExport(mod: *Module, export_init: Module.Export) error{OutOfMemory}!void { | ... | @@ -6578,8 +6508,8 @@ fn addExport(mod: *Module, export_init: Module.Export) error{OutOfMemory}!void { |
| 6578 | fn zirSetAlignStack(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!void { | 6508 | fn zirSetAlignStack(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!void { |
| 6579 | const mod = sema.mod; | 6509 | const mod = sema.mod; |
| 6580 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; | 6510 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; |
| 6581 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node }; | 6511 | const operand_src = block.builtinCallArgSrc(extra.node, 0); |
| 6582 | const src = LazySrcLoc.nodeOffset(extra.node); | 6512 | const src = block.nodeOffset(extra.node); |
| 6583 | const alignment = try sema.resolveAlign(block, operand_src, extra.operand); | 6513 | const alignment = try sema.resolveAlign(block, operand_src, extra.operand); |
| 6584 | if (alignment.order(Alignment.fromNonzeroByteUnits(256)).compare(.gt)) { | 6514 | if (alignment.order(Alignment.fromNonzeroByteUnits(256)).compare(.gt)) { |
| 6585 | return sema.fail(block, src, "attempt to @setAlignStack({d}); maximum is 256", .{ | 6515 | return sema.fail(block, src, "attempt to @setAlignStack({d}); maximum is 256", .{ |
| ... | @@ -6598,9 +6528,9 @@ fn zirSetAlignStack(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.Inst | ... | @@ -6598,9 +6528,9 @@ fn zirSetAlignStack(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.Inst |
| 6598 | | 6528 | |
| 6599 | if (sema.prev_stack_alignment_src) |prev_src| { | 6529 | if (sema.prev_stack_alignment_src) |prev_src| { |
| 6600 | const msg = msg: { | 6530 | const msg = msg: { |
| 6601 | const msg = try sema.errMsg(block, src, "multiple @setAlignStack in the same function body", .{}); | 6531 | const msg = try sema.errMsg(src, "multiple @setAlignStack in the same function body", .{}); |
| 6602 | errdefer msg.destroy(sema.gpa); | 6532 | errdefer msg.destroy(sema.gpa); |
| 6603 | try sema.errNote(block, prev_src, msg, "other instance here", .{}); | 6533 | try sema.errNote(prev_src, msg, "other instance here", .{}); |
| 6604 | break :msg msg; | 6534 | break :msg msg; |
| 6605 | }; | 6535 | }; |
| 6606 | return sema.failWithOwnedErrorMsg(block, msg); | 6536 | return sema.failWithOwnedErrorMsg(block, msg); |
| ... | @@ -6621,7 +6551,7 @@ fn zirSetCold(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) | ... | @@ -6621,7 +6551,7 @@ fn zirSetCold(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) |
| 6621 | const mod = sema.mod; | 6551 | const mod = sema.mod; |
| 6622 | const ip = &mod.intern_pool; | 6552 | const ip = &mod.intern_pool; |
| 6623 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; | 6553 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; |
| 6624 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node }; | 6554 | const operand_src = block.builtinCallArgSrc(extra.node, 0); |
| 6625 | const is_cold = try sema.resolveConstBool(block, operand_src, extra.operand, .{ | 6555 | const is_cold = try sema.resolveConstBool(block, operand_src, extra.operand, .{ |
| 6626 | .needed_comptime_reason = "operand to @setCold must be comptime-known", | 6556 | .needed_comptime_reason = "operand to @setCold must be comptime-known", |
| 6627 | }); | 6557 | }); |
| ... | @@ -6631,7 +6561,7 @@ fn zirSetCold(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) | ... | @@ -6631,7 +6561,7 @@ fn zirSetCold(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) |
| 6631 | | 6561 | |
| 6632 | fn zirSetFloatMode(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!void { | 6562 | fn zirSetFloatMode(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!void { |
| 6633 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; | 6563 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; |
| 6634 | const src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node }; | 6564 | const src = block.builtinCallArgSrc(extra.node, 0); |
| 6635 | block.float_mode = try sema.resolveBuiltinEnum(block, src, extra.operand, "FloatMode", .{ | 6565 | block.float_mode = try sema.resolveBuiltinEnum(block, src, extra.operand, "FloatMode", .{ |
| 6636 | .needed_comptime_reason = "operand to @setFloatMode must be comptime-known", | 6566 | .needed_comptime_reason = "operand to @setFloatMode must be comptime-known", |
| 6637 | }); | 6567 | }); |
| ... | @@ -6639,7 +6569,7 @@ fn zirSetFloatMode(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstD | ... | @@ -6639,7 +6569,7 @@ fn zirSetFloatMode(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstD |
| 6639 | | 6569 | |
| 6640 | fn zirSetRuntimeSafety(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void { | 6570 | fn zirSetRuntimeSafety(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void { |
| 6641 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; | 6571 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 6642 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 6572 | const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0); |
| 6643 | block.want_safety = try sema.resolveConstBool(block, operand_src, inst_data.operand, .{ | 6573 | block.want_safety = try sema.resolveConstBool(block, operand_src, inst_data.operand, .{ |
| 6644 | .needed_comptime_reason = "operand to @setRuntimeSafety must be comptime-known", | 6574 | .needed_comptime_reason = "operand to @setRuntimeSafety must be comptime-known", |
| 6645 | }); | 6575 | }); |
| ... | @@ -6649,7 +6579,7 @@ fn zirFence(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) Co | ... | @@ -6649,7 +6579,7 @@ fn zirFence(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) Co |
| 6649 | if (block.is_comptime) return; | 6579 | if (block.is_comptime) return; |
| 6650 | | 6580 | |
| 6651 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; | 6581 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; |
| 6652 | const order_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node }; | 6582 | const order_src = block.builtinCallArgSrc(extra.node, 0); |
| 6653 | const order = try sema.resolveAtomicOrder(block, order_src, extra.operand, .{ | 6583 | const order = try sema.resolveAtomicOrder(block, order_src, extra.operand, .{ |
| 6654 | .needed_comptime_reason = "atomic order of @fence must be comptime-known", | 6584 | .needed_comptime_reason = "atomic order of @fence must be comptime-known", |
| 6655 | }); | 6585 | }); |
| ... | @@ -6679,7 +6609,7 @@ fn zirBreak(sema: *Sema, start_block: *Block, inst: Zir.Inst.Index) CompileError | ... | @@ -6679,7 +6609,7 @@ fn zirBreak(sema: *Sema, start_block: *Block, inst: Zir.Inst.Index) CompileError |
| 6679 | if (label.zir_block == zir_block) { | 6609 | if (label.zir_block == zir_block) { |
| 6680 | const br_ref = try start_block.addBr(label.merges.block_inst, operand); | 6610 | const br_ref = try start_block.addBr(label.merges.block_inst, operand); |
| 6681 | const src_loc = if (extra.operand_src_node != Zir.Inst.Break.no_src_node) | 6611 | const src_loc = if (extra.operand_src_node != Zir.Inst.Break.no_src_node) |
| 6682 | LazySrcLoc.nodeOffset(extra.operand_src_node) | 6612 | start_block.nodeOffset(extra.operand_src_node) |
| 6683 | else | 6613 | else |
| 6684 | null; | 6614 | null; |
| 6685 | try label.merges.src_locs.append(sema.gpa, src_loc); | 6615 | try label.merges.src_locs.append(sema.gpa, src_loc); |
| ... | @@ -6906,12 +6836,14 @@ fn lookupInNamespace( | ... | @@ -6906,12 +6836,14 @@ fn lookupInNamespace( |
| 6906 | }, | 6836 | }, |
| 6907 | else => { | 6837 | else => { |
| 6908 | const msg = msg: { | 6838 | const msg = msg: { |
| 6909 | const msg = try sema.errMsg(block, src, "ambiguous reference", .{}); | 6839 | const msg = try sema.errMsg(src, "ambiguous reference", .{}); |
| 6910 | errdefer msg.destroy(gpa); | 6840 | errdefer msg.destroy(gpa); |
| 6911 | for (candidates.items) |candidate_index| { | 6841 | for (candidates.items) |candidate_index| { |
| 6912 | const candidate = mod.declPtr(candidate_index); | 6842 | const candidate = mod.declPtr(candidate_index); |
| 6913 | const src_loc = candidate.srcLoc(mod); | 6843 | try sema.errNote(.{ |
| 6914 | try mod.errNoteNonLazy(src_loc, msg, "declared here", .{}); | 6844 | .base_node_inst = candidate.zir_decl_index.unwrap().?, |
| | 6845 | .offset = LazySrcLoc.Offset.nodeOffset(0), |
| | 6846 | }, msg, "declared here", .{}); |
| 6915 | } | 6847 | } |
| 6916 | break :msg msg; | 6848 | break :msg msg; |
| 6917 | }; | 6849 | }; |
| ... | @@ -6953,16 +6885,16 @@ pub fn analyzeSaveErrRetIndex(sema: *Sema, block: *Block) SemaError!Air.Inst.Ref | ... | @@ -6953,16 +6885,16 @@ pub fn analyzeSaveErrRetIndex(sema: *Sema, block: *Block) SemaError!Air.Inst.Ref |
| 6953 | if (!block.ownerModule().error_tracing) return .none; | 6885 | if (!block.ownerModule().error_tracing) return .none; |
| 6954 | | 6886 | |
| 6955 | const stack_trace_ty = sema.getBuiltinType("StackTrace") catch |err| switch (err) { | 6887 | const stack_trace_ty = sema.getBuiltinType("StackTrace") catch |err| switch (err) { |
| 6956 | error.NeededSourceLocation, error.GenericPoison, error.ComptimeReturn, error.ComptimeBreak => unreachable, | 6888 | error.GenericPoison, error.ComptimeReturn, error.ComptimeBreak => unreachable, |
| 6957 | else => |e| return e, | 6889 | else => |e| return e, |
| 6958 | }; | 6890 | }; |
| 6959 | sema.resolveTypeFields(stack_trace_ty) catch |err| switch (err) { | 6891 | sema.resolveTypeFields(stack_trace_ty) catch |err| switch (err) { |
| 6960 | error.NeededSourceLocation, error.GenericPoison, error.ComptimeReturn, error.ComptimeBreak => unreachable, | 6892 | error.GenericPoison, error.ComptimeReturn, error.ComptimeBreak => unreachable, |
| 6961 | else => |e| return e, | 6893 | else => |e| return e, |
| 6962 | }; | 6894 | }; |
| 6963 | const field_name = try mod.intern_pool.getOrPutString(gpa, "index", .no_embedded_nulls); | 6895 | const field_name = try mod.intern_pool.getOrPutString(gpa, "index", .no_embedded_nulls); |
| 6964 | const field_index = sema.structFieldIndex(block, stack_trace_ty, field_name, .unneeded) catch |err| switch (err) { | 6896 | const field_index = sema.structFieldIndex(block, stack_trace_ty, field_name, LazySrcLoc.unneeded) catch |err| switch (err) { |
| 6965 | error.AnalysisFail, error.NeededSourceLocation => @panic("std.builtin.StackTrace is corrupt"), | 6897 | error.AnalysisFail => @panic("std.builtin.StackTrace is corrupt"), |
| 6966 | error.GenericPoison, error.ComptimeReturn, error.ComptimeBreak => unreachable, | 6898 | error.GenericPoison, error.ComptimeReturn, error.ComptimeBreak => unreachable, |
| 6967 | error.OutOfMemory => |e| return e, | 6899 | error.OutOfMemory => |e| return e, |
| 6968 | }; | 6900 | }; |
| ... | @@ -7070,7 +7002,7 @@ fn zirCall( | ... | @@ -7070,7 +7002,7 @@ fn zirCall( |
| 7070 | | 7002 | |
| 7071 | const mod = sema.mod; | 7003 | const mod = sema.mod; |
| 7072 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 7004 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 7073 | const callee_src: LazySrcLoc = .{ .node_offset_call_func = inst_data.src_node }; | 7005 | const callee_src = block.src(.{ .node_offset_call_func = inst_data.src_node }); |
| 7074 | const call_src = block.nodeOffset(inst_data.src_node); | 7006 | const call_src = block.nodeOffset(inst_data.src_node); |
| 7075 | const ExtraType = switch (kind) { | 7007 | const ExtraType = switch (kind) { |
| 7076 | .direct => Zir.Inst.Call, | 7008 | .direct => Zir.Inst.Call, |
| ... | @@ -7092,7 +7024,7 @@ fn zirCall( | ... | @@ -7092,7 +7024,7 @@ fn zirCall( |
| 7092 | sema.code.nullTerminatedString(extra.data.field_name_start), | 7024 | sema.code.nullTerminatedString(extra.data.field_name_start), |
| 7093 | .no_embedded_nulls, | 7025 | .no_embedded_nulls, |
| 7094 | ); | 7026 | ); |
| 7095 | const field_name_src: LazySrcLoc = .{ .node_offset_field_name = inst_data.src_node }; | 7027 | const field_name_src = block.src(.{ .node_offset_field_name = inst_data.src_node }); |
| 7096 | break :blk try sema.fieldCallBind(block, callee_src, object_ptr, field_name, field_name_src); | 7028 | break :blk try sema.fieldCallBind(block, callee_src, object_ptr, field_name, field_name_src); |
| 7097 | }, | 7029 | }, |
| 7098 | }; | 7030 | }; |
| ... | @@ -7202,11 +7134,11 @@ fn checkCallArgumentCount( | ... | @@ -7202,11 +7134,11 @@ fn checkCallArgumentCount( |
| 7202 | opt_child.childType(mod).zigTypeTag(mod) == .Fn)) | 7134 | opt_child.childType(mod).zigTypeTag(mod) == .Fn)) |
| 7203 | { | 7135 | { |
| 7204 | const msg = msg: { | 7136 | const msg = msg: { |
| 7205 | const msg = try sema.errMsg(block, func_src, "cannot call optional type '{}'", .{ | 7137 | const msg = try sema.errMsg(func_src, "cannot call optional type '{}'", .{ |
| 7206 | callee_ty.fmt(mod), | 7138 | callee_ty.fmt(mod), |
| 7207 | }); | 7139 | }); |
| 7208 | errdefer msg.destroy(sema.gpa); | 7140 | errdefer msg.destroy(sema.gpa); |
| 7209 | try sema.errNote(block, func_src, msg, "consider using '.?', 'orelse' or 'if'", .{}); | 7141 | try sema.errNote(func_src, msg, "consider using '.?', 'orelse' or 'if'", .{}); |
| 7210 | break :msg msg; | 7142 | break :msg msg; |
| 7211 | }; | 7143 | }; |
| 7212 | return sema.failWithOwnedErrorMsg(block, msg); | 7144 | return sema.failWithOwnedErrorMsg(block, msg); |
| ... | @@ -7232,7 +7164,6 @@ fn checkCallArgumentCount( | ... | @@ -7232,7 +7164,6 @@ fn checkCallArgumentCount( |
| 7232 | const variadic_str = if (func_ty_info.is_var_args) "at least " else ""; | 7164 | const variadic_str = if (func_ty_info.is_var_args) "at least " else ""; |
| 7233 | const msg = msg: { | 7165 | const msg = msg: { |
| 7234 | const msg = try sema.errMsg( | 7166 | const msg = try sema.errMsg( |
| 7235 | block, | | |
| 7236 | func_src, | 7167 | func_src, |
| 7237 | "{s}expected {s}{d} argument(s), found {d}", | 7168 | "{s}expected {s}{d} argument(s), found {d}", |
| 7238 | .{ | 7169 | .{ |
| ... | @@ -7244,7 +7175,12 @@ fn checkCallArgumentCount( | ... | @@ -7244,7 +7175,12 @@ fn checkCallArgumentCount( |
| 7244 | ); | 7175 | ); |
| 7245 | errdefer msg.destroy(sema.gpa); | 7176 | errdefer msg.destroy(sema.gpa); |
| 7246 | | 7177 | |
| 7247 | if (maybe_decl) |fn_decl| try mod.errNoteNonLazy(fn_decl.srcLoc(mod), msg, "function declared here", .{}); | 7178 | if (maybe_decl) |fn_decl| { |
| | 7179 | try sema.errNote(.{ |
| | 7180 | .base_node_inst = fn_decl.zir_decl_index.unwrap().?, |
| | 7181 | .offset = LazySrcLoc.Offset.nodeOffset(0), |
| | 7182 | }, msg, "function declared here", .{}); |
| | 7183 | } |
| 7248 | break :msg msg; | 7184 | break :msg msg; |
| 7249 | }; | 7185 | }; |
| 7250 | return sema.failWithOwnedErrorMsg(block, msg); | 7186 | return sema.failWithOwnedErrorMsg(block, msg); |
| ... | @@ -7352,18 +7288,16 @@ const CallArgsInfo = union(enum) { | ... | @@ -7352,18 +7288,16 @@ const CallArgsInfo = union(enum) { |
| 7352 | fn argSrc(cai: CallArgsInfo, block: *Block, arg_index: usize) LazySrcLoc { | 7288 | fn argSrc(cai: CallArgsInfo, block: *Block, arg_index: usize) LazySrcLoc { |
| 7353 | return switch (cai) { | 7289 | return switch (cai) { |
| 7354 | .resolved => |resolved| resolved.src, | 7290 | .resolved => |resolved| resolved.src, |
| 7355 | .call_builtin => |call_builtin| .{ .call_arg = .{ | 7291 | .call_builtin => |call_builtin| block.src(.{ .call_arg = .{ |
| 7356 | .decl = block.src_decl, | | |
| 7357 | .call_node_offset = call_builtin.call_node_offset, | 7292 | .call_node_offset = call_builtin.call_node_offset, |
| 7358 | .arg_index = @intCast(arg_index), | 7293 | .arg_index = @intCast(arg_index), |
| 7359 | } }, | 7294 | } }), |
| 7360 | .zir_call => |zir_call| if (arg_index == 0 and zir_call.bound_arg != .none) { | 7295 | .zir_call => |zir_call| if (arg_index == 0 and zir_call.bound_arg != .none) { |
| 7361 | return zir_call.bound_arg_src; | 7296 | return zir_call.bound_arg_src; |
| 7362 | } else .{ .call_arg = .{ | 7297 | } else block.src(.{ .call_arg = .{ |
| 7363 | .decl = block.src_decl, | | |
| 7364 | .call_node_offset = zir_call.call_node_offset, | 7298 | .call_node_offset = zir_call.call_node_offset, |
| 7365 | .arg_index = @intCast(arg_index - @intFromBool(zir_call.bound_arg != .none)), | 7299 | .arg_index = @intCast(arg_index - @intFromBool(zir_call.bound_arg != .none)), |
| 7366 | } }, | 7300 | } }), |
| 7367 | }; | 7301 | }; |
| 7368 | } | 7302 | } |
| 7369 | | 7303 | |
| ... | @@ -7475,7 +7409,6 @@ const InlineCallSema = struct { | ... | @@ -7475,7 +7409,6 @@ const InlineCallSema = struct { |
| 7475 | other_error_return_trace_index_on_fn_entry: Air.Inst.Ref, | 7409 | other_error_return_trace_index_on_fn_entry: Air.Inst.Ref, |
| 7476 | other_generic_owner: InternPool.Index, | 7410 | other_generic_owner: InternPool.Index, |
| 7477 | other_generic_call_src: LazySrcLoc, | 7411 | other_generic_call_src: LazySrcLoc, |
| 7478 | other_generic_call_decl: InternPool.OptionalDeclIndex, | | |
| 7479 | | 7412 | |
| 7480 | /// Sema should currently be set up for the caller (i.e. unchanged yet). This init will not | 7413 | /// Sema should currently be set up for the caller (i.e. unchanged yet). This init will not |
| 7481 | /// change that. The other parameters contain data for the callee Sema. The other modified | 7414 | /// change that. The other parameters contain data for the callee Sema. The other modified |
| ... | @@ -7497,8 +7430,7 @@ const InlineCallSema = struct { | ... | @@ -7497,8 +7430,7 @@ const InlineCallSema = struct { |
| 7497 | .other_inst_map = .{}, | 7430 | .other_inst_map = .{}, |
| 7498 | .other_error_return_trace_index_on_fn_entry = callee_error_return_trace_index_on_fn_entry, | 7431 | .other_error_return_trace_index_on_fn_entry = callee_error_return_trace_index_on_fn_entry, |
| 7499 | .other_generic_owner = .none, | 7432 | .other_generic_owner = .none, |
| 7500 | .other_generic_call_src = .unneeded, | 7433 | .other_generic_call_src = LazySrcLoc.unneeded, |
| 7501 | .other_generic_call_decl = .none, | | |
| 7502 | }; | 7434 | }; |
| 7503 | } | 7435 | } |
| 7504 | | 7436 | |
| ... | @@ -7545,7 +7477,6 @@ const InlineCallSema = struct { | ... | @@ -7545,7 +7477,6 @@ const InlineCallSema = struct { |
| 7545 | std.mem.swap(InstMap, &ics.sema.inst_map, &ics.other_inst_map); | 7477 | std.mem.swap(InstMap, &ics.sema.inst_map, &ics.other_inst_map); |
| 7546 | std.mem.swap(InternPool.Index, &ics.sema.generic_owner, &ics.other_generic_owner); | 7478 | std.mem.swap(InternPool.Index, &ics.sema.generic_owner, &ics.other_generic_owner); |
| 7547 | std.mem.swap(LazySrcLoc, &ics.sema.generic_call_src, &ics.other_generic_call_src); | 7479 | std.mem.swap(LazySrcLoc, &ics.sema.generic_call_src, &ics.other_generic_call_src); |
| 7548 | std.mem.swap(InternPool.OptionalDeclIndex, &ics.sema.generic_call_decl, &ics.other_generic_call_decl); | | |
| 7549 | std.mem.swap(Air.Inst.Ref, &ics.sema.error_return_trace_index_on_fn_entry, &ics.other_error_return_trace_index_on_fn_entry); | 7480 | std.mem.swap(Air.Inst.Ref, &ics.sema.error_return_trace_index_on_fn_entry, &ics.other_error_return_trace_index_on_fn_entry); |
| 7550 | // zig fmt: on | 7481 | // zig fmt: on |
| 7551 | } | 7482 | } |
| ... | @@ -7577,14 +7508,16 @@ fn analyzeCall( | ... | @@ -7577,14 +7508,16 @@ fn analyzeCall( |
| 7577 | const maybe_decl = try sema.funcDeclSrc(func); | 7508 | const maybe_decl = try sema.funcDeclSrc(func); |
| 7578 | const msg = msg: { | 7509 | const msg = msg: { |
| 7579 | const msg = try sema.errMsg( | 7510 | const msg = try sema.errMsg( |
| 7580 | block, | | |
| 7581 | func_src, | 7511 | func_src, |
| 7582 | "unable to call function with naked calling convention", | 7512 | "unable to call function with naked calling convention", |
| 7583 | .{}, | 7513 | .{}, |
| 7584 | ); | 7514 | ); |
| 7585 | errdefer msg.destroy(sema.gpa); | 7515 | errdefer msg.destroy(sema.gpa); |
| 7586 | | 7516 | |
| 7587 | if (maybe_decl) |fn_decl| try mod.errNoteNonLazy(fn_decl.srcLoc(mod), msg, "function declared here", .{}); | 7517 | if (maybe_decl) |fn_decl| try sema.errNote(.{ |
| | 7518 | .base_node_inst = fn_decl.zir_decl_index.unwrap().?, |
| | 7519 | .offset = LazySrcLoc.Offset.nodeOffset(0), |
| | 7520 | }, msg, "function declared here", .{}); |
| 7588 | break :msg msg; | 7521 | break :msg msg; |
| 7589 | }; | 7522 | }; |
| 7590 | return sema.failWithOwnedErrorMsg(block, msg); | 7523 | return sema.failWithOwnedErrorMsg(block, msg); |
| ... | @@ -7623,7 +7556,6 @@ fn analyzeCall( | ... | @@ -7623,7 +7556,6 @@ fn analyzeCall( |
| 7623 | is_inline_call = ct; | 7556 | is_inline_call = ct; |
| 7624 | if (ct) { | 7557 | if (ct) { |
| 7625 | comptime_reason = &.{ .comptime_ret_ty = .{ | 7558 | comptime_reason = &.{ .comptime_ret_ty = .{ |
| 7626 | .block = block, | | |
| 7627 | .func = func, | 7559 | .func = func, |
| 7628 | .func_src = func_src, | 7560 | .func_src = func_src, |
| 7629 | .return_ty = Type.fromInterned(func_ty_info.return_type), | 7561 | .return_ty = Type.fromInterned(func_ty_info.return_type), |
| ... | @@ -7637,12 +7569,12 @@ fn analyzeCall( | ... | @@ -7637,12 +7569,12 @@ fn analyzeCall( |
| 7637 | | 7569 | |
| 7638 | if (sema.func_is_naked and !is_inline_call and !is_comptime_call) { | 7570 | if (sema.func_is_naked and !is_inline_call and !is_comptime_call) { |
| 7639 | const msg = msg: { | 7571 | const msg = msg: { |
| 7640 | const msg = try sema.errMsg(block, call_src, "runtime {s} not allowed in naked function", .{@tagName(operation)}); | 7572 | const msg = try sema.errMsg(call_src, "runtime {s} not allowed in naked function", .{@tagName(operation)}); |
| 7641 | errdefer msg.destroy(sema.gpa); | 7573 | errdefer msg.destroy(sema.gpa); |
| 7642 | | 7574 | |
| 7643 | switch (operation) { | 7575 | switch (operation) { |
| 7644 | .call, .@"@call", .@"@panic", .@"error return" => {}, | 7576 | .call, .@"@call", .@"@panic", .@"error return" => {}, |
| 7645 | .@"safety check" => try sema.errNote(block, call_src, msg, "use @setRuntimeSafety to disable runtime safety", .{}), | 7577 | .@"safety check" => try sema.errNote(call_src, msg, "use @setRuntimeSafety to disable runtime safety", .{}), |
| 7646 | } | 7578 | } |
| 7647 | break :msg msg; | 7579 | break :msg msg; |
| 7648 | }; | 7580 | }; |
| ... | @@ -7669,7 +7601,6 @@ fn analyzeCall( | ... | @@ -7669,7 +7601,6 @@ fn analyzeCall( |
| 7669 | is_inline_call = true; | 7601 | is_inline_call = true; |
| 7670 | is_comptime_call = true; | 7602 | is_comptime_call = true; |
| 7671 | comptime_reason = &.{ .comptime_ret_ty = .{ | 7603 | comptime_reason = &.{ .comptime_ret_ty = .{ |
| 7672 | .block = block, | | |
| 7673 | .func = func, | 7604 | .func = func, |
| 7674 | .func_src = func_src, | 7605 | .func_src = func_src, |
| 7675 | .return_ty = Type.fromInterned(func_ty_info.return_type), | 7606 | .return_ty = Type.fromInterned(func_ty_info.return_type), |
| ... | @@ -7776,6 +7707,7 @@ fn analyzeCall( | ... | @@ -7776,6 +7707,7 @@ fn analyzeCall( |
| 7776 | .runtime_cond = block.runtime_cond, | 7707 | .runtime_cond = block.runtime_cond, |
| 7777 | .runtime_loop = block.runtime_loop, | 7708 | .runtime_loop = block.runtime_loop, |
| 7778 | .runtime_index = block.runtime_index, | 7709 | .runtime_index = block.runtime_index, |
| | 7710 | .src_base_inst = fn_owner_decl.zir_decl_index.unwrap().?, |
| 7779 | }; | 7711 | }; |
| 7780 | | 7712 | |
| 7781 | const merges = &child_block.inlining.?.merges; | 7713 | const merges = &child_block.inlining.?.merges; |
| ... | @@ -7849,7 +7781,7 @@ fn analyzeCall( | ... | @@ -7849,7 +7781,7 @@ fn analyzeCall( |
| 7849 | var block_it = block; | 7781 | var block_it = block; |
| 7850 | while (block_it.inlining) |parent_inlining| { | 7782 | while (block_it.inlining) |parent_inlining| { |
| 7851 | if (!parent_inlining.has_comptime_args and parent_inlining.func == module_fn_index) { | 7783 | if (!parent_inlining.has_comptime_args and parent_inlining.func == module_fn_index) { |
| 7852 | const err_msg = try sema.errMsg(block, call_src, "inline call is recursive", .{}); | 7784 | const err_msg = try sema.errMsg(call_src, "inline call is recursive", .{}); |
| 7853 | return sema.failWithOwnedErrorMsg(null, err_msg); | 7785 | return sema.failWithOwnedErrorMsg(null, err_msg); |
| 7854 | } | 7786 | } |
| 7855 | block_it = parent_inlining.call_block; | 7787 | block_it = parent_inlining.call_block; |
| ... | @@ -7864,7 +7796,7 @@ fn analyzeCall( | ... | @@ -7864,7 +7796,7 @@ fn analyzeCall( |
| 7864 | try sema.resolveInlineBody(&child_block, fn_info.ret_ty_body, module_fn.zir_body_inst.resolve(ip)) | 7796 | try sema.resolveInlineBody(&child_block, fn_info.ret_ty_body, module_fn.zir_body_inst.resolve(ip)) |
| 7865 | else | 7797 | else |
| 7866 | try sema.resolveInst(fn_info.ret_ty_ref); | 7798 | try sema.resolveInst(fn_info.ret_ty_ref); |
| 7867 | const ret_ty_src: LazySrcLoc = .{ .node_offset_fn_type_ret_ty = 0 }; | 7799 | const ret_ty_src: LazySrcLoc = .{ .base_node_inst = module_fn.zir_body_inst, .offset = .{ .node_offset_fn_type_ret_ty = 0 } }; |
| 7868 | sema.fn_ret_ty = try sema.analyzeAsType(&child_block, ret_ty_src, ret_ty_inst); | 7800 | sema.fn_ret_ty = try sema.analyzeAsType(&child_block, ret_ty_src, ret_ty_inst); |
| 7869 | if (module_fn.analysis(ip).inferred_error_set) { | 7801 | if (module_fn.analysis(ip).inferred_error_set) { |
| 7870 | // Create a fresh inferred error set type for inline/comptime calls. | 7802 | // Create a fresh inferred error set type for inline/comptime calls. |
| ... | @@ -7935,7 +7867,7 @@ fn analyzeCall( | ... | @@ -7935,7 +7867,7 @@ fn analyzeCall( |
| 7935 | }; | 7867 | }; |
| 7936 | | 7868 | |
| 7937 | if (is_comptime_call) { | 7869 | if (is_comptime_call) { |
| 7938 | const result_val = try sema.resolveConstValue(block, .unneeded, result, undefined); | 7870 | const result_val = try sema.resolveConstValue(block, LazySrcLoc.unneeded, result, undefined); |
| 7939 | const result_interned = result_val.toIntern(); | 7871 | const result_interned = result_val.toIntern(); |
| 7940 | | 7872 | |
| 7941 | // Transform ad-hoc inferred error set types into concrete error sets. | 7873 | // Transform ad-hoc inferred error set types into concrete error sets. |
| ... | @@ -8276,7 +8208,6 @@ fn instantiateGenericCall( | ... | @@ -8276,7 +8208,6 @@ fn instantiateGenericCall( |
| 8276 | .comptime_args = comptime_args, | 8208 | .comptime_args = comptime_args, |
| 8277 | .generic_owner = generic_owner, | 8209 | .generic_owner = generic_owner, |
| 8278 | .generic_call_src = call_src, | 8210 | .generic_call_src = call_src, |
| 8279 | .generic_call_decl = block.src_decl.toOptional(), | | |
| 8280 | .branch_quota = sema.branch_quota, | 8211 | .branch_quota = sema.branch_quota, |
| 8281 | .branch_count = sema.branch_count, | 8212 | .branch_count = sema.branch_count, |
| 8282 | .comptime_err_ret_trace = sema.comptime_err_ret_trace, | 8213 | .comptime_err_ret_trace = sema.comptime_err_ret_trace, |
| ... | @@ -8291,6 +8222,7 @@ fn instantiateGenericCall( | ... | @@ -8291,6 +8222,7 @@ fn instantiateGenericCall( |
| 8291 | .instructions = .{}, | 8222 | .instructions = .{}, |
| 8292 | .inlining = null, | 8223 | .inlining = null, |
| 8293 | .is_comptime = true, | 8224 | .is_comptime = true, |
| | 8225 | .src_base_inst = fn_owner_decl.zir_decl_index.unwrap().?, |
| 8294 | }; | 8226 | }; |
| 8295 | defer child_block.instructions.deinit(gpa); | 8227 | defer child_block.instructions.deinit(gpa); |
| 8296 | | 8228 | |
| ... | @@ -8321,18 +8253,15 @@ fn instantiateGenericCall( | ... | @@ -8321,18 +8253,15 @@ fn instantiateGenericCall( |
| 8321 | const prev_no_partial_func_ty = child_sema.no_partial_func_ty; | 8253 | const prev_no_partial_func_ty = child_sema.no_partial_func_ty; |
| 8322 | const prev_generic_owner = child_sema.generic_owner; | 8254 | const prev_generic_owner = child_sema.generic_owner; |
| 8323 | const prev_generic_call_src = child_sema.generic_call_src; | 8255 | const prev_generic_call_src = child_sema.generic_call_src; |
| 8324 | const prev_generic_call_decl = child_sema.generic_call_decl; | | |
| 8325 | child_block.params = .{}; | 8256 | child_block.params = .{}; |
| 8326 | child_sema.no_partial_func_ty = true; | 8257 | child_sema.no_partial_func_ty = true; |
| 8327 | child_sema.generic_owner = .none; | 8258 | child_sema.generic_owner = .none; |
| 8328 | child_sema.generic_call_src = .unneeded; | 8259 | child_sema.generic_call_src = LazySrcLoc.unneeded; |
| 8329 | child_sema.generic_call_decl = .none; | | |
| 8330 | defer { | 8260 | defer { |
| 8331 | child_block.params = prev_params; | 8261 | child_block.params = prev_params; |
| 8332 | child_sema.no_partial_func_ty = prev_no_partial_func_ty; | 8262 | child_sema.no_partial_func_ty = prev_no_partial_func_ty; |
| 8333 | child_sema.generic_owner = prev_generic_owner; | 8263 | child_sema.generic_owner = prev_generic_owner; |
| 8334 | child_sema.generic_call_src = prev_generic_call_src; | 8264 | child_sema.generic_call_src = prev_generic_call_src; |
| 8335 | child_sema.generic_call_decl = prev_generic_call_decl; | | |
| 8336 | } | 8265 | } |
| 8337 | | 8266 | |
| 8338 | const param_ty_inst = try child_sema.resolveInlineBody(&child_block, param_ty_body, param_inst); | 8267 | const param_ty_inst = try child_sema.resolveInlineBody(&child_block, param_ty_body, param_inst); |
| ... | @@ -8372,14 +8301,14 @@ fn instantiateGenericCall( | ... | @@ -8372,14 +8301,14 @@ fn instantiateGenericCall( |
| 8372 | .param_anytype_comptime, | 8301 | .param_anytype_comptime, |
| 8373 | => return sema.failWithOwnedErrorMsg(block, msg: { | 8302 | => return sema.failWithOwnedErrorMsg(block, msg: { |
| 8374 | const arg_src = args_info.argSrc(block, arg_index); | 8303 | const arg_src = args_info.argSrc(block, arg_index); |
| 8375 | const msg = try sema.errMsg(block, arg_src, "runtime-known argument passed to comptime parameter", .{}); | 8304 | const msg = try sema.errMsg(arg_src, "runtime-known argument passed to comptime parameter", .{}); |
| 8376 | errdefer msg.destroy(sema.gpa); | 8305 | errdefer msg.destroy(sema.gpa); |
| 8377 | const param_src = child_block.tokenOffset(switch (param_tag) { | 8306 | const param_src = child_block.tokenOffset(switch (param_tag) { |
| 8378 | .param_comptime => fn_zir.instructions.items(.data)[@intFromEnum(param_inst)].pl_tok.src_tok, | 8307 | .param_comptime => fn_zir.instructions.items(.data)[@intFromEnum(param_inst)].pl_tok.src_tok, |
| 8379 | .param_anytype_comptime => fn_zir.instructions.items(.data)[@intFromEnum(param_inst)].str_tok.src_tok, | 8308 | .param_anytype_comptime => fn_zir.instructions.items(.data)[@intFromEnum(param_inst)].str_tok.src_tok, |
| 8380 | else => unreachable, | 8309 | else => unreachable, |
| 8381 | }); | 8310 | }); |
| 8382 | try child_sema.errNote(&child_block, param_src, msg, "declared comptime here", .{}); | 8311 | try child_sema.errNote(param_src, msg, "declared comptime here", .{}); |
| 8383 | break :msg msg; | 8312 | break :msg msg; |
| 8384 | }), | 8313 | }), |
| 8385 | | 8314 | |
| ... | @@ -8387,16 +8316,15 @@ fn instantiateGenericCall( | ... | @@ -8387,16 +8316,15 @@ fn instantiateGenericCall( |
| 8387 | .param_anytype, | 8316 | .param_anytype, |
| 8388 | => return sema.failWithOwnedErrorMsg(block, msg: { | 8317 | => return sema.failWithOwnedErrorMsg(block, msg: { |
| 8389 | const arg_src = args_info.argSrc(block, arg_index); | 8318 | const arg_src = args_info.argSrc(block, arg_index); |
| 8390 | const msg = try sema.errMsg(block, arg_src, "runtime-known argument passed to parameter of comptime-only type", .{}); | 8319 | const msg = try sema.errMsg(arg_src, "runtime-known argument passed to parameter of comptime-only type", .{}); |
| 8391 | errdefer msg.destroy(sema.gpa); | 8320 | errdefer msg.destroy(sema.gpa); |
| 8392 | const param_src = child_block.tokenOffset(switch (param_tag) { | 8321 | const param_src = child_block.tokenOffset(switch (param_tag) { |
| 8393 | .param => fn_zir.instructions.items(.data)[@intFromEnum(param_inst)].pl_tok.src_tok, | 8322 | .param => fn_zir.instructions.items(.data)[@intFromEnum(param_inst)].pl_tok.src_tok, |
| 8394 | .param_anytype => fn_zir.instructions.items(.data)[@intFromEnum(param_inst)].str_tok.src_tok, | 8323 | .param_anytype => fn_zir.instructions.items(.data)[@intFromEnum(param_inst)].str_tok.src_tok, |
| 8395 | else => unreachable, | 8324 | else => unreachable, |
| 8396 | }); | 8325 | }); |
| 8397 | try child_sema.errNote(&child_block, param_src, msg, "declared here", .{}); | 8326 | try child_sema.errNote(param_src, msg, "declared here", .{}); |
| 8398 | const src_decl = mod.declPtr(block.src_decl); | 8327 | try sema.explainWhyTypeIsComptime(msg, arg_src, arg_ty); |
| 8399 | try sema.explainWhyTypeIsComptime(msg, src_decl.toSrcLoc(arg_src, mod), arg_ty); | | |
| 8400 | break :msg msg; | 8328 | break :msg msg; |
| 8401 | }), | 8329 | }), |
| 8402 | | 8330 | |
| ... | @@ -8433,7 +8361,7 @@ fn instantiateGenericCall( | ... | @@ -8433,7 +8361,7 @@ fn instantiateGenericCall( |
| 8433 | // We've already handled parameters, so don't resolve the whole body. Instead, just | 8361 | // We've already handled parameters, so don't resolve the whole body. Instead, just |
| 8434 | // do the instructions after the params (i.e. the func itself). | 8362 | // do the instructions after the params (i.e. the func itself). |
| 8435 | const new_func_inst = try child_sema.resolveInlineBody(&child_block, fn_info.param_body[args_info.count()..], fn_info.param_body_inst); | 8363 | const new_func_inst = try child_sema.resolveInlineBody(&child_block, fn_info.param_body[args_info.count()..], fn_info.param_body_inst); |
| 8436 | const callee_index = (child_sema.resolveConstDefinedValue(&child_block, .unneeded, new_func_inst, undefined) catch unreachable).toIntern(); | 8364 | const callee_index = (child_sema.resolveConstDefinedValue(&child_block, LazySrcLoc.unneeded, new_func_inst, undefined) catch unreachable).toIntern(); |
| 8437 | | 8365 | |
| 8438 | const callee = mod.funcInfo(callee_index); | 8366 | const callee = mod.funcInfo(callee_index); |
| 8439 | callee.branchQuota(ip).* = @max(callee.branchQuota(ip).*, sema.branch_quota); | 8367 | callee.branchQuota(ip).* = @max(callee.branchQuota(ip).*, sema.branch_quota); |
| ... | @@ -8520,7 +8448,7 @@ fn zirOptionalType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro | ... | @@ -8520,7 +8448,7 @@ fn zirOptionalType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro |
| 8520 | | 8448 | |
| 8521 | const mod = sema.mod; | 8449 | const mod = sema.mod; |
| 8522 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; | 8450 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 8523 | const operand_src: LazySrcLoc = .{ .node_offset_un_op = inst_data.src_node }; | 8451 | const operand_src = block.src(.{ .node_offset_un_op = inst_data.src_node }); |
| 8524 | const child_type = try sema.resolveType(block, operand_src, inst_data.operand); | 8452 | const child_type = try sema.resolveType(block, operand_src, inst_data.operand); |
| 8525 | if (child_type.zigTypeTag(mod) == .Opaque) { | 8453 | if (child_type.zigTypeTag(mod) == .Opaque) { |
| 8526 | return sema.fail(block, operand_src, "opaque type '{}' cannot be optional", .{child_type.fmt(mod)}); | 8454 | return sema.fail(block, operand_src, "opaque type '{}' cannot be optional", .{child_type.fmt(mod)}); |
| ... | @@ -8535,7 +8463,7 @@ fn zirOptionalType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro | ... | @@ -8535,7 +8463,7 @@ fn zirOptionalType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro |
| 8535 | fn zirArrayInitElemType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 8463 | fn zirArrayInitElemType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 8536 | const mod = sema.mod; | 8464 | const mod = sema.mod; |
| 8537 | const bin = sema.code.instructions.items(.data)[@intFromEnum(inst)].bin; | 8465 | const bin = sema.code.instructions.items(.data)[@intFromEnum(inst)].bin; |
| 8538 | const maybe_wrapped_indexable_ty = sema.resolveType(block, .unneeded, bin.lhs) catch |err| switch (err) { | 8466 | const maybe_wrapped_indexable_ty = sema.resolveType(block, LazySrcLoc.unneeded, bin.lhs) catch |err| switch (err) { |
| 8539 | // Since this is a ZIR instruction that returns a type, encountering | 8467 | // Since this is a ZIR instruction that returns a type, encountering |
| 8540 | // generic poison should not result in a failed compilation, but the | 8468 | // generic poison should not result in a failed compilation, but the |
| 8541 | // generic poison type. This prevents unnecessary failures when | 8469 | // generic poison type. This prevents unnecessary failures when |
| ... | @@ -8558,7 +8486,7 @@ fn zirArrayInitElemType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compil | ... | @@ -8558,7 +8486,7 @@ fn zirArrayInitElemType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compil |
| 8558 | fn zirElemType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 8486 | fn zirElemType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 8559 | const mod = sema.mod; | 8487 | const mod = sema.mod; |
| 8560 | const un_node = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; | 8488 | const un_node = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 8561 | const maybe_wrapped_ptr_ty = sema.resolveType(block, .unneeded, un_node.operand) catch |err| switch (err) { | 8489 | const maybe_wrapped_ptr_ty = sema.resolveType(block, LazySrcLoc.unneeded, un_node.operand) catch |err| switch (err) { |
| 8562 | error.GenericPoison => return .generic_poison_type, | 8490 | error.GenericPoison => return .generic_poison_type, |
| 8563 | else => |e| return e, | 8491 | else => |e| return e, |
| 8564 | }; | 8492 | }; |
| ... | @@ -8592,7 +8520,7 @@ fn zirIndexablePtrElemType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com | ... | @@ -8592,7 +8520,7 @@ fn zirIndexablePtrElemType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com |
| 8592 | fn zirVectorElemType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 8520 | fn zirVectorElemType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 8593 | const mod = sema.mod; | 8521 | const mod = sema.mod; |
| 8594 | const un_node = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; | 8522 | const un_node = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 8595 | const vec_ty = sema.resolveType(block, .unneeded, un_node.operand) catch |err| switch (err) { | 8523 | const vec_ty = sema.resolveType(block, LazySrcLoc.unneeded, un_node.operand) catch |err| switch (err) { |
| 8596 | // Since this is a ZIR instruction that returns a type, encountering | 8524 | // Since this is a ZIR instruction that returns a type, encountering |
| 8597 | // generic poison should not result in a failed compilation, but the | 8525 | // generic poison should not result in a failed compilation, but the |
| 8598 | // generic poison type. This prevents unnecessary failures when | 8526 | // generic poison type. This prevents unnecessary failures when |
| ... | @@ -8609,8 +8537,8 @@ fn zirVectorElemType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr | ... | @@ -8609,8 +8537,8 @@ fn zirVectorElemType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr |
| 8609 | fn zirVectorType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 8537 | fn zirVectorType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 8610 | const mod = sema.mod; | 8538 | const mod = sema.mod; |
| 8611 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 8539 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 8612 | const len_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 8540 | const len_src = block.builtinCallArgSrc(inst_data.src_node, 0); |
| 8613 | const elem_type_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; | 8541 | const elem_type_src = block.builtinCallArgSrc(inst_data.src_node, 1); |
| 8614 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; | 8542 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 8615 | const len: u32 = @intCast(try sema.resolveInt(block, len_src, extra.lhs, Type.u32, .{ | 8543 | const len: u32 = @intCast(try sema.resolveInt(block, len_src, extra.lhs, Type.u32, .{ |
| 8616 | .needed_comptime_reason = "vector length must be comptime-known", | 8544 | .needed_comptime_reason = "vector length must be comptime-known", |
| ... | @@ -8630,8 +8558,8 @@ fn zirArrayType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A | ... | @@ -8630,8 +8558,8 @@ fn zirArrayType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 8630 | | 8558 | |
| 8631 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 8559 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 8632 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; | 8560 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 8633 | const len_src: LazySrcLoc = .{ .node_offset_array_type_len = inst_data.src_node }; | 8561 | const len_src = block.src(.{ .node_offset_array_type_len = inst_data.src_node }); |
| 8634 | const elem_src: LazySrcLoc = .{ .node_offset_array_type_elem = inst_data.src_node }; | 8562 | const elem_src = block.src(.{ .node_offset_array_type_elem = inst_data.src_node }); |
| 8635 | const len = try sema.resolveInt(block, len_src, extra.lhs, Type.usize, .{ | 8563 | const len = try sema.resolveInt(block, len_src, extra.lhs, Type.usize, .{ |
| 8636 | .needed_comptime_reason = "array length must be comptime-known", | 8564 | .needed_comptime_reason = "array length must be comptime-known", |
| 8637 | }); | 8565 | }); |
| ... | @@ -8651,9 +8579,9 @@ fn zirArrayTypeSentinel(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compil | ... | @@ -8651,9 +8579,9 @@ fn zirArrayTypeSentinel(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compil |
| 8651 | | 8579 | |
| 8652 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 8580 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 8653 | const extra = sema.code.extraData(Zir.Inst.ArrayTypeSentinel, inst_data.payload_index).data; | 8581 | const extra = sema.code.extraData(Zir.Inst.ArrayTypeSentinel, inst_data.payload_index).data; |
| 8654 | const len_src: LazySrcLoc = .{ .node_offset_array_type_len = inst_data.src_node }; | 8582 | const len_src = block.src(.{ .node_offset_array_type_len = inst_data.src_node }); |
| 8655 | const sentinel_src: LazySrcLoc = .{ .node_offset_array_type_sentinel = inst_data.src_node }; | 8583 | const sentinel_src = block.src(.{ .node_offset_array_type_sentinel = inst_data.src_node }); |
| 8656 | const elem_src: LazySrcLoc = .{ .node_offset_array_type_elem = inst_data.src_node }; | 8584 | const elem_src = block.src(.{ .node_offset_array_type_elem = inst_data.src_node }); |
| 8657 | const len = try sema.resolveInt(block, len_src, extra.len, Type.usize, .{ | 8585 | const len = try sema.resolveInt(block, len_src, extra.len, Type.usize, .{ |
| 8658 | .needed_comptime_reason = "array length must be comptime-known", | 8586 | .needed_comptime_reason = "array length must be comptime-known", |
| 8659 | }); | 8587 | }); |
| ... | @@ -8691,7 +8619,7 @@ fn zirAnyframeType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro | ... | @@ -8691,7 +8619,7 @@ fn zirAnyframeType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro |
| 8691 | return sema.failWithUseOfAsync(block, block.nodeOffset(inst_data.src_node)); | 8619 | return sema.failWithUseOfAsync(block, block.nodeOffset(inst_data.src_node)); |
| 8692 | } | 8620 | } |
| 8693 | const mod = sema.mod; | 8621 | const mod = sema.mod; |
| 8694 | const operand_src: LazySrcLoc = .{ .node_offset_anyframe_type = inst_data.src_node }; | 8622 | const operand_src = block.src(.{ .node_offset_anyframe_type = inst_data.src_node }); |
| 8695 | const return_type = try sema.resolveType(block, operand_src, inst_data.operand); | 8623 | const return_type = try sema.resolveType(block, operand_src, inst_data.operand); |
| 8696 | const anyframe_type = try mod.anyframeType(return_type); | 8624 | const anyframe_type = try mod.anyframeType(return_type); |
| 8697 | | 8625 | |
| ... | @@ -8705,8 +8633,8 @@ fn zirErrorUnionType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr | ... | @@ -8705,8 +8633,8 @@ fn zirErrorUnionType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr |
| 8705 | const mod = sema.mod; | 8633 | const mod = sema.mod; |
| 8706 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 8634 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 8707 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; | 8635 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 8708 | const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node }; | 8636 | const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node }); |
| 8709 | const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node }; | 8637 | const rhs_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node }); |
| 8710 | const error_set = try sema.resolveType(block, lhs_src, extra.lhs); | 8638 | const error_set = try sema.resolveType(block, lhs_src, extra.lhs); |
| 8711 | const payload = try sema.resolveType(block, rhs_src, extra.rhs); | 8639 | const payload = try sema.resolveType(block, rhs_src, extra.rhs); |
| 8712 | | 8640 | |
| ... | @@ -8758,8 +8686,8 @@ fn zirIntFromError(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstD | ... | @@ -8758,8 +8686,8 @@ fn zirIntFromError(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstD |
| 8758 | const mod = sema.mod; | 8686 | const mod = sema.mod; |
| 8759 | const ip = &mod.intern_pool; | 8687 | const ip = &mod.intern_pool; |
| 8760 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; | 8688 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; |
| 8761 | const src = LazySrcLoc.nodeOffset(extra.node); | 8689 | const src = block.nodeOffset(extra.node); |
| 8762 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node }; | 8690 | const operand_src = block.builtinCallArgSrc(extra.node, 0); |
| 8763 | const uncasted_operand = try sema.resolveInst(extra.operand); | 8691 | const uncasted_operand = try sema.resolveInst(extra.operand); |
| 8764 | const operand = try sema.coerce(block, Type.anyerror, uncasted_operand, operand_src); | 8692 | const operand = try sema.coerce(block, Type.anyerror, uncasted_operand, operand_src); |
| 8765 | const err_int_ty = try mod.errorIntType(); | 8693 | const err_int_ty = try mod.errorIntType(); |
| ... | @@ -8801,8 +8729,8 @@ fn zirErrorFromInt(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstD | ... | @@ -8801,8 +8729,8 @@ fn zirErrorFromInt(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstD |
| 8801 | | 8729 | |
| 8802 | const mod = sema.mod; | 8730 | const mod = sema.mod; |
| 8803 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; | 8731 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; |
| 8804 | const src = LazySrcLoc.nodeOffset(extra.node); | 8732 | const src = block.nodeOffset(extra.node); |
| 8805 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node }; | 8733 | const operand_src = block.builtinCallArgSrc(extra.node, 0); |
| 8806 | const uncasted_operand = try sema.resolveInst(extra.operand); | 8734 | const uncasted_operand = try sema.resolveInst(extra.operand); |
| 8807 | const err_int_ty = try mod.errorIntType(); | 8735 | const err_int_ty = try mod.errorIntType(); |
| 8808 | const operand = try sema.coerce(block, err_int_ty, uncasted_operand, operand_src); | 8736 | const operand = try sema.coerce(block, err_int_ty, uncasted_operand, operand_src); |
| ... | @@ -8841,16 +8769,16 @@ fn zirMergeErrorSets(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr | ... | @@ -8841,16 +8769,16 @@ fn zirMergeErrorSets(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr |
| 8841 | const ip = &mod.intern_pool; | 8769 | const ip = &mod.intern_pool; |
| 8842 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 8770 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 8843 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; | 8771 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 8844 | const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node }; | 8772 | const src = block.src(.{ .node_offset_bin_op = inst_data.src_node }); |
| 8845 | const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node }; | 8773 | const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node }); |
| 8846 | const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node }; | 8774 | const rhs_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node }); |
| 8847 | const lhs = try sema.resolveInst(extra.lhs); | 8775 | const lhs = try sema.resolveInst(extra.lhs); |
| 8848 | const rhs = try sema.resolveInst(extra.rhs); | 8776 | const rhs = try sema.resolveInst(extra.rhs); |
| 8849 | if (sema.typeOf(lhs).zigTypeTag(mod) == .Bool and sema.typeOf(rhs).zigTypeTag(mod) == .Bool) { | 8777 | if (sema.typeOf(lhs).zigTypeTag(mod) == .Bool and sema.typeOf(rhs).zigTypeTag(mod) == .Bool) { |
| 8850 | const msg = msg: { | 8778 | const msg = msg: { |
| 8851 | const msg = try sema.errMsg(block, lhs_src, "expected error set type, found 'bool'", .{}); | 8779 | const msg = try sema.errMsg(lhs_src, "expected error set type, found 'bool'", .{}); |
| 8852 | errdefer msg.destroy(sema.gpa); | 8780 | errdefer msg.destroy(sema.gpa); |
| 8853 | try sema.errNote(block, src, msg, "'||' merges error sets; 'or' performs boolean OR", .{}); | 8781 | try sema.errNote(src, msg, "'||' merges error sets; 'or' performs boolean OR", .{}); |
| 8854 | break :msg msg; | 8782 | break :msg msg; |
| 8855 | }; | 8783 | }; |
| 8856 | return sema.failWithOwnedErrorMsg(block, msg); | 8784 | return sema.failWithOwnedErrorMsg(block, msg); |
| ... | @@ -8905,7 +8833,7 @@ fn zirIntFromEnum(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError | ... | @@ -8905,7 +8833,7 @@ fn zirIntFromEnum(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 8905 | const mod = sema.mod; | 8833 | const mod = sema.mod; |
| 8906 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; | 8834 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 8907 | const src = block.nodeOffset(inst_data.src_node); | 8835 | const src = block.nodeOffset(inst_data.src_node); |
| 8908 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 8836 | const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0); |
| 8909 | const operand = try sema.resolveInst(inst_data.operand); | 8837 | const operand = try sema.resolveInst(inst_data.operand); |
| 8910 | const operand_ty = sema.typeOf(operand); | 8838 | const operand_ty = sema.typeOf(operand); |
| 8911 | | 8839 | |
| ... | @@ -8963,7 +8891,7 @@ fn zirEnumFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError | ... | @@ -8963,7 +8891,7 @@ fn zirEnumFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 8963 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 8891 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 8964 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; | 8892 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 8965 | const src = block.nodeOffset(inst_data.src_node); | 8893 | const src = block.nodeOffset(inst_data.src_node); |
| 8966 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 8894 | const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0); |
| 8967 | const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu_opt, "@enumFromInt"); | 8895 | const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu_opt, "@enumFromInt"); |
| 8968 | const operand = try sema.resolveInst(extra.rhs); | 8896 | const operand = try sema.resolveInst(extra.rhs); |
| 8969 | | 8897 | |
| ... | @@ -9379,7 +9307,7 @@ fn zirFunc( | ... | @@ -9379,7 +9307,7 @@ fn zirFunc( |
| 9379 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 9307 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 9380 | const extra = sema.code.extraData(Zir.Inst.Func, inst_data.payload_index); | 9308 | const extra = sema.code.extraData(Zir.Inst.Func, inst_data.payload_index); |
| 9381 | const target = sema.mod.getTarget(); | 9309 | const target = sema.mod.getTarget(); |
| 9382 | const ret_ty_src: LazySrcLoc = .{ .node_offset_fn_type_ret_ty = inst_data.src_node }; | 9310 | const ret_ty_src = block.src(.{ .node_offset_fn_type_ret_ty = inst_data.src_node }); |
| 9383 | | 9311 | |
| 9384 | var extra_index = extra.end; | 9312 | var extra_index = extra.end; |
| 9385 | | 9313 | |
| ... | @@ -9460,18 +9388,15 @@ fn resolveGenericBody( | ... | @@ -9460,18 +9388,15 @@ fn resolveGenericBody( |
| 9460 | const prev_no_partial_func_type = sema.no_partial_func_ty; | 9388 | const prev_no_partial_func_type = sema.no_partial_func_ty; |
| 9461 | const prev_generic_owner = sema.generic_owner; | 9389 | const prev_generic_owner = sema.generic_owner; |
| 9462 | const prev_generic_call_src = sema.generic_call_src; | 9390 | const prev_generic_call_src = sema.generic_call_src; |
| 9463 | const prev_generic_call_decl = sema.generic_call_decl; | | |
| 9464 | block.params = .{}; | 9391 | block.params = .{}; |
| 9465 | sema.no_partial_func_ty = true; | 9392 | sema.no_partial_func_ty = true; |
| 9466 | sema.generic_owner = .none; | 9393 | sema.generic_owner = .none; |
| 9467 | sema.generic_call_src = .unneeded; | 9394 | sema.generic_call_src = LazySrcLoc.unneeded; |
| 9468 | sema.generic_call_decl = .none; | | |
| 9469 | defer { | 9395 | defer { |
| 9470 | block.params = prev_params; | 9396 | block.params = prev_params; |
| 9471 | sema.no_partial_func_ty = prev_no_partial_func_type; | 9397 | sema.no_partial_func_ty = prev_no_partial_func_type; |
| 9472 | sema.generic_owner = prev_generic_owner; | 9398 | sema.generic_owner = prev_generic_owner; |
| 9473 | sema.generic_call_src = prev_generic_call_src; | 9399 | sema.generic_call_src = prev_generic_call_src; |
| 9474 | sema.generic_call_decl = prev_generic_call_decl; | | |
| 9475 | } | 9400 | } |
| 9476 | | 9401 | |
| 9477 | const uncasted = sema.resolveInlineBody(block, body, func_inst) catch |err| break :err err; | 9402 | const uncasted = sema.resolveInlineBody(block, body, func_inst) catch |err| break :err err; |
| ... | @@ -9581,9 +9506,9 @@ fn checkCallConvSupportsVarArgs(sema: *Sema, block: *Block, src: LazySrcLoc, cc: | ... | @@ -9581,9 +9506,9 @@ fn checkCallConvSupportsVarArgs(sema: *Sema, block: *Block, src: LazySrcLoc, cc: |
| 9581 | | 9506 | |
| 9582 | if (!callConvSupportsVarArgs(cc)) { | 9507 | if (!callConvSupportsVarArgs(cc)) { |
| 9583 | const msg = msg: { | 9508 | const msg = msg: { |
| 9584 | const msg = try sema.errMsg(block, src, "variadic function does not support '.{s}' calling convention", .{@tagName(cc)}); | 9509 | const msg = try sema.errMsg(src, "variadic function does not support '.{s}' calling convention", .{@tagName(cc)}); |
| 9585 | errdefer msg.destroy(sema.gpa); | 9510 | errdefer msg.destroy(sema.gpa); |
| 9586 | try sema.errNote(block, src, msg, "supported calling conventions: {}", .{CallingConventionsSupportingVarArgsList{}}); | 9511 | try sema.errNote(src, msg, "supported calling conventions: {}", .{CallingConventionsSupportingVarArgsList{}}); |
| 9587 | break :msg msg; | 9512 | break :msg msg; |
| 9588 | }; | 9513 | }; |
| 9589 | return sema.failWithOwnedErrorMsg(block, msg); | 9514 | return sema.failWithOwnedErrorMsg(block, msg); |
| ... | @@ -9623,9 +9548,9 @@ fn funcCommon( | ... | @@ -9623,9 +9548,9 @@ fn funcCommon( |
| 9623 | const gpa = sema.gpa; | 9548 | const gpa = sema.gpa; |
| 9624 | const target = mod.getTarget(); | 9549 | const target = mod.getTarget(); |
| 9625 | const ip = &mod.intern_pool; | 9550 | const ip = &mod.intern_pool; |
| 9626 | const ret_ty_src: LazySrcLoc = .{ .node_offset_fn_type_ret_ty = src_node_offset }; | 9551 | const ret_ty_src = block.src(.{ .node_offset_fn_type_ret_ty = src_node_offset }); |
| 9627 | const cc_src: LazySrcLoc = .{ .node_offset_fn_type_cc = src_node_offset }; | 9552 | const cc_src = block.src(.{ .node_offset_fn_type_cc = src_node_offset }); |
| 9628 | const func_src = LazySrcLoc.nodeOffset(src_node_offset); | 9553 | const func_src = block.nodeOffset(src_node_offset); |
| 9629 | | 9554 | |
| 9630 | var is_generic = bare_return_type.isGenericPoison() or | 9555 | var is_generic = bare_return_type.isGenericPoison() or |
| 9631 | alignment == null or | 9556 | alignment == null or |
| ... | @@ -9654,11 +9579,10 @@ fn funcCommon( | ... | @@ -9654,11 +9579,10 @@ fn funcCommon( |
| 9654 | const index = std.math.cast(u5, i) orelse break :blk false; | 9579 | const index = std.math.cast(u5, i) orelse break :blk false; |
| 9655 | break :blk @as(u1, @truncate(noalias_bits >> index)) != 0; | 9580 | break :blk @as(u1, @truncate(noalias_bits >> index)) != 0; |
| 9656 | }; | 9581 | }; |
| 9657 | const param_src: LazySrcLoc = .{ .fn_proto_param = .{ | 9582 | const param_src = block.src(.{ .fn_proto_param = .{ |
| 9658 | .decl = block.src_decl, | | |
| 9659 | .fn_proto_node_offset = src_node_offset, | 9583 | .fn_proto_node_offset = src_node_offset, |
| 9660 | .param_index = @intCast(i), | 9584 | .param_index = @intCast(i), |
| 9661 | } }; | 9585 | } }); |
| 9662 | const requires_comptime = try sema.typeRequiresComptime(param_ty); | 9586 | const requires_comptime = try sema.typeRequiresComptime(param_ty); |
| 9663 | if (param_is_comptime or requires_comptime) { | 9587 | if (param_is_comptime or requires_comptime) { |
| 9664 | comptime_bits |= @as(u32, 1) << @intCast(i); // TODO: handle cast error | 9588 | comptime_bits |= @as(u32, 1) << @intCast(i); // TODO: handle cast error |
| ... | @@ -9679,13 +9603,12 @@ fn funcCommon( | ... | @@ -9679,13 +9603,12 @@ fn funcCommon( |
| 9679 | } | 9603 | } |
| 9680 | if (!this_generic and !target_util.fnCallConvAllowsZigTypes(target, cc_resolved) and !try sema.validateExternType(param_ty, .param_ty)) { | 9604 | if (!this_generic and !target_util.fnCallConvAllowsZigTypes(target, cc_resolved) and !try sema.validateExternType(param_ty, .param_ty)) { |
| 9681 | const msg = msg: { | 9605 | const msg = msg: { |
| 9682 | const msg = try sema.errMsg(block, param_src, "parameter of type '{}' not allowed in function with calling convention '{s}'", .{ | 9606 | const msg = try sema.errMsg(param_src, "parameter of type '{}' not allowed in function with calling convention '{s}'", .{ |
| 9683 | param_ty.fmt(mod), @tagName(cc_resolved), | 9607 | param_ty.fmt(mod), @tagName(cc_resolved), |
| 9684 | }); | 9608 | }); |
| 9685 | errdefer msg.destroy(sema.gpa); | 9609 | errdefer msg.destroy(sema.gpa); |
| 9686 | | 9610 | |
| 9687 | const src_decl = mod.declPtr(block.src_decl); | 9611 | try sema.explainWhyTypeIsNotExtern(msg, param_src, param_ty, .param_ty); |
| 9688 | try sema.explainWhyTypeIsNotExtern(msg, src_decl.toSrcLoc(param_src, mod), param_ty, .param_ty); | | |
| 9689 | | 9612 | |
| 9690 | try sema.addDeclaredHereNote(msg, param_ty); | 9613 | try sema.addDeclaredHereNote(msg, param_ty); |
| 9691 | break :msg msg; | 9614 | break :msg msg; |
| ... | @@ -9694,13 +9617,12 @@ fn funcCommon( | ... | @@ -9694,13 +9617,12 @@ fn funcCommon( |
| 9694 | } | 9617 | } |
| 9695 | if (is_source_decl and requires_comptime and !param_is_comptime and has_body and !block.is_comptime) { | 9618 | if (is_source_decl and requires_comptime and !param_is_comptime and has_body and !block.is_comptime) { |
| 9696 | const msg = msg: { | 9619 | const msg = msg: { |
| 9697 | const msg = try sema.errMsg(block, param_src, "parameter of type '{}' must be declared comptime", .{ | 9620 | const msg = try sema.errMsg(param_src, "parameter of type '{}' must be declared comptime", .{ |
| 9698 | param_ty.fmt(mod), | 9621 | param_ty.fmt(mod), |
| 9699 | }); | 9622 | }); |
| 9700 | errdefer msg.destroy(sema.gpa); | 9623 | errdefer msg.destroy(sema.gpa); |
| 9701 | | 9624 | |
| 9702 | const src_decl = mod.declPtr(block.src_decl); | 9625 | try sema.explainWhyTypeIsComptime(msg, param_src, param_ty); |
| 9703 | try sema.explainWhyTypeIsComptime(msg, src_decl.toSrcLoc(param_src, mod), param_ty); | | |
| 9704 | | 9626 | |
| 9705 | try sema.addDeclaredHereNote(msg, param_ty); | 9627 | try sema.addDeclaredHereNote(msg, param_ty); |
| 9706 | break :msg msg; | 9628 | break :msg msg; |
| ... | @@ -9861,9 +9783,9 @@ fn funcCommon( | ... | @@ -9861,9 +9783,9 @@ fn funcCommon( |
| 9861 | assert(section != .generic); | 9783 | assert(section != .generic); |
| 9862 | assert(address_space != null); | 9784 | assert(address_space != null); |
| 9863 | assert(!is_generic); | 9785 | assert(!is_generic); |
| 9864 | if (opt_lib_name) |lib_name| try sema.handleExternLibName(block, .{ | 9786 | if (opt_lib_name) |lib_name| try sema.handleExternLibName(block, block.src(.{ |
| 9865 | .node_offset_lib_name = src_node_offset, | 9787 | .node_offset_lib_name = src_node_offset, |
| 9866 | }, lib_name); | 9788 | }), lib_name); |
| 9867 | const func_index = try ip.getExternFunc(gpa, .{ | 9789 | const func_index = try ip.getExternFunc(gpa, .{ |
| 9868 | .ty = func_ty, | 9790 | .ty = func_ty, |
| 9869 | .decl = sema.owner_decl_index, | 9791 | .decl = sema.owner_decl_index, |
| ... | @@ -9975,13 +9897,12 @@ fn finishFunc( | ... | @@ -9975,13 +9897,12 @@ fn finishFunc( |
| 9975 | !try sema.validateExternType(return_type, .ret_ty)) | 9897 | !try sema.validateExternType(return_type, .ret_ty)) |
| 9976 | { | 9898 | { |
| 9977 | const msg = msg: { | 9899 | const msg = msg: { |
| 9978 | const msg = try sema.errMsg(block, ret_ty_src, "return type '{}' not allowed in function with calling convention '{s}'", .{ | 9900 | const msg = try sema.errMsg(ret_ty_src, "return type '{}' not allowed in function with calling convention '{s}'", .{ |
| 9979 | return_type.fmt(mod), @tagName(cc_resolved), | 9901 | return_type.fmt(mod), @tagName(cc_resolved), |
| 9980 | }); | 9902 | }); |
| 9981 | errdefer msg.destroy(gpa); | 9903 | errdefer msg.destroy(gpa); |
| 9982 | | 9904 | |
| 9983 | const src_decl = mod.declPtr(block.src_decl); | 9905 | try sema.explainWhyTypeIsNotExtern(msg, ret_ty_src, return_type, .ret_ty); |
| 9984 | try sema.explainWhyTypeIsNotExtern(msg, src_decl.toSrcLoc(ret_ty_src, mod), return_type, .ret_ty); | | |
| 9985 | | 9906 | |
| 9986 | try sema.addDeclaredHereNote(msg, return_type); | 9907 | try sema.addDeclaredHereNote(msg, return_type); |
| 9987 | break :msg msg; | 9908 | break :msg msg; |
| ... | @@ -9997,12 +9918,11 @@ fn finishFunc( | ... | @@ -9997,12 +9918,11 @@ fn finishFunc( |
| 9997 | } else break :comptime_check; | 9918 | } else break :comptime_check; |
| 9998 | | 9919 | |
| 9999 | const msg = try sema.errMsg( | 9920 | const msg = try sema.errMsg( |
| 10000 | block, | | |
| 10001 | ret_ty_src, | 9921 | ret_ty_src, |
| 10002 | "function with comptime-only return type '{}' requires all parameters to be comptime", | 9922 | "function with comptime-only return type '{}' requires all parameters to be comptime", |
| 10003 | .{return_type.fmt(mod)}, | 9923 | .{return_type.fmt(mod)}, |
| 10004 | ); | 9924 | ); |
| 10005 | try sema.explainWhyTypeIsComptime(msg, sema.owner_decl.toSrcLoc(ret_ty_src, mod), return_type); | 9925 | try sema.explainWhyTypeIsComptime(msg, ret_ty_src, return_type); |
| 10006 | | 9926 | |
| 10007 | const tags = sema.code.instructions.items(.tag); | 9927 | const tags = sema.code.instructions.items(.tag); |
| 10008 | const data = sema.code.instructions.items(.data); | 9928 | const data = sema.code.instructions.items(.data); |
| ... | @@ -10020,9 +9940,9 @@ fn finishFunc( | ... | @@ -10020,9 +9940,9 @@ fn finishFunc( |
| 10020 | }); | 9940 | }); |
| 10021 | const name = sema.code.nullTerminatedString(name_nts); | 9941 | const name = sema.code.nullTerminatedString(name_nts); |
| 10022 | if (name.len != 0) { | 9942 | if (name.len != 0) { |
| 10023 | try sema.errNote(block, param_src, msg, "param '{s}' is required to be comptime", .{name}); | 9943 | try sema.errNote(param_src, msg, "param '{s}' is required to be comptime", .{name}); |
| 10024 | } else { | 9944 | } else { |
| 10025 | try sema.errNote(block, param_src, msg, "param is required to be comptime", .{}); | 9945 | try sema.errNote(param_src, msg, "param is required to be comptime", .{}); |
| 10026 | } | 9946 | } |
| 10027 | } | 9947 | } |
| 10028 | } | 9948 | } |
| ... | @@ -10112,18 +10032,15 @@ fn zirParam( | ... | @@ -10112,18 +10032,15 @@ fn zirParam( |
| 10112 | const prev_no_partial_func_type = sema.no_partial_func_ty; | 10032 | const prev_no_partial_func_type = sema.no_partial_func_ty; |
| 10113 | const prev_generic_owner = sema.generic_owner; | 10033 | const prev_generic_owner = sema.generic_owner; |
| 10114 | const prev_generic_call_src = sema.generic_call_src; | 10034 | const prev_generic_call_src = sema.generic_call_src; |
| 10115 | const prev_generic_call_decl = sema.generic_call_decl; | | |
| 10116 | block.params = .{}; | 10035 | block.params = .{}; |
| 10117 | sema.no_partial_func_ty = true; | 10036 | sema.no_partial_func_ty = true; |
| 10118 | sema.generic_owner = .none; | 10037 | sema.generic_owner = .none; |
| 10119 | sema.generic_call_src = .unneeded; | 10038 | sema.generic_call_src = LazySrcLoc.unneeded; |
| 10120 | sema.generic_call_decl = .none; | | |
| 10121 | defer { | 10039 | defer { |
| 10122 | block.params = prev_params; | 10040 | block.params = prev_params; |
| 10123 | sema.no_partial_func_ty = prev_no_partial_func_type; | 10041 | sema.no_partial_func_ty = prev_no_partial_func_type; |
| 10124 | sema.generic_owner = prev_generic_owner; | 10042 | sema.generic_owner = prev_generic_owner; |
| 10125 | sema.generic_call_src = prev_generic_call_src; | 10043 | sema.generic_call_src = prev_generic_call_src; |
| 10126 | sema.generic_call_decl = prev_generic_call_decl; | | |
| 10127 | } | 10044 | } |
| 10128 | | 10045 | |
| 10129 | if (sema.resolveInlineBody(block, body, inst)) |param_ty_inst| { | 10046 | if (sema.resolveInlineBody(block, body, inst)) |param_ty_inst| { |
| ... | @@ -10265,7 +10182,7 @@ fn zirIntFromPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! | ... | @@ -10265,7 +10182,7 @@ fn zirIntFromPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! |
| 10265 | | 10182 | |
| 10266 | const zcu = sema.mod; | 10183 | const zcu = sema.mod; |
| 10267 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; | 10184 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 10268 | const ptr_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 10185 | const ptr_src = block.builtinCallArgSrc(inst_data.src_node, 0); |
| 10269 | const operand = try sema.resolveInst(inst_data.operand); | 10186 | const operand = try sema.resolveInst(inst_data.operand); |
| 10270 | const operand_ty = sema.typeOf(operand); | 10187 | const operand_ty = sema.typeOf(operand); |
| 10271 | const ptr_ty = operand_ty.scalarType(zcu); | 10188 | const ptr_ty = operand_ty.scalarType(zcu); |
| ... | @@ -10276,10 +10193,9 @@ fn zirIntFromPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! | ... | @@ -10276,10 +10193,9 @@ fn zirIntFromPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! |
| 10276 | const pointee_ty = ptr_ty.childType(zcu); | 10193 | const pointee_ty = ptr_ty.childType(zcu); |
| 10277 | if (try sema.typeRequiresComptime(ptr_ty)) { | 10194 | if (try sema.typeRequiresComptime(ptr_ty)) { |
| 10278 | const msg = msg: { | 10195 | const msg = msg: { |
| 10279 | const msg = try sema.errMsg(block, ptr_src, "comptime-only type '{}' has no pointer address", .{pointee_ty.fmt(zcu)}); | 10196 | const msg = try sema.errMsg(ptr_src, "comptime-only type '{}' has no pointer address", .{pointee_ty.fmt(zcu)}); |
| 10280 | errdefer msg.destroy(sema.gpa); | 10197 | errdefer msg.destroy(sema.gpa); |
| 10281 | const src_decl = zcu.declPtr(block.src_decl); | 10198 | try sema.explainWhyTypeIsComptime(msg, ptr_src, pointee_ty); |
| 10282 | try sema.explainWhyTypeIsComptime(msg, src_decl.toSrcLoc(ptr_src, zcu), pointee_ty); | | |
| 10283 | break :msg msg; | 10199 | break :msg msg; |
| 10284 | }; | 10200 | }; |
| 10285 | return sema.failWithOwnedErrorMsg(block, msg); | 10201 | return sema.failWithOwnedErrorMsg(block, msg); |
| ... | @@ -10340,7 +10256,7 @@ fn zirFieldVal(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -10340,7 +10256,7 @@ fn zirFieldVal(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 10340 | const mod = sema.mod; | 10256 | const mod = sema.mod; |
| 10341 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 10257 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 10342 | const src = block.nodeOffset(inst_data.src_node); | 10258 | const src = block.nodeOffset(inst_data.src_node); |
| 10343 | const field_name_src: LazySrcLoc = .{ .node_offset_field_name = inst_data.src_node }; | 10259 | const field_name_src = block.src(.{ .node_offset_field_name = inst_data.src_node }); |
| 10344 | const extra = sema.code.extraData(Zir.Inst.Field, inst_data.payload_index).data; | 10260 | const extra = sema.code.extraData(Zir.Inst.Field, inst_data.payload_index).data; |
| 10345 | const field_name = try mod.intern_pool.getOrPutString( | 10261 | const field_name = try mod.intern_pool.getOrPutString( |
| 10346 | sema.gpa, | 10262 | sema.gpa, |
| ... | @@ -10358,7 +10274,7 @@ fn zirFieldPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -10358,7 +10274,7 @@ fn zirFieldPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 10358 | const mod = sema.mod; | 10274 | const mod = sema.mod; |
| 10359 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 10275 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 10360 | const src = block.nodeOffset(inst_data.src_node); | 10276 | const src = block.nodeOffset(inst_data.src_node); |
| 10361 | const field_name_src: LazySrcLoc = .{ .node_offset_field_name = inst_data.src_node }; | 10277 | const field_name_src = block.src(.{ .node_offset_field_name = inst_data.src_node }); |
| 10362 | const extra = sema.code.extraData(Zir.Inst.Field, inst_data.payload_index).data; | 10278 | const extra = sema.code.extraData(Zir.Inst.Field, inst_data.payload_index).data; |
| 10363 | const field_name = try mod.intern_pool.getOrPutString( | 10279 | const field_name = try mod.intern_pool.getOrPutString( |
| 10364 | sema.gpa, | 10280 | sema.gpa, |
| ... | @@ -10376,7 +10292,7 @@ fn zirStructInitFieldPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compi | ... | @@ -10376,7 +10292,7 @@ fn zirStructInitFieldPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compi |
| 10376 | const mod = sema.mod; | 10292 | const mod = sema.mod; |
| 10377 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 10293 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 10378 | const src = block.nodeOffset(inst_data.src_node); | 10294 | const src = block.nodeOffset(inst_data.src_node); |
| 10379 | const field_name_src: LazySrcLoc = .{ .node_offset_field_name_init = inst_data.src_node }; | 10295 | const field_name_src = block.src(.{ .node_offset_field_name_init = inst_data.src_node }); |
| 10380 | const extra = sema.code.extraData(Zir.Inst.Field, inst_data.payload_index).data; | 10296 | const extra = sema.code.extraData(Zir.Inst.Field, inst_data.payload_index).data; |
| 10381 | const field_name = try mod.intern_pool.getOrPutString( | 10297 | const field_name = try mod.intern_pool.getOrPutString( |
| 10382 | sema.gpa, | 10298 | sema.gpa, |
| ... | @@ -10401,7 +10317,7 @@ fn zirFieldValNamed(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr | ... | @@ -10401,7 +10317,7 @@ fn zirFieldValNamed(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr |
| 10401 | | 10317 | |
| 10402 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 10318 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 10403 | const src = block.nodeOffset(inst_data.src_node); | 10319 | const src = block.nodeOffset(inst_data.src_node); |
| 10404 | const field_name_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; | 10320 | const field_name_src = block.builtinCallArgSrc(inst_data.src_node, 1); |
| 10405 | const extra = sema.code.extraData(Zir.Inst.FieldNamed, inst_data.payload_index).data; | 10321 | const extra = sema.code.extraData(Zir.Inst.FieldNamed, inst_data.payload_index).data; |
| 10406 | const object = try sema.resolveInst(extra.lhs); | 10322 | const object = try sema.resolveInst(extra.lhs); |
| 10407 | const field_name = try sema.resolveConstStringIntern(block, field_name_src, extra.field_name, .{ | 10323 | const field_name = try sema.resolveConstStringIntern(block, field_name_src, extra.field_name, .{ |
| ... | @@ -10416,7 +10332,7 @@ fn zirFieldPtrNamed(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr | ... | @@ -10416,7 +10332,7 @@ fn zirFieldPtrNamed(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr |
| 10416 | | 10332 | |
| 10417 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 10333 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 10418 | const src = block.nodeOffset(inst_data.src_node); | 10334 | const src = block.nodeOffset(inst_data.src_node); |
| 10419 | const field_name_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; | 10335 | const field_name_src = block.builtinCallArgSrc(inst_data.src_node, 1); |
| 10420 | const extra = sema.code.extraData(Zir.Inst.FieldNamed, inst_data.payload_index).data; | 10336 | const extra = sema.code.extraData(Zir.Inst.FieldNamed, inst_data.payload_index).data; |
| 10421 | const object_ptr = try sema.resolveInst(extra.lhs); | 10337 | const object_ptr = try sema.resolveInst(extra.lhs); |
| 10422 | const field_name = try sema.resolveConstStringIntern(block, field_name_src, extra.field_name, .{ | 10338 | const field_name = try sema.resolveConstStringIntern(block, field_name_src, extra.field_name, .{ |
| ... | @@ -10431,7 +10347,7 @@ fn zirIntCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air | ... | @@ -10431,7 +10347,7 @@ fn zirIntCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 10431 | | 10347 | |
| 10432 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 10348 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 10433 | const src = block.nodeOffset(inst_data.src_node); | 10349 | const src = block.nodeOffset(inst_data.src_node); |
| 10434 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 10350 | const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0); |
| 10435 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; | 10351 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 10436 | | 10352 | |
| 10437 | const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu_opt, "@intCast"); | 10353 | const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu_opt, "@intCast"); |
| ... | @@ -10601,7 +10517,7 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air | ... | @@ -10601,7 +10517,7 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 10601 | const mod = sema.mod; | 10517 | const mod = sema.mod; |
| 10602 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 10518 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 10603 | const src = block.nodeOffset(inst_data.src_node); | 10519 | const src = block.nodeOffset(inst_data.src_node); |
| 10604 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 10520 | const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0); |
| 10605 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; | 10521 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 10606 | | 10522 | |
| 10607 | const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu_opt, "@bitCast"); | 10523 | const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu_opt, "@bitCast"); |
| ... | @@ -10627,10 +10543,10 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air | ... | @@ -10627,10 +10543,10 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 10627 | | 10543 | |
| 10628 | .Enum => { | 10544 | .Enum => { |
| 10629 | const msg = msg: { | 10545 | const msg = msg: { |
| 10630 | const msg = try sema.errMsg(block, src, "cannot @bitCast to '{}'", .{dest_ty.fmt(mod)}); | 10546 | const msg = try sema.errMsg(src, "cannot @bitCast to '{}'", .{dest_ty.fmt(mod)}); |
| 10631 | errdefer msg.destroy(sema.gpa); | 10547 | errdefer msg.destroy(sema.gpa); |
| 10632 | switch (operand_ty.zigTypeTag(mod)) { | 10548 | switch (operand_ty.zigTypeTag(mod)) { |
| 10633 | .Int, .ComptimeInt => try sema.errNote(block, src, msg, "use @enumFromInt to cast from '{}'", .{operand_ty.fmt(mod)}), | 10549 | .Int, .ComptimeInt => try sema.errNote(src, msg, "use @enumFromInt to cast from '{}'", .{operand_ty.fmt(mod)}), |
| 10634 | else => {}, | 10550 | else => {}, |
| 10635 | } | 10551 | } |
| 10636 | | 10552 | |
| ... | @@ -10641,11 +10557,11 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air | ... | @@ -10641,11 +10557,11 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 10641 | | 10557 | |
| 10642 | .Pointer => { | 10558 | .Pointer => { |
| 10643 | const msg = msg: { | 10559 | const msg = msg: { |
| 10644 | const msg = try sema.errMsg(block, src, "cannot @bitCast to '{}'", .{dest_ty.fmt(mod)}); | 10560 | const msg = try sema.errMsg(src, "cannot @bitCast to '{}'", .{dest_ty.fmt(mod)}); |
| 10645 | errdefer msg.destroy(sema.gpa); | 10561 | errdefer msg.destroy(sema.gpa); |
| 10646 | switch (operand_ty.zigTypeTag(mod)) { | 10562 | switch (operand_ty.zigTypeTag(mod)) { |
| 10647 | .Int, .ComptimeInt => try sema.errNote(block, src, msg, "use @ptrFromInt to cast from '{}'", .{operand_ty.fmt(mod)}), | 10563 | .Int, .ComptimeInt => try sema.errNote(src, msg, "use @ptrFromInt to cast from '{}'", .{operand_ty.fmt(mod)}), |
| 10648 | .Pointer => try sema.errNote(block, src, msg, "use @ptrCast to cast from '{}'", .{operand_ty.fmt(mod)}), | 10564 | .Pointer => try sema.errNote(src, msg, "use @ptrCast to cast from '{}'", .{operand_ty.fmt(mod)}), |
| 10649 | else => {}, | 10565 | else => {}, |
| 10650 | } | 10566 | } |
| 10651 | | 10567 | |
| ... | @@ -10691,10 +10607,10 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air | ... | @@ -10691,10 +10607,10 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 10691 | | 10607 | |
| 10692 | .Enum => { | 10608 | .Enum => { |
| 10693 | const msg = msg: { | 10609 | const msg = msg: { |
| 10694 | const msg = try sema.errMsg(block, operand_src, "cannot @bitCast from '{}'", .{operand_ty.fmt(mod)}); | 10610 | const msg = try sema.errMsg(operand_src, "cannot @bitCast from '{}'", .{operand_ty.fmt(mod)}); |
| 10695 | errdefer msg.destroy(sema.gpa); | 10611 | errdefer msg.destroy(sema.gpa); |
| 10696 | switch (dest_ty.zigTypeTag(mod)) { | 10612 | switch (dest_ty.zigTypeTag(mod)) { |
| 10697 | .Int, .ComptimeInt => try sema.errNote(block, operand_src, msg, "use @intFromEnum to cast to '{}'", .{dest_ty.fmt(mod)}), | 10613 | .Int, .ComptimeInt => try sema.errNote(operand_src, msg, "use @intFromEnum to cast to '{}'", .{dest_ty.fmt(mod)}), |
| 10698 | else => {}, | 10614 | else => {}, |
| 10699 | } | 10615 | } |
| 10700 | | 10616 | |
| ... | @@ -10704,11 +10620,11 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air | ... | @@ -10704,11 +10620,11 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 10704 | }, | 10620 | }, |
| 10705 | .Pointer => { | 10621 | .Pointer => { |
| 10706 | const msg = msg: { | 10622 | const msg = msg: { |
| 10707 | const msg = try sema.errMsg(block, operand_src, "cannot @bitCast from '{}'", .{operand_ty.fmt(mod)}); | 10623 | const msg = try sema.errMsg(operand_src, "cannot @bitCast from '{}'", .{operand_ty.fmt(mod)}); |
| 10708 | errdefer msg.destroy(sema.gpa); | 10624 | errdefer msg.destroy(sema.gpa); |
| 10709 | switch (dest_ty.zigTypeTag(mod)) { | 10625 | switch (dest_ty.zigTypeTag(mod)) { |
| 10710 | .Int, .ComptimeInt => try sema.errNote(block, operand_src, msg, "use @intFromPtr to cast to '{}'", .{dest_ty.fmt(mod)}), | 10626 | .Int, .ComptimeInt => try sema.errNote(operand_src, msg, "use @intFromPtr to cast to '{}'", .{dest_ty.fmt(mod)}), |
| 10711 | .Pointer => try sema.errNote(block, operand_src, msg, "use @ptrCast to cast to '{}'", .{dest_ty.fmt(mod)}), | 10627 | .Pointer => try sema.errNote(operand_src, msg, "use @ptrCast to cast to '{}'", .{dest_ty.fmt(mod)}), |
| 10712 | else => {}, | 10628 | else => {}, |
| 10713 | } | 10629 | } |
| 10714 | | 10630 | |
| ... | @@ -10744,7 +10660,7 @@ fn zirFloatCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A | ... | @@ -10744,7 +10660,7 @@ fn zirFloatCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 10744 | const mod = sema.mod; | 10660 | const mod = sema.mod; |
| 10745 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 10661 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 10746 | const src = block.nodeOffset(inst_data.src_node); | 10662 | const src = block.nodeOffset(inst_data.src_node); |
| 10747 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 10663 | const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0); |
| 10748 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; | 10664 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 10749 | | 10665 | |
| 10750 | const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu_opt, "@floatCast"); | 10666 | const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu_opt, "@floatCast"); |
| ... | @@ -10835,7 +10751,7 @@ fn zirElemValNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError | ... | @@ -10835,7 +10751,7 @@ fn zirElemValNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 10835 | | 10751 | |
| 10836 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 10752 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 10837 | const src = block.nodeOffset(inst_data.src_node); | 10753 | const src = block.nodeOffset(inst_data.src_node); |
| 10838 | const elem_index_src: LazySrcLoc = .{ .node_offset_array_access_index = inst_data.src_node }; | 10754 | const elem_index_src = block.src(.{ .node_offset_array_access_index = inst_data.src_node }); |
| 10839 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; | 10755 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 10840 | const array = try sema.resolveInst(extra.lhs); | 10756 | const array = try sema.resolveInst(extra.lhs); |
| 10841 | const uncoerced_elem_index = try sema.resolveInst(extra.rhs); | 10757 | const uncoerced_elem_index = try sema.resolveInst(extra.rhs); |
| ... | @@ -10851,7 +10767,7 @@ fn zirElemValImm(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! | ... | @@ -10851,7 +10767,7 @@ fn zirElemValImm(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! |
| 10851 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].elem_val_imm; | 10767 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].elem_val_imm; |
| 10852 | const array = try sema.resolveInst(inst_data.operand); | 10768 | const array = try sema.resolveInst(inst_data.operand); |
| 10853 | const elem_index = try mod.intRef(Type.usize, inst_data.idx); | 10769 | const elem_index = try mod.intRef(Type.usize, inst_data.idx); |
| 10854 | return sema.elemVal(block, .unneeded, array, elem_index, .unneeded, false); | 10770 | return sema.elemVal(block, LazySrcLoc.unneeded, array, elem_index, LazySrcLoc.unneeded, false); |
| 10855 | } | 10771 | } |
| 10856 | | 10772 | |
| 10857 | fn zirElemPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 10773 | fn zirElemPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| ... | @@ -10866,14 +10782,14 @@ fn zirElemPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air | ... | @@ -10866,14 +10782,14 @@ fn zirElemPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 10866 | const elem_index = try sema.resolveInst(extra.rhs); | 10782 | const elem_index = try sema.resolveInst(extra.rhs); |
| 10867 | const indexable_ty = sema.typeOf(array_ptr); | 10783 | const indexable_ty = sema.typeOf(array_ptr); |
| 10868 | if (indexable_ty.zigTypeTag(mod) != .Pointer) { | 10784 | if (indexable_ty.zigTypeTag(mod) != .Pointer) { |
| 10869 | const capture_src: LazySrcLoc = .{ .for_capture_from_input = inst_data.src_node }; | 10785 | const capture_src = block.src(.{ .for_capture_from_input = inst_data.src_node }); |
| 10870 | const msg = msg: { | 10786 | const msg = msg: { |
| 10871 | const msg = try sema.errMsg(block, capture_src, "pointer capture of non pointer type '{}'", .{ | 10787 | const msg = try sema.errMsg(capture_src, "pointer capture of non pointer type '{}'", .{ |
| 10872 | indexable_ty.fmt(mod), | 10788 | indexable_ty.fmt(mod), |
| 10873 | }); | 10789 | }); |
| 10874 | errdefer msg.destroy(sema.gpa); | 10790 | errdefer msg.destroy(sema.gpa); |
| 10875 | if (indexable_ty.isIndexable(mod)) { | 10791 | if (indexable_ty.isIndexable(mod)) { |
| 10876 | try sema.errNote(block, src, msg, "consider using '&' here", .{}); | 10792 | try sema.errNote(src, msg, "consider using '&' here", .{}); |
| 10877 | } | 10793 | } |
| 10878 | break :msg msg; | 10794 | break :msg msg; |
| 10879 | }; | 10795 | }; |
| ... | @@ -10888,7 +10804,7 @@ fn zirElemPtrNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError | ... | @@ -10888,7 +10804,7 @@ fn zirElemPtrNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 10888 | | 10804 | |
| 10889 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 10805 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 10890 | const src = block.nodeOffset(inst_data.src_node); | 10806 | const src = block.nodeOffset(inst_data.src_node); |
| 10891 | const elem_index_src: LazySrcLoc = .{ .node_offset_array_access_index = inst_data.src_node }; | 10807 | const elem_index_src = block.src(.{ .node_offset_array_access_index = inst_data.src_node }); |
| 10892 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; | 10808 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 10893 | const array_ptr = try sema.resolveInst(extra.lhs); | 10809 | const array_ptr = try sema.resolveInst(extra.lhs); |
| 10894 | const uncoerced_elem_index = try sema.resolveInst(extra.rhs); | 10810 | const uncoerced_elem_index = try sema.resolveInst(extra.rhs); |
| ... | @@ -10925,11 +10841,11 @@ fn zirSliceStart(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! | ... | @@ -10925,11 +10841,11 @@ fn zirSliceStart(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! |
| 10925 | const extra = sema.code.extraData(Zir.Inst.SliceStart, inst_data.payload_index).data; | 10841 | const extra = sema.code.extraData(Zir.Inst.SliceStart, inst_data.payload_index).data; |
| 10926 | const array_ptr = try sema.resolveInst(extra.lhs); | 10842 | const array_ptr = try sema.resolveInst(extra.lhs); |
| 10927 | const start = try sema.resolveInst(extra.start); | 10843 | const start = try sema.resolveInst(extra.start); |
| 10928 | const ptr_src: LazySrcLoc = .{ .node_offset_slice_ptr = inst_data.src_node }; | 10844 | const ptr_src = block.src(.{ .node_offset_slice_ptr = inst_data.src_node }); |
| 10929 | const start_src: LazySrcLoc = .{ .node_offset_slice_start = inst_data.src_node }; | 10845 | const start_src = block.src(.{ .node_offset_slice_start = inst_data.src_node }); |
| 10930 | const end_src: LazySrcLoc = .{ .node_offset_slice_end = inst_data.src_node }; | 10846 | const end_src = block.src(.{ .node_offset_slice_end = inst_data.src_node }); |
| 10931 | | 10847 | |
| 10932 | return sema.analyzeSlice(block, src, array_ptr, start, .none, .none, .unneeded, ptr_src, start_src, end_src, false); | 10848 | return sema.analyzeSlice(block, src, array_ptr, start, .none, .none, LazySrcLoc.unneeded, ptr_src, start_src, end_src, false); |
| 10933 | } | 10849 | } |
| 10934 | | 10850 | |
| 10935 | fn zirSliceEnd(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 10851 | fn zirSliceEnd(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| ... | @@ -10942,11 +10858,11 @@ fn zirSliceEnd(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -10942,11 +10858,11 @@ fn zirSliceEnd(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 10942 | const array_ptr = try sema.resolveInst(extra.lhs); | 10858 | const array_ptr = try sema.resolveInst(extra.lhs); |
| 10943 | const start = try sema.resolveInst(extra.start); | 10859 | const start = try sema.resolveInst(extra.start); |
| 10944 | const end = try sema.resolveInst(extra.end); | 10860 | const end = try sema.resolveInst(extra.end); |
| 10945 | const ptr_src: LazySrcLoc = .{ .node_offset_slice_ptr = inst_data.src_node }; | 10861 | const ptr_src = block.src(.{ .node_offset_slice_ptr = inst_data.src_node }); |
| 10946 | const start_src: LazySrcLoc = .{ .node_offset_slice_start = inst_data.src_node }; | 10862 | const start_src = block.src(.{ .node_offset_slice_start = inst_data.src_node }); |
| 10947 | const end_src: LazySrcLoc = .{ .node_offset_slice_end = inst_data.src_node }; | 10863 | const end_src = block.src(.{ .node_offset_slice_end = inst_data.src_node }); |
| 10948 | | 10864 | |
| 10949 | return sema.analyzeSlice(block, src, array_ptr, start, end, .none, .unneeded, ptr_src, start_src, end_src, false); | 10865 | return sema.analyzeSlice(block, src, array_ptr, start, end, .none, LazySrcLoc.unneeded, ptr_src, start_src, end_src, false); |
| 10950 | } | 10866 | } |
| 10951 | | 10867 | |
| 10952 | fn zirSliceSentinel(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 10868 | fn zirSliceSentinel(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| ... | @@ -10955,15 +10871,15 @@ fn zirSliceSentinel(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr | ... | @@ -10955,15 +10871,15 @@ fn zirSliceSentinel(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr |
| 10955 | | 10871 | |
| 10956 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 10872 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 10957 | const src = block.nodeOffset(inst_data.src_node); | 10873 | const src = block.nodeOffset(inst_data.src_node); |
| 10958 | const sentinel_src: LazySrcLoc = .{ .node_offset_slice_sentinel = inst_data.src_node }; | 10874 | const sentinel_src = block.src(.{ .node_offset_slice_sentinel = inst_data.src_node }); |
| 10959 | const extra = sema.code.extraData(Zir.Inst.SliceSentinel, inst_data.payload_index).data; | 10875 | const extra = sema.code.extraData(Zir.Inst.SliceSentinel, inst_data.payload_index).data; |
| 10960 | const array_ptr = try sema.resolveInst(extra.lhs); | 10876 | const array_ptr = try sema.resolveInst(extra.lhs); |
| 10961 | const start = try sema.resolveInst(extra.start); | 10877 | const start = try sema.resolveInst(extra.start); |
| 10962 | const end: Air.Inst.Ref = if (extra.end == .none) .none else try sema.resolveInst(extra.end); | 10878 | const end: Air.Inst.Ref = if (extra.end == .none) .none else try sema.resolveInst(extra.end); |
| 10963 | const sentinel = try sema.resolveInst(extra.sentinel); | 10879 | const sentinel = try sema.resolveInst(extra.sentinel); |
| 10964 | const ptr_src: LazySrcLoc = .{ .node_offset_slice_ptr = inst_data.src_node }; | 10880 | const ptr_src = block.src(.{ .node_offset_slice_ptr = inst_data.src_node }); |
| 10965 | const start_src: LazySrcLoc = .{ .node_offset_slice_start = inst_data.src_node }; | 10881 | const start_src = block.src(.{ .node_offset_slice_start = inst_data.src_node }); |
| 10966 | const end_src: LazySrcLoc = .{ .node_offset_slice_end = inst_data.src_node }; | 10882 | const end_src = block.src(.{ .node_offset_slice_end = inst_data.src_node }); |
| 10967 | | 10883 | |
| 10968 | return sema.analyzeSlice(block, src, array_ptr, start, end, sentinel, sentinel_src, ptr_src, start_src, end_src, false); | 10884 | return sema.analyzeSlice(block, src, array_ptr, start, end, sentinel, sentinel_src, ptr_src, start_src, end_src, false); |
| 10969 | } | 10885 | } |
| ... | @@ -10979,13 +10895,13 @@ fn zirSliceLength(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError | ... | @@ -10979,13 +10895,13 @@ fn zirSliceLength(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 10979 | const start = try sema.resolveInst(extra.start); | 10895 | const start = try sema.resolveInst(extra.start); |
| 10980 | const len = try sema.resolveInst(extra.len); | 10896 | const len = try sema.resolveInst(extra.len); |
| 10981 | const sentinel = if (extra.sentinel == .none) .none else try sema.resolveInst(extra.sentinel); | 10897 | const sentinel = if (extra.sentinel == .none) .none else try sema.resolveInst(extra.sentinel); |
| 10982 | const ptr_src: LazySrcLoc = .{ .node_offset_slice_ptr = inst_data.src_node }; | 10898 | const ptr_src = block.src(.{ .node_offset_slice_ptr = inst_data.src_node }); |
| 10983 | const start_src: LazySrcLoc = .{ .node_offset_slice_start = extra.start_src_node_offset }; | 10899 | const start_src = block.src(.{ .node_offset_slice_start = extra.start_src_node_offset }); |
| 10984 | const end_src: LazySrcLoc = .{ .node_offset_slice_end = inst_data.src_node }; | 10900 | const end_src = block.src(.{ .node_offset_slice_end = inst_data.src_node }); |
| 10985 | const sentinel_src: LazySrcLoc = if (sentinel == .none) | 10901 | const sentinel_src: LazySrcLoc = if (sentinel == .none) |
| 10986 | .unneeded | 10902 | LazySrcLoc.unneeded |
| 10987 | else | 10903 | else |
| 10988 | .{ .node_offset_slice_sentinel = inst_data.src_node }; | 10904 | block.src(.{ .node_offset_slice_sentinel = inst_data.src_node }); |
| 10989 | | 10905 | |
| 10990 | return sema.analyzeSlice(block, src, array_ptr, start, len, sentinel, sentinel_src, ptr_src, start_src, end_src, true); | 10906 | return sema.analyzeSlice(block, src, array_ptr, start, len, sentinel, sentinel_src, ptr_src, start_src, end_src, true); |
| 10991 | } | 10907 | } |
| ... | @@ -11019,8 +10935,8 @@ const SwitchProngAnalysis = struct { | ... | @@ -11019,8 +10935,8 @@ const SwitchProngAnalysis = struct { |
| 11019 | prong_type: enum { normal, special }, | 10935 | prong_type: enum { normal, special }, |
| 11020 | prong_body: []const Zir.Inst.Index, | 10936 | prong_body: []const Zir.Inst.Index, |
| 11021 | capture: Zir.Inst.SwitchBlock.ProngInfo.Capture, | 10937 | capture: Zir.Inst.SwitchBlock.ProngInfo.Capture, |
| 11022 | /// Must use the `scalar_capture`, `special_capture`, or `multi_capture` union field. | 10938 | /// Must use the `switch_capture` field in `offset`. |
| 11023 | raw_capture_src: Module.SwitchProngSrc, | 10939 | capture_src: LazySrcLoc, |
| 11024 | /// The set of all values which can reach this prong. May be undefined | 10940 | /// The set of all values which can reach this prong. May be undefined |
| 11025 | /// if the prong is special or contains ranges. | 10941 | /// if the prong is special or contains ranges. |
| 11026 | case_vals: []const Air.Inst.Ref, | 10942 | case_vals: []const Air.Inst.Ref, |
| ... | @@ -11038,7 +10954,7 @@ const SwitchProngAnalysis = struct { | ... | @@ -11038,7 +10954,7 @@ const SwitchProngAnalysis = struct { |
| 11038 | ); | 10954 | ); |
| 11039 | | 10955 | |
| 11040 | if (has_tag_capture) { | 10956 | if (has_tag_capture) { |
| 11041 | const tag_ref = try spa.analyzeTagCapture(child_block, raw_capture_src, inline_case_capture); | 10957 | const tag_ref = try spa.analyzeTagCapture(child_block, capture_src, inline_case_capture); |
| 11042 | sema.inst_map.putAssumeCapacity(spa.tag_capture_inst, tag_ref); | 10958 | sema.inst_map.putAssumeCapacity(spa.tag_capture_inst, tag_ref); |
| 11043 | } | 10959 | } |
| 11044 | defer if (has_tag_capture) assert(sema.inst_map.remove(spa.tag_capture_inst)); | 10960 | defer if (has_tag_capture) assert(sema.inst_map.remove(spa.tag_capture_inst)); |
| ... | @@ -11053,7 +10969,7 @@ const SwitchProngAnalysis = struct { | ... | @@ -11053,7 +10969,7 @@ const SwitchProngAnalysis = struct { |
| 11053 | child_block, | 10969 | child_block, |
| 11054 | capture == .by_ref, | 10970 | capture == .by_ref, |
| 11055 | prong_type == .special, | 10971 | prong_type == .special, |
| 11056 | raw_capture_src, | 10972 | capture_src, |
| 11057 | case_vals, | 10973 | case_vals, |
| 11058 | inline_case_capture, | 10974 | inline_case_capture, |
| 11059 | ); | 10975 | ); |
| ... | @@ -11079,8 +10995,8 @@ const SwitchProngAnalysis = struct { | ... | @@ -11079,8 +10995,8 @@ const SwitchProngAnalysis = struct { |
| 11079 | prong_type: enum { normal, special }, | 10995 | prong_type: enum { normal, special }, |
| 11080 | prong_body: []const Zir.Inst.Index, | 10996 | prong_body: []const Zir.Inst.Index, |
| 11081 | capture: Zir.Inst.SwitchBlock.ProngInfo.Capture, | 10997 | capture: Zir.Inst.SwitchBlock.ProngInfo.Capture, |
| 11082 | /// Must use the `scalar`, `special`, or `multi_capture` union field. | 10998 | /// Must use the `switch_capture` field in `offset`. |
| 11083 | raw_capture_src: Module.SwitchProngSrc, | 10999 | capture_src: LazySrcLoc, |
| 11084 | /// The set of all values which can reach this prong. May be undefined | 11000 | /// The set of all values which can reach this prong. May be undefined |
| 11085 | /// if the prong is special or contains ranges. | 11001 | /// if the prong is special or contains ranges. |
| 11086 | case_vals: []const Air.Inst.Ref, | 11002 | case_vals: []const Air.Inst.Ref, |
| ... | @@ -11094,7 +11010,7 @@ const SwitchProngAnalysis = struct { | ... | @@ -11094,7 +11010,7 @@ const SwitchProngAnalysis = struct { |
| 11094 | const sema = spa.sema; | 11010 | const sema = spa.sema; |
| 11095 | | 11011 | |
| 11096 | if (has_tag_capture) { | 11012 | if (has_tag_capture) { |
| 11097 | const tag_ref = try spa.analyzeTagCapture(case_block, raw_capture_src, inline_case_capture); | 11013 | const tag_ref = try spa.analyzeTagCapture(case_block, capture_src, inline_case_capture); |
| 11098 | sema.inst_map.putAssumeCapacity(spa.tag_capture_inst, tag_ref); | 11014 | sema.inst_map.putAssumeCapacity(spa.tag_capture_inst, tag_ref); |
| 11099 | } | 11015 | } |
| 11100 | defer if (has_tag_capture) assert(sema.inst_map.remove(spa.tag_capture_inst)); | 11016 | defer if (has_tag_capture) assert(sema.inst_map.remove(spa.tag_capture_inst)); |
| ... | @@ -11109,7 +11025,7 @@ const SwitchProngAnalysis = struct { | ... | @@ -11109,7 +11025,7 @@ const SwitchProngAnalysis = struct { |
| 11109 | case_block, | 11025 | case_block, |
| 11110 | capture == .by_ref, | 11026 | capture == .by_ref, |
| 11111 | prong_type == .special, | 11027 | prong_type == .special, |
| 11112 | raw_capture_src, | 11028 | capture_src, |
| 11113 | case_vals, | 11029 | case_vals, |
| 11114 | inline_case_capture, | 11030 | inline_case_capture, |
| 11115 | ); | 11031 | ); |
| ... | @@ -11130,23 +11046,18 @@ const SwitchProngAnalysis = struct { | ... | @@ -11130,23 +11046,18 @@ const SwitchProngAnalysis = struct { |
| 11130 | fn analyzeTagCapture( | 11046 | fn analyzeTagCapture( |
| 11131 | spa: SwitchProngAnalysis, | 11047 | spa: SwitchProngAnalysis, |
| 11132 | block: *Block, | 11048 | block: *Block, |
| 11133 | raw_capture_src: Module.SwitchProngSrc, | 11049 | capture_src: LazySrcLoc, |
| 11134 | inline_case_capture: Air.Inst.Ref, | 11050 | inline_case_capture: Air.Inst.Ref, |
| 11135 | ) CompileError!Air.Inst.Ref { | 11051 | ) CompileError!Air.Inst.Ref { |
| 11136 | const sema = spa.sema; | 11052 | const sema = spa.sema; |
| 11137 | const mod = sema.mod; | 11053 | const mod = sema.mod; |
| 11138 | const operand_ty = sema.typeOf(spa.operand); | 11054 | const operand_ty = sema.typeOf(spa.operand); |
| 11139 | if (operand_ty.zigTypeTag(mod) != .Union) { | 11055 | if (operand_ty.zigTypeTag(mod) != .Union) { |
| 11140 | const zir_datas = sema.code.instructions.items(.data); | 11056 | const tag_capture_src: LazySrcLoc = .{ |
| 11141 | const switch_node_offset = zir_datas[@intFromEnum(spa.switch_block_inst)].pl_node.src_node; | 11057 | .base_node_inst = capture_src.base_node_inst, |
| 11142 | const raw_tag_capture_src: Module.SwitchProngSrc = switch (raw_capture_src) { | 11058 | .offset = .{ .switch_tag_capture = capture_src.offset.switch_capture }, |
| 11143 | .scalar_capture => |i| .{ .scalar_tag_capture = i }, | | |
| 11144 | .multi_capture => |i| .{ .multi_tag_capture = i }, | | |
| 11145 | .special_capture => .special_tag_capture, | | |
| 11146 | else => unreachable, | | |
| 11147 | }; | 11059 | }; |
| 11148 | const capture_src = raw_tag_capture_src.resolve(mod, mod.declPtr(block.src_decl), switch_node_offset, .none); | 11060 | return sema.fail(block, tag_capture_src, "cannot capture tag of non-union type '{}'", .{ |
| 11149 | return sema.fail(block, capture_src, "cannot capture tag of non-union type '{}'", .{ | | |
| 11150 | operand_ty.fmt(mod), | 11061 | operand_ty.fmt(mod), |
| 11151 | }); | 11062 | }); |
| 11152 | } | 11063 | } |
| ... | @@ -11159,7 +11070,7 @@ const SwitchProngAnalysis = struct { | ... | @@ -11159,7 +11070,7 @@ const SwitchProngAnalysis = struct { |
| 11159 | block: *Block, | 11070 | block: *Block, |
| 11160 | capture_byref: bool, | 11071 | capture_byref: bool, |
| 11161 | is_special_prong: bool, | 11072 | is_special_prong: bool, |
| 11162 | raw_capture_src: Module.SwitchProngSrc, | 11073 | capture_src: LazySrcLoc, |
| 11163 | case_vals: []const Air.Inst.Ref, | 11074 | case_vals: []const Air.Inst.Ref, |
| 11164 | inline_case_capture: Air.Inst.Ref, | 11075 | inline_case_capture: Air.Inst.Ref, |
| 11165 | ) CompileError!Air.Inst.Ref { | 11076 | ) CompileError!Air.Inst.Ref { |
| ... | @@ -11172,10 +11083,10 @@ const SwitchProngAnalysis = struct { | ... | @@ -11172,10 +11083,10 @@ const SwitchProngAnalysis = struct { |
| 11172 | | 11083 | |
| 11173 | const operand_ty = sema.typeOf(spa.operand); | 11084 | const operand_ty = sema.typeOf(spa.operand); |
| 11174 | const operand_ptr_ty = if (capture_byref) sema.typeOf(spa.operand_ptr) else undefined; | 11085 | const operand_ptr_ty = if (capture_byref) sema.typeOf(spa.operand_ptr) else undefined; |
| 11175 | const operand_src: LazySrcLoc = .{ .node_offset_switch_operand = switch_node_offset }; | 11086 | const operand_src = block.src(.{ .node_offset_switch_operand = switch_node_offset }); |
| 11176 | | 11087 | |
| 11177 | if (inline_case_capture != .none) { | 11088 | if (inline_case_capture != .none) { |
| 11178 | const item_val = sema.resolveConstDefinedValue(block, .unneeded, inline_case_capture, undefined) catch unreachable; | 11089 | const item_val = sema.resolveConstDefinedValue(block, LazySrcLoc.unneeded, inline_case_capture, undefined) catch unreachable; |
| 11179 | if (operand_ty.zigTypeTag(zcu) == .Union) { | 11090 | if (operand_ty.zigTypeTag(zcu) == .Union) { |
| 11180 | const field_index: u32 = @intCast(operand_ty.unionTagFieldIndex(item_val, zcu).?); | 11091 | const field_index: u32 = @intCast(operand_ty.unionTagFieldIndex(item_val, zcu).?); |
| 11181 | const union_obj = zcu.typeToUnion(operand_ty).?; | 11092 | const union_obj = zcu.typeToUnion(operand_ty).?; |
| ... | @@ -11216,7 +11127,7 @@ const SwitchProngAnalysis = struct { | ... | @@ -11216,7 +11127,7 @@ const SwitchProngAnalysis = struct { |
| 11216 | .ErrorSet => if (spa.else_error_ty) |ty| { | 11127 | .ErrorSet => if (spa.else_error_ty) |ty| { |
| 11217 | return sema.bitCast(block, ty, spa.operand, operand_src, null); | 11128 | return sema.bitCast(block, ty, spa.operand, operand_src, null); |
| 11218 | } else { | 11129 | } else { |
| 11219 | try block.addUnreachable(operand_src, false); | 11130 | try sema.analyzeUnreachable(block, operand_src, false); |
| 11220 | return .unreachable_value; | 11131 | return .unreachable_value; |
| 11221 | }, | 11132 | }, |
| 11222 | else => return spa.operand, | 11133 | else => return spa.operand, |
| ... | @@ -11226,14 +11137,14 @@ const SwitchProngAnalysis = struct { | ... | @@ -11226,14 +11137,14 @@ const SwitchProngAnalysis = struct { |
| 11226 | switch (operand_ty.zigTypeTag(zcu)) { | 11137 | switch (operand_ty.zigTypeTag(zcu)) { |
| 11227 | .Union => { | 11138 | .Union => { |
| 11228 | const union_obj = zcu.typeToUnion(operand_ty).?; | 11139 | const union_obj = zcu.typeToUnion(operand_ty).?; |
| 11229 | const first_item_val = sema.resolveConstDefinedValue(block, .unneeded, case_vals[0], undefined) catch unreachable; | 11140 | const first_item_val = sema.resolveConstDefinedValue(block, LazySrcLoc.unneeded, case_vals[0], undefined) catch unreachable; |
| 11230 | | 11141 | |
| 11231 | const first_field_index: u32 = zcu.unionTagFieldIndex(union_obj, first_item_val).?; | 11142 | const first_field_index: u32 = zcu.unionTagFieldIndex(union_obj, first_item_val).?; |
| 11232 | const first_field_ty = Type.fromInterned(union_obj.field_types.get(ip)[first_field_index]); | 11143 | const first_field_ty = Type.fromInterned(union_obj.field_types.get(ip)[first_field_index]); |
| 11233 | | 11144 | |
| 11234 | const field_indices = try sema.arena.alloc(u32, case_vals.len); | 11145 | const field_indices = try sema.arena.alloc(u32, case_vals.len); |
| 11235 | for (case_vals, field_indices) |item, *field_idx| { | 11146 | for (case_vals, field_indices) |item, *field_idx| { |
| 11236 | const item_val = sema.resolveConstDefinedValue(block, .unneeded, item, undefined) catch unreachable; | 11147 | const item_val = sema.resolveConstDefinedValue(block, LazySrcLoc.unneeded, item, undefined) catch unreachable; |
| 11237 | field_idx.* = zcu.unionTagFieldIndex(union_obj, item_val).?; | 11148 | field_idx.* = zcu.unionTagFieldIndex(union_obj, item_val).?; |
| 11238 | } | 11149 | } |
| 11239 | | 11150 | |
| ... | @@ -11253,27 +11164,22 @@ const SwitchProngAnalysis = struct { | ... | @@ -11253,27 +11164,22 @@ const SwitchProngAnalysis = struct { |
| 11253 | } | 11164 | } |
| 11254 | | 11165 | |
| 11255 | const case_srcs = try sema.arena.alloc(?LazySrcLoc, case_vals.len); | 11166 | const case_srcs = try sema.arena.alloc(?LazySrcLoc, case_vals.len); |
| 11256 | @memset(case_srcs, .unneeded); | 11167 | for (case_srcs, 0..) |*case_src, i| { |
| 11257 | | 11168 | case_src.* = .{ |
| 11258 | break :capture_ty sema.resolvePeerTypes(block, .unneeded, dummy_captures, .{ .override = case_srcs }) catch |err| switch (err) { | 11169 | .base_node_inst = capture_src.base_node_inst, |
| 11259 | error.NeededSourceLocation => { | 11170 | .offset = .{ .switch_case_item = .{ |
| 11260 | // This must be a multi-prong so this must be a `multi_capture` src | 11171 | .switch_node_offset = switch_node_offset, |
| 11261 | const multi_idx = raw_capture_src.multi_capture; | 11172 | .case_idx = capture_src.offset.switch_capture.case_idx, |
| 11262 | const src_decl_ptr = zcu.declPtr(block.src_decl); | 11173 | .item_idx = .{ .kind = .single, .index = @intCast(i) }, |
| 11263 | for (case_srcs, 0..) |*case_src, i| { | 11174 | } }, |
| 11264 | const raw_case_src: Module.SwitchProngSrc = .{ .multi = .{ .prong = multi_idx, .item = @intCast(i) } }; | 11175 | }; |
| 11265 | case_src.* = raw_case_src.resolve(zcu, src_decl_ptr, switch_node_offset, .none); | 11176 | } |
| 11266 | } | 11177 | |
| 11267 | const capture_src = raw_capture_src.resolve(zcu, src_decl_ptr, switch_node_offset, .none); | 11178 | break :capture_ty sema.resolvePeerTypes(block, capture_src, dummy_captures, .{ .override = case_srcs }) catch |err| switch (err) { |
| 11268 | _ = sema.resolvePeerTypes(block, capture_src, dummy_captures, .{ .override = case_srcs }) catch |err1| switch (err1) { | 11179 | error.AnalysisFail => { |
| 11269 | error.AnalysisFail => { | 11180 | const msg = sema.err orelse return error.AnalysisFail; |
| 11270 | const msg = sema.err orelse return error.AnalysisFail; | 11181 | try sema.reparentOwnedErrorMsg(capture_src, msg, "capture group with incompatible types", .{}); |
| 11271 | try sema.reparentOwnedErrorMsg(block, capture_src, msg, "capture group with incompatible types", .{}); | 11182 | return error.AnalysisFail; |
| 11272 | return error.AnalysisFail; | | |
| 11273 | }, | | |
| 11274 | else => |e| return e, | | |
| 11275 | }; | | |
| 11276 | unreachable; | | |
| 11277 | }, | 11183 | }, |
| 11278 | else => |e| return e, | 11184 | else => |e| return e, |
| 11279 | }; | 11185 | }; |
| ... | @@ -11301,28 +11207,23 @@ const SwitchProngAnalysis = struct { | ... | @@ -11301,28 +11207,23 @@ const SwitchProngAnalysis = struct { |
| 11301 | dummy.* = try zcu.undefRef(field_ptr_ty); | 11207 | dummy.* = try zcu.undefRef(field_ptr_ty); |
| 11302 | } | 11208 | } |
| 11303 | const case_srcs = try sema.arena.alloc(?LazySrcLoc, case_vals.len); | 11209 | const case_srcs = try sema.arena.alloc(?LazySrcLoc, case_vals.len); |
| 11304 | @memset(case_srcs, .unneeded); | 11210 | for (case_srcs, 0..) |*case_src, i| { |
| 11305 | | 11211 | case_src.* = .{ |
| 11306 | break :resolve sema.resolvePeerTypes(block, .unneeded, dummy_captures, .{ .override = case_srcs }) catch |err| switch (err) { | 11212 | .base_node_inst = capture_src.base_node_inst, |
| 11307 | error.NeededSourceLocation => { | 11213 | .offset = .{ .switch_case_item = .{ |
| 11308 | // This must be a multi-prong so this must be a `multi_capture` src | 11214 | .switch_node_offset = switch_node_offset, |
| 11309 | const multi_idx = raw_capture_src.multi_capture; | 11215 | .case_idx = capture_src.offset.switch_capture.case_idx, |
| 11310 | const src_decl_ptr = zcu.declPtr(block.src_decl); | 11216 | .item_idx = .{ .kind = .single, .index = @intCast(i) }, |
| 11311 | for (case_srcs, 0..) |*case_src, i| { | 11217 | } }, |
| 11312 | const raw_case_src: Module.SwitchProngSrc = .{ .multi = .{ .prong = multi_idx, .item = @intCast(i) } }; | 11218 | }; |
| 11313 | case_src.* = raw_case_src.resolve(zcu, src_decl_ptr, switch_node_offset, .none); | 11219 | } |
| 11314 | } | 11220 | |
| 11315 | const capture_src = raw_capture_src.resolve(zcu, src_decl_ptr, switch_node_offset, .none); | 11221 | break :resolve sema.resolvePeerTypes(block, capture_src, dummy_captures, .{ .override = case_srcs }) catch |err| switch (err) { |
| 11316 | _ = sema.resolvePeerTypes(block, capture_src, dummy_captures, .{ .override = case_srcs }) catch |err1| switch (err1) { | 11222 | error.AnalysisFail => { |
| 11317 | error.AnalysisFail => { | 11223 | const msg = sema.err orelse return error.AnalysisFail; |
| 11318 | const msg = sema.err orelse return error.AnalysisFail; | 11224 | try sema.errNote(capture_src, msg, "this coercion is only possible when capturing by value", .{}); |
| 11319 | try sema.errNote(block, capture_src, msg, "this coercion is only possible when capturing by value", .{}); | 11225 | try sema.reparentOwnedErrorMsg(capture_src, msg, "capture group with incompatible types", .{}); |
| 11320 | try sema.reparentOwnedErrorMsg(block, capture_src, msg, "capture group with incompatible types", .{}); | 11226 | return error.AnalysisFail; |
| 11321 | return error.AnalysisFail; | | |
| 11322 | }, | | |
| 11323 | else => |e| return e, | | |
| 11324 | }; | | |
| 11325 | unreachable; | | |
| 11326 | }, | 11227 | }, |
| 11327 | else => |e| return e, | 11228 | else => |e| return e, |
| 11328 | }; | 11229 | }; |
| ... | @@ -11357,7 +11258,7 @@ const SwitchProngAnalysis = struct { | ... | @@ -11357,7 +11258,7 @@ const SwitchProngAnalysis = struct { |
| 11357 | const first_non_imc = in_mem: { | 11258 | const first_non_imc = in_mem: { |
| 11358 | for (field_indices, 0..) |field_idx, i| { | 11259 | for (field_indices, 0..) |field_idx, i| { |
| 11359 | const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[field_idx]); | 11260 | const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[field_idx]); |
| 11360 | if (.ok != try sema.coerceInMemoryAllowed(block, capture_ty, field_ty, false, zcu.getTarget(), .unneeded, .unneeded)) { | 11261 | if (.ok != try sema.coerceInMemoryAllowed(block, capture_ty, field_ty, false, zcu.getTarget(), LazySrcLoc.unneeded, LazySrcLoc.unneeded)) { |
| 11361 | break :in_mem i; | 11262 | break :in_mem i; |
| 11362 | } | 11263 | } |
| 11363 | } | 11264 | } |
| ... | @@ -11380,7 +11281,7 @@ const SwitchProngAnalysis = struct { | ... | @@ -11380,7 +11281,7 @@ const SwitchProngAnalysis = struct { |
| 11380 | const next = first_non_imc + 1; | 11281 | const next = first_non_imc + 1; |
| 11381 | for (field_indices[next..], next..) |field_idx, i| { | 11282 | for (field_indices[next..], next..) |field_idx, i| { |
| 11382 | const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[field_idx]); | 11283 | const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[field_idx]); |
| 11383 | if (.ok != try sema.coerceInMemoryAllowed(block, capture_ty, field_ty, false, zcu.getTarget(), .unneeded, .unneeded)) { | 11284 | if (.ok != try sema.coerceInMemoryAllowed(block, capture_ty, field_ty, false, zcu.getTarget(), LazySrcLoc.unneeded, LazySrcLoc.unneeded)) { |
| 11384 | in_mem_coercible.unset(i); | 11285 | in_mem_coercible.unset(i); |
| 11385 | } | 11286 | } |
| 11386 | } | 11287 | } |
| ... | @@ -11409,20 +11310,19 @@ const SwitchProngAnalysis = struct { | ... | @@ -11409,20 +11310,19 @@ const SwitchProngAnalysis = struct { |
| 11409 | var coerce_block = block.makeSubBlock(); | 11310 | var coerce_block = block.makeSubBlock(); |
| 11410 | defer coerce_block.instructions.deinit(sema.gpa); | 11311 | defer coerce_block.instructions.deinit(sema.gpa); |
| 11411 | | 11312 | |
| | 11313 | const case_src: LazySrcLoc = .{ |
| | 11314 | .base_node_inst = capture_src.base_node_inst, |
| | 11315 | .offset = .{ .switch_case_item = .{ |
| | 11316 | .switch_node_offset = switch_node_offset, |
| | 11317 | .case_idx = capture_src.offset.switch_capture.case_idx, |
| | 11318 | .item_idx = .{ .kind = .single, .index = @intCast(idx) }, |
| | 11319 | } }, |
| | 11320 | }; |
| | 11321 | |
| 11412 | const field_idx = field_indices[idx]; | 11322 | const field_idx = field_indices[idx]; |
| 11413 | const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[field_idx]); | 11323 | const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[field_idx]); |
| 11414 | const uncoerced = try coerce_block.addStructFieldVal(spa.operand, field_idx, field_ty); | 11324 | const uncoerced = try coerce_block.addStructFieldVal(spa.operand, field_idx, field_ty); |
| 11415 | const coerced = sema.coerce(&coerce_block, capture_ty, uncoerced, .unneeded) catch |err| switch (err) { | 11325 | const coerced = try sema.coerce(&coerce_block, capture_ty, uncoerced, case_src); |
| 11416 | error.NeededSourceLocation => { | | |
| 11417 | const multi_idx = raw_capture_src.multi_capture; | | |
| 11418 | const src_decl_ptr = zcu.declPtr(block.src_decl); | | |
| 11419 | const raw_case_src: Module.SwitchProngSrc = .{ .multi = .{ .prong = multi_idx, .item = @intCast(idx) } }; | | |
| 11420 | const case_src = raw_case_src.resolve(zcu, src_decl_ptr, switch_node_offset, .none); | | |
| 11421 | _ = try sema.coerce(&coerce_block, capture_ty, uncoerced, case_src); | | |
| 11422 | unreachable; | | |
| 11423 | }, | | |
| 11424 | else => |e| return e, | | |
| 11425 | }; | | |
| 11426 | _ = try coerce_block.addBr(capture_block_inst, coerced); | 11326 | _ = try coerce_block.addBr(capture_block_inst, coerced); |
| 11427 | | 11327 | |
| 11428 | try cases_extra.ensureUnusedCapacity(3 + coerce_block.instructions.items.len); | 11328 | try cases_extra.ensureUnusedCapacity(3 + coerce_block.instructions.items.len); |
| ... | @@ -11476,7 +11376,6 @@ const SwitchProngAnalysis = struct { | ... | @@ -11476,7 +11376,6 @@ const SwitchProngAnalysis = struct { |
| 11476 | }, | 11376 | }, |
| 11477 | .ErrorSet => { | 11377 | .ErrorSet => { |
| 11478 | if (capture_byref) { | 11378 | if (capture_byref) { |
| 11479 | const capture_src = raw_capture_src.resolve(zcu, zcu.declPtr(block.src_decl), switch_node_offset, .none); | | |
| 11480 | return sema.fail( | 11379 | return sema.fail( |
| 11481 | block, | 11380 | block, |
| 11482 | capture_src, | 11381 | capture_src, |
| ... | @@ -11486,7 +11385,7 @@ const SwitchProngAnalysis = struct { | ... | @@ -11486,7 +11385,7 @@ const SwitchProngAnalysis = struct { |
| 11486 | } | 11385 | } |
| 11487 | | 11386 | |
| 11488 | if (case_vals.len == 1) { | 11387 | if (case_vals.len == 1) { |
| 11489 | const item_val = sema.resolveConstDefinedValue(block, .unneeded, case_vals[0], undefined) catch unreachable; | 11388 | const item_val = sema.resolveConstDefinedValue(block, LazySrcLoc.unneeded, case_vals[0], undefined) catch unreachable; |
| 11490 | const item_ty = try zcu.singleErrorSetType(item_val.getErrorName(zcu).unwrap().?); | 11389 | const item_ty = try zcu.singleErrorSetType(item_val.getErrorName(zcu).unwrap().?); |
| 11491 | return sema.bitCast(block, item_ty, spa.operand, operand_src, null); | 11390 | return sema.bitCast(block, item_ty, spa.operand, operand_src, null); |
| 11492 | } | 11391 | } |
| ... | @@ -11494,7 +11393,7 @@ const SwitchProngAnalysis = struct { | ... | @@ -11494,7 +11393,7 @@ const SwitchProngAnalysis = struct { |
| 11494 | var names: InferredErrorSet.NameMap = .{}; | 11393 | var names: InferredErrorSet.NameMap = .{}; |
| 11495 | try names.ensureUnusedCapacity(sema.arena, case_vals.len); | 11394 | try names.ensureUnusedCapacity(sema.arena, case_vals.len); |
| 11496 | for (case_vals) |err| { | 11395 | for (case_vals) |err| { |
| 11497 | const err_val = sema.resolveConstDefinedValue(block, .unneeded, err, undefined) catch unreachable; | 11396 | const err_val = sema.resolveConstDefinedValue(block, LazySrcLoc.unneeded, err, undefined) catch unreachable; |
| 11498 | names.putAssumeCapacityNoClobber(err_val.getErrorName(zcu).unwrap().?, {}); | 11397 | names.putAssumeCapacityNoClobber(err_val.getErrorName(zcu).unwrap().?, {}); |
| 11499 | } | 11398 | } |
| 11500 | const error_ty = try zcu.errorSetFromUnsortedNames(names.keys()); | 11399 | const error_ty = try zcu.errorSetFromUnsortedNames(names.keys()); |
| ... | @@ -11548,10 +11447,10 @@ fn switchCond( | ... | @@ -11548,10 +11447,10 @@ fn switchCond( |
| 11548 | try sema.resolveTypeFields(operand_ty); | 11447 | try sema.resolveTypeFields(operand_ty); |
| 11549 | const enum_ty = operand_ty.unionTagType(mod) orelse { | 11448 | const enum_ty = operand_ty.unionTagType(mod) orelse { |
| 11550 | const msg = msg: { | 11449 | const msg = msg: { |
| 11551 | const msg = try sema.errMsg(block, src, "switch on union with no attached enum", .{}); | 11450 | const msg = try sema.errMsg(src, "switch on union with no attached enum", .{}); |
| 11552 | errdefer msg.destroy(sema.gpa); | 11451 | errdefer msg.destroy(sema.gpa); |
| 11553 | if (operand_ty.declSrcLocOrNull(mod)) |union_src| { | 11452 | if (operand_ty.srcLocOrNull(mod)) |union_src| { |
| 11554 | try mod.errNoteNonLazy(union_src, msg, "consider 'union(enum)' here", .{}); | 11453 | try sema.errNote(union_src, msg, "consider 'union(enum)' here", .{}); |
| 11555 | } | 11454 | } |
| 11556 | break :msg msg; | 11455 | break :msg msg; |
| 11557 | }; | 11456 | }; |
| ... | @@ -11575,7 +11474,7 @@ fn switchCond( | ... | @@ -11575,7 +11474,7 @@ fn switchCond( |
| 11575 | } | 11474 | } |
| 11576 | } | 11475 | } |
| 11577 | | 11476 | |
| 11578 | const SwitchErrorSet = std.AutoHashMap(InternPool.NullTerminatedString, Module.SwitchProngSrc); | 11477 | const SwitchErrorSet = std.AutoHashMap(InternPool.NullTerminatedString, LazySrcLoc); |
| 11579 | | 11478 | |
| 11580 | fn zirSwitchBlockErrUnion(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 11479 | fn zirSwitchBlockErrUnion(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 11581 | const tracy = trace(@src()); | 11480 | const tracy = trace(@src()); |
| ... | @@ -11586,11 +11485,11 @@ fn zirSwitchBlockErrUnion(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp | ... | @@ -11586,11 +11485,11 @@ fn zirSwitchBlockErrUnion(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp |
| 11586 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 11485 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 11587 | const switch_src = block.nodeOffset(inst_data.src_node); | 11486 | const switch_src = block.nodeOffset(inst_data.src_node); |
| 11588 | const switch_src_node_offset = inst_data.src_node; | 11487 | const switch_src_node_offset = inst_data.src_node; |
| 11589 | const switch_operand_src: LazySrcLoc = .{ .node_offset_switch_operand = switch_src_node_offset }; | 11488 | const switch_operand_src = block.src(.{ .node_offset_switch_operand = switch_src_node_offset }); |
| 11590 | const else_prong_src: LazySrcLoc = .{ .node_offset_switch_special_prong = switch_src_node_offset }; | 11489 | const else_prong_src = block.src(.{ .node_offset_switch_special_prong = switch_src_node_offset }); |
| 11591 | const extra = sema.code.extraData(Zir.Inst.SwitchBlockErrUnion, inst_data.payload_index); | 11490 | const extra = sema.code.extraData(Zir.Inst.SwitchBlockErrUnion, inst_data.payload_index); |
| 11592 | const main_operand_src: LazySrcLoc = .{ .node_offset_if_cond = extra.data.main_src_node_offset }; | 11491 | const main_operand_src = block.src(.{ .node_offset_if_cond = extra.data.main_src_node_offset }); |
| 11593 | const main_src: LazySrcLoc = .{ .node_offset_main_token = extra.data.main_src_node_offset }; | 11492 | const main_src = block.src(.{ .node_offset_main_token = extra.data.main_src_node_offset }); |
| 11594 | | 11493 | |
| 11595 | const raw_operand_val = try sema.resolveInst(extra.data.operand); | 11494 | const raw_operand_val = try sema.resolveInst(extra.data.operand); |
| 11596 | | 11495 | |
| ... | @@ -11710,6 +11609,7 @@ fn zirSwitchBlockErrUnion(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp | ... | @@ -11710,6 +11609,7 @@ fn zirSwitchBlockErrUnion(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp |
| 11710 | .runtime_index = block.runtime_index, | 11609 | .runtime_index = block.runtime_index, |
| 11711 | .error_return_trace_index = block.error_return_trace_index, | 11610 | .error_return_trace_index = block.error_return_trace_index, |
| 11712 | .want_safety = block.want_safety, | 11611 | .want_safety = block.want_safety, |
| | 11612 | .src_base_inst = block.src_base_inst, |
| 11713 | }; | 11613 | }; |
| 11714 | const merges = &child_block.label.?.merges; | 11614 | const merges = &child_block.label.?.merges; |
| 11715 | defer child_block.instructions.deinit(gpa); | 11615 | defer child_block.instructions.deinit(gpa); |
| ... | @@ -11776,6 +11676,7 @@ fn zirSwitchBlockErrUnion(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp | ... | @@ -11776,6 +11676,7 @@ fn zirSwitchBlockErrUnion(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp |
| 11776 | try sema.switchCond(block, switch_operand_src, spa.operand), | 11676 | try sema.switchCond(block, switch_operand_src, spa.operand), |
| 11777 | err_val, | 11677 | err_val, |
| 11778 | operand_err_set_ty, | 11678 | operand_err_set_ty, |
| | 11679 | switch_src_node_offset, |
| 11779 | .{ | 11680 | .{ |
| 11780 | .body = else_case.body, | 11681 | .body = else_case.body, |
| 11781 | .end = else_case.end, | 11682 | .end = else_case.end, |
| ... | @@ -11817,7 +11718,7 @@ fn zirSwitchBlockErrUnion(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp | ... | @@ -11817,7 +11718,7 @@ fn zirSwitchBlockErrUnion(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp |
| 11817 | | 11718 | |
| 11818 | var sub_block = child_block.makeSubBlock(); | 11719 | var sub_block = child_block.makeSubBlock(); |
| 11819 | sub_block.runtime_loop = null; | 11720 | sub_block.runtime_loop = null; |
| 11820 | sub_block.runtime_cond = mod.declPtr(child_block.src_decl).toSrcLoc(main_operand_src, mod); | 11721 | sub_block.runtime_cond = main_operand_src; |
| 11821 | sub_block.runtime_index.increment(); | 11722 | sub_block.runtime_index.increment(); |
| 11822 | sub_block.need_debug_scope = null; // this body is emitted regardless | 11723 | sub_block.need_debug_scope = null; // this body is emitted regardless |
| 11823 | defer sub_block.instructions.deinit(gpa); | 11724 | defer sub_block.instructions.deinit(gpa); |
| ... | @@ -11894,8 +11795,8 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r | ... | @@ -11894,8 +11795,8 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 11894 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 11795 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 11895 | const src = block.nodeOffset(inst_data.src_node); | 11796 | const src = block.nodeOffset(inst_data.src_node); |
| 11896 | const src_node_offset = inst_data.src_node; | 11797 | const src_node_offset = inst_data.src_node; |
| 11897 | const operand_src: LazySrcLoc = .{ .node_offset_switch_operand = src_node_offset }; | 11798 | const operand_src = block.src(.{ .node_offset_switch_operand = src_node_offset }); |
| 11898 | const special_prong_src: LazySrcLoc = .{ .node_offset_switch_special_prong = src_node_offset }; | 11799 | const special_prong_src = block.src(.{ .node_offset_switch_special_prong = src_node_offset }); |
| 11899 | const extra = sema.code.extraData(Zir.Inst.SwitchBlock, inst_data.payload_index); | 11800 | const extra = sema.code.extraData(Zir.Inst.SwitchBlock, inst_data.payload_index); |
| 11900 | | 11801 | |
| 11901 | const raw_operand_val: Air.Inst.Ref, const raw_operand_ptr: Air.Inst.Ref = blk: { | 11802 | const raw_operand_val: Air.Inst.Ref, const raw_operand_ptr: Air.Inst.Ref = blk: { |
| ... | @@ -11962,7 +11863,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r | ... | @@ -11962,7 +11863,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 11962 | const union_originally = maybe_union_ty.zigTypeTag(mod) == .Union; | 11863 | const union_originally = maybe_union_ty.zigTypeTag(mod) == .Union; |
| 11963 | | 11864 | |
| 11964 | // Duplicate checking variables later also used for `inline else`. | 11865 | // Duplicate checking variables later also used for `inline else`. |
| 11965 | var seen_enum_fields: []?Module.SwitchProngSrc = &.{}; | 11866 | var seen_enum_fields: []?LazySrcLoc = &.{}; |
| 11966 | var seen_errors = SwitchErrorSet.init(gpa); | 11867 | var seen_errors = SwitchErrorSet.init(gpa); |
| 11967 | var range_set = RangeSet.init(gpa, mod); | 11868 | var range_set = RangeSet.init(gpa, mod); |
| 11968 | var true_count: u8 = 0; | 11869 | var true_count: u8 = 0; |
| ... | @@ -11985,21 +11886,18 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r | ... | @@ -11985,21 +11886,18 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 11985 | if (special_prong == .under and (!operand_ty.isNonexhaustiveEnum(mod) or union_originally)) { | 11886 | if (special_prong == .under and (!operand_ty.isNonexhaustiveEnum(mod) or union_originally)) { |
| 11986 | const msg = msg: { | 11887 | const msg = msg: { |
| 11987 | const msg = try sema.errMsg( | 11888 | const msg = try sema.errMsg( |
| 11988 | block, | | |
| 11989 | src, | 11889 | src, |
| 11990 | "'_' prong only allowed when switching on non-exhaustive enums", | 11890 | "'_' prong only allowed when switching on non-exhaustive enums", |
| 11991 | .{}, | 11891 | .{}, |
| 11992 | ); | 11892 | ); |
| 11993 | errdefer msg.destroy(gpa); | 11893 | errdefer msg.destroy(gpa); |
| 11994 | try sema.errNote( | 11894 | try sema.errNote( |
| 11995 | block, | | |
| 11996 | special_prong_src, | 11895 | special_prong_src, |
| 11997 | msg, | 11896 | msg, |
| 11998 | "'_' prong here", | 11897 | "'_' prong here", |
| 11999 | .{}, | 11898 | .{}, |
| 12000 | ); | 11899 | ); |
| 12001 | try sema.errNote( | 11900 | try sema.errNote( |
| 12002 | block, | | |
| 12003 | src, | 11901 | src, |
| 12004 | msg, | 11902 | msg, |
| 12005 | "consider using 'else'", | 11903 | "consider using 'else'", |
| ... | @@ -12014,7 +11912,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r | ... | @@ -12014,7 +11912,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 12014 | switch (operand_ty.zigTypeTag(mod)) { | 11912 | switch (operand_ty.zigTypeTag(mod)) { |
| 12015 | .Union => unreachable, // handled in `switchCond` | 11913 | .Union => unreachable, // handled in `switchCond` |
| 12016 | .Enum => { | 11914 | .Enum => { |
| 12017 | seen_enum_fields = try gpa.alloc(?Module.SwitchProngSrc, operand_ty.enumFieldCount(mod)); | 11915 | seen_enum_fields = try gpa.alloc(?LazySrcLoc, operand_ty.enumFieldCount(mod)); |
| 12018 | empty_enum = seen_enum_fields.len == 0 and !operand_ty.isNonexhaustiveEnum(mod); | 11916 | empty_enum = seen_enum_fields.len == 0 and !operand_ty.isNonexhaustiveEnum(mod); |
| 12019 | @memset(seen_enum_fields, null); | 11917 | @memset(seen_enum_fields, null); |
| 12020 | // `range_set` is used for non-exhaustive enum values that do not correspond to any tags. | 11918 | // `range_set` is used for non-exhaustive enum values that do not correspond to any tags. |
| ... | @@ -12034,8 +11932,11 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r | ... | @@ -12034,8 +11932,11 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 12034 | &range_set, | 11932 | &range_set, |
| 12035 | item_ref, | 11933 | item_ref, |
| 12036 | operand_ty, | 11934 | operand_ty, |
| 12037 | src_node_offset, | 11935 | block.src(.{ .switch_case_item = .{ |
| 12038 | .{ .scalar = scalar_i }, | 11936 | .switch_node_offset = src_node_offset, |
| | 11937 | .case_idx = .{ .kind = .scalar, .index = @intCast(scalar_i) }, |
| | 11938 | .item_idx = .{ .kind = .single, .index = 0 }, |
| | 11939 | } }), |
| 12039 | )); | 11940 | )); |
| 12040 | } | 11941 | } |
| 12041 | } | 11942 | } |
| ... | @@ -12059,8 +11960,11 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r | ... | @@ -12059,8 +11960,11 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 12059 | &range_set, | 11960 | &range_set, |
| 12060 | item_ref, | 11961 | item_ref, |
| 12061 | operand_ty, | 11962 | operand_ty, |
| 12062 | src_node_offset, | 11963 | block.src(.{ .switch_case_item = .{ |
| 12063 | .{ .multi = .{ .prong = multi_i, .item = @intCast(item_i) } }, | 11964 | .switch_node_offset = src_node_offset, |
| | 11965 | .case_idx = .{ .kind = .multi, .index = @intCast(multi_i) }, |
| | 11966 | .item_idx = .{ .kind = .single, .index = @intCast(item_i) }, |
| | 11967 | } }), |
| 12064 | )); | 11968 | )); |
| 12065 | } | 11969 | } |
| 12066 | | 11970 | |
| ... | @@ -12081,7 +11985,6 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r | ... | @@ -12081,7 +11985,6 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 12081 | } else if (!all_tags_handled) { | 11985 | } else if (!all_tags_handled) { |
| 12082 | const msg = msg: { | 11986 | const msg = msg: { |
| 12083 | const msg = try sema.errMsg( | 11987 | const msg = try sema.errMsg( |
| 12084 | block, | | |
| 12085 | src, | 11988 | src, |
| 12086 | "switch must handle all possibilities", | 11989 | "switch must handle all possibilities", |
| 12087 | .{}, | 11990 | .{}, |
| ... | @@ -12099,8 +12002,8 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r | ... | @@ -12099,8 +12002,8 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 12099 | .{field_name.fmt(&mod.intern_pool)}, | 12002 | .{field_name.fmt(&mod.intern_pool)}, |
| 12100 | ); | 12003 | ); |
| 12101 | } | 12004 | } |
| 12102 | try mod.errNoteNonLazy( | 12005 | try sema.errNote( |
| 12103 | operand_ty.declSrcLoc(mod), | 12006 | operand_ty.srcLoc(mod), |
| 12104 | msg, | 12007 | msg, |
| 12105 | "enum '{}' declared here", | 12008 | "enum '{}' declared here", |
| 12106 | .{operand_ty.fmt(mod)}, | 12009 | .{operand_ty.fmt(mod)}, |
| ... | @@ -12144,8 +12047,11 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r | ... | @@ -12144,8 +12047,11 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 12144 | &range_set, | 12047 | &range_set, |
| 12145 | item_ref, | 12048 | item_ref, |
| 12146 | operand_ty, | 12049 | operand_ty, |
| 12147 | src_node_offset, | 12050 | block.src(.{ .switch_case_item = .{ |
| 12148 | .{ .scalar = scalar_i }, | 12051 | .switch_node_offset = src_node_offset, |
| | 12052 | .case_idx = .{ .kind = .scalar, .index = @intCast(scalar_i) }, |
| | 12053 | .item_idx = .{ .kind = .single, .index = 0 }, |
| | 12054 | } }), |
| 12149 | )); | 12055 | )); |
| 12150 | } | 12056 | } |
| 12151 | } | 12057 | } |
| ... | @@ -12168,8 +12074,11 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r | ... | @@ -12168,8 +12074,11 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 12168 | &range_set, | 12074 | &range_set, |
| 12169 | item_ref, | 12075 | item_ref, |
| 12170 | operand_ty, | 12076 | operand_ty, |
| 12171 | src_node_offset, | 12077 | block.src(.{ .switch_case_item = .{ |
| 12172 | .{ .multi = .{ .prong = multi_i, .item = @intCast(item_i) } }, | 12078 | .switch_node_offset = src_node_offset, |
| | 12079 | .case_idx = .{ .kind = .multi, .index = @intCast(multi_i) }, |
| | 12080 | .item_idx = .{ .kind = .single, .index = @intCast(item_i) }, |
| | 12081 | } }), |
| 12173 | )); | 12082 | )); |
| 12174 | } | 12083 | } |
| 12175 | | 12084 | |
| ... | @@ -12187,8 +12096,11 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r | ... | @@ -12187,8 +12096,11 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 12187 | item_first, | 12096 | item_first, |
| 12188 | item_last, | 12097 | item_last, |
| 12189 | operand_ty, | 12098 | operand_ty, |
| 12190 | src_node_offset, | 12099 | block.src(.{ .switch_case_item = .{ |
| 12191 | .{ .range = .{ .prong = multi_i, .item = range_i } }, | 12100 | .switch_node_offset = src_node_offset, |
| | 12101 | .case_idx = .{ .kind = .multi, .index = @intCast(multi_i) }, |
| | 12102 | .item_idx = .{ .kind = .range, .index = @intCast(range_i) }, |
| | 12103 | } }), |
| 12192 | ); | 12104 | ); |
| 12193 | case_vals.appendAssumeCapacity(vals[0]); | 12105 | case_vals.appendAssumeCapacity(vals[0]); |
| 12194 | case_vals.appendAssumeCapacity(vals[1]); | 12106 | case_vals.appendAssumeCapacity(vals[1]); |
| ... | @@ -12239,8 +12151,11 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r | ... | @@ -12239,8 +12151,11 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 12239 | &true_count, | 12151 | &true_count, |
| 12240 | &false_count, | 12152 | &false_count, |
| 12241 | item_ref, | 12153 | item_ref, |
| 12242 | src_node_offset, | 12154 | block.src(.{ .switch_case_item = .{ |
| 12243 | .{ .scalar = scalar_i }, | 12155 | .switch_node_offset = src_node_offset, |
| | 12156 | .case_idx = .{ .kind = .scalar, .index = @intCast(scalar_i) }, |
| | 12157 | .item_idx = .{ .kind = .single, .index = 0 }, |
| | 12158 | } }), |
| 12244 | )); | 12159 | )); |
| 12245 | } | 12160 | } |
| 12246 | } | 12161 | } |
| ... | @@ -12263,8 +12178,11 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r | ... | @@ -12263,8 +12178,11 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 12263 | &true_count, | 12178 | &true_count, |
| 12264 | &false_count, | 12179 | &false_count, |
| 12265 | item_ref, | 12180 | item_ref, |
| 12266 | src_node_offset, | 12181 | block.src(.{ .switch_case_item = .{ |
| 12267 | .{ .multi = .{ .prong = multi_i, .item = @intCast(item_i) } }, | 12182 | .switch_node_offset = src_node_offset, |
| | 12183 | .case_idx = .{ .kind = .multi, .index = @intCast(multi_i) }, |
| | 12184 | .item_idx = .{ .kind = .single, .index = @intCast(item_i) }, |
| | 12185 | } }), |
| 12268 | )); | 12186 | )); |
| 12269 | } | 12187 | } |
| 12270 | | 12188 | |
| ... | @@ -12322,8 +12240,11 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r | ... | @@ -12322,8 +12240,11 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 12322 | &seen_values, | 12240 | &seen_values, |
| 12323 | item_ref, | 12241 | item_ref, |
| 12324 | operand_ty, | 12242 | operand_ty, |
| 12325 | src_node_offset, | 12243 | block.src(.{ .switch_case_item = .{ |
| 12326 | .{ .scalar = scalar_i }, | 12244 | .switch_node_offset = src_node_offset, |
| | 12245 | .case_idx = .{ .kind = .scalar, .index = @intCast(scalar_i) }, |
| | 12246 | .item_idx = .{ .kind = .single, .index = 0 }, |
| | 12247 | } }), |
| 12327 | )); | 12248 | )); |
| 12328 | } | 12249 | } |
| 12329 | } | 12250 | } |
| ... | @@ -12346,8 +12267,11 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r | ... | @@ -12346,8 +12267,11 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 12346 | &seen_values, | 12267 | &seen_values, |
| 12347 | item_ref, | 12268 | item_ref, |
| 12348 | operand_ty, | 12269 | operand_ty, |
| 12349 | src_node_offset, | 12270 | block.src(.{ .switch_case_item = .{ |
| 12350 | .{ .multi = .{ .prong = multi_i, .item = @intCast(item_i) } }, | 12271 | .switch_node_offset = src_node_offset, |
| | 12272 | .case_idx = .{ .kind = .multi, .index = @intCast(multi_i) }, |
| | 12273 | .item_idx = .{ .kind = .single, .index = @intCast(item_i) }, |
| | 12274 | } }), |
| 12351 | )); | 12275 | )); |
| 12352 | } | 12276 | } |
| 12353 | | 12277 | |
| ... | @@ -12417,6 +12341,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r | ... | @@ -12417,6 +12341,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 12417 | .runtime_index = block.runtime_index, | 12341 | .runtime_index = block.runtime_index, |
| 12418 | .want_safety = block.want_safety, | 12342 | .want_safety = block.want_safety, |
| 12419 | .error_return_trace_index = block.error_return_trace_index, | 12343 | .error_return_trace_index = block.error_return_trace_index, |
| | 12344 | .src_base_inst = block.src_base_inst, |
| 12420 | }; | 12345 | }; |
| 12421 | const merges = &child_block.label.?.merges; | 12346 | const merges = &child_block.label.?.merges; |
| 12422 | defer child_block.instructions.deinit(gpa); | 12347 | defer child_block.instructions.deinit(gpa); |
| ... | @@ -12430,6 +12355,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r | ... | @@ -12430,6 +12355,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 12430 | operand, | 12355 | operand, |
| 12431 | operand_val, | 12356 | operand_val, |
| 12432 | operand_ty, | 12357 | operand_ty, |
| | 12358 | src_node_offset, |
| 12433 | special, | 12359 | special, |
| 12434 | case_vals, | 12360 | case_vals, |
| 12435 | scalar_cases_len, | 12361 | scalar_cases_len, |
| ... | @@ -12462,7 +12388,10 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r | ... | @@ -12462,7 +12388,10 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 12462 | .special, | 12388 | .special, |
| 12463 | special.body, | 12389 | special.body, |
| 12464 | special.capture, | 12390 | special.capture, |
| 12465 | .special_capture, | 12391 | block.src(.{ .switch_capture = .{ |
| | 12392 | .switch_node_offset = src_node_offset, |
| | 12393 | .case_idx = LazySrcLoc.Offset.SwitchCaseIndex.special, |
| | 12394 | } }), |
| 12466 | undefined, // case_vals may be undefined for special prongs | 12395 | undefined, // case_vals may be undefined for special prongs |
| 12467 | .none, | 12396 | .none, |
| 12468 | false, | 12397 | false, |
| ... | @@ -12529,9 +12458,9 @@ fn analyzeSwitchRuntimeBlock( | ... | @@ -12529,9 +12458,9 @@ fn analyzeSwitchRuntimeBlock( |
| 12529 | union_originally: bool, | 12458 | union_originally: bool, |
| 12530 | maybe_union_ty: Type, | 12459 | maybe_union_ty: Type, |
| 12531 | err_set: bool, | 12460 | err_set: bool, |
| 12532 | src_node_offset: i32, | 12461 | switch_node_offset: i32, |
| 12533 | special_prong_src: LazySrcLoc, | 12462 | special_prong_src: LazySrcLoc, |
| 12534 | seen_enum_fields: []?Module.SwitchProngSrc, | 12463 | seen_enum_fields: []?LazySrcLoc, |
| 12535 | seen_errors: SwitchErrorSet, | 12464 | seen_errors: SwitchErrorSet, |
| 12536 | range_set: RangeSet, | 12465 | range_set: RangeSet, |
| 12537 | true_count: u8, | 12466 | true_count: u8, |
| ... | @@ -12552,7 +12481,7 @@ fn analyzeSwitchRuntimeBlock( | ... | @@ -12552,7 +12481,7 @@ fn analyzeSwitchRuntimeBlock( |
| 12552 | | 12481 | |
| 12553 | var case_block = child_block.makeSubBlock(); | 12482 | var case_block = child_block.makeSubBlock(); |
| 12554 | case_block.runtime_loop = null; | 12483 | case_block.runtime_loop = null; |
| 12555 | case_block.runtime_cond = mod.declPtr(child_block.src_decl).toSrcLoc(operand_src, mod); | 12484 | case_block.runtime_cond = operand_src; |
| 12556 | case_block.runtime_index.increment(); | 12485 | case_block.runtime_index.increment(); |
| 12557 | case_block.need_debug_scope = null; // this body is emitted regardless | 12486 | case_block.need_debug_scope = null; // this body is emitted regardless |
| 12558 | defer case_block.instructions.deinit(gpa); | 12487 | defer case_block.instructions.deinit(gpa); |
| ... | @@ -12574,7 +12503,7 @@ fn analyzeSwitchRuntimeBlock( | ... | @@ -12574,7 +12503,7 @@ fn analyzeSwitchRuntimeBlock( |
| 12574 | // `item` is already guaranteed to be constant known. | 12503 | // `item` is already guaranteed to be constant known. |
| 12575 | | 12504 | |
| 12576 | const analyze_body = if (union_originally) blk: { | 12505 | const analyze_body = if (union_originally) blk: { |
| 12577 | const unresolved_item_val = sema.resolveConstDefinedValue(block, .unneeded, item, undefined) catch unreachable; | 12506 | const unresolved_item_val = sema.resolveConstDefinedValue(block, LazySrcLoc.unneeded, item, undefined) catch unreachable; |
| 12578 | const item_val = sema.resolveLazyValue(unresolved_item_val) catch unreachable; | 12507 | const item_val = sema.resolveLazyValue(unresolved_item_val) catch unreachable; |
| 12579 | const field_ty = maybe_union_ty.unionFieldType(item_val, mod).?; | 12508 | const field_ty = maybe_union_ty.unionFieldType(item_val, mod).?; |
| 12580 | break :blk field_ty.zigTypeTag(mod) != .NoReturn; | 12509 | break :blk field_ty.zigTypeTag(mod) != .NoReturn; |
| ... | @@ -12588,7 +12517,10 @@ fn analyzeSwitchRuntimeBlock( | ... | @@ -12588,7 +12517,10 @@ fn analyzeSwitchRuntimeBlock( |
| 12588 | .normal, | 12517 | .normal, |
| 12589 | body, | 12518 | body, |
| 12590 | info.capture, | 12519 | info.capture, |
| 12591 | .{ .scalar_capture = @intCast(scalar_i) }, | 12520 | child_block.src(.{ .switch_capture = .{ |
| | 12521 | .switch_node_offset = switch_node_offset, |
| | 12522 | .case_idx = .{ .kind = .scalar, .index = @intCast(scalar_i) }, |
| | 12523 | } }), |
| 12592 | &.{item}, | 12524 | &.{item}, |
| 12593 | if (info.is_inline) item else .none, | 12525 | if (info.is_inline) item else .none, |
| 12594 | info.has_tag_capture, | 12526 | info.has_tag_capture, |
| ... | @@ -12643,8 +12575,8 @@ fn analyzeSwitchRuntimeBlock( | ... | @@ -12643,8 +12575,8 @@ fn analyzeSwitchRuntimeBlock( |
| 12643 | const item_first_ref = range_items[0]; | 12575 | const item_first_ref = range_items[0]; |
| 12644 | const item_last_ref = range_items[1]; | 12576 | const item_last_ref = range_items[1]; |
| 12645 | | 12577 | |
| 12646 | var item = sema.resolveConstDefinedValue(block, .unneeded, item_first_ref, undefined) catch unreachable; | 12578 | var item = sema.resolveConstDefinedValue(block, LazySrcLoc.unneeded, item_first_ref, undefined) catch unreachable; |
| 12647 | const item_last = sema.resolveConstDefinedValue(block, .unneeded, item_last_ref, undefined) catch unreachable; | 12579 | const item_last = sema.resolveConstDefinedValue(block, LazySrcLoc.unneeded, item_last_ref, undefined) catch unreachable; |
| 12648 | | 12580 | |
| 12649 | while (item.compareScalar(.lte, item_last, operand_ty, mod)) : ({ | 12581 | while (item.compareScalar(.lte, item_last, operand_ty, mod)) : ({ |
| 12650 | // Previous validation has resolved any possible lazy values. | 12582 | // Previous validation has resolved any possible lazy values. |
| ... | @@ -12660,17 +12592,11 @@ fn analyzeSwitchRuntimeBlock( | ... | @@ -12660,17 +12592,11 @@ fn analyzeSwitchRuntimeBlock( |
| 12660 | case_block.instructions.shrinkRetainingCapacity(0); | 12592 | case_block.instructions.shrinkRetainingCapacity(0); |
| 12661 | case_block.error_return_trace_index = child_block.error_return_trace_index; | 12593 | case_block.error_return_trace_index = child_block.error_return_trace_index; |
| 12662 | | 12594 | |
| 12663 | if (emit_bb) sema.emitBackwardBranch(block, .unneeded) catch |err| switch (err) { | 12595 | if (emit_bb) try sema.emitBackwardBranch(block, block.src(.{ .switch_case_item = .{ |
| 12664 | error.NeededSourceLocation => { | 12596 | .switch_node_offset = switch_node_offset, |
| 12665 | const case_src = Module.SwitchProngSrc{ | 12597 | .case_idx = .{ .kind = .multi, .index = @intCast(multi_i) }, |
| 12666 | .range = .{ .prong = multi_i, .item = range_i }, | 12598 | .item_idx = .{ .kind = .range, .index = @intCast(range_i) }, |
| 12667 | }; | 12599 | } })); |
| 12668 | const decl = mod.declPtr(case_block.src_decl); | | |
| 12669 | try sema.emitBackwardBranch(block, case_src.resolve(mod, decl, src_node_offset, .none)); | | |
| 12670 | unreachable; | | |
| 12671 | }, | | |
| 12672 | else => return err, | | |
| 12673 | }; | | |
| 12674 | emit_bb = true; | 12600 | emit_bb = true; |
| 12675 | | 12601 | |
| 12676 | try spa.analyzeProngRuntime( | 12602 | try spa.analyzeProngRuntime( |
| ... | @@ -12678,7 +12604,10 @@ fn analyzeSwitchRuntimeBlock( | ... | @@ -12678,7 +12604,10 @@ fn analyzeSwitchRuntimeBlock( |
| 12678 | .normal, | 12604 | .normal, |
| 12679 | body, | 12605 | body, |
| 12680 | info.capture, | 12606 | info.capture, |
| 12681 | .{ .multi_capture = multi_i }, | 12607 | child_block.src(.{ .switch_capture = .{ |
| | 12608 | .switch_node_offset = switch_node_offset, |
| | 12609 | .case_idx = .{ .kind = .multi, .index = @intCast(multi_i) }, |
| | 12610 | } }), |
| 12682 | undefined, // case_vals may be undefined for ranges | 12611 | undefined, // case_vals may be undefined for ranges |
| 12683 | item_ref, | 12612 | item_ref, |
| 12684 | info.has_tag_capture, | 12613 | info.has_tag_capture, |
| ... | @@ -12701,22 +12630,16 @@ fn analyzeSwitchRuntimeBlock( | ... | @@ -12701,22 +12630,16 @@ fn analyzeSwitchRuntimeBlock( |
| 12701 | case_block.error_return_trace_index = child_block.error_return_trace_index; | 12630 | case_block.error_return_trace_index = child_block.error_return_trace_index; |
| 12702 | | 12631 | |
| 12703 | const analyze_body = if (union_originally) blk: { | 12632 | const analyze_body = if (union_originally) blk: { |
| 12704 | const item_val = sema.resolveConstDefinedValue(block, .unneeded, item, undefined) catch unreachable; | 12633 | const item_val = sema.resolveConstDefinedValue(block, LazySrcLoc.unneeded, item, undefined) catch unreachable; |
| 12705 | const field_ty = maybe_union_ty.unionFieldType(item_val, mod).?; | 12634 | const field_ty = maybe_union_ty.unionFieldType(item_val, mod).?; |
| 12706 | break :blk field_ty.zigTypeTag(mod) != .NoReturn; | 12635 | break :blk field_ty.zigTypeTag(mod) != .NoReturn; |
| 12707 | } else true; | 12636 | } else true; |
| 12708 | | 12637 | |
| 12709 | if (emit_bb) sema.emitBackwardBranch(block, .unneeded) catch |err| switch (err) { | 12638 | if (emit_bb) try sema.emitBackwardBranch(block, block.src(.{ .switch_case_item = .{ |
| 12710 | error.NeededSourceLocation => { | 12639 | .switch_node_offset = switch_node_offset, |
| 12711 | const case_src = Module.SwitchProngSrc{ | 12640 | .case_idx = .{ .kind = .multi, .index = @intCast(multi_i) }, |
| 12712 | .multi = .{ .prong = multi_i, .item = @intCast(item_i) }, | 12641 | .item_idx = .{ .kind = .single, .index = @intCast(item_i) }, |
| 12713 | }; | 12642 | } })); |
| 12714 | const decl = mod.declPtr(case_block.src_decl); | | |
| 12715 | try sema.emitBackwardBranch(block, case_src.resolve(mod, decl, src_node_offset, .none)); | | |
| 12716 | unreachable; | | |
| 12717 | }, | | |
| 12718 | else => return err, | | |
| 12719 | }; | | |
| 12720 | emit_bb = true; | 12643 | emit_bb = true; |
| 12721 | | 12644 | |
| 12722 | if (analyze_body) { | 12645 | if (analyze_body) { |
| ... | @@ -12725,7 +12648,10 @@ fn analyzeSwitchRuntimeBlock( | ... | @@ -12725,7 +12648,10 @@ fn analyzeSwitchRuntimeBlock( |
| 12725 | .normal, | 12648 | .normal, |
| 12726 | body, | 12649 | body, |
| 12727 | info.capture, | 12650 | info.capture, |
| 12728 | .{ .multi_capture = multi_i }, | 12651 | child_block.src(.{ .switch_capture = .{ |
| | 12652 | .switch_node_offset = switch_node_offset, |
| | 12653 | .case_idx = .{ .kind = .multi, .index = @intCast(multi_i) }, |
| | 12654 | } }), |
| 12729 | &.{item}, | 12655 | &.{item}, |
| 12730 | item, | 12656 | item, |
| 12731 | info.has_tag_capture, | 12657 | info.has_tag_capture, |
| ... | @@ -12755,7 +12681,7 @@ fn analyzeSwitchRuntimeBlock( | ... | @@ -12755,7 +12681,7 @@ fn analyzeSwitchRuntimeBlock( |
| 12755 | | 12681 | |
| 12756 | const analyze_body = if (union_originally) | 12682 | const analyze_body = if (union_originally) |
| 12757 | for (items) |item| { | 12683 | for (items) |item| { |
| 12758 | const item_val = sema.resolveConstDefinedValue(block, .unneeded, item, undefined) catch unreachable; | 12684 | const item_val = sema.resolveConstDefinedValue(block, LazySrcLoc.unneeded, item, undefined) catch unreachable; |
| 12759 | const field_ty = maybe_union_ty.unionFieldType(item_val, mod).?; | 12685 | const field_ty = maybe_union_ty.unionFieldType(item_val, mod).?; |
| 12760 | if (field_ty.zigTypeTag(mod) != .NoReturn) break true; | 12686 | if (field_ty.zigTypeTag(mod) != .NoReturn) break true; |
| 12761 | } else false | 12687 | } else false |
| ... | @@ -12772,7 +12698,10 @@ fn analyzeSwitchRuntimeBlock( | ... | @@ -12772,7 +12698,10 @@ fn analyzeSwitchRuntimeBlock( |
| 12772 | .normal, | 12698 | .normal, |
| 12773 | body, | 12699 | body, |
| 12774 | info.capture, | 12700 | info.capture, |
| 12775 | .{ .multi_capture = multi_i }, | 12701 | child_block.src(.{ .switch_capture = .{ |
| | 12702 | .switch_node_offset = switch_node_offset, |
| | 12703 | .case_idx = .{ .kind = .multi, .index = @intCast(multi_i) }, |
| | 12704 | } }), |
| 12776 | items, | 12705 | items, |
| 12777 | .none, | 12706 | .none, |
| 12778 | false, | 12707 | false, |
| ... | @@ -12856,7 +12785,10 @@ fn analyzeSwitchRuntimeBlock( | ... | @@ -12856,7 +12785,10 @@ fn analyzeSwitchRuntimeBlock( |
| 12856 | .normal, | 12785 | .normal, |
| 12857 | body, | 12786 | body, |
| 12858 | info.capture, | 12787 | info.capture, |
| 12859 | .{ .multi_capture = multi_i }, | 12788 | child_block.src(.{ .switch_capture = .{ |
| | 12789 | .switch_node_offset = switch_node_offset, |
| | 12790 | .case_idx = .{ .kind = .multi, .index = @intCast(multi_i) }, |
| | 12791 | } }), |
| 12860 | items, | 12792 | items, |
| 12861 | .none, | 12793 | .none, |
| 12862 | false, | 12794 | false, |
| ... | @@ -12921,7 +12853,10 @@ fn analyzeSwitchRuntimeBlock( | ... | @@ -12921,7 +12853,10 @@ fn analyzeSwitchRuntimeBlock( |
| 12921 | .special, | 12853 | .special, |
| 12922 | special.body, | 12854 | special.body, |
| 12923 | special.capture, | 12855 | special.capture, |
| 12924 | .special_capture, | 12856 | child_block.src(.{ .switch_capture = .{ |
| | 12857 | .switch_node_offset = switch_node_offset, |
| | 12858 | .case_idx = LazySrcLoc.Offset.SwitchCaseIndex.special, |
| | 12859 | } }), |
| 12925 | &.{item_ref}, | 12860 | &.{item_ref}, |
| 12926 | item_ref, | 12861 | item_ref, |
| 12927 | special.has_tag_capture, | 12862 | special.has_tag_capture, |
| ... | @@ -12966,7 +12901,10 @@ fn analyzeSwitchRuntimeBlock( | ... | @@ -12966,7 +12901,10 @@ fn analyzeSwitchRuntimeBlock( |
| 12966 | .special, | 12901 | .special, |
| 12967 | special.body, | 12902 | special.body, |
| 12968 | special.capture, | 12903 | special.capture, |
| 12969 | .special_capture, | 12904 | child_block.src(.{ .switch_capture = .{ |
| | 12905 | .switch_node_offset = switch_node_offset, |
| | 12906 | .case_idx = LazySrcLoc.Offset.SwitchCaseIndex.special, |
| | 12907 | } }), |
| 12970 | &.{item_ref}, | 12908 | &.{item_ref}, |
| 12971 | item_ref, | 12909 | item_ref, |
| 12972 | special.has_tag_capture, | 12910 | special.has_tag_capture, |
| ... | @@ -12997,7 +12935,10 @@ fn analyzeSwitchRuntimeBlock( | ... | @@ -12997,7 +12935,10 @@ fn analyzeSwitchRuntimeBlock( |
| 12997 | .special, | 12935 | .special, |
| 12998 | special.body, | 12936 | special.body, |
| 12999 | special.capture, | 12937 | special.capture, |
| 13000 | .special_capture, | 12938 | child_block.src(.{ .switch_capture = .{ |
| | 12939 | .switch_node_offset = switch_node_offset, |
| | 12940 | .case_idx = LazySrcLoc.Offset.SwitchCaseIndex.special, |
| | 12941 | } }), |
| 13001 | &.{item_ref}, | 12942 | &.{item_ref}, |
| 13002 | item_ref, | 12943 | item_ref, |
| 13003 | special.has_tag_capture, | 12944 | special.has_tag_capture, |
| ... | @@ -13025,7 +12966,10 @@ fn analyzeSwitchRuntimeBlock( | ... | @@ -13025,7 +12966,10 @@ fn analyzeSwitchRuntimeBlock( |
| 13025 | .special, | 12966 | .special, |
| 13026 | special.body, | 12967 | special.body, |
| 13027 | special.capture, | 12968 | special.capture, |
| 13028 | .special_capture, | 12969 | child_block.src(.{ .switch_capture = .{ |
| | 12970 | .switch_node_offset = switch_node_offset, |
| | 12971 | .case_idx = LazySrcLoc.Offset.SwitchCaseIndex.special, |
| | 12972 | } }), |
| 13029 | &.{.bool_true}, | 12973 | &.{.bool_true}, |
| 13030 | .bool_true, | 12974 | .bool_true, |
| 13031 | special.has_tag_capture, | 12975 | special.has_tag_capture, |
| ... | @@ -13051,7 +12995,10 @@ fn analyzeSwitchRuntimeBlock( | ... | @@ -13051,7 +12995,10 @@ fn analyzeSwitchRuntimeBlock( |
| 13051 | .special, | 12995 | .special, |
| 13052 | special.body, | 12996 | special.body, |
| 13053 | special.capture, | 12997 | special.capture, |
| 13054 | .special_capture, | 12998 | child_block.src(.{ .switch_capture = .{ |
| | 12999 | .switch_node_offset = switch_node_offset, |
| | 13000 | .case_idx = LazySrcLoc.Offset.SwitchCaseIndex.special, |
| | 13001 | } }), |
| 13055 | &.{.bool_false}, | 13002 | &.{.bool_false}, |
| 13056 | .bool_false, | 13003 | .bool_false, |
| 13057 | special.has_tag_capture, | 13004 | special.has_tag_capture, |
| ... | @@ -13101,7 +13048,10 @@ fn analyzeSwitchRuntimeBlock( | ... | @@ -13101,7 +13048,10 @@ fn analyzeSwitchRuntimeBlock( |
| 13101 | .special, | 13048 | .special, |
| 13102 | special.body, | 13049 | special.body, |
| 13103 | special.capture, | 13050 | special.capture, |
| 13104 | .special_capture, | 13051 | child_block.src(.{ .switch_capture = .{ |
| | 13052 | .switch_node_offset = switch_node_offset, |
| | 13053 | .case_idx = LazySrcLoc.Offset.SwitchCaseIndex.special, |
| | 13054 | } }), |
| 13105 | undefined, // case_vals may be undefined for special prongs | 13055 | undefined, // case_vals may be undefined for special prongs |
| 13106 | .none, | 13056 | .none, |
| 13107 | false, | 13057 | false, |
| ... | @@ -13161,6 +13111,7 @@ fn resolveSwitchComptime( | ... | @@ -13161,6 +13111,7 @@ fn resolveSwitchComptime( |
| 13161 | cond_operand: Air.Inst.Ref, | 13111 | cond_operand: Air.Inst.Ref, |
| 13162 | operand_val: Value, | 13112 | operand_val: Value, |
| 13163 | operand_ty: Type, | 13113 | operand_ty: Type, |
| | 13114 | switch_node_offset: i32, |
| 13164 | special: SpecialProng, | 13115 | special: SpecialProng, |
| 13165 | case_vals: std.ArrayListUnmanaged(Air.Inst.Ref), | 13116 | case_vals: std.ArrayListUnmanaged(Air.Inst.Ref), |
| 13166 | scalar_cases_len: u32, | 13117 | scalar_cases_len: u32, |
| ... | @@ -13181,7 +13132,7 @@ fn resolveSwitchComptime( | ... | @@ -13181,7 +13132,7 @@ fn resolveSwitchComptime( |
| 13181 | extra_index += info.body_len; | 13132 | extra_index += info.body_len; |
| 13182 | | 13133 | |
| 13183 | const item = case_vals.items[scalar_i]; | 13134 | const item = case_vals.items[scalar_i]; |
| 13184 | const item_val = sema.resolveConstDefinedValue(child_block, .unneeded, item, undefined) catch unreachable; | 13135 | const item_val = sema.resolveConstDefinedValue(child_block, LazySrcLoc.unneeded, item, undefined) catch unreachable; |
| 13185 | if (operand_val.eql(item_val, operand_ty, sema.mod)) { | 13136 | if (operand_val.eql(item_val, operand_ty, sema.mod)) { |
| 13186 | if (err_set) try sema.maybeErrorUnwrapComptime(child_block, body, cond_operand); | 13137 | if (err_set) try sema.maybeErrorUnwrapComptime(child_block, body, cond_operand); |
| 13187 | return spa.resolveProngComptime( | 13138 | return spa.resolveProngComptime( |
| ... | @@ -13189,7 +13140,10 @@ fn resolveSwitchComptime( | ... | @@ -13189,7 +13140,10 @@ fn resolveSwitchComptime( |
| 13189 | .normal, | 13140 | .normal, |
| 13190 | body, | 13141 | body, |
| 13191 | info.capture, | 13142 | info.capture, |
| 13192 | .{ .scalar_capture = @intCast(scalar_i) }, | 13143 | child_block.src(.{ .switch_capture = .{ |
| | 13144 | .switch_node_offset = switch_node_offset, |
| | 13145 | .case_idx = .{ .kind = .scalar, .index = @intCast(scalar_i) }, |
| | 13146 | } }), |
| 13193 | &.{item}, | 13147 | &.{item}, |
| 13194 | if (info.is_inline) cond_operand else .none, | 13148 | if (info.is_inline) cond_operand else .none, |
| 13195 | info.has_tag_capture, | 13149 | info.has_tag_capture, |
| ... | @@ -13215,7 +13169,7 @@ fn resolveSwitchComptime( | ... | @@ -13215,7 +13169,7 @@ fn resolveSwitchComptime( |
| 13215 | | 13169 | |
| 13216 | for (items) |item| { | 13170 | for (items) |item| { |
| 13217 | // Validation above ensured these will succeed. | 13171 | // Validation above ensured these will succeed. |
| 13218 | const item_val = sema.resolveConstDefinedValue(child_block, .unneeded, item, undefined) catch unreachable; | 13172 | const item_val = sema.resolveConstDefinedValue(child_block, LazySrcLoc.unneeded, item, undefined) catch unreachable; |
| 13219 | if (operand_val.eql(item_val, operand_ty, sema.mod)) { | 13173 | if (operand_val.eql(item_val, operand_ty, sema.mod)) { |
| 13220 | if (err_set) try sema.maybeErrorUnwrapComptime(child_block, body, cond_operand); | 13174 | if (err_set) try sema.maybeErrorUnwrapComptime(child_block, body, cond_operand); |
| 13221 | return spa.resolveProngComptime( | 13175 | return spa.resolveProngComptime( |
| ... | @@ -13223,7 +13177,10 @@ fn resolveSwitchComptime( | ... | @@ -13223,7 +13177,10 @@ fn resolveSwitchComptime( |
| 13223 | .normal, | 13177 | .normal, |
| 13224 | body, | 13178 | body, |
| 13225 | info.capture, | 13179 | info.capture, |
| 13226 | .{ .multi_capture = @intCast(multi_i) }, | 13180 | child_block.src(.{ .switch_capture = .{ |
| | 13181 | .switch_node_offset = switch_node_offset, |
| | 13182 | .case_idx = .{ .kind = .multi, .index = @intCast(multi_i) }, |
| | 13183 | } }), |
| 13227 | items, | 13184 | items, |
| 13228 | if (info.is_inline) cond_operand else .none, | 13185 | if (info.is_inline) cond_operand else .none, |
| 13229 | info.has_tag_capture, | 13186 | info.has_tag_capture, |
| ... | @@ -13239,8 +13196,8 @@ fn resolveSwitchComptime( | ... | @@ -13239,8 +13196,8 @@ fn resolveSwitchComptime( |
| 13239 | case_val_idx += 2; | 13196 | case_val_idx += 2; |
| 13240 | | 13197 | |
| 13241 | // Validation above ensured these will succeed. | 13198 | // Validation above ensured these will succeed. |
| 13242 | const first_val = sema.resolveConstDefinedValue(child_block, .unneeded, range_items[0], undefined) catch unreachable; | 13199 | const first_val = sema.resolveConstDefinedValue(child_block, LazySrcLoc.unneeded, range_items[0], undefined) catch unreachable; |
| 13243 | const last_val = sema.resolveConstDefinedValue(child_block, .unneeded, range_items[1], undefined) catch unreachable; | 13200 | const last_val = sema.resolveConstDefinedValue(child_block, LazySrcLoc.unneeded, range_items[1], undefined) catch unreachable; |
| 13244 | if ((try sema.compareAll(resolved_operand_val, .gte, first_val, operand_ty)) and | 13201 | if ((try sema.compareAll(resolved_operand_val, .gte, first_val, operand_ty)) and |
| 13245 | (try sema.compareAll(resolved_operand_val, .lte, last_val, operand_ty))) | 13202 | (try sema.compareAll(resolved_operand_val, .lte, last_val, operand_ty))) |
| 13246 | { | 13203 | { |
| ... | @@ -13250,7 +13207,10 @@ fn resolveSwitchComptime( | ... | @@ -13250,7 +13207,10 @@ fn resolveSwitchComptime( |
| 13250 | .normal, | 13207 | .normal, |
| 13251 | body, | 13208 | body, |
| 13252 | info.capture, | 13209 | info.capture, |
| 13253 | .{ .multi_capture = @intCast(multi_i) }, | 13210 | child_block.src(.{ .switch_capture = .{ |
| | 13211 | .switch_node_offset = switch_node_offset, |
| | 13212 | .case_idx = .{ .kind = .multi, .index = @intCast(multi_i) }, |
| | 13213 | } }), |
| 13254 | undefined, // case_vals may be undefined for ranges | 13214 | undefined, // case_vals may be undefined for ranges |
| 13255 | if (info.is_inline) cond_operand else .none, | 13215 | if (info.is_inline) cond_operand else .none, |
| 13256 | info.has_tag_capture, | 13216 | info.has_tag_capture, |
| ... | @@ -13272,7 +13232,10 @@ fn resolveSwitchComptime( | ... | @@ -13272,7 +13232,10 @@ fn resolveSwitchComptime( |
| 13272 | .special, | 13232 | .special, |
| 13273 | special.body, | 13233 | special.body, |
| 13274 | special.capture, | 13234 | special.capture, |
| 13275 | .special_capture, | 13235 | child_block.src(.{ .switch_capture = .{ |
| | 13236 | .switch_node_offset = switch_node_offset, |
| | 13237 | .case_idx = LazySrcLoc.Offset.SwitchCaseIndex.special, |
| | 13238 | } }), |
| 13276 | undefined, // case_vals may be undefined for special prongs | 13239 | undefined, // case_vals may be undefined for special prongs |
| 13277 | if (special.is_inline) cond_operand else .none, | 13240 | if (special.is_inline) cond_operand else .none, |
| 13278 | special.has_tag_capture, | 13241 | special.has_tag_capture, |
| ... | @@ -13358,36 +13321,19 @@ fn resolveSwitchItemVal( | ... | @@ -13358,36 +13321,19 @@ fn resolveSwitchItemVal( |
| 13358 | item_ref: Zir.Inst.Ref, | 13321 | item_ref: Zir.Inst.Ref, |
| 13359 | /// Coerce `item_ref` to this type. | 13322 | /// Coerce `item_ref` to this type. |
| 13360 | coerce_ty: Type, | 13323 | coerce_ty: Type, |
| 13361 | switch_node_offset: i32, | 13324 | item_src: LazySrcLoc, |
| 13362 | switch_prong_src: Module.SwitchProngSrc, | | |
| 13363 | range_expand: Module.SwitchProngSrc.RangeExpand, | | |
| 13364 | ) CompileError!ResolvedSwitchItem { | 13325 | ) CompileError!ResolvedSwitchItem { |
| 13365 | const mod = sema.mod; | | |
| 13366 | const uncoerced_item = try sema.resolveInst(item_ref); | 13326 | const uncoerced_item = try sema.resolveInst(item_ref); |
| 13367 | | 13327 | |
| 13368 | // Constructing a LazySrcLoc is costly because we only have the switch AST node. | 13328 | // Constructing a LazySrcLoc is costly because we only have the switch AST node. |
| 13369 | // Only if we know for sure we need to report a compile error do we resolve the | 13329 | // Only if we know for sure we need to report a compile error do we resolve the |
| 13370 | // full source locations. | 13330 | // full source locations. |
| 13371 | | 13331 | |
| 13372 | const item = sema.coerce(block, coerce_ty, uncoerced_item, .unneeded) catch |err| switch (err) { | 13332 | const item = try sema.coerce(block, coerce_ty, uncoerced_item, item_src); |
| 13373 | error.NeededSourceLocation => { | | |
| 13374 | const src = switch_prong_src.resolve(mod, mod.declPtr(block.src_decl), switch_node_offset, range_expand); | | |
| 13375 | _ = try sema.coerce(block, coerce_ty, uncoerced_item, src); | | |
| 13376 | unreachable; | | |
| 13377 | }, | | |
| 13378 | else => |e| return e, | | |
| 13379 | }; | | |
| 13380 | | 13333 | |
| 13381 | const maybe_lazy = sema.resolveConstDefinedValue(block, .unneeded, item, undefined) catch |err| switch (err) { | 13334 | const maybe_lazy = try sema.resolveConstDefinedValue(block, item_src, item, .{ |
| 13382 | error.NeededSourceLocation => { | 13335 | .needed_comptime_reason = "switch prong values must be comptime-known", |
| 13383 | const src = switch_prong_src.resolve(mod, mod.declPtr(block.src_decl), switch_node_offset, range_expand); | 13336 | }); |
| 13384 | _ = try sema.resolveConstDefinedValue(block, src, item, .{ | | |
| 13385 | .needed_comptime_reason = "switch prong values must be comptime-known", | | |
| 13386 | }); | | |
| 13387 | unreachable; | | |
| 13388 | }, | | |
| 13389 | else => |e| return e, | | |
| 13390 | }; | | |
| 13391 | | 13337 | |
| 13392 | const val = try sema.resolveLazyValue(maybe_lazy); | 13338 | const val = try sema.resolveLazyValue(maybe_lazy); |
| 13393 | const new_item = if (val.toIntern() != maybe_lazy.toIntern()) blk: { | 13339 | const new_item = if (val.toIntern() != maybe_lazy.toIntern()) blk: { |
| ... | @@ -13430,8 +13376,11 @@ fn validateErrSetSwitch( | ... | @@ -13430,8 +13376,11 @@ fn validateErrSetSwitch( |
| 13430 | seen_errors, | 13376 | seen_errors, |
| 13431 | item_ref, | 13377 | item_ref, |
| 13432 | operand_ty, | 13378 | operand_ty, |
| 13433 | src_node_offset, | 13379 | block.src(.{ .switch_case_item = .{ |
| 13434 | .{ .scalar = scalar_i }, | 13380 | .switch_node_offset = src_node_offset, |
| | 13381 | .case_idx = .{ .kind = .scalar, .index = @intCast(scalar_i) }, |
| | 13382 | .item_idx = .{ .kind = .single, .index = 0 }, |
| | 13383 | } }), |
| 13435 | )); | 13384 | )); |
| 13436 | } | 13385 | } |
| 13437 | } | 13386 | } |
| ... | @@ -13454,8 +13403,11 @@ fn validateErrSetSwitch( | ... | @@ -13454,8 +13403,11 @@ fn validateErrSetSwitch( |
| 13454 | seen_errors, | 13403 | seen_errors, |
| 13455 | item_ref, | 13404 | item_ref, |
| 13456 | operand_ty, | 13405 | operand_ty, |
| 13457 | src_node_offset, | 13406 | block.src(.{ .switch_case_item = .{ |
| 13458 | .{ .multi = .{ .prong = multi_i, .item = @intCast(item_i) } }, | 13407 | .switch_node_offset = src_node_offset, |
| | 13408 | .case_idx = .{ .kind = .multi, .index = @intCast(multi_i) }, |
| | 13409 | .item_idx = .{ .kind = .single, .index = @intCast(item_i) }, |
| | 13410 | } }), |
| 13459 | )); | 13411 | )); |
| 13460 | } | 13412 | } |
| 13461 | | 13413 | |
| ... | @@ -13484,7 +13436,6 @@ fn validateErrSetSwitch( | ... | @@ -13484,7 +13436,6 @@ fn validateErrSetSwitch( |
| 13484 | if (!seen_errors.contains(error_name) and !has_else) { | 13436 | if (!seen_errors.contains(error_name) and !has_else) { |
| 13485 | const msg = maybe_msg orelse blk: { | 13437 | const msg = maybe_msg orelse blk: { |
| 13486 | maybe_msg = try sema.errMsg( | 13438 | maybe_msg = try sema.errMsg( |
| 13487 | block, | | |
| 13488 | src, | 13439 | src, |
| 13489 | "switch must handle all possibilities", | 13440 | "switch must handle all possibilities", |
| 13490 | .{}, | 13441 | .{}, |
| ... | @@ -13493,7 +13444,6 @@ fn validateErrSetSwitch( | ... | @@ -13493,7 +13444,6 @@ fn validateErrSetSwitch( |
| 13493 | }; | 13444 | }; |
| 13494 | | 13445 | |
| 13495 | try sema.errNote( | 13446 | try sema.errNote( |
| 13496 | block, | | |
| 13497 | src, | 13447 | src, |
| 13498 | msg, | 13448 | msg, |
| 13499 | "unhandled error value: 'error.{}'", | 13449 | "unhandled error value: 'error.{}'", |
| ... | @@ -13571,18 +13521,24 @@ fn validateSwitchRange( | ... | @@ -13571,18 +13521,24 @@ fn validateSwitchRange( |
| 13571 | first_ref: Zir.Inst.Ref, | 13521 | first_ref: Zir.Inst.Ref, |
| 13572 | last_ref: Zir.Inst.Ref, | 13522 | last_ref: Zir.Inst.Ref, |
| 13573 | operand_ty: Type, | 13523 | operand_ty: Type, |
| 13574 | src_node_offset: i32, | 13524 | item_src: LazySrcLoc, |
| 13575 | switch_prong_src: Module.SwitchProngSrc, | | |
| 13576 | ) CompileError![2]Air.Inst.Ref { | 13525 | ) CompileError![2]Air.Inst.Ref { |
| 13577 | const mod = sema.mod; | 13526 | const mod = sema.mod; |
| 13578 | const first = try sema.resolveSwitchItemVal(block, first_ref, operand_ty, src_node_offset, switch_prong_src, .first); | 13527 | const first_src: LazySrcLoc = .{ |
| 13579 | const last = try sema.resolveSwitchItemVal(block, last_ref, operand_ty, src_node_offset, switch_prong_src, .last); | 13528 | .base_node_inst = item_src.base_node_inst, |
| | 13529 | .offset = .{ .switch_case_item_range_first = item_src.offset.switch_case_item }, |
| | 13530 | }; |
| | 13531 | const last_src: LazySrcLoc = .{ |
| | 13532 | .base_node_inst = item_src.base_node_inst, |
| | 13533 | .offset = .{ .switch_case_item_range_last = item_src.offset.switch_case_item }, |
| | 13534 | }; |
| | 13535 | const first = try sema.resolveSwitchItemVal(block, first_ref, operand_ty, first_src); |
| | 13536 | const last = try sema.resolveSwitchItemVal(block, last_ref, operand_ty, last_src); |
| 13580 | if (try Value.fromInterned(first.val).compareAll(.gt, Value.fromInterned(last.val), operand_ty, mod)) { | 13537 | if (try Value.fromInterned(first.val).compareAll(.gt, Value.fromInterned(last.val), operand_ty, mod)) { |
| 13581 | const src = switch_prong_src.resolve(mod, mod.declPtr(block.src_decl), src_node_offset, .first); | 13538 | return sema.fail(block, item_src, "range start value is greater than the end value", .{}); |
| 13582 | return sema.fail(block, src, "range start value is greater than the end value", .{}); | | |
| 13583 | } | 13539 | } |
| 13584 | const maybe_prev_src = try range_set.add(first.val, last.val, switch_prong_src); | 13540 | const maybe_prev_src = try range_set.add(first.val, last.val, item_src); |
| 13585 | try sema.validateSwitchDupe(block, maybe_prev_src, switch_prong_src, src_node_offset); | 13541 | try sema.validateSwitchDupe(block, maybe_prev_src, item_src); |
| 13586 | return .{ first.ref, last.ref }; | 13542 | return .{ first.ref, last.ref }; |
| 13587 | } | 13543 | } |
| 13588 | | 13544 | |
| ... | @@ -13592,36 +13548,34 @@ fn validateSwitchItemInt( | ... | @@ -13592,36 +13548,34 @@ fn validateSwitchItemInt( |
| 13592 | range_set: *RangeSet, | 13548 | range_set: *RangeSet, |
| 13593 | item_ref: Zir.Inst.Ref, | 13549 | item_ref: Zir.Inst.Ref, |
| 13594 | operand_ty: Type, | 13550 | operand_ty: Type, |
| 13595 | src_node_offset: i32, | 13551 | item_src: LazySrcLoc, |
| 13596 | switch_prong_src: Module.SwitchProngSrc, | | |
| 13597 | ) CompileError!Air.Inst.Ref { | 13552 | ) CompileError!Air.Inst.Ref { |
| 13598 | const item = try sema.resolveSwitchItemVal(block, item_ref, operand_ty, src_node_offset, switch_prong_src, .none); | 13553 | const item = try sema.resolveSwitchItemVal(block, item_ref, operand_ty, item_src); |
| 13599 | const maybe_prev_src = try range_set.add(item.val, item.val, switch_prong_src); | 13554 | const maybe_prev_src = try range_set.add(item.val, item.val, item_src); |
| 13600 | try sema.validateSwitchDupe(block, maybe_prev_src, switch_prong_src, src_node_offset); | 13555 | try sema.validateSwitchDupe(block, maybe_prev_src, item_src); |
| 13601 | return item.ref; | 13556 | return item.ref; |
| 13602 | } | 13557 | } |
| 13603 | | 13558 | |
| 13604 | fn validateSwitchItemEnum( | 13559 | fn validateSwitchItemEnum( |
| 13605 | sema: *Sema, | 13560 | sema: *Sema, |
| 13606 | block: *Block, | 13561 | block: *Block, |
| 13607 | seen_fields: []?Module.SwitchProngSrc, | 13562 | seen_fields: []?LazySrcLoc, |
| 13608 | range_set: *RangeSet, | 13563 | range_set: *RangeSet, |
| 13609 | item_ref: Zir.Inst.Ref, | 13564 | item_ref: Zir.Inst.Ref, |
| 13610 | operand_ty: Type, | 13565 | operand_ty: Type, |
| 13611 | src_node_offset: i32, | 13566 | item_src: LazySrcLoc, |
| 13612 | switch_prong_src: Module.SwitchProngSrc, | | |
| 13613 | ) CompileError!Air.Inst.Ref { | 13567 | ) CompileError!Air.Inst.Ref { |
| 13614 | const ip = &sema.mod.intern_pool; | 13568 | const ip = &sema.mod.intern_pool; |
| 13615 | const item = try sema.resolveSwitchItemVal(block, item_ref, operand_ty, src_node_offset, switch_prong_src, .none); | 13569 | const item = try sema.resolveSwitchItemVal(block, item_ref, operand_ty, item_src); |
| 13616 | const int = ip.indexToKey(item.val).enum_tag.int; | 13570 | const int = ip.indexToKey(item.val).enum_tag.int; |
| 13617 | const field_index = ip.loadEnumType(ip.typeOf(item.val)).tagValueIndex(ip, int) orelse { | 13571 | const field_index = ip.loadEnumType(ip.typeOf(item.val)).tagValueIndex(ip, int) orelse { |
| 13618 | const maybe_prev_src = try range_set.add(int, int, switch_prong_src); | 13572 | const maybe_prev_src = try range_set.add(int, int, item_src); |
| 13619 | try sema.validateSwitchDupe(block, maybe_prev_src, switch_prong_src, src_node_offset); | 13573 | try sema.validateSwitchDupe(block, maybe_prev_src, item_src); |
| 13620 | return item.ref; | 13574 | return item.ref; |
| 13621 | }; | 13575 | }; |
| 13622 | const maybe_prev_src = seen_fields[field_index]; | 13576 | const maybe_prev_src = seen_fields[field_index]; |
| 13623 | seen_fields[field_index] = switch_prong_src; | 13577 | seen_fields[field_index] = item_src; |
| 13624 | try sema.validateSwitchDupe(block, maybe_prev_src, switch_prong_src, src_node_offset); | 13578 | try sema.validateSwitchDupe(block, maybe_prev_src, item_src); |
| 13625 | return item.ref; | 13579 | return item.ref; |
| 13626 | } | 13580 | } |
| 13627 | | 13581 | |
| ... | @@ -13631,50 +13585,41 @@ fn validateSwitchItemError( | ... | @@ -13631,50 +13585,41 @@ fn validateSwitchItemError( |
| 13631 | seen_errors: *SwitchErrorSet, | 13585 | seen_errors: *SwitchErrorSet, |
| 13632 | item_ref: Zir.Inst.Ref, | 13586 | item_ref: Zir.Inst.Ref, |
| 13633 | operand_ty: Type, | 13587 | operand_ty: Type, |
| 13634 | src_node_offset: i32, | 13588 | item_src: LazySrcLoc, |
| 13635 | switch_prong_src: Module.SwitchProngSrc, | | |
| 13636 | ) CompileError!Air.Inst.Ref { | 13589 | ) CompileError!Air.Inst.Ref { |
| 13637 | const ip = &sema.mod.intern_pool; | 13590 | const ip = &sema.mod.intern_pool; |
| 13638 | const item = try sema.resolveSwitchItemVal(block, item_ref, operand_ty, src_node_offset, switch_prong_src, .none); | 13591 | const item = try sema.resolveSwitchItemVal(block, item_ref, operand_ty, item_src); |
| 13639 | const error_name = ip.indexToKey(item.val).err.name; | 13592 | const error_name = ip.indexToKey(item.val).err.name; |
| 13640 | const maybe_prev_src = if (try seen_errors.fetchPut(error_name, switch_prong_src)) |prev| | 13593 | const maybe_prev_src = if (try seen_errors.fetchPut(error_name, item_src)) |prev| |
| 13641 | prev.value | 13594 | prev.value |
| 13642 | else | 13595 | else |
| 13643 | null; | 13596 | null; |
| 13644 | try sema.validateSwitchDupe(block, maybe_prev_src, switch_prong_src, src_node_offset); | 13597 | try sema.validateSwitchDupe(block, maybe_prev_src, item_src); |
| 13645 | return item.ref; | 13598 | return item.ref; |
| 13646 | } | 13599 | } |
| 13647 | | 13600 | |
| 13648 | fn validateSwitchDupe( | 13601 | fn validateSwitchDupe( |
| 13649 | sema: *Sema, | 13602 | sema: *Sema, |
| 13650 | block: *Block, | 13603 | block: *Block, |
| 13651 | maybe_prev_src: ?Module.SwitchProngSrc, | 13604 | maybe_prev_src: ?LazySrcLoc, |
| 13652 | switch_prong_src: Module.SwitchProngSrc, | 13605 | item_src: LazySrcLoc, |
| 13653 | src_node_offset: i32, | | |
| 13654 | ) CompileError!void { | 13606 | ) CompileError!void { |
| 13655 | const prev_prong_src = maybe_prev_src orelse return; | 13607 | const prev_item_src = maybe_prev_src orelse return; |
| 13656 | const mod = sema.mod; | 13608 | return sema.failWithOwnedErrorMsg(block, msg: { |
| 13657 | const block_src_decl = mod.declPtr(block.src_decl); | | |
| 13658 | const src = switch_prong_src.resolve(mod, block_src_decl, src_node_offset, .none); | | |
| 13659 | const prev_src = prev_prong_src.resolve(mod, block_src_decl, src_node_offset, .none); | | |
| 13660 | const msg = msg: { | | |
| 13661 | const msg = try sema.errMsg( | 13609 | const msg = try sema.errMsg( |
| 13662 | block, | 13610 | item_src, |
| 13663 | src, | | |
| 13664 | "duplicate switch value", | 13611 | "duplicate switch value", |
| 13665 | .{}, | 13612 | .{}, |
| 13666 | ); | 13613 | ); |
| 13667 | errdefer msg.destroy(sema.gpa); | 13614 | errdefer msg.destroy(sema.gpa); |
| 13668 | try sema.errNote( | 13615 | try sema.errNote( |
| 13669 | block, | 13616 | prev_item_src, |
| 13670 | prev_src, | | |
| 13671 | msg, | 13617 | msg, |
| 13672 | "previous value here", | 13618 | "previous value here", |
| 13673 | .{}, | 13619 | .{}, |
| 13674 | ); | 13620 | ); |
| 13675 | break :msg msg; | 13621 | break :msg msg; |
| 13676 | }; | 13622 | }); |
| 13677 | return sema.failWithOwnedErrorMsg(block, msg); | | |
| 13678 | } | 13623 | } |
| 13679 | | 13624 | |
| 13680 | fn validateSwitchItemBool( | 13625 | fn validateSwitchItemBool( |
| ... | @@ -13683,25 +13628,21 @@ fn validateSwitchItemBool( | ... | @@ -13683,25 +13628,21 @@ fn validateSwitchItemBool( |
| 13683 | true_count: *u8, | 13628 | true_count: *u8, |
| 13684 | false_count: *u8, | 13629 | false_count: *u8, |
| 13685 | item_ref: Zir.Inst.Ref, | 13630 | item_ref: Zir.Inst.Ref, |
| 13686 | src_node_offset: i32, | 13631 | item_src: LazySrcLoc, |
| 13687 | switch_prong_src: Module.SwitchProngSrc, | | |
| 13688 | ) CompileError!Air.Inst.Ref { | 13632 | ) CompileError!Air.Inst.Ref { |
| 13689 | const mod = sema.mod; | 13633 | const item = try sema.resolveSwitchItemVal(block, item_ref, Type.bool, item_src); |
| 13690 | const item = try sema.resolveSwitchItemVal(block, item_ref, Type.bool, src_node_offset, switch_prong_src, .none); | | |
| 13691 | if (Value.fromInterned(item.val).toBool()) { | 13634 | if (Value.fromInterned(item.val).toBool()) { |
| 13692 | true_count.* += 1; | 13635 | true_count.* += 1; |
| 13693 | } else { | 13636 | } else { |
| 13694 | false_count.* += 1; | 13637 | false_count.* += 1; |
| 13695 | } | 13638 | } |
| 13696 | if (true_count.* > 1 or false_count.* > 1) { | 13639 | if (true_count.* > 1 or false_count.* > 1) { |
| 13697 | const block_src_decl = sema.mod.declPtr(block.src_decl); | 13640 | return sema.fail(block, item_src, "duplicate switch value", .{}); |
| 13698 | const src = switch_prong_src.resolve(mod, block_src_decl, src_node_offset, .none); | | |
| 13699 | return sema.fail(block, src, "duplicate switch value", .{}); | | |
| 13700 | } | 13641 | } |
| 13701 | return item.ref; | 13642 | return item.ref; |
| 13702 | } | 13643 | } |
| 13703 | | 13644 | |
| 13704 | const ValueSrcMap = std.AutoHashMapUnmanaged(InternPool.Index, Module.SwitchProngSrc); | 13645 | const ValueSrcMap = std.AutoHashMapUnmanaged(InternPool.Index, LazySrcLoc); |
| 13705 | | 13646 | |
| 13706 | fn validateSwitchItemSparse( | 13647 | fn validateSwitchItemSparse( |
| 13707 | sema: *Sema, | 13648 | sema: *Sema, |
| ... | @@ -13709,12 +13650,11 @@ fn validateSwitchItemSparse( | ... | @@ -13709,12 +13650,11 @@ fn validateSwitchItemSparse( |
| 13709 | seen_values: *ValueSrcMap, | 13650 | seen_values: *ValueSrcMap, |
| 13710 | item_ref: Zir.Inst.Ref, | 13651 | item_ref: Zir.Inst.Ref, |
| 13711 | operand_ty: Type, | 13652 | operand_ty: Type, |
| 13712 | src_node_offset: i32, | 13653 | item_src: LazySrcLoc, |
| 13713 | switch_prong_src: Module.SwitchProngSrc, | | |
| 13714 | ) CompileError!Air.Inst.Ref { | 13654 | ) CompileError!Air.Inst.Ref { |
| 13715 | const item = try sema.resolveSwitchItemVal(block, item_ref, operand_ty, src_node_offset, switch_prong_src, .none); | 13655 | const item = try sema.resolveSwitchItemVal(block, item_ref, operand_ty, item_src); |
| 13716 | const kv = (try seen_values.fetchPut(sema.gpa, item.val, switch_prong_src)) orelse return item.ref; | 13656 | const kv = try seen_values.fetchPut(sema.gpa, item.val, item_src) orelse return item.ref; |
| 13717 | try sema.validateSwitchDupe(block, kv.value, switch_prong_src, src_node_offset); | 13657 | try sema.validateSwitchDupe(block, kv.value, item_src); |
| 13718 | unreachable; | 13658 | unreachable; |
| 13719 | } | 13659 | } |
| 13720 | | 13660 | |
| ... | @@ -13728,19 +13668,17 @@ fn validateSwitchNoRange( | ... | @@ -13728,19 +13668,17 @@ fn validateSwitchNoRange( |
| 13728 | if (ranges_len == 0) | 13668 | if (ranges_len == 0) |
| 13729 | return; | 13669 | return; |
| 13730 | | 13670 | |
| 13731 | const operand_src: LazySrcLoc = .{ .node_offset_switch_operand = src_node_offset }; | 13671 | const operand_src = block.src(.{ .node_offset_switch_operand = src_node_offset }); |
| 13732 | const range_src: LazySrcLoc = .{ .node_offset_switch_range = src_node_offset }; | 13672 | const range_src = block.src(.{ .node_offset_switch_range = src_node_offset }); |
| 13733 | | 13673 | |
| 13734 | const msg = msg: { | 13674 | const msg = msg: { |
| 13735 | const msg = try sema.errMsg( | 13675 | const msg = try sema.errMsg( |
| 13736 | block, | | |
| 13737 | operand_src, | 13676 | operand_src, |
| 13738 | "ranges not allowed when switching on type '{}'", | 13677 | "ranges not allowed when switching on type '{}'", |
| 13739 | .{operand_ty.fmt(sema.mod)}, | 13678 | .{operand_ty.fmt(sema.mod)}, |
| 13740 | ); | 13679 | ); |
| 13741 | errdefer msg.destroy(sema.gpa); | 13680 | errdefer msg.destroy(sema.gpa); |
| 13742 | try sema.errNote( | 13681 | try sema.errNote( |
| 13743 | block, | | |
| 13744 | range_src, | 13682 | range_src, |
| 13745 | msg, | 13683 | msg, |
| 13746 | "range here", | 13684 | "range here", |
| ... | @@ -13867,8 +13805,8 @@ fn zirHasField(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -13867,8 +13805,8 @@ fn zirHasField(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 13867 | const mod = sema.mod; | 13805 | const mod = sema.mod; |
| 13868 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 13806 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 13869 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; | 13807 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 13870 | const ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 13808 | const ty_src = block.builtinCallArgSrc(inst_data.src_node, 0); |
| 13871 | const name_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; | 13809 | const name_src = block.builtinCallArgSrc(inst_data.src_node, 1); |
| 13872 | const ty = try sema.resolveType(block, ty_src, extra.lhs); | 13810 | const ty = try sema.resolveType(block, ty_src, extra.lhs); |
| 13873 | const field_name = try sema.resolveConstStringIntern(block, name_src, extra.rhs, .{ | 13811 | const field_name = try sema.resolveConstStringIntern(block, name_src, extra.rhs, .{ |
| 13874 | .needed_comptime_reason = "field name must be comptime-known", | 13812 | .needed_comptime_reason = "field name must be comptime-known", |
| ... | @@ -13919,8 +13857,8 @@ fn zirHasDecl(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air | ... | @@ -13919,8 +13857,8 @@ fn zirHasDecl(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 13919 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 13857 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 13920 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; | 13858 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 13921 | const src = block.nodeOffset(inst_data.src_node); | 13859 | const src = block.nodeOffset(inst_data.src_node); |
| 13922 | const lhs_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 13860 | const lhs_src = block.builtinCallArgSrc(inst_data.src_node, 0); |
| 13923 | const rhs_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; | 13861 | const rhs_src = block.builtinCallArgSrc(inst_data.src_node, 1); |
| 13924 | const container_type = try sema.resolveType(block, lhs_src, extra.lhs); | 13862 | const container_type = try sema.resolveType(block, lhs_src, extra.lhs); |
| 13925 | const decl_name = try sema.resolveConstStringIntern(block, rhs_src, extra.rhs, .{ | 13863 | const decl_name = try sema.resolveConstStringIntern(block, rhs_src, extra.rhs, .{ |
| 13926 | .needed_comptime_reason = "decl name must be comptime-known", | 13864 | .needed_comptime_reason = "decl name must be comptime-known", |
| ... | @@ -13979,7 +13917,7 @@ fn zirEmbedFile(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A | ... | @@ -13979,7 +13917,7 @@ fn zirEmbedFile(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 13979 | | 13917 | |
| 13980 | const mod = sema.mod; | 13918 | const mod = sema.mod; |
| 13981 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; | 13919 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 13982 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 13920 | const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0); |
| 13983 | const name = try sema.resolveConstString(block, operand_src, inst_data.operand, .{ | 13921 | const name = try sema.resolveConstString(block, operand_src, inst_data.operand, .{ |
| 13984 | .needed_comptime_reason = "file path name must be comptime-known", | 13922 | .needed_comptime_reason = "file path name must be comptime-known", |
| 13985 | }); | 13923 | }); |
| ... | @@ -13988,8 +13926,7 @@ fn zirEmbedFile(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A | ... | @@ -13988,8 +13926,7 @@ fn zirEmbedFile(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 13988 | return sema.fail(block, operand_src, "file path name cannot be empty", .{}); | 13926 | return sema.fail(block, operand_src, "file path name cannot be empty", .{}); |
| 13989 | } | 13927 | } |
| 13990 | | 13928 | |
| 13991 | const src_loc = mod.declPtr(block.src_decl).toSrcLoc(operand_src, mod); | 13929 | const val = mod.embedFile(block.getFileScope(mod), name, operand_src.upgrade(mod)) catch |err| switch (err) { |
| 13992 | const val = mod.embedFile(block.getFileScope(mod), name, src_loc) catch |err| switch (err) { | | |
| 13993 | error.ImportOutsideModulePath => { | 13930 | error.ImportOutsideModulePath => { |
| 13994 | return sema.fail(block, operand_src, "embed of file outside package path: '{s}'", .{name}); | 13931 | return sema.fail(block, operand_src, "embed of file outside package path: '{s}'", .{name}); |
| 13995 | }, | 13932 | }, |
| ... | @@ -14031,8 +13968,8 @@ fn zirShl( | ... | @@ -14031,8 +13968,8 @@ fn zirShl( |
| 14031 | const mod = sema.mod; | 13968 | const mod = sema.mod; |
| 14032 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 13969 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 14033 | const src = block.nodeOffset(inst_data.src_node); | 13970 | const src = block.nodeOffset(inst_data.src_node); |
| 14034 | const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node }; | 13971 | const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node }); |
| 14035 | const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node }; | 13972 | const rhs_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node }); |
| 14036 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; | 13973 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 14037 | const lhs = try sema.resolveInst(extra.lhs); | 13974 | const lhs = try sema.resolveInst(extra.lhs); |
| 14038 | const rhs = try sema.resolveInst(extra.rhs); | 13975 | const rhs = try sema.resolveInst(extra.rhs); |
| ... | @@ -14201,8 +14138,8 @@ fn zirShr( | ... | @@ -14201,8 +14138,8 @@ fn zirShr( |
| 14201 | const mod = sema.mod; | 14138 | const mod = sema.mod; |
| 14202 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 14139 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 14203 | const src = block.nodeOffset(inst_data.src_node); | 14140 | const src = block.nodeOffset(inst_data.src_node); |
| 14204 | const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node }; | 14141 | const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node }); |
| 14205 | const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node }; | 14142 | const rhs_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node }); |
| 14206 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; | 14143 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 14207 | const lhs = try sema.resolveInst(extra.lhs); | 14144 | const lhs = try sema.resolveInst(extra.lhs); |
| 14208 | const rhs = try sema.resolveInst(extra.rhs); | 14145 | const rhs = try sema.resolveInst(extra.rhs); |
| ... | @@ -14335,9 +14272,9 @@ fn zirBitwise( | ... | @@ -14335,9 +14272,9 @@ fn zirBitwise( |
| 14335 | | 14272 | |
| 14336 | const mod = sema.mod; | 14273 | const mod = sema.mod; |
| 14337 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 14274 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 14338 | const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node }; | 14275 | const src = block.src(.{ .node_offset_bin_op = inst_data.src_node }); |
| 14339 | const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node }; | 14276 | const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node }); |
| 14340 | const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node }; | 14277 | const rhs_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node }); |
| 14341 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; | 14278 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 14342 | const lhs = try sema.resolveInst(extra.lhs); | 14279 | const lhs = try sema.resolveInst(extra.lhs); |
| 14343 | const rhs = try sema.resolveInst(extra.rhs); | 14280 | const rhs = try sema.resolveInst(extra.rhs); |
| ... | @@ -14390,7 +14327,7 @@ fn zirBitNot(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. | ... | @@ -14390,7 +14327,7 @@ fn zirBitNot(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. |
| 14390 | const mod = sema.mod; | 14327 | const mod = sema.mod; |
| 14391 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; | 14328 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 14392 | const src = block.nodeOffset(inst_data.src_node); | 14329 | const src = block.nodeOffset(inst_data.src_node); |
| 14393 | const operand_src: LazySrcLoc = .{ .node_offset_un_op = inst_data.src_node }; | 14330 | const operand_src = block.src(.{ .node_offset_un_op = inst_data.src_node }); |
| 14394 | | 14331 | |
| 14395 | const operand = try sema.resolveInst(inst_data.operand); | 14332 | const operand = try sema.resolveInst(inst_data.operand); |
| 14396 | const operand_type = sema.typeOf(operand); | 14333 | const operand_type = sema.typeOf(operand); |
| ... | @@ -14436,7 +14373,7 @@ fn analyzeTupleCat( | ... | @@ -14436,7 +14373,7 @@ fn analyzeTupleCat( |
| 14436 | const mod = sema.mod; | 14373 | const mod = sema.mod; |
| 14437 | const lhs_ty = sema.typeOf(lhs); | 14374 | const lhs_ty = sema.typeOf(lhs); |
| 14438 | const rhs_ty = sema.typeOf(rhs); | 14375 | const rhs_ty = sema.typeOf(rhs); |
| 14439 | const src = LazySrcLoc.nodeOffset(src_node); | 14376 | const src = block.nodeOffset(src_node); |
| 14440 | | 14377 | |
| 14441 | const lhs_len = lhs_ty.structFieldCount(mod); | 14378 | const lhs_len = lhs_ty.structFieldCount(mod); |
| 14442 | const rhs_len = rhs_ty.structFieldCount(mod); | 14379 | const rhs_len = rhs_ty.structFieldCount(mod); |
| ... | @@ -14463,10 +14400,10 @@ fn analyzeTupleCat( | ... | @@ -14463,10 +14400,10 @@ fn analyzeTupleCat( |
| 14463 | types[i] = lhs_ty.structFieldType(i, mod).toIntern(); | 14400 | types[i] = lhs_ty.structFieldType(i, mod).toIntern(); |
| 14464 | const default_val = lhs_ty.structFieldDefaultValue(i, mod); | 14401 | const default_val = lhs_ty.structFieldDefaultValue(i, mod); |
| 14465 | values[i] = default_val.toIntern(); | 14402 | values[i] = default_val.toIntern(); |
| 14466 | const operand_src: LazySrcLoc = .{ .array_cat_lhs = .{ | 14403 | const operand_src = block.src(.{ .array_cat_lhs = .{ |
| 14467 | .array_cat_offset = src_node, | 14404 | .array_cat_offset = src_node, |
| 14468 | .elem_index = i, | 14405 | .elem_index = i, |
| 14469 | } }; | 14406 | } }); |
| 14470 | if (default_val.toIntern() == .unreachable_value) { | 14407 | if (default_val.toIntern() == .unreachable_value) { |
| 14471 | runtime_src = operand_src; | 14408 | runtime_src = operand_src; |
| 14472 | values[i] = .none; | 14409 | values[i] = .none; |
| ... | @@ -14477,10 +14414,10 @@ fn analyzeTupleCat( | ... | @@ -14477,10 +14414,10 @@ fn analyzeTupleCat( |
| 14477 | types[i + lhs_len] = rhs_ty.structFieldType(i, mod).toIntern(); | 14414 | types[i + lhs_len] = rhs_ty.structFieldType(i, mod).toIntern(); |
| 14478 | const default_val = rhs_ty.structFieldDefaultValue(i, mod); | 14415 | const default_val = rhs_ty.structFieldDefaultValue(i, mod); |
| 14479 | values[i + lhs_len] = default_val.toIntern(); | 14416 | values[i + lhs_len] = default_val.toIntern(); |
| 14480 | const operand_src: LazySrcLoc = .{ .array_cat_rhs = .{ | 14417 | const operand_src = block.src(.{ .array_cat_rhs = .{ |
| 14481 | .array_cat_offset = src_node, | 14418 | .array_cat_offset = src_node, |
| 14482 | .elem_index = i, | 14419 | .elem_index = i, |
| 14483 | } }; | 14420 | } }); |
| 14484 | if (default_val.toIntern() == .unreachable_value) { | 14421 | if (default_val.toIntern() == .unreachable_value) { |
| 14485 | runtime_src = operand_src; | 14422 | runtime_src = operand_src; |
| 14486 | values[i + lhs_len] = .none; | 14423 | values[i + lhs_len] = .none; |
| ... | @@ -14508,18 +14445,18 @@ fn analyzeTupleCat( | ... | @@ -14508,18 +14445,18 @@ fn analyzeTupleCat( |
| 14508 | const element_refs = try sema.arena.alloc(Air.Inst.Ref, final_len); | 14445 | const element_refs = try sema.arena.alloc(Air.Inst.Ref, final_len); |
| 14509 | var i: u32 = 0; | 14446 | var i: u32 = 0; |
| 14510 | while (i < lhs_len) : (i += 1) { | 14447 | while (i < lhs_len) : (i += 1) { |
| 14511 | const operand_src: LazySrcLoc = .{ .array_cat_lhs = .{ | 14448 | const operand_src = block.src(.{ .array_cat_lhs = .{ |
| 14512 | .array_cat_offset = src_node, | 14449 | .array_cat_offset = src_node, |
| 14513 | .elem_index = i, | 14450 | .elem_index = i, |
| 14514 | } }; | 14451 | } }); |
| 14515 | element_refs[i] = try sema.tupleFieldValByIndex(block, operand_src, lhs, i, lhs_ty); | 14452 | element_refs[i] = try sema.tupleFieldValByIndex(block, operand_src, lhs, i, lhs_ty); |
| 14516 | } | 14453 | } |
| 14517 | i = 0; | 14454 | i = 0; |
| 14518 | while (i < rhs_len) : (i += 1) { | 14455 | while (i < rhs_len) : (i += 1) { |
| 14519 | const operand_src: LazySrcLoc = .{ .array_cat_rhs = .{ | 14456 | const operand_src = block.src(.{ .array_cat_rhs = .{ |
| 14520 | .array_cat_offset = src_node, | 14457 | .array_cat_offset = src_node, |
| 14521 | .elem_index = i, | 14458 | .elem_index = i, |
| 14522 | } }; | 14459 | } }); |
| 14523 | element_refs[i + lhs_len] = | 14460 | element_refs[i + lhs_len] = |
| 14524 | try sema.tupleFieldValByIndex(block, operand_src, rhs, i, rhs_ty); | 14461 | try sema.tupleFieldValByIndex(block, operand_src, rhs, i, rhs_ty); |
| 14525 | } | 14462 | } |
| ... | @@ -14546,8 +14483,8 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -14546,8 +14483,8 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 14546 | return sema.analyzeTupleCat(block, inst_data.src_node, lhs, rhs); | 14483 | return sema.analyzeTupleCat(block, inst_data.src_node, lhs, rhs); |
| 14547 | } | 14484 | } |
| 14548 | | 14485 | |
| 14549 | const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node }; | 14486 | const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node }); |
| 14550 | const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node }; | 14487 | const rhs_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node }); |
| 14551 | | 14488 | |
| 14552 | const lhs_info = try sema.getArrayCatInfo(block, lhs_src, lhs, rhs_ty) orelse lhs_info: { | 14489 | const lhs_info = try sema.getArrayCatInfo(block, lhs_src, lhs, rhs_ty) orelse lhs_info: { |
| 14553 | if (lhs_is_tuple) break :lhs_info @as(Type.ArrayInfo, undefined); | 14490 | if (lhs_is_tuple) break :lhs_info @as(Type.ArrayInfo, undefined); |
| ... | @@ -14659,10 +14596,10 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -14659,10 +14596,10 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 14659 | const elem_default_val = if (lhs_is_tuple) lhs_ty.structFieldDefaultValue(lhs_elem_i, mod) else Value.@"unreachable"; | 14596 | const elem_default_val = if (lhs_is_tuple) lhs_ty.structFieldDefaultValue(lhs_elem_i, mod) else Value.@"unreachable"; |
| 14660 | const elem_val = if (elem_default_val.toIntern() == .unreachable_value) try lhs_sub_val.elemValue(mod, lhs_elem_i) else elem_default_val; | 14597 | const elem_val = if (elem_default_val.toIntern() == .unreachable_value) try lhs_sub_val.elemValue(mod, lhs_elem_i) else elem_default_val; |
| 14661 | const elem_val_inst = Air.internedToRef(elem_val.toIntern()); | 14598 | const elem_val_inst = Air.internedToRef(elem_val.toIntern()); |
| 14662 | const operand_src: LazySrcLoc = .{ .array_cat_lhs = .{ | 14599 | const operand_src = block.src(.{ .array_cat_lhs = .{ |
| 14663 | .array_cat_offset = inst_data.src_node, | 14600 | .array_cat_offset = inst_data.src_node, |
| 14664 | .elem_index = elem_i, | 14601 | .elem_index = elem_i, |
| 14665 | } }; | 14602 | } }); |
| 14666 | const coerced_elem_val_inst = try sema.coerce(block, resolved_elem_ty, elem_val_inst, operand_src); | 14603 | const coerced_elem_val_inst = try sema.coerce(block, resolved_elem_ty, elem_val_inst, operand_src); |
| 14667 | const coerced_elem_val = try sema.resolveConstValue(block, operand_src, coerced_elem_val_inst, undefined); | 14604 | const coerced_elem_val = try sema.resolveConstValue(block, operand_src, coerced_elem_val_inst, undefined); |
| 14668 | element_vals[elem_i] = coerced_elem_val.toIntern(); | 14605 | element_vals[elem_i] = coerced_elem_val.toIntern(); |
| ... | @@ -14672,10 +14609,10 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -14672,10 +14609,10 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 14672 | const elem_default_val = if (rhs_is_tuple) rhs_ty.structFieldDefaultValue(rhs_elem_i, mod) else Value.@"unreachable"; | 14609 | const elem_default_val = if (rhs_is_tuple) rhs_ty.structFieldDefaultValue(rhs_elem_i, mod) else Value.@"unreachable"; |
| 14673 | const elem_val = if (elem_default_val.toIntern() == .unreachable_value) try rhs_sub_val.elemValue(mod, rhs_elem_i) else elem_default_val; | 14610 | const elem_val = if (elem_default_val.toIntern() == .unreachable_value) try rhs_sub_val.elemValue(mod, rhs_elem_i) else elem_default_val; |
| 14674 | const elem_val_inst = Air.internedToRef(elem_val.toIntern()); | 14611 | const elem_val_inst = Air.internedToRef(elem_val.toIntern()); |
| 14675 | const operand_src: LazySrcLoc = .{ .array_cat_rhs = .{ | 14612 | const operand_src = block.src(.{ .array_cat_rhs = .{ |
| 14676 | .array_cat_offset = inst_data.src_node, | 14613 | .array_cat_offset = inst_data.src_node, |
| 14677 | .elem_index = @intCast(rhs_elem_i), | 14614 | .elem_index = @intCast(rhs_elem_i), |
| 14678 | } }; | 14615 | } }); |
| 14679 | const coerced_elem_val_inst = try sema.coerce(block, resolved_elem_ty, elem_val_inst, operand_src); | 14616 | const coerced_elem_val_inst = try sema.coerce(block, resolved_elem_ty, elem_val_inst, operand_src); |
| 14680 | const coerced_elem_val = try sema.resolveConstValue(block, operand_src, coerced_elem_val_inst, undefined); | 14617 | const coerced_elem_val = try sema.resolveConstValue(block, operand_src, coerced_elem_val_inst, undefined); |
| 14681 | element_vals[elem_i] = coerced_elem_val.toIntern(); | 14618 | element_vals[elem_i] = coerced_elem_val.toIntern(); |
| ... | @@ -14704,10 +14641,10 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -14704,10 +14641,10 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 14704 | while (elem_i < lhs_len) : (elem_i += 1) { | 14641 | while (elem_i < lhs_len) : (elem_i += 1) { |
| 14705 | const elem_index = try mod.intRef(Type.usize, elem_i); | 14642 | const elem_index = try mod.intRef(Type.usize, elem_i); |
| 14706 | const elem_ptr = try block.addPtrElemPtr(alloc, elem_index, elem_ptr_ty); | 14643 | const elem_ptr = try block.addPtrElemPtr(alloc, elem_index, elem_ptr_ty); |
| 14707 | const operand_src: LazySrcLoc = .{ .array_cat_lhs = .{ | 14644 | const operand_src = block.src(.{ .array_cat_lhs = .{ |
| 14708 | .array_cat_offset = inst_data.src_node, | 14645 | .array_cat_offset = inst_data.src_node, |
| 14709 | .elem_index = elem_i, | 14646 | .elem_index = elem_i, |
| 14710 | } }; | 14647 | } }); |
| 14711 | const init = try sema.elemVal(block, operand_src, lhs, elem_index, src, true); | 14648 | const init = try sema.elemVal(block, operand_src, lhs, elem_index, src, true); |
| 14712 | try sema.storePtr2(block, src, elem_ptr, src, init, operand_src, .store); | 14649 | try sema.storePtr2(block, src, elem_ptr, src, init, operand_src, .store); |
| 14713 | } | 14650 | } |
| ... | @@ -14716,10 +14653,10 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -14716,10 +14653,10 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 14716 | const elem_index = try mod.intRef(Type.usize, elem_i); | 14653 | const elem_index = try mod.intRef(Type.usize, elem_i); |
| 14717 | const rhs_index = try mod.intRef(Type.usize, rhs_elem_i); | 14654 | const rhs_index = try mod.intRef(Type.usize, rhs_elem_i); |
| 14718 | const elem_ptr = try block.addPtrElemPtr(alloc, elem_index, elem_ptr_ty); | 14655 | const elem_ptr = try block.addPtrElemPtr(alloc, elem_index, elem_ptr_ty); |
| 14719 | const operand_src: LazySrcLoc = .{ .array_cat_rhs = .{ | 14656 | const operand_src = block.src(.{ .array_cat_rhs = .{ |
| 14720 | .array_cat_offset = inst_data.src_node, | 14657 | .array_cat_offset = inst_data.src_node, |
| 14721 | .elem_index = @intCast(rhs_elem_i), | 14658 | .elem_index = @intCast(rhs_elem_i), |
| 14722 | } }; | 14659 | } }); |
| 14723 | const init = try sema.elemVal(block, operand_src, rhs, rhs_index, src, true); | 14660 | const init = try sema.elemVal(block, operand_src, rhs, rhs_index, src, true); |
| 14724 | try sema.storePtr2(block, src, elem_ptr, src, init, operand_src, .store); | 14661 | try sema.storePtr2(block, src, elem_ptr, src, init, operand_src, .store); |
| 14725 | } | 14662 | } |
| ... | @@ -14738,20 +14675,20 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -14738,20 +14675,20 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 14738 | var elem_i: u32 = 0; | 14675 | var elem_i: u32 = 0; |
| 14739 | while (elem_i < lhs_len) : (elem_i += 1) { | 14676 | while (elem_i < lhs_len) : (elem_i += 1) { |
| 14740 | const index = try mod.intRef(Type.usize, elem_i); | 14677 | const index = try mod.intRef(Type.usize, elem_i); |
| 14741 | const operand_src: LazySrcLoc = .{ .array_cat_lhs = .{ | 14678 | const operand_src = block.src(.{ .array_cat_lhs = .{ |
| 14742 | .array_cat_offset = inst_data.src_node, | 14679 | .array_cat_offset = inst_data.src_node, |
| 14743 | .elem_index = elem_i, | 14680 | .elem_index = elem_i, |
| 14744 | } }; | 14681 | } }); |
| 14745 | const init = try sema.elemVal(block, operand_src, lhs, index, src, true); | 14682 | const init = try sema.elemVal(block, operand_src, lhs, index, src, true); |
| 14746 | element_refs[elem_i] = try sema.coerce(block, resolved_elem_ty, init, operand_src); | 14683 | element_refs[elem_i] = try sema.coerce(block, resolved_elem_ty, init, operand_src); |
| 14747 | } | 14684 | } |
| 14748 | while (elem_i < result_len) : (elem_i += 1) { | 14685 | while (elem_i < result_len) : (elem_i += 1) { |
| 14749 | const rhs_elem_i = elem_i - lhs_len; | 14686 | const rhs_elem_i = elem_i - lhs_len; |
| 14750 | const index = try mod.intRef(Type.usize, rhs_elem_i); | 14687 | const index = try mod.intRef(Type.usize, rhs_elem_i); |
| 14751 | const operand_src: LazySrcLoc = .{ .array_cat_rhs = .{ | 14688 | const operand_src = block.src(.{ .array_cat_rhs = .{ |
| 14752 | .array_cat_offset = inst_data.src_node, | 14689 | .array_cat_offset = inst_data.src_node, |
| 14753 | .elem_index = @intCast(rhs_elem_i), | 14690 | .elem_index = @intCast(rhs_elem_i), |
| 14754 | } }; | 14691 | } }); |
| 14755 | const init = try sema.elemVal(block, operand_src, rhs, index, src, true); | 14692 | const init = try sema.elemVal(block, operand_src, rhs, index, src, true); |
| 14756 | element_refs[elem_i] = try sema.coerce(block, resolved_elem_ty, init, operand_src); | 14693 | element_refs[elem_i] = try sema.coerce(block, resolved_elem_ty, init, operand_src); |
| 14757 | } | 14694 | } |
| ... | @@ -14813,8 +14750,8 @@ fn analyzeTupleMul( | ... | @@ -14813,8 +14750,8 @@ fn analyzeTupleMul( |
| 14813 | ) CompileError!Air.Inst.Ref { | 14750 | ) CompileError!Air.Inst.Ref { |
| 14814 | const mod = sema.mod; | 14751 | const mod = sema.mod; |
| 14815 | const operand_ty = sema.typeOf(operand); | 14752 | const operand_ty = sema.typeOf(operand); |
| 14816 | const src = LazySrcLoc.nodeOffset(src_node); | 14753 | const src = block.nodeOffset(src_node); |
| 14817 | const len_src: LazySrcLoc = .{ .node_offset_bin_rhs = src_node }; | 14754 | const len_src = block.src(.{ .node_offset_bin_rhs = src_node }); |
| 14818 | | 14755 | |
| 14819 | const tuple_len = operand_ty.structFieldCount(mod); | 14756 | const tuple_len = operand_ty.structFieldCount(mod); |
| 14820 | const final_len = std.math.mul(usize, tuple_len, factor) catch | 14757 | const final_len = std.math.mul(usize, tuple_len, factor) catch |
| ... | @@ -14831,10 +14768,10 @@ fn analyzeTupleMul( | ... | @@ -14831,10 +14768,10 @@ fn analyzeTupleMul( |
| 14831 | for (0..tuple_len) |i| { | 14768 | for (0..tuple_len) |i| { |
| 14832 | types[i] = operand_ty.structFieldType(i, mod).toIntern(); | 14769 | types[i] = operand_ty.structFieldType(i, mod).toIntern(); |
| 14833 | values[i] = operand_ty.structFieldDefaultValue(i, mod).toIntern(); | 14770 | values[i] = operand_ty.structFieldDefaultValue(i, mod).toIntern(); |
| 14834 | const operand_src: LazySrcLoc = .{ .array_cat_lhs = .{ | 14771 | const operand_src = block.src(.{ .array_cat_lhs = .{ |
| 14835 | .array_cat_offset = src_node, | 14772 | .array_cat_offset = src_node, |
| 14836 | .elem_index = @intCast(i), | 14773 | .elem_index = @intCast(i), |
| 14837 | } }; | 14774 | } }); |
| 14838 | if (values[i] == .unreachable_value) { | 14775 | if (values[i] == .unreachable_value) { |
| 14839 | runtime_src = operand_src; | 14776 | runtime_src = operand_src; |
| 14840 | values[i] = .none; // TODO don't treat unreachable_value as special | 14777 | values[i] = .none; // TODO don't treat unreachable_value as special |
| ... | @@ -14866,10 +14803,10 @@ fn analyzeTupleMul( | ... | @@ -14866,10 +14803,10 @@ fn analyzeTupleMul( |
| 14866 | const element_refs = try sema.arena.alloc(Air.Inst.Ref, final_len); | 14803 | const element_refs = try sema.arena.alloc(Air.Inst.Ref, final_len); |
| 14867 | var i: u32 = 0; | 14804 | var i: u32 = 0; |
| 14868 | while (i < tuple_len) : (i += 1) { | 14805 | while (i < tuple_len) : (i += 1) { |
| 14869 | const operand_src: LazySrcLoc = .{ .array_cat_lhs = .{ | 14806 | const operand_src = block.src(.{ .array_cat_lhs = .{ |
| 14870 | .array_cat_offset = src_node, | 14807 | .array_cat_offset = src_node, |
| 14871 | .elem_index = i, | 14808 | .elem_index = i, |
| 14872 | } }; | 14809 | } }); |
| 14873 | element_refs[i] = try sema.tupleFieldValByIndex(block, operand_src, operand, @intCast(i), operand_ty); | 14810 | element_refs[i] = try sema.tupleFieldValByIndex(block, operand_src, operand, @intCast(i), operand_ty); |
| 14874 | } | 14811 | } |
| 14875 | i = 1; | 14812 | i = 1; |
| ... | @@ -14890,9 +14827,9 @@ fn zirArrayMul(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -14890,9 +14827,9 @@ fn zirArrayMul(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 14890 | const uncoerced_lhs = try sema.resolveInst(extra.lhs); | 14827 | const uncoerced_lhs = try sema.resolveInst(extra.lhs); |
| 14891 | const uncoerced_lhs_ty = sema.typeOf(uncoerced_lhs); | 14828 | const uncoerced_lhs_ty = sema.typeOf(uncoerced_lhs); |
| 14892 | const src: LazySrcLoc = block.nodeOffset(inst_data.src_node); | 14829 | const src: LazySrcLoc = block.nodeOffset(inst_data.src_node); |
| 14893 | const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node }; | 14830 | const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node }); |
| 14894 | const operator_src: LazySrcLoc = .{ .node_offset_main_token = inst_data.src_node }; | 14831 | const operator_src = block.src(.{ .node_offset_main_token = inst_data.src_node }); |
| 14895 | const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node }; | 14832 | const rhs_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node }); |
| 14896 | | 14833 | |
| 14897 | const lhs, const lhs_ty = coerced_lhs: { | 14834 | const lhs, const lhs_ty = coerced_lhs: { |
| 14898 | // If we have a result type, we might be able to do this more efficiently | 14835 | // If we have a result type, we might be able to do this more efficiently |
| ... | @@ -14941,11 +14878,11 @@ fn zirArrayMul(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -14941,11 +14878,11 @@ fn zirArrayMul(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 14941 | // Analyze the lhs first, to catch the case that someone tried to do exponentiation | 14878 | // Analyze the lhs first, to catch the case that someone tried to do exponentiation |
| 14942 | const lhs_info = try sema.getArrayCatInfo(block, lhs_src, lhs, lhs_ty) orelse { | 14879 | const lhs_info = try sema.getArrayCatInfo(block, lhs_src, lhs, lhs_ty) orelse { |
| 14943 | const msg = msg: { | 14880 | const msg = msg: { |
| 14944 | const msg = try sema.errMsg(block, lhs_src, "expected indexable; found '{}'", .{lhs_ty.fmt(mod)}); | 14881 | const msg = try sema.errMsg(lhs_src, "expected indexable; found '{}'", .{lhs_ty.fmt(mod)}); |
| 14945 | errdefer msg.destroy(sema.gpa); | 14882 | errdefer msg.destroy(sema.gpa); |
| 14946 | switch (lhs_ty.zigTypeTag(mod)) { | 14883 | switch (lhs_ty.zigTypeTag(mod)) { |
| 14947 | .Int, .Float, .ComptimeFloat, .ComptimeInt, .Vector => { | 14884 | .Int, .Float, .ComptimeFloat, .ComptimeInt, .Vector => { |
| 14948 | try sema.errNote(block, operator_src, msg, "this operator multiplies arrays; use std.math.pow for exponentiation", .{}); | 14885 | try sema.errNote(operator_src, msg, "this operator multiplies arrays; use std.math.pow for exponentiation", .{}); |
| 14949 | }, | 14886 | }, |
| 14950 | else => {}, | 14887 | else => {}, |
| 14951 | } | 14888 | } |
| ... | @@ -15061,7 +14998,7 @@ fn zirNegate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. | ... | @@ -15061,7 +14998,7 @@ fn zirNegate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. |
| 15061 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; | 14998 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 15062 | const src = block.nodeOffset(inst_data.src_node); | 14999 | const src = block.nodeOffset(inst_data.src_node); |
| 15063 | const lhs_src = src; | 15000 | const lhs_src = src; |
| 15064 | const rhs_src: LazySrcLoc = .{ .node_offset_un_op = inst_data.src_node }; | 15001 | const rhs_src = block.src(.{ .node_offset_un_op = inst_data.src_node }); |
| 15065 | | 15002 | |
| 15066 | const rhs = try sema.resolveInst(inst_data.operand); | 15003 | const rhs = try sema.resolveInst(inst_data.operand); |
| 15067 | const rhs_ty = sema.typeOf(rhs); | 15004 | const rhs_ty = sema.typeOf(rhs); |
| ... | @@ -15093,7 +15030,7 @@ fn zirNegateWrap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! | ... | @@ -15093,7 +15030,7 @@ fn zirNegateWrap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! |
| 15093 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; | 15030 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 15094 | const src = block.nodeOffset(inst_data.src_node); | 15031 | const src = block.nodeOffset(inst_data.src_node); |
| 15095 | const lhs_src = src; | 15032 | const lhs_src = src; |
| 15096 | const rhs_src: LazySrcLoc = .{ .node_offset_un_op = inst_data.src_node }; | 15033 | const rhs_src = block.src(.{ .node_offset_un_op = inst_data.src_node }); |
| 15097 | | 15034 | |
| 15098 | const rhs = try sema.resolveInst(inst_data.operand); | 15035 | const rhs = try sema.resolveInst(inst_data.operand); |
| 15099 | const rhs_ty = sema.typeOf(rhs); | 15036 | const rhs_ty = sema.typeOf(rhs); |
| ... | @@ -15119,9 +15056,9 @@ fn zirArithmetic( | ... | @@ -15119,9 +15056,9 @@ fn zirArithmetic( |
| 15119 | defer tracy.end(); | 15056 | defer tracy.end(); |
| 15120 | | 15057 | |
| 15121 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 15058 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 15122 | const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node }; | 15059 | const src = block.src(.{ .node_offset_bin_op = inst_data.src_node }); |
| 15123 | const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node }; | 15060 | const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node }); |
| 15124 | const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node }; | 15061 | const rhs_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node }); |
| 15125 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; | 15062 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 15126 | const lhs = try sema.resolveInst(extra.lhs); | 15063 | const lhs = try sema.resolveInst(extra.lhs); |
| 15127 | const rhs = try sema.resolveInst(extra.rhs); | 15064 | const rhs = try sema.resolveInst(extra.rhs); |
| ... | @@ -15132,9 +15069,9 @@ fn zirArithmetic( | ... | @@ -15132,9 +15069,9 @@ fn zirArithmetic( |
| 15132 | fn zirDiv(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 15069 | fn zirDiv(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 15133 | const mod = sema.mod; | 15070 | const mod = sema.mod; |
| 15134 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 15071 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 15135 | const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node }; | 15072 | const src = block.src(.{ .node_offset_bin_op = inst_data.src_node }); |
| 15136 | const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node }; | 15073 | const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node }); |
| 15137 | const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node }; | 15074 | const rhs_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node }); |
| 15138 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; | 15075 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 15139 | const lhs = try sema.resolveInst(extra.lhs); | 15076 | const lhs = try sema.resolveInst(extra.lhs); |
| 15140 | const rhs = try sema.resolveInst(extra.rhs); | 15077 | const rhs = try sema.resolveInst(extra.rhs); |
| ... | @@ -15297,9 +15234,9 @@ fn zirDiv(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins | ... | @@ -15297,9 +15234,9 @@ fn zirDiv(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins |
| 15297 | fn zirDivExact(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 15234 | fn zirDivExact(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 15298 | const mod = sema.mod; | 15235 | const mod = sema.mod; |
| 15299 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 15236 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 15300 | const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node }; | 15237 | const src = block.src(.{ .node_offset_bin_op = inst_data.src_node }); |
| 15301 | const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node }; | 15238 | const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node }); |
| 15302 | const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node }; | 15239 | const rhs_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node }); |
| 15303 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; | 15240 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 15304 | const lhs = try sema.resolveInst(extra.lhs); | 15241 | const lhs = try sema.resolveInst(extra.lhs); |
| 15305 | const rhs = try sema.resolveInst(extra.rhs); | 15242 | const rhs = try sema.resolveInst(extra.rhs); |
| ... | @@ -15462,9 +15399,9 @@ fn zirDivExact(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -15462,9 +15399,9 @@ fn zirDivExact(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 15462 | fn zirDivFloor(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 15399 | fn zirDivFloor(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 15463 | const mod = sema.mod; | 15400 | const mod = sema.mod; |
| 15464 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 15401 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 15465 | const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node }; | 15402 | const src = block.src(.{ .node_offset_bin_op = inst_data.src_node }); |
| 15466 | const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node }; | 15403 | const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node }); |
| 15467 | const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node }; | 15404 | const rhs_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node }); |
| 15468 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; | 15405 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 15469 | const lhs = try sema.resolveInst(extra.lhs); | 15406 | const lhs = try sema.resolveInst(extra.lhs); |
| 15470 | const rhs = try sema.resolveInst(extra.rhs); | 15407 | const rhs = try sema.resolveInst(extra.rhs); |
| ... | @@ -15572,9 +15509,9 @@ fn zirDivFloor(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -15572,9 +15509,9 @@ fn zirDivFloor(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 15572 | fn zirDivTrunc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 15509 | fn zirDivTrunc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 15573 | const mod = sema.mod; | 15510 | const mod = sema.mod; |
| 15574 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 15511 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 15575 | const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node }; | 15512 | const src = block.src(.{ .node_offset_bin_op = inst_data.src_node }); |
| 15576 | const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node }; | 15513 | const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node }); |
| 15577 | const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node }; | 15514 | const rhs_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node }); |
| 15578 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; | 15515 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 15579 | const lhs = try sema.resolveInst(extra.lhs); | 15516 | const lhs = try sema.resolveInst(extra.lhs); |
| 15580 | const rhs = try sema.resolveInst(extra.rhs); | 15517 | const rhs = try sema.resolveInst(extra.rhs); |
| ... | @@ -15813,9 +15750,9 @@ fn airTag(block: *Block, is_int: bool, normal: Air.Inst.Tag, optimized: Air.Inst | ... | @@ -15813,9 +15750,9 @@ fn airTag(block: *Block, is_int: bool, normal: Air.Inst.Tag, optimized: Air.Inst |
| 15813 | fn zirModRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 15750 | fn zirModRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 15814 | const mod = sema.mod; | 15751 | const mod = sema.mod; |
| 15815 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 15752 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 15816 | const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node }; | 15753 | const src = block.src(.{ .node_offset_bin_op = inst_data.src_node }); |
| 15817 | const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node }; | 15754 | const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node }); |
| 15818 | const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node }; | 15755 | const rhs_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node }); |
| 15819 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; | 15756 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 15820 | const lhs = try sema.resolveInst(extra.lhs); | 15757 | const lhs = try sema.resolveInst(extra.lhs); |
| 15821 | const rhs = try sema.resolveInst(extra.rhs); | 15758 | const rhs = try sema.resolveInst(extra.rhs); |
| ... | @@ -15997,9 +15934,9 @@ fn intRemScalar(sema: *Sema, lhs: Value, rhs: Value, scalar_ty: Type) CompileErr | ... | @@ -15997,9 +15934,9 @@ fn intRemScalar(sema: *Sema, lhs: Value, rhs: Value, scalar_ty: Type) CompileErr |
| 15997 | fn zirMod(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 15934 | fn zirMod(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 15998 | const mod = sema.mod; | 15935 | const mod = sema.mod; |
| 15999 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 15936 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 16000 | const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node }; | 15937 | const src = block.src(.{ .node_offset_bin_op = inst_data.src_node }); |
| 16001 | const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node }; | 15938 | const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node }); |
| 16002 | const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node }; | 15939 | const rhs_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node }); |
| 16003 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; | 15940 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 16004 | const lhs = try sema.resolveInst(extra.lhs); | 15941 | const lhs = try sema.resolveInst(extra.lhs); |
| 16005 | const rhs = try sema.resolveInst(extra.rhs); | 15942 | const rhs = try sema.resolveInst(extra.rhs); |
| ... | @@ -16092,9 +16029,9 @@ fn zirMod(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins | ... | @@ -16092,9 +16029,9 @@ fn zirMod(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins |
| 16092 | fn zirRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 16029 | fn zirRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 16093 | const mod = sema.mod; | 16030 | const mod = sema.mod; |
| 16094 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 16031 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 16095 | const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node }; | 16032 | const src = block.src(.{ .node_offset_bin_op = inst_data.src_node }); |
| 16096 | const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node }; | 16033 | const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node }); |
| 16097 | const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node }; | 16034 | const rhs_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node }); |
| 16098 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; | 16035 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 16099 | const lhs = try sema.resolveInst(extra.lhs); | 16036 | const lhs = try sema.resolveInst(extra.lhs); |
| 16100 | const rhs = try sema.resolveInst(extra.rhs); | 16037 | const rhs = try sema.resolveInst(extra.rhs); |
| ... | @@ -16194,10 +16131,10 @@ fn zirOverflowArithmetic( | ... | @@ -16194,10 +16131,10 @@ fn zirOverflowArithmetic( |
| 16194 | defer tracy.end(); | 16131 | defer tracy.end(); |
| 16195 | | 16132 | |
| 16196 | const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data; | 16133 | const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data; |
| 16197 | const src = LazySrcLoc.nodeOffset(extra.node); | 16134 | const src = block.nodeOffset(extra.node); |
| 16198 | | 16135 | |
| 16199 | const lhs_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node }; | 16136 | const lhs_src = block.builtinCallArgSrc(extra.node, 0); |
| 16200 | const rhs_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = extra.node }; | 16137 | const rhs_src = block.builtinCallArgSrc(extra.node, 1); |
| 16201 | | 16138 | |
| 16202 | const uncasted_lhs = try sema.resolveInst(extra.lhs); | 16139 | const uncasted_lhs = try sema.resolveInst(extra.lhs); |
| 16203 | const uncasted_rhs = try sema.resolveInst(extra.rhs); | 16140 | const uncasted_rhs = try sema.resolveInst(extra.rhs); |
| ... | @@ -17025,8 +16962,8 @@ fn zirAsm( | ... | @@ -17025,8 +16962,8 @@ fn zirAsm( |
| 17025 | defer tracy.end(); | 16962 | defer tracy.end(); |
| 17026 | | 16963 | |
| 17027 | const extra = sema.code.extraData(Zir.Inst.Asm, extended.operand); | 16964 | const extra = sema.code.extraData(Zir.Inst.Asm, extended.operand); |
| 17028 | const src = LazySrcLoc.nodeOffset(extra.data.src_node); | 16965 | const src = block.nodeOffset(extra.data.src_node); |
| 17029 | const ret_ty_src: LazySrcLoc = .{ .node_offset_asm_ret_ty = extra.data.src_node }; | 16966 | const ret_ty_src = block.src(.{ .node_offset_asm_ret_ty = extra.data.src_node }); |
| 17030 | const outputs_len: u5 = @truncate(extended.small); | 16967 | const outputs_len: u5 = @truncate(extended.small); |
| 17031 | const inputs_len: u5 = @truncate(extended.small >> 5); | 16968 | const inputs_len: u5 = @truncate(extended.small >> 5); |
| 17032 | const clobbers_len: u5 = @truncate(extended.small >> 10); | 16969 | const clobbers_len: u5 = @truncate(extended.small >> 10); |
| ... | @@ -17200,8 +17137,8 @@ fn zirCmpEq( | ... | @@ -17200,8 +17137,8 @@ fn zirCmpEq( |
| 17200 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 17137 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 17201 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; | 17138 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 17202 | const src: LazySrcLoc = block.nodeOffset(inst_data.src_node); | 17139 | const src: LazySrcLoc = block.nodeOffset(inst_data.src_node); |
| 17203 | const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node }; | 17140 | const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node }); |
| 17204 | const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node }; | 17141 | const rhs_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node }); |
| 17205 | const lhs = try sema.resolveInst(extra.lhs); | 17142 | const lhs = try sema.resolveInst(extra.lhs); |
| 17206 | const rhs = try sema.resolveInst(extra.rhs); | 17143 | const rhs = try sema.resolveInst(extra.rhs); |
| 17207 | | 17144 | |
| ... | @@ -17280,9 +17217,9 @@ fn analyzeCmpUnionTag( | ... | @@ -17280,9 +17217,9 @@ fn analyzeCmpUnionTag( |
| 17280 | try sema.resolveTypeFields(union_ty); | 17217 | try sema.resolveTypeFields(union_ty); |
| 17281 | const union_tag_ty = union_ty.unionTagType(mod) orelse { | 17218 | const union_tag_ty = union_ty.unionTagType(mod) orelse { |
| 17282 | const msg = msg: { | 17219 | const msg = msg: { |
| 17283 | const msg = try sema.errMsg(block, un_src, "comparison of union and enum literal is only valid for tagged union types", .{}); | 17220 | const msg = try sema.errMsg(un_src, "comparison of union and enum literal is only valid for tagged union types", .{}); |
| 17284 | errdefer msg.destroy(sema.gpa); | 17221 | errdefer msg.destroy(sema.gpa); |
| 17285 | try mod.errNoteNonLazy(union_ty.declSrcLoc(mod), msg, "union '{}' is not a tagged union", .{union_ty.fmt(mod)}); | 17222 | try sema.errNote(union_ty.srcLoc(mod), msg, "union '{}' is not a tagged union", .{union_ty.fmt(mod)}); |
| 17286 | break :msg msg; | 17223 | break :msg msg; |
| 17287 | }; | 17224 | }; |
| 17288 | return sema.failWithOwnedErrorMsg(block, msg); | 17225 | return sema.failWithOwnedErrorMsg(block, msg); |
| ... | @@ -17316,8 +17253,8 @@ fn zirCmp( | ... | @@ -17316,8 +17253,8 @@ fn zirCmp( |
| 17316 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 17253 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 17317 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; | 17254 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 17318 | const src: LazySrcLoc = block.nodeOffset(inst_data.src_node); | 17255 | const src: LazySrcLoc = block.nodeOffset(inst_data.src_node); |
| 17319 | const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node }; | 17256 | const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node }); |
| 17320 | const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node }; | 17257 | const rhs_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node }); |
| 17321 | const lhs = try sema.resolveInst(extra.lhs); | 17258 | const lhs = try sema.resolveInst(extra.lhs); |
| 17322 | const rhs = try sema.resolveInst(extra.rhs); | 17259 | const rhs = try sema.resolveInst(extra.rhs); |
| 17323 | return sema.analyzeCmp(block, src, lhs, rhs, op, lhs_src, rhs_src, false); | 17260 | return sema.analyzeCmp(block, src, lhs, rhs, op, lhs_src, rhs_src, false); |
| ... | @@ -17459,7 +17396,7 @@ fn runtimeBoolCmp( | ... | @@ -17459,7 +17396,7 @@ fn runtimeBoolCmp( |
| 17459 | fn zirSizeOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 17396 | fn zirSizeOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 17460 | const mod = sema.mod; | 17397 | const mod = sema.mod; |
| 17461 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; | 17398 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 17462 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 17399 | const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0); |
| 17463 | const ty = try sema.resolveType(block, operand_src, inst_data.operand); | 17400 | const ty = try sema.resolveType(block, operand_src, inst_data.operand); |
| 17464 | switch (ty.zigTypeTag(mod)) { | 17401 | switch (ty.zigTypeTag(mod)) { |
| 17465 | .Fn, | 17402 | .Fn, |
| ... | @@ -17502,7 +17439,7 @@ fn zirSizeOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. | ... | @@ -17502,7 +17439,7 @@ fn zirSizeOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. |
| 17502 | fn zirBitSizeOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 17439 | fn zirBitSizeOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 17503 | const mod = sema.mod; | 17440 | const mod = sema.mod; |
| 17504 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; | 17441 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 17505 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 17442 | const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0); |
| 17506 | const operand_ty = try sema.resolveType(block, operand_src, inst_data.operand); | 17443 | const operand_ty = try sema.resolveType(block, operand_src, inst_data.operand); |
| 17507 | switch (operand_ty.zigTypeTag(mod)) { | 17444 | switch (operand_ty.zigTypeTag(mod)) { |
| 17508 | .Fn, | 17445 | .Fn, |
| ... | @@ -17546,7 +17483,7 @@ fn zirThis( | ... | @@ -17546,7 +17483,7 @@ fn zirThis( |
| 17546 | ) CompileError!Air.Inst.Ref { | 17483 | ) CompileError!Air.Inst.Ref { |
| 17547 | const mod = sema.mod; | 17484 | const mod = sema.mod; |
| 17548 | const this_decl_index = mod.namespacePtr(block.namespace).decl_index; | 17485 | const this_decl_index = mod.namespacePtr(block.namespace).decl_index; |
| 17549 | const src = LazySrcLoc.nodeOffset(@bitCast(extended.operand)); | 17486 | const src = block.nodeOffset(@bitCast(extended.operand)); |
| 17550 | return sema.analyzeDeclVal(block, src, this_decl_index); | 17487 | return sema.analyzeDeclVal(block, src, this_decl_index); |
| 17551 | } | 17488 | } |
| 17552 | | 17489 | |
| ... | @@ -17556,7 +17493,7 @@ fn zirClosureGet(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat | ... | @@ -17556,7 +17493,7 @@ fn zirClosureGet(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat |
| 17556 | const captures = mod.namespacePtr(block.namespace).getType(mod).getCaptures(mod); | 17493 | const captures = mod.namespacePtr(block.namespace).getType(mod).getCaptures(mod); |
| 17557 | | 17494 | |
| 17558 | const src_node: i32 = @bitCast(extended.operand); | 17495 | const src_node: i32 = @bitCast(extended.operand); |
| 17559 | const src = LazySrcLoc.nodeOffset(src_node); | 17496 | const src = block.nodeOffset(src_node); |
| 17560 | | 17497 | |
| 17561 | const capture_ty = switch (captures.get(ip)[extended.small].unwrap()) { | 17498 | const capture_ty = switch (captures.get(ip)[extended.small].unwrap()) { |
| 17562 | .@"comptime" => |index| return Air.internedToRef(index), | 17499 | .@"comptime" => |index| return Air.internedToRef(index), |
| ... | @@ -17570,7 +17507,8 @@ fn zirClosureGet(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat | ... | @@ -17570,7 +17507,8 @@ fn zirClosureGet(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat |
| 17570 | if (!block.is_typeof and sema.func_index == .none) { | 17507 | if (!block.is_typeof and sema.func_index == .none) { |
| 17571 | const msg = msg: { | 17508 | const msg = msg: { |
| 17572 | const name = name: { | 17509 | const name = name: { |
| 17573 | const file = sema.owner_decl.getFileScope(mod); | 17510 | // TODO: we should probably store this name in the ZIR to avoid this complexity. |
| | 17511 | const file, const src_base_node = Module.LazySrcLoc.resolveBaseNode(block.src_base_inst, mod); |
| 17574 | const tree = file.getTree(sema.gpa) catch |err| { | 17512 | const tree = file.getTree(sema.gpa) catch |err| { |
| 17575 | // In this case we emit a warning + a less precise source location. | 17513 | // In this case we emit a warning + a less precise source location. |
| 17576 | log.warn("unable to load {s}: {s}", .{ | 17514 | log.warn("unable to load {s}: {s}", .{ |
| ... | @@ -17578,15 +17516,15 @@ fn zirClosureGet(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat | ... | @@ -17578,15 +17516,15 @@ fn zirClosureGet(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat |
| 17578 | }); | 17516 | }); |
| 17579 | break :name null; | 17517 | break :name null; |
| 17580 | }; | 17518 | }; |
| 17581 | const node = sema.owner_decl.relativeToNodeIndex(src_node); | 17519 | const node: std.zig.Ast.Node.Index = @bitCast(src_node + @as(i32, @bitCast(src_base_node))); |
| 17582 | const token = tree.nodes.items(.main_token)[node]; | 17520 | const token = tree.nodes.items(.main_token)[node]; |
| 17583 | break :name tree.tokenSlice(token); | 17521 | break :name tree.tokenSlice(token); |
| 17584 | }; | 17522 | }; |
| 17585 | | 17523 | |
| 17586 | const msg = if (name) |some| | 17524 | const msg = if (name) |some| |
| 17587 | try sema.errMsg(block, src, "'{s}' not accessible outside function scope", .{some}) | 17525 | try sema.errMsg(src, "'{s}' not accessible outside function scope", .{some}) |
| 17588 | else | 17526 | else |
| 17589 | try sema.errMsg(block, src, "variable not accessible outside function scope", .{}); | 17527 | try sema.errMsg(src, "variable not accessible outside function scope", .{}); |
| 17590 | errdefer msg.destroy(sema.gpa); | 17528 | errdefer msg.destroy(sema.gpa); |
| 17591 | | 17529 | |
| 17592 | // TODO add "declared here" note | 17530 | // TODO add "declared here" note |
| ... | @@ -17598,7 +17536,7 @@ fn zirClosureGet(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat | ... | @@ -17598,7 +17536,7 @@ fn zirClosureGet(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat |
| 17598 | if (!block.is_typeof and !block.is_comptime and sema.func_index != .none) { | 17536 | if (!block.is_typeof and !block.is_comptime and sema.func_index != .none) { |
| 17599 | const msg = msg: { | 17537 | const msg = msg: { |
| 17600 | const name = name: { | 17538 | const name = name: { |
| 17601 | const file = sema.owner_decl.getFileScope(mod); | 17539 | const file, const src_base_node = Module.LazySrcLoc.resolveBaseNode(block.src_base_inst, mod); |
| 17602 | const tree = file.getTree(sema.gpa) catch |err| { | 17540 | const tree = file.getTree(sema.gpa) catch |err| { |
| 17603 | // In this case we emit a warning + a less precise source location. | 17541 | // In this case we emit a warning + a less precise source location. |
| 17604 | log.warn("unable to load {s}: {s}", .{ | 17542 | log.warn("unable to load {s}: {s}", .{ |
| ... | @@ -17606,18 +17544,18 @@ fn zirClosureGet(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat | ... | @@ -17606,18 +17544,18 @@ fn zirClosureGet(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat |
| 17606 | }); | 17544 | }); |
| 17607 | break :name null; | 17545 | break :name null; |
| 17608 | }; | 17546 | }; |
| 17609 | const node = sema.owner_decl.relativeToNodeIndex(src_node); | 17547 | const node: std.zig.Ast.Node.Index = @bitCast(src_node + @as(i32, @bitCast(src_base_node))); |
| 17610 | const token = tree.nodes.items(.main_token)[node]; | 17548 | const token = tree.nodes.items(.main_token)[node]; |
| 17611 | break :name tree.tokenSlice(token); | 17549 | break :name tree.tokenSlice(token); |
| 17612 | }; | 17550 | }; |
| 17613 | | 17551 | |
| 17614 | const msg = if (name) |some| | 17552 | const msg = if (name) |some| |
| 17615 | try sema.errMsg(block, src, "'{s}' not accessible from inner function", .{some}) | 17553 | try sema.errMsg(src, "'{s}' not accessible from inner function", .{some}) |
| 17616 | else | 17554 | else |
| 17617 | try sema.errMsg(block, src, "variable not accessible from inner function", .{}); | 17555 | try sema.errMsg(src, "variable not accessible from inner function", .{}); |
| 17618 | errdefer msg.destroy(sema.gpa); | 17556 | errdefer msg.destroy(sema.gpa); |
| 17619 | | 17557 | |
| 17620 | try sema.errNote(block, LazySrcLoc.nodeOffset(0), msg, "crossed function definition here", .{}); | 17558 | try sema.errNote(block.nodeOffset(0), msg, "crossed function definition here", .{}); |
| 17621 | | 17559 | |
| 17622 | // TODO add "declared here" note | 17560 | // TODO add "declared here" note |
| 17623 | break :msg msg; | 17561 | break :msg msg; |
| ... | @@ -17649,7 +17587,7 @@ fn zirFrameAddress( | ... | @@ -17649,7 +17587,7 @@ fn zirFrameAddress( |
| 17649 | block: *Block, | 17587 | block: *Block, |
| 17650 | extended: Zir.Inst.Extended.InstData, | 17588 | extended: Zir.Inst.Extended.InstData, |
| 17651 | ) CompileError!Air.Inst.Ref { | 17589 | ) CompileError!Air.Inst.Ref { |
| 17652 | const src = LazySrcLoc.nodeOffset(@bitCast(extended.operand)); | 17590 | const src = block.nodeOffset(@bitCast(extended.operand)); |
| 17653 | try sema.requireRuntimeBlock(block, src, null); | 17591 | try sema.requireRuntimeBlock(block, src, null); |
| 17654 | return try block.addNoOp(.frame_addr); | 17592 | return try block.addNoOp(.frame_addr); |
| 17655 | } | 17593 | } |
| ... | @@ -18913,6 +18851,7 @@ fn zirTypeofBuiltin(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr | ... | @@ -18913,6 +18851,7 @@ fn zirTypeofBuiltin(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr |
| 18913 | .is_typeof = true, | 18851 | .is_typeof = true, |
| 18914 | .want_safety = false, | 18852 | .want_safety = false, |
| 18915 | .error_return_trace_index = block.error_return_trace_index, | 18853 | .error_return_trace_index = block.error_return_trace_index, |
| | 18854 | .src_base_inst = block.src_base_inst, |
| 18916 | }; | 18855 | }; |
| 18917 | defer child_block.instructions.deinit(sema.gpa); | 18856 | defer child_block.instructions.deinit(sema.gpa); |
| 18918 | | 18857 | |
| ... | @@ -18977,7 +18916,7 @@ fn zirTypeofPeer( | ... | @@ -18977,7 +18916,7 @@ fn zirTypeofPeer( |
| 18977 | defer tracy.end(); | 18916 | defer tracy.end(); |
| 18978 | | 18917 | |
| 18979 | const extra = sema.code.extraData(Zir.Inst.TypeOfPeer, extended.operand); | 18918 | const extra = sema.code.extraData(Zir.Inst.TypeOfPeer, extended.operand); |
| 18980 | const src = LazySrcLoc.nodeOffset(extra.data.src_node); | 18919 | const src = block.nodeOffset(extra.data.src_node); |
| 18981 | const body = sema.code.bodySlice(extra.data.body_index, extra.data.body_len); | 18920 | const body = sema.code.bodySlice(extra.data.body_index, extra.data.body_len); |
| 18982 | | 18921 | |
| 18983 | var child_block: Block = .{ | 18922 | var child_block: Block = .{ |
| ... | @@ -18992,6 +18931,7 @@ fn zirTypeofPeer( | ... | @@ -18992,6 +18931,7 @@ fn zirTypeofPeer( |
| 18992 | .runtime_cond = block.runtime_cond, | 18931 | .runtime_cond = block.runtime_cond, |
| 18993 | .runtime_loop = block.runtime_loop, | 18932 | .runtime_loop = block.runtime_loop, |
| 18994 | .runtime_index = block.runtime_index, | 18933 | .runtime_index = block.runtime_index, |
| | 18934 | .src_base_inst = block.src_base_inst, |
| 18995 | }; | 18935 | }; |
| 18996 | defer child_block.instructions.deinit(sema.gpa); | 18936 | defer child_block.instructions.deinit(sema.gpa); |
| 18997 | // Ignore the result, we only care about the instructions in `args`. | 18937 | // Ignore the result, we only care about the instructions in `args`. |
| ... | @@ -19017,7 +18957,7 @@ fn zirBoolNot(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air | ... | @@ -19017,7 +18957,7 @@ fn zirBoolNot(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 19017 | const mod = sema.mod; | 18957 | const mod = sema.mod; |
| 19018 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; | 18958 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 19019 | const src = block.nodeOffset(inst_data.src_node); | 18959 | const src = block.nodeOffset(inst_data.src_node); |
| 19020 | const operand_src: LazySrcLoc = .{ .node_offset_un_op = inst_data.src_node }; | 18960 | const operand_src = block.src(.{ .node_offset_un_op = inst_data.src_node }); |
| 19021 | const uncasted_operand = try sema.resolveInst(inst_data.operand); | 18961 | const uncasted_operand = try sema.resolveInst(inst_data.operand); |
| 19022 | | 18962 | |
| 19023 | const operand = try sema.coerce(block, Type.bool, uncasted_operand, operand_src); | 18963 | const operand = try sema.coerce(block, Type.bool, uncasted_operand, operand_src); |
| ... | @@ -19048,8 +18988,8 @@ fn zirBoolBr( | ... | @@ -19048,8 +18988,8 @@ fn zirBoolBr( |
| 19048 | | 18988 | |
| 19049 | const uncoerced_lhs = try sema.resolveInst(extra.data.lhs); | 18989 | const uncoerced_lhs = try sema.resolveInst(extra.data.lhs); |
| 19050 | const body = sema.code.bodySlice(extra.end, extra.data.body_len); | 18990 | const body = sema.code.bodySlice(extra.end, extra.data.body_len); |
| 19051 | const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node }; | 18991 | const lhs_src = parent_block.src(.{ .node_offset_bin_lhs = inst_data.src_node }); |
| 19052 | const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node }; | 18992 | const rhs_src = parent_block.src(.{ .node_offset_bin_rhs = inst_data.src_node }); |
| 19053 | | 18993 | |
| 19054 | const lhs = try sema.coerce(parent_block, Type.bool, uncoerced_lhs, lhs_src); | 18994 | const lhs = try sema.coerce(parent_block, Type.bool, uncoerced_lhs, lhs_src); |
| 19055 | | 18995 | |
| ... | @@ -19080,7 +19020,7 @@ fn zirBoolBr( | ... | @@ -19080,7 +19020,7 @@ fn zirBoolBr( |
| 19080 | | 19020 | |
| 19081 | var child_block = parent_block.makeSubBlock(); | 19021 | var child_block = parent_block.makeSubBlock(); |
| 19082 | child_block.runtime_loop = null; | 19022 | child_block.runtime_loop = null; |
| 19083 | child_block.runtime_cond = mod.declPtr(child_block.src_decl).toSrcLoc(lhs_src, mod); | 19023 | child_block.runtime_cond = lhs_src; |
| 19084 | child_block.runtime_index.increment(); | 19024 | child_block.runtime_index.increment(); |
| 19085 | defer child_block.instructions.deinit(gpa); | 19025 | defer child_block.instructions.deinit(gpa); |
| 19086 | | 19026 | |
| ... | @@ -19253,7 +19193,7 @@ fn zirCondbr( | ... | @@ -19253,7 +19193,7 @@ fn zirCondbr( |
| 19253 | | 19193 | |
| 19254 | const mod = sema.mod; | 19194 | const mod = sema.mod; |
| 19255 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 19195 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 19256 | const cond_src: LazySrcLoc = .{ .node_offset_if_cond = inst_data.src_node }; | 19196 | const cond_src = parent_block.src(.{ .node_offset_if_cond = inst_data.src_node }); |
| 19257 | const extra = sema.code.extraData(Zir.Inst.CondBr, inst_data.payload_index); | 19197 | const extra = sema.code.extraData(Zir.Inst.CondBr, inst_data.payload_index); |
| 19258 | | 19198 | |
| 19259 | const then_body = sema.code.bodySlice(extra.end, extra.data.then_body_len); | 19199 | const then_body = sema.code.bodySlice(extra.end, extra.data.then_body_len); |
| ... | @@ -19276,7 +19216,7 @@ fn zirCondbr( | ... | @@ -19276,7 +19216,7 @@ fn zirCondbr( |
| 19276 | // instructions array in between using it for the then block and else block. | 19216 | // instructions array in between using it for the then block and else block. |
| 19277 | var sub_block = parent_block.makeSubBlock(); | 19217 | var sub_block = parent_block.makeSubBlock(); |
| 19278 | sub_block.runtime_loop = null; | 19218 | sub_block.runtime_loop = null; |
| 19279 | sub_block.runtime_cond = mod.declPtr(parent_block.src_decl).toSrcLoc(cond_src, mod); | 19219 | sub_block.runtime_cond = cond_src; |
| 19280 | sub_block.runtime_index.increment(); | 19220 | sub_block.runtime_index.increment(); |
| 19281 | sub_block.need_debug_scope = null; // this body is emitted regardless | 19221 | sub_block.need_debug_scope = null; // this body is emitted regardless |
| 19282 | defer sub_block.instructions.deinit(gpa); | 19222 | defer sub_block.instructions.deinit(gpa); |
| ... | @@ -19321,7 +19261,7 @@ fn zirCondbr( | ... | @@ -19321,7 +19261,7 @@ fn zirCondbr( |
| 19321 | fn zirTry(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 19261 | fn zirTry(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 19322 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 19262 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 19323 | const src = parent_block.nodeOffset(inst_data.src_node); | 19263 | const src = parent_block.nodeOffset(inst_data.src_node); |
| 19324 | const operand_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node }; | 19264 | const operand_src = parent_block.src(.{ .node_offset_bin_lhs = inst_data.src_node }); |
| 19325 | const extra = sema.code.extraData(Zir.Inst.Try, inst_data.payload_index); | 19265 | const extra = sema.code.extraData(Zir.Inst.Try, inst_data.payload_index); |
| 19326 | const body = sema.code.bodySlice(extra.end, extra.data.body_len); | 19266 | const body = sema.code.bodySlice(extra.end, extra.data.body_len); |
| 19327 | const err_union = try sema.resolveInst(extra.data.operand); | 19267 | const err_union = try sema.resolveInst(extra.data.operand); |
| ... | @@ -19368,7 +19308,7 @@ fn zirTry(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError! | ... | @@ -19368,7 +19308,7 @@ fn zirTry(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError! |
| 19368 | fn zirTryPtr(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 19308 | fn zirTryPtr(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 19369 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 19309 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 19370 | const src = parent_block.nodeOffset(inst_data.src_node); | 19310 | const src = parent_block.nodeOffset(inst_data.src_node); |
| 19371 | const operand_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node }; | 19311 | const operand_src = parent_block.src(.{ .node_offset_bin_lhs = inst_data.src_node }); |
| 19372 | const extra = sema.code.extraData(Zir.Inst.Try, inst_data.payload_index); | 19312 | const extra = sema.code.extraData(Zir.Inst.Try, inst_data.payload_index); |
| 19373 | const body = sema.code.bodySlice(extra.end, extra.data.body_len); | 19313 | const body = sema.code.bodySlice(extra.end, extra.data.body_len); |
| 19374 | const operand = try sema.resolveInst(extra.data.operand); | 19314 | const operand = try sema.resolveInst(extra.data.operand); |
| ... | @@ -19464,6 +19404,7 @@ fn ensurePostHoc(sema: *Sema, block: *Block, dest_block: Zir.Inst.Index) !*Label | ... | @@ -19464,6 +19404,7 @@ fn ensurePostHoc(sema: *Sema, block: *Block, dest_block: Zir.Inst.Index) !*Label |
| 19464 | .label = &labeled_block.label, | 19404 | .label = &labeled_block.label, |
| 19465 | .inlining = block.inlining, | 19405 | .inlining = block.inlining, |
| 19466 | .is_comptime = block.is_comptime, | 19406 | .is_comptime = block.is_comptime, |
| | 19407 | .src_base_inst = block.src_base_inst, |
| 19467 | }, | 19408 | }, |
| 19468 | }; | 19409 | }; |
| 19469 | sema.post_hoc_blocks.putAssumeCapacityNoClobber(new_block_inst, labeled_block); | 19410 | sema.post_hoc_blocks.putAssumeCapacityNoClobber(new_block_inst, labeled_block); |
| ... | @@ -19498,11 +19439,11 @@ fn zirUnreachable(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError | ... | @@ -19498,11 +19439,11 @@ fn zirUnreachable(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 19498 | return sema.fail(block, src, "reached unreachable code", .{}); | 19439 | return sema.fail(block, src, "reached unreachable code", .{}); |
| 19499 | } | 19440 | } |
| 19500 | // TODO Add compile error for @optimizeFor occurring too late in a scope. | 19441 | // TODO Add compile error for @optimizeFor occurring too late in a scope. |
| 19501 | block.addUnreachable(src, true) catch |err| switch (err) { | 19442 | sema.analyzeUnreachable(block, src, true) catch |err| switch (err) { |
| 19502 | error.AnalysisFail => { | 19443 | error.AnalysisFail => { |
| 19503 | const msg = sema.err orelse return err; | 19444 | const msg = sema.err orelse return err; |
| 19504 | if (!mem.eql(u8, msg.msg, "runtime safety check not allowed in naked function")) return err; | 19445 | if (!mem.eql(u8, msg.msg, "runtime safety check not allowed in naked function")) return err; |
| 19505 | try sema.errNote(block, src, msg, "the end of a naked function is implicitly unreachable", .{}); | 19446 | try sema.errNote(src, msg, "the end of a naked function is implicitly unreachable", .{}); |
| 19506 | return err; | 19447 | return err; |
| 19507 | }, | 19448 | }, |
| 19508 | else => |e| return e, | 19449 | else => |e| return e, |
| ... | @@ -19549,31 +19490,31 @@ fn zirRetImplicit( | ... | @@ -19549,31 +19490,31 @@ fn zirRetImplicit( |
| 19549 | // Calling a safety function from a naked function would not be legal. | 19490 | // Calling a safety function from a naked function would not be legal. |
| 19550 | _ = try block.addNoOp(.trap); | 19491 | _ = try block.addNoOp(.trap); |
| 19551 | } else { | 19492 | } else { |
| 19552 | try block.addUnreachable(r_brace_src, false); | 19493 | try sema.analyzeUnreachable(block, r_brace_src, false); |
| 19553 | } | 19494 | } |
| 19554 | return; | 19495 | return; |
| 19555 | } | 19496 | } |
| 19556 | | 19497 | |
| 19557 | const operand = try sema.resolveInst(inst_data.operand); | 19498 | const operand = try sema.resolveInst(inst_data.operand); |
| 19558 | const ret_ty_src: LazySrcLoc = .{ .node_offset_fn_type_ret_ty = 0 }; | 19499 | const ret_ty_src = block.src(.{ .node_offset_fn_type_ret_ty = 0 }); |
| 19559 | const base_tag = sema.fn_ret_ty.baseZigTypeTag(mod); | 19500 | const base_tag = sema.fn_ret_ty.baseZigTypeTag(mod); |
| 19560 | if (base_tag == .NoReturn) { | 19501 | if (base_tag == .NoReturn) { |
| 19561 | const msg = msg: { | 19502 | const msg = msg: { |
| 19562 | const msg = try sema.errMsg(block, ret_ty_src, "function declared '{}' implicitly returns", .{ | 19503 | const msg = try sema.errMsg(ret_ty_src, "function declared '{}' implicitly returns", .{ |
| 19563 | sema.fn_ret_ty.fmt(mod), | 19504 | sema.fn_ret_ty.fmt(mod), |
| 19564 | }); | 19505 | }); |
| 19565 | errdefer msg.destroy(sema.gpa); | 19506 | errdefer msg.destroy(sema.gpa); |
| 19566 | try sema.errNote(block, r_brace_src, msg, "control flow reaches end of body here", .{}); | 19507 | try sema.errNote(r_brace_src, msg, "control flow reaches end of body here", .{}); |
| 19567 | break :msg msg; | 19508 | break :msg msg; |
| 19568 | }; | 19509 | }; |
| 19569 | return sema.failWithOwnedErrorMsg(block, msg); | 19510 | return sema.failWithOwnedErrorMsg(block, msg); |
| 19570 | } else if (base_tag != .Void) { | 19511 | } else if (base_tag != .Void) { |
| 19571 | const msg = msg: { | 19512 | const msg = msg: { |
| 19572 | const msg = try sema.errMsg(block, ret_ty_src, "function with non-void return type '{}' implicitly returns", .{ | 19513 | const msg = try sema.errMsg(ret_ty_src, "function with non-void return type '{}' implicitly returns", .{ |
| 19573 | sema.fn_ret_ty.fmt(mod), | 19514 | sema.fn_ret_ty.fmt(mod), |
| 19574 | }); | 19515 | }); |
| 19575 | errdefer msg.destroy(sema.gpa); | 19516 | errdefer msg.destroy(sema.gpa); |
| 19576 | try sema.errNote(block, r_brace_src, msg, "control flow reaches end of body here", .{}); | 19517 | try sema.errNote(r_brace_src, msg, "control flow reaches end of body here", .{}); |
| 19577 | break :msg msg; | 19518 | break :msg msg; |
| 19578 | }; | 19519 | }; |
| 19579 | return sema.failWithOwnedErrorMsg(block, msg); | 19520 | return sema.failWithOwnedErrorMsg(block, msg); |
| ... | @@ -19590,7 +19531,7 @@ fn zirRetNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!voi | ... | @@ -19590,7 +19531,7 @@ fn zirRetNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!voi |
| 19590 | const operand = try sema.resolveInst(inst_data.operand); | 19531 | const operand = try sema.resolveInst(inst_data.operand); |
| 19591 | const src = block.nodeOffset(inst_data.src_node); | 19532 | const src = block.nodeOffset(inst_data.src_node); |
| 19592 | | 19533 | |
| 19593 | return sema.analyzeRet(block, operand, src, .{ .node_offset_return_operand = inst_data.src_node }); | 19534 | return sema.analyzeRet(block, operand, src, block.src(.{ .node_offset_return_operand = inst_data.src_node })); |
| 19594 | } | 19535 | } |
| 19595 | | 19536 | |
| 19596 | fn zirRetLoad(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void { | 19537 | fn zirRetLoad(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void { |
| ... | @@ -19603,7 +19544,7 @@ fn zirRetLoad(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!voi | ... | @@ -19603,7 +19544,7 @@ fn zirRetLoad(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!voi |
| 19603 | | 19544 | |
| 19604 | if (block.is_comptime or block.inlining != null or sema.func_is_naked) { | 19545 | if (block.is_comptime or block.inlining != null or sema.func_is_naked) { |
| 19605 | const operand = try sema.analyzeLoad(block, src, ret_ptr, src); | 19546 | const operand = try sema.analyzeLoad(block, src, ret_ptr, src); |
| 19606 | return sema.analyzeRet(block, operand, src, .{ .node_offset_return_operand = inst_data.src_node }); | 19547 | return sema.analyzeRet(block, operand, src, block.src(.{ .node_offset_return_operand = inst_data.src_node })); |
| 19607 | } | 19548 | } |
| 19608 | | 19549 | |
| 19609 | if (sema.wantErrorReturnTracing(sema.fn_ret_ty)) { | 19550 | if (sema.wantErrorReturnTracing(sema.fn_ret_ty)) { |
| ... | @@ -19816,9 +19757,7 @@ fn analyzeRet( | ... | @@ -19816,9 +19757,7 @@ fn analyzeRet( |
| 19816 | inlining.comptime_result = operand; | 19757 | inlining.comptime_result = operand; |
| 19817 | | 19758 | |
| 19818 | if (sema.fn_ret_ty.isError(mod) and ret_val.getErrorName(mod) != .none) { | 19759 | if (sema.fn_ret_ty.isError(mod) and ret_val.getErrorName(mod) != .none) { |
| 19819 | const src_decl = mod.declPtr(block.src_decl); | 19760 | try sema.comptime_err_ret_trace.append(src); |
| 19820 | const src_loc = src_decl.toSrcLoc(src, mod); | | |
| 19821 | try sema.comptime_err_ret_trace.append(src_loc); | | |
| 19822 | } | 19761 | } |
| 19823 | return error.ComptimeReturn; | 19762 | return error.ComptimeReturn; |
| 19824 | } | 19763 | } |
| ... | @@ -19832,10 +19771,10 @@ fn analyzeRet( | ... | @@ -19832,10 +19771,10 @@ fn analyzeRet( |
| 19832 | return sema.fail(block, src, "function called at runtime cannot return value at comptime", .{}); | 19771 | return sema.fail(block, src, "function called at runtime cannot return value at comptime", .{}); |
| 19833 | } else if (sema.func_is_naked) { | 19772 | } else if (sema.func_is_naked) { |
| 19834 | const msg = msg: { | 19773 | const msg = msg: { |
| 19835 | const msg = try sema.errMsg(block, src, "cannot return from naked function", .{}); | 19774 | const msg = try sema.errMsg(src, "cannot return from naked function", .{}); |
| 19836 | errdefer msg.destroy(sema.gpa); | 19775 | errdefer msg.destroy(sema.gpa); |
| 19837 | | 19776 | |
| 19838 | try sema.errNote(block, src, msg, "can only return using assembly", .{}); | 19777 | try sema.errNote(src, msg, "can only return using assembly", .{}); |
| 19839 | break :msg msg; | 19778 | break :msg msg; |
| 19840 | }; | 19779 | }; |
| 19841 | return sema.failWithOwnedErrorMsg(block, msg); | 19780 | return sema.failWithOwnedErrorMsg(block, msg); |
| ... | @@ -19871,18 +19810,18 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air | ... | @@ -19871,18 +19810,18 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 19871 | const mod = sema.mod; | 19810 | const mod = sema.mod; |
| 19872 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].ptr_type; | 19811 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].ptr_type; |
| 19873 | const extra = sema.code.extraData(Zir.Inst.PtrType, inst_data.payload_index); | 19812 | const extra = sema.code.extraData(Zir.Inst.PtrType, inst_data.payload_index); |
| 19874 | const elem_ty_src: LazySrcLoc = .{ .node_offset_ptr_elem = extra.data.src_node }; | 19813 | const elem_ty_src = block.src(.{ .node_offset_ptr_elem = extra.data.src_node }); |
| 19875 | const sentinel_src: LazySrcLoc = .{ .node_offset_ptr_sentinel = extra.data.src_node }; | 19814 | const sentinel_src = block.src(.{ .node_offset_ptr_sentinel = extra.data.src_node }); |
| 19876 | const align_src: LazySrcLoc = .{ .node_offset_ptr_align = extra.data.src_node }; | 19815 | const align_src = block.src(.{ .node_offset_ptr_align = extra.data.src_node }); |
| 19877 | const addrspace_src: LazySrcLoc = .{ .node_offset_ptr_addrspace = extra.data.src_node }; | 19816 | const addrspace_src = block.src(.{ .node_offset_ptr_addrspace = extra.data.src_node }); |
| 19878 | const bitoffset_src: LazySrcLoc = .{ .node_offset_ptr_bitoffset = extra.data.src_node }; | 19817 | const bitoffset_src = block.src(.{ .node_offset_ptr_bitoffset = extra.data.src_node }); |
| 19879 | const hostsize_src: LazySrcLoc = .{ .node_offset_ptr_hostsize = extra.data.src_node }; | 19818 | const hostsize_src = block.src(.{ .node_offset_ptr_hostsize = extra.data.src_node }); |
| 19880 | | 19819 | |
| 19881 | const elem_ty = blk: { | 19820 | const elem_ty = blk: { |
| 19882 | const air_inst = try sema.resolveInst(extra.data.elem_type); | 19821 | const air_inst = try sema.resolveInst(extra.data.elem_type); |
| 19883 | const ty = sema.analyzeAsType(block, elem_ty_src, air_inst) catch |err| { | 19822 | const ty = sema.analyzeAsType(block, elem_ty_src, air_inst) catch |err| { |
| 19884 | if (err == error.AnalysisFail and sema.err != null and sema.typeOf(air_inst).isSinglePointer(mod)) { | 19823 | if (err == error.AnalysisFail and sema.err != null and sema.typeOf(air_inst).isSinglePointer(mod)) { |
| 19885 | try sema.errNote(block, elem_ty_src, sema.err.?, "use '.*' to dereference pointer", .{}); | 19824 | try sema.errNote(elem_ty_src, sema.err.?, "use '.*' to dereference pointer", .{}); |
| 19886 | } | 19825 | } |
| 19887 | return err; | 19826 | return err; |
| 19888 | }; | 19827 | }; |
| ... | @@ -19974,11 +19913,10 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air | ... | @@ -19974,11 +19913,10 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 19974 | } else if (inst_data.size == .C) { | 19913 | } else if (inst_data.size == .C) { |
| 19975 | if (!try sema.validateExternType(elem_ty, .other)) { | 19914 | if (!try sema.validateExternType(elem_ty, .other)) { |
| 19976 | const msg = msg: { | 19915 | const msg = msg: { |
| 19977 | const msg = try sema.errMsg(block, elem_ty_src, "C pointers cannot point to non-C-ABI-compatible type '{}'", .{elem_ty.fmt(mod)}); | 19916 | const msg = try sema.errMsg(elem_ty_src, "C pointers cannot point to non-C-ABI-compatible type '{}'", .{elem_ty.fmt(mod)}); |
| 19978 | errdefer msg.destroy(sema.gpa); | 19917 | errdefer msg.destroy(sema.gpa); |
| 19979 | | 19918 | |
| 19980 | const src_decl = mod.declPtr(block.src_decl); | 19919 | try sema.explainWhyTypeIsNotExtern(msg, elem_ty_src, elem_ty, .other); |
| 19981 | try sema.explainWhyTypeIsNotExtern(msg, src_decl.toSrcLoc(elem_ty_src, mod), elem_ty, .other); | | |
| 19982 | | 19920 | |
| 19983 | try sema.addDeclaredHereNote(msg, elem_ty); | 19921 | try sema.addDeclaredHereNote(msg, elem_ty); |
| 19984 | break :msg msg; | 19922 | break :msg msg; |
| ... | @@ -19992,10 +19930,9 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air | ... | @@ -19992,10 +19930,9 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 19992 | | 19930 | |
| 19993 | if (host_size != 0 and !try sema.validatePackedType(elem_ty)) { | 19931 | if (host_size != 0 and !try sema.validatePackedType(elem_ty)) { |
| 19994 | return sema.failWithOwnedErrorMsg(block, msg: { | 19932 | return sema.failWithOwnedErrorMsg(block, msg: { |
| 19995 | const msg = try sema.errMsg(block, elem_ty_src, "bit-pointer cannot refer to value of type '{}'", .{elem_ty.fmt(mod)}); | 19933 | const msg = try sema.errMsg(elem_ty_src, "bit-pointer cannot refer to value of type '{}'", .{elem_ty.fmt(mod)}); |
| 19996 | errdefer msg.destroy(sema.gpa); | 19934 | errdefer msg.destroy(sema.gpa); |
| 19997 | const src_decl = mod.declPtr(block.src_decl); | 19935 | try sema.explainWhyTypeIsNotPacked(msg, elem_ty_src, elem_ty); |
| 19998 | try sema.explainWhyTypeIsNotPacked(msg, src_decl.toSrcLoc(elem_ty_src, mod), elem_ty); | | |
| 19999 | break :msg msg; | 19936 | break :msg msg; |
| 20000 | }); | 19937 | }); |
| 20001 | } | 19938 | } |
| ... | @@ -20025,7 +19962,7 @@ fn zirStructInitEmpty(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE | ... | @@ -20025,7 +19962,7 @@ fn zirStructInitEmpty(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE |
| 20025 | | 19962 | |
| 20026 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; | 19963 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 20027 | const src = block.nodeOffset(inst_data.src_node); | 19964 | const src = block.nodeOffset(inst_data.src_node); |
| 20028 | const ty_src: LazySrcLoc = .{ .node_offset_init_ty = inst_data.src_node }; | 19965 | const ty_src = block.src(.{ .node_offset_init_ty = inst_data.src_node }); |
| 20029 | const obj_ty = try sema.resolveType(block, ty_src, inst_data.operand); | 19966 | const obj_ty = try sema.resolveType(block, ty_src, inst_data.operand); |
| 20030 | const mod = sema.mod; | 19967 | const mod = sema.mod; |
| 20031 | | 19968 | |
| ... | @@ -20119,9 +20056,9 @@ fn arrayInitEmpty(sema: *Sema, block: *Block, src: LazySrcLoc, obj_ty: Type) Com | ... | @@ -20119,9 +20056,9 @@ fn arrayInitEmpty(sema: *Sema, block: *Block, src: LazySrcLoc, obj_ty: Type) Com |
| 20119 | | 20056 | |
| 20120 | fn zirUnionInit(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 20057 | fn zirUnionInit(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 20121 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 20058 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 20122 | const ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 20059 | const ty_src = block.builtinCallArgSrc(inst_data.src_node, 0); |
| 20123 | const field_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; | 20060 | const field_src = block.builtinCallArgSrc(inst_data.src_node, 1); |
| 20124 | const init_src: LazySrcLoc = .{ .node_offset_builtin_call_arg2 = inst_data.src_node }; | 20061 | const init_src = block.builtinCallArgSrc(inst_data.src_node, 2); |
| 20125 | const extra = sema.code.extraData(Zir.Inst.UnionInit, inst_data.payload_index).data; | 20062 | const extra = sema.code.extraData(Zir.Inst.UnionInit, inst_data.payload_index).data; |
| 20126 | const union_ty = try sema.resolveType(block, ty_src, extra.union_type); | 20063 | const union_ty = try sema.resolveType(block, ty_src, extra.union_type); |
| 20127 | if (union_ty.zigTypeTag(sema.mod) != .Union) { | 20064 | if (union_ty.zigTypeTag(sema.mod) != .Union) { |
| ... | @@ -20215,7 +20152,7 @@ fn zirStructInit( | ... | @@ -20215,7 +20152,7 @@ fn zirStructInit( |
| 20215 | extra_index = item.end; | 20152 | extra_index = item.end; |
| 20216 | | 20153 | |
| 20217 | const field_type_data = zir_datas[@intFromEnum(item.data.field_type)].pl_node; | 20154 | const field_type_data = zir_datas[@intFromEnum(item.data.field_type)].pl_node; |
| 20218 | const field_src: LazySrcLoc = .{ .node_offset_initializer = field_type_data.src_node }; | 20155 | const field_src = block.src(.{ .node_offset_initializer = field_type_data.src_node }); |
| 20219 | const field_type_extra = sema.code.extraData(Zir.Inst.FieldType, field_type_data.payload_index).data; | 20156 | const field_type_extra = sema.code.extraData(Zir.Inst.FieldType, field_type_data.payload_index).data; |
| 20220 | const field_name = try ip.getOrPutString( | 20157 | const field_name = try ip.getOrPutString( |
| 20221 | gpa, | 20158 | gpa, |
| ... | @@ -20256,7 +20193,7 @@ fn zirStructInit( | ... | @@ -20256,7 +20193,7 @@ fn zirStructInit( |
| 20256 | const item = sema.code.extraData(Zir.Inst.StructInit.Item, extra.end); | 20193 | const item = sema.code.extraData(Zir.Inst.StructInit.Item, extra.end); |
| 20257 | | 20194 | |
| 20258 | const field_type_data = zir_datas[@intFromEnum(item.data.field_type)].pl_node; | 20195 | const field_type_data = zir_datas[@intFromEnum(item.data.field_type)].pl_node; |
| 20259 | const field_src: LazySrcLoc = .{ .node_offset_initializer = field_type_data.src_node }; | 20196 | const field_src = block.src(.{ .node_offset_initializer = field_type_data.src_node }); |
| 20260 | const field_type_extra = sema.code.extraData(Zir.Inst.FieldType, field_type_data.payload_index).data; | 20197 | const field_type_extra = sema.code.extraData(Zir.Inst.FieldType, field_type_data.payload_index).data; |
| 20261 | const field_name = try ip.getOrPutString( | 20198 | const field_name = try ip.getOrPutString( |
| 20262 | gpa, | 20199 | gpa, |
| ... | @@ -20270,7 +20207,7 @@ fn zirStructInit( | ... | @@ -20270,7 +20207,7 @@ fn zirStructInit( |
| 20270 | | 20207 | |
| 20271 | if (field_ty.zigTypeTag(mod) == .NoReturn) { | 20208 | if (field_ty.zigTypeTag(mod) == .NoReturn) { |
| 20272 | return sema.failWithOwnedErrorMsg(block, msg: { | 20209 | return sema.failWithOwnedErrorMsg(block, msg: { |
| 20273 | const msg = try sema.errMsg(block, src, "cannot initialize 'noreturn' field of union", .{}); | 20210 | const msg = try sema.errMsg(src, "cannot initialize 'noreturn' field of union", .{}); |
| 20274 | errdefer msg.destroy(sema.gpa); | 20211 | errdefer msg.destroy(sema.gpa); |
| 20275 | | 20212 | |
| 20276 | try sema.addFieldErrNote(resolved_ty, field_index, msg, "field '{}' declared here", .{ | 20213 | try sema.addFieldErrNote(resolved_ty, field_index, msg, "field '{}' declared here", .{ |
| ... | @@ -20348,16 +20285,12 @@ fn finishStructInit( | ... | @@ -20348,16 +20285,12 @@ fn finishStructInit( |
| 20348 | for (0..anon_struct.types.len) |i| { | 20285 | for (0..anon_struct.types.len) |i| { |
| 20349 | if (field_inits[i] != .none) { | 20286 | if (field_inits[i] != .none) { |
| 20350 | // Coerce the init value to the field type. | 20287 | // Coerce the init value to the field type. |
| | 20288 | const field_src = block.src(.{ .init_elem = .{ |
| | 20289 | .init_node_offset = init_src.offset.node_offset.x, |
| | 20290 | .elem_index = @intCast(i), |
| | 20291 | } }); |
| 20351 | const field_ty = Type.fromInterned(anon_struct.types.get(ip)[i]); | 20292 | const field_ty = Type.fromInterned(anon_struct.types.get(ip)[i]); |
| 20352 | field_inits[i] = sema.coerce(block, field_ty, field_inits[i], .unneeded) catch |err| switch (err) { | 20293 | field_inits[i] = try sema.coerce(block, field_ty, field_inits[i], field_src); |
| 20353 | error.NeededSourceLocation => { | | |
| 20354 | const decl = mod.declPtr(block.src_decl); | | |
| 20355 | const field_src = mod.initSrc(init_src.node_offset.x, decl, i); | | |
| 20356 | _ = try sema.coerce(block, field_ty, field_inits[i], field_src); | | |
| 20357 | unreachable; | | |
| 20358 | }, | | |
| 20359 | else => |e| return e, | | |
| 20360 | }; | | |
| 20361 | continue; | 20294 | continue; |
| 20362 | } | 20295 | } |
| 20363 | | 20296 | |
| ... | @@ -20367,18 +20300,18 @@ fn finishStructInit( | ... | @@ -20367,18 +20300,18 @@ fn finishStructInit( |
| 20367 | if (anon_struct.names.len == 0) { | 20300 | if (anon_struct.names.len == 0) { |
| 20368 | const template = "missing tuple field with index {d}"; | 20301 | const template = "missing tuple field with index {d}"; |
| 20369 | if (root_msg) |msg| { | 20302 | if (root_msg) |msg| { |
| 20370 | try sema.errNote(block, init_src, msg, template, .{i}); | 20303 | try sema.errNote(init_src, msg, template, .{i}); |
| 20371 | } else { | 20304 | } else { |
| 20372 | root_msg = try sema.errMsg(block, init_src, template, .{i}); | 20305 | root_msg = try sema.errMsg(init_src, template, .{i}); |
| 20373 | } | 20306 | } |
| 20374 | } else { | 20307 | } else { |
| 20375 | const field_name = anon_struct.names.get(ip)[i]; | 20308 | const field_name = anon_struct.names.get(ip)[i]; |
| 20376 | const template = "missing struct field: {}"; | 20309 | const template = "missing struct field: {}"; |
| 20377 | const args = .{field_name.fmt(ip)}; | 20310 | const args = .{field_name.fmt(ip)}; |
| 20378 | if (root_msg) |msg| { | 20311 | if (root_msg) |msg| { |
| 20379 | try sema.errNote(block, init_src, msg, template, args); | 20312 | try sema.errNote(init_src, msg, template, args); |
| 20380 | } else { | 20313 | } else { |
| 20381 | root_msg = try sema.errMsg(block, init_src, template, args); | 20314 | root_msg = try sema.errMsg(init_src, template, args); |
| 20382 | } | 20315 | } |
| 20383 | } | 20316 | } |
| 20384 | } else { | 20317 | } else { |
| ... | @@ -20391,16 +20324,12 @@ fn finishStructInit( | ... | @@ -20391,16 +20324,12 @@ fn finishStructInit( |
| 20391 | for (0..struct_type.field_types.len) |i| { | 20324 | for (0..struct_type.field_types.len) |i| { |
| 20392 | if (field_inits[i] != .none) { | 20325 | if (field_inits[i] != .none) { |
| 20393 | // Coerce the init value to the field type. | 20326 | // Coerce the init value to the field type. |
| | 20327 | const field_src = block.src(.{ .init_elem = .{ |
| | 20328 | .init_node_offset = init_src.offset.node_offset.x, |
| | 20329 | .elem_index = @intCast(i), |
| | 20330 | } }); |
| 20394 | const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[i]); | 20331 | const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[i]); |
| 20395 | field_inits[i] = sema.coerce(block, field_ty, field_inits[i], init_src) catch |err| switch (err) { | 20332 | field_inits[i] = try sema.coerce(block, field_ty, field_inits[i], field_src); |
| 20396 | error.NeededSourceLocation => { | | |
| 20397 | const decl = mod.declPtr(block.src_decl); | | |
| 20398 | const field_src = mod.initSrc(init_src.node_offset.x, decl, i); | | |
| 20399 | _ = try sema.coerce(block, field_ty, field_inits[i], field_src); | | |
| 20400 | unreachable; | | |
| 20401 | }, | | |
| 20402 | else => |e| return e, | | |
| 20403 | }; | | |
| 20404 | continue; | 20333 | continue; |
| 20405 | } | 20334 | } |
| 20406 | | 20335 | |
| ... | @@ -20413,16 +20342,16 @@ fn finishStructInit( | ... | @@ -20413,16 +20342,16 @@ fn finishStructInit( |
| 20413 | const template = "missing struct field: {}"; | 20342 | const template = "missing struct field: {}"; |
| 20414 | const args = .{field_name.fmt(ip)}; | 20343 | const args = .{field_name.fmt(ip)}; |
| 20415 | if (root_msg) |msg| { | 20344 | if (root_msg) |msg| { |
| 20416 | try sema.errNote(block, init_src, msg, template, args); | 20345 | try sema.errNote(init_src, msg, template, args); |
| 20417 | } else { | 20346 | } else { |
| 20418 | root_msg = try sema.errMsg(block, init_src, template, args); | 20347 | root_msg = try sema.errMsg(init_src, template, args); |
| 20419 | } | 20348 | } |
| 20420 | } else { | 20349 | } else { |
| 20421 | const template = "missing tuple field with index {d}"; | 20350 | const template = "missing tuple field with index {d}"; |
| 20422 | if (root_msg) |msg| { | 20351 | if (root_msg) |msg| { |
| 20423 | try sema.errNote(block, init_src, msg, template, .{i}); | 20352 | try sema.errNote(init_src, msg, template, .{i}); |
| 20424 | } else { | 20353 | } else { |
| 20425 | root_msg = try sema.errMsg(block, init_src, template, .{i}); | 20354 | root_msg = try sema.errMsg(init_src, template, .{i}); |
| 20426 | } | 20355 | } |
| 20427 | } | 20356 | } |
| 20428 | } else { | 20357 | } else { |
| ... | @@ -20434,16 +20363,7 @@ fn finishStructInit( | ... | @@ -20434,16 +20363,7 @@ fn finishStructInit( |
| 20434 | } | 20363 | } |
| 20435 | | 20364 | |
| 20436 | if (root_msg) |msg| { | 20365 | if (root_msg) |msg| { |
| 20437 | if (mod.typeToStruct(struct_ty)) |struct_type| { | 20366 | try sema.addDeclaredHereNote(msg, struct_ty); |
| 20438 | const decl = mod.declPtr(struct_type.decl.unwrap().?); | | |
| 20439 | const fqn = try decl.fullyQualifiedName(mod); | | |
| 20440 | try mod.errNoteNonLazy( | | |
| 20441 | decl.srcLoc(mod), | | |
| 20442 | msg, | | |
| 20443 | "struct '{}' declared here", | | |
| 20444 | .{fqn.fmt(ip)}, | | |
| 20445 | ); | | |
| 20446 | } | | |
| 20447 | root_msg = null; | 20367 | root_msg = null; |
| 20448 | return sema.failWithOwnedErrorMsg(block, msg); | 20368 | return sema.failWithOwnedErrorMsg(block, msg); |
| 20449 | } | 20369 | } |
| ... | @@ -20470,9 +20390,10 @@ fn finishStructInit( | ... | @@ -20470,9 +20390,10 @@ fn finishStructInit( |
| 20470 | }; | 20390 | }; |
| 20471 | | 20391 | |
| 20472 | if (try sema.typeRequiresComptime(struct_ty)) { | 20392 | if (try sema.typeRequiresComptime(struct_ty)) { |
| 20473 | const decl = mod.declPtr(block.src_decl); | 20393 | return sema.failWithNeededComptime(block, block.src(.{ .init_elem = .{ |
| 20474 | const field_src = mod.initSrc(init_src.node_offset.x, decl, runtime_index); | 20394 | .init_node_offset = init_src.offset.node_offset.x, |
| 20475 | return sema.failWithNeededComptime(block, field_src, .{ | 20395 | .elem_index = @intCast(runtime_index), |
| | 20396 | } }), .{ |
| 20476 | .needed_comptime_reason = "initializer of comptime only struct must be comptime-known", | 20397 | .needed_comptime_reason = "initializer of comptime only struct must be comptime-known", |
| 20477 | }); | 20398 | }); |
| 20478 | } | 20399 | } |
| ... | @@ -20500,15 +20421,10 @@ fn finishStructInit( | ... | @@ -20500,15 +20421,10 @@ fn finishStructInit( |
| 20500 | return sema.makePtrConst(block, alloc); | 20421 | return sema.makePtrConst(block, alloc); |
| 20501 | } | 20422 | } |
| 20502 | | 20423 | |
| 20503 | sema.requireRuntimeBlock(block, .unneeded, null) catch |err| switch (err) { | 20424 | try sema.requireRuntimeBlock(block, dest_src, block.src(.{ .init_elem = .{ |
| 20504 | error.NeededSourceLocation => { | 20425 | .init_node_offset = init_src.offset.node_offset.x, |
| 20505 | const decl = mod.declPtr(block.src_decl); | 20426 | .elem_index = @intCast(runtime_index), |
| 20506 | const field_src = mod.initSrc(dest_src.node_offset.x, decl, runtime_index); | 20427 | } })); |
| 20507 | try sema.requireRuntimeBlock(block, dest_src, field_src); | | |
| 20508 | unreachable; | | |
| 20509 | }, | | |
| 20510 | else => |e| return e, | | |
| 20511 | }; | | |
| 20512 | try sema.resolveStructFieldInits(struct_ty); | 20428 | try sema.resolveStructFieldInits(struct_ty); |
| 20513 | try sema.queueFullTypeResolution(struct_ty); | 20429 | try sema.queueFullTypeResolution(struct_ty); |
| 20514 | const struct_val = try block.addAggregateInit(struct_ty, field_inits); | 20430 | const struct_val = try block.addAggregateInit(struct_ty, field_inits); |
| ... | @@ -20576,9 +20492,11 @@ fn structInitAnon( | ... | @@ -20576,9 +20492,11 @@ fn structInitAnon( |
| 20576 | field_ty.* = sema.typeOf(init).toIntern(); | 20492 | field_ty.* = sema.typeOf(init).toIntern(); |
| 20577 | if (Type.fromInterned(field_ty.*).zigTypeTag(mod) == .Opaque) { | 20493 | if (Type.fromInterned(field_ty.*).zigTypeTag(mod) == .Opaque) { |
| 20578 | const msg = msg: { | 20494 | const msg = msg: { |
| 20579 | const decl = mod.declPtr(block.src_decl); | 20495 | const field_src = block.src(.{ .init_elem = .{ |
| 20580 | const field_src = mod.initSrc(src.node_offset.x, decl, @intCast(i_usize)); | 20496 | .init_node_offset = src.offset.node_offset.x, |
| 20581 | const msg = try sema.errMsg(block, field_src, "opaque types have unknown size and therefore cannot be directly embedded in structs", .{}); | 20497 | .elem_index = @intCast(i_usize), |
| | 20498 | } }); |
| | 20499 | const msg = try sema.errMsg(field_src, "opaque types have unknown size and therefore cannot be directly embedded in structs", .{}); |
| 20582 | errdefer msg.destroy(sema.gpa); | 20500 | errdefer msg.destroy(sema.gpa); |
| 20583 | | 20501 | |
| 20584 | try sema.addDeclaredHereNote(msg, Type.fromInterned(field_ty.*)); | 20502 | try sema.addDeclaredHereNote(msg, Type.fromInterned(field_ty.*)); |
| ... | @@ -20610,15 +20528,10 @@ fn structInitAnon( | ... | @@ -20610,15 +20528,10 @@ fn structInitAnon( |
| 20610 | return sema.addConstantMaybeRef(tuple_val, is_ref); | 20528 | return sema.addConstantMaybeRef(tuple_val, is_ref); |
| 20611 | }; | 20529 | }; |
| 20612 | | 20530 | |
| 20613 | sema.requireRuntimeBlock(block, .unneeded, null) catch |err| switch (err) { | 20531 | try sema.requireRuntimeBlock(block, LazySrcLoc.unneeded, block.src(.{ .init_elem = .{ |
| 20614 | error.NeededSourceLocation => { | 20532 | .init_node_offset = src.offset.node_offset.x, |
| 20615 | const decl = mod.declPtr(block.src_decl); | 20533 | .elem_index = @intCast(runtime_index), |
| 20616 | const field_src = mod.initSrc(src.node_offset.x, decl, runtime_index); | 20534 | } })); |
| 20617 | try sema.requireRuntimeBlock(block, src, field_src); | | |
| 20618 | unreachable; | | |
| 20619 | }, | | |
| 20620 | else => |e| return e, | | |
| 20621 | }; | | |
| 20622 | | 20535 | |
| 20623 | if (is_ref) { | 20536 | if (is_ref) { |
| 20624 | const target = mod.getTarget(); | 20537 | const target = mod.getTarget(); |
| ... | @@ -20697,15 +20610,19 @@ fn zirArrayInit( | ... | @@ -20697,15 +20610,19 @@ fn zirArrayInit( |
| 20697 | const resolved_args = try gpa.alloc(Air.Inst.Ref, final_len); | 20610 | const resolved_args = try gpa.alloc(Air.Inst.Ref, final_len); |
| 20698 | defer gpa.free(resolved_args); | 20611 | defer gpa.free(resolved_args); |
| 20699 | for (resolved_args, 0..) |*dest, i| { | 20612 | for (resolved_args, 0..) |*dest, i| { |
| | 20613 | const elem_src = block.src(.{ .init_elem = .{ |
| | 20614 | .init_node_offset = src.offset.node_offset.x, |
| | 20615 | .elem_index = @intCast(i), |
| | 20616 | } }); |
| 20700 | // Less inits than needed. | 20617 | // Less inits than needed. |
| 20701 | if (i + 2 > args.len) if (is_tuple) { | 20618 | if (i + 2 > args.len) if (is_tuple) { |
| 20702 | const default_val = array_ty.structFieldDefaultValue(i, mod).toIntern(); | 20619 | const default_val = array_ty.structFieldDefaultValue(i, mod).toIntern(); |
| 20703 | if (default_val == .unreachable_value) { | 20620 | if (default_val == .unreachable_value) { |
| 20704 | const template = "missing tuple field with index {d}"; | 20621 | const template = "missing tuple field with index {d}"; |
| 20705 | if (root_msg) |msg| { | 20622 | if (root_msg) |msg| { |
| 20706 | try sema.errNote(block, src, msg, template, .{i}); | 20623 | try sema.errNote(src, msg, template, .{i}); |
| 20707 | } else { | 20624 | } else { |
| 20708 | root_msg = try sema.errMsg(block, src, template, .{i}); | 20625 | root_msg = try sema.errMsg(src, template, .{i}); |
| 20709 | } | 20626 | } |
| 20710 | } else { | 20627 | } else { |
| 20711 | dest.* = Air.internedToRef(default_val); | 20628 | dest.* = Air.internedToRef(default_val); |
| ... | @@ -20722,29 +20639,17 @@ fn zirArrayInit( | ... | @@ -20722,29 +20639,17 @@ fn zirArrayInit( |
| 20722 | array_ty.structFieldType(i, mod) | 20639 | array_ty.structFieldType(i, mod) |
| 20723 | else | 20640 | else |
| 20724 | array_ty.elemType2(mod); | 20641 | array_ty.elemType2(mod); |
| 20725 | dest.* = sema.coerce(block, elem_ty, resolved_arg, .unneeded) catch |err| switch (err) { | 20642 | dest.* = try sema.coerce(block, elem_ty, resolved_arg, elem_src); |
| 20726 | error.NeededSourceLocation => { | | |
| 20727 | const decl = mod.declPtr(block.src_decl); | | |
| 20728 | const elem_src = mod.initSrc(src.node_offset.x, decl, i); | | |
| 20729 | _ = try sema.coerce(block, elem_ty, resolved_arg, elem_src); | | |
| 20730 | unreachable; | | |
| 20731 | }, | | |
| 20732 | else => return err, | | |
| 20733 | }; | | |
| 20734 | if (is_tuple) { | 20643 | if (is_tuple) { |
| 20735 | if (array_ty.structFieldIsComptime(i, mod)) | 20644 | if (array_ty.structFieldIsComptime(i, mod)) |
| 20736 | try sema.resolveStructFieldInits(array_ty); | 20645 | try sema.resolveStructFieldInits(array_ty); |
| 20737 | if (try array_ty.structFieldValueComptime(mod, i)) |field_val| { | 20646 | if (try array_ty.structFieldValueComptime(mod, i)) |field_val| { |
| 20738 | const init_val = try sema.resolveValue(dest.*) orelse { | 20647 | const init_val = try sema.resolveValue(dest.*) orelse { |
| 20739 | const decl = mod.declPtr(block.src_decl); | | |
| 20740 | const elem_src = mod.initSrc(src.node_offset.x, decl, i); | | |
| 20741 | return sema.failWithNeededComptime(block, elem_src, .{ | 20648 | return sema.failWithNeededComptime(block, elem_src, .{ |
| 20742 | .needed_comptime_reason = "value stored in comptime field must be comptime-known", | 20649 | .needed_comptime_reason = "value stored in comptime field must be comptime-known", |
| 20743 | }); | 20650 | }); |
| 20744 | }; | 20651 | }; |
| 20745 | if (!field_val.eql(init_val, elem_ty, mod)) { | 20652 | if (!field_val.eql(init_val, elem_ty, mod)) { |
| 20746 | const decl = mod.declPtr(block.src_decl); | | |
| 20747 | const elem_src = mod.initSrc(src.node_offset.x, decl, i); | | |
| 20748 | return sema.failWithInvalidComptimeFieldStore(block, elem_src, array_ty, i); | 20653 | return sema.failWithInvalidComptimeFieldStore(block, elem_src, array_ty, i); |
| 20749 | } | 20654 | } |
| 20750 | } | 20655 | } |
| ... | @@ -20777,15 +20682,10 @@ fn zirArrayInit( | ... | @@ -20777,15 +20682,10 @@ fn zirArrayInit( |
| 20777 | return sema.addConstantMaybeRef(result_val.toIntern(), is_ref); | 20682 | return sema.addConstantMaybeRef(result_val.toIntern(), is_ref); |
| 20778 | }; | 20683 | }; |
| 20779 | | 20684 | |
| 20780 | sema.requireRuntimeBlock(block, .unneeded, null) catch |err| switch (err) { | 20685 | try sema.requireRuntimeBlock(block, LazySrcLoc.unneeded, block.src(.{ .init_elem = .{ |
| 20781 | error.NeededSourceLocation => { | 20686 | .init_node_offset = src.offset.node_offset.x, |
| 20782 | const decl = mod.declPtr(block.src_decl); | 20687 | .elem_index = runtime_index, |
| 20783 | const elem_src = mod.initSrc(src.node_offset.x, decl, runtime_index); | 20688 | } })); |
| 20784 | try sema.requireRuntimeBlock(block, src, elem_src); | | |
| 20785 | unreachable; | | |
| 20786 | }, | | |
| 20787 | else => return err, | | |
| 20788 | }; | | |
| 20789 | try sema.queueFullTypeResolution(array_ty); | 20689 | try sema.queueFullTypeResolution(array_ty); |
| 20790 | | 20690 | |
| 20791 | if (is_ref) { | 20691 | if (is_ref) { |
| ... | @@ -20864,7 +20764,7 @@ fn arrayInitAnon( | ... | @@ -20864,7 +20764,7 @@ fn arrayInitAnon( |
| 20864 | types[i] = sema.typeOf(elem).toIntern(); | 20764 | types[i] = sema.typeOf(elem).toIntern(); |
| 20865 | if (Type.fromInterned(types[i]).zigTypeTag(mod) == .Opaque) { | 20765 | if (Type.fromInterned(types[i]).zigTypeTag(mod) == .Opaque) { |
| 20866 | const msg = msg: { | 20766 | const msg = msg: { |
| 20867 | const msg = try sema.errMsg(block, operand_src, "opaque types have unknown size and therefore cannot be directly embedded in structs", .{}); | 20767 | const msg = try sema.errMsg(operand_src, "opaque types have unknown size and therefore cannot be directly embedded in structs", .{}); |
| 20868 | errdefer msg.destroy(gpa); | 20768 | errdefer msg.destroy(gpa); |
| 20869 | | 20769 | |
| 20870 | try sema.addDeclaredHereNote(msg, Type.fromInterned(types[i])); | 20770 | try sema.addDeclaredHereNote(msg, Type.fromInterned(types[i])); |
| ... | @@ -20935,8 +20835,8 @@ fn addConstantMaybeRef(sema: *Sema, val: InternPool.Index, is_ref: bool) !Air.In | ... | @@ -20935,8 +20835,8 @@ fn addConstantMaybeRef(sema: *Sema, val: InternPool.Index, is_ref: bool) !Air.In |
| 20935 | fn zirFieldTypeRef(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 20835 | fn zirFieldTypeRef(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 20936 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 20836 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 20937 | const extra = sema.code.extraData(Zir.Inst.FieldTypeRef, inst_data.payload_index).data; | 20837 | const extra = sema.code.extraData(Zir.Inst.FieldTypeRef, inst_data.payload_index).data; |
| 20938 | const ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 20838 | const ty_src = block.builtinCallArgSrc(inst_data.src_node, 0); |
| 20939 | const field_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; | 20839 | const field_src = block.builtinCallArgSrc(inst_data.src_node, 1); |
| 20940 | const aggregate_ty = try sema.resolveType(block, ty_src, extra.container_type); | 20840 | const aggregate_ty = try sema.resolveType(block, ty_src, extra.container_type); |
| 20941 | const field_name = try sema.resolveConstStringIntern(block, field_src, extra.field_name, .{ | 20841 | const field_name = try sema.resolveConstStringIntern(block, field_src, extra.field_name, .{ |
| 20942 | .needed_comptime_reason = "field name must be comptime-known", | 20842 | .needed_comptime_reason = "field name must be comptime-known", |
| ... | @@ -20950,7 +20850,7 @@ fn zirStructInitFieldType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp | ... | @@ -20950,7 +20850,7 @@ fn zirStructInitFieldType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp |
| 20950 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 20850 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 20951 | const extra = sema.code.extraData(Zir.Inst.FieldType, inst_data.payload_index).data; | 20851 | const extra = sema.code.extraData(Zir.Inst.FieldType, inst_data.payload_index).data; |
| 20952 | const ty_src = block.nodeOffset(inst_data.src_node); | 20852 | const ty_src = block.nodeOffset(inst_data.src_node); |
| 20953 | const field_name_src: LazySrcLoc = .{ .node_offset_field_name_init = inst_data.src_node }; | 20853 | const field_name_src = block.src(.{ .node_offset_field_name_init = inst_data.src_node }); |
| 20954 | const wrapped_aggregate_ty = sema.resolveType(block, ty_src, extra.container_type) catch |err| switch (err) { | 20854 | const wrapped_aggregate_ty = sema.resolveType(block, ty_src, extra.container_type) catch |err| switch (err) { |
| 20955 | // Since this is a ZIR instruction that returns a type, encountering | 20855 | // Since this is a ZIR instruction that returns a type, encountering |
| 20956 | // generic poison should not result in a failed compilation, but the | 20856 | // generic poison should not result in a failed compilation, but the |
| ... | @@ -20990,7 +20890,7 @@ fn fieldType( | ... | @@ -20990,7 +20890,7 @@ fn fieldType( |
| 20990 | .struct_type => { | 20890 | .struct_type => { |
| 20991 | const struct_type = ip.loadStructType(cur_ty.toIntern()); | 20891 | const struct_type = ip.loadStructType(cur_ty.toIntern()); |
| 20992 | const field_index = struct_type.nameIndex(ip, field_name) orelse | 20892 | const field_index = struct_type.nameIndex(ip, field_name) orelse |
| 20993 | return sema.failWithBadStructFieldAccess(block, struct_type, field_src, field_name); | 20893 | return sema.failWithBadStructFieldAccess(block, cur_ty, struct_type, field_src, field_name); |
| 20994 | const field_ty = struct_type.field_types.get(ip)[field_index]; | 20894 | const field_ty = struct_type.field_types.get(ip)[field_index]; |
| 20995 | return Air.internedToRef(field_ty); | 20895 | return Air.internedToRef(field_ty); |
| 20996 | }, | 20896 | }, |
| ... | @@ -20999,7 +20899,7 @@ fn fieldType( | ... | @@ -20999,7 +20899,7 @@ fn fieldType( |
| 20999 | .Union => { | 20899 | .Union => { |
| 21000 | const union_obj = mod.typeToUnion(cur_ty).?; | 20900 | const union_obj = mod.typeToUnion(cur_ty).?; |
| 21001 | const field_index = union_obj.loadTagType(ip).nameIndex(ip, field_name) orelse | 20901 | const field_index = union_obj.loadTagType(ip).nameIndex(ip, field_name) orelse |
| 21002 | return sema.failWithBadUnionFieldAccess(block, union_obj, field_src, field_name); | 20902 | return sema.failWithBadUnionFieldAccess(block, cur_ty, union_obj, field_src, field_name); |
| 21003 | const field_ty = union_obj.field_types.get(ip)[field_index]; | 20903 | const field_ty = union_obj.field_types.get(ip)[field_index]; |
| 21004 | return Air.internedToRef(field_ty); | 20904 | return Air.internedToRef(field_ty); |
| 21005 | }, | 20905 | }, |
| ... | @@ -21050,14 +20950,14 @@ fn zirFrame( | ... | @@ -21050,14 +20950,14 @@ fn zirFrame( |
| 21050 | block: *Block, | 20950 | block: *Block, |
| 21051 | extended: Zir.Inst.Extended.InstData, | 20951 | extended: Zir.Inst.Extended.InstData, |
| 21052 | ) CompileError!Air.Inst.Ref { | 20952 | ) CompileError!Air.Inst.Ref { |
| 21053 | const src = LazySrcLoc.nodeOffset(@bitCast(extended.operand)); | 20953 | const src = block.nodeOffset(@bitCast(extended.operand)); |
| 21054 | return sema.failWithUseOfAsync(block, src); | 20954 | return sema.failWithUseOfAsync(block, src); |
| 21055 | } | 20955 | } |
| 21056 | | 20956 | |
| 21057 | fn zirAlignOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 20957 | fn zirAlignOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 21058 | const mod = sema.mod; | 20958 | const mod = sema.mod; |
| 21059 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; | 20959 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 21060 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 20960 | const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0); |
| 21061 | const ty = try sema.resolveType(block, operand_src, inst_data.operand); | 20961 | const ty = try sema.resolveType(block, operand_src, inst_data.operand); |
| 21062 | if (ty.isNoReturn(mod)) { | 20962 | if (ty.isNoReturn(mod)) { |
| 21063 | return sema.fail(block, operand_src, "no align available for type '{}'", .{ty.fmt(sema.mod)}); | 20963 | return sema.fail(block, operand_src, "no align available for type '{}'", .{ty.fmt(sema.mod)}); |
| ... | @@ -21121,7 +21021,7 @@ fn zirIntFromBool(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError | ... | @@ -21121,7 +21021,7 @@ fn zirIntFromBool(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 21121 | | 21021 | |
| 21122 | fn zirErrorName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 21022 | fn zirErrorName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 21123 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; | 21023 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 21124 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 21024 | const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0); |
| 21125 | const uncoerced_operand = try sema.resolveInst(inst_data.operand); | 21025 | const uncoerced_operand = try sema.resolveInst(inst_data.operand); |
| 21126 | const operand = try sema.coerce(block, Type.anyerror, uncoerced_operand, operand_src); | 21026 | const operand = try sema.coerce(block, Type.anyerror, uncoerced_operand, operand_src); |
| 21127 | | 21027 | |
| ... | @@ -21143,7 +21043,7 @@ fn zirAbs( | ... | @@ -21143,7 +21043,7 @@ fn zirAbs( |
| 21143 | const mod = sema.mod; | 21043 | const mod = sema.mod; |
| 21144 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; | 21044 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 21145 | const operand = try sema.resolveInst(inst_data.operand); | 21045 | const operand = try sema.resolveInst(inst_data.operand); |
| 21146 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 21046 | const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0); |
| 21147 | const operand_ty = sema.typeOf(operand); | 21047 | const operand_ty = sema.typeOf(operand); |
| 21148 | const scalar_ty = operand_ty.scalarType(mod); | 21048 | const scalar_ty = operand_ty.scalarType(mod); |
| 21149 | | 21049 | |
| ... | @@ -21211,7 +21111,7 @@ fn zirUnaryMath( | ... | @@ -21211,7 +21111,7 @@ fn zirUnaryMath( |
| 21211 | const mod = sema.mod; | 21111 | const mod = sema.mod; |
| 21212 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; | 21112 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 21213 | const operand = try sema.resolveInst(inst_data.operand); | 21113 | const operand = try sema.resolveInst(inst_data.operand); |
| 21214 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 21114 | const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0); |
| 21215 | const operand_ty = sema.typeOf(operand); | 21115 | const operand_ty = sema.typeOf(operand); |
| 21216 | const scalar_ty = operand_ty.scalarType(mod); | 21116 | const scalar_ty = operand_ty.scalarType(mod); |
| 21217 | | 21117 | |
| ... | @@ -21233,7 +21133,7 @@ fn zirUnaryMath( | ... | @@ -21233,7 +21133,7 @@ fn zirUnaryMath( |
| 21233 | | 21133 | |
| 21234 | fn zirTagName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 21134 | fn zirTagName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 21235 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; | 21135 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 21236 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 21136 | const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0); |
| 21237 | const src = block.nodeOffset(inst_data.src_node); | 21137 | const src = block.nodeOffset(inst_data.src_node); |
| 21238 | const operand = try sema.resolveInst(inst_data.operand); | 21138 | const operand = try sema.resolveInst(inst_data.operand); |
| 21239 | const operand_ty = sema.typeOf(operand); | 21139 | const operand_ty = sema.typeOf(operand); |
| ... | @@ -21243,7 +21143,7 @@ fn zirTagName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air | ... | @@ -21243,7 +21143,7 @@ fn zirTagName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 21243 | try sema.resolveTypeLayout(operand_ty); | 21143 | try sema.resolveTypeLayout(operand_ty); |
| 21244 | const enum_ty = switch (operand_ty.zigTypeTag(mod)) { | 21144 | const enum_ty = switch (operand_ty.zigTypeTag(mod)) { |
| 21245 | .EnumLiteral => { | 21145 | .EnumLiteral => { |
| 21246 | const val = try sema.resolveConstDefinedValue(block, .unneeded, operand, undefined); | 21146 | const val = try sema.resolveConstDefinedValue(block, LazySrcLoc.unneeded, operand, undefined); |
| 21247 | const tag_name = ip.indexToKey(val.toIntern()).enum_literal; | 21147 | const tag_name = ip.indexToKey(val.toIntern()).enum_literal; |
| 21248 | return sema.addNullTerminatedStrLit(tag_name); | 21148 | return sema.addNullTerminatedStrLit(tag_name); |
| 21249 | }, | 21149 | }, |
| ... | @@ -21266,13 +21166,12 @@ fn zirTagName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air | ... | @@ -21266,13 +21166,12 @@ fn zirTagName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 21266 | const casted_operand = try sema.coerce(block, enum_ty, operand, operand_src); | 21166 | const casted_operand = try sema.coerce(block, enum_ty, operand, operand_src); |
| 21267 | if (try sema.resolveDefinedValue(block, operand_src, casted_operand)) |val| { | 21167 | if (try sema.resolveDefinedValue(block, operand_src, casted_operand)) |val| { |
| 21268 | const field_index = enum_ty.enumTagFieldIndex(val, mod) orelse { | 21168 | const field_index = enum_ty.enumTagFieldIndex(val, mod) orelse { |
| 21269 | const enum_decl = mod.declPtr(enum_decl_index); | | |
| 21270 | const msg = msg: { | 21169 | const msg = msg: { |
| 21271 | const msg = try sema.errMsg(block, src, "no field with value '{}' in enum '{}'", .{ | 21170 | const msg = try sema.errMsg(src, "no field with value '{}' in enum '{}'", .{ |
| 21272 | val.fmtValue(sema.mod, sema), enum_decl.name.fmt(ip), | 21171 | val.fmtValue(sema.mod, sema), mod.declPtr(enum_decl_index).name.fmt(ip), |
| 21273 | }); | 21172 | }); |
| 21274 | errdefer msg.destroy(sema.gpa); | 21173 | errdefer msg.destroy(sema.gpa); |
| 21275 | try mod.errNoteNonLazy(enum_decl.srcLoc(mod), msg, "declared here", .{}); | 21174 | try sema.errNote(enum_ty.srcLoc(mod), msg, "declared here", .{}); |
| 21276 | break :msg msg; | 21175 | break :msg msg; |
| 21277 | }; | 21176 | }; |
| 21278 | return sema.failWithOwnedErrorMsg(block, msg); | 21177 | return sema.failWithOwnedErrorMsg(block, msg); |
| ... | @@ -21303,10 +21202,10 @@ fn zirReify( | ... | @@ -21303,10 +21202,10 @@ fn zirReify( |
| 21303 | const ip = &mod.intern_pool; | 21202 | const ip = &mod.intern_pool; |
| 21304 | const name_strategy: Zir.Inst.NameStrategy = @enumFromInt(extended.small); | 21203 | const name_strategy: Zir.Inst.NameStrategy = @enumFromInt(extended.small); |
| 21305 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; | 21204 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; |
| 21306 | const src = LazySrcLoc.nodeOffset(extra.node); | 21205 | const src = block.nodeOffset(extra.node); |
| 21307 | const type_info_ty = try sema.getBuiltinType("Type"); | 21206 | const type_info_ty = try sema.getBuiltinType("Type"); |
| 21308 | const uncasted_operand = try sema.resolveInst(extra.operand); | 21207 | const uncasted_operand = try sema.resolveInst(extra.operand); |
| 21309 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node }; | 21208 | const operand_src = block.builtinCallArgSrc(extra.node, 0); |
| 21310 | const type_info = try sema.coerce(block, type_info_ty, uncasted_operand, operand_src); | 21209 | const type_info = try sema.coerce(block, type_info_ty, uncasted_operand, operand_src); |
| 21311 | const val = try sema.resolveConstDefinedValue(block, operand_src, type_info, .{ | 21210 | const val = try sema.resolveConstDefinedValue(block, operand_src, type_info, .{ |
| 21312 | .needed_comptime_reason = "operand to @Type must be comptime-known", | 21211 | .needed_comptime_reason = "operand to @Type must be comptime-known", |
| ... | @@ -21459,11 +21358,10 @@ fn zirReify( | ... | @@ -21459,11 +21358,10 @@ fn zirReify( |
| 21459 | } else if (ptr_size == .C) { | 21358 | } else if (ptr_size == .C) { |
| 21460 | if (!try sema.validateExternType(elem_ty, .other)) { | 21359 | if (!try sema.validateExternType(elem_ty, .other)) { |
| 21461 | const msg = msg: { | 21360 | const msg = msg: { |
| 21462 | const msg = try sema.errMsg(block, src, "C pointers cannot point to non-C-ABI-compatible type '{}'", .{elem_ty.fmt(mod)}); | 21361 | const msg = try sema.errMsg(src, "C pointers cannot point to non-C-ABI-compatible type '{}'", .{elem_ty.fmt(mod)}); |
| 21463 | errdefer msg.destroy(gpa); | 21362 | errdefer msg.destroy(gpa); |
| 21464 | | 21363 | |
| 21465 | const src_decl = mod.declPtr(block.src_decl); | 21364 | try sema.explainWhyTypeIsNotExtern(msg, src, elem_ty, .other); |
| 21466 | try sema.explainWhyTypeIsNotExtern(msg, src_decl.toSrcLoc(src, mod), elem_ty, .other); | | |
| 21467 | | 21365 | |
| 21468 | try sema.addDeclaredHereNote(msg, elem_ty); | 21366 | try sema.addDeclaredHereNote(msg, elem_ty); |
| 21469 | break :msg msg; | 21367 | break :msg msg; |
| ... | @@ -21679,7 +21577,6 @@ fn zirReify( | ... | @@ -21679,7 +21577,6 @@ fn zirReify( |
| 21679 | | 21577 | |
| 21680 | const new_decl_index = try sema.createAnonymousDeclTypeNamed( | 21578 | const new_decl_index = try sema.createAnonymousDeclTypeNamed( |
| 21681 | block, | 21579 | block, |
| 21682 | mod.declPtr(block.src_decl).relativeToNodeIndex(src.node_offset.x), | | |
| 21683 | Value.fromInterned(wip_ty.index), | 21580 | Value.fromInterned(wip_ty.index), |
| 21684 | name_strategy, | 21581 | name_strategy, |
| 21685 | "opaque", | 21582 | "opaque", |
| ... | @@ -21879,7 +21776,6 @@ fn reifyEnum( | ... | @@ -21879,7 +21776,6 @@ fn reifyEnum( |
| 21879 | | 21776 | |
| 21880 | const new_decl_index = try sema.createAnonymousDeclTypeNamed( | 21777 | const new_decl_index = try sema.createAnonymousDeclTypeNamed( |
| 21881 | block, | 21778 | block, |
| 21882 | mod.declPtr(block.src_decl).relativeToNodeIndex(src.node_offset.x), | | |
| 21883 | Value.fromInterned(wip_ty.index), | 21779 | Value.fromInterned(wip_ty.index), |
| 21884 | name_strategy, | 21780 | name_strategy, |
| 21885 | "enum", | 21781 | "enum", |
| ... | @@ -21913,17 +21809,17 @@ fn reifyEnum( | ... | @@ -21913,17 +21809,17 @@ fn reifyEnum( |
| 21913 | if (wip_ty.nextField(ip, field_name, coerced_field_val.toIntern())) |conflict| { | 21809 | if (wip_ty.nextField(ip, field_name, coerced_field_val.toIntern())) |conflict| { |
| 21914 | return sema.failWithOwnedErrorMsg(block, switch (conflict.kind) { | 21810 | return sema.failWithOwnedErrorMsg(block, switch (conflict.kind) { |
| 21915 | .name => msg: { | 21811 | .name => msg: { |
| 21916 | const msg = try sema.errMsg(block, src, "duplicate enum field '{}'", .{field_name.fmt(ip)}); | 21812 | const msg = try sema.errMsg(src, "duplicate enum field '{}'", .{field_name.fmt(ip)}); |
| 21917 | errdefer msg.destroy(gpa); | 21813 | errdefer msg.destroy(gpa); |
| 21918 | _ = conflict.prev_field_idx; // TODO: this note is incorrect | 21814 | _ = conflict.prev_field_idx; // TODO: this note is incorrect |
| 21919 | try sema.errNote(block, src, msg, "other field here", .{}); | 21815 | try sema.errNote(src, msg, "other field here", .{}); |
| 21920 | break :msg msg; | 21816 | break :msg msg; |
| 21921 | }, | 21817 | }, |
| 21922 | .value => msg: { | 21818 | .value => msg: { |
| 21923 | const msg = try sema.errMsg(block, src, "enum tag value {} already taken", .{field_value_val.fmtValue(mod, sema)}); | 21819 | const msg = try sema.errMsg(src, "enum tag value {} already taken", .{field_value_val.fmtValue(mod, sema)}); |
| 21924 | errdefer msg.destroy(gpa); | 21820 | errdefer msg.destroy(gpa); |
| 21925 | _ = conflict.prev_field_idx; // TODO: this note is incorrect | 21821 | _ = conflict.prev_field_idx; // TODO: this note is incorrect |
| 21926 | try sema.errNote(block, src, msg, "other enum tag value here", .{}); | 21822 | try sema.errNote(src, msg, "other enum tag value here", .{}); |
| 21927 | break :msg msg; | 21823 | break :msg msg; |
| 21928 | }, | 21824 | }, |
| 21929 | }); | 21825 | }); |
| ... | @@ -22026,7 +21922,6 @@ fn reifyUnion( | ... | @@ -22026,7 +21922,6 @@ fn reifyUnion( |
| 22026 | | 21922 | |
| 22027 | const new_decl_index = try sema.createAnonymousDeclTypeNamed( | 21923 | const new_decl_index = try sema.createAnonymousDeclTypeNamed( |
| 22028 | block, | 21924 | block, |
| 22029 | mod.declPtr(block.src_decl).relativeToNodeIndex(src.node_offset.x), | | |
| 22030 | Value.fromInterned(wip_ty.index), | 21925 | Value.fromInterned(wip_ty.index), |
| 22031 | name_strategy, | 21926 | name_strategy, |
| 22032 | "union", | 21927 | "union", |
| ... | @@ -22082,7 +21977,7 @@ fn reifyUnion( | ... | @@ -22082,7 +21977,7 @@ fn reifyUnion( |
| 22082 | } | 21977 | } |
| 22083 | | 21978 | |
| 22084 | if (tag_ty_fields_len > fields_len) return sema.failWithOwnedErrorMsg(block, msg: { | 21979 | if (tag_ty_fields_len > fields_len) return sema.failWithOwnedErrorMsg(block, msg: { |
| 22085 | const msg = try sema.errMsg(block, src, "enum fields missing in union", .{}); | 21980 | const msg = try sema.errMsg(src, "enum fields missing in union", .{}); |
| 22086 | errdefer msg.destroy(gpa); | 21981 | errdefer msg.destroy(gpa); |
| 22087 | var it = seen_tags.iterator(.{ .kind = .unset }); | 21982 | var it = seen_tags.iterator(.{ .kind = .unset }); |
| 22088 | while (it.next()) |enum_index| { | 21983 | while (it.next()) |enum_index| { |
| ... | @@ -22135,7 +22030,7 @@ fn reifyUnion( | ... | @@ -22135,7 +22030,7 @@ fn reifyUnion( |
| 22135 | const field_ty = Type.fromInterned(field_ty_ip); | 22030 | const field_ty = Type.fromInterned(field_ty_ip); |
| 22136 | if (field_ty.zigTypeTag(mod) == .Opaque) { | 22031 | if (field_ty.zigTypeTag(mod) == .Opaque) { |
| 22137 | return sema.failWithOwnedErrorMsg(block, msg: { | 22032 | return sema.failWithOwnedErrorMsg(block, msg: { |
| 22138 | const msg = try sema.errMsg(block, src, "opaque types have unknown size and therefore cannot be directly embedded in unions", .{}); | 22033 | const msg = try sema.errMsg(src, "opaque types have unknown size and therefore cannot be directly embedded in unions", .{}); |
| 22139 | errdefer msg.destroy(gpa); | 22034 | errdefer msg.destroy(gpa); |
| 22140 | | 22035 | |
| 22141 | try sema.addDeclaredHereNote(msg, field_ty); | 22036 | try sema.addDeclaredHereNote(msg, field_ty); |
| ... | @@ -22144,22 +22039,20 @@ fn reifyUnion( | ... | @@ -22144,22 +22039,20 @@ fn reifyUnion( |
| 22144 | } | 22039 | } |
| 22145 | if (layout == .@"extern" and !try sema.validateExternType(field_ty, .union_field)) { | 22040 | if (layout == .@"extern" and !try sema.validateExternType(field_ty, .union_field)) { |
| 22146 | return sema.failWithOwnedErrorMsg(block, msg: { | 22041 | return sema.failWithOwnedErrorMsg(block, msg: { |
| 22147 | const msg = try sema.errMsg(block, src, "extern unions cannot contain fields of type '{}'", .{field_ty.fmt(mod)}); | 22042 | const msg = try sema.errMsg(src, "extern unions cannot contain fields of type '{}'", .{field_ty.fmt(mod)}); |
| 22148 | errdefer msg.destroy(gpa); | 22043 | errdefer msg.destroy(gpa); |
| 22149 | | 22044 | |
| 22150 | const src_decl = mod.declPtr(block.src_decl); | 22045 | try sema.explainWhyTypeIsNotExtern(msg, src, field_ty, .union_field); |
| 22151 | try sema.explainWhyTypeIsNotExtern(msg, src_decl.toSrcLoc(src, mod), field_ty, .union_field); | | |
| 22152 | | 22046 | |
| 22153 | try sema.addDeclaredHereNote(msg, field_ty); | 22047 | try sema.addDeclaredHereNote(msg, field_ty); |
| 22154 | break :msg msg; | 22048 | break :msg msg; |
| 22155 | }); | 22049 | }); |
| 22156 | } else if (layout == .@"packed" and !try sema.validatePackedType(field_ty)) { | 22050 | } else if (layout == .@"packed" and !try sema.validatePackedType(field_ty)) { |
| 22157 | return sema.failWithOwnedErrorMsg(block, msg: { | 22051 | return sema.failWithOwnedErrorMsg(block, msg: { |
| 22158 | const msg = try sema.errMsg(block, src, "packed unions cannot contain fields of type '{}'", .{field_ty.fmt(mod)}); | 22052 | const msg = try sema.errMsg(src, "packed unions cannot contain fields of type '{}'", .{field_ty.fmt(mod)}); |
| 22159 | errdefer msg.destroy(gpa); | 22053 | errdefer msg.destroy(gpa); |
| 22160 | | 22054 | |
| 22161 | const src_decl = mod.declPtr(block.src_decl); | 22055 | try sema.explainWhyTypeIsNotPacked(msg, src, field_ty); |
| 22162 | try sema.explainWhyTypeIsNotPacked(msg, src_decl.toSrcLoc(src, mod), field_ty); | | |
| 22163 | | 22056 | |
| 22164 | try sema.addDeclaredHereNote(msg, field_ty); | 22057 | try sema.addDeclaredHereNote(msg, field_ty); |
| 22165 | break :msg msg; | 22058 | break :msg msg; |
| ... | @@ -22285,7 +22178,6 @@ fn reifyStruct( | ... | @@ -22285,7 +22178,6 @@ fn reifyStruct( |
| 22285 | | 22178 | |
| 22286 | const new_decl_index = try sema.createAnonymousDeclTypeNamed( | 22179 | const new_decl_index = try sema.createAnonymousDeclTypeNamed( |
| 22287 | block, | 22180 | block, |
| 22288 | mod.declPtr(block.src_decl).relativeToNodeIndex(src.node_offset.x), | | |
| 22289 | Value.fromInterned(wip_ty.index), | 22181 | Value.fromInterned(wip_ty.index), |
| 22290 | name_strategy, | 22182 | name_strategy, |
| 22291 | "struct", | 22183 | "struct", |
| ... | @@ -22376,7 +22268,7 @@ fn reifyStruct( | ... | @@ -22376,7 +22268,7 @@ fn reifyStruct( |
| 22376 | | 22268 | |
| 22377 | if (field_ty.zigTypeTag(mod) == .Opaque) { | 22269 | if (field_ty.zigTypeTag(mod) == .Opaque) { |
| 22378 | return sema.failWithOwnedErrorMsg(block, msg: { | 22270 | return sema.failWithOwnedErrorMsg(block, msg: { |
| 22379 | const msg = try sema.errMsg(block, src, "opaque types have unknown size and therefore cannot be directly embedded in structs", .{}); | 22271 | const msg = try sema.errMsg(src, "opaque types have unknown size and therefore cannot be directly embedded in structs", .{}); |
| 22380 | errdefer msg.destroy(gpa); | 22272 | errdefer msg.destroy(gpa); |
| 22381 | | 22273 | |
| 22382 | try sema.addDeclaredHereNote(msg, field_ty); | 22274 | try sema.addDeclaredHereNote(msg, field_ty); |
| ... | @@ -22385,7 +22277,7 @@ fn reifyStruct( | ... | @@ -22385,7 +22277,7 @@ fn reifyStruct( |
| 22385 | } | 22277 | } |
| 22386 | if (field_ty.zigTypeTag(mod) == .NoReturn) { | 22278 | if (field_ty.zigTypeTag(mod) == .NoReturn) { |
| 22387 | return sema.failWithOwnedErrorMsg(block, msg: { | 22279 | return sema.failWithOwnedErrorMsg(block, msg: { |
| 22388 | const msg = try sema.errMsg(block, src, "struct fields cannot be 'noreturn'", .{}); | 22280 | const msg = try sema.errMsg(src, "struct fields cannot be 'noreturn'", .{}); |
| 22389 | errdefer msg.destroy(gpa); | 22281 | errdefer msg.destroy(gpa); |
| 22390 | | 22282 | |
| 22391 | try sema.addDeclaredHereNote(msg, field_ty); | 22283 | try sema.addDeclaredHereNote(msg, field_ty); |
| ... | @@ -22394,22 +22286,20 @@ fn reifyStruct( | ... | @@ -22394,22 +22286,20 @@ fn reifyStruct( |
| 22394 | } | 22286 | } |
| 22395 | if (layout == .@"extern" and !try sema.validateExternType(field_ty, .struct_field)) { | 22287 | if (layout == .@"extern" and !try sema.validateExternType(field_ty, .struct_field)) { |
| 22396 | return sema.failWithOwnedErrorMsg(block, msg: { | 22288 | return sema.failWithOwnedErrorMsg(block, msg: { |
| 22397 | const msg = try sema.errMsg(block, src, "extern structs cannot contain fields of type '{}'", .{field_ty.fmt(sema.mod)}); | 22289 | const msg = try sema.errMsg(src, "extern structs cannot contain fields of type '{}'", .{field_ty.fmt(sema.mod)}); |
| 22398 | errdefer msg.destroy(gpa); | 22290 | errdefer msg.destroy(gpa); |
| 22399 | | 22291 | |
| 22400 | const src_decl = sema.mod.declPtr(block.src_decl); | 22292 | try sema.explainWhyTypeIsNotExtern(msg, src, field_ty, .struct_field); |
| 22401 | try sema.explainWhyTypeIsNotExtern(msg, src_decl.toSrcLoc(src, mod), field_ty, .struct_field); | | |
| 22402 | | 22293 | |
| 22403 | try sema.addDeclaredHereNote(msg, field_ty); | 22294 | try sema.addDeclaredHereNote(msg, field_ty); |
| 22404 | break :msg msg; | 22295 | break :msg msg; |
| 22405 | }); | 22296 | }); |
| 22406 | } else if (layout == .@"packed" and !try sema.validatePackedType(field_ty)) { | 22297 | } else if (layout == .@"packed" and !try sema.validatePackedType(field_ty)) { |
| 22407 | return sema.failWithOwnedErrorMsg(block, msg: { | 22298 | return sema.failWithOwnedErrorMsg(block, msg: { |
| 22408 | const msg = try sema.errMsg(block, src, "packed structs cannot contain fields of type '{}'", .{field_ty.fmt(sema.mod)}); | 22299 | const msg = try sema.errMsg(src, "packed structs cannot contain fields of type '{}'", .{field_ty.fmt(sema.mod)}); |
| 22409 | errdefer msg.destroy(gpa); | 22300 | errdefer msg.destroy(gpa); |
| 22410 | | 22301 | |
| 22411 | const src_decl = sema.mod.declPtr(block.src_decl); | 22302 | try sema.explainWhyTypeIsNotPacked(msg, src, field_ty); |
| 22412 | try sema.explainWhyTypeIsNotPacked(msg, src_decl.toSrcLoc(src, mod), field_ty); | | |
| 22413 | | 22303 | |
| 22414 | try sema.addDeclaredHereNote(msg, field_ty); | 22304 | try sema.addDeclaredHereNote(msg, field_ty); |
| 22415 | break :msg msg; | 22305 | break :msg msg; |
| ... | @@ -22424,7 +22314,7 @@ fn reifyStruct( | ... | @@ -22424,7 +22314,7 @@ fn reifyStruct( |
| 22424 | sema.resolveTypeLayout(field_ty) catch |err| switch (err) { | 22314 | sema.resolveTypeLayout(field_ty) catch |err| switch (err) { |
| 22425 | error.AnalysisFail => { | 22315 | error.AnalysisFail => { |
| 22426 | const msg = sema.err orelse return err; | 22316 | const msg = sema.err orelse return err; |
| 22427 | try sema.errNote(block, src, msg, "while checking a field of this struct", .{}); | 22317 | try sema.errNote(src, msg, "while checking a field of this struct", .{}); |
| 22428 | return err; | 22318 | return err; |
| 22429 | }, | 22319 | }, |
| 22430 | else => return err, | 22320 | else => return err, |
| ... | @@ -22455,22 +22345,20 @@ fn resolveVaListRef(sema: *Sema, block: *Block, src: LazySrcLoc, zir_ref: Zir.In | ... | @@ -22455,22 +22345,20 @@ fn resolveVaListRef(sema: *Sema, block: *Block, src: LazySrcLoc, zir_ref: Zir.In |
| 22455 | } | 22345 | } |
| 22456 | | 22346 | |
| 22457 | fn zirCVaArg(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!Air.Inst.Ref { | 22347 | fn zirCVaArg(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!Air.Inst.Ref { |
| 22458 | const mod = sema.mod; | | |
| 22459 | const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data; | 22348 | const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data; |
| 22460 | const src = LazySrcLoc.nodeOffset(extra.node); | 22349 | const src = block.nodeOffset(extra.node); |
| 22461 | const va_list_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node }; | 22350 | const va_list_src = block.builtinCallArgSrc(extra.node, 0); |
| 22462 | const ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = extra.node }; | 22351 | const ty_src = block.builtinCallArgSrc(extra.node, 1); |
| 22463 | | 22352 | |
| 22464 | const va_list_ref = try sema.resolveVaListRef(block, va_list_src, extra.lhs); | 22353 | const va_list_ref = try sema.resolveVaListRef(block, va_list_src, extra.lhs); |
| 22465 | const arg_ty = try sema.resolveType(block, ty_src, extra.rhs); | 22354 | const arg_ty = try sema.resolveType(block, ty_src, extra.rhs); |
| 22466 | | 22355 | |
| 22467 | if (!try sema.validateExternType(arg_ty, .param_ty)) { | 22356 | if (!try sema.validateExternType(arg_ty, .param_ty)) { |
| 22468 | const msg = msg: { | 22357 | const msg = msg: { |
| 22469 | const msg = try sema.errMsg(block, ty_src, "cannot get '{}' from variadic argument", .{arg_ty.fmt(sema.mod)}); | 22358 | const msg = try sema.errMsg(ty_src, "cannot get '{}' from variadic argument", .{arg_ty.fmt(sema.mod)}); |
| 22470 | errdefer msg.destroy(sema.gpa); | 22359 | errdefer msg.destroy(sema.gpa); |
| 22471 | | 22360 | |
| 22472 | const src_decl = sema.mod.declPtr(block.src_decl); | 22361 | try sema.explainWhyTypeIsNotExtern(msg, ty_src, arg_ty, .param_ty); |
| 22473 | try sema.explainWhyTypeIsNotExtern(msg, src_decl.toSrcLoc(ty_src, mod), arg_ty, .param_ty); | | |
| 22474 | | 22362 | |
| 22475 | try sema.addDeclaredHereNote(msg, arg_ty); | 22363 | try sema.addDeclaredHereNote(msg, arg_ty); |
| 22476 | break :msg msg; | 22364 | break :msg msg; |
| ... | @@ -22484,8 +22372,8 @@ fn zirCVaArg(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) C | ... | @@ -22484,8 +22372,8 @@ fn zirCVaArg(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) C |
| 22484 | | 22372 | |
| 22485 | fn zirCVaCopy(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!Air.Inst.Ref { | 22373 | fn zirCVaCopy(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!Air.Inst.Ref { |
| 22486 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; | 22374 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; |
| 22487 | const src = LazySrcLoc.nodeOffset(extra.node); | 22375 | const src = block.nodeOffset(extra.node); |
| 22488 | const va_list_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node }; | 22376 | const va_list_src = block.builtinCallArgSrc(extra.node, 0); |
| 22489 | | 22377 | |
| 22490 | const va_list_ref = try sema.resolveVaListRef(block, va_list_src, extra.operand); | 22378 | const va_list_ref = try sema.resolveVaListRef(block, va_list_src, extra.operand); |
| 22491 | const va_list_ty = try sema.getBuiltinType("VaList"); | 22379 | const va_list_ty = try sema.getBuiltinType("VaList"); |
| ... | @@ -22496,8 +22384,8 @@ fn zirCVaCopy(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) | ... | @@ -22496,8 +22384,8 @@ fn zirCVaCopy(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) |
| 22496 | | 22384 | |
| 22497 | fn zirCVaEnd(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!Air.Inst.Ref { | 22385 | fn zirCVaEnd(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!Air.Inst.Ref { |
| 22498 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; | 22386 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; |
| 22499 | const src = LazySrcLoc.nodeOffset(extra.node); | 22387 | const src = block.nodeOffset(extra.node); |
| 22500 | const va_list_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node }; | 22388 | const va_list_src = block.builtinCallArgSrc(extra.node, 0); |
| 22501 | | 22389 | |
| 22502 | const va_list_ref = try sema.resolveVaListRef(block, va_list_src, extra.operand); | 22390 | const va_list_ref = try sema.resolveVaListRef(block, va_list_src, extra.operand); |
| 22503 | | 22391 | |
| ... | @@ -22506,7 +22394,7 @@ fn zirCVaEnd(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) C | ... | @@ -22506,7 +22394,7 @@ fn zirCVaEnd(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) C |
| 22506 | } | 22394 | } |
| 22507 | | 22395 | |
| 22508 | fn zirCVaStart(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!Air.Inst.Ref { | 22396 | fn zirCVaStart(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!Air.Inst.Ref { |
| 22509 | const src = LazySrcLoc.nodeOffset(@bitCast(extended.operand)); | 22397 | const src = block.nodeOffset(@bitCast(extended.operand)); |
| 22510 | | 22398 | |
| 22511 | const va_list_ty = try sema.getBuiltinType("VaList"); | 22399 | const va_list_ty = try sema.getBuiltinType("VaList"); |
| 22512 | try sema.requireRuntimeBlock(block, src, null); | 22400 | try sema.requireRuntimeBlock(block, src, null); |
| ... | @@ -22521,7 +22409,7 @@ fn zirTypeName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -22521,7 +22409,7 @@ fn zirTypeName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 22521 | const ip = &mod.intern_pool; | 22409 | const ip = &mod.intern_pool; |
| 22522 | | 22410 | |
| 22523 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; | 22411 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 22524 | const ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 22412 | const ty_src = block.builtinCallArgSrc(inst_data.src_node, 0); |
| 22525 | const ty = try sema.resolveType(block, ty_src, inst_data.operand); | 22413 | const ty = try sema.resolveType(block, ty_src, inst_data.operand); |
| 22526 | | 22414 | |
| 22527 | const type_name = try ip.getOrPutStringFmt(sema.gpa, "{}", .{ty.fmt(mod)}, .no_embedded_nulls); | 22415 | const type_name = try ip.getOrPutStringFmt(sema.gpa, "{}", .{ty.fmt(mod)}, .no_embedded_nulls); |
| ... | @@ -22545,7 +22433,7 @@ fn zirIntFromFloat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro | ... | @@ -22545,7 +22433,7 @@ fn zirIntFromFloat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro |
| 22545 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 22433 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 22546 | const src = block.nodeOffset(inst_data.src_node); | 22434 | const src = block.nodeOffset(inst_data.src_node); |
| 22547 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; | 22435 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 22548 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 22436 | const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0); |
| 22549 | const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu_opt, "@intFromFloat"); | 22437 | const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu_opt, "@intFromFloat"); |
| 22550 | const operand = try sema.resolveInst(extra.rhs); | 22438 | const operand = try sema.resolveInst(extra.rhs); |
| 22551 | const operand_ty = sema.typeOf(operand); | 22439 | const operand_ty = sema.typeOf(operand); |
| ... | @@ -22627,7 +22515,7 @@ fn zirFloatFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro | ... | @@ -22627,7 +22515,7 @@ fn zirFloatFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro |
| 22627 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 22515 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 22628 | const src = block.nodeOffset(inst_data.src_node); | 22516 | const src = block.nodeOffset(inst_data.src_node); |
| 22629 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; | 22517 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 22630 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 22518 | const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0); |
| 22631 | const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu_opt, "@floatFromInt"); | 22519 | const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu_opt, "@floatFromInt"); |
| 22632 | const operand = try sema.resolveInst(extra.rhs); | 22520 | const operand = try sema.resolveInst(extra.rhs); |
| 22633 | const operand_ty = sema.typeOf(operand); | 22521 | const operand_ty = sema.typeOf(operand); |
| ... | @@ -22671,7 +22559,7 @@ fn zirPtrFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! | ... | @@ -22671,7 +22559,7 @@ fn zirPtrFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! |
| 22671 | | 22559 | |
| 22672 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; | 22560 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 22673 | | 22561 | |
| 22674 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 22562 | const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0); |
| 22675 | const operand_res = try sema.resolveInst(extra.rhs); | 22563 | const operand_res = try sema.resolveInst(extra.rhs); |
| 22676 | | 22564 | |
| 22677 | const uncoerced_operand_ty = sema.typeOf(operand_res); | 22565 | const uncoerced_operand_ty = sema.typeOf(operand_res); |
| ... | @@ -22694,9 +22582,9 @@ fn zirPtrFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! | ... | @@ -22694,9 +22582,9 @@ fn zirPtrFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! |
| 22694 | | 22582 | |
| 22695 | if (ptr_ty.isSlice(mod)) { | 22583 | if (ptr_ty.isSlice(mod)) { |
| 22696 | const msg = msg: { | 22584 | const msg = msg: { |
| 22697 | const msg = try sema.errMsg(block, src, "integer cannot be converted to slice type '{}'", .{ptr_ty.fmt(sema.mod)}); | 22585 | const msg = try sema.errMsg(src, "integer cannot be converted to slice type '{}'", .{ptr_ty.fmt(sema.mod)}); |
| 22698 | errdefer msg.destroy(sema.gpa); | 22586 | errdefer msg.destroy(sema.gpa); |
| 22699 | try sema.errNote(block, src, msg, "slice length cannot be inferred from address", .{}); | 22587 | try sema.errNote(src, msg, "slice length cannot be inferred from address", .{}); |
| 22700 | break :msg msg; | 22588 | break :msg msg; |
| 22701 | }; | 22589 | }; |
| 22702 | return sema.failWithOwnedErrorMsg(block, msg); | 22590 | return sema.failWithOwnedErrorMsg(block, msg); |
| ... | @@ -22721,11 +22609,10 @@ fn zirPtrFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! | ... | @@ -22721,11 +22609,10 @@ fn zirPtrFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! |
| 22721 | } | 22609 | } |
| 22722 | if (try sema.typeRequiresComptime(ptr_ty)) { | 22610 | if (try sema.typeRequiresComptime(ptr_ty)) { |
| 22723 | return sema.failWithOwnedErrorMsg(block, msg: { | 22611 | return sema.failWithOwnedErrorMsg(block, msg: { |
| 22724 | const msg = try sema.errMsg(block, src, "pointer to comptime-only type '{}' must be comptime-known, but operand is runtime-known", .{ptr_ty.fmt(mod)}); | 22612 | const msg = try sema.errMsg(src, "pointer to comptime-only type '{}' must be comptime-known, but operand is runtime-known", .{ptr_ty.fmt(mod)}); |
| 22725 | errdefer msg.destroy(sema.gpa); | 22613 | errdefer msg.destroy(sema.gpa); |
| 22726 | | 22614 | |
| 22727 | const src_decl = mod.declPtr(block.src_decl); | 22615 | try sema.explainWhyTypeIsComptime(msg, src, ptr_ty); |
| 22728 | try sema.explainWhyTypeIsComptime(msg, src_decl.toSrcLoc(src, mod), ptr_ty); | | |
| 22729 | break :msg msg; | 22616 | break :msg msg; |
| 22730 | }); | 22617 | }); |
| 22731 | } | 22618 | } |
| ... | @@ -22810,8 +22697,8 @@ fn zirErrorCast(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData | ... | @@ -22810,8 +22697,8 @@ fn zirErrorCast(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData |
| 22810 | const mod = sema.mod; | 22697 | const mod = sema.mod; |
| 22811 | const ip = &mod.intern_pool; | 22698 | const ip = &mod.intern_pool; |
| 22812 | const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data; | 22699 | const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data; |
| 22813 | const src = LazySrcLoc.nodeOffset(extra.node); | 22700 | const src = block.nodeOffset(extra.node); |
| 22814 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node }; | 22701 | const operand_src = block.builtinCallArgSrc(extra.node, 0); |
| 22815 | const base_dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_opt, "@errorCast"); | 22702 | const base_dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_opt, "@errorCast"); |
| 22816 | const operand = try sema.resolveInst(extra.rhs); | 22703 | const operand = try sema.resolveInst(extra.rhs); |
| 22817 | const base_operand_ty = sema.typeOf(operand); | 22704 | const base_operand_ty = sema.typeOf(operand); |
| ... | @@ -22831,12 +22718,12 @@ fn zirErrorCast(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData | ... | @@ -22831,12 +22718,12 @@ fn zirErrorCast(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData |
| 22831 | base_dest_ty.errorUnionPayload(mod).toIntern() != base_operand_ty.errorUnionPayload(mod).toIntern()) | 22718 | base_dest_ty.errorUnionPayload(mod).toIntern() != base_operand_ty.errorUnionPayload(mod).toIntern()) |
| 22832 | { | 22719 | { |
| 22833 | return sema.failWithOwnedErrorMsg(block, msg: { | 22720 | return sema.failWithOwnedErrorMsg(block, msg: { |
| 22834 | const msg = try sema.errMsg(block, src, "payload types of error unions must match", .{}); | 22721 | const msg = try sema.errMsg(src, "payload types of error unions must match", .{}); |
| 22835 | errdefer msg.destroy(sema.gpa); | 22722 | errdefer msg.destroy(sema.gpa); |
| 22836 | const dest_ty = base_dest_ty.errorUnionPayload(mod); | 22723 | const dest_ty = base_dest_ty.errorUnionPayload(mod); |
| 22837 | const operand_ty = base_operand_ty.errorUnionPayload(mod); | 22724 | const operand_ty = base_operand_ty.errorUnionPayload(mod); |
| 22838 | try sema.errNote(block, src, msg, "destination payload is '{}'", .{dest_ty.fmt(mod)}); | 22725 | try sema.errNote(src, msg, "destination payload is '{}'", .{dest_ty.fmt(mod)}); |
| 22839 | try sema.errNote(block, src, msg, "operand payload is '{}'", .{operand_ty.fmt(mod)}); | 22726 | try sema.errNote(src, msg, "operand payload is '{}'", .{operand_ty.fmt(mod)}); |
| 22840 | try addDeclaredHereNote(sema, msg, dest_ty); | 22727 | try addDeclaredHereNote(sema, msg, dest_ty); |
| 22841 | try addDeclaredHereNote(sema, msg, operand_ty); | 22728 | try addDeclaredHereNote(sema, msg, operand_ty); |
| 22842 | break :msg msg; | 22729 | break :msg msg; |
| ... | @@ -22935,8 +22822,8 @@ fn zirPtrCastFull(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDa | ... | @@ -22935,8 +22822,8 @@ fn zirPtrCastFull(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDa |
| 22935 | const FlagsInt = @typeInfo(Zir.Inst.FullPtrCastFlags).Struct.backing_integer.?; | 22822 | const FlagsInt = @typeInfo(Zir.Inst.FullPtrCastFlags).Struct.backing_integer.?; |
| 22936 | const flags: Zir.Inst.FullPtrCastFlags = @bitCast(@as(FlagsInt, @truncate(extended.small))); | 22823 | const flags: Zir.Inst.FullPtrCastFlags = @bitCast(@as(FlagsInt, @truncate(extended.small))); |
| 22937 | const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data; | 22824 | const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data; |
| 22938 | const src = LazySrcLoc.nodeOffset(extra.node); | 22825 | const src = block.nodeOffset(extra.node); |
| 22939 | const operand_src: LazySrcLoc = .{ .node_offset_ptrcast_operand = extra.node }; | 22826 | const operand_src = block.src(.{ .node_offset_ptrcast_operand = extra.node }); |
| 22940 | const operand = try sema.resolveInst(extra.rhs); | 22827 | const operand = try sema.resolveInst(extra.rhs); |
| 22941 | const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu, flags.needResultTypeBuiltinName()); | 22828 | const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu, flags.needResultTypeBuiltinName()); |
| 22942 | return sema.ptrCastFull( | 22829 | return sema.ptrCastFull( |
| ... | @@ -22953,7 +22840,7 @@ fn zirPtrCastFull(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDa | ... | @@ -22953,7 +22840,7 @@ fn zirPtrCastFull(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDa |
| 22953 | fn zirPtrCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 22840 | fn zirPtrCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 22954 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 22841 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 22955 | const src = block.nodeOffset(inst_data.src_node); | 22842 | const src = block.nodeOffset(inst_data.src_node); |
| 22956 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 22843 | const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0); |
| 22957 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; | 22844 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 22958 | const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu, "@ptrCast"); | 22845 | const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu, "@ptrCast"); |
| 22959 | const operand = try sema.resolveInst(extra.rhs); | 22846 | const operand = try sema.resolveInst(extra.rhs); |
| ... | @@ -23023,7 +22910,7 @@ fn ptrCastFull( | ... | @@ -23023,7 +22910,7 @@ fn ptrCastFull( |
| 23023 | if (src_info.flags.size == .C) break :check_size; | 22910 | if (src_info.flags.size == .C) break :check_size; |
| 23024 | if (dest_info.flags.size == .C) break :check_size; | 22911 | if (dest_info.flags.size == .C) break :check_size; |
| 23025 | return sema.failWithOwnedErrorMsg(block, msg: { | 22912 | return sema.failWithOwnedErrorMsg(block, msg: { |
| 23026 | const msg = try sema.errMsg(block, src, "cannot implicitly convert {s} pointer to {s} pointer", .{ | 22913 | const msg = try sema.errMsg(src, "cannot implicitly convert {s} pointer to {s} pointer", .{ |
| 23027 | pointerSizeString(src_info.flags.size), | 22914 | pointerSizeString(src_info.flags.size), |
| 23028 | pointerSizeString(dest_info.flags.size), | 22915 | pointerSizeString(dest_info.flags.size), |
| 23029 | }); | 22916 | }); |
| ... | @@ -23032,9 +22919,9 @@ fn ptrCastFull( | ... | @@ -23032,9 +22919,9 @@ fn ptrCastFull( |
| 23032 | (src_info.flags.size == .Slice or | 22919 | (src_info.flags.size == .Slice or |
| 23033 | (src_info.flags.size == .One and Type.fromInterned(src_info.child).zigTypeTag(mod) == .Array))) | 22920 | (src_info.flags.size == .One and Type.fromInterned(src_info.child).zigTypeTag(mod) == .Array))) |
| 23034 | { | 22921 | { |
| 23035 | try sema.errNote(block, src, msg, "use 'ptr' field to convert slice to many pointer", .{}); | 22922 | try sema.errNote(src, msg, "use 'ptr' field to convert slice to many pointer", .{}); |
| 23036 | } else { | 22923 | } else { |
| 23037 | try sema.errNote(block, src, msg, "use @ptrCast to change pointer size", .{}); | 22924 | try sema.errNote(src, msg, "use @ptrCast to change pointer size", .{}); |
| 23038 | } | 22925 | } |
| 23039 | break :msg msg; | 22926 | break :msg msg; |
| 23040 | }); | 22927 | }); |
| ... | @@ -23059,13 +22946,13 @@ fn ptrCastFull( | ... | @@ -23059,13 +22946,13 @@ fn ptrCastFull( |
| 23059 | ); | 22946 | ); |
| 23060 | if (imc_res == .ok) break :check_child; | 22947 | if (imc_res == .ok) break :check_child; |
| 23061 | return sema.failWithOwnedErrorMsg(block, msg: { | 22948 | return sema.failWithOwnedErrorMsg(block, msg: { |
| 23062 | const msg = try sema.errMsg(block, src, "pointer element type '{}' cannot coerce into element type '{}'", .{ | 22949 | const msg = try sema.errMsg(src, "pointer element type '{}' cannot coerce into element type '{}'", .{ |
| 23063 | src_child.fmt(mod), | 22950 | src_child.fmt(mod), |
| 23064 | dest_child.fmt(mod), | 22951 | dest_child.fmt(mod), |
| 23065 | }); | 22952 | }); |
| 23066 | errdefer msg.destroy(sema.gpa); | 22953 | errdefer msg.destroy(sema.gpa); |
| 23067 | try imc_res.report(sema, block, src, msg); | 22954 | try imc_res.report(sema, src, msg); |
| 23068 | try sema.errNote(block, src, msg, "use @ptrCast to cast pointer element type", .{}); | 22955 | try sema.errNote(src, msg, "use @ptrCast to cast pointer element type", .{}); |
| 23069 | break :msg msg; | 22956 | break :msg msg; |
| 23070 | }); | 22957 | }); |
| 23071 | } | 22958 | } |
| ... | @@ -23087,41 +22974,41 @@ fn ptrCastFull( | ... | @@ -23087,41 +22974,41 @@ fn ptrCastFull( |
| 23087 | } | 22974 | } |
| 23088 | return sema.failWithOwnedErrorMsg(block, msg: { | 22975 | return sema.failWithOwnedErrorMsg(block, msg: { |
| 23089 | const msg = if (src_info.sentinel == .none) blk: { | 22976 | const msg = if (src_info.sentinel == .none) blk: { |
| 23090 | break :blk try sema.errMsg(block, src, "destination pointer requires '{}' sentinel", .{ | 22977 | break :blk try sema.errMsg(src, "destination pointer requires '{}' sentinel", .{ |
| 23091 | Value.fromInterned(dest_info.sentinel).fmtValue(mod, sema), | 22978 | Value.fromInterned(dest_info.sentinel).fmtValue(mod, sema), |
| 23092 | }); | 22979 | }); |
| 23093 | } else blk: { | 22980 | } else blk: { |
| 23094 | break :blk try sema.errMsg(block, src, "pointer sentinel '{}' cannot coerce into pointer sentinel '{}'", .{ | 22981 | break :blk try sema.errMsg(src, "pointer sentinel '{}' cannot coerce into pointer sentinel '{}'", .{ |
| 23095 | Value.fromInterned(src_info.sentinel).fmtValue(mod, sema), | 22982 | Value.fromInterned(src_info.sentinel).fmtValue(mod, sema), |
| 23096 | Value.fromInterned(dest_info.sentinel).fmtValue(mod, sema), | 22983 | Value.fromInterned(dest_info.sentinel).fmtValue(mod, sema), |
| 23097 | }); | 22984 | }); |
| 23098 | }; | 22985 | }; |
| 23099 | errdefer msg.destroy(sema.gpa); | 22986 | errdefer msg.destroy(sema.gpa); |
| 23100 | try sema.errNote(block, src, msg, "use @ptrCast to cast pointer sentinel", .{}); | 22987 | try sema.errNote(src, msg, "use @ptrCast to cast pointer sentinel", .{}); |
| 23101 | break :msg msg; | 22988 | break :msg msg; |
| 23102 | }); | 22989 | }); |
| 23103 | } | 22990 | } |
| 23104 | | 22991 | |
| 23105 | if (src_info.packed_offset.host_size != dest_info.packed_offset.host_size) { | 22992 | if (src_info.packed_offset.host_size != dest_info.packed_offset.host_size) { |
| 23106 | return sema.failWithOwnedErrorMsg(block, msg: { | 22993 | return sema.failWithOwnedErrorMsg(block, msg: { |
| 23107 | const msg = try sema.errMsg(block, src, "pointer host size '{}' cannot coerce into pointer host size '{}'", .{ | 22994 | const msg = try sema.errMsg(src, "pointer host size '{}' cannot coerce into pointer host size '{}'", .{ |
| 23108 | src_info.packed_offset.host_size, | 22995 | src_info.packed_offset.host_size, |
| 23109 | dest_info.packed_offset.host_size, | 22996 | dest_info.packed_offset.host_size, |
| 23110 | }); | 22997 | }); |
| 23111 | errdefer msg.destroy(sema.gpa); | 22998 | errdefer msg.destroy(sema.gpa); |
| 23112 | try sema.errNote(block, src, msg, "use @ptrCast to cast pointer host size", .{}); | 22999 | try sema.errNote(src, msg, "use @ptrCast to cast pointer host size", .{}); |
| 23113 | break :msg msg; | 23000 | break :msg msg; |
| 23114 | }); | 23001 | }); |
| 23115 | } | 23002 | } |
| 23116 | | 23003 | |
| 23117 | if (src_info.packed_offset.bit_offset != dest_info.packed_offset.bit_offset) { | 23004 | if (src_info.packed_offset.bit_offset != dest_info.packed_offset.bit_offset) { |
| 23118 | return sema.failWithOwnedErrorMsg(block, msg: { | 23005 | return sema.failWithOwnedErrorMsg(block, msg: { |
| 23119 | const msg = try sema.errMsg(block, src, "pointer bit offset '{}' cannot coerce into pointer bit offset '{}'", .{ | 23006 | const msg = try sema.errMsg(src, "pointer bit offset '{}' cannot coerce into pointer bit offset '{}'", .{ |
| 23120 | src_info.packed_offset.bit_offset, | 23007 | src_info.packed_offset.bit_offset, |
| 23121 | dest_info.packed_offset.bit_offset, | 23008 | dest_info.packed_offset.bit_offset, |
| 23122 | }); | 23009 | }); |
| 23123 | errdefer msg.destroy(sema.gpa); | 23010 | errdefer msg.destroy(sema.gpa); |
| 23124 | try sema.errNote(block, src, msg, "use @ptrCast to cast pointer bit offset", .{}); | 23011 | try sema.errNote(src, msg, "use @ptrCast to cast pointer bit offset", .{}); |
| 23125 | break :msg msg; | 23012 | break :msg msg; |
| 23126 | }); | 23013 | }); |
| 23127 | } | 23014 | } |
| ... | @@ -23133,12 +23020,12 @@ fn ptrCastFull( | ... | @@ -23133,12 +23020,12 @@ fn ptrCastFull( |
| 23133 | if (dest_allows_zero) break :check_allowzero; | 23020 | if (dest_allows_zero) break :check_allowzero; |
| 23134 | | 23021 | |
| 23135 | return sema.failWithOwnedErrorMsg(block, msg: { | 23022 | return sema.failWithOwnedErrorMsg(block, msg: { |
| 23136 | const msg = try sema.errMsg(block, src, "'{}' could have null values which are illegal in type '{}'", .{ | 23023 | const msg = try sema.errMsg(src, "'{}' could have null values which are illegal in type '{}'", .{ |
| 23137 | operand_ty.fmt(mod), | 23024 | operand_ty.fmt(mod), |
| 23138 | dest_ty.fmt(mod), | 23025 | dest_ty.fmt(mod), |
| 23139 | }); | 23026 | }); |
| 23140 | errdefer msg.destroy(sema.gpa); | 23027 | errdefer msg.destroy(sema.gpa); |
| 23141 | try sema.errNote(block, src, msg, "use @ptrCast to assert the pointer is not null", .{}); | 23028 | try sema.errNote(src, msg, "use @ptrCast to assert the pointer is not null", .{}); |
| 23142 | break :msg msg; | 23029 | break :msg msg; |
| 23143 | }); | 23030 | }); |
| 23144 | } | 23031 | } |
| ... | @@ -23159,15 +23046,15 @@ fn ptrCastFull( | ... | @@ -23159,15 +23046,15 @@ fn ptrCastFull( |
| 23159 | if (!flags.align_cast) { | 23046 | if (!flags.align_cast) { |
| 23160 | if (dest_align.compare(.gt, src_align)) { | 23047 | if (dest_align.compare(.gt, src_align)) { |
| 23161 | return sema.failWithOwnedErrorMsg(block, msg: { | 23048 | return sema.failWithOwnedErrorMsg(block, msg: { |
| 23162 | const msg = try sema.errMsg(block, src, "{s} increases pointer alignment", .{operation}); | 23049 | const msg = try sema.errMsg(src, "{s} increases pointer alignment", .{operation}); |
| 23163 | errdefer msg.destroy(sema.gpa); | 23050 | errdefer msg.destroy(sema.gpa); |
| 23164 | try sema.errNote(block, operand_src, msg, "'{}' has alignment '{d}'", .{ | 23051 | try sema.errNote(operand_src, msg, "'{}' has alignment '{d}'", .{ |
| 23165 | operand_ty.fmt(mod), src_align.toByteUnits() orelse 0, | 23052 | operand_ty.fmt(mod), src_align.toByteUnits() orelse 0, |
| 23166 | }); | 23053 | }); |
| 23167 | try sema.errNote(block, src, msg, "'{}' has alignment '{d}'", .{ | 23054 | try sema.errNote(src, msg, "'{}' has alignment '{d}'", .{ |
| 23168 | dest_ty.fmt(mod), dest_align.toByteUnits() orelse 0, | 23055 | dest_ty.fmt(mod), dest_align.toByteUnits() orelse 0, |
| 23169 | }); | 23056 | }); |
| 23170 | try sema.errNote(block, src, msg, "use @alignCast to assert pointer alignment", .{}); | 23057 | try sema.errNote(src, msg, "use @alignCast to assert pointer alignment", .{}); |
| 23171 | break :msg msg; | 23058 | break :msg msg; |
| 23172 | }); | 23059 | }); |
| 23173 | } | 23060 | } |
| ... | @@ -23176,15 +23063,15 @@ fn ptrCastFull( | ... | @@ -23176,15 +23063,15 @@ fn ptrCastFull( |
| 23176 | if (!flags.addrspace_cast) { | 23063 | if (!flags.addrspace_cast) { |
| 23177 | if (src_info.flags.address_space != dest_info.flags.address_space) { | 23064 | if (src_info.flags.address_space != dest_info.flags.address_space) { |
| 23178 | return sema.failWithOwnedErrorMsg(block, msg: { | 23065 | return sema.failWithOwnedErrorMsg(block, msg: { |
| 23179 | const msg = try sema.errMsg(block, src, "{s} changes pointer address space", .{operation}); | 23066 | const msg = try sema.errMsg(src, "{s} changes pointer address space", .{operation}); |
| 23180 | errdefer msg.destroy(sema.gpa); | 23067 | errdefer msg.destroy(sema.gpa); |
| 23181 | try sema.errNote(block, operand_src, msg, "'{}' has address space '{s}'", .{ | 23068 | try sema.errNote(operand_src, msg, "'{}' has address space '{s}'", .{ |
| 23182 | operand_ty.fmt(mod), @tagName(src_info.flags.address_space), | 23069 | operand_ty.fmt(mod), @tagName(src_info.flags.address_space), |
| 23183 | }); | 23070 | }); |
| 23184 | try sema.errNote(block, src, msg, "'{}' has address space '{s}'", .{ | 23071 | try sema.errNote(src, msg, "'{}' has address space '{s}'", .{ |
| 23185 | dest_ty.fmt(mod), @tagName(dest_info.flags.address_space), | 23072 | dest_ty.fmt(mod), @tagName(dest_info.flags.address_space), |
| 23186 | }); | 23073 | }); |
| 23187 | try sema.errNote(block, src, msg, "use @addrSpaceCast to cast pointer address space", .{}); | 23074 | try sema.errNote(src, msg, "use @addrSpaceCast to cast pointer address space", .{}); |
| 23188 | break :msg msg; | 23075 | break :msg msg; |
| 23189 | }); | 23076 | }); |
| 23190 | } | 23077 | } |
| ... | @@ -23192,9 +23079,9 @@ fn ptrCastFull( | ... | @@ -23192,9 +23079,9 @@ fn ptrCastFull( |
| 23192 | // Some address space casts are always disallowed | 23079 | // Some address space casts are always disallowed |
| 23193 | if (!target_util.addrSpaceCastIsValid(mod.getTarget(), src_info.flags.address_space, dest_info.flags.address_space)) { | 23080 | if (!target_util.addrSpaceCastIsValid(mod.getTarget(), src_info.flags.address_space, dest_info.flags.address_space)) { |
| 23194 | return sema.failWithOwnedErrorMsg(block, msg: { | 23081 | return sema.failWithOwnedErrorMsg(block, msg: { |
| 23195 | const msg = try sema.errMsg(block, src, "invalid address space cast", .{}); | 23082 | const msg = try sema.errMsg(src, "invalid address space cast", .{}); |
| 23196 | errdefer msg.destroy(sema.gpa); | 23083 | errdefer msg.destroy(sema.gpa); |
| 23197 | try sema.errNote(block, operand_src, msg, "address space '{s}' is not compatible with address space '{s}'", .{ | 23084 | try sema.errNote(operand_src, msg, "address space '{s}' is not compatible with address space '{s}'", .{ |
| 23198 | @tagName(src_info.flags.address_space), | 23085 | @tagName(src_info.flags.address_space), |
| 23199 | @tagName(dest_info.flags.address_space), | 23086 | @tagName(dest_info.flags.address_space), |
| 23200 | }); | 23087 | }); |
| ... | @@ -23206,9 +23093,9 @@ fn ptrCastFull( | ... | @@ -23206,9 +23093,9 @@ fn ptrCastFull( |
| 23206 | if (!flags.const_cast) { | 23093 | if (!flags.const_cast) { |
| 23207 | if (src_info.flags.is_const and !dest_info.flags.is_const) { | 23094 | if (src_info.flags.is_const and !dest_info.flags.is_const) { |
| 23208 | return sema.failWithOwnedErrorMsg(block, msg: { | 23095 | return sema.failWithOwnedErrorMsg(block, msg: { |
| 23209 | const msg = try sema.errMsg(block, src, "{s} discards const qualifier", .{operation}); | 23096 | const msg = try sema.errMsg(src, "{s} discards const qualifier", .{operation}); |
| 23210 | errdefer msg.destroy(sema.gpa); | 23097 | errdefer msg.destroy(sema.gpa); |
| 23211 | try sema.errNote(block, src, msg, "use @constCast to discard const qualifier", .{}); | 23098 | try sema.errNote(src, msg, "use @constCast to discard const qualifier", .{}); |
| 23212 | break :msg msg; | 23099 | break :msg msg; |
| 23213 | }); | 23100 | }); |
| 23214 | } | 23101 | } |
| ... | @@ -23217,9 +23104,9 @@ fn ptrCastFull( | ... | @@ -23217,9 +23104,9 @@ fn ptrCastFull( |
| 23217 | if (!flags.volatile_cast) { | 23104 | if (!flags.volatile_cast) { |
| 23218 | if (src_info.flags.is_volatile and !dest_info.flags.is_volatile) { | 23105 | if (src_info.flags.is_volatile and !dest_info.flags.is_volatile) { |
| 23219 | return sema.failWithOwnedErrorMsg(block, msg: { | 23106 | return sema.failWithOwnedErrorMsg(block, msg: { |
| 23220 | const msg = try sema.errMsg(block, src, "{s} discards volatile qualifier", .{operation}); | 23107 | const msg = try sema.errMsg(src, "{s} discards volatile qualifier", .{operation}); |
| 23221 | errdefer msg.destroy(sema.gpa); | 23108 | errdefer msg.destroy(sema.gpa); |
| 23222 | try sema.errNote(block, src, msg, "use @volatileCast to discard volatile qualifier", .{}); | 23109 | try sema.errNote(src, msg, "use @volatileCast to discard volatile qualifier", .{}); |
| 23223 | break :msg msg; | 23110 | break :msg msg; |
| 23224 | }); | 23111 | }); |
| 23225 | } | 23112 | } |
| ... | @@ -23368,8 +23255,8 @@ fn zirPtrCastNoDest(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.Inst | ... | @@ -23368,8 +23255,8 @@ fn zirPtrCastNoDest(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.Inst |
| 23368 | const FlagsInt = @typeInfo(Zir.Inst.FullPtrCastFlags).Struct.backing_integer.?; | 23255 | const FlagsInt = @typeInfo(Zir.Inst.FullPtrCastFlags).Struct.backing_integer.?; |
| 23369 | const flags: Zir.Inst.FullPtrCastFlags = @bitCast(@as(FlagsInt, @truncate(extended.small))); | 23256 | const flags: Zir.Inst.FullPtrCastFlags = @bitCast(@as(FlagsInt, @truncate(extended.small))); |
| 23370 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; | 23257 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; |
| 23371 | const src = LazySrcLoc.nodeOffset(extra.node); | 23258 | const src = block.nodeOffset(extra.node); |
| 23372 | const operand_src: LazySrcLoc = .{ .node_offset_ptrcast_operand = extra.node }; | 23259 | const operand_src = block.src(.{ .node_offset_ptrcast_operand = extra.node }); |
| 23373 | const operand = try sema.resolveInst(extra.operand); | 23260 | const operand = try sema.resolveInst(extra.operand); |
| 23374 | const operand_ty = sema.typeOf(operand); | 23261 | const operand_ty = sema.typeOf(operand); |
| 23375 | try sema.checkPtrOperand(block, operand_src, operand_ty); | 23262 | try sema.checkPtrOperand(block, operand_src, operand_ty); |
| ... | @@ -23400,7 +23287,7 @@ fn zirTruncate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -23400,7 +23287,7 @@ fn zirTruncate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 23400 | const mod = sema.mod; | 23287 | const mod = sema.mod; |
| 23401 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 23288 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 23402 | const src = block.nodeOffset(inst_data.src_node); | 23289 | const src = block.nodeOffset(inst_data.src_node); |
| 23403 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 23290 | const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0); |
| 23404 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; | 23291 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 23405 | const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu_opt, "@truncate"); | 23292 | const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu_opt, "@truncate"); |
| 23406 | const dest_scalar_ty = try sema.checkIntOrVectorAllowComptime(block, dest_ty, src); | 23293 | const dest_scalar_ty = try sema.checkIntOrVectorAllowComptime(block, dest_ty, src); |
| ... | @@ -23438,16 +23325,15 @@ fn zirTruncate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -23438,16 +23325,15 @@ fn zirTruncate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 23438 | if (operand_info.bits < dest_info.bits) { | 23325 | if (operand_info.bits < dest_info.bits) { |
| 23439 | const msg = msg: { | 23326 | const msg = msg: { |
| 23440 | const msg = try sema.errMsg( | 23327 | const msg = try sema.errMsg( |
| 23441 | block, | | |
| 23442 | src, | 23328 | src, |
| 23443 | "destination type '{}' has more bits than source type '{}'", | 23329 | "destination type '{}' has more bits than source type '{}'", |
| 23444 | .{ dest_ty.fmt(mod), operand_ty.fmt(mod) }, | 23330 | .{ dest_ty.fmt(mod), operand_ty.fmt(mod) }, |
| 23445 | ); | 23331 | ); |
| 23446 | errdefer msg.destroy(sema.gpa); | 23332 | errdefer msg.destroy(sema.gpa); |
| 23447 | try sema.errNote(block, src, msg, "destination type has {d} bits", .{ | 23333 | try sema.errNote(src, msg, "destination type has {d} bits", .{ |
| 23448 | dest_info.bits, | 23334 | dest_info.bits, |
| 23449 | }); | 23335 | }); |
| 23450 | try sema.errNote(block, operand_src, msg, "operand type has {d} bits", .{ | 23336 | try sema.errNote(operand_src, msg, "operand type has {d} bits", .{ |
| 23451 | operand_info.bits, | 23337 | operand_info.bits, |
| 23452 | }); | 23338 | }); |
| 23453 | break :msg msg; | 23339 | break :msg msg; |
| ... | @@ -23490,7 +23376,7 @@ fn zirBitCount( | ... | @@ -23490,7 +23376,7 @@ fn zirBitCount( |
| 23490 | const mod = sema.mod; | 23376 | const mod = sema.mod; |
| 23491 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; | 23377 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 23492 | const src = block.nodeOffset(inst_data.src_node); | 23378 | const src = block.nodeOffset(inst_data.src_node); |
| 23493 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 23379 | const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0); |
| 23494 | const operand = try sema.resolveInst(inst_data.operand); | 23380 | const operand = try sema.resolveInst(inst_data.operand); |
| 23495 | const operand_ty = sema.typeOf(operand); | 23381 | const operand_ty = sema.typeOf(operand); |
| 23496 | _ = try sema.checkIntOrVector(block, operand, operand_src); | 23382 | _ = try sema.checkIntOrVector(block, operand, operand_src); |
| ... | @@ -23544,7 +23430,7 @@ fn zirByteSwap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -23544,7 +23430,7 @@ fn zirByteSwap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 23544 | const mod = sema.mod; | 23430 | const mod = sema.mod; |
| 23545 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; | 23431 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 23546 | const src = block.nodeOffset(inst_data.src_node); | 23432 | const src = block.nodeOffset(inst_data.src_node); |
| 23547 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 23433 | const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0); |
| 23548 | const operand = try sema.resolveInst(inst_data.operand); | 23434 | const operand = try sema.resolveInst(inst_data.operand); |
| 23549 | const operand_ty = sema.typeOf(operand); | 23435 | const operand_ty = sema.typeOf(operand); |
| 23550 | const scalar_ty = try sema.checkIntOrVector(block, operand, operand_src); | 23436 | const scalar_ty = try sema.checkIntOrVector(block, operand, operand_src); |
| ... | @@ -23600,7 +23486,7 @@ fn zirByteSwap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -23600,7 +23486,7 @@ fn zirByteSwap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 23600 | fn zirBitReverse(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 23486 | fn zirBitReverse(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 23601 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; | 23487 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 23602 | const src = block.nodeOffset(inst_data.src_node); | 23488 | const src = block.nodeOffset(inst_data.src_node); |
| 23603 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 23489 | const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0); |
| 23604 | const operand = try sema.resolveInst(inst_data.operand); | 23490 | const operand = try sema.resolveInst(inst_data.operand); |
| 23605 | const operand_ty = sema.typeOf(operand); | 23491 | const operand_ty = sema.typeOf(operand); |
| 23606 | const scalar_ty = try sema.checkIntOrVector(block, operand, operand_src); | 23492 | const scalar_ty = try sema.checkIntOrVector(block, operand, operand_src); |
| ... | @@ -23658,9 +23544,9 @@ fn zirOffsetOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -23658,9 +23544,9 @@ fn zirOffsetOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 23658 | | 23544 | |
| 23659 | fn bitOffsetOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!u64 { | 23545 | fn bitOffsetOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!u64 { |
| 23660 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 23546 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 23661 | const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node }; | 23547 | const src = block.src(.{ .node_offset_bin_op = inst_data.src_node }); |
| 23662 | const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node }; | 23548 | const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node }); |
| 23663 | const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node }; | 23549 | const rhs_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node }); |
| 23664 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; | 23550 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 23665 | | 23551 | |
| 23666 | const ty = try sema.resolveType(block, lhs_src, extra.lhs); | 23552 | const ty = try sema.resolveType(block, lhs_src, extra.lhs); |
| ... | @@ -23773,14 +23659,13 @@ fn checkPtrOperand( | ... | @@ -23773,14 +23659,13 @@ fn checkPtrOperand( |
| 23773 | .Fn => { | 23659 | .Fn => { |
| 23774 | const msg = msg: { | 23660 | const msg = msg: { |
| 23775 | const msg = try sema.errMsg( | 23661 | const msg = try sema.errMsg( |
| 23776 | block, | | |
| 23777 | ty_src, | 23662 | ty_src, |
| 23778 | "expected pointer, found '{}'", | 23663 | "expected pointer, found '{}'", |
| 23779 | .{ty.fmt(mod)}, | 23664 | .{ty.fmt(mod)}, |
| 23780 | ); | 23665 | ); |
| 23781 | errdefer msg.destroy(sema.gpa); | 23666 | errdefer msg.destroy(sema.gpa); |
| 23782 | | 23667 | |
| 23783 | try sema.errNote(block, ty_src, msg, "use '&' to obtain a function pointer", .{}); | 23668 | try sema.errNote(ty_src, msg, "use '&' to obtain a function pointer", .{}); |
| 23784 | | 23669 | |
| 23785 | break :msg msg; | 23670 | break :msg msg; |
| 23786 | }; | 23671 | }; |
| ... | @@ -23805,14 +23690,13 @@ fn checkPtrType( | ... | @@ -23805,14 +23690,13 @@ fn checkPtrType( |
| 23805 | .Fn => { | 23690 | .Fn => { |
| 23806 | const msg = msg: { | 23691 | const msg = msg: { |
| 23807 | const msg = try sema.errMsg( | 23692 | const msg = try sema.errMsg( |
| 23808 | block, | | |
| 23809 | ty_src, | 23693 | ty_src, |
| 23810 | "expected pointer type, found '{}'", | 23694 | "expected pointer type, found '{}'", |
| 23811 | .{ty.fmt(mod)}, | 23695 | .{ty.fmt(mod)}, |
| 23812 | ); | 23696 | ); |
| 23813 | errdefer msg.destroy(sema.gpa); | 23697 | errdefer msg.destroy(sema.gpa); |
| 23814 | | 23698 | |
| 23815 | try sema.errNote(block, ty_src, msg, "use '*const ' to make a function pointer type", .{}); | 23699 | try sema.errNote(ty_src, msg, "use '*const ' to make a function pointer type", .{}); |
| 23816 | | 23700 | |
| 23817 | break :msg msg; | 23701 | break :msg msg; |
| 23818 | }; | 23702 | }; |
| ... | @@ -24066,26 +23950,26 @@ fn checkVectorizableBinaryOperands( | ... | @@ -24066,26 +23950,26 @@ fn checkVectorizableBinaryOperands( |
| 24066 | const rhs_len = rhs_ty.arrayLen(mod); | 23950 | const rhs_len = rhs_ty.arrayLen(mod); |
| 24067 | if (lhs_len != rhs_len) { | 23951 | if (lhs_len != rhs_len) { |
| 24068 | const msg = msg: { | 23952 | const msg = msg: { |
| 24069 | const msg = try sema.errMsg(block, src, "vector length mismatch", .{}); | 23953 | const msg = try sema.errMsg(src, "vector length mismatch", .{}); |
| 24070 | errdefer msg.destroy(sema.gpa); | 23954 | errdefer msg.destroy(sema.gpa); |
| 24071 | try sema.errNote(block, lhs_src, msg, "length {d} here", .{lhs_len}); | 23955 | try sema.errNote(lhs_src, msg, "length {d} here", .{lhs_len}); |
| 24072 | try sema.errNote(block, rhs_src, msg, "length {d} here", .{rhs_len}); | 23956 | try sema.errNote(rhs_src, msg, "length {d} here", .{rhs_len}); |
| 24073 | break :msg msg; | 23957 | break :msg msg; |
| 24074 | }; | 23958 | }; |
| 24075 | return sema.failWithOwnedErrorMsg(block, msg); | 23959 | return sema.failWithOwnedErrorMsg(block, msg); |
| 24076 | } | 23960 | } |
| 24077 | } else { | 23961 | } else { |
| 24078 | const msg = msg: { | 23962 | const msg = msg: { |
| 24079 | const msg = try sema.errMsg(block, src, "mixed scalar and vector operands: '{}' and '{}'", .{ | 23963 | const msg = try sema.errMsg(src, "mixed scalar and vector operands: '{}' and '{}'", .{ |
| 24080 | lhs_ty.fmt(mod), rhs_ty.fmt(mod), | 23964 | lhs_ty.fmt(mod), rhs_ty.fmt(mod), |
| 24081 | }); | 23965 | }); |
| 24082 | errdefer msg.destroy(sema.gpa); | 23966 | errdefer msg.destroy(sema.gpa); |
| 24083 | if (lhs_is_vector) { | 23967 | if (lhs_is_vector) { |
| 24084 | try sema.errNote(block, lhs_src, msg, "vector here", .{}); | 23968 | try sema.errNote(lhs_src, msg, "vector here", .{}); |
| 24085 | try sema.errNote(block, rhs_src, msg, "scalar here", .{}); | 23969 | try sema.errNote(rhs_src, msg, "scalar here", .{}); |
| 24086 | } else { | 23970 | } else { |
| 24087 | try sema.errNote(block, lhs_src, msg, "scalar here", .{}); | 23971 | try sema.errNote(lhs_src, msg, "scalar here", .{}); |
| 24088 | try sema.errNote(block, rhs_src, msg, "vector here", .{}); | 23972 | try sema.errNote(rhs_src, msg, "vector here", .{}); |
| 24089 | } | 23973 | } |
| 24090 | break :msg msg; | 23974 | break :msg msg; |
| 24091 | }; | 23975 | }; |
| ... | @@ -24093,12 +23977,6 @@ fn checkVectorizableBinaryOperands( | ... | @@ -24093,12 +23977,6 @@ fn checkVectorizableBinaryOperands( |
| 24093 | } | 23977 | } |
| 24094 | } | 23978 | } |
| 24095 | | 23979 | |
| 24096 | fn maybeOptionsSrc(sema: *Sema, block: *Block, base_src: LazySrcLoc, wanted: []const u8) LazySrcLoc { | | |
| 24097 | if (base_src == .unneeded) return .unneeded; | | |
| 24098 | const mod = sema.mod; | | |
| 24099 | return mod.optionsSrc(mod.declPtr(block.src_decl), base_src, wanted); | | |
| 24100 | } | | |
| 24101 | | | |
| 24102 | fn resolveExportOptions( | 23980 | fn resolveExportOptions( |
| 24103 | sema: *Sema, | 23981 | sema: *Sema, |
| 24104 | block: *Block, | 23982 | block: *Block, |
| ... | @@ -24112,10 +23990,10 @@ fn resolveExportOptions( | ... | @@ -24112,10 +23990,10 @@ fn resolveExportOptions( |
| 24112 | const air_ref = try sema.resolveInst(zir_ref); | 23990 | const air_ref = try sema.resolveInst(zir_ref); |
| 24113 | const options = try sema.coerce(block, export_options_ty, air_ref, src); | 23991 | const options = try sema.coerce(block, export_options_ty, air_ref, src); |
| 24114 | | 23992 | |
| 24115 | const name_src = sema.maybeOptionsSrc(block, src, "name"); | 23993 | const name_src = block.src(.{ .init_field_name = src.offset.node_offset_builtin_call_arg.builtin_call_node }); |
| 24116 | const linkage_src = sema.maybeOptionsSrc(block, src, "linkage"); | 23994 | const linkage_src = block.src(.{ .init_field_linkage = src.offset.node_offset_builtin_call_arg.builtin_call_node }); |
| 24117 | const section_src = sema.maybeOptionsSrc(block, src, "section"); | 23995 | const section_src = block.src(.{ .init_field_section = src.offset.node_offset_builtin_call_arg.builtin_call_node }); |
| 24118 | const visibility_src = sema.maybeOptionsSrc(block, src, "visibility"); | 23996 | const visibility_src = block.src(.{ .init_field_visibility = src.offset.node_offset_builtin_call_arg.builtin_call_node }); |
| 24119 | | 23997 | |
| 24120 | const name_operand = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "name", .no_embedded_nulls), name_src); | 23998 | const name_operand = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "name", .no_embedded_nulls), name_src); |
| 24121 | const name = try sema.toConstString(block, name_src, name_operand, .{ | 23999 | const name = try sema.toConstString(block, name_src, name_operand, .{ |
| ... | @@ -24212,14 +24090,14 @@ fn zirCmpxchg( | ... | @@ -24212,14 +24090,14 @@ fn zirCmpxchg( |
| 24212 | 1 => .cmpxchg_strong, | 24090 | 1 => .cmpxchg_strong, |
| 24213 | else => unreachable, | 24091 | else => unreachable, |
| 24214 | }; | 24092 | }; |
| 24215 | const src = LazySrcLoc.nodeOffset(extra.node); | 24093 | const src = block.nodeOffset(extra.node); |
| 24216 | // zig fmt: off | 24094 | // zig fmt: off |
| 24217 | const elem_ty_src : LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node }; | 24095 | const elem_ty_src = block.builtinCallArgSrc(extra.node, 0); |
| 24218 | const ptr_src : LazySrcLoc = .{ .node_offset_builtin_call_arg1 = extra.node }; | 24096 | const ptr_src = block.builtinCallArgSrc(extra.node, 1); |
| 24219 | const expected_src : LazySrcLoc = .{ .node_offset_builtin_call_arg2 = extra.node }; | 24097 | const expected_src = block.builtinCallArgSrc(extra.node, 2); |
| 24220 | const new_value_src : LazySrcLoc = .{ .node_offset_builtin_call_arg3 = extra.node }; | 24098 | const new_value_src = block.builtinCallArgSrc(extra.node, 3); |
| 24221 | const success_order_src: LazySrcLoc = .{ .node_offset_builtin_call_arg4 = extra.node }; | 24099 | const success_order_src = block.builtinCallArgSrc(extra.node, 4); |
| 24222 | const failure_order_src: LazySrcLoc = .{ .node_offset_builtin_call_arg5 = extra.node }; | 24100 | const failure_order_src = block.builtinCallArgSrc(extra.node, 5); |
| 24223 | // zig fmt: on | 24101 | // zig fmt: on |
| 24224 | const expected_value = try sema.resolveInst(extra.expected_value); | 24102 | const expected_value = try sema.resolveInst(extra.expected_value); |
| 24225 | const elem_ty = sema.typeOf(expected_value); | 24103 | const elem_ty = sema.typeOf(expected_value); |
| ... | @@ -24309,7 +24187,7 @@ fn zirSplat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.I | ... | @@ -24309,7 +24187,7 @@ fn zirSplat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.I |
| 24309 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 24187 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 24310 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; | 24188 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 24311 | const src = block.nodeOffset(inst_data.src_node); | 24189 | const src = block.nodeOffset(inst_data.src_node); |
| 24312 | const scalar_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 24190 | const scalar_src = block.builtinCallArgSrc(inst_data.src_node, 0); |
| 24313 | const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu_opt, "@splat"); | 24191 | const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu_opt, "@splat"); |
| 24314 | | 24192 | |
| 24315 | if (!dest_ty.isVector(mod)) return sema.fail(block, src, "expected vector type, found '{}'", .{dest_ty.fmt(mod)}); | 24193 | if (!dest_ty.isVector(mod)) return sema.fail(block, src, "expected vector type, found '{}'", .{dest_ty.fmt(mod)}); |
| ... | @@ -24337,8 +24215,8 @@ fn zirSplat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.I | ... | @@ -24337,8 +24215,8 @@ fn zirSplat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.I |
| 24337 | fn zirReduce(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 24215 | fn zirReduce(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 24338 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 24216 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 24339 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; | 24217 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 24340 | const op_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 24218 | const op_src = block.builtinCallArgSrc(inst_data.src_node, 0); |
| 24341 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; | 24219 | const operand_src = block.builtinCallArgSrc(inst_data.src_node, 1); |
| 24342 | const operation = try sema.resolveBuiltinEnum(block, op_src, extra.lhs, "ReduceOp", .{ | 24220 | const operation = try sema.resolveBuiltinEnum(block, op_src, extra.lhs, "ReduceOp", .{ |
| 24343 | .needed_comptime_reason = "@reduce operation must be comptime-known", | 24221 | .needed_comptime_reason = "@reduce operation must be comptime-known", |
| 24344 | }); | 24222 | }); |
| ... | @@ -24409,8 +24287,8 @@ fn zirShuffle(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air | ... | @@ -24409,8 +24287,8 @@ fn zirShuffle(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 24409 | const mod = sema.mod; | 24287 | const mod = sema.mod; |
| 24410 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 24288 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 24411 | const extra = sema.code.extraData(Zir.Inst.Shuffle, inst_data.payload_index).data; | 24289 | const extra = sema.code.extraData(Zir.Inst.Shuffle, inst_data.payload_index).data; |
| 24412 | const elem_ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 24290 | const elem_ty_src = block.builtinCallArgSrc(inst_data.src_node, 0); |
| 24413 | const mask_src: LazySrcLoc = .{ .node_offset_builtin_call_arg3 = inst_data.src_node }; | 24291 | const mask_src = block.builtinCallArgSrc(inst_data.src_node, 3); |
| 24414 | | 24292 | |
| 24415 | const elem_ty = try sema.resolveType(block, elem_ty_src, extra.elem_type); | 24293 | const elem_ty = try sema.resolveType(block, elem_ty_src, extra.elem_type); |
| 24416 | try sema.checkVectorElemType(block, elem_ty_src, elem_ty); | 24294 | try sema.checkVectorElemType(block, elem_ty_src, elem_ty); |
| ... | @@ -24445,9 +24323,9 @@ fn analyzeShuffle( | ... | @@ -24445,9 +24323,9 @@ fn analyzeShuffle( |
| 24445 | mask_len: u32, | 24323 | mask_len: u32, |
| 24446 | ) CompileError!Air.Inst.Ref { | 24324 | ) CompileError!Air.Inst.Ref { |
| 24447 | const mod = sema.mod; | 24325 | const mod = sema.mod; |
| 24448 | const a_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = src_node }; | 24326 | const a_src = block.builtinCallArgSrc(src_node, 1); |
| 24449 | const b_src: LazySrcLoc = .{ .node_offset_builtin_call_arg2 = src_node }; | 24327 | const b_src = block.builtinCallArgSrc(src_node, 2); |
| 24450 | const mask_src: LazySrcLoc = .{ .node_offset_builtin_call_arg3 = src_node }; | 24328 | const mask_src = block.builtinCallArgSrc(src_node, 3); |
| 24451 | var a = a_arg; | 24329 | var a = a_arg; |
| 24452 | var b = b_arg; | 24330 | var b = b_arg; |
| 24453 | | 24331 | |
| ... | @@ -24511,16 +24389,16 @@ fn analyzeShuffle( | ... | @@ -24511,16 +24389,16 @@ fn analyzeShuffle( |
| 24511 | } | 24389 | } |
| 24512 | if (unsigned >= operand_info[chosen][0]) { | 24390 | if (unsigned >= operand_info[chosen][0]) { |
| 24513 | const msg = msg: { | 24391 | const msg = msg: { |
| 24514 | const msg = try sema.errMsg(block, mask_src, "mask index '{d}' has out-of-bounds selection", .{i}); | 24392 | const msg = try sema.errMsg(mask_src, "mask index '{d}' has out-of-bounds selection", .{i}); |
| 24515 | errdefer msg.destroy(sema.gpa); | 24393 | errdefer msg.destroy(sema.gpa); |
| 24516 | | 24394 | |
| 24517 | try sema.errNote(block, operand_info[chosen][1], msg, "selected index '{d}' out of bounds of '{}'", .{ | 24395 | try sema.errNote(operand_info[chosen][1], msg, "selected index '{d}' out of bounds of '{}'", .{ |
| 24518 | unsigned, | 24396 | unsigned, |
| 24519 | operand_info[chosen][2].fmt(sema.mod), | 24397 | operand_info[chosen][2].fmt(sema.mod), |
| 24520 | }); | 24398 | }); |
| 24521 | | 24399 | |
| 24522 | if (chosen == 0) { | 24400 | if (chosen == 0) { |
| 24523 | try sema.errNote(block, b_src, msg, "selections from the second vector are specified with negative numbers", .{}); | 24401 | try sema.errNote(b_src, msg, "selections from the second vector are specified with negative numbers", .{}); |
| 24524 | } | 24402 | } |
| 24525 | | 24403 | |
| 24526 | break :msg msg; | 24404 | break :msg msg; |
| ... | @@ -24598,11 +24476,11 @@ fn zirSelect(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) C | ... | @@ -24598,11 +24476,11 @@ fn zirSelect(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) C |
| 24598 | const mod = sema.mod; | 24476 | const mod = sema.mod; |
| 24599 | const extra = sema.code.extraData(Zir.Inst.Select, extended.operand).data; | 24477 | const extra = sema.code.extraData(Zir.Inst.Select, extended.operand).data; |
| 24600 | | 24478 | |
| 24601 | const src = LazySrcLoc.nodeOffset(extra.node); | 24479 | const src = block.nodeOffset(extra.node); |
| 24602 | const elem_ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node }; | 24480 | const elem_ty_src = block.builtinCallArgSrc(extra.node, 0); |
| 24603 | const pred_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = extra.node }; | 24481 | const pred_src = block.builtinCallArgSrc(extra.node, 1); |
| 24604 | const a_src: LazySrcLoc = .{ .node_offset_builtin_call_arg2 = extra.node }; | 24482 | const a_src = block.builtinCallArgSrc(extra.node, 2); |
| 24605 | const b_src: LazySrcLoc = .{ .node_offset_builtin_call_arg3 = extra.node }; | 24483 | const b_src = block.builtinCallArgSrc(extra.node, 3); |
| 24606 | | 24484 | |
| 24607 | const elem_ty = try sema.resolveType(block, elem_ty_src, extra.elem_type); | 24485 | const elem_ty = try sema.resolveType(block, elem_ty_src, extra.elem_type); |
| 24608 | try sema.checkVectorElemType(block, elem_ty_src, elem_ty); | 24486 | try sema.checkVectorElemType(block, elem_ty_src, elem_ty); |
| ... | @@ -24689,9 +24567,9 @@ fn zirAtomicLoad(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! | ... | @@ -24689,9 +24567,9 @@ fn zirAtomicLoad(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! |
| 24689 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 24567 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 24690 | const extra = sema.code.extraData(Zir.Inst.AtomicLoad, inst_data.payload_index).data; | 24568 | const extra = sema.code.extraData(Zir.Inst.AtomicLoad, inst_data.payload_index).data; |
| 24691 | // zig fmt: off | 24569 | // zig fmt: off |
| 24692 | const elem_ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 24570 | const elem_ty_src = block.builtinCallArgSrc(inst_data.src_node, 0); |
| 24693 | const ptr_src : LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; | 24571 | const ptr_src = block.builtinCallArgSrc(inst_data.src_node, 1); |
| 24694 | const order_src : LazySrcLoc = .{ .node_offset_builtin_call_arg2 = inst_data.src_node }; | 24572 | const order_src = block.builtinCallArgSrc(inst_data.src_node, 2); |
| 24695 | // zig fmt: on | 24573 | // zig fmt: on |
| 24696 | const elem_ty = try sema.resolveType(block, elem_ty_src, extra.elem_type); | 24574 | const elem_ty = try sema.resolveType(block, elem_ty_src, extra.elem_type); |
| 24697 | const uncasted_ptr = try sema.resolveInst(extra.ptr); | 24575 | const uncasted_ptr = try sema.resolveInst(extra.ptr); |
| ... | @@ -24738,11 +24616,11 @@ fn zirAtomicRmw(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A | ... | @@ -24738,11 +24616,11 @@ fn zirAtomicRmw(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 24738 | const extra = sema.code.extraData(Zir.Inst.AtomicRmw, inst_data.payload_index).data; | 24616 | const extra = sema.code.extraData(Zir.Inst.AtomicRmw, inst_data.payload_index).data; |
| 24739 | const src = block.nodeOffset(inst_data.src_node); | 24617 | const src = block.nodeOffset(inst_data.src_node); |
| 24740 | // zig fmt: off | 24618 | // zig fmt: off |
| 24741 | const elem_ty_src : LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 24619 | const elem_ty_src = block.builtinCallArgSrc(inst_data.src_node, 0); |
| 24742 | const ptr_src : LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; | 24620 | const ptr_src = block.builtinCallArgSrc(inst_data.src_node, 1); |
| 24743 | const op_src : LazySrcLoc = .{ .node_offset_builtin_call_arg2 = inst_data.src_node }; | 24621 | const op_src = block.builtinCallArgSrc(inst_data.src_node, 2); |
| 24744 | const operand_src : LazySrcLoc = .{ .node_offset_builtin_call_arg3 = inst_data.src_node }; | 24622 | const operand_src = block.builtinCallArgSrc(inst_data.src_node, 3); |
| 24745 | const order_src : LazySrcLoc = .{ .node_offset_builtin_call_arg4 = inst_data.src_node }; | 24623 | const order_src = block.builtinCallArgSrc(inst_data.src_node, 4); |
| 24746 | // zig fmt: on | 24624 | // zig fmt: on |
| 24747 | const operand = try sema.resolveInst(extra.operand); | 24625 | const operand = try sema.resolveInst(extra.operand); |
| 24748 | const elem_ty = sema.typeOf(operand); | 24626 | const elem_ty = sema.typeOf(operand); |
| ... | @@ -24823,10 +24701,10 @@ fn zirAtomicStore(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError | ... | @@ -24823,10 +24701,10 @@ fn zirAtomicStore(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 24823 | const extra = sema.code.extraData(Zir.Inst.AtomicStore, inst_data.payload_index).data; | 24701 | const extra = sema.code.extraData(Zir.Inst.AtomicStore, inst_data.payload_index).data; |
| 24824 | const src = block.nodeOffset(inst_data.src_node); | 24702 | const src = block.nodeOffset(inst_data.src_node); |
| 24825 | // zig fmt: off | 24703 | // zig fmt: off |
| 24826 | const elem_ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 24704 | const elem_ty_src = block.builtinCallArgSrc(inst_data.src_node, 0); |
| 24827 | const ptr_src : LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; | 24705 | const ptr_src = block.builtinCallArgSrc(inst_data.src_node, 1); |
| 24828 | const operand_src : LazySrcLoc = .{ .node_offset_builtin_call_arg2 = inst_data.src_node }; | 24706 | const operand_src = block.builtinCallArgSrc(inst_data.src_node, 2); |
| 24829 | const order_src : LazySrcLoc = .{ .node_offset_builtin_call_arg3 = inst_data.src_node }; | 24707 | const order_src = block.builtinCallArgSrc(inst_data.src_node, 3); |
| 24830 | // zig fmt: on | 24708 | // zig fmt: on |
| 24831 | const operand = try sema.resolveInst(extra.operand); | 24709 | const operand = try sema.resolveInst(extra.operand); |
| 24832 | const elem_ty = sema.typeOf(operand); | 24710 | const elem_ty = sema.typeOf(operand); |
| ... | @@ -24859,9 +24737,9 @@ fn zirMulAdd(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. | ... | @@ -24859,9 +24737,9 @@ fn zirMulAdd(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. |
| 24859 | const extra = sema.code.extraData(Zir.Inst.MulAdd, inst_data.payload_index).data; | 24737 | const extra = sema.code.extraData(Zir.Inst.MulAdd, inst_data.payload_index).data; |
| 24860 | const src = block.nodeOffset(inst_data.src_node); | 24738 | const src = block.nodeOffset(inst_data.src_node); |
| 24861 | | 24739 | |
| 24862 | const mulend1_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; | 24740 | const mulend1_src = block.builtinCallArgSrc(inst_data.src_node, 1); |
| 24863 | const mulend2_src: LazySrcLoc = .{ .node_offset_builtin_call_arg2 = inst_data.src_node }; | 24741 | const mulend2_src = block.builtinCallArgSrc(inst_data.src_node, 2); |
| 24864 | const addend_src: LazySrcLoc = .{ .node_offset_builtin_call_arg3 = inst_data.src_node }; | 24742 | const addend_src = block.builtinCallArgSrc(inst_data.src_node, 3); |
| 24865 | | 24743 | |
| 24866 | const addend = try sema.resolveInst(extra.addend); | 24744 | const addend = try sema.resolveInst(extra.addend); |
| 24867 | const ty = sema.typeOf(addend); | 24745 | const ty = sema.typeOf(addend); |
| ... | @@ -24924,9 +24802,9 @@ fn zirBuiltinCall(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError | ... | @@ -24924,9 +24802,9 @@ fn zirBuiltinCall(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 24924 | | 24802 | |
| 24925 | const mod = sema.mod; | 24803 | const mod = sema.mod; |
| 24926 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 24804 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 24927 | const modifier_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 24805 | const modifier_src = block.builtinCallArgSrc(inst_data.src_node, 0); |
| 24928 | const func_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; | 24806 | const func_src = block.builtinCallArgSrc(inst_data.src_node, 1); |
| 24929 | const args_src: LazySrcLoc = .{ .node_offset_builtin_call_arg2 = inst_data.src_node }; | 24807 | const args_src = block.builtinCallArgSrc(inst_data.src_node, 2); |
| 24930 | const call_src = block.nodeOffset(inst_data.src_node); | 24808 | const call_src = block.nodeOffset(inst_data.src_node); |
| 24931 | | 24809 | |
| 24932 | const extra = sema.code.extraData(Zir.Inst.BuiltinCall, inst_data.payload_index).data; | 24810 | const extra = sema.code.extraData(Zir.Inst.BuiltinCall, inst_data.payload_index).data; |
| ... | @@ -25022,8 +24900,8 @@ fn zirFieldParentPtr(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.Ins | ... | @@ -25022,8 +24900,8 @@ fn zirFieldParentPtr(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.Ins |
| 25022 | const flags: Zir.Inst.FullPtrCastFlags = @bitCast(@as(FlagsInt, @truncate(extended.small))); | 24900 | const flags: Zir.Inst.FullPtrCastFlags = @bitCast(@as(FlagsInt, @truncate(extended.small))); |
| 25023 | assert(!flags.ptr_cast); | 24901 | assert(!flags.ptr_cast); |
| 25024 | const inst_src = block.nodeOffset(extra.src_node); | 24902 | const inst_src = block.nodeOffset(extra.src_node); |
| 25025 | const field_name_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.src_node }; | 24903 | const field_name_src = block.builtinCallArgSrc(extra.src_node, 0); |
| 25026 | const field_ptr_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = extra.src_node }; | 24904 | const field_ptr_src = block.builtinCallArgSrc(extra.src_node, 1); |
| 25027 | | 24905 | |
| 25028 | const parent_ptr_ty = try sema.resolveDestType(block, inst_src, extra.parent_ptr_type, .remove_eu, "@fieldParentPtr"); | 24906 | const parent_ptr_ty = try sema.resolveDestType(block, inst_src, extra.parent_ptr_type, .remove_eu, "@fieldParentPtr"); |
| 25029 | try sema.checkPtrType(block, inst_src, parent_ptr_ty, true); | 24907 | try sema.checkPtrType(block, inst_src, parent_ptr_ty, true); |
| ... | @@ -25212,9 +25090,9 @@ fn ptrSubtract(sema: *Sema, block: *Block, src: LazySrcLoc, ptr_val: Value, byte | ... | @@ -25212,9 +25090,9 @@ fn ptrSubtract(sema: *Sema, block: *Block, src: LazySrcLoc, ptr_val: Value, byte |
| 25212 | }; | 25090 | }; |
| 25213 | if (ptr.byte_offset < byte_subtract) { | 25091 | if (ptr.byte_offset < byte_subtract) { |
| 25214 | return sema.failWithOwnedErrorMsg(block, msg: { | 25092 | return sema.failWithOwnedErrorMsg(block, msg: { |
| 25215 | const msg = try sema.errMsg(block, src, "pointer computation here causes undefined behavior", .{}); | 25093 | const msg = try sema.errMsg(src, "pointer computation here causes undefined behavior", .{}); |
| 25216 | errdefer msg.destroy(sema.gpa); | 25094 | errdefer msg.destroy(sema.gpa); |
| 25217 | try sema.errNote(block, src, msg, "resulting pointer exceeds bounds of containing value which may trigger overflow", .{}); | 25095 | try sema.errNote(src, msg, "resulting pointer exceeds bounds of containing value which may trigger overflow", .{}); |
| 25218 | break :msg msg; | 25096 | break :msg msg; |
| 25219 | }); | 25097 | }); |
| 25220 | } | 25098 | } |
| ... | @@ -25232,8 +25110,8 @@ fn zirMinMax( | ... | @@ -25232,8 +25110,8 @@ fn zirMinMax( |
| 25232 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 25110 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 25233 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; | 25111 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 25234 | const src = block.nodeOffset(inst_data.src_node); | 25112 | const src = block.nodeOffset(inst_data.src_node); |
| 25235 | const lhs_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 25113 | const lhs_src = block.builtinCallArgSrc(inst_data.src_node, 0); |
| 25236 | const rhs_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; | 25114 | const rhs_src = block.builtinCallArgSrc(inst_data.src_node, 1); |
| 25237 | const lhs = try sema.resolveInst(extra.lhs); | 25115 | const lhs = try sema.resolveInst(extra.lhs); |
| 25238 | const rhs = try sema.resolveInst(extra.rhs); | 25116 | const rhs = try sema.resolveInst(extra.rhs); |
| 25239 | try sema.checkNumericType(block, lhs_src, sema.typeOf(lhs)); | 25117 | try sema.checkNumericType(block, lhs_src, sema.typeOf(lhs)); |
| ... | @@ -25249,22 +25127,14 @@ fn zirMinMaxMulti( | ... | @@ -25249,22 +25127,14 @@ fn zirMinMaxMulti( |
| 25249 | ) CompileError!Air.Inst.Ref { | 25127 | ) CompileError!Air.Inst.Ref { |
| 25250 | const extra = sema.code.extraData(Zir.Inst.NodeMultiOp, extended.operand); | 25128 | const extra = sema.code.extraData(Zir.Inst.NodeMultiOp, extended.operand); |
| 25251 | const src_node = extra.data.src_node; | 25129 | const src_node = extra.data.src_node; |
| 25252 | const src = LazySrcLoc.nodeOffset(src_node); | 25130 | const src = block.nodeOffset(src_node); |
| 25253 | const operands = sema.code.refSlice(extra.end, extended.small); | 25131 | const operands = sema.code.refSlice(extra.end, extended.small); |
| 25254 | | 25132 | |
| 25255 | const air_refs = try sema.arena.alloc(Air.Inst.Ref, operands.len); | 25133 | const air_refs = try sema.arena.alloc(Air.Inst.Ref, operands.len); |
| 25256 | const operand_srcs = try sema.arena.alloc(LazySrcLoc, operands.len); | 25134 | const operand_srcs = try sema.arena.alloc(LazySrcLoc, operands.len); |
| 25257 | | 25135 | |
| 25258 | for (operands, air_refs, operand_srcs, 0..) |zir_ref, *air_ref, *op_src, i| { | 25136 | for (operands, air_refs, operand_srcs, 0..) |zir_ref, *air_ref, *op_src, i| { |
| 25259 | op_src.* = switch (i) { | 25137 | op_src.* = block.builtinCallArgSrc(src_node, @intCast(i)); |
| 25260 | 0 => .{ .node_offset_builtin_call_arg0 = src_node }, | | |
| 25261 | 1 => .{ .node_offset_builtin_call_arg1 = src_node }, | | |
| 25262 | 2 => .{ .node_offset_builtin_call_arg2 = src_node }, | | |
| 25263 | 3 => .{ .node_offset_builtin_call_arg3 = src_node }, | | |
| 25264 | 4 => .{ .node_offset_builtin_call_arg4 = src_node }, | | |
| 25265 | 5 => .{ .node_offset_builtin_call_arg5 = src_node }, | | |
| 25266 | else => src, // TODO: better source location | | |
| 25267 | }; | | |
| 25268 | air_ref.* = try sema.resolveInst(zir_ref); | 25138 | air_ref.* = try sema.resolveInst(zir_ref); |
| 25269 | try sema.checkNumericType(block, op_src.*, sema.typeOf(air_ref.*)); | 25139 | try sema.checkNumericType(block, op_src.*, sema.typeOf(air_ref.*)); |
| 25270 | } | 25140 | } |
| ... | @@ -25533,8 +25403,8 @@ fn zirMemcpy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void | ... | @@ -25533,8 +25403,8 @@ fn zirMemcpy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void |
| 25533 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 25403 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 25534 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; | 25404 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 25535 | const src = block.nodeOffset(inst_data.src_node); | 25405 | const src = block.nodeOffset(inst_data.src_node); |
| 25536 | const dest_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 25406 | const dest_src = block.builtinCallArgSrc(inst_data.src_node, 0); |
| 25537 | const src_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; | 25407 | const src_src = block.builtinCallArgSrc(inst_data.src_node, 1); |
| 25538 | const dest_ptr = try sema.resolveInst(extra.lhs); | 25408 | const dest_ptr = try sema.resolveInst(extra.lhs); |
| 25539 | const src_ptr = try sema.resolveInst(extra.rhs); | 25409 | const src_ptr = try sema.resolveInst(extra.rhs); |
| 25540 | const dest_ty = sema.typeOf(dest_ptr); | 25410 | const dest_ty = sema.typeOf(dest_ptr); |
| ... | @@ -25550,12 +25420,12 @@ fn zirMemcpy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void | ... | @@ -25550,12 +25420,12 @@ fn zirMemcpy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void |
| 25550 | | 25420 | |
| 25551 | if (dest_len == .none and src_len == .none) { | 25421 | if (dest_len == .none and src_len == .none) { |
| 25552 | const msg = msg: { | 25422 | const msg = msg: { |
| 25553 | const msg = try sema.errMsg(block, src, "unknown @memcpy length", .{}); | 25423 | const msg = try sema.errMsg(src, "unknown @memcpy length", .{}); |
| 25554 | errdefer msg.destroy(sema.gpa); | 25424 | errdefer msg.destroy(sema.gpa); |
| 25555 | try sema.errNote(block, dest_src, msg, "destination type '{}' provides no length", .{ | 25425 | try sema.errNote(dest_src, msg, "destination type '{}' provides no length", .{ |
| 25556 | dest_ty.fmt(sema.mod), | 25426 | dest_ty.fmt(sema.mod), |
| 25557 | }); | 25427 | }); |
| 25558 | try sema.errNote(block, src_src, msg, "source type '{}' provides no length", .{ | 25428 | try sema.errNote(src_src, msg, "source type '{}' provides no length", .{ |
| 25559 | src_ty.fmt(sema.mod), | 25429 | src_ty.fmt(sema.mod), |
| 25560 | }); | 25430 | }); |
| 25561 | break :msg msg; | 25431 | break :msg msg; |
| ... | @@ -25572,12 +25442,12 @@ fn zirMemcpy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void | ... | @@ -25572,12 +25442,12 @@ fn zirMemcpy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void |
| 25572 | if (try sema.resolveDefinedValue(block, src_src, src_len)) |src_len_val| { | 25442 | if (try sema.resolveDefinedValue(block, src_src, src_len)) |src_len_val| { |
| 25573 | if (!(try sema.valuesEqual(dest_len_val, src_len_val, Type.usize))) { | 25443 | if (!(try sema.valuesEqual(dest_len_val, src_len_val, Type.usize))) { |
| 25574 | const msg = msg: { | 25444 | const msg = msg: { |
| 25575 | const msg = try sema.errMsg(block, src, "non-matching @memcpy lengths", .{}); | 25445 | const msg = try sema.errMsg(src, "non-matching @memcpy lengths", .{}); |
| 25576 | errdefer msg.destroy(sema.gpa); | 25446 | errdefer msg.destroy(sema.gpa); |
| 25577 | try sema.errNote(block, dest_src, msg, "length {} here", .{ | 25447 | try sema.errNote(dest_src, msg, "length {} here", .{ |
| 25578 | dest_len_val.fmtValue(sema.mod, sema), | 25448 | dest_len_val.fmtValue(sema.mod, sema), |
| 25579 | }); | 25449 | }); |
| 25580 | try sema.errNote(block, src_src, msg, "length {} here", .{ | 25450 | try sema.errNote(src_src, msg, "length {} here", .{ |
| 25581 | src_len_val.fmtValue(sema.mod, sema), | 25451 | src_len_val.fmtValue(sema.mod, sema), |
| 25582 | }); | 25452 | }); |
| 25583 | break :msg msg; | 25453 | break :msg msg; |
| ... | @@ -25685,7 +25555,7 @@ fn zirMemcpy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void | ... | @@ -25685,7 +25555,7 @@ fn zirMemcpy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void |
| 25685 | } else if (dest_len == .none and len_val == null) { | 25555 | } else if (dest_len == .none and len_val == null) { |
| 25686 | // Change the dest to a slice, since its type must have the length. | 25556 | // Change the dest to a slice, since its type must have the length. |
| 25687 | const dest_ptr_ptr = try sema.analyzeRef(block, dest_src, new_dest_ptr); | 25557 | const dest_ptr_ptr = try sema.analyzeRef(block, dest_src, new_dest_ptr); |
| 25688 | new_dest_ptr = try sema.analyzeSlice(block, dest_src, dest_ptr_ptr, .zero, src_len, .none, .unneeded, dest_src, dest_src, dest_src, false); | 25558 | new_dest_ptr = try sema.analyzeSlice(block, dest_src, dest_ptr_ptr, .zero, src_len, .none, LazySrcLoc.unneeded, dest_src, dest_src, dest_src, false); |
| 25689 | const new_src_ptr_ty = sema.typeOf(new_src_ptr); | 25559 | const new_src_ptr_ty = sema.typeOf(new_src_ptr); |
| 25690 | if (new_src_ptr_ty.isSlice(mod)) { | 25560 | if (new_src_ptr_ty.isSlice(mod)) { |
| 25691 | new_src_ptr = try sema.analyzeSlicePtr(block, src_src, new_src_ptr, new_src_ptr_ty); | 25561 | new_src_ptr = try sema.analyzeSlicePtr(block, src_src, new_src_ptr, new_src_ptr_ty); |
| ... | @@ -25753,8 +25623,8 @@ fn zirMemset(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void | ... | @@ -25753,8 +25623,8 @@ fn zirMemset(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void |
| 25753 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 25623 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 25754 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; | 25624 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 25755 | const src = block.nodeOffset(inst_data.src_node); | 25625 | const src = block.nodeOffset(inst_data.src_node); |
| 25756 | const dest_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 25626 | const dest_src = block.builtinCallArgSrc(inst_data.src_node, 0); |
| 25757 | const value_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; | 25627 | const value_src = block.builtinCallArgSrc(inst_data.src_node, 1); |
| 25758 | const dest_ptr = try sema.resolveInst(extra.lhs); | 25628 | const dest_ptr = try sema.resolveInst(extra.lhs); |
| 25759 | const uncoerced_elem = try sema.resolveInst(extra.rhs); | 25629 | const uncoerced_elem = try sema.resolveInst(extra.rhs); |
| 25760 | const dest_ptr_ty = sema.typeOf(dest_ptr); | 25630 | const dest_ptr_ty = sema.typeOf(dest_ptr); |
| ... | @@ -25776,9 +25646,9 @@ fn zirMemset(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void | ... | @@ -25776,9 +25646,9 @@ fn zirMemset(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void |
| 25776 | .Many, .C => {}, | 25646 | .Many, .C => {}, |
| 25777 | } | 25647 | } |
| 25778 | return sema.failWithOwnedErrorMsg(block, msg: { | 25648 | return sema.failWithOwnedErrorMsg(block, msg: { |
| 25779 | const msg = try sema.errMsg(block, src, "unknown @memset length", .{}); | 25649 | const msg = try sema.errMsg(src, "unknown @memset length", .{}); |
| 25780 | errdefer msg.destroy(sema.gpa); | 25650 | errdefer msg.destroy(sema.gpa); |
| 25781 | try sema.errNote(block, dest_src, msg, "destination type '{}' provides no length", .{ | 25651 | try sema.errNote(dest_src, msg, "destination type '{}' provides no length", .{ |
| 25782 | dest_ptr_ty.fmt(mod), | 25652 | dest_ptr_ty.fmt(mod), |
| 25783 | }); | 25653 | }); |
| 25784 | break :msg msg; | 25654 | break :msg msg; |
| ... | @@ -25831,7 +25701,7 @@ fn zirMemset(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void | ... | @@ -25831,7 +25701,7 @@ fn zirMemset(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void |
| 25831 | | 25701 | |
| 25832 | fn zirBuiltinAsyncCall(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!Air.Inst.Ref { | 25702 | fn zirBuiltinAsyncCall(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!Air.Inst.Ref { |
| 25833 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; | 25703 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; |
| 25834 | const src = LazySrcLoc.nodeOffset(extra.node); | 25704 | const src = block.nodeOffset(extra.node); |
| 25835 | return sema.failWithUseOfAsync(block, src); | 25705 | return sema.failWithUseOfAsync(block, src); |
| 25836 | } | 25706 | } |
| 25837 | | 25707 | |
| ... | @@ -25858,7 +25728,7 @@ fn zirAwaitNosuspend( | ... | @@ -25858,7 +25728,7 @@ fn zirAwaitNosuspend( |
| 25858 | extended: Zir.Inst.Extended.InstData, | 25728 | extended: Zir.Inst.Extended.InstData, |
| 25859 | ) CompileError!Air.Inst.Ref { | 25729 | ) CompileError!Air.Inst.Ref { |
| 25860 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; | 25730 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; |
| 25861 | const src = LazySrcLoc.nodeOffset(extra.node); | 25731 | const src = block.nodeOffset(extra.node); |
| 25862 | | 25732 | |
| 25863 | return sema.failWithUseOfAsync(block, src); | 25733 | return sema.failWithUseOfAsync(block, src); |
| 25864 | } | 25734 | } |
| ... | @@ -25870,8 +25740,8 @@ fn zirVarExtended( | ... | @@ -25870,8 +25740,8 @@ fn zirVarExtended( |
| 25870 | ) CompileError!Air.Inst.Ref { | 25740 | ) CompileError!Air.Inst.Ref { |
| 25871 | const mod = sema.mod; | 25741 | const mod = sema.mod; |
| 25872 | const extra = sema.code.extraData(Zir.Inst.ExtendedVar, extended.operand); | 25742 | const extra = sema.code.extraData(Zir.Inst.ExtendedVar, extended.operand); |
| 25873 | const ty_src: LazySrcLoc = .{ .node_offset_var_decl_ty = 0 }; | 25743 | const ty_src = block.src(.{ .node_offset_var_decl_ty = 0 }); |
| 25874 | const init_src: LazySrcLoc = .{ .node_offset_var_decl_init = 0 }; | 25744 | const init_src = block.src(.{ .node_offset_var_decl_init = 0 }); |
| 25875 | const small: Zir.Inst.ExtendedVar.Small = @bitCast(extended.small); | 25745 | const small: Zir.Inst.ExtendedVar.Small = @bitCast(extended.small); |
| 25876 | | 25746 | |
| 25877 | var extra_index: usize = extra.end; | 25747 | var extra_index: usize = extra.end; |
| ... | @@ -25936,11 +25806,11 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A | ... | @@ -25936,11 +25806,11 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 25936 | const extra = sema.code.extraData(Zir.Inst.FuncFancy, inst_data.payload_index); | 25806 | const extra = sema.code.extraData(Zir.Inst.FuncFancy, inst_data.payload_index); |
| 25937 | const target = mod.getTarget(); | 25807 | const target = mod.getTarget(); |
| 25938 | | 25808 | |
| 25939 | const align_src: LazySrcLoc = .{ .node_offset_fn_type_align = inst_data.src_node }; | 25809 | const align_src = block.src(.{ .node_offset_fn_type_align = inst_data.src_node }); |
| 25940 | const addrspace_src: LazySrcLoc = .{ .node_offset_fn_type_addrspace = inst_data.src_node }; | 25810 | const addrspace_src = block.src(.{ .node_offset_fn_type_addrspace = inst_data.src_node }); |
| 25941 | const section_src: LazySrcLoc = .{ .node_offset_fn_type_section = inst_data.src_node }; | 25811 | const section_src = block.src(.{ .node_offset_fn_type_section = inst_data.src_node }); |
| 25942 | const cc_src: LazySrcLoc = .{ .node_offset_fn_type_cc = inst_data.src_node }; | 25812 | const cc_src = block.src(.{ .node_offset_fn_type_cc = inst_data.src_node }); |
| 25943 | const ret_src: LazySrcLoc = .{ .node_offset_fn_type_ret_ty = inst_data.src_node }; | 25813 | const ret_src = block.src(.{ .node_offset_fn_type_ret_ty = inst_data.src_node }); |
| 25944 | const has_body = extra.data.body_len != 0; | 25814 | const has_body = extra.data.body_len != 0; |
| 25945 | | 25815 | |
| 25946 | var extra_index: usize = extra.end; | 25816 | var extra_index: usize = extra.end; |
| ... | @@ -26167,7 +26037,7 @@ fn zirCUndef( | ... | @@ -26167,7 +26037,7 @@ fn zirCUndef( |
| 26167 | extended: Zir.Inst.Extended.InstData, | 26037 | extended: Zir.Inst.Extended.InstData, |
| 26168 | ) CompileError!Air.Inst.Ref { | 26038 | ) CompileError!Air.Inst.Ref { |
| 26169 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; | 26039 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; |
| 26170 | const src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node }; | 26040 | const src = block.builtinCallArgSrc(extra.node, 0); |
| 26171 | | 26041 | |
| 26172 | const name = try sema.resolveConstString(block, src, extra.operand, .{ | 26042 | const name = try sema.resolveConstString(block, src, extra.operand, .{ |
| 26173 | .needed_comptime_reason = "name of macro being undefined must be comptime-known", | 26043 | .needed_comptime_reason = "name of macro being undefined must be comptime-known", |
| ... | @@ -26182,7 +26052,7 @@ fn zirCInclude( | ... | @@ -26182,7 +26052,7 @@ fn zirCInclude( |
| 26182 | extended: Zir.Inst.Extended.InstData, | 26052 | extended: Zir.Inst.Extended.InstData, |
| 26183 | ) CompileError!Air.Inst.Ref { | 26053 | ) CompileError!Air.Inst.Ref { |
| 26184 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; | 26054 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; |
| 26185 | const src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node }; | 26055 | const src = block.builtinCallArgSrc(extra.node, 0); |
| 26186 | | 26056 | |
| 26187 | const name = try sema.resolveConstString(block, src, extra.operand, .{ | 26057 | const name = try sema.resolveConstString(block, src, extra.operand, .{ |
| 26188 | .needed_comptime_reason = "path being included must be comptime-known", | 26058 | .needed_comptime_reason = "path being included must be comptime-known", |
| ... | @@ -26198,8 +26068,8 @@ fn zirCDefine( | ... | @@ -26198,8 +26068,8 @@ fn zirCDefine( |
| 26198 | ) CompileError!Air.Inst.Ref { | 26068 | ) CompileError!Air.Inst.Ref { |
| 26199 | const mod = sema.mod; | 26069 | const mod = sema.mod; |
| 26200 | const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data; | 26070 | const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data; |
| 26201 | const name_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node }; | 26071 | const name_src = block.builtinCallArgSrc(extra.node, 0); |
| 26202 | const val_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = extra.node }; | 26072 | const val_src = block.builtinCallArgSrc(extra.node, 1); |
| 26203 | | 26073 | |
| 26204 | const name = try sema.resolveConstString(block, name_src, extra.lhs, .{ | 26074 | const name = try sema.resolveConstString(block, name_src, extra.lhs, .{ |
| 26205 | .needed_comptime_reason = "name of macro being undefined must be comptime-known", | 26075 | .needed_comptime_reason = "name of macro being undefined must be comptime-known", |
| ... | @@ -26222,8 +26092,8 @@ fn zirWasmMemorySize( | ... | @@ -26222,8 +26092,8 @@ fn zirWasmMemorySize( |
| 26222 | extended: Zir.Inst.Extended.InstData, | 26092 | extended: Zir.Inst.Extended.InstData, |
| 26223 | ) CompileError!Air.Inst.Ref { | 26093 | ) CompileError!Air.Inst.Ref { |
| 26224 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; | 26094 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; |
| 26225 | const index_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node }; | 26095 | const index_src = block.builtinCallArgSrc(extra.node, 0); |
| 26226 | const builtin_src = LazySrcLoc.nodeOffset(extra.node); | 26096 | const builtin_src = block.nodeOffset(extra.node); |
| 26227 | const target = sema.mod.getTarget(); | 26097 | const target = sema.mod.getTarget(); |
| 26228 | if (!target.isWasm()) { | 26098 | if (!target.isWasm()) { |
| 26229 | return sema.fail(block, builtin_src, "builtin @wasmMemorySize is available when targeting WebAssembly; targeted CPU architecture is {s}", .{@tagName(target.cpu.arch)}); | 26099 | return sema.fail(block, builtin_src, "builtin @wasmMemorySize is available when targeting WebAssembly; targeted CPU architecture is {s}", .{@tagName(target.cpu.arch)}); |
| ... | @@ -26248,9 +26118,9 @@ fn zirWasmMemoryGrow( | ... | @@ -26248,9 +26118,9 @@ fn zirWasmMemoryGrow( |
| 26248 | extended: Zir.Inst.Extended.InstData, | 26118 | extended: Zir.Inst.Extended.InstData, |
| 26249 | ) CompileError!Air.Inst.Ref { | 26119 | ) CompileError!Air.Inst.Ref { |
| 26250 | const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data; | 26120 | const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data; |
| 26251 | const builtin_src = LazySrcLoc.nodeOffset(extra.node); | 26121 | const builtin_src = block.nodeOffset(extra.node); |
| 26252 | const index_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node }; | 26122 | const index_src = block.builtinCallArgSrc(extra.node, 0); |
| 26253 | const delta_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = extra.node }; | 26123 | const delta_src = block.builtinCallArgSrc(extra.node, 1); |
| 26254 | const target = sema.mod.getTarget(); | 26124 | const target = sema.mod.getTarget(); |
| 26255 | if (!target.isWasm()) { | 26125 | if (!target.isWasm()) { |
| 26256 | return sema.fail(block, builtin_src, "builtin @wasmMemoryGrow is available when targeting WebAssembly; targeted CPU architecture is {s}", .{@tagName(target.cpu.arch)}); | 26126 | return sema.fail(block, builtin_src, "builtin @wasmMemoryGrow is available when targeting WebAssembly; targeted CPU architecture is {s}", .{@tagName(target.cpu.arch)}); |
| ... | @@ -26283,9 +26153,9 @@ fn resolvePrefetchOptions( | ... | @@ -26283,9 +26153,9 @@ fn resolvePrefetchOptions( |
| 26283 | const options_ty = try sema.getBuiltinType("PrefetchOptions"); | 26153 | const options_ty = try sema.getBuiltinType("PrefetchOptions"); |
| 26284 | const options = try sema.coerce(block, options_ty, try sema.resolveInst(zir_ref), src); | 26154 | const options = try sema.coerce(block, options_ty, try sema.resolveInst(zir_ref), src); |
| 26285 | | 26155 | |
| 26286 | const rw_src = sema.maybeOptionsSrc(block, src, "rw"); | 26156 | const rw_src = block.src(.{ .init_field_rw = src.offset.node_offset_builtin_call_arg.builtin_call_node }); |
| 26287 | const locality_src = sema.maybeOptionsSrc(block, src, "locality"); | 26157 | const locality_src = block.src(.{ .init_field_locality = src.offset.node_offset_builtin_call_arg.builtin_call_node }); |
| 26288 | const cache_src = sema.maybeOptionsSrc(block, src, "cache"); | 26158 | const cache_src = block.src(.{ .init_field_cache = src.offset.node_offset_builtin_call_arg.builtin_call_node }); |
| 26289 | | 26159 | |
| 26290 | const rw = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "rw", .no_embedded_nulls), rw_src); | 26160 | const rw = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "rw", .no_embedded_nulls), rw_src); |
| 26291 | const rw_val = try sema.resolveConstDefinedValue(block, rw_src, rw, .{ | 26161 | const rw_val = try sema.resolveConstDefinedValue(block, rw_src, rw, .{ |
| ... | @@ -26315,18 +26185,12 @@ fn zirPrefetch( | ... | @@ -26315,18 +26185,12 @@ fn zirPrefetch( |
| 26315 | extended: Zir.Inst.Extended.InstData, | 26185 | extended: Zir.Inst.Extended.InstData, |
| 26316 | ) CompileError!Air.Inst.Ref { | 26186 | ) CompileError!Air.Inst.Ref { |
| 26317 | const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data; | 26187 | const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data; |
| 26318 | const ptr_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node }; | 26188 | const ptr_src = block.builtinCallArgSrc(extra.node, 0); |
| 26319 | const opts_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = extra.node }; | 26189 | const opts_src = block.builtinCallArgSrc(extra.node, 1); |
| 26320 | const ptr = try sema.resolveInst(extra.lhs); | 26190 | const ptr = try sema.resolveInst(extra.lhs); |
| 26321 | try sema.checkPtrOperand(block, ptr_src, sema.typeOf(ptr)); | 26191 | try sema.checkPtrOperand(block, ptr_src, sema.typeOf(ptr)); |
| 26322 | | 26192 | |
| 26323 | const options = sema.resolvePrefetchOptions(block, .unneeded, extra.rhs) catch |err| switch (err) { | 26193 | const options = try sema.resolvePrefetchOptions(block, opts_src, extra.rhs); |
| 26324 | error.NeededSourceLocation => { | | |
| 26325 | _ = try sema.resolvePrefetchOptions(block, opts_src, extra.rhs); | | |
| 26326 | unreachable; | | |
| 26327 | }, | | |
| 26328 | else => |e| return e, | | |
| 26329 | }; | | |
| 26330 | | 26194 | |
| 26331 | if (!block.is_comptime) { | 26195 | if (!block.is_comptime) { |
| 26332 | _ = try block.addInst(.{ | 26196 | _ = try block.addInst(.{ |
| ... | @@ -26361,10 +26225,10 @@ fn resolveExternOptions( | ... | @@ -26361,10 +26225,10 @@ fn resolveExternOptions( |
| 26361 | const extern_options_ty = try sema.getBuiltinType("ExternOptions"); | 26225 | const extern_options_ty = try sema.getBuiltinType("ExternOptions"); |
| 26362 | const options = try sema.coerce(block, extern_options_ty, options_inst, src); | 26226 | const options = try sema.coerce(block, extern_options_ty, options_inst, src); |
| 26363 | | 26227 | |
| 26364 | const name_src = sema.maybeOptionsSrc(block, src, "name"); | 26228 | const name_src = block.src(.{ .init_field_name = src.offset.node_offset_builtin_call_arg.builtin_call_node }); |
| 26365 | const library_src = sema.maybeOptionsSrc(block, src, "library"); | 26229 | const library_src = block.src(.{ .init_field_library = src.offset.node_offset_builtin_call_arg.builtin_call_node }); |
| 26366 | const linkage_src = sema.maybeOptionsSrc(block, src, "linkage"); | 26230 | const linkage_src = block.src(.{ .init_field_linkage = src.offset.node_offset_builtin_call_arg.builtin_call_node }); |
| 26367 | const thread_local_src = sema.maybeOptionsSrc(block, src, "thread_local"); | 26231 | const thread_local_src = block.src(.{ .init_field_thread_local = src.offset.node_offset_builtin_call_arg.builtin_call_node }); |
| 26368 | | 26232 | |
| 26369 | const name_ref = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "name", .no_embedded_nulls), name_src); | 26233 | const name_ref = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "name", .no_embedded_nulls), name_src); |
| 26370 | const name = try sema.toConstString(block, name_src, name_ref, .{ | 26234 | const name = try sema.toConstString(block, name_src, name_ref, .{ |
| ... | @@ -26422,8 +26286,8 @@ fn zirBuiltinExtern( | ... | @@ -26422,8 +26286,8 @@ fn zirBuiltinExtern( |
| 26422 | const mod = sema.mod; | 26286 | const mod = sema.mod; |
| 26423 | const ip = &mod.intern_pool; | 26287 | const ip = &mod.intern_pool; |
| 26424 | const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data; | 26288 | const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data; |
| 26425 | const ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node }; | 26289 | const ty_src = block.builtinCallArgSrc(extra.node, 0); |
| 26426 | const options_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = extra.node }; | 26290 | const options_src = block.builtinCallArgSrc(extra.node, 1); |
| 26427 | | 26291 | |
| 26428 | var ty = try sema.resolveType(block, ty_src, extra.lhs); | 26292 | var ty = try sema.resolveType(block, ty_src, extra.lhs); |
| 26429 | if (!ty.isPtrAtRuntime(mod)) { | 26293 | if (!ty.isPtrAtRuntime(mod)) { |
| ... | @@ -26431,29 +26295,22 @@ fn zirBuiltinExtern( | ... | @@ -26431,29 +26295,22 @@ fn zirBuiltinExtern( |
| 26431 | } | 26295 | } |
| 26432 | if (!try sema.validateExternType(ty, .other)) { | 26296 | if (!try sema.validateExternType(ty, .other)) { |
| 26433 | const msg = msg: { | 26297 | const msg = msg: { |
| 26434 | const msg = try sema.errMsg(block, ty_src, "extern symbol cannot have type '{}'", .{ty.fmt(mod)}); | 26298 | const msg = try sema.errMsg(ty_src, "extern symbol cannot have type '{}'", .{ty.fmt(mod)}); |
| 26435 | errdefer msg.destroy(sema.gpa); | 26299 | errdefer msg.destroy(sema.gpa); |
| 26436 | const src_decl = sema.mod.declPtr(block.src_decl); | 26300 | try sema.explainWhyTypeIsNotExtern(msg, ty_src, ty, .other); |
| 26437 | try sema.explainWhyTypeIsNotExtern(msg, src_decl.toSrcLoc(ty_src, mod), ty, .other); | | |
| 26438 | break :msg msg; | 26301 | break :msg msg; |
| 26439 | }; | 26302 | }; |
| 26440 | return sema.failWithOwnedErrorMsg(block, msg); | 26303 | return sema.failWithOwnedErrorMsg(block, msg); |
| 26441 | } | 26304 | } |
| 26442 | | 26305 | |
| 26443 | const options = sema.resolveExternOptions(block, .unneeded, extra.rhs) catch |err| switch (err) { | 26306 | const options = try sema.resolveExternOptions(block, options_src, extra.rhs); |
| 26444 | error.NeededSourceLocation => { | | |
| 26445 | _ = try sema.resolveExternOptions(block, options_src, extra.rhs); | | |
| 26446 | unreachable; | | |
| 26447 | }, | | |
| 26448 | else => |e| return e, | | |
| 26449 | }; | | |
| 26450 | | 26307 | |
| 26451 | if (options.linkage == .weak and !ty.ptrAllowsZero(mod)) { | 26308 | if (options.linkage == .weak and !ty.ptrAllowsZero(mod)) { |
| 26452 | ty = try mod.optionalType(ty.toIntern()); | 26309 | ty = try mod.optionalType(ty.toIntern()); |
| 26453 | } | 26310 | } |
| 26454 | const ptr_info = ty.ptrInfo(mod); | 26311 | const ptr_info = ty.ptrInfo(mod); |
| 26455 | | 26312 | |
| 26456 | const new_decl_index = try mod.allocateNewDecl(sema.owner_decl.src_namespace, sema.owner_decl.src_node); | 26313 | const new_decl_index = try mod.allocateNewDecl(sema.owner_decl.src_namespace); |
| 26457 | errdefer mod.destroyDecl(new_decl_index); | 26314 | errdefer mod.destroyDecl(new_decl_index); |
| 26458 | const new_decl = mod.declPtr(new_decl_index); | 26315 | const new_decl = mod.declPtr(new_decl_index); |
| 26459 | try mod.initNewAnonDecl( | 26316 | try mod.initNewAnonDecl( |
| ... | @@ -26503,8 +26360,8 @@ fn zirWorkItem( | ... | @@ -26503,8 +26360,8 @@ fn zirWorkItem( |
| 26503 | zir_tag: Zir.Inst.Extended, | 26360 | zir_tag: Zir.Inst.Extended, |
| 26504 | ) CompileError!Air.Inst.Ref { | 26361 | ) CompileError!Air.Inst.Ref { |
| 26505 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; | 26362 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; |
| 26506 | const dimension_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node }; | 26363 | const dimension_src = block.builtinCallArgSrc(extra.node, 0); |
| 26507 | const builtin_src = LazySrcLoc.nodeOffset(extra.node); | 26364 | const builtin_src = block.nodeOffset(extra.node); |
| 26508 | const target = sema.mod.getTarget(); | 26365 | const target = sema.mod.getTarget(); |
| 26509 | | 26366 | |
| 26510 | switch (target.cpu.arch) { | 26367 | switch (target.cpu.arch) { |
| ... | @@ -26545,11 +26402,11 @@ fn zirInComptime( | ... | @@ -26545,11 +26402,11 @@ fn zirInComptime( |
| 26545 | fn requireRuntimeBlock(sema: *Sema, block: *Block, src: LazySrcLoc, runtime_src: ?LazySrcLoc) !void { | 26402 | fn requireRuntimeBlock(sema: *Sema, block: *Block, src: LazySrcLoc, runtime_src: ?LazySrcLoc) !void { |
| 26546 | if (block.is_comptime) { | 26403 | if (block.is_comptime) { |
| 26547 | const msg = msg: { | 26404 | const msg = msg: { |
| 26548 | const msg = try sema.errMsg(block, src, "unable to evaluate comptime expression", .{}); | 26405 | const msg = try sema.errMsg(src, "unable to evaluate comptime expression", .{}); |
| 26549 | errdefer msg.destroy(sema.gpa); | 26406 | errdefer msg.destroy(sema.gpa); |
| 26550 | | 26407 | |
| 26551 | if (runtime_src) |some| { | 26408 | if (runtime_src) |some| { |
| 26552 | try sema.errNote(block, some, msg, "operation is runtime due to this operand", .{}); | 26409 | try sema.errNote(some, msg, "operation is runtime due to this operand", .{}); |
| 26553 | } | 26410 | } |
| 26554 | if (block.comptime_reason) |some| { | 26411 | if (block.comptime_reason) |some| { |
| 26555 | try some.explain(sema, msg); | 26412 | try some.explain(sema, msg); |
| ... | @@ -26572,10 +26429,9 @@ fn validateVarType( | ... | @@ -26572,10 +26429,9 @@ fn validateVarType( |
| 26572 | if (is_extern) { | 26429 | if (is_extern) { |
| 26573 | if (!try sema.validateExternType(var_ty, .other)) { | 26430 | if (!try sema.validateExternType(var_ty, .other)) { |
| 26574 | const msg = msg: { | 26431 | const msg = msg: { |
| 26575 | const msg = try sema.errMsg(block, src, "extern variable cannot have type '{}'", .{var_ty.fmt(mod)}); | 26432 | const msg = try sema.errMsg(src, "extern variable cannot have type '{}'", .{var_ty.fmt(mod)}); |
| 26576 | errdefer msg.destroy(sema.gpa); | 26433 | errdefer msg.destroy(sema.gpa); |
| 26577 | const src_decl = mod.declPtr(block.src_decl); | 26434 | try sema.explainWhyTypeIsNotExtern(msg, src, var_ty, .other); |
| 26578 | try sema.explainWhyTypeIsNotExtern(msg, src_decl.toSrcLoc(src, mod), var_ty, .other); | | |
| 26579 | break :msg msg; | 26435 | break :msg msg; |
| 26580 | }; | 26436 | }; |
| 26581 | return sema.failWithOwnedErrorMsg(block, msg); | 26437 | return sema.failWithOwnedErrorMsg(block, msg); |
| ... | @@ -26594,13 +26450,12 @@ fn validateVarType( | ... | @@ -26594,13 +26450,12 @@ fn validateVarType( |
| 26594 | if (!try sema.typeRequiresComptime(var_ty)) return; | 26450 | if (!try sema.typeRequiresComptime(var_ty)) return; |
| 26595 | | 26451 | |
| 26596 | const msg = msg: { | 26452 | const msg = msg: { |
| 26597 | const msg = try sema.errMsg(block, src, "variable of type '{}' must be const or comptime", .{var_ty.fmt(mod)}); | 26453 | const msg = try sema.errMsg(src, "variable of type '{}' must be const or comptime", .{var_ty.fmt(mod)}); |
| 26598 | errdefer msg.destroy(sema.gpa); | 26454 | errdefer msg.destroy(sema.gpa); |
| 26599 | | 26455 | |
| 26600 | const src_decl = mod.declPtr(block.src_decl); | 26456 | try sema.explainWhyTypeIsComptime(msg, src, var_ty); |
| 26601 | try sema.explainWhyTypeIsComptime(msg, src_decl.toSrcLoc(src, mod), var_ty); | | |
| 26602 | if (var_ty.zigTypeTag(mod) == .ComptimeInt or var_ty.zigTypeTag(mod) == .ComptimeFloat) { | 26457 | if (var_ty.zigTypeTag(mod) == .ComptimeInt or var_ty.zigTypeTag(mod) == .ComptimeFloat) { |
| 26603 | try sema.errNote(block, src, msg, "to modify this variable at runtime, it must be given an explicit fixed-size number type", .{}); | 26458 | try sema.errNote(src, msg, "to modify this variable at runtime, it must be given an explicit fixed-size number type", .{}); |
| 26604 | } | 26459 | } |
| 26605 | | 26460 | |
| 26606 | break :msg msg; | 26461 | break :msg msg; |
| ... | @@ -26613,7 +26468,7 @@ const TypeSet = std.AutoHashMapUnmanaged(InternPool.Index, void); | ... | @@ -26613,7 +26468,7 @@ const TypeSet = std.AutoHashMapUnmanaged(InternPool.Index, void); |
| 26613 | fn explainWhyTypeIsComptime( | 26468 | fn explainWhyTypeIsComptime( |
| 26614 | sema: *Sema, | 26469 | sema: *Sema, |
| 26615 | msg: *Module.ErrorMsg, | 26470 | msg: *Module.ErrorMsg, |
| 26616 | src_loc: Module.SrcLoc, | 26471 | src_loc: LazySrcLoc, |
| 26617 | ty: Type, | 26472 | ty: Type, |
| 26618 | ) CompileError!void { | 26473 | ) CompileError!void { |
| 26619 | var type_set = TypeSet{}; | 26474 | var type_set = TypeSet{}; |
| ... | @@ -26626,7 +26481,7 @@ fn explainWhyTypeIsComptime( | ... | @@ -26626,7 +26481,7 @@ fn explainWhyTypeIsComptime( |
| 26626 | fn explainWhyTypeIsComptimeInner( | 26481 | fn explainWhyTypeIsComptimeInner( |
| 26627 | sema: *Sema, | 26482 | sema: *Sema, |
| 26628 | msg: *Module.ErrorMsg, | 26483 | msg: *Module.ErrorMsg, |
| 26629 | src_loc: Module.SrcLoc, | 26484 | src_loc: LazySrcLoc, |
| 26630 | ty: Type, | 26485 | ty: Type, |
| 26631 | type_set: *TypeSet, | 26486 | type_set: *TypeSet, |
| 26632 | ) CompileError!void { | 26487 | ) CompileError!void { |
| ... | @@ -26644,13 +26499,13 @@ fn explainWhyTypeIsComptimeInner( | ... | @@ -26644,13 +26499,13 @@ fn explainWhyTypeIsComptimeInner( |
| 26644 | => return, | 26499 | => return, |
| 26645 | | 26500 | |
| 26646 | .Fn => { | 26501 | .Fn => { |
| 26647 | try mod.errNoteNonLazy(src_loc, msg, "use '*const {}' for a function pointer type", .{ | 26502 | try sema.errNote(src_loc, msg, "use '*const {}' for a function pointer type", .{ |
| 26648 | ty.fmt(sema.mod), | 26503 | ty.fmt(sema.mod), |
| 26649 | }); | 26504 | }); |
| 26650 | }, | 26505 | }, |
| 26651 | | 26506 | |
| 26652 | .Type => { | 26507 | .Type => { |
| 26653 | try mod.errNoteNonLazy(src_loc, msg, "types are not available at runtime", .{}); | 26508 | try sema.errNote(src_loc, msg, "types are not available at runtime", .{}); |
| 26654 | }, | 26509 | }, |
| 26655 | | 26510 | |
| 26656 | .ComptimeFloat, | 26511 | .ComptimeFloat, |
| ... | @@ -26662,7 +26517,7 @@ fn explainWhyTypeIsComptimeInner( | ... | @@ -26662,7 +26517,7 @@ fn explainWhyTypeIsComptimeInner( |
| 26662 | => return, | 26517 | => return, |
| 26663 | | 26518 | |
| 26664 | .Opaque => { | 26519 | .Opaque => { |
| 26665 | try mod.errNoteNonLazy(src_loc, msg, "opaque type '{}' has undefined size", .{ty.fmt(sema.mod)}); | 26520 | try sema.errNote(src_loc, msg, "opaque type '{}' has undefined size", .{ty.fmt(sema.mod)}); |
| 26666 | }, | 26521 | }, |
| 26667 | | 26522 | |
| 26668 | .Array, .Vector => { | 26523 | .Array, .Vector => { |
| ... | @@ -26673,14 +26528,14 @@ fn explainWhyTypeIsComptimeInner( | ... | @@ -26673,14 +26528,14 @@ fn explainWhyTypeIsComptimeInner( |
| 26673 | if (elem_ty.zigTypeTag(mod) == .Fn) { | 26528 | if (elem_ty.zigTypeTag(mod) == .Fn) { |
| 26674 | const fn_info = mod.typeToFunc(elem_ty).?; | 26529 | const fn_info = mod.typeToFunc(elem_ty).?; |
| 26675 | if (fn_info.is_generic) { | 26530 | if (fn_info.is_generic) { |
| 26676 | try mod.errNoteNonLazy(src_loc, msg, "function is generic", .{}); | 26531 | try sema.errNote(src_loc, msg, "function is generic", .{}); |
| 26677 | } | 26532 | } |
| 26678 | switch (fn_info.cc) { | 26533 | switch (fn_info.cc) { |
| 26679 | .Inline => try mod.errNoteNonLazy(src_loc, msg, "function has inline calling convention", .{}), | 26534 | .Inline => try sema.errNote(src_loc, msg, "function has inline calling convention", .{}), |
| 26680 | else => {}, | 26535 | else => {}, |
| 26681 | } | 26536 | } |
| 26682 | if (Type.fromInterned(fn_info.return_type).comptimeOnly(mod)) { | 26537 | if (Type.fromInterned(fn_info.return_type).comptimeOnly(mod)) { |
| 26683 | try mod.errNoteNonLazy(src_loc, msg, "function has a comptime-only return type", .{}); | 26538 | try sema.errNote(src_loc, msg, "function has a comptime-only return type", .{}); |
| 26684 | } | 26539 | } |
| 26685 | return; | 26540 | return; |
| 26686 | } | 26541 | } |
| ... | @@ -26700,14 +26555,14 @@ fn explainWhyTypeIsComptimeInner( | ... | @@ -26700,14 +26555,14 @@ fn explainWhyTypeIsComptimeInner( |
| 26700 | if (mod.typeToStruct(ty)) |struct_type| { | 26555 | if (mod.typeToStruct(ty)) |struct_type| { |
| 26701 | for (0..struct_type.field_types.len) |i| { | 26556 | for (0..struct_type.field_types.len) |i| { |
| 26702 | const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[i]); | 26557 | const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[i]); |
| 26703 | const field_src_loc = mod.fieldSrcLoc(struct_type.decl.unwrap().?, .{ | 26558 | const field_src: LazySrcLoc = .{ |
| 26704 | .index = i, | 26559 | .base_node_inst = struct_type.zir_index.unwrap().?, |
| 26705 | .range = .type, | 26560 | .offset = .{ .container_field_type = @intCast(i) }, |
| 26706 | }); | 26561 | }; |
| 26707 | | 26562 | |
| 26708 | if (try sema.typeRequiresComptime(field_ty)) { | 26563 | if (try sema.typeRequiresComptime(field_ty)) { |
| 26709 | try mod.errNoteNonLazy(field_src_loc, msg, "struct requires comptime because of this field", .{}); | 26564 | try sema.errNote(field_src, msg, "struct requires comptime because of this field", .{}); |
| 26710 | try sema.explainWhyTypeIsComptimeInner(msg, field_src_loc, field_ty, type_set); | 26565 | try sema.explainWhyTypeIsComptimeInner(msg, field_src, field_ty, type_set); |
| 26711 | } | 26566 | } |
| 26712 | } | 26567 | } |
| 26713 | } | 26568 | } |
| ... | @@ -26720,14 +26575,14 @@ fn explainWhyTypeIsComptimeInner( | ... | @@ -26720,14 +26575,14 @@ fn explainWhyTypeIsComptimeInner( |
| 26720 | if (mod.typeToUnion(ty)) |union_obj| { | 26575 | if (mod.typeToUnion(ty)) |union_obj| { |
| 26721 | for (0..union_obj.field_types.len) |i| { | 26576 | for (0..union_obj.field_types.len) |i| { |
| 26722 | const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[i]); | 26577 | const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[i]); |
| 26723 | const field_src_loc = mod.fieldSrcLoc(union_obj.decl, .{ | 26578 | const field_src: LazySrcLoc = .{ |
| 26724 | .index = i, | 26579 | .base_node_inst = union_obj.zir_index, |
| 26725 | .range = .type, | 26580 | .offset = .{ .container_field_type = @intCast(i) }, |
| 26726 | }); | 26581 | }; |
| 26727 | | 26582 | |
| 26728 | if (try sema.typeRequiresComptime(field_ty)) { | 26583 | if (try sema.typeRequiresComptime(field_ty)) { |
| 26729 | try mod.errNoteNonLazy(field_src_loc, msg, "union requires comptime because of this field", .{}); | 26584 | try sema.errNote(field_src, msg, "union requires comptime because of this field", .{}); |
| 26730 | try sema.explainWhyTypeIsComptimeInner(msg, field_src_loc, field_ty, type_set); | 26585 | try sema.explainWhyTypeIsComptimeInner(msg, field_src, field_ty, type_set); |
| 26731 | } | 26586 | } |
| 26732 | } | 26587 | } |
| 26733 | } | 26588 | } |
| ... | @@ -26817,7 +26672,7 @@ fn validateExternType( | ... | @@ -26817,7 +26672,7 @@ fn validateExternType( |
| 26817 | fn explainWhyTypeIsNotExtern( | 26672 | fn explainWhyTypeIsNotExtern( |
| 26818 | sema: *Sema, | 26673 | sema: *Sema, |
| 26819 | msg: *Module.ErrorMsg, | 26674 | msg: *Module.ErrorMsg, |
| 26820 | src_loc: Module.SrcLoc, | 26675 | src_loc: LazySrcLoc, |
| 26821 | ty: Type, | 26676 | ty: Type, |
| 26822 | position: ExternPosition, | 26677 | position: ExternPosition, |
| 26823 | ) CompileError!void { | 26678 | ) CompileError!void { |
| ... | @@ -26842,55 +26697,55 @@ fn explainWhyTypeIsNotExtern( | ... | @@ -26842,55 +26697,55 @@ fn explainWhyTypeIsNotExtern( |
| 26842 | | 26697 | |
| 26843 | .Pointer => { | 26698 | .Pointer => { |
| 26844 | if (ty.isSlice(mod)) { | 26699 | if (ty.isSlice(mod)) { |
| 26845 | try mod.errNoteNonLazy(src_loc, msg, "slices have no guaranteed in-memory representation", .{}); | 26700 | try sema.errNote(src_loc, msg, "slices have no guaranteed in-memory representation", .{}); |
| 26846 | } else { | 26701 | } else { |
| 26847 | const pointee_ty = ty.childType(mod); | 26702 | const pointee_ty = ty.childType(mod); |
| 26848 | if (!ty.isConstPtr(mod) and pointee_ty.zigTypeTag(mod) == .Fn) { | 26703 | if (!ty.isConstPtr(mod) and pointee_ty.zigTypeTag(mod) == .Fn) { |
| 26849 | try mod.errNoteNonLazy(src_loc, msg, "pointer to extern function must be 'const'", .{}); | 26704 | try sema.errNote(src_loc, msg, "pointer to extern function must be 'const'", .{}); |
| 26850 | } else if (try sema.typeRequiresComptime(ty)) { | 26705 | } else if (try sema.typeRequiresComptime(ty)) { |
| 26851 | try mod.errNoteNonLazy(src_loc, msg, "pointer to comptime-only type '{}'", .{pointee_ty.fmt(sema.mod)}); | 26706 | try sema.errNote(src_loc, msg, "pointer to comptime-only type '{}'", .{pointee_ty.fmt(sema.mod)}); |
| 26852 | try sema.explainWhyTypeIsComptime(msg, src_loc, ty); | 26707 | try sema.explainWhyTypeIsComptime(msg, src_loc, ty); |
| 26853 | } | 26708 | } |
| 26854 | try sema.explainWhyTypeIsNotExtern(msg, src_loc, pointee_ty, .other); | 26709 | try sema.explainWhyTypeIsNotExtern(msg, src_loc, pointee_ty, .other); |
| 26855 | } | 26710 | } |
| 26856 | }, | 26711 | }, |
| 26857 | .Void => try mod.errNoteNonLazy(src_loc, msg, "'void' is a zero bit type; for C 'void' use 'anyopaque'", .{}), | 26712 | .Void => try sema.errNote(src_loc, msg, "'void' is a zero bit type; for C 'void' use 'anyopaque'", .{}), |
| 26858 | .NoReturn => try mod.errNoteNonLazy(src_loc, msg, "'noreturn' is only allowed as a return type", .{}), | 26713 | .NoReturn => try sema.errNote(src_loc, msg, "'noreturn' is only allowed as a return type", .{}), |
| 26859 | .Int => if (!std.math.isPowerOfTwo(ty.intInfo(mod).bits)) { | 26714 | .Int => if (!std.math.isPowerOfTwo(ty.intInfo(mod).bits)) { |
| 26860 | try mod.errNoteNonLazy(src_loc, msg, "only integers with 0 or power of two bits are extern compatible", .{}); | 26715 | try sema.errNote(src_loc, msg, "only integers with 0 or power of two bits are extern compatible", .{}); |
| 26861 | } else { | 26716 | } else { |
| 26862 | try mod.errNoteNonLazy(src_loc, msg, "only integers with 0, 8, 16, 32, 64 and 128 bits are extern compatible", .{}); | 26717 | try sema.errNote(src_loc, msg, "only integers with 0, 8, 16, 32, 64 and 128 bits are extern compatible", .{}); |
| 26863 | }, | 26718 | }, |
| 26864 | .Fn => { | 26719 | .Fn => { |
| 26865 | if (position != .other) { | 26720 | if (position != .other) { |
| 26866 | try mod.errNoteNonLazy(src_loc, msg, "type has no guaranteed in-memory representation", .{}); | 26721 | try sema.errNote(src_loc, msg, "type has no guaranteed in-memory representation", .{}); |
| 26867 | try mod.errNoteNonLazy(src_loc, msg, "use '*const ' to make a function pointer type", .{}); | 26722 | try sema.errNote(src_loc, msg, "use '*const ' to make a function pointer type", .{}); |
| 26868 | return; | 26723 | return; |
| 26869 | } | 26724 | } |
| 26870 | switch (ty.fnCallingConvention(mod)) { | 26725 | switch (ty.fnCallingConvention(mod)) { |
| 26871 | .Unspecified => try mod.errNoteNonLazy(src_loc, msg, "extern function must specify calling convention", .{}), | 26726 | .Unspecified => try sema.errNote(src_loc, msg, "extern function must specify calling convention", .{}), |
| 26872 | .Async => try mod.errNoteNonLazy(src_loc, msg, "async function cannot be extern", .{}), | 26727 | .Async => try sema.errNote(src_loc, msg, "async function cannot be extern", .{}), |
| 26873 | .Inline => try mod.errNoteNonLazy(src_loc, msg, "inline function cannot be extern", .{}), | 26728 | .Inline => try sema.errNote(src_loc, msg, "inline function cannot be extern", .{}), |
| 26874 | else => return, | 26729 | else => return, |
| 26875 | } | 26730 | } |
| 26876 | }, | 26731 | }, |
| 26877 | .Enum => { | 26732 | .Enum => { |
| 26878 | const tag_ty = ty.intTagType(mod); | 26733 | const tag_ty = ty.intTagType(mod); |
| 26879 | try mod.errNoteNonLazy(src_loc, msg, "enum tag type '{}' is not extern compatible", .{tag_ty.fmt(sema.mod)}); | 26734 | try sema.errNote(src_loc, msg, "enum tag type '{}' is not extern compatible", .{tag_ty.fmt(sema.mod)}); |
| 26880 | try sema.explainWhyTypeIsNotExtern(msg, src_loc, tag_ty, position); | 26735 | try sema.explainWhyTypeIsNotExtern(msg, src_loc, tag_ty, position); |
| 26881 | }, | 26736 | }, |
| 26882 | .Struct => try mod.errNoteNonLazy(src_loc, msg, "only extern structs and ABI sized packed structs are extern compatible", .{}), | 26737 | .Struct => try sema.errNote(src_loc, msg, "only extern structs and ABI sized packed structs are extern compatible", .{}), |
| 26883 | .Union => try mod.errNoteNonLazy(src_loc, msg, "only extern unions and ABI sized packed unions are extern compatible", .{}), | 26738 | .Union => try sema.errNote(src_loc, msg, "only extern unions and ABI sized packed unions are extern compatible", .{}), |
| 26884 | .Array => { | 26739 | .Array => { |
| 26885 | if (position == .ret_ty) { | 26740 | if (position == .ret_ty) { |
| 26886 | return mod.errNoteNonLazy(src_loc, msg, "arrays are not allowed as a return type", .{}); | 26741 | return sema.errNote(src_loc, msg, "arrays are not allowed as a return type", .{}); |
| 26887 | } else if (position == .param_ty) { | 26742 | } else if (position == .param_ty) { |
| 26888 | return mod.errNoteNonLazy(src_loc, msg, "arrays are not allowed as a parameter type", .{}); | 26743 | return sema.errNote(src_loc, msg, "arrays are not allowed as a parameter type", .{}); |
| 26889 | } | 26744 | } |
| 26890 | try sema.explainWhyTypeIsNotExtern(msg, src_loc, ty.elemType2(mod), .element); | 26745 | try sema.explainWhyTypeIsNotExtern(msg, src_loc, ty.elemType2(mod), .element); |
| 26891 | }, | 26746 | }, |
| 26892 | .Vector => try sema.explainWhyTypeIsNotExtern(msg, src_loc, ty.elemType2(mod), .element), | 26747 | .Vector => try sema.explainWhyTypeIsNotExtern(msg, src_loc, ty.elemType2(mod), .element), |
| 26893 | .Optional => try mod.errNoteNonLazy(src_loc, msg, "only pointer like optionals are extern compatible", .{}), | 26748 | .Optional => try sema.errNote(src_loc, msg, "only pointer like optionals are extern compatible", .{}), |
| 26894 | } | 26749 | } |
| 26895 | } | 26750 | } |
| 26896 | | 26751 | |
| ... | @@ -26933,7 +26788,7 @@ fn validatePackedType(sema: *Sema, ty: Type) !bool { | ... | @@ -26933,7 +26788,7 @@ fn validatePackedType(sema: *Sema, ty: Type) !bool { |
| 26933 | fn explainWhyTypeIsNotPacked( | 26788 | fn explainWhyTypeIsNotPacked( |
| 26934 | sema: *Sema, | 26789 | sema: *Sema, |
| 26935 | msg: *Module.ErrorMsg, | 26790 | msg: *Module.ErrorMsg, |
| 26936 | src_loc: Module.SrcLoc, | 26791 | src_loc: LazySrcLoc, |
| 26937 | ty: Type, | 26792 | ty: Type, |
| 26938 | ) CompileError!void { | 26793 | ) CompileError!void { |
| 26939 | const mod = sema.mod; | 26794 | const mod = sema.mod; |
| ... | @@ -26959,19 +26814,19 @@ fn explainWhyTypeIsNotPacked( | ... | @@ -26959,19 +26814,19 @@ fn explainWhyTypeIsNotPacked( |
| 26959 | .AnyFrame, | 26814 | .AnyFrame, |
| 26960 | .Optional, | 26815 | .Optional, |
| 26961 | .Array, | 26816 | .Array, |
| 26962 | => try mod.errNoteNonLazy(src_loc, msg, "type has no guaranteed in-memory representation", .{}), | 26817 | => try sema.errNote(src_loc, msg, "type has no guaranteed in-memory representation", .{}), |
| 26963 | .Pointer => if (ty.isSlice(mod)) { | 26818 | .Pointer => if (ty.isSlice(mod)) { |
| 26964 | try mod.errNoteNonLazy(src_loc, msg, "slices have no guaranteed in-memory representation", .{}); | 26819 | try sema.errNote(src_loc, msg, "slices have no guaranteed in-memory representation", .{}); |
| 26965 | } else { | 26820 | } else { |
| 26966 | try mod.errNoteNonLazy(src_loc, msg, "comptime-only pointer has no guaranteed in-memory representation", .{}); | 26821 | try sema.errNote(src_loc, msg, "comptime-only pointer has no guaranteed in-memory representation", .{}); |
| 26967 | try sema.explainWhyTypeIsComptime(msg, src_loc, ty); | 26822 | try sema.explainWhyTypeIsComptime(msg, src_loc, ty); |
| 26968 | }, | 26823 | }, |
| 26969 | .Fn => { | 26824 | .Fn => { |
| 26970 | try mod.errNoteNonLazy(src_loc, msg, "type has no guaranteed in-memory representation", .{}); | 26825 | try sema.errNote(src_loc, msg, "type has no guaranteed in-memory representation", .{}); |
| 26971 | try mod.errNoteNonLazy(src_loc, msg, "use '*const ' to make a function pointer type", .{}); | 26826 | try sema.errNote(src_loc, msg, "use '*const ' to make a function pointer type", .{}); |
| 26972 | }, | 26827 | }, |
| 26973 | .Struct => try mod.errNoteNonLazy(src_loc, msg, "only packed structs layout are allowed in packed types", .{}), | 26828 | .Struct => try sema.errNote(src_loc, msg, "only packed structs layout are allowed in packed types", .{}), |
| 26974 | .Union => try mod.errNoteNonLazy(src_loc, msg, "only packed unions layout are allowed in packed types", .{}), | 26829 | .Union => try sema.errNote(src_loc, msg, "only packed unions layout are allowed in packed types", .{}), |
| 26975 | } | 26830 | } |
| 26976 | } | 26831 | } |
| 26977 | | 26832 | |
| ... | @@ -27022,11 +26877,11 @@ fn preparePanicId(sema: *Sema, block: *Block, panic_id: Module.PanicId) !InternP | ... | @@ -27022,11 +26877,11 @@ fn preparePanicId(sema: *Sema, block: *Block, panic_id: Module.PanicId) !InternP |
| 27022 | const panic_messages_ty = try sema.getBuiltinType("panic_messages"); | 26877 | const panic_messages_ty = try sema.getBuiltinType("panic_messages"); |
| 27023 | const msg_decl_index = (sema.namespaceLookup( | 26878 | const msg_decl_index = (sema.namespaceLookup( |
| 27024 | block, | 26879 | block, |
| 27025 | .unneeded, | 26880 | LazySrcLoc.unneeded, |
| 27026 | panic_messages_ty.getNamespaceIndex(mod), | 26881 | panic_messages_ty.getNamespaceIndex(mod), |
| 27027 | try mod.intern_pool.getOrPutString(gpa, @tagName(panic_id), .no_embedded_nulls), | 26882 | try mod.intern_pool.getOrPutString(gpa, @tagName(panic_id), .no_embedded_nulls), |
| 27028 | ) catch |err| switch (err) { | 26883 | ) catch |err| switch (err) { |
| 27029 | error.AnalysisFail, error.NeededSourceLocation => @panic("std.builtin.panic_messages is corrupt"), | 26884 | error.AnalysisFail => @panic("std.builtin.panic_messages is corrupt"), |
| 27030 | error.GenericPoison, error.ComptimeReturn, error.ComptimeBreak => unreachable, | 26885 | error.GenericPoison, error.ComptimeReturn, error.ComptimeBreak => unreachable, |
| 27031 | error.OutOfMemory => |e| return e, | 26886 | error.OutOfMemory => |e| return e, |
| 27032 | }).?; | 26887 | }).?; |
| ... | @@ -27053,6 +26908,7 @@ fn addSafetyCheck( | ... | @@ -27053,6 +26908,7 @@ fn addSafetyCheck( |
| 27053 | .instructions = .{}, | 26908 | .instructions = .{}, |
| 27054 | .inlining = parent_block.inlining, | 26909 | .inlining = parent_block.inlining, |
| 27055 | .is_comptime = false, | 26910 | .is_comptime = false, |
| | 26911 | .src_base_inst = parent_block.src_base_inst, |
| 27056 | }; | 26912 | }; |
| 27057 | | 26913 | |
| 27058 | defer fail_block.instructions.deinit(gpa); | 26914 | defer fail_block.instructions.deinit(gpa); |
| ... | @@ -27161,6 +27017,7 @@ fn panicUnwrapError( | ... | @@ -27161,6 +27017,7 @@ fn panicUnwrapError( |
| 27161 | .instructions = .{}, | 27017 | .instructions = .{}, |
| 27162 | .inlining = parent_block.inlining, | 27018 | .inlining = parent_block.inlining, |
| 27163 | .is_comptime = false, | 27019 | .is_comptime = false, |
| | 27020 | .src_base_inst = parent_block.src_base_inst, |
| 27164 | }; | 27021 | }; |
| 27165 | | 27022 | |
| 27166 | defer fail_block.instructions.deinit(gpa); | 27023 | defer fail_block.instructions.deinit(gpa); |
| ... | @@ -27277,6 +27134,7 @@ fn safetyCheckFormatted( | ... | @@ -27277,6 +27134,7 @@ fn safetyCheckFormatted( |
| 27277 | .instructions = .{}, | 27134 | .instructions = .{}, |
| 27278 | .inlining = parent_block.inlining, | 27135 | .inlining = parent_block.inlining, |
| 27279 | .is_comptime = false, | 27136 | .is_comptime = false, |
| | 27137 | .src_base_inst = parent_block.src_base_inst, |
| 27280 | }; | 27138 | }; |
| 27281 | | 27139 | |
| 27282 | defer fail_block.instructions.deinit(gpa); | 27140 | defer fail_block.instructions.deinit(gpa); |
| ... | @@ -27300,13 +27158,11 @@ fn emitBackwardBranch(sema: *Sema, block: *Block, src: LazySrcLoc) !void { | ... | @@ -27300,13 +27158,11 @@ fn emitBackwardBranch(sema: *Sema, block: *Block, src: LazySrcLoc) !void { |
| 27300 | sema.branch_count += 1; | 27158 | sema.branch_count += 1; |
| 27301 | if (sema.branch_count > sema.branch_quota) { | 27159 | if (sema.branch_count > sema.branch_quota) { |
| 27302 | const msg = try sema.errMsg( | 27160 | const msg = try sema.errMsg( |
| 27303 | block, | | |
| 27304 | src, | 27161 | src, |
| 27305 | "evaluation exceeded {d} backwards branches", | 27162 | "evaluation exceeded {d} backwards branches", |
| 27306 | .{sema.branch_quota}, | 27163 | .{sema.branch_quota}, |
| 27307 | ); | 27164 | ); |
| 27308 | try sema.errNote( | 27165 | try sema.errNote( |
| 27309 | block, | | |
| 27310 | src, | 27166 | src, |
| 27311 | msg, | 27167 | msg, |
| 27312 | "use @setEvalBranchQuota() to raise the branch limit from {d}", | 27168 | "use @setEvalBranchQuota() to raise the branch limit from {d}", |
| ... | @@ -27472,10 +27328,10 @@ fn fieldVal( | ... | @@ -27472,10 +27328,10 @@ fn fieldVal( |
| 27472 | }, | 27328 | }, |
| 27473 | else => { | 27329 | else => { |
| 27474 | const msg = msg: { | 27330 | const msg = msg: { |
| 27475 | const msg = try sema.errMsg(block, src, "type '{}' has no members", .{child_type.fmt(mod)}); | 27331 | const msg = try sema.errMsg(src, "type '{}' has no members", .{child_type.fmt(mod)}); |
| 27476 | errdefer msg.destroy(sema.gpa); | 27332 | errdefer msg.destroy(sema.gpa); |
| 27477 | if (child_type.isSlice(mod)) try sema.errNote(block, src, msg, "slice values have 'len' and 'ptr' members", .{}); | 27333 | if (child_type.isSlice(mod)) try sema.errNote(src, msg, "slice values have 'len' and 'ptr' members", .{}); |
| 27478 | if (child_type.zigTypeTag(mod) == .Array) try sema.errNote(block, src, msg, "array values have 'len' member", .{}); | 27334 | if (child_type.zigTypeTag(mod) == .Array) try sema.errNote(src, msg, "array values have 'len' member", .{}); |
| 27479 | break :msg msg; | 27335 | break :msg msg; |
| 27480 | }; | 27336 | }; |
| 27481 | return sema.failWithOwnedErrorMsg(block, msg); | 27337 | return sema.failWithOwnedErrorMsg(block, msg); |
| ... | @@ -27633,7 +27489,7 @@ fn fieldPtr( | ... | @@ -27633,7 +27489,7 @@ fn fieldPtr( |
| 27633 | } | 27489 | } |
| 27634 | }, | 27490 | }, |
| 27635 | .Type => { | 27491 | .Type => { |
| 27636 | _ = try sema.resolveConstDefinedValue(block, .unneeded, object_ptr, undefined); | 27492 | _ = try sema.resolveConstDefinedValue(block, LazySrcLoc.unneeded, object_ptr, undefined); |
| 27637 | const result = try sema.analyzeLoad(block, src, object_ptr, object_ptr_src); | 27493 | const result = try sema.analyzeLoad(block, src, object_ptr, object_ptr_src); |
| 27638 | const inner = if (is_pointer_to) | 27494 | const inner = if (is_pointer_to) |
| 27639 | try sema.analyzeLoad(block, src, result, object_ptr_src) | 27495 | try sema.analyzeLoad(block, src, result, object_ptr_src) |
| ... | @@ -27885,7 +27741,7 @@ fn fieldCallBind( | ... | @@ -27885,7 +27741,7 @@ fn fieldCallBind( |
| 27885 | }; | 27741 | }; |
| 27886 | | 27742 | |
| 27887 | const msg = msg: { | 27743 | const msg = msg: { |
| 27888 | const msg = try sema.errMsg(block, src, "no field or member function named '{}' in '{}'", .{ | 27744 | const msg = try sema.errMsg(src, "no field or member function named '{}' in '{}'", .{ |
| 27889 | field_name.fmt(ip), | 27745 | field_name.fmt(ip), |
| 27890 | concrete_ty.fmt(mod), | 27746 | concrete_ty.fmt(mod), |
| 27891 | }); | 27747 | }); |
| ... | @@ -27893,10 +27749,13 @@ fn fieldCallBind( | ... | @@ -27893,10 +27749,13 @@ fn fieldCallBind( |
| 27893 | try sema.addDeclaredHereNote(msg, concrete_ty); | 27749 | try sema.addDeclaredHereNote(msg, concrete_ty); |
| 27894 | if (found_decl) |decl_idx| { | 27750 | if (found_decl) |decl_idx| { |
| 27895 | const decl = mod.declPtr(decl_idx); | 27751 | const decl = mod.declPtr(decl_idx); |
| 27896 | try mod.errNoteNonLazy(decl.srcLoc(mod), msg, "'{}' is not a member function", .{field_name.fmt(ip)}); | 27752 | try sema.errNote(.{ |
| | 27753 | .base_node_inst = decl.zir_decl_index.unwrap().?, |
| | 27754 | .offset = LazySrcLoc.Offset.nodeOffset(0), |
| | 27755 | }, msg, "'{}' is not a member function", .{field_name.fmt(ip)}); |
| 27897 | } | 27756 | } |
| 27898 | if (concrete_ty.zigTypeTag(mod) == .ErrorUnion) { | 27757 | if (concrete_ty.zigTypeTag(mod) == .ErrorUnion) { |
| 27899 | try sema.errNote(block, src, msg, "consider using 'try', 'catch', or 'if'", .{}); | 27758 | try sema.errNote(src, msg, "consider using 'try', 'catch', or 'if'", .{}); |
| 27900 | } | 27759 | } |
| 27901 | break :msg msg; | 27760 | break :msg msg; |
| 27902 | }; | 27761 | }; |
| ... | @@ -27954,11 +27813,14 @@ fn namespaceLookup( | ... | @@ -27954,11 +27813,14 @@ fn namespaceLookup( |
| 27954 | const decl = mod.declPtr(decl_index); | 27813 | const decl = mod.declPtr(decl_index); |
| 27955 | if (!decl.is_pub and decl.getFileScope(mod) != block.getFileScope(mod)) { | 27814 | if (!decl.is_pub and decl.getFileScope(mod) != block.getFileScope(mod)) { |
| 27956 | const msg = msg: { | 27815 | const msg = msg: { |
| 27957 | const msg = try sema.errMsg(block, src, "'{}' is not marked 'pub'", .{ | 27816 | const msg = try sema.errMsg(src, "'{}' is not marked 'pub'", .{ |
| 27958 | decl_name.fmt(&mod.intern_pool), | 27817 | decl_name.fmt(&mod.intern_pool), |
| 27959 | }); | 27818 | }); |
| 27960 | errdefer msg.destroy(gpa); | 27819 | errdefer msg.destroy(gpa); |
| 27961 | try mod.errNoteNonLazy(decl.srcLoc(mod), msg, "declared here", .{}); | 27820 | try sema.errNote(.{ |
| | 27821 | .base_node_inst = decl.zir_decl_index.unwrap().?, |
| | 27822 | .offset = LazySrcLoc.Offset.nodeOffset(0), |
| | 27823 | }, msg, "declared here", .{}); |
| 27962 | break :msg msg; | 27824 | break :msg msg; |
| 27963 | }; | 27825 | }; |
| 27964 | return sema.failWithOwnedErrorMsg(block, msg); | 27826 | return sema.failWithOwnedErrorMsg(block, msg); |
| ... | @@ -28023,7 +27885,7 @@ fn structFieldPtr( | ... | @@ -28023,7 +27885,7 @@ fn structFieldPtr( |
| 28023 | const struct_type = mod.typeToStruct(struct_ty).?; | 27885 | const struct_type = mod.typeToStruct(struct_ty).?; |
| 28024 | | 27886 | |
| 28025 | const field_index = struct_type.nameIndex(ip, field_name) orelse | 27887 | const field_index = struct_type.nameIndex(ip, field_name) orelse |
| 28026 | return sema.failWithBadStructFieldAccess(block, struct_type, field_name_src, field_name); | 27888 | return sema.failWithBadStructFieldAccess(block, struct_ty, struct_type, field_name_src, field_name); |
| 28027 | | 27889 | |
| 28028 | return sema.structFieldPtrByIndex(block, src, struct_ptr, field_index, field_name_src, struct_ty, initializing); | 27890 | return sema.structFieldPtrByIndex(block, src, struct_ptr, field_index, field_name_src, struct_ty, initializing); |
| 28029 | } | 27891 | } |
| ... | @@ -28138,7 +28000,7 @@ fn structFieldVal( | ... | @@ -28138,7 +28000,7 @@ fn structFieldVal( |
| 28138 | return sema.tupleFieldVal(block, src, struct_byval, field_name, field_name_src, struct_ty); | 28000 | return sema.tupleFieldVal(block, src, struct_byval, field_name, field_name_src, struct_ty); |
| 28139 | | 28001 | |
| 28140 | const field_index = struct_type.nameIndex(ip, field_name) orelse | 28002 | const field_index = struct_type.nameIndex(ip, field_name) orelse |
| 28141 | return sema.failWithBadStructFieldAccess(block, struct_type, field_name_src, field_name); | 28003 | return sema.failWithBadStructFieldAccess(block, struct_ty, struct_type, field_name_src, field_name); |
| 28142 | if (struct_type.fieldIsComptime(ip, field_index)) { | 28004 | if (struct_type.fieldIsComptime(ip, field_index)) { |
| 28143 | try sema.resolveStructFieldInits(struct_ty); | 28005 | try sema.resolveStructFieldInits(struct_ty); |
| 28144 | return Air.internedToRef(struct_type.field_inits.get(ip)[field_index]); | 28006 | return Air.internedToRef(struct_type.field_inits.get(ip)[field_index]); |
| ... | @@ -28291,7 +28153,7 @@ fn unionFieldPtr( | ... | @@ -28291,7 +28153,7 @@ fn unionFieldPtr( |
| 28291 | | 28153 | |
| 28292 | if (initializing and field_ty.zigTypeTag(mod) == .NoReturn) { | 28154 | if (initializing and field_ty.zigTypeTag(mod) == .NoReturn) { |
| 28293 | const msg = msg: { | 28155 | const msg = msg: { |
| 28294 | const msg = try sema.errMsg(block, src, "cannot initialize 'noreturn' field of union", .{}); | 28156 | const msg = try sema.errMsg(src, "cannot initialize 'noreturn' field of union", .{}); |
| 28295 | errdefer msg.destroy(sema.gpa); | 28157 | errdefer msg.destroy(sema.gpa); |
| 28296 | | 28158 | |
| 28297 | try sema.addFieldErrNote(union_ty, field_index, msg, "field '{}' declared here", .{ | 28159 | try sema.addFieldErrNote(union_ty, field_index, msg, "field '{}' declared here", .{ |
| ... | @@ -28324,7 +28186,7 @@ fn unionFieldPtr( | ... | @@ -28324,7 +28186,7 @@ fn unionFieldPtr( |
| 28324 | const msg = msg: { | 28186 | const msg = msg: { |
| 28325 | const active_index = Type.fromInterned(union_obj.enum_tag_ty).enumTagFieldIndex(Value.fromInterned(un.tag), mod).?; | 28187 | const active_index = Type.fromInterned(union_obj.enum_tag_ty).enumTagFieldIndex(Value.fromInterned(un.tag), mod).?; |
| 28326 | const active_field_name = Type.fromInterned(union_obj.enum_tag_ty).enumFieldName(active_index, mod); | 28188 | const active_field_name = Type.fromInterned(union_obj.enum_tag_ty).enumFieldName(active_index, mod); |
| 28327 | const msg = try sema.errMsg(block, src, "access of union field '{}' while field '{}' is active", .{ | 28189 | const msg = try sema.errMsg(src, "access of union field '{}' while field '{}' is active", .{ |
| 28328 | field_name.fmt(ip), | 28190 | field_name.fmt(ip), |
| 28329 | active_field_name.fmt(ip), | 28191 | active_field_name.fmt(ip), |
| 28330 | }); | 28192 | }); |
| ... | @@ -28392,7 +28254,7 @@ fn unionFieldVal( | ... | @@ -28392,7 +28254,7 @@ fn unionFieldVal( |
| 28392 | const msg = msg: { | 28254 | const msg = msg: { |
| 28393 | const active_index = Type.fromInterned(union_obj.enum_tag_ty).enumTagFieldIndex(Value.fromInterned(un.tag), zcu).?; | 28255 | const active_index = Type.fromInterned(union_obj.enum_tag_ty).enumTagFieldIndex(Value.fromInterned(un.tag), zcu).?; |
| 28394 | const active_field_name = Type.fromInterned(union_obj.enum_tag_ty).enumFieldName(active_index, zcu); | 28256 | const active_field_name = Type.fromInterned(union_obj.enum_tag_ty).enumFieldName(active_index, zcu); |
| 28395 | const msg = try sema.errMsg(block, src, "access of union field '{}' while field '{}' is active", .{ | 28257 | const msg = try sema.errMsg(src, "access of union field '{}' while field '{}' is active", .{ |
| 28396 | field_name.fmt(ip), active_field_name.fmt(ip), | 28258 | field_name.fmt(ip), active_field_name.fmt(ip), |
| 28397 | }); | 28259 | }); |
| 28398 | errdefer msg.destroy(sema.gpa); | 28260 | errdefer msg.destroy(sema.gpa); |
| ... | @@ -28615,15 +28477,13 @@ fn validateRuntimeElemAccess( | ... | @@ -28615,15 +28477,13 @@ fn validateRuntimeElemAccess( |
| 28615 | if (try sema.typeRequiresComptime(elem_ty)) { | 28477 | if (try sema.typeRequiresComptime(elem_ty)) { |
| 28616 | const msg = msg: { | 28478 | const msg = msg: { |
| 28617 | const msg = try sema.errMsg( | 28479 | const msg = try sema.errMsg( |
| 28618 | block, | | |
| 28619 | elem_index_src, | 28480 | elem_index_src, |
| 28620 | "values of type '{}' must be comptime-known, but index value is runtime-known", | 28481 | "values of type '{}' must be comptime-known, but index value is runtime-known", |
| 28621 | .{parent_ty.fmt(mod)}, | 28482 | .{parent_ty.fmt(mod)}, |
| 28622 | ); | 28483 | ); |
| 28623 | errdefer msg.destroy(sema.gpa); | 28484 | errdefer msg.destroy(sema.gpa); |
| 28624 | | 28485 | |
| 28625 | const src_decl = mod.declPtr(block.src_decl); | 28486 | try sema.explainWhyTypeIsComptime(msg, parent_src, parent_ty); |
| 28626 | try sema.explainWhyTypeIsComptime(msg, src_decl.toSrcLoc(parent_src, mod), parent_ty); | | |
| 28627 | | 28487 | |
| 28628 | break :msg msg; | 28488 | break :msg msg; |
| 28629 | }; | 28489 | }; |
| ... | @@ -29011,21 +28871,18 @@ const CoerceOpts = struct { | ... | @@ -29011,21 +28871,18 @@ const CoerceOpts = struct { |
| 29011 | func_inst: Air.Inst.Ref = .none, | 28871 | func_inst: Air.Inst.Ref = .none, |
| 29012 | param_i: u32 = undefined, | 28872 | param_i: u32 = undefined, |
| 29013 | | 28873 | |
| 29014 | fn get(info: @This(), sema: *Sema) !?Module.SrcLoc { | 28874 | fn get(info: @This(), sema: *Sema) !?LazySrcLoc { |
| 29015 | if (info.func_inst == .none) return null; | 28875 | if (info.func_inst == .none) return null; |
| 29016 | const mod = sema.mod; | 28876 | const fn_decl = try sema.funcDeclSrc(info.func_inst) orelse return null; |
| 29017 | const fn_decl = (try sema.funcDeclSrc(info.func_inst)) orelse return null; | 28877 | return .{ |
| 29018 | const param_src = Module.paramSrc(0, mod, fn_decl, info.param_i); | 28878 | .base_node_inst = fn_decl.zir_decl_index.unwrap().?, |
| 29019 | if (param_src == .node_offset_param) { | 28879 | .offset = .{ .fn_proto_param_type = .{ |
| 29020 | return Module.SrcLoc{ | 28880 | .fn_proto_node_offset = 0, |
| 29021 | .file_scope = fn_decl.getFileScope(mod), | 28881 | .param_index = info.param_i, |
| 29022 | .parent_decl_node = fn_decl.src_node, | 28882 | } }, |
| 29023 | .lazy = LazySrcLoc.nodeOffset(param_src.node_offset_param), | 28883 | }; |
| 29024 | }; | | |
| 29025 | } | | |
| 29026 | return fn_decl.toSrcLoc(param_src, mod); | | |
| 29027 | } | 28884 | } |
| 29028 | } = .{}, | 28885 | } = .{ .func_inst = .none, .param_i = undefined }, |
| 29029 | }; | 28886 | }; |
| 29030 | | 28887 | |
| 29031 | fn coerceExtra( | 28888 | fn coerceExtra( |
| ... | @@ -29118,7 +28975,7 @@ fn coerceExtra( | ... | @@ -29118,7 +28975,7 @@ fn coerceExtra( |
| 29118 | | 28975 | |
| 29119 | // Function body to function pointer. | 28976 | // Function body to function pointer. |
| 29120 | if (inst_ty.zigTypeTag(zcu) == .Fn) { | 28977 | if (inst_ty.zigTypeTag(zcu) == .Fn) { |
| 29121 | const fn_val = try sema.resolveConstDefinedValue(block, .unneeded, inst, undefined); | 28978 | const fn_val = try sema.resolveConstDefinedValue(block, LazySrcLoc.unneeded, inst, undefined); |
| 29122 | const fn_decl = fn_val.pointerDecl(zcu).?; | 28979 | const fn_decl = fn_val.pointerDecl(zcu).?; |
| 29123 | const inst_as_ptr = try sema.analyzeDeclRef(fn_decl); | 28980 | const inst_as_ptr = try sema.analyzeDeclRef(fn_decl); |
| 29124 | return sema.coerce(block, dest_ty, inst_as_ptr, inst_src); | 28981 | return sema.coerce(block, dest_ty, inst_as_ptr, inst_src); |
| ... | @@ -29366,9 +29223,9 @@ fn coerceExtra( | ... | @@ -29366,9 +29223,9 @@ fn coerceExtra( |
| 29366 | // pointer to tuple to slice | 29223 | // pointer to tuple to slice |
| 29367 | if (!dest_info.flags.is_const) { | 29224 | if (!dest_info.flags.is_const) { |
| 29368 | const err_msg = err_msg: { | 29225 | const err_msg = err_msg: { |
| 29369 | const err_msg = try sema.errMsg(block, inst_src, "cannot cast pointer to tuple to '{}'", .{dest_ty.fmt(zcu)}); | 29226 | const err_msg = try sema.errMsg(inst_src, "cannot cast pointer to tuple to '{}'", .{dest_ty.fmt(zcu)}); |
| 29370 | errdefer err_msg.destroy(sema.gpa); | 29227 | errdefer err_msg.destroy(sema.gpa); |
| 29371 | try sema.errNote(block, dest_ty_src, err_msg, "pointers to tuples can only coerce to constant pointers", .{}); | 29228 | try sema.errNote(dest_ty_src, err_msg, "pointers to tuples can only coerce to constant pointers", .{}); |
| 29372 | break :err_msg err_msg; | 29229 | break :err_msg err_msg; |
| 29373 | }; | 29230 | }; |
| 29374 | return sema.failWithOwnedErrorMsg(block, err_msg); | 29231 | return sema.failWithOwnedErrorMsg(block, err_msg); |
| ... | @@ -29455,7 +29312,7 @@ fn coerceExtra( | ... | @@ -29455,7 +29312,7 @@ fn coerceExtra( |
| 29455 | }, | 29312 | }, |
| 29456 | .Float, .ComptimeFloat => switch (inst_ty.zigTypeTag(zcu)) { | 29313 | .Float, .ComptimeFloat => switch (inst_ty.zigTypeTag(zcu)) { |
| 29457 | .ComptimeFloat => { | 29314 | .ComptimeFloat => { |
| 29458 | const val = try sema.resolveConstDefinedValue(block, .unneeded, inst, undefined); | 29315 | const val = try sema.resolveConstDefinedValue(block, LazySrcLoc.unneeded, inst, undefined); |
| 29459 | const result_val = try val.floatCast(dest_ty, zcu); | 29316 | const result_val = try val.floatCast(dest_ty, zcu); |
| 29460 | return Air.internedToRef(result_val.toIntern()); | 29317 | return Air.internedToRef(result_val.toIntern()); |
| 29461 | }, | 29318 | }, |
| ... | @@ -29514,7 +29371,7 @@ fn coerceExtra( | ... | @@ -29514,7 +29371,7 @@ fn coerceExtra( |
| 29514 | .Enum => switch (inst_ty.zigTypeTag(zcu)) { | 29371 | .Enum => switch (inst_ty.zigTypeTag(zcu)) { |
| 29515 | .EnumLiteral => { | 29372 | .EnumLiteral => { |
| 29516 | // enum literal to enum | 29373 | // enum literal to enum |
| 29517 | const val = try sema.resolveConstDefinedValue(block, .unneeded, inst, undefined); | 29374 | const val = try sema.resolveConstDefinedValue(block, LazySrcLoc.unneeded, inst, undefined); |
| 29518 | const string = zcu.intern_pool.indexToKey(val.toIntern()).enum_literal; | 29375 | const string = zcu.intern_pool.indexToKey(val.toIntern()).enum_literal; |
| 29519 | const field_index = dest_ty.enumFieldIndex(string, zcu) orelse { | 29376 | const field_index = dest_ty.enumFieldIndex(string, zcu) orelse { |
| 29520 | return sema.fail(block, inst_src, "no field named '{}' in enum '{}'", .{ | 29377 | return sema.fail(block, inst_src, "no field named '{}' in enum '{}'", .{ |
| ... | @@ -29648,54 +29505,58 @@ fn coerceExtra( | ... | @@ -29648,54 +29505,58 @@ fn coerceExtra( |
| 29648 | | 29505 | |
| 29649 | if (opts.is_ret and dest_ty.zigTypeTag(zcu) == .NoReturn) { | 29506 | if (opts.is_ret and dest_ty.zigTypeTag(zcu) == .NoReturn) { |
| 29650 | const msg = msg: { | 29507 | const msg = msg: { |
| 29651 | const msg = try sema.errMsg(block, inst_src, "function declared 'noreturn' returns", .{}); | 29508 | const msg = try sema.errMsg(inst_src, "function declared 'noreturn' returns", .{}); |
| 29652 | errdefer msg.destroy(sema.gpa); | 29509 | errdefer msg.destroy(sema.gpa); |
| 29653 | | 29510 | |
| 29654 | const ret_ty_src: LazySrcLoc = .{ .node_offset_fn_type_ret_ty = 0 }; | 29511 | const ret_ty_src: LazySrcLoc = .{ |
| 29655 | const src_decl = zcu.funcOwnerDeclPtr(sema.func_index); | 29512 | .base_node_inst = zcu.funcOwnerDeclPtr(sema.func_index).zir_decl_index.unwrap().?, |
| 29656 | try zcu.errNoteNonLazy(src_decl.toSrcLoc(ret_ty_src, zcu), msg, "'noreturn' declared here", .{}); | 29513 | .offset = .{ .node_offset_fn_type_ret_ty = 0 }, |
| | 29514 | }; |
| | 29515 | try sema.errNote(ret_ty_src, msg, "'noreturn' declared here", .{}); |
| 29657 | break :msg msg; | 29516 | break :msg msg; |
| 29658 | }; | 29517 | }; |
| 29659 | return sema.failWithOwnedErrorMsg(block, msg); | 29518 | return sema.failWithOwnedErrorMsg(block, msg); |
| 29660 | } | 29519 | } |
| 29661 | | 29520 | |
| 29662 | const msg = msg: { | 29521 | const msg = msg: { |
| 29663 | const msg = try sema.errMsg(block, inst_src, "expected type '{}', found '{}'", .{ dest_ty.fmt(zcu), inst_ty.fmt(zcu) }); | 29522 | const msg = try sema.errMsg(inst_src, "expected type '{}', found '{}'", .{ dest_ty.fmt(zcu), inst_ty.fmt(zcu) }); |
| 29664 | errdefer msg.destroy(sema.gpa); | 29523 | errdefer msg.destroy(sema.gpa); |
| 29665 | | 29524 | |
| 29666 | // E!T to T | 29525 | // E!T to T |
| 29667 | if (inst_ty.zigTypeTag(zcu) == .ErrorUnion and | 29526 | if (inst_ty.zigTypeTag(zcu) == .ErrorUnion and |
| 29668 | (try sema.coerceInMemoryAllowed(block, inst_ty.errorUnionPayload(zcu), dest_ty, false, target, dest_ty_src, inst_src)) == .ok) | 29527 | (try sema.coerceInMemoryAllowed(block, inst_ty.errorUnionPayload(zcu), dest_ty, false, target, dest_ty_src, inst_src)) == .ok) |
| 29669 | { | 29528 | { |
| 29670 | try sema.errNote(block, inst_src, msg, "cannot convert error union to payload type", .{}); | 29529 | try sema.errNote(inst_src, msg, "cannot convert error union to payload type", .{}); |
| 29671 | try sema.errNote(block, inst_src, msg, "consider using 'try', 'catch', or 'if'", .{}); | 29530 | try sema.errNote(inst_src, msg, "consider using 'try', 'catch', or 'if'", .{}); |
| 29672 | } | 29531 | } |
| 29673 | | 29532 | |
| 29674 | // ?T to T | 29533 | // ?T to T |
| 29675 | if (inst_ty.zigTypeTag(zcu) == .Optional and | 29534 | if (inst_ty.zigTypeTag(zcu) == .Optional and |
| 29676 | (try sema.coerceInMemoryAllowed(block, inst_ty.optionalChild(zcu), dest_ty, false, target, dest_ty_src, inst_src)) == .ok) | 29535 | (try sema.coerceInMemoryAllowed(block, inst_ty.optionalChild(zcu), dest_ty, false, target, dest_ty_src, inst_src)) == .ok) |
| 29677 | { | 29536 | { |
| 29678 | try sema.errNote(block, inst_src, msg, "cannot convert optional to payload type", .{}); | 29537 | try sema.errNote(inst_src, msg, "cannot convert optional to payload type", .{}); |
| 29679 | try sema.errNote(block, inst_src, msg, "consider using '.?', 'orelse', or 'if'", .{}); | 29538 | try sema.errNote(inst_src, msg, "consider using '.?', 'orelse', or 'if'", .{}); |
| 29680 | } | 29539 | } |
| 29681 | | 29540 | |
| 29682 | try in_memory_result.report(sema, block, inst_src, msg); | 29541 | try in_memory_result.report(sema, inst_src, msg); |
| 29683 | | 29542 | |
| 29684 | // Add notes about function return type | 29543 | // Add notes about function return type |
| 29685 | if (opts.is_ret and | 29544 | if (opts.is_ret and |
| 29686 | zcu.test_functions.get(zcu.funcOwnerDeclIndex(sema.func_index)) == null) | 29545 | zcu.test_functions.get(zcu.funcOwnerDeclIndex(sema.func_index)) == null) |
| 29687 | { | 29546 | { |
| 29688 | const ret_ty_src: LazySrcLoc = .{ .node_offset_fn_type_ret_ty = 0 }; | 29547 | const ret_ty_src: LazySrcLoc = .{ |
| 29689 | const src_decl = zcu.funcOwnerDeclPtr(sema.func_index); | 29548 | .base_node_inst = zcu.funcOwnerDeclPtr(sema.func_index).zir_decl_index.unwrap().?, |
| | 29549 | .offset = .{ .node_offset_fn_type_ret_ty = 0 }, |
| | 29550 | }; |
| 29690 | if (inst_ty.isError(zcu) and !dest_ty.isError(zcu)) { | 29551 | if (inst_ty.isError(zcu) and !dest_ty.isError(zcu)) { |
| 29691 | try zcu.errNoteNonLazy(src_decl.toSrcLoc(ret_ty_src, zcu), msg, "function cannot return an error", .{}); | 29552 | try sema.errNote(ret_ty_src, msg, "function cannot return an error", .{}); |
| 29692 | } else { | 29553 | } else { |
| 29693 | try zcu.errNoteNonLazy(src_decl.toSrcLoc(ret_ty_src, zcu), msg, "function return type declared here", .{}); | 29554 | try sema.errNote(ret_ty_src, msg, "function return type declared here", .{}); |
| 29694 | } | 29555 | } |
| 29695 | } | 29556 | } |
| 29696 | | 29557 | |
| 29697 | if (try opts.param_src.get(sema)) |param_src| { | 29558 | if (try opts.param_src.get(sema)) |param_src| { |
| 29698 | try zcu.errNoteNonLazy(param_src, msg, "parameter type declared here", .{}); | 29559 | try sema.errNote(param_src, msg, "parameter type declared here", .{}); |
| 29699 | } | 29560 | } |
| 29700 | | 29561 | |
| 29701 | // TODO maybe add "cannot store an error in type '{}'" note | 29562 | // TODO maybe add "cannot store an error in type '{}'" note |
| ... | @@ -29830,7 +29691,7 @@ const InMemoryCoercionResult = union(enum) { | ... | @@ -29830,7 +29691,7 @@ const InMemoryCoercionResult = union(enum) { |
| 29830 | return res; | 29691 | return res; |
| 29831 | } | 29692 | } |
| 29832 | | 29693 | |
| 29833 | fn report(res: *const InMemoryCoercionResult, sema: *Sema, block: *Block, src: LazySrcLoc, msg: *Module.ErrorMsg) !void { | 29694 | fn report(res: *const InMemoryCoercionResult, sema: *Sema, src: LazySrcLoc, msg: *Module.ErrorMsg) !void { |
| 29834 | const mod = sema.mod; | 29695 | const mod = sema.mod; |
| 29835 | var cur = res; | 29696 | var cur = res; |
| 29836 | while (true) switch (cur.*) { | 29697 | while (true) switch (cur.*) { |
| ... | @@ -29841,93 +29702,93 @@ const InMemoryCoercionResult = union(enum) { | ... | @@ -29841,93 +29702,93 @@ const InMemoryCoercionResult = union(enum) { |
| 29841 | break; | 29702 | break; |
| 29842 | }, | 29703 | }, |
| 29843 | .int_not_coercible => |int| { | 29704 | .int_not_coercible => |int| { |
| 29844 | try sema.errNote(block, src, msg, "{s} {d}-bit int cannot represent all possible {s} {d}-bit values", .{ | 29705 | try sema.errNote(src, msg, "{s} {d}-bit int cannot represent all possible {s} {d}-bit values", .{ |
| 29845 | @tagName(int.wanted_signedness), int.wanted_bits, @tagName(int.actual_signedness), int.actual_bits, | 29706 | @tagName(int.wanted_signedness), int.wanted_bits, @tagName(int.actual_signedness), int.actual_bits, |
| 29846 | }); | 29707 | }); |
| 29847 | break; | 29708 | break; |
| 29848 | }, | 29709 | }, |
| 29849 | .error_union_payload => |pair| { | 29710 | .error_union_payload => |pair| { |
| 29850 | try sema.errNote(block, src, msg, "error union payload '{}' cannot cast into error union payload '{}'", .{ | 29711 | try sema.errNote(src, msg, "error union payload '{}' cannot cast into error union payload '{}'", .{ |
| 29851 | pair.actual.fmt(mod), pair.wanted.fmt(mod), | 29712 | pair.actual.fmt(mod), pair.wanted.fmt(mod), |
| 29852 | }); | 29713 | }); |
| 29853 | cur = pair.child; | 29714 | cur = pair.child; |
| 29854 | }, | 29715 | }, |
| 29855 | .array_len => |lens| { | 29716 | .array_len => |lens| { |
| 29856 | try sema.errNote(block, src, msg, "array of length {d} cannot cast into an array of length {d}", .{ | 29717 | try sema.errNote(src, msg, "array of length {d} cannot cast into an array of length {d}", .{ |
| 29857 | lens.actual, lens.wanted, | 29718 | lens.actual, lens.wanted, |
| 29858 | }); | 29719 | }); |
| 29859 | break; | 29720 | break; |
| 29860 | }, | 29721 | }, |
| 29861 | .array_sentinel => |sentinel| { | 29722 | .array_sentinel => |sentinel| { |
| 29862 | if (sentinel.actual.toIntern() != .unreachable_value) { | 29723 | if (sentinel.actual.toIntern() != .unreachable_value) { |
| 29863 | try sema.errNote(block, src, msg, "array sentinel '{}' cannot cast into array sentinel '{}'", .{ | 29724 | try sema.errNote(src, msg, "array sentinel '{}' cannot cast into array sentinel '{}'", .{ |
| 29864 | sentinel.actual.fmtValue(mod, sema), sentinel.wanted.fmtValue(mod, sema), | 29725 | sentinel.actual.fmtValue(mod, sema), sentinel.wanted.fmtValue(mod, sema), |
| 29865 | }); | 29726 | }); |
| 29866 | } else { | 29727 | } else { |
| 29867 | try sema.errNote(block, src, msg, "destination array requires '{}' sentinel", .{ | 29728 | try sema.errNote(src, msg, "destination array requires '{}' sentinel", .{ |
| 29868 | sentinel.wanted.fmtValue(mod, sema), | 29729 | sentinel.wanted.fmtValue(mod, sema), |
| 29869 | }); | 29730 | }); |
| 29870 | } | 29731 | } |
| 29871 | break; | 29732 | break; |
| 29872 | }, | 29733 | }, |
| 29873 | .array_elem => |pair| { | 29734 | .array_elem => |pair| { |
| 29874 | try sema.errNote(block, src, msg, "array element type '{}' cannot cast into array element type '{}'", .{ | 29735 | try sema.errNote(src, msg, "array element type '{}' cannot cast into array element type '{}'", .{ |
| 29875 | pair.actual.fmt(mod), pair.wanted.fmt(mod), | 29736 | pair.actual.fmt(mod), pair.wanted.fmt(mod), |
| 29876 | }); | 29737 | }); |
| 29877 | cur = pair.child; | 29738 | cur = pair.child; |
| 29878 | }, | 29739 | }, |
| 29879 | .vector_len => |lens| { | 29740 | .vector_len => |lens| { |
| 29880 | try sema.errNote(block, src, msg, "vector of length {d} cannot cast into a vector of length {d}", .{ | 29741 | try sema.errNote(src, msg, "vector of length {d} cannot cast into a vector of length {d}", .{ |
| 29881 | lens.actual, lens.wanted, | 29742 | lens.actual, lens.wanted, |
| 29882 | }); | 29743 | }); |
| 29883 | break; | 29744 | break; |
| 29884 | }, | 29745 | }, |
| 29885 | .vector_elem => |pair| { | 29746 | .vector_elem => |pair| { |
| 29886 | try sema.errNote(block, src, msg, "vector element type '{}' cannot cast into vector element type '{}'", .{ | 29747 | try sema.errNote(src, msg, "vector element type '{}' cannot cast into vector element type '{}'", .{ |
| 29887 | pair.actual.fmt(mod), pair.wanted.fmt(mod), | 29748 | pair.actual.fmt(mod), pair.wanted.fmt(mod), |
| 29888 | }); | 29749 | }); |
| 29889 | cur = pair.child; | 29750 | cur = pair.child; |
| 29890 | }, | 29751 | }, |
| 29891 | .optional_shape => |pair| { | 29752 | .optional_shape => |pair| { |
| 29892 | try sema.errNote(block, src, msg, "optional type child '{}' cannot cast into optional type child '{}'", .{ | 29753 | try sema.errNote(src, msg, "optional type child '{}' cannot cast into optional type child '{}'", .{ |
| 29893 | pair.actual.optionalChild(mod).fmt(mod), pair.wanted.optionalChild(mod).fmt(mod), | 29754 | pair.actual.optionalChild(mod).fmt(mod), pair.wanted.optionalChild(mod).fmt(mod), |
| 29894 | }); | 29755 | }); |
| 29895 | break; | 29756 | break; |
| 29896 | }, | 29757 | }, |
| 29897 | .optional_child => |pair| { | 29758 | .optional_child => |pair| { |
| 29898 | try sema.errNote(block, src, msg, "optional type child '{}' cannot cast into optional type child '{}'", .{ | 29759 | try sema.errNote(src, msg, "optional type child '{}' cannot cast into optional type child '{}'", .{ |
| 29899 | pair.actual.fmt(mod), pair.wanted.fmt(mod), | 29760 | pair.actual.fmt(mod), pair.wanted.fmt(mod), |
| 29900 | }); | 29761 | }); |
| 29901 | cur = pair.child; | 29762 | cur = pair.child; |
| 29902 | }, | 29763 | }, |
| 29903 | .from_anyerror => { | 29764 | .from_anyerror => { |
| 29904 | try sema.errNote(block, src, msg, "global error set cannot cast into a smaller set", .{}); | 29765 | try sema.errNote(src, msg, "global error set cannot cast into a smaller set", .{}); |
| 29905 | break; | 29766 | break; |
| 29906 | }, | 29767 | }, |
| 29907 | .missing_error => |missing_errors| { | 29768 | .missing_error => |missing_errors| { |
| 29908 | for (missing_errors) |err| { | 29769 | for (missing_errors) |err| { |
| 29909 | try sema.errNote(block, src, msg, "'error.{}' not a member of destination error set", .{err.fmt(&mod.intern_pool)}); | 29770 | try sema.errNote(src, msg, "'error.{}' not a member of destination error set", .{err.fmt(&mod.intern_pool)}); |
| 29910 | } | 29771 | } |
| 29911 | break; | 29772 | break; |
| 29912 | }, | 29773 | }, |
| 29913 | .fn_var_args => |wanted_var_args| { | 29774 | .fn_var_args => |wanted_var_args| { |
| 29914 | if (wanted_var_args) { | 29775 | if (wanted_var_args) { |
| 29915 | try sema.errNote(block, src, msg, "non-variadic function cannot cast into a variadic function", .{}); | 29776 | try sema.errNote(src, msg, "non-variadic function cannot cast into a variadic function", .{}); |
| 29916 | } else { | 29777 | } else { |
| 29917 | try sema.errNote(block, src, msg, "variadic function cannot cast into a non-variadic function", .{}); | 29778 | try sema.errNote(src, msg, "variadic function cannot cast into a non-variadic function", .{}); |
| 29918 | } | 29779 | } |
| 29919 | break; | 29780 | break; |
| 29920 | }, | 29781 | }, |
| 29921 | .fn_generic => |wanted_generic| { | 29782 | .fn_generic => |wanted_generic| { |
| 29922 | if (wanted_generic) { | 29783 | if (wanted_generic) { |
| 29923 | try sema.errNote(block, src, msg, "non-generic function cannot cast into a generic function", .{}); | 29784 | try sema.errNote(src, msg, "non-generic function cannot cast into a generic function", .{}); |
| 29924 | } else { | 29785 | } else { |
| 29925 | try sema.errNote(block, src, msg, "generic function cannot cast into a non-generic function", .{}); | 29786 | try sema.errNote(src, msg, "generic function cannot cast into a non-generic function", .{}); |
| 29926 | } | 29787 | } |
| 29927 | break; | 29788 | break; |
| 29928 | }, | 29789 | }, |
| 29929 | .fn_param_count => |lens| { | 29790 | .fn_param_count => |lens| { |
| 29930 | try sema.errNote(block, src, msg, "function with {d} parameters cannot cast into a function with {d} parameters", .{ | 29791 | try sema.errNote(src, msg, "function with {d} parameters cannot cast into a function with {d} parameters", .{ |
| 29931 | lens.actual, lens.wanted, | 29792 | lens.actual, lens.wanted, |
| 29932 | }); | 29793 | }); |
| 29933 | break; | 29794 | break; |
| ... | @@ -29944,69 +29805,69 @@ const InMemoryCoercionResult = union(enum) { | ... | @@ -29944,69 +29805,69 @@ const InMemoryCoercionResult = union(enum) { |
| 29944 | } | 29805 | } |
| 29945 | } | 29806 | } |
| 29946 | if (!actual_noalias) { | 29807 | if (!actual_noalias) { |
| 29947 | try sema.errNote(block, src, msg, "regular parameter {d} cannot cast into a noalias parameter", .{index}); | 29808 | try sema.errNote(src, msg, "regular parameter {d} cannot cast into a noalias parameter", .{index}); |
| 29948 | } else { | 29809 | } else { |
| 29949 | try sema.errNote(block, src, msg, "noalias parameter {d} cannot cast into a regular parameter", .{index}); | 29810 | try sema.errNote(src, msg, "noalias parameter {d} cannot cast into a regular parameter", .{index}); |
| 29950 | } | 29811 | } |
| 29951 | break; | 29812 | break; |
| 29952 | }, | 29813 | }, |
| 29953 | .fn_param_comptime => |param| { | 29814 | .fn_param_comptime => |param| { |
| 29954 | if (param.wanted) { | 29815 | if (param.wanted) { |
| 29955 | try sema.errNote(block, src, msg, "non-comptime parameter {d} cannot cast into a comptime parameter", .{param.index}); | 29816 | try sema.errNote(src, msg, "non-comptime parameter {d} cannot cast into a comptime parameter", .{param.index}); |
| 29956 | } else { | 29817 | } else { |
| 29957 | try sema.errNote(block, src, msg, "comptime parameter {d} cannot cast into a non-comptime parameter", .{param.index}); | 29818 | try sema.errNote(src, msg, "comptime parameter {d} cannot cast into a non-comptime parameter", .{param.index}); |
| 29958 | } | 29819 | } |
| 29959 | break; | 29820 | break; |
| 29960 | }, | 29821 | }, |
| 29961 | .fn_param => |param| { | 29822 | .fn_param => |param| { |
| 29962 | try sema.errNote(block, src, msg, "parameter {d} '{}' cannot cast into '{}'", .{ | 29823 | try sema.errNote(src, msg, "parameter {d} '{}' cannot cast into '{}'", .{ |
| 29963 | param.index, param.actual.fmt(mod), param.wanted.fmt(mod), | 29824 | param.index, param.actual.fmt(mod), param.wanted.fmt(mod), |
| 29964 | }); | 29825 | }); |
| 29965 | cur = param.child; | 29826 | cur = param.child; |
| 29966 | }, | 29827 | }, |
| 29967 | .fn_cc => |cc| { | 29828 | .fn_cc => |cc| { |
| 29968 | try sema.errNote(block, src, msg, "calling convention '{s}' cannot cast into calling convention '{s}'", .{ @tagName(cc.actual), @tagName(cc.wanted) }); | 29829 | try sema.errNote(src, msg, "calling convention '{s}' cannot cast into calling convention '{s}'", .{ @tagName(cc.actual), @tagName(cc.wanted) }); |
| 29969 | break; | 29830 | break; |
| 29970 | }, | 29831 | }, |
| 29971 | .fn_return_type => |pair| { | 29832 | .fn_return_type => |pair| { |
| 29972 | try sema.errNote(block, src, msg, "return type '{}' cannot cast into return type '{}'", .{ | 29833 | try sema.errNote(src, msg, "return type '{}' cannot cast into return type '{}'", .{ |
| 29973 | pair.actual.fmt(mod), pair.wanted.fmt(mod), | 29834 | pair.actual.fmt(mod), pair.wanted.fmt(mod), |
| 29974 | }); | 29835 | }); |
| 29975 | cur = pair.child; | 29836 | cur = pair.child; |
| 29976 | }, | 29837 | }, |
| 29977 | .ptr_child => |pair| { | 29838 | .ptr_child => |pair| { |
| 29978 | try sema.errNote(block, src, msg, "pointer type child '{}' cannot cast into pointer type child '{}'", .{ | 29839 | try sema.errNote(src, msg, "pointer type child '{}' cannot cast into pointer type child '{}'", .{ |
| 29979 | pair.actual.fmt(mod), pair.wanted.fmt(mod), | 29840 | pair.actual.fmt(mod), pair.wanted.fmt(mod), |
| 29980 | }); | 29841 | }); |
| 29981 | cur = pair.child; | 29842 | cur = pair.child; |
| 29982 | }, | 29843 | }, |
| 29983 | .ptr_addrspace => |@"addrspace"| { | 29844 | .ptr_addrspace => |@"addrspace"| { |
| 29984 | try sema.errNote(block, src, msg, "address space '{s}' cannot cast into address space '{s}'", .{ @tagName(@"addrspace".actual), @tagName(@"addrspace".wanted) }); | 29845 | try sema.errNote(src, msg, "address space '{s}' cannot cast into address space '{s}'", .{ @tagName(@"addrspace".actual), @tagName(@"addrspace".wanted) }); |
| 29985 | break; | 29846 | break; |
| 29986 | }, | 29847 | }, |
| 29987 | .ptr_sentinel => |sentinel| { | 29848 | .ptr_sentinel => |sentinel| { |
| 29988 | if (sentinel.actual.toIntern() != .unreachable_value) { | 29849 | if (sentinel.actual.toIntern() != .unreachable_value) { |
| 29989 | try sema.errNote(block, src, msg, "pointer sentinel '{}' cannot cast into pointer sentinel '{}'", .{ | 29850 | try sema.errNote(src, msg, "pointer sentinel '{}' cannot cast into pointer sentinel '{}'", .{ |
| 29990 | sentinel.actual.fmtValue(mod, sema), sentinel.wanted.fmtValue(mod, sema), | 29851 | sentinel.actual.fmtValue(mod, sema), sentinel.wanted.fmtValue(mod, sema), |
| 29991 | }); | 29852 | }); |
| 29992 | } else { | 29853 | } else { |
| 29993 | try sema.errNote(block, src, msg, "destination pointer requires '{}' sentinel", .{ | 29854 | try sema.errNote(src, msg, "destination pointer requires '{}' sentinel", .{ |
| 29994 | sentinel.wanted.fmtValue(mod, sema), | 29855 | sentinel.wanted.fmtValue(mod, sema), |
| 29995 | }); | 29856 | }); |
| 29996 | } | 29857 | } |
| 29997 | break; | 29858 | break; |
| 29998 | }, | 29859 | }, |
| 29999 | .ptr_size => |size| { | 29860 | .ptr_size => |size| { |
| 30000 | try sema.errNote(block, src, msg, "a {s} pointer cannot cast into a {s} pointer", .{ pointerSizeString(size.actual), pointerSizeString(size.wanted) }); | 29861 | try sema.errNote(src, msg, "a {s} pointer cannot cast into a {s} pointer", .{ pointerSizeString(size.actual), pointerSizeString(size.wanted) }); |
| 30001 | break; | 29862 | break; |
| 30002 | }, | 29863 | }, |
| 30003 | .ptr_qualifiers => |qualifiers| { | 29864 | .ptr_qualifiers => |qualifiers| { |
| 30004 | const ok_const = !qualifiers.actual_const or qualifiers.wanted_const; | 29865 | const ok_const = !qualifiers.actual_const or qualifiers.wanted_const; |
| 30005 | const ok_volatile = !qualifiers.actual_volatile or qualifiers.wanted_volatile; | 29866 | const ok_volatile = !qualifiers.actual_volatile or qualifiers.wanted_volatile; |
| 30006 | if (!ok_const) { | 29867 | if (!ok_const) { |
| 30007 | try sema.errNote(block, src, msg, "cast discards const qualifier", .{}); | 29868 | try sema.errNote(src, msg, "cast discards const qualifier", .{}); |
| 30008 | } else if (!ok_volatile) { | 29869 | } else if (!ok_volatile) { |
| 30009 | try sema.errNote(block, src, msg, "cast discards volatile qualifier", .{}); | 29870 | try sema.errNote(src, msg, "cast discards volatile qualifier", .{}); |
| 30010 | } | 29871 | } |
| 30011 | break; | 29872 | break; |
| 30012 | }, | 29873 | }, |
| ... | @@ -30014,11 +29875,11 @@ const InMemoryCoercionResult = union(enum) { | ... | @@ -30014,11 +29875,11 @@ const InMemoryCoercionResult = union(enum) { |
| 30014 | const wanted_allow_zero = pair.wanted.ptrAllowsZero(mod); | 29875 | const wanted_allow_zero = pair.wanted.ptrAllowsZero(mod); |
| 30015 | const actual_allow_zero = pair.actual.ptrAllowsZero(mod); | 29876 | const actual_allow_zero = pair.actual.ptrAllowsZero(mod); |
| 30016 | if (actual_allow_zero and !wanted_allow_zero) { | 29877 | if (actual_allow_zero and !wanted_allow_zero) { |
| 30017 | try sema.errNote(block, src, msg, "'{}' could have null values which are illegal in type '{}'", .{ | 29878 | try sema.errNote(src, msg, "'{}' could have null values which are illegal in type '{}'", .{ |
| 30018 | pair.actual.fmt(mod), pair.wanted.fmt(mod), | 29879 | pair.actual.fmt(mod), pair.wanted.fmt(mod), |
| 30019 | }); | 29880 | }); |
| 30020 | } else { | 29881 | } else { |
| 30021 | try sema.errNote(block, src, msg, "mutable '{}' allows illegal null values stored to type '{}'", .{ | 29882 | try sema.errNote(src, msg, "mutable '{}' allows illegal null values stored to type '{}'", .{ |
| 30022 | pair.actual.fmt(mod), pair.wanted.fmt(mod), | 29883 | pair.actual.fmt(mod), pair.wanted.fmt(mod), |
| 30023 | }); | 29884 | }); |
| 30024 | } | 29885 | } |
| ... | @@ -30026,34 +29887,34 @@ const InMemoryCoercionResult = union(enum) { | ... | @@ -30026,34 +29887,34 @@ const InMemoryCoercionResult = union(enum) { |
| 30026 | }, | 29887 | }, |
| 30027 | .ptr_bit_range => |bit_range| { | 29888 | .ptr_bit_range => |bit_range| { |
| 30028 | if (bit_range.actual_host != bit_range.wanted_host) { | 29889 | if (bit_range.actual_host != bit_range.wanted_host) { |
| 30029 | try sema.errNote(block, src, msg, "pointer host size '{}' cannot cast into pointer host size '{}'", .{ | 29890 | try sema.errNote(src, msg, "pointer host size '{}' cannot cast into pointer host size '{}'", .{ |
| 30030 | bit_range.actual_host, bit_range.wanted_host, | 29891 | bit_range.actual_host, bit_range.wanted_host, |
| 30031 | }); | 29892 | }); |
| 30032 | } | 29893 | } |
| 30033 | if (bit_range.actual_offset != bit_range.wanted_offset) { | 29894 | if (bit_range.actual_offset != bit_range.wanted_offset) { |
| 30034 | try sema.errNote(block, src, msg, "pointer bit offset '{}' cannot cast into pointer bit offset '{}'", .{ | 29895 | try sema.errNote(src, msg, "pointer bit offset '{}' cannot cast into pointer bit offset '{}'", .{ |
| 30035 | bit_range.actual_offset, bit_range.wanted_offset, | 29896 | bit_range.actual_offset, bit_range.wanted_offset, |
| 30036 | }); | 29897 | }); |
| 30037 | } | 29898 | } |
| 30038 | break; | 29899 | break; |
| 30039 | }, | 29900 | }, |
| 30040 | .ptr_alignment => |pair| { | 29901 | .ptr_alignment => |pair| { |
| 30041 | try sema.errNote(block, src, msg, "pointer alignment '{d}' cannot cast into pointer alignment '{d}'", .{ | 29902 | try sema.errNote(src, msg, "pointer alignment '{d}' cannot cast into pointer alignment '{d}'", .{ |
| 30042 | pair.actual.toByteUnits() orelse 0, pair.wanted.toByteUnits() orelse 0, | 29903 | pair.actual.toByteUnits() orelse 0, pair.wanted.toByteUnits() orelse 0, |
| 30043 | }); | 29904 | }); |
| 30044 | break; | 29905 | break; |
| 30045 | }, | 29906 | }, |
| 30046 | .double_ptr_to_anyopaque => |pair| { | 29907 | .double_ptr_to_anyopaque => |pair| { |
| 30047 | try sema.errNote(block, src, msg, "cannot implicitly cast double pointer '{}' to anyopaque pointer '{}'", .{ | 29908 | try sema.errNote(src, msg, "cannot implicitly cast double pointer '{}' to anyopaque pointer '{}'", .{ |
| 30048 | pair.actual.fmt(mod), pair.wanted.fmt(mod), | 29909 | pair.actual.fmt(mod), pair.wanted.fmt(mod), |
| 30049 | }); | 29910 | }); |
| 30050 | break; | 29911 | break; |
| 30051 | }, | 29912 | }, |
| 30052 | .slice_to_anyopaque => |pair| { | 29913 | .slice_to_anyopaque => |pair| { |
| 30053 | try sema.errNote(block, src, msg, "cannot implicitly cast slice '{}' to anyopaque pointer '{}'", .{ | 29914 | try sema.errNote(src, msg, "cannot implicitly cast slice '{}' to anyopaque pointer '{}'", .{ |
| 30054 | pair.actual.fmt(mod), pair.wanted.fmt(mod), | 29915 | pair.actual.fmt(mod), pair.wanted.fmt(mod), |
| 30055 | }); | 29916 | }); |
| 30056 | try sema.errNote(block, src, msg, "consider using '.ptr'", .{}); | 29917 | try sema.errNote(src, msg, "consider using '.ptr'", .{}); |
| 30057 | break; | 29918 | break; |
| 30058 | }, | 29919 | }, |
| 30059 | }; | 29920 | }; |
| ... | @@ -30667,7 +30528,7 @@ fn coerceVarArgParam( | ... | @@ -30667,7 +30528,7 @@ fn coerceVarArgParam( |
| 30667 | .{}, | 30528 | .{}, |
| 30668 | ), | 30529 | ), |
| 30669 | .Fn => fn_ptr: { | 30530 | .Fn => fn_ptr: { |
| 30670 | const fn_val = try sema.resolveConstDefinedValue(block, .unneeded, inst, undefined); | 30531 | const fn_val = try sema.resolveConstDefinedValue(block, LazySrcLoc.unneeded, inst, undefined); |
| 30671 | const fn_decl = fn_val.pointerDecl(mod).?; | 30532 | const fn_decl = fn_val.pointerDecl(mod).?; |
| 30672 | break :fn_ptr try sema.analyzeDeclRef(fn_decl); | 30533 | break :fn_ptr try sema.analyzeDeclRef(fn_decl); |
| 30673 | }, | 30534 | }, |
| ... | @@ -30715,11 +30576,10 @@ fn coerceVarArgParam( | ... | @@ -30715,11 +30576,10 @@ fn coerceVarArgParam( |
| 30715 | const coerced_ty = sema.typeOf(coerced); | 30576 | const coerced_ty = sema.typeOf(coerced); |
| 30716 | if (!try sema.validateExternType(coerced_ty, .param_ty)) { | 30577 | if (!try sema.validateExternType(coerced_ty, .param_ty)) { |
| 30717 | const msg = msg: { | 30578 | const msg = msg: { |
| 30718 | const msg = try sema.errMsg(block, inst_src, "cannot pass '{}' to variadic function", .{coerced_ty.fmt(sema.mod)}); | 30579 | const msg = try sema.errMsg(inst_src, "cannot pass '{}' to variadic function", .{coerced_ty.fmt(sema.mod)}); |
| 30719 | errdefer msg.destroy(sema.gpa); | 30580 | errdefer msg.destroy(sema.gpa); |
| 30720 | | 30581 | |
| 30721 | const src_decl = sema.mod.declPtr(block.src_decl); | 30582 | try sema.explainWhyTypeIsNotExtern(msg, inst_src, coerced_ty, .param_ty); |
| 30722 | try sema.explainWhyTypeIsNotExtern(msg, src_decl.toSrcLoc(inst_src, mod), coerced_ty, .param_ty); | | |
| 30723 | | 30583 | |
| 30724 | try sema.addDeclaredHereNote(msg, coerced_ty); | 30584 | try sema.addDeclaredHereNote(msg, coerced_ty); |
| 30725 | break :msg msg; | 30585 | break :msg msg; |
| ... | @@ -30879,7 +30739,6 @@ fn checkComptimeKnownStore(sema: *Sema, block: *Block, store_inst_ref: Air.Inst. | ... | @@ -30879,7 +30739,6 @@ fn checkComptimeKnownStore(sema: *Sema, block: *Block, store_inst_ref: Air.Inst. |
| 30879 | { | 30739 | { |
| 30880 | try maybe_comptime_alloc.stores.append(sema.arena, .{ | 30740 | try maybe_comptime_alloc.stores.append(sema.arena, .{ |
| 30881 | .inst = store_inst, | 30741 | .inst = store_inst, |
| 30882 | .src_decl = block.src_decl, | | |
| 30883 | .src = store_src, | 30742 | .src = store_src, |
| 30884 | }); | 30743 | }); |
| 30885 | return; | 30744 | return; |
| ... | @@ -30913,8 +30772,7 @@ fn checkKnownAllocPtr(sema: *Sema, block: *Block, base_ptr: Air.Inst.Ref, new_pt | ... | @@ -30913,8 +30772,7 @@ fn checkKnownAllocPtr(sema: *Sema, block: *Block, base_ptr: Air.Inst.Ref, new_pt |
| 30913 | | 30772 | |
| 30914 | try maybe_comptime_alloc.stores.append(sema.arena, .{ | 30773 | try maybe_comptime_alloc.stores.append(sema.arena, .{ |
| 30915 | .inst = new_ptr_inst, | 30774 | .inst = new_ptr_inst, |
| 30916 | .src_decl = block.src_decl, | 30775 | .src = LazySrcLoc.unneeded, |
| 30917 | .src = .unneeded, | | |
| 30918 | }); | 30776 | }); |
| 30919 | }, | 30777 | }, |
| 30920 | .ptr_elem_ptr => { | 30778 | .ptr_elem_ptr => { |
| ... | @@ -30937,10 +30795,9 @@ fn markMaybeComptimeAllocRuntime(sema: *Sema, block: *Block, alloc_inst: Air.Ins | ... | @@ -30937,10 +30795,9 @@ fn markMaybeComptimeAllocRuntime(sema: *Sema, block: *Block, alloc_inst: Air.Ins |
| 30937 | const maybe_comptime_alloc = (sema.maybe_comptime_allocs.fetchRemove(alloc_inst) orelse return).value; | 30795 | const maybe_comptime_alloc = (sema.maybe_comptime_allocs.fetchRemove(alloc_inst) orelse return).value; |
| 30938 | // Since the alloc has been determined to be runtime, we must check that | 30796 | // Since the alloc has been determined to be runtime, we must check that |
| 30939 | // all other stores to it are permitted to be runtime values. | 30797 | // all other stores to it are permitted to be runtime values. |
| 30940 | const mod = sema.mod; | | |
| 30941 | const slice = maybe_comptime_alloc.stores.slice(); | 30798 | const slice = maybe_comptime_alloc.stores.slice(); |
| 30942 | for (slice.items(.inst), slice.items(.src_decl), slice.items(.src)) |other_inst, other_src_decl, other_src| { | 30799 | for (slice.items(.inst), slice.items(.src)) |other_inst, other_src| { |
| 30943 | if (other_src == .unneeded) { | 30800 | if (other_src.offset == .unneeded) { |
| 30944 | switch (sema.air_instructions.items(.tag)[@intFromEnum(other_inst)]) { | 30801 | switch (sema.air_instructions.items(.tag)[@intFromEnum(other_inst)]) { |
| 30945 | .set_union_tag, .optional_payload_ptr_set, .errunion_payload_ptr_set => continue, | 30802 | .set_union_tag, .optional_payload_ptr_set, .errunion_payload_ptr_set => continue, |
| 30946 | else => unreachable, // assertion failure | 30803 | else => unreachable, // assertion failure |
| ... | @@ -30950,10 +30807,9 @@ fn markMaybeComptimeAllocRuntime(sema: *Sema, block: *Block, alloc_inst: Air.Ins | ... | @@ -30950,10 +30807,9 @@ fn markMaybeComptimeAllocRuntime(sema: *Sema, block: *Block, alloc_inst: Air.Ins |
| 30950 | const other_operand = other_data.rhs; | 30807 | const other_operand = other_data.rhs; |
| 30951 | if (!sema.checkRuntimeValue(other_operand)) { | 30808 | if (!sema.checkRuntimeValue(other_operand)) { |
| 30952 | return sema.failWithOwnedErrorMsg(block, msg: { | 30809 | return sema.failWithOwnedErrorMsg(block, msg: { |
| 30953 | const other_src_resolved = mod.declPtr(other_src_decl).toSrcLoc(other_src, mod); | 30810 | const msg = try sema.errMsg(other_src, "runtime value contains reference to comptime var", .{}); |
| 30954 | const msg = try Module.ErrorMsg.create(sema.gpa, other_src_resolved, "runtime value contains reference to comptime var", .{}); | | |
| 30955 | errdefer msg.destroy(sema.gpa); | 30811 | errdefer msg.destroy(sema.gpa); |
| 30956 | try mod.errNoteNonLazy(other_src_resolved, msg, "comptime var pointers are not available at runtime", .{}); | 30812 | try sema.errNote(other_src, msg, "comptime var pointers are not available at runtime", .{}); |
| 30957 | break :msg msg; | 30813 | break :msg msg; |
| 30958 | }); | 30814 | }); |
| 30959 | } | 30815 | } |
| ... | @@ -31215,11 +31071,11 @@ fn coerceEnumToUnion( | ... | @@ -31215,11 +31071,11 @@ fn coerceEnumToUnion( |
| 31215 | | 31071 | |
| 31216 | const tag_ty = union_ty.unionTagType(mod) orelse { | 31072 | const tag_ty = union_ty.unionTagType(mod) orelse { |
| 31217 | const msg = msg: { | 31073 | const msg = msg: { |
| 31218 | const msg = try sema.errMsg(block, inst_src, "expected type '{}', found '{}'", .{ | 31074 | const msg = try sema.errMsg(inst_src, "expected type '{}', found '{}'", .{ |
| 31219 | union_ty.fmt(sema.mod), inst_ty.fmt(sema.mod), | 31075 | union_ty.fmt(sema.mod), inst_ty.fmt(sema.mod), |
| 31220 | }); | 31076 | }); |
| 31221 | errdefer msg.destroy(sema.gpa); | 31077 | errdefer msg.destroy(sema.gpa); |
| 31222 | try sema.errNote(block, union_ty_src, msg, "cannot coerce enum to untagged union", .{}); | 31078 | try sema.errNote(union_ty_src, msg, "cannot coerce enum to untagged union", .{}); |
| 31223 | try sema.addDeclaredHereNote(msg, union_ty); | 31079 | try sema.addDeclaredHereNote(msg, union_ty); |
| 31224 | break :msg msg; | 31080 | break :msg msg; |
| 31225 | }; | 31081 | }; |
| ... | @@ -31239,7 +31095,7 @@ fn coerceEnumToUnion( | ... | @@ -31239,7 +31095,7 @@ fn coerceEnumToUnion( |
| 31239 | try sema.resolveTypeFields(field_ty); | 31095 | try sema.resolveTypeFields(field_ty); |
| 31240 | if (field_ty.zigTypeTag(mod) == .NoReturn) { | 31096 | if (field_ty.zigTypeTag(mod) == .NoReturn) { |
| 31241 | const msg = msg: { | 31097 | const msg = msg: { |
| 31242 | const msg = try sema.errMsg(block, inst_src, "cannot initialize 'noreturn' field of union", .{}); | 31098 | const msg = try sema.errMsg(inst_src, "cannot initialize 'noreturn' field of union", .{}); |
| 31243 | errdefer msg.destroy(sema.gpa); | 31099 | errdefer msg.destroy(sema.gpa); |
| 31244 | | 31100 | |
| 31245 | const field_name = union_obj.loadTagType(ip).names.get(ip)[field_index]; | 31101 | const field_name = union_obj.loadTagType(ip).names.get(ip)[field_index]; |
| ... | @@ -31254,7 +31110,7 @@ fn coerceEnumToUnion( | ... | @@ -31254,7 +31110,7 @@ fn coerceEnumToUnion( |
| 31254 | const opv = (try sema.typeHasOnePossibleValue(field_ty)) orelse { | 31110 | const opv = (try sema.typeHasOnePossibleValue(field_ty)) orelse { |
| 31255 | const msg = msg: { | 31111 | const msg = msg: { |
| 31256 | const field_name = union_obj.loadTagType(ip).names.get(ip)[field_index]; | 31112 | const field_name = union_obj.loadTagType(ip).names.get(ip)[field_index]; |
| 31257 | const msg = try sema.errMsg(block, inst_src, "coercion from enum '{}' to union '{}' must initialize '{}' field '{}'", .{ | 31113 | const msg = try sema.errMsg(inst_src, "coercion from enum '{}' to union '{}' must initialize '{}' field '{}'", .{ |
| 31258 | inst_ty.fmt(sema.mod), union_ty.fmt(sema.mod), | 31114 | inst_ty.fmt(sema.mod), union_ty.fmt(sema.mod), |
| 31259 | field_ty.fmt(sema.mod), field_name.fmt(ip), | 31115 | field_ty.fmt(sema.mod), field_name.fmt(ip), |
| 31260 | }); | 31116 | }); |
| ... | @@ -31276,7 +31132,7 @@ fn coerceEnumToUnion( | ... | @@ -31276,7 +31132,7 @@ fn coerceEnumToUnion( |
| 31276 | | 31132 | |
| 31277 | if (tag_ty.isNonexhaustiveEnum(mod)) { | 31133 | if (tag_ty.isNonexhaustiveEnum(mod)) { |
| 31278 | const msg = msg: { | 31134 | const msg = msg: { |
| 31279 | const msg = try sema.errMsg(block, inst_src, "runtime coercion to union '{}' from non-exhaustive enum", .{ | 31135 | const msg = try sema.errMsg(inst_src, "runtime coercion to union '{}' from non-exhaustive enum", .{ |
| 31280 | union_ty.fmt(sema.mod), | 31136 | union_ty.fmt(sema.mod), |
| 31281 | }); | 31137 | }); |
| 31282 | errdefer msg.destroy(sema.gpa); | 31138 | errdefer msg.destroy(sema.gpa); |
| ... | @@ -31294,7 +31150,6 @@ fn coerceEnumToUnion( | ... | @@ -31294,7 +31150,6 @@ fn coerceEnumToUnion( |
| 31294 | for (union_obj.field_types.get(ip), 0..) |field_ty, field_index| { | 31150 | for (union_obj.field_types.get(ip), 0..) |field_ty, field_index| { |
| 31295 | if (Type.fromInterned(field_ty).zigTypeTag(mod) == .NoReturn) { | 31151 | if (Type.fromInterned(field_ty).zigTypeTag(mod) == .NoReturn) { |
| 31296 | const err_msg = msg orelse try sema.errMsg( | 31152 | const err_msg = msg orelse try sema.errMsg( |
| 31297 | block, | | |
| 31298 | inst_src, | 31153 | inst_src, |
| 31299 | "runtime coercion from enum '{}' to union '{}' which has a 'noreturn' field", | 31154 | "runtime coercion from enum '{}' to union '{}' which has a 'noreturn' field", |
| 31300 | .{ tag_ty.fmt(sema.mod), union_ty.fmt(sema.mod) }, | 31155 | .{ tag_ty.fmt(sema.mod), union_ty.fmt(sema.mod) }, |
| ... | @@ -31318,7 +31173,6 @@ fn coerceEnumToUnion( | ... | @@ -31318,7 +31173,6 @@ fn coerceEnumToUnion( |
| 31318 | | 31173 | |
| 31319 | const msg = msg: { | 31174 | const msg = msg: { |
| 31320 | const msg = try sema.errMsg( | 31175 | const msg = try sema.errMsg( |
| 31321 | block, | | |
| 31322 | inst_src, | 31176 | inst_src, |
| 31323 | "runtime coercion from enum '{}' to union '{}' which has non-void fields", | 31177 | "runtime coercion from enum '{}' to union '{}' which has non-void fields", |
| 31324 | .{ tag_ty.fmt(sema.mod), union_ty.fmt(sema.mod) }, | 31178 | .{ tag_ty.fmt(sema.mod), union_ty.fmt(sema.mod) }, |
| ... | @@ -31377,12 +31231,10 @@ fn coerceAnonStructToUnion( | ... | @@ -31377,12 +31231,10 @@ fn coerceAnonStructToUnion( |
| 31377 | assert(field_count != 1); | 31231 | assert(field_count != 1); |
| 31378 | const msg = msg: { | 31232 | const msg = msg: { |
| 31379 | const msg = if (field_count > 1) try sema.errMsg( | 31233 | const msg = if (field_count > 1) try sema.errMsg( |
| 31380 | block, | | |
| 31381 | inst_src, | 31234 | inst_src, |
| 31382 | "cannot initialize multiple union fields at once; unions can only have one active field", | 31235 | "cannot initialize multiple union fields at once; unions can only have one active field", |
| 31383 | .{}, | 31236 | .{}, |
| 31384 | ) else try sema.errMsg( | 31237 | ) else try sema.errMsg( |
| 31385 | block, | | |
| 31386 | inst_src, | 31238 | inst_src, |
| 31387 | "union initializer must initialize one field", | 31239 | "union initializer must initialize one field", |
| 31388 | .{}, | 31240 | .{}, |
| ... | @@ -31459,12 +31311,12 @@ fn coerceArrayLike( | ... | @@ -31459,12 +31311,12 @@ fn coerceArrayLike( |
| 31459 | const dest_len = try sema.usizeCast(block, dest_ty_src, dest_ty.arrayLen(mod)); | 31311 | const dest_len = try sema.usizeCast(block, dest_ty_src, dest_ty.arrayLen(mod)); |
| 31460 | if (dest_len != inst_len) { | 31312 | if (dest_len != inst_len) { |
| 31461 | const msg = msg: { | 31313 | const msg = msg: { |
| 31462 | const msg = try sema.errMsg(block, inst_src, "expected type '{}', found '{}'", .{ | 31314 | const msg = try sema.errMsg(inst_src, "expected type '{}', found '{}'", .{ |
| 31463 | dest_ty.fmt(mod), inst_ty.fmt(mod), | 31315 | dest_ty.fmt(mod), inst_ty.fmt(mod), |
| 31464 | }); | 31316 | }); |
| 31465 | errdefer msg.destroy(sema.gpa); | 31317 | errdefer msg.destroy(sema.gpa); |
| 31466 | try sema.errNote(block, dest_ty_src, msg, "destination has length {d}", .{dest_len}); | 31318 | try sema.errNote(dest_ty_src, msg, "destination has length {d}", .{dest_len}); |
| 31467 | try sema.errNote(block, inst_src, msg, "source has length {d}", .{inst_len}); | 31319 | try sema.errNote(inst_src, msg, "source has length {d}", .{inst_len}); |
| 31468 | break :msg msg; | 31320 | break :msg msg; |
| 31469 | }; | 31321 | }; |
| 31470 | return sema.failWithOwnedErrorMsg(block, msg); | 31322 | return sema.failWithOwnedErrorMsg(block, msg); |
| ... | @@ -31546,12 +31398,12 @@ fn coerceTupleToArray( | ... | @@ -31546,12 +31398,12 @@ fn coerceTupleToArray( |
| 31546 | | 31398 | |
| 31547 | if (dest_len != inst_len) { | 31399 | if (dest_len != inst_len) { |
| 31548 | const msg = msg: { | 31400 | const msg = msg: { |
| 31549 | const msg = try sema.errMsg(block, inst_src, "expected type '{}', found '{}'", .{ | 31401 | const msg = try sema.errMsg(inst_src, "expected type '{}', found '{}'", .{ |
| 31550 | dest_ty.fmt(sema.mod), inst_ty.fmt(sema.mod), | 31402 | dest_ty.fmt(sema.mod), inst_ty.fmt(sema.mod), |
| 31551 | }); | 31403 | }); |
| 31552 | errdefer msg.destroy(sema.gpa); | 31404 | errdefer msg.destroy(sema.gpa); |
| 31553 | try sema.errNote(block, dest_ty_src, msg, "destination has length {d}", .{dest_len}); | 31405 | try sema.errNote(dest_ty_src, msg, "destination has length {d}", .{dest_len}); |
| 31554 | try sema.errNote(block, inst_src, msg, "source has length {d}", .{inst_len}); | 31406 | try sema.errNote(inst_src, msg, "source has length {d}", .{inst_len}); |
| 31555 | break :msg msg; | 31407 | break :msg msg; |
| 31556 | }; | 31408 | }; |
| 31557 | return sema.failWithOwnedErrorMsg(block, msg); | 31409 | return sema.failWithOwnedErrorMsg(block, msg); |
| ... | @@ -31722,9 +31574,9 @@ fn coerceTupleToStruct( | ... | @@ -31722,9 +31574,9 @@ fn coerceTupleToStruct( |
| 31722 | const template = "missing struct field: {}"; | 31574 | const template = "missing struct field: {}"; |
| 31723 | const args = .{field_name.fmt(ip)}; | 31575 | const args = .{field_name.fmt(ip)}; |
| 31724 | if (root_msg) |msg| { | 31576 | if (root_msg) |msg| { |
| 31725 | try sema.errNote(block, field_src, msg, template, args); | 31577 | try sema.errNote(field_src, msg, template, args); |
| 31726 | } else { | 31578 | } else { |
| 31727 | root_msg = try sema.errMsg(block, field_src, template, args); | 31579 | root_msg = try sema.errMsg(field_src, template, args); |
| 31728 | } | 31580 | } |
| 31729 | continue; | 31581 | continue; |
| 31730 | } | 31582 | } |
| ... | @@ -31860,18 +31712,18 @@ fn coerceTupleToTuple( | ... | @@ -31860,18 +31712,18 @@ fn coerceTupleToTuple( |
| 31860 | const field_name = tuple_ty.structFieldName(i, mod).unwrap() orelse { | 31712 | const field_name = tuple_ty.structFieldName(i, mod).unwrap() orelse { |
| 31861 | const template = "missing tuple field: {d}"; | 31713 | const template = "missing tuple field: {d}"; |
| 31862 | if (root_msg) |msg| { | 31714 | if (root_msg) |msg| { |
| 31863 | try sema.errNote(block, field_src, msg, template, .{i}); | 31715 | try sema.errNote(field_src, msg, template, .{i}); |
| 31864 | } else { | 31716 | } else { |
| 31865 | root_msg = try sema.errMsg(block, field_src, template, .{i}); | 31717 | root_msg = try sema.errMsg(field_src, template, .{i}); |
| 31866 | } | 31718 | } |
| 31867 | continue; | 31719 | continue; |
| 31868 | }; | 31720 | }; |
| 31869 | const template = "missing struct field: {}"; | 31721 | const template = "missing struct field: {}"; |
| 31870 | const args = .{field_name.fmt(ip)}; | 31722 | const args = .{field_name.fmt(ip)}; |
| 31871 | if (root_msg) |msg| { | 31723 | if (root_msg) |msg| { |
| 31872 | try sema.errNote(block, field_src, msg, template, args); | 31724 | try sema.errNote(field_src, msg, template, args); |
| 31873 | } else { | 31725 | } else { |
| 31874 | root_msg = try sema.errMsg(block, field_src, template, args); | 31726 | root_msg = try sema.errMsg(field_src, template, args); |
| 31875 | } | 31727 | } |
| 31876 | continue; | 31728 | continue; |
| 31877 | } | 31729 | } |
| ... | @@ -31926,14 +31778,6 @@ fn addReferencedBy( | ... | @@ -31926,14 +31778,6 @@ fn addReferencedBy( |
| 31926 | decl_index: InternPool.DeclIndex, | 31778 | decl_index: InternPool.DeclIndex, |
| 31927 | ) !void { | 31779 | ) !void { |
| 31928 | if (sema.mod.comp.reference_trace == 0) return; | 31780 | if (sema.mod.comp.reference_trace == 0) return; |
| 31929 | if (src == .unneeded) { | | |
| 31930 | // We can't use NeededSourceLocation, since sites handling that assume it means a compile | | |
| 31931 | // error. Our long-term strategy here is to gradually transition from NeededSourceLocation | | |
| 31932 | // into having more LazySrcLoc tags. In the meantime, let release compilers just ignore this | | |
| 31933 | // reference (a slightly-incomplete error is better than a crash!), but trigger a panic in | | |
| 31934 | // debug so we can fix this case. | | |
| 31935 | if (std.debug.runtime_safety) unreachable else return; | | |
| 31936 | } | | |
| 31937 | try sema.mod.reference_table.put(sema.gpa, decl_index, .{ | 31781 | try sema.mod.reference_table.put(sema.gpa, decl_index, .{ |
| 31938 | .referencer = block.src_decl, | 31782 | .referencer = block.src_decl, |
| 31939 | .src = src, | 31783 | .src = src, |
| ... | @@ -31945,7 +31789,10 @@ pub fn ensureDeclAnalyzed(sema: *Sema, decl_index: InternPool.DeclIndex) Compile | ... | @@ -31945,7 +31789,10 @@ pub fn ensureDeclAnalyzed(sema: *Sema, decl_index: InternPool.DeclIndex) Compile |
| 31945 | const ip = &mod.intern_pool; | 31789 | const ip = &mod.intern_pool; |
| 31946 | const decl = mod.declPtr(decl_index); | 31790 | const decl = mod.declPtr(decl_index); |
| 31947 | if (decl.analysis == .in_progress) { | 31791 | if (decl.analysis == .in_progress) { |
| 31948 | const msg = try Module.ErrorMsg.create(sema.gpa, decl.srcLoc(mod), "dependency loop detected", .{}); | 31792 | const msg = try sema.errMsg(.{ |
| | 31793 | .base_node_inst = decl.zir_decl_index.unwrap().?, |
| | 31794 | .offset = LazySrcLoc.Offset.nodeOffset(0), |
| | 31795 | }, "dependency loop detected", .{}); |
| 31949 | return sema.failWithOwnedErrorMsg(null, msg); | 31796 | return sema.failWithOwnedErrorMsg(null, msg); |
| 31950 | } | 31797 | } |
| 31951 | | 31798 | |
| ... | @@ -32440,10 +32287,9 @@ fn analyzeSlice( | ... | @@ -32440,10 +32287,9 @@ fn analyzeSlice( |
| 32440 | if (try sema.compareScalar(start_value, .neq, end_value, Type.comptime_int)) { | 32287 | if (try sema.compareScalar(start_value, .neq, end_value, Type.comptime_int)) { |
| 32441 | if (try sema.compareScalar(start_value, .neq, Value.zero_comptime_int, Type.comptime_int)) { | 32288 | if (try sema.compareScalar(start_value, .neq, Value.zero_comptime_int, Type.comptime_int)) { |
| 32442 | const msg = msg: { | 32289 | const msg = msg: { |
| 32443 | const msg = try sema.errMsg(block, start_src, bounds_error_message, .{}); | 32290 | const msg = try sema.errMsg(start_src, bounds_error_message, .{}); |
| 32444 | errdefer msg.destroy(sema.gpa); | 32291 | errdefer msg.destroy(sema.gpa); |
| 32445 | try sema.errNote( | 32292 | try sema.errNote( |
| 32446 | block, | | |
| 32447 | start_src, | 32293 | start_src, |
| 32448 | msg, | 32294 | msg, |
| 32449 | "expected '{}', found '{}'", | 32295 | "expected '{}', found '{}'", |
| ... | @@ -32457,10 +32303,9 @@ fn analyzeSlice( | ... | @@ -32457,10 +32303,9 @@ fn analyzeSlice( |
| 32457 | return sema.failWithOwnedErrorMsg(block, msg); | 32303 | return sema.failWithOwnedErrorMsg(block, msg); |
| 32458 | } else if (try sema.compareScalar(end_value, .neq, Value.one_comptime_int, Type.comptime_int)) { | 32304 | } else if (try sema.compareScalar(end_value, .neq, Value.one_comptime_int, Type.comptime_int)) { |
| 32459 | const msg = msg: { | 32305 | const msg = msg: { |
| 32460 | const msg = try sema.errMsg(block, end_src, bounds_error_message, .{}); | 32306 | const msg = try sema.errMsg(end_src, bounds_error_message, .{}); |
| 32461 | errdefer msg.destroy(sema.gpa); | 32307 | errdefer msg.destroy(sema.gpa); |
| 32462 | try sema.errNote( | 32308 | try sema.errNote( |
| 32463 | block, | | |
| 32464 | end_src, | 32309 | end_src, |
| 32465 | msg, | 32310 | msg, |
| 32466 | "expected '{}', found '{}'", | 32311 | "expected '{}', found '{}'", |
| ... | @@ -32714,9 +32559,9 @@ fn analyzeSlice( | ... | @@ -32714,9 +32559,9 @@ fn analyzeSlice( |
| 32714 | | 32559 | |
| 32715 | if (!actual_sentinel.eql(expected_sentinel, elem_ty, mod)) { | 32560 | if (!actual_sentinel.eql(expected_sentinel, elem_ty, mod)) { |
| 32716 | const msg = msg: { | 32561 | const msg = msg: { |
| 32717 | const msg = try sema.errMsg(block, src, "value in memory does not match slice sentinel", .{}); | 32562 | const msg = try sema.errMsg(src, "value in memory does not match slice sentinel", .{}); |
| 32718 | errdefer msg.destroy(sema.gpa); | 32563 | errdefer msg.destroy(sema.gpa); |
| 32719 | try sema.errNote(block, src, msg, "expected '{}', found '{}'", .{ | 32564 | try sema.errNote(src, msg, "expected '{}', found '{}'", .{ |
| 32720 | expected_sentinel.fmtValue(mod, sema), | 32565 | expected_sentinel.fmtValue(mod, sema), |
| 32721 | actual_sentinel.fmtValue(mod, sema), | 32566 | actual_sentinel.fmtValue(mod, sema), |
| 32722 | }); | 32567 | }); |
| ... | @@ -33588,6 +33433,31 @@ const PeerResolveStrategy = enum { | ... | @@ -33588,6 +33433,31 @@ const PeerResolveStrategy = enum { |
| 33588 | } | 33433 | } |
| 33589 | }; | 33434 | }; |
| 33590 | | 33435 | |
| | 33436 | const PeerTypeCandidateSrc = union(enum) { |
| | 33437 | /// Do not print out error notes for candidate sources |
| | 33438 | none: void, |
| | 33439 | /// When we want to know the the src of candidate i, look up at |
| | 33440 | /// index i in this slice |
| | 33441 | override: []const ?LazySrcLoc, |
| | 33442 | /// resolvePeerTypes originates from a @TypeOf(...) call |
| | 33443 | typeof_builtin_call_node_offset: i32, |
| | 33444 | |
| | 33445 | pub fn resolve( |
| | 33446 | self: PeerTypeCandidateSrc, |
| | 33447 | block: *Block, |
| | 33448 | candidate_i: usize, |
| | 33449 | ) ?LazySrcLoc { |
| | 33450 | return switch (self) { |
| | 33451 | .none => null, |
| | 33452 | .override => |candidate_srcs| if (candidate_i >= candidate_srcs.len) |
| | 33453 | null |
| | 33454 | else |
| | 33455 | candidate_srcs[candidate_i], |
| | 33456 | .typeof_builtin_call_node_offset => |node_offset| block.builtinCallArgSrc(node_offset, @intCast(candidate_i)), |
| | 33457 | }; |
| | 33458 | } |
| | 33459 | }; |
| | 33460 | |
| 33591 | const PeerResolveResult = union(enum) { | 33461 | const PeerResolveResult = union(enum) { |
| 33592 | /// The peer type resolution was successful, and resulted in the given type. | 33462 | /// The peer type resolution was successful, and resulted in the given type. |
| 33593 | success: Type, | 33463 | success: Type, |
| ... | @@ -33612,10 +33482,9 @@ const PeerResolveResult = union(enum) { | ... | @@ -33612,10 +33482,9 @@ const PeerResolveResult = union(enum) { |
| 33612 | block: *Block, | 33482 | block: *Block, |
| 33613 | src: LazySrcLoc, | 33483 | src: LazySrcLoc, |
| 33614 | instructions: []const Air.Inst.Ref, | 33484 | instructions: []const Air.Inst.Ref, |
| 33615 | candidate_srcs: Module.PeerTypeCandidateSrc, | 33485 | candidate_srcs: PeerTypeCandidateSrc, |
| 33616 | ) !*Module.ErrorMsg { | 33486 | ) !*Module.ErrorMsg { |
| 33617 | const mod = sema.mod; | 33487 | const mod = sema.mod; |
| 33618 | const decl_ptr = mod.declPtr(block.src_decl); | | |
| 33619 | | 33488 | |
| 33620 | var opt_msg: ?*Module.ErrorMsg = null; | 33489 | var opt_msg: ?*Module.ErrorMsg = null; |
| 33621 | errdefer if (opt_msg) |msg| msg.destroy(sema.gpa); | 33490 | errdefer if (opt_msg) |msg| msg.destroy(sema.gpa); |
| ... | @@ -33643,9 +33512,9 @@ const PeerResolveResult = union(enum) { | ... | @@ -33643,9 +33512,9 @@ const PeerResolveResult = union(enum) { |
| 33643 | const fmt = "struct field '{}' has conflicting types"; | 33512 | const fmt = "struct field '{}' has conflicting types"; |
| 33644 | const args = .{field_error.field_name.fmt(&mod.intern_pool)}; | 33513 | const args = .{field_error.field_name.fmt(&mod.intern_pool)}; |
| 33645 | if (opt_msg) |msg| { | 33514 | if (opt_msg) |msg| { |
| 33646 | try sema.errNote(block, src, msg, fmt, args); | 33515 | try sema.errNote(src, msg, fmt, args); |
| 33647 | } else { | 33516 | } else { |
| 33648 | opt_msg = try sema.errMsg(block, src, fmt, args); | 33517 | opt_msg = try sema.errMsg(src, fmt, args); |
| 33649 | } | 33518 | } |
| 33650 | | 33519 | |
| 33651 | // Continue on to child error | 33520 | // Continue on to child error |
| ... | @@ -33667,8 +33536,8 @@ const PeerResolveResult = union(enum) { | ... | @@ -33667,8 +33536,8 @@ const PeerResolveResult = union(enum) { |
| 33667 | peer_tys[conflict_idx[1]], | 33536 | peer_tys[conflict_idx[1]], |
| 33668 | }; | 33537 | }; |
| 33669 | const conflict_srcs: [2]?LazySrcLoc = .{ | 33538 | const conflict_srcs: [2]?LazySrcLoc = .{ |
| 33670 | candidate_srcs.resolve(mod, decl_ptr, conflict_idx[0]), | 33539 | candidate_srcs.resolve(block, conflict_idx[0]), |
| 33671 | candidate_srcs.resolve(mod, decl_ptr, conflict_idx[1]), | 33540 | candidate_srcs.resolve(block, conflict_idx[1]), |
| 33672 | }; | 33541 | }; |
| 33673 | | 33542 | |
| 33674 | const fmt = "incompatible types: '{}' and '{}'"; | 33543 | const fmt = "incompatible types: '{}' and '{}'"; |
| ... | @@ -33677,16 +33546,16 @@ const PeerResolveResult = union(enum) { | ... | @@ -33677,16 +33546,16 @@ const PeerResolveResult = union(enum) { |
| 33677 | conflict_tys[1].fmt(mod), | 33546 | conflict_tys[1].fmt(mod), |
| 33678 | }; | 33547 | }; |
| 33679 | const msg = if (opt_msg) |msg| msg: { | 33548 | const msg = if (opt_msg) |msg| msg: { |
| 33680 | try sema.errNote(block, src, msg, fmt, args); | 33549 | try sema.errNote(src, msg, fmt, args); |
| 33681 | break :msg msg; | 33550 | break :msg msg; |
| 33682 | } else msg: { | 33551 | } else msg: { |
| 33683 | const msg = try sema.errMsg(block, src, fmt, args); | 33552 | const msg = try sema.errMsg(src, fmt, args); |
| 33684 | opt_msg = msg; | 33553 | opt_msg = msg; |
| 33685 | break :msg msg; | 33554 | break :msg msg; |
| 33686 | }; | 33555 | }; |
| 33687 | | 33556 | |
| 33688 | if (conflict_srcs[0]) |src_loc| try sema.errNote(block, src_loc, msg, "type '{}' here", .{conflict_tys[0].fmt(mod)}); | 33557 | if (conflict_srcs[0]) |src_loc| try sema.errNote(src_loc, msg, "type '{}' here", .{conflict_tys[0].fmt(mod)}); |
| 33689 | if (conflict_srcs[1]) |src_loc| try sema.errNote(block, src_loc, msg, "type '{}' here", .{conflict_tys[1].fmt(mod)}); | 33558 | if (conflict_srcs[1]) |src_loc| try sema.errNote(src_loc, msg, "type '{}' here", .{conflict_tys[1].fmt(mod)}); |
| 33690 | | 33559 | |
| 33691 | // No child error | 33560 | // No child error |
| 33692 | break; | 33561 | break; |
| ... | @@ -33701,7 +33570,7 @@ fn resolvePeerTypes( | ... | @@ -33701,7 +33570,7 @@ fn resolvePeerTypes( |
| 33701 | block: *Block, | 33570 | block: *Block, |
| 33702 | src: LazySrcLoc, | 33571 | src: LazySrcLoc, |
| 33703 | instructions: []const Air.Inst.Ref, | 33572 | instructions: []const Air.Inst.Ref, |
| 33704 | candidate_srcs: Module.PeerTypeCandidateSrc, | 33573 | candidate_srcs: PeerTypeCandidateSrc, |
| 33705 | ) !Type { | 33574 | ) !Type { |
| 33706 | switch (instructions.len) { | 33575 | switch (instructions.len) { |
| 33707 | 0 => return Type.noreturn, | 33576 | 0 => return Type.noreturn, |
| ... | @@ -35140,9 +35009,9 @@ pub fn resolveStructAlignment( | ... | @@ -35140,9 +35009,9 @@ pub fn resolveStructAlignment( |
| 35140 | } | 35009 | } |
| 35141 | | 35010 | |
| 35142 | fn resolveStructLayout(sema: *Sema, ty: Type) CompileError!void { | 35011 | fn resolveStructLayout(sema: *Sema, ty: Type) CompileError!void { |
| 35143 | const mod = sema.mod; | 35012 | const zcu = sema.mod; |
| 35144 | const ip = &mod.intern_pool; | 35013 | const ip = &zcu.intern_pool; |
| 35145 | const struct_type = mod.typeToStruct(ty) orelse return; | 35014 | const struct_type = zcu.typeToStruct(ty) orelse return; |
| 35146 | | 35015 | |
| 35147 | if (struct_type.haveLayout(ip)) | 35016 | if (struct_type.haveLayout(ip)) |
| 35148 | return; | 35017 | return; |
| ... | @@ -35150,16 +35019,15 @@ fn resolveStructLayout(sema: *Sema, ty: Type) CompileError!void { | ... | @@ -35150,16 +35019,15 @@ fn resolveStructLayout(sema: *Sema, ty: Type) CompileError!void { |
| 35150 | try sema.resolveTypeFields(ty); | 35019 | try sema.resolveTypeFields(ty); |
| 35151 | | 35020 | |
| 35152 | if (struct_type.layout == .@"packed") { | 35021 | if (struct_type.layout == .@"packed") { |
| 35153 | try semaBackingIntType(mod, struct_type); | 35022 | try semaBackingIntType(zcu, struct_type); |
| 35154 | return; | 35023 | return; |
| 35155 | } | 35024 | } |
| 35156 | | 35025 | |
| 35157 | if (struct_type.setLayoutWip(ip)) { | 35026 | if (struct_type.setLayoutWip(ip)) { |
| 35158 | const msg = try Module.ErrorMsg.create( | 35027 | const msg = try sema.errMsg( |
| 35159 | sema.gpa, | 35028 | ty.srcLoc(zcu), |
| 35160 | mod.declPtr(struct_type.decl.unwrap().?).srcLoc(mod), | | |
| 35161 | "struct '{}' depends on itself", | 35029 | "struct '{}' depends on itself", |
| 35162 | .{ty.fmt(mod)}, | 35030 | .{ty.fmt(zcu)}, |
| 35163 | ); | 35031 | ); |
| 35164 | return sema.failWithOwnedErrorMsg(null, msg); | 35032 | return sema.failWithOwnedErrorMsg(null, msg); |
| 35165 | } | 35033 | } |
| ... | @@ -35196,9 +35064,8 @@ fn resolveStructLayout(sema: *Sema, ty: Type) CompileError!void { | ... | @@ -35196,9 +35064,8 @@ fn resolveStructLayout(sema: *Sema, ty: Type) CompileError!void { |
| 35196 | } | 35064 | } |
| 35197 | | 35065 | |
| 35198 | if (struct_type.flagsPtr(ip).assumed_runtime_bits and !(try sema.typeHasRuntimeBits(ty))) { | 35066 | if (struct_type.flagsPtr(ip).assumed_runtime_bits and !(try sema.typeHasRuntimeBits(ty))) { |
| 35199 | const msg = try Module.ErrorMsg.create( | 35067 | const msg = try sema.errMsg( |
| 35200 | sema.gpa, | 35068 | ty.srcLoc(zcu), |
| 35201 | mod.declPtr(struct_type.decl.unwrap().?).srcLoc(mod), | | |
| 35202 | "struct layout depends on it having runtime bits", | 35069 | "struct layout depends on it having runtime bits", |
| 35203 | .{}, | 35070 | .{}, |
| 35204 | ); | 35071 | ); |
| ... | @@ -35206,11 +35073,10 @@ fn resolveStructLayout(sema: *Sema, ty: Type) CompileError!void { | ... | @@ -35206,11 +35073,10 @@ fn resolveStructLayout(sema: *Sema, ty: Type) CompileError!void { |
| 35206 | } | 35073 | } |
| 35207 | | 35074 | |
| 35208 | if (struct_type.flagsPtr(ip).assumed_pointer_aligned and | 35075 | if (struct_type.flagsPtr(ip).assumed_pointer_aligned and |
| 35209 | big_align.compareStrict(.neq, Alignment.fromByteUnits(@divExact(mod.getTarget().ptrBitWidth(), 8)))) | 35076 | big_align.compareStrict(.neq, Alignment.fromByteUnits(@divExact(zcu.getTarget().ptrBitWidth(), 8)))) |
| 35210 | { | 35077 | { |
| 35211 | const msg = try Module.ErrorMsg.create( | 35078 | const msg = try sema.errMsg( |
| 35212 | sema.gpa, | 35079 | ty.srcLoc(zcu), |
| 35213 | mod.declPtr(struct_type.decl.unwrap().?).srcLoc(mod), | | |
| 35214 | "struct layout depends on being pointer aligned", | 35080 | "struct layout depends on being pointer aligned", |
| 35215 | .{}, | 35081 | .{}, |
| 35216 | ); | 35082 | ); |
| ... | @@ -35242,7 +35108,7 @@ fn resolveStructLayout(sema: *Sema, ty: Type) CompileError!void { | ... | @@ -35242,7 +35108,7 @@ fn resolveStructLayout(sema: *Sema, ty: Type) CompileError!void { |
| 35242 | return a_align.compare(.gt, b_align); | 35108 | return a_align.compare(.gt, b_align); |
| 35243 | } | 35109 | } |
| 35244 | }; | 35110 | }; |
| 35245 | if (struct_type.isTuple(ip) or !mod.backendSupportsFeature(.field_reordering)) { | 35111 | if (struct_type.isTuple(ip) or !zcu.backendSupportsFeature(.field_reordering)) { |
| 35246 | // TODO: don't handle tuples differently. This logic exists only because it | 35112 | // TODO: don't handle tuples differently. This logic exists only because it |
| 35247 | // uncovers latent bugs if removed. Fix the latent bugs and remove this logic! | 35113 | // uncovers latent bugs if removed. Fix the latent bugs and remove this logic! |
| 35248 | // Likewise, implement field reordering support in all the backends! | 35114 | // Likewise, implement field reordering support in all the backends! |
| ... | @@ -35293,7 +35159,7 @@ fn semaBackingIntType(mod: *Module, struct_type: InternPool.LoadedStructType) Co | ... | @@ -35293,7 +35159,7 @@ fn semaBackingIntType(mod: *Module, struct_type: InternPool.LoadedStructType) Co |
| 35293 | var analysis_arena = std.heap.ArenaAllocator.init(gpa); | 35159 | var analysis_arena = std.heap.ArenaAllocator.init(gpa); |
| 35294 | defer analysis_arena.deinit(); | 35160 | defer analysis_arena.deinit(); |
| 35295 | | 35161 | |
| 35296 | var comptime_err_ret_trace = std.ArrayList(Module.SrcLoc).init(gpa); | 35162 | var comptime_err_ret_trace = std.ArrayList(LazySrcLoc).init(gpa); |
| 35297 | defer comptime_err_ret_trace.deinit(); | 35163 | defer comptime_err_ret_trace.deinit(); |
| 35298 | | 35164 | |
| 35299 | var sema: Sema = .{ | 35165 | var sema: Sema = .{ |
| ... | @@ -35320,6 +35186,7 @@ fn semaBackingIntType(mod: *Module, struct_type: InternPool.LoadedStructType) Co | ... | @@ -35320,6 +35186,7 @@ fn semaBackingIntType(mod: *Module, struct_type: InternPool.LoadedStructType) Co |
| 35320 | .instructions = .{}, | 35186 | .instructions = .{}, |
| 35321 | .inlining = null, | 35187 | .inlining = null, |
| 35322 | .is_comptime = true, | 35188 | .is_comptime = true, |
| | 35189 | .src_base_inst = struct_type.zir_index.unwrap().?, |
| 35323 | }; | 35190 | }; |
| 35324 | defer assert(block.instructions.items.len == 0); | 35191 | defer assert(block.instructions.items.len == 0); |
| 35325 | | 35192 | |
| ... | @@ -35352,7 +35219,10 @@ fn semaBackingIntType(mod: *Module, struct_type: InternPool.LoadedStructType) Co | ... | @@ -35352,7 +35219,10 @@ fn semaBackingIntType(mod: *Module, struct_type: InternPool.LoadedStructType) Co |
| 35352 | const backing_int_body_len = zir.extra[extra_index]; | 35219 | const backing_int_body_len = zir.extra[extra_index]; |
| 35353 | extra_index += 1; | 35220 | extra_index += 1; |
| 35354 | | 35221 | |
| 35355 | const backing_int_src: LazySrcLoc = .{ .node_offset_container_tag = 0 }; | 35222 | const backing_int_src: LazySrcLoc = .{ |
| | 35223 | .base_node_inst = struct_type.zir_index.unwrap().?, |
| | 35224 | .offset = .{ .node_offset_container_tag = 0 }, |
| | 35225 | }; |
| 35356 | const backing_int_ty = blk: { | 35226 | const backing_int_ty = blk: { |
| 35357 | if (backing_int_body_len == 0) { | 35227 | if (backing_int_body_len == 0) { |
| 35358 | const backing_int_ref: Zir.Inst.Ref = @enumFromInt(zir.extra[extra_index]); | 35228 | const backing_int_ref: Zir.Inst.Ref = @enumFromInt(zir.extra[extra_index]); |
| ... | @@ -35368,7 +35238,7 @@ fn semaBackingIntType(mod: *Module, struct_type: InternPool.LoadedStructType) Co | ... | @@ -35368,7 +35238,7 @@ fn semaBackingIntType(mod: *Module, struct_type: InternPool.LoadedStructType) Co |
| 35368 | struct_type.backingIntType(ip).* = backing_int_ty.toIntern(); | 35238 | struct_type.backingIntType(ip).* = backing_int_ty.toIntern(); |
| 35369 | } else { | 35239 | } else { |
| 35370 | if (fields_bit_sum > std.math.maxInt(u16)) { | 35240 | if (fields_bit_sum > std.math.maxInt(u16)) { |
| 35371 | return sema.fail(&block, LazySrcLoc.nodeOffset(0), "size of packed struct '{d}' exceeds maximum bit width of 65535", .{fields_bit_sum}); | 35241 | return sema.fail(&block, block.nodeOffset(0), "size of packed struct '{d}' exceeds maximum bit width of 65535", .{fields_bit_sum}); |
| 35372 | } | 35242 | } |
| 35373 | const backing_int_ty = try mod.intType(.unsigned, @intCast(fields_bit_sum)); | 35243 | const backing_int_ty = try mod.intType(.unsigned, @intCast(fields_bit_sum)); |
| 35374 | struct_type.backingIntType(ip).* = backing_int_ty.toIntern(); | 35244 | struct_type.backingIntType(ip).* = backing_int_ty.toIntern(); |
| ... | @@ -35395,9 +35265,9 @@ fn checkIndexable(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) !void { | ... | @@ -35395,9 +35265,9 @@ fn checkIndexable(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) !void { |
| 35395 | const mod = sema.mod; | 35265 | const mod = sema.mod; |
| 35396 | if (!ty.isIndexable(mod)) { | 35266 | if (!ty.isIndexable(mod)) { |
| 35397 | const msg = msg: { | 35267 | const msg = msg: { |
| 35398 | const msg = try sema.errMsg(block, src, "type '{}' does not support indexing", .{ty.fmt(sema.mod)}); | 35268 | const msg = try sema.errMsg(src, "type '{}' does not support indexing", .{ty.fmt(sema.mod)}); |
| 35399 | errdefer msg.destroy(sema.gpa); | 35269 | errdefer msg.destroy(sema.gpa); |
| 35400 | try sema.errNote(block, src, msg, "operand must be an array, slice, tuple, or vector", .{}); | 35270 | try sema.errNote(src, msg, "operand must be an array, slice, tuple, or vector", .{}); |
| 35401 | break :msg msg; | 35271 | break :msg msg; |
| 35402 | }; | 35272 | }; |
| 35403 | return sema.failWithOwnedErrorMsg(block, msg); | 35273 | return sema.failWithOwnedErrorMsg(block, msg); |
| ... | @@ -35418,9 +35288,9 @@ fn checkMemOperand(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) !void | ... | @@ -35418,9 +35288,9 @@ fn checkMemOperand(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) !void |
| 35418 | } | 35288 | } |
| 35419 | } | 35289 | } |
| 35420 | const msg = msg: { | 35290 | const msg = msg: { |
| 35421 | const msg = try sema.errMsg(block, src, "type '{}' is not an indexable pointer", .{ty.fmt(sema.mod)}); | 35291 | const msg = try sema.errMsg(src, "type '{}' is not an indexable pointer", .{ty.fmt(sema.mod)}); |
| 35422 | errdefer msg.destroy(sema.gpa); | 35292 | errdefer msg.destroy(sema.gpa); |
| 35423 | try sema.errNote(block, src, msg, "operand must be a slice, a many pointer or a pointer to an array", .{}); | 35293 | try sema.errNote(src, msg, "operand must be a slice, a many pointer or a pointer to an array", .{}); |
| 35424 | break :msg msg; | 35294 | break :msg msg; |
| 35425 | }; | 35295 | }; |
| 35426 | return sema.failWithOwnedErrorMsg(block, msg); | 35296 | return sema.failWithOwnedErrorMsg(block, msg); |
| ... | @@ -35471,8 +35341,8 @@ pub fn resolveUnionAlignment( | ... | @@ -35471,8 +35341,8 @@ pub fn resolveUnionAlignment( |
| 35471 | | 35341 | |
| 35472 | /// This logic must be kept in sync with `Module.getUnionLayout`. | 35342 | /// This logic must be kept in sync with `Module.getUnionLayout`. |
| 35473 | fn resolveUnionLayout(sema: *Sema, ty: Type) CompileError!void { | 35343 | fn resolveUnionLayout(sema: *Sema, ty: Type) CompileError!void { |
| 35474 | const mod = sema.mod; | 35344 | const zcu = sema.mod; |
| 35475 | const ip = &mod.intern_pool; | 35345 | const ip = &zcu.intern_pool; |
| 35476 | | 35346 | |
| 35477 | try sema.resolveTypeFieldsUnion(ty, ip.loadUnionType(ty.ip_index)); | 35347 | try sema.resolveTypeFieldsUnion(ty, ip.loadUnionType(ty.ip_index)); |
| 35478 | | 35348 | |
| ... | @@ -35482,11 +35352,10 @@ fn resolveUnionLayout(sema: *Sema, ty: Type) CompileError!void { | ... | @@ -35482,11 +35352,10 @@ fn resolveUnionLayout(sema: *Sema, ty: Type) CompileError!void { |
| 35482 | switch (union_type.flagsPtr(ip).status) { | 35352 | switch (union_type.flagsPtr(ip).status) { |
| 35483 | .none, .have_field_types => {}, | 35353 | .none, .have_field_types => {}, |
| 35484 | .field_types_wip, .layout_wip => { | 35354 | .field_types_wip, .layout_wip => { |
| 35485 | const msg = try Module.ErrorMsg.create( | 35355 | const msg = try sema.errMsg( |
| 35486 | sema.gpa, | 35356 | ty.srcLoc(zcu), |
| 35487 | mod.declPtr(union_type.decl).srcLoc(mod), | | |
| 35488 | "union '{}' depends on itself", | 35357 | "union '{}' depends on itself", |
| 35489 | .{ty.fmt(mod)}, | 35358 | .{ty.fmt(zcu)}, |
| 35490 | ); | 35359 | ); |
| 35491 | return sema.failWithOwnedErrorMsg(null, msg); | 35360 | return sema.failWithOwnedErrorMsg(null, msg); |
| 35492 | }, | 35361 | }, |
| ... | @@ -35505,7 +35374,7 @@ fn resolveUnionLayout(sema: *Sema, ty: Type) CompileError!void { | ... | @@ -35505,7 +35374,7 @@ fn resolveUnionLayout(sema: *Sema, ty: Type) CompileError!void { |
| 35505 | for (0..union_type.field_types.len) |field_index| { | 35374 | for (0..union_type.field_types.len) |field_index| { |
| 35506 | const field_ty = Type.fromInterned(union_type.field_types.get(ip)[field_index]); | 35375 | const field_ty = Type.fromInterned(union_type.field_types.get(ip)[field_index]); |
| 35507 | | 35376 | |
| 35508 | if (try sema.typeRequiresComptime(field_ty) or field_ty.zigTypeTag(mod) == .NoReturn) continue; // TODO: should this affect alignment? | 35377 | if (try sema.typeRequiresComptime(field_ty) or field_ty.zigTypeTag(zcu) == .NoReturn) continue; // TODO: should this affect alignment? |
| 35509 | | 35378 | |
| 35510 | max_size = @max(max_size, sema.typeAbiSize(field_ty) catch |err| switch (err) { | 35379 | max_size = @max(max_size, sema.typeAbiSize(field_ty) catch |err| switch (err) { |
| 35511 | error.AnalysisFail => { | 35380 | error.AnalysisFail => { |
| ... | @@ -35547,7 +35416,7 @@ fn resolveUnionLayout(sema: *Sema, ty: Type) CompileError!void { | ... | @@ -35547,7 +35416,7 @@ fn resolveUnionLayout(sema: *Sema, ty: Type) CompileError!void { |
| 35547 | } else { | 35416 | } else { |
| 35548 | // {Payload, Tag} | 35417 | // {Payload, Tag} |
| 35549 | size += max_size; | 35418 | size += max_size; |
| 35550 | size = switch (mod.getTarget().ofmt) { | 35419 | size = switch (zcu.getTarget().ofmt) { |
| 35551 | .c => max_align, | 35420 | .c => max_align, |
| 35552 | else => tag_align, | 35421 | else => tag_align, |
| 35553 | }.forward(size); | 35422 | }.forward(size); |
| ... | @@ -35566,9 +35435,8 @@ fn resolveUnionLayout(sema: *Sema, ty: Type) CompileError!void { | ... | @@ -35566,9 +35435,8 @@ fn resolveUnionLayout(sema: *Sema, ty: Type) CompileError!void { |
| 35566 | flags.status = .have_layout; | 35435 | flags.status = .have_layout; |
| 35567 | | 35436 | |
| 35568 | if (union_type.flagsPtr(ip).assumed_runtime_bits and !(try sema.typeHasRuntimeBits(ty))) { | 35437 | if (union_type.flagsPtr(ip).assumed_runtime_bits and !(try sema.typeHasRuntimeBits(ty))) { |
| 35569 | const msg = try Module.ErrorMsg.create( | 35438 | const msg = try sema.errMsg( |
| 35570 | sema.gpa, | 35439 | ty.srcLoc(zcu), |
| 35571 | mod.declPtr(union_type.decl).srcLoc(mod), | | |
| 35572 | "union layout depends on it having runtime bits", | 35440 | "union layout depends on it having runtime bits", |
| 35573 | .{}, | 35441 | .{}, |
| 35574 | ); | 35442 | ); |
| ... | @@ -35576,11 +35444,10 @@ fn resolveUnionLayout(sema: *Sema, ty: Type) CompileError!void { | ... | @@ -35576,11 +35444,10 @@ fn resolveUnionLayout(sema: *Sema, ty: Type) CompileError!void { |
| 35576 | } | 35444 | } |
| 35577 | | 35445 | |
| 35578 | if (union_type.flagsPtr(ip).assumed_pointer_aligned and | 35446 | if (union_type.flagsPtr(ip).assumed_pointer_aligned and |
| 35579 | alignment.compareStrict(.neq, Alignment.fromByteUnits(@divExact(mod.getTarget().ptrBitWidth(), 8)))) | 35447 | alignment.compareStrict(.neq, Alignment.fromByteUnits(@divExact(zcu.getTarget().ptrBitWidth(), 8)))) |
| 35580 | { | 35448 | { |
| 35581 | const msg = try Module.ErrorMsg.create( | 35449 | const msg = try sema.errMsg( |
| 35582 | sema.gpa, | 35450 | ty.srcLoc(zcu), |
| 35583 | mod.declPtr(union_type.decl).srcLoc(mod), | | |
| 35584 | "union layout depends on being pointer aligned", | 35451 | "union layout depends on being pointer aligned", |
| 35585 | .{}, | 35452 | .{}, |
| 35586 | ); | 35453 | ); |
| ... | @@ -35804,12 +35671,12 @@ pub fn resolveTypeFieldsStruct( | ... | @@ -35804,12 +35671,12 @@ pub fn resolveTypeFieldsStruct( |
| 35804 | ty: InternPool.Index, | 35671 | ty: InternPool.Index, |
| 35805 | struct_type: InternPool.LoadedStructType, | 35672 | struct_type: InternPool.LoadedStructType, |
| 35806 | ) CompileError!void { | 35673 | ) CompileError!void { |
| 35807 | const mod = sema.mod; | 35674 | const zcu = sema.mod; |
| 35808 | const ip = &mod.intern_pool; | 35675 | const ip = &zcu.intern_pool; |
| 35809 | // If there is no owner decl it means the struct has no fields. | 35676 | // If there is no owner decl it means the struct has no fields. |
| 35810 | const owner_decl = struct_type.decl.unwrap() orelse return; | 35677 | const owner_decl = struct_type.decl.unwrap() orelse return; |
| 35811 | | 35678 | |
| 35812 | switch (mod.declPtr(owner_decl).analysis) { | 35679 | switch (zcu.declPtr(owner_decl).analysis) { |
| 35813 | .file_failure, | 35680 | .file_failure, |
| 35814 | .dependency_failure, | 35681 | .dependency_failure, |
| 35815 | .sema_failure, | 35682 | .sema_failure, |
| ... | @@ -35823,20 +35690,19 @@ pub fn resolveTypeFieldsStruct( | ... | @@ -35823,20 +35690,19 @@ pub fn resolveTypeFieldsStruct( |
| 35823 | if (struct_type.haveFieldTypes(ip)) return; | 35690 | if (struct_type.haveFieldTypes(ip)) return; |
| 35824 | | 35691 | |
| 35825 | if (struct_type.setTypesWip(ip)) { | 35692 | if (struct_type.setTypesWip(ip)) { |
| 35826 | const msg = try Module.ErrorMsg.create( | 35693 | const msg = try sema.errMsg( |
| 35827 | sema.gpa, | 35694 | Type.fromInterned(ty).srcLoc(zcu), |
| 35828 | mod.declPtr(owner_decl).srcLoc(mod), | | |
| 35829 | "struct '{}' depends on itself", | 35695 | "struct '{}' depends on itself", |
| 35830 | .{Type.fromInterned(ty).fmt(mod)}, | 35696 | .{Type.fromInterned(ty).fmt(zcu)}, |
| 35831 | ); | 35697 | ); |
| 35832 | return sema.failWithOwnedErrorMsg(null, msg); | 35698 | return sema.failWithOwnedErrorMsg(null, msg); |
| 35833 | } | 35699 | } |
| 35834 | defer struct_type.clearTypesWip(ip); | 35700 | defer struct_type.clearTypesWip(ip); |
| 35835 | | 35701 | |
| 35836 | semaStructFields(mod, sema.arena, struct_type) catch |err| switch (err) { | 35702 | semaStructFields(zcu, sema.arena, struct_type) catch |err| switch (err) { |
| 35837 | error.AnalysisFail => { | 35703 | error.AnalysisFail => { |
| 35838 | if (mod.declPtr(owner_decl).analysis == .complete) { | 35704 | if (zcu.declPtr(owner_decl).analysis == .complete) { |
| 35839 | mod.declPtr(owner_decl).analysis = .dependency_failure; | 35705 | zcu.declPtr(owner_decl).analysis = .dependency_failure; |
| 35840 | } | 35706 | } |
| 35841 | return error.AnalysisFail; | 35707 | return error.AnalysisFail; |
| 35842 | }, | 35708 | }, |
| ... | @@ -35845,9 +35711,9 @@ pub fn resolveTypeFieldsStruct( | ... | @@ -35845,9 +35711,9 @@ pub fn resolveTypeFieldsStruct( |
| 35845 | } | 35711 | } |
| 35846 | | 35712 | |
| 35847 | pub fn resolveStructFieldInits(sema: *Sema, ty: Type) CompileError!void { | 35713 | pub fn resolveStructFieldInits(sema: *Sema, ty: Type) CompileError!void { |
| 35848 | const mod = sema.mod; | 35714 | const zcu = sema.mod; |
| 35849 | const ip = &mod.intern_pool; | 35715 | const ip = &zcu.intern_pool; |
| 35850 | const struct_type = mod.typeToStruct(ty) orelse return; | 35716 | const struct_type = zcu.typeToStruct(ty) orelse return; |
| 35851 | const owner_decl = struct_type.decl.unwrap() orelse return; | 35717 | const owner_decl = struct_type.decl.unwrap() orelse return; |
| 35852 | | 35718 | |
| 35853 | // Inits can start as resolved | 35719 | // Inits can start as resolved |
| ... | @@ -35856,20 +35722,19 @@ pub fn resolveStructFieldInits(sema: *Sema, ty: Type) CompileError!void { | ... | @@ -35856,20 +35722,19 @@ pub fn resolveStructFieldInits(sema: *Sema, ty: Type) CompileError!void { |
| 35856 | try sema.resolveStructLayout(ty); | 35722 | try sema.resolveStructLayout(ty); |
| 35857 | | 35723 | |
| 35858 | if (struct_type.setInitsWip(ip)) { | 35724 | if (struct_type.setInitsWip(ip)) { |
| 35859 | const msg = try Module.ErrorMsg.create( | 35725 | const msg = try sema.errMsg( |
| 35860 | sema.gpa, | 35726 | ty.srcLoc(zcu), |
| 35861 | mod.declPtr(owner_decl).srcLoc(mod), | | |
| 35862 | "struct '{}' depends on itself", | 35727 | "struct '{}' depends on itself", |
| 35863 | .{ty.fmt(mod)}, | 35728 | .{ty.fmt(zcu)}, |
| 35864 | ); | 35729 | ); |
| 35865 | return sema.failWithOwnedErrorMsg(null, msg); | 35730 | return sema.failWithOwnedErrorMsg(null, msg); |
| 35866 | } | 35731 | } |
| 35867 | defer struct_type.clearInitsWip(ip); | 35732 | defer struct_type.clearInitsWip(ip); |
| 35868 | | 35733 | |
| 35869 | semaStructFieldInits(mod, sema.arena, struct_type) catch |err| switch (err) { | 35734 | semaStructFieldInits(zcu, sema.arena, struct_type) catch |err| switch (err) { |
| 35870 | error.AnalysisFail => { | 35735 | error.AnalysisFail => { |
| 35871 | if (mod.declPtr(owner_decl).analysis == .complete) { | 35736 | if (zcu.declPtr(owner_decl).analysis == .complete) { |
| 35872 | mod.declPtr(owner_decl).analysis = .dependency_failure; | 35737 | zcu.declPtr(owner_decl).analysis = .dependency_failure; |
| 35873 | } | 35738 | } |
| 35874 | return error.AnalysisFail; | 35739 | return error.AnalysisFail; |
| 35875 | }, | 35740 | }, |
| ... | @@ -35879,9 +35744,9 @@ pub fn resolveStructFieldInits(sema: *Sema, ty: Type) CompileError!void { | ... | @@ -35879,9 +35744,9 @@ pub fn resolveStructFieldInits(sema: *Sema, ty: Type) CompileError!void { |
| 35879 | } | 35744 | } |
| 35880 | | 35745 | |
| 35881 | pub fn resolveTypeFieldsUnion(sema: *Sema, ty: Type, union_type: InternPool.LoadedUnionType) CompileError!void { | 35746 | pub fn resolveTypeFieldsUnion(sema: *Sema, ty: Type, union_type: InternPool.LoadedUnionType) CompileError!void { |
| 35882 | const mod = sema.mod; | 35747 | const zcu = sema.mod; |
| 35883 | const ip = &mod.intern_pool; | 35748 | const ip = &zcu.intern_pool; |
| 35884 | const owner_decl = mod.declPtr(union_type.decl); | 35749 | const owner_decl = zcu.declPtr(union_type.decl); |
| 35885 | switch (owner_decl.analysis) { | 35750 | switch (owner_decl.analysis) { |
| 35886 | .file_failure, | 35751 | .file_failure, |
| 35887 | .dependency_failure, | 35752 | .dependency_failure, |
| ... | @@ -35895,11 +35760,10 @@ pub fn resolveTypeFieldsUnion(sema: *Sema, ty: Type, union_type: InternPool.Load | ... | @@ -35895,11 +35760,10 @@ pub fn resolveTypeFieldsUnion(sema: *Sema, ty: Type, union_type: InternPool.Load |
| 35895 | switch (union_type.flagsPtr(ip).status) { | 35760 | switch (union_type.flagsPtr(ip).status) { |
| 35896 | .none => {}, | 35761 | .none => {}, |
| 35897 | .field_types_wip => { | 35762 | .field_types_wip => { |
| 35898 | const msg = try Module.ErrorMsg.create( | 35763 | const msg = try sema.errMsg( |
| 35899 | sema.gpa, | 35764 | ty.srcLoc(zcu), |
| 35900 | owner_decl.srcLoc(mod), | | |
| 35901 | "union '{}' depends on itself", | 35765 | "union '{}' depends on itself", |
| 35902 | .{ty.fmt(mod)}, | 35766 | .{ty.fmt(zcu)}, |
| 35903 | ); | 35767 | ); |
| 35904 | return sema.failWithOwnedErrorMsg(null, msg); | 35768 | return sema.failWithOwnedErrorMsg(null, msg); |
| 35905 | }, | 35769 | }, |
| ... | @@ -35913,7 +35777,7 @@ pub fn resolveTypeFieldsUnion(sema: *Sema, ty: Type, union_type: InternPool.Load | ... | @@ -35913,7 +35777,7 @@ pub fn resolveTypeFieldsUnion(sema: *Sema, ty: Type, union_type: InternPool.Load |
| 35913 | | 35777 | |
| 35914 | union_type.flagsPtr(ip).status = .field_types_wip; | 35778 | union_type.flagsPtr(ip).status = .field_types_wip; |
| 35915 | errdefer union_type.flagsPtr(ip).status = .none; | 35779 | errdefer union_type.flagsPtr(ip).status = .none; |
| 35916 | semaUnionFields(mod, sema.arena, union_type) catch |err| switch (err) { | 35780 | semaUnionFields(zcu, sema.arena, union_type) catch |err| switch (err) { |
| 35917 | error.AnalysisFail => { | 35781 | error.AnalysisFail => { |
| 35918 | if (owner_decl.analysis == .complete) { | 35782 | if (owner_decl.analysis == .complete) { |
| 35919 | owner_decl.analysis = .dependency_failure; | 35783 | owner_decl.analysis = .dependency_failure; |
| ... | @@ -35963,10 +35827,13 @@ fn resolveInferredErrorSet( | ... | @@ -35963,10 +35827,13 @@ fn resolveInferredErrorSet( |
| 35963 | } else if (ip.errorUnionSet(ies_func_info.return_type) == ies_index) { | 35827 | } else if (ip.errorUnionSet(ies_func_info.return_type) == ies_index) { |
| 35964 | if (ies_func_info.is_generic) { | 35828 | if (ies_func_info.is_generic) { |
| 35965 | const msg = msg: { | 35829 | const msg = msg: { |
| 35966 | const msg = try sema.errMsg(block, src, "unable to resolve inferred error set of generic function", .{}); | 35830 | const msg = try sema.errMsg(src, "unable to resolve inferred error set of generic function", .{}); |
| 35967 | errdefer msg.destroy(sema.gpa); | 35831 | errdefer msg.destroy(sema.gpa); |
| 35968 | | 35832 | |
| 35969 | try sema.mod.errNoteNonLazy(ies_func_owner_decl.srcLoc(mod), msg, "generic function declared here", .{}); | 35833 | try sema.errNote(.{ |
| | 35834 | .base_node_inst = ies_func_owner_decl.zir_decl_index.unwrap().?, |
| | 35835 | .offset = LazySrcLoc.Offset.nodeOffset(0), |
| | 35836 | }, msg, "generic function declared here", .{}); |
| 35970 | break :msg msg; | 35837 | break :msg msg; |
| 35971 | }; | 35838 | }; |
| 35972 | return sema.failWithOwnedErrorMsg(block, msg); | 35839 | return sema.failWithOwnedErrorMsg(block, msg); |
| ... | @@ -36147,7 +36014,7 @@ fn semaStructFields( | ... | @@ -36147,7 +36014,7 @@ fn semaStructFields( |
| 36147 | }, | 36014 | }, |
| 36148 | }; | 36015 | }; |
| 36149 | | 36016 | |
| 36150 | var comptime_err_ret_trace = std.ArrayList(Module.SrcLoc).init(gpa); | 36017 | var comptime_err_ret_trace = std.ArrayList(LazySrcLoc).init(gpa); |
| 36151 | defer comptime_err_ret_trace.deinit(); | 36018 | defer comptime_err_ret_trace.deinit(); |
| 36152 | | 36019 | |
| 36153 | var sema: Sema = .{ | 36020 | var sema: Sema = .{ |
| ... | @@ -36174,6 +36041,7 @@ fn semaStructFields( | ... | @@ -36174,6 +36041,7 @@ fn semaStructFields( |
| 36174 | .instructions = .{}, | 36041 | .instructions = .{}, |
| 36175 | .inlining = null, | 36042 | .inlining = null, |
| 36176 | .is_comptime = true, | 36043 | .is_comptime = true, |
| | 36044 | .src_base_inst = struct_type.zir_index.unwrap().?, |
| 36177 | }; | 36045 | }; |
| 36178 | defer assert(block_scope.instructions.items.len == 0); | 36046 | defer assert(block_scope.instructions.items.len == 0); |
| 36179 | | 36047 | |
| ... | @@ -36252,35 +36120,19 @@ fn semaStructFields( | ... | @@ -36252,35 +36120,19 @@ fn semaStructFields( |
| 36252 | // so that init values may depend on type layout. | 36120 | // so that init values may depend on type layout. |
| 36253 | | 36121 | |
| 36254 | for (fields, 0..) |zir_field, field_i| { | 36122 | for (fields, 0..) |zir_field, field_i| { |
| | 36123 | const ty_src: LazySrcLoc = .{ |
| | 36124 | .base_node_inst = struct_type.zir_index.unwrap().?, |
| | 36125 | .offset = .{ .container_field_type = @intCast(field_i) }, |
| | 36126 | }; |
| 36255 | const field_ty: Type = ty: { | 36127 | const field_ty: Type = ty: { |
| 36256 | if (zir_field.type_ref != .none) { | 36128 | if (zir_field.type_ref != .none) { |
| 36257 | break :ty sema.resolveType(&block_scope, .unneeded, zir_field.type_ref) catch |err| switch (err) { | 36129 | break :ty try sema.resolveType(&block_scope, ty_src, zir_field.type_ref); |
| 36258 | error.NeededSourceLocation => { | | |
| 36259 | const ty_src = mod.fieldSrcLoc(decl_index, .{ | | |
| 36260 | .index = field_i, | | |
| 36261 | .range = .type, | | |
| 36262 | }).lazy; | | |
| 36263 | _ = try sema.resolveType(&block_scope, ty_src, zir_field.type_ref); | | |
| 36264 | unreachable; | | |
| 36265 | }, | | |
| 36266 | else => |e| return e, | | |
| 36267 | }; | | |
| 36268 | } | 36130 | } |
| 36269 | assert(zir_field.type_body_len != 0); | 36131 | assert(zir_field.type_body_len != 0); |
| 36270 | const body = zir.bodySlice(extra_index, zir_field.type_body_len); | 36132 | const body = zir.bodySlice(extra_index, zir_field.type_body_len); |
| 36271 | extra_index += body.len; | 36133 | extra_index += body.len; |
| 36272 | const ty_ref = try sema.resolveInlineBody(&block_scope, body, zir_index); | 36134 | const ty_ref = try sema.resolveInlineBody(&block_scope, body, zir_index); |
| 36273 | break :ty sema.analyzeAsType(&block_scope, .unneeded, ty_ref) catch |err| switch (err) { | 36135 | break :ty try sema.analyzeAsType(&block_scope, ty_src, ty_ref); |
| 36274 | error.NeededSourceLocation => { | | |
| 36275 | const ty_src = mod.fieldSrcLoc(decl_index, .{ | | |
| 36276 | .index = field_i, | | |
| 36277 | .range = .type, | | |
| 36278 | }).lazy; | | |
| 36279 | _ = try sema.analyzeAsType(&block_scope, ty_src, ty_ref); | | |
| 36280 | unreachable; | | |
| 36281 | }, | | |
| 36282 | else => |e| return e, | | |
| 36283 | }; | | |
| 36284 | }; | 36136 | }; |
| 36285 | if (field_ty.isGenericPoison()) { | 36137 | if (field_ty.isGenericPoison()) { |
| 36286 | return error.GenericPoison; | 36138 | return error.GenericPoison; |
| ... | @@ -36290,11 +36142,7 @@ fn semaStructFields( | ... | @@ -36290,11 +36142,7 @@ fn semaStructFields( |
| 36290 | | 36142 | |
| 36291 | if (field_ty.zigTypeTag(mod) == .Opaque) { | 36143 | if (field_ty.zigTypeTag(mod) == .Opaque) { |
| 36292 | const msg = msg: { | 36144 | const msg = msg: { |
| 36293 | const ty_src = mod.fieldSrcLoc(decl_index, .{ | 36145 | const msg = try sema.errMsg(ty_src, "opaque types have unknown size and therefore cannot be directly embedded in structs", .{}); |
| 36294 | .index = field_i, | | |
| 36295 | .range = .type, | | |
| 36296 | }).lazy; | | |
| 36297 | const msg = try sema.errMsg(&block_scope, ty_src, "opaque types have unknown size and therefore cannot be directly embedded in structs", .{}); | | |
| 36298 | errdefer msg.destroy(sema.gpa); | 36146 | errdefer msg.destroy(sema.gpa); |
| 36299 | | 36147 | |
| 36300 | try sema.addDeclaredHereNote(msg, field_ty); | 36148 | try sema.addDeclaredHereNote(msg, field_ty); |
| ... | @@ -36304,11 +36152,7 @@ fn semaStructFields( | ... | @@ -36304,11 +36152,7 @@ fn semaStructFields( |
| 36304 | } | 36152 | } |
| 36305 | if (field_ty.zigTypeTag(mod) == .NoReturn) { | 36153 | if (field_ty.zigTypeTag(mod) == .NoReturn) { |
| 36306 | const msg = msg: { | 36154 | const msg = msg: { |
| 36307 | const ty_src = mod.fieldSrcLoc(decl_index, .{ | 36155 | const msg = try sema.errMsg(ty_src, "struct fields cannot be 'noreturn'", .{}); |
| 36308 | .index = field_i, | | |
| 36309 | .range = .type, | | |
| 36310 | }).lazy; | | |
| 36311 | const msg = try sema.errMsg(&block_scope, ty_src, "struct fields cannot be 'noreturn'", .{}); | | |
| 36312 | errdefer msg.destroy(sema.gpa); | 36156 | errdefer msg.destroy(sema.gpa); |
| 36313 | | 36157 | |
| 36314 | try sema.addDeclaredHereNote(msg, field_ty); | 36158 | try sema.addDeclaredHereNote(msg, field_ty); |
| ... | @@ -36319,11 +36163,7 @@ fn semaStructFields( | ... | @@ -36319,11 +36163,7 @@ fn semaStructFields( |
| 36319 | switch (struct_type.layout) { | 36163 | switch (struct_type.layout) { |
| 36320 | .@"extern" => if (!try sema.validateExternType(field_ty, .struct_field)) { | 36164 | .@"extern" => if (!try sema.validateExternType(field_ty, .struct_field)) { |
| 36321 | const msg = msg: { | 36165 | const msg = msg: { |
| 36322 | const ty_src = mod.fieldSrcLoc(decl_index, .{ | 36166 | const msg = try sema.errMsg(ty_src, "extern structs cannot contain fields of type '{}'", .{field_ty.fmt(mod)}); |
| 36323 | .index = field_i, | | |
| 36324 | .range = .type, | | |
| 36325 | }); | | |
| 36326 | const msg = try sema.errMsg(&block_scope, ty_src.lazy, "extern structs cannot contain fields of type '{}'", .{field_ty.fmt(mod)}); | | |
| 36327 | errdefer msg.destroy(sema.gpa); | 36167 | errdefer msg.destroy(sema.gpa); |
| 36328 | | 36168 | |
| 36329 | try sema.explainWhyTypeIsNotExtern(msg, ty_src, field_ty, .struct_field); | 36169 | try sema.explainWhyTypeIsNotExtern(msg, ty_src, field_ty, .struct_field); |
| ... | @@ -36335,11 +36175,7 @@ fn semaStructFields( | ... | @@ -36335,11 +36175,7 @@ fn semaStructFields( |
| 36335 | }, | 36175 | }, |
| 36336 | .@"packed" => if (!try sema.validatePackedType(field_ty)) { | 36176 | .@"packed" => if (!try sema.validatePackedType(field_ty)) { |
| 36337 | const msg = msg: { | 36177 | const msg = msg: { |
| 36338 | const ty_src = mod.fieldSrcLoc(decl_index, .{ | 36178 | const msg = try sema.errMsg(ty_src, "packed structs cannot contain fields of type '{}'", .{field_ty.fmt(mod)}); |
| 36339 | .index = field_i, | | |
| 36340 | .range = .type, | | |
| 36341 | }); | | |
| 36342 | const msg = try sema.errMsg(&block_scope, ty_src.lazy, "packed structs cannot contain fields of type '{}'", .{field_ty.fmt(mod)}); | | |
| 36343 | errdefer msg.destroy(sema.gpa); | 36179 | errdefer msg.destroy(sema.gpa); |
| 36344 | | 36180 | |
| 36345 | try sema.explainWhyTypeIsNotPacked(msg, ty_src, field_ty); | 36181 | try sema.explainWhyTypeIsNotPacked(msg, ty_src, field_ty); |
| ... | @@ -36356,17 +36192,11 @@ fn semaStructFields( | ... | @@ -36356,17 +36192,11 @@ fn semaStructFields( |
| 36356 | const body = zir.bodySlice(extra_index, zir_field.align_body_len); | 36192 | const body = zir.bodySlice(extra_index, zir_field.align_body_len); |
| 36357 | extra_index += body.len; | 36193 | extra_index += body.len; |
| 36358 | const align_ref = try sema.resolveInlineBody(&block_scope, body, zir_index); | 36194 | const align_ref = try sema.resolveInlineBody(&block_scope, body, zir_index); |
| 36359 | const field_align = sema.analyzeAsAlign(&block_scope, .unneeded, align_ref) catch |err| switch (err) { | 36195 | const align_src: LazySrcLoc = .{ |
| 36360 | error.NeededSourceLocation => { | 36196 | .base_node_inst = struct_type.zir_index.unwrap().?, |
| 36361 | const align_src = mod.fieldSrcLoc(decl_index, .{ | 36197 | .offset = .{ .container_field_align = @intCast(field_i) }, |
| 36362 | .index = field_i, | | |
| 36363 | .range = .alignment, | | |
| 36364 | }).lazy; | | |
| 36365 | _ = try sema.analyzeAsAlign(&block_scope, align_src, align_ref); | | |
| 36366 | unreachable; | | |
| 36367 | }, | | |
| 36368 | else => |e| return e, | | |
| 36369 | }; | 36198 | }; |
| | 36199 | const field_align = try sema.analyzeAsAlign(&block_scope, align_src, align_ref); |
| 36370 | struct_type.field_aligns.get(ip)[field_i] = field_align; | 36200 | struct_type.field_aligns.get(ip)[field_i] = field_align; |
| 36371 | } | 36201 | } |
| 36372 | | 36202 | |
| ... | @@ -36395,7 +36225,7 @@ fn semaStructFieldInits( | ... | @@ -36395,7 +36225,7 @@ fn semaStructFieldInits( |
| 36395 | const zir_index = struct_type.zir_index.unwrap().?.resolve(ip); | 36225 | const zir_index = struct_type.zir_index.unwrap().?.resolve(ip); |
| 36396 | const fields_len, const small, var extra_index = structZirInfo(zir, zir_index); | 36226 | const fields_len, const small, var extra_index = structZirInfo(zir, zir_index); |
| 36397 | | 36227 | |
| 36398 | var comptime_err_ret_trace = std.ArrayList(Module.SrcLoc).init(gpa); | 36228 | var comptime_err_ret_trace = std.ArrayList(LazySrcLoc).init(gpa); |
| 36399 | defer comptime_err_ret_trace.deinit(); | 36229 | defer comptime_err_ret_trace.deinit(); |
| 36400 | | 36230 | |
| 36401 | var sema: Sema = .{ | 36231 | var sema: Sema = .{ |
| ... | @@ -36422,6 +36252,7 @@ fn semaStructFieldInits( | ... | @@ -36422,6 +36252,7 @@ fn semaStructFieldInits( |
| 36422 | .instructions = .{}, | 36252 | .instructions = .{}, |
| 36423 | .inlining = null, | 36253 | .inlining = null, |
| 36424 | .is_comptime = true, | 36254 | .is_comptime = true, |
| | 36255 | .src_base_inst = struct_type.zir_index.unwrap().?, |
| 36425 | }; | 36256 | }; |
| 36426 | defer assert(block_scope.instructions.items.len == 0); | 36257 | defer assert(block_scope.instructions.items.len == 0); |
| 36427 | | 36258 | |
| ... | @@ -36495,33 +36326,20 @@ fn semaStructFieldInits( | ... | @@ -36495,33 +36326,20 @@ fn semaStructFieldInits( |
| 36495 | try sema.inst_map.ensureSpaceForInstructions(sema.gpa, &.{zir_index}); | 36326 | try sema.inst_map.ensureSpaceForInstructions(sema.gpa, &.{zir_index}); |
| 36496 | sema.inst_map.putAssumeCapacity(zir_index, type_ref); | 36327 | sema.inst_map.putAssumeCapacity(zir_index, type_ref); |
| 36497 | | 36328 | |
| 36498 | const init = try sema.resolveInlineBody(&block_scope, body, zir_index); | 36329 | const init_src: LazySrcLoc = .{ |
| 36499 | const coerced = sema.coerce(&block_scope, field_ty, init, .unneeded) catch |err| switch (err) { | 36330 | .base_node_inst = struct_type.zir_index.unwrap().?, |
| 36500 | error.NeededSourceLocation => { | 36331 | .offset = .{ .container_field_value = @intCast(field_i) }, |
| 36501 | const init_src = mod.fieldSrcLoc(decl_index, .{ | | |
| 36502 | .index = field_i, | | |
| 36503 | .range = .value, | | |
| 36504 | }).lazy; | | |
| 36505 | _ = try sema.coerce(&block_scope, field_ty, init, init_src); | | |
| 36506 | unreachable; | | |
| 36507 | }, | | |
| 36508 | else => |e| return e, | | |
| 36509 | }; | 36332 | }; |
| 36510 | const default_val = (try sema.resolveValue(coerced)) orelse { | 36333 | |
| 36511 | const init_src = mod.fieldSrcLoc(decl_index, .{ | 36334 | const init = try sema.resolveInlineBody(&block_scope, body, zir_index); |
| 36512 | .index = field_i, | 36335 | const coerced = try sema.coerce(&block_scope, field_ty, init, init_src); |
| 36513 | .range = .value, | 36336 | const default_val = try sema.resolveValue(coerced) orelse { |
| 36514 | }).lazy; | | |
| 36515 | return sema.failWithNeededComptime(&block_scope, init_src, .{ | 36337 | return sema.failWithNeededComptime(&block_scope, init_src, .{ |
| 36516 | .needed_comptime_reason = "struct field default value must be comptime-known", | 36338 | .needed_comptime_reason = "struct field default value must be comptime-known", |
| 36517 | }); | 36339 | }); |
| 36518 | }; | 36340 | }; |
| 36519 | | 36341 | |
| 36520 | if (default_val.canMutateComptimeVarState(mod)) { | 36342 | if (default_val.canMutateComptimeVarState(mod)) { |
| 36521 | const init_src = mod.fieldSrcLoc(decl_index, .{ | | |
| 36522 | .index = field_i, | | |
| 36523 | .range = .value, | | |
| 36524 | }).lazy; | | |
| 36525 | return sema.fail(&block_scope, init_src, "field default value contains reference to comptime-mutable memory", .{}); | 36343 | return sema.fail(&block_scope, init_src, "field default value contains reference to comptime-mutable memory", .{}); |
| 36526 | } | 36344 | } |
| 36527 | struct_type.field_inits.get(ip)[field_i] = default_val.toIntern(); | 36345 | struct_type.field_inits.get(ip)[field_i] = default_val.toIntern(); |
| ... | @@ -36543,8 +36361,6 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded | ... | @@ -36543,8 +36361,6 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded |
| 36543 | const small: Zir.Inst.UnionDecl.Small = @bitCast(extended.small); | 36361 | const small: Zir.Inst.UnionDecl.Small = @bitCast(extended.small); |
| 36544 | var extra_index: usize = extended.operand + @typeInfo(Zir.Inst.UnionDecl).Struct.fields.len; | 36362 | var extra_index: usize = extended.operand + @typeInfo(Zir.Inst.UnionDecl).Struct.fields.len; |
| 36545 | | 36363 | |
| 36546 | const src = LazySrcLoc.nodeOffset(0); | | |
| 36547 | | | |
| 36548 | const tag_type_ref: Zir.Inst.Ref = if (small.has_tag_type) blk: { | 36364 | const tag_type_ref: Zir.Inst.Ref = if (small.has_tag_type) blk: { |
| 36549 | const ty_ref: Zir.Inst.Ref = @enumFromInt(zir.extra[extra_index]); | 36365 | const ty_ref: Zir.Inst.Ref = @enumFromInt(zir.extra[extra_index]); |
| 36550 | extra_index += 1; | 36366 | extra_index += 1; |
| ... | @@ -36583,7 +36399,7 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded | ... | @@ -36583,7 +36399,7 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded |
| 36583 | | 36399 | |
| 36584 | const decl = mod.declPtr(decl_index); | 36400 | const decl = mod.declPtr(decl_index); |
| 36585 | | 36401 | |
| 36586 | var comptime_err_ret_trace = std.ArrayList(Module.SrcLoc).init(gpa); | 36402 | var comptime_err_ret_trace = std.ArrayList(LazySrcLoc).init(gpa); |
| 36587 | defer comptime_err_ret_trace.deinit(); | 36403 | defer comptime_err_ret_trace.deinit(); |
| 36588 | | 36404 | |
| 36589 | var sema: Sema = .{ | 36405 | var sema: Sema = .{ |
| ... | @@ -36610,9 +36426,12 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded | ... | @@ -36610,9 +36426,12 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded |
| 36610 | .instructions = .{}, | 36426 | .instructions = .{}, |
| 36611 | .inlining = null, | 36427 | .inlining = null, |
| 36612 | .is_comptime = true, | 36428 | .is_comptime = true, |
| | 36429 | .src_base_inst = union_type.zir_index, |
| 36613 | }; | 36430 | }; |
| 36614 | defer assert(block_scope.instructions.items.len == 0); | 36431 | defer assert(block_scope.instructions.items.len == 0); |
| 36615 | | 36432 | |
| | 36433 | const src = block_scope.nodeOffset(0); |
| | 36434 | |
| 36616 | if (body.len != 0) { | 36435 | if (body.len != 0) { |
| 36617 | _ = try sema.analyzeInlineBody(&block_scope, body, zir_index); | 36436 | _ = try sema.analyzeInlineBody(&block_scope, body, zir_index); |
| 36618 | } | 36437 | } |
| ... | @@ -36622,7 +36441,10 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded | ... | @@ -36622,7 +36441,10 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded |
| 36622 | var enum_field_vals: std.AutoArrayHashMapUnmanaged(InternPool.Index, void) = .{}; | 36441 | var enum_field_vals: std.AutoArrayHashMapUnmanaged(InternPool.Index, void) = .{}; |
| 36623 | var explicit_tags_seen: []bool = &.{}; | 36442 | var explicit_tags_seen: []bool = &.{}; |
| 36624 | if (tag_type_ref != .none) { | 36443 | if (tag_type_ref != .none) { |
| 36625 | const tag_ty_src: LazySrcLoc = .{ .node_offset_container_tag = src.node_offset.x }; | 36444 | const tag_ty_src: LazySrcLoc = .{ |
| | 36445 | .base_node_inst = union_type.zir_index, |
| | 36446 | .offset = .{ .node_offset_container_tag = 0 }, |
| | 36447 | }; |
| 36626 | const provided_ty = try sema.resolveType(&block_scope, tag_ty_src, tag_type_ref); | 36448 | const provided_ty = try sema.resolveType(&block_scope, tag_ty_src, tag_type_ref); |
| 36627 | if (small.auto_enum_tag) { | 36449 | if (small.auto_enum_tag) { |
| 36628 | // The provided type is an integer type and we must construct the enum tag type here. | 36450 | // The provided type is an integer type and we must construct the enum tag type here. |
| ... | @@ -36635,9 +36457,9 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded | ... | @@ -36635,9 +36457,9 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded |
| 36635 | const field_count_val = try mod.intValue(Type.comptime_int, fields_len - 1); | 36457 | const field_count_val = try mod.intValue(Type.comptime_int, fields_len - 1); |
| 36636 | if (!(try sema.intFitsInType(field_count_val, int_tag_ty, null))) { | 36458 | if (!(try sema.intFitsInType(field_count_val, int_tag_ty, null))) { |
| 36637 | const msg = msg: { | 36459 | const msg = msg: { |
| 36638 | const msg = try sema.errMsg(&block_scope, tag_ty_src, "specified integer tag type cannot represent every field", .{}); | 36460 | const msg = try sema.errMsg(tag_ty_src, "specified integer tag type cannot represent every field", .{}); |
| 36639 | errdefer msg.destroy(sema.gpa); | 36461 | errdefer msg.destroy(sema.gpa); |
| 36640 | try sema.errNote(&block_scope, tag_ty_src, msg, "type '{}' cannot fit values in range 0...{d}", .{ | 36462 | try sema.errNote(tag_ty_src, msg, "type '{}' cannot fit values in range 0...{d}", .{ |
| 36641 | int_tag_ty.fmt(mod), | 36463 | int_tag_ty.fmt(mod), |
| 36642 | fields_len - 1, | 36464 | fields_len - 1, |
| 36643 | }); | 36465 | }); |
| ... | @@ -36722,19 +36544,26 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded | ... | @@ -36722,19 +36544,26 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded |
| 36722 | break :blk try sema.resolveInst(tag_ref); | 36544 | break :blk try sema.resolveInst(tag_ref); |
| 36723 | } else .none; | 36545 | } else .none; |
| 36724 | | 36546 | |
| | 36547 | const name_src: LazySrcLoc = .{ |
| | 36548 | .base_node_inst = union_type.zir_index, |
| | 36549 | .offset = .{ .container_field_name = field_i }, |
| | 36550 | }; |
| | 36551 | const value_src: LazySrcLoc = .{ |
| | 36552 | .base_node_inst = union_type.zir_index, |
| | 36553 | .offset = .{ .container_field_value = field_i }, |
| | 36554 | }; |
| | 36555 | const align_src: LazySrcLoc = .{ |
| | 36556 | .base_node_inst = union_type.zir_index, |
| | 36557 | .offset = .{ .container_field_align = field_i }, |
| | 36558 | }; |
| | 36559 | const type_src: LazySrcLoc = .{ |
| | 36560 | .base_node_inst = union_type.zir_index, |
| | 36561 | .offset = .{ .container_field_type = field_i }, |
| | 36562 | }; |
| | 36563 | |
| 36725 | if (enum_field_vals.capacity() > 0) { | 36564 | if (enum_field_vals.capacity() > 0) { |
| 36726 | const enum_tag_val = if (tag_ref != .none) blk: { | 36565 | const enum_tag_val = if (tag_ref != .none) blk: { |
| 36727 | const val = sema.semaUnionFieldVal(&block_scope, .unneeded, int_tag_ty, tag_ref) catch |err| switch (err) { | 36566 | const val = try sema.semaUnionFieldVal(&block_scope, value_src, int_tag_ty, tag_ref); |
| 36728 | error.NeededSourceLocation => { | | |
| 36729 | const val_src = mod.fieldSrcLoc(union_type.decl, .{ | | |
| 36730 | .index = field_i, | | |
| 36731 | .range = .value, | | |
| 36732 | }).lazy; | | |
| 36733 | _ = try sema.semaUnionFieldVal(&block_scope, val_src, int_tag_ty, tag_ref); | | |
| 36734 | unreachable; | | |
| 36735 | }, | | |
| 36736 | else => |e| return e, | | |
| 36737 | }; | | |
| 36738 | last_tag_val = val; | 36567 | last_tag_val = val; |
| 36739 | | 36568 | |
| 36740 | break :blk val; | 36569 | break :blk val; |
| ... | @@ -36749,12 +36578,14 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded | ... | @@ -36749,12 +36578,14 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded |
| 36749 | }; | 36578 | }; |
| 36750 | const gop = enum_field_vals.getOrPutAssumeCapacity(enum_tag_val.toIntern()); | 36579 | const gop = enum_field_vals.getOrPutAssumeCapacity(enum_tag_val.toIntern()); |
| 36751 | if (gop.found_existing) { | 36580 | if (gop.found_existing) { |
| 36752 | const field_src = mod.fieldSrcLoc(union_type.decl, .{ .index = field_i }).lazy; | 36581 | const other_value_src: LazySrcLoc = .{ |
| 36753 | const other_field_src = mod.fieldSrcLoc(union_type.decl, .{ .index = gop.index }).lazy; | 36582 | .base_node_inst = union_type.zir_index, |
| | 36583 | .offset = .{ .container_field_value = @intCast(gop.index) }, |
| | 36584 | }; |
| 36754 | const msg = msg: { | 36585 | const msg = msg: { |
| 36755 | const msg = try sema.errMsg(&block_scope, field_src, "enum tag value {} already taken", .{enum_tag_val.fmtValue(mod, &sema)}); | 36586 | const msg = try sema.errMsg(value_src, "enum tag value {} already taken", .{enum_tag_val.fmtValue(mod, &sema)}); |
| 36756 | errdefer msg.destroy(gpa); | 36587 | errdefer msg.destroy(gpa); |
| 36757 | try sema.errNote(&block_scope, other_field_src, msg, "other occurrence here", .{}); | 36588 | try sema.errNote(other_value_src, msg, "other occurrence here", .{}); |
| 36758 | break :msg msg; | 36589 | break :msg msg; |
| 36759 | }; | 36590 | }; |
| 36760 | return sema.failWithOwnedErrorMsg(&block_scope, msg); | 36591 | return sema.failWithOwnedErrorMsg(&block_scope, msg); |
| ... | @@ -36772,17 +36603,7 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded | ... | @@ -36772,17 +36603,7 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded |
| 36772 | else if (field_type_ref == .none) | 36603 | else if (field_type_ref == .none) |
| 36773 | Type.noreturn | 36604 | Type.noreturn |
| 36774 | else | 36605 | else |
| 36775 | sema.resolveType(&block_scope, .unneeded, field_type_ref) catch |err| switch (err) { | 36606 | try sema.resolveType(&block_scope, type_src, field_type_ref); |
| 36776 | error.NeededSourceLocation => { | | |
| 36777 | const ty_src = mod.fieldSrcLoc(union_type.decl, .{ | | |
| 36778 | .index = field_i, | | |
| 36779 | .range = .type, | | |
| 36780 | }).lazy; | | |
| 36781 | _ = try sema.resolveType(&block_scope, ty_src, field_type_ref); | | |
| 36782 | unreachable; | | |
| 36783 | }, | | |
| 36784 | else => |e| return e, | | |
| 36785 | }; | | |
| 36786 | | 36607 | |
| 36787 | if (field_ty.isGenericPoison()) { | 36608 | if (field_ty.isGenericPoison()) { |
| 36788 | return error.GenericPoison; | 36609 | return error.GenericPoison; |
| ... | @@ -36791,11 +36612,7 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded | ... | @@ -36791,11 +36612,7 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded |
| 36791 | if (explicit_tags_seen.len > 0) { | 36612 | if (explicit_tags_seen.len > 0) { |
| 36792 | const tag_info = ip.loadEnumType(union_type.tagTypePtr(ip).*); | 36613 | const tag_info = ip.loadEnumType(union_type.tagTypePtr(ip).*); |
| 36793 | const enum_index = tag_info.nameIndex(ip, field_name) orelse { | 36614 | const enum_index = tag_info.nameIndex(ip, field_name) orelse { |
| 36794 | const ty_src = mod.fieldSrcLoc(union_type.decl, .{ | 36615 | return sema.fail(&block_scope, name_src, "no field named '{}' in enum '{}'", .{ |
| 36795 | .index = field_i, | | |
| 36796 | .range = .name, | | |
| 36797 | }).lazy; | | |
| 36798 | return sema.fail(&block_scope, ty_src, "no field named '{}' in enum '{}'", .{ | | |
| 36799 | field_name.fmt(ip), Type.fromInterned(union_type.tagTypePtr(ip).*).fmt(mod), | 36616 | field_name.fmt(ip), Type.fromInterned(union_type.tagTypePtr(ip).*).fmt(mod), |
| 36800 | }); | 36617 | }); |
| 36801 | }; | 36618 | }; |
| ... | @@ -36808,17 +36625,15 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded | ... | @@ -36808,17 +36625,15 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded |
| 36808 | // Enforce the enum fields and the union fields being in the same order. | 36625 | // Enforce the enum fields and the union fields being in the same order. |
| 36809 | if (enum_index != field_i) { | 36626 | if (enum_index != field_i) { |
| 36810 | const msg = msg: { | 36627 | const msg = msg: { |
| 36811 | const ty_src = mod.fieldSrcLoc(union_type.decl, .{ | 36628 | const enum_field_src: LazySrcLoc = .{ |
| 36812 | .index = field_i, | 36629 | .base_node_inst = tag_info.zir_index.unwrap().?, |
| 36813 | .range = .name, | 36630 | .offset = .{ .container_field_name = enum_index }, |
| 36814 | }).lazy; | 36631 | }; |
| 36815 | const enum_field_src = mod.fieldSrcLoc(tag_info.decl, .{ .index = enum_index }).lazy; | 36632 | const msg = try sema.errMsg(name_src, "union field '{}' ordered differently than corresponding enum field", .{ |
| 36816 | const msg = try sema.errMsg(&block_scope, ty_src, "union field '{}' ordered differently than corresponding enum field", .{ | | |
| 36817 | field_name.fmt(ip), | 36633 | field_name.fmt(ip), |
| 36818 | }); | 36634 | }); |
| 36819 | errdefer msg.destroy(sema.gpa); | 36635 | errdefer msg.destroy(sema.gpa); |
| 36820 | const decl_ptr = mod.declPtr(tag_info.decl); | 36636 | try sema.errNote(enum_field_src, msg, "enum field here", .{}); |
| 36821 | try mod.errNoteNonLazy(decl_ptr.toSrcLoc(enum_field_src, mod), msg, "enum field here", .{}); | | |
| 36822 | break :msg msg; | 36637 | break :msg msg; |
| 36823 | }; | 36638 | }; |
| 36824 | return sema.failWithOwnedErrorMsg(&block_scope, msg); | 36639 | return sema.failWithOwnedErrorMsg(&block_scope, msg); |
| ... | @@ -36827,11 +36642,7 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded | ... | @@ -36827,11 +36642,7 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded |
| 36827 | | 36642 | |
| 36828 | if (field_ty.zigTypeTag(mod) == .Opaque) { | 36643 | if (field_ty.zigTypeTag(mod) == .Opaque) { |
| 36829 | const msg = msg: { | 36644 | const msg = msg: { |
| 36830 | const ty_src = mod.fieldSrcLoc(union_type.decl, .{ | 36645 | const msg = try sema.errMsg(type_src, "opaque types have unknown size and therefore cannot be directly embedded in unions", .{}); |
| 36831 | .index = field_i, | | |
| 36832 | .range = .type, | | |
| 36833 | }).lazy; | | |
| 36834 | const msg = try sema.errMsg(&block_scope, ty_src, "opaque types have unknown size and therefore cannot be directly embedded in unions", .{}); | | |
| 36835 | errdefer msg.destroy(sema.gpa); | 36646 | errdefer msg.destroy(sema.gpa); |
| 36836 | | 36647 | |
| 36837 | try sema.addDeclaredHereNote(msg, field_ty); | 36648 | try sema.addDeclaredHereNote(msg, field_ty); |
| ... | @@ -36844,14 +36655,10 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded | ... | @@ -36844,14 +36655,10 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded |
| 36844 | !try sema.validateExternType(field_ty, .union_field)) | 36655 | !try sema.validateExternType(field_ty, .union_field)) |
| 36845 | { | 36656 | { |
| 36846 | const msg = msg: { | 36657 | const msg = msg: { |
| 36847 | const ty_src = mod.fieldSrcLoc(union_type.decl, .{ | 36658 | const msg = try sema.errMsg(type_src, "extern unions cannot contain fields of type '{}'", .{field_ty.fmt(mod)}); |
| 36848 | .index = field_i, | | |
| 36849 | .range = .type, | | |
| 36850 | }); | | |
| 36851 | const msg = try sema.errMsg(&block_scope, ty_src.lazy, "extern unions cannot contain fields of type '{}'", .{field_ty.fmt(mod)}); | | |
| 36852 | errdefer msg.destroy(sema.gpa); | 36659 | errdefer msg.destroy(sema.gpa); |
| 36853 | | 36660 | |
| 36854 | try sema.explainWhyTypeIsNotExtern(msg, ty_src, field_ty, .union_field); | 36661 | try sema.explainWhyTypeIsNotExtern(msg, type_src, field_ty, .union_field); |
| 36855 | | 36662 | |
| 36856 | try sema.addDeclaredHereNote(msg, field_ty); | 36663 | try sema.addDeclaredHereNote(msg, field_ty); |
| 36857 | break :msg msg; | 36664 | break :msg msg; |
| ... | @@ -36859,14 +36666,10 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded | ... | @@ -36859,14 +36666,10 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded |
| 36859 | return sema.failWithOwnedErrorMsg(&block_scope, msg); | 36666 | return sema.failWithOwnedErrorMsg(&block_scope, msg); |
| 36860 | } else if (layout == .@"packed" and !try sema.validatePackedType(field_ty)) { | 36667 | } else if (layout == .@"packed" and !try sema.validatePackedType(field_ty)) { |
| 36861 | const msg = msg: { | 36668 | const msg = msg: { |
| 36862 | const ty_src = mod.fieldSrcLoc(union_type.decl, .{ | 36669 | const msg = try sema.errMsg(type_src, "packed unions cannot contain fields of type '{}'", .{field_ty.fmt(mod)}); |
| 36863 | .index = field_i, | | |
| 36864 | .range = .type, | | |
| 36865 | }); | | |
| 36866 | const msg = try sema.errMsg(&block_scope, ty_src.lazy, "packed unions cannot contain fields of type '{}'", .{field_ty.fmt(mod)}); | | |
| 36867 | errdefer msg.destroy(sema.gpa); | 36670 | errdefer msg.destroy(sema.gpa); |
| 36868 | | 36671 | |
| 36869 | try sema.explainWhyTypeIsNotPacked(msg, ty_src, field_ty); | 36672 | try sema.explainWhyTypeIsNotPacked(msg, type_src, field_ty); |
| 36870 | | 36673 | |
| 36871 | try sema.addDeclaredHereNote(msg, field_ty); | 36674 | try sema.addDeclaredHereNote(msg, field_ty); |
| 36872 | break :msg msg; | 36675 | break :msg msg; |
| ... | @@ -36878,17 +36681,7 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded | ... | @@ -36878,17 +36681,7 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded |
| 36878 | | 36681 | |
| 36879 | if (small.any_aligned_fields) { | 36682 | if (small.any_aligned_fields) { |
| 36880 | field_aligns.appendAssumeCapacity(if (align_ref != .none) | 36683 | field_aligns.appendAssumeCapacity(if (align_ref != .none) |
| 36881 | sema.resolveAlign(&block_scope, .unneeded, align_ref) catch |err| switch (err) { | 36684 | try sema.resolveAlign(&block_scope, align_src, align_ref) |
| 36882 | error.NeededSourceLocation => { | | |
| 36883 | const align_src = mod.fieldSrcLoc(union_type.decl, .{ | | |
| 36884 | .index = field_i, | | |
| 36885 | .range = .alignment, | | |
| 36886 | }).lazy; | | |
| 36887 | _ = try sema.resolveAlign(&block_scope, align_src, align_ref); | | |
| 36888 | unreachable; | | |
| 36889 | }, | | |
| 36890 | else => |e| return e, | | |
| 36891 | } | | |
| 36892 | else | 36685 | else |
| 36893 | .none); | 36686 | .none); |
| 36894 | } else { | 36687 | } else { |
| ... | @@ -36903,7 +36696,7 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded | ... | @@ -36903,7 +36696,7 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded |
| 36903 | const tag_info = ip.loadEnumType(union_type.tagTypePtr(ip).*); | 36696 | const tag_info = ip.loadEnumType(union_type.tagTypePtr(ip).*); |
| 36904 | if (tag_info.names.len > fields_len) { | 36697 | if (tag_info.names.len > fields_len) { |
| 36905 | const msg = msg: { | 36698 | const msg = msg: { |
| 36906 | const msg = try sema.errMsg(&block_scope, src, "enum field(s) missing in union", .{}); | 36699 | const msg = try sema.errMsg(src, "enum field(s) missing in union", .{}); |
| 36907 | errdefer msg.destroy(sema.gpa); | 36700 | errdefer msg.destroy(sema.gpa); |
| 36908 | | 36701 | |
| 36909 | for (tag_info.names.get(ip), 0..) |field_name, field_index| { | 36702 | for (tag_info.names.get(ip), 0..) |field_name, field_index| { |
| ... | @@ -36945,7 +36738,7 @@ fn generateUnionTagTypeNumbered( | ... | @@ -36945,7 +36738,7 @@ fn generateUnionTagTypeNumbered( |
| 36945 | const ip = &mod.intern_pool; | 36738 | const ip = &mod.intern_pool; |
| 36946 | | 36739 | |
| 36947 | const src_decl = mod.declPtr(block.src_decl); | 36740 | const src_decl = mod.declPtr(block.src_decl); |
| 36948 | const new_decl_index = try mod.allocateNewDecl(block.namespace, src_decl.src_node); | 36741 | const new_decl_index = try mod.allocateNewDecl(block.namespace); |
| 36949 | errdefer mod.destroyDecl(new_decl_index); | 36742 | errdefer mod.destroyDecl(new_decl_index); |
| 36950 | const fqn = try union_owner_decl.fullyQualifiedName(mod); | 36743 | const fqn = try union_owner_decl.fullyQualifiedName(mod); |
| 36951 | const name = try ip.getOrPutStringFmt( | 36744 | const name = try ip.getOrPutStringFmt( |
| ... | @@ -36997,7 +36790,7 @@ fn generateUnionTagTypeSimple( | ... | @@ -36997,7 +36790,7 @@ fn generateUnionTagTypeSimple( |
| 36997 | const new_decl_index = new_decl_index: { | 36790 | const new_decl_index = new_decl_index: { |
| 36998 | const fqn = try union_owner_decl.fullyQualifiedName(mod); | 36791 | const fqn = try union_owner_decl.fullyQualifiedName(mod); |
| 36999 | const src_decl = mod.declPtr(block.src_decl); | 36792 | const src_decl = mod.declPtr(block.src_decl); |
| 37000 | const new_decl_index = try mod.allocateNewDecl(block.namespace, src_decl.src_node); | 36793 | const new_decl_index = try mod.allocateNewDecl(block.namespace); |
| 37001 | errdefer mod.destroyDecl(new_decl_index); | 36794 | errdefer mod.destroyDecl(new_decl_index); |
| 37002 | const name = try ip.getOrPutStringFmt( | 36795 | const name = try ip.getOrPutStringFmt( |
| 37003 | gpa, | 36796 | gpa, |
| ... | @@ -37037,8 +36830,7 @@ fn generateUnionTagTypeSimple( | ... | @@ -37037,8 +36830,7 @@ fn generateUnionTagTypeSimple( |
| 37037 | } | 36830 | } |
| 37038 | | 36831 | |
| 37039 | fn getBuiltin(sema: *Sema, name: []const u8) CompileError!Air.Inst.Ref { | 36832 | fn getBuiltin(sema: *Sema, name: []const u8) CompileError!Air.Inst.Ref { |
| 37040 | const gpa = sema.gpa; | 36833 | const zcu = sema.mod; |
| 37041 | const src = LazySrcLoc.nodeOffset(0); | | |
| 37042 | | 36834 | |
| 37043 | var block: Block = .{ | 36835 | var block: Block = .{ |
| 37044 | .parent = null, | 36836 | .parent = null, |
| ... | @@ -37048,8 +36840,23 @@ fn getBuiltin(sema: *Sema, name: []const u8) CompileError!Air.Inst.Ref { | ... | @@ -37048,8 +36840,23 @@ fn getBuiltin(sema: *Sema, name: []const u8) CompileError!Air.Inst.Ref { |
| 37048 | .instructions = .{}, | 36840 | .instructions = .{}, |
| 37049 | .inlining = null, | 36841 | .inlining = null, |
| 37050 | .is_comptime = true, | 36842 | .is_comptime = true, |
| | 36843 | .src_base_inst = sema.owner_decl.zir_decl_index.unwrap() orelse owner: { |
| | 36844 | assert(sema.owner_decl.has_tv); |
| | 36845 | assert(sema.owner_decl.owns_tv); |
| | 36846 | switch (sema.owner_decl.typeOf(zcu).zigTypeTag(zcu)) { |
| | 36847 | .Type => break :owner sema.owner_decl.val.toType().typeDeclInst(zcu).?, |
| | 36848 | .Fn => { |
| | 36849 | const owner = zcu.funcInfo(sema.owner_decl.val.toIntern()).generic_owner; |
| | 36850 | const generic_owner_decl = zcu.declPtr(zcu.funcInfo(owner).owner_decl); |
| | 36851 | break :owner generic_owner_decl.zir_decl_index.unwrap().?; |
| | 36852 | }, |
| | 36853 | else => unreachable, |
| | 36854 | } |
| | 36855 | }, |
| 37051 | }; | 36856 | }; |
| 37052 | defer block.instructions.deinit(gpa); | 36857 | defer block.instructions.deinit(sema.gpa); |
| | 36858 | |
| | 36859 | const src = block.nodeOffset(0); |
| 37053 | | 36860 | |
| 37054 | const decl_index = try getBuiltinDecl(sema, &block, name); | 36861 | const decl_index = try getBuiltinDecl(sema, &block, name); |
| 37055 | return sema.analyzeDeclVal(&block, src, decl_index); | 36862 | return sema.analyzeDeclVal(&block, src, decl_index); |
| ... | @@ -37058,7 +36865,7 @@ fn getBuiltin(sema: *Sema, name: []const u8) CompileError!Air.Inst.Ref { | ... | @@ -37058,7 +36865,7 @@ fn getBuiltin(sema: *Sema, name: []const u8) CompileError!Air.Inst.Ref { |
| 37058 | fn getBuiltinDecl(sema: *Sema, block: *Block, name: []const u8) CompileError!InternPool.DeclIndex { | 36865 | fn getBuiltinDecl(sema: *Sema, block: *Block, name: []const u8) CompileError!InternPool.DeclIndex { |
| 37059 | const gpa = sema.gpa; | 36866 | const gpa = sema.gpa; |
| 37060 | | 36867 | |
| 37061 | const src = LazySrcLoc.nodeOffset(0); | 36868 | const src = block.nodeOffset(0); |
| 37062 | | 36869 | |
| 37063 | const mod = sema.mod; | 36870 | const mod = sema.mod; |
| 37064 | const ip = &mod.intern_pool; | 36871 | const ip = &mod.intern_pool; |
| ... | @@ -37085,6 +36892,7 @@ fn getBuiltinDecl(sema: *Sema, block: *Block, name: []const u8) CompileError!Int | ... | @@ -37085,6 +36892,7 @@ fn getBuiltinDecl(sema: *Sema, block: *Block, name: []const u8) CompileError!Int |
| 37085 | } | 36892 | } |
| 37086 | | 36893 | |
| 37087 | fn getBuiltinType(sema: *Sema, name: []const u8) CompileError!Type { | 36894 | fn getBuiltinType(sema: *Sema, name: []const u8) CompileError!Type { |
| | 36895 | const zcu = sema.mod; |
| 37088 | const ty_inst = try sema.getBuiltin(name); | 36896 | const ty_inst = try sema.getBuiltin(name); |
| 37089 | | 36897 | |
| 37090 | var block: Block = .{ | 36898 | var block: Block = .{ |
| ... | @@ -37095,9 +36903,23 @@ fn getBuiltinType(sema: *Sema, name: []const u8) CompileError!Type { | ... | @@ -37095,9 +36903,23 @@ fn getBuiltinType(sema: *Sema, name: []const u8) CompileError!Type { |
| 37095 | .instructions = .{}, | 36903 | .instructions = .{}, |
| 37096 | .inlining = null, | 36904 | .inlining = null, |
| 37097 | .is_comptime = true, | 36905 | .is_comptime = true, |
| | 36906 | .src_base_inst = sema.owner_decl.zir_decl_index.unwrap() orelse owner: { |
| | 36907 | assert(sema.owner_decl.has_tv); |
| | 36908 | assert(sema.owner_decl.owns_tv); |
| | 36909 | switch (sema.owner_decl.typeOf(zcu).zigTypeTag(zcu)) { |
| | 36910 | .Type => break :owner sema.owner_decl.val.toType().typeDeclInst(zcu).?, |
| | 36911 | .Fn => { |
| | 36912 | const owner = zcu.funcInfo(sema.owner_decl.val.toIntern()).generic_owner; |
| | 36913 | const generic_owner_decl = zcu.declPtr(zcu.funcInfo(owner).owner_decl); |
| | 36914 | break :owner generic_owner_decl.zir_decl_index.unwrap().?; |
| | 36915 | }, |
| | 36916 | else => unreachable, |
| | 36917 | } |
| | 36918 | }, |
| 37098 | }; | 36919 | }; |
| 37099 | defer block.instructions.deinit(sema.gpa); | 36920 | defer block.instructions.deinit(sema.gpa); |
| 37100 | const src = LazySrcLoc.nodeOffset(0); | 36921 | |
| | 36922 | const src = block.nodeOffset(0); |
| 37101 | | 36923 | |
| 37102 | const result_ty = sema.analyzeAsType(&block, src, ty_inst) catch |err| switch (err) { | 36924 | const result_ty = sema.analyzeAsType(&block, src, ty_inst) catch |err| switch (err) { |
| 37103 | error.AnalysisFail => std.debug.panic("std.builtin.{s} is corrupt", .{name}), | 36925 | error.AnalysisFail => std.debug.panic("std.builtin.{s} is corrupt", .{name}), |
| ... | @@ -37113,12 +36935,12 @@ fn getBuiltinType(sema: *Sema, name: []const u8) CompileError!Type { | ... | @@ -37113,12 +36935,12 @@ fn getBuiltinType(sema: *Sema, name: []const u8) CompileError!Type { |
| 37113 | /// that the types are already resolved. | 36935 | /// that the types are already resolved. |
| 37114 | /// TODO assert the return value matches `ty.onePossibleValue` | 36936 | /// TODO assert the return value matches `ty.onePossibleValue` |
| 37115 | pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value { | 36937 | pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value { |
| 37116 | const mod = sema.mod; | 36938 | const zcu = sema.mod; |
| 37117 | const ip = &mod.intern_pool; | 36939 | const ip = &zcu.intern_pool; |
| 37118 | return switch (ty.toIntern()) { | 36940 | return switch (ty.toIntern()) { |
| 37119 | .u0_type, | 36941 | .u0_type, |
| 37120 | .i0_type, | 36942 | .i0_type, |
| 37121 | => try mod.intValue(ty, 0), | 36943 | => try zcu.intValue(ty, 0), |
| 37122 | .u1_type, | 36944 | .u1_type, |
| 37123 | .u8_type, | 36945 | .u8_type, |
| 37124 | .i8_type, | 36946 | .i8_type, |
| ... | @@ -37181,7 +37003,7 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value { | ... | @@ -37181,7 +37003,7 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value { |
| 37181 | .anyframe_type => unreachable, | 37003 | .anyframe_type => unreachable, |
| 37182 | .null_type => Value.null, | 37004 | .null_type => Value.null, |
| 37183 | .undefined_type => Value.undef, | 37005 | .undefined_type => Value.undef, |
| 37184 | .optional_noreturn_type => try mod.nullValue(ty), | 37006 | .optional_noreturn_type => try zcu.nullValue(ty), |
| 37185 | .generic_poison_type => error.GenericPoison, | 37007 | .generic_poison_type => error.GenericPoison, |
| 37186 | .empty_struct_type => Value.empty_struct, | 37008 | .empty_struct_type => Value.empty_struct, |
| 37187 | // values, not types | 37009 | // values, not types |
| ... | @@ -37295,13 +37117,13 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value { | ... | @@ -37295,13 +37117,13 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value { |
| 37295 | => switch (ip.indexToKey(ty.toIntern())) { | 37117 | => switch (ip.indexToKey(ty.toIntern())) { |
| 37296 | inline .array_type, .vector_type => |seq_type, seq_tag| { | 37118 | inline .array_type, .vector_type => |seq_type, seq_tag| { |
| 37297 | const has_sentinel = seq_tag == .array_type and seq_type.sentinel != .none; | 37119 | const has_sentinel = seq_tag == .array_type and seq_type.sentinel != .none; |
| 37298 | if (seq_type.len + @intFromBool(has_sentinel) == 0) return Value.fromInterned((try mod.intern(.{ .aggregate = .{ | 37120 | if (seq_type.len + @intFromBool(has_sentinel) == 0) return Value.fromInterned((try zcu.intern(.{ .aggregate = .{ |
| 37299 | .ty = ty.toIntern(), | 37121 | .ty = ty.toIntern(), |
| 37300 | .storage = .{ .elems = &.{} }, | 37122 | .storage = .{ .elems = &.{} }, |
| 37301 | } }))); | 37123 | } }))); |
| 37302 | | 37124 | |
| 37303 | if (try sema.typeHasOnePossibleValue(Type.fromInterned(seq_type.child))) |opv| { | 37125 | if (try sema.typeHasOnePossibleValue(Type.fromInterned(seq_type.child))) |opv| { |
| 37304 | return Value.fromInterned((try mod.intern(.{ .aggregate = .{ | 37126 | return Value.fromInterned((try zcu.intern(.{ .aggregate = .{ |
| 37305 | .ty = ty.toIntern(), | 37127 | .ty = ty.toIntern(), |
| 37306 | .storage = .{ .repeated_elem = opv.toIntern() }, | 37128 | .storage = .{ .repeated_elem = opv.toIntern() }, |
| 37307 | } }))); | 37129 | } }))); |
| ... | @@ -37316,7 +37138,7 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value { | ... | @@ -37316,7 +37138,7 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value { |
| 37316 | if (struct_type.field_types.len == 0) { | 37138 | if (struct_type.field_types.len == 0) { |
| 37317 | // In this case the struct has no fields at all and | 37139 | // In this case the struct has no fields at all and |
| 37318 | // therefore has one possible value. | 37140 | // therefore has one possible value. |
| 37319 | return Value.fromInterned((try mod.intern(.{ .aggregate = .{ | 37141 | return Value.fromInterned((try zcu.intern(.{ .aggregate = .{ |
| 37320 | .ty = ty.toIntern(), | 37142 | .ty = ty.toIntern(), |
| 37321 | .storage = .{ .elems = &.{} }, | 37143 | .storage = .{ .elems = &.{} }, |
| 37322 | } }))); | 37144 | } }))); |
| ... | @@ -37333,12 +37155,11 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value { | ... | @@ -37333,12 +37155,11 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value { |
| 37333 | continue; | 37155 | continue; |
| 37334 | } | 37156 | } |
| 37335 | const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[i]); | 37157 | const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[i]); |
| 37336 | if (field_ty.eql(ty, mod)) { | 37158 | if (field_ty.eql(ty, zcu)) { |
| 37337 | const msg = try Module.ErrorMsg.create( | 37159 | const msg = try sema.errMsg( |
| 37338 | sema.gpa, | 37160 | ty.srcLoc(zcu), |
| 37339 | mod.declPtr(struct_type.decl.unwrap().?).srcLoc(mod), | | |
| 37340 | "struct '{}' depends on itself", | 37161 | "struct '{}' depends on itself", |
| 37341 | .{ty.fmt(mod)}, | 37162 | .{ty.fmt(zcu)}, |
| 37342 | ); | 37163 | ); |
| 37343 | try sema.addFieldErrNote(ty, i, msg, "while checking this field", .{}); | 37164 | try sema.addFieldErrNote(ty, i, msg, "while checking this field", .{}); |
| 37344 | return sema.failWithOwnedErrorMsg(null, msg); | 37165 | return sema.failWithOwnedErrorMsg(null, msg); |
| ... | @@ -37350,7 +37171,7 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value { | ... | @@ -37350,7 +37171,7 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value { |
| 37350 | | 37171 | |
| 37351 | // In this case the struct has no runtime-known fields and | 37172 | // In this case the struct has no runtime-known fields and |
| 37352 | // therefore has one possible value. | 37173 | // therefore has one possible value. |
| 37353 | return Value.fromInterned((try mod.intern(.{ .aggregate = .{ | 37174 | return Value.fromInterned((try zcu.intern(.{ .aggregate = .{ |
| 37354 | .ty = ty.toIntern(), | 37175 | .ty = ty.toIntern(), |
| 37355 | .storage = .{ .elems = field_vals }, | 37176 | .storage = .{ .elems = field_vals }, |
| 37356 | } }))); | 37177 | } }))); |
| ... | @@ -37363,7 +37184,7 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value { | ... | @@ -37363,7 +37184,7 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value { |
| 37363 | // In this case the struct has all comptime-known fields and | 37184 | // In this case the struct has all comptime-known fields and |
| 37364 | // therefore has one possible value. | 37185 | // therefore has one possible value. |
| 37365 | // TODO: write something like getCoercedInts to avoid needing to dupe | 37186 | // TODO: write something like getCoercedInts to avoid needing to dupe |
| 37366 | return Value.fromInterned((try mod.intern(.{ .aggregate = .{ | 37187 | return Value.fromInterned((try zcu.intern(.{ .aggregate = .{ |
| 37367 | .ty = ty.toIntern(), | 37188 | .ty = ty.toIntern(), |
| 37368 | .storage = .{ .elems = try sema.arena.dupe(InternPool.Index, tuple.values.get(ip)) }, | 37189 | .storage = .{ .elems = try sema.arena.dupe(InternPool.Index, tuple.values.get(ip)) }, |
| 37369 | } }))); | 37190 | } }))); |
| ... | @@ -37375,23 +37196,22 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value { | ... | @@ -37375,23 +37196,22 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value { |
| 37375 | const tag_val = (try sema.typeHasOnePossibleValue(Type.fromInterned(union_obj.tagTypePtr(ip).*))) orelse | 37196 | const tag_val = (try sema.typeHasOnePossibleValue(Type.fromInterned(union_obj.tagTypePtr(ip).*))) orelse |
| 37376 | return null; | 37197 | return null; |
| 37377 | if (union_obj.field_types.len == 0) { | 37198 | if (union_obj.field_types.len == 0) { |
| 37378 | const only = try mod.intern(.{ .empty_enum_value = ty.toIntern() }); | 37199 | const only = try zcu.intern(.{ .empty_enum_value = ty.toIntern() }); |
| 37379 | return Value.fromInterned(only); | 37200 | return Value.fromInterned(only); |
| 37380 | } | 37201 | } |
| 37381 | const only_field_ty = Type.fromInterned(union_obj.field_types.get(ip)[0]); | 37202 | const only_field_ty = Type.fromInterned(union_obj.field_types.get(ip)[0]); |
| 37382 | if (only_field_ty.eql(ty, mod)) { | 37203 | if (only_field_ty.eql(ty, zcu)) { |
| 37383 | const msg = try Module.ErrorMsg.create( | 37204 | const msg = try sema.errMsg( |
| 37384 | sema.gpa, | 37205 | ty.srcLoc(zcu), |
| 37385 | mod.declPtr(union_obj.decl).srcLoc(mod), | | |
| 37386 | "union '{}' depends on itself", | 37206 | "union '{}' depends on itself", |
| 37387 | .{ty.fmt(mod)}, | 37207 | .{ty.fmt(zcu)}, |
| 37388 | ); | 37208 | ); |
| 37389 | try sema.addFieldErrNote(ty, 0, msg, "while checking this field", .{}); | 37209 | try sema.addFieldErrNote(ty, 0, msg, "while checking this field", .{}); |
| 37390 | return sema.failWithOwnedErrorMsg(null, msg); | 37210 | return sema.failWithOwnedErrorMsg(null, msg); |
| 37391 | } | 37211 | } |
| 37392 | const val_val = (try sema.typeHasOnePossibleValue(only_field_ty)) orelse | 37212 | const val_val = (try sema.typeHasOnePossibleValue(only_field_ty)) orelse |
| 37393 | return null; | 37213 | return null; |
| 37394 | const only = try mod.intern(.{ .un = .{ | 37214 | const only = try zcu.intern(.{ .un = .{ |
| 37395 | .ty = ty.toIntern(), | 37215 | .ty = ty.toIntern(), |
| 37396 | .tag = tag_val.toIntern(), | 37216 | .tag = tag_val.toIntern(), |
| 37397 | .val = val_val.toIntern(), | 37217 | .val = val_val.toIntern(), |
| ... | @@ -37406,7 +37226,7 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value { | ... | @@ -37406,7 +37226,7 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value { |
| 37406 | if (enum_type.tag_ty == .comptime_int_type) return null; | 37226 | if (enum_type.tag_ty == .comptime_int_type) return null; |
| 37407 | | 37227 | |
| 37408 | if (try sema.typeHasOnePossibleValue(Type.fromInterned(enum_type.tag_ty))) |int_opv| { | 37228 | if (try sema.typeHasOnePossibleValue(Type.fromInterned(enum_type.tag_ty))) |int_opv| { |
| 37409 | const only = try mod.intern(.{ .enum_tag = .{ | 37229 | const only = try zcu.intern(.{ .enum_tag = .{ |
| 37410 | .ty = ty.toIntern(), | 37230 | .ty = ty.toIntern(), |
| 37411 | .int = int_opv.toIntern(), | 37231 | .int = int_opv.toIntern(), |
| 37412 | } }); | 37232 | } }); |
| ... | @@ -37416,18 +37236,18 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value { | ... | @@ -37416,18 +37236,18 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value { |
| 37416 | return null; | 37236 | return null; |
| 37417 | }, | 37237 | }, |
| 37418 | .auto, .explicit => { | 37238 | .auto, .explicit => { |
| 37419 | if (Type.fromInterned(enum_type.tag_ty).hasRuntimeBits(mod)) return null; | 37239 | if (Type.fromInterned(enum_type.tag_ty).hasRuntimeBits(zcu)) return null; |
| 37420 | | 37240 | |
| 37421 | return Value.fromInterned(switch (enum_type.names.len) { | 37241 | return Value.fromInterned(switch (enum_type.names.len) { |
| 37422 | 0 => try mod.intern(.{ .empty_enum_value = ty.toIntern() }), | 37242 | 0 => try zcu.intern(.{ .empty_enum_value = ty.toIntern() }), |
| 37423 | 1 => try mod.intern(.{ .enum_tag = .{ | 37243 | 1 => try zcu.intern(.{ .enum_tag = .{ |
| 37424 | .ty = ty.toIntern(), | 37244 | .ty = ty.toIntern(), |
| 37425 | .int = if (enum_type.values.len == 0) | 37245 | .int = if (enum_type.values.len == 0) |
| 37426 | (try mod.intValue(Type.fromInterned(enum_type.tag_ty), 0)).toIntern() | 37246 | (try zcu.intValue(Type.fromInterned(enum_type.tag_ty), 0)).toIntern() |
| 37427 | else | 37247 | else |
| 37428 | try mod.intern_pool.getCoercedInts( | 37248 | try zcu.intern_pool.getCoercedInts( |
| 37429 | mod.gpa, | 37249 | zcu.gpa, |
| 37430 | mod.intern_pool.indexToKey(enum_type.values.get(ip)[0]).int, | 37250 | zcu.intern_pool.indexToKey(enum_type.values.get(ip)[0]).int, |
| 37431 | enum_type.tag_ty, | 37251 | enum_type.tag_ty, |
| 37432 | ), | 37252 | ), |
| 37433 | } }), | 37253 | } }), |
| ... | @@ -37765,7 +37585,7 @@ fn unionFieldIndex( | ... | @@ -37765,7 +37585,7 @@ fn unionFieldIndex( |
| 37765 | try sema.resolveTypeFields(union_ty); | 37585 | try sema.resolveTypeFields(union_ty); |
| 37766 | const union_obj = mod.typeToUnion(union_ty).?; | 37586 | const union_obj = mod.typeToUnion(union_ty).?; |
| 37767 | const field_index = union_obj.loadTagType(ip).nameIndex(ip, field_name) orelse | 37587 | const field_index = union_obj.loadTagType(ip).nameIndex(ip, field_name) orelse |
| 37768 | return sema.failWithBadUnionFieldAccess(block, union_obj, field_src, field_name); | 37588 | return sema.failWithBadUnionFieldAccess(block, union_ty, union_obj, field_src, field_name); |
| 37769 | return @intCast(field_index); | 37589 | return @intCast(field_index); |
| 37770 | } | 37590 | } |
| 37771 | | 37591 | |
| ... | @@ -37784,7 +37604,7 @@ fn structFieldIndex( | ... | @@ -37784,7 +37604,7 @@ fn structFieldIndex( |
| 37784 | } else { | 37604 | } else { |
| 37785 | const struct_type = mod.typeToStruct(struct_ty).?; | 37605 | const struct_type = mod.typeToStruct(struct_ty).?; |
| 37786 | return struct_type.nameIndex(ip, field_name) orelse | 37606 | return struct_type.nameIndex(ip, field_name) orelse |
| 37787 | return sema.failWithBadStructFieldAccess(block, struct_type, field_src, field_name); | 37607 | return sema.failWithBadStructFieldAccess(block, struct_ty, struct_type, field_src, field_name); |
| 37788 | } | 37608 | } |
| 37789 | } | 37609 | } |
| 37790 | | 37610 | |
| ... | @@ -38556,9 +38376,9 @@ fn checkRuntimeValue(sema: *Sema, ptr: Air.Inst.Ref) bool { | ... | @@ -38556,9 +38376,9 @@ fn checkRuntimeValue(sema: *Sema, ptr: Air.Inst.Ref) bool { |
| 38556 | fn validateRuntimeValue(sema: *Sema, block: *Block, val_src: LazySrcLoc, val: Air.Inst.Ref) CompileError!void { | 38376 | fn validateRuntimeValue(sema: *Sema, block: *Block, val_src: LazySrcLoc, val: Air.Inst.Ref) CompileError!void { |
| 38557 | if (sema.checkRuntimeValue(val)) return; | 38377 | if (sema.checkRuntimeValue(val)) return; |
| 38558 | return sema.failWithOwnedErrorMsg(block, msg: { | 38378 | return sema.failWithOwnedErrorMsg(block, msg: { |
| 38559 | const msg = try sema.errMsg(block, val_src, "runtime value contains reference to comptime var", .{}); | 38379 | const msg = try sema.errMsg(val_src, "runtime value contains reference to comptime var", .{}); |
| 38560 | errdefer msg.destroy(sema.gpa); | 38380 | errdefer msg.destroy(sema.gpa); |
| 38561 | try sema.errNote(block, val_src, msg, "comptime var pointers are not available at runtime", .{}); | 38381 | try sema.errNote(val_src, msg, "comptime var pointers are not available at runtime", .{}); |
| 38562 | break :msg msg; | 38382 | break :msg msg; |
| 38563 | }); | 38383 | }); |
| 38564 | } | 38384 | } |
| ... | @@ -38649,6 +38469,14 @@ fn maybeDerefSliceAsArray( | ... | @@ -38649,6 +38469,14 @@ fn maybeDerefSliceAsArray( |
| 38649 | return sema.pointerDeref(block, src, casted_ptr, ptr_ty); | 38469 | return sema.pointerDeref(block, src, casted_ptr, ptr_ty); |
| 38650 | } | 38470 | } |
| 38651 | | 38471 | |
| | 38472 | fn analyzeUnreachable(sema: *Sema, block: *Block, src: LazySrcLoc, safety_check: bool) !void { |
| | 38473 | if (safety_check and block.wantSafety()) { |
| | 38474 | try sema.safetyPanic(block, src, .unreach); |
| | 38475 | } else { |
| | 38476 | _ = try block.addNoOp(.unreach); |
| | 38477 | } |
| | 38478 | } |
| | 38479 | |
| 38652 | pub const bitCastVal = @import("Sema/bitcast.zig").bitCast; | 38480 | pub const bitCastVal = @import("Sema/bitcast.zig").bitCast; |
| 38653 | pub const bitCastSpliceVal = @import("Sema/bitcast.zig").bitCastSplice; | 38481 | pub const bitCastSpliceVal = @import("Sema/bitcast.zig").bitCastSplice; |
| 38654 | | 38482 | |