| ... | ... | @@ -34,7 +34,7 @@ func_index: InternPool.Index, |
| 34 | 34 | func_is_naked: bool, |
| 35 | 35 | /// Used to restore the error return trace when returning a non-error from a function. |
| 36 | 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 | 38 | /// When semantic analysis needs to know the return type of the function whose body |
| 39 | 39 | /// is being analyzed, this `Type` should be used instead of going through `func`. |
| 40 | 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 | 65 | /// instantiation callsite so that compile errors on the parameter types of the |
| 66 | 66 | /// instantiation can point back to the instantiation site in addition to the |
| 67 | 67 | /// declaration site. |
| 68 | | generic_call_src: LazySrcLoc = .unneeded, |
| 69 | | /// Corresponds to `generic_call_src`. |
| 70 | | generic_call_decl: InternPool.OptionalDeclIndex = .none, |
| 68 | generic_call_src: LazySrcLoc = LazySrcLoc.unneeded, |
| 71 | 69 | /// The key is types that must be fully resolved prior to machine code |
| 72 | 70 | /// generation pass. Types are added to this set when resolving them |
| 73 | 71 | /// immediately could cause a dependency loop, but they do need to be resolved |
| ... | ... | @@ -131,7 +129,6 @@ const MaybeComptimeAlloc = struct { |
| 131 | 129 | /// If the instruction is one of these three tags, `src` may be `.unneeded`. |
| 132 | 130 | stores: std.MultiArrayList(struct { |
| 133 | 131 | inst: Air.Inst.Index, |
| 134 | | src_decl: InternPool.DeclIndex, |
| 135 | 132 | src: LazySrcLoc, |
| 136 | 133 | }) = .{}, |
| 137 | 134 | }; |
| ... | ... | @@ -361,8 +358,8 @@ pub const Block = struct { |
| 361 | 358 | label: ?*Label = null, |
| 362 | 359 | inlining: ?*Inlining, |
| 363 | 360 | /// If runtime_index is not 0 then one of these is guaranteed to be non null. |
| 364 | | runtime_cond: ?Module.SrcLoc = null, |
| 365 | | runtime_loop: ?Module.SrcLoc = null, |
| 361 | runtime_cond: ?LazySrcLoc = null, |
| 362 | runtime_loop: ?LazySrcLoc = null, |
| 366 | 363 | /// This Decl is the Decl according to the Zig source code corresponding to this Block. |
| 367 | 364 | /// This can vary during inline or comptime function calls. See `Sema.owner_decl` |
| 368 | 365 | /// for the one that will be the same for all Block instances. |
| ... | ... | @@ -395,25 +392,39 @@ pub const Block = struct { |
| 395 | 392 | /// `block` in order for codegen to match lexical scoping for debug vars. |
| 396 | 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 | 415 | fn nodeOffset(block: Block, node_offset: i32) LazySrcLoc { |
| 401 | | _ = block; |
| 402 | | return LazySrcLoc.nodeOffset(node_offset); |
| 416 | return block.src(LazySrcLoc.Offset.nodeOffset(node_offset)); |
| 403 | 417 | } |
| 404 | 418 | |
| 405 | 419 | fn tokenOffset(block: Block, tok_offset: u32) LazySrcLoc { |
| 406 | | _ = block; |
| 407 | | return .{ .token_offset = tok_offset }; |
| 420 | return block.src(.{ .token_offset = tok_offset }); |
| 408 | 421 | } |
| 409 | 422 | |
| 410 | 423 | const ComptimeReason = union(enum) { |
| 411 | 424 | c_import: struct { |
| 412 | | block: *Block, |
| 413 | 425 | src: LazySrcLoc, |
| 414 | 426 | }, |
| 415 | 427 | comptime_ret_ty: struct { |
| 416 | | block: *Block, |
| 417 | 428 | func: Air.Inst.Ref, |
| 418 | 429 | func_src: LazySrcLoc, |
| 419 | 430 | return_ty: Type, |
| ... | ... | @@ -425,27 +436,23 @@ pub const Block = struct { |
| 425 | 436 | const prefix = "expression is evaluated at comptime because "; |
| 426 | 437 | switch (cr) { |
| 427 | 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 | 441 | .comptime_ret_ty => |rt| { |
| 431 | | const src_loc = if (try sema.funcDeclSrc(rt.func)) |fn_decl| blk: { |
| 432 | | var src_loc = fn_decl.srcLoc(mod); |
| 433 | | src_loc.lazy = .{ .node_offset_fn_type_ret_ty = 0 }; |
| 434 | | break :blk src_loc; |
| 435 | | } else blk: { |
| 436 | | const src_decl = mod.declPtr(rt.block.src_decl); |
| 437 | | break :blk src_decl.toSrcLoc(rt.func_src, mod); |
| 438 | | }; |
| 442 | const ret_ty_src: LazySrcLoc = if (try sema.funcDeclSrc(rt.func)) |fn_decl| .{ |
| 443 | .base_node_inst = fn_decl.zir_decl_index.unwrap().?, |
| 444 | .offset = .{ .node_offset_fn_type_ret_ty = 0 }, |
| 445 | } else rt.func_src; |
| 439 | 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( |
| 443 | | src_loc, |
| 449 | try sema.errNote( |
| 450 | ret_ty_src, |
| 444 | 451 | parent, |
| 445 | 452 | prefix ++ "the function returns a comptime-only type '{}'", |
| 446 | 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 | 532 | .c_import_buf = parent.c_import_buf, |
| 526 | 533 | .error_return_trace_index = parent.error_return_trace_index, |
| 527 | 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 | 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 | 826 | pub fn ownerModule(block: Block) *Package.Module { |
| 827 | 827 | const zcu = block.sema.mod; |
| 828 | 828 | return zcu.namespacePtr(block.namespace).file_scope.mod; |
| ... | ... | @@ -1237,7 +1237,7 @@ fn analyzeBodyInner( |
| 1237 | 1237 | .@"asm" => try sema.zirAsm( block, extended, false), |
| 1238 | 1238 | .asm_expr => try sema.zirAsm( block, extended, true), |
| 1239 | 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 | 1241 | .min_multi => try sema.zirMinMaxMulti( block, extended, .min), |
| 1242 | 1242 | .max_multi => try sema.zirMinMaxMulti( block, extended, .max), |
| 1243 | 1243 | .add_with_overflow => try sema.zirOverflowArithmetic(block, extended, extended.opcode), |
| ... | ... | @@ -1475,10 +1475,9 @@ fn analyzeBodyInner( |
| 1475 | 1475 | if (@intFromEnum(target_runtime_index) < @intFromEnum(block.runtime_index)) { |
| 1476 | 1476 | const runtime_src = block.runtime_cond orelse block.runtime_loop.?; |
| 1477 | 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 | 1479 | errdefer msg.destroy(sema.gpa); |
| 1480 | | |
| 1481 | | try mod.errNoteNonLazy(runtime_src, msg, "runtime control flow here", .{}); |
| 1480 | try sema.errNote(runtime_src, msg, "runtime control flow here", .{}); |
| 1482 | 1481 | break :msg msg; |
| 1483 | 1482 | }; |
| 1484 | 1483 | return sema.failWithOwnedErrorMsg(block, msg); |
| ... | ... | @@ -1522,7 +1521,7 @@ fn analyzeBodyInner( |
| 1522 | 1521 | .repeat => { |
| 1523 | 1522 | if (block.is_comptime) { |
| 1524 | 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 | 1525 | try sema.emitBackwardBranch(block, src); |
| 1527 | 1526 | i = 0; |
| 1528 | 1527 | continue; |
| ... | ... | @@ -1535,7 +1534,7 @@ fn analyzeBodyInner( |
| 1535 | 1534 | }, |
| 1536 | 1535 | .repeat_inline => { |
| 1537 | 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 | 1538 | try sema.emitBackwardBranch(block, src); |
| 1540 | 1539 | i = 0; |
| 1541 | 1540 | continue; |
| ... | ... | @@ -1705,7 +1704,7 @@ fn analyzeBodyInner( |
| 1705 | 1704 | } |
| 1706 | 1705 | // Same as condbr_inline. TODO https://github.com/ziglang/zig/issues/8220 |
| 1707 | 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 | 1708 | const extra = sema.code.extraData(Zir.Inst.CondBr, inst_data.payload_index); |
| 1710 | 1709 | const then_body = sema.code.bodySlice(extra.end, extra.data.then_body_len); |
| 1711 | 1710 | const else_body = sema.code.bodySlice( |
| ... | ... | @@ -1725,7 +1724,7 @@ fn analyzeBodyInner( |
| 1725 | 1724 | }, |
| 1726 | 1725 | .condbr_inline => blk: { |
| 1727 | 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 | 1728 | const extra = sema.code.extraData(Zir.Inst.CondBr, inst_data.payload_index); |
| 1730 | 1729 | const then_body = sema.code.bodySlice(extra.end, extra.data.then_body_len); |
| 1731 | 1730 | const else_body = sema.code.bodySlice( |
| ... | ... | @@ -1749,7 +1748,7 @@ fn analyzeBodyInner( |
| 1749 | 1748 | if (!block.is_comptime) break :blk try sema.zirTry(block, inst); |
| 1750 | 1749 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 1751 | 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 | 1752 | const extra = sema.code.extraData(Zir.Inst.Try, inst_data.payload_index); |
| 1754 | 1753 | const inline_body = sema.code.bodySlice(extra.end, extra.data.body_len); |
| 1755 | 1754 | const err_union = try sema.resolveInst(extra.data.operand); |
| ... | ... | @@ -1775,7 +1774,7 @@ fn analyzeBodyInner( |
| 1775 | 1774 | if (!block.is_comptime) break :blk try sema.zirTryPtr(block, inst); |
| 1776 | 1775 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 1777 | 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 | 1778 | const extra = sema.code.extraData(Zir.Inst.Try, inst_data.payload_index); |
| 1780 | 1779 | const inline_body = sema.code.bodySlice(extra.end, extra.data.body_len); |
| 1781 | 1780 | const operand = try sema.resolveInst(extra.data.operand); |
| ... | ... | @@ -1939,14 +1938,14 @@ fn resolveDestType( |
| 1939 | 1938 | // Cast builtins use their result type as the destination type, but |
| 1940 | 1939 | // it could be an anytype argument, which we can't catch in AstGen. |
| 1941 | 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 | 1942 | errdefer msg.destroy(sema.gpa); |
| 1944 | 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", .{}), |
| 1946 | | .anyopaque_ptr => |ptr_src| try sema.errNote(block, ptr_src, msg, "result type is unknown due to opaque pointer type", .{}), |
| 1944 | .anytype_param => |call_src| try sema.errNote(call_src, msg, "result type is unknown due to anytype parameter", .{}), |
| 1945 | .anyopaque_ptr => |ptr_src| try sema.errNote(ptr_src, msg, "result type is unknown due to opaque pointer type", .{}), |
| 1947 | 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 | 1949 | break :msg msg; |
| 1951 | 1950 | }; |
| 1952 | 1951 | return sema.failWithOwnedErrorMsg(block, msg); |
| ... | ... | @@ -2051,7 +2050,7 @@ pub fn setupErrorReturnTrace(sema: *Sema, block: *Block, last_arg_index: usize) |
| 2051 | 2050 | var err_trace_block = block.makeSubBlock(); |
| 2052 | 2051 | defer err_trace_block.instructions.deinit(gpa); |
| 2053 | 2052 | |
| 2054 | | const src: LazySrcLoc = .unneeded; |
| 2053 | const src: LazySrcLoc = LazySrcLoc.unneeded; |
| 2055 | 2054 | |
| 2056 | 2055 | // var addrs: [err_return_trace_addr_count]usize = undefined; |
| 2057 | 2056 | const err_return_trace_addr_count = 32; |
| ... | ... | @@ -2212,9 +2211,9 @@ pub fn resolveFinalDeclValue( |
| 2212 | 2211 | |
| 2213 | 2212 | fn failWithNeededComptime(sema: *Sema, block: *Block, src: LazySrcLoc, reason: NeededComptimeReason) CompileError { |
| 2214 | 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 | 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 | 2218 | if (reason.block_comptime_reason) |block_comptime_reason| { |
| 2220 | 2219 | try block_comptime_reason.explain(sema, msg); |
| ... | ... | @@ -2241,12 +2240,12 @@ fn failWithModRemNegative(sema: *Sema, block: *Block, src: LazySrcLoc, lhs_ty: T |
| 2241 | 2240 | fn failWithExpectedOptionalType(sema: *Sema, block: *Block, src: LazySrcLoc, non_optional_ty: Type) CompileError { |
| 2242 | 2241 | const mod = sema.mod; |
| 2243 | 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 | 2244 | non_optional_ty.fmt(mod), |
| 2246 | 2245 | }); |
| 2247 | 2246 | errdefer msg.destroy(sema.gpa); |
| 2248 | 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 | 2250 | try addDeclaredHereNote(sema, msg, non_optional_ty); |
| 2252 | 2251 | break :msg msg; |
| ... | ... | @@ -2257,12 +2256,12 @@ fn failWithExpectedOptionalType(sema: *Sema, block: *Block, src: LazySrcLoc, non |
| 2257 | 2256 | fn failWithArrayInitNotSupported(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) CompileError { |
| 2258 | 2257 | const mod = sema.mod; |
| 2259 | 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 | 2260 | ty.fmt(mod), |
| 2262 | 2261 | }); |
| 2263 | 2262 | errdefer msg.destroy(sema.gpa); |
| 2264 | 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 | 2266 | break :msg msg; |
| 2268 | 2267 | }; |
| ... | ... | @@ -2291,11 +2290,11 @@ fn failWithIntegerOverflow(sema: *Sema, block: *Block, src: LazySrcLoc, int_ty: |
| 2291 | 2290 | const zcu = sema.mod; |
| 2292 | 2291 | if (int_ty.zigTypeTag(zcu) == .Vector) { |
| 2293 | 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 | 2294 | int_ty.fmt(zcu), val.fmtValue(zcu, sema), |
| 2296 | 2295 | }); |
| 2297 | 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 | 2298 | break :msg msg; |
| 2300 | 2299 | }; |
| 2301 | 2300 | return sema.failWithOwnedErrorMsg(block, msg); |
| ... | ... | @@ -2308,15 +2307,14 @@ fn failWithIntegerOverflow(sema: *Sema, block: *Block, src: LazySrcLoc, int_ty: |
| 2308 | 2307 | fn failWithInvalidComptimeFieldStore(sema: *Sema, block: *Block, init_src: LazySrcLoc, container_ty: Type, field_index: usize) CompileError { |
| 2309 | 2308 | const mod = sema.mod; |
| 2310 | 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 | 2311 | errdefer msg.destroy(sema.gpa); |
| 2313 | 2312 | |
| 2314 | 2313 | const struct_type = mod.typeToStruct(container_ty) orelse break :msg msg; |
| 2315 | | const default_value_src = mod.fieldSrcLoc(struct_type.decl.unwrap().?, .{ |
| 2316 | | .index = field_index, |
| 2317 | | .range = .value, |
| 2318 | | }); |
| 2319 | | try mod.errNoteNonLazy(default_value_src, msg, "default value set here", .{}); |
| 2314 | try sema.errNote(.{ |
| 2315 | .base_node_inst = struct_type.zir_index.unwrap().?, |
| 2316 | .offset = .{ .container_field_value = @intCast(field_index) }, |
| 2317 | }, msg, "default value set here", .{}); |
| 2320 | 2318 | break :msg msg; |
| 2321 | 2319 | }; |
| 2322 | 2320 | return sema.failWithOwnedErrorMsg(block, msg); |
| ... | ... | @@ -2324,7 +2322,7 @@ fn failWithInvalidComptimeFieldStore(sema: *Sema, block: *Block, init_src: LazyS |
| 2324 | 2322 | |
| 2325 | 2323 | fn failWithUseOfAsync(sema: *Sema, block: *Block, src: LazySrcLoc) CompileError { |
| 2326 | 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 | 2326 | errdefer msg.destroy(sema.gpa); |
| 2329 | 2327 | break :msg msg; |
| 2330 | 2328 | }; |
| ... | ... | @@ -2345,9 +2343,9 @@ fn failWithInvalidFieldAccess( |
| 2345 | 2343 | const child_ty = inner_ty.optionalChild(mod); |
| 2346 | 2344 | if (!typeSupportsFieldAccess(mod, child_ty, field_name)) break :opt; |
| 2347 | 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 | 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 | 2349 | break :msg msg; |
| 2352 | 2350 | }; |
| 2353 | 2351 | return sema.failWithOwnedErrorMsg(block, msg); |
| ... | ... | @@ -2355,9 +2353,9 @@ fn failWithInvalidFieldAccess( |
| 2355 | 2353 | const child_ty = inner_ty.errorUnionPayload(mod); |
| 2356 | 2354 | if (!typeSupportsFieldAccess(mod, child_ty, field_name)) break :err; |
| 2357 | 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 | 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 | 2359 | break :msg msg; |
| 2362 | 2360 | }; |
| 2363 | 2361 | return sema.failWithOwnedErrorMsg(block, msg); |
| ... | ... | @@ -2390,11 +2388,11 @@ fn failWithComptimeErrorRetTrace( |
| 2390 | 2388 | ) CompileError { |
| 2391 | 2389 | const mod = sema.mod; |
| 2392 | 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 | 2392 | errdefer msg.destroy(sema.gpa); |
| 2395 | 2393 | |
| 2396 | 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 | 2397 | break :msg msg; |
| 2400 | 2398 | }; |
| ... | ... | @@ -2403,17 +2401,15 @@ fn failWithComptimeErrorRetTrace( |
| 2403 | 2401 | |
| 2404 | 2402 | /// We don't return a pointer to the new error note because the pointer |
| 2405 | 2403 | /// becomes invalid when you add another one. |
| 2406 | | fn errNote( |
| 2404 | pub fn errNote( |
| 2407 | 2405 | sema: *Sema, |
| 2408 | | block: *Block, |
| 2409 | 2406 | src: LazySrcLoc, |
| 2410 | 2407 | parent: *Module.ErrorMsg, |
| 2411 | 2408 | comptime format: []const u8, |
| 2412 | 2409 | args: anytype, |
| 2413 | 2410 | ) error{OutOfMemory}!void { |
| 2414 | | const mod = sema.mod; |
| 2415 | | const src_decl = mod.declPtr(block.src_decl); |
| 2416 | | return mod.errNoteNonLazy(src_decl.toSrcLoc(src, mod), parent, format, args); |
| 2411 | const zcu = sema.mod; |
| 2412 | return zcu.errNoteNonLazy(src.upgrade(zcu), parent, format, args); |
| 2417 | 2413 | } |
| 2418 | 2414 | |
| 2419 | 2415 | fn addFieldErrNote( |
| ... | ... | @@ -2425,52 +2421,23 @@ fn addFieldErrNote( |
| 2425 | 2421 | args: anytype, |
| 2426 | 2422 | ) !void { |
| 2427 | 2423 | @setCold(true); |
| 2428 | | const mod = sema.mod; |
| 2429 | | const decl_index = container_ty.getOwnerDecl(mod); |
| 2430 | | const decl = mod.declPtr(decl_index); |
| 2431 | | |
| 2432 | | const field_src = blk: { |
| 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; |
| 2424 | const zcu = sema.mod; |
| 2425 | const type_src = container_ty.srcLocOrNull(zcu) orelse return; |
| 2426 | const field_src: LazySrcLoc = .{ |
| 2427 | .base_node_inst = type_src.base_node_inst, |
| 2428 | .offset = .{ .container_field_name = @intCast(field_index) }, |
| 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 | 2433 | pub fn errMsg( |
| 2464 | 2434 | sema: *Sema, |
| 2465 | | block: *Block, |
| 2466 | 2435 | src: LazySrcLoc, |
| 2467 | 2436 | comptime format: []const u8, |
| 2468 | 2437 | args: anytype, |
| 2469 | | ) error{ NeededSourceLocation, OutOfMemory }!*Module.ErrorMsg { |
| 2470 | | const mod = sema.mod; |
| 2471 | | if (src == .unneeded) return error.NeededSourceLocation; |
| 2472 | | const src_decl = mod.declPtr(block.src_decl); |
| 2473 | | return Module.ErrorMsg.create(sema.gpa, src_decl.toSrcLoc(src, mod), format, args); |
| 2438 | ) Allocator.Error!*Module.ErrorMsg { |
| 2439 | assert(src.offset != .unneeded); |
| 2440 | return Module.ErrorMsg.create(sema.gpa, src.upgrade(sema.mod), format, args); |
| 2474 | 2441 | } |
| 2475 | 2442 | |
| 2476 | 2443 | pub fn fail( |
| ... | ... | @@ -2480,7 +2447,7 @@ pub fn fail( |
| 2480 | 2447 | comptime format: []const u8, |
| 2481 | 2448 | args: anytype, |
| 2482 | 2449 | ) CompileError { |
| 2483 | | const err_msg = try sema.errMsg(block, src, format, args); |
| 2450 | const err_msg = try sema.errMsg(src, format, args); |
| 2484 | 2451 | inline for (args) |arg| { |
| 2485 | 2452 | if (@TypeOf(arg) == Type.Formatter) { |
| 2486 | 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 | 2481 | var block_it = start_block; |
| 2515 | 2482 | while (block_it.inlining) |inlining| { |
| 2516 | 2483 | try sema.errNote( |
| 2517 | | inlining.call_block, |
| 2518 | 2484 | inlining.call_src, |
| 2519 | 2485 | err_msg, |
| 2520 | 2486 | "called from here", |
| ... | ... | @@ -2548,7 +2514,7 @@ pub fn failWithOwnedErrorMsg(sema: *Sema, block: ?*Block, err_msg: *Module.Error |
| 2548 | 2514 | const decl = mod.declPtr(ref.referencer); |
| 2549 | 2515 | try reference_stack.append(.{ |
| 2550 | 2516 | .decl = decl.name, |
| 2551 | | .src_loc = decl.toSrcLoc(ref.src, mod), |
| 2517 | .src_loc = ref.src.upgrade(mod), |
| 2552 | 2518 | }); |
| 2553 | 2519 | } |
| 2554 | 2520 | referenced_by = ref.referencer; |
| ... | ... | @@ -2583,15 +2549,13 @@ pub fn failWithOwnedErrorMsg(sema: *Sema, block: ?*Block, err_msg: *Module.Error |
| 2583 | 2549 | /// Reference trace is preserved. |
| 2584 | 2550 | fn reparentOwnedErrorMsg( |
| 2585 | 2551 | sema: *Sema, |
| 2586 | | block: *Block, |
| 2587 | 2552 | src: LazySrcLoc, |
| 2588 | 2553 | msg: *Module.ErrorMsg, |
| 2589 | 2554 | comptime format: []const u8, |
| 2590 | 2555 | args: anytype, |
| 2591 | 2556 | ) !void { |
| 2592 | 2557 | const mod = sema.mod; |
| 2593 | | const src_decl = mod.declPtr(block.src_decl); |
| 2594 | | const resolved_src = src_decl.toSrcLoc(src, mod); |
| 2558 | const resolved_src = src.upgrade(mod); |
| 2595 | 2559 | const msg_str = try std.fmt.allocPrint(mod.gpa, format, args); |
| 2596 | 2560 | |
| 2597 | 2561 | const orig_notes = msg.notes.len; |
| ... | ... | @@ -2728,7 +2692,7 @@ fn getCaptures(sema: *Sema, block: *Block, type_src: LazySrcLoc, extra_index: us |
| 2728 | 2692 | sema.code.nullTerminatedString(str), |
| 2729 | 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 | 2696 | break :capture InternPool.CaptureValue.wrap(.{ .decl_val = decl }); |
| 2733 | 2697 | }, |
| 2734 | 2698 | .decl_ref => |str| capture: { |
| ... | ... | @@ -2737,7 +2701,7 @@ fn getCaptures(sema: *Sema, block: *Block, type_src: LazySrcLoc, extra_index: us |
| 2737 | 2701 | sema.code.nullTerminatedString(str), |
| 2738 | 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 | 2705 | break :capture InternPool.CaptureValue.wrap(.{ .decl_ref = decl }); |
| 2742 | 2706 | }, |
| 2743 | 2707 | }; |
| ... | ... | @@ -2788,7 +2752,13 @@ fn zirStructDecl( |
| 2788 | 2752 | const ip = &mod.intern_pool; |
| 2789 | 2753 | const small: Zir.Inst.StructDecl.Small = @bitCast(extended.small); |
| 2790 | 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 | 2762 | var extra_index = extra.end; |
| 2793 | 2763 | |
| 2794 | 2764 | const captures_len = if (small.has_captures_len) blk: { |
| ... | ... | @@ -2832,7 +2802,7 @@ fn zirStructDecl( |
| 2832 | 2802 | .any_aligned_fields = small.any_aligned_fields, |
| 2833 | 2803 | .has_namespace = true or decls_len > 0, // TODO: see below |
| 2834 | 2804 | .key = .{ .declared = .{ |
| 2835 | | .zir_index = try ip.trackZir(gpa, block.getFileScope(mod), inst), |
| 2805 | .zir_index = tracked_inst, |
| 2836 | 2806 | .captures = captures, |
| 2837 | 2807 | } }, |
| 2838 | 2808 | }; |
| ... | ... | @@ -2847,7 +2817,6 @@ fn zirStructDecl( |
| 2847 | 2817 | |
| 2848 | 2818 | const new_decl_index = try sema.createAnonymousDeclTypeNamed( |
| 2849 | 2819 | block, |
| 2850 | | extra.data.src_node, |
| 2851 | 2820 | Value.fromInterned(wip_ty.index), |
| 2852 | 2821 | small.name_strategy, |
| 2853 | 2822 | "struct", |
| ... | ... | @@ -2884,7 +2853,6 @@ fn zirStructDecl( |
| 2884 | 2853 | fn createAnonymousDeclTypeNamed( |
| 2885 | 2854 | sema: *Sema, |
| 2886 | 2855 | block: *Block, |
| 2887 | | src_node: std.zig.Ast.Node.Index, |
| 2888 | 2856 | val: Value, |
| 2889 | 2857 | name_strategy: Zir.Inst.NameStrategy, |
| 2890 | 2858 | anon_prefix: []const u8, |
| ... | ... | @@ -2895,7 +2863,7 @@ fn createAnonymousDeclTypeNamed( |
| 2895 | 2863 | const gpa = sema.gpa; |
| 2896 | 2864 | const namespace = block.namespace; |
| 2897 | 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 | 2867 | errdefer zcu.destroyDecl(new_decl_index); |
| 2900 | 2868 | |
| 2901 | 2869 | switch (name_strategy) { |
| ... | ... | @@ -2924,8 +2892,7 @@ fn createAnonymousDeclTypeNamed( |
| 2924 | 2892 | // If not then this is a struct type being returned from a non-generic |
| 2925 | 2893 | // function and the name doesn't matter since it will later |
| 2926 | 2894 | // result in a compile error. |
| 2927 | | const arg_val = sema.resolveConstValue(block, .unneeded, arg, undefined) catch |
| 2928 | | break :func_strat; // fall through to anon strat |
| 2895 | const arg_val = try sema.resolveValue(arg) orelse break :func_strat; // fall through to anon strat |
| 2929 | 2896 | |
| 2930 | 2897 | if (arg_i != 0) try writer.writeByte(','); |
| 2931 | 2898 | |
| ... | ... | @@ -3003,7 +2970,9 @@ fn zirEnumDecl( |
| 3003 | 2970 | const extra = sema.code.extraData(Zir.Inst.EnumDecl, extended.operand); |
| 3004 | 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 | 2977 | const tag_type_ref = if (small.has_tag_type) blk: { |
| 3009 | 2978 | const tag_type_ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_index]); |
| ... | ... | @@ -3063,7 +3032,7 @@ fn zirEnumDecl( |
| 3063 | 3032 | .explicit, |
| 3064 | 3033 | .fields_len = fields_len, |
| 3065 | 3034 | .key = .{ .declared = .{ |
| 3066 | | .zir_index = try mod.intern_pool.trackZir(sema.gpa, block.getFileScope(mod), inst), |
| 3035 | .zir_index = tracked_inst, |
| 3067 | 3036 | .captures = captures, |
| 3068 | 3037 | } }, |
| 3069 | 3038 | }; |
| ... | ... | @@ -3083,7 +3052,6 @@ fn zirEnumDecl( |
| 3083 | 3052 | |
| 3084 | 3053 | const new_decl_index = try sema.createAnonymousDeclTypeNamed( |
| 3085 | 3054 | block, |
| 3086 | | extra.data.src_node, |
| 3087 | 3055 | Value.fromInterned(wip_ty.index), |
| 3088 | 3056 | small.name_strategy, |
| 3089 | 3057 | "enum", |
| ... | ... | @@ -3149,12 +3117,10 @@ fn zirEnumDecl( |
| 3149 | 3117 | .instructions = .{}, |
| 3150 | 3118 | .inlining = null, |
| 3151 | 3119 | .is_comptime = true, |
| 3120 | .src_base_inst = tracked_inst, |
| 3152 | 3121 | }; |
| 3153 | 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 | 3124 | if (body.len != 0) { |
| 3159 | 3125 | _ = try sema.analyzeInlineBody(&enum_block, body, inst); |
| 3160 | 3126 | } |
| ... | ... | @@ -3199,36 +3165,33 @@ fn zirEnumDecl( |
| 3199 | 3165 | |
| 3200 | 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 | 3173 | const tag_overflow = if (has_tag_value) overflow: { |
| 3203 | 3174 | const tag_val_ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_index]); |
| 3204 | 3175 | extra_index += 1; |
| 3205 | 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) { |
| 3207 | | error.NeededSourceLocation => { |
| 3208 | | const value_src = mod.fieldSrcLoc(new_decl_index, .{ |
| 3209 | | .index = field_i, |
| 3210 | | .range = .value, |
| 3211 | | }).lazy; |
| 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 | | }; |
| 3177 | last_tag_val = try sema.resolveConstDefinedValue(block, .{ |
| 3178 | .base_node_inst = tracked_inst, |
| 3179 | .offset = .{ .container_field_name = field_i }, |
| 3180 | }, tag_inst, .{ |
| 3181 | .needed_comptime_reason = "enum tag value must be comptime-known", |
| 3182 | }); |
| 3219 | 3183 | if (!(try sema.intFitsInType(last_tag_val.?, int_tag_ty, null))) break :overflow true; |
| 3220 | 3184 | last_tag_val = try mod.getCoerced(last_tag_val.?, int_tag_ty); |
| 3221 | 3185 | if (wip_ty.nextField(&mod.intern_pool, field_name, last_tag_val.?.toIntern())) |conflict| { |
| 3222 | 3186 | assert(conflict.kind == .value); // AstGen validated names are unique |
| 3223 | | const value_src = mod.fieldSrcLoc(new_decl_index, .{ |
| 3224 | | .index = field_i, |
| 3225 | | .range = .value, |
| 3226 | | }).lazy; |
| 3227 | | const other_field_src = mod.fieldSrcLoc(new_decl_index, .{ .index = conflict.prev_field_idx }).lazy; |
| 3187 | const other_field_src: LazySrcLoc = .{ |
| 3188 | .base_node_inst = tracked_inst, |
| 3189 | .offset = .{ .container_field_value = conflict.prev_field_idx }, |
| 3190 | }; |
| 3228 | 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 | 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 | 3195 | break :msg msg; |
| 3233 | 3196 | }; |
| 3234 | 3197 | return sema.failWithOwnedErrorMsg(block, msg); |
| ... | ... | @@ -3243,12 +3206,14 @@ fn zirEnumDecl( |
| 3243 | 3206 | if (overflow != null) break :overflow true; |
| 3244 | 3207 | if (wip_ty.nextField(&mod.intern_pool, field_name, last_tag_val.?.toIntern())) |conflict| { |
| 3245 | 3208 | assert(conflict.kind == .value); // AstGen validated names are unique |
| 3246 | | const field_src = mod.fieldSrcLoc(new_decl_index, .{ .index = field_i }).lazy; |
| 3247 | | const other_field_src = mod.fieldSrcLoc(new_decl_index, .{ .index = conflict.prev_field_idx }).lazy; |
| 3209 | const other_field_src: LazySrcLoc = .{ |
| 3210 | .base_node_inst = tracked_inst, |
| 3211 | .offset = .{ .container_field_value = conflict.prev_field_idx }, |
| 3212 | }; |
| 3248 | 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 | 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 | 3217 | break :msg msg; |
| 3253 | 3218 | }; |
| 3254 | 3219 | return sema.failWithOwnedErrorMsg(block, msg); |
| ... | ... | @@ -3263,11 +3228,7 @@ fn zirEnumDecl( |
| 3263 | 3228 | }; |
| 3264 | 3229 | |
| 3265 | 3230 | if (tag_overflow) { |
| 3266 | | const value_src = mod.fieldSrcLoc(new_decl_index, .{ |
| 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 '{}'", .{ |
| 3231 | const msg = try sema.errMsg(value_src, "enumeration value '{}' too large for type '{}'", .{ |
| 3271 | 3232 | last_tag_val.?.fmtValue(mod, sema), int_tag_ty.fmt(mod), |
| 3272 | 3233 | }); |
| 3273 | 3234 | return sema.failWithOwnedErrorMsg(block, msg); |
| ... | ... | @@ -3294,7 +3255,8 @@ fn zirUnionDecl( |
| 3294 | 3255 | const extra = sema.code.extraData(Zir.Inst.UnionDecl, extended.operand); |
| 3295 | 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 | 3261 | extra_index += @intFromBool(small.has_tag_type); |
| 3300 | 3262 | const captures_len = if (small.has_captures_len) blk: { |
| ... | ... | @@ -3342,7 +3304,7 @@ fn zirUnionDecl( |
| 3342 | 3304 | .field_types = &.{}, // set later |
| 3343 | 3305 | .field_aligns = &.{}, // set later |
| 3344 | 3306 | .key = .{ .declared = .{ |
| 3345 | | .zir_index = try ip.trackZir(gpa, block.getFileScope(mod), inst), |
| 3307 | .zir_index = tracked_inst, |
| 3346 | 3308 | .captures = captures, |
| 3347 | 3309 | } }, |
| 3348 | 3310 | }; |
| ... | ... | @@ -3357,7 +3319,6 @@ fn zirUnionDecl( |
| 3357 | 3319 | |
| 3358 | 3320 | const new_decl_index = try sema.createAnonymousDeclTypeNamed( |
| 3359 | 3321 | block, |
| 3360 | | extra.data.src_node, |
| 3361 | 3322 | Value.fromInterned(wip_ty.index), |
| 3362 | 3323 | small.name_strategy, |
| 3363 | 3324 | "union", |
| ... | ... | @@ -3409,7 +3370,8 @@ fn zirOpaqueDecl( |
| 3409 | 3370 | const extra = sema.code.extraData(Zir.Inst.OpaqueDecl, extended.operand); |
| 3410 | 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 | 3376 | const captures_len = if (small.has_captures_len) blk: { |
| 3415 | 3377 | const captures_len = sema.code.extra[extra_index]; |
| ... | ... | @@ -3429,7 +3391,7 @@ fn zirOpaqueDecl( |
| 3429 | 3391 | const opaque_init: InternPool.OpaqueTypeInit = .{ |
| 3430 | 3392 | .has_namespace = decls_len != 0, |
| 3431 | 3393 | .key = .{ .declared = .{ |
| 3432 | | .zir_index = try ip.trackZir(gpa, block.getFileScope(mod), inst), |
| 3394 | .zir_index = tracked_inst, |
| 3433 | 3395 | .captures = captures, |
| 3434 | 3396 | } }, |
| 3435 | 3397 | }; |
| ... | ... | @@ -3445,7 +3407,6 @@ fn zirOpaqueDecl( |
| 3445 | 3407 | |
| 3446 | 3408 | const new_decl_index = try sema.createAnonymousDeclTypeNamed( |
| 3447 | 3409 | block, |
| 3448 | | extra.data.src_node, |
| 3449 | 3410 | Value.fromInterned(wip_ty.index), |
| 3450 | 3411 | small.name_strategy, |
| 3451 | 3412 | "opaque", |
| ... | ... | @@ -3566,19 +3527,19 @@ fn ensureResultUsed( |
| 3566 | 3527 | .ErrorSet => return sema.fail(block, src, "error set is ignored", .{}), |
| 3567 | 3528 | .ErrorUnion => { |
| 3568 | 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 | 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 | 3533 | break :msg msg; |
| 3573 | 3534 | }; |
| 3574 | 3535 | return sema.failWithOwnedErrorMsg(block, msg); |
| 3575 | 3536 | }, |
| 3576 | 3537 | else => { |
| 3577 | 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 | 3540 | errdefer msg.destroy(sema.gpa); |
| 3580 | | try sema.errNote(block, src, msg, "all non-void values must be used", .{}); |
| 3581 | | try sema.errNote(block, src, msg, "to discard the value, assign it to '_'", .{}); |
| 3541 | try sema.errNote(src, msg, "all non-void values must be used", .{}); |
| 3542 | try sema.errNote(src, msg, "to discard the value, assign it to '_'", .{}); |
| 3582 | 3543 | break :msg msg; |
| 3583 | 3544 | }; |
| 3584 | 3545 | return sema.failWithOwnedErrorMsg(block, msg); |
| ... | ... | @@ -3599,9 +3560,9 @@ fn zirEnsureResultNonError(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com |
| 3599 | 3560 | .ErrorSet => return sema.fail(block, src, "error set is discarded", .{}), |
| 3600 | 3561 | .ErrorUnion => { |
| 3601 | 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 | 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 | 3566 | break :msg msg; |
| 3606 | 3567 | }; |
| 3607 | 3568 | return sema.failWithOwnedErrorMsg(block, msg); |
| ... | ... | @@ -3627,9 +3588,9 @@ fn zirEnsureErrUnionPayloadVoid(sema: *Sema, block: *Block, inst: Zir.Inst.Index |
| 3627 | 3588 | const payload_ty = err_union_ty.errorUnionPayload(mod).zigTypeTag(mod); |
| 3628 | 3589 | if (payload_ty != .Void and payload_ty != .NoReturn) { |
| 3629 | 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 | 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 | 3594 | break :msg msg; |
| 3634 | 3595 | }; |
| 3635 | 3596 | return sema.failWithOwnedErrorMsg(block, msg); |
| ... | ... | @@ -3683,8 +3644,8 @@ fn zirAllocExtended( |
| 3683 | 3644 | ) CompileError!Air.Inst.Ref { |
| 3684 | 3645 | const gpa = sema.gpa; |
| 3685 | 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 }; |
| 3687 | | const align_src: LazySrcLoc = .{ .node_offset_var_decl_align = extra.data.src_node }; |
| 3647 | const ty_src = block.src(.{ .node_offset_var_decl_ty = extra.data.src_node }); |
| 3648 | const align_src = block.src(.{ .node_offset_var_decl_align = extra.data.src_node }); |
| 3688 | 3649 | const small: Zir.Inst.AllocExtended.Small = @bitCast(extended.small); |
| 3689 | 3650 | |
| 3690 | 3651 | var extra_index: usize = extra.end; |
| ... | ... | @@ -3760,7 +3721,7 @@ fn zirAllocComptime(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr |
| 3760 | 3721 | defer tracy.end(); |
| 3761 | 3722 | |
| 3762 | 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 | 3725 | const var_ty = try sema.resolveType(block, ty_src, inst_data.operand); |
| 3765 | 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 | 3787 | if (try sema.typeRequiresComptime(elem_ty)) { |
| 3827 | 3788 | // The value was initialized through RLS, so we didn't detect the runtime condition earlier. |
| 3828 | 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 | 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 | 3956 | .ty = opt_ty.toIntern(), |
| 3996 | 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 | 3960 | break :ptr (try Value.fromInterned(decl_parent_ptr).ptrOptPayload(sema)).toIntern(); |
| 4000 | 3961 | }, |
| 4001 | 3962 | .eu_payload => ptr: { |
| ... | ... | @@ -4008,7 +3969,7 @@ fn resolveComptimeKnownAllocPtr(sema: *Sema, block: *Block, alloc: Air.Inst.Ref, |
| 4008 | 3969 | .ty = eu_ty.toIntern(), |
| 4009 | 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 | 3973 | break :ptr (try Value.fromInterned(decl_parent_ptr).ptrEuPayload(sema)).toIntern(); |
| 4013 | 3974 | }, |
| 4014 | 3975 | .field => |idx| ptr: { |
| ... | ... | @@ -4021,7 +3982,7 @@ fn resolveComptimeKnownAllocPtr(sema: *Sema, block: *Block, alloc: Air.Inst.Ref, |
| 4021 | 3982 | const payload_val = try sema.typeHasOnePossibleValue(payload_ty) orelse try zcu.undefValue(payload_ty); |
| 4022 | 3983 | const tag_val = try zcu.enumValueFieldIndex(Type.fromInterned(union_obj.enum_tag_ty), idx); |
| 4023 | 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 | 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 | 4004 | const air_ptr_inst = store_inst.data.bin_op.lhs.toIndex().?; |
| 4044 | 4005 | const store_val = (try sema.resolveValue(store_inst.data.bin_op.rhs)).?; |
| 4045 | 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 | 4009 | else => unreachable, |
| 4049 | 4010 | } |
| 4050 | 4011 | } |
| 4051 | 4012 | |
| 4052 | 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 | 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 | 4114 | defer tracy.end(); |
| 4154 | 4115 | |
| 4155 | 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 | 4118 | const var_ty = try sema.resolveType(block, ty_src, inst_data.operand); |
| 4158 | 4119 | if (block.is_comptime) { |
| 4159 | 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 | 4137 | defer tracy.end(); |
| 4177 | 4138 | |
| 4178 | 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 | 4141 | const var_ty = try sema.resolveType(block, ty_src, inst_data.operand); |
| 4181 | 4142 | if (block.is_comptime) { |
| 4182 | 4143 | return sema.analyzeComptimeAlloc(block, var_ty, .none); |
| ... | ... | @@ -4236,7 +4197,7 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com |
| 4236 | 4197 | const gpa = sema.gpa; |
| 4237 | 4198 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 4238 | 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 | 4201 | const ptr = try sema.resolveInst(inst_data.operand); |
| 4241 | 4202 | const ptr_inst = ptr.toIndex().?; |
| 4242 | 4203 | const target = mod.getTarget(); |
| ... | ... | @@ -4399,20 +4360,20 @@ fn zirForLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. |
| 4399 | 4360 | .Int, .ComptimeInt => true, |
| 4400 | 4361 | else => false, |
| 4401 | 4362 | }; |
| 4402 | | const arg_src: LazySrcLoc = .{ .for_input = .{ |
| 4363 | const arg_src = block.src(.{ .for_input = .{ |
| 4403 | 4364 | .for_node_offset = inst_data.src_node, |
| 4404 | 4365 | .input_index = i, |
| 4405 | | } }; |
| 4366 | } }); |
| 4406 | 4367 | const arg_len_uncoerced = if (is_int) object else l: { |
| 4407 | 4368 | if (!object_ty.isIndexable(mod)) { |
| 4408 | 4369 | // Instead of using checkIndexable we customize this error. |
| 4409 | 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 | 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 | 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 | 4379 | break :msg msg; |
| ... | ... | @@ -4432,16 +4393,16 @@ fn zirForLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. |
| 4432 | 4393 | if (len_val) |v| { |
| 4433 | 4394 | if (!(try sema.valuesEqual(arg_val, v, Type.usize))) { |
| 4434 | 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 | 4397 | errdefer msg.destroy(gpa); |
| 4437 | | const a_src: LazySrcLoc = .{ .for_input = .{ |
| 4398 | const a_src = block.src(.{ .for_input = .{ |
| 4438 | 4399 | .for_node_offset = inst_data.src_node, |
| 4439 | 4400 | .input_index = len_idx, |
| 4440 | | } }; |
| 4441 | | try sema.errNote(block, a_src, msg, "length {} here", .{ |
| 4401 | } }); |
| 4402 | try sema.errNote(a_src, msg, "length {} here", .{ |
| 4442 | 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 | 4406 | arg_val.fmtValue(sema.mod, sema), |
| 4446 | 4407 | }); |
| 4447 | 4408 | break :msg msg; |
| ... | ... | @@ -4461,7 +4422,7 @@ fn zirForLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. |
| 4461 | 4422 | |
| 4462 | 4423 | if (len == .none) { |
| 4463 | 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 | 4426 | errdefer msg.destroy(gpa); |
| 4466 | 4427 | for (args, 0..) |zir_arg, i_usize| { |
| 4467 | 4428 | const i: u32 = @intCast(i_usize); |
| ... | ... | @@ -4474,11 +4435,11 @@ fn zirForLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. |
| 4474 | 4435 | .Int, .ComptimeInt => continue, |
| 4475 | 4436 | else => {}, |
| 4476 | 4437 | } |
| 4477 | | const arg_src: LazySrcLoc = .{ .for_input = .{ |
| 4438 | const arg_src = block.src(.{ .for_input = .{ |
| 4478 | 4439 | .for_node_offset = inst_data.src_node, |
| 4479 | 4440 | .input_index = i, |
| 4480 | | } }; |
| 4481 | | try sema.errNote(block, arg_src, msg, "type '{}' has no upper bound", .{ |
| 4441 | } }); |
| 4442 | try sema.errNote(arg_src, msg, "type '{}' has no upper bound", .{ |
| 4482 | 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 | 4489 | const src = block.nodeOffset(pl_node.src_node); |
| 4529 | 4490 | const extra = sema.code.extraData(Zir.Inst.Bin, pl_node.payload_index).data; |
| 4530 | 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 | 4493 | error.GenericPoison => return uncoerced_val, |
| 4533 | 4494 | else => |e| return e, |
| 4534 | 4495 | }; |
| ... | ... | @@ -4590,9 +4551,9 @@ fn zirValidateRefTy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr |
| 4590 | 4551 | if (ty_operand.isGenericPoison()) return; |
| 4591 | 4552 | if (ty_operand.optEuBaseType(mod).zigTypeTag(mod) != .Pointer) { |
| 4592 | 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 | 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 | 4557 | break :msg msg; |
| 4597 | 4558 | }); |
| 4598 | 4559 | } |
| ... | ... | @@ -4607,7 +4568,7 @@ fn zirValidateArrayInitRefTy( |
| 4607 | 4568 | const pl_node = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 4608 | 4569 | const src = block.nodeOffset(pl_node.src_node); |
| 4609 | 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 | 4572 | error.GenericPoison => return .generic_poison_type, |
| 4612 | 4573 | else => |e| return e, |
| 4613 | 4574 | }; |
| ... | ... | @@ -4648,7 +4609,7 @@ fn zirValidateArrayInitTy( |
| 4648 | 4609 | const mod = sema.mod; |
| 4649 | 4610 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 4650 | 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 | 4613 | const extra = sema.code.extraData(Zir.Inst.ArrayInit, inst_data.payload_index).data; |
| 4653 | 4614 | const ty = sema.resolveType(block, ty_src, extra.ty) catch |err| switch (err) { |
| 4654 | 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 | 4735 | if (instrs.len != 1) { |
| 4775 | 4736 | const msg = msg: { |
| 4776 | 4737 | const msg = try sema.errMsg( |
| 4777 | | block, |
| 4778 | 4738 | init_src, |
| 4779 | 4739 | "cannot initialize multiple union fields at once; unions can only have one active field", |
| 4780 | 4740 | .{}, |
| ... | ... | @@ -4783,8 +4743,8 @@ fn validateUnionInit( |
| 4783 | 4743 | |
| 4784 | 4744 | for (instrs[1..]) |inst| { |
| 4785 | 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 }; |
| 4787 | | try sema.errNote(block, inst_src, msg, "additional initializer here", .{}); |
| 4746 | const inst_src = block.src(.{ .node_offset_initializer = inst_data.src_node }); |
| 4747 | try sema.errNote(inst_src, msg, "additional initializer here", .{}); |
| 4788 | 4748 | } |
| 4789 | 4749 | try sema.addDeclaredHereNote(msg, union_ty); |
| 4790 | 4750 | break :msg msg; |
| ... | ... | @@ -4801,7 +4761,7 @@ fn validateUnionInit( |
| 4801 | 4761 | |
| 4802 | 4762 | const field_ptr = instrs[0]; |
| 4803 | 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 | 4765 | const field_ptr_extra = sema.code.extraData(Zir.Inst.Field, field_ptr_data.payload_index).data; |
| 4806 | 4766 | const field_name = try mod.intern_pool.getOrPutString( |
| 4807 | 4767 | gpa, |
| ... | ... | @@ -4918,7 +4878,7 @@ fn validateUnionInit( |
| 4918 | 4878 | |
| 4919 | 4879 | const new_tag = Air.internedToRef(tag_val.toIntern()); |
| 4920 | 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 | 4884 | fn validateStructInit( |
| ... | ... | @@ -4944,7 +4904,7 @@ fn validateStructInit( |
| 4944 | 4904 | |
| 4945 | 4905 | for (instrs, field_indices) |field_ptr, *field_index| { |
| 4946 | 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 | 4908 | const field_ptr_extra = sema.code.extraData(Zir.Inst.Field, field_ptr_data.payload_index).data; |
| 4949 | 4909 | struct_ptr_zir_ref = field_ptr_extra.lhs; |
| 4950 | 4910 | const field_name = try ip.getOrPutString( |
| ... | ... | @@ -4981,18 +4941,18 @@ fn validateStructInit( |
| 4981 | 4941 | const field_name = struct_ty.structFieldName(i, mod).unwrap() orelse { |
| 4982 | 4942 | const template = "missing tuple field with index {d}"; |
| 4983 | 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 | 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 | 4948 | continue; |
| 4989 | 4949 | }; |
| 4990 | 4950 | const template = "missing struct field: {}"; |
| 4991 | 4951 | const args = .{field_name.fmt(ip)}; |
| 4992 | 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 | 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 | 4957 | continue; |
| 4998 | 4958 | } |
| ... | ... | @@ -5007,16 +4967,7 @@ fn validateStructInit( |
| 5007 | 4967 | } |
| 5008 | 4968 | |
| 5009 | 4969 | if (root_msg) |msg| { |
| 5010 | | if (mod.typeToStruct(struct_ty)) |struct_type| { |
| 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 | | } |
| 4970 | try sema.addDeclaredHereNote(msg, struct_ty); |
| 5020 | 4971 | root_msg = null; |
| 5021 | 4972 | return sema.failWithOwnedErrorMsg(block, msg); |
| 5022 | 4973 | } |
| ... | ... | @@ -5118,18 +5069,18 @@ fn validateStructInit( |
| 5118 | 5069 | const field_name = struct_ty.structFieldName(i, mod).unwrap() orelse { |
| 5119 | 5070 | const template = "missing tuple field with index {d}"; |
| 5120 | 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 | 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 | 5076 | continue; |
| 5126 | 5077 | }; |
| 5127 | 5078 | const template = "missing struct field: {}"; |
| 5128 | 5079 | const args = .{field_name.fmt(ip)}; |
| 5129 | 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 | 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 | 5085 | continue; |
| 5135 | 5086 | } |
| ... | ... | @@ -5137,21 +5088,12 @@ fn validateStructInit( |
| 5137 | 5088 | } |
| 5138 | 5089 | |
| 5139 | 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", .{}); |
| 5141 | | try sema.errNote(block, init_src, root_msg.?, "comptime var pointers are not available at runtime", .{}); |
| 5091 | root_msg = try sema.errMsg(init_src, "runtime value contains reference to comptime var", .{}); |
| 5092 | try sema.errNote(init_src, root_msg.?, "comptime var pointers are not available at runtime", .{}); |
| 5142 | 5093 | } |
| 5143 | 5094 | |
| 5144 | 5095 | if (root_msg) |msg| { |
| 5145 | | if (mod.typeToStruct(struct_ty)) |struct_type| { |
| 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 | | } |
| 5096 | try sema.addDeclaredHereNote(msg, struct_ty); |
| 5155 | 5097 | root_msg = null; |
| 5156 | 5098 | return sema.failWithOwnedErrorMsg(block, msg); |
| 5157 | 5099 | } |
| ... | ... | @@ -5253,9 +5195,9 @@ fn zirValidatePtrArrayInit( |
| 5253 | 5195 | if (default_val == .unreachable_value) { |
| 5254 | 5196 | const template = "missing tuple field with index {d}"; |
| 5255 | 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 | 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 | 5202 | continue; |
| 5261 | 5203 | } |
| ... | ... | @@ -5455,15 +5397,13 @@ fn zirValidateDeref(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr |
| 5455 | 5397 | } else if (try sema.typeRequiresComptime(elem_ty)) { |
| 5456 | 5398 | const msg = msg: { |
| 5457 | 5399 | const msg = try sema.errMsg( |
| 5458 | | block, |
| 5459 | 5400 | src, |
| 5460 | 5401 | "values of type '{}' must be comptime-known, but operand value is runtime-known", |
| 5461 | 5402 | .{elem_ty.fmt(mod)}, |
| 5462 | 5403 | ); |
| 5463 | 5404 | errdefer msg.destroy(sema.gpa); |
| 5464 | 5405 | |
| 5465 | | const src_decl = mod.declPtr(block.src_decl); |
| 5466 | | try sema.explainWhyTypeIsComptime(msg, src_decl.toSrcLoc(src, mod), elem_ty); |
| 5406 | try sema.explainWhyTypeIsComptime(msg, src, elem_ty); |
| 5467 | 5407 | break :msg msg; |
| 5468 | 5408 | }; |
| 5469 | 5409 | return sema.failWithOwnedErrorMsg(block, msg); |
| ... | ... | @@ -5475,7 +5415,7 @@ fn zirValidateDestructure(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp |
| 5475 | 5415 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 5476 | 5416 | const extra = sema.code.extraData(Zir.Inst.ValidateDestructure, inst_data.payload_index).data; |
| 5477 | 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 | 5419 | const operand = try sema.resolveInst(extra.operand); |
| 5480 | 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 | 5427 | |
| 5488 | 5428 | if (!can_destructure) { |
| 5489 | 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 | 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 | 5433 | break :msg msg; |
| 5494 | 5434 | }); |
| 5495 | 5435 | } |
| 5496 | 5436 | |
| 5497 | 5437 | if (operand_ty.arrayLen(mod) != extra.expect_len) { |
| 5498 | 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 | 5440 | extra.expect_len, |
| 5501 | 5441 | operand_ty.arrayLen(mod), |
| 5502 | 5442 | }); |
| 5503 | 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 | 5445 | break :msg msg; |
| 5506 | 5446 | }); |
| 5507 | 5447 | } |
| ... | ... | @@ -5536,24 +5476,24 @@ fn failWithBadMemberAccess( |
| 5536 | 5476 | fn failWithBadStructFieldAccess( |
| 5537 | 5477 | sema: *Sema, |
| 5538 | 5478 | block: *Block, |
| 5479 | struct_ty: Type, |
| 5539 | 5480 | struct_type: InternPool.LoadedStructType, |
| 5540 | 5481 | field_src: LazySrcLoc, |
| 5541 | 5482 | field_name: InternPool.NullTerminatedString, |
| 5542 | 5483 | ) CompileError { |
| 5543 | | const mod = sema.mod; |
| 5484 | const zcu = sema.mod; |
| 5544 | 5485 | const gpa = sema.gpa; |
| 5545 | | const decl = mod.declPtr(struct_type.decl.unwrap().?); |
| 5546 | | const fqn = try decl.fullyQualifiedName(mod); |
| 5486 | const decl = zcu.declPtr(struct_type.decl.unwrap().?); |
| 5487 | const fqn = try decl.fullyQualifiedName(zcu); |
| 5547 | 5488 | |
| 5548 | 5489 | const msg = msg: { |
| 5549 | 5490 | const msg = try sema.errMsg( |
| 5550 | | block, |
| 5551 | 5491 | field_src, |
| 5552 | 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 | 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 | 5497 | break :msg msg; |
| 5558 | 5498 | }; |
| 5559 | 5499 | return sema.failWithOwnedErrorMsg(block, msg); |
| ... | ... | @@ -5562,25 +5502,25 @@ fn failWithBadStructFieldAccess( |
| 5562 | 5502 | fn failWithBadUnionFieldAccess( |
| 5563 | 5503 | sema: *Sema, |
| 5564 | 5504 | block: *Block, |
| 5505 | union_ty: Type, |
| 5565 | 5506 | union_obj: InternPool.LoadedUnionType, |
| 5566 | 5507 | field_src: LazySrcLoc, |
| 5567 | 5508 | field_name: InternPool.NullTerminatedString, |
| 5568 | 5509 | ) CompileError { |
| 5569 | | const mod = sema.mod; |
| 5510 | const zcu = sema.mod; |
| 5570 | 5511 | const gpa = sema.gpa; |
| 5571 | 5512 | |
| 5572 | | const decl = mod.declPtr(union_obj.decl); |
| 5573 | | const fqn = try decl.fullyQualifiedName(mod); |
| 5513 | const decl = zcu.declPtr(union_obj.decl); |
| 5514 | const fqn = try decl.fullyQualifiedName(zcu); |
| 5574 | 5515 | |
| 5575 | 5516 | const msg = msg: { |
| 5576 | 5517 | const msg = try sema.errMsg( |
| 5577 | | block, |
| 5578 | 5518 | field_src, |
| 5579 | 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 | 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 | 5524 | break :msg msg; |
| 5585 | 5525 | }; |
| 5586 | 5526 | return sema.failWithOwnedErrorMsg(block, msg); |
| ... | ... | @@ -5588,16 +5528,15 @@ fn failWithBadUnionFieldAccess( |
| 5588 | 5528 | |
| 5589 | 5529 | fn addDeclaredHereNote(sema: *Sema, parent: *Module.ErrorMsg, decl_ty: Type) !void { |
| 5590 | 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 | 5532 | const category = switch (decl_ty.zigTypeTag(mod)) { |
| 5593 | 5533 | .Union => "union", |
| 5594 | 5534 | .Struct => "struct", |
| 5595 | 5535 | .Enum => "enum", |
| 5596 | 5536 | .Opaque => "opaque", |
| 5597 | | .ErrorSet => "error set", |
| 5598 | 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 | 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 | 5661 | else => {}, |
| 5723 | 5662 | }; |
| 5724 | 5663 | |
| 5725 | | const ptr_src: LazySrcLoc = .{ .node_offset_store_ptr = inst_data.src_node }; |
| 5726 | | const operand_src: LazySrcLoc = .{ .node_offset_store_operand = inst_data.src_node }; |
| 5664 | const ptr_src = block.src(.{ .node_offset_store_ptr = inst_data.src_node }); |
| 5665 | const operand_src = block.src(.{ .node_offset_store_operand = inst_data.src_node }); |
| 5727 | 5666 | const air_tag: Air.Inst.Tag = if (is_ret) |
| 5728 | 5667 | .ret_ptr |
| 5729 | 5668 | else if (block.wantSafety()) |
| ... | ... | @@ -5837,7 +5776,7 @@ fn zirCompileError(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro |
| 5837 | 5776 | |
| 5838 | 5777 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 5839 | 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 | 5780 | const msg = try sema.resolveConstString(block, operand_src, inst_data.operand, .{ |
| 5842 | 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 | 5785 | |
| 5847 | 5786 | fn zirCompileLog( |
| 5848 | 5787 | sema: *Sema, |
| 5788 | block: *Block, |
| 5849 | 5789 | extended: Zir.Inst.Extended.InstData, |
| 5850 | 5790 | ) CompileError!Air.Inst.Ref { |
| 5851 | 5791 | const mod = sema.mod; |
| ... | ... | @@ -5878,9 +5818,10 @@ fn zirCompileLog( |
| 5878 | 5818 | else |
| 5879 | 5819 | sema.owner_decl_index; |
| 5880 | 5820 | const gop = try mod.compile_log_decls.getOrPut(sema.gpa, decl_index); |
| 5881 | | if (!gop.found_existing) { |
| 5882 | | gop.value_ptr.* = src_node; |
| 5883 | | } |
| 5821 | if (!gop.found_existing) gop.value_ptr.* = .{ |
| 5822 | .base_node_inst = block.src_base_inst, |
| 5823 | .node_offset = src_node, |
| 5824 | }; |
| 5884 | 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 | 5832 | |
| 5892 | 5833 | // `panicWithMsg` would perform this coercion for us, but we can get a better |
| 5893 | 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 | 5837 | if (block.is_comptime) { |
| 5897 | 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 | 5842 | |
| 5902 | 5843 | fn zirTrap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void { |
| 5903 | 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 | 5846 | if (block.is_comptime) |
| 5906 | 5847 | return sema.fail(block, src, "encountered @trap at comptime", .{}); |
| 5907 | 5848 | _ = try block.addNoOp(.trap); |
| ... | ... | @@ -5948,7 +5889,7 @@ fn zirLoop(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError |
| 5948 | 5889 | var child_block = parent_block.makeSubBlock(); |
| 5949 | 5890 | child_block.label = &label; |
| 5950 | 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 | 5893 | child_block.runtime_index.increment(); |
| 5953 | 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 | 5938 | var c_import_buf = std.ArrayList(u8).init(gpa); |
| 5998 | 5939 | defer c_import_buf.deinit(); |
| 5999 | 5940 | |
| 6000 | | var comptime_reason: Block.ComptimeReason = .{ .c_import = .{ |
| 6001 | | .block = parent_block, |
| 6002 | | .src = src, |
| 6003 | | } }; |
| 5941 | const comptime_reason: Block.ComptimeReason = .{ .c_import = .{ .src = src } }; |
| 6004 | 5942 | var child_block: Block = .{ |
| 6005 | 5943 | .parent = parent_block, |
| 6006 | 5944 | .sema = sema, |
| ... | ... | @@ -6014,6 +5952,7 @@ fn zirCImport(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileEr |
| 6014 | 5952 | .runtime_cond = parent_block.runtime_cond, |
| 6015 | 5953 | .runtime_loop = parent_block.runtime_loop, |
| 6016 | 5954 | .runtime_index = parent_block.runtime_index, |
| 5955 | .src_base_inst = parent_block.src_base_inst, |
| 6017 | 5956 | }; |
| 6018 | 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 | 5964 | |
| 6026 | 5965 | if (c_import_res.errors.errorMessageCount() != 0) { |
| 6027 | 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 | 5968 | errdefer msg.destroy(gpa); |
| 6030 | 5969 | |
| 6031 | 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 | 5973 | const gop = try mod.cimport_errors.getOrPut(gpa, sema.owner_decl_index); |
| 6035 | 5974 | if (!gop.found_existing) { |
| ... | ... | @@ -6139,6 +6078,7 @@ fn zirBlock(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index, force_compt |
| 6139 | 6078 | .runtime_loop = parent_block.runtime_loop, |
| 6140 | 6079 | .runtime_index = parent_block.runtime_index, |
| 6141 | 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 | 6084 | defer child_block.instructions.deinit(gpa); |
| ... | ... | @@ -6333,14 +6273,13 @@ fn resolveAnalyzedBlock( |
| 6333 | 6273 | const type_src = src; // TODO: better source location |
| 6334 | 6274 | if (try sema.typeRequiresComptime(resolved_ty)) { |
| 6335 | 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 | 6277 | errdefer msg.destroy(sema.gpa); |
| 6338 | 6278 | |
| 6339 | 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); |
| 6343 | | try sema.explainWhyTypeIsComptime(msg, child_src_decl.toSrcLoc(type_src, mod), resolved_ty); |
| 6282 | try sema.explainWhyTypeIsComptime(msg, type_src, resolved_ty); |
| 6344 | 6283 | |
| 6345 | 6284 | break :msg msg; |
| 6346 | 6285 | }; |
| ... | ... | @@ -6433,8 +6372,8 @@ fn zirExport(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void |
| 6433 | 6372 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 6434 | 6373 | const extra = sema.code.extraData(Zir.Inst.Export, inst_data.payload_index).data; |
| 6435 | 6374 | const src = block.nodeOffset(inst_data.src_node); |
| 6436 | | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 6437 | | const options_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; |
| 6375 | const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0); |
| 6376 | const options_src = block.builtinCallArgSrc(inst_data.src_node, 1); |
| 6438 | 6377 | const decl_name = try mod.intern_pool.getOrPutString( |
| 6439 | 6378 | mod.gpa, |
| 6440 | 6379 | sema.code.nullTerminatedString(extra.decl_name), |
| ... | ... | @@ -6448,13 +6387,7 @@ fn zirExport(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void |
| 6448 | 6387 | break :index_blk maybe_index orelse |
| 6449 | 6388 | return sema.failWithBadMemberAccess(block, container_ty, operand_src, decl_name); |
| 6450 | 6389 | } else try sema.lookupIdentifier(block, operand_src, decl_name); |
| 6451 | | const options = sema.resolveExportOptions(block, .unneeded, extra.options) catch |err| switch (err) { |
| 6452 | | error.NeededSourceLocation => { |
| 6453 | | _ = try sema.resolveExportOptions(block, options_src, extra.options); |
| 6454 | | unreachable; |
| 6455 | | }, |
| 6456 | | else => |e| return e, |
| 6457 | | }; |
| 6390 | const options = try sema.resolveExportOptions(block, options_src, extra.options); |
| 6458 | 6391 | { |
| 6459 | 6392 | try sema.ensureDeclAnalyzed(decl_index); |
| 6460 | 6393 | const exported_decl = mod.declPtr(decl_index); |
| ... | ... | @@ -6473,8 +6406,8 @@ fn zirExportValue(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 6473 | 6406 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 6474 | 6407 | const extra = sema.code.extraData(Zir.Inst.ExportValue, inst_data.payload_index).data; |
| 6475 | 6408 | const src = block.nodeOffset(inst_data.src_node); |
| 6476 | | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 6477 | | const options_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; |
| 6409 | const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0); |
| 6410 | const options_src = block.builtinCallArgSrc(inst_data.src_node, 1); |
| 6478 | 6411 | const operand = try sema.resolveInstConst(block, operand_src, extra.operand, .{ |
| 6479 | 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 | 6423 | .opts = options, |
| 6491 | 6424 | .src = src, |
| 6492 | 6425 | .owner_decl = sema.owner_decl_index, |
| 6493 | | .src_decl = block.src_decl, |
| 6494 | 6426 | .exported = .{ .value = operand.toIntern() }, |
| 6495 | 6427 | .status = .in_progress, |
| 6496 | 6428 | }); |
| ... | ... | @@ -6515,11 +6447,10 @@ pub fn analyzeExport( |
| 6515 | 6447 | |
| 6516 | 6448 | if (!try sema.validateExternType(export_ty, .other)) { |
| 6517 | 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 | 6451 | errdefer msg.destroy(gpa); |
| 6520 | 6452 | |
| 6521 | | const src_decl = mod.declPtr(block.src_decl); |
| 6522 | | try sema.explainWhyTypeIsNotExtern(msg, src_decl.toSrcLoc(src, mod), export_ty, .other); |
| 6453 | try sema.explainWhyTypeIsNotExtern(msg, src, export_ty, .other); |
| 6523 | 6454 | |
| 6524 | 6455 | try sema.addDeclaredHereNote(msg, export_ty); |
| 6525 | 6456 | break :msg msg; |
| ... | ... | @@ -6538,7 +6469,6 @@ pub fn analyzeExport( |
| 6538 | 6469 | .opts = options, |
| 6539 | 6470 | .src = src, |
| 6540 | 6471 | .owner_decl = sema.owner_decl_index, |
| 6541 | | .src_decl = block.src_decl, |
| 6542 | 6472 | .exported = .{ .decl_index = exported_decl_index }, |
| 6543 | 6473 | .status = .in_progress, |
| 6544 | 6474 | }); |
| ... | ... | @@ -6578,8 +6508,8 @@ fn addExport(mod: *Module, export_init: Module.Export) error{OutOfMemory}!void { |
| 6578 | 6508 | fn zirSetAlignStack(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!void { |
| 6579 | 6509 | const mod = sema.mod; |
| 6580 | 6510 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; |
| 6581 | | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node }; |
| 6582 | | const src = LazySrcLoc.nodeOffset(extra.node); |
| 6511 | const operand_src = block.builtinCallArgSrc(extra.node, 0); |
| 6512 | const src = block.nodeOffset(extra.node); |
| 6583 | 6513 | const alignment = try sema.resolveAlign(block, operand_src, extra.operand); |
| 6584 | 6514 | if (alignment.order(Alignment.fromNonzeroByteUnits(256)).compare(.gt)) { |
| 6585 | 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 | 6528 | |
| 6599 | 6529 | if (sema.prev_stack_alignment_src) |prev_src| { |
| 6600 | 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 | 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 | 6534 | break :msg msg; |
| 6605 | 6535 | }; |
| 6606 | 6536 | return sema.failWithOwnedErrorMsg(block, msg); |
| ... | ... | @@ -6621,7 +6551,7 @@ fn zirSetCold(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) |
| 6621 | 6551 | const mod = sema.mod; |
| 6622 | 6552 | const ip = &mod.intern_pool; |
| 6623 | 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 | 6555 | const is_cold = try sema.resolveConstBool(block, operand_src, extra.operand, .{ |
| 6626 | 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 | 6561 | |
| 6632 | 6562 | fn zirSetFloatMode(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!void { |
| 6633 | 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 | 6565 | block.float_mode = try sema.resolveBuiltinEnum(block, src, extra.operand, "FloatMode", .{ |
| 6636 | 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 | 6569 | |
| 6640 | 6570 | fn zirSetRuntimeSafety(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void { |
| 6641 | 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 | 6573 | block.want_safety = try sema.resolveConstBool(block, operand_src, inst_data.operand, .{ |
| 6644 | 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 | 6579 | if (block.is_comptime) return; |
| 6650 | 6580 | |
| 6651 | 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 | 6583 | const order = try sema.resolveAtomicOrder(block, order_src, extra.operand, .{ |
| 6654 | 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 | 6609 | if (label.zir_block == zir_block) { |
| 6680 | 6610 | const br_ref = try start_block.addBr(label.merges.block_inst, operand); |
| 6681 | 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 | 6613 | else |
| 6684 | 6614 | null; |
| 6685 | 6615 | try label.merges.src_locs.append(sema.gpa, src_loc); |
| ... | ... | @@ -6906,12 +6836,14 @@ fn lookupInNamespace( |
| 6906 | 6836 | }, |
| 6907 | 6837 | else => { |
| 6908 | 6838 | const msg = msg: { |
| 6909 | | const msg = try sema.errMsg(block, src, "ambiguous reference", .{}); |
| 6839 | const msg = try sema.errMsg(src, "ambiguous reference", .{}); |
| 6910 | 6840 | errdefer msg.destroy(gpa); |
| 6911 | 6841 | for (candidates.items) |candidate_index| { |
| 6912 | 6842 | const candidate = mod.declPtr(candidate_index); |
| 6913 | | const src_loc = candidate.srcLoc(mod); |
| 6914 | | try mod.errNoteNonLazy(src_loc, msg, "declared here", .{}); |
| 6843 | try sema.errNote(.{ |
| 6844 | .base_node_inst = candidate.zir_decl_index.unwrap().?, |
| 6845 | .offset = LazySrcLoc.Offset.nodeOffset(0), |
| 6846 | }, msg, "declared here", .{}); |
| 6915 | 6847 | } |
| 6916 | 6848 | break :msg msg; |
| 6917 | 6849 | }; |
| ... | ... | @@ -6953,16 +6885,16 @@ pub fn analyzeSaveErrRetIndex(sema: *Sema, block: *Block) SemaError!Air.Inst.Ref |
| 6953 | 6885 | if (!block.ownerModule().error_tracing) return .none; |
| 6954 | 6886 | |
| 6955 | 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 | 6889 | else => |e| return e, |
| 6958 | 6890 | }; |
| 6959 | 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 | 6893 | else => |e| return e, |
| 6962 | 6894 | }; |
| 6963 | 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) { |
| 6965 | | error.AnalysisFail, error.NeededSourceLocation => @panic("std.builtin.StackTrace is corrupt"), |
| 6896 | const field_index = sema.structFieldIndex(block, stack_trace_ty, field_name, LazySrcLoc.unneeded) catch |err| switch (err) { |
| 6897 | error.AnalysisFail => @panic("std.builtin.StackTrace is corrupt"), |
| 6966 | 6898 | error.GenericPoison, error.ComptimeReturn, error.ComptimeBreak => unreachable, |
| 6967 | 6899 | error.OutOfMemory => |e| return e, |
| 6968 | 6900 | }; |
| ... | ... | @@ -7070,7 +7002,7 @@ fn zirCall( |
| 7070 | 7002 | |
| 7071 | 7003 | const mod = sema.mod; |
| 7072 | 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 | 7006 | const call_src = block.nodeOffset(inst_data.src_node); |
| 7075 | 7007 | const ExtraType = switch (kind) { |
| 7076 | 7008 | .direct => Zir.Inst.Call, |
| ... | ... | @@ -7092,7 +7024,7 @@ fn zirCall( |
| 7092 | 7024 | sema.code.nullTerminatedString(extra.data.field_name_start), |
| 7093 | 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 | 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 | 7134 | opt_child.childType(mod).zigTypeTag(mod) == .Fn)) |
| 7203 | 7135 | { |
| 7204 | 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 | 7138 | callee_ty.fmt(mod), |
| 7207 | 7139 | }); |
| 7208 | 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 | 7142 | break :msg msg; |
| 7211 | 7143 | }; |
| 7212 | 7144 | return sema.failWithOwnedErrorMsg(block, msg); |
| ... | ... | @@ -7232,7 +7164,6 @@ fn checkCallArgumentCount( |
| 7232 | 7164 | const variadic_str = if (func_ty_info.is_var_args) "at least " else ""; |
| 7233 | 7165 | const msg = msg: { |
| 7234 | 7166 | const msg = try sema.errMsg( |
| 7235 | | block, |
| 7236 | 7167 | func_src, |
| 7237 | 7168 | "{s}expected {s}{d} argument(s), found {d}", |
| 7238 | 7169 | .{ |
| ... | ... | @@ -7244,7 +7175,12 @@ fn checkCallArgumentCount( |
| 7244 | 7175 | ); |
| 7245 | 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 | 7184 | break :msg msg; |
| 7249 | 7185 | }; |
| 7250 | 7186 | return sema.failWithOwnedErrorMsg(block, msg); |
| ... | ... | @@ -7352,18 +7288,16 @@ const CallArgsInfo = union(enum) { |
| 7352 | 7288 | fn argSrc(cai: CallArgsInfo, block: *Block, arg_index: usize) LazySrcLoc { |
| 7353 | 7289 | return switch (cai) { |
| 7354 | 7290 | .resolved => |resolved| resolved.src, |
| 7355 | | .call_builtin => |call_builtin| .{ .call_arg = .{ |
| 7356 | | .decl = block.src_decl, |
| 7291 | .call_builtin => |call_builtin| block.src(.{ .call_arg = .{ |
| 7357 | 7292 | .call_node_offset = call_builtin.call_node_offset, |
| 7358 | 7293 | .arg_index = @intCast(arg_index), |
| 7359 | | } }, |
| 7294 | } }), |
| 7360 | 7295 | .zir_call => |zir_call| if (arg_index == 0 and zir_call.bound_arg != .none) { |
| 7361 | 7296 | return zir_call.bound_arg_src; |
| 7362 | | } else .{ .call_arg = .{ |
| 7363 | | .decl = block.src_decl, |
| 7297 | } else block.src(.{ .call_arg = .{ |
| 7364 | 7298 | .call_node_offset = zir_call.call_node_offset, |
| 7365 | 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 | 7409 | other_error_return_trace_index_on_fn_entry: Air.Inst.Ref, |
| 7476 | 7410 | other_generic_owner: InternPool.Index, |
| 7477 | 7411 | other_generic_call_src: LazySrcLoc, |
| 7478 | | other_generic_call_decl: InternPool.OptionalDeclIndex, |
| 7479 | 7412 | |
| 7480 | 7413 | /// Sema should currently be set up for the caller (i.e. unchanged yet). This init will not |
| 7481 | 7414 | /// change that. The other parameters contain data for the callee Sema. The other modified |
| ... | ... | @@ -7497,8 +7430,7 @@ const InlineCallSema = struct { |
| 7497 | 7430 | .other_inst_map = .{}, |
| 7498 | 7431 | .other_error_return_trace_index_on_fn_entry = callee_error_return_trace_index_on_fn_entry, |
| 7499 | 7432 | .other_generic_owner = .none, |
| 7500 | | .other_generic_call_src = .unneeded, |
| 7501 | | .other_generic_call_decl = .none, |
| 7433 | .other_generic_call_src = LazySrcLoc.unneeded, |
| 7502 | 7434 | }; |
| 7503 | 7435 | } |
| 7504 | 7436 | |
| ... | ... | @@ -7545,7 +7477,6 @@ const InlineCallSema = struct { |
| 7545 | 7477 | std.mem.swap(InstMap, &ics.sema.inst_map, &ics.other_inst_map); |
| 7546 | 7478 | std.mem.swap(InternPool.Index, &ics.sema.generic_owner, &ics.other_generic_owner); |
| 7547 | 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 | 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 | 7481 | // zig fmt: on |
| 7551 | 7482 | } |
| ... | ... | @@ -7577,14 +7508,16 @@ fn analyzeCall( |
| 7577 | 7508 | const maybe_decl = try sema.funcDeclSrc(func); |
| 7578 | 7509 | const msg = msg: { |
| 7579 | 7510 | const msg = try sema.errMsg( |
| 7580 | | block, |
| 7581 | 7511 | func_src, |
| 7582 | 7512 | "unable to call function with naked calling convention", |
| 7583 | 7513 | .{}, |
| 7584 | 7514 | ); |
| 7585 | 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 | 7521 | break :msg msg; |
| 7589 | 7522 | }; |
| 7590 | 7523 | return sema.failWithOwnedErrorMsg(block, msg); |
| ... | ... | @@ -7623,7 +7556,6 @@ fn analyzeCall( |
| 7623 | 7556 | is_inline_call = ct; |
| 7624 | 7557 | if (ct) { |
| 7625 | 7558 | comptime_reason = &.{ .comptime_ret_ty = .{ |
| 7626 | | .block = block, |
| 7627 | 7559 | .func = func, |
| 7628 | 7560 | .func_src = func_src, |
| 7629 | 7561 | .return_ty = Type.fromInterned(func_ty_info.return_type), |
| ... | ... | @@ -7637,12 +7569,12 @@ fn analyzeCall( |
| 7637 | 7569 | |
| 7638 | 7570 | if (sema.func_is_naked and !is_inline_call and !is_comptime_call) { |
| 7639 | 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 | 7573 | errdefer msg.destroy(sema.gpa); |
| 7642 | 7574 | |
| 7643 | 7575 | switch (operation) { |
| 7644 | 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 | 7579 | break :msg msg; |
| 7648 | 7580 | }; |
| ... | ... | @@ -7669,7 +7601,6 @@ fn analyzeCall( |
| 7669 | 7601 | is_inline_call = true; |
| 7670 | 7602 | is_comptime_call = true; |
| 7671 | 7603 | comptime_reason = &.{ .comptime_ret_ty = .{ |
| 7672 | | .block = block, |
| 7673 | 7604 | .func = func, |
| 7674 | 7605 | .func_src = func_src, |
| 7675 | 7606 | .return_ty = Type.fromInterned(func_ty_info.return_type), |
| ... | ... | @@ -7776,6 +7707,7 @@ fn analyzeCall( |
| 7776 | 7707 | .runtime_cond = block.runtime_cond, |
| 7777 | 7708 | .runtime_loop = block.runtime_loop, |
| 7778 | 7709 | .runtime_index = block.runtime_index, |
| 7710 | .src_base_inst = fn_owner_decl.zir_decl_index.unwrap().?, |
| 7779 | 7711 | }; |
| 7780 | 7712 | |
| 7781 | 7713 | const merges = &child_block.inlining.?.merges; |
| ... | ... | @@ -7849,7 +7781,7 @@ fn analyzeCall( |
| 7849 | 7781 | var block_it = block; |
| 7850 | 7782 | while (block_it.inlining) |parent_inlining| { |
| 7851 | 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 | 7785 | return sema.failWithOwnedErrorMsg(null, err_msg); |
| 7854 | 7786 | } |
| 7855 | 7787 | block_it = parent_inlining.call_block; |
| ... | ... | @@ -7864,7 +7796,7 @@ fn analyzeCall( |
| 7864 | 7796 | try sema.resolveInlineBody(&child_block, fn_info.ret_ty_body, module_fn.zir_body_inst.resolve(ip)) |
| 7865 | 7797 | else |
| 7866 | 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 | 7800 | sema.fn_ret_ty = try sema.analyzeAsType(&child_block, ret_ty_src, ret_ty_inst); |
| 7869 | 7801 | if (module_fn.analysis(ip).inferred_error_set) { |
| 7870 | 7802 | // Create a fresh inferred error set type for inline/comptime calls. |
| ... | ... | @@ -7935,7 +7867,7 @@ fn analyzeCall( |
| 7935 | 7867 | }; |
| 7936 | 7868 | |
| 7937 | 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 | 7871 | const result_interned = result_val.toIntern(); |
| 7940 | 7872 | |
| 7941 | 7873 | // Transform ad-hoc inferred error set types into concrete error sets. |
| ... | ... | @@ -8276,7 +8208,6 @@ fn instantiateGenericCall( |
| 8276 | 8208 | .comptime_args = comptime_args, |
| 8277 | 8209 | .generic_owner = generic_owner, |
| 8278 | 8210 | .generic_call_src = call_src, |
| 8279 | | .generic_call_decl = block.src_decl.toOptional(), |
| 8280 | 8211 | .branch_quota = sema.branch_quota, |
| 8281 | 8212 | .branch_count = sema.branch_count, |
| 8282 | 8213 | .comptime_err_ret_trace = sema.comptime_err_ret_trace, |
| ... | ... | @@ -8291,6 +8222,7 @@ fn instantiateGenericCall( |
| 8291 | 8222 | .instructions = .{}, |
| 8292 | 8223 | .inlining = null, |
| 8293 | 8224 | .is_comptime = true, |
| 8225 | .src_base_inst = fn_owner_decl.zir_decl_index.unwrap().?, |
| 8294 | 8226 | }; |
| 8295 | 8227 | defer child_block.instructions.deinit(gpa); |
| 8296 | 8228 | |
| ... | ... | @@ -8321,18 +8253,15 @@ fn instantiateGenericCall( |
| 8321 | 8253 | const prev_no_partial_func_ty = child_sema.no_partial_func_ty; |
| 8322 | 8254 | const prev_generic_owner = child_sema.generic_owner; |
| 8323 | 8255 | const prev_generic_call_src = child_sema.generic_call_src; |
| 8324 | | const prev_generic_call_decl = child_sema.generic_call_decl; |
| 8325 | 8256 | child_block.params = .{}; |
| 8326 | 8257 | child_sema.no_partial_func_ty = true; |
| 8327 | 8258 | child_sema.generic_owner = .none; |
| 8328 | | child_sema.generic_call_src = .unneeded; |
| 8329 | | child_sema.generic_call_decl = .none; |
| 8259 | child_sema.generic_call_src = LazySrcLoc.unneeded; |
| 8330 | 8260 | defer { |
| 8331 | 8261 | child_block.params = prev_params; |
| 8332 | 8262 | child_sema.no_partial_func_ty = prev_no_partial_func_ty; |
| 8333 | 8263 | child_sema.generic_owner = prev_generic_owner; |
| 8334 | 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 | 8267 | const param_ty_inst = try child_sema.resolveInlineBody(&child_block, param_ty_body, param_inst); |
| ... | ... | @@ -8372,14 +8301,14 @@ fn instantiateGenericCall( |
| 8372 | 8301 | .param_anytype_comptime, |
| 8373 | 8302 | => return sema.failWithOwnedErrorMsg(block, msg: { |
| 8374 | 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 | 8305 | errdefer msg.destroy(sema.gpa); |
| 8377 | 8306 | const param_src = child_block.tokenOffset(switch (param_tag) { |
| 8378 | 8307 | .param_comptime => fn_zir.instructions.items(.data)[@intFromEnum(param_inst)].pl_tok.src_tok, |
| 8379 | 8308 | .param_anytype_comptime => fn_zir.instructions.items(.data)[@intFromEnum(param_inst)].str_tok.src_tok, |
| 8380 | 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 | 8312 | break :msg msg; |
| 8384 | 8313 | }), |
| 8385 | 8314 | |
| ... | ... | @@ -8387,16 +8316,15 @@ fn instantiateGenericCall( |
| 8387 | 8316 | .param_anytype, |
| 8388 | 8317 | => return sema.failWithOwnedErrorMsg(block, msg: { |
| 8389 | 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 | 8320 | errdefer msg.destroy(sema.gpa); |
| 8392 | 8321 | const param_src = child_block.tokenOffset(switch (param_tag) { |
| 8393 | 8322 | .param => fn_zir.instructions.items(.data)[@intFromEnum(param_inst)].pl_tok.src_tok, |
| 8394 | 8323 | .param_anytype => fn_zir.instructions.items(.data)[@intFromEnum(param_inst)].str_tok.src_tok, |
| 8395 | 8324 | else => unreachable, |
| 8396 | 8325 | }); |
| 8397 | | try child_sema.errNote(&child_block, param_src, msg, "declared here", .{}); |
| 8398 | | const src_decl = mod.declPtr(block.src_decl); |
| 8399 | | try sema.explainWhyTypeIsComptime(msg, src_decl.toSrcLoc(arg_src, mod), arg_ty); |
| 8326 | try child_sema.errNote(param_src, msg, "declared here", .{}); |
| 8327 | try sema.explainWhyTypeIsComptime(msg, arg_src, arg_ty); |
| 8400 | 8328 | break :msg msg; |
| 8401 | 8329 | }), |
| 8402 | 8330 | |
| ... | ... | @@ -8433,7 +8361,7 @@ fn instantiateGenericCall( |
| 8433 | 8361 | // We've already handled parameters, so don't resolve the whole body. Instead, just |
| 8434 | 8362 | // do the instructions after the params (i.e. the func itself). |
| 8435 | 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 | 8366 | const callee = mod.funcInfo(callee_index); |
| 8439 | 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 | 8448 | |
| 8521 | 8449 | const mod = sema.mod; |
| 8522 | 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 | 8452 | const child_type = try sema.resolveType(block, operand_src, inst_data.operand); |
| 8525 | 8453 | if (child_type.zigTypeTag(mod) == .Opaque) { |
| 8526 | 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 | 8463 | fn zirArrayInitElemType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 8536 | 8464 | const mod = sema.mod; |
| 8537 | 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 | 8467 | // Since this is a ZIR instruction that returns a type, encountering |
| 8540 | 8468 | // generic poison should not result in a failed compilation, but the |
| 8541 | 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 | 8486 | fn zirElemType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 8559 | 8487 | const mod = sema.mod; |
| 8560 | 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 | 8490 | error.GenericPoison => return .generic_poison_type, |
| 8563 | 8491 | else => |e| return e, |
| 8564 | 8492 | }; |
| ... | ... | @@ -8592,7 +8520,7 @@ fn zirIndexablePtrElemType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com |
| 8592 | 8520 | fn zirVectorElemType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 8593 | 8521 | const mod = sema.mod; |
| 8594 | 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 | 8524 | // Since this is a ZIR instruction that returns a type, encountering |
| 8597 | 8525 | // generic poison should not result in a failed compilation, but the |
| 8598 | 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 | 8537 | fn zirVectorType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 8610 | 8538 | const mod = sema.mod; |
| 8611 | 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 }; |
| 8613 | | const elem_type_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; |
| 8540 | const len_src = block.builtinCallArgSrc(inst_data.src_node, 0); |
| 8541 | const elem_type_src = block.builtinCallArgSrc(inst_data.src_node, 1); |
| 8614 | 8542 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 8615 | 8543 | const len: u32 = @intCast(try sema.resolveInt(block, len_src, extra.lhs, Type.u32, .{ |
| 8616 | 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 | 8558 | |
| 8631 | 8559 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 8632 | 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 }; |
| 8634 | | const elem_src: LazySrcLoc = .{ .node_offset_array_type_elem = inst_data.src_node }; |
| 8561 | const len_src = block.src(.{ .node_offset_array_type_len = inst_data.src_node }); |
| 8562 | const elem_src = block.src(.{ .node_offset_array_type_elem = inst_data.src_node }); |
| 8635 | 8563 | const len = try sema.resolveInt(block, len_src, extra.lhs, Type.usize, .{ |
| 8636 | 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 | 8579 | |
| 8652 | 8580 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 8653 | 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 }; |
| 8655 | | const sentinel_src: LazySrcLoc = .{ .node_offset_array_type_sentinel = inst_data.src_node }; |
| 8656 | | const elem_src: LazySrcLoc = .{ .node_offset_array_type_elem = inst_data.src_node }; |
| 8582 | const len_src = block.src(.{ .node_offset_array_type_len = inst_data.src_node }); |
| 8583 | const sentinel_src = block.src(.{ .node_offset_array_type_sentinel = inst_data.src_node }); |
| 8584 | const elem_src = block.src(.{ .node_offset_array_type_elem = inst_data.src_node }); |
| 8657 | 8585 | const len = try sema.resolveInt(block, len_src, extra.len, Type.usize, .{ |
| 8658 | 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 | 8619 | return sema.failWithUseOfAsync(block, block.nodeOffset(inst_data.src_node)); |
| 8692 | 8620 | } |
| 8693 | 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 | 8623 | const return_type = try sema.resolveType(block, operand_src, inst_data.operand); |
| 8696 | 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 | 8633 | const mod = sema.mod; |
| 8706 | 8634 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 8707 | 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 }; |
| 8709 | | const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node }; |
| 8636 | const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node }); |
| 8637 | const rhs_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node }); |
| 8710 | 8638 | const error_set = try sema.resolveType(block, lhs_src, extra.lhs); |
| 8711 | 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 | 8686 | const mod = sema.mod; |
| 8759 | 8687 | const ip = &mod.intern_pool; |
| 8760 | 8688 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; |
| 8761 | | const src = LazySrcLoc.nodeOffset(extra.node); |
| 8762 | | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node }; |
| 8689 | const src = block.nodeOffset(extra.node); |
| 8690 | const operand_src = block.builtinCallArgSrc(extra.node, 0); |
| 8763 | 8691 | const uncasted_operand = try sema.resolveInst(extra.operand); |
| 8764 | 8692 | const operand = try sema.coerce(block, Type.anyerror, uncasted_operand, operand_src); |
| 8765 | 8693 | const err_int_ty = try mod.errorIntType(); |
| ... | ... | @@ -8801,8 +8729,8 @@ fn zirErrorFromInt(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstD |
| 8801 | 8729 | |
| 8802 | 8730 | const mod = sema.mod; |
| 8803 | 8731 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; |
| 8804 | | const src = LazySrcLoc.nodeOffset(extra.node); |
| 8805 | | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node }; |
| 8732 | const src = block.nodeOffset(extra.node); |
| 8733 | const operand_src = block.builtinCallArgSrc(extra.node, 0); |
| 8806 | 8734 | const uncasted_operand = try sema.resolveInst(extra.operand); |
| 8807 | 8735 | const err_int_ty = try mod.errorIntType(); |
| 8808 | 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 | 8769 | const ip = &mod.intern_pool; |
| 8842 | 8770 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 8843 | 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 }; |
| 8845 | | const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node }; |
| 8846 | | const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node }; |
| 8772 | const src = block.src(.{ .node_offset_bin_op = inst_data.src_node }); |
| 8773 | const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node }); |
| 8774 | const rhs_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node }); |
| 8847 | 8775 | const lhs = try sema.resolveInst(extra.lhs); |
| 8848 | 8776 | const rhs = try sema.resolveInst(extra.rhs); |
| 8849 | 8777 | if (sema.typeOf(lhs).zigTypeTag(mod) == .Bool and sema.typeOf(rhs).zigTypeTag(mod) == .Bool) { |
| 8850 | 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 | 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 | 8782 | break :msg msg; |
| 8855 | 8783 | }; |
| 8856 | 8784 | return sema.failWithOwnedErrorMsg(block, msg); |
| ... | ... | @@ -8905,7 +8833,7 @@ fn zirIntFromEnum(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 8905 | 8833 | const mod = sema.mod; |
| 8906 | 8834 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 8907 | 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 | 8837 | const operand = try sema.resolveInst(inst_data.operand); |
| 8910 | 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 | 8891 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 8964 | 8892 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 8965 | 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 | 8895 | const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu_opt, "@enumFromInt"); |
| 8968 | 8896 | const operand = try sema.resolveInst(extra.rhs); |
| 8969 | 8897 | |
| ... | ... | @@ -9379,7 +9307,7 @@ fn zirFunc( |
| 9379 | 9307 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 9380 | 9308 | const extra = sema.code.extraData(Zir.Inst.Func, inst_data.payload_index); |
| 9381 | 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 | 9312 | var extra_index = extra.end; |
| 9385 | 9313 | |
| ... | ... | @@ -9460,18 +9388,15 @@ fn resolveGenericBody( |
| 9460 | 9388 | const prev_no_partial_func_type = sema.no_partial_func_ty; |
| 9461 | 9389 | const prev_generic_owner = sema.generic_owner; |
| 9462 | 9390 | const prev_generic_call_src = sema.generic_call_src; |
| 9463 | | const prev_generic_call_decl = sema.generic_call_decl; |
| 9464 | 9391 | block.params = .{}; |
| 9465 | 9392 | sema.no_partial_func_ty = true; |
| 9466 | 9393 | sema.generic_owner = .none; |
| 9467 | | sema.generic_call_src = .unneeded; |
| 9468 | | sema.generic_call_decl = .none; |
| 9394 | sema.generic_call_src = LazySrcLoc.unneeded; |
| 9469 | 9395 | defer { |
| 9470 | 9396 | block.params = prev_params; |
| 9471 | 9397 | sema.no_partial_func_ty = prev_no_partial_func_type; |
| 9472 | 9398 | sema.generic_owner = prev_generic_owner; |
| 9473 | 9399 | sema.generic_call_src = prev_generic_call_src; |
| 9474 | | sema.generic_call_decl = prev_generic_call_decl; |
| 9475 | 9400 | } |
| 9476 | 9401 | |
| 9477 | 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 | 9506 | |
| 9582 | 9507 | if (!callConvSupportsVarArgs(cc)) { |
| 9583 | 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 | 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 | 9512 | break :msg msg; |
| 9588 | 9513 | }; |
| 9589 | 9514 | return sema.failWithOwnedErrorMsg(block, msg); |
| ... | ... | @@ -9623,9 +9548,9 @@ fn funcCommon( |
| 9623 | 9548 | const gpa = sema.gpa; |
| 9624 | 9549 | const target = mod.getTarget(); |
| 9625 | 9550 | const ip = &mod.intern_pool; |
| 9626 | | const ret_ty_src: LazySrcLoc = .{ .node_offset_fn_type_ret_ty = src_node_offset }; |
| 9627 | | const cc_src: LazySrcLoc = .{ .node_offset_fn_type_cc = src_node_offset }; |
| 9628 | | const func_src = LazySrcLoc.nodeOffset(src_node_offset); |
| 9551 | const ret_ty_src = block.src(.{ .node_offset_fn_type_ret_ty = src_node_offset }); |
| 9552 | const cc_src = block.src(.{ .node_offset_fn_type_cc = src_node_offset }); |
| 9553 | const func_src = block.nodeOffset(src_node_offset); |
| 9629 | 9554 | |
| 9630 | 9555 | var is_generic = bare_return_type.isGenericPoison() or |
| 9631 | 9556 | alignment == null or |
| ... | ... | @@ -9654,11 +9579,10 @@ fn funcCommon( |
| 9654 | 9579 | const index = std.math.cast(u5, i) orelse break :blk false; |
| 9655 | 9580 | break :blk @as(u1, @truncate(noalias_bits >> index)) != 0; |
| 9656 | 9581 | }; |
| 9657 | | const param_src: LazySrcLoc = .{ .fn_proto_param = .{ |
| 9658 | | .decl = block.src_decl, |
| 9582 | const param_src = block.src(.{ .fn_proto_param = .{ |
| 9659 | 9583 | .fn_proto_node_offset = src_node_offset, |
| 9660 | 9584 | .param_index = @intCast(i), |
| 9661 | | } }; |
| 9585 | } }); |
| 9662 | 9586 | const requires_comptime = try sema.typeRequiresComptime(param_ty); |
| 9663 | 9587 | if (param_is_comptime or requires_comptime) { |
| 9664 | 9588 | comptime_bits |= @as(u32, 1) << @intCast(i); // TODO: handle cast error |
| ... | ... | @@ -9679,13 +9603,12 @@ fn funcCommon( |
| 9679 | 9603 | } |
| 9680 | 9604 | if (!this_generic and !target_util.fnCallConvAllowsZigTypes(target, cc_resolved) and !try sema.validateExternType(param_ty, .param_ty)) { |
| 9681 | 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 | 9607 | param_ty.fmt(mod), @tagName(cc_resolved), |
| 9684 | 9608 | }); |
| 9685 | 9609 | errdefer msg.destroy(sema.gpa); |
| 9686 | 9610 | |
| 9687 | | const src_decl = mod.declPtr(block.src_decl); |
| 9688 | | try sema.explainWhyTypeIsNotExtern(msg, src_decl.toSrcLoc(param_src, mod), param_ty, .param_ty); |
| 9611 | try sema.explainWhyTypeIsNotExtern(msg, param_src, param_ty, .param_ty); |
| 9689 | 9612 | |
| 9690 | 9613 | try sema.addDeclaredHereNote(msg, param_ty); |
| 9691 | 9614 | break :msg msg; |
| ... | ... | @@ -9694,13 +9617,12 @@ fn funcCommon( |
| 9694 | 9617 | } |
| 9695 | 9618 | if (is_source_decl and requires_comptime and !param_is_comptime and has_body and !block.is_comptime) { |
| 9696 | 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 | 9621 | param_ty.fmt(mod), |
| 9699 | 9622 | }); |
| 9700 | 9623 | errdefer msg.destroy(sema.gpa); |
| 9701 | 9624 | |
| 9702 | | const src_decl = mod.declPtr(block.src_decl); |
| 9703 | | try sema.explainWhyTypeIsComptime(msg, src_decl.toSrcLoc(param_src, mod), param_ty); |
| 9625 | try sema.explainWhyTypeIsComptime(msg, param_src, param_ty); |
| 9704 | 9626 | |
| 9705 | 9627 | try sema.addDeclaredHereNote(msg, param_ty); |
| 9706 | 9628 | break :msg msg; |
| ... | ... | @@ -9861,9 +9783,9 @@ fn funcCommon( |
| 9861 | 9783 | assert(section != .generic); |
| 9862 | 9784 | assert(address_space != null); |
| 9863 | 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 | 9787 | .node_offset_lib_name = src_node_offset, |
| 9866 | | }, lib_name); |
| 9788 | }), lib_name); |
| 9867 | 9789 | const func_index = try ip.getExternFunc(gpa, .{ |
| 9868 | 9790 | .ty = func_ty, |
| 9869 | 9791 | .decl = sema.owner_decl_index, |
| ... | ... | @@ -9975,13 +9897,12 @@ fn finishFunc( |
| 9975 | 9897 | !try sema.validateExternType(return_type, .ret_ty)) |
| 9976 | 9898 | { |
| 9977 | 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 | 9901 | return_type.fmt(mod), @tagName(cc_resolved), |
| 9980 | 9902 | }); |
| 9981 | 9903 | errdefer msg.destroy(gpa); |
| 9982 | 9904 | |
| 9983 | | const src_decl = mod.declPtr(block.src_decl); |
| 9984 | | try sema.explainWhyTypeIsNotExtern(msg, src_decl.toSrcLoc(ret_ty_src, mod), return_type, .ret_ty); |
| 9905 | try sema.explainWhyTypeIsNotExtern(msg, ret_ty_src, return_type, .ret_ty); |
| 9985 | 9906 | |
| 9986 | 9907 | try sema.addDeclaredHereNote(msg, return_type); |
| 9987 | 9908 | break :msg msg; |
| ... | ... | @@ -9997,12 +9918,11 @@ fn finishFunc( |
| 9997 | 9918 | } else break :comptime_check; |
| 9998 | 9919 | |
| 9999 | 9920 | const msg = try sema.errMsg( |
| 10000 | | block, |
| 10001 | 9921 | ret_ty_src, |
| 10002 | 9922 | "function with comptime-only return type '{}' requires all parameters to be comptime", |
| 10003 | 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 | 9927 | const tags = sema.code.instructions.items(.tag); |
| 10008 | 9928 | const data = sema.code.instructions.items(.data); |
| ... | ... | @@ -10020,9 +9940,9 @@ fn finishFunc( |
| 10020 | 9940 | }); |
| 10021 | 9941 | const name = sema.code.nullTerminatedString(name_nts); |
| 10022 | 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 | 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 | 10032 | const prev_no_partial_func_type = sema.no_partial_func_ty; |
| 10113 | 10033 | const prev_generic_owner = sema.generic_owner; |
| 10114 | 10034 | const prev_generic_call_src = sema.generic_call_src; |
| 10115 | | const prev_generic_call_decl = sema.generic_call_decl; |
| 10116 | 10035 | block.params = .{}; |
| 10117 | 10036 | sema.no_partial_func_ty = true; |
| 10118 | 10037 | sema.generic_owner = .none; |
| 10119 | | sema.generic_call_src = .unneeded; |
| 10120 | | sema.generic_call_decl = .none; |
| 10038 | sema.generic_call_src = LazySrcLoc.unneeded; |
| 10121 | 10039 | defer { |
| 10122 | 10040 | block.params = prev_params; |
| 10123 | 10041 | sema.no_partial_func_ty = prev_no_partial_func_type; |
| 10124 | 10042 | sema.generic_owner = prev_generic_owner; |
| 10125 | 10043 | sema.generic_call_src = prev_generic_call_src; |
| 10126 | | sema.generic_call_decl = prev_generic_call_decl; |
| 10127 | 10044 | } |
| 10128 | 10045 | |
| 10129 | 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 | 10182 | |
| 10266 | 10183 | const zcu = sema.mod; |
| 10267 | 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 | 10186 | const operand = try sema.resolveInst(inst_data.operand); |
| 10270 | 10187 | const operand_ty = sema.typeOf(operand); |
| 10271 | 10188 | const ptr_ty = operand_ty.scalarType(zcu); |
| ... | ... | @@ -10276,10 +10193,9 @@ fn zirIntFromPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! |
| 10276 | 10193 | const pointee_ty = ptr_ty.childType(zcu); |
| 10277 | 10194 | if (try sema.typeRequiresComptime(ptr_ty)) { |
| 10278 | 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 | 10197 | errdefer msg.destroy(sema.gpa); |
| 10281 | | const src_decl = zcu.declPtr(block.src_decl); |
| 10282 | | try sema.explainWhyTypeIsComptime(msg, src_decl.toSrcLoc(ptr_src, zcu), pointee_ty); |
| 10198 | try sema.explainWhyTypeIsComptime(msg, ptr_src, pointee_ty); |
| 10283 | 10199 | break :msg msg; |
| 10284 | 10200 | }; |
| 10285 | 10201 | return sema.failWithOwnedErrorMsg(block, msg); |
| ... | ... | @@ -10340,7 +10256,7 @@ fn zirFieldVal(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 10340 | 10256 | const mod = sema.mod; |
| 10341 | 10257 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 10342 | 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 | 10260 | const extra = sema.code.extraData(Zir.Inst.Field, inst_data.payload_index).data; |
| 10345 | 10261 | const field_name = try mod.intern_pool.getOrPutString( |
| 10346 | 10262 | sema.gpa, |
| ... | ... | @@ -10358,7 +10274,7 @@ fn zirFieldPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 10358 | 10274 | const mod = sema.mod; |
| 10359 | 10275 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 10360 | 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 | 10278 | const extra = sema.code.extraData(Zir.Inst.Field, inst_data.payload_index).data; |
| 10363 | 10279 | const field_name = try mod.intern_pool.getOrPutString( |
| 10364 | 10280 | sema.gpa, |
| ... | ... | @@ -10376,7 +10292,7 @@ fn zirStructInitFieldPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compi |
| 10376 | 10292 | const mod = sema.mod; |
| 10377 | 10293 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 10378 | 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 | 10296 | const extra = sema.code.extraData(Zir.Inst.Field, inst_data.payload_index).data; |
| 10381 | 10297 | const field_name = try mod.intern_pool.getOrPutString( |
| 10382 | 10298 | sema.gpa, |
| ... | ... | @@ -10401,7 +10317,7 @@ fn zirFieldValNamed(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr |
| 10401 | 10317 | |
| 10402 | 10318 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 10403 | 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 | 10321 | const extra = sema.code.extraData(Zir.Inst.FieldNamed, inst_data.payload_index).data; |
| 10406 | 10322 | const object = try sema.resolveInst(extra.lhs); |
| 10407 | 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 | 10332 | |
| 10417 | 10333 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 10418 | 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 | 10336 | const extra = sema.code.extraData(Zir.Inst.FieldNamed, inst_data.payload_index).data; |
| 10421 | 10337 | const object_ptr = try sema.resolveInst(extra.lhs); |
| 10422 | 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 | 10347 | |
| 10432 | 10348 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 10433 | 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 | 10351 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 10436 | 10352 | |
| 10437 | 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 | 10517 | const mod = sema.mod; |
| 10602 | 10518 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 10603 | 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 | 10521 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 10606 | 10522 | |
| 10607 | 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 | 10543 | |
| 10628 | 10544 | .Enum => { |
| 10629 | 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 | 10547 | errdefer msg.destroy(sema.gpa); |
| 10632 | 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 | 10550 | else => {}, |
| 10635 | 10551 | } |
| 10636 | 10552 | |
| ... | ... | @@ -10641,11 +10557,11 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 10641 | 10557 | |
| 10642 | 10558 | .Pointer => { |
| 10643 | 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 | 10561 | errdefer msg.destroy(sema.gpa); |
| 10646 | 10562 | switch (operand_ty.zigTypeTag(mod)) { |
| 10647 | | .Int, .ComptimeInt => try sema.errNote(block, 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)}), |
| 10563 | .Int, .ComptimeInt => try sema.errNote(src, msg, "use @ptrFromInt to cast from '{}'", .{operand_ty.fmt(mod)}), |
| 10564 | .Pointer => try sema.errNote(src, msg, "use @ptrCast to cast from '{}'", .{operand_ty.fmt(mod)}), |
| 10649 | 10565 | else => {}, |
| 10650 | 10566 | } |
| 10651 | 10567 | |
| ... | ... | @@ -10691,10 +10607,10 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 10691 | 10607 | |
| 10692 | 10608 | .Enum => { |
| 10693 | 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 | 10611 | errdefer msg.destroy(sema.gpa); |
| 10696 | 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 | 10614 | else => {}, |
| 10699 | 10615 | } |
| 10700 | 10616 | |
| ... | ... | @@ -10704,11 +10620,11 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 10704 | 10620 | }, |
| 10705 | 10621 | .Pointer => { |
| 10706 | 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 | 10624 | errdefer msg.destroy(sema.gpa); |
| 10709 | 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)}), |
| 10711 | | .Pointer => try sema.errNote(block, operand_src, msg, "use @ptrCast 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)}), |
| 10627 | .Pointer => try sema.errNote(operand_src, msg, "use @ptrCast to cast to '{}'", .{dest_ty.fmt(mod)}), |
| 10712 | 10628 | else => {}, |
| 10713 | 10629 | } |
| 10714 | 10630 | |
| ... | ... | @@ -10744,7 +10660,7 @@ fn zirFloatCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 10744 | 10660 | const mod = sema.mod; |
| 10745 | 10661 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 10746 | 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 | 10664 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 10749 | 10665 | |
| 10750 | 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 | 10751 | |
| 10836 | 10752 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 10837 | 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 | 10755 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 10840 | 10756 | const array = try sema.resolveInst(extra.lhs); |
| 10841 | 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 | 10767 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].elem_val_imm; |
| 10852 | 10768 | const array = try sema.resolveInst(inst_data.operand); |
| 10853 | 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 | 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 | 10782 | const elem_index = try sema.resolveInst(extra.rhs); |
| 10867 | 10783 | const indexable_ty = sema.typeOf(array_ptr); |
| 10868 | 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 | 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 | 10788 | indexable_ty.fmt(mod), |
| 10873 | 10789 | }); |
| 10874 | 10790 | errdefer msg.destroy(sema.gpa); |
| 10875 | 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 | 10794 | break :msg msg; |
| 10879 | 10795 | }; |
| ... | ... | @@ -10888,7 +10804,7 @@ fn zirElemPtrNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 10888 | 10804 | |
| 10889 | 10805 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 10890 | 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 | 10808 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 10893 | 10809 | const array_ptr = try sema.resolveInst(extra.lhs); |
| 10894 | 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 | 10841 | const extra = sema.code.extraData(Zir.Inst.SliceStart, inst_data.payload_index).data; |
| 10926 | 10842 | const array_ptr = try sema.resolveInst(extra.lhs); |
| 10927 | 10843 | const start = try sema.resolveInst(extra.start); |
| 10928 | | const ptr_src: LazySrcLoc = .{ .node_offset_slice_ptr = inst_data.src_node }; |
| 10929 | | const start_src: LazySrcLoc = .{ .node_offset_slice_start = inst_data.src_node }; |
| 10930 | | const end_src: LazySrcLoc = .{ .node_offset_slice_end = inst_data.src_node }; |
| 10844 | const ptr_src = block.src(.{ .node_offset_slice_ptr = inst_data.src_node }); |
| 10845 | const start_src = block.src(.{ .node_offset_slice_start = 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 | 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 | 10858 | const array_ptr = try sema.resolveInst(extra.lhs); |
| 10943 | 10859 | const start = try sema.resolveInst(extra.start); |
| 10944 | 10860 | const end = try sema.resolveInst(extra.end); |
| 10945 | | const ptr_src: LazySrcLoc = .{ .node_offset_slice_ptr = inst_data.src_node }; |
| 10946 | | const start_src: LazySrcLoc = .{ .node_offset_slice_start = inst_data.src_node }; |
| 10947 | | const end_src: LazySrcLoc = .{ .node_offset_slice_end = inst_data.src_node }; |
| 10861 | const ptr_src = block.src(.{ .node_offset_slice_ptr = inst_data.src_node }); |
| 10862 | const start_src = block.src(.{ .node_offset_slice_start = 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 | 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 | 10871 | |
| 10956 | 10872 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 10957 | 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 | 10875 | const extra = sema.code.extraData(Zir.Inst.SliceSentinel, inst_data.payload_index).data; |
| 10960 | 10876 | const array_ptr = try sema.resolveInst(extra.lhs); |
| 10961 | 10877 | const start = try sema.resolveInst(extra.start); |
| 10962 | 10878 | const end: Air.Inst.Ref = if (extra.end == .none) .none else try sema.resolveInst(extra.end); |
| 10963 | 10879 | const sentinel = try sema.resolveInst(extra.sentinel); |
| 10964 | | const ptr_src: LazySrcLoc = .{ .node_offset_slice_ptr = inst_data.src_node }; |
| 10965 | | const start_src: LazySrcLoc = .{ .node_offset_slice_start = inst_data.src_node }; |
| 10966 | | const end_src: LazySrcLoc = .{ .node_offset_slice_end = inst_data.src_node }; |
| 10880 | const ptr_src = block.src(.{ .node_offset_slice_ptr = inst_data.src_node }); |
| 10881 | const start_src = block.src(.{ .node_offset_slice_start = inst_data.src_node }); |
| 10882 | const end_src = block.src(.{ .node_offset_slice_end = inst_data.src_node }); |
| 10967 | 10883 | |
| 10968 | 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 | 10895 | const start = try sema.resolveInst(extra.start); |
| 10980 | 10896 | const len = try sema.resolveInst(extra.len); |
| 10981 | 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 }; |
| 10983 | | const start_src: LazySrcLoc = .{ .node_offset_slice_start = extra.start_src_node_offset }; |
| 10984 | | const end_src: LazySrcLoc = .{ .node_offset_slice_end = inst_data.src_node }; |
| 10898 | const ptr_src = block.src(.{ .node_offset_slice_ptr = inst_data.src_node }); |
| 10899 | const start_src = block.src(.{ .node_offset_slice_start = extra.start_src_node_offset }); |
| 10900 | const end_src = block.src(.{ .node_offset_slice_end = inst_data.src_node }); |
| 10985 | 10901 | const sentinel_src: LazySrcLoc = if (sentinel == .none) |
| 10986 | | .unneeded |
| 10902 | LazySrcLoc.unneeded |
| 10987 | 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 | 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 | 10935 | prong_type: enum { normal, special }, |
| 11020 | 10936 | prong_body: []const Zir.Inst.Index, |
| 11021 | 10937 | capture: Zir.Inst.SwitchBlock.ProngInfo.Capture, |
| 11022 | | /// Must use the `scalar_capture`, `special_capture`, or `multi_capture` union field. |
| 11023 | | raw_capture_src: Module.SwitchProngSrc, |
| 10938 | /// Must use the `switch_capture` field in `offset`. |
| 10939 | capture_src: LazySrcLoc, |
| 11024 | 10940 | /// The set of all values which can reach this prong. May be undefined |
| 11025 | 10941 | /// if the prong is special or contains ranges. |
| 11026 | 10942 | case_vals: []const Air.Inst.Ref, |
| ... | ... | @@ -11038,7 +10954,7 @@ const SwitchProngAnalysis = struct { |
| 11038 | 10954 | ); |
| 11039 | 10955 | |
| 11040 | 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 | 10958 | sema.inst_map.putAssumeCapacity(spa.tag_capture_inst, tag_ref); |
| 11043 | 10959 | } |
| 11044 | 10960 | defer if (has_tag_capture) assert(sema.inst_map.remove(spa.tag_capture_inst)); |
| ... | ... | @@ -11053,7 +10969,7 @@ const SwitchProngAnalysis = struct { |
| 11053 | 10969 | child_block, |
| 11054 | 10970 | capture == .by_ref, |
| 11055 | 10971 | prong_type == .special, |
| 11056 | | raw_capture_src, |
| 10972 | capture_src, |
| 11057 | 10973 | case_vals, |
| 11058 | 10974 | inline_case_capture, |
| 11059 | 10975 | ); |
| ... | ... | @@ -11079,8 +10995,8 @@ const SwitchProngAnalysis = struct { |
| 11079 | 10995 | prong_type: enum { normal, special }, |
| 11080 | 10996 | prong_body: []const Zir.Inst.Index, |
| 11081 | 10997 | capture: Zir.Inst.SwitchBlock.ProngInfo.Capture, |
| 11082 | | /// Must use the `scalar`, `special`, or `multi_capture` union field. |
| 11083 | | raw_capture_src: Module.SwitchProngSrc, |
| 10998 | /// Must use the `switch_capture` field in `offset`. |
| 10999 | capture_src: LazySrcLoc, |
| 11084 | 11000 | /// The set of all values which can reach this prong. May be undefined |
| 11085 | 11001 | /// if the prong is special or contains ranges. |
| 11086 | 11002 | case_vals: []const Air.Inst.Ref, |
| ... | ... | @@ -11094,7 +11010,7 @@ const SwitchProngAnalysis = struct { |
| 11094 | 11010 | const sema = spa.sema; |
| 11095 | 11011 | |
| 11096 | 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 | 11014 | sema.inst_map.putAssumeCapacity(spa.tag_capture_inst, tag_ref); |
| 11099 | 11015 | } |
| 11100 | 11016 | defer if (has_tag_capture) assert(sema.inst_map.remove(spa.tag_capture_inst)); |
| ... | ... | @@ -11109,7 +11025,7 @@ const SwitchProngAnalysis = struct { |
| 11109 | 11025 | case_block, |
| 11110 | 11026 | capture == .by_ref, |
| 11111 | 11027 | prong_type == .special, |
| 11112 | | raw_capture_src, |
| 11028 | capture_src, |
| 11113 | 11029 | case_vals, |
| 11114 | 11030 | inline_case_capture, |
| 11115 | 11031 | ); |
| ... | ... | @@ -11130,23 +11046,18 @@ const SwitchProngAnalysis = struct { |
| 11130 | 11046 | fn analyzeTagCapture( |
| 11131 | 11047 | spa: SwitchProngAnalysis, |
| 11132 | 11048 | block: *Block, |
| 11133 | | raw_capture_src: Module.SwitchProngSrc, |
| 11049 | capture_src: LazySrcLoc, |
| 11134 | 11050 | inline_case_capture: Air.Inst.Ref, |
| 11135 | 11051 | ) CompileError!Air.Inst.Ref { |
| 11136 | 11052 | const sema = spa.sema; |
| 11137 | 11053 | const mod = sema.mod; |
| 11138 | 11054 | const operand_ty = sema.typeOf(spa.operand); |
| 11139 | 11055 | if (operand_ty.zigTypeTag(mod) != .Union) { |
| 11140 | | const zir_datas = sema.code.instructions.items(.data); |
| 11141 | | const switch_node_offset = zir_datas[@intFromEnum(spa.switch_block_inst)].pl_node.src_node; |
| 11142 | | const raw_tag_capture_src: Module.SwitchProngSrc = switch (raw_capture_src) { |
| 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, |
| 11056 | const tag_capture_src: LazySrcLoc = .{ |
| 11057 | .base_node_inst = capture_src.base_node_inst, |
| 11058 | .offset = .{ .switch_tag_capture = capture_src.offset.switch_capture }, |
| 11147 | 11059 | }; |
| 11148 | | const capture_src = raw_tag_capture_src.resolve(mod, mod.declPtr(block.src_decl), switch_node_offset, .none); |
| 11149 | | return sema.fail(block, capture_src, "cannot capture tag of non-union type '{}'", .{ |
| 11060 | return sema.fail(block, tag_capture_src, "cannot capture tag of non-union type '{}'", .{ |
| 11150 | 11061 | operand_ty.fmt(mod), |
| 11151 | 11062 | }); |
| 11152 | 11063 | } |
| ... | ... | @@ -11159,7 +11070,7 @@ const SwitchProngAnalysis = struct { |
| 11159 | 11070 | block: *Block, |
| 11160 | 11071 | capture_byref: bool, |
| 11161 | 11072 | is_special_prong: bool, |
| 11162 | | raw_capture_src: Module.SwitchProngSrc, |
| 11073 | capture_src: LazySrcLoc, |
| 11163 | 11074 | case_vals: []const Air.Inst.Ref, |
| 11164 | 11075 | inline_case_capture: Air.Inst.Ref, |
| 11165 | 11076 | ) CompileError!Air.Inst.Ref { |
| ... | ... | @@ -11172,10 +11083,10 @@ const SwitchProngAnalysis = struct { |
| 11172 | 11083 | |
| 11173 | 11084 | const operand_ty = sema.typeOf(spa.operand); |
| 11174 | 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 | 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 | 11090 | if (operand_ty.zigTypeTag(zcu) == .Union) { |
| 11180 | 11091 | const field_index: u32 = @intCast(operand_ty.unionTagFieldIndex(item_val, zcu).?); |
| 11181 | 11092 | const union_obj = zcu.typeToUnion(operand_ty).?; |
| ... | ... | @@ -11216,7 +11127,7 @@ const SwitchProngAnalysis = struct { |
| 11216 | 11127 | .ErrorSet => if (spa.else_error_ty) |ty| { |
| 11217 | 11128 | return sema.bitCast(block, ty, spa.operand, operand_src, null); |
| 11218 | 11129 | } else { |
| 11219 | | try block.addUnreachable(operand_src, false); |
| 11130 | try sema.analyzeUnreachable(block, operand_src, false); |
| 11220 | 11131 | return .unreachable_value; |
| 11221 | 11132 | }, |
| 11222 | 11133 | else => return spa.operand, |
| ... | ... | @@ -11226,14 +11137,14 @@ const SwitchProngAnalysis = struct { |
| 11226 | 11137 | switch (operand_ty.zigTypeTag(zcu)) { |
| 11227 | 11138 | .Union => { |
| 11228 | 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 | 11142 | const first_field_index: u32 = zcu.unionTagFieldIndex(union_obj, first_item_val).?; |
| 11232 | 11143 | const first_field_ty = Type.fromInterned(union_obj.field_types.get(ip)[first_field_index]); |
| 11233 | 11144 | |
| 11234 | 11145 | const field_indices = try sema.arena.alloc(u32, case_vals.len); |
| 11235 | 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 | 11148 | field_idx.* = zcu.unionTagFieldIndex(union_obj, item_val).?; |
| 11238 | 11149 | } |
| 11239 | 11150 | |
| ... | ... | @@ -11253,27 +11164,22 @@ const SwitchProngAnalysis = struct { |
| 11253 | 11164 | } |
| 11254 | 11165 | |
| 11255 | 11166 | const case_srcs = try sema.arena.alloc(?LazySrcLoc, case_vals.len); |
| 11256 | | @memset(case_srcs, .unneeded); |
| 11257 | | |
| 11258 | | break :capture_ty sema.resolvePeerTypes(block, .unneeded, dummy_captures, .{ .override = case_srcs }) catch |err| switch (err) { |
| 11259 | | error.NeededSourceLocation => { |
| 11260 | | // This must be a multi-prong so this must be a `multi_capture` src |
| 11261 | | const multi_idx = raw_capture_src.multi_capture; |
| 11262 | | const src_decl_ptr = zcu.declPtr(block.src_decl); |
| 11263 | | for (case_srcs, 0..) |*case_src, i| { |
| 11264 | | const raw_case_src: Module.SwitchProngSrc = .{ .multi = .{ .prong = multi_idx, .item = @intCast(i) } }; |
| 11265 | | case_src.* = raw_case_src.resolve(zcu, src_decl_ptr, switch_node_offset, .none); |
| 11266 | | } |
| 11267 | | const capture_src = raw_capture_src.resolve(zcu, src_decl_ptr, switch_node_offset, .none); |
| 11268 | | _ = sema.resolvePeerTypes(block, capture_src, dummy_captures, .{ .override = case_srcs }) catch |err1| switch (err1) { |
| 11269 | | error.AnalysisFail => { |
| 11270 | | const msg = sema.err orelse return error.AnalysisFail; |
| 11271 | | try sema.reparentOwnedErrorMsg(block, capture_src, msg, "capture group with incompatible types", .{}); |
| 11272 | | return error.AnalysisFail; |
| 11273 | | }, |
| 11274 | | else => |e| return e, |
| 11275 | | }; |
| 11276 | | unreachable; |
| 11167 | for (case_srcs, 0..) |*case_src, i| { |
| 11168 | case_src.* = .{ |
| 11169 | .base_node_inst = capture_src.base_node_inst, |
| 11170 | .offset = .{ .switch_case_item = .{ |
| 11171 | .switch_node_offset = switch_node_offset, |
| 11172 | .case_idx = capture_src.offset.switch_capture.case_idx, |
| 11173 | .item_idx = .{ .kind = .single, .index = @intCast(i) }, |
| 11174 | } }, |
| 11175 | }; |
| 11176 | } |
| 11177 | |
| 11178 | break :capture_ty sema.resolvePeerTypes(block, capture_src, dummy_captures, .{ .override = case_srcs }) catch |err| switch (err) { |
| 11179 | error.AnalysisFail => { |
| 11180 | const msg = sema.err orelse return error.AnalysisFail; |
| 11181 | try sema.reparentOwnedErrorMsg(capture_src, msg, "capture group with incompatible types", .{}); |
| 11182 | return error.AnalysisFail; |
| 11277 | 11183 | }, |
| 11278 | 11184 | else => |e| return e, |
| 11279 | 11185 | }; |
| ... | ... | @@ -11301,28 +11207,23 @@ const SwitchProngAnalysis = struct { |
| 11301 | 11207 | dummy.* = try zcu.undefRef(field_ptr_ty); |
| 11302 | 11208 | } |
| 11303 | 11209 | const case_srcs = try sema.arena.alloc(?LazySrcLoc, case_vals.len); |
| 11304 | | @memset(case_srcs, .unneeded); |
| 11305 | | |
| 11306 | | break :resolve sema.resolvePeerTypes(block, .unneeded, dummy_captures, .{ .override = case_srcs }) catch |err| switch (err) { |
| 11307 | | error.NeededSourceLocation => { |
| 11308 | | // This must be a multi-prong so this must be a `multi_capture` src |
| 11309 | | const multi_idx = raw_capture_src.multi_capture; |
| 11310 | | const src_decl_ptr = zcu.declPtr(block.src_decl); |
| 11311 | | for (case_srcs, 0..) |*case_src, i| { |
| 11312 | | const raw_case_src: Module.SwitchProngSrc = .{ .multi = .{ .prong = multi_idx, .item = @intCast(i) } }; |
| 11313 | | case_src.* = raw_case_src.resolve(zcu, src_decl_ptr, switch_node_offset, .none); |
| 11314 | | } |
| 11315 | | const capture_src = raw_capture_src.resolve(zcu, src_decl_ptr, switch_node_offset, .none); |
| 11316 | | _ = sema.resolvePeerTypes(block, capture_src, dummy_captures, .{ .override = case_srcs }) catch |err1| switch (err1) { |
| 11317 | | error.AnalysisFail => { |
| 11318 | | const msg = sema.err orelse return error.AnalysisFail; |
| 11319 | | try sema.errNote(block, capture_src, msg, "this coercion is only possible when capturing by value", .{}); |
| 11320 | | try sema.reparentOwnedErrorMsg(block, capture_src, msg, "capture group with incompatible types", .{}); |
| 11321 | | return error.AnalysisFail; |
| 11322 | | }, |
| 11323 | | else => |e| return e, |
| 11324 | | }; |
| 11325 | | unreachable; |
| 11210 | for (case_srcs, 0..) |*case_src, i| { |
| 11211 | case_src.* = .{ |
| 11212 | .base_node_inst = capture_src.base_node_inst, |
| 11213 | .offset = .{ .switch_case_item = .{ |
| 11214 | .switch_node_offset = switch_node_offset, |
| 11215 | .case_idx = capture_src.offset.switch_capture.case_idx, |
| 11216 | .item_idx = .{ .kind = .single, .index = @intCast(i) }, |
| 11217 | } }, |
| 11218 | }; |
| 11219 | } |
| 11220 | |
| 11221 | break :resolve sema.resolvePeerTypes(block, capture_src, dummy_captures, .{ .override = case_srcs }) catch |err| switch (err) { |
| 11222 | error.AnalysisFail => { |
| 11223 | const msg = sema.err orelse return error.AnalysisFail; |
| 11224 | try sema.errNote(capture_src, msg, "this coercion is only possible when capturing by value", .{}); |
| 11225 | try sema.reparentOwnedErrorMsg(capture_src, msg, "capture group with incompatible types", .{}); |
| 11226 | return error.AnalysisFail; |
| 11326 | 11227 | }, |
| 11327 | 11228 | else => |e| return e, |
| 11328 | 11229 | }; |
| ... | ... | @@ -11357,7 +11258,7 @@ const SwitchProngAnalysis = struct { |
| 11357 | 11258 | const first_non_imc = in_mem: { |
| 11358 | 11259 | for (field_indices, 0..) |field_idx, i| { |
| 11359 | 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 | 11262 | break :in_mem i; |
| 11362 | 11263 | } |
| 11363 | 11264 | } |
| ... | ... | @@ -11380,7 +11281,7 @@ const SwitchProngAnalysis = struct { |
| 11380 | 11281 | const next = first_non_imc + 1; |
| 11381 | 11282 | for (field_indices[next..], next..) |field_idx, i| { |
| 11382 | 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 | 11285 | in_mem_coercible.unset(i); |
| 11385 | 11286 | } |
| 11386 | 11287 | } |
| ... | ... | @@ -11409,20 +11310,19 @@ const SwitchProngAnalysis = struct { |
| 11409 | 11310 | var coerce_block = block.makeSubBlock(); |
| 11410 | 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 | 11322 | const field_idx = field_indices[idx]; |
| 11413 | 11323 | const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[field_idx]); |
| 11414 | 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) { |
| 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 | | }; |
| 11325 | const coerced = try sema.coerce(&coerce_block, capture_ty, uncoerced, case_src); |
| 11426 | 11326 | _ = try coerce_block.addBr(capture_block_inst, coerced); |
| 11427 | 11327 | |
| 11428 | 11328 | try cases_extra.ensureUnusedCapacity(3 + coerce_block.instructions.items.len); |
| ... | ... | @@ -11476,7 +11376,6 @@ const SwitchProngAnalysis = struct { |
| 11476 | 11376 | }, |
| 11477 | 11377 | .ErrorSet => { |
| 11478 | 11378 | if (capture_byref) { |
| 11479 | | const capture_src = raw_capture_src.resolve(zcu, zcu.declPtr(block.src_decl), switch_node_offset, .none); |
| 11480 | 11379 | return sema.fail( |
| 11481 | 11380 | block, |
| 11482 | 11381 | capture_src, |
| ... | ... | @@ -11486,7 +11385,7 @@ const SwitchProngAnalysis = struct { |
| 11486 | 11385 | } |
| 11487 | 11386 | |
| 11488 | 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 | 11389 | const item_ty = try zcu.singleErrorSetType(item_val.getErrorName(zcu).unwrap().?); |
| 11491 | 11390 | return sema.bitCast(block, item_ty, spa.operand, operand_src, null); |
| 11492 | 11391 | } |
| ... | ... | @@ -11494,7 +11393,7 @@ const SwitchProngAnalysis = struct { |
| 11494 | 11393 | var names: InferredErrorSet.NameMap = .{}; |
| 11495 | 11394 | try names.ensureUnusedCapacity(sema.arena, case_vals.len); |
| 11496 | 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 | 11397 | names.putAssumeCapacityNoClobber(err_val.getErrorName(zcu).unwrap().?, {}); |
| 11499 | 11398 | } |
| 11500 | 11399 | const error_ty = try zcu.errorSetFromUnsortedNames(names.keys()); |
| ... | ... | @@ -11548,10 +11447,10 @@ fn switchCond( |
| 11548 | 11447 | try sema.resolveTypeFields(operand_ty); |
| 11549 | 11448 | const enum_ty = operand_ty.unionTagType(mod) orelse { |
| 11550 | 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 | 11451 | errdefer msg.destroy(sema.gpa); |
| 11553 | | if (operand_ty.declSrcLocOrNull(mod)) |union_src| { |
| 11554 | | try mod.errNoteNonLazy(union_src, msg, "consider 'union(enum)' here", .{}); |
| 11452 | if (operand_ty.srcLocOrNull(mod)) |union_src| { |
| 11453 | try sema.errNote(union_src, msg, "consider 'union(enum)' here", .{}); |
| 11555 | 11454 | } |
| 11556 | 11455 | break :msg msg; |
| 11557 | 11456 | }; |
| ... | ... | @@ -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 | 11479 | fn zirSwitchBlockErrUnion(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 11581 | 11480 | const tracy = trace(@src()); |
| ... | ... | @@ -11586,11 +11485,11 @@ fn zirSwitchBlockErrUnion(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp |
| 11586 | 11485 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 11587 | 11486 | const switch_src = block.nodeOffset(inst_data.src_node); |
| 11588 | 11487 | const switch_src_node_offset = inst_data.src_node; |
| 11589 | | const switch_operand_src: LazySrcLoc = .{ .node_offset_switch_operand = switch_src_node_offset }; |
| 11590 | | const else_prong_src: LazySrcLoc = .{ .node_offset_switch_special_prong = switch_src_node_offset }; |
| 11488 | const switch_operand_src = block.src(.{ .node_offset_switch_operand = switch_src_node_offset }); |
| 11489 | const else_prong_src = block.src(.{ .node_offset_switch_special_prong = switch_src_node_offset }); |
| 11591 | 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 }; |
| 11593 | | const main_src: LazySrcLoc = .{ .node_offset_main_token = extra.data.main_src_node_offset }; |
| 11491 | const main_operand_src = block.src(.{ .node_offset_if_cond = 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 | 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 | 11609 | .runtime_index = block.runtime_index, |
| 11711 | 11610 | .error_return_trace_index = block.error_return_trace_index, |
| 11712 | 11611 | .want_safety = block.want_safety, |
| 11612 | .src_base_inst = block.src_base_inst, |
| 11713 | 11613 | }; |
| 11714 | 11614 | const merges = &child_block.label.?.merges; |
| 11715 | 11615 | defer child_block.instructions.deinit(gpa); |
| ... | ... | @@ -11776,6 +11676,7 @@ fn zirSwitchBlockErrUnion(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp |
| 11776 | 11676 | try sema.switchCond(block, switch_operand_src, spa.operand), |
| 11777 | 11677 | err_val, |
| 11778 | 11678 | operand_err_set_ty, |
| 11679 | switch_src_node_offset, |
| 11779 | 11680 | .{ |
| 11780 | 11681 | .body = else_case.body, |
| 11781 | 11682 | .end = else_case.end, |
| ... | ... | @@ -11817,7 +11718,7 @@ fn zirSwitchBlockErrUnion(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp |
| 11817 | 11718 | |
| 11818 | 11719 | var sub_block = child_block.makeSubBlock(); |
| 11819 | 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 | 11722 | sub_block.runtime_index.increment(); |
| 11822 | 11723 | sub_block.need_debug_scope = null; // this body is emitted regardless |
| 11823 | 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 | 11795 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 11895 | 11796 | const src = block.nodeOffset(inst_data.src_node); |
| 11896 | 11797 | const src_node_offset = inst_data.src_node; |
| 11897 | | const operand_src: LazySrcLoc = .{ .node_offset_switch_operand = src_node_offset }; |
| 11898 | | const special_prong_src: LazySrcLoc = .{ .node_offset_switch_special_prong = src_node_offset }; |
| 11798 | const operand_src = block.src(.{ .node_offset_switch_operand = src_node_offset }); |
| 11799 | const special_prong_src = block.src(.{ .node_offset_switch_special_prong = src_node_offset }); |
| 11899 | 11800 | const extra = sema.code.extraData(Zir.Inst.SwitchBlock, inst_data.payload_index); |
| 11900 | 11801 | |
| 11901 | 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 | 11863 | const union_originally = maybe_union_ty.zigTypeTag(mod) == .Union; |
| 11963 | 11864 | |
| 11964 | 11865 | // Duplicate checking variables later also used for `inline else`. |
| 11965 | | var seen_enum_fields: []?Module.SwitchProngSrc = &.{}; |
| 11866 | var seen_enum_fields: []?LazySrcLoc = &.{}; |
| 11966 | 11867 | var seen_errors = SwitchErrorSet.init(gpa); |
| 11967 | 11868 | var range_set = RangeSet.init(gpa, mod); |
| 11968 | 11869 | var true_count: u8 = 0; |
| ... | ... | @@ -11985,21 +11886,18 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 11985 | 11886 | if (special_prong == .under and (!operand_ty.isNonexhaustiveEnum(mod) or union_originally)) { |
| 11986 | 11887 | const msg = msg: { |
| 11987 | 11888 | const msg = try sema.errMsg( |
| 11988 | | block, |
| 11989 | 11889 | src, |
| 11990 | 11890 | "'_' prong only allowed when switching on non-exhaustive enums", |
| 11991 | 11891 | .{}, |
| 11992 | 11892 | ); |
| 11993 | 11893 | errdefer msg.destroy(gpa); |
| 11994 | 11894 | try sema.errNote( |
| 11995 | | block, |
| 11996 | 11895 | special_prong_src, |
| 11997 | 11896 | msg, |
| 11998 | 11897 | "'_' prong here", |
| 11999 | 11898 | .{}, |
| 12000 | 11899 | ); |
| 12001 | 11900 | try sema.errNote( |
| 12002 | | block, |
| 12003 | 11901 | src, |
| 12004 | 11902 | msg, |
| 12005 | 11903 | "consider using 'else'", |
| ... | ... | @@ -12014,7 +11912,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 12014 | 11912 | switch (operand_ty.zigTypeTag(mod)) { |
| 12015 | 11913 | .Union => unreachable, // handled in `switchCond` |
| 12016 | 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 | 11916 | empty_enum = seen_enum_fields.len == 0 and !operand_ty.isNonexhaustiveEnum(mod); |
| 12019 | 11917 | @memset(seen_enum_fields, null); |
| 12020 | 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 | 11932 | &range_set, |
| 12035 | 11933 | item_ref, |
| 12036 | 11934 | operand_ty, |
| 12037 | | src_node_offset, |
| 12038 | | .{ .scalar = scalar_i }, |
| 11935 | block.src(.{ .switch_case_item = .{ |
| 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 | 11960 | &range_set, |
| 12060 | 11961 | item_ref, |
| 12061 | 11962 | operand_ty, |
| 12062 | | src_node_offset, |
| 12063 | | .{ .multi = .{ .prong = multi_i, .item = @intCast(item_i) } }, |
| 11963 | block.src(.{ .switch_case_item = .{ |
| 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 | 11985 | } else if (!all_tags_handled) { |
| 12082 | 11986 | const msg = msg: { |
| 12083 | 11987 | const msg = try sema.errMsg( |
| 12084 | | block, |
| 12085 | 11988 | src, |
| 12086 | 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 | 12002 | .{field_name.fmt(&mod.intern_pool)}, |
| 12100 | 12003 | ); |
| 12101 | 12004 | } |
| 12102 | | try mod.errNoteNonLazy( |
| 12103 | | operand_ty.declSrcLoc(mod), |
| 12005 | try sema.errNote( |
| 12006 | operand_ty.srcLoc(mod), |
| 12104 | 12007 | msg, |
| 12105 | 12008 | "enum '{}' declared here", |
| 12106 | 12009 | .{operand_ty.fmt(mod)}, |
| ... | ... | @@ -12144,8 +12047,11 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 12144 | 12047 | &range_set, |
| 12145 | 12048 | item_ref, |
| 12146 | 12049 | operand_ty, |
| 12147 | | src_node_offset, |
| 12148 | | .{ .scalar = scalar_i }, |
| 12050 | block.src(.{ .switch_case_item = .{ |
| 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 | 12074 | &range_set, |
| 12169 | 12075 | item_ref, |
| 12170 | 12076 | operand_ty, |
| 12171 | | src_node_offset, |
| 12172 | | .{ .multi = .{ .prong = multi_i, .item = @intCast(item_i) } }, |
| 12077 | block.src(.{ .switch_case_item = .{ |
| 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 | 12096 | item_first, |
| 12188 | 12097 | item_last, |
| 12189 | 12098 | operand_ty, |
| 12190 | | src_node_offset, |
| 12191 | | .{ .range = .{ .prong = multi_i, .item = range_i } }, |
| 12099 | block.src(.{ .switch_case_item = .{ |
| 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 | 12105 | case_vals.appendAssumeCapacity(vals[0]); |
| 12194 | 12106 | case_vals.appendAssumeCapacity(vals[1]); |
| ... | ... | @@ -12239,8 +12151,11 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 12239 | 12151 | &true_count, |
| 12240 | 12152 | &false_count, |
| 12241 | 12153 | item_ref, |
| 12242 | | src_node_offset, |
| 12243 | | .{ .scalar = scalar_i }, |
| 12154 | block.src(.{ .switch_case_item = .{ |
| 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 | 12178 | &true_count, |
| 12264 | 12179 | &false_count, |
| 12265 | 12180 | item_ref, |
| 12266 | | src_node_offset, |
| 12267 | | .{ .multi = .{ .prong = multi_i, .item = @intCast(item_i) } }, |
| 12181 | block.src(.{ .switch_case_item = .{ |
| 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 | 12240 | &seen_values, |
| 12323 | 12241 | item_ref, |
| 12324 | 12242 | operand_ty, |
| 12325 | | src_node_offset, |
| 12326 | | .{ .scalar = scalar_i }, |
| 12243 | block.src(.{ .switch_case_item = .{ |
| 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 | 12267 | &seen_values, |
| 12347 | 12268 | item_ref, |
| 12348 | 12269 | operand_ty, |
| 12349 | | src_node_offset, |
| 12350 | | .{ .multi = .{ .prong = multi_i, .item = @intCast(item_i) } }, |
| 12270 | block.src(.{ .switch_case_item = .{ |
| 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 | 12341 | .runtime_index = block.runtime_index, |
| 12418 | 12342 | .want_safety = block.want_safety, |
| 12419 | 12343 | .error_return_trace_index = block.error_return_trace_index, |
| 12344 | .src_base_inst = block.src_base_inst, |
| 12420 | 12345 | }; |
| 12421 | 12346 | const merges = &child_block.label.?.merges; |
| 12422 | 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 | 12355 | operand, |
| 12431 | 12356 | operand_val, |
| 12432 | 12357 | operand_ty, |
| 12358 | src_node_offset, |
| 12433 | 12359 | special, |
| 12434 | 12360 | case_vals, |
| 12435 | 12361 | scalar_cases_len, |
| ... | ... | @@ -12462,7 +12388,10 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 12462 | 12388 | .special, |
| 12463 | 12389 | special.body, |
| 12464 | 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 | 12395 | undefined, // case_vals may be undefined for special prongs |
| 12467 | 12396 | .none, |
| 12468 | 12397 | false, |
| ... | ... | @@ -12529,9 +12458,9 @@ fn analyzeSwitchRuntimeBlock( |
| 12529 | 12458 | union_originally: bool, |
| 12530 | 12459 | maybe_union_ty: Type, |
| 12531 | 12460 | err_set: bool, |
| 12532 | | src_node_offset: i32, |
| 12461 | switch_node_offset: i32, |
| 12533 | 12462 | special_prong_src: LazySrcLoc, |
| 12534 | | seen_enum_fields: []?Module.SwitchProngSrc, |
| 12463 | seen_enum_fields: []?LazySrcLoc, |
| 12535 | 12464 | seen_errors: SwitchErrorSet, |
| 12536 | 12465 | range_set: RangeSet, |
| 12537 | 12466 | true_count: u8, |
| ... | ... | @@ -12552,7 +12481,7 @@ fn analyzeSwitchRuntimeBlock( |
| 12552 | 12481 | |
| 12553 | 12482 | var case_block = child_block.makeSubBlock(); |
| 12554 | 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 | 12485 | case_block.runtime_index.increment(); |
| 12557 | 12486 | case_block.need_debug_scope = null; // this body is emitted regardless |
| 12558 | 12487 | defer case_block.instructions.deinit(gpa); |
| ... | ... | @@ -12574,7 +12503,7 @@ fn analyzeSwitchRuntimeBlock( |
| 12574 | 12503 | // `item` is already guaranteed to be constant known. |
| 12575 | 12504 | |
| 12576 | 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 | 12507 | const item_val = sema.resolveLazyValue(unresolved_item_val) catch unreachable; |
| 12579 | 12508 | const field_ty = maybe_union_ty.unionFieldType(item_val, mod).?; |
| 12580 | 12509 | break :blk field_ty.zigTypeTag(mod) != .NoReturn; |
| ... | ... | @@ -12588,7 +12517,10 @@ fn analyzeSwitchRuntimeBlock( |
| 12588 | 12517 | .normal, |
| 12589 | 12518 | body, |
| 12590 | 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 | 12524 | &.{item}, |
| 12593 | 12525 | if (info.is_inline) item else .none, |
| 12594 | 12526 | info.has_tag_capture, |
| ... | ... | @@ -12643,8 +12575,8 @@ fn analyzeSwitchRuntimeBlock( |
| 12643 | 12575 | const item_first_ref = range_items[0]; |
| 12644 | 12576 | const item_last_ref = range_items[1]; |
| 12645 | 12577 | |
| 12646 | | var item = sema.resolveConstDefinedValue(block, .unneeded, item_first_ref, undefined) catch unreachable; |
| 12647 | | const item_last = sema.resolveConstDefinedValue(block, .unneeded, item_last_ref, undefined) catch unreachable; |
| 12578 | var item = sema.resolveConstDefinedValue(block, LazySrcLoc.unneeded, item_first_ref, undefined) catch unreachable; |
| 12579 | const item_last = sema.resolveConstDefinedValue(block, LazySrcLoc.unneeded, item_last_ref, undefined) catch unreachable; |
| 12648 | 12580 | |
| 12649 | 12581 | while (item.compareScalar(.lte, item_last, operand_ty, mod)) : ({ |
| 12650 | 12582 | // Previous validation has resolved any possible lazy values. |
| ... | ... | @@ -12660,17 +12592,11 @@ fn analyzeSwitchRuntimeBlock( |
| 12660 | 12592 | case_block.instructions.shrinkRetainingCapacity(0); |
| 12661 | 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) { |
| 12664 | | error.NeededSourceLocation => { |
| 12665 | | const case_src = Module.SwitchProngSrc{ |
| 12666 | | .range = .{ .prong = multi_i, .item = range_i }, |
| 12667 | | }; |
| 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 | | }; |
| 12595 | if (emit_bb) try sema.emitBackwardBranch(block, block.src(.{ .switch_case_item = .{ |
| 12596 | .switch_node_offset = switch_node_offset, |
| 12597 | .case_idx = .{ .kind = .multi, .index = @intCast(multi_i) }, |
| 12598 | .item_idx = .{ .kind = .range, .index = @intCast(range_i) }, |
| 12599 | } })); |
| 12674 | 12600 | emit_bb = true; |
| 12675 | 12601 | |
| 12676 | 12602 | try spa.analyzeProngRuntime( |
| ... | ... | @@ -12678,7 +12604,10 @@ fn analyzeSwitchRuntimeBlock( |
| 12678 | 12604 | .normal, |
| 12679 | 12605 | body, |
| 12680 | 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 | 12611 | undefined, // case_vals may be undefined for ranges |
| 12683 | 12612 | item_ref, |
| 12684 | 12613 | info.has_tag_capture, |
| ... | ... | @@ -12701,22 +12630,16 @@ fn analyzeSwitchRuntimeBlock( |
| 12701 | 12630 | case_block.error_return_trace_index = child_block.error_return_trace_index; |
| 12702 | 12631 | |
| 12703 | 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 | 12634 | const field_ty = maybe_union_ty.unionFieldType(item_val, mod).?; |
| 12706 | 12635 | break :blk field_ty.zigTypeTag(mod) != .NoReturn; |
| 12707 | 12636 | } else true; |
| 12708 | 12637 | |
| 12709 | | if (emit_bb) sema.emitBackwardBranch(block, .unneeded) catch |err| switch (err) { |
| 12710 | | error.NeededSourceLocation => { |
| 12711 | | const case_src = Module.SwitchProngSrc{ |
| 12712 | | .multi = .{ .prong = multi_i, .item = @intCast(item_i) }, |
| 12713 | | }; |
| 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 | | }; |
| 12638 | if (emit_bb) try sema.emitBackwardBranch(block, block.src(.{ .switch_case_item = .{ |
| 12639 | .switch_node_offset = switch_node_offset, |
| 12640 | .case_idx = .{ .kind = .multi, .index = @intCast(multi_i) }, |
| 12641 | .item_idx = .{ .kind = .single, .index = @intCast(item_i) }, |
| 12642 | } })); |
| 12720 | 12643 | emit_bb = true; |
| 12721 | 12644 | |
| 12722 | 12645 | if (analyze_body) { |
| ... | ... | @@ -12725,7 +12648,10 @@ fn analyzeSwitchRuntimeBlock( |
| 12725 | 12648 | .normal, |
| 12726 | 12649 | body, |
| 12727 | 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 | 12655 | &.{item}, |
| 12730 | 12656 | item, |
| 12731 | 12657 | info.has_tag_capture, |
| ... | ... | @@ -12755,7 +12681,7 @@ fn analyzeSwitchRuntimeBlock( |
| 12755 | 12681 | |
| 12756 | 12682 | const analyze_body = if (union_originally) |
| 12757 | 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 | 12685 | const field_ty = maybe_union_ty.unionFieldType(item_val, mod).?; |
| 12760 | 12686 | if (field_ty.zigTypeTag(mod) != .NoReturn) break true; |
| 12761 | 12687 | } else false |
| ... | ... | @@ -12772,7 +12698,10 @@ fn analyzeSwitchRuntimeBlock( |
| 12772 | 12698 | .normal, |
| 12773 | 12699 | body, |
| 12774 | 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 | 12705 | items, |
| 12777 | 12706 | .none, |
| 12778 | 12707 | false, |
| ... | ... | @@ -12856,7 +12785,10 @@ fn analyzeSwitchRuntimeBlock( |
| 12856 | 12785 | .normal, |
| 12857 | 12786 | body, |
| 12858 | 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 | 12792 | items, |
| 12861 | 12793 | .none, |
| 12862 | 12794 | false, |
| ... | ... | @@ -12921,7 +12853,10 @@ fn analyzeSwitchRuntimeBlock( |
| 12921 | 12853 | .special, |
| 12922 | 12854 | special.body, |
| 12923 | 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 | 12860 | &.{item_ref}, |
| 12926 | 12861 | item_ref, |
| 12927 | 12862 | special.has_tag_capture, |
| ... | ... | @@ -12966,7 +12901,10 @@ fn analyzeSwitchRuntimeBlock( |
| 12966 | 12901 | .special, |
| 12967 | 12902 | special.body, |
| 12968 | 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 | 12908 | &.{item_ref}, |
| 12971 | 12909 | item_ref, |
| 12972 | 12910 | special.has_tag_capture, |
| ... | ... | @@ -12997,7 +12935,10 @@ fn analyzeSwitchRuntimeBlock( |
| 12997 | 12935 | .special, |
| 12998 | 12936 | special.body, |
| 12999 | 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 | 12942 | &.{item_ref}, |
| 13002 | 12943 | item_ref, |
| 13003 | 12944 | special.has_tag_capture, |
| ... | ... | @@ -13025,7 +12966,10 @@ fn analyzeSwitchRuntimeBlock( |
| 13025 | 12966 | .special, |
| 13026 | 12967 | special.body, |
| 13027 | 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 | 12973 | &.{.bool_true}, |
| 13030 | 12974 | .bool_true, |
| 13031 | 12975 | special.has_tag_capture, |
| ... | ... | @@ -13051,7 +12995,10 @@ fn analyzeSwitchRuntimeBlock( |
| 13051 | 12995 | .special, |
| 13052 | 12996 | special.body, |
| 13053 | 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 | 13002 | &.{.bool_false}, |
| 13056 | 13003 | .bool_false, |
| 13057 | 13004 | special.has_tag_capture, |
| ... | ... | @@ -13101,7 +13048,10 @@ fn analyzeSwitchRuntimeBlock( |
| 13101 | 13048 | .special, |
| 13102 | 13049 | special.body, |
| 13103 | 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 | 13055 | undefined, // case_vals may be undefined for special prongs |
| 13106 | 13056 | .none, |
| 13107 | 13057 | false, |
| ... | ... | @@ -13161,6 +13111,7 @@ fn resolveSwitchComptime( |
| 13161 | 13111 | cond_operand: Air.Inst.Ref, |
| 13162 | 13112 | operand_val: Value, |
| 13163 | 13113 | operand_ty: Type, |
| 13114 | switch_node_offset: i32, |
| 13164 | 13115 | special: SpecialProng, |
| 13165 | 13116 | case_vals: std.ArrayListUnmanaged(Air.Inst.Ref), |
| 13166 | 13117 | scalar_cases_len: u32, |
| ... | ... | @@ -13181,7 +13132,7 @@ fn resolveSwitchComptime( |
| 13181 | 13132 | extra_index += info.body_len; |
| 13182 | 13133 | |
| 13183 | 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 | 13136 | if (operand_val.eql(item_val, operand_ty, sema.mod)) { |
| 13186 | 13137 | if (err_set) try sema.maybeErrorUnwrapComptime(child_block, body, cond_operand); |
| 13187 | 13138 | return spa.resolveProngComptime( |
| ... | ... | @@ -13189,7 +13140,10 @@ fn resolveSwitchComptime( |
| 13189 | 13140 | .normal, |
| 13190 | 13141 | body, |
| 13191 | 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 | 13147 | &.{item}, |
| 13194 | 13148 | if (info.is_inline) cond_operand else .none, |
| 13195 | 13149 | info.has_tag_capture, |
| ... | ... | @@ -13215,7 +13169,7 @@ fn resolveSwitchComptime( |
| 13215 | 13169 | |
| 13216 | 13170 | for (items) |item| { |
| 13217 | 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 | 13173 | if (operand_val.eql(item_val, operand_ty, sema.mod)) { |
| 13220 | 13174 | if (err_set) try sema.maybeErrorUnwrapComptime(child_block, body, cond_operand); |
| 13221 | 13175 | return spa.resolveProngComptime( |
| ... | ... | @@ -13223,7 +13177,10 @@ fn resolveSwitchComptime( |
| 13223 | 13177 | .normal, |
| 13224 | 13178 | body, |
| 13225 | 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 | 13184 | items, |
| 13228 | 13185 | if (info.is_inline) cond_operand else .none, |
| 13229 | 13186 | info.has_tag_capture, |
| ... | ... | @@ -13239,8 +13196,8 @@ fn resolveSwitchComptime( |
| 13239 | 13196 | case_val_idx += 2; |
| 13240 | 13197 | |
| 13241 | 13198 | // Validation above ensured these will succeed. |
| 13242 | | const first_val = sema.resolveConstDefinedValue(child_block, .unneeded, range_items[0], undefined) catch unreachable; |
| 13243 | | const last_val = sema.resolveConstDefinedValue(child_block, .unneeded, range_items[1], undefined) catch unreachable; |
| 13199 | const first_val = sema.resolveConstDefinedValue(child_block, LazySrcLoc.unneeded, range_items[0], undefined) catch unreachable; |
| 13200 | const last_val = sema.resolveConstDefinedValue(child_block, LazySrcLoc.unneeded, range_items[1], undefined) catch unreachable; |
| 13244 | 13201 | if ((try sema.compareAll(resolved_operand_val, .gte, first_val, operand_ty)) and |
| 13245 | 13202 | (try sema.compareAll(resolved_operand_val, .lte, last_val, operand_ty))) |
| 13246 | 13203 | { |
| ... | ... | @@ -13250,7 +13207,10 @@ fn resolveSwitchComptime( |
| 13250 | 13207 | .normal, |
| 13251 | 13208 | body, |
| 13252 | 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 | 13214 | undefined, // case_vals may be undefined for ranges |
| 13255 | 13215 | if (info.is_inline) cond_operand else .none, |
| 13256 | 13216 | info.has_tag_capture, |
| ... | ... | @@ -13272,7 +13232,10 @@ fn resolveSwitchComptime( |
| 13272 | 13232 | .special, |
| 13273 | 13233 | special.body, |
| 13274 | 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 | 13239 | undefined, // case_vals may be undefined for special prongs |
| 13277 | 13240 | if (special.is_inline) cond_operand else .none, |
| 13278 | 13241 | special.has_tag_capture, |
| ... | ... | @@ -13358,36 +13321,19 @@ fn resolveSwitchItemVal( |
| 13358 | 13321 | item_ref: Zir.Inst.Ref, |
| 13359 | 13322 | /// Coerce `item_ref` to this type. |
| 13360 | 13323 | coerce_ty: Type, |
| 13361 | | switch_node_offset: i32, |
| 13362 | | switch_prong_src: Module.SwitchProngSrc, |
| 13363 | | range_expand: Module.SwitchProngSrc.RangeExpand, |
| 13324 | item_src: LazySrcLoc, |
| 13364 | 13325 | ) CompileError!ResolvedSwitchItem { |
| 13365 | | const mod = sema.mod; |
| 13366 | 13326 | const uncoerced_item = try sema.resolveInst(item_ref); |
| 13367 | 13327 | |
| 13368 | 13328 | // Constructing a LazySrcLoc is costly because we only have the switch AST node. |
| 13369 | 13329 | // Only if we know for sure we need to report a compile error do we resolve the |
| 13370 | 13330 | // full source locations. |
| 13371 | 13331 | |
| 13372 | | const item = sema.coerce(block, coerce_ty, uncoerced_item, .unneeded) catch |err| switch (err) { |
| 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 | | }; |
| 13332 | const item = try sema.coerce(block, coerce_ty, uncoerced_item, item_src); |
| 13380 | 13333 | |
| 13381 | | const maybe_lazy = sema.resolveConstDefinedValue(block, .unneeded, item, undefined) catch |err| switch (err) { |
| 13382 | | error.NeededSourceLocation => { |
| 13383 | | const src = switch_prong_src.resolve(mod, mod.declPtr(block.src_decl), switch_node_offset, range_expand); |
| 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 | | }; |
| 13334 | const maybe_lazy = try sema.resolveConstDefinedValue(block, item_src, item, .{ |
| 13335 | .needed_comptime_reason = "switch prong values must be comptime-known", |
| 13336 | }); |
| 13391 | 13337 | |
| 13392 | 13338 | const val = try sema.resolveLazyValue(maybe_lazy); |
| 13393 | 13339 | const new_item = if (val.toIntern() != maybe_lazy.toIntern()) blk: { |
| ... | ... | @@ -13430,8 +13376,11 @@ fn validateErrSetSwitch( |
| 13430 | 13376 | seen_errors, |
| 13431 | 13377 | item_ref, |
| 13432 | 13378 | operand_ty, |
| 13433 | | src_node_offset, |
| 13434 | | .{ .scalar = scalar_i }, |
| 13379 | block.src(.{ .switch_case_item = .{ |
| 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 | 13403 | seen_errors, |
| 13455 | 13404 | item_ref, |
| 13456 | 13405 | operand_ty, |
| 13457 | | src_node_offset, |
| 13458 | | .{ .multi = .{ .prong = multi_i, .item = @intCast(item_i) } }, |
| 13406 | block.src(.{ .switch_case_item = .{ |
| 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 | 13436 | if (!seen_errors.contains(error_name) and !has_else) { |
| 13485 | 13437 | const msg = maybe_msg orelse blk: { |
| 13486 | 13438 | maybe_msg = try sema.errMsg( |
| 13487 | | block, |
| 13488 | 13439 | src, |
| 13489 | 13440 | "switch must handle all possibilities", |
| 13490 | 13441 | .{}, |
| ... | ... | @@ -13493,7 +13444,6 @@ fn validateErrSetSwitch( |
| 13493 | 13444 | }; |
| 13494 | 13445 | |
| 13495 | 13446 | try sema.errNote( |
| 13496 | | block, |
| 13497 | 13447 | src, |
| 13498 | 13448 | msg, |
| 13499 | 13449 | "unhandled error value: 'error.{}'", |
| ... | ... | @@ -13571,18 +13521,24 @@ fn validateSwitchRange( |
| 13571 | 13521 | first_ref: Zir.Inst.Ref, |
| 13572 | 13522 | last_ref: Zir.Inst.Ref, |
| 13573 | 13523 | operand_ty: Type, |
| 13574 | | src_node_offset: i32, |
| 13575 | | switch_prong_src: Module.SwitchProngSrc, |
| 13524 | item_src: LazySrcLoc, |
| 13576 | 13525 | ) CompileError![2]Air.Inst.Ref { |
| 13577 | 13526 | const mod = sema.mod; |
| 13578 | | const first = try sema.resolveSwitchItemVal(block, first_ref, operand_ty, src_node_offset, switch_prong_src, .first); |
| 13579 | | const last = try sema.resolveSwitchItemVal(block, last_ref, operand_ty, src_node_offset, switch_prong_src, .last); |
| 13527 | const first_src: LazySrcLoc = .{ |
| 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 | 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); |
| 13582 | | return sema.fail(block, src, "range start value is greater than the end value", .{}); |
| 13538 | return sema.fail(block, item_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); |
| 13585 | | try sema.validateSwitchDupe(block, maybe_prev_src, switch_prong_src, src_node_offset); |
| 13540 | const maybe_prev_src = try range_set.add(first.val, last.val, item_src); |
| 13541 | try sema.validateSwitchDupe(block, maybe_prev_src, item_src); |
| 13586 | 13542 | return .{ first.ref, last.ref }; |
| 13587 | 13543 | } |
| 13588 | 13544 | |
| ... | ... | @@ -13592,36 +13548,34 @@ fn validateSwitchItemInt( |
| 13592 | 13548 | range_set: *RangeSet, |
| 13593 | 13549 | item_ref: Zir.Inst.Ref, |
| 13594 | 13550 | operand_ty: Type, |
| 13595 | | src_node_offset: i32, |
| 13596 | | switch_prong_src: Module.SwitchProngSrc, |
| 13551 | item_src: LazySrcLoc, |
| 13597 | 13552 | ) CompileError!Air.Inst.Ref { |
| 13598 | | const item = try sema.resolveSwitchItemVal(block, item_ref, operand_ty, src_node_offset, switch_prong_src, .none); |
| 13599 | | const maybe_prev_src = try range_set.add(item.val, item.val, switch_prong_src); |
| 13600 | | try sema.validateSwitchDupe(block, maybe_prev_src, switch_prong_src, src_node_offset); |
| 13553 | const item = try sema.resolveSwitchItemVal(block, item_ref, operand_ty, item_src); |
| 13554 | const maybe_prev_src = try range_set.add(item.val, item.val, item_src); |
| 13555 | try sema.validateSwitchDupe(block, maybe_prev_src, item_src); |
| 13601 | 13556 | return item.ref; |
| 13602 | 13557 | } |
| 13603 | 13558 | |
| 13604 | 13559 | fn validateSwitchItemEnum( |
| 13605 | 13560 | sema: *Sema, |
| 13606 | 13561 | block: *Block, |
| 13607 | | seen_fields: []?Module.SwitchProngSrc, |
| 13562 | seen_fields: []?LazySrcLoc, |
| 13608 | 13563 | range_set: *RangeSet, |
| 13609 | 13564 | item_ref: Zir.Inst.Ref, |
| 13610 | 13565 | operand_ty: Type, |
| 13611 | | src_node_offset: i32, |
| 13612 | | switch_prong_src: Module.SwitchProngSrc, |
| 13566 | item_src: LazySrcLoc, |
| 13613 | 13567 | ) CompileError!Air.Inst.Ref { |
| 13614 | 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 | 13570 | const int = ip.indexToKey(item.val).enum_tag.int; |
| 13617 | 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); |
| 13619 | | try sema.validateSwitchDupe(block, maybe_prev_src, switch_prong_src, src_node_offset); |
| 13572 | const maybe_prev_src = try range_set.add(int, int, item_src); |
| 13573 | try sema.validateSwitchDupe(block, maybe_prev_src, item_src); |
| 13620 | 13574 | return item.ref; |
| 13621 | 13575 | }; |
| 13622 | 13576 | const maybe_prev_src = seen_fields[field_index]; |
| 13623 | | seen_fields[field_index] = switch_prong_src; |
| 13624 | | try sema.validateSwitchDupe(block, maybe_prev_src, switch_prong_src, src_node_offset); |
| 13577 | seen_fields[field_index] = item_src; |
| 13578 | try sema.validateSwitchDupe(block, maybe_prev_src, item_src); |
| 13625 | 13579 | return item.ref; |
| 13626 | 13580 | } |
| 13627 | 13581 | |
| ... | ... | @@ -13631,50 +13585,41 @@ fn validateSwitchItemError( |
| 13631 | 13585 | seen_errors: *SwitchErrorSet, |
| 13632 | 13586 | item_ref: Zir.Inst.Ref, |
| 13633 | 13587 | operand_ty: Type, |
| 13634 | | src_node_offset: i32, |
| 13635 | | switch_prong_src: Module.SwitchProngSrc, |
| 13588 | item_src: LazySrcLoc, |
| 13636 | 13589 | ) CompileError!Air.Inst.Ref { |
| 13637 | 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 | 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 | 13594 | prev.value |
| 13642 | 13595 | else |
| 13643 | 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 | 13598 | return item.ref; |
| 13646 | 13599 | } |
| 13647 | 13600 | |
| 13648 | 13601 | fn validateSwitchDupe( |
| 13649 | 13602 | sema: *Sema, |
| 13650 | 13603 | block: *Block, |
| 13651 | | maybe_prev_src: ?Module.SwitchProngSrc, |
| 13652 | | switch_prong_src: Module.SwitchProngSrc, |
| 13653 | | src_node_offset: i32, |
| 13604 | maybe_prev_src: ?LazySrcLoc, |
| 13605 | item_src: LazySrcLoc, |
| 13654 | 13606 | ) CompileError!void { |
| 13655 | | const prev_prong_src = maybe_prev_src orelse return; |
| 13656 | | const mod = sema.mod; |
| 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: { |
| 13607 | const prev_item_src = maybe_prev_src orelse return; |
| 13608 | return sema.failWithOwnedErrorMsg(block, msg: { |
| 13661 | 13609 | const msg = try sema.errMsg( |
| 13662 | | block, |
| 13663 | | src, |
| 13610 | item_src, |
| 13664 | 13611 | "duplicate switch value", |
| 13665 | 13612 | .{}, |
| 13666 | 13613 | ); |
| 13667 | 13614 | errdefer msg.destroy(sema.gpa); |
| 13668 | 13615 | try sema.errNote( |
| 13669 | | block, |
| 13670 | | prev_src, |
| 13616 | prev_item_src, |
| 13671 | 13617 | msg, |
| 13672 | 13618 | "previous value here", |
| 13673 | 13619 | .{}, |
| 13674 | 13620 | ); |
| 13675 | 13621 | break :msg msg; |
| 13676 | | }; |
| 13677 | | return sema.failWithOwnedErrorMsg(block, msg); |
| 13622 | }); |
| 13678 | 13623 | } |
| 13679 | 13624 | |
| 13680 | 13625 | fn validateSwitchItemBool( |
| ... | ... | @@ -13683,25 +13628,21 @@ fn validateSwitchItemBool( |
| 13683 | 13628 | true_count: *u8, |
| 13684 | 13629 | false_count: *u8, |
| 13685 | 13630 | item_ref: Zir.Inst.Ref, |
| 13686 | | src_node_offset: i32, |
| 13687 | | switch_prong_src: Module.SwitchProngSrc, |
| 13631 | item_src: LazySrcLoc, |
| 13688 | 13632 | ) CompileError!Air.Inst.Ref { |
| 13689 | | const mod = sema.mod; |
| 13690 | | const item = try sema.resolveSwitchItemVal(block, item_ref, Type.bool, src_node_offset, switch_prong_src, .none); |
| 13633 | const item = try sema.resolveSwitchItemVal(block, item_ref, Type.bool, item_src); |
| 13691 | 13634 | if (Value.fromInterned(item.val).toBool()) { |
| 13692 | 13635 | true_count.* += 1; |
| 13693 | 13636 | } else { |
| 13694 | 13637 | false_count.* += 1; |
| 13695 | 13638 | } |
| 13696 | 13639 | if (true_count.* > 1 or false_count.* > 1) { |
| 13697 | | const block_src_decl = sema.mod.declPtr(block.src_decl); |
| 13698 | | const src = switch_prong_src.resolve(mod, block_src_decl, src_node_offset, .none); |
| 13699 | | return sema.fail(block, src, "duplicate switch value", .{}); |
| 13640 | return sema.fail(block, item_src, "duplicate switch value", .{}); |
| 13700 | 13641 | } |
| 13701 | 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 | 13647 | fn validateSwitchItemSparse( |
| 13707 | 13648 | sema: *Sema, |
| ... | ... | @@ -13709,12 +13650,11 @@ fn validateSwitchItemSparse( |
| 13709 | 13650 | seen_values: *ValueSrcMap, |
| 13710 | 13651 | item_ref: Zir.Inst.Ref, |
| 13711 | 13652 | operand_ty: Type, |
| 13712 | | src_node_offset: i32, |
| 13713 | | switch_prong_src: Module.SwitchProngSrc, |
| 13653 | item_src: LazySrcLoc, |
| 13714 | 13654 | ) CompileError!Air.Inst.Ref { |
| 13715 | | const item = try sema.resolveSwitchItemVal(block, item_ref, operand_ty, src_node_offset, switch_prong_src, .none); |
| 13716 | | const kv = (try seen_values.fetchPut(sema.gpa, item.val, switch_prong_src)) orelse return item.ref; |
| 13717 | | try sema.validateSwitchDupe(block, kv.value, switch_prong_src, src_node_offset); |
| 13655 | const item = try sema.resolveSwitchItemVal(block, item_ref, operand_ty, item_src); |
| 13656 | const kv = try seen_values.fetchPut(sema.gpa, item.val, item_src) orelse return item.ref; |
| 13657 | try sema.validateSwitchDupe(block, kv.value, item_src); |
| 13718 | 13658 | unreachable; |
| 13719 | 13659 | } |
| 13720 | 13660 | |
| ... | ... | @@ -13728,19 +13668,17 @@ fn validateSwitchNoRange( |
| 13728 | 13668 | if (ranges_len == 0) |
| 13729 | 13669 | return; |
| 13730 | 13670 | |
| 13731 | | const operand_src: LazySrcLoc = .{ .node_offset_switch_operand = src_node_offset }; |
| 13732 | | const range_src: LazySrcLoc = .{ .node_offset_switch_range = src_node_offset }; |
| 13671 | const operand_src = block.src(.{ .node_offset_switch_operand = src_node_offset }); |
| 13672 | const range_src = block.src(.{ .node_offset_switch_range = src_node_offset }); |
| 13733 | 13673 | |
| 13734 | 13674 | const msg = msg: { |
| 13735 | 13675 | const msg = try sema.errMsg( |
| 13736 | | block, |
| 13737 | 13676 | operand_src, |
| 13738 | 13677 | "ranges not allowed when switching on type '{}'", |
| 13739 | 13678 | .{operand_ty.fmt(sema.mod)}, |
| 13740 | 13679 | ); |
| 13741 | 13680 | errdefer msg.destroy(sema.gpa); |
| 13742 | 13681 | try sema.errNote( |
| 13743 | | block, |
| 13744 | 13682 | range_src, |
| 13745 | 13683 | msg, |
| 13746 | 13684 | "range here", |
| ... | ... | @@ -13867,8 +13805,8 @@ fn zirHasField(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 13867 | 13805 | const mod = sema.mod; |
| 13868 | 13806 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 13869 | 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 }; |
| 13871 | | const name_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; |
| 13808 | const ty_src = block.builtinCallArgSrc(inst_data.src_node, 0); |
| 13809 | const name_src = block.builtinCallArgSrc(inst_data.src_node, 1); |
| 13872 | 13810 | const ty = try sema.resolveType(block, ty_src, extra.lhs); |
| 13873 | 13811 | const field_name = try sema.resolveConstStringIntern(block, name_src, extra.rhs, .{ |
| 13874 | 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 | 13857 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 13920 | 13858 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 13921 | 13859 | const src = block.nodeOffset(inst_data.src_node); |
| 13922 | | const lhs_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 13923 | | const rhs_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; |
| 13860 | const lhs_src = block.builtinCallArgSrc(inst_data.src_node, 0); |
| 13861 | const rhs_src = block.builtinCallArgSrc(inst_data.src_node, 1); |
| 13924 | 13862 | const container_type = try sema.resolveType(block, lhs_src, extra.lhs); |
| 13925 | 13863 | const decl_name = try sema.resolveConstStringIntern(block, rhs_src, extra.rhs, .{ |
| 13926 | 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 | 13917 | |
| 13980 | 13918 | const mod = sema.mod; |
| 13981 | 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 | 13921 | const name = try sema.resolveConstString(block, operand_src, inst_data.operand, .{ |
| 13984 | 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 | 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); |
| 13992 | | const val = mod.embedFile(block.getFileScope(mod), name, src_loc) catch |err| switch (err) { |
| 13929 | const val = mod.embedFile(block.getFileScope(mod), name, operand_src.upgrade(mod)) catch |err| switch (err) { |
| 13993 | 13930 | error.ImportOutsideModulePath => { |
| 13994 | 13931 | return sema.fail(block, operand_src, "embed of file outside package path: '{s}'", .{name}); |
| 13995 | 13932 | }, |
| ... | ... | @@ -14031,8 +13968,8 @@ fn zirShl( |
| 14031 | 13968 | const mod = sema.mod; |
| 14032 | 13969 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 14033 | 13970 | const src = block.nodeOffset(inst_data.src_node); |
| 14034 | | const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node }; |
| 14035 | | const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node }; |
| 13971 | const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node }); |
| 13972 | const rhs_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node }); |
| 14036 | 13973 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 14037 | 13974 | const lhs = try sema.resolveInst(extra.lhs); |
| 14038 | 13975 | const rhs = try sema.resolveInst(extra.rhs); |
| ... | ... | @@ -14201,8 +14138,8 @@ fn zirShr( |
| 14201 | 14138 | const mod = sema.mod; |
| 14202 | 14139 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 14203 | 14140 | const src = block.nodeOffset(inst_data.src_node); |
| 14204 | | const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node }; |
| 14205 | | const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node }; |
| 14141 | const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node }); |
| 14142 | const rhs_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node }); |
| 14206 | 14143 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 14207 | 14144 | const lhs = try sema.resolveInst(extra.lhs); |
| 14208 | 14145 | const rhs = try sema.resolveInst(extra.rhs); |
| ... | ... | @@ -14335,9 +14272,9 @@ fn zirBitwise( |
| 14335 | 14272 | |
| 14336 | 14273 | const mod = sema.mod; |
| 14337 | 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 }; |
| 14339 | | const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node }; |
| 14340 | | const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node }; |
| 14275 | const src = block.src(.{ .node_offset_bin_op = inst_data.src_node }); |
| 14276 | const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node }); |
| 14277 | const rhs_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node }); |
| 14341 | 14278 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 14342 | 14279 | const lhs = try sema.resolveInst(extra.lhs); |
| 14343 | 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 | 14327 | const mod = sema.mod; |
| 14391 | 14328 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 14392 | 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 | 14332 | const operand = try sema.resolveInst(inst_data.operand); |
| 14396 | 14333 | const operand_type = sema.typeOf(operand); |
| ... | ... | @@ -14436,7 +14373,7 @@ fn analyzeTupleCat( |
| 14436 | 14373 | const mod = sema.mod; |
| 14437 | 14374 | const lhs_ty = sema.typeOf(lhs); |
| 14438 | 14375 | const rhs_ty = sema.typeOf(rhs); |
| 14439 | | const src = LazySrcLoc.nodeOffset(src_node); |
| 14376 | const src = block.nodeOffset(src_node); |
| 14440 | 14377 | |
| 14441 | 14378 | const lhs_len = lhs_ty.structFieldCount(mod); |
| 14442 | 14379 | const rhs_len = rhs_ty.structFieldCount(mod); |
| ... | ... | @@ -14463,10 +14400,10 @@ fn analyzeTupleCat( |
| 14463 | 14400 | types[i] = lhs_ty.structFieldType(i, mod).toIntern(); |
| 14464 | 14401 | const default_val = lhs_ty.structFieldDefaultValue(i, mod); |
| 14465 | 14402 | values[i] = default_val.toIntern(); |
| 14466 | | const operand_src: LazySrcLoc = .{ .array_cat_lhs = .{ |
| 14403 | const operand_src = block.src(.{ .array_cat_lhs = .{ |
| 14467 | 14404 | .array_cat_offset = src_node, |
| 14468 | 14405 | .elem_index = i, |
| 14469 | | } }; |
| 14406 | } }); |
| 14470 | 14407 | if (default_val.toIntern() == .unreachable_value) { |
| 14471 | 14408 | runtime_src = operand_src; |
| 14472 | 14409 | values[i] = .none; |
| ... | ... | @@ -14477,10 +14414,10 @@ fn analyzeTupleCat( |
| 14477 | 14414 | types[i + lhs_len] = rhs_ty.structFieldType(i, mod).toIntern(); |
| 14478 | 14415 | const default_val = rhs_ty.structFieldDefaultValue(i, mod); |
| 14479 | 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 | 14418 | .array_cat_offset = src_node, |
| 14482 | 14419 | .elem_index = i, |
| 14483 | | } }; |
| 14420 | } }); |
| 14484 | 14421 | if (default_val.toIntern() == .unreachable_value) { |
| 14485 | 14422 | runtime_src = operand_src; |
| 14486 | 14423 | values[i + lhs_len] = .none; |
| ... | ... | @@ -14508,18 +14445,18 @@ fn analyzeTupleCat( |
| 14508 | 14445 | const element_refs = try sema.arena.alloc(Air.Inst.Ref, final_len); |
| 14509 | 14446 | var i: u32 = 0; |
| 14510 | 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 | 14449 | .array_cat_offset = src_node, |
| 14513 | 14450 | .elem_index = i, |
| 14514 | | } }; |
| 14451 | } }); |
| 14515 | 14452 | element_refs[i] = try sema.tupleFieldValByIndex(block, operand_src, lhs, i, lhs_ty); |
| 14516 | 14453 | } |
| 14517 | 14454 | i = 0; |
| 14518 | 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 | 14457 | .array_cat_offset = src_node, |
| 14521 | 14458 | .elem_index = i, |
| 14522 | | } }; |
| 14459 | } }); |
| 14523 | 14460 | element_refs[i + lhs_len] = |
| 14524 | 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 | 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 }; |
| 14550 | | const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node }; |
| 14486 | const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node }); |
| 14487 | const rhs_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node }); |
| 14551 | 14488 | |
| 14552 | 14489 | const lhs_info = try sema.getArrayCatInfo(block, lhs_src, lhs, rhs_ty) orelse lhs_info: { |
| 14553 | 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 | 14596 | const elem_default_val = if (lhs_is_tuple) lhs_ty.structFieldDefaultValue(lhs_elem_i, mod) else Value.@"unreachable"; |
| 14660 | 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 | 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 | 14600 | .array_cat_offset = inst_data.src_node, |
| 14664 | 14601 | .elem_index = elem_i, |
| 14665 | | } }; |
| 14602 | } }); |
| 14666 | 14603 | const coerced_elem_val_inst = try sema.coerce(block, resolved_elem_ty, elem_val_inst, operand_src); |
| 14667 | 14604 | const coerced_elem_val = try sema.resolveConstValue(block, operand_src, coerced_elem_val_inst, undefined); |
| 14668 | 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 | 14609 | const elem_default_val = if (rhs_is_tuple) rhs_ty.structFieldDefaultValue(rhs_elem_i, mod) else Value.@"unreachable"; |
| 14673 | 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 | 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 | 14613 | .array_cat_offset = inst_data.src_node, |
| 14677 | 14614 | .elem_index = @intCast(rhs_elem_i), |
| 14678 | | } }; |
| 14615 | } }); |
| 14679 | 14616 | const coerced_elem_val_inst = try sema.coerce(block, resolved_elem_ty, elem_val_inst, operand_src); |
| 14680 | 14617 | const coerced_elem_val = try sema.resolveConstValue(block, operand_src, coerced_elem_val_inst, undefined); |
| 14681 | 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 | 14641 | while (elem_i < lhs_len) : (elem_i += 1) { |
| 14705 | 14642 | const elem_index = try mod.intRef(Type.usize, elem_i); |
| 14706 | 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 | 14645 | .array_cat_offset = inst_data.src_node, |
| 14709 | 14646 | .elem_index = elem_i, |
| 14710 | | } }; |
| 14647 | } }); |
| 14711 | 14648 | const init = try sema.elemVal(block, operand_src, lhs, elem_index, src, true); |
| 14712 | 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 | 14653 | const elem_index = try mod.intRef(Type.usize, elem_i); |
| 14717 | 14654 | const rhs_index = try mod.intRef(Type.usize, rhs_elem_i); |
| 14718 | 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 | 14657 | .array_cat_offset = inst_data.src_node, |
| 14721 | 14658 | .elem_index = @intCast(rhs_elem_i), |
| 14722 | | } }; |
| 14659 | } }); |
| 14723 | 14660 | const init = try sema.elemVal(block, operand_src, rhs, rhs_index, src, true); |
| 14724 | 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 | 14675 | var elem_i: u32 = 0; |
| 14739 | 14676 | while (elem_i < lhs_len) : (elem_i += 1) { |
| 14740 | 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 | 14679 | .array_cat_offset = inst_data.src_node, |
| 14743 | 14680 | .elem_index = elem_i, |
| 14744 | | } }; |
| 14681 | } }); |
| 14745 | 14682 | const init = try sema.elemVal(block, operand_src, lhs, index, src, true); |
| 14746 | 14683 | element_refs[elem_i] = try sema.coerce(block, resolved_elem_ty, init, operand_src); |
| 14747 | 14684 | } |
| 14748 | 14685 | while (elem_i < result_len) : (elem_i += 1) { |
| 14749 | 14686 | const rhs_elem_i = elem_i - lhs_len; |
| 14750 | 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 | 14689 | .array_cat_offset = inst_data.src_node, |
| 14753 | 14690 | .elem_index = @intCast(rhs_elem_i), |
| 14754 | | } }; |
| 14691 | } }); |
| 14755 | 14692 | const init = try sema.elemVal(block, operand_src, rhs, index, src, true); |
| 14756 | 14693 | element_refs[elem_i] = try sema.coerce(block, resolved_elem_ty, init, operand_src); |
| 14757 | 14694 | } |
| ... | ... | @@ -14813,8 +14750,8 @@ fn analyzeTupleMul( |
| 14813 | 14750 | ) CompileError!Air.Inst.Ref { |
| 14814 | 14751 | const mod = sema.mod; |
| 14815 | 14752 | const operand_ty = sema.typeOf(operand); |
| 14816 | | const src = LazySrcLoc.nodeOffset(src_node); |
| 14817 | | const len_src: LazySrcLoc = .{ .node_offset_bin_rhs = src_node }; |
| 14753 | const src = block.nodeOffset(src_node); |
| 14754 | const len_src = block.src(.{ .node_offset_bin_rhs = src_node }); |
| 14818 | 14755 | |
| 14819 | 14756 | const tuple_len = operand_ty.structFieldCount(mod); |
| 14820 | 14757 | const final_len = std.math.mul(usize, tuple_len, factor) catch |
| ... | ... | @@ -14831,10 +14768,10 @@ fn analyzeTupleMul( |
| 14831 | 14768 | for (0..tuple_len) |i| { |
| 14832 | 14769 | types[i] = operand_ty.structFieldType(i, mod).toIntern(); |
| 14833 | 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 | 14772 | .array_cat_offset = src_node, |
| 14836 | 14773 | .elem_index = @intCast(i), |
| 14837 | | } }; |
| 14774 | } }); |
| 14838 | 14775 | if (values[i] == .unreachable_value) { |
| 14839 | 14776 | runtime_src = operand_src; |
| 14840 | 14777 | values[i] = .none; // TODO don't treat unreachable_value as special |
| ... | ... | @@ -14866,10 +14803,10 @@ fn analyzeTupleMul( |
| 14866 | 14803 | const element_refs = try sema.arena.alloc(Air.Inst.Ref, final_len); |
| 14867 | 14804 | var i: u32 = 0; |
| 14868 | 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 | 14807 | .array_cat_offset = src_node, |
| 14871 | 14808 | .elem_index = i, |
| 14872 | | } }; |
| 14809 | } }); |
| 14873 | 14810 | element_refs[i] = try sema.tupleFieldValByIndex(block, operand_src, operand, @intCast(i), operand_ty); |
| 14874 | 14811 | } |
| 14875 | 14812 | i = 1; |
| ... | ... | @@ -14890,9 +14827,9 @@ fn zirArrayMul(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 14890 | 14827 | const uncoerced_lhs = try sema.resolveInst(extra.lhs); |
| 14891 | 14828 | const uncoerced_lhs_ty = sema.typeOf(uncoerced_lhs); |
| 14892 | 14829 | const src: LazySrcLoc = block.nodeOffset(inst_data.src_node); |
| 14893 | | const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node }; |
| 14894 | | const operator_src: LazySrcLoc = .{ .node_offset_main_token = inst_data.src_node }; |
| 14895 | | const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node }; |
| 14830 | const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node }); |
| 14831 | const operator_src = block.src(.{ .node_offset_main_token = inst_data.src_node }); |
| 14832 | const rhs_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node }); |
| 14896 | 14833 | |
| 14897 | 14834 | const lhs, const lhs_ty = coerced_lhs: { |
| 14898 | 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 | 14878 | // Analyze the lhs first, to catch the case that someone tried to do exponentiation |
| 14942 | 14879 | const lhs_info = try sema.getArrayCatInfo(block, lhs_src, lhs, lhs_ty) orelse { |
| 14943 | 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 | 14882 | errdefer msg.destroy(sema.gpa); |
| 14946 | 14883 | switch (lhs_ty.zigTypeTag(mod)) { |
| 14947 | 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 | 14887 | else => {}, |
| 14951 | 14888 | } |
| ... | ... | @@ -15061,7 +14998,7 @@ fn zirNegate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. |
| 15061 | 14998 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 15062 | 14999 | const src = block.nodeOffset(inst_data.src_node); |
| 15063 | 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 | 15003 | const rhs = try sema.resolveInst(inst_data.operand); |
| 15067 | 15004 | const rhs_ty = sema.typeOf(rhs); |
| ... | ... | @@ -15093,7 +15030,7 @@ fn zirNegateWrap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! |
| 15093 | 15030 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 15094 | 15031 | const src = block.nodeOffset(inst_data.src_node); |
| 15095 | 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 | 15035 | const rhs = try sema.resolveInst(inst_data.operand); |
| 15099 | 15036 | const rhs_ty = sema.typeOf(rhs); |
| ... | ... | @@ -15119,9 +15056,9 @@ fn zirArithmetic( |
| 15119 | 15056 | defer tracy.end(); |
| 15120 | 15057 | |
| 15121 | 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 }; |
| 15123 | | const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node }; |
| 15124 | | const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node }; |
| 15059 | const src = block.src(.{ .node_offset_bin_op = inst_data.src_node }); |
| 15060 | const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node }); |
| 15061 | const rhs_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node }); |
| 15125 | 15062 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 15126 | 15063 | const lhs = try sema.resolveInst(extra.lhs); |
| 15127 | 15064 | const rhs = try sema.resolveInst(extra.rhs); |
| ... | ... | @@ -15132,9 +15069,9 @@ fn zirArithmetic( |
| 15132 | 15069 | fn zirDiv(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 15133 | 15070 | const mod = sema.mod; |
| 15134 | 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 }; |
| 15136 | | const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node }; |
| 15137 | | const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node }; |
| 15072 | const src = block.src(.{ .node_offset_bin_op = inst_data.src_node }); |
| 15073 | const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node }); |
| 15074 | const rhs_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node }); |
| 15138 | 15075 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 15139 | 15076 | const lhs = try sema.resolveInst(extra.lhs); |
| 15140 | 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 | 15234 | fn zirDivExact(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 15298 | 15235 | const mod = sema.mod; |
| 15299 | 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 }; |
| 15301 | | const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node }; |
| 15302 | | const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node }; |
| 15237 | const src = block.src(.{ .node_offset_bin_op = inst_data.src_node }); |
| 15238 | const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node }); |
| 15239 | const rhs_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node }); |
| 15303 | 15240 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 15304 | 15241 | const lhs = try sema.resolveInst(extra.lhs); |
| 15305 | 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 | 15399 | fn zirDivFloor(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 15463 | 15400 | const mod = sema.mod; |
| 15464 | 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 }; |
| 15466 | | const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node }; |
| 15467 | | const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node }; |
| 15402 | const src = block.src(.{ .node_offset_bin_op = inst_data.src_node }); |
| 15403 | const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node }); |
| 15404 | const rhs_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node }); |
| 15468 | 15405 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 15469 | 15406 | const lhs = try sema.resolveInst(extra.lhs); |
| 15470 | 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 | 15509 | fn zirDivTrunc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 15573 | 15510 | const mod = sema.mod; |
| 15574 | 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 }; |
| 15576 | | const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node }; |
| 15577 | | const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node }; |
| 15512 | const src = block.src(.{ .node_offset_bin_op = inst_data.src_node }); |
| 15513 | const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node }); |
| 15514 | const rhs_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node }); |
| 15578 | 15515 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 15579 | 15516 | const lhs = try sema.resolveInst(extra.lhs); |
| 15580 | 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 | 15750 | fn zirModRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 15814 | 15751 | const mod = sema.mod; |
| 15815 | 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 }; |
| 15817 | | const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node }; |
| 15818 | | const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node }; |
| 15753 | const src = block.src(.{ .node_offset_bin_op = inst_data.src_node }); |
| 15754 | const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node }); |
| 15755 | const rhs_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node }); |
| 15819 | 15756 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 15820 | 15757 | const lhs = try sema.resolveInst(extra.lhs); |
| 15821 | 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 | 15934 | fn zirMod(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 15998 | 15935 | const mod = sema.mod; |
| 15999 | 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 }; |
| 16001 | | const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node }; |
| 16002 | | const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node }; |
| 15937 | const src = block.src(.{ .node_offset_bin_op = inst_data.src_node }); |
| 15938 | const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node }); |
| 15939 | const rhs_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node }); |
| 16003 | 15940 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 16004 | 15941 | const lhs = try sema.resolveInst(extra.lhs); |
| 16005 | 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 | 16029 | fn zirRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 16093 | 16030 | const mod = sema.mod; |
| 16094 | 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 }; |
| 16096 | | const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node }; |
| 16097 | | const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node }; |
| 16032 | const src = block.src(.{ .node_offset_bin_op = inst_data.src_node }); |
| 16033 | const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node }); |
| 16034 | const rhs_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node }); |
| 16098 | 16035 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 16099 | 16036 | const lhs = try sema.resolveInst(extra.lhs); |
| 16100 | 16037 | const rhs = try sema.resolveInst(extra.rhs); |
| ... | ... | @@ -16194,10 +16131,10 @@ fn zirOverflowArithmetic( |
| 16194 | 16131 | defer tracy.end(); |
| 16195 | 16132 | |
| 16196 | 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 }; |
| 16200 | | const rhs_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = extra.node }; |
| 16136 | const lhs_src = block.builtinCallArgSrc(extra.node, 0); |
| 16137 | const rhs_src = block.builtinCallArgSrc(extra.node, 1); |
| 16201 | 16138 | |
| 16202 | 16139 | const uncasted_lhs = try sema.resolveInst(extra.lhs); |
| 16203 | 16140 | const uncasted_rhs = try sema.resolveInst(extra.rhs); |
| ... | ... | @@ -17025,8 +16962,8 @@ fn zirAsm( |
| 17025 | 16962 | defer tracy.end(); |
| 17026 | 16963 | |
| 17027 | 16964 | const extra = sema.code.extraData(Zir.Inst.Asm, extended.operand); |
| 17028 | | const src = LazySrcLoc.nodeOffset(extra.data.src_node); |
| 17029 | | const ret_ty_src: LazySrcLoc = .{ .node_offset_asm_ret_ty = extra.data.src_node }; |
| 16965 | const src = block.nodeOffset(extra.data.src_node); |
| 16966 | const ret_ty_src = block.src(.{ .node_offset_asm_ret_ty = extra.data.src_node }); |
| 17030 | 16967 | const outputs_len: u5 = @truncate(extended.small); |
| 17031 | 16968 | const inputs_len: u5 = @truncate(extended.small >> 5); |
| 17032 | 16969 | const clobbers_len: u5 = @truncate(extended.small >> 10); |
| ... | ... | @@ -17200,8 +17137,8 @@ fn zirCmpEq( |
| 17200 | 17137 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 17201 | 17138 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 17202 | 17139 | const src: LazySrcLoc = block.nodeOffset(inst_data.src_node); |
| 17203 | | const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node }; |
| 17204 | | const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node }; |
| 17140 | const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node }); |
| 17141 | const rhs_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node }); |
| 17205 | 17142 | const lhs = try sema.resolveInst(extra.lhs); |
| 17206 | 17143 | const rhs = try sema.resolveInst(extra.rhs); |
| 17207 | 17144 | |
| ... | ... | @@ -17280,9 +17217,9 @@ fn analyzeCmpUnionTag( |
| 17280 | 17217 | try sema.resolveTypeFields(union_ty); |
| 17281 | 17218 | const union_tag_ty = union_ty.unionTagType(mod) orelse { |
| 17282 | 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 | 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 | 17223 | break :msg msg; |
| 17287 | 17224 | }; |
| 17288 | 17225 | return sema.failWithOwnedErrorMsg(block, msg); |
| ... | ... | @@ -17316,8 +17253,8 @@ fn zirCmp( |
| 17316 | 17253 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 17317 | 17254 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 17318 | 17255 | const src: LazySrcLoc = block.nodeOffset(inst_data.src_node); |
| 17319 | | const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node }; |
| 17320 | | const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node }; |
| 17256 | const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node }); |
| 17257 | const rhs_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node }); |
| 17321 | 17258 | const lhs = try sema.resolveInst(extra.lhs); |
| 17322 | 17259 | const rhs = try sema.resolveInst(extra.rhs); |
| 17323 | 17260 | return sema.analyzeCmp(block, src, lhs, rhs, op, lhs_src, rhs_src, false); |
| ... | ... | @@ -17459,7 +17396,7 @@ fn runtimeBoolCmp( |
| 17459 | 17396 | fn zirSizeOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 17460 | 17397 | const mod = sema.mod; |
| 17461 | 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 | 17400 | const ty = try sema.resolveType(block, operand_src, inst_data.operand); |
| 17464 | 17401 | switch (ty.zigTypeTag(mod)) { |
| 17465 | 17402 | .Fn, |
| ... | ... | @@ -17502,7 +17439,7 @@ fn zirSizeOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. |
| 17502 | 17439 | fn zirBitSizeOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 17503 | 17440 | const mod = sema.mod; |
| 17504 | 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 | 17443 | const operand_ty = try sema.resolveType(block, operand_src, inst_data.operand); |
| 17507 | 17444 | switch (operand_ty.zigTypeTag(mod)) { |
| 17508 | 17445 | .Fn, |
| ... | ... | @@ -17546,7 +17483,7 @@ fn zirThis( |
| 17546 | 17483 | ) CompileError!Air.Inst.Ref { |
| 17547 | 17484 | const mod = sema.mod; |
| 17548 | 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 | 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 | 17493 | const captures = mod.namespacePtr(block.namespace).getType(mod).getCaptures(mod); |
| 17557 | 17494 | |
| 17558 | 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 | 17498 | const capture_ty = switch (captures.get(ip)[extended.small].unwrap()) { |
| 17562 | 17499 | .@"comptime" => |index| return Air.internedToRef(index), |
| ... | ... | @@ -17570,7 +17507,8 @@ fn zirClosureGet(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat |
| 17570 | 17507 | if (!block.is_typeof and sema.func_index == .none) { |
| 17571 | 17508 | const msg = msg: { |
| 17572 | 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 | 17512 | const tree = file.getTree(sema.gpa) catch |err| { |
| 17575 | 17513 | // In this case we emit a warning + a less precise source location. |
| 17576 | 17514 | log.warn("unable to load {s}: {s}", .{ |
| ... | ... | @@ -17578,15 +17516,15 @@ fn zirClosureGet(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat |
| 17578 | 17516 | }); |
| 17579 | 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 | 17520 | const token = tree.nodes.items(.main_token)[node]; |
| 17583 | 17521 | break :name tree.tokenSlice(token); |
| 17584 | 17522 | }; |
| 17585 | 17523 | |
| 17586 | 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 | 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 | 17528 | errdefer msg.destroy(sema.gpa); |
| 17591 | 17529 | |
| 17592 | 17530 | // TODO add "declared here" note |
| ... | ... | @@ -17598,7 +17536,7 @@ fn zirClosureGet(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat |
| 17598 | 17536 | if (!block.is_typeof and !block.is_comptime and sema.func_index != .none) { |
| 17599 | 17537 | const msg = msg: { |
| 17600 | 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 | 17540 | const tree = file.getTree(sema.gpa) catch |err| { |
| 17603 | 17541 | // In this case we emit a warning + a less precise source location. |
| 17604 | 17542 | log.warn("unable to load {s}: {s}", .{ |
| ... | ... | @@ -17606,18 +17544,18 @@ fn zirClosureGet(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat |
| 17606 | 17544 | }); |
| 17607 | 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 | 17548 | const token = tree.nodes.items(.main_token)[node]; |
| 17611 | 17549 | break :name tree.tokenSlice(token); |
| 17612 | 17550 | }; |
| 17613 | 17551 | |
| 17614 | 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 | 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 | 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 | 17560 | // TODO add "declared here" note |
| 17623 | 17561 | break :msg msg; |
| ... | ... | @@ -17649,7 +17587,7 @@ fn zirFrameAddress( |
| 17649 | 17587 | block: *Block, |
| 17650 | 17588 | extended: Zir.Inst.Extended.InstData, |
| 17651 | 17589 | ) CompileError!Air.Inst.Ref { |
| 17652 | | const src = LazySrcLoc.nodeOffset(@bitCast(extended.operand)); |
| 17590 | const src = block.nodeOffset(@bitCast(extended.operand)); |
| 17653 | 17591 | try sema.requireRuntimeBlock(block, src, null); |
| 17654 | 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 | 18851 | .is_typeof = true, |
| 18914 | 18852 | .want_safety = false, |
| 18915 | 18853 | .error_return_trace_index = block.error_return_trace_index, |
| 18854 | .src_base_inst = block.src_base_inst, |
| 18916 | 18855 | }; |
| 18917 | 18856 | defer child_block.instructions.deinit(sema.gpa); |
| 18918 | 18857 | |
| ... | ... | @@ -18977,7 +18916,7 @@ fn zirTypeofPeer( |
| 18977 | 18916 | defer tracy.end(); |
| 18978 | 18917 | |
| 18979 | 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 | 18920 | const body = sema.code.bodySlice(extra.data.body_index, extra.data.body_len); |
| 18982 | 18921 | |
| 18983 | 18922 | var child_block: Block = .{ |
| ... | ... | @@ -18992,6 +18931,7 @@ fn zirTypeofPeer( |
| 18992 | 18931 | .runtime_cond = block.runtime_cond, |
| 18993 | 18932 | .runtime_loop = block.runtime_loop, |
| 18994 | 18933 | .runtime_index = block.runtime_index, |
| 18934 | .src_base_inst = block.src_base_inst, |
| 18995 | 18935 | }; |
| 18996 | 18936 | defer child_block.instructions.deinit(sema.gpa); |
| 18997 | 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 | 18957 | const mod = sema.mod; |
| 19018 | 18958 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 19019 | 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 | 18961 | const uncasted_operand = try sema.resolveInst(inst_data.operand); |
| 19022 | 18962 | |
| 19023 | 18963 | const operand = try sema.coerce(block, Type.bool, uncasted_operand, operand_src); |
| ... | ... | @@ -19048,8 +18988,8 @@ fn zirBoolBr( |
| 19048 | 18988 | |
| 19049 | 18989 | const uncoerced_lhs = try sema.resolveInst(extra.data.lhs); |
| 19050 | 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 }; |
| 19052 | | const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node }; |
| 18991 | const lhs_src = parent_block.src(.{ .node_offset_bin_lhs = inst_data.src_node }); |
| 18992 | const rhs_src = parent_block.src(.{ .node_offset_bin_rhs = inst_data.src_node }); |
| 19053 | 18993 | |
| 19054 | 18994 | const lhs = try sema.coerce(parent_block, Type.bool, uncoerced_lhs, lhs_src); |
| 19055 | 18995 | |
| ... | ... | @@ -19080,7 +19020,7 @@ fn zirBoolBr( |
| 19080 | 19020 | |
| 19081 | 19021 | var child_block = parent_block.makeSubBlock(); |
| 19082 | 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 | 19024 | child_block.runtime_index.increment(); |
| 19085 | 19025 | defer child_block.instructions.deinit(gpa); |
| 19086 | 19026 | |
| ... | ... | @@ -19253,7 +19193,7 @@ fn zirCondbr( |
| 19253 | 19193 | |
| 19254 | 19194 | const mod = sema.mod; |
| 19255 | 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 | 19197 | const extra = sema.code.extraData(Zir.Inst.CondBr, inst_data.payload_index); |
| 19258 | 19198 | |
| 19259 | 19199 | const then_body = sema.code.bodySlice(extra.end, extra.data.then_body_len); |
| ... | ... | @@ -19276,7 +19216,7 @@ fn zirCondbr( |
| 19276 | 19216 | // instructions array in between using it for the then block and else block. |
| 19277 | 19217 | var sub_block = parent_block.makeSubBlock(); |
| 19278 | 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 | 19220 | sub_block.runtime_index.increment(); |
| 19281 | 19221 | sub_block.need_debug_scope = null; // this body is emitted regardless |
| 19282 | 19222 | defer sub_block.instructions.deinit(gpa); |
| ... | ... | @@ -19321,7 +19261,7 @@ fn zirCondbr( |
| 19321 | 19261 | fn zirTry(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 19322 | 19262 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 19323 | 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 | 19265 | const extra = sema.code.extraData(Zir.Inst.Try, inst_data.payload_index); |
| 19326 | 19266 | const body = sema.code.bodySlice(extra.end, extra.data.body_len); |
| 19327 | 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 | 19308 | fn zirTryPtr(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 19369 | 19309 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 19370 | 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 | 19312 | const extra = sema.code.extraData(Zir.Inst.Try, inst_data.payload_index); |
| 19373 | 19313 | const body = sema.code.bodySlice(extra.end, extra.data.body_len); |
| 19374 | 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 | 19404 | .label = &labeled_block.label, |
| 19465 | 19405 | .inlining = block.inlining, |
| 19466 | 19406 | .is_comptime = block.is_comptime, |
| 19407 | .src_base_inst = block.src_base_inst, |
| 19467 | 19408 | }, |
| 19468 | 19409 | }; |
| 19469 | 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 | 19439 | return sema.fail(block, src, "reached unreachable code", .{}); |
| 19499 | 19440 | } |
| 19500 | 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 | 19443 | error.AnalysisFail => { |
| 19503 | 19444 | const msg = sema.err orelse return err; |
| 19504 | 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 | 19447 | return err; |
| 19507 | 19448 | }, |
| 19508 | 19449 | else => |e| return e, |
| ... | ... | @@ -19549,31 +19490,31 @@ fn zirRetImplicit( |
| 19549 | 19490 | // Calling a safety function from a naked function would not be legal. |
| 19550 | 19491 | _ = try block.addNoOp(.trap); |
| 19551 | 19492 | } else { |
| 19552 | | try block.addUnreachable(r_brace_src, false); |
| 19493 | try sema.analyzeUnreachable(block, r_brace_src, false); |
| 19553 | 19494 | } |
| 19554 | 19495 | return; |
| 19555 | 19496 | } |
| 19556 | 19497 | |
| 19557 | 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 | 19500 | const base_tag = sema.fn_ret_ty.baseZigTypeTag(mod); |
| 19560 | 19501 | if (base_tag == .NoReturn) { |
| 19561 | 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 | 19504 | sema.fn_ret_ty.fmt(mod), |
| 19564 | 19505 | }); |
| 19565 | 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 | 19508 | break :msg msg; |
| 19568 | 19509 | }; |
| 19569 | 19510 | return sema.failWithOwnedErrorMsg(block, msg); |
| 19570 | 19511 | } else if (base_tag != .Void) { |
| 19571 | 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 | 19514 | sema.fn_ret_ty.fmt(mod), |
| 19574 | 19515 | }); |
| 19575 | 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 | 19518 | break :msg msg; |
| 19578 | 19519 | }; |
| 19579 | 19520 | return sema.failWithOwnedErrorMsg(block, msg); |
| ... | ... | @@ -19590,7 +19531,7 @@ fn zirRetNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!voi |
| 19590 | 19531 | const operand = try sema.resolveInst(inst_data.operand); |
| 19591 | 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 | 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 | 19544 | |
| 19604 | 19545 | if (block.is_comptime or block.inlining != null or sema.func_is_naked) { |
| 19605 | 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 | 19550 | if (sema.wantErrorReturnTracing(sema.fn_ret_ty)) { |
| ... | ... | @@ -19816,9 +19757,7 @@ fn analyzeRet( |
| 19816 | 19757 | inlining.comptime_result = operand; |
| 19817 | 19758 | |
| 19818 | 19759 | if (sema.fn_ret_ty.isError(mod) and ret_val.getErrorName(mod) != .none) { |
| 19819 | | const src_decl = mod.declPtr(block.src_decl); |
| 19820 | | const src_loc = src_decl.toSrcLoc(src, mod); |
| 19821 | | try sema.comptime_err_ret_trace.append(src_loc); |
| 19760 | try sema.comptime_err_ret_trace.append(src); |
| 19822 | 19761 | } |
| 19823 | 19762 | return error.ComptimeReturn; |
| 19824 | 19763 | } |
| ... | ... | @@ -19832,10 +19771,10 @@ fn analyzeRet( |
| 19832 | 19771 | return sema.fail(block, src, "function called at runtime cannot return value at comptime", .{}); |
| 19833 | 19772 | } else if (sema.func_is_naked) { |
| 19834 | 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 | 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 | 19778 | break :msg msg; |
| 19840 | 19779 | }; |
| 19841 | 19780 | return sema.failWithOwnedErrorMsg(block, msg); |
| ... | ... | @@ -19871,18 +19810,18 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 19871 | 19810 | const mod = sema.mod; |
| 19872 | 19811 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].ptr_type; |
| 19873 | 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 }; |
| 19875 | | const sentinel_src: LazySrcLoc = .{ .node_offset_ptr_sentinel = extra.data.src_node }; |
| 19876 | | const align_src: LazySrcLoc = .{ .node_offset_ptr_align = extra.data.src_node }; |
| 19877 | | const addrspace_src: LazySrcLoc = .{ .node_offset_ptr_addrspace = extra.data.src_node }; |
| 19878 | | const bitoffset_src: LazySrcLoc = .{ .node_offset_ptr_bitoffset = extra.data.src_node }; |
| 19879 | | const hostsize_src: LazySrcLoc = .{ .node_offset_ptr_hostsize = extra.data.src_node }; |
| 19813 | const elem_ty_src = block.src(.{ .node_offset_ptr_elem = extra.data.src_node }); |
| 19814 | const sentinel_src = block.src(.{ .node_offset_ptr_sentinel = extra.data.src_node }); |
| 19815 | const align_src = block.src(.{ .node_offset_ptr_align = extra.data.src_node }); |
| 19816 | const addrspace_src = block.src(.{ .node_offset_ptr_addrspace = extra.data.src_node }); |
| 19817 | const bitoffset_src = block.src(.{ .node_offset_ptr_bitoffset = extra.data.src_node }); |
| 19818 | const hostsize_src = block.src(.{ .node_offset_ptr_hostsize = extra.data.src_node }); |
| 19880 | 19819 | |
| 19881 | 19820 | const elem_ty = blk: { |
| 19882 | 19821 | const air_inst = try sema.resolveInst(extra.data.elem_type); |
| 19883 | 19822 | const ty = sema.analyzeAsType(block, elem_ty_src, air_inst) catch |err| { |
| 19884 | 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 | 19826 | return err; |
| 19888 | 19827 | }; |
| ... | ... | @@ -19974,11 +19913,10 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 19974 | 19913 | } else if (inst_data.size == .C) { |
| 19975 | 19914 | if (!try sema.validateExternType(elem_ty, .other)) { |
| 19976 | 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 | 19917 | errdefer msg.destroy(sema.gpa); |
| 19979 | 19918 | |
| 19980 | | const src_decl = mod.declPtr(block.src_decl); |
| 19981 | | try sema.explainWhyTypeIsNotExtern(msg, src_decl.toSrcLoc(elem_ty_src, mod), elem_ty, .other); |
| 19919 | try sema.explainWhyTypeIsNotExtern(msg, elem_ty_src, elem_ty, .other); |
| 19982 | 19920 | |
| 19983 | 19921 | try sema.addDeclaredHereNote(msg, elem_ty); |
| 19984 | 19922 | break :msg msg; |
| ... | ... | @@ -19992,10 +19930,9 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 19992 | 19930 | |
| 19993 | 19931 | if (host_size != 0 and !try sema.validatePackedType(elem_ty)) { |
| 19994 | 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 | 19934 | errdefer msg.destroy(sema.gpa); |
| 19997 | | const src_decl = mod.declPtr(block.src_decl); |
| 19998 | | try sema.explainWhyTypeIsNotPacked(msg, src_decl.toSrcLoc(elem_ty_src, mod), elem_ty); |
| 19935 | try sema.explainWhyTypeIsNotPacked(msg, elem_ty_src, elem_ty); |
| 19999 | 19936 | break :msg msg; |
| 20000 | 19937 | }); |
| 20001 | 19938 | } |
| ... | ... | @@ -20025,7 +19962,7 @@ fn zirStructInitEmpty(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE |
| 20025 | 19962 | |
| 20026 | 19963 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 20027 | 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 | 19966 | const obj_ty = try sema.resolveType(block, ty_src, inst_data.operand); |
| 20030 | 19967 | const mod = sema.mod; |
| 20031 | 19968 | |
| ... | ... | @@ -20119,9 +20056,9 @@ fn arrayInitEmpty(sema: *Sema, block: *Block, src: LazySrcLoc, obj_ty: Type) Com |
| 20119 | 20056 | |
| 20120 | 20057 | fn zirUnionInit(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 20121 | 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 }; |
| 20123 | | const field_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; |
| 20124 | | const init_src: LazySrcLoc = .{ .node_offset_builtin_call_arg2 = inst_data.src_node }; |
| 20059 | const ty_src = block.builtinCallArgSrc(inst_data.src_node, 0); |
| 20060 | const field_src = block.builtinCallArgSrc(inst_data.src_node, 1); |
| 20061 | const init_src = block.builtinCallArgSrc(inst_data.src_node, 2); |
| 20125 | 20062 | const extra = sema.code.extraData(Zir.Inst.UnionInit, inst_data.payload_index).data; |
| 20126 | 20063 | const union_ty = try sema.resolveType(block, ty_src, extra.union_type); |
| 20127 | 20064 | if (union_ty.zigTypeTag(sema.mod) != .Union) { |
| ... | ... | @@ -20215,7 +20152,7 @@ fn zirStructInit( |
| 20215 | 20152 | extra_index = item.end; |
| 20216 | 20153 | |
| 20217 | 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 | 20156 | const field_type_extra = sema.code.extraData(Zir.Inst.FieldType, field_type_data.payload_index).data; |
| 20220 | 20157 | const field_name = try ip.getOrPutString( |
| 20221 | 20158 | gpa, |
| ... | ... | @@ -20256,7 +20193,7 @@ fn zirStructInit( |
| 20256 | 20193 | const item = sema.code.extraData(Zir.Inst.StructInit.Item, extra.end); |
| 20257 | 20194 | |
| 20258 | 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 | 20197 | const field_type_extra = sema.code.extraData(Zir.Inst.FieldType, field_type_data.payload_index).data; |
| 20261 | 20198 | const field_name = try ip.getOrPutString( |
| 20262 | 20199 | gpa, |
| ... | ... | @@ -20270,7 +20207,7 @@ fn zirStructInit( |
| 20270 | 20207 | |
| 20271 | 20208 | if (field_ty.zigTypeTag(mod) == .NoReturn) { |
| 20272 | 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 | 20211 | errdefer msg.destroy(sema.gpa); |
| 20275 | 20212 | |
| 20276 | 20213 | try sema.addFieldErrNote(resolved_ty, field_index, msg, "field '{}' declared here", .{ |
| ... | ... | @@ -20348,16 +20285,12 @@ fn finishStructInit( |
| 20348 | 20285 | for (0..anon_struct.types.len) |i| { |
| 20349 | 20286 | if (field_inits[i] != .none) { |
| 20350 | 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 | 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) { |
| 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 | | }; |
| 20293 | field_inits[i] = try sema.coerce(block, field_ty, field_inits[i], field_src); |
| 20361 | 20294 | continue; |
| 20362 | 20295 | } |
| 20363 | 20296 | |
| ... | ... | @@ -20367,18 +20300,18 @@ fn finishStructInit( |
| 20367 | 20300 | if (anon_struct.names.len == 0) { |
| 20368 | 20301 | const template = "missing tuple field with index {d}"; |
| 20369 | 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 | 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 | 20307 | } else { |
| 20375 | 20308 | const field_name = anon_struct.names.get(ip)[i]; |
| 20376 | 20309 | const template = "missing struct field: {}"; |
| 20377 | 20310 | const args = .{field_name.fmt(ip)}; |
| 20378 | 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 | 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 | 20317 | } else { |
| ... | ... | @@ -20391,16 +20324,12 @@ fn finishStructInit( |
| 20391 | 20324 | for (0..struct_type.field_types.len) |i| { |
| 20392 | 20325 | if (field_inits[i] != .none) { |
| 20393 | 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 | 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) { |
| 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 | | }; |
| 20332 | field_inits[i] = try sema.coerce(block, field_ty, field_inits[i], field_src); |
| 20404 | 20333 | continue; |
| 20405 | 20334 | } |
| 20406 | 20335 | |
| ... | ... | @@ -20413,16 +20342,16 @@ fn finishStructInit( |
| 20413 | 20342 | const template = "missing struct field: {}"; |
| 20414 | 20343 | const args = .{field_name.fmt(ip)}; |
| 20415 | 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 | 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 | 20349 | } else { |
| 20421 | 20350 | const template = "missing tuple field with index {d}"; |
| 20422 | 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 | 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 | 20357 | } else { |
| ... | ... | @@ -20434,16 +20363,7 @@ fn finishStructInit( |
| 20434 | 20363 | } |
| 20435 | 20364 | |
| 20436 | 20365 | if (root_msg) |msg| { |
| 20437 | | if (mod.typeToStruct(struct_ty)) |struct_type| { |
| 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 | | } |
| 20366 | try sema.addDeclaredHereNote(msg, struct_ty); |
| 20447 | 20367 | root_msg = null; |
| 20448 | 20368 | return sema.failWithOwnedErrorMsg(block, msg); |
| 20449 | 20369 | } |
| ... | ... | @@ -20470,9 +20390,10 @@ fn finishStructInit( |
| 20470 | 20390 | }; |
| 20471 | 20391 | |
| 20472 | 20392 | if (try sema.typeRequiresComptime(struct_ty)) { |
| 20473 | | const decl = mod.declPtr(block.src_decl); |
| 20474 | | const field_src = mod.initSrc(init_src.node_offset.x, decl, runtime_index); |
| 20475 | | return sema.failWithNeededComptime(block, field_src, .{ |
| 20393 | return sema.failWithNeededComptime(block, block.src(.{ .init_elem = .{ |
| 20394 | .init_node_offset = init_src.offset.node_offset.x, |
| 20395 | .elem_index = @intCast(runtime_index), |
| 20396 | } }), .{ |
| 20476 | 20397 | .needed_comptime_reason = "initializer of comptime only struct must be comptime-known", |
| 20477 | 20398 | }); |
| 20478 | 20399 | } |
| ... | ... | @@ -20500,15 +20421,10 @@ fn finishStructInit( |
| 20500 | 20421 | return sema.makePtrConst(block, alloc); |
| 20501 | 20422 | } |
| 20502 | 20423 | |
| 20503 | | sema.requireRuntimeBlock(block, .unneeded, null) catch |err| switch (err) { |
| 20504 | | error.NeededSourceLocation => { |
| 20505 | | const decl = mod.declPtr(block.src_decl); |
| 20506 | | const field_src = mod.initSrc(dest_src.node_offset.x, decl, runtime_index); |
| 20507 | | try sema.requireRuntimeBlock(block, dest_src, field_src); |
| 20508 | | unreachable; |
| 20509 | | }, |
| 20510 | | else => |e| return e, |
| 20511 | | }; |
| 20424 | try sema.requireRuntimeBlock(block, dest_src, block.src(.{ .init_elem = .{ |
| 20425 | .init_node_offset = init_src.offset.node_offset.x, |
| 20426 | .elem_index = @intCast(runtime_index), |
| 20427 | } })); |
| 20512 | 20428 | try sema.resolveStructFieldInits(struct_ty); |
| 20513 | 20429 | try sema.queueFullTypeResolution(struct_ty); |
| 20514 | 20430 | const struct_val = try block.addAggregateInit(struct_ty, field_inits); |
| ... | ... | @@ -20576,9 +20492,11 @@ fn structInitAnon( |
| 20576 | 20492 | field_ty.* = sema.typeOf(init).toIntern(); |
| 20577 | 20493 | if (Type.fromInterned(field_ty.*).zigTypeTag(mod) == .Opaque) { |
| 20578 | 20494 | const msg = msg: { |
| 20579 | | const decl = mod.declPtr(block.src_decl); |
| 20580 | | const field_src = mod.initSrc(src.node_offset.x, decl, @intCast(i_usize)); |
| 20581 | | const msg = try sema.errMsg(block, field_src, "opaque types have unknown size and therefore cannot be directly embedded in structs", .{}); |
| 20495 | const field_src = block.src(.{ .init_elem = .{ |
| 20496 | .init_node_offset = src.offset.node_offset.x, |
| 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 | 20500 | errdefer msg.destroy(sema.gpa); |
| 20583 | 20501 | |
| 20584 | 20502 | try sema.addDeclaredHereNote(msg, Type.fromInterned(field_ty.*)); |
| ... | ... | @@ -20610,15 +20528,10 @@ fn structInitAnon( |
| 20610 | 20528 | return sema.addConstantMaybeRef(tuple_val, is_ref); |
| 20611 | 20529 | }; |
| 20612 | 20530 | |
| 20613 | | sema.requireRuntimeBlock(block, .unneeded, null) catch |err| switch (err) { |
| 20614 | | error.NeededSourceLocation => { |
| 20615 | | const decl = mod.declPtr(block.src_decl); |
| 20616 | | const field_src = mod.initSrc(src.node_offset.x, decl, runtime_index); |
| 20617 | | try sema.requireRuntimeBlock(block, src, field_src); |
| 20618 | | unreachable; |
| 20619 | | }, |
| 20620 | | else => |e| return e, |
| 20621 | | }; |
| 20531 | try sema.requireRuntimeBlock(block, LazySrcLoc.unneeded, block.src(.{ .init_elem = .{ |
| 20532 | .init_node_offset = src.offset.node_offset.x, |
| 20533 | .elem_index = @intCast(runtime_index), |
| 20534 | } })); |
| 20622 | 20535 | |
| 20623 | 20536 | if (is_ref) { |
| 20624 | 20537 | const target = mod.getTarget(); |
| ... | ... | @@ -20697,15 +20610,19 @@ fn zirArrayInit( |
| 20697 | 20610 | const resolved_args = try gpa.alloc(Air.Inst.Ref, final_len); |
| 20698 | 20611 | defer gpa.free(resolved_args); |
| 20699 | 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 | 20617 | // Less inits than needed. |
| 20701 | 20618 | if (i + 2 > args.len) if (is_tuple) { |
| 20702 | 20619 | const default_val = array_ty.structFieldDefaultValue(i, mod).toIntern(); |
| 20703 | 20620 | if (default_val == .unreachable_value) { |
| 20704 | 20621 | const template = "missing tuple field with index {d}"; |
| 20705 | 20622 | if (root_msg) |msg| { |
| 20706 | | try sema.errNote(block, src, msg, template, .{i}); |
| 20623 | try sema.errNote(src, msg, template, .{i}); |
| 20707 | 20624 | } else { |
| 20708 | | root_msg = try sema.errMsg(block, src, template, .{i}); |
| 20625 | root_msg = try sema.errMsg(src, template, .{i}); |
| 20709 | 20626 | } |
| 20710 | 20627 | } else { |
| 20711 | 20628 | dest.* = Air.internedToRef(default_val); |
| ... | ... | @@ -20722,29 +20639,17 @@ fn zirArrayInit( |
| 20722 | 20639 | array_ty.structFieldType(i, mod) |
| 20723 | 20640 | else |
| 20724 | 20641 | array_ty.elemType2(mod); |
| 20725 | | dest.* = sema.coerce(block, elem_ty, resolved_arg, .unneeded) catch |err| switch (err) { |
| 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 | | }; |
| 20642 | dest.* = try sema.coerce(block, elem_ty, resolved_arg, elem_src); |
| 20734 | 20643 | if (is_tuple) { |
| 20735 | 20644 | if (array_ty.structFieldIsComptime(i, mod)) |
| 20736 | 20645 | try sema.resolveStructFieldInits(array_ty); |
| 20737 | 20646 | if (try array_ty.structFieldValueComptime(mod, i)) |field_val| { |
| 20738 | 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 | 20648 | return sema.failWithNeededComptime(block, elem_src, .{ |
| 20742 | 20649 | .needed_comptime_reason = "value stored in comptime field must be comptime-known", |
| 20743 | 20650 | }); |
| 20744 | 20651 | }; |
| 20745 | 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 | 20653 | return sema.failWithInvalidComptimeFieldStore(block, elem_src, array_ty, i); |
| 20749 | 20654 | } |
| 20750 | 20655 | } |
| ... | ... | @@ -20777,15 +20682,10 @@ fn zirArrayInit( |
| 20777 | 20682 | return sema.addConstantMaybeRef(result_val.toIntern(), is_ref); |
| 20778 | 20683 | }; |
| 20779 | 20684 | |
| 20780 | | sema.requireRuntimeBlock(block, .unneeded, null) catch |err| switch (err) { |
| 20781 | | error.NeededSourceLocation => { |
| 20782 | | const decl = mod.declPtr(block.src_decl); |
| 20783 | | const elem_src = mod.initSrc(src.node_offset.x, decl, runtime_index); |
| 20784 | | try sema.requireRuntimeBlock(block, src, elem_src); |
| 20785 | | unreachable; |
| 20786 | | }, |
| 20787 | | else => return err, |
| 20788 | | }; |
| 20685 | try sema.requireRuntimeBlock(block, LazySrcLoc.unneeded, block.src(.{ .init_elem = .{ |
| 20686 | .init_node_offset = src.offset.node_offset.x, |
| 20687 | .elem_index = runtime_index, |
| 20688 | } })); |
| 20789 | 20689 | try sema.queueFullTypeResolution(array_ty); |
| 20790 | 20690 | |
| 20791 | 20691 | if (is_ref) { |
| ... | ... | @@ -20864,7 +20764,7 @@ fn arrayInitAnon( |
| 20864 | 20764 | types[i] = sema.typeOf(elem).toIntern(); |
| 20865 | 20765 | if (Type.fromInterned(types[i]).zigTypeTag(mod) == .Opaque) { |
| 20866 | 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 | 20768 | errdefer msg.destroy(gpa); |
| 20869 | 20769 | |
| 20870 | 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 | 20835 | fn zirFieldTypeRef(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 20936 | 20836 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 20937 | 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 }; |
| 20939 | | const field_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; |
| 20838 | const ty_src = block.builtinCallArgSrc(inst_data.src_node, 0); |
| 20839 | const field_src = block.builtinCallArgSrc(inst_data.src_node, 1); |
| 20940 | 20840 | const aggregate_ty = try sema.resolveType(block, ty_src, extra.container_type); |
| 20941 | 20841 | const field_name = try sema.resolveConstStringIntern(block, field_src, extra.field_name, .{ |
| 20942 | 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 | 20850 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 20951 | 20851 | const extra = sema.code.extraData(Zir.Inst.FieldType, inst_data.payload_index).data; |
| 20952 | 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 | 20854 | const wrapped_aggregate_ty = sema.resolveType(block, ty_src, extra.container_type) catch |err| switch (err) { |
| 20955 | 20855 | // Since this is a ZIR instruction that returns a type, encountering |
| 20956 | 20856 | // generic poison should not result in a failed compilation, but the |
| ... | ... | @@ -20990,7 +20890,7 @@ fn fieldType( |
| 20990 | 20890 | .struct_type => { |
| 20991 | 20891 | const struct_type = ip.loadStructType(cur_ty.toIntern()); |
| 20992 | 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 | 20894 | const field_ty = struct_type.field_types.get(ip)[field_index]; |
| 20995 | 20895 | return Air.internedToRef(field_ty); |
| 20996 | 20896 | }, |
| ... | ... | @@ -20999,7 +20899,7 @@ fn fieldType( |
| 20999 | 20899 | .Union => { |
| 21000 | 20900 | const union_obj = mod.typeToUnion(cur_ty).?; |
| 21001 | 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 | 20903 | const field_ty = union_obj.field_types.get(ip)[field_index]; |
| 21004 | 20904 | return Air.internedToRef(field_ty); |
| 21005 | 20905 | }, |
| ... | ... | @@ -21050,14 +20950,14 @@ fn zirFrame( |
| 21050 | 20950 | block: *Block, |
| 21051 | 20951 | extended: Zir.Inst.Extended.InstData, |
| 21052 | 20952 | ) CompileError!Air.Inst.Ref { |
| 21053 | | const src = LazySrcLoc.nodeOffset(@bitCast(extended.operand)); |
| 20953 | const src = block.nodeOffset(@bitCast(extended.operand)); |
| 21054 | 20954 | return sema.failWithUseOfAsync(block, src); |
| 21055 | 20955 | } |
| 21056 | 20956 | |
| 21057 | 20957 | fn zirAlignOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 21058 | 20958 | const mod = sema.mod; |
| 21059 | 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 | 20961 | const ty = try sema.resolveType(block, operand_src, inst_data.operand); |
| 21062 | 20962 | if (ty.isNoReturn(mod)) { |
| 21063 | 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 | 21021 | |
| 21122 | 21022 | fn zirErrorName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 21123 | 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 | 21025 | const uncoerced_operand = try sema.resolveInst(inst_data.operand); |
| 21126 | 21026 | const operand = try sema.coerce(block, Type.anyerror, uncoerced_operand, operand_src); |
| 21127 | 21027 | |
| ... | ... | @@ -21143,7 +21043,7 @@ fn zirAbs( |
| 21143 | 21043 | const mod = sema.mod; |
| 21144 | 21044 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 21145 | 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 | 21047 | const operand_ty = sema.typeOf(operand); |
| 21148 | 21048 | const scalar_ty = operand_ty.scalarType(mod); |
| 21149 | 21049 | |
| ... | ... | @@ -21211,7 +21111,7 @@ fn zirUnaryMath( |
| 21211 | 21111 | const mod = sema.mod; |
| 21212 | 21112 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 21213 | 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 | 21115 | const operand_ty = sema.typeOf(operand); |
| 21216 | 21116 | const scalar_ty = operand_ty.scalarType(mod); |
| 21217 | 21117 | |
| ... | ... | @@ -21233,7 +21133,7 @@ fn zirUnaryMath( |
| 21233 | 21133 | |
| 21234 | 21134 | fn zirTagName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 21235 | 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 | 21137 | const src = block.nodeOffset(inst_data.src_node); |
| 21238 | 21138 | const operand = try sema.resolveInst(inst_data.operand); |
| 21239 | 21139 | const operand_ty = sema.typeOf(operand); |
| ... | ... | @@ -21243,7 +21143,7 @@ fn zirTagName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 21243 | 21143 | try sema.resolveTypeLayout(operand_ty); |
| 21244 | 21144 | const enum_ty = switch (operand_ty.zigTypeTag(mod)) { |
| 21245 | 21145 | .EnumLiteral => { |
| 21246 | | const val = try sema.resolveConstDefinedValue(block, .unneeded, operand, undefined); |
| 21146 | const val = try sema.resolveConstDefinedValue(block, LazySrcLoc.unneeded, operand, undefined); |
| 21247 | 21147 | const tag_name = ip.indexToKey(val.toIntern()).enum_literal; |
| 21248 | 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 | 21166 | const casted_operand = try sema.coerce(block, enum_ty, operand, operand_src); |
| 21267 | 21167 | if (try sema.resolveDefinedValue(block, operand_src, casted_operand)) |val| { |
| 21268 | 21168 | const field_index = enum_ty.enumTagFieldIndex(val, mod) orelse { |
| 21269 | | const enum_decl = mod.declPtr(enum_decl_index); |
| 21270 | 21169 | const msg = msg: { |
| 21271 | | const msg = try sema.errMsg(block, src, "no field with value '{}' in enum '{}'", .{ |
| 21272 | | val.fmtValue(sema.mod, sema), enum_decl.name.fmt(ip), |
| 21170 | const msg = try sema.errMsg(src, "no field with value '{}' in enum '{}'", .{ |
| 21171 | val.fmtValue(sema.mod, sema), mod.declPtr(enum_decl_index).name.fmt(ip), |
| 21273 | 21172 | }); |
| 21274 | 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 | 21175 | break :msg msg; |
| 21277 | 21176 | }; |
| 21278 | 21177 | return sema.failWithOwnedErrorMsg(block, msg); |
| ... | ... | @@ -21303,10 +21202,10 @@ fn zirReify( |
| 21303 | 21202 | const ip = &mod.intern_pool; |
| 21304 | 21203 | const name_strategy: Zir.Inst.NameStrategy = @enumFromInt(extended.small); |
| 21305 | 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 | 21206 | const type_info_ty = try sema.getBuiltinType("Type"); |
| 21308 | 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 | 21209 | const type_info = try sema.coerce(block, type_info_ty, uncasted_operand, operand_src); |
| 21311 | 21210 | const val = try sema.resolveConstDefinedValue(block, operand_src, type_info, .{ |
| 21312 | 21211 | .needed_comptime_reason = "operand to @Type must be comptime-known", |
| ... | ... | @@ -21459,11 +21358,10 @@ fn zirReify( |
| 21459 | 21358 | } else if (ptr_size == .C) { |
| 21460 | 21359 | if (!try sema.validateExternType(elem_ty, .other)) { |
| 21461 | 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 | 21362 | errdefer msg.destroy(gpa); |
| 21464 | 21363 | |
| 21465 | | const src_decl = mod.declPtr(block.src_decl); |
| 21466 | | try sema.explainWhyTypeIsNotExtern(msg, src_decl.toSrcLoc(src, mod), elem_ty, .other); |
| 21364 | try sema.explainWhyTypeIsNotExtern(msg, src, elem_ty, .other); |
| 21467 | 21365 | |
| 21468 | 21366 | try sema.addDeclaredHereNote(msg, elem_ty); |
| 21469 | 21367 | break :msg msg; |
| ... | ... | @@ -21679,7 +21577,6 @@ fn zirReify( |
| 21679 | 21577 | |
| 21680 | 21578 | const new_decl_index = try sema.createAnonymousDeclTypeNamed( |
| 21681 | 21579 | block, |
| 21682 | | mod.declPtr(block.src_decl).relativeToNodeIndex(src.node_offset.x), |
| 21683 | 21580 | Value.fromInterned(wip_ty.index), |
| 21684 | 21581 | name_strategy, |
| 21685 | 21582 | "opaque", |
| ... | ... | @@ -21879,7 +21776,6 @@ fn reifyEnum( |
| 21879 | 21776 | |
| 21880 | 21777 | const new_decl_index = try sema.createAnonymousDeclTypeNamed( |
| 21881 | 21778 | block, |
| 21882 | | mod.declPtr(block.src_decl).relativeToNodeIndex(src.node_offset.x), |
| 21883 | 21779 | Value.fromInterned(wip_ty.index), |
| 21884 | 21780 | name_strategy, |
| 21885 | 21781 | "enum", |
| ... | ... | @@ -21913,17 +21809,17 @@ fn reifyEnum( |
| 21913 | 21809 | if (wip_ty.nextField(ip, field_name, coerced_field_val.toIntern())) |conflict| { |
| 21914 | 21810 | return sema.failWithOwnedErrorMsg(block, switch (conflict.kind) { |
| 21915 | 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 | 21813 | errdefer msg.destroy(gpa); |
| 21918 | 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 | 21816 | break :msg msg; |
| 21921 | 21817 | }, |
| 21922 | 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 | 21820 | errdefer msg.destroy(gpa); |
| 21925 | 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 | 21823 | break :msg msg; |
| 21928 | 21824 | }, |
| 21929 | 21825 | }); |
| ... | ... | @@ -22026,7 +21922,6 @@ fn reifyUnion( |
| 22026 | 21922 | |
| 22027 | 21923 | const new_decl_index = try sema.createAnonymousDeclTypeNamed( |
| 22028 | 21924 | block, |
| 22029 | | mod.declPtr(block.src_decl).relativeToNodeIndex(src.node_offset.x), |
| 22030 | 21925 | Value.fromInterned(wip_ty.index), |
| 22031 | 21926 | name_strategy, |
| 22032 | 21927 | "union", |
| ... | ... | @@ -22082,7 +21977,7 @@ fn reifyUnion( |
| 22082 | 21977 | } |
| 22083 | 21978 | |
| 22084 | 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 | 21981 | errdefer msg.destroy(gpa); |
| 22087 | 21982 | var it = seen_tags.iterator(.{ .kind = .unset }); |
| 22088 | 21983 | while (it.next()) |enum_index| { |
| ... | ... | @@ -22135,7 +22030,7 @@ fn reifyUnion( |
| 22135 | 22030 | const field_ty = Type.fromInterned(field_ty_ip); |
| 22136 | 22031 | if (field_ty.zigTypeTag(mod) == .Opaque) { |
| 22137 | 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 | 22034 | errdefer msg.destroy(gpa); |
| 22140 | 22035 | |
| 22141 | 22036 | try sema.addDeclaredHereNote(msg, field_ty); |
| ... | ... | @@ -22144,22 +22039,20 @@ fn reifyUnion( |
| 22144 | 22039 | } |
| 22145 | 22040 | if (layout == .@"extern" and !try sema.validateExternType(field_ty, .union_field)) { |
| 22146 | 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 | 22043 | errdefer msg.destroy(gpa); |
| 22149 | 22044 | |
| 22150 | | const src_decl = mod.declPtr(block.src_decl); |
| 22151 | | try sema.explainWhyTypeIsNotExtern(msg, src_decl.toSrcLoc(src, mod), field_ty, .union_field); |
| 22045 | try sema.explainWhyTypeIsNotExtern(msg, src, field_ty, .union_field); |
| 22152 | 22046 | |
| 22153 | 22047 | try sema.addDeclaredHereNote(msg, field_ty); |
| 22154 | 22048 | break :msg msg; |
| 22155 | 22049 | }); |
| 22156 | 22050 | } else if (layout == .@"packed" and !try sema.validatePackedType(field_ty)) { |
| 22157 | 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 | 22053 | errdefer msg.destroy(gpa); |
| 22160 | 22054 | |
| 22161 | | const src_decl = mod.declPtr(block.src_decl); |
| 22162 | | try sema.explainWhyTypeIsNotPacked(msg, src_decl.toSrcLoc(src, mod), field_ty); |
| 22055 | try sema.explainWhyTypeIsNotPacked(msg, src, field_ty); |
| 22163 | 22056 | |
| 22164 | 22057 | try sema.addDeclaredHereNote(msg, field_ty); |
| 22165 | 22058 | break :msg msg; |
| ... | ... | @@ -22285,7 +22178,6 @@ fn reifyStruct( |
| 22285 | 22178 | |
| 22286 | 22179 | const new_decl_index = try sema.createAnonymousDeclTypeNamed( |
| 22287 | 22180 | block, |
| 22288 | | mod.declPtr(block.src_decl).relativeToNodeIndex(src.node_offset.x), |
| 22289 | 22181 | Value.fromInterned(wip_ty.index), |
| 22290 | 22182 | name_strategy, |
| 22291 | 22183 | "struct", |
| ... | ... | @@ -22376,7 +22268,7 @@ fn reifyStruct( |
| 22376 | 22268 | |
| 22377 | 22269 | if (field_ty.zigTypeTag(mod) == .Opaque) { |
| 22378 | 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 | 22272 | errdefer msg.destroy(gpa); |
| 22381 | 22273 | |
| 22382 | 22274 | try sema.addDeclaredHereNote(msg, field_ty); |
| ... | ... | @@ -22385,7 +22277,7 @@ fn reifyStruct( |
| 22385 | 22277 | } |
| 22386 | 22278 | if (field_ty.zigTypeTag(mod) == .NoReturn) { |
| 22387 | 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 | 22281 | errdefer msg.destroy(gpa); |
| 22390 | 22282 | |
| 22391 | 22283 | try sema.addDeclaredHereNote(msg, field_ty); |
| ... | ... | @@ -22394,22 +22286,20 @@ fn reifyStruct( |
| 22394 | 22286 | } |
| 22395 | 22287 | if (layout == .@"extern" and !try sema.validateExternType(field_ty, .struct_field)) { |
| 22396 | 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 | 22290 | errdefer msg.destroy(gpa); |
| 22399 | 22291 | |
| 22400 | | const src_decl = sema.mod.declPtr(block.src_decl); |
| 22401 | | try sema.explainWhyTypeIsNotExtern(msg, src_decl.toSrcLoc(src, mod), field_ty, .struct_field); |
| 22292 | try sema.explainWhyTypeIsNotExtern(msg, src, field_ty, .struct_field); |
| 22402 | 22293 | |
| 22403 | 22294 | try sema.addDeclaredHereNote(msg, field_ty); |
| 22404 | 22295 | break :msg msg; |
| 22405 | 22296 | }); |
| 22406 | 22297 | } else if (layout == .@"packed" and !try sema.validatePackedType(field_ty)) { |
| 22407 | 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 | 22300 | errdefer msg.destroy(gpa); |
| 22410 | 22301 | |
| 22411 | | const src_decl = sema.mod.declPtr(block.src_decl); |
| 22412 | | try sema.explainWhyTypeIsNotPacked(msg, src_decl.toSrcLoc(src, mod), field_ty); |
| 22302 | try sema.explainWhyTypeIsNotPacked(msg, src, field_ty); |
| 22413 | 22303 | |
| 22414 | 22304 | try sema.addDeclaredHereNote(msg, field_ty); |
| 22415 | 22305 | break :msg msg; |
| ... | ... | @@ -22424,7 +22314,7 @@ fn reifyStruct( |
| 22424 | 22314 | sema.resolveTypeLayout(field_ty) catch |err| switch (err) { |
| 22425 | 22315 | error.AnalysisFail => { |
| 22426 | 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 | 22318 | return err; |
| 22429 | 22319 | }, |
| 22430 | 22320 | else => return err, |
| ... | ... | @@ -22455,22 +22345,20 @@ fn resolveVaListRef(sema: *Sema, block: *Block, src: LazySrcLoc, zir_ref: Zir.In |
| 22455 | 22345 | } |
| 22456 | 22346 | |
| 22457 | 22347 | fn zirCVaArg(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!Air.Inst.Ref { |
| 22458 | | const mod = sema.mod; |
| 22459 | 22348 | const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data; |
| 22460 | | const src = LazySrcLoc.nodeOffset(extra.node); |
| 22461 | | const va_list_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node }; |
| 22462 | | const ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = extra.node }; |
| 22349 | const src = block.nodeOffset(extra.node); |
| 22350 | const va_list_src = block.builtinCallArgSrc(extra.node, 0); |
| 22351 | const ty_src = block.builtinCallArgSrc(extra.node, 1); |
| 22463 | 22352 | |
| 22464 | 22353 | const va_list_ref = try sema.resolveVaListRef(block, va_list_src, extra.lhs); |
| 22465 | 22354 | const arg_ty = try sema.resolveType(block, ty_src, extra.rhs); |
| 22466 | 22355 | |
| 22467 | 22356 | if (!try sema.validateExternType(arg_ty, .param_ty)) { |
| 22468 | 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 | 22359 | errdefer msg.destroy(sema.gpa); |
| 22471 | 22360 | |
| 22472 | | const src_decl = sema.mod.declPtr(block.src_decl); |
| 22473 | | try sema.explainWhyTypeIsNotExtern(msg, src_decl.toSrcLoc(ty_src, mod), arg_ty, .param_ty); |
| 22361 | try sema.explainWhyTypeIsNotExtern(msg, ty_src, arg_ty, .param_ty); |
| 22474 | 22362 | |
| 22475 | 22363 | try sema.addDeclaredHereNote(msg, arg_ty); |
| 22476 | 22364 | break :msg msg; |
| ... | ... | @@ -22484,8 +22372,8 @@ fn zirCVaArg(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) C |
| 22484 | 22372 | |
| 22485 | 22373 | fn zirCVaCopy(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!Air.Inst.Ref { |
| 22486 | 22374 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; |
| 22487 | | const src = LazySrcLoc.nodeOffset(extra.node); |
| 22488 | | const va_list_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node }; |
| 22375 | const src = block.nodeOffset(extra.node); |
| 22376 | const va_list_src = block.builtinCallArgSrc(extra.node, 0); |
| 22489 | 22377 | |
| 22490 | 22378 | const va_list_ref = try sema.resolveVaListRef(block, va_list_src, extra.operand); |
| 22491 | 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 | 22384 | |
| 22497 | 22385 | fn zirCVaEnd(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!Air.Inst.Ref { |
| 22498 | 22386 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; |
| 22499 | | const src = LazySrcLoc.nodeOffset(extra.node); |
| 22500 | | const va_list_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node }; |
| 22387 | const src = block.nodeOffset(extra.node); |
| 22388 | const va_list_src = block.builtinCallArgSrc(extra.node, 0); |
| 22501 | 22389 | |
| 22502 | 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 | 22394 | } |
| 22507 | 22395 | |
| 22508 | 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 | 22399 | const va_list_ty = try sema.getBuiltinType("VaList"); |
| 22512 | 22400 | try sema.requireRuntimeBlock(block, src, null); |
| ... | ... | @@ -22521,7 +22409,7 @@ fn zirTypeName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 22521 | 22409 | const ip = &mod.intern_pool; |
| 22522 | 22410 | |
| 22523 | 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 | 22413 | const ty = try sema.resolveType(block, ty_src, inst_data.operand); |
| 22526 | 22414 | |
| 22527 | 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 | 22433 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 22546 | 22434 | const src = block.nodeOffset(inst_data.src_node); |
| 22547 | 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 | 22437 | const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu_opt, "@intFromFloat"); |
| 22550 | 22438 | const operand = try sema.resolveInst(extra.rhs); |
| 22551 | 22439 | const operand_ty = sema.typeOf(operand); |
| ... | ... | @@ -22627,7 +22515,7 @@ fn zirFloatFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro |
| 22627 | 22515 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 22628 | 22516 | const src = block.nodeOffset(inst_data.src_node); |
| 22629 | 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 | 22519 | const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu_opt, "@floatFromInt"); |
| 22632 | 22520 | const operand = try sema.resolveInst(extra.rhs); |
| 22633 | 22521 | const operand_ty = sema.typeOf(operand); |
| ... | ... | @@ -22671,7 +22559,7 @@ fn zirPtrFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! |
| 22671 | 22559 | |
| 22672 | 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 | 22563 | const operand_res = try sema.resolveInst(extra.rhs); |
| 22676 | 22564 | |
| 22677 | 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 | 22582 | |
| 22695 | 22583 | if (ptr_ty.isSlice(mod)) { |
| 22696 | 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 | 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 | 22588 | break :msg msg; |
| 22701 | 22589 | }; |
| 22702 | 22590 | return sema.failWithOwnedErrorMsg(block, msg); |
| ... | ... | @@ -22721,11 +22609,10 @@ fn zirPtrFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! |
| 22721 | 22609 | } |
| 22722 | 22610 | if (try sema.typeRequiresComptime(ptr_ty)) { |
| 22723 | 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 | 22613 | errdefer msg.destroy(sema.gpa); |
| 22726 | 22614 | |
| 22727 | | const src_decl = mod.declPtr(block.src_decl); |
| 22728 | | try sema.explainWhyTypeIsComptime(msg, src_decl.toSrcLoc(src, mod), ptr_ty); |
| 22615 | try sema.explainWhyTypeIsComptime(msg, src, ptr_ty); |
| 22729 | 22616 | break :msg msg; |
| 22730 | 22617 | }); |
| 22731 | 22618 | } |
| ... | ... | @@ -22810,8 +22697,8 @@ fn zirErrorCast(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData |
| 22810 | 22697 | const mod = sema.mod; |
| 22811 | 22698 | const ip = &mod.intern_pool; |
| 22812 | 22699 | const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data; |
| 22813 | | const src = LazySrcLoc.nodeOffset(extra.node); |
| 22814 | | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node }; |
| 22700 | const src = block.nodeOffset(extra.node); |
| 22701 | const operand_src = block.builtinCallArgSrc(extra.node, 0); |
| 22815 | 22702 | const base_dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_opt, "@errorCast"); |
| 22816 | 22703 | const operand = try sema.resolveInst(extra.rhs); |
| 22817 | 22704 | const base_operand_ty = sema.typeOf(operand); |
| ... | ... | @@ -22831,12 +22718,12 @@ fn zirErrorCast(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData |
| 22831 | 22718 | base_dest_ty.errorUnionPayload(mod).toIntern() != base_operand_ty.errorUnionPayload(mod).toIntern()) |
| 22832 | 22719 | { |
| 22833 | 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 | 22722 | errdefer msg.destroy(sema.gpa); |
| 22836 | 22723 | const dest_ty = base_dest_ty.errorUnionPayload(mod); |
| 22837 | 22724 | const operand_ty = base_operand_ty.errorUnionPayload(mod); |
| 22838 | | try sema.errNote(block, src, msg, "destination payload is '{}'", .{dest_ty.fmt(mod)}); |
| 22839 | | try sema.errNote(block, src, msg, "operand payload is '{}'", .{operand_ty.fmt(mod)}); |
| 22725 | try sema.errNote(src, msg, "destination payload is '{}'", .{dest_ty.fmt(mod)}); |
| 22726 | try sema.errNote(src, msg, "operand payload is '{}'", .{operand_ty.fmt(mod)}); |
| 22840 | 22727 | try addDeclaredHereNote(sema, msg, dest_ty); |
| 22841 | 22728 | try addDeclaredHereNote(sema, msg, operand_ty); |
| 22842 | 22729 | break :msg msg; |
| ... | ... | @@ -22935,8 +22822,8 @@ fn zirPtrCastFull(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDa |
| 22935 | 22822 | const FlagsInt = @typeInfo(Zir.Inst.FullPtrCastFlags).Struct.backing_integer.?; |
| 22936 | 22823 | const flags: Zir.Inst.FullPtrCastFlags = @bitCast(@as(FlagsInt, @truncate(extended.small))); |
| 22937 | 22824 | const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data; |
| 22938 | | const src = LazySrcLoc.nodeOffset(extra.node); |
| 22939 | | const operand_src: LazySrcLoc = .{ .node_offset_ptrcast_operand = extra.node }; |
| 22825 | const src = block.nodeOffset(extra.node); |
| 22826 | const operand_src = block.src(.{ .node_offset_ptrcast_operand = extra.node }); |
| 22940 | 22827 | const operand = try sema.resolveInst(extra.rhs); |
| 22941 | 22828 | const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu, flags.needResultTypeBuiltinName()); |
| 22942 | 22829 | return sema.ptrCastFull( |
| ... | ... | @@ -22953,7 +22840,7 @@ fn zirPtrCastFull(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDa |
| 22953 | 22840 | fn zirPtrCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 22954 | 22841 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 22955 | 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 | 22844 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 22958 | 22845 | const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu, "@ptrCast"); |
| 22959 | 22846 | const operand = try sema.resolveInst(extra.rhs); |
| ... | ... | @@ -23023,7 +22910,7 @@ fn ptrCastFull( |
| 23023 | 22910 | if (src_info.flags.size == .C) break :check_size; |
| 23024 | 22911 | if (dest_info.flags.size == .C) break :check_size; |
| 23025 | 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 | 22914 | pointerSizeString(src_info.flags.size), |
| 23028 | 22915 | pointerSizeString(dest_info.flags.size), |
| 23029 | 22916 | }); |
| ... | ... | @@ -23032,9 +22919,9 @@ fn ptrCastFull( |
| 23032 | 22919 | (src_info.flags.size == .Slice or |
| 23033 | 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 | 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 | 22926 | break :msg msg; |
| 23040 | 22927 | }); |
| ... | ... | @@ -23059,13 +22946,13 @@ fn ptrCastFull( |
| 23059 | 22946 | ); |
| 23060 | 22947 | if (imc_res == .ok) break :check_child; |
| 23061 | 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 | 22950 | src_child.fmt(mod), |
| 23064 | 22951 | dest_child.fmt(mod), |
| 23065 | 22952 | }); |
| 23066 | 22953 | errdefer msg.destroy(sema.gpa); |
| 23067 | | try imc_res.report(sema, block, src, msg); |
| 23068 | | try sema.errNote(block, src, msg, "use @ptrCast to cast pointer element type", .{}); |
| 22954 | try imc_res.report(sema, src, msg); |
| 22955 | try sema.errNote(src, msg, "use @ptrCast to cast pointer element type", .{}); |
| 23069 | 22956 | break :msg msg; |
| 23070 | 22957 | }); |
| 23071 | 22958 | } |
| ... | ... | @@ -23087,41 +22974,41 @@ fn ptrCastFull( |
| 23087 | 22974 | } |
| 23088 | 22975 | return sema.failWithOwnedErrorMsg(block, msg: { |
| 23089 | 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 | 22978 | Value.fromInterned(dest_info.sentinel).fmtValue(mod, sema), |
| 23092 | 22979 | }); |
| 23093 | 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 | 22982 | Value.fromInterned(src_info.sentinel).fmtValue(mod, sema), |
| 23096 | 22983 | Value.fromInterned(dest_info.sentinel).fmtValue(mod, sema), |
| 23097 | 22984 | }); |
| 23098 | 22985 | }; |
| 23099 | 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 | 22988 | break :msg msg; |
| 23102 | 22989 | }); |
| 23103 | 22990 | } |
| 23104 | 22991 | |
| 23105 | 22992 | if (src_info.packed_offset.host_size != dest_info.packed_offset.host_size) { |
| 23106 | 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 | 22995 | src_info.packed_offset.host_size, |
| 23109 | 22996 | dest_info.packed_offset.host_size, |
| 23110 | 22997 | }); |
| 23111 | 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 | 23000 | break :msg msg; |
| 23114 | 23001 | }); |
| 23115 | 23002 | } |
| 23116 | 23003 | |
| 23117 | 23004 | if (src_info.packed_offset.bit_offset != dest_info.packed_offset.bit_offset) { |
| 23118 | 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 | 23007 | src_info.packed_offset.bit_offset, |
| 23121 | 23008 | dest_info.packed_offset.bit_offset, |
| 23122 | 23009 | }); |
| 23123 | 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 | 23012 | break :msg msg; |
| 23126 | 23013 | }); |
| 23127 | 23014 | } |
| ... | ... | @@ -23133,12 +23020,12 @@ fn ptrCastFull( |
| 23133 | 23020 | if (dest_allows_zero) break :check_allowzero; |
| 23134 | 23021 | |
| 23135 | 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 | 23024 | operand_ty.fmt(mod), |
| 23138 | 23025 | dest_ty.fmt(mod), |
| 23139 | 23026 | }); |
| 23140 | 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 | 23029 | break :msg msg; |
| 23143 | 23030 | }); |
| 23144 | 23031 | } |
| ... | ... | @@ -23159,15 +23046,15 @@ fn ptrCastFull( |
| 23159 | 23046 | if (!flags.align_cast) { |
| 23160 | 23047 | if (dest_align.compare(.gt, src_align)) { |
| 23161 | 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 | 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 | 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 | 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 | 23058 | break :msg msg; |
| 23172 | 23059 | }); |
| 23173 | 23060 | } |
| ... | ... | @@ -23176,15 +23063,15 @@ fn ptrCastFull( |
| 23176 | 23063 | if (!flags.addrspace_cast) { |
| 23177 | 23064 | if (src_info.flags.address_space != dest_info.flags.address_space) { |
| 23178 | 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 | 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 | 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 | 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 | 23075 | break :msg msg; |
| 23189 | 23076 | }); |
| 23190 | 23077 | } |
| ... | ... | @@ -23192,9 +23079,9 @@ fn ptrCastFull( |
| 23192 | 23079 | // Some address space casts are always disallowed |
| 23193 | 23080 | if (!target_util.addrSpaceCastIsValid(mod.getTarget(), src_info.flags.address_space, dest_info.flags.address_space)) { |
| 23194 | 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 | 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 | 23085 | @tagName(src_info.flags.address_space), |
| 23199 | 23086 | @tagName(dest_info.flags.address_space), |
| 23200 | 23087 | }); |
| ... | ... | @@ -23206,9 +23093,9 @@ fn ptrCastFull( |
| 23206 | 23093 | if (!flags.const_cast) { |
| 23207 | 23094 | if (src_info.flags.is_const and !dest_info.flags.is_const) { |
| 23208 | 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 | 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 | 23099 | break :msg msg; |
| 23213 | 23100 | }); |
| 23214 | 23101 | } |
| ... | ... | @@ -23217,9 +23104,9 @@ fn ptrCastFull( |
| 23217 | 23104 | if (!flags.volatile_cast) { |
| 23218 | 23105 | if (src_info.flags.is_volatile and !dest_info.flags.is_volatile) { |
| 23219 | 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 | 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 | 23110 | break :msg msg; |
| 23224 | 23111 | }); |
| 23225 | 23112 | } |
| ... | ... | @@ -23368,8 +23255,8 @@ fn zirPtrCastNoDest(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.Inst |
| 23368 | 23255 | const FlagsInt = @typeInfo(Zir.Inst.FullPtrCastFlags).Struct.backing_integer.?; |
| 23369 | 23256 | const flags: Zir.Inst.FullPtrCastFlags = @bitCast(@as(FlagsInt, @truncate(extended.small))); |
| 23370 | 23257 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; |
| 23371 | | const src = LazySrcLoc.nodeOffset(extra.node); |
| 23372 | | const operand_src: LazySrcLoc = .{ .node_offset_ptrcast_operand = extra.node }; |
| 23258 | const src = block.nodeOffset(extra.node); |
| 23259 | const operand_src = block.src(.{ .node_offset_ptrcast_operand = extra.node }); |
| 23373 | 23260 | const operand = try sema.resolveInst(extra.operand); |
| 23374 | 23261 | const operand_ty = sema.typeOf(operand); |
| 23375 | 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 | 23287 | const mod = sema.mod; |
| 23401 | 23288 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 23402 | 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 | 23291 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 23405 | 23292 | const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu_opt, "@truncate"); |
| 23406 | 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 | 23325 | if (operand_info.bits < dest_info.bits) { |
| 23439 | 23326 | const msg = msg: { |
| 23440 | 23327 | const msg = try sema.errMsg( |
| 23441 | | block, |
| 23442 | 23328 | src, |
| 23443 | 23329 | "destination type '{}' has more bits than source type '{}'", |
| 23444 | 23330 | .{ dest_ty.fmt(mod), operand_ty.fmt(mod) }, |
| 23445 | 23331 | ); |
| 23446 | 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 | 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 | 23337 | operand_info.bits, |
| 23452 | 23338 | }); |
| 23453 | 23339 | break :msg msg; |
| ... | ... | @@ -23490,7 +23376,7 @@ fn zirBitCount( |
| 23490 | 23376 | const mod = sema.mod; |
| 23491 | 23377 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 23492 | 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 | 23380 | const operand = try sema.resolveInst(inst_data.operand); |
| 23495 | 23381 | const operand_ty = sema.typeOf(operand); |
| 23496 | 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 | 23430 | const mod = sema.mod; |
| 23545 | 23431 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 23546 | 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 | 23434 | const operand = try sema.resolveInst(inst_data.operand); |
| 23549 | 23435 | const operand_ty = sema.typeOf(operand); |
| 23550 | 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 | 23486 | fn zirBitReverse(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 23601 | 23487 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 23602 | 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 | 23490 | const operand = try sema.resolveInst(inst_data.operand); |
| 23605 | 23491 | const operand_ty = sema.typeOf(operand); |
| 23606 | 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 | 23544 | |
| 23659 | 23545 | fn bitOffsetOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!u64 { |
| 23660 | 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 }; |
| 23662 | | const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node }; |
| 23663 | | const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node }; |
| 23547 | const src = block.src(.{ .node_offset_bin_op = inst_data.src_node }); |
| 23548 | const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node }); |
| 23549 | const rhs_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node }); |
| 23664 | 23550 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 23665 | 23551 | |
| 23666 | 23552 | const ty = try sema.resolveType(block, lhs_src, extra.lhs); |
| ... | ... | @@ -23773,14 +23659,13 @@ fn checkPtrOperand( |
| 23773 | 23659 | .Fn => { |
| 23774 | 23660 | const msg = msg: { |
| 23775 | 23661 | const msg = try sema.errMsg( |
| 23776 | | block, |
| 23777 | 23662 | ty_src, |
| 23778 | 23663 | "expected pointer, found '{}'", |
| 23779 | 23664 | .{ty.fmt(mod)}, |
| 23780 | 23665 | ); |
| 23781 | 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 | 23670 | break :msg msg; |
| 23786 | 23671 | }; |
| ... | ... | @@ -23805,14 +23690,13 @@ fn checkPtrType( |
| 23805 | 23690 | .Fn => { |
| 23806 | 23691 | const msg = msg: { |
| 23807 | 23692 | const msg = try sema.errMsg( |
| 23808 | | block, |
| 23809 | 23693 | ty_src, |
| 23810 | 23694 | "expected pointer type, found '{}'", |
| 23811 | 23695 | .{ty.fmt(mod)}, |
| 23812 | 23696 | ); |
| 23813 | 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 | 23701 | break :msg msg; |
| 23818 | 23702 | }; |
| ... | ... | @@ -24066,26 +23950,26 @@ fn checkVectorizableBinaryOperands( |
| 24066 | 23950 | const rhs_len = rhs_ty.arrayLen(mod); |
| 24067 | 23951 | if (lhs_len != rhs_len) { |
| 24068 | 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 | 23954 | errdefer msg.destroy(sema.gpa); |
| 24071 | | try sema.errNote(block, lhs_src, msg, "length {d} here", .{lhs_len}); |
| 24072 | | try sema.errNote(block, rhs_src, msg, "length {d} here", .{rhs_len}); |
| 23955 | try sema.errNote(lhs_src, msg, "length {d} here", .{lhs_len}); |
| 23956 | try sema.errNote(rhs_src, msg, "length {d} here", .{rhs_len}); |
| 24073 | 23957 | break :msg msg; |
| 24074 | 23958 | }; |
| 24075 | 23959 | return sema.failWithOwnedErrorMsg(block, msg); |
| 24076 | 23960 | } |
| 24077 | 23961 | } else { |
| 24078 | 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 | 23964 | lhs_ty.fmt(mod), rhs_ty.fmt(mod), |
| 24081 | 23965 | }); |
| 24082 | 23966 | errdefer msg.destroy(sema.gpa); |
| 24083 | 23967 | if (lhs_is_vector) { |
| 24084 | | try sema.errNote(block, lhs_src, msg, "vector here", .{}); |
| 24085 | | try sema.errNote(block, rhs_src, msg, "scalar here", .{}); |
| 23968 | try sema.errNote(lhs_src, msg, "vector here", .{}); |
| 23969 | try sema.errNote(rhs_src, msg, "scalar here", .{}); |
| 24086 | 23970 | } else { |
| 24087 | | try sema.errNote(block, lhs_src, msg, "scalar here", .{}); |
| 24088 | | try sema.errNote(block, rhs_src, msg, "vector here", .{}); |
| 23971 | try sema.errNote(lhs_src, msg, "scalar here", .{}); |
| 23972 | try sema.errNote(rhs_src, msg, "vector here", .{}); |
| 24089 | 23973 | } |
| 24090 | 23974 | break :msg msg; |
| 24091 | 23975 | }; |
| ... | ... | @@ -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 | 23980 | fn resolveExportOptions( |
| 24103 | 23981 | sema: *Sema, |
| 24104 | 23982 | block: *Block, |
| ... | ... | @@ -24112,10 +23990,10 @@ fn resolveExportOptions( |
| 24112 | 23990 | const air_ref = try sema.resolveInst(zir_ref); |
| 24113 | 23991 | const options = try sema.coerce(block, export_options_ty, air_ref, src); |
| 24114 | 23992 | |
| 24115 | | const name_src = sema.maybeOptionsSrc(block, src, "name"); |
| 24116 | | const linkage_src = sema.maybeOptionsSrc(block, src, "linkage"); |
| 24117 | | const section_src = sema.maybeOptionsSrc(block, src, "section"); |
| 24118 | | const visibility_src = sema.maybeOptionsSrc(block, src, "visibility"); |
| 23993 | const name_src = block.src(.{ .init_field_name = src.offset.node_offset_builtin_call_arg.builtin_call_node }); |
| 23994 | const linkage_src = block.src(.{ .init_field_linkage = src.offset.node_offset_builtin_call_arg.builtin_call_node }); |
| 23995 | const section_src = block.src(.{ .init_field_section = src.offset.node_offset_builtin_call_arg.builtin_call_node }); |
| 23996 | const visibility_src = block.src(.{ .init_field_visibility = src.offset.node_offset_builtin_call_arg.builtin_call_node }); |
| 24119 | 23997 | |
| 24120 | 23998 | const name_operand = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "name", .no_embedded_nulls), name_src); |
| 24121 | 23999 | const name = try sema.toConstString(block, name_src, name_operand, .{ |
| ... | ... | @@ -24212,14 +24090,14 @@ fn zirCmpxchg( |
| 24212 | 24090 | 1 => .cmpxchg_strong, |
| 24213 | 24091 | else => unreachable, |
| 24214 | 24092 | }; |
| 24215 | | const src = LazySrcLoc.nodeOffset(extra.node); |
| 24093 | const src = block.nodeOffset(extra.node); |
| 24216 | 24094 | // zig fmt: off |
| 24217 | | const elem_ty_src : LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node }; |
| 24218 | | const ptr_src : LazySrcLoc = .{ .node_offset_builtin_call_arg1 = extra.node }; |
| 24219 | | const expected_src : LazySrcLoc = .{ .node_offset_builtin_call_arg2 = extra.node }; |
| 24220 | | const new_value_src : LazySrcLoc = .{ .node_offset_builtin_call_arg3 = extra.node }; |
| 24221 | | const success_order_src: LazySrcLoc = .{ .node_offset_builtin_call_arg4 = extra.node }; |
| 24222 | | const failure_order_src: LazySrcLoc = .{ .node_offset_builtin_call_arg5 = extra.node }; |
| 24095 | const elem_ty_src = block.builtinCallArgSrc(extra.node, 0); |
| 24096 | const ptr_src = block.builtinCallArgSrc(extra.node, 1); |
| 24097 | const expected_src = block.builtinCallArgSrc(extra.node, 2); |
| 24098 | const new_value_src = block.builtinCallArgSrc(extra.node, 3); |
| 24099 | const success_order_src = block.builtinCallArgSrc(extra.node, 4); |
| 24100 | const failure_order_src = block.builtinCallArgSrc(extra.node, 5); |
| 24223 | 24101 | // zig fmt: on |
| 24224 | 24102 | const expected_value = try sema.resolveInst(extra.expected_value); |
| 24225 | 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 | 24187 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 24310 | 24188 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 24311 | 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 | 24191 | const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu_opt, "@splat"); |
| 24314 | 24192 | |
| 24315 | 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 | 24215 | fn zirReduce(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 24338 | 24216 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 24339 | 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 }; |
| 24341 | | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; |
| 24218 | const op_src = block.builtinCallArgSrc(inst_data.src_node, 0); |
| 24219 | const operand_src = block.builtinCallArgSrc(inst_data.src_node, 1); |
| 24342 | 24220 | const operation = try sema.resolveBuiltinEnum(block, op_src, extra.lhs, "ReduceOp", .{ |
| 24343 | 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 | 24287 | const mod = sema.mod; |
| 24410 | 24288 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 24411 | 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 }; |
| 24413 | | const mask_src: LazySrcLoc = .{ .node_offset_builtin_call_arg3 = inst_data.src_node }; |
| 24290 | const elem_ty_src = block.builtinCallArgSrc(inst_data.src_node, 0); |
| 24291 | const mask_src = block.builtinCallArgSrc(inst_data.src_node, 3); |
| 24414 | 24292 | |
| 24415 | 24293 | const elem_ty = try sema.resolveType(block, elem_ty_src, extra.elem_type); |
| 24416 | 24294 | try sema.checkVectorElemType(block, elem_ty_src, elem_ty); |
| ... | ... | @@ -24445,9 +24323,9 @@ fn analyzeShuffle( |
| 24445 | 24323 | mask_len: u32, |
| 24446 | 24324 | ) CompileError!Air.Inst.Ref { |
| 24447 | 24325 | const mod = sema.mod; |
| 24448 | | const a_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = src_node }; |
| 24449 | | const b_src: LazySrcLoc = .{ .node_offset_builtin_call_arg2 = src_node }; |
| 24450 | | const mask_src: LazySrcLoc = .{ .node_offset_builtin_call_arg3 = src_node }; |
| 24326 | const a_src = block.builtinCallArgSrc(src_node, 1); |
| 24327 | const b_src = block.builtinCallArgSrc(src_node, 2); |
| 24328 | const mask_src = block.builtinCallArgSrc(src_node, 3); |
| 24451 | 24329 | var a = a_arg; |
| 24452 | 24330 | var b = b_arg; |
| 24453 | 24331 | |
| ... | ... | @@ -24511,16 +24389,16 @@ fn analyzeShuffle( |
| 24511 | 24389 | } |
| 24512 | 24390 | if (unsigned >= operand_info[chosen][0]) { |
| 24513 | 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 | 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 | 24396 | unsigned, |
| 24519 | 24397 | operand_info[chosen][2].fmt(sema.mod), |
| 24520 | 24398 | }); |
| 24521 | 24399 | |
| 24522 | 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 | 24404 | break :msg msg; |
| ... | ... | @@ -24598,11 +24476,11 @@ fn zirSelect(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) C |
| 24598 | 24476 | const mod = sema.mod; |
| 24599 | 24477 | const extra = sema.code.extraData(Zir.Inst.Select, extended.operand).data; |
| 24600 | 24478 | |
| 24601 | | const src = LazySrcLoc.nodeOffset(extra.node); |
| 24602 | | const elem_ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node }; |
| 24603 | | const pred_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = extra.node }; |
| 24604 | | const a_src: LazySrcLoc = .{ .node_offset_builtin_call_arg2 = extra.node }; |
| 24605 | | const b_src: LazySrcLoc = .{ .node_offset_builtin_call_arg3 = extra.node }; |
| 24479 | const src = block.nodeOffset(extra.node); |
| 24480 | const elem_ty_src = block.builtinCallArgSrc(extra.node, 0); |
| 24481 | const pred_src = block.builtinCallArgSrc(extra.node, 1); |
| 24482 | const a_src = block.builtinCallArgSrc(extra.node, 2); |
| 24483 | const b_src = block.builtinCallArgSrc(extra.node, 3); |
| 24606 | 24484 | |
| 24607 | 24485 | const elem_ty = try sema.resolveType(block, elem_ty_src, extra.elem_type); |
| 24608 | 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 | 24567 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 24690 | 24568 | const extra = sema.code.extraData(Zir.Inst.AtomicLoad, inst_data.payload_index).data; |
| 24691 | 24569 | // zig fmt: off |
| 24692 | | const elem_ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 24693 | | const ptr_src : LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; |
| 24694 | | const order_src : LazySrcLoc = .{ .node_offset_builtin_call_arg2 = inst_data.src_node }; |
| 24570 | const elem_ty_src = block.builtinCallArgSrc(inst_data.src_node, 0); |
| 24571 | const ptr_src = block.builtinCallArgSrc(inst_data.src_node, 1); |
| 24572 | const order_src = block.builtinCallArgSrc(inst_data.src_node, 2); |
| 24695 | 24573 | // zig fmt: on |
| 24696 | 24574 | const elem_ty = try sema.resolveType(block, elem_ty_src, extra.elem_type); |
| 24697 | 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 | 24616 | const extra = sema.code.extraData(Zir.Inst.AtomicRmw, inst_data.payload_index).data; |
| 24739 | 24617 | const src = block.nodeOffset(inst_data.src_node); |
| 24740 | 24618 | // zig fmt: off |
| 24741 | | const elem_ty_src : LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 24742 | | const ptr_src : LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; |
| 24743 | | const op_src : LazySrcLoc = .{ .node_offset_builtin_call_arg2 = inst_data.src_node }; |
| 24744 | | const operand_src : LazySrcLoc = .{ .node_offset_builtin_call_arg3 = inst_data.src_node }; |
| 24745 | | const order_src : LazySrcLoc = .{ .node_offset_builtin_call_arg4 = inst_data.src_node }; |
| 24619 | const elem_ty_src = block.builtinCallArgSrc(inst_data.src_node, 0); |
| 24620 | const ptr_src = block.builtinCallArgSrc(inst_data.src_node, 1); |
| 24621 | const op_src = block.builtinCallArgSrc(inst_data.src_node, 2); |
| 24622 | const operand_src = block.builtinCallArgSrc(inst_data.src_node, 3); |
| 24623 | const order_src = block.builtinCallArgSrc(inst_data.src_node, 4); |
| 24746 | 24624 | // zig fmt: on |
| 24747 | 24625 | const operand = try sema.resolveInst(extra.operand); |
| 24748 | 24626 | const elem_ty = sema.typeOf(operand); |
| ... | ... | @@ -24823,10 +24701,10 @@ fn zirAtomicStore(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 24823 | 24701 | const extra = sema.code.extraData(Zir.Inst.AtomicStore, inst_data.payload_index).data; |
| 24824 | 24702 | const src = block.nodeOffset(inst_data.src_node); |
| 24825 | 24703 | // zig fmt: off |
| 24826 | | const elem_ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 24827 | | const ptr_src : LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; |
| 24828 | | const operand_src : LazySrcLoc = .{ .node_offset_builtin_call_arg2 = inst_data.src_node }; |
| 24829 | | const order_src : LazySrcLoc = .{ .node_offset_builtin_call_arg3 = inst_data.src_node }; |
| 24704 | const elem_ty_src = block.builtinCallArgSrc(inst_data.src_node, 0); |
| 24705 | const ptr_src = block.builtinCallArgSrc(inst_data.src_node, 1); |
| 24706 | const operand_src = block.builtinCallArgSrc(inst_data.src_node, 2); |
| 24707 | const order_src = block.builtinCallArgSrc(inst_data.src_node, 3); |
| 24830 | 24708 | // zig fmt: on |
| 24831 | 24709 | const operand = try sema.resolveInst(extra.operand); |
| 24832 | 24710 | const elem_ty = sema.typeOf(operand); |
| ... | ... | @@ -24859,9 +24737,9 @@ fn zirMulAdd(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. |
| 24859 | 24737 | const extra = sema.code.extraData(Zir.Inst.MulAdd, inst_data.payload_index).data; |
| 24860 | 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 }; |
| 24863 | | const mulend2_src: LazySrcLoc = .{ .node_offset_builtin_call_arg2 = inst_data.src_node }; |
| 24864 | | const addend_src: LazySrcLoc = .{ .node_offset_builtin_call_arg3 = inst_data.src_node }; |
| 24740 | const mulend1_src = block.builtinCallArgSrc(inst_data.src_node, 1); |
| 24741 | const mulend2_src = block.builtinCallArgSrc(inst_data.src_node, 2); |
| 24742 | const addend_src = block.builtinCallArgSrc(inst_data.src_node, 3); |
| 24865 | 24743 | |
| 24866 | 24744 | const addend = try sema.resolveInst(extra.addend); |
| 24867 | 24745 | const ty = sema.typeOf(addend); |
| ... | ... | @@ -24924,9 +24802,9 @@ fn zirBuiltinCall(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 24924 | 24802 | |
| 24925 | 24803 | const mod = sema.mod; |
| 24926 | 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 }; |
| 24928 | | const func_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; |
| 24929 | | const args_src: LazySrcLoc = .{ .node_offset_builtin_call_arg2 = inst_data.src_node }; |
| 24805 | const modifier_src = block.builtinCallArgSrc(inst_data.src_node, 0); |
| 24806 | const func_src = block.builtinCallArgSrc(inst_data.src_node, 1); |
| 24807 | const args_src = block.builtinCallArgSrc(inst_data.src_node, 2); |
| 24930 | 24808 | const call_src = block.nodeOffset(inst_data.src_node); |
| 24931 | 24809 | |
| 24932 | 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 | 24900 | const flags: Zir.Inst.FullPtrCastFlags = @bitCast(@as(FlagsInt, @truncate(extended.small))); |
| 25023 | 24901 | assert(!flags.ptr_cast); |
| 25024 | 24902 | const inst_src = block.nodeOffset(extra.src_node); |
| 25025 | | const field_name_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.src_node }; |
| 25026 | | const field_ptr_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = extra.src_node }; |
| 24903 | const field_name_src = block.builtinCallArgSrc(extra.src_node, 0); |
| 24904 | const field_ptr_src = block.builtinCallArgSrc(extra.src_node, 1); |
| 25027 | 24905 | |
| 25028 | 24906 | const parent_ptr_ty = try sema.resolveDestType(block, inst_src, extra.parent_ptr_type, .remove_eu, "@fieldParentPtr"); |
| 25029 | 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 | 25090 | }; |
| 25213 | 25091 | if (ptr.byte_offset < byte_subtract) { |
| 25214 | 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 | 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 | 25096 | break :msg msg; |
| 25219 | 25097 | }); |
| 25220 | 25098 | } |
| ... | ... | @@ -25232,8 +25110,8 @@ fn zirMinMax( |
| 25232 | 25110 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 25233 | 25111 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 25234 | 25112 | const src = block.nodeOffset(inst_data.src_node); |
| 25235 | | const lhs_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 25236 | | const rhs_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; |
| 25113 | const lhs_src = block.builtinCallArgSrc(inst_data.src_node, 0); |
| 25114 | const rhs_src = block.builtinCallArgSrc(inst_data.src_node, 1); |
| 25237 | 25115 | const lhs = try sema.resolveInst(extra.lhs); |
| 25238 | 25116 | const rhs = try sema.resolveInst(extra.rhs); |
| 25239 | 25117 | try sema.checkNumericType(block, lhs_src, sema.typeOf(lhs)); |
| ... | ... | @@ -25249,22 +25127,14 @@ fn zirMinMaxMulti( |
| 25249 | 25127 | ) CompileError!Air.Inst.Ref { |
| 25250 | 25128 | const extra = sema.code.extraData(Zir.Inst.NodeMultiOp, extended.operand); |
| 25251 | 25129 | const src_node = extra.data.src_node; |
| 25252 | | const src = LazySrcLoc.nodeOffset(src_node); |
| 25130 | const src = block.nodeOffset(src_node); |
| 25253 | 25131 | const operands = sema.code.refSlice(extra.end, extended.small); |
| 25254 | 25132 | |
| 25255 | 25133 | const air_refs = try sema.arena.alloc(Air.Inst.Ref, operands.len); |
| 25256 | 25134 | const operand_srcs = try sema.arena.alloc(LazySrcLoc, operands.len); |
| 25257 | 25135 | |
| 25258 | 25136 | for (operands, air_refs, operand_srcs, 0..) |zir_ref, *air_ref, *op_src, i| { |
| 25259 | | op_src.* = switch (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 | | }; |
| 25137 | op_src.* = block.builtinCallArgSrc(src_node, @intCast(i)); |
| 25268 | 25138 | air_ref.* = try sema.resolveInst(zir_ref); |
| 25269 | 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 | 25403 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 25534 | 25404 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 25535 | 25405 | const src = block.nodeOffset(inst_data.src_node); |
| 25536 | | const dest_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 25537 | | const src_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; |
| 25406 | const dest_src = block.builtinCallArgSrc(inst_data.src_node, 0); |
| 25407 | const src_src = block.builtinCallArgSrc(inst_data.src_node, 1); |
| 25538 | 25408 | const dest_ptr = try sema.resolveInst(extra.lhs); |
| 25539 | 25409 | const src_ptr = try sema.resolveInst(extra.rhs); |
| 25540 | 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 | 25420 | |
| 25551 | 25421 | if (dest_len == .none and src_len == .none) { |
| 25552 | 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 | 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 | 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 | 25429 | src_ty.fmt(sema.mod), |
| 25560 | 25430 | }); |
| 25561 | 25431 | break :msg msg; |
| ... | ... | @@ -25572,12 +25442,12 @@ fn zirMemcpy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void |
| 25572 | 25442 | if (try sema.resolveDefinedValue(block, src_src, src_len)) |src_len_val| { |
| 25573 | 25443 | if (!(try sema.valuesEqual(dest_len_val, src_len_val, Type.usize))) { |
| 25574 | 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 | 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 | 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 | 25451 | src_len_val.fmtValue(sema.mod, sema), |
| 25582 | 25452 | }); |
| 25583 | 25453 | break :msg msg; |
| ... | ... | @@ -25685,7 +25555,7 @@ fn zirMemcpy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void |
| 25685 | 25555 | } else if (dest_len == .none and len_val == null) { |
| 25686 | 25556 | // Change the dest to a slice, since its type must have the length. |
| 25687 | 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 | 25559 | const new_src_ptr_ty = sema.typeOf(new_src_ptr); |
| 25690 | 25560 | if (new_src_ptr_ty.isSlice(mod)) { |
| 25691 | 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 | 25623 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 25754 | 25624 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 25755 | 25625 | const src = block.nodeOffset(inst_data.src_node); |
| 25756 | | const dest_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 25757 | | const value_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; |
| 25626 | const dest_src = block.builtinCallArgSrc(inst_data.src_node, 0); |
| 25627 | const value_src = block.builtinCallArgSrc(inst_data.src_node, 1); |
| 25758 | 25628 | const dest_ptr = try sema.resolveInst(extra.lhs); |
| 25759 | 25629 | const uncoerced_elem = try sema.resolveInst(extra.rhs); |
| 25760 | 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 | 25646 | .Many, .C => {}, |
| 25777 | 25647 | } |
| 25778 | 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 | 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 | 25652 | dest_ptr_ty.fmt(mod), |
| 25783 | 25653 | }); |
| 25784 | 25654 | break :msg msg; |
| ... | ... | @@ -25831,7 +25701,7 @@ fn zirMemset(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void |
| 25831 | 25701 | |
| 25832 | 25702 | fn zirBuiltinAsyncCall(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!Air.Inst.Ref { |
| 25833 | 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 | 25705 | return sema.failWithUseOfAsync(block, src); |
| 25836 | 25706 | } |
| 25837 | 25707 | |
| ... | ... | @@ -25858,7 +25728,7 @@ fn zirAwaitNosuspend( |
| 25858 | 25728 | extended: Zir.Inst.Extended.InstData, |
| 25859 | 25729 | ) CompileError!Air.Inst.Ref { |
| 25860 | 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 | 25733 | return sema.failWithUseOfAsync(block, src); |
| 25864 | 25734 | } |
| ... | ... | @@ -25870,8 +25740,8 @@ fn zirVarExtended( |
| 25870 | 25740 | ) CompileError!Air.Inst.Ref { |
| 25871 | 25741 | const mod = sema.mod; |
| 25872 | 25742 | const extra = sema.code.extraData(Zir.Inst.ExtendedVar, extended.operand); |
| 25873 | | const ty_src: LazySrcLoc = .{ .node_offset_var_decl_ty = 0 }; |
| 25874 | | const init_src: LazySrcLoc = .{ .node_offset_var_decl_init = 0 }; |
| 25743 | const ty_src = block.src(.{ .node_offset_var_decl_ty = 0 }); |
| 25744 | const init_src = block.src(.{ .node_offset_var_decl_init = 0 }); |
| 25875 | 25745 | const small: Zir.Inst.ExtendedVar.Small = @bitCast(extended.small); |
| 25876 | 25746 | |
| 25877 | 25747 | var extra_index: usize = extra.end; |
| ... | ... | @@ -25936,11 +25806,11 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 25936 | 25806 | const extra = sema.code.extraData(Zir.Inst.FuncFancy, inst_data.payload_index); |
| 25937 | 25807 | const target = mod.getTarget(); |
| 25938 | 25808 | |
| 25939 | | const align_src: LazySrcLoc = .{ .node_offset_fn_type_align = inst_data.src_node }; |
| 25940 | | const addrspace_src: LazySrcLoc = .{ .node_offset_fn_type_addrspace = inst_data.src_node }; |
| 25941 | | const section_src: LazySrcLoc = .{ .node_offset_fn_type_section = inst_data.src_node }; |
| 25942 | | const cc_src: LazySrcLoc = .{ .node_offset_fn_type_cc = inst_data.src_node }; |
| 25943 | | const ret_src: LazySrcLoc = .{ .node_offset_fn_type_ret_ty = inst_data.src_node }; |
| 25809 | const align_src = block.src(.{ .node_offset_fn_type_align = inst_data.src_node }); |
| 25810 | const addrspace_src = block.src(.{ .node_offset_fn_type_addrspace = inst_data.src_node }); |
| 25811 | const section_src = block.src(.{ .node_offset_fn_type_section = inst_data.src_node }); |
| 25812 | const cc_src = block.src(.{ .node_offset_fn_type_cc = inst_data.src_node }); |
| 25813 | const ret_src = block.src(.{ .node_offset_fn_type_ret_ty = inst_data.src_node }); |
| 25944 | 25814 | const has_body = extra.data.body_len != 0; |
| 25945 | 25815 | |
| 25946 | 25816 | var extra_index: usize = extra.end; |
| ... | ... | @@ -26167,7 +26037,7 @@ fn zirCUndef( |
| 26167 | 26037 | extended: Zir.Inst.Extended.InstData, |
| 26168 | 26038 | ) CompileError!Air.Inst.Ref { |
| 26169 | 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 | 26042 | const name = try sema.resolveConstString(block, src, extra.operand, .{ |
| 26173 | 26043 | .needed_comptime_reason = "name of macro being undefined must be comptime-known", |
| ... | ... | @@ -26182,7 +26052,7 @@ fn zirCInclude( |
| 26182 | 26052 | extended: Zir.Inst.Extended.InstData, |
| 26183 | 26053 | ) CompileError!Air.Inst.Ref { |
| 26184 | 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 | 26057 | const name = try sema.resolveConstString(block, src, extra.operand, .{ |
| 26188 | 26058 | .needed_comptime_reason = "path being included must be comptime-known", |
| ... | ... | @@ -26198,8 +26068,8 @@ fn zirCDefine( |
| 26198 | 26068 | ) CompileError!Air.Inst.Ref { |
| 26199 | 26069 | const mod = sema.mod; |
| 26200 | 26070 | const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data; |
| 26201 | | const name_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node }; |
| 26202 | | const val_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = extra.node }; |
| 26071 | const name_src = block.builtinCallArgSrc(extra.node, 0); |
| 26072 | const val_src = block.builtinCallArgSrc(extra.node, 1); |
| 26203 | 26073 | |
| 26204 | 26074 | const name = try sema.resolveConstString(block, name_src, extra.lhs, .{ |
| 26205 | 26075 | .needed_comptime_reason = "name of macro being undefined must be comptime-known", |
| ... | ... | @@ -26222,8 +26092,8 @@ fn zirWasmMemorySize( |
| 26222 | 26092 | extended: Zir.Inst.Extended.InstData, |
| 26223 | 26093 | ) CompileError!Air.Inst.Ref { |
| 26224 | 26094 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; |
| 26225 | | const index_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node }; |
| 26226 | | const builtin_src = LazySrcLoc.nodeOffset(extra.node); |
| 26095 | const index_src = block.builtinCallArgSrc(extra.node, 0); |
| 26096 | const builtin_src = block.nodeOffset(extra.node); |
| 26227 | 26097 | const target = sema.mod.getTarget(); |
| 26228 | 26098 | if (!target.isWasm()) { |
| 26229 | 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 | 26118 | extended: Zir.Inst.Extended.InstData, |
| 26249 | 26119 | ) CompileError!Air.Inst.Ref { |
| 26250 | 26120 | const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data; |
| 26251 | | const builtin_src = LazySrcLoc.nodeOffset(extra.node); |
| 26252 | | const index_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node }; |
| 26253 | | const delta_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = extra.node }; |
| 26121 | const builtin_src = block.nodeOffset(extra.node); |
| 26122 | const index_src = block.builtinCallArgSrc(extra.node, 0); |
| 26123 | const delta_src = block.builtinCallArgSrc(extra.node, 1); |
| 26254 | 26124 | const target = sema.mod.getTarget(); |
| 26255 | 26125 | if (!target.isWasm()) { |
| 26256 | 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 | 26153 | const options_ty = try sema.getBuiltinType("PrefetchOptions"); |
| 26284 | 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"); |
| 26287 | | const locality_src = sema.maybeOptionsSrc(block, src, "locality"); |
| 26288 | | const cache_src = sema.maybeOptionsSrc(block, src, "cache"); |
| 26156 | const rw_src = block.src(.{ .init_field_rw = src.offset.node_offset_builtin_call_arg.builtin_call_node }); |
| 26157 | const locality_src = block.src(.{ .init_field_locality = src.offset.node_offset_builtin_call_arg.builtin_call_node }); |
| 26158 | const cache_src = block.src(.{ .init_field_cache = src.offset.node_offset_builtin_call_arg.builtin_call_node }); |
| 26289 | 26159 | |
| 26290 | 26160 | const rw = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "rw", .no_embedded_nulls), rw_src); |
| 26291 | 26161 | const rw_val = try sema.resolveConstDefinedValue(block, rw_src, rw, .{ |
| ... | ... | @@ -26315,18 +26185,12 @@ fn zirPrefetch( |
| 26315 | 26185 | extended: Zir.Inst.Extended.InstData, |
| 26316 | 26186 | ) CompileError!Air.Inst.Ref { |
| 26317 | 26187 | const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data; |
| 26318 | | const ptr_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node }; |
| 26319 | | const opts_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = extra.node }; |
| 26188 | const ptr_src = block.builtinCallArgSrc(extra.node, 0); |
| 26189 | const opts_src = block.builtinCallArgSrc(extra.node, 1); |
| 26320 | 26190 | const ptr = try sema.resolveInst(extra.lhs); |
| 26321 | 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) { |
| 26324 | | error.NeededSourceLocation => { |
| 26325 | | _ = try sema.resolvePrefetchOptions(block, opts_src, extra.rhs); |
| 26326 | | unreachable; |
| 26327 | | }, |
| 26328 | | else => |e| return e, |
| 26329 | | }; |
| 26193 | const options = try sema.resolvePrefetchOptions(block, opts_src, extra.rhs); |
| 26330 | 26194 | |
| 26331 | 26195 | if (!block.is_comptime) { |
| 26332 | 26196 | _ = try block.addInst(.{ |
| ... | ... | @@ -26361,10 +26225,10 @@ fn resolveExternOptions( |
| 26361 | 26225 | const extern_options_ty = try sema.getBuiltinType("ExternOptions"); |
| 26362 | 26226 | const options = try sema.coerce(block, extern_options_ty, options_inst, src); |
| 26363 | 26227 | |
| 26364 | | const name_src = sema.maybeOptionsSrc(block, src, "name"); |
| 26365 | | const library_src = sema.maybeOptionsSrc(block, src, "library"); |
| 26366 | | const linkage_src = sema.maybeOptionsSrc(block, src, "linkage"); |
| 26367 | | const thread_local_src = sema.maybeOptionsSrc(block, src, "thread_local"); |
| 26228 | const name_src = block.src(.{ .init_field_name = src.offset.node_offset_builtin_call_arg.builtin_call_node }); |
| 26229 | const library_src = block.src(.{ .init_field_library = src.offset.node_offset_builtin_call_arg.builtin_call_node }); |
| 26230 | const linkage_src = block.src(.{ .init_field_linkage = src.offset.node_offset_builtin_call_arg.builtin_call_node }); |
| 26231 | const thread_local_src = block.src(.{ .init_field_thread_local = src.offset.node_offset_builtin_call_arg.builtin_call_node }); |
| 26368 | 26232 | |
| 26369 | 26233 | const name_ref = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "name", .no_embedded_nulls), name_src); |
| 26370 | 26234 | const name = try sema.toConstString(block, name_src, name_ref, .{ |
| ... | ... | @@ -26422,8 +26286,8 @@ fn zirBuiltinExtern( |
| 26422 | 26286 | const mod = sema.mod; |
| 26423 | 26287 | const ip = &mod.intern_pool; |
| 26424 | 26288 | const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data; |
| 26425 | | const ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node }; |
| 26426 | | const options_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = extra.node }; |
| 26289 | const ty_src = block.builtinCallArgSrc(extra.node, 0); |
| 26290 | const options_src = block.builtinCallArgSrc(extra.node, 1); |
| 26427 | 26291 | |
| 26428 | 26292 | var ty = try sema.resolveType(block, ty_src, extra.lhs); |
| 26429 | 26293 | if (!ty.isPtrAtRuntime(mod)) { |
| ... | ... | @@ -26431,29 +26295,22 @@ fn zirBuiltinExtern( |
| 26431 | 26295 | } |
| 26432 | 26296 | if (!try sema.validateExternType(ty, .other)) { |
| 26433 | 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 | 26299 | errdefer msg.destroy(sema.gpa); |
| 26436 | | const src_decl = sema.mod.declPtr(block.src_decl); |
| 26437 | | try sema.explainWhyTypeIsNotExtern(msg, src_decl.toSrcLoc(ty_src, mod), ty, .other); |
| 26300 | try sema.explainWhyTypeIsNotExtern(msg, ty_src, ty, .other); |
| 26438 | 26301 | break :msg msg; |
| 26439 | 26302 | }; |
| 26440 | 26303 | return sema.failWithOwnedErrorMsg(block, msg); |
| 26441 | 26304 | } |
| 26442 | 26305 | |
| 26443 | | const options = sema.resolveExternOptions(block, .unneeded, extra.rhs) catch |err| switch (err) { |
| 26444 | | error.NeededSourceLocation => { |
| 26445 | | _ = try sema.resolveExternOptions(block, options_src, extra.rhs); |
| 26446 | | unreachable; |
| 26447 | | }, |
| 26448 | | else => |e| return e, |
| 26449 | | }; |
| 26306 | const options = try sema.resolveExternOptions(block, options_src, extra.rhs); |
| 26450 | 26307 | |
| 26451 | 26308 | if (options.linkage == .weak and !ty.ptrAllowsZero(mod)) { |
| 26452 | 26309 | ty = try mod.optionalType(ty.toIntern()); |
| 26453 | 26310 | } |
| 26454 | 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 | 26314 | errdefer mod.destroyDecl(new_decl_index); |
| 26458 | 26315 | const new_decl = mod.declPtr(new_decl_index); |
| 26459 | 26316 | try mod.initNewAnonDecl( |
| ... | ... | @@ -26503,8 +26360,8 @@ fn zirWorkItem( |
| 26503 | 26360 | zir_tag: Zir.Inst.Extended, |
| 26504 | 26361 | ) CompileError!Air.Inst.Ref { |
| 26505 | 26362 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; |
| 26506 | | const dimension_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node }; |
| 26507 | | const builtin_src = LazySrcLoc.nodeOffset(extra.node); |
| 26363 | const dimension_src = block.builtinCallArgSrc(extra.node, 0); |
| 26364 | const builtin_src = block.nodeOffset(extra.node); |
| 26508 | 26365 | const target = sema.mod.getTarget(); |
| 26509 | 26366 | |
| 26510 | 26367 | switch (target.cpu.arch) { |
| ... | ... | @@ -26545,11 +26402,11 @@ fn zirInComptime( |
| 26545 | 26402 | fn requireRuntimeBlock(sema: *Sema, block: *Block, src: LazySrcLoc, runtime_src: ?LazySrcLoc) !void { |
| 26546 | 26403 | if (block.is_comptime) { |
| 26547 | 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 | 26406 | errdefer msg.destroy(sema.gpa); |
| 26550 | 26407 | |
| 26551 | 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 | 26411 | if (block.comptime_reason) |some| { |
| 26555 | 26412 | try some.explain(sema, msg); |
| ... | ... | @@ -26572,10 +26429,9 @@ fn validateVarType( |
| 26572 | 26429 | if (is_extern) { |
| 26573 | 26430 | if (!try sema.validateExternType(var_ty, .other)) { |
| 26574 | 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 | 26433 | errdefer msg.destroy(sema.gpa); |
| 26577 | | const src_decl = mod.declPtr(block.src_decl); |
| 26578 | | try sema.explainWhyTypeIsNotExtern(msg, src_decl.toSrcLoc(src, mod), var_ty, .other); |
| 26434 | try sema.explainWhyTypeIsNotExtern(msg, src, var_ty, .other); |
| 26579 | 26435 | break :msg msg; |
| 26580 | 26436 | }; |
| 26581 | 26437 | return sema.failWithOwnedErrorMsg(block, msg); |
| ... | ... | @@ -26594,13 +26450,12 @@ fn validateVarType( |
| 26594 | 26450 | if (!try sema.typeRequiresComptime(var_ty)) return; |
| 26595 | 26451 | |
| 26596 | 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 | 26454 | errdefer msg.destroy(sema.gpa); |
| 26599 | 26455 | |
| 26600 | | const src_decl = mod.declPtr(block.src_decl); |
| 26601 | | try sema.explainWhyTypeIsComptime(msg, src_decl.toSrcLoc(src, mod), var_ty); |
| 26456 | try sema.explainWhyTypeIsComptime(msg, src, var_ty); |
| 26602 | 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 | 26461 | break :msg msg; |
| ... | ... | @@ -26613,7 +26468,7 @@ const TypeSet = std.AutoHashMapUnmanaged(InternPool.Index, void); |
| 26613 | 26468 | fn explainWhyTypeIsComptime( |
| 26614 | 26469 | sema: *Sema, |
| 26615 | 26470 | msg: *Module.ErrorMsg, |
| 26616 | | src_loc: Module.SrcLoc, |
| 26471 | src_loc: LazySrcLoc, |
| 26617 | 26472 | ty: Type, |
| 26618 | 26473 | ) CompileError!void { |
| 26619 | 26474 | var type_set = TypeSet{}; |
| ... | ... | @@ -26626,7 +26481,7 @@ fn explainWhyTypeIsComptime( |
| 26626 | 26481 | fn explainWhyTypeIsComptimeInner( |
| 26627 | 26482 | sema: *Sema, |
| 26628 | 26483 | msg: *Module.ErrorMsg, |
| 26629 | | src_loc: Module.SrcLoc, |
| 26484 | src_loc: LazySrcLoc, |
| 26630 | 26485 | ty: Type, |
| 26631 | 26486 | type_set: *TypeSet, |
| 26632 | 26487 | ) CompileError!void { |
| ... | ... | @@ -26644,13 +26499,13 @@ fn explainWhyTypeIsComptimeInner( |
| 26644 | 26499 | => return, |
| 26645 | 26500 | |
| 26646 | 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 | 26503 | ty.fmt(sema.mod), |
| 26649 | 26504 | }); |
| 26650 | 26505 | }, |
| 26651 | 26506 | |
| 26652 | 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 | 26511 | .ComptimeFloat, |
| ... | ... | @@ -26662,7 +26517,7 @@ fn explainWhyTypeIsComptimeInner( |
| 26662 | 26517 | => return, |
| 26663 | 26518 | |
| 26664 | 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 | 26523 | .Array, .Vector => { |
| ... | ... | @@ -26673,14 +26528,14 @@ fn explainWhyTypeIsComptimeInner( |
| 26673 | 26528 | if (elem_ty.zigTypeTag(mod) == .Fn) { |
| 26674 | 26529 | const fn_info = mod.typeToFunc(elem_ty).?; |
| 26675 | 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 | 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 | 26535 | else => {}, |
| 26681 | 26536 | } |
| 26682 | 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 | 26540 | return; |
| 26686 | 26541 | } |
| ... | ... | @@ -26700,14 +26555,14 @@ fn explainWhyTypeIsComptimeInner( |
| 26700 | 26555 | if (mod.typeToStruct(ty)) |struct_type| { |
| 26701 | 26556 | for (0..struct_type.field_types.len) |i| { |
| 26702 | 26557 | const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[i]); |
| 26703 | | const field_src_loc = mod.fieldSrcLoc(struct_type.decl.unwrap().?, .{ |
| 26704 | | .index = i, |
| 26705 | | .range = .type, |
| 26706 | | }); |
| 26558 | const field_src: LazySrcLoc = .{ |
| 26559 | .base_node_inst = struct_type.zir_index.unwrap().?, |
| 26560 | .offset = .{ .container_field_type = @intCast(i) }, |
| 26561 | }; |
| 26707 | 26562 | |
| 26708 | 26563 | if (try sema.typeRequiresComptime(field_ty)) { |
| 26709 | | try mod.errNoteNonLazy(field_src_loc, msg, "struct requires comptime because of this field", .{}); |
| 26710 | | try sema.explainWhyTypeIsComptimeInner(msg, field_src_loc, field_ty, type_set); |
| 26564 | try sema.errNote(field_src, msg, "struct requires comptime because of this field", .{}); |
| 26565 | try sema.explainWhyTypeIsComptimeInner(msg, field_src, field_ty, type_set); |
| 26711 | 26566 | } |
| 26712 | 26567 | } |
| 26713 | 26568 | } |
| ... | ... | @@ -26720,14 +26575,14 @@ fn explainWhyTypeIsComptimeInner( |
| 26720 | 26575 | if (mod.typeToUnion(ty)) |union_obj| { |
| 26721 | 26576 | for (0..union_obj.field_types.len) |i| { |
| 26722 | 26577 | const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[i]); |
| 26723 | | const field_src_loc = mod.fieldSrcLoc(union_obj.decl, .{ |
| 26724 | | .index = i, |
| 26725 | | .range = .type, |
| 26726 | | }); |
| 26578 | const field_src: LazySrcLoc = .{ |
| 26579 | .base_node_inst = union_obj.zir_index, |
| 26580 | .offset = .{ .container_field_type = @intCast(i) }, |
| 26581 | }; |
| 26727 | 26582 | |
| 26728 | 26583 | if (try sema.typeRequiresComptime(field_ty)) { |
| 26729 | | try mod.errNoteNonLazy(field_src_loc, msg, "union requires comptime because of this field", .{}); |
| 26730 | | try sema.explainWhyTypeIsComptimeInner(msg, field_src_loc, field_ty, type_set); |
| 26584 | try sema.errNote(field_src, msg, "union requires comptime because of this field", .{}); |
| 26585 | try sema.explainWhyTypeIsComptimeInner(msg, field_src, field_ty, type_set); |
| 26731 | 26586 | } |
| 26732 | 26587 | } |
| 26733 | 26588 | } |
| ... | ... | @@ -26817,7 +26672,7 @@ fn validateExternType( |
| 26817 | 26672 | fn explainWhyTypeIsNotExtern( |
| 26818 | 26673 | sema: *Sema, |
| 26819 | 26674 | msg: *Module.ErrorMsg, |
| 26820 | | src_loc: Module.SrcLoc, |
| 26675 | src_loc: LazySrcLoc, |
| 26821 | 26676 | ty: Type, |
| 26822 | 26677 | position: ExternPosition, |
| 26823 | 26678 | ) CompileError!void { |
| ... | ... | @@ -26842,55 +26697,55 @@ fn explainWhyTypeIsNotExtern( |
| 26842 | 26697 | |
| 26843 | 26698 | .Pointer => { |
| 26844 | 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 | 26701 | } else { |
| 26847 | 26702 | const pointee_ty = ty.childType(mod); |
| 26848 | 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 | 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 | 26707 | try sema.explainWhyTypeIsComptime(msg, src_loc, ty); |
| 26853 | 26708 | } |
| 26854 | 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'", .{}), |
| 26858 | | .NoReturn => try mod.errNoteNonLazy(src_loc, msg, "'noreturn' is only allowed as a return type", .{}), |
| 26712 | .Void => try sema.errNote(src_loc, msg, "'void' is a zero bit type; for C 'void' use 'anyopaque'", .{}), |
| 26713 | .NoReturn => try sema.errNote(src_loc, msg, "'noreturn' is only allowed as a return type", .{}), |
| 26859 | 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 | 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 | 26719 | .Fn => { |
| 26865 | 26720 | if (position != .other) { |
| 26866 | | try mod.errNoteNonLazy(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", .{}); |
| 26721 | try sema.errNote(src_loc, msg, "type has no guaranteed in-memory representation", .{}); |
| 26722 | try sema.errNote(src_loc, msg, "use '*const ' to make a function pointer type", .{}); |
| 26868 | 26723 | return; |
| 26869 | 26724 | } |
| 26870 | 26725 | switch (ty.fnCallingConvention(mod)) { |
| 26871 | | .Unspecified => try mod.errNoteNonLazy(src_loc, msg, "extern function must specify calling convention", .{}), |
| 26872 | | .Async => try mod.errNoteNonLazy(src_loc, msg, "async function cannot be extern", .{}), |
| 26873 | | .Inline => try mod.errNoteNonLazy(src_loc, msg, "inline function cannot be extern", .{}), |
| 26726 | .Unspecified => try sema.errNote(src_loc, msg, "extern function must specify calling convention", .{}), |
| 26727 | .Async => try sema.errNote(src_loc, msg, "async function cannot be extern", .{}), |
| 26728 | .Inline => try sema.errNote(src_loc, msg, "inline function cannot be extern", .{}), |
| 26874 | 26729 | else => return, |
| 26875 | 26730 | } |
| 26876 | 26731 | }, |
| 26877 | 26732 | .Enum => { |
| 26878 | 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 | 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", .{}), |
| 26883 | | .Union => try mod.errNoteNonLazy(src_loc, msg, "only extern unions and ABI sized packed unions are extern compatible", .{}), |
| 26737 | .Struct => try sema.errNote(src_loc, msg, "only extern structs and ABI sized packed structs are extern compatible", .{}), |
| 26738 | .Union => try sema.errNote(src_loc, msg, "only extern unions and ABI sized packed unions are extern compatible", .{}), |
| 26884 | 26739 | .Array => { |
| 26885 | 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 | 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 | 26745 | try sema.explainWhyTypeIsNotExtern(msg, src_loc, ty.elemType2(mod), .element); |
| 26891 | 26746 | }, |
| 26892 | 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 | 26788 | fn explainWhyTypeIsNotPacked( |
| 26934 | 26789 | sema: *Sema, |
| 26935 | 26790 | msg: *Module.ErrorMsg, |
| 26936 | | src_loc: Module.SrcLoc, |
| 26791 | src_loc: LazySrcLoc, |
| 26937 | 26792 | ty: Type, |
| 26938 | 26793 | ) CompileError!void { |
| 26939 | 26794 | const mod = sema.mod; |
| ... | ... | @@ -26959,19 +26814,19 @@ fn explainWhyTypeIsNotPacked( |
| 26959 | 26814 | .AnyFrame, |
| 26960 | 26815 | .Optional, |
| 26961 | 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 | 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 | 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 | 26822 | try sema.explainWhyTypeIsComptime(msg, src_loc, ty); |
| 26968 | 26823 | }, |
| 26969 | 26824 | .Fn => { |
| 26970 | | try mod.errNoteNonLazy(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", .{}); |
| 26825 | try sema.errNote(src_loc, msg, "type has no guaranteed in-memory representation", .{}); |
| 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", .{}), |
| 26974 | | .Union => try mod.errNoteNonLazy(src_loc, msg, "only packed unions layout are allowed in packed types", .{}), |
| 26828 | .Struct => try sema.errNote(src_loc, msg, "only packed structs 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 | 26877 | const panic_messages_ty = try sema.getBuiltinType("panic_messages"); |
| 27023 | 26878 | const msg_decl_index = (sema.namespaceLookup( |
| 27024 | 26879 | block, |
| 27025 | | .unneeded, |
| 26880 | LazySrcLoc.unneeded, |
| 27026 | 26881 | panic_messages_ty.getNamespaceIndex(mod), |
| 27027 | 26882 | try mod.intern_pool.getOrPutString(gpa, @tagName(panic_id), .no_embedded_nulls), |
| 27028 | 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 | 26885 | error.GenericPoison, error.ComptimeReturn, error.ComptimeBreak => unreachable, |
| 27031 | 26886 | error.OutOfMemory => |e| return e, |
| 27032 | 26887 | }).?; |
| ... | ... | @@ -27053,6 +26908,7 @@ fn addSafetyCheck( |
| 27053 | 26908 | .instructions = .{}, |
| 27054 | 26909 | .inlining = parent_block.inlining, |
| 27055 | 26910 | .is_comptime = false, |
| 26911 | .src_base_inst = parent_block.src_base_inst, |
| 27056 | 26912 | }; |
| 27057 | 26913 | |
| 27058 | 26914 | defer fail_block.instructions.deinit(gpa); |
| ... | ... | @@ -27161,6 +27017,7 @@ fn panicUnwrapError( |
| 27161 | 27017 | .instructions = .{}, |
| 27162 | 27018 | .inlining = parent_block.inlining, |
| 27163 | 27019 | .is_comptime = false, |
| 27020 | .src_base_inst = parent_block.src_base_inst, |
| 27164 | 27021 | }; |
| 27165 | 27022 | |
| 27166 | 27023 | defer fail_block.instructions.deinit(gpa); |
| ... | ... | @@ -27277,6 +27134,7 @@ fn safetyCheckFormatted( |
| 27277 | 27134 | .instructions = .{}, |
| 27278 | 27135 | .inlining = parent_block.inlining, |
| 27279 | 27136 | .is_comptime = false, |
| 27137 | .src_base_inst = parent_block.src_base_inst, |
| 27280 | 27138 | }; |
| 27281 | 27139 | |
| 27282 | 27140 | defer fail_block.instructions.deinit(gpa); |
| ... | ... | @@ -27300,13 +27158,11 @@ fn emitBackwardBranch(sema: *Sema, block: *Block, src: LazySrcLoc) !void { |
| 27300 | 27158 | sema.branch_count += 1; |
| 27301 | 27159 | if (sema.branch_count > sema.branch_quota) { |
| 27302 | 27160 | const msg = try sema.errMsg( |
| 27303 | | block, |
| 27304 | 27161 | src, |
| 27305 | 27162 | "evaluation exceeded {d} backwards branches", |
| 27306 | 27163 | .{sema.branch_quota}, |
| 27307 | 27164 | ); |
| 27308 | 27165 | try sema.errNote( |
| 27309 | | block, |
| 27310 | 27166 | src, |
| 27311 | 27167 | msg, |
| 27312 | 27168 | "use @setEvalBranchQuota() to raise the branch limit from {d}", |
| ... | ... | @@ -27472,10 +27328,10 @@ fn fieldVal( |
| 27472 | 27328 | }, |
| 27473 | 27329 | else => { |
| 27474 | 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 | 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", .{}); |
| 27478 | | if (child_type.zigTypeTag(mod) == .Array) try sema.errNote(block, src, msg, "array values have 'len' member", .{}); |
| 27333 | if (child_type.isSlice(mod)) try sema.errNote(src, msg, "slice values have 'len' and 'ptr' members", .{}); |
| 27334 | if (child_type.zigTypeTag(mod) == .Array) try sema.errNote(src, msg, "array values have 'len' member", .{}); |
| 27479 | 27335 | break :msg msg; |
| 27480 | 27336 | }; |
| 27481 | 27337 | return sema.failWithOwnedErrorMsg(block, msg); |
| ... | ... | @@ -27633,7 +27489,7 @@ fn fieldPtr( |
| 27633 | 27489 | } |
| 27634 | 27490 | }, |
| 27635 | 27491 | .Type => { |
| 27636 | | _ = try sema.resolveConstDefinedValue(block, .unneeded, object_ptr, undefined); |
| 27492 | _ = try sema.resolveConstDefinedValue(block, LazySrcLoc.unneeded, object_ptr, undefined); |
| 27637 | 27493 | const result = try sema.analyzeLoad(block, src, object_ptr, object_ptr_src); |
| 27638 | 27494 | const inner = if (is_pointer_to) |
| 27639 | 27495 | try sema.analyzeLoad(block, src, result, object_ptr_src) |
| ... | ... | @@ -27885,7 +27741,7 @@ fn fieldCallBind( |
| 27885 | 27741 | }; |
| 27886 | 27742 | |
| 27887 | 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 | 27745 | field_name.fmt(ip), |
| 27890 | 27746 | concrete_ty.fmt(mod), |
| 27891 | 27747 | }); |
| ... | ... | @@ -27893,10 +27749,13 @@ fn fieldCallBind( |
| 27893 | 27749 | try sema.addDeclaredHereNote(msg, concrete_ty); |
| 27894 | 27750 | if (found_decl) |decl_idx| { |
| 27895 | 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 | 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 | 27760 | break :msg msg; |
| 27902 | 27761 | }; |
| ... | ... | @@ -27954,11 +27813,14 @@ fn namespaceLookup( |
| 27954 | 27813 | const decl = mod.declPtr(decl_index); |
| 27955 | 27814 | if (!decl.is_pub and decl.getFileScope(mod) != block.getFileScope(mod)) { |
| 27956 | 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 | 27817 | decl_name.fmt(&mod.intern_pool), |
| 27959 | 27818 | }); |
| 27960 | 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 | 27824 | break :msg msg; |
| 27963 | 27825 | }; |
| 27964 | 27826 | return sema.failWithOwnedErrorMsg(block, msg); |
| ... | ... | @@ -28023,7 +27885,7 @@ fn structFieldPtr( |
| 28023 | 27885 | const struct_type = mod.typeToStruct(struct_ty).?; |
| 28024 | 27886 | |
| 28025 | 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 | 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 | 28000 | return sema.tupleFieldVal(block, src, struct_byval, field_name, field_name_src, struct_ty); |
| 28139 | 28001 | |
| 28140 | 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 | 28004 | if (struct_type.fieldIsComptime(ip, field_index)) { |
| 28143 | 28005 | try sema.resolveStructFieldInits(struct_ty); |
| 28144 | 28006 | return Air.internedToRef(struct_type.field_inits.get(ip)[field_index]); |
| ... | ... | @@ -28291,7 +28153,7 @@ fn unionFieldPtr( |
| 28291 | 28153 | |
| 28292 | 28154 | if (initializing and field_ty.zigTypeTag(mod) == .NoReturn) { |
| 28293 | 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 | 28157 | errdefer msg.destroy(sema.gpa); |
| 28296 | 28158 | |
| 28297 | 28159 | try sema.addFieldErrNote(union_ty, field_index, msg, "field '{}' declared here", .{ |
| ... | ... | @@ -28324,7 +28186,7 @@ fn unionFieldPtr( |
| 28324 | 28186 | const msg = msg: { |
| 28325 | 28187 | const active_index = Type.fromInterned(union_obj.enum_tag_ty).enumTagFieldIndex(Value.fromInterned(un.tag), mod).?; |
| 28326 | 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 | 28190 | field_name.fmt(ip), |
| 28329 | 28191 | active_field_name.fmt(ip), |
| 28330 | 28192 | }); |
| ... | ... | @@ -28392,7 +28254,7 @@ fn unionFieldVal( |
| 28392 | 28254 | const msg = msg: { |
| 28393 | 28255 | const active_index = Type.fromInterned(union_obj.enum_tag_ty).enumTagFieldIndex(Value.fromInterned(un.tag), zcu).?; |
| 28394 | 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 | 28258 | field_name.fmt(ip), active_field_name.fmt(ip), |
| 28397 | 28259 | }); |
| 28398 | 28260 | errdefer msg.destroy(sema.gpa); |
| ... | ... | @@ -28615,15 +28477,13 @@ fn validateRuntimeElemAccess( |
| 28615 | 28477 | if (try sema.typeRequiresComptime(elem_ty)) { |
| 28616 | 28478 | const msg = msg: { |
| 28617 | 28479 | const msg = try sema.errMsg( |
| 28618 | | block, |
| 28619 | 28480 | elem_index_src, |
| 28620 | 28481 | "values of type '{}' must be comptime-known, but index value is runtime-known", |
| 28621 | 28482 | .{parent_ty.fmt(mod)}, |
| 28622 | 28483 | ); |
| 28623 | 28484 | errdefer msg.destroy(sema.gpa); |
| 28624 | 28485 | |
| 28625 | | const src_decl = mod.declPtr(block.src_decl); |
| 28626 | | try sema.explainWhyTypeIsComptime(msg, src_decl.toSrcLoc(parent_src, mod), parent_ty); |
| 28486 | try sema.explainWhyTypeIsComptime(msg, parent_src, parent_ty); |
| 28627 | 28487 | |
| 28628 | 28488 | break :msg msg; |
| 28629 | 28489 | }; |
| ... | ... | @@ -29011,21 +28871,18 @@ const CoerceOpts = struct { |
| 29011 | 28871 | func_inst: Air.Inst.Ref = .none, |
| 29012 | 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 | 28875 | if (info.func_inst == .none) return null; |
| 29016 | | const mod = sema.mod; |
| 29017 | | const fn_decl = (try sema.funcDeclSrc(info.func_inst)) orelse return null; |
| 29018 | | const param_src = Module.paramSrc(0, mod, fn_decl, info.param_i); |
| 29019 | | if (param_src == .node_offset_param) { |
| 29020 | | return Module.SrcLoc{ |
| 29021 | | .file_scope = fn_decl.getFileScope(mod), |
| 29022 | | .parent_decl_node = fn_decl.src_node, |
| 29023 | | .lazy = LazySrcLoc.nodeOffset(param_src.node_offset_param), |
| 29024 | | }; |
| 29025 | | } |
| 29026 | | return fn_decl.toSrcLoc(param_src, mod); |
| 28876 | const fn_decl = try sema.funcDeclSrc(info.func_inst) orelse return null; |
| 28877 | return .{ |
| 28878 | .base_node_inst = fn_decl.zir_decl_index.unwrap().?, |
| 28879 | .offset = .{ .fn_proto_param_type = .{ |
| 28880 | .fn_proto_node_offset = 0, |
| 28881 | .param_index = info.param_i, |
| 28882 | } }, |
| 28883 | }; |
| 29027 | 28884 | } |
| 29028 | | } = .{}, |
| 28885 | } = .{ .func_inst = .none, .param_i = undefined }, |
| 29029 | 28886 | }; |
| 29030 | 28887 | |
| 29031 | 28888 | fn coerceExtra( |
| ... | ... | @@ -29118,7 +28975,7 @@ fn coerceExtra( |
| 29118 | 28975 | |
| 29119 | 28976 | // Function body to function pointer. |
| 29120 | 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 | 28979 | const fn_decl = fn_val.pointerDecl(zcu).?; |
| 29123 | 28980 | const inst_as_ptr = try sema.analyzeDeclRef(fn_decl); |
| 29124 | 28981 | return sema.coerce(block, dest_ty, inst_as_ptr, inst_src); |
| ... | ... | @@ -29366,9 +29223,9 @@ fn coerceExtra( |
| 29366 | 29223 | // pointer to tuple to slice |
| 29367 | 29224 | if (!dest_info.flags.is_const) { |
| 29368 | 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 | 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 | 29229 | break :err_msg err_msg; |
| 29373 | 29230 | }; |
| 29374 | 29231 | return sema.failWithOwnedErrorMsg(block, err_msg); |
| ... | ... | @@ -29455,7 +29312,7 @@ fn coerceExtra( |
| 29455 | 29312 | }, |
| 29456 | 29313 | .Float, .ComptimeFloat => switch (inst_ty.zigTypeTag(zcu)) { |
| 29457 | 29314 | .ComptimeFloat => { |
| 29458 | | const val = try sema.resolveConstDefinedValue(block, .unneeded, inst, undefined); |
| 29315 | const val = try sema.resolveConstDefinedValue(block, LazySrcLoc.unneeded, inst, undefined); |
| 29459 | 29316 | const result_val = try val.floatCast(dest_ty, zcu); |
| 29460 | 29317 | return Air.internedToRef(result_val.toIntern()); |
| 29461 | 29318 | }, |
| ... | ... | @@ -29514,7 +29371,7 @@ fn coerceExtra( |
| 29514 | 29371 | .Enum => switch (inst_ty.zigTypeTag(zcu)) { |
| 29515 | 29372 | .EnumLiteral => { |
| 29516 | 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 | 29375 | const string = zcu.intern_pool.indexToKey(val.toIntern()).enum_literal; |
| 29519 | 29376 | const field_index = dest_ty.enumFieldIndex(string, zcu) orelse { |
| 29520 | 29377 | return sema.fail(block, inst_src, "no field named '{}' in enum '{}'", .{ |
| ... | ... | @@ -29648,54 +29505,58 @@ fn coerceExtra( |
| 29648 | 29505 | |
| 29649 | 29506 | if (opts.is_ret and dest_ty.zigTypeTag(zcu) == .NoReturn) { |
| 29650 | 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 | 29509 | errdefer msg.destroy(sema.gpa); |
| 29653 | 29510 | |
| 29654 | | const ret_ty_src: LazySrcLoc = .{ .node_offset_fn_type_ret_ty = 0 }; |
| 29655 | | const src_decl = zcu.funcOwnerDeclPtr(sema.func_index); |
| 29656 | | try zcu.errNoteNonLazy(src_decl.toSrcLoc(ret_ty_src, zcu), msg, "'noreturn' declared here", .{}); |
| 29511 | const ret_ty_src: LazySrcLoc = .{ |
| 29512 | .base_node_inst = zcu.funcOwnerDeclPtr(sema.func_index).zir_decl_index.unwrap().?, |
| 29513 | .offset = .{ .node_offset_fn_type_ret_ty = 0 }, |
| 29514 | }; |
| 29515 | try sema.errNote(ret_ty_src, msg, "'noreturn' declared here", .{}); |
| 29657 | 29516 | break :msg msg; |
| 29658 | 29517 | }; |
| 29659 | 29518 | return sema.failWithOwnedErrorMsg(block, msg); |
| 29660 | 29519 | } |
| 29661 | 29520 | |
| 29662 | 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 | 29523 | errdefer msg.destroy(sema.gpa); |
| 29665 | 29524 | |
| 29666 | 29525 | // E!T to T |
| 29667 | 29526 | if (inst_ty.zigTypeTag(zcu) == .ErrorUnion and |
| 29668 | 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", .{}); |
| 29671 | | try sema.errNote(block, inst_src, msg, "consider using 'try', 'catch', or 'if'", .{}); |
| 29529 | try sema.errNote(inst_src, msg, "cannot convert error union to payload type", .{}); |
| 29530 | try sema.errNote(inst_src, msg, "consider using 'try', 'catch', or 'if'", .{}); |
| 29672 | 29531 | } |
| 29673 | 29532 | |
| 29674 | 29533 | // ?T to T |
| 29675 | 29534 | if (inst_ty.zigTypeTag(zcu) == .Optional and |
| 29676 | 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", .{}); |
| 29679 | | try sema.errNote(block, inst_src, msg, "consider using '.?', 'orelse', or 'if'", .{}); |
| 29537 | try sema.errNote(inst_src, msg, "cannot convert optional to payload type", .{}); |
| 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 | 29543 | // Add notes about function return type |
| 29685 | 29544 | if (opts.is_ret and |
| 29686 | 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 }; |
| 29689 | | const src_decl = zcu.funcOwnerDeclPtr(sema.func_index); |
| 29547 | const ret_ty_src: LazySrcLoc = .{ |
| 29548 | .base_node_inst = zcu.funcOwnerDeclPtr(sema.func_index).zir_decl_index.unwrap().?, |
| 29549 | .offset = .{ .node_offset_fn_type_ret_ty = 0 }, |
| 29550 | }; |
| 29690 | 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 | 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 | 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 | 29562 | // TODO maybe add "cannot store an error in type '{}'" note |
| ... | ... | @@ -29830,7 +29691,7 @@ const InMemoryCoercionResult = union(enum) { |
| 29830 | 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 | 29695 | const mod = sema.mod; |
| 29835 | 29696 | var cur = res; |
| 29836 | 29697 | while (true) switch (cur.*) { |
| ... | ... | @@ -29841,93 +29702,93 @@ const InMemoryCoercionResult = union(enum) { |
| 29841 | 29702 | break; |
| 29842 | 29703 | }, |
| 29843 | 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 | 29706 | @tagName(int.wanted_signedness), int.wanted_bits, @tagName(int.actual_signedness), int.actual_bits, |
| 29846 | 29707 | }); |
| 29847 | 29708 | break; |
| 29848 | 29709 | }, |
| 29849 | 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 | 29712 | pair.actual.fmt(mod), pair.wanted.fmt(mod), |
| 29852 | 29713 | }); |
| 29853 | 29714 | cur = pair.child; |
| 29854 | 29715 | }, |
| 29855 | 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 | 29718 | lens.actual, lens.wanted, |
| 29858 | 29719 | }); |
| 29859 | 29720 | break; |
| 29860 | 29721 | }, |
| 29861 | 29722 | .array_sentinel => |sentinel| { |
| 29862 | 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 | 29725 | sentinel.actual.fmtValue(mod, sema), sentinel.wanted.fmtValue(mod, sema), |
| 29865 | 29726 | }); |
| 29866 | 29727 | } else { |
| 29867 | | try sema.errNote(block, src, msg, "destination array requires '{}' sentinel", .{ |
| 29728 | try sema.errNote(src, msg, "destination array requires '{}' sentinel", .{ |
| 29868 | 29729 | sentinel.wanted.fmtValue(mod, sema), |
| 29869 | 29730 | }); |
| 29870 | 29731 | } |
| 29871 | 29732 | break; |
| 29872 | 29733 | }, |
| 29873 | 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 | 29736 | pair.actual.fmt(mod), pair.wanted.fmt(mod), |
| 29876 | 29737 | }); |
| 29877 | 29738 | cur = pair.child; |
| 29878 | 29739 | }, |
| 29879 | 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 | 29742 | lens.actual, lens.wanted, |
| 29882 | 29743 | }); |
| 29883 | 29744 | break; |
| 29884 | 29745 | }, |
| 29885 | 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 | 29748 | pair.actual.fmt(mod), pair.wanted.fmt(mod), |
| 29888 | 29749 | }); |
| 29889 | 29750 | cur = pair.child; |
| 29890 | 29751 | }, |
| 29891 | 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 | 29754 | pair.actual.optionalChild(mod).fmt(mod), pair.wanted.optionalChild(mod).fmt(mod), |
| 29894 | 29755 | }); |
| 29895 | 29756 | break; |
| 29896 | 29757 | }, |
| 29897 | 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 | 29760 | pair.actual.fmt(mod), pair.wanted.fmt(mod), |
| 29900 | 29761 | }); |
| 29901 | 29762 | cur = pair.child; |
| 29902 | 29763 | }, |
| 29903 | 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 | 29766 | break; |
| 29906 | 29767 | }, |
| 29907 | 29768 | .missing_error => |missing_errors| { |
| 29908 | 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 | 29772 | break; |
| 29912 | 29773 | }, |
| 29913 | 29774 | .fn_var_args => |wanted_var_args| { |
| 29914 | 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 | 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 | 29780 | break; |
| 29920 | 29781 | }, |
| 29921 | 29782 | .fn_generic => |wanted_generic| { |
| 29922 | 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 | 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 | 29788 | break; |
| 29928 | 29789 | }, |
| 29929 | 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 | 29792 | lens.actual, lens.wanted, |
| 29932 | 29793 | }); |
| 29933 | 29794 | break; |
| ... | ... | @@ -29944,69 +29805,69 @@ const InMemoryCoercionResult = union(enum) { |
| 29944 | 29805 | } |
| 29945 | 29806 | } |
| 29946 | 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 | 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 | 29812 | break; |
| 29952 | 29813 | }, |
| 29953 | 29814 | .fn_param_comptime => |param| { |
| 29954 | 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 | 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 | 29820 | break; |
| 29960 | 29821 | }, |
| 29961 | 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 | 29824 | param.index, param.actual.fmt(mod), param.wanted.fmt(mod), |
| 29964 | 29825 | }); |
| 29965 | 29826 | cur = param.child; |
| 29966 | 29827 | }, |
| 29967 | 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 | 29830 | break; |
| 29970 | 29831 | }, |
| 29971 | 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 | 29834 | pair.actual.fmt(mod), pair.wanted.fmt(mod), |
| 29974 | 29835 | }); |
| 29975 | 29836 | cur = pair.child; |
| 29976 | 29837 | }, |
| 29977 | 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 | 29840 | pair.actual.fmt(mod), pair.wanted.fmt(mod), |
| 29980 | 29841 | }); |
| 29981 | 29842 | cur = pair.child; |
| 29982 | 29843 | }, |
| 29983 | 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 | 29846 | break; |
| 29986 | 29847 | }, |
| 29987 | 29848 | .ptr_sentinel => |sentinel| { |
| 29988 | 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 | 29851 | sentinel.actual.fmtValue(mod, sema), sentinel.wanted.fmtValue(mod, sema), |
| 29991 | 29852 | }); |
| 29992 | 29853 | } else { |
| 29993 | | try sema.errNote(block, src, msg, "destination pointer requires '{}' sentinel", .{ |
| 29854 | try sema.errNote(src, msg, "destination pointer requires '{}' sentinel", .{ |
| 29994 | 29855 | sentinel.wanted.fmtValue(mod, sema), |
| 29995 | 29856 | }); |
| 29996 | 29857 | } |
| 29997 | 29858 | break; |
| 29998 | 29859 | }, |
| 29999 | 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 | 29862 | break; |
| 30002 | 29863 | }, |
| 30003 | 29864 | .ptr_qualifiers => |qualifiers| { |
| 30004 | 29865 | const ok_const = !qualifiers.actual_const or qualifiers.wanted_const; |
| 30005 | 29866 | const ok_volatile = !qualifiers.actual_volatile or qualifiers.wanted_volatile; |
| 30006 | 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 | 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 | 29872 | break; |
| 30012 | 29873 | }, |
| ... | ... | @@ -30014,11 +29875,11 @@ const InMemoryCoercionResult = union(enum) { |
| 30014 | 29875 | const wanted_allow_zero = pair.wanted.ptrAllowsZero(mod); |
| 30015 | 29876 | const actual_allow_zero = pair.actual.ptrAllowsZero(mod); |
| 30016 | 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 | 29879 | pair.actual.fmt(mod), pair.wanted.fmt(mod), |
| 30019 | 29880 | }); |
| 30020 | 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 | 29883 | pair.actual.fmt(mod), pair.wanted.fmt(mod), |
| 30023 | 29884 | }); |
| 30024 | 29885 | } |
| ... | ... | @@ -30026,34 +29887,34 @@ const InMemoryCoercionResult = union(enum) { |
| 30026 | 29887 | }, |
| 30027 | 29888 | .ptr_bit_range => |bit_range| { |
| 30028 | 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 | 29891 | bit_range.actual_host, bit_range.wanted_host, |
| 30031 | 29892 | }); |
| 30032 | 29893 | } |
| 30033 | 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 | 29896 | bit_range.actual_offset, bit_range.wanted_offset, |
| 30036 | 29897 | }); |
| 30037 | 29898 | } |
| 30038 | 29899 | break; |
| 30039 | 29900 | }, |
| 30040 | 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 | 29903 | pair.actual.toByteUnits() orelse 0, pair.wanted.toByteUnits() orelse 0, |
| 30043 | 29904 | }); |
| 30044 | 29905 | break; |
| 30045 | 29906 | }, |
| 30046 | 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 | 29909 | pair.actual.fmt(mod), pair.wanted.fmt(mod), |
| 30049 | 29910 | }); |
| 30050 | 29911 | break; |
| 30051 | 29912 | }, |
| 30052 | 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 | 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 | 29918 | break; |
| 30058 | 29919 | }, |
| 30059 | 29920 | }; |
| ... | ... | @@ -30667,7 +30528,7 @@ fn coerceVarArgParam( |
| 30667 | 30528 | .{}, |
| 30668 | 30529 | ), |
| 30669 | 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 | 30532 | const fn_decl = fn_val.pointerDecl(mod).?; |
| 30672 | 30533 | break :fn_ptr try sema.analyzeDeclRef(fn_decl); |
| 30673 | 30534 | }, |
| ... | ... | @@ -30715,11 +30576,10 @@ fn coerceVarArgParam( |
| 30715 | 30576 | const coerced_ty = sema.typeOf(coerced); |
| 30716 | 30577 | if (!try sema.validateExternType(coerced_ty, .param_ty)) { |
| 30717 | 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 | 30580 | errdefer msg.destroy(sema.gpa); |
| 30720 | 30581 | |
| 30721 | | const src_decl = sema.mod.declPtr(block.src_decl); |
| 30722 | | try sema.explainWhyTypeIsNotExtern(msg, src_decl.toSrcLoc(inst_src, mod), coerced_ty, .param_ty); |
| 30582 | try sema.explainWhyTypeIsNotExtern(msg, inst_src, coerced_ty, .param_ty); |
| 30723 | 30583 | |
| 30724 | 30584 | try sema.addDeclaredHereNote(msg, coerced_ty); |
| 30725 | 30585 | break :msg msg; |
| ... | ... | @@ -30879,7 +30739,6 @@ fn checkComptimeKnownStore(sema: *Sema, block: *Block, store_inst_ref: Air.Inst. |
| 30879 | 30739 | { |
| 30880 | 30740 | try maybe_comptime_alloc.stores.append(sema.arena, .{ |
| 30881 | 30741 | .inst = store_inst, |
| 30882 | | .src_decl = block.src_decl, |
| 30883 | 30742 | .src = store_src, |
| 30884 | 30743 | }); |
| 30885 | 30744 | return; |
| ... | ... | @@ -30913,8 +30772,7 @@ fn checkKnownAllocPtr(sema: *Sema, block: *Block, base_ptr: Air.Inst.Ref, new_pt |
| 30913 | 30772 | |
| 30914 | 30773 | try maybe_comptime_alloc.stores.append(sema.arena, .{ |
| 30915 | 30774 | .inst = new_ptr_inst, |
| 30916 | | .src_decl = block.src_decl, |
| 30917 | | .src = .unneeded, |
| 30775 | .src = LazySrcLoc.unneeded, |
| 30918 | 30776 | }); |
| 30919 | 30777 | }, |
| 30920 | 30778 | .ptr_elem_ptr => { |
| ... | ... | @@ -30937,10 +30795,9 @@ fn markMaybeComptimeAllocRuntime(sema: *Sema, block: *Block, alloc_inst: Air.Ins |
| 30937 | 30795 | const maybe_comptime_alloc = (sema.maybe_comptime_allocs.fetchRemove(alloc_inst) orelse return).value; |
| 30938 | 30796 | // Since the alloc has been determined to be runtime, we must check that |
| 30939 | 30797 | // all other stores to it are permitted to be runtime values. |
| 30940 | | const mod = sema.mod; |
| 30941 | 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| { |
| 30943 | | if (other_src == .unneeded) { |
| 30799 | for (slice.items(.inst), slice.items(.src)) |other_inst, other_src| { |
| 30800 | if (other_src.offset == .unneeded) { |
| 30944 | 30801 | switch (sema.air_instructions.items(.tag)[@intFromEnum(other_inst)]) { |
| 30945 | 30802 | .set_union_tag, .optional_payload_ptr_set, .errunion_payload_ptr_set => continue, |
| 30946 | 30803 | else => unreachable, // assertion failure |
| ... | ... | @@ -30950,10 +30807,9 @@ fn markMaybeComptimeAllocRuntime(sema: *Sema, block: *Block, alloc_inst: Air.Ins |
| 30950 | 30807 | const other_operand = other_data.rhs; |
| 30951 | 30808 | if (!sema.checkRuntimeValue(other_operand)) { |
| 30952 | 30809 | return sema.failWithOwnedErrorMsg(block, msg: { |
| 30953 | | const other_src_resolved = mod.declPtr(other_src_decl).toSrcLoc(other_src, mod); |
| 30954 | | const msg = try Module.ErrorMsg.create(sema.gpa, other_src_resolved, "runtime value contains reference to comptime var", .{}); |
| 30810 | const msg = try sema.errMsg(other_src, "runtime value contains reference to comptime var", .{}); |
| 30955 | 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 | 30813 | break :msg msg; |
| 30958 | 30814 | }); |
| 30959 | 30815 | } |
| ... | ... | @@ -31215,11 +31071,11 @@ fn coerceEnumToUnion( |
| 31215 | 31071 | |
| 31216 | 31072 | const tag_ty = union_ty.unionTagType(mod) orelse { |
| 31217 | 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 | 31075 | union_ty.fmt(sema.mod), inst_ty.fmt(sema.mod), |
| 31220 | 31076 | }); |
| 31221 | 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 | 31079 | try sema.addDeclaredHereNote(msg, union_ty); |
| 31224 | 31080 | break :msg msg; |
| 31225 | 31081 | }; |
| ... | ... | @@ -31239,7 +31095,7 @@ fn coerceEnumToUnion( |
| 31239 | 31095 | try sema.resolveTypeFields(field_ty); |
| 31240 | 31096 | if (field_ty.zigTypeTag(mod) == .NoReturn) { |
| 31241 | 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 | 31099 | errdefer msg.destroy(sema.gpa); |
| 31244 | 31100 | |
| 31245 | 31101 | const field_name = union_obj.loadTagType(ip).names.get(ip)[field_index]; |
| ... | ... | @@ -31254,7 +31110,7 @@ fn coerceEnumToUnion( |
| 31254 | 31110 | const opv = (try sema.typeHasOnePossibleValue(field_ty)) orelse { |
| 31255 | 31111 | const msg = msg: { |
| 31256 | 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 | 31114 | inst_ty.fmt(sema.mod), union_ty.fmt(sema.mod), |
| 31259 | 31115 | field_ty.fmt(sema.mod), field_name.fmt(ip), |
| 31260 | 31116 | }); |
| ... | ... | @@ -31276,7 +31132,7 @@ fn coerceEnumToUnion( |
| 31276 | 31132 | |
| 31277 | 31133 | if (tag_ty.isNonexhaustiveEnum(mod)) { |
| 31278 | 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 | 31136 | union_ty.fmt(sema.mod), |
| 31281 | 31137 | }); |
| 31282 | 31138 | errdefer msg.destroy(sema.gpa); |
| ... | ... | @@ -31294,7 +31150,6 @@ fn coerceEnumToUnion( |
| 31294 | 31150 | for (union_obj.field_types.get(ip), 0..) |field_ty, field_index| { |
| 31295 | 31151 | if (Type.fromInterned(field_ty).zigTypeTag(mod) == .NoReturn) { |
| 31296 | 31152 | const err_msg = msg orelse try sema.errMsg( |
| 31297 | | block, |
| 31298 | 31153 | inst_src, |
| 31299 | 31154 | "runtime coercion from enum '{}' to union '{}' which has a 'noreturn' field", |
| 31300 | 31155 | .{ tag_ty.fmt(sema.mod), union_ty.fmt(sema.mod) }, |
| ... | ... | @@ -31318,7 +31173,6 @@ fn coerceEnumToUnion( |
| 31318 | 31173 | |
| 31319 | 31174 | const msg = msg: { |
| 31320 | 31175 | const msg = try sema.errMsg( |
| 31321 | | block, |
| 31322 | 31176 | inst_src, |
| 31323 | 31177 | "runtime coercion from enum '{}' to union '{}' which has non-void fields", |
| 31324 | 31178 | .{ tag_ty.fmt(sema.mod), union_ty.fmt(sema.mod) }, |
| ... | ... | @@ -31377,12 +31231,10 @@ fn coerceAnonStructToUnion( |
| 31377 | 31231 | assert(field_count != 1); |
| 31378 | 31232 | const msg = msg: { |
| 31379 | 31233 | const msg = if (field_count > 1) try sema.errMsg( |
| 31380 | | block, |
| 31381 | 31234 | inst_src, |
| 31382 | 31235 | "cannot initialize multiple union fields at once; unions can only have one active field", |
| 31383 | 31236 | .{}, |
| 31384 | 31237 | ) else try sema.errMsg( |
| 31385 | | block, |
| 31386 | 31238 | inst_src, |
| 31387 | 31239 | "union initializer must initialize one field", |
| 31388 | 31240 | .{}, |
| ... | ... | @@ -31459,12 +31311,12 @@ fn coerceArrayLike( |
| 31459 | 31311 | const dest_len = try sema.usizeCast(block, dest_ty_src, dest_ty.arrayLen(mod)); |
| 31460 | 31312 | if (dest_len != inst_len) { |
| 31461 | 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 | 31315 | dest_ty.fmt(mod), inst_ty.fmt(mod), |
| 31464 | 31316 | }); |
| 31465 | 31317 | errdefer msg.destroy(sema.gpa); |
| 31466 | | try sema.errNote(block, dest_ty_src, msg, "destination has length {d}", .{dest_len}); |
| 31467 | | try sema.errNote(block, inst_src, msg, "source has length {d}", .{inst_len}); |
| 31318 | try sema.errNote(dest_ty_src, msg, "destination has length {d}", .{dest_len}); |
| 31319 | try sema.errNote(inst_src, msg, "source has length {d}", .{inst_len}); |
| 31468 | 31320 | break :msg msg; |
| 31469 | 31321 | }; |
| 31470 | 31322 | return sema.failWithOwnedErrorMsg(block, msg); |
| ... | ... | @@ -31546,12 +31398,12 @@ fn coerceTupleToArray( |
| 31546 | 31398 | |
| 31547 | 31399 | if (dest_len != inst_len) { |
| 31548 | 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 | 31402 | dest_ty.fmt(sema.mod), inst_ty.fmt(sema.mod), |
| 31551 | 31403 | }); |
| 31552 | 31404 | errdefer msg.destroy(sema.gpa); |
| 31553 | | try sema.errNote(block, dest_ty_src, msg, "destination has length {d}", .{dest_len}); |
| 31554 | | try sema.errNote(block, inst_src, msg, "source has length {d}", .{inst_len}); |
| 31405 | try sema.errNote(dest_ty_src, msg, "destination has length {d}", .{dest_len}); |
| 31406 | try sema.errNote(inst_src, msg, "source has length {d}", .{inst_len}); |
| 31555 | 31407 | break :msg msg; |
| 31556 | 31408 | }; |
| 31557 | 31409 | return sema.failWithOwnedErrorMsg(block, msg); |
| ... | ... | @@ -31722,9 +31574,9 @@ fn coerceTupleToStruct( |
| 31722 | 31574 | const template = "missing struct field: {}"; |
| 31723 | 31575 | const args = .{field_name.fmt(ip)}; |
| 31724 | 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 | 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 | 31581 | continue; |
| 31730 | 31582 | } |
| ... | ... | @@ -31860,18 +31712,18 @@ fn coerceTupleToTuple( |
| 31860 | 31712 | const field_name = tuple_ty.structFieldName(i, mod).unwrap() orelse { |
| 31861 | 31713 | const template = "missing tuple field: {d}"; |
| 31862 | 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 | 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 | 31719 | continue; |
| 31868 | 31720 | }; |
| 31869 | 31721 | const template = "missing struct field: {}"; |
| 31870 | 31722 | const args = .{field_name.fmt(ip)}; |
| 31871 | 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 | 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 | 31728 | continue; |
| 31877 | 31729 | } |
| ... | ... | @@ -31926,14 +31778,6 @@ fn addReferencedBy( |
| 31926 | 31778 | decl_index: InternPool.DeclIndex, |
| 31927 | 31779 | ) !void { |
| 31928 | 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 | 31781 | try sema.mod.reference_table.put(sema.gpa, decl_index, .{ |
| 31938 | 31782 | .referencer = block.src_decl, |
| 31939 | 31783 | .src = src, |
| ... | ... | @@ -31945,7 +31789,10 @@ pub fn ensureDeclAnalyzed(sema: *Sema, decl_index: InternPool.DeclIndex) Compile |
| 31945 | 31789 | const ip = &mod.intern_pool; |
| 31946 | 31790 | const decl = mod.declPtr(decl_index); |
| 31947 | 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 | 31796 | return sema.failWithOwnedErrorMsg(null, msg); |
| 31950 | 31797 | } |
| 31951 | 31798 | |
| ... | ... | @@ -32440,10 +32287,9 @@ fn analyzeSlice( |
| 32440 | 32287 | if (try sema.compareScalar(start_value, .neq, end_value, Type.comptime_int)) { |
| 32441 | 32288 | if (try sema.compareScalar(start_value, .neq, Value.zero_comptime_int, Type.comptime_int)) { |
| 32442 | 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 | 32291 | errdefer msg.destroy(sema.gpa); |
| 32445 | 32292 | try sema.errNote( |
| 32446 | | block, |
| 32447 | 32293 | start_src, |
| 32448 | 32294 | msg, |
| 32449 | 32295 | "expected '{}', found '{}'", |
| ... | ... | @@ -32457,10 +32303,9 @@ fn analyzeSlice( |
| 32457 | 32303 | return sema.failWithOwnedErrorMsg(block, msg); |
| 32458 | 32304 | } else if (try sema.compareScalar(end_value, .neq, Value.one_comptime_int, Type.comptime_int)) { |
| 32459 | 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 | 32307 | errdefer msg.destroy(sema.gpa); |
| 32462 | 32308 | try sema.errNote( |
| 32463 | | block, |
| 32464 | 32309 | end_src, |
| 32465 | 32310 | msg, |
| 32466 | 32311 | "expected '{}', found '{}'", |
| ... | ... | @@ -32714,9 +32559,9 @@ fn analyzeSlice( |
| 32714 | 32559 | |
| 32715 | 32560 | if (!actual_sentinel.eql(expected_sentinel, elem_ty, mod)) { |
| 32716 | 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 | 32563 | errdefer msg.destroy(sema.gpa); |
| 32719 | | try sema.errNote(block, src, msg, "expected '{}', found '{}'", .{ |
| 32564 | try sema.errNote(src, msg, "expected '{}', found '{}'", .{ |
| 32720 | 32565 | expected_sentinel.fmtValue(mod, sema), |
| 32721 | 32566 | actual_sentinel.fmtValue(mod, sema), |
| 32722 | 32567 | }); |
| ... | ... | @@ -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 | 33461 | const PeerResolveResult = union(enum) { |
| 33592 | 33462 | /// The peer type resolution was successful, and resulted in the given type. |
| 33593 | 33463 | success: Type, |
| ... | ... | @@ -33612,10 +33482,9 @@ const PeerResolveResult = union(enum) { |
| 33612 | 33482 | block: *Block, |
| 33613 | 33483 | src: LazySrcLoc, |
| 33614 | 33484 | instructions: []const Air.Inst.Ref, |
| 33615 | | candidate_srcs: Module.PeerTypeCandidateSrc, |
| 33485 | candidate_srcs: PeerTypeCandidateSrc, |
| 33616 | 33486 | ) !*Module.ErrorMsg { |
| 33617 | 33487 | const mod = sema.mod; |
| 33618 | | const decl_ptr = mod.declPtr(block.src_decl); |
| 33619 | 33488 | |
| 33620 | 33489 | var opt_msg: ?*Module.ErrorMsg = null; |
| 33621 | 33490 | errdefer if (opt_msg) |msg| msg.destroy(sema.gpa); |
| ... | ... | @@ -33643,9 +33512,9 @@ const PeerResolveResult = union(enum) { |
| 33643 | 33512 | const fmt = "struct field '{}' has conflicting types"; |
| 33644 | 33513 | const args = .{field_error.field_name.fmt(&mod.intern_pool)}; |
| 33645 | 33514 | if (opt_msg) |msg| { |
| 33646 | | try sema.errNote(block, src, msg, fmt, args); |
| 33515 | try sema.errNote(src, msg, fmt, args); |
| 33647 | 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 | 33520 | // Continue on to child error |
| ... | ... | @@ -33667,8 +33536,8 @@ const PeerResolveResult = union(enum) { |
| 33667 | 33536 | peer_tys[conflict_idx[1]], |
| 33668 | 33537 | }; |
| 33669 | 33538 | const conflict_srcs: [2]?LazySrcLoc = .{ |
| 33670 | | candidate_srcs.resolve(mod, decl_ptr, conflict_idx[0]), |
| 33671 | | candidate_srcs.resolve(mod, decl_ptr, conflict_idx[1]), |
| 33539 | candidate_srcs.resolve(block, conflict_idx[0]), |
| 33540 | candidate_srcs.resolve(block, conflict_idx[1]), |
| 33672 | 33541 | }; |
| 33673 | 33542 | |
| 33674 | 33543 | const fmt = "incompatible types: '{}' and '{}'"; |
| ... | ... | @@ -33677,16 +33546,16 @@ const PeerResolveResult = union(enum) { |
| 33677 | 33546 | conflict_tys[1].fmt(mod), |
| 33678 | 33547 | }; |
| 33679 | 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 | 33550 | break :msg msg; |
| 33682 | 33551 | } else msg: { |
| 33683 | | const msg = try sema.errMsg(block, src, fmt, args); |
| 33552 | const msg = try sema.errMsg(src, fmt, args); |
| 33684 | 33553 | opt_msg = msg; |
| 33685 | 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)}); |
| 33689 | | if (conflict_srcs[1]) |src_loc| try sema.errNote(block, src_loc, msg, "type '{}' here", .{conflict_tys[1].fmt(mod)}); |
| 33557 | if (conflict_srcs[0]) |src_loc| try sema.errNote(src_loc, msg, "type '{}' here", .{conflict_tys[0].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 | 33560 | // No child error |
| 33692 | 33561 | break; |
| ... | ... | @@ -33701,7 +33570,7 @@ fn resolvePeerTypes( |
| 33701 | 33570 | block: *Block, |
| 33702 | 33571 | src: LazySrcLoc, |
| 33703 | 33572 | instructions: []const Air.Inst.Ref, |
| 33704 | | candidate_srcs: Module.PeerTypeCandidateSrc, |
| 33573 | candidate_srcs: PeerTypeCandidateSrc, |
| 33705 | 33574 | ) !Type { |
| 33706 | 33575 | switch (instructions.len) { |
| 33707 | 33576 | 0 => return Type.noreturn, |
| ... | ... | @@ -35140,9 +35009,9 @@ pub fn resolveStructAlignment( |
| 35140 | 35009 | } |
| 35141 | 35010 | |
| 35142 | 35011 | fn resolveStructLayout(sema: *Sema, ty: Type) CompileError!void { |
| 35143 | | const mod = sema.mod; |
| 35144 | | const ip = &mod.intern_pool; |
| 35145 | | const struct_type = mod.typeToStruct(ty) orelse return; |
| 35012 | const zcu = sema.mod; |
| 35013 | const ip = &zcu.intern_pool; |
| 35014 | const struct_type = zcu.typeToStruct(ty) orelse return; |
| 35146 | 35015 | |
| 35147 | 35016 | if (struct_type.haveLayout(ip)) |
| 35148 | 35017 | return; |
| ... | ... | @@ -35150,16 +35019,15 @@ fn resolveStructLayout(sema: *Sema, ty: Type) CompileError!void { |
| 35150 | 35019 | try sema.resolveTypeFields(ty); |
| 35151 | 35020 | |
| 35152 | 35021 | if (struct_type.layout == .@"packed") { |
| 35153 | | try semaBackingIntType(mod, struct_type); |
| 35022 | try semaBackingIntType(zcu, struct_type); |
| 35154 | 35023 | return; |
| 35155 | 35024 | } |
| 35156 | 35025 | |
| 35157 | 35026 | if (struct_type.setLayoutWip(ip)) { |
| 35158 | | const msg = try Module.ErrorMsg.create( |
| 35159 | | sema.gpa, |
| 35160 | | mod.declPtr(struct_type.decl.unwrap().?).srcLoc(mod), |
| 35027 | const msg = try sema.errMsg( |
| 35028 | ty.srcLoc(zcu), |
| 35161 | 35029 | "struct '{}' depends on itself", |
| 35162 | | .{ty.fmt(mod)}, |
| 35030 | .{ty.fmt(zcu)}, |
| 35163 | 35031 | ); |
| 35164 | 35032 | return sema.failWithOwnedErrorMsg(null, msg); |
| 35165 | 35033 | } |
| ... | ... | @@ -35196,9 +35064,8 @@ fn resolveStructLayout(sema: *Sema, ty: Type) CompileError!void { |
| 35196 | 35064 | } |
| 35197 | 35065 | |
| 35198 | 35066 | if (struct_type.flagsPtr(ip).assumed_runtime_bits and !(try sema.typeHasRuntimeBits(ty))) { |
| 35199 | | const msg = try Module.ErrorMsg.create( |
| 35200 | | sema.gpa, |
| 35201 | | mod.declPtr(struct_type.decl.unwrap().?).srcLoc(mod), |
| 35067 | const msg = try sema.errMsg( |
| 35068 | ty.srcLoc(zcu), |
| 35202 | 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 | 35073 | } |
| 35207 | 35074 | |
| 35208 | 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( |
| 35212 | | sema.gpa, |
| 35213 | | mod.declPtr(struct_type.decl.unwrap().?).srcLoc(mod), |
| 35078 | const msg = try sema.errMsg( |
| 35079 | ty.srcLoc(zcu), |
| 35214 | 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 | 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 | 35112 | // TODO: don't handle tuples differently. This logic exists only because it |
| 35247 | 35113 | // uncovers latent bugs if removed. Fix the latent bugs and remove this logic! |
| 35248 | 35114 | // Likewise, implement field reordering support in all the backends! |
| ... | ... | @@ -35293,7 +35159,7 @@ fn semaBackingIntType(mod: *Module, struct_type: InternPool.LoadedStructType) Co |
| 35293 | 35159 | var analysis_arena = std.heap.ArenaAllocator.init(gpa); |
| 35294 | 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 | 35163 | defer comptime_err_ret_trace.deinit(); |
| 35298 | 35164 | |
| 35299 | 35165 | var sema: Sema = .{ |
| ... | ... | @@ -35320,6 +35186,7 @@ fn semaBackingIntType(mod: *Module, struct_type: InternPool.LoadedStructType) Co |
| 35320 | 35186 | .instructions = .{}, |
| 35321 | 35187 | .inlining = null, |
| 35322 | 35188 | .is_comptime = true, |
| 35189 | .src_base_inst = struct_type.zir_index.unwrap().?, |
| 35323 | 35190 | }; |
| 35324 | 35191 | defer assert(block.instructions.items.len == 0); |
| 35325 | 35192 | |
| ... | ... | @@ -35352,7 +35219,10 @@ fn semaBackingIntType(mod: *Module, struct_type: InternPool.LoadedStructType) Co |
| 35352 | 35219 | const backing_int_body_len = zir.extra[extra_index]; |
| 35353 | 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 | 35226 | const backing_int_ty = blk: { |
| 35357 | 35227 | if (backing_int_body_len == 0) { |
| 35358 | 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 | 35238 | struct_type.backingIntType(ip).* = backing_int_ty.toIntern(); |
| 35369 | 35239 | } else { |
| 35370 | 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 | 35243 | const backing_int_ty = try mod.intType(.unsigned, @intCast(fields_bit_sum)); |
| 35374 | 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 | 35265 | const mod = sema.mod; |
| 35396 | 35266 | if (!ty.isIndexable(mod)) { |
| 35397 | 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 | 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 | 35271 | break :msg msg; |
| 35402 | 35272 | }; |
| 35403 | 35273 | return sema.failWithOwnedErrorMsg(block, msg); |
| ... | ... | @@ -35418,9 +35288,9 @@ fn checkMemOperand(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) !void |
| 35418 | 35288 | } |
| 35419 | 35289 | } |
| 35420 | 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 | 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 | 35294 | break :msg msg; |
| 35425 | 35295 | }; |
| 35426 | 35296 | return sema.failWithOwnedErrorMsg(block, msg); |
| ... | ... | @@ -35471,8 +35341,8 @@ pub fn resolveUnionAlignment( |
| 35471 | 35341 | |
| 35472 | 35342 | /// This logic must be kept in sync with `Module.getUnionLayout`. |
| 35473 | 35343 | fn resolveUnionLayout(sema: *Sema, ty: Type) CompileError!void { |
| 35474 | | const mod = sema.mod; |
| 35475 | | const ip = &mod.intern_pool; |
| 35344 | const zcu = sema.mod; |
| 35345 | const ip = &zcu.intern_pool; |
| 35476 | 35346 | |
| 35477 | 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 | 35352 | switch (union_type.flagsPtr(ip).status) { |
| 35483 | 35353 | .none, .have_field_types => {}, |
| 35484 | 35354 | .field_types_wip, .layout_wip => { |
| 35485 | | const msg = try Module.ErrorMsg.create( |
| 35486 | | sema.gpa, |
| 35487 | | mod.declPtr(union_type.decl).srcLoc(mod), |
| 35355 | const msg = try sema.errMsg( |
| 35356 | ty.srcLoc(zcu), |
| 35488 | 35357 | "union '{}' depends on itself", |
| 35489 | | .{ty.fmt(mod)}, |
| 35358 | .{ty.fmt(zcu)}, |
| 35490 | 35359 | ); |
| 35491 | 35360 | return sema.failWithOwnedErrorMsg(null, msg); |
| 35492 | 35361 | }, |
| ... | ... | @@ -35505,7 +35374,7 @@ fn resolveUnionLayout(sema: *Sema, ty: Type) CompileError!void { |
| 35505 | 35374 | for (0..union_type.field_types.len) |field_index| { |
| 35506 | 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 | 35379 | max_size = @max(max_size, sema.typeAbiSize(field_ty) catch |err| switch (err) { |
| 35511 | 35380 | error.AnalysisFail => { |
| ... | ... | @@ -35547,7 +35416,7 @@ fn resolveUnionLayout(sema: *Sema, ty: Type) CompileError!void { |
| 35547 | 35416 | } else { |
| 35548 | 35417 | // {Payload, Tag} |
| 35549 | 35418 | size += max_size; |
| 35550 | | size = switch (mod.getTarget().ofmt) { |
| 35419 | size = switch (zcu.getTarget().ofmt) { |
| 35551 | 35420 | .c => max_align, |
| 35552 | 35421 | else => tag_align, |
| 35553 | 35422 | }.forward(size); |
| ... | ... | @@ -35566,9 +35435,8 @@ fn resolveUnionLayout(sema: *Sema, ty: Type) CompileError!void { |
| 35566 | 35435 | flags.status = .have_layout; |
| 35567 | 35436 | |
| 35568 | 35437 | if (union_type.flagsPtr(ip).assumed_runtime_bits and !(try sema.typeHasRuntimeBits(ty))) { |
| 35569 | | const msg = try Module.ErrorMsg.create( |
| 35570 | | sema.gpa, |
| 35571 | | mod.declPtr(union_type.decl).srcLoc(mod), |
| 35438 | const msg = try sema.errMsg( |
| 35439 | ty.srcLoc(zcu), |
| 35572 | 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 | 35444 | } |
| 35577 | 35445 | |
| 35578 | 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( |
| 35582 | | sema.gpa, |
| 35583 | | mod.declPtr(union_type.decl).srcLoc(mod), |
| 35449 | const msg = try sema.errMsg( |
| 35450 | ty.srcLoc(zcu), |
| 35584 | 35451 | "union layout depends on being pointer aligned", |
| 35585 | 35452 | .{}, |
| 35586 | 35453 | ); |
| ... | ... | @@ -35804,12 +35671,12 @@ pub fn resolveTypeFieldsStruct( |
| 35804 | 35671 | ty: InternPool.Index, |
| 35805 | 35672 | struct_type: InternPool.LoadedStructType, |
| 35806 | 35673 | ) CompileError!void { |
| 35807 | | const mod = sema.mod; |
| 35808 | | const ip = &mod.intern_pool; |
| 35674 | const zcu = sema.mod; |
| 35675 | const ip = &zcu.intern_pool; |
| 35809 | 35676 | // If there is no owner decl it means the struct has no fields. |
| 35810 | 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 | 35680 | .file_failure, |
| 35814 | 35681 | .dependency_failure, |
| 35815 | 35682 | .sema_failure, |
| ... | ... | @@ -35823,20 +35690,19 @@ pub fn resolveTypeFieldsStruct( |
| 35823 | 35690 | if (struct_type.haveFieldTypes(ip)) return; |
| 35824 | 35691 | |
| 35825 | 35692 | if (struct_type.setTypesWip(ip)) { |
| 35826 | | const msg = try Module.ErrorMsg.create( |
| 35827 | | sema.gpa, |
| 35828 | | mod.declPtr(owner_decl).srcLoc(mod), |
| 35693 | const msg = try sema.errMsg( |
| 35694 | Type.fromInterned(ty).srcLoc(zcu), |
| 35829 | 35695 | "struct '{}' depends on itself", |
| 35830 | | .{Type.fromInterned(ty).fmt(mod)}, |
| 35696 | .{Type.fromInterned(ty).fmt(zcu)}, |
| 35831 | 35697 | ); |
| 35832 | 35698 | return sema.failWithOwnedErrorMsg(null, msg); |
| 35833 | 35699 | } |
| 35834 | 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 | 35703 | error.AnalysisFail => { |
| 35838 | | if (mod.declPtr(owner_decl).analysis == .complete) { |
| 35839 | | mod.declPtr(owner_decl).analysis = .dependency_failure; |
| 35704 | if (zcu.declPtr(owner_decl).analysis == .complete) { |
| 35705 | zcu.declPtr(owner_decl).analysis = .dependency_failure; |
| 35840 | 35706 | } |
| 35841 | 35707 | return error.AnalysisFail; |
| 35842 | 35708 | }, |
| ... | ... | @@ -35845,9 +35711,9 @@ pub fn resolveTypeFieldsStruct( |
| 35845 | 35711 | } |
| 35846 | 35712 | |
| 35847 | 35713 | pub fn resolveStructFieldInits(sema: *Sema, ty: Type) CompileError!void { |
| 35848 | | const mod = sema.mod; |
| 35849 | | const ip = &mod.intern_pool; |
| 35850 | | const struct_type = mod.typeToStruct(ty) orelse return; |
| 35714 | const zcu = sema.mod; |
| 35715 | const ip = &zcu.intern_pool; |
| 35716 | const struct_type = zcu.typeToStruct(ty) orelse return; |
| 35851 | 35717 | const owner_decl = struct_type.decl.unwrap() orelse return; |
| 35852 | 35718 | |
| 35853 | 35719 | // Inits can start as resolved |
| ... | ... | @@ -35856,20 +35722,19 @@ pub fn resolveStructFieldInits(sema: *Sema, ty: Type) CompileError!void { |
| 35856 | 35722 | try sema.resolveStructLayout(ty); |
| 35857 | 35723 | |
| 35858 | 35724 | if (struct_type.setInitsWip(ip)) { |
| 35859 | | const msg = try Module.ErrorMsg.create( |
| 35860 | | sema.gpa, |
| 35861 | | mod.declPtr(owner_decl).srcLoc(mod), |
| 35725 | const msg = try sema.errMsg( |
| 35726 | ty.srcLoc(zcu), |
| 35862 | 35727 | "struct '{}' depends on itself", |
| 35863 | | .{ty.fmt(mod)}, |
| 35728 | .{ty.fmt(zcu)}, |
| 35864 | 35729 | ); |
| 35865 | 35730 | return sema.failWithOwnedErrorMsg(null, msg); |
| 35866 | 35731 | } |
| 35867 | 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 | 35735 | error.AnalysisFail => { |
| 35871 | | if (mod.declPtr(owner_decl).analysis == .complete) { |
| 35872 | | mod.declPtr(owner_decl).analysis = .dependency_failure; |
| 35736 | if (zcu.declPtr(owner_decl).analysis == .complete) { |
| 35737 | zcu.declPtr(owner_decl).analysis = .dependency_failure; |
| 35873 | 35738 | } |
| 35874 | 35739 | return error.AnalysisFail; |
| 35875 | 35740 | }, |
| ... | ... | @@ -35879,9 +35744,9 @@ pub fn resolveStructFieldInits(sema: *Sema, ty: Type) CompileError!void { |
| 35879 | 35744 | } |
| 35880 | 35745 | |
| 35881 | 35746 | pub fn resolveTypeFieldsUnion(sema: *Sema, ty: Type, union_type: InternPool.LoadedUnionType) CompileError!void { |
| 35882 | | const mod = sema.mod; |
| 35883 | | const ip = &mod.intern_pool; |
| 35884 | | const owner_decl = mod.declPtr(union_type.decl); |
| 35747 | const zcu = sema.mod; |
| 35748 | const ip = &zcu.intern_pool; |
| 35749 | const owner_decl = zcu.declPtr(union_type.decl); |
| 35885 | 35750 | switch (owner_decl.analysis) { |
| 35886 | 35751 | .file_failure, |
| 35887 | 35752 | .dependency_failure, |
| ... | ... | @@ -35895,11 +35760,10 @@ pub fn resolveTypeFieldsUnion(sema: *Sema, ty: Type, union_type: InternPool.Load |
| 35895 | 35760 | switch (union_type.flagsPtr(ip).status) { |
| 35896 | 35761 | .none => {}, |
| 35897 | 35762 | .field_types_wip => { |
| 35898 | | const msg = try Module.ErrorMsg.create( |
| 35899 | | sema.gpa, |
| 35900 | | owner_decl.srcLoc(mod), |
| 35763 | const msg = try sema.errMsg( |
| 35764 | ty.srcLoc(zcu), |
| 35901 | 35765 | "union '{}' depends on itself", |
| 35902 | | .{ty.fmt(mod)}, |
| 35766 | .{ty.fmt(zcu)}, |
| 35903 | 35767 | ); |
| 35904 | 35768 | return sema.failWithOwnedErrorMsg(null, msg); |
| 35905 | 35769 | }, |
| ... | ... | @@ -35913,7 +35777,7 @@ pub fn resolveTypeFieldsUnion(sema: *Sema, ty: Type, union_type: InternPool.Load |
| 35913 | 35777 | |
| 35914 | 35778 | union_type.flagsPtr(ip).status = .field_types_wip; |
| 35915 | 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 | 35781 | error.AnalysisFail => { |
| 35918 | 35782 | if (owner_decl.analysis == .complete) { |
| 35919 | 35783 | owner_decl.analysis = .dependency_failure; |
| ... | ... | @@ -35963,10 +35827,13 @@ fn resolveInferredErrorSet( |
| 35963 | 35827 | } else if (ip.errorUnionSet(ies_func_info.return_type) == ies_index) { |
| 35964 | 35828 | if (ies_func_info.is_generic) { |
| 35965 | 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 | 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 | 35837 | break :msg msg; |
| 35971 | 35838 | }; |
| 35972 | 35839 | return sema.failWithOwnedErrorMsg(block, msg); |
| ... | ... | @@ -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 | 36018 | defer comptime_err_ret_trace.deinit(); |
| 36152 | 36019 | |
| 36153 | 36020 | var sema: Sema = .{ |
| ... | ... | @@ -36174,6 +36041,7 @@ fn semaStructFields( |
| 36174 | 36041 | .instructions = .{}, |
| 36175 | 36042 | .inlining = null, |
| 36176 | 36043 | .is_comptime = true, |
| 36044 | .src_base_inst = struct_type.zir_index.unwrap().?, |
| 36177 | 36045 | }; |
| 36178 | 36046 | defer assert(block_scope.instructions.items.len == 0); |
| 36179 | 36047 | |
| ... | ... | @@ -36252,35 +36120,19 @@ fn semaStructFields( |
| 36252 | 36120 | // so that init values may depend on type layout. |
| 36253 | 36121 | |
| 36254 | 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 | 36127 | const field_ty: Type = ty: { |
| 36256 | 36128 | if (zir_field.type_ref != .none) { |
| 36257 | | break :ty sema.resolveType(&block_scope, .unneeded, zir_field.type_ref) catch |err| switch (err) { |
| 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 | | }; |
| 36129 | break :ty try sema.resolveType(&block_scope, ty_src, zir_field.type_ref); |
| 36268 | 36130 | } |
| 36269 | 36131 | assert(zir_field.type_body_len != 0); |
| 36270 | 36132 | const body = zir.bodySlice(extra_index, zir_field.type_body_len); |
| 36271 | 36133 | extra_index += body.len; |
| 36272 | 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) { |
| 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 | | }; |
| 36135 | break :ty try sema.analyzeAsType(&block_scope, ty_src, ty_ref); |
| 36284 | 36136 | }; |
| 36285 | 36137 | if (field_ty.isGenericPoison()) { |
| 36286 | 36138 | return error.GenericPoison; |
| ... | ... | @@ -36290,11 +36142,7 @@ fn semaStructFields( |
| 36290 | 36142 | |
| 36291 | 36143 | if (field_ty.zigTypeTag(mod) == .Opaque) { |
| 36292 | 36144 | const msg = msg: { |
| 36293 | | const ty_src = mod.fieldSrcLoc(decl_index, .{ |
| 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", .{}); |
| 36145 | const msg = try sema.errMsg(ty_src, "opaque types have unknown size and therefore cannot be directly embedded in structs", .{}); |
| 36298 | 36146 | errdefer msg.destroy(sema.gpa); |
| 36299 | 36147 | |
| 36300 | 36148 | try sema.addDeclaredHereNote(msg, field_ty); |
| ... | ... | @@ -36304,11 +36152,7 @@ fn semaStructFields( |
| 36304 | 36152 | } |
| 36305 | 36153 | if (field_ty.zigTypeTag(mod) == .NoReturn) { |
| 36306 | 36154 | const msg = msg: { |
| 36307 | | const ty_src = mod.fieldSrcLoc(decl_index, .{ |
| 36308 | | .index = field_i, |
| 36309 | | .range = .type, |
| 36310 | | }).lazy; |
| 36311 | | const msg = try sema.errMsg(&block_scope, ty_src, "struct fields cannot be 'noreturn'", .{}); |
| 36155 | const msg = try sema.errMsg(ty_src, "struct fields cannot be 'noreturn'", .{}); |
| 36312 | 36156 | errdefer msg.destroy(sema.gpa); |
| 36313 | 36157 | |
| 36314 | 36158 | try sema.addDeclaredHereNote(msg, field_ty); |
| ... | ... | @@ -36319,11 +36163,7 @@ fn semaStructFields( |
| 36319 | 36163 | switch (struct_type.layout) { |
| 36320 | 36164 | .@"extern" => if (!try sema.validateExternType(field_ty, .struct_field)) { |
| 36321 | 36165 | const msg = msg: { |
| 36322 | | const ty_src = mod.fieldSrcLoc(decl_index, .{ |
| 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)}); |
| 36166 | const msg = try sema.errMsg(ty_src, "extern structs cannot contain fields of type '{}'", .{field_ty.fmt(mod)}); |
| 36327 | 36167 | errdefer msg.destroy(sema.gpa); |
| 36328 | 36168 | |
| 36329 | 36169 | try sema.explainWhyTypeIsNotExtern(msg, ty_src, field_ty, .struct_field); |
| ... | ... | @@ -36335,11 +36175,7 @@ fn semaStructFields( |
| 36335 | 36175 | }, |
| 36336 | 36176 | .@"packed" => if (!try sema.validatePackedType(field_ty)) { |
| 36337 | 36177 | const msg = msg: { |
| 36338 | | const ty_src = mod.fieldSrcLoc(decl_index, .{ |
| 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)}); |
| 36178 | const msg = try sema.errMsg(ty_src, "packed structs cannot contain fields of type '{}'", .{field_ty.fmt(mod)}); |
| 36343 | 36179 | errdefer msg.destroy(sema.gpa); |
| 36344 | 36180 | |
| 36345 | 36181 | try sema.explainWhyTypeIsNotPacked(msg, ty_src, field_ty); |
| ... | ... | @@ -36356,17 +36192,11 @@ fn semaStructFields( |
| 36356 | 36192 | const body = zir.bodySlice(extra_index, zir_field.align_body_len); |
| 36357 | 36193 | extra_index += body.len; |
| 36358 | 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) { |
| 36360 | | error.NeededSourceLocation => { |
| 36361 | | const align_src = mod.fieldSrcLoc(decl_index, .{ |
| 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, |
| 36195 | const align_src: LazySrcLoc = .{ |
| 36196 | .base_node_inst = struct_type.zir_index.unwrap().?, |
| 36197 | .offset = .{ .container_field_align = @intCast(field_i) }, |
| 36369 | 36198 | }; |
| 36199 | const field_align = try sema.analyzeAsAlign(&block_scope, align_src, align_ref); |
| 36370 | 36200 | struct_type.field_aligns.get(ip)[field_i] = field_align; |
| 36371 | 36201 | } |
| 36372 | 36202 | |
| ... | ... | @@ -36395,7 +36225,7 @@ fn semaStructFieldInits( |
| 36395 | 36225 | const zir_index = struct_type.zir_index.unwrap().?.resolve(ip); |
| 36396 | 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 | 36229 | defer comptime_err_ret_trace.deinit(); |
| 36400 | 36230 | |
| 36401 | 36231 | var sema: Sema = .{ |
| ... | ... | @@ -36422,6 +36252,7 @@ fn semaStructFieldInits( |
| 36422 | 36252 | .instructions = .{}, |
| 36423 | 36253 | .inlining = null, |
| 36424 | 36254 | .is_comptime = true, |
| 36255 | .src_base_inst = struct_type.zir_index.unwrap().?, |
| 36425 | 36256 | }; |
| 36426 | 36257 | defer assert(block_scope.instructions.items.len == 0); |
| 36427 | 36258 | |
| ... | ... | @@ -36495,33 +36326,20 @@ fn semaStructFieldInits( |
| 36495 | 36326 | try sema.inst_map.ensureSpaceForInstructions(sema.gpa, &.{zir_index}); |
| 36496 | 36327 | sema.inst_map.putAssumeCapacity(zir_index, type_ref); |
| 36497 | 36328 | |
| 36498 | | const init = try sema.resolveInlineBody(&block_scope, body, zir_index); |
| 36499 | | const coerced = sema.coerce(&block_scope, field_ty, init, .unneeded) catch |err| switch (err) { |
| 36500 | | error.NeededSourceLocation => { |
| 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, |
| 36329 | const init_src: LazySrcLoc = .{ |
| 36330 | .base_node_inst = struct_type.zir_index.unwrap().?, |
| 36331 | .offset = .{ .container_field_value = @intCast(field_i) }, |
| 36509 | 36332 | }; |
| 36510 | | const default_val = (try sema.resolveValue(coerced)) orelse { |
| 36511 | | const init_src = mod.fieldSrcLoc(decl_index, .{ |
| 36512 | | .index = field_i, |
| 36513 | | .range = .value, |
| 36514 | | }).lazy; |
| 36333 | |
| 36334 | const init = try sema.resolveInlineBody(&block_scope, body, zir_index); |
| 36335 | const coerced = try sema.coerce(&block_scope, field_ty, init, init_src); |
| 36336 | const default_val = try sema.resolveValue(coerced) orelse { |
| 36515 | 36337 | return sema.failWithNeededComptime(&block_scope, init_src, .{ |
| 36516 | 36338 | .needed_comptime_reason = "struct field default value must be comptime-known", |
| 36517 | 36339 | }); |
| 36518 | 36340 | }; |
| 36519 | 36341 | |
| 36520 | 36342 | if (default_val.canMutateComptimeVarState(mod)) { |
| 36521 | | const init_src = mod.fieldSrcLoc(decl_index, .{ |
| 36522 | | .index = field_i, |
| 36523 | | .range = .value, |
| 36524 | | }).lazy; |
| 36525 | 36343 | return sema.fail(&block_scope, init_src, "field default value contains reference to comptime-mutable memory", .{}); |
| 36526 | 36344 | } |
| 36527 | 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 | 36361 | const small: Zir.Inst.UnionDecl.Small = @bitCast(extended.small); |
| 36544 | 36362 | var extra_index: usize = extended.operand + @typeInfo(Zir.Inst.UnionDecl).Struct.fields.len; |
| 36545 | 36363 | |
| 36546 | | const src = LazySrcLoc.nodeOffset(0); |
| 36547 | | |
| 36548 | 36364 | const tag_type_ref: Zir.Inst.Ref = if (small.has_tag_type) blk: { |
| 36549 | 36365 | const ty_ref: Zir.Inst.Ref = @enumFromInt(zir.extra[extra_index]); |
| 36550 | 36366 | extra_index += 1; |
| ... | ... | @@ -36583,7 +36399,7 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded |
| 36583 | 36399 | |
| 36584 | 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 | 36403 | defer comptime_err_ret_trace.deinit(); |
| 36588 | 36404 | |
| 36589 | 36405 | var sema: Sema = .{ |
| ... | ... | @@ -36610,9 +36426,12 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded |
| 36610 | 36426 | .instructions = .{}, |
| 36611 | 36427 | .inlining = null, |
| 36612 | 36428 | .is_comptime = true, |
| 36429 | .src_base_inst = union_type.zir_index, |
| 36613 | 36430 | }; |
| 36614 | 36431 | defer assert(block_scope.instructions.items.len == 0); |
| 36615 | 36432 | |
| 36433 | const src = block_scope.nodeOffset(0); |
| 36434 | |
| 36616 | 36435 | if (body.len != 0) { |
| 36617 | 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 | 36441 | var enum_field_vals: std.AutoArrayHashMapUnmanaged(InternPool.Index, void) = .{}; |
| 36623 | 36442 | var explicit_tags_seen: []bool = &.{}; |
| 36624 | 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 | 36448 | const provided_ty = try sema.resolveType(&block_scope, tag_ty_src, tag_type_ref); |
| 36627 | 36449 | if (small.auto_enum_tag) { |
| 36628 | 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 | 36457 | const field_count_val = try mod.intValue(Type.comptime_int, fields_len - 1); |
| 36636 | 36458 | if (!(try sema.intFitsInType(field_count_val, int_tag_ty, null))) { |
| 36637 | 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 | 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 | 36463 | int_tag_ty.fmt(mod), |
| 36642 | 36464 | fields_len - 1, |
| 36643 | 36465 | }); |
| ... | ... | @@ -36722,19 +36544,26 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded |
| 36722 | 36544 | break :blk try sema.resolveInst(tag_ref); |
| 36723 | 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 | 36564 | if (enum_field_vals.capacity() > 0) { |
| 36726 | 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) { |
| 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 | | }; |
| 36566 | const val = try sema.semaUnionFieldVal(&block_scope, value_src, int_tag_ty, tag_ref); |
| 36738 | 36567 | last_tag_val = val; |
| 36739 | 36568 | |
| 36740 | 36569 | break :blk val; |
| ... | ... | @@ -36749,12 +36578,14 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded |
| 36749 | 36578 | }; |
| 36750 | 36579 | const gop = enum_field_vals.getOrPutAssumeCapacity(enum_tag_val.toIntern()); |
| 36751 | 36580 | if (gop.found_existing) { |
| 36752 | | const field_src = mod.fieldSrcLoc(union_type.decl, .{ .index = field_i }).lazy; |
| 36753 | | const other_field_src = mod.fieldSrcLoc(union_type.decl, .{ .index = gop.index }).lazy; |
| 36581 | const other_value_src: LazySrcLoc = .{ |
| 36582 | .base_node_inst = union_type.zir_index, |
| 36583 | .offset = .{ .container_field_value = @intCast(gop.index) }, |
| 36584 | }; |
| 36754 | 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 | 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 | 36589 | break :msg msg; |
| 36759 | 36590 | }; |
| 36760 | 36591 | return sema.failWithOwnedErrorMsg(&block_scope, msg); |
| ... | ... | @@ -36772,17 +36603,7 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded |
| 36772 | 36603 | else if (field_type_ref == .none) |
| 36773 | 36604 | Type.noreturn |
| 36774 | 36605 | else |
| 36775 | | sema.resolveType(&block_scope, .unneeded, field_type_ref) catch |err| switch (err) { |
| 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 | | }; |
| 36606 | try sema.resolveType(&block_scope, type_src, field_type_ref); |
| 36786 | 36607 | |
| 36787 | 36608 | if (field_ty.isGenericPoison()) { |
| 36788 | 36609 | return error.GenericPoison; |
| ... | ... | @@ -36791,11 +36612,7 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded |
| 36791 | 36612 | if (explicit_tags_seen.len > 0) { |
| 36792 | 36613 | const tag_info = ip.loadEnumType(union_type.tagTypePtr(ip).*); |
| 36793 | 36614 | const enum_index = tag_info.nameIndex(ip, field_name) orelse { |
| 36794 | | const ty_src = mod.fieldSrcLoc(union_type.decl, .{ |
| 36795 | | .index = field_i, |
| 36796 | | .range = .name, |
| 36797 | | }).lazy; |
| 36798 | | return sema.fail(&block_scope, ty_src, "no field named '{}' in enum '{}'", .{ |
| 36615 | return sema.fail(&block_scope, name_src, "no field named '{}' in enum '{}'", .{ |
| 36799 | 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 | 36625 | // Enforce the enum fields and the union fields being in the same order. |
| 36809 | 36626 | if (enum_index != field_i) { |
| 36810 | 36627 | const msg = msg: { |
| 36811 | | const ty_src = mod.fieldSrcLoc(union_type.decl, .{ |
| 36812 | | .index = field_i, |
| 36813 | | .range = .name, |
| 36814 | | }).lazy; |
| 36815 | | const enum_field_src = mod.fieldSrcLoc(tag_info.decl, .{ .index = enum_index }).lazy; |
| 36816 | | const msg = try sema.errMsg(&block_scope, ty_src, "union field '{}' ordered differently than corresponding enum field", .{ |
| 36628 | const enum_field_src: LazySrcLoc = .{ |
| 36629 | .base_node_inst = tag_info.zir_index.unwrap().?, |
| 36630 | .offset = .{ .container_field_name = enum_index }, |
| 36631 | }; |
| 36632 | const msg = try sema.errMsg(name_src, "union field '{}' ordered differently than corresponding enum field", .{ |
| 36817 | 36633 | field_name.fmt(ip), |
| 36818 | 36634 | }); |
| 36819 | 36635 | errdefer msg.destroy(sema.gpa); |
| 36820 | | const decl_ptr = mod.declPtr(tag_info.decl); |
| 36821 | | try mod.errNoteNonLazy(decl_ptr.toSrcLoc(enum_field_src, mod), msg, "enum field here", .{}); |
| 36636 | try sema.errNote(enum_field_src, msg, "enum field here", .{}); |
| 36822 | 36637 | break :msg msg; |
| 36823 | 36638 | }; |
| 36824 | 36639 | return sema.failWithOwnedErrorMsg(&block_scope, msg); |
| ... | ... | @@ -36827,11 +36642,7 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded |
| 36827 | 36642 | |
| 36828 | 36643 | if (field_ty.zigTypeTag(mod) == .Opaque) { |
| 36829 | 36644 | const msg = msg: { |
| 36830 | | const ty_src = mod.fieldSrcLoc(union_type.decl, .{ |
| 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", .{}); |
| 36645 | const msg = try sema.errMsg(type_src, "opaque types have unknown size and therefore cannot be directly embedded in unions", .{}); |
| 36835 | 36646 | errdefer msg.destroy(sema.gpa); |
| 36836 | 36647 | |
| 36837 | 36648 | try sema.addDeclaredHereNote(msg, field_ty); |
| ... | ... | @@ -36844,14 +36655,10 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded |
| 36844 | 36655 | !try sema.validateExternType(field_ty, .union_field)) |
| 36845 | 36656 | { |
| 36846 | 36657 | const msg = msg: { |
| 36847 | | const ty_src = mod.fieldSrcLoc(union_type.decl, .{ |
| 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)}); |
| 36658 | const msg = try sema.errMsg(type_src, "extern unions cannot contain fields of type '{}'", .{field_ty.fmt(mod)}); |
| 36852 | 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 | 36663 | try sema.addDeclaredHereNote(msg, field_ty); |
| 36857 | 36664 | break :msg msg; |
| ... | ... | @@ -36859,14 +36666,10 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded |
| 36859 | 36666 | return sema.failWithOwnedErrorMsg(&block_scope, msg); |
| 36860 | 36667 | } else if (layout == .@"packed" and !try sema.validatePackedType(field_ty)) { |
| 36861 | 36668 | const msg = msg: { |
| 36862 | | const ty_src = mod.fieldSrcLoc(union_type.decl, .{ |
| 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)}); |
| 36669 | const msg = try sema.errMsg(type_src, "packed unions cannot contain fields of type '{}'", .{field_ty.fmt(mod)}); |
| 36867 | 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 | 36674 | try sema.addDeclaredHereNote(msg, field_ty); |
| 36872 | 36675 | break :msg msg; |
| ... | ... | @@ -36878,17 +36681,7 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded |
| 36878 | 36681 | |
| 36879 | 36682 | if (small.any_aligned_fields) { |
| 36880 | 36683 | field_aligns.appendAssumeCapacity(if (align_ref != .none) |
| 36881 | | sema.resolveAlign(&block_scope, .unneeded, align_ref) catch |err| switch (err) { |
| 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 | | } |
| 36684 | try sema.resolveAlign(&block_scope, align_src, align_ref) |
| 36892 | 36685 | else |
| 36893 | 36686 | .none); |
| 36894 | 36687 | } else { |
| ... | ... | @@ -36903,7 +36696,7 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded |
| 36903 | 36696 | const tag_info = ip.loadEnumType(union_type.tagTypePtr(ip).*); |
| 36904 | 36697 | if (tag_info.names.len > fields_len) { |
| 36905 | 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 | 36700 | errdefer msg.destroy(sema.gpa); |
| 36908 | 36701 | |
| 36909 | 36702 | for (tag_info.names.get(ip), 0..) |field_name, field_index| { |
| ... | ... | @@ -36945,7 +36738,7 @@ fn generateUnionTagTypeNumbered( |
| 36945 | 36738 | const ip = &mod.intern_pool; |
| 36946 | 36739 | |
| 36947 | 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 | 36742 | errdefer mod.destroyDecl(new_decl_index); |
| 36950 | 36743 | const fqn = try union_owner_decl.fullyQualifiedName(mod); |
| 36951 | 36744 | const name = try ip.getOrPutStringFmt( |
| ... | ... | @@ -36997,7 +36790,7 @@ fn generateUnionTagTypeSimple( |
| 36997 | 36790 | const new_decl_index = new_decl_index: { |
| 36998 | 36791 | const fqn = try union_owner_decl.fullyQualifiedName(mod); |
| 36999 | 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 | 36794 | errdefer mod.destroyDecl(new_decl_index); |
| 37002 | 36795 | const name = try ip.getOrPutStringFmt( |
| 37003 | 36796 | gpa, |
| ... | ... | @@ -37037,8 +36830,7 @@ fn generateUnionTagTypeSimple( |
| 37037 | 36830 | } |
| 37038 | 36831 | |
| 37039 | 36832 | fn getBuiltin(sema: *Sema, name: []const u8) CompileError!Air.Inst.Ref { |
| 37040 | | const gpa = sema.gpa; |
| 37041 | | const src = LazySrcLoc.nodeOffset(0); |
| 36833 | const zcu = sema.mod; |
| 37042 | 36834 | |
| 37043 | 36835 | var block: Block = .{ |
| 37044 | 36836 | .parent = null, |
| ... | ... | @@ -37048,8 +36840,23 @@ fn getBuiltin(sema: *Sema, name: []const u8) CompileError!Air.Inst.Ref { |
| 37048 | 36840 | .instructions = .{}, |
| 37049 | 36841 | .inlining = null, |
| 37050 | 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 | 36861 | const decl_index = try getBuiltinDecl(sema, &block, name); |
| 37055 | 36862 | return sema.analyzeDeclVal(&block, src, decl_index); |
| ... | ... | @@ -37058,7 +36865,7 @@ fn getBuiltin(sema: *Sema, name: []const u8) CompileError!Air.Inst.Ref { |
| 37058 | 36865 | fn getBuiltinDecl(sema: *Sema, block: *Block, name: []const u8) CompileError!InternPool.DeclIndex { |
| 37059 | 36866 | const gpa = sema.gpa; |
| 37060 | 36867 | |
| 37061 | | const src = LazySrcLoc.nodeOffset(0); |
| 36868 | const src = block.nodeOffset(0); |
| 37062 | 36869 | |
| 37063 | 36870 | const mod = sema.mod; |
| 37064 | 36871 | const ip = &mod.intern_pool; |
| ... | ... | @@ -37085,6 +36892,7 @@ fn getBuiltinDecl(sema: *Sema, block: *Block, name: []const u8) CompileError!Int |
| 37085 | 36892 | } |
| 37086 | 36893 | |
| 37087 | 36894 | fn getBuiltinType(sema: *Sema, name: []const u8) CompileError!Type { |
| 36895 | const zcu = sema.mod; |
| 37088 | 36896 | const ty_inst = try sema.getBuiltin(name); |
| 37089 | 36897 | |
| 37090 | 36898 | var block: Block = .{ |
| ... | ... | @@ -37095,9 +36903,23 @@ fn getBuiltinType(sema: *Sema, name: []const u8) CompileError!Type { |
| 37095 | 36903 | .instructions = .{}, |
| 37096 | 36904 | .inlining = null, |
| 37097 | 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 | 36920 | defer block.instructions.deinit(sema.gpa); |
| 37100 | | const src = LazySrcLoc.nodeOffset(0); |
| 36921 | |
| 36922 | const src = block.nodeOffset(0); |
| 37101 | 36923 | |
| 37102 | 36924 | const result_ty = sema.analyzeAsType(&block, src, ty_inst) catch |err| switch (err) { |
| 37103 | 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 | 36935 | /// that the types are already resolved. |
| 37114 | 36936 | /// TODO assert the return value matches `ty.onePossibleValue` |
| 37115 | 36937 | pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value { |
| 37116 | | const mod = sema.mod; |
| 37117 | | const ip = &mod.intern_pool; |
| 36938 | const zcu = sema.mod; |
| 36939 | const ip = &zcu.intern_pool; |
| 37118 | 36940 | return switch (ty.toIntern()) { |
| 37119 | 36941 | .u0_type, |
| 37120 | 36942 | .i0_type, |
| 37121 | | => try mod.intValue(ty, 0), |
| 36943 | => try zcu.intValue(ty, 0), |
| 37122 | 36944 | .u1_type, |
| 37123 | 36945 | .u8_type, |
| 37124 | 36946 | .i8_type, |
| ... | ... | @@ -37181,7 +37003,7 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value { |
| 37181 | 37003 | .anyframe_type => unreachable, |
| 37182 | 37004 | .null_type => Value.null, |
| 37183 | 37005 | .undefined_type => Value.undef, |
| 37184 | | .optional_noreturn_type => try mod.nullValue(ty), |
| 37006 | .optional_noreturn_type => try zcu.nullValue(ty), |
| 37185 | 37007 | .generic_poison_type => error.GenericPoison, |
| 37186 | 37008 | .empty_struct_type => Value.empty_struct, |
| 37187 | 37009 | // values, not types |
| ... | ... | @@ -37295,13 +37117,13 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value { |
| 37295 | 37117 | => switch (ip.indexToKey(ty.toIntern())) { |
| 37296 | 37118 | inline .array_type, .vector_type => |seq_type, seq_tag| { |
| 37297 | 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 | 37121 | .ty = ty.toIntern(), |
| 37300 | 37122 | .storage = .{ .elems = &.{} }, |
| 37301 | 37123 | } }))); |
| 37302 | 37124 | |
| 37303 | 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 | 37127 | .ty = ty.toIntern(), |
| 37306 | 37128 | .storage = .{ .repeated_elem = opv.toIntern() }, |
| 37307 | 37129 | } }))); |
| ... | ... | @@ -37316,7 +37138,7 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value { |
| 37316 | 37138 | if (struct_type.field_types.len == 0) { |
| 37317 | 37139 | // In this case the struct has no fields at all and |
| 37318 | 37140 | // therefore has one possible value. |
| 37319 | | return Value.fromInterned((try mod.intern(.{ .aggregate = .{ |
| 37141 | return Value.fromInterned((try zcu.intern(.{ .aggregate = .{ |
| 37320 | 37142 | .ty = ty.toIntern(), |
| 37321 | 37143 | .storage = .{ .elems = &.{} }, |
| 37322 | 37144 | } }))); |
| ... | ... | @@ -37333,12 +37155,11 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value { |
| 37333 | 37155 | continue; |
| 37334 | 37156 | } |
| 37335 | 37157 | const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[i]); |
| 37336 | | if (field_ty.eql(ty, mod)) { |
| 37337 | | const msg = try Module.ErrorMsg.create( |
| 37338 | | sema.gpa, |
| 37339 | | mod.declPtr(struct_type.decl.unwrap().?).srcLoc(mod), |
| 37158 | if (field_ty.eql(ty, zcu)) { |
| 37159 | const msg = try sema.errMsg( |
| 37160 | ty.srcLoc(zcu), |
| 37340 | 37161 | "struct '{}' depends on itself", |
| 37341 | | .{ty.fmt(mod)}, |
| 37162 | .{ty.fmt(zcu)}, |
| 37342 | 37163 | ); |
| 37343 | 37164 | try sema.addFieldErrNote(ty, i, msg, "while checking this field", .{}); |
| 37344 | 37165 | return sema.failWithOwnedErrorMsg(null, msg); |
| ... | ... | @@ -37350,7 +37171,7 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value { |
| 37350 | 37171 | |
| 37351 | 37172 | // In this case the struct has no runtime-known fields and |
| 37352 | 37173 | // therefore has one possible value. |
| 37353 | | return Value.fromInterned((try mod.intern(.{ .aggregate = .{ |
| 37174 | return Value.fromInterned((try zcu.intern(.{ .aggregate = .{ |
| 37354 | 37175 | .ty = ty.toIntern(), |
| 37355 | 37176 | .storage = .{ .elems = field_vals }, |
| 37356 | 37177 | } }))); |
| ... | ... | @@ -37363,7 +37184,7 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value { |
| 37363 | 37184 | // In this case the struct has all comptime-known fields and |
| 37364 | 37185 | // therefore has one possible value. |
| 37365 | 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 | 37188 | .ty = ty.toIntern(), |
| 37368 | 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 | 37196 | const tag_val = (try sema.typeHasOnePossibleValue(Type.fromInterned(union_obj.tagTypePtr(ip).*))) orelse |
| 37376 | 37197 | return null; |
| 37377 | 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 | 37200 | return Value.fromInterned(only); |
| 37380 | 37201 | } |
| 37381 | 37202 | const only_field_ty = Type.fromInterned(union_obj.field_types.get(ip)[0]); |
| 37382 | | if (only_field_ty.eql(ty, mod)) { |
| 37383 | | const msg = try Module.ErrorMsg.create( |
| 37384 | | sema.gpa, |
| 37385 | | mod.declPtr(union_obj.decl).srcLoc(mod), |
| 37203 | if (only_field_ty.eql(ty, zcu)) { |
| 37204 | const msg = try sema.errMsg( |
| 37205 | ty.srcLoc(zcu), |
| 37386 | 37206 | "union '{}' depends on itself", |
| 37387 | | .{ty.fmt(mod)}, |
| 37207 | .{ty.fmt(zcu)}, |
| 37388 | 37208 | ); |
| 37389 | 37209 | try sema.addFieldErrNote(ty, 0, msg, "while checking this field", .{}); |
| 37390 | 37210 | return sema.failWithOwnedErrorMsg(null, msg); |
| 37391 | 37211 | } |
| 37392 | 37212 | const val_val = (try sema.typeHasOnePossibleValue(only_field_ty)) orelse |
| 37393 | 37213 | return null; |
| 37394 | | const only = try mod.intern(.{ .un = .{ |
| 37214 | const only = try zcu.intern(.{ .un = .{ |
| 37395 | 37215 | .ty = ty.toIntern(), |
| 37396 | 37216 | .tag = tag_val.toIntern(), |
| 37397 | 37217 | .val = val_val.toIntern(), |
| ... | ... | @@ -37406,7 +37226,7 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value { |
| 37406 | 37226 | if (enum_type.tag_ty == .comptime_int_type) return null; |
| 37407 | 37227 | |
| 37408 | 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 | 37230 | .ty = ty.toIntern(), |
| 37411 | 37231 | .int = int_opv.toIntern(), |
| 37412 | 37232 | } }); |
| ... | ... | @@ -37416,18 +37236,18 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value { |
| 37416 | 37236 | return null; |
| 37417 | 37237 | }, |
| 37418 | 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 | 37241 | return Value.fromInterned(switch (enum_type.names.len) { |
| 37422 | | 0 => try mod.intern(.{ .empty_enum_value = ty.toIntern() }), |
| 37423 | | 1 => try mod.intern(.{ .enum_tag = .{ |
| 37242 | 0 => try zcu.intern(.{ .empty_enum_value = ty.toIntern() }), |
| 37243 | 1 => try zcu.intern(.{ .enum_tag = .{ |
| 37424 | 37244 | .ty = ty.toIntern(), |
| 37425 | 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 | 37247 | else |
| 37428 | | try mod.intern_pool.getCoercedInts( |
| 37429 | | mod.gpa, |
| 37430 | | mod.intern_pool.indexToKey(enum_type.values.get(ip)[0]).int, |
| 37248 | try zcu.intern_pool.getCoercedInts( |
| 37249 | zcu.gpa, |
| 37250 | zcu.intern_pool.indexToKey(enum_type.values.get(ip)[0]).int, |
| 37431 | 37251 | enum_type.tag_ty, |
| 37432 | 37252 | ), |
| 37433 | 37253 | } }), |
| ... | ... | @@ -37765,7 +37585,7 @@ fn unionFieldIndex( |
| 37765 | 37585 | try sema.resolveTypeFields(union_ty); |
| 37766 | 37586 | const union_obj = mod.typeToUnion(union_ty).?; |
| 37767 | 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 | 37589 | return @intCast(field_index); |
| 37770 | 37590 | } |
| 37771 | 37591 | |
| ... | ... | @@ -37784,7 +37604,7 @@ fn structFieldIndex( |
| 37784 | 37604 | } else { |
| 37785 | 37605 | const struct_type = mod.typeToStruct(struct_ty).?; |
| 37786 | 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 | 38376 | fn validateRuntimeValue(sema: *Sema, block: *Block, val_src: LazySrcLoc, val: Air.Inst.Ref) CompileError!void { |
| 38557 | 38377 | if (sema.checkRuntimeValue(val)) return; |
| 38558 | 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 | 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 | 38382 | break :msg msg; |
| 38563 | 38383 | }); |
| 38564 | 38384 | } |
| ... | ... | @@ -38649,6 +38469,14 @@ fn maybeDerefSliceAsArray( |
| 38649 | 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 | 38480 | pub const bitCastVal = @import("Sema/bitcast.zig").bitCast; |
| 38653 | 38481 | pub const bitCastSpliceVal = @import("Sema/bitcast.zig").bitCastSplice; |
| 38654 | 38482 | |