| ... | @@ -16,9 +16,7 @@ air_instructions: std.MultiArrayList(Air.Inst) = .{}, | ... | @@ -16,9 +16,7 @@ air_instructions: std.MultiArrayList(Air.Inst) = .{}, |
| 16 | air_extra: std.ArrayListUnmanaged(u32) = .{}, | 16 | air_extra: std.ArrayListUnmanaged(u32) = .{}, |
| 17 | /// Maps ZIR to AIR. | 17 | /// Maps ZIR to AIR. |
| 18 | inst_map: InstMap = .{}, | 18 | inst_map: InstMap = .{}, |
| 19 | /// When analyzing an inline function call, owner_decl is the Decl of the caller | 19 | /// When analyzing an inline function call, owner_decl is the Decl of the caller. |
| 20 | /// and `src_decl` of `Block` is the `Decl` of the callee. | | |
| 21 | /// This `Decl` owns the arena memory of this `Sema`. | | |
| 22 | owner_decl: *Decl, | 20 | owner_decl: *Decl, |
| 23 | owner_decl_index: InternPool.DeclIndex, | 21 | owner_decl_index: InternPool.DeclIndex, |
| 24 | /// For an inline or comptime function call, this will be the root parent function | 22 | /// For an inline or comptime function call, this will be the root parent function |
| ... | @@ -34,7 +32,7 @@ func_index: InternPool.Index, | ... | @@ -34,7 +32,7 @@ func_index: InternPool.Index, |
| 34 | func_is_naked: bool, | 32 | func_is_naked: bool, |
| 35 | /// Used to restore the error return trace when returning a non-error from a function. | 33 | /// Used to restore the error return trace when returning a non-error from a function. |
| 36 | error_return_trace_index_on_fn_entry: Air.Inst.Ref = .none, | 34 | error_return_trace_index_on_fn_entry: Air.Inst.Ref = .none, |
| 37 | comptime_err_ret_trace: *std.ArrayList(Module.SrcLoc), | 35 | comptime_err_ret_trace: *std.ArrayList(LazySrcLoc), |
| 38 | /// When semantic analysis needs to know the return type of the function whose body | 36 | /// When semantic analysis needs to know the return type of the function whose body |
| 39 | /// is being analyzed, this `Type` should be used instead of going through `func`. | 37 | /// is being analyzed, this `Type` should be used instead of going through `func`. |
| 40 | /// This will correctly handle the case of a comptime/inline function call of a | 38 | /// This will correctly handle the case of a comptime/inline function call of a |
| ... | @@ -65,9 +63,7 @@ generic_owner: InternPool.Index = .none, | ... | @@ -65,9 +63,7 @@ generic_owner: InternPool.Index = .none, |
| 65 | /// instantiation callsite so that compile errors on the parameter types of the | 63 | /// instantiation callsite so that compile errors on the parameter types of the |
| 66 | /// instantiation can point back to the instantiation site in addition to the | 64 | /// instantiation can point back to the instantiation site in addition to the |
| 67 | /// declaration site. | 65 | /// declaration site. |
| 68 | generic_call_src: LazySrcLoc = .unneeded, | 66 | generic_call_src: LazySrcLoc = LazySrcLoc.unneeded, |
| 69 | /// Corresponds to `generic_call_src`. | | |
| 70 | generic_call_decl: InternPool.OptionalDeclIndex = .none, | | |
| 71 | /// The key is types that must be fully resolved prior to machine code | 67 | /// The key is types that must be fully resolved prior to machine code |
| 72 | /// generation pass. Types are added to this set when resolving them | 68 | /// generation pass. Types are added to this set when resolving them |
| 73 | /// immediately could cause a dependency loop, but they do need to be resolved | 69 | /// immediately could cause a dependency loop, but they do need to be resolved |
| ... | @@ -131,7 +127,6 @@ const MaybeComptimeAlloc = struct { | ... | @@ -131,7 +127,6 @@ const MaybeComptimeAlloc = struct { |
| 131 | /// If the instruction is one of these three tags, `src` may be `.unneeded`. | 127 | /// If the instruction is one of these three tags, `src` may be `.unneeded`. |
| 132 | stores: std.MultiArrayList(struct { | 128 | stores: std.MultiArrayList(struct { |
| 133 | inst: Air.Inst.Index, | 129 | inst: Air.Inst.Index, |
| 134 | src_decl: InternPool.DeclIndex, | | |
| 135 | src: LazySrcLoc, | 130 | src: LazySrcLoc, |
| 136 | }) = .{}, | 131 | }) = .{}, |
| 137 | }; | 132 | }; |
| ... | @@ -182,7 +177,7 @@ const Namespace = Module.Namespace; | ... | @@ -182,7 +177,7 @@ const Namespace = Module.Namespace; |
| 182 | const CompileError = Module.CompileError; | 177 | const CompileError = Module.CompileError; |
| 183 | const SemaError = Module.SemaError; | 178 | const SemaError = Module.SemaError; |
| 184 | const Decl = Module.Decl; | 179 | const Decl = Module.Decl; |
| 185 | const LazySrcLoc = std.zig.LazySrcLoc; | 180 | const LazySrcLoc = Zcu.LazySrcLoc; |
| 186 | const RangeSet = @import("RangeSet.zig"); | 181 | const RangeSet = @import("RangeSet.zig"); |
| 187 | const target_util = @import("target.zig"); | 182 | const target_util = @import("target.zig"); |
| 188 | const Package = @import("Package.zig"); | 183 | const Package = @import("Package.zig"); |
| ... | @@ -345,7 +340,6 @@ pub const Block = struct { | ... | @@ -345,7 +340,6 @@ pub const Block = struct { |
| 345 | /// Shared among all child blocks. | 340 | /// Shared among all child blocks. |
| 346 | sema: *Sema, | 341 | sema: *Sema, |
| 347 | /// The namespace to use for lookups from this source block | 342 | /// The namespace to use for lookups from this source block |
| 348 | /// When analyzing fields, this is different from src_decl.src_namespace. | | |
| 349 | namespace: InternPool.NamespaceIndex, | 343 | namespace: InternPool.NamespaceIndex, |
| 350 | /// The AIR instructions generated for this block. | 344 | /// The AIR instructions generated for this block. |
| 351 | instructions: std.ArrayListUnmanaged(Air.Inst.Index), | 345 | instructions: std.ArrayListUnmanaged(Air.Inst.Index), |
| ... | @@ -361,12 +355,8 @@ pub const Block = struct { | ... | @@ -361,12 +355,8 @@ pub const Block = struct { |
| 361 | label: ?*Label = null, | 355 | label: ?*Label = null, |
| 362 | inlining: ?*Inlining, | 356 | inlining: ?*Inlining, |
| 363 | /// If runtime_index is not 0 then one of these is guaranteed to be non null. | 357 | /// If runtime_index is not 0 then one of these is guaranteed to be non null. |
| 364 | runtime_cond: ?Module.SrcLoc = null, | 358 | runtime_cond: ?LazySrcLoc = null, |
| 365 | runtime_loop: ?Module.SrcLoc = null, | 359 | runtime_loop: ?LazySrcLoc = null, |
| 366 | /// This Decl is the Decl according to the Zig source code corresponding to this Block. | | |
| 367 | /// This can vary during inline or comptime function calls. See `Sema.owner_decl` | | |
| 368 | /// for the one that will be the same for all Block instances. | | |
| 369 | src_decl: InternPool.DeclIndex, | | |
| 370 | /// Non zero if a non-inline loop or a runtime conditional have been encountered. | 360 | /// Non zero if a non-inline loop or a runtime conditional have been encountered. |
| 371 | /// Stores to comptime variables are only allowed when var.runtime_index <= runtime_index. | 361 | /// Stores to comptime variables are only allowed when var.runtime_index <= runtime_index. |
| 372 | runtime_index: Value.RuntimeIndex = .zero, | 362 | runtime_index: Value.RuntimeIndex = .zero, |
| ... | @@ -395,13 +385,45 @@ pub const Block = struct { | ... | @@ -395,13 +385,45 @@ pub const Block = struct { |
| 395 | /// `block` in order for codegen to match lexical scoping for debug vars. | 385 | /// `block` in order for codegen to match lexical scoping for debug vars. |
| 396 | need_debug_scope: ?*bool = null, | 386 | need_debug_scope: ?*bool = null, |
| 397 | | 387 | |
| | 388 | /// Relative source locations encountered while traversing this block should be |
| | 389 | /// treated as relative to the AST node of this ZIR instruction. |
| | 390 | src_base_inst: InternPool.TrackedInst.Index, |
| | 391 | |
| | 392 | /// The name of the current "context" for naming namespace types. |
| | 393 | /// The interpretation of this depends on the name strategy in ZIR, but the name |
| | 394 | /// is always incorporated into the type name somehow. |
| | 395 | /// See `Sema.createAnonymousDeclTypeNamed`. |
| | 396 | type_name_ctx: InternPool.NullTerminatedString, |
| | 397 | |
| | 398 | /// Create a `LazySrcLoc` based on an `Offset` from the code being analyzed in this block. |
| | 399 | /// Specifically, the given `Offset` is treated as relative to `block.src_base_inst`. |
| | 400 | pub fn src(block: Block, offset: LazySrcLoc.Offset) LazySrcLoc { |
| | 401 | return .{ |
| | 402 | .base_node_inst = block.src_base_inst, |
| | 403 | .offset = offset, |
| | 404 | }; |
| | 405 | } |
| | 406 | |
| | 407 | fn builtinCallArgSrc(block: *Block, builtin_call_node: i32, arg_index: u32) LazySrcLoc { |
| | 408 | return block.src(.{ .node_offset_builtin_call_arg = .{ |
| | 409 | .builtin_call_node = builtin_call_node, |
| | 410 | .arg_index = arg_index, |
| | 411 | } }); |
| | 412 | } |
| | 413 | |
| | 414 | fn nodeOffset(block: Block, node_offset: i32) LazySrcLoc { |
| | 415 | return block.src(LazySrcLoc.Offset.nodeOffset(node_offset)); |
| | 416 | } |
| | 417 | |
| | 418 | fn tokenOffset(block: Block, tok_offset: u32) LazySrcLoc { |
| | 419 | return block.src(.{ .token_offset = tok_offset }); |
| | 420 | } |
| | 421 | |
| 398 | const ComptimeReason = union(enum) { | 422 | const ComptimeReason = union(enum) { |
| 399 | c_import: struct { | 423 | c_import: struct { |
| 400 | block: *Block, | | |
| 401 | src: LazySrcLoc, | 424 | src: LazySrcLoc, |
| 402 | }, | 425 | }, |
| 403 | comptime_ret_ty: struct { | 426 | comptime_ret_ty: struct { |
| 404 | block: *Block, | | |
| 405 | func: Air.Inst.Ref, | 427 | func: Air.Inst.Ref, |
| 406 | func_src: LazySrcLoc, | 428 | func_src: LazySrcLoc, |
| 407 | return_ty: Type, | 429 | return_ty: Type, |
| ... | @@ -413,27 +435,23 @@ pub const Block = struct { | ... | @@ -413,27 +435,23 @@ pub const Block = struct { |
| 413 | const prefix = "expression is evaluated at comptime because "; | 435 | const prefix = "expression is evaluated at comptime because "; |
| 414 | switch (cr) { | 436 | switch (cr) { |
| 415 | .c_import => |ci| { | 437 | .c_import => |ci| { |
| 416 | try sema.errNote(ci.block, ci.src, parent, prefix ++ "it is inside a @cImport", .{}); | 438 | try sema.errNote(ci.src, parent, prefix ++ "it is inside a @cImport", .{}); |
| 417 | }, | 439 | }, |
| 418 | .comptime_ret_ty => |rt| { | 440 | .comptime_ret_ty => |rt| { |
| 419 | const src_loc = if (try sema.funcDeclSrc(rt.func)) |fn_decl| blk: { | 441 | const ret_ty_src: LazySrcLoc = if (try sema.funcDeclSrc(rt.func)) |fn_decl| .{ |
| 420 | var src_loc = fn_decl.srcLoc(mod); | 442 | .base_node_inst = fn_decl.zir_decl_index.unwrap().?, |
| 421 | src_loc.lazy = .{ .node_offset_fn_type_ret_ty = 0 }; | 443 | .offset = .{ .node_offset_fn_type_ret_ty = 0 }, |
| 422 | break :blk src_loc; | 444 | } else rt.func_src; |
| 423 | } else blk: { | | |
| 424 | const src_decl = mod.declPtr(rt.block.src_decl); | | |
| 425 | break :blk src_decl.toSrcLoc(rt.func_src, mod); | | |
| 426 | }; | | |
| 427 | if (rt.return_ty.isGenericPoison()) { | 445 | if (rt.return_ty.isGenericPoison()) { |
| 428 | return mod.errNoteNonLazy(src_loc, parent, prefix ++ "the generic function was instantiated with a comptime-only return type", .{}); | 446 | return sema.errNote(ret_ty_src, parent, prefix ++ "the generic function was instantiated with a comptime-only return type", .{}); |
| 429 | } | 447 | } |
| 430 | try mod.errNoteNonLazy( | 448 | try sema.errNote( |
| 431 | src_loc, | 449 | ret_ty_src, |
| 432 | parent, | 450 | parent, |
| 433 | prefix ++ "the function returns a comptime-only type '{}'", | 451 | prefix ++ "the function returns a comptime-only type '{}'", |
| 434 | .{rt.return_ty.fmt(mod)}, | 452 | .{rt.return_ty.fmt(mod)}, |
| 435 | ); | 453 | ); |
| 436 | try sema.explainWhyTypeIsComptime(parent, src_loc, rt.return_ty); | 454 | try sema.explainWhyTypeIsComptime(parent, ret_ty_src, rt.return_ty); |
| 437 | }, | 455 | }, |
| 438 | } | 456 | } |
| 439 | } | 457 | } |
| ... | @@ -497,7 +515,6 @@ pub const Block = struct { | ... | @@ -497,7 +515,6 @@ pub const Block = struct { |
| 497 | return .{ | 515 | return .{ |
| 498 | .parent = parent, | 516 | .parent = parent, |
| 499 | .sema = parent.sema, | 517 | .sema = parent.sema, |
| 500 | .src_decl = parent.src_decl, | | |
| 501 | .namespace = parent.namespace, | 518 | .namespace = parent.namespace, |
| 502 | .instructions = .{}, | 519 | .instructions = .{}, |
| 503 | .label = null, | 520 | .label = null, |
| ... | @@ -513,6 +530,8 @@ pub const Block = struct { | ... | @@ -513,6 +530,8 @@ pub const Block = struct { |
| 513 | .c_import_buf = parent.c_import_buf, | 530 | .c_import_buf = parent.c_import_buf, |
| 514 | .error_return_trace_index = parent.error_return_trace_index, | 531 | .error_return_trace_index = parent.error_return_trace_index, |
| 515 | .need_debug_scope = parent.need_debug_scope, | 532 | .need_debug_scope = parent.need_debug_scope, |
| | 533 | .src_base_inst = parent.src_base_inst, |
| | 534 | .type_name_ctx = parent.type_name_ctx, |
| 516 | }; | 535 | }; |
| 517 | } | 536 | } |
| 518 | | 537 | |
| ... | @@ -803,14 +822,6 @@ pub const Block = struct { | ... | @@ -803,14 +822,6 @@ pub const Block = struct { |
| 803 | return result_index; | 822 | return result_index; |
| 804 | } | 823 | } |
| 805 | | 824 | |
| 806 | fn addUnreachable(block: *Block, src: LazySrcLoc, safety_check: bool) !void { | | |
| 807 | if (safety_check and block.wantSafety()) { | | |
| 808 | try block.sema.safetyPanic(block, src, .unreach); | | |
| 809 | } else { | | |
| 810 | _ = try block.addNoOp(.unreach); | | |
| 811 | } | | |
| 812 | } | | |
| 813 | | | |
| 814 | pub fn ownerModule(block: Block) *Package.Module { | 825 | pub fn ownerModule(block: Block) *Package.Module { |
| 815 | const zcu = block.sema.mod; | 826 | const zcu = block.sema.mod; |
| 816 | return zcu.namespacePtr(block.namespace).file_scope.mod; | 827 | return zcu.namespacePtr(block.namespace).file_scope.mod; |
| ... | @@ -981,9 +992,16 @@ fn analyzeBodyInner( | ... | @@ -981,9 +992,16 @@ fn analyzeBodyInner( |
| 981 | while (true) { | 992 | while (true) { |
| 982 | crash_info.setBodyIndex(i); | 993 | crash_info.setBodyIndex(i); |
| 983 | const inst = body[i]; | 994 | const inst = body[i]; |
| 984 | std.log.scoped(.sema_zir).debug("sema ZIR {s} %{d}", .{ | 995 | |
| 985 | mod.namespacePtr(mod.declPtr(block.src_decl).src_namespace).file_scope.sub_file_path, inst, | 996 | // The hashmap lookup in here is a little expensive, and LLVM fails to optimize it away. |
| 986 | }); | 997 | if (build_options.enable_logging) { |
| | 998 | std.log.scoped(.sema_zir).debug("sema ZIR {s} %{d}", .{ sub_file_path: { |
| | 999 | const path_digest = block.src_base_inst.resolveFull(&mod.intern_pool).path_digest; |
| | 1000 | const index = mod.path_digest_map.getIndex(path_digest).?; |
| | 1001 | break :sub_file_path mod.import_table.values()[index].sub_file_path; |
| | 1002 | }, inst }); |
| | 1003 | } |
| | 1004 | |
| 987 | const air_inst: Air.Inst.Ref = switch (tags[@intFromEnum(inst)]) { | 1005 | const air_inst: Air.Inst.Ref = switch (tags[@intFromEnum(inst)]) { |
| 988 | // zig fmt: off | 1006 | // zig fmt: off |
| 989 | .alloc => try sema.zirAlloc(block, inst), | 1007 | .alloc => try sema.zirAlloc(block, inst), |
| ... | @@ -1225,7 +1243,7 @@ fn analyzeBodyInner( | ... | @@ -1225,7 +1243,7 @@ fn analyzeBodyInner( |
| 1225 | .@"asm" => try sema.zirAsm( block, extended, false), | 1243 | .@"asm" => try sema.zirAsm( block, extended, false), |
| 1226 | .asm_expr => try sema.zirAsm( block, extended, true), | 1244 | .asm_expr => try sema.zirAsm( block, extended, true), |
| 1227 | .typeof_peer => try sema.zirTypeofPeer( block, extended, inst), | 1245 | .typeof_peer => try sema.zirTypeofPeer( block, extended, inst), |
| 1228 | .compile_log => try sema.zirCompileLog( extended), | 1246 | .compile_log => try sema.zirCompileLog( block, extended), |
| 1229 | .min_multi => try sema.zirMinMaxMulti( block, extended, .min), | 1247 | .min_multi => try sema.zirMinMaxMulti( block, extended, .min), |
| 1230 | .max_multi => try sema.zirMinMaxMulti( block, extended, .max), | 1248 | .max_multi => try sema.zirMinMaxMulti( block, extended, .max), |
| 1231 | .add_with_overflow => try sema.zirOverflowArithmetic(block, extended, extended.opcode), | 1249 | .add_with_overflow => try sema.zirOverflowArithmetic(block, extended, extended.opcode), |
| ... | @@ -1449,7 +1467,7 @@ fn analyzeBodyInner( | ... | @@ -1449,7 +1467,7 @@ fn analyzeBodyInner( |
| 1449 | .check_comptime_control_flow => { | 1467 | .check_comptime_control_flow => { |
| 1450 | if (!block.is_comptime) { | 1468 | if (!block.is_comptime) { |
| 1451 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; | 1469 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 1452 | const src = inst_data.src(); | 1470 | const src = block.nodeOffset(inst_data.src_node); |
| 1453 | const inline_block = inst_data.operand.toIndex().?; | 1471 | const inline_block = inst_data.operand.toIndex().?; |
| 1454 | | 1472 | |
| 1455 | var check_block = block; | 1473 | var check_block = block; |
| ... | @@ -1463,10 +1481,9 @@ fn analyzeBodyInner( | ... | @@ -1463,10 +1481,9 @@ fn analyzeBodyInner( |
| 1463 | if (@intFromEnum(target_runtime_index) < @intFromEnum(block.runtime_index)) { | 1481 | if (@intFromEnum(target_runtime_index) < @intFromEnum(block.runtime_index)) { |
| 1464 | const runtime_src = block.runtime_cond orelse block.runtime_loop.?; | 1482 | const runtime_src = block.runtime_cond orelse block.runtime_loop.?; |
| 1465 | const msg = msg: { | 1483 | const msg = msg: { |
| 1466 | const msg = try sema.errMsg(block, src, "comptime control flow inside runtime block", .{}); | 1484 | const msg = try sema.errMsg(src, "comptime control flow inside runtime block", .{}); |
| 1467 | errdefer msg.destroy(sema.gpa); | 1485 | errdefer msg.destroy(sema.gpa); |
| 1468 | | 1486 | try sema.errNote(runtime_src, msg, "runtime control flow here", .{}); |
| 1469 | try mod.errNoteNonLazy(runtime_src, msg, "runtime control flow here", .{}); | | |
| 1470 | break :msg msg; | 1487 | break :msg msg; |
| 1471 | }; | 1488 | }; |
| 1472 | return sema.failWithOwnedErrorMsg(block, msg); | 1489 | return sema.failWithOwnedErrorMsg(block, msg); |
| ... | @@ -1482,13 +1499,13 @@ fn analyzeBodyInner( | ... | @@ -1482,13 +1499,13 @@ fn analyzeBodyInner( |
| 1482 | }, | 1499 | }, |
| 1483 | .restore_err_ret_index_unconditional => { | 1500 | .restore_err_ret_index_unconditional => { |
| 1484 | const un_node = datas[@intFromEnum(inst)].un_node; | 1501 | const un_node = datas[@intFromEnum(inst)].un_node; |
| 1485 | try sema.restoreErrRetIndex(block, un_node.src(), un_node.operand, .none); | 1502 | try sema.restoreErrRetIndex(block, block.nodeOffset(un_node.src_node), un_node.operand, .none); |
| 1486 | i += 1; | 1503 | i += 1; |
| 1487 | continue; | 1504 | continue; |
| 1488 | }, | 1505 | }, |
| 1489 | .restore_err_ret_index_fn_entry => { | 1506 | .restore_err_ret_index_fn_entry => { |
| 1490 | const un_node = datas[@intFromEnum(inst)].un_node; | 1507 | const un_node = datas[@intFromEnum(inst)].un_node; |
| 1491 | try sema.restoreErrRetIndex(block, un_node.src(), .none, un_node.operand); | 1508 | try sema.restoreErrRetIndex(block, block.nodeOffset(un_node.src_node), .none, un_node.operand); |
| 1492 | i += 1; | 1509 | i += 1; |
| 1493 | continue; | 1510 | continue; |
| 1494 | }, | 1511 | }, |
| ... | @@ -1510,7 +1527,7 @@ fn analyzeBodyInner( | ... | @@ -1510,7 +1527,7 @@ fn analyzeBodyInner( |
| 1510 | .repeat => { | 1527 | .repeat => { |
| 1511 | if (block.is_comptime) { | 1528 | if (block.is_comptime) { |
| 1512 | // Send comptime control flow back to the beginning of this block. | 1529 | // Send comptime control flow back to the beginning of this block. |
| 1513 | const src = LazySrcLoc.nodeOffset(datas[@intFromEnum(inst)].node); | 1530 | const src = block.nodeOffset(datas[@intFromEnum(inst)].node); |
| 1514 | try sema.emitBackwardBranch(block, src); | 1531 | try sema.emitBackwardBranch(block, src); |
| 1515 | i = 0; | 1532 | i = 0; |
| 1516 | continue; | 1533 | continue; |
| ... | @@ -1523,7 +1540,7 @@ fn analyzeBodyInner( | ... | @@ -1523,7 +1540,7 @@ fn analyzeBodyInner( |
| 1523 | }, | 1540 | }, |
| 1524 | .repeat_inline => { | 1541 | .repeat_inline => { |
| 1525 | // Send comptime control flow back to the beginning of this block. | 1542 | // Send comptime control flow back to the beginning of this block. |
| 1526 | const src = LazySrcLoc.nodeOffset(datas[@intFromEnum(inst)].node); | 1543 | const src = block.nodeOffset(datas[@intFromEnum(inst)].node); |
| 1527 | try sema.emitBackwardBranch(block, src); | 1544 | try sema.emitBackwardBranch(block, src); |
| 1528 | i = 0; | 1545 | i = 0; |
| 1529 | continue; | 1546 | continue; |
| ... | @@ -1667,7 +1684,7 @@ fn analyzeBodyInner( | ... | @@ -1667,7 +1684,7 @@ fn analyzeBodyInner( |
| 1667 | try labeled_block.block.instructions.appendSlice(gpa, block.instructions.items[block_index..]); | 1684 | try labeled_block.block.instructions.appendSlice(gpa, block.instructions.items[block_index..]); |
| 1668 | block.instructions.items.len = block_index; | 1685 | block.instructions.items.len = block_index; |
| 1669 | | 1686 | |
| 1670 | const block_result = try sema.resolveAnalyzedBlock(block, inst_data.src(), &labeled_block.block, &labeled_block.label.merges, need_debug_scope); | 1687 | const block_result = try sema.resolveAnalyzedBlock(block, block.nodeOffset(inst_data.src_node), &labeled_block.block, &labeled_block.label.merges, need_debug_scope); |
| 1671 | { | 1688 | { |
| 1672 | // Destroy the ad-hoc block entry so that it does not interfere with | 1689 | // Destroy the ad-hoc block entry so that it does not interfere with |
| 1673 | // the next iteration of comptime control flow, if any. | 1690 | // the next iteration of comptime control flow, if any. |
| ... | @@ -1693,7 +1710,7 @@ fn analyzeBodyInner( | ... | @@ -1693,7 +1710,7 @@ fn analyzeBodyInner( |
| 1693 | } | 1710 | } |
| 1694 | // Same as condbr_inline. TODO https://github.com/ziglang/zig/issues/8220 | 1711 | // Same as condbr_inline. TODO https://github.com/ziglang/zig/issues/8220 |
| 1695 | const inst_data = datas[@intFromEnum(inst)].pl_node; | 1712 | const inst_data = datas[@intFromEnum(inst)].pl_node; |
| 1696 | const cond_src: LazySrcLoc = .{ .node_offset_if_cond = inst_data.src_node }; | 1713 | const cond_src = block.src(.{ .node_offset_if_cond = inst_data.src_node }); |
| 1697 | const extra = sema.code.extraData(Zir.Inst.CondBr, inst_data.payload_index); | 1714 | const extra = sema.code.extraData(Zir.Inst.CondBr, inst_data.payload_index); |
| 1698 | const then_body = sema.code.bodySlice(extra.end, extra.data.then_body_len); | 1715 | const then_body = sema.code.bodySlice(extra.end, extra.data.then_body_len); |
| 1699 | const else_body = sema.code.bodySlice( | 1716 | const else_body = sema.code.bodySlice( |
| ... | @@ -1713,7 +1730,7 @@ fn analyzeBodyInner( | ... | @@ -1713,7 +1730,7 @@ fn analyzeBodyInner( |
| 1713 | }, | 1730 | }, |
| 1714 | .condbr_inline => blk: { | 1731 | .condbr_inline => blk: { |
| 1715 | const inst_data = datas[@intFromEnum(inst)].pl_node; | 1732 | const inst_data = datas[@intFromEnum(inst)].pl_node; |
| 1716 | const cond_src: LazySrcLoc = .{ .node_offset_if_cond = inst_data.src_node }; | 1733 | const cond_src = block.src(.{ .node_offset_if_cond = inst_data.src_node }); |
| 1717 | const extra = sema.code.extraData(Zir.Inst.CondBr, inst_data.payload_index); | 1734 | const extra = sema.code.extraData(Zir.Inst.CondBr, inst_data.payload_index); |
| 1718 | const then_body = sema.code.bodySlice(extra.end, extra.data.then_body_len); | 1735 | const then_body = sema.code.bodySlice(extra.end, extra.data.then_body_len); |
| 1719 | const else_body = sema.code.bodySlice( | 1736 | const else_body = sema.code.bodySlice( |
| ... | @@ -1736,8 +1753,8 @@ fn analyzeBodyInner( | ... | @@ -1736,8 +1753,8 @@ fn analyzeBodyInner( |
| 1736 | .@"try" => blk: { | 1753 | .@"try" => blk: { |
| 1737 | if (!block.is_comptime) break :blk try sema.zirTry(block, inst); | 1754 | if (!block.is_comptime) break :blk try sema.zirTry(block, inst); |
| 1738 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 1755 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 1739 | const src = inst_data.src(); | 1756 | const src = block.nodeOffset(inst_data.src_node); |
| 1740 | const operand_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node }; | 1757 | const operand_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node }); |
| 1741 | const extra = sema.code.extraData(Zir.Inst.Try, inst_data.payload_index); | 1758 | const extra = sema.code.extraData(Zir.Inst.Try, inst_data.payload_index); |
| 1742 | const inline_body = sema.code.bodySlice(extra.end, extra.data.body_len); | 1759 | const inline_body = sema.code.bodySlice(extra.end, extra.data.body_len); |
| 1743 | const err_union = try sema.resolveInst(extra.data.operand); | 1760 | const err_union = try sema.resolveInst(extra.data.operand); |
| ... | @@ -1762,8 +1779,8 @@ fn analyzeBodyInner( | ... | @@ -1762,8 +1779,8 @@ fn analyzeBodyInner( |
| 1762 | .try_ptr => blk: { | 1779 | .try_ptr => blk: { |
| 1763 | if (!block.is_comptime) break :blk try sema.zirTryPtr(block, inst); | 1780 | if (!block.is_comptime) break :blk try sema.zirTryPtr(block, inst); |
| 1764 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 1781 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 1765 | const src = inst_data.src(); | 1782 | const src = block.nodeOffset(inst_data.src_node); |
| 1766 | const operand_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node }; | 1783 | const operand_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node }); |
| 1767 | const extra = sema.code.extraData(Zir.Inst.Try, inst_data.payload_index); | 1784 | const extra = sema.code.extraData(Zir.Inst.Try, inst_data.payload_index); |
| 1768 | const inline_body = sema.code.bodySlice(extra.end, extra.data.body_len); | 1785 | const inline_body = sema.code.bodySlice(extra.end, extra.data.body_len); |
| 1769 | const operand = try sema.resolveInst(extra.data.operand); | 1786 | const operand = try sema.resolveInst(extra.data.operand); |
| ... | @@ -1927,14 +1944,14 @@ fn resolveDestType( | ... | @@ -1927,14 +1944,14 @@ fn resolveDestType( |
| 1927 | // Cast builtins use their result type as the destination type, but | 1944 | // Cast builtins use their result type as the destination type, but |
| 1928 | // it could be an anytype argument, which we can't catch in AstGen. | 1945 | // it could be an anytype argument, which we can't catch in AstGen. |
| 1929 | const msg = msg: { | 1946 | const msg = msg: { |
| 1930 | const msg = try sema.errMsg(block, src, "{s} must have a known result type", .{builtin_name}); | 1947 | const msg = try sema.errMsg(src, "{s} must have a known result type", .{builtin_name}); |
| 1931 | errdefer msg.destroy(sema.gpa); | 1948 | errdefer msg.destroy(sema.gpa); |
| 1932 | switch (sema.genericPoisonReason(zir_ref)) { | 1949 | switch (sema.genericPoisonReason(block, zir_ref)) { |
| 1933 | .anytype_param => |call_src| try sema.errNote(block, call_src, msg, "result type is unknown due to anytype parameter", .{}), | 1950 | .anytype_param => |call_src| try sema.errNote(call_src, msg, "result type is unknown due to anytype parameter", .{}), |
| 1934 | .anyopaque_ptr => |ptr_src| try sema.errNote(block, ptr_src, msg, "result type is unknown due to opaque pointer type", .{}), | 1951 | .anyopaque_ptr => |ptr_src| try sema.errNote(ptr_src, msg, "result type is unknown due to opaque pointer type", .{}), |
| 1935 | .unknown => {}, | 1952 | .unknown => {}, |
| 1936 | } | 1953 | } |
| 1937 | try sema.errNote(block, src, msg, "use @as to provide explicit result type", .{}); | 1954 | try sema.errNote(src, msg, "use @as to provide explicit result type", .{}); |
| 1938 | break :msg msg; | 1955 | break :msg msg; |
| 1939 | }; | 1956 | }; |
| 1940 | return sema.failWithOwnedErrorMsg(block, msg); | 1957 | return sema.failWithOwnedErrorMsg(block, msg); |
| ... | @@ -1963,7 +1980,7 @@ const GenericPoisonReason = union(enum) { | ... | @@ -1963,7 +1980,7 @@ const GenericPoisonReason = union(enum) { |
| 1963 | | 1980 | |
| 1964 | /// Backtracks through ZIR instructions to determine the reason a generic poison | 1981 | /// Backtracks through ZIR instructions to determine the reason a generic poison |
| 1965 | /// type was created. Used for error reporting. | 1982 | /// type was created. Used for error reporting. |
| 1966 | fn genericPoisonReason(sema: *Sema, ref: Zir.Inst.Ref) GenericPoisonReason { | 1983 | fn genericPoisonReason(sema: *Sema, block: *Block, ref: Zir.Inst.Ref) GenericPoisonReason { |
| 1967 | var cur = ref; | 1984 | var cur = ref; |
| 1968 | while (true) { | 1985 | while (true) { |
| 1969 | const inst = cur.toIndex() orelse return .unknown; | 1986 | const inst = cur.toIndex() orelse return .unknown; |
| ... | @@ -1999,7 +2016,7 @@ fn genericPoisonReason(sema: *Sema, ref: Zir.Inst.Ref) GenericPoisonReason { | ... | @@ -1999,7 +2016,7 @@ fn genericPoisonReason(sema: *Sema, ref: Zir.Inst.Ref) GenericPoisonReason { |
| 1999 | cur = un_node.operand; | 2016 | cur = un_node.operand; |
| 2000 | } else { | 2017 | } else { |
| 2001 | // This must be an anyopaque pointer! | 2018 | // This must be an anyopaque pointer! |
| 2002 | return .{ .anyopaque_ptr = un_node.src() }; | 2019 | return .{ .anyopaque_ptr = block.nodeOffset(un_node.src_node) }; |
| 2003 | } | 2020 | } |
| 2004 | }, | 2021 | }, |
| 2005 | .call, .field_call => { | 2022 | .call, .field_call => { |
| ... | @@ -2007,7 +2024,7 @@ fn genericPoisonReason(sema: *Sema, ref: Zir.Inst.Ref) GenericPoisonReason { | ... | @@ -2007,7 +2024,7 @@ fn genericPoisonReason(sema: *Sema, ref: Zir.Inst.Ref) GenericPoisonReason { |
| 2007 | // evaluating an `anytype` function parameter. | 2024 | // evaluating an `anytype` function parameter. |
| 2008 | // TODO: better source location - function decl rather than call | 2025 | // TODO: better source location - function decl rather than call |
| 2009 | const pl_node = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 2026 | const pl_node = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 2010 | return .{ .anytype_param = pl_node.src() }; | 2027 | return .{ .anytype_param = block.nodeOffset(pl_node.src_node) }; |
| 2011 | }, | 2028 | }, |
| 2012 | else => return .unknown, | 2029 | else => return .unknown, |
| 2013 | } | 2030 | } |
| ... | @@ -2039,7 +2056,7 @@ pub fn setupErrorReturnTrace(sema: *Sema, block: *Block, last_arg_index: usize) | ... | @@ -2039,7 +2056,7 @@ pub fn setupErrorReturnTrace(sema: *Sema, block: *Block, last_arg_index: usize) |
| 2039 | var err_trace_block = block.makeSubBlock(); | 2056 | var err_trace_block = block.makeSubBlock(); |
| 2040 | defer err_trace_block.instructions.deinit(gpa); | 2057 | defer err_trace_block.instructions.deinit(gpa); |
| 2041 | | 2058 | |
| 2042 | const src: LazySrcLoc = .unneeded; | 2059 | const src: LazySrcLoc = LazySrcLoc.unneeded; |
| 2043 | | 2060 | |
| 2044 | // var addrs: [err_return_trace_addr_count]usize = undefined; | 2061 | // var addrs: [err_return_trace_addr_count]usize = undefined; |
| 2045 | const err_return_trace_addr_count = 32; | 2062 | const err_return_trace_addr_count = 32; |
| ... | @@ -2200,9 +2217,9 @@ pub fn resolveFinalDeclValue( | ... | @@ -2200,9 +2217,9 @@ pub fn resolveFinalDeclValue( |
| 2200 | | 2217 | |
| 2201 | fn failWithNeededComptime(sema: *Sema, block: *Block, src: LazySrcLoc, reason: NeededComptimeReason) CompileError { | 2218 | fn failWithNeededComptime(sema: *Sema, block: *Block, src: LazySrcLoc, reason: NeededComptimeReason) CompileError { |
| 2202 | const msg = msg: { | 2219 | const msg = msg: { |
| 2203 | const msg = try sema.errMsg(block, src, "unable to resolve comptime value", .{}); | 2220 | const msg = try sema.errMsg(src, "unable to resolve comptime value", .{}); |
| 2204 | errdefer msg.destroy(sema.gpa); | 2221 | errdefer msg.destroy(sema.gpa); |
| 2205 | try sema.errNote(block, src, msg, "{s}", .{reason.needed_comptime_reason}); | 2222 | try sema.errNote(src, msg, "{s}", .{reason.needed_comptime_reason}); |
| 2206 | | 2223 | |
| 2207 | if (reason.block_comptime_reason) |block_comptime_reason| { | 2224 | if (reason.block_comptime_reason) |block_comptime_reason| { |
| 2208 | try block_comptime_reason.explain(sema, msg); | 2225 | try block_comptime_reason.explain(sema, msg); |
| ... | @@ -2229,12 +2246,12 @@ fn failWithModRemNegative(sema: *Sema, block: *Block, src: LazySrcLoc, lhs_ty: T | ... | @@ -2229,12 +2246,12 @@ fn failWithModRemNegative(sema: *Sema, block: *Block, src: LazySrcLoc, lhs_ty: T |
| 2229 | fn failWithExpectedOptionalType(sema: *Sema, block: *Block, src: LazySrcLoc, non_optional_ty: Type) CompileError { | 2246 | fn failWithExpectedOptionalType(sema: *Sema, block: *Block, src: LazySrcLoc, non_optional_ty: Type) CompileError { |
| 2230 | const mod = sema.mod; | 2247 | const mod = sema.mod; |
| 2231 | const msg = msg: { | 2248 | const msg = msg: { |
| 2232 | const msg = try sema.errMsg(block, src, "expected optional type, found '{}'", .{ | 2249 | const msg = try sema.errMsg(src, "expected optional type, found '{}'", .{ |
| 2233 | non_optional_ty.fmt(mod), | 2250 | non_optional_ty.fmt(mod), |
| 2234 | }); | 2251 | }); |
| 2235 | errdefer msg.destroy(sema.gpa); | 2252 | errdefer msg.destroy(sema.gpa); |
| 2236 | if (non_optional_ty.zigTypeTag(mod) == .ErrorUnion) { | 2253 | if (non_optional_ty.zigTypeTag(mod) == .ErrorUnion) { |
| 2237 | try sema.errNote(block, src, msg, "consider using 'try', 'catch', or 'if'", .{}); | 2254 | try sema.errNote(src, msg, "consider using 'try', 'catch', or 'if'", .{}); |
| 2238 | } | 2255 | } |
| 2239 | try addDeclaredHereNote(sema, msg, non_optional_ty); | 2256 | try addDeclaredHereNote(sema, msg, non_optional_ty); |
| 2240 | break :msg msg; | 2257 | break :msg msg; |
| ... | @@ -2245,12 +2262,12 @@ fn failWithExpectedOptionalType(sema: *Sema, block: *Block, src: LazySrcLoc, non | ... | @@ -2245,12 +2262,12 @@ fn failWithExpectedOptionalType(sema: *Sema, block: *Block, src: LazySrcLoc, non |
| 2245 | fn failWithArrayInitNotSupported(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) CompileError { | 2262 | fn failWithArrayInitNotSupported(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) CompileError { |
| 2246 | const mod = sema.mod; | 2263 | const mod = sema.mod; |
| 2247 | const msg = msg: { | 2264 | const msg = msg: { |
| 2248 | const msg = try sema.errMsg(block, src, "type '{}' does not support array initialization syntax", .{ | 2265 | const msg = try sema.errMsg(src, "type '{}' does not support array initialization syntax", .{ |
| 2249 | ty.fmt(mod), | 2266 | ty.fmt(mod), |
| 2250 | }); | 2267 | }); |
| 2251 | errdefer msg.destroy(sema.gpa); | 2268 | errdefer msg.destroy(sema.gpa); |
| 2252 | if (ty.isSlice(mod)) { | 2269 | if (ty.isSlice(mod)) { |
| 2253 | try sema.errNote(block, src, msg, "inferred array length is specified with an underscore: '[_]{}'", .{ty.elemType2(mod).fmt(mod)}); | 2270 | try sema.errNote(src, msg, "inferred array length is specified with an underscore: '[_]{}'", .{ty.elemType2(mod).fmt(mod)}); |
| 2254 | } | 2271 | } |
| 2255 | break :msg msg; | 2272 | break :msg msg; |
| 2256 | }; | 2273 | }; |
| ... | @@ -2279,11 +2296,11 @@ fn failWithIntegerOverflow(sema: *Sema, block: *Block, src: LazySrcLoc, int_ty: | ... | @@ -2279,11 +2296,11 @@ fn failWithIntegerOverflow(sema: *Sema, block: *Block, src: LazySrcLoc, int_ty: |
| 2279 | const zcu = sema.mod; | 2296 | const zcu = sema.mod; |
| 2280 | if (int_ty.zigTypeTag(zcu) == .Vector) { | 2297 | if (int_ty.zigTypeTag(zcu) == .Vector) { |
| 2281 | const msg = msg: { | 2298 | const msg = msg: { |
| 2282 | const msg = try sema.errMsg(block, src, "overflow of vector type '{}' with value '{}'", .{ | 2299 | const msg = try sema.errMsg(src, "overflow of vector type '{}' with value '{}'", .{ |
| 2283 | int_ty.fmt(zcu), val.fmtValue(zcu, sema), | 2300 | int_ty.fmt(zcu), val.fmtValue(zcu, sema), |
| 2284 | }); | 2301 | }); |
| 2285 | errdefer msg.destroy(sema.gpa); | 2302 | errdefer msg.destroy(sema.gpa); |
| 2286 | try sema.errNote(block, src, msg, "when computing vector element at index '{d}'", .{vector_index}); | 2303 | try sema.errNote(src, msg, "when computing vector element at index '{d}'", .{vector_index}); |
| 2287 | break :msg msg; | 2304 | break :msg msg; |
| 2288 | }; | 2305 | }; |
| 2289 | return sema.failWithOwnedErrorMsg(block, msg); | 2306 | return sema.failWithOwnedErrorMsg(block, msg); |
| ... | @@ -2296,15 +2313,14 @@ fn failWithIntegerOverflow(sema: *Sema, block: *Block, src: LazySrcLoc, int_ty: | ... | @@ -2296,15 +2313,14 @@ fn failWithIntegerOverflow(sema: *Sema, block: *Block, src: LazySrcLoc, int_ty: |
| 2296 | fn failWithInvalidComptimeFieldStore(sema: *Sema, block: *Block, init_src: LazySrcLoc, container_ty: Type, field_index: usize) CompileError { | 2313 | fn failWithInvalidComptimeFieldStore(sema: *Sema, block: *Block, init_src: LazySrcLoc, container_ty: Type, field_index: usize) CompileError { |
| 2297 | const mod = sema.mod; | 2314 | const mod = sema.mod; |
| 2298 | const msg = msg: { | 2315 | const msg = msg: { |
| 2299 | const msg = try sema.errMsg(block, init_src, "value stored in comptime field does not match the default value of the field", .{}); | 2316 | const msg = try sema.errMsg(init_src, "value stored in comptime field does not match the default value of the field", .{}); |
| 2300 | errdefer msg.destroy(sema.gpa); | 2317 | errdefer msg.destroy(sema.gpa); |
| 2301 | | 2318 | |
| 2302 | const struct_type = mod.typeToStruct(container_ty) orelse break :msg msg; | 2319 | const struct_type = mod.typeToStruct(container_ty) orelse break :msg msg; |
| 2303 | const default_value_src = mod.fieldSrcLoc(struct_type.decl.unwrap().?, .{ | 2320 | try sema.errNote(.{ |
| 2304 | .index = field_index, | 2321 | .base_node_inst = struct_type.zir_index.unwrap().?, |
| 2305 | .range = .value, | 2322 | .offset = .{ .container_field_value = @intCast(field_index) }, |
| 2306 | }); | 2323 | }, msg, "default value set here", .{}); |
| 2307 | try mod.errNoteNonLazy(default_value_src, msg, "default value set here", .{}); | | |
| 2308 | break :msg msg; | 2324 | break :msg msg; |
| 2309 | }; | 2325 | }; |
| 2310 | return sema.failWithOwnedErrorMsg(block, msg); | 2326 | return sema.failWithOwnedErrorMsg(block, msg); |
| ... | @@ -2312,7 +2328,7 @@ fn failWithInvalidComptimeFieldStore(sema: *Sema, block: *Block, init_src: LazyS | ... | @@ -2312,7 +2328,7 @@ fn failWithInvalidComptimeFieldStore(sema: *Sema, block: *Block, init_src: LazyS |
| 2312 | | 2328 | |
| 2313 | fn failWithUseOfAsync(sema: *Sema, block: *Block, src: LazySrcLoc) CompileError { | 2329 | fn failWithUseOfAsync(sema: *Sema, block: *Block, src: LazySrcLoc) CompileError { |
| 2314 | const msg = msg: { | 2330 | const msg = msg: { |
| 2315 | const msg = try sema.errMsg(block, src, "async has not been implemented in the self-hosted compiler yet", .{}); | 2331 | const msg = try sema.errMsg(src, "async has not been implemented in the self-hosted compiler yet", .{}); |
| 2316 | errdefer msg.destroy(sema.gpa); | 2332 | errdefer msg.destroy(sema.gpa); |
| 2317 | break :msg msg; | 2333 | break :msg msg; |
| 2318 | }; | 2334 | }; |
| ... | @@ -2333,9 +2349,9 @@ fn failWithInvalidFieldAccess( | ... | @@ -2333,9 +2349,9 @@ fn failWithInvalidFieldAccess( |
| 2333 | const child_ty = inner_ty.optionalChild(mod); | 2349 | const child_ty = inner_ty.optionalChild(mod); |
| 2334 | if (!typeSupportsFieldAccess(mod, child_ty, field_name)) break :opt; | 2350 | if (!typeSupportsFieldAccess(mod, child_ty, field_name)) break :opt; |
| 2335 | const msg = msg: { | 2351 | const msg = msg: { |
| 2336 | const msg = try sema.errMsg(block, src, "optional type '{}' does not support field access", .{object_ty.fmt(sema.mod)}); | 2352 | const msg = try sema.errMsg(src, "optional type '{}' does not support field access", .{object_ty.fmt(sema.mod)}); |
| 2337 | errdefer msg.destroy(sema.gpa); | 2353 | errdefer msg.destroy(sema.gpa); |
| 2338 | try sema.errNote(block, src, msg, "consider using '.?', 'orelse', or 'if'", .{}); | 2354 | try sema.errNote(src, msg, "consider using '.?', 'orelse', or 'if'", .{}); |
| 2339 | break :msg msg; | 2355 | break :msg msg; |
| 2340 | }; | 2356 | }; |
| 2341 | return sema.failWithOwnedErrorMsg(block, msg); | 2357 | return sema.failWithOwnedErrorMsg(block, msg); |
| ... | @@ -2343,9 +2359,9 @@ fn failWithInvalidFieldAccess( | ... | @@ -2343,9 +2359,9 @@ fn failWithInvalidFieldAccess( |
| 2343 | const child_ty = inner_ty.errorUnionPayload(mod); | 2359 | const child_ty = inner_ty.errorUnionPayload(mod); |
| 2344 | if (!typeSupportsFieldAccess(mod, child_ty, field_name)) break :err; | 2360 | if (!typeSupportsFieldAccess(mod, child_ty, field_name)) break :err; |
| 2345 | const msg = msg: { | 2361 | const msg = msg: { |
| 2346 | const msg = try sema.errMsg(block, src, "error union type '{}' does not support field access", .{object_ty.fmt(sema.mod)}); | 2362 | const msg = try sema.errMsg(src, "error union type '{}' does not support field access", .{object_ty.fmt(sema.mod)}); |
| 2347 | errdefer msg.destroy(sema.gpa); | 2363 | errdefer msg.destroy(sema.gpa); |
| 2348 | try sema.errNote(block, src, msg, "consider using 'try', 'catch', or 'if'", .{}); | 2364 | try sema.errNote(src, msg, "consider using 'try', 'catch', or 'if'", .{}); |
| 2349 | break :msg msg; | 2365 | break :msg msg; |
| 2350 | }; | 2366 | }; |
| 2351 | return sema.failWithOwnedErrorMsg(block, msg); | 2367 | return sema.failWithOwnedErrorMsg(block, msg); |
| ... | @@ -2378,11 +2394,11 @@ fn failWithComptimeErrorRetTrace( | ... | @@ -2378,11 +2394,11 @@ fn failWithComptimeErrorRetTrace( |
| 2378 | ) CompileError { | 2394 | ) CompileError { |
| 2379 | const mod = sema.mod; | 2395 | const mod = sema.mod; |
| 2380 | const msg = msg: { | 2396 | const msg = msg: { |
| 2381 | const msg = try sema.errMsg(block, src, "caught unexpected error '{}'", .{name.fmt(&mod.intern_pool)}); | 2397 | const msg = try sema.errMsg(src, "caught unexpected error '{}'", .{name.fmt(&mod.intern_pool)}); |
| 2382 | errdefer msg.destroy(sema.gpa); | 2398 | errdefer msg.destroy(sema.gpa); |
| 2383 | | 2399 | |
| 2384 | for (sema.comptime_err_ret_trace.items) |src_loc| { | 2400 | for (sema.comptime_err_ret_trace.items) |src_loc| { |
| 2385 | try mod.errNoteNonLazy(src_loc, msg, "error returned here", .{}); | 2401 | try sema.errNote(src_loc, msg, "error returned here", .{}); |
| 2386 | } | 2402 | } |
| 2387 | break :msg msg; | 2403 | break :msg msg; |
| 2388 | }; | 2404 | }; |
| ... | @@ -2391,17 +2407,15 @@ fn failWithComptimeErrorRetTrace( | ... | @@ -2391,17 +2407,15 @@ fn failWithComptimeErrorRetTrace( |
| 2391 | | 2407 | |
| 2392 | /// We don't return a pointer to the new error note because the pointer | 2408 | /// We don't return a pointer to the new error note because the pointer |
| 2393 | /// becomes invalid when you add another one. | 2409 | /// becomes invalid when you add another one. |
| 2394 | fn errNote( | 2410 | pub fn errNote( |
| 2395 | sema: *Sema, | 2411 | sema: *Sema, |
| 2396 | block: *Block, | | |
| 2397 | src: LazySrcLoc, | 2412 | src: LazySrcLoc, |
| 2398 | parent: *Module.ErrorMsg, | 2413 | parent: *Module.ErrorMsg, |
| 2399 | comptime format: []const u8, | 2414 | comptime format: []const u8, |
| 2400 | args: anytype, | 2415 | args: anytype, |
| 2401 | ) error{OutOfMemory}!void { | 2416 | ) error{OutOfMemory}!void { |
| 2402 | const mod = sema.mod; | 2417 | const zcu = sema.mod; |
| 2403 | const src_decl = mod.declPtr(block.src_decl); | 2418 | return zcu.errNoteNonLazy(src.upgrade(zcu), parent, format, args); |
| 2404 | return mod.errNoteNonLazy(src_decl.toSrcLoc(src, mod), parent, format, args); | | |
| 2405 | } | 2419 | } |
| 2406 | | 2420 | |
| 2407 | fn addFieldErrNote( | 2421 | fn addFieldErrNote( |
| ... | @@ -2413,52 +2427,23 @@ fn addFieldErrNote( | ... | @@ -2413,52 +2427,23 @@ fn addFieldErrNote( |
| 2413 | args: anytype, | 2427 | args: anytype, |
| 2414 | ) !void { | 2428 | ) !void { |
| 2415 | @setCold(true); | 2429 | @setCold(true); |
| 2416 | const mod = sema.mod; | 2430 | const zcu = sema.mod; |
| 2417 | const decl_index = container_ty.getOwnerDecl(mod); | 2431 | const type_src = container_ty.srcLocOrNull(zcu) orelse return; |
| 2418 | const decl = mod.declPtr(decl_index); | 2432 | const field_src: LazySrcLoc = .{ |
| 2419 | | 2433 | .base_node_inst = type_src.base_node_inst, |
| 2420 | const field_src = blk: { | 2434 | .offset = .{ .container_field_name = @intCast(field_index) }, |
| 2421 | const tree = decl.getFileScope(mod).getTree(sema.gpa) catch |err| { | | |
| 2422 | log.err("unable to load AST to report compile error: {s}", .{@errorName(err)}); | | |
| 2423 | break :blk decl.srcLoc(mod); | | |
| 2424 | }; | | |
| 2425 | | | |
| 2426 | const container_node = decl.relativeToNodeIndex(0); | | |
| 2427 | const node_tags = tree.nodes.items(.tag); | | |
| 2428 | var buf: [2]std.zig.Ast.Node.Index = undefined; | | |
| 2429 | const container_decl = tree.fullContainerDecl(&buf, container_node) orelse break :blk decl.srcLoc(mod); | | |
| 2430 | | | |
| 2431 | var it_index: usize = 0; | | |
| 2432 | for (container_decl.ast.members) |member_node| { | | |
| 2433 | switch (node_tags[member_node]) { | | |
| 2434 | .container_field_init, | | |
| 2435 | .container_field_align, | | |
| 2436 | .container_field, | | |
| 2437 | => { | | |
| 2438 | if (it_index == field_index) { | | |
| 2439 | break :blk decl.nodeOffsetSrcLoc(decl.nodeIndexToRelative(member_node), mod); | | |
| 2440 | } | | |
| 2441 | it_index += 1; | | |
| 2442 | }, | | |
| 2443 | else => continue, | | |
| 2444 | } | | |
| 2445 | } | | |
| 2446 | unreachable; | | |
| 2447 | }; | 2435 | }; |
| 2448 | try mod.errNoteNonLazy(field_src, parent, format, args); | 2436 | try sema.errNote(field_src, parent, format, args); |
| 2449 | } | 2437 | } |
| 2450 | | 2438 | |
| 2451 | pub fn errMsg( | 2439 | pub fn errMsg( |
| 2452 | sema: *Sema, | 2440 | sema: *Sema, |
| 2453 | block: *Block, | | |
| 2454 | src: LazySrcLoc, | 2441 | src: LazySrcLoc, |
| 2455 | comptime format: []const u8, | 2442 | comptime format: []const u8, |
| 2456 | args: anytype, | 2443 | args: anytype, |
| 2457 | ) error{ NeededSourceLocation, OutOfMemory }!*Module.ErrorMsg { | 2444 | ) Allocator.Error!*Module.ErrorMsg { |
| 2458 | const mod = sema.mod; | 2445 | assert(src.offset != .unneeded); |
| 2459 | if (src == .unneeded) return error.NeededSourceLocation; | 2446 | return Module.ErrorMsg.create(sema.gpa, src.upgrade(sema.mod), format, args); |
| 2460 | const src_decl = mod.declPtr(block.src_decl); | | |
| 2461 | return Module.ErrorMsg.create(sema.gpa, src_decl.toSrcLoc(src, mod), format, args); | | |
| 2462 | } | 2447 | } |
| 2463 | | 2448 | |
| 2464 | pub fn fail( | 2449 | pub fn fail( |
| ... | @@ -2468,7 +2453,7 @@ pub fn fail( | ... | @@ -2468,7 +2453,7 @@ pub fn fail( |
| 2468 | comptime format: []const u8, | 2453 | comptime format: []const u8, |
| 2469 | args: anytype, | 2454 | args: anytype, |
| 2470 | ) CompileError { | 2455 | ) CompileError { |
| 2471 | const err_msg = try sema.errMsg(block, src, format, args); | 2456 | const err_msg = try sema.errMsg(src, format, args); |
| 2472 | inline for (args) |arg| { | 2457 | inline for (args) |arg| { |
| 2473 | if (@TypeOf(arg) == Type.Formatter) { | 2458 | if (@TypeOf(arg) == Type.Formatter) { |
| 2474 | try addDeclaredHereNote(sema, err_msg, arg.data.ty); | 2459 | try addDeclaredHereNote(sema, err_msg, arg.data.ty); |
| ... | @@ -2502,7 +2487,6 @@ pub fn failWithOwnedErrorMsg(sema: *Sema, block: ?*Block, err_msg: *Module.Error | ... | @@ -2502,7 +2487,6 @@ pub fn failWithOwnedErrorMsg(sema: *Sema, block: ?*Block, err_msg: *Module.Error |
| 2502 | var block_it = start_block; | 2487 | var block_it = start_block; |
| 2503 | while (block_it.inlining) |inlining| { | 2488 | while (block_it.inlining) |inlining| { |
| 2504 | try sema.errNote( | 2489 | try sema.errNote( |
| 2505 | inlining.call_block, | | |
| 2506 | inlining.call_src, | 2490 | inlining.call_src, |
| 2507 | err_msg, | 2491 | err_msg, |
| 2508 | "called from here", | 2492 | "called from here", |
| ... | @@ -2536,7 +2520,7 @@ pub fn failWithOwnedErrorMsg(sema: *Sema, block: ?*Block, err_msg: *Module.Error | ... | @@ -2536,7 +2520,7 @@ pub fn failWithOwnedErrorMsg(sema: *Sema, block: ?*Block, err_msg: *Module.Error |
| 2536 | const decl = mod.declPtr(ref.referencer); | 2520 | const decl = mod.declPtr(ref.referencer); |
| 2537 | try reference_stack.append(.{ | 2521 | try reference_stack.append(.{ |
| 2538 | .decl = decl.name, | 2522 | .decl = decl.name, |
| 2539 | .src_loc = decl.toSrcLoc(ref.src, mod), | 2523 | .src_loc = ref.src.upgrade(mod), |
| 2540 | }); | 2524 | }); |
| 2541 | } | 2525 | } |
| 2542 | referenced_by = ref.referencer; | 2526 | referenced_by = ref.referencer; |
| ... | @@ -2571,15 +2555,13 @@ pub fn failWithOwnedErrorMsg(sema: *Sema, block: ?*Block, err_msg: *Module.Error | ... | @@ -2571,15 +2555,13 @@ pub fn failWithOwnedErrorMsg(sema: *Sema, block: ?*Block, err_msg: *Module.Error |
| 2571 | /// Reference trace is preserved. | 2555 | /// Reference trace is preserved. |
| 2572 | fn reparentOwnedErrorMsg( | 2556 | fn reparentOwnedErrorMsg( |
| 2573 | sema: *Sema, | 2557 | sema: *Sema, |
| 2574 | block: *Block, | | |
| 2575 | src: LazySrcLoc, | 2558 | src: LazySrcLoc, |
| 2576 | msg: *Module.ErrorMsg, | 2559 | msg: *Module.ErrorMsg, |
| 2577 | comptime format: []const u8, | 2560 | comptime format: []const u8, |
| 2578 | args: anytype, | 2561 | args: anytype, |
| 2579 | ) !void { | 2562 | ) !void { |
| 2580 | const mod = sema.mod; | 2563 | const mod = sema.mod; |
| 2581 | const src_decl = mod.declPtr(block.src_decl); | 2564 | const resolved_src = src.upgrade(mod); |
| 2582 | const resolved_src = src_decl.toSrcLoc(src, mod); | | |
| 2583 | const msg_str = try std.fmt.allocPrint(mod.gpa, format, args); | 2565 | const msg_str = try std.fmt.allocPrint(mod.gpa, format, args); |
| 2584 | | 2566 | |
| 2585 | const orig_notes = msg.notes.len; | 2567 | const orig_notes = msg.notes.len; |
| ... | @@ -2716,7 +2698,7 @@ fn getCaptures(sema: *Sema, block: *Block, type_src: LazySrcLoc, extra_index: us | ... | @@ -2716,7 +2698,7 @@ fn getCaptures(sema: *Sema, block: *Block, type_src: LazySrcLoc, extra_index: us |
| 2716 | sema.code.nullTerminatedString(str), | 2698 | sema.code.nullTerminatedString(str), |
| 2717 | .no_embedded_nulls, | 2699 | .no_embedded_nulls, |
| 2718 | ); | 2700 | ); |
| 2719 | const decl = try sema.lookupIdentifier(block, .unneeded, decl_name); // TODO: could we need this src loc? | 2701 | const decl = try sema.lookupIdentifier(block, LazySrcLoc.unneeded, decl_name); // TODO: could we need this src loc? |
| 2720 | break :capture InternPool.CaptureValue.wrap(.{ .decl_val = decl }); | 2702 | break :capture InternPool.CaptureValue.wrap(.{ .decl_val = decl }); |
| 2721 | }, | 2703 | }, |
| 2722 | .decl_ref => |str| capture: { | 2704 | .decl_ref => |str| capture: { |
| ... | @@ -2725,7 +2707,7 @@ fn getCaptures(sema: *Sema, block: *Block, type_src: LazySrcLoc, extra_index: us | ... | @@ -2725,7 +2707,7 @@ fn getCaptures(sema: *Sema, block: *Block, type_src: LazySrcLoc, extra_index: us |
| 2725 | sema.code.nullTerminatedString(str), | 2707 | sema.code.nullTerminatedString(str), |
| 2726 | .no_embedded_nulls, | 2708 | .no_embedded_nulls, |
| 2727 | ); | 2709 | ); |
| 2728 | const decl = try sema.lookupIdentifier(block, .unneeded, decl_name); // TODO: could we need this src loc? | 2710 | const decl = try sema.lookupIdentifier(block, LazySrcLoc.unneeded, decl_name); // TODO: could we need this src loc? |
| 2729 | break :capture InternPool.CaptureValue.wrap(.{ .decl_ref = decl }); | 2711 | break :capture InternPool.CaptureValue.wrap(.{ .decl_ref = decl }); |
| 2730 | }, | 2712 | }, |
| 2731 | }; | 2713 | }; |
| ... | @@ -2776,7 +2758,13 @@ fn zirStructDecl( | ... | @@ -2776,7 +2758,13 @@ fn zirStructDecl( |
| 2776 | const ip = &mod.intern_pool; | 2758 | const ip = &mod.intern_pool; |
| 2777 | const small: Zir.Inst.StructDecl.Small = @bitCast(extended.small); | 2759 | const small: Zir.Inst.StructDecl.Small = @bitCast(extended.small); |
| 2778 | const extra = sema.code.extraData(Zir.Inst.StructDecl, extended.operand); | 2760 | const extra = sema.code.extraData(Zir.Inst.StructDecl, extended.operand); |
| 2779 | const src = extra.data.src(); | 2761 | |
| | 2762 | const tracked_inst = try ip.trackZir(gpa, block.getFileScope(mod), inst); |
| | 2763 | const src: LazySrcLoc = .{ |
| | 2764 | .base_node_inst = tracked_inst, |
| | 2765 | .offset = LazySrcLoc.Offset.nodeOffset(0), |
| | 2766 | }; |
| | 2767 | |
| 2780 | var extra_index = extra.end; | 2768 | var extra_index = extra.end; |
| 2781 | | 2769 | |
| 2782 | const captures_len = if (small.has_captures_len) blk: { | 2770 | const captures_len = if (small.has_captures_len) blk: { |
| ... | @@ -2820,7 +2808,7 @@ fn zirStructDecl( | ... | @@ -2820,7 +2808,7 @@ fn zirStructDecl( |
| 2820 | .any_aligned_fields = small.any_aligned_fields, | 2808 | .any_aligned_fields = small.any_aligned_fields, |
| 2821 | .has_namespace = true or decls_len > 0, // TODO: see below | 2809 | .has_namespace = true or decls_len > 0, // TODO: see below |
| 2822 | .key = .{ .declared = .{ | 2810 | .key = .{ .declared = .{ |
| 2823 | .zir_index = try ip.trackZir(gpa, block.getFileScope(mod), inst), | 2811 | .zir_index = tracked_inst, |
| 2824 | .captures = captures, | 2812 | .captures = captures, |
| 2825 | } }, | 2813 | } }, |
| 2826 | }; | 2814 | }; |
| ... | @@ -2835,11 +2823,11 @@ fn zirStructDecl( | ... | @@ -2835,11 +2823,11 @@ fn zirStructDecl( |
| 2835 | | 2823 | |
| 2836 | const new_decl_index = try sema.createAnonymousDeclTypeNamed( | 2824 | const new_decl_index = try sema.createAnonymousDeclTypeNamed( |
| 2837 | block, | 2825 | block, |
| 2838 | src, | | |
| 2839 | Value.fromInterned(wip_ty.index), | 2826 | Value.fromInterned(wip_ty.index), |
| 2840 | small.name_strategy, | 2827 | small.name_strategy, |
| 2841 | "struct", | 2828 | "struct", |
| 2842 | inst, | 2829 | inst, |
| | 2830 | extra.data.src_line, |
| 2843 | ); | 2831 | ); |
| 2844 | mod.declPtr(new_decl_index).owns_tv = true; | 2832 | mod.declPtr(new_decl_index).owns_tv = true; |
| 2845 | errdefer mod.abortAnonDecl(new_decl_index); | 2833 | errdefer mod.abortAnonDecl(new_decl_index); |
| ... | @@ -2872,42 +2860,26 @@ fn zirStructDecl( | ... | @@ -2872,42 +2860,26 @@ fn zirStructDecl( |
| 2872 | fn createAnonymousDeclTypeNamed( | 2860 | fn createAnonymousDeclTypeNamed( |
| 2873 | sema: *Sema, | 2861 | sema: *Sema, |
| 2874 | block: *Block, | 2862 | block: *Block, |
| 2875 | src: LazySrcLoc, | | |
| 2876 | val: Value, | 2863 | val: Value, |
| 2877 | name_strategy: Zir.Inst.NameStrategy, | 2864 | name_strategy: Zir.Inst.NameStrategy, |
| 2878 | anon_prefix: []const u8, | 2865 | anon_prefix: []const u8, |
| 2879 | inst: ?Zir.Inst.Index, | 2866 | inst: ?Zir.Inst.Index, |
| | 2867 | src_line: u32, |
| 2880 | ) !InternPool.DeclIndex { | 2868 | ) !InternPool.DeclIndex { |
| 2881 | const zcu = sema.mod; | 2869 | const zcu = sema.mod; |
| 2882 | const ip = &zcu.intern_pool; | 2870 | const ip = &zcu.intern_pool; |
| 2883 | const gpa = sema.gpa; | 2871 | const gpa = sema.gpa; |
| 2884 | const namespace = block.namespace; | 2872 | const namespace = block.namespace; |
| 2885 | const src_decl = zcu.declPtr(block.src_decl); | 2873 | const new_decl_index = try zcu.allocateNewDecl(namespace); |
| 2886 | const src_node = src_decl.relativeToNodeIndex(src.node_offset.x); | | |
| 2887 | const new_decl_index = try zcu.allocateNewDecl(namespace, src_node); | | |
| 2888 | errdefer zcu.destroyDecl(new_decl_index); | 2874 | errdefer zcu.destroyDecl(new_decl_index); |
| 2889 | | 2875 | |
| 2890 | switch (name_strategy) { | 2876 | switch (name_strategy) { |
| 2891 | .anon => { | 2877 | .anon => {}, // handled after switch |
| 2892 | // It would be neat to have "struct:line:column" but this name has | | |
| 2893 | // to survive incremental updates, where it may have been shifted down | | |
| 2894 | // or up to a different line, but unchanged, and thus not unnecessarily | | |
| 2895 | // semantically analyzed. | | |
| 2896 | // This name is also used as the key in the parent namespace so it cannot be | | |
| 2897 | // renamed. | | |
| 2898 | | | |
| 2899 | const name = ip.getOrPutStringFmt(gpa, "{}__{s}_{d}", .{ | | |
| 2900 | src_decl.name.fmt(ip), anon_prefix, @intFromEnum(new_decl_index), | | |
| 2901 | }, .no_embedded_nulls) catch unreachable; | | |
| 2902 | try zcu.initNewAnonDecl(new_decl_index, src_decl.src_line, val, name); | | |
| 2903 | return new_decl_index; | | |
| 2904 | }, | | |
| 2905 | .parent => { | 2878 | .parent => { |
| 2906 | const name = zcu.declPtr(block.src_decl).name; | 2879 | try zcu.initNewAnonDecl(new_decl_index, src_line, val, block.type_name_ctx); |
| 2907 | try zcu.initNewAnonDecl(new_decl_index, src_decl.src_line, val, name); | | |
| 2908 | return new_decl_index; | 2880 | return new_decl_index; |
| 2909 | }, | 2881 | }, |
| 2910 | .func => { | 2882 | .func => func_strat: { |
| 2911 | const fn_info = sema.code.getFnInfo(ip.funcZirBodyInst(sema.func_index).resolve(ip)); | 2883 | const fn_info = sema.code.getFnInfo(ip.funcZirBodyInst(sema.func_index).resolve(ip)); |
| 2912 | const zir_tags = sema.code.instructions.items(.tag); | 2884 | const zir_tags = sema.code.instructions.items(.tag); |
| 2913 | | 2885 | |
| ... | @@ -2915,7 +2887,7 @@ fn createAnonymousDeclTypeNamed( | ... | @@ -2915,7 +2887,7 @@ fn createAnonymousDeclTypeNamed( |
| 2915 | defer buf.deinit(); | 2887 | defer buf.deinit(); |
| 2916 | | 2888 | |
| 2917 | const writer = buf.writer(); | 2889 | const writer = buf.writer(); |
| 2918 | try writer.print("{}(", .{zcu.declPtr(block.src_decl).name.fmt(ip)}); | 2890 | try writer.print("{}(", .{block.type_name_ctx.fmt(ip)}); |
| 2919 | | 2891 | |
| 2920 | var arg_i: usize = 0; | 2892 | var arg_i: usize = 0; |
| 2921 | for (fn_info.param_body) |zir_inst| switch (zir_tags[@intFromEnum(zir_inst)]) { | 2893 | for (fn_info.param_body) |zir_inst| switch (zir_tags[@intFromEnum(zir_inst)]) { |
| ... | @@ -2926,8 +2898,7 @@ fn createAnonymousDeclTypeNamed( | ... | @@ -2926,8 +2898,7 @@ fn createAnonymousDeclTypeNamed( |
| 2926 | // If not then this is a struct type being returned from a non-generic | 2898 | // If not then this is a struct type being returned from a non-generic |
| 2927 | // function and the name doesn't matter since it will later | 2899 | // function and the name doesn't matter since it will later |
| 2928 | // result in a compile error. | 2900 | // result in a compile error. |
| 2929 | const arg_val = sema.resolveConstValue(block, .unneeded, arg, undefined) catch | 2901 | const arg_val = try sema.resolveValue(arg) orelse break :func_strat; // fall through to anon strat |
| 2930 | return sema.createAnonymousDeclTypeNamed(block, src, val, .anon, anon_prefix, null); | | |
| 2931 | | 2902 | |
| 2932 | if (arg_i != 0) try writer.writeByte(','); | 2903 | if (arg_i != 0) try writer.writeByte(','); |
| 2933 | | 2904 | |
| ... | @@ -2950,7 +2921,7 @@ fn createAnonymousDeclTypeNamed( | ... | @@ -2950,7 +2921,7 @@ fn createAnonymousDeclTypeNamed( |
| 2950 | | 2921 | |
| 2951 | try writer.writeByte(')'); | 2922 | try writer.writeByte(')'); |
| 2952 | const name = try ip.getOrPutString(gpa, buf.items, .no_embedded_nulls); | 2923 | const name = try ip.getOrPutString(gpa, buf.items, .no_embedded_nulls); |
| 2953 | try zcu.initNewAnonDecl(new_decl_index, src_decl.src_line, val, name); | 2924 | try zcu.initNewAnonDecl(new_decl_index, src_line, val, name); |
| 2954 | return new_decl_index; | 2925 | return new_decl_index; |
| 2955 | }, | 2926 | }, |
| 2956 | .dbg_var => { | 2927 | .dbg_var => { |
| ... | @@ -2962,16 +2933,31 @@ fn createAnonymousDeclTypeNamed( | ... | @@ -2962,16 +2933,31 @@ fn createAnonymousDeclTypeNamed( |
| 2962 | if (zir_data[i].str_op.operand != ref) continue; | 2933 | if (zir_data[i].str_op.operand != ref) continue; |
| 2963 | | 2934 | |
| 2964 | const name = try ip.getOrPutStringFmt(gpa, "{}.{s}", .{ | 2935 | const name = try ip.getOrPutStringFmt(gpa, "{}.{s}", .{ |
| 2965 | src_decl.name.fmt(ip), zir_data[i].str_op.getStr(sema.code), | 2936 | block.type_name_ctx.fmt(ip), zir_data[i].str_op.getStr(sema.code), |
| 2966 | }, .no_embedded_nulls); | 2937 | }, .no_embedded_nulls); |
| 2967 | try zcu.initNewAnonDecl(new_decl_index, src_decl.src_line, val, name); | 2938 | try zcu.initNewAnonDecl(new_decl_index, src_line, val, name); |
| 2968 | return new_decl_index; | 2939 | return new_decl_index; |
| 2969 | }, | 2940 | }, |
| 2970 | else => {}, | 2941 | else => {}, |
| 2971 | }; | 2942 | }; |
| 2972 | return sema.createAnonymousDeclTypeNamed(block, src, val, .anon, anon_prefix, null); | 2943 | // fall through to anon strat |
| 2973 | }, | 2944 | }, |
| 2974 | } | 2945 | } |
| | 2946 | |
| | 2947 | // anon strat handling. |
| | 2948 | |
| | 2949 | // It would be neat to have "struct:line:column" but this name has |
| | 2950 | // to survive incremental updates, where it may have been shifted down |
| | 2951 | // or up to a different line, but unchanged, and thus not unnecessarily |
| | 2952 | // semantically analyzed. |
| | 2953 | // This name is also used as the key in the parent namespace so it cannot be |
| | 2954 | // renamed. |
| | 2955 | |
| | 2956 | const name = ip.getOrPutStringFmt(gpa, "{}__{s}_{d}", .{ |
| | 2957 | block.type_name_ctx.fmt(ip), anon_prefix, @intFromEnum(new_decl_index), |
| | 2958 | }, .no_embedded_nulls) catch unreachable; |
| | 2959 | try zcu.initNewAnonDecl(new_decl_index, src_line, val, name); |
| | 2960 | return new_decl_index; |
| 2975 | } | 2961 | } |
| 2976 | | 2962 | |
| 2977 | fn zirEnumDecl( | 2963 | fn zirEnumDecl( |
| ... | @@ -2990,8 +2976,9 @@ fn zirEnumDecl( | ... | @@ -2990,8 +2976,9 @@ fn zirEnumDecl( |
| 2990 | const extra = sema.code.extraData(Zir.Inst.EnumDecl, extended.operand); | 2976 | const extra = sema.code.extraData(Zir.Inst.EnumDecl, extended.operand); |
| 2991 | var extra_index: usize = extra.end; | 2977 | var extra_index: usize = extra.end; |
| 2992 | | 2978 | |
| 2993 | const src = extra.data.src(); | 2979 | const tracked_inst = try ip.trackZir(gpa, block.getFileScope(mod), inst); |
| 2994 | const tag_ty_src: LazySrcLoc = .{ .node_offset_container_tag = src.node_offset.x }; | 2980 | const src: LazySrcLoc = .{ .base_node_inst = tracked_inst, .offset = LazySrcLoc.Offset.nodeOffset(0) }; |
| | 2981 | const tag_ty_src: LazySrcLoc = .{ .base_node_inst = tracked_inst, .offset = .{ .node_offset_container_tag = 0 } }; |
| 2995 | | 2982 | |
| 2996 | const tag_type_ref = if (small.has_tag_type) blk: { | 2983 | const tag_type_ref = if (small.has_tag_type) blk: { |
| 2997 | const tag_type_ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_index]); | 2984 | const tag_type_ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_index]); |
| ... | @@ -3051,7 +3038,7 @@ fn zirEnumDecl( | ... | @@ -3051,7 +3038,7 @@ fn zirEnumDecl( |
| 3051 | .explicit, | 3038 | .explicit, |
| 3052 | .fields_len = fields_len, | 3039 | .fields_len = fields_len, |
| 3053 | .key = .{ .declared = .{ | 3040 | .key = .{ .declared = .{ |
| 3054 | .zir_index = try mod.intern_pool.trackZir(sema.gpa, block.getFileScope(mod), inst), | 3041 | .zir_index = tracked_inst, |
| 3055 | .captures = captures, | 3042 | .captures = captures, |
| 3056 | } }, | 3043 | } }, |
| 3057 | }; | 3044 | }; |
| ... | @@ -3071,11 +3058,11 @@ fn zirEnumDecl( | ... | @@ -3071,11 +3058,11 @@ fn zirEnumDecl( |
| 3071 | | 3058 | |
| 3072 | const new_decl_index = try sema.createAnonymousDeclTypeNamed( | 3059 | const new_decl_index = try sema.createAnonymousDeclTypeNamed( |
| 3073 | block, | 3060 | block, |
| 3074 | src, | | |
| 3075 | Value.fromInterned(wip_ty.index), | 3061 | Value.fromInterned(wip_ty.index), |
| 3076 | small.name_strategy, | 3062 | small.name_strategy, |
| 3077 | "enum", | 3063 | "enum", |
| 3078 | inst, | 3064 | inst, |
| | 3065 | extra.data.src_line, |
| 3079 | ); | 3066 | ); |
| 3080 | const new_decl = mod.declPtr(new_decl_index); | 3067 | const new_decl = mod.declPtr(new_decl_index); |
| 3081 | new_decl.owns_tv = true; | 3068 | new_decl.owns_tv = true; |
| ... | @@ -3132,11 +3119,12 @@ fn zirEnumDecl( | ... | @@ -3132,11 +3119,12 @@ fn zirEnumDecl( |
| 3132 | var enum_block: Block = .{ | 3119 | var enum_block: Block = .{ |
| 3133 | .parent = null, | 3120 | .parent = null, |
| 3134 | .sema = sema, | 3121 | .sema = sema, |
| 3135 | .src_decl = new_decl_index, | | |
| 3136 | .namespace = new_namespace_index.unwrap() orelse block.namespace, | 3122 | .namespace = new_namespace_index.unwrap() orelse block.namespace, |
| 3137 | .instructions = .{}, | 3123 | .instructions = .{}, |
| 3138 | .inlining = null, | 3124 | .inlining = null, |
| 3139 | .is_comptime = true, | 3125 | .is_comptime = true, |
| | 3126 | .src_base_inst = tracked_inst, |
| | 3127 | .type_name_ctx = new_decl.name, |
| 3140 | }; | 3128 | }; |
| 3141 | defer enum_block.instructions.deinit(sema.gpa); | 3129 | defer enum_block.instructions.deinit(sema.gpa); |
| 3142 | | 3130 | |
| ... | @@ -3145,9 +3133,9 @@ fn zirEnumDecl( | ... | @@ -3145,9 +3133,9 @@ fn zirEnumDecl( |
| 3145 | } | 3133 | } |
| 3146 | | 3134 | |
| 3147 | if (tag_type_ref != .none) { | 3135 | if (tag_type_ref != .none) { |
| 3148 | const ty = try sema.resolveType(block, tag_ty_src, tag_type_ref); | 3136 | const ty = try sema.resolveType(&enum_block, tag_ty_src, tag_type_ref); |
| 3149 | if (ty.zigTypeTag(mod) != .Int and ty.zigTypeTag(mod) != .ComptimeInt) { | 3137 | if (ty.zigTypeTag(mod) != .Int and ty.zigTypeTag(mod) != .ComptimeInt) { |
| 3150 | return sema.fail(block, tag_ty_src, "expected integer tag type, found '{}'", .{ty.fmt(sema.mod)}); | 3138 | return sema.fail(&enum_block, tag_ty_src, "expected integer tag type, found '{}'", .{ty.fmt(sema.mod)}); |
| 3151 | } | 3139 | } |
| 3152 | break :ty ty; | 3140 | break :ty ty; |
| 3153 | } else if (fields_len == 0) { | 3141 | } else if (fields_len == 0) { |
| ... | @@ -3184,36 +3172,33 @@ fn zirEnumDecl( | ... | @@ -3184,36 +3172,33 @@ fn zirEnumDecl( |
| 3184 | | 3172 | |
| 3185 | const field_name = try mod.intern_pool.getOrPutString(gpa, field_name_zir, .no_embedded_nulls); | 3173 | const field_name = try mod.intern_pool.getOrPutString(gpa, field_name_zir, .no_embedded_nulls); |
| 3186 | | 3174 | |
| | 3175 | const value_src: LazySrcLoc = .{ |
| | 3176 | .base_node_inst = tracked_inst, |
| | 3177 | .offset = .{ .container_field_value = field_i }, |
| | 3178 | }; |
| | 3179 | |
| 3187 | const tag_overflow = if (has_tag_value) overflow: { | 3180 | const tag_overflow = if (has_tag_value) overflow: { |
| 3188 | const tag_val_ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_index]); | 3181 | const tag_val_ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_index]); |
| 3189 | extra_index += 1; | 3182 | extra_index += 1; |
| 3190 | const tag_inst = try sema.resolveInst(tag_val_ref); | 3183 | const tag_inst = try sema.resolveInst(tag_val_ref); |
| 3191 | last_tag_val = sema.resolveConstDefinedValue(block, .unneeded, tag_inst, undefined) catch |err| switch (err) { | 3184 | last_tag_val = try sema.resolveConstDefinedValue(block, .{ |
| 3192 | error.NeededSourceLocation => { | 3185 | .base_node_inst = tracked_inst, |
| 3193 | const value_src = mod.fieldSrcLoc(new_decl_index, .{ | 3186 | .offset = .{ .container_field_name = field_i }, |
| 3194 | .index = field_i, | 3187 | }, tag_inst, .{ |
| 3195 | .range = .value, | 3188 | .needed_comptime_reason = "enum tag value must be comptime-known", |
| 3196 | }).lazy; | 3189 | }); |
| 3197 | _ = try sema.resolveConstDefinedValue(block, value_src, tag_inst, .{ | | |
| 3198 | .needed_comptime_reason = "enum tag value must be comptime-known", | | |
| 3199 | }); | | |
| 3200 | unreachable; | | |
| 3201 | }, | | |
| 3202 | else => |e| return e, | | |
| 3203 | }; | | |
| 3204 | if (!(try sema.intFitsInType(last_tag_val.?, int_tag_ty, null))) break :overflow true; | 3190 | if (!(try sema.intFitsInType(last_tag_val.?, int_tag_ty, null))) break :overflow true; |
| 3205 | last_tag_val = try mod.getCoerced(last_tag_val.?, int_tag_ty); | 3191 | last_tag_val = try mod.getCoerced(last_tag_val.?, int_tag_ty); |
| 3206 | if (wip_ty.nextField(&mod.intern_pool, field_name, last_tag_val.?.toIntern())) |conflict| { | 3192 | if (wip_ty.nextField(&mod.intern_pool, field_name, last_tag_val.?.toIntern())) |conflict| { |
| 3207 | assert(conflict.kind == .value); // AstGen validated names are unique | 3193 | assert(conflict.kind == .value); // AstGen validated names are unique |
| 3208 | const value_src = mod.fieldSrcLoc(new_decl_index, .{ | 3194 | const other_field_src: LazySrcLoc = .{ |
| 3209 | .index = field_i, | 3195 | .base_node_inst = tracked_inst, |
| 3210 | .range = .value, | 3196 | .offset = .{ .container_field_value = conflict.prev_field_idx }, |
| 3211 | }).lazy; | 3197 | }; |
| 3212 | const other_field_src = mod.fieldSrcLoc(new_decl_index, .{ .index = conflict.prev_field_idx }).lazy; | | |
| 3213 | const msg = msg: { | 3198 | const msg = msg: { |
| 3214 | const msg = try sema.errMsg(block, value_src, "enum tag value {} already taken", .{last_tag_val.?.fmtValue(sema.mod, sema)}); | 3199 | const msg = try sema.errMsg(value_src, "enum tag value {} already taken", .{last_tag_val.?.fmtValue(sema.mod, sema)}); |
| 3215 | errdefer msg.destroy(gpa); | 3200 | errdefer msg.destroy(gpa); |
| 3216 | try sema.errNote(block, other_field_src, msg, "other occurrence here", .{}); | 3201 | try sema.errNote(other_field_src, msg, "other occurrence here", .{}); |
| 3217 | break :msg msg; | 3202 | break :msg msg; |
| 3218 | }; | 3203 | }; |
| 3219 | return sema.failWithOwnedErrorMsg(block, msg); | 3204 | return sema.failWithOwnedErrorMsg(block, msg); |
| ... | @@ -3228,12 +3213,14 @@ fn zirEnumDecl( | ... | @@ -3228,12 +3213,14 @@ fn zirEnumDecl( |
| 3228 | if (overflow != null) break :overflow true; | 3213 | if (overflow != null) break :overflow true; |
| 3229 | if (wip_ty.nextField(&mod.intern_pool, field_name, last_tag_val.?.toIntern())) |conflict| { | 3214 | if (wip_ty.nextField(&mod.intern_pool, field_name, last_tag_val.?.toIntern())) |conflict| { |
| 3230 | assert(conflict.kind == .value); // AstGen validated names are unique | 3215 | assert(conflict.kind == .value); // AstGen validated names are unique |
| 3231 | const field_src = mod.fieldSrcLoc(new_decl_index, .{ .index = field_i }).lazy; | 3216 | const other_field_src: LazySrcLoc = .{ |
| 3232 | const other_field_src = mod.fieldSrcLoc(new_decl_index, .{ .index = conflict.prev_field_idx }).lazy; | 3217 | .base_node_inst = tracked_inst, |
| | 3218 | .offset = .{ .container_field_value = conflict.prev_field_idx }, |
| | 3219 | }; |
| 3233 | const msg = msg: { | 3220 | const msg = msg: { |
| 3234 | const msg = try sema.errMsg(block, field_src, "enum tag value {} already taken", .{last_tag_val.?.fmtValue(sema.mod, sema)}); | 3221 | const msg = try sema.errMsg(value_src, "enum tag value {} already taken", .{last_tag_val.?.fmtValue(sema.mod, sema)}); |
| 3235 | errdefer msg.destroy(gpa); | 3222 | errdefer msg.destroy(gpa); |
| 3236 | try sema.errNote(block, other_field_src, msg, "other occurrence here", .{}); | 3223 | try sema.errNote(other_field_src, msg, "other occurrence here", .{}); |
| 3237 | break :msg msg; | 3224 | break :msg msg; |
| 3238 | }; | 3225 | }; |
| 3239 | return sema.failWithOwnedErrorMsg(block, msg); | 3226 | return sema.failWithOwnedErrorMsg(block, msg); |
| ... | @@ -3248,11 +3235,7 @@ fn zirEnumDecl( | ... | @@ -3248,11 +3235,7 @@ fn zirEnumDecl( |
| 3248 | }; | 3235 | }; |
| 3249 | | 3236 | |
| 3250 | if (tag_overflow) { | 3237 | if (tag_overflow) { |
| 3251 | const value_src = mod.fieldSrcLoc(new_decl_index, .{ | 3238 | const msg = try sema.errMsg(value_src, "enumeration value '{}' too large for type '{}'", .{ |
| 3252 | .index = field_i, | | |
| 3253 | .range = if (has_tag_value) .value else .name, | | |
| 3254 | }).lazy; | | |
| 3255 | const msg = try sema.errMsg(block, value_src, "enumeration value '{}' too large for type '{}'", .{ | | |
| 3256 | last_tag_val.?.fmtValue(mod, sema), int_tag_ty.fmt(mod), | 3239 | last_tag_val.?.fmtValue(mod, sema), int_tag_ty.fmt(mod), |
| 3257 | }); | 3240 | }); |
| 3258 | return sema.failWithOwnedErrorMsg(block, msg); | 3241 | return sema.failWithOwnedErrorMsg(block, msg); |
| ... | @@ -3279,7 +3262,8 @@ fn zirUnionDecl( | ... | @@ -3279,7 +3262,8 @@ fn zirUnionDecl( |
| 3279 | const extra = sema.code.extraData(Zir.Inst.UnionDecl, extended.operand); | 3262 | const extra = sema.code.extraData(Zir.Inst.UnionDecl, extended.operand); |
| 3280 | var extra_index: usize = extra.end; | 3263 | var extra_index: usize = extra.end; |
| 3281 | | 3264 | |
| 3282 | const src = extra.data.src(); | 3265 | const tracked_inst = try ip.trackZir(gpa, block.getFileScope(mod), inst); |
| | 3266 | const src: LazySrcLoc = .{ .base_node_inst = tracked_inst, .offset = LazySrcLoc.Offset.nodeOffset(0) }; |
| 3283 | | 3267 | |
| 3284 | extra_index += @intFromBool(small.has_tag_type); | 3268 | extra_index += @intFromBool(small.has_tag_type); |
| 3285 | const captures_len = if (small.has_captures_len) blk: { | 3269 | const captures_len = if (small.has_captures_len) blk: { |
| ... | @@ -3327,7 +3311,7 @@ fn zirUnionDecl( | ... | @@ -3327,7 +3311,7 @@ fn zirUnionDecl( |
| 3327 | .field_types = &.{}, // set later | 3311 | .field_types = &.{}, // set later |
| 3328 | .field_aligns = &.{}, // set later | 3312 | .field_aligns = &.{}, // set later |
| 3329 | .key = .{ .declared = .{ | 3313 | .key = .{ .declared = .{ |
| 3330 | .zir_index = try ip.trackZir(gpa, block.getFileScope(mod), inst), | 3314 | .zir_index = tracked_inst, |
| 3331 | .captures = captures, | 3315 | .captures = captures, |
| 3332 | } }, | 3316 | } }, |
| 3333 | }; | 3317 | }; |
| ... | @@ -3342,11 +3326,11 @@ fn zirUnionDecl( | ... | @@ -3342,11 +3326,11 @@ fn zirUnionDecl( |
| 3342 | | 3326 | |
| 3343 | const new_decl_index = try sema.createAnonymousDeclTypeNamed( | 3327 | const new_decl_index = try sema.createAnonymousDeclTypeNamed( |
| 3344 | block, | 3328 | block, |
| 3345 | src, | | |
| 3346 | Value.fromInterned(wip_ty.index), | 3329 | Value.fromInterned(wip_ty.index), |
| 3347 | small.name_strategy, | 3330 | small.name_strategy, |
| 3348 | "union", | 3331 | "union", |
| 3349 | inst, | 3332 | inst, |
| | 3333 | extra.data.src_line, |
| 3350 | ); | 3334 | ); |
| 3351 | mod.declPtr(new_decl_index).owns_tv = true; | 3335 | mod.declPtr(new_decl_index).owns_tv = true; |
| 3352 | errdefer mod.abortAnonDecl(new_decl_index); | 3336 | errdefer mod.abortAnonDecl(new_decl_index); |
| ... | @@ -3394,7 +3378,8 @@ fn zirOpaqueDecl( | ... | @@ -3394,7 +3378,8 @@ fn zirOpaqueDecl( |
| 3394 | const extra = sema.code.extraData(Zir.Inst.OpaqueDecl, extended.operand); | 3378 | const extra = sema.code.extraData(Zir.Inst.OpaqueDecl, extended.operand); |
| 3395 | var extra_index: usize = extra.end; | 3379 | var extra_index: usize = extra.end; |
| 3396 | | 3380 | |
| 3397 | const src = extra.data.src(); | 3381 | const tracked_inst = try ip.trackZir(gpa, block.getFileScope(mod), inst); |
| | 3382 | const src: LazySrcLoc = .{ .base_node_inst = tracked_inst, .offset = LazySrcLoc.Offset.nodeOffset(0) }; |
| 3398 | | 3383 | |
| 3399 | const captures_len = if (small.has_captures_len) blk: { | 3384 | const captures_len = if (small.has_captures_len) blk: { |
| 3400 | const captures_len = sema.code.extra[extra_index]; | 3385 | const captures_len = sema.code.extra[extra_index]; |
| ... | @@ -3414,7 +3399,7 @@ fn zirOpaqueDecl( | ... | @@ -3414,7 +3399,7 @@ fn zirOpaqueDecl( |
| 3414 | const opaque_init: InternPool.OpaqueTypeInit = .{ | 3399 | const opaque_init: InternPool.OpaqueTypeInit = .{ |
| 3415 | .has_namespace = decls_len != 0, | 3400 | .has_namespace = decls_len != 0, |
| 3416 | .key = .{ .declared = .{ | 3401 | .key = .{ .declared = .{ |
| 3417 | .zir_index = try ip.trackZir(gpa, block.getFileScope(mod), inst), | 3402 | .zir_index = tracked_inst, |
| 3418 | .captures = captures, | 3403 | .captures = captures, |
| 3419 | } }, | 3404 | } }, |
| 3420 | }; | 3405 | }; |
| ... | @@ -3430,11 +3415,11 @@ fn zirOpaqueDecl( | ... | @@ -3430,11 +3415,11 @@ fn zirOpaqueDecl( |
| 3430 | | 3415 | |
| 3431 | const new_decl_index = try sema.createAnonymousDeclTypeNamed( | 3416 | const new_decl_index = try sema.createAnonymousDeclTypeNamed( |
| 3432 | block, | 3417 | block, |
| 3433 | src, | | |
| 3434 | Value.fromInterned(wip_ty.index), | 3418 | Value.fromInterned(wip_ty.index), |
| 3435 | small.name_strategy, | 3419 | small.name_strategy, |
| 3436 | "opaque", | 3420 | "opaque", |
| 3437 | inst, | 3421 | inst, |
| | 3422 | extra.data.src_line, |
| 3438 | ); | 3423 | ); |
| 3439 | mod.declPtr(new_decl_index).owns_tv = true; | 3424 | mod.declPtr(new_decl_index).owns_tv = true; |
| 3440 | errdefer mod.abortAnonDecl(new_decl_index); | 3425 | errdefer mod.abortAnonDecl(new_decl_index); |
| ... | @@ -3525,7 +3510,7 @@ fn zirRef(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins | ... | @@ -3525,7 +3510,7 @@ fn zirRef(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins |
| 3525 | | 3510 | |
| 3526 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_tok; | 3511 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_tok; |
| 3527 | const operand = try sema.resolveInst(inst_data.operand); | 3512 | const operand = try sema.resolveInst(inst_data.operand); |
| 3528 | return sema.analyzeRef(block, inst_data.src(), operand); | 3513 | return sema.analyzeRef(block, block.tokenOffset(inst_data.src_tok), operand); |
| 3529 | } | 3514 | } |
| 3530 | | 3515 | |
| 3531 | fn zirEnsureResultUsed(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void { | 3516 | fn zirEnsureResultUsed(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void { |
| ... | @@ -3534,7 +3519,7 @@ fn zirEnsureResultUsed(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compile | ... | @@ -3534,7 +3519,7 @@ fn zirEnsureResultUsed(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compile |
| 3534 | | 3519 | |
| 3535 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; | 3520 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 3536 | const operand = try sema.resolveInst(inst_data.operand); | 3521 | const operand = try sema.resolveInst(inst_data.operand); |
| 3537 | const src = inst_data.src(); | 3522 | const src = block.nodeOffset(inst_data.src_node); |
| 3538 | | 3523 | |
| 3539 | return sema.ensureResultUsed(block, sema.typeOf(operand), src); | 3524 | return sema.ensureResultUsed(block, sema.typeOf(operand), src); |
| 3540 | } | 3525 | } |
| ... | @@ -3551,19 +3536,19 @@ fn ensureResultUsed( | ... | @@ -3551,19 +3536,19 @@ fn ensureResultUsed( |
| 3551 | .ErrorSet => return sema.fail(block, src, "error set is ignored", .{}), | 3536 | .ErrorSet => return sema.fail(block, src, "error set is ignored", .{}), |
| 3552 | .ErrorUnion => { | 3537 | .ErrorUnion => { |
| 3553 | const msg = msg: { | 3538 | const msg = msg: { |
| 3554 | const msg = try sema.errMsg(block, src, "error union is ignored", .{}); | 3539 | const msg = try sema.errMsg(src, "error union is ignored", .{}); |
| 3555 | errdefer msg.destroy(sema.gpa); | 3540 | errdefer msg.destroy(sema.gpa); |
| 3556 | try sema.errNote(block, src, msg, "consider using 'try', 'catch', or 'if'", .{}); | 3541 | try sema.errNote(src, msg, "consider using 'try', 'catch', or 'if'", .{}); |
| 3557 | break :msg msg; | 3542 | break :msg msg; |
| 3558 | }; | 3543 | }; |
| 3559 | return sema.failWithOwnedErrorMsg(block, msg); | 3544 | return sema.failWithOwnedErrorMsg(block, msg); |
| 3560 | }, | 3545 | }, |
| 3561 | else => { | 3546 | else => { |
| 3562 | const msg = msg: { | 3547 | const msg = msg: { |
| 3563 | const msg = try sema.errMsg(block, src, "value of type '{}' ignored", .{ty.fmt(sema.mod)}); | 3548 | const msg = try sema.errMsg(src, "value of type '{}' ignored", .{ty.fmt(sema.mod)}); |
| 3564 | errdefer msg.destroy(sema.gpa); | 3549 | errdefer msg.destroy(sema.gpa); |
| 3565 | try sema.errNote(block, src, msg, "all non-void values must be used", .{}); | 3550 | try sema.errNote(src, msg, "all non-void values must be used", .{}); |
| 3566 | try sema.errNote(block, src, msg, "to discard the value, assign it to '_'", .{}); | 3551 | try sema.errNote(src, msg, "to discard the value, assign it to '_'", .{}); |
| 3567 | break :msg msg; | 3552 | break :msg msg; |
| 3568 | }; | 3553 | }; |
| 3569 | return sema.failWithOwnedErrorMsg(block, msg); | 3554 | return sema.failWithOwnedErrorMsg(block, msg); |
| ... | @@ -3578,15 +3563,15 @@ fn zirEnsureResultNonError(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com | ... | @@ -3578,15 +3563,15 @@ fn zirEnsureResultNonError(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com |
| 3578 | const mod = sema.mod; | 3563 | const mod = sema.mod; |
| 3579 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; | 3564 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 3580 | const operand = try sema.resolveInst(inst_data.operand); | 3565 | const operand = try sema.resolveInst(inst_data.operand); |
| 3581 | const src = inst_data.src(); | 3566 | const src = block.nodeOffset(inst_data.src_node); |
| 3582 | const operand_ty = sema.typeOf(operand); | 3567 | const operand_ty = sema.typeOf(operand); |
| 3583 | switch (operand_ty.zigTypeTag(mod)) { | 3568 | switch (operand_ty.zigTypeTag(mod)) { |
| 3584 | .ErrorSet => return sema.fail(block, src, "error set is discarded", .{}), | 3569 | .ErrorSet => return sema.fail(block, src, "error set is discarded", .{}), |
| 3585 | .ErrorUnion => { | 3570 | .ErrorUnion => { |
| 3586 | const msg = msg: { | 3571 | const msg = msg: { |
| 3587 | const msg = try sema.errMsg(block, src, "error union is discarded", .{}); | 3572 | const msg = try sema.errMsg(src, "error union is discarded", .{}); |
| 3588 | errdefer msg.destroy(sema.gpa); | 3573 | errdefer msg.destroy(sema.gpa); |
| 3589 | try sema.errNote(block, src, msg, "consider using 'try', 'catch', or 'if'", .{}); | 3574 | try sema.errNote(src, msg, "consider using 'try', 'catch', or 'if'", .{}); |
| 3590 | break :msg msg; | 3575 | break :msg msg; |
| 3591 | }; | 3576 | }; |
| 3592 | return sema.failWithOwnedErrorMsg(block, msg); | 3577 | return sema.failWithOwnedErrorMsg(block, msg); |
| ... | @@ -3601,7 +3586,7 @@ fn zirEnsureErrUnionPayloadVoid(sema: *Sema, block: *Block, inst: Zir.Inst.Index | ... | @@ -3601,7 +3586,7 @@ fn zirEnsureErrUnionPayloadVoid(sema: *Sema, block: *Block, inst: Zir.Inst.Index |
| 3601 | | 3586 | |
| 3602 | const mod = sema.mod; | 3587 | const mod = sema.mod; |
| 3603 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; | 3588 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 3604 | const src = inst_data.src(); | 3589 | const src = block.nodeOffset(inst_data.src_node); |
| 3605 | const operand = try sema.resolveInst(inst_data.operand); | 3590 | const operand = try sema.resolveInst(inst_data.operand); |
| 3606 | const operand_ty = sema.typeOf(operand); | 3591 | const operand_ty = sema.typeOf(operand); |
| 3607 | const err_union_ty = if (operand_ty.zigTypeTag(mod) == .Pointer) | 3592 | const err_union_ty = if (operand_ty.zigTypeTag(mod) == .Pointer) |
| ... | @@ -3612,9 +3597,9 @@ fn zirEnsureErrUnionPayloadVoid(sema: *Sema, block: *Block, inst: Zir.Inst.Index | ... | @@ -3612,9 +3597,9 @@ fn zirEnsureErrUnionPayloadVoid(sema: *Sema, block: *Block, inst: Zir.Inst.Index |
| 3612 | const payload_ty = err_union_ty.errorUnionPayload(mod).zigTypeTag(mod); | 3597 | const payload_ty = err_union_ty.errorUnionPayload(mod).zigTypeTag(mod); |
| 3613 | if (payload_ty != .Void and payload_ty != .NoReturn) { | 3598 | if (payload_ty != .Void and payload_ty != .NoReturn) { |
| 3614 | const msg = msg: { | 3599 | const msg = msg: { |
| 3615 | const msg = try sema.errMsg(block, src, "error union payload is ignored", .{}); | 3600 | const msg = try sema.errMsg(src, "error union payload is ignored", .{}); |
| 3616 | errdefer msg.destroy(sema.gpa); | 3601 | errdefer msg.destroy(sema.gpa); |
| 3617 | try sema.errNote(block, src, msg, "payload value can be explicitly ignored with '|_|'", .{}); | 3602 | try sema.errNote(src, msg, "payload value can be explicitly ignored with '|_|'", .{}); |
| 3618 | break :msg msg; | 3603 | break :msg msg; |
| 3619 | }; | 3604 | }; |
| 3620 | return sema.failWithOwnedErrorMsg(block, msg); | 3605 | return sema.failWithOwnedErrorMsg(block, msg); |
| ... | @@ -3626,7 +3611,7 @@ fn zirIndexablePtrLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE | ... | @@ -3626,7 +3611,7 @@ fn zirIndexablePtrLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE |
| 3626 | defer tracy.end(); | 3611 | defer tracy.end(); |
| 3627 | | 3612 | |
| 3628 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; | 3613 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 3629 | const src = inst_data.src(); | 3614 | const src = block.nodeOffset(inst_data.src_node); |
| 3630 | const object = try sema.resolveInst(inst_data.operand); | 3615 | const object = try sema.resolveInst(inst_data.operand); |
| 3631 | | 3616 | |
| 3632 | return indexablePtrLen(sema, block, src, object); | 3617 | return indexablePtrLen(sema, block, src, object); |
| ... | @@ -3668,8 +3653,8 @@ fn zirAllocExtended( | ... | @@ -3668,8 +3653,8 @@ fn zirAllocExtended( |
| 3668 | ) CompileError!Air.Inst.Ref { | 3653 | ) CompileError!Air.Inst.Ref { |
| 3669 | const gpa = sema.gpa; | 3654 | const gpa = sema.gpa; |
| 3670 | const extra = sema.code.extraData(Zir.Inst.AllocExtended, extended.operand); | 3655 | const extra = sema.code.extraData(Zir.Inst.AllocExtended, extended.operand); |
| 3671 | const ty_src: LazySrcLoc = .{ .node_offset_var_decl_ty = extra.data.src_node }; | 3656 | const ty_src = block.src(.{ .node_offset_var_decl_ty = extra.data.src_node }); |
| 3672 | const align_src: LazySrcLoc = .{ .node_offset_var_decl_align = extra.data.src_node }; | 3657 | const align_src = block.src(.{ .node_offset_var_decl_align = extra.data.src_node }); |
| 3673 | const small: Zir.Inst.AllocExtended.Small = @bitCast(extended.small); | 3658 | const small: Zir.Inst.AllocExtended.Small = @bitCast(extended.small); |
| 3674 | | 3659 | |
| 3675 | var extra_index: usize = extra.end; | 3660 | var extra_index: usize = extra.end; |
| ... | @@ -3745,7 +3730,7 @@ fn zirAllocComptime(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr | ... | @@ -3745,7 +3730,7 @@ fn zirAllocComptime(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr |
| 3745 | defer tracy.end(); | 3730 | defer tracy.end(); |
| 3746 | | 3731 | |
| 3747 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; | 3732 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 3748 | const ty_src: LazySrcLoc = .{ .node_offset_var_decl_ty = inst_data.src_node }; | 3733 | const ty_src = block.src(.{ .node_offset_var_decl_ty = inst_data.src_node }); |
| 3749 | const var_ty = try sema.resolveType(block, ty_src, inst_data.operand); | 3734 | const var_ty = try sema.resolveType(block, ty_src, inst_data.operand); |
| 3750 | return sema.analyzeComptimeAlloc(block, var_ty, .none); | 3735 | return sema.analyzeComptimeAlloc(block, var_ty, .none); |
| 3751 | } | 3736 | } |
| ... | @@ -3811,7 +3796,7 @@ fn zirMakePtrConst(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro | ... | @@ -3811,7 +3796,7 @@ fn zirMakePtrConst(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro |
| 3811 | if (try sema.typeRequiresComptime(elem_ty)) { | 3796 | if (try sema.typeRequiresComptime(elem_ty)) { |
| 3812 | // The value was initialized through RLS, so we didn't detect the runtime condition earlier. | 3797 | // The value was initialized through RLS, so we didn't detect the runtime condition earlier. |
| 3813 | // TODO: source location of runtime control flow | 3798 | // TODO: source location of runtime control flow |
| 3814 | const init_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node }; | 3799 | const init_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node }); |
| 3815 | return sema.fail(block, init_src, "value with comptime-only type '{}' depends on runtime control flow", .{elem_ty.fmt(mod)}); | 3800 | return sema.fail(block, init_src, "value with comptime-only type '{}' depends on runtime control flow", .{elem_ty.fmt(mod)}); |
| 3816 | } | 3801 | } |
| 3817 | | 3802 | |
| ... | @@ -3980,7 +3965,7 @@ fn resolveComptimeKnownAllocPtr(sema: *Sema, block: *Block, alloc: Air.Inst.Ref, | ... | @@ -3980,7 +3965,7 @@ fn resolveComptimeKnownAllocPtr(sema: *Sema, block: *Block, alloc: Air.Inst.Ref, |
| 3980 | .ty = opt_ty.toIntern(), | 3965 | .ty = opt_ty.toIntern(), |
| 3981 | .val = payload_val.toIntern(), | 3966 | .val = payload_val.toIntern(), |
| 3982 | } }); | 3967 | } }); |
| 3983 | try sema.storePtrVal(block, .unneeded, Value.fromInterned(decl_parent_ptr), Value.fromInterned(opt_val), opt_ty); | 3968 | try sema.storePtrVal(block, LazySrcLoc.unneeded, Value.fromInterned(decl_parent_ptr), Value.fromInterned(opt_val), opt_ty); |
| 3984 | break :ptr (try Value.fromInterned(decl_parent_ptr).ptrOptPayload(sema)).toIntern(); | 3969 | break :ptr (try Value.fromInterned(decl_parent_ptr).ptrOptPayload(sema)).toIntern(); |
| 3985 | }, | 3970 | }, |
| 3986 | .eu_payload => ptr: { | 3971 | .eu_payload => ptr: { |
| ... | @@ -3993,7 +3978,7 @@ fn resolveComptimeKnownAllocPtr(sema: *Sema, block: *Block, alloc: Air.Inst.Ref, | ... | @@ -3993,7 +3978,7 @@ fn resolveComptimeKnownAllocPtr(sema: *Sema, block: *Block, alloc: Air.Inst.Ref, |
| 3993 | .ty = eu_ty.toIntern(), | 3978 | .ty = eu_ty.toIntern(), |
| 3994 | .val = .{ .payload = payload_val.toIntern() }, | 3979 | .val = .{ .payload = payload_val.toIntern() }, |
| 3995 | } }); | 3980 | } }); |
| 3996 | try sema.storePtrVal(block, .unneeded, Value.fromInterned(decl_parent_ptr), Value.fromInterned(eu_val), eu_ty); | 3981 | try sema.storePtrVal(block, LazySrcLoc.unneeded, Value.fromInterned(decl_parent_ptr), Value.fromInterned(eu_val), eu_ty); |
| 3997 | break :ptr (try Value.fromInterned(decl_parent_ptr).ptrEuPayload(sema)).toIntern(); | 3982 | break :ptr (try Value.fromInterned(decl_parent_ptr).ptrEuPayload(sema)).toIntern(); |
| 3998 | }, | 3983 | }, |
| 3999 | .field => |idx| ptr: { | 3984 | .field => |idx| ptr: { |
| ... | @@ -4006,7 +3991,7 @@ fn resolveComptimeKnownAllocPtr(sema: *Sema, block: *Block, alloc: Air.Inst.Ref, | ... | @@ -4006,7 +3991,7 @@ fn resolveComptimeKnownAllocPtr(sema: *Sema, block: *Block, alloc: Air.Inst.Ref, |
| 4006 | const payload_val = try sema.typeHasOnePossibleValue(payload_ty) orelse try zcu.undefValue(payload_ty); | 3991 | const payload_val = try sema.typeHasOnePossibleValue(payload_ty) orelse try zcu.undefValue(payload_ty); |
| 4007 | const tag_val = try zcu.enumValueFieldIndex(Type.fromInterned(union_obj.enum_tag_ty), idx); | 3992 | const tag_val = try zcu.enumValueFieldIndex(Type.fromInterned(union_obj.enum_tag_ty), idx); |
| 4008 | const store_val = try zcu.unionValue(maybe_union_ty, tag_val, payload_val); | 3993 | const store_val = try zcu.unionValue(maybe_union_ty, tag_val, payload_val); |
| 4009 | try sema.storePtrVal(block, .unneeded, Value.fromInterned(decl_parent_ptr), store_val, maybe_union_ty); | 3994 | try sema.storePtrVal(block, LazySrcLoc.unneeded, Value.fromInterned(decl_parent_ptr), store_val, maybe_union_ty); |
| 4010 | } | 3995 | } |
| 4011 | break :ptr (try Value.fromInterned(decl_parent_ptr).ptrField(idx, sema)).toIntern(); | 3996 | break :ptr (try Value.fromInterned(decl_parent_ptr).ptrField(idx, sema)).toIntern(); |
| 4012 | }, | 3997 | }, |
| ... | @@ -4028,14 +4013,14 @@ fn resolveComptimeKnownAllocPtr(sema: *Sema, block: *Block, alloc: Air.Inst.Ref, | ... | @@ -4028,14 +4013,14 @@ fn resolveComptimeKnownAllocPtr(sema: *Sema, block: *Block, alloc: Air.Inst.Ref, |
| 4028 | const air_ptr_inst = store_inst.data.bin_op.lhs.toIndex().?; | 4013 | const air_ptr_inst = store_inst.data.bin_op.lhs.toIndex().?; |
| 4029 | const store_val = (try sema.resolveValue(store_inst.data.bin_op.rhs)).?; | 4014 | const store_val = (try sema.resolveValue(store_inst.data.bin_op.rhs)).?; |
| 4030 | const new_ptr = ptr_mapping.get(air_ptr_inst).?; | 4015 | const new_ptr = ptr_mapping.get(air_ptr_inst).?; |
| 4031 | try sema.storePtrVal(block, .unneeded, Value.fromInterned(new_ptr), store_val, Type.fromInterned(zcu.intern_pool.typeOf(store_val.toIntern()))); | 4016 | try sema.storePtrVal(block, LazySrcLoc.unneeded, Value.fromInterned(new_ptr), store_val, Type.fromInterned(zcu.intern_pool.typeOf(store_val.toIntern()))); |
| 4032 | }, | 4017 | }, |
| 4033 | else => unreachable, | 4018 | else => unreachable, |
| 4034 | } | 4019 | } |
| 4035 | } | 4020 | } |
| 4036 | | 4021 | |
| 4037 | // The value is finalized - load it! | 4022 | // The value is finalized - load it! |
| 4038 | const val = (try sema.pointerDeref(block, .unneeded, Value.fromInterned(alloc_ptr), alloc_ty)).?.toIntern(); | 4023 | const val = (try sema.pointerDeref(block, LazySrcLoc.unneeded, Value.fromInterned(alloc_ptr), alloc_ty)).?.toIntern(); |
| 4039 | return sema.finishResolveComptimeKnownAllocPtr(block, alloc_ty, val, ct_alloc, alloc_inst, comptime_info.value); | 4024 | return sema.finishResolveComptimeKnownAllocPtr(block, alloc_ty, val, ct_alloc, alloc_inst, comptime_info.value); |
| 4040 | } | 4025 | } |
| 4041 | | 4026 | |
| ... | @@ -4138,7 +4123,7 @@ fn zirAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.I | ... | @@ -4138,7 +4123,7 @@ fn zirAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.I |
| 4138 | defer tracy.end(); | 4123 | defer tracy.end(); |
| 4139 | | 4124 | |
| 4140 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; | 4125 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 4141 | const ty_src: LazySrcLoc = .{ .node_offset_var_decl_ty = inst_data.src_node }; | 4126 | const ty_src = block.src(.{ .node_offset_var_decl_ty = inst_data.src_node }); |
| 4142 | const var_ty = try sema.resolveType(block, ty_src, inst_data.operand); | 4127 | const var_ty = try sema.resolveType(block, ty_src, inst_data.operand); |
| 4143 | if (block.is_comptime) { | 4128 | if (block.is_comptime) { |
| 4144 | return sema.analyzeComptimeAlloc(block, var_ty, .none); | 4129 | return sema.analyzeComptimeAlloc(block, var_ty, .none); |
| ... | @@ -4161,7 +4146,7 @@ fn zirAllocMut(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -4161,7 +4146,7 @@ fn zirAllocMut(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 4161 | defer tracy.end(); | 4146 | defer tracy.end(); |
| 4162 | | 4147 | |
| 4163 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; | 4148 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 4164 | const ty_src: LazySrcLoc = .{ .node_offset_var_decl_ty = inst_data.src_node }; | 4149 | const ty_src = block.src(.{ .node_offset_var_decl_ty = inst_data.src_node }); |
| 4165 | const var_ty = try sema.resolveType(block, ty_src, inst_data.operand); | 4150 | const var_ty = try sema.resolveType(block, ty_src, inst_data.operand); |
| 4166 | if (block.is_comptime) { | 4151 | if (block.is_comptime) { |
| 4167 | return sema.analyzeComptimeAlloc(block, var_ty, .none); | 4152 | return sema.analyzeComptimeAlloc(block, var_ty, .none); |
| ... | @@ -4220,8 +4205,8 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com | ... | @@ -4220,8 +4205,8 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com |
| 4220 | const mod = sema.mod; | 4205 | const mod = sema.mod; |
| 4221 | const gpa = sema.gpa; | 4206 | const gpa = sema.gpa; |
| 4222 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; | 4207 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 4223 | const src = inst_data.src(); | 4208 | const src = block.nodeOffset(inst_data.src_node); |
| 4224 | const ty_src: LazySrcLoc = .{ .node_offset_var_decl_ty = inst_data.src_node }; | 4209 | const ty_src = block.src(.{ .node_offset_var_decl_ty = inst_data.src_node }); |
| 4225 | const ptr = try sema.resolveInst(inst_data.operand); | 4210 | const ptr = try sema.resolveInst(inst_data.operand); |
| 4226 | const ptr_inst = ptr.toIndex().?; | 4211 | const ptr_inst = ptr.toIndex().?; |
| 4227 | const target = mod.getTarget(); | 4212 | const target = mod.getTarget(); |
| ... | @@ -4361,7 +4346,7 @@ fn zirForLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. | ... | @@ -4361,7 +4346,7 @@ fn zirForLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. |
| 4361 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 4346 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 4362 | const extra = sema.code.extraData(Zir.Inst.MultiOp, inst_data.payload_index); | 4347 | const extra = sema.code.extraData(Zir.Inst.MultiOp, inst_data.payload_index); |
| 4363 | const args = sema.code.refSlice(extra.end, extra.data.operands_len); | 4348 | const args = sema.code.refSlice(extra.end, extra.data.operands_len); |
| 4364 | const src = inst_data.src(); | 4349 | const src = block.nodeOffset(inst_data.src_node); |
| 4365 | | 4350 | |
| 4366 | var len: Air.Inst.Ref = .none; | 4351 | var len: Air.Inst.Ref = .none; |
| 4367 | var len_val: ?Value = null; | 4352 | var len_val: ?Value = null; |
| ... | @@ -4384,20 +4369,20 @@ fn zirForLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. | ... | @@ -4384,20 +4369,20 @@ fn zirForLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. |
| 4384 | .Int, .ComptimeInt => true, | 4369 | .Int, .ComptimeInt => true, |
| 4385 | else => false, | 4370 | else => false, |
| 4386 | }; | 4371 | }; |
| 4387 | const arg_src: LazySrcLoc = .{ .for_input = .{ | 4372 | const arg_src = block.src(.{ .for_input = .{ |
| 4388 | .for_node_offset = inst_data.src_node, | 4373 | .for_node_offset = inst_data.src_node, |
| 4389 | .input_index = i, | 4374 | .input_index = i, |
| 4390 | } }; | 4375 | } }); |
| 4391 | const arg_len_uncoerced = if (is_int) object else l: { | 4376 | const arg_len_uncoerced = if (is_int) object else l: { |
| 4392 | if (!object_ty.isIndexable(mod)) { | 4377 | if (!object_ty.isIndexable(mod)) { |
| 4393 | // Instead of using checkIndexable we customize this error. | 4378 | // Instead of using checkIndexable we customize this error. |
| 4394 | const msg = msg: { | 4379 | const msg = msg: { |
| 4395 | const msg = try sema.errMsg(block, arg_src, "type '{}' is not indexable and not a range", .{object_ty.fmt(sema.mod)}); | 4380 | const msg = try sema.errMsg(arg_src, "type '{}' is not indexable and not a range", .{object_ty.fmt(sema.mod)}); |
| 4396 | errdefer msg.destroy(sema.gpa); | 4381 | errdefer msg.destroy(sema.gpa); |
| 4397 | try sema.errNote(block, arg_src, msg, "for loop operand must be a range, array, slice, tuple, or vector", .{}); | 4382 | try sema.errNote(arg_src, msg, "for loop operand must be a range, array, slice, tuple, or vector", .{}); |
| 4398 | | 4383 | |
| 4399 | if (object_ty.zigTypeTag(mod) == .ErrorUnion) { | 4384 | if (object_ty.zigTypeTag(mod) == .ErrorUnion) { |
| 4400 | try sema.errNote(block, arg_src, msg, "consider using 'try', 'catch', or 'if'", .{}); | 4385 | try sema.errNote(arg_src, msg, "consider using 'try', 'catch', or 'if'", .{}); |
| 4401 | } | 4386 | } |
| 4402 | | 4387 | |
| 4403 | break :msg msg; | 4388 | break :msg msg; |
| ... | @@ -4417,16 +4402,16 @@ fn zirForLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. | ... | @@ -4417,16 +4402,16 @@ fn zirForLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. |
| 4417 | if (len_val) |v| { | 4402 | if (len_val) |v| { |
| 4418 | if (!(try sema.valuesEqual(arg_val, v, Type.usize))) { | 4403 | if (!(try sema.valuesEqual(arg_val, v, Type.usize))) { |
| 4419 | const msg = msg: { | 4404 | const msg = msg: { |
| 4420 | const msg = try sema.errMsg(block, src, "non-matching for loop lengths", .{}); | 4405 | const msg = try sema.errMsg(src, "non-matching for loop lengths", .{}); |
| 4421 | errdefer msg.destroy(gpa); | 4406 | errdefer msg.destroy(gpa); |
| 4422 | const a_src: LazySrcLoc = .{ .for_input = .{ | 4407 | const a_src = block.src(.{ .for_input = .{ |
| 4423 | .for_node_offset = inst_data.src_node, | 4408 | .for_node_offset = inst_data.src_node, |
| 4424 | .input_index = len_idx, | 4409 | .input_index = len_idx, |
| 4425 | } }; | 4410 | } }); |
| 4426 | try sema.errNote(block, a_src, msg, "length {} here", .{ | 4411 | try sema.errNote(a_src, msg, "length {} here", .{ |
| 4427 | v.fmtValue(sema.mod, sema), | 4412 | v.fmtValue(sema.mod, sema), |
| 4428 | }); | 4413 | }); |
| 4429 | try sema.errNote(block, arg_src, msg, "length {} here", .{ | 4414 | try sema.errNote(arg_src, msg, "length {} here", .{ |
| 4430 | arg_val.fmtValue(sema.mod, sema), | 4415 | arg_val.fmtValue(sema.mod, sema), |
| 4431 | }); | 4416 | }); |
| 4432 | break :msg msg; | 4417 | break :msg msg; |
| ... | @@ -4446,7 +4431,7 @@ fn zirForLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. | ... | @@ -4446,7 +4431,7 @@ fn zirForLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. |
| 4446 | | 4431 | |
| 4447 | if (len == .none) { | 4432 | if (len == .none) { |
| 4448 | const msg = msg: { | 4433 | const msg = msg: { |
| 4449 | const msg = try sema.errMsg(block, src, "unbounded for loop", .{}); | 4434 | const msg = try sema.errMsg(src, "unbounded for loop", .{}); |
| 4450 | errdefer msg.destroy(gpa); | 4435 | errdefer msg.destroy(gpa); |
| 4451 | for (args, 0..) |zir_arg, i_usize| { | 4436 | for (args, 0..) |zir_arg, i_usize| { |
| 4452 | const i: u32 = @intCast(i_usize); | 4437 | const i: u32 = @intCast(i_usize); |
| ... | @@ -4459,11 +4444,11 @@ fn zirForLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. | ... | @@ -4459,11 +4444,11 @@ fn zirForLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. |
| 4459 | .Int, .ComptimeInt => continue, | 4444 | .Int, .ComptimeInt => continue, |
| 4460 | else => {}, | 4445 | else => {}, |
| 4461 | } | 4446 | } |
| 4462 | const arg_src: LazySrcLoc = .{ .for_input = .{ | 4447 | const arg_src = block.src(.{ .for_input = .{ |
| 4463 | .for_node_offset = inst_data.src_node, | 4448 | .for_node_offset = inst_data.src_node, |
| 4464 | .input_index = i, | 4449 | .input_index = i, |
| 4465 | } }; | 4450 | } }); |
| 4466 | try sema.errNote(block, arg_src, msg, "type '{}' has no upper bound", .{ | 4451 | try sema.errNote(arg_src, msg, "type '{}' has no upper bound", .{ |
| 4467 | object_ty.fmt(sema.mod), | 4452 | object_ty.fmt(sema.mod), |
| 4468 | }); | 4453 | }); |
| 4469 | } | 4454 | } |
| ... | @@ -4504,16 +4489,16 @@ fn optEuBasePtrInit(sema: *Sema, block: *Block, ptr: Air.Inst.Ref, src: LazySrcL | ... | @@ -4504,16 +4489,16 @@ fn optEuBasePtrInit(sema: *Sema, block: *Block, ptr: Air.Inst.Ref, src: LazySrcL |
| 4504 | fn zirOptEuBasePtrInit(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 4489 | fn zirOptEuBasePtrInit(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 4505 | const un_node = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; | 4490 | const un_node = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 4506 | const ptr = try sema.resolveInst(un_node.operand); | 4491 | const ptr = try sema.resolveInst(un_node.operand); |
| 4507 | return sema.optEuBasePtrInit(block, ptr, un_node.src()); | 4492 | return sema.optEuBasePtrInit(block, ptr, block.nodeOffset(un_node.src_node)); |
| 4508 | } | 4493 | } |
| 4509 | | 4494 | |
| 4510 | fn zirCoercePtrElemTy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 4495 | fn zirCoercePtrElemTy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 4511 | const mod = sema.mod; | 4496 | const mod = sema.mod; |
| 4512 | const pl_node = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 4497 | const pl_node = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 4513 | const src = pl_node.src(); | 4498 | const src = block.nodeOffset(pl_node.src_node); |
| 4514 | const extra = sema.code.extraData(Zir.Inst.Bin, pl_node.payload_index).data; | 4499 | const extra = sema.code.extraData(Zir.Inst.Bin, pl_node.payload_index).data; |
| 4515 | const uncoerced_val = try sema.resolveInst(extra.rhs); | 4500 | const uncoerced_val = try sema.resolveInst(extra.rhs); |
| 4516 | const maybe_wrapped_ptr_ty = sema.resolveType(block, .unneeded, extra.lhs) catch |err| switch (err) { | 4501 | const maybe_wrapped_ptr_ty = sema.resolveType(block, LazySrcLoc.unneeded, extra.lhs) catch |err| switch (err) { |
| 4517 | error.GenericPoison => return uncoerced_val, | 4502 | error.GenericPoison => return uncoerced_val, |
| 4518 | else => |e| return e, | 4503 | else => |e| return e, |
| 4519 | }; | 4504 | }; |
| ... | @@ -4561,7 +4546,7 @@ fn zirCoercePtrElemTy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE | ... | @@ -4561,7 +4546,7 @@ fn zirCoercePtrElemTy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE |
| 4561 | fn zirValidateRefTy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void { | 4546 | fn zirValidateRefTy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void { |
| 4562 | const mod = sema.mod; | 4547 | const mod = sema.mod; |
| 4563 | const un_tok = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_tok; | 4548 | const un_tok = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_tok; |
| 4564 | const src = un_tok.src(); | 4549 | const src = block.tokenOffset(un_tok.src_tok); |
| 4565 | // In case of GenericPoison, we don't actually have a type, so this will be | 4550 | // In case of GenericPoison, we don't actually have a type, so this will be |
| 4566 | // treated as an untyped address-of operator. | 4551 | // treated as an untyped address-of operator. |
| 4567 | const operand_air_inst = sema.resolveInst(un_tok.operand) catch |err| switch (err) { | 4552 | const operand_air_inst = sema.resolveInst(un_tok.operand) catch |err| switch (err) { |
| ... | @@ -4575,9 +4560,9 @@ fn zirValidateRefTy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr | ... | @@ -4575,9 +4560,9 @@ fn zirValidateRefTy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr |
| 4575 | if (ty_operand.isGenericPoison()) return; | 4560 | if (ty_operand.isGenericPoison()) return; |
| 4576 | if (ty_operand.optEuBaseType(mod).zigTypeTag(mod) != .Pointer) { | 4561 | if (ty_operand.optEuBaseType(mod).zigTypeTag(mod) != .Pointer) { |
| 4577 | return sema.failWithOwnedErrorMsg(block, msg: { | 4562 | return sema.failWithOwnedErrorMsg(block, msg: { |
| 4578 | const msg = try sema.errMsg(block, src, "expected type '{}', found pointer", .{ty_operand.fmt(mod)}); | 4563 | const msg = try sema.errMsg(src, "expected type '{}', found pointer", .{ty_operand.fmt(mod)}); |
| 4579 | errdefer msg.destroy(sema.gpa); | 4564 | errdefer msg.destroy(sema.gpa); |
| 4580 | try sema.errNote(block, src, msg, "address-of operator always returns a pointer", .{}); | 4565 | try sema.errNote(src, msg, "address-of operator always returns a pointer", .{}); |
| 4581 | break :msg msg; | 4566 | break :msg msg; |
| 4582 | }); | 4567 | }); |
| 4583 | } | 4568 | } |
| ... | @@ -4590,9 +4575,9 @@ fn zirValidateArrayInitRefTy( | ... | @@ -4590,9 +4575,9 @@ fn zirValidateArrayInitRefTy( |
| 4590 | ) CompileError!Air.Inst.Ref { | 4575 | ) CompileError!Air.Inst.Ref { |
| 4591 | const mod = sema.mod; | 4576 | const mod = sema.mod; |
| 4592 | const pl_node = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 4577 | const pl_node = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 4593 | const src = pl_node.src(); | 4578 | const src = block.nodeOffset(pl_node.src_node); |
| 4594 | const extra = sema.code.extraData(Zir.Inst.ArrayInitRefTy, pl_node.payload_index).data; | 4579 | const extra = sema.code.extraData(Zir.Inst.ArrayInitRefTy, pl_node.payload_index).data; |
| 4595 | const maybe_wrapped_ptr_ty = sema.resolveType(block, .unneeded, extra.ptr_ty) catch |err| switch (err) { | 4580 | const maybe_wrapped_ptr_ty = sema.resolveType(block, LazySrcLoc.unneeded, extra.ptr_ty) catch |err| switch (err) { |
| 4596 | error.GenericPoison => return .generic_poison_type, | 4581 | error.GenericPoison => return .generic_poison_type, |
| 4597 | else => |e| return e, | 4582 | else => |e| return e, |
| 4598 | }; | 4583 | }; |
| ... | @@ -4632,8 +4617,8 @@ fn zirValidateArrayInitTy( | ... | @@ -4632,8 +4617,8 @@ fn zirValidateArrayInitTy( |
| 4632 | ) CompileError!void { | 4617 | ) CompileError!void { |
| 4633 | const mod = sema.mod; | 4618 | const mod = sema.mod; |
| 4634 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 4619 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 4635 | const src = inst_data.src(); | 4620 | const src = block.nodeOffset(inst_data.src_node); |
| 4636 | const ty_src: LazySrcLoc = if (is_result_ty) src else .{ .node_offset_init_ty = inst_data.src_node }; | 4621 | const ty_src: LazySrcLoc = if (is_result_ty) src else block.src(.{ .node_offset_init_ty = inst_data.src_node }); |
| 4637 | const extra = sema.code.extraData(Zir.Inst.ArrayInit, inst_data.payload_index).data; | 4622 | const extra = sema.code.extraData(Zir.Inst.ArrayInit, inst_data.payload_index).data; |
| 4638 | const ty = sema.resolveType(block, ty_src, extra.ty) catch |err| switch (err) { | 4623 | const ty = sema.resolveType(block, ty_src, extra.ty) catch |err| switch (err) { |
| 4639 | // It's okay for the type to be unknown: this will result in an anonymous array init. | 4624 | // It's okay for the type to be unknown: this will result in an anonymous array init. |
| ... | @@ -4695,7 +4680,7 @@ fn zirValidateStructInitTy( | ... | @@ -4695,7 +4680,7 @@ fn zirValidateStructInitTy( |
| 4695 | ) CompileError!void { | 4680 | ) CompileError!void { |
| 4696 | const mod = sema.mod; | 4681 | const mod = sema.mod; |
| 4697 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; | 4682 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 4698 | const src = inst_data.src(); | 4683 | const src = block.nodeOffset(inst_data.src_node); |
| 4699 | const ty = sema.resolveType(block, src, inst_data.operand) catch |err| switch (err) { | 4684 | const ty = sema.resolveType(block, src, inst_data.operand) catch |err| switch (err) { |
| 4700 | // It's okay for the type to be unknown: this will result in an anonymous struct init. | 4685 | // It's okay for the type to be unknown: this will result in an anonymous struct init. |
| 4701 | error.GenericPoison => return, | 4686 | error.GenericPoison => return, |
| ... | @@ -4720,7 +4705,7 @@ fn zirValidatePtrStructInit( | ... | @@ -4720,7 +4705,7 @@ fn zirValidatePtrStructInit( |
| 4720 | | 4705 | |
| 4721 | const mod = sema.mod; | 4706 | const mod = sema.mod; |
| 4722 | const validate_inst = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 4707 | const validate_inst = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 4723 | const init_src = validate_inst.src(); | 4708 | const init_src = block.nodeOffset(validate_inst.src_node); |
| 4724 | const validate_extra = sema.code.extraData(Zir.Inst.Block, validate_inst.payload_index); | 4709 | const validate_extra = sema.code.extraData(Zir.Inst.Block, validate_inst.payload_index); |
| 4725 | const instrs = sema.code.bodySlice(validate_extra.end, validate_extra.data.body_len); | 4710 | const instrs = sema.code.bodySlice(validate_extra.end, validate_extra.data.body_len); |
| 4726 | const field_ptr_data = sema.code.instructions.items(.data)[@intFromEnum(instrs[0])].pl_node; | 4711 | const field_ptr_data = sema.code.instructions.items(.data)[@intFromEnum(instrs[0])].pl_node; |
| ... | @@ -4759,7 +4744,6 @@ fn validateUnionInit( | ... | @@ -4759,7 +4744,6 @@ fn validateUnionInit( |
| 4759 | if (instrs.len != 1) { | 4744 | if (instrs.len != 1) { |
| 4760 | const msg = msg: { | 4745 | const msg = msg: { |
| 4761 | const msg = try sema.errMsg( | 4746 | const msg = try sema.errMsg( |
| 4762 | block, | | |
| 4763 | init_src, | 4747 | init_src, |
| 4764 | "cannot initialize multiple union fields at once; unions can only have one active field", | 4748 | "cannot initialize multiple union fields at once; unions can only have one active field", |
| 4765 | .{}, | 4749 | .{}, |
| ... | @@ -4768,8 +4752,8 @@ fn validateUnionInit( | ... | @@ -4768,8 +4752,8 @@ fn validateUnionInit( |
| 4768 | | 4752 | |
| 4769 | for (instrs[1..]) |inst| { | 4753 | for (instrs[1..]) |inst| { |
| 4770 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 4754 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 4771 | const inst_src: LazySrcLoc = .{ .node_offset_initializer = inst_data.src_node }; | 4755 | const inst_src = block.src(.{ .node_offset_initializer = inst_data.src_node }); |
| 4772 | try sema.errNote(block, inst_src, msg, "additional initializer here", .{}); | 4756 | try sema.errNote(inst_src, msg, "additional initializer here", .{}); |
| 4773 | } | 4757 | } |
| 4774 | try sema.addDeclaredHereNote(msg, union_ty); | 4758 | try sema.addDeclaredHereNote(msg, union_ty); |
| 4775 | break :msg msg; | 4759 | break :msg msg; |
| ... | @@ -4786,7 +4770,7 @@ fn validateUnionInit( | ... | @@ -4786,7 +4770,7 @@ fn validateUnionInit( |
| 4786 | | 4770 | |
| 4787 | const field_ptr = instrs[0]; | 4771 | const field_ptr = instrs[0]; |
| 4788 | const field_ptr_data = sema.code.instructions.items(.data)[@intFromEnum(field_ptr)].pl_node; | 4772 | const field_ptr_data = sema.code.instructions.items(.data)[@intFromEnum(field_ptr)].pl_node; |
| 4789 | const field_src: LazySrcLoc = .{ .node_offset_initializer = field_ptr_data.src_node }; | 4773 | const field_src = block.src(.{ .node_offset_initializer = field_ptr_data.src_node }); |
| 4790 | const field_ptr_extra = sema.code.extraData(Zir.Inst.Field, field_ptr_data.payload_index).data; | 4774 | const field_ptr_extra = sema.code.extraData(Zir.Inst.Field, field_ptr_data.payload_index).data; |
| 4791 | const field_name = try mod.intern_pool.getOrPutString( | 4775 | const field_name = try mod.intern_pool.getOrPutString( |
| 4792 | gpa, | 4776 | gpa, |
| ... | @@ -4895,15 +4879,15 @@ fn validateUnionInit( | ... | @@ -4895,15 +4879,15 @@ fn validateUnionInit( |
| 4895 | try sema.storePtr2(block, init_src, union_ptr, init_src, union_init, init_src, .store); | 4879 | try sema.storePtr2(block, init_src, union_ptr, init_src, union_init, init_src, .store); |
| 4896 | return; | 4880 | return; |
| 4897 | } else if (try sema.typeRequiresComptime(union_ty)) { | 4881 | } else if (try sema.typeRequiresComptime(union_ty)) { |
| 4898 | return sema.failWithNeededComptime(block, field_ptr_data.src(), .{ | 4882 | return sema.failWithNeededComptime(block, block.nodeOffset(field_ptr_data.src_node), .{ |
| 4899 | .needed_comptime_reason = "initializer of comptime only union must be comptime-known", | 4883 | .needed_comptime_reason = "initializer of comptime only union must be comptime-known", |
| 4900 | }); | 4884 | }); |
| 4901 | } | 4885 | } |
| 4902 | if (init_ref) |v| try sema.validateRuntimeValue(block, field_ptr_data.src(), v); | 4886 | if (init_ref) |v| try sema.validateRuntimeValue(block, block.nodeOffset(field_ptr_data.src_node), v); |
| 4903 | | 4887 | |
| 4904 | const new_tag = Air.internedToRef(tag_val.toIntern()); | 4888 | const new_tag = Air.internedToRef(tag_val.toIntern()); |
| 4905 | const set_tag_inst = try block.addBinOp(.set_union_tag, union_ptr, new_tag); | 4889 | const set_tag_inst = try block.addBinOp(.set_union_tag, union_ptr, new_tag); |
| 4906 | try sema.checkComptimeKnownStore(block, set_tag_inst, .unneeded); // `unneeded` since this isn't a "proper" store | 4890 | try sema.checkComptimeKnownStore(block, set_tag_inst, LazySrcLoc.unneeded); // `unneeded` since this isn't a "proper" store |
| 4907 | } | 4891 | } |
| 4908 | | 4892 | |
| 4909 | fn validateStructInit( | 4893 | fn validateStructInit( |
| ... | @@ -4929,7 +4913,7 @@ fn validateStructInit( | ... | @@ -4929,7 +4913,7 @@ fn validateStructInit( |
| 4929 | | 4913 | |
| 4930 | for (instrs, field_indices) |field_ptr, *field_index| { | 4914 | for (instrs, field_indices) |field_ptr, *field_index| { |
| 4931 | const field_ptr_data = sema.code.instructions.items(.data)[@intFromEnum(field_ptr)].pl_node; | 4915 | const field_ptr_data = sema.code.instructions.items(.data)[@intFromEnum(field_ptr)].pl_node; |
| 4932 | const field_src: LazySrcLoc = .{ .node_offset_initializer = field_ptr_data.src_node }; | 4916 | const field_src = block.src(.{ .node_offset_initializer = field_ptr_data.src_node }); |
| 4933 | const field_ptr_extra = sema.code.extraData(Zir.Inst.Field, field_ptr_data.payload_index).data; | 4917 | const field_ptr_extra = sema.code.extraData(Zir.Inst.Field, field_ptr_data.payload_index).data; |
| 4934 | struct_ptr_zir_ref = field_ptr_extra.lhs; | 4918 | struct_ptr_zir_ref = field_ptr_extra.lhs; |
| 4935 | const field_name = try ip.getOrPutString( | 4919 | const field_name = try ip.getOrPutString( |
| ... | @@ -4966,18 +4950,18 @@ fn validateStructInit( | ... | @@ -4966,18 +4950,18 @@ fn validateStructInit( |
| 4966 | const field_name = struct_ty.structFieldName(i, mod).unwrap() orelse { | 4950 | const field_name = struct_ty.structFieldName(i, mod).unwrap() orelse { |
| 4967 | const template = "missing tuple field with index {d}"; | 4951 | const template = "missing tuple field with index {d}"; |
| 4968 | if (root_msg) |msg| { | 4952 | if (root_msg) |msg| { |
| 4969 | try sema.errNote(block, init_src, msg, template, .{i}); | 4953 | try sema.errNote(init_src, msg, template, .{i}); |
| 4970 | } else { | 4954 | } else { |
| 4971 | root_msg = try sema.errMsg(block, init_src, template, .{i}); | 4955 | root_msg = try sema.errMsg(init_src, template, .{i}); |
| 4972 | } | 4956 | } |
| 4973 | continue; | 4957 | continue; |
| 4974 | }; | 4958 | }; |
| 4975 | const template = "missing struct field: {}"; | 4959 | const template = "missing struct field: {}"; |
| 4976 | const args = .{field_name.fmt(ip)}; | 4960 | const args = .{field_name.fmt(ip)}; |
| 4977 | if (root_msg) |msg| { | 4961 | if (root_msg) |msg| { |
| 4978 | try sema.errNote(block, init_src, msg, template, args); | 4962 | try sema.errNote(init_src, msg, template, args); |
| 4979 | } else { | 4963 | } else { |
| 4980 | root_msg = try sema.errMsg(block, init_src, template, args); | 4964 | root_msg = try sema.errMsg(init_src, template, args); |
| 4981 | } | 4965 | } |
| 4982 | continue; | 4966 | continue; |
| 4983 | } | 4967 | } |
| ... | @@ -4992,16 +4976,7 @@ fn validateStructInit( | ... | @@ -4992,16 +4976,7 @@ fn validateStructInit( |
| 4992 | } | 4976 | } |
| 4993 | | 4977 | |
| 4994 | if (root_msg) |msg| { | 4978 | if (root_msg) |msg| { |
| 4995 | if (mod.typeToStruct(struct_ty)) |struct_type| { | 4979 | try sema.addDeclaredHereNote(msg, struct_ty); |
| 4996 | const decl = mod.declPtr(struct_type.decl.unwrap().?); | | |
| 4997 | const fqn = try decl.fullyQualifiedName(mod); | | |
| 4998 | try mod.errNoteNonLazy( | | |
| 4999 | decl.srcLoc(mod), | | |
| 5000 | msg, | | |
| 5001 | "struct '{}' declared here", | | |
| 5002 | .{fqn.fmt(ip)}, | | |
| 5003 | ); | | |
| 5004 | } | | |
| 5005 | root_msg = null; | 4980 | root_msg = null; |
| 5006 | return sema.failWithOwnedErrorMsg(block, msg); | 4981 | return sema.failWithOwnedErrorMsg(block, msg); |
| 5007 | } | 4982 | } |
| ... | @@ -5086,7 +5061,7 @@ fn validateStructInit( | ... | @@ -5086,7 +5061,7 @@ fn validateStructInit( |
| 5086 | field_values[i] = val.toIntern(); | 5061 | field_values[i] = val.toIntern(); |
| 5087 | } else if (require_comptime) { | 5062 | } else if (require_comptime) { |
| 5088 | const field_ptr_data = sema.code.instructions.items(.data)[@intFromEnum(field_ptr)].pl_node; | 5063 | const field_ptr_data = sema.code.instructions.items(.data)[@intFromEnum(field_ptr)].pl_node; |
| 5089 | return sema.failWithNeededComptime(block, field_ptr_data.src(), .{ | 5064 | return sema.failWithNeededComptime(block, block.nodeOffset(field_ptr_data.src_node), .{ |
| 5090 | .needed_comptime_reason = "initializer of comptime only struct must be comptime-known", | 5065 | .needed_comptime_reason = "initializer of comptime only struct must be comptime-known", |
| 5091 | }); | 5066 | }); |
| 5092 | } else { | 5067 | } else { |
| ... | @@ -5103,18 +5078,18 @@ fn validateStructInit( | ... | @@ -5103,18 +5078,18 @@ fn validateStructInit( |
| 5103 | const field_name = struct_ty.structFieldName(i, mod).unwrap() orelse { | 5078 | const field_name = struct_ty.structFieldName(i, mod).unwrap() orelse { |
| 5104 | const template = "missing tuple field with index {d}"; | 5079 | const template = "missing tuple field with index {d}"; |
| 5105 | if (root_msg) |msg| { | 5080 | if (root_msg) |msg| { |
| 5106 | try sema.errNote(block, init_src, msg, template, .{i}); | 5081 | try sema.errNote(init_src, msg, template, .{i}); |
| 5107 | } else { | 5082 | } else { |
| 5108 | root_msg = try sema.errMsg(block, init_src, template, .{i}); | 5083 | root_msg = try sema.errMsg(init_src, template, .{i}); |
| 5109 | } | 5084 | } |
| 5110 | continue; | 5085 | continue; |
| 5111 | }; | 5086 | }; |
| 5112 | const template = "missing struct field: {}"; | 5087 | const template = "missing struct field: {}"; |
| 5113 | const args = .{field_name.fmt(ip)}; | 5088 | const args = .{field_name.fmt(ip)}; |
| 5114 | if (root_msg) |msg| { | 5089 | if (root_msg) |msg| { |
| 5115 | try sema.errNote(block, init_src, msg, template, args); | 5090 | try sema.errNote(init_src, msg, template, args); |
| 5116 | } else { | 5091 | } else { |
| 5117 | root_msg = try sema.errMsg(block, init_src, template, args); | 5092 | root_msg = try sema.errMsg(init_src, template, args); |
| 5118 | } | 5093 | } |
| 5119 | continue; | 5094 | continue; |
| 5120 | } | 5095 | } |
| ... | @@ -5122,21 +5097,12 @@ fn validateStructInit( | ... | @@ -5122,21 +5097,12 @@ fn validateStructInit( |
| 5122 | } | 5097 | } |
| 5123 | | 5098 | |
| 5124 | if (!struct_is_comptime and !fields_allow_runtime and root_msg == null) { | 5099 | if (!struct_is_comptime and !fields_allow_runtime and root_msg == null) { |
| 5125 | root_msg = try sema.errMsg(block, init_src, "runtime value contains reference to comptime var", .{}); | 5100 | root_msg = try sema.errMsg(init_src, "runtime value contains reference to comptime var", .{}); |
| 5126 | try sema.errNote(block, init_src, root_msg.?, "comptime var pointers are not available at runtime", .{}); | 5101 | try sema.errNote(init_src, root_msg.?, "comptime var pointers are not available at runtime", .{}); |
| 5127 | } | 5102 | } |
| 5128 | | 5103 | |
| 5129 | if (root_msg) |msg| { | 5104 | if (root_msg) |msg| { |
| 5130 | if (mod.typeToStruct(struct_ty)) |struct_type| { | 5105 | try sema.addDeclaredHereNote(msg, struct_ty); |
| 5131 | const decl = mod.declPtr(struct_type.decl.unwrap().?); | | |
| 5132 | const fqn = try decl.fullyQualifiedName(mod); | | |
| 5133 | try mod.errNoteNonLazy( | | |
| 5134 | decl.srcLoc(mod), | | |
| 5135 | msg, | | |
| 5136 | "struct '{}' declared here", | | |
| 5137 | .{fqn.fmt(ip)}, | | |
| 5138 | ); | | |
| 5139 | } | | |
| 5140 | root_msg = null; | 5106 | root_msg = null; |
| 5141 | return sema.failWithOwnedErrorMsg(block, msg); | 5107 | return sema.failWithOwnedErrorMsg(block, msg); |
| 5142 | } | 5108 | } |
| ... | @@ -5210,7 +5176,7 @@ fn zirValidatePtrArrayInit( | ... | @@ -5210,7 +5176,7 @@ fn zirValidatePtrArrayInit( |
| 5210 | ) CompileError!void { | 5176 | ) CompileError!void { |
| 5211 | const mod = sema.mod; | 5177 | const mod = sema.mod; |
| 5212 | const validate_inst = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 5178 | const validate_inst = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 5213 | const init_src = validate_inst.src(); | 5179 | const init_src = block.nodeOffset(validate_inst.src_node); |
| 5214 | const validate_extra = sema.code.extraData(Zir.Inst.Block, validate_inst.payload_index); | 5180 | const validate_extra = sema.code.extraData(Zir.Inst.Block, validate_inst.payload_index); |
| 5215 | const instrs = sema.code.bodySlice(validate_extra.end, validate_extra.data.body_len); | 5181 | const instrs = sema.code.bodySlice(validate_extra.end, validate_extra.data.body_len); |
| 5216 | const first_elem_ptr_data = sema.code.instructions.items(.data)[@intFromEnum(instrs[0])].pl_node; | 5182 | const first_elem_ptr_data = sema.code.instructions.items(.data)[@intFromEnum(instrs[0])].pl_node; |
| ... | @@ -5238,9 +5204,9 @@ fn zirValidatePtrArrayInit( | ... | @@ -5238,9 +5204,9 @@ fn zirValidatePtrArrayInit( |
| 5238 | if (default_val == .unreachable_value) { | 5204 | if (default_val == .unreachable_value) { |
| 5239 | const template = "missing tuple field with index {d}"; | 5205 | const template = "missing tuple field with index {d}"; |
| 5240 | if (root_msg) |msg| { | 5206 | if (root_msg) |msg| { |
| 5241 | try sema.errNote(block, init_src, msg, template, .{i}); | 5207 | try sema.errNote(init_src, msg, template, .{i}); |
| 5242 | } else { | 5208 | } else { |
| 5243 | root_msg = try sema.errMsg(block, init_src, template, .{i}); | 5209 | root_msg = try sema.errMsg(init_src, template, .{i}); |
| 5244 | } | 5210 | } |
| 5245 | continue; | 5211 | continue; |
| 5246 | } | 5212 | } |
| ... | @@ -5415,7 +5381,7 @@ fn zirValidatePtrArrayInit( | ... | @@ -5415,7 +5381,7 @@ fn zirValidatePtrArrayInit( |
| 5415 | fn zirValidateDeref(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void { | 5381 | fn zirValidateDeref(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void { |
| 5416 | const mod = sema.mod; | 5382 | const mod = sema.mod; |
| 5417 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; | 5383 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 5418 | const src = inst_data.src(); | 5384 | const src = block.nodeOffset(inst_data.src_node); |
| 5419 | const operand = try sema.resolveInst(inst_data.operand); | 5385 | const operand = try sema.resolveInst(inst_data.operand); |
| 5420 | const operand_ty = sema.typeOf(operand); | 5386 | const operand_ty = sema.typeOf(operand); |
| 5421 | | 5387 | |
| ... | @@ -5440,15 +5406,13 @@ fn zirValidateDeref(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr | ... | @@ -5440,15 +5406,13 @@ fn zirValidateDeref(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr |
| 5440 | } else if (try sema.typeRequiresComptime(elem_ty)) { | 5406 | } else if (try sema.typeRequiresComptime(elem_ty)) { |
| 5441 | const msg = msg: { | 5407 | const msg = msg: { |
| 5442 | const msg = try sema.errMsg( | 5408 | const msg = try sema.errMsg( |
| 5443 | block, | | |
| 5444 | src, | 5409 | src, |
| 5445 | "values of type '{}' must be comptime-known, but operand value is runtime-known", | 5410 | "values of type '{}' must be comptime-known, but operand value is runtime-known", |
| 5446 | .{elem_ty.fmt(mod)}, | 5411 | .{elem_ty.fmt(mod)}, |
| 5447 | ); | 5412 | ); |
| 5448 | errdefer msg.destroy(sema.gpa); | 5413 | errdefer msg.destroy(sema.gpa); |
| 5449 | | 5414 | |
| 5450 | const src_decl = mod.declPtr(block.src_decl); | 5415 | try sema.explainWhyTypeIsComptime(msg, src, elem_ty); |
| 5451 | try sema.explainWhyTypeIsComptime(msg, src_decl.toSrcLoc(src, mod), elem_ty); | | |
| 5452 | break :msg msg; | 5416 | break :msg msg; |
| 5453 | }; | 5417 | }; |
| 5454 | return sema.failWithOwnedErrorMsg(block, msg); | 5418 | return sema.failWithOwnedErrorMsg(block, msg); |
| ... | @@ -5459,8 +5423,8 @@ fn zirValidateDestructure(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp | ... | @@ -5459,8 +5423,8 @@ fn zirValidateDestructure(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp |
| 5459 | const mod = sema.mod; | 5423 | const mod = sema.mod; |
| 5460 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 5424 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 5461 | const extra = sema.code.extraData(Zir.Inst.ValidateDestructure, inst_data.payload_index).data; | 5425 | const extra = sema.code.extraData(Zir.Inst.ValidateDestructure, inst_data.payload_index).data; |
| 5462 | const src = inst_data.src(); | 5426 | const src = block.nodeOffset(inst_data.src_node); |
| 5463 | const destructure_src = LazySrcLoc.nodeOffset(extra.destructure_node); | 5427 | const destructure_src = block.nodeOffset(extra.destructure_node); |
| 5464 | const operand = try sema.resolveInst(extra.operand); | 5428 | const operand = try sema.resolveInst(extra.operand); |
| 5465 | const operand_ty = sema.typeOf(operand); | 5429 | const operand_ty = sema.typeOf(operand); |
| 5466 | | 5430 | |
| ... | @@ -5472,21 +5436,21 @@ fn zirValidateDestructure(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp | ... | @@ -5472,21 +5436,21 @@ fn zirValidateDestructure(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp |
| 5472 | | 5436 | |
| 5473 | if (!can_destructure) { | 5437 | if (!can_destructure) { |
| 5474 | return sema.failWithOwnedErrorMsg(block, msg: { | 5438 | return sema.failWithOwnedErrorMsg(block, msg: { |
| 5475 | const msg = try sema.errMsg(block, src, "type '{}' cannot be destructured", .{operand_ty.fmt(mod)}); | 5439 | const msg = try sema.errMsg(src, "type '{}' cannot be destructured", .{operand_ty.fmt(mod)}); |
| 5476 | errdefer msg.destroy(sema.gpa); | 5440 | errdefer msg.destroy(sema.gpa); |
| 5477 | try sema.errNote(block, destructure_src, msg, "result destructured here", .{}); | 5441 | try sema.errNote(destructure_src, msg, "result destructured here", .{}); |
| 5478 | break :msg msg; | 5442 | break :msg msg; |
| 5479 | }); | 5443 | }); |
| 5480 | } | 5444 | } |
| 5481 | | 5445 | |
| 5482 | if (operand_ty.arrayLen(mod) != extra.expect_len) { | 5446 | if (operand_ty.arrayLen(mod) != extra.expect_len) { |
| 5483 | return sema.failWithOwnedErrorMsg(block, msg: { | 5447 | return sema.failWithOwnedErrorMsg(block, msg: { |
| 5484 | const msg = try sema.errMsg(block, src, "expected {} elements for destructure, found {}", .{ | 5448 | const msg = try sema.errMsg(src, "expected {} elements for destructure, found {}", .{ |
| 5485 | extra.expect_len, | 5449 | extra.expect_len, |
| 5486 | operand_ty.arrayLen(mod), | 5450 | operand_ty.arrayLen(mod), |
| 5487 | }); | 5451 | }); |
| 5488 | errdefer msg.destroy(sema.gpa); | 5452 | errdefer msg.destroy(sema.gpa); |
| 5489 | try sema.errNote(block, destructure_src, msg, "result destructured here", .{}); | 5453 | try sema.errNote(destructure_src, msg, "result destructured here", .{}); |
| 5490 | break :msg msg; | 5454 | break :msg msg; |
| 5491 | }); | 5455 | }); |
| 5492 | } | 5456 | } |
| ... | @@ -5521,24 +5485,24 @@ fn failWithBadMemberAccess( | ... | @@ -5521,24 +5485,24 @@ fn failWithBadMemberAccess( |
| 5521 | fn failWithBadStructFieldAccess( | 5485 | fn failWithBadStructFieldAccess( |
| 5522 | sema: *Sema, | 5486 | sema: *Sema, |
| 5523 | block: *Block, | 5487 | block: *Block, |
| | 5488 | struct_ty: Type, |
| 5524 | struct_type: InternPool.LoadedStructType, | 5489 | struct_type: InternPool.LoadedStructType, |
| 5525 | field_src: LazySrcLoc, | 5490 | field_src: LazySrcLoc, |
| 5526 | field_name: InternPool.NullTerminatedString, | 5491 | field_name: InternPool.NullTerminatedString, |
| 5527 | ) CompileError { | 5492 | ) CompileError { |
| 5528 | const mod = sema.mod; | 5493 | const zcu = sema.mod; |
| 5529 | const gpa = sema.gpa; | 5494 | const gpa = sema.gpa; |
| 5530 | const decl = mod.declPtr(struct_type.decl.unwrap().?); | 5495 | const decl = zcu.declPtr(struct_type.decl.unwrap().?); |
| 5531 | const fqn = try decl.fullyQualifiedName(mod); | 5496 | const fqn = try decl.fullyQualifiedName(zcu); |
| 5532 | | 5497 | |
| 5533 | const msg = msg: { | 5498 | const msg = msg: { |
| 5534 | const msg = try sema.errMsg( | 5499 | const msg = try sema.errMsg( |
| 5535 | block, | | |
| 5536 | field_src, | 5500 | field_src, |
| 5537 | "no field named '{}' in struct '{}'", | 5501 | "no field named '{}' in struct '{}'", |
| 5538 | .{ field_name.fmt(&mod.intern_pool), fqn.fmt(&mod.intern_pool) }, | 5502 | .{ field_name.fmt(&zcu.intern_pool), fqn.fmt(&zcu.intern_pool) }, |
| 5539 | ); | 5503 | ); |
| 5540 | errdefer msg.destroy(gpa); | 5504 | errdefer msg.destroy(gpa); |
| 5541 | try mod.errNoteNonLazy(decl.srcLoc(mod), msg, "struct declared here", .{}); | 5505 | try sema.errNote(struct_ty.srcLoc(zcu), msg, "struct declared here", .{}); |
| 5542 | break :msg msg; | 5506 | break :msg msg; |
| 5543 | }; | 5507 | }; |
| 5544 | return sema.failWithOwnedErrorMsg(block, msg); | 5508 | return sema.failWithOwnedErrorMsg(block, msg); |
| ... | @@ -5547,25 +5511,25 @@ fn failWithBadStructFieldAccess( | ... | @@ -5547,25 +5511,25 @@ fn failWithBadStructFieldAccess( |
| 5547 | fn failWithBadUnionFieldAccess( | 5511 | fn failWithBadUnionFieldAccess( |
| 5548 | sema: *Sema, | 5512 | sema: *Sema, |
| 5549 | block: *Block, | 5513 | block: *Block, |
| | 5514 | union_ty: Type, |
| 5550 | union_obj: InternPool.LoadedUnionType, | 5515 | union_obj: InternPool.LoadedUnionType, |
| 5551 | field_src: LazySrcLoc, | 5516 | field_src: LazySrcLoc, |
| 5552 | field_name: InternPool.NullTerminatedString, | 5517 | field_name: InternPool.NullTerminatedString, |
| 5553 | ) CompileError { | 5518 | ) CompileError { |
| 5554 | const mod = sema.mod; | 5519 | const zcu = sema.mod; |
| 5555 | const gpa = sema.gpa; | 5520 | const gpa = sema.gpa; |
| 5556 | | 5521 | |
| 5557 | const decl = mod.declPtr(union_obj.decl); | 5522 | const decl = zcu.declPtr(union_obj.decl); |
| 5558 | const fqn = try decl.fullyQualifiedName(mod); | 5523 | const fqn = try decl.fullyQualifiedName(zcu); |
| 5559 | | 5524 | |
| 5560 | const msg = msg: { | 5525 | const msg = msg: { |
| 5561 | const msg = try sema.errMsg( | 5526 | const msg = try sema.errMsg( |
| 5562 | block, | | |
| 5563 | field_src, | 5527 | field_src, |
| 5564 | "no field named '{}' in union '{}'", | 5528 | "no field named '{}' in union '{}'", |
| 5565 | .{ field_name.fmt(&mod.intern_pool), fqn.fmt(&mod.intern_pool) }, | 5529 | .{ field_name.fmt(&zcu.intern_pool), fqn.fmt(&zcu.intern_pool) }, |
| 5566 | ); | 5530 | ); |
| 5567 | errdefer msg.destroy(gpa); | 5531 | errdefer msg.destroy(gpa); |
| 5568 | try mod.errNoteNonLazy(decl.srcLoc(mod), msg, "union declared here", .{}); | 5532 | try sema.errNote(union_ty.srcLoc(zcu), msg, "union declared here", .{}); |
| 5569 | break :msg msg; | 5533 | break :msg msg; |
| 5570 | }; | 5534 | }; |
| 5571 | return sema.failWithOwnedErrorMsg(block, msg); | 5535 | return sema.failWithOwnedErrorMsg(block, msg); |
| ... | @@ -5573,16 +5537,15 @@ fn failWithBadUnionFieldAccess( | ... | @@ -5573,16 +5537,15 @@ fn failWithBadUnionFieldAccess( |
| 5573 | | 5537 | |
| 5574 | fn addDeclaredHereNote(sema: *Sema, parent: *Module.ErrorMsg, decl_ty: Type) !void { | 5538 | fn addDeclaredHereNote(sema: *Sema, parent: *Module.ErrorMsg, decl_ty: Type) !void { |
| 5575 | const mod = sema.mod; | 5539 | const mod = sema.mod; |
| 5576 | const src_loc = decl_ty.declSrcLocOrNull(mod) orelse return; | 5540 | const src_loc = decl_ty.srcLocOrNull(mod) orelse return; |
| 5577 | const category = switch (decl_ty.zigTypeTag(mod)) { | 5541 | const category = switch (decl_ty.zigTypeTag(mod)) { |
| 5578 | .Union => "union", | 5542 | .Union => "union", |
| 5579 | .Struct => "struct", | 5543 | .Struct => "struct", |
| 5580 | .Enum => "enum", | 5544 | .Enum => "enum", |
| 5581 | .Opaque => "opaque", | 5545 | .Opaque => "opaque", |
| 5582 | .ErrorSet => "error set", | | |
| 5583 | else => unreachable, | 5546 | else => unreachable, |
| 5584 | }; | 5547 | }; |
| 5585 | try mod.errNoteNonLazy(src_loc, parent, "{s} declared here", .{category}); | 5548 | try sema.errNote(src_loc, parent, "{s} declared here", .{category}); |
| 5586 | } | 5549 | } |
| 5587 | | 5550 | |
| 5588 | fn zirStoreToInferredPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void { | 5551 | fn zirStoreToInferredPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void { |
| ... | @@ -5590,7 +5553,7 @@ fn zirStoreToInferredPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compi | ... | @@ -5590,7 +5553,7 @@ fn zirStoreToInferredPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compi |
| 5590 | defer tracy.end(); | 5553 | defer tracy.end(); |
| 5591 | | 5554 | |
| 5592 | const pl_node = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 5555 | const pl_node = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 5593 | const src = pl_node.src(); | 5556 | const src = block.nodeOffset(pl_node.src_node); |
| 5594 | const bin = sema.code.extraData(Zir.Inst.Bin, pl_node.payload_index).data; | 5557 | const bin = sema.code.extraData(Zir.Inst.Bin, pl_node.payload_index).data; |
| 5595 | const ptr = try sema.resolveInst(bin.lhs); | 5558 | const ptr = try sema.resolveInst(bin.lhs); |
| 5596 | const operand = try sema.resolveInst(bin.rhs); | 5559 | const operand = try sema.resolveInst(bin.rhs); |
| ... | @@ -5672,7 +5635,7 @@ fn storeToInferredAllocComptime( | ... | @@ -5672,7 +5635,7 @@ fn storeToInferredAllocComptime( |
| 5672 | | 5635 | |
| 5673 | fn zirSetEvalBranchQuota(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void { | 5636 | fn zirSetEvalBranchQuota(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void { |
| 5674 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; | 5637 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 5675 | const src = inst_data.src(); | 5638 | const src = block.nodeOffset(inst_data.src_node); |
| 5676 | const quota: u32 = @intCast(try sema.resolveInt(block, src, inst_data.operand, Type.u32, .{ | 5639 | const quota: u32 = @intCast(try sema.resolveInt(block, src, inst_data.operand, Type.u32, .{ |
| 5677 | .needed_comptime_reason = "eval branch quota must be comptime-known", | 5640 | .needed_comptime_reason = "eval branch quota must be comptime-known", |
| 5678 | })); | 5641 | })); |
| ... | @@ -5687,7 +5650,7 @@ fn zirStoreNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!v | ... | @@ -5687,7 +5650,7 @@ fn zirStoreNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!v |
| 5687 | const zir_tags = sema.code.instructions.items(.tag); | 5650 | const zir_tags = sema.code.instructions.items(.tag); |
| 5688 | const zir_datas = sema.code.instructions.items(.data); | 5651 | const zir_datas = sema.code.instructions.items(.data); |
| 5689 | const inst_data = zir_datas[@intFromEnum(inst)].pl_node; | 5652 | const inst_data = zir_datas[@intFromEnum(inst)].pl_node; |
| 5690 | const src = inst_data.src(); | 5653 | const src = block.nodeOffset(inst_data.src_node); |
| 5691 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; | 5654 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 5692 | const ptr = try sema.resolveInst(extra.lhs); | 5655 | const ptr = try sema.resolveInst(extra.lhs); |
| 5693 | const operand = try sema.resolveInst(extra.rhs); | 5656 | const operand = try sema.resolveInst(extra.rhs); |
| ... | @@ -5707,8 +5670,8 @@ fn zirStoreNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!v | ... | @@ -5707,8 +5670,8 @@ fn zirStoreNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!v |
| 5707 | else => {}, | 5670 | else => {}, |
| 5708 | }; | 5671 | }; |
| 5709 | | 5672 | |
| 5710 | const ptr_src: LazySrcLoc = .{ .node_offset_store_ptr = inst_data.src_node }; | 5673 | const ptr_src = block.src(.{ .node_offset_store_ptr = inst_data.src_node }); |
| 5711 | const operand_src: LazySrcLoc = .{ .node_offset_store_operand = inst_data.src_node }; | 5674 | const operand_src = block.src(.{ .node_offset_store_operand = inst_data.src_node }); |
| 5712 | const air_tag: Air.Inst.Tag = if (is_ret) | 5675 | const air_tag: Air.Inst.Tag = if (is_ret) |
| 5713 | .ret_ptr | 5676 | .ret_ptr |
| 5714 | else if (block.wantSafety()) | 5677 | else if (block.wantSafety()) |
| ... | @@ -5821,8 +5784,8 @@ fn zirCompileError(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro | ... | @@ -5821,8 +5784,8 @@ fn zirCompileError(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro |
| 5821 | defer tracy.end(); | 5784 | defer tracy.end(); |
| 5822 | | 5785 | |
| 5823 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; | 5786 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 5824 | const src = inst_data.src(); | 5787 | const src = block.nodeOffset(inst_data.src_node); |
| 5825 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 5788 | const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0); |
| 5826 | const msg = try sema.resolveConstString(block, operand_src, inst_data.operand, .{ | 5789 | const msg = try sema.resolveConstString(block, operand_src, inst_data.operand, .{ |
| 5827 | .needed_comptime_reason = "compile error string must be comptime-known", | 5790 | .needed_comptime_reason = "compile error string must be comptime-known", |
| 5828 | }); | 5791 | }); |
| ... | @@ -5831,6 +5794,7 @@ fn zirCompileError(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro | ... | @@ -5831,6 +5794,7 @@ fn zirCompileError(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro |
| 5831 | | 5794 | |
| 5832 | fn zirCompileLog( | 5795 | fn zirCompileLog( |
| 5833 | sema: *Sema, | 5796 | sema: *Sema, |
| | 5797 | block: *Block, |
| 5834 | extended: Zir.Inst.Extended.InstData, | 5798 | extended: Zir.Inst.Extended.InstData, |
| 5835 | ) CompileError!Air.Inst.Ref { | 5799 | ) CompileError!Air.Inst.Ref { |
| 5836 | const mod = sema.mod; | 5800 | const mod = sema.mod; |
| ... | @@ -5863,20 +5827,21 @@ fn zirCompileLog( | ... | @@ -5863,20 +5827,21 @@ fn zirCompileLog( |
| 5863 | else | 5827 | else |
| 5864 | sema.owner_decl_index; | 5828 | sema.owner_decl_index; |
| 5865 | const gop = try mod.compile_log_decls.getOrPut(sema.gpa, decl_index); | 5829 | const gop = try mod.compile_log_decls.getOrPut(sema.gpa, decl_index); |
| 5866 | if (!gop.found_existing) { | 5830 | if (!gop.found_existing) gop.value_ptr.* = .{ |
| 5867 | gop.value_ptr.* = src_node; | 5831 | .base_node_inst = block.src_base_inst, |
| 5868 | } | 5832 | .node_offset = src_node, |
| | 5833 | }; |
| 5869 | return .void_value; | 5834 | return .void_value; |
| 5870 | } | 5835 | } |
| 5871 | | 5836 | |
| 5872 | fn zirPanic(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void { | 5837 | fn zirPanic(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void { |
| 5873 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; | 5838 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 5874 | const src = inst_data.src(); | 5839 | const src = block.nodeOffset(inst_data.src_node); |
| 5875 | const msg_inst = try sema.resolveInst(inst_data.operand); | 5840 | const msg_inst = try sema.resolveInst(inst_data.operand); |
| 5876 | | 5841 | |
| 5877 | // `panicWithMsg` would perform this coercion for us, but we can get a better | 5842 | // `panicWithMsg` would perform this coercion for us, but we can get a better |
| 5878 | // source location if we do it here. | 5843 | // source location if we do it here. |
| 5879 | const coerced_msg = try sema.coerce(block, Type.slice_const_u8, msg_inst, .{ .node_offset_builtin_call_arg0 = inst_data.src_node }); | 5844 | const coerced_msg = try sema.coerce(block, Type.slice_const_u8, msg_inst, block.builtinCallArgSrc(inst_data.src_node, 0)); |
| 5880 | | 5845 | |
| 5881 | if (block.is_comptime) { | 5846 | if (block.is_comptime) { |
| 5882 | return sema.fail(block, src, "encountered @panic at comptime", .{}); | 5847 | return sema.fail(block, src, "encountered @panic at comptime", .{}); |
| ... | @@ -5886,7 +5851,7 @@ fn zirPanic(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void | ... | @@ -5886,7 +5851,7 @@ fn zirPanic(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void |
| 5886 | | 5851 | |
| 5887 | fn zirTrap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void { | 5852 | fn zirTrap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void { |
| 5888 | const src_node = sema.code.instructions.items(.data)[@intFromEnum(inst)].node; | 5853 | const src_node = sema.code.instructions.items(.data)[@intFromEnum(inst)].node; |
| 5889 | const src = LazySrcLoc.nodeOffset(src_node); | 5854 | const src = block.nodeOffset(src_node); |
| 5890 | if (block.is_comptime) | 5855 | if (block.is_comptime) |
| 5891 | return sema.fail(block, src, "encountered @trap at comptime", .{}); | 5856 | return sema.fail(block, src, "encountered @trap at comptime", .{}); |
| 5892 | _ = try block.addNoOp(.trap); | 5857 | _ = try block.addNoOp(.trap); |
| ... | @@ -5898,7 +5863,7 @@ fn zirLoop(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError | ... | @@ -5898,7 +5863,7 @@ fn zirLoop(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError |
| 5898 | | 5863 | |
| 5899 | const mod = sema.mod; | 5864 | const mod = sema.mod; |
| 5900 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 5865 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 5901 | const src = inst_data.src(); | 5866 | const src = parent_block.nodeOffset(inst_data.src_node); |
| 5902 | const extra = sema.code.extraData(Zir.Inst.Block, inst_data.payload_index); | 5867 | const extra = sema.code.extraData(Zir.Inst.Block, inst_data.payload_index); |
| 5903 | const body = sema.code.bodySlice(extra.end, extra.data.body_len); | 5868 | const body = sema.code.bodySlice(extra.end, extra.data.body_len); |
| 5904 | const gpa = sema.gpa; | 5869 | const gpa = sema.gpa; |
| ... | @@ -5933,7 +5898,7 @@ fn zirLoop(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError | ... | @@ -5933,7 +5898,7 @@ fn zirLoop(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError |
| 5933 | var child_block = parent_block.makeSubBlock(); | 5898 | var child_block = parent_block.makeSubBlock(); |
| 5934 | child_block.label = &label; | 5899 | child_block.label = &label; |
| 5935 | child_block.runtime_cond = null; | 5900 | child_block.runtime_cond = null; |
| 5936 | child_block.runtime_loop = mod.declPtr(child_block.src_decl).toSrcLoc(src, mod); | 5901 | child_block.runtime_loop = src; |
| 5937 | child_block.runtime_index.increment(); | 5902 | child_block.runtime_index.increment(); |
| 5938 | const merges = &child_block.label.?.merges; | 5903 | const merges = &child_block.label.?.merges; |
| 5939 | | 5904 | |
| ... | @@ -5971,7 +5936,7 @@ fn zirCImport(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileEr | ... | @@ -5971,7 +5936,7 @@ fn zirCImport(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileEr |
| 5971 | const comp = mod.comp; | 5936 | const comp = mod.comp; |
| 5972 | const gpa = sema.gpa; | 5937 | const gpa = sema.gpa; |
| 5973 | const pl_node = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 5938 | const pl_node = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 5974 | const src = pl_node.src(); | 5939 | const src = parent_block.nodeOffset(pl_node.src_node); |
| 5975 | const extra = sema.code.extraData(Zir.Inst.Block, pl_node.payload_index); | 5940 | const extra = sema.code.extraData(Zir.Inst.Block, pl_node.payload_index); |
| 5976 | const body = sema.code.bodySlice(extra.end, extra.data.body_len); | 5941 | const body = sema.code.bodySlice(extra.end, extra.data.body_len); |
| 5977 | | 5942 | |
| ... | @@ -5982,14 +5947,10 @@ fn zirCImport(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileEr | ... | @@ -5982,14 +5947,10 @@ fn zirCImport(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileEr |
| 5982 | var c_import_buf = std.ArrayList(u8).init(gpa); | 5947 | var c_import_buf = std.ArrayList(u8).init(gpa); |
| 5983 | defer c_import_buf.deinit(); | 5948 | defer c_import_buf.deinit(); |
| 5984 | | 5949 | |
| 5985 | var comptime_reason: Block.ComptimeReason = .{ .c_import = .{ | 5950 | const comptime_reason: Block.ComptimeReason = .{ .c_import = .{ .src = src } }; |
| 5986 | .block = parent_block, | | |
| 5987 | .src = src, | | |
| 5988 | } }; | | |
| 5989 | var child_block: Block = .{ | 5951 | var child_block: Block = .{ |
| 5990 | .parent = parent_block, | 5952 | .parent = parent_block, |
| 5991 | .sema = sema, | 5953 | .sema = sema, |
| 5992 | .src_decl = parent_block.src_decl, | | |
| 5993 | .namespace = parent_block.namespace, | 5954 | .namespace = parent_block.namespace, |
| 5994 | .instructions = .{}, | 5955 | .instructions = .{}, |
| 5995 | .inlining = parent_block.inlining, | 5956 | .inlining = parent_block.inlining, |
| ... | @@ -5999,6 +5960,8 @@ fn zirCImport(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileEr | ... | @@ -5999,6 +5960,8 @@ fn zirCImport(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileEr |
| 5999 | .runtime_cond = parent_block.runtime_cond, | 5960 | .runtime_cond = parent_block.runtime_cond, |
| 6000 | .runtime_loop = parent_block.runtime_loop, | 5961 | .runtime_loop = parent_block.runtime_loop, |
| 6001 | .runtime_index = parent_block.runtime_index, | 5962 | .runtime_index = parent_block.runtime_index, |
| | 5963 | .src_base_inst = parent_block.src_base_inst, |
| | 5964 | .type_name_ctx = parent_block.type_name_ctx, |
| 6002 | }; | 5965 | }; |
| 6003 | defer child_block.instructions.deinit(gpa); | 5966 | defer child_block.instructions.deinit(gpa); |
| 6004 | | 5967 | |
| ... | @@ -6010,11 +5973,11 @@ fn zirCImport(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileEr | ... | @@ -6010,11 +5973,11 @@ fn zirCImport(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileEr |
| 6010 | | 5973 | |
| 6011 | if (c_import_res.errors.errorMessageCount() != 0) { | 5974 | if (c_import_res.errors.errorMessageCount() != 0) { |
| 6012 | const msg = msg: { | 5975 | const msg = msg: { |
| 6013 | const msg = try sema.errMsg(&child_block, src, "C import failed", .{}); | 5976 | const msg = try sema.errMsg(src, "C import failed", .{}); |
| 6014 | errdefer msg.destroy(gpa); | 5977 | errdefer msg.destroy(gpa); |
| 6015 | | 5978 | |
| 6016 | if (!comp.config.link_libc) | 5979 | if (!comp.config.link_libc) |
| 6017 | try sema.errNote(&child_block, src, msg, "libc headers not available; compilation does not link against libc", .{}); | 5980 | try sema.errNote(src, msg, "libc headers not available; compilation does not link against libc", .{}); |
| 6018 | | 5981 | |
| 6019 | const gop = try mod.cimport_errors.getOrPut(gpa, sema.owner_decl_index); | 5982 | const gop = try mod.cimport_errors.getOrPut(gpa, sema.owner_decl_index); |
| 6020 | if (!gop.found_existing) { | 5983 | if (!gop.found_existing) { |
| ... | @@ -6073,7 +6036,7 @@ fn zirCImport(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileEr | ... | @@ -6073,7 +6036,7 @@ fn zirCImport(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileEr |
| 6073 | | 6036 | |
| 6074 | fn zirSuspendBlock(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 6037 | fn zirSuspendBlock(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 6075 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 6038 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 6076 | const src = inst_data.src(); | 6039 | const src = parent_block.nodeOffset(inst_data.src_node); |
| 6077 | return sema.failWithUseOfAsync(parent_block, src); | 6040 | return sema.failWithUseOfAsync(parent_block, src); |
| 6078 | } | 6041 | } |
| 6079 | | 6042 | |
| ... | @@ -6082,7 +6045,7 @@ fn zirBlock(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index, force_compt | ... | @@ -6082,7 +6045,7 @@ fn zirBlock(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index, force_compt |
| 6082 | defer tracy.end(); | 6045 | defer tracy.end(); |
| 6083 | | 6046 | |
| 6084 | const pl_node = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 6047 | const pl_node = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 6085 | const src = pl_node.src(); | 6048 | const src = parent_block.nodeOffset(pl_node.src_node); |
| 6086 | const extra = sema.code.extraData(Zir.Inst.Block, pl_node.payload_index); | 6049 | const extra = sema.code.extraData(Zir.Inst.Block, pl_node.payload_index); |
| 6087 | const body = sema.code.bodySlice(extra.end, extra.data.body_len); | 6050 | const body = sema.code.bodySlice(extra.end, extra.data.body_len); |
| 6088 | const gpa = sema.gpa; | 6051 | const gpa = sema.gpa; |
| ... | @@ -6109,7 +6072,6 @@ fn zirBlock(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index, force_compt | ... | @@ -6109,7 +6072,6 @@ fn zirBlock(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index, force_compt |
| 6109 | var child_block: Block = .{ | 6072 | var child_block: Block = .{ |
| 6110 | .parent = parent_block, | 6073 | .parent = parent_block, |
| 6111 | .sema = sema, | 6074 | .sema = sema, |
| 6112 | .src_decl = parent_block.src_decl, | | |
| 6113 | .namespace = parent_block.namespace, | 6075 | .namespace = parent_block.namespace, |
| 6114 | .instructions = .{}, | 6076 | .instructions = .{}, |
| 6115 | .label = &label, | 6077 | .label = &label, |
| ... | @@ -6124,6 +6086,8 @@ fn zirBlock(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index, force_compt | ... | @@ -6124,6 +6086,8 @@ fn zirBlock(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index, force_compt |
| 6124 | .runtime_loop = parent_block.runtime_loop, | 6086 | .runtime_loop = parent_block.runtime_loop, |
| 6125 | .runtime_index = parent_block.runtime_index, | 6087 | .runtime_index = parent_block.runtime_index, |
| 6126 | .error_return_trace_index = parent_block.error_return_trace_index, | 6088 | .error_return_trace_index = parent_block.error_return_trace_index, |
| | 6089 | .src_base_inst = parent_block.src_base_inst, |
| | 6090 | .type_name_ctx = parent_block.type_name_ctx, |
| 6127 | }; | 6091 | }; |
| 6128 | | 6092 | |
| 6129 | defer child_block.instructions.deinit(gpa); | 6093 | defer child_block.instructions.deinit(gpa); |
| ... | @@ -6318,14 +6282,13 @@ fn resolveAnalyzedBlock( | ... | @@ -6318,14 +6282,13 @@ fn resolveAnalyzedBlock( |
| 6318 | const type_src = src; // TODO: better source location | 6282 | const type_src = src; // TODO: better source location |
| 6319 | if (try sema.typeRequiresComptime(resolved_ty)) { | 6283 | if (try sema.typeRequiresComptime(resolved_ty)) { |
| 6320 | const msg = msg: { | 6284 | const msg = msg: { |
| 6321 | const msg = try sema.errMsg(child_block, type_src, "value with comptime-only type '{}' depends on runtime control flow", .{resolved_ty.fmt(mod)}); | 6285 | const msg = try sema.errMsg(type_src, "value with comptime-only type '{}' depends on runtime control flow", .{resolved_ty.fmt(mod)}); |
| 6322 | errdefer msg.destroy(sema.gpa); | 6286 | errdefer msg.destroy(sema.gpa); |
| 6323 | | 6287 | |
| 6324 | const runtime_src = child_block.runtime_cond orelse child_block.runtime_loop.?; | 6288 | const runtime_src = child_block.runtime_cond orelse child_block.runtime_loop.?; |
| 6325 | try mod.errNoteNonLazy(runtime_src, msg, "runtime control flow here", .{}); | 6289 | try sema.errNote(runtime_src, msg, "runtime control flow here", .{}); |
| 6326 | | 6290 | |
| 6327 | const child_src_decl = mod.declPtr(child_block.src_decl); | 6291 | try sema.explainWhyTypeIsComptime(msg, type_src, resolved_ty); |
| 6328 | try sema.explainWhyTypeIsComptime(msg, child_src_decl.toSrcLoc(type_src, mod), resolved_ty); | | |
| 6329 | | 6292 | |
| 6330 | break :msg msg; | 6293 | break :msg msg; |
| 6331 | }; | 6294 | }; |
| ... | @@ -6417,9 +6380,9 @@ fn zirExport(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void | ... | @@ -6417,9 +6380,9 @@ fn zirExport(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void |
| 6417 | const mod = sema.mod; | 6380 | const mod = sema.mod; |
| 6418 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 6381 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 6419 | const extra = sema.code.extraData(Zir.Inst.Export, inst_data.payload_index).data; | 6382 | const extra = sema.code.extraData(Zir.Inst.Export, inst_data.payload_index).data; |
| 6420 | const src = inst_data.src(); | 6383 | const src = block.nodeOffset(inst_data.src_node); |
| 6421 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 6384 | const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0); |
| 6422 | const options_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; | 6385 | const options_src = block.builtinCallArgSrc(inst_data.src_node, 1); |
| 6423 | const decl_name = try mod.intern_pool.getOrPutString( | 6386 | const decl_name = try mod.intern_pool.getOrPutString( |
| 6424 | mod.gpa, | 6387 | mod.gpa, |
| 6425 | sema.code.nullTerminatedString(extra.decl_name), | 6388 | sema.code.nullTerminatedString(extra.decl_name), |
| ... | @@ -6433,13 +6396,7 @@ fn zirExport(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void | ... | @@ -6433,13 +6396,7 @@ fn zirExport(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void |
| 6433 | break :index_blk maybe_index orelse | 6396 | break :index_blk maybe_index orelse |
| 6434 | return sema.failWithBadMemberAccess(block, container_ty, operand_src, decl_name); | 6397 | return sema.failWithBadMemberAccess(block, container_ty, operand_src, decl_name); |
| 6435 | } else try sema.lookupIdentifier(block, operand_src, decl_name); | 6398 | } else try sema.lookupIdentifier(block, operand_src, decl_name); |
| 6436 | const options = sema.resolveExportOptions(block, .unneeded, extra.options) catch |err| switch (err) { | 6399 | const options = try sema.resolveExportOptions(block, options_src, extra.options); |
| 6437 | error.NeededSourceLocation => { | | |
| 6438 | _ = try sema.resolveExportOptions(block, options_src, extra.options); | | |
| 6439 | unreachable; | | |
| 6440 | }, | | |
| 6441 | else => |e| return e, | | |
| 6442 | }; | | |
| 6443 | { | 6400 | { |
| 6444 | try sema.ensureDeclAnalyzed(decl_index); | 6401 | try sema.ensureDeclAnalyzed(decl_index); |
| 6445 | const exported_decl = mod.declPtr(decl_index); | 6402 | const exported_decl = mod.declPtr(decl_index); |
| ... | @@ -6457,9 +6414,9 @@ fn zirExportValue(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError | ... | @@ -6457,9 +6414,9 @@ fn zirExportValue(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 6457 | const mod = sema.mod; | 6414 | const mod = sema.mod; |
| 6458 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 6415 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 6459 | const extra = sema.code.extraData(Zir.Inst.ExportValue, inst_data.payload_index).data; | 6416 | const extra = sema.code.extraData(Zir.Inst.ExportValue, inst_data.payload_index).data; |
| 6460 | const src = inst_data.src(); | 6417 | const src = block.nodeOffset(inst_data.src_node); |
| 6461 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 6418 | const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0); |
| 6462 | const options_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; | 6419 | const options_src = block.builtinCallArgSrc(inst_data.src_node, 1); |
| 6463 | const operand = try sema.resolveInstConst(block, operand_src, extra.operand, .{ | 6420 | const operand = try sema.resolveInstConst(block, operand_src, extra.operand, .{ |
| 6464 | .needed_comptime_reason = "export target must be comptime-known", | 6421 | .needed_comptime_reason = "export target must be comptime-known", |
| 6465 | }); | 6422 | }); |
| ... | @@ -6475,7 +6432,6 @@ fn zirExportValue(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError | ... | @@ -6475,7 +6432,6 @@ fn zirExportValue(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 6475 | .opts = options, | 6432 | .opts = options, |
| 6476 | .src = src, | 6433 | .src = src, |
| 6477 | .owner_decl = sema.owner_decl_index, | 6434 | .owner_decl = sema.owner_decl_index, |
| 6478 | .src_decl = block.src_decl, | | |
| 6479 | .exported = .{ .value = operand.toIntern() }, | 6435 | .exported = .{ .value = operand.toIntern() }, |
| 6480 | .status = .in_progress, | 6436 | .status = .in_progress, |
| 6481 | }); | 6437 | }); |
| ... | @@ -6500,11 +6456,10 @@ pub fn analyzeExport( | ... | @@ -6500,11 +6456,10 @@ pub fn analyzeExport( |
| 6500 | | 6456 | |
| 6501 | if (!try sema.validateExternType(export_ty, .other)) { | 6457 | if (!try sema.validateExternType(export_ty, .other)) { |
| 6502 | const msg = msg: { | 6458 | const msg = msg: { |
| 6503 | const msg = try sema.errMsg(block, src, "unable to export type '{}'", .{export_ty.fmt(mod)}); | 6459 | const msg = try sema.errMsg(src, "unable to export type '{}'", .{export_ty.fmt(mod)}); |
| 6504 | errdefer msg.destroy(gpa); | 6460 | errdefer msg.destroy(gpa); |
| 6505 | | 6461 | |
| 6506 | const src_decl = mod.declPtr(block.src_decl); | 6462 | try sema.explainWhyTypeIsNotExtern(msg, src, export_ty, .other); |
| 6507 | try sema.explainWhyTypeIsNotExtern(msg, src_decl.toSrcLoc(src, mod), export_ty, .other); | | |
| 6508 | | 6463 | |
| 6509 | try sema.addDeclaredHereNote(msg, export_ty); | 6464 | try sema.addDeclaredHereNote(msg, export_ty); |
| 6510 | break :msg msg; | 6465 | break :msg msg; |
| ... | @@ -6523,7 +6478,6 @@ pub fn analyzeExport( | ... | @@ -6523,7 +6478,6 @@ pub fn analyzeExport( |
| 6523 | .opts = options, | 6478 | .opts = options, |
| 6524 | .src = src, | 6479 | .src = src, |
| 6525 | .owner_decl = sema.owner_decl_index, | 6480 | .owner_decl = sema.owner_decl_index, |
| 6526 | .src_decl = block.src_decl, | | |
| 6527 | .exported = .{ .decl_index = exported_decl_index }, | 6481 | .exported = .{ .decl_index = exported_decl_index }, |
| 6528 | .status = .in_progress, | 6482 | .status = .in_progress, |
| 6529 | }); | 6483 | }); |
| ... | @@ -6563,8 +6517,8 @@ fn addExport(mod: *Module, export_init: Module.Export) error{OutOfMemory}!void { | ... | @@ -6563,8 +6517,8 @@ fn addExport(mod: *Module, export_init: Module.Export) error{OutOfMemory}!void { |
| 6563 | fn zirSetAlignStack(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!void { | 6517 | fn zirSetAlignStack(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!void { |
| 6564 | const mod = sema.mod; | 6518 | const mod = sema.mod; |
| 6565 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; | 6519 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; |
| 6566 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node }; | 6520 | const operand_src = block.builtinCallArgSrc(extra.node, 0); |
| 6567 | const src = LazySrcLoc.nodeOffset(extra.node); | 6521 | const src = block.nodeOffset(extra.node); |
| 6568 | const alignment = try sema.resolveAlign(block, operand_src, extra.operand); | 6522 | const alignment = try sema.resolveAlign(block, operand_src, extra.operand); |
| 6569 | if (alignment.order(Alignment.fromNonzeroByteUnits(256)).compare(.gt)) { | 6523 | if (alignment.order(Alignment.fromNonzeroByteUnits(256)).compare(.gt)) { |
| 6570 | return sema.fail(block, src, "attempt to @setAlignStack({d}); maximum is 256", .{ | 6524 | return sema.fail(block, src, "attempt to @setAlignStack({d}); maximum is 256", .{ |
| ... | @@ -6583,9 +6537,9 @@ fn zirSetAlignStack(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.Inst | ... | @@ -6583,9 +6537,9 @@ fn zirSetAlignStack(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.Inst |
| 6583 | | 6537 | |
| 6584 | if (sema.prev_stack_alignment_src) |prev_src| { | 6538 | if (sema.prev_stack_alignment_src) |prev_src| { |
| 6585 | const msg = msg: { | 6539 | const msg = msg: { |
| 6586 | const msg = try sema.errMsg(block, src, "multiple @setAlignStack in the same function body", .{}); | 6540 | const msg = try sema.errMsg(src, "multiple @setAlignStack in the same function body", .{}); |
| 6587 | errdefer msg.destroy(sema.gpa); | 6541 | errdefer msg.destroy(sema.gpa); |
| 6588 | try sema.errNote(block, prev_src, msg, "other instance here", .{}); | 6542 | try sema.errNote(prev_src, msg, "other instance here", .{}); |
| 6589 | break :msg msg; | 6543 | break :msg msg; |
| 6590 | }; | 6544 | }; |
| 6591 | return sema.failWithOwnedErrorMsg(block, msg); | 6545 | return sema.failWithOwnedErrorMsg(block, msg); |
| ... | @@ -6606,7 +6560,7 @@ fn zirSetCold(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) | ... | @@ -6606,7 +6560,7 @@ fn zirSetCold(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) |
| 6606 | const mod = sema.mod; | 6560 | const mod = sema.mod; |
| 6607 | const ip = &mod.intern_pool; | 6561 | const ip = &mod.intern_pool; |
| 6608 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; | 6562 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; |
| 6609 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node }; | 6563 | const operand_src = block.builtinCallArgSrc(extra.node, 0); |
| 6610 | const is_cold = try sema.resolveConstBool(block, operand_src, extra.operand, .{ | 6564 | const is_cold = try sema.resolveConstBool(block, operand_src, extra.operand, .{ |
| 6611 | .needed_comptime_reason = "operand to @setCold must be comptime-known", | 6565 | .needed_comptime_reason = "operand to @setCold must be comptime-known", |
| 6612 | }); | 6566 | }); |
| ... | @@ -6616,7 +6570,7 @@ fn zirSetCold(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) | ... | @@ -6616,7 +6570,7 @@ fn zirSetCold(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) |
| 6616 | | 6570 | |
| 6617 | fn zirSetFloatMode(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!void { | 6571 | fn zirSetFloatMode(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!void { |
| 6618 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; | 6572 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; |
| 6619 | const src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node }; | 6573 | const src = block.builtinCallArgSrc(extra.node, 0); |
| 6620 | block.float_mode = try sema.resolveBuiltinEnum(block, src, extra.operand, "FloatMode", .{ | 6574 | block.float_mode = try sema.resolveBuiltinEnum(block, src, extra.operand, "FloatMode", .{ |
| 6621 | .needed_comptime_reason = "operand to @setFloatMode must be comptime-known", | 6575 | .needed_comptime_reason = "operand to @setFloatMode must be comptime-known", |
| 6622 | }); | 6576 | }); |
| ... | @@ -6624,7 +6578,7 @@ fn zirSetFloatMode(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstD | ... | @@ -6624,7 +6578,7 @@ fn zirSetFloatMode(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstD |
| 6624 | | 6578 | |
| 6625 | fn zirSetRuntimeSafety(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void { | 6579 | fn zirSetRuntimeSafety(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void { |
| 6626 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; | 6580 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 6627 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 6581 | const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0); |
| 6628 | block.want_safety = try sema.resolveConstBool(block, operand_src, inst_data.operand, .{ | 6582 | block.want_safety = try sema.resolveConstBool(block, operand_src, inst_data.operand, .{ |
| 6629 | .needed_comptime_reason = "operand to @setRuntimeSafety must be comptime-known", | 6583 | .needed_comptime_reason = "operand to @setRuntimeSafety must be comptime-known", |
| 6630 | }); | 6584 | }); |
| ... | @@ -6634,7 +6588,7 @@ fn zirFence(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) Co | ... | @@ -6634,7 +6588,7 @@ fn zirFence(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) Co |
| 6634 | if (block.is_comptime) return; | 6588 | if (block.is_comptime) return; |
| 6635 | | 6589 | |
| 6636 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; | 6590 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; |
| 6637 | const order_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node }; | 6591 | const order_src = block.builtinCallArgSrc(extra.node, 0); |
| 6638 | const order = try sema.resolveAtomicOrder(block, order_src, extra.operand, .{ | 6592 | const order = try sema.resolveAtomicOrder(block, order_src, extra.operand, .{ |
| 6639 | .needed_comptime_reason = "atomic order of @fence must be comptime-known", | 6593 | .needed_comptime_reason = "atomic order of @fence must be comptime-known", |
| 6640 | }); | 6594 | }); |
| ... | @@ -6664,7 +6618,7 @@ fn zirBreak(sema: *Sema, start_block: *Block, inst: Zir.Inst.Index) CompileError | ... | @@ -6664,7 +6618,7 @@ fn zirBreak(sema: *Sema, start_block: *Block, inst: Zir.Inst.Index) CompileError |
| 6664 | if (label.zir_block == zir_block) { | 6618 | if (label.zir_block == zir_block) { |
| 6665 | const br_ref = try start_block.addBr(label.merges.block_inst, operand); | 6619 | const br_ref = try start_block.addBr(label.merges.block_inst, operand); |
| 6666 | const src_loc = if (extra.operand_src_node != Zir.Inst.Break.no_src_node) | 6620 | const src_loc = if (extra.operand_src_node != Zir.Inst.Break.no_src_node) |
| 6667 | LazySrcLoc.nodeOffset(extra.operand_src_node) | 6621 | start_block.nodeOffset(extra.operand_src_node) |
| 6668 | else | 6622 | else |
| 6669 | null; | 6623 | null; |
| 6670 | try label.merges.src_locs.append(sema.gpa, src_loc); | 6624 | try label.merges.src_locs.append(sema.gpa, src_loc); |
| ... | @@ -6774,21 +6728,21 @@ fn addDbgVar( | ... | @@ -6774,21 +6728,21 @@ fn addDbgVar( |
| 6774 | fn zirDeclRef(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 6728 | fn zirDeclRef(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 6775 | const mod = sema.mod; | 6729 | const mod = sema.mod; |
| 6776 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].str_tok; | 6730 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].str_tok; |
| 6777 | const src = inst_data.src(); | 6731 | const src = block.tokenOffset(inst_data.src_tok); |
| 6778 | const decl_name = try mod.intern_pool.getOrPutString( | 6732 | const decl_name = try mod.intern_pool.getOrPutString( |
| 6779 | sema.gpa, | 6733 | sema.gpa, |
| 6780 | inst_data.get(sema.code), | 6734 | inst_data.get(sema.code), |
| 6781 | .no_embedded_nulls, | 6735 | .no_embedded_nulls, |
| 6782 | ); | 6736 | ); |
| 6783 | const decl_index = try sema.lookupIdentifier(block, src, decl_name); | 6737 | const decl_index = try sema.lookupIdentifier(block, src, decl_name); |
| 6784 | try sema.addReferencedBy(block, src, decl_index); | 6738 | try sema.addReferencedBy(src, decl_index); |
| 6785 | return sema.analyzeDeclRef(decl_index); | 6739 | return sema.analyzeDeclRef(decl_index); |
| 6786 | } | 6740 | } |
| 6787 | | 6741 | |
| 6788 | fn zirDeclVal(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 6742 | fn zirDeclVal(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 6789 | const mod = sema.mod; | 6743 | const mod = sema.mod; |
| 6790 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].str_tok; | 6744 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].str_tok; |
| 6791 | const src = inst_data.src(); | 6745 | const src = block.tokenOffset(inst_data.src_tok); |
| 6792 | const decl_name = try mod.intern_pool.getOrPutString( | 6746 | const decl_name = try mod.intern_pool.getOrPutString( |
| 6793 | sema.gpa, | 6747 | sema.gpa, |
| 6794 | inst_data.get(sema.code), | 6748 | inst_data.get(sema.code), |
| ... | @@ -6891,12 +6845,14 @@ fn lookupInNamespace( | ... | @@ -6891,12 +6845,14 @@ fn lookupInNamespace( |
| 6891 | }, | 6845 | }, |
| 6892 | else => { | 6846 | else => { |
| 6893 | const msg = msg: { | 6847 | const msg = msg: { |
| 6894 | const msg = try sema.errMsg(block, src, "ambiguous reference", .{}); | 6848 | const msg = try sema.errMsg(src, "ambiguous reference", .{}); |
| 6895 | errdefer msg.destroy(gpa); | 6849 | errdefer msg.destroy(gpa); |
| 6896 | for (candidates.items) |candidate_index| { | 6850 | for (candidates.items) |candidate_index| { |
| 6897 | const candidate = mod.declPtr(candidate_index); | 6851 | const candidate = mod.declPtr(candidate_index); |
| 6898 | const src_loc = candidate.srcLoc(mod); | 6852 | try sema.errNote(.{ |
| 6899 | try mod.errNoteNonLazy(src_loc, msg, "declared here", .{}); | 6853 | .base_node_inst = candidate.zir_decl_index.unwrap().?, |
| | 6854 | .offset = LazySrcLoc.Offset.nodeOffset(0), |
| | 6855 | }, msg, "declared here", .{}); |
| 6900 | } | 6856 | } |
| 6901 | break :msg msg; | 6857 | break :msg msg; |
| 6902 | }; | 6858 | }; |
| ... | @@ -6938,16 +6894,16 @@ pub fn analyzeSaveErrRetIndex(sema: *Sema, block: *Block) SemaError!Air.Inst.Ref | ... | @@ -6938,16 +6894,16 @@ pub fn analyzeSaveErrRetIndex(sema: *Sema, block: *Block) SemaError!Air.Inst.Ref |
| 6938 | if (!block.ownerModule().error_tracing) return .none; | 6894 | if (!block.ownerModule().error_tracing) return .none; |
| 6939 | | 6895 | |
| 6940 | const stack_trace_ty = sema.getBuiltinType("StackTrace") catch |err| switch (err) { | 6896 | const stack_trace_ty = sema.getBuiltinType("StackTrace") catch |err| switch (err) { |
| 6941 | error.NeededSourceLocation, error.GenericPoison, error.ComptimeReturn, error.ComptimeBreak => unreachable, | 6897 | error.GenericPoison, error.ComptimeReturn, error.ComptimeBreak => unreachable, |
| 6942 | else => |e| return e, | 6898 | else => |e| return e, |
| 6943 | }; | 6899 | }; |
| 6944 | sema.resolveTypeFields(stack_trace_ty) catch |err| switch (err) { | 6900 | sema.resolveTypeFields(stack_trace_ty) catch |err| switch (err) { |
| 6945 | error.NeededSourceLocation, error.GenericPoison, error.ComptimeReturn, error.ComptimeBreak => unreachable, | 6901 | error.GenericPoison, error.ComptimeReturn, error.ComptimeBreak => unreachable, |
| 6946 | else => |e| return e, | 6902 | else => |e| return e, |
| 6947 | }; | 6903 | }; |
| 6948 | const field_name = try mod.intern_pool.getOrPutString(gpa, "index", .no_embedded_nulls); | 6904 | const field_name = try mod.intern_pool.getOrPutString(gpa, "index", .no_embedded_nulls); |
| 6949 | const field_index = sema.structFieldIndex(block, stack_trace_ty, field_name, .unneeded) catch |err| switch (err) { | 6905 | const field_index = sema.structFieldIndex(block, stack_trace_ty, field_name, LazySrcLoc.unneeded) catch |err| switch (err) { |
| 6950 | error.AnalysisFail, error.NeededSourceLocation => @panic("std.builtin.StackTrace is corrupt"), | 6906 | error.AnalysisFail => @panic("std.builtin.StackTrace is corrupt"), |
| 6951 | error.GenericPoison, error.ComptimeReturn, error.ComptimeBreak => unreachable, | 6907 | error.GenericPoison, error.ComptimeReturn, error.ComptimeBreak => unreachable, |
| 6952 | error.OutOfMemory => |e| return e, | 6908 | error.OutOfMemory => |e| return e, |
| 6953 | }; | 6909 | }; |
| ... | @@ -7055,8 +7011,8 @@ fn zirCall( | ... | @@ -7055,8 +7011,8 @@ fn zirCall( |
| 7055 | | 7011 | |
| 7056 | const mod = sema.mod; | 7012 | const mod = sema.mod; |
| 7057 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 7013 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 7058 | const callee_src: LazySrcLoc = .{ .node_offset_call_func = inst_data.src_node }; | 7014 | const callee_src = block.src(.{ .node_offset_call_func = inst_data.src_node }); |
| 7059 | const call_src = inst_data.src(); | 7015 | const call_src = block.nodeOffset(inst_data.src_node); |
| 7060 | const ExtraType = switch (kind) { | 7016 | const ExtraType = switch (kind) { |
| 7061 | .direct => Zir.Inst.Call, | 7017 | .direct => Zir.Inst.Call, |
| 7062 | .field => Zir.Inst.FieldCall, | 7018 | .field => Zir.Inst.FieldCall, |
| ... | @@ -7077,7 +7033,7 @@ fn zirCall( | ... | @@ -7077,7 +7033,7 @@ fn zirCall( |
| 7077 | sema.code.nullTerminatedString(extra.data.field_name_start), | 7033 | sema.code.nullTerminatedString(extra.data.field_name_start), |
| 7078 | .no_embedded_nulls, | 7034 | .no_embedded_nulls, |
| 7079 | ); | 7035 | ); |
| 7080 | const field_name_src: LazySrcLoc = .{ .node_offset_field_name = inst_data.src_node }; | 7036 | const field_name_src = block.src(.{ .node_offset_field_name = inst_data.src_node }); |
| 7081 | break :blk try sema.fieldCallBind(block, callee_src, object_ptr, field_name, field_name_src); | 7037 | break :blk try sema.fieldCallBind(block, callee_src, object_ptr, field_name, field_name_src); |
| 7082 | }, | 7038 | }, |
| 7083 | }; | 7039 | }; |
| ... | @@ -7187,11 +7143,11 @@ fn checkCallArgumentCount( | ... | @@ -7187,11 +7143,11 @@ fn checkCallArgumentCount( |
| 7187 | opt_child.childType(mod).zigTypeTag(mod) == .Fn)) | 7143 | opt_child.childType(mod).zigTypeTag(mod) == .Fn)) |
| 7188 | { | 7144 | { |
| 7189 | const msg = msg: { | 7145 | const msg = msg: { |
| 7190 | const msg = try sema.errMsg(block, func_src, "cannot call optional type '{}'", .{ | 7146 | const msg = try sema.errMsg(func_src, "cannot call optional type '{}'", .{ |
| 7191 | callee_ty.fmt(mod), | 7147 | callee_ty.fmt(mod), |
| 7192 | }); | 7148 | }); |
| 7193 | errdefer msg.destroy(sema.gpa); | 7149 | errdefer msg.destroy(sema.gpa); |
| 7194 | try sema.errNote(block, func_src, msg, "consider using '.?', 'orelse' or 'if'", .{}); | 7150 | try sema.errNote(func_src, msg, "consider using '.?', 'orelse' or 'if'", .{}); |
| 7195 | break :msg msg; | 7151 | break :msg msg; |
| 7196 | }; | 7152 | }; |
| 7197 | return sema.failWithOwnedErrorMsg(block, msg); | 7153 | return sema.failWithOwnedErrorMsg(block, msg); |
| ... | @@ -7217,7 +7173,6 @@ fn checkCallArgumentCount( | ... | @@ -7217,7 +7173,6 @@ fn checkCallArgumentCount( |
| 7217 | const variadic_str = if (func_ty_info.is_var_args) "at least " else ""; | 7173 | const variadic_str = if (func_ty_info.is_var_args) "at least " else ""; |
| 7218 | const msg = msg: { | 7174 | const msg = msg: { |
| 7219 | const msg = try sema.errMsg( | 7175 | const msg = try sema.errMsg( |
| 7220 | block, | | |
| 7221 | func_src, | 7176 | func_src, |
| 7222 | "{s}expected {s}{d} argument(s), found {d}", | 7177 | "{s}expected {s}{d} argument(s), found {d}", |
| 7223 | .{ | 7178 | .{ |
| ... | @@ -7229,7 +7184,12 @@ fn checkCallArgumentCount( | ... | @@ -7229,7 +7184,12 @@ fn checkCallArgumentCount( |
| 7229 | ); | 7184 | ); |
| 7230 | errdefer msg.destroy(sema.gpa); | 7185 | errdefer msg.destroy(sema.gpa); |
| 7231 | | 7186 | |
| 7232 | if (maybe_decl) |fn_decl| try mod.errNoteNonLazy(fn_decl.srcLoc(mod), msg, "function declared here", .{}); | 7187 | if (maybe_decl) |fn_decl| { |
| | 7188 | try sema.errNote(.{ |
| | 7189 | .base_node_inst = fn_decl.zir_decl_index.unwrap().?, |
| | 7190 | .offset = LazySrcLoc.Offset.nodeOffset(0), |
| | 7191 | }, msg, "function declared here", .{}); |
| | 7192 | } |
| 7233 | break :msg msg; | 7193 | break :msg msg; |
| 7234 | }; | 7194 | }; |
| 7235 | return sema.failWithOwnedErrorMsg(block, msg); | 7195 | return sema.failWithOwnedErrorMsg(block, msg); |
| ... | @@ -7337,18 +7297,16 @@ const CallArgsInfo = union(enum) { | ... | @@ -7337,18 +7297,16 @@ const CallArgsInfo = union(enum) { |
| 7337 | fn argSrc(cai: CallArgsInfo, block: *Block, arg_index: usize) LazySrcLoc { | 7297 | fn argSrc(cai: CallArgsInfo, block: *Block, arg_index: usize) LazySrcLoc { |
| 7338 | return switch (cai) { | 7298 | return switch (cai) { |
| 7339 | .resolved => |resolved| resolved.src, | 7299 | .resolved => |resolved| resolved.src, |
| 7340 | .call_builtin => |call_builtin| .{ .call_arg = .{ | 7300 | .call_builtin => |call_builtin| block.src(.{ .call_arg = .{ |
| 7341 | .decl = block.src_decl, | | |
| 7342 | .call_node_offset = call_builtin.call_node_offset, | 7301 | .call_node_offset = call_builtin.call_node_offset, |
| 7343 | .arg_index = @intCast(arg_index), | 7302 | .arg_index = @intCast(arg_index), |
| 7344 | } }, | 7303 | } }), |
| 7345 | .zir_call => |zir_call| if (arg_index == 0 and zir_call.bound_arg != .none) { | 7304 | .zir_call => |zir_call| if (arg_index == 0 and zir_call.bound_arg != .none) { |
| 7346 | return zir_call.bound_arg_src; | 7305 | return zir_call.bound_arg_src; |
| 7347 | } else .{ .call_arg = .{ | 7306 | } else block.src(.{ .call_arg = .{ |
| 7348 | .decl = block.src_decl, | | |
| 7349 | .call_node_offset = zir_call.call_node_offset, | 7307 | .call_node_offset = zir_call.call_node_offset, |
| 7350 | .arg_index = @intCast(arg_index - @intFromBool(zir_call.bound_arg != .none)), | 7308 | .arg_index = @intCast(arg_index - @intFromBool(zir_call.bound_arg != .none)), |
| 7351 | } }, | 7309 | } }), |
| 7352 | }; | 7310 | }; |
| 7353 | } | 7311 | } |
| 7354 | | 7312 | |
| ... | @@ -7460,7 +7418,6 @@ const InlineCallSema = struct { | ... | @@ -7460,7 +7418,6 @@ const InlineCallSema = struct { |
| 7460 | other_error_return_trace_index_on_fn_entry: Air.Inst.Ref, | 7418 | other_error_return_trace_index_on_fn_entry: Air.Inst.Ref, |
| 7461 | other_generic_owner: InternPool.Index, | 7419 | other_generic_owner: InternPool.Index, |
| 7462 | other_generic_call_src: LazySrcLoc, | 7420 | other_generic_call_src: LazySrcLoc, |
| 7463 | other_generic_call_decl: InternPool.OptionalDeclIndex, | | |
| 7464 | | 7421 | |
| 7465 | /// Sema should currently be set up for the caller (i.e. unchanged yet). This init will not | 7422 | /// Sema should currently be set up for the caller (i.e. unchanged yet). This init will not |
| 7466 | /// change that. The other parameters contain data for the callee Sema. The other modified | 7423 | /// change that. The other parameters contain data for the callee Sema. The other modified |
| ... | @@ -7482,8 +7439,7 @@ const InlineCallSema = struct { | ... | @@ -7482,8 +7439,7 @@ const InlineCallSema = struct { |
| 7482 | .other_inst_map = .{}, | 7439 | .other_inst_map = .{}, |
| 7483 | .other_error_return_trace_index_on_fn_entry = callee_error_return_trace_index_on_fn_entry, | 7440 | .other_error_return_trace_index_on_fn_entry = callee_error_return_trace_index_on_fn_entry, |
| 7484 | .other_generic_owner = .none, | 7441 | .other_generic_owner = .none, |
| 7485 | .other_generic_call_src = .unneeded, | 7442 | .other_generic_call_src = LazySrcLoc.unneeded, |
| 7486 | .other_generic_call_decl = .none, | | |
| 7487 | }; | 7443 | }; |
| 7488 | } | 7444 | } |
| 7489 | | 7445 | |
| ... | @@ -7530,7 +7486,6 @@ const InlineCallSema = struct { | ... | @@ -7530,7 +7486,6 @@ const InlineCallSema = struct { |
| 7530 | std.mem.swap(InstMap, &ics.sema.inst_map, &ics.other_inst_map); | 7486 | std.mem.swap(InstMap, &ics.sema.inst_map, &ics.other_inst_map); |
| 7531 | std.mem.swap(InternPool.Index, &ics.sema.generic_owner, &ics.other_generic_owner); | 7487 | std.mem.swap(InternPool.Index, &ics.sema.generic_owner, &ics.other_generic_owner); |
| 7532 | std.mem.swap(LazySrcLoc, &ics.sema.generic_call_src, &ics.other_generic_call_src); | 7488 | std.mem.swap(LazySrcLoc, &ics.sema.generic_call_src, &ics.other_generic_call_src); |
| 7533 | std.mem.swap(InternPool.OptionalDeclIndex, &ics.sema.generic_call_decl, &ics.other_generic_call_decl); | | |
| 7534 | std.mem.swap(Air.Inst.Ref, &ics.sema.error_return_trace_index_on_fn_entry, &ics.other_error_return_trace_index_on_fn_entry); | 7489 | std.mem.swap(Air.Inst.Ref, &ics.sema.error_return_trace_index_on_fn_entry, &ics.other_error_return_trace_index_on_fn_entry); |
| 7535 | // zig fmt: on | 7490 | // zig fmt: on |
| 7536 | } | 7491 | } |
| ... | @@ -7562,14 +7517,16 @@ fn analyzeCall( | ... | @@ -7562,14 +7517,16 @@ fn analyzeCall( |
| 7562 | const maybe_decl = try sema.funcDeclSrc(func); | 7517 | const maybe_decl = try sema.funcDeclSrc(func); |
| 7563 | const msg = msg: { | 7518 | const msg = msg: { |
| 7564 | const msg = try sema.errMsg( | 7519 | const msg = try sema.errMsg( |
| 7565 | block, | | |
| 7566 | func_src, | 7520 | func_src, |
| 7567 | "unable to call function with naked calling convention", | 7521 | "unable to call function with naked calling convention", |
| 7568 | .{}, | 7522 | .{}, |
| 7569 | ); | 7523 | ); |
| 7570 | errdefer msg.destroy(sema.gpa); | 7524 | errdefer msg.destroy(sema.gpa); |
| 7571 | | 7525 | |
| 7572 | if (maybe_decl) |fn_decl| try mod.errNoteNonLazy(fn_decl.srcLoc(mod), msg, "function declared here", .{}); | 7526 | if (maybe_decl) |fn_decl| try sema.errNote(.{ |
| | 7527 | .base_node_inst = fn_decl.zir_decl_index.unwrap().?, |
| | 7528 | .offset = LazySrcLoc.Offset.nodeOffset(0), |
| | 7529 | }, msg, "function declared here", .{}); |
| 7573 | break :msg msg; | 7530 | break :msg msg; |
| 7574 | }; | 7531 | }; |
| 7575 | return sema.failWithOwnedErrorMsg(block, msg); | 7532 | return sema.failWithOwnedErrorMsg(block, msg); |
| ... | @@ -7608,7 +7565,6 @@ fn analyzeCall( | ... | @@ -7608,7 +7565,6 @@ fn analyzeCall( |
| 7608 | is_inline_call = ct; | 7565 | is_inline_call = ct; |
| 7609 | if (ct) { | 7566 | if (ct) { |
| 7610 | comptime_reason = &.{ .comptime_ret_ty = .{ | 7567 | comptime_reason = &.{ .comptime_ret_ty = .{ |
| 7611 | .block = block, | | |
| 7612 | .func = func, | 7568 | .func = func, |
| 7613 | .func_src = func_src, | 7569 | .func_src = func_src, |
| 7614 | .return_ty = Type.fromInterned(func_ty_info.return_type), | 7570 | .return_ty = Type.fromInterned(func_ty_info.return_type), |
| ... | @@ -7622,12 +7578,12 @@ fn analyzeCall( | ... | @@ -7622,12 +7578,12 @@ fn analyzeCall( |
| 7622 | | 7578 | |
| 7623 | if (sema.func_is_naked and !is_inline_call and !is_comptime_call) { | 7579 | if (sema.func_is_naked and !is_inline_call and !is_comptime_call) { |
| 7624 | const msg = msg: { | 7580 | const msg = msg: { |
| 7625 | const msg = try sema.errMsg(block, call_src, "runtime {s} not allowed in naked function", .{@tagName(operation)}); | 7581 | const msg = try sema.errMsg(call_src, "runtime {s} not allowed in naked function", .{@tagName(operation)}); |
| 7626 | errdefer msg.destroy(sema.gpa); | 7582 | errdefer msg.destroy(sema.gpa); |
| 7627 | | 7583 | |
| 7628 | switch (operation) { | 7584 | switch (operation) { |
| 7629 | .call, .@"@call", .@"@panic", .@"error return" => {}, | 7585 | .call, .@"@call", .@"@panic", .@"error return" => {}, |
| 7630 | .@"safety check" => try sema.errNote(block, call_src, msg, "use @setRuntimeSafety to disable runtime safety", .{}), | 7586 | .@"safety check" => try sema.errNote(call_src, msg, "use @setRuntimeSafety to disable runtime safety", .{}), |
| 7631 | } | 7587 | } |
| 7632 | break :msg msg; | 7588 | break :msg msg; |
| 7633 | }; | 7589 | }; |
| ... | @@ -7654,7 +7610,6 @@ fn analyzeCall( | ... | @@ -7654,7 +7610,6 @@ fn analyzeCall( |
| 7654 | is_inline_call = true; | 7610 | is_inline_call = true; |
| 7655 | is_comptime_call = true; | 7611 | is_comptime_call = true; |
| 7656 | comptime_reason = &.{ .comptime_ret_ty = .{ | 7612 | comptime_reason = &.{ .comptime_ret_ty = .{ |
| 7657 | .block = block, | | |
| 7658 | .func = func, | 7613 | .func = func, |
| 7659 | .func_src = func_src, | 7614 | .func_src = func_src, |
| 7660 | .return_ty = Type.fromInterned(func_ty_info.return_type), | 7615 | .return_ty = Type.fromInterned(func_ty_info.return_type), |
| ... | @@ -7749,7 +7704,6 @@ fn analyzeCall( | ... | @@ -7749,7 +7704,6 @@ fn analyzeCall( |
| 7749 | var child_block: Block = .{ | 7704 | var child_block: Block = .{ |
| 7750 | .parent = null, | 7705 | .parent = null, |
| 7751 | .sema = sema, | 7706 | .sema = sema, |
| 7752 | .src_decl = module_fn.owner_decl, | | |
| 7753 | .namespace = fn_owner_decl.src_namespace, | 7707 | .namespace = fn_owner_decl.src_namespace, |
| 7754 | .instructions = .{}, | 7708 | .instructions = .{}, |
| 7755 | .label = null, | 7709 | .label = null, |
| ... | @@ -7761,6 +7715,8 @@ fn analyzeCall( | ... | @@ -7761,6 +7715,8 @@ fn analyzeCall( |
| 7761 | .runtime_cond = block.runtime_cond, | 7715 | .runtime_cond = block.runtime_cond, |
| 7762 | .runtime_loop = block.runtime_loop, | 7716 | .runtime_loop = block.runtime_loop, |
| 7763 | .runtime_index = block.runtime_index, | 7717 | .runtime_index = block.runtime_index, |
| | 7718 | .src_base_inst = fn_owner_decl.zir_decl_index.unwrap().?, |
| | 7719 | .type_name_ctx = fn_owner_decl.name, |
| 7764 | }; | 7720 | }; |
| 7765 | | 7721 | |
| 7766 | const merges = &child_block.inlining.?.merges; | 7722 | const merges = &child_block.inlining.?.merges; |
| ... | @@ -7834,7 +7790,7 @@ fn analyzeCall( | ... | @@ -7834,7 +7790,7 @@ fn analyzeCall( |
| 7834 | var block_it = block; | 7790 | var block_it = block; |
| 7835 | while (block_it.inlining) |parent_inlining| { | 7791 | while (block_it.inlining) |parent_inlining| { |
| 7836 | if (!parent_inlining.has_comptime_args and parent_inlining.func == module_fn_index) { | 7792 | if (!parent_inlining.has_comptime_args and parent_inlining.func == module_fn_index) { |
| 7837 | const err_msg = try sema.errMsg(block, call_src, "inline call is recursive", .{}); | 7793 | const err_msg = try sema.errMsg(call_src, "inline call is recursive", .{}); |
| 7838 | return sema.failWithOwnedErrorMsg(null, err_msg); | 7794 | return sema.failWithOwnedErrorMsg(null, err_msg); |
| 7839 | } | 7795 | } |
| 7840 | block_it = parent_inlining.call_block; | 7796 | block_it = parent_inlining.call_block; |
| ... | @@ -7849,7 +7805,7 @@ fn analyzeCall( | ... | @@ -7849,7 +7805,7 @@ fn analyzeCall( |
| 7849 | try sema.resolveInlineBody(&child_block, fn_info.ret_ty_body, module_fn.zir_body_inst.resolve(ip)) | 7805 | try sema.resolveInlineBody(&child_block, fn_info.ret_ty_body, module_fn.zir_body_inst.resolve(ip)) |
| 7850 | else | 7806 | else |
| 7851 | try sema.resolveInst(fn_info.ret_ty_ref); | 7807 | try sema.resolveInst(fn_info.ret_ty_ref); |
| 7852 | const ret_ty_src: LazySrcLoc = .{ .node_offset_fn_type_ret_ty = 0 }; | 7808 | const ret_ty_src: LazySrcLoc = .{ .base_node_inst = module_fn.zir_body_inst, .offset = .{ .node_offset_fn_type_ret_ty = 0 } }; |
| 7853 | sema.fn_ret_ty = try sema.analyzeAsType(&child_block, ret_ty_src, ret_ty_inst); | 7809 | sema.fn_ret_ty = try sema.analyzeAsType(&child_block, ret_ty_src, ret_ty_inst); |
| 7854 | if (module_fn.analysis(ip).inferred_error_set) { | 7810 | if (module_fn.analysis(ip).inferred_error_set) { |
| 7855 | // Create a fresh inferred error set type for inline/comptime calls. | 7811 | // Create a fresh inferred error set type for inline/comptime calls. |
| ... | @@ -7920,7 +7876,7 @@ fn analyzeCall( | ... | @@ -7920,7 +7876,7 @@ fn analyzeCall( |
| 7920 | }; | 7876 | }; |
| 7921 | | 7877 | |
| 7922 | if (is_comptime_call) { | 7878 | if (is_comptime_call) { |
| 7923 | const result_val = try sema.resolveConstValue(block, .unneeded, result, undefined); | 7879 | const result_val = try sema.resolveConstValue(block, LazySrcLoc.unneeded, result, undefined); |
| 7924 | const result_interned = result_val.toIntern(); | 7880 | const result_interned = result_val.toIntern(); |
| 7925 | | 7881 | |
| 7926 | // Transform ad-hoc inferred error set types into concrete error sets. | 7882 | // Transform ad-hoc inferred error set types into concrete error sets. |
| ... | @@ -8081,7 +8037,7 @@ fn analyzeInlineCallArg( | ... | @@ -8081,7 +8037,7 @@ fn analyzeInlineCallArg( |
| 8081 | // Evaluate the parameter type expression now that previous ones have | 8037 | // Evaluate the parameter type expression now that previous ones have |
| 8082 | // been mapped, and coerce the corresponding argument to it. | 8038 | // been mapped, and coerce the corresponding argument to it. |
| 8083 | const pl_tok = ics.callee().code.instructions.items(.data)[@intFromEnum(inst)].pl_tok; | 8039 | const pl_tok = ics.callee().code.instructions.items(.data)[@intFromEnum(inst)].pl_tok; |
| 8084 | const param_src = pl_tok.src(); | 8040 | const param_src = param_block.tokenOffset(pl_tok.src_tok); |
| 8085 | const extra = ics.callee().code.extraData(Zir.Inst.Param, pl_tok.payload_index); | 8041 | const extra = ics.callee().code.extraData(Zir.Inst.Param, pl_tok.payload_index); |
| 8086 | const param_body = ics.callee().code.bodySlice(extra.end, extra.data.body_len); | 8042 | const param_body = ics.callee().code.bodySlice(extra.end, extra.data.body_len); |
| 8087 | const param_ty = param_ty: { | 8043 | const param_ty = param_ty: { |
| ... | @@ -8261,7 +8217,6 @@ fn instantiateGenericCall( | ... | @@ -8261,7 +8217,6 @@ fn instantiateGenericCall( |
| 8261 | .comptime_args = comptime_args, | 8217 | .comptime_args = comptime_args, |
| 8262 | .generic_owner = generic_owner, | 8218 | .generic_owner = generic_owner, |
| 8263 | .generic_call_src = call_src, | 8219 | .generic_call_src = call_src, |
| 8264 | .generic_call_decl = block.src_decl.toOptional(), | | |
| 8265 | .branch_quota = sema.branch_quota, | 8220 | .branch_quota = sema.branch_quota, |
| 8266 | .branch_count = sema.branch_count, | 8221 | .branch_count = sema.branch_count, |
| 8267 | .comptime_err_ret_trace = sema.comptime_err_ret_trace, | 8222 | .comptime_err_ret_trace = sema.comptime_err_ret_trace, |
| ... | @@ -8271,11 +8226,12 @@ fn instantiateGenericCall( | ... | @@ -8271,11 +8226,12 @@ fn instantiateGenericCall( |
| 8271 | var child_block: Block = .{ | 8226 | var child_block: Block = .{ |
| 8272 | .parent = null, | 8227 | .parent = null, |
| 8273 | .sema = &child_sema, | 8228 | .sema = &child_sema, |
| 8274 | .src_decl = generic_owner_func.owner_decl, | | |
| 8275 | .namespace = namespace_index, | 8229 | .namespace = namespace_index, |
| 8276 | .instructions = .{}, | 8230 | .instructions = .{}, |
| 8277 | .inlining = null, | 8231 | .inlining = null, |
| 8278 | .is_comptime = true, | 8232 | .is_comptime = true, |
| | 8233 | .src_base_inst = fn_owner_decl.zir_decl_index.unwrap().?, |
| | 8234 | .type_name_ctx = fn_owner_decl.name, |
| 8279 | }; | 8235 | }; |
| 8280 | defer child_block.instructions.deinit(gpa); | 8236 | defer child_block.instructions.deinit(gpa); |
| 8281 | | 8237 | |
| ... | @@ -8306,22 +8262,23 @@ fn instantiateGenericCall( | ... | @@ -8306,22 +8262,23 @@ fn instantiateGenericCall( |
| 8306 | const prev_no_partial_func_ty = child_sema.no_partial_func_ty; | 8262 | const prev_no_partial_func_ty = child_sema.no_partial_func_ty; |
| 8307 | const prev_generic_owner = child_sema.generic_owner; | 8263 | const prev_generic_owner = child_sema.generic_owner; |
| 8308 | const prev_generic_call_src = child_sema.generic_call_src; | 8264 | const prev_generic_call_src = child_sema.generic_call_src; |
| 8309 | const prev_generic_call_decl = child_sema.generic_call_decl; | | |
| 8310 | child_block.params = .{}; | 8265 | child_block.params = .{}; |
| 8311 | child_sema.no_partial_func_ty = true; | 8266 | child_sema.no_partial_func_ty = true; |
| 8312 | child_sema.generic_owner = .none; | 8267 | child_sema.generic_owner = .none; |
| 8313 | child_sema.generic_call_src = .unneeded; | 8268 | child_sema.generic_call_src = LazySrcLoc.unneeded; |
| 8314 | child_sema.generic_call_decl = .none; | | |
| 8315 | defer { | 8269 | defer { |
| 8316 | child_block.params = prev_params; | 8270 | child_block.params = prev_params; |
| 8317 | child_sema.no_partial_func_ty = prev_no_partial_func_ty; | 8271 | child_sema.no_partial_func_ty = prev_no_partial_func_ty; |
| 8318 | child_sema.generic_owner = prev_generic_owner; | 8272 | child_sema.generic_owner = prev_generic_owner; |
| 8319 | child_sema.generic_call_src = prev_generic_call_src; | 8273 | child_sema.generic_call_src = prev_generic_call_src; |
| 8320 | child_sema.generic_call_decl = prev_generic_call_decl; | | |
| 8321 | } | 8274 | } |
| 8322 | | 8275 | |
| 8323 | const param_ty_inst = try child_sema.resolveInlineBody(&child_block, param_ty_body, param_inst); | 8276 | const param_ty_inst = try child_sema.resolveInlineBody(&child_block, param_ty_body, param_inst); |
| 8324 | break :param_ty try child_sema.analyzeAsType(&child_block, param_data.src(), param_ty_inst); | 8277 | break :param_ty try child_sema.analyzeAsType( |
| | 8278 | &child_block, |
| | 8279 | child_block.tokenOffset(param_data.src_tok), |
| | 8280 | param_ty_inst, |
| | 8281 | ); |
| 8325 | }, | 8282 | }, |
| 8326 | else => unreachable, | 8283 | else => unreachable, |
| 8327 | } | 8284 | } |
| ... | @@ -8353,14 +8310,14 @@ fn instantiateGenericCall( | ... | @@ -8353,14 +8310,14 @@ fn instantiateGenericCall( |
| 8353 | .param_anytype_comptime, | 8310 | .param_anytype_comptime, |
| 8354 | => return sema.failWithOwnedErrorMsg(block, msg: { | 8311 | => return sema.failWithOwnedErrorMsg(block, msg: { |
| 8355 | const arg_src = args_info.argSrc(block, arg_index); | 8312 | const arg_src = args_info.argSrc(block, arg_index); |
| 8356 | const msg = try sema.errMsg(block, arg_src, "runtime-known argument passed to comptime parameter", .{}); | 8313 | const msg = try sema.errMsg(arg_src, "runtime-known argument passed to comptime parameter", .{}); |
| 8357 | errdefer msg.destroy(sema.gpa); | 8314 | errdefer msg.destroy(sema.gpa); |
| 8358 | const param_src = switch (param_tag) { | 8315 | const param_src = child_block.tokenOffset(switch (param_tag) { |
| 8359 | .param_comptime => fn_zir.instructions.items(.data)[@intFromEnum(param_inst)].pl_tok.src(), | 8316 | .param_comptime => fn_zir.instructions.items(.data)[@intFromEnum(param_inst)].pl_tok.src_tok, |
| 8360 | .param_anytype_comptime => fn_zir.instructions.items(.data)[@intFromEnum(param_inst)].str_tok.src(), | 8317 | .param_anytype_comptime => fn_zir.instructions.items(.data)[@intFromEnum(param_inst)].str_tok.src_tok, |
| 8361 | else => unreachable, | 8318 | else => unreachable, |
| 8362 | }; | 8319 | }); |
| 8363 | try child_sema.errNote(&child_block, param_src, msg, "declared comptime here", .{}); | 8320 | try child_sema.errNote(param_src, msg, "declared comptime here", .{}); |
| 8364 | break :msg msg; | 8321 | break :msg msg; |
| 8365 | }), | 8322 | }), |
| 8366 | | 8323 | |
| ... | @@ -8368,16 +8325,15 @@ fn instantiateGenericCall( | ... | @@ -8368,16 +8325,15 @@ fn instantiateGenericCall( |
| 8368 | .param_anytype, | 8325 | .param_anytype, |
| 8369 | => return sema.failWithOwnedErrorMsg(block, msg: { | 8326 | => return sema.failWithOwnedErrorMsg(block, msg: { |
| 8370 | const arg_src = args_info.argSrc(block, arg_index); | 8327 | const arg_src = args_info.argSrc(block, arg_index); |
| 8371 | const msg = try sema.errMsg(block, arg_src, "runtime-known argument passed to parameter of comptime-only type", .{}); | 8328 | const msg = try sema.errMsg(arg_src, "runtime-known argument passed to parameter of comptime-only type", .{}); |
| 8372 | errdefer msg.destroy(sema.gpa); | 8329 | errdefer msg.destroy(sema.gpa); |
| 8373 | const param_src = switch (param_tag) { | 8330 | const param_src = child_block.tokenOffset(switch (param_tag) { |
| 8374 | .param => fn_zir.instructions.items(.data)[@intFromEnum(param_inst)].pl_tok.src(), | 8331 | .param => fn_zir.instructions.items(.data)[@intFromEnum(param_inst)].pl_tok.src_tok, |
| 8375 | .param_anytype => fn_zir.instructions.items(.data)[@intFromEnum(param_inst)].str_tok.src(), | 8332 | .param_anytype => fn_zir.instructions.items(.data)[@intFromEnum(param_inst)].str_tok.src_tok, |
| 8376 | else => unreachable, | 8333 | else => unreachable, |
| 8377 | }; | 8334 | }); |
| 8378 | try child_sema.errNote(&child_block, param_src, msg, "declared here", .{}); | 8335 | try child_sema.errNote(param_src, msg, "declared here", .{}); |
| 8379 | const src_decl = mod.declPtr(block.src_decl); | 8336 | try sema.explainWhyTypeIsComptime(msg, arg_src, arg_ty); |
| 8380 | try sema.explainWhyTypeIsComptime(msg, src_decl.toSrcLoc(arg_src, mod), arg_ty); | | |
| 8381 | break :msg msg; | 8337 | break :msg msg; |
| 8382 | }), | 8338 | }), |
| 8383 | | 8339 | |
| ... | @@ -8414,12 +8370,12 @@ fn instantiateGenericCall( | ... | @@ -8414,12 +8370,12 @@ fn instantiateGenericCall( |
| 8414 | // We've already handled parameters, so don't resolve the whole body. Instead, just | 8370 | // We've already handled parameters, so don't resolve the whole body. Instead, just |
| 8415 | // do the instructions after the params (i.e. the func itself). | 8371 | // do the instructions after the params (i.e. the func itself). |
| 8416 | const new_func_inst = try child_sema.resolveInlineBody(&child_block, fn_info.param_body[args_info.count()..], fn_info.param_body_inst); | 8372 | const new_func_inst = try child_sema.resolveInlineBody(&child_block, fn_info.param_body[args_info.count()..], fn_info.param_body_inst); |
| 8417 | const callee_index = (child_sema.resolveConstDefinedValue(&child_block, .unneeded, new_func_inst, undefined) catch unreachable).toIntern(); | 8373 | const callee_index = (child_sema.resolveConstDefinedValue(&child_block, LazySrcLoc.unneeded, new_func_inst, undefined) catch unreachable).toIntern(); |
| 8418 | | 8374 | |
| 8419 | const callee = mod.funcInfo(callee_index); | 8375 | const callee = mod.funcInfo(callee_index); |
| 8420 | callee.branchQuota(ip).* = @max(callee.branchQuota(ip).*, sema.branch_quota); | 8376 | callee.branchQuota(ip).* = @max(callee.branchQuota(ip).*, sema.branch_quota); |
| 8421 | | 8377 | |
| 8422 | try sema.addReferencedBy(block, call_src, callee.owner_decl); | 8378 | try sema.addReferencedBy(call_src, callee.owner_decl); |
| 8423 | | 8379 | |
| 8424 | // Make a runtime call to the new function, making sure to omit the comptime args. | 8380 | // Make a runtime call to the new function, making sure to omit the comptime args. |
| 8425 | const func_ty = Type.fromInterned(callee.ty); | 8381 | const func_ty = Type.fromInterned(callee.ty); |
| ... | @@ -8501,7 +8457,7 @@ fn zirOptionalType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro | ... | @@ -8501,7 +8457,7 @@ fn zirOptionalType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro |
| 8501 | | 8457 | |
| 8502 | const mod = sema.mod; | 8458 | const mod = sema.mod; |
| 8503 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; | 8459 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 8504 | const operand_src: LazySrcLoc = .{ .node_offset_un_op = inst_data.src_node }; | 8460 | const operand_src = block.src(.{ .node_offset_un_op = inst_data.src_node }); |
| 8505 | const child_type = try sema.resolveType(block, operand_src, inst_data.operand); | 8461 | const child_type = try sema.resolveType(block, operand_src, inst_data.operand); |
| 8506 | if (child_type.zigTypeTag(mod) == .Opaque) { | 8462 | if (child_type.zigTypeTag(mod) == .Opaque) { |
| 8507 | return sema.fail(block, operand_src, "opaque type '{}' cannot be optional", .{child_type.fmt(mod)}); | 8463 | return sema.fail(block, operand_src, "opaque type '{}' cannot be optional", .{child_type.fmt(mod)}); |
| ... | @@ -8516,7 +8472,7 @@ fn zirOptionalType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro | ... | @@ -8516,7 +8472,7 @@ fn zirOptionalType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro |
| 8516 | fn zirArrayInitElemType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 8472 | fn zirArrayInitElemType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 8517 | const mod = sema.mod; | 8473 | const mod = sema.mod; |
| 8518 | const bin = sema.code.instructions.items(.data)[@intFromEnum(inst)].bin; | 8474 | const bin = sema.code.instructions.items(.data)[@intFromEnum(inst)].bin; |
| 8519 | const maybe_wrapped_indexable_ty = sema.resolveType(block, .unneeded, bin.lhs) catch |err| switch (err) { | 8475 | const maybe_wrapped_indexable_ty = sema.resolveType(block, LazySrcLoc.unneeded, bin.lhs) catch |err| switch (err) { |
| 8520 | // Since this is a ZIR instruction that returns a type, encountering | 8476 | // Since this is a ZIR instruction that returns a type, encountering |
| 8521 | // generic poison should not result in a failed compilation, but the | 8477 | // generic poison should not result in a failed compilation, but the |
| 8522 | // generic poison type. This prevents unnecessary failures when | 8478 | // generic poison type. This prevents unnecessary failures when |
| ... | @@ -8539,7 +8495,7 @@ fn zirArrayInitElemType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compil | ... | @@ -8539,7 +8495,7 @@ fn zirArrayInitElemType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compil |
| 8539 | fn zirElemType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 8495 | fn zirElemType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 8540 | const mod = sema.mod; | 8496 | const mod = sema.mod; |
| 8541 | const un_node = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; | 8497 | const un_node = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 8542 | const maybe_wrapped_ptr_ty = sema.resolveType(block, .unneeded, un_node.operand) catch |err| switch (err) { | 8498 | const maybe_wrapped_ptr_ty = sema.resolveType(block, LazySrcLoc.unneeded, un_node.operand) catch |err| switch (err) { |
| 8543 | error.GenericPoison => return .generic_poison_type, | 8499 | error.GenericPoison => return .generic_poison_type, |
| 8544 | else => |e| return e, | 8500 | else => |e| return e, |
| 8545 | }; | 8501 | }; |
| ... | @@ -8557,7 +8513,7 @@ fn zirElemType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -8557,7 +8513,7 @@ fn zirElemType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 8557 | fn zirIndexablePtrElemType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 8513 | fn zirIndexablePtrElemType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 8558 | const mod = sema.mod; | 8514 | const mod = sema.mod; |
| 8559 | const un_node = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; | 8515 | const un_node = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 8560 | const src = un_node.src(); | 8516 | const src = block.nodeOffset(un_node.src_node); |
| 8561 | const ptr_ty = sema.resolveType(block, src, un_node.operand) catch |err| switch (err) { | 8517 | const ptr_ty = sema.resolveType(block, src, un_node.operand) catch |err| switch (err) { |
| 8562 | error.GenericPoison => return .generic_poison_type, | 8518 | error.GenericPoison => return .generic_poison_type, |
| 8563 | else => |e| return e, | 8519 | else => |e| return e, |
| ... | @@ -8573,7 +8529,7 @@ fn zirIndexablePtrElemType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com | ... | @@ -8573,7 +8529,7 @@ fn zirIndexablePtrElemType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com |
| 8573 | fn zirVectorElemType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 8529 | fn zirVectorElemType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 8574 | const mod = sema.mod; | 8530 | const mod = sema.mod; |
| 8575 | const un_node = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; | 8531 | const un_node = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 8576 | const vec_ty = sema.resolveType(block, .unneeded, un_node.operand) catch |err| switch (err) { | 8532 | const vec_ty = sema.resolveType(block, LazySrcLoc.unneeded, un_node.operand) catch |err| switch (err) { |
| 8577 | // Since this is a ZIR instruction that returns a type, encountering | 8533 | // Since this is a ZIR instruction that returns a type, encountering |
| 8578 | // generic poison should not result in a failed compilation, but the | 8534 | // generic poison should not result in a failed compilation, but the |
| 8579 | // generic poison type. This prevents unnecessary failures when | 8535 | // generic poison type. This prevents unnecessary failures when |
| ... | @@ -8582,7 +8538,7 @@ fn zirVectorElemType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr | ... | @@ -8582,7 +8538,7 @@ fn zirVectorElemType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr |
| 8582 | else => |e| return e, | 8538 | else => |e| return e, |
| 8583 | }; | 8539 | }; |
| 8584 | if (!vec_ty.isVector(mod)) { | 8540 | if (!vec_ty.isVector(mod)) { |
| 8585 | return sema.fail(block, un_node.src(), "expected vector type, found '{}'", .{vec_ty.fmt(mod)}); | 8541 | return sema.fail(block, block.nodeOffset(un_node.src_node), "expected vector type, found '{}'", .{vec_ty.fmt(mod)}); |
| 8586 | } | 8542 | } |
| 8587 | return Air.internedToRef(vec_ty.childType(mod).toIntern()); | 8543 | return Air.internedToRef(vec_ty.childType(mod).toIntern()); |
| 8588 | } | 8544 | } |
| ... | @@ -8590,8 +8546,8 @@ fn zirVectorElemType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr | ... | @@ -8590,8 +8546,8 @@ fn zirVectorElemType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr |
| 8590 | fn zirVectorType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 8546 | fn zirVectorType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 8591 | const mod = sema.mod; | 8547 | const mod = sema.mod; |
| 8592 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 8548 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 8593 | const len_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 8549 | const len_src = block.builtinCallArgSrc(inst_data.src_node, 0); |
| 8594 | const elem_type_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; | 8550 | const elem_type_src = block.builtinCallArgSrc(inst_data.src_node, 1); |
| 8595 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; | 8551 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 8596 | const len: u32 = @intCast(try sema.resolveInt(block, len_src, extra.lhs, Type.u32, .{ | 8552 | const len: u32 = @intCast(try sema.resolveInt(block, len_src, extra.lhs, Type.u32, .{ |
| 8597 | .needed_comptime_reason = "vector length must be comptime-known", | 8553 | .needed_comptime_reason = "vector length must be comptime-known", |
| ... | @@ -8611,8 +8567,8 @@ fn zirArrayType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A | ... | @@ -8611,8 +8567,8 @@ fn zirArrayType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 8611 | | 8567 | |
| 8612 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 8568 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 8613 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; | 8569 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 8614 | const len_src: LazySrcLoc = .{ .node_offset_array_type_len = inst_data.src_node }; | 8570 | const len_src = block.src(.{ .node_offset_array_type_len = inst_data.src_node }); |
| 8615 | const elem_src: LazySrcLoc = .{ .node_offset_array_type_elem = inst_data.src_node }; | 8571 | const elem_src = block.src(.{ .node_offset_array_type_elem = inst_data.src_node }); |
| 8616 | const len = try sema.resolveInt(block, len_src, extra.lhs, Type.usize, .{ | 8572 | const len = try sema.resolveInt(block, len_src, extra.lhs, Type.usize, .{ |
| 8617 | .needed_comptime_reason = "array length must be comptime-known", | 8573 | .needed_comptime_reason = "array length must be comptime-known", |
| 8618 | }); | 8574 | }); |
| ... | @@ -8632,9 +8588,9 @@ fn zirArrayTypeSentinel(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compil | ... | @@ -8632,9 +8588,9 @@ fn zirArrayTypeSentinel(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compil |
| 8632 | | 8588 | |
| 8633 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 8589 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 8634 | const extra = sema.code.extraData(Zir.Inst.ArrayTypeSentinel, inst_data.payload_index).data; | 8590 | const extra = sema.code.extraData(Zir.Inst.ArrayTypeSentinel, inst_data.payload_index).data; |
| 8635 | const len_src: LazySrcLoc = .{ .node_offset_array_type_len = inst_data.src_node }; | 8591 | const len_src = block.src(.{ .node_offset_array_type_len = inst_data.src_node }); |
| 8636 | const sentinel_src: LazySrcLoc = .{ .node_offset_array_type_sentinel = inst_data.src_node }; | 8592 | const sentinel_src = block.src(.{ .node_offset_array_type_sentinel = inst_data.src_node }); |
| 8637 | const elem_src: LazySrcLoc = .{ .node_offset_array_type_elem = inst_data.src_node }; | 8593 | const elem_src = block.src(.{ .node_offset_array_type_elem = inst_data.src_node }); |
| 8638 | const len = try sema.resolveInt(block, len_src, extra.len, Type.usize, .{ | 8594 | const len = try sema.resolveInt(block, len_src, extra.len, Type.usize, .{ |
| 8639 | .needed_comptime_reason = "array length must be comptime-known", | 8595 | .needed_comptime_reason = "array length must be comptime-known", |
| 8640 | }); | 8596 | }); |
| ... | @@ -8669,10 +8625,10 @@ fn zirAnyframeType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro | ... | @@ -8669,10 +8625,10 @@ fn zirAnyframeType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro |
| 8669 | | 8625 | |
| 8670 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; | 8626 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 8671 | if (true) { | 8627 | if (true) { |
| 8672 | return sema.failWithUseOfAsync(block, inst_data.src()); | 8628 | return sema.failWithUseOfAsync(block, block.nodeOffset(inst_data.src_node)); |
| 8673 | } | 8629 | } |
| 8674 | const mod = sema.mod; | 8630 | const mod = sema.mod; |
| 8675 | const operand_src: LazySrcLoc = .{ .node_offset_anyframe_type = inst_data.src_node }; | 8631 | const operand_src = block.src(.{ .node_offset_anyframe_type = inst_data.src_node }); |
| 8676 | const return_type = try sema.resolveType(block, operand_src, inst_data.operand); | 8632 | const return_type = try sema.resolveType(block, operand_src, inst_data.operand); |
| 8677 | const anyframe_type = try mod.anyframeType(return_type); | 8633 | const anyframe_type = try mod.anyframeType(return_type); |
| 8678 | | 8634 | |
| ... | @@ -8686,8 +8642,8 @@ fn zirErrorUnionType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr | ... | @@ -8686,8 +8642,8 @@ fn zirErrorUnionType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr |
| 8686 | const mod = sema.mod; | 8642 | const mod = sema.mod; |
| 8687 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 8643 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 8688 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; | 8644 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 8689 | const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node }; | 8645 | const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node }); |
| 8690 | const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node }; | 8646 | const rhs_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node }); |
| 8691 | const error_set = try sema.resolveType(block, lhs_src, extra.lhs); | 8647 | const error_set = try sema.resolveType(block, lhs_src, extra.lhs); |
| 8692 | const payload = try sema.resolveType(block, rhs_src, extra.rhs); | 8648 | const payload = try sema.resolveType(block, rhs_src, extra.rhs); |
| 8693 | | 8649 | |
| ... | @@ -8739,8 +8695,8 @@ fn zirIntFromError(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstD | ... | @@ -8739,8 +8695,8 @@ fn zirIntFromError(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstD |
| 8739 | const mod = sema.mod; | 8695 | const mod = sema.mod; |
| 8740 | const ip = &mod.intern_pool; | 8696 | const ip = &mod.intern_pool; |
| 8741 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; | 8697 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; |
| 8742 | const src = LazySrcLoc.nodeOffset(extra.node); | 8698 | const src = block.nodeOffset(extra.node); |
| 8743 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node }; | 8699 | const operand_src = block.builtinCallArgSrc(extra.node, 0); |
| 8744 | const uncasted_operand = try sema.resolveInst(extra.operand); | 8700 | const uncasted_operand = try sema.resolveInst(extra.operand); |
| 8745 | const operand = try sema.coerce(block, Type.anyerror, uncasted_operand, operand_src); | 8701 | const operand = try sema.coerce(block, Type.anyerror, uncasted_operand, operand_src); |
| 8746 | const err_int_ty = try mod.errorIntType(); | 8702 | const err_int_ty = try mod.errorIntType(); |
| ... | @@ -8782,8 +8738,8 @@ fn zirErrorFromInt(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstD | ... | @@ -8782,8 +8738,8 @@ fn zirErrorFromInt(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstD |
| 8782 | | 8738 | |
| 8783 | const mod = sema.mod; | 8739 | const mod = sema.mod; |
| 8784 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; | 8740 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; |
| 8785 | const src = LazySrcLoc.nodeOffset(extra.node); | 8741 | const src = block.nodeOffset(extra.node); |
| 8786 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node }; | 8742 | const operand_src = block.builtinCallArgSrc(extra.node, 0); |
| 8787 | const uncasted_operand = try sema.resolveInst(extra.operand); | 8743 | const uncasted_operand = try sema.resolveInst(extra.operand); |
| 8788 | const err_int_ty = try mod.errorIntType(); | 8744 | const err_int_ty = try mod.errorIntType(); |
| 8789 | const operand = try sema.coerce(block, err_int_ty, uncasted_operand, operand_src); | 8745 | const operand = try sema.coerce(block, err_int_ty, uncasted_operand, operand_src); |
| ... | @@ -8822,16 +8778,16 @@ fn zirMergeErrorSets(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr | ... | @@ -8822,16 +8778,16 @@ fn zirMergeErrorSets(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr |
| 8822 | const ip = &mod.intern_pool; | 8778 | const ip = &mod.intern_pool; |
| 8823 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 8779 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 8824 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; | 8780 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 8825 | const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node }; | 8781 | const src = block.src(.{ .node_offset_bin_op = inst_data.src_node }); |
| 8826 | const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node }; | 8782 | const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node }); |
| 8827 | const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node }; | 8783 | const rhs_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node }); |
| 8828 | const lhs = try sema.resolveInst(extra.lhs); | 8784 | const lhs = try sema.resolveInst(extra.lhs); |
| 8829 | const rhs = try sema.resolveInst(extra.rhs); | 8785 | const rhs = try sema.resolveInst(extra.rhs); |
| 8830 | if (sema.typeOf(lhs).zigTypeTag(mod) == .Bool and sema.typeOf(rhs).zigTypeTag(mod) == .Bool) { | 8786 | if (sema.typeOf(lhs).zigTypeTag(mod) == .Bool and sema.typeOf(rhs).zigTypeTag(mod) == .Bool) { |
| 8831 | const msg = msg: { | 8787 | const msg = msg: { |
| 8832 | const msg = try sema.errMsg(block, lhs_src, "expected error set type, found 'bool'", .{}); | 8788 | const msg = try sema.errMsg(lhs_src, "expected error set type, found 'bool'", .{}); |
| 8833 | errdefer msg.destroy(sema.gpa); | 8789 | errdefer msg.destroy(sema.gpa); |
| 8834 | try sema.errNote(block, src, msg, "'||' merges error sets; 'or' performs boolean OR", .{}); | 8790 | try sema.errNote(src, msg, "'||' merges error sets; 'or' performs boolean OR", .{}); |
| 8835 | break :msg msg; | 8791 | break :msg msg; |
| 8836 | }; | 8792 | }; |
| 8837 | return sema.failWithOwnedErrorMsg(block, msg); | 8793 | return sema.failWithOwnedErrorMsg(block, msg); |
| ... | @@ -8885,8 +8841,8 @@ fn zirEnumLiteral(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError | ... | @@ -8885,8 +8841,8 @@ fn zirEnumLiteral(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 8885 | fn zirIntFromEnum(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 8841 | fn zirIntFromEnum(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 8886 | const mod = sema.mod; | 8842 | const mod = sema.mod; |
| 8887 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; | 8843 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 8888 | const src = inst_data.src(); | 8844 | const src = block.nodeOffset(inst_data.src_node); |
| 8889 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 8845 | const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0); |
| 8890 | const operand = try sema.resolveInst(inst_data.operand); | 8846 | const operand = try sema.resolveInst(inst_data.operand); |
| 8891 | const operand_ty = sema.typeOf(operand); | 8847 | const operand_ty = sema.typeOf(operand); |
| 8892 | | 8848 | |
| ... | @@ -8943,8 +8899,8 @@ fn zirEnumFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError | ... | @@ -8943,8 +8899,8 @@ fn zirEnumFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 8943 | const mod = sema.mod; | 8899 | const mod = sema.mod; |
| 8944 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 8900 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 8945 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; | 8901 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 8946 | const src = inst_data.src(); | 8902 | const src = block.nodeOffset(inst_data.src_node); |
| 8947 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 8903 | const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0); |
| 8948 | const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu_opt, "@enumFromInt"); | 8904 | const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu_opt, "@enumFromInt"); |
| 8949 | const operand = try sema.resolveInst(extra.rhs); | 8905 | const operand = try sema.resolveInst(extra.rhs); |
| 8950 | | 8906 | |
| ... | @@ -9012,7 +8968,7 @@ fn zirOptionalPayloadPtr( | ... | @@ -9012,7 +8968,7 @@ fn zirOptionalPayloadPtr( |
| 9012 | | 8968 | |
| 9013 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; | 8969 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 9014 | const optional_ptr = try sema.resolveInst(inst_data.operand); | 8970 | const optional_ptr = try sema.resolveInst(inst_data.operand); |
| 9015 | const src = inst_data.src(); | 8971 | const src = block.nodeOffset(inst_data.src_node); |
| 9016 | | 8972 | |
| 9017 | return sema.analyzeOptionalPayloadPtr(block, src, optional_ptr, safety_check, false); | 8973 | return sema.analyzeOptionalPayloadPtr(block, src, optional_ptr, safety_check, false); |
| 9018 | } | 8974 | } |
| ... | @@ -9096,7 +9052,7 @@ fn zirOptionalPayload( | ... | @@ -9096,7 +9052,7 @@ fn zirOptionalPayload( |
| 9096 | | 9052 | |
| 9097 | const mod = sema.mod; | 9053 | const mod = sema.mod; |
| 9098 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; | 9054 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 9099 | const src = inst_data.src(); | 9055 | const src = block.nodeOffset(inst_data.src_node); |
| 9100 | const operand = try sema.resolveInst(inst_data.operand); | 9056 | const operand = try sema.resolveInst(inst_data.operand); |
| 9101 | const operand_ty = sema.typeOf(operand); | 9057 | const operand_ty = sema.typeOf(operand); |
| 9102 | const result_ty = switch (operand_ty.zigTypeTag(mod)) { | 9058 | const result_ty = switch (operand_ty.zigTypeTag(mod)) { |
| ... | @@ -9148,7 +9104,7 @@ fn zirErrUnionPayload( | ... | @@ -9148,7 +9104,7 @@ fn zirErrUnionPayload( |
| 9148 | | 9104 | |
| 9149 | const mod = sema.mod; | 9105 | const mod = sema.mod; |
| 9150 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; | 9106 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 9151 | const src = inst_data.src(); | 9107 | const src = block.nodeOffset(inst_data.src_node); |
| 9152 | const operand = try sema.resolveInst(inst_data.operand); | 9108 | const operand = try sema.resolveInst(inst_data.operand); |
| 9153 | const operand_src = src; | 9109 | const operand_src = src; |
| 9154 | const err_union_ty = sema.typeOf(operand); | 9110 | const err_union_ty = sema.typeOf(operand); |
| ... | @@ -9201,7 +9157,7 @@ fn zirErrUnionPayloadPtr( | ... | @@ -9201,7 +9157,7 @@ fn zirErrUnionPayloadPtr( |
| 9201 | | 9157 | |
| 9202 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; | 9158 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 9203 | const operand = try sema.resolveInst(inst_data.operand); | 9159 | const operand = try sema.resolveInst(inst_data.operand); |
| 9204 | const src = inst_data.src(); | 9160 | const src = block.nodeOffset(inst_data.src_node); |
| 9205 | | 9161 | |
| 9206 | return sema.analyzeErrUnionPayloadPtr(block, src, operand, false, false); | 9162 | return sema.analyzeErrUnionPayloadPtr(block, src, operand, false, false); |
| 9207 | } | 9163 | } |
| ... | @@ -9285,7 +9241,7 @@ fn zirErrUnionCode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro | ... | @@ -9285,7 +9241,7 @@ fn zirErrUnionCode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro |
| 9285 | defer tracy.end(); | 9241 | defer tracy.end(); |
| 9286 | | 9242 | |
| 9287 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; | 9243 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 9288 | const src = inst_data.src(); | 9244 | const src = block.nodeOffset(inst_data.src_node); |
| 9289 | const operand = try sema.resolveInst(inst_data.operand); | 9245 | const operand = try sema.resolveInst(inst_data.operand); |
| 9290 | return sema.analyzeErrUnionCode(block, src, operand); | 9246 | return sema.analyzeErrUnionCode(block, src, operand); |
| 9291 | } | 9247 | } |
| ... | @@ -9318,7 +9274,7 @@ fn zirErrUnionCodePtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE | ... | @@ -9318,7 +9274,7 @@ fn zirErrUnionCodePtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE |
| 9318 | defer tracy.end(); | 9274 | defer tracy.end(); |
| 9319 | | 9275 | |
| 9320 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; | 9276 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 9321 | const src = inst_data.src(); | 9277 | const src = block.nodeOffset(inst_data.src_node); |
| 9322 | const operand = try sema.resolveInst(inst_data.operand); | 9278 | const operand = try sema.resolveInst(inst_data.operand); |
| 9323 | return sema.analyzeErrUnionCodePtr(block, src, operand); | 9279 | return sema.analyzeErrUnionCodePtr(block, src, operand); |
| 9324 | } | 9280 | } |
| ... | @@ -9360,7 +9316,7 @@ fn zirFunc( | ... | @@ -9360,7 +9316,7 @@ fn zirFunc( |
| 9360 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 9316 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 9361 | const extra = sema.code.extraData(Zir.Inst.Func, inst_data.payload_index); | 9317 | const extra = sema.code.extraData(Zir.Inst.Func, inst_data.payload_index); |
| 9362 | const target = sema.mod.getTarget(); | 9318 | const target = sema.mod.getTarget(); |
| 9363 | const ret_ty_src: LazySrcLoc = .{ .node_offset_fn_type_ret_ty = inst_data.src_node }; | 9319 | const ret_ty_src = block.src(.{ .node_offset_fn_type_ret_ty = inst_data.src_node }); |
| 9364 | | 9320 | |
| 9365 | var extra_index = extra.end; | 9321 | var extra_index = extra.end; |
| 9366 | | 9322 | |
| ... | @@ -9396,13 +9352,17 @@ fn zirFunc( | ... | @@ -9396,13 +9352,17 @@ fn zirFunc( |
| 9396 | src_locs = sema.code.extraData(Zir.Inst.Func.SrcLocs, extra_index).data; | 9352 | src_locs = sema.code.extraData(Zir.Inst.Func.SrcLocs, extra_index).data; |
| 9397 | } | 9353 | } |
| 9398 | | 9354 | |
| 9399 | // If this instruction has a body it means it's the type of the `owner_decl` | 9355 | // If this instruction has a body, then it's a function declaration, and we decide |
| 9400 | // otherwise it's a function type without a `callconv` attribute and should | 9356 | // the callconv based on whether it is exported. Otherwise, the callconv defaults |
| 9401 | // never be `.C`. | 9357 | // to `.Unspecified`. |
| 9402 | const cc: std.builtin.CallingConvention = if (has_body and mod.declPtr(block.src_decl).is_exported) | 9358 | const cc: std.builtin.CallingConvention = if (has_body) cc: { |
| 9403 | .C | 9359 | const fn_is_exported = if (sema.generic_owner != .none) exported: { |
| 9404 | else | 9360 | const generic_owner_fn = mod.funcInfo(sema.generic_owner); |
| 9405 | .Unspecified; | 9361 | const generic_owner_decl = mod.declPtr(generic_owner_fn.owner_decl); |
| | 9362 | break :exported generic_owner_decl.is_exported; |
| | 9363 | } else sema.owner_decl.is_exported; |
| | 9364 | break :cc if (fn_is_exported) .C else .Unspecified; |
| | 9365 | } else .Unspecified; |
| 9406 | | 9366 | |
| 9407 | return sema.funcCommon( | 9367 | return sema.funcCommon( |
| 9408 | block, | 9368 | block, |
| ... | @@ -9441,18 +9401,15 @@ fn resolveGenericBody( | ... | @@ -9441,18 +9401,15 @@ fn resolveGenericBody( |
| 9441 | const prev_no_partial_func_type = sema.no_partial_func_ty; | 9401 | const prev_no_partial_func_type = sema.no_partial_func_ty; |
| 9442 | const prev_generic_owner = sema.generic_owner; | 9402 | const prev_generic_owner = sema.generic_owner; |
| 9443 | const prev_generic_call_src = sema.generic_call_src; | 9403 | const prev_generic_call_src = sema.generic_call_src; |
| 9444 | const prev_generic_call_decl = sema.generic_call_decl; | | |
| 9445 | block.params = .{}; | 9404 | block.params = .{}; |
| 9446 | sema.no_partial_func_ty = true; | 9405 | sema.no_partial_func_ty = true; |
| 9447 | sema.generic_owner = .none; | 9406 | sema.generic_owner = .none; |
| 9448 | sema.generic_call_src = .unneeded; | 9407 | sema.generic_call_src = LazySrcLoc.unneeded; |
| 9449 | sema.generic_call_decl = .none; | | |
| 9450 | defer { | 9408 | defer { |
| 9451 | block.params = prev_params; | 9409 | block.params = prev_params; |
| 9452 | sema.no_partial_func_ty = prev_no_partial_func_type; | 9410 | sema.no_partial_func_ty = prev_no_partial_func_type; |
| 9453 | sema.generic_owner = prev_generic_owner; | 9411 | sema.generic_owner = prev_generic_owner; |
| 9454 | sema.generic_call_src = prev_generic_call_src; | 9412 | sema.generic_call_src = prev_generic_call_src; |
| 9455 | sema.generic_call_decl = prev_generic_call_decl; | | |
| 9456 | } | 9413 | } |
| 9457 | | 9414 | |
| 9458 | const uncasted = sema.resolveInlineBody(block, body, func_inst) catch |err| break :err err; | 9415 | const uncasted = sema.resolveInlineBody(block, body, func_inst) catch |err| break :err err; |
| ... | @@ -9562,9 +9519,9 @@ fn checkCallConvSupportsVarArgs(sema: *Sema, block: *Block, src: LazySrcLoc, cc: | ... | @@ -9562,9 +9519,9 @@ fn checkCallConvSupportsVarArgs(sema: *Sema, block: *Block, src: LazySrcLoc, cc: |
| 9562 | | 9519 | |
| 9563 | if (!callConvSupportsVarArgs(cc)) { | 9520 | if (!callConvSupportsVarArgs(cc)) { |
| 9564 | const msg = msg: { | 9521 | const msg = msg: { |
| 9565 | const msg = try sema.errMsg(block, src, "variadic function does not support '.{s}' calling convention", .{@tagName(cc)}); | 9522 | const msg = try sema.errMsg(src, "variadic function does not support '.{s}' calling convention", .{@tagName(cc)}); |
| 9566 | errdefer msg.destroy(sema.gpa); | 9523 | errdefer msg.destroy(sema.gpa); |
| 9567 | try sema.errNote(block, src, msg, "supported calling conventions: {}", .{CallingConventionsSupportingVarArgsList{}}); | 9524 | try sema.errNote(src, msg, "supported calling conventions: {}", .{CallingConventionsSupportingVarArgsList{}}); |
| 9568 | break :msg msg; | 9525 | break :msg msg; |
| 9569 | }; | 9526 | }; |
| 9570 | return sema.failWithOwnedErrorMsg(block, msg); | 9527 | return sema.failWithOwnedErrorMsg(block, msg); |
| ... | @@ -9604,9 +9561,9 @@ fn funcCommon( | ... | @@ -9604,9 +9561,9 @@ fn funcCommon( |
| 9604 | const gpa = sema.gpa; | 9561 | const gpa = sema.gpa; |
| 9605 | const target = mod.getTarget(); | 9562 | const target = mod.getTarget(); |
| 9606 | const ip = &mod.intern_pool; | 9563 | const ip = &mod.intern_pool; |
| 9607 | const ret_ty_src: LazySrcLoc = .{ .node_offset_fn_type_ret_ty = src_node_offset }; | 9564 | const ret_ty_src = block.src(.{ .node_offset_fn_type_ret_ty = src_node_offset }); |
| 9608 | const cc_src: LazySrcLoc = .{ .node_offset_fn_type_cc = src_node_offset }; | 9565 | const cc_src = block.src(.{ .node_offset_fn_type_cc = src_node_offset }); |
| 9609 | const func_src = LazySrcLoc.nodeOffset(src_node_offset); | 9566 | const func_src = block.nodeOffset(src_node_offset); |
| 9610 | | 9567 | |
| 9611 | var is_generic = bare_return_type.isGenericPoison() or | 9568 | var is_generic = bare_return_type.isGenericPoison() or |
| 9612 | alignment == null or | 9569 | alignment == null or |
| ... | @@ -9635,11 +9592,10 @@ fn funcCommon( | ... | @@ -9635,11 +9592,10 @@ fn funcCommon( |
| 9635 | const index = std.math.cast(u5, i) orelse break :blk false; | 9592 | const index = std.math.cast(u5, i) orelse break :blk false; |
| 9636 | break :blk @as(u1, @truncate(noalias_bits >> index)) != 0; | 9593 | break :blk @as(u1, @truncate(noalias_bits >> index)) != 0; |
| 9637 | }; | 9594 | }; |
| 9638 | const param_src: LazySrcLoc = .{ .fn_proto_param = .{ | 9595 | const param_src = block.src(.{ .fn_proto_param = .{ |
| 9639 | .decl = block.src_decl, | | |
| 9640 | .fn_proto_node_offset = src_node_offset, | 9596 | .fn_proto_node_offset = src_node_offset, |
| 9641 | .param_index = @intCast(i), | 9597 | .param_index = @intCast(i), |
| 9642 | } }; | 9598 | } }); |
| 9643 | const requires_comptime = try sema.typeRequiresComptime(param_ty); | 9599 | const requires_comptime = try sema.typeRequiresComptime(param_ty); |
| 9644 | if (param_is_comptime or requires_comptime) { | 9600 | if (param_is_comptime or requires_comptime) { |
| 9645 | comptime_bits |= @as(u32, 1) << @intCast(i); // TODO: handle cast error | 9601 | comptime_bits |= @as(u32, 1) << @intCast(i); // TODO: handle cast error |
| ... | @@ -9660,13 +9616,12 @@ fn funcCommon( | ... | @@ -9660,13 +9616,12 @@ fn funcCommon( |
| 9660 | } | 9616 | } |
| 9661 | if (!this_generic and !target_util.fnCallConvAllowsZigTypes(target, cc_resolved) and !try sema.validateExternType(param_ty, .param_ty)) { | 9617 | if (!this_generic and !target_util.fnCallConvAllowsZigTypes(target, cc_resolved) and !try sema.validateExternType(param_ty, .param_ty)) { |
| 9662 | const msg = msg: { | 9618 | const msg = msg: { |
| 9663 | const msg = try sema.errMsg(block, param_src, "parameter of type '{}' not allowed in function with calling convention '{s}'", .{ | 9619 | const msg = try sema.errMsg(param_src, "parameter of type '{}' not allowed in function with calling convention '{s}'", .{ |
| 9664 | param_ty.fmt(mod), @tagName(cc_resolved), | 9620 | param_ty.fmt(mod), @tagName(cc_resolved), |
| 9665 | }); | 9621 | }); |
| 9666 | errdefer msg.destroy(sema.gpa); | 9622 | errdefer msg.destroy(sema.gpa); |
| 9667 | | 9623 | |
| 9668 | const src_decl = mod.declPtr(block.src_decl); | 9624 | try sema.explainWhyTypeIsNotExtern(msg, param_src, param_ty, .param_ty); |
| 9669 | try sema.explainWhyTypeIsNotExtern(msg, src_decl.toSrcLoc(param_src, mod), param_ty, .param_ty); | | |
| 9670 | | 9625 | |
| 9671 | try sema.addDeclaredHereNote(msg, param_ty); | 9626 | try sema.addDeclaredHereNote(msg, param_ty); |
| 9672 | break :msg msg; | 9627 | break :msg msg; |
| ... | @@ -9675,13 +9630,12 @@ fn funcCommon( | ... | @@ -9675,13 +9630,12 @@ fn funcCommon( |
| 9675 | } | 9630 | } |
| 9676 | if (is_source_decl and requires_comptime and !param_is_comptime and has_body and !block.is_comptime) { | 9631 | if (is_source_decl and requires_comptime and !param_is_comptime and has_body and !block.is_comptime) { |
| 9677 | const msg = msg: { | 9632 | const msg = msg: { |
| 9678 | const msg = try sema.errMsg(block, param_src, "parameter of type '{}' must be declared comptime", .{ | 9633 | const msg = try sema.errMsg(param_src, "parameter of type '{}' must be declared comptime", .{ |
| 9679 | param_ty.fmt(mod), | 9634 | param_ty.fmt(mod), |
| 9680 | }); | 9635 | }); |
| 9681 | errdefer msg.destroy(sema.gpa); | 9636 | errdefer msg.destroy(sema.gpa); |
| 9682 | | 9637 | |
| 9683 | const src_decl = mod.declPtr(block.src_decl); | 9638 | try sema.explainWhyTypeIsComptime(msg, param_src, param_ty); |
| 9684 | try sema.explainWhyTypeIsComptime(msg, src_decl.toSrcLoc(param_src, mod), param_ty); | | |
| 9685 | | 9639 | |
| 9686 | try sema.addDeclaredHereNote(msg, param_ty); | 9640 | try sema.addDeclaredHereNote(msg, param_ty); |
| 9687 | break :msg msg; | 9641 | break :msg msg; |
| ... | @@ -9842,9 +9796,9 @@ fn funcCommon( | ... | @@ -9842,9 +9796,9 @@ fn funcCommon( |
| 9842 | assert(section != .generic); | 9796 | assert(section != .generic); |
| 9843 | assert(address_space != null); | 9797 | assert(address_space != null); |
| 9844 | assert(!is_generic); | 9798 | assert(!is_generic); |
| 9845 | if (opt_lib_name) |lib_name| try sema.handleExternLibName(block, .{ | 9799 | if (opt_lib_name) |lib_name| try sema.handleExternLibName(block, block.src(.{ |
| 9846 | .node_offset_lib_name = src_node_offset, | 9800 | .node_offset_lib_name = src_node_offset, |
| 9847 | }, lib_name); | 9801 | }), lib_name); |
| 9848 | const func_index = try ip.getExternFunc(gpa, .{ | 9802 | const func_index = try ip.getExternFunc(gpa, .{ |
| 9849 | .ty = func_ty, | 9803 | .ty = func_ty, |
| 9850 | .decl = sema.owner_decl_index, | 9804 | .decl = sema.owner_decl_index, |
| ... | @@ -9956,13 +9910,12 @@ fn finishFunc( | ... | @@ -9956,13 +9910,12 @@ fn finishFunc( |
| 9956 | !try sema.validateExternType(return_type, .ret_ty)) | 9910 | !try sema.validateExternType(return_type, .ret_ty)) |
| 9957 | { | 9911 | { |
| 9958 | const msg = msg: { | 9912 | const msg = msg: { |
| 9959 | const msg = try sema.errMsg(block, ret_ty_src, "return type '{}' not allowed in function with calling convention '{s}'", .{ | 9913 | const msg = try sema.errMsg(ret_ty_src, "return type '{}' not allowed in function with calling convention '{s}'", .{ |
| 9960 | return_type.fmt(mod), @tagName(cc_resolved), | 9914 | return_type.fmt(mod), @tagName(cc_resolved), |
| 9961 | }); | 9915 | }); |
| 9962 | errdefer msg.destroy(gpa); | 9916 | errdefer msg.destroy(gpa); |
| 9963 | | 9917 | |
| 9964 | const src_decl = mod.declPtr(block.src_decl); | 9918 | try sema.explainWhyTypeIsNotExtern(msg, ret_ty_src, return_type, .ret_ty); |
| 9965 | try sema.explainWhyTypeIsNotExtern(msg, src_decl.toSrcLoc(ret_ty_src, mod), return_type, .ret_ty); | | |
| 9966 | | 9919 | |
| 9967 | try sema.addDeclaredHereNote(msg, return_type); | 9920 | try sema.addDeclaredHereNote(msg, return_type); |
| 9968 | break :msg msg; | 9921 | break :msg msg; |
| ... | @@ -9978,12 +9931,11 @@ fn finishFunc( | ... | @@ -9978,12 +9931,11 @@ fn finishFunc( |
| 9978 | } else break :comptime_check; | 9931 | } else break :comptime_check; |
| 9979 | | 9932 | |
| 9980 | const msg = try sema.errMsg( | 9933 | const msg = try sema.errMsg( |
| 9981 | block, | | |
| 9982 | ret_ty_src, | 9934 | ret_ty_src, |
| 9983 | "function with comptime-only return type '{}' requires all parameters to be comptime", | 9935 | "function with comptime-only return type '{}' requires all parameters to be comptime", |
| 9984 | .{return_type.fmt(mod)}, | 9936 | .{return_type.fmt(mod)}, |
| 9985 | ); | 9937 | ); |
| 9986 | try sema.explainWhyTypeIsComptime(msg, sema.owner_decl.toSrcLoc(ret_ty_src, mod), return_type); | 9938 | try sema.explainWhyTypeIsComptime(msg, ret_ty_src, return_type); |
| 9987 | | 9939 | |
| 9988 | const tags = sema.code.instructions.items(.tag); | 9940 | const tags = sema.code.instructions.items(.tag); |
| 9989 | const data = sema.code.instructions.items(.data); | 9941 | const data = sema.code.instructions.items(.data); |
| ... | @@ -9994,16 +9946,16 @@ fn finishFunc( | ... | @@ -9994,16 +9946,16 @@ fn finishFunc( |
| 9994 | param_body[0..block.params.len], | 9946 | param_body[0..block.params.len], |
| 9995 | ) |is_comptime, name_nts, param_index| { | 9947 | ) |is_comptime, name_nts, param_index| { |
| 9996 | if (!is_comptime) { | 9948 | if (!is_comptime) { |
| 9997 | const param_src = switch (tags[@intFromEnum(param_index)]) { | 9949 | const param_src = block.tokenOffset(switch (tags[@intFromEnum(param_index)]) { |
| 9998 | .param => data[@intFromEnum(param_index)].pl_tok.src(), | 9950 | .param => data[@intFromEnum(param_index)].pl_tok.src_tok, |
| 9999 | .param_anytype => data[@intFromEnum(param_index)].str_tok.src(), | 9951 | .param_anytype => data[@intFromEnum(param_index)].str_tok.src_tok, |
| 10000 | else => unreachable, | 9952 | else => unreachable, |
| 10001 | }; | 9953 | }); |
| 10002 | const name = sema.code.nullTerminatedString(name_nts); | 9954 | const name = sema.code.nullTerminatedString(name_nts); |
| 10003 | if (name.len != 0) { | 9955 | if (name.len != 0) { |
| 10004 | try sema.errNote(block, param_src, msg, "param '{s}' is required to be comptime", .{name}); | 9956 | try sema.errNote(param_src, msg, "param '{s}' is required to be comptime", .{name}); |
| 10005 | } else { | 9957 | } else { |
| 10006 | try sema.errNote(block, param_src, msg, "param is required to be comptime", .{}); | 9958 | try sema.errNote(param_src, msg, "param is required to be comptime", .{}); |
| 10007 | } | 9959 | } |
| 10008 | } | 9960 | } |
| 10009 | } | 9961 | } |
| ... | @@ -10081,7 +10033,7 @@ fn zirParam( | ... | @@ -10081,7 +10033,7 @@ fn zirParam( |
| 10081 | comptime_syntax: bool, | 10033 | comptime_syntax: bool, |
| 10082 | ) CompileError!void { | 10034 | ) CompileError!void { |
| 10083 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_tok; | 10035 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_tok; |
| 10084 | const src = inst_data.src(); | 10036 | const src = block.tokenOffset(inst_data.src_tok); |
| 10085 | const extra = sema.code.extraData(Zir.Inst.Param, inst_data.payload_index); | 10037 | const extra = sema.code.extraData(Zir.Inst.Param, inst_data.payload_index); |
| 10086 | const param_name: Zir.NullTerminatedString = extra.data.name; | 10038 | const param_name: Zir.NullTerminatedString = extra.data.name; |
| 10087 | const body = sema.code.bodySlice(extra.end, extra.data.body_len); | 10039 | const body = sema.code.bodySlice(extra.end, extra.data.body_len); |
| ... | @@ -10093,18 +10045,15 @@ fn zirParam( | ... | @@ -10093,18 +10045,15 @@ fn zirParam( |
| 10093 | const prev_no_partial_func_type = sema.no_partial_func_ty; | 10045 | const prev_no_partial_func_type = sema.no_partial_func_ty; |
| 10094 | const prev_generic_owner = sema.generic_owner; | 10046 | const prev_generic_owner = sema.generic_owner; |
| 10095 | const prev_generic_call_src = sema.generic_call_src; | 10047 | const prev_generic_call_src = sema.generic_call_src; |
| 10096 | const prev_generic_call_decl = sema.generic_call_decl; | | |
| 10097 | block.params = .{}; | 10048 | block.params = .{}; |
| 10098 | sema.no_partial_func_ty = true; | 10049 | sema.no_partial_func_ty = true; |
| 10099 | sema.generic_owner = .none; | 10050 | sema.generic_owner = .none; |
| 10100 | sema.generic_call_src = .unneeded; | 10051 | sema.generic_call_src = LazySrcLoc.unneeded; |
| 10101 | sema.generic_call_decl = .none; | | |
| 10102 | defer { | 10052 | defer { |
| 10103 | block.params = prev_params; | 10053 | block.params = prev_params; |
| 10104 | sema.no_partial_func_ty = prev_no_partial_func_type; | 10054 | sema.no_partial_func_ty = prev_no_partial_func_type; |
| 10105 | sema.generic_owner = prev_generic_owner; | 10055 | sema.generic_owner = prev_generic_owner; |
| 10106 | sema.generic_call_src = prev_generic_call_src; | 10056 | sema.generic_call_src = prev_generic_call_src; |
| 10107 | sema.generic_call_decl = prev_generic_call_decl; | | |
| 10108 | } | 10057 | } |
| 10109 | | 10058 | |
| 10110 | if (sema.resolveInlineBody(block, body, inst)) |param_ty_inst| { | 10059 | if (sema.resolveInlineBody(block, body, inst)) |param_ty_inst| { |
| ... | @@ -10191,7 +10140,7 @@ fn zirAsNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. | ... | @@ -10191,7 +10140,7 @@ fn zirAsNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. |
| 10191 | defer tracy.end(); | 10140 | defer tracy.end(); |
| 10192 | | 10141 | |
| 10193 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 10142 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 10194 | const src = inst_data.src(); | 10143 | const src = block.nodeOffset(inst_data.src_node); |
| 10195 | const extra = sema.code.extraData(Zir.Inst.As, inst_data.payload_index).data; | 10144 | const extra = sema.code.extraData(Zir.Inst.As, inst_data.payload_index).data; |
| 10196 | return sema.analyzeAs(block, src, extra.dest_type, extra.operand, false); | 10145 | return sema.analyzeAs(block, src, extra.dest_type, extra.operand, false); |
| 10197 | } | 10146 | } |
| ... | @@ -10201,7 +10150,7 @@ fn zirAsShiftOperand(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr | ... | @@ -10201,7 +10150,7 @@ fn zirAsShiftOperand(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr |
| 10201 | defer tracy.end(); | 10150 | defer tracy.end(); |
| 10202 | | 10151 | |
| 10203 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 10152 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 10204 | const src = inst_data.src(); | 10153 | const src = block.nodeOffset(inst_data.src_node); |
| 10205 | const extra = sema.code.extraData(Zir.Inst.As, inst_data.payload_index).data; | 10154 | const extra = sema.code.extraData(Zir.Inst.As, inst_data.payload_index).data; |
| 10206 | return sema.analyzeAs(block, src, extra.dest_type, extra.operand, true); | 10155 | return sema.analyzeAs(block, src, extra.dest_type, extra.operand, true); |
| 10207 | } | 10156 | } |
| ... | @@ -10246,7 +10195,7 @@ fn zirIntFromPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! | ... | @@ -10246,7 +10195,7 @@ fn zirIntFromPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! |
| 10246 | | 10195 | |
| 10247 | const zcu = sema.mod; | 10196 | const zcu = sema.mod; |
| 10248 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; | 10197 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 10249 | const ptr_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 10198 | const ptr_src = block.builtinCallArgSrc(inst_data.src_node, 0); |
| 10250 | const operand = try sema.resolveInst(inst_data.operand); | 10199 | const operand = try sema.resolveInst(inst_data.operand); |
| 10251 | const operand_ty = sema.typeOf(operand); | 10200 | const operand_ty = sema.typeOf(operand); |
| 10252 | const ptr_ty = operand_ty.scalarType(zcu); | 10201 | const ptr_ty = operand_ty.scalarType(zcu); |
| ... | @@ -10257,10 +10206,9 @@ fn zirIntFromPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! | ... | @@ -10257,10 +10206,9 @@ fn zirIntFromPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! |
| 10257 | const pointee_ty = ptr_ty.childType(zcu); | 10206 | const pointee_ty = ptr_ty.childType(zcu); |
| 10258 | if (try sema.typeRequiresComptime(ptr_ty)) { | 10207 | if (try sema.typeRequiresComptime(ptr_ty)) { |
| 10259 | const msg = msg: { | 10208 | const msg = msg: { |
| 10260 | const msg = try sema.errMsg(block, ptr_src, "comptime-only type '{}' has no pointer address", .{pointee_ty.fmt(zcu)}); | 10209 | const msg = try sema.errMsg(ptr_src, "comptime-only type '{}' has no pointer address", .{pointee_ty.fmt(zcu)}); |
| 10261 | errdefer msg.destroy(sema.gpa); | 10210 | errdefer msg.destroy(sema.gpa); |
| 10262 | const src_decl = zcu.declPtr(block.src_decl); | 10211 | try sema.explainWhyTypeIsComptime(msg, ptr_src, pointee_ty); |
| 10263 | try sema.explainWhyTypeIsComptime(msg, src_decl.toSrcLoc(ptr_src, zcu), pointee_ty); | | |
| 10264 | break :msg msg; | 10212 | break :msg msg; |
| 10265 | }; | 10213 | }; |
| 10266 | return sema.failWithOwnedErrorMsg(block, msg); | 10214 | return sema.failWithOwnedErrorMsg(block, msg); |
| ... | @@ -10298,7 +10246,7 @@ fn zirIntFromPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! | ... | @@ -10298,7 +10246,7 @@ fn zirIntFromPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! |
| 10298 | .storage = .{ .elems = new_elems }, | 10246 | .storage = .{ .elems = new_elems }, |
| 10299 | } })); | 10247 | } })); |
| 10300 | } | 10248 | } |
| 10301 | try sema.requireRuntimeBlock(block, inst_data.src(), ptr_src); | 10249 | try sema.requireRuntimeBlock(block, block.nodeOffset(inst_data.src_node), ptr_src); |
| 10302 | try sema.validateRuntimeValue(block, ptr_src, operand); | 10250 | try sema.validateRuntimeValue(block, ptr_src, operand); |
| 10303 | if (!is_vector) { | 10251 | if (!is_vector) { |
| 10304 | return block.addUnOp(.int_from_ptr, operand); | 10252 | return block.addUnOp(.int_from_ptr, operand); |
| ... | @@ -10320,8 +10268,8 @@ fn zirFieldVal(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -10320,8 +10268,8 @@ fn zirFieldVal(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 10320 | | 10268 | |
| 10321 | const mod = sema.mod; | 10269 | const mod = sema.mod; |
| 10322 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 10270 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 10323 | const src = inst_data.src(); | 10271 | const src = block.nodeOffset(inst_data.src_node); |
| 10324 | const field_name_src: LazySrcLoc = .{ .node_offset_field_name = inst_data.src_node }; | 10272 | const field_name_src = block.src(.{ .node_offset_field_name = inst_data.src_node }); |
| 10325 | const extra = sema.code.extraData(Zir.Inst.Field, inst_data.payload_index).data; | 10273 | const extra = sema.code.extraData(Zir.Inst.Field, inst_data.payload_index).data; |
| 10326 | const field_name = try mod.intern_pool.getOrPutString( | 10274 | const field_name = try mod.intern_pool.getOrPutString( |
| 10327 | sema.gpa, | 10275 | sema.gpa, |
| ... | @@ -10338,8 +10286,8 @@ fn zirFieldPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -10338,8 +10286,8 @@ fn zirFieldPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 10338 | | 10286 | |
| 10339 | const mod = sema.mod; | 10287 | const mod = sema.mod; |
| 10340 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 10288 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 10341 | const src = inst_data.src(); | 10289 | const src = block.nodeOffset(inst_data.src_node); |
| 10342 | const field_name_src: LazySrcLoc = .{ .node_offset_field_name = inst_data.src_node }; | 10290 | const field_name_src = block.src(.{ .node_offset_field_name = inst_data.src_node }); |
| 10343 | const extra = sema.code.extraData(Zir.Inst.Field, inst_data.payload_index).data; | 10291 | const extra = sema.code.extraData(Zir.Inst.Field, inst_data.payload_index).data; |
| 10344 | const field_name = try mod.intern_pool.getOrPutString( | 10292 | const field_name = try mod.intern_pool.getOrPutString( |
| 10345 | sema.gpa, | 10293 | sema.gpa, |
| ... | @@ -10356,8 +10304,8 @@ fn zirStructInitFieldPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compi | ... | @@ -10356,8 +10304,8 @@ fn zirStructInitFieldPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compi |
| 10356 | | 10304 | |
| 10357 | const mod = sema.mod; | 10305 | const mod = sema.mod; |
| 10358 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 10306 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 10359 | const src = inst_data.src(); | 10307 | const src = block.nodeOffset(inst_data.src_node); |
| 10360 | const field_name_src: LazySrcLoc = .{ .node_offset_field_name_init = inst_data.src_node }; | 10308 | const field_name_src = block.src(.{ .node_offset_field_name_init = inst_data.src_node }); |
| 10361 | const extra = sema.code.extraData(Zir.Inst.Field, inst_data.payload_index).data; | 10309 | const extra = sema.code.extraData(Zir.Inst.Field, inst_data.payload_index).data; |
| 10362 | const field_name = try mod.intern_pool.getOrPutString( | 10310 | const field_name = try mod.intern_pool.getOrPutString( |
| 10363 | sema.gpa, | 10311 | sema.gpa, |
| ... | @@ -10381,8 +10329,8 @@ fn zirFieldValNamed(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr | ... | @@ -10381,8 +10329,8 @@ fn zirFieldValNamed(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr |
| 10381 | defer tracy.end(); | 10329 | defer tracy.end(); |
| 10382 | | 10330 | |
| 10383 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 10331 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 10384 | const src = inst_data.src(); | 10332 | const src = block.nodeOffset(inst_data.src_node); |
| 10385 | const field_name_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; | 10333 | const field_name_src = block.builtinCallArgSrc(inst_data.src_node, 1); |
| 10386 | const extra = sema.code.extraData(Zir.Inst.FieldNamed, inst_data.payload_index).data; | 10334 | const extra = sema.code.extraData(Zir.Inst.FieldNamed, inst_data.payload_index).data; |
| 10387 | const object = try sema.resolveInst(extra.lhs); | 10335 | const object = try sema.resolveInst(extra.lhs); |
| 10388 | const field_name = try sema.resolveConstStringIntern(block, field_name_src, extra.field_name, .{ | 10336 | const field_name = try sema.resolveConstStringIntern(block, field_name_src, extra.field_name, .{ |
| ... | @@ -10396,8 +10344,8 @@ fn zirFieldPtrNamed(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr | ... | @@ -10396,8 +10344,8 @@ fn zirFieldPtrNamed(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr |
| 10396 | defer tracy.end(); | 10344 | defer tracy.end(); |
| 10397 | | 10345 | |
| 10398 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 10346 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 10399 | const src = inst_data.src(); | 10347 | const src = block.nodeOffset(inst_data.src_node); |
| 10400 | const field_name_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; | 10348 | const field_name_src = block.builtinCallArgSrc(inst_data.src_node, 1); |
| 10401 | const extra = sema.code.extraData(Zir.Inst.FieldNamed, inst_data.payload_index).data; | 10349 | const extra = sema.code.extraData(Zir.Inst.FieldNamed, inst_data.payload_index).data; |
| 10402 | const object_ptr = try sema.resolveInst(extra.lhs); | 10350 | const object_ptr = try sema.resolveInst(extra.lhs); |
| 10403 | const field_name = try sema.resolveConstStringIntern(block, field_name_src, extra.field_name, .{ | 10351 | const field_name = try sema.resolveConstStringIntern(block, field_name_src, extra.field_name, .{ |
| ... | @@ -10411,14 +10359,14 @@ fn zirIntCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air | ... | @@ -10411,14 +10359,14 @@ fn zirIntCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 10411 | defer tracy.end(); | 10359 | defer tracy.end(); |
| 10412 | | 10360 | |
| 10413 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 10361 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 10414 | const src = inst_data.src(); | 10362 | const src = block.nodeOffset(inst_data.src_node); |
| 10415 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 10363 | const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0); |
| 10416 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; | 10364 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 10417 | | 10365 | |
| 10418 | const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu_opt, "@intCast"); | 10366 | const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu_opt, "@intCast"); |
| 10419 | const operand = try sema.resolveInst(extra.rhs); | 10367 | const operand = try sema.resolveInst(extra.rhs); |
| 10420 | | 10368 | |
| 10421 | return sema.intCast(block, inst_data.src(), dest_ty, src, operand, operand_src, true); | 10369 | return sema.intCast(block, block.nodeOffset(inst_data.src_node), dest_ty, src, operand, operand_src, true); |
| 10422 | } | 10370 | } |
| 10423 | | 10371 | |
| 10424 | fn intCast( | 10372 | fn intCast( |
| ... | @@ -10581,8 +10529,8 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air | ... | @@ -10581,8 +10529,8 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 10581 | | 10529 | |
| 10582 | const mod = sema.mod; | 10530 | const mod = sema.mod; |
| 10583 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 10531 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 10584 | const src = inst_data.src(); | 10532 | const src = block.nodeOffset(inst_data.src_node); |
| 10585 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 10533 | const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0); |
| 10586 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; | 10534 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 10587 | | 10535 | |
| 10588 | const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu_opt, "@bitCast"); | 10536 | const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu_opt, "@bitCast"); |
| ... | @@ -10608,10 +10556,10 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air | ... | @@ -10608,10 +10556,10 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 10608 | | 10556 | |
| 10609 | .Enum => { | 10557 | .Enum => { |
| 10610 | const msg = msg: { | 10558 | const msg = msg: { |
| 10611 | const msg = try sema.errMsg(block, src, "cannot @bitCast to '{}'", .{dest_ty.fmt(mod)}); | 10559 | const msg = try sema.errMsg(src, "cannot @bitCast to '{}'", .{dest_ty.fmt(mod)}); |
| 10612 | errdefer msg.destroy(sema.gpa); | 10560 | errdefer msg.destroy(sema.gpa); |
| 10613 | switch (operand_ty.zigTypeTag(mod)) { | 10561 | switch (operand_ty.zigTypeTag(mod)) { |
| 10614 | .Int, .ComptimeInt => try sema.errNote(block, src, msg, "use @enumFromInt to cast from '{}'", .{operand_ty.fmt(mod)}), | 10562 | .Int, .ComptimeInt => try sema.errNote(src, msg, "use @enumFromInt to cast from '{}'", .{operand_ty.fmt(mod)}), |
| 10615 | else => {}, | 10563 | else => {}, |
| 10616 | } | 10564 | } |
| 10617 | | 10565 | |
| ... | @@ -10622,11 +10570,11 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air | ... | @@ -10622,11 +10570,11 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 10622 | | 10570 | |
| 10623 | .Pointer => { | 10571 | .Pointer => { |
| 10624 | const msg = msg: { | 10572 | const msg = msg: { |
| 10625 | const msg = try sema.errMsg(block, src, "cannot @bitCast to '{}'", .{dest_ty.fmt(mod)}); | 10573 | const msg = try sema.errMsg(src, "cannot @bitCast to '{}'", .{dest_ty.fmt(mod)}); |
| 10626 | errdefer msg.destroy(sema.gpa); | 10574 | errdefer msg.destroy(sema.gpa); |
| 10627 | switch (operand_ty.zigTypeTag(mod)) { | 10575 | switch (operand_ty.zigTypeTag(mod)) { |
| 10628 | .Int, .ComptimeInt => try sema.errNote(block, src, msg, "use @ptrFromInt to cast from '{}'", .{operand_ty.fmt(mod)}), | 10576 | .Int, .ComptimeInt => try sema.errNote(src, msg, "use @ptrFromInt to cast from '{}'", .{operand_ty.fmt(mod)}), |
| 10629 | .Pointer => try sema.errNote(block, src, msg, "use @ptrCast to cast from '{}'", .{operand_ty.fmt(mod)}), | 10577 | .Pointer => try sema.errNote(src, msg, "use @ptrCast to cast from '{}'", .{operand_ty.fmt(mod)}), |
| 10630 | else => {}, | 10578 | else => {}, |
| 10631 | } | 10579 | } |
| 10632 | | 10580 | |
| ... | @@ -10672,10 +10620,10 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air | ... | @@ -10672,10 +10620,10 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 10672 | | 10620 | |
| 10673 | .Enum => { | 10621 | .Enum => { |
| 10674 | const msg = msg: { | 10622 | const msg = msg: { |
| 10675 | 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)}); |
| 10676 | errdefer msg.destroy(sema.gpa); | 10624 | errdefer msg.destroy(sema.gpa); |
| 10677 | switch (dest_ty.zigTypeTag(mod)) { | 10625 | switch (dest_ty.zigTypeTag(mod)) { |
| 10678 | .Int, .ComptimeInt => try sema.errNote(block, operand_src, msg, "use @intFromEnum to cast to '{}'", .{dest_ty.fmt(mod)}), | 10626 | .Int, .ComptimeInt => try sema.errNote(operand_src, msg, "use @intFromEnum to cast to '{}'", .{dest_ty.fmt(mod)}), |
| 10679 | else => {}, | 10627 | else => {}, |
| 10680 | } | 10628 | } |
| 10681 | | 10629 | |
| ... | @@ -10685,11 +10633,11 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air | ... | @@ -10685,11 +10633,11 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 10685 | }, | 10633 | }, |
| 10686 | .Pointer => { | 10634 | .Pointer => { |
| 10687 | const msg = msg: { | 10635 | const msg = msg: { |
| 10688 | const msg = try sema.errMsg(block, operand_src, "cannot @bitCast from '{}'", .{operand_ty.fmt(mod)}); | 10636 | const msg = try sema.errMsg(operand_src, "cannot @bitCast from '{}'", .{operand_ty.fmt(mod)}); |
| 10689 | errdefer msg.destroy(sema.gpa); | 10637 | errdefer msg.destroy(sema.gpa); |
| 10690 | switch (dest_ty.zigTypeTag(mod)) { | 10638 | switch (dest_ty.zigTypeTag(mod)) { |
| 10691 | .Int, .ComptimeInt => try sema.errNote(block, operand_src, msg, "use @intFromPtr to cast to '{}'", .{dest_ty.fmt(mod)}), | 10639 | .Int, .ComptimeInt => try sema.errNote(operand_src, msg, "use @intFromPtr to cast to '{}'", .{dest_ty.fmt(mod)}), |
| 10692 | .Pointer => try sema.errNote(block, operand_src, msg, "use @ptrCast to cast to '{}'", .{dest_ty.fmt(mod)}), | 10640 | .Pointer => try sema.errNote(operand_src, msg, "use @ptrCast to cast to '{}'", .{dest_ty.fmt(mod)}), |
| 10693 | else => {}, | 10641 | else => {}, |
| 10694 | } | 10642 | } |
| 10695 | | 10643 | |
| ... | @@ -10715,7 +10663,7 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air | ... | @@ -10715,7 +10663,7 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 10715 | .Vector, | 10663 | .Vector, |
| 10716 | => {}, | 10664 | => {}, |
| 10717 | } | 10665 | } |
| 10718 | return sema.bitCast(block, dest_ty, operand, inst_data.src(), operand_src); | 10666 | return sema.bitCast(block, dest_ty, operand, block.nodeOffset(inst_data.src_node), operand_src); |
| 10719 | } | 10667 | } |
| 10720 | | 10668 | |
| 10721 | fn zirFloatCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 10669 | fn zirFloatCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| ... | @@ -10724,8 +10672,8 @@ fn zirFloatCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A | ... | @@ -10724,8 +10672,8 @@ fn zirFloatCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 10724 | | 10672 | |
| 10725 | const mod = sema.mod; | 10673 | const mod = sema.mod; |
| 10726 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 10674 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 10727 | const src = inst_data.src(); | 10675 | const src = block.nodeOffset(inst_data.src_node); |
| 10728 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 10676 | const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0); |
| 10729 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; | 10677 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 10730 | | 10678 | |
| 10731 | const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu_opt, "@floatCast"); | 10679 | const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu_opt, "@floatCast"); |
| ... | @@ -10778,7 +10726,7 @@ fn zirFloatCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A | ... | @@ -10778,7 +10726,7 @@ fn zirFloatCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 10778 | if (dest_is_comptime_float) { | 10726 | if (dest_is_comptime_float) { |
| 10779 | return sema.fail(block, operand_src, "unable to cast runtime value to 'comptime_float'", .{}); | 10727 | return sema.fail(block, operand_src, "unable to cast runtime value to 'comptime_float'", .{}); |
| 10780 | } | 10728 | } |
| 10781 | try sema.requireRuntimeBlock(block, inst_data.src(), operand_src); | 10729 | try sema.requireRuntimeBlock(block, block.nodeOffset(inst_data.src_node), operand_src); |
| 10782 | | 10730 | |
| 10783 | const src_bits = operand_scalar_ty.floatBits(target); | 10731 | const src_bits = operand_scalar_ty.floatBits(target); |
| 10784 | const dst_bits = dest_scalar_ty.floatBits(target); | 10732 | const dst_bits = dest_scalar_ty.floatBits(target); |
| ... | @@ -10803,7 +10751,7 @@ fn zirElemVal(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air | ... | @@ -10803,7 +10751,7 @@ fn zirElemVal(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 10803 | defer tracy.end(); | 10751 | defer tracy.end(); |
| 10804 | | 10752 | |
| 10805 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 10753 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 10806 | const src = inst_data.src(); | 10754 | const src = block.nodeOffset(inst_data.src_node); |
| 10807 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; | 10755 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 10808 | const array = try sema.resolveInst(extra.lhs); | 10756 | const array = try sema.resolveInst(extra.lhs); |
| 10809 | const elem_index = try sema.resolveInst(extra.rhs); | 10757 | const elem_index = try sema.resolveInst(extra.rhs); |
| ... | @@ -10815,8 +10763,8 @@ fn zirElemValNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError | ... | @@ -10815,8 +10763,8 @@ fn zirElemValNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 10815 | defer tracy.end(); | 10763 | defer tracy.end(); |
| 10816 | | 10764 | |
| 10817 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 10765 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 10818 | const src = inst_data.src(); | 10766 | const src = block.nodeOffset(inst_data.src_node); |
| 10819 | const elem_index_src: LazySrcLoc = .{ .node_offset_array_access_index = inst_data.src_node }; | 10767 | const elem_index_src = block.src(.{ .node_offset_array_access_index = inst_data.src_node }); |
| 10820 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; | 10768 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 10821 | const array = try sema.resolveInst(extra.lhs); | 10769 | const array = try sema.resolveInst(extra.lhs); |
| 10822 | const uncoerced_elem_index = try sema.resolveInst(extra.rhs); | 10770 | const uncoerced_elem_index = try sema.resolveInst(extra.rhs); |
| ... | @@ -10832,7 +10780,7 @@ fn zirElemValImm(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! | ... | @@ -10832,7 +10780,7 @@ fn zirElemValImm(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! |
| 10832 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].elem_val_imm; | 10780 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].elem_val_imm; |
| 10833 | const array = try sema.resolveInst(inst_data.operand); | 10781 | const array = try sema.resolveInst(inst_data.operand); |
| 10834 | const elem_index = try mod.intRef(Type.usize, inst_data.idx); | 10782 | const elem_index = try mod.intRef(Type.usize, inst_data.idx); |
| 10835 | return sema.elemVal(block, .unneeded, array, elem_index, .unneeded, false); | 10783 | return sema.elemVal(block, LazySrcLoc.unneeded, array, elem_index, LazySrcLoc.unneeded, false); |
| 10836 | } | 10784 | } |
| 10837 | | 10785 | |
| 10838 | fn zirElemPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 10786 | fn zirElemPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| ... | @@ -10841,20 +10789,20 @@ fn zirElemPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air | ... | @@ -10841,20 +10789,20 @@ fn zirElemPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 10841 | | 10789 | |
| 10842 | const mod = sema.mod; | 10790 | const mod = sema.mod; |
| 10843 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 10791 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 10844 | const src = inst_data.src(); | 10792 | const src = block.nodeOffset(inst_data.src_node); |
| 10845 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; | 10793 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 10846 | const array_ptr = try sema.resolveInst(extra.lhs); | 10794 | const array_ptr = try sema.resolveInst(extra.lhs); |
| 10847 | const elem_index = try sema.resolveInst(extra.rhs); | 10795 | const elem_index = try sema.resolveInst(extra.rhs); |
| 10848 | const indexable_ty = sema.typeOf(array_ptr); | 10796 | const indexable_ty = sema.typeOf(array_ptr); |
| 10849 | if (indexable_ty.zigTypeTag(mod) != .Pointer) { | 10797 | if (indexable_ty.zigTypeTag(mod) != .Pointer) { |
| 10850 | const capture_src: LazySrcLoc = .{ .for_capture_from_input = inst_data.src_node }; | 10798 | const capture_src = block.src(.{ .for_capture_from_input = inst_data.src_node }); |
| 10851 | const msg = msg: { | 10799 | const msg = msg: { |
| 10852 | const msg = try sema.errMsg(block, capture_src, "pointer capture of non pointer type '{}'", .{ | 10800 | const msg = try sema.errMsg(capture_src, "pointer capture of non pointer type '{}'", .{ |
| 10853 | indexable_ty.fmt(mod), | 10801 | indexable_ty.fmt(mod), |
| 10854 | }); | 10802 | }); |
| 10855 | errdefer msg.destroy(sema.gpa); | 10803 | errdefer msg.destroy(sema.gpa); |
| 10856 | if (indexable_ty.isIndexable(mod)) { | 10804 | if (indexable_ty.isIndexable(mod)) { |
| 10857 | try sema.errNote(block, src, msg, "consider using '&' here", .{}); | 10805 | try sema.errNote(src, msg, "consider using '&' here", .{}); |
| 10858 | } | 10806 | } |
| 10859 | break :msg msg; | 10807 | break :msg msg; |
| 10860 | }; | 10808 | }; |
| ... | @@ -10868,8 +10816,8 @@ fn zirElemPtrNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError | ... | @@ -10868,8 +10816,8 @@ fn zirElemPtrNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 10868 | defer tracy.end(); | 10816 | defer tracy.end(); |
| 10869 | | 10817 | |
| 10870 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 10818 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 10871 | const src = inst_data.src(); | 10819 | const src = block.nodeOffset(inst_data.src_node); |
| 10872 | const elem_index_src: LazySrcLoc = .{ .node_offset_array_access_index = inst_data.src_node }; | 10820 | const elem_index_src = block.src(.{ .node_offset_array_access_index = inst_data.src_node }); |
| 10873 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; | 10821 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 10874 | const array_ptr = try sema.resolveInst(extra.lhs); | 10822 | const array_ptr = try sema.resolveInst(extra.lhs); |
| 10875 | const uncoerced_elem_index = try sema.resolveInst(extra.rhs); | 10823 | const uncoerced_elem_index = try sema.resolveInst(extra.rhs); |
| ... | @@ -10883,7 +10831,7 @@ fn zirArrayInitElemPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compile | ... | @@ -10883,7 +10831,7 @@ fn zirArrayInitElemPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compile |
| 10883 | | 10831 | |
| 10884 | const mod = sema.mod; | 10832 | const mod = sema.mod; |
| 10885 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 10833 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 10886 | const src = inst_data.src(); | 10834 | const src = block.nodeOffset(inst_data.src_node); |
| 10887 | const extra = sema.code.extraData(Zir.Inst.ElemPtrImm, inst_data.payload_index).data; | 10835 | const extra = sema.code.extraData(Zir.Inst.ElemPtrImm, inst_data.payload_index).data; |
| 10888 | const array_ptr = try sema.resolveInst(extra.ptr); | 10836 | const array_ptr = try sema.resolveInst(extra.ptr); |
| 10889 | const elem_index = try sema.mod.intRef(Type.usize, extra.index); | 10837 | const elem_index = try sema.mod.intRef(Type.usize, extra.index); |
| ... | @@ -10902,15 +10850,15 @@ fn zirSliceStart(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! | ... | @@ -10902,15 +10850,15 @@ fn zirSliceStart(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! |
| 10902 | defer tracy.end(); | 10850 | defer tracy.end(); |
| 10903 | | 10851 | |
| 10904 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 10852 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 10905 | const src = inst_data.src(); | 10853 | const src = block.nodeOffset(inst_data.src_node); |
| 10906 | const extra = sema.code.extraData(Zir.Inst.SliceStart, inst_data.payload_index).data; | 10854 | const extra = sema.code.extraData(Zir.Inst.SliceStart, inst_data.payload_index).data; |
| 10907 | const array_ptr = try sema.resolveInst(extra.lhs); | 10855 | const array_ptr = try sema.resolveInst(extra.lhs); |
| 10908 | const start = try sema.resolveInst(extra.start); | 10856 | const start = try sema.resolveInst(extra.start); |
| 10909 | const ptr_src: LazySrcLoc = .{ .node_offset_slice_ptr = inst_data.src_node }; | 10857 | const ptr_src = block.src(.{ .node_offset_slice_ptr = inst_data.src_node }); |
| 10910 | const start_src: LazySrcLoc = .{ .node_offset_slice_start = inst_data.src_node }; | 10858 | const start_src = block.src(.{ .node_offset_slice_start = inst_data.src_node }); |
| 10911 | const end_src: LazySrcLoc = .{ .node_offset_slice_end = inst_data.src_node }; | 10859 | const end_src = block.src(.{ .node_offset_slice_end = inst_data.src_node }); |
| 10912 | | 10860 | |
| 10913 | return sema.analyzeSlice(block, src, array_ptr, start, .none, .none, .unneeded, ptr_src, start_src, end_src, false); | 10861 | return sema.analyzeSlice(block, src, array_ptr, start, .none, .none, LazySrcLoc.unneeded, ptr_src, start_src, end_src, false); |
| 10914 | } | 10862 | } |
| 10915 | | 10863 | |
| 10916 | fn zirSliceEnd(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 10864 | fn zirSliceEnd(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| ... | @@ -10918,16 +10866,16 @@ fn zirSliceEnd(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -10918,16 +10866,16 @@ fn zirSliceEnd(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 10918 | defer tracy.end(); | 10866 | defer tracy.end(); |
| 10919 | | 10867 | |
| 10920 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 10868 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 10921 | const src = inst_data.src(); | 10869 | const src = block.nodeOffset(inst_data.src_node); |
| 10922 | const extra = sema.code.extraData(Zir.Inst.SliceEnd, inst_data.payload_index).data; | 10870 | const extra = sema.code.extraData(Zir.Inst.SliceEnd, inst_data.payload_index).data; |
| 10923 | const array_ptr = try sema.resolveInst(extra.lhs); | 10871 | const array_ptr = try sema.resolveInst(extra.lhs); |
| 10924 | const start = try sema.resolveInst(extra.start); | 10872 | const start = try sema.resolveInst(extra.start); |
| 10925 | const end = try sema.resolveInst(extra.end); | 10873 | const end = try sema.resolveInst(extra.end); |
| 10926 | const ptr_src: LazySrcLoc = .{ .node_offset_slice_ptr = inst_data.src_node }; | 10874 | const ptr_src = block.src(.{ .node_offset_slice_ptr = inst_data.src_node }); |
| 10927 | const start_src: LazySrcLoc = .{ .node_offset_slice_start = inst_data.src_node }; | 10875 | const start_src = block.src(.{ .node_offset_slice_start = inst_data.src_node }); |
| 10928 | const end_src: LazySrcLoc = .{ .node_offset_slice_end = inst_data.src_node }; | 10876 | const end_src = block.src(.{ .node_offset_slice_end = inst_data.src_node }); |
| 10929 | | 10877 | |
| 10930 | return sema.analyzeSlice(block, src, array_ptr, start, end, .none, .unneeded, ptr_src, start_src, end_src, false); | 10878 | return sema.analyzeSlice(block, src, array_ptr, start, end, .none, LazySrcLoc.unneeded, ptr_src, start_src, end_src, false); |
| 10931 | } | 10879 | } |
| 10932 | | 10880 | |
| 10933 | fn zirSliceSentinel(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 10881 | fn zirSliceSentinel(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| ... | @@ -10935,16 +10883,16 @@ fn zirSliceSentinel(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr | ... | @@ -10935,16 +10883,16 @@ fn zirSliceSentinel(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr |
| 10935 | defer tracy.end(); | 10883 | defer tracy.end(); |
| 10936 | | 10884 | |
| 10937 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 10885 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 10938 | const src = inst_data.src(); | 10886 | const src = block.nodeOffset(inst_data.src_node); |
| 10939 | const sentinel_src: LazySrcLoc = .{ .node_offset_slice_sentinel = inst_data.src_node }; | 10887 | const sentinel_src = block.src(.{ .node_offset_slice_sentinel = inst_data.src_node }); |
| 10940 | const extra = sema.code.extraData(Zir.Inst.SliceSentinel, inst_data.payload_index).data; | 10888 | const extra = sema.code.extraData(Zir.Inst.SliceSentinel, inst_data.payload_index).data; |
| 10941 | const array_ptr = try sema.resolveInst(extra.lhs); | 10889 | const array_ptr = try sema.resolveInst(extra.lhs); |
| 10942 | const start = try sema.resolveInst(extra.start); | 10890 | const start = try sema.resolveInst(extra.start); |
| 10943 | const end: Air.Inst.Ref = if (extra.end == .none) .none else try sema.resolveInst(extra.end); | 10891 | const end: Air.Inst.Ref = if (extra.end == .none) .none else try sema.resolveInst(extra.end); |
| 10944 | const sentinel = try sema.resolveInst(extra.sentinel); | 10892 | const sentinel = try sema.resolveInst(extra.sentinel); |
| 10945 | const ptr_src: LazySrcLoc = .{ .node_offset_slice_ptr = inst_data.src_node }; | 10893 | const ptr_src = block.src(.{ .node_offset_slice_ptr = inst_data.src_node }); |
| 10946 | const start_src: LazySrcLoc = .{ .node_offset_slice_start = inst_data.src_node }; | 10894 | const start_src = block.src(.{ .node_offset_slice_start = inst_data.src_node }); |
| 10947 | const end_src: LazySrcLoc = .{ .node_offset_slice_end = inst_data.src_node }; | 10895 | const end_src = block.src(.{ .node_offset_slice_end = inst_data.src_node }); |
| 10948 | | 10896 | |
| 10949 | return sema.analyzeSlice(block, src, array_ptr, start, end, sentinel, sentinel_src, ptr_src, start_src, end_src, false); | 10897 | return sema.analyzeSlice(block, src, array_ptr, start, end, sentinel, sentinel_src, ptr_src, start_src, end_src, false); |
| 10950 | } | 10898 | } |
| ... | @@ -10954,19 +10902,19 @@ fn zirSliceLength(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError | ... | @@ -10954,19 +10902,19 @@ fn zirSliceLength(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 10954 | defer tracy.end(); | 10902 | defer tracy.end(); |
| 10955 | | 10903 | |
| 10956 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 10904 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 10957 | const src = inst_data.src(); | 10905 | const src = block.nodeOffset(inst_data.src_node); |
| 10958 | const extra = sema.code.extraData(Zir.Inst.SliceLength, inst_data.payload_index).data; | 10906 | const extra = sema.code.extraData(Zir.Inst.SliceLength, inst_data.payload_index).data; |
| 10959 | const array_ptr = try sema.resolveInst(extra.lhs); | 10907 | const array_ptr = try sema.resolveInst(extra.lhs); |
| 10960 | const start = try sema.resolveInst(extra.start); | 10908 | const start = try sema.resolveInst(extra.start); |
| 10961 | const len = try sema.resolveInst(extra.len); | 10909 | const len = try sema.resolveInst(extra.len); |
| 10962 | const sentinel = if (extra.sentinel == .none) .none else try sema.resolveInst(extra.sentinel); | 10910 | const sentinel = if (extra.sentinel == .none) .none else try sema.resolveInst(extra.sentinel); |
| 10963 | const ptr_src: LazySrcLoc = .{ .node_offset_slice_ptr = inst_data.src_node }; | 10911 | const ptr_src = block.src(.{ .node_offset_slice_ptr = inst_data.src_node }); |
| 10964 | const start_src: LazySrcLoc = .{ .node_offset_slice_start = extra.start_src_node_offset }; | 10912 | const start_src = block.src(.{ .node_offset_slice_start = extra.start_src_node_offset }); |
| 10965 | const end_src: LazySrcLoc = .{ .node_offset_slice_end = inst_data.src_node }; | 10913 | const end_src = block.src(.{ .node_offset_slice_end = inst_data.src_node }); |
| 10966 | const sentinel_src: LazySrcLoc = if (sentinel == .none) | 10914 | const sentinel_src: LazySrcLoc = if (sentinel == .none) |
| 10967 | .unneeded | 10915 | LazySrcLoc.unneeded |
| 10968 | else | 10916 | else |
| 10969 | .{ .node_offset_slice_sentinel = inst_data.src_node }; | 10917 | block.src(.{ .node_offset_slice_sentinel = inst_data.src_node }); |
| 10970 | | 10918 | |
| 10971 | return sema.analyzeSlice(block, src, array_ptr, start, len, sentinel, sentinel_src, ptr_src, start_src, end_src, true); | 10919 | return sema.analyzeSlice(block, src, array_ptr, start, len, sentinel, sentinel_src, ptr_src, start_src, end_src, true); |
| 10972 | } | 10920 | } |
| ... | @@ -11000,8 +10948,8 @@ const SwitchProngAnalysis = struct { | ... | @@ -11000,8 +10948,8 @@ const SwitchProngAnalysis = struct { |
| 11000 | prong_type: enum { normal, special }, | 10948 | prong_type: enum { normal, special }, |
| 11001 | prong_body: []const Zir.Inst.Index, | 10949 | prong_body: []const Zir.Inst.Index, |
| 11002 | capture: Zir.Inst.SwitchBlock.ProngInfo.Capture, | 10950 | capture: Zir.Inst.SwitchBlock.ProngInfo.Capture, |
| 11003 | /// Must use the `scalar_capture`, `special_capture`, or `multi_capture` union field. | 10951 | /// Must use the `switch_capture` field in `offset`. |
| 11004 | raw_capture_src: Module.SwitchProngSrc, | 10952 | capture_src: LazySrcLoc, |
| 11005 | /// The set of all values which can reach this prong. May be undefined | 10953 | /// The set of all values which can reach this prong. May be undefined |
| 11006 | /// if the prong is special or contains ranges. | 10954 | /// if the prong is special or contains ranges. |
| 11007 | case_vals: []const Air.Inst.Ref, | 10955 | case_vals: []const Air.Inst.Ref, |
| ... | @@ -11014,10 +10962,12 @@ const SwitchProngAnalysis = struct { | ... | @@ -11014,10 +10962,12 @@ const SwitchProngAnalysis = struct { |
| 11014 | merges: *Block.Merges, | 10962 | merges: *Block.Merges, |
| 11015 | ) CompileError!Air.Inst.Ref { | 10963 | ) CompileError!Air.Inst.Ref { |
| 11016 | const sema = spa.sema; | 10964 | const sema = spa.sema; |
| 11017 | const src = sema.code.instructions.items(.data)[@intFromEnum(spa.switch_block_inst)].pl_node.src(); | 10965 | const src = spa.parent_block.nodeOffset( |
| | 10966 | sema.code.instructions.items(.data)[@intFromEnum(spa.switch_block_inst)].pl_node.src_node, |
| | 10967 | ); |
| 11018 | | 10968 | |
| 11019 | if (has_tag_capture) { | 10969 | if (has_tag_capture) { |
| 11020 | const tag_ref = try spa.analyzeTagCapture(child_block, raw_capture_src, inline_case_capture); | 10970 | const tag_ref = try spa.analyzeTagCapture(child_block, capture_src, inline_case_capture); |
| 11021 | sema.inst_map.putAssumeCapacity(spa.tag_capture_inst, tag_ref); | 10971 | sema.inst_map.putAssumeCapacity(spa.tag_capture_inst, tag_ref); |
| 11022 | } | 10972 | } |
| 11023 | defer if (has_tag_capture) assert(sema.inst_map.remove(spa.tag_capture_inst)); | 10973 | defer if (has_tag_capture) assert(sema.inst_map.remove(spa.tag_capture_inst)); |
| ... | @@ -11032,7 +10982,7 @@ const SwitchProngAnalysis = struct { | ... | @@ -11032,7 +10982,7 @@ const SwitchProngAnalysis = struct { |
| 11032 | child_block, | 10982 | child_block, |
| 11033 | capture == .by_ref, | 10983 | capture == .by_ref, |
| 11034 | prong_type == .special, | 10984 | prong_type == .special, |
| 11035 | raw_capture_src, | 10985 | capture_src, |
| 11036 | case_vals, | 10986 | case_vals, |
| 11037 | inline_case_capture, | 10987 | inline_case_capture, |
| 11038 | ); | 10988 | ); |
| ... | @@ -11058,8 +11008,8 @@ const SwitchProngAnalysis = struct { | ... | @@ -11058,8 +11008,8 @@ const SwitchProngAnalysis = struct { |
| 11058 | prong_type: enum { normal, special }, | 11008 | prong_type: enum { normal, special }, |
| 11059 | prong_body: []const Zir.Inst.Index, | 11009 | prong_body: []const Zir.Inst.Index, |
| 11060 | capture: Zir.Inst.SwitchBlock.ProngInfo.Capture, | 11010 | capture: Zir.Inst.SwitchBlock.ProngInfo.Capture, |
| 11061 | /// Must use the `scalar`, `special`, or `multi_capture` union field. | 11011 | /// Must use the `switch_capture` field in `offset`. |
| 11062 | raw_capture_src: Module.SwitchProngSrc, | 11012 | capture_src: LazySrcLoc, |
| 11063 | /// The set of all values which can reach this prong. May be undefined | 11013 | /// The set of all values which can reach this prong. May be undefined |
| 11064 | /// if the prong is special or contains ranges. | 11014 | /// if the prong is special or contains ranges. |
| 11065 | case_vals: []const Air.Inst.Ref, | 11015 | case_vals: []const Air.Inst.Ref, |
| ... | @@ -11073,7 +11023,7 @@ const SwitchProngAnalysis = struct { | ... | @@ -11073,7 +11023,7 @@ const SwitchProngAnalysis = struct { |
| 11073 | const sema = spa.sema; | 11023 | const sema = spa.sema; |
| 11074 | | 11024 | |
| 11075 | if (has_tag_capture) { | 11025 | if (has_tag_capture) { |
| 11076 | const tag_ref = try spa.analyzeTagCapture(case_block, raw_capture_src, inline_case_capture); | 11026 | const tag_ref = try spa.analyzeTagCapture(case_block, capture_src, inline_case_capture); |
| 11077 | sema.inst_map.putAssumeCapacity(spa.tag_capture_inst, tag_ref); | 11027 | sema.inst_map.putAssumeCapacity(spa.tag_capture_inst, tag_ref); |
| 11078 | } | 11028 | } |
| 11079 | defer if (has_tag_capture) assert(sema.inst_map.remove(spa.tag_capture_inst)); | 11029 | defer if (has_tag_capture) assert(sema.inst_map.remove(spa.tag_capture_inst)); |
| ... | @@ -11088,7 +11038,7 @@ const SwitchProngAnalysis = struct { | ... | @@ -11088,7 +11038,7 @@ const SwitchProngAnalysis = struct { |
| 11088 | case_block, | 11038 | case_block, |
| 11089 | capture == .by_ref, | 11039 | capture == .by_ref, |
| 11090 | prong_type == .special, | 11040 | prong_type == .special, |
| 11091 | raw_capture_src, | 11041 | capture_src, |
| 11092 | case_vals, | 11042 | case_vals, |
| 11093 | inline_case_capture, | 11043 | inline_case_capture, |
| 11094 | ); | 11044 | ); |
| ... | @@ -11109,23 +11059,18 @@ const SwitchProngAnalysis = struct { | ... | @@ -11109,23 +11059,18 @@ const SwitchProngAnalysis = struct { |
| 11109 | fn analyzeTagCapture( | 11059 | fn analyzeTagCapture( |
| 11110 | spa: SwitchProngAnalysis, | 11060 | spa: SwitchProngAnalysis, |
| 11111 | block: *Block, | 11061 | block: *Block, |
| 11112 | raw_capture_src: Module.SwitchProngSrc, | 11062 | capture_src: LazySrcLoc, |
| 11113 | inline_case_capture: Air.Inst.Ref, | 11063 | inline_case_capture: Air.Inst.Ref, |
| 11114 | ) CompileError!Air.Inst.Ref { | 11064 | ) CompileError!Air.Inst.Ref { |
| 11115 | const sema = spa.sema; | 11065 | const sema = spa.sema; |
| 11116 | const mod = sema.mod; | 11066 | const mod = sema.mod; |
| 11117 | const operand_ty = sema.typeOf(spa.operand); | 11067 | const operand_ty = sema.typeOf(spa.operand); |
| 11118 | if (operand_ty.zigTypeTag(mod) != .Union) { | 11068 | if (operand_ty.zigTypeTag(mod) != .Union) { |
| 11119 | const zir_datas = sema.code.instructions.items(.data); | 11069 | const tag_capture_src: LazySrcLoc = .{ |
| 11120 | const switch_node_offset = zir_datas[@intFromEnum(spa.switch_block_inst)].pl_node.src_node; | 11070 | .base_node_inst = capture_src.base_node_inst, |
| 11121 | const raw_tag_capture_src: Module.SwitchProngSrc = switch (raw_capture_src) { | 11071 | .offset = .{ .switch_tag_capture = capture_src.offset.switch_capture }, |
| 11122 | .scalar_capture => |i| .{ .scalar_tag_capture = i }, | | |
| 11123 | .multi_capture => |i| .{ .multi_tag_capture = i }, | | |
| 11124 | .special_capture => .special_tag_capture, | | |
| 11125 | else => unreachable, | | |
| 11126 | }; | 11072 | }; |
| 11127 | const capture_src = raw_tag_capture_src.resolve(mod, mod.declPtr(block.src_decl), switch_node_offset, .none); | 11073 | return sema.fail(block, tag_capture_src, "cannot capture tag of non-union type '{}'", .{ |
| 11128 | return sema.fail(block, capture_src, "cannot capture tag of non-union type '{}'", .{ | | |
| 11129 | operand_ty.fmt(mod), | 11074 | operand_ty.fmt(mod), |
| 11130 | }); | 11075 | }); |
| 11131 | } | 11076 | } |
| ... | @@ -11138,7 +11083,7 @@ const SwitchProngAnalysis = struct { | ... | @@ -11138,7 +11083,7 @@ const SwitchProngAnalysis = struct { |
| 11138 | block: *Block, | 11083 | block: *Block, |
| 11139 | capture_byref: bool, | 11084 | capture_byref: bool, |
| 11140 | is_special_prong: bool, | 11085 | is_special_prong: bool, |
| 11141 | raw_capture_src: Module.SwitchProngSrc, | 11086 | capture_src: LazySrcLoc, |
| 11142 | case_vals: []const Air.Inst.Ref, | 11087 | case_vals: []const Air.Inst.Ref, |
| 11143 | inline_case_capture: Air.Inst.Ref, | 11088 | inline_case_capture: Air.Inst.Ref, |
| 11144 | ) CompileError!Air.Inst.Ref { | 11089 | ) CompileError!Air.Inst.Ref { |
| ... | @@ -11151,10 +11096,10 @@ const SwitchProngAnalysis = struct { | ... | @@ -11151,10 +11096,10 @@ const SwitchProngAnalysis = struct { |
| 11151 | | 11096 | |
| 11152 | const operand_ty = sema.typeOf(spa.operand); | 11097 | const operand_ty = sema.typeOf(spa.operand); |
| 11153 | const operand_ptr_ty = if (capture_byref) sema.typeOf(spa.operand_ptr) else undefined; | 11098 | const operand_ptr_ty = if (capture_byref) sema.typeOf(spa.operand_ptr) else undefined; |
| 11154 | const operand_src: LazySrcLoc = .{ .node_offset_switch_operand = switch_node_offset }; | 11099 | const operand_src = block.src(.{ .node_offset_switch_operand = switch_node_offset }); |
| 11155 | | 11100 | |
| 11156 | if (inline_case_capture != .none) { | 11101 | if (inline_case_capture != .none) { |
| 11157 | const item_val = sema.resolveConstDefinedValue(block, .unneeded, inline_case_capture, undefined) catch unreachable; | 11102 | const item_val = sema.resolveConstDefinedValue(block, LazySrcLoc.unneeded, inline_case_capture, undefined) catch unreachable; |
| 11158 | if (operand_ty.zigTypeTag(zcu) == .Union) { | 11103 | if (operand_ty.zigTypeTag(zcu) == .Union) { |
| 11159 | const field_index: u32 = @intCast(operand_ty.unionTagFieldIndex(item_val, zcu).?); | 11104 | const field_index: u32 = @intCast(operand_ty.unionTagFieldIndex(item_val, zcu).?); |
| 11160 | const union_obj = zcu.typeToUnion(operand_ty).?; | 11105 | const union_obj = zcu.typeToUnion(operand_ty).?; |
| ... | @@ -11195,7 +11140,7 @@ const SwitchProngAnalysis = struct { | ... | @@ -11195,7 +11140,7 @@ const SwitchProngAnalysis = struct { |
| 11195 | .ErrorSet => if (spa.else_error_ty) |ty| { | 11140 | .ErrorSet => if (spa.else_error_ty) |ty| { |
| 11196 | return sema.bitCast(block, ty, spa.operand, operand_src, null); | 11141 | return sema.bitCast(block, ty, spa.operand, operand_src, null); |
| 11197 | } else { | 11142 | } else { |
| 11198 | try block.addUnreachable(operand_src, false); | 11143 | try sema.analyzeUnreachable(block, operand_src, false); |
| 11199 | return .unreachable_value; | 11144 | return .unreachable_value; |
| 11200 | }, | 11145 | }, |
| 11201 | else => return spa.operand, | 11146 | else => return spa.operand, |
| ... | @@ -11205,14 +11150,14 @@ const SwitchProngAnalysis = struct { | ... | @@ -11205,14 +11150,14 @@ const SwitchProngAnalysis = struct { |
| 11205 | switch (operand_ty.zigTypeTag(zcu)) { | 11150 | switch (operand_ty.zigTypeTag(zcu)) { |
| 11206 | .Union => { | 11151 | .Union => { |
| 11207 | const union_obj = zcu.typeToUnion(operand_ty).?; | 11152 | const union_obj = zcu.typeToUnion(operand_ty).?; |
| 11208 | const first_item_val = sema.resolveConstDefinedValue(block, .unneeded, case_vals[0], undefined) catch unreachable; | 11153 | const first_item_val = sema.resolveConstDefinedValue(block, LazySrcLoc.unneeded, case_vals[0], undefined) catch unreachable; |
| 11209 | | 11154 | |
| 11210 | const first_field_index: u32 = zcu.unionTagFieldIndex(union_obj, first_item_val).?; | 11155 | const first_field_index: u32 = zcu.unionTagFieldIndex(union_obj, first_item_val).?; |
| 11211 | const first_field_ty = Type.fromInterned(union_obj.field_types.get(ip)[first_field_index]); | 11156 | const first_field_ty = Type.fromInterned(union_obj.field_types.get(ip)[first_field_index]); |
| 11212 | | 11157 | |
| 11213 | const field_indices = try sema.arena.alloc(u32, case_vals.len); | 11158 | const field_indices = try sema.arena.alloc(u32, case_vals.len); |
| 11214 | for (case_vals, field_indices) |item, *field_idx| { | 11159 | for (case_vals, field_indices) |item, *field_idx| { |
| 11215 | const item_val = sema.resolveConstDefinedValue(block, .unneeded, item, undefined) catch unreachable; | 11160 | const item_val = sema.resolveConstDefinedValue(block, LazySrcLoc.unneeded, item, undefined) catch unreachable; |
| 11216 | field_idx.* = zcu.unionTagFieldIndex(union_obj, item_val).?; | 11161 | field_idx.* = zcu.unionTagFieldIndex(union_obj, item_val).?; |
| 11217 | } | 11162 | } |
| 11218 | | 11163 | |
| ... | @@ -11232,27 +11177,22 @@ const SwitchProngAnalysis = struct { | ... | @@ -11232,27 +11177,22 @@ const SwitchProngAnalysis = struct { |
| 11232 | } | 11177 | } |
| 11233 | | 11178 | |
| 11234 | const case_srcs = try sema.arena.alloc(?LazySrcLoc, case_vals.len); | 11179 | const case_srcs = try sema.arena.alloc(?LazySrcLoc, case_vals.len); |
| 11235 | @memset(case_srcs, .unneeded); | 11180 | for (case_srcs, 0..) |*case_src, i| { |
| 11236 | | 11181 | case_src.* = .{ |
| 11237 | break :capture_ty sema.resolvePeerTypes(block, .unneeded, dummy_captures, .{ .override = case_srcs }) catch |err| switch (err) { | 11182 | .base_node_inst = capture_src.base_node_inst, |
| 11238 | error.NeededSourceLocation => { | 11183 | .offset = .{ .switch_case_item = .{ |
| 11239 | // This must be a multi-prong so this must be a `multi_capture` src | 11184 | .switch_node_offset = switch_node_offset, |
| 11240 | const multi_idx = raw_capture_src.multi_capture; | 11185 | .case_idx = capture_src.offset.switch_capture.case_idx, |
| 11241 | const src_decl_ptr = zcu.declPtr(block.src_decl); | 11186 | .item_idx = .{ .kind = .single, .index = @intCast(i) }, |
| 11242 | for (case_srcs, 0..) |*case_src, i| { | 11187 | } }, |
| 11243 | const raw_case_src: Module.SwitchProngSrc = .{ .multi = .{ .prong = multi_idx, .item = @intCast(i) } }; | 11188 | }; |
| 11244 | case_src.* = raw_case_src.resolve(zcu, src_decl_ptr, switch_node_offset, .none); | 11189 | } |
| 11245 | } | 11190 | |
| 11246 | const capture_src = raw_capture_src.resolve(zcu, src_decl_ptr, switch_node_offset, .none); | 11191 | break :capture_ty sema.resolvePeerTypes(block, capture_src, dummy_captures, .{ .override = case_srcs }) catch |err| switch (err) { |
| 11247 | _ = sema.resolvePeerTypes(block, capture_src, dummy_captures, .{ .override = case_srcs }) catch |err1| switch (err1) { | 11192 | error.AnalysisFail => { |
| 11248 | error.AnalysisFail => { | 11193 | const msg = sema.err orelse return error.AnalysisFail; |
| 11249 | const msg = sema.err orelse return error.AnalysisFail; | 11194 | try sema.reparentOwnedErrorMsg(capture_src, msg, "capture group with incompatible types", .{}); |
| 11250 | try sema.reparentOwnedErrorMsg(block, capture_src, msg, "capture group with incompatible types", .{}); | 11195 | return error.AnalysisFail; |
| 11251 | return error.AnalysisFail; | | |
| 11252 | }, | | |
| 11253 | else => |e| return e, | | |
| 11254 | }; | | |
| 11255 | unreachable; | | |
| 11256 | }, | 11196 | }, |
| 11257 | else => |e| return e, | 11197 | else => |e| return e, |
| 11258 | }; | 11198 | }; |
| ... | @@ -11280,28 +11220,23 @@ const SwitchProngAnalysis = struct { | ... | @@ -11280,28 +11220,23 @@ const SwitchProngAnalysis = struct { |
| 11280 | dummy.* = try zcu.undefRef(field_ptr_ty); | 11220 | dummy.* = try zcu.undefRef(field_ptr_ty); |
| 11281 | } | 11221 | } |
| 11282 | const case_srcs = try sema.arena.alloc(?LazySrcLoc, case_vals.len); | 11222 | const case_srcs = try sema.arena.alloc(?LazySrcLoc, case_vals.len); |
| 11283 | @memset(case_srcs, .unneeded); | 11223 | for (case_srcs, 0..) |*case_src, i| { |
| 11284 | | 11224 | case_src.* = .{ |
| 11285 | break :resolve sema.resolvePeerTypes(block, .unneeded, dummy_captures, .{ .override = case_srcs }) catch |err| switch (err) { | 11225 | .base_node_inst = capture_src.base_node_inst, |
| 11286 | error.NeededSourceLocation => { | 11226 | .offset = .{ .switch_case_item = .{ |
| 11287 | // This must be a multi-prong so this must be a `multi_capture` src | 11227 | .switch_node_offset = switch_node_offset, |
| 11288 | const multi_idx = raw_capture_src.multi_capture; | 11228 | .case_idx = capture_src.offset.switch_capture.case_idx, |
| 11289 | const src_decl_ptr = zcu.declPtr(block.src_decl); | 11229 | .item_idx = .{ .kind = .single, .index = @intCast(i) }, |
| 11290 | for (case_srcs, 0..) |*case_src, i| { | 11230 | } }, |
| 11291 | const raw_case_src: Module.SwitchProngSrc = .{ .multi = .{ .prong = multi_idx, .item = @intCast(i) } }; | 11231 | }; |
| 11292 | case_src.* = raw_case_src.resolve(zcu, src_decl_ptr, switch_node_offset, .none); | 11232 | } |
| 11293 | } | 11233 | |
| 11294 | const capture_src = raw_capture_src.resolve(zcu, src_decl_ptr, switch_node_offset, .none); | 11234 | break :resolve sema.resolvePeerTypes(block, capture_src, dummy_captures, .{ .override = case_srcs }) catch |err| switch (err) { |
| 11295 | _ = sema.resolvePeerTypes(block, capture_src, dummy_captures, .{ .override = case_srcs }) catch |err1| switch (err1) { | 11235 | error.AnalysisFail => { |
| 11296 | error.AnalysisFail => { | 11236 | const msg = sema.err orelse return error.AnalysisFail; |
| 11297 | const msg = sema.err orelse return error.AnalysisFail; | 11237 | try sema.errNote(capture_src, msg, "this coercion is only possible when capturing by value", .{}); |
| 11298 | try sema.errNote(block, capture_src, msg, "this coercion is only possible when capturing by value", .{}); | 11238 | try sema.reparentOwnedErrorMsg(capture_src, msg, "capture group with incompatible types", .{}); |
| 11299 | try sema.reparentOwnedErrorMsg(block, capture_src, msg, "capture group with incompatible types", .{}); | 11239 | return error.AnalysisFail; |
| 11300 | return error.AnalysisFail; | | |
| 11301 | }, | | |
| 11302 | else => |e| return e, | | |
| 11303 | }; | | |
| 11304 | unreachable; | | |
| 11305 | }, | 11240 | }, |
| 11306 | else => |e| return e, | 11241 | else => |e| return e, |
| 11307 | }; | 11242 | }; |
| ... | @@ -11336,7 +11271,7 @@ const SwitchProngAnalysis = struct { | ... | @@ -11336,7 +11271,7 @@ const SwitchProngAnalysis = struct { |
| 11336 | const first_non_imc = in_mem: { | 11271 | const first_non_imc = in_mem: { |
| 11337 | for (field_indices, 0..) |field_idx, i| { | 11272 | for (field_indices, 0..) |field_idx, i| { |
| 11338 | const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[field_idx]); | 11273 | const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[field_idx]); |
| 11339 | if (.ok != try sema.coerceInMemoryAllowed(block, capture_ty, field_ty, false, zcu.getTarget(), .unneeded, .unneeded)) { | 11274 | if (.ok != try sema.coerceInMemoryAllowed(block, capture_ty, field_ty, false, zcu.getTarget(), LazySrcLoc.unneeded, LazySrcLoc.unneeded)) { |
| 11340 | break :in_mem i; | 11275 | break :in_mem i; |
| 11341 | } | 11276 | } |
| 11342 | } | 11277 | } |
| ... | @@ -11359,7 +11294,7 @@ const SwitchProngAnalysis = struct { | ... | @@ -11359,7 +11294,7 @@ const SwitchProngAnalysis = struct { |
| 11359 | const next = first_non_imc + 1; | 11294 | const next = first_non_imc + 1; |
| 11360 | for (field_indices[next..], next..) |field_idx, i| { | 11295 | for (field_indices[next..], next..) |field_idx, i| { |
| 11361 | const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[field_idx]); | 11296 | const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[field_idx]); |
| 11362 | if (.ok != try sema.coerceInMemoryAllowed(block, capture_ty, field_ty, false, zcu.getTarget(), .unneeded, .unneeded)) { | 11297 | if (.ok != try sema.coerceInMemoryAllowed(block, capture_ty, field_ty, false, zcu.getTarget(), LazySrcLoc.unneeded, LazySrcLoc.unneeded)) { |
| 11363 | in_mem_coercible.unset(i); | 11298 | in_mem_coercible.unset(i); |
| 11364 | } | 11299 | } |
| 11365 | } | 11300 | } |
| ... | @@ -11388,20 +11323,19 @@ const SwitchProngAnalysis = struct { | ... | @@ -11388,20 +11323,19 @@ const SwitchProngAnalysis = struct { |
| 11388 | var coerce_block = block.makeSubBlock(); | 11323 | var coerce_block = block.makeSubBlock(); |
| 11389 | defer coerce_block.instructions.deinit(sema.gpa); | 11324 | defer coerce_block.instructions.deinit(sema.gpa); |
| 11390 | | 11325 | |
| | 11326 | const case_src: LazySrcLoc = .{ |
| | 11327 | .base_node_inst = capture_src.base_node_inst, |
| | 11328 | .offset = .{ .switch_case_item = .{ |
| | 11329 | .switch_node_offset = switch_node_offset, |
| | 11330 | .case_idx = capture_src.offset.switch_capture.case_idx, |
| | 11331 | .item_idx = .{ .kind = .single, .index = @intCast(idx) }, |
| | 11332 | } }, |
| | 11333 | }; |
| | 11334 | |
| 11391 | const field_idx = field_indices[idx]; | 11335 | const field_idx = field_indices[idx]; |
| 11392 | const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[field_idx]); | 11336 | const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[field_idx]); |
| 11393 | const uncoerced = try coerce_block.addStructFieldVal(spa.operand, field_idx, field_ty); | 11337 | const uncoerced = try coerce_block.addStructFieldVal(spa.operand, field_idx, field_ty); |
| 11394 | const coerced = sema.coerce(&coerce_block, capture_ty, uncoerced, .unneeded) catch |err| switch (err) { | 11338 | const coerced = try sema.coerce(&coerce_block, capture_ty, uncoerced, case_src); |
| 11395 | error.NeededSourceLocation => { | | |
| 11396 | const multi_idx = raw_capture_src.multi_capture; | | |
| 11397 | const src_decl_ptr = zcu.declPtr(block.src_decl); | | |
| 11398 | const raw_case_src: Module.SwitchProngSrc = .{ .multi = .{ .prong = multi_idx, .item = @intCast(idx) } }; | | |
| 11399 | const case_src = raw_case_src.resolve(zcu, src_decl_ptr, switch_node_offset, .none); | | |
| 11400 | _ = try sema.coerce(&coerce_block, capture_ty, uncoerced, case_src); | | |
| 11401 | unreachable; | | |
| 11402 | }, | | |
| 11403 | else => |e| return e, | | |
| 11404 | }; | | |
| 11405 | _ = try coerce_block.addBr(capture_block_inst, coerced); | 11339 | _ = try coerce_block.addBr(capture_block_inst, coerced); |
| 11406 | | 11340 | |
| 11407 | try cases_extra.ensureUnusedCapacity(3 + coerce_block.instructions.items.len); | 11341 | try cases_extra.ensureUnusedCapacity(3 + coerce_block.instructions.items.len); |
| ... | @@ -11455,7 +11389,6 @@ const SwitchProngAnalysis = struct { | ... | @@ -11455,7 +11389,6 @@ const SwitchProngAnalysis = struct { |
| 11455 | }, | 11389 | }, |
| 11456 | .ErrorSet => { | 11390 | .ErrorSet => { |
| 11457 | if (capture_byref) { | 11391 | if (capture_byref) { |
| 11458 | const capture_src = raw_capture_src.resolve(zcu, zcu.declPtr(block.src_decl), switch_node_offset, .none); | | |
| 11459 | return sema.fail( | 11392 | return sema.fail( |
| 11460 | block, | 11393 | block, |
| 11461 | capture_src, | 11394 | capture_src, |
| ... | @@ -11465,7 +11398,7 @@ const SwitchProngAnalysis = struct { | ... | @@ -11465,7 +11398,7 @@ const SwitchProngAnalysis = struct { |
| 11465 | } | 11398 | } |
| 11466 | | 11399 | |
| 11467 | if (case_vals.len == 1) { | 11400 | if (case_vals.len == 1) { |
| 11468 | const item_val = sema.resolveConstDefinedValue(block, .unneeded, case_vals[0], undefined) catch unreachable; | 11401 | const item_val = sema.resolveConstDefinedValue(block, LazySrcLoc.unneeded, case_vals[0], undefined) catch unreachable; |
| 11469 | const item_ty = try zcu.singleErrorSetType(item_val.getErrorName(zcu).unwrap().?); | 11402 | const item_ty = try zcu.singleErrorSetType(item_val.getErrorName(zcu).unwrap().?); |
| 11470 | return sema.bitCast(block, item_ty, spa.operand, operand_src, null); | 11403 | return sema.bitCast(block, item_ty, spa.operand, operand_src, null); |
| 11471 | } | 11404 | } |
| ... | @@ -11473,7 +11406,7 @@ const SwitchProngAnalysis = struct { | ... | @@ -11473,7 +11406,7 @@ const SwitchProngAnalysis = struct { |
| 11473 | var names: InferredErrorSet.NameMap = .{}; | 11406 | var names: InferredErrorSet.NameMap = .{}; |
| 11474 | try names.ensureUnusedCapacity(sema.arena, case_vals.len); | 11407 | try names.ensureUnusedCapacity(sema.arena, case_vals.len); |
| 11475 | for (case_vals) |err| { | 11408 | for (case_vals) |err| { |
| 11476 | const err_val = sema.resolveConstDefinedValue(block, .unneeded, err, undefined) catch unreachable; | 11409 | const err_val = sema.resolveConstDefinedValue(block, LazySrcLoc.unneeded, err, undefined) catch unreachable; |
| 11477 | names.putAssumeCapacityNoClobber(err_val.getErrorName(zcu).unwrap().?, {}); | 11410 | names.putAssumeCapacityNoClobber(err_val.getErrorName(zcu).unwrap().?, {}); |
| 11478 | } | 11411 | } |
| 11479 | const error_ty = try zcu.errorSetFromUnsortedNames(names.keys()); | 11412 | const error_ty = try zcu.errorSetFromUnsortedNames(names.keys()); |
| ... | @@ -11527,10 +11460,10 @@ fn switchCond( | ... | @@ -11527,10 +11460,10 @@ fn switchCond( |
| 11527 | try sema.resolveTypeFields(operand_ty); | 11460 | try sema.resolveTypeFields(operand_ty); |
| 11528 | const enum_ty = operand_ty.unionTagType(mod) orelse { | 11461 | const enum_ty = operand_ty.unionTagType(mod) orelse { |
| 11529 | const msg = msg: { | 11462 | const msg = msg: { |
| 11530 | const msg = try sema.errMsg(block, src, "switch on union with no attached enum", .{}); | 11463 | const msg = try sema.errMsg(src, "switch on union with no attached enum", .{}); |
| 11531 | errdefer msg.destroy(sema.gpa); | 11464 | errdefer msg.destroy(sema.gpa); |
| 11532 | if (operand_ty.declSrcLocOrNull(mod)) |union_src| { | 11465 | if (operand_ty.srcLocOrNull(mod)) |union_src| { |
| 11533 | try mod.errNoteNonLazy(union_src, msg, "consider 'union(enum)' here", .{}); | 11466 | try sema.errNote(union_src, msg, "consider 'union(enum)' here", .{}); |
| 11534 | } | 11467 | } |
| 11535 | break :msg msg; | 11468 | break :msg msg; |
| 11536 | }; | 11469 | }; |
| ... | @@ -11554,7 +11487,7 @@ fn switchCond( | ... | @@ -11554,7 +11487,7 @@ fn switchCond( |
| 11554 | } | 11487 | } |
| 11555 | } | 11488 | } |
| 11556 | | 11489 | |
| 11557 | const SwitchErrorSet = std.AutoHashMap(InternPool.NullTerminatedString, Module.SwitchProngSrc); | 11490 | const SwitchErrorSet = std.AutoHashMap(InternPool.NullTerminatedString, LazySrcLoc); |
| 11558 | | 11491 | |
| 11559 | fn zirSwitchBlockErrUnion(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 11492 | fn zirSwitchBlockErrUnion(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 11560 | const tracy = trace(@src()); | 11493 | const tracy = trace(@src()); |
| ... | @@ -11563,13 +11496,13 @@ fn zirSwitchBlockErrUnion(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp | ... | @@ -11563,13 +11496,13 @@ fn zirSwitchBlockErrUnion(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp |
| 11563 | const mod = sema.mod; | 11496 | const mod = sema.mod; |
| 11564 | const gpa = sema.gpa; | 11497 | const gpa = sema.gpa; |
| 11565 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 11498 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 11566 | const switch_src = inst_data.src(); | 11499 | const switch_src = block.nodeOffset(inst_data.src_node); |
| 11567 | const switch_src_node_offset = inst_data.src_node; | 11500 | const switch_src_node_offset = inst_data.src_node; |
| 11568 | const switch_operand_src: LazySrcLoc = .{ .node_offset_switch_operand = switch_src_node_offset }; | 11501 | const switch_operand_src = block.src(.{ .node_offset_switch_operand = switch_src_node_offset }); |
| 11569 | const else_prong_src: LazySrcLoc = .{ .node_offset_switch_special_prong = switch_src_node_offset }; | 11502 | const else_prong_src = block.src(.{ .node_offset_switch_special_prong = switch_src_node_offset }); |
| 11570 | const extra = sema.code.extraData(Zir.Inst.SwitchBlockErrUnion, inst_data.payload_index); | 11503 | const extra = sema.code.extraData(Zir.Inst.SwitchBlockErrUnion, inst_data.payload_index); |
| 11571 | const main_operand_src: LazySrcLoc = .{ .node_offset_if_cond = extra.data.main_src_node_offset }; | 11504 | const main_operand_src = block.src(.{ .node_offset_if_cond = extra.data.main_src_node_offset }); |
| 11572 | const main_src: LazySrcLoc = .{ .node_offset_main_token = extra.data.main_src_node_offset }; | 11505 | const main_src = block.src(.{ .node_offset_main_token = extra.data.main_src_node_offset }); |
| 11573 | | 11506 | |
| 11574 | const raw_operand_val = try sema.resolveInst(extra.data.operand); | 11507 | const raw_operand_val = try sema.resolveInst(extra.data.operand); |
| 11575 | | 11508 | |
| ... | @@ -11675,7 +11608,6 @@ fn zirSwitchBlockErrUnion(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp | ... | @@ -11675,7 +11608,6 @@ fn zirSwitchBlockErrUnion(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp |
| 11675 | var child_block: Block = .{ | 11608 | var child_block: Block = .{ |
| 11676 | .parent = block, | 11609 | .parent = block, |
| 11677 | .sema = sema, | 11610 | .sema = sema, |
| 11678 | .src_decl = block.src_decl, | | |
| 11679 | .namespace = block.namespace, | 11611 | .namespace = block.namespace, |
| 11680 | .instructions = .{}, | 11612 | .instructions = .{}, |
| 11681 | .label = &label, | 11613 | .label = &label, |
| ... | @@ -11689,6 +11621,8 @@ fn zirSwitchBlockErrUnion(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp | ... | @@ -11689,6 +11621,8 @@ fn zirSwitchBlockErrUnion(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp |
| 11689 | .runtime_index = block.runtime_index, | 11621 | .runtime_index = block.runtime_index, |
| 11690 | .error_return_trace_index = block.error_return_trace_index, | 11622 | .error_return_trace_index = block.error_return_trace_index, |
| 11691 | .want_safety = block.want_safety, | 11623 | .want_safety = block.want_safety, |
| | 11624 | .src_base_inst = block.src_base_inst, |
| | 11625 | .type_name_ctx = block.type_name_ctx, |
| 11692 | }; | 11626 | }; |
| 11693 | const merges = &child_block.label.?.merges; | 11627 | const merges = &child_block.label.?.merges; |
| 11694 | defer child_block.instructions.deinit(gpa); | 11628 | defer child_block.instructions.deinit(gpa); |
| ... | @@ -11755,6 +11689,7 @@ fn zirSwitchBlockErrUnion(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp | ... | @@ -11755,6 +11689,7 @@ fn zirSwitchBlockErrUnion(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp |
| 11755 | try sema.switchCond(block, switch_operand_src, spa.operand), | 11689 | try sema.switchCond(block, switch_operand_src, spa.operand), |
| 11756 | err_val, | 11690 | err_val, |
| 11757 | operand_err_set_ty, | 11691 | operand_err_set_ty, |
| | 11692 | switch_src_node_offset, |
| 11758 | .{ | 11693 | .{ |
| 11759 | .body = else_case.body, | 11694 | .body = else_case.body, |
| 11760 | .end = else_case.end, | 11695 | .end = else_case.end, |
| ... | @@ -11796,7 +11731,7 @@ fn zirSwitchBlockErrUnion(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp | ... | @@ -11796,7 +11731,7 @@ fn zirSwitchBlockErrUnion(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp |
| 11796 | | 11731 | |
| 11797 | var sub_block = child_block.makeSubBlock(); | 11732 | var sub_block = child_block.makeSubBlock(); |
| 11798 | sub_block.runtime_loop = null; | 11733 | sub_block.runtime_loop = null; |
| 11799 | sub_block.runtime_cond = mod.declPtr(child_block.src_decl).toSrcLoc(main_operand_src, mod); | 11734 | sub_block.runtime_cond = main_operand_src; |
| 11800 | sub_block.runtime_index.increment(); | 11735 | sub_block.runtime_index.increment(); |
| 11801 | sub_block.need_debug_scope = null; // this body is emitted regardless | 11736 | sub_block.need_debug_scope = null; // this body is emitted regardless |
| 11802 | defer sub_block.instructions.deinit(gpa); | 11737 | defer sub_block.instructions.deinit(gpa); |
| ... | @@ -11871,10 +11806,10 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r | ... | @@ -11871,10 +11806,10 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 11871 | const mod = sema.mod; | 11806 | const mod = sema.mod; |
| 11872 | const gpa = sema.gpa; | 11807 | const gpa = sema.gpa; |
| 11873 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 11808 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 11874 | const src = inst_data.src(); | 11809 | const src = block.nodeOffset(inst_data.src_node); |
| 11875 | const src_node_offset = inst_data.src_node; | 11810 | const src_node_offset = inst_data.src_node; |
| 11876 | const operand_src: LazySrcLoc = .{ .node_offset_switch_operand = src_node_offset }; | 11811 | const operand_src = block.src(.{ .node_offset_switch_operand = src_node_offset }); |
| 11877 | const special_prong_src: LazySrcLoc = .{ .node_offset_switch_special_prong = src_node_offset }; | 11812 | const special_prong_src = block.src(.{ .node_offset_switch_special_prong = src_node_offset }); |
| 11878 | const extra = sema.code.extraData(Zir.Inst.SwitchBlock, inst_data.payload_index); | 11813 | const extra = sema.code.extraData(Zir.Inst.SwitchBlock, inst_data.payload_index); |
| 11879 | | 11814 | |
| 11880 | const raw_operand_val: Air.Inst.Ref, const raw_operand_ptr: Air.Inst.Ref = blk: { | 11815 | const raw_operand_val: Air.Inst.Ref, const raw_operand_ptr: Air.Inst.Ref = blk: { |
| ... | @@ -11941,7 +11876,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r | ... | @@ -11941,7 +11876,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 11941 | const union_originally = maybe_union_ty.zigTypeTag(mod) == .Union; | 11876 | const union_originally = maybe_union_ty.zigTypeTag(mod) == .Union; |
| 11942 | | 11877 | |
| 11943 | // Duplicate checking variables later also used for `inline else`. | 11878 | // Duplicate checking variables later also used for `inline else`. |
| 11944 | var seen_enum_fields: []?Module.SwitchProngSrc = &.{}; | 11879 | var seen_enum_fields: []?LazySrcLoc = &.{}; |
| 11945 | var seen_errors = SwitchErrorSet.init(gpa); | 11880 | var seen_errors = SwitchErrorSet.init(gpa); |
| 11946 | var range_set = RangeSet.init(gpa, mod); | 11881 | var range_set = RangeSet.init(gpa, mod); |
| 11947 | var true_count: u8 = 0; | 11882 | var true_count: u8 = 0; |
| ... | @@ -11964,21 +11899,18 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r | ... | @@ -11964,21 +11899,18 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 11964 | if (special_prong == .under and (!operand_ty.isNonexhaustiveEnum(mod) or union_originally)) { | 11899 | if (special_prong == .under and (!operand_ty.isNonexhaustiveEnum(mod) or union_originally)) { |
| 11965 | const msg = msg: { | 11900 | const msg = msg: { |
| 11966 | const msg = try sema.errMsg( | 11901 | const msg = try sema.errMsg( |
| 11967 | block, | | |
| 11968 | src, | 11902 | src, |
| 11969 | "'_' prong only allowed when switching on non-exhaustive enums", | 11903 | "'_' prong only allowed when switching on non-exhaustive enums", |
| 11970 | .{}, | 11904 | .{}, |
| 11971 | ); | 11905 | ); |
| 11972 | errdefer msg.destroy(gpa); | 11906 | errdefer msg.destroy(gpa); |
| 11973 | try sema.errNote( | 11907 | try sema.errNote( |
| 11974 | block, | | |
| 11975 | special_prong_src, | 11908 | special_prong_src, |
| 11976 | msg, | 11909 | msg, |
| 11977 | "'_' prong here", | 11910 | "'_' prong here", |
| 11978 | .{}, | 11911 | .{}, |
| 11979 | ); | 11912 | ); |
| 11980 | try sema.errNote( | 11913 | try sema.errNote( |
| 11981 | block, | | |
| 11982 | src, | 11914 | src, |
| 11983 | msg, | 11915 | msg, |
| 11984 | "consider using 'else'", | 11916 | "consider using 'else'", |
| ... | @@ -11993,7 +11925,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r | ... | @@ -11993,7 +11925,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 11993 | switch (operand_ty.zigTypeTag(mod)) { | 11925 | switch (operand_ty.zigTypeTag(mod)) { |
| 11994 | .Union => unreachable, // handled in `switchCond` | 11926 | .Union => unreachable, // handled in `switchCond` |
| 11995 | .Enum => { | 11927 | .Enum => { |
| 11996 | seen_enum_fields = try gpa.alloc(?Module.SwitchProngSrc, operand_ty.enumFieldCount(mod)); | 11928 | seen_enum_fields = try gpa.alloc(?LazySrcLoc, operand_ty.enumFieldCount(mod)); |
| 11997 | empty_enum = seen_enum_fields.len == 0 and !operand_ty.isNonexhaustiveEnum(mod); | 11929 | empty_enum = seen_enum_fields.len == 0 and !operand_ty.isNonexhaustiveEnum(mod); |
| 11998 | @memset(seen_enum_fields, null); | 11930 | @memset(seen_enum_fields, null); |
| 11999 | // `range_set` is used for non-exhaustive enum values that do not correspond to any tags. | 11931 | // `range_set` is used for non-exhaustive enum values that do not correspond to any tags. |
| ... | @@ -12013,8 +11945,11 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r | ... | @@ -12013,8 +11945,11 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 12013 | &range_set, | 11945 | &range_set, |
| 12014 | item_ref, | 11946 | item_ref, |
| 12015 | operand_ty, | 11947 | operand_ty, |
| 12016 | src_node_offset, | 11948 | block.src(.{ .switch_case_item = .{ |
| 12017 | .{ .scalar = scalar_i }, | 11949 | .switch_node_offset = src_node_offset, |
| | 11950 | .case_idx = .{ .kind = .scalar, .index = @intCast(scalar_i) }, |
| | 11951 | .item_idx = .{ .kind = .single, .index = 0 }, |
| | 11952 | } }), |
| 12018 | )); | 11953 | )); |
| 12019 | } | 11954 | } |
| 12020 | } | 11955 | } |
| ... | @@ -12038,8 +11973,11 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r | ... | @@ -12038,8 +11973,11 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 12038 | &range_set, | 11973 | &range_set, |
| 12039 | item_ref, | 11974 | item_ref, |
| 12040 | operand_ty, | 11975 | operand_ty, |
| 12041 | src_node_offset, | 11976 | block.src(.{ .switch_case_item = .{ |
| 12042 | .{ .multi = .{ .prong = multi_i, .item = @intCast(item_i) } }, | 11977 | .switch_node_offset = src_node_offset, |
| | 11978 | .case_idx = .{ .kind = .multi, .index = @intCast(multi_i) }, |
| | 11979 | .item_idx = .{ .kind = .single, .index = @intCast(item_i) }, |
| | 11980 | } }), |
| 12043 | )); | 11981 | )); |
| 12044 | } | 11982 | } |
| 12045 | | 11983 | |
| ... | @@ -12060,7 +11998,6 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r | ... | @@ -12060,7 +11998,6 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 12060 | } else if (!all_tags_handled) { | 11998 | } else if (!all_tags_handled) { |
| 12061 | const msg = msg: { | 11999 | const msg = msg: { |
| 12062 | const msg = try sema.errMsg( | 12000 | const msg = try sema.errMsg( |
| 12063 | block, | | |
| 12064 | src, | 12001 | src, |
| 12065 | "switch must handle all possibilities", | 12002 | "switch must handle all possibilities", |
| 12066 | .{}, | 12003 | .{}, |
| ... | @@ -12078,8 +12015,8 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r | ... | @@ -12078,8 +12015,8 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 12078 | .{field_name.fmt(&mod.intern_pool)}, | 12015 | .{field_name.fmt(&mod.intern_pool)}, |
| 12079 | ); | 12016 | ); |
| 12080 | } | 12017 | } |
| 12081 | try mod.errNoteNonLazy( | 12018 | try sema.errNote( |
| 12082 | operand_ty.declSrcLoc(mod), | 12019 | operand_ty.srcLoc(mod), |
| 12083 | msg, | 12020 | msg, |
| 12084 | "enum '{}' declared here", | 12021 | "enum '{}' declared here", |
| 12085 | .{operand_ty.fmt(mod)}, | 12022 | .{operand_ty.fmt(mod)}, |
| ... | @@ -12123,8 +12060,11 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r | ... | @@ -12123,8 +12060,11 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 12123 | &range_set, | 12060 | &range_set, |
| 12124 | item_ref, | 12061 | item_ref, |
| 12125 | operand_ty, | 12062 | operand_ty, |
| 12126 | src_node_offset, | 12063 | block.src(.{ .switch_case_item = .{ |
| 12127 | .{ .scalar = scalar_i }, | 12064 | .switch_node_offset = src_node_offset, |
| | 12065 | .case_idx = .{ .kind = .scalar, .index = @intCast(scalar_i) }, |
| | 12066 | .item_idx = .{ .kind = .single, .index = 0 }, |
| | 12067 | } }), |
| 12128 | )); | 12068 | )); |
| 12129 | } | 12069 | } |
| 12130 | } | 12070 | } |
| ... | @@ -12147,8 +12087,11 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r | ... | @@ -12147,8 +12087,11 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 12147 | &range_set, | 12087 | &range_set, |
| 12148 | item_ref, | 12088 | item_ref, |
| 12149 | operand_ty, | 12089 | operand_ty, |
| 12150 | src_node_offset, | 12090 | block.src(.{ .switch_case_item = .{ |
| 12151 | .{ .multi = .{ .prong = multi_i, .item = @intCast(item_i) } }, | 12091 | .switch_node_offset = src_node_offset, |
| | 12092 | .case_idx = .{ .kind = .multi, .index = @intCast(multi_i) }, |
| | 12093 | .item_idx = .{ .kind = .single, .index = @intCast(item_i) }, |
| | 12094 | } }), |
| 12152 | )); | 12095 | )); |
| 12153 | } | 12096 | } |
| 12154 | | 12097 | |
| ... | @@ -12166,8 +12109,11 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r | ... | @@ -12166,8 +12109,11 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 12166 | item_first, | 12109 | item_first, |
| 12167 | item_last, | 12110 | item_last, |
| 12168 | operand_ty, | 12111 | operand_ty, |
| 12169 | src_node_offset, | 12112 | block.src(.{ .switch_case_item = .{ |
| 12170 | .{ .range = .{ .prong = multi_i, .item = range_i } }, | 12113 | .switch_node_offset = src_node_offset, |
| | 12114 | .case_idx = .{ .kind = .multi, .index = @intCast(multi_i) }, |
| | 12115 | .item_idx = .{ .kind = .range, .index = @intCast(range_i) }, |
| | 12116 | } }), |
| 12171 | ); | 12117 | ); |
| 12172 | case_vals.appendAssumeCapacity(vals[0]); | 12118 | case_vals.appendAssumeCapacity(vals[0]); |
| 12173 | case_vals.appendAssumeCapacity(vals[1]); | 12119 | case_vals.appendAssumeCapacity(vals[1]); |
| ... | @@ -12218,8 +12164,11 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r | ... | @@ -12218,8 +12164,11 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 12218 | &true_count, | 12164 | &true_count, |
| 12219 | &false_count, | 12165 | &false_count, |
| 12220 | item_ref, | 12166 | item_ref, |
| 12221 | src_node_offset, | 12167 | block.src(.{ .switch_case_item = .{ |
| 12222 | .{ .scalar = scalar_i }, | 12168 | .switch_node_offset = src_node_offset, |
| | 12169 | .case_idx = .{ .kind = .scalar, .index = @intCast(scalar_i) }, |
| | 12170 | .item_idx = .{ .kind = .single, .index = 0 }, |
| | 12171 | } }), |
| 12223 | )); | 12172 | )); |
| 12224 | } | 12173 | } |
| 12225 | } | 12174 | } |
| ... | @@ -12242,8 +12191,11 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r | ... | @@ -12242,8 +12191,11 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 12242 | &true_count, | 12191 | &true_count, |
| 12243 | &false_count, | 12192 | &false_count, |
| 12244 | item_ref, | 12193 | item_ref, |
| 12245 | src_node_offset, | 12194 | block.src(.{ .switch_case_item = .{ |
| 12246 | .{ .multi = .{ .prong = multi_i, .item = @intCast(item_i) } }, | 12195 | .switch_node_offset = src_node_offset, |
| | 12196 | .case_idx = .{ .kind = .multi, .index = @intCast(multi_i) }, |
| | 12197 | .item_idx = .{ .kind = .single, .index = @intCast(item_i) }, |
| | 12198 | } }), |
| 12247 | )); | 12199 | )); |
| 12248 | } | 12200 | } |
| 12249 | | 12201 | |
| ... | @@ -12301,8 +12253,11 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r | ... | @@ -12301,8 +12253,11 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 12301 | &seen_values, | 12253 | &seen_values, |
| 12302 | item_ref, | 12254 | item_ref, |
| 12303 | operand_ty, | 12255 | operand_ty, |
| 12304 | src_node_offset, | 12256 | block.src(.{ .switch_case_item = .{ |
| 12305 | .{ .scalar = scalar_i }, | 12257 | .switch_node_offset = src_node_offset, |
| | 12258 | .case_idx = .{ .kind = .scalar, .index = @intCast(scalar_i) }, |
| | 12259 | .item_idx = .{ .kind = .single, .index = 0 }, |
| | 12260 | } }), |
| 12306 | )); | 12261 | )); |
| 12307 | } | 12262 | } |
| 12308 | } | 12263 | } |
| ... | @@ -12325,8 +12280,11 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r | ... | @@ -12325,8 +12280,11 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 12325 | &seen_values, | 12280 | &seen_values, |
| 12326 | item_ref, | 12281 | item_ref, |
| 12327 | operand_ty, | 12282 | operand_ty, |
| 12328 | src_node_offset, | 12283 | block.src(.{ .switch_case_item = .{ |
| 12329 | .{ .multi = .{ .prong = multi_i, .item = @intCast(item_i) } }, | 12284 | .switch_node_offset = src_node_offset, |
| | 12285 | .case_idx = .{ .kind = .multi, .index = @intCast(multi_i) }, |
| | 12286 | .item_idx = .{ .kind = .single, .index = @intCast(item_i) }, |
| | 12287 | } }), |
| 12330 | )); | 12288 | )); |
| 12331 | } | 12289 | } |
| 12332 | | 12290 | |
| ... | @@ -12382,7 +12340,6 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r | ... | @@ -12382,7 +12340,6 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 12382 | var child_block: Block = .{ | 12340 | var child_block: Block = .{ |
| 12383 | .parent = block, | 12341 | .parent = block, |
| 12384 | .sema = sema, | 12342 | .sema = sema, |
| 12385 | .src_decl = block.src_decl, | | |
| 12386 | .namespace = block.namespace, | 12343 | .namespace = block.namespace, |
| 12387 | .instructions = .{}, | 12344 | .instructions = .{}, |
| 12388 | .label = &label, | 12345 | .label = &label, |
| ... | @@ -12396,6 +12353,8 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r | ... | @@ -12396,6 +12353,8 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 12396 | .runtime_index = block.runtime_index, | 12353 | .runtime_index = block.runtime_index, |
| 12397 | .want_safety = block.want_safety, | 12354 | .want_safety = block.want_safety, |
| 12398 | .error_return_trace_index = block.error_return_trace_index, | 12355 | .error_return_trace_index = block.error_return_trace_index, |
| | 12356 | .src_base_inst = block.src_base_inst, |
| | 12357 | .type_name_ctx = block.type_name_ctx, |
| 12399 | }; | 12358 | }; |
| 12400 | const merges = &child_block.label.?.merges; | 12359 | const merges = &child_block.label.?.merges; |
| 12401 | defer child_block.instructions.deinit(gpa); | 12360 | defer child_block.instructions.deinit(gpa); |
| ... | @@ -12409,6 +12368,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r | ... | @@ -12409,6 +12368,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 12409 | operand, | 12368 | operand, |
| 12410 | operand_val, | 12369 | operand_val, |
| 12411 | operand_ty, | 12370 | operand_ty, |
| | 12371 | src_node_offset, |
| 12412 | special, | 12372 | special, |
| 12413 | case_vals, | 12373 | case_vals, |
| 12414 | scalar_cases_len, | 12374 | scalar_cases_len, |
| ... | @@ -12441,7 +12401,10 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r | ... | @@ -12441,7 +12401,10 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 12441 | .special, | 12401 | .special, |
| 12442 | special.body, | 12402 | special.body, |
| 12443 | special.capture, | 12403 | special.capture, |
| 12444 | .special_capture, | 12404 | block.src(.{ .switch_capture = .{ |
| | 12405 | .switch_node_offset = src_node_offset, |
| | 12406 | .case_idx = LazySrcLoc.Offset.SwitchCaseIndex.special, |
| | 12407 | } }), |
| 12445 | undefined, // case_vals may be undefined for special prongs | 12408 | undefined, // case_vals may be undefined for special prongs |
| 12446 | .none, | 12409 | .none, |
| 12447 | false, | 12410 | false, |
| ... | @@ -12508,9 +12471,9 @@ fn analyzeSwitchRuntimeBlock( | ... | @@ -12508,9 +12471,9 @@ fn analyzeSwitchRuntimeBlock( |
| 12508 | union_originally: bool, | 12471 | union_originally: bool, |
| 12509 | maybe_union_ty: Type, | 12472 | maybe_union_ty: Type, |
| 12510 | err_set: bool, | 12473 | err_set: bool, |
| 12511 | src_node_offset: i32, | 12474 | switch_node_offset: i32, |
| 12512 | special_prong_src: LazySrcLoc, | 12475 | special_prong_src: LazySrcLoc, |
| 12513 | seen_enum_fields: []?Module.SwitchProngSrc, | 12476 | seen_enum_fields: []?LazySrcLoc, |
| 12514 | seen_errors: SwitchErrorSet, | 12477 | seen_errors: SwitchErrorSet, |
| 12515 | range_set: RangeSet, | 12478 | range_set: RangeSet, |
| 12516 | true_count: u8, | 12479 | true_count: u8, |
| ... | @@ -12531,7 +12494,7 @@ fn analyzeSwitchRuntimeBlock( | ... | @@ -12531,7 +12494,7 @@ fn analyzeSwitchRuntimeBlock( |
| 12531 | | 12494 | |
| 12532 | var case_block = child_block.makeSubBlock(); | 12495 | var case_block = child_block.makeSubBlock(); |
| 12533 | case_block.runtime_loop = null; | 12496 | case_block.runtime_loop = null; |
| 12534 | case_block.runtime_cond = mod.declPtr(child_block.src_decl).toSrcLoc(operand_src, mod); | 12497 | case_block.runtime_cond = operand_src; |
| 12535 | case_block.runtime_index.increment(); | 12498 | case_block.runtime_index.increment(); |
| 12536 | case_block.need_debug_scope = null; // this body is emitted regardless | 12499 | case_block.need_debug_scope = null; // this body is emitted regardless |
| 12537 | defer case_block.instructions.deinit(gpa); | 12500 | defer case_block.instructions.deinit(gpa); |
| ... | @@ -12553,7 +12516,7 @@ fn analyzeSwitchRuntimeBlock( | ... | @@ -12553,7 +12516,7 @@ fn analyzeSwitchRuntimeBlock( |
| 12553 | // `item` is already guaranteed to be constant known. | 12516 | // `item` is already guaranteed to be constant known. |
| 12554 | | 12517 | |
| 12555 | const analyze_body = if (union_originally) blk: { | 12518 | const analyze_body = if (union_originally) blk: { |
| 12556 | const unresolved_item_val = sema.resolveConstDefinedValue(block, .unneeded, item, undefined) catch unreachable; | 12519 | const unresolved_item_val = sema.resolveConstDefinedValue(block, LazySrcLoc.unneeded, item, undefined) catch unreachable; |
| 12557 | const item_val = sema.resolveLazyValue(unresolved_item_val) catch unreachable; | 12520 | const item_val = sema.resolveLazyValue(unresolved_item_val) catch unreachable; |
| 12558 | const field_ty = maybe_union_ty.unionFieldType(item_val, mod).?; | 12521 | const field_ty = maybe_union_ty.unionFieldType(item_val, mod).?; |
| 12559 | break :blk field_ty.zigTypeTag(mod) != .NoReturn; | 12522 | break :blk field_ty.zigTypeTag(mod) != .NoReturn; |
| ... | @@ -12567,7 +12530,10 @@ fn analyzeSwitchRuntimeBlock( | ... | @@ -12567,7 +12530,10 @@ fn analyzeSwitchRuntimeBlock( |
| 12567 | .normal, | 12530 | .normal, |
| 12568 | body, | 12531 | body, |
| 12569 | info.capture, | 12532 | info.capture, |
| 12570 | .{ .scalar_capture = @intCast(scalar_i) }, | 12533 | child_block.src(.{ .switch_capture = .{ |
| | 12534 | .switch_node_offset = switch_node_offset, |
| | 12535 | .case_idx = .{ .kind = .scalar, .index = @intCast(scalar_i) }, |
| | 12536 | } }), |
| 12571 | &.{item}, | 12537 | &.{item}, |
| 12572 | if (info.is_inline) item else .none, | 12538 | if (info.is_inline) item else .none, |
| 12573 | info.has_tag_capture, | 12539 | info.has_tag_capture, |
| ... | @@ -12622,8 +12588,8 @@ fn analyzeSwitchRuntimeBlock( | ... | @@ -12622,8 +12588,8 @@ fn analyzeSwitchRuntimeBlock( |
| 12622 | const item_first_ref = range_items[0]; | 12588 | const item_first_ref = range_items[0]; |
| 12623 | const item_last_ref = range_items[1]; | 12589 | const item_last_ref = range_items[1]; |
| 12624 | | 12590 | |
| 12625 | var item = sema.resolveConstDefinedValue(block, .unneeded, item_first_ref, undefined) catch unreachable; | 12591 | var item = sema.resolveConstDefinedValue(block, LazySrcLoc.unneeded, item_first_ref, undefined) catch unreachable; |
| 12626 | const item_last = sema.resolveConstDefinedValue(block, .unneeded, item_last_ref, undefined) catch unreachable; | 12592 | const item_last = sema.resolveConstDefinedValue(block, LazySrcLoc.unneeded, item_last_ref, undefined) catch unreachable; |
| 12627 | | 12593 | |
| 12628 | while (item.compareScalar(.lte, item_last, operand_ty, mod)) : ({ | 12594 | while (item.compareScalar(.lte, item_last, operand_ty, mod)) : ({ |
| 12629 | // Previous validation has resolved any possible lazy values. | 12595 | // Previous validation has resolved any possible lazy values. |
| ... | @@ -12639,17 +12605,11 @@ fn analyzeSwitchRuntimeBlock( | ... | @@ -12639,17 +12605,11 @@ fn analyzeSwitchRuntimeBlock( |
| 12639 | case_block.instructions.shrinkRetainingCapacity(0); | 12605 | case_block.instructions.shrinkRetainingCapacity(0); |
| 12640 | case_block.error_return_trace_index = child_block.error_return_trace_index; | 12606 | case_block.error_return_trace_index = child_block.error_return_trace_index; |
| 12641 | | 12607 | |
| 12642 | if (emit_bb) sema.emitBackwardBranch(block, .unneeded) catch |err| switch (err) { | 12608 | if (emit_bb) try sema.emitBackwardBranch(block, block.src(.{ .switch_case_item = .{ |
| 12643 | error.NeededSourceLocation => { | 12609 | .switch_node_offset = switch_node_offset, |
| 12644 | const case_src = Module.SwitchProngSrc{ | 12610 | .case_idx = .{ .kind = .multi, .index = @intCast(multi_i) }, |
| 12645 | .range = .{ .prong = multi_i, .item = range_i }, | 12611 | .item_idx = .{ .kind = .range, .index = @intCast(range_i) }, |
| 12646 | }; | 12612 | } })); |
| 12647 | const decl = mod.declPtr(case_block.src_decl); | | |
| 12648 | try sema.emitBackwardBranch(block, case_src.resolve(mod, decl, src_node_offset, .none)); | | |
| 12649 | unreachable; | | |
| 12650 | }, | | |
| 12651 | else => return err, | | |
| 12652 | }; | | |
| 12653 | emit_bb = true; | 12613 | emit_bb = true; |
| 12654 | | 12614 | |
| 12655 | try spa.analyzeProngRuntime( | 12615 | try spa.analyzeProngRuntime( |
| ... | @@ -12657,7 +12617,10 @@ fn analyzeSwitchRuntimeBlock( | ... | @@ -12657,7 +12617,10 @@ fn analyzeSwitchRuntimeBlock( |
| 12657 | .normal, | 12617 | .normal, |
| 12658 | body, | 12618 | body, |
| 12659 | info.capture, | 12619 | info.capture, |
| 12660 | .{ .multi_capture = multi_i }, | 12620 | child_block.src(.{ .switch_capture = .{ |
| | 12621 | .switch_node_offset = switch_node_offset, |
| | 12622 | .case_idx = .{ .kind = .multi, .index = @intCast(multi_i) }, |
| | 12623 | } }), |
| 12661 | undefined, // case_vals may be undefined for ranges | 12624 | undefined, // case_vals may be undefined for ranges |
| 12662 | item_ref, | 12625 | item_ref, |
| 12663 | info.has_tag_capture, | 12626 | info.has_tag_capture, |
| ... | @@ -12680,22 +12643,16 @@ fn analyzeSwitchRuntimeBlock( | ... | @@ -12680,22 +12643,16 @@ fn analyzeSwitchRuntimeBlock( |
| 12680 | case_block.error_return_trace_index = child_block.error_return_trace_index; | 12643 | case_block.error_return_trace_index = child_block.error_return_trace_index; |
| 12681 | | 12644 | |
| 12682 | const analyze_body = if (union_originally) blk: { | 12645 | const analyze_body = if (union_originally) blk: { |
| 12683 | const item_val = sema.resolveConstDefinedValue(block, .unneeded, item, undefined) catch unreachable; | 12646 | const item_val = sema.resolveConstDefinedValue(block, LazySrcLoc.unneeded, item, undefined) catch unreachable; |
| 12684 | const field_ty = maybe_union_ty.unionFieldType(item_val, mod).?; | 12647 | const field_ty = maybe_union_ty.unionFieldType(item_val, mod).?; |
| 12685 | break :blk field_ty.zigTypeTag(mod) != .NoReturn; | 12648 | break :blk field_ty.zigTypeTag(mod) != .NoReturn; |
| 12686 | } else true; | 12649 | } else true; |
| 12687 | | 12650 | |
| 12688 | if (emit_bb) sema.emitBackwardBranch(block, .unneeded) catch |err| switch (err) { | 12651 | if (emit_bb) try sema.emitBackwardBranch(block, block.src(.{ .switch_case_item = .{ |
| 12689 | error.NeededSourceLocation => { | 12652 | .switch_node_offset = switch_node_offset, |
| 12690 | const case_src = Module.SwitchProngSrc{ | 12653 | .case_idx = .{ .kind = .multi, .index = @intCast(multi_i) }, |
| 12691 | .multi = .{ .prong = multi_i, .item = @intCast(item_i) }, | 12654 | .item_idx = .{ .kind = .single, .index = @intCast(item_i) }, |
| 12692 | }; | 12655 | } })); |
| 12693 | const decl = mod.declPtr(case_block.src_decl); | | |
| 12694 | try sema.emitBackwardBranch(block, case_src.resolve(mod, decl, src_node_offset, .none)); | | |
| 12695 | unreachable; | | |
| 12696 | }, | | |
| 12697 | else => return err, | | |
| 12698 | }; | | |
| 12699 | emit_bb = true; | 12656 | emit_bb = true; |
| 12700 | | 12657 | |
| 12701 | if (analyze_body) { | 12658 | if (analyze_body) { |
| ... | @@ -12704,7 +12661,10 @@ fn analyzeSwitchRuntimeBlock( | ... | @@ -12704,7 +12661,10 @@ fn analyzeSwitchRuntimeBlock( |
| 12704 | .normal, | 12661 | .normal, |
| 12705 | body, | 12662 | body, |
| 12706 | info.capture, | 12663 | info.capture, |
| 12707 | .{ .multi_capture = multi_i }, | 12664 | child_block.src(.{ .switch_capture = .{ |
| | 12665 | .switch_node_offset = switch_node_offset, |
| | 12666 | .case_idx = .{ .kind = .multi, .index = @intCast(multi_i) }, |
| | 12667 | } }), |
| 12708 | &.{item}, | 12668 | &.{item}, |
| 12709 | item, | 12669 | item, |
| 12710 | info.has_tag_capture, | 12670 | info.has_tag_capture, |
| ... | @@ -12734,7 +12694,7 @@ fn analyzeSwitchRuntimeBlock( | ... | @@ -12734,7 +12694,7 @@ fn analyzeSwitchRuntimeBlock( |
| 12734 | | 12694 | |
| 12735 | const analyze_body = if (union_originally) | 12695 | const analyze_body = if (union_originally) |
| 12736 | for (items) |item| { | 12696 | for (items) |item| { |
| 12737 | const item_val = sema.resolveConstDefinedValue(block, .unneeded, item, undefined) catch unreachable; | 12697 | const item_val = sema.resolveConstDefinedValue(block, LazySrcLoc.unneeded, item, undefined) catch unreachable; |
| 12738 | const field_ty = maybe_union_ty.unionFieldType(item_val, mod).?; | 12698 | const field_ty = maybe_union_ty.unionFieldType(item_val, mod).?; |
| 12739 | if (field_ty.zigTypeTag(mod) != .NoReturn) break true; | 12699 | if (field_ty.zigTypeTag(mod) != .NoReturn) break true; |
| 12740 | } else false | 12700 | } else false |
| ... | @@ -12751,7 +12711,10 @@ fn analyzeSwitchRuntimeBlock( | ... | @@ -12751,7 +12711,10 @@ fn analyzeSwitchRuntimeBlock( |
| 12751 | .normal, | 12711 | .normal, |
| 12752 | body, | 12712 | body, |
| 12753 | info.capture, | 12713 | info.capture, |
| 12754 | .{ .multi_capture = multi_i }, | 12714 | child_block.src(.{ .switch_capture = .{ |
| | 12715 | .switch_node_offset = switch_node_offset, |
| | 12716 | .case_idx = .{ .kind = .multi, .index = @intCast(multi_i) }, |
| | 12717 | } }), |
| 12755 | items, | 12718 | items, |
| 12756 | .none, | 12719 | .none, |
| 12757 | false, | 12720 | false, |
| ... | @@ -12835,7 +12798,10 @@ fn analyzeSwitchRuntimeBlock( | ... | @@ -12835,7 +12798,10 @@ fn analyzeSwitchRuntimeBlock( |
| 12835 | .normal, | 12798 | .normal, |
| 12836 | body, | 12799 | body, |
| 12837 | info.capture, | 12800 | info.capture, |
| 12838 | .{ .multi_capture = multi_i }, | 12801 | child_block.src(.{ .switch_capture = .{ |
| | 12802 | .switch_node_offset = switch_node_offset, |
| | 12803 | .case_idx = .{ .kind = .multi, .index = @intCast(multi_i) }, |
| | 12804 | } }), |
| 12839 | items, | 12805 | items, |
| 12840 | .none, | 12806 | .none, |
| 12841 | false, | 12807 | false, |
| ... | @@ -12900,7 +12866,10 @@ fn analyzeSwitchRuntimeBlock( | ... | @@ -12900,7 +12866,10 @@ fn analyzeSwitchRuntimeBlock( |
| 12900 | .special, | 12866 | .special, |
| 12901 | special.body, | 12867 | special.body, |
| 12902 | special.capture, | 12868 | special.capture, |
| 12903 | .special_capture, | 12869 | child_block.src(.{ .switch_capture = .{ |
| | 12870 | .switch_node_offset = switch_node_offset, |
| | 12871 | .case_idx = LazySrcLoc.Offset.SwitchCaseIndex.special, |
| | 12872 | } }), |
| 12904 | &.{item_ref}, | 12873 | &.{item_ref}, |
| 12905 | item_ref, | 12874 | item_ref, |
| 12906 | special.has_tag_capture, | 12875 | special.has_tag_capture, |
| ... | @@ -12945,7 +12914,10 @@ fn analyzeSwitchRuntimeBlock( | ... | @@ -12945,7 +12914,10 @@ fn analyzeSwitchRuntimeBlock( |
| 12945 | .special, | 12914 | .special, |
| 12946 | special.body, | 12915 | special.body, |
| 12947 | special.capture, | 12916 | special.capture, |
| 12948 | .special_capture, | 12917 | child_block.src(.{ .switch_capture = .{ |
| | 12918 | .switch_node_offset = switch_node_offset, |
| | 12919 | .case_idx = LazySrcLoc.Offset.SwitchCaseIndex.special, |
| | 12920 | } }), |
| 12949 | &.{item_ref}, | 12921 | &.{item_ref}, |
| 12950 | item_ref, | 12922 | item_ref, |
| 12951 | special.has_tag_capture, | 12923 | special.has_tag_capture, |
| ... | @@ -12976,7 +12948,10 @@ fn analyzeSwitchRuntimeBlock( | ... | @@ -12976,7 +12948,10 @@ fn analyzeSwitchRuntimeBlock( |
| 12976 | .special, | 12948 | .special, |
| 12977 | special.body, | 12949 | special.body, |
| 12978 | special.capture, | 12950 | special.capture, |
| 12979 | .special_capture, | 12951 | child_block.src(.{ .switch_capture = .{ |
| | 12952 | .switch_node_offset = switch_node_offset, |
| | 12953 | .case_idx = LazySrcLoc.Offset.SwitchCaseIndex.special, |
| | 12954 | } }), |
| 12980 | &.{item_ref}, | 12955 | &.{item_ref}, |
| 12981 | item_ref, | 12956 | item_ref, |
| 12982 | special.has_tag_capture, | 12957 | special.has_tag_capture, |
| ... | @@ -13004,7 +12979,10 @@ fn analyzeSwitchRuntimeBlock( | ... | @@ -13004,7 +12979,10 @@ fn analyzeSwitchRuntimeBlock( |
| 13004 | .special, | 12979 | .special, |
| 13005 | special.body, | 12980 | special.body, |
| 13006 | special.capture, | 12981 | special.capture, |
| 13007 | .special_capture, | 12982 | child_block.src(.{ .switch_capture = .{ |
| | 12983 | .switch_node_offset = switch_node_offset, |
| | 12984 | .case_idx = LazySrcLoc.Offset.SwitchCaseIndex.special, |
| | 12985 | } }), |
| 13008 | &.{.bool_true}, | 12986 | &.{.bool_true}, |
| 13009 | .bool_true, | 12987 | .bool_true, |
| 13010 | special.has_tag_capture, | 12988 | special.has_tag_capture, |
| ... | @@ -13030,7 +13008,10 @@ fn analyzeSwitchRuntimeBlock( | ... | @@ -13030,7 +13008,10 @@ fn analyzeSwitchRuntimeBlock( |
| 13030 | .special, | 13008 | .special, |
| 13031 | special.body, | 13009 | special.body, |
| 13032 | special.capture, | 13010 | special.capture, |
| 13033 | .special_capture, | 13011 | child_block.src(.{ .switch_capture = .{ |
| | 13012 | .switch_node_offset = switch_node_offset, |
| | 13013 | .case_idx = LazySrcLoc.Offset.SwitchCaseIndex.special, |
| | 13014 | } }), |
| 13034 | &.{.bool_false}, | 13015 | &.{.bool_false}, |
| 13035 | .bool_false, | 13016 | .bool_false, |
| 13036 | special.has_tag_capture, | 13017 | special.has_tag_capture, |
| ... | @@ -13080,7 +13061,10 @@ fn analyzeSwitchRuntimeBlock( | ... | @@ -13080,7 +13061,10 @@ fn analyzeSwitchRuntimeBlock( |
| 13080 | .special, | 13061 | .special, |
| 13081 | special.body, | 13062 | special.body, |
| 13082 | special.capture, | 13063 | special.capture, |
| 13083 | .special_capture, | 13064 | child_block.src(.{ .switch_capture = .{ |
| | 13065 | .switch_node_offset = switch_node_offset, |
| | 13066 | .case_idx = LazySrcLoc.Offset.SwitchCaseIndex.special, |
| | 13067 | } }), |
| 13084 | undefined, // case_vals may be undefined for special prongs | 13068 | undefined, // case_vals may be undefined for special prongs |
| 13085 | .none, | 13069 | .none, |
| 13086 | false, | 13070 | false, |
| ... | @@ -13140,6 +13124,7 @@ fn resolveSwitchComptime( | ... | @@ -13140,6 +13124,7 @@ fn resolveSwitchComptime( |
| 13140 | cond_operand: Air.Inst.Ref, | 13124 | cond_operand: Air.Inst.Ref, |
| 13141 | operand_val: Value, | 13125 | operand_val: Value, |
| 13142 | operand_ty: Type, | 13126 | operand_ty: Type, |
| | 13127 | switch_node_offset: i32, |
| 13143 | special: SpecialProng, | 13128 | special: SpecialProng, |
| 13144 | case_vals: std.ArrayListUnmanaged(Air.Inst.Ref), | 13129 | case_vals: std.ArrayListUnmanaged(Air.Inst.Ref), |
| 13145 | scalar_cases_len: u32, | 13130 | scalar_cases_len: u32, |
| ... | @@ -13160,7 +13145,7 @@ fn resolveSwitchComptime( | ... | @@ -13160,7 +13145,7 @@ fn resolveSwitchComptime( |
| 13160 | extra_index += info.body_len; | 13145 | extra_index += info.body_len; |
| 13161 | | 13146 | |
| 13162 | const item = case_vals.items[scalar_i]; | 13147 | const item = case_vals.items[scalar_i]; |
| 13163 | const item_val = sema.resolveConstDefinedValue(child_block, .unneeded, item, undefined) catch unreachable; | 13148 | const item_val = sema.resolveConstDefinedValue(child_block, LazySrcLoc.unneeded, item, undefined) catch unreachable; |
| 13164 | if (operand_val.eql(item_val, operand_ty, sema.mod)) { | 13149 | if (operand_val.eql(item_val, operand_ty, sema.mod)) { |
| 13165 | if (err_set) try sema.maybeErrorUnwrapComptime(child_block, body, cond_operand); | 13150 | if (err_set) try sema.maybeErrorUnwrapComptime(child_block, body, cond_operand); |
| 13166 | return spa.resolveProngComptime( | 13151 | return spa.resolveProngComptime( |
| ... | @@ -13168,7 +13153,10 @@ fn resolveSwitchComptime( | ... | @@ -13168,7 +13153,10 @@ fn resolveSwitchComptime( |
| 13168 | .normal, | 13153 | .normal, |
| 13169 | body, | 13154 | body, |
| 13170 | info.capture, | 13155 | info.capture, |
| 13171 | .{ .scalar_capture = @intCast(scalar_i) }, | 13156 | child_block.src(.{ .switch_capture = .{ |
| | 13157 | .switch_node_offset = switch_node_offset, |
| | 13158 | .case_idx = .{ .kind = .scalar, .index = @intCast(scalar_i) }, |
| | 13159 | } }), |
| 13172 | &.{item}, | 13160 | &.{item}, |
| 13173 | if (info.is_inline) cond_operand else .none, | 13161 | if (info.is_inline) cond_operand else .none, |
| 13174 | info.has_tag_capture, | 13162 | info.has_tag_capture, |
| ... | @@ -13194,7 +13182,7 @@ fn resolveSwitchComptime( | ... | @@ -13194,7 +13182,7 @@ fn resolveSwitchComptime( |
| 13194 | | 13182 | |
| 13195 | for (items) |item| { | 13183 | for (items) |item| { |
| 13196 | // Validation above ensured these will succeed. | 13184 | // Validation above ensured these will succeed. |
| 13197 | const item_val = sema.resolveConstDefinedValue(child_block, .unneeded, item, undefined) catch unreachable; | 13185 | const item_val = sema.resolveConstDefinedValue(child_block, LazySrcLoc.unneeded, item, undefined) catch unreachable; |
| 13198 | if (operand_val.eql(item_val, operand_ty, sema.mod)) { | 13186 | if (operand_val.eql(item_val, operand_ty, sema.mod)) { |
| 13199 | if (err_set) try sema.maybeErrorUnwrapComptime(child_block, body, cond_operand); | 13187 | if (err_set) try sema.maybeErrorUnwrapComptime(child_block, body, cond_operand); |
| 13200 | return spa.resolveProngComptime( | 13188 | return spa.resolveProngComptime( |
| ... | @@ -13202,7 +13190,10 @@ fn resolveSwitchComptime( | ... | @@ -13202,7 +13190,10 @@ fn resolveSwitchComptime( |
| 13202 | .normal, | 13190 | .normal, |
| 13203 | body, | 13191 | body, |
| 13204 | info.capture, | 13192 | info.capture, |
| 13205 | .{ .multi_capture = @intCast(multi_i) }, | 13193 | child_block.src(.{ .switch_capture = .{ |
| | 13194 | .switch_node_offset = switch_node_offset, |
| | 13195 | .case_idx = .{ .kind = .multi, .index = @intCast(multi_i) }, |
| | 13196 | } }), |
| 13206 | items, | 13197 | items, |
| 13207 | if (info.is_inline) cond_operand else .none, | 13198 | if (info.is_inline) cond_operand else .none, |
| 13208 | info.has_tag_capture, | 13199 | info.has_tag_capture, |
| ... | @@ -13218,8 +13209,8 @@ fn resolveSwitchComptime( | ... | @@ -13218,8 +13209,8 @@ fn resolveSwitchComptime( |
| 13218 | case_val_idx += 2; | 13209 | case_val_idx += 2; |
| 13219 | | 13210 | |
| 13220 | // Validation above ensured these will succeed. | 13211 | // Validation above ensured these will succeed. |
| 13221 | const first_val = sema.resolveConstDefinedValue(child_block, .unneeded, range_items[0], undefined) catch unreachable; | 13212 | const first_val = sema.resolveConstDefinedValue(child_block, LazySrcLoc.unneeded, range_items[0], undefined) catch unreachable; |
| 13222 | const last_val = sema.resolveConstDefinedValue(child_block, .unneeded, range_items[1], undefined) catch unreachable; | 13213 | const last_val = sema.resolveConstDefinedValue(child_block, LazySrcLoc.unneeded, range_items[1], undefined) catch unreachable; |
| 13223 | if ((try sema.compareAll(resolved_operand_val, .gte, first_val, operand_ty)) and | 13214 | if ((try sema.compareAll(resolved_operand_val, .gte, first_val, operand_ty)) and |
| 13224 | (try sema.compareAll(resolved_operand_val, .lte, last_val, operand_ty))) | 13215 | (try sema.compareAll(resolved_operand_val, .lte, last_val, operand_ty))) |
| 13225 | { | 13216 | { |
| ... | @@ -13229,7 +13220,10 @@ fn resolveSwitchComptime( | ... | @@ -13229,7 +13220,10 @@ fn resolveSwitchComptime( |
| 13229 | .normal, | 13220 | .normal, |
| 13230 | body, | 13221 | body, |
| 13231 | info.capture, | 13222 | info.capture, |
| 13232 | .{ .multi_capture = @intCast(multi_i) }, | 13223 | child_block.src(.{ .switch_capture = .{ |
| | 13224 | .switch_node_offset = switch_node_offset, |
| | 13225 | .case_idx = .{ .kind = .multi, .index = @intCast(multi_i) }, |
| | 13226 | } }), |
| 13233 | undefined, // case_vals may be undefined for ranges | 13227 | undefined, // case_vals may be undefined for ranges |
| 13234 | if (info.is_inline) cond_operand else .none, | 13228 | if (info.is_inline) cond_operand else .none, |
| 13235 | info.has_tag_capture, | 13229 | info.has_tag_capture, |
| ... | @@ -13251,7 +13245,10 @@ fn resolveSwitchComptime( | ... | @@ -13251,7 +13245,10 @@ fn resolveSwitchComptime( |
| 13251 | .special, | 13245 | .special, |
| 13252 | special.body, | 13246 | special.body, |
| 13253 | special.capture, | 13247 | special.capture, |
| 13254 | .special_capture, | 13248 | child_block.src(.{ .switch_capture = .{ |
| | 13249 | .switch_node_offset = switch_node_offset, |
| | 13250 | .case_idx = LazySrcLoc.Offset.SwitchCaseIndex.special, |
| | 13251 | } }), |
| 13255 | undefined, // case_vals may be undefined for special prongs | 13252 | undefined, // case_vals may be undefined for special prongs |
| 13256 | if (special.is_inline) cond_operand else .none, | 13253 | if (special.is_inline) cond_operand else .none, |
| 13257 | special.has_tag_capture, | 13254 | special.has_tag_capture, |
| ... | @@ -13337,36 +13334,19 @@ fn resolveSwitchItemVal( | ... | @@ -13337,36 +13334,19 @@ fn resolveSwitchItemVal( |
| 13337 | item_ref: Zir.Inst.Ref, | 13334 | item_ref: Zir.Inst.Ref, |
| 13338 | /// Coerce `item_ref` to this type. | 13335 | /// Coerce `item_ref` to this type. |
| 13339 | coerce_ty: Type, | 13336 | coerce_ty: Type, |
| 13340 | switch_node_offset: i32, | 13337 | item_src: LazySrcLoc, |
| 13341 | switch_prong_src: Module.SwitchProngSrc, | | |
| 13342 | range_expand: Module.SwitchProngSrc.RangeExpand, | | |
| 13343 | ) CompileError!ResolvedSwitchItem { | 13338 | ) CompileError!ResolvedSwitchItem { |
| 13344 | const mod = sema.mod; | | |
| 13345 | const uncoerced_item = try sema.resolveInst(item_ref); | 13339 | const uncoerced_item = try sema.resolveInst(item_ref); |
| 13346 | | 13340 | |
| 13347 | // Constructing a LazySrcLoc is costly because we only have the switch AST node. | 13341 | // Constructing a LazySrcLoc is costly because we only have the switch AST node. |
| 13348 | // Only if we know for sure we need to report a compile error do we resolve the | 13342 | // Only if we know for sure we need to report a compile error do we resolve the |
| 13349 | // full source locations. | 13343 | // full source locations. |
| 13350 | | 13344 | |
| 13351 | const item = sema.coerce(block, coerce_ty, uncoerced_item, .unneeded) catch |err| switch (err) { | 13345 | const item = try sema.coerce(block, coerce_ty, uncoerced_item, item_src); |
| 13352 | error.NeededSourceLocation => { | | |
| 13353 | const src = switch_prong_src.resolve(mod, mod.declPtr(block.src_decl), switch_node_offset, range_expand); | | |
| 13354 | _ = try sema.coerce(block, coerce_ty, uncoerced_item, src); | | |
| 13355 | unreachable; | | |
| 13356 | }, | | |
| 13357 | else => |e| return e, | | |
| 13358 | }; | | |
| 13359 | | 13346 | |
| 13360 | const maybe_lazy = sema.resolveConstDefinedValue(block, .unneeded, item, undefined) catch |err| switch (err) { | 13347 | const maybe_lazy = try sema.resolveConstDefinedValue(block, item_src, item, .{ |
| 13361 | error.NeededSourceLocation => { | 13348 | .needed_comptime_reason = "switch prong values must be comptime-known", |
| 13362 | const src = switch_prong_src.resolve(mod, mod.declPtr(block.src_decl), switch_node_offset, range_expand); | 13349 | }); |
| 13363 | _ = try sema.resolveConstDefinedValue(block, src, item, .{ | | |
| 13364 | .needed_comptime_reason = "switch prong values must be comptime-known", | | |
| 13365 | }); | | |
| 13366 | unreachable; | | |
| 13367 | }, | | |
| 13368 | else => |e| return e, | | |
| 13369 | }; | | |
| 13370 | | 13350 | |
| 13371 | const val = try sema.resolveLazyValue(maybe_lazy); | 13351 | const val = try sema.resolveLazyValue(maybe_lazy); |
| 13372 | const new_item = if (val.toIntern() != maybe_lazy.toIntern()) blk: { | 13352 | const new_item = if (val.toIntern() != maybe_lazy.toIntern()) blk: { |
| ... | @@ -13393,7 +13373,7 @@ fn validateErrSetSwitch( | ... | @@ -13393,7 +13373,7 @@ fn validateErrSetSwitch( |
| 13393 | const ip = &mod.intern_pool; | 13373 | const ip = &mod.intern_pool; |
| 13394 | | 13374 | |
| 13395 | const src_node_offset = inst_data.src_node; | 13375 | const src_node_offset = inst_data.src_node; |
| 13396 | const src = inst_data.src(); | 13376 | const src = block.nodeOffset(src_node_offset); |
| 13397 | | 13377 | |
| 13398 | var extra_index: usize = else_case.end; | 13378 | var extra_index: usize = else_case.end; |
| 13399 | { | 13379 | { |
| ... | @@ -13409,8 +13389,11 @@ fn validateErrSetSwitch( | ... | @@ -13409,8 +13389,11 @@ fn validateErrSetSwitch( |
| 13409 | seen_errors, | 13389 | seen_errors, |
| 13410 | item_ref, | 13390 | item_ref, |
| 13411 | operand_ty, | 13391 | operand_ty, |
| 13412 | src_node_offset, | 13392 | block.src(.{ .switch_case_item = .{ |
| 13413 | .{ .scalar = scalar_i }, | 13393 | .switch_node_offset = src_node_offset, |
| | 13394 | .case_idx = .{ .kind = .scalar, .index = @intCast(scalar_i) }, |
| | 13395 | .item_idx = .{ .kind = .single, .index = 0 }, |
| | 13396 | } }), |
| 13414 | )); | 13397 | )); |
| 13415 | } | 13398 | } |
| 13416 | } | 13399 | } |
| ... | @@ -13433,8 +13416,11 @@ fn validateErrSetSwitch( | ... | @@ -13433,8 +13416,11 @@ fn validateErrSetSwitch( |
| 13433 | seen_errors, | 13416 | seen_errors, |
| 13434 | item_ref, | 13417 | item_ref, |
| 13435 | operand_ty, | 13418 | operand_ty, |
| 13436 | src_node_offset, | 13419 | block.src(.{ .switch_case_item = .{ |
| 13437 | .{ .multi = .{ .prong = multi_i, .item = @intCast(item_i) } }, | 13420 | .switch_node_offset = src_node_offset, |
| | 13421 | .case_idx = .{ .kind = .multi, .index = @intCast(multi_i) }, |
| | 13422 | .item_idx = .{ .kind = .single, .index = @intCast(item_i) }, |
| | 13423 | } }), |
| 13438 | )); | 13424 | )); |
| 13439 | } | 13425 | } |
| 13440 | | 13426 | |
| ... | @@ -13463,7 +13449,6 @@ fn validateErrSetSwitch( | ... | @@ -13463,7 +13449,6 @@ fn validateErrSetSwitch( |
| 13463 | if (!seen_errors.contains(error_name) and !has_else) { | 13449 | if (!seen_errors.contains(error_name) and !has_else) { |
| 13464 | const msg = maybe_msg orelse blk: { | 13450 | const msg = maybe_msg orelse blk: { |
| 13465 | maybe_msg = try sema.errMsg( | 13451 | maybe_msg = try sema.errMsg( |
| 13466 | block, | | |
| 13467 | src, | 13452 | src, |
| 13468 | "switch must handle all possibilities", | 13453 | "switch must handle all possibilities", |
| 13469 | .{}, | 13454 | .{}, |
| ... | @@ -13472,7 +13457,6 @@ fn validateErrSetSwitch( | ... | @@ -13472,7 +13457,6 @@ fn validateErrSetSwitch( |
| 13472 | }; | 13457 | }; |
| 13473 | | 13458 | |
| 13474 | try sema.errNote( | 13459 | try sema.errNote( |
| 13475 | block, | | |
| 13476 | src, | 13460 | src, |
| 13477 | msg, | 13461 | msg, |
| 13478 | "unhandled error value: 'error.{}'", | 13462 | "unhandled error value: 'error.{}'", |
| ... | @@ -13550,18 +13534,24 @@ fn validateSwitchRange( | ... | @@ -13550,18 +13534,24 @@ fn validateSwitchRange( |
| 13550 | first_ref: Zir.Inst.Ref, | 13534 | first_ref: Zir.Inst.Ref, |
| 13551 | last_ref: Zir.Inst.Ref, | 13535 | last_ref: Zir.Inst.Ref, |
| 13552 | operand_ty: Type, | 13536 | operand_ty: Type, |
| 13553 | src_node_offset: i32, | 13537 | item_src: LazySrcLoc, |
| 13554 | switch_prong_src: Module.SwitchProngSrc, | | |
| 13555 | ) CompileError![2]Air.Inst.Ref { | 13538 | ) CompileError![2]Air.Inst.Ref { |
| 13556 | const mod = sema.mod; | 13539 | const mod = sema.mod; |
| 13557 | const first = try sema.resolveSwitchItemVal(block, first_ref, operand_ty, src_node_offset, switch_prong_src, .first); | 13540 | const first_src: LazySrcLoc = .{ |
| 13558 | const last = try sema.resolveSwitchItemVal(block, last_ref, operand_ty, src_node_offset, switch_prong_src, .last); | 13541 | .base_node_inst = item_src.base_node_inst, |
| | 13542 | .offset = .{ .switch_case_item_range_first = item_src.offset.switch_case_item }, |
| | 13543 | }; |
| | 13544 | const last_src: LazySrcLoc = .{ |
| | 13545 | .base_node_inst = item_src.base_node_inst, |
| | 13546 | .offset = .{ .switch_case_item_range_last = item_src.offset.switch_case_item }, |
| | 13547 | }; |
| | 13548 | const first = try sema.resolveSwitchItemVal(block, first_ref, operand_ty, first_src); |
| | 13549 | const last = try sema.resolveSwitchItemVal(block, last_ref, operand_ty, last_src); |
| 13559 | if (try Value.fromInterned(first.val).compareAll(.gt, Value.fromInterned(last.val), operand_ty, mod)) { | 13550 | if (try Value.fromInterned(first.val).compareAll(.gt, Value.fromInterned(last.val), operand_ty, mod)) { |
| 13560 | const src = switch_prong_src.resolve(mod, mod.declPtr(block.src_decl), src_node_offset, .first); | 13551 | return sema.fail(block, item_src, "range start value is greater than the end value", .{}); |
| 13561 | return sema.fail(block, src, "range start value is greater than the end value", .{}); | | |
| 13562 | } | 13552 | } |
| 13563 | const maybe_prev_src = try range_set.add(first.val, last.val, switch_prong_src); | 13553 | const maybe_prev_src = try range_set.add(first.val, last.val, item_src); |
| 13564 | try sema.validateSwitchDupe(block, maybe_prev_src, switch_prong_src, src_node_offset); | 13554 | try sema.validateSwitchDupe(block, maybe_prev_src, item_src); |
| 13565 | return .{ first.ref, last.ref }; | 13555 | return .{ first.ref, last.ref }; |
| 13566 | } | 13556 | } |
| 13567 | | 13557 | |
| ... | @@ -13571,36 +13561,34 @@ fn validateSwitchItemInt( | ... | @@ -13571,36 +13561,34 @@ fn validateSwitchItemInt( |
| 13571 | range_set: *RangeSet, | 13561 | range_set: *RangeSet, |
| 13572 | item_ref: Zir.Inst.Ref, | 13562 | item_ref: Zir.Inst.Ref, |
| 13573 | operand_ty: Type, | 13563 | operand_ty: Type, |
| 13574 | src_node_offset: i32, | 13564 | item_src: LazySrcLoc, |
| 13575 | switch_prong_src: Module.SwitchProngSrc, | | |
| 13576 | ) CompileError!Air.Inst.Ref { | 13565 | ) CompileError!Air.Inst.Ref { |
| 13577 | const item = try sema.resolveSwitchItemVal(block, item_ref, operand_ty, src_node_offset, switch_prong_src, .none); | 13566 | const item = try sema.resolveSwitchItemVal(block, item_ref, operand_ty, item_src); |
| 13578 | const maybe_prev_src = try range_set.add(item.val, item.val, switch_prong_src); | 13567 | const maybe_prev_src = try range_set.add(item.val, item.val, item_src); |
| 13579 | try sema.validateSwitchDupe(block, maybe_prev_src, switch_prong_src, src_node_offset); | 13568 | try sema.validateSwitchDupe(block, maybe_prev_src, item_src); |
| 13580 | return item.ref; | 13569 | return item.ref; |
| 13581 | } | 13570 | } |
| 13582 | | 13571 | |
| 13583 | fn validateSwitchItemEnum( | 13572 | fn validateSwitchItemEnum( |
| 13584 | sema: *Sema, | 13573 | sema: *Sema, |
| 13585 | block: *Block, | 13574 | block: *Block, |
| 13586 | seen_fields: []?Module.SwitchProngSrc, | 13575 | seen_fields: []?LazySrcLoc, |
| 13587 | range_set: *RangeSet, | 13576 | range_set: *RangeSet, |
| 13588 | item_ref: Zir.Inst.Ref, | 13577 | item_ref: Zir.Inst.Ref, |
| 13589 | operand_ty: Type, | 13578 | operand_ty: Type, |
| 13590 | src_node_offset: i32, | 13579 | item_src: LazySrcLoc, |
| 13591 | switch_prong_src: Module.SwitchProngSrc, | | |
| 13592 | ) CompileError!Air.Inst.Ref { | 13580 | ) CompileError!Air.Inst.Ref { |
| 13593 | const ip = &sema.mod.intern_pool; | 13581 | const ip = &sema.mod.intern_pool; |
| 13594 | const item = try sema.resolveSwitchItemVal(block, item_ref, operand_ty, src_node_offset, switch_prong_src, .none); | 13582 | const item = try sema.resolveSwitchItemVal(block, item_ref, operand_ty, item_src); |
| 13595 | const int = ip.indexToKey(item.val).enum_tag.int; | 13583 | const int = ip.indexToKey(item.val).enum_tag.int; |
| 13596 | const field_index = ip.loadEnumType(ip.typeOf(item.val)).tagValueIndex(ip, int) orelse { | 13584 | const field_index = ip.loadEnumType(ip.typeOf(item.val)).tagValueIndex(ip, int) orelse { |
| 13597 | const maybe_prev_src = try range_set.add(int, int, switch_prong_src); | 13585 | const maybe_prev_src = try range_set.add(int, int, item_src); |
| 13598 | try sema.validateSwitchDupe(block, maybe_prev_src, switch_prong_src, src_node_offset); | 13586 | try sema.validateSwitchDupe(block, maybe_prev_src, item_src); |
| 13599 | return item.ref; | 13587 | return item.ref; |
| 13600 | }; | 13588 | }; |
| 13601 | const maybe_prev_src = seen_fields[field_index]; | 13589 | const maybe_prev_src = seen_fields[field_index]; |
| 13602 | seen_fields[field_index] = switch_prong_src; | 13590 | seen_fields[field_index] = item_src; |
| 13603 | try sema.validateSwitchDupe(block, maybe_prev_src, switch_prong_src, src_node_offset); | 13591 | try sema.validateSwitchDupe(block, maybe_prev_src, item_src); |
| 13604 | return item.ref; | 13592 | return item.ref; |
| 13605 | } | 13593 | } |
| 13606 | | 13594 | |
| ... | @@ -13610,50 +13598,41 @@ fn validateSwitchItemError( | ... | @@ -13610,50 +13598,41 @@ fn validateSwitchItemError( |
| 13610 | seen_errors: *SwitchErrorSet, | 13598 | seen_errors: *SwitchErrorSet, |
| 13611 | item_ref: Zir.Inst.Ref, | 13599 | item_ref: Zir.Inst.Ref, |
| 13612 | operand_ty: Type, | 13600 | operand_ty: Type, |
| 13613 | src_node_offset: i32, | 13601 | item_src: LazySrcLoc, |
| 13614 | switch_prong_src: Module.SwitchProngSrc, | | |
| 13615 | ) CompileError!Air.Inst.Ref { | 13602 | ) CompileError!Air.Inst.Ref { |
| 13616 | const ip = &sema.mod.intern_pool; | 13603 | const ip = &sema.mod.intern_pool; |
| 13617 | const item = try sema.resolveSwitchItemVal(block, item_ref, operand_ty, src_node_offset, switch_prong_src, .none); | 13604 | const item = try sema.resolveSwitchItemVal(block, item_ref, operand_ty, item_src); |
| 13618 | const error_name = ip.indexToKey(item.val).err.name; | 13605 | const error_name = ip.indexToKey(item.val).err.name; |
| 13619 | const maybe_prev_src = if (try seen_errors.fetchPut(error_name, switch_prong_src)) |prev| | 13606 | const maybe_prev_src = if (try seen_errors.fetchPut(error_name, item_src)) |prev| |
| 13620 | prev.value | 13607 | prev.value |
| 13621 | else | 13608 | else |
| 13622 | null; | 13609 | null; |
| 13623 | try sema.validateSwitchDupe(block, maybe_prev_src, switch_prong_src, src_node_offset); | 13610 | try sema.validateSwitchDupe(block, maybe_prev_src, item_src); |
| 13624 | return item.ref; | 13611 | return item.ref; |
| 13625 | } | 13612 | } |
| 13626 | | 13613 | |
| 13627 | fn validateSwitchDupe( | 13614 | fn validateSwitchDupe( |
| 13628 | sema: *Sema, | 13615 | sema: *Sema, |
| 13629 | block: *Block, | 13616 | block: *Block, |
| 13630 | maybe_prev_src: ?Module.SwitchProngSrc, | 13617 | maybe_prev_src: ?LazySrcLoc, |
| 13631 | switch_prong_src: Module.SwitchProngSrc, | 13618 | item_src: LazySrcLoc, |
| 13632 | src_node_offset: i32, | | |
| 13633 | ) CompileError!void { | 13619 | ) CompileError!void { |
| 13634 | const prev_prong_src = maybe_prev_src orelse return; | 13620 | const prev_item_src = maybe_prev_src orelse return; |
| 13635 | const mod = sema.mod; | 13621 | return sema.failWithOwnedErrorMsg(block, msg: { |
| 13636 | const block_src_decl = mod.declPtr(block.src_decl); | | |
| 13637 | const src = switch_prong_src.resolve(mod, block_src_decl, src_node_offset, .none); | | |
| 13638 | const prev_src = prev_prong_src.resolve(mod, block_src_decl, src_node_offset, .none); | | |
| 13639 | const msg = msg: { | | |
| 13640 | const msg = try sema.errMsg( | 13622 | const msg = try sema.errMsg( |
| 13641 | block, | 13623 | item_src, |
| 13642 | src, | | |
| 13643 | "duplicate switch value", | 13624 | "duplicate switch value", |
| 13644 | .{}, | 13625 | .{}, |
| 13645 | ); | 13626 | ); |
| 13646 | errdefer msg.destroy(sema.gpa); | 13627 | errdefer msg.destroy(sema.gpa); |
| 13647 | try sema.errNote( | 13628 | try sema.errNote( |
| 13648 | block, | 13629 | prev_item_src, |
| 13649 | prev_src, | | |
| 13650 | msg, | 13630 | msg, |
| 13651 | "previous value here", | 13631 | "previous value here", |
| 13652 | .{}, | 13632 | .{}, |
| 13653 | ); | 13633 | ); |
| 13654 | break :msg msg; | 13634 | break :msg msg; |
| 13655 | }; | 13635 | }); |
| 13656 | return sema.failWithOwnedErrorMsg(block, msg); | | |
| 13657 | } | 13636 | } |
| 13658 | | 13637 | |
| 13659 | fn validateSwitchItemBool( | 13638 | fn validateSwitchItemBool( |
| ... | @@ -13662,25 +13641,21 @@ fn validateSwitchItemBool( | ... | @@ -13662,25 +13641,21 @@ fn validateSwitchItemBool( |
| 13662 | true_count: *u8, | 13641 | true_count: *u8, |
| 13663 | false_count: *u8, | 13642 | false_count: *u8, |
| 13664 | item_ref: Zir.Inst.Ref, | 13643 | item_ref: Zir.Inst.Ref, |
| 13665 | src_node_offset: i32, | 13644 | item_src: LazySrcLoc, |
| 13666 | switch_prong_src: Module.SwitchProngSrc, | | |
| 13667 | ) CompileError!Air.Inst.Ref { | 13645 | ) CompileError!Air.Inst.Ref { |
| 13668 | const mod = sema.mod; | 13646 | const item = try sema.resolveSwitchItemVal(block, item_ref, Type.bool, item_src); |
| 13669 | const item = try sema.resolveSwitchItemVal(block, item_ref, Type.bool, src_node_offset, switch_prong_src, .none); | | |
| 13670 | if (Value.fromInterned(item.val).toBool()) { | 13647 | if (Value.fromInterned(item.val).toBool()) { |
| 13671 | true_count.* += 1; | 13648 | true_count.* += 1; |
| 13672 | } else { | 13649 | } else { |
| 13673 | false_count.* += 1; | 13650 | false_count.* += 1; |
| 13674 | } | 13651 | } |
| 13675 | if (true_count.* > 1 or false_count.* > 1) { | 13652 | if (true_count.* > 1 or false_count.* > 1) { |
| 13676 | const block_src_decl = sema.mod.declPtr(block.src_decl); | 13653 | return sema.fail(block, item_src, "duplicate switch value", .{}); |
| 13677 | const src = switch_prong_src.resolve(mod, block_src_decl, src_node_offset, .none); | | |
| 13678 | return sema.fail(block, src, "duplicate switch value", .{}); | | |
| 13679 | } | 13654 | } |
| 13680 | return item.ref; | 13655 | return item.ref; |
| 13681 | } | 13656 | } |
| 13682 | | 13657 | |
| 13683 | const ValueSrcMap = std.AutoHashMapUnmanaged(InternPool.Index, Module.SwitchProngSrc); | 13658 | const ValueSrcMap = std.AutoHashMapUnmanaged(InternPool.Index, LazySrcLoc); |
| 13684 | | 13659 | |
| 13685 | fn validateSwitchItemSparse( | 13660 | fn validateSwitchItemSparse( |
| 13686 | sema: *Sema, | 13661 | sema: *Sema, |
| ... | @@ -13688,12 +13663,11 @@ fn validateSwitchItemSparse( | ... | @@ -13688,12 +13663,11 @@ fn validateSwitchItemSparse( |
| 13688 | seen_values: *ValueSrcMap, | 13663 | seen_values: *ValueSrcMap, |
| 13689 | item_ref: Zir.Inst.Ref, | 13664 | item_ref: Zir.Inst.Ref, |
| 13690 | operand_ty: Type, | 13665 | operand_ty: Type, |
| 13691 | src_node_offset: i32, | 13666 | item_src: LazySrcLoc, |
| 13692 | switch_prong_src: Module.SwitchProngSrc, | | |
| 13693 | ) CompileError!Air.Inst.Ref { | 13667 | ) CompileError!Air.Inst.Ref { |
| 13694 | const item = try sema.resolveSwitchItemVal(block, item_ref, operand_ty, src_node_offset, switch_prong_src, .none); | 13668 | const item = try sema.resolveSwitchItemVal(block, item_ref, operand_ty, item_src); |
| 13695 | const kv = (try seen_values.fetchPut(sema.gpa, item.val, switch_prong_src)) orelse return item.ref; | 13669 | const kv = try seen_values.fetchPut(sema.gpa, item.val, item_src) orelse return item.ref; |
| 13696 | try sema.validateSwitchDupe(block, kv.value, switch_prong_src, src_node_offset); | 13670 | try sema.validateSwitchDupe(block, kv.value, item_src); |
| 13697 | unreachable; | 13671 | unreachable; |
| 13698 | } | 13672 | } |
| 13699 | | 13673 | |
| ... | @@ -13707,19 +13681,17 @@ fn validateSwitchNoRange( | ... | @@ -13707,19 +13681,17 @@ fn validateSwitchNoRange( |
| 13707 | if (ranges_len == 0) | 13681 | if (ranges_len == 0) |
| 13708 | return; | 13682 | return; |
| 13709 | | 13683 | |
| 13710 | const operand_src: LazySrcLoc = .{ .node_offset_switch_operand = src_node_offset }; | 13684 | const operand_src = block.src(.{ .node_offset_switch_operand = src_node_offset }); |
| 13711 | const range_src: LazySrcLoc = .{ .node_offset_switch_range = src_node_offset }; | 13685 | const range_src = block.src(.{ .node_offset_switch_range = src_node_offset }); |
| 13712 | | 13686 | |
| 13713 | const msg = msg: { | 13687 | const msg = msg: { |
| 13714 | const msg = try sema.errMsg( | 13688 | const msg = try sema.errMsg( |
| 13715 | block, | | |
| 13716 | operand_src, | 13689 | operand_src, |
| 13717 | "ranges not allowed when switching on type '{}'", | 13690 | "ranges not allowed when switching on type '{}'", |
| 13718 | .{operand_ty.fmt(sema.mod)}, | 13691 | .{operand_ty.fmt(sema.mod)}, |
| 13719 | ); | 13692 | ); |
| 13720 | errdefer msg.destroy(sema.gpa); | 13693 | errdefer msg.destroy(sema.gpa); |
| 13721 | try sema.errNote( | 13694 | try sema.errNote( |
| 13722 | block, | | |
| 13723 | range_src, | 13695 | range_src, |
| 13724 | msg, | 13696 | msg, |
| 13725 | "range here", | 13697 | "range here", |
| ... | @@ -13833,7 +13805,7 @@ fn maybeErrorUnwrapComptime(sema: *Sema, block: *Block, body: []const Zir.Inst.I | ... | @@ -13833,7 +13805,7 @@ fn maybeErrorUnwrapComptime(sema: *Sema, block: *Block, body: []const Zir.Inst.I |
| 13833 | } | 13805 | } |
| 13834 | } else return; | 13806 | } else return; |
| 13835 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].@"unreachable"; | 13807 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].@"unreachable"; |
| 13836 | const src = inst_data.src(); | 13808 | const src = block.nodeOffset(inst_data.src_node); |
| 13837 | | 13809 | |
| 13838 | if (try sema.resolveDefinedValue(block, src, operand)) |val| { | 13810 | if (try sema.resolveDefinedValue(block, src, operand)) |val| { |
| 13839 | if (val.getErrorName(sema.mod).unwrap()) |name| { | 13811 | if (val.getErrorName(sema.mod).unwrap()) |name| { |
| ... | @@ -13846,8 +13818,8 @@ fn zirHasField(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -13846,8 +13818,8 @@ fn zirHasField(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 13846 | const mod = sema.mod; | 13818 | const mod = sema.mod; |
| 13847 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 13819 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 13848 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; | 13820 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 13849 | const ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 13821 | const ty_src = block.builtinCallArgSrc(inst_data.src_node, 0); |
| 13850 | const name_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; | 13822 | const name_src = block.builtinCallArgSrc(inst_data.src_node, 1); |
| 13851 | const ty = try sema.resolveType(block, ty_src, extra.lhs); | 13823 | const ty = try sema.resolveType(block, ty_src, extra.lhs); |
| 13852 | const field_name = try sema.resolveConstStringIntern(block, name_src, extra.rhs, .{ | 13824 | const field_name = try sema.resolveConstStringIntern(block, name_src, extra.rhs, .{ |
| 13853 | .needed_comptime_reason = "field name must be comptime-known", | 13825 | .needed_comptime_reason = "field name must be comptime-known", |
| ... | @@ -13897,9 +13869,9 @@ fn zirHasDecl(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air | ... | @@ -13897,9 +13869,9 @@ fn zirHasDecl(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 13897 | const mod = sema.mod; | 13869 | const mod = sema.mod; |
| 13898 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 13870 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 13899 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; | 13871 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 13900 | const src = inst_data.src(); | 13872 | const src = block.nodeOffset(inst_data.src_node); |
| 13901 | const lhs_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 13873 | const lhs_src = block.builtinCallArgSrc(inst_data.src_node, 0); |
| 13902 | const rhs_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; | 13874 | const rhs_src = block.builtinCallArgSrc(inst_data.src_node, 1); |
| 13903 | const container_type = try sema.resolveType(block, lhs_src, extra.lhs); | 13875 | const container_type = try sema.resolveType(block, lhs_src, extra.lhs); |
| 13904 | const decl_name = try sema.resolveConstStringIntern(block, rhs_src, extra.rhs, .{ | 13876 | const decl_name = try sema.resolveConstStringIntern(block, rhs_src, extra.rhs, .{ |
| 13905 | .needed_comptime_reason = "decl name must be comptime-known", | 13877 | .needed_comptime_reason = "decl name must be comptime-known", |
| ... | @@ -13929,7 +13901,7 @@ fn zirImport(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. | ... | @@ -13929,7 +13901,7 @@ fn zirImport(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. |
| 13929 | | 13901 | |
| 13930 | const mod = sema.mod; | 13902 | const mod = sema.mod; |
| 13931 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].str_tok; | 13903 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].str_tok; |
| 13932 | const operand_src = inst_data.src(); | 13904 | const operand_src = block.tokenOffset(inst_data.src_tok); |
| 13933 | const operand = inst_data.get(sema.code); | 13905 | const operand = inst_data.get(sema.code); |
| 13934 | | 13906 | |
| 13935 | const result = mod.importFile(block.getFileScope(mod), operand) catch |err| switch (err) { | 13907 | const result = mod.importFile(block.getFileScope(mod), operand) catch |err| switch (err) { |
| ... | @@ -13958,7 +13930,7 @@ fn zirEmbedFile(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A | ... | @@ -13958,7 +13930,7 @@ fn zirEmbedFile(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 13958 | | 13930 | |
| 13959 | const mod = sema.mod; | 13931 | const mod = sema.mod; |
| 13960 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; | 13932 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 13961 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 13933 | const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0); |
| 13962 | const name = try sema.resolveConstString(block, operand_src, inst_data.operand, .{ | 13934 | const name = try sema.resolveConstString(block, operand_src, inst_data.operand, .{ |
| 13963 | .needed_comptime_reason = "file path name must be comptime-known", | 13935 | .needed_comptime_reason = "file path name must be comptime-known", |
| 13964 | }); | 13936 | }); |
| ... | @@ -13967,8 +13939,7 @@ fn zirEmbedFile(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A | ... | @@ -13967,8 +13939,7 @@ fn zirEmbedFile(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 13967 | return sema.fail(block, operand_src, "file path name cannot be empty", .{}); | 13939 | return sema.fail(block, operand_src, "file path name cannot be empty", .{}); |
| 13968 | } | 13940 | } |
| 13969 | | 13941 | |
| 13970 | const src_loc = mod.declPtr(block.src_decl).toSrcLoc(operand_src, mod); | 13942 | const val = mod.embedFile(block.getFileScope(mod), name, operand_src.upgrade(mod)) catch |err| switch (err) { |
| 13971 | const val = mod.embedFile(block.getFileScope(mod), name, src_loc) catch |err| switch (err) { | | |
| 13972 | error.ImportOutsideModulePath => { | 13943 | error.ImportOutsideModulePath => { |
| 13973 | return sema.fail(block, operand_src, "embed of file outside package path: '{s}'", .{name}); | 13944 | return sema.fail(block, operand_src, "embed of file outside package path: '{s}'", .{name}); |
| 13974 | }, | 13945 | }, |
| ... | @@ -14009,9 +13980,9 @@ fn zirShl( | ... | @@ -14009,9 +13980,9 @@ fn zirShl( |
| 14009 | | 13980 | |
| 14010 | const mod = sema.mod; | 13981 | const mod = sema.mod; |
| 14011 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 13982 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 14012 | const src = inst_data.src(); | 13983 | const src = block.nodeOffset(inst_data.src_node); |
| 14013 | const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node }; | 13984 | const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node }); |
| 14014 | const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node }; | 13985 | const rhs_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node }); |
| 14015 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; | 13986 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 14016 | const lhs = try sema.resolveInst(extra.lhs); | 13987 | const lhs = try sema.resolveInst(extra.lhs); |
| 14017 | const rhs = try sema.resolveInst(extra.rhs); | 13988 | const rhs = try sema.resolveInst(extra.rhs); |
| ... | @@ -14179,9 +14150,9 @@ fn zirShr( | ... | @@ -14179,9 +14150,9 @@ fn zirShr( |
| 14179 | | 14150 | |
| 14180 | const mod = sema.mod; | 14151 | const mod = sema.mod; |
| 14181 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 14152 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 14182 | const src = inst_data.src(); | 14153 | const src = block.nodeOffset(inst_data.src_node); |
| 14183 | const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node }; | 14154 | const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node }); |
| 14184 | const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node }; | 14155 | const rhs_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node }); |
| 14185 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; | 14156 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 14186 | const lhs = try sema.resolveInst(extra.lhs); | 14157 | const lhs = try sema.resolveInst(extra.lhs); |
| 14187 | const rhs = try sema.resolveInst(extra.rhs); | 14158 | const rhs = try sema.resolveInst(extra.rhs); |
| ... | @@ -14314,9 +14285,9 @@ fn zirBitwise( | ... | @@ -14314,9 +14285,9 @@ fn zirBitwise( |
| 14314 | | 14285 | |
| 14315 | const mod = sema.mod; | 14286 | const mod = sema.mod; |
| 14316 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 14287 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 14317 | const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node }; | 14288 | const src = block.src(.{ .node_offset_bin_op = inst_data.src_node }); |
| 14318 | const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node }; | 14289 | const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node }); |
| 14319 | const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node }; | 14290 | const rhs_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node }); |
| 14320 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; | 14291 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 14321 | const lhs = try sema.resolveInst(extra.lhs); | 14292 | const lhs = try sema.resolveInst(extra.lhs); |
| 14322 | const rhs = try sema.resolveInst(extra.rhs); | 14293 | const rhs = try sema.resolveInst(extra.rhs); |
| ... | @@ -14368,8 +14339,8 @@ fn zirBitNot(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. | ... | @@ -14368,8 +14339,8 @@ fn zirBitNot(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. |
| 14368 | | 14339 | |
| 14369 | const mod = sema.mod; | 14340 | const mod = sema.mod; |
| 14370 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; | 14341 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 14371 | const src = inst_data.src(); | 14342 | const src = block.nodeOffset(inst_data.src_node); |
| 14372 | const operand_src: LazySrcLoc = .{ .node_offset_un_op = inst_data.src_node }; | 14343 | const operand_src = block.src(.{ .node_offset_un_op = inst_data.src_node }); |
| 14373 | | 14344 | |
| 14374 | const operand = try sema.resolveInst(inst_data.operand); | 14345 | const operand = try sema.resolveInst(inst_data.operand); |
| 14375 | const operand_type = sema.typeOf(operand); | 14346 | const operand_type = sema.typeOf(operand); |
| ... | @@ -14415,7 +14386,7 @@ fn analyzeTupleCat( | ... | @@ -14415,7 +14386,7 @@ fn analyzeTupleCat( |
| 14415 | const mod = sema.mod; | 14386 | const mod = sema.mod; |
| 14416 | const lhs_ty = sema.typeOf(lhs); | 14387 | const lhs_ty = sema.typeOf(lhs); |
| 14417 | const rhs_ty = sema.typeOf(rhs); | 14388 | const rhs_ty = sema.typeOf(rhs); |
| 14418 | const src = LazySrcLoc.nodeOffset(src_node); | 14389 | const src = block.nodeOffset(src_node); |
| 14419 | | 14390 | |
| 14420 | const lhs_len = lhs_ty.structFieldCount(mod); | 14391 | const lhs_len = lhs_ty.structFieldCount(mod); |
| 14421 | const rhs_len = rhs_ty.structFieldCount(mod); | 14392 | const rhs_len = rhs_ty.structFieldCount(mod); |
| ... | @@ -14442,10 +14413,10 @@ fn analyzeTupleCat( | ... | @@ -14442,10 +14413,10 @@ fn analyzeTupleCat( |
| 14442 | types[i] = lhs_ty.structFieldType(i, mod).toIntern(); | 14413 | types[i] = lhs_ty.structFieldType(i, mod).toIntern(); |
| 14443 | const default_val = lhs_ty.structFieldDefaultValue(i, mod); | 14414 | const default_val = lhs_ty.structFieldDefaultValue(i, mod); |
| 14444 | values[i] = default_val.toIntern(); | 14415 | values[i] = default_val.toIntern(); |
| 14445 | const operand_src: LazySrcLoc = .{ .array_cat_lhs = .{ | 14416 | const operand_src = block.src(.{ .array_cat_lhs = .{ |
| 14446 | .array_cat_offset = src_node, | 14417 | .array_cat_offset = src_node, |
| 14447 | .elem_index = i, | 14418 | .elem_index = i, |
| 14448 | } }; | 14419 | } }); |
| 14449 | if (default_val.toIntern() == .unreachable_value) { | 14420 | if (default_val.toIntern() == .unreachable_value) { |
| 14450 | runtime_src = operand_src; | 14421 | runtime_src = operand_src; |
| 14451 | values[i] = .none; | 14422 | values[i] = .none; |
| ... | @@ -14456,10 +14427,10 @@ fn analyzeTupleCat( | ... | @@ -14456,10 +14427,10 @@ fn analyzeTupleCat( |
| 14456 | types[i + lhs_len] = rhs_ty.structFieldType(i, mod).toIntern(); | 14427 | types[i + lhs_len] = rhs_ty.structFieldType(i, mod).toIntern(); |
| 14457 | const default_val = rhs_ty.structFieldDefaultValue(i, mod); | 14428 | const default_val = rhs_ty.structFieldDefaultValue(i, mod); |
| 14458 | values[i + lhs_len] = default_val.toIntern(); | 14429 | values[i + lhs_len] = default_val.toIntern(); |
| 14459 | const operand_src: LazySrcLoc = .{ .array_cat_rhs = .{ | 14430 | const operand_src = block.src(.{ .array_cat_rhs = .{ |
| 14460 | .array_cat_offset = src_node, | 14431 | .array_cat_offset = src_node, |
| 14461 | .elem_index = i, | 14432 | .elem_index = i, |
| 14462 | } }; | 14433 | } }); |
| 14463 | if (default_val.toIntern() == .unreachable_value) { | 14434 | if (default_val.toIntern() == .unreachable_value) { |
| 14464 | runtime_src = operand_src; | 14435 | runtime_src = operand_src; |
| 14465 | values[i + lhs_len] = .none; | 14436 | values[i + lhs_len] = .none; |
| ... | @@ -14487,18 +14458,18 @@ fn analyzeTupleCat( | ... | @@ -14487,18 +14458,18 @@ fn analyzeTupleCat( |
| 14487 | const element_refs = try sema.arena.alloc(Air.Inst.Ref, final_len); | 14458 | const element_refs = try sema.arena.alloc(Air.Inst.Ref, final_len); |
| 14488 | var i: u32 = 0; | 14459 | var i: u32 = 0; |
| 14489 | while (i < lhs_len) : (i += 1) { | 14460 | while (i < lhs_len) : (i += 1) { |
| 14490 | const operand_src: LazySrcLoc = .{ .array_cat_lhs = .{ | 14461 | const operand_src = block.src(.{ .array_cat_lhs = .{ |
| 14491 | .array_cat_offset = src_node, | 14462 | .array_cat_offset = src_node, |
| 14492 | .elem_index = i, | 14463 | .elem_index = i, |
| 14493 | } }; | 14464 | } }); |
| 14494 | element_refs[i] = try sema.tupleFieldValByIndex(block, operand_src, lhs, i, lhs_ty); | 14465 | element_refs[i] = try sema.tupleFieldValByIndex(block, operand_src, lhs, i, lhs_ty); |
| 14495 | } | 14466 | } |
| 14496 | i = 0; | 14467 | i = 0; |
| 14497 | while (i < rhs_len) : (i += 1) { | 14468 | while (i < rhs_len) : (i += 1) { |
| 14498 | const operand_src: LazySrcLoc = .{ .array_cat_rhs = .{ | 14469 | const operand_src = block.src(.{ .array_cat_rhs = .{ |
| 14499 | .array_cat_offset = src_node, | 14470 | .array_cat_offset = src_node, |
| 14500 | .elem_index = i, | 14471 | .elem_index = i, |
| 14501 | } }; | 14472 | } }); |
| 14502 | element_refs[i + lhs_len] = | 14473 | element_refs[i + lhs_len] = |
| 14503 | try sema.tupleFieldValByIndex(block, operand_src, rhs, i, rhs_ty); | 14474 | try sema.tupleFieldValByIndex(block, operand_src, rhs, i, rhs_ty); |
| 14504 | } | 14475 | } |
| ... | @@ -14517,7 +14488,7 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -14517,7 +14488,7 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 14517 | const rhs = try sema.resolveInst(extra.rhs); | 14488 | const rhs = try sema.resolveInst(extra.rhs); |
| 14518 | const lhs_ty = sema.typeOf(lhs); | 14489 | const lhs_ty = sema.typeOf(lhs); |
| 14519 | const rhs_ty = sema.typeOf(rhs); | 14490 | const rhs_ty = sema.typeOf(rhs); |
| 14520 | const src = inst_data.src(); | 14491 | const src = block.nodeOffset(inst_data.src_node); |
| 14521 | | 14492 | |
| 14522 | const lhs_is_tuple = lhs_ty.isTuple(mod); | 14493 | const lhs_is_tuple = lhs_ty.isTuple(mod); |
| 14523 | const rhs_is_tuple = rhs_ty.isTuple(mod); | 14494 | const rhs_is_tuple = rhs_ty.isTuple(mod); |
| ... | @@ -14525,8 +14496,8 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -14525,8 +14496,8 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 14525 | return sema.analyzeTupleCat(block, inst_data.src_node, lhs, rhs); | 14496 | return sema.analyzeTupleCat(block, inst_data.src_node, lhs, rhs); |
| 14526 | } | 14497 | } |
| 14527 | | 14498 | |
| 14528 | const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node }; | 14499 | const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node }); |
| 14529 | const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node }; | 14500 | const rhs_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node }); |
| 14530 | | 14501 | |
| 14531 | const lhs_info = try sema.getArrayCatInfo(block, lhs_src, lhs, rhs_ty) orelse lhs_info: { | 14502 | const lhs_info = try sema.getArrayCatInfo(block, lhs_src, lhs, rhs_ty) orelse lhs_info: { |
| 14532 | if (lhs_is_tuple) break :lhs_info @as(Type.ArrayInfo, undefined); | 14503 | if (lhs_is_tuple) break :lhs_info @as(Type.ArrayInfo, undefined); |
| ... | @@ -14638,10 +14609,10 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -14638,10 +14609,10 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 14638 | const elem_default_val = if (lhs_is_tuple) lhs_ty.structFieldDefaultValue(lhs_elem_i, mod) else Value.@"unreachable"; | 14609 | const elem_default_val = if (lhs_is_tuple) lhs_ty.structFieldDefaultValue(lhs_elem_i, mod) else Value.@"unreachable"; |
| 14639 | const elem_val = if (elem_default_val.toIntern() == .unreachable_value) try lhs_sub_val.elemValue(mod, lhs_elem_i) else elem_default_val; | 14610 | const elem_val = if (elem_default_val.toIntern() == .unreachable_value) try lhs_sub_val.elemValue(mod, lhs_elem_i) else elem_default_val; |
| 14640 | const elem_val_inst = Air.internedToRef(elem_val.toIntern()); | 14611 | const elem_val_inst = Air.internedToRef(elem_val.toIntern()); |
| 14641 | const operand_src: LazySrcLoc = .{ .array_cat_lhs = .{ | 14612 | const operand_src = block.src(.{ .array_cat_lhs = .{ |
| 14642 | .array_cat_offset = inst_data.src_node, | 14613 | .array_cat_offset = inst_data.src_node, |
| 14643 | .elem_index = elem_i, | 14614 | .elem_index = elem_i, |
| 14644 | } }; | 14615 | } }); |
| 14645 | const coerced_elem_val_inst = try sema.coerce(block, resolved_elem_ty, elem_val_inst, operand_src); | 14616 | const coerced_elem_val_inst = try sema.coerce(block, resolved_elem_ty, elem_val_inst, operand_src); |
| 14646 | const coerced_elem_val = try sema.resolveConstValue(block, operand_src, coerced_elem_val_inst, undefined); | 14617 | const coerced_elem_val = try sema.resolveConstValue(block, operand_src, coerced_elem_val_inst, undefined); |
| 14647 | element_vals[elem_i] = coerced_elem_val.toIntern(); | 14618 | element_vals[elem_i] = coerced_elem_val.toIntern(); |
| ... | @@ -14651,10 +14622,10 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -14651,10 +14622,10 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 14651 | const elem_default_val = if (rhs_is_tuple) rhs_ty.structFieldDefaultValue(rhs_elem_i, mod) else Value.@"unreachable"; | 14622 | const elem_default_val = if (rhs_is_tuple) rhs_ty.structFieldDefaultValue(rhs_elem_i, mod) else Value.@"unreachable"; |
| 14652 | const elem_val = if (elem_default_val.toIntern() == .unreachable_value) try rhs_sub_val.elemValue(mod, rhs_elem_i) else elem_default_val; | 14623 | const elem_val = if (elem_default_val.toIntern() == .unreachable_value) try rhs_sub_val.elemValue(mod, rhs_elem_i) else elem_default_val; |
| 14653 | const elem_val_inst = Air.internedToRef(elem_val.toIntern()); | 14624 | const elem_val_inst = Air.internedToRef(elem_val.toIntern()); |
| 14654 | const operand_src: LazySrcLoc = .{ .array_cat_rhs = .{ | 14625 | const operand_src = block.src(.{ .array_cat_rhs = .{ |
| 14655 | .array_cat_offset = inst_data.src_node, | 14626 | .array_cat_offset = inst_data.src_node, |
| 14656 | .elem_index = @intCast(rhs_elem_i), | 14627 | .elem_index = @intCast(rhs_elem_i), |
| 14657 | } }; | 14628 | } }); |
| 14658 | const coerced_elem_val_inst = try sema.coerce(block, resolved_elem_ty, elem_val_inst, operand_src); | 14629 | const coerced_elem_val_inst = try sema.coerce(block, resolved_elem_ty, elem_val_inst, operand_src); |
| 14659 | const coerced_elem_val = try sema.resolveConstValue(block, operand_src, coerced_elem_val_inst, undefined); | 14630 | const coerced_elem_val = try sema.resolveConstValue(block, operand_src, coerced_elem_val_inst, undefined); |
| 14660 | element_vals[elem_i] = coerced_elem_val.toIntern(); | 14631 | element_vals[elem_i] = coerced_elem_val.toIntern(); |
| ... | @@ -14683,10 +14654,10 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -14683,10 +14654,10 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 14683 | while (elem_i < lhs_len) : (elem_i += 1) { | 14654 | while (elem_i < lhs_len) : (elem_i += 1) { |
| 14684 | const elem_index = try mod.intRef(Type.usize, elem_i); | 14655 | const elem_index = try mod.intRef(Type.usize, elem_i); |
| 14685 | const elem_ptr = try block.addPtrElemPtr(alloc, elem_index, elem_ptr_ty); | 14656 | const elem_ptr = try block.addPtrElemPtr(alloc, elem_index, elem_ptr_ty); |
| 14686 | const operand_src: LazySrcLoc = .{ .array_cat_lhs = .{ | 14657 | const operand_src = block.src(.{ .array_cat_lhs = .{ |
| 14687 | .array_cat_offset = inst_data.src_node, | 14658 | .array_cat_offset = inst_data.src_node, |
| 14688 | .elem_index = elem_i, | 14659 | .elem_index = elem_i, |
| 14689 | } }; | 14660 | } }); |
| 14690 | const init = try sema.elemVal(block, operand_src, lhs, elem_index, src, true); | 14661 | const init = try sema.elemVal(block, operand_src, lhs, elem_index, src, true); |
| 14691 | try sema.storePtr2(block, src, elem_ptr, src, init, operand_src, .store); | 14662 | try sema.storePtr2(block, src, elem_ptr, src, init, operand_src, .store); |
| 14692 | } | 14663 | } |
| ... | @@ -14695,10 +14666,10 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -14695,10 +14666,10 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 14695 | const elem_index = try mod.intRef(Type.usize, elem_i); | 14666 | const elem_index = try mod.intRef(Type.usize, elem_i); |
| 14696 | const rhs_index = try mod.intRef(Type.usize, rhs_elem_i); | 14667 | const rhs_index = try mod.intRef(Type.usize, rhs_elem_i); |
| 14697 | const elem_ptr = try block.addPtrElemPtr(alloc, elem_index, elem_ptr_ty); | 14668 | const elem_ptr = try block.addPtrElemPtr(alloc, elem_index, elem_ptr_ty); |
| 14698 | const operand_src: LazySrcLoc = .{ .array_cat_rhs = .{ | 14669 | const operand_src = block.src(.{ .array_cat_rhs = .{ |
| 14699 | .array_cat_offset = inst_data.src_node, | 14670 | .array_cat_offset = inst_data.src_node, |
| 14700 | .elem_index = @intCast(rhs_elem_i), | 14671 | .elem_index = @intCast(rhs_elem_i), |
| 14701 | } }; | 14672 | } }); |
| 14702 | const init = try sema.elemVal(block, operand_src, rhs, rhs_index, src, true); | 14673 | const init = try sema.elemVal(block, operand_src, rhs, rhs_index, src, true); |
| 14703 | try sema.storePtr2(block, src, elem_ptr, src, init, operand_src, .store); | 14674 | try sema.storePtr2(block, src, elem_ptr, src, init, operand_src, .store); |
| 14704 | } | 14675 | } |
| ... | @@ -14717,20 +14688,20 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -14717,20 +14688,20 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 14717 | var elem_i: u32 = 0; | 14688 | var elem_i: u32 = 0; |
| 14718 | while (elem_i < lhs_len) : (elem_i += 1) { | 14689 | while (elem_i < lhs_len) : (elem_i += 1) { |
| 14719 | const index = try mod.intRef(Type.usize, elem_i); | 14690 | const index = try mod.intRef(Type.usize, elem_i); |
| 14720 | const operand_src: LazySrcLoc = .{ .array_cat_lhs = .{ | 14691 | const operand_src = block.src(.{ .array_cat_lhs = .{ |
| 14721 | .array_cat_offset = inst_data.src_node, | 14692 | .array_cat_offset = inst_data.src_node, |
| 14722 | .elem_index = elem_i, | 14693 | .elem_index = elem_i, |
| 14723 | } }; | 14694 | } }); |
| 14724 | const init = try sema.elemVal(block, operand_src, lhs, index, src, true); | 14695 | const init = try sema.elemVal(block, operand_src, lhs, index, src, true); |
| 14725 | element_refs[elem_i] = try sema.coerce(block, resolved_elem_ty, init, operand_src); | 14696 | element_refs[elem_i] = try sema.coerce(block, resolved_elem_ty, init, operand_src); |
| 14726 | } | 14697 | } |
| 14727 | while (elem_i < result_len) : (elem_i += 1) { | 14698 | while (elem_i < result_len) : (elem_i += 1) { |
| 14728 | const rhs_elem_i = elem_i - lhs_len; | 14699 | const rhs_elem_i = elem_i - lhs_len; |
| 14729 | const index = try mod.intRef(Type.usize, rhs_elem_i); | 14700 | const index = try mod.intRef(Type.usize, rhs_elem_i); |
| 14730 | const operand_src: LazySrcLoc = .{ .array_cat_rhs = .{ | 14701 | const operand_src = block.src(.{ .array_cat_rhs = .{ |
| 14731 | .array_cat_offset = inst_data.src_node, | 14702 | .array_cat_offset = inst_data.src_node, |
| 14732 | .elem_index = @intCast(rhs_elem_i), | 14703 | .elem_index = @intCast(rhs_elem_i), |
| 14733 | } }; | 14704 | } }); |
| 14734 | const init = try sema.elemVal(block, operand_src, rhs, index, src, true); | 14705 | const init = try sema.elemVal(block, operand_src, rhs, index, src, true); |
| 14735 | element_refs[elem_i] = try sema.coerce(block, resolved_elem_ty, init, operand_src); | 14706 | element_refs[elem_i] = try sema.coerce(block, resolved_elem_ty, init, operand_src); |
| 14736 | } | 14707 | } |
| ... | @@ -14792,8 +14763,8 @@ fn analyzeTupleMul( | ... | @@ -14792,8 +14763,8 @@ fn analyzeTupleMul( |
| 14792 | ) CompileError!Air.Inst.Ref { | 14763 | ) CompileError!Air.Inst.Ref { |
| 14793 | const mod = sema.mod; | 14764 | const mod = sema.mod; |
| 14794 | const operand_ty = sema.typeOf(operand); | 14765 | const operand_ty = sema.typeOf(operand); |
| 14795 | const src = LazySrcLoc.nodeOffset(src_node); | 14766 | const src = block.nodeOffset(src_node); |
| 14796 | const len_src: LazySrcLoc = .{ .node_offset_bin_rhs = src_node }; | 14767 | const len_src = block.src(.{ .node_offset_bin_rhs = src_node }); |
| 14797 | | 14768 | |
| 14798 | const tuple_len = operand_ty.structFieldCount(mod); | 14769 | const tuple_len = operand_ty.structFieldCount(mod); |
| 14799 | const final_len = std.math.mul(usize, tuple_len, factor) catch | 14770 | const final_len = std.math.mul(usize, tuple_len, factor) catch |
| ... | @@ -14810,10 +14781,10 @@ fn analyzeTupleMul( | ... | @@ -14810,10 +14781,10 @@ fn analyzeTupleMul( |
| 14810 | for (0..tuple_len) |i| { | 14781 | for (0..tuple_len) |i| { |
| 14811 | types[i] = operand_ty.structFieldType(i, mod).toIntern(); | 14782 | types[i] = operand_ty.structFieldType(i, mod).toIntern(); |
| 14812 | values[i] = operand_ty.structFieldDefaultValue(i, mod).toIntern(); | 14783 | values[i] = operand_ty.structFieldDefaultValue(i, mod).toIntern(); |
| 14813 | const operand_src: LazySrcLoc = .{ .array_cat_lhs = .{ | 14784 | const operand_src = block.src(.{ .array_cat_lhs = .{ |
| 14814 | .array_cat_offset = src_node, | 14785 | .array_cat_offset = src_node, |
| 14815 | .elem_index = @intCast(i), | 14786 | .elem_index = @intCast(i), |
| 14816 | } }; | 14787 | } }); |
| 14817 | if (values[i] == .unreachable_value) { | 14788 | if (values[i] == .unreachable_value) { |
| 14818 | runtime_src = operand_src; | 14789 | runtime_src = operand_src; |
| 14819 | values[i] = .none; // TODO don't treat unreachable_value as special | 14790 | values[i] = .none; // TODO don't treat unreachable_value as special |
| ... | @@ -14845,10 +14816,10 @@ fn analyzeTupleMul( | ... | @@ -14845,10 +14816,10 @@ fn analyzeTupleMul( |
| 14845 | const element_refs = try sema.arena.alloc(Air.Inst.Ref, final_len); | 14816 | const element_refs = try sema.arena.alloc(Air.Inst.Ref, final_len); |
| 14846 | var i: u32 = 0; | 14817 | var i: u32 = 0; |
| 14847 | while (i < tuple_len) : (i += 1) { | 14818 | while (i < tuple_len) : (i += 1) { |
| 14848 | const operand_src: LazySrcLoc = .{ .array_cat_lhs = .{ | 14819 | const operand_src = block.src(.{ .array_cat_lhs = .{ |
| 14849 | .array_cat_offset = src_node, | 14820 | .array_cat_offset = src_node, |
| 14850 | .elem_index = i, | 14821 | .elem_index = i, |
| 14851 | } }; | 14822 | } }); |
| 14852 | element_refs[i] = try sema.tupleFieldValByIndex(block, operand_src, operand, @intCast(i), operand_ty); | 14823 | element_refs[i] = try sema.tupleFieldValByIndex(block, operand_src, operand, @intCast(i), operand_ty); |
| 14853 | } | 14824 | } |
| 14854 | i = 1; | 14825 | i = 1; |
| ... | @@ -14868,10 +14839,10 @@ fn zirArrayMul(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -14868,10 +14839,10 @@ fn zirArrayMul(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 14868 | const extra = sema.code.extraData(Zir.Inst.ArrayMul, inst_data.payload_index).data; | 14839 | const extra = sema.code.extraData(Zir.Inst.ArrayMul, inst_data.payload_index).data; |
| 14869 | const uncoerced_lhs = try sema.resolveInst(extra.lhs); | 14840 | const uncoerced_lhs = try sema.resolveInst(extra.lhs); |
| 14870 | const uncoerced_lhs_ty = sema.typeOf(uncoerced_lhs); | 14841 | const uncoerced_lhs_ty = sema.typeOf(uncoerced_lhs); |
| 14871 | const src: LazySrcLoc = inst_data.src(); | 14842 | const src: LazySrcLoc = block.nodeOffset(inst_data.src_node); |
| 14872 | const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node }; | 14843 | const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node }); |
| 14873 | const operator_src: LazySrcLoc = .{ .node_offset_main_token = inst_data.src_node }; | 14844 | const operator_src = block.src(.{ .node_offset_main_token = inst_data.src_node }); |
| 14874 | const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node }; | 14845 | const rhs_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node }); |
| 14875 | | 14846 | |
| 14876 | const lhs, const lhs_ty = coerced_lhs: { | 14847 | const lhs, const lhs_ty = coerced_lhs: { |
| 14877 | // If we have a result type, we might be able to do this more efficiently | 14848 | // If we have a result type, we might be able to do this more efficiently |
| ... | @@ -14920,11 +14891,11 @@ fn zirArrayMul(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -14920,11 +14891,11 @@ fn zirArrayMul(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 14920 | // Analyze the lhs first, to catch the case that someone tried to do exponentiation | 14891 | // Analyze the lhs first, to catch the case that someone tried to do exponentiation |
| 14921 | const lhs_info = try sema.getArrayCatInfo(block, lhs_src, lhs, lhs_ty) orelse { | 14892 | const lhs_info = try sema.getArrayCatInfo(block, lhs_src, lhs, lhs_ty) orelse { |
| 14922 | const msg = msg: { | 14893 | const msg = msg: { |
| 14923 | const msg = try sema.errMsg(block, lhs_src, "expected indexable; found '{}'", .{lhs_ty.fmt(mod)}); | 14894 | const msg = try sema.errMsg(lhs_src, "expected indexable; found '{}'", .{lhs_ty.fmt(mod)}); |
| 14924 | errdefer msg.destroy(sema.gpa); | 14895 | errdefer msg.destroy(sema.gpa); |
| 14925 | switch (lhs_ty.zigTypeTag(mod)) { | 14896 | switch (lhs_ty.zigTypeTag(mod)) { |
| 14926 | .Int, .Float, .ComptimeFloat, .ComptimeInt, .Vector => { | 14897 | .Int, .Float, .ComptimeFloat, .ComptimeInt, .Vector => { |
| 14927 | try sema.errNote(block, operator_src, msg, "this operator multiplies arrays; use std.math.pow for exponentiation", .{}); | 14898 | try sema.errNote(operator_src, msg, "this operator multiplies arrays; use std.math.pow for exponentiation", .{}); |
| 14928 | }, | 14899 | }, |
| 14929 | else => {}, | 14900 | else => {}, |
| 14930 | } | 14901 | } |
| ... | @@ -15038,9 +15009,9 @@ fn zirArrayMul(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -15038,9 +15009,9 @@ fn zirArrayMul(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 15038 | fn zirNegate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 15009 | fn zirNegate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 15039 | const mod = sema.mod; | 15010 | const mod = sema.mod; |
| 15040 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; | 15011 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 15041 | const src = inst_data.src(); | 15012 | const src = block.nodeOffset(inst_data.src_node); |
| 15042 | const lhs_src = src; | 15013 | const lhs_src = src; |
| 15043 | const rhs_src: LazySrcLoc = .{ .node_offset_un_op = inst_data.src_node }; | 15014 | const rhs_src = block.src(.{ .node_offset_un_op = inst_data.src_node }); |
| 15044 | | 15015 | |
| 15045 | const rhs = try sema.resolveInst(inst_data.operand); | 15016 | const rhs = try sema.resolveInst(inst_data.operand); |
| 15046 | const rhs_ty = sema.typeOf(rhs); | 15017 | const rhs_ty = sema.typeOf(rhs); |
| ... | @@ -15070,9 +15041,9 @@ fn zirNegate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. | ... | @@ -15070,9 +15041,9 @@ fn zirNegate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. |
| 15070 | fn zirNegateWrap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 15041 | fn zirNegateWrap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 15071 | const mod = sema.mod; | 15042 | const mod = sema.mod; |
| 15072 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; | 15043 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 15073 | const src = inst_data.src(); | 15044 | const src = block.nodeOffset(inst_data.src_node); |
| 15074 | const lhs_src = src; | 15045 | const lhs_src = src; |
| 15075 | const rhs_src: LazySrcLoc = .{ .node_offset_un_op = inst_data.src_node }; | 15046 | const rhs_src = block.src(.{ .node_offset_un_op = inst_data.src_node }); |
| 15076 | | 15047 | |
| 15077 | const rhs = try sema.resolveInst(inst_data.operand); | 15048 | const rhs = try sema.resolveInst(inst_data.operand); |
| 15078 | const rhs_ty = sema.typeOf(rhs); | 15049 | const rhs_ty = sema.typeOf(rhs); |
| ... | @@ -15098,9 +15069,9 @@ fn zirArithmetic( | ... | @@ -15098,9 +15069,9 @@ fn zirArithmetic( |
| 15098 | defer tracy.end(); | 15069 | defer tracy.end(); |
| 15099 | | 15070 | |
| 15100 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 15071 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 15101 | const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node }; | 15072 | const src = block.src(.{ .node_offset_bin_op = inst_data.src_node }); |
| 15102 | const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node }; | 15073 | const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node }); |
| 15103 | const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node }; | 15074 | const rhs_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node }); |
| 15104 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; | 15075 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 15105 | const lhs = try sema.resolveInst(extra.lhs); | 15076 | const lhs = try sema.resolveInst(extra.lhs); |
| 15106 | const rhs = try sema.resolveInst(extra.rhs); | 15077 | const rhs = try sema.resolveInst(extra.rhs); |
| ... | @@ -15111,9 +15082,9 @@ fn zirArithmetic( | ... | @@ -15111,9 +15082,9 @@ fn zirArithmetic( |
| 15111 | fn zirDiv(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 15082 | fn zirDiv(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 15112 | const mod = sema.mod; | 15083 | const mod = sema.mod; |
| 15113 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 15084 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 15114 | const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node }; | 15085 | const src = block.src(.{ .node_offset_bin_op = inst_data.src_node }); |
| 15115 | const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node }; | 15086 | const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node }); |
| 15116 | const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node }; | 15087 | const rhs_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node }); |
| 15117 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; | 15088 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 15118 | const lhs = try sema.resolveInst(extra.lhs); | 15089 | const lhs = try sema.resolveInst(extra.lhs); |
| 15119 | const rhs = try sema.resolveInst(extra.rhs); | 15090 | const rhs = try sema.resolveInst(extra.rhs); |
| ... | @@ -15276,9 +15247,9 @@ fn zirDiv(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins | ... | @@ -15276,9 +15247,9 @@ fn zirDiv(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins |
| 15276 | fn zirDivExact(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 15247 | fn zirDivExact(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 15277 | const mod = sema.mod; | 15248 | const mod = sema.mod; |
| 15278 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 15249 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 15279 | const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node }; | 15250 | const src = block.src(.{ .node_offset_bin_op = inst_data.src_node }); |
| 15280 | const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node }; | 15251 | const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node }); |
| 15281 | const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node }; | 15252 | const rhs_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node }); |
| 15282 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; | 15253 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 15283 | const lhs = try sema.resolveInst(extra.lhs); | 15254 | const lhs = try sema.resolveInst(extra.lhs); |
| 15284 | const rhs = try sema.resolveInst(extra.rhs); | 15255 | const rhs = try sema.resolveInst(extra.rhs); |
| ... | @@ -15441,9 +15412,9 @@ fn zirDivExact(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -15441,9 +15412,9 @@ fn zirDivExact(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 15441 | fn zirDivFloor(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 15412 | fn zirDivFloor(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 15442 | const mod = sema.mod; | 15413 | const mod = sema.mod; |
| 15443 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 15414 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 15444 | const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node }; | 15415 | const src = block.src(.{ .node_offset_bin_op = inst_data.src_node }); |
| 15445 | const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node }; | 15416 | const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node }); |
| 15446 | const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node }; | 15417 | const rhs_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node }); |
| 15447 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; | 15418 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 15448 | const lhs = try sema.resolveInst(extra.lhs); | 15419 | const lhs = try sema.resolveInst(extra.lhs); |
| 15449 | const rhs = try sema.resolveInst(extra.rhs); | 15420 | const rhs = try sema.resolveInst(extra.rhs); |
| ... | @@ -15551,9 +15522,9 @@ fn zirDivFloor(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -15551,9 +15522,9 @@ fn zirDivFloor(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 15551 | fn zirDivTrunc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 15522 | fn zirDivTrunc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 15552 | const mod = sema.mod; | 15523 | const mod = sema.mod; |
| 15553 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 15524 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 15554 | const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node }; | 15525 | const src = block.src(.{ .node_offset_bin_op = inst_data.src_node }); |
| 15555 | const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node }; | 15526 | const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node }); |
| 15556 | const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node }; | 15527 | const rhs_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node }); |
| 15557 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; | 15528 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 15558 | const lhs = try sema.resolveInst(extra.lhs); | 15529 | const lhs = try sema.resolveInst(extra.lhs); |
| 15559 | const rhs = try sema.resolveInst(extra.rhs); | 15530 | const rhs = try sema.resolveInst(extra.rhs); |
| ... | @@ -15792,9 +15763,9 @@ fn airTag(block: *Block, is_int: bool, normal: Air.Inst.Tag, optimized: Air.Inst | ... | @@ -15792,9 +15763,9 @@ fn airTag(block: *Block, is_int: bool, normal: Air.Inst.Tag, optimized: Air.Inst |
| 15792 | fn zirModRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 15763 | fn zirModRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 15793 | const mod = sema.mod; | 15764 | const mod = sema.mod; |
| 15794 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 15765 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 15795 | const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node }; | 15766 | const src = block.src(.{ .node_offset_bin_op = inst_data.src_node }); |
| 15796 | const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node }; | 15767 | const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node }); |
| 15797 | const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node }; | 15768 | const rhs_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node }); |
| 15798 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; | 15769 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 15799 | const lhs = try sema.resolveInst(extra.lhs); | 15770 | const lhs = try sema.resolveInst(extra.lhs); |
| 15800 | const rhs = try sema.resolveInst(extra.rhs); | 15771 | const rhs = try sema.resolveInst(extra.rhs); |
| ... | @@ -15976,9 +15947,9 @@ fn intRemScalar(sema: *Sema, lhs: Value, rhs: Value, scalar_ty: Type) CompileErr | ... | @@ -15976,9 +15947,9 @@ fn intRemScalar(sema: *Sema, lhs: Value, rhs: Value, scalar_ty: Type) CompileErr |
| 15976 | fn zirMod(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 15947 | fn zirMod(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 15977 | const mod = sema.mod; | 15948 | const mod = sema.mod; |
| 15978 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 15949 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 15979 | const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node }; | 15950 | const src = block.src(.{ .node_offset_bin_op = inst_data.src_node }); |
| 15980 | const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node }; | 15951 | const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node }); |
| 15981 | const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node }; | 15952 | const rhs_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node }); |
| 15982 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; | 15953 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 15983 | const lhs = try sema.resolveInst(extra.lhs); | 15954 | const lhs = try sema.resolveInst(extra.lhs); |
| 15984 | const rhs = try sema.resolveInst(extra.rhs); | 15955 | const rhs = try sema.resolveInst(extra.rhs); |
| ... | @@ -16071,9 +16042,9 @@ fn zirMod(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins | ... | @@ -16071,9 +16042,9 @@ fn zirMod(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins |
| 16071 | fn zirRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 16042 | fn zirRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 16072 | const mod = sema.mod; | 16043 | const mod = sema.mod; |
| 16073 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 16044 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 16074 | const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node }; | 16045 | const src = block.src(.{ .node_offset_bin_op = inst_data.src_node }); |
| 16075 | const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node }; | 16046 | const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node }); |
| 16076 | const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node }; | 16047 | const rhs_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node }); |
| 16077 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; | 16048 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 16078 | const lhs = try sema.resolveInst(extra.lhs); | 16049 | const lhs = try sema.resolveInst(extra.lhs); |
| 16079 | const rhs = try sema.resolveInst(extra.rhs); | 16050 | const rhs = try sema.resolveInst(extra.rhs); |
| ... | @@ -16173,10 +16144,10 @@ fn zirOverflowArithmetic( | ... | @@ -16173,10 +16144,10 @@ fn zirOverflowArithmetic( |
| 16173 | defer tracy.end(); | 16144 | defer tracy.end(); |
| 16174 | | 16145 | |
| 16175 | const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data; | 16146 | const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data; |
| 16176 | const src = LazySrcLoc.nodeOffset(extra.node); | 16147 | const src = block.nodeOffset(extra.node); |
| 16177 | | 16148 | |
| 16178 | const lhs_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node }; | 16149 | const lhs_src = block.builtinCallArgSrc(extra.node, 0); |
| 16179 | const rhs_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = extra.node }; | 16150 | const rhs_src = block.builtinCallArgSrc(extra.node, 1); |
| 16180 | | 16151 | |
| 16181 | const uncasted_lhs = try sema.resolveInst(extra.lhs); | 16152 | const uncasted_lhs = try sema.resolveInst(extra.lhs); |
| 16182 | const uncasted_rhs = try sema.resolveInst(extra.rhs); | 16153 | const uncasted_rhs = try sema.resolveInst(extra.rhs); |
| ... | @@ -16988,7 +16959,7 @@ fn zirLoad(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.In | ... | @@ -16988,7 +16959,7 @@ fn zirLoad(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.In |
| 16988 | defer tracy.end(); | 16959 | defer tracy.end(); |
| 16989 | | 16960 | |
| 16990 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; | 16961 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 16991 | const src = inst_data.src(); | 16962 | const src = block.nodeOffset(inst_data.src_node); |
| 16992 | const ptr_src = src; // TODO better source location | 16963 | const ptr_src = src; // TODO better source location |
| 16993 | const ptr = try sema.resolveInst(inst_data.operand); | 16964 | const ptr = try sema.resolveInst(inst_data.operand); |
| 16994 | return sema.analyzeLoad(block, src, ptr, ptr_src); | 16965 | return sema.analyzeLoad(block, src, ptr, ptr_src); |
| ... | @@ -17004,8 +16975,8 @@ fn zirAsm( | ... | @@ -17004,8 +16975,8 @@ fn zirAsm( |
| 17004 | defer tracy.end(); | 16975 | defer tracy.end(); |
| 17005 | | 16976 | |
| 17006 | const extra = sema.code.extraData(Zir.Inst.Asm, extended.operand); | 16977 | const extra = sema.code.extraData(Zir.Inst.Asm, extended.operand); |
| 17007 | const src = LazySrcLoc.nodeOffset(extra.data.src_node); | 16978 | const src = block.nodeOffset(extra.data.src_node); |
| 17008 | const ret_ty_src: LazySrcLoc = .{ .node_offset_asm_ret_ty = extra.data.src_node }; | 16979 | const ret_ty_src = block.src(.{ .node_offset_asm_ret_ty = extra.data.src_node }); |
| 17009 | const outputs_len: u5 = @truncate(extended.small); | 16980 | const outputs_len: u5 = @truncate(extended.small); |
| 17010 | const inputs_len: u5 = @truncate(extended.small >> 5); | 16981 | const inputs_len: u5 = @truncate(extended.small >> 5); |
| 17011 | const clobbers_len: u5 = @truncate(extended.small >> 10); | 16982 | const clobbers_len: u5 = @truncate(extended.small >> 10); |
| ... | @@ -17178,9 +17149,9 @@ fn zirCmpEq( | ... | @@ -17178,9 +17149,9 @@ fn zirCmpEq( |
| 17178 | const mod = sema.mod; | 17149 | const mod = sema.mod; |
| 17179 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 17150 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 17180 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; | 17151 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 17181 | const src: LazySrcLoc = inst_data.src(); | 17152 | const src: LazySrcLoc = block.nodeOffset(inst_data.src_node); |
| 17182 | const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node }; | 17153 | const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node }); |
| 17183 | const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node }; | 17154 | const rhs_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node }); |
| 17184 | const lhs = try sema.resolveInst(extra.lhs); | 17155 | const lhs = try sema.resolveInst(extra.lhs); |
| 17185 | const rhs = try sema.resolveInst(extra.rhs); | 17156 | const rhs = try sema.resolveInst(extra.rhs); |
| 17186 | | 17157 | |
| ... | @@ -17259,9 +17230,9 @@ fn analyzeCmpUnionTag( | ... | @@ -17259,9 +17230,9 @@ fn analyzeCmpUnionTag( |
| 17259 | try sema.resolveTypeFields(union_ty); | 17230 | try sema.resolveTypeFields(union_ty); |
| 17260 | const union_tag_ty = union_ty.unionTagType(mod) orelse { | 17231 | const union_tag_ty = union_ty.unionTagType(mod) orelse { |
| 17261 | const msg = msg: { | 17232 | const msg = msg: { |
| 17262 | const msg = try sema.errMsg(block, un_src, "comparison of union and enum literal is only valid for tagged union types", .{}); | 17233 | const msg = try sema.errMsg(un_src, "comparison of union and enum literal is only valid for tagged union types", .{}); |
| 17263 | errdefer msg.destroy(sema.gpa); | 17234 | errdefer msg.destroy(sema.gpa); |
| 17264 | try mod.errNoteNonLazy(union_ty.declSrcLoc(mod), msg, "union '{}' is not a tagged union", .{union_ty.fmt(mod)}); | 17235 | try sema.errNote(union_ty.srcLoc(mod), msg, "union '{}' is not a tagged union", .{union_ty.fmt(mod)}); |
| 17265 | break :msg msg; | 17236 | break :msg msg; |
| 17266 | }; | 17237 | }; |
| 17267 | return sema.failWithOwnedErrorMsg(block, msg); | 17238 | return sema.failWithOwnedErrorMsg(block, msg); |
| ... | @@ -17294,9 +17265,9 @@ fn zirCmp( | ... | @@ -17294,9 +17265,9 @@ fn zirCmp( |
| 17294 | | 17265 | |
| 17295 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 17266 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 17296 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; | 17267 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 17297 | const src: LazySrcLoc = inst_data.src(); | 17268 | const src: LazySrcLoc = block.nodeOffset(inst_data.src_node); |
| 17298 | const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node }; | 17269 | const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node }); |
| 17299 | const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node }; | 17270 | const rhs_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node }); |
| 17300 | const lhs = try sema.resolveInst(extra.lhs); | 17271 | const lhs = try sema.resolveInst(extra.lhs); |
| 17301 | const rhs = try sema.resolveInst(extra.rhs); | 17272 | const rhs = try sema.resolveInst(extra.rhs); |
| 17302 | return sema.analyzeCmp(block, src, lhs, rhs, op, lhs_src, rhs_src, false); | 17273 | return sema.analyzeCmp(block, src, lhs, rhs, op, lhs_src, rhs_src, false); |
| ... | @@ -17438,7 +17409,7 @@ fn runtimeBoolCmp( | ... | @@ -17438,7 +17409,7 @@ fn runtimeBoolCmp( |
| 17438 | fn zirSizeOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 17409 | fn zirSizeOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 17439 | const mod = sema.mod; | 17410 | const mod = sema.mod; |
| 17440 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; | 17411 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 17441 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 17412 | const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0); |
| 17442 | const ty = try sema.resolveType(block, operand_src, inst_data.operand); | 17413 | const ty = try sema.resolveType(block, operand_src, inst_data.operand); |
| 17443 | switch (ty.zigTypeTag(mod)) { | 17414 | switch (ty.zigTypeTag(mod)) { |
| 17444 | .Fn, | 17415 | .Fn, |
| ... | @@ -17481,7 +17452,7 @@ fn zirSizeOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. | ... | @@ -17481,7 +17452,7 @@ fn zirSizeOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. |
| 17481 | fn zirBitSizeOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 17452 | fn zirBitSizeOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 17482 | const mod = sema.mod; | 17453 | const mod = sema.mod; |
| 17483 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; | 17454 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 17484 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 17455 | const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0); |
| 17485 | const operand_ty = try sema.resolveType(block, operand_src, inst_data.operand); | 17456 | const operand_ty = try sema.resolveType(block, operand_src, inst_data.operand); |
| 17486 | switch (operand_ty.zigTypeTag(mod)) { | 17457 | switch (operand_ty.zigTypeTag(mod)) { |
| 17487 | .Fn, | 17458 | .Fn, |
| ... | @@ -17525,7 +17496,7 @@ fn zirThis( | ... | @@ -17525,7 +17496,7 @@ fn zirThis( |
| 17525 | ) CompileError!Air.Inst.Ref { | 17496 | ) CompileError!Air.Inst.Ref { |
| 17526 | const mod = sema.mod; | 17497 | const mod = sema.mod; |
| 17527 | const this_decl_index = mod.namespacePtr(block.namespace).decl_index; | 17498 | const this_decl_index = mod.namespacePtr(block.namespace).decl_index; |
| 17528 | const src = LazySrcLoc.nodeOffset(@bitCast(extended.operand)); | 17499 | const src = block.nodeOffset(@bitCast(extended.operand)); |
| 17529 | return sema.analyzeDeclVal(block, src, this_decl_index); | 17500 | return sema.analyzeDeclVal(block, src, this_decl_index); |
| 17530 | } | 17501 | } |
| 17531 | | 17502 | |
| ... | @@ -17535,7 +17506,7 @@ fn zirClosureGet(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat | ... | @@ -17535,7 +17506,7 @@ fn zirClosureGet(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat |
| 17535 | const captures = mod.namespacePtr(block.namespace).getType(mod).getCaptures(mod); | 17506 | const captures = mod.namespacePtr(block.namespace).getType(mod).getCaptures(mod); |
| 17536 | | 17507 | |
| 17537 | const src_node: i32 = @bitCast(extended.operand); | 17508 | const src_node: i32 = @bitCast(extended.operand); |
| 17538 | const src = LazySrcLoc.nodeOffset(src_node); | 17509 | const src = block.nodeOffset(src_node); |
| 17539 | | 17510 | |
| 17540 | const capture_ty = switch (captures.get(ip)[extended.small].unwrap()) { | 17511 | const capture_ty = switch (captures.get(ip)[extended.small].unwrap()) { |
| 17541 | .@"comptime" => |index| return Air.internedToRef(index), | 17512 | .@"comptime" => |index| return Air.internedToRef(index), |
| ... | @@ -17549,7 +17520,8 @@ fn zirClosureGet(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat | ... | @@ -17549,7 +17520,8 @@ fn zirClosureGet(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat |
| 17549 | if (!block.is_typeof and sema.func_index == .none) { | 17520 | if (!block.is_typeof and sema.func_index == .none) { |
| 17550 | const msg = msg: { | 17521 | const msg = msg: { |
| 17551 | const name = name: { | 17522 | const name = name: { |
| 17552 | const file = sema.owner_decl.getFileScope(mod); | 17523 | // TODO: we should probably store this name in the ZIR to avoid this complexity. |
| | 17524 | const file, const src_base_node = Module.LazySrcLoc.resolveBaseNode(block.src_base_inst, mod); |
| 17553 | const tree = file.getTree(sema.gpa) catch |err| { | 17525 | const tree = file.getTree(sema.gpa) catch |err| { |
| 17554 | // In this case we emit a warning + a less precise source location. | 17526 | // In this case we emit a warning + a less precise source location. |
| 17555 | log.warn("unable to load {s}: {s}", .{ | 17527 | log.warn("unable to load {s}: {s}", .{ |
| ... | @@ -17557,15 +17529,15 @@ fn zirClosureGet(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat | ... | @@ -17557,15 +17529,15 @@ fn zirClosureGet(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat |
| 17557 | }); | 17529 | }); |
| 17558 | break :name null; | 17530 | break :name null; |
| 17559 | }; | 17531 | }; |
| 17560 | const node = sema.owner_decl.relativeToNodeIndex(src_node); | 17532 | const node: std.zig.Ast.Node.Index = @bitCast(src_node + @as(i32, @bitCast(src_base_node))); |
| 17561 | const token = tree.nodes.items(.main_token)[node]; | 17533 | const token = tree.nodes.items(.main_token)[node]; |
| 17562 | break :name tree.tokenSlice(token); | 17534 | break :name tree.tokenSlice(token); |
| 17563 | }; | 17535 | }; |
| 17564 | | 17536 | |
| 17565 | const msg = if (name) |some| | 17537 | const msg = if (name) |some| |
| 17566 | try sema.errMsg(block, src, "'{s}' not accessible outside function scope", .{some}) | 17538 | try sema.errMsg(src, "'{s}' not accessible outside function scope", .{some}) |
| 17567 | else | 17539 | else |
| 17568 | try sema.errMsg(block, src, "variable not accessible outside function scope", .{}); | 17540 | try sema.errMsg(src, "variable not accessible outside function scope", .{}); |
| 17569 | errdefer msg.destroy(sema.gpa); | 17541 | errdefer msg.destroy(sema.gpa); |
| 17570 | | 17542 | |
| 17571 | // TODO add "declared here" note | 17543 | // TODO add "declared here" note |
| ... | @@ -17577,7 +17549,7 @@ fn zirClosureGet(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat | ... | @@ -17577,7 +17549,7 @@ fn zirClosureGet(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat |
| 17577 | if (!block.is_typeof and !block.is_comptime and sema.func_index != .none) { | 17549 | if (!block.is_typeof and !block.is_comptime and sema.func_index != .none) { |
| 17578 | const msg = msg: { | 17550 | const msg = msg: { |
| 17579 | const name = name: { | 17551 | const name = name: { |
| 17580 | const file = sema.owner_decl.getFileScope(mod); | 17552 | const file, const src_base_node = Module.LazySrcLoc.resolveBaseNode(block.src_base_inst, mod); |
| 17581 | const tree = file.getTree(sema.gpa) catch |err| { | 17553 | const tree = file.getTree(sema.gpa) catch |err| { |
| 17582 | // In this case we emit a warning + a less precise source location. | 17554 | // In this case we emit a warning + a less precise source location. |
| 17583 | log.warn("unable to load {s}: {s}", .{ | 17555 | log.warn("unable to load {s}: {s}", .{ |
| ... | @@ -17585,18 +17557,18 @@ fn zirClosureGet(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat | ... | @@ -17585,18 +17557,18 @@ fn zirClosureGet(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat |
| 17585 | }); | 17557 | }); |
| 17586 | break :name null; | 17558 | break :name null; |
| 17587 | }; | 17559 | }; |
| 17588 | const node = sema.owner_decl.relativeToNodeIndex(src_node); | 17560 | const node: std.zig.Ast.Node.Index = @bitCast(src_node + @as(i32, @bitCast(src_base_node))); |
| 17589 | const token = tree.nodes.items(.main_token)[node]; | 17561 | const token = tree.nodes.items(.main_token)[node]; |
| 17590 | break :name tree.tokenSlice(token); | 17562 | break :name tree.tokenSlice(token); |
| 17591 | }; | 17563 | }; |
| 17592 | | 17564 | |
| 17593 | const msg = if (name) |some| | 17565 | const msg = if (name) |some| |
| 17594 | try sema.errMsg(block, src, "'{s}' not accessible from inner function", .{some}) | 17566 | try sema.errMsg(src, "'{s}' not accessible from inner function", .{some}) |
| 17595 | else | 17567 | else |
| 17596 | try sema.errMsg(block, src, "variable not accessible from inner function", .{}); | 17568 | try sema.errMsg(src, "variable not accessible from inner function", .{}); |
| 17597 | errdefer msg.destroy(sema.gpa); | 17569 | errdefer msg.destroy(sema.gpa); |
| 17598 | | 17570 | |
| 17599 | try sema.errNote(block, LazySrcLoc.nodeOffset(0), msg, "crossed function definition here", .{}); | 17571 | try sema.errNote(block.nodeOffset(0), msg, "crossed function definition here", .{}); |
| 17600 | | 17572 | |
| 17601 | // TODO add "declared here" note | 17573 | // TODO add "declared here" note |
| 17602 | break :msg msg; | 17574 | break :msg msg; |
| ... | @@ -17628,7 +17600,7 @@ fn zirFrameAddress( | ... | @@ -17628,7 +17600,7 @@ fn zirFrameAddress( |
| 17628 | block: *Block, | 17600 | block: *Block, |
| 17629 | extended: Zir.Inst.Extended.InstData, | 17601 | extended: Zir.Inst.Extended.InstData, |
| 17630 | ) CompileError!Air.Inst.Ref { | 17602 | ) CompileError!Air.Inst.Ref { |
| 17631 | const src = LazySrcLoc.nodeOffset(@bitCast(extended.operand)); | 17603 | const src = block.nodeOffset(@bitCast(extended.operand)); |
| 17632 | try sema.requireRuntimeBlock(block, src, null); | 17604 | try sema.requireRuntimeBlock(block, src, null); |
| 17633 | return try block.addNoOp(.frame_addr); | 17605 | return try block.addNoOp(.frame_addr); |
| 17634 | } | 17606 | } |
| ... | @@ -17721,7 +17693,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -17721,7 +17693,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 17721 | const gpa = sema.gpa; | 17693 | const gpa = sema.gpa; |
| 17722 | const ip = &mod.intern_pool; | 17694 | const ip = &mod.intern_pool; |
| 17723 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; | 17695 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 17724 | const src = inst_data.src(); | 17696 | const src = block.nodeOffset(inst_data.src_node); |
| 17725 | const ty = try sema.resolveType(block, src, inst_data.operand); | 17697 | const ty = try sema.resolveType(block, src, inst_data.operand); |
| 17726 | const type_info_ty = try sema.getBuiltinType("Type"); | 17698 | const type_info_ty = try sema.getBuiltinType("Type"); |
| 17727 | const type_info_tag_ty = type_info_ty.unionTagType(mod).?; | 17699 | const type_info_tag_ty = type_info_ty.unionTagType(mod).?; |
| ... | @@ -18884,7 +18856,6 @@ fn zirTypeofBuiltin(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr | ... | @@ -18884,7 +18856,6 @@ fn zirTypeofBuiltin(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr |
| 18884 | var child_block: Block = .{ | 18856 | var child_block: Block = .{ |
| 18885 | .parent = block, | 18857 | .parent = block, |
| 18886 | .sema = sema, | 18858 | .sema = sema, |
| 18887 | .src_decl = block.src_decl, | | |
| 18888 | .namespace = block.namespace, | 18859 | .namespace = block.namespace, |
| 18889 | .instructions = .{}, | 18860 | .instructions = .{}, |
| 18890 | .inlining = block.inlining, | 18861 | .inlining = block.inlining, |
| ... | @@ -18892,6 +18863,8 @@ fn zirTypeofBuiltin(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr | ... | @@ -18892,6 +18863,8 @@ fn zirTypeofBuiltin(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr |
| 18892 | .is_typeof = true, | 18863 | .is_typeof = true, |
| 18893 | .want_safety = false, | 18864 | .want_safety = false, |
| 18894 | .error_return_trace_index = block.error_return_trace_index, | 18865 | .error_return_trace_index = block.error_return_trace_index, |
| | 18866 | .src_base_inst = block.src_base_inst, |
| | 18867 | .type_name_ctx = block.type_name_ctx, |
| 18895 | }; | 18868 | }; |
| 18896 | defer child_block.instructions.deinit(sema.gpa); | 18869 | defer child_block.instructions.deinit(sema.gpa); |
| 18897 | | 18870 | |
| ... | @@ -18903,7 +18876,7 @@ fn zirTypeofBuiltin(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr | ... | @@ -18903,7 +18876,7 @@ fn zirTypeofBuiltin(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr |
| 18903 | | 18876 | |
| 18904 | fn zirTypeofLog2IntType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 18877 | fn zirTypeofLog2IntType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 18905 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; | 18878 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 18906 | const src = inst_data.src(); | 18879 | const src = block.nodeOffset(inst_data.src_node); |
| 18907 | const operand = try sema.resolveInst(inst_data.operand); | 18880 | const operand = try sema.resolveInst(inst_data.operand); |
| 18908 | const operand_ty = sema.typeOf(operand); | 18881 | const operand_ty = sema.typeOf(operand); |
| 18909 | const res_ty = try sema.log2IntType(block, operand_ty, src); | 18882 | const res_ty = try sema.log2IntType(block, operand_ty, src); |
| ... | @@ -18956,13 +18929,12 @@ fn zirTypeofPeer( | ... | @@ -18956,13 +18929,12 @@ fn zirTypeofPeer( |
| 18956 | defer tracy.end(); | 18929 | defer tracy.end(); |
| 18957 | | 18930 | |
| 18958 | const extra = sema.code.extraData(Zir.Inst.TypeOfPeer, extended.operand); | 18931 | const extra = sema.code.extraData(Zir.Inst.TypeOfPeer, extended.operand); |
| 18959 | const src = LazySrcLoc.nodeOffset(extra.data.src_node); | 18932 | const src = block.nodeOffset(extra.data.src_node); |
| 18960 | const body = sema.code.bodySlice(extra.data.body_index, extra.data.body_len); | 18933 | const body = sema.code.bodySlice(extra.data.body_index, extra.data.body_len); |
| 18961 | | 18934 | |
| 18962 | var child_block: Block = .{ | 18935 | var child_block: Block = .{ |
| 18963 | .parent = block, | 18936 | .parent = block, |
| 18964 | .sema = sema, | 18937 | .sema = sema, |
| 18965 | .src_decl = block.src_decl, | | |
| 18966 | .namespace = block.namespace, | 18938 | .namespace = block.namespace, |
| 18967 | .instructions = .{}, | 18939 | .instructions = .{}, |
| 18968 | .inlining = block.inlining, | 18940 | .inlining = block.inlining, |
| ... | @@ -18971,6 +18943,8 @@ fn zirTypeofPeer( | ... | @@ -18971,6 +18943,8 @@ fn zirTypeofPeer( |
| 18971 | .runtime_cond = block.runtime_cond, | 18943 | .runtime_cond = block.runtime_cond, |
| 18972 | .runtime_loop = block.runtime_loop, | 18944 | .runtime_loop = block.runtime_loop, |
| 18973 | .runtime_index = block.runtime_index, | 18945 | .runtime_index = block.runtime_index, |
| | 18946 | .src_base_inst = block.src_base_inst, |
| | 18947 | .type_name_ctx = block.type_name_ctx, |
| 18974 | }; | 18948 | }; |
| 18975 | defer child_block.instructions.deinit(sema.gpa); | 18949 | defer child_block.instructions.deinit(sema.gpa); |
| 18976 | // Ignore the result, we only care about the instructions in `args`. | 18950 | // Ignore the result, we only care about the instructions in `args`. |
| ... | @@ -18995,8 +18969,8 @@ fn zirBoolNot(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air | ... | @@ -18995,8 +18969,8 @@ fn zirBoolNot(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 18995 | | 18969 | |
| 18996 | const mod = sema.mod; | 18970 | const mod = sema.mod; |
| 18997 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; | 18971 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 18998 | const src = inst_data.src(); | 18972 | const src = block.nodeOffset(inst_data.src_node); |
| 18999 | const operand_src: LazySrcLoc = .{ .node_offset_un_op = inst_data.src_node }; | 18973 | const operand_src = block.src(.{ .node_offset_un_op = inst_data.src_node }); |
| 19000 | const uncasted_operand = try sema.resolveInst(inst_data.operand); | 18974 | const uncasted_operand = try sema.resolveInst(inst_data.operand); |
| 19001 | | 18975 | |
| 19002 | const operand = try sema.coerce(block, Type.bool, uncasted_operand, operand_src); | 18976 | const operand = try sema.coerce(block, Type.bool, uncasted_operand, operand_src); |
| ... | @@ -19027,8 +19001,8 @@ fn zirBoolBr( | ... | @@ -19027,8 +19001,8 @@ fn zirBoolBr( |
| 19027 | | 19001 | |
| 19028 | const uncoerced_lhs = try sema.resolveInst(extra.data.lhs); | 19002 | const uncoerced_lhs = try sema.resolveInst(extra.data.lhs); |
| 19029 | const body = sema.code.bodySlice(extra.end, extra.data.body_len); | 19003 | const body = sema.code.bodySlice(extra.end, extra.data.body_len); |
| 19030 | const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node }; | 19004 | const lhs_src = parent_block.src(.{ .node_offset_bin_lhs = inst_data.src_node }); |
| 19031 | const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node }; | 19005 | const rhs_src = parent_block.src(.{ .node_offset_bin_rhs = inst_data.src_node }); |
| 19032 | | 19006 | |
| 19033 | const lhs = try sema.coerce(parent_block, Type.bool, uncoerced_lhs, lhs_src); | 19007 | const lhs = try sema.coerce(parent_block, Type.bool, uncoerced_lhs, lhs_src); |
| 19034 | | 19008 | |
| ... | @@ -19059,7 +19033,7 @@ fn zirBoolBr( | ... | @@ -19059,7 +19033,7 @@ fn zirBoolBr( |
| 19059 | | 19033 | |
| 19060 | var child_block = parent_block.makeSubBlock(); | 19034 | var child_block = parent_block.makeSubBlock(); |
| 19061 | child_block.runtime_loop = null; | 19035 | child_block.runtime_loop = null; |
| 19062 | child_block.runtime_cond = mod.declPtr(child_block.src_decl).toSrcLoc(lhs_src, mod); | 19036 | child_block.runtime_cond = lhs_src; |
| 19063 | child_block.runtime_index.increment(); | 19037 | child_block.runtime_index.increment(); |
| 19064 | defer child_block.instructions.deinit(gpa); | 19038 | defer child_block.instructions.deinit(gpa); |
| 19065 | | 19039 | |
| ... | @@ -19152,7 +19126,7 @@ fn zirIsNonNull( | ... | @@ -19152,7 +19126,7 @@ fn zirIsNonNull( |
| 19152 | defer tracy.end(); | 19126 | defer tracy.end(); |
| 19153 | | 19127 | |
| 19154 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; | 19128 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 19155 | const src = inst_data.src(); | 19129 | const src = block.nodeOffset(inst_data.src_node); |
| 19156 | const operand = try sema.resolveInst(inst_data.operand); | 19130 | const operand = try sema.resolveInst(inst_data.operand); |
| 19157 | try sema.checkNullableType(block, src, sema.typeOf(operand)); | 19131 | try sema.checkNullableType(block, src, sema.typeOf(operand)); |
| 19158 | return sema.analyzeIsNull(block, src, operand, true); | 19132 | return sema.analyzeIsNull(block, src, operand, true); |
| ... | @@ -19168,7 +19142,7 @@ fn zirIsNonNullPtr( | ... | @@ -19168,7 +19142,7 @@ fn zirIsNonNullPtr( |
| 19168 | | 19142 | |
| 19169 | const mod = sema.mod; | 19143 | const mod = sema.mod; |
| 19170 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; | 19144 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 19171 | const src = inst_data.src(); | 19145 | const src = block.nodeOffset(inst_data.src_node); |
| 19172 | const ptr = try sema.resolveInst(inst_data.operand); | 19146 | const ptr = try sema.resolveInst(inst_data.operand); |
| 19173 | try sema.checkNullableType(block, src, sema.typeOf(ptr).elemType2(mod)); | 19147 | try sema.checkNullableType(block, src, sema.typeOf(ptr).elemType2(mod)); |
| 19174 | if ((try sema.resolveValue(ptr)) == null) { | 19148 | if ((try sema.resolveValue(ptr)) == null) { |
| ... | @@ -19193,7 +19167,7 @@ fn zirIsNonErr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -19193,7 +19167,7 @@ fn zirIsNonErr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 19193 | defer tracy.end(); | 19167 | defer tracy.end(); |
| 19194 | | 19168 | |
| 19195 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; | 19169 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 19196 | const src = inst_data.src(); | 19170 | const src = block.nodeOffset(inst_data.src_node); |
| 19197 | const operand = try sema.resolveInst(inst_data.operand); | 19171 | const operand = try sema.resolveInst(inst_data.operand); |
| 19198 | try sema.checkErrorType(block, src, sema.typeOf(operand)); | 19172 | try sema.checkErrorType(block, src, sema.typeOf(operand)); |
| 19199 | return sema.analyzeIsNonErr(block, src, operand); | 19173 | return sema.analyzeIsNonErr(block, src, operand); |
| ... | @@ -19205,7 +19179,7 @@ fn zirIsNonErrPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError | ... | @@ -19205,7 +19179,7 @@ fn zirIsNonErrPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 19205 | | 19179 | |
| 19206 | const mod = sema.mod; | 19180 | const mod = sema.mod; |
| 19207 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; | 19181 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 19208 | const src = inst_data.src(); | 19182 | const src = block.nodeOffset(inst_data.src_node); |
| 19209 | const ptr = try sema.resolveInst(inst_data.operand); | 19183 | const ptr = try sema.resolveInst(inst_data.operand); |
| 19210 | try sema.checkErrorType(block, src, sema.typeOf(ptr).elemType2(mod)); | 19184 | try sema.checkErrorType(block, src, sema.typeOf(ptr).elemType2(mod)); |
| 19211 | const loaded = try sema.analyzeLoad(block, src, ptr, src); | 19185 | const loaded = try sema.analyzeLoad(block, src, ptr, src); |
| ... | @@ -19217,7 +19191,7 @@ fn zirRetIsNonErr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError | ... | @@ -19217,7 +19191,7 @@ fn zirRetIsNonErr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 19217 | defer tracy.end(); | 19191 | defer tracy.end(); |
| 19218 | | 19192 | |
| 19219 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; | 19193 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 19220 | const src = inst_data.src(); | 19194 | const src = block.nodeOffset(inst_data.src_node); |
| 19221 | const operand = try sema.resolveInst(inst_data.operand); | 19195 | const operand = try sema.resolveInst(inst_data.operand); |
| 19222 | return sema.analyzeIsNonErr(block, src, operand); | 19196 | return sema.analyzeIsNonErr(block, src, operand); |
| 19223 | } | 19197 | } |
| ... | @@ -19232,7 +19206,7 @@ fn zirCondbr( | ... | @@ -19232,7 +19206,7 @@ fn zirCondbr( |
| 19232 | | 19206 | |
| 19233 | const mod = sema.mod; | 19207 | const mod = sema.mod; |
| 19234 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 19208 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 19235 | const cond_src: LazySrcLoc = .{ .node_offset_if_cond = inst_data.src_node }; | 19209 | const cond_src = parent_block.src(.{ .node_offset_if_cond = inst_data.src_node }); |
| 19236 | const extra = sema.code.extraData(Zir.Inst.CondBr, inst_data.payload_index); | 19210 | const extra = sema.code.extraData(Zir.Inst.CondBr, inst_data.payload_index); |
| 19237 | | 19211 | |
| 19238 | const then_body = sema.code.bodySlice(extra.end, extra.data.then_body_len); | 19212 | const then_body = sema.code.bodySlice(extra.end, extra.data.then_body_len); |
| ... | @@ -19255,7 +19229,7 @@ fn zirCondbr( | ... | @@ -19255,7 +19229,7 @@ fn zirCondbr( |
| 19255 | // instructions array in between using it for the then block and else block. | 19229 | // instructions array in between using it for the then block and else block. |
| 19256 | var sub_block = parent_block.makeSubBlock(); | 19230 | var sub_block = parent_block.makeSubBlock(); |
| 19257 | sub_block.runtime_loop = null; | 19231 | sub_block.runtime_loop = null; |
| 19258 | sub_block.runtime_cond = mod.declPtr(parent_block.src_decl).toSrcLoc(cond_src, mod); | 19232 | sub_block.runtime_cond = cond_src; |
| 19259 | sub_block.runtime_index.increment(); | 19233 | sub_block.runtime_index.increment(); |
| 19260 | sub_block.need_debug_scope = null; // this body is emitted regardless | 19234 | sub_block.need_debug_scope = null; // this body is emitted regardless |
| 19261 | defer sub_block.instructions.deinit(gpa); | 19235 | defer sub_block.instructions.deinit(gpa); |
| ... | @@ -19299,8 +19273,8 @@ fn zirCondbr( | ... | @@ -19299,8 +19273,8 @@ fn zirCondbr( |
| 19299 | | 19273 | |
| 19300 | fn zirTry(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 19274 | fn zirTry(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 19301 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 19275 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 19302 | const src = inst_data.src(); | 19276 | const src = parent_block.nodeOffset(inst_data.src_node); |
| 19303 | const operand_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node }; | 19277 | const operand_src = parent_block.src(.{ .node_offset_bin_lhs = inst_data.src_node }); |
| 19304 | const extra = sema.code.extraData(Zir.Inst.Try, inst_data.payload_index); | 19278 | const extra = sema.code.extraData(Zir.Inst.Try, inst_data.payload_index); |
| 19305 | const body = sema.code.bodySlice(extra.end, extra.data.body_len); | 19279 | const body = sema.code.bodySlice(extra.end, extra.data.body_len); |
| 19306 | const err_union = try sema.resolveInst(extra.data.operand); | 19280 | const err_union = try sema.resolveInst(extra.data.operand); |
| ... | @@ -19346,8 +19320,8 @@ fn zirTry(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError! | ... | @@ -19346,8 +19320,8 @@ fn zirTry(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError! |
| 19346 | | 19320 | |
| 19347 | fn zirTryPtr(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 19321 | fn zirTryPtr(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 19348 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 19322 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 19349 | const src = inst_data.src(); | 19323 | const src = parent_block.nodeOffset(inst_data.src_node); |
| 19350 | const operand_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node }; | 19324 | const operand_src = parent_block.src(.{ .node_offset_bin_lhs = inst_data.src_node }); |
| 19351 | const extra = sema.code.extraData(Zir.Inst.Try, inst_data.payload_index); | 19325 | const extra = sema.code.extraData(Zir.Inst.Try, inst_data.payload_index); |
| 19352 | const body = sema.code.bodySlice(extra.end, extra.data.body_len); | 19326 | const body = sema.code.bodySlice(extra.end, extra.data.body_len); |
| 19353 | const operand = try sema.resolveInst(extra.data.operand); | 19327 | const operand = try sema.resolveInst(extra.data.operand); |
| ... | @@ -19437,12 +19411,13 @@ fn ensurePostHoc(sema: *Sema, block: *Block, dest_block: Zir.Inst.Index) !*Label | ... | @@ -19437,12 +19411,13 @@ fn ensurePostHoc(sema: *Sema, block: *Block, dest_block: Zir.Inst.Index) !*Label |
| 19437 | .block = .{ | 19411 | .block = .{ |
| 19438 | .parent = block, | 19412 | .parent = block, |
| 19439 | .sema = sema, | 19413 | .sema = sema, |
| 19440 | .src_decl = block.src_decl, | | |
| 19441 | .namespace = block.namespace, | 19414 | .namespace = block.namespace, |
| 19442 | .instructions = .{}, | 19415 | .instructions = .{}, |
| 19443 | .label = &labeled_block.label, | 19416 | .label = &labeled_block.label, |
| 19444 | .inlining = block.inlining, | 19417 | .inlining = block.inlining, |
| 19445 | .is_comptime = block.is_comptime, | 19418 | .is_comptime = block.is_comptime, |
| | 19419 | .src_base_inst = block.src_base_inst, |
| | 19420 | .type_name_ctx = block.type_name_ctx, |
| 19446 | }, | 19421 | }, |
| 19447 | }; | 19422 | }; |
| 19448 | sema.post_hoc_blocks.putAssumeCapacityNoClobber(new_block_inst, labeled_block); | 19423 | sema.post_hoc_blocks.putAssumeCapacityNoClobber(new_block_inst, labeled_block); |
| ... | @@ -19471,17 +19446,17 @@ fn addRuntimeBreak(sema: *Sema, child_block: *Block, block_inst: Zir.Inst.Index, | ... | @@ -19471,17 +19446,17 @@ fn addRuntimeBreak(sema: *Sema, child_block: *Block, block_inst: Zir.Inst.Index, |
| 19471 | | 19446 | |
| 19472 | fn zirUnreachable(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void { | 19447 | fn zirUnreachable(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void { |
| 19473 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].@"unreachable"; | 19448 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].@"unreachable"; |
| 19474 | const src = inst_data.src(); | 19449 | const src = block.nodeOffset(inst_data.src_node); |
| 19475 | | 19450 | |
| 19476 | if (block.is_comptime) { | 19451 | if (block.is_comptime) { |
| 19477 | return sema.fail(block, src, "reached unreachable code", .{}); | 19452 | return sema.fail(block, src, "reached unreachable code", .{}); |
| 19478 | } | 19453 | } |
| 19479 | // TODO Add compile error for @optimizeFor occurring too late in a scope. | 19454 | // TODO Add compile error for @optimizeFor occurring too late in a scope. |
| 19480 | block.addUnreachable(src, true) catch |err| switch (err) { | 19455 | sema.analyzeUnreachable(block, src, true) catch |err| switch (err) { |
| 19481 | error.AnalysisFail => { | 19456 | error.AnalysisFail => { |
| 19482 | const msg = sema.err orelse return err; | 19457 | const msg = sema.err orelse return err; |
| 19483 | if (!mem.eql(u8, msg.msg, "runtime safety check not allowed in naked function")) return err; | 19458 | if (!mem.eql(u8, msg.msg, "runtime safety check not allowed in naked function")) return err; |
| 19484 | try sema.errNote(block, src, msg, "the end of a naked function is implicitly unreachable", .{}); | 19459 | try sema.errNote(src, msg, "the end of a naked function is implicitly unreachable", .{}); |
| 19485 | return err; | 19460 | return err; |
| 19486 | }, | 19461 | }, |
| 19487 | else => |e| return e, | 19462 | else => |e| return e, |
| ... | @@ -19495,13 +19470,13 @@ fn zirRetErrValue( | ... | @@ -19495,13 +19470,13 @@ fn zirRetErrValue( |
| 19495 | ) CompileError!void { | 19470 | ) CompileError!void { |
| 19496 | const mod = sema.mod; | 19471 | const mod = sema.mod; |
| 19497 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].str_tok; | 19472 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].str_tok; |
| | 19473 | const src = block.tokenOffset(inst_data.src_tok); |
| 19498 | const err_name = try mod.intern_pool.getOrPutString( | 19474 | const err_name = try mod.intern_pool.getOrPutString( |
| 19499 | sema.gpa, | 19475 | sema.gpa, |
| 19500 | inst_data.get(sema.code), | 19476 | inst_data.get(sema.code), |
| 19501 | .no_embedded_nulls, | 19477 | .no_embedded_nulls, |
| 19502 | ); | 19478 | ); |
| 19503 | _ = try mod.getErrorValue(err_name); | 19479 | _ = try mod.getErrorValue(err_name); |
| 19504 | const src = inst_data.src(); | | |
| 19505 | // Return the error code from the function. | 19480 | // Return the error code from the function. |
| 19506 | const error_set_type = try mod.singleErrorSetType(err_name); | 19481 | const error_set_type = try mod.singleErrorSetType(err_name); |
| 19507 | const result_inst = Air.internedToRef((try mod.intern(.{ .err = .{ | 19482 | const result_inst = Air.internedToRef((try mod.intern(.{ .err = .{ |
| ... | @@ -19521,38 +19496,38 @@ fn zirRetImplicit( | ... | @@ -19521,38 +19496,38 @@ fn zirRetImplicit( |
| 19521 | | 19496 | |
| 19522 | const mod = sema.mod; | 19497 | const mod = sema.mod; |
| 19523 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_tok; | 19498 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_tok; |
| 19524 | const r_brace_src = inst_data.src(); | 19499 | const r_brace_src = block.tokenOffset(inst_data.src_tok); |
| 19525 | if (block.inlining == null and sema.func_is_naked) { | 19500 | if (block.inlining == null and sema.func_is_naked) { |
| 19526 | assert(!block.is_comptime); | 19501 | assert(!block.is_comptime); |
| 19527 | if (block.wantSafety()) { | 19502 | if (block.wantSafety()) { |
| 19528 | // Calling a safety function from a naked function would not be legal. | 19503 | // Calling a safety function from a naked function would not be legal. |
| 19529 | _ = try block.addNoOp(.trap); | 19504 | _ = try block.addNoOp(.trap); |
| 19530 | } else { | 19505 | } else { |
| 19531 | try block.addUnreachable(r_brace_src, false); | 19506 | try sema.analyzeUnreachable(block, r_brace_src, false); |
| 19532 | } | 19507 | } |
| 19533 | return; | 19508 | return; |
| 19534 | } | 19509 | } |
| 19535 | | 19510 | |
| 19536 | const operand = try sema.resolveInst(inst_data.operand); | 19511 | const operand = try sema.resolveInst(inst_data.operand); |
| 19537 | const ret_ty_src: LazySrcLoc = .{ .node_offset_fn_type_ret_ty = 0 }; | 19512 | const ret_ty_src = block.src(.{ .node_offset_fn_type_ret_ty = 0 }); |
| 19538 | const base_tag = sema.fn_ret_ty.baseZigTypeTag(mod); | 19513 | const base_tag = sema.fn_ret_ty.baseZigTypeTag(mod); |
| 19539 | if (base_tag == .NoReturn) { | 19514 | if (base_tag == .NoReturn) { |
| 19540 | const msg = msg: { | 19515 | const msg = msg: { |
| 19541 | const msg = try sema.errMsg(block, ret_ty_src, "function declared '{}' implicitly returns", .{ | 19516 | const msg = try sema.errMsg(ret_ty_src, "function declared '{}' implicitly returns", .{ |
| 19542 | sema.fn_ret_ty.fmt(mod), | 19517 | sema.fn_ret_ty.fmt(mod), |
| 19543 | }); | 19518 | }); |
| 19544 | errdefer msg.destroy(sema.gpa); | 19519 | errdefer msg.destroy(sema.gpa); |
| 19545 | try sema.errNote(block, r_brace_src, msg, "control flow reaches end of body here", .{}); | 19520 | try sema.errNote(r_brace_src, msg, "control flow reaches end of body here", .{}); |
| 19546 | break :msg msg; | 19521 | break :msg msg; |
| 19547 | }; | 19522 | }; |
| 19548 | return sema.failWithOwnedErrorMsg(block, msg); | 19523 | return sema.failWithOwnedErrorMsg(block, msg); |
| 19549 | } else if (base_tag != .Void) { | 19524 | } else if (base_tag != .Void) { |
| 19550 | const msg = msg: { | 19525 | const msg = msg: { |
| 19551 | const msg = try sema.errMsg(block, ret_ty_src, "function with non-void return type '{}' implicitly returns", .{ | 19526 | const msg = try sema.errMsg(ret_ty_src, "function with non-void return type '{}' implicitly returns", .{ |
| 19552 | sema.fn_ret_ty.fmt(mod), | 19527 | sema.fn_ret_ty.fmt(mod), |
| 19553 | }); | 19528 | }); |
| 19554 | errdefer msg.destroy(sema.gpa); | 19529 | errdefer msg.destroy(sema.gpa); |
| 19555 | try sema.errNote(block, r_brace_src, msg, "control flow reaches end of body here", .{}); | 19530 | try sema.errNote(r_brace_src, msg, "control flow reaches end of body here", .{}); |
| 19556 | break :msg msg; | 19531 | break :msg msg; |
| 19557 | }; | 19532 | }; |
| 19558 | return sema.failWithOwnedErrorMsg(block, msg); | 19533 | return sema.failWithOwnedErrorMsg(block, msg); |
| ... | @@ -19567,9 +19542,9 @@ fn zirRetNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!voi | ... | @@ -19567,9 +19542,9 @@ fn zirRetNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!voi |
| 19567 | | 19542 | |
| 19568 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; | 19543 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 19569 | const operand = try sema.resolveInst(inst_data.operand); | 19544 | const operand = try sema.resolveInst(inst_data.operand); |
| 19570 | const src = inst_data.src(); | 19545 | const src = block.nodeOffset(inst_data.src_node); |
| 19571 | | 19546 | |
| 19572 | 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 })); |
| 19573 | } | 19548 | } |
| 19574 | | 19549 | |
| 19575 | fn zirRetLoad(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void { | 19550 | fn zirRetLoad(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void { |
| ... | @@ -19577,12 +19552,12 @@ fn zirRetLoad(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!voi | ... | @@ -19577,12 +19552,12 @@ fn zirRetLoad(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!voi |
| 19577 | defer tracy.end(); | 19552 | defer tracy.end(); |
| 19578 | | 19553 | |
| 19579 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; | 19554 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 19580 | const src = inst_data.src(); | 19555 | const src = block.nodeOffset(inst_data.src_node); |
| 19581 | const ret_ptr = try sema.resolveInst(inst_data.operand); | 19556 | const ret_ptr = try sema.resolveInst(inst_data.operand); |
| 19582 | | 19557 | |
| 19583 | if (block.is_comptime or block.inlining != null or sema.func_is_naked) { | 19558 | if (block.is_comptime or block.inlining != null or sema.func_is_naked) { |
| 19584 | const operand = try sema.analyzeLoad(block, src, ret_ptr, src); | 19559 | const operand = try sema.analyzeLoad(block, src, ret_ptr, src); |
| 19585 | return sema.analyzeRet(block, operand, src, .{ .node_offset_return_operand = inst_data.src_node }); | 19560 | return sema.analyzeRet(block, operand, src, block.src(.{ .node_offset_return_operand = inst_data.src_node })); |
| 19586 | } | 19561 | } |
| 19587 | | 19562 | |
| 19588 | if (sema.wantErrorReturnTracing(sema.fn_ret_ty)) { | 19563 | if (sema.wantErrorReturnTracing(sema.fn_ret_ty)) { |
| ... | @@ -19676,7 +19651,7 @@ fn zirSaveErrRetIndex(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE | ... | @@ -19676,7 +19651,7 @@ fn zirSaveErrRetIndex(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE |
| 19676 | | 19651 | |
| 19677 | fn zirRestoreErrRetIndex(sema: *Sema, start_block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!void { | 19652 | fn zirRestoreErrRetIndex(sema: *Sema, start_block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!void { |
| 19678 | const extra = sema.code.extraData(Zir.Inst.RestoreErrRetIndex, extended.operand).data; | 19653 | const extra = sema.code.extraData(Zir.Inst.RestoreErrRetIndex, extended.operand).data; |
| 19679 | return sema.restoreErrRetIndex(start_block, extra.src(), extra.block, extra.operand); | 19654 | return sema.restoreErrRetIndex(start_block, start_block.nodeOffset(extra.src_node), extra.block, extra.operand); |
| 19680 | } | 19655 | } |
| 19681 | | 19656 | |
| 19682 | /// If `operand` is non-error (or is `none`), restores the error return trace to | 19657 | /// If `operand` is non-error (or is `none`), restores the error return trace to |
| ... | @@ -19795,9 +19770,7 @@ fn analyzeRet( | ... | @@ -19795,9 +19770,7 @@ fn analyzeRet( |
| 19795 | inlining.comptime_result = operand; | 19770 | inlining.comptime_result = operand; |
| 19796 | | 19771 | |
| 19797 | if (sema.fn_ret_ty.isError(mod) and ret_val.getErrorName(mod) != .none) { | 19772 | if (sema.fn_ret_ty.isError(mod) and ret_val.getErrorName(mod) != .none) { |
| 19798 | const src_decl = mod.declPtr(block.src_decl); | 19773 | try sema.comptime_err_ret_trace.append(src); |
| 19799 | const src_loc = src_decl.toSrcLoc(src, mod); | | |
| 19800 | try sema.comptime_err_ret_trace.append(src_loc); | | |
| 19801 | } | 19774 | } |
| 19802 | return error.ComptimeReturn; | 19775 | return error.ComptimeReturn; |
| 19803 | } | 19776 | } |
| ... | @@ -19811,10 +19784,10 @@ fn analyzeRet( | ... | @@ -19811,10 +19784,10 @@ fn analyzeRet( |
| 19811 | return sema.fail(block, src, "function called at runtime cannot return value at comptime", .{}); | 19784 | return sema.fail(block, src, "function called at runtime cannot return value at comptime", .{}); |
| 19812 | } else if (sema.func_is_naked) { | 19785 | } else if (sema.func_is_naked) { |
| 19813 | const msg = msg: { | 19786 | const msg = msg: { |
| 19814 | const msg = try sema.errMsg(block, src, "cannot return from naked function", .{}); | 19787 | const msg = try sema.errMsg(src, "cannot return from naked function", .{}); |
| 19815 | errdefer msg.destroy(sema.gpa); | 19788 | errdefer msg.destroy(sema.gpa); |
| 19816 | | 19789 | |
| 19817 | try sema.errNote(block, src, msg, "can only return using assembly", .{}); | 19790 | try sema.errNote(src, msg, "can only return using assembly", .{}); |
| 19818 | break :msg msg; | 19791 | break :msg msg; |
| 19819 | }; | 19792 | }; |
| 19820 | return sema.failWithOwnedErrorMsg(block, msg); | 19793 | return sema.failWithOwnedErrorMsg(block, msg); |
| ... | @@ -19850,18 +19823,18 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air | ... | @@ -19850,18 +19823,18 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 19850 | const mod = sema.mod; | 19823 | const mod = sema.mod; |
| 19851 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].ptr_type; | 19824 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].ptr_type; |
| 19852 | const extra = sema.code.extraData(Zir.Inst.PtrType, inst_data.payload_index); | 19825 | const extra = sema.code.extraData(Zir.Inst.PtrType, inst_data.payload_index); |
| 19853 | const elem_ty_src: LazySrcLoc = .{ .node_offset_ptr_elem = extra.data.src_node }; | 19826 | const elem_ty_src = block.src(.{ .node_offset_ptr_elem = extra.data.src_node }); |
| 19854 | const sentinel_src: LazySrcLoc = .{ .node_offset_ptr_sentinel = extra.data.src_node }; | 19827 | const sentinel_src = block.src(.{ .node_offset_ptr_sentinel = extra.data.src_node }); |
| 19855 | const align_src: LazySrcLoc = .{ .node_offset_ptr_align = extra.data.src_node }; | 19828 | const align_src = block.src(.{ .node_offset_ptr_align = extra.data.src_node }); |
| 19856 | const addrspace_src: LazySrcLoc = .{ .node_offset_ptr_addrspace = extra.data.src_node }; | 19829 | const addrspace_src = block.src(.{ .node_offset_ptr_addrspace = extra.data.src_node }); |
| 19857 | const bitoffset_src: LazySrcLoc = .{ .node_offset_ptr_bitoffset = extra.data.src_node }; | 19830 | const bitoffset_src = block.src(.{ .node_offset_ptr_bitoffset = extra.data.src_node }); |
| 19858 | const hostsize_src: LazySrcLoc = .{ .node_offset_ptr_hostsize = extra.data.src_node }; | 19831 | const hostsize_src = block.src(.{ .node_offset_ptr_hostsize = extra.data.src_node }); |
| 19859 | | 19832 | |
| 19860 | const elem_ty = blk: { | 19833 | const elem_ty = blk: { |
| 19861 | const air_inst = try sema.resolveInst(extra.data.elem_type); | 19834 | const air_inst = try sema.resolveInst(extra.data.elem_type); |
| 19862 | const ty = sema.analyzeAsType(block, elem_ty_src, air_inst) catch |err| { | 19835 | const ty = sema.analyzeAsType(block, elem_ty_src, air_inst) catch |err| { |
| 19863 | if (err == error.AnalysisFail and sema.err != null and sema.typeOf(air_inst).isSinglePointer(mod)) { | 19836 | if (err == error.AnalysisFail and sema.err != null and sema.typeOf(air_inst).isSinglePointer(mod)) { |
| 19864 | try sema.errNote(block, elem_ty_src, sema.err.?, "use '.*' to dereference pointer", .{}); | 19837 | try sema.errNote(elem_ty_src, sema.err.?, "use '.*' to dereference pointer", .{}); |
| 19865 | } | 19838 | } |
| 19866 | return err; | 19839 | return err; |
| 19867 | }; | 19840 | }; |
| ... | @@ -19953,11 +19926,10 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air | ... | @@ -19953,11 +19926,10 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 19953 | } else if (inst_data.size == .C) { | 19926 | } else if (inst_data.size == .C) { |
| 19954 | if (!try sema.validateExternType(elem_ty, .other)) { | 19927 | if (!try sema.validateExternType(elem_ty, .other)) { |
| 19955 | const msg = msg: { | 19928 | const msg = msg: { |
| 19956 | const msg = try sema.errMsg(block, elem_ty_src, "C pointers cannot point to non-C-ABI-compatible type '{}'", .{elem_ty.fmt(mod)}); | 19929 | const msg = try sema.errMsg(elem_ty_src, "C pointers cannot point to non-C-ABI-compatible type '{}'", .{elem_ty.fmt(mod)}); |
| 19957 | errdefer msg.destroy(sema.gpa); | 19930 | errdefer msg.destroy(sema.gpa); |
| 19958 | | 19931 | |
| 19959 | const src_decl = mod.declPtr(block.src_decl); | 19932 | try sema.explainWhyTypeIsNotExtern(msg, elem_ty_src, elem_ty, .other); |
| 19960 | try sema.explainWhyTypeIsNotExtern(msg, src_decl.toSrcLoc(elem_ty_src, mod), elem_ty, .other); | | |
| 19961 | | 19933 | |
| 19962 | try sema.addDeclaredHereNote(msg, elem_ty); | 19934 | try sema.addDeclaredHereNote(msg, elem_ty); |
| 19963 | break :msg msg; | 19935 | break :msg msg; |
| ... | @@ -19971,10 +19943,9 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air | ... | @@ -19971,10 +19943,9 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 19971 | | 19943 | |
| 19972 | if (host_size != 0 and !try sema.validatePackedType(elem_ty)) { | 19944 | if (host_size != 0 and !try sema.validatePackedType(elem_ty)) { |
| 19973 | return sema.failWithOwnedErrorMsg(block, msg: { | 19945 | return sema.failWithOwnedErrorMsg(block, msg: { |
| 19974 | const msg = try sema.errMsg(block, elem_ty_src, "bit-pointer cannot refer to value of type '{}'", .{elem_ty.fmt(mod)}); | 19946 | const msg = try sema.errMsg(elem_ty_src, "bit-pointer cannot refer to value of type '{}'", .{elem_ty.fmt(mod)}); |
| 19975 | errdefer msg.destroy(sema.gpa); | 19947 | errdefer msg.destroy(sema.gpa); |
| 19976 | const src_decl = mod.declPtr(block.src_decl); | 19948 | try sema.explainWhyTypeIsNotPacked(msg, elem_ty_src, elem_ty); |
| 19977 | try sema.explainWhyTypeIsNotPacked(msg, src_decl.toSrcLoc(elem_ty_src, mod), elem_ty); | | |
| 19978 | break :msg msg; | 19949 | break :msg msg; |
| 19979 | }); | 19950 | }); |
| 19980 | } | 19951 | } |
| ... | @@ -20003,8 +19974,8 @@ fn zirStructInitEmpty(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE | ... | @@ -20003,8 +19974,8 @@ fn zirStructInitEmpty(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE |
| 20003 | defer tracy.end(); | 19974 | defer tracy.end(); |
| 20004 | | 19975 | |
| 20005 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; | 19976 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 20006 | const src = inst_data.src(); | 19977 | const src = block.nodeOffset(inst_data.src_node); |
| 20007 | const ty_src: LazySrcLoc = .{ .node_offset_init_ty = inst_data.src_node }; | 19978 | const ty_src = block.src(.{ .node_offset_init_ty = inst_data.src_node }); |
| 20008 | const obj_ty = try sema.resolveType(block, ty_src, inst_data.operand); | 19979 | const obj_ty = try sema.resolveType(block, ty_src, inst_data.operand); |
| 20009 | const mod = sema.mod; | 19980 | const mod = sema.mod; |
| 20010 | | 19981 | |
| ... | @@ -20023,7 +19994,7 @@ fn zirStructInitEmptyResult(sema: *Sema, block: *Block, inst: Zir.Inst.Index, is | ... | @@ -20023,7 +19994,7 @@ fn zirStructInitEmptyResult(sema: *Sema, block: *Block, inst: Zir.Inst.Index, is |
| 20023 | | 19994 | |
| 20024 | const mod = sema.mod; | 19995 | const mod = sema.mod; |
| 20025 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; | 19996 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 20026 | const src = inst_data.src(); | 19997 | const src = block.nodeOffset(inst_data.src_node); |
| 20027 | const ty_operand = sema.resolveType(block, src, inst_data.operand) catch |err| switch (err) { | 19998 | const ty_operand = sema.resolveType(block, src, inst_data.operand) catch |err| switch (err) { |
| 20028 | // Generic poison means this is an untyped anonymous empty struct init | 19999 | // Generic poison means this is an untyped anonymous empty struct init |
| 20029 | error.GenericPoison => return .empty_struct, | 20000 | error.GenericPoison => return .empty_struct, |
| ... | @@ -20098,9 +20069,9 @@ fn arrayInitEmpty(sema: *Sema, block: *Block, src: LazySrcLoc, obj_ty: Type) Com | ... | @@ -20098,9 +20069,9 @@ fn arrayInitEmpty(sema: *Sema, block: *Block, src: LazySrcLoc, obj_ty: Type) Com |
| 20098 | | 20069 | |
| 20099 | fn zirUnionInit(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 20070 | fn zirUnionInit(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 20100 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 20071 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 20101 | const ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 20072 | const ty_src = block.builtinCallArgSrc(inst_data.src_node, 0); |
| 20102 | const field_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; | 20073 | const field_src = block.builtinCallArgSrc(inst_data.src_node, 1); |
| 20103 | const init_src: LazySrcLoc = .{ .node_offset_builtin_call_arg2 = inst_data.src_node }; | 20074 | const init_src = block.builtinCallArgSrc(inst_data.src_node, 2); |
| 20104 | const extra = sema.code.extraData(Zir.Inst.UnionInit, inst_data.payload_index).data; | 20075 | const extra = sema.code.extraData(Zir.Inst.UnionInit, inst_data.payload_index).data; |
| 20105 | const union_ty = try sema.resolveType(block, ty_src, extra.union_type); | 20076 | const union_ty = try sema.resolveType(block, ty_src, extra.union_type); |
| 20106 | if (union_ty.zigTypeTag(sema.mod) != .Union) { | 20077 | if (union_ty.zigTypeTag(sema.mod) != .Union) { |
| ... | @@ -20155,7 +20126,7 @@ fn zirStructInit( | ... | @@ -20155,7 +20126,7 @@ fn zirStructInit( |
| 20155 | const zir_datas = sema.code.instructions.items(.data); | 20126 | const zir_datas = sema.code.instructions.items(.data); |
| 20156 | const inst_data = zir_datas[@intFromEnum(inst)].pl_node; | 20127 | const inst_data = zir_datas[@intFromEnum(inst)].pl_node; |
| 20157 | const extra = sema.code.extraData(Zir.Inst.StructInit, inst_data.payload_index); | 20128 | const extra = sema.code.extraData(Zir.Inst.StructInit, inst_data.payload_index); |
| 20158 | const src = inst_data.src(); | 20129 | const src = block.nodeOffset(inst_data.src_node); |
| 20159 | | 20130 | |
| 20160 | const mod = sema.mod; | 20131 | const mod = sema.mod; |
| 20161 | const ip = &mod.intern_pool; | 20132 | const ip = &mod.intern_pool; |
| ... | @@ -20194,7 +20165,7 @@ fn zirStructInit( | ... | @@ -20194,7 +20165,7 @@ fn zirStructInit( |
| 20194 | extra_index = item.end; | 20165 | extra_index = item.end; |
| 20195 | | 20166 | |
| 20196 | const field_type_data = zir_datas[@intFromEnum(item.data.field_type)].pl_node; | 20167 | const field_type_data = zir_datas[@intFromEnum(item.data.field_type)].pl_node; |
| 20197 | const field_src: LazySrcLoc = .{ .node_offset_initializer = field_type_data.src_node }; | 20168 | const field_src = block.src(.{ .node_offset_initializer = field_type_data.src_node }); |
| 20198 | const field_type_extra = sema.code.extraData(Zir.Inst.FieldType, field_type_data.payload_index).data; | 20169 | const field_type_extra = sema.code.extraData(Zir.Inst.FieldType, field_type_data.payload_index).data; |
| 20199 | const field_name = try ip.getOrPutString( | 20170 | const field_name = try ip.getOrPutString( |
| 20200 | gpa, | 20171 | gpa, |
| ... | @@ -20235,7 +20206,7 @@ fn zirStructInit( | ... | @@ -20235,7 +20206,7 @@ fn zirStructInit( |
| 20235 | const item = sema.code.extraData(Zir.Inst.StructInit.Item, extra.end); | 20206 | const item = sema.code.extraData(Zir.Inst.StructInit.Item, extra.end); |
| 20236 | | 20207 | |
| 20237 | const field_type_data = zir_datas[@intFromEnum(item.data.field_type)].pl_node; | 20208 | const field_type_data = zir_datas[@intFromEnum(item.data.field_type)].pl_node; |
| 20238 | const field_src: LazySrcLoc = .{ .node_offset_initializer = field_type_data.src_node }; | 20209 | const field_src = block.src(.{ .node_offset_initializer = field_type_data.src_node }); |
| 20239 | const field_type_extra = sema.code.extraData(Zir.Inst.FieldType, field_type_data.payload_index).data; | 20210 | const field_type_extra = sema.code.extraData(Zir.Inst.FieldType, field_type_data.payload_index).data; |
| 20240 | const field_name = try ip.getOrPutString( | 20211 | const field_name = try ip.getOrPutString( |
| 20241 | gpa, | 20212 | gpa, |
| ... | @@ -20249,7 +20220,7 @@ fn zirStructInit( | ... | @@ -20249,7 +20220,7 @@ fn zirStructInit( |
| 20249 | | 20220 | |
| 20250 | if (field_ty.zigTypeTag(mod) == .NoReturn) { | 20221 | if (field_ty.zigTypeTag(mod) == .NoReturn) { |
| 20251 | return sema.failWithOwnedErrorMsg(block, msg: { | 20222 | return sema.failWithOwnedErrorMsg(block, msg: { |
| 20252 | const msg = try sema.errMsg(block, src, "cannot initialize 'noreturn' field of union", .{}); | 20223 | const msg = try sema.errMsg(src, "cannot initialize 'noreturn' field of union", .{}); |
| 20253 | errdefer msg.destroy(sema.gpa); | 20224 | errdefer msg.destroy(sema.gpa); |
| 20254 | | 20225 | |
| 20255 | try sema.addFieldErrNote(resolved_ty, field_index, msg, "field '{}' declared here", .{ | 20226 | try sema.addFieldErrNote(resolved_ty, field_index, msg, "field '{}' declared here", .{ |
| ... | @@ -20327,16 +20298,12 @@ fn finishStructInit( | ... | @@ -20327,16 +20298,12 @@ fn finishStructInit( |
| 20327 | for (0..anon_struct.types.len) |i| { | 20298 | for (0..anon_struct.types.len) |i| { |
| 20328 | if (field_inits[i] != .none) { | 20299 | if (field_inits[i] != .none) { |
| 20329 | // Coerce the init value to the field type. | 20300 | // Coerce the init value to the field type. |
| | 20301 | const field_src = block.src(.{ .init_elem = .{ |
| | 20302 | .init_node_offset = init_src.offset.node_offset.x, |
| | 20303 | .elem_index = @intCast(i), |
| | 20304 | } }); |
| 20330 | const field_ty = Type.fromInterned(anon_struct.types.get(ip)[i]); | 20305 | const field_ty = Type.fromInterned(anon_struct.types.get(ip)[i]); |
| 20331 | field_inits[i] = sema.coerce(block, field_ty, field_inits[i], .unneeded) catch |err| switch (err) { | 20306 | field_inits[i] = try sema.coerce(block, field_ty, field_inits[i], field_src); |
| 20332 | error.NeededSourceLocation => { | | |
| 20333 | const decl = mod.declPtr(block.src_decl); | | |
| 20334 | const field_src = mod.initSrc(init_src.node_offset.x, decl, i); | | |
| 20335 | _ = try sema.coerce(block, field_ty, field_inits[i], field_src); | | |
| 20336 | unreachable; | | |
| 20337 | }, | | |
| 20338 | else => |e| return e, | | |
| 20339 | }; | | |
| 20340 | continue; | 20307 | continue; |
| 20341 | } | 20308 | } |
| 20342 | | 20309 | |
| ... | @@ -20346,18 +20313,18 @@ fn finishStructInit( | ... | @@ -20346,18 +20313,18 @@ fn finishStructInit( |
| 20346 | if (anon_struct.names.len == 0) { | 20313 | if (anon_struct.names.len == 0) { |
| 20347 | const template = "missing tuple field with index {d}"; | 20314 | const template = "missing tuple field with index {d}"; |
| 20348 | if (root_msg) |msg| { | 20315 | if (root_msg) |msg| { |
| 20349 | try sema.errNote(block, init_src, msg, template, .{i}); | 20316 | try sema.errNote(init_src, msg, template, .{i}); |
| 20350 | } else { | 20317 | } else { |
| 20351 | root_msg = try sema.errMsg(block, init_src, template, .{i}); | 20318 | root_msg = try sema.errMsg(init_src, template, .{i}); |
| 20352 | } | 20319 | } |
| 20353 | } else { | 20320 | } else { |
| 20354 | const field_name = anon_struct.names.get(ip)[i]; | 20321 | const field_name = anon_struct.names.get(ip)[i]; |
| 20355 | const template = "missing struct field: {}"; | 20322 | const template = "missing struct field: {}"; |
| 20356 | const args = .{field_name.fmt(ip)}; | 20323 | const args = .{field_name.fmt(ip)}; |
| 20357 | if (root_msg) |msg| { | 20324 | if (root_msg) |msg| { |
| 20358 | try sema.errNote(block, init_src, msg, template, args); | 20325 | try sema.errNote(init_src, msg, template, args); |
| 20359 | } else { | 20326 | } else { |
| 20360 | root_msg = try sema.errMsg(block, init_src, template, args); | 20327 | root_msg = try sema.errMsg(init_src, template, args); |
| 20361 | } | 20328 | } |
| 20362 | } | 20329 | } |
| 20363 | } else { | 20330 | } else { |
| ... | @@ -20370,16 +20337,12 @@ fn finishStructInit( | ... | @@ -20370,16 +20337,12 @@ fn finishStructInit( |
| 20370 | for (0..struct_type.field_types.len) |i| { | 20337 | for (0..struct_type.field_types.len) |i| { |
| 20371 | if (field_inits[i] != .none) { | 20338 | if (field_inits[i] != .none) { |
| 20372 | // Coerce the init value to the field type. | 20339 | // Coerce the init value to the field type. |
| | 20340 | const field_src = block.src(.{ .init_elem = .{ |
| | 20341 | .init_node_offset = init_src.offset.node_offset.x, |
| | 20342 | .elem_index = @intCast(i), |
| | 20343 | } }); |
| 20373 | const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[i]); | 20344 | const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[i]); |
| 20374 | field_inits[i] = sema.coerce(block, field_ty, field_inits[i], init_src) catch |err| switch (err) { | 20345 | field_inits[i] = try sema.coerce(block, field_ty, field_inits[i], field_src); |
| 20375 | error.NeededSourceLocation => { | | |
| 20376 | const decl = mod.declPtr(block.src_decl); | | |
| 20377 | const field_src = mod.initSrc(init_src.node_offset.x, decl, i); | | |
| 20378 | _ = try sema.coerce(block, field_ty, field_inits[i], field_src); | | |
| 20379 | unreachable; | | |
| 20380 | }, | | |
| 20381 | else => |e| return e, | | |
| 20382 | }; | | |
| 20383 | continue; | 20346 | continue; |
| 20384 | } | 20347 | } |
| 20385 | | 20348 | |
| ... | @@ -20392,16 +20355,16 @@ fn finishStructInit( | ... | @@ -20392,16 +20355,16 @@ fn finishStructInit( |
| 20392 | const template = "missing struct field: {}"; | 20355 | const template = "missing struct field: {}"; |
| 20393 | const args = .{field_name.fmt(ip)}; | 20356 | const args = .{field_name.fmt(ip)}; |
| 20394 | if (root_msg) |msg| { | 20357 | if (root_msg) |msg| { |
| 20395 | try sema.errNote(block, init_src, msg, template, args); | 20358 | try sema.errNote(init_src, msg, template, args); |
| 20396 | } else { | 20359 | } else { |
| 20397 | root_msg = try sema.errMsg(block, init_src, template, args); | 20360 | root_msg = try sema.errMsg(init_src, template, args); |
| 20398 | } | 20361 | } |
| 20399 | } else { | 20362 | } else { |
| 20400 | const template = "missing tuple field with index {d}"; | 20363 | const template = "missing tuple field with index {d}"; |
| 20401 | if (root_msg) |msg| { | 20364 | if (root_msg) |msg| { |
| 20402 | try sema.errNote(block, init_src, msg, template, .{i}); | 20365 | try sema.errNote(init_src, msg, template, .{i}); |
| 20403 | } else { | 20366 | } else { |
| 20404 | root_msg = try sema.errMsg(block, init_src, template, .{i}); | 20367 | root_msg = try sema.errMsg(init_src, template, .{i}); |
| 20405 | } | 20368 | } |
| 20406 | } | 20369 | } |
| 20407 | } else { | 20370 | } else { |
| ... | @@ -20413,16 +20376,7 @@ fn finishStructInit( | ... | @@ -20413,16 +20376,7 @@ fn finishStructInit( |
| 20413 | } | 20376 | } |
| 20414 | | 20377 | |
| 20415 | if (root_msg) |msg| { | 20378 | if (root_msg) |msg| { |
| 20416 | if (mod.typeToStruct(struct_ty)) |struct_type| { | 20379 | try sema.addDeclaredHereNote(msg, struct_ty); |
| 20417 | const decl = mod.declPtr(struct_type.decl.unwrap().?); | | |
| 20418 | const fqn = try decl.fullyQualifiedName(mod); | | |
| 20419 | try mod.errNoteNonLazy( | | |
| 20420 | decl.srcLoc(mod), | | |
| 20421 | msg, | | |
| 20422 | "struct '{}' declared here", | | |
| 20423 | .{fqn.fmt(ip)}, | | |
| 20424 | ); | | |
| 20425 | } | | |
| 20426 | root_msg = null; | 20380 | root_msg = null; |
| 20427 | return sema.failWithOwnedErrorMsg(block, msg); | 20381 | return sema.failWithOwnedErrorMsg(block, msg); |
| 20428 | } | 20382 | } |
| ... | @@ -20449,9 +20403,10 @@ fn finishStructInit( | ... | @@ -20449,9 +20403,10 @@ fn finishStructInit( |
| 20449 | }; | 20403 | }; |
| 20450 | | 20404 | |
| 20451 | if (try sema.typeRequiresComptime(struct_ty)) { | 20405 | if (try sema.typeRequiresComptime(struct_ty)) { |
| 20452 | const decl = mod.declPtr(block.src_decl); | 20406 | return sema.failWithNeededComptime(block, block.src(.{ .init_elem = .{ |
| 20453 | const field_src = mod.initSrc(init_src.node_offset.x, decl, runtime_index); | 20407 | .init_node_offset = init_src.offset.node_offset.x, |
| 20454 | return sema.failWithNeededComptime(block, field_src, .{ | 20408 | .elem_index = @intCast(runtime_index), |
| | 20409 | } }), .{ |
| 20455 | .needed_comptime_reason = "initializer of comptime only struct must be comptime-known", | 20410 | .needed_comptime_reason = "initializer of comptime only struct must be comptime-known", |
| 20456 | }); | 20411 | }); |
| 20457 | } | 20412 | } |
| ... | @@ -20479,15 +20434,10 @@ fn finishStructInit( | ... | @@ -20479,15 +20434,10 @@ fn finishStructInit( |
| 20479 | return sema.makePtrConst(block, alloc); | 20434 | return sema.makePtrConst(block, alloc); |
| 20480 | } | 20435 | } |
| 20481 | | 20436 | |
| 20482 | sema.requireRuntimeBlock(block, .unneeded, null) catch |err| switch (err) { | 20437 | try sema.requireRuntimeBlock(block, dest_src, block.src(.{ .init_elem = .{ |
| 20483 | error.NeededSourceLocation => { | 20438 | .init_node_offset = init_src.offset.node_offset.x, |
| 20484 | const decl = mod.declPtr(block.src_decl); | 20439 | .elem_index = @intCast(runtime_index), |
| 20485 | const field_src = mod.initSrc(dest_src.node_offset.x, decl, runtime_index); | 20440 | } })); |
| 20486 | try sema.requireRuntimeBlock(block, dest_src, field_src); | | |
| 20487 | unreachable; | | |
| 20488 | }, | | |
| 20489 | else => |e| return e, | | |
| 20490 | }; | | |
| 20491 | try sema.resolveStructFieldInits(struct_ty); | 20441 | try sema.resolveStructFieldInits(struct_ty); |
| 20492 | try sema.queueFullTypeResolution(struct_ty); | 20442 | try sema.queueFullTypeResolution(struct_ty); |
| 20493 | const struct_val = try block.addAggregateInit(struct_ty, field_inits); | 20443 | const struct_val = try block.addAggregateInit(struct_ty, field_inits); |
| ... | @@ -20500,7 +20450,7 @@ fn zirStructInitAnon( | ... | @@ -20500,7 +20450,7 @@ fn zirStructInitAnon( |
| 20500 | inst: Zir.Inst.Index, | 20450 | inst: Zir.Inst.Index, |
| 20501 | ) CompileError!Air.Inst.Ref { | 20451 | ) CompileError!Air.Inst.Ref { |
| 20502 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 20452 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 20503 | const src = inst_data.src(); | 20453 | const src = block.nodeOffset(inst_data.src_node); |
| 20504 | const extra = sema.code.extraData(Zir.Inst.StructInitAnon, inst_data.payload_index); | 20454 | const extra = sema.code.extraData(Zir.Inst.StructInitAnon, inst_data.payload_index); |
| 20505 | return sema.structInitAnon(block, src, .anon_init, extra.data, extra.end, false); | 20455 | return sema.structInitAnon(block, src, .anon_init, extra.data, extra.end, false); |
| 20506 | } | 20456 | } |
| ... | @@ -20555,9 +20505,11 @@ fn structInitAnon( | ... | @@ -20555,9 +20505,11 @@ fn structInitAnon( |
| 20555 | field_ty.* = sema.typeOf(init).toIntern(); | 20505 | field_ty.* = sema.typeOf(init).toIntern(); |
| 20556 | if (Type.fromInterned(field_ty.*).zigTypeTag(mod) == .Opaque) { | 20506 | if (Type.fromInterned(field_ty.*).zigTypeTag(mod) == .Opaque) { |
| 20557 | const msg = msg: { | 20507 | const msg = msg: { |
| 20558 | const decl = mod.declPtr(block.src_decl); | 20508 | const field_src = block.src(.{ .init_elem = .{ |
| 20559 | const field_src = mod.initSrc(src.node_offset.x, decl, @intCast(i_usize)); | 20509 | .init_node_offset = src.offset.node_offset.x, |
| 20560 | const msg = try sema.errMsg(block, field_src, "opaque types have unknown size and therefore cannot be directly embedded in structs", .{}); | 20510 | .elem_index = @intCast(i_usize), |
| | 20511 | } }); |
| | 20512 | const msg = try sema.errMsg(field_src, "opaque types have unknown size and therefore cannot be directly embedded in structs", .{}); |
| 20561 | errdefer msg.destroy(sema.gpa); | 20513 | errdefer msg.destroy(sema.gpa); |
| 20562 | | 20514 | |
| 20563 | try sema.addDeclaredHereNote(msg, Type.fromInterned(field_ty.*)); | 20515 | try sema.addDeclaredHereNote(msg, Type.fromInterned(field_ty.*)); |
| ... | @@ -20589,15 +20541,10 @@ fn structInitAnon( | ... | @@ -20589,15 +20541,10 @@ fn structInitAnon( |
| 20589 | return sema.addConstantMaybeRef(tuple_val, is_ref); | 20541 | return sema.addConstantMaybeRef(tuple_val, is_ref); |
| 20590 | }; | 20542 | }; |
| 20591 | | 20543 | |
| 20592 | sema.requireRuntimeBlock(block, .unneeded, null) catch |err| switch (err) { | 20544 | try sema.requireRuntimeBlock(block, LazySrcLoc.unneeded, block.src(.{ .init_elem = .{ |
| 20593 | error.NeededSourceLocation => { | 20545 | .init_node_offset = src.offset.node_offset.x, |
| 20594 | const decl = mod.declPtr(block.src_decl); | 20546 | .elem_index = @intCast(runtime_index), |
| 20595 | const field_src = mod.initSrc(src.node_offset.x, decl, runtime_index); | 20547 | } })); |
| 20596 | try sema.requireRuntimeBlock(block, src, field_src); | | |
| 20597 | unreachable; | | |
| 20598 | }, | | |
| 20599 | else => |e| return e, | | |
| 20600 | }; | | |
| 20601 | | 20548 | |
| 20602 | if (is_ref) { | 20549 | if (is_ref) { |
| 20603 | const target = mod.getTarget(); | 20550 | const target = mod.getTarget(); |
| ... | @@ -20652,7 +20599,7 @@ fn zirArrayInit( | ... | @@ -20652,7 +20599,7 @@ fn zirArrayInit( |
| 20652 | const mod = sema.mod; | 20599 | const mod = sema.mod; |
| 20653 | const gpa = sema.gpa; | 20600 | const gpa = sema.gpa; |
| 20654 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 20601 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 20655 | const src = inst_data.src(); | 20602 | const src = block.nodeOffset(inst_data.src_node); |
| 20656 | | 20603 | |
| 20657 | const extra = sema.code.extraData(Zir.Inst.MultiOp, inst_data.payload_index); | 20604 | const extra = sema.code.extraData(Zir.Inst.MultiOp, inst_data.payload_index); |
| 20658 | const args = sema.code.refSlice(extra.end, extra.data.operands_len); | 20605 | const args = sema.code.refSlice(extra.end, extra.data.operands_len); |
| ... | @@ -20676,15 +20623,19 @@ fn zirArrayInit( | ... | @@ -20676,15 +20623,19 @@ fn zirArrayInit( |
| 20676 | const resolved_args = try gpa.alloc(Air.Inst.Ref, final_len); | 20623 | const resolved_args = try gpa.alloc(Air.Inst.Ref, final_len); |
| 20677 | defer gpa.free(resolved_args); | 20624 | defer gpa.free(resolved_args); |
| 20678 | for (resolved_args, 0..) |*dest, i| { | 20625 | for (resolved_args, 0..) |*dest, i| { |
| | 20626 | const elem_src = block.src(.{ .init_elem = .{ |
| | 20627 | .init_node_offset = src.offset.node_offset.x, |
| | 20628 | .elem_index = @intCast(i), |
| | 20629 | } }); |
| 20679 | // Less inits than needed. | 20630 | // Less inits than needed. |
| 20680 | if (i + 2 > args.len) if (is_tuple) { | 20631 | if (i + 2 > args.len) if (is_tuple) { |
| 20681 | const default_val = array_ty.structFieldDefaultValue(i, mod).toIntern(); | 20632 | const default_val = array_ty.structFieldDefaultValue(i, mod).toIntern(); |
| 20682 | if (default_val == .unreachable_value) { | 20633 | if (default_val == .unreachable_value) { |
| 20683 | const template = "missing tuple field with index {d}"; | 20634 | const template = "missing tuple field with index {d}"; |
| 20684 | if (root_msg) |msg| { | 20635 | if (root_msg) |msg| { |
| 20685 | try sema.errNote(block, src, msg, template, .{i}); | 20636 | try sema.errNote(src, msg, template, .{i}); |
| 20686 | } else { | 20637 | } else { |
| 20687 | root_msg = try sema.errMsg(block, src, template, .{i}); | 20638 | root_msg = try sema.errMsg(src, template, .{i}); |
| 20688 | } | 20639 | } |
| 20689 | } else { | 20640 | } else { |
| 20690 | dest.* = Air.internedToRef(default_val); | 20641 | dest.* = Air.internedToRef(default_val); |
| ... | @@ -20701,29 +20652,17 @@ fn zirArrayInit( | ... | @@ -20701,29 +20652,17 @@ fn zirArrayInit( |
| 20701 | array_ty.structFieldType(i, mod) | 20652 | array_ty.structFieldType(i, mod) |
| 20702 | else | 20653 | else |
| 20703 | array_ty.elemType2(mod); | 20654 | array_ty.elemType2(mod); |
| 20704 | dest.* = sema.coerce(block, elem_ty, resolved_arg, .unneeded) catch |err| switch (err) { | 20655 | dest.* = try sema.coerce(block, elem_ty, resolved_arg, elem_src); |
| 20705 | error.NeededSourceLocation => { | | |
| 20706 | const decl = mod.declPtr(block.src_decl); | | |
| 20707 | const elem_src = mod.initSrc(src.node_offset.x, decl, i); | | |
| 20708 | _ = try sema.coerce(block, elem_ty, resolved_arg, elem_src); | | |
| 20709 | unreachable; | | |
| 20710 | }, | | |
| 20711 | else => return err, | | |
| 20712 | }; | | |
| 20713 | if (is_tuple) { | 20656 | if (is_tuple) { |
| 20714 | if (array_ty.structFieldIsComptime(i, mod)) | 20657 | if (array_ty.structFieldIsComptime(i, mod)) |
| 20715 | try sema.resolveStructFieldInits(array_ty); | 20658 | try sema.resolveStructFieldInits(array_ty); |
| 20716 | if (try array_ty.structFieldValueComptime(mod, i)) |field_val| { | 20659 | if (try array_ty.structFieldValueComptime(mod, i)) |field_val| { |
| 20717 | const init_val = try sema.resolveValue(dest.*) orelse { | 20660 | const init_val = try sema.resolveValue(dest.*) orelse { |
| 20718 | const decl = mod.declPtr(block.src_decl); | | |
| 20719 | const elem_src = mod.initSrc(src.node_offset.x, decl, i); | | |
| 20720 | return sema.failWithNeededComptime(block, elem_src, .{ | 20661 | return sema.failWithNeededComptime(block, elem_src, .{ |
| 20721 | .needed_comptime_reason = "value stored in comptime field must be comptime-known", | 20662 | .needed_comptime_reason = "value stored in comptime field must be comptime-known", |
| 20722 | }); | 20663 | }); |
| 20723 | }; | 20664 | }; |
| 20724 | if (!field_val.eql(init_val, elem_ty, mod)) { | 20665 | if (!field_val.eql(init_val, elem_ty, mod)) { |
| 20725 | const decl = mod.declPtr(block.src_decl); | | |
| 20726 | const elem_src = mod.initSrc(src.node_offset.x, decl, i); | | |
| 20727 | return sema.failWithInvalidComptimeFieldStore(block, elem_src, array_ty, i); | 20666 | return sema.failWithInvalidComptimeFieldStore(block, elem_src, array_ty, i); |
| 20728 | } | 20667 | } |
| 20729 | } | 20668 | } |
| ... | @@ -20756,15 +20695,10 @@ fn zirArrayInit( | ... | @@ -20756,15 +20695,10 @@ fn zirArrayInit( |
| 20756 | return sema.addConstantMaybeRef(result_val.toIntern(), is_ref); | 20695 | return sema.addConstantMaybeRef(result_val.toIntern(), is_ref); |
| 20757 | }; | 20696 | }; |
| 20758 | | 20697 | |
| 20759 | sema.requireRuntimeBlock(block, .unneeded, null) catch |err| switch (err) { | 20698 | try sema.requireRuntimeBlock(block, LazySrcLoc.unneeded, block.src(.{ .init_elem = .{ |
| 20760 | error.NeededSourceLocation => { | 20699 | .init_node_offset = src.offset.node_offset.x, |
| 20761 | const decl = mod.declPtr(block.src_decl); | 20700 | .elem_index = runtime_index, |
| 20762 | const elem_src = mod.initSrc(src.node_offset.x, decl, runtime_index); | 20701 | } })); |
| 20763 | try sema.requireRuntimeBlock(block, src, elem_src); | | |
| 20764 | unreachable; | | |
| 20765 | }, | | |
| 20766 | else => return err, | | |
| 20767 | }; | | |
| 20768 | try sema.queueFullTypeResolution(array_ty); | 20702 | try sema.queueFullTypeResolution(array_ty); |
| 20769 | | 20703 | |
| 20770 | if (is_ref) { | 20704 | if (is_ref) { |
| ... | @@ -20815,7 +20749,7 @@ fn zirArrayInitAnon( | ... | @@ -20815,7 +20749,7 @@ fn zirArrayInitAnon( |
| 20815 | inst: Zir.Inst.Index, | 20749 | inst: Zir.Inst.Index, |
| 20816 | ) CompileError!Air.Inst.Ref { | 20750 | ) CompileError!Air.Inst.Ref { |
| 20817 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 20751 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 20818 | const src = inst_data.src(); | 20752 | const src = block.nodeOffset(inst_data.src_node); |
| 20819 | const extra = sema.code.extraData(Zir.Inst.MultiOp, inst_data.payload_index); | 20753 | const extra = sema.code.extraData(Zir.Inst.MultiOp, inst_data.payload_index); |
| 20820 | const operands = sema.code.refSlice(extra.end, extra.data.operands_len); | 20754 | const operands = sema.code.refSlice(extra.end, extra.data.operands_len); |
| 20821 | return sema.arrayInitAnon(block, src, operands, false); | 20755 | return sema.arrayInitAnon(block, src, operands, false); |
| ... | @@ -20843,7 +20777,7 @@ fn arrayInitAnon( | ... | @@ -20843,7 +20777,7 @@ fn arrayInitAnon( |
| 20843 | types[i] = sema.typeOf(elem).toIntern(); | 20777 | types[i] = sema.typeOf(elem).toIntern(); |
| 20844 | if (Type.fromInterned(types[i]).zigTypeTag(mod) == .Opaque) { | 20778 | if (Type.fromInterned(types[i]).zigTypeTag(mod) == .Opaque) { |
| 20845 | const msg = msg: { | 20779 | const msg = msg: { |
| 20846 | const msg = try sema.errMsg(block, operand_src, "opaque types have unknown size and therefore cannot be directly embedded in structs", .{}); | 20780 | const msg = try sema.errMsg(operand_src, "opaque types have unknown size and therefore cannot be directly embedded in structs", .{}); |
| 20847 | errdefer msg.destroy(gpa); | 20781 | errdefer msg.destroy(gpa); |
| 20848 | | 20782 | |
| 20849 | try sema.addDeclaredHereNote(msg, Type.fromInterned(types[i])); | 20783 | try sema.addDeclaredHereNote(msg, Type.fromInterned(types[i])); |
| ... | @@ -20914,8 +20848,8 @@ fn addConstantMaybeRef(sema: *Sema, val: InternPool.Index, is_ref: bool) !Air.In | ... | @@ -20914,8 +20848,8 @@ fn addConstantMaybeRef(sema: *Sema, val: InternPool.Index, is_ref: bool) !Air.In |
| 20914 | fn zirFieldTypeRef(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 20848 | fn zirFieldTypeRef(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 20915 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 20849 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 20916 | const extra = sema.code.extraData(Zir.Inst.FieldTypeRef, inst_data.payload_index).data; | 20850 | const extra = sema.code.extraData(Zir.Inst.FieldTypeRef, inst_data.payload_index).data; |
| 20917 | const ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 20851 | const ty_src = block.builtinCallArgSrc(inst_data.src_node, 0); |
| 20918 | const field_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; | 20852 | const field_src = block.builtinCallArgSrc(inst_data.src_node, 1); |
| 20919 | const aggregate_ty = try sema.resolveType(block, ty_src, extra.container_type); | 20853 | const aggregate_ty = try sema.resolveType(block, ty_src, extra.container_type); |
| 20920 | const field_name = try sema.resolveConstStringIntern(block, field_src, extra.field_name, .{ | 20854 | const field_name = try sema.resolveConstStringIntern(block, field_src, extra.field_name, .{ |
| 20921 | .needed_comptime_reason = "field name must be comptime-known", | 20855 | .needed_comptime_reason = "field name must be comptime-known", |
| ... | @@ -20928,8 +20862,8 @@ fn zirStructInitFieldType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp | ... | @@ -20928,8 +20862,8 @@ fn zirStructInitFieldType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp |
| 20928 | const ip = &mod.intern_pool; | 20862 | const ip = &mod.intern_pool; |
| 20929 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 20863 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 20930 | const extra = sema.code.extraData(Zir.Inst.FieldType, inst_data.payload_index).data; | 20864 | const extra = sema.code.extraData(Zir.Inst.FieldType, inst_data.payload_index).data; |
| 20931 | const ty_src = inst_data.src(); | 20865 | const ty_src = block.nodeOffset(inst_data.src_node); |
| 20932 | const field_name_src: LazySrcLoc = .{ .node_offset_field_name_init = inst_data.src_node }; | 20866 | const field_name_src = block.src(.{ .node_offset_field_name_init = inst_data.src_node }); |
| 20933 | const wrapped_aggregate_ty = sema.resolveType(block, ty_src, extra.container_type) catch |err| switch (err) { | 20867 | const wrapped_aggregate_ty = sema.resolveType(block, ty_src, extra.container_type) catch |err| switch (err) { |
| 20934 | // Since this is a ZIR instruction that returns a type, encountering | 20868 | // Since this is a ZIR instruction that returns a type, encountering |
| 20935 | // generic poison should not result in a failed compilation, but the | 20869 | // generic poison should not result in a failed compilation, but the |
| ... | @@ -20969,7 +20903,7 @@ fn fieldType( | ... | @@ -20969,7 +20903,7 @@ fn fieldType( |
| 20969 | .struct_type => { | 20903 | .struct_type => { |
| 20970 | const struct_type = ip.loadStructType(cur_ty.toIntern()); | 20904 | const struct_type = ip.loadStructType(cur_ty.toIntern()); |
| 20971 | const field_index = struct_type.nameIndex(ip, field_name) orelse | 20905 | const field_index = struct_type.nameIndex(ip, field_name) orelse |
| 20972 | return sema.failWithBadStructFieldAccess(block, struct_type, field_src, field_name); | 20906 | return sema.failWithBadStructFieldAccess(block, cur_ty, struct_type, field_src, field_name); |
| 20973 | const field_ty = struct_type.field_types.get(ip)[field_index]; | 20907 | const field_ty = struct_type.field_types.get(ip)[field_index]; |
| 20974 | return Air.internedToRef(field_ty); | 20908 | return Air.internedToRef(field_ty); |
| 20975 | }, | 20909 | }, |
| ... | @@ -20978,7 +20912,7 @@ fn fieldType( | ... | @@ -20978,7 +20912,7 @@ fn fieldType( |
| 20978 | .Union => { | 20912 | .Union => { |
| 20979 | const union_obj = mod.typeToUnion(cur_ty).?; | 20913 | const union_obj = mod.typeToUnion(cur_ty).?; |
| 20980 | const field_index = union_obj.loadTagType(ip).nameIndex(ip, field_name) orelse | 20914 | const field_index = union_obj.loadTagType(ip).nameIndex(ip, field_name) orelse |
| 20981 | return sema.failWithBadUnionFieldAccess(block, union_obj, field_src, field_name); | 20915 | return sema.failWithBadUnionFieldAccess(block, cur_ty, union_obj, field_src, field_name); |
| 20982 | const field_ty = union_obj.field_types.get(ip)[field_index]; | 20916 | const field_ty = union_obj.field_types.get(ip)[field_index]; |
| 20983 | return Air.internedToRef(field_ty); | 20917 | return Air.internedToRef(field_ty); |
| 20984 | }, | 20918 | }, |
| ... | @@ -21029,14 +20963,14 @@ fn zirFrame( | ... | @@ -21029,14 +20963,14 @@ fn zirFrame( |
| 21029 | block: *Block, | 20963 | block: *Block, |
| 21030 | extended: Zir.Inst.Extended.InstData, | 20964 | extended: Zir.Inst.Extended.InstData, |
| 21031 | ) CompileError!Air.Inst.Ref { | 20965 | ) CompileError!Air.Inst.Ref { |
| 21032 | const src = LazySrcLoc.nodeOffset(@bitCast(extended.operand)); | 20966 | const src = block.nodeOffset(@bitCast(extended.operand)); |
| 21033 | return sema.failWithUseOfAsync(block, src); | 20967 | return sema.failWithUseOfAsync(block, src); |
| 21034 | } | 20968 | } |
| 21035 | | 20969 | |
| 21036 | fn zirAlignOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 20970 | fn zirAlignOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 21037 | const mod = sema.mod; | 20971 | const mod = sema.mod; |
| 21038 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; | 20972 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 21039 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 20973 | const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0); |
| 21040 | const ty = try sema.resolveType(block, operand_src, inst_data.operand); | 20974 | const ty = try sema.resolveType(block, operand_src, inst_data.operand); |
| 21041 | if (ty.isNoReturn(mod)) { | 20975 | if (ty.isNoReturn(mod)) { |
| 21042 | return sema.fail(block, operand_src, "no align available for type '{}'", .{ty.fmt(sema.mod)}); | 20976 | return sema.fail(block, operand_src, "no align available for type '{}'", .{ty.fmt(sema.mod)}); |
| ... | @@ -21051,7 +20985,7 @@ fn zirAlignOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air | ... | @@ -21051,7 +20985,7 @@ fn zirAlignOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 21051 | fn zirIntFromBool(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 20985 | fn zirIntFromBool(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 21052 | const mod = sema.mod; | 20986 | const mod = sema.mod; |
| 21053 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; | 20987 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 21054 | const src = inst_data.src(); | 20988 | const src = block.nodeOffset(inst_data.src_node); |
| 21055 | const operand = try sema.resolveInst(inst_data.operand); | 20989 | const operand = try sema.resolveInst(inst_data.operand); |
| 21056 | const operand_ty = sema.typeOf(operand); | 20990 | const operand_ty = sema.typeOf(operand); |
| 21057 | const is_vector = operand_ty.zigTypeTag(mod) == .Vector; | 20991 | const is_vector = operand_ty.zigTypeTag(mod) == .Vector; |
| ... | @@ -21100,7 +21034,7 @@ fn zirIntFromBool(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError | ... | @@ -21100,7 +21034,7 @@ fn zirIntFromBool(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 21100 | | 21034 | |
| 21101 | fn zirErrorName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 21035 | fn zirErrorName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 21102 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; | 21036 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 21103 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 21037 | const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0); |
| 21104 | const uncoerced_operand = try sema.resolveInst(inst_data.operand); | 21038 | const uncoerced_operand = try sema.resolveInst(inst_data.operand); |
| 21105 | const operand = try sema.coerce(block, Type.anyerror, uncoerced_operand, operand_src); | 21039 | const operand = try sema.coerce(block, Type.anyerror, uncoerced_operand, operand_src); |
| 21106 | | 21040 | |
| ... | @@ -21122,7 +21056,7 @@ fn zirAbs( | ... | @@ -21122,7 +21056,7 @@ fn zirAbs( |
| 21122 | const mod = sema.mod; | 21056 | const mod = sema.mod; |
| 21123 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; | 21057 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 21124 | const operand = try sema.resolveInst(inst_data.operand); | 21058 | const operand = try sema.resolveInst(inst_data.operand); |
| 21125 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 21059 | const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0); |
| 21126 | const operand_ty = sema.typeOf(operand); | 21060 | const operand_ty = sema.typeOf(operand); |
| 21127 | const scalar_ty = operand_ty.scalarType(mod); | 21061 | const scalar_ty = operand_ty.scalarType(mod); |
| 21128 | | 21062 | |
| ... | @@ -21190,7 +21124,7 @@ fn zirUnaryMath( | ... | @@ -21190,7 +21124,7 @@ fn zirUnaryMath( |
| 21190 | const mod = sema.mod; | 21124 | const mod = sema.mod; |
| 21191 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; | 21125 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 21192 | const operand = try sema.resolveInst(inst_data.operand); | 21126 | const operand = try sema.resolveInst(inst_data.operand); |
| 21193 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 21127 | const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0); |
| 21194 | const operand_ty = sema.typeOf(operand); | 21128 | const operand_ty = sema.typeOf(operand); |
| 21195 | const scalar_ty = operand_ty.scalarType(mod); | 21129 | const scalar_ty = operand_ty.scalarType(mod); |
| 21196 | | 21130 | |
| ... | @@ -21212,8 +21146,8 @@ fn zirUnaryMath( | ... | @@ -21212,8 +21146,8 @@ fn zirUnaryMath( |
| 21212 | | 21146 | |
| 21213 | fn zirTagName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 21147 | fn zirTagName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 21214 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; | 21148 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 21215 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 21149 | const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0); |
| 21216 | const src = inst_data.src(); | 21150 | const src = block.nodeOffset(inst_data.src_node); |
| 21217 | const operand = try sema.resolveInst(inst_data.operand); | 21151 | const operand = try sema.resolveInst(inst_data.operand); |
| 21218 | const operand_ty = sema.typeOf(operand); | 21152 | const operand_ty = sema.typeOf(operand); |
| 21219 | const mod = sema.mod; | 21153 | const mod = sema.mod; |
| ... | @@ -21222,7 +21156,7 @@ fn zirTagName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air | ... | @@ -21222,7 +21156,7 @@ fn zirTagName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 21222 | try sema.resolveTypeLayout(operand_ty); | 21156 | try sema.resolveTypeLayout(operand_ty); |
| 21223 | const enum_ty = switch (operand_ty.zigTypeTag(mod)) { | 21157 | const enum_ty = switch (operand_ty.zigTypeTag(mod)) { |
| 21224 | .EnumLiteral => { | 21158 | .EnumLiteral => { |
| 21225 | const val = try sema.resolveConstDefinedValue(block, .unneeded, operand, undefined); | 21159 | const val = try sema.resolveConstDefinedValue(block, LazySrcLoc.unneeded, operand, undefined); |
| 21226 | const tag_name = ip.indexToKey(val.toIntern()).enum_literal; | 21160 | const tag_name = ip.indexToKey(val.toIntern()).enum_literal; |
| 21227 | return sema.addNullTerminatedStrLit(tag_name); | 21161 | return sema.addNullTerminatedStrLit(tag_name); |
| 21228 | }, | 21162 | }, |
| ... | @@ -21245,13 +21179,12 @@ fn zirTagName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air | ... | @@ -21245,13 +21179,12 @@ fn zirTagName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 21245 | const casted_operand = try sema.coerce(block, enum_ty, operand, operand_src); | 21179 | const casted_operand = try sema.coerce(block, enum_ty, operand, operand_src); |
| 21246 | if (try sema.resolveDefinedValue(block, operand_src, casted_operand)) |val| { | 21180 | if (try sema.resolveDefinedValue(block, operand_src, casted_operand)) |val| { |
| 21247 | const field_index = enum_ty.enumTagFieldIndex(val, mod) orelse { | 21181 | const field_index = enum_ty.enumTagFieldIndex(val, mod) orelse { |
| 21248 | const enum_decl = mod.declPtr(enum_decl_index); | | |
| 21249 | const msg = msg: { | 21182 | const msg = msg: { |
| 21250 | const msg = try sema.errMsg(block, src, "no field with value '{}' in enum '{}'", .{ | 21183 | const msg = try sema.errMsg(src, "no field with value '{}' in enum '{}'", .{ |
| 21251 | val.fmtValue(sema.mod, sema), enum_decl.name.fmt(ip), | 21184 | val.fmtValue(sema.mod, sema), mod.declPtr(enum_decl_index).name.fmt(ip), |
| 21252 | }); | 21185 | }); |
| 21253 | errdefer msg.destroy(sema.gpa); | 21186 | errdefer msg.destroy(sema.gpa); |
| 21254 | try mod.errNoteNonLazy(enum_decl.srcLoc(mod), msg, "declared here", .{}); | 21187 | try sema.errNote(enum_ty.srcLoc(mod), msg, "declared here", .{}); |
| 21255 | break :msg msg; | 21188 | break :msg msg; |
| 21256 | }; | 21189 | }; |
| 21257 | return sema.failWithOwnedErrorMsg(block, msg); | 21190 | return sema.failWithOwnedErrorMsg(block, msg); |
| ... | @@ -21281,11 +21214,23 @@ fn zirReify( | ... | @@ -21281,11 +21214,23 @@ fn zirReify( |
| 21281 | const gpa = sema.gpa; | 21214 | const gpa = sema.gpa; |
| 21282 | const ip = &mod.intern_pool; | 21215 | const ip = &mod.intern_pool; |
| 21283 | const name_strategy: Zir.Inst.NameStrategy = @enumFromInt(extended.small); | 21216 | const name_strategy: Zir.Inst.NameStrategy = @enumFromInt(extended.small); |
| 21284 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; | 21217 | const extra = sema.code.extraData(Zir.Inst.Reify, extended.operand).data; |
| 21285 | const src = LazySrcLoc.nodeOffset(extra.node); | 21218 | const tracked_inst = try ip.trackZir(gpa, block.getFileScope(mod), inst); |
| | 21219 | const src: LazySrcLoc = .{ |
| | 21220 | .base_node_inst = tracked_inst, |
| | 21221 | .offset = LazySrcLoc.Offset.nodeOffset(0), |
| | 21222 | }; |
| | 21223 | const operand_src: LazySrcLoc = .{ |
| | 21224 | .base_node_inst = tracked_inst, |
| | 21225 | .offset = .{ |
| | 21226 | .node_offset_builtin_call_arg = .{ |
| | 21227 | .builtin_call_node = 0, // `tracked_inst` is precisely the `reify` instruction, so offset is 0 |
| | 21228 | .arg_index = 0, |
| | 21229 | }, |
| | 21230 | }, |
| | 21231 | }; |
| 21286 | const type_info_ty = try sema.getBuiltinType("Type"); | 21232 | const type_info_ty = try sema.getBuiltinType("Type"); |
| 21287 | const uncasted_operand = try sema.resolveInst(extra.operand); | 21233 | const uncasted_operand = try sema.resolveInst(extra.operand); |
| 21288 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node }; | | |
| 21289 | const type_info = try sema.coerce(block, type_info_ty, uncasted_operand, operand_src); | 21234 | const type_info = try sema.coerce(block, type_info_ty, uncasted_operand, operand_src); |
| 21290 | const val = try sema.resolveConstDefinedValue(block, operand_src, type_info, .{ | 21235 | const val = try sema.resolveConstDefinedValue(block, operand_src, type_info, .{ |
| 21291 | .needed_comptime_reason = "operand to @Type must be comptime-known", | 21236 | .needed_comptime_reason = "operand to @Type must be comptime-known", |
| ... | @@ -21438,11 +21383,10 @@ fn zirReify( | ... | @@ -21438,11 +21383,10 @@ fn zirReify( |
| 21438 | } else if (ptr_size == .C) { | 21383 | } else if (ptr_size == .C) { |
| 21439 | if (!try sema.validateExternType(elem_ty, .other)) { | 21384 | if (!try sema.validateExternType(elem_ty, .other)) { |
| 21440 | const msg = msg: { | 21385 | const msg = msg: { |
| 21441 | const msg = try sema.errMsg(block, src, "C pointers cannot point to non-C-ABI-compatible type '{}'", .{elem_ty.fmt(mod)}); | 21386 | const msg = try sema.errMsg(src, "C pointers cannot point to non-C-ABI-compatible type '{}'", .{elem_ty.fmt(mod)}); |
| 21442 | errdefer msg.destroy(gpa); | 21387 | errdefer msg.destroy(gpa); |
| 21443 | | 21388 | |
| 21444 | const src_decl = mod.declPtr(block.src_decl); | 21389 | try sema.explainWhyTypeIsNotExtern(msg, src, elem_ty, .other); |
| 21445 | try sema.explainWhyTypeIsNotExtern(msg, src_decl.toSrcLoc(src, mod), elem_ty, .other); | | |
| 21446 | | 21390 | |
| 21447 | try sema.addDeclaredHereNote(msg, elem_ty); | 21391 | try sema.addDeclaredHereNote(msg, elem_ty); |
| 21448 | break :msg msg; | 21392 | break :msg msg; |
| ... | @@ -21602,7 +21546,7 @@ fn zirReify( | ... | @@ -21602,7 +21546,7 @@ fn zirReify( |
| 21602 | .needed_comptime_reason = "struct fields must be comptime-known", | 21546 | .needed_comptime_reason = "struct fields must be comptime-known", |
| 21603 | }); | 21547 | }); |
| 21604 | | 21548 | |
| 21605 | return try sema.reifyStruct(block, inst, src, layout, backing_integer_val, fields_arr, name_strategy, is_tuple_val.toBool()); | 21549 | return try sema.reifyStruct(block, inst, src, layout, backing_integer_val, fields_arr, name_strategy, is_tuple_val.toBool(), extra.src_line); |
| 21606 | }, | 21550 | }, |
| 21607 | .Enum => { | 21551 | .Enum => { |
| 21608 | const struct_type = ip.loadStructType(ip.typeOf(union_val.val)); | 21552 | const struct_type = ip.loadStructType(ip.typeOf(union_val.val)); |
| ... | @@ -21631,7 +21575,7 @@ fn zirReify( | ... | @@ -21631,7 +21575,7 @@ fn zirReify( |
| 21631 | .needed_comptime_reason = "enum fields must be comptime-known", | 21575 | .needed_comptime_reason = "enum fields must be comptime-known", |
| 21632 | }); | 21576 | }); |
| 21633 | | 21577 | |
| 21634 | return sema.reifyEnum(block, inst, src, tag_type_val.toType(), is_exhaustive_val.toBool(), fields_arr, name_strategy); | 21578 | return sema.reifyEnum(block, inst, src, tag_type_val.toType(), is_exhaustive_val.toBool(), fields_arr, name_strategy, extra.src_line); |
| 21635 | }, | 21579 | }, |
| 21636 | .Opaque => { | 21580 | .Opaque => { |
| 21637 | const struct_type = ip.loadStructType(ip.typeOf(union_val.val)); | 21581 | const struct_type = ip.loadStructType(ip.typeOf(union_val.val)); |
| ... | @@ -21658,11 +21602,11 @@ fn zirReify( | ... | @@ -21658,11 +21602,11 @@ fn zirReify( |
| 21658 | | 21602 | |
| 21659 | const new_decl_index = try sema.createAnonymousDeclTypeNamed( | 21603 | const new_decl_index = try sema.createAnonymousDeclTypeNamed( |
| 21660 | block, | 21604 | block, |
| 21661 | src, | | |
| 21662 | Value.fromInterned(wip_ty.index), | 21605 | Value.fromInterned(wip_ty.index), |
| 21663 | name_strategy, | 21606 | name_strategy, |
| 21664 | "opaque", | 21607 | "opaque", |
| 21665 | inst, | 21608 | inst, |
| | 21609 | extra.src_line, |
| 21666 | ); | 21610 | ); |
| 21667 | mod.declPtr(new_decl_index).owns_tv = true; | 21611 | mod.declPtr(new_decl_index).owns_tv = true; |
| 21668 | errdefer mod.abortAnonDecl(new_decl_index); | 21612 | errdefer mod.abortAnonDecl(new_decl_index); |
| ... | @@ -21699,7 +21643,7 @@ fn zirReify( | ... | @@ -21699,7 +21643,7 @@ fn zirReify( |
| 21699 | .needed_comptime_reason = "union fields must be comptime-known", | 21643 | .needed_comptime_reason = "union fields must be comptime-known", |
| 21700 | }); | 21644 | }); |
| 21701 | | 21645 | |
| 21702 | return sema.reifyUnion(block, inst, src, layout, tag_type_val, fields_arr, name_strategy); | 21646 | return sema.reifyUnion(block, inst, src, layout, tag_type_val, fields_arr, name_strategy, extra.src_line); |
| 21703 | }, | 21647 | }, |
| 21704 | .Fn => { | 21648 | .Fn => { |
| 21705 | const struct_type = ip.loadStructType(ip.typeOf(union_val.val)); | 21649 | const struct_type = ip.loadStructType(ip.typeOf(union_val.val)); |
| ... | @@ -21801,6 +21745,7 @@ fn reifyEnum( | ... | @@ -21801,6 +21745,7 @@ fn reifyEnum( |
| 21801 | is_exhaustive: bool, | 21745 | is_exhaustive: bool, |
| 21802 | fields_val: Value, | 21746 | fields_val: Value, |
| 21803 | name_strategy: Zir.Inst.NameStrategy, | 21747 | name_strategy: Zir.Inst.NameStrategy, |
| | 21748 | src_line: u32, |
| 21804 | ) CompileError!Air.Inst.Ref { | 21749 | ) CompileError!Air.Inst.Ref { |
| 21805 | const mod = sema.mod; | 21750 | const mod = sema.mod; |
| 21806 | const gpa = sema.gpa; | 21751 | const gpa = sema.gpa; |
| ... | @@ -21858,11 +21803,11 @@ fn reifyEnum( | ... | @@ -21858,11 +21803,11 @@ fn reifyEnum( |
| 21858 | | 21803 | |
| 21859 | const new_decl_index = try sema.createAnonymousDeclTypeNamed( | 21804 | const new_decl_index = try sema.createAnonymousDeclTypeNamed( |
| 21860 | block, | 21805 | block, |
| 21861 | src, | | |
| 21862 | Value.fromInterned(wip_ty.index), | 21806 | Value.fromInterned(wip_ty.index), |
| 21863 | name_strategy, | 21807 | name_strategy, |
| 21864 | "enum", | 21808 | "enum", |
| 21865 | inst, | 21809 | inst, |
| | 21810 | src_line, |
| 21866 | ); | 21811 | ); |
| 21867 | mod.declPtr(new_decl_index).owns_tv = true; | 21812 | mod.declPtr(new_decl_index).owns_tv = true; |
| 21868 | errdefer mod.abortAnonDecl(new_decl_index); | 21813 | errdefer mod.abortAnonDecl(new_decl_index); |
| ... | @@ -21892,17 +21837,17 @@ fn reifyEnum( | ... | @@ -21892,17 +21837,17 @@ fn reifyEnum( |
| 21892 | if (wip_ty.nextField(ip, field_name, coerced_field_val.toIntern())) |conflict| { | 21837 | if (wip_ty.nextField(ip, field_name, coerced_field_val.toIntern())) |conflict| { |
| 21893 | return sema.failWithOwnedErrorMsg(block, switch (conflict.kind) { | 21838 | return sema.failWithOwnedErrorMsg(block, switch (conflict.kind) { |
| 21894 | .name => msg: { | 21839 | .name => msg: { |
| 21895 | const msg = try sema.errMsg(block, src, "duplicate enum field '{}'", .{field_name.fmt(ip)}); | 21840 | const msg = try sema.errMsg(src, "duplicate enum field '{}'", .{field_name.fmt(ip)}); |
| 21896 | errdefer msg.destroy(gpa); | 21841 | errdefer msg.destroy(gpa); |
| 21897 | _ = conflict.prev_field_idx; // TODO: this note is incorrect | 21842 | _ = conflict.prev_field_idx; // TODO: this note is incorrect |
| 21898 | try sema.errNote(block, src, msg, "other field here", .{}); | 21843 | try sema.errNote(src, msg, "other field here", .{}); |
| 21899 | break :msg msg; | 21844 | break :msg msg; |
| 21900 | }, | 21845 | }, |
| 21901 | .value => msg: { | 21846 | .value => msg: { |
| 21902 | const msg = try sema.errMsg(block, src, "enum tag value {} already taken", .{field_value_val.fmtValue(mod, sema)}); | 21847 | const msg = try sema.errMsg(src, "enum tag value {} already taken", .{field_value_val.fmtValue(mod, sema)}); |
| 21903 | errdefer msg.destroy(gpa); | 21848 | errdefer msg.destroy(gpa); |
| 21904 | _ = conflict.prev_field_idx; // TODO: this note is incorrect | 21849 | _ = conflict.prev_field_idx; // TODO: this note is incorrect |
| 21905 | try sema.errNote(block, src, msg, "other enum tag value here", .{}); | 21850 | try sema.errNote(src, msg, "other enum tag value here", .{}); |
| 21906 | break :msg msg; | 21851 | break :msg msg; |
| 21907 | }, | 21852 | }, |
| 21908 | }); | 21853 | }); |
| ... | @@ -21926,6 +21871,7 @@ fn reifyUnion( | ... | @@ -21926,6 +21871,7 @@ fn reifyUnion( |
| 21926 | opt_tag_type_val: Value, | 21871 | opt_tag_type_val: Value, |
| 21927 | fields_val: Value, | 21872 | fields_val: Value, |
| 21928 | name_strategy: Zir.Inst.NameStrategy, | 21873 | name_strategy: Zir.Inst.NameStrategy, |
| | 21874 | src_line: u32, |
| 21929 | ) CompileError!Air.Inst.Ref { | 21875 | ) CompileError!Air.Inst.Ref { |
| 21930 | const mod = sema.mod; | 21876 | const mod = sema.mod; |
| 21931 | const gpa = sema.gpa; | 21877 | const gpa = sema.gpa; |
| ... | @@ -22005,11 +21951,11 @@ fn reifyUnion( | ... | @@ -22005,11 +21951,11 @@ fn reifyUnion( |
| 22005 | | 21951 | |
| 22006 | const new_decl_index = try sema.createAnonymousDeclTypeNamed( | 21952 | const new_decl_index = try sema.createAnonymousDeclTypeNamed( |
| 22007 | block, | 21953 | block, |
| 22008 | src, | | |
| 22009 | Value.fromInterned(wip_ty.index), | 21954 | Value.fromInterned(wip_ty.index), |
| 22010 | name_strategy, | 21955 | name_strategy, |
| 22011 | "union", | 21956 | "union", |
| 22012 | inst, | 21957 | inst, |
| | 21958 | src_line, |
| 22013 | ); | 21959 | ); |
| 22014 | mod.declPtr(new_decl_index).owns_tv = true; | 21960 | mod.declPtr(new_decl_index).owns_tv = true; |
| 22015 | errdefer mod.abortAnonDecl(new_decl_index); | 21961 | errdefer mod.abortAnonDecl(new_decl_index); |
| ... | @@ -22061,7 +22007,7 @@ fn reifyUnion( | ... | @@ -22061,7 +22007,7 @@ fn reifyUnion( |
| 22061 | } | 22007 | } |
| 22062 | | 22008 | |
| 22063 | if (tag_ty_fields_len > fields_len) return sema.failWithOwnedErrorMsg(block, msg: { | 22009 | if (tag_ty_fields_len > fields_len) return sema.failWithOwnedErrorMsg(block, msg: { |
| 22064 | const msg = try sema.errMsg(block, src, "enum fields missing in union", .{}); | 22010 | const msg = try sema.errMsg(src, "enum fields missing in union", .{}); |
| 22065 | errdefer msg.destroy(gpa); | 22011 | errdefer msg.destroy(gpa); |
| 22066 | var it = seen_tags.iterator(.{ .kind = .unset }); | 22012 | var it = seen_tags.iterator(.{ .kind = .unset }); |
| 22067 | while (it.next()) |enum_index| { | 22013 | while (it.next()) |enum_index| { |
| ... | @@ -22105,7 +22051,7 @@ fn reifyUnion( | ... | @@ -22105,7 +22051,7 @@ fn reifyUnion( |
| 22105 | } | 22051 | } |
| 22106 | } | 22052 | } |
| 22107 | | 22053 | |
| 22108 | const enum_tag_ty = try sema.generateUnionTagTypeSimple(block, field_names.keys(), mod.declPtr(new_decl_index)); | 22054 | const enum_tag_ty = try sema.generateUnionTagTypeSimple(block, field_names.keys(), mod.declPtr(new_decl_index), src_line); |
| 22109 | break :tag_ty .{ enum_tag_ty, false }; | 22055 | break :tag_ty .{ enum_tag_ty, false }; |
| 22110 | }; | 22056 | }; |
| 22111 | errdefer if (!has_explicit_tag) ip.remove(enum_tag_ty); // remove generated tag type on error | 22057 | errdefer if (!has_explicit_tag) ip.remove(enum_tag_ty); // remove generated tag type on error |
| ... | @@ -22114,7 +22060,7 @@ fn reifyUnion( | ... | @@ -22114,7 +22060,7 @@ fn reifyUnion( |
| 22114 | const field_ty = Type.fromInterned(field_ty_ip); | 22060 | const field_ty = Type.fromInterned(field_ty_ip); |
| 22115 | if (field_ty.zigTypeTag(mod) == .Opaque) { | 22061 | if (field_ty.zigTypeTag(mod) == .Opaque) { |
| 22116 | return sema.failWithOwnedErrorMsg(block, msg: { | 22062 | return sema.failWithOwnedErrorMsg(block, msg: { |
| 22117 | const msg = try sema.errMsg(block, src, "opaque types have unknown size and therefore cannot be directly embedded in unions", .{}); | 22063 | const msg = try sema.errMsg(src, "opaque types have unknown size and therefore cannot be directly embedded in unions", .{}); |
| 22118 | errdefer msg.destroy(gpa); | 22064 | errdefer msg.destroy(gpa); |
| 22119 | | 22065 | |
| 22120 | try sema.addDeclaredHereNote(msg, field_ty); | 22066 | try sema.addDeclaredHereNote(msg, field_ty); |
| ... | @@ -22123,22 +22069,20 @@ fn reifyUnion( | ... | @@ -22123,22 +22069,20 @@ fn reifyUnion( |
| 22123 | } | 22069 | } |
| 22124 | if (layout == .@"extern" and !try sema.validateExternType(field_ty, .union_field)) { | 22070 | if (layout == .@"extern" and !try sema.validateExternType(field_ty, .union_field)) { |
| 22125 | return sema.failWithOwnedErrorMsg(block, msg: { | 22071 | return sema.failWithOwnedErrorMsg(block, msg: { |
| 22126 | const msg = try sema.errMsg(block, src, "extern unions cannot contain fields of type '{}'", .{field_ty.fmt(mod)}); | 22072 | const msg = try sema.errMsg(src, "extern unions cannot contain fields of type '{}'", .{field_ty.fmt(mod)}); |
| 22127 | errdefer msg.destroy(gpa); | 22073 | errdefer msg.destroy(gpa); |
| 22128 | | 22074 | |
| 22129 | const src_decl = mod.declPtr(block.src_decl); | 22075 | try sema.explainWhyTypeIsNotExtern(msg, src, field_ty, .union_field); |
| 22130 | try sema.explainWhyTypeIsNotExtern(msg, src_decl.toSrcLoc(src, mod), field_ty, .union_field); | | |
| 22131 | | 22076 | |
| 22132 | try sema.addDeclaredHereNote(msg, field_ty); | 22077 | try sema.addDeclaredHereNote(msg, field_ty); |
| 22133 | break :msg msg; | 22078 | break :msg msg; |
| 22134 | }); | 22079 | }); |
| 22135 | } else if (layout == .@"packed" and !try sema.validatePackedType(field_ty)) { | 22080 | } else if (layout == .@"packed" and !try sema.validatePackedType(field_ty)) { |
| 22136 | return sema.failWithOwnedErrorMsg(block, msg: { | 22081 | return sema.failWithOwnedErrorMsg(block, msg: { |
| 22137 | const msg = try sema.errMsg(block, src, "packed unions cannot contain fields of type '{}'", .{field_ty.fmt(mod)}); | 22082 | const msg = try sema.errMsg(src, "packed unions cannot contain fields of type '{}'", .{field_ty.fmt(mod)}); |
| 22138 | errdefer msg.destroy(gpa); | 22083 | errdefer msg.destroy(gpa); |
| 22139 | | 22084 | |
| 22140 | const src_decl = mod.declPtr(block.src_decl); | 22085 | try sema.explainWhyTypeIsNotPacked(msg, src, field_ty); |
| 22141 | try sema.explainWhyTypeIsNotPacked(msg, src_decl.toSrcLoc(src, mod), field_ty); | | |
| 22142 | | 22086 | |
| 22143 | try sema.addDeclaredHereNote(msg, field_ty); | 22087 | try sema.addDeclaredHereNote(msg, field_ty); |
| 22144 | break :msg msg; | 22088 | break :msg msg; |
| ... | @@ -22168,6 +22112,7 @@ fn reifyStruct( | ... | @@ -22168,6 +22112,7 @@ fn reifyStruct( |
| 22168 | fields_val: Value, | 22112 | fields_val: Value, |
| 22169 | name_strategy: Zir.Inst.NameStrategy, | 22113 | name_strategy: Zir.Inst.NameStrategy, |
| 22170 | is_tuple: bool, | 22114 | is_tuple: bool, |
| | 22115 | src_line: u32, |
| 22171 | ) CompileError!Air.Inst.Ref { | 22116 | ) CompileError!Air.Inst.Ref { |
| 22172 | const mod = sema.mod; | 22117 | const mod = sema.mod; |
| 22173 | const gpa = sema.gpa; | 22118 | const gpa = sema.gpa; |
| ... | @@ -22264,11 +22209,11 @@ fn reifyStruct( | ... | @@ -22264,11 +22209,11 @@ fn reifyStruct( |
| 22264 | | 22209 | |
| 22265 | const new_decl_index = try sema.createAnonymousDeclTypeNamed( | 22210 | const new_decl_index = try sema.createAnonymousDeclTypeNamed( |
| 22266 | block, | 22211 | block, |
| 22267 | src, | | |
| 22268 | Value.fromInterned(wip_ty.index), | 22212 | Value.fromInterned(wip_ty.index), |
| 22269 | name_strategy, | 22213 | name_strategy, |
| 22270 | "struct", | 22214 | "struct", |
| 22271 | inst, | 22215 | inst, |
| | 22216 | src_line, |
| 22272 | ); | 22217 | ); |
| 22273 | mod.declPtr(new_decl_index).owns_tv = true; | 22218 | mod.declPtr(new_decl_index).owns_tv = true; |
| 22274 | errdefer mod.abortAnonDecl(new_decl_index); | 22219 | errdefer mod.abortAnonDecl(new_decl_index); |
| ... | @@ -22355,7 +22300,7 @@ fn reifyStruct( | ... | @@ -22355,7 +22300,7 @@ fn reifyStruct( |
| 22355 | | 22300 | |
| 22356 | if (field_ty.zigTypeTag(mod) == .Opaque) { | 22301 | if (field_ty.zigTypeTag(mod) == .Opaque) { |
| 22357 | return sema.failWithOwnedErrorMsg(block, msg: { | 22302 | return sema.failWithOwnedErrorMsg(block, msg: { |
| 22358 | const msg = try sema.errMsg(block, src, "opaque types have unknown size and therefore cannot be directly embedded in structs", .{}); | 22303 | const msg = try sema.errMsg(src, "opaque types have unknown size and therefore cannot be directly embedded in structs", .{}); |
| 22359 | errdefer msg.destroy(gpa); | 22304 | errdefer msg.destroy(gpa); |
| 22360 | | 22305 | |
| 22361 | try sema.addDeclaredHereNote(msg, field_ty); | 22306 | try sema.addDeclaredHereNote(msg, field_ty); |
| ... | @@ -22364,7 +22309,7 @@ fn reifyStruct( | ... | @@ -22364,7 +22309,7 @@ fn reifyStruct( |
| 22364 | } | 22309 | } |
| 22365 | if (field_ty.zigTypeTag(mod) == .NoReturn) { | 22310 | if (field_ty.zigTypeTag(mod) == .NoReturn) { |
| 22366 | return sema.failWithOwnedErrorMsg(block, msg: { | 22311 | return sema.failWithOwnedErrorMsg(block, msg: { |
| 22367 | const msg = try sema.errMsg(block, src, "struct fields cannot be 'noreturn'", .{}); | 22312 | const msg = try sema.errMsg(src, "struct fields cannot be 'noreturn'", .{}); |
| 22368 | errdefer msg.destroy(gpa); | 22313 | errdefer msg.destroy(gpa); |
| 22369 | | 22314 | |
| 22370 | try sema.addDeclaredHereNote(msg, field_ty); | 22315 | try sema.addDeclaredHereNote(msg, field_ty); |
| ... | @@ -22373,22 +22318,20 @@ fn reifyStruct( | ... | @@ -22373,22 +22318,20 @@ fn reifyStruct( |
| 22373 | } | 22318 | } |
| 22374 | if (layout == .@"extern" and !try sema.validateExternType(field_ty, .struct_field)) { | 22319 | if (layout == .@"extern" and !try sema.validateExternType(field_ty, .struct_field)) { |
| 22375 | return sema.failWithOwnedErrorMsg(block, msg: { | 22320 | return sema.failWithOwnedErrorMsg(block, msg: { |
| 22376 | const msg = try sema.errMsg(block, src, "extern structs cannot contain fields of type '{}'", .{field_ty.fmt(sema.mod)}); | 22321 | const msg = try sema.errMsg(src, "extern structs cannot contain fields of type '{}'", .{field_ty.fmt(sema.mod)}); |
| 22377 | errdefer msg.destroy(gpa); | 22322 | errdefer msg.destroy(gpa); |
| 22378 | | 22323 | |
| 22379 | const src_decl = sema.mod.declPtr(block.src_decl); | 22324 | try sema.explainWhyTypeIsNotExtern(msg, src, field_ty, .struct_field); |
| 22380 | try sema.explainWhyTypeIsNotExtern(msg, src_decl.toSrcLoc(src, mod), field_ty, .struct_field); | | |
| 22381 | | 22325 | |
| 22382 | try sema.addDeclaredHereNote(msg, field_ty); | 22326 | try sema.addDeclaredHereNote(msg, field_ty); |
| 22383 | break :msg msg; | 22327 | break :msg msg; |
| 22384 | }); | 22328 | }); |
| 22385 | } else if (layout == .@"packed" and !try sema.validatePackedType(field_ty)) { | 22329 | } else if (layout == .@"packed" and !try sema.validatePackedType(field_ty)) { |
| 22386 | return sema.failWithOwnedErrorMsg(block, msg: { | 22330 | return sema.failWithOwnedErrorMsg(block, msg: { |
| 22387 | const msg = try sema.errMsg(block, src, "packed structs cannot contain fields of type '{}'", .{field_ty.fmt(sema.mod)}); | 22331 | const msg = try sema.errMsg(src, "packed structs cannot contain fields of type '{}'", .{field_ty.fmt(sema.mod)}); |
| 22388 | errdefer msg.destroy(gpa); | 22332 | errdefer msg.destroy(gpa); |
| 22389 | | 22333 | |
| 22390 | const src_decl = sema.mod.declPtr(block.src_decl); | 22334 | try sema.explainWhyTypeIsNotPacked(msg, src, field_ty); |
| 22391 | try sema.explainWhyTypeIsNotPacked(msg, src_decl.toSrcLoc(src, mod), field_ty); | | |
| 22392 | | 22335 | |
| 22393 | try sema.addDeclaredHereNote(msg, field_ty); | 22336 | try sema.addDeclaredHereNote(msg, field_ty); |
| 22394 | break :msg msg; | 22337 | break :msg msg; |
| ... | @@ -22403,7 +22346,7 @@ fn reifyStruct( | ... | @@ -22403,7 +22346,7 @@ fn reifyStruct( |
| 22403 | sema.resolveTypeLayout(field_ty) catch |err| switch (err) { | 22346 | sema.resolveTypeLayout(field_ty) catch |err| switch (err) { |
| 22404 | error.AnalysisFail => { | 22347 | error.AnalysisFail => { |
| 22405 | const msg = sema.err orelse return err; | 22348 | const msg = sema.err orelse return err; |
| 22406 | try sema.errNote(block, src, msg, "while checking a field of this struct", .{}); | 22349 | try sema.errNote(src, msg, "while checking a field of this struct", .{}); |
| 22407 | return err; | 22350 | return err; |
| 22408 | }, | 22351 | }, |
| 22409 | else => return err, | 22352 | else => return err, |
| ... | @@ -22434,22 +22377,20 @@ fn resolveVaListRef(sema: *Sema, block: *Block, src: LazySrcLoc, zir_ref: Zir.In | ... | @@ -22434,22 +22377,20 @@ fn resolveVaListRef(sema: *Sema, block: *Block, src: LazySrcLoc, zir_ref: Zir.In |
| 22434 | } | 22377 | } |
| 22435 | | 22378 | |
| 22436 | fn zirCVaArg(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!Air.Inst.Ref { | 22379 | fn zirCVaArg(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!Air.Inst.Ref { |
| 22437 | const mod = sema.mod; | | |
| 22438 | const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data; | 22380 | const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data; |
| 22439 | const src = LazySrcLoc.nodeOffset(extra.node); | 22381 | const src = block.nodeOffset(extra.node); |
| 22440 | const va_list_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node }; | 22382 | const va_list_src = block.builtinCallArgSrc(extra.node, 0); |
| 22441 | const ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = extra.node }; | 22383 | const ty_src = block.builtinCallArgSrc(extra.node, 1); |
| 22442 | | 22384 | |
| 22443 | const va_list_ref = try sema.resolveVaListRef(block, va_list_src, extra.lhs); | 22385 | const va_list_ref = try sema.resolveVaListRef(block, va_list_src, extra.lhs); |
| 22444 | const arg_ty = try sema.resolveType(block, ty_src, extra.rhs); | 22386 | const arg_ty = try sema.resolveType(block, ty_src, extra.rhs); |
| 22445 | | 22387 | |
| 22446 | if (!try sema.validateExternType(arg_ty, .param_ty)) { | 22388 | if (!try sema.validateExternType(arg_ty, .param_ty)) { |
| 22447 | const msg = msg: { | 22389 | const msg = msg: { |
| 22448 | const msg = try sema.errMsg(block, ty_src, "cannot get '{}' from variadic argument", .{arg_ty.fmt(sema.mod)}); | 22390 | const msg = try sema.errMsg(ty_src, "cannot get '{}' from variadic argument", .{arg_ty.fmt(sema.mod)}); |
| 22449 | errdefer msg.destroy(sema.gpa); | 22391 | errdefer msg.destroy(sema.gpa); |
| 22450 | | 22392 | |
| 22451 | const src_decl = sema.mod.declPtr(block.src_decl); | 22393 | try sema.explainWhyTypeIsNotExtern(msg, ty_src, arg_ty, .param_ty); |
| 22452 | try sema.explainWhyTypeIsNotExtern(msg, src_decl.toSrcLoc(ty_src, mod), arg_ty, .param_ty); | | |
| 22453 | | 22394 | |
| 22454 | try sema.addDeclaredHereNote(msg, arg_ty); | 22395 | try sema.addDeclaredHereNote(msg, arg_ty); |
| 22455 | break :msg msg; | 22396 | break :msg msg; |
| ... | @@ -22463,8 +22404,8 @@ fn zirCVaArg(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) C | ... | @@ -22463,8 +22404,8 @@ fn zirCVaArg(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) C |
| 22463 | | 22404 | |
| 22464 | fn zirCVaCopy(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!Air.Inst.Ref { | 22405 | fn zirCVaCopy(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!Air.Inst.Ref { |
| 22465 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; | 22406 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; |
| 22466 | const src = LazySrcLoc.nodeOffset(extra.node); | 22407 | const src = block.nodeOffset(extra.node); |
| 22467 | const va_list_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node }; | 22408 | const va_list_src = block.builtinCallArgSrc(extra.node, 0); |
| 22468 | | 22409 | |
| 22469 | const va_list_ref = try sema.resolveVaListRef(block, va_list_src, extra.operand); | 22410 | const va_list_ref = try sema.resolveVaListRef(block, va_list_src, extra.operand); |
| 22470 | const va_list_ty = try sema.getBuiltinType("VaList"); | 22411 | const va_list_ty = try sema.getBuiltinType("VaList"); |
| ... | @@ -22475,8 +22416,8 @@ fn zirCVaCopy(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) | ... | @@ -22475,8 +22416,8 @@ fn zirCVaCopy(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) |
| 22475 | | 22416 | |
| 22476 | fn zirCVaEnd(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!Air.Inst.Ref { | 22417 | fn zirCVaEnd(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!Air.Inst.Ref { |
| 22477 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; | 22418 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; |
| 22478 | const src = LazySrcLoc.nodeOffset(extra.node); | 22419 | const src = block.nodeOffset(extra.node); |
| 22479 | const va_list_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node }; | 22420 | const va_list_src = block.builtinCallArgSrc(extra.node, 0); |
| 22480 | | 22421 | |
| 22481 | const va_list_ref = try sema.resolveVaListRef(block, va_list_src, extra.operand); | 22422 | const va_list_ref = try sema.resolveVaListRef(block, va_list_src, extra.operand); |
| 22482 | | 22423 | |
| ... | @@ -22485,7 +22426,7 @@ fn zirCVaEnd(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) C | ... | @@ -22485,7 +22426,7 @@ fn zirCVaEnd(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) C |
| 22485 | } | 22426 | } |
| 22486 | | 22427 | |
| 22487 | fn zirCVaStart(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!Air.Inst.Ref { | 22428 | fn zirCVaStart(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!Air.Inst.Ref { |
| 22488 | const src = LazySrcLoc.nodeOffset(@bitCast(extended.operand)); | 22429 | const src = block.nodeOffset(@bitCast(extended.operand)); |
| 22489 | | 22430 | |
| 22490 | const va_list_ty = try sema.getBuiltinType("VaList"); | 22431 | const va_list_ty = try sema.getBuiltinType("VaList"); |
| 22491 | try sema.requireRuntimeBlock(block, src, null); | 22432 | try sema.requireRuntimeBlock(block, src, null); |
| ... | @@ -22500,7 +22441,7 @@ fn zirTypeName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -22500,7 +22441,7 @@ fn zirTypeName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 22500 | const ip = &mod.intern_pool; | 22441 | const ip = &mod.intern_pool; |
| 22501 | | 22442 | |
| 22502 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; | 22443 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 22503 | const ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 22444 | const ty_src = block.builtinCallArgSrc(inst_data.src_node, 0); |
| 22504 | const ty = try sema.resolveType(block, ty_src, inst_data.operand); | 22445 | const ty = try sema.resolveType(block, ty_src, inst_data.operand); |
| 22505 | | 22446 | |
| 22506 | const type_name = try ip.getOrPutStringFmt(sema.gpa, "{}", .{ty.fmt(mod)}, .no_embedded_nulls); | 22447 | const type_name = try ip.getOrPutStringFmt(sema.gpa, "{}", .{ty.fmt(mod)}, .no_embedded_nulls); |
| ... | @@ -22509,22 +22450,22 @@ fn zirTypeName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -22509,22 +22450,22 @@ fn zirTypeName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 22509 | | 22450 | |
| 22510 | fn zirFrameType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 22451 | fn zirFrameType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 22511 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; | 22452 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 22512 | const src = inst_data.src(); | 22453 | const src = block.nodeOffset(inst_data.src_node); |
| 22513 | return sema.failWithUseOfAsync(block, src); | 22454 | return sema.failWithUseOfAsync(block, src); |
| 22514 | } | 22455 | } |
| 22515 | | 22456 | |
| 22516 | fn zirFrameSize(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 22457 | fn zirFrameSize(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 22517 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; | 22458 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 22518 | const src = inst_data.src(); | 22459 | const src = block.nodeOffset(inst_data.src_node); |
| 22519 | return sema.failWithUseOfAsync(block, src); | 22460 | return sema.failWithUseOfAsync(block, src); |
| 22520 | } | 22461 | } |
| 22521 | | 22462 | |
| 22522 | fn zirIntFromFloat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 22463 | fn zirIntFromFloat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 22523 | const mod = sema.mod; | 22464 | const mod = sema.mod; |
| 22524 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 22465 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 22525 | const src = inst_data.src(); | 22466 | const src = block.nodeOffset(inst_data.src_node); |
| 22526 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; | 22467 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 22527 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 22468 | const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0); |
| 22528 | const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu_opt, "@intFromFloat"); | 22469 | const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu_opt, "@intFromFloat"); |
| 22529 | const operand = try sema.resolveInst(extra.rhs); | 22470 | const operand = try sema.resolveInst(extra.rhs); |
| 22530 | const operand_ty = sema.typeOf(operand); | 22471 | const operand_ty = sema.typeOf(operand); |
| ... | @@ -22547,7 +22488,7 @@ fn zirIntFromFloat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro | ... | @@ -22547,7 +22488,7 @@ fn zirIntFromFloat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro |
| 22547 | }); | 22488 | }); |
| 22548 | } | 22489 | } |
| 22549 | | 22490 | |
| 22550 | try sema.requireRuntimeBlock(block, inst_data.src(), operand_src); | 22491 | try sema.requireRuntimeBlock(block, src, operand_src); |
| 22551 | if (dest_scalar_ty.intInfo(mod).bits == 0) { | 22492 | if (dest_scalar_ty.intInfo(mod).bits == 0) { |
| 22552 | if (!is_vector) { | 22493 | if (!is_vector) { |
| 22553 | if (block.wantSafety()) { | 22494 | if (block.wantSafety()) { |
| ... | @@ -22604,9 +22545,9 @@ fn zirIntFromFloat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro | ... | @@ -22604,9 +22545,9 @@ fn zirIntFromFloat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro |
| 22604 | fn zirFloatFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 22545 | fn zirFloatFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 22605 | const mod = sema.mod; | 22546 | const mod = sema.mod; |
| 22606 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 22547 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 22607 | const src = inst_data.src(); | 22548 | const src = block.nodeOffset(inst_data.src_node); |
| 22608 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; | 22549 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 22609 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 22550 | const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0); |
| 22610 | const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu_opt, "@floatFromInt"); | 22551 | const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu_opt, "@floatFromInt"); |
| 22611 | const operand = try sema.resolveInst(extra.rhs); | 22552 | const operand = try sema.resolveInst(extra.rhs); |
| 22612 | const operand_ty = sema.typeOf(operand); | 22553 | const operand_ty = sema.typeOf(operand); |
| ... | @@ -22646,11 +22587,11 @@ fn zirFloatFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro | ... | @@ -22646,11 +22587,11 @@ fn zirFloatFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro |
| 22646 | fn zirPtrFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 22587 | fn zirPtrFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 22647 | const mod = sema.mod; | 22588 | const mod = sema.mod; |
| 22648 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 22589 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 22649 | const src = inst_data.src(); | 22590 | const src = block.nodeOffset(inst_data.src_node); |
| 22650 | | 22591 | |
| 22651 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; | 22592 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 22652 | | 22593 | |
| 22653 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 22594 | const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0); |
| 22654 | const operand_res = try sema.resolveInst(extra.rhs); | 22595 | const operand_res = try sema.resolveInst(extra.rhs); |
| 22655 | | 22596 | |
| 22656 | const uncoerced_operand_ty = sema.typeOf(operand_res); | 22597 | const uncoerced_operand_ty = sema.typeOf(operand_res); |
| ... | @@ -22673,9 +22614,9 @@ fn zirPtrFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! | ... | @@ -22673,9 +22614,9 @@ fn zirPtrFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! |
| 22673 | | 22614 | |
| 22674 | if (ptr_ty.isSlice(mod)) { | 22615 | if (ptr_ty.isSlice(mod)) { |
| 22675 | const msg = msg: { | 22616 | const msg = msg: { |
| 22676 | const msg = try sema.errMsg(block, src, "integer cannot be converted to slice type '{}'", .{ptr_ty.fmt(sema.mod)}); | 22617 | const msg = try sema.errMsg(src, "integer cannot be converted to slice type '{}'", .{ptr_ty.fmt(sema.mod)}); |
| 22677 | errdefer msg.destroy(sema.gpa); | 22618 | errdefer msg.destroy(sema.gpa); |
| 22678 | try sema.errNote(block, src, msg, "slice length cannot be inferred from address", .{}); | 22619 | try sema.errNote(src, msg, "slice length cannot be inferred from address", .{}); |
| 22679 | break :msg msg; | 22620 | break :msg msg; |
| 22680 | }; | 22621 | }; |
| 22681 | return sema.failWithOwnedErrorMsg(block, msg); | 22622 | return sema.failWithOwnedErrorMsg(block, msg); |
| ... | @@ -22700,11 +22641,10 @@ fn zirPtrFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! | ... | @@ -22700,11 +22641,10 @@ fn zirPtrFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! |
| 22700 | } | 22641 | } |
| 22701 | if (try sema.typeRequiresComptime(ptr_ty)) { | 22642 | if (try sema.typeRequiresComptime(ptr_ty)) { |
| 22702 | return sema.failWithOwnedErrorMsg(block, msg: { | 22643 | return sema.failWithOwnedErrorMsg(block, msg: { |
| 22703 | 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)}); | 22644 | const msg = try sema.errMsg(src, "pointer to comptime-only type '{}' must be comptime-known, but operand is runtime-known", .{ptr_ty.fmt(mod)}); |
| 22704 | errdefer msg.destroy(sema.gpa); | 22645 | errdefer msg.destroy(sema.gpa); |
| 22705 | | 22646 | |
| 22706 | const src_decl = mod.declPtr(block.src_decl); | 22647 | try sema.explainWhyTypeIsComptime(msg, src, ptr_ty); |
| 22707 | try sema.explainWhyTypeIsComptime(msg, src_decl.toSrcLoc(src, mod), ptr_ty); | | |
| 22708 | break :msg msg; | 22648 | break :msg msg; |
| 22709 | }); | 22649 | }); |
| 22710 | } | 22650 | } |
| ... | @@ -22789,8 +22729,8 @@ fn zirErrorCast(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData | ... | @@ -22789,8 +22729,8 @@ fn zirErrorCast(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData |
| 22789 | const mod = sema.mod; | 22729 | const mod = sema.mod; |
| 22790 | const ip = &mod.intern_pool; | 22730 | const ip = &mod.intern_pool; |
| 22791 | const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data; | 22731 | const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data; |
| 22792 | const src = LazySrcLoc.nodeOffset(extra.node); | 22732 | const src = block.nodeOffset(extra.node); |
| 22793 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node }; | 22733 | const operand_src = block.builtinCallArgSrc(extra.node, 0); |
| 22794 | const base_dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_opt, "@errorCast"); | 22734 | const base_dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_opt, "@errorCast"); |
| 22795 | const operand = try sema.resolveInst(extra.rhs); | 22735 | const operand = try sema.resolveInst(extra.rhs); |
| 22796 | const base_operand_ty = sema.typeOf(operand); | 22736 | const base_operand_ty = sema.typeOf(operand); |
| ... | @@ -22810,12 +22750,12 @@ fn zirErrorCast(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData | ... | @@ -22810,12 +22750,12 @@ fn zirErrorCast(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData |
| 22810 | base_dest_ty.errorUnionPayload(mod).toIntern() != base_operand_ty.errorUnionPayload(mod).toIntern()) | 22750 | base_dest_ty.errorUnionPayload(mod).toIntern() != base_operand_ty.errorUnionPayload(mod).toIntern()) |
| 22811 | { | 22751 | { |
| 22812 | return sema.failWithOwnedErrorMsg(block, msg: { | 22752 | return sema.failWithOwnedErrorMsg(block, msg: { |
| 22813 | const msg = try sema.errMsg(block, src, "payload types of error unions must match", .{}); | 22753 | const msg = try sema.errMsg(src, "payload types of error unions must match", .{}); |
| 22814 | errdefer msg.destroy(sema.gpa); | 22754 | errdefer msg.destroy(sema.gpa); |
| 22815 | const dest_ty = base_dest_ty.errorUnionPayload(mod); | 22755 | const dest_ty = base_dest_ty.errorUnionPayload(mod); |
| 22816 | const operand_ty = base_operand_ty.errorUnionPayload(mod); | 22756 | const operand_ty = base_operand_ty.errorUnionPayload(mod); |
| 22817 | try sema.errNote(block, src, msg, "destination payload is '{}'", .{dest_ty.fmt(mod)}); | 22757 | try sema.errNote(src, msg, "destination payload is '{}'", .{dest_ty.fmt(mod)}); |
| 22818 | try sema.errNote(block, src, msg, "operand payload is '{}'", .{operand_ty.fmt(mod)}); | 22758 | try sema.errNote(src, msg, "operand payload is '{}'", .{operand_ty.fmt(mod)}); |
| 22819 | try addDeclaredHereNote(sema, msg, dest_ty); | 22759 | try addDeclaredHereNote(sema, msg, dest_ty); |
| 22820 | try addDeclaredHereNote(sema, msg, operand_ty); | 22760 | try addDeclaredHereNote(sema, msg, operand_ty); |
| 22821 | break :msg msg; | 22761 | break :msg msg; |
| ... | @@ -22914,8 +22854,8 @@ fn zirPtrCastFull(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDa | ... | @@ -22914,8 +22854,8 @@ fn zirPtrCastFull(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDa |
| 22914 | const FlagsInt = @typeInfo(Zir.Inst.FullPtrCastFlags).Struct.backing_integer.?; | 22854 | const FlagsInt = @typeInfo(Zir.Inst.FullPtrCastFlags).Struct.backing_integer.?; |
| 22915 | const flags: Zir.Inst.FullPtrCastFlags = @bitCast(@as(FlagsInt, @truncate(extended.small))); | 22855 | const flags: Zir.Inst.FullPtrCastFlags = @bitCast(@as(FlagsInt, @truncate(extended.small))); |
| 22916 | const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data; | 22856 | const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data; |
| 22917 | const src = LazySrcLoc.nodeOffset(extra.node); | 22857 | const src = block.nodeOffset(extra.node); |
| 22918 | const operand_src: LazySrcLoc = .{ .node_offset_ptrcast_operand = extra.node }; | 22858 | const operand_src = block.src(.{ .node_offset_ptrcast_operand = extra.node }); |
| 22919 | const operand = try sema.resolveInst(extra.rhs); | 22859 | const operand = try sema.resolveInst(extra.rhs); |
| 22920 | const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu, flags.needResultTypeBuiltinName()); | 22860 | const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu, flags.needResultTypeBuiltinName()); |
| 22921 | return sema.ptrCastFull( | 22861 | return sema.ptrCastFull( |
| ... | @@ -22931,8 +22871,8 @@ fn zirPtrCastFull(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDa | ... | @@ -22931,8 +22871,8 @@ fn zirPtrCastFull(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDa |
| 22931 | | 22871 | |
| 22932 | fn zirPtrCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 22872 | fn zirPtrCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 22933 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 22873 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 22934 | const src = inst_data.src(); | 22874 | const src = block.nodeOffset(inst_data.src_node); |
| 22935 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 22875 | const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0); |
| 22936 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; | 22876 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 22937 | const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu, "@ptrCast"); | 22877 | const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu, "@ptrCast"); |
| 22938 | const operand = try sema.resolveInst(extra.rhs); | 22878 | const operand = try sema.resolveInst(extra.rhs); |
| ... | @@ -23002,7 +22942,7 @@ fn ptrCastFull( | ... | @@ -23002,7 +22942,7 @@ fn ptrCastFull( |
| 23002 | if (src_info.flags.size == .C) break :check_size; | 22942 | if (src_info.flags.size == .C) break :check_size; |
| 23003 | if (dest_info.flags.size == .C) break :check_size; | 22943 | if (dest_info.flags.size == .C) break :check_size; |
| 23004 | return sema.failWithOwnedErrorMsg(block, msg: { | 22944 | return sema.failWithOwnedErrorMsg(block, msg: { |
| 23005 | const msg = try sema.errMsg(block, src, "cannot implicitly convert {s} pointer to {s} pointer", .{ | 22945 | const msg = try sema.errMsg(src, "cannot implicitly convert {s} pointer to {s} pointer", .{ |
| 23006 | pointerSizeString(src_info.flags.size), | 22946 | pointerSizeString(src_info.flags.size), |
| 23007 | pointerSizeString(dest_info.flags.size), | 22947 | pointerSizeString(dest_info.flags.size), |
| 23008 | }); | 22948 | }); |
| ... | @@ -23011,9 +22951,9 @@ fn ptrCastFull( | ... | @@ -23011,9 +22951,9 @@ fn ptrCastFull( |
| 23011 | (src_info.flags.size == .Slice or | 22951 | (src_info.flags.size == .Slice or |
| 23012 | (src_info.flags.size == .One and Type.fromInterned(src_info.child).zigTypeTag(mod) == .Array))) | 22952 | (src_info.flags.size == .One and Type.fromInterned(src_info.child).zigTypeTag(mod) == .Array))) |
| 23013 | { | 22953 | { |
| 23014 | try sema.errNote(block, src, msg, "use 'ptr' field to convert slice to many pointer", .{}); | 22954 | try sema.errNote(src, msg, "use 'ptr' field to convert slice to many pointer", .{}); |
| 23015 | } else { | 22955 | } else { |
| 23016 | try sema.errNote(block, src, msg, "use @ptrCast to change pointer size", .{}); | 22956 | try sema.errNote(src, msg, "use @ptrCast to change pointer size", .{}); |
| 23017 | } | 22957 | } |
| 23018 | break :msg msg; | 22958 | break :msg msg; |
| 23019 | }); | 22959 | }); |
| ... | @@ -23038,13 +22978,13 @@ fn ptrCastFull( | ... | @@ -23038,13 +22978,13 @@ fn ptrCastFull( |
| 23038 | ); | 22978 | ); |
| 23039 | if (imc_res == .ok) break :check_child; | 22979 | if (imc_res == .ok) break :check_child; |
| 23040 | return sema.failWithOwnedErrorMsg(block, msg: { | 22980 | return sema.failWithOwnedErrorMsg(block, msg: { |
| 23041 | const msg = try sema.errMsg(block, src, "pointer element type '{}' cannot coerce into element type '{}'", .{ | 22981 | const msg = try sema.errMsg(src, "pointer element type '{}' cannot coerce into element type '{}'", .{ |
| 23042 | src_child.fmt(mod), | 22982 | src_child.fmt(mod), |
| 23043 | dest_child.fmt(mod), | 22983 | dest_child.fmt(mod), |
| 23044 | }); | 22984 | }); |
| 23045 | errdefer msg.destroy(sema.gpa); | 22985 | errdefer msg.destroy(sema.gpa); |
| 23046 | try imc_res.report(sema, block, src, msg); | 22986 | try imc_res.report(sema, src, msg); |
| 23047 | try sema.errNote(block, src, msg, "use @ptrCast to cast pointer element type", .{}); | 22987 | try sema.errNote(src, msg, "use @ptrCast to cast pointer element type", .{}); |
| 23048 | break :msg msg; | 22988 | break :msg msg; |
| 23049 | }); | 22989 | }); |
| 23050 | } | 22990 | } |
| ... | @@ -23066,41 +23006,41 @@ fn ptrCastFull( | ... | @@ -23066,41 +23006,41 @@ fn ptrCastFull( |
| 23066 | } | 23006 | } |
| 23067 | return sema.failWithOwnedErrorMsg(block, msg: { | 23007 | return sema.failWithOwnedErrorMsg(block, msg: { |
| 23068 | const msg = if (src_info.sentinel == .none) blk: { | 23008 | const msg = if (src_info.sentinel == .none) blk: { |
| 23069 | break :blk try sema.errMsg(block, src, "destination pointer requires '{}' sentinel", .{ | 23009 | break :blk try sema.errMsg(src, "destination pointer requires '{}' sentinel", .{ |
| 23070 | Value.fromInterned(dest_info.sentinel).fmtValue(mod, sema), | 23010 | Value.fromInterned(dest_info.sentinel).fmtValue(mod, sema), |
| 23071 | }); | 23011 | }); |
| 23072 | } else blk: { | 23012 | } else blk: { |
| 23073 | break :blk try sema.errMsg(block, src, "pointer sentinel '{}' cannot coerce into pointer sentinel '{}'", .{ | 23013 | break :blk try sema.errMsg(src, "pointer sentinel '{}' cannot coerce into pointer sentinel '{}'", .{ |
| 23074 | Value.fromInterned(src_info.sentinel).fmtValue(mod, sema), | 23014 | Value.fromInterned(src_info.sentinel).fmtValue(mod, sema), |
| 23075 | Value.fromInterned(dest_info.sentinel).fmtValue(mod, sema), | 23015 | Value.fromInterned(dest_info.sentinel).fmtValue(mod, sema), |
| 23076 | }); | 23016 | }); |
| 23077 | }; | 23017 | }; |
| 23078 | errdefer msg.destroy(sema.gpa); | 23018 | errdefer msg.destroy(sema.gpa); |
| 23079 | try sema.errNote(block, src, msg, "use @ptrCast to cast pointer sentinel", .{}); | 23019 | try sema.errNote(src, msg, "use @ptrCast to cast pointer sentinel", .{}); |
| 23080 | break :msg msg; | 23020 | break :msg msg; |
| 23081 | }); | 23021 | }); |
| 23082 | } | 23022 | } |
| 23083 | | 23023 | |
| 23084 | if (src_info.packed_offset.host_size != dest_info.packed_offset.host_size) { | 23024 | if (src_info.packed_offset.host_size != dest_info.packed_offset.host_size) { |
| 23085 | return sema.failWithOwnedErrorMsg(block, msg: { | 23025 | return sema.failWithOwnedErrorMsg(block, msg: { |
| 23086 | const msg = try sema.errMsg(block, src, "pointer host size '{}' cannot coerce into pointer host size '{}'", .{ | 23026 | const msg = try sema.errMsg(src, "pointer host size '{}' cannot coerce into pointer host size '{}'", .{ |
| 23087 | src_info.packed_offset.host_size, | 23027 | src_info.packed_offset.host_size, |
| 23088 | dest_info.packed_offset.host_size, | 23028 | dest_info.packed_offset.host_size, |
| 23089 | }); | 23029 | }); |
| 23090 | errdefer msg.destroy(sema.gpa); | 23030 | errdefer msg.destroy(sema.gpa); |
| 23091 | try sema.errNote(block, src, msg, "use @ptrCast to cast pointer host size", .{}); | 23031 | try sema.errNote(src, msg, "use @ptrCast to cast pointer host size", .{}); |
| 23092 | break :msg msg; | 23032 | break :msg msg; |
| 23093 | }); | 23033 | }); |
| 23094 | } | 23034 | } |
| 23095 | | 23035 | |
| 23096 | if (src_info.packed_offset.bit_offset != dest_info.packed_offset.bit_offset) { | 23036 | if (src_info.packed_offset.bit_offset != dest_info.packed_offset.bit_offset) { |
| 23097 | return sema.failWithOwnedErrorMsg(block, msg: { | 23037 | return sema.failWithOwnedErrorMsg(block, msg: { |
| 23098 | const msg = try sema.errMsg(block, src, "pointer bit offset '{}' cannot coerce into pointer bit offset '{}'", .{ | 23038 | const msg = try sema.errMsg(src, "pointer bit offset '{}' cannot coerce into pointer bit offset '{}'", .{ |
| 23099 | src_info.packed_offset.bit_offset, | 23039 | src_info.packed_offset.bit_offset, |
| 23100 | dest_info.packed_offset.bit_offset, | 23040 | dest_info.packed_offset.bit_offset, |
| 23101 | }); | 23041 | }); |
| 23102 | errdefer msg.destroy(sema.gpa); | 23042 | errdefer msg.destroy(sema.gpa); |
| 23103 | try sema.errNote(block, src, msg, "use @ptrCast to cast pointer bit offset", .{}); | 23043 | try sema.errNote(src, msg, "use @ptrCast to cast pointer bit offset", .{}); |
| 23104 | break :msg msg; | 23044 | break :msg msg; |
| 23105 | }); | 23045 | }); |
| 23106 | } | 23046 | } |
| ... | @@ -23112,12 +23052,12 @@ fn ptrCastFull( | ... | @@ -23112,12 +23052,12 @@ fn ptrCastFull( |
| 23112 | if (dest_allows_zero) break :check_allowzero; | 23052 | if (dest_allows_zero) break :check_allowzero; |
| 23113 | | 23053 | |
| 23114 | return sema.failWithOwnedErrorMsg(block, msg: { | 23054 | return sema.failWithOwnedErrorMsg(block, msg: { |
| 23115 | const msg = try sema.errMsg(block, src, "'{}' could have null values which are illegal in type '{}'", .{ | 23055 | const msg = try sema.errMsg(src, "'{}' could have null values which are illegal in type '{}'", .{ |
| 23116 | operand_ty.fmt(mod), | 23056 | operand_ty.fmt(mod), |
| 23117 | dest_ty.fmt(mod), | 23057 | dest_ty.fmt(mod), |
| 23118 | }); | 23058 | }); |
| 23119 | errdefer msg.destroy(sema.gpa); | 23059 | errdefer msg.destroy(sema.gpa); |
| 23120 | try sema.errNote(block, src, msg, "use @ptrCast to assert the pointer is not null", .{}); | 23060 | try sema.errNote(src, msg, "use @ptrCast to assert the pointer is not null", .{}); |
| 23121 | break :msg msg; | 23061 | break :msg msg; |
| 23122 | }); | 23062 | }); |
| 23123 | } | 23063 | } |
| ... | @@ -23138,15 +23078,15 @@ fn ptrCastFull( | ... | @@ -23138,15 +23078,15 @@ fn ptrCastFull( |
| 23138 | if (!flags.align_cast) { | 23078 | if (!flags.align_cast) { |
| 23139 | if (dest_align.compare(.gt, src_align)) { | 23079 | if (dest_align.compare(.gt, src_align)) { |
| 23140 | return sema.failWithOwnedErrorMsg(block, msg: { | 23080 | return sema.failWithOwnedErrorMsg(block, msg: { |
| 23141 | const msg = try sema.errMsg(block, src, "{s} increases pointer alignment", .{operation}); | 23081 | const msg = try sema.errMsg(src, "{s} increases pointer alignment", .{operation}); |
| 23142 | errdefer msg.destroy(sema.gpa); | 23082 | errdefer msg.destroy(sema.gpa); |
| 23143 | try sema.errNote(block, operand_src, msg, "'{}' has alignment '{d}'", .{ | 23083 | try sema.errNote(operand_src, msg, "'{}' has alignment '{d}'", .{ |
| 23144 | operand_ty.fmt(mod), src_align.toByteUnits() orelse 0, | 23084 | operand_ty.fmt(mod), src_align.toByteUnits() orelse 0, |
| 23145 | }); | 23085 | }); |
| 23146 | try sema.errNote(block, src, msg, "'{}' has alignment '{d}'", .{ | 23086 | try sema.errNote(src, msg, "'{}' has alignment '{d}'", .{ |
| 23147 | dest_ty.fmt(mod), dest_align.toByteUnits() orelse 0, | 23087 | dest_ty.fmt(mod), dest_align.toByteUnits() orelse 0, |
| 23148 | }); | 23088 | }); |
| 23149 | try sema.errNote(block, src, msg, "use @alignCast to assert pointer alignment", .{}); | 23089 | try sema.errNote(src, msg, "use @alignCast to assert pointer alignment", .{}); |
| 23150 | break :msg msg; | 23090 | break :msg msg; |
| 23151 | }); | 23091 | }); |
| 23152 | } | 23092 | } |
| ... | @@ -23155,15 +23095,15 @@ fn ptrCastFull( | ... | @@ -23155,15 +23095,15 @@ fn ptrCastFull( |
| 23155 | if (!flags.addrspace_cast) { | 23095 | if (!flags.addrspace_cast) { |
| 23156 | if (src_info.flags.address_space != dest_info.flags.address_space) { | 23096 | if (src_info.flags.address_space != dest_info.flags.address_space) { |
| 23157 | return sema.failWithOwnedErrorMsg(block, msg: { | 23097 | return sema.failWithOwnedErrorMsg(block, msg: { |
| 23158 | const msg = try sema.errMsg(block, src, "{s} changes pointer address space", .{operation}); | 23098 | const msg = try sema.errMsg(src, "{s} changes pointer address space", .{operation}); |
| 23159 | errdefer msg.destroy(sema.gpa); | 23099 | errdefer msg.destroy(sema.gpa); |
| 23160 | try sema.errNote(block, operand_src, msg, "'{}' has address space '{s}'", .{ | 23100 | try sema.errNote(operand_src, msg, "'{}' has address space '{s}'", .{ |
| 23161 | operand_ty.fmt(mod), @tagName(src_info.flags.address_space), | 23101 | operand_ty.fmt(mod), @tagName(src_info.flags.address_space), |
| 23162 | }); | 23102 | }); |
| 23163 | try sema.errNote(block, src, msg, "'{}' has address space '{s}'", .{ | 23103 | try sema.errNote(src, msg, "'{}' has address space '{s}'", .{ |
| 23164 | dest_ty.fmt(mod), @tagName(dest_info.flags.address_space), | 23104 | dest_ty.fmt(mod), @tagName(dest_info.flags.address_space), |
| 23165 | }); | 23105 | }); |
| 23166 | try sema.errNote(block, src, msg, "use @addrSpaceCast to cast pointer address space", .{}); | 23106 | try sema.errNote(src, msg, "use @addrSpaceCast to cast pointer address space", .{}); |
| 23167 | break :msg msg; | 23107 | break :msg msg; |
| 23168 | }); | 23108 | }); |
| 23169 | } | 23109 | } |
| ... | @@ -23171,9 +23111,9 @@ fn ptrCastFull( | ... | @@ -23171,9 +23111,9 @@ fn ptrCastFull( |
| 23171 | // Some address space casts are always disallowed | 23111 | // Some address space casts are always disallowed |
| 23172 | if (!target_util.addrSpaceCastIsValid(mod.getTarget(), src_info.flags.address_space, dest_info.flags.address_space)) { | 23112 | if (!target_util.addrSpaceCastIsValid(mod.getTarget(), src_info.flags.address_space, dest_info.flags.address_space)) { |
| 23173 | return sema.failWithOwnedErrorMsg(block, msg: { | 23113 | return sema.failWithOwnedErrorMsg(block, msg: { |
| 23174 | const msg = try sema.errMsg(block, src, "invalid address space cast", .{}); | 23114 | const msg = try sema.errMsg(src, "invalid address space cast", .{}); |
| 23175 | errdefer msg.destroy(sema.gpa); | 23115 | errdefer msg.destroy(sema.gpa); |
| 23176 | try sema.errNote(block, operand_src, msg, "address space '{s}' is not compatible with address space '{s}'", .{ | 23116 | try sema.errNote(operand_src, msg, "address space '{s}' is not compatible with address space '{s}'", .{ |
| 23177 | @tagName(src_info.flags.address_space), | 23117 | @tagName(src_info.flags.address_space), |
| 23178 | @tagName(dest_info.flags.address_space), | 23118 | @tagName(dest_info.flags.address_space), |
| 23179 | }); | 23119 | }); |
| ... | @@ -23185,9 +23125,9 @@ fn ptrCastFull( | ... | @@ -23185,9 +23125,9 @@ fn ptrCastFull( |
| 23185 | if (!flags.const_cast) { | 23125 | if (!flags.const_cast) { |
| 23186 | if (src_info.flags.is_const and !dest_info.flags.is_const) { | 23126 | if (src_info.flags.is_const and !dest_info.flags.is_const) { |
| 23187 | return sema.failWithOwnedErrorMsg(block, msg: { | 23127 | return sema.failWithOwnedErrorMsg(block, msg: { |
| 23188 | const msg = try sema.errMsg(block, src, "{s} discards const qualifier", .{operation}); | 23128 | const msg = try sema.errMsg(src, "{s} discards const qualifier", .{operation}); |
| 23189 | errdefer msg.destroy(sema.gpa); | 23129 | errdefer msg.destroy(sema.gpa); |
| 23190 | try sema.errNote(block, src, msg, "use @constCast to discard const qualifier", .{}); | 23130 | try sema.errNote(src, msg, "use @constCast to discard const qualifier", .{}); |
| 23191 | break :msg msg; | 23131 | break :msg msg; |
| 23192 | }); | 23132 | }); |
| 23193 | } | 23133 | } |
| ... | @@ -23196,9 +23136,9 @@ fn ptrCastFull( | ... | @@ -23196,9 +23136,9 @@ fn ptrCastFull( |
| 23196 | if (!flags.volatile_cast) { | 23136 | if (!flags.volatile_cast) { |
| 23197 | if (src_info.flags.is_volatile and !dest_info.flags.is_volatile) { | 23137 | if (src_info.flags.is_volatile and !dest_info.flags.is_volatile) { |
| 23198 | return sema.failWithOwnedErrorMsg(block, msg: { | 23138 | return sema.failWithOwnedErrorMsg(block, msg: { |
| 23199 | const msg = try sema.errMsg(block, src, "{s} discards volatile qualifier", .{operation}); | 23139 | const msg = try sema.errMsg(src, "{s} discards volatile qualifier", .{operation}); |
| 23200 | errdefer msg.destroy(sema.gpa); | 23140 | errdefer msg.destroy(sema.gpa); |
| 23201 | try sema.errNote(block, src, msg, "use @volatileCast to discard volatile qualifier", .{}); | 23141 | try sema.errNote(src, msg, "use @volatileCast to discard volatile qualifier", .{}); |
| 23202 | break :msg msg; | 23142 | break :msg msg; |
| 23203 | }); | 23143 | }); |
| 23204 | } | 23144 | } |
| ... | @@ -23347,8 +23287,8 @@ fn zirPtrCastNoDest(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.Inst | ... | @@ -23347,8 +23287,8 @@ fn zirPtrCastNoDest(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.Inst |
| 23347 | const FlagsInt = @typeInfo(Zir.Inst.FullPtrCastFlags).Struct.backing_integer.?; | 23287 | const FlagsInt = @typeInfo(Zir.Inst.FullPtrCastFlags).Struct.backing_integer.?; |
| 23348 | const flags: Zir.Inst.FullPtrCastFlags = @bitCast(@as(FlagsInt, @truncate(extended.small))); | 23288 | const flags: Zir.Inst.FullPtrCastFlags = @bitCast(@as(FlagsInt, @truncate(extended.small))); |
| 23349 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; | 23289 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; |
| 23350 | const src = LazySrcLoc.nodeOffset(extra.node); | 23290 | const src = block.nodeOffset(extra.node); |
| 23351 | const operand_src: LazySrcLoc = .{ .node_offset_ptrcast_operand = extra.node }; | 23291 | const operand_src = block.src(.{ .node_offset_ptrcast_operand = extra.node }); |
| 23352 | const operand = try sema.resolveInst(extra.operand); | 23292 | const operand = try sema.resolveInst(extra.operand); |
| 23353 | const operand_ty = sema.typeOf(operand); | 23293 | const operand_ty = sema.typeOf(operand); |
| 23354 | try sema.checkPtrOperand(block, operand_src, operand_ty); | 23294 | try sema.checkPtrOperand(block, operand_src, operand_ty); |
| ... | @@ -23378,8 +23318,8 @@ fn zirPtrCastNoDest(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.Inst | ... | @@ -23378,8 +23318,8 @@ fn zirPtrCastNoDest(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.Inst |
| 23378 | fn zirTruncate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 23318 | fn zirTruncate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 23379 | const mod = sema.mod; | 23319 | const mod = sema.mod; |
| 23380 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 23320 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 23381 | const src = inst_data.src(); | 23321 | const src = block.nodeOffset(inst_data.src_node); |
| 23382 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 23322 | const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0); |
| 23383 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; | 23323 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 23384 | const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu_opt, "@truncate"); | 23324 | const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu_opt, "@truncate"); |
| 23385 | const dest_scalar_ty = try sema.checkIntOrVectorAllowComptime(block, dest_ty, src); | 23325 | const dest_scalar_ty = try sema.checkIntOrVectorAllowComptime(block, dest_ty, src); |
| ... | @@ -23417,16 +23357,15 @@ fn zirTruncate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -23417,16 +23357,15 @@ fn zirTruncate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 23417 | if (operand_info.bits < dest_info.bits) { | 23357 | if (operand_info.bits < dest_info.bits) { |
| 23418 | const msg = msg: { | 23358 | const msg = msg: { |
| 23419 | const msg = try sema.errMsg( | 23359 | const msg = try sema.errMsg( |
| 23420 | block, | | |
| 23421 | src, | 23360 | src, |
| 23422 | "destination type '{}' has more bits than source type '{}'", | 23361 | "destination type '{}' has more bits than source type '{}'", |
| 23423 | .{ dest_ty.fmt(mod), operand_ty.fmt(mod) }, | 23362 | .{ dest_ty.fmt(mod), operand_ty.fmt(mod) }, |
| 23424 | ); | 23363 | ); |
| 23425 | errdefer msg.destroy(sema.gpa); | 23364 | errdefer msg.destroy(sema.gpa); |
| 23426 | try sema.errNote(block, src, msg, "destination type has {d} bits", .{ | 23365 | try sema.errNote(src, msg, "destination type has {d} bits", .{ |
| 23427 | dest_info.bits, | 23366 | dest_info.bits, |
| 23428 | }); | 23367 | }); |
| 23429 | try sema.errNote(block, operand_src, msg, "operand type has {d} bits", .{ | 23368 | try sema.errNote(operand_src, msg, "operand type has {d} bits", .{ |
| 23430 | operand_info.bits, | 23369 | operand_info.bits, |
| 23431 | }); | 23370 | }); |
| 23432 | break :msg msg; | 23371 | break :msg msg; |
| ... | @@ -23468,8 +23407,8 @@ fn zirBitCount( | ... | @@ -23468,8 +23407,8 @@ fn zirBitCount( |
| 23468 | ) CompileError!Air.Inst.Ref { | 23407 | ) CompileError!Air.Inst.Ref { |
| 23469 | const mod = sema.mod; | 23408 | const mod = sema.mod; |
| 23470 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; | 23409 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 23471 | const src = inst_data.src(); | 23410 | const src = block.nodeOffset(inst_data.src_node); |
| 23472 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 23411 | const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0); |
| 23473 | const operand = try sema.resolveInst(inst_data.operand); | 23412 | const operand = try sema.resolveInst(inst_data.operand); |
| 23474 | const operand_ty = sema.typeOf(operand); | 23413 | const operand_ty = sema.typeOf(operand); |
| 23475 | _ = try sema.checkIntOrVector(block, operand, operand_src); | 23414 | _ = try sema.checkIntOrVector(block, operand, operand_src); |
| ... | @@ -23522,8 +23461,8 @@ fn zirBitCount( | ... | @@ -23522,8 +23461,8 @@ fn zirBitCount( |
| 23522 | fn zirByteSwap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 23461 | fn zirByteSwap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 23523 | const mod = sema.mod; | 23462 | const mod = sema.mod; |
| 23524 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; | 23463 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 23525 | const src = inst_data.src(); | 23464 | const src = block.nodeOffset(inst_data.src_node); |
| 23526 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 23465 | const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0); |
| 23527 | const operand = try sema.resolveInst(inst_data.operand); | 23466 | const operand = try sema.resolveInst(inst_data.operand); |
| 23528 | const operand_ty = sema.typeOf(operand); | 23467 | const operand_ty = sema.typeOf(operand); |
| 23529 | const scalar_ty = try sema.checkIntOrVector(block, operand, operand_src); | 23468 | const scalar_ty = try sema.checkIntOrVector(block, operand, operand_src); |
| ... | @@ -23578,8 +23517,8 @@ fn zirByteSwap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -23578,8 +23517,8 @@ fn zirByteSwap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 23578 | | 23517 | |
| 23579 | fn zirBitReverse(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 23518 | fn zirBitReverse(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 23580 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; | 23519 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 23581 | const src = inst_data.src(); | 23520 | const src = block.nodeOffset(inst_data.src_node); |
| 23582 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 23521 | const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0); |
| 23583 | const operand = try sema.resolveInst(inst_data.operand); | 23522 | const operand = try sema.resolveInst(inst_data.operand); |
| 23584 | const operand_ty = sema.typeOf(operand); | 23523 | const operand_ty = sema.typeOf(operand); |
| 23585 | const scalar_ty = try sema.checkIntOrVector(block, operand, operand_src); | 23524 | const scalar_ty = try sema.checkIntOrVector(block, operand, operand_src); |
| ... | @@ -23637,9 +23576,9 @@ fn zirOffsetOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai | ... | @@ -23637,9 +23576,9 @@ fn zirOffsetOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 23637 | | 23576 | |
| 23638 | fn bitOffsetOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!u64 { | 23577 | fn bitOffsetOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!u64 { |
| 23639 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 23578 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 23640 | const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node }; | 23579 | const src = block.src(.{ .node_offset_bin_op = inst_data.src_node }); |
| 23641 | const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node }; | 23580 | const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node }); |
| 23642 | const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node }; | 23581 | const rhs_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node }); |
| 23643 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; | 23582 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 23644 | | 23583 | |
| 23645 | const ty = try sema.resolveType(block, lhs_src, extra.lhs); | 23584 | const ty = try sema.resolveType(block, lhs_src, extra.lhs); |
| ... | @@ -23752,14 +23691,13 @@ fn checkPtrOperand( | ... | @@ -23752,14 +23691,13 @@ fn checkPtrOperand( |
| 23752 | .Fn => { | 23691 | .Fn => { |
| 23753 | const msg = msg: { | 23692 | const msg = msg: { |
| 23754 | const msg = try sema.errMsg( | 23693 | const msg = try sema.errMsg( |
| 23755 | block, | | |
| 23756 | ty_src, | 23694 | ty_src, |
| 23757 | "expected pointer, found '{}'", | 23695 | "expected pointer, found '{}'", |
| 23758 | .{ty.fmt(mod)}, | 23696 | .{ty.fmt(mod)}, |
| 23759 | ); | 23697 | ); |
| 23760 | errdefer msg.destroy(sema.gpa); | 23698 | errdefer msg.destroy(sema.gpa); |
| 23761 | | 23699 | |
| 23762 | try sema.errNote(block, ty_src, msg, "use '&' to obtain a function pointer", .{}); | 23700 | try sema.errNote(ty_src, msg, "use '&' to obtain a function pointer", .{}); |
| 23763 | | 23701 | |
| 23764 | break :msg msg; | 23702 | break :msg msg; |
| 23765 | }; | 23703 | }; |
| ... | @@ -23784,14 +23722,13 @@ fn checkPtrType( | ... | @@ -23784,14 +23722,13 @@ fn checkPtrType( |
| 23784 | .Fn => { | 23722 | .Fn => { |
| 23785 | const msg = msg: { | 23723 | const msg = msg: { |
| 23786 | const msg = try sema.errMsg( | 23724 | const msg = try sema.errMsg( |
| 23787 | block, | | |
| 23788 | ty_src, | 23725 | ty_src, |
| 23789 | "expected pointer type, found '{}'", | 23726 | "expected pointer type, found '{}'", |
| 23790 | .{ty.fmt(mod)}, | 23727 | .{ty.fmt(mod)}, |
| 23791 | ); | 23728 | ); |
| 23792 | errdefer msg.destroy(sema.gpa); | 23729 | errdefer msg.destroy(sema.gpa); |
| 23793 | | 23730 | |
| 23794 | try sema.errNote(block, ty_src, msg, "use '*const ' to make a function pointer type", .{}); | 23731 | try sema.errNote(ty_src, msg, "use '*const ' to make a function pointer type", .{}); |
| 23795 | | 23732 | |
| 23796 | break :msg msg; | 23733 | break :msg msg; |
| 23797 | }; | 23734 | }; |
| ... | @@ -24045,26 +23982,26 @@ fn checkVectorizableBinaryOperands( | ... | @@ -24045,26 +23982,26 @@ fn checkVectorizableBinaryOperands( |
| 24045 | const rhs_len = rhs_ty.arrayLen(mod); | 23982 | const rhs_len = rhs_ty.arrayLen(mod); |
| 24046 | if (lhs_len != rhs_len) { | 23983 | if (lhs_len != rhs_len) { |
| 24047 | const msg = msg: { | 23984 | const msg = msg: { |
| 24048 | const msg = try sema.errMsg(block, src, "vector length mismatch", .{}); | 23985 | const msg = try sema.errMsg(src, "vector length mismatch", .{}); |
| 24049 | errdefer msg.destroy(sema.gpa); | 23986 | errdefer msg.destroy(sema.gpa); |
| 24050 | try sema.errNote(block, lhs_src, msg, "length {d} here", .{lhs_len}); | 23987 | try sema.errNote(lhs_src, msg, "length {d} here", .{lhs_len}); |
| 24051 | try sema.errNote(block, rhs_src, msg, "length {d} here", .{rhs_len}); | 23988 | try sema.errNote(rhs_src, msg, "length {d} here", .{rhs_len}); |
| 24052 | break :msg msg; | 23989 | break :msg msg; |
| 24053 | }; | 23990 | }; |
| 24054 | return sema.failWithOwnedErrorMsg(block, msg); | 23991 | return sema.failWithOwnedErrorMsg(block, msg); |
| 24055 | } | 23992 | } |
| 24056 | } else { | 23993 | } else { |
| 24057 | const msg = msg: { | 23994 | const msg = msg: { |
| 24058 | const msg = try sema.errMsg(block, src, "mixed scalar and vector operands: '{}' and '{}'", .{ | 23995 | const msg = try sema.errMsg(src, "mixed scalar and vector operands: '{}' and '{}'", .{ |
| 24059 | lhs_ty.fmt(mod), rhs_ty.fmt(mod), | 23996 | lhs_ty.fmt(mod), rhs_ty.fmt(mod), |
| 24060 | }); | 23997 | }); |
| 24061 | errdefer msg.destroy(sema.gpa); | 23998 | errdefer msg.destroy(sema.gpa); |
| 24062 | if (lhs_is_vector) { | 23999 | if (lhs_is_vector) { |
| 24063 | try sema.errNote(block, lhs_src, msg, "vector here", .{}); | 24000 | try sema.errNote(lhs_src, msg, "vector here", .{}); |
| 24064 | try sema.errNote(block, rhs_src, msg, "scalar here", .{}); | 24001 | try sema.errNote(rhs_src, msg, "scalar here", .{}); |
| 24065 | } else { | 24002 | } else { |
| 24066 | try sema.errNote(block, lhs_src, msg, "scalar here", .{}); | 24003 | try sema.errNote(lhs_src, msg, "scalar here", .{}); |
| 24067 | try sema.errNote(block, rhs_src, msg, "vector here", .{}); | 24004 | try sema.errNote(rhs_src, msg, "vector here", .{}); |
| 24068 | } | 24005 | } |
| 24069 | break :msg msg; | 24006 | break :msg msg; |
| 24070 | }; | 24007 | }; |
| ... | @@ -24072,12 +24009,6 @@ fn checkVectorizableBinaryOperands( | ... | @@ -24072,12 +24009,6 @@ fn checkVectorizableBinaryOperands( |
| 24072 | } | 24009 | } |
| 24073 | } | 24010 | } |
| 24074 | | 24011 | |
| 24075 | fn maybeOptionsSrc(sema: *Sema, block: *Block, base_src: LazySrcLoc, wanted: []const u8) LazySrcLoc { | | |
| 24076 | if (base_src == .unneeded) return .unneeded; | | |
| 24077 | const mod = sema.mod; | | |
| 24078 | return mod.optionsSrc(mod.declPtr(block.src_decl), base_src, wanted); | | |
| 24079 | } | | |
| 24080 | | | |
| 24081 | fn resolveExportOptions( | 24012 | fn resolveExportOptions( |
| 24082 | sema: *Sema, | 24013 | sema: *Sema, |
| 24083 | block: *Block, | 24014 | block: *Block, |
| ... | @@ -24091,10 +24022,10 @@ fn resolveExportOptions( | ... | @@ -24091,10 +24022,10 @@ fn resolveExportOptions( |
| 24091 | const air_ref = try sema.resolveInst(zir_ref); | 24022 | const air_ref = try sema.resolveInst(zir_ref); |
| 24092 | const options = try sema.coerce(block, export_options_ty, air_ref, src); | 24023 | const options = try sema.coerce(block, export_options_ty, air_ref, src); |
| 24093 | | 24024 | |
| 24094 | const name_src = sema.maybeOptionsSrc(block, src, "name"); | 24025 | const name_src = block.src(.{ .init_field_name = src.offset.node_offset_builtin_call_arg.builtin_call_node }); |
| 24095 | const linkage_src = sema.maybeOptionsSrc(block, src, "linkage"); | 24026 | const linkage_src = block.src(.{ .init_field_linkage = src.offset.node_offset_builtin_call_arg.builtin_call_node }); |
| 24096 | const section_src = sema.maybeOptionsSrc(block, src, "section"); | 24027 | const section_src = block.src(.{ .init_field_section = src.offset.node_offset_builtin_call_arg.builtin_call_node }); |
| 24097 | const visibility_src = sema.maybeOptionsSrc(block, src, "visibility"); | 24028 | const visibility_src = block.src(.{ .init_field_visibility = src.offset.node_offset_builtin_call_arg.builtin_call_node }); |
| 24098 | | 24029 | |
| 24099 | const name_operand = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "name", .no_embedded_nulls), name_src); | 24030 | const name_operand = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "name", .no_embedded_nulls), name_src); |
| 24100 | const name = try sema.toConstString(block, name_src, name_operand, .{ | 24031 | const name = try sema.toConstString(block, name_src, name_operand, .{ |
| ... | @@ -24191,14 +24122,14 @@ fn zirCmpxchg( | ... | @@ -24191,14 +24122,14 @@ fn zirCmpxchg( |
| 24191 | 1 => .cmpxchg_strong, | 24122 | 1 => .cmpxchg_strong, |
| 24192 | else => unreachable, | 24123 | else => unreachable, |
| 24193 | }; | 24124 | }; |
| 24194 | const src = LazySrcLoc.nodeOffset(extra.node); | 24125 | const src = block.nodeOffset(extra.node); |
| 24195 | // zig fmt: off | 24126 | // zig fmt: off |
| 24196 | const elem_ty_src : LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node }; | 24127 | const elem_ty_src = block.builtinCallArgSrc(extra.node, 0); |
| 24197 | const ptr_src : LazySrcLoc = .{ .node_offset_builtin_call_arg1 = extra.node }; | 24128 | const ptr_src = block.builtinCallArgSrc(extra.node, 1); |
| 24198 | const expected_src : LazySrcLoc = .{ .node_offset_builtin_call_arg2 = extra.node }; | 24129 | const expected_src = block.builtinCallArgSrc(extra.node, 2); |
| 24199 | const new_value_src : LazySrcLoc = .{ .node_offset_builtin_call_arg3 = extra.node }; | 24130 | const new_value_src = block.builtinCallArgSrc(extra.node, 3); |
| 24200 | const success_order_src: LazySrcLoc = .{ .node_offset_builtin_call_arg4 = extra.node }; | 24131 | const success_order_src = block.builtinCallArgSrc(extra.node, 4); |
| 24201 | const failure_order_src: LazySrcLoc = .{ .node_offset_builtin_call_arg5 = extra.node }; | 24132 | const failure_order_src = block.builtinCallArgSrc(extra.node, 5); |
| 24202 | // zig fmt: on | 24133 | // zig fmt: on |
| 24203 | const expected_value = try sema.resolveInst(extra.expected_value); | 24134 | const expected_value = try sema.resolveInst(extra.expected_value); |
| 24204 | const elem_ty = sema.typeOf(expected_value); | 24135 | const elem_ty = sema.typeOf(expected_value); |
| ... | @@ -24287,8 +24218,8 @@ fn zirSplat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.I | ... | @@ -24287,8 +24218,8 @@ fn zirSplat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.I |
| 24287 | const mod = sema.mod; | 24218 | const mod = sema.mod; |
| 24288 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 24219 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 24289 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; | 24220 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 24290 | const src = inst_data.src(); | 24221 | const src = block.nodeOffset(inst_data.src_node); |
| 24291 | const scalar_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 24222 | const scalar_src = block.builtinCallArgSrc(inst_data.src_node, 0); |
| 24292 | const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu_opt, "@splat"); | 24223 | const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu_opt, "@splat"); |
| 24293 | | 24224 | |
| 24294 | if (!dest_ty.isVector(mod)) return sema.fail(block, src, "expected vector type, found '{}'", .{dest_ty.fmt(mod)}); | 24225 | if (!dest_ty.isVector(mod)) return sema.fail(block, src, "expected vector type, found '{}'", .{dest_ty.fmt(mod)}); |
| ... | @@ -24309,15 +24240,15 @@ fn zirSplat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.I | ... | @@ -24309,15 +24240,15 @@ fn zirSplat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.I |
| 24309 | return Air.internedToRef((try sema.splat(dest_ty, scalar_val)).toIntern()); | 24240 | return Air.internedToRef((try sema.splat(dest_ty, scalar_val)).toIntern()); |
| 24310 | } | 24241 | } |
| 24311 | | 24242 | |
| 24312 | try sema.requireRuntimeBlock(block, inst_data.src(), scalar_src); | 24243 | try sema.requireRuntimeBlock(block, src, scalar_src); |
| 24313 | return block.addTyOp(.splat, dest_ty, scalar); | 24244 | return block.addTyOp(.splat, dest_ty, scalar); |
| 24314 | } | 24245 | } |
| 24315 | | 24246 | |
| 24316 | fn zirReduce(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 24247 | fn zirReduce(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 24317 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 24248 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 24318 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; | 24249 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 24319 | const op_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 24250 | const op_src = block.builtinCallArgSrc(inst_data.src_node, 0); |
| 24320 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; | 24251 | const operand_src = block.builtinCallArgSrc(inst_data.src_node, 1); |
| 24321 | const operation = try sema.resolveBuiltinEnum(block, op_src, extra.lhs, "ReduceOp", .{ | 24252 | const operation = try sema.resolveBuiltinEnum(block, op_src, extra.lhs, "ReduceOp", .{ |
| 24322 | .needed_comptime_reason = "@reduce operation must be comptime-known", | 24253 | .needed_comptime_reason = "@reduce operation must be comptime-known", |
| 24323 | }); | 24254 | }); |
| ... | @@ -24374,7 +24305,7 @@ fn zirReduce(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. | ... | @@ -24374,7 +24305,7 @@ fn zirReduce(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. |
| 24374 | return Air.internedToRef(accum.toIntern()); | 24305 | return Air.internedToRef(accum.toIntern()); |
| 24375 | } | 24306 | } |
| 24376 | | 24307 | |
| 24377 | try sema.requireRuntimeBlock(block, inst_data.src(), operand_src); | 24308 | try sema.requireRuntimeBlock(block, block.nodeOffset(inst_data.src_node), operand_src); |
| 24378 | return block.addInst(.{ | 24309 | return block.addInst(.{ |
| 24379 | .tag = if (block.float_mode == .optimized) .reduce_optimized else .reduce, | 24310 | .tag = if (block.float_mode == .optimized) .reduce_optimized else .reduce, |
| 24380 | .data = .{ .reduce = .{ | 24311 | .data = .{ .reduce = .{ |
| ... | @@ -24388,8 +24319,8 @@ fn zirShuffle(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air | ... | @@ -24388,8 +24319,8 @@ fn zirShuffle(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 24388 | const mod = sema.mod; | 24319 | const mod = sema.mod; |
| 24389 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 24320 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 24390 | const extra = sema.code.extraData(Zir.Inst.Shuffle, inst_data.payload_index).data; | 24321 | const extra = sema.code.extraData(Zir.Inst.Shuffle, inst_data.payload_index).data; |
| 24391 | const elem_ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 24322 | const elem_ty_src = block.builtinCallArgSrc(inst_data.src_node, 0); |
| 24392 | const mask_src: LazySrcLoc = .{ .node_offset_builtin_call_arg3 = inst_data.src_node }; | 24323 | const mask_src = block.builtinCallArgSrc(inst_data.src_node, 3); |
| 24393 | | 24324 | |
| 24394 | const elem_ty = try sema.resolveType(block, elem_ty_src, extra.elem_type); | 24325 | const elem_ty = try sema.resolveType(block, elem_ty_src, extra.elem_type); |
| 24395 | try sema.checkVectorElemType(block, elem_ty_src, elem_ty); | 24326 | try sema.checkVectorElemType(block, elem_ty_src, elem_ty); |
| ... | @@ -24424,9 +24355,9 @@ fn analyzeShuffle( | ... | @@ -24424,9 +24355,9 @@ fn analyzeShuffle( |
| 24424 | mask_len: u32, | 24355 | mask_len: u32, |
| 24425 | ) CompileError!Air.Inst.Ref { | 24356 | ) CompileError!Air.Inst.Ref { |
| 24426 | const mod = sema.mod; | 24357 | const mod = sema.mod; |
| 24427 | const a_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = src_node }; | 24358 | const a_src = block.builtinCallArgSrc(src_node, 1); |
| 24428 | const b_src: LazySrcLoc = .{ .node_offset_builtin_call_arg2 = src_node }; | 24359 | const b_src = block.builtinCallArgSrc(src_node, 2); |
| 24429 | const mask_src: LazySrcLoc = .{ .node_offset_builtin_call_arg3 = src_node }; | 24360 | const mask_src = block.builtinCallArgSrc(src_node, 3); |
| 24430 | var a = a_arg; | 24361 | var a = a_arg; |
| 24431 | var b = b_arg; | 24362 | var b = b_arg; |
| 24432 | | 24363 | |
| ... | @@ -24490,16 +24421,16 @@ fn analyzeShuffle( | ... | @@ -24490,16 +24421,16 @@ fn analyzeShuffle( |
| 24490 | } | 24421 | } |
| 24491 | if (unsigned >= operand_info[chosen][0]) { | 24422 | if (unsigned >= operand_info[chosen][0]) { |
| 24492 | const msg = msg: { | 24423 | const msg = msg: { |
| 24493 | const msg = try sema.errMsg(block, mask_src, "mask index '{d}' has out-of-bounds selection", .{i}); | 24424 | const msg = try sema.errMsg(mask_src, "mask index '{d}' has out-of-bounds selection", .{i}); |
| 24494 | errdefer msg.destroy(sema.gpa); | 24425 | errdefer msg.destroy(sema.gpa); |
| 24495 | | 24426 | |
| 24496 | try sema.errNote(block, operand_info[chosen][1], msg, "selected index '{d}' out of bounds of '{}'", .{ | 24427 | try sema.errNote(operand_info[chosen][1], msg, "selected index '{d}' out of bounds of '{}'", .{ |
| 24497 | unsigned, | 24428 | unsigned, |
| 24498 | operand_info[chosen][2].fmt(sema.mod), | 24429 | operand_info[chosen][2].fmt(sema.mod), |
| 24499 | }); | 24430 | }); |
| 24500 | | 24431 | |
| 24501 | if (chosen == 0) { | 24432 | if (chosen == 0) { |
| 24502 | try sema.errNote(block, b_src, msg, "selections from the second vector are specified with negative numbers", .{}); | 24433 | try sema.errNote(b_src, msg, "selections from the second vector are specified with negative numbers", .{}); |
| 24503 | } | 24434 | } |
| 24504 | | 24435 | |
| 24505 | break :msg msg; | 24436 | break :msg msg; |
| ... | @@ -24577,11 +24508,11 @@ fn zirSelect(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) C | ... | @@ -24577,11 +24508,11 @@ fn zirSelect(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) C |
| 24577 | const mod = sema.mod; | 24508 | const mod = sema.mod; |
| 24578 | const extra = sema.code.extraData(Zir.Inst.Select, extended.operand).data; | 24509 | const extra = sema.code.extraData(Zir.Inst.Select, extended.operand).data; |
| 24579 | | 24510 | |
| 24580 | const src = LazySrcLoc.nodeOffset(extra.node); | 24511 | const src = block.nodeOffset(extra.node); |
| 24581 | const elem_ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node }; | 24512 | const elem_ty_src = block.builtinCallArgSrc(extra.node, 0); |
| 24582 | const pred_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = extra.node }; | 24513 | const pred_src = block.builtinCallArgSrc(extra.node, 1); |
| 24583 | const a_src: LazySrcLoc = .{ .node_offset_builtin_call_arg2 = extra.node }; | 24514 | const a_src = block.builtinCallArgSrc(extra.node, 2); |
| 24584 | const b_src: LazySrcLoc = .{ .node_offset_builtin_call_arg3 = extra.node }; | 24515 | const b_src = block.builtinCallArgSrc(extra.node, 3); |
| 24585 | | 24516 | |
| 24586 | const elem_ty = try sema.resolveType(block, elem_ty_src, extra.elem_type); | 24517 | const elem_ty = try sema.resolveType(block, elem_ty_src, extra.elem_type); |
| 24587 | try sema.checkVectorElemType(block, elem_ty_src, elem_ty); | 24518 | try sema.checkVectorElemType(block, elem_ty_src, elem_ty); |
| ... | @@ -24668,9 +24599,9 @@ fn zirAtomicLoad(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! | ... | @@ -24668,9 +24599,9 @@ fn zirAtomicLoad(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! |
| 24668 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 24599 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 24669 | const extra = sema.code.extraData(Zir.Inst.AtomicLoad, inst_data.payload_index).data; | 24600 | const extra = sema.code.extraData(Zir.Inst.AtomicLoad, inst_data.payload_index).data; |
| 24670 | // zig fmt: off | 24601 | // zig fmt: off |
| 24671 | const elem_ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 24602 | const elem_ty_src = block.builtinCallArgSrc(inst_data.src_node, 0); |
| 24672 | const ptr_src : LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; | 24603 | const ptr_src = block.builtinCallArgSrc(inst_data.src_node, 1); |
| 24673 | const order_src : LazySrcLoc = .{ .node_offset_builtin_call_arg2 = inst_data.src_node }; | 24604 | const order_src = block.builtinCallArgSrc(inst_data.src_node, 2); |
| 24674 | // zig fmt: on | 24605 | // zig fmt: on |
| 24675 | const elem_ty = try sema.resolveType(block, elem_ty_src, extra.elem_type); | 24606 | const elem_ty = try sema.resolveType(block, elem_ty_src, extra.elem_type); |
| 24676 | const uncasted_ptr = try sema.resolveInst(extra.ptr); | 24607 | const uncasted_ptr = try sema.resolveInst(extra.ptr); |
| ... | @@ -24701,7 +24632,7 @@ fn zirAtomicLoad(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! | ... | @@ -24701,7 +24632,7 @@ fn zirAtomicLoad(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! |
| 24701 | } | 24632 | } |
| 24702 | } | 24633 | } |
| 24703 | | 24634 | |
| 24704 | try sema.requireRuntimeBlock(block, inst_data.src(), ptr_src); | 24635 | try sema.requireRuntimeBlock(block, block.nodeOffset(inst_data.src_node), ptr_src); |
| 24705 | return block.addInst(.{ | 24636 | return block.addInst(.{ |
| 24706 | .tag = .atomic_load, | 24637 | .tag = .atomic_load, |
| 24707 | .data = .{ .atomic_load = .{ | 24638 | .data = .{ .atomic_load = .{ |
| ... | @@ -24715,13 +24646,13 @@ fn zirAtomicRmw(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A | ... | @@ -24715,13 +24646,13 @@ fn zirAtomicRmw(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 24715 | const mod = sema.mod; | 24646 | const mod = sema.mod; |
| 24716 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 24647 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 24717 | const extra = sema.code.extraData(Zir.Inst.AtomicRmw, inst_data.payload_index).data; | 24648 | const extra = sema.code.extraData(Zir.Inst.AtomicRmw, inst_data.payload_index).data; |
| 24718 | const src = inst_data.src(); | 24649 | const src = block.nodeOffset(inst_data.src_node); |
| 24719 | // zig fmt: off | 24650 | // zig fmt: off |
| 24720 | const elem_ty_src : LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 24651 | const elem_ty_src = block.builtinCallArgSrc(inst_data.src_node, 0); |
| 24721 | const ptr_src : LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; | 24652 | const ptr_src = block.builtinCallArgSrc(inst_data.src_node, 1); |
| 24722 | const op_src : LazySrcLoc = .{ .node_offset_builtin_call_arg2 = inst_data.src_node }; | 24653 | const op_src = block.builtinCallArgSrc(inst_data.src_node, 2); |
| 24723 | const operand_src : LazySrcLoc = .{ .node_offset_builtin_call_arg3 = inst_data.src_node }; | 24654 | const operand_src = block.builtinCallArgSrc(inst_data.src_node, 3); |
| 24724 | const order_src : LazySrcLoc = .{ .node_offset_builtin_call_arg4 = inst_data.src_node }; | 24655 | const order_src = block.builtinCallArgSrc(inst_data.src_node, 4); |
| 24725 | // zig fmt: on | 24656 | // zig fmt: on |
| 24726 | const operand = try sema.resolveInst(extra.operand); | 24657 | const operand = try sema.resolveInst(extra.operand); |
| 24727 | const elem_ty = sema.typeOf(operand); | 24658 | const elem_ty = sema.typeOf(operand); |
| ... | @@ -24800,12 +24731,12 @@ fn zirAtomicRmw(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A | ... | @@ -24800,12 +24731,12 @@ fn zirAtomicRmw(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 24800 | fn zirAtomicStore(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void { | 24731 | fn zirAtomicStore(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void { |
| 24801 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 24732 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 24802 | const extra = sema.code.extraData(Zir.Inst.AtomicStore, inst_data.payload_index).data; | 24733 | const extra = sema.code.extraData(Zir.Inst.AtomicStore, inst_data.payload_index).data; |
| 24803 | const src = inst_data.src(); | 24734 | const src = block.nodeOffset(inst_data.src_node); |
| 24804 | // zig fmt: off | 24735 | // zig fmt: off |
| 24805 | const elem_ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 24736 | const elem_ty_src = block.builtinCallArgSrc(inst_data.src_node, 0); |
| 24806 | const ptr_src : LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; | 24737 | const ptr_src = block.builtinCallArgSrc(inst_data.src_node, 1); |
| 24807 | const operand_src : LazySrcLoc = .{ .node_offset_builtin_call_arg2 = inst_data.src_node }; | 24738 | const operand_src = block.builtinCallArgSrc(inst_data.src_node, 2); |
| 24808 | const order_src : LazySrcLoc = .{ .node_offset_builtin_call_arg3 = inst_data.src_node }; | 24739 | const order_src = block.builtinCallArgSrc(inst_data.src_node, 3); |
| 24809 | // zig fmt: on | 24740 | // zig fmt: on |
| 24810 | const operand = try sema.resolveInst(extra.operand); | 24741 | const operand = try sema.resolveInst(extra.operand); |
| 24811 | const elem_ty = sema.typeOf(operand); | 24742 | const elem_ty = sema.typeOf(operand); |
| ... | @@ -24836,11 +24767,11 @@ fn zirAtomicStore(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError | ... | @@ -24836,11 +24767,11 @@ fn zirAtomicStore(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 24836 | fn zirMulAdd(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 24767 | fn zirMulAdd(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 24837 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 24768 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 24838 | const extra = sema.code.extraData(Zir.Inst.MulAdd, inst_data.payload_index).data; | 24769 | const extra = sema.code.extraData(Zir.Inst.MulAdd, inst_data.payload_index).data; |
| 24839 | const src = inst_data.src(); | 24770 | const src = block.nodeOffset(inst_data.src_node); |
| 24840 | | 24771 | |
| 24841 | const mulend1_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; | 24772 | const mulend1_src = block.builtinCallArgSrc(inst_data.src_node, 1); |
| 24842 | const mulend2_src: LazySrcLoc = .{ .node_offset_builtin_call_arg2 = inst_data.src_node }; | 24773 | const mulend2_src = block.builtinCallArgSrc(inst_data.src_node, 2); |
| 24843 | const addend_src: LazySrcLoc = .{ .node_offset_builtin_call_arg3 = inst_data.src_node }; | 24774 | const addend_src = block.builtinCallArgSrc(inst_data.src_node, 3); |
| 24844 | | 24775 | |
| 24845 | const addend = try sema.resolveInst(extra.addend); | 24776 | const addend = try sema.resolveInst(extra.addend); |
| 24846 | const ty = sema.typeOf(addend); | 24777 | const ty = sema.typeOf(addend); |
| ... | @@ -24903,10 +24834,10 @@ fn zirBuiltinCall(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError | ... | @@ -24903,10 +24834,10 @@ fn zirBuiltinCall(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 24903 | | 24834 | |
| 24904 | const mod = sema.mod; | 24835 | const mod = sema.mod; |
| 24905 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 24836 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 24906 | const modifier_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 24837 | const modifier_src = block.builtinCallArgSrc(inst_data.src_node, 0); |
| 24907 | const func_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; | 24838 | const func_src = block.builtinCallArgSrc(inst_data.src_node, 1); |
| 24908 | const args_src: LazySrcLoc = .{ .node_offset_builtin_call_arg2 = inst_data.src_node }; | 24839 | const args_src = block.builtinCallArgSrc(inst_data.src_node, 2); |
| 24909 | const call_src = inst_data.src(); | 24840 | const call_src = block.nodeOffset(inst_data.src_node); |
| 24910 | | 24841 | |
| 24911 | const extra = sema.code.extraData(Zir.Inst.BuiltinCall, inst_data.payload_index).data; | 24842 | const extra = sema.code.extraData(Zir.Inst.BuiltinCall, inst_data.payload_index).data; |
| 24912 | const func = try sema.resolveInst(extra.callee); | 24843 | const func = try sema.resolveInst(extra.callee); |
| ... | @@ -25000,9 +24931,9 @@ fn zirFieldParentPtr(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.Ins | ... | @@ -25000,9 +24931,9 @@ fn zirFieldParentPtr(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.Ins |
| 25000 | const FlagsInt = @typeInfo(Zir.Inst.FullPtrCastFlags).Struct.backing_integer.?; | 24931 | const FlagsInt = @typeInfo(Zir.Inst.FullPtrCastFlags).Struct.backing_integer.?; |
| 25001 | const flags: Zir.Inst.FullPtrCastFlags = @bitCast(@as(FlagsInt, @truncate(extended.small))); | 24932 | const flags: Zir.Inst.FullPtrCastFlags = @bitCast(@as(FlagsInt, @truncate(extended.small))); |
| 25002 | assert(!flags.ptr_cast); | 24933 | assert(!flags.ptr_cast); |
| 25003 | const inst_src = extra.src(); | 24934 | const inst_src = block.nodeOffset(extra.src_node); |
| 25004 | const field_name_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.src_node }; | 24935 | const field_name_src = block.builtinCallArgSrc(extra.src_node, 0); |
| 25005 | const field_ptr_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = extra.src_node }; | 24936 | const field_ptr_src = block.builtinCallArgSrc(extra.src_node, 1); |
| 25006 | | 24937 | |
| 25007 | const parent_ptr_ty = try sema.resolveDestType(block, inst_src, extra.parent_ptr_type, .remove_eu, "@fieldParentPtr"); | 24938 | const parent_ptr_ty = try sema.resolveDestType(block, inst_src, extra.parent_ptr_type, .remove_eu, "@fieldParentPtr"); |
| 25008 | try sema.checkPtrType(block, inst_src, parent_ptr_ty, true); | 24939 | try sema.checkPtrType(block, inst_src, parent_ptr_ty, true); |
| ... | @@ -25191,9 +25122,9 @@ fn ptrSubtract(sema: *Sema, block: *Block, src: LazySrcLoc, ptr_val: Value, byte | ... | @@ -25191,9 +25122,9 @@ fn ptrSubtract(sema: *Sema, block: *Block, src: LazySrcLoc, ptr_val: Value, byte |
| 25191 | }; | 25122 | }; |
| 25192 | if (ptr.byte_offset < byte_subtract) { | 25123 | if (ptr.byte_offset < byte_subtract) { |
| 25193 | return sema.failWithOwnedErrorMsg(block, msg: { | 25124 | return sema.failWithOwnedErrorMsg(block, msg: { |
| 25194 | const msg = try sema.errMsg(block, src, "pointer computation here causes undefined behavior", .{}); | 25125 | const msg = try sema.errMsg(src, "pointer computation here causes undefined behavior", .{}); |
| 25195 | errdefer msg.destroy(sema.gpa); | 25126 | errdefer msg.destroy(sema.gpa); |
| 25196 | try sema.errNote(block, src, msg, "resulting pointer exceeds bounds of containing value which may trigger overflow", .{}); | 25127 | try sema.errNote(src, msg, "resulting pointer exceeds bounds of containing value which may trigger overflow", .{}); |
| 25197 | break :msg msg; | 25128 | break :msg msg; |
| 25198 | }); | 25129 | }); |
| 25199 | } | 25130 | } |
| ... | @@ -25210,9 +25141,9 @@ fn zirMinMax( | ... | @@ -25210,9 +25141,9 @@ fn zirMinMax( |
| 25210 | ) CompileError!Air.Inst.Ref { | 25141 | ) CompileError!Air.Inst.Ref { |
| 25211 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 25142 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 25212 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; | 25143 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 25213 | const src = inst_data.src(); | 25144 | const src = block.nodeOffset(inst_data.src_node); |
| 25214 | const lhs_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 25145 | const lhs_src = block.builtinCallArgSrc(inst_data.src_node, 0); |
| 25215 | const rhs_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; | 25146 | const rhs_src = block.builtinCallArgSrc(inst_data.src_node, 1); |
| 25216 | const lhs = try sema.resolveInst(extra.lhs); | 25147 | const lhs = try sema.resolveInst(extra.lhs); |
| 25217 | const rhs = try sema.resolveInst(extra.rhs); | 25148 | const rhs = try sema.resolveInst(extra.rhs); |
| 25218 | try sema.checkNumericType(block, lhs_src, sema.typeOf(lhs)); | 25149 | try sema.checkNumericType(block, lhs_src, sema.typeOf(lhs)); |
| ... | @@ -25228,22 +25159,14 @@ fn zirMinMaxMulti( | ... | @@ -25228,22 +25159,14 @@ fn zirMinMaxMulti( |
| 25228 | ) CompileError!Air.Inst.Ref { | 25159 | ) CompileError!Air.Inst.Ref { |
| 25229 | const extra = sema.code.extraData(Zir.Inst.NodeMultiOp, extended.operand); | 25160 | const extra = sema.code.extraData(Zir.Inst.NodeMultiOp, extended.operand); |
| 25230 | const src_node = extra.data.src_node; | 25161 | const src_node = extra.data.src_node; |
| 25231 | const src = LazySrcLoc.nodeOffset(src_node); | 25162 | const src = block.nodeOffset(src_node); |
| 25232 | const operands = sema.code.refSlice(extra.end, extended.small); | 25163 | const operands = sema.code.refSlice(extra.end, extended.small); |
| 25233 | | 25164 | |
| 25234 | const air_refs = try sema.arena.alloc(Air.Inst.Ref, operands.len); | 25165 | const air_refs = try sema.arena.alloc(Air.Inst.Ref, operands.len); |
| 25235 | const operand_srcs = try sema.arena.alloc(LazySrcLoc, operands.len); | 25166 | const operand_srcs = try sema.arena.alloc(LazySrcLoc, operands.len); |
| 25236 | | 25167 | |
| 25237 | for (operands, air_refs, operand_srcs, 0..) |zir_ref, *air_ref, *op_src, i| { | 25168 | for (operands, air_refs, operand_srcs, 0..) |zir_ref, *air_ref, *op_src, i| { |
| 25238 | op_src.* = switch (i) { | 25169 | op_src.* = block.builtinCallArgSrc(src_node, @intCast(i)); |
| 25239 | 0 => .{ .node_offset_builtin_call_arg0 = src_node }, | | |
| 25240 | 1 => .{ .node_offset_builtin_call_arg1 = src_node }, | | |
| 25241 | 2 => .{ .node_offset_builtin_call_arg2 = src_node }, | | |
| 25242 | 3 => .{ .node_offset_builtin_call_arg3 = src_node }, | | |
| 25243 | 4 => .{ .node_offset_builtin_call_arg4 = src_node }, | | |
| 25244 | 5 => .{ .node_offset_builtin_call_arg5 = src_node }, | | |
| 25245 | else => src, // TODO: better source location | | |
| 25246 | }; | | |
| 25247 | air_ref.* = try sema.resolveInst(zir_ref); | 25170 | air_ref.* = try sema.resolveInst(zir_ref); |
| 25248 | try sema.checkNumericType(block, op_src.*, sema.typeOf(air_ref.*)); | 25171 | try sema.checkNumericType(block, op_src.*, sema.typeOf(air_ref.*)); |
| 25249 | } | 25172 | } |
| ... | @@ -25511,9 +25434,9 @@ fn upgradeToArrayPtr(sema: *Sema, block: *Block, ptr: Air.Inst.Ref, len: u64) !A | ... | @@ -25511,9 +25434,9 @@ fn upgradeToArrayPtr(sema: *Sema, block: *Block, ptr: Air.Inst.Ref, len: u64) !A |
| 25511 | fn zirMemcpy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void { | 25434 | fn zirMemcpy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void { |
| 25512 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 25435 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 25513 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; | 25436 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 25514 | const src = inst_data.src(); | 25437 | const src = block.nodeOffset(inst_data.src_node); |
| 25515 | const dest_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 25438 | const dest_src = block.builtinCallArgSrc(inst_data.src_node, 0); |
| 25516 | const src_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; | 25439 | const src_src = block.builtinCallArgSrc(inst_data.src_node, 1); |
| 25517 | const dest_ptr = try sema.resolveInst(extra.lhs); | 25440 | const dest_ptr = try sema.resolveInst(extra.lhs); |
| 25518 | const src_ptr = try sema.resolveInst(extra.rhs); | 25441 | const src_ptr = try sema.resolveInst(extra.rhs); |
| 25519 | const dest_ty = sema.typeOf(dest_ptr); | 25442 | const dest_ty = sema.typeOf(dest_ptr); |
| ... | @@ -25529,12 +25452,12 @@ fn zirMemcpy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void | ... | @@ -25529,12 +25452,12 @@ fn zirMemcpy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void |
| 25529 | | 25452 | |
| 25530 | if (dest_len == .none and src_len == .none) { | 25453 | if (dest_len == .none and src_len == .none) { |
| 25531 | const msg = msg: { | 25454 | const msg = msg: { |
| 25532 | const msg = try sema.errMsg(block, src, "unknown @memcpy length", .{}); | 25455 | const msg = try sema.errMsg(src, "unknown @memcpy length", .{}); |
| 25533 | errdefer msg.destroy(sema.gpa); | 25456 | errdefer msg.destroy(sema.gpa); |
| 25534 | try sema.errNote(block, dest_src, msg, "destination type '{}' provides no length", .{ | 25457 | try sema.errNote(dest_src, msg, "destination type '{}' provides no length", .{ |
| 25535 | dest_ty.fmt(sema.mod), | 25458 | dest_ty.fmt(sema.mod), |
| 25536 | }); | 25459 | }); |
| 25537 | try sema.errNote(block, src_src, msg, "source type '{}' provides no length", .{ | 25460 | try sema.errNote(src_src, msg, "source type '{}' provides no length", .{ |
| 25538 | src_ty.fmt(sema.mod), | 25461 | src_ty.fmt(sema.mod), |
| 25539 | }); | 25462 | }); |
| 25540 | break :msg msg; | 25463 | break :msg msg; |
| ... | @@ -25551,12 +25474,12 @@ fn zirMemcpy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void | ... | @@ -25551,12 +25474,12 @@ fn zirMemcpy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void |
| 25551 | if (try sema.resolveDefinedValue(block, src_src, src_len)) |src_len_val| { | 25474 | if (try sema.resolveDefinedValue(block, src_src, src_len)) |src_len_val| { |
| 25552 | if (!(try sema.valuesEqual(dest_len_val, src_len_val, Type.usize))) { | 25475 | if (!(try sema.valuesEqual(dest_len_val, src_len_val, Type.usize))) { |
| 25553 | const msg = msg: { | 25476 | const msg = msg: { |
| 25554 | const msg = try sema.errMsg(block, src, "non-matching @memcpy lengths", .{}); | 25477 | const msg = try sema.errMsg(src, "non-matching @memcpy lengths", .{}); |
| 25555 | errdefer msg.destroy(sema.gpa); | 25478 | errdefer msg.destroy(sema.gpa); |
| 25556 | try sema.errNote(block, dest_src, msg, "length {} here", .{ | 25479 | try sema.errNote(dest_src, msg, "length {} here", .{ |
| 25557 | dest_len_val.fmtValue(sema.mod, sema), | 25480 | dest_len_val.fmtValue(sema.mod, sema), |
| 25558 | }); | 25481 | }); |
| 25559 | try sema.errNote(block, src_src, msg, "length {} here", .{ | 25482 | try sema.errNote(src_src, msg, "length {} here", .{ |
| 25560 | src_len_val.fmtValue(sema.mod, sema), | 25483 | src_len_val.fmtValue(sema.mod, sema), |
| 25561 | }); | 25484 | }); |
| 25562 | break :msg msg; | 25485 | break :msg msg; |
| ... | @@ -25664,7 +25587,7 @@ fn zirMemcpy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void | ... | @@ -25664,7 +25587,7 @@ fn zirMemcpy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void |
| 25664 | } else if (dest_len == .none and len_val == null) { | 25587 | } else if (dest_len == .none and len_val == null) { |
| 25665 | // Change the dest to a slice, since its type must have the length. | 25588 | // Change the dest to a slice, since its type must have the length. |
| 25666 | const dest_ptr_ptr = try sema.analyzeRef(block, dest_src, new_dest_ptr); | 25589 | const dest_ptr_ptr = try sema.analyzeRef(block, dest_src, new_dest_ptr); |
| 25667 | new_dest_ptr = try sema.analyzeSlice(block, dest_src, dest_ptr_ptr, .zero, src_len, .none, .unneeded, dest_src, dest_src, dest_src, false); | 25590 | 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); |
| 25668 | const new_src_ptr_ty = sema.typeOf(new_src_ptr); | 25591 | const new_src_ptr_ty = sema.typeOf(new_src_ptr); |
| 25669 | if (new_src_ptr_ty.isSlice(mod)) { | 25592 | if (new_src_ptr_ty.isSlice(mod)) { |
| 25670 | new_src_ptr = try sema.analyzeSlicePtr(block, src_src, new_src_ptr, new_src_ptr_ty); | 25593 | new_src_ptr = try sema.analyzeSlicePtr(block, src_src, new_src_ptr, new_src_ptr_ty); |
| ... | @@ -25731,9 +25654,9 @@ fn zirMemset(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void | ... | @@ -25731,9 +25654,9 @@ fn zirMemset(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void |
| 25731 | const ip = &mod.intern_pool; | 25654 | const ip = &mod.intern_pool; |
| 25732 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 25655 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 25733 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; | 25656 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 25734 | const src = inst_data.src(); | 25657 | const src = block.nodeOffset(inst_data.src_node); |
| 25735 | const dest_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | 25658 | const dest_src = block.builtinCallArgSrc(inst_data.src_node, 0); |
| 25736 | const value_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; | 25659 | const value_src = block.builtinCallArgSrc(inst_data.src_node, 1); |
| 25737 | const dest_ptr = try sema.resolveInst(extra.lhs); | 25660 | const dest_ptr = try sema.resolveInst(extra.lhs); |
| 25738 | const uncoerced_elem = try sema.resolveInst(extra.rhs); | 25661 | const uncoerced_elem = try sema.resolveInst(extra.rhs); |
| 25739 | const dest_ptr_ty = sema.typeOf(dest_ptr); | 25662 | const dest_ptr_ty = sema.typeOf(dest_ptr); |
| ... | @@ -25755,9 +25678,9 @@ fn zirMemset(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void | ... | @@ -25755,9 +25678,9 @@ fn zirMemset(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void |
| 25755 | .Many, .C => {}, | 25678 | .Many, .C => {}, |
| 25756 | } | 25679 | } |
| 25757 | return sema.failWithOwnedErrorMsg(block, msg: { | 25680 | return sema.failWithOwnedErrorMsg(block, msg: { |
| 25758 | const msg = try sema.errMsg(block, src, "unknown @memset length", .{}); | 25681 | const msg = try sema.errMsg(src, "unknown @memset length", .{}); |
| 25759 | errdefer msg.destroy(sema.gpa); | 25682 | errdefer msg.destroy(sema.gpa); |
| 25760 | try sema.errNote(block, dest_src, msg, "destination type '{}' provides no length", .{ | 25683 | try sema.errNote(dest_src, msg, "destination type '{}' provides no length", .{ |
| 25761 | dest_ptr_ty.fmt(mod), | 25684 | dest_ptr_ty.fmt(mod), |
| 25762 | }); | 25685 | }); |
| 25763 | break :msg msg; | 25686 | break :msg msg; |
| ... | @@ -25810,13 +25733,13 @@ fn zirMemset(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void | ... | @@ -25810,13 +25733,13 @@ fn zirMemset(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void |
| 25810 | | 25733 | |
| 25811 | fn zirBuiltinAsyncCall(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!Air.Inst.Ref { | 25734 | fn zirBuiltinAsyncCall(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!Air.Inst.Ref { |
| 25812 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; | 25735 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; |
| 25813 | const src = LazySrcLoc.nodeOffset(extra.node); | 25736 | const src = block.nodeOffset(extra.node); |
| 25814 | return sema.failWithUseOfAsync(block, src); | 25737 | return sema.failWithUseOfAsync(block, src); |
| 25815 | } | 25738 | } |
| 25816 | | 25739 | |
| 25817 | fn zirResume(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 25740 | fn zirResume(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 25818 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; | 25741 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 25819 | const src = inst_data.src(); | 25742 | const src = block.nodeOffset(inst_data.src_node); |
| 25820 | return sema.failWithUseOfAsync(block, src); | 25743 | return sema.failWithUseOfAsync(block, src); |
| 25821 | } | 25744 | } |
| 25822 | | 25745 | |
| ... | @@ -25826,7 +25749,7 @@ fn zirAwait( | ... | @@ -25826,7 +25749,7 @@ fn zirAwait( |
| 25826 | inst: Zir.Inst.Index, | 25749 | inst: Zir.Inst.Index, |
| 25827 | ) CompileError!Air.Inst.Ref { | 25750 | ) CompileError!Air.Inst.Ref { |
| 25828 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; | 25751 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 25829 | const src = inst_data.src(); | 25752 | const src = block.nodeOffset(inst_data.src_node); |
| 25830 | | 25753 | |
| 25831 | return sema.failWithUseOfAsync(block, src); | 25754 | return sema.failWithUseOfAsync(block, src); |
| 25832 | } | 25755 | } |
| ... | @@ -25837,7 +25760,7 @@ fn zirAwaitNosuspend( | ... | @@ -25837,7 +25760,7 @@ fn zirAwaitNosuspend( |
| 25837 | extended: Zir.Inst.Extended.InstData, | 25760 | extended: Zir.Inst.Extended.InstData, |
| 25838 | ) CompileError!Air.Inst.Ref { | 25761 | ) CompileError!Air.Inst.Ref { |
| 25839 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; | 25762 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; |
| 25840 | const src = LazySrcLoc.nodeOffset(extra.node); | 25763 | const src = block.nodeOffset(extra.node); |
| 25841 | | 25764 | |
| 25842 | return sema.failWithUseOfAsync(block, src); | 25765 | return sema.failWithUseOfAsync(block, src); |
| 25843 | } | 25766 | } |
| ... | @@ -25849,8 +25772,8 @@ fn zirVarExtended( | ... | @@ -25849,8 +25772,8 @@ fn zirVarExtended( |
| 25849 | ) CompileError!Air.Inst.Ref { | 25772 | ) CompileError!Air.Inst.Ref { |
| 25850 | const mod = sema.mod; | 25773 | const mod = sema.mod; |
| 25851 | const extra = sema.code.extraData(Zir.Inst.ExtendedVar, extended.operand); | 25774 | const extra = sema.code.extraData(Zir.Inst.ExtendedVar, extended.operand); |
| 25852 | const ty_src: LazySrcLoc = .{ .node_offset_var_decl_ty = 0 }; | 25775 | const ty_src = block.src(.{ .node_offset_var_decl_ty = 0 }); |
| 25853 | const init_src: LazySrcLoc = .{ .node_offset_var_decl_init = 0 }; | 25776 | const init_src = block.src(.{ .node_offset_var_decl_init = 0 }); |
| 25854 | const small: Zir.Inst.ExtendedVar.Small = @bitCast(extended.small); | 25777 | const small: Zir.Inst.ExtendedVar.Small = @bitCast(extended.small); |
| 25855 | | 25778 | |
| 25856 | var extra_index: usize = extra.end; | 25779 | var extra_index: usize = extra.end; |
| ... | @@ -25915,11 +25838,11 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A | ... | @@ -25915,11 +25838,11 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 25915 | const extra = sema.code.extraData(Zir.Inst.FuncFancy, inst_data.payload_index); | 25838 | const extra = sema.code.extraData(Zir.Inst.FuncFancy, inst_data.payload_index); |
| 25916 | const target = mod.getTarget(); | 25839 | const target = mod.getTarget(); |
| 25917 | | 25840 | |
| 25918 | const align_src: LazySrcLoc = .{ .node_offset_fn_type_align = inst_data.src_node }; | 25841 | const align_src = block.src(.{ .node_offset_fn_type_align = inst_data.src_node }); |
| 25919 | const addrspace_src: LazySrcLoc = .{ .node_offset_fn_type_addrspace = inst_data.src_node }; | 25842 | const addrspace_src = block.src(.{ .node_offset_fn_type_addrspace = inst_data.src_node }); |
| 25920 | const section_src: LazySrcLoc = .{ .node_offset_fn_type_section = inst_data.src_node }; | 25843 | const section_src = block.src(.{ .node_offset_fn_type_section = inst_data.src_node }); |
| 25921 | const cc_src: LazySrcLoc = .{ .node_offset_fn_type_cc = inst_data.src_node }; | 25844 | const cc_src = block.src(.{ .node_offset_fn_type_cc = inst_data.src_node }); |
| 25922 | const ret_src: LazySrcLoc = .{ .node_offset_fn_type_ret_ty = inst_data.src_node }; | 25845 | const ret_src = block.src(.{ .node_offset_fn_type_ret_ty = inst_data.src_node }); |
| 25923 | const has_body = extra.data.body_len != 0; | 25846 | const has_body = extra.data.body_len != 0; |
| 25924 | | 25847 | |
| 25925 | var extra_index: usize = extra.end; | 25848 | var extra_index: usize = extra.end; |
| ... | @@ -26146,7 +26069,7 @@ fn zirCUndef( | ... | @@ -26146,7 +26069,7 @@ fn zirCUndef( |
| 26146 | extended: Zir.Inst.Extended.InstData, | 26069 | extended: Zir.Inst.Extended.InstData, |
| 26147 | ) CompileError!Air.Inst.Ref { | 26070 | ) CompileError!Air.Inst.Ref { |
| 26148 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; | 26071 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; |
| 26149 | const src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node }; | 26072 | const src = block.builtinCallArgSrc(extra.node, 0); |
| 26150 | | 26073 | |
| 26151 | const name = try sema.resolveConstString(block, src, extra.operand, .{ | 26074 | const name = try sema.resolveConstString(block, src, extra.operand, .{ |
| 26152 | .needed_comptime_reason = "name of macro being undefined must be comptime-known", | 26075 | .needed_comptime_reason = "name of macro being undefined must be comptime-known", |
| ... | @@ -26161,7 +26084,7 @@ fn zirCInclude( | ... | @@ -26161,7 +26084,7 @@ fn zirCInclude( |
| 26161 | extended: Zir.Inst.Extended.InstData, | 26084 | extended: Zir.Inst.Extended.InstData, |
| 26162 | ) CompileError!Air.Inst.Ref { | 26085 | ) CompileError!Air.Inst.Ref { |
| 26163 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; | 26086 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; |
| 26164 | const src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node }; | 26087 | const src = block.builtinCallArgSrc(extra.node, 0); |
| 26165 | | 26088 | |
| 26166 | const name = try sema.resolveConstString(block, src, extra.operand, .{ | 26089 | const name = try sema.resolveConstString(block, src, extra.operand, .{ |
| 26167 | .needed_comptime_reason = "path being included must be comptime-known", | 26090 | .needed_comptime_reason = "path being included must be comptime-known", |
| ... | @@ -26177,8 +26100,8 @@ fn zirCDefine( | ... | @@ -26177,8 +26100,8 @@ fn zirCDefine( |
| 26177 | ) CompileError!Air.Inst.Ref { | 26100 | ) CompileError!Air.Inst.Ref { |
| 26178 | const mod = sema.mod; | 26101 | const mod = sema.mod; |
| 26179 | const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data; | 26102 | const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data; |
| 26180 | const name_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node }; | 26103 | const name_src = block.builtinCallArgSrc(extra.node, 0); |
| 26181 | const val_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = extra.node }; | 26104 | const val_src = block.builtinCallArgSrc(extra.node, 1); |
| 26182 | | 26105 | |
| 26183 | const name = try sema.resolveConstString(block, name_src, extra.lhs, .{ | 26106 | const name = try sema.resolveConstString(block, name_src, extra.lhs, .{ |
| 26184 | .needed_comptime_reason = "name of macro being undefined must be comptime-known", | 26107 | .needed_comptime_reason = "name of macro being undefined must be comptime-known", |
| ... | @@ -26201,8 +26124,8 @@ fn zirWasmMemorySize( | ... | @@ -26201,8 +26124,8 @@ fn zirWasmMemorySize( |
| 26201 | extended: Zir.Inst.Extended.InstData, | 26124 | extended: Zir.Inst.Extended.InstData, |
| 26202 | ) CompileError!Air.Inst.Ref { | 26125 | ) CompileError!Air.Inst.Ref { |
| 26203 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; | 26126 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; |
| 26204 | const index_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node }; | 26127 | const index_src = block.builtinCallArgSrc(extra.node, 0); |
| 26205 | const builtin_src = LazySrcLoc.nodeOffset(extra.node); | 26128 | const builtin_src = block.nodeOffset(extra.node); |
| 26206 | const target = sema.mod.getTarget(); | 26129 | const target = sema.mod.getTarget(); |
| 26207 | if (!target.isWasm()) { | 26130 | if (!target.isWasm()) { |
| 26208 | return sema.fail(block, builtin_src, "builtin @wasmMemorySize is available when targeting WebAssembly; targeted CPU architecture is {s}", .{@tagName(target.cpu.arch)}); | 26131 | return sema.fail(block, builtin_src, "builtin @wasmMemorySize is available when targeting WebAssembly; targeted CPU architecture is {s}", .{@tagName(target.cpu.arch)}); |
| ... | @@ -26227,9 +26150,9 @@ fn zirWasmMemoryGrow( | ... | @@ -26227,9 +26150,9 @@ fn zirWasmMemoryGrow( |
| 26227 | extended: Zir.Inst.Extended.InstData, | 26150 | extended: Zir.Inst.Extended.InstData, |
| 26228 | ) CompileError!Air.Inst.Ref { | 26151 | ) CompileError!Air.Inst.Ref { |
| 26229 | const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data; | 26152 | const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data; |
| 26230 | const builtin_src = LazySrcLoc.nodeOffset(extra.node); | 26153 | const builtin_src = block.nodeOffset(extra.node); |
| 26231 | const index_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node }; | 26154 | const index_src = block.builtinCallArgSrc(extra.node, 0); |
| 26232 | const delta_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = extra.node }; | 26155 | const delta_src = block.builtinCallArgSrc(extra.node, 1); |
| 26233 | const target = sema.mod.getTarget(); | 26156 | const target = sema.mod.getTarget(); |
| 26234 | if (!target.isWasm()) { | 26157 | if (!target.isWasm()) { |
| 26235 | return sema.fail(block, builtin_src, "builtin @wasmMemoryGrow is available when targeting WebAssembly; targeted CPU architecture is {s}", .{@tagName(target.cpu.arch)}); | 26158 | return sema.fail(block, builtin_src, "builtin @wasmMemoryGrow is available when targeting WebAssembly; targeted CPU architecture is {s}", .{@tagName(target.cpu.arch)}); |
| ... | @@ -26262,9 +26185,9 @@ fn resolvePrefetchOptions( | ... | @@ -26262,9 +26185,9 @@ fn resolvePrefetchOptions( |
| 26262 | const options_ty = try sema.getBuiltinType("PrefetchOptions"); | 26185 | const options_ty = try sema.getBuiltinType("PrefetchOptions"); |
| 26263 | const options = try sema.coerce(block, options_ty, try sema.resolveInst(zir_ref), src); | 26186 | const options = try sema.coerce(block, options_ty, try sema.resolveInst(zir_ref), src); |
| 26264 | | 26187 | |
| 26265 | const rw_src = sema.maybeOptionsSrc(block, src, "rw"); | 26188 | const rw_src = block.src(.{ .init_field_rw = src.offset.node_offset_builtin_call_arg.builtin_call_node }); |
| 26266 | const locality_src = sema.maybeOptionsSrc(block, src, "locality"); | 26189 | const locality_src = block.src(.{ .init_field_locality = src.offset.node_offset_builtin_call_arg.builtin_call_node }); |
| 26267 | const cache_src = sema.maybeOptionsSrc(block, src, "cache"); | 26190 | const cache_src = block.src(.{ .init_field_cache = src.offset.node_offset_builtin_call_arg.builtin_call_node }); |
| 26268 | | 26191 | |
| 26269 | const rw = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "rw", .no_embedded_nulls), rw_src); | 26192 | const rw = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "rw", .no_embedded_nulls), rw_src); |
| 26270 | const rw_val = try sema.resolveConstDefinedValue(block, rw_src, rw, .{ | 26193 | const rw_val = try sema.resolveConstDefinedValue(block, rw_src, rw, .{ |
| ... | @@ -26294,18 +26217,12 @@ fn zirPrefetch( | ... | @@ -26294,18 +26217,12 @@ fn zirPrefetch( |
| 26294 | extended: Zir.Inst.Extended.InstData, | 26217 | extended: Zir.Inst.Extended.InstData, |
| 26295 | ) CompileError!Air.Inst.Ref { | 26218 | ) CompileError!Air.Inst.Ref { |
| 26296 | const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data; | 26219 | const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data; |
| 26297 | const ptr_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node }; | 26220 | const ptr_src = block.builtinCallArgSrc(extra.node, 0); |
| 26298 | const opts_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = extra.node }; | 26221 | const opts_src = block.builtinCallArgSrc(extra.node, 1); |
| 26299 | const ptr = try sema.resolveInst(extra.lhs); | 26222 | const ptr = try sema.resolveInst(extra.lhs); |
| 26300 | try sema.checkPtrOperand(block, ptr_src, sema.typeOf(ptr)); | 26223 | try sema.checkPtrOperand(block, ptr_src, sema.typeOf(ptr)); |
| 26301 | | 26224 | |
| 26302 | const options = sema.resolvePrefetchOptions(block, .unneeded, extra.rhs) catch |err| switch (err) { | 26225 | const options = try sema.resolvePrefetchOptions(block, opts_src, extra.rhs); |
| 26303 | error.NeededSourceLocation => { | | |
| 26304 | _ = try sema.resolvePrefetchOptions(block, opts_src, extra.rhs); | | |
| 26305 | unreachable; | | |
| 26306 | }, | | |
| 26307 | else => |e| return e, | | |
| 26308 | }; | | |
| 26309 | | 26226 | |
| 26310 | if (!block.is_comptime) { | 26227 | if (!block.is_comptime) { |
| 26311 | _ = try block.addInst(.{ | 26228 | _ = try block.addInst(.{ |
| ... | @@ -26340,10 +26257,10 @@ fn resolveExternOptions( | ... | @@ -26340,10 +26257,10 @@ fn resolveExternOptions( |
| 26340 | const extern_options_ty = try sema.getBuiltinType("ExternOptions"); | 26257 | const extern_options_ty = try sema.getBuiltinType("ExternOptions"); |
| 26341 | const options = try sema.coerce(block, extern_options_ty, options_inst, src); | 26258 | const options = try sema.coerce(block, extern_options_ty, options_inst, src); |
| 26342 | | 26259 | |
| 26343 | const name_src = sema.maybeOptionsSrc(block, src, "name"); | 26260 | const name_src = block.src(.{ .init_field_name = src.offset.node_offset_builtin_call_arg.builtin_call_node }); |
| 26344 | const library_src = sema.maybeOptionsSrc(block, src, "library"); | 26261 | const library_src = block.src(.{ .init_field_library = src.offset.node_offset_builtin_call_arg.builtin_call_node }); |
| 26345 | const linkage_src = sema.maybeOptionsSrc(block, src, "linkage"); | 26262 | const linkage_src = block.src(.{ .init_field_linkage = src.offset.node_offset_builtin_call_arg.builtin_call_node }); |
| 26346 | const thread_local_src = sema.maybeOptionsSrc(block, src, "thread_local"); | 26263 | const thread_local_src = block.src(.{ .init_field_thread_local = src.offset.node_offset_builtin_call_arg.builtin_call_node }); |
| 26347 | | 26264 | |
| 26348 | const name_ref = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "name", .no_embedded_nulls), name_src); | 26265 | const name_ref = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "name", .no_embedded_nulls), name_src); |
| 26349 | const name = try sema.toConstString(block, name_src, name_ref, .{ | 26266 | const name = try sema.toConstString(block, name_src, name_ref, .{ |
| ... | @@ -26401,8 +26318,8 @@ fn zirBuiltinExtern( | ... | @@ -26401,8 +26318,8 @@ fn zirBuiltinExtern( |
| 26401 | const mod = sema.mod; | 26318 | const mod = sema.mod; |
| 26402 | const ip = &mod.intern_pool; | 26319 | const ip = &mod.intern_pool; |
| 26403 | const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data; | 26320 | const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data; |
| 26404 | const ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node }; | 26321 | const ty_src = block.builtinCallArgSrc(extra.node, 0); |
| 26405 | const options_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = extra.node }; | 26322 | const options_src = block.builtinCallArgSrc(extra.node, 1); |
| 26406 | | 26323 | |
| 26407 | var ty = try sema.resolveType(block, ty_src, extra.lhs); | 26324 | var ty = try sema.resolveType(block, ty_src, extra.lhs); |
| 26408 | if (!ty.isPtrAtRuntime(mod)) { | 26325 | if (!ty.isPtrAtRuntime(mod)) { |
| ... | @@ -26410,29 +26327,22 @@ fn zirBuiltinExtern( | ... | @@ -26410,29 +26327,22 @@ fn zirBuiltinExtern( |
| 26410 | } | 26327 | } |
| 26411 | if (!try sema.validateExternType(ty, .other)) { | 26328 | if (!try sema.validateExternType(ty, .other)) { |
| 26412 | const msg = msg: { | 26329 | const msg = msg: { |
| 26413 | const msg = try sema.errMsg(block, ty_src, "extern symbol cannot have type '{}'", .{ty.fmt(mod)}); | 26330 | const msg = try sema.errMsg(ty_src, "extern symbol cannot have type '{}'", .{ty.fmt(mod)}); |
| 26414 | errdefer msg.destroy(sema.gpa); | 26331 | errdefer msg.destroy(sema.gpa); |
| 26415 | const src_decl = sema.mod.declPtr(block.src_decl); | 26332 | try sema.explainWhyTypeIsNotExtern(msg, ty_src, ty, .other); |
| 26416 | try sema.explainWhyTypeIsNotExtern(msg, src_decl.toSrcLoc(ty_src, mod), ty, .other); | | |
| 26417 | break :msg msg; | 26333 | break :msg msg; |
| 26418 | }; | 26334 | }; |
| 26419 | return sema.failWithOwnedErrorMsg(block, msg); | 26335 | return sema.failWithOwnedErrorMsg(block, msg); |
| 26420 | } | 26336 | } |
| 26421 | | 26337 | |
| 26422 | const options = sema.resolveExternOptions(block, .unneeded, extra.rhs) catch |err| switch (err) { | 26338 | const options = try sema.resolveExternOptions(block, options_src, extra.rhs); |
| 26423 | error.NeededSourceLocation => { | | |
| 26424 | _ = try sema.resolveExternOptions(block, options_src, extra.rhs); | | |
| 26425 | unreachable; | | |
| 26426 | }, | | |
| 26427 | else => |e| return e, | | |
| 26428 | }; | | |
| 26429 | | 26339 | |
| 26430 | if (options.linkage == .weak and !ty.ptrAllowsZero(mod)) { | 26340 | if (options.linkage == .weak and !ty.ptrAllowsZero(mod)) { |
| 26431 | ty = try mod.optionalType(ty.toIntern()); | 26341 | ty = try mod.optionalType(ty.toIntern()); |
| 26432 | } | 26342 | } |
| 26433 | const ptr_info = ty.ptrInfo(mod); | 26343 | const ptr_info = ty.ptrInfo(mod); |
| 26434 | | 26344 | |
| 26435 | const new_decl_index = try mod.allocateNewDecl(sema.owner_decl.src_namespace, sema.owner_decl.src_node); | 26345 | const new_decl_index = try mod.allocateNewDecl(sema.owner_decl.src_namespace); |
| 26436 | errdefer mod.destroyDecl(new_decl_index); | 26346 | errdefer mod.destroyDecl(new_decl_index); |
| 26437 | const new_decl = mod.declPtr(new_decl_index); | 26347 | const new_decl = mod.declPtr(new_decl_index); |
| 26438 | try mod.initNewAnonDecl( | 26348 | try mod.initNewAnonDecl( |
| ... | @@ -26482,8 +26392,8 @@ fn zirWorkItem( | ... | @@ -26482,8 +26392,8 @@ fn zirWorkItem( |
| 26482 | zir_tag: Zir.Inst.Extended, | 26392 | zir_tag: Zir.Inst.Extended, |
| 26483 | ) CompileError!Air.Inst.Ref { | 26393 | ) CompileError!Air.Inst.Ref { |
| 26484 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; | 26394 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; |
| 26485 | const dimension_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node }; | 26395 | const dimension_src = block.builtinCallArgSrc(extra.node, 0); |
| 26486 | const builtin_src = LazySrcLoc.nodeOffset(extra.node); | 26396 | const builtin_src = block.nodeOffset(extra.node); |
| 26487 | const target = sema.mod.getTarget(); | 26397 | const target = sema.mod.getTarget(); |
| 26488 | | 26398 | |
| 26489 | switch (target.cpu.arch) { | 26399 | switch (target.cpu.arch) { |
| ... | @@ -26524,11 +26434,11 @@ fn zirInComptime( | ... | @@ -26524,11 +26434,11 @@ fn zirInComptime( |
| 26524 | fn requireRuntimeBlock(sema: *Sema, block: *Block, src: LazySrcLoc, runtime_src: ?LazySrcLoc) !void { | 26434 | fn requireRuntimeBlock(sema: *Sema, block: *Block, src: LazySrcLoc, runtime_src: ?LazySrcLoc) !void { |
| 26525 | if (block.is_comptime) { | 26435 | if (block.is_comptime) { |
| 26526 | const msg = msg: { | 26436 | const msg = msg: { |
| 26527 | const msg = try sema.errMsg(block, src, "unable to evaluate comptime expression", .{}); | 26437 | const msg = try sema.errMsg(src, "unable to evaluate comptime expression", .{}); |
| 26528 | errdefer msg.destroy(sema.gpa); | 26438 | errdefer msg.destroy(sema.gpa); |
| 26529 | | 26439 | |
| 26530 | if (runtime_src) |some| { | 26440 | if (runtime_src) |some| { |
| 26531 | try sema.errNote(block, some, msg, "operation is runtime due to this operand", .{}); | 26441 | try sema.errNote(some, msg, "operation is runtime due to this operand", .{}); |
| 26532 | } | 26442 | } |
| 26533 | if (block.comptime_reason) |some| { | 26443 | if (block.comptime_reason) |some| { |
| 26534 | try some.explain(sema, msg); | 26444 | try some.explain(sema, msg); |
| ... | @@ -26551,10 +26461,9 @@ fn validateVarType( | ... | @@ -26551,10 +26461,9 @@ fn validateVarType( |
| 26551 | if (is_extern) { | 26461 | if (is_extern) { |
| 26552 | if (!try sema.validateExternType(var_ty, .other)) { | 26462 | if (!try sema.validateExternType(var_ty, .other)) { |
| 26553 | const msg = msg: { | 26463 | const msg = msg: { |
| 26554 | const msg = try sema.errMsg(block, src, "extern variable cannot have type '{}'", .{var_ty.fmt(mod)}); | 26464 | const msg = try sema.errMsg(src, "extern variable cannot have type '{}'", .{var_ty.fmt(mod)}); |
| 26555 | errdefer msg.destroy(sema.gpa); | 26465 | errdefer msg.destroy(sema.gpa); |
| 26556 | const src_decl = mod.declPtr(block.src_decl); | 26466 | try sema.explainWhyTypeIsNotExtern(msg, src, var_ty, .other); |
| 26557 | try sema.explainWhyTypeIsNotExtern(msg, src_decl.toSrcLoc(src, mod), var_ty, .other); | | |
| 26558 | break :msg msg; | 26467 | break :msg msg; |
| 26559 | }; | 26468 | }; |
| 26560 | return sema.failWithOwnedErrorMsg(block, msg); | 26469 | return sema.failWithOwnedErrorMsg(block, msg); |
| ... | @@ -26573,13 +26482,12 @@ fn validateVarType( | ... | @@ -26573,13 +26482,12 @@ fn validateVarType( |
| 26573 | if (!try sema.typeRequiresComptime(var_ty)) return; | 26482 | if (!try sema.typeRequiresComptime(var_ty)) return; |
| 26574 | | 26483 | |
| 26575 | const msg = msg: { | 26484 | const msg = msg: { |
| 26576 | const msg = try sema.errMsg(block, src, "variable of type '{}' must be const or comptime", .{var_ty.fmt(mod)}); | 26485 | const msg = try sema.errMsg(src, "variable of type '{}' must be const or comptime", .{var_ty.fmt(mod)}); |
| 26577 | errdefer msg.destroy(sema.gpa); | 26486 | errdefer msg.destroy(sema.gpa); |
| 26578 | | 26487 | |
| 26579 | const src_decl = mod.declPtr(block.src_decl); | 26488 | try sema.explainWhyTypeIsComptime(msg, src, var_ty); |
| 26580 | try sema.explainWhyTypeIsComptime(msg, src_decl.toSrcLoc(src, mod), var_ty); | | |
| 26581 | if (var_ty.zigTypeTag(mod) == .ComptimeInt or var_ty.zigTypeTag(mod) == .ComptimeFloat) { | 26489 | if (var_ty.zigTypeTag(mod) == .ComptimeInt or var_ty.zigTypeTag(mod) == .ComptimeFloat) { |
| 26582 | try sema.errNote(block, src, msg, "to modify this variable at runtime, it must be given an explicit fixed-size number type", .{}); | 26490 | try sema.errNote(src, msg, "to modify this variable at runtime, it must be given an explicit fixed-size number type", .{}); |
| 26583 | } | 26491 | } |
| 26584 | | 26492 | |
| 26585 | break :msg msg; | 26493 | break :msg msg; |
| ... | @@ -26592,7 +26500,7 @@ const TypeSet = std.AutoHashMapUnmanaged(InternPool.Index, void); | ... | @@ -26592,7 +26500,7 @@ const TypeSet = std.AutoHashMapUnmanaged(InternPool.Index, void); |
| 26592 | fn explainWhyTypeIsComptime( | 26500 | fn explainWhyTypeIsComptime( |
| 26593 | sema: *Sema, | 26501 | sema: *Sema, |
| 26594 | msg: *Module.ErrorMsg, | 26502 | msg: *Module.ErrorMsg, |
| 26595 | src_loc: Module.SrcLoc, | 26503 | src_loc: LazySrcLoc, |
| 26596 | ty: Type, | 26504 | ty: Type, |
| 26597 | ) CompileError!void { | 26505 | ) CompileError!void { |
| 26598 | var type_set = TypeSet{}; | 26506 | var type_set = TypeSet{}; |
| ... | @@ -26605,7 +26513,7 @@ fn explainWhyTypeIsComptime( | ... | @@ -26605,7 +26513,7 @@ fn explainWhyTypeIsComptime( |
| 26605 | fn explainWhyTypeIsComptimeInner( | 26513 | fn explainWhyTypeIsComptimeInner( |
| 26606 | sema: *Sema, | 26514 | sema: *Sema, |
| 26607 | msg: *Module.ErrorMsg, | 26515 | msg: *Module.ErrorMsg, |
| 26608 | src_loc: Module.SrcLoc, | 26516 | src_loc: LazySrcLoc, |
| 26609 | ty: Type, | 26517 | ty: Type, |
| 26610 | type_set: *TypeSet, | 26518 | type_set: *TypeSet, |
| 26611 | ) CompileError!void { | 26519 | ) CompileError!void { |
| ... | @@ -26623,13 +26531,13 @@ fn explainWhyTypeIsComptimeInner( | ... | @@ -26623,13 +26531,13 @@ fn explainWhyTypeIsComptimeInner( |
| 26623 | => return, | 26531 | => return, |
| 26624 | | 26532 | |
| 26625 | .Fn => { | 26533 | .Fn => { |
| 26626 | try mod.errNoteNonLazy(src_loc, msg, "use '*const {}' for a function pointer type", .{ | 26534 | try sema.errNote(src_loc, msg, "use '*const {}' for a function pointer type", .{ |
| 26627 | ty.fmt(sema.mod), | 26535 | ty.fmt(sema.mod), |
| 26628 | }); | 26536 | }); |
| 26629 | }, | 26537 | }, |
| 26630 | | 26538 | |
| 26631 | .Type => { | 26539 | .Type => { |
| 26632 | try mod.errNoteNonLazy(src_loc, msg, "types are not available at runtime", .{}); | 26540 | try sema.errNote(src_loc, msg, "types are not available at runtime", .{}); |
| 26633 | }, | 26541 | }, |
| 26634 | | 26542 | |
| 26635 | .ComptimeFloat, | 26543 | .ComptimeFloat, |
| ... | @@ -26641,7 +26549,7 @@ fn explainWhyTypeIsComptimeInner( | ... | @@ -26641,7 +26549,7 @@ fn explainWhyTypeIsComptimeInner( |
| 26641 | => return, | 26549 | => return, |
| 26642 | | 26550 | |
| 26643 | .Opaque => { | 26551 | .Opaque => { |
| 26644 | try mod.errNoteNonLazy(src_loc, msg, "opaque type '{}' has undefined size", .{ty.fmt(sema.mod)}); | 26552 | try sema.errNote(src_loc, msg, "opaque type '{}' has undefined size", .{ty.fmt(sema.mod)}); |
| 26645 | }, | 26553 | }, |
| 26646 | | 26554 | |
| 26647 | .Array, .Vector => { | 26555 | .Array, .Vector => { |
| ... | @@ -26652,14 +26560,14 @@ fn explainWhyTypeIsComptimeInner( | ... | @@ -26652,14 +26560,14 @@ fn explainWhyTypeIsComptimeInner( |
| 26652 | if (elem_ty.zigTypeTag(mod) == .Fn) { | 26560 | if (elem_ty.zigTypeTag(mod) == .Fn) { |
| 26653 | const fn_info = mod.typeToFunc(elem_ty).?; | 26561 | const fn_info = mod.typeToFunc(elem_ty).?; |
| 26654 | if (fn_info.is_generic) { | 26562 | if (fn_info.is_generic) { |
| 26655 | try mod.errNoteNonLazy(src_loc, msg, "function is generic", .{}); | 26563 | try sema.errNote(src_loc, msg, "function is generic", .{}); |
| 26656 | } | 26564 | } |
| 26657 | switch (fn_info.cc) { | 26565 | switch (fn_info.cc) { |
| 26658 | .Inline => try mod.errNoteNonLazy(src_loc, msg, "function has inline calling convention", .{}), | 26566 | .Inline => try sema.errNote(src_loc, msg, "function has inline calling convention", .{}), |
| 26659 | else => {}, | 26567 | else => {}, |
| 26660 | } | 26568 | } |
| 26661 | if (Type.fromInterned(fn_info.return_type).comptimeOnly(mod)) { | 26569 | if (Type.fromInterned(fn_info.return_type).comptimeOnly(mod)) { |
| 26662 | try mod.errNoteNonLazy(src_loc, msg, "function has a comptime-only return type", .{}); | 26570 | try sema.errNote(src_loc, msg, "function has a comptime-only return type", .{}); |
| 26663 | } | 26571 | } |
| 26664 | return; | 26572 | return; |
| 26665 | } | 26573 | } |
| ... | @@ -26679,14 +26587,14 @@ fn explainWhyTypeIsComptimeInner( | ... | @@ -26679,14 +26587,14 @@ fn explainWhyTypeIsComptimeInner( |
| 26679 | if (mod.typeToStruct(ty)) |struct_type| { | 26587 | if (mod.typeToStruct(ty)) |struct_type| { |
| 26680 | for (0..struct_type.field_types.len) |i| { | 26588 | for (0..struct_type.field_types.len) |i| { |
| 26681 | const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[i]); | 26589 | const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[i]); |
| 26682 | const field_src_loc = mod.fieldSrcLoc(struct_type.decl.unwrap().?, .{ | 26590 | const field_src: LazySrcLoc = .{ |
| 26683 | .index = i, | 26591 | .base_node_inst = struct_type.zir_index.unwrap().?, |
| 26684 | .range = .type, | 26592 | .offset = .{ .container_field_type = @intCast(i) }, |
| 26685 | }); | 26593 | }; |
| 26686 | | 26594 | |
| 26687 | if (try sema.typeRequiresComptime(field_ty)) { | 26595 | if (try sema.typeRequiresComptime(field_ty)) { |
| 26688 | try mod.errNoteNonLazy(field_src_loc, msg, "struct requires comptime because of this field", .{}); | 26596 | try sema.errNote(field_src, msg, "struct requires comptime because of this field", .{}); |
| 26689 | try sema.explainWhyTypeIsComptimeInner(msg, field_src_loc, field_ty, type_set); | 26597 | try sema.explainWhyTypeIsComptimeInner(msg, field_src, field_ty, type_set); |
| 26690 | } | 26598 | } |
| 26691 | } | 26599 | } |
| 26692 | } | 26600 | } |
| ... | @@ -26699,14 +26607,14 @@ fn explainWhyTypeIsComptimeInner( | ... | @@ -26699,14 +26607,14 @@ fn explainWhyTypeIsComptimeInner( |
| 26699 | if (mod.typeToUnion(ty)) |union_obj| { | 26607 | if (mod.typeToUnion(ty)) |union_obj| { |
| 26700 | for (0..union_obj.field_types.len) |i| { | 26608 | for (0..union_obj.field_types.len) |i| { |
| 26701 | const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[i]); | 26609 | const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[i]); |
| 26702 | const field_src_loc = mod.fieldSrcLoc(union_obj.decl, .{ | 26610 | const field_src: LazySrcLoc = .{ |
| 26703 | .index = i, | 26611 | .base_node_inst = union_obj.zir_index, |
| 26704 | .range = .type, | 26612 | .offset = .{ .container_field_type = @intCast(i) }, |
| 26705 | }); | 26613 | }; |
| 26706 | | 26614 | |
| 26707 | if (try sema.typeRequiresComptime(field_ty)) { | 26615 | if (try sema.typeRequiresComptime(field_ty)) { |
| 26708 | try mod.errNoteNonLazy(field_src_loc, msg, "union requires comptime because of this field", .{}); | 26616 | try sema.errNote(field_src, msg, "union requires comptime because of this field", .{}); |
| 26709 | try sema.explainWhyTypeIsComptimeInner(msg, field_src_loc, field_ty, type_set); | 26617 | try sema.explainWhyTypeIsComptimeInner(msg, field_src, field_ty, type_set); |
| 26710 | } | 26618 | } |
| 26711 | } | 26619 | } |
| 26712 | } | 26620 | } |
| ... | @@ -26796,7 +26704,7 @@ fn validateExternType( | ... | @@ -26796,7 +26704,7 @@ fn validateExternType( |
| 26796 | fn explainWhyTypeIsNotExtern( | 26704 | fn explainWhyTypeIsNotExtern( |
| 26797 | sema: *Sema, | 26705 | sema: *Sema, |
| 26798 | msg: *Module.ErrorMsg, | 26706 | msg: *Module.ErrorMsg, |
| 26799 | src_loc: Module.SrcLoc, | 26707 | src_loc: LazySrcLoc, |
| 26800 | ty: Type, | 26708 | ty: Type, |
| 26801 | position: ExternPosition, | 26709 | position: ExternPosition, |
| 26802 | ) CompileError!void { | 26710 | ) CompileError!void { |
| ... | @@ -26821,55 +26729,55 @@ fn explainWhyTypeIsNotExtern( | ... | @@ -26821,55 +26729,55 @@ fn explainWhyTypeIsNotExtern( |
| 26821 | | 26729 | |
| 26822 | .Pointer => { | 26730 | .Pointer => { |
| 26823 | if (ty.isSlice(mod)) { | 26731 | if (ty.isSlice(mod)) { |
| 26824 | try mod.errNoteNonLazy(src_loc, msg, "slices have no guaranteed in-memory representation", .{}); | 26732 | try sema.errNote(src_loc, msg, "slices have no guaranteed in-memory representation", .{}); |
| 26825 | } else { | 26733 | } else { |
| 26826 | const pointee_ty = ty.childType(mod); | 26734 | const pointee_ty = ty.childType(mod); |
| 26827 | if (!ty.isConstPtr(mod) and pointee_ty.zigTypeTag(mod) == .Fn) { | 26735 | if (!ty.isConstPtr(mod) and pointee_ty.zigTypeTag(mod) == .Fn) { |
| 26828 | try mod.errNoteNonLazy(src_loc, msg, "pointer to extern function must be 'const'", .{}); | 26736 | try sema.errNote(src_loc, msg, "pointer to extern function must be 'const'", .{}); |
| 26829 | } else if (try sema.typeRequiresComptime(ty)) { | 26737 | } else if (try sema.typeRequiresComptime(ty)) { |
| 26830 | try mod.errNoteNonLazy(src_loc, msg, "pointer to comptime-only type '{}'", .{pointee_ty.fmt(sema.mod)}); | 26738 | try sema.errNote(src_loc, msg, "pointer to comptime-only type '{}'", .{pointee_ty.fmt(sema.mod)}); |
| 26831 | try sema.explainWhyTypeIsComptime(msg, src_loc, ty); | 26739 | try sema.explainWhyTypeIsComptime(msg, src_loc, ty); |
| 26832 | } | 26740 | } |
| 26833 | try sema.explainWhyTypeIsNotExtern(msg, src_loc, pointee_ty, .other); | 26741 | try sema.explainWhyTypeIsNotExtern(msg, src_loc, pointee_ty, .other); |
| 26834 | } | 26742 | } |
| 26835 | }, | 26743 | }, |
| 26836 | .Void => try mod.errNoteNonLazy(src_loc, msg, "'void' is a zero bit type; for C 'void' use 'anyopaque'", .{}), | 26744 | .Void => try sema.errNote(src_loc, msg, "'void' is a zero bit type; for C 'void' use 'anyopaque'", .{}), |
| 26837 | .NoReturn => try mod.errNoteNonLazy(src_loc, msg, "'noreturn' is only allowed as a return type", .{}), | 26745 | .NoReturn => try sema.errNote(src_loc, msg, "'noreturn' is only allowed as a return type", .{}), |
| 26838 | .Int => if (!std.math.isPowerOfTwo(ty.intInfo(mod).bits)) { | 26746 | .Int => if (!std.math.isPowerOfTwo(ty.intInfo(mod).bits)) { |
| 26839 | try mod.errNoteNonLazy(src_loc, msg, "only integers with 0 or power of two bits are extern compatible", .{}); | 26747 | try sema.errNote(src_loc, msg, "only integers with 0 or power of two bits are extern compatible", .{}); |
| 26840 | } else { | 26748 | } else { |
| 26841 | try mod.errNoteNonLazy(src_loc, msg, "only integers with 0, 8, 16, 32, 64 and 128 bits are extern compatible", .{}); | 26749 | try sema.errNote(src_loc, msg, "only integers with 0, 8, 16, 32, 64 and 128 bits are extern compatible", .{}); |
| 26842 | }, | 26750 | }, |
| 26843 | .Fn => { | 26751 | .Fn => { |
| 26844 | if (position != .other) { | 26752 | if (position != .other) { |
| 26845 | try mod.errNoteNonLazy(src_loc, msg, "type has no guaranteed in-memory representation", .{}); | 26753 | try sema.errNote(src_loc, msg, "type has no guaranteed in-memory representation", .{}); |
| 26846 | try mod.errNoteNonLazy(src_loc, msg, "use '*const ' to make a function pointer type", .{}); | 26754 | try sema.errNote(src_loc, msg, "use '*const ' to make a function pointer type", .{}); |
| 26847 | return; | 26755 | return; |
| 26848 | } | 26756 | } |
| 26849 | switch (ty.fnCallingConvention(mod)) { | 26757 | switch (ty.fnCallingConvention(mod)) { |
| 26850 | .Unspecified => try mod.errNoteNonLazy(src_loc, msg, "extern function must specify calling convention", .{}), | 26758 | .Unspecified => try sema.errNote(src_loc, msg, "extern function must specify calling convention", .{}), |
| 26851 | .Async => try mod.errNoteNonLazy(src_loc, msg, "async function cannot be extern", .{}), | 26759 | .Async => try sema.errNote(src_loc, msg, "async function cannot be extern", .{}), |
| 26852 | .Inline => try mod.errNoteNonLazy(src_loc, msg, "inline function cannot be extern", .{}), | 26760 | .Inline => try sema.errNote(src_loc, msg, "inline function cannot be extern", .{}), |
| 26853 | else => return, | 26761 | else => return, |
| 26854 | } | 26762 | } |
| 26855 | }, | 26763 | }, |
| 26856 | .Enum => { | 26764 | .Enum => { |
| 26857 | const tag_ty = ty.intTagType(mod); | 26765 | const tag_ty = ty.intTagType(mod); |
| 26858 | try mod.errNoteNonLazy(src_loc, msg, "enum tag type '{}' is not extern compatible", .{tag_ty.fmt(sema.mod)}); | 26766 | try sema.errNote(src_loc, msg, "enum tag type '{}' is not extern compatible", .{tag_ty.fmt(sema.mod)}); |
| 26859 | try sema.explainWhyTypeIsNotExtern(msg, src_loc, tag_ty, position); | 26767 | try sema.explainWhyTypeIsNotExtern(msg, src_loc, tag_ty, position); |
| 26860 | }, | 26768 | }, |
| 26861 | .Struct => try mod.errNoteNonLazy(src_loc, msg, "only extern structs and ABI sized packed structs are extern compatible", .{}), | 26769 | .Struct => try sema.errNote(src_loc, msg, "only extern structs and ABI sized packed structs are extern compatible", .{}), |
| 26862 | .Union => try mod.errNoteNonLazy(src_loc, msg, "only extern unions and ABI sized packed unions are extern compatible", .{}), | 26770 | .Union => try sema.errNote(src_loc, msg, "only extern unions and ABI sized packed unions are extern compatible", .{}), |
| 26863 | .Array => { | 26771 | .Array => { |
| 26864 | if (position == .ret_ty) { | 26772 | if (position == .ret_ty) { |
| 26865 | return mod.errNoteNonLazy(src_loc, msg, "arrays are not allowed as a return type", .{}); | 26773 | return sema.errNote(src_loc, msg, "arrays are not allowed as a return type", .{}); |
| 26866 | } else if (position == .param_ty) { | 26774 | } else if (position == .param_ty) { |
| 26867 | return mod.errNoteNonLazy(src_loc, msg, "arrays are not allowed as a parameter type", .{}); | 26775 | return sema.errNote(src_loc, msg, "arrays are not allowed as a parameter type", .{}); |
| 26868 | } | 26776 | } |
| 26869 | try sema.explainWhyTypeIsNotExtern(msg, src_loc, ty.elemType2(mod), .element); | 26777 | try sema.explainWhyTypeIsNotExtern(msg, src_loc, ty.elemType2(mod), .element); |
| 26870 | }, | 26778 | }, |
| 26871 | .Vector => try sema.explainWhyTypeIsNotExtern(msg, src_loc, ty.elemType2(mod), .element), | 26779 | .Vector => try sema.explainWhyTypeIsNotExtern(msg, src_loc, ty.elemType2(mod), .element), |
| 26872 | .Optional => try mod.errNoteNonLazy(src_loc, msg, "only pointer like optionals are extern compatible", .{}), | 26780 | .Optional => try sema.errNote(src_loc, msg, "only pointer like optionals are extern compatible", .{}), |
| 26873 | } | 26781 | } |
| 26874 | } | 26782 | } |
| 26875 | | 26783 | |
| ... | @@ -26912,7 +26820,7 @@ fn validatePackedType(sema: *Sema, ty: Type) !bool { | ... | @@ -26912,7 +26820,7 @@ fn validatePackedType(sema: *Sema, ty: Type) !bool { |
| 26912 | fn explainWhyTypeIsNotPacked( | 26820 | fn explainWhyTypeIsNotPacked( |
| 26913 | sema: *Sema, | 26821 | sema: *Sema, |
| 26914 | msg: *Module.ErrorMsg, | 26822 | msg: *Module.ErrorMsg, |
| 26915 | src_loc: Module.SrcLoc, | 26823 | src_loc: LazySrcLoc, |
| 26916 | ty: Type, | 26824 | ty: Type, |
| 26917 | ) CompileError!void { | 26825 | ) CompileError!void { |
| 26918 | const mod = sema.mod; | 26826 | const mod = sema.mod; |
| ... | @@ -26938,19 +26846,19 @@ fn explainWhyTypeIsNotPacked( | ... | @@ -26938,19 +26846,19 @@ fn explainWhyTypeIsNotPacked( |
| 26938 | .AnyFrame, | 26846 | .AnyFrame, |
| 26939 | .Optional, | 26847 | .Optional, |
| 26940 | .Array, | 26848 | .Array, |
| 26941 | => try mod.errNoteNonLazy(src_loc, msg, "type has no guaranteed in-memory representation", .{}), | 26849 | => try sema.errNote(src_loc, msg, "type has no guaranteed in-memory representation", .{}), |
| 26942 | .Pointer => if (ty.isSlice(mod)) { | 26850 | .Pointer => if (ty.isSlice(mod)) { |
| 26943 | try mod.errNoteNonLazy(src_loc, msg, "slices have no guaranteed in-memory representation", .{}); | 26851 | try sema.errNote(src_loc, msg, "slices have no guaranteed in-memory representation", .{}); |
| 26944 | } else { | 26852 | } else { |
| 26945 | try mod.errNoteNonLazy(src_loc, msg, "comptime-only pointer has no guaranteed in-memory representation", .{}); | 26853 | try sema.errNote(src_loc, msg, "comptime-only pointer has no guaranteed in-memory representation", .{}); |
| 26946 | try sema.explainWhyTypeIsComptime(msg, src_loc, ty); | 26854 | try sema.explainWhyTypeIsComptime(msg, src_loc, ty); |
| 26947 | }, | 26855 | }, |
| 26948 | .Fn => { | 26856 | .Fn => { |
| 26949 | try mod.errNoteNonLazy(src_loc, msg, "type has no guaranteed in-memory representation", .{}); | 26857 | try sema.errNote(src_loc, msg, "type has no guaranteed in-memory representation", .{}); |
| 26950 | try mod.errNoteNonLazy(src_loc, msg, "use '*const ' to make a function pointer type", .{}); | 26858 | try sema.errNote(src_loc, msg, "use '*const ' to make a function pointer type", .{}); |
| 26951 | }, | 26859 | }, |
| 26952 | .Struct => try mod.errNoteNonLazy(src_loc, msg, "only packed structs layout are allowed in packed types", .{}), | 26860 | .Struct => try sema.errNote(src_loc, msg, "only packed structs layout are allowed in packed types", .{}), |
| 26953 | .Union => try mod.errNoteNonLazy(src_loc, msg, "only packed unions layout are allowed in packed types", .{}), | 26861 | .Union => try sema.errNote(src_loc, msg, "only packed unions layout are allowed in packed types", .{}), |
| 26954 | } | 26862 | } |
| 26955 | } | 26863 | } |
| 26956 | | 26864 | |
| ... | @@ -27001,11 +26909,11 @@ fn preparePanicId(sema: *Sema, block: *Block, panic_id: Module.PanicId) !InternP | ... | @@ -27001,11 +26909,11 @@ fn preparePanicId(sema: *Sema, block: *Block, panic_id: Module.PanicId) !InternP |
| 27001 | const panic_messages_ty = try sema.getBuiltinType("panic_messages"); | 26909 | const panic_messages_ty = try sema.getBuiltinType("panic_messages"); |
| 27002 | const msg_decl_index = (sema.namespaceLookup( | 26910 | const msg_decl_index = (sema.namespaceLookup( |
| 27003 | block, | 26911 | block, |
| 27004 | .unneeded, | 26912 | LazySrcLoc.unneeded, |
| 27005 | panic_messages_ty.getNamespaceIndex(mod), | 26913 | panic_messages_ty.getNamespaceIndex(mod), |
| 27006 | try mod.intern_pool.getOrPutString(gpa, @tagName(panic_id), .no_embedded_nulls), | 26914 | try mod.intern_pool.getOrPutString(gpa, @tagName(panic_id), .no_embedded_nulls), |
| 27007 | ) catch |err| switch (err) { | 26915 | ) catch |err| switch (err) { |
| 27008 | error.AnalysisFail, error.NeededSourceLocation => @panic("std.builtin.panic_messages is corrupt"), | 26916 | error.AnalysisFail => @panic("std.builtin.panic_messages is corrupt"), |
| 27009 | error.GenericPoison, error.ComptimeReturn, error.ComptimeBreak => unreachable, | 26917 | error.GenericPoison, error.ComptimeReturn, error.ComptimeBreak => unreachable, |
| 27010 | error.OutOfMemory => |e| return e, | 26918 | error.OutOfMemory => |e| return e, |
| 27011 | }).?; | 26919 | }).?; |
| ... | @@ -27027,11 +26935,12 @@ fn addSafetyCheck( | ... | @@ -27027,11 +26935,12 @@ fn addSafetyCheck( |
| 27027 | var fail_block: Block = .{ | 26935 | var fail_block: Block = .{ |
| 27028 | .parent = parent_block, | 26936 | .parent = parent_block, |
| 27029 | .sema = sema, | 26937 | .sema = sema, |
| 27030 | .src_decl = parent_block.src_decl, | | |
| 27031 | .namespace = parent_block.namespace, | 26938 | .namespace = parent_block.namespace, |
| 27032 | .instructions = .{}, | 26939 | .instructions = .{}, |
| 27033 | .inlining = parent_block.inlining, | 26940 | .inlining = parent_block.inlining, |
| 27034 | .is_comptime = false, | 26941 | .is_comptime = false, |
| | 26942 | .src_base_inst = parent_block.src_base_inst, |
| | 26943 | .type_name_ctx = parent_block.type_name_ctx, |
| 27035 | }; | 26944 | }; |
| 27036 | | 26945 | |
| 27037 | defer fail_block.instructions.deinit(gpa); | 26946 | defer fail_block.instructions.deinit(gpa); |
| ... | @@ -27135,11 +27044,12 @@ fn panicUnwrapError( | ... | @@ -27135,11 +27044,12 @@ fn panicUnwrapError( |
| 27135 | var fail_block: Block = .{ | 27044 | var fail_block: Block = .{ |
| 27136 | .parent = parent_block, | 27045 | .parent = parent_block, |
| 27137 | .sema = sema, | 27046 | .sema = sema, |
| 27138 | .src_decl = parent_block.src_decl, | | |
| 27139 | .namespace = parent_block.namespace, | 27047 | .namespace = parent_block.namespace, |
| 27140 | .instructions = .{}, | 27048 | .instructions = .{}, |
| 27141 | .inlining = parent_block.inlining, | 27049 | .inlining = parent_block.inlining, |
| 27142 | .is_comptime = false, | 27050 | .is_comptime = false, |
| | 27051 | .src_base_inst = parent_block.src_base_inst, |
| | 27052 | .type_name_ctx = parent_block.type_name_ctx, |
| 27143 | }; | 27053 | }; |
| 27144 | | 27054 | |
| 27145 | defer fail_block.instructions.deinit(gpa); | 27055 | defer fail_block.instructions.deinit(gpa); |
| ... | @@ -27251,11 +27161,12 @@ fn safetyCheckFormatted( | ... | @@ -27251,11 +27161,12 @@ fn safetyCheckFormatted( |
| 27251 | var fail_block: Block = .{ | 27161 | var fail_block: Block = .{ |
| 27252 | .parent = parent_block, | 27162 | .parent = parent_block, |
| 27253 | .sema = sema, | 27163 | .sema = sema, |
| 27254 | .src_decl = parent_block.src_decl, | | |
| 27255 | .namespace = parent_block.namespace, | 27164 | .namespace = parent_block.namespace, |
| 27256 | .instructions = .{}, | 27165 | .instructions = .{}, |
| 27257 | .inlining = parent_block.inlining, | 27166 | .inlining = parent_block.inlining, |
| 27258 | .is_comptime = false, | 27167 | .is_comptime = false, |
| | 27168 | .src_base_inst = parent_block.src_base_inst, |
| | 27169 | .type_name_ctx = parent_block.type_name_ctx, |
| 27259 | }; | 27170 | }; |
| 27260 | | 27171 | |
| 27261 | defer fail_block.instructions.deinit(gpa); | 27172 | defer fail_block.instructions.deinit(gpa); |
| ... | @@ -27279,13 +27190,11 @@ fn emitBackwardBranch(sema: *Sema, block: *Block, src: LazySrcLoc) !void { | ... | @@ -27279,13 +27190,11 @@ fn emitBackwardBranch(sema: *Sema, block: *Block, src: LazySrcLoc) !void { |
| 27279 | sema.branch_count += 1; | 27190 | sema.branch_count += 1; |
| 27280 | if (sema.branch_count > sema.branch_quota) { | 27191 | if (sema.branch_count > sema.branch_quota) { |
| 27281 | const msg = try sema.errMsg( | 27192 | const msg = try sema.errMsg( |
| 27282 | block, | | |
| 27283 | src, | 27193 | src, |
| 27284 | "evaluation exceeded {d} backwards branches", | 27194 | "evaluation exceeded {d} backwards branches", |
| 27285 | .{sema.branch_quota}, | 27195 | .{sema.branch_quota}, |
| 27286 | ); | 27196 | ); |
| 27287 | try sema.errNote( | 27197 | try sema.errNote( |
| 27288 | block, | | |
| 27289 | src, | 27198 | src, |
| 27290 | msg, | 27199 | msg, |
| 27291 | "use @setEvalBranchQuota() to raise the branch limit from {d}", | 27200 | "use @setEvalBranchQuota() to raise the branch limit from {d}", |
| ... | @@ -27451,10 +27360,10 @@ fn fieldVal( | ... | @@ -27451,10 +27360,10 @@ fn fieldVal( |
| 27451 | }, | 27360 | }, |
| 27452 | else => { | 27361 | else => { |
| 27453 | const msg = msg: { | 27362 | const msg = msg: { |
| 27454 | const msg = try sema.errMsg(block, src, "type '{}' has no members", .{child_type.fmt(mod)}); | 27363 | const msg = try sema.errMsg(src, "type '{}' has no members", .{child_type.fmt(mod)}); |
| 27455 | errdefer msg.destroy(sema.gpa); | 27364 | errdefer msg.destroy(sema.gpa); |
| 27456 | if (child_type.isSlice(mod)) try sema.errNote(block, src, msg, "slice values have 'len' and 'ptr' members", .{}); | 27365 | if (child_type.isSlice(mod)) try sema.errNote(src, msg, "slice values have 'len' and 'ptr' members", .{}); |
| 27457 | if (child_type.zigTypeTag(mod) == .Array) try sema.errNote(block, src, msg, "array values have 'len' member", .{}); | 27366 | if (child_type.zigTypeTag(mod) == .Array) try sema.errNote(src, msg, "array values have 'len' member", .{}); |
| 27458 | break :msg msg; | 27367 | break :msg msg; |
| 27459 | }; | 27368 | }; |
| 27460 | return sema.failWithOwnedErrorMsg(block, msg); | 27369 | return sema.failWithOwnedErrorMsg(block, msg); |
| ... | @@ -27612,7 +27521,7 @@ fn fieldPtr( | ... | @@ -27612,7 +27521,7 @@ fn fieldPtr( |
| 27612 | } | 27521 | } |
| 27613 | }, | 27522 | }, |
| 27614 | .Type => { | 27523 | .Type => { |
| 27615 | _ = try sema.resolveConstDefinedValue(block, .unneeded, object_ptr, undefined); | 27524 | _ = try sema.resolveConstDefinedValue(block, LazySrcLoc.unneeded, object_ptr, undefined); |
| 27616 | const result = try sema.analyzeLoad(block, src, object_ptr, object_ptr_src); | 27525 | const result = try sema.analyzeLoad(block, src, object_ptr, object_ptr_src); |
| 27617 | const inner = if (is_pointer_to) | 27526 | const inner = if (is_pointer_to) |
| 27618 | try sema.analyzeLoad(block, src, result, object_ptr_src) | 27527 | try sema.analyzeLoad(block, src, result, object_ptr_src) |
| ... | @@ -27805,7 +27714,7 @@ fn fieldCallBind( | ... | @@ -27805,7 +27714,7 @@ fn fieldCallBind( |
| 27805 | const decl_idx = (try sema.namespaceLookup(block, src, namespace, field_name)) orelse | 27714 | const decl_idx = (try sema.namespaceLookup(block, src, namespace, field_name)) orelse |
| 27806 | break :found_decl null; | 27715 | break :found_decl null; |
| 27807 | | 27716 | |
| 27808 | try sema.addReferencedBy(block, src, decl_idx); | 27717 | try sema.addReferencedBy(src, decl_idx); |
| 27809 | const decl_val = try sema.analyzeDeclVal(block, src, decl_idx); | 27718 | const decl_val = try sema.analyzeDeclVal(block, src, decl_idx); |
| 27810 | const decl_type = sema.typeOf(decl_val); | 27719 | const decl_type = sema.typeOf(decl_val); |
| 27811 | if (mod.typeToFunc(decl_type)) |func_type| f: { | 27720 | if (mod.typeToFunc(decl_type)) |func_type| f: { |
| ... | @@ -27864,7 +27773,7 @@ fn fieldCallBind( | ... | @@ -27864,7 +27773,7 @@ fn fieldCallBind( |
| 27864 | }; | 27773 | }; |
| 27865 | | 27774 | |
| 27866 | const msg = msg: { | 27775 | const msg = msg: { |
| 27867 | const msg = try sema.errMsg(block, src, "no field or member function named '{}' in '{}'", .{ | 27776 | const msg = try sema.errMsg(src, "no field or member function named '{}' in '{}'", .{ |
| 27868 | field_name.fmt(ip), | 27777 | field_name.fmt(ip), |
| 27869 | concrete_ty.fmt(mod), | 27778 | concrete_ty.fmt(mod), |
| 27870 | }); | 27779 | }); |
| ... | @@ -27872,10 +27781,13 @@ fn fieldCallBind( | ... | @@ -27872,10 +27781,13 @@ fn fieldCallBind( |
| 27872 | try sema.addDeclaredHereNote(msg, concrete_ty); | 27781 | try sema.addDeclaredHereNote(msg, concrete_ty); |
| 27873 | if (found_decl) |decl_idx| { | 27782 | if (found_decl) |decl_idx| { |
| 27874 | const decl = mod.declPtr(decl_idx); | 27783 | const decl = mod.declPtr(decl_idx); |
| 27875 | try mod.errNoteNonLazy(decl.srcLoc(mod), msg, "'{}' is not a member function", .{field_name.fmt(ip)}); | 27784 | try sema.errNote(.{ |
| | 27785 | .base_node_inst = decl.zir_decl_index.unwrap().?, |
| | 27786 | .offset = LazySrcLoc.Offset.nodeOffset(0), |
| | 27787 | }, msg, "'{}' is not a member function", .{field_name.fmt(ip)}); |
| 27876 | } | 27788 | } |
| 27877 | if (concrete_ty.zigTypeTag(mod) == .ErrorUnion) { | 27789 | if (concrete_ty.zigTypeTag(mod) == .ErrorUnion) { |
| 27878 | try sema.errNote(block, src, msg, "consider using 'try', 'catch', or 'if'", .{}); | 27790 | try sema.errNote(src, msg, "consider using 'try', 'catch', or 'if'", .{}); |
| 27879 | } | 27791 | } |
| 27880 | break :msg msg; | 27792 | break :msg msg; |
| 27881 | }; | 27793 | }; |
| ... | @@ -27933,11 +27845,14 @@ fn namespaceLookup( | ... | @@ -27933,11 +27845,14 @@ fn namespaceLookup( |
| 27933 | const decl = mod.declPtr(decl_index); | 27845 | const decl = mod.declPtr(decl_index); |
| 27934 | if (!decl.is_pub and decl.getFileScope(mod) != block.getFileScope(mod)) { | 27846 | if (!decl.is_pub and decl.getFileScope(mod) != block.getFileScope(mod)) { |
| 27935 | const msg = msg: { | 27847 | const msg = msg: { |
| 27936 | const msg = try sema.errMsg(block, src, "'{}' is not marked 'pub'", .{ | 27848 | const msg = try sema.errMsg(src, "'{}' is not marked 'pub'", .{ |
| 27937 | decl_name.fmt(&mod.intern_pool), | 27849 | decl_name.fmt(&mod.intern_pool), |
| 27938 | }); | 27850 | }); |
| 27939 | errdefer msg.destroy(gpa); | 27851 | errdefer msg.destroy(gpa); |
| 27940 | try mod.errNoteNonLazy(decl.srcLoc(mod), msg, "declared here", .{}); | 27852 | try sema.errNote(.{ |
| | 27853 | .base_node_inst = decl.zir_decl_index.unwrap().?, |
| | 27854 | .offset = LazySrcLoc.Offset.nodeOffset(0), |
| | 27855 | }, msg, "declared here", .{}); |
| 27941 | break :msg msg; | 27856 | break :msg msg; |
| 27942 | }; | 27857 | }; |
| 27943 | return sema.failWithOwnedErrorMsg(block, msg); | 27858 | return sema.failWithOwnedErrorMsg(block, msg); |
| ... | @@ -27955,7 +27870,7 @@ fn namespaceLookupRef( | ... | @@ -27955,7 +27870,7 @@ fn namespaceLookupRef( |
| 27955 | decl_name: InternPool.NullTerminatedString, | 27870 | decl_name: InternPool.NullTerminatedString, |
| 27956 | ) CompileError!?Air.Inst.Ref { | 27871 | ) CompileError!?Air.Inst.Ref { |
| 27957 | const decl = (try sema.namespaceLookup(block, src, opt_namespace, decl_name)) orelse return null; | 27872 | const decl = (try sema.namespaceLookup(block, src, opt_namespace, decl_name)) orelse return null; |
| 27958 | try sema.addReferencedBy(block, src, decl); | 27873 | try sema.addReferencedBy(src, decl); |
| 27959 | return try sema.analyzeDeclRef(decl); | 27874 | return try sema.analyzeDeclRef(decl); |
| 27960 | } | 27875 | } |
| 27961 | | 27876 | |
| ... | @@ -28002,7 +27917,7 @@ fn structFieldPtr( | ... | @@ -28002,7 +27917,7 @@ fn structFieldPtr( |
| 28002 | const struct_type = mod.typeToStruct(struct_ty).?; | 27917 | const struct_type = mod.typeToStruct(struct_ty).?; |
| 28003 | | 27918 | |
| 28004 | const field_index = struct_type.nameIndex(ip, field_name) orelse | 27919 | const field_index = struct_type.nameIndex(ip, field_name) orelse |
| 28005 | return sema.failWithBadStructFieldAccess(block, struct_type, field_name_src, field_name); | 27920 | return sema.failWithBadStructFieldAccess(block, struct_ty, struct_type, field_name_src, field_name); |
| 28006 | | 27921 | |
| 28007 | return sema.structFieldPtrByIndex(block, src, struct_ptr, field_index, field_name_src, struct_ty, initializing); | 27922 | return sema.structFieldPtrByIndex(block, src, struct_ptr, field_index, field_name_src, struct_ty, initializing); |
| 28008 | } | 27923 | } |
| ... | @@ -28117,7 +28032,7 @@ fn structFieldVal( | ... | @@ -28117,7 +28032,7 @@ fn structFieldVal( |
| 28117 | return sema.tupleFieldVal(block, src, struct_byval, field_name, field_name_src, struct_ty); | 28032 | return sema.tupleFieldVal(block, src, struct_byval, field_name, field_name_src, struct_ty); |
| 28118 | | 28033 | |
| 28119 | const field_index = struct_type.nameIndex(ip, field_name) orelse | 28034 | const field_index = struct_type.nameIndex(ip, field_name) orelse |
| 28120 | return sema.failWithBadStructFieldAccess(block, struct_type, field_name_src, field_name); | 28035 | return sema.failWithBadStructFieldAccess(block, struct_ty, struct_type, field_name_src, field_name); |
| 28121 | if (struct_type.fieldIsComptime(ip, field_index)) { | 28036 | if (struct_type.fieldIsComptime(ip, field_index)) { |
| 28122 | try sema.resolveStructFieldInits(struct_ty); | 28037 | try sema.resolveStructFieldInits(struct_ty); |
| 28123 | return Air.internedToRef(struct_type.field_inits.get(ip)[field_index]); | 28038 | return Air.internedToRef(struct_type.field_inits.get(ip)[field_index]); |
| ... | @@ -28270,7 +28185,7 @@ fn unionFieldPtr( | ... | @@ -28270,7 +28185,7 @@ fn unionFieldPtr( |
| 28270 | | 28185 | |
| 28271 | if (initializing and field_ty.zigTypeTag(mod) == .NoReturn) { | 28186 | if (initializing and field_ty.zigTypeTag(mod) == .NoReturn) { |
| 28272 | const msg = msg: { | 28187 | const msg = msg: { |
| 28273 | const msg = try sema.errMsg(block, src, "cannot initialize 'noreturn' field of union", .{}); | 28188 | const msg = try sema.errMsg(src, "cannot initialize 'noreturn' field of union", .{}); |
| 28274 | errdefer msg.destroy(sema.gpa); | 28189 | errdefer msg.destroy(sema.gpa); |
| 28275 | | 28190 | |
| 28276 | try sema.addFieldErrNote(union_ty, field_index, msg, "field '{}' declared here", .{ | 28191 | try sema.addFieldErrNote(union_ty, field_index, msg, "field '{}' declared here", .{ |
| ... | @@ -28303,7 +28218,7 @@ fn unionFieldPtr( | ... | @@ -28303,7 +28218,7 @@ fn unionFieldPtr( |
| 28303 | const msg = msg: { | 28218 | const msg = msg: { |
| 28304 | const active_index = Type.fromInterned(union_obj.enum_tag_ty).enumTagFieldIndex(Value.fromInterned(un.tag), mod).?; | 28219 | const active_index = Type.fromInterned(union_obj.enum_tag_ty).enumTagFieldIndex(Value.fromInterned(un.tag), mod).?; |
| 28305 | const active_field_name = Type.fromInterned(union_obj.enum_tag_ty).enumFieldName(active_index, mod); | 28220 | const active_field_name = Type.fromInterned(union_obj.enum_tag_ty).enumFieldName(active_index, mod); |
| 28306 | const msg = try sema.errMsg(block, src, "access of union field '{}' while field '{}' is active", .{ | 28221 | const msg = try sema.errMsg(src, "access of union field '{}' while field '{}' is active", .{ |
| 28307 | field_name.fmt(ip), | 28222 | field_name.fmt(ip), |
| 28308 | active_field_name.fmt(ip), | 28223 | active_field_name.fmt(ip), |
| 28309 | }); | 28224 | }); |
| ... | @@ -28371,7 +28286,7 @@ fn unionFieldVal( | ... | @@ -28371,7 +28286,7 @@ fn unionFieldVal( |
| 28371 | const msg = msg: { | 28286 | const msg = msg: { |
| 28372 | const active_index = Type.fromInterned(union_obj.enum_tag_ty).enumTagFieldIndex(Value.fromInterned(un.tag), zcu).?; | 28287 | const active_index = Type.fromInterned(union_obj.enum_tag_ty).enumTagFieldIndex(Value.fromInterned(un.tag), zcu).?; |
| 28373 | const active_field_name = Type.fromInterned(union_obj.enum_tag_ty).enumFieldName(active_index, zcu); | 28288 | const active_field_name = Type.fromInterned(union_obj.enum_tag_ty).enumFieldName(active_index, zcu); |
| 28374 | const msg = try sema.errMsg(block, src, "access of union field '{}' while field '{}' is active", .{ | 28289 | const msg = try sema.errMsg(src, "access of union field '{}' while field '{}' is active", .{ |
| 28375 | field_name.fmt(ip), active_field_name.fmt(ip), | 28290 | field_name.fmt(ip), active_field_name.fmt(ip), |
| 28376 | }); | 28291 | }); |
| 28377 | errdefer msg.destroy(sema.gpa); | 28292 | errdefer msg.destroy(sema.gpa); |
| ... | @@ -28594,15 +28509,13 @@ fn validateRuntimeElemAccess( | ... | @@ -28594,15 +28509,13 @@ fn validateRuntimeElemAccess( |
| 28594 | if (try sema.typeRequiresComptime(elem_ty)) { | 28509 | if (try sema.typeRequiresComptime(elem_ty)) { |
| 28595 | const msg = msg: { | 28510 | const msg = msg: { |
| 28596 | const msg = try sema.errMsg( | 28511 | const msg = try sema.errMsg( |
| 28597 | block, | | |
| 28598 | elem_index_src, | 28512 | elem_index_src, |
| 28599 | "values of type '{}' must be comptime-known, but index value is runtime-known", | 28513 | "values of type '{}' must be comptime-known, but index value is runtime-known", |
| 28600 | .{parent_ty.fmt(mod)}, | 28514 | .{parent_ty.fmt(mod)}, |
| 28601 | ); | 28515 | ); |
| 28602 | errdefer msg.destroy(sema.gpa); | 28516 | errdefer msg.destroy(sema.gpa); |
| 28603 | | 28517 | |
| 28604 | const src_decl = mod.declPtr(block.src_decl); | 28518 | try sema.explainWhyTypeIsComptime(msg, parent_src, parent_ty); |
| 28605 | try sema.explainWhyTypeIsComptime(msg, src_decl.toSrcLoc(parent_src, mod), parent_ty); | | |
| 28606 | | 28519 | |
| 28607 | break :msg msg; | 28520 | break :msg msg; |
| 28608 | }; | 28521 | }; |
| ... | @@ -28990,21 +28903,18 @@ const CoerceOpts = struct { | ... | @@ -28990,21 +28903,18 @@ const CoerceOpts = struct { |
| 28990 | func_inst: Air.Inst.Ref = .none, | 28903 | func_inst: Air.Inst.Ref = .none, |
| 28991 | param_i: u32 = undefined, | 28904 | param_i: u32 = undefined, |
| 28992 | | 28905 | |
| 28993 | fn get(info: @This(), sema: *Sema) !?Module.SrcLoc { | 28906 | fn get(info: @This(), sema: *Sema) !?LazySrcLoc { |
| 28994 | if (info.func_inst == .none) return null; | 28907 | if (info.func_inst == .none) return null; |
| 28995 | const mod = sema.mod; | 28908 | const fn_decl = try sema.funcDeclSrc(info.func_inst) orelse return null; |
| 28996 | const fn_decl = (try sema.funcDeclSrc(info.func_inst)) orelse return null; | 28909 | return .{ |
| 28997 | const param_src = Module.paramSrc(0, mod, fn_decl, info.param_i); | 28910 | .base_node_inst = fn_decl.zir_decl_index.unwrap().?, |
| 28998 | if (param_src == .node_offset_param) { | 28911 | .offset = .{ .fn_proto_param_type = .{ |
| 28999 | return Module.SrcLoc{ | 28912 | .fn_proto_node_offset = 0, |
| 29000 | .file_scope = fn_decl.getFileScope(mod), | 28913 | .param_index = info.param_i, |
| 29001 | .parent_decl_node = fn_decl.src_node, | 28914 | } }, |
| 29002 | .lazy = LazySrcLoc.nodeOffset(param_src.node_offset_param), | 28915 | }; |
| 29003 | }; | | |
| 29004 | } | | |
| 29005 | return fn_decl.toSrcLoc(param_src, mod); | | |
| 29006 | } | 28916 | } |
| 29007 | } = .{}, | 28917 | } = .{ .func_inst = .none, .param_i = undefined }, |
| 29008 | }; | 28918 | }; |
| 29009 | | 28919 | |
| 29010 | fn coerceExtra( | 28920 | fn coerceExtra( |
| ... | @@ -29097,7 +29007,7 @@ fn coerceExtra( | ... | @@ -29097,7 +29007,7 @@ fn coerceExtra( |
| 29097 | | 29007 | |
| 29098 | // Function body to function pointer. | 29008 | // Function body to function pointer. |
| 29099 | if (inst_ty.zigTypeTag(zcu) == .Fn) { | 29009 | if (inst_ty.zigTypeTag(zcu) == .Fn) { |
| 29100 | const fn_val = try sema.resolveConstDefinedValue(block, .unneeded, inst, undefined); | 29010 | const fn_val = try sema.resolveConstDefinedValue(block, LazySrcLoc.unneeded, inst, undefined); |
| 29101 | const fn_decl = fn_val.pointerDecl(zcu).?; | 29011 | const fn_decl = fn_val.pointerDecl(zcu).?; |
| 29102 | const inst_as_ptr = try sema.analyzeDeclRef(fn_decl); | 29012 | const inst_as_ptr = try sema.analyzeDeclRef(fn_decl); |
| 29103 | return sema.coerce(block, dest_ty, inst_as_ptr, inst_src); | 29013 | return sema.coerce(block, dest_ty, inst_as_ptr, inst_src); |
| ... | @@ -29345,9 +29255,9 @@ fn coerceExtra( | ... | @@ -29345,9 +29255,9 @@ fn coerceExtra( |
| 29345 | // pointer to tuple to slice | 29255 | // pointer to tuple to slice |
| 29346 | if (!dest_info.flags.is_const) { | 29256 | if (!dest_info.flags.is_const) { |
| 29347 | const err_msg = err_msg: { | 29257 | const err_msg = err_msg: { |
| 29348 | const err_msg = try sema.errMsg(block, inst_src, "cannot cast pointer to tuple to '{}'", .{dest_ty.fmt(zcu)}); | 29258 | const err_msg = try sema.errMsg(inst_src, "cannot cast pointer to tuple to '{}'", .{dest_ty.fmt(zcu)}); |
| 29349 | errdefer err_msg.destroy(sema.gpa); | 29259 | errdefer err_msg.destroy(sema.gpa); |
| 29350 | try sema.errNote(block, dest_ty_src, err_msg, "pointers to tuples can only coerce to constant pointers", .{}); | 29260 | try sema.errNote(dest_ty_src, err_msg, "pointers to tuples can only coerce to constant pointers", .{}); |
| 29351 | break :err_msg err_msg; | 29261 | break :err_msg err_msg; |
| 29352 | }; | 29262 | }; |
| 29353 | return sema.failWithOwnedErrorMsg(block, err_msg); | 29263 | return sema.failWithOwnedErrorMsg(block, err_msg); |
| ... | @@ -29434,7 +29344,7 @@ fn coerceExtra( | ... | @@ -29434,7 +29344,7 @@ fn coerceExtra( |
| 29434 | }, | 29344 | }, |
| 29435 | .Float, .ComptimeFloat => switch (inst_ty.zigTypeTag(zcu)) { | 29345 | .Float, .ComptimeFloat => switch (inst_ty.zigTypeTag(zcu)) { |
| 29436 | .ComptimeFloat => { | 29346 | .ComptimeFloat => { |
| 29437 | const val = try sema.resolveConstDefinedValue(block, .unneeded, inst, undefined); | 29347 | const val = try sema.resolveConstDefinedValue(block, LazySrcLoc.unneeded, inst, undefined); |
| 29438 | const result_val = try val.floatCast(dest_ty, zcu); | 29348 | const result_val = try val.floatCast(dest_ty, zcu); |
| 29439 | return Air.internedToRef(result_val.toIntern()); | 29349 | return Air.internedToRef(result_val.toIntern()); |
| 29440 | }, | 29350 | }, |
| ... | @@ -29493,7 +29403,7 @@ fn coerceExtra( | ... | @@ -29493,7 +29403,7 @@ fn coerceExtra( |
| 29493 | .Enum => switch (inst_ty.zigTypeTag(zcu)) { | 29403 | .Enum => switch (inst_ty.zigTypeTag(zcu)) { |
| 29494 | .EnumLiteral => { | 29404 | .EnumLiteral => { |
| 29495 | // enum literal to enum | 29405 | // enum literal to enum |
| 29496 | const val = try sema.resolveConstDefinedValue(block, .unneeded, inst, undefined); | 29406 | const val = try sema.resolveConstDefinedValue(block, LazySrcLoc.unneeded, inst, undefined); |
| 29497 | const string = zcu.intern_pool.indexToKey(val.toIntern()).enum_literal; | 29407 | const string = zcu.intern_pool.indexToKey(val.toIntern()).enum_literal; |
| 29498 | const field_index = dest_ty.enumFieldIndex(string, zcu) orelse { | 29408 | const field_index = dest_ty.enumFieldIndex(string, zcu) orelse { |
| 29499 | return sema.fail(block, inst_src, "no field named '{}' in enum '{}'", .{ | 29409 | return sema.fail(block, inst_src, "no field named '{}' in enum '{}'", .{ |
| ... | @@ -29627,54 +29537,58 @@ fn coerceExtra( | ... | @@ -29627,54 +29537,58 @@ fn coerceExtra( |
| 29627 | | 29537 | |
| 29628 | if (opts.is_ret and dest_ty.zigTypeTag(zcu) == .NoReturn) { | 29538 | if (opts.is_ret and dest_ty.zigTypeTag(zcu) == .NoReturn) { |
| 29629 | const msg = msg: { | 29539 | const msg = msg: { |
| 29630 | const msg = try sema.errMsg(block, inst_src, "function declared 'noreturn' returns", .{}); | 29540 | const msg = try sema.errMsg(inst_src, "function declared 'noreturn' returns", .{}); |
| 29631 | errdefer msg.destroy(sema.gpa); | 29541 | errdefer msg.destroy(sema.gpa); |
| 29632 | | 29542 | |
| 29633 | const ret_ty_src: LazySrcLoc = .{ .node_offset_fn_type_ret_ty = 0 }; | 29543 | const ret_ty_src: LazySrcLoc = .{ |
| 29634 | const src_decl = zcu.funcOwnerDeclPtr(sema.func_index); | 29544 | .base_node_inst = zcu.funcOwnerDeclPtr(sema.func_index).zir_decl_index.unwrap().?, |
| 29635 | try zcu.errNoteNonLazy(src_decl.toSrcLoc(ret_ty_src, zcu), msg, "'noreturn' declared here", .{}); | 29545 | .offset = .{ .node_offset_fn_type_ret_ty = 0 }, |
| | 29546 | }; |
| | 29547 | try sema.errNote(ret_ty_src, msg, "'noreturn' declared here", .{}); |
| 29636 | break :msg msg; | 29548 | break :msg msg; |
| 29637 | }; | 29549 | }; |
| 29638 | return sema.failWithOwnedErrorMsg(block, msg); | 29550 | return sema.failWithOwnedErrorMsg(block, msg); |
| 29639 | } | 29551 | } |
| 29640 | | 29552 | |
| 29641 | const msg = msg: { | 29553 | const msg = msg: { |
| 29642 | const msg = try sema.errMsg(block, inst_src, "expected type '{}', found '{}'", .{ dest_ty.fmt(zcu), inst_ty.fmt(zcu) }); | 29554 | const msg = try sema.errMsg(inst_src, "expected type '{}', found '{}'", .{ dest_ty.fmt(zcu), inst_ty.fmt(zcu) }); |
| 29643 | errdefer msg.destroy(sema.gpa); | 29555 | errdefer msg.destroy(sema.gpa); |
| 29644 | | 29556 | |
| 29645 | // E!T to T | 29557 | // E!T to T |
| 29646 | if (inst_ty.zigTypeTag(zcu) == .ErrorUnion and | 29558 | if (inst_ty.zigTypeTag(zcu) == .ErrorUnion and |
| 29647 | (try sema.coerceInMemoryAllowed(block, inst_ty.errorUnionPayload(zcu), dest_ty, false, target, dest_ty_src, inst_src)) == .ok) | 29559 | (try sema.coerceInMemoryAllowed(block, inst_ty.errorUnionPayload(zcu), dest_ty, false, target, dest_ty_src, inst_src)) == .ok) |
| 29648 | { | 29560 | { |
| 29649 | try sema.errNote(block, inst_src, msg, "cannot convert error union to payload type", .{}); | 29561 | try sema.errNote(inst_src, msg, "cannot convert error union to payload type", .{}); |
| 29650 | try sema.errNote(block, inst_src, msg, "consider using 'try', 'catch', or 'if'", .{}); | 29562 | try sema.errNote(inst_src, msg, "consider using 'try', 'catch', or 'if'", .{}); |
| 29651 | } | 29563 | } |
| 29652 | | 29564 | |
| 29653 | // ?T to T | 29565 | // ?T to T |
| 29654 | if (inst_ty.zigTypeTag(zcu) == .Optional and | 29566 | if (inst_ty.zigTypeTag(zcu) == .Optional and |
| 29655 | (try sema.coerceInMemoryAllowed(block, inst_ty.optionalChild(zcu), dest_ty, false, target, dest_ty_src, inst_src)) == .ok) | 29567 | (try sema.coerceInMemoryAllowed(block, inst_ty.optionalChild(zcu), dest_ty, false, target, dest_ty_src, inst_src)) == .ok) |
| 29656 | { | 29568 | { |
| 29657 | try sema.errNote(block, inst_src, msg, "cannot convert optional to payload type", .{}); | 29569 | try sema.errNote(inst_src, msg, "cannot convert optional to payload type", .{}); |
| 29658 | try sema.errNote(block, inst_src, msg, "consider using '.?', 'orelse', or 'if'", .{}); | 29570 | try sema.errNote(inst_src, msg, "consider using '.?', 'orelse', or 'if'", .{}); |
| 29659 | } | 29571 | } |
| 29660 | | 29572 | |
| 29661 | try in_memory_result.report(sema, block, inst_src, msg); | 29573 | try in_memory_result.report(sema, inst_src, msg); |
| 29662 | | 29574 | |
| 29663 | // Add notes about function return type | 29575 | // Add notes about function return type |
| 29664 | if (opts.is_ret and | 29576 | if (opts.is_ret and |
| 29665 | zcu.test_functions.get(zcu.funcOwnerDeclIndex(sema.func_index)) == null) | 29577 | zcu.test_functions.get(zcu.funcOwnerDeclIndex(sema.func_index)) == null) |
| 29666 | { | 29578 | { |
| 29667 | const ret_ty_src: LazySrcLoc = .{ .node_offset_fn_type_ret_ty = 0 }; | 29579 | const ret_ty_src: LazySrcLoc = .{ |
| 29668 | const src_decl = zcu.funcOwnerDeclPtr(sema.func_index); | 29580 | .base_node_inst = zcu.funcOwnerDeclPtr(sema.func_index).zir_decl_index.unwrap().?, |
| | 29581 | .offset = .{ .node_offset_fn_type_ret_ty = 0 }, |
| | 29582 | }; |
| 29669 | if (inst_ty.isError(zcu) and !dest_ty.isError(zcu)) { | 29583 | if (inst_ty.isError(zcu) and !dest_ty.isError(zcu)) { |
| 29670 | try zcu.errNoteNonLazy(src_decl.toSrcLoc(ret_ty_src, zcu), msg, "function cannot return an error", .{}); | 29584 | try sema.errNote(ret_ty_src, msg, "function cannot return an error", .{}); |
| 29671 | } else { | 29585 | } else { |
| 29672 | try zcu.errNoteNonLazy(src_decl.toSrcLoc(ret_ty_src, zcu), msg, "function return type declared here", .{}); | 29586 | try sema.errNote(ret_ty_src, msg, "function return type declared here", .{}); |
| 29673 | } | 29587 | } |
| 29674 | } | 29588 | } |
| 29675 | | 29589 | |
| 29676 | if (try opts.param_src.get(sema)) |param_src| { | 29590 | if (try opts.param_src.get(sema)) |param_src| { |
| 29677 | try zcu.errNoteNonLazy(param_src, msg, "parameter type declared here", .{}); | 29591 | try sema.errNote(param_src, msg, "parameter type declared here", .{}); |
| 29678 | } | 29592 | } |
| 29679 | | 29593 | |
| 29680 | // TODO maybe add "cannot store an error in type '{}'" note | 29594 | // TODO maybe add "cannot store an error in type '{}'" note |
| ... | @@ -29809,7 +29723,7 @@ const InMemoryCoercionResult = union(enum) { | ... | @@ -29809,7 +29723,7 @@ const InMemoryCoercionResult = union(enum) { |
| 29809 | return res; | 29723 | return res; |
| 29810 | } | 29724 | } |
| 29811 | | 29725 | |
| 29812 | fn report(res: *const InMemoryCoercionResult, sema: *Sema, block: *Block, src: LazySrcLoc, msg: *Module.ErrorMsg) !void { | 29726 | fn report(res: *const InMemoryCoercionResult, sema: *Sema, src: LazySrcLoc, msg: *Module.ErrorMsg) !void { |
| 29813 | const mod = sema.mod; | 29727 | const mod = sema.mod; |
| 29814 | var cur = res; | 29728 | var cur = res; |
| 29815 | while (true) switch (cur.*) { | 29729 | while (true) switch (cur.*) { |
| ... | @@ -29820,93 +29734,93 @@ const InMemoryCoercionResult = union(enum) { | ... | @@ -29820,93 +29734,93 @@ const InMemoryCoercionResult = union(enum) { |
| 29820 | break; | 29734 | break; |
| 29821 | }, | 29735 | }, |
| 29822 | .int_not_coercible => |int| { | 29736 | .int_not_coercible => |int| { |
| 29823 | try sema.errNote(block, src, msg, "{s} {d}-bit int cannot represent all possible {s} {d}-bit values", .{ | 29737 | try sema.errNote(src, msg, "{s} {d}-bit int cannot represent all possible {s} {d}-bit values", .{ |
| 29824 | @tagName(int.wanted_signedness), int.wanted_bits, @tagName(int.actual_signedness), int.actual_bits, | 29738 | @tagName(int.wanted_signedness), int.wanted_bits, @tagName(int.actual_signedness), int.actual_bits, |
| 29825 | }); | 29739 | }); |
| 29826 | break; | 29740 | break; |
| 29827 | }, | 29741 | }, |
| 29828 | .error_union_payload => |pair| { | 29742 | .error_union_payload => |pair| { |
| 29829 | try sema.errNote(block, src, msg, "error union payload '{}' cannot cast into error union payload '{}'", .{ | 29743 | try sema.errNote(src, msg, "error union payload '{}' cannot cast into error union payload '{}'", .{ |
| 29830 | pair.actual.fmt(mod), pair.wanted.fmt(mod), | 29744 | pair.actual.fmt(mod), pair.wanted.fmt(mod), |
| 29831 | }); | 29745 | }); |
| 29832 | cur = pair.child; | 29746 | cur = pair.child; |
| 29833 | }, | 29747 | }, |
| 29834 | .array_len => |lens| { | 29748 | .array_len => |lens| { |
| 29835 | try sema.errNote(block, src, msg, "array of length {d} cannot cast into an array of length {d}", .{ | 29749 | try sema.errNote(src, msg, "array of length {d} cannot cast into an array of length {d}", .{ |
| 29836 | lens.actual, lens.wanted, | 29750 | lens.actual, lens.wanted, |
| 29837 | }); | 29751 | }); |
| 29838 | break; | 29752 | break; |
| 29839 | }, | 29753 | }, |
| 29840 | .array_sentinel => |sentinel| { | 29754 | .array_sentinel => |sentinel| { |
| 29841 | if (sentinel.actual.toIntern() != .unreachable_value) { | 29755 | if (sentinel.actual.toIntern() != .unreachable_value) { |
| 29842 | try sema.errNote(block, src, msg, "array sentinel '{}' cannot cast into array sentinel '{}'", .{ | 29756 | try sema.errNote(src, msg, "array sentinel '{}' cannot cast into array sentinel '{}'", .{ |
| 29843 | sentinel.actual.fmtValue(mod, sema), sentinel.wanted.fmtValue(mod, sema), | 29757 | sentinel.actual.fmtValue(mod, sema), sentinel.wanted.fmtValue(mod, sema), |
| 29844 | }); | 29758 | }); |
| 29845 | } else { | 29759 | } else { |
| 29846 | try sema.errNote(block, src, msg, "destination array requires '{}' sentinel", .{ | 29760 | try sema.errNote(src, msg, "destination array requires '{}' sentinel", .{ |
| 29847 | sentinel.wanted.fmtValue(mod, sema), | 29761 | sentinel.wanted.fmtValue(mod, sema), |
| 29848 | }); | 29762 | }); |
| 29849 | } | 29763 | } |
| 29850 | break; | 29764 | break; |
| 29851 | }, | 29765 | }, |
| 29852 | .array_elem => |pair| { | 29766 | .array_elem => |pair| { |
| 29853 | try sema.errNote(block, src, msg, "array element type '{}' cannot cast into array element type '{}'", .{ | 29767 | try sema.errNote(src, msg, "array element type '{}' cannot cast into array element type '{}'", .{ |
| 29854 | pair.actual.fmt(mod), pair.wanted.fmt(mod), | 29768 | pair.actual.fmt(mod), pair.wanted.fmt(mod), |
| 29855 | }); | 29769 | }); |
| 29856 | cur = pair.child; | 29770 | cur = pair.child; |
| 29857 | }, | 29771 | }, |
| 29858 | .vector_len => |lens| { | 29772 | .vector_len => |lens| { |
| 29859 | try sema.errNote(block, src, msg, "vector of length {d} cannot cast into a vector of length {d}", .{ | 29773 | try sema.errNote(src, msg, "vector of length {d} cannot cast into a vector of length {d}", .{ |
| 29860 | lens.actual, lens.wanted, | 29774 | lens.actual, lens.wanted, |
| 29861 | }); | 29775 | }); |
| 29862 | break; | 29776 | break; |
| 29863 | }, | 29777 | }, |
| 29864 | .vector_elem => |pair| { | 29778 | .vector_elem => |pair| { |
| 29865 | try sema.errNote(block, src, msg, "vector element type '{}' cannot cast into vector element type '{}'", .{ | 29779 | try sema.errNote(src, msg, "vector element type '{}' cannot cast into vector element type '{}'", .{ |
| 29866 | pair.actual.fmt(mod), pair.wanted.fmt(mod), | 29780 | pair.actual.fmt(mod), pair.wanted.fmt(mod), |
| 29867 | }); | 29781 | }); |
| 29868 | cur = pair.child; | 29782 | cur = pair.child; |
| 29869 | }, | 29783 | }, |
| 29870 | .optional_shape => |pair| { | 29784 | .optional_shape => |pair| { |
| 29871 | try sema.errNote(block, src, msg, "optional type child '{}' cannot cast into optional type child '{}'", .{ | 29785 | try sema.errNote(src, msg, "optional type child '{}' cannot cast into optional type child '{}'", .{ |
| 29872 | pair.actual.optionalChild(mod).fmt(mod), pair.wanted.optionalChild(mod).fmt(mod), | 29786 | pair.actual.optionalChild(mod).fmt(mod), pair.wanted.optionalChild(mod).fmt(mod), |
| 29873 | }); | 29787 | }); |
| 29874 | break; | 29788 | break; |
| 29875 | }, | 29789 | }, |
| 29876 | .optional_child => |pair| { | 29790 | .optional_child => |pair| { |
| 29877 | try sema.errNote(block, src, msg, "optional type child '{}' cannot cast into optional type child '{}'", .{ | 29791 | try sema.errNote(src, msg, "optional type child '{}' cannot cast into optional type child '{}'", .{ |
| 29878 | pair.actual.fmt(mod), pair.wanted.fmt(mod), | 29792 | pair.actual.fmt(mod), pair.wanted.fmt(mod), |
| 29879 | }); | 29793 | }); |
| 29880 | cur = pair.child; | 29794 | cur = pair.child; |
| 29881 | }, | 29795 | }, |
| 29882 | .from_anyerror => { | 29796 | .from_anyerror => { |
| 29883 | try sema.errNote(block, src, msg, "global error set cannot cast into a smaller set", .{}); | 29797 | try sema.errNote(src, msg, "global error set cannot cast into a smaller set", .{}); |
| 29884 | break; | 29798 | break; |
| 29885 | }, | 29799 | }, |
| 29886 | .missing_error => |missing_errors| { | 29800 | .missing_error => |missing_errors| { |
| 29887 | for (missing_errors) |err| { | 29801 | for (missing_errors) |err| { |
| 29888 | try sema.errNote(block, src, msg, "'error.{}' not a member of destination error set", .{err.fmt(&mod.intern_pool)}); | 29802 | try sema.errNote(src, msg, "'error.{}' not a member of destination error set", .{err.fmt(&mod.intern_pool)}); |
| 29889 | } | 29803 | } |
| 29890 | break; | 29804 | break; |
| 29891 | }, | 29805 | }, |
| 29892 | .fn_var_args => |wanted_var_args| { | 29806 | .fn_var_args => |wanted_var_args| { |
| 29893 | if (wanted_var_args) { | 29807 | if (wanted_var_args) { |
| 29894 | try sema.errNote(block, src, msg, "non-variadic function cannot cast into a variadic function", .{}); | 29808 | try sema.errNote(src, msg, "non-variadic function cannot cast into a variadic function", .{}); |
| 29895 | } else { | 29809 | } else { |
| 29896 | try sema.errNote(block, src, msg, "variadic function cannot cast into a non-variadic function", .{}); | 29810 | try sema.errNote(src, msg, "variadic function cannot cast into a non-variadic function", .{}); |
| 29897 | } | 29811 | } |
| 29898 | break; | 29812 | break; |
| 29899 | }, | 29813 | }, |
| 29900 | .fn_generic => |wanted_generic| { | 29814 | .fn_generic => |wanted_generic| { |
| 29901 | if (wanted_generic) { | 29815 | if (wanted_generic) { |
| 29902 | try sema.errNote(block, src, msg, "non-generic function cannot cast into a generic function", .{}); | 29816 | try sema.errNote(src, msg, "non-generic function cannot cast into a generic function", .{}); |
| 29903 | } else { | 29817 | } else { |
| 29904 | try sema.errNote(block, src, msg, "generic function cannot cast into a non-generic function", .{}); | 29818 | try sema.errNote(src, msg, "generic function cannot cast into a non-generic function", .{}); |
| 29905 | } | 29819 | } |
| 29906 | break; | 29820 | break; |
| 29907 | }, | 29821 | }, |
| 29908 | .fn_param_count => |lens| { | 29822 | .fn_param_count => |lens| { |
| 29909 | try sema.errNote(block, src, msg, "function with {d} parameters cannot cast into a function with {d} parameters", .{ | 29823 | try sema.errNote(src, msg, "function with {d} parameters cannot cast into a function with {d} parameters", .{ |
| 29910 | lens.actual, lens.wanted, | 29824 | lens.actual, lens.wanted, |
| 29911 | }); | 29825 | }); |
| 29912 | break; | 29826 | break; |
| ... | @@ -29923,69 +29837,69 @@ const InMemoryCoercionResult = union(enum) { | ... | @@ -29923,69 +29837,69 @@ const InMemoryCoercionResult = union(enum) { |
| 29923 | } | 29837 | } |
| 29924 | } | 29838 | } |
| 29925 | if (!actual_noalias) { | 29839 | if (!actual_noalias) { |
| 29926 | try sema.errNote(block, src, msg, "regular parameter {d} cannot cast into a noalias parameter", .{index}); | 29840 | try sema.errNote(src, msg, "regular parameter {d} cannot cast into a noalias parameter", .{index}); |
| 29927 | } else { | 29841 | } else { |
| 29928 | try sema.errNote(block, src, msg, "noalias parameter {d} cannot cast into a regular parameter", .{index}); | 29842 | try sema.errNote(src, msg, "noalias parameter {d} cannot cast into a regular parameter", .{index}); |
| 29929 | } | 29843 | } |
| 29930 | break; | 29844 | break; |
| 29931 | }, | 29845 | }, |
| 29932 | .fn_param_comptime => |param| { | 29846 | .fn_param_comptime => |param| { |
| 29933 | if (param.wanted) { | 29847 | if (param.wanted) { |
| 29934 | try sema.errNote(block, src, msg, "non-comptime parameter {d} cannot cast into a comptime parameter", .{param.index}); | 29848 | try sema.errNote(src, msg, "non-comptime parameter {d} cannot cast into a comptime parameter", .{param.index}); |
| 29935 | } else { | 29849 | } else { |
| 29936 | try sema.errNote(block, src, msg, "comptime parameter {d} cannot cast into a non-comptime parameter", .{param.index}); | 29850 | try sema.errNote(src, msg, "comptime parameter {d} cannot cast into a non-comptime parameter", .{param.index}); |
| 29937 | } | 29851 | } |
| 29938 | break; | 29852 | break; |
| 29939 | }, | 29853 | }, |
| 29940 | .fn_param => |param| { | 29854 | .fn_param => |param| { |
| 29941 | try sema.errNote(block, src, msg, "parameter {d} '{}' cannot cast into '{}'", .{ | 29855 | try sema.errNote(src, msg, "parameter {d} '{}' cannot cast into '{}'", .{ |
| 29942 | param.index, param.actual.fmt(mod), param.wanted.fmt(mod), | 29856 | param.index, param.actual.fmt(mod), param.wanted.fmt(mod), |
| 29943 | }); | 29857 | }); |
| 29944 | cur = param.child; | 29858 | cur = param.child; |
| 29945 | }, | 29859 | }, |
| 29946 | .fn_cc => |cc| { | 29860 | .fn_cc => |cc| { |
| 29947 | try sema.errNote(block, src, msg, "calling convention '{s}' cannot cast into calling convention '{s}'", .{ @tagName(cc.actual), @tagName(cc.wanted) }); | 29861 | try sema.errNote(src, msg, "calling convention '{s}' cannot cast into calling convention '{s}'", .{ @tagName(cc.actual), @tagName(cc.wanted) }); |
| 29948 | break; | 29862 | break; |
| 29949 | }, | 29863 | }, |
| 29950 | .fn_return_type => |pair| { | 29864 | .fn_return_type => |pair| { |
| 29951 | try sema.errNote(block, src, msg, "return type '{}' cannot cast into return type '{}'", .{ | 29865 | try sema.errNote(src, msg, "return type '{}' cannot cast into return type '{}'", .{ |
| 29952 | pair.actual.fmt(mod), pair.wanted.fmt(mod), | 29866 | pair.actual.fmt(mod), pair.wanted.fmt(mod), |
| 29953 | }); | 29867 | }); |
| 29954 | cur = pair.child; | 29868 | cur = pair.child; |
| 29955 | }, | 29869 | }, |
| 29956 | .ptr_child => |pair| { | 29870 | .ptr_child => |pair| { |
| 29957 | try sema.errNote(block, src, msg, "pointer type child '{}' cannot cast into pointer type child '{}'", .{ | 29871 | try sema.errNote(src, msg, "pointer type child '{}' cannot cast into pointer type child '{}'", .{ |
| 29958 | pair.actual.fmt(mod), pair.wanted.fmt(mod), | 29872 | pair.actual.fmt(mod), pair.wanted.fmt(mod), |
| 29959 | }); | 29873 | }); |
| 29960 | cur = pair.child; | 29874 | cur = pair.child; |
| 29961 | }, | 29875 | }, |
| 29962 | .ptr_addrspace => |@"addrspace"| { | 29876 | .ptr_addrspace => |@"addrspace"| { |
| 29963 | try sema.errNote(block, src, msg, "address space '{s}' cannot cast into address space '{s}'", .{ @tagName(@"addrspace".actual), @tagName(@"addrspace".wanted) }); | 29877 | try sema.errNote(src, msg, "address space '{s}' cannot cast into address space '{s}'", .{ @tagName(@"addrspace".actual), @tagName(@"addrspace".wanted) }); |
| 29964 | break; | 29878 | break; |
| 29965 | }, | 29879 | }, |
| 29966 | .ptr_sentinel => |sentinel| { | 29880 | .ptr_sentinel => |sentinel| { |
| 29967 | if (sentinel.actual.toIntern() != .unreachable_value) { | 29881 | if (sentinel.actual.toIntern() != .unreachable_value) { |
| 29968 | try sema.errNote(block, src, msg, "pointer sentinel '{}' cannot cast into pointer sentinel '{}'", .{ | 29882 | try sema.errNote(src, msg, "pointer sentinel '{}' cannot cast into pointer sentinel '{}'", .{ |
| 29969 | sentinel.actual.fmtValue(mod, sema), sentinel.wanted.fmtValue(mod, sema), | 29883 | sentinel.actual.fmtValue(mod, sema), sentinel.wanted.fmtValue(mod, sema), |
| 29970 | }); | 29884 | }); |
| 29971 | } else { | 29885 | } else { |
| 29972 | try sema.errNote(block, src, msg, "destination pointer requires '{}' sentinel", .{ | 29886 | try sema.errNote(src, msg, "destination pointer requires '{}' sentinel", .{ |
| 29973 | sentinel.wanted.fmtValue(mod, sema), | 29887 | sentinel.wanted.fmtValue(mod, sema), |
| 29974 | }); | 29888 | }); |
| 29975 | } | 29889 | } |
| 29976 | break; | 29890 | break; |
| 29977 | }, | 29891 | }, |
| 29978 | .ptr_size => |size| { | 29892 | .ptr_size => |size| { |
| 29979 | try sema.errNote(block, src, msg, "a {s} pointer cannot cast into a {s} pointer", .{ pointerSizeString(size.actual), pointerSizeString(size.wanted) }); | 29893 | try sema.errNote(src, msg, "a {s} pointer cannot cast into a {s} pointer", .{ pointerSizeString(size.actual), pointerSizeString(size.wanted) }); |
| 29980 | break; | 29894 | break; |
| 29981 | }, | 29895 | }, |
| 29982 | .ptr_qualifiers => |qualifiers| { | 29896 | .ptr_qualifiers => |qualifiers| { |
| 29983 | const ok_const = !qualifiers.actual_const or qualifiers.wanted_const; | 29897 | const ok_const = !qualifiers.actual_const or qualifiers.wanted_const; |
| 29984 | const ok_volatile = !qualifiers.actual_volatile or qualifiers.wanted_volatile; | 29898 | const ok_volatile = !qualifiers.actual_volatile or qualifiers.wanted_volatile; |
| 29985 | if (!ok_const) { | 29899 | if (!ok_const) { |
| 29986 | try sema.errNote(block, src, msg, "cast discards const qualifier", .{}); | 29900 | try sema.errNote(src, msg, "cast discards const qualifier", .{}); |
| 29987 | } else if (!ok_volatile) { | 29901 | } else if (!ok_volatile) { |
| 29988 | try sema.errNote(block, src, msg, "cast discards volatile qualifier", .{}); | 29902 | try sema.errNote(src, msg, "cast discards volatile qualifier", .{}); |
| 29989 | } | 29903 | } |
| 29990 | break; | 29904 | break; |
| 29991 | }, | 29905 | }, |
| ... | @@ -29993,11 +29907,11 @@ const InMemoryCoercionResult = union(enum) { | ... | @@ -29993,11 +29907,11 @@ const InMemoryCoercionResult = union(enum) { |
| 29993 | const wanted_allow_zero = pair.wanted.ptrAllowsZero(mod); | 29907 | const wanted_allow_zero = pair.wanted.ptrAllowsZero(mod); |
| 29994 | const actual_allow_zero = pair.actual.ptrAllowsZero(mod); | 29908 | const actual_allow_zero = pair.actual.ptrAllowsZero(mod); |
| 29995 | if (actual_allow_zero and !wanted_allow_zero) { | 29909 | if (actual_allow_zero and !wanted_allow_zero) { |
| 29996 | try sema.errNote(block, src, msg, "'{}' could have null values which are illegal in type '{}'", .{ | 29910 | try sema.errNote(src, msg, "'{}' could have null values which are illegal in type '{}'", .{ |
| 29997 | pair.actual.fmt(mod), pair.wanted.fmt(mod), | 29911 | pair.actual.fmt(mod), pair.wanted.fmt(mod), |
| 29998 | }); | 29912 | }); |
| 29999 | } else { | 29913 | } else { |
| 30000 | try sema.errNote(block, src, msg, "mutable '{}' allows illegal null values stored to type '{}'", .{ | 29914 | try sema.errNote(src, msg, "mutable '{}' allows illegal null values stored to type '{}'", .{ |
| 30001 | pair.actual.fmt(mod), pair.wanted.fmt(mod), | 29915 | pair.actual.fmt(mod), pair.wanted.fmt(mod), |
| 30002 | }); | 29916 | }); |
| 30003 | } | 29917 | } |
| ... | @@ -30005,34 +29919,34 @@ const InMemoryCoercionResult = union(enum) { | ... | @@ -30005,34 +29919,34 @@ const InMemoryCoercionResult = union(enum) { |
| 30005 | }, | 29919 | }, |
| 30006 | .ptr_bit_range => |bit_range| { | 29920 | .ptr_bit_range => |bit_range| { |
| 30007 | if (bit_range.actual_host != bit_range.wanted_host) { | 29921 | if (bit_range.actual_host != bit_range.wanted_host) { |
| 30008 | try sema.errNote(block, src, msg, "pointer host size '{}' cannot cast into pointer host size '{}'", .{ | 29922 | try sema.errNote(src, msg, "pointer host size '{}' cannot cast into pointer host size '{}'", .{ |
| 30009 | bit_range.actual_host, bit_range.wanted_host, | 29923 | bit_range.actual_host, bit_range.wanted_host, |
| 30010 | }); | 29924 | }); |
| 30011 | } | 29925 | } |
| 30012 | if (bit_range.actual_offset != bit_range.wanted_offset) { | 29926 | if (bit_range.actual_offset != bit_range.wanted_offset) { |
| 30013 | try sema.errNote(block, src, msg, "pointer bit offset '{}' cannot cast into pointer bit offset '{}'", .{ | 29927 | try sema.errNote(src, msg, "pointer bit offset '{}' cannot cast into pointer bit offset '{}'", .{ |
| 30014 | bit_range.actual_offset, bit_range.wanted_offset, | 29928 | bit_range.actual_offset, bit_range.wanted_offset, |
| 30015 | }); | 29929 | }); |
| 30016 | } | 29930 | } |
| 30017 | break; | 29931 | break; |
| 30018 | }, | 29932 | }, |
| 30019 | .ptr_alignment => |pair| { | 29933 | .ptr_alignment => |pair| { |
| 30020 | try sema.errNote(block, src, msg, "pointer alignment '{d}' cannot cast into pointer alignment '{d}'", .{ | 29934 | try sema.errNote(src, msg, "pointer alignment '{d}' cannot cast into pointer alignment '{d}'", .{ |
| 30021 | pair.actual.toByteUnits() orelse 0, pair.wanted.toByteUnits() orelse 0, | 29935 | pair.actual.toByteUnits() orelse 0, pair.wanted.toByteUnits() orelse 0, |
| 30022 | }); | 29936 | }); |
| 30023 | break; | 29937 | break; |
| 30024 | }, | 29938 | }, |
| 30025 | .double_ptr_to_anyopaque => |pair| { | 29939 | .double_ptr_to_anyopaque => |pair| { |
| 30026 | try sema.errNote(block, src, msg, "cannot implicitly cast double pointer '{}' to anyopaque pointer '{}'", .{ | 29940 | try sema.errNote(src, msg, "cannot implicitly cast double pointer '{}' to anyopaque pointer '{}'", .{ |
| 30027 | pair.actual.fmt(mod), pair.wanted.fmt(mod), | 29941 | pair.actual.fmt(mod), pair.wanted.fmt(mod), |
| 30028 | }); | 29942 | }); |
| 30029 | break; | 29943 | break; |
| 30030 | }, | 29944 | }, |
| 30031 | .slice_to_anyopaque => |pair| { | 29945 | .slice_to_anyopaque => |pair| { |
| 30032 | try sema.errNote(block, src, msg, "cannot implicitly cast slice '{}' to anyopaque pointer '{}'", .{ | 29946 | try sema.errNote(src, msg, "cannot implicitly cast slice '{}' to anyopaque pointer '{}'", .{ |
| 30033 | pair.actual.fmt(mod), pair.wanted.fmt(mod), | 29947 | pair.actual.fmt(mod), pair.wanted.fmt(mod), |
| 30034 | }); | 29948 | }); |
| 30035 | try sema.errNote(block, src, msg, "consider using '.ptr'", .{}); | 29949 | try sema.errNote(src, msg, "consider using '.ptr'", .{}); |
| 30036 | break; | 29950 | break; |
| 30037 | }, | 29951 | }, |
| 30038 | }; | 29952 | }; |
| ... | @@ -30646,7 +30560,7 @@ fn coerceVarArgParam( | ... | @@ -30646,7 +30560,7 @@ fn coerceVarArgParam( |
| 30646 | .{}, | 30560 | .{}, |
| 30647 | ), | 30561 | ), |
| 30648 | .Fn => fn_ptr: { | 30562 | .Fn => fn_ptr: { |
| 30649 | const fn_val = try sema.resolveConstDefinedValue(block, .unneeded, inst, undefined); | 30563 | const fn_val = try sema.resolveConstDefinedValue(block, LazySrcLoc.unneeded, inst, undefined); |
| 30650 | const fn_decl = fn_val.pointerDecl(mod).?; | 30564 | const fn_decl = fn_val.pointerDecl(mod).?; |
| 30651 | break :fn_ptr try sema.analyzeDeclRef(fn_decl); | 30565 | break :fn_ptr try sema.analyzeDeclRef(fn_decl); |
| 30652 | }, | 30566 | }, |
| ... | @@ -30694,11 +30608,10 @@ fn coerceVarArgParam( | ... | @@ -30694,11 +30608,10 @@ fn coerceVarArgParam( |
| 30694 | const coerced_ty = sema.typeOf(coerced); | 30608 | const coerced_ty = sema.typeOf(coerced); |
| 30695 | if (!try sema.validateExternType(coerced_ty, .param_ty)) { | 30609 | if (!try sema.validateExternType(coerced_ty, .param_ty)) { |
| 30696 | const msg = msg: { | 30610 | const msg = msg: { |
| 30697 | const msg = try sema.errMsg(block, inst_src, "cannot pass '{}' to variadic function", .{coerced_ty.fmt(sema.mod)}); | 30611 | const msg = try sema.errMsg(inst_src, "cannot pass '{}' to variadic function", .{coerced_ty.fmt(sema.mod)}); |
| 30698 | errdefer msg.destroy(sema.gpa); | 30612 | errdefer msg.destroy(sema.gpa); |
| 30699 | | 30613 | |
| 30700 | const src_decl = sema.mod.declPtr(block.src_decl); | 30614 | try sema.explainWhyTypeIsNotExtern(msg, inst_src, coerced_ty, .param_ty); |
| 30701 | try sema.explainWhyTypeIsNotExtern(msg, src_decl.toSrcLoc(inst_src, mod), coerced_ty, .param_ty); | | |
| 30702 | | 30615 | |
| 30703 | try sema.addDeclaredHereNote(msg, coerced_ty); | 30616 | try sema.addDeclaredHereNote(msg, coerced_ty); |
| 30704 | break :msg msg; | 30617 | break :msg msg; |
| ... | @@ -30858,7 +30771,6 @@ fn checkComptimeKnownStore(sema: *Sema, block: *Block, store_inst_ref: Air.Inst. | ... | @@ -30858,7 +30771,6 @@ fn checkComptimeKnownStore(sema: *Sema, block: *Block, store_inst_ref: Air.Inst. |
| 30858 | { | 30771 | { |
| 30859 | try maybe_comptime_alloc.stores.append(sema.arena, .{ | 30772 | try maybe_comptime_alloc.stores.append(sema.arena, .{ |
| 30860 | .inst = store_inst, | 30773 | .inst = store_inst, |
| 30861 | .src_decl = block.src_decl, | | |
| 30862 | .src = store_src, | 30774 | .src = store_src, |
| 30863 | }); | 30775 | }); |
| 30864 | return; | 30776 | return; |
| ... | @@ -30892,8 +30804,7 @@ fn checkKnownAllocPtr(sema: *Sema, block: *Block, base_ptr: Air.Inst.Ref, new_pt | ... | @@ -30892,8 +30804,7 @@ fn checkKnownAllocPtr(sema: *Sema, block: *Block, base_ptr: Air.Inst.Ref, new_pt |
| 30892 | | 30804 | |
| 30893 | try maybe_comptime_alloc.stores.append(sema.arena, .{ | 30805 | try maybe_comptime_alloc.stores.append(sema.arena, .{ |
| 30894 | .inst = new_ptr_inst, | 30806 | .inst = new_ptr_inst, |
| 30895 | .src_decl = block.src_decl, | 30807 | .src = LazySrcLoc.unneeded, |
| 30896 | .src = .unneeded, | | |
| 30897 | }); | 30808 | }); |
| 30898 | }, | 30809 | }, |
| 30899 | .ptr_elem_ptr => { | 30810 | .ptr_elem_ptr => { |
| ... | @@ -30916,10 +30827,9 @@ fn markMaybeComptimeAllocRuntime(sema: *Sema, block: *Block, alloc_inst: Air.Ins | ... | @@ -30916,10 +30827,9 @@ fn markMaybeComptimeAllocRuntime(sema: *Sema, block: *Block, alloc_inst: Air.Ins |
| 30916 | const maybe_comptime_alloc = (sema.maybe_comptime_allocs.fetchRemove(alloc_inst) orelse return).value; | 30827 | const maybe_comptime_alloc = (sema.maybe_comptime_allocs.fetchRemove(alloc_inst) orelse return).value; |
| 30917 | // Since the alloc has been determined to be runtime, we must check that | 30828 | // Since the alloc has been determined to be runtime, we must check that |
| 30918 | // all other stores to it are permitted to be runtime values. | 30829 | // all other stores to it are permitted to be runtime values. |
| 30919 | const mod = sema.mod; | | |
| 30920 | const slice = maybe_comptime_alloc.stores.slice(); | 30830 | const slice = maybe_comptime_alloc.stores.slice(); |
| 30921 | for (slice.items(.inst), slice.items(.src_decl), slice.items(.src)) |other_inst, other_src_decl, other_src| { | 30831 | for (slice.items(.inst), slice.items(.src)) |other_inst, other_src| { |
| 30922 | if (other_src == .unneeded) { | 30832 | if (other_src.offset == .unneeded) { |
| 30923 | switch (sema.air_instructions.items(.tag)[@intFromEnum(other_inst)]) { | 30833 | switch (sema.air_instructions.items(.tag)[@intFromEnum(other_inst)]) { |
| 30924 | .set_union_tag, .optional_payload_ptr_set, .errunion_payload_ptr_set => continue, | 30834 | .set_union_tag, .optional_payload_ptr_set, .errunion_payload_ptr_set => continue, |
| 30925 | else => unreachable, // assertion failure | 30835 | else => unreachable, // assertion failure |
| ... | @@ -30929,10 +30839,9 @@ fn markMaybeComptimeAllocRuntime(sema: *Sema, block: *Block, alloc_inst: Air.Ins | ... | @@ -30929,10 +30839,9 @@ fn markMaybeComptimeAllocRuntime(sema: *Sema, block: *Block, alloc_inst: Air.Ins |
| 30929 | const other_operand = other_data.rhs; | 30839 | const other_operand = other_data.rhs; |
| 30930 | if (!sema.checkRuntimeValue(other_operand)) { | 30840 | if (!sema.checkRuntimeValue(other_operand)) { |
| 30931 | return sema.failWithOwnedErrorMsg(block, msg: { | 30841 | return sema.failWithOwnedErrorMsg(block, msg: { |
| 30932 | const other_src_resolved = mod.declPtr(other_src_decl).toSrcLoc(other_src, mod); | 30842 | const msg = try sema.errMsg(other_src, "runtime value contains reference to comptime var", .{}); |
| 30933 | const msg = try Module.ErrorMsg.create(sema.gpa, other_src_resolved, "runtime value contains reference to comptime var", .{}); | | |
| 30934 | errdefer msg.destroy(sema.gpa); | 30843 | errdefer msg.destroy(sema.gpa); |
| 30935 | try mod.errNoteNonLazy(other_src_resolved, msg, "comptime var pointers are not available at runtime", .{}); | 30844 | try sema.errNote(other_src, msg, "comptime var pointers are not available at runtime", .{}); |
| 30936 | break :msg msg; | 30845 | break :msg msg; |
| 30937 | }); | 30846 | }); |
| 30938 | } | 30847 | } |
| ... | @@ -31194,11 +31103,11 @@ fn coerceEnumToUnion( | ... | @@ -31194,11 +31103,11 @@ fn coerceEnumToUnion( |
| 31194 | | 31103 | |
| 31195 | const tag_ty = union_ty.unionTagType(mod) orelse { | 31104 | const tag_ty = union_ty.unionTagType(mod) orelse { |
| 31196 | const msg = msg: { | 31105 | const msg = msg: { |
| 31197 | const msg = try sema.errMsg(block, inst_src, "expected type '{}', found '{}'", .{ | 31106 | const msg = try sema.errMsg(inst_src, "expected type '{}', found '{}'", .{ |
| 31198 | union_ty.fmt(sema.mod), inst_ty.fmt(sema.mod), | 31107 | union_ty.fmt(sema.mod), inst_ty.fmt(sema.mod), |
| 31199 | }); | 31108 | }); |
| 31200 | errdefer msg.destroy(sema.gpa); | 31109 | errdefer msg.destroy(sema.gpa); |
| 31201 | try sema.errNote(block, union_ty_src, msg, "cannot coerce enum to untagged union", .{}); | 31110 | try sema.errNote(union_ty_src, msg, "cannot coerce enum to untagged union", .{}); |
| 31202 | try sema.addDeclaredHereNote(msg, union_ty); | 31111 | try sema.addDeclaredHereNote(msg, union_ty); |
| 31203 | break :msg msg; | 31112 | break :msg msg; |
| 31204 | }; | 31113 | }; |
| ... | @@ -31218,7 +31127,7 @@ fn coerceEnumToUnion( | ... | @@ -31218,7 +31127,7 @@ fn coerceEnumToUnion( |
| 31218 | try sema.resolveTypeFields(field_ty); | 31127 | try sema.resolveTypeFields(field_ty); |
| 31219 | if (field_ty.zigTypeTag(mod) == .NoReturn) { | 31128 | if (field_ty.zigTypeTag(mod) == .NoReturn) { |
| 31220 | const msg = msg: { | 31129 | const msg = msg: { |
| 31221 | const msg = try sema.errMsg(block, inst_src, "cannot initialize 'noreturn' field of union", .{}); | 31130 | const msg = try sema.errMsg(inst_src, "cannot initialize 'noreturn' field of union", .{}); |
| 31222 | errdefer msg.destroy(sema.gpa); | 31131 | errdefer msg.destroy(sema.gpa); |
| 31223 | | 31132 | |
| 31224 | const field_name = union_obj.loadTagType(ip).names.get(ip)[field_index]; | 31133 | const field_name = union_obj.loadTagType(ip).names.get(ip)[field_index]; |
| ... | @@ -31233,7 +31142,7 @@ fn coerceEnumToUnion( | ... | @@ -31233,7 +31142,7 @@ fn coerceEnumToUnion( |
| 31233 | const opv = (try sema.typeHasOnePossibleValue(field_ty)) orelse { | 31142 | const opv = (try sema.typeHasOnePossibleValue(field_ty)) orelse { |
| 31234 | const msg = msg: { | 31143 | const msg = msg: { |
| 31235 | const field_name = union_obj.loadTagType(ip).names.get(ip)[field_index]; | 31144 | const field_name = union_obj.loadTagType(ip).names.get(ip)[field_index]; |
| 31236 | const msg = try sema.errMsg(block, inst_src, "coercion from enum '{}' to union '{}' must initialize '{}' field '{}'", .{ | 31145 | const msg = try sema.errMsg(inst_src, "coercion from enum '{}' to union '{}' must initialize '{}' field '{}'", .{ |
| 31237 | inst_ty.fmt(sema.mod), union_ty.fmt(sema.mod), | 31146 | inst_ty.fmt(sema.mod), union_ty.fmt(sema.mod), |
| 31238 | field_ty.fmt(sema.mod), field_name.fmt(ip), | 31147 | field_ty.fmt(sema.mod), field_name.fmt(ip), |
| 31239 | }); | 31148 | }); |
| ... | @@ -31255,7 +31164,7 @@ fn coerceEnumToUnion( | ... | @@ -31255,7 +31164,7 @@ fn coerceEnumToUnion( |
| 31255 | | 31164 | |
| 31256 | if (tag_ty.isNonexhaustiveEnum(mod)) { | 31165 | if (tag_ty.isNonexhaustiveEnum(mod)) { |
| 31257 | const msg = msg: { | 31166 | const msg = msg: { |
| 31258 | const msg = try sema.errMsg(block, inst_src, "runtime coercion to union '{}' from non-exhaustive enum", .{ | 31167 | const msg = try sema.errMsg(inst_src, "runtime coercion to union '{}' from non-exhaustive enum", .{ |
| 31259 | union_ty.fmt(sema.mod), | 31168 | union_ty.fmt(sema.mod), |
| 31260 | }); | 31169 | }); |
| 31261 | errdefer msg.destroy(sema.gpa); | 31170 | errdefer msg.destroy(sema.gpa); |
| ... | @@ -31273,7 +31182,6 @@ fn coerceEnumToUnion( | ... | @@ -31273,7 +31182,6 @@ fn coerceEnumToUnion( |
| 31273 | for (union_obj.field_types.get(ip), 0..) |field_ty, field_index| { | 31182 | for (union_obj.field_types.get(ip), 0..) |field_ty, field_index| { |
| 31274 | if (Type.fromInterned(field_ty).zigTypeTag(mod) == .NoReturn) { | 31183 | if (Type.fromInterned(field_ty).zigTypeTag(mod) == .NoReturn) { |
| 31275 | const err_msg = msg orelse try sema.errMsg( | 31184 | const err_msg = msg orelse try sema.errMsg( |
| 31276 | block, | | |
| 31277 | inst_src, | 31185 | inst_src, |
| 31278 | "runtime coercion from enum '{}' to union '{}' which has a 'noreturn' field", | 31186 | "runtime coercion from enum '{}' to union '{}' which has a 'noreturn' field", |
| 31279 | .{ tag_ty.fmt(sema.mod), union_ty.fmt(sema.mod) }, | 31187 | .{ tag_ty.fmt(sema.mod), union_ty.fmt(sema.mod) }, |
| ... | @@ -31297,7 +31205,6 @@ fn coerceEnumToUnion( | ... | @@ -31297,7 +31205,6 @@ fn coerceEnumToUnion( |
| 31297 | | 31205 | |
| 31298 | const msg = msg: { | 31206 | const msg = msg: { |
| 31299 | const msg = try sema.errMsg( | 31207 | const msg = try sema.errMsg( |
| 31300 | block, | | |
| 31301 | inst_src, | 31208 | inst_src, |
| 31302 | "runtime coercion from enum '{}' to union '{}' which has non-void fields", | 31209 | "runtime coercion from enum '{}' to union '{}' which has non-void fields", |
| 31303 | .{ tag_ty.fmt(sema.mod), union_ty.fmt(sema.mod) }, | 31210 | .{ tag_ty.fmt(sema.mod), union_ty.fmt(sema.mod) }, |
| ... | @@ -31356,12 +31263,10 @@ fn coerceAnonStructToUnion( | ... | @@ -31356,12 +31263,10 @@ fn coerceAnonStructToUnion( |
| 31356 | assert(field_count != 1); | 31263 | assert(field_count != 1); |
| 31357 | const msg = msg: { | 31264 | const msg = msg: { |
| 31358 | const msg = if (field_count > 1) try sema.errMsg( | 31265 | const msg = if (field_count > 1) try sema.errMsg( |
| 31359 | block, | | |
| 31360 | inst_src, | 31266 | inst_src, |
| 31361 | "cannot initialize multiple union fields at once; unions can only have one active field", | 31267 | "cannot initialize multiple union fields at once; unions can only have one active field", |
| 31362 | .{}, | 31268 | .{}, |
| 31363 | ) else try sema.errMsg( | 31269 | ) else try sema.errMsg( |
| 31364 | block, | | |
| 31365 | inst_src, | 31270 | inst_src, |
| 31366 | "union initializer must initialize one field", | 31271 | "union initializer must initialize one field", |
| 31367 | .{}, | 31272 | .{}, |
| ... | @@ -31438,12 +31343,12 @@ fn coerceArrayLike( | ... | @@ -31438,12 +31343,12 @@ fn coerceArrayLike( |
| 31438 | const dest_len = try sema.usizeCast(block, dest_ty_src, dest_ty.arrayLen(mod)); | 31343 | const dest_len = try sema.usizeCast(block, dest_ty_src, dest_ty.arrayLen(mod)); |
| 31439 | if (dest_len != inst_len) { | 31344 | if (dest_len != inst_len) { |
| 31440 | const msg = msg: { | 31345 | const msg = msg: { |
| 31441 | const msg = try sema.errMsg(block, inst_src, "expected type '{}', found '{}'", .{ | 31346 | const msg = try sema.errMsg(inst_src, "expected type '{}', found '{}'", .{ |
| 31442 | dest_ty.fmt(mod), inst_ty.fmt(mod), | 31347 | dest_ty.fmt(mod), inst_ty.fmt(mod), |
| 31443 | }); | 31348 | }); |
| 31444 | errdefer msg.destroy(sema.gpa); | 31349 | errdefer msg.destroy(sema.gpa); |
| 31445 | try sema.errNote(block, dest_ty_src, msg, "destination has length {d}", .{dest_len}); | 31350 | try sema.errNote(dest_ty_src, msg, "destination has length {d}", .{dest_len}); |
| 31446 | try sema.errNote(block, inst_src, msg, "source has length {d}", .{inst_len}); | 31351 | try sema.errNote(inst_src, msg, "source has length {d}", .{inst_len}); |
| 31447 | break :msg msg; | 31352 | break :msg msg; |
| 31448 | }; | 31353 | }; |
| 31449 | return sema.failWithOwnedErrorMsg(block, msg); | 31354 | return sema.failWithOwnedErrorMsg(block, msg); |
| ... | @@ -31525,12 +31430,12 @@ fn coerceTupleToArray( | ... | @@ -31525,12 +31430,12 @@ fn coerceTupleToArray( |
| 31525 | | 31430 | |
| 31526 | if (dest_len != inst_len) { | 31431 | if (dest_len != inst_len) { |
| 31527 | const msg = msg: { | 31432 | const msg = msg: { |
| 31528 | const msg = try sema.errMsg(block, inst_src, "expected type '{}', found '{}'", .{ | 31433 | const msg = try sema.errMsg(inst_src, "expected type '{}', found '{}'", .{ |
| 31529 | dest_ty.fmt(sema.mod), inst_ty.fmt(sema.mod), | 31434 | dest_ty.fmt(sema.mod), inst_ty.fmt(sema.mod), |
| 31530 | }); | 31435 | }); |
| 31531 | errdefer msg.destroy(sema.gpa); | 31436 | errdefer msg.destroy(sema.gpa); |
| 31532 | try sema.errNote(block, dest_ty_src, msg, "destination has length {d}", .{dest_len}); | 31437 | try sema.errNote(dest_ty_src, msg, "destination has length {d}", .{dest_len}); |
| 31533 | try sema.errNote(block, inst_src, msg, "source has length {d}", .{inst_len}); | 31438 | try sema.errNote(inst_src, msg, "source has length {d}", .{inst_len}); |
| 31534 | break :msg msg; | 31439 | break :msg msg; |
| 31535 | }; | 31440 | }; |
| 31536 | return sema.failWithOwnedErrorMsg(block, msg); | 31441 | return sema.failWithOwnedErrorMsg(block, msg); |
| ... | @@ -31701,9 +31606,9 @@ fn coerceTupleToStruct( | ... | @@ -31701,9 +31606,9 @@ fn coerceTupleToStruct( |
| 31701 | const template = "missing struct field: {}"; | 31606 | const template = "missing struct field: {}"; |
| 31702 | const args = .{field_name.fmt(ip)}; | 31607 | const args = .{field_name.fmt(ip)}; |
| 31703 | if (root_msg) |msg| { | 31608 | if (root_msg) |msg| { |
| 31704 | try sema.errNote(block, field_src, msg, template, args); | 31609 | try sema.errNote(field_src, msg, template, args); |
| 31705 | } else { | 31610 | } else { |
| 31706 | root_msg = try sema.errMsg(block, field_src, template, args); | 31611 | root_msg = try sema.errMsg(field_src, template, args); |
| 31707 | } | 31612 | } |
| 31708 | continue; | 31613 | continue; |
| 31709 | } | 31614 | } |
| ... | @@ -31839,18 +31744,18 @@ fn coerceTupleToTuple( | ... | @@ -31839,18 +31744,18 @@ fn coerceTupleToTuple( |
| 31839 | const field_name = tuple_ty.structFieldName(i, mod).unwrap() orelse { | 31744 | const field_name = tuple_ty.structFieldName(i, mod).unwrap() orelse { |
| 31840 | const template = "missing tuple field: {d}"; | 31745 | const template = "missing tuple field: {d}"; |
| 31841 | if (root_msg) |msg| { | 31746 | if (root_msg) |msg| { |
| 31842 | try sema.errNote(block, field_src, msg, template, .{i}); | 31747 | try sema.errNote(field_src, msg, template, .{i}); |
| 31843 | } else { | 31748 | } else { |
| 31844 | root_msg = try sema.errMsg(block, field_src, template, .{i}); | 31749 | root_msg = try sema.errMsg(field_src, template, .{i}); |
| 31845 | } | 31750 | } |
| 31846 | continue; | 31751 | continue; |
| 31847 | }; | 31752 | }; |
| 31848 | const template = "missing struct field: {}"; | 31753 | const template = "missing struct field: {}"; |
| 31849 | const args = .{field_name.fmt(ip)}; | 31754 | const args = .{field_name.fmt(ip)}; |
| 31850 | if (root_msg) |msg| { | 31755 | if (root_msg) |msg| { |
| 31851 | try sema.errNote(block, field_src, msg, template, args); | 31756 | try sema.errNote(field_src, msg, template, args); |
| 31852 | } else { | 31757 | } else { |
| 31853 | root_msg = try sema.errMsg(block, field_src, template, args); | 31758 | root_msg = try sema.errMsg(field_src, template, args); |
| 31854 | } | 31759 | } |
| 31855 | continue; | 31760 | continue; |
| 31856 | } | 31761 | } |
| ... | @@ -31884,7 +31789,7 @@ fn analyzeDeclVal( | ... | @@ -31884,7 +31789,7 @@ fn analyzeDeclVal( |
| 31884 | src: LazySrcLoc, | 31789 | src: LazySrcLoc, |
| 31885 | decl_index: InternPool.DeclIndex, | 31790 | decl_index: InternPool.DeclIndex, |
| 31886 | ) CompileError!Air.Inst.Ref { | 31791 | ) CompileError!Air.Inst.Ref { |
| 31887 | try sema.addReferencedBy(block, src, decl_index); | 31792 | try sema.addReferencedBy(src, decl_index); |
| 31888 | if (sema.decl_val_table.get(decl_index)) |result| { | 31793 | if (sema.decl_val_table.get(decl_index)) |result| { |
| 31889 | return result; | 31794 | return result; |
| 31890 | } | 31795 | } |
| ... | @@ -31900,21 +31805,14 @@ fn analyzeDeclVal( | ... | @@ -31900,21 +31805,14 @@ fn analyzeDeclVal( |
| 31900 | | 31805 | |
| 31901 | fn addReferencedBy( | 31806 | fn addReferencedBy( |
| 31902 | sema: *Sema, | 31807 | sema: *Sema, |
| 31903 | block: *Block, | | |
| 31904 | src: LazySrcLoc, | 31808 | src: LazySrcLoc, |
| 31905 | decl_index: InternPool.DeclIndex, | 31809 | decl_index: InternPool.DeclIndex, |
| 31906 | ) !void { | 31810 | ) !void { |
| 31907 | if (sema.mod.comp.reference_trace == 0) return; | 31811 | if (sema.mod.comp.reference_trace == 0) return; |
| 31908 | if (src == .unneeded) { | | |
| 31909 | // We can't use NeededSourceLocation, since sites handling that assume it means a compile | | |
| 31910 | // error. Our long-term strategy here is to gradually transition from NeededSourceLocation | | |
| 31911 | // into having more LazySrcLoc tags. In the meantime, let release compilers just ignore this | | |
| 31912 | // reference (a slightly-incomplete error is better than a crash!), but trigger a panic in | | |
| 31913 | // debug so we can fix this case. | | |
| 31914 | if (std.debug.runtime_safety) unreachable else return; | | |
| 31915 | } | | |
| 31916 | try sema.mod.reference_table.put(sema.gpa, decl_index, .{ | 31812 | try sema.mod.reference_table.put(sema.gpa, decl_index, .{ |
| 31917 | .referencer = block.src_decl, | 31813 | // TODO: this can make the reference trace suboptimal. This will be fixed |
| | 31814 | // once the reference table is reworked for incremental compilation. |
| | 31815 | .referencer = sema.owner_decl_index, |
| 31918 | .src = src, | 31816 | .src = src, |
| 31919 | }); | 31817 | }); |
| 31920 | } | 31818 | } |
| ... | @@ -31924,7 +31822,10 @@ pub fn ensureDeclAnalyzed(sema: *Sema, decl_index: InternPool.DeclIndex) Compile | ... | @@ -31924,7 +31822,10 @@ pub fn ensureDeclAnalyzed(sema: *Sema, decl_index: InternPool.DeclIndex) Compile |
| 31924 | const ip = &mod.intern_pool; | 31822 | const ip = &mod.intern_pool; |
| 31925 | const decl = mod.declPtr(decl_index); | 31823 | const decl = mod.declPtr(decl_index); |
| 31926 | if (decl.analysis == .in_progress) { | 31824 | if (decl.analysis == .in_progress) { |
| 31927 | const msg = try Module.ErrorMsg.create(sema.gpa, decl.srcLoc(mod), "dependency loop detected", .{}); | 31825 | const msg = try sema.errMsg(.{ |
| | 31826 | .base_node_inst = decl.zir_decl_index.unwrap().?, |
| | 31827 | .offset = LazySrcLoc.Offset.nodeOffset(0), |
| | 31828 | }, "dependency loop detected", .{}); |
| 31928 | return sema.failWithOwnedErrorMsg(null, msg); | 31829 | return sema.failWithOwnedErrorMsg(null, msg); |
| 31929 | } | 31830 | } |
| 31930 | | 31831 | |
| ... | @@ -32419,10 +32320,9 @@ fn analyzeSlice( | ... | @@ -32419,10 +32320,9 @@ fn analyzeSlice( |
| 32419 | if (try sema.compareScalar(start_value, .neq, end_value, Type.comptime_int)) { | 32320 | if (try sema.compareScalar(start_value, .neq, end_value, Type.comptime_int)) { |
| 32420 | if (try sema.compareScalar(start_value, .neq, Value.zero_comptime_int, Type.comptime_int)) { | 32321 | if (try sema.compareScalar(start_value, .neq, Value.zero_comptime_int, Type.comptime_int)) { |
| 32421 | const msg = msg: { | 32322 | const msg = msg: { |
| 32422 | const msg = try sema.errMsg(block, start_src, bounds_error_message, .{}); | 32323 | const msg = try sema.errMsg(start_src, bounds_error_message, .{}); |
| 32423 | errdefer msg.destroy(sema.gpa); | 32324 | errdefer msg.destroy(sema.gpa); |
| 32424 | try sema.errNote( | 32325 | try sema.errNote( |
| 32425 | block, | | |
| 32426 | start_src, | 32326 | start_src, |
| 32427 | msg, | 32327 | msg, |
| 32428 | "expected '{}', found '{}'", | 32328 | "expected '{}', found '{}'", |
| ... | @@ -32436,10 +32336,9 @@ fn analyzeSlice( | ... | @@ -32436,10 +32336,9 @@ fn analyzeSlice( |
| 32436 | return sema.failWithOwnedErrorMsg(block, msg); | 32336 | return sema.failWithOwnedErrorMsg(block, msg); |
| 32437 | } else if (try sema.compareScalar(end_value, .neq, Value.one_comptime_int, Type.comptime_int)) { | 32337 | } else if (try sema.compareScalar(end_value, .neq, Value.one_comptime_int, Type.comptime_int)) { |
| 32438 | const msg = msg: { | 32338 | const msg = msg: { |
| 32439 | const msg = try sema.errMsg(block, end_src, bounds_error_message, .{}); | 32339 | const msg = try sema.errMsg(end_src, bounds_error_message, .{}); |
| 32440 | errdefer msg.destroy(sema.gpa); | 32340 | errdefer msg.destroy(sema.gpa); |
| 32441 | try sema.errNote( | 32341 | try sema.errNote( |
| 32442 | block, | | |
| 32443 | end_src, | 32342 | end_src, |
| 32444 | msg, | 32343 | msg, |
| 32445 | "expected '{}', found '{}'", | 32344 | "expected '{}', found '{}'", |
| ... | @@ -32693,9 +32592,9 @@ fn analyzeSlice( | ... | @@ -32693,9 +32592,9 @@ fn analyzeSlice( |
| 32693 | | 32592 | |
| 32694 | if (!actual_sentinel.eql(expected_sentinel, elem_ty, mod)) { | 32593 | if (!actual_sentinel.eql(expected_sentinel, elem_ty, mod)) { |
| 32695 | const msg = msg: { | 32594 | const msg = msg: { |
| 32696 | const msg = try sema.errMsg(block, src, "value in memory does not match slice sentinel", .{}); | 32595 | const msg = try sema.errMsg(src, "value in memory does not match slice sentinel", .{}); |
| 32697 | errdefer msg.destroy(sema.gpa); | 32596 | errdefer msg.destroy(sema.gpa); |
| 32698 | try sema.errNote(block, src, msg, "expected '{}', found '{}'", .{ | 32597 | try sema.errNote(src, msg, "expected '{}', found '{}'", .{ |
| 32699 | expected_sentinel.fmtValue(mod, sema), | 32598 | expected_sentinel.fmtValue(mod, sema), |
| 32700 | actual_sentinel.fmtValue(mod, sema), | 32599 | actual_sentinel.fmtValue(mod, sema), |
| 32701 | }); | 32600 | }); |
| ... | @@ -33567,6 +33466,31 @@ const PeerResolveStrategy = enum { | ... | @@ -33567,6 +33466,31 @@ const PeerResolveStrategy = enum { |
| 33567 | } | 33466 | } |
| 33568 | }; | 33467 | }; |
| 33569 | | 33468 | |
| | 33469 | const PeerTypeCandidateSrc = union(enum) { |
| | 33470 | /// Do not print out error notes for candidate sources |
| | 33471 | none: void, |
| | 33472 | /// When we want to know the the src of candidate i, look up at |
| | 33473 | /// index i in this slice |
| | 33474 | override: []const ?LazySrcLoc, |
| | 33475 | /// resolvePeerTypes originates from a @TypeOf(...) call |
| | 33476 | typeof_builtin_call_node_offset: i32, |
| | 33477 | |
| | 33478 | pub fn resolve( |
| | 33479 | self: PeerTypeCandidateSrc, |
| | 33480 | block: *Block, |
| | 33481 | candidate_i: usize, |
| | 33482 | ) ?LazySrcLoc { |
| | 33483 | return switch (self) { |
| | 33484 | .none => null, |
| | 33485 | .override => |candidate_srcs| if (candidate_i >= candidate_srcs.len) |
| | 33486 | null |
| | 33487 | else |
| | 33488 | candidate_srcs[candidate_i], |
| | 33489 | .typeof_builtin_call_node_offset => |node_offset| block.builtinCallArgSrc(node_offset, @intCast(candidate_i)), |
| | 33490 | }; |
| | 33491 | } |
| | 33492 | }; |
| | 33493 | |
| 33570 | const PeerResolveResult = union(enum) { | 33494 | const PeerResolveResult = union(enum) { |
| 33571 | /// The peer type resolution was successful, and resulted in the given type. | 33495 | /// The peer type resolution was successful, and resulted in the given type. |
| 33572 | success: Type, | 33496 | success: Type, |
| ... | @@ -33591,10 +33515,9 @@ const PeerResolveResult = union(enum) { | ... | @@ -33591,10 +33515,9 @@ const PeerResolveResult = union(enum) { |
| 33591 | block: *Block, | 33515 | block: *Block, |
| 33592 | src: LazySrcLoc, | 33516 | src: LazySrcLoc, |
| 33593 | instructions: []const Air.Inst.Ref, | 33517 | instructions: []const Air.Inst.Ref, |
| 33594 | candidate_srcs: Module.PeerTypeCandidateSrc, | 33518 | candidate_srcs: PeerTypeCandidateSrc, |
| 33595 | ) !*Module.ErrorMsg { | 33519 | ) !*Module.ErrorMsg { |
| 33596 | const mod = sema.mod; | 33520 | const mod = sema.mod; |
| 33597 | const decl_ptr = mod.declPtr(block.src_decl); | | |
| 33598 | | 33521 | |
| 33599 | var opt_msg: ?*Module.ErrorMsg = null; | 33522 | var opt_msg: ?*Module.ErrorMsg = null; |
| 33600 | errdefer if (opt_msg) |msg| msg.destroy(sema.gpa); | 33523 | errdefer if (opt_msg) |msg| msg.destroy(sema.gpa); |
| ... | @@ -33622,9 +33545,9 @@ const PeerResolveResult = union(enum) { | ... | @@ -33622,9 +33545,9 @@ const PeerResolveResult = union(enum) { |
| 33622 | const fmt = "struct field '{}' has conflicting types"; | 33545 | const fmt = "struct field '{}' has conflicting types"; |
| 33623 | const args = .{field_error.field_name.fmt(&mod.intern_pool)}; | 33546 | const args = .{field_error.field_name.fmt(&mod.intern_pool)}; |
| 33624 | if (opt_msg) |msg| { | 33547 | if (opt_msg) |msg| { |
| 33625 | try sema.errNote(block, src, msg, fmt, args); | 33548 | try sema.errNote(src, msg, fmt, args); |
| 33626 | } else { | 33549 | } else { |
| 33627 | opt_msg = try sema.errMsg(block, src, fmt, args); | 33550 | opt_msg = try sema.errMsg(src, fmt, args); |
| 33628 | } | 33551 | } |
| 33629 | | 33552 | |
| 33630 | // Continue on to child error | 33553 | // Continue on to child error |
| ... | @@ -33646,8 +33569,8 @@ const PeerResolveResult = union(enum) { | ... | @@ -33646,8 +33569,8 @@ const PeerResolveResult = union(enum) { |
| 33646 | peer_tys[conflict_idx[1]], | 33569 | peer_tys[conflict_idx[1]], |
| 33647 | }; | 33570 | }; |
| 33648 | const conflict_srcs: [2]?LazySrcLoc = .{ | 33571 | const conflict_srcs: [2]?LazySrcLoc = .{ |
| 33649 | candidate_srcs.resolve(mod, decl_ptr, conflict_idx[0]), | 33572 | candidate_srcs.resolve(block, conflict_idx[0]), |
| 33650 | candidate_srcs.resolve(mod, decl_ptr, conflict_idx[1]), | 33573 | candidate_srcs.resolve(block, conflict_idx[1]), |
| 33651 | }; | 33574 | }; |
| 33652 | | 33575 | |
| 33653 | const fmt = "incompatible types: '{}' and '{}'"; | 33576 | const fmt = "incompatible types: '{}' and '{}'"; |
| ... | @@ -33656,16 +33579,16 @@ const PeerResolveResult = union(enum) { | ... | @@ -33656,16 +33579,16 @@ const PeerResolveResult = union(enum) { |
| 33656 | conflict_tys[1].fmt(mod), | 33579 | conflict_tys[1].fmt(mod), |
| 33657 | }; | 33580 | }; |
| 33658 | const msg = if (opt_msg) |msg| msg: { | 33581 | const msg = if (opt_msg) |msg| msg: { |
| 33659 | try sema.errNote(block, src, msg, fmt, args); | 33582 | try sema.errNote(src, msg, fmt, args); |
| 33660 | break :msg msg; | 33583 | break :msg msg; |
| 33661 | } else msg: { | 33584 | } else msg: { |
| 33662 | const msg = try sema.errMsg(block, src, fmt, args); | 33585 | const msg = try sema.errMsg(src, fmt, args); |
| 33663 | opt_msg = msg; | 33586 | opt_msg = msg; |
| 33664 | break :msg msg; | 33587 | break :msg msg; |
| 33665 | }; | 33588 | }; |
| 33666 | | 33589 | |
| 33667 | if (conflict_srcs[0]) |src_loc| try sema.errNote(block, src_loc, msg, "type '{}' here", .{conflict_tys[0].fmt(mod)}); | 33590 | if (conflict_srcs[0]) |src_loc| try sema.errNote(src_loc, msg, "type '{}' here", .{conflict_tys[0].fmt(mod)}); |
| 33668 | if (conflict_srcs[1]) |src_loc| try sema.errNote(block, src_loc, msg, "type '{}' here", .{conflict_tys[1].fmt(mod)}); | 33591 | if (conflict_srcs[1]) |src_loc| try sema.errNote(src_loc, msg, "type '{}' here", .{conflict_tys[1].fmt(mod)}); |
| 33669 | | 33592 | |
| 33670 | // No child error | 33593 | // No child error |
| 33671 | break; | 33594 | break; |
| ... | @@ -33680,7 +33603,7 @@ fn resolvePeerTypes( | ... | @@ -33680,7 +33603,7 @@ fn resolvePeerTypes( |
| 33680 | block: *Block, | 33603 | block: *Block, |
| 33681 | src: LazySrcLoc, | 33604 | src: LazySrcLoc, |
| 33682 | instructions: []const Air.Inst.Ref, | 33605 | instructions: []const Air.Inst.Ref, |
| 33683 | candidate_srcs: Module.PeerTypeCandidateSrc, | 33606 | candidate_srcs: PeerTypeCandidateSrc, |
| 33684 | ) !Type { | 33607 | ) !Type { |
| 33685 | switch (instructions.len) { | 33608 | switch (instructions.len) { |
| 33686 | 0 => return Type.noreturn, | 33609 | 0 => return Type.noreturn, |
| ... | @@ -35119,9 +35042,9 @@ pub fn resolveStructAlignment( | ... | @@ -35119,9 +35042,9 @@ pub fn resolveStructAlignment( |
| 35119 | } | 35042 | } |
| 35120 | | 35043 | |
| 35121 | fn resolveStructLayout(sema: *Sema, ty: Type) CompileError!void { | 35044 | fn resolveStructLayout(sema: *Sema, ty: Type) CompileError!void { |
| 35122 | const mod = sema.mod; | 35045 | const zcu = sema.mod; |
| 35123 | const ip = &mod.intern_pool; | 35046 | const ip = &zcu.intern_pool; |
| 35124 | const struct_type = mod.typeToStruct(ty) orelse return; | 35047 | const struct_type = zcu.typeToStruct(ty) orelse return; |
| 35125 | | 35048 | |
| 35126 | if (struct_type.haveLayout(ip)) | 35049 | if (struct_type.haveLayout(ip)) |
| 35127 | return; | 35050 | return; |
| ... | @@ -35129,16 +35052,15 @@ fn resolveStructLayout(sema: *Sema, ty: Type) CompileError!void { | ... | @@ -35129,16 +35052,15 @@ fn resolveStructLayout(sema: *Sema, ty: Type) CompileError!void { |
| 35129 | try sema.resolveTypeFields(ty); | 35052 | try sema.resolveTypeFields(ty); |
| 35130 | | 35053 | |
| 35131 | if (struct_type.layout == .@"packed") { | 35054 | if (struct_type.layout == .@"packed") { |
| 35132 | try semaBackingIntType(mod, struct_type); | 35055 | try semaBackingIntType(zcu, struct_type); |
| 35133 | return; | 35056 | return; |
| 35134 | } | 35057 | } |
| 35135 | | 35058 | |
| 35136 | if (struct_type.setLayoutWip(ip)) { | 35059 | if (struct_type.setLayoutWip(ip)) { |
| 35137 | const msg = try Module.ErrorMsg.create( | 35060 | const msg = try sema.errMsg( |
| 35138 | sema.gpa, | 35061 | ty.srcLoc(zcu), |
| 35139 | mod.declPtr(struct_type.decl.unwrap().?).srcLoc(mod), | | |
| 35140 | "struct '{}' depends on itself", | 35062 | "struct '{}' depends on itself", |
| 35141 | .{ty.fmt(mod)}, | 35063 | .{ty.fmt(zcu)}, |
| 35142 | ); | 35064 | ); |
| 35143 | return sema.failWithOwnedErrorMsg(null, msg); | 35065 | return sema.failWithOwnedErrorMsg(null, msg); |
| 35144 | } | 35066 | } |
| ... | @@ -35175,9 +35097,8 @@ fn resolveStructLayout(sema: *Sema, ty: Type) CompileError!void { | ... | @@ -35175,9 +35097,8 @@ fn resolveStructLayout(sema: *Sema, ty: Type) CompileError!void { |
| 35175 | } | 35097 | } |
| 35176 | | 35098 | |
| 35177 | if (struct_type.flagsPtr(ip).assumed_runtime_bits and !(try sema.typeHasRuntimeBits(ty))) { | 35099 | if (struct_type.flagsPtr(ip).assumed_runtime_bits and !(try sema.typeHasRuntimeBits(ty))) { |
| 35178 | const msg = try Module.ErrorMsg.create( | 35100 | const msg = try sema.errMsg( |
| 35179 | sema.gpa, | 35101 | ty.srcLoc(zcu), |
| 35180 | mod.declPtr(struct_type.decl.unwrap().?).srcLoc(mod), | | |
| 35181 | "struct layout depends on it having runtime bits", | 35102 | "struct layout depends on it having runtime bits", |
| 35182 | .{}, | 35103 | .{}, |
| 35183 | ); | 35104 | ); |
| ... | @@ -35185,11 +35106,10 @@ fn resolveStructLayout(sema: *Sema, ty: Type) CompileError!void { | ... | @@ -35185,11 +35106,10 @@ fn resolveStructLayout(sema: *Sema, ty: Type) CompileError!void { |
| 35185 | } | 35106 | } |
| 35186 | | 35107 | |
| 35187 | if (struct_type.flagsPtr(ip).assumed_pointer_aligned and | 35108 | if (struct_type.flagsPtr(ip).assumed_pointer_aligned and |
| 35188 | big_align.compareStrict(.neq, Alignment.fromByteUnits(@divExact(mod.getTarget().ptrBitWidth(), 8)))) | 35109 | big_align.compareStrict(.neq, Alignment.fromByteUnits(@divExact(zcu.getTarget().ptrBitWidth(), 8)))) |
| 35189 | { | 35110 | { |
| 35190 | const msg = try Module.ErrorMsg.create( | 35111 | const msg = try sema.errMsg( |
| 35191 | sema.gpa, | 35112 | ty.srcLoc(zcu), |
| 35192 | mod.declPtr(struct_type.decl.unwrap().?).srcLoc(mod), | | |
| 35193 | "struct layout depends on being pointer aligned", | 35113 | "struct layout depends on being pointer aligned", |
| 35194 | .{}, | 35114 | .{}, |
| 35195 | ); | 35115 | ); |
| ... | @@ -35221,7 +35141,7 @@ fn resolveStructLayout(sema: *Sema, ty: Type) CompileError!void { | ... | @@ -35221,7 +35141,7 @@ fn resolveStructLayout(sema: *Sema, ty: Type) CompileError!void { |
| 35221 | return a_align.compare(.gt, b_align); | 35141 | return a_align.compare(.gt, b_align); |
| 35222 | } | 35142 | } |
| 35223 | }; | 35143 | }; |
| 35224 | if (struct_type.isTuple(ip) or !mod.backendSupportsFeature(.field_reordering)) { | 35144 | if (struct_type.isTuple(ip) or !zcu.backendSupportsFeature(.field_reordering)) { |
| 35225 | // TODO: don't handle tuples differently. This logic exists only because it | 35145 | // TODO: don't handle tuples differently. This logic exists only because it |
| 35226 | // uncovers latent bugs if removed. Fix the latent bugs and remove this logic! | 35146 | // uncovers latent bugs if removed. Fix the latent bugs and remove this logic! |
| 35227 | // Likewise, implement field reordering support in all the backends! | 35147 | // Likewise, implement field reordering support in all the backends! |
| ... | @@ -35272,7 +35192,7 @@ fn semaBackingIntType(mod: *Module, struct_type: InternPool.LoadedStructType) Co | ... | @@ -35272,7 +35192,7 @@ fn semaBackingIntType(mod: *Module, struct_type: InternPool.LoadedStructType) Co |
| 35272 | var analysis_arena = std.heap.ArenaAllocator.init(gpa); | 35192 | var analysis_arena = std.heap.ArenaAllocator.init(gpa); |
| 35273 | defer analysis_arena.deinit(); | 35193 | defer analysis_arena.deinit(); |
| 35274 | | 35194 | |
| 35275 | var comptime_err_ret_trace = std.ArrayList(Module.SrcLoc).init(gpa); | 35195 | var comptime_err_ret_trace = std.ArrayList(LazySrcLoc).init(gpa); |
| 35276 | defer comptime_err_ret_trace.deinit(); | 35196 | defer comptime_err_ret_trace.deinit(); |
| 35277 | | 35197 | |
| 35278 | var sema: Sema = .{ | 35198 | var sema: Sema = .{ |
| ... | @@ -35294,11 +35214,12 @@ fn semaBackingIntType(mod: *Module, struct_type: InternPool.LoadedStructType) Co | ... | @@ -35294,11 +35214,12 @@ fn semaBackingIntType(mod: *Module, struct_type: InternPool.LoadedStructType) Co |
| 35294 | var block: Block = .{ | 35214 | var block: Block = .{ |
| 35295 | .parent = null, | 35215 | .parent = null, |
| 35296 | .sema = &sema, | 35216 | .sema = &sema, |
| 35297 | .src_decl = decl_index, | | |
| 35298 | .namespace = struct_type.namespace.unwrap() orelse decl.src_namespace, | 35217 | .namespace = struct_type.namespace.unwrap() orelse decl.src_namespace, |
| 35299 | .instructions = .{}, | 35218 | .instructions = .{}, |
| 35300 | .inlining = null, | 35219 | .inlining = null, |
| 35301 | .is_comptime = true, | 35220 | .is_comptime = true, |
| | 35221 | .src_base_inst = struct_type.zir_index.unwrap().?, |
| | 35222 | .type_name_ctx = decl.name, |
| 35302 | }; | 35223 | }; |
| 35303 | defer assert(block.instructions.items.len == 0); | 35224 | defer assert(block.instructions.items.len == 0); |
| 35304 | | 35225 | |
| ... | @@ -35331,7 +35252,10 @@ fn semaBackingIntType(mod: *Module, struct_type: InternPool.LoadedStructType) Co | ... | @@ -35331,7 +35252,10 @@ fn semaBackingIntType(mod: *Module, struct_type: InternPool.LoadedStructType) Co |
| 35331 | const backing_int_body_len = zir.extra[extra_index]; | 35252 | const backing_int_body_len = zir.extra[extra_index]; |
| 35332 | extra_index += 1; | 35253 | extra_index += 1; |
| 35333 | | 35254 | |
| 35334 | const backing_int_src: LazySrcLoc = .{ .node_offset_container_tag = 0 }; | 35255 | const backing_int_src: LazySrcLoc = .{ |
| | 35256 | .base_node_inst = struct_type.zir_index.unwrap().?, |
| | 35257 | .offset = .{ .node_offset_container_tag = 0 }, |
| | 35258 | }; |
| 35335 | const backing_int_ty = blk: { | 35259 | const backing_int_ty = blk: { |
| 35336 | if (backing_int_body_len == 0) { | 35260 | if (backing_int_body_len == 0) { |
| 35337 | const backing_int_ref: Zir.Inst.Ref = @enumFromInt(zir.extra[extra_index]); | 35261 | const backing_int_ref: Zir.Inst.Ref = @enumFromInt(zir.extra[extra_index]); |
| ... | @@ -35347,7 +35271,7 @@ fn semaBackingIntType(mod: *Module, struct_type: InternPool.LoadedStructType) Co | ... | @@ -35347,7 +35271,7 @@ fn semaBackingIntType(mod: *Module, struct_type: InternPool.LoadedStructType) Co |
| 35347 | struct_type.backingIntType(ip).* = backing_int_ty.toIntern(); | 35271 | struct_type.backingIntType(ip).* = backing_int_ty.toIntern(); |
| 35348 | } else { | 35272 | } else { |
| 35349 | if (fields_bit_sum > std.math.maxInt(u16)) { | 35273 | if (fields_bit_sum > std.math.maxInt(u16)) { |
| 35350 | return sema.fail(&block, LazySrcLoc.nodeOffset(0), "size of packed struct '{d}' exceeds maximum bit width of 65535", .{fields_bit_sum}); | 35274 | return sema.fail(&block, block.nodeOffset(0), "size of packed struct '{d}' exceeds maximum bit width of 65535", .{fields_bit_sum}); |
| 35351 | } | 35275 | } |
| 35352 | const backing_int_ty = try mod.intType(.unsigned, @intCast(fields_bit_sum)); | 35276 | const backing_int_ty = try mod.intType(.unsigned, @intCast(fields_bit_sum)); |
| 35353 | struct_type.backingIntType(ip).* = backing_int_ty.toIntern(); | 35277 | struct_type.backingIntType(ip).* = backing_int_ty.toIntern(); |
| ... | @@ -35374,9 +35298,9 @@ fn checkIndexable(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) !void { | ... | @@ -35374,9 +35298,9 @@ fn checkIndexable(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) !void { |
| 35374 | const mod = sema.mod; | 35298 | const mod = sema.mod; |
| 35375 | if (!ty.isIndexable(mod)) { | 35299 | if (!ty.isIndexable(mod)) { |
| 35376 | const msg = msg: { | 35300 | const msg = msg: { |
| 35377 | const msg = try sema.errMsg(block, src, "type '{}' does not support indexing", .{ty.fmt(sema.mod)}); | 35301 | const msg = try sema.errMsg(src, "type '{}' does not support indexing", .{ty.fmt(sema.mod)}); |
| 35378 | errdefer msg.destroy(sema.gpa); | 35302 | errdefer msg.destroy(sema.gpa); |
| 35379 | try sema.errNote(block, src, msg, "operand must be an array, slice, tuple, or vector", .{}); | 35303 | try sema.errNote(src, msg, "operand must be an array, slice, tuple, or vector", .{}); |
| 35380 | break :msg msg; | 35304 | break :msg msg; |
| 35381 | }; | 35305 | }; |
| 35382 | return sema.failWithOwnedErrorMsg(block, msg); | 35306 | return sema.failWithOwnedErrorMsg(block, msg); |
| ... | @@ -35397,9 +35321,9 @@ fn checkMemOperand(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) !void | ... | @@ -35397,9 +35321,9 @@ fn checkMemOperand(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) !void |
| 35397 | } | 35321 | } |
| 35398 | } | 35322 | } |
| 35399 | const msg = msg: { | 35323 | const msg = msg: { |
| 35400 | const msg = try sema.errMsg(block, src, "type '{}' is not an indexable pointer", .{ty.fmt(sema.mod)}); | 35324 | const msg = try sema.errMsg(src, "type '{}' is not an indexable pointer", .{ty.fmt(sema.mod)}); |
| 35401 | errdefer msg.destroy(sema.gpa); | 35325 | errdefer msg.destroy(sema.gpa); |
| 35402 | try sema.errNote(block, src, msg, "operand must be a slice, a many pointer or a pointer to an array", .{}); | 35326 | try sema.errNote(src, msg, "operand must be a slice, a many pointer or a pointer to an array", .{}); |
| 35403 | break :msg msg; | 35327 | break :msg msg; |
| 35404 | }; | 35328 | }; |
| 35405 | return sema.failWithOwnedErrorMsg(block, msg); | 35329 | return sema.failWithOwnedErrorMsg(block, msg); |
| ... | @@ -35450,8 +35374,8 @@ pub fn resolveUnionAlignment( | ... | @@ -35450,8 +35374,8 @@ pub fn resolveUnionAlignment( |
| 35450 | | 35374 | |
| 35451 | /// This logic must be kept in sync with `Module.getUnionLayout`. | 35375 | /// This logic must be kept in sync with `Module.getUnionLayout`. |
| 35452 | fn resolveUnionLayout(sema: *Sema, ty: Type) CompileError!void { | 35376 | fn resolveUnionLayout(sema: *Sema, ty: Type) CompileError!void { |
| 35453 | const mod = sema.mod; | 35377 | const zcu = sema.mod; |
| 35454 | const ip = &mod.intern_pool; | 35378 | const ip = &zcu.intern_pool; |
| 35455 | | 35379 | |
| 35456 | try sema.resolveTypeFieldsUnion(ty, ip.loadUnionType(ty.ip_index)); | 35380 | try sema.resolveTypeFieldsUnion(ty, ip.loadUnionType(ty.ip_index)); |
| 35457 | | 35381 | |
| ... | @@ -35461,11 +35385,10 @@ fn resolveUnionLayout(sema: *Sema, ty: Type) CompileError!void { | ... | @@ -35461,11 +35385,10 @@ fn resolveUnionLayout(sema: *Sema, ty: Type) CompileError!void { |
| 35461 | switch (union_type.flagsPtr(ip).status) { | 35385 | switch (union_type.flagsPtr(ip).status) { |
| 35462 | .none, .have_field_types => {}, | 35386 | .none, .have_field_types => {}, |
| 35463 | .field_types_wip, .layout_wip => { | 35387 | .field_types_wip, .layout_wip => { |
| 35464 | const msg = try Module.ErrorMsg.create( | 35388 | const msg = try sema.errMsg( |
| 35465 | sema.gpa, | 35389 | ty.srcLoc(zcu), |
| 35466 | mod.declPtr(union_type.decl).srcLoc(mod), | | |
| 35467 | "union '{}' depends on itself", | 35390 | "union '{}' depends on itself", |
| 35468 | .{ty.fmt(mod)}, | 35391 | .{ty.fmt(zcu)}, |
| 35469 | ); | 35392 | ); |
| 35470 | return sema.failWithOwnedErrorMsg(null, msg); | 35393 | return sema.failWithOwnedErrorMsg(null, msg); |
| 35471 | }, | 35394 | }, |
| ... | @@ -35484,7 +35407,7 @@ fn resolveUnionLayout(sema: *Sema, ty: Type) CompileError!void { | ... | @@ -35484,7 +35407,7 @@ fn resolveUnionLayout(sema: *Sema, ty: Type) CompileError!void { |
| 35484 | for (0..union_type.field_types.len) |field_index| { | 35407 | for (0..union_type.field_types.len) |field_index| { |
| 35485 | const field_ty = Type.fromInterned(union_type.field_types.get(ip)[field_index]); | 35408 | const field_ty = Type.fromInterned(union_type.field_types.get(ip)[field_index]); |
| 35486 | | 35409 | |
| 35487 | if (try sema.typeRequiresComptime(field_ty) or field_ty.zigTypeTag(mod) == .NoReturn) continue; // TODO: should this affect alignment? | 35410 | if (try sema.typeRequiresComptime(field_ty) or field_ty.zigTypeTag(zcu) == .NoReturn) continue; // TODO: should this affect alignment? |
| 35488 | | 35411 | |
| 35489 | max_size = @max(max_size, sema.typeAbiSize(field_ty) catch |err| switch (err) { | 35412 | max_size = @max(max_size, sema.typeAbiSize(field_ty) catch |err| switch (err) { |
| 35490 | error.AnalysisFail => { | 35413 | error.AnalysisFail => { |
| ... | @@ -35526,7 +35449,7 @@ fn resolveUnionLayout(sema: *Sema, ty: Type) CompileError!void { | ... | @@ -35526,7 +35449,7 @@ fn resolveUnionLayout(sema: *Sema, ty: Type) CompileError!void { |
| 35526 | } else { | 35449 | } else { |
| 35527 | // {Payload, Tag} | 35450 | // {Payload, Tag} |
| 35528 | size += max_size; | 35451 | size += max_size; |
| 35529 | size = switch (mod.getTarget().ofmt) { | 35452 | size = switch (zcu.getTarget().ofmt) { |
| 35530 | .c => max_align, | 35453 | .c => max_align, |
| 35531 | else => tag_align, | 35454 | else => tag_align, |
| 35532 | }.forward(size); | 35455 | }.forward(size); |
| ... | @@ -35545,9 +35468,8 @@ fn resolveUnionLayout(sema: *Sema, ty: Type) CompileError!void { | ... | @@ -35545,9 +35468,8 @@ fn resolveUnionLayout(sema: *Sema, ty: Type) CompileError!void { |
| 35545 | flags.status = .have_layout; | 35468 | flags.status = .have_layout; |
| 35546 | | 35469 | |
| 35547 | if (union_type.flagsPtr(ip).assumed_runtime_bits and !(try sema.typeHasRuntimeBits(ty))) { | 35470 | if (union_type.flagsPtr(ip).assumed_runtime_bits and !(try sema.typeHasRuntimeBits(ty))) { |
| 35548 | const msg = try Module.ErrorMsg.create( | 35471 | const msg = try sema.errMsg( |
| 35549 | sema.gpa, | 35472 | ty.srcLoc(zcu), |
| 35550 | mod.declPtr(union_type.decl).srcLoc(mod), | | |
| 35551 | "union layout depends on it having runtime bits", | 35473 | "union layout depends on it having runtime bits", |
| 35552 | .{}, | 35474 | .{}, |
| 35553 | ); | 35475 | ); |
| ... | @@ -35555,11 +35477,10 @@ fn resolveUnionLayout(sema: *Sema, ty: Type) CompileError!void { | ... | @@ -35555,11 +35477,10 @@ fn resolveUnionLayout(sema: *Sema, ty: Type) CompileError!void { |
| 35555 | } | 35477 | } |
| 35556 | | 35478 | |
| 35557 | if (union_type.flagsPtr(ip).assumed_pointer_aligned and | 35479 | if (union_type.flagsPtr(ip).assumed_pointer_aligned and |
| 35558 | alignment.compareStrict(.neq, Alignment.fromByteUnits(@divExact(mod.getTarget().ptrBitWidth(), 8)))) | 35480 | alignment.compareStrict(.neq, Alignment.fromByteUnits(@divExact(zcu.getTarget().ptrBitWidth(), 8)))) |
| 35559 | { | 35481 | { |
| 35560 | const msg = try Module.ErrorMsg.create( | 35482 | const msg = try sema.errMsg( |
| 35561 | sema.gpa, | 35483 | ty.srcLoc(zcu), |
| 35562 | mod.declPtr(union_type.decl).srcLoc(mod), | | |
| 35563 | "union layout depends on being pointer aligned", | 35484 | "union layout depends on being pointer aligned", |
| 35564 | .{}, | 35485 | .{}, |
| 35565 | ); | 35486 | ); |
| ... | @@ -35783,12 +35704,12 @@ pub fn resolveTypeFieldsStruct( | ... | @@ -35783,12 +35704,12 @@ pub fn resolveTypeFieldsStruct( |
| 35783 | ty: InternPool.Index, | 35704 | ty: InternPool.Index, |
| 35784 | struct_type: InternPool.LoadedStructType, | 35705 | struct_type: InternPool.LoadedStructType, |
| 35785 | ) CompileError!void { | 35706 | ) CompileError!void { |
| 35786 | const mod = sema.mod; | 35707 | const zcu = sema.mod; |
| 35787 | const ip = &mod.intern_pool; | 35708 | const ip = &zcu.intern_pool; |
| 35788 | // If there is no owner decl it means the struct has no fields. | 35709 | // If there is no owner decl it means the struct has no fields. |
| 35789 | const owner_decl = struct_type.decl.unwrap() orelse return; | 35710 | const owner_decl = struct_type.decl.unwrap() orelse return; |
| 35790 | | 35711 | |
| 35791 | switch (mod.declPtr(owner_decl).analysis) { | 35712 | switch (zcu.declPtr(owner_decl).analysis) { |
| 35792 | .file_failure, | 35713 | .file_failure, |
| 35793 | .dependency_failure, | 35714 | .dependency_failure, |
| 35794 | .sema_failure, | 35715 | .sema_failure, |
| ... | @@ -35802,20 +35723,19 @@ pub fn resolveTypeFieldsStruct( | ... | @@ -35802,20 +35723,19 @@ pub fn resolveTypeFieldsStruct( |
| 35802 | if (struct_type.haveFieldTypes(ip)) return; | 35723 | if (struct_type.haveFieldTypes(ip)) return; |
| 35803 | | 35724 | |
| 35804 | if (struct_type.setTypesWip(ip)) { | 35725 | if (struct_type.setTypesWip(ip)) { |
| 35805 | const msg = try Module.ErrorMsg.create( | 35726 | const msg = try sema.errMsg( |
| 35806 | sema.gpa, | 35727 | Type.fromInterned(ty).srcLoc(zcu), |
| 35807 | mod.declPtr(owner_decl).srcLoc(mod), | | |
| 35808 | "struct '{}' depends on itself", | 35728 | "struct '{}' depends on itself", |
| 35809 | .{Type.fromInterned(ty).fmt(mod)}, | 35729 | .{Type.fromInterned(ty).fmt(zcu)}, |
| 35810 | ); | 35730 | ); |
| 35811 | return sema.failWithOwnedErrorMsg(null, msg); | 35731 | return sema.failWithOwnedErrorMsg(null, msg); |
| 35812 | } | 35732 | } |
| 35813 | defer struct_type.clearTypesWip(ip); | 35733 | defer struct_type.clearTypesWip(ip); |
| 35814 | | 35734 | |
| 35815 | semaStructFields(mod, sema.arena, struct_type) catch |err| switch (err) { | 35735 | semaStructFields(zcu, sema.arena, struct_type) catch |err| switch (err) { |
| 35816 | error.AnalysisFail => { | 35736 | error.AnalysisFail => { |
| 35817 | if (mod.declPtr(owner_decl).analysis == .complete) { | 35737 | if (zcu.declPtr(owner_decl).analysis == .complete) { |
| 35818 | mod.declPtr(owner_decl).analysis = .dependency_failure; | 35738 | zcu.declPtr(owner_decl).analysis = .dependency_failure; |
| 35819 | } | 35739 | } |
| 35820 | return error.AnalysisFail; | 35740 | return error.AnalysisFail; |
| 35821 | }, | 35741 | }, |
| ... | @@ -35824,9 +35744,9 @@ pub fn resolveTypeFieldsStruct( | ... | @@ -35824,9 +35744,9 @@ pub fn resolveTypeFieldsStruct( |
| 35824 | } | 35744 | } |
| 35825 | | 35745 | |
| 35826 | pub fn resolveStructFieldInits(sema: *Sema, ty: Type) CompileError!void { | 35746 | pub fn resolveStructFieldInits(sema: *Sema, ty: Type) CompileError!void { |
| 35827 | const mod = sema.mod; | 35747 | const zcu = sema.mod; |
| 35828 | const ip = &mod.intern_pool; | 35748 | const ip = &zcu.intern_pool; |
| 35829 | const struct_type = mod.typeToStruct(ty) orelse return; | 35749 | const struct_type = zcu.typeToStruct(ty) orelse return; |
| 35830 | const owner_decl = struct_type.decl.unwrap() orelse return; | 35750 | const owner_decl = struct_type.decl.unwrap() orelse return; |
| 35831 | | 35751 | |
| 35832 | // Inits can start as resolved | 35752 | // Inits can start as resolved |
| ... | @@ -35835,20 +35755,19 @@ pub fn resolveStructFieldInits(sema: *Sema, ty: Type) CompileError!void { | ... | @@ -35835,20 +35755,19 @@ pub fn resolveStructFieldInits(sema: *Sema, ty: Type) CompileError!void { |
| 35835 | try sema.resolveStructLayout(ty); | 35755 | try sema.resolveStructLayout(ty); |
| 35836 | | 35756 | |
| 35837 | if (struct_type.setInitsWip(ip)) { | 35757 | if (struct_type.setInitsWip(ip)) { |
| 35838 | const msg = try Module.ErrorMsg.create( | 35758 | const msg = try sema.errMsg( |
| 35839 | sema.gpa, | 35759 | ty.srcLoc(zcu), |
| 35840 | mod.declPtr(owner_decl).srcLoc(mod), | | |
| 35841 | "struct '{}' depends on itself", | 35760 | "struct '{}' depends on itself", |
| 35842 | .{ty.fmt(mod)}, | 35761 | .{ty.fmt(zcu)}, |
| 35843 | ); | 35762 | ); |
| 35844 | return sema.failWithOwnedErrorMsg(null, msg); | 35763 | return sema.failWithOwnedErrorMsg(null, msg); |
| 35845 | } | 35764 | } |
| 35846 | defer struct_type.clearInitsWip(ip); | 35765 | defer struct_type.clearInitsWip(ip); |
| 35847 | | 35766 | |
| 35848 | semaStructFieldInits(mod, sema.arena, struct_type) catch |err| switch (err) { | 35767 | semaStructFieldInits(zcu, sema.arena, struct_type) catch |err| switch (err) { |
| 35849 | error.AnalysisFail => { | 35768 | error.AnalysisFail => { |
| 35850 | if (mod.declPtr(owner_decl).analysis == .complete) { | 35769 | if (zcu.declPtr(owner_decl).analysis == .complete) { |
| 35851 | mod.declPtr(owner_decl).analysis = .dependency_failure; | 35770 | zcu.declPtr(owner_decl).analysis = .dependency_failure; |
| 35852 | } | 35771 | } |
| 35853 | return error.AnalysisFail; | 35772 | return error.AnalysisFail; |
| 35854 | }, | 35773 | }, |
| ... | @@ -35858,9 +35777,9 @@ pub fn resolveStructFieldInits(sema: *Sema, ty: Type) CompileError!void { | ... | @@ -35858,9 +35777,9 @@ pub fn resolveStructFieldInits(sema: *Sema, ty: Type) CompileError!void { |
| 35858 | } | 35777 | } |
| 35859 | | 35778 | |
| 35860 | pub fn resolveTypeFieldsUnion(sema: *Sema, ty: Type, union_type: InternPool.LoadedUnionType) CompileError!void { | 35779 | pub fn resolveTypeFieldsUnion(sema: *Sema, ty: Type, union_type: InternPool.LoadedUnionType) CompileError!void { |
| 35861 | const mod = sema.mod; | 35780 | const zcu = sema.mod; |
| 35862 | const ip = &mod.intern_pool; | 35781 | const ip = &zcu.intern_pool; |
| 35863 | const owner_decl = mod.declPtr(union_type.decl); | 35782 | const owner_decl = zcu.declPtr(union_type.decl); |
| 35864 | switch (owner_decl.analysis) { | 35783 | switch (owner_decl.analysis) { |
| 35865 | .file_failure, | 35784 | .file_failure, |
| 35866 | .dependency_failure, | 35785 | .dependency_failure, |
| ... | @@ -35874,11 +35793,10 @@ pub fn resolveTypeFieldsUnion(sema: *Sema, ty: Type, union_type: InternPool.Load | ... | @@ -35874,11 +35793,10 @@ pub fn resolveTypeFieldsUnion(sema: *Sema, ty: Type, union_type: InternPool.Load |
| 35874 | switch (union_type.flagsPtr(ip).status) { | 35793 | switch (union_type.flagsPtr(ip).status) { |
| 35875 | .none => {}, | 35794 | .none => {}, |
| 35876 | .field_types_wip => { | 35795 | .field_types_wip => { |
| 35877 | const msg = try Module.ErrorMsg.create( | 35796 | const msg = try sema.errMsg( |
| 35878 | sema.gpa, | 35797 | ty.srcLoc(zcu), |
| 35879 | owner_decl.srcLoc(mod), | | |
| 35880 | "union '{}' depends on itself", | 35798 | "union '{}' depends on itself", |
| 35881 | .{ty.fmt(mod)}, | 35799 | .{ty.fmt(zcu)}, |
| 35882 | ); | 35800 | ); |
| 35883 | return sema.failWithOwnedErrorMsg(null, msg); | 35801 | return sema.failWithOwnedErrorMsg(null, msg); |
| 35884 | }, | 35802 | }, |
| ... | @@ -35892,7 +35810,7 @@ pub fn resolveTypeFieldsUnion(sema: *Sema, ty: Type, union_type: InternPool.Load | ... | @@ -35892,7 +35810,7 @@ pub fn resolveTypeFieldsUnion(sema: *Sema, ty: Type, union_type: InternPool.Load |
| 35892 | | 35810 | |
| 35893 | union_type.flagsPtr(ip).status = .field_types_wip; | 35811 | union_type.flagsPtr(ip).status = .field_types_wip; |
| 35894 | errdefer union_type.flagsPtr(ip).status = .none; | 35812 | errdefer union_type.flagsPtr(ip).status = .none; |
| 35895 | semaUnionFields(mod, sema.arena, union_type) catch |err| switch (err) { | 35813 | semaUnionFields(zcu, sema.arena, union_type) catch |err| switch (err) { |
| 35896 | error.AnalysisFail => { | 35814 | error.AnalysisFail => { |
| 35897 | if (owner_decl.analysis == .complete) { | 35815 | if (owner_decl.analysis == .complete) { |
| 35898 | owner_decl.analysis = .dependency_failure; | 35816 | owner_decl.analysis = .dependency_failure; |
| ... | @@ -35942,10 +35860,13 @@ fn resolveInferredErrorSet( | ... | @@ -35942,10 +35860,13 @@ fn resolveInferredErrorSet( |
| 35942 | } else if (ip.errorUnionSet(ies_func_info.return_type) == ies_index) { | 35860 | } else if (ip.errorUnionSet(ies_func_info.return_type) == ies_index) { |
| 35943 | if (ies_func_info.is_generic) { | 35861 | if (ies_func_info.is_generic) { |
| 35944 | const msg = msg: { | 35862 | const msg = msg: { |
| 35945 | const msg = try sema.errMsg(block, src, "unable to resolve inferred error set of generic function", .{}); | 35863 | const msg = try sema.errMsg(src, "unable to resolve inferred error set of generic function", .{}); |
| 35946 | errdefer msg.destroy(sema.gpa); | 35864 | errdefer msg.destroy(sema.gpa); |
| 35947 | | 35865 | |
| 35948 | try sema.mod.errNoteNonLazy(ies_func_owner_decl.srcLoc(mod), msg, "generic function declared here", .{}); | 35866 | try sema.errNote(.{ |
| | 35867 | .base_node_inst = ies_func_owner_decl.zir_decl_index.unwrap().?, |
| | 35868 | .offset = LazySrcLoc.Offset.nodeOffset(0), |
| | 35869 | }, msg, "generic function declared here", .{}); |
| 35949 | break :msg msg; | 35870 | break :msg msg; |
| 35950 | }; | 35871 | }; |
| 35951 | return sema.failWithOwnedErrorMsg(block, msg); | 35872 | return sema.failWithOwnedErrorMsg(block, msg); |
| ... | @@ -36126,7 +36047,7 @@ fn semaStructFields( | ... | @@ -36126,7 +36047,7 @@ fn semaStructFields( |
| 36126 | }, | 36047 | }, |
| 36127 | }; | 36048 | }; |
| 36128 | | 36049 | |
| 36129 | var comptime_err_ret_trace = std.ArrayList(Module.SrcLoc).init(gpa); | 36050 | var comptime_err_ret_trace = std.ArrayList(LazySrcLoc).init(gpa); |
| 36130 | defer comptime_err_ret_trace.deinit(); | 36051 | defer comptime_err_ret_trace.deinit(); |
| 36131 | | 36052 | |
| 36132 | var sema: Sema = .{ | 36053 | var sema: Sema = .{ |
| ... | @@ -36148,11 +36069,12 @@ fn semaStructFields( | ... | @@ -36148,11 +36069,12 @@ fn semaStructFields( |
| 36148 | var block_scope: Block = .{ | 36069 | var block_scope: Block = .{ |
| 36149 | .parent = null, | 36070 | .parent = null, |
| 36150 | .sema = &sema, | 36071 | .sema = &sema, |
| 36151 | .src_decl = decl_index, | | |
| 36152 | .namespace = namespace_index, | 36072 | .namespace = namespace_index, |
| 36153 | .instructions = .{}, | 36073 | .instructions = .{}, |
| 36154 | .inlining = null, | 36074 | .inlining = null, |
| 36155 | .is_comptime = true, | 36075 | .is_comptime = true, |
| | 36076 | .src_base_inst = struct_type.zir_index.unwrap().?, |
| | 36077 | .type_name_ctx = decl.name, |
| 36156 | }; | 36078 | }; |
| 36157 | defer assert(block_scope.instructions.items.len == 0); | 36079 | defer assert(block_scope.instructions.items.len == 0); |
| 36158 | | 36080 | |
| ... | @@ -36231,35 +36153,19 @@ fn semaStructFields( | ... | @@ -36231,35 +36153,19 @@ fn semaStructFields( |
| 36231 | // so that init values may depend on type layout. | 36153 | // so that init values may depend on type layout. |
| 36232 | | 36154 | |
| 36233 | for (fields, 0..) |zir_field, field_i| { | 36155 | for (fields, 0..) |zir_field, field_i| { |
| | 36156 | const ty_src: LazySrcLoc = .{ |
| | 36157 | .base_node_inst = struct_type.zir_index.unwrap().?, |
| | 36158 | .offset = .{ .container_field_type = @intCast(field_i) }, |
| | 36159 | }; |
| 36234 | const field_ty: Type = ty: { | 36160 | const field_ty: Type = ty: { |
| 36235 | if (zir_field.type_ref != .none) { | 36161 | if (zir_field.type_ref != .none) { |
| 36236 | break :ty sema.resolveType(&block_scope, .unneeded, zir_field.type_ref) catch |err| switch (err) { | 36162 | break :ty try sema.resolveType(&block_scope, ty_src, zir_field.type_ref); |
| 36237 | error.NeededSourceLocation => { | | |
| 36238 | const ty_src = mod.fieldSrcLoc(decl_index, .{ | | |
| 36239 | .index = field_i, | | |
| 36240 | .range = .type, | | |
| 36241 | }).lazy; | | |
| 36242 | _ = try sema.resolveType(&block_scope, ty_src, zir_field.type_ref); | | |
| 36243 | unreachable; | | |
| 36244 | }, | | |
| 36245 | else => |e| return e, | | |
| 36246 | }; | | |
| 36247 | } | 36163 | } |
| 36248 | assert(zir_field.type_body_len != 0); | 36164 | assert(zir_field.type_body_len != 0); |
| 36249 | const body = zir.bodySlice(extra_index, zir_field.type_body_len); | 36165 | const body = zir.bodySlice(extra_index, zir_field.type_body_len); |
| 36250 | extra_index += body.len; | 36166 | extra_index += body.len; |
| 36251 | const ty_ref = try sema.resolveInlineBody(&block_scope, body, zir_index); | 36167 | const ty_ref = try sema.resolveInlineBody(&block_scope, body, zir_index); |
| 36252 | break :ty sema.analyzeAsType(&block_scope, .unneeded, ty_ref) catch |err| switch (err) { | 36168 | break :ty try sema.analyzeAsType(&block_scope, ty_src, ty_ref); |
| 36253 | error.NeededSourceLocation => { | | |
| 36254 | const ty_src = mod.fieldSrcLoc(decl_index, .{ | | |
| 36255 | .index = field_i, | | |
| 36256 | .range = .type, | | |
| 36257 | }).lazy; | | |
| 36258 | _ = try sema.analyzeAsType(&block_scope, ty_src, ty_ref); | | |
| 36259 | unreachable; | | |
| 36260 | }, | | |
| 36261 | else => |e| return e, | | |
| 36262 | }; | | |
| 36263 | }; | 36169 | }; |
| 36264 | if (field_ty.isGenericPoison()) { | 36170 | if (field_ty.isGenericPoison()) { |
| 36265 | return error.GenericPoison; | 36171 | return error.GenericPoison; |
| ... | @@ -36269,11 +36175,7 @@ fn semaStructFields( | ... | @@ -36269,11 +36175,7 @@ fn semaStructFields( |
| 36269 | | 36175 | |
| 36270 | if (field_ty.zigTypeTag(mod) == .Opaque) { | 36176 | if (field_ty.zigTypeTag(mod) == .Opaque) { |
| 36271 | const msg = msg: { | 36177 | const msg = msg: { |
| 36272 | const ty_src = mod.fieldSrcLoc(decl_index, .{ | 36178 | const msg = try sema.errMsg(ty_src, "opaque types have unknown size and therefore cannot be directly embedded in structs", .{}); |
| 36273 | .index = field_i, | | |
| 36274 | .range = .type, | | |
| 36275 | }).lazy; | | |
| 36276 | const msg = try sema.errMsg(&block_scope, ty_src, "opaque types have unknown size and therefore cannot be directly embedded in structs", .{}); | | |
| 36277 | errdefer msg.destroy(sema.gpa); | 36179 | errdefer msg.destroy(sema.gpa); |
| 36278 | | 36180 | |
| 36279 | try sema.addDeclaredHereNote(msg, field_ty); | 36181 | try sema.addDeclaredHereNote(msg, field_ty); |
| ... | @@ -36283,11 +36185,7 @@ fn semaStructFields( | ... | @@ -36283,11 +36185,7 @@ fn semaStructFields( |
| 36283 | } | 36185 | } |
| 36284 | if (field_ty.zigTypeTag(mod) == .NoReturn) { | 36186 | if (field_ty.zigTypeTag(mod) == .NoReturn) { |
| 36285 | const msg = msg: { | 36187 | const msg = msg: { |
| 36286 | const ty_src = mod.fieldSrcLoc(decl_index, .{ | 36188 | const msg = try sema.errMsg(ty_src, "struct fields cannot be 'noreturn'", .{}); |
| 36287 | .index = field_i, | | |
| 36288 | .range = .type, | | |
| 36289 | }).lazy; | | |
| 36290 | const msg = try sema.errMsg(&block_scope, ty_src, "struct fields cannot be 'noreturn'", .{}); | | |
| 36291 | errdefer msg.destroy(sema.gpa); | 36189 | errdefer msg.destroy(sema.gpa); |
| 36292 | | 36190 | |
| 36293 | try sema.addDeclaredHereNote(msg, field_ty); | 36191 | try sema.addDeclaredHereNote(msg, field_ty); |
| ... | @@ -36298,11 +36196,7 @@ fn semaStructFields( | ... | @@ -36298,11 +36196,7 @@ fn semaStructFields( |
| 36298 | switch (struct_type.layout) { | 36196 | switch (struct_type.layout) { |
| 36299 | .@"extern" => if (!try sema.validateExternType(field_ty, .struct_field)) { | 36197 | .@"extern" => if (!try sema.validateExternType(field_ty, .struct_field)) { |
| 36300 | const msg = msg: { | 36198 | const msg = msg: { |
| 36301 | const ty_src = mod.fieldSrcLoc(decl_index, .{ | 36199 | const msg = try sema.errMsg(ty_src, "extern structs cannot contain fields of type '{}'", .{field_ty.fmt(mod)}); |
| 36302 | .index = field_i, | | |
| 36303 | .range = .type, | | |
| 36304 | }); | | |
| 36305 | const msg = try sema.errMsg(&block_scope, ty_src.lazy, "extern structs cannot contain fields of type '{}'", .{field_ty.fmt(mod)}); | | |
| 36306 | errdefer msg.destroy(sema.gpa); | 36200 | errdefer msg.destroy(sema.gpa); |
| 36307 | | 36201 | |
| 36308 | try sema.explainWhyTypeIsNotExtern(msg, ty_src, field_ty, .struct_field); | 36202 | try sema.explainWhyTypeIsNotExtern(msg, ty_src, field_ty, .struct_field); |
| ... | @@ -36314,11 +36208,7 @@ fn semaStructFields( | ... | @@ -36314,11 +36208,7 @@ fn semaStructFields( |
| 36314 | }, | 36208 | }, |
| 36315 | .@"packed" => if (!try sema.validatePackedType(field_ty)) { | 36209 | .@"packed" => if (!try sema.validatePackedType(field_ty)) { |
| 36316 | const msg = msg: { | 36210 | const msg = msg: { |
| 36317 | const ty_src = mod.fieldSrcLoc(decl_index, .{ | 36211 | const msg = try sema.errMsg(ty_src, "packed structs cannot contain fields of type '{}'", .{field_ty.fmt(mod)}); |
| 36318 | .index = field_i, | | |
| 36319 | .range = .type, | | |
| 36320 | }); | | |
| 36321 | const msg = try sema.errMsg(&block_scope, ty_src.lazy, "packed structs cannot contain fields of type '{}'", .{field_ty.fmt(mod)}); | | |
| 36322 | errdefer msg.destroy(sema.gpa); | 36212 | errdefer msg.destroy(sema.gpa); |
| 36323 | | 36213 | |
| 36324 | try sema.explainWhyTypeIsNotPacked(msg, ty_src, field_ty); | 36214 | try sema.explainWhyTypeIsNotPacked(msg, ty_src, field_ty); |
| ... | @@ -36335,17 +36225,11 @@ fn semaStructFields( | ... | @@ -36335,17 +36225,11 @@ fn semaStructFields( |
| 36335 | const body = zir.bodySlice(extra_index, zir_field.align_body_len); | 36225 | const body = zir.bodySlice(extra_index, zir_field.align_body_len); |
| 36336 | extra_index += body.len; | 36226 | extra_index += body.len; |
| 36337 | const align_ref = try sema.resolveInlineBody(&block_scope, body, zir_index); | 36227 | const align_ref = try sema.resolveInlineBody(&block_scope, body, zir_index); |
| 36338 | const field_align = sema.analyzeAsAlign(&block_scope, .unneeded, align_ref) catch |err| switch (err) { | 36228 | const align_src: LazySrcLoc = .{ |
| 36339 | error.NeededSourceLocation => { | 36229 | .base_node_inst = struct_type.zir_index.unwrap().?, |
| 36340 | const align_src = mod.fieldSrcLoc(decl_index, .{ | 36230 | .offset = .{ .container_field_align = @intCast(field_i) }, |
| 36341 | .index = field_i, | | |
| 36342 | .range = .alignment, | | |
| 36343 | }).lazy; | | |
| 36344 | _ = try sema.analyzeAsAlign(&block_scope, align_src, align_ref); | | |
| 36345 | unreachable; | | |
| 36346 | }, | | |
| 36347 | else => |e| return e, | | |
| 36348 | }; | 36231 | }; |
| | 36232 | const field_align = try sema.analyzeAsAlign(&block_scope, align_src, align_ref); |
| 36349 | struct_type.field_aligns.get(ip)[field_i] = field_align; | 36233 | struct_type.field_aligns.get(ip)[field_i] = field_align; |
| 36350 | } | 36234 | } |
| 36351 | | 36235 | |
| ... | @@ -36374,7 +36258,7 @@ fn semaStructFieldInits( | ... | @@ -36374,7 +36258,7 @@ fn semaStructFieldInits( |
| 36374 | const zir_index = struct_type.zir_index.unwrap().?.resolve(ip); | 36258 | const zir_index = struct_type.zir_index.unwrap().?.resolve(ip); |
| 36375 | const fields_len, const small, var extra_index = structZirInfo(zir, zir_index); | 36259 | const fields_len, const small, var extra_index = structZirInfo(zir, zir_index); |
| 36376 | | 36260 | |
| 36377 | var comptime_err_ret_trace = std.ArrayList(Module.SrcLoc).init(gpa); | 36261 | var comptime_err_ret_trace = std.ArrayList(LazySrcLoc).init(gpa); |
| 36378 | defer comptime_err_ret_trace.deinit(); | 36262 | defer comptime_err_ret_trace.deinit(); |
| 36379 | | 36263 | |
| 36380 | var sema: Sema = .{ | 36264 | var sema: Sema = .{ |
| ... | @@ -36396,11 +36280,12 @@ fn semaStructFieldInits( | ... | @@ -36396,11 +36280,12 @@ fn semaStructFieldInits( |
| 36396 | var block_scope: Block = .{ | 36280 | var block_scope: Block = .{ |
| 36397 | .parent = null, | 36281 | .parent = null, |
| 36398 | .sema = &sema, | 36282 | .sema = &sema, |
| 36399 | .src_decl = decl_index, | | |
| 36400 | .namespace = namespace_index, | 36283 | .namespace = namespace_index, |
| 36401 | .instructions = .{}, | 36284 | .instructions = .{}, |
| 36402 | .inlining = null, | 36285 | .inlining = null, |
| 36403 | .is_comptime = true, | 36286 | .is_comptime = true, |
| | 36287 | .src_base_inst = struct_type.zir_index.unwrap().?, |
| | 36288 | .type_name_ctx = decl.name, |
| 36404 | }; | 36289 | }; |
| 36405 | defer assert(block_scope.instructions.items.len == 0); | 36290 | defer assert(block_scope.instructions.items.len == 0); |
| 36406 | | 36291 | |
| ... | @@ -36474,33 +36359,20 @@ fn semaStructFieldInits( | ... | @@ -36474,33 +36359,20 @@ fn semaStructFieldInits( |
| 36474 | try sema.inst_map.ensureSpaceForInstructions(sema.gpa, &.{zir_index}); | 36359 | try sema.inst_map.ensureSpaceForInstructions(sema.gpa, &.{zir_index}); |
| 36475 | sema.inst_map.putAssumeCapacity(zir_index, type_ref); | 36360 | sema.inst_map.putAssumeCapacity(zir_index, type_ref); |
| 36476 | | 36361 | |
| 36477 | const init = try sema.resolveInlineBody(&block_scope, body, zir_index); | 36362 | const init_src: LazySrcLoc = .{ |
| 36478 | const coerced = sema.coerce(&block_scope, field_ty, init, .unneeded) catch |err| switch (err) { | 36363 | .base_node_inst = struct_type.zir_index.unwrap().?, |
| 36479 | error.NeededSourceLocation => { | 36364 | .offset = .{ .container_field_value = @intCast(field_i) }, |
| 36480 | const init_src = mod.fieldSrcLoc(decl_index, .{ | | |
| 36481 | .index = field_i, | | |
| 36482 | .range = .value, | | |
| 36483 | }).lazy; | | |
| 36484 | _ = try sema.coerce(&block_scope, field_ty, init, init_src); | | |
| 36485 | unreachable; | | |
| 36486 | }, | | |
| 36487 | else => |e| return e, | | |
| 36488 | }; | 36365 | }; |
| 36489 | const default_val = (try sema.resolveValue(coerced)) orelse { | 36366 | |
| 36490 | const init_src = mod.fieldSrcLoc(decl_index, .{ | 36367 | const init = try sema.resolveInlineBody(&block_scope, body, zir_index); |
| 36491 | .index = field_i, | 36368 | const coerced = try sema.coerce(&block_scope, field_ty, init, init_src); |
| 36492 | .range = .value, | 36369 | const default_val = try sema.resolveValue(coerced) orelse { |
| 36493 | }).lazy; | | |
| 36494 | return sema.failWithNeededComptime(&block_scope, init_src, .{ | 36370 | return sema.failWithNeededComptime(&block_scope, init_src, .{ |
| 36495 | .needed_comptime_reason = "struct field default value must be comptime-known", | 36371 | .needed_comptime_reason = "struct field default value must be comptime-known", |
| 36496 | }); | 36372 | }); |
| 36497 | }; | 36373 | }; |
| 36498 | | 36374 | |
| 36499 | if (default_val.canMutateComptimeVarState(mod)) { | 36375 | if (default_val.canMutateComptimeVarState(mod)) { |
| 36500 | const init_src = mod.fieldSrcLoc(decl_index, .{ | | |
| 36501 | .index = field_i, | | |
| 36502 | .range = .value, | | |
| 36503 | }).lazy; | | |
| 36504 | return sema.fail(&block_scope, init_src, "field default value contains reference to comptime-mutable memory", .{}); | 36376 | return sema.fail(&block_scope, init_src, "field default value contains reference to comptime-mutable memory", .{}); |
| 36505 | } | 36377 | } |
| 36506 | struct_type.field_inits.get(ip)[field_i] = default_val.toIntern(); | 36378 | struct_type.field_inits.get(ip)[field_i] = default_val.toIntern(); |
| ... | @@ -36520,9 +36392,8 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded | ... | @@ -36520,9 +36392,8 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded |
| 36520 | const extended = zir.instructions.items(.data)[@intFromEnum(zir_index)].extended; | 36392 | const extended = zir.instructions.items(.data)[@intFromEnum(zir_index)].extended; |
| 36521 | assert(extended.opcode == .union_decl); | 36393 | assert(extended.opcode == .union_decl); |
| 36522 | const small: Zir.Inst.UnionDecl.Small = @bitCast(extended.small); | 36394 | const small: Zir.Inst.UnionDecl.Small = @bitCast(extended.small); |
| 36523 | var extra_index: usize = extended.operand + @typeInfo(Zir.Inst.UnionDecl).Struct.fields.len; | 36395 | const extra = zir.extraData(Zir.Inst.UnionDecl, extended.operand); |
| 36524 | | 36396 | var extra_index: usize = extra.end; |
| 36525 | const src = LazySrcLoc.nodeOffset(0); | | |
| 36526 | | 36397 | |
| 36527 | const tag_type_ref: Zir.Inst.Ref = if (small.has_tag_type) blk: { | 36398 | const tag_type_ref: Zir.Inst.Ref = if (small.has_tag_type) blk: { |
| 36528 | const ty_ref: Zir.Inst.Ref = @enumFromInt(zir.extra[extra_index]); | 36399 | const ty_ref: Zir.Inst.Ref = @enumFromInt(zir.extra[extra_index]); |
| ... | @@ -36562,7 +36433,7 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded | ... | @@ -36562,7 +36433,7 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded |
| 36562 | | 36433 | |
| 36563 | const decl = mod.declPtr(decl_index); | 36434 | const decl = mod.declPtr(decl_index); |
| 36564 | | 36435 | |
| 36565 | var comptime_err_ret_trace = std.ArrayList(Module.SrcLoc).init(gpa); | 36436 | var comptime_err_ret_trace = std.ArrayList(LazySrcLoc).init(gpa); |
| 36566 | defer comptime_err_ret_trace.deinit(); | 36437 | defer comptime_err_ret_trace.deinit(); |
| 36567 | | 36438 | |
| 36568 | var sema: Sema = .{ | 36439 | var sema: Sema = .{ |
| ... | @@ -36584,14 +36455,17 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded | ... | @@ -36584,14 +36455,17 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded |
| 36584 | var block_scope: Block = .{ | 36455 | var block_scope: Block = .{ |
| 36585 | .parent = null, | 36456 | .parent = null, |
| 36586 | .sema = &sema, | 36457 | .sema = &sema, |
| 36587 | .src_decl = decl_index, | | |
| 36588 | .namespace = union_type.namespace.unwrap().?, | 36458 | .namespace = union_type.namespace.unwrap().?, |
| 36589 | .instructions = .{}, | 36459 | .instructions = .{}, |
| 36590 | .inlining = null, | 36460 | .inlining = null, |
| 36591 | .is_comptime = true, | 36461 | .is_comptime = true, |
| | 36462 | .src_base_inst = union_type.zir_index, |
| | 36463 | .type_name_ctx = decl.name, |
| 36592 | }; | 36464 | }; |
| 36593 | defer assert(block_scope.instructions.items.len == 0); | 36465 | defer assert(block_scope.instructions.items.len == 0); |
| 36594 | | 36466 | |
| | 36467 | const src = block_scope.nodeOffset(0); |
| | 36468 | |
| 36595 | if (body.len != 0) { | 36469 | if (body.len != 0) { |
| 36596 | _ = try sema.analyzeInlineBody(&block_scope, body, zir_index); | 36470 | _ = try sema.analyzeInlineBody(&block_scope, body, zir_index); |
| 36597 | } | 36471 | } |
| ... | @@ -36601,7 +36475,10 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded | ... | @@ -36601,7 +36475,10 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded |
| 36601 | var enum_field_vals: std.AutoArrayHashMapUnmanaged(InternPool.Index, void) = .{}; | 36475 | var enum_field_vals: std.AutoArrayHashMapUnmanaged(InternPool.Index, void) = .{}; |
| 36602 | var explicit_tags_seen: []bool = &.{}; | 36476 | var explicit_tags_seen: []bool = &.{}; |
| 36603 | if (tag_type_ref != .none) { | 36477 | if (tag_type_ref != .none) { |
| 36604 | const tag_ty_src: LazySrcLoc = .{ .node_offset_container_tag = src.node_offset.x }; | 36478 | const tag_ty_src: LazySrcLoc = .{ |
| | 36479 | .base_node_inst = union_type.zir_index, |
| | 36480 | .offset = .{ .node_offset_container_tag = 0 }, |
| | 36481 | }; |
| 36605 | const provided_ty = try sema.resolveType(&block_scope, tag_ty_src, tag_type_ref); | 36482 | const provided_ty = try sema.resolveType(&block_scope, tag_ty_src, tag_type_ref); |
| 36606 | if (small.auto_enum_tag) { | 36483 | if (small.auto_enum_tag) { |
| 36607 | // The provided type is an integer type and we must construct the enum tag type here. | 36484 | // The provided type is an integer type and we must construct the enum tag type here. |
| ... | @@ -36614,9 +36491,9 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded | ... | @@ -36614,9 +36491,9 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded |
| 36614 | const field_count_val = try mod.intValue(Type.comptime_int, fields_len - 1); | 36491 | const field_count_val = try mod.intValue(Type.comptime_int, fields_len - 1); |
| 36615 | if (!(try sema.intFitsInType(field_count_val, int_tag_ty, null))) { | 36492 | if (!(try sema.intFitsInType(field_count_val, int_tag_ty, null))) { |
| 36616 | const msg = msg: { | 36493 | const msg = msg: { |
| 36617 | const msg = try sema.errMsg(&block_scope, tag_ty_src, "specified integer tag type cannot represent every field", .{}); | 36494 | const msg = try sema.errMsg(tag_ty_src, "specified integer tag type cannot represent every field", .{}); |
| 36618 | errdefer msg.destroy(sema.gpa); | 36495 | errdefer msg.destroy(sema.gpa); |
| 36619 | try sema.errNote(&block_scope, tag_ty_src, msg, "type '{}' cannot fit values in range 0...{d}", .{ | 36496 | try sema.errNote(tag_ty_src, msg, "type '{}' cannot fit values in range 0...{d}", .{ |
| 36620 | int_tag_ty.fmt(mod), | 36497 | int_tag_ty.fmt(mod), |
| 36621 | fields_len - 1, | 36498 | fields_len - 1, |
| 36622 | }); | 36499 | }); |
| ... | @@ -36701,19 +36578,26 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded | ... | @@ -36701,19 +36578,26 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded |
| 36701 | break :blk try sema.resolveInst(tag_ref); | 36578 | break :blk try sema.resolveInst(tag_ref); |
| 36702 | } else .none; | 36579 | } else .none; |
| 36703 | | 36580 | |
| | 36581 | const name_src: LazySrcLoc = .{ |
| | 36582 | .base_node_inst = union_type.zir_index, |
| | 36583 | .offset = .{ .container_field_name = field_i }, |
| | 36584 | }; |
| | 36585 | const value_src: LazySrcLoc = .{ |
| | 36586 | .base_node_inst = union_type.zir_index, |
| | 36587 | .offset = .{ .container_field_value = field_i }, |
| | 36588 | }; |
| | 36589 | const align_src: LazySrcLoc = .{ |
| | 36590 | .base_node_inst = union_type.zir_index, |
| | 36591 | .offset = .{ .container_field_align = field_i }, |
| | 36592 | }; |
| | 36593 | const type_src: LazySrcLoc = .{ |
| | 36594 | .base_node_inst = union_type.zir_index, |
| | 36595 | .offset = .{ .container_field_type = field_i }, |
| | 36596 | }; |
| | 36597 | |
| 36704 | if (enum_field_vals.capacity() > 0) { | 36598 | if (enum_field_vals.capacity() > 0) { |
| 36705 | const enum_tag_val = if (tag_ref != .none) blk: { | 36599 | const enum_tag_val = if (tag_ref != .none) blk: { |
| 36706 | const val = sema.semaUnionFieldVal(&block_scope, .unneeded, int_tag_ty, tag_ref) catch |err| switch (err) { | 36600 | const val = try sema.semaUnionFieldVal(&block_scope, value_src, int_tag_ty, tag_ref); |
| 36707 | error.NeededSourceLocation => { | | |
| 36708 | const val_src = mod.fieldSrcLoc(union_type.decl, .{ | | |
| 36709 | .index = field_i, | | |
| 36710 | .range = .value, | | |
| 36711 | }).lazy; | | |
| 36712 | _ = try sema.semaUnionFieldVal(&block_scope, val_src, int_tag_ty, tag_ref); | | |
| 36713 | unreachable; | | |
| 36714 | }, | | |
| 36715 | else => |e| return e, | | |
| 36716 | }; | | |
| 36717 | last_tag_val = val; | 36601 | last_tag_val = val; |
| 36718 | | 36602 | |
| 36719 | break :blk val; | 36603 | break :blk val; |
| ... | @@ -36728,12 +36612,14 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded | ... | @@ -36728,12 +36612,14 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded |
| 36728 | }; | 36612 | }; |
| 36729 | const gop = enum_field_vals.getOrPutAssumeCapacity(enum_tag_val.toIntern()); | 36613 | const gop = enum_field_vals.getOrPutAssumeCapacity(enum_tag_val.toIntern()); |
| 36730 | if (gop.found_existing) { | 36614 | if (gop.found_existing) { |
| 36731 | const field_src = mod.fieldSrcLoc(union_type.decl, .{ .index = field_i }).lazy; | 36615 | const other_value_src: LazySrcLoc = .{ |
| 36732 | const other_field_src = mod.fieldSrcLoc(union_type.decl, .{ .index = gop.index }).lazy; | 36616 | .base_node_inst = union_type.zir_index, |
| | 36617 | .offset = .{ .container_field_value = @intCast(gop.index) }, |
| | 36618 | }; |
| 36733 | const msg = msg: { | 36619 | const msg = msg: { |
| 36734 | const msg = try sema.errMsg(&block_scope, field_src, "enum tag value {} already taken", .{enum_tag_val.fmtValue(mod, &sema)}); | 36620 | const msg = try sema.errMsg(value_src, "enum tag value {} already taken", .{enum_tag_val.fmtValue(mod, &sema)}); |
| 36735 | errdefer msg.destroy(gpa); | 36621 | errdefer msg.destroy(gpa); |
| 36736 | try sema.errNote(&block_scope, other_field_src, msg, "other occurrence here", .{}); | 36622 | try sema.errNote(other_value_src, msg, "other occurrence here", .{}); |
| 36737 | break :msg msg; | 36623 | break :msg msg; |
| 36738 | }; | 36624 | }; |
| 36739 | return sema.failWithOwnedErrorMsg(&block_scope, msg); | 36625 | return sema.failWithOwnedErrorMsg(&block_scope, msg); |
| ... | @@ -36751,17 +36637,7 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded | ... | @@ -36751,17 +36637,7 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded |
| 36751 | else if (field_type_ref == .none) | 36637 | else if (field_type_ref == .none) |
| 36752 | Type.noreturn | 36638 | Type.noreturn |
| 36753 | else | 36639 | else |
| 36754 | sema.resolveType(&block_scope, .unneeded, field_type_ref) catch |err| switch (err) { | 36640 | try sema.resolveType(&block_scope, type_src, field_type_ref); |
| 36755 | error.NeededSourceLocation => { | | |
| 36756 | const ty_src = mod.fieldSrcLoc(union_type.decl, .{ | | |
| 36757 | .index = field_i, | | |
| 36758 | .range = .type, | | |
| 36759 | }).lazy; | | |
| 36760 | _ = try sema.resolveType(&block_scope, ty_src, field_type_ref); | | |
| 36761 | unreachable; | | |
| 36762 | }, | | |
| 36763 | else => |e| return e, | | |
| 36764 | }; | | |
| 36765 | | 36641 | |
| 36766 | if (field_ty.isGenericPoison()) { | 36642 | if (field_ty.isGenericPoison()) { |
| 36767 | return error.GenericPoison; | 36643 | return error.GenericPoison; |
| ... | @@ -36770,11 +36646,7 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded | ... | @@ -36770,11 +36646,7 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded |
| 36770 | if (explicit_tags_seen.len > 0) { | 36646 | if (explicit_tags_seen.len > 0) { |
| 36771 | const tag_info = ip.loadEnumType(union_type.tagTypePtr(ip).*); | 36647 | const tag_info = ip.loadEnumType(union_type.tagTypePtr(ip).*); |
| 36772 | const enum_index = tag_info.nameIndex(ip, field_name) orelse { | 36648 | const enum_index = tag_info.nameIndex(ip, field_name) orelse { |
| 36773 | const ty_src = mod.fieldSrcLoc(union_type.decl, .{ | 36649 | return sema.fail(&block_scope, name_src, "no field named '{}' in enum '{}'", .{ |
| 36774 | .index = field_i, | | |
| 36775 | .range = .name, | | |
| 36776 | }).lazy; | | |
| 36777 | return sema.fail(&block_scope, ty_src, "no field named '{}' in enum '{}'", .{ | | |
| 36778 | field_name.fmt(ip), Type.fromInterned(union_type.tagTypePtr(ip).*).fmt(mod), | 36650 | field_name.fmt(ip), Type.fromInterned(union_type.tagTypePtr(ip).*).fmt(mod), |
| 36779 | }); | 36651 | }); |
| 36780 | }; | 36652 | }; |
| ... | @@ -36787,17 +36659,15 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded | ... | @@ -36787,17 +36659,15 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded |
| 36787 | // Enforce the enum fields and the union fields being in the same order. | 36659 | // Enforce the enum fields and the union fields being in the same order. |
| 36788 | if (enum_index != field_i) { | 36660 | if (enum_index != field_i) { |
| 36789 | const msg = msg: { | 36661 | const msg = msg: { |
| 36790 | const ty_src = mod.fieldSrcLoc(union_type.decl, .{ | 36662 | const enum_field_src: LazySrcLoc = .{ |
| 36791 | .index = field_i, | 36663 | .base_node_inst = tag_info.zir_index.unwrap().?, |
| 36792 | .range = .name, | 36664 | .offset = .{ .container_field_name = enum_index }, |
| 36793 | }).lazy; | 36665 | }; |
| 36794 | const enum_field_src = mod.fieldSrcLoc(tag_info.decl, .{ .index = enum_index }).lazy; | 36666 | const msg = try sema.errMsg(name_src, "union field '{}' ordered differently than corresponding enum field", .{ |
| 36795 | const msg = try sema.errMsg(&block_scope, ty_src, "union field '{}' ordered differently than corresponding enum field", .{ | | |
| 36796 | field_name.fmt(ip), | 36667 | field_name.fmt(ip), |
| 36797 | }); | 36668 | }); |
| 36798 | errdefer msg.destroy(sema.gpa); | 36669 | errdefer msg.destroy(sema.gpa); |
| 36799 | const decl_ptr = mod.declPtr(tag_info.decl); | 36670 | try sema.errNote(enum_field_src, msg, "enum field here", .{}); |
| 36800 | try mod.errNoteNonLazy(decl_ptr.toSrcLoc(enum_field_src, mod), msg, "enum field here", .{}); | | |
| 36801 | break :msg msg; | 36671 | break :msg msg; |
| 36802 | }; | 36672 | }; |
| 36803 | return sema.failWithOwnedErrorMsg(&block_scope, msg); | 36673 | return sema.failWithOwnedErrorMsg(&block_scope, msg); |
| ... | @@ -36806,11 +36676,7 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded | ... | @@ -36806,11 +36676,7 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded |
| 36806 | | 36676 | |
| 36807 | if (field_ty.zigTypeTag(mod) == .Opaque) { | 36677 | if (field_ty.zigTypeTag(mod) == .Opaque) { |
| 36808 | const msg = msg: { | 36678 | const msg = msg: { |
| 36809 | const ty_src = mod.fieldSrcLoc(union_type.decl, .{ | 36679 | const msg = try sema.errMsg(type_src, "opaque types have unknown size and therefore cannot be directly embedded in unions", .{}); |
| 36810 | .index = field_i, | | |
| 36811 | .range = .type, | | |
| 36812 | }).lazy; | | |
| 36813 | const msg = try sema.errMsg(&block_scope, ty_src, "opaque types have unknown size and therefore cannot be directly embedded in unions", .{}); | | |
| 36814 | errdefer msg.destroy(sema.gpa); | 36680 | errdefer msg.destroy(sema.gpa); |
| 36815 | | 36681 | |
| 36816 | try sema.addDeclaredHereNote(msg, field_ty); | 36682 | try sema.addDeclaredHereNote(msg, field_ty); |
| ... | @@ -36823,14 +36689,10 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded | ... | @@ -36823,14 +36689,10 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded |
| 36823 | !try sema.validateExternType(field_ty, .union_field)) | 36689 | !try sema.validateExternType(field_ty, .union_field)) |
| 36824 | { | 36690 | { |
| 36825 | const msg = msg: { | 36691 | const msg = msg: { |
| 36826 | const ty_src = mod.fieldSrcLoc(union_type.decl, .{ | 36692 | const msg = try sema.errMsg(type_src, "extern unions cannot contain fields of type '{}'", .{field_ty.fmt(mod)}); |
| 36827 | .index = field_i, | | |
| 36828 | .range = .type, | | |
| 36829 | }); | | |
| 36830 | const msg = try sema.errMsg(&block_scope, ty_src.lazy, "extern unions cannot contain fields of type '{}'", .{field_ty.fmt(mod)}); | | |
| 36831 | errdefer msg.destroy(sema.gpa); | 36693 | errdefer msg.destroy(sema.gpa); |
| 36832 | | 36694 | |
| 36833 | try sema.explainWhyTypeIsNotExtern(msg, ty_src, field_ty, .union_field); | 36695 | try sema.explainWhyTypeIsNotExtern(msg, type_src, field_ty, .union_field); |
| 36834 | | 36696 | |
| 36835 | try sema.addDeclaredHereNote(msg, field_ty); | 36697 | try sema.addDeclaredHereNote(msg, field_ty); |
| 36836 | break :msg msg; | 36698 | break :msg msg; |
| ... | @@ -36838,14 +36700,10 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded | ... | @@ -36838,14 +36700,10 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded |
| 36838 | return sema.failWithOwnedErrorMsg(&block_scope, msg); | 36700 | return sema.failWithOwnedErrorMsg(&block_scope, msg); |
| 36839 | } else if (layout == .@"packed" and !try sema.validatePackedType(field_ty)) { | 36701 | } else if (layout == .@"packed" and !try sema.validatePackedType(field_ty)) { |
| 36840 | const msg = msg: { | 36702 | const msg = msg: { |
| 36841 | const ty_src = mod.fieldSrcLoc(union_type.decl, .{ | 36703 | const msg = try sema.errMsg(type_src, "packed unions cannot contain fields of type '{}'", .{field_ty.fmt(mod)}); |
| 36842 | .index = field_i, | | |
| 36843 | .range = .type, | | |
| 36844 | }); | | |
| 36845 | const msg = try sema.errMsg(&block_scope, ty_src.lazy, "packed unions cannot contain fields of type '{}'", .{field_ty.fmt(mod)}); | | |
| 36846 | errdefer msg.destroy(sema.gpa); | 36704 | errdefer msg.destroy(sema.gpa); |
| 36847 | | 36705 | |
| 36848 | try sema.explainWhyTypeIsNotPacked(msg, ty_src, field_ty); | 36706 | try sema.explainWhyTypeIsNotPacked(msg, type_src, field_ty); |
| 36849 | | 36707 | |
| 36850 | try sema.addDeclaredHereNote(msg, field_ty); | 36708 | try sema.addDeclaredHereNote(msg, field_ty); |
| 36851 | break :msg msg; | 36709 | break :msg msg; |
| ... | @@ -36857,17 +36715,7 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded | ... | @@ -36857,17 +36715,7 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded |
| 36857 | | 36715 | |
| 36858 | if (small.any_aligned_fields) { | 36716 | if (small.any_aligned_fields) { |
| 36859 | field_aligns.appendAssumeCapacity(if (align_ref != .none) | 36717 | field_aligns.appendAssumeCapacity(if (align_ref != .none) |
| 36860 | sema.resolveAlign(&block_scope, .unneeded, align_ref) catch |err| switch (err) { | 36718 | try sema.resolveAlign(&block_scope, align_src, align_ref) |
| 36861 | error.NeededSourceLocation => { | | |
| 36862 | const align_src = mod.fieldSrcLoc(union_type.decl, .{ | | |
| 36863 | .index = field_i, | | |
| 36864 | .range = .alignment, | | |
| 36865 | }).lazy; | | |
| 36866 | _ = try sema.resolveAlign(&block_scope, align_src, align_ref); | | |
| 36867 | unreachable; | | |
| 36868 | }, | | |
| 36869 | else => |e| return e, | | |
| 36870 | } | | |
| 36871 | else | 36719 | else |
| 36872 | .none); | 36720 | .none); |
| 36873 | } else { | 36721 | } else { |
| ... | @@ -36882,7 +36730,7 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded | ... | @@ -36882,7 +36730,7 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded |
| 36882 | const tag_info = ip.loadEnumType(union_type.tagTypePtr(ip).*); | 36730 | const tag_info = ip.loadEnumType(union_type.tagTypePtr(ip).*); |
| 36883 | if (tag_info.names.len > fields_len) { | 36731 | if (tag_info.names.len > fields_len) { |
| 36884 | const msg = msg: { | 36732 | const msg = msg: { |
| 36885 | const msg = try sema.errMsg(&block_scope, src, "enum field(s) missing in union", .{}); | 36733 | const msg = try sema.errMsg(src, "enum field(s) missing in union", .{}); |
| 36886 | errdefer msg.destroy(sema.gpa); | 36734 | errdefer msg.destroy(sema.gpa); |
| 36887 | | 36735 | |
| 36888 | for (tag_info.names.get(ip), 0..) |field_name, field_index| { | 36736 | for (tag_info.names.get(ip), 0..) |field_name, field_index| { |
| ... | @@ -36897,10 +36745,10 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded | ... | @@ -36897,10 +36745,10 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded |
| 36897 | return sema.failWithOwnedErrorMsg(&block_scope, msg); | 36745 | return sema.failWithOwnedErrorMsg(&block_scope, msg); |
| 36898 | } | 36746 | } |
| 36899 | } else if (enum_field_vals.count() > 0) { | 36747 | } else if (enum_field_vals.count() > 0) { |
| 36900 | const enum_ty = try sema.generateUnionTagTypeNumbered(&block_scope, enum_field_names, enum_field_vals.keys(), mod.declPtr(union_type.decl)); | 36748 | const enum_ty = try sema.generateUnionTagTypeNumbered(&block_scope, enum_field_names, enum_field_vals.keys(), mod.declPtr(union_type.decl), extra.data.src_line); |
| 36901 | union_type.tagTypePtr(ip).* = enum_ty; | 36749 | union_type.tagTypePtr(ip).* = enum_ty; |
| 36902 | } else { | 36750 | } else { |
| 36903 | const enum_ty = try sema.generateUnionTagTypeSimple(&block_scope, enum_field_names, mod.declPtr(union_type.decl)); | 36751 | const enum_ty = try sema.generateUnionTagTypeSimple(&block_scope, enum_field_names, mod.declPtr(union_type.decl), extra.data.src_line); |
| 36904 | union_type.tagTypePtr(ip).* = enum_ty; | 36752 | union_type.tagTypePtr(ip).* = enum_ty; |
| 36905 | } | 36753 | } |
| 36906 | } | 36754 | } |
| ... | @@ -36918,13 +36766,13 @@ fn generateUnionTagTypeNumbered( | ... | @@ -36918,13 +36766,13 @@ fn generateUnionTagTypeNumbered( |
| 36918 | enum_field_names: []const InternPool.NullTerminatedString, | 36766 | enum_field_names: []const InternPool.NullTerminatedString, |
| 36919 | enum_field_vals: []const InternPool.Index, | 36767 | enum_field_vals: []const InternPool.Index, |
| 36920 | union_owner_decl: *Module.Decl, | 36768 | union_owner_decl: *Module.Decl, |
| | 36769 | src_line: u32, |
| 36921 | ) !InternPool.Index { | 36770 | ) !InternPool.Index { |
| 36922 | const mod = sema.mod; | 36771 | const mod = sema.mod; |
| 36923 | const gpa = sema.gpa; | 36772 | const gpa = sema.gpa; |
| 36924 | const ip = &mod.intern_pool; | 36773 | const ip = &mod.intern_pool; |
| 36925 | | 36774 | |
| 36926 | const src_decl = mod.declPtr(block.src_decl); | 36775 | const new_decl_index = try mod.allocateNewDecl(block.namespace); |
| 36927 | const new_decl_index = try mod.allocateNewDecl(block.namespace, src_decl.src_node); | | |
| 36928 | errdefer mod.destroyDecl(new_decl_index); | 36776 | errdefer mod.destroyDecl(new_decl_index); |
| 36929 | const fqn = try union_owner_decl.fullyQualifiedName(mod); | 36777 | const fqn = try union_owner_decl.fullyQualifiedName(mod); |
| 36930 | const name = try ip.getOrPutStringFmt( | 36778 | const name = try ip.getOrPutStringFmt( |
| ... | @@ -36935,7 +36783,7 @@ fn generateUnionTagTypeNumbered( | ... | @@ -36935,7 +36783,7 @@ fn generateUnionTagTypeNumbered( |
| 36935 | ); | 36783 | ); |
| 36936 | try mod.initNewAnonDecl( | 36784 | try mod.initNewAnonDecl( |
| 36937 | new_decl_index, | 36785 | new_decl_index, |
| 36938 | src_decl.src_line, | 36786 | src_line, |
| 36939 | Value.@"unreachable", | 36787 | Value.@"unreachable", |
| 36940 | name, | 36788 | name, |
| 36941 | ); | 36789 | ); |
| ... | @@ -36968,6 +36816,7 @@ fn generateUnionTagTypeSimple( | ... | @@ -36968,6 +36816,7 @@ fn generateUnionTagTypeSimple( |
| 36968 | block: *Block, | 36816 | block: *Block, |
| 36969 | enum_field_names: []const InternPool.NullTerminatedString, | 36817 | enum_field_names: []const InternPool.NullTerminatedString, |
| 36970 | union_owner_decl: *Module.Decl, | 36818 | union_owner_decl: *Module.Decl, |
| | 36819 | src_line: u32, |
| 36971 | ) !InternPool.Index { | 36820 | ) !InternPool.Index { |
| 36972 | const mod = sema.mod; | 36821 | const mod = sema.mod; |
| 36973 | const ip = &mod.intern_pool; | 36822 | const ip = &mod.intern_pool; |
| ... | @@ -36975,8 +36824,7 @@ fn generateUnionTagTypeSimple( | ... | @@ -36975,8 +36824,7 @@ fn generateUnionTagTypeSimple( |
| 36975 | | 36824 | |
| 36976 | const new_decl_index = new_decl_index: { | 36825 | const new_decl_index = new_decl_index: { |
| 36977 | const fqn = try union_owner_decl.fullyQualifiedName(mod); | 36826 | const fqn = try union_owner_decl.fullyQualifiedName(mod); |
| 36978 | const src_decl = mod.declPtr(block.src_decl); | 36827 | const new_decl_index = try mod.allocateNewDecl(block.namespace); |
| 36979 | const new_decl_index = try mod.allocateNewDecl(block.namespace, src_decl.src_node); | | |
| 36980 | errdefer mod.destroyDecl(new_decl_index); | 36828 | errdefer mod.destroyDecl(new_decl_index); |
| 36981 | const name = try ip.getOrPutStringFmt( | 36829 | const name = try ip.getOrPutStringFmt( |
| 36982 | gpa, | 36830 | gpa, |
| ... | @@ -36986,7 +36834,7 @@ fn generateUnionTagTypeSimple( | ... | @@ -36986,7 +36834,7 @@ fn generateUnionTagTypeSimple( |
| 36986 | ); | 36834 | ); |
| 36987 | try mod.initNewAnonDecl( | 36835 | try mod.initNewAnonDecl( |
| 36988 | new_decl_index, | 36836 | new_decl_index, |
| 36989 | src_decl.src_line, | 36837 | src_line, |
| 36990 | Value.@"unreachable", | 36838 | Value.@"unreachable", |
| 36991 | name, | 36839 | name, |
| 36992 | ); | 36840 | ); |
| ... | @@ -37016,19 +36864,33 @@ fn generateUnionTagTypeSimple( | ... | @@ -37016,19 +36864,33 @@ fn generateUnionTagTypeSimple( |
| 37016 | } | 36864 | } |
| 37017 | | 36865 | |
| 37018 | fn getBuiltin(sema: *Sema, name: []const u8) CompileError!Air.Inst.Ref { | 36866 | fn getBuiltin(sema: *Sema, name: []const u8) CompileError!Air.Inst.Ref { |
| 37019 | const gpa = sema.gpa; | 36867 | const zcu = sema.mod; |
| 37020 | const src = LazySrcLoc.nodeOffset(0); | | |
| 37021 | | 36868 | |
| 37022 | var block: Block = .{ | 36869 | var block: Block = .{ |
| 37023 | .parent = null, | 36870 | .parent = null, |
| 37024 | .sema = sema, | 36871 | .sema = sema, |
| 37025 | .src_decl = sema.owner_decl_index, | | |
| 37026 | .namespace = sema.owner_decl.src_namespace, | 36872 | .namespace = sema.owner_decl.src_namespace, |
| 37027 | .instructions = .{}, | 36873 | .instructions = .{}, |
| 37028 | .inlining = null, | 36874 | .inlining = null, |
| 37029 | .is_comptime = true, | 36875 | .is_comptime = true, |
| | 36876 | .src_base_inst = sema.owner_decl.zir_decl_index.unwrap() orelse owner: { |
| | 36877 | assert(sema.owner_decl.has_tv); |
| | 36878 | assert(sema.owner_decl.owns_tv); |
| | 36879 | switch (sema.owner_decl.typeOf(zcu).zigTypeTag(zcu)) { |
| | 36880 | .Type => break :owner sema.owner_decl.val.toType().typeDeclInst(zcu).?, |
| | 36881 | .Fn => { |
| | 36882 | const owner = zcu.funcInfo(sema.owner_decl.val.toIntern()).generic_owner; |
| | 36883 | const generic_owner_decl = zcu.declPtr(zcu.funcInfo(owner).owner_decl); |
| | 36884 | break :owner generic_owner_decl.zir_decl_index.unwrap().?; |
| | 36885 | }, |
| | 36886 | else => unreachable, |
| | 36887 | } |
| | 36888 | }, |
| | 36889 | .type_name_ctx = sema.owner_decl.name, |
| 37030 | }; | 36890 | }; |
| 37031 | defer block.instructions.deinit(gpa); | 36891 | defer block.instructions.deinit(sema.gpa); |
| | 36892 | |
| | 36893 | const src = block.nodeOffset(0); |
| 37032 | | 36894 | |
| 37033 | const decl_index = try getBuiltinDecl(sema, &block, name); | 36895 | const decl_index = try getBuiltinDecl(sema, &block, name); |
| 37034 | return sema.analyzeDeclVal(&block, src, decl_index); | 36896 | return sema.analyzeDeclVal(&block, src, decl_index); |
| ... | @@ -37037,7 +36899,7 @@ fn getBuiltin(sema: *Sema, name: []const u8) CompileError!Air.Inst.Ref { | ... | @@ -37037,7 +36899,7 @@ fn getBuiltin(sema: *Sema, name: []const u8) CompileError!Air.Inst.Ref { |
| 37037 | fn getBuiltinDecl(sema: *Sema, block: *Block, name: []const u8) CompileError!InternPool.DeclIndex { | 36899 | fn getBuiltinDecl(sema: *Sema, block: *Block, name: []const u8) CompileError!InternPool.DeclIndex { |
| 37038 | const gpa = sema.gpa; | 36900 | const gpa = sema.gpa; |
| 37039 | | 36901 | |
| 37040 | const src = LazySrcLoc.nodeOffset(0); | 36902 | const src = block.nodeOffset(0); |
| 37041 | | 36903 | |
| 37042 | const mod = sema.mod; | 36904 | const mod = sema.mod; |
| 37043 | const ip = &mod.intern_pool; | 36905 | const ip = &mod.intern_pool; |
| ... | @@ -37064,19 +36926,34 @@ fn getBuiltinDecl(sema: *Sema, block: *Block, name: []const u8) CompileError!Int | ... | @@ -37064,19 +36926,34 @@ fn getBuiltinDecl(sema: *Sema, block: *Block, name: []const u8) CompileError!Int |
| 37064 | } | 36926 | } |
| 37065 | | 36927 | |
| 37066 | fn getBuiltinType(sema: *Sema, name: []const u8) CompileError!Type { | 36928 | fn getBuiltinType(sema: *Sema, name: []const u8) CompileError!Type { |
| | 36929 | const zcu = sema.mod; |
| 37067 | const ty_inst = try sema.getBuiltin(name); | 36930 | const ty_inst = try sema.getBuiltin(name); |
| 37068 | | 36931 | |
| 37069 | var block: Block = .{ | 36932 | var block: Block = .{ |
| 37070 | .parent = null, | 36933 | .parent = null, |
| 37071 | .sema = sema, | 36934 | .sema = sema, |
| 37072 | .src_decl = sema.owner_decl_index, | | |
| 37073 | .namespace = sema.owner_decl.src_namespace, | 36935 | .namespace = sema.owner_decl.src_namespace, |
| 37074 | .instructions = .{}, | 36936 | .instructions = .{}, |
| 37075 | .inlining = null, | 36937 | .inlining = null, |
| 37076 | .is_comptime = true, | 36938 | .is_comptime = true, |
| | 36939 | .src_base_inst = sema.owner_decl.zir_decl_index.unwrap() orelse owner: { |
| | 36940 | assert(sema.owner_decl.has_tv); |
| | 36941 | assert(sema.owner_decl.owns_tv); |
| | 36942 | switch (sema.owner_decl.typeOf(zcu).zigTypeTag(zcu)) { |
| | 36943 | .Type => break :owner sema.owner_decl.val.toType().typeDeclInst(zcu).?, |
| | 36944 | .Fn => { |
| | 36945 | const owner = zcu.funcInfo(sema.owner_decl.val.toIntern()).generic_owner; |
| | 36946 | const generic_owner_decl = zcu.declPtr(zcu.funcInfo(owner).owner_decl); |
| | 36947 | break :owner generic_owner_decl.zir_decl_index.unwrap().?; |
| | 36948 | }, |
| | 36949 | else => unreachable, |
| | 36950 | } |
| | 36951 | }, |
| | 36952 | .type_name_ctx = sema.owner_decl.name, |
| 37077 | }; | 36953 | }; |
| 37078 | defer block.instructions.deinit(sema.gpa); | 36954 | defer block.instructions.deinit(sema.gpa); |
| 37079 | const src = LazySrcLoc.nodeOffset(0); | 36955 | |
| | 36956 | const src = block.nodeOffset(0); |
| 37080 | | 36957 | |
| 37081 | const result_ty = sema.analyzeAsType(&block, src, ty_inst) catch |err| switch (err) { | 36958 | const result_ty = sema.analyzeAsType(&block, src, ty_inst) catch |err| switch (err) { |
| 37082 | error.AnalysisFail => std.debug.panic("std.builtin.{s} is corrupt", .{name}), | 36959 | error.AnalysisFail => std.debug.panic("std.builtin.{s} is corrupt", .{name}), |
| ... | @@ -37092,12 +36969,12 @@ fn getBuiltinType(sema: *Sema, name: []const u8) CompileError!Type { | ... | @@ -37092,12 +36969,12 @@ fn getBuiltinType(sema: *Sema, name: []const u8) CompileError!Type { |
| 37092 | /// that the types are already resolved. | 36969 | /// that the types are already resolved. |
| 37093 | /// TODO assert the return value matches `ty.onePossibleValue` | 36970 | /// TODO assert the return value matches `ty.onePossibleValue` |
| 37094 | pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value { | 36971 | pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value { |
| 37095 | const mod = sema.mod; | 36972 | const zcu = sema.mod; |
| 37096 | const ip = &mod.intern_pool; | 36973 | const ip = &zcu.intern_pool; |
| 37097 | return switch (ty.toIntern()) { | 36974 | return switch (ty.toIntern()) { |
| 37098 | .u0_type, | 36975 | .u0_type, |
| 37099 | .i0_type, | 36976 | .i0_type, |
| 37100 | => try mod.intValue(ty, 0), | 36977 | => try zcu.intValue(ty, 0), |
| 37101 | .u1_type, | 36978 | .u1_type, |
| 37102 | .u8_type, | 36979 | .u8_type, |
| 37103 | .i8_type, | 36980 | .i8_type, |
| ... | @@ -37160,7 +37037,7 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value { | ... | @@ -37160,7 +37037,7 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value { |
| 37160 | .anyframe_type => unreachable, | 37037 | .anyframe_type => unreachable, |
| 37161 | .null_type => Value.null, | 37038 | .null_type => Value.null, |
| 37162 | .undefined_type => Value.undef, | 37039 | .undefined_type => Value.undef, |
| 37163 | .optional_noreturn_type => try mod.nullValue(ty), | 37040 | .optional_noreturn_type => try zcu.nullValue(ty), |
| 37164 | .generic_poison_type => error.GenericPoison, | 37041 | .generic_poison_type => error.GenericPoison, |
| 37165 | .empty_struct_type => Value.empty_struct, | 37042 | .empty_struct_type => Value.empty_struct, |
| 37166 | // values, not types | 37043 | // values, not types |
| ... | @@ -37274,13 +37151,13 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value { | ... | @@ -37274,13 +37151,13 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value { |
| 37274 | => switch (ip.indexToKey(ty.toIntern())) { | 37151 | => switch (ip.indexToKey(ty.toIntern())) { |
| 37275 | inline .array_type, .vector_type => |seq_type, seq_tag| { | 37152 | inline .array_type, .vector_type => |seq_type, seq_tag| { |
| 37276 | const has_sentinel = seq_tag == .array_type and seq_type.sentinel != .none; | 37153 | const has_sentinel = seq_tag == .array_type and seq_type.sentinel != .none; |
| 37277 | if (seq_type.len + @intFromBool(has_sentinel) == 0) return Value.fromInterned((try mod.intern(.{ .aggregate = .{ | 37154 | if (seq_type.len + @intFromBool(has_sentinel) == 0) return Value.fromInterned((try zcu.intern(.{ .aggregate = .{ |
| 37278 | .ty = ty.toIntern(), | 37155 | .ty = ty.toIntern(), |
| 37279 | .storage = .{ .elems = &.{} }, | 37156 | .storage = .{ .elems = &.{} }, |
| 37280 | } }))); | 37157 | } }))); |
| 37281 | | 37158 | |
| 37282 | if (try sema.typeHasOnePossibleValue(Type.fromInterned(seq_type.child))) |opv| { | 37159 | if (try sema.typeHasOnePossibleValue(Type.fromInterned(seq_type.child))) |opv| { |
| 37283 | return Value.fromInterned((try mod.intern(.{ .aggregate = .{ | 37160 | return Value.fromInterned((try zcu.intern(.{ .aggregate = .{ |
| 37284 | .ty = ty.toIntern(), | 37161 | .ty = ty.toIntern(), |
| 37285 | .storage = .{ .repeated_elem = opv.toIntern() }, | 37162 | .storage = .{ .repeated_elem = opv.toIntern() }, |
| 37286 | } }))); | 37163 | } }))); |
| ... | @@ -37295,7 +37172,7 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value { | ... | @@ -37295,7 +37172,7 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value { |
| 37295 | if (struct_type.field_types.len == 0) { | 37172 | if (struct_type.field_types.len == 0) { |
| 37296 | // In this case the struct has no fields at all and | 37173 | // In this case the struct has no fields at all and |
| 37297 | // therefore has one possible value. | 37174 | // therefore has one possible value. |
| 37298 | return Value.fromInterned((try mod.intern(.{ .aggregate = .{ | 37175 | return Value.fromInterned((try zcu.intern(.{ .aggregate = .{ |
| 37299 | .ty = ty.toIntern(), | 37176 | .ty = ty.toIntern(), |
| 37300 | .storage = .{ .elems = &.{} }, | 37177 | .storage = .{ .elems = &.{} }, |
| 37301 | } }))); | 37178 | } }))); |
| ... | @@ -37312,12 +37189,11 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value { | ... | @@ -37312,12 +37189,11 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value { |
| 37312 | continue; | 37189 | continue; |
| 37313 | } | 37190 | } |
| 37314 | const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[i]); | 37191 | const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[i]); |
| 37315 | if (field_ty.eql(ty, mod)) { | 37192 | if (field_ty.eql(ty, zcu)) { |
| 37316 | const msg = try Module.ErrorMsg.create( | 37193 | const msg = try sema.errMsg( |
| 37317 | sema.gpa, | 37194 | ty.srcLoc(zcu), |
| 37318 | mod.declPtr(struct_type.decl.unwrap().?).srcLoc(mod), | | |
| 37319 | "struct '{}' depends on itself", | 37195 | "struct '{}' depends on itself", |
| 37320 | .{ty.fmt(mod)}, | 37196 | .{ty.fmt(zcu)}, |
| 37321 | ); | 37197 | ); |
| 37322 | try sema.addFieldErrNote(ty, i, msg, "while checking this field", .{}); | 37198 | try sema.addFieldErrNote(ty, i, msg, "while checking this field", .{}); |
| 37323 | return sema.failWithOwnedErrorMsg(null, msg); | 37199 | return sema.failWithOwnedErrorMsg(null, msg); |
| ... | @@ -37329,7 +37205,7 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value { | ... | @@ -37329,7 +37205,7 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value { |
| 37329 | | 37205 | |
| 37330 | // In this case the struct has no runtime-known fields and | 37206 | // In this case the struct has no runtime-known fields and |
| 37331 | // therefore has one possible value. | 37207 | // therefore has one possible value. |
| 37332 | return Value.fromInterned((try mod.intern(.{ .aggregate = .{ | 37208 | return Value.fromInterned((try zcu.intern(.{ .aggregate = .{ |
| 37333 | .ty = ty.toIntern(), | 37209 | .ty = ty.toIntern(), |
| 37334 | .storage = .{ .elems = field_vals }, | 37210 | .storage = .{ .elems = field_vals }, |
| 37335 | } }))); | 37211 | } }))); |
| ... | @@ -37342,7 +37218,7 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value { | ... | @@ -37342,7 +37218,7 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value { |
| 37342 | // In this case the struct has all comptime-known fields and | 37218 | // In this case the struct has all comptime-known fields and |
| 37343 | // therefore has one possible value. | 37219 | // therefore has one possible value. |
| 37344 | // TODO: write something like getCoercedInts to avoid needing to dupe | 37220 | // TODO: write something like getCoercedInts to avoid needing to dupe |
| 37345 | return Value.fromInterned((try mod.intern(.{ .aggregate = .{ | 37221 | return Value.fromInterned((try zcu.intern(.{ .aggregate = .{ |
| 37346 | .ty = ty.toIntern(), | 37222 | .ty = ty.toIntern(), |
| 37347 | .storage = .{ .elems = try sema.arena.dupe(InternPool.Index, tuple.values.get(ip)) }, | 37223 | .storage = .{ .elems = try sema.arena.dupe(InternPool.Index, tuple.values.get(ip)) }, |
| 37348 | } }))); | 37224 | } }))); |
| ... | @@ -37354,23 +37230,22 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value { | ... | @@ -37354,23 +37230,22 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value { |
| 37354 | const tag_val = (try sema.typeHasOnePossibleValue(Type.fromInterned(union_obj.tagTypePtr(ip).*))) orelse | 37230 | const tag_val = (try sema.typeHasOnePossibleValue(Type.fromInterned(union_obj.tagTypePtr(ip).*))) orelse |
| 37355 | return null; | 37231 | return null; |
| 37356 | if (union_obj.field_types.len == 0) { | 37232 | if (union_obj.field_types.len == 0) { |
| 37357 | const only = try mod.intern(.{ .empty_enum_value = ty.toIntern() }); | 37233 | const only = try zcu.intern(.{ .empty_enum_value = ty.toIntern() }); |
| 37358 | return Value.fromInterned(only); | 37234 | return Value.fromInterned(only); |
| 37359 | } | 37235 | } |
| 37360 | const only_field_ty = Type.fromInterned(union_obj.field_types.get(ip)[0]); | 37236 | const only_field_ty = Type.fromInterned(union_obj.field_types.get(ip)[0]); |
| 37361 | if (only_field_ty.eql(ty, mod)) { | 37237 | if (only_field_ty.eql(ty, zcu)) { |
| 37362 | const msg = try Module.ErrorMsg.create( | 37238 | const msg = try sema.errMsg( |
| 37363 | sema.gpa, | 37239 | ty.srcLoc(zcu), |
| 37364 | mod.declPtr(union_obj.decl).srcLoc(mod), | | |
| 37365 | "union '{}' depends on itself", | 37240 | "union '{}' depends on itself", |
| 37366 | .{ty.fmt(mod)}, | 37241 | .{ty.fmt(zcu)}, |
| 37367 | ); | 37242 | ); |
| 37368 | try sema.addFieldErrNote(ty, 0, msg, "while checking this field", .{}); | 37243 | try sema.addFieldErrNote(ty, 0, msg, "while checking this field", .{}); |
| 37369 | return sema.failWithOwnedErrorMsg(null, msg); | 37244 | return sema.failWithOwnedErrorMsg(null, msg); |
| 37370 | } | 37245 | } |
| 37371 | const val_val = (try sema.typeHasOnePossibleValue(only_field_ty)) orelse | 37246 | const val_val = (try sema.typeHasOnePossibleValue(only_field_ty)) orelse |
| 37372 | return null; | 37247 | return null; |
| 37373 | const only = try mod.intern(.{ .un = .{ | 37248 | const only = try zcu.intern(.{ .un = .{ |
| 37374 | .ty = ty.toIntern(), | 37249 | .ty = ty.toIntern(), |
| 37375 | .tag = tag_val.toIntern(), | 37250 | .tag = tag_val.toIntern(), |
| 37376 | .val = val_val.toIntern(), | 37251 | .val = val_val.toIntern(), |
| ... | @@ -37385,7 +37260,7 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value { | ... | @@ -37385,7 +37260,7 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value { |
| 37385 | if (enum_type.tag_ty == .comptime_int_type) return null; | 37260 | if (enum_type.tag_ty == .comptime_int_type) return null; |
| 37386 | | 37261 | |
| 37387 | if (try sema.typeHasOnePossibleValue(Type.fromInterned(enum_type.tag_ty))) |int_opv| { | 37262 | if (try sema.typeHasOnePossibleValue(Type.fromInterned(enum_type.tag_ty))) |int_opv| { |
| 37388 | const only = try mod.intern(.{ .enum_tag = .{ | 37263 | const only = try zcu.intern(.{ .enum_tag = .{ |
| 37389 | .ty = ty.toIntern(), | 37264 | .ty = ty.toIntern(), |
| 37390 | .int = int_opv.toIntern(), | 37265 | .int = int_opv.toIntern(), |
| 37391 | } }); | 37266 | } }); |
| ... | @@ -37395,18 +37270,18 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value { | ... | @@ -37395,18 +37270,18 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value { |
| 37395 | return null; | 37270 | return null; |
| 37396 | }, | 37271 | }, |
| 37397 | .auto, .explicit => { | 37272 | .auto, .explicit => { |
| 37398 | if (Type.fromInterned(enum_type.tag_ty).hasRuntimeBits(mod)) return null; | 37273 | if (Type.fromInterned(enum_type.tag_ty).hasRuntimeBits(zcu)) return null; |
| 37399 | | 37274 | |
| 37400 | return Value.fromInterned(switch (enum_type.names.len) { | 37275 | return Value.fromInterned(switch (enum_type.names.len) { |
| 37401 | 0 => try mod.intern(.{ .empty_enum_value = ty.toIntern() }), | 37276 | 0 => try zcu.intern(.{ .empty_enum_value = ty.toIntern() }), |
| 37402 | 1 => try mod.intern(.{ .enum_tag = .{ | 37277 | 1 => try zcu.intern(.{ .enum_tag = .{ |
| 37403 | .ty = ty.toIntern(), | 37278 | .ty = ty.toIntern(), |
| 37404 | .int = if (enum_type.values.len == 0) | 37279 | .int = if (enum_type.values.len == 0) |
| 37405 | (try mod.intValue(Type.fromInterned(enum_type.tag_ty), 0)).toIntern() | 37280 | (try zcu.intValue(Type.fromInterned(enum_type.tag_ty), 0)).toIntern() |
| 37406 | else | 37281 | else |
| 37407 | try mod.intern_pool.getCoercedInts( | 37282 | try zcu.intern_pool.getCoercedInts( |
| 37408 | mod.gpa, | 37283 | zcu.gpa, |
| 37409 | mod.intern_pool.indexToKey(enum_type.values.get(ip)[0]).int, | 37284 | zcu.intern_pool.indexToKey(enum_type.values.get(ip)[0]).int, |
| 37410 | enum_type.tag_ty, | 37285 | enum_type.tag_ty, |
| 37411 | ), | 37286 | ), |
| 37412 | } }), | 37287 | } }), |
| ... | @@ -37744,7 +37619,7 @@ fn unionFieldIndex( | ... | @@ -37744,7 +37619,7 @@ fn unionFieldIndex( |
| 37744 | try sema.resolveTypeFields(union_ty); | 37619 | try sema.resolveTypeFields(union_ty); |
| 37745 | const union_obj = mod.typeToUnion(union_ty).?; | 37620 | const union_obj = mod.typeToUnion(union_ty).?; |
| 37746 | const field_index = union_obj.loadTagType(ip).nameIndex(ip, field_name) orelse | 37621 | const field_index = union_obj.loadTagType(ip).nameIndex(ip, field_name) orelse |
| 37747 | return sema.failWithBadUnionFieldAccess(block, union_obj, field_src, field_name); | 37622 | return sema.failWithBadUnionFieldAccess(block, union_ty, union_obj, field_src, field_name); |
| 37748 | return @intCast(field_index); | 37623 | return @intCast(field_index); |
| 37749 | } | 37624 | } |
| 37750 | | 37625 | |
| ... | @@ -37763,7 +37638,7 @@ fn structFieldIndex( | ... | @@ -37763,7 +37638,7 @@ fn structFieldIndex( |
| 37763 | } else { | 37638 | } else { |
| 37764 | const struct_type = mod.typeToStruct(struct_ty).?; | 37639 | const struct_type = mod.typeToStruct(struct_ty).?; |
| 37765 | return struct_type.nameIndex(ip, field_name) orelse | 37640 | return struct_type.nameIndex(ip, field_name) orelse |
| 37766 | return sema.failWithBadStructFieldAccess(block, struct_type, field_src, field_name); | 37641 | return sema.failWithBadStructFieldAccess(block, struct_ty, struct_type, field_src, field_name); |
| 37767 | } | 37642 | } |
| 37768 | } | 37643 | } |
| 37769 | | 37644 | |
| ... | @@ -38535,9 +38410,9 @@ fn checkRuntimeValue(sema: *Sema, ptr: Air.Inst.Ref) bool { | ... | @@ -38535,9 +38410,9 @@ fn checkRuntimeValue(sema: *Sema, ptr: Air.Inst.Ref) bool { |
| 38535 | fn validateRuntimeValue(sema: *Sema, block: *Block, val_src: LazySrcLoc, val: Air.Inst.Ref) CompileError!void { | 38410 | fn validateRuntimeValue(sema: *Sema, block: *Block, val_src: LazySrcLoc, val: Air.Inst.Ref) CompileError!void { |
| 38536 | if (sema.checkRuntimeValue(val)) return; | 38411 | if (sema.checkRuntimeValue(val)) return; |
| 38537 | return sema.failWithOwnedErrorMsg(block, msg: { | 38412 | return sema.failWithOwnedErrorMsg(block, msg: { |
| 38538 | const msg = try sema.errMsg(block, val_src, "runtime value contains reference to comptime var", .{}); | 38413 | const msg = try sema.errMsg(val_src, "runtime value contains reference to comptime var", .{}); |
| 38539 | errdefer msg.destroy(sema.gpa); | 38414 | errdefer msg.destroy(sema.gpa); |
| 38540 | try sema.errNote(block, val_src, msg, "comptime var pointers are not available at runtime", .{}); | 38415 | try sema.errNote(val_src, msg, "comptime var pointers are not available at runtime", .{}); |
| 38541 | break :msg msg; | 38416 | break :msg msg; |
| 38542 | }); | 38417 | }); |
| 38543 | } | 38418 | } |
| ... | @@ -38628,6 +38503,14 @@ fn maybeDerefSliceAsArray( | ... | @@ -38628,6 +38503,14 @@ fn maybeDerefSliceAsArray( |
| 38628 | return sema.pointerDeref(block, src, casted_ptr, ptr_ty); | 38503 | return sema.pointerDeref(block, src, casted_ptr, ptr_ty); |
| 38629 | } | 38504 | } |
| 38630 | | 38505 | |
| | 38506 | fn analyzeUnreachable(sema: *Sema, block: *Block, src: LazySrcLoc, safety_check: bool) !void { |
| | 38507 | if (safety_check and block.wantSafety()) { |
| | 38508 | try sema.safetyPanic(block, src, .unreach); |
| | 38509 | } else { |
| | 38510 | _ = try block.addNoOp(.unreach); |
| | 38511 | } |
| | 38512 | } |
| | 38513 | |
| 38631 | pub const bitCastVal = @import("Sema/bitcast.zig").bitCast; | 38514 | pub const bitCastVal = @import("Sema/bitcast.zig").bitCast; |
| 38632 | pub const bitCastSpliceVal = @import("Sema/bitcast.zig").bitCastSplice; | 38515 | pub const bitCastSpliceVal = @import("Sema/bitcast.zig").bitCastSplice; |
| 38633 | | 38516 | |