authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2024-06-14 23:05:39+01:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2024-06-15 00:57:52+01:00
log1eaeb4a0a838a783d2060f4e5b3b26b483b26009
tree16fc6b1e9279a6c19e9d41574e4c304e2f387d42
parent07a24bec9a578857920f4c5508f1d7eea65177b8
signaturelock-open Commit is signed but in an unrecognized format.

Zcu: rework source locations

`LazySrcLoc` now stores a reference to the "base AST node" to which it is relative. The previous tagged union is `LazySrcLoc.Offset`. To make working with this structure convenient, `Sema.Block` contains a convenience `src` method which takes an `Offset` and returns a `LazySrcLoc`. The "base node" of a source location is no longer given by a `Decl`, but rather a `TrackedInst` representing either a `declaration`, `struct_decl`, `union_decl`, `enum_decl`, or `opaque_decl`. This is a more appropriate model, and removes an unnecessary responsibility from `Decl` in preparation for the upcoming refactor which will split it into `Nav` and `Cau`. As a part of these `Decl` reworks, the `src_node` field is eliminated. This change aids incremental compilation, and simplifies `Decl`. In some cases -- particularly in backends -- the source location of a declaration is desired. This was previously `Decl.srcLoc` and worked for any `Decl`. Now, it is `Decl.navSrcLoc` in reference to the upcoming refactor, since the set of `Decl`s this works for precisely corresponds to what will in future become a `Nav` -- that is, source-level declarations and generic function instantiations, but *not* type owner Decls. This commit introduces more tags to `LazySrcLoc.Offset` so as to eliminate the concept of `error.NeededSourceLocation`. Now, `.unneeded` should only be used to assert that an error path is unreachable. In the future, uses of `.unneeded` can probably be replaced with `undefined`. The `src_decl` field of `Sema.Block` no longer has a role in type resolution. Its main remaining purpose is to handle namespacing of type names. It will be eliminated entirely in a future commit to remove another undue responsibility from `Decl`. It is worth noting that in future, the `Zcu.SrcLoc` type should probably be eliminated entirely in favour of storing `Zcu.LazySrcLoc` values. This is because `Zcu.SrcLoc` is not valid across incremental updates, and we want to be able to reuse error messages from previous updates even if the source file in question changed. The error reporting logic should instead simply resolve the location from the `LazySrcLoc` on the fly.

34 files changed, 2447 insertions(+), 2868 deletions(-)

src/Compilation.zig+17-20
......@@ -2639,7 +2639,7 @@ fn reportMultiModuleErrors(mod: *Module) !void {
26392639 .root => |pkg| blk: {
26402640 break :blk try Module.ErrorMsg.init(
26412641 mod.gpa,
2642 .{ .file_scope = file, .parent_decl_node = 0, .lazy = .entire_file },
2642 .{ .file_scope = file, .base_node = 0, .lazy = .entire_file },
26432643 "root of module {s}",
26442644 .{pkg.fully_qualified_name},
26452645 );
......@@ -2651,7 +2651,7 @@ fn reportMultiModuleErrors(mod: *Module) !void {
26512651 if (omitted > 0) {
26522652 notes[num_notes] = try Module.ErrorMsg.init(
26532653 mod.gpa,
2654 .{ .file_scope = file, .parent_decl_node = 0, .lazy = .entire_file },
2654 .{ .file_scope = file, .base_node = 0, .lazy = .entire_file },
26552655 "{} more references omitted",
26562656 .{omitted},
26572657 );
......@@ -2660,7 +2660,7 @@ fn reportMultiModuleErrors(mod: *Module) !void {
26602660
26612661 const err = try Module.ErrorMsg.create(
26622662 mod.gpa,
2663 .{ .file_scope = file, .parent_decl_node = 0, .lazy = .entire_file },
2663 .{ .file_scope = file, .base_node = 0, .lazy = .entire_file },
26642664 "file exists in multiple modules",
26652665 .{},
26662666 );
......@@ -3040,29 +3040,26 @@ pub fn getAllErrorsAlloc(comp: *Compilation) !ErrorBundle {
30403040 }
30413041 }
30423042
3043 if (comp.module) |module| {
3044 if (bundle.root_list.items.len == 0 and module.compile_log_decls.count() != 0) {
3045 const keys = module.compile_log_decls.keys();
3046 const values = module.compile_log_decls.values();
3043 if (comp.module) |zcu| {
3044 if (bundle.root_list.items.len == 0 and zcu.compile_log_decls.count() != 0) {
3045 const values = zcu.compile_log_decls.values();
30473046 // First one will be the error; subsequent ones will be notes.
3048 const err_decl = module.declPtr(keys[0]);
3049 const src_loc = err_decl.nodeOffsetSrcLoc(values[0], module);
3050 const err_msg = Module.ErrorMsg{
3047 const src_loc = values[0].src().upgrade(zcu);
3048 const err_msg: Module.ErrorMsg = .{
30513049 .src_loc = src_loc,
30523050 .msg = "found compile log statement",
3053 .notes = try gpa.alloc(Module.ErrorMsg, module.compile_log_decls.count() - 1),
3051 .notes = try gpa.alloc(Module.ErrorMsg, zcu.compile_log_decls.count() - 1),
30543052 };
30553053 defer gpa.free(err_msg.notes);
30563054
3057 for (keys[1..], 0..) |key, i| {
3058 const note_decl = module.declPtr(key);
3059 err_msg.notes[i] = .{
3060 .src_loc = note_decl.nodeOffsetSrcLoc(values[i + 1], module),
3055 for (values[1..], err_msg.notes) |src_info, *note| {
3056 note.* = .{
3057 .src_loc = src_info.src().upgrade(zcu),
30613058 .msg = "also here",
30623059 };
30633060 }
30643061
3065 try addModuleErrorMsg(module, &bundle, err_msg);
3062 try addModuleErrorMsg(zcu, &bundle, err_msg);
30663063 }
30673064 }
30683065
......@@ -3492,7 +3489,7 @@ fn processOneJob(comp: *Compilation, job: Job, prog_node: std.Progress.Node) !vo
34923489 try module.failed_decls.ensureUnusedCapacity(gpa, 1);
34933490 module.failed_decls.putAssumeCapacityNoClobber(decl_index, try Module.ErrorMsg.create(
34943491 gpa,
3495 decl.srcLoc(module),
3492 decl.navSrcLoc(module).upgrade(module),
34963493 "unable to update line number: {s}",
34973494 .{@errorName(err)},
34983495 ));
......@@ -3993,7 +3990,7 @@ fn workerAstGenFile(
39933990 if (!res.is_pkg) {
39943991 res.file.addReference(mod.*, .{ .import = .{
39953992 .file_scope = file,
3996 .parent_decl_node = 0,
3993 .base_node = 0,
39973994 .lazy = .{ .token_abs = item.data.token },
39983995 } }) catch continue;
39993996 }
......@@ -4370,7 +4367,7 @@ fn reportRetryableAstGenError(
43704367 const src_loc: Module.SrcLoc = switch (src) {
43714368 .root => .{
43724369 .file_scope = file,
4373 .parent_decl_node = 0,
4370 .base_node = 0,
43744371 .lazy = .entire_file,
43754372 },
43764373 .import => |info| blk: {
......@@ -4378,7 +4375,7 @@ fn reportRetryableAstGenError(
43784375
43794376 break :blk .{
43804377 .file_scope = importing_file,
4381 .parent_decl_node = 0,
4378 .base_node = 0,
43824379 .lazy = .{ .token_abs = info.import_tok },
43834380 };
43844381 },
src/InternPool.zig+4-2
......@@ -101,8 +101,11 @@ pub const TrackedInst = extern struct {
101101 }
102102 pub const Index = enum(u32) {
103103 _,
104 pub fn resolveFull(i: TrackedInst.Index, ip: *const InternPool) TrackedInst {
105 return ip.tracked_insts.keys()[@intFromEnum(i)];
106 }
104107 pub fn resolve(i: TrackedInst.Index, ip: *const InternPool) Zir.Inst.Index {
105 return ip.tracked_insts.keys()[@intFromEnum(i)].inst;
108 return i.resolveFull(ip).inst;
106109 }
107110 pub fn toOptional(i: TrackedInst.Index) Optional {
108111 return @enumFromInt(@intFromEnum(i));
......@@ -6954,7 +6957,6 @@ fn finishFuncInstance(
69546957 const decl_index = try ip.createDecl(gpa, .{
69556958 .name = undefined,
69566959 .src_namespace = fn_owner_decl.src_namespace,
6957 .src_node = fn_owner_decl.src_node,
69586960 .src_line = fn_owner_decl.src_line,
69596961 .has_tv = true,
69606962 .owns_tv = true,
src/Module.zig+772-1033
......@@ -107,8 +107,17 @@ intern_pool: InternPool = .{},
107107/// a Decl can have a failed_decls entry but have analysis status of success.
108108failed_decls: std.AutoArrayHashMapUnmanaged(Decl.Index, *ErrorMsg) = .{},
109109/// Keep track of one `@compileLog` callsite per owner Decl.
110/// The value is the AST node index offset from the Decl.
111compile_log_decls: std.AutoArrayHashMapUnmanaged(Decl.Index, i32) = .{},
110/// The value is the source location of the `@compileLog` call, convertible to a `LazySrcLoc`.
111compile_log_decls: std.AutoArrayHashMapUnmanaged(Decl.Index, extern struct {
112 base_node_inst: InternPool.TrackedInst.Index,
113 node_offset: i32,
114 pub fn src(self: @This()) LazySrcLoc {
115 return .{
116 .base_node_inst = self.base_node_inst,
117 .offset = LazySrcLoc.Offset.nodeOffset(self.node_offset),
118 };
119 }
120}) = .{},
112121/// Using a map here for consistency with the other fields here.
113122/// The ErrorMsg memory is owned by the `File`, using Module's general purpose allocator.
114123failed_files: std.AutoArrayHashMapUnmanaged(*File, ?*ErrorMsg) = .{},
......@@ -257,9 +266,6 @@ pub const Export = struct {
257266 src: LazySrcLoc,
258267 /// The Decl that performs the export. Note that this is *not* the Decl being exported.
259268 owner_decl: Decl.Index,
260 /// The Decl containing the export statement. Inline function calls
261 /// may cause this to be different from the owner_decl.
262 src_decl: Decl.Index,
263269 exported: Exported,
264270 status: enum {
265271 in_progress,
......@@ -278,12 +284,7 @@ pub const Export = struct {
278284 };
279285
280286 pub fn getSrcLoc(exp: Export, mod: *Module) SrcLoc {
281 const src_decl = mod.declPtr(exp.src_decl);
282 return .{
283 .file_scope = src_decl.getFileScope(mod),
284 .parent_decl_node = src_decl.src_node,
285 .lazy = exp.src,
286 };
287 return exp.src.upgrade(mod);
287288 }
288289};
289290
......@@ -343,9 +344,6 @@ pub const Decl = struct {
343344 /// there is no parent.
344345 src_namespace: Namespace.Index,
345346
346 /// The AST node index of this declaration.
347 /// Must be recomputed when the corresponding source file is modified.
348 src_node: Ast.Node.Index,
349347 /// Line number corresponding to `src_node`. Stored separately so that source files
350348 /// do not need to be loaded into memory in order to compute debug line numbers.
351349 /// This value is absolute.
......@@ -417,26 +415,6 @@ pub const Decl = struct {
417415 return extra.data.getBodies(@intCast(extra.end), zir);
418416 }
419417
420 pub fn relativeToNodeIndex(decl: Decl, offset: i32) Ast.Node.Index {
421 return @bitCast(offset + @as(i32, @bitCast(decl.src_node)));
422 }
423
424 pub fn nodeIndexToRelative(decl: Decl, node_index: Ast.Node.Index) i32 {
425 return @as(i32, @bitCast(node_index)) - @as(i32, @bitCast(decl.src_node));
426 }
427
428 pub fn srcLoc(decl: Decl, zcu: *Zcu) SrcLoc {
429 return decl.nodeOffsetSrcLoc(0, zcu);
430 }
431
432 pub fn nodeOffsetSrcLoc(decl: Decl, node_offset: i32, zcu: *Zcu) SrcLoc {
433 return .{
434 .file_scope = decl.getFileScope(zcu),
435 .parent_decl_node = decl.src_node,
436 .lazy = LazySrcLoc.nodeOffset(node_offset),
437 };
438 }
439
440418 pub fn renderFullyQualifiedName(decl: Decl, zcu: *Zcu, writer: anytype) !void {
441419 if (decl.name_fully_qualified) {
442420 try writer.print("{}", .{decl.name.fmt(&zcu.intern_pool)});
......@@ -551,101 +529,6 @@ pub const Decl = struct {
551529 return decl.typeOf(zcu).abiAlignment(zcu);
552530 }
553531
554 /// Upgrade a `LazySrcLoc` to a `SrcLoc` based on the `Decl` provided.
555 pub fn toSrcLoc(decl: *Decl, lazy: LazySrcLoc, mod: *Module) SrcLoc {
556 return switch (lazy) {
557 .unneeded,
558 .entire_file,
559 .byte_abs,
560 .token_abs,
561 .node_abs,
562 => .{
563 .file_scope = decl.getFileScope(mod),
564 .parent_decl_node = 0,
565 .lazy = lazy,
566 },
567
568 .byte_offset,
569 .token_offset,
570 .node_offset,
571 .node_offset_main_token,
572 .node_offset_initializer,
573 .node_offset_var_decl_ty,
574 .node_offset_var_decl_align,
575 .node_offset_var_decl_section,
576 .node_offset_var_decl_addrspace,
577 .node_offset_var_decl_init,
578 .node_offset_builtin_call_arg0,
579 .node_offset_builtin_call_arg1,
580 .node_offset_builtin_call_arg2,
581 .node_offset_builtin_call_arg3,
582 .node_offset_builtin_call_arg4,
583 .node_offset_builtin_call_arg5,
584 .node_offset_ptrcast_operand,
585 .node_offset_array_access_index,
586 .node_offset_slice_ptr,
587 .node_offset_slice_start,
588 .node_offset_slice_end,
589 .node_offset_slice_sentinel,
590 .node_offset_call_func,
591 .node_offset_field_name,
592 .node_offset_field_name_init,
593 .node_offset_deref_ptr,
594 .node_offset_asm_source,
595 .node_offset_asm_ret_ty,
596 .node_offset_if_cond,
597 .node_offset_bin_op,
598 .node_offset_bin_lhs,
599 .node_offset_bin_rhs,
600 .node_offset_switch_operand,
601 .node_offset_switch_special_prong,
602 .node_offset_switch_range,
603 .node_offset_switch_prong_capture,
604 .node_offset_switch_prong_tag_capture,
605 .node_offset_fn_type_align,
606 .node_offset_fn_type_addrspace,
607 .node_offset_fn_type_section,
608 .node_offset_fn_type_cc,
609 .node_offset_fn_type_ret_ty,
610 .node_offset_param,
611 .token_offset_param,
612 .node_offset_anyframe_type,
613 .node_offset_lib_name,
614 .node_offset_array_type_len,
615 .node_offset_array_type_sentinel,
616 .node_offset_array_type_elem,
617 .node_offset_un_op,
618 .node_offset_ptr_elem,
619 .node_offset_ptr_sentinel,
620 .node_offset_ptr_align,
621 .node_offset_ptr_addrspace,
622 .node_offset_ptr_bitoffset,
623 .node_offset_ptr_hostsize,
624 .node_offset_container_tag,
625 .node_offset_field_default,
626 .node_offset_init_ty,
627 .node_offset_store_ptr,
628 .node_offset_store_operand,
629 .node_offset_return_operand,
630 .for_input,
631 .for_capture_from_input,
632 .array_cat_lhs,
633 .array_cat_rhs,
634 => .{
635 .file_scope = decl.getFileScope(mod),
636 .parent_decl_node = decl.src_node,
637 .lazy = lazy,
638 },
639 inline .call_arg,
640 .fn_proto_param,
641 => |x| .{
642 .file_scope = decl.getFileScope(mod),
643 .parent_decl_node = mod.declPtr(x.decl).src_node,
644 .lazy = lazy,
645 },
646 };
647 }
648
649532 pub fn declPtrType(decl: Decl, zcu: *Zcu) !Type {
650533 assert(decl.has_tv);
651534 const decl_ty = decl.typeOf(zcu);
......@@ -661,6 +544,23 @@ pub const Decl = struct {
661544 },
662545 });
663546 }
547
548 /// Returns the source location of this `Decl`.
549 /// Asserts that this `Decl` corresponds to what will in future be a `Nav` (Named
550 /// Addressable Value): a source-level declaration or generic instantiation.
551 pub fn navSrcLoc(decl: Decl, zcu: *Zcu) LazySrcLoc {
552 return .{
553 .base_node_inst = decl.zir_decl_index.unwrap() orelse inst: {
554 // generic instantiation
555 assert(decl.has_tv);
556 assert(decl.owns_tv);
557 const owner = zcu.funcInfo(decl.val.toIntern()).generic_owner;
558 const generic_owner_decl = zcu.declPtr(zcu.funcInfo(owner).owner_decl);
559 break :inst generic_owner_decl.zir_decl_index.unwrap().?;
560 },
561 .offset = LazySrcLoc.Offset.nodeOffset(0),
562 };
563 }
664564};
665565
666566/// This state is attached to every Decl when Module emit_h is non-null.
......@@ -1137,18 +1037,17 @@ pub const ErrorMsg = struct {
11371037/// Canonical reference to a position within a source file.
11381038pub const SrcLoc = struct {
11391039 file_scope: *File,
1140 /// Might be 0 depending on tag of `lazy`.
1141 parent_decl_node: Ast.Node.Index,
1142 /// Relative to `parent_decl_node`.
1143 lazy: LazySrcLoc,
1040 base_node: Ast.Node.Index,
1041 /// Relative to `base_node`.
1042 lazy: LazySrcLoc.Offset,
11441043
1145 pub fn declSrcToken(src_loc: SrcLoc) Ast.TokenIndex {
1044 pub fn baseSrcToken(src_loc: SrcLoc) Ast.TokenIndex {
11461045 const tree = src_loc.file_scope.tree;
1147 return tree.firstToken(src_loc.parent_decl_node);
1046 return tree.firstToken(src_loc.base_node);
11481047 }
11491048
1150 pub fn declRelativeToNodeIndex(src_loc: SrcLoc, offset: i32) Ast.Node.Index {
1151 return @bitCast(offset + @as(i32, @bitCast(src_loc.parent_decl_node)));
1049 pub fn relativeToNodeIndex(src_loc: SrcLoc, offset: i32) Ast.Node.Index {
1050 return @bitCast(offset + @as(i32, @bitCast(src_loc.base_node)));
11521051 }
11531052
11541053 pub const Span = Ast.Span;
......@@ -1172,14 +1071,14 @@ pub const SrcLoc = struct {
11721071 },
11731072 .byte_offset => |byte_off| {
11741073 const tree = try src_loc.file_scope.getTree(gpa);
1175 const tok_index = src_loc.declSrcToken();
1074 const tok_index = src_loc.baseSrcToken();
11761075 const start = tree.tokens.items(.start)[tok_index] + byte_off;
11771076 const end = start + @as(u32, @intCast(tree.tokenSlice(tok_index).len));
11781077 return Span{ .start = start, .end = end, .main = start };
11791078 },
11801079 .token_offset => |tok_off| {
11811080 const tree = try src_loc.file_scope.getTree(gpa);
1182 const tok_index = src_loc.declSrcToken() + tok_off;
1081 const tok_index = src_loc.baseSrcToken() + tok_off;
11831082 const start = tree.tokens.items(.start)[tok_index];
11841083 const end = start + @as(u32, @intCast(tree.tokenSlice(tok_index).len));
11851084 return Span{ .start = start, .end = end, .main = start };
......@@ -1187,25 +1086,25 @@ pub const SrcLoc = struct {
11871086 .node_offset => |traced_off| {
11881087 const node_off = traced_off.x;
11891088 const tree = try src_loc.file_scope.getTree(gpa);
1190 const node = src_loc.declRelativeToNodeIndex(node_off);
1089 const node = src_loc.relativeToNodeIndex(node_off);
11911090 assert(src_loc.file_scope.tree_loaded);
11921091 return tree.nodeToSpan(node);
11931092 },
11941093 .node_offset_main_token => |node_off| {
11951094 const tree = try src_loc.file_scope.getTree(gpa);
1196 const node = src_loc.declRelativeToNodeIndex(node_off);
1095 const node = src_loc.relativeToNodeIndex(node_off);
11971096 const main_token = tree.nodes.items(.main_token)[node];
11981097 return tree.tokensToSpan(main_token, main_token, main_token);
11991098 },
12001099 .node_offset_bin_op => |node_off| {
12011100 const tree = try src_loc.file_scope.getTree(gpa);
1202 const node = src_loc.declRelativeToNodeIndex(node_off);
1101 const node = src_loc.relativeToNodeIndex(node_off);
12031102 assert(src_loc.file_scope.tree_loaded);
12041103 return tree.nodeToSpan(node);
12051104 },
12061105 .node_offset_initializer => |node_off| {
12071106 const tree = try src_loc.file_scope.getTree(gpa);
1208 const node = src_loc.declRelativeToNodeIndex(node_off);
1107 const node = src_loc.relativeToNodeIndex(node_off);
12091108 return tree.tokensToSpan(
12101109 tree.firstToken(node) - 3,
12111110 tree.lastToken(node),
......@@ -1214,7 +1113,7 @@ pub const SrcLoc = struct {
12141113 },
12151114 .node_offset_var_decl_ty => |node_off| {
12161115 const tree = try src_loc.file_scope.getTree(gpa);
1217 const node = src_loc.declRelativeToNodeIndex(node_off);
1116 const node = src_loc.relativeToNodeIndex(node_off);
12181117 const node_tags = tree.nodes.items(.tag);
12191118 const full = switch (node_tags[node]) {
12201119 .global_var_decl,
......@@ -1238,41 +1137,51 @@ pub const SrcLoc = struct {
12381137 },
12391138 .node_offset_var_decl_align => |node_off| {
12401139 const tree = try src_loc.file_scope.getTree(gpa);
1241 const node = src_loc.declRelativeToNodeIndex(node_off);
1140 const node = src_loc.relativeToNodeIndex(node_off);
12421141 const full = tree.fullVarDecl(node).?;
12431142 return tree.nodeToSpan(full.ast.align_node);
12441143 },
12451144 .node_offset_var_decl_section => |node_off| {
12461145 const tree = try src_loc.file_scope.getTree(gpa);
1247 const node = src_loc.declRelativeToNodeIndex(node_off);
1146 const node = src_loc.relativeToNodeIndex(node_off);
12481147 const full = tree.fullVarDecl(node).?;
12491148 return tree.nodeToSpan(full.ast.section_node);
12501149 },
12511150 .node_offset_var_decl_addrspace => |node_off| {
12521151 const tree = try src_loc.file_scope.getTree(gpa);
1253 const node = src_loc.declRelativeToNodeIndex(node_off);
1152 const node = src_loc.relativeToNodeIndex(node_off);
12541153 const full = tree.fullVarDecl(node).?;
12551154 return tree.nodeToSpan(full.ast.addrspace_node);
12561155 },
12571156 .node_offset_var_decl_init => |node_off| {
12581157 const tree = try src_loc.file_scope.getTree(gpa);
1259 const node = src_loc.declRelativeToNodeIndex(node_off);
1158 const node = src_loc.relativeToNodeIndex(node_off);
12601159 const full = tree.fullVarDecl(node).?;
12611160 return tree.nodeToSpan(full.ast.init_node);
12621161 },
1263 .node_offset_builtin_call_arg0 => |n| return src_loc.byteOffsetBuiltinCallArg(gpa, n, 0),
1264 .node_offset_builtin_call_arg1 => |n| return src_loc.byteOffsetBuiltinCallArg(gpa, n, 1),
1265 .node_offset_builtin_call_arg2 => |n| return src_loc.byteOffsetBuiltinCallArg(gpa, n, 2),
1266 .node_offset_builtin_call_arg3 => |n| return src_loc.byteOffsetBuiltinCallArg(gpa, n, 3),
1267 .node_offset_builtin_call_arg4 => |n| return src_loc.byteOffsetBuiltinCallArg(gpa, n, 4),
1268 .node_offset_builtin_call_arg5 => |n| return src_loc.byteOffsetBuiltinCallArg(gpa, n, 5),
1162 .node_offset_builtin_call_arg => |builtin_arg| {
1163 const tree = try src_loc.file_scope.getTree(gpa);
1164 const node_datas = tree.nodes.items(.data);
1165 const node_tags = tree.nodes.items(.tag);
1166 const node = src_loc.relativeToNodeIndex(builtin_arg.builtin_call_node);
1167 const param = switch (node_tags[node]) {
1168 .builtin_call_two, .builtin_call_two_comma => switch (builtin_arg.arg_index) {
1169 0 => node_datas[node].lhs,
1170 1 => node_datas[node].rhs,
1171 else => unreachable,
1172 },
1173 .builtin_call, .builtin_call_comma => tree.extra_data[node_datas[node].lhs + builtin_arg.arg_index],
1174 else => unreachable,
1175 };
1176 return tree.nodeToSpan(param);
1177 },
12691178 .node_offset_ptrcast_operand => |node_off| {
12701179 const tree = try src_loc.file_scope.getTree(gpa);
12711180 const main_tokens = tree.nodes.items(.main_token);
12721181 const node_datas = tree.nodes.items(.data);
12731182 const node_tags = tree.nodes.items(.tag);
12741183
1275 var node = src_loc.declRelativeToNodeIndex(node_off);
1184 var node = src_loc.relativeToNodeIndex(node_off);
12761185 while (true) {
12771186 switch (node_tags[node]) {
12781187 .builtin_call_two, .builtin_call_two_comma => {},
......@@ -1304,7 +1213,7 @@ pub const SrcLoc = struct {
13041213 .node_offset_array_access_index => |node_off| {
13051214 const tree = try src_loc.file_scope.getTree(gpa);
13061215 const node_datas = tree.nodes.items(.data);
1307 const node = src_loc.declRelativeToNodeIndex(node_off);
1216 const node = src_loc.relativeToNodeIndex(node_off);
13081217 return tree.nodeToSpan(node_datas[node].rhs);
13091218 },
13101219 .node_offset_slice_ptr,
......@@ -1313,7 +1222,7 @@ pub const SrcLoc = struct {
13131222 .node_offset_slice_sentinel,
13141223 => |node_off| {
13151224 const tree = try src_loc.file_scope.getTree(gpa);
1316 const node = src_loc.declRelativeToNodeIndex(node_off);
1225 const node = src_loc.relativeToNodeIndex(node_off);
13171226 const full = tree.fullSlice(node).?;
13181227 const part_node = switch (src_loc.lazy) {
13191228 .node_offset_slice_ptr => full.ast.sliced,
......@@ -1326,7 +1235,7 @@ pub const SrcLoc = struct {
13261235 },
13271236 .node_offset_call_func => |node_off| {
13281237 const tree = try src_loc.file_scope.getTree(gpa);
1329 const node = src_loc.declRelativeToNodeIndex(node_off);
1238 const node = src_loc.relativeToNodeIndex(node_off);
13301239 var buf: [1]Ast.Node.Index = undefined;
13311240 const full = tree.fullCall(&buf, node).?;
13321241 return tree.nodeToSpan(full.ast.fn_expr);
......@@ -1335,7 +1244,7 @@ pub const SrcLoc = struct {
13351244 const tree = try src_loc.file_scope.getTree(gpa);
13361245 const node_datas = tree.nodes.items(.data);
13371246 const node_tags = tree.nodes.items(.tag);
1338 const node = src_loc.declRelativeToNodeIndex(node_off);
1247 const node = src_loc.relativeToNodeIndex(node_off);
13391248 var buf: [1]Ast.Node.Index = undefined;
13401249 const tok_index = switch (node_tags[node]) {
13411250 .field_access => node_datas[node].rhs,
......@@ -1359,7 +1268,7 @@ pub const SrcLoc = struct {
13591268 },
13601269 .node_offset_field_name_init => |node_off| {
13611270 const tree = try src_loc.file_scope.getTree(gpa);
1362 const node = src_loc.declRelativeToNodeIndex(node_off);
1271 const node = src_loc.relativeToNodeIndex(node_off);
13631272 const tok_index = tree.firstToken(node) - 2;
13641273 const start = tree.tokens.items(.start)[tok_index];
13651274 const end = start + @as(u32, @intCast(tree.tokenSlice(tok_index).len));
......@@ -1367,18 +1276,18 @@ pub const SrcLoc = struct {
13671276 },
13681277 .node_offset_deref_ptr => |node_off| {
13691278 const tree = try src_loc.file_scope.getTree(gpa);
1370 const node = src_loc.declRelativeToNodeIndex(node_off);
1279 const node = src_loc.relativeToNodeIndex(node_off);
13711280 return tree.nodeToSpan(node);
13721281 },
13731282 .node_offset_asm_source => |node_off| {
13741283 const tree = try src_loc.file_scope.getTree(gpa);
1375 const node = src_loc.declRelativeToNodeIndex(node_off);
1284 const node = src_loc.relativeToNodeIndex(node_off);
13761285 const full = tree.fullAsm(node).?;
13771286 return tree.nodeToSpan(full.ast.template);
13781287 },
13791288 .node_offset_asm_ret_ty => |node_off| {
13801289 const tree = try src_loc.file_scope.getTree(gpa);
1381 const node = src_loc.declRelativeToNodeIndex(node_off);
1290 const node = src_loc.relativeToNodeIndex(node_off);
13821291 const full = tree.fullAsm(node).?;
13831292 const asm_output = full.outputs[0];
13841293 const node_datas = tree.nodes.items(.data);
......@@ -1387,7 +1296,7 @@ pub const SrcLoc = struct {
13871296
13881297 .node_offset_if_cond => |node_off| {
13891298 const tree = try src_loc.file_scope.getTree(gpa);
1390 const node = src_loc.declRelativeToNodeIndex(node_off);
1299 const node = src_loc.relativeToNodeIndex(node_off);
13911300 const node_tags = tree.nodes.items(.tag);
13921301 const src_node = switch (node_tags[node]) {
13931302 .if_simple,
......@@ -1416,7 +1325,7 @@ pub const SrcLoc = struct {
14161325 },
14171326 .for_input => |for_input| {
14181327 const tree = try src_loc.file_scope.getTree(gpa);
1419 const node = src_loc.declRelativeToNodeIndex(for_input.for_node_offset);
1328 const node = src_loc.relativeToNodeIndex(for_input.for_node_offset);
14201329 const for_full = tree.fullFor(node).?;
14211330 const src_node = for_full.ast.inputs[for_input.input_index];
14221331 return tree.nodeToSpan(src_node);
......@@ -1424,7 +1333,7 @@ pub const SrcLoc = struct {
14241333 .for_capture_from_input => |node_off| {
14251334 const tree = try src_loc.file_scope.getTree(gpa);
14261335 const token_tags = tree.tokens.items(.tag);
1427 const input_node = src_loc.declRelativeToNodeIndex(node_off);
1336 const input_node = src_loc.relativeToNodeIndex(node_off);
14281337 // We have to actually linear scan the whole AST to find the for loop
14291338 // that contains this input.
14301339 const node_tags = tree.nodes.items(.tag);
......@@ -1465,7 +1374,7 @@ pub const SrcLoc = struct {
14651374 },
14661375 .call_arg => |call_arg| {
14671376 const tree = try src_loc.file_scope.getTree(gpa);
1468 const node = src_loc.declRelativeToNodeIndex(call_arg.call_node_offset);
1377 const node = src_loc.relativeToNodeIndex(call_arg.call_node_offset);
14691378 var buf: [2]Ast.Node.Index = undefined;
14701379 const call_full = tree.fullCall(buf[0..1], node) orelse {
14711380 const node_tags = tree.nodes.items(.tag);
......@@ -1501,43 +1410,49 @@ pub const SrcLoc = struct {
15011410 };
15021411 return tree.nodeToSpan(call_full.ast.params[call_arg.arg_index]);
15031412 },
1504 .fn_proto_param => |fn_proto_param| {
1413 .fn_proto_param, .fn_proto_param_type => |fn_proto_param| {
15051414 const tree = try src_loc.file_scope.getTree(gpa);
1506 const node = src_loc.declRelativeToNodeIndex(fn_proto_param.fn_proto_node_offset);
1415 const node = src_loc.relativeToNodeIndex(fn_proto_param.fn_proto_node_offset);
15071416 var buf: [1]Ast.Node.Index = undefined;
15081417 const full = tree.fullFnProto(&buf, node).?;
15091418 var it = full.iterate(tree);
15101419 var i: usize = 0;
15111420 while (it.next()) |param| : (i += 1) {
1512 if (i == fn_proto_param.param_index) {
1513 if (param.anytype_ellipsis3) |token| return tree.tokenToSpan(token);
1514 const first_token = param.comptime_noalias orelse
1515 param.name_token orelse
1516 tree.firstToken(param.type_expr);
1517 return tree.tokensToSpan(
1518 first_token,
1519 tree.lastToken(param.type_expr),
1520 first_token,
1521 );
1421 if (i != fn_proto_param.param_index) continue;
1422
1423 switch (src_loc.lazy) {
1424 .fn_proto_param_type => if (param.anytype_ellipsis3) |tok| {
1425 return tree.tokenToSpan(tok);
1426 } else {
1427 return tree.nodeToSpan(param.type_expr);
1428 },
1429 .fn_proto_param => if (param.anytype_ellipsis3) |tok| {
1430 const first = param.comptime_noalias orelse param.name_token orelse tok;
1431 return tree.tokensToSpan(first, tok, first);
1432 } else {
1433 const first = param.comptime_noalias orelse param.name_token orelse tree.firstToken(param.type_expr);
1434 return tree.tokensToSpan(first, tree.lastToken(param.type_expr), first);
1435 },
1436 else => unreachable,
15221437 }
15231438 }
15241439 unreachable;
15251440 },
15261441 .node_offset_bin_lhs => |node_off| {
15271442 const tree = try src_loc.file_scope.getTree(gpa);
1528 const node = src_loc.declRelativeToNodeIndex(node_off);
1443 const node = src_loc.relativeToNodeIndex(node_off);
15291444 const node_datas = tree.nodes.items(.data);
15301445 return tree.nodeToSpan(node_datas[node].lhs);
15311446 },
15321447 .node_offset_bin_rhs => |node_off| {
15331448 const tree = try src_loc.file_scope.getTree(gpa);
1534 const node = src_loc.declRelativeToNodeIndex(node_off);
1449 const node = src_loc.relativeToNodeIndex(node_off);
15351450 const node_datas = tree.nodes.items(.data);
15361451 return tree.nodeToSpan(node_datas[node].rhs);
15371452 },
15381453 .array_cat_lhs, .array_cat_rhs => |cat| {
15391454 const tree = try src_loc.file_scope.getTree(gpa);
1540 const node = src_loc.declRelativeToNodeIndex(cat.array_cat_offset);
1455 const node = src_loc.relativeToNodeIndex(cat.array_cat_offset);
15411456 const node_datas = tree.nodes.items(.data);
15421457 const arr_node = if (src_loc.lazy == .array_cat_lhs)
15431458 node_datas[node].lhs
......@@ -1565,14 +1480,14 @@ pub const SrcLoc = struct {
15651480
15661481 .node_offset_switch_operand => |node_off| {
15671482 const tree = try src_loc.file_scope.getTree(gpa);
1568 const node = src_loc.declRelativeToNodeIndex(node_off);
1483 const node = src_loc.relativeToNodeIndex(node_off);
15691484 const node_datas = tree.nodes.items(.data);
15701485 return tree.nodeToSpan(node_datas[node].lhs);
15711486 },
15721487
15731488 .node_offset_switch_special_prong => |node_off| {
15741489 const tree = try src_loc.file_scope.getTree(gpa);
1575 const switch_node = src_loc.declRelativeToNodeIndex(node_off);
1490 const switch_node = src_loc.relativeToNodeIndex(node_off);
15761491 const node_datas = tree.nodes.items(.data);
15771492 const node_tags = tree.nodes.items(.tag);
15781493 const main_tokens = tree.nodes.items(.main_token);
......@@ -1592,7 +1507,7 @@ pub const SrcLoc = struct {
15921507
15931508 .node_offset_switch_range => |node_off| {
15941509 const tree = try src_loc.file_scope.getTree(gpa);
1595 const switch_node = src_loc.declRelativeToNodeIndex(node_off);
1510 const switch_node = src_loc.relativeToNodeIndex(node_off);
15961511 const node_datas = tree.nodes.items(.data);
15971512 const node_tags = tree.nodes.items(.tag);
15981513 const main_tokens = tree.nodes.items(.main_token);
......@@ -1613,56 +1528,30 @@ pub const SrcLoc = struct {
16131528 }
16141529 } else unreachable;
16151530 },
1616 .node_offset_switch_prong_capture,
1617 .node_offset_switch_prong_tag_capture,
1618 => |node_off| {
1619 const tree = try src_loc.file_scope.getTree(gpa);
1620 const case_node = src_loc.declRelativeToNodeIndex(node_off);
1621 const case = tree.fullSwitchCase(case_node).?;
1622 const token_tags = tree.tokens.items(.tag);
1623 const start_tok = switch (src_loc.lazy) {
1624 .node_offset_switch_prong_capture => case.payload_token.?,
1625 .node_offset_switch_prong_tag_capture => blk: {
1626 var tok = case.payload_token.?;
1627 if (token_tags[tok] == .asterisk) tok += 1;
1628 tok += 2; // skip over comma
1629 break :blk tok;
1630 },
1631 else => unreachable,
1632 };
1633 const end_tok = switch (token_tags[start_tok]) {
1634 .asterisk => start_tok + 1,
1635 else => start_tok,
1636 };
1637 const start = tree.tokens.items(.start)[start_tok];
1638 const end_start = tree.tokens.items(.start)[end_tok];
1639 const end = end_start + @as(u32, @intCast(tree.tokenSlice(end_tok).len));
1640 return Span{ .start = start, .end = end, .main = start };
1641 },
16421531 .node_offset_fn_type_align => |node_off| {
16431532 const tree = try src_loc.file_scope.getTree(gpa);
1644 const node = src_loc.declRelativeToNodeIndex(node_off);
1533 const node = src_loc.relativeToNodeIndex(node_off);
16451534 var buf: [1]Ast.Node.Index = undefined;
16461535 const full = tree.fullFnProto(&buf, node).?;
16471536 return tree.nodeToSpan(full.ast.align_expr);
16481537 },
16491538 .node_offset_fn_type_addrspace => |node_off| {
16501539 const tree = try src_loc.file_scope.getTree(gpa);
1651 const node = src_loc.declRelativeToNodeIndex(node_off);
1540 const node = src_loc.relativeToNodeIndex(node_off);
16521541 var buf: [1]Ast.Node.Index = undefined;
16531542 const full = tree.fullFnProto(&buf, node).?;
16541543 return tree.nodeToSpan(full.ast.addrspace_expr);
16551544 },
16561545 .node_offset_fn_type_section => |node_off| {
16571546 const tree = try src_loc.file_scope.getTree(gpa);
1658 const node = src_loc.declRelativeToNodeIndex(node_off);
1547 const node = src_loc.relativeToNodeIndex(node_off);
16591548 var buf: [1]Ast.Node.Index = undefined;
16601549 const full = tree.fullFnProto(&buf, node).?;
16611550 return tree.nodeToSpan(full.ast.section_expr);
16621551 },
16631552 .node_offset_fn_type_cc => |node_off| {
16641553 const tree = try src_loc.file_scope.getTree(gpa);
1665 const node = src_loc.declRelativeToNodeIndex(node_off);
1554 const node = src_loc.relativeToNodeIndex(node_off);
16661555 var buf: [1]Ast.Node.Index = undefined;
16671556 const full = tree.fullFnProto(&buf, node).?;
16681557 return tree.nodeToSpan(full.ast.callconv_expr);
......@@ -1670,7 +1559,7 @@ pub const SrcLoc = struct {
16701559
16711560 .node_offset_fn_type_ret_ty => |node_off| {
16721561 const tree = try src_loc.file_scope.getTree(gpa);
1673 const node = src_loc.declRelativeToNodeIndex(node_off);
1562 const node = src_loc.relativeToNodeIndex(node_off);
16741563 var buf: [1]Ast.Node.Index = undefined;
16751564 const full = tree.fullFnProto(&buf, node).?;
16761565 return tree.nodeToSpan(full.ast.return_type);
......@@ -1678,7 +1567,7 @@ pub const SrcLoc = struct {
16781567 .node_offset_param => |node_off| {
16791568 const tree = try src_loc.file_scope.getTree(gpa);
16801569 const token_tags = tree.tokens.items(.tag);
1681 const node = src_loc.declRelativeToNodeIndex(node_off);
1570 const node = src_loc.relativeToNodeIndex(node_off);
16821571
16831572 var first_tok = tree.firstToken(node);
16841573 while (true) switch (token_tags[first_tok - 1]) {
......@@ -1694,7 +1583,7 @@ pub const SrcLoc = struct {
16941583 .token_offset_param => |token_off| {
16951584 const tree = try src_loc.file_scope.getTree(gpa);
16961585 const token_tags = tree.tokens.items(.tag);
1697 const main_token = tree.nodes.items(.main_token)[src_loc.parent_decl_node];
1586 const main_token = tree.nodes.items(.main_token)[src_loc.base_node];
16981587 const tok_index = @as(Ast.TokenIndex, @bitCast(token_off + @as(i32, @bitCast(main_token))));
16991588
17001589 var first_tok = tok_index;
......@@ -1712,13 +1601,13 @@ pub const SrcLoc = struct {
17121601 .node_offset_anyframe_type => |node_off| {
17131602 const tree = try src_loc.file_scope.getTree(gpa);
17141603 const node_datas = tree.nodes.items(.data);
1715 const parent_node = src_loc.declRelativeToNodeIndex(node_off);
1604 const parent_node = src_loc.relativeToNodeIndex(node_off);
17161605 return tree.nodeToSpan(node_datas[parent_node].rhs);
17171606 },
17181607
17191608 .node_offset_lib_name => |node_off| {
17201609 const tree = try src_loc.file_scope.getTree(gpa);
1721 const parent_node = src_loc.declRelativeToNodeIndex(node_off);
1610 const parent_node = src_loc.relativeToNodeIndex(node_off);
17221611 var buf: [1]Ast.Node.Index = undefined;
17231612 const full = tree.fullFnProto(&buf, parent_node).?;
17241613 const tok_index = full.lib_name.?;
......@@ -1729,21 +1618,21 @@ pub const SrcLoc = struct {
17291618
17301619 .node_offset_array_type_len => |node_off| {
17311620 const tree = try src_loc.file_scope.getTree(gpa);
1732 const parent_node = src_loc.declRelativeToNodeIndex(node_off);
1621 const parent_node = src_loc.relativeToNodeIndex(node_off);
17331622
17341623 const full = tree.fullArrayType(parent_node).?;
17351624 return tree.nodeToSpan(full.ast.elem_count);
17361625 },
17371626 .node_offset_array_type_sentinel => |node_off| {
17381627 const tree = try src_loc.file_scope.getTree(gpa);
1739 const parent_node = src_loc.declRelativeToNodeIndex(node_off);
1628 const parent_node = src_loc.relativeToNodeIndex(node_off);
17401629
17411630 const full = tree.fullArrayType(parent_node).?;
17421631 return tree.nodeToSpan(full.ast.sentinel);
17431632 },
17441633 .node_offset_array_type_elem => |node_off| {
17451634 const tree = try src_loc.file_scope.getTree(gpa);
1746 const parent_node = src_loc.declRelativeToNodeIndex(node_off);
1635 const parent_node = src_loc.relativeToNodeIndex(node_off);
17471636
17481637 const full = tree.fullArrayType(parent_node).?;
17491638 return tree.nodeToSpan(full.ast.elem_type);
......@@ -1751,48 +1640,48 @@ pub const SrcLoc = struct {
17511640 .node_offset_un_op => |node_off| {
17521641 const tree = try src_loc.file_scope.getTree(gpa);
17531642 const node_datas = tree.nodes.items(.data);
1754 const node = src_loc.declRelativeToNodeIndex(node_off);
1643 const node = src_loc.relativeToNodeIndex(node_off);
17551644
17561645 return tree.nodeToSpan(node_datas[node].lhs);
17571646 },
17581647 .node_offset_ptr_elem => |node_off| {
17591648 const tree = try src_loc.file_scope.getTree(gpa);
1760 const parent_node = src_loc.declRelativeToNodeIndex(node_off);
1649 const parent_node = src_loc.relativeToNodeIndex(node_off);
17611650
17621651 const full = tree.fullPtrType(parent_node).?;
17631652 return tree.nodeToSpan(full.ast.child_type);
17641653 },
17651654 .node_offset_ptr_sentinel => |node_off| {
17661655 const tree = try src_loc.file_scope.getTree(gpa);
1767 const parent_node = src_loc.declRelativeToNodeIndex(node_off);
1656 const parent_node = src_loc.relativeToNodeIndex(node_off);
17681657
17691658 const full = tree.fullPtrType(parent_node).?;
17701659 return tree.nodeToSpan(full.ast.sentinel);
17711660 },
17721661 .node_offset_ptr_align => |node_off| {
17731662 const tree = try src_loc.file_scope.getTree(gpa);
1774 const parent_node = src_loc.declRelativeToNodeIndex(node_off);
1663 const parent_node = src_loc.relativeToNodeIndex(node_off);
17751664
17761665 const full = tree.fullPtrType(parent_node).?;
17771666 return tree.nodeToSpan(full.ast.align_node);
17781667 },
17791668 .node_offset_ptr_addrspace => |node_off| {
17801669 const tree = try src_loc.file_scope.getTree(gpa);
1781 const parent_node = src_loc.declRelativeToNodeIndex(node_off);
1670 const parent_node = src_loc.relativeToNodeIndex(node_off);
17821671
17831672 const full = tree.fullPtrType(parent_node).?;
17841673 return tree.nodeToSpan(full.ast.addrspace_node);
17851674 },
17861675 .node_offset_ptr_bitoffset => |node_off| {
17871676 const tree = try src_loc.file_scope.getTree(gpa);
1788 const parent_node = src_loc.declRelativeToNodeIndex(node_off);
1677 const parent_node = src_loc.relativeToNodeIndex(node_off);
17891678
17901679 const full = tree.fullPtrType(parent_node).?;
17911680 return tree.nodeToSpan(full.ast.bit_range_start);
17921681 },
17931682 .node_offset_ptr_hostsize => |node_off| {
17941683 const tree = try src_loc.file_scope.getTree(gpa);
1795 const parent_node = src_loc.declRelativeToNodeIndex(node_off);
1684 const parent_node = src_loc.relativeToNodeIndex(node_off);
17961685
17971686 const full = tree.fullPtrType(parent_node).?;
17981687 return tree.nodeToSpan(full.ast.bit_range_end);
......@@ -1800,7 +1689,7 @@ pub const SrcLoc = struct {
18001689 .node_offset_container_tag => |node_off| {
18011690 const tree = try src_loc.file_scope.getTree(gpa);
18021691 const node_tags = tree.nodes.items(.tag);
1803 const parent_node = src_loc.declRelativeToNodeIndex(node_off);
1692 const parent_node = src_loc.relativeToNodeIndex(node_off);
18041693
18051694 switch (node_tags[parent_node]) {
18061695 .container_decl_arg, .container_decl_arg_trailing => {
......@@ -1822,7 +1711,7 @@ pub const SrcLoc = struct {
18221711 .node_offset_field_default => |node_off| {
18231712 const tree = try src_loc.file_scope.getTree(gpa);
18241713 const node_tags = tree.nodes.items(.tag);
1825 const parent_node = src_loc.declRelativeToNodeIndex(node_off);
1714 const parent_node = src_loc.relativeToNodeIndex(node_off);
18261715
18271716 const full: Ast.full.ContainerField = switch (node_tags[parent_node]) {
18281717 .container_field => tree.containerField(parent_node),
......@@ -1833,7 +1722,7 @@ pub const SrcLoc = struct {
18331722 },
18341723 .node_offset_init_ty => |node_off| {
18351724 const tree = try src_loc.file_scope.getTree(gpa);
1836 const parent_node = src_loc.declRelativeToNodeIndex(node_off);
1725 const parent_node = src_loc.relativeToNodeIndex(node_off);
18371726
18381727 var buf: [2]Ast.Node.Index = undefined;
18391728 const type_expr = if (tree.fullArrayInit(&buf, parent_node)) |array_init|
......@@ -1846,7 +1735,7 @@ pub const SrcLoc = struct {
18461735 const tree = try src_loc.file_scope.getTree(gpa);
18471736 const node_tags = tree.nodes.items(.tag);
18481737 const node_datas = tree.nodes.items(.data);
1849 const node = src_loc.declRelativeToNodeIndex(node_off);
1738 const node = src_loc.relativeToNodeIndex(node_off);
18501739
18511740 switch (node_tags[node]) {
18521741 .assign => {
......@@ -1859,7 +1748,7 @@ pub const SrcLoc = struct {
18591748 const tree = try src_loc.file_scope.getTree(gpa);
18601749 const node_tags = tree.nodes.items(.tag);
18611750 const node_datas = tree.nodes.items(.data);
1862 const node = src_loc.declRelativeToNodeIndex(node_off);
1751 const node = src_loc.relativeToNodeIndex(node_off);
18631752
18641753 switch (node_tags[node]) {
18651754 .assign => {
......@@ -1870,7 +1759,7 @@ pub const SrcLoc = struct {
18701759 },
18711760 .node_offset_return_operand => |node_off| {
18721761 const tree = try src_loc.file_scope.getTree(gpa);
1873 const node = src_loc.declRelativeToNodeIndex(node_off);
1762 const node = src_loc.relativeToNodeIndex(node_off);
18741763 const node_tags = tree.nodes.items(.tag);
18751764 const node_datas = tree.nodes.items(.data);
18761765 if (node_tags[node] == .@"return" and node_datas[node].lhs != 0) {
......@@ -1878,381 +1767,629 @@ pub const SrcLoc = struct {
18781767 }
18791768 return tree.nodeToSpan(node);
18801769 },
1881 }
1882 }
1770 .container_field_name,
1771 .container_field_value,
1772 .container_field_type,
1773 .container_field_align,
1774 => |field_idx| {
1775 const tree = try src_loc.file_scope.getTree(gpa);
1776 const node = src_loc.relativeToNodeIndex(0);
1777 var buf: [2]Ast.Node.Index = undefined;
1778 const container_decl = tree.fullContainerDecl(&buf, node) orelse
1779 return tree.nodeToSpan(node);
1780
1781 var cur_field_idx: usize = 0;
1782 for (container_decl.ast.members) |member_node| {
1783 const field = tree.fullContainerField(member_node) orelse continue;
1784 if (cur_field_idx < field_idx) {
1785 cur_field_idx += 1;
1786 continue;
1787 }
1788 const field_component_node = switch (src_loc.lazy) {
1789 .container_field_name => 0,
1790 .container_field_value => field.ast.value_expr,
1791 .container_field_type => field.ast.type_expr,
1792 .container_field_align => field.ast.align_expr,
1793 else => unreachable,
1794 };
1795 if (field_component_node == 0) {
1796 return tree.tokenToSpan(field.ast.main_token);
1797 } else {
1798 return tree.nodeToSpan(field_component_node);
1799 }
1800 } else unreachable;
1801 },
1802 .init_elem => |init_elem| {
1803 const tree = try src_loc.file_scope.getTree(gpa);
1804 const init_node = src_loc.relativeToNodeIndex(init_elem.init_node_offset);
1805 var buf: [2]Ast.Node.Index = undefined;
1806 if (tree.fullArrayInit(&buf, init_node)) |full| {
1807 const elem_node = full.ast.elements[init_elem.elem_index];
1808 return tree.nodeToSpan(elem_node);
1809 } else if (tree.fullStructInit(&buf, init_node)) |full| {
1810 const field_node = full.ast.fields[init_elem.elem_index];
1811 return tree.tokensToSpan(
1812 tree.firstToken(field_node) - 3,
1813 tree.lastToken(field_node),
1814 tree.nodes.items(.main_token)[field_node] - 2,
1815 );
1816 } else unreachable;
1817 },
1818 .init_field_name,
1819 .init_field_linkage,
1820 .init_field_section,
1821 .init_field_visibility,
1822 .init_field_rw,
1823 .init_field_locality,
1824 .init_field_cache,
1825 .init_field_library,
1826 .init_field_thread_local,
1827 => |builtin_call_node| {
1828 const wanted = switch (src_loc.lazy) {
1829 .init_field_name => "name",
1830 .init_field_linkage => "linkage",
1831 .init_field_section => "section",
1832 .init_field_visibility => "visibility",
1833 .init_field_rw => "rw",
1834 .init_field_locality => "locality",
1835 .init_field_cache => "cache",
1836 .init_field_library => "library",
1837 .init_field_thread_local => "thread_local",
1838 else => unreachable,
1839 };
1840 const tree = try src_loc.file_scope.getTree(gpa);
1841 const node_datas = tree.nodes.items(.data);
1842 const node_tags = tree.nodes.items(.tag);
1843 const node = src_loc.relativeToNodeIndex(builtin_call_node);
1844 const arg_node = switch (node_tags[node]) {
1845 .builtin_call_two, .builtin_call_two_comma => node_datas[node].rhs,
1846 .builtin_call, .builtin_call_comma => tree.extra_data[node_datas[node].lhs + 1],
1847 else => unreachable,
1848 };
1849 var buf: [2]Ast.Node.Index = undefined;
1850 const full = tree.fullStructInit(&buf, arg_node) orelse
1851 return tree.nodeToSpan(arg_node);
1852 for (full.ast.fields) |field_node| {
1853 // . IDENTIFIER = field_node
1854 const name_token = tree.firstToken(field_node) - 2;
1855 const name = tree.tokenSlice(name_token);
1856 if (std.mem.eql(u8, name, wanted)) {
1857 return tree.tokensToSpan(
1858 name_token - 1,
1859 tree.lastToken(field_node),
1860 tree.nodes.items(.main_token)[field_node] - 2,
1861 );
1862 }
1863 }
1864 return tree.nodeToSpan(arg_node);
1865 },
1866 .switch_case_item,
1867 .switch_case_item_range_first,
1868 .switch_case_item_range_last,
1869 .switch_capture,
1870 .switch_tag_capture,
1871 => {
1872 const switch_node_offset, const want_case_idx = switch (src_loc.lazy) {
1873 .switch_case_item,
1874 .switch_case_item_range_first,
1875 .switch_case_item_range_last,
1876 => |x| .{ x.switch_node_offset, x.case_idx },
1877 .switch_capture,
1878 .switch_tag_capture,
1879 => |x| .{ x.switch_node_offset, x.case_idx },
1880 else => unreachable,
1881 };
18831882
1884 pub fn byteOffsetBuiltinCallArg(
1885 src_loc: SrcLoc,
1886 gpa: Allocator,
1887 node_off: i32,
1888 arg_index: u32,
1889 ) !Span {
1890 const tree = try src_loc.file_scope.getTree(gpa);
1891 const node_datas = tree.nodes.items(.data);
1892 const node_tags = tree.nodes.items(.tag);
1893 const node = src_loc.declRelativeToNodeIndex(node_off);
1894 const param = switch (node_tags[node]) {
1895 .builtin_call_two, .builtin_call_two_comma => switch (arg_index) {
1896 0 => node_datas[node].lhs,
1897 1 => node_datas[node].rhs,
1898 else => unreachable,
1883 const tree = try src_loc.file_scope.getTree(gpa);
1884 const node_datas = tree.nodes.items(.data);
1885 const node_tags = tree.nodes.items(.tag);
1886 const main_tokens = tree.nodes.items(.main_token);
1887 const switch_node = src_loc.relativeToNodeIndex(switch_node_offset);
1888 const extra = tree.extraData(node_datas[switch_node].rhs, Ast.Node.SubRange);
1889 const case_nodes = tree.extra_data[extra.start..extra.end];
1890
1891 var multi_i: u32 = 0;
1892 var scalar_i: u32 = 0;
1893 const case = for (case_nodes) |case_node| {
1894 const case = tree.fullSwitchCase(case_node).?;
1895 const is_special = special: {
1896 if (case.ast.values.len == 0) break :special true;
1897 if (case.ast.values.len == 1 and node_tags[case.ast.values[0]] == .identifier) {
1898 break :special mem.eql(u8, tree.tokenSlice(main_tokens[case.ast.values[0]]), "_");
1899 }
1900 break :special false;
1901 };
1902 if (is_special) {
1903 if (want_case_idx.isSpecial()) {
1904 break case;
1905 }
1906 }
1907
1908 const is_multi = case.ast.values.len != 1 or
1909 node_tags[case.ast.values[0]] == .switch_range;
1910
1911 if (!want_case_idx.isSpecial()) switch (want_case_idx.kind) {
1912 .scalar => if (!is_multi and want_case_idx.index == scalar_i) break case,
1913 .multi => if (is_multi and want_case_idx.index == multi_i) break case,
1914 };
1915
1916 if (is_multi) {
1917 multi_i += 1;
1918 } else {
1919 scalar_i += 1;
1920 }
1921 } else unreachable;
1922
1923 const want_item = switch (src_loc.lazy) {
1924 .switch_case_item,
1925 .switch_case_item_range_first,
1926 .switch_case_item_range_last,
1927 => |x| x.item_idx,
1928 .switch_capture, .switch_tag_capture => {
1929 const token_tags = tree.tokens.items(.tag);
1930 const start = switch (src_loc.lazy) {
1931 .switch_capture => case.payload_token.?,
1932 .switch_tag_capture => tok: {
1933 var tok = case.payload_token.?;
1934 if (token_tags[tok] == .asterisk) tok += 1;
1935 tok += 2; // skip over comma
1936 break :tok tok;
1937 },
1938 else => unreachable,
1939 };
1940 const end = switch (token_tags[start]) {
1941 .asterisk => start + 1,
1942 else => start,
1943 };
1944 return tree.tokensToSpan(start, end, start);
1945 },
1946 else => unreachable,
1947 };
1948
1949 switch (want_item.kind) {
1950 .single => {
1951 var item_i: u32 = 0;
1952 for (case.ast.values) |item_node| {
1953 if (node_tags[item_node] == .switch_range) continue;
1954 if (item_i != want_item.index) {
1955 item_i += 1;
1956 continue;
1957 }
1958 return tree.nodeToSpan(item_node);
1959 } else unreachable;
1960 },
1961 .range => {
1962 var range_i: u32 = 0;
1963 for (case.ast.values) |item_node| {
1964 if (node_tags[item_node] != .switch_range) continue;
1965 if (range_i != want_item.index) {
1966 range_i += 1;
1967 continue;
1968 }
1969 return switch (src_loc.lazy) {
1970 .switch_case_item => tree.nodeToSpan(item_node),
1971 .switch_case_item_range_first => tree.nodeToSpan(node_datas[item_node].lhs),
1972 .switch_case_item_range_last => tree.nodeToSpan(node_datas[item_node].rhs),
1973 else => unreachable,
1974 };
1975 } else unreachable;
1976 },
1977 }
18991978 },
1900 .builtin_call, .builtin_call_comma => tree.extra_data[node_datas[node].lhs + arg_index],
1901 else => unreachable,
1902 };
1903 return tree.nodeToSpan(param);
1979 }
19041980 }
19051981};
19061982
1907/// Resolving a source location into a byte offset may require doing work
1908/// that we would rather not do unless the error actually occurs.
1909/// Therefore we need a data structure that contains the information necessary
1910/// to lazily produce a `SrcLoc` as required.
1911/// Most of the offsets in this data structure are relative to the containing Decl.
1912/// This makes the source location resolve properly even when a Decl gets
1913/// shifted up or down in the file, as long as the Decl's contents itself
1914/// do not change.
1915pub const LazySrcLoc = union(enum) {
1916 /// When this tag is set, the code that constructed this `LazySrcLoc` is asserting
1917 /// that all code paths which would need to resolve the source location are
1918 /// unreachable. If you are debugging this tag incorrectly being this value,
1919 /// look into using reverse-continue with a memory watchpoint to see where the
1920 /// value is being set to this tag.
1921 unneeded,
1922 /// Means the source location points to an entire file; not any particular
1923 /// location within the file. `file_scope` union field will be active.
1924 entire_file,
1925 /// The source location points to a byte offset within a source file,
1926 /// offset from 0. The source file is determined contextually.
1927 /// Inside a `SrcLoc`, the `file_scope` union field will be active.
1928 byte_abs: u32,
1929 /// The source location points to a token within a source file,
1930 /// offset from 0. The source file is determined contextually.
1931 /// Inside a `SrcLoc`, the `file_scope` union field will be active.
1932 token_abs: u32,
1933 /// The source location points to an AST node within a source file,
1934 /// offset from 0. The source file is determined contextually.
1935 /// Inside a `SrcLoc`, the `file_scope` union field will be active.
1936 node_abs: u32,
1937 /// The source location points to a byte offset within a source file,
1938 /// offset from the byte offset of the Decl within the file.
1939 /// The Decl is determined contextually.
1940 byte_offset: u32,
1941 /// This data is the offset into the token list from the Decl token.
1942 /// The Decl is determined contextually.
1943 token_offset: u32,
1944 /// The source location points to an AST node, which is this value offset
1945 /// from its containing Decl node AST index.
1946 /// The Decl is determined contextually.
1947 node_offset: TracedOffset,
1948 /// The source location points to the main token of an AST node, found
1949 /// by taking this AST node index offset from the containing Decl AST node.
1950 /// The Decl is determined contextually.
1951 node_offset_main_token: i32,
1952 /// The source location points to the beginning of a struct initializer.
1953 /// The Decl is determined contextually.
1954 node_offset_initializer: i32,
1955 /// The source location points to a variable declaration type expression,
1956 /// found by taking this AST node index offset from the containing
1957 /// Decl AST node, which points to a variable declaration AST node. Next, navigate
1958 /// to the type expression.
1959 /// The Decl is determined contextually.
1960 node_offset_var_decl_ty: i32,
1961 /// The source location points to the alignment expression of a var decl.
1962 /// The Decl is determined contextually.
1963 node_offset_var_decl_align: i32,
1964 /// The source location points to the linksection expression of a var decl.
1965 /// The Decl is determined contextually.
1966 node_offset_var_decl_section: i32,
1967 /// The source location points to the addrspace expression of a var decl.
1968 /// The Decl is determined contextually.
1969 node_offset_var_decl_addrspace: i32,
1970 /// The source location points to the initializer of a var decl.
1971 /// The Decl is determined contextually.
1972 node_offset_var_decl_init: i32,
1973 /// The source location points to the first parameter of a builtin
1974 /// function call, found by taking this AST node index offset from the containing
1975 /// Decl AST node, which points to a builtin call AST node. Next, navigate
1976 /// to the first parameter.
1977 /// The Decl is determined contextually.
1978 node_offset_builtin_call_arg0: i32,
1979 /// Same as `node_offset_builtin_call_arg0` except arg index 1.
1980 node_offset_builtin_call_arg1: i32,
1981 node_offset_builtin_call_arg2: i32,
1982 node_offset_builtin_call_arg3: i32,
1983 node_offset_builtin_call_arg4: i32,
1984 node_offset_builtin_call_arg5: i32,
1985 /// Like `node_offset_builtin_call_arg0` but recurses through arbitrarily many calls
1986 /// to pointer cast builtins.
1987 node_offset_ptrcast_operand: i32,
1988 /// The source location points to the index expression of an array access
1989 /// expression, found by taking this AST node index offset from the containing
1990 /// Decl AST node, which points to an array access AST node. Next, navigate
1991 /// to the index expression.
1992 /// The Decl is determined contextually.
1993 node_offset_array_access_index: i32,
1994 /// The source location points to the LHS of a slice expression
1995 /// expression, found by taking this AST node index offset from the containing
1996 /// Decl AST node, which points to a slice AST node. Next, navigate
1997 /// to the sentinel expression.
1998 /// The Decl is determined contextually.
1999 node_offset_slice_ptr: i32,
2000 /// The source location points to start expression of a slice expression
2001 /// expression, found by taking this AST node index offset from the containing
2002 /// Decl AST node, which points to a slice AST node. Next, navigate
2003 /// to the sentinel expression.
2004 /// The Decl is determined contextually.
2005 node_offset_slice_start: i32,
2006 /// The source location points to the end expression of a slice
2007 /// expression, found by taking this AST node index offset from the containing
2008 /// Decl AST node, which points to a slice AST node. Next, navigate
2009 /// to the sentinel expression.
2010 /// The Decl is determined contextually.
2011 node_offset_slice_end: i32,
2012 /// The source location points to the sentinel expression of a slice
2013 /// expression, found by taking this AST node index offset from the containing
2014 /// Decl AST node, which points to a slice AST node. Next, navigate
2015 /// to the sentinel expression.
2016 /// The Decl is determined contextually.
2017 node_offset_slice_sentinel: i32,
2018 /// The source location points to the callee expression of a function
2019 /// call expression, found by taking this AST node index offset from the containing
2020 /// Decl AST node, which points to a function call AST node. Next, navigate
2021 /// to the callee expression.
2022 /// The Decl is determined contextually.
2023 node_offset_call_func: i32,
2024 /// The payload is offset from the containing Decl AST node.
2025 /// The source location points to the field name of:
2026 /// * a field access expression (`a.b`), or
2027 /// * the callee of a method call (`a.b()`)
2028 /// The Decl is determined contextually.
2029 node_offset_field_name: i32,
2030 /// The payload is offset from the containing Decl AST node.
2031 /// The source location points to the field name of the operand ("b" node)
2032 /// of a field initialization expression (`.a = b`)
2033 /// The Decl is determined contextually.
2034 node_offset_field_name_init: i32,
2035 /// The source location points to the pointer of a pointer deref expression,
2036 /// found by taking this AST node index offset from the containing
2037 /// Decl AST node, which points to a pointer deref AST node. Next, navigate
2038 /// to the pointer expression.
2039 /// The Decl is determined contextually.
2040 node_offset_deref_ptr: i32,
2041 /// The source location points to the assembly source code of an inline assembly
2042 /// expression, found by taking this AST node index offset from the containing
2043 /// Decl AST node, which points to inline assembly AST node. Next, navigate
2044 /// to the asm template source code.
2045 /// The Decl is determined contextually.
2046 node_offset_asm_source: i32,
2047 /// The source location points to the return type of an inline assembly
2048 /// expression, found by taking this AST node index offset from the containing
2049 /// Decl AST node, which points to inline assembly AST node. Next, navigate
2050 /// to the return type expression.
2051 /// The Decl is determined contextually.
2052 node_offset_asm_ret_ty: i32,
2053 /// The source location points to the condition expression of an if
2054 /// expression, found by taking this AST node index offset from the containing
2055 /// Decl AST node, which points to an if expression AST node. Next, navigate
2056 /// to the condition expression.
2057 /// The Decl is determined contextually.
2058 node_offset_if_cond: i32,
2059 /// The source location points to a binary expression, such as `a + b`, found
2060 /// by taking this AST node index offset from the containing Decl AST node.
2061 /// The Decl is determined contextually.
2062 node_offset_bin_op: i32,
2063 /// The source location points to the LHS of a binary expression, found
2064 /// by taking this AST node index offset from the containing Decl AST node,
2065 /// which points to a binary expression AST node. Next, navigate to the LHS.
2066 /// The Decl is determined contextually.
2067 node_offset_bin_lhs: i32,
2068 /// The source location points to the RHS of a binary expression, found
2069 /// by taking this AST node index offset from the containing Decl AST node,
2070 /// which points to a binary expression AST node. Next, navigate to the RHS.
2071 /// The Decl is determined contextually.
2072 node_offset_bin_rhs: i32,
2073 /// The source location points to the operand of a switch expression, found
2074 /// by taking this AST node index offset from the containing Decl AST node,
2075 /// which points to a switch expression AST node. Next, navigate to the operand.
2076 /// The Decl is determined contextually.
2077 node_offset_switch_operand: i32,
2078 /// The source location points to the else/`_` prong of a switch expression, found
2079 /// by taking this AST node index offset from the containing Decl AST node,
2080 /// which points to a switch expression AST node. Next, navigate to the else/`_` prong.
2081 /// The Decl is determined contextually.
2082 node_offset_switch_special_prong: i32,
2083 /// The source location points to all the ranges of a switch expression, found
2084 /// by taking this AST node index offset from the containing Decl AST node,
2085 /// which points to a switch expression AST node. Next, navigate to any of the
2086 /// range nodes. The error applies to all of them.
2087 /// The Decl is determined contextually.
2088 node_offset_switch_range: i32,
2089 /// The source location points to the capture of a switch_prong.
2090 /// The Decl is determined contextually.
2091 node_offset_switch_prong_capture: i32,
2092 /// The source location points to the tag capture of a switch_prong.
2093 /// The Decl is determined contextually.
2094 node_offset_switch_prong_tag_capture: i32,
2095 /// The source location points to the align expr of a function type
2096 /// expression, found by taking this AST node index offset from the containing
2097 /// Decl AST node, which points to a function type AST node. Next, navigate to
2098 /// the calling convention node.
2099 /// The Decl is determined contextually.
2100 node_offset_fn_type_align: i32,
2101 /// The source location points to the addrspace expr of a function type
2102 /// expression, found by taking this AST node index offset from the containing
2103 /// Decl AST node, which points to a function type AST node. Next, navigate to
2104 /// the calling convention node.
2105 /// The Decl is determined contextually.
2106 node_offset_fn_type_addrspace: i32,
2107 /// The source location points to the linksection expr of a function type
2108 /// expression, found by taking this AST node index offset from the containing
2109 /// Decl AST node, which points to a function type AST node. Next, navigate to
2110 /// the calling convention node.
2111 /// The Decl is determined contextually.
2112 node_offset_fn_type_section: i32,
2113 /// The source location points to the calling convention of a function type
2114 /// expression, found by taking this AST node index offset from the containing
2115 /// Decl AST node, which points to a function type AST node. Next, navigate to
2116 /// the calling convention node.
2117 /// The Decl is determined contextually.
2118 node_offset_fn_type_cc: i32,
2119 /// The source location points to the return type of a function type
2120 /// expression, found by taking this AST node index offset from the containing
2121 /// Decl AST node, which points to a function type AST node. Next, navigate to
2122 /// the return type node.
2123 /// The Decl is determined contextually.
2124 node_offset_fn_type_ret_ty: i32,
2125 node_offset_param: i32,
2126 token_offset_param: i32,
2127 /// The source location points to the type expression of an `anyframe->T`
2128 /// expression, found by taking this AST node index offset from the containing
2129 /// Decl AST node, which points to a `anyframe->T` expression AST node. Next, navigate
2130 /// to the type expression.
2131 /// The Decl is determined contextually.
2132 node_offset_anyframe_type: i32,
2133 /// The source location points to the string literal of `extern "foo"`, found
2134 /// by taking this AST node index offset from the containing
2135 /// Decl AST node, which points to a function prototype or variable declaration
2136 /// expression AST node. Next, navigate to the string literal of the `extern "foo"`.
2137 /// The Decl is determined contextually.
2138 node_offset_lib_name: i32,
2139 /// The source location points to the len expression of an `[N:S]T`
2140 /// expression, found by taking this AST node index offset from the containing
2141 /// Decl AST node, which points to an `[N:S]T` expression AST node. Next, navigate
2142 /// to the len expression.
2143 /// The Decl is determined contextually.
2144 node_offset_array_type_len: i32,
2145 /// The source location points to the sentinel expression of an `[N:S]T`
2146 /// expression, found by taking this AST node index offset from the containing
2147 /// Decl AST node, which points to an `[N:S]T` expression AST node. Next, navigate
2148 /// to the sentinel expression.
2149 /// The Decl is determined contextually.
2150 node_offset_array_type_sentinel: i32,
2151 /// The source location points to the elem expression of an `[N:S]T`
2152 /// expression, found by taking this AST node index offset from the containing
2153 /// Decl AST node, which points to an `[N:S]T` expression AST node. Next, navigate
2154 /// to the elem expression.
2155 /// The Decl is determined contextually.
2156 node_offset_array_type_elem: i32,
2157 /// The source location points to the operand of an unary expression.
2158 /// The Decl is determined contextually.
2159 node_offset_un_op: i32,
2160 /// The source location points to the elem type of a pointer.
2161 /// The Decl is determined contextually.
2162 node_offset_ptr_elem: i32,
2163 /// The source location points to the sentinel of a pointer.
2164 /// The Decl is determined contextually.
2165 node_offset_ptr_sentinel: i32,
2166 /// The source location points to the align expr of a pointer.
2167 /// The Decl is determined contextually.
2168 node_offset_ptr_align: i32,
2169 /// The source location points to the addrspace expr of a pointer.
2170 /// The Decl is determined contextually.
2171 node_offset_ptr_addrspace: i32,
2172 /// The source location points to the bit-offset of a pointer.
2173 /// The Decl is determined contextually.
2174 node_offset_ptr_bitoffset: i32,
2175 /// The source location points to the host size of a pointer.
2176 /// The Decl is determined contextually.
2177 node_offset_ptr_hostsize: i32,
2178 /// The source location points to the tag type of an union or an enum.
2179 /// The Decl is determined contextually.
2180 node_offset_container_tag: i32,
2181 /// The source location points to the default value of a field.
2182 /// The Decl is determined contextually.
2183 node_offset_field_default: i32,
2184 /// The source location points to the type of an array or struct initializer.
2185 /// The Decl is determined contextually.
2186 node_offset_init_ty: i32,
2187 /// The source location points to the LHS of an assignment.
2188 /// The Decl is determined contextually.
2189 node_offset_store_ptr: i32,
2190 /// The source location points to the RHS of an assignment.
2191 /// The Decl is determined contextually.
2192 node_offset_store_operand: i32,
2193 /// The source location points to the operand of a `return` statement, or
2194 /// the `return` itself if there is no explicit operand.
2195 /// The Decl is determined contextually.
2196 node_offset_return_operand: i32,
2197 /// The source location points to a for loop input.
2198 /// The Decl is determined contextually.
2199 for_input: struct {
2200 /// Points to the for loop AST node.
2201 for_node_offset: i32,
2202 /// Picks one of the inputs from the condition.
2203 input_index: u32,
2204 },
2205 /// The source location points to one of the captures of a for loop, found
2206 /// by taking this AST node index offset from the containing
2207 /// Decl AST node, which points to one of the input nodes of a for loop.
2208 /// Next, navigate to the corresponding capture.
2209 /// The Decl is determined contextually.
2210 for_capture_from_input: i32,
2211 /// The source location points to the argument node of a function call.
2212 call_arg: struct {
2213 decl: Decl.Index,
2214 /// Points to the function call AST node.
2215 call_node_offset: i32,
2216 /// The index of the argument the source location points to.
2217 arg_index: u32,
2218 },
2219 fn_proto_param: struct {
2220 decl: Decl.Index,
2221 /// Points to the function prototype AST node.
2222 fn_proto_node_offset: i32,
2223 /// The index of the parameter the source location points to.
2224 param_index: u32,
2225 },
2226 array_cat_lhs: ArrayCat,
2227 array_cat_rhs: ArrayCat,
2228
2229 const ArrayCat = struct {
2230 /// Points to the array concat AST node.
2231 array_cat_offset: i32,
2232 /// The index of the element the source location points to.
2233 elem_index: u32,
2234 };
1983pub const LazySrcLoc = struct {
1984 /// This instruction provides the source node locations are resolved relative to.
1985 /// It is a `declaration`, `struct_decl`, `union_decl`, `enum_decl`, or `opaque_decl`.
1986 /// This must be valid even if `relative` is an absolute value, since it is required to
1987 /// determine the file which the `LazySrcLoc` refers to.
1988 base_node_inst: InternPool.TrackedInst.Index,
1989 /// This field determines the source location relative to `base_node_inst`.
1990 offset: Offset,
1991
1992 pub const Offset = union(enum) {
1993 /// When this tag is set, the code that constructed this `LazySrcLoc` is asserting
1994 /// that all code paths which would need to resolve the source location are
1995 /// unreachable. If you are debugging this tag incorrectly being this value,
1996 /// look into using reverse-continue with a memory watchpoint to see where the
1997 /// value is being set to this tag.
1998 /// `base_node_inst` is unused.
1999 unneeded,
2000 /// Means the source location points to an entire file; not any particular
2001 /// location within the file. `file_scope` union field will be active.
2002 entire_file,
2003 /// The source location points to a byte offset within a source file,
2004 /// offset from 0. The source file is determined contextually.
2005 /// Inside a `SrcLoc`, the `file_scope` union field will be active.
2006 byte_abs: u32,
2007 /// The source location points to a token within a source file,
2008 /// offset from 0. The source file is determined contextually.
2009 /// Inside a `SrcLoc`, the `file_scope` union field will be active.
2010 token_abs: u32,
2011 /// The source location points to an AST node within a source file,
2012 /// offset from 0. The source file is determined contextually.
2013 /// Inside a `SrcLoc`, the `file_scope` union field will be active.
2014 node_abs: u32,
2015 /// The source location points to a byte offset within a source file,
2016 /// offset from the byte offset of the base node within the file.
2017 byte_offset: u32,
2018 /// This data is the offset into the token list from the base node's first token.
2019 token_offset: u32,
2020 /// The source location points to an AST node, which is this value offset
2021 /// from its containing base node AST index.
2022 node_offset: TracedOffset,
2023 /// The source location points to the main token of an AST node, found
2024 /// by taking this AST node index offset from the containing base node.
2025 node_offset_main_token: i32,
2026 /// The source location points to the beginning of a struct initializer.
2027 node_offset_initializer: i32,
2028 /// The source location points to a variable declaration type expression,
2029 /// found by taking this AST node index offset from the containing
2030 /// base node, which points to a variable declaration AST node. Next, navigate
2031 /// to the type expression.
2032 node_offset_var_decl_ty: i32,
2033 /// The source location points to the alignment expression of a var decl.
2034 node_offset_var_decl_align: i32,
2035 /// The source location points to the linksection expression of a var decl.
2036 node_offset_var_decl_section: i32,
2037 /// The source location points to the addrspace expression of a var decl.
2038 node_offset_var_decl_addrspace: i32,
2039 /// The source location points to the initializer of a var decl.
2040 node_offset_var_decl_init: i32,
2041 /// The source location points to the given argument of a builtin function call.
2042 /// `builtin_call_node` points to the builtin call.
2043 /// `arg_index` is the index of the argument which hte source location refers to.
2044 node_offset_builtin_call_arg: struct {
2045 builtin_call_node: i32,
2046 arg_index: u32,
2047 },
2048 /// Like `node_offset_builtin_call_arg` but recurses through arbitrarily many calls
2049 /// to pointer cast builtins (taking the first argument of the most nested).
2050 node_offset_ptrcast_operand: i32,
2051 /// The source location points to the index expression of an array access
2052 /// expression, found by taking this AST node index offset from the containing
2053 /// base node, which points to an array access AST node. Next, navigate
2054 /// to the index expression.
2055 node_offset_array_access_index: i32,
2056 /// The source location points to the LHS of a slice expression
2057 /// expression, found by taking this AST node index offset from the containing
2058 /// base node, which points to a slice AST node. Next, navigate
2059 /// to the sentinel expression.
2060 node_offset_slice_ptr: i32,
2061 /// The source location points to start expression of a slice expression
2062 /// expression, found by taking this AST node index offset from the containing
2063 /// base node, which points to a slice AST node. Next, navigate
2064 /// to the sentinel expression.
2065 node_offset_slice_start: i32,
2066 /// The source location points to the end expression of a slice
2067 /// expression, found by taking this AST node index offset from the containing
2068 /// base node, which points to a slice AST node. Next, navigate
2069 /// to the sentinel expression.
2070 node_offset_slice_end: i32,
2071 /// The source location points to the sentinel expression of a slice
2072 /// expression, found by taking this AST node index offset from the containing
2073 /// base node, which points to a slice AST node. Next, navigate
2074 /// to the sentinel expression.
2075 node_offset_slice_sentinel: i32,
2076 /// The source location points to the callee expression of a function
2077 /// call expression, found by taking this AST node index offset from the containing
2078 /// base node, which points to a function call AST node. Next, navigate
2079 /// to the callee expression.
2080 node_offset_call_func: i32,
2081 /// The payload is offset from the containing base node.
2082 /// The source location points to the field name of:
2083 /// * a field access expression (`a.b`), or
2084 /// * the callee of a method call (`a.b()`)
2085 node_offset_field_name: i32,
2086 /// The payload is offset from the containing base node.
2087 /// The source location points to the field name of the operand ("b" node)
2088 /// of a field initialization expression (`.a = b`)
2089 node_offset_field_name_init: i32,
2090 /// The source location points to the pointer of a pointer deref expression,
2091 /// found by taking this AST node index offset from the containing
2092 /// base node, which points to a pointer deref AST node. Next, navigate
2093 /// to the pointer expression.
2094 node_offset_deref_ptr: i32,
2095 /// The source location points to the assembly source code of an inline assembly
2096 /// expression, found by taking this AST node index offset from the containing
2097 /// base node, which points to inline assembly AST node. Next, navigate
2098 /// to the asm template source code.
2099 node_offset_asm_source: i32,
2100 /// The source location points to the return type of an inline assembly
2101 /// expression, found by taking this AST node index offset from the containing
2102 /// base node, which points to inline assembly AST node. Next, navigate
2103 /// to the return type expression.
2104 node_offset_asm_ret_ty: i32,
2105 /// The source location points to the condition expression of an if
2106 /// expression, found by taking this AST node index offset from the containing
2107 /// base node, which points to an if expression AST node. Next, navigate
2108 /// to the condition expression.
2109 node_offset_if_cond: i32,
2110 /// The source location points to a binary expression, such as `a + b`, found
2111 /// by taking this AST node index offset from the containing base node.
2112 node_offset_bin_op: i32,
2113 /// The source location points to the LHS of a binary expression, found
2114 /// by taking this AST node index offset from the containing base node,
2115 /// which points to a binary expression AST node. Next, navigate to the LHS.
2116 node_offset_bin_lhs: i32,
2117 /// The source location points to the RHS of a binary expression, found
2118 /// by taking this AST node index offset from the containing base node,
2119 /// which points to a binary expression AST node. Next, navigate to the RHS.
2120 node_offset_bin_rhs: i32,
2121 /// The source location points to the operand of a switch expression, found
2122 /// by taking this AST node index offset from the containing base node,
2123 /// which points to a switch expression AST node. Next, navigate to the operand.
2124 node_offset_switch_operand: i32,
2125 /// The source location points to the else/`_` prong of a switch expression, found
2126 /// by taking this AST node index offset from the containing base node,
2127 /// which points to a switch expression AST node. Next, navigate to the else/`_` prong.
2128 node_offset_switch_special_prong: i32,
2129 /// The source location points to all the ranges of a switch expression, found
2130 /// by taking this AST node index offset from the containing base node,
2131 /// which points to a switch expression AST node. Next, navigate to any of the
2132 /// range nodes. The error applies to all of them.
2133 node_offset_switch_range: i32,
2134 /// The source location points to the align expr of a function type
2135 /// expression, found by taking this AST node index offset from the containing
2136 /// base node, which points to a function type AST node. Next, navigate to
2137 /// the calling convention node.
2138 node_offset_fn_type_align: i32,
2139 /// The source location points to the addrspace expr of a function type
2140 /// expression, found by taking this AST node index offset from the containing
2141 /// base node, which points to a function type AST node. Next, navigate to
2142 /// the calling convention node.
2143 node_offset_fn_type_addrspace: i32,
2144 /// The source location points to the linksection expr of a function type
2145 /// expression, found by taking this AST node index offset from the containing
2146 /// base node, which points to a function type AST node. Next, navigate to
2147 /// the calling convention node.
2148 node_offset_fn_type_section: i32,
2149 /// The source location points to the calling convention of a function type
2150 /// expression, found by taking this AST node index offset from the containing
2151 /// base node, which points to a function type AST node. Next, navigate to
2152 /// the calling convention node.
2153 node_offset_fn_type_cc: i32,
2154 /// The source location points to the return type of a function type
2155 /// expression, found by taking this AST node index offset from the containing
2156 /// base node, which points to a function type AST node. Next, navigate to
2157 /// the return type node.
2158 node_offset_fn_type_ret_ty: i32,
2159 node_offset_param: i32,
2160 token_offset_param: i32,
2161 /// The source location points to the type expression of an `anyframe->T`
2162 /// expression, found by taking this AST node index offset from the containing
2163 /// base node, which points to a `anyframe->T` expression AST node. Next, navigate
2164 /// to the type expression.
2165 node_offset_anyframe_type: i32,
2166 /// The source location points to the string literal of `extern "foo"`, found
2167 /// by taking this AST node index offset from the containing
2168 /// base node, which points to a function prototype or variable declaration
2169 /// expression AST node. Next, navigate to the string literal of the `extern "foo"`.
2170 node_offset_lib_name: i32,
2171 /// The source location points to the len expression of an `[N:S]T`
2172 /// expression, found by taking this AST node index offset from the containing
2173 /// base node, which points to an `[N:S]T` expression AST node. Next, navigate
2174 /// to the len expression.
2175 node_offset_array_type_len: i32,
2176 /// The source location points to the sentinel expression of an `[N:S]T`
2177 /// expression, found by taking this AST node index offset from the containing
2178 /// base node, which points to an `[N:S]T` expression AST node. Next, navigate
2179 /// to the sentinel expression.
2180 node_offset_array_type_sentinel: i32,
2181 /// The source location points to the elem expression of an `[N:S]T`
2182 /// expression, found by taking this AST node index offset from the containing
2183 /// base node, which points to an `[N:S]T` expression AST node. Next, navigate
2184 /// to the elem expression.
2185 node_offset_array_type_elem: i32,
2186 /// The source location points to the operand of an unary expression.
2187 node_offset_un_op: i32,
2188 /// The source location points to the elem type of a pointer.
2189 node_offset_ptr_elem: i32,
2190 /// The source location points to the sentinel of a pointer.
2191 node_offset_ptr_sentinel: i32,
2192 /// The source location points to the align expr of a pointer.
2193 node_offset_ptr_align: i32,
2194 /// The source location points to the addrspace expr of a pointer.
2195 node_offset_ptr_addrspace: i32,
2196 /// The source location points to the bit-offset of a pointer.
2197 node_offset_ptr_bitoffset: i32,
2198 /// The source location points to the host size of a pointer.
2199 node_offset_ptr_hostsize: i32,
2200 /// The source location points to the tag type of an union or an enum.
2201 node_offset_container_tag: i32,
2202 /// The source location points to the default value of a field.
2203 node_offset_field_default: i32,
2204 /// The source location points to the type of an array or struct initializer.
2205 node_offset_init_ty: i32,
2206 /// The source location points to the LHS of an assignment.
2207 node_offset_store_ptr: i32,
2208 /// The source location points to the RHS of an assignment.
2209 node_offset_store_operand: i32,
2210 /// The source location points to the operand of a `return` statement, or
2211 /// the `return` itself if there is no explicit operand.
2212 node_offset_return_operand: i32,
2213 /// The source location points to a for loop input.
2214 for_input: struct {
2215 /// Points to the for loop AST node.
2216 for_node_offset: i32,
2217 /// Picks one of the inputs from the condition.
2218 input_index: u32,
2219 },
2220 /// The source location points to one of the captures of a for loop, found
2221 /// by taking this AST node index offset from the containing
2222 /// base node, which points to one of the input nodes of a for loop.
2223 /// Next, navigate to the corresponding capture.
2224 for_capture_from_input: i32,
2225 /// The source location points to the argument node of a function call.
2226 call_arg: struct {
2227 /// Points to the function call AST node.
2228 call_node_offset: i32,
2229 /// The index of the argument the source location points to.
2230 arg_index: u32,
2231 },
2232 fn_proto_param: FnProtoParam,
2233 fn_proto_param_type: FnProtoParam,
2234 array_cat_lhs: ArrayCat,
2235 array_cat_rhs: ArrayCat,
2236 /// The source location points to the name of the field at the given index
2237 /// of the container type declaration at the base node.
2238 container_field_name: u32,
2239 /// Like `continer_field_name`, but points at the field's default value.
2240 container_field_value: u32,
2241 /// Like `continer_field_name`, but points at the field's type.
2242 container_field_type: u32,
2243 /// Like `continer_field_name`, but points at the field's alignment.
2244 container_field_align: u32,
2245 /// The source location points to the given element/field of a struct or
2246 /// array initialization expression.
2247 init_elem: struct {
2248 /// Points to the AST node of the initialization expression.
2249 init_node_offset: i32,
2250 /// The index of the field/element the source location points to.
2251 elem_index: u32,
2252 },
2253 // The following source locations are like `init_elem`, but refer to a
2254 // field with a specific name. If such a field is not given, the entire
2255 // initialization expression is used instead.
2256 // The `i32` points to the AST node of a builtin call, whose *second*
2257 // argument is the init expression.
2258 init_field_name: i32,
2259 init_field_linkage: i32,
2260 init_field_section: i32,
2261 init_field_visibility: i32,
2262 init_field_rw: i32,
2263 init_field_locality: i32,
2264 init_field_cache: i32,
2265 init_field_library: i32,
2266 init_field_thread_local: i32,
2267 /// The source location points to the value of an item in a specific
2268 /// case of a `switch`.
2269 switch_case_item: SwitchItem,
2270 /// The source location points to the "first" value of a range item in
2271 /// a specific case of a `switch`.
2272 switch_case_item_range_first: SwitchItem,
2273 /// The source location points to the "last" value of a range item in
2274 /// a specific case of a `switch`.
2275 switch_case_item_range_last: SwitchItem,
2276 /// The source location points to the main capture of a specific case of
2277 /// a `switch`.
2278 switch_capture: SwitchCapture,
2279 /// The source location points to the "tag" capture (second capture) of
2280 /// a specific case of a `switch`.
2281 switch_tag_capture: SwitchCapture,
2282
2283 pub const FnProtoParam = struct {
2284 /// The offset of the function prototype AST node.
2285 fn_proto_node_offset: i32,
2286 /// The index of the parameter the source location points to.
2287 param_index: u32,
2288 };
22352289
2236 pub const nodeOffset = if (TracedOffset.want_tracing) nodeOffsetDebug else nodeOffsetRelease;
2290 pub const SwitchItem = struct {
2291 /// The offset of the switch AST node.
2292 switch_node_offset: i32,
2293 /// The index of the case to point to within this switch.
2294 case_idx: SwitchCaseIndex,
2295 /// The index of the item to point to within this case.
2296 item_idx: SwitchItemIndex,
2297 };
22372298
2238 noinline fn nodeOffsetDebug(node_offset: i32) LazySrcLoc {
2239 var result: LazySrcLoc = .{ .node_offset = .{ .x = node_offset } };
2240 result.node_offset.trace.addAddr(@returnAddress(), "init");
2241 return result;
2242 }
2299 pub const SwitchCapture = struct {
2300 /// The offset of the switch AST node.
2301 switch_node_offset: i32,
2302 /// The index of the case whose capture to point to.
2303 case_idx: SwitchCaseIndex,
2304 };
22432305
2244 fn nodeOffsetRelease(node_offset: i32) LazySrcLoc {
2245 return .{ .node_offset = .{ .x = node_offset } };
2246 }
2306 pub const SwitchCaseIndex = packed struct(u32) {
2307 kind: enum(u1) { scalar, multi },
2308 index: u31,
22472309
2248 /// This wraps a simple integer in debug builds so that later on we can find out
2249 /// where in semantic analysis the value got set.
2250 pub const TracedOffset = struct {
2251 x: i32,
2252 trace: std.debug.Trace = std.debug.Trace.init,
2310 pub const special: SwitchCaseIndex = @bitCast(@as(u32, std.math.maxInt(u32)));
2311 pub fn isSpecial(idx: SwitchCaseIndex) bool {
2312 return @as(u32, @bitCast(idx)) == @as(u32, @bitCast(special));
2313 }
2314 };
2315
2316 pub const SwitchItemIndex = packed struct(u32) {
2317 kind: enum(u1) { single, range },
2318 index: u31,
2319 };
2320
2321 const ArrayCat = struct {
2322 /// Points to the array concat AST node.
2323 array_cat_offset: i32,
2324 /// The index of the element the source location points to.
2325 elem_index: u32,
2326 };
2327
2328 pub const nodeOffset = if (TracedOffset.want_tracing) nodeOffsetDebug else nodeOffsetRelease;
2329
2330 noinline fn nodeOffsetDebug(node_offset: i32) Offset {
2331 var result: LazySrcLoc = .{ .node_offset = .{ .x = node_offset } };
2332 result.node_offset.trace.addAddr(@returnAddress(), "init");
2333 return result;
2334 }
22532335
2254 const want_tracing = false;
2336 fn nodeOffsetRelease(node_offset: i32) Offset {
2337 return .{ .node_offset = .{ .x = node_offset } };
2338 }
2339
2340 /// This wraps a simple integer in debug builds so that later on we can find out
2341 /// where in semantic analysis the value got set.
2342 pub const TracedOffset = struct {
2343 x: i32,
2344 trace: std.debug.Trace = std.debug.Trace.init,
2345
2346 const want_tracing = false;
2347 };
22552348 };
2349
2350 pub const unneeded: LazySrcLoc = .{
2351 .base_node_inst = undefined,
2352 .offset = .unneeded,
2353 };
2354
2355 pub fn resolveBaseNode(base_node_inst: InternPool.TrackedInst.Index, zcu: *Zcu) struct { *File, Ast.Node.Index } {
2356 const want_path_digest, const zir_inst = inst: {
2357 const info = base_node_inst.resolveFull(&zcu.intern_pool);
2358 break :inst .{ info.path_digest, info.inst };
2359 };
2360 // TODO: avoid iterating all files for this!
2361 const file = for (zcu.import_table.values()) |file| {
2362 if (std.mem.eql(u8, &file.path_digest, &want_path_digest)) break file;
2363 } else unreachable;
2364 assert(file.zir_loaded);
2365
2366 const zir = file.zir;
2367 const inst = zir.instructions.get(@intFromEnum(zir_inst));
2368 const base_node: Ast.Node.Index = switch (inst.tag) {
2369 .declaration => inst.data.declaration.src_node,
2370 .extended => switch (inst.data.extended.opcode) {
2371 .struct_decl => zir.extraData(Zir.Inst.StructDecl, inst.data.extended.operand).data.src_node,
2372 .union_decl => zir.extraData(Zir.Inst.UnionDecl, inst.data.extended.operand).data.src_node,
2373 .enum_decl => zir.extraData(Zir.Inst.EnumDecl, inst.data.extended.operand).data.src_node,
2374 .opaque_decl => zir.extraData(Zir.Inst.OpaqueDecl, inst.data.extended.operand).data.src_node,
2375 else => unreachable,
2376 },
2377 else => unreachable,
2378 };
2379 return .{ file, base_node };
2380 }
2381
2382 /// Resolve the file and AST node of `base_node_inst` to get a resolved `SrcLoc`.
2383 /// TODO: it is incorrect to store a `SrcLoc` anywhere due to incremental compilation.
2384 /// Probably the type should be removed entirely and this resolution performed on-the-fly when needed.
2385 pub fn upgrade(lazy: LazySrcLoc, zcu: *Zcu) SrcLoc {
2386 const file, const base_node = resolveBaseNode(lazy.base_node_inst, zcu);
2387 return .{
2388 .file_scope = file,
2389 .base_node = base_node,
2390 .lazy = lazy.offset,
2391 };
2392 }
22562393};
22572394
22582395pub const SemaError = error{ OutOfMemory, AnalysisFail };
......@@ -2260,11 +2397,6 @@ pub const CompileError = error{
22602397 OutOfMemory,
22612398 /// When this is returned, the compile error for the failure has already been recorded.
22622399 AnalysisFail,
2263 /// Returned when a compile error needed to be reported but a provided LazySrcLoc was set
2264 /// to the `unneeded` tag. The source location was, in fact, needed. It is expected that
2265 /// somewhere up the call stack, the operation will be retried after doing expensive work
2266 /// to compute a source location.
2267 NeededSourceLocation,
22682400 /// A Type or Value was needed to be used during semantic analysis, but it was not available
22692401 /// because the function is generic. This is only seen when analyzing the body of a param
22702402 /// instruction.
......@@ -3373,7 +3505,6 @@ pub fn ensureDeclAnalyzed(mod: *Module, decl_index: Decl.Index) SemaError!void {
33733505 }
33743506 return error.AnalysisFail;
33753507 },
3376 error.NeededSourceLocation => unreachable,
33773508 error.GenericPoison => unreachable,
33783509 else => |e| {
33793510 decl.analysis = .sema_failure;
......@@ -3381,7 +3512,7 @@ pub fn ensureDeclAnalyzed(mod: *Module, decl_index: Decl.Index) SemaError!void {
33813512 try mod.retryable_failures.append(mod.gpa, InternPool.Depender.wrap(.{ .decl = decl_index }));
33823513 mod.failed_decls.putAssumeCapacityNoClobber(decl_index, try ErrorMsg.create(
33833514 mod.gpa,
3384 decl.srcLoc(mod),
3515 decl.navSrcLoc(mod).upgrade(mod),
33853516 "unable to analyze: {s}",
33863517 .{@errorName(e)},
33873518 ));
......@@ -3555,7 +3686,7 @@ pub fn ensureFuncBodyAnalyzed(zcu: *Zcu, maybe_coerced_func_index: InternPool.In
35553686 decl_index,
35563687 try Module.ErrorMsg.create(
35573688 gpa,
3558 decl.srcLoc(zcu),
3689 decl.navSrcLoc(zcu).upgrade(zcu),
35593690 "invalid liveness: {s}",
35603691 .{@errorName(err)},
35613692 ),
......@@ -3579,7 +3710,7 @@ pub fn ensureFuncBodyAnalyzed(zcu: *Zcu, maybe_coerced_func_index: InternPool.In
35793710 try zcu.failed_decls.ensureUnusedCapacity(gpa, 1);
35803711 zcu.failed_decls.putAssumeCapacityNoClobber(decl_index, try Module.ErrorMsg.create(
35813712 gpa,
3582 decl.srcLoc(zcu),
3713 decl.navSrcLoc(zcu).upgrade(zcu),
35833714 "unable to codegen: {s}",
35843715 .{@errorName(err)},
35853716 ));
......@@ -3814,7 +3945,7 @@ fn semaFile(mod: *Module, file: *File) SemaError!void {
38143945 });
38153946 errdefer mod.destroyNamespace(new_namespace_index);
38163947
3817 const new_decl_index = try mod.allocateNewDecl(new_namespace_index, 0);
3948 const new_decl_index = try mod.allocateNewDecl(new_namespace_index);
38183949 const new_decl = mod.declPtr(new_decl_index);
38193950 errdefer @panic("TODO error handling");
38203951
......@@ -3961,7 +4092,7 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !SemaDeclResult {
39614092 var analysis_arena = std.heap.ArenaAllocator.init(gpa);
39624093 defer analysis_arena.deinit();
39634094
3964 var comptime_err_ret_trace = std.ArrayList(SrcLoc).init(gpa);
4095 var comptime_err_ret_trace = std.ArrayList(LazySrcLoc).init(gpa);
39654096 defer comptime_err_ret_trace.deinit();
39664097
39674098 var sema: Sema = .{
......@@ -3996,6 +4127,7 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !SemaDeclResult {
39964127 .instructions = .{},
39974128 .inlining = null,
39984129 .is_comptime = true,
4130 .src_base_inst = decl.zir_decl_index.unwrap().?,
39994131 };
40004132 defer block_scope.instructions.deinit(gpa);
40014133
......@@ -4005,11 +4137,11 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !SemaDeclResult {
40054137 // We'll do some other bits with the Sema. Clear the type target index just
40064138 // in case they analyze any type.
40074139 sema.builtin_type_target_index = .none;
4008 const align_src: LazySrcLoc = .{ .node_offset_var_decl_align = 0 };
4009 const section_src: LazySrcLoc = .{ .node_offset_var_decl_section = 0 };
4010 const address_space_src: LazySrcLoc = .{ .node_offset_var_decl_addrspace = 0 };
4011 const ty_src: LazySrcLoc = .{ .node_offset_var_decl_ty = 0 };
4012 const init_src: LazySrcLoc = .{ .node_offset_var_decl_init = 0 };
4140 const align_src: LazySrcLoc = block_scope.src(.{ .node_offset_var_decl_align = 0 });
4141 const section_src: LazySrcLoc = block_scope.src(.{ .node_offset_var_decl_section = 0 });
4142 const address_space_src: LazySrcLoc = block_scope.src(.{ .node_offset_var_decl_addrspace = 0 });
4143 const ty_src: LazySrcLoc = block_scope.src(.{ .node_offset_var_decl_ty = 0 });
4144 const init_src: LazySrcLoc = block_scope.src(.{ .node_offset_var_decl_init = 0 });
40134145 const decl_val = try sema.resolveFinalDeclValue(&block_scope, init_src, result_ref);
40144146 const decl_ty = decl_val.typeOf(mod);
40154147
......@@ -4143,7 +4275,7 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !SemaDeclResult {
41434275 }
41444276
41454277 if (decl.is_exported) {
4146 const export_src: LazySrcLoc = .{ .token_offset = @intFromBool(decl.is_pub) };
4278 const export_src: LazySrcLoc = block_scope.src(.{ .token_offset = @intFromBool(decl.is_pub) });
41474279 if (is_inline) return sema.fail(&block_scope, export_src, "export of inline function", .{});
41484280 // The scope needs to have the decl in it.
41494281 try sema.analyzeExport(&block_scope, export_src, .{ .name = decl.name }, decl_index);
......@@ -4697,14 +4829,13 @@ fn scanDecl(iter: *ScanDeclIter, decl_inst: Zir.Inst.Index) Allocator.Error!void
46974829 const was_exported = decl.is_exported;
46984830 assert(decl.kind == kind); // ZIR tracking should preserve this
46994831 decl.name = decl_name;
4700 decl.src_node = inst_data.src_node;
47014832 decl.src_line = line;
47024833 decl.is_pub = declaration.flags.is_pub;
47034834 decl.is_exported = declaration.flags.is_export;
47044835 break :decl_index .{ was_exported, decl_index };
47054836 } else decl_index: {
47064837 // Create and set up a new Decl.
4707 const new_decl_index = try zcu.allocateNewDecl(namespace_index, inst_data.src_node);
4838 const new_decl_index = try zcu.allocateNewDecl(namespace_index);
47084839 const new_decl = zcu.declPtr(new_decl_index);
47094840 new_decl.kind = kind;
47104841 new_decl.name = decl_name;
......@@ -4858,7 +4989,7 @@ pub fn analyzeFnBody(mod: *Module, func_index: InternPool.Index, arena: Allocato
48584989
48594990 mod.intern_pool.removeDependenciesForDepender(gpa, InternPool.Depender.wrap(.{ .func = func_index }));
48604991
4861 var comptime_err_ret_trace = std.ArrayList(SrcLoc).init(gpa);
4992 var comptime_err_ret_trace = std.ArrayList(LazySrcLoc).init(gpa);
48624993 defer comptime_err_ret_trace.deinit();
48634994
48644995 // In the case of a generic function instance, this is the type of the
......@@ -4913,6 +5044,14 @@ pub fn analyzeFnBody(mod: *Module, func_index: InternPool.Index, arena: Allocato
49135044 .instructions = .{},
49145045 .inlining = null,
49155046 .is_comptime = false,
5047 .src_base_inst = inst: {
5048 const owner_info = if (func.generic_owner == .none)
5049 func
5050 else
5051 mod.funcInfo(func.generic_owner);
5052 const orig_decl = mod.declPtr(owner_info.owner_decl);
5053 break :inst orig_decl.zir_decl_index.unwrap().?;
5054 },
49165055 };
49175056 defer inner_block.instructions.deinit(gpa);
49185057
......@@ -4954,7 +5093,6 @@ pub fn analyzeFnBody(mod: *Module, func_index: InternPool.Index, arena: Allocato
49545093 runtime_param_index += 1;
49555094
49565095 const opt_opv = sema.typeHasOnePossibleValue(Type.fromInterned(param_ty)) catch |err| switch (err) {
4957 error.NeededSourceLocation => unreachable,
49585096 error.GenericPoison => unreachable,
49595097 error.ComptimeReturn => unreachable,
49605098 error.ComptimeBreak => unreachable,
......@@ -4988,7 +5126,6 @@ pub fn analyzeFnBody(mod: *Module, func_index: InternPool.Index, arena: Allocato
49885126
49895127 sema.analyzeFnBody(&inner_block, fn_info.body) catch |err| switch (err) {
49905128 // TODO make these unreachable instead of @panic
4991 error.NeededSourceLocation => @panic("zig compiler bug: NeededSourceLocation"),
49925129 error.GenericPoison => @panic("zig compiler bug: GenericPoison"),
49935130 error.ComptimeReturn => @panic("zig compiler bug: ComptimeReturn"),
49945131 else => |e| return e,
......@@ -5010,7 +5147,6 @@ pub fn analyzeFnBody(mod: *Module, func_index: InternPool.Index, arena: Allocato
50105147 {
50115148 sema.setupErrorReturnTrace(&inner_block, last_arg_index) catch |err| switch (err) {
50125149 // TODO make these unreachable instead of @panic
5013 error.NeededSourceLocation => @panic("zig compiler bug: NeededSourceLocation"),
50145150 error.GenericPoison => @panic("zig compiler bug: GenericPoison"),
50155151 error.ComptimeReturn => @panic("zig compiler bug: ComptimeReturn"),
50165152 error.ComptimeBreak => @panic("zig compiler bug: ComptimeBreak"),
......@@ -5031,8 +5167,10 @@ pub fn analyzeFnBody(mod: *Module, func_index: InternPool.Index, arena: Allocato
50315167 // state to success, so that "unable to resolve inferred error set" errors
50325168 // can be emitted here.
50335169 if (sema.fn_ret_ty_ies) |ies| {
5034 sema.resolveInferredErrorSetPtr(&inner_block, LazySrcLoc.nodeOffset(0), ies) catch |err| switch (err) {
5035 error.NeededSourceLocation => unreachable,
5170 sema.resolveInferredErrorSetPtr(&inner_block, .{
5171 .base_node_inst = inner_block.src_base_inst,
5172 .offset = LazySrcLoc.Offset.nodeOffset(0),
5173 }, ies) catch |err| switch (err) {
50365174 error.GenericPoison => unreachable,
50375175 error.ComptimeReturn => unreachable,
50385176 error.ComptimeBreak => unreachable,
......@@ -5056,7 +5194,6 @@ pub fn analyzeFnBody(mod: *Module, func_index: InternPool.Index, arena: Allocato
50565194 // so that dependencies on the function body will now be satisfied rather than
50575195 // result in circular dependency errors.
50585196 sema.resolveFnTypes(fn_ty) catch |err| switch (err) {
5059 error.NeededSourceLocation => unreachable,
50605197 error.GenericPoison => unreachable,
50615198 error.ComptimeReturn => unreachable,
50625199 error.ComptimeBreak => unreachable,
......@@ -5073,7 +5210,6 @@ pub fn analyzeFnBody(mod: *Module, func_index: InternPool.Index, arena: Allocato
50735210 // the backends.
50745211 for (sema.types_to_resolve.keys()) |ty| {
50755212 sema.resolveTypeFully(Type.fromInterned(ty)) catch |err| switch (err) {
5076 error.NeededSourceLocation => unreachable,
50775213 error.GenericPoison => unreachable,
50785214 error.ComptimeReturn => unreachable,
50795215 error.ComptimeBreak => unreachable,
......@@ -5101,17 +5237,11 @@ pub fn destroyNamespace(mod: *Module, index: Namespace.Index) void {
51015237 return mod.intern_pool.destroyNamespace(mod.gpa, index);
51025238}
51035239
5104pub fn allocateNewDecl(
5105 mod: *Module,
5106 namespace: Namespace.Index,
5107 src_node: Ast.Node.Index,
5108) !Decl.Index {
5109 const ip = &mod.intern_pool;
5110 const gpa = mod.gpa;
5111 const decl_index = try ip.createDecl(gpa, .{
5240pub fn allocateNewDecl(zcu: *Zcu, namespace: Namespace.Index) !Decl.Index {
5241 const gpa = zcu.gpa;
5242 const decl_index = try zcu.intern_pool.createDecl(gpa, .{
51125243 .name = undefined,
51135244 .src_namespace = namespace,
5114 .src_node = src_node,
51155245 .src_line = undefined,
51165246 .has_tv = false,
51175247 .owns_tv = false,
......@@ -5126,10 +5256,10 @@ pub fn allocateNewDecl(
51265256 .kind = .anon,
51275257 });
51285258
5129 if (mod.emit_h) |mod_emit_h| {
5130 if (@intFromEnum(decl_index) >= mod_emit_h.allocated_emit_h.len) {
5131 try mod_emit_h.allocated_emit_h.append(gpa, .{});
5132 assert(@intFromEnum(decl_index) == mod_emit_h.allocated_emit_h.len);
5259 if (zcu.emit_h) |zcu_emit_h| {
5260 if (@intFromEnum(decl_index) >= zcu_emit_h.allocated_emit_h.len) {
5261 try zcu_emit_h.allocated_emit_h.append(gpa, .{});
5262 assert(@intFromEnum(decl_index) == zcu_emit_h.allocated_emit_h.len);
51335263 }
51345264 }
51355265
......@@ -5223,376 +5353,6 @@ fn lockAndClearFileCompileError(mod: *Module, file: *File) void {
52235353 }
52245354}
52255355
5226pub const SwitchProngSrc = union(enum) {
5227 /// The item for a scalar prong.
5228 scalar: u32,
5229 /// A given single item for a multi prong.
5230 multi: Multi,
5231 /// A given range item for a multi prong.
5232 range: Multi,
5233 /// The item for the special prong.
5234 special,
5235 /// The main capture for a scalar prong.
5236 scalar_capture: u32,
5237 /// The main capture for a multi prong.
5238 multi_capture: u32,
5239 /// The main capture for the special prong.
5240 special_capture,
5241 /// The tag capture for a scalar prong.
5242 scalar_tag_capture: u32,
5243 /// The tag capture for a multi prong.
5244 multi_tag_capture: u32,
5245 /// The tag capture for the special prong.
5246 special_tag_capture,
5247
5248 pub const Multi = struct {
5249 prong: u32,
5250 item: u32,
5251 };
5252
5253 pub const RangeExpand = enum { none, first, last };
5254
5255 /// This function is intended to be called only when it is certain that we need
5256 /// the LazySrcLoc in order to emit a compile error.
5257 pub fn resolve(
5258 prong_src: SwitchProngSrc,
5259 mod: *Module,
5260 decl: *Decl,
5261 switch_node_offset: i32,
5262 /// Ignored if `prong_src` is not `.range`
5263 range_expand: RangeExpand,
5264 ) LazySrcLoc {
5265 @setCold(true);
5266 const gpa = mod.gpa;
5267 const tree = decl.getFileScope(mod).getTree(gpa) catch |err| {
5268 // In this case we emit a warning + a less precise source location.
5269 log.warn("unable to load {s}: {s}", .{
5270 decl.getFileScope(mod).sub_file_path, @errorName(err),
5271 });
5272 return LazySrcLoc.nodeOffset(0);
5273 };
5274 const switch_node = decl.relativeToNodeIndex(switch_node_offset);
5275 const main_tokens = tree.nodes.items(.main_token);
5276 const node_datas = tree.nodes.items(.data);
5277 const node_tags = tree.nodes.items(.tag);
5278 const extra = tree.extraData(node_datas[switch_node].rhs, Ast.Node.SubRange);
5279 const case_nodes = tree.extra_data[extra.start..extra.end];
5280
5281 var multi_i: u32 = 0;
5282 var scalar_i: u32 = 0;
5283 const case_node = for (case_nodes) |case_node| {
5284 const case = tree.fullSwitchCase(case_node).?;
5285
5286 const is_special = special: {
5287 if (case.ast.values.len == 0) break :special true;
5288 if (case.ast.values.len == 1 and node_tags[case.ast.values[0]] == .identifier) {
5289 break :special mem.eql(u8, tree.tokenSlice(main_tokens[case.ast.values[0]]), "_");
5290 }
5291 break :special false;
5292 };
5293
5294 if (is_special) {
5295 switch (prong_src) {
5296 .special, .special_capture, .special_tag_capture => break case_node,
5297 else => continue,
5298 }
5299 }
5300
5301 const is_multi = case.ast.values.len != 1 or
5302 node_tags[case.ast.values[0]] == .switch_range;
5303
5304 switch (prong_src) {
5305 .scalar,
5306 .scalar_capture,
5307 .scalar_tag_capture,
5308 => |i| if (!is_multi and i == scalar_i) break case_node,
5309
5310 .multi_capture,
5311 .multi_tag_capture,
5312 => |i| if (is_multi and i == multi_i) break case_node,
5313
5314 .multi,
5315 .range,
5316 => |m| if (is_multi and m.prong == multi_i) break case_node,
5317
5318 .special,
5319 .special_capture,
5320 .special_tag_capture,
5321 => {},
5322 }
5323
5324 if (is_multi) {
5325 multi_i += 1;
5326 } else {
5327 scalar_i += 1;
5328 }
5329 } else unreachable;
5330
5331 const case = tree.fullSwitchCase(case_node).?;
5332
5333 switch (prong_src) {
5334 .scalar, .special => return LazySrcLoc.nodeOffset(
5335 decl.nodeIndexToRelative(case.ast.values[0]),
5336 ),
5337 .multi => |m| {
5338 var item_i: u32 = 0;
5339 for (case.ast.values) |item_node| {
5340 if (node_tags[item_node] == .switch_range) continue;
5341 if (item_i == m.item) return LazySrcLoc.nodeOffset(
5342 decl.nodeIndexToRelative(item_node),
5343 );
5344 item_i += 1;
5345 }
5346 unreachable;
5347 },
5348 .range => |m| {
5349 var range_i: u32 = 0;
5350 for (case.ast.values) |range| {
5351 if (node_tags[range] != .switch_range) continue;
5352 if (range_i == m.item) switch (range_expand) {
5353 .none => return LazySrcLoc.nodeOffset(
5354 decl.nodeIndexToRelative(range),
5355 ),
5356 .first => return LazySrcLoc.nodeOffset(
5357 decl.nodeIndexToRelative(node_datas[range].lhs),
5358 ),
5359 .last => return LazySrcLoc.nodeOffset(
5360 decl.nodeIndexToRelative(node_datas[range].rhs),
5361 ),
5362 };
5363 range_i += 1;
5364 }
5365 unreachable;
5366 },
5367 .scalar_capture, .multi_capture, .special_capture => {
5368 return .{ .node_offset_switch_prong_capture = decl.nodeIndexToRelative(case_node) };
5369 },
5370 .scalar_tag_capture, .multi_tag_capture, .special_tag_capture => {
5371 return .{ .node_offset_switch_prong_tag_capture = decl.nodeIndexToRelative(case_node) };
5372 },
5373 }
5374 }
5375};
5376
5377pub const PeerTypeCandidateSrc = union(enum) {
5378 /// Do not print out error notes for candidate sources
5379 none: void,
5380 /// When we want to know the the src of candidate i, look up at
5381 /// index i in this slice
5382 override: []const ?LazySrcLoc,
5383 /// resolvePeerTypes originates from a @TypeOf(...) call
5384 typeof_builtin_call_node_offset: i32,
5385
5386 pub fn resolve(
5387 self: PeerTypeCandidateSrc,
5388 mod: *Module,
5389 decl: *Decl,
5390 candidate_i: usize,
5391 ) ?LazySrcLoc {
5392 @setCold(true);
5393 const gpa = mod.gpa;
5394
5395 switch (self) {
5396 .none => {
5397 return null;
5398 },
5399 .override => |candidate_srcs| {
5400 if (candidate_i >= candidate_srcs.len)
5401 return null;
5402 return candidate_srcs[candidate_i];
5403 },
5404 .typeof_builtin_call_node_offset => |node_offset| {
5405 switch (candidate_i) {
5406 0 => return LazySrcLoc{ .node_offset_builtin_call_arg0 = node_offset },
5407 1 => return LazySrcLoc{ .node_offset_builtin_call_arg1 = node_offset },
5408 2 => return LazySrcLoc{ .node_offset_builtin_call_arg2 = node_offset },
5409 3 => return LazySrcLoc{ .node_offset_builtin_call_arg3 = node_offset },
5410 4 => return LazySrcLoc{ .node_offset_builtin_call_arg4 = node_offset },
5411 5 => return LazySrcLoc{ .node_offset_builtin_call_arg5 = node_offset },
5412 else => {},
5413 }
5414
5415 const tree = decl.getFileScope(mod).getTree(gpa) catch |err| {
5416 // In this case we emit a warning + a less precise source location.
5417 log.warn("unable to load {s}: {s}", .{
5418 decl.getFileScope(mod).sub_file_path, @errorName(err),
5419 });
5420 return LazySrcLoc.nodeOffset(0);
5421 };
5422 const node = decl.relativeToNodeIndex(node_offset);
5423 const node_datas = tree.nodes.items(.data);
5424 const params = tree.extra_data[node_datas[node].lhs..node_datas[node].rhs];
5425
5426 return LazySrcLoc{ .node_abs = params[candidate_i] };
5427 },
5428 }
5429 }
5430};
5431
5432const FieldSrcQuery = struct {
5433 index: usize,
5434 range: enum { name, type, value, alignment } = .name,
5435};
5436
5437fn queryFieldSrc(
5438 tree: Ast,
5439 query: FieldSrcQuery,
5440 file_scope: *File,
5441 container_decl: Ast.full.ContainerDecl,
5442) SrcLoc {
5443 var field_index: usize = 0;
5444 for (container_decl.ast.members) |member_node| {
5445 const field = tree.fullContainerField(member_node) orelse continue;
5446 if (field_index == query.index) {
5447 return switch (query.range) {
5448 .name => .{
5449 .file_scope = file_scope,
5450 .parent_decl_node = 0,
5451 .lazy = .{ .token_abs = field.ast.main_token },
5452 },
5453 .type => .{
5454 .file_scope = file_scope,
5455 .parent_decl_node = 0,
5456 .lazy = .{ .node_abs = field.ast.type_expr },
5457 },
5458 .value => .{
5459 .file_scope = file_scope,
5460 .parent_decl_node = 0,
5461 .lazy = .{ .node_abs = field.ast.value_expr },
5462 },
5463 .alignment => .{
5464 .file_scope = file_scope,
5465 .parent_decl_node = 0,
5466 .lazy = .{ .node_abs = field.ast.align_expr },
5467 },
5468 };
5469 }
5470 field_index += 1;
5471 }
5472 unreachable;
5473}
5474
5475pub fn paramSrc(
5476 func_node_offset: i32,
5477 mod: *Module,
5478 decl: *Decl,
5479 param_i: usize,
5480) LazySrcLoc {
5481 @setCold(true);
5482 const gpa = mod.gpa;
5483 const tree = decl.getFileScope(mod).getTree(gpa) catch |err| {
5484 // In this case we emit a warning + a less precise source location.
5485 log.warn("unable to load {s}: {s}", .{
5486 decl.getFileScope(mod).sub_file_path, @errorName(err),
5487 });
5488 return LazySrcLoc.nodeOffset(0);
5489 };
5490 const node = decl.relativeToNodeIndex(func_node_offset);
5491 var buf: [1]Ast.Node.Index = undefined;
5492 const full = tree.fullFnProto(&buf, node).?;
5493 var it = full.iterate(tree);
5494 var i: usize = 0;
5495 while (it.next()) |param| : (i += 1) {
5496 if (i == param_i) {
5497 if (param.anytype_ellipsis3) |some| {
5498 const main_token = tree.nodes.items(.main_token)[decl.src_node];
5499 return .{ .token_offset_param = @as(i32, @bitCast(some)) - @as(i32, @bitCast(main_token)) };
5500 }
5501 return .{ .node_offset_param = decl.nodeIndexToRelative(param.type_expr) };
5502 }
5503 }
5504 unreachable;
5505}
5506
5507pub fn initSrc(
5508 mod: *Module,
5509 init_node_offset: i32,
5510 decl: *Decl,
5511 init_index: usize,
5512) LazySrcLoc {
5513 @setCold(true);
5514 const gpa = mod.gpa;
5515 const tree = decl.getFileScope(mod).getTree(gpa) catch |err| {
5516 // In this case we emit a warning + a less precise source location.
5517 log.warn("unable to load {s}: {s}", .{
5518 decl.getFileScope(mod).sub_file_path, @errorName(err),
5519 });
5520 return LazySrcLoc.nodeOffset(0);
5521 };
5522 const node_tags = tree.nodes.items(.tag);
5523 const node = decl.relativeToNodeIndex(init_node_offset);
5524 var buf: [2]Ast.Node.Index = undefined;
5525 switch (node_tags[node]) {
5526 .array_init_one,
5527 .array_init_one_comma,
5528 .array_init_dot_two,
5529 .array_init_dot_two_comma,
5530 .array_init_dot,
5531 .array_init_dot_comma,
5532 .array_init,
5533 .array_init_comma,
5534 => {
5535 const full = tree.fullArrayInit(&buf, node).?.ast.elements;
5536 return LazySrcLoc.nodeOffset(decl.nodeIndexToRelative(full[init_index]));
5537 },
5538 .struct_init_one,
5539 .struct_init_one_comma,
5540 .struct_init_dot_two,
5541 .struct_init_dot_two_comma,
5542 .struct_init_dot,
5543 .struct_init_dot_comma,
5544 .struct_init,
5545 .struct_init_comma,
5546 => {
5547 const full = tree.fullStructInit(&buf, node).?.ast.fields;
5548 return LazySrcLoc{ .node_offset_initializer = decl.nodeIndexToRelative(full[init_index]) };
5549 },
5550 else => return LazySrcLoc.nodeOffset(init_node_offset),
5551 }
5552}
5553
5554pub fn optionsSrc(mod: *Module, decl: *Decl, base_src: LazySrcLoc, wanted: []const u8) LazySrcLoc {
5555 @setCold(true);
5556 const gpa = mod.gpa;
5557 const tree = decl.getFileScope(mod).getTree(gpa) catch |err| {
5558 // In this case we emit a warning + a less precise source location.
5559 log.warn("unable to load {s}: {s}", .{
5560 decl.getFileScope(mod).sub_file_path, @errorName(err),
5561 });
5562 return LazySrcLoc.nodeOffset(0);
5563 };
5564
5565 const o_i: struct { off: i32, i: u8 } = switch (base_src) {
5566 .node_offset_builtin_call_arg0 => |n| .{ .off = n, .i = 0 },
5567 .node_offset_builtin_call_arg1 => |n| .{ .off = n, .i = 1 },
5568 else => unreachable,
5569 };
5570
5571 const node = decl.relativeToNodeIndex(o_i.off);
5572 const node_datas = tree.nodes.items(.data);
5573 const node_tags = tree.nodes.items(.tag);
5574 const arg_node = switch (node_tags[node]) {
5575 .builtin_call_two, .builtin_call_two_comma => switch (o_i.i) {
5576 0 => node_datas[node].lhs,
5577 1 => node_datas[node].rhs,
5578 else => unreachable,
5579 },
5580 .builtin_call, .builtin_call_comma => tree.extra_data[node_datas[node].lhs + o_i.i],
5581 else => unreachable,
5582 };
5583 var buf: [2]std.zig.Ast.Node.Index = undefined;
5584 const init_nodes = if (tree.fullStructInit(&buf, arg_node)) |struct_init| struct_init.ast.fields else return base_src;
5585 for (init_nodes) |init_node| {
5586 // . IDENTIFIER = init_node
5587 const name_token = tree.firstToken(init_node) - 2;
5588 const name = tree.tokenSlice(name_token);
5589 if (std.mem.eql(u8, name, wanted)) {
5590 return LazySrcLoc{ .node_offset_initializer = decl.nodeIndexToRelative(init_node) };
5591 }
5592 }
5593 return base_src;
5594}
5595
55965356/// Called from `Compilation.update`, after everything is done, just before
55975357/// reporting compile errors. In this function we emit exported symbol collision
55985358/// errors and communicate exported symbols to the linker backend.
......@@ -5826,7 +5586,7 @@ pub fn linkerUpdateDecl(zcu: *Zcu, decl_index: Decl.Index) !void {
58265586 try zcu.failed_decls.ensureUnusedCapacity(gpa, 1);
58275587 zcu.failed_decls.putAssumeCapacityNoClobber(decl_index, try ErrorMsg.create(
58285588 gpa,
5829 decl.srcLoc(zcu),
5589 decl.navSrcLoc(zcu).upgrade(zcu),
58305590 "unable to codegen: {s}",
58315591 .{@errorName(err)},
58325592 ));
......@@ -5857,7 +5617,7 @@ fn reportRetryableFileError(
58575617 mod.gpa,
58585618 .{
58595619 .file_scope = file,
5860 .parent_decl_node = 0,
5620 .base_node = 0,
58615621 .lazy = .entire_file,
58625622 },
58635623 format,
......@@ -6432,27 +6192,6 @@ pub fn funcInfo(mod: *Module, func_index: InternPool.Index) InternPool.Key.Func
64326192 return mod.intern_pool.indexToKey(func_index).func;
64336193}
64346194
6435pub fn fieldSrcLoc(mod: *Module, owner_decl_index: Decl.Index, query: FieldSrcQuery) SrcLoc {
6436 @setCold(true);
6437 const owner_decl = mod.declPtr(owner_decl_index);
6438 const file = owner_decl.getFileScope(mod);
6439 const tree = file.getTree(mod.gpa) catch |err| {
6440 // In this case we emit a warning + a less precise source location.
6441 log.warn("unable to load {s}: {s}", .{
6442 file.sub_file_path, @errorName(err),
6443 });
6444 return owner_decl.srcLoc(mod);
6445 };
6446 const node = owner_decl.relativeToNodeIndex(0);
6447 var buf: [2]Ast.Node.Index = undefined;
6448 if (tree.fullContainerDecl(&buf, node)) |container_decl| {
6449 return queryFieldSrc(tree.*, query, file, container_decl);
6450 } else {
6451 // This type was generated using @Type
6452 return owner_decl.srcLoc(mod);
6453 }
6454}
6455
64566195pub fn toEnum(mod: *Module, comptime E: type, val: Value) E {
64576196 return mod.intern_pool.toEnum(E, val.toIntern());
64586197}
src/RangeSet.zig+4-4
......@@ -7,7 +7,7 @@ const Type = @import("type.zig").Type;
77const Value = @import("Value.zig");
88const Module = @import("Module.zig");
99const RangeSet = @This();
10const SwitchProngSrc = @import("Module.zig").SwitchProngSrc;
10const LazySrcLoc = @import("Module.zig").LazySrcLoc;
1111
1212ranges: std.ArrayList(Range),
1313module: *Module,
......@@ -15,7 +15,7 @@ module: *Module,
1515pub const Range = struct {
1616 first: InternPool.Index,
1717 last: InternPool.Index,
18 src: SwitchProngSrc,
18 src: LazySrcLoc,
1919};
2020
2121pub fn init(allocator: std.mem.Allocator, module: *Module) RangeSet {
......@@ -33,8 +33,8 @@ pub fn add(
3333 self: *RangeSet,
3434 first: InternPool.Index,
3535 last: InternPool.Index,
36 src: SwitchProngSrc,
37) !?SwitchProngSrc {
36 src: LazySrcLoc,
37) !?LazySrcLoc {
3838 const mod = self.module;
3939 const ip = &mod.intern_pool;
4040
src/Sema.zig+1497-1669
......@@ -34,7 +34,7 @@ func_index: InternPool.Index,
3434func_is_naked: bool,
3535/// Used to restore the error return trace when returning a non-error from a function.
3636error_return_trace_index_on_fn_entry: Air.Inst.Ref = .none,
37comptime_err_ret_trace: *std.ArrayList(Module.SrcLoc),
37comptime_err_ret_trace: *std.ArrayList(LazySrcLoc),
3838/// When semantic analysis needs to know the return type of the function whose body
3939/// is being analyzed, this `Type` should be used instead of going through `func`.
4040/// This will correctly handle the case of a comptime/inline function call of a
......@@ -65,9 +65,7 @@ generic_owner: InternPool.Index = .none,
6565/// instantiation callsite so that compile errors on the parameter types of the
6666/// instantiation can point back to the instantiation site in addition to the
6767/// declaration site.
68generic_call_src: LazySrcLoc = .unneeded,
69/// Corresponds to `generic_call_src`.
70generic_call_decl: InternPool.OptionalDeclIndex = .none,
68generic_call_src: LazySrcLoc = LazySrcLoc.unneeded,
7169/// The key is types that must be fully resolved prior to machine code
7270/// generation pass. Types are added to this set when resolving them
7371/// immediately could cause a dependency loop, but they do need to be resolved
......@@ -131,7 +129,6 @@ const MaybeComptimeAlloc = struct {
131129 /// If the instruction is one of these three tags, `src` may be `.unneeded`.
132130 stores: std.MultiArrayList(struct {
133131 inst: Air.Inst.Index,
134 src_decl: InternPool.DeclIndex,
135132 src: LazySrcLoc,
136133 }) = .{},
137134};
......@@ -361,8 +358,8 @@ pub const Block = struct {
361358 label: ?*Label = null,
362359 inlining: ?*Inlining,
363360 /// If runtime_index is not 0 then one of these is guaranteed to be non null.
364 runtime_cond: ?Module.SrcLoc = null,
365 runtime_loop: ?Module.SrcLoc = null,
361 runtime_cond: ?LazySrcLoc = null,
362 runtime_loop: ?LazySrcLoc = null,
366363 /// This Decl is the Decl according to the Zig source code corresponding to this Block.
367364 /// This can vary during inline or comptime function calls. See `Sema.owner_decl`
368365 /// for the one that will be the same for all Block instances.
......@@ -395,25 +392,39 @@ pub const Block = struct {
395392 /// `block` in order for codegen to match lexical scoping for debug vars.
396393 need_debug_scope: ?*bool = null,
397394
398 // These functions will be less stupid soon!
395 /// Relative source locations encountered while traversing this block should be
396 /// treated as relative to the AST node of this ZIR instruction.
397 src_base_inst: InternPool.TrackedInst.Index,
398
399 /// Create a `LazySrcLoc` based on an `Offset` from the code being analyzed in this block.
400 /// Specifically, the given `Offset` is treated as relative to `block.src_base_inst`.
401 pub fn src(block: Block, offset: LazySrcLoc.Offset) LazySrcLoc {
402 return .{
403 .base_node_inst = block.src_base_inst,
404 .offset = offset,
405 };
406 }
407
408 fn builtinCallArgSrc(block: *Block, builtin_call_node: i32, arg_index: u32) LazySrcLoc {
409 return block.src(.{ .node_offset_builtin_call_arg = .{
410 .builtin_call_node = builtin_call_node,
411 .arg_index = arg_index,
412 } });
413 }
399414
400415 fn nodeOffset(block: Block, node_offset: i32) LazySrcLoc {
401 _ = block;
402 return LazySrcLoc.nodeOffset(node_offset);
416 return block.src(LazySrcLoc.Offset.nodeOffset(node_offset));
403417 }
404418
405419 fn tokenOffset(block: Block, tok_offset: u32) LazySrcLoc {
406 _ = block;
407 return .{ .token_offset = tok_offset };
420 return block.src(.{ .token_offset = tok_offset });
408421 }
409422
410423 const ComptimeReason = union(enum) {
411424 c_import: struct {
412 block: *Block,
413425 src: LazySrcLoc,
414426 },
415427 comptime_ret_ty: struct {
416 block: *Block,
417428 func: Air.Inst.Ref,
418429 func_src: LazySrcLoc,
419430 return_ty: Type,
......@@ -425,27 +436,23 @@ pub const Block = struct {
425436 const prefix = "expression is evaluated at comptime because ";
426437 switch (cr) {
427438 .c_import => |ci| {
428 try sema.errNote(ci.block, ci.src, parent, prefix ++ "it is inside a @cImport", .{});
439 try sema.errNote(ci.src, parent, prefix ++ "it is inside a @cImport", .{});
429440 },
430441 .comptime_ret_ty => |rt| {
431 const src_loc = if (try sema.funcDeclSrc(rt.func)) |fn_decl| blk: {
432 var src_loc = fn_decl.srcLoc(mod);
433 src_loc.lazy = .{ .node_offset_fn_type_ret_ty = 0 };
434 break :blk src_loc;
435 } else blk: {
436 const src_decl = mod.declPtr(rt.block.src_decl);
437 break :blk src_decl.toSrcLoc(rt.func_src, mod);
438 };
442 const ret_ty_src: LazySrcLoc = if (try sema.funcDeclSrc(rt.func)) |fn_decl| .{
443 .base_node_inst = fn_decl.zir_decl_index.unwrap().?,
444 .offset = .{ .node_offset_fn_type_ret_ty = 0 },
445 } else rt.func_src;
439446 if (rt.return_ty.isGenericPoison()) {
440 return mod.errNoteNonLazy(src_loc, parent, prefix ++ "the generic function was instantiated with a comptime-only return type", .{});
447 return sema.errNote(ret_ty_src, parent, prefix ++ "the generic function was instantiated with a comptime-only return type", .{});
441448 }
442 try mod.errNoteNonLazy(
443 src_loc,
449 try sema.errNote(
450 ret_ty_src,
444451 parent,
445452 prefix ++ "the function returns a comptime-only type '{}'",
446453 .{rt.return_ty.fmt(mod)},
447454 );
448 try sema.explainWhyTypeIsComptime(parent, src_loc, rt.return_ty);
455 try sema.explainWhyTypeIsComptime(parent, ret_ty_src, rt.return_ty);
449456 },
450457 }
451458 }
......@@ -525,6 +532,7 @@ pub const Block = struct {
525532 .c_import_buf = parent.c_import_buf,
526533 .error_return_trace_index = parent.error_return_trace_index,
527534 .need_debug_scope = parent.need_debug_scope,
535 .src_base_inst = parent.src_base_inst,
528536 };
529537 }
530538
......@@ -815,14 +823,6 @@ pub const Block = struct {
815823 return result_index;
816824 }
817825
818 fn addUnreachable(block: *Block, src: LazySrcLoc, safety_check: bool) !void {
819 if (safety_check and block.wantSafety()) {
820 try block.sema.safetyPanic(block, src, .unreach);
821 } else {
822 _ = try block.addNoOp(.unreach);
823 }
824 }
825
826826 pub fn ownerModule(block: Block) *Package.Module {
827827 const zcu = block.sema.mod;
828828 return zcu.namespacePtr(block.namespace).file_scope.mod;
......@@ -1237,7 +1237,7 @@ fn analyzeBodyInner(
12371237 .@"asm" => try sema.zirAsm( block, extended, false),
12381238 .asm_expr => try sema.zirAsm( block, extended, true),
12391239 .typeof_peer => try sema.zirTypeofPeer( block, extended, inst),
1240 .compile_log => try sema.zirCompileLog( extended),
1240 .compile_log => try sema.zirCompileLog( block, extended),
12411241 .min_multi => try sema.zirMinMaxMulti( block, extended, .min),
12421242 .max_multi => try sema.zirMinMaxMulti( block, extended, .max),
12431243 .add_with_overflow => try sema.zirOverflowArithmetic(block, extended, extended.opcode),
......@@ -1475,10 +1475,9 @@ fn analyzeBodyInner(
14751475 if (@intFromEnum(target_runtime_index) < @intFromEnum(block.runtime_index)) {
14761476 const runtime_src = block.runtime_cond orelse block.runtime_loop.?;
14771477 const msg = msg: {
1478 const msg = try sema.errMsg(block, src, "comptime control flow inside runtime block", .{});
1478 const msg = try sema.errMsg(src, "comptime control flow inside runtime block", .{});
14791479 errdefer msg.destroy(sema.gpa);
1480
1481 try mod.errNoteNonLazy(runtime_src, msg, "runtime control flow here", .{});
1480 try sema.errNote(runtime_src, msg, "runtime control flow here", .{});
14821481 break :msg msg;
14831482 };
14841483 return sema.failWithOwnedErrorMsg(block, msg);
......@@ -1522,7 +1521,7 @@ fn analyzeBodyInner(
15221521 .repeat => {
15231522 if (block.is_comptime) {
15241523 // Send comptime control flow back to the beginning of this block.
1525 const src = LazySrcLoc.nodeOffset(datas[@intFromEnum(inst)].node);
1524 const src = block.nodeOffset(datas[@intFromEnum(inst)].node);
15261525 try sema.emitBackwardBranch(block, src);
15271526 i = 0;
15281527 continue;
......@@ -1535,7 +1534,7 @@ fn analyzeBodyInner(
15351534 },
15361535 .repeat_inline => {
15371536 // Send comptime control flow back to the beginning of this block.
1538 const src = LazySrcLoc.nodeOffset(datas[@intFromEnum(inst)].node);
1537 const src = block.nodeOffset(datas[@intFromEnum(inst)].node);
15391538 try sema.emitBackwardBranch(block, src);
15401539 i = 0;
15411540 continue;
......@@ -1705,7 +1704,7 @@ fn analyzeBodyInner(
17051704 }
17061705 // Same as condbr_inline. TODO https://github.com/ziglang/zig/issues/8220
17071706 const inst_data = datas[@intFromEnum(inst)].pl_node;
1708 const cond_src: LazySrcLoc = .{ .node_offset_if_cond = inst_data.src_node };
1707 const cond_src = block.src(.{ .node_offset_if_cond = inst_data.src_node });
17091708 const extra = sema.code.extraData(Zir.Inst.CondBr, inst_data.payload_index);
17101709 const then_body = sema.code.bodySlice(extra.end, extra.data.then_body_len);
17111710 const else_body = sema.code.bodySlice(
......@@ -1725,7 +1724,7 @@ fn analyzeBodyInner(
17251724 },
17261725 .condbr_inline => blk: {
17271726 const inst_data = datas[@intFromEnum(inst)].pl_node;
1728 const cond_src: LazySrcLoc = .{ .node_offset_if_cond = inst_data.src_node };
1727 const cond_src = block.src(.{ .node_offset_if_cond = inst_data.src_node });
17291728 const extra = sema.code.extraData(Zir.Inst.CondBr, inst_data.payload_index);
17301729 const then_body = sema.code.bodySlice(extra.end, extra.data.then_body_len);
17311730 const else_body = sema.code.bodySlice(
......@@ -1749,7 +1748,7 @@ fn analyzeBodyInner(
17491748 if (!block.is_comptime) break :blk try sema.zirTry(block, inst);
17501749 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
17511750 const src = block.nodeOffset(inst_data.src_node);
1752 const operand_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };
1751 const operand_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node });
17531752 const extra = sema.code.extraData(Zir.Inst.Try, inst_data.payload_index);
17541753 const inline_body = sema.code.bodySlice(extra.end, extra.data.body_len);
17551754 const err_union = try sema.resolveInst(extra.data.operand);
......@@ -1775,7 +1774,7 @@ fn analyzeBodyInner(
17751774 if (!block.is_comptime) break :blk try sema.zirTryPtr(block, inst);
17761775 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
17771776 const src = block.nodeOffset(inst_data.src_node);
1778 const operand_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };
1777 const operand_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node });
17791778 const extra = sema.code.extraData(Zir.Inst.Try, inst_data.payload_index);
17801779 const inline_body = sema.code.bodySlice(extra.end, extra.data.body_len);
17811780 const operand = try sema.resolveInst(extra.data.operand);
......@@ -1939,14 +1938,14 @@ fn resolveDestType(
19391938 // Cast builtins use their result type as the destination type, but
19401939 // it could be an anytype argument, which we can't catch in AstGen.
19411940 const msg = msg: {
1942 const msg = try sema.errMsg(block, src, "{s} must have a known result type", .{builtin_name});
1941 const msg = try sema.errMsg(src, "{s} must have a known result type", .{builtin_name});
19431942 errdefer msg.destroy(sema.gpa);
19441943 switch (sema.genericPoisonReason(block, zir_ref)) {
1945 .anytype_param => |call_src| try sema.errNote(block, call_src, msg, "result type is unknown due to anytype parameter", .{}),
1946 .anyopaque_ptr => |ptr_src| try sema.errNote(block, ptr_src, msg, "result type is unknown due to opaque pointer type", .{}),
1944 .anytype_param => |call_src| try sema.errNote(call_src, msg, "result type is unknown due to anytype parameter", .{}),
1945 .anyopaque_ptr => |ptr_src| try sema.errNote(ptr_src, msg, "result type is unknown due to opaque pointer type", .{}),
19471946 .unknown => {},
19481947 }
1949 try sema.errNote(block, src, msg, "use @as to provide explicit result type", .{});
1948 try sema.errNote(src, msg, "use @as to provide explicit result type", .{});
19501949 break :msg msg;
19511950 };
19521951 return sema.failWithOwnedErrorMsg(block, msg);
......@@ -2051,7 +2050,7 @@ pub fn setupErrorReturnTrace(sema: *Sema, block: *Block, last_arg_index: usize)
20512050 var err_trace_block = block.makeSubBlock();
20522051 defer err_trace_block.instructions.deinit(gpa);
20532052
2054 const src: LazySrcLoc = .unneeded;
2053 const src: LazySrcLoc = LazySrcLoc.unneeded;
20552054
20562055 // var addrs: [err_return_trace_addr_count]usize = undefined;
20572056 const err_return_trace_addr_count = 32;
......@@ -2212,9 +2211,9 @@ pub fn resolveFinalDeclValue(
22122211
22132212fn failWithNeededComptime(sema: *Sema, block: *Block, src: LazySrcLoc, reason: NeededComptimeReason) CompileError {
22142213 const msg = msg: {
2215 const msg = try sema.errMsg(block, src, "unable to resolve comptime value", .{});
2214 const msg = try sema.errMsg(src, "unable to resolve comptime value", .{});
22162215 errdefer msg.destroy(sema.gpa);
2217 try sema.errNote(block, src, msg, "{s}", .{reason.needed_comptime_reason});
2216 try sema.errNote(src, msg, "{s}", .{reason.needed_comptime_reason});
22182217
22192218 if (reason.block_comptime_reason) |block_comptime_reason| {
22202219 try block_comptime_reason.explain(sema, msg);
......@@ -2241,12 +2240,12 @@ fn failWithModRemNegative(sema: *Sema, block: *Block, src: LazySrcLoc, lhs_ty: T
22412240fn failWithExpectedOptionalType(sema: *Sema, block: *Block, src: LazySrcLoc, non_optional_ty: Type) CompileError {
22422241 const mod = sema.mod;
22432242 const msg = msg: {
2244 const msg = try sema.errMsg(block, src, "expected optional type, found '{}'", .{
2243 const msg = try sema.errMsg(src, "expected optional type, found '{}'", .{
22452244 non_optional_ty.fmt(mod),
22462245 });
22472246 errdefer msg.destroy(sema.gpa);
22482247 if (non_optional_ty.zigTypeTag(mod) == .ErrorUnion) {
2249 try sema.errNote(block, src, msg, "consider using 'try', 'catch', or 'if'", .{});
2248 try sema.errNote(src, msg, "consider using 'try', 'catch', or 'if'", .{});
22502249 }
22512250 try addDeclaredHereNote(sema, msg, non_optional_ty);
22522251 break :msg msg;
......@@ -2257,12 +2256,12 @@ fn failWithExpectedOptionalType(sema: *Sema, block: *Block, src: LazySrcLoc, non
22572256fn failWithArrayInitNotSupported(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) CompileError {
22582257 const mod = sema.mod;
22592258 const msg = msg: {
2260 const msg = try sema.errMsg(block, src, "type '{}' does not support array initialization syntax", .{
2259 const msg = try sema.errMsg(src, "type '{}' does not support array initialization syntax", .{
22612260 ty.fmt(mod),
22622261 });
22632262 errdefer msg.destroy(sema.gpa);
22642263 if (ty.isSlice(mod)) {
2265 try sema.errNote(block, src, msg, "inferred array length is specified with an underscore: '[_]{}'", .{ty.elemType2(mod).fmt(mod)});
2264 try sema.errNote(src, msg, "inferred array length is specified with an underscore: '[_]{}'", .{ty.elemType2(mod).fmt(mod)});
22662265 }
22672266 break :msg msg;
22682267 };
......@@ -2291,11 +2290,11 @@ fn failWithIntegerOverflow(sema: *Sema, block: *Block, src: LazySrcLoc, int_ty:
22912290 const zcu = sema.mod;
22922291 if (int_ty.zigTypeTag(zcu) == .Vector) {
22932292 const msg = msg: {
2294 const msg = try sema.errMsg(block, src, "overflow of vector type '{}' with value '{}'", .{
2293 const msg = try sema.errMsg(src, "overflow of vector type '{}' with value '{}'", .{
22952294 int_ty.fmt(zcu), val.fmtValue(zcu, sema),
22962295 });
22972296 errdefer msg.destroy(sema.gpa);
2298 try sema.errNote(block, src, msg, "when computing vector element at index '{d}'", .{vector_index});
2297 try sema.errNote(src, msg, "when computing vector element at index '{d}'", .{vector_index});
22992298 break :msg msg;
23002299 };
23012300 return sema.failWithOwnedErrorMsg(block, msg);
......@@ -2308,15 +2307,14 @@ fn failWithIntegerOverflow(sema: *Sema, block: *Block, src: LazySrcLoc, int_ty:
23082307fn failWithInvalidComptimeFieldStore(sema: *Sema, block: *Block, init_src: LazySrcLoc, container_ty: Type, field_index: usize) CompileError {
23092308 const mod = sema.mod;
23102309 const msg = msg: {
2311 const msg = try sema.errMsg(block, init_src, "value stored in comptime field does not match the default value of the field", .{});
2310 const msg = try sema.errMsg(init_src, "value stored in comptime field does not match the default value of the field", .{});
23122311 errdefer msg.destroy(sema.gpa);
23132312
23142313 const struct_type = mod.typeToStruct(container_ty) orelse break :msg msg;
2315 const default_value_src = mod.fieldSrcLoc(struct_type.decl.unwrap().?, .{
2316 .index = field_index,
2317 .range = .value,
2318 });
2319 try mod.errNoteNonLazy(default_value_src, msg, "default value set here", .{});
2314 try sema.errNote(.{
2315 .base_node_inst = struct_type.zir_index.unwrap().?,
2316 .offset = .{ .container_field_value = @intCast(field_index) },
2317 }, msg, "default value set here", .{});
23202318 break :msg msg;
23212319 };
23222320 return sema.failWithOwnedErrorMsg(block, msg);
......@@ -2324,7 +2322,7 @@ fn failWithInvalidComptimeFieldStore(sema: *Sema, block: *Block, init_src: LazyS
23242322
23252323fn failWithUseOfAsync(sema: *Sema, block: *Block, src: LazySrcLoc) CompileError {
23262324 const msg = msg: {
2327 const msg = try sema.errMsg(block, src, "async has not been implemented in the self-hosted compiler yet", .{});
2325 const msg = try sema.errMsg(src, "async has not been implemented in the self-hosted compiler yet", .{});
23282326 errdefer msg.destroy(sema.gpa);
23292327 break :msg msg;
23302328 };
......@@ -2345,9 +2343,9 @@ fn failWithInvalidFieldAccess(
23452343 const child_ty = inner_ty.optionalChild(mod);
23462344 if (!typeSupportsFieldAccess(mod, child_ty, field_name)) break :opt;
23472345 const msg = msg: {
2348 const msg = try sema.errMsg(block, src, "optional type '{}' does not support field access", .{object_ty.fmt(sema.mod)});
2346 const msg = try sema.errMsg(src, "optional type '{}' does not support field access", .{object_ty.fmt(sema.mod)});
23492347 errdefer msg.destroy(sema.gpa);
2350 try sema.errNote(block, src, msg, "consider using '.?', 'orelse', or 'if'", .{});
2348 try sema.errNote(src, msg, "consider using '.?', 'orelse', or 'if'", .{});
23512349 break :msg msg;
23522350 };
23532351 return sema.failWithOwnedErrorMsg(block, msg);
......@@ -2355,9 +2353,9 @@ fn failWithInvalidFieldAccess(
23552353 const child_ty = inner_ty.errorUnionPayload(mod);
23562354 if (!typeSupportsFieldAccess(mod, child_ty, field_name)) break :err;
23572355 const msg = msg: {
2358 const msg = try sema.errMsg(block, src, "error union type '{}' does not support field access", .{object_ty.fmt(sema.mod)});
2356 const msg = try sema.errMsg(src, "error union type '{}' does not support field access", .{object_ty.fmt(sema.mod)});
23592357 errdefer msg.destroy(sema.gpa);
2360 try sema.errNote(block, src, msg, "consider using 'try', 'catch', or 'if'", .{});
2358 try sema.errNote(src, msg, "consider using 'try', 'catch', or 'if'", .{});
23612359 break :msg msg;
23622360 };
23632361 return sema.failWithOwnedErrorMsg(block, msg);
......@@ -2390,11 +2388,11 @@ fn failWithComptimeErrorRetTrace(
23902388) CompileError {
23912389 const mod = sema.mod;
23922390 const msg = msg: {
2393 const msg = try sema.errMsg(block, src, "caught unexpected error '{}'", .{name.fmt(&mod.intern_pool)});
2391 const msg = try sema.errMsg(src, "caught unexpected error '{}'", .{name.fmt(&mod.intern_pool)});
23942392 errdefer msg.destroy(sema.gpa);
23952393
23962394 for (sema.comptime_err_ret_trace.items) |src_loc| {
2397 try mod.errNoteNonLazy(src_loc, msg, "error returned here", .{});
2395 try sema.errNote(src_loc, msg, "error returned here", .{});
23982396 }
23992397 break :msg msg;
24002398 };
......@@ -2403,17 +2401,15 @@ fn failWithComptimeErrorRetTrace(
24032401
24042402/// We don't return a pointer to the new error note because the pointer
24052403/// becomes invalid when you add another one.
2406fn errNote(
2404pub fn errNote(
24072405 sema: *Sema,
2408 block: *Block,
24092406 src: LazySrcLoc,
24102407 parent: *Module.ErrorMsg,
24112408 comptime format: []const u8,
24122409 args: anytype,
24132410) error{OutOfMemory}!void {
2414 const mod = sema.mod;
2415 const src_decl = mod.declPtr(block.src_decl);
2416 return mod.errNoteNonLazy(src_decl.toSrcLoc(src, mod), parent, format, args);
2411 const zcu = sema.mod;
2412 return zcu.errNoteNonLazy(src.upgrade(zcu), parent, format, args);
24172413}
24182414
24192415fn addFieldErrNote(
......@@ -2425,52 +2421,23 @@ fn addFieldErrNote(
24252421 args: anytype,
24262422) !void {
24272423 @setCold(true);
2428 const mod = sema.mod;
2429 const decl_index = container_ty.getOwnerDecl(mod);
2430 const decl = mod.declPtr(decl_index);
2431
2432 const field_src = blk: {
2433 const tree = decl.getFileScope(mod).getTree(sema.gpa) catch |err| {
2434 log.err("unable to load AST to report compile error: {s}", .{@errorName(err)});
2435 break :blk decl.srcLoc(mod);
2436 };
2437
2438 const container_node = decl.relativeToNodeIndex(0);
2439 const node_tags = tree.nodes.items(.tag);
2440 var buf: [2]std.zig.Ast.Node.Index = undefined;
2441 const container_decl = tree.fullContainerDecl(&buf, container_node) orelse break :blk decl.srcLoc(mod);
2442
2443 var it_index: usize = 0;
2444 for (container_decl.ast.members) |member_node| {
2445 switch (node_tags[member_node]) {
2446 .container_field_init,
2447 .container_field_align,
2448 .container_field,
2449 => {
2450 if (it_index == field_index) {
2451 break :blk decl.nodeOffsetSrcLoc(decl.nodeIndexToRelative(member_node), mod);
2452 }
2453 it_index += 1;
2454 },
2455 else => continue,
2456 }
2457 }
2458 unreachable;
2424 const zcu = sema.mod;
2425 const type_src = container_ty.srcLocOrNull(zcu) orelse return;
2426 const field_src: LazySrcLoc = .{
2427 .base_node_inst = type_src.base_node_inst,
2428 .offset = .{ .container_field_name = @intCast(field_index) },
24592429 };
2460 try mod.errNoteNonLazy(field_src, parent, format, args);
2430 try sema.errNote(field_src, parent, format, args);
24612431}
24622432
24632433pub fn errMsg(
24642434 sema: *Sema,
2465 block: *Block,
24662435 src: LazySrcLoc,
24672436 comptime format: []const u8,
24682437 args: anytype,
2469) error{ NeededSourceLocation, OutOfMemory }!*Module.ErrorMsg {
2470 const mod = sema.mod;
2471 if (src == .unneeded) return error.NeededSourceLocation;
2472 const src_decl = mod.declPtr(block.src_decl);
2473 return Module.ErrorMsg.create(sema.gpa, src_decl.toSrcLoc(src, mod), format, args);
2438) Allocator.Error!*Module.ErrorMsg {
2439 assert(src.offset != .unneeded);
2440 return Module.ErrorMsg.create(sema.gpa, src.upgrade(sema.mod), format, args);
24742441}
24752442
24762443pub fn fail(
......@@ -2480,7 +2447,7 @@ pub fn fail(
24802447 comptime format: []const u8,
24812448 args: anytype,
24822449) CompileError {
2483 const err_msg = try sema.errMsg(block, src, format, args);
2450 const err_msg = try sema.errMsg(src, format, args);
24842451 inline for (args) |arg| {
24852452 if (@TypeOf(arg) == Type.Formatter) {
24862453 try addDeclaredHereNote(sema, err_msg, arg.data.ty);
......@@ -2514,7 +2481,6 @@ pub fn failWithOwnedErrorMsg(sema: *Sema, block: ?*Block, err_msg: *Module.Error
25142481 var block_it = start_block;
25152482 while (block_it.inlining) |inlining| {
25162483 try sema.errNote(
2517 inlining.call_block,
25182484 inlining.call_src,
25192485 err_msg,
25202486 "called from here",
......@@ -2548,7 +2514,7 @@ pub fn failWithOwnedErrorMsg(sema: *Sema, block: ?*Block, err_msg: *Module.Error
25482514 const decl = mod.declPtr(ref.referencer);
25492515 try reference_stack.append(.{
25502516 .decl = decl.name,
2551 .src_loc = decl.toSrcLoc(ref.src, mod),
2517 .src_loc = ref.src.upgrade(mod),
25522518 });
25532519 }
25542520 referenced_by = ref.referencer;
......@@ -2583,15 +2549,13 @@ pub fn failWithOwnedErrorMsg(sema: *Sema, block: ?*Block, err_msg: *Module.Error
25832549/// Reference trace is preserved.
25842550fn reparentOwnedErrorMsg(
25852551 sema: *Sema,
2586 block: *Block,
25872552 src: LazySrcLoc,
25882553 msg: *Module.ErrorMsg,
25892554 comptime format: []const u8,
25902555 args: anytype,
25912556) !void {
25922557 const mod = sema.mod;
2593 const src_decl = mod.declPtr(block.src_decl);
2594 const resolved_src = src_decl.toSrcLoc(src, mod);
2558 const resolved_src = src.upgrade(mod);
25952559 const msg_str = try std.fmt.allocPrint(mod.gpa, format, args);
25962560
25972561 const orig_notes = msg.notes.len;
......@@ -2728,7 +2692,7 @@ fn getCaptures(sema: *Sema, block: *Block, type_src: LazySrcLoc, extra_index: us
27282692 sema.code.nullTerminatedString(str),
27292693 .no_embedded_nulls,
27302694 );
2731 const decl = try sema.lookupIdentifier(block, .unneeded, decl_name); // TODO: could we need this src loc?
2695 const decl = try sema.lookupIdentifier(block, LazySrcLoc.unneeded, decl_name); // TODO: could we need this src loc?
27322696 break :capture InternPool.CaptureValue.wrap(.{ .decl_val = decl });
27332697 },
27342698 .decl_ref => |str| capture: {
......@@ -2737,7 +2701,7 @@ fn getCaptures(sema: *Sema, block: *Block, type_src: LazySrcLoc, extra_index: us
27372701 sema.code.nullTerminatedString(str),
27382702 .no_embedded_nulls,
27392703 );
2740 const decl = try sema.lookupIdentifier(block, .unneeded, decl_name); // TODO: could we need this src loc?
2704 const decl = try sema.lookupIdentifier(block, LazySrcLoc.unneeded, decl_name); // TODO: could we need this src loc?
27412705 break :capture InternPool.CaptureValue.wrap(.{ .decl_ref = decl });
27422706 },
27432707 };
......@@ -2788,7 +2752,13 @@ fn zirStructDecl(
27882752 const ip = &mod.intern_pool;
27892753 const small: Zir.Inst.StructDecl.Small = @bitCast(extended.small);
27902754 const extra = sema.code.extraData(Zir.Inst.StructDecl, extended.operand);
2791 const src: LazySrcLoc = .{ .node_abs = extra.data.src_node };
2755
2756 const tracked_inst = try ip.trackZir(gpa, block.getFileScope(mod), inst);
2757 const src: LazySrcLoc = .{
2758 .base_node_inst = tracked_inst,
2759 .offset = LazySrcLoc.Offset.nodeOffset(0),
2760 };
2761
27922762 var extra_index = extra.end;
27932763
27942764 const captures_len = if (small.has_captures_len) blk: {
......@@ -2832,7 +2802,7 @@ fn zirStructDecl(
28322802 .any_aligned_fields = small.any_aligned_fields,
28332803 .has_namespace = true or decls_len > 0, // TODO: see below
28342804 .key = .{ .declared = .{
2835 .zir_index = try ip.trackZir(gpa, block.getFileScope(mod), inst),
2805 .zir_index = tracked_inst,
28362806 .captures = captures,
28372807 } },
28382808 };
......@@ -2847,7 +2817,6 @@ fn zirStructDecl(
28472817
28482818 const new_decl_index = try sema.createAnonymousDeclTypeNamed(
28492819 block,
2850 extra.data.src_node,
28512820 Value.fromInterned(wip_ty.index),
28522821 small.name_strategy,
28532822 "struct",
......@@ -2884,7 +2853,6 @@ fn zirStructDecl(
28842853fn createAnonymousDeclTypeNamed(
28852854 sema: *Sema,
28862855 block: *Block,
2887 src_node: std.zig.Ast.Node.Index,
28882856 val: Value,
28892857 name_strategy: Zir.Inst.NameStrategy,
28902858 anon_prefix: []const u8,
......@@ -2895,7 +2863,7 @@ fn createAnonymousDeclTypeNamed(
28952863 const gpa = sema.gpa;
28962864 const namespace = block.namespace;
28972865 const src_decl = zcu.declPtr(block.src_decl);
2898 const new_decl_index = try zcu.allocateNewDecl(namespace, src_node);
2866 const new_decl_index = try zcu.allocateNewDecl(namespace);
28992867 errdefer zcu.destroyDecl(new_decl_index);
29002868
29012869 switch (name_strategy) {
......@@ -2924,8 +2892,7 @@ fn createAnonymousDeclTypeNamed(
29242892 // If not then this is a struct type being returned from a non-generic
29252893 // function and the name doesn't matter since it will later
29262894 // result in a compile error.
2927 const arg_val = sema.resolveConstValue(block, .unneeded, arg, undefined) catch
2928 break :func_strat; // fall through to anon strat
2895 const arg_val = try sema.resolveValue(arg) orelse break :func_strat; // fall through to anon strat
29292896
29302897 if (arg_i != 0) try writer.writeByte(',');
29312898
......@@ -3003,7 +2970,9 @@ fn zirEnumDecl(
30032970 const extra = sema.code.extraData(Zir.Inst.EnumDecl, extended.operand);
30042971 var extra_index: usize = extra.end;
30052972
3006 const src: LazySrcLoc = .{ .node_abs = extra.data.src_node };
2973 const tracked_inst = try ip.trackZir(gpa, block.getFileScope(mod), inst);
2974 const src: LazySrcLoc = .{ .base_node_inst = tracked_inst, .offset = LazySrcLoc.Offset.nodeOffset(0) };
2975 const tag_ty_src: LazySrcLoc = .{ .base_node_inst = tracked_inst, .offset = .{ .node_offset_container_tag = 0 } };
30072976
30082977 const tag_type_ref = if (small.has_tag_type) blk: {
30092978 const tag_type_ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_index]);
......@@ -3063,7 +3032,7 @@ fn zirEnumDecl(
30633032 .explicit,
30643033 .fields_len = fields_len,
30653034 .key = .{ .declared = .{
3066 .zir_index = try mod.intern_pool.trackZir(sema.gpa, block.getFileScope(mod), inst),
3035 .zir_index = tracked_inst,
30673036 .captures = captures,
30683037 } },
30693038 };
......@@ -3083,7 +3052,6 @@ fn zirEnumDecl(
30833052
30843053 const new_decl_index = try sema.createAnonymousDeclTypeNamed(
30853054 block,
3086 extra.data.src_node,
30873055 Value.fromInterned(wip_ty.index),
30883056 small.name_strategy,
30893057 "enum",
......@@ -3149,12 +3117,10 @@ fn zirEnumDecl(
31493117 .instructions = .{},
31503118 .inlining = null,
31513119 .is_comptime = true,
3120 .src_base_inst = tracked_inst,
31523121 };
31533122 defer enum_block.instructions.deinit(sema.gpa);
31543123
3155 // This source location applies in the context of `enum_block`.
3156 const tag_ty_src: LazySrcLoc = .{ .node_offset_container_tag = 0 };
3157
31583124 if (body.len != 0) {
31593125 _ = try sema.analyzeInlineBody(&enum_block, body, inst);
31603126 }
......@@ -3199,36 +3165,33 @@ fn zirEnumDecl(
31993165
32003166 const field_name = try mod.intern_pool.getOrPutString(gpa, field_name_zir, .no_embedded_nulls);
32013167
3168 const value_src: LazySrcLoc = .{
3169 .base_node_inst = tracked_inst,
3170 .offset = .{ .container_field_value = field_i },
3171 };
3172
32023173 const tag_overflow = if (has_tag_value) overflow: {
32033174 const tag_val_ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_index]);
32043175 extra_index += 1;
32053176 const tag_inst = try sema.resolveInst(tag_val_ref);
3206 last_tag_val = sema.resolveConstDefinedValue(block, .unneeded, tag_inst, undefined) catch |err| switch (err) {
3207 error.NeededSourceLocation => {
3208 const value_src = mod.fieldSrcLoc(new_decl_index, .{
3209 .index = field_i,
3210 .range = .value,
3211 }).lazy;
3212 _ = try sema.resolveConstDefinedValue(block, value_src, tag_inst, .{
3213 .needed_comptime_reason = "enum tag value must be comptime-known",
3214 });
3215 unreachable;
3216 },
3217 else => |e| return e,
3218 };
3177 last_tag_val = try sema.resolveConstDefinedValue(block, .{
3178 .base_node_inst = tracked_inst,
3179 .offset = .{ .container_field_name = field_i },
3180 }, tag_inst, .{
3181 .needed_comptime_reason = "enum tag value must be comptime-known",
3182 });
32193183 if (!(try sema.intFitsInType(last_tag_val.?, int_tag_ty, null))) break :overflow true;
32203184 last_tag_val = try mod.getCoerced(last_tag_val.?, int_tag_ty);
32213185 if (wip_ty.nextField(&mod.intern_pool, field_name, last_tag_val.?.toIntern())) |conflict| {
32223186 assert(conflict.kind == .value); // AstGen validated names are unique
3223 const value_src = mod.fieldSrcLoc(new_decl_index, .{
3224 .index = field_i,
3225 .range = .value,
3226 }).lazy;
3227 const other_field_src = mod.fieldSrcLoc(new_decl_index, .{ .index = conflict.prev_field_idx }).lazy;
3187 const other_field_src: LazySrcLoc = .{
3188 .base_node_inst = tracked_inst,
3189 .offset = .{ .container_field_value = conflict.prev_field_idx },
3190 };
32283191 const msg = msg: {
3229 const msg = try sema.errMsg(block, value_src, "enum tag value {} already taken", .{last_tag_val.?.fmtValue(sema.mod, sema)});
3192 const msg = try sema.errMsg(value_src, "enum tag value {} already taken", .{last_tag_val.?.fmtValue(sema.mod, sema)});
32303193 errdefer msg.destroy(gpa);
3231 try sema.errNote(block, other_field_src, msg, "other occurrence here", .{});
3194 try sema.errNote(other_field_src, msg, "other occurrence here", .{});
32323195 break :msg msg;
32333196 };
32343197 return sema.failWithOwnedErrorMsg(block, msg);
......@@ -3243,12 +3206,14 @@ fn zirEnumDecl(
32433206 if (overflow != null) break :overflow true;
32443207 if (wip_ty.nextField(&mod.intern_pool, field_name, last_tag_val.?.toIntern())) |conflict| {
32453208 assert(conflict.kind == .value); // AstGen validated names are unique
3246 const field_src = mod.fieldSrcLoc(new_decl_index, .{ .index = field_i }).lazy;
3247 const other_field_src = mod.fieldSrcLoc(new_decl_index, .{ .index = conflict.prev_field_idx }).lazy;
3209 const other_field_src: LazySrcLoc = .{
3210 .base_node_inst = tracked_inst,
3211 .offset = .{ .container_field_value = conflict.prev_field_idx },
3212 };
32483213 const msg = msg: {
3249 const msg = try sema.errMsg(block, field_src, "enum tag value {} already taken", .{last_tag_val.?.fmtValue(sema.mod, sema)});
3214 const msg = try sema.errMsg(value_src, "enum tag value {} already taken", .{last_tag_val.?.fmtValue(sema.mod, sema)});
32503215 errdefer msg.destroy(gpa);
3251 try sema.errNote(block, other_field_src, msg, "other occurrence here", .{});
3216 try sema.errNote(other_field_src, msg, "other occurrence here", .{});
32523217 break :msg msg;
32533218 };
32543219 return sema.failWithOwnedErrorMsg(block, msg);
......@@ -3263,11 +3228,7 @@ fn zirEnumDecl(
32633228 };
32643229
32653230 if (tag_overflow) {
3266 const value_src = mod.fieldSrcLoc(new_decl_index, .{
3267 .index = field_i,
3268 .range = if (has_tag_value) .value else .name,
3269 }).lazy;
3270 const msg = try sema.errMsg(block, value_src, "enumeration value '{}' too large for type '{}'", .{
3231 const msg = try sema.errMsg(value_src, "enumeration value '{}' too large for type '{}'", .{
32713232 last_tag_val.?.fmtValue(mod, sema), int_tag_ty.fmt(mod),
32723233 });
32733234 return sema.failWithOwnedErrorMsg(block, msg);
......@@ -3294,7 +3255,8 @@ fn zirUnionDecl(
32943255 const extra = sema.code.extraData(Zir.Inst.UnionDecl, extended.operand);
32953256 var extra_index: usize = extra.end;
32963257
3297 const src: LazySrcLoc = .{ .node_abs = extra.data.src_node };
3258 const tracked_inst = try ip.trackZir(gpa, block.getFileScope(mod), inst);
3259 const src: LazySrcLoc = .{ .base_node_inst = tracked_inst, .offset = LazySrcLoc.Offset.nodeOffset(0) };
32983260
32993261 extra_index += @intFromBool(small.has_tag_type);
33003262 const captures_len = if (small.has_captures_len) blk: {
......@@ -3342,7 +3304,7 @@ fn zirUnionDecl(
33423304 .field_types = &.{}, // set later
33433305 .field_aligns = &.{}, // set later
33443306 .key = .{ .declared = .{
3345 .zir_index = try ip.trackZir(gpa, block.getFileScope(mod), inst),
3307 .zir_index = tracked_inst,
33463308 .captures = captures,
33473309 } },
33483310 };
......@@ -3357,7 +3319,6 @@ fn zirUnionDecl(
33573319
33583320 const new_decl_index = try sema.createAnonymousDeclTypeNamed(
33593321 block,
3360 extra.data.src_node,
33613322 Value.fromInterned(wip_ty.index),
33623323 small.name_strategy,
33633324 "union",
......@@ -3409,7 +3370,8 @@ fn zirOpaqueDecl(
34093370 const extra = sema.code.extraData(Zir.Inst.OpaqueDecl, extended.operand);
34103371 var extra_index: usize = extra.end;
34113372
3412 const src: LazySrcLoc = .{ .node_abs = extra.data.src_node };
3373 const tracked_inst = try ip.trackZir(gpa, block.getFileScope(mod), inst);
3374 const src: LazySrcLoc = .{ .base_node_inst = tracked_inst, .offset = LazySrcLoc.Offset.nodeOffset(0) };
34133375
34143376 const captures_len = if (small.has_captures_len) blk: {
34153377 const captures_len = sema.code.extra[extra_index];
......@@ -3429,7 +3391,7 @@ fn zirOpaqueDecl(
34293391 const opaque_init: InternPool.OpaqueTypeInit = .{
34303392 .has_namespace = decls_len != 0,
34313393 .key = .{ .declared = .{
3432 .zir_index = try ip.trackZir(gpa, block.getFileScope(mod), inst),
3394 .zir_index = tracked_inst,
34333395 .captures = captures,
34343396 } },
34353397 };
......@@ -3445,7 +3407,6 @@ fn zirOpaqueDecl(
34453407
34463408 const new_decl_index = try sema.createAnonymousDeclTypeNamed(
34473409 block,
3448 extra.data.src_node,
34493410 Value.fromInterned(wip_ty.index),
34503411 small.name_strategy,
34513412 "opaque",
......@@ -3566,19 +3527,19 @@ fn ensureResultUsed(
35663527 .ErrorSet => return sema.fail(block, src, "error set is ignored", .{}),
35673528 .ErrorUnion => {
35683529 const msg = msg: {
3569 const msg = try sema.errMsg(block, src, "error union is ignored", .{});
3530 const msg = try sema.errMsg(src, "error union is ignored", .{});
35703531 errdefer msg.destroy(sema.gpa);
3571 try sema.errNote(block, src, msg, "consider using 'try', 'catch', or 'if'", .{});
3532 try sema.errNote(src, msg, "consider using 'try', 'catch', or 'if'", .{});
35723533 break :msg msg;
35733534 };
35743535 return sema.failWithOwnedErrorMsg(block, msg);
35753536 },
35763537 else => {
35773538 const msg = msg: {
3578 const msg = try sema.errMsg(block, src, "value of type '{}' ignored", .{ty.fmt(sema.mod)});
3539 const msg = try sema.errMsg(src, "value of type '{}' ignored", .{ty.fmt(sema.mod)});
35793540 errdefer msg.destroy(sema.gpa);
3580 try sema.errNote(block, src, msg, "all non-void values must be used", .{});
3581 try sema.errNote(block, src, msg, "to discard the value, assign it to '_'", .{});
3541 try sema.errNote(src, msg, "all non-void values must be used", .{});
3542 try sema.errNote(src, msg, "to discard the value, assign it to '_'", .{});
35823543 break :msg msg;
35833544 };
35843545 return sema.failWithOwnedErrorMsg(block, msg);
......@@ -3599,9 +3560,9 @@ fn zirEnsureResultNonError(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com
35993560 .ErrorSet => return sema.fail(block, src, "error set is discarded", .{}),
36003561 .ErrorUnion => {
36013562 const msg = msg: {
3602 const msg = try sema.errMsg(block, src, "error union is discarded", .{});
3563 const msg = try sema.errMsg(src, "error union is discarded", .{});
36033564 errdefer msg.destroy(sema.gpa);
3604 try sema.errNote(block, src, msg, "consider using 'try', 'catch', or 'if'", .{});
3565 try sema.errNote(src, msg, "consider using 'try', 'catch', or 'if'", .{});
36053566 break :msg msg;
36063567 };
36073568 return sema.failWithOwnedErrorMsg(block, msg);
......@@ -3627,9 +3588,9 @@ fn zirEnsureErrUnionPayloadVoid(sema: *Sema, block: *Block, inst: Zir.Inst.Index
36273588 const payload_ty = err_union_ty.errorUnionPayload(mod).zigTypeTag(mod);
36283589 if (payload_ty != .Void and payload_ty != .NoReturn) {
36293590 const msg = msg: {
3630 const msg = try sema.errMsg(block, src, "error union payload is ignored", .{});
3591 const msg = try sema.errMsg(src, "error union payload is ignored", .{});
36313592 errdefer msg.destroy(sema.gpa);
3632 try sema.errNote(block, src, msg, "payload value can be explicitly ignored with '|_|'", .{});
3593 try sema.errNote(src, msg, "payload value can be explicitly ignored with '|_|'", .{});
36333594 break :msg msg;
36343595 };
36353596 return sema.failWithOwnedErrorMsg(block, msg);
......@@ -3683,8 +3644,8 @@ fn zirAllocExtended(
36833644) CompileError!Air.Inst.Ref {
36843645 const gpa = sema.gpa;
36853646 const extra = sema.code.extraData(Zir.Inst.AllocExtended, extended.operand);
3686 const ty_src: LazySrcLoc = .{ .node_offset_var_decl_ty = extra.data.src_node };
3687 const align_src: LazySrcLoc = .{ .node_offset_var_decl_align = extra.data.src_node };
3647 const ty_src = block.src(.{ .node_offset_var_decl_ty = extra.data.src_node });
3648 const align_src = block.src(.{ .node_offset_var_decl_align = extra.data.src_node });
36883649 const small: Zir.Inst.AllocExtended.Small = @bitCast(extended.small);
36893650
36903651 var extra_index: usize = extra.end;
......@@ -3760,7 +3721,7 @@ fn zirAllocComptime(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr
37603721 defer tracy.end();
37613722
37623723 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
3763 const ty_src: LazySrcLoc = .{ .node_offset_var_decl_ty = inst_data.src_node };
3724 const ty_src = block.src(.{ .node_offset_var_decl_ty = inst_data.src_node });
37643725 const var_ty = try sema.resolveType(block, ty_src, inst_data.operand);
37653726 return sema.analyzeComptimeAlloc(block, var_ty, .none);
37663727}
......@@ -3826,7 +3787,7 @@ fn zirMakePtrConst(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
38263787 if (try sema.typeRequiresComptime(elem_ty)) {
38273788 // The value was initialized through RLS, so we didn't detect the runtime condition earlier.
38283789 // TODO: source location of runtime control flow
3829 const init_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };
3790 const init_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node });
38303791 return sema.fail(block, init_src, "value with comptime-only type '{}' depends on runtime control flow", .{elem_ty.fmt(mod)});
38313792 }
38323793
......@@ -3995,7 +3956,7 @@ fn resolveComptimeKnownAllocPtr(sema: *Sema, block: *Block, alloc: Air.Inst.Ref,
39953956 .ty = opt_ty.toIntern(),
39963957 .val = payload_val.toIntern(),
39973958 } });
3998 try sema.storePtrVal(block, .unneeded, Value.fromInterned(decl_parent_ptr), Value.fromInterned(opt_val), opt_ty);
3959 try sema.storePtrVal(block, LazySrcLoc.unneeded, Value.fromInterned(decl_parent_ptr), Value.fromInterned(opt_val), opt_ty);
39993960 break :ptr (try Value.fromInterned(decl_parent_ptr).ptrOptPayload(sema)).toIntern();
40003961 },
40013962 .eu_payload => ptr: {
......@@ -4008,7 +3969,7 @@ fn resolveComptimeKnownAllocPtr(sema: *Sema, block: *Block, alloc: Air.Inst.Ref,
40083969 .ty = eu_ty.toIntern(),
40093970 .val = .{ .payload = payload_val.toIntern() },
40103971 } });
4011 try sema.storePtrVal(block, .unneeded, Value.fromInterned(decl_parent_ptr), Value.fromInterned(eu_val), eu_ty);
3972 try sema.storePtrVal(block, LazySrcLoc.unneeded, Value.fromInterned(decl_parent_ptr), Value.fromInterned(eu_val), eu_ty);
40123973 break :ptr (try Value.fromInterned(decl_parent_ptr).ptrEuPayload(sema)).toIntern();
40133974 },
40143975 .field => |idx| ptr: {
......@@ -4021,7 +3982,7 @@ fn resolveComptimeKnownAllocPtr(sema: *Sema, block: *Block, alloc: Air.Inst.Ref,
40213982 const payload_val = try sema.typeHasOnePossibleValue(payload_ty) orelse try zcu.undefValue(payload_ty);
40223983 const tag_val = try zcu.enumValueFieldIndex(Type.fromInterned(union_obj.enum_tag_ty), idx);
40233984 const store_val = try zcu.unionValue(maybe_union_ty, tag_val, payload_val);
4024 try sema.storePtrVal(block, .unneeded, Value.fromInterned(decl_parent_ptr), store_val, maybe_union_ty);
3985 try sema.storePtrVal(block, LazySrcLoc.unneeded, Value.fromInterned(decl_parent_ptr), store_val, maybe_union_ty);
40253986 }
40263987 break :ptr (try Value.fromInterned(decl_parent_ptr).ptrField(idx, sema)).toIntern();
40273988 },
......@@ -4043,14 +4004,14 @@ fn resolveComptimeKnownAllocPtr(sema: *Sema, block: *Block, alloc: Air.Inst.Ref,
40434004 const air_ptr_inst = store_inst.data.bin_op.lhs.toIndex().?;
40444005 const store_val = (try sema.resolveValue(store_inst.data.bin_op.rhs)).?;
40454006 const new_ptr = ptr_mapping.get(air_ptr_inst).?;
4046 try sema.storePtrVal(block, .unneeded, Value.fromInterned(new_ptr), store_val, Type.fromInterned(zcu.intern_pool.typeOf(store_val.toIntern())));
4007 try sema.storePtrVal(block, LazySrcLoc.unneeded, Value.fromInterned(new_ptr), store_val, Type.fromInterned(zcu.intern_pool.typeOf(store_val.toIntern())));
40474008 },
40484009 else => unreachable,
40494010 }
40504011 }
40514012
40524013 // The value is finalized - load it!
4053 const val = (try sema.pointerDeref(block, .unneeded, Value.fromInterned(alloc_ptr), alloc_ty)).?.toIntern();
4014 const val = (try sema.pointerDeref(block, LazySrcLoc.unneeded, Value.fromInterned(alloc_ptr), alloc_ty)).?.toIntern();
40544015 return sema.finishResolveComptimeKnownAllocPtr(block, alloc_ty, val, ct_alloc, alloc_inst, comptime_info.value);
40554016}
40564017
......@@ -4153,7 +4114,7 @@ fn zirAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.I
41534114 defer tracy.end();
41544115
41554116 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
4156 const ty_src: LazySrcLoc = .{ .node_offset_var_decl_ty = inst_data.src_node };
4117 const ty_src = block.src(.{ .node_offset_var_decl_ty = inst_data.src_node });
41574118 const var_ty = try sema.resolveType(block, ty_src, inst_data.operand);
41584119 if (block.is_comptime) {
41594120 return sema.analyzeComptimeAlloc(block, var_ty, .none);
......@@ -4176,7 +4137,7 @@ fn zirAllocMut(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
41764137 defer tracy.end();
41774138
41784139 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
4179 const ty_src: LazySrcLoc = .{ .node_offset_var_decl_ty = inst_data.src_node };
4140 const ty_src = block.src(.{ .node_offset_var_decl_ty = inst_data.src_node });
41804141 const var_ty = try sema.resolveType(block, ty_src, inst_data.operand);
41814142 if (block.is_comptime) {
41824143 return sema.analyzeComptimeAlloc(block, var_ty, .none);
......@@ -4236,7 +4197,7 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com
42364197 const gpa = sema.gpa;
42374198 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
42384199 const src = block.nodeOffset(inst_data.src_node);
4239 const ty_src: LazySrcLoc = .{ .node_offset_var_decl_ty = inst_data.src_node };
4200 const ty_src = block.src(.{ .node_offset_var_decl_ty = inst_data.src_node });
42404201 const ptr = try sema.resolveInst(inst_data.operand);
42414202 const ptr_inst = ptr.toIndex().?;
42424203 const target = mod.getTarget();
......@@ -4399,20 +4360,20 @@ fn zirForLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
43994360 .Int, .ComptimeInt => true,
44004361 else => false,
44014362 };
4402 const arg_src: LazySrcLoc = .{ .for_input = .{
4363 const arg_src = block.src(.{ .for_input = .{
44034364 .for_node_offset = inst_data.src_node,
44044365 .input_index = i,
4405 } };
4366 } });
44064367 const arg_len_uncoerced = if (is_int) object else l: {
44074368 if (!object_ty.isIndexable(mod)) {
44084369 // Instead of using checkIndexable we customize this error.
44094370 const msg = msg: {
4410 const msg = try sema.errMsg(block, arg_src, "type '{}' is not indexable and not a range", .{object_ty.fmt(sema.mod)});
4371 const msg = try sema.errMsg(arg_src, "type '{}' is not indexable and not a range", .{object_ty.fmt(sema.mod)});
44114372 errdefer msg.destroy(sema.gpa);
4412 try sema.errNote(block, arg_src, msg, "for loop operand must be a range, array, slice, tuple, or vector", .{});
4373 try sema.errNote(arg_src, msg, "for loop operand must be a range, array, slice, tuple, or vector", .{});
44134374
44144375 if (object_ty.zigTypeTag(mod) == .ErrorUnion) {
4415 try sema.errNote(block, arg_src, msg, "consider using 'try', 'catch', or 'if'", .{});
4376 try sema.errNote(arg_src, msg, "consider using 'try', 'catch', or 'if'", .{});
44164377 }
44174378
44184379 break :msg msg;
......@@ -4432,16 +4393,16 @@ fn zirForLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
44324393 if (len_val) |v| {
44334394 if (!(try sema.valuesEqual(arg_val, v, Type.usize))) {
44344395 const msg = msg: {
4435 const msg = try sema.errMsg(block, src, "non-matching for loop lengths", .{});
4396 const msg = try sema.errMsg(src, "non-matching for loop lengths", .{});
44364397 errdefer msg.destroy(gpa);
4437 const a_src: LazySrcLoc = .{ .for_input = .{
4398 const a_src = block.src(.{ .for_input = .{
44384399 .for_node_offset = inst_data.src_node,
44394400 .input_index = len_idx,
4440 } };
4441 try sema.errNote(block, a_src, msg, "length {} here", .{
4401 } });
4402 try sema.errNote(a_src, msg, "length {} here", .{
44424403 v.fmtValue(sema.mod, sema),
44434404 });
4444 try sema.errNote(block, arg_src, msg, "length {} here", .{
4405 try sema.errNote(arg_src, msg, "length {} here", .{
44454406 arg_val.fmtValue(sema.mod, sema),
44464407 });
44474408 break :msg msg;
......@@ -4461,7 +4422,7 @@ fn zirForLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
44614422
44624423 if (len == .none) {
44634424 const msg = msg: {
4464 const msg = try sema.errMsg(block, src, "unbounded for loop", .{});
4425 const msg = try sema.errMsg(src, "unbounded for loop", .{});
44654426 errdefer msg.destroy(gpa);
44664427 for (args, 0..) |zir_arg, i_usize| {
44674428 const i: u32 = @intCast(i_usize);
......@@ -4474,11 +4435,11 @@ fn zirForLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
44744435 .Int, .ComptimeInt => continue,
44754436 else => {},
44764437 }
4477 const arg_src: LazySrcLoc = .{ .for_input = .{
4438 const arg_src = block.src(.{ .for_input = .{
44784439 .for_node_offset = inst_data.src_node,
44794440 .input_index = i,
4480 } };
4481 try sema.errNote(block, arg_src, msg, "type '{}' has no upper bound", .{
4441 } });
4442 try sema.errNote(arg_src, msg, "type '{}' has no upper bound", .{
44824443 object_ty.fmt(sema.mod),
44834444 });
44844445 }
......@@ -4528,7 +4489,7 @@ fn zirCoercePtrElemTy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE
45284489 const src = block.nodeOffset(pl_node.src_node);
45294490 const extra = sema.code.extraData(Zir.Inst.Bin, pl_node.payload_index).data;
45304491 const uncoerced_val = try sema.resolveInst(extra.rhs);
4531 const maybe_wrapped_ptr_ty = sema.resolveType(block, .unneeded, extra.lhs) catch |err| switch (err) {
4492 const maybe_wrapped_ptr_ty = sema.resolveType(block, LazySrcLoc.unneeded, extra.lhs) catch |err| switch (err) {
45324493 error.GenericPoison => return uncoerced_val,
45334494 else => |e| return e,
45344495 };
......@@ -4590,9 +4551,9 @@ fn zirValidateRefTy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr
45904551 if (ty_operand.isGenericPoison()) return;
45914552 if (ty_operand.optEuBaseType(mod).zigTypeTag(mod) != .Pointer) {
45924553 return sema.failWithOwnedErrorMsg(block, msg: {
4593 const msg = try sema.errMsg(block, src, "expected type '{}', found pointer", .{ty_operand.fmt(mod)});
4554 const msg = try sema.errMsg(src, "expected type '{}', found pointer", .{ty_operand.fmt(mod)});
45944555 errdefer msg.destroy(sema.gpa);
4595 try sema.errNote(block, src, msg, "address-of operator always returns a pointer", .{});
4556 try sema.errNote(src, msg, "address-of operator always returns a pointer", .{});
45964557 break :msg msg;
45974558 });
45984559 }
......@@ -4607,7 +4568,7 @@ fn zirValidateArrayInitRefTy(
46074568 const pl_node = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
46084569 const src = block.nodeOffset(pl_node.src_node);
46094570 const extra = sema.code.extraData(Zir.Inst.ArrayInitRefTy, pl_node.payload_index).data;
4610 const maybe_wrapped_ptr_ty = sema.resolveType(block, .unneeded, extra.ptr_ty) catch |err| switch (err) {
4571 const maybe_wrapped_ptr_ty = sema.resolveType(block, LazySrcLoc.unneeded, extra.ptr_ty) catch |err| switch (err) {
46114572 error.GenericPoison => return .generic_poison_type,
46124573 else => |e| return e,
46134574 };
......@@ -4648,7 +4609,7 @@ fn zirValidateArrayInitTy(
46484609 const mod = sema.mod;
46494610 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
46504611 const src = block.nodeOffset(inst_data.src_node);
4651 const ty_src: LazySrcLoc = if (is_result_ty) src else .{ .node_offset_init_ty = inst_data.src_node };
4612 const ty_src: LazySrcLoc = if (is_result_ty) src else block.src(.{ .node_offset_init_ty = inst_data.src_node });
46524613 const extra = sema.code.extraData(Zir.Inst.ArrayInit, inst_data.payload_index).data;
46534614 const ty = sema.resolveType(block, ty_src, extra.ty) catch |err| switch (err) {
46544615 // It's okay for the type to be unknown: this will result in an anonymous array init.
......@@ -4774,7 +4735,6 @@ fn validateUnionInit(
47744735 if (instrs.len != 1) {
47754736 const msg = msg: {
47764737 const msg = try sema.errMsg(
4777 block,
47784738 init_src,
47794739 "cannot initialize multiple union fields at once; unions can only have one active field",
47804740 .{},
......@@ -4783,8 +4743,8 @@ fn validateUnionInit(
47834743
47844744 for (instrs[1..]) |inst| {
47854745 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
4786 const inst_src: LazySrcLoc = .{ .node_offset_initializer = inst_data.src_node };
4787 try sema.errNote(block, inst_src, msg, "additional initializer here", .{});
4746 const inst_src = block.src(.{ .node_offset_initializer = inst_data.src_node });
4747 try sema.errNote(inst_src, msg, "additional initializer here", .{});
47884748 }
47894749 try sema.addDeclaredHereNote(msg, union_ty);
47904750 break :msg msg;
......@@ -4801,7 +4761,7 @@ fn validateUnionInit(
48014761
48024762 const field_ptr = instrs[0];
48034763 const field_ptr_data = sema.code.instructions.items(.data)[@intFromEnum(field_ptr)].pl_node;
4804 const field_src: LazySrcLoc = .{ .node_offset_initializer = field_ptr_data.src_node };
4764 const field_src = block.src(.{ .node_offset_initializer = field_ptr_data.src_node });
48054765 const field_ptr_extra = sema.code.extraData(Zir.Inst.Field, field_ptr_data.payload_index).data;
48064766 const field_name = try mod.intern_pool.getOrPutString(
48074767 gpa,
......@@ -4918,7 +4878,7 @@ fn validateUnionInit(
49184878
49194879 const new_tag = Air.internedToRef(tag_val.toIntern());
49204880 const set_tag_inst = try block.addBinOp(.set_union_tag, union_ptr, new_tag);
4921 try sema.checkComptimeKnownStore(block, set_tag_inst, .unneeded); // `unneeded` since this isn't a "proper" store
4881 try sema.checkComptimeKnownStore(block, set_tag_inst, LazySrcLoc.unneeded); // `unneeded` since this isn't a "proper" store
49224882}
49234883
49244884fn validateStructInit(
......@@ -4944,7 +4904,7 @@ fn validateStructInit(
49444904
49454905 for (instrs, field_indices) |field_ptr, *field_index| {
49464906 const field_ptr_data = sema.code.instructions.items(.data)[@intFromEnum(field_ptr)].pl_node;
4947 const field_src: LazySrcLoc = .{ .node_offset_initializer = field_ptr_data.src_node };
4907 const field_src = block.src(.{ .node_offset_initializer = field_ptr_data.src_node });
49484908 const field_ptr_extra = sema.code.extraData(Zir.Inst.Field, field_ptr_data.payload_index).data;
49494909 struct_ptr_zir_ref = field_ptr_extra.lhs;
49504910 const field_name = try ip.getOrPutString(
......@@ -4981,18 +4941,18 @@ fn validateStructInit(
49814941 const field_name = struct_ty.structFieldName(i, mod).unwrap() orelse {
49824942 const template = "missing tuple field with index {d}";
49834943 if (root_msg) |msg| {
4984 try sema.errNote(block, init_src, msg, template, .{i});
4944 try sema.errNote(init_src, msg, template, .{i});
49854945 } else {
4986 root_msg = try sema.errMsg(block, init_src, template, .{i});
4946 root_msg = try sema.errMsg(init_src, template, .{i});
49874947 }
49884948 continue;
49894949 };
49904950 const template = "missing struct field: {}";
49914951 const args = .{field_name.fmt(ip)};
49924952 if (root_msg) |msg| {
4993 try sema.errNote(block, init_src, msg, template, args);
4953 try sema.errNote(init_src, msg, template, args);
49944954 } else {
4995 root_msg = try sema.errMsg(block, init_src, template, args);
4955 root_msg = try sema.errMsg(init_src, template, args);
49964956 }
49974957 continue;
49984958 }
......@@ -5007,16 +4967,7 @@ fn validateStructInit(
50074967 }
50084968
50094969 if (root_msg) |msg| {
5010 if (mod.typeToStruct(struct_ty)) |struct_type| {
5011 const decl = mod.declPtr(struct_type.decl.unwrap().?);
5012 const fqn = try decl.fullyQualifiedName(mod);
5013 try mod.errNoteNonLazy(
5014 decl.srcLoc(mod),
5015 msg,
5016 "struct '{}' declared here",
5017 .{fqn.fmt(ip)},
5018 );
5019 }
4970 try sema.addDeclaredHereNote(msg, struct_ty);
50204971 root_msg = null;
50214972 return sema.failWithOwnedErrorMsg(block, msg);
50224973 }
......@@ -5118,18 +5069,18 @@ fn validateStructInit(
51185069 const field_name = struct_ty.structFieldName(i, mod).unwrap() orelse {
51195070 const template = "missing tuple field with index {d}";
51205071 if (root_msg) |msg| {
5121 try sema.errNote(block, init_src, msg, template, .{i});
5072 try sema.errNote(init_src, msg, template, .{i});
51225073 } else {
5123 root_msg = try sema.errMsg(block, init_src, template, .{i});
5074 root_msg = try sema.errMsg(init_src, template, .{i});
51245075 }
51255076 continue;
51265077 };
51275078 const template = "missing struct field: {}";
51285079 const args = .{field_name.fmt(ip)};
51295080 if (root_msg) |msg| {
5130 try sema.errNote(block, init_src, msg, template, args);
5081 try sema.errNote(init_src, msg, template, args);
51315082 } else {
5132 root_msg = try sema.errMsg(block, init_src, template, args);
5083 root_msg = try sema.errMsg(init_src, template, args);
51335084 }
51345085 continue;
51355086 }
......@@ -5137,21 +5088,12 @@ fn validateStructInit(
51375088 }
51385089
51395090 if (!struct_is_comptime and !fields_allow_runtime and root_msg == null) {
5140 root_msg = try sema.errMsg(block, init_src, "runtime value contains reference to comptime var", .{});
5141 try sema.errNote(block, init_src, root_msg.?, "comptime var pointers are not available at runtime", .{});
5091 root_msg = try sema.errMsg(init_src, "runtime value contains reference to comptime var", .{});
5092 try sema.errNote(init_src, root_msg.?, "comptime var pointers are not available at runtime", .{});
51425093 }
51435094
51445095 if (root_msg) |msg| {
5145 if (mod.typeToStruct(struct_ty)) |struct_type| {
5146 const decl = mod.declPtr(struct_type.decl.unwrap().?);
5147 const fqn = try decl.fullyQualifiedName(mod);
5148 try mod.errNoteNonLazy(
5149 decl.srcLoc(mod),
5150 msg,
5151 "struct '{}' declared here",
5152 .{fqn.fmt(ip)},
5153 );
5154 }
5096 try sema.addDeclaredHereNote(msg, struct_ty);
51555097 root_msg = null;
51565098 return sema.failWithOwnedErrorMsg(block, msg);
51575099 }
......@@ -5253,9 +5195,9 @@ fn zirValidatePtrArrayInit(
52535195 if (default_val == .unreachable_value) {
52545196 const template = "missing tuple field with index {d}";
52555197 if (root_msg) |msg| {
5256 try sema.errNote(block, init_src, msg, template, .{i});
5198 try sema.errNote(init_src, msg, template, .{i});
52575199 } else {
5258 root_msg = try sema.errMsg(block, init_src, template, .{i});
5200 root_msg = try sema.errMsg(init_src, template, .{i});
52595201 }
52605202 continue;
52615203 }
......@@ -5455,15 +5397,13 @@ fn zirValidateDeref(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr
54555397 } else if (try sema.typeRequiresComptime(elem_ty)) {
54565398 const msg = msg: {
54575399 const msg = try sema.errMsg(
5458 block,
54595400 src,
54605401 "values of type '{}' must be comptime-known, but operand value is runtime-known",
54615402 .{elem_ty.fmt(mod)},
54625403 );
54635404 errdefer msg.destroy(sema.gpa);
54645405
5465 const src_decl = mod.declPtr(block.src_decl);
5466 try sema.explainWhyTypeIsComptime(msg, src_decl.toSrcLoc(src, mod), elem_ty);
5406 try sema.explainWhyTypeIsComptime(msg, src, elem_ty);
54675407 break :msg msg;
54685408 };
54695409 return sema.failWithOwnedErrorMsg(block, msg);
......@@ -5475,7 +5415,7 @@ fn zirValidateDestructure(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp
54755415 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
54765416 const extra = sema.code.extraData(Zir.Inst.ValidateDestructure, inst_data.payload_index).data;
54775417 const src = block.nodeOffset(inst_data.src_node);
5478 const destructure_src = LazySrcLoc.nodeOffset(extra.destructure_node);
5418 const destructure_src = block.nodeOffset(extra.destructure_node);
54795419 const operand = try sema.resolveInst(extra.operand);
54805420 const operand_ty = sema.typeOf(operand);
54815421
......@@ -5487,21 +5427,21 @@ fn zirValidateDestructure(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp
54875427
54885428 if (!can_destructure) {
54895429 return sema.failWithOwnedErrorMsg(block, msg: {
5490 const msg = try sema.errMsg(block, src, "type '{}' cannot be destructured", .{operand_ty.fmt(mod)});
5430 const msg = try sema.errMsg(src, "type '{}' cannot be destructured", .{operand_ty.fmt(mod)});
54915431 errdefer msg.destroy(sema.gpa);
5492 try sema.errNote(block, destructure_src, msg, "result destructured here", .{});
5432 try sema.errNote(destructure_src, msg, "result destructured here", .{});
54935433 break :msg msg;
54945434 });
54955435 }
54965436
54975437 if (operand_ty.arrayLen(mod) != extra.expect_len) {
54985438 return sema.failWithOwnedErrorMsg(block, msg: {
5499 const msg = try sema.errMsg(block, src, "expected {} elements for destructure, found {}", .{
5439 const msg = try sema.errMsg(src, "expected {} elements for destructure, found {}", .{
55005440 extra.expect_len,
55015441 operand_ty.arrayLen(mod),
55025442 });
55035443 errdefer msg.destroy(sema.gpa);
5504 try sema.errNote(block, destructure_src, msg, "result destructured here", .{});
5444 try sema.errNote(destructure_src, msg, "result destructured here", .{});
55055445 break :msg msg;
55065446 });
55075447 }
......@@ -5536,24 +5476,24 @@ fn failWithBadMemberAccess(
55365476fn failWithBadStructFieldAccess(
55375477 sema: *Sema,
55385478 block: *Block,
5479 struct_ty: Type,
55395480 struct_type: InternPool.LoadedStructType,
55405481 field_src: LazySrcLoc,
55415482 field_name: InternPool.NullTerminatedString,
55425483) CompileError {
5543 const mod = sema.mod;
5484 const zcu = sema.mod;
55445485 const gpa = sema.gpa;
5545 const decl = mod.declPtr(struct_type.decl.unwrap().?);
5546 const fqn = try decl.fullyQualifiedName(mod);
5486 const decl = zcu.declPtr(struct_type.decl.unwrap().?);
5487 const fqn = try decl.fullyQualifiedName(zcu);
55475488
55485489 const msg = msg: {
55495490 const msg = try sema.errMsg(
5550 block,
55515491 field_src,
55525492 "no field named '{}' in struct '{}'",
5553 .{ field_name.fmt(&mod.intern_pool), fqn.fmt(&mod.intern_pool) },
5493 .{ field_name.fmt(&zcu.intern_pool), fqn.fmt(&zcu.intern_pool) },
55545494 );
55555495 errdefer msg.destroy(gpa);
5556 try mod.errNoteNonLazy(decl.srcLoc(mod), msg, "struct declared here", .{});
5496 try sema.errNote(struct_ty.srcLoc(zcu), msg, "struct declared here", .{});
55575497 break :msg msg;
55585498 };
55595499 return sema.failWithOwnedErrorMsg(block, msg);
......@@ -5562,25 +5502,25 @@ fn failWithBadStructFieldAccess(
55625502fn failWithBadUnionFieldAccess(
55635503 sema: *Sema,
55645504 block: *Block,
5505 union_ty: Type,
55655506 union_obj: InternPool.LoadedUnionType,
55665507 field_src: LazySrcLoc,
55675508 field_name: InternPool.NullTerminatedString,
55685509) CompileError {
5569 const mod = sema.mod;
5510 const zcu = sema.mod;
55705511 const gpa = sema.gpa;
55715512
5572 const decl = mod.declPtr(union_obj.decl);
5573 const fqn = try decl.fullyQualifiedName(mod);
5513 const decl = zcu.declPtr(union_obj.decl);
5514 const fqn = try decl.fullyQualifiedName(zcu);
55745515
55755516 const msg = msg: {
55765517 const msg = try sema.errMsg(
5577 block,
55785518 field_src,
55795519 "no field named '{}' in union '{}'",
5580 .{ field_name.fmt(&mod.intern_pool), fqn.fmt(&mod.intern_pool) },
5520 .{ field_name.fmt(&zcu.intern_pool), fqn.fmt(&zcu.intern_pool) },
55815521 );
55825522 errdefer msg.destroy(gpa);
5583 try mod.errNoteNonLazy(decl.srcLoc(mod), msg, "union declared here", .{});
5523 try sema.errNote(union_ty.srcLoc(zcu), msg, "union declared here", .{});
55845524 break :msg msg;
55855525 };
55865526 return sema.failWithOwnedErrorMsg(block, msg);
......@@ -5588,16 +5528,15 @@ fn failWithBadUnionFieldAccess(
55885528
55895529fn addDeclaredHereNote(sema: *Sema, parent: *Module.ErrorMsg, decl_ty: Type) !void {
55905530 const mod = sema.mod;
5591 const src_loc = decl_ty.declSrcLocOrNull(mod) orelse return;
5531 const src_loc = decl_ty.srcLocOrNull(mod) orelse return;
55925532 const category = switch (decl_ty.zigTypeTag(mod)) {
55935533 .Union => "union",
55945534 .Struct => "struct",
55955535 .Enum => "enum",
55965536 .Opaque => "opaque",
5597 .ErrorSet => "error set",
55985537 else => unreachable,
55995538 };
5600 try mod.errNoteNonLazy(src_loc, parent, "{s} declared here", .{category});
5539 try sema.errNote(src_loc, parent, "{s} declared here", .{category});
56015540}
56025541
56035542fn zirStoreToInferredPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void {
......@@ -5722,8 +5661,8 @@ fn zirStoreNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!v
57225661 else => {},
57235662 };
57245663
5725 const ptr_src: LazySrcLoc = .{ .node_offset_store_ptr = inst_data.src_node };
5726 const operand_src: LazySrcLoc = .{ .node_offset_store_operand = inst_data.src_node };
5664 const ptr_src = block.src(.{ .node_offset_store_ptr = inst_data.src_node });
5665 const operand_src = block.src(.{ .node_offset_store_operand = inst_data.src_node });
57275666 const air_tag: Air.Inst.Tag = if (is_ret)
57285667 .ret_ptr
57295668 else if (block.wantSafety())
......@@ -5837,7 +5776,7 @@ fn zirCompileError(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
58375776
58385777 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
58395778 const src = block.nodeOffset(inst_data.src_node);
5840 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
5779 const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0);
58415780 const msg = try sema.resolveConstString(block, operand_src, inst_data.operand, .{
58425781 .needed_comptime_reason = "compile error string must be comptime-known",
58435782 });
......@@ -5846,6 +5785,7 @@ fn zirCompileError(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
58465785
58475786fn zirCompileLog(
58485787 sema: *Sema,
5788 block: *Block,
58495789 extended: Zir.Inst.Extended.InstData,
58505790) CompileError!Air.Inst.Ref {
58515791 const mod = sema.mod;
......@@ -5878,9 +5818,10 @@ fn zirCompileLog(
58785818 else
58795819 sema.owner_decl_index;
58805820 const gop = try mod.compile_log_decls.getOrPut(sema.gpa, decl_index);
5881 if (!gop.found_existing) {
5882 gop.value_ptr.* = src_node;
5883 }
5821 if (!gop.found_existing) gop.value_ptr.* = .{
5822 .base_node_inst = block.src_base_inst,
5823 .node_offset = src_node,
5824 };
58845825 return .void_value;
58855826}
58865827
......@@ -5891,7 +5832,7 @@ fn zirPanic(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void
58915832
58925833 // `panicWithMsg` would perform this coercion for us, but we can get a better
58935834 // source location if we do it here.
5894 const coerced_msg = try sema.coerce(block, Type.slice_const_u8, msg_inst, .{ .node_offset_builtin_call_arg0 = inst_data.src_node });
5835 const coerced_msg = try sema.coerce(block, Type.slice_const_u8, msg_inst, block.builtinCallArgSrc(inst_data.src_node, 0));
58955836
58965837 if (block.is_comptime) {
58975838 return sema.fail(block, src, "encountered @panic at comptime", .{});
......@@ -5901,7 +5842,7 @@ fn zirPanic(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void
59015842
59025843fn zirTrap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void {
59035844 const src_node = sema.code.instructions.items(.data)[@intFromEnum(inst)].node;
5904 const src = LazySrcLoc.nodeOffset(src_node);
5845 const src = block.nodeOffset(src_node);
59055846 if (block.is_comptime)
59065847 return sema.fail(block, src, "encountered @trap at comptime", .{});
59075848 _ = try block.addNoOp(.trap);
......@@ -5948,7 +5889,7 @@ fn zirLoop(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError
59485889 var child_block = parent_block.makeSubBlock();
59495890 child_block.label = &label;
59505891 child_block.runtime_cond = null;
5951 child_block.runtime_loop = mod.declPtr(child_block.src_decl).toSrcLoc(src, mod);
5892 child_block.runtime_loop = src;
59525893 child_block.runtime_index.increment();
59535894 const merges = &child_block.label.?.merges;
59545895
......@@ -5997,10 +5938,7 @@ fn zirCImport(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileEr
59975938 var c_import_buf = std.ArrayList(u8).init(gpa);
59985939 defer c_import_buf.deinit();
59995940
6000 var comptime_reason: Block.ComptimeReason = .{ .c_import = .{
6001 .block = parent_block,
6002 .src = src,
6003 } };
5941 const comptime_reason: Block.ComptimeReason = .{ .c_import = .{ .src = src } };
60045942 var child_block: Block = .{
60055943 .parent = parent_block,
60065944 .sema = sema,
......@@ -6014,6 +5952,7 @@ fn zirCImport(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileEr
60145952 .runtime_cond = parent_block.runtime_cond,
60155953 .runtime_loop = parent_block.runtime_loop,
60165954 .runtime_index = parent_block.runtime_index,
5955 .src_base_inst = parent_block.src_base_inst,
60175956 };
60185957 defer child_block.instructions.deinit(gpa);
60195958
......@@ -6025,11 +5964,11 @@ fn zirCImport(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileEr
60255964
60265965 if (c_import_res.errors.errorMessageCount() != 0) {
60275966 const msg = msg: {
6028 const msg = try sema.errMsg(&child_block, src, "C import failed", .{});
5967 const msg = try sema.errMsg(src, "C import failed", .{});
60295968 errdefer msg.destroy(gpa);
60305969
60315970 if (!comp.config.link_libc)
6032 try sema.errNote(&child_block, src, msg, "libc headers not available; compilation does not link against libc", .{});
5971 try sema.errNote(src, msg, "libc headers not available; compilation does not link against libc", .{});
60335972
60345973 const gop = try mod.cimport_errors.getOrPut(gpa, sema.owner_decl_index);
60355974 if (!gop.found_existing) {
......@@ -6139,6 +6078,7 @@ fn zirBlock(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index, force_compt
61396078 .runtime_loop = parent_block.runtime_loop,
61406079 .runtime_index = parent_block.runtime_index,
61416080 .error_return_trace_index = parent_block.error_return_trace_index,
6081 .src_base_inst = parent_block.src_base_inst,
61426082 };
61436083
61446084 defer child_block.instructions.deinit(gpa);
......@@ -6333,14 +6273,13 @@ fn resolveAnalyzedBlock(
63336273 const type_src = src; // TODO: better source location
63346274 if (try sema.typeRequiresComptime(resolved_ty)) {
63356275 const msg = msg: {
6336 const msg = try sema.errMsg(child_block, type_src, "value with comptime-only type '{}' depends on runtime control flow", .{resolved_ty.fmt(mod)});
6276 const msg = try sema.errMsg(type_src, "value with comptime-only type '{}' depends on runtime control flow", .{resolved_ty.fmt(mod)});
63376277 errdefer msg.destroy(sema.gpa);
63386278
63396279 const runtime_src = child_block.runtime_cond orelse child_block.runtime_loop.?;
6340 try mod.errNoteNonLazy(runtime_src, msg, "runtime control flow here", .{});
6280 try sema.errNote(runtime_src, msg, "runtime control flow here", .{});
63416281
6342 const child_src_decl = mod.declPtr(child_block.src_decl);
6343 try sema.explainWhyTypeIsComptime(msg, child_src_decl.toSrcLoc(type_src, mod), resolved_ty);
6282 try sema.explainWhyTypeIsComptime(msg, type_src, resolved_ty);
63446283
63456284 break :msg msg;
63466285 };
......@@ -6433,8 +6372,8 @@ fn zirExport(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void
64336372 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
64346373 const extra = sema.code.extraData(Zir.Inst.Export, inst_data.payload_index).data;
64356374 const src = block.nodeOffset(inst_data.src_node);
6436 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
6437 const options_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };
6375 const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0);
6376 const options_src = block.builtinCallArgSrc(inst_data.src_node, 1);
64386377 const decl_name = try mod.intern_pool.getOrPutString(
64396378 mod.gpa,
64406379 sema.code.nullTerminatedString(extra.decl_name),
......@@ -6448,13 +6387,7 @@ fn zirExport(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void
64486387 break :index_blk maybe_index orelse
64496388 return sema.failWithBadMemberAccess(block, container_ty, operand_src, decl_name);
64506389 } else try sema.lookupIdentifier(block, operand_src, decl_name);
6451 const options = sema.resolveExportOptions(block, .unneeded, extra.options) catch |err| switch (err) {
6452 error.NeededSourceLocation => {
6453 _ = try sema.resolveExportOptions(block, options_src, extra.options);
6454 unreachable;
6455 },
6456 else => |e| return e,
6457 };
6390 const options = try sema.resolveExportOptions(block, options_src, extra.options);
64586391 {
64596392 try sema.ensureDeclAnalyzed(decl_index);
64606393 const exported_decl = mod.declPtr(decl_index);
......@@ -6473,8 +6406,8 @@ fn zirExportValue(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
64736406 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
64746407 const extra = sema.code.extraData(Zir.Inst.ExportValue, inst_data.payload_index).data;
64756408 const src = block.nodeOffset(inst_data.src_node);
6476 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
6477 const options_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };
6409 const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0);
6410 const options_src = block.builtinCallArgSrc(inst_data.src_node, 1);
64786411 const operand = try sema.resolveInstConst(block, operand_src, extra.operand, .{
64796412 .needed_comptime_reason = "export target must be comptime-known",
64806413 });
......@@ -6490,7 +6423,6 @@ fn zirExportValue(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
64906423 .opts = options,
64916424 .src = src,
64926425 .owner_decl = sema.owner_decl_index,
6493 .src_decl = block.src_decl,
64946426 .exported = .{ .value = operand.toIntern() },
64956427 .status = .in_progress,
64966428 });
......@@ -6515,11 +6447,10 @@ pub fn analyzeExport(
65156447
65166448 if (!try sema.validateExternType(export_ty, .other)) {
65176449 const msg = msg: {
6518 const msg = try sema.errMsg(block, src, "unable to export type '{}'", .{export_ty.fmt(mod)});
6450 const msg = try sema.errMsg(src, "unable to export type '{}'", .{export_ty.fmt(mod)});
65196451 errdefer msg.destroy(gpa);
65206452
6521 const src_decl = mod.declPtr(block.src_decl);
6522 try sema.explainWhyTypeIsNotExtern(msg, src_decl.toSrcLoc(src, mod), export_ty, .other);
6453 try sema.explainWhyTypeIsNotExtern(msg, src, export_ty, .other);
65236454
65246455 try sema.addDeclaredHereNote(msg, export_ty);
65256456 break :msg msg;
......@@ -6538,7 +6469,6 @@ pub fn analyzeExport(
65386469 .opts = options,
65396470 .src = src,
65406471 .owner_decl = sema.owner_decl_index,
6541 .src_decl = block.src_decl,
65426472 .exported = .{ .decl_index = exported_decl_index },
65436473 .status = .in_progress,
65446474 });
......@@ -6578,8 +6508,8 @@ fn addExport(mod: *Module, export_init: Module.Export) error{OutOfMemory}!void {
65786508fn zirSetAlignStack(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!void {
65796509 const mod = sema.mod;
65806510 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;
6581 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node };
6582 const src = LazySrcLoc.nodeOffset(extra.node);
6511 const operand_src = block.builtinCallArgSrc(extra.node, 0);
6512 const src = block.nodeOffset(extra.node);
65836513 const alignment = try sema.resolveAlign(block, operand_src, extra.operand);
65846514 if (alignment.order(Alignment.fromNonzeroByteUnits(256)).compare(.gt)) {
65856515 return sema.fail(block, src, "attempt to @setAlignStack({d}); maximum is 256", .{
......@@ -6598,9 +6528,9 @@ fn zirSetAlignStack(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.Inst
65986528
65996529 if (sema.prev_stack_alignment_src) |prev_src| {
66006530 const msg = msg: {
6601 const msg = try sema.errMsg(block, src, "multiple @setAlignStack in the same function body", .{});
6531 const msg = try sema.errMsg(src, "multiple @setAlignStack in the same function body", .{});
66026532 errdefer msg.destroy(sema.gpa);
6603 try sema.errNote(block, prev_src, msg, "other instance here", .{});
6533 try sema.errNote(prev_src, msg, "other instance here", .{});
66046534 break :msg msg;
66056535 };
66066536 return sema.failWithOwnedErrorMsg(block, msg);
......@@ -6621,7 +6551,7 @@ fn zirSetCold(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData)
66216551 const mod = sema.mod;
66226552 const ip = &mod.intern_pool;
66236553 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;
6624 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node };
6554 const operand_src = block.builtinCallArgSrc(extra.node, 0);
66256555 const is_cold = try sema.resolveConstBool(block, operand_src, extra.operand, .{
66266556 .needed_comptime_reason = "operand to @setCold must be comptime-known",
66276557 });
......@@ -6631,7 +6561,7 @@ fn zirSetCold(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData)
66316561
66326562fn zirSetFloatMode(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!void {
66336563 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;
6634 const src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node };
6564 const src = block.builtinCallArgSrc(extra.node, 0);
66356565 block.float_mode = try sema.resolveBuiltinEnum(block, src, extra.operand, "FloatMode", .{
66366566 .needed_comptime_reason = "operand to @setFloatMode must be comptime-known",
66376567 });
......@@ -6639,7 +6569,7 @@ fn zirSetFloatMode(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstD
66396569
66406570fn zirSetRuntimeSafety(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void {
66416571 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
6642 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
6572 const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0);
66436573 block.want_safety = try sema.resolveConstBool(block, operand_src, inst_data.operand, .{
66446574 .needed_comptime_reason = "operand to @setRuntimeSafety must be comptime-known",
66456575 });
......@@ -6649,7 +6579,7 @@ fn zirFence(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) Co
66496579 if (block.is_comptime) return;
66506580
66516581 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;
6652 const order_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node };
6582 const order_src = block.builtinCallArgSrc(extra.node, 0);
66536583 const order = try sema.resolveAtomicOrder(block, order_src, extra.operand, .{
66546584 .needed_comptime_reason = "atomic order of @fence must be comptime-known",
66556585 });
......@@ -6679,7 +6609,7 @@ fn zirBreak(sema: *Sema, start_block: *Block, inst: Zir.Inst.Index) CompileError
66796609 if (label.zir_block == zir_block) {
66806610 const br_ref = try start_block.addBr(label.merges.block_inst, operand);
66816611 const src_loc = if (extra.operand_src_node != Zir.Inst.Break.no_src_node)
6682 LazySrcLoc.nodeOffset(extra.operand_src_node)
6612 start_block.nodeOffset(extra.operand_src_node)
66836613 else
66846614 null;
66856615 try label.merges.src_locs.append(sema.gpa, src_loc);
......@@ -6906,12 +6836,14 @@ fn lookupInNamespace(
69066836 },
69076837 else => {
69086838 const msg = msg: {
6909 const msg = try sema.errMsg(block, src, "ambiguous reference", .{});
6839 const msg = try sema.errMsg(src, "ambiguous reference", .{});
69106840 errdefer msg.destroy(gpa);
69116841 for (candidates.items) |candidate_index| {
69126842 const candidate = mod.declPtr(candidate_index);
6913 const src_loc = candidate.srcLoc(mod);
6914 try mod.errNoteNonLazy(src_loc, msg, "declared here", .{});
6843 try sema.errNote(.{
6844 .base_node_inst = candidate.zir_decl_index.unwrap().?,
6845 .offset = LazySrcLoc.Offset.nodeOffset(0),
6846 }, msg, "declared here", .{});
69156847 }
69166848 break :msg msg;
69176849 };
......@@ -6953,16 +6885,16 @@ pub fn analyzeSaveErrRetIndex(sema: *Sema, block: *Block) SemaError!Air.Inst.Ref
69536885 if (!block.ownerModule().error_tracing) return .none;
69546886
69556887 const stack_trace_ty = sema.getBuiltinType("StackTrace") catch |err| switch (err) {
6956 error.NeededSourceLocation, error.GenericPoison, error.ComptimeReturn, error.ComptimeBreak => unreachable,
6888 error.GenericPoison, error.ComptimeReturn, error.ComptimeBreak => unreachable,
69576889 else => |e| return e,
69586890 };
69596891 sema.resolveTypeFields(stack_trace_ty) catch |err| switch (err) {
6960 error.NeededSourceLocation, error.GenericPoison, error.ComptimeReturn, error.ComptimeBreak => unreachable,
6892 error.GenericPoison, error.ComptimeReturn, error.ComptimeBreak => unreachable,
69616893 else => |e| return e,
69626894 };
69636895 const field_name = try mod.intern_pool.getOrPutString(gpa, "index", .no_embedded_nulls);
6964 const field_index = sema.structFieldIndex(block, stack_trace_ty, field_name, .unneeded) catch |err| switch (err) {
6965 error.AnalysisFail, error.NeededSourceLocation => @panic("std.builtin.StackTrace is corrupt"),
6896 const field_index = sema.structFieldIndex(block, stack_trace_ty, field_name, LazySrcLoc.unneeded) catch |err| switch (err) {
6897 error.AnalysisFail => @panic("std.builtin.StackTrace is corrupt"),
69666898 error.GenericPoison, error.ComptimeReturn, error.ComptimeBreak => unreachable,
69676899 error.OutOfMemory => |e| return e,
69686900 };
......@@ -7070,7 +7002,7 @@ fn zirCall(
70707002
70717003 const mod = sema.mod;
70727004 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
7073 const callee_src: LazySrcLoc = .{ .node_offset_call_func = inst_data.src_node };
7005 const callee_src = block.src(.{ .node_offset_call_func = inst_data.src_node });
70747006 const call_src = block.nodeOffset(inst_data.src_node);
70757007 const ExtraType = switch (kind) {
70767008 .direct => Zir.Inst.Call,
......@@ -7092,7 +7024,7 @@ fn zirCall(
70927024 sema.code.nullTerminatedString(extra.data.field_name_start),
70937025 .no_embedded_nulls,
70947026 );
7095 const field_name_src: LazySrcLoc = .{ .node_offset_field_name = inst_data.src_node };
7027 const field_name_src = block.src(.{ .node_offset_field_name = inst_data.src_node });
70967028 break :blk try sema.fieldCallBind(block, callee_src, object_ptr, field_name, field_name_src);
70977029 },
70987030 };
......@@ -7202,11 +7134,11 @@ fn checkCallArgumentCount(
72027134 opt_child.childType(mod).zigTypeTag(mod) == .Fn))
72037135 {
72047136 const msg = msg: {
7205 const msg = try sema.errMsg(block, func_src, "cannot call optional type '{}'", .{
7137 const msg = try sema.errMsg(func_src, "cannot call optional type '{}'", .{
72067138 callee_ty.fmt(mod),
72077139 });
72087140 errdefer msg.destroy(sema.gpa);
7209 try sema.errNote(block, func_src, msg, "consider using '.?', 'orelse' or 'if'", .{});
7141 try sema.errNote(func_src, msg, "consider using '.?', 'orelse' or 'if'", .{});
72107142 break :msg msg;
72117143 };
72127144 return sema.failWithOwnedErrorMsg(block, msg);
......@@ -7232,7 +7164,6 @@ fn checkCallArgumentCount(
72327164 const variadic_str = if (func_ty_info.is_var_args) "at least " else "";
72337165 const msg = msg: {
72347166 const msg = try sema.errMsg(
7235 block,
72367167 func_src,
72377168 "{s}expected {s}{d} argument(s), found {d}",
72387169 .{
......@@ -7244,7 +7175,12 @@ fn checkCallArgumentCount(
72447175 );
72457176 errdefer msg.destroy(sema.gpa);
72467177
7247 if (maybe_decl) |fn_decl| try mod.errNoteNonLazy(fn_decl.srcLoc(mod), msg, "function declared here", .{});
7178 if (maybe_decl) |fn_decl| {
7179 try sema.errNote(.{
7180 .base_node_inst = fn_decl.zir_decl_index.unwrap().?,
7181 .offset = LazySrcLoc.Offset.nodeOffset(0),
7182 }, msg, "function declared here", .{});
7183 }
72487184 break :msg msg;
72497185 };
72507186 return sema.failWithOwnedErrorMsg(block, msg);
......@@ -7352,18 +7288,16 @@ const CallArgsInfo = union(enum) {
73527288 fn argSrc(cai: CallArgsInfo, block: *Block, arg_index: usize) LazySrcLoc {
73537289 return switch (cai) {
73547290 .resolved => |resolved| resolved.src,
7355 .call_builtin => |call_builtin| .{ .call_arg = .{
7356 .decl = block.src_decl,
7291 .call_builtin => |call_builtin| block.src(.{ .call_arg = .{
73577292 .call_node_offset = call_builtin.call_node_offset,
73587293 .arg_index = @intCast(arg_index),
7359 } },
7294 } }),
73607295 .zir_call => |zir_call| if (arg_index == 0 and zir_call.bound_arg != .none) {
73617296 return zir_call.bound_arg_src;
7362 } else .{ .call_arg = .{
7363 .decl = block.src_decl,
7297 } else block.src(.{ .call_arg = .{
73647298 .call_node_offset = zir_call.call_node_offset,
73657299 .arg_index = @intCast(arg_index - @intFromBool(zir_call.bound_arg != .none)),
7366 } },
7300 } }),
73677301 };
73687302 }
73697303
......@@ -7475,7 +7409,6 @@ const InlineCallSema = struct {
74757409 other_error_return_trace_index_on_fn_entry: Air.Inst.Ref,
74767410 other_generic_owner: InternPool.Index,
74777411 other_generic_call_src: LazySrcLoc,
7478 other_generic_call_decl: InternPool.OptionalDeclIndex,
74797412
74807413 /// Sema should currently be set up for the caller (i.e. unchanged yet). This init will not
74817414 /// change that. The other parameters contain data for the callee Sema. The other modified
......@@ -7497,8 +7430,7 @@ const InlineCallSema = struct {
74977430 .other_inst_map = .{},
74987431 .other_error_return_trace_index_on_fn_entry = callee_error_return_trace_index_on_fn_entry,
74997432 .other_generic_owner = .none,
7500 .other_generic_call_src = .unneeded,
7501 .other_generic_call_decl = .none,
7433 .other_generic_call_src = LazySrcLoc.unneeded,
75027434 };
75037435 }
75047436
......@@ -7545,7 +7477,6 @@ const InlineCallSema = struct {
75457477 std.mem.swap(InstMap, &ics.sema.inst_map, &ics.other_inst_map);
75467478 std.mem.swap(InternPool.Index, &ics.sema.generic_owner, &ics.other_generic_owner);
75477479 std.mem.swap(LazySrcLoc, &ics.sema.generic_call_src, &ics.other_generic_call_src);
7548 std.mem.swap(InternPool.OptionalDeclIndex, &ics.sema.generic_call_decl, &ics.other_generic_call_decl);
75497480 std.mem.swap(Air.Inst.Ref, &ics.sema.error_return_trace_index_on_fn_entry, &ics.other_error_return_trace_index_on_fn_entry);
75507481 // zig fmt: on
75517482 }
......@@ -7577,14 +7508,16 @@ fn analyzeCall(
75777508 const maybe_decl = try sema.funcDeclSrc(func);
75787509 const msg = msg: {
75797510 const msg = try sema.errMsg(
7580 block,
75817511 func_src,
75827512 "unable to call function with naked calling convention",
75837513 .{},
75847514 );
75857515 errdefer msg.destroy(sema.gpa);
75867516
7587 if (maybe_decl) |fn_decl| try mod.errNoteNonLazy(fn_decl.srcLoc(mod), msg, "function declared here", .{});
7517 if (maybe_decl) |fn_decl| try sema.errNote(.{
7518 .base_node_inst = fn_decl.zir_decl_index.unwrap().?,
7519 .offset = LazySrcLoc.Offset.nodeOffset(0),
7520 }, msg, "function declared here", .{});
75887521 break :msg msg;
75897522 };
75907523 return sema.failWithOwnedErrorMsg(block, msg);
......@@ -7623,7 +7556,6 @@ fn analyzeCall(
76237556 is_inline_call = ct;
76247557 if (ct) {
76257558 comptime_reason = &.{ .comptime_ret_ty = .{
7626 .block = block,
76277559 .func = func,
76287560 .func_src = func_src,
76297561 .return_ty = Type.fromInterned(func_ty_info.return_type),
......@@ -7637,12 +7569,12 @@ fn analyzeCall(
76377569
76387570 if (sema.func_is_naked and !is_inline_call and !is_comptime_call) {
76397571 const msg = msg: {
7640 const msg = try sema.errMsg(block, call_src, "runtime {s} not allowed in naked function", .{@tagName(operation)});
7572 const msg = try sema.errMsg(call_src, "runtime {s} not allowed in naked function", .{@tagName(operation)});
76417573 errdefer msg.destroy(sema.gpa);
76427574
76437575 switch (operation) {
76447576 .call, .@"@call", .@"@panic", .@"error return" => {},
7645 .@"safety check" => try sema.errNote(block, call_src, msg, "use @setRuntimeSafety to disable runtime safety", .{}),
7577 .@"safety check" => try sema.errNote(call_src, msg, "use @setRuntimeSafety to disable runtime safety", .{}),
76467578 }
76477579 break :msg msg;
76487580 };
......@@ -7669,7 +7601,6 @@ fn analyzeCall(
76697601 is_inline_call = true;
76707602 is_comptime_call = true;
76717603 comptime_reason = &.{ .comptime_ret_ty = .{
7672 .block = block,
76737604 .func = func,
76747605 .func_src = func_src,
76757606 .return_ty = Type.fromInterned(func_ty_info.return_type),
......@@ -7776,6 +7707,7 @@ fn analyzeCall(
77767707 .runtime_cond = block.runtime_cond,
77777708 .runtime_loop = block.runtime_loop,
77787709 .runtime_index = block.runtime_index,
7710 .src_base_inst = fn_owner_decl.zir_decl_index.unwrap().?,
77797711 };
77807712
77817713 const merges = &child_block.inlining.?.merges;
......@@ -7849,7 +7781,7 @@ fn analyzeCall(
78497781 var block_it = block;
78507782 while (block_it.inlining) |parent_inlining| {
78517783 if (!parent_inlining.has_comptime_args and parent_inlining.func == module_fn_index) {
7852 const err_msg = try sema.errMsg(block, call_src, "inline call is recursive", .{});
7784 const err_msg = try sema.errMsg(call_src, "inline call is recursive", .{});
78537785 return sema.failWithOwnedErrorMsg(null, err_msg);
78547786 }
78557787 block_it = parent_inlining.call_block;
......@@ -7864,7 +7796,7 @@ fn analyzeCall(
78647796 try sema.resolveInlineBody(&child_block, fn_info.ret_ty_body, module_fn.zir_body_inst.resolve(ip))
78657797 else
78667798 try sema.resolveInst(fn_info.ret_ty_ref);
7867 const ret_ty_src: LazySrcLoc = .{ .node_offset_fn_type_ret_ty = 0 };
7799 const ret_ty_src: LazySrcLoc = .{ .base_node_inst = module_fn.zir_body_inst, .offset = .{ .node_offset_fn_type_ret_ty = 0 } };
78687800 sema.fn_ret_ty = try sema.analyzeAsType(&child_block, ret_ty_src, ret_ty_inst);
78697801 if (module_fn.analysis(ip).inferred_error_set) {
78707802 // Create a fresh inferred error set type for inline/comptime calls.
......@@ -7935,7 +7867,7 @@ fn analyzeCall(
79357867 };
79367868
79377869 if (is_comptime_call) {
7938 const result_val = try sema.resolveConstValue(block, .unneeded, result, undefined);
7870 const result_val = try sema.resolveConstValue(block, LazySrcLoc.unneeded, result, undefined);
79397871 const result_interned = result_val.toIntern();
79407872
79417873 // Transform ad-hoc inferred error set types into concrete error sets.
......@@ -8276,7 +8208,6 @@ fn instantiateGenericCall(
82768208 .comptime_args = comptime_args,
82778209 .generic_owner = generic_owner,
82788210 .generic_call_src = call_src,
8279 .generic_call_decl = block.src_decl.toOptional(),
82808211 .branch_quota = sema.branch_quota,
82818212 .branch_count = sema.branch_count,
82828213 .comptime_err_ret_trace = sema.comptime_err_ret_trace,
......@@ -8291,6 +8222,7 @@ fn instantiateGenericCall(
82918222 .instructions = .{},
82928223 .inlining = null,
82938224 .is_comptime = true,
8225 .src_base_inst = fn_owner_decl.zir_decl_index.unwrap().?,
82948226 };
82958227 defer child_block.instructions.deinit(gpa);
82968228
......@@ -8321,18 +8253,15 @@ fn instantiateGenericCall(
83218253 const prev_no_partial_func_ty = child_sema.no_partial_func_ty;
83228254 const prev_generic_owner = child_sema.generic_owner;
83238255 const prev_generic_call_src = child_sema.generic_call_src;
8324 const prev_generic_call_decl = child_sema.generic_call_decl;
83258256 child_block.params = .{};
83268257 child_sema.no_partial_func_ty = true;
83278258 child_sema.generic_owner = .none;
8328 child_sema.generic_call_src = .unneeded;
8329 child_sema.generic_call_decl = .none;
8259 child_sema.generic_call_src = LazySrcLoc.unneeded;
83308260 defer {
83318261 child_block.params = prev_params;
83328262 child_sema.no_partial_func_ty = prev_no_partial_func_ty;
83338263 child_sema.generic_owner = prev_generic_owner;
83348264 child_sema.generic_call_src = prev_generic_call_src;
8335 child_sema.generic_call_decl = prev_generic_call_decl;
83368265 }
83378266
83388267 const param_ty_inst = try child_sema.resolveInlineBody(&child_block, param_ty_body, param_inst);
......@@ -8372,14 +8301,14 @@ fn instantiateGenericCall(
83728301 .param_anytype_comptime,
83738302 => return sema.failWithOwnedErrorMsg(block, msg: {
83748303 const arg_src = args_info.argSrc(block, arg_index);
8375 const msg = try sema.errMsg(block, arg_src, "runtime-known argument passed to comptime parameter", .{});
8304 const msg = try sema.errMsg(arg_src, "runtime-known argument passed to comptime parameter", .{});
83768305 errdefer msg.destroy(sema.gpa);
83778306 const param_src = child_block.tokenOffset(switch (param_tag) {
83788307 .param_comptime => fn_zir.instructions.items(.data)[@intFromEnum(param_inst)].pl_tok.src_tok,
83798308 .param_anytype_comptime => fn_zir.instructions.items(.data)[@intFromEnum(param_inst)].str_tok.src_tok,
83808309 else => unreachable,
83818310 });
8382 try child_sema.errNote(&child_block, param_src, msg, "declared comptime here", .{});
8311 try child_sema.errNote(param_src, msg, "declared comptime here", .{});
83838312 break :msg msg;
83848313 }),
83858314
......@@ -8387,16 +8316,15 @@ fn instantiateGenericCall(
83878316 .param_anytype,
83888317 => return sema.failWithOwnedErrorMsg(block, msg: {
83898318 const arg_src = args_info.argSrc(block, arg_index);
8390 const msg = try sema.errMsg(block, arg_src, "runtime-known argument passed to parameter of comptime-only type", .{});
8319 const msg = try sema.errMsg(arg_src, "runtime-known argument passed to parameter of comptime-only type", .{});
83918320 errdefer msg.destroy(sema.gpa);
83928321 const param_src = child_block.tokenOffset(switch (param_tag) {
83938322 .param => fn_zir.instructions.items(.data)[@intFromEnum(param_inst)].pl_tok.src_tok,
83948323 .param_anytype => fn_zir.instructions.items(.data)[@intFromEnum(param_inst)].str_tok.src_tok,
83958324 else => unreachable,
83968325 });
8397 try child_sema.errNote(&child_block, param_src, msg, "declared here", .{});
8398 const src_decl = mod.declPtr(block.src_decl);
8399 try sema.explainWhyTypeIsComptime(msg, src_decl.toSrcLoc(arg_src, mod), arg_ty);
8326 try child_sema.errNote(param_src, msg, "declared here", .{});
8327 try sema.explainWhyTypeIsComptime(msg, arg_src, arg_ty);
84008328 break :msg msg;
84018329 }),
84028330
......@@ -8433,7 +8361,7 @@ fn instantiateGenericCall(
84338361 // We've already handled parameters, so don't resolve the whole body. Instead, just
84348362 // do the instructions after the params (i.e. the func itself).
84358363 const new_func_inst = try child_sema.resolveInlineBody(&child_block, fn_info.param_body[args_info.count()..], fn_info.param_body_inst);
8436 const callee_index = (child_sema.resolveConstDefinedValue(&child_block, .unneeded, new_func_inst, undefined) catch unreachable).toIntern();
8364 const callee_index = (child_sema.resolveConstDefinedValue(&child_block, LazySrcLoc.unneeded, new_func_inst, undefined) catch unreachable).toIntern();
84378365
84388366 const callee = mod.funcInfo(callee_index);
84398367 callee.branchQuota(ip).* = @max(callee.branchQuota(ip).*, sema.branch_quota);
......@@ -8520,7 +8448,7 @@ fn zirOptionalType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
85208448
85218449 const mod = sema.mod;
85228450 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
8523 const operand_src: LazySrcLoc = .{ .node_offset_un_op = inst_data.src_node };
8451 const operand_src = block.src(.{ .node_offset_un_op = inst_data.src_node });
85248452 const child_type = try sema.resolveType(block, operand_src, inst_data.operand);
85258453 if (child_type.zigTypeTag(mod) == .Opaque) {
85268454 return sema.fail(block, operand_src, "opaque type '{}' cannot be optional", .{child_type.fmt(mod)});
......@@ -8535,7 +8463,7 @@ fn zirOptionalType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
85358463fn zirArrayInitElemType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
85368464 const mod = sema.mod;
85378465 const bin = sema.code.instructions.items(.data)[@intFromEnum(inst)].bin;
8538 const maybe_wrapped_indexable_ty = sema.resolveType(block, .unneeded, bin.lhs) catch |err| switch (err) {
8466 const maybe_wrapped_indexable_ty = sema.resolveType(block, LazySrcLoc.unneeded, bin.lhs) catch |err| switch (err) {
85398467 // Since this is a ZIR instruction that returns a type, encountering
85408468 // generic poison should not result in a failed compilation, but the
85418469 // generic poison type. This prevents unnecessary failures when
......@@ -8558,7 +8486,7 @@ fn zirArrayInitElemType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compil
85588486fn zirElemType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
85598487 const mod = sema.mod;
85608488 const un_node = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
8561 const maybe_wrapped_ptr_ty = sema.resolveType(block, .unneeded, un_node.operand) catch |err| switch (err) {
8489 const maybe_wrapped_ptr_ty = sema.resolveType(block, LazySrcLoc.unneeded, un_node.operand) catch |err| switch (err) {
85628490 error.GenericPoison => return .generic_poison_type,
85638491 else => |e| return e,
85648492 };
......@@ -8592,7 +8520,7 @@ fn zirIndexablePtrElemType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com
85928520fn zirVectorElemType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
85938521 const mod = sema.mod;
85948522 const un_node = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
8595 const vec_ty = sema.resolveType(block, .unneeded, un_node.operand) catch |err| switch (err) {
8523 const vec_ty = sema.resolveType(block, LazySrcLoc.unneeded, un_node.operand) catch |err| switch (err) {
85968524 // Since this is a ZIR instruction that returns a type, encountering
85978525 // generic poison should not result in a failed compilation, but the
85988526 // generic poison type. This prevents unnecessary failures when
......@@ -8609,8 +8537,8 @@ fn zirVectorElemType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr
86098537fn zirVectorType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
86108538 const mod = sema.mod;
86118539 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
8612 const len_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
8613 const elem_type_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };
8540 const len_src = block.builtinCallArgSrc(inst_data.src_node, 0);
8541 const elem_type_src = block.builtinCallArgSrc(inst_data.src_node, 1);
86148542 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
86158543 const len: u32 = @intCast(try sema.resolveInt(block, len_src, extra.lhs, Type.u32, .{
86168544 .needed_comptime_reason = "vector length must be comptime-known",
......@@ -8630,8 +8558,8 @@ fn zirArrayType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
86308558
86318559 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
86328560 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
8633 const len_src: LazySrcLoc = .{ .node_offset_array_type_len = inst_data.src_node };
8634 const elem_src: LazySrcLoc = .{ .node_offset_array_type_elem = inst_data.src_node };
8561 const len_src = block.src(.{ .node_offset_array_type_len = inst_data.src_node });
8562 const elem_src = block.src(.{ .node_offset_array_type_elem = inst_data.src_node });
86358563 const len = try sema.resolveInt(block, len_src, extra.lhs, Type.usize, .{
86368564 .needed_comptime_reason = "array length must be comptime-known",
86378565 });
......@@ -8651,9 +8579,9 @@ fn zirArrayTypeSentinel(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compil
86518579
86528580 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
86538581 const extra = sema.code.extraData(Zir.Inst.ArrayTypeSentinel, inst_data.payload_index).data;
8654 const len_src: LazySrcLoc = .{ .node_offset_array_type_len = inst_data.src_node };
8655 const sentinel_src: LazySrcLoc = .{ .node_offset_array_type_sentinel = inst_data.src_node };
8656 const elem_src: LazySrcLoc = .{ .node_offset_array_type_elem = inst_data.src_node };
8582 const len_src = block.src(.{ .node_offset_array_type_len = inst_data.src_node });
8583 const sentinel_src = block.src(.{ .node_offset_array_type_sentinel = inst_data.src_node });
8584 const elem_src = block.src(.{ .node_offset_array_type_elem = inst_data.src_node });
86578585 const len = try sema.resolveInt(block, len_src, extra.len, Type.usize, .{
86588586 .needed_comptime_reason = "array length must be comptime-known",
86598587 });
......@@ -8691,7 +8619,7 @@ fn zirAnyframeType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
86918619 return sema.failWithUseOfAsync(block, block.nodeOffset(inst_data.src_node));
86928620 }
86938621 const mod = sema.mod;
8694 const operand_src: LazySrcLoc = .{ .node_offset_anyframe_type = inst_data.src_node };
8622 const operand_src = block.src(.{ .node_offset_anyframe_type = inst_data.src_node });
86958623 const return_type = try sema.resolveType(block, operand_src, inst_data.operand);
86968624 const anyframe_type = try mod.anyframeType(return_type);
86978625
......@@ -8705,8 +8633,8 @@ fn zirErrorUnionType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr
87058633 const mod = sema.mod;
87068634 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
87078635 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
8708 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };
8709 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };
8636 const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node });
8637 const rhs_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node });
87108638 const error_set = try sema.resolveType(block, lhs_src, extra.lhs);
87118639 const payload = try sema.resolveType(block, rhs_src, extra.rhs);
87128640
......@@ -8758,8 +8686,8 @@ fn zirIntFromError(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstD
87588686 const mod = sema.mod;
87598687 const ip = &mod.intern_pool;
87608688 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;
8761 const src = LazySrcLoc.nodeOffset(extra.node);
8762 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node };
8689 const src = block.nodeOffset(extra.node);
8690 const operand_src = block.builtinCallArgSrc(extra.node, 0);
87638691 const uncasted_operand = try sema.resolveInst(extra.operand);
87648692 const operand = try sema.coerce(block, Type.anyerror, uncasted_operand, operand_src);
87658693 const err_int_ty = try mod.errorIntType();
......@@ -8801,8 +8729,8 @@ fn zirErrorFromInt(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstD
88018729
88028730 const mod = sema.mod;
88038731 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;
8804 const src = LazySrcLoc.nodeOffset(extra.node);
8805 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node };
8732 const src = block.nodeOffset(extra.node);
8733 const operand_src = block.builtinCallArgSrc(extra.node, 0);
88068734 const uncasted_operand = try sema.resolveInst(extra.operand);
88078735 const err_int_ty = try mod.errorIntType();
88088736 const operand = try sema.coerce(block, err_int_ty, uncasted_operand, operand_src);
......@@ -8841,16 +8769,16 @@ fn zirMergeErrorSets(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr
88418769 const ip = &mod.intern_pool;
88428770 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
88438771 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
8844 const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node };
8845 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };
8846 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };
8772 const src = block.src(.{ .node_offset_bin_op = inst_data.src_node });
8773 const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node });
8774 const rhs_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node });
88478775 const lhs = try sema.resolveInst(extra.lhs);
88488776 const rhs = try sema.resolveInst(extra.rhs);
88498777 if (sema.typeOf(lhs).zigTypeTag(mod) == .Bool and sema.typeOf(rhs).zigTypeTag(mod) == .Bool) {
88508778 const msg = msg: {
8851 const msg = try sema.errMsg(block, lhs_src, "expected error set type, found 'bool'", .{});
8779 const msg = try sema.errMsg(lhs_src, "expected error set type, found 'bool'", .{});
88528780 errdefer msg.destroy(sema.gpa);
8853 try sema.errNote(block, src, msg, "'||' merges error sets; 'or' performs boolean OR", .{});
8781 try sema.errNote(src, msg, "'||' merges error sets; 'or' performs boolean OR", .{});
88548782 break :msg msg;
88558783 };
88568784 return sema.failWithOwnedErrorMsg(block, msg);
......@@ -8905,7 +8833,7 @@ fn zirIntFromEnum(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
89058833 const mod = sema.mod;
89068834 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
89078835 const src = block.nodeOffset(inst_data.src_node);
8908 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
8836 const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0);
89098837 const operand = try sema.resolveInst(inst_data.operand);
89108838 const operand_ty = sema.typeOf(operand);
89118839
......@@ -8963,7 +8891,7 @@ fn zirEnumFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
89638891 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
89648892 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
89658893 const src = block.nodeOffset(inst_data.src_node);
8966 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
8894 const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0);
89678895 const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu_opt, "@enumFromInt");
89688896 const operand = try sema.resolveInst(extra.rhs);
89698897
......@@ -9379,7 +9307,7 @@ fn zirFunc(
93799307 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
93809308 const extra = sema.code.extraData(Zir.Inst.Func, inst_data.payload_index);
93819309 const target = sema.mod.getTarget();
9382 const ret_ty_src: LazySrcLoc = .{ .node_offset_fn_type_ret_ty = inst_data.src_node };
9310 const ret_ty_src = block.src(.{ .node_offset_fn_type_ret_ty = inst_data.src_node });
93839311
93849312 var extra_index = extra.end;
93859313
......@@ -9460,18 +9388,15 @@ fn resolveGenericBody(
94609388 const prev_no_partial_func_type = sema.no_partial_func_ty;
94619389 const prev_generic_owner = sema.generic_owner;
94629390 const prev_generic_call_src = sema.generic_call_src;
9463 const prev_generic_call_decl = sema.generic_call_decl;
94649391 block.params = .{};
94659392 sema.no_partial_func_ty = true;
94669393 sema.generic_owner = .none;
9467 sema.generic_call_src = .unneeded;
9468 sema.generic_call_decl = .none;
9394 sema.generic_call_src = LazySrcLoc.unneeded;
94699395 defer {
94709396 block.params = prev_params;
94719397 sema.no_partial_func_ty = prev_no_partial_func_type;
94729398 sema.generic_owner = prev_generic_owner;
94739399 sema.generic_call_src = prev_generic_call_src;
9474 sema.generic_call_decl = prev_generic_call_decl;
94759400 }
94769401
94779402 const uncasted = sema.resolveInlineBody(block, body, func_inst) catch |err| break :err err;
......@@ -9581,9 +9506,9 @@ fn checkCallConvSupportsVarArgs(sema: *Sema, block: *Block, src: LazySrcLoc, cc:
95819506
95829507 if (!callConvSupportsVarArgs(cc)) {
95839508 const msg = msg: {
9584 const msg = try sema.errMsg(block, src, "variadic function does not support '.{s}' calling convention", .{@tagName(cc)});
9509 const msg = try sema.errMsg(src, "variadic function does not support '.{s}' calling convention", .{@tagName(cc)});
95859510 errdefer msg.destroy(sema.gpa);
9586 try sema.errNote(block, src, msg, "supported calling conventions: {}", .{CallingConventionsSupportingVarArgsList{}});
9511 try sema.errNote(src, msg, "supported calling conventions: {}", .{CallingConventionsSupportingVarArgsList{}});
95879512 break :msg msg;
95889513 };
95899514 return sema.failWithOwnedErrorMsg(block, msg);
......@@ -9623,9 +9548,9 @@ fn funcCommon(
96239548 const gpa = sema.gpa;
96249549 const target = mod.getTarget();
96259550 const ip = &mod.intern_pool;
9626 const ret_ty_src: LazySrcLoc = .{ .node_offset_fn_type_ret_ty = src_node_offset };
9627 const cc_src: LazySrcLoc = .{ .node_offset_fn_type_cc = src_node_offset };
9628 const func_src = LazySrcLoc.nodeOffset(src_node_offset);
9551 const ret_ty_src = block.src(.{ .node_offset_fn_type_ret_ty = src_node_offset });
9552 const cc_src = block.src(.{ .node_offset_fn_type_cc = src_node_offset });
9553 const func_src = block.nodeOffset(src_node_offset);
96299554
96309555 var is_generic = bare_return_type.isGenericPoison() or
96319556 alignment == null or
......@@ -9654,11 +9579,10 @@ fn funcCommon(
96549579 const index = std.math.cast(u5, i) orelse break :blk false;
96559580 break :blk @as(u1, @truncate(noalias_bits >> index)) != 0;
96569581 };
9657 const param_src: LazySrcLoc = .{ .fn_proto_param = .{
9658 .decl = block.src_decl,
9582 const param_src = block.src(.{ .fn_proto_param = .{
96599583 .fn_proto_node_offset = src_node_offset,
96609584 .param_index = @intCast(i),
9661 } };
9585 } });
96629586 const requires_comptime = try sema.typeRequiresComptime(param_ty);
96639587 if (param_is_comptime or requires_comptime) {
96649588 comptime_bits |= @as(u32, 1) << @intCast(i); // TODO: handle cast error
......@@ -9679,13 +9603,12 @@ fn funcCommon(
96799603 }
96809604 if (!this_generic and !target_util.fnCallConvAllowsZigTypes(target, cc_resolved) and !try sema.validateExternType(param_ty, .param_ty)) {
96819605 const msg = msg: {
9682 const msg = try sema.errMsg(block, param_src, "parameter of type '{}' not allowed in function with calling convention '{s}'", .{
9606 const msg = try sema.errMsg(param_src, "parameter of type '{}' not allowed in function with calling convention '{s}'", .{
96839607 param_ty.fmt(mod), @tagName(cc_resolved),
96849608 });
96859609 errdefer msg.destroy(sema.gpa);
96869610
9687 const src_decl = mod.declPtr(block.src_decl);
9688 try sema.explainWhyTypeIsNotExtern(msg, src_decl.toSrcLoc(param_src, mod), param_ty, .param_ty);
9611 try sema.explainWhyTypeIsNotExtern(msg, param_src, param_ty, .param_ty);
96899612
96909613 try sema.addDeclaredHereNote(msg, param_ty);
96919614 break :msg msg;
......@@ -9694,13 +9617,12 @@ fn funcCommon(
96949617 }
96959618 if (is_source_decl and requires_comptime and !param_is_comptime and has_body and !block.is_comptime) {
96969619 const msg = msg: {
9697 const msg = try sema.errMsg(block, param_src, "parameter of type '{}' must be declared comptime", .{
9620 const msg = try sema.errMsg(param_src, "parameter of type '{}' must be declared comptime", .{
96989621 param_ty.fmt(mod),
96999622 });
97009623 errdefer msg.destroy(sema.gpa);
97019624
9702 const src_decl = mod.declPtr(block.src_decl);
9703 try sema.explainWhyTypeIsComptime(msg, src_decl.toSrcLoc(param_src, mod), param_ty);
9625 try sema.explainWhyTypeIsComptime(msg, param_src, param_ty);
97049626
97059627 try sema.addDeclaredHereNote(msg, param_ty);
97069628 break :msg msg;
......@@ -9861,9 +9783,9 @@ fn funcCommon(
98619783 assert(section != .generic);
98629784 assert(address_space != null);
98639785 assert(!is_generic);
9864 if (opt_lib_name) |lib_name| try sema.handleExternLibName(block, .{
9786 if (opt_lib_name) |lib_name| try sema.handleExternLibName(block, block.src(.{
98659787 .node_offset_lib_name = src_node_offset,
9866 }, lib_name);
9788 }), lib_name);
98679789 const func_index = try ip.getExternFunc(gpa, .{
98689790 .ty = func_ty,
98699791 .decl = sema.owner_decl_index,
......@@ -9975,13 +9897,12 @@ fn finishFunc(
99759897 !try sema.validateExternType(return_type, .ret_ty))
99769898 {
99779899 const msg = msg: {
9978 const msg = try sema.errMsg(block, ret_ty_src, "return type '{}' not allowed in function with calling convention '{s}'", .{
9900 const msg = try sema.errMsg(ret_ty_src, "return type '{}' not allowed in function with calling convention '{s}'", .{
99799901 return_type.fmt(mod), @tagName(cc_resolved),
99809902 });
99819903 errdefer msg.destroy(gpa);
99829904
9983 const src_decl = mod.declPtr(block.src_decl);
9984 try sema.explainWhyTypeIsNotExtern(msg, src_decl.toSrcLoc(ret_ty_src, mod), return_type, .ret_ty);
9905 try sema.explainWhyTypeIsNotExtern(msg, ret_ty_src, return_type, .ret_ty);
99859906
99869907 try sema.addDeclaredHereNote(msg, return_type);
99879908 break :msg msg;
......@@ -9997,12 +9918,11 @@ fn finishFunc(
99979918 } else break :comptime_check;
99989919
99999920 const msg = try sema.errMsg(
10000 block,
100019921 ret_ty_src,
100029922 "function with comptime-only return type '{}' requires all parameters to be comptime",
100039923 .{return_type.fmt(mod)},
100049924 );
10005 try sema.explainWhyTypeIsComptime(msg, sema.owner_decl.toSrcLoc(ret_ty_src, mod), return_type);
9925 try sema.explainWhyTypeIsComptime(msg, ret_ty_src, return_type);
100069926
100079927 const tags = sema.code.instructions.items(.tag);
100089928 const data = sema.code.instructions.items(.data);
......@@ -10020,9 +9940,9 @@ fn finishFunc(
100209940 });
100219941 const name = sema.code.nullTerminatedString(name_nts);
100229942 if (name.len != 0) {
10023 try sema.errNote(block, param_src, msg, "param '{s}' is required to be comptime", .{name});
9943 try sema.errNote(param_src, msg, "param '{s}' is required to be comptime", .{name});
100249944 } else {
10025 try sema.errNote(block, param_src, msg, "param is required to be comptime", .{});
9945 try sema.errNote(param_src, msg, "param is required to be comptime", .{});
100269946 }
100279947 }
100289948 }
......@@ -10112,18 +10032,15 @@ fn zirParam(
1011210032 const prev_no_partial_func_type = sema.no_partial_func_ty;
1011310033 const prev_generic_owner = sema.generic_owner;
1011410034 const prev_generic_call_src = sema.generic_call_src;
10115 const prev_generic_call_decl = sema.generic_call_decl;
1011610035 block.params = .{};
1011710036 sema.no_partial_func_ty = true;
1011810037 sema.generic_owner = .none;
10119 sema.generic_call_src = .unneeded;
10120 sema.generic_call_decl = .none;
10038 sema.generic_call_src = LazySrcLoc.unneeded;
1012110039 defer {
1012210040 block.params = prev_params;
1012310041 sema.no_partial_func_ty = prev_no_partial_func_type;
1012410042 sema.generic_owner = prev_generic_owner;
1012510043 sema.generic_call_src = prev_generic_call_src;
10126 sema.generic_call_decl = prev_generic_call_decl;
1012710044 }
1012810045
1012910046 if (sema.resolveInlineBody(block, body, inst)) |param_ty_inst| {
......@@ -10265,7 +10182,7 @@ fn zirIntFromPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
1026510182
1026610183 const zcu = sema.mod;
1026710184 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
10268 const ptr_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
10185 const ptr_src = block.builtinCallArgSrc(inst_data.src_node, 0);
1026910186 const operand = try sema.resolveInst(inst_data.operand);
1027010187 const operand_ty = sema.typeOf(operand);
1027110188 const ptr_ty = operand_ty.scalarType(zcu);
......@@ -10276,10 +10193,9 @@ fn zirIntFromPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
1027610193 const pointee_ty = ptr_ty.childType(zcu);
1027710194 if (try sema.typeRequiresComptime(ptr_ty)) {
1027810195 const msg = msg: {
10279 const msg = try sema.errMsg(block, ptr_src, "comptime-only type '{}' has no pointer address", .{pointee_ty.fmt(zcu)});
10196 const msg = try sema.errMsg(ptr_src, "comptime-only type '{}' has no pointer address", .{pointee_ty.fmt(zcu)});
1028010197 errdefer msg.destroy(sema.gpa);
10281 const src_decl = zcu.declPtr(block.src_decl);
10282 try sema.explainWhyTypeIsComptime(msg, src_decl.toSrcLoc(ptr_src, zcu), pointee_ty);
10198 try sema.explainWhyTypeIsComptime(msg, ptr_src, pointee_ty);
1028310199 break :msg msg;
1028410200 };
1028510201 return sema.failWithOwnedErrorMsg(block, msg);
......@@ -10340,7 +10256,7 @@ fn zirFieldVal(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1034010256 const mod = sema.mod;
1034110257 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
1034210258 const src = block.nodeOffset(inst_data.src_node);
10343 const field_name_src: LazySrcLoc = .{ .node_offset_field_name = inst_data.src_node };
10259 const field_name_src = block.src(.{ .node_offset_field_name = inst_data.src_node });
1034410260 const extra = sema.code.extraData(Zir.Inst.Field, inst_data.payload_index).data;
1034510261 const field_name = try mod.intern_pool.getOrPutString(
1034610262 sema.gpa,
......@@ -10358,7 +10274,7 @@ fn zirFieldPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1035810274 const mod = sema.mod;
1035910275 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
1036010276 const src = block.nodeOffset(inst_data.src_node);
10361 const field_name_src: LazySrcLoc = .{ .node_offset_field_name = inst_data.src_node };
10277 const field_name_src = block.src(.{ .node_offset_field_name = inst_data.src_node });
1036210278 const extra = sema.code.extraData(Zir.Inst.Field, inst_data.payload_index).data;
1036310279 const field_name = try mod.intern_pool.getOrPutString(
1036410280 sema.gpa,
......@@ -10376,7 +10292,7 @@ fn zirStructInitFieldPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compi
1037610292 const mod = sema.mod;
1037710293 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
1037810294 const src = block.nodeOffset(inst_data.src_node);
10379 const field_name_src: LazySrcLoc = .{ .node_offset_field_name_init = inst_data.src_node };
10295 const field_name_src = block.src(.{ .node_offset_field_name_init = inst_data.src_node });
1038010296 const extra = sema.code.extraData(Zir.Inst.Field, inst_data.payload_index).data;
1038110297 const field_name = try mod.intern_pool.getOrPutString(
1038210298 sema.gpa,
......@@ -10401,7 +10317,7 @@ fn zirFieldValNamed(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr
1040110317
1040210318 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
1040310319 const src = block.nodeOffset(inst_data.src_node);
10404 const field_name_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };
10320 const field_name_src = block.builtinCallArgSrc(inst_data.src_node, 1);
1040510321 const extra = sema.code.extraData(Zir.Inst.FieldNamed, inst_data.payload_index).data;
1040610322 const object = try sema.resolveInst(extra.lhs);
1040710323 const field_name = try sema.resolveConstStringIntern(block, field_name_src, extra.field_name, .{
......@@ -10416,7 +10332,7 @@ fn zirFieldPtrNamed(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr
1041610332
1041710333 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
1041810334 const src = block.nodeOffset(inst_data.src_node);
10419 const field_name_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };
10335 const field_name_src = block.builtinCallArgSrc(inst_data.src_node, 1);
1042010336 const extra = sema.code.extraData(Zir.Inst.FieldNamed, inst_data.payload_index).data;
1042110337 const object_ptr = try sema.resolveInst(extra.lhs);
1042210338 const field_name = try sema.resolveConstStringIntern(block, field_name_src, extra.field_name, .{
......@@ -10431,7 +10347,7 @@ fn zirIntCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1043110347
1043210348 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
1043310349 const src = block.nodeOffset(inst_data.src_node);
10434 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
10350 const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0);
1043510351 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
1043610352
1043710353 const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu_opt, "@intCast");
......@@ -10601,7 +10517,7 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1060110517 const mod = sema.mod;
1060210518 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
1060310519 const src = block.nodeOffset(inst_data.src_node);
10604 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
10520 const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0);
1060510521 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
1060610522
1060710523 const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu_opt, "@bitCast");
......@@ -10627,10 +10543,10 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1062710543
1062810544 .Enum => {
1062910545 const msg = msg: {
10630 const msg = try sema.errMsg(block, src, "cannot @bitCast to '{}'", .{dest_ty.fmt(mod)});
10546 const msg = try sema.errMsg(src, "cannot @bitCast to '{}'", .{dest_ty.fmt(mod)});
1063110547 errdefer msg.destroy(sema.gpa);
1063210548 switch (operand_ty.zigTypeTag(mod)) {
10633 .Int, .ComptimeInt => try sema.errNote(block, src, msg, "use @enumFromInt to cast from '{}'", .{operand_ty.fmt(mod)}),
10549 .Int, .ComptimeInt => try sema.errNote(src, msg, "use @enumFromInt to cast from '{}'", .{operand_ty.fmt(mod)}),
1063410550 else => {},
1063510551 }
1063610552
......@@ -10641,11 +10557,11 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1064110557
1064210558 .Pointer => {
1064310559 const msg = msg: {
10644 const msg = try sema.errMsg(block, src, "cannot @bitCast to '{}'", .{dest_ty.fmt(mod)});
10560 const msg = try sema.errMsg(src, "cannot @bitCast to '{}'", .{dest_ty.fmt(mod)});
1064510561 errdefer msg.destroy(sema.gpa);
1064610562 switch (operand_ty.zigTypeTag(mod)) {
10647 .Int, .ComptimeInt => try sema.errNote(block, src, msg, "use @ptrFromInt to cast from '{}'", .{operand_ty.fmt(mod)}),
10648 .Pointer => try sema.errNote(block, src, msg, "use @ptrCast to cast from '{}'", .{operand_ty.fmt(mod)}),
10563 .Int, .ComptimeInt => try sema.errNote(src, msg, "use @ptrFromInt to cast from '{}'", .{operand_ty.fmt(mod)}),
10564 .Pointer => try sema.errNote(src, msg, "use @ptrCast to cast from '{}'", .{operand_ty.fmt(mod)}),
1064910565 else => {},
1065010566 }
1065110567
......@@ -10691,10 +10607,10 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1069110607
1069210608 .Enum => {
1069310609 const msg = msg: {
10694 const msg = try sema.errMsg(block, operand_src, "cannot @bitCast from '{}'", .{operand_ty.fmt(mod)});
10610 const msg = try sema.errMsg(operand_src, "cannot @bitCast from '{}'", .{operand_ty.fmt(mod)});
1069510611 errdefer msg.destroy(sema.gpa);
1069610612 switch (dest_ty.zigTypeTag(mod)) {
10697 .Int, .ComptimeInt => try sema.errNote(block, operand_src, msg, "use @intFromEnum to cast to '{}'", .{dest_ty.fmt(mod)}),
10613 .Int, .ComptimeInt => try sema.errNote(operand_src, msg, "use @intFromEnum to cast to '{}'", .{dest_ty.fmt(mod)}),
1069810614 else => {},
1069910615 }
1070010616
......@@ -10704,11 +10620,11 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1070410620 },
1070510621 .Pointer => {
1070610622 const msg = msg: {
10707 const msg = try sema.errMsg(block, operand_src, "cannot @bitCast from '{}'", .{operand_ty.fmt(mod)});
10623 const msg = try sema.errMsg(operand_src, "cannot @bitCast from '{}'", .{operand_ty.fmt(mod)});
1070810624 errdefer msg.destroy(sema.gpa);
1070910625 switch (dest_ty.zigTypeTag(mod)) {
10710 .Int, .ComptimeInt => try sema.errNote(block, operand_src, msg, "use @intFromPtr to cast to '{}'", .{dest_ty.fmt(mod)}),
10711 .Pointer => try sema.errNote(block, operand_src, msg, "use @ptrCast to cast to '{}'", .{dest_ty.fmt(mod)}),
10626 .Int, .ComptimeInt => try sema.errNote(operand_src, msg, "use @intFromPtr to cast to '{}'", .{dest_ty.fmt(mod)}),
10627 .Pointer => try sema.errNote(operand_src, msg, "use @ptrCast to cast to '{}'", .{dest_ty.fmt(mod)}),
1071210628 else => {},
1071310629 }
1071410630
......@@ -10744,7 +10660,7 @@ fn zirFloatCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
1074410660 const mod = sema.mod;
1074510661 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
1074610662 const src = block.nodeOffset(inst_data.src_node);
10747 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
10663 const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0);
1074810664 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
1074910665
1075010666 const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu_opt, "@floatCast");
......@@ -10835,7 +10751,7 @@ fn zirElemValNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
1083510751
1083610752 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
1083710753 const src = block.nodeOffset(inst_data.src_node);
10838 const elem_index_src: LazySrcLoc = .{ .node_offset_array_access_index = inst_data.src_node };
10754 const elem_index_src = block.src(.{ .node_offset_array_access_index = inst_data.src_node });
1083910755 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
1084010756 const array = try sema.resolveInst(extra.lhs);
1084110757 const uncoerced_elem_index = try sema.resolveInst(extra.rhs);
......@@ -10851,7 +10767,7 @@ fn zirElemValImm(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
1085110767 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].elem_val_imm;
1085210768 const array = try sema.resolveInst(inst_data.operand);
1085310769 const elem_index = try mod.intRef(Type.usize, inst_data.idx);
10854 return sema.elemVal(block, .unneeded, array, elem_index, .unneeded, false);
10770 return sema.elemVal(block, LazySrcLoc.unneeded, array, elem_index, LazySrcLoc.unneeded, false);
1085510771}
1085610772
1085710773fn zirElemPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
......@@ -10866,14 +10782,14 @@ fn zirElemPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1086610782 const elem_index = try sema.resolveInst(extra.rhs);
1086710783 const indexable_ty = sema.typeOf(array_ptr);
1086810784 if (indexable_ty.zigTypeTag(mod) != .Pointer) {
10869 const capture_src: LazySrcLoc = .{ .for_capture_from_input = inst_data.src_node };
10785 const capture_src = block.src(.{ .for_capture_from_input = inst_data.src_node });
1087010786 const msg = msg: {
10871 const msg = try sema.errMsg(block, capture_src, "pointer capture of non pointer type '{}'", .{
10787 const msg = try sema.errMsg(capture_src, "pointer capture of non pointer type '{}'", .{
1087210788 indexable_ty.fmt(mod),
1087310789 });
1087410790 errdefer msg.destroy(sema.gpa);
1087510791 if (indexable_ty.isIndexable(mod)) {
10876 try sema.errNote(block, src, msg, "consider using '&' here", .{});
10792 try sema.errNote(src, msg, "consider using '&' here", .{});
1087710793 }
1087810794 break :msg msg;
1087910795 };
......@@ -10888,7 +10804,7 @@ fn zirElemPtrNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
1088810804
1088910805 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
1089010806 const src = block.nodeOffset(inst_data.src_node);
10891 const elem_index_src: LazySrcLoc = .{ .node_offset_array_access_index = inst_data.src_node };
10807 const elem_index_src = block.src(.{ .node_offset_array_access_index = inst_data.src_node });
1089210808 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
1089310809 const array_ptr = try sema.resolveInst(extra.lhs);
1089410810 const uncoerced_elem_index = try sema.resolveInst(extra.rhs);
......@@ -10925,11 +10841,11 @@ fn zirSliceStart(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
1092510841 const extra = sema.code.extraData(Zir.Inst.SliceStart, inst_data.payload_index).data;
1092610842 const array_ptr = try sema.resolveInst(extra.lhs);
1092710843 const start = try sema.resolveInst(extra.start);
10928 const ptr_src: LazySrcLoc = .{ .node_offset_slice_ptr = inst_data.src_node };
10929 const start_src: LazySrcLoc = .{ .node_offset_slice_start = inst_data.src_node };
10930 const end_src: LazySrcLoc = .{ .node_offset_slice_end = inst_data.src_node };
10844 const ptr_src = block.src(.{ .node_offset_slice_ptr = inst_data.src_node });
10845 const start_src = block.src(.{ .node_offset_slice_start = inst_data.src_node });
10846 const end_src = block.src(.{ .node_offset_slice_end = inst_data.src_node });
1093110847
10932 return sema.analyzeSlice(block, src, array_ptr, start, .none, .none, .unneeded, ptr_src, start_src, end_src, false);
10848 return sema.analyzeSlice(block, src, array_ptr, start, .none, .none, LazySrcLoc.unneeded, ptr_src, start_src, end_src, false);
1093310849}
1093410850
1093510851fn zirSliceEnd(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
......@@ -10942,11 +10858,11 @@ fn zirSliceEnd(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1094210858 const array_ptr = try sema.resolveInst(extra.lhs);
1094310859 const start = try sema.resolveInst(extra.start);
1094410860 const end = try sema.resolveInst(extra.end);
10945 const ptr_src: LazySrcLoc = .{ .node_offset_slice_ptr = inst_data.src_node };
10946 const start_src: LazySrcLoc = .{ .node_offset_slice_start = inst_data.src_node };
10947 const end_src: LazySrcLoc = .{ .node_offset_slice_end = inst_data.src_node };
10861 const ptr_src = block.src(.{ .node_offset_slice_ptr = inst_data.src_node });
10862 const start_src = block.src(.{ .node_offset_slice_start = inst_data.src_node });
10863 const end_src = block.src(.{ .node_offset_slice_end = inst_data.src_node });
1094810864
10949 return sema.analyzeSlice(block, src, array_ptr, start, end, .none, .unneeded, ptr_src, start_src, end_src, false);
10865 return sema.analyzeSlice(block, src, array_ptr, start, end, .none, LazySrcLoc.unneeded, ptr_src, start_src, end_src, false);
1095010866}
1095110867
1095210868fn zirSliceSentinel(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
......@@ -10955,15 +10871,15 @@ fn zirSliceSentinel(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr
1095510871
1095610872 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
1095710873 const src = block.nodeOffset(inst_data.src_node);
10958 const sentinel_src: LazySrcLoc = .{ .node_offset_slice_sentinel = inst_data.src_node };
10874 const sentinel_src = block.src(.{ .node_offset_slice_sentinel = inst_data.src_node });
1095910875 const extra = sema.code.extraData(Zir.Inst.SliceSentinel, inst_data.payload_index).data;
1096010876 const array_ptr = try sema.resolveInst(extra.lhs);
1096110877 const start = try sema.resolveInst(extra.start);
1096210878 const end: Air.Inst.Ref = if (extra.end == .none) .none else try sema.resolveInst(extra.end);
1096310879 const sentinel = try sema.resolveInst(extra.sentinel);
10964 const ptr_src: LazySrcLoc = .{ .node_offset_slice_ptr = inst_data.src_node };
10965 const start_src: LazySrcLoc = .{ .node_offset_slice_start = inst_data.src_node };
10966 const end_src: LazySrcLoc = .{ .node_offset_slice_end = inst_data.src_node };
10880 const ptr_src = block.src(.{ .node_offset_slice_ptr = inst_data.src_node });
10881 const start_src = block.src(.{ .node_offset_slice_start = inst_data.src_node });
10882 const end_src = block.src(.{ .node_offset_slice_end = inst_data.src_node });
1096710883
1096810884 return sema.analyzeSlice(block, src, array_ptr, start, end, sentinel, sentinel_src, ptr_src, start_src, end_src, false);
1096910885}
......@@ -10979,13 +10895,13 @@ fn zirSliceLength(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
1097910895 const start = try sema.resolveInst(extra.start);
1098010896 const len = try sema.resolveInst(extra.len);
1098110897 const sentinel = if (extra.sentinel == .none) .none else try sema.resolveInst(extra.sentinel);
10982 const ptr_src: LazySrcLoc = .{ .node_offset_slice_ptr = inst_data.src_node };
10983 const start_src: LazySrcLoc = .{ .node_offset_slice_start = extra.start_src_node_offset };
10984 const end_src: LazySrcLoc = .{ .node_offset_slice_end = inst_data.src_node };
10898 const ptr_src = block.src(.{ .node_offset_slice_ptr = inst_data.src_node });
10899 const start_src = block.src(.{ .node_offset_slice_start = extra.start_src_node_offset });
10900 const end_src = block.src(.{ .node_offset_slice_end = inst_data.src_node });
1098510901 const sentinel_src: LazySrcLoc = if (sentinel == .none)
10986 .unneeded
10902 LazySrcLoc.unneeded
1098710903 else
10988 .{ .node_offset_slice_sentinel = inst_data.src_node };
10904 block.src(.{ .node_offset_slice_sentinel = inst_data.src_node });
1098910905
1099010906 return sema.analyzeSlice(block, src, array_ptr, start, len, sentinel, sentinel_src, ptr_src, start_src, end_src, true);
1099110907}
......@@ -11019,8 +10935,8 @@ const SwitchProngAnalysis = struct {
1101910935 prong_type: enum { normal, special },
1102010936 prong_body: []const Zir.Inst.Index,
1102110937 capture: Zir.Inst.SwitchBlock.ProngInfo.Capture,
11022 /// Must use the `scalar_capture`, `special_capture`, or `multi_capture` union field.
11023 raw_capture_src: Module.SwitchProngSrc,
10938 /// Must use the `switch_capture` field in `offset`.
10939 capture_src: LazySrcLoc,
1102410940 /// The set of all values which can reach this prong. May be undefined
1102510941 /// if the prong is special or contains ranges.
1102610942 case_vals: []const Air.Inst.Ref,
......@@ -11038,7 +10954,7 @@ const SwitchProngAnalysis = struct {
1103810954 );
1103910955
1104010956 if (has_tag_capture) {
11041 const tag_ref = try spa.analyzeTagCapture(child_block, raw_capture_src, inline_case_capture);
10957 const tag_ref = try spa.analyzeTagCapture(child_block, capture_src, inline_case_capture);
1104210958 sema.inst_map.putAssumeCapacity(spa.tag_capture_inst, tag_ref);
1104310959 }
1104410960 defer if (has_tag_capture) assert(sema.inst_map.remove(spa.tag_capture_inst));
......@@ -11053,7 +10969,7 @@ const SwitchProngAnalysis = struct {
1105310969 child_block,
1105410970 capture == .by_ref,
1105510971 prong_type == .special,
11056 raw_capture_src,
10972 capture_src,
1105710973 case_vals,
1105810974 inline_case_capture,
1105910975 );
......@@ -11079,8 +10995,8 @@ const SwitchProngAnalysis = struct {
1107910995 prong_type: enum { normal, special },
1108010996 prong_body: []const Zir.Inst.Index,
1108110997 capture: Zir.Inst.SwitchBlock.ProngInfo.Capture,
11082 /// Must use the `scalar`, `special`, or `multi_capture` union field.
11083 raw_capture_src: Module.SwitchProngSrc,
10998 /// Must use the `switch_capture` field in `offset`.
10999 capture_src: LazySrcLoc,
1108411000 /// The set of all values which can reach this prong. May be undefined
1108511001 /// if the prong is special or contains ranges.
1108611002 case_vals: []const Air.Inst.Ref,
......@@ -11094,7 +11010,7 @@ const SwitchProngAnalysis = struct {
1109411010 const sema = spa.sema;
1109511011
1109611012 if (has_tag_capture) {
11097 const tag_ref = try spa.analyzeTagCapture(case_block, raw_capture_src, inline_case_capture);
11013 const tag_ref = try spa.analyzeTagCapture(case_block, capture_src, inline_case_capture);
1109811014 sema.inst_map.putAssumeCapacity(spa.tag_capture_inst, tag_ref);
1109911015 }
1110011016 defer if (has_tag_capture) assert(sema.inst_map.remove(spa.tag_capture_inst));
......@@ -11109,7 +11025,7 @@ const SwitchProngAnalysis = struct {
1110911025 case_block,
1111011026 capture == .by_ref,
1111111027 prong_type == .special,
11112 raw_capture_src,
11028 capture_src,
1111311029 case_vals,
1111411030 inline_case_capture,
1111511031 );
......@@ -11130,23 +11046,18 @@ const SwitchProngAnalysis = struct {
1113011046 fn analyzeTagCapture(
1113111047 spa: SwitchProngAnalysis,
1113211048 block: *Block,
11133 raw_capture_src: Module.SwitchProngSrc,
11049 capture_src: LazySrcLoc,
1113411050 inline_case_capture: Air.Inst.Ref,
1113511051 ) CompileError!Air.Inst.Ref {
1113611052 const sema = spa.sema;
1113711053 const mod = sema.mod;
1113811054 const operand_ty = sema.typeOf(spa.operand);
1113911055 if (operand_ty.zigTypeTag(mod) != .Union) {
11140 const zir_datas = sema.code.instructions.items(.data);
11141 const switch_node_offset = zir_datas[@intFromEnum(spa.switch_block_inst)].pl_node.src_node;
11142 const raw_tag_capture_src: Module.SwitchProngSrc = switch (raw_capture_src) {
11143 .scalar_capture => |i| .{ .scalar_tag_capture = i },
11144 .multi_capture => |i| .{ .multi_tag_capture = i },
11145 .special_capture => .special_tag_capture,
11146 else => unreachable,
11056 const tag_capture_src: LazySrcLoc = .{
11057 .base_node_inst = capture_src.base_node_inst,
11058 .offset = .{ .switch_tag_capture = capture_src.offset.switch_capture },
1114711059 };
11148 const capture_src = raw_tag_capture_src.resolve(mod, mod.declPtr(block.src_decl), switch_node_offset, .none);
11149 return sema.fail(block, capture_src, "cannot capture tag of non-union type '{}'", .{
11060 return sema.fail(block, tag_capture_src, "cannot capture tag of non-union type '{}'", .{
1115011061 operand_ty.fmt(mod),
1115111062 });
1115211063 }
......@@ -11159,7 +11070,7 @@ const SwitchProngAnalysis = struct {
1115911070 block: *Block,
1116011071 capture_byref: bool,
1116111072 is_special_prong: bool,
11162 raw_capture_src: Module.SwitchProngSrc,
11073 capture_src: LazySrcLoc,
1116311074 case_vals: []const Air.Inst.Ref,
1116411075 inline_case_capture: Air.Inst.Ref,
1116511076 ) CompileError!Air.Inst.Ref {
......@@ -11172,10 +11083,10 @@ const SwitchProngAnalysis = struct {
1117211083
1117311084 const operand_ty = sema.typeOf(spa.operand);
1117411085 const operand_ptr_ty = if (capture_byref) sema.typeOf(spa.operand_ptr) else undefined;
11175 const operand_src: LazySrcLoc = .{ .node_offset_switch_operand = switch_node_offset };
11086 const operand_src = block.src(.{ .node_offset_switch_operand = switch_node_offset });
1117611087
1117711088 if (inline_case_capture != .none) {
11178 const item_val = sema.resolveConstDefinedValue(block, .unneeded, inline_case_capture, undefined) catch unreachable;
11089 const item_val = sema.resolveConstDefinedValue(block, LazySrcLoc.unneeded, inline_case_capture, undefined) catch unreachable;
1117911090 if (operand_ty.zigTypeTag(zcu) == .Union) {
1118011091 const field_index: u32 = @intCast(operand_ty.unionTagFieldIndex(item_val, zcu).?);
1118111092 const union_obj = zcu.typeToUnion(operand_ty).?;
......@@ -11216,7 +11127,7 @@ const SwitchProngAnalysis = struct {
1121611127 .ErrorSet => if (spa.else_error_ty) |ty| {
1121711128 return sema.bitCast(block, ty, spa.operand, operand_src, null);
1121811129 } else {
11219 try block.addUnreachable(operand_src, false);
11130 try sema.analyzeUnreachable(block, operand_src, false);
1122011131 return .unreachable_value;
1122111132 },
1122211133 else => return spa.operand,
......@@ -11226,14 +11137,14 @@ const SwitchProngAnalysis = struct {
1122611137 switch (operand_ty.zigTypeTag(zcu)) {
1122711138 .Union => {
1122811139 const union_obj = zcu.typeToUnion(operand_ty).?;
11229 const first_item_val = sema.resolveConstDefinedValue(block, .unneeded, case_vals[0], undefined) catch unreachable;
11140 const first_item_val = sema.resolveConstDefinedValue(block, LazySrcLoc.unneeded, case_vals[0], undefined) catch unreachable;
1123011141
1123111142 const first_field_index: u32 = zcu.unionTagFieldIndex(union_obj, first_item_val).?;
1123211143 const first_field_ty = Type.fromInterned(union_obj.field_types.get(ip)[first_field_index]);
1123311144
1123411145 const field_indices = try sema.arena.alloc(u32, case_vals.len);
1123511146 for (case_vals, field_indices) |item, *field_idx| {
11236 const item_val = sema.resolveConstDefinedValue(block, .unneeded, item, undefined) catch unreachable;
11147 const item_val = sema.resolveConstDefinedValue(block, LazySrcLoc.unneeded, item, undefined) catch unreachable;
1123711148 field_idx.* = zcu.unionTagFieldIndex(union_obj, item_val).?;
1123811149 }
1123911150
......@@ -11253,27 +11164,22 @@ const SwitchProngAnalysis = struct {
1125311164 }
1125411165
1125511166 const case_srcs = try sema.arena.alloc(?LazySrcLoc, case_vals.len);
11256 @memset(case_srcs, .unneeded);
11257
11258 break :capture_ty sema.resolvePeerTypes(block, .unneeded, dummy_captures, .{ .override = case_srcs }) catch |err| switch (err) {
11259 error.NeededSourceLocation => {
11260 // This must be a multi-prong so this must be a `multi_capture` src
11261 const multi_idx = raw_capture_src.multi_capture;
11262 const src_decl_ptr = zcu.declPtr(block.src_decl);
11263 for (case_srcs, 0..) |*case_src, i| {
11264 const raw_case_src: Module.SwitchProngSrc = .{ .multi = .{ .prong = multi_idx, .item = @intCast(i) } };
11265 case_src.* = raw_case_src.resolve(zcu, src_decl_ptr, switch_node_offset, .none);
11266 }
11267 const capture_src = raw_capture_src.resolve(zcu, src_decl_ptr, switch_node_offset, .none);
11268 _ = sema.resolvePeerTypes(block, capture_src, dummy_captures, .{ .override = case_srcs }) catch |err1| switch (err1) {
11269 error.AnalysisFail => {
11270 const msg = sema.err orelse return error.AnalysisFail;
11271 try sema.reparentOwnedErrorMsg(block, capture_src, msg, "capture group with incompatible types", .{});
11272 return error.AnalysisFail;
11273 },
11274 else => |e| return e,
11275 };
11276 unreachable;
11167 for (case_srcs, 0..) |*case_src, i| {
11168 case_src.* = .{
11169 .base_node_inst = capture_src.base_node_inst,
11170 .offset = .{ .switch_case_item = .{
11171 .switch_node_offset = switch_node_offset,
11172 .case_idx = capture_src.offset.switch_capture.case_idx,
11173 .item_idx = .{ .kind = .single, .index = @intCast(i) },
11174 } },
11175 };
11176 }
11177
11178 break :capture_ty sema.resolvePeerTypes(block, capture_src, dummy_captures, .{ .override = case_srcs }) catch |err| switch (err) {
11179 error.AnalysisFail => {
11180 const msg = sema.err orelse return error.AnalysisFail;
11181 try sema.reparentOwnedErrorMsg(capture_src, msg, "capture group with incompatible types", .{});
11182 return error.AnalysisFail;
1127711183 },
1127811184 else => |e| return e,
1127911185 };
......@@ -11301,28 +11207,23 @@ const SwitchProngAnalysis = struct {
1130111207 dummy.* = try zcu.undefRef(field_ptr_ty);
1130211208 }
1130311209 const case_srcs = try sema.arena.alloc(?LazySrcLoc, case_vals.len);
11304 @memset(case_srcs, .unneeded);
11305
11306 break :resolve sema.resolvePeerTypes(block, .unneeded, dummy_captures, .{ .override = case_srcs }) catch |err| switch (err) {
11307 error.NeededSourceLocation => {
11308 // This must be a multi-prong so this must be a `multi_capture` src
11309 const multi_idx = raw_capture_src.multi_capture;
11310 const src_decl_ptr = zcu.declPtr(block.src_decl);
11311 for (case_srcs, 0..) |*case_src, i| {
11312 const raw_case_src: Module.SwitchProngSrc = .{ .multi = .{ .prong = multi_idx, .item = @intCast(i) } };
11313 case_src.* = raw_case_src.resolve(zcu, src_decl_ptr, switch_node_offset, .none);
11314 }
11315 const capture_src = raw_capture_src.resolve(zcu, src_decl_ptr, switch_node_offset, .none);
11316 _ = sema.resolvePeerTypes(block, capture_src, dummy_captures, .{ .override = case_srcs }) catch |err1| switch (err1) {
11317 error.AnalysisFail => {
11318 const msg = sema.err orelse return error.AnalysisFail;
11319 try sema.errNote(block, capture_src, msg, "this coercion is only possible when capturing by value", .{});
11320 try sema.reparentOwnedErrorMsg(block, capture_src, msg, "capture group with incompatible types", .{});
11321 return error.AnalysisFail;
11322 },
11323 else => |e| return e,
11324 };
11325 unreachable;
11210 for (case_srcs, 0..) |*case_src, i| {
11211 case_src.* = .{
11212 .base_node_inst = capture_src.base_node_inst,
11213 .offset = .{ .switch_case_item = .{
11214 .switch_node_offset = switch_node_offset,
11215 .case_idx = capture_src.offset.switch_capture.case_idx,
11216 .item_idx = .{ .kind = .single, .index = @intCast(i) },
11217 } },
11218 };
11219 }
11220
11221 break :resolve sema.resolvePeerTypes(block, capture_src, dummy_captures, .{ .override = case_srcs }) catch |err| switch (err) {
11222 error.AnalysisFail => {
11223 const msg = sema.err orelse return error.AnalysisFail;
11224 try sema.errNote(capture_src, msg, "this coercion is only possible when capturing by value", .{});
11225 try sema.reparentOwnedErrorMsg(capture_src, msg, "capture group with incompatible types", .{});
11226 return error.AnalysisFail;
1132611227 },
1132711228 else => |e| return e,
1132811229 };
......@@ -11357,7 +11258,7 @@ const SwitchProngAnalysis = struct {
1135711258 const first_non_imc = in_mem: {
1135811259 for (field_indices, 0..) |field_idx, i| {
1135911260 const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[field_idx]);
11360 if (.ok != try sema.coerceInMemoryAllowed(block, capture_ty, field_ty, false, zcu.getTarget(), .unneeded, .unneeded)) {
11261 if (.ok != try sema.coerceInMemoryAllowed(block, capture_ty, field_ty, false, zcu.getTarget(), LazySrcLoc.unneeded, LazySrcLoc.unneeded)) {
1136111262 break :in_mem i;
1136211263 }
1136311264 }
......@@ -11380,7 +11281,7 @@ const SwitchProngAnalysis = struct {
1138011281 const next = first_non_imc + 1;
1138111282 for (field_indices[next..], next..) |field_idx, i| {
1138211283 const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[field_idx]);
11383 if (.ok != try sema.coerceInMemoryAllowed(block, capture_ty, field_ty, false, zcu.getTarget(), .unneeded, .unneeded)) {
11284 if (.ok != try sema.coerceInMemoryAllowed(block, capture_ty, field_ty, false, zcu.getTarget(), LazySrcLoc.unneeded, LazySrcLoc.unneeded)) {
1138411285 in_mem_coercible.unset(i);
1138511286 }
1138611287 }
......@@ -11409,20 +11310,19 @@ const SwitchProngAnalysis = struct {
1140911310 var coerce_block = block.makeSubBlock();
1141011311 defer coerce_block.instructions.deinit(sema.gpa);
1141111312
11313 const case_src: LazySrcLoc = .{
11314 .base_node_inst = capture_src.base_node_inst,
11315 .offset = .{ .switch_case_item = .{
11316 .switch_node_offset = switch_node_offset,
11317 .case_idx = capture_src.offset.switch_capture.case_idx,
11318 .item_idx = .{ .kind = .single, .index = @intCast(idx) },
11319 } },
11320 };
11321
1141211322 const field_idx = field_indices[idx];
1141311323 const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[field_idx]);
1141411324 const uncoerced = try coerce_block.addStructFieldVal(spa.operand, field_idx, field_ty);
11415 const coerced = sema.coerce(&coerce_block, capture_ty, uncoerced, .unneeded) catch |err| switch (err) {
11416 error.NeededSourceLocation => {
11417 const multi_idx = raw_capture_src.multi_capture;
11418 const src_decl_ptr = zcu.declPtr(block.src_decl);
11419 const raw_case_src: Module.SwitchProngSrc = .{ .multi = .{ .prong = multi_idx, .item = @intCast(idx) } };
11420 const case_src = raw_case_src.resolve(zcu, src_decl_ptr, switch_node_offset, .none);
11421 _ = try sema.coerce(&coerce_block, capture_ty, uncoerced, case_src);
11422 unreachable;
11423 },
11424 else => |e| return e,
11425 };
11325 const coerced = try sema.coerce(&coerce_block, capture_ty, uncoerced, case_src);
1142611326 _ = try coerce_block.addBr(capture_block_inst, coerced);
1142711327
1142811328 try cases_extra.ensureUnusedCapacity(3 + coerce_block.instructions.items.len);
......@@ -11476,7 +11376,6 @@ const SwitchProngAnalysis = struct {
1147611376 },
1147711377 .ErrorSet => {
1147811378 if (capture_byref) {
11479 const capture_src = raw_capture_src.resolve(zcu, zcu.declPtr(block.src_decl), switch_node_offset, .none);
1148011379 return sema.fail(
1148111380 block,
1148211381 capture_src,
......@@ -11486,7 +11385,7 @@ const SwitchProngAnalysis = struct {
1148611385 }
1148711386
1148811387 if (case_vals.len == 1) {
11489 const item_val = sema.resolveConstDefinedValue(block, .unneeded, case_vals[0], undefined) catch unreachable;
11388 const item_val = sema.resolveConstDefinedValue(block, LazySrcLoc.unneeded, case_vals[0], undefined) catch unreachable;
1149011389 const item_ty = try zcu.singleErrorSetType(item_val.getErrorName(zcu).unwrap().?);
1149111390 return sema.bitCast(block, item_ty, spa.operand, operand_src, null);
1149211391 }
......@@ -11494,7 +11393,7 @@ const SwitchProngAnalysis = struct {
1149411393 var names: InferredErrorSet.NameMap = .{};
1149511394 try names.ensureUnusedCapacity(sema.arena, case_vals.len);
1149611395 for (case_vals) |err| {
11497 const err_val = sema.resolveConstDefinedValue(block, .unneeded, err, undefined) catch unreachable;
11396 const err_val = sema.resolveConstDefinedValue(block, LazySrcLoc.unneeded, err, undefined) catch unreachable;
1149811397 names.putAssumeCapacityNoClobber(err_val.getErrorName(zcu).unwrap().?, {});
1149911398 }
1150011399 const error_ty = try zcu.errorSetFromUnsortedNames(names.keys());
......@@ -11548,10 +11447,10 @@ fn switchCond(
1154811447 try sema.resolveTypeFields(operand_ty);
1154911448 const enum_ty = operand_ty.unionTagType(mod) orelse {
1155011449 const msg = msg: {
11551 const msg = try sema.errMsg(block, src, "switch on union with no attached enum", .{});
11450 const msg = try sema.errMsg(src, "switch on union with no attached enum", .{});
1155211451 errdefer msg.destroy(sema.gpa);
11553 if (operand_ty.declSrcLocOrNull(mod)) |union_src| {
11554 try mod.errNoteNonLazy(union_src, msg, "consider 'union(enum)' here", .{});
11452 if (operand_ty.srcLocOrNull(mod)) |union_src| {
11453 try sema.errNote(union_src, msg, "consider 'union(enum)' here", .{});
1155511454 }
1155611455 break :msg msg;
1155711456 };
......@@ -11575,7 +11474,7 @@ fn switchCond(
1157511474 }
1157611475}
1157711476
11578const SwitchErrorSet = std.AutoHashMap(InternPool.NullTerminatedString, Module.SwitchProngSrc);
11477const SwitchErrorSet = std.AutoHashMap(InternPool.NullTerminatedString, LazySrcLoc);
1157911478
1158011479fn zirSwitchBlockErrUnion(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
1158111480 const tracy = trace(@src());
......@@ -11586,11 +11485,11 @@ fn zirSwitchBlockErrUnion(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp
1158611485 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
1158711486 const switch_src = block.nodeOffset(inst_data.src_node);
1158811487 const switch_src_node_offset = inst_data.src_node;
11589 const switch_operand_src: LazySrcLoc = .{ .node_offset_switch_operand = switch_src_node_offset };
11590 const else_prong_src: LazySrcLoc = .{ .node_offset_switch_special_prong = switch_src_node_offset };
11488 const switch_operand_src = block.src(.{ .node_offset_switch_operand = switch_src_node_offset });
11489 const else_prong_src = block.src(.{ .node_offset_switch_special_prong = switch_src_node_offset });
1159111490 const extra = sema.code.extraData(Zir.Inst.SwitchBlockErrUnion, inst_data.payload_index);
11592 const main_operand_src: LazySrcLoc = .{ .node_offset_if_cond = extra.data.main_src_node_offset };
11593 const main_src: LazySrcLoc = .{ .node_offset_main_token = extra.data.main_src_node_offset };
11491 const main_operand_src = block.src(.{ .node_offset_if_cond = extra.data.main_src_node_offset });
11492 const main_src = block.src(.{ .node_offset_main_token = extra.data.main_src_node_offset });
1159411493
1159511494 const raw_operand_val = try sema.resolveInst(extra.data.operand);
1159611495
......@@ -11710,6 +11609,7 @@ fn zirSwitchBlockErrUnion(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp
1171011609 .runtime_index = block.runtime_index,
1171111610 .error_return_trace_index = block.error_return_trace_index,
1171211611 .want_safety = block.want_safety,
11612 .src_base_inst = block.src_base_inst,
1171311613 };
1171411614 const merges = &child_block.label.?.merges;
1171511615 defer child_block.instructions.deinit(gpa);
......@@ -11776,6 +11676,7 @@ fn zirSwitchBlockErrUnion(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp
1177611676 try sema.switchCond(block, switch_operand_src, spa.operand),
1177711677 err_val,
1177811678 operand_err_set_ty,
11679 switch_src_node_offset,
1177911680 .{
1178011681 .body = else_case.body,
1178111682 .end = else_case.end,
......@@ -11817,7 +11718,7 @@ fn zirSwitchBlockErrUnion(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp
1181711718
1181811719 var sub_block = child_block.makeSubBlock();
1181911720 sub_block.runtime_loop = null;
11820 sub_block.runtime_cond = mod.declPtr(child_block.src_decl).toSrcLoc(main_operand_src, mod);
11721 sub_block.runtime_cond = main_operand_src;
1182111722 sub_block.runtime_index.increment();
1182211723 sub_block.need_debug_scope = null; // this body is emitted regardless
1182311724 defer sub_block.instructions.deinit(gpa);
......@@ -11894,8 +11795,8 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1189411795 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
1189511796 const src = block.nodeOffset(inst_data.src_node);
1189611797 const src_node_offset = inst_data.src_node;
11897 const operand_src: LazySrcLoc = .{ .node_offset_switch_operand = src_node_offset };
11898 const special_prong_src: LazySrcLoc = .{ .node_offset_switch_special_prong = src_node_offset };
11798 const operand_src = block.src(.{ .node_offset_switch_operand = src_node_offset });
11799 const special_prong_src = block.src(.{ .node_offset_switch_special_prong = src_node_offset });
1189911800 const extra = sema.code.extraData(Zir.Inst.SwitchBlock, inst_data.payload_index);
1190011801
1190111802 const raw_operand_val: Air.Inst.Ref, const raw_operand_ptr: Air.Inst.Ref = blk: {
......@@ -11962,7 +11863,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1196211863 const union_originally = maybe_union_ty.zigTypeTag(mod) == .Union;
1196311864
1196411865 // Duplicate checking variables later also used for `inline else`.
11965 var seen_enum_fields: []?Module.SwitchProngSrc = &.{};
11866 var seen_enum_fields: []?LazySrcLoc = &.{};
1196611867 var seen_errors = SwitchErrorSet.init(gpa);
1196711868 var range_set = RangeSet.init(gpa, mod);
1196811869 var true_count: u8 = 0;
......@@ -11985,21 +11886,18 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1198511886 if (special_prong == .under and (!operand_ty.isNonexhaustiveEnum(mod) or union_originally)) {
1198611887 const msg = msg: {
1198711888 const msg = try sema.errMsg(
11988 block,
1198911889 src,
1199011890 "'_' prong only allowed when switching on non-exhaustive enums",
1199111891 .{},
1199211892 );
1199311893 errdefer msg.destroy(gpa);
1199411894 try sema.errNote(
11995 block,
1199611895 special_prong_src,
1199711896 msg,
1199811897 "'_' prong here",
1199911898 .{},
1200011899 );
1200111900 try sema.errNote(
12002 block,
1200311901 src,
1200411902 msg,
1200511903 "consider using 'else'",
......@@ -12014,7 +11912,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1201411912 switch (operand_ty.zigTypeTag(mod)) {
1201511913 .Union => unreachable, // handled in `switchCond`
1201611914 .Enum => {
12017 seen_enum_fields = try gpa.alloc(?Module.SwitchProngSrc, operand_ty.enumFieldCount(mod));
11915 seen_enum_fields = try gpa.alloc(?LazySrcLoc, operand_ty.enumFieldCount(mod));
1201811916 empty_enum = seen_enum_fields.len == 0 and !operand_ty.isNonexhaustiveEnum(mod);
1201911917 @memset(seen_enum_fields, null);
1202011918 // `range_set` is used for non-exhaustive enum values that do not correspond to any tags.
......@@ -12034,8 +11932,11 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1203411932 &range_set,
1203511933 item_ref,
1203611934 operand_ty,
12037 src_node_offset,
12038 .{ .scalar = scalar_i },
11935 block.src(.{ .switch_case_item = .{
11936 .switch_node_offset = src_node_offset,
11937 .case_idx = .{ .kind = .scalar, .index = @intCast(scalar_i) },
11938 .item_idx = .{ .kind = .single, .index = 0 },
11939 } }),
1203911940 ));
1204011941 }
1204111942 }
......@@ -12059,8 +11960,11 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1205911960 &range_set,
1206011961 item_ref,
1206111962 operand_ty,
12062 src_node_offset,
12063 .{ .multi = .{ .prong = multi_i, .item = @intCast(item_i) } },
11963 block.src(.{ .switch_case_item = .{
11964 .switch_node_offset = src_node_offset,
11965 .case_idx = .{ .kind = .multi, .index = @intCast(multi_i) },
11966 .item_idx = .{ .kind = .single, .index = @intCast(item_i) },
11967 } }),
1206411968 ));
1206511969 }
1206611970
......@@ -12081,7 +11985,6 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1208111985 } else if (!all_tags_handled) {
1208211986 const msg = msg: {
1208311987 const msg = try sema.errMsg(
12084 block,
1208511988 src,
1208611989 "switch must handle all possibilities",
1208711990 .{},
......@@ -12099,8 +12002,8 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1209912002 .{field_name.fmt(&mod.intern_pool)},
1210012003 );
1210112004 }
12102 try mod.errNoteNonLazy(
12103 operand_ty.declSrcLoc(mod),
12005 try sema.errNote(
12006 operand_ty.srcLoc(mod),
1210412007 msg,
1210512008 "enum '{}' declared here",
1210612009 .{operand_ty.fmt(mod)},
......@@ -12144,8 +12047,11 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1214412047 &range_set,
1214512048 item_ref,
1214612049 operand_ty,
12147 src_node_offset,
12148 .{ .scalar = scalar_i },
12050 block.src(.{ .switch_case_item = .{
12051 .switch_node_offset = src_node_offset,
12052 .case_idx = .{ .kind = .scalar, .index = @intCast(scalar_i) },
12053 .item_idx = .{ .kind = .single, .index = 0 },
12054 } }),
1214912055 ));
1215012056 }
1215112057 }
......@@ -12168,8 +12074,11 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1216812074 &range_set,
1216912075 item_ref,
1217012076 operand_ty,
12171 src_node_offset,
12172 .{ .multi = .{ .prong = multi_i, .item = @intCast(item_i) } },
12077 block.src(.{ .switch_case_item = .{
12078 .switch_node_offset = src_node_offset,
12079 .case_idx = .{ .kind = .multi, .index = @intCast(multi_i) },
12080 .item_idx = .{ .kind = .single, .index = @intCast(item_i) },
12081 } }),
1217312082 ));
1217412083 }
1217512084
......@@ -12187,8 +12096,11 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1218712096 item_first,
1218812097 item_last,
1218912098 operand_ty,
12190 src_node_offset,
12191 .{ .range = .{ .prong = multi_i, .item = range_i } },
12099 block.src(.{ .switch_case_item = .{
12100 .switch_node_offset = src_node_offset,
12101 .case_idx = .{ .kind = .multi, .index = @intCast(multi_i) },
12102 .item_idx = .{ .kind = .range, .index = @intCast(range_i) },
12103 } }),
1219212104 );
1219312105 case_vals.appendAssumeCapacity(vals[0]);
1219412106 case_vals.appendAssumeCapacity(vals[1]);
......@@ -12239,8 +12151,11 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1223912151 &true_count,
1224012152 &false_count,
1224112153 item_ref,
12242 src_node_offset,
12243 .{ .scalar = scalar_i },
12154 block.src(.{ .switch_case_item = .{
12155 .switch_node_offset = src_node_offset,
12156 .case_idx = .{ .kind = .scalar, .index = @intCast(scalar_i) },
12157 .item_idx = .{ .kind = .single, .index = 0 },
12158 } }),
1224412159 ));
1224512160 }
1224612161 }
......@@ -12263,8 +12178,11 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1226312178 &true_count,
1226412179 &false_count,
1226512180 item_ref,
12266 src_node_offset,
12267 .{ .multi = .{ .prong = multi_i, .item = @intCast(item_i) } },
12181 block.src(.{ .switch_case_item = .{
12182 .switch_node_offset = src_node_offset,
12183 .case_idx = .{ .kind = .multi, .index = @intCast(multi_i) },
12184 .item_idx = .{ .kind = .single, .index = @intCast(item_i) },
12185 } }),
1226812186 ));
1226912187 }
1227012188
......@@ -12322,8 +12240,11 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1232212240 &seen_values,
1232312241 item_ref,
1232412242 operand_ty,
12325 src_node_offset,
12326 .{ .scalar = scalar_i },
12243 block.src(.{ .switch_case_item = .{
12244 .switch_node_offset = src_node_offset,
12245 .case_idx = .{ .kind = .scalar, .index = @intCast(scalar_i) },
12246 .item_idx = .{ .kind = .single, .index = 0 },
12247 } }),
1232712248 ));
1232812249 }
1232912250 }
......@@ -12346,8 +12267,11 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1234612267 &seen_values,
1234712268 item_ref,
1234812269 operand_ty,
12349 src_node_offset,
12350 .{ .multi = .{ .prong = multi_i, .item = @intCast(item_i) } },
12270 block.src(.{ .switch_case_item = .{
12271 .switch_node_offset = src_node_offset,
12272 .case_idx = .{ .kind = .multi, .index = @intCast(multi_i) },
12273 .item_idx = .{ .kind = .single, .index = @intCast(item_i) },
12274 } }),
1235112275 ));
1235212276 }
1235312277
......@@ -12417,6 +12341,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1241712341 .runtime_index = block.runtime_index,
1241812342 .want_safety = block.want_safety,
1241912343 .error_return_trace_index = block.error_return_trace_index,
12344 .src_base_inst = block.src_base_inst,
1242012345 };
1242112346 const merges = &child_block.label.?.merges;
1242212347 defer child_block.instructions.deinit(gpa);
......@@ -12430,6 +12355,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1243012355 operand,
1243112356 operand_val,
1243212357 operand_ty,
12358 src_node_offset,
1243312359 special,
1243412360 case_vals,
1243512361 scalar_cases_len,
......@@ -12462,7 +12388,10 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1246212388 .special,
1246312389 special.body,
1246412390 special.capture,
12465 .special_capture,
12391 block.src(.{ .switch_capture = .{
12392 .switch_node_offset = src_node_offset,
12393 .case_idx = LazySrcLoc.Offset.SwitchCaseIndex.special,
12394 } }),
1246612395 undefined, // case_vals may be undefined for special prongs
1246712396 .none,
1246812397 false,
......@@ -12529,9 +12458,9 @@ fn analyzeSwitchRuntimeBlock(
1252912458 union_originally: bool,
1253012459 maybe_union_ty: Type,
1253112460 err_set: bool,
12532 src_node_offset: i32,
12461 switch_node_offset: i32,
1253312462 special_prong_src: LazySrcLoc,
12534 seen_enum_fields: []?Module.SwitchProngSrc,
12463 seen_enum_fields: []?LazySrcLoc,
1253512464 seen_errors: SwitchErrorSet,
1253612465 range_set: RangeSet,
1253712466 true_count: u8,
......@@ -12552,7 +12481,7 @@ fn analyzeSwitchRuntimeBlock(
1255212481
1255312482 var case_block = child_block.makeSubBlock();
1255412483 case_block.runtime_loop = null;
12555 case_block.runtime_cond = mod.declPtr(child_block.src_decl).toSrcLoc(operand_src, mod);
12484 case_block.runtime_cond = operand_src;
1255612485 case_block.runtime_index.increment();
1255712486 case_block.need_debug_scope = null; // this body is emitted regardless
1255812487 defer case_block.instructions.deinit(gpa);
......@@ -12574,7 +12503,7 @@ fn analyzeSwitchRuntimeBlock(
1257412503 // `item` is already guaranteed to be constant known.
1257512504
1257612505 const analyze_body = if (union_originally) blk: {
12577 const unresolved_item_val = sema.resolveConstDefinedValue(block, .unneeded, item, undefined) catch unreachable;
12506 const unresolved_item_val = sema.resolveConstDefinedValue(block, LazySrcLoc.unneeded, item, undefined) catch unreachable;
1257812507 const item_val = sema.resolveLazyValue(unresolved_item_val) catch unreachable;
1257912508 const field_ty = maybe_union_ty.unionFieldType(item_val, mod).?;
1258012509 break :blk field_ty.zigTypeTag(mod) != .NoReturn;
......@@ -12588,7 +12517,10 @@ fn analyzeSwitchRuntimeBlock(
1258812517 .normal,
1258912518 body,
1259012519 info.capture,
12591 .{ .scalar_capture = @intCast(scalar_i) },
12520 child_block.src(.{ .switch_capture = .{
12521 .switch_node_offset = switch_node_offset,
12522 .case_idx = .{ .kind = .scalar, .index = @intCast(scalar_i) },
12523 } }),
1259212524 &.{item},
1259312525 if (info.is_inline) item else .none,
1259412526 info.has_tag_capture,
......@@ -12643,8 +12575,8 @@ fn analyzeSwitchRuntimeBlock(
1264312575 const item_first_ref = range_items[0];
1264412576 const item_last_ref = range_items[1];
1264512577
12646 var item = sema.resolveConstDefinedValue(block, .unneeded, item_first_ref, undefined) catch unreachable;
12647 const item_last = sema.resolveConstDefinedValue(block, .unneeded, item_last_ref, undefined) catch unreachable;
12578 var item = sema.resolveConstDefinedValue(block, LazySrcLoc.unneeded, item_first_ref, undefined) catch unreachable;
12579 const item_last = sema.resolveConstDefinedValue(block, LazySrcLoc.unneeded, item_last_ref, undefined) catch unreachable;
1264812580
1264912581 while (item.compareScalar(.lte, item_last, operand_ty, mod)) : ({
1265012582 // Previous validation has resolved any possible lazy values.
......@@ -12660,17 +12592,11 @@ fn analyzeSwitchRuntimeBlock(
1266012592 case_block.instructions.shrinkRetainingCapacity(0);
1266112593 case_block.error_return_trace_index = child_block.error_return_trace_index;
1266212594
12663 if (emit_bb) sema.emitBackwardBranch(block, .unneeded) catch |err| switch (err) {
12664 error.NeededSourceLocation => {
12665 const case_src = Module.SwitchProngSrc{
12666 .range = .{ .prong = multi_i, .item = range_i },
12667 };
12668 const decl = mod.declPtr(case_block.src_decl);
12669 try sema.emitBackwardBranch(block, case_src.resolve(mod, decl, src_node_offset, .none));
12670 unreachable;
12671 },
12672 else => return err,
12673 };
12595 if (emit_bb) try sema.emitBackwardBranch(block, block.src(.{ .switch_case_item = .{
12596 .switch_node_offset = switch_node_offset,
12597 .case_idx = .{ .kind = .multi, .index = @intCast(multi_i) },
12598 .item_idx = .{ .kind = .range, .index = @intCast(range_i) },
12599 } }));
1267412600 emit_bb = true;
1267512601
1267612602 try spa.analyzeProngRuntime(
......@@ -12678,7 +12604,10 @@ fn analyzeSwitchRuntimeBlock(
1267812604 .normal,
1267912605 body,
1268012606 info.capture,
12681 .{ .multi_capture = multi_i },
12607 child_block.src(.{ .switch_capture = .{
12608 .switch_node_offset = switch_node_offset,
12609 .case_idx = .{ .kind = .multi, .index = @intCast(multi_i) },
12610 } }),
1268212611 undefined, // case_vals may be undefined for ranges
1268312612 item_ref,
1268412613 info.has_tag_capture,
......@@ -12701,22 +12630,16 @@ fn analyzeSwitchRuntimeBlock(
1270112630 case_block.error_return_trace_index = child_block.error_return_trace_index;
1270212631
1270312632 const analyze_body = if (union_originally) blk: {
12704 const item_val = sema.resolveConstDefinedValue(block, .unneeded, item, undefined) catch unreachable;
12633 const item_val = sema.resolveConstDefinedValue(block, LazySrcLoc.unneeded, item, undefined) catch unreachable;
1270512634 const field_ty = maybe_union_ty.unionFieldType(item_val, mod).?;
1270612635 break :blk field_ty.zigTypeTag(mod) != .NoReturn;
1270712636 } else true;
1270812637
12709 if (emit_bb) sema.emitBackwardBranch(block, .unneeded) catch |err| switch (err) {
12710 error.NeededSourceLocation => {
12711 const case_src = Module.SwitchProngSrc{
12712 .multi = .{ .prong = multi_i, .item = @intCast(item_i) },
12713 };
12714 const decl = mod.declPtr(case_block.src_decl);
12715 try sema.emitBackwardBranch(block, case_src.resolve(mod, decl, src_node_offset, .none));
12716 unreachable;
12717 },
12718 else => return err,
12719 };
12638 if (emit_bb) try sema.emitBackwardBranch(block, block.src(.{ .switch_case_item = .{
12639 .switch_node_offset = switch_node_offset,
12640 .case_idx = .{ .kind = .multi, .index = @intCast(multi_i) },
12641 .item_idx = .{ .kind = .single, .index = @intCast(item_i) },
12642 } }));
1272012643 emit_bb = true;
1272112644
1272212645 if (analyze_body) {
......@@ -12725,7 +12648,10 @@ fn analyzeSwitchRuntimeBlock(
1272512648 .normal,
1272612649 body,
1272712650 info.capture,
12728 .{ .multi_capture = multi_i },
12651 child_block.src(.{ .switch_capture = .{
12652 .switch_node_offset = switch_node_offset,
12653 .case_idx = .{ .kind = .multi, .index = @intCast(multi_i) },
12654 } }),
1272912655 &.{item},
1273012656 item,
1273112657 info.has_tag_capture,
......@@ -12755,7 +12681,7 @@ fn analyzeSwitchRuntimeBlock(
1275512681
1275612682 const analyze_body = if (union_originally)
1275712683 for (items) |item| {
12758 const item_val = sema.resolveConstDefinedValue(block, .unneeded, item, undefined) catch unreachable;
12684 const item_val = sema.resolveConstDefinedValue(block, LazySrcLoc.unneeded, item, undefined) catch unreachable;
1275912685 const field_ty = maybe_union_ty.unionFieldType(item_val, mod).?;
1276012686 if (field_ty.zigTypeTag(mod) != .NoReturn) break true;
1276112687 } else false
......@@ -12772,7 +12698,10 @@ fn analyzeSwitchRuntimeBlock(
1277212698 .normal,
1277312699 body,
1277412700 info.capture,
12775 .{ .multi_capture = multi_i },
12701 child_block.src(.{ .switch_capture = .{
12702 .switch_node_offset = switch_node_offset,
12703 .case_idx = .{ .kind = .multi, .index = @intCast(multi_i) },
12704 } }),
1277612705 items,
1277712706 .none,
1277812707 false,
......@@ -12856,7 +12785,10 @@ fn analyzeSwitchRuntimeBlock(
1285612785 .normal,
1285712786 body,
1285812787 info.capture,
12859 .{ .multi_capture = multi_i },
12788 child_block.src(.{ .switch_capture = .{
12789 .switch_node_offset = switch_node_offset,
12790 .case_idx = .{ .kind = .multi, .index = @intCast(multi_i) },
12791 } }),
1286012792 items,
1286112793 .none,
1286212794 false,
......@@ -12921,7 +12853,10 @@ fn analyzeSwitchRuntimeBlock(
1292112853 .special,
1292212854 special.body,
1292312855 special.capture,
12924 .special_capture,
12856 child_block.src(.{ .switch_capture = .{
12857 .switch_node_offset = switch_node_offset,
12858 .case_idx = LazySrcLoc.Offset.SwitchCaseIndex.special,
12859 } }),
1292512860 &.{item_ref},
1292612861 item_ref,
1292712862 special.has_tag_capture,
......@@ -12966,7 +12901,10 @@ fn analyzeSwitchRuntimeBlock(
1296612901 .special,
1296712902 special.body,
1296812903 special.capture,
12969 .special_capture,
12904 child_block.src(.{ .switch_capture = .{
12905 .switch_node_offset = switch_node_offset,
12906 .case_idx = LazySrcLoc.Offset.SwitchCaseIndex.special,
12907 } }),
1297012908 &.{item_ref},
1297112909 item_ref,
1297212910 special.has_tag_capture,
......@@ -12997,7 +12935,10 @@ fn analyzeSwitchRuntimeBlock(
1299712935 .special,
1299812936 special.body,
1299912937 special.capture,
13000 .special_capture,
12938 child_block.src(.{ .switch_capture = .{
12939 .switch_node_offset = switch_node_offset,
12940 .case_idx = LazySrcLoc.Offset.SwitchCaseIndex.special,
12941 } }),
1300112942 &.{item_ref},
1300212943 item_ref,
1300312944 special.has_tag_capture,
......@@ -13025,7 +12966,10 @@ fn analyzeSwitchRuntimeBlock(
1302512966 .special,
1302612967 special.body,
1302712968 special.capture,
13028 .special_capture,
12969 child_block.src(.{ .switch_capture = .{
12970 .switch_node_offset = switch_node_offset,
12971 .case_idx = LazySrcLoc.Offset.SwitchCaseIndex.special,
12972 } }),
1302912973 &.{.bool_true},
1303012974 .bool_true,
1303112975 special.has_tag_capture,
......@@ -13051,7 +12995,10 @@ fn analyzeSwitchRuntimeBlock(
1305112995 .special,
1305212996 special.body,
1305312997 special.capture,
13054 .special_capture,
12998 child_block.src(.{ .switch_capture = .{
12999 .switch_node_offset = switch_node_offset,
13000 .case_idx = LazySrcLoc.Offset.SwitchCaseIndex.special,
13001 } }),
1305513002 &.{.bool_false},
1305613003 .bool_false,
1305713004 special.has_tag_capture,
......@@ -13101,7 +13048,10 @@ fn analyzeSwitchRuntimeBlock(
1310113048 .special,
1310213049 special.body,
1310313050 special.capture,
13104 .special_capture,
13051 child_block.src(.{ .switch_capture = .{
13052 .switch_node_offset = switch_node_offset,
13053 .case_idx = LazySrcLoc.Offset.SwitchCaseIndex.special,
13054 } }),
1310513055 undefined, // case_vals may be undefined for special prongs
1310613056 .none,
1310713057 false,
......@@ -13161,6 +13111,7 @@ fn resolveSwitchComptime(
1316113111 cond_operand: Air.Inst.Ref,
1316213112 operand_val: Value,
1316313113 operand_ty: Type,
13114 switch_node_offset: i32,
1316413115 special: SpecialProng,
1316513116 case_vals: std.ArrayListUnmanaged(Air.Inst.Ref),
1316613117 scalar_cases_len: u32,
......@@ -13181,7 +13132,7 @@ fn resolveSwitchComptime(
1318113132 extra_index += info.body_len;
1318213133
1318313134 const item = case_vals.items[scalar_i];
13184 const item_val = sema.resolveConstDefinedValue(child_block, .unneeded, item, undefined) catch unreachable;
13135 const item_val = sema.resolveConstDefinedValue(child_block, LazySrcLoc.unneeded, item, undefined) catch unreachable;
1318513136 if (operand_val.eql(item_val, operand_ty, sema.mod)) {
1318613137 if (err_set) try sema.maybeErrorUnwrapComptime(child_block, body, cond_operand);
1318713138 return spa.resolveProngComptime(
......@@ -13189,7 +13140,10 @@ fn resolveSwitchComptime(
1318913140 .normal,
1319013141 body,
1319113142 info.capture,
13192 .{ .scalar_capture = @intCast(scalar_i) },
13143 child_block.src(.{ .switch_capture = .{
13144 .switch_node_offset = switch_node_offset,
13145 .case_idx = .{ .kind = .scalar, .index = @intCast(scalar_i) },
13146 } }),
1319313147 &.{item},
1319413148 if (info.is_inline) cond_operand else .none,
1319513149 info.has_tag_capture,
......@@ -13215,7 +13169,7 @@ fn resolveSwitchComptime(
1321513169
1321613170 for (items) |item| {
1321713171 // Validation above ensured these will succeed.
13218 const item_val = sema.resolveConstDefinedValue(child_block, .unneeded, item, undefined) catch unreachable;
13172 const item_val = sema.resolveConstDefinedValue(child_block, LazySrcLoc.unneeded, item, undefined) catch unreachable;
1321913173 if (operand_val.eql(item_val, operand_ty, sema.mod)) {
1322013174 if (err_set) try sema.maybeErrorUnwrapComptime(child_block, body, cond_operand);
1322113175 return spa.resolveProngComptime(
......@@ -13223,7 +13177,10 @@ fn resolveSwitchComptime(
1322313177 .normal,
1322413178 body,
1322513179 info.capture,
13226 .{ .multi_capture = @intCast(multi_i) },
13180 child_block.src(.{ .switch_capture = .{
13181 .switch_node_offset = switch_node_offset,
13182 .case_idx = .{ .kind = .multi, .index = @intCast(multi_i) },
13183 } }),
1322713184 items,
1322813185 if (info.is_inline) cond_operand else .none,
1322913186 info.has_tag_capture,
......@@ -13239,8 +13196,8 @@ fn resolveSwitchComptime(
1323913196 case_val_idx += 2;
1324013197
1324113198 // Validation above ensured these will succeed.
13242 const first_val = sema.resolveConstDefinedValue(child_block, .unneeded, range_items[0], undefined) catch unreachable;
13243 const last_val = sema.resolveConstDefinedValue(child_block, .unneeded, range_items[1], undefined) catch unreachable;
13199 const first_val = sema.resolveConstDefinedValue(child_block, LazySrcLoc.unneeded, range_items[0], undefined) catch unreachable;
13200 const last_val = sema.resolveConstDefinedValue(child_block, LazySrcLoc.unneeded, range_items[1], undefined) catch unreachable;
1324413201 if ((try sema.compareAll(resolved_operand_val, .gte, first_val, operand_ty)) and
1324513202 (try sema.compareAll(resolved_operand_val, .lte, last_val, operand_ty)))
1324613203 {
......@@ -13250,7 +13207,10 @@ fn resolveSwitchComptime(
1325013207 .normal,
1325113208 body,
1325213209 info.capture,
13253 .{ .multi_capture = @intCast(multi_i) },
13210 child_block.src(.{ .switch_capture = .{
13211 .switch_node_offset = switch_node_offset,
13212 .case_idx = .{ .kind = .multi, .index = @intCast(multi_i) },
13213 } }),
1325413214 undefined, // case_vals may be undefined for ranges
1325513215 if (info.is_inline) cond_operand else .none,
1325613216 info.has_tag_capture,
......@@ -13272,7 +13232,10 @@ fn resolveSwitchComptime(
1327213232 .special,
1327313233 special.body,
1327413234 special.capture,
13275 .special_capture,
13235 child_block.src(.{ .switch_capture = .{
13236 .switch_node_offset = switch_node_offset,
13237 .case_idx = LazySrcLoc.Offset.SwitchCaseIndex.special,
13238 } }),
1327613239 undefined, // case_vals may be undefined for special prongs
1327713240 if (special.is_inline) cond_operand else .none,
1327813241 special.has_tag_capture,
......@@ -13358,36 +13321,19 @@ fn resolveSwitchItemVal(
1335813321 item_ref: Zir.Inst.Ref,
1335913322 /// Coerce `item_ref` to this type.
1336013323 coerce_ty: Type,
13361 switch_node_offset: i32,
13362 switch_prong_src: Module.SwitchProngSrc,
13363 range_expand: Module.SwitchProngSrc.RangeExpand,
13324 item_src: LazySrcLoc,
1336413325) CompileError!ResolvedSwitchItem {
13365 const mod = sema.mod;
1336613326 const uncoerced_item = try sema.resolveInst(item_ref);
1336713327
1336813328 // Constructing a LazySrcLoc is costly because we only have the switch AST node.
1336913329 // Only if we know for sure we need to report a compile error do we resolve the
1337013330 // full source locations.
1337113331
13372 const item = sema.coerce(block, coerce_ty, uncoerced_item, .unneeded) catch |err| switch (err) {
13373 error.NeededSourceLocation => {
13374 const src = switch_prong_src.resolve(mod, mod.declPtr(block.src_decl), switch_node_offset, range_expand);
13375 _ = try sema.coerce(block, coerce_ty, uncoerced_item, src);
13376 unreachable;
13377 },
13378 else => |e| return e,
13379 };
13332 const item = try sema.coerce(block, coerce_ty, uncoerced_item, item_src);
1338013333
13381 const maybe_lazy = sema.resolveConstDefinedValue(block, .unneeded, item, undefined) catch |err| switch (err) {
13382 error.NeededSourceLocation => {
13383 const src = switch_prong_src.resolve(mod, mod.declPtr(block.src_decl), switch_node_offset, range_expand);
13384 _ = try sema.resolveConstDefinedValue(block, src, item, .{
13385 .needed_comptime_reason = "switch prong values must be comptime-known",
13386 });
13387 unreachable;
13388 },
13389 else => |e| return e,
13390 };
13334 const maybe_lazy = try sema.resolveConstDefinedValue(block, item_src, item, .{
13335 .needed_comptime_reason = "switch prong values must be comptime-known",
13336 });
1339113337
1339213338 const val = try sema.resolveLazyValue(maybe_lazy);
1339313339 const new_item = if (val.toIntern() != maybe_lazy.toIntern()) blk: {
......@@ -13430,8 +13376,11 @@ fn validateErrSetSwitch(
1343013376 seen_errors,
1343113377 item_ref,
1343213378 operand_ty,
13433 src_node_offset,
13434 .{ .scalar = scalar_i },
13379 block.src(.{ .switch_case_item = .{
13380 .switch_node_offset = src_node_offset,
13381 .case_idx = .{ .kind = .scalar, .index = @intCast(scalar_i) },
13382 .item_idx = .{ .kind = .single, .index = 0 },
13383 } }),
1343513384 ));
1343613385 }
1343713386 }
......@@ -13454,8 +13403,11 @@ fn validateErrSetSwitch(
1345413403 seen_errors,
1345513404 item_ref,
1345613405 operand_ty,
13457 src_node_offset,
13458 .{ .multi = .{ .prong = multi_i, .item = @intCast(item_i) } },
13406 block.src(.{ .switch_case_item = .{
13407 .switch_node_offset = src_node_offset,
13408 .case_idx = .{ .kind = .multi, .index = @intCast(multi_i) },
13409 .item_idx = .{ .kind = .single, .index = @intCast(item_i) },
13410 } }),
1345913411 ));
1346013412 }
1346113413
......@@ -13484,7 +13436,6 @@ fn validateErrSetSwitch(
1348413436 if (!seen_errors.contains(error_name) and !has_else) {
1348513437 const msg = maybe_msg orelse blk: {
1348613438 maybe_msg = try sema.errMsg(
13487 block,
1348813439 src,
1348913440 "switch must handle all possibilities",
1349013441 .{},
......@@ -13493,7 +13444,6 @@ fn validateErrSetSwitch(
1349313444 };
1349413445
1349513446 try sema.errNote(
13496 block,
1349713447 src,
1349813448 msg,
1349913449 "unhandled error value: 'error.{}'",
......@@ -13571,18 +13521,24 @@ fn validateSwitchRange(
1357113521 first_ref: Zir.Inst.Ref,
1357213522 last_ref: Zir.Inst.Ref,
1357313523 operand_ty: Type,
13574 src_node_offset: i32,
13575 switch_prong_src: Module.SwitchProngSrc,
13524 item_src: LazySrcLoc,
1357613525) CompileError![2]Air.Inst.Ref {
1357713526 const mod = sema.mod;
13578 const first = try sema.resolveSwitchItemVal(block, first_ref, operand_ty, src_node_offset, switch_prong_src, .first);
13579 const last = try sema.resolveSwitchItemVal(block, last_ref, operand_ty, src_node_offset, switch_prong_src, .last);
13527 const first_src: LazySrcLoc = .{
13528 .base_node_inst = item_src.base_node_inst,
13529 .offset = .{ .switch_case_item_range_first = item_src.offset.switch_case_item },
13530 };
13531 const last_src: LazySrcLoc = .{
13532 .base_node_inst = item_src.base_node_inst,
13533 .offset = .{ .switch_case_item_range_last = item_src.offset.switch_case_item },
13534 };
13535 const first = try sema.resolveSwitchItemVal(block, first_ref, operand_ty, first_src);
13536 const last = try sema.resolveSwitchItemVal(block, last_ref, operand_ty, last_src);
1358013537 if (try Value.fromInterned(first.val).compareAll(.gt, Value.fromInterned(last.val), operand_ty, mod)) {
13581 const src = switch_prong_src.resolve(mod, mod.declPtr(block.src_decl), src_node_offset, .first);
13582 return sema.fail(block, src, "range start value is greater than the end value", .{});
13538 return sema.fail(block, item_src, "range start value is greater than the end value", .{});
1358313539 }
13584 const maybe_prev_src = try range_set.add(first.val, last.val, switch_prong_src);
13585 try sema.validateSwitchDupe(block, maybe_prev_src, switch_prong_src, src_node_offset);
13540 const maybe_prev_src = try range_set.add(first.val, last.val, item_src);
13541 try sema.validateSwitchDupe(block, maybe_prev_src, item_src);
1358613542 return .{ first.ref, last.ref };
1358713543}
1358813544
......@@ -13592,36 +13548,34 @@ fn validateSwitchItemInt(
1359213548 range_set: *RangeSet,
1359313549 item_ref: Zir.Inst.Ref,
1359413550 operand_ty: Type,
13595 src_node_offset: i32,
13596 switch_prong_src: Module.SwitchProngSrc,
13551 item_src: LazySrcLoc,
1359713552) CompileError!Air.Inst.Ref {
13598 const item = try sema.resolveSwitchItemVal(block, item_ref, operand_ty, src_node_offset, switch_prong_src, .none);
13599 const maybe_prev_src = try range_set.add(item.val, item.val, switch_prong_src);
13600 try sema.validateSwitchDupe(block, maybe_prev_src, switch_prong_src, src_node_offset);
13553 const item = try sema.resolveSwitchItemVal(block, item_ref, operand_ty, item_src);
13554 const maybe_prev_src = try range_set.add(item.val, item.val, item_src);
13555 try sema.validateSwitchDupe(block, maybe_prev_src, item_src);
1360113556 return item.ref;
1360213557}
1360313558
1360413559fn validateSwitchItemEnum(
1360513560 sema: *Sema,
1360613561 block: *Block,
13607 seen_fields: []?Module.SwitchProngSrc,
13562 seen_fields: []?LazySrcLoc,
1360813563 range_set: *RangeSet,
1360913564 item_ref: Zir.Inst.Ref,
1361013565 operand_ty: Type,
13611 src_node_offset: i32,
13612 switch_prong_src: Module.SwitchProngSrc,
13566 item_src: LazySrcLoc,
1361313567) CompileError!Air.Inst.Ref {
1361413568 const ip = &sema.mod.intern_pool;
13615 const item = try sema.resolveSwitchItemVal(block, item_ref, operand_ty, src_node_offset, switch_prong_src, .none);
13569 const item = try sema.resolveSwitchItemVal(block, item_ref, operand_ty, item_src);
1361613570 const int = ip.indexToKey(item.val).enum_tag.int;
1361713571 const field_index = ip.loadEnumType(ip.typeOf(item.val)).tagValueIndex(ip, int) orelse {
13618 const maybe_prev_src = try range_set.add(int, int, switch_prong_src);
13619 try sema.validateSwitchDupe(block, maybe_prev_src, switch_prong_src, src_node_offset);
13572 const maybe_prev_src = try range_set.add(int, int, item_src);
13573 try sema.validateSwitchDupe(block, maybe_prev_src, item_src);
1362013574 return item.ref;
1362113575 };
1362213576 const maybe_prev_src = seen_fields[field_index];
13623 seen_fields[field_index] = switch_prong_src;
13624 try sema.validateSwitchDupe(block, maybe_prev_src, switch_prong_src, src_node_offset);
13577 seen_fields[field_index] = item_src;
13578 try sema.validateSwitchDupe(block, maybe_prev_src, item_src);
1362513579 return item.ref;
1362613580}
1362713581
......@@ -13631,50 +13585,41 @@ fn validateSwitchItemError(
1363113585 seen_errors: *SwitchErrorSet,
1363213586 item_ref: Zir.Inst.Ref,
1363313587 operand_ty: Type,
13634 src_node_offset: i32,
13635 switch_prong_src: Module.SwitchProngSrc,
13588 item_src: LazySrcLoc,
1363613589) CompileError!Air.Inst.Ref {
1363713590 const ip = &sema.mod.intern_pool;
13638 const item = try sema.resolveSwitchItemVal(block, item_ref, operand_ty, src_node_offset, switch_prong_src, .none);
13591 const item = try sema.resolveSwitchItemVal(block, item_ref, operand_ty, item_src);
1363913592 const error_name = ip.indexToKey(item.val).err.name;
13640 const maybe_prev_src = if (try seen_errors.fetchPut(error_name, switch_prong_src)) |prev|
13593 const maybe_prev_src = if (try seen_errors.fetchPut(error_name, item_src)) |prev|
1364113594 prev.value
1364213595 else
1364313596 null;
13644 try sema.validateSwitchDupe(block, maybe_prev_src, switch_prong_src, src_node_offset);
13597 try sema.validateSwitchDupe(block, maybe_prev_src, item_src);
1364513598 return item.ref;
1364613599}
1364713600
1364813601fn validateSwitchDupe(
1364913602 sema: *Sema,
1365013603 block: *Block,
13651 maybe_prev_src: ?Module.SwitchProngSrc,
13652 switch_prong_src: Module.SwitchProngSrc,
13653 src_node_offset: i32,
13604 maybe_prev_src: ?LazySrcLoc,
13605 item_src: LazySrcLoc,
1365413606) CompileError!void {
13655 const prev_prong_src = maybe_prev_src orelse return;
13656 const mod = sema.mod;
13657 const block_src_decl = mod.declPtr(block.src_decl);
13658 const src = switch_prong_src.resolve(mod, block_src_decl, src_node_offset, .none);
13659 const prev_src = prev_prong_src.resolve(mod, block_src_decl, src_node_offset, .none);
13660 const msg = msg: {
13607 const prev_item_src = maybe_prev_src orelse return;
13608 return sema.failWithOwnedErrorMsg(block, msg: {
1366113609 const msg = try sema.errMsg(
13662 block,
13663 src,
13610 item_src,
1366413611 "duplicate switch value",
1366513612 .{},
1366613613 );
1366713614 errdefer msg.destroy(sema.gpa);
1366813615 try sema.errNote(
13669 block,
13670 prev_src,
13616 prev_item_src,
1367113617 msg,
1367213618 "previous value here",
1367313619 .{},
1367413620 );
1367513621 break :msg msg;
13676 };
13677 return sema.failWithOwnedErrorMsg(block, msg);
13622 });
1367813623}
1367913624
1368013625fn validateSwitchItemBool(
......@@ -13683,25 +13628,21 @@ fn validateSwitchItemBool(
1368313628 true_count: *u8,
1368413629 false_count: *u8,
1368513630 item_ref: Zir.Inst.Ref,
13686 src_node_offset: i32,
13687 switch_prong_src: Module.SwitchProngSrc,
13631 item_src: LazySrcLoc,
1368813632) CompileError!Air.Inst.Ref {
13689 const mod = sema.mod;
13690 const item = try sema.resolveSwitchItemVal(block, item_ref, Type.bool, src_node_offset, switch_prong_src, .none);
13633 const item = try sema.resolveSwitchItemVal(block, item_ref, Type.bool, item_src);
1369113634 if (Value.fromInterned(item.val).toBool()) {
1369213635 true_count.* += 1;
1369313636 } else {
1369413637 false_count.* += 1;
1369513638 }
1369613639 if (true_count.* > 1 or false_count.* > 1) {
13697 const block_src_decl = sema.mod.declPtr(block.src_decl);
13698 const src = switch_prong_src.resolve(mod, block_src_decl, src_node_offset, .none);
13699 return sema.fail(block, src, "duplicate switch value", .{});
13640 return sema.fail(block, item_src, "duplicate switch value", .{});
1370013641 }
1370113642 return item.ref;
1370213643}
1370313644
13704const ValueSrcMap = std.AutoHashMapUnmanaged(InternPool.Index, Module.SwitchProngSrc);
13645const ValueSrcMap = std.AutoHashMapUnmanaged(InternPool.Index, LazySrcLoc);
1370513646
1370613647fn validateSwitchItemSparse(
1370713648 sema: *Sema,
......@@ -13709,12 +13650,11 @@ fn validateSwitchItemSparse(
1370913650 seen_values: *ValueSrcMap,
1371013651 item_ref: Zir.Inst.Ref,
1371113652 operand_ty: Type,
13712 src_node_offset: i32,
13713 switch_prong_src: Module.SwitchProngSrc,
13653 item_src: LazySrcLoc,
1371413654) CompileError!Air.Inst.Ref {
13715 const item = try sema.resolveSwitchItemVal(block, item_ref, operand_ty, src_node_offset, switch_prong_src, .none);
13716 const kv = (try seen_values.fetchPut(sema.gpa, item.val, switch_prong_src)) orelse return item.ref;
13717 try sema.validateSwitchDupe(block, kv.value, switch_prong_src, src_node_offset);
13655 const item = try sema.resolveSwitchItemVal(block, item_ref, operand_ty, item_src);
13656 const kv = try seen_values.fetchPut(sema.gpa, item.val, item_src) orelse return item.ref;
13657 try sema.validateSwitchDupe(block, kv.value, item_src);
1371813658 unreachable;
1371913659}
1372013660
......@@ -13728,19 +13668,17 @@ fn validateSwitchNoRange(
1372813668 if (ranges_len == 0)
1372913669 return;
1373013670
13731 const operand_src: LazySrcLoc = .{ .node_offset_switch_operand = src_node_offset };
13732 const range_src: LazySrcLoc = .{ .node_offset_switch_range = src_node_offset };
13671 const operand_src = block.src(.{ .node_offset_switch_operand = src_node_offset });
13672 const range_src = block.src(.{ .node_offset_switch_range = src_node_offset });
1373313673
1373413674 const msg = msg: {
1373513675 const msg = try sema.errMsg(
13736 block,
1373713676 operand_src,
1373813677 "ranges not allowed when switching on type '{}'",
1373913678 .{operand_ty.fmt(sema.mod)},
1374013679 );
1374113680 errdefer msg.destroy(sema.gpa);
1374213681 try sema.errNote(
13743 block,
1374413682 range_src,
1374513683 msg,
1374613684 "range here",
......@@ -13867,8 +13805,8 @@ fn zirHasField(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1386713805 const mod = sema.mod;
1386813806 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
1386913807 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
13870 const ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
13871 const name_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };
13808 const ty_src = block.builtinCallArgSrc(inst_data.src_node, 0);
13809 const name_src = block.builtinCallArgSrc(inst_data.src_node, 1);
1387213810 const ty = try sema.resolveType(block, ty_src, extra.lhs);
1387313811 const field_name = try sema.resolveConstStringIntern(block, name_src, extra.rhs, .{
1387413812 .needed_comptime_reason = "field name must be comptime-known",
......@@ -13919,8 +13857,8 @@ fn zirHasDecl(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1391913857 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
1392013858 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
1392113859 const src = block.nodeOffset(inst_data.src_node);
13922 const lhs_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
13923 const rhs_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };
13860 const lhs_src = block.builtinCallArgSrc(inst_data.src_node, 0);
13861 const rhs_src = block.builtinCallArgSrc(inst_data.src_node, 1);
1392413862 const container_type = try sema.resolveType(block, lhs_src, extra.lhs);
1392513863 const decl_name = try sema.resolveConstStringIntern(block, rhs_src, extra.rhs, .{
1392613864 .needed_comptime_reason = "decl name must be comptime-known",
......@@ -13979,7 +13917,7 @@ fn zirEmbedFile(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
1397913917
1398013918 const mod = sema.mod;
1398113919 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
13982 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
13920 const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0);
1398313921 const name = try sema.resolveConstString(block, operand_src, inst_data.operand, .{
1398413922 .needed_comptime_reason = "file path name must be comptime-known",
1398513923 });
......@@ -13988,8 +13926,7 @@ fn zirEmbedFile(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
1398813926 return sema.fail(block, operand_src, "file path name cannot be empty", .{});
1398913927 }
1399013928
13991 const src_loc = mod.declPtr(block.src_decl).toSrcLoc(operand_src, mod);
13992 const val = mod.embedFile(block.getFileScope(mod), name, src_loc) catch |err| switch (err) {
13929 const val = mod.embedFile(block.getFileScope(mod), name, operand_src.upgrade(mod)) catch |err| switch (err) {
1399313930 error.ImportOutsideModulePath => {
1399413931 return sema.fail(block, operand_src, "embed of file outside package path: '{s}'", .{name});
1399513932 },
......@@ -14031,8 +13968,8 @@ fn zirShl(
1403113968 const mod = sema.mod;
1403213969 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
1403313970 const src = block.nodeOffset(inst_data.src_node);
14034 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };
14035 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };
13971 const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node });
13972 const rhs_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node });
1403613973 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
1403713974 const lhs = try sema.resolveInst(extra.lhs);
1403813975 const rhs = try sema.resolveInst(extra.rhs);
......@@ -14201,8 +14138,8 @@ fn zirShr(
1420114138 const mod = sema.mod;
1420214139 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
1420314140 const src = block.nodeOffset(inst_data.src_node);
14204 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };
14205 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };
14141 const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node });
14142 const rhs_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node });
1420614143 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
1420714144 const lhs = try sema.resolveInst(extra.lhs);
1420814145 const rhs = try sema.resolveInst(extra.rhs);
......@@ -14335,9 +14272,9 @@ fn zirBitwise(
1433514272
1433614273 const mod = sema.mod;
1433714274 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
14338 const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node };
14339 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };
14340 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };
14275 const src = block.src(.{ .node_offset_bin_op = inst_data.src_node });
14276 const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node });
14277 const rhs_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node });
1434114278 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
1434214279 const lhs = try sema.resolveInst(extra.lhs);
1434314280 const rhs = try sema.resolveInst(extra.rhs);
......@@ -14390,7 +14327,7 @@ fn zirBitNot(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
1439014327 const mod = sema.mod;
1439114328 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
1439214329 const src = block.nodeOffset(inst_data.src_node);
14393 const operand_src: LazySrcLoc = .{ .node_offset_un_op = inst_data.src_node };
14330 const operand_src = block.src(.{ .node_offset_un_op = inst_data.src_node });
1439414331
1439514332 const operand = try sema.resolveInst(inst_data.operand);
1439614333 const operand_type = sema.typeOf(operand);
......@@ -14436,7 +14373,7 @@ fn analyzeTupleCat(
1443614373 const mod = sema.mod;
1443714374 const lhs_ty = sema.typeOf(lhs);
1443814375 const rhs_ty = sema.typeOf(rhs);
14439 const src = LazySrcLoc.nodeOffset(src_node);
14376 const src = block.nodeOffset(src_node);
1444014377
1444114378 const lhs_len = lhs_ty.structFieldCount(mod);
1444214379 const rhs_len = rhs_ty.structFieldCount(mod);
......@@ -14463,10 +14400,10 @@ fn analyzeTupleCat(
1446314400 types[i] = lhs_ty.structFieldType(i, mod).toIntern();
1446414401 const default_val = lhs_ty.structFieldDefaultValue(i, mod);
1446514402 values[i] = default_val.toIntern();
14466 const operand_src: LazySrcLoc = .{ .array_cat_lhs = .{
14403 const operand_src = block.src(.{ .array_cat_lhs = .{
1446714404 .array_cat_offset = src_node,
1446814405 .elem_index = i,
14469 } };
14406 } });
1447014407 if (default_val.toIntern() == .unreachable_value) {
1447114408 runtime_src = operand_src;
1447214409 values[i] = .none;
......@@ -14477,10 +14414,10 @@ fn analyzeTupleCat(
1447714414 types[i + lhs_len] = rhs_ty.structFieldType(i, mod).toIntern();
1447814415 const default_val = rhs_ty.structFieldDefaultValue(i, mod);
1447914416 values[i + lhs_len] = default_val.toIntern();
14480 const operand_src: LazySrcLoc = .{ .array_cat_rhs = .{
14417 const operand_src = block.src(.{ .array_cat_rhs = .{
1448114418 .array_cat_offset = src_node,
1448214419 .elem_index = i,
14483 } };
14420 } });
1448414421 if (default_val.toIntern() == .unreachable_value) {
1448514422 runtime_src = operand_src;
1448614423 values[i + lhs_len] = .none;
......@@ -14508,18 +14445,18 @@ fn analyzeTupleCat(
1450814445 const element_refs = try sema.arena.alloc(Air.Inst.Ref, final_len);
1450914446 var i: u32 = 0;
1451014447 while (i < lhs_len) : (i += 1) {
14511 const operand_src: LazySrcLoc = .{ .array_cat_lhs = .{
14448 const operand_src = block.src(.{ .array_cat_lhs = .{
1451214449 .array_cat_offset = src_node,
1451314450 .elem_index = i,
14514 } };
14451 } });
1451514452 element_refs[i] = try sema.tupleFieldValByIndex(block, operand_src, lhs, i, lhs_ty);
1451614453 }
1451714454 i = 0;
1451814455 while (i < rhs_len) : (i += 1) {
14519 const operand_src: LazySrcLoc = .{ .array_cat_rhs = .{
14456 const operand_src = block.src(.{ .array_cat_rhs = .{
1452014457 .array_cat_offset = src_node,
1452114458 .elem_index = i,
14522 } };
14459 } });
1452314460 element_refs[i + lhs_len] =
1452414461 try sema.tupleFieldValByIndex(block, operand_src, rhs, i, rhs_ty);
1452514462 }
......@@ -14546,8 +14483,8 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1454614483 return sema.analyzeTupleCat(block, inst_data.src_node, lhs, rhs);
1454714484 }
1454814485
14549 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };
14550 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };
14486 const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node });
14487 const rhs_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node });
1455114488
1455214489 const lhs_info = try sema.getArrayCatInfo(block, lhs_src, lhs, rhs_ty) orelse lhs_info: {
1455314490 if (lhs_is_tuple) break :lhs_info @as(Type.ArrayInfo, undefined);
......@@ -14659,10 +14596,10 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1465914596 const elem_default_val = if (lhs_is_tuple) lhs_ty.structFieldDefaultValue(lhs_elem_i, mod) else Value.@"unreachable";
1466014597 const elem_val = if (elem_default_val.toIntern() == .unreachable_value) try lhs_sub_val.elemValue(mod, lhs_elem_i) else elem_default_val;
1466114598 const elem_val_inst = Air.internedToRef(elem_val.toIntern());
14662 const operand_src: LazySrcLoc = .{ .array_cat_lhs = .{
14599 const operand_src = block.src(.{ .array_cat_lhs = .{
1466314600 .array_cat_offset = inst_data.src_node,
1466414601 .elem_index = elem_i,
14665 } };
14602 } });
1466614603 const coerced_elem_val_inst = try sema.coerce(block, resolved_elem_ty, elem_val_inst, operand_src);
1466714604 const coerced_elem_val = try sema.resolveConstValue(block, operand_src, coerced_elem_val_inst, undefined);
1466814605 element_vals[elem_i] = coerced_elem_val.toIntern();
......@@ -14672,10 +14609,10 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1467214609 const elem_default_val = if (rhs_is_tuple) rhs_ty.structFieldDefaultValue(rhs_elem_i, mod) else Value.@"unreachable";
1467314610 const elem_val = if (elem_default_val.toIntern() == .unreachable_value) try rhs_sub_val.elemValue(mod, rhs_elem_i) else elem_default_val;
1467414611 const elem_val_inst = Air.internedToRef(elem_val.toIntern());
14675 const operand_src: LazySrcLoc = .{ .array_cat_rhs = .{
14612 const operand_src = block.src(.{ .array_cat_rhs = .{
1467614613 .array_cat_offset = inst_data.src_node,
1467714614 .elem_index = @intCast(rhs_elem_i),
14678 } };
14615 } });
1467914616 const coerced_elem_val_inst = try sema.coerce(block, resolved_elem_ty, elem_val_inst, operand_src);
1468014617 const coerced_elem_val = try sema.resolveConstValue(block, operand_src, coerced_elem_val_inst, undefined);
1468114618 element_vals[elem_i] = coerced_elem_val.toIntern();
......@@ -14704,10 +14641,10 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1470414641 while (elem_i < lhs_len) : (elem_i += 1) {
1470514642 const elem_index = try mod.intRef(Type.usize, elem_i);
1470614643 const elem_ptr = try block.addPtrElemPtr(alloc, elem_index, elem_ptr_ty);
14707 const operand_src: LazySrcLoc = .{ .array_cat_lhs = .{
14644 const operand_src = block.src(.{ .array_cat_lhs = .{
1470814645 .array_cat_offset = inst_data.src_node,
1470914646 .elem_index = elem_i,
14710 } };
14647 } });
1471114648 const init = try sema.elemVal(block, operand_src, lhs, elem_index, src, true);
1471214649 try sema.storePtr2(block, src, elem_ptr, src, init, operand_src, .store);
1471314650 }
......@@ -14716,10 +14653,10 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1471614653 const elem_index = try mod.intRef(Type.usize, elem_i);
1471714654 const rhs_index = try mod.intRef(Type.usize, rhs_elem_i);
1471814655 const elem_ptr = try block.addPtrElemPtr(alloc, elem_index, elem_ptr_ty);
14719 const operand_src: LazySrcLoc = .{ .array_cat_rhs = .{
14656 const operand_src = block.src(.{ .array_cat_rhs = .{
1472014657 .array_cat_offset = inst_data.src_node,
1472114658 .elem_index = @intCast(rhs_elem_i),
14722 } };
14659 } });
1472314660 const init = try sema.elemVal(block, operand_src, rhs, rhs_index, src, true);
1472414661 try sema.storePtr2(block, src, elem_ptr, src, init, operand_src, .store);
1472514662 }
......@@ -14738,20 +14675,20 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1473814675 var elem_i: u32 = 0;
1473914676 while (elem_i < lhs_len) : (elem_i += 1) {
1474014677 const index = try mod.intRef(Type.usize, elem_i);
14741 const operand_src: LazySrcLoc = .{ .array_cat_lhs = .{
14678 const operand_src = block.src(.{ .array_cat_lhs = .{
1474214679 .array_cat_offset = inst_data.src_node,
1474314680 .elem_index = elem_i,
14744 } };
14681 } });
1474514682 const init = try sema.elemVal(block, operand_src, lhs, index, src, true);
1474614683 element_refs[elem_i] = try sema.coerce(block, resolved_elem_ty, init, operand_src);
1474714684 }
1474814685 while (elem_i < result_len) : (elem_i += 1) {
1474914686 const rhs_elem_i = elem_i - lhs_len;
1475014687 const index = try mod.intRef(Type.usize, rhs_elem_i);
14751 const operand_src: LazySrcLoc = .{ .array_cat_rhs = .{
14688 const operand_src = block.src(.{ .array_cat_rhs = .{
1475214689 .array_cat_offset = inst_data.src_node,
1475314690 .elem_index = @intCast(rhs_elem_i),
14754 } };
14691 } });
1475514692 const init = try sema.elemVal(block, operand_src, rhs, index, src, true);
1475614693 element_refs[elem_i] = try sema.coerce(block, resolved_elem_ty, init, operand_src);
1475714694 }
......@@ -14813,8 +14750,8 @@ fn analyzeTupleMul(
1481314750) CompileError!Air.Inst.Ref {
1481414751 const mod = sema.mod;
1481514752 const operand_ty = sema.typeOf(operand);
14816 const src = LazySrcLoc.nodeOffset(src_node);
14817 const len_src: LazySrcLoc = .{ .node_offset_bin_rhs = src_node };
14753 const src = block.nodeOffset(src_node);
14754 const len_src = block.src(.{ .node_offset_bin_rhs = src_node });
1481814755
1481914756 const tuple_len = operand_ty.structFieldCount(mod);
1482014757 const final_len = std.math.mul(usize, tuple_len, factor) catch
......@@ -14831,10 +14768,10 @@ fn analyzeTupleMul(
1483114768 for (0..tuple_len) |i| {
1483214769 types[i] = operand_ty.structFieldType(i, mod).toIntern();
1483314770 values[i] = operand_ty.structFieldDefaultValue(i, mod).toIntern();
14834 const operand_src: LazySrcLoc = .{ .array_cat_lhs = .{
14771 const operand_src = block.src(.{ .array_cat_lhs = .{
1483514772 .array_cat_offset = src_node,
1483614773 .elem_index = @intCast(i),
14837 } };
14774 } });
1483814775 if (values[i] == .unreachable_value) {
1483914776 runtime_src = operand_src;
1484014777 values[i] = .none; // TODO don't treat unreachable_value as special
......@@ -14866,10 +14803,10 @@ fn analyzeTupleMul(
1486614803 const element_refs = try sema.arena.alloc(Air.Inst.Ref, final_len);
1486714804 var i: u32 = 0;
1486814805 while (i < tuple_len) : (i += 1) {
14869 const operand_src: LazySrcLoc = .{ .array_cat_lhs = .{
14806 const operand_src = block.src(.{ .array_cat_lhs = .{
1487014807 .array_cat_offset = src_node,
1487114808 .elem_index = i,
14872 } };
14809 } });
1487314810 element_refs[i] = try sema.tupleFieldValByIndex(block, operand_src, operand, @intCast(i), operand_ty);
1487414811 }
1487514812 i = 1;
......@@ -14890,9 +14827,9 @@ fn zirArrayMul(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1489014827 const uncoerced_lhs = try sema.resolveInst(extra.lhs);
1489114828 const uncoerced_lhs_ty = sema.typeOf(uncoerced_lhs);
1489214829 const src: LazySrcLoc = block.nodeOffset(inst_data.src_node);
14893 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };
14894 const operator_src: LazySrcLoc = .{ .node_offset_main_token = inst_data.src_node };
14895 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };
14830 const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node });
14831 const operator_src = block.src(.{ .node_offset_main_token = inst_data.src_node });
14832 const rhs_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node });
1489614833
1489714834 const lhs, const lhs_ty = coerced_lhs: {
1489814835 // If we have a result type, we might be able to do this more efficiently
......@@ -14941,11 +14878,11 @@ fn zirArrayMul(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1494114878 // Analyze the lhs first, to catch the case that someone tried to do exponentiation
1494214879 const lhs_info = try sema.getArrayCatInfo(block, lhs_src, lhs, lhs_ty) orelse {
1494314880 const msg = msg: {
14944 const msg = try sema.errMsg(block, lhs_src, "expected indexable; found '{}'", .{lhs_ty.fmt(mod)});
14881 const msg = try sema.errMsg(lhs_src, "expected indexable; found '{}'", .{lhs_ty.fmt(mod)});
1494514882 errdefer msg.destroy(sema.gpa);
1494614883 switch (lhs_ty.zigTypeTag(mod)) {
1494714884 .Int, .Float, .ComptimeFloat, .ComptimeInt, .Vector => {
14948 try sema.errNote(block, operator_src, msg, "this operator multiplies arrays; use std.math.pow for exponentiation", .{});
14885 try sema.errNote(operator_src, msg, "this operator multiplies arrays; use std.math.pow for exponentiation", .{});
1494914886 },
1495014887 else => {},
1495114888 }
......@@ -15061,7 +14998,7 @@ fn zirNegate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
1506114998 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
1506214999 const src = block.nodeOffset(inst_data.src_node);
1506315000 const lhs_src = src;
15064 const rhs_src: LazySrcLoc = .{ .node_offset_un_op = inst_data.src_node };
15001 const rhs_src = block.src(.{ .node_offset_un_op = inst_data.src_node });
1506515002
1506615003 const rhs = try sema.resolveInst(inst_data.operand);
1506715004 const rhs_ty = sema.typeOf(rhs);
......@@ -15093,7 +15030,7 @@ fn zirNegateWrap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
1509315030 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
1509415031 const src = block.nodeOffset(inst_data.src_node);
1509515032 const lhs_src = src;
15096 const rhs_src: LazySrcLoc = .{ .node_offset_un_op = inst_data.src_node };
15033 const rhs_src = block.src(.{ .node_offset_un_op = inst_data.src_node });
1509715034
1509815035 const rhs = try sema.resolveInst(inst_data.operand);
1509915036 const rhs_ty = sema.typeOf(rhs);
......@@ -15119,9 +15056,9 @@ fn zirArithmetic(
1511915056 defer tracy.end();
1512015057
1512115058 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
15122 const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node };
15123 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };
15124 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };
15059 const src = block.src(.{ .node_offset_bin_op = inst_data.src_node });
15060 const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node });
15061 const rhs_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node });
1512515062 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
1512615063 const lhs = try sema.resolveInst(extra.lhs);
1512715064 const rhs = try sema.resolveInst(extra.rhs);
......@@ -15132,9 +15069,9 @@ fn zirArithmetic(
1513215069fn zirDiv(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
1513315070 const mod = sema.mod;
1513415071 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
15135 const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node };
15136 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };
15137 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };
15072 const src = block.src(.{ .node_offset_bin_op = inst_data.src_node });
15073 const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node });
15074 const rhs_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node });
1513815075 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
1513915076 const lhs = try sema.resolveInst(extra.lhs);
1514015077 const rhs = try sema.resolveInst(extra.rhs);
......@@ -15297,9 +15234,9 @@ fn zirDiv(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins
1529715234fn zirDivExact(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
1529815235 const mod = sema.mod;
1529915236 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
15300 const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node };
15301 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };
15302 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };
15237 const src = block.src(.{ .node_offset_bin_op = inst_data.src_node });
15238 const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node });
15239 const rhs_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node });
1530315240 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
1530415241 const lhs = try sema.resolveInst(extra.lhs);
1530515242 const rhs = try sema.resolveInst(extra.rhs);
......@@ -15462,9 +15399,9 @@ fn zirDivExact(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1546215399fn zirDivFloor(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
1546315400 const mod = sema.mod;
1546415401 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
15465 const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node };
15466 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };
15467 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };
15402 const src = block.src(.{ .node_offset_bin_op = inst_data.src_node });
15403 const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node });
15404 const rhs_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node });
1546815405 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
1546915406 const lhs = try sema.resolveInst(extra.lhs);
1547015407 const rhs = try sema.resolveInst(extra.rhs);
......@@ -15572,9 +15509,9 @@ fn zirDivFloor(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1557215509fn zirDivTrunc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
1557315510 const mod = sema.mod;
1557415511 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
15575 const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node };
15576 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };
15577 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };
15512 const src = block.src(.{ .node_offset_bin_op = inst_data.src_node });
15513 const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node });
15514 const rhs_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node });
1557815515 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
1557915516 const lhs = try sema.resolveInst(extra.lhs);
1558015517 const rhs = try sema.resolveInst(extra.rhs);
......@@ -15813,9 +15750,9 @@ fn airTag(block: *Block, is_int: bool, normal: Air.Inst.Tag, optimized: Air.Inst
1581315750fn zirModRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
1581415751 const mod = sema.mod;
1581515752 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
15816 const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node };
15817 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };
15818 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };
15753 const src = block.src(.{ .node_offset_bin_op = inst_data.src_node });
15754 const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node });
15755 const rhs_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node });
1581915756 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
1582015757 const lhs = try sema.resolveInst(extra.lhs);
1582115758 const rhs = try sema.resolveInst(extra.rhs);
......@@ -15997,9 +15934,9 @@ fn intRemScalar(sema: *Sema, lhs: Value, rhs: Value, scalar_ty: Type) CompileErr
1599715934fn zirMod(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
1599815935 const mod = sema.mod;
1599915936 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
16000 const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node };
16001 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };
16002 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };
15937 const src = block.src(.{ .node_offset_bin_op = inst_data.src_node });
15938 const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node });
15939 const rhs_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node });
1600315940 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
1600415941 const lhs = try sema.resolveInst(extra.lhs);
1600515942 const rhs = try sema.resolveInst(extra.rhs);
......@@ -16092,9 +16029,9 @@ fn zirMod(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins
1609216029fn zirRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
1609316030 const mod = sema.mod;
1609416031 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
16095 const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node };
16096 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };
16097 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };
16032 const src = block.src(.{ .node_offset_bin_op = inst_data.src_node });
16033 const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node });
16034 const rhs_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node });
1609816035 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
1609916036 const lhs = try sema.resolveInst(extra.lhs);
1610016037 const rhs = try sema.resolveInst(extra.rhs);
......@@ -16194,10 +16131,10 @@ fn zirOverflowArithmetic(
1619416131 defer tracy.end();
1619516132
1619616133 const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data;
16197 const src = LazySrcLoc.nodeOffset(extra.node);
16134 const src = block.nodeOffset(extra.node);
1619816135
16199 const lhs_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node };
16200 const rhs_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = extra.node };
16136 const lhs_src = block.builtinCallArgSrc(extra.node, 0);
16137 const rhs_src = block.builtinCallArgSrc(extra.node, 1);
1620116138
1620216139 const uncasted_lhs = try sema.resolveInst(extra.lhs);
1620316140 const uncasted_rhs = try sema.resolveInst(extra.rhs);
......@@ -17025,8 +16962,8 @@ fn zirAsm(
1702516962 defer tracy.end();
1702616963
1702716964 const extra = sema.code.extraData(Zir.Inst.Asm, extended.operand);
17028 const src = LazySrcLoc.nodeOffset(extra.data.src_node);
17029 const ret_ty_src: LazySrcLoc = .{ .node_offset_asm_ret_ty = extra.data.src_node };
16965 const src = block.nodeOffset(extra.data.src_node);
16966 const ret_ty_src = block.src(.{ .node_offset_asm_ret_ty = extra.data.src_node });
1703016967 const outputs_len: u5 = @truncate(extended.small);
1703116968 const inputs_len: u5 = @truncate(extended.small >> 5);
1703216969 const clobbers_len: u5 = @truncate(extended.small >> 10);
......@@ -17200,8 +17137,8 @@ fn zirCmpEq(
1720017137 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
1720117138 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
1720217139 const src: LazySrcLoc = block.nodeOffset(inst_data.src_node);
17203 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };
17204 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };
17140 const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node });
17141 const rhs_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node });
1720517142 const lhs = try sema.resolveInst(extra.lhs);
1720617143 const rhs = try sema.resolveInst(extra.rhs);
1720717144
......@@ -17280,9 +17217,9 @@ fn analyzeCmpUnionTag(
1728017217 try sema.resolveTypeFields(union_ty);
1728117218 const union_tag_ty = union_ty.unionTagType(mod) orelse {
1728217219 const msg = msg: {
17283 const msg = try sema.errMsg(block, un_src, "comparison of union and enum literal is only valid for tagged union types", .{});
17220 const msg = try sema.errMsg(un_src, "comparison of union and enum literal is only valid for tagged union types", .{});
1728417221 errdefer msg.destroy(sema.gpa);
17285 try mod.errNoteNonLazy(union_ty.declSrcLoc(mod), msg, "union '{}' is not a tagged union", .{union_ty.fmt(mod)});
17222 try sema.errNote(union_ty.srcLoc(mod), msg, "union '{}' is not a tagged union", .{union_ty.fmt(mod)});
1728617223 break :msg msg;
1728717224 };
1728817225 return sema.failWithOwnedErrorMsg(block, msg);
......@@ -17316,8 +17253,8 @@ fn zirCmp(
1731617253 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
1731717254 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
1731817255 const src: LazySrcLoc = block.nodeOffset(inst_data.src_node);
17319 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };
17320 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };
17256 const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node });
17257 const rhs_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node });
1732117258 const lhs = try sema.resolveInst(extra.lhs);
1732217259 const rhs = try sema.resolveInst(extra.rhs);
1732317260 return sema.analyzeCmp(block, src, lhs, rhs, op, lhs_src, rhs_src, false);
......@@ -17459,7 +17396,7 @@ fn runtimeBoolCmp(
1745917396fn zirSizeOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
1746017397 const mod = sema.mod;
1746117398 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
17462 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
17399 const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0);
1746317400 const ty = try sema.resolveType(block, operand_src, inst_data.operand);
1746417401 switch (ty.zigTypeTag(mod)) {
1746517402 .Fn,
......@@ -17502,7 +17439,7 @@ fn zirSizeOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
1750217439fn zirBitSizeOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
1750317440 const mod = sema.mod;
1750417441 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
17505 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
17442 const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0);
1750617443 const operand_ty = try sema.resolveType(block, operand_src, inst_data.operand);
1750717444 switch (operand_ty.zigTypeTag(mod)) {
1750817445 .Fn,
......@@ -17546,7 +17483,7 @@ fn zirThis(
1754617483) CompileError!Air.Inst.Ref {
1754717484 const mod = sema.mod;
1754817485 const this_decl_index = mod.namespacePtr(block.namespace).decl_index;
17549 const src = LazySrcLoc.nodeOffset(@bitCast(extended.operand));
17486 const src = block.nodeOffset(@bitCast(extended.operand));
1755017487 return sema.analyzeDeclVal(block, src, this_decl_index);
1755117488}
1755217489
......@@ -17556,7 +17493,7 @@ fn zirClosureGet(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat
1755617493 const captures = mod.namespacePtr(block.namespace).getType(mod).getCaptures(mod);
1755717494
1755817495 const src_node: i32 = @bitCast(extended.operand);
17559 const src = LazySrcLoc.nodeOffset(src_node);
17496 const src = block.nodeOffset(src_node);
1756017497
1756117498 const capture_ty = switch (captures.get(ip)[extended.small].unwrap()) {
1756217499 .@"comptime" => |index| return Air.internedToRef(index),
......@@ -17570,7 +17507,8 @@ fn zirClosureGet(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat
1757017507 if (!block.is_typeof and sema.func_index == .none) {
1757117508 const msg = msg: {
1757217509 const name = name: {
17573 const file = sema.owner_decl.getFileScope(mod);
17510 // TODO: we should probably store this name in the ZIR to avoid this complexity.
17511 const file, const src_base_node = Module.LazySrcLoc.resolveBaseNode(block.src_base_inst, mod);
1757417512 const tree = file.getTree(sema.gpa) catch |err| {
1757517513 // In this case we emit a warning + a less precise source location.
1757617514 log.warn("unable to load {s}: {s}", .{
......@@ -17578,15 +17516,15 @@ fn zirClosureGet(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat
1757817516 });
1757917517 break :name null;
1758017518 };
17581 const node = sema.owner_decl.relativeToNodeIndex(src_node);
17519 const node: std.zig.Ast.Node.Index = @bitCast(src_node + @as(i32, @bitCast(src_base_node)));
1758217520 const token = tree.nodes.items(.main_token)[node];
1758317521 break :name tree.tokenSlice(token);
1758417522 };
1758517523
1758617524 const msg = if (name) |some|
17587 try sema.errMsg(block, src, "'{s}' not accessible outside function scope", .{some})
17525 try sema.errMsg(src, "'{s}' not accessible outside function scope", .{some})
1758817526 else
17589 try sema.errMsg(block, src, "variable not accessible outside function scope", .{});
17527 try sema.errMsg(src, "variable not accessible outside function scope", .{});
1759017528 errdefer msg.destroy(sema.gpa);
1759117529
1759217530 // TODO add "declared here" note
......@@ -17598,7 +17536,7 @@ fn zirClosureGet(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat
1759817536 if (!block.is_typeof and !block.is_comptime and sema.func_index != .none) {
1759917537 const msg = msg: {
1760017538 const name = name: {
17601 const file = sema.owner_decl.getFileScope(mod);
17539 const file, const src_base_node = Module.LazySrcLoc.resolveBaseNode(block.src_base_inst, mod);
1760217540 const tree = file.getTree(sema.gpa) catch |err| {
1760317541 // In this case we emit a warning + a less precise source location.
1760417542 log.warn("unable to load {s}: {s}", .{
......@@ -17606,18 +17544,18 @@ fn zirClosureGet(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat
1760617544 });
1760717545 break :name null;
1760817546 };
17609 const node = sema.owner_decl.relativeToNodeIndex(src_node);
17547 const node: std.zig.Ast.Node.Index = @bitCast(src_node + @as(i32, @bitCast(src_base_node)));
1761017548 const token = tree.nodes.items(.main_token)[node];
1761117549 break :name tree.tokenSlice(token);
1761217550 };
1761317551
1761417552 const msg = if (name) |some|
17615 try sema.errMsg(block, src, "'{s}' not accessible from inner function", .{some})
17553 try sema.errMsg(src, "'{s}' not accessible from inner function", .{some})
1761617554 else
17617 try sema.errMsg(block, src, "variable not accessible from inner function", .{});
17555 try sema.errMsg(src, "variable not accessible from inner function", .{});
1761817556 errdefer msg.destroy(sema.gpa);
1761917557
17620 try sema.errNote(block, LazySrcLoc.nodeOffset(0), msg, "crossed function definition here", .{});
17558 try sema.errNote(block.nodeOffset(0), msg, "crossed function definition here", .{});
1762117559
1762217560 // TODO add "declared here" note
1762317561 break :msg msg;
......@@ -17649,7 +17587,7 @@ fn zirFrameAddress(
1764917587 block: *Block,
1765017588 extended: Zir.Inst.Extended.InstData,
1765117589) CompileError!Air.Inst.Ref {
17652 const src = LazySrcLoc.nodeOffset(@bitCast(extended.operand));
17590 const src = block.nodeOffset(@bitCast(extended.operand));
1765317591 try sema.requireRuntimeBlock(block, src, null);
1765417592 return try block.addNoOp(.frame_addr);
1765517593}
......@@ -18913,6 +18851,7 @@ fn zirTypeofBuiltin(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr
1891318851 .is_typeof = true,
1891418852 .want_safety = false,
1891518853 .error_return_trace_index = block.error_return_trace_index,
18854 .src_base_inst = block.src_base_inst,
1891618855 };
1891718856 defer child_block.instructions.deinit(sema.gpa);
1891818857
......@@ -18977,7 +18916,7 @@ fn zirTypeofPeer(
1897718916 defer tracy.end();
1897818917
1897918918 const extra = sema.code.extraData(Zir.Inst.TypeOfPeer, extended.operand);
18980 const src = LazySrcLoc.nodeOffset(extra.data.src_node);
18919 const src = block.nodeOffset(extra.data.src_node);
1898118920 const body = sema.code.bodySlice(extra.data.body_index, extra.data.body_len);
1898218921
1898318922 var child_block: Block = .{
......@@ -18992,6 +18931,7 @@ fn zirTypeofPeer(
1899218931 .runtime_cond = block.runtime_cond,
1899318932 .runtime_loop = block.runtime_loop,
1899418933 .runtime_index = block.runtime_index,
18934 .src_base_inst = block.src_base_inst,
1899518935 };
1899618936 defer child_block.instructions.deinit(sema.gpa);
1899718937 // Ignore the result, we only care about the instructions in `args`.
......@@ -19017,7 +18957,7 @@ fn zirBoolNot(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1901718957 const mod = sema.mod;
1901818958 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
1901918959 const src = block.nodeOffset(inst_data.src_node);
19020 const operand_src: LazySrcLoc = .{ .node_offset_un_op = inst_data.src_node };
18960 const operand_src = block.src(.{ .node_offset_un_op = inst_data.src_node });
1902118961 const uncasted_operand = try sema.resolveInst(inst_data.operand);
1902218962
1902318963 const operand = try sema.coerce(block, Type.bool, uncasted_operand, operand_src);
......@@ -19048,8 +18988,8 @@ fn zirBoolBr(
1904818988
1904918989 const uncoerced_lhs = try sema.resolveInst(extra.data.lhs);
1905018990 const body = sema.code.bodySlice(extra.end, extra.data.body_len);
19051 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };
19052 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };
18991 const lhs_src = parent_block.src(.{ .node_offset_bin_lhs = inst_data.src_node });
18992 const rhs_src = parent_block.src(.{ .node_offset_bin_rhs = inst_data.src_node });
1905318993
1905418994 const lhs = try sema.coerce(parent_block, Type.bool, uncoerced_lhs, lhs_src);
1905518995
......@@ -19080,7 +19020,7 @@ fn zirBoolBr(
1908019020
1908119021 var child_block = parent_block.makeSubBlock();
1908219022 child_block.runtime_loop = null;
19083 child_block.runtime_cond = mod.declPtr(child_block.src_decl).toSrcLoc(lhs_src, mod);
19023 child_block.runtime_cond = lhs_src;
1908419024 child_block.runtime_index.increment();
1908519025 defer child_block.instructions.deinit(gpa);
1908619026
......@@ -19253,7 +19193,7 @@ fn zirCondbr(
1925319193
1925419194 const mod = sema.mod;
1925519195 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
19256 const cond_src: LazySrcLoc = .{ .node_offset_if_cond = inst_data.src_node };
19196 const cond_src = parent_block.src(.{ .node_offset_if_cond = inst_data.src_node });
1925719197 const extra = sema.code.extraData(Zir.Inst.CondBr, inst_data.payload_index);
1925819198
1925919199 const then_body = sema.code.bodySlice(extra.end, extra.data.then_body_len);
......@@ -19276,7 +19216,7 @@ fn zirCondbr(
1927619216 // instructions array in between using it for the then block and else block.
1927719217 var sub_block = parent_block.makeSubBlock();
1927819218 sub_block.runtime_loop = null;
19279 sub_block.runtime_cond = mod.declPtr(parent_block.src_decl).toSrcLoc(cond_src, mod);
19219 sub_block.runtime_cond = cond_src;
1928019220 sub_block.runtime_index.increment();
1928119221 sub_block.need_debug_scope = null; // this body is emitted regardless
1928219222 defer sub_block.instructions.deinit(gpa);
......@@ -19321,7 +19261,7 @@ fn zirCondbr(
1932119261fn zirTry(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
1932219262 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
1932319263 const src = parent_block.nodeOffset(inst_data.src_node);
19324 const operand_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };
19264 const operand_src = parent_block.src(.{ .node_offset_bin_lhs = inst_data.src_node });
1932519265 const extra = sema.code.extraData(Zir.Inst.Try, inst_data.payload_index);
1932619266 const body = sema.code.bodySlice(extra.end, extra.data.body_len);
1932719267 const err_union = try sema.resolveInst(extra.data.operand);
......@@ -19368,7 +19308,7 @@ fn zirTry(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError!
1936819308fn zirTryPtr(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
1936919309 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
1937019310 const src = parent_block.nodeOffset(inst_data.src_node);
19371 const operand_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };
19311 const operand_src = parent_block.src(.{ .node_offset_bin_lhs = inst_data.src_node });
1937219312 const extra = sema.code.extraData(Zir.Inst.Try, inst_data.payload_index);
1937319313 const body = sema.code.bodySlice(extra.end, extra.data.body_len);
1937419314 const operand = try sema.resolveInst(extra.data.operand);
......@@ -19464,6 +19404,7 @@ fn ensurePostHoc(sema: *Sema, block: *Block, dest_block: Zir.Inst.Index) !*Label
1946419404 .label = &labeled_block.label,
1946519405 .inlining = block.inlining,
1946619406 .is_comptime = block.is_comptime,
19407 .src_base_inst = block.src_base_inst,
1946719408 },
1946819409 };
1946919410 sema.post_hoc_blocks.putAssumeCapacityNoClobber(new_block_inst, labeled_block);
......@@ -19498,11 +19439,11 @@ fn zirUnreachable(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
1949819439 return sema.fail(block, src, "reached unreachable code", .{});
1949919440 }
1950019441 // TODO Add compile error for @optimizeFor occurring too late in a scope.
19501 block.addUnreachable(src, true) catch |err| switch (err) {
19442 sema.analyzeUnreachable(block, src, true) catch |err| switch (err) {
1950219443 error.AnalysisFail => {
1950319444 const msg = sema.err orelse return err;
1950419445 if (!mem.eql(u8, msg.msg, "runtime safety check not allowed in naked function")) return err;
19505 try sema.errNote(block, src, msg, "the end of a naked function is implicitly unreachable", .{});
19446 try sema.errNote(src, msg, "the end of a naked function is implicitly unreachable", .{});
1950619447 return err;
1950719448 },
1950819449 else => |e| return e,
......@@ -19549,31 +19490,31 @@ fn zirRetImplicit(
1954919490 // Calling a safety function from a naked function would not be legal.
1955019491 _ = try block.addNoOp(.trap);
1955119492 } else {
19552 try block.addUnreachable(r_brace_src, false);
19493 try sema.analyzeUnreachable(block, r_brace_src, false);
1955319494 }
1955419495 return;
1955519496 }
1955619497
1955719498 const operand = try sema.resolveInst(inst_data.operand);
19558 const ret_ty_src: LazySrcLoc = .{ .node_offset_fn_type_ret_ty = 0 };
19499 const ret_ty_src = block.src(.{ .node_offset_fn_type_ret_ty = 0 });
1955919500 const base_tag = sema.fn_ret_ty.baseZigTypeTag(mod);
1956019501 if (base_tag == .NoReturn) {
1956119502 const msg = msg: {
19562 const msg = try sema.errMsg(block, ret_ty_src, "function declared '{}' implicitly returns", .{
19503 const msg = try sema.errMsg(ret_ty_src, "function declared '{}' implicitly returns", .{
1956319504 sema.fn_ret_ty.fmt(mod),
1956419505 });
1956519506 errdefer msg.destroy(sema.gpa);
19566 try sema.errNote(block, r_brace_src, msg, "control flow reaches end of body here", .{});
19507 try sema.errNote(r_brace_src, msg, "control flow reaches end of body here", .{});
1956719508 break :msg msg;
1956819509 };
1956919510 return sema.failWithOwnedErrorMsg(block, msg);
1957019511 } else if (base_tag != .Void) {
1957119512 const msg = msg: {
19572 const msg = try sema.errMsg(block, ret_ty_src, "function with non-void return type '{}' implicitly returns", .{
19513 const msg = try sema.errMsg(ret_ty_src, "function with non-void return type '{}' implicitly returns", .{
1957319514 sema.fn_ret_ty.fmt(mod),
1957419515 });
1957519516 errdefer msg.destroy(sema.gpa);
19576 try sema.errNote(block, r_brace_src, msg, "control flow reaches end of body here", .{});
19517 try sema.errNote(r_brace_src, msg, "control flow reaches end of body here", .{});
1957719518 break :msg msg;
1957819519 };
1957919520 return sema.failWithOwnedErrorMsg(block, msg);
......@@ -19590,7 +19531,7 @@ fn zirRetNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!voi
1959019531 const operand = try sema.resolveInst(inst_data.operand);
1959119532 const src = block.nodeOffset(inst_data.src_node);
1959219533
19593 return sema.analyzeRet(block, operand, src, .{ .node_offset_return_operand = inst_data.src_node });
19534 return sema.analyzeRet(block, operand, src, block.src(.{ .node_offset_return_operand = inst_data.src_node }));
1959419535}
1959519536
1959619537fn zirRetLoad(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void {
......@@ -19603,7 +19544,7 @@ fn zirRetLoad(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!voi
1960319544
1960419545 if (block.is_comptime or block.inlining != null or sema.func_is_naked) {
1960519546 const operand = try sema.analyzeLoad(block, src, ret_ptr, src);
19606 return sema.analyzeRet(block, operand, src, .{ .node_offset_return_operand = inst_data.src_node });
19547 return sema.analyzeRet(block, operand, src, block.src(.{ .node_offset_return_operand = inst_data.src_node }));
1960719548 }
1960819549
1960919550 if (sema.wantErrorReturnTracing(sema.fn_ret_ty)) {
......@@ -19816,9 +19757,7 @@ fn analyzeRet(
1981619757 inlining.comptime_result = operand;
1981719758
1981819759 if (sema.fn_ret_ty.isError(mod) and ret_val.getErrorName(mod) != .none) {
19819 const src_decl = mod.declPtr(block.src_decl);
19820 const src_loc = src_decl.toSrcLoc(src, mod);
19821 try sema.comptime_err_ret_trace.append(src_loc);
19760 try sema.comptime_err_ret_trace.append(src);
1982219761 }
1982319762 return error.ComptimeReturn;
1982419763 }
......@@ -19832,10 +19771,10 @@ fn analyzeRet(
1983219771 return sema.fail(block, src, "function called at runtime cannot return value at comptime", .{});
1983319772 } else if (sema.func_is_naked) {
1983419773 const msg = msg: {
19835 const msg = try sema.errMsg(block, src, "cannot return from naked function", .{});
19774 const msg = try sema.errMsg(src, "cannot return from naked function", .{});
1983619775 errdefer msg.destroy(sema.gpa);
1983719776
19838 try sema.errNote(block, src, msg, "can only return using assembly", .{});
19777 try sema.errNote(src, msg, "can only return using assembly", .{});
1983919778 break :msg msg;
1984019779 };
1984119780 return sema.failWithOwnedErrorMsg(block, msg);
......@@ -19871,18 +19810,18 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1987119810 const mod = sema.mod;
1987219811 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].ptr_type;
1987319812 const extra = sema.code.extraData(Zir.Inst.PtrType, inst_data.payload_index);
19874 const elem_ty_src: LazySrcLoc = .{ .node_offset_ptr_elem = extra.data.src_node };
19875 const sentinel_src: LazySrcLoc = .{ .node_offset_ptr_sentinel = extra.data.src_node };
19876 const align_src: LazySrcLoc = .{ .node_offset_ptr_align = extra.data.src_node };
19877 const addrspace_src: LazySrcLoc = .{ .node_offset_ptr_addrspace = extra.data.src_node };
19878 const bitoffset_src: LazySrcLoc = .{ .node_offset_ptr_bitoffset = extra.data.src_node };
19879 const hostsize_src: LazySrcLoc = .{ .node_offset_ptr_hostsize = extra.data.src_node };
19813 const elem_ty_src = block.src(.{ .node_offset_ptr_elem = extra.data.src_node });
19814 const sentinel_src = block.src(.{ .node_offset_ptr_sentinel = extra.data.src_node });
19815 const align_src = block.src(.{ .node_offset_ptr_align = extra.data.src_node });
19816 const addrspace_src = block.src(.{ .node_offset_ptr_addrspace = extra.data.src_node });
19817 const bitoffset_src = block.src(.{ .node_offset_ptr_bitoffset = extra.data.src_node });
19818 const hostsize_src = block.src(.{ .node_offset_ptr_hostsize = extra.data.src_node });
1988019819
1988119820 const elem_ty = blk: {
1988219821 const air_inst = try sema.resolveInst(extra.data.elem_type);
1988319822 const ty = sema.analyzeAsType(block, elem_ty_src, air_inst) catch |err| {
1988419823 if (err == error.AnalysisFail and sema.err != null and sema.typeOf(air_inst).isSinglePointer(mod)) {
19885 try sema.errNote(block, elem_ty_src, sema.err.?, "use '.*' to dereference pointer", .{});
19824 try sema.errNote(elem_ty_src, sema.err.?, "use '.*' to dereference pointer", .{});
1988619825 }
1988719826 return err;
1988819827 };
......@@ -19974,11 +19913,10 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1997419913 } else if (inst_data.size == .C) {
1997519914 if (!try sema.validateExternType(elem_ty, .other)) {
1997619915 const msg = msg: {
19977 const msg = try sema.errMsg(block, elem_ty_src, "C pointers cannot point to non-C-ABI-compatible type '{}'", .{elem_ty.fmt(mod)});
19916 const msg = try sema.errMsg(elem_ty_src, "C pointers cannot point to non-C-ABI-compatible type '{}'", .{elem_ty.fmt(mod)});
1997819917 errdefer msg.destroy(sema.gpa);
1997919918
19980 const src_decl = mod.declPtr(block.src_decl);
19981 try sema.explainWhyTypeIsNotExtern(msg, src_decl.toSrcLoc(elem_ty_src, mod), elem_ty, .other);
19919 try sema.explainWhyTypeIsNotExtern(msg, elem_ty_src, elem_ty, .other);
1998219920
1998319921 try sema.addDeclaredHereNote(msg, elem_ty);
1998419922 break :msg msg;
......@@ -19992,10 +19930,9 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1999219930
1999319931 if (host_size != 0 and !try sema.validatePackedType(elem_ty)) {
1999419932 return sema.failWithOwnedErrorMsg(block, msg: {
19995 const msg = try sema.errMsg(block, elem_ty_src, "bit-pointer cannot refer to value of type '{}'", .{elem_ty.fmt(mod)});
19933 const msg = try sema.errMsg(elem_ty_src, "bit-pointer cannot refer to value of type '{}'", .{elem_ty.fmt(mod)});
1999619934 errdefer msg.destroy(sema.gpa);
19997 const src_decl = mod.declPtr(block.src_decl);
19998 try sema.explainWhyTypeIsNotPacked(msg, src_decl.toSrcLoc(elem_ty_src, mod), elem_ty);
19935 try sema.explainWhyTypeIsNotPacked(msg, elem_ty_src, elem_ty);
1999919936 break :msg msg;
2000019937 });
2000119938 }
......@@ -20025,7 +19962,7 @@ fn zirStructInitEmpty(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE
2002519962
2002619963 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
2002719964 const src = block.nodeOffset(inst_data.src_node);
20028 const ty_src: LazySrcLoc = .{ .node_offset_init_ty = inst_data.src_node };
19965 const ty_src = block.src(.{ .node_offset_init_ty = inst_data.src_node });
2002919966 const obj_ty = try sema.resolveType(block, ty_src, inst_data.operand);
2003019967 const mod = sema.mod;
2003119968
......@@ -20119,9 +20056,9 @@ fn arrayInitEmpty(sema: *Sema, block: *Block, src: LazySrcLoc, obj_ty: Type) Com
2011920056
2012020057fn zirUnionInit(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
2012120058 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
20122 const ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
20123 const field_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };
20124 const init_src: LazySrcLoc = .{ .node_offset_builtin_call_arg2 = inst_data.src_node };
20059 const ty_src = block.builtinCallArgSrc(inst_data.src_node, 0);
20060 const field_src = block.builtinCallArgSrc(inst_data.src_node, 1);
20061 const init_src = block.builtinCallArgSrc(inst_data.src_node, 2);
2012520062 const extra = sema.code.extraData(Zir.Inst.UnionInit, inst_data.payload_index).data;
2012620063 const union_ty = try sema.resolveType(block, ty_src, extra.union_type);
2012720064 if (union_ty.zigTypeTag(sema.mod) != .Union) {
......@@ -20215,7 +20152,7 @@ fn zirStructInit(
2021520152 extra_index = item.end;
2021620153
2021720154 const field_type_data = zir_datas[@intFromEnum(item.data.field_type)].pl_node;
20218 const field_src: LazySrcLoc = .{ .node_offset_initializer = field_type_data.src_node };
20155 const field_src = block.src(.{ .node_offset_initializer = field_type_data.src_node });
2021920156 const field_type_extra = sema.code.extraData(Zir.Inst.FieldType, field_type_data.payload_index).data;
2022020157 const field_name = try ip.getOrPutString(
2022120158 gpa,
......@@ -20256,7 +20193,7 @@ fn zirStructInit(
2025620193 const item = sema.code.extraData(Zir.Inst.StructInit.Item, extra.end);
2025720194
2025820195 const field_type_data = zir_datas[@intFromEnum(item.data.field_type)].pl_node;
20259 const field_src: LazySrcLoc = .{ .node_offset_initializer = field_type_data.src_node };
20196 const field_src = block.src(.{ .node_offset_initializer = field_type_data.src_node });
2026020197 const field_type_extra = sema.code.extraData(Zir.Inst.FieldType, field_type_data.payload_index).data;
2026120198 const field_name = try ip.getOrPutString(
2026220199 gpa,
......@@ -20270,7 +20207,7 @@ fn zirStructInit(
2027020207
2027120208 if (field_ty.zigTypeTag(mod) == .NoReturn) {
2027220209 return sema.failWithOwnedErrorMsg(block, msg: {
20273 const msg = try sema.errMsg(block, src, "cannot initialize 'noreturn' field of union", .{});
20210 const msg = try sema.errMsg(src, "cannot initialize 'noreturn' field of union", .{});
2027420211 errdefer msg.destroy(sema.gpa);
2027520212
2027620213 try sema.addFieldErrNote(resolved_ty, field_index, msg, "field '{}' declared here", .{
......@@ -20348,16 +20285,12 @@ fn finishStructInit(
2034820285 for (0..anon_struct.types.len) |i| {
2034920286 if (field_inits[i] != .none) {
2035020287 // Coerce the init value to the field type.
20288 const field_src = block.src(.{ .init_elem = .{
20289 .init_node_offset = init_src.offset.node_offset.x,
20290 .elem_index = @intCast(i),
20291 } });
2035120292 const field_ty = Type.fromInterned(anon_struct.types.get(ip)[i]);
20352 field_inits[i] = sema.coerce(block, field_ty, field_inits[i], .unneeded) catch |err| switch (err) {
20353 error.NeededSourceLocation => {
20354 const decl = mod.declPtr(block.src_decl);
20355 const field_src = mod.initSrc(init_src.node_offset.x, decl, i);
20356 _ = try sema.coerce(block, field_ty, field_inits[i], field_src);
20357 unreachable;
20358 },
20359 else => |e| return e,
20360 };
20293 field_inits[i] = try sema.coerce(block, field_ty, field_inits[i], field_src);
2036120294 continue;
2036220295 }
2036320296
......@@ -20367,18 +20300,18 @@ fn finishStructInit(
2036720300 if (anon_struct.names.len == 0) {
2036820301 const template = "missing tuple field with index {d}";
2036920302 if (root_msg) |msg| {
20370 try sema.errNote(block, init_src, msg, template, .{i});
20303 try sema.errNote(init_src, msg, template, .{i});
2037120304 } else {
20372 root_msg = try sema.errMsg(block, init_src, template, .{i});
20305 root_msg = try sema.errMsg(init_src, template, .{i});
2037320306 }
2037420307 } else {
2037520308 const field_name = anon_struct.names.get(ip)[i];
2037620309 const template = "missing struct field: {}";
2037720310 const args = .{field_name.fmt(ip)};
2037820311 if (root_msg) |msg| {
20379 try sema.errNote(block, init_src, msg, template, args);
20312 try sema.errNote(init_src, msg, template, args);
2038020313 } else {
20381 root_msg = try sema.errMsg(block, init_src, template, args);
20314 root_msg = try sema.errMsg(init_src, template, args);
2038220315 }
2038320316 }
2038420317 } else {
......@@ -20391,16 +20324,12 @@ fn finishStructInit(
2039120324 for (0..struct_type.field_types.len) |i| {
2039220325 if (field_inits[i] != .none) {
2039320326 // Coerce the init value to the field type.
20327 const field_src = block.src(.{ .init_elem = .{
20328 .init_node_offset = init_src.offset.node_offset.x,
20329 .elem_index = @intCast(i),
20330 } });
2039420331 const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[i]);
20395 field_inits[i] = sema.coerce(block, field_ty, field_inits[i], init_src) catch |err| switch (err) {
20396 error.NeededSourceLocation => {
20397 const decl = mod.declPtr(block.src_decl);
20398 const field_src = mod.initSrc(init_src.node_offset.x, decl, i);
20399 _ = try sema.coerce(block, field_ty, field_inits[i], field_src);
20400 unreachable;
20401 },
20402 else => |e| return e,
20403 };
20332 field_inits[i] = try sema.coerce(block, field_ty, field_inits[i], field_src);
2040420333 continue;
2040520334 }
2040620335
......@@ -20413,16 +20342,16 @@ fn finishStructInit(
2041320342 const template = "missing struct field: {}";
2041420343 const args = .{field_name.fmt(ip)};
2041520344 if (root_msg) |msg| {
20416 try sema.errNote(block, init_src, msg, template, args);
20345 try sema.errNote(init_src, msg, template, args);
2041720346 } else {
20418 root_msg = try sema.errMsg(block, init_src, template, args);
20347 root_msg = try sema.errMsg(init_src, template, args);
2041920348 }
2042020349 } else {
2042120350 const template = "missing tuple field with index {d}";
2042220351 if (root_msg) |msg| {
20423 try sema.errNote(block, init_src, msg, template, .{i});
20352 try sema.errNote(init_src, msg, template, .{i});
2042420353 } else {
20425 root_msg = try sema.errMsg(block, init_src, template, .{i});
20354 root_msg = try sema.errMsg(init_src, template, .{i});
2042620355 }
2042720356 }
2042820357 } else {
......@@ -20434,16 +20363,7 @@ fn finishStructInit(
2043420363 }
2043520364
2043620365 if (root_msg) |msg| {
20437 if (mod.typeToStruct(struct_ty)) |struct_type| {
20438 const decl = mod.declPtr(struct_type.decl.unwrap().?);
20439 const fqn = try decl.fullyQualifiedName(mod);
20440 try mod.errNoteNonLazy(
20441 decl.srcLoc(mod),
20442 msg,
20443 "struct '{}' declared here",
20444 .{fqn.fmt(ip)},
20445 );
20446 }
20366 try sema.addDeclaredHereNote(msg, struct_ty);
2044720367 root_msg = null;
2044820368 return sema.failWithOwnedErrorMsg(block, msg);
2044920369 }
......@@ -20470,9 +20390,10 @@ fn finishStructInit(
2047020390 };
2047120391
2047220392 if (try sema.typeRequiresComptime(struct_ty)) {
20473 const decl = mod.declPtr(block.src_decl);
20474 const field_src = mod.initSrc(init_src.node_offset.x, decl, runtime_index);
20475 return sema.failWithNeededComptime(block, field_src, .{
20393 return sema.failWithNeededComptime(block, block.src(.{ .init_elem = .{
20394 .init_node_offset = init_src.offset.node_offset.x,
20395 .elem_index = @intCast(runtime_index),
20396 } }), .{
2047620397 .needed_comptime_reason = "initializer of comptime only struct must be comptime-known",
2047720398 });
2047820399 }
......@@ -20500,15 +20421,10 @@ fn finishStructInit(
2050020421 return sema.makePtrConst(block, alloc);
2050120422 }
2050220423
20503 sema.requireRuntimeBlock(block, .unneeded, null) catch |err| switch (err) {
20504 error.NeededSourceLocation => {
20505 const decl = mod.declPtr(block.src_decl);
20506 const field_src = mod.initSrc(dest_src.node_offset.x, decl, runtime_index);
20507 try sema.requireRuntimeBlock(block, dest_src, field_src);
20508 unreachable;
20509 },
20510 else => |e| return e,
20511 };
20424 try sema.requireRuntimeBlock(block, dest_src, block.src(.{ .init_elem = .{
20425 .init_node_offset = init_src.offset.node_offset.x,
20426 .elem_index = @intCast(runtime_index),
20427 } }));
2051220428 try sema.resolveStructFieldInits(struct_ty);
2051320429 try sema.queueFullTypeResolution(struct_ty);
2051420430 const struct_val = try block.addAggregateInit(struct_ty, field_inits);
......@@ -20576,9 +20492,11 @@ fn structInitAnon(
2057620492 field_ty.* = sema.typeOf(init).toIntern();
2057720493 if (Type.fromInterned(field_ty.*).zigTypeTag(mod) == .Opaque) {
2057820494 const msg = msg: {
20579 const decl = mod.declPtr(block.src_decl);
20580 const field_src = mod.initSrc(src.node_offset.x, decl, @intCast(i_usize));
20581 const msg = try sema.errMsg(block, field_src, "opaque types have unknown size and therefore cannot be directly embedded in structs", .{});
20495 const field_src = block.src(.{ .init_elem = .{
20496 .init_node_offset = src.offset.node_offset.x,
20497 .elem_index = @intCast(i_usize),
20498 } });
20499 const msg = try sema.errMsg(field_src, "opaque types have unknown size and therefore cannot be directly embedded in structs", .{});
2058220500 errdefer msg.destroy(sema.gpa);
2058320501
2058420502 try sema.addDeclaredHereNote(msg, Type.fromInterned(field_ty.*));
......@@ -20610,15 +20528,10 @@ fn structInitAnon(
2061020528 return sema.addConstantMaybeRef(tuple_val, is_ref);
2061120529 };
2061220530
20613 sema.requireRuntimeBlock(block, .unneeded, null) catch |err| switch (err) {
20614 error.NeededSourceLocation => {
20615 const decl = mod.declPtr(block.src_decl);
20616 const field_src = mod.initSrc(src.node_offset.x, decl, runtime_index);
20617 try sema.requireRuntimeBlock(block, src, field_src);
20618 unreachable;
20619 },
20620 else => |e| return e,
20621 };
20531 try sema.requireRuntimeBlock(block, LazySrcLoc.unneeded, block.src(.{ .init_elem = .{
20532 .init_node_offset = src.offset.node_offset.x,
20533 .elem_index = @intCast(runtime_index),
20534 } }));
2062220535
2062320536 if (is_ref) {
2062420537 const target = mod.getTarget();
......@@ -20697,15 +20610,19 @@ fn zirArrayInit(
2069720610 const resolved_args = try gpa.alloc(Air.Inst.Ref, final_len);
2069820611 defer gpa.free(resolved_args);
2069920612 for (resolved_args, 0..) |*dest, i| {
20613 const elem_src = block.src(.{ .init_elem = .{
20614 .init_node_offset = src.offset.node_offset.x,
20615 .elem_index = @intCast(i),
20616 } });
2070020617 // Less inits than needed.
2070120618 if (i + 2 > args.len) if (is_tuple) {
2070220619 const default_val = array_ty.structFieldDefaultValue(i, mod).toIntern();
2070320620 if (default_val == .unreachable_value) {
2070420621 const template = "missing tuple field with index {d}";
2070520622 if (root_msg) |msg| {
20706 try sema.errNote(block, src, msg, template, .{i});
20623 try sema.errNote(src, msg, template, .{i});
2070720624 } else {
20708 root_msg = try sema.errMsg(block, src, template, .{i});
20625 root_msg = try sema.errMsg(src, template, .{i});
2070920626 }
2071020627 } else {
2071120628 dest.* = Air.internedToRef(default_val);
......@@ -20722,29 +20639,17 @@ fn zirArrayInit(
2072220639 array_ty.structFieldType(i, mod)
2072320640 else
2072420641 array_ty.elemType2(mod);
20725 dest.* = sema.coerce(block, elem_ty, resolved_arg, .unneeded) catch |err| switch (err) {
20726 error.NeededSourceLocation => {
20727 const decl = mod.declPtr(block.src_decl);
20728 const elem_src = mod.initSrc(src.node_offset.x, decl, i);
20729 _ = try sema.coerce(block, elem_ty, resolved_arg, elem_src);
20730 unreachable;
20731 },
20732 else => return err,
20733 };
20642 dest.* = try sema.coerce(block, elem_ty, resolved_arg, elem_src);
2073420643 if (is_tuple) {
2073520644 if (array_ty.structFieldIsComptime(i, mod))
2073620645 try sema.resolveStructFieldInits(array_ty);
2073720646 if (try array_ty.structFieldValueComptime(mod, i)) |field_val| {
2073820647 const init_val = try sema.resolveValue(dest.*) orelse {
20739 const decl = mod.declPtr(block.src_decl);
20740 const elem_src = mod.initSrc(src.node_offset.x, decl, i);
2074120648 return sema.failWithNeededComptime(block, elem_src, .{
2074220649 .needed_comptime_reason = "value stored in comptime field must be comptime-known",
2074320650 });
2074420651 };
2074520652 if (!field_val.eql(init_val, elem_ty, mod)) {
20746 const decl = mod.declPtr(block.src_decl);
20747 const elem_src = mod.initSrc(src.node_offset.x, decl, i);
2074820653 return sema.failWithInvalidComptimeFieldStore(block, elem_src, array_ty, i);
2074920654 }
2075020655 }
......@@ -20777,15 +20682,10 @@ fn zirArrayInit(
2077720682 return sema.addConstantMaybeRef(result_val.toIntern(), is_ref);
2077820683 };
2077920684
20780 sema.requireRuntimeBlock(block, .unneeded, null) catch |err| switch (err) {
20781 error.NeededSourceLocation => {
20782 const decl = mod.declPtr(block.src_decl);
20783 const elem_src = mod.initSrc(src.node_offset.x, decl, runtime_index);
20784 try sema.requireRuntimeBlock(block, src, elem_src);
20785 unreachable;
20786 },
20787 else => return err,
20788 };
20685 try sema.requireRuntimeBlock(block, LazySrcLoc.unneeded, block.src(.{ .init_elem = .{
20686 .init_node_offset = src.offset.node_offset.x,
20687 .elem_index = runtime_index,
20688 } }));
2078920689 try sema.queueFullTypeResolution(array_ty);
2079020690
2079120691 if (is_ref) {
......@@ -20864,7 +20764,7 @@ fn arrayInitAnon(
2086420764 types[i] = sema.typeOf(elem).toIntern();
2086520765 if (Type.fromInterned(types[i]).zigTypeTag(mod) == .Opaque) {
2086620766 const msg = msg: {
20867 const msg = try sema.errMsg(block, operand_src, "opaque types have unknown size and therefore cannot be directly embedded in structs", .{});
20767 const msg = try sema.errMsg(operand_src, "opaque types have unknown size and therefore cannot be directly embedded in structs", .{});
2086820768 errdefer msg.destroy(gpa);
2086920769
2087020770 try sema.addDeclaredHereNote(msg, Type.fromInterned(types[i]));
......@@ -20935,8 +20835,8 @@ fn addConstantMaybeRef(sema: *Sema, val: InternPool.Index, is_ref: bool) !Air.In
2093520835fn zirFieldTypeRef(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
2093620836 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
2093720837 const extra = sema.code.extraData(Zir.Inst.FieldTypeRef, inst_data.payload_index).data;
20938 const ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
20939 const field_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };
20838 const ty_src = block.builtinCallArgSrc(inst_data.src_node, 0);
20839 const field_src = block.builtinCallArgSrc(inst_data.src_node, 1);
2094020840 const aggregate_ty = try sema.resolveType(block, ty_src, extra.container_type);
2094120841 const field_name = try sema.resolveConstStringIntern(block, field_src, extra.field_name, .{
2094220842 .needed_comptime_reason = "field name must be comptime-known",
......@@ -20950,7 +20850,7 @@ fn zirStructInitFieldType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp
2095020850 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
2095120851 const extra = sema.code.extraData(Zir.Inst.FieldType, inst_data.payload_index).data;
2095220852 const ty_src = block.nodeOffset(inst_data.src_node);
20953 const field_name_src: LazySrcLoc = .{ .node_offset_field_name_init = inst_data.src_node };
20853 const field_name_src = block.src(.{ .node_offset_field_name_init = inst_data.src_node });
2095420854 const wrapped_aggregate_ty = sema.resolveType(block, ty_src, extra.container_type) catch |err| switch (err) {
2095520855 // Since this is a ZIR instruction that returns a type, encountering
2095620856 // generic poison should not result in a failed compilation, but the
......@@ -20990,7 +20890,7 @@ fn fieldType(
2099020890 .struct_type => {
2099120891 const struct_type = ip.loadStructType(cur_ty.toIntern());
2099220892 const field_index = struct_type.nameIndex(ip, field_name) orelse
20993 return sema.failWithBadStructFieldAccess(block, struct_type, field_src, field_name);
20893 return sema.failWithBadStructFieldAccess(block, cur_ty, struct_type, field_src, field_name);
2099420894 const field_ty = struct_type.field_types.get(ip)[field_index];
2099520895 return Air.internedToRef(field_ty);
2099620896 },
......@@ -20999,7 +20899,7 @@ fn fieldType(
2099920899 .Union => {
2100020900 const union_obj = mod.typeToUnion(cur_ty).?;
2100120901 const field_index = union_obj.loadTagType(ip).nameIndex(ip, field_name) orelse
21002 return sema.failWithBadUnionFieldAccess(block, union_obj, field_src, field_name);
20902 return sema.failWithBadUnionFieldAccess(block, cur_ty, union_obj, field_src, field_name);
2100320903 const field_ty = union_obj.field_types.get(ip)[field_index];
2100420904 return Air.internedToRef(field_ty);
2100520905 },
......@@ -21050,14 +20950,14 @@ fn zirFrame(
2105020950 block: *Block,
2105120951 extended: Zir.Inst.Extended.InstData,
2105220952) CompileError!Air.Inst.Ref {
21053 const src = LazySrcLoc.nodeOffset(@bitCast(extended.operand));
20953 const src = block.nodeOffset(@bitCast(extended.operand));
2105420954 return sema.failWithUseOfAsync(block, src);
2105520955}
2105620956
2105720957fn zirAlignOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
2105820958 const mod = sema.mod;
2105920959 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
21060 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
20960 const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0);
2106120961 const ty = try sema.resolveType(block, operand_src, inst_data.operand);
2106220962 if (ty.isNoReturn(mod)) {
2106320963 return sema.fail(block, operand_src, "no align available for type '{}'", .{ty.fmt(sema.mod)});
......@@ -21121,7 +21021,7 @@ fn zirIntFromBool(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
2112121021
2112221022fn zirErrorName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
2112321023 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
21124 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
21024 const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0);
2112521025 const uncoerced_operand = try sema.resolveInst(inst_data.operand);
2112621026 const operand = try sema.coerce(block, Type.anyerror, uncoerced_operand, operand_src);
2112721027
......@@ -21143,7 +21043,7 @@ fn zirAbs(
2114321043 const mod = sema.mod;
2114421044 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
2114521045 const operand = try sema.resolveInst(inst_data.operand);
21146 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
21046 const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0);
2114721047 const operand_ty = sema.typeOf(operand);
2114821048 const scalar_ty = operand_ty.scalarType(mod);
2114921049
......@@ -21211,7 +21111,7 @@ fn zirUnaryMath(
2121121111 const mod = sema.mod;
2121221112 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
2121321113 const operand = try sema.resolveInst(inst_data.operand);
21214 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
21114 const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0);
2121521115 const operand_ty = sema.typeOf(operand);
2121621116 const scalar_ty = operand_ty.scalarType(mod);
2121721117
......@@ -21233,7 +21133,7 @@ fn zirUnaryMath(
2123321133
2123421134fn zirTagName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
2123521135 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
21236 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
21136 const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0);
2123721137 const src = block.nodeOffset(inst_data.src_node);
2123821138 const operand = try sema.resolveInst(inst_data.operand);
2123921139 const operand_ty = sema.typeOf(operand);
......@@ -21243,7 +21143,7 @@ fn zirTagName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
2124321143 try sema.resolveTypeLayout(operand_ty);
2124421144 const enum_ty = switch (operand_ty.zigTypeTag(mod)) {
2124521145 .EnumLiteral => {
21246 const val = try sema.resolveConstDefinedValue(block, .unneeded, operand, undefined);
21146 const val = try sema.resolveConstDefinedValue(block, LazySrcLoc.unneeded, operand, undefined);
2124721147 const tag_name = ip.indexToKey(val.toIntern()).enum_literal;
2124821148 return sema.addNullTerminatedStrLit(tag_name);
2124921149 },
......@@ -21266,13 +21166,12 @@ fn zirTagName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
2126621166 const casted_operand = try sema.coerce(block, enum_ty, operand, operand_src);
2126721167 if (try sema.resolveDefinedValue(block, operand_src, casted_operand)) |val| {
2126821168 const field_index = enum_ty.enumTagFieldIndex(val, mod) orelse {
21269 const enum_decl = mod.declPtr(enum_decl_index);
2127021169 const msg = msg: {
21271 const msg = try sema.errMsg(block, src, "no field with value '{}' in enum '{}'", .{
21272 val.fmtValue(sema.mod, sema), enum_decl.name.fmt(ip),
21170 const msg = try sema.errMsg(src, "no field with value '{}' in enum '{}'", .{
21171 val.fmtValue(sema.mod, sema), mod.declPtr(enum_decl_index).name.fmt(ip),
2127321172 });
2127421173 errdefer msg.destroy(sema.gpa);
21275 try mod.errNoteNonLazy(enum_decl.srcLoc(mod), msg, "declared here", .{});
21174 try sema.errNote(enum_ty.srcLoc(mod), msg, "declared here", .{});
2127621175 break :msg msg;
2127721176 };
2127821177 return sema.failWithOwnedErrorMsg(block, msg);
......@@ -21303,10 +21202,10 @@ fn zirReify(
2130321202 const ip = &mod.intern_pool;
2130421203 const name_strategy: Zir.Inst.NameStrategy = @enumFromInt(extended.small);
2130521204 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;
21306 const src = LazySrcLoc.nodeOffset(extra.node);
21205 const src = block.nodeOffset(extra.node);
2130721206 const type_info_ty = try sema.getBuiltinType("Type");
2130821207 const uncasted_operand = try sema.resolveInst(extra.operand);
21309 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node };
21208 const operand_src = block.builtinCallArgSrc(extra.node, 0);
2131021209 const type_info = try sema.coerce(block, type_info_ty, uncasted_operand, operand_src);
2131121210 const val = try sema.resolveConstDefinedValue(block, operand_src, type_info, .{
2131221211 .needed_comptime_reason = "operand to @Type must be comptime-known",
......@@ -21459,11 +21358,10 @@ fn zirReify(
2145921358 } else if (ptr_size == .C) {
2146021359 if (!try sema.validateExternType(elem_ty, .other)) {
2146121360 const msg = msg: {
21462 const msg = try sema.errMsg(block, src, "C pointers cannot point to non-C-ABI-compatible type '{}'", .{elem_ty.fmt(mod)});
21361 const msg = try sema.errMsg(src, "C pointers cannot point to non-C-ABI-compatible type '{}'", .{elem_ty.fmt(mod)});
2146321362 errdefer msg.destroy(gpa);
2146421363
21465 const src_decl = mod.declPtr(block.src_decl);
21466 try sema.explainWhyTypeIsNotExtern(msg, src_decl.toSrcLoc(src, mod), elem_ty, .other);
21364 try sema.explainWhyTypeIsNotExtern(msg, src, elem_ty, .other);
2146721365
2146821366 try sema.addDeclaredHereNote(msg, elem_ty);
2146921367 break :msg msg;
......@@ -21679,7 +21577,6 @@ fn zirReify(
2167921577
2168021578 const new_decl_index = try sema.createAnonymousDeclTypeNamed(
2168121579 block,
21682 mod.declPtr(block.src_decl).relativeToNodeIndex(src.node_offset.x),
2168321580 Value.fromInterned(wip_ty.index),
2168421581 name_strategy,
2168521582 "opaque",
......@@ -21879,7 +21776,6 @@ fn reifyEnum(
2187921776
2188021777 const new_decl_index = try sema.createAnonymousDeclTypeNamed(
2188121778 block,
21882 mod.declPtr(block.src_decl).relativeToNodeIndex(src.node_offset.x),
2188321779 Value.fromInterned(wip_ty.index),
2188421780 name_strategy,
2188521781 "enum",
......@@ -21913,17 +21809,17 @@ fn reifyEnum(
2191321809 if (wip_ty.nextField(ip, field_name, coerced_field_val.toIntern())) |conflict| {
2191421810 return sema.failWithOwnedErrorMsg(block, switch (conflict.kind) {
2191521811 .name => msg: {
21916 const msg = try sema.errMsg(block, src, "duplicate enum field '{}'", .{field_name.fmt(ip)});
21812 const msg = try sema.errMsg(src, "duplicate enum field '{}'", .{field_name.fmt(ip)});
2191721813 errdefer msg.destroy(gpa);
2191821814 _ = conflict.prev_field_idx; // TODO: this note is incorrect
21919 try sema.errNote(block, src, msg, "other field here", .{});
21815 try sema.errNote(src, msg, "other field here", .{});
2192021816 break :msg msg;
2192121817 },
2192221818 .value => msg: {
21923 const msg = try sema.errMsg(block, src, "enum tag value {} already taken", .{field_value_val.fmtValue(mod, sema)});
21819 const msg = try sema.errMsg(src, "enum tag value {} already taken", .{field_value_val.fmtValue(mod, sema)});
2192421820 errdefer msg.destroy(gpa);
2192521821 _ = conflict.prev_field_idx; // TODO: this note is incorrect
21926 try sema.errNote(block, src, msg, "other enum tag value here", .{});
21822 try sema.errNote(src, msg, "other enum tag value here", .{});
2192721823 break :msg msg;
2192821824 },
2192921825 });
......@@ -22026,7 +21922,6 @@ fn reifyUnion(
2202621922
2202721923 const new_decl_index = try sema.createAnonymousDeclTypeNamed(
2202821924 block,
22029 mod.declPtr(block.src_decl).relativeToNodeIndex(src.node_offset.x),
2203021925 Value.fromInterned(wip_ty.index),
2203121926 name_strategy,
2203221927 "union",
......@@ -22082,7 +21977,7 @@ fn reifyUnion(
2208221977 }
2208321978
2208421979 if (tag_ty_fields_len > fields_len) return sema.failWithOwnedErrorMsg(block, msg: {
22085 const msg = try sema.errMsg(block, src, "enum fields missing in union", .{});
21980 const msg = try sema.errMsg(src, "enum fields missing in union", .{});
2208621981 errdefer msg.destroy(gpa);
2208721982 var it = seen_tags.iterator(.{ .kind = .unset });
2208821983 while (it.next()) |enum_index| {
......@@ -22135,7 +22030,7 @@ fn reifyUnion(
2213522030 const field_ty = Type.fromInterned(field_ty_ip);
2213622031 if (field_ty.zigTypeTag(mod) == .Opaque) {
2213722032 return sema.failWithOwnedErrorMsg(block, msg: {
22138 const msg = try sema.errMsg(block, src, "opaque types have unknown size and therefore cannot be directly embedded in unions", .{});
22033 const msg = try sema.errMsg(src, "opaque types have unknown size and therefore cannot be directly embedded in unions", .{});
2213922034 errdefer msg.destroy(gpa);
2214022035
2214122036 try sema.addDeclaredHereNote(msg, field_ty);
......@@ -22144,22 +22039,20 @@ fn reifyUnion(
2214422039 }
2214522040 if (layout == .@"extern" and !try sema.validateExternType(field_ty, .union_field)) {
2214622041 return sema.failWithOwnedErrorMsg(block, msg: {
22147 const msg = try sema.errMsg(block, src, "extern unions cannot contain fields of type '{}'", .{field_ty.fmt(mod)});
22042 const msg = try sema.errMsg(src, "extern unions cannot contain fields of type '{}'", .{field_ty.fmt(mod)});
2214822043 errdefer msg.destroy(gpa);
2214922044
22150 const src_decl = mod.declPtr(block.src_decl);
22151 try sema.explainWhyTypeIsNotExtern(msg, src_decl.toSrcLoc(src, mod), field_ty, .union_field);
22045 try sema.explainWhyTypeIsNotExtern(msg, src, field_ty, .union_field);
2215222046
2215322047 try sema.addDeclaredHereNote(msg, field_ty);
2215422048 break :msg msg;
2215522049 });
2215622050 } else if (layout == .@"packed" and !try sema.validatePackedType(field_ty)) {
2215722051 return sema.failWithOwnedErrorMsg(block, msg: {
22158 const msg = try sema.errMsg(block, src, "packed unions cannot contain fields of type '{}'", .{field_ty.fmt(mod)});
22052 const msg = try sema.errMsg(src, "packed unions cannot contain fields of type '{}'", .{field_ty.fmt(mod)});
2215922053 errdefer msg.destroy(gpa);
2216022054
22161 const src_decl = mod.declPtr(block.src_decl);
22162 try sema.explainWhyTypeIsNotPacked(msg, src_decl.toSrcLoc(src, mod), field_ty);
22055 try sema.explainWhyTypeIsNotPacked(msg, src, field_ty);
2216322056
2216422057 try sema.addDeclaredHereNote(msg, field_ty);
2216522058 break :msg msg;
......@@ -22285,7 +22178,6 @@ fn reifyStruct(
2228522178
2228622179 const new_decl_index = try sema.createAnonymousDeclTypeNamed(
2228722180 block,
22288 mod.declPtr(block.src_decl).relativeToNodeIndex(src.node_offset.x),
2228922181 Value.fromInterned(wip_ty.index),
2229022182 name_strategy,
2229122183 "struct",
......@@ -22376,7 +22268,7 @@ fn reifyStruct(
2237622268
2237722269 if (field_ty.zigTypeTag(mod) == .Opaque) {
2237822270 return sema.failWithOwnedErrorMsg(block, msg: {
22379 const msg = try sema.errMsg(block, src, "opaque types have unknown size and therefore cannot be directly embedded in structs", .{});
22271 const msg = try sema.errMsg(src, "opaque types have unknown size and therefore cannot be directly embedded in structs", .{});
2238022272 errdefer msg.destroy(gpa);
2238122273
2238222274 try sema.addDeclaredHereNote(msg, field_ty);
......@@ -22385,7 +22277,7 @@ fn reifyStruct(
2238522277 }
2238622278 if (field_ty.zigTypeTag(mod) == .NoReturn) {
2238722279 return sema.failWithOwnedErrorMsg(block, msg: {
22388 const msg = try sema.errMsg(block, src, "struct fields cannot be 'noreturn'", .{});
22280 const msg = try sema.errMsg(src, "struct fields cannot be 'noreturn'", .{});
2238922281 errdefer msg.destroy(gpa);
2239022282
2239122283 try sema.addDeclaredHereNote(msg, field_ty);
......@@ -22394,22 +22286,20 @@ fn reifyStruct(
2239422286 }
2239522287 if (layout == .@"extern" and !try sema.validateExternType(field_ty, .struct_field)) {
2239622288 return sema.failWithOwnedErrorMsg(block, msg: {
22397 const msg = try sema.errMsg(block, src, "extern structs cannot contain fields of type '{}'", .{field_ty.fmt(sema.mod)});
22289 const msg = try sema.errMsg(src, "extern structs cannot contain fields of type '{}'", .{field_ty.fmt(sema.mod)});
2239822290 errdefer msg.destroy(gpa);
2239922291
22400 const src_decl = sema.mod.declPtr(block.src_decl);
22401 try sema.explainWhyTypeIsNotExtern(msg, src_decl.toSrcLoc(src, mod), field_ty, .struct_field);
22292 try sema.explainWhyTypeIsNotExtern(msg, src, field_ty, .struct_field);
2240222293
2240322294 try sema.addDeclaredHereNote(msg, field_ty);
2240422295 break :msg msg;
2240522296 });
2240622297 } else if (layout == .@"packed" and !try sema.validatePackedType(field_ty)) {
2240722298 return sema.failWithOwnedErrorMsg(block, msg: {
22408 const msg = try sema.errMsg(block, src, "packed structs cannot contain fields of type '{}'", .{field_ty.fmt(sema.mod)});
22299 const msg = try sema.errMsg(src, "packed structs cannot contain fields of type '{}'", .{field_ty.fmt(sema.mod)});
2240922300 errdefer msg.destroy(gpa);
2241022301
22411 const src_decl = sema.mod.declPtr(block.src_decl);
22412 try sema.explainWhyTypeIsNotPacked(msg, src_decl.toSrcLoc(src, mod), field_ty);
22302 try sema.explainWhyTypeIsNotPacked(msg, src, field_ty);
2241322303
2241422304 try sema.addDeclaredHereNote(msg, field_ty);
2241522305 break :msg msg;
......@@ -22424,7 +22314,7 @@ fn reifyStruct(
2242422314 sema.resolveTypeLayout(field_ty) catch |err| switch (err) {
2242522315 error.AnalysisFail => {
2242622316 const msg = sema.err orelse return err;
22427 try sema.errNote(block, src, msg, "while checking a field of this struct", .{});
22317 try sema.errNote(src, msg, "while checking a field of this struct", .{});
2242822318 return err;
2242922319 },
2243022320 else => return err,
......@@ -22455,22 +22345,20 @@ fn resolveVaListRef(sema: *Sema, block: *Block, src: LazySrcLoc, zir_ref: Zir.In
2245522345}
2245622346
2245722347fn zirCVaArg(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!Air.Inst.Ref {
22458 const mod = sema.mod;
2245922348 const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data;
22460 const src = LazySrcLoc.nodeOffset(extra.node);
22461 const va_list_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node };
22462 const ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = extra.node };
22349 const src = block.nodeOffset(extra.node);
22350 const va_list_src = block.builtinCallArgSrc(extra.node, 0);
22351 const ty_src = block.builtinCallArgSrc(extra.node, 1);
2246322352
2246422353 const va_list_ref = try sema.resolveVaListRef(block, va_list_src, extra.lhs);
2246522354 const arg_ty = try sema.resolveType(block, ty_src, extra.rhs);
2246622355
2246722356 if (!try sema.validateExternType(arg_ty, .param_ty)) {
2246822357 const msg = msg: {
22469 const msg = try sema.errMsg(block, ty_src, "cannot get '{}' from variadic argument", .{arg_ty.fmt(sema.mod)});
22358 const msg = try sema.errMsg(ty_src, "cannot get '{}' from variadic argument", .{arg_ty.fmt(sema.mod)});
2247022359 errdefer msg.destroy(sema.gpa);
2247122360
22472 const src_decl = sema.mod.declPtr(block.src_decl);
22473 try sema.explainWhyTypeIsNotExtern(msg, src_decl.toSrcLoc(ty_src, mod), arg_ty, .param_ty);
22361 try sema.explainWhyTypeIsNotExtern(msg, ty_src, arg_ty, .param_ty);
2247422362
2247522363 try sema.addDeclaredHereNote(msg, arg_ty);
2247622364 break :msg msg;
......@@ -22484,8 +22372,8 @@ fn zirCVaArg(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) C
2248422372
2248522373fn zirCVaCopy(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!Air.Inst.Ref {
2248622374 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;
22487 const src = LazySrcLoc.nodeOffset(extra.node);
22488 const va_list_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node };
22375 const src = block.nodeOffset(extra.node);
22376 const va_list_src = block.builtinCallArgSrc(extra.node, 0);
2248922377
2249022378 const va_list_ref = try sema.resolveVaListRef(block, va_list_src, extra.operand);
2249122379 const va_list_ty = try sema.getBuiltinType("VaList");
......@@ -22496,8 +22384,8 @@ fn zirCVaCopy(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData)
2249622384
2249722385fn zirCVaEnd(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!Air.Inst.Ref {
2249822386 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;
22499 const src = LazySrcLoc.nodeOffset(extra.node);
22500 const va_list_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node };
22387 const src = block.nodeOffset(extra.node);
22388 const va_list_src = block.builtinCallArgSrc(extra.node, 0);
2250122389
2250222390 const va_list_ref = try sema.resolveVaListRef(block, va_list_src, extra.operand);
2250322391
......@@ -22506,7 +22394,7 @@ fn zirCVaEnd(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) C
2250622394}
2250722395
2250822396fn zirCVaStart(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!Air.Inst.Ref {
22509 const src = LazySrcLoc.nodeOffset(@bitCast(extended.operand));
22397 const src = block.nodeOffset(@bitCast(extended.operand));
2251022398
2251122399 const va_list_ty = try sema.getBuiltinType("VaList");
2251222400 try sema.requireRuntimeBlock(block, src, null);
......@@ -22521,7 +22409,7 @@ fn zirTypeName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
2252122409 const ip = &mod.intern_pool;
2252222410
2252322411 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
22524 const ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
22412 const ty_src = block.builtinCallArgSrc(inst_data.src_node, 0);
2252522413 const ty = try sema.resolveType(block, ty_src, inst_data.operand);
2252622414
2252722415 const type_name = try ip.getOrPutStringFmt(sema.gpa, "{}", .{ty.fmt(mod)}, .no_embedded_nulls);
......@@ -22545,7 +22433,7 @@ fn zirIntFromFloat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
2254522433 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
2254622434 const src = block.nodeOffset(inst_data.src_node);
2254722435 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
22548 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
22436 const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0);
2254922437 const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu_opt, "@intFromFloat");
2255022438 const operand = try sema.resolveInst(extra.rhs);
2255122439 const operand_ty = sema.typeOf(operand);
......@@ -22627,7 +22515,7 @@ fn zirFloatFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
2262722515 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
2262822516 const src = block.nodeOffset(inst_data.src_node);
2262922517 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
22630 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
22518 const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0);
2263122519 const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu_opt, "@floatFromInt");
2263222520 const operand = try sema.resolveInst(extra.rhs);
2263322521 const operand_ty = sema.typeOf(operand);
......@@ -22671,7 +22559,7 @@ fn zirPtrFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
2267122559
2267222560 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
2267322561
22674 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
22562 const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0);
2267522563 const operand_res = try sema.resolveInst(extra.rhs);
2267622564
2267722565 const uncoerced_operand_ty = sema.typeOf(operand_res);
......@@ -22694,9 +22582,9 @@ fn zirPtrFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
2269422582
2269522583 if (ptr_ty.isSlice(mod)) {
2269622584 const msg = msg: {
22697 const msg = try sema.errMsg(block, src, "integer cannot be converted to slice type '{}'", .{ptr_ty.fmt(sema.mod)});
22585 const msg = try sema.errMsg(src, "integer cannot be converted to slice type '{}'", .{ptr_ty.fmt(sema.mod)});
2269822586 errdefer msg.destroy(sema.gpa);
22699 try sema.errNote(block, src, msg, "slice length cannot be inferred from address", .{});
22587 try sema.errNote(src, msg, "slice length cannot be inferred from address", .{});
2270022588 break :msg msg;
2270122589 };
2270222590 return sema.failWithOwnedErrorMsg(block, msg);
......@@ -22721,11 +22609,10 @@ fn zirPtrFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
2272122609 }
2272222610 if (try sema.typeRequiresComptime(ptr_ty)) {
2272322611 return sema.failWithOwnedErrorMsg(block, msg: {
22724 const msg = try sema.errMsg(block, src, "pointer to comptime-only type '{}' must be comptime-known, but operand is runtime-known", .{ptr_ty.fmt(mod)});
22612 const msg = try sema.errMsg(src, "pointer to comptime-only type '{}' must be comptime-known, but operand is runtime-known", .{ptr_ty.fmt(mod)});
2272522613 errdefer msg.destroy(sema.gpa);
2272622614
22727 const src_decl = mod.declPtr(block.src_decl);
22728 try sema.explainWhyTypeIsComptime(msg, src_decl.toSrcLoc(src, mod), ptr_ty);
22615 try sema.explainWhyTypeIsComptime(msg, src, ptr_ty);
2272922616 break :msg msg;
2273022617 });
2273122618 }
......@@ -22810,8 +22697,8 @@ fn zirErrorCast(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData
2281022697 const mod = sema.mod;
2281122698 const ip = &mod.intern_pool;
2281222699 const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data;
22813 const src = LazySrcLoc.nodeOffset(extra.node);
22814 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node };
22700 const src = block.nodeOffset(extra.node);
22701 const operand_src = block.builtinCallArgSrc(extra.node, 0);
2281522702 const base_dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_opt, "@errorCast");
2281622703 const operand = try sema.resolveInst(extra.rhs);
2281722704 const base_operand_ty = sema.typeOf(operand);
......@@ -22831,12 +22718,12 @@ fn zirErrorCast(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData
2283122718 base_dest_ty.errorUnionPayload(mod).toIntern() != base_operand_ty.errorUnionPayload(mod).toIntern())
2283222719 {
2283322720 return sema.failWithOwnedErrorMsg(block, msg: {
22834 const msg = try sema.errMsg(block, src, "payload types of error unions must match", .{});
22721 const msg = try sema.errMsg(src, "payload types of error unions must match", .{});
2283522722 errdefer msg.destroy(sema.gpa);
2283622723 const dest_ty = base_dest_ty.errorUnionPayload(mod);
2283722724 const operand_ty = base_operand_ty.errorUnionPayload(mod);
22838 try sema.errNote(block, src, msg, "destination payload is '{}'", .{dest_ty.fmt(mod)});
22839 try sema.errNote(block, src, msg, "operand payload is '{}'", .{operand_ty.fmt(mod)});
22725 try sema.errNote(src, msg, "destination payload is '{}'", .{dest_ty.fmt(mod)});
22726 try sema.errNote(src, msg, "operand payload is '{}'", .{operand_ty.fmt(mod)});
2284022727 try addDeclaredHereNote(sema, msg, dest_ty);
2284122728 try addDeclaredHereNote(sema, msg, operand_ty);
2284222729 break :msg msg;
......@@ -22935,8 +22822,8 @@ fn zirPtrCastFull(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDa
2293522822 const FlagsInt = @typeInfo(Zir.Inst.FullPtrCastFlags).Struct.backing_integer.?;
2293622823 const flags: Zir.Inst.FullPtrCastFlags = @bitCast(@as(FlagsInt, @truncate(extended.small)));
2293722824 const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data;
22938 const src = LazySrcLoc.nodeOffset(extra.node);
22939 const operand_src: LazySrcLoc = .{ .node_offset_ptrcast_operand = extra.node };
22825 const src = block.nodeOffset(extra.node);
22826 const operand_src = block.src(.{ .node_offset_ptrcast_operand = extra.node });
2294022827 const operand = try sema.resolveInst(extra.rhs);
2294122828 const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu, flags.needResultTypeBuiltinName());
2294222829 return sema.ptrCastFull(
......@@ -22953,7 +22840,7 @@ fn zirPtrCastFull(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDa
2295322840fn zirPtrCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
2295422841 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
2295522842 const src = block.nodeOffset(inst_data.src_node);
22956 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
22843 const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0);
2295722844 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
2295822845 const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu, "@ptrCast");
2295922846 const operand = try sema.resolveInst(extra.rhs);
......@@ -23023,7 +22910,7 @@ fn ptrCastFull(
2302322910 if (src_info.flags.size == .C) break :check_size;
2302422911 if (dest_info.flags.size == .C) break :check_size;
2302522912 return sema.failWithOwnedErrorMsg(block, msg: {
23026 const msg = try sema.errMsg(block, src, "cannot implicitly convert {s} pointer to {s} pointer", .{
22913 const msg = try sema.errMsg(src, "cannot implicitly convert {s} pointer to {s} pointer", .{
2302722914 pointerSizeString(src_info.flags.size),
2302822915 pointerSizeString(dest_info.flags.size),
2302922916 });
......@@ -23032,9 +22919,9 @@ fn ptrCastFull(
2303222919 (src_info.flags.size == .Slice or
2303322920 (src_info.flags.size == .One and Type.fromInterned(src_info.child).zigTypeTag(mod) == .Array)))
2303422921 {
23035 try sema.errNote(block, src, msg, "use 'ptr' field to convert slice to many pointer", .{});
22922 try sema.errNote(src, msg, "use 'ptr' field to convert slice to many pointer", .{});
2303622923 } else {
23037 try sema.errNote(block, src, msg, "use @ptrCast to change pointer size", .{});
22924 try sema.errNote(src, msg, "use @ptrCast to change pointer size", .{});
2303822925 }
2303922926 break :msg msg;
2304022927 });
......@@ -23059,13 +22946,13 @@ fn ptrCastFull(
2305922946 );
2306022947 if (imc_res == .ok) break :check_child;
2306122948 return sema.failWithOwnedErrorMsg(block, msg: {
23062 const msg = try sema.errMsg(block, src, "pointer element type '{}' cannot coerce into element type '{}'", .{
22949 const msg = try sema.errMsg(src, "pointer element type '{}' cannot coerce into element type '{}'", .{
2306322950 src_child.fmt(mod),
2306422951 dest_child.fmt(mod),
2306522952 });
2306622953 errdefer msg.destroy(sema.gpa);
23067 try imc_res.report(sema, block, src, msg);
23068 try sema.errNote(block, src, msg, "use @ptrCast to cast pointer element type", .{});
22954 try imc_res.report(sema, src, msg);
22955 try sema.errNote(src, msg, "use @ptrCast to cast pointer element type", .{});
2306922956 break :msg msg;
2307022957 });
2307122958 }
......@@ -23087,41 +22974,41 @@ fn ptrCastFull(
2308722974 }
2308822975 return sema.failWithOwnedErrorMsg(block, msg: {
2308922976 const msg = if (src_info.sentinel == .none) blk: {
23090 break :blk try sema.errMsg(block, src, "destination pointer requires '{}' sentinel", .{
22977 break :blk try sema.errMsg(src, "destination pointer requires '{}' sentinel", .{
2309122978 Value.fromInterned(dest_info.sentinel).fmtValue(mod, sema),
2309222979 });
2309322980 } else blk: {
23094 break :blk try sema.errMsg(block, src, "pointer sentinel '{}' cannot coerce into pointer sentinel '{}'", .{
22981 break :blk try sema.errMsg(src, "pointer sentinel '{}' cannot coerce into pointer sentinel '{}'", .{
2309522982 Value.fromInterned(src_info.sentinel).fmtValue(mod, sema),
2309622983 Value.fromInterned(dest_info.sentinel).fmtValue(mod, sema),
2309722984 });
2309822985 };
2309922986 errdefer msg.destroy(sema.gpa);
23100 try sema.errNote(block, src, msg, "use @ptrCast to cast pointer sentinel", .{});
22987 try sema.errNote(src, msg, "use @ptrCast to cast pointer sentinel", .{});
2310122988 break :msg msg;
2310222989 });
2310322990 }
2310422991
2310522992 if (src_info.packed_offset.host_size != dest_info.packed_offset.host_size) {
2310622993 return sema.failWithOwnedErrorMsg(block, msg: {
23107 const msg = try sema.errMsg(block, src, "pointer host size '{}' cannot coerce into pointer host size '{}'", .{
22994 const msg = try sema.errMsg(src, "pointer host size '{}' cannot coerce into pointer host size '{}'", .{
2310822995 src_info.packed_offset.host_size,
2310922996 dest_info.packed_offset.host_size,
2311022997 });
2311122998 errdefer msg.destroy(sema.gpa);
23112 try sema.errNote(block, src, msg, "use @ptrCast to cast pointer host size", .{});
22999 try sema.errNote(src, msg, "use @ptrCast to cast pointer host size", .{});
2311323000 break :msg msg;
2311423001 });
2311523002 }
2311623003
2311723004 if (src_info.packed_offset.bit_offset != dest_info.packed_offset.bit_offset) {
2311823005 return sema.failWithOwnedErrorMsg(block, msg: {
23119 const msg = try sema.errMsg(block, src, "pointer bit offset '{}' cannot coerce into pointer bit offset '{}'", .{
23006 const msg = try sema.errMsg(src, "pointer bit offset '{}' cannot coerce into pointer bit offset '{}'", .{
2312023007 src_info.packed_offset.bit_offset,
2312123008 dest_info.packed_offset.bit_offset,
2312223009 });
2312323010 errdefer msg.destroy(sema.gpa);
23124 try sema.errNote(block, src, msg, "use @ptrCast to cast pointer bit offset", .{});
23011 try sema.errNote(src, msg, "use @ptrCast to cast pointer bit offset", .{});
2312523012 break :msg msg;
2312623013 });
2312723014 }
......@@ -23133,12 +23020,12 @@ fn ptrCastFull(
2313323020 if (dest_allows_zero) break :check_allowzero;
2313423021
2313523022 return sema.failWithOwnedErrorMsg(block, msg: {
23136 const msg = try sema.errMsg(block, src, "'{}' could have null values which are illegal in type '{}'", .{
23023 const msg = try sema.errMsg(src, "'{}' could have null values which are illegal in type '{}'", .{
2313723024 operand_ty.fmt(mod),
2313823025 dest_ty.fmt(mod),
2313923026 });
2314023027 errdefer msg.destroy(sema.gpa);
23141 try sema.errNote(block, src, msg, "use @ptrCast to assert the pointer is not null", .{});
23028 try sema.errNote(src, msg, "use @ptrCast to assert the pointer is not null", .{});
2314223029 break :msg msg;
2314323030 });
2314423031 }
......@@ -23159,15 +23046,15 @@ fn ptrCastFull(
2315923046 if (!flags.align_cast) {
2316023047 if (dest_align.compare(.gt, src_align)) {
2316123048 return sema.failWithOwnedErrorMsg(block, msg: {
23162 const msg = try sema.errMsg(block, src, "{s} increases pointer alignment", .{operation});
23049 const msg = try sema.errMsg(src, "{s} increases pointer alignment", .{operation});
2316323050 errdefer msg.destroy(sema.gpa);
23164 try sema.errNote(block, operand_src, msg, "'{}' has alignment '{d}'", .{
23051 try sema.errNote(operand_src, msg, "'{}' has alignment '{d}'", .{
2316523052 operand_ty.fmt(mod), src_align.toByteUnits() orelse 0,
2316623053 });
23167 try sema.errNote(block, src, msg, "'{}' has alignment '{d}'", .{
23054 try sema.errNote(src, msg, "'{}' has alignment '{d}'", .{
2316823055 dest_ty.fmt(mod), dest_align.toByteUnits() orelse 0,
2316923056 });
23170 try sema.errNote(block, src, msg, "use @alignCast to assert pointer alignment", .{});
23057 try sema.errNote(src, msg, "use @alignCast to assert pointer alignment", .{});
2317123058 break :msg msg;
2317223059 });
2317323060 }
......@@ -23176,15 +23063,15 @@ fn ptrCastFull(
2317623063 if (!flags.addrspace_cast) {
2317723064 if (src_info.flags.address_space != dest_info.flags.address_space) {
2317823065 return sema.failWithOwnedErrorMsg(block, msg: {
23179 const msg = try sema.errMsg(block, src, "{s} changes pointer address space", .{operation});
23066 const msg = try sema.errMsg(src, "{s} changes pointer address space", .{operation});
2318023067 errdefer msg.destroy(sema.gpa);
23181 try sema.errNote(block, operand_src, msg, "'{}' has address space '{s}'", .{
23068 try sema.errNote(operand_src, msg, "'{}' has address space '{s}'", .{
2318223069 operand_ty.fmt(mod), @tagName(src_info.flags.address_space),
2318323070 });
23184 try sema.errNote(block, src, msg, "'{}' has address space '{s}'", .{
23071 try sema.errNote(src, msg, "'{}' has address space '{s}'", .{
2318523072 dest_ty.fmt(mod), @tagName(dest_info.flags.address_space),
2318623073 });
23187 try sema.errNote(block, src, msg, "use @addrSpaceCast to cast pointer address space", .{});
23074 try sema.errNote(src, msg, "use @addrSpaceCast to cast pointer address space", .{});
2318823075 break :msg msg;
2318923076 });
2319023077 }
......@@ -23192,9 +23079,9 @@ fn ptrCastFull(
2319223079 // Some address space casts are always disallowed
2319323080 if (!target_util.addrSpaceCastIsValid(mod.getTarget(), src_info.flags.address_space, dest_info.flags.address_space)) {
2319423081 return sema.failWithOwnedErrorMsg(block, msg: {
23195 const msg = try sema.errMsg(block, src, "invalid address space cast", .{});
23082 const msg = try sema.errMsg(src, "invalid address space cast", .{});
2319623083 errdefer msg.destroy(sema.gpa);
23197 try sema.errNote(block, operand_src, msg, "address space '{s}' is not compatible with address space '{s}'", .{
23084 try sema.errNote(operand_src, msg, "address space '{s}' is not compatible with address space '{s}'", .{
2319823085 @tagName(src_info.flags.address_space),
2319923086 @tagName(dest_info.flags.address_space),
2320023087 });
......@@ -23206,9 +23093,9 @@ fn ptrCastFull(
2320623093 if (!flags.const_cast) {
2320723094 if (src_info.flags.is_const and !dest_info.flags.is_const) {
2320823095 return sema.failWithOwnedErrorMsg(block, msg: {
23209 const msg = try sema.errMsg(block, src, "{s} discards const qualifier", .{operation});
23096 const msg = try sema.errMsg(src, "{s} discards const qualifier", .{operation});
2321023097 errdefer msg.destroy(sema.gpa);
23211 try sema.errNote(block, src, msg, "use @constCast to discard const qualifier", .{});
23098 try sema.errNote(src, msg, "use @constCast to discard const qualifier", .{});
2321223099 break :msg msg;
2321323100 });
2321423101 }
......@@ -23217,9 +23104,9 @@ fn ptrCastFull(
2321723104 if (!flags.volatile_cast) {
2321823105 if (src_info.flags.is_volatile and !dest_info.flags.is_volatile) {
2321923106 return sema.failWithOwnedErrorMsg(block, msg: {
23220 const msg = try sema.errMsg(block, src, "{s} discards volatile qualifier", .{operation});
23107 const msg = try sema.errMsg(src, "{s} discards volatile qualifier", .{operation});
2322123108 errdefer msg.destroy(sema.gpa);
23222 try sema.errNote(block, src, msg, "use @volatileCast to discard volatile qualifier", .{});
23109 try sema.errNote(src, msg, "use @volatileCast to discard volatile qualifier", .{});
2322323110 break :msg msg;
2322423111 });
2322523112 }
......@@ -23368,8 +23255,8 @@ fn zirPtrCastNoDest(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.Inst
2336823255 const FlagsInt = @typeInfo(Zir.Inst.FullPtrCastFlags).Struct.backing_integer.?;
2336923256 const flags: Zir.Inst.FullPtrCastFlags = @bitCast(@as(FlagsInt, @truncate(extended.small)));
2337023257 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;
23371 const src = LazySrcLoc.nodeOffset(extra.node);
23372 const operand_src: LazySrcLoc = .{ .node_offset_ptrcast_operand = extra.node };
23258 const src = block.nodeOffset(extra.node);
23259 const operand_src = block.src(.{ .node_offset_ptrcast_operand = extra.node });
2337323260 const operand = try sema.resolveInst(extra.operand);
2337423261 const operand_ty = sema.typeOf(operand);
2337523262 try sema.checkPtrOperand(block, operand_src, operand_ty);
......@@ -23400,7 +23287,7 @@ fn zirTruncate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
2340023287 const mod = sema.mod;
2340123288 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
2340223289 const src = block.nodeOffset(inst_data.src_node);
23403 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
23290 const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0);
2340423291 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
2340523292 const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu_opt, "@truncate");
2340623293 const dest_scalar_ty = try sema.checkIntOrVectorAllowComptime(block, dest_ty, src);
......@@ -23438,16 +23325,15 @@ fn zirTruncate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
2343823325 if (operand_info.bits < dest_info.bits) {
2343923326 const msg = msg: {
2344023327 const msg = try sema.errMsg(
23441 block,
2344223328 src,
2344323329 "destination type '{}' has more bits than source type '{}'",
2344423330 .{ dest_ty.fmt(mod), operand_ty.fmt(mod) },
2344523331 );
2344623332 errdefer msg.destroy(sema.gpa);
23447 try sema.errNote(block, src, msg, "destination type has {d} bits", .{
23333 try sema.errNote(src, msg, "destination type has {d} bits", .{
2344823334 dest_info.bits,
2344923335 });
23450 try sema.errNote(block, operand_src, msg, "operand type has {d} bits", .{
23336 try sema.errNote(operand_src, msg, "operand type has {d} bits", .{
2345123337 operand_info.bits,
2345223338 });
2345323339 break :msg msg;
......@@ -23490,7 +23376,7 @@ fn zirBitCount(
2349023376 const mod = sema.mod;
2349123377 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
2349223378 const src = block.nodeOffset(inst_data.src_node);
23493 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
23379 const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0);
2349423380 const operand = try sema.resolveInst(inst_data.operand);
2349523381 const operand_ty = sema.typeOf(operand);
2349623382 _ = try sema.checkIntOrVector(block, operand, operand_src);
......@@ -23544,7 +23430,7 @@ fn zirByteSwap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
2354423430 const mod = sema.mod;
2354523431 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
2354623432 const src = block.nodeOffset(inst_data.src_node);
23547 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
23433 const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0);
2354823434 const operand = try sema.resolveInst(inst_data.operand);
2354923435 const operand_ty = sema.typeOf(operand);
2355023436 const scalar_ty = try sema.checkIntOrVector(block, operand, operand_src);
......@@ -23600,7 +23486,7 @@ fn zirByteSwap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
2360023486fn zirBitReverse(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
2360123487 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
2360223488 const src = block.nodeOffset(inst_data.src_node);
23603 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
23489 const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0);
2360423490 const operand = try sema.resolveInst(inst_data.operand);
2360523491 const operand_ty = sema.typeOf(operand);
2360623492 const scalar_ty = try sema.checkIntOrVector(block, operand, operand_src);
......@@ -23658,9 +23544,9 @@ fn zirOffsetOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
2365823544
2365923545fn bitOffsetOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!u64 {
2366023546 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
23661 const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node };
23662 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };
23663 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };
23547 const src = block.src(.{ .node_offset_bin_op = inst_data.src_node });
23548 const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node });
23549 const rhs_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node });
2366423550 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
2366523551
2366623552 const ty = try sema.resolveType(block, lhs_src, extra.lhs);
......@@ -23773,14 +23659,13 @@ fn checkPtrOperand(
2377323659 .Fn => {
2377423660 const msg = msg: {
2377523661 const msg = try sema.errMsg(
23776 block,
2377723662 ty_src,
2377823663 "expected pointer, found '{}'",
2377923664 .{ty.fmt(mod)},
2378023665 );
2378123666 errdefer msg.destroy(sema.gpa);
2378223667
23783 try sema.errNote(block, ty_src, msg, "use '&' to obtain a function pointer", .{});
23668 try sema.errNote(ty_src, msg, "use '&' to obtain a function pointer", .{});
2378423669
2378523670 break :msg msg;
2378623671 };
......@@ -23805,14 +23690,13 @@ fn checkPtrType(
2380523690 .Fn => {
2380623691 const msg = msg: {
2380723692 const msg = try sema.errMsg(
23808 block,
2380923693 ty_src,
2381023694 "expected pointer type, found '{}'",
2381123695 .{ty.fmt(mod)},
2381223696 );
2381323697 errdefer msg.destroy(sema.gpa);
2381423698
23815 try sema.errNote(block, ty_src, msg, "use '*const ' to make a function pointer type", .{});
23699 try sema.errNote(ty_src, msg, "use '*const ' to make a function pointer type", .{});
2381623700
2381723701 break :msg msg;
2381823702 };
......@@ -24066,26 +23950,26 @@ fn checkVectorizableBinaryOperands(
2406623950 const rhs_len = rhs_ty.arrayLen(mod);
2406723951 if (lhs_len != rhs_len) {
2406823952 const msg = msg: {
24069 const msg = try sema.errMsg(block, src, "vector length mismatch", .{});
23953 const msg = try sema.errMsg(src, "vector length mismatch", .{});
2407023954 errdefer msg.destroy(sema.gpa);
24071 try sema.errNote(block, lhs_src, msg, "length {d} here", .{lhs_len});
24072 try sema.errNote(block, rhs_src, msg, "length {d} here", .{rhs_len});
23955 try sema.errNote(lhs_src, msg, "length {d} here", .{lhs_len});
23956 try sema.errNote(rhs_src, msg, "length {d} here", .{rhs_len});
2407323957 break :msg msg;
2407423958 };
2407523959 return sema.failWithOwnedErrorMsg(block, msg);
2407623960 }
2407723961 } else {
2407823962 const msg = msg: {
24079 const msg = try sema.errMsg(block, src, "mixed scalar and vector operands: '{}' and '{}'", .{
23963 const msg = try sema.errMsg(src, "mixed scalar and vector operands: '{}' and '{}'", .{
2408023964 lhs_ty.fmt(mod), rhs_ty.fmt(mod),
2408123965 });
2408223966 errdefer msg.destroy(sema.gpa);
2408323967 if (lhs_is_vector) {
24084 try sema.errNote(block, lhs_src, msg, "vector here", .{});
24085 try sema.errNote(block, rhs_src, msg, "scalar here", .{});
23968 try sema.errNote(lhs_src, msg, "vector here", .{});
23969 try sema.errNote(rhs_src, msg, "scalar here", .{});
2408623970 } else {
24087 try sema.errNote(block, lhs_src, msg, "scalar here", .{});
24088 try sema.errNote(block, rhs_src, msg, "vector here", .{});
23971 try sema.errNote(lhs_src, msg, "scalar here", .{});
23972 try sema.errNote(rhs_src, msg, "vector here", .{});
2408923973 }
2409023974 break :msg msg;
2409123975 };
......@@ -24093,12 +23977,6 @@ fn checkVectorizableBinaryOperands(
2409323977 }
2409423978}
2409523979
24096fn maybeOptionsSrc(sema: *Sema, block: *Block, base_src: LazySrcLoc, wanted: []const u8) LazySrcLoc {
24097 if (base_src == .unneeded) return .unneeded;
24098 const mod = sema.mod;
24099 return mod.optionsSrc(mod.declPtr(block.src_decl), base_src, wanted);
24100}
24101
2410223980fn resolveExportOptions(
2410323981 sema: *Sema,
2410423982 block: *Block,
......@@ -24112,10 +23990,10 @@ fn resolveExportOptions(
2411223990 const air_ref = try sema.resolveInst(zir_ref);
2411323991 const options = try sema.coerce(block, export_options_ty, air_ref, src);
2411423992
24115 const name_src = sema.maybeOptionsSrc(block, src, "name");
24116 const linkage_src = sema.maybeOptionsSrc(block, src, "linkage");
24117 const section_src = sema.maybeOptionsSrc(block, src, "section");
24118 const visibility_src = sema.maybeOptionsSrc(block, src, "visibility");
23993 const name_src = block.src(.{ .init_field_name = src.offset.node_offset_builtin_call_arg.builtin_call_node });
23994 const linkage_src = block.src(.{ .init_field_linkage = src.offset.node_offset_builtin_call_arg.builtin_call_node });
23995 const section_src = block.src(.{ .init_field_section = src.offset.node_offset_builtin_call_arg.builtin_call_node });
23996 const visibility_src = block.src(.{ .init_field_visibility = src.offset.node_offset_builtin_call_arg.builtin_call_node });
2411923997
2412023998 const name_operand = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "name", .no_embedded_nulls), name_src);
2412123999 const name = try sema.toConstString(block, name_src, name_operand, .{
......@@ -24212,14 +24090,14 @@ fn zirCmpxchg(
2421224090 1 => .cmpxchg_strong,
2421324091 else => unreachable,
2421424092 };
24215 const src = LazySrcLoc.nodeOffset(extra.node);
24093 const src = block.nodeOffset(extra.node);
2421624094 // zig fmt: off
24217 const elem_ty_src : LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node };
24218 const ptr_src : LazySrcLoc = .{ .node_offset_builtin_call_arg1 = extra.node };
24219 const expected_src : LazySrcLoc = .{ .node_offset_builtin_call_arg2 = extra.node };
24220 const new_value_src : LazySrcLoc = .{ .node_offset_builtin_call_arg3 = extra.node };
24221 const success_order_src: LazySrcLoc = .{ .node_offset_builtin_call_arg4 = extra.node };
24222 const failure_order_src: LazySrcLoc = .{ .node_offset_builtin_call_arg5 = extra.node };
24095 const elem_ty_src = block.builtinCallArgSrc(extra.node, 0);
24096 const ptr_src = block.builtinCallArgSrc(extra.node, 1);
24097 const expected_src = block.builtinCallArgSrc(extra.node, 2);
24098 const new_value_src = block.builtinCallArgSrc(extra.node, 3);
24099 const success_order_src = block.builtinCallArgSrc(extra.node, 4);
24100 const failure_order_src = block.builtinCallArgSrc(extra.node, 5);
2422324101 // zig fmt: on
2422424102 const expected_value = try sema.resolveInst(extra.expected_value);
2422524103 const elem_ty = sema.typeOf(expected_value);
......@@ -24309,7 +24187,7 @@ fn zirSplat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.I
2430924187 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
2431024188 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
2431124189 const src = block.nodeOffset(inst_data.src_node);
24312 const scalar_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
24190 const scalar_src = block.builtinCallArgSrc(inst_data.src_node, 0);
2431324191 const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu_opt, "@splat");
2431424192
2431524193 if (!dest_ty.isVector(mod)) return sema.fail(block, src, "expected vector type, found '{}'", .{dest_ty.fmt(mod)});
......@@ -24337,8 +24215,8 @@ fn zirSplat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.I
2433724215fn zirReduce(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
2433824216 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
2433924217 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
24340 const op_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
24341 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };
24218 const op_src = block.builtinCallArgSrc(inst_data.src_node, 0);
24219 const operand_src = block.builtinCallArgSrc(inst_data.src_node, 1);
2434224220 const operation = try sema.resolveBuiltinEnum(block, op_src, extra.lhs, "ReduceOp", .{
2434324221 .needed_comptime_reason = "@reduce operation must be comptime-known",
2434424222 });
......@@ -24409,8 +24287,8 @@ fn zirShuffle(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
2440924287 const mod = sema.mod;
2441024288 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
2441124289 const extra = sema.code.extraData(Zir.Inst.Shuffle, inst_data.payload_index).data;
24412 const elem_ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
24413 const mask_src: LazySrcLoc = .{ .node_offset_builtin_call_arg3 = inst_data.src_node };
24290 const elem_ty_src = block.builtinCallArgSrc(inst_data.src_node, 0);
24291 const mask_src = block.builtinCallArgSrc(inst_data.src_node, 3);
2441424292
2441524293 const elem_ty = try sema.resolveType(block, elem_ty_src, extra.elem_type);
2441624294 try sema.checkVectorElemType(block, elem_ty_src, elem_ty);
......@@ -24445,9 +24323,9 @@ fn analyzeShuffle(
2444524323 mask_len: u32,
2444624324) CompileError!Air.Inst.Ref {
2444724325 const mod = sema.mod;
24448 const a_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = src_node };
24449 const b_src: LazySrcLoc = .{ .node_offset_builtin_call_arg2 = src_node };
24450 const mask_src: LazySrcLoc = .{ .node_offset_builtin_call_arg3 = src_node };
24326 const a_src = block.builtinCallArgSrc(src_node, 1);
24327 const b_src = block.builtinCallArgSrc(src_node, 2);
24328 const mask_src = block.builtinCallArgSrc(src_node, 3);
2445124329 var a = a_arg;
2445224330 var b = b_arg;
2445324331
......@@ -24511,16 +24389,16 @@ fn analyzeShuffle(
2451124389 }
2451224390 if (unsigned >= operand_info[chosen][0]) {
2451324391 const msg = msg: {
24514 const msg = try sema.errMsg(block, mask_src, "mask index '{d}' has out-of-bounds selection", .{i});
24392 const msg = try sema.errMsg(mask_src, "mask index '{d}' has out-of-bounds selection", .{i});
2451524393 errdefer msg.destroy(sema.gpa);
2451624394
24517 try sema.errNote(block, operand_info[chosen][1], msg, "selected index '{d}' out of bounds of '{}'", .{
24395 try sema.errNote(operand_info[chosen][1], msg, "selected index '{d}' out of bounds of '{}'", .{
2451824396 unsigned,
2451924397 operand_info[chosen][2].fmt(sema.mod),
2452024398 });
2452124399
2452224400 if (chosen == 0) {
24523 try sema.errNote(block, b_src, msg, "selections from the second vector are specified with negative numbers", .{});
24401 try sema.errNote(b_src, msg, "selections from the second vector are specified with negative numbers", .{});
2452424402 }
2452524403
2452624404 break :msg msg;
......@@ -24598,11 +24476,11 @@ fn zirSelect(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) C
2459824476 const mod = sema.mod;
2459924477 const extra = sema.code.extraData(Zir.Inst.Select, extended.operand).data;
2460024478
24601 const src = LazySrcLoc.nodeOffset(extra.node);
24602 const elem_ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node };
24603 const pred_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = extra.node };
24604 const a_src: LazySrcLoc = .{ .node_offset_builtin_call_arg2 = extra.node };
24605 const b_src: LazySrcLoc = .{ .node_offset_builtin_call_arg3 = extra.node };
24479 const src = block.nodeOffset(extra.node);
24480 const elem_ty_src = block.builtinCallArgSrc(extra.node, 0);
24481 const pred_src = block.builtinCallArgSrc(extra.node, 1);
24482 const a_src = block.builtinCallArgSrc(extra.node, 2);
24483 const b_src = block.builtinCallArgSrc(extra.node, 3);
2460624484
2460724485 const elem_ty = try sema.resolveType(block, elem_ty_src, extra.elem_type);
2460824486 try sema.checkVectorElemType(block, elem_ty_src, elem_ty);
......@@ -24689,9 +24567,9 @@ fn zirAtomicLoad(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
2468924567 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
2469024568 const extra = sema.code.extraData(Zir.Inst.AtomicLoad, inst_data.payload_index).data;
2469124569 // zig fmt: off
24692 const elem_ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
24693 const ptr_src : LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };
24694 const order_src : LazySrcLoc = .{ .node_offset_builtin_call_arg2 = inst_data.src_node };
24570 const elem_ty_src = block.builtinCallArgSrc(inst_data.src_node, 0);
24571 const ptr_src = block.builtinCallArgSrc(inst_data.src_node, 1);
24572 const order_src = block.builtinCallArgSrc(inst_data.src_node, 2);
2469524573 // zig fmt: on
2469624574 const elem_ty = try sema.resolveType(block, elem_ty_src, extra.elem_type);
2469724575 const uncasted_ptr = try sema.resolveInst(extra.ptr);
......@@ -24738,11 +24616,11 @@ fn zirAtomicRmw(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
2473824616 const extra = sema.code.extraData(Zir.Inst.AtomicRmw, inst_data.payload_index).data;
2473924617 const src = block.nodeOffset(inst_data.src_node);
2474024618 // zig fmt: off
24741 const elem_ty_src : LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
24742 const ptr_src : LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };
24743 const op_src : LazySrcLoc = .{ .node_offset_builtin_call_arg2 = inst_data.src_node };
24744 const operand_src : LazySrcLoc = .{ .node_offset_builtin_call_arg3 = inst_data.src_node };
24745 const order_src : LazySrcLoc = .{ .node_offset_builtin_call_arg4 = inst_data.src_node };
24619 const elem_ty_src = block.builtinCallArgSrc(inst_data.src_node, 0);
24620 const ptr_src = block.builtinCallArgSrc(inst_data.src_node, 1);
24621 const op_src = block.builtinCallArgSrc(inst_data.src_node, 2);
24622 const operand_src = block.builtinCallArgSrc(inst_data.src_node, 3);
24623 const order_src = block.builtinCallArgSrc(inst_data.src_node, 4);
2474624624 // zig fmt: on
2474724625 const operand = try sema.resolveInst(extra.operand);
2474824626 const elem_ty = sema.typeOf(operand);
......@@ -24823,10 +24701,10 @@ fn zirAtomicStore(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
2482324701 const extra = sema.code.extraData(Zir.Inst.AtomicStore, inst_data.payload_index).data;
2482424702 const src = block.nodeOffset(inst_data.src_node);
2482524703 // zig fmt: off
24826 const elem_ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
24827 const ptr_src : LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };
24828 const operand_src : LazySrcLoc = .{ .node_offset_builtin_call_arg2 = inst_data.src_node };
24829 const order_src : LazySrcLoc = .{ .node_offset_builtin_call_arg3 = inst_data.src_node };
24704 const elem_ty_src = block.builtinCallArgSrc(inst_data.src_node, 0);
24705 const ptr_src = block.builtinCallArgSrc(inst_data.src_node, 1);
24706 const operand_src = block.builtinCallArgSrc(inst_data.src_node, 2);
24707 const order_src = block.builtinCallArgSrc(inst_data.src_node, 3);
2483024708 // zig fmt: on
2483124709 const operand = try sema.resolveInst(extra.operand);
2483224710 const elem_ty = sema.typeOf(operand);
......@@ -24859,9 +24737,9 @@ fn zirMulAdd(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
2485924737 const extra = sema.code.extraData(Zir.Inst.MulAdd, inst_data.payload_index).data;
2486024738 const src = block.nodeOffset(inst_data.src_node);
2486124739
24862 const mulend1_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };
24863 const mulend2_src: LazySrcLoc = .{ .node_offset_builtin_call_arg2 = inst_data.src_node };
24864 const addend_src: LazySrcLoc = .{ .node_offset_builtin_call_arg3 = inst_data.src_node };
24740 const mulend1_src = block.builtinCallArgSrc(inst_data.src_node, 1);
24741 const mulend2_src = block.builtinCallArgSrc(inst_data.src_node, 2);
24742 const addend_src = block.builtinCallArgSrc(inst_data.src_node, 3);
2486524743
2486624744 const addend = try sema.resolveInst(extra.addend);
2486724745 const ty = sema.typeOf(addend);
......@@ -24924,9 +24802,9 @@ fn zirBuiltinCall(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
2492424802
2492524803 const mod = sema.mod;
2492624804 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
24927 const modifier_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
24928 const func_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };
24929 const args_src: LazySrcLoc = .{ .node_offset_builtin_call_arg2 = inst_data.src_node };
24805 const modifier_src = block.builtinCallArgSrc(inst_data.src_node, 0);
24806 const func_src = block.builtinCallArgSrc(inst_data.src_node, 1);
24807 const args_src = block.builtinCallArgSrc(inst_data.src_node, 2);
2493024808 const call_src = block.nodeOffset(inst_data.src_node);
2493124809
2493224810 const extra = sema.code.extraData(Zir.Inst.BuiltinCall, inst_data.payload_index).data;
......@@ -25022,8 +24900,8 @@ fn zirFieldParentPtr(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.Ins
2502224900 const flags: Zir.Inst.FullPtrCastFlags = @bitCast(@as(FlagsInt, @truncate(extended.small)));
2502324901 assert(!flags.ptr_cast);
2502424902 const inst_src = block.nodeOffset(extra.src_node);
25025 const field_name_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.src_node };
25026 const field_ptr_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = extra.src_node };
24903 const field_name_src = block.builtinCallArgSrc(extra.src_node, 0);
24904 const field_ptr_src = block.builtinCallArgSrc(extra.src_node, 1);
2502724905
2502824906 const parent_ptr_ty = try sema.resolveDestType(block, inst_src, extra.parent_ptr_type, .remove_eu, "@fieldParentPtr");
2502924907 try sema.checkPtrType(block, inst_src, parent_ptr_ty, true);
......@@ -25212,9 +25090,9 @@ fn ptrSubtract(sema: *Sema, block: *Block, src: LazySrcLoc, ptr_val: Value, byte
2521225090 };
2521325091 if (ptr.byte_offset < byte_subtract) {
2521425092 return sema.failWithOwnedErrorMsg(block, msg: {
25215 const msg = try sema.errMsg(block, src, "pointer computation here causes undefined behavior", .{});
25093 const msg = try sema.errMsg(src, "pointer computation here causes undefined behavior", .{});
2521625094 errdefer msg.destroy(sema.gpa);
25217 try sema.errNote(block, src, msg, "resulting pointer exceeds bounds of containing value which may trigger overflow", .{});
25095 try sema.errNote(src, msg, "resulting pointer exceeds bounds of containing value which may trigger overflow", .{});
2521825096 break :msg msg;
2521925097 });
2522025098 }
......@@ -25232,8 +25110,8 @@ fn zirMinMax(
2523225110 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
2523325111 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
2523425112 const src = block.nodeOffset(inst_data.src_node);
25235 const lhs_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
25236 const rhs_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };
25113 const lhs_src = block.builtinCallArgSrc(inst_data.src_node, 0);
25114 const rhs_src = block.builtinCallArgSrc(inst_data.src_node, 1);
2523725115 const lhs = try sema.resolveInst(extra.lhs);
2523825116 const rhs = try sema.resolveInst(extra.rhs);
2523925117 try sema.checkNumericType(block, lhs_src, sema.typeOf(lhs));
......@@ -25249,22 +25127,14 @@ fn zirMinMaxMulti(
2524925127) CompileError!Air.Inst.Ref {
2525025128 const extra = sema.code.extraData(Zir.Inst.NodeMultiOp, extended.operand);
2525125129 const src_node = extra.data.src_node;
25252 const src = LazySrcLoc.nodeOffset(src_node);
25130 const src = block.nodeOffset(src_node);
2525325131 const operands = sema.code.refSlice(extra.end, extended.small);
2525425132
2525525133 const air_refs = try sema.arena.alloc(Air.Inst.Ref, operands.len);
2525625134 const operand_srcs = try sema.arena.alloc(LazySrcLoc, operands.len);
2525725135
2525825136 for (operands, air_refs, operand_srcs, 0..) |zir_ref, *air_ref, *op_src, i| {
25259 op_src.* = switch (i) {
25260 0 => .{ .node_offset_builtin_call_arg0 = src_node },
25261 1 => .{ .node_offset_builtin_call_arg1 = src_node },
25262 2 => .{ .node_offset_builtin_call_arg2 = src_node },
25263 3 => .{ .node_offset_builtin_call_arg3 = src_node },
25264 4 => .{ .node_offset_builtin_call_arg4 = src_node },
25265 5 => .{ .node_offset_builtin_call_arg5 = src_node },
25266 else => src, // TODO: better source location
25267 };
25137 op_src.* = block.builtinCallArgSrc(src_node, @intCast(i));
2526825138 air_ref.* = try sema.resolveInst(zir_ref);
2526925139 try sema.checkNumericType(block, op_src.*, sema.typeOf(air_ref.*));
2527025140 }
......@@ -25533,8 +25403,8 @@ fn zirMemcpy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void
2553325403 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
2553425404 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
2553525405 const src = block.nodeOffset(inst_data.src_node);
25536 const dest_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
25537 const src_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };
25406 const dest_src = block.builtinCallArgSrc(inst_data.src_node, 0);
25407 const src_src = block.builtinCallArgSrc(inst_data.src_node, 1);
2553825408 const dest_ptr = try sema.resolveInst(extra.lhs);
2553925409 const src_ptr = try sema.resolveInst(extra.rhs);
2554025410 const dest_ty = sema.typeOf(dest_ptr);
......@@ -25550,12 +25420,12 @@ fn zirMemcpy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void
2555025420
2555125421 if (dest_len == .none and src_len == .none) {
2555225422 const msg = msg: {
25553 const msg = try sema.errMsg(block, src, "unknown @memcpy length", .{});
25423 const msg = try sema.errMsg(src, "unknown @memcpy length", .{});
2555425424 errdefer msg.destroy(sema.gpa);
25555 try sema.errNote(block, dest_src, msg, "destination type '{}' provides no length", .{
25425 try sema.errNote(dest_src, msg, "destination type '{}' provides no length", .{
2555625426 dest_ty.fmt(sema.mod),
2555725427 });
25558 try sema.errNote(block, src_src, msg, "source type '{}' provides no length", .{
25428 try sema.errNote(src_src, msg, "source type '{}' provides no length", .{
2555925429 src_ty.fmt(sema.mod),
2556025430 });
2556125431 break :msg msg;
......@@ -25572,12 +25442,12 @@ fn zirMemcpy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void
2557225442 if (try sema.resolveDefinedValue(block, src_src, src_len)) |src_len_val| {
2557325443 if (!(try sema.valuesEqual(dest_len_val, src_len_val, Type.usize))) {
2557425444 const msg = msg: {
25575 const msg = try sema.errMsg(block, src, "non-matching @memcpy lengths", .{});
25445 const msg = try sema.errMsg(src, "non-matching @memcpy lengths", .{});
2557625446 errdefer msg.destroy(sema.gpa);
25577 try sema.errNote(block, dest_src, msg, "length {} here", .{
25447 try sema.errNote(dest_src, msg, "length {} here", .{
2557825448 dest_len_val.fmtValue(sema.mod, sema),
2557925449 });
25580 try sema.errNote(block, src_src, msg, "length {} here", .{
25450 try sema.errNote(src_src, msg, "length {} here", .{
2558125451 src_len_val.fmtValue(sema.mod, sema),
2558225452 });
2558325453 break :msg msg;
......@@ -25685,7 +25555,7 @@ fn zirMemcpy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void
2568525555 } else if (dest_len == .none and len_val == null) {
2568625556 // Change the dest to a slice, since its type must have the length.
2568725557 const dest_ptr_ptr = try sema.analyzeRef(block, dest_src, new_dest_ptr);
25688 new_dest_ptr = try sema.analyzeSlice(block, dest_src, dest_ptr_ptr, .zero, src_len, .none, .unneeded, dest_src, dest_src, dest_src, false);
25558 new_dest_ptr = try sema.analyzeSlice(block, dest_src, dest_ptr_ptr, .zero, src_len, .none, LazySrcLoc.unneeded, dest_src, dest_src, dest_src, false);
2568925559 const new_src_ptr_ty = sema.typeOf(new_src_ptr);
2569025560 if (new_src_ptr_ty.isSlice(mod)) {
2569125561 new_src_ptr = try sema.analyzeSlicePtr(block, src_src, new_src_ptr, new_src_ptr_ty);
......@@ -25753,8 +25623,8 @@ fn zirMemset(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void
2575325623 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
2575425624 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
2575525625 const src = block.nodeOffset(inst_data.src_node);
25756 const dest_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
25757 const value_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };
25626 const dest_src = block.builtinCallArgSrc(inst_data.src_node, 0);
25627 const value_src = block.builtinCallArgSrc(inst_data.src_node, 1);
2575825628 const dest_ptr = try sema.resolveInst(extra.lhs);
2575925629 const uncoerced_elem = try sema.resolveInst(extra.rhs);
2576025630 const dest_ptr_ty = sema.typeOf(dest_ptr);
......@@ -25776,9 +25646,9 @@ fn zirMemset(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void
2577625646 .Many, .C => {},
2577725647 }
2577825648 return sema.failWithOwnedErrorMsg(block, msg: {
25779 const msg = try sema.errMsg(block, src, "unknown @memset length", .{});
25649 const msg = try sema.errMsg(src, "unknown @memset length", .{});
2578025650 errdefer msg.destroy(sema.gpa);
25781 try sema.errNote(block, dest_src, msg, "destination type '{}' provides no length", .{
25651 try sema.errNote(dest_src, msg, "destination type '{}' provides no length", .{
2578225652 dest_ptr_ty.fmt(mod),
2578325653 });
2578425654 break :msg msg;
......@@ -25831,7 +25701,7 @@ fn zirMemset(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void
2583125701
2583225702fn zirBuiltinAsyncCall(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!Air.Inst.Ref {
2583325703 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;
25834 const src = LazySrcLoc.nodeOffset(extra.node);
25704 const src = block.nodeOffset(extra.node);
2583525705 return sema.failWithUseOfAsync(block, src);
2583625706}
2583725707
......@@ -25858,7 +25728,7 @@ fn zirAwaitNosuspend(
2585825728 extended: Zir.Inst.Extended.InstData,
2585925729) CompileError!Air.Inst.Ref {
2586025730 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;
25861 const src = LazySrcLoc.nodeOffset(extra.node);
25731 const src = block.nodeOffset(extra.node);
2586225732
2586325733 return sema.failWithUseOfAsync(block, src);
2586425734}
......@@ -25870,8 +25740,8 @@ fn zirVarExtended(
2587025740) CompileError!Air.Inst.Ref {
2587125741 const mod = sema.mod;
2587225742 const extra = sema.code.extraData(Zir.Inst.ExtendedVar, extended.operand);
25873 const ty_src: LazySrcLoc = .{ .node_offset_var_decl_ty = 0 };
25874 const init_src: LazySrcLoc = .{ .node_offset_var_decl_init = 0 };
25743 const ty_src = block.src(.{ .node_offset_var_decl_ty = 0 });
25744 const init_src = block.src(.{ .node_offset_var_decl_init = 0 });
2587525745 const small: Zir.Inst.ExtendedVar.Small = @bitCast(extended.small);
2587625746
2587725747 var extra_index: usize = extra.end;
......@@ -25936,11 +25806,11 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
2593625806 const extra = sema.code.extraData(Zir.Inst.FuncFancy, inst_data.payload_index);
2593725807 const target = mod.getTarget();
2593825808
25939 const align_src: LazySrcLoc = .{ .node_offset_fn_type_align = inst_data.src_node };
25940 const addrspace_src: LazySrcLoc = .{ .node_offset_fn_type_addrspace = inst_data.src_node };
25941 const section_src: LazySrcLoc = .{ .node_offset_fn_type_section = inst_data.src_node };
25942 const cc_src: LazySrcLoc = .{ .node_offset_fn_type_cc = inst_data.src_node };
25943 const ret_src: LazySrcLoc = .{ .node_offset_fn_type_ret_ty = inst_data.src_node };
25809 const align_src = block.src(.{ .node_offset_fn_type_align = inst_data.src_node });
25810 const addrspace_src = block.src(.{ .node_offset_fn_type_addrspace = inst_data.src_node });
25811 const section_src = block.src(.{ .node_offset_fn_type_section = inst_data.src_node });
25812 const cc_src = block.src(.{ .node_offset_fn_type_cc = inst_data.src_node });
25813 const ret_src = block.src(.{ .node_offset_fn_type_ret_ty = inst_data.src_node });
2594425814 const has_body = extra.data.body_len != 0;
2594525815
2594625816 var extra_index: usize = extra.end;
......@@ -26167,7 +26037,7 @@ fn zirCUndef(
2616726037 extended: Zir.Inst.Extended.InstData,
2616826038) CompileError!Air.Inst.Ref {
2616926039 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;
26170 const src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node };
26040 const src = block.builtinCallArgSrc(extra.node, 0);
2617126041
2617226042 const name = try sema.resolveConstString(block, src, extra.operand, .{
2617326043 .needed_comptime_reason = "name of macro being undefined must be comptime-known",
......@@ -26182,7 +26052,7 @@ fn zirCInclude(
2618226052 extended: Zir.Inst.Extended.InstData,
2618326053) CompileError!Air.Inst.Ref {
2618426054 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;
26185 const src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node };
26055 const src = block.builtinCallArgSrc(extra.node, 0);
2618626056
2618726057 const name = try sema.resolveConstString(block, src, extra.operand, .{
2618826058 .needed_comptime_reason = "path being included must be comptime-known",
......@@ -26198,8 +26068,8 @@ fn zirCDefine(
2619826068) CompileError!Air.Inst.Ref {
2619926069 const mod = sema.mod;
2620026070 const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data;
26201 const name_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node };
26202 const val_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = extra.node };
26071 const name_src = block.builtinCallArgSrc(extra.node, 0);
26072 const val_src = block.builtinCallArgSrc(extra.node, 1);
2620326073
2620426074 const name = try sema.resolveConstString(block, name_src, extra.lhs, .{
2620526075 .needed_comptime_reason = "name of macro being undefined must be comptime-known",
......@@ -26222,8 +26092,8 @@ fn zirWasmMemorySize(
2622226092 extended: Zir.Inst.Extended.InstData,
2622326093) CompileError!Air.Inst.Ref {
2622426094 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;
26225 const index_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node };
26226 const builtin_src = LazySrcLoc.nodeOffset(extra.node);
26095 const index_src = block.builtinCallArgSrc(extra.node, 0);
26096 const builtin_src = block.nodeOffset(extra.node);
2622726097 const target = sema.mod.getTarget();
2622826098 if (!target.isWasm()) {
2622926099 return sema.fail(block, builtin_src, "builtin @wasmMemorySize is available when targeting WebAssembly; targeted CPU architecture is {s}", .{@tagName(target.cpu.arch)});
......@@ -26248,9 +26118,9 @@ fn zirWasmMemoryGrow(
2624826118 extended: Zir.Inst.Extended.InstData,
2624926119) CompileError!Air.Inst.Ref {
2625026120 const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data;
26251 const builtin_src = LazySrcLoc.nodeOffset(extra.node);
26252 const index_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node };
26253 const delta_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = extra.node };
26121 const builtin_src = block.nodeOffset(extra.node);
26122 const index_src = block.builtinCallArgSrc(extra.node, 0);
26123 const delta_src = block.builtinCallArgSrc(extra.node, 1);
2625426124 const target = sema.mod.getTarget();
2625526125 if (!target.isWasm()) {
2625626126 return sema.fail(block, builtin_src, "builtin @wasmMemoryGrow is available when targeting WebAssembly; targeted CPU architecture is {s}", .{@tagName(target.cpu.arch)});
......@@ -26283,9 +26153,9 @@ fn resolvePrefetchOptions(
2628326153 const options_ty = try sema.getBuiltinType("PrefetchOptions");
2628426154 const options = try sema.coerce(block, options_ty, try sema.resolveInst(zir_ref), src);
2628526155
26286 const rw_src = sema.maybeOptionsSrc(block, src, "rw");
26287 const locality_src = sema.maybeOptionsSrc(block, src, "locality");
26288 const cache_src = sema.maybeOptionsSrc(block, src, "cache");
26156 const rw_src = block.src(.{ .init_field_rw = src.offset.node_offset_builtin_call_arg.builtin_call_node });
26157 const locality_src = block.src(.{ .init_field_locality = src.offset.node_offset_builtin_call_arg.builtin_call_node });
26158 const cache_src = block.src(.{ .init_field_cache = src.offset.node_offset_builtin_call_arg.builtin_call_node });
2628926159
2629026160 const rw = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "rw", .no_embedded_nulls), rw_src);
2629126161 const rw_val = try sema.resolveConstDefinedValue(block, rw_src, rw, .{
......@@ -26315,18 +26185,12 @@ fn zirPrefetch(
2631526185 extended: Zir.Inst.Extended.InstData,
2631626186) CompileError!Air.Inst.Ref {
2631726187 const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data;
26318 const ptr_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node };
26319 const opts_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = extra.node };
26188 const ptr_src = block.builtinCallArgSrc(extra.node, 0);
26189 const opts_src = block.builtinCallArgSrc(extra.node, 1);
2632026190 const ptr = try sema.resolveInst(extra.lhs);
2632126191 try sema.checkPtrOperand(block, ptr_src, sema.typeOf(ptr));
2632226192
26323 const options = sema.resolvePrefetchOptions(block, .unneeded, extra.rhs) catch |err| switch (err) {
26324 error.NeededSourceLocation => {
26325 _ = try sema.resolvePrefetchOptions(block, opts_src, extra.rhs);
26326 unreachable;
26327 },
26328 else => |e| return e,
26329 };
26193 const options = try sema.resolvePrefetchOptions(block, opts_src, extra.rhs);
2633026194
2633126195 if (!block.is_comptime) {
2633226196 _ = try block.addInst(.{
......@@ -26361,10 +26225,10 @@ fn resolveExternOptions(
2636126225 const extern_options_ty = try sema.getBuiltinType("ExternOptions");
2636226226 const options = try sema.coerce(block, extern_options_ty, options_inst, src);
2636326227
26364 const name_src = sema.maybeOptionsSrc(block, src, "name");
26365 const library_src = sema.maybeOptionsSrc(block, src, "library");
26366 const linkage_src = sema.maybeOptionsSrc(block, src, "linkage");
26367 const thread_local_src = sema.maybeOptionsSrc(block, src, "thread_local");
26228 const name_src = block.src(.{ .init_field_name = src.offset.node_offset_builtin_call_arg.builtin_call_node });
26229 const library_src = block.src(.{ .init_field_library = src.offset.node_offset_builtin_call_arg.builtin_call_node });
26230 const linkage_src = block.src(.{ .init_field_linkage = src.offset.node_offset_builtin_call_arg.builtin_call_node });
26231 const thread_local_src = block.src(.{ .init_field_thread_local = src.offset.node_offset_builtin_call_arg.builtin_call_node });
2636826232
2636926233 const name_ref = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "name", .no_embedded_nulls), name_src);
2637026234 const name = try sema.toConstString(block, name_src, name_ref, .{
......@@ -26422,8 +26286,8 @@ fn zirBuiltinExtern(
2642226286 const mod = sema.mod;
2642326287 const ip = &mod.intern_pool;
2642426288 const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data;
26425 const ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node };
26426 const options_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = extra.node };
26289 const ty_src = block.builtinCallArgSrc(extra.node, 0);
26290 const options_src = block.builtinCallArgSrc(extra.node, 1);
2642726291
2642826292 var ty = try sema.resolveType(block, ty_src, extra.lhs);
2642926293 if (!ty.isPtrAtRuntime(mod)) {
......@@ -26431,29 +26295,22 @@ fn zirBuiltinExtern(
2643126295 }
2643226296 if (!try sema.validateExternType(ty, .other)) {
2643326297 const msg = msg: {
26434 const msg = try sema.errMsg(block, ty_src, "extern symbol cannot have type '{}'", .{ty.fmt(mod)});
26298 const msg = try sema.errMsg(ty_src, "extern symbol cannot have type '{}'", .{ty.fmt(mod)});
2643526299 errdefer msg.destroy(sema.gpa);
26436 const src_decl = sema.mod.declPtr(block.src_decl);
26437 try sema.explainWhyTypeIsNotExtern(msg, src_decl.toSrcLoc(ty_src, mod), ty, .other);
26300 try sema.explainWhyTypeIsNotExtern(msg, ty_src, ty, .other);
2643826301 break :msg msg;
2643926302 };
2644026303 return sema.failWithOwnedErrorMsg(block, msg);
2644126304 }
2644226305
26443 const options = sema.resolveExternOptions(block, .unneeded, extra.rhs) catch |err| switch (err) {
26444 error.NeededSourceLocation => {
26445 _ = try sema.resolveExternOptions(block, options_src, extra.rhs);
26446 unreachable;
26447 },
26448 else => |e| return e,
26449 };
26306 const options = try sema.resolveExternOptions(block, options_src, extra.rhs);
2645026307
2645126308 if (options.linkage == .weak and !ty.ptrAllowsZero(mod)) {
2645226309 ty = try mod.optionalType(ty.toIntern());
2645326310 }
2645426311 const ptr_info = ty.ptrInfo(mod);
2645526312
26456 const new_decl_index = try mod.allocateNewDecl(sema.owner_decl.src_namespace, sema.owner_decl.src_node);
26313 const new_decl_index = try mod.allocateNewDecl(sema.owner_decl.src_namespace);
2645726314 errdefer mod.destroyDecl(new_decl_index);
2645826315 const new_decl = mod.declPtr(new_decl_index);
2645926316 try mod.initNewAnonDecl(
......@@ -26503,8 +26360,8 @@ fn zirWorkItem(
2650326360 zir_tag: Zir.Inst.Extended,
2650426361) CompileError!Air.Inst.Ref {
2650526362 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;
26506 const dimension_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node };
26507 const builtin_src = LazySrcLoc.nodeOffset(extra.node);
26363 const dimension_src = block.builtinCallArgSrc(extra.node, 0);
26364 const builtin_src = block.nodeOffset(extra.node);
2650826365 const target = sema.mod.getTarget();
2650926366
2651026367 switch (target.cpu.arch) {
......@@ -26545,11 +26402,11 @@ fn zirInComptime(
2654526402fn requireRuntimeBlock(sema: *Sema, block: *Block, src: LazySrcLoc, runtime_src: ?LazySrcLoc) !void {
2654626403 if (block.is_comptime) {
2654726404 const msg = msg: {
26548 const msg = try sema.errMsg(block, src, "unable to evaluate comptime expression", .{});
26405 const msg = try sema.errMsg(src, "unable to evaluate comptime expression", .{});
2654926406 errdefer msg.destroy(sema.gpa);
2655026407
2655126408 if (runtime_src) |some| {
26552 try sema.errNote(block, some, msg, "operation is runtime due to this operand", .{});
26409 try sema.errNote(some, msg, "operation is runtime due to this operand", .{});
2655326410 }
2655426411 if (block.comptime_reason) |some| {
2655526412 try some.explain(sema, msg);
......@@ -26572,10 +26429,9 @@ fn validateVarType(
2657226429 if (is_extern) {
2657326430 if (!try sema.validateExternType(var_ty, .other)) {
2657426431 const msg = msg: {
26575 const msg = try sema.errMsg(block, src, "extern variable cannot have type '{}'", .{var_ty.fmt(mod)});
26432 const msg = try sema.errMsg(src, "extern variable cannot have type '{}'", .{var_ty.fmt(mod)});
2657626433 errdefer msg.destroy(sema.gpa);
26577 const src_decl = mod.declPtr(block.src_decl);
26578 try sema.explainWhyTypeIsNotExtern(msg, src_decl.toSrcLoc(src, mod), var_ty, .other);
26434 try sema.explainWhyTypeIsNotExtern(msg, src, var_ty, .other);
2657926435 break :msg msg;
2658026436 };
2658126437 return sema.failWithOwnedErrorMsg(block, msg);
......@@ -26594,13 +26450,12 @@ fn validateVarType(
2659426450 if (!try sema.typeRequiresComptime(var_ty)) return;
2659526451
2659626452 const msg = msg: {
26597 const msg = try sema.errMsg(block, src, "variable of type '{}' must be const or comptime", .{var_ty.fmt(mod)});
26453 const msg = try sema.errMsg(src, "variable of type '{}' must be const or comptime", .{var_ty.fmt(mod)});
2659826454 errdefer msg.destroy(sema.gpa);
2659926455
26600 const src_decl = mod.declPtr(block.src_decl);
26601 try sema.explainWhyTypeIsComptime(msg, src_decl.toSrcLoc(src, mod), var_ty);
26456 try sema.explainWhyTypeIsComptime(msg, src, var_ty);
2660226457 if (var_ty.zigTypeTag(mod) == .ComptimeInt or var_ty.zigTypeTag(mod) == .ComptimeFloat) {
26603 try sema.errNote(block, src, msg, "to modify this variable at runtime, it must be given an explicit fixed-size number type", .{});
26458 try sema.errNote(src, msg, "to modify this variable at runtime, it must be given an explicit fixed-size number type", .{});
2660426459 }
2660526460
2660626461 break :msg msg;
......@@ -26613,7 +26468,7 @@ const TypeSet = std.AutoHashMapUnmanaged(InternPool.Index, void);
2661326468fn explainWhyTypeIsComptime(
2661426469 sema: *Sema,
2661526470 msg: *Module.ErrorMsg,
26616 src_loc: Module.SrcLoc,
26471 src_loc: LazySrcLoc,
2661726472 ty: Type,
2661826473) CompileError!void {
2661926474 var type_set = TypeSet{};
......@@ -26626,7 +26481,7 @@ fn explainWhyTypeIsComptime(
2662626481fn explainWhyTypeIsComptimeInner(
2662726482 sema: *Sema,
2662826483 msg: *Module.ErrorMsg,
26629 src_loc: Module.SrcLoc,
26484 src_loc: LazySrcLoc,
2663026485 ty: Type,
2663126486 type_set: *TypeSet,
2663226487) CompileError!void {
......@@ -26644,13 +26499,13 @@ fn explainWhyTypeIsComptimeInner(
2664426499 => return,
2664526500
2664626501 .Fn => {
26647 try mod.errNoteNonLazy(src_loc, msg, "use '*const {}' for a function pointer type", .{
26502 try sema.errNote(src_loc, msg, "use '*const {}' for a function pointer type", .{
2664826503 ty.fmt(sema.mod),
2664926504 });
2665026505 },
2665126506
2665226507 .Type => {
26653 try mod.errNoteNonLazy(src_loc, msg, "types are not available at runtime", .{});
26508 try sema.errNote(src_loc, msg, "types are not available at runtime", .{});
2665426509 },
2665526510
2665626511 .ComptimeFloat,
......@@ -26662,7 +26517,7 @@ fn explainWhyTypeIsComptimeInner(
2666226517 => return,
2666326518
2666426519 .Opaque => {
26665 try mod.errNoteNonLazy(src_loc, msg, "opaque type '{}' has undefined size", .{ty.fmt(sema.mod)});
26520 try sema.errNote(src_loc, msg, "opaque type '{}' has undefined size", .{ty.fmt(sema.mod)});
2666626521 },
2666726522
2666826523 .Array, .Vector => {
......@@ -26673,14 +26528,14 @@ fn explainWhyTypeIsComptimeInner(
2667326528 if (elem_ty.zigTypeTag(mod) == .Fn) {
2667426529 const fn_info = mod.typeToFunc(elem_ty).?;
2667526530 if (fn_info.is_generic) {
26676 try mod.errNoteNonLazy(src_loc, msg, "function is generic", .{});
26531 try sema.errNote(src_loc, msg, "function is generic", .{});
2667726532 }
2667826533 switch (fn_info.cc) {
26679 .Inline => try mod.errNoteNonLazy(src_loc, msg, "function has inline calling convention", .{}),
26534 .Inline => try sema.errNote(src_loc, msg, "function has inline calling convention", .{}),
2668026535 else => {},
2668126536 }
2668226537 if (Type.fromInterned(fn_info.return_type).comptimeOnly(mod)) {
26683 try mod.errNoteNonLazy(src_loc, msg, "function has a comptime-only return type", .{});
26538 try sema.errNote(src_loc, msg, "function has a comptime-only return type", .{});
2668426539 }
2668526540 return;
2668626541 }
......@@ -26700,14 +26555,14 @@ fn explainWhyTypeIsComptimeInner(
2670026555 if (mod.typeToStruct(ty)) |struct_type| {
2670126556 for (0..struct_type.field_types.len) |i| {
2670226557 const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[i]);
26703 const field_src_loc = mod.fieldSrcLoc(struct_type.decl.unwrap().?, .{
26704 .index = i,
26705 .range = .type,
26706 });
26558 const field_src: LazySrcLoc = .{
26559 .base_node_inst = struct_type.zir_index.unwrap().?,
26560 .offset = .{ .container_field_type = @intCast(i) },
26561 };
2670726562
2670826563 if (try sema.typeRequiresComptime(field_ty)) {
26709 try mod.errNoteNonLazy(field_src_loc, msg, "struct requires comptime because of this field", .{});
26710 try sema.explainWhyTypeIsComptimeInner(msg, field_src_loc, field_ty, type_set);
26564 try sema.errNote(field_src, msg, "struct requires comptime because of this field", .{});
26565 try sema.explainWhyTypeIsComptimeInner(msg, field_src, field_ty, type_set);
2671126566 }
2671226567 }
2671326568 }
......@@ -26720,14 +26575,14 @@ fn explainWhyTypeIsComptimeInner(
2672026575 if (mod.typeToUnion(ty)) |union_obj| {
2672126576 for (0..union_obj.field_types.len) |i| {
2672226577 const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[i]);
26723 const field_src_loc = mod.fieldSrcLoc(union_obj.decl, .{
26724 .index = i,
26725 .range = .type,
26726 });
26578 const field_src: LazySrcLoc = .{
26579 .base_node_inst = union_obj.zir_index,
26580 .offset = .{ .container_field_type = @intCast(i) },
26581 };
2672726582
2672826583 if (try sema.typeRequiresComptime(field_ty)) {
26729 try mod.errNoteNonLazy(field_src_loc, msg, "union requires comptime because of this field", .{});
26730 try sema.explainWhyTypeIsComptimeInner(msg, field_src_loc, field_ty, type_set);
26584 try sema.errNote(field_src, msg, "union requires comptime because of this field", .{});
26585 try sema.explainWhyTypeIsComptimeInner(msg, field_src, field_ty, type_set);
2673126586 }
2673226587 }
2673326588 }
......@@ -26817,7 +26672,7 @@ fn validateExternType(
2681726672fn explainWhyTypeIsNotExtern(
2681826673 sema: *Sema,
2681926674 msg: *Module.ErrorMsg,
26820 src_loc: Module.SrcLoc,
26675 src_loc: LazySrcLoc,
2682126676 ty: Type,
2682226677 position: ExternPosition,
2682326678) CompileError!void {
......@@ -26842,55 +26697,55 @@ fn explainWhyTypeIsNotExtern(
2684226697
2684326698 .Pointer => {
2684426699 if (ty.isSlice(mod)) {
26845 try mod.errNoteNonLazy(src_loc, msg, "slices have no guaranteed in-memory representation", .{});
26700 try sema.errNote(src_loc, msg, "slices have no guaranteed in-memory representation", .{});
2684626701 } else {
2684726702 const pointee_ty = ty.childType(mod);
2684826703 if (!ty.isConstPtr(mod) and pointee_ty.zigTypeTag(mod) == .Fn) {
26849 try mod.errNoteNonLazy(src_loc, msg, "pointer to extern function must be 'const'", .{});
26704 try sema.errNote(src_loc, msg, "pointer to extern function must be 'const'", .{});
2685026705 } else if (try sema.typeRequiresComptime(ty)) {
26851 try mod.errNoteNonLazy(src_loc, msg, "pointer to comptime-only type '{}'", .{pointee_ty.fmt(sema.mod)});
26706 try sema.errNote(src_loc, msg, "pointer to comptime-only type '{}'", .{pointee_ty.fmt(sema.mod)});
2685226707 try sema.explainWhyTypeIsComptime(msg, src_loc, ty);
2685326708 }
2685426709 try sema.explainWhyTypeIsNotExtern(msg, src_loc, pointee_ty, .other);
2685526710 }
2685626711 },
26857 .Void => try mod.errNoteNonLazy(src_loc, msg, "'void' is a zero bit type; for C 'void' use 'anyopaque'", .{}),
26858 .NoReturn => try mod.errNoteNonLazy(src_loc, msg, "'noreturn' is only allowed as a return type", .{}),
26712 .Void => try sema.errNote(src_loc, msg, "'void' is a zero bit type; for C 'void' use 'anyopaque'", .{}),
26713 .NoReturn => try sema.errNote(src_loc, msg, "'noreturn' is only allowed as a return type", .{}),
2685926714 .Int => if (!std.math.isPowerOfTwo(ty.intInfo(mod).bits)) {
26860 try mod.errNoteNonLazy(src_loc, msg, "only integers with 0 or power of two bits are extern compatible", .{});
26715 try sema.errNote(src_loc, msg, "only integers with 0 or power of two bits are extern compatible", .{});
2686126716 } else {
26862 try mod.errNoteNonLazy(src_loc, msg, "only integers with 0, 8, 16, 32, 64 and 128 bits are extern compatible", .{});
26717 try sema.errNote(src_loc, msg, "only integers with 0, 8, 16, 32, 64 and 128 bits are extern compatible", .{});
2686326718 },
2686426719 .Fn => {
2686526720 if (position != .other) {
26866 try mod.errNoteNonLazy(src_loc, msg, "type has no guaranteed in-memory representation", .{});
26867 try mod.errNoteNonLazy(src_loc, msg, "use '*const ' to make a function pointer type", .{});
26721 try sema.errNote(src_loc, msg, "type has no guaranteed in-memory representation", .{});
26722 try sema.errNote(src_loc, msg, "use '*const ' to make a function pointer type", .{});
2686826723 return;
2686926724 }
2687026725 switch (ty.fnCallingConvention(mod)) {
26871 .Unspecified => try mod.errNoteNonLazy(src_loc, msg, "extern function must specify calling convention", .{}),
26872 .Async => try mod.errNoteNonLazy(src_loc, msg, "async function cannot be extern", .{}),
26873 .Inline => try mod.errNoteNonLazy(src_loc, msg, "inline function cannot be extern", .{}),
26726 .Unspecified => try sema.errNote(src_loc, msg, "extern function must specify calling convention", .{}),
26727 .Async => try sema.errNote(src_loc, msg, "async function cannot be extern", .{}),
26728 .Inline => try sema.errNote(src_loc, msg, "inline function cannot be extern", .{}),
2687426729 else => return,
2687526730 }
2687626731 },
2687726732 .Enum => {
2687826733 const tag_ty = ty.intTagType(mod);
26879 try mod.errNoteNonLazy(src_loc, msg, "enum tag type '{}' is not extern compatible", .{tag_ty.fmt(sema.mod)});
26734 try sema.errNote(src_loc, msg, "enum tag type '{}' is not extern compatible", .{tag_ty.fmt(sema.mod)});
2688026735 try sema.explainWhyTypeIsNotExtern(msg, src_loc, tag_ty, position);
2688126736 },
26882 .Struct => try mod.errNoteNonLazy(src_loc, msg, "only extern structs and ABI sized packed structs are extern compatible", .{}),
26883 .Union => try mod.errNoteNonLazy(src_loc, msg, "only extern unions and ABI sized packed unions are extern compatible", .{}),
26737 .Struct => try sema.errNote(src_loc, msg, "only extern structs and ABI sized packed structs are extern compatible", .{}),
26738 .Union => try sema.errNote(src_loc, msg, "only extern unions and ABI sized packed unions are extern compatible", .{}),
2688426739 .Array => {
2688526740 if (position == .ret_ty) {
26886 return mod.errNoteNonLazy(src_loc, msg, "arrays are not allowed as a return type", .{});
26741 return sema.errNote(src_loc, msg, "arrays are not allowed as a return type", .{});
2688726742 } else if (position == .param_ty) {
26888 return mod.errNoteNonLazy(src_loc, msg, "arrays are not allowed as a parameter type", .{});
26743 return sema.errNote(src_loc, msg, "arrays are not allowed as a parameter type", .{});
2688926744 }
2689026745 try sema.explainWhyTypeIsNotExtern(msg, src_loc, ty.elemType2(mod), .element);
2689126746 },
2689226747 .Vector => try sema.explainWhyTypeIsNotExtern(msg, src_loc, ty.elemType2(mod), .element),
26893 .Optional => try mod.errNoteNonLazy(src_loc, msg, "only pointer like optionals are extern compatible", .{}),
26748 .Optional => try sema.errNote(src_loc, msg, "only pointer like optionals are extern compatible", .{}),
2689426749 }
2689526750}
2689626751
......@@ -26933,7 +26788,7 @@ fn validatePackedType(sema: *Sema, ty: Type) !bool {
2693326788fn explainWhyTypeIsNotPacked(
2693426789 sema: *Sema,
2693526790 msg: *Module.ErrorMsg,
26936 src_loc: Module.SrcLoc,
26791 src_loc: LazySrcLoc,
2693726792 ty: Type,
2693826793) CompileError!void {
2693926794 const mod = sema.mod;
......@@ -26959,19 +26814,19 @@ fn explainWhyTypeIsNotPacked(
2695926814 .AnyFrame,
2696026815 .Optional,
2696126816 .Array,
26962 => try mod.errNoteNonLazy(src_loc, msg, "type has no guaranteed in-memory representation", .{}),
26817 => try sema.errNote(src_loc, msg, "type has no guaranteed in-memory representation", .{}),
2696326818 .Pointer => if (ty.isSlice(mod)) {
26964 try mod.errNoteNonLazy(src_loc, msg, "slices have no guaranteed in-memory representation", .{});
26819 try sema.errNote(src_loc, msg, "slices have no guaranteed in-memory representation", .{});
2696526820 } else {
26966 try mod.errNoteNonLazy(src_loc, msg, "comptime-only pointer has no guaranteed in-memory representation", .{});
26821 try sema.errNote(src_loc, msg, "comptime-only pointer has no guaranteed in-memory representation", .{});
2696726822 try sema.explainWhyTypeIsComptime(msg, src_loc, ty);
2696826823 },
2696926824 .Fn => {
26970 try mod.errNoteNonLazy(src_loc, msg, "type has no guaranteed in-memory representation", .{});
26971 try mod.errNoteNonLazy(src_loc, msg, "use '*const ' to make a function pointer type", .{});
26825 try sema.errNote(src_loc, msg, "type has no guaranteed in-memory representation", .{});
26826 try sema.errNote(src_loc, msg, "use '*const ' to make a function pointer type", .{});
2697226827 },
26973 .Struct => try mod.errNoteNonLazy(src_loc, msg, "only packed structs layout are allowed in packed types", .{}),
26974 .Union => try mod.errNoteNonLazy(src_loc, msg, "only packed unions layout are allowed in packed types", .{}),
26828 .Struct => try sema.errNote(src_loc, msg, "only packed structs layout are allowed in packed types", .{}),
26829 .Union => try sema.errNote(src_loc, msg, "only packed unions layout are allowed in packed types", .{}),
2697526830 }
2697626831}
2697726832
......@@ -27022,11 +26877,11 @@ fn preparePanicId(sema: *Sema, block: *Block, panic_id: Module.PanicId) !InternP
2702226877 const panic_messages_ty = try sema.getBuiltinType("panic_messages");
2702326878 const msg_decl_index = (sema.namespaceLookup(
2702426879 block,
27025 .unneeded,
26880 LazySrcLoc.unneeded,
2702626881 panic_messages_ty.getNamespaceIndex(mod),
2702726882 try mod.intern_pool.getOrPutString(gpa, @tagName(panic_id), .no_embedded_nulls),
2702826883 ) catch |err| switch (err) {
27029 error.AnalysisFail, error.NeededSourceLocation => @panic("std.builtin.panic_messages is corrupt"),
26884 error.AnalysisFail => @panic("std.builtin.panic_messages is corrupt"),
2703026885 error.GenericPoison, error.ComptimeReturn, error.ComptimeBreak => unreachable,
2703126886 error.OutOfMemory => |e| return e,
2703226887 }).?;
......@@ -27053,6 +26908,7 @@ fn addSafetyCheck(
2705326908 .instructions = .{},
2705426909 .inlining = parent_block.inlining,
2705526910 .is_comptime = false,
26911 .src_base_inst = parent_block.src_base_inst,
2705626912 };
2705726913
2705826914 defer fail_block.instructions.deinit(gpa);
......@@ -27161,6 +27017,7 @@ fn panicUnwrapError(
2716127017 .instructions = .{},
2716227018 .inlining = parent_block.inlining,
2716327019 .is_comptime = false,
27020 .src_base_inst = parent_block.src_base_inst,
2716427021 };
2716527022
2716627023 defer fail_block.instructions.deinit(gpa);
......@@ -27277,6 +27134,7 @@ fn safetyCheckFormatted(
2727727134 .instructions = .{},
2727827135 .inlining = parent_block.inlining,
2727927136 .is_comptime = false,
27137 .src_base_inst = parent_block.src_base_inst,
2728027138 };
2728127139
2728227140 defer fail_block.instructions.deinit(gpa);
......@@ -27300,13 +27158,11 @@ fn emitBackwardBranch(sema: *Sema, block: *Block, src: LazySrcLoc) !void {
2730027158 sema.branch_count += 1;
2730127159 if (sema.branch_count > sema.branch_quota) {
2730227160 const msg = try sema.errMsg(
27303 block,
2730427161 src,
2730527162 "evaluation exceeded {d} backwards branches",
2730627163 .{sema.branch_quota},
2730727164 );
2730827165 try sema.errNote(
27309 block,
2731027166 src,
2731127167 msg,
2731227168 "use @setEvalBranchQuota() to raise the branch limit from {d}",
......@@ -27472,10 +27328,10 @@ fn fieldVal(
2747227328 },
2747327329 else => {
2747427330 const msg = msg: {
27475 const msg = try sema.errMsg(block, src, "type '{}' has no members", .{child_type.fmt(mod)});
27331 const msg = try sema.errMsg(src, "type '{}' has no members", .{child_type.fmt(mod)});
2747627332 errdefer msg.destroy(sema.gpa);
27477 if (child_type.isSlice(mod)) try sema.errNote(block, src, msg, "slice values have 'len' and 'ptr' members", .{});
27478 if (child_type.zigTypeTag(mod) == .Array) try sema.errNote(block, src, msg, "array values have 'len' member", .{});
27333 if (child_type.isSlice(mod)) try sema.errNote(src, msg, "slice values have 'len' and 'ptr' members", .{});
27334 if (child_type.zigTypeTag(mod) == .Array) try sema.errNote(src, msg, "array values have 'len' member", .{});
2747927335 break :msg msg;
2748027336 };
2748127337 return sema.failWithOwnedErrorMsg(block, msg);
......@@ -27633,7 +27489,7 @@ fn fieldPtr(
2763327489 }
2763427490 },
2763527491 .Type => {
27636 _ = try sema.resolveConstDefinedValue(block, .unneeded, object_ptr, undefined);
27492 _ = try sema.resolveConstDefinedValue(block, LazySrcLoc.unneeded, object_ptr, undefined);
2763727493 const result = try sema.analyzeLoad(block, src, object_ptr, object_ptr_src);
2763827494 const inner = if (is_pointer_to)
2763927495 try sema.analyzeLoad(block, src, result, object_ptr_src)
......@@ -27885,7 +27741,7 @@ fn fieldCallBind(
2788527741 };
2788627742
2788727743 const msg = msg: {
27888 const msg = try sema.errMsg(block, src, "no field or member function named '{}' in '{}'", .{
27744 const msg = try sema.errMsg(src, "no field or member function named '{}' in '{}'", .{
2788927745 field_name.fmt(ip),
2789027746 concrete_ty.fmt(mod),
2789127747 });
......@@ -27893,10 +27749,13 @@ fn fieldCallBind(
2789327749 try sema.addDeclaredHereNote(msg, concrete_ty);
2789427750 if (found_decl) |decl_idx| {
2789527751 const decl = mod.declPtr(decl_idx);
27896 try mod.errNoteNonLazy(decl.srcLoc(mod), msg, "'{}' is not a member function", .{field_name.fmt(ip)});
27752 try sema.errNote(.{
27753 .base_node_inst = decl.zir_decl_index.unwrap().?,
27754 .offset = LazySrcLoc.Offset.nodeOffset(0),
27755 }, msg, "'{}' is not a member function", .{field_name.fmt(ip)});
2789727756 }
2789827757 if (concrete_ty.zigTypeTag(mod) == .ErrorUnion) {
27899 try sema.errNote(block, src, msg, "consider using 'try', 'catch', or 'if'", .{});
27758 try sema.errNote(src, msg, "consider using 'try', 'catch', or 'if'", .{});
2790027759 }
2790127760 break :msg msg;
2790227761 };
......@@ -27954,11 +27813,14 @@ fn namespaceLookup(
2795427813 const decl = mod.declPtr(decl_index);
2795527814 if (!decl.is_pub and decl.getFileScope(mod) != block.getFileScope(mod)) {
2795627815 const msg = msg: {
27957 const msg = try sema.errMsg(block, src, "'{}' is not marked 'pub'", .{
27816 const msg = try sema.errMsg(src, "'{}' is not marked 'pub'", .{
2795827817 decl_name.fmt(&mod.intern_pool),
2795927818 });
2796027819 errdefer msg.destroy(gpa);
27961 try mod.errNoteNonLazy(decl.srcLoc(mod), msg, "declared here", .{});
27820 try sema.errNote(.{
27821 .base_node_inst = decl.zir_decl_index.unwrap().?,
27822 .offset = LazySrcLoc.Offset.nodeOffset(0),
27823 }, msg, "declared here", .{});
2796227824 break :msg msg;
2796327825 };
2796427826 return sema.failWithOwnedErrorMsg(block, msg);
......@@ -28023,7 +27885,7 @@ fn structFieldPtr(
2802327885 const struct_type = mod.typeToStruct(struct_ty).?;
2802427886
2802527887 const field_index = struct_type.nameIndex(ip, field_name) orelse
28026 return sema.failWithBadStructFieldAccess(block, struct_type, field_name_src, field_name);
27888 return sema.failWithBadStructFieldAccess(block, struct_ty, struct_type, field_name_src, field_name);
2802727889
2802827890 return sema.structFieldPtrByIndex(block, src, struct_ptr, field_index, field_name_src, struct_ty, initializing);
2802927891}
......@@ -28138,7 +28000,7 @@ fn structFieldVal(
2813828000 return sema.tupleFieldVal(block, src, struct_byval, field_name, field_name_src, struct_ty);
2813928001
2814028002 const field_index = struct_type.nameIndex(ip, field_name) orelse
28141 return sema.failWithBadStructFieldAccess(block, struct_type, field_name_src, field_name);
28003 return sema.failWithBadStructFieldAccess(block, struct_ty, struct_type, field_name_src, field_name);
2814228004 if (struct_type.fieldIsComptime(ip, field_index)) {
2814328005 try sema.resolveStructFieldInits(struct_ty);
2814428006 return Air.internedToRef(struct_type.field_inits.get(ip)[field_index]);
......@@ -28291,7 +28153,7 @@ fn unionFieldPtr(
2829128153
2829228154 if (initializing and field_ty.zigTypeTag(mod) == .NoReturn) {
2829328155 const msg = msg: {
28294 const msg = try sema.errMsg(block, src, "cannot initialize 'noreturn' field of union", .{});
28156 const msg = try sema.errMsg(src, "cannot initialize 'noreturn' field of union", .{});
2829528157 errdefer msg.destroy(sema.gpa);
2829628158
2829728159 try sema.addFieldErrNote(union_ty, field_index, msg, "field '{}' declared here", .{
......@@ -28324,7 +28186,7 @@ fn unionFieldPtr(
2832428186 const msg = msg: {
2832528187 const active_index = Type.fromInterned(union_obj.enum_tag_ty).enumTagFieldIndex(Value.fromInterned(un.tag), mod).?;
2832628188 const active_field_name = Type.fromInterned(union_obj.enum_tag_ty).enumFieldName(active_index, mod);
28327 const msg = try sema.errMsg(block, src, "access of union field '{}' while field '{}' is active", .{
28189 const msg = try sema.errMsg(src, "access of union field '{}' while field '{}' is active", .{
2832828190 field_name.fmt(ip),
2832928191 active_field_name.fmt(ip),
2833028192 });
......@@ -28392,7 +28254,7 @@ fn unionFieldVal(
2839228254 const msg = msg: {
2839328255 const active_index = Type.fromInterned(union_obj.enum_tag_ty).enumTagFieldIndex(Value.fromInterned(un.tag), zcu).?;
2839428256 const active_field_name = Type.fromInterned(union_obj.enum_tag_ty).enumFieldName(active_index, zcu);
28395 const msg = try sema.errMsg(block, src, "access of union field '{}' while field '{}' is active", .{
28257 const msg = try sema.errMsg(src, "access of union field '{}' while field '{}' is active", .{
2839628258 field_name.fmt(ip), active_field_name.fmt(ip),
2839728259 });
2839828260 errdefer msg.destroy(sema.gpa);
......@@ -28615,15 +28477,13 @@ fn validateRuntimeElemAccess(
2861528477 if (try sema.typeRequiresComptime(elem_ty)) {
2861628478 const msg = msg: {
2861728479 const msg = try sema.errMsg(
28618 block,
2861928480 elem_index_src,
2862028481 "values of type '{}' must be comptime-known, but index value is runtime-known",
2862128482 .{parent_ty.fmt(mod)},
2862228483 );
2862328484 errdefer msg.destroy(sema.gpa);
2862428485
28625 const src_decl = mod.declPtr(block.src_decl);
28626 try sema.explainWhyTypeIsComptime(msg, src_decl.toSrcLoc(parent_src, mod), parent_ty);
28486 try sema.explainWhyTypeIsComptime(msg, parent_src, parent_ty);
2862728487
2862828488 break :msg msg;
2862928489 };
......@@ -29011,21 +28871,18 @@ const CoerceOpts = struct {
2901128871 func_inst: Air.Inst.Ref = .none,
2901228872 param_i: u32 = undefined,
2901328873
29014 fn get(info: @This(), sema: *Sema) !?Module.SrcLoc {
28874 fn get(info: @This(), sema: *Sema) !?LazySrcLoc {
2901528875 if (info.func_inst == .none) return null;
29016 const mod = sema.mod;
29017 const fn_decl = (try sema.funcDeclSrc(info.func_inst)) orelse return null;
29018 const param_src = Module.paramSrc(0, mod, fn_decl, info.param_i);
29019 if (param_src == .node_offset_param) {
29020 return Module.SrcLoc{
29021 .file_scope = fn_decl.getFileScope(mod),
29022 .parent_decl_node = fn_decl.src_node,
29023 .lazy = LazySrcLoc.nodeOffset(param_src.node_offset_param),
29024 };
29025 }
29026 return fn_decl.toSrcLoc(param_src, mod);
28876 const fn_decl = try sema.funcDeclSrc(info.func_inst) orelse return null;
28877 return .{
28878 .base_node_inst = fn_decl.zir_decl_index.unwrap().?,
28879 .offset = .{ .fn_proto_param_type = .{
28880 .fn_proto_node_offset = 0,
28881 .param_index = info.param_i,
28882 } },
28883 };
2902728884 }
29028 } = .{},
28885 } = .{ .func_inst = .none, .param_i = undefined },
2902928886};
2903028887
2903128888fn coerceExtra(
......@@ -29118,7 +28975,7 @@ fn coerceExtra(
2911828975
2911928976 // Function body to function pointer.
2912028977 if (inst_ty.zigTypeTag(zcu) == .Fn) {
29121 const fn_val = try sema.resolveConstDefinedValue(block, .unneeded, inst, undefined);
28978 const fn_val = try sema.resolveConstDefinedValue(block, LazySrcLoc.unneeded, inst, undefined);
2912228979 const fn_decl = fn_val.pointerDecl(zcu).?;
2912328980 const inst_as_ptr = try sema.analyzeDeclRef(fn_decl);
2912428981 return sema.coerce(block, dest_ty, inst_as_ptr, inst_src);
......@@ -29366,9 +29223,9 @@ fn coerceExtra(
2936629223 // pointer to tuple to slice
2936729224 if (!dest_info.flags.is_const) {
2936829225 const err_msg = err_msg: {
29369 const err_msg = try sema.errMsg(block, inst_src, "cannot cast pointer to tuple to '{}'", .{dest_ty.fmt(zcu)});
29226 const err_msg = try sema.errMsg(inst_src, "cannot cast pointer to tuple to '{}'", .{dest_ty.fmt(zcu)});
2937029227 errdefer err_msg.destroy(sema.gpa);
29371 try sema.errNote(block, dest_ty_src, err_msg, "pointers to tuples can only coerce to constant pointers", .{});
29228 try sema.errNote(dest_ty_src, err_msg, "pointers to tuples can only coerce to constant pointers", .{});
2937229229 break :err_msg err_msg;
2937329230 };
2937429231 return sema.failWithOwnedErrorMsg(block, err_msg);
......@@ -29455,7 +29312,7 @@ fn coerceExtra(
2945529312 },
2945629313 .Float, .ComptimeFloat => switch (inst_ty.zigTypeTag(zcu)) {
2945729314 .ComptimeFloat => {
29458 const val = try sema.resolveConstDefinedValue(block, .unneeded, inst, undefined);
29315 const val = try sema.resolveConstDefinedValue(block, LazySrcLoc.unneeded, inst, undefined);
2945929316 const result_val = try val.floatCast(dest_ty, zcu);
2946029317 return Air.internedToRef(result_val.toIntern());
2946129318 },
......@@ -29514,7 +29371,7 @@ fn coerceExtra(
2951429371 .Enum => switch (inst_ty.zigTypeTag(zcu)) {
2951529372 .EnumLiteral => {
2951629373 // enum literal to enum
29517 const val = try sema.resolveConstDefinedValue(block, .unneeded, inst, undefined);
29374 const val = try sema.resolveConstDefinedValue(block, LazySrcLoc.unneeded, inst, undefined);
2951829375 const string = zcu.intern_pool.indexToKey(val.toIntern()).enum_literal;
2951929376 const field_index = dest_ty.enumFieldIndex(string, zcu) orelse {
2952029377 return sema.fail(block, inst_src, "no field named '{}' in enum '{}'", .{
......@@ -29648,54 +29505,58 @@ fn coerceExtra(
2964829505
2964929506 if (opts.is_ret and dest_ty.zigTypeTag(zcu) == .NoReturn) {
2965029507 const msg = msg: {
29651 const msg = try sema.errMsg(block, inst_src, "function declared 'noreturn' returns", .{});
29508 const msg = try sema.errMsg(inst_src, "function declared 'noreturn' returns", .{});
2965229509 errdefer msg.destroy(sema.gpa);
2965329510
29654 const ret_ty_src: LazySrcLoc = .{ .node_offset_fn_type_ret_ty = 0 };
29655 const src_decl = zcu.funcOwnerDeclPtr(sema.func_index);
29656 try zcu.errNoteNonLazy(src_decl.toSrcLoc(ret_ty_src, zcu), msg, "'noreturn' declared here", .{});
29511 const ret_ty_src: LazySrcLoc = .{
29512 .base_node_inst = zcu.funcOwnerDeclPtr(sema.func_index).zir_decl_index.unwrap().?,
29513 .offset = .{ .node_offset_fn_type_ret_ty = 0 },
29514 };
29515 try sema.errNote(ret_ty_src, msg, "'noreturn' declared here", .{});
2965729516 break :msg msg;
2965829517 };
2965929518 return sema.failWithOwnedErrorMsg(block, msg);
2966029519 }
2966129520
2966229521 const msg = msg: {
29663 const msg = try sema.errMsg(block, inst_src, "expected type '{}', found '{}'", .{ dest_ty.fmt(zcu), inst_ty.fmt(zcu) });
29522 const msg = try sema.errMsg(inst_src, "expected type '{}', found '{}'", .{ dest_ty.fmt(zcu), inst_ty.fmt(zcu) });
2966429523 errdefer msg.destroy(sema.gpa);
2966529524
2966629525 // E!T to T
2966729526 if (inst_ty.zigTypeTag(zcu) == .ErrorUnion and
2966829527 (try sema.coerceInMemoryAllowed(block, inst_ty.errorUnionPayload(zcu), dest_ty, false, target, dest_ty_src, inst_src)) == .ok)
2966929528 {
29670 try sema.errNote(block, inst_src, msg, "cannot convert error union to payload type", .{});
29671 try sema.errNote(block, inst_src, msg, "consider using 'try', 'catch', or 'if'", .{});
29529 try sema.errNote(inst_src, msg, "cannot convert error union to payload type", .{});
29530 try sema.errNote(inst_src, msg, "consider using 'try', 'catch', or 'if'", .{});
2967229531 }
2967329532
2967429533 // ?T to T
2967529534 if (inst_ty.zigTypeTag(zcu) == .Optional and
2967629535 (try sema.coerceInMemoryAllowed(block, inst_ty.optionalChild(zcu), dest_ty, false, target, dest_ty_src, inst_src)) == .ok)
2967729536 {
29678 try sema.errNote(block, inst_src, msg, "cannot convert optional to payload type", .{});
29679 try sema.errNote(block, inst_src, msg, "consider using '.?', 'orelse', or 'if'", .{});
29537 try sema.errNote(inst_src, msg, "cannot convert optional to payload type", .{});
29538 try sema.errNote(inst_src, msg, "consider using '.?', 'orelse', or 'if'", .{});
2968029539 }
2968129540
29682 try in_memory_result.report(sema, block, inst_src, msg);
29541 try in_memory_result.report(sema, inst_src, msg);
2968329542
2968429543 // Add notes about function return type
2968529544 if (opts.is_ret and
2968629545 zcu.test_functions.get(zcu.funcOwnerDeclIndex(sema.func_index)) == null)
2968729546 {
29688 const ret_ty_src: LazySrcLoc = .{ .node_offset_fn_type_ret_ty = 0 };
29689 const src_decl = zcu.funcOwnerDeclPtr(sema.func_index);
29547 const ret_ty_src: LazySrcLoc = .{
29548 .base_node_inst = zcu.funcOwnerDeclPtr(sema.func_index).zir_decl_index.unwrap().?,
29549 .offset = .{ .node_offset_fn_type_ret_ty = 0 },
29550 };
2969029551 if (inst_ty.isError(zcu) and !dest_ty.isError(zcu)) {
29691 try zcu.errNoteNonLazy(src_decl.toSrcLoc(ret_ty_src, zcu), msg, "function cannot return an error", .{});
29552 try sema.errNote(ret_ty_src, msg, "function cannot return an error", .{});
2969229553 } else {
29693 try zcu.errNoteNonLazy(src_decl.toSrcLoc(ret_ty_src, zcu), msg, "function return type declared here", .{});
29554 try sema.errNote(ret_ty_src, msg, "function return type declared here", .{});
2969429555 }
2969529556 }
2969629557
2969729558 if (try opts.param_src.get(sema)) |param_src| {
29698 try zcu.errNoteNonLazy(param_src, msg, "parameter type declared here", .{});
29559 try sema.errNote(param_src, msg, "parameter type declared here", .{});
2969929560 }
2970029561
2970129562 // TODO maybe add "cannot store an error in type '{}'" note
......@@ -29830,7 +29691,7 @@ const InMemoryCoercionResult = union(enum) {
2983029691 return res;
2983129692 }
2983229693
29833 fn report(res: *const InMemoryCoercionResult, sema: *Sema, block: *Block, src: LazySrcLoc, msg: *Module.ErrorMsg) !void {
29694 fn report(res: *const InMemoryCoercionResult, sema: *Sema, src: LazySrcLoc, msg: *Module.ErrorMsg) !void {
2983429695 const mod = sema.mod;
2983529696 var cur = res;
2983629697 while (true) switch (cur.*) {
......@@ -29841,93 +29702,93 @@ const InMemoryCoercionResult = union(enum) {
2984129702 break;
2984229703 },
2984329704 .int_not_coercible => |int| {
29844 try sema.errNote(block, src, msg, "{s} {d}-bit int cannot represent all possible {s} {d}-bit values", .{
29705 try sema.errNote(src, msg, "{s} {d}-bit int cannot represent all possible {s} {d}-bit values", .{
2984529706 @tagName(int.wanted_signedness), int.wanted_bits, @tagName(int.actual_signedness), int.actual_bits,
2984629707 });
2984729708 break;
2984829709 },
2984929710 .error_union_payload => |pair| {
29850 try sema.errNote(block, src, msg, "error union payload '{}' cannot cast into error union payload '{}'", .{
29711 try sema.errNote(src, msg, "error union payload '{}' cannot cast into error union payload '{}'", .{
2985129712 pair.actual.fmt(mod), pair.wanted.fmt(mod),
2985229713 });
2985329714 cur = pair.child;
2985429715 },
2985529716 .array_len => |lens| {
29856 try sema.errNote(block, src, msg, "array of length {d} cannot cast into an array of length {d}", .{
29717 try sema.errNote(src, msg, "array of length {d} cannot cast into an array of length {d}", .{
2985729718 lens.actual, lens.wanted,
2985829719 });
2985929720 break;
2986029721 },
2986129722 .array_sentinel => |sentinel| {
2986229723 if (sentinel.actual.toIntern() != .unreachable_value) {
29863 try sema.errNote(block, src, msg, "array sentinel '{}' cannot cast into array sentinel '{}'", .{
29724 try sema.errNote(src, msg, "array sentinel '{}' cannot cast into array sentinel '{}'", .{
2986429725 sentinel.actual.fmtValue(mod, sema), sentinel.wanted.fmtValue(mod, sema),
2986529726 });
2986629727 } else {
29867 try sema.errNote(block, src, msg, "destination array requires '{}' sentinel", .{
29728 try sema.errNote(src, msg, "destination array requires '{}' sentinel", .{
2986829729 sentinel.wanted.fmtValue(mod, sema),
2986929730 });
2987029731 }
2987129732 break;
2987229733 },
2987329734 .array_elem => |pair| {
29874 try sema.errNote(block, src, msg, "array element type '{}' cannot cast into array element type '{}'", .{
29735 try sema.errNote(src, msg, "array element type '{}' cannot cast into array element type '{}'", .{
2987529736 pair.actual.fmt(mod), pair.wanted.fmt(mod),
2987629737 });
2987729738 cur = pair.child;
2987829739 },
2987929740 .vector_len => |lens| {
29880 try sema.errNote(block, src, msg, "vector of length {d} cannot cast into a vector of length {d}", .{
29741 try sema.errNote(src, msg, "vector of length {d} cannot cast into a vector of length {d}", .{
2988129742 lens.actual, lens.wanted,
2988229743 });
2988329744 break;
2988429745 },
2988529746 .vector_elem => |pair| {
29886 try sema.errNote(block, src, msg, "vector element type '{}' cannot cast into vector element type '{}'", .{
29747 try sema.errNote(src, msg, "vector element type '{}' cannot cast into vector element type '{}'", .{
2988729748 pair.actual.fmt(mod), pair.wanted.fmt(mod),
2988829749 });
2988929750 cur = pair.child;
2989029751 },
2989129752 .optional_shape => |pair| {
29892 try sema.errNote(block, src, msg, "optional type child '{}' cannot cast into optional type child '{}'", .{
29753 try sema.errNote(src, msg, "optional type child '{}' cannot cast into optional type child '{}'", .{
2989329754 pair.actual.optionalChild(mod).fmt(mod), pair.wanted.optionalChild(mod).fmt(mod),
2989429755 });
2989529756 break;
2989629757 },
2989729758 .optional_child => |pair| {
29898 try sema.errNote(block, src, msg, "optional type child '{}' cannot cast into optional type child '{}'", .{
29759 try sema.errNote(src, msg, "optional type child '{}' cannot cast into optional type child '{}'", .{
2989929760 pair.actual.fmt(mod), pair.wanted.fmt(mod),
2990029761 });
2990129762 cur = pair.child;
2990229763 },
2990329764 .from_anyerror => {
29904 try sema.errNote(block, src, msg, "global error set cannot cast into a smaller set", .{});
29765 try sema.errNote(src, msg, "global error set cannot cast into a smaller set", .{});
2990529766 break;
2990629767 },
2990729768 .missing_error => |missing_errors| {
2990829769 for (missing_errors) |err| {
29909 try sema.errNote(block, src, msg, "'error.{}' not a member of destination error set", .{err.fmt(&mod.intern_pool)});
29770 try sema.errNote(src, msg, "'error.{}' not a member of destination error set", .{err.fmt(&mod.intern_pool)});
2991029771 }
2991129772 break;
2991229773 },
2991329774 .fn_var_args => |wanted_var_args| {
2991429775 if (wanted_var_args) {
29915 try sema.errNote(block, src, msg, "non-variadic function cannot cast into a variadic function", .{});
29776 try sema.errNote(src, msg, "non-variadic function cannot cast into a variadic function", .{});
2991629777 } else {
29917 try sema.errNote(block, src, msg, "variadic function cannot cast into a non-variadic function", .{});
29778 try sema.errNote(src, msg, "variadic function cannot cast into a non-variadic function", .{});
2991829779 }
2991929780 break;
2992029781 },
2992129782 .fn_generic => |wanted_generic| {
2992229783 if (wanted_generic) {
29923 try sema.errNote(block, src, msg, "non-generic function cannot cast into a generic function", .{});
29784 try sema.errNote(src, msg, "non-generic function cannot cast into a generic function", .{});
2992429785 } else {
29925 try sema.errNote(block, src, msg, "generic function cannot cast into a non-generic function", .{});
29786 try sema.errNote(src, msg, "generic function cannot cast into a non-generic function", .{});
2992629787 }
2992729788 break;
2992829789 },
2992929790 .fn_param_count => |lens| {
29930 try sema.errNote(block, src, msg, "function with {d} parameters cannot cast into a function with {d} parameters", .{
29791 try sema.errNote(src, msg, "function with {d} parameters cannot cast into a function with {d} parameters", .{
2993129792 lens.actual, lens.wanted,
2993229793 });
2993329794 break;
......@@ -29944,69 +29805,69 @@ const InMemoryCoercionResult = union(enum) {
2994429805 }
2994529806 }
2994629807 if (!actual_noalias) {
29947 try sema.errNote(block, src, msg, "regular parameter {d} cannot cast into a noalias parameter", .{index});
29808 try sema.errNote(src, msg, "regular parameter {d} cannot cast into a noalias parameter", .{index});
2994829809 } else {
29949 try sema.errNote(block, src, msg, "noalias parameter {d} cannot cast into a regular parameter", .{index});
29810 try sema.errNote(src, msg, "noalias parameter {d} cannot cast into a regular parameter", .{index});
2995029811 }
2995129812 break;
2995229813 },
2995329814 .fn_param_comptime => |param| {
2995429815 if (param.wanted) {
29955 try sema.errNote(block, src, msg, "non-comptime parameter {d} cannot cast into a comptime parameter", .{param.index});
29816 try sema.errNote(src, msg, "non-comptime parameter {d} cannot cast into a comptime parameter", .{param.index});
2995629817 } else {
29957 try sema.errNote(block, src, msg, "comptime parameter {d} cannot cast into a non-comptime parameter", .{param.index});
29818 try sema.errNote(src, msg, "comptime parameter {d} cannot cast into a non-comptime parameter", .{param.index});
2995829819 }
2995929820 break;
2996029821 },
2996129822 .fn_param => |param| {
29962 try sema.errNote(block, src, msg, "parameter {d} '{}' cannot cast into '{}'", .{
29823 try sema.errNote(src, msg, "parameter {d} '{}' cannot cast into '{}'", .{
2996329824 param.index, param.actual.fmt(mod), param.wanted.fmt(mod),
2996429825 });
2996529826 cur = param.child;
2996629827 },
2996729828 .fn_cc => |cc| {
29968 try sema.errNote(block, src, msg, "calling convention '{s}' cannot cast into calling convention '{s}'", .{ @tagName(cc.actual), @tagName(cc.wanted) });
29829 try sema.errNote(src, msg, "calling convention '{s}' cannot cast into calling convention '{s}'", .{ @tagName(cc.actual), @tagName(cc.wanted) });
2996929830 break;
2997029831 },
2997129832 .fn_return_type => |pair| {
29972 try sema.errNote(block, src, msg, "return type '{}' cannot cast into return type '{}'", .{
29833 try sema.errNote(src, msg, "return type '{}' cannot cast into return type '{}'", .{
2997329834 pair.actual.fmt(mod), pair.wanted.fmt(mod),
2997429835 });
2997529836 cur = pair.child;
2997629837 },
2997729838 .ptr_child => |pair| {
29978 try sema.errNote(block, src, msg, "pointer type child '{}' cannot cast into pointer type child '{}'", .{
29839 try sema.errNote(src, msg, "pointer type child '{}' cannot cast into pointer type child '{}'", .{
2997929840 pair.actual.fmt(mod), pair.wanted.fmt(mod),
2998029841 });
2998129842 cur = pair.child;
2998229843 },
2998329844 .ptr_addrspace => |@"addrspace"| {
29984 try sema.errNote(block, src, msg, "address space '{s}' cannot cast into address space '{s}'", .{ @tagName(@"addrspace".actual), @tagName(@"addrspace".wanted) });
29845 try sema.errNote(src, msg, "address space '{s}' cannot cast into address space '{s}'", .{ @tagName(@"addrspace".actual), @tagName(@"addrspace".wanted) });
2998529846 break;
2998629847 },
2998729848 .ptr_sentinel => |sentinel| {
2998829849 if (sentinel.actual.toIntern() != .unreachable_value) {
29989 try sema.errNote(block, src, msg, "pointer sentinel '{}' cannot cast into pointer sentinel '{}'", .{
29850 try sema.errNote(src, msg, "pointer sentinel '{}' cannot cast into pointer sentinel '{}'", .{
2999029851 sentinel.actual.fmtValue(mod, sema), sentinel.wanted.fmtValue(mod, sema),
2999129852 });
2999229853 } else {
29993 try sema.errNote(block, src, msg, "destination pointer requires '{}' sentinel", .{
29854 try sema.errNote(src, msg, "destination pointer requires '{}' sentinel", .{
2999429855 sentinel.wanted.fmtValue(mod, sema),
2999529856 });
2999629857 }
2999729858 break;
2999829859 },
2999929860 .ptr_size => |size| {
30000 try sema.errNote(block, src, msg, "a {s} pointer cannot cast into a {s} pointer", .{ pointerSizeString(size.actual), pointerSizeString(size.wanted) });
29861 try sema.errNote(src, msg, "a {s} pointer cannot cast into a {s} pointer", .{ pointerSizeString(size.actual), pointerSizeString(size.wanted) });
3000129862 break;
3000229863 },
3000329864 .ptr_qualifiers => |qualifiers| {
3000429865 const ok_const = !qualifiers.actual_const or qualifiers.wanted_const;
3000529866 const ok_volatile = !qualifiers.actual_volatile or qualifiers.wanted_volatile;
3000629867 if (!ok_const) {
30007 try sema.errNote(block, src, msg, "cast discards const qualifier", .{});
29868 try sema.errNote(src, msg, "cast discards const qualifier", .{});
3000829869 } else if (!ok_volatile) {
30009 try sema.errNote(block, src, msg, "cast discards volatile qualifier", .{});
29870 try sema.errNote(src, msg, "cast discards volatile qualifier", .{});
3001029871 }
3001129872 break;
3001229873 },
......@@ -30014,11 +29875,11 @@ const InMemoryCoercionResult = union(enum) {
3001429875 const wanted_allow_zero = pair.wanted.ptrAllowsZero(mod);
3001529876 const actual_allow_zero = pair.actual.ptrAllowsZero(mod);
3001629877 if (actual_allow_zero and !wanted_allow_zero) {
30017 try sema.errNote(block, src, msg, "'{}' could have null values which are illegal in type '{}'", .{
29878 try sema.errNote(src, msg, "'{}' could have null values which are illegal in type '{}'", .{
3001829879 pair.actual.fmt(mod), pair.wanted.fmt(mod),
3001929880 });
3002029881 } else {
30021 try sema.errNote(block, src, msg, "mutable '{}' allows illegal null values stored to type '{}'", .{
29882 try sema.errNote(src, msg, "mutable '{}' allows illegal null values stored to type '{}'", .{
3002229883 pair.actual.fmt(mod), pair.wanted.fmt(mod),
3002329884 });
3002429885 }
......@@ -30026,34 +29887,34 @@ const InMemoryCoercionResult = union(enum) {
3002629887 },
3002729888 .ptr_bit_range => |bit_range| {
3002829889 if (bit_range.actual_host != bit_range.wanted_host) {
30029 try sema.errNote(block, src, msg, "pointer host size '{}' cannot cast into pointer host size '{}'", .{
29890 try sema.errNote(src, msg, "pointer host size '{}' cannot cast into pointer host size '{}'", .{
3003029891 bit_range.actual_host, bit_range.wanted_host,
3003129892 });
3003229893 }
3003329894 if (bit_range.actual_offset != bit_range.wanted_offset) {
30034 try sema.errNote(block, src, msg, "pointer bit offset '{}' cannot cast into pointer bit offset '{}'", .{
29895 try sema.errNote(src, msg, "pointer bit offset '{}' cannot cast into pointer bit offset '{}'", .{
3003529896 bit_range.actual_offset, bit_range.wanted_offset,
3003629897 });
3003729898 }
3003829899 break;
3003929900 },
3004029901 .ptr_alignment => |pair| {
30041 try sema.errNote(block, src, msg, "pointer alignment '{d}' cannot cast into pointer alignment '{d}'", .{
29902 try sema.errNote(src, msg, "pointer alignment '{d}' cannot cast into pointer alignment '{d}'", .{
3004229903 pair.actual.toByteUnits() orelse 0, pair.wanted.toByteUnits() orelse 0,
3004329904 });
3004429905 break;
3004529906 },
3004629907 .double_ptr_to_anyopaque => |pair| {
30047 try sema.errNote(block, src, msg, "cannot implicitly cast double pointer '{}' to anyopaque pointer '{}'", .{
29908 try sema.errNote(src, msg, "cannot implicitly cast double pointer '{}' to anyopaque pointer '{}'", .{
3004829909 pair.actual.fmt(mod), pair.wanted.fmt(mod),
3004929910 });
3005029911 break;
3005129912 },
3005229913 .slice_to_anyopaque => |pair| {
30053 try sema.errNote(block, src, msg, "cannot implicitly cast slice '{}' to anyopaque pointer '{}'", .{
29914 try sema.errNote(src, msg, "cannot implicitly cast slice '{}' to anyopaque pointer '{}'", .{
3005429915 pair.actual.fmt(mod), pair.wanted.fmt(mod),
3005529916 });
30056 try sema.errNote(block, src, msg, "consider using '.ptr'", .{});
29917 try sema.errNote(src, msg, "consider using '.ptr'", .{});
3005729918 break;
3005829919 },
3005929920 };
......@@ -30667,7 +30528,7 @@ fn coerceVarArgParam(
3066730528 .{},
3066830529 ),
3066930530 .Fn => fn_ptr: {
30670 const fn_val = try sema.resolveConstDefinedValue(block, .unneeded, inst, undefined);
30531 const fn_val = try sema.resolveConstDefinedValue(block, LazySrcLoc.unneeded, inst, undefined);
3067130532 const fn_decl = fn_val.pointerDecl(mod).?;
3067230533 break :fn_ptr try sema.analyzeDeclRef(fn_decl);
3067330534 },
......@@ -30715,11 +30576,10 @@ fn coerceVarArgParam(
3071530576 const coerced_ty = sema.typeOf(coerced);
3071630577 if (!try sema.validateExternType(coerced_ty, .param_ty)) {
3071730578 const msg = msg: {
30718 const msg = try sema.errMsg(block, inst_src, "cannot pass '{}' to variadic function", .{coerced_ty.fmt(sema.mod)});
30579 const msg = try sema.errMsg(inst_src, "cannot pass '{}' to variadic function", .{coerced_ty.fmt(sema.mod)});
3071930580 errdefer msg.destroy(sema.gpa);
3072030581
30721 const src_decl = sema.mod.declPtr(block.src_decl);
30722 try sema.explainWhyTypeIsNotExtern(msg, src_decl.toSrcLoc(inst_src, mod), coerced_ty, .param_ty);
30582 try sema.explainWhyTypeIsNotExtern(msg, inst_src, coerced_ty, .param_ty);
3072330583
3072430584 try sema.addDeclaredHereNote(msg, coerced_ty);
3072530585 break :msg msg;
......@@ -30879,7 +30739,6 @@ fn checkComptimeKnownStore(sema: *Sema, block: *Block, store_inst_ref: Air.Inst.
3087930739 {
3088030740 try maybe_comptime_alloc.stores.append(sema.arena, .{
3088130741 .inst = store_inst,
30882 .src_decl = block.src_decl,
3088330742 .src = store_src,
3088430743 });
3088530744 return;
......@@ -30913,8 +30772,7 @@ fn checkKnownAllocPtr(sema: *Sema, block: *Block, base_ptr: Air.Inst.Ref, new_pt
3091330772
3091430773 try maybe_comptime_alloc.stores.append(sema.arena, .{
3091530774 .inst = new_ptr_inst,
30916 .src_decl = block.src_decl,
30917 .src = .unneeded,
30775 .src = LazySrcLoc.unneeded,
3091830776 });
3091930777 },
3092030778 .ptr_elem_ptr => {
......@@ -30937,10 +30795,9 @@ fn markMaybeComptimeAllocRuntime(sema: *Sema, block: *Block, alloc_inst: Air.Ins
3093730795 const maybe_comptime_alloc = (sema.maybe_comptime_allocs.fetchRemove(alloc_inst) orelse return).value;
3093830796 // Since the alloc has been determined to be runtime, we must check that
3093930797 // all other stores to it are permitted to be runtime values.
30940 const mod = sema.mod;
3094130798 const slice = maybe_comptime_alloc.stores.slice();
30942 for (slice.items(.inst), slice.items(.src_decl), slice.items(.src)) |other_inst, other_src_decl, other_src| {
30943 if (other_src == .unneeded) {
30799 for (slice.items(.inst), slice.items(.src)) |other_inst, other_src| {
30800 if (other_src.offset == .unneeded) {
3094430801 switch (sema.air_instructions.items(.tag)[@intFromEnum(other_inst)]) {
3094530802 .set_union_tag, .optional_payload_ptr_set, .errunion_payload_ptr_set => continue,
3094630803 else => unreachable, // assertion failure
......@@ -30950,10 +30807,9 @@ fn markMaybeComptimeAllocRuntime(sema: *Sema, block: *Block, alloc_inst: Air.Ins
3095030807 const other_operand = other_data.rhs;
3095130808 if (!sema.checkRuntimeValue(other_operand)) {
3095230809 return sema.failWithOwnedErrorMsg(block, msg: {
30953 const other_src_resolved = mod.declPtr(other_src_decl).toSrcLoc(other_src, mod);
30954 const msg = try Module.ErrorMsg.create(sema.gpa, other_src_resolved, "runtime value contains reference to comptime var", .{});
30810 const msg = try sema.errMsg(other_src, "runtime value contains reference to comptime var", .{});
3095530811 errdefer msg.destroy(sema.gpa);
30956 try mod.errNoteNonLazy(other_src_resolved, msg, "comptime var pointers are not available at runtime", .{});
30812 try sema.errNote(other_src, msg, "comptime var pointers are not available at runtime", .{});
3095730813 break :msg msg;
3095830814 });
3095930815 }
......@@ -31215,11 +31071,11 @@ fn coerceEnumToUnion(
3121531071
3121631072 const tag_ty = union_ty.unionTagType(mod) orelse {
3121731073 const msg = msg: {
31218 const msg = try sema.errMsg(block, inst_src, "expected type '{}', found '{}'", .{
31074 const msg = try sema.errMsg(inst_src, "expected type '{}', found '{}'", .{
3121931075 union_ty.fmt(sema.mod), inst_ty.fmt(sema.mod),
3122031076 });
3122131077 errdefer msg.destroy(sema.gpa);
31222 try sema.errNote(block, union_ty_src, msg, "cannot coerce enum to untagged union", .{});
31078 try sema.errNote(union_ty_src, msg, "cannot coerce enum to untagged union", .{});
3122331079 try sema.addDeclaredHereNote(msg, union_ty);
3122431080 break :msg msg;
3122531081 };
......@@ -31239,7 +31095,7 @@ fn coerceEnumToUnion(
3123931095 try sema.resolveTypeFields(field_ty);
3124031096 if (field_ty.zigTypeTag(mod) == .NoReturn) {
3124131097 const msg = msg: {
31242 const msg = try sema.errMsg(block, inst_src, "cannot initialize 'noreturn' field of union", .{});
31098 const msg = try sema.errMsg(inst_src, "cannot initialize 'noreturn' field of union", .{});
3124331099 errdefer msg.destroy(sema.gpa);
3124431100
3124531101 const field_name = union_obj.loadTagType(ip).names.get(ip)[field_index];
......@@ -31254,7 +31110,7 @@ fn coerceEnumToUnion(
3125431110 const opv = (try sema.typeHasOnePossibleValue(field_ty)) orelse {
3125531111 const msg = msg: {
3125631112 const field_name = union_obj.loadTagType(ip).names.get(ip)[field_index];
31257 const msg = try sema.errMsg(block, inst_src, "coercion from enum '{}' to union '{}' must initialize '{}' field '{}'", .{
31113 const msg = try sema.errMsg(inst_src, "coercion from enum '{}' to union '{}' must initialize '{}' field '{}'", .{
3125831114 inst_ty.fmt(sema.mod), union_ty.fmt(sema.mod),
3125931115 field_ty.fmt(sema.mod), field_name.fmt(ip),
3126031116 });
......@@ -31276,7 +31132,7 @@ fn coerceEnumToUnion(
3127631132
3127731133 if (tag_ty.isNonexhaustiveEnum(mod)) {
3127831134 const msg = msg: {
31279 const msg = try sema.errMsg(block, inst_src, "runtime coercion to union '{}' from non-exhaustive enum", .{
31135 const msg = try sema.errMsg(inst_src, "runtime coercion to union '{}' from non-exhaustive enum", .{
3128031136 union_ty.fmt(sema.mod),
3128131137 });
3128231138 errdefer msg.destroy(sema.gpa);
......@@ -31294,7 +31150,6 @@ fn coerceEnumToUnion(
3129431150 for (union_obj.field_types.get(ip), 0..) |field_ty, field_index| {
3129531151 if (Type.fromInterned(field_ty).zigTypeTag(mod) == .NoReturn) {
3129631152 const err_msg = msg orelse try sema.errMsg(
31297 block,
3129831153 inst_src,
3129931154 "runtime coercion from enum '{}' to union '{}' which has a 'noreturn' field",
3130031155 .{ tag_ty.fmt(sema.mod), union_ty.fmt(sema.mod) },
......@@ -31318,7 +31173,6 @@ fn coerceEnumToUnion(
3131831173
3131931174 const msg = msg: {
3132031175 const msg = try sema.errMsg(
31321 block,
3132231176 inst_src,
3132331177 "runtime coercion from enum '{}' to union '{}' which has non-void fields",
3132431178 .{ tag_ty.fmt(sema.mod), union_ty.fmt(sema.mod) },
......@@ -31377,12 +31231,10 @@ fn coerceAnonStructToUnion(
3137731231 assert(field_count != 1);
3137831232 const msg = msg: {
3137931233 const msg = if (field_count > 1) try sema.errMsg(
31380 block,
3138131234 inst_src,
3138231235 "cannot initialize multiple union fields at once; unions can only have one active field",
3138331236 .{},
3138431237 ) else try sema.errMsg(
31385 block,
3138631238 inst_src,
3138731239 "union initializer must initialize one field",
3138831240 .{},
......@@ -31459,12 +31311,12 @@ fn coerceArrayLike(
3145931311 const dest_len = try sema.usizeCast(block, dest_ty_src, dest_ty.arrayLen(mod));
3146031312 if (dest_len != inst_len) {
3146131313 const msg = msg: {
31462 const msg = try sema.errMsg(block, inst_src, "expected type '{}', found '{}'", .{
31314 const msg = try sema.errMsg(inst_src, "expected type '{}', found '{}'", .{
3146331315 dest_ty.fmt(mod), inst_ty.fmt(mod),
3146431316 });
3146531317 errdefer msg.destroy(sema.gpa);
31466 try sema.errNote(block, dest_ty_src, msg, "destination has length {d}", .{dest_len});
31467 try sema.errNote(block, inst_src, msg, "source has length {d}", .{inst_len});
31318 try sema.errNote(dest_ty_src, msg, "destination has length {d}", .{dest_len});
31319 try sema.errNote(inst_src, msg, "source has length {d}", .{inst_len});
3146831320 break :msg msg;
3146931321 };
3147031322 return sema.failWithOwnedErrorMsg(block, msg);
......@@ -31546,12 +31398,12 @@ fn coerceTupleToArray(
3154631398
3154731399 if (dest_len != inst_len) {
3154831400 const msg = msg: {
31549 const msg = try sema.errMsg(block, inst_src, "expected type '{}', found '{}'", .{
31401 const msg = try sema.errMsg(inst_src, "expected type '{}', found '{}'", .{
3155031402 dest_ty.fmt(sema.mod), inst_ty.fmt(sema.mod),
3155131403 });
3155231404 errdefer msg.destroy(sema.gpa);
31553 try sema.errNote(block, dest_ty_src, msg, "destination has length {d}", .{dest_len});
31554 try sema.errNote(block, inst_src, msg, "source has length {d}", .{inst_len});
31405 try sema.errNote(dest_ty_src, msg, "destination has length {d}", .{dest_len});
31406 try sema.errNote(inst_src, msg, "source has length {d}", .{inst_len});
3155531407 break :msg msg;
3155631408 };
3155731409 return sema.failWithOwnedErrorMsg(block, msg);
......@@ -31722,9 +31574,9 @@ fn coerceTupleToStruct(
3172231574 const template = "missing struct field: {}";
3172331575 const args = .{field_name.fmt(ip)};
3172431576 if (root_msg) |msg| {
31725 try sema.errNote(block, field_src, msg, template, args);
31577 try sema.errNote(field_src, msg, template, args);
3172631578 } else {
31727 root_msg = try sema.errMsg(block, field_src, template, args);
31579 root_msg = try sema.errMsg(field_src, template, args);
3172831580 }
3172931581 continue;
3173031582 }
......@@ -31860,18 +31712,18 @@ fn coerceTupleToTuple(
3186031712 const field_name = tuple_ty.structFieldName(i, mod).unwrap() orelse {
3186131713 const template = "missing tuple field: {d}";
3186231714 if (root_msg) |msg| {
31863 try sema.errNote(block, field_src, msg, template, .{i});
31715 try sema.errNote(field_src, msg, template, .{i});
3186431716 } else {
31865 root_msg = try sema.errMsg(block, field_src, template, .{i});
31717 root_msg = try sema.errMsg(field_src, template, .{i});
3186631718 }
3186731719 continue;
3186831720 };
3186931721 const template = "missing struct field: {}";
3187031722 const args = .{field_name.fmt(ip)};
3187131723 if (root_msg) |msg| {
31872 try sema.errNote(block, field_src, msg, template, args);
31724 try sema.errNote(field_src, msg, template, args);
3187331725 } else {
31874 root_msg = try sema.errMsg(block, field_src, template, args);
31726 root_msg = try sema.errMsg(field_src, template, args);
3187531727 }
3187631728 continue;
3187731729 }
......@@ -31926,14 +31778,6 @@ fn addReferencedBy(
3192631778 decl_index: InternPool.DeclIndex,
3192731779) !void {
3192831780 if (sema.mod.comp.reference_trace == 0) return;
31929 if (src == .unneeded) {
31930 // We can't use NeededSourceLocation, since sites handling that assume it means a compile
31931 // error. Our long-term strategy here is to gradually transition from NeededSourceLocation
31932 // into having more LazySrcLoc tags. In the meantime, let release compilers just ignore this
31933 // reference (a slightly-incomplete error is better than a crash!), but trigger a panic in
31934 // debug so we can fix this case.
31935 if (std.debug.runtime_safety) unreachable else return;
31936 }
3193731781 try sema.mod.reference_table.put(sema.gpa, decl_index, .{
3193831782 .referencer = block.src_decl,
3193931783 .src = src,
......@@ -31945,7 +31789,10 @@ pub fn ensureDeclAnalyzed(sema: *Sema, decl_index: InternPool.DeclIndex) Compile
3194531789 const ip = &mod.intern_pool;
3194631790 const decl = mod.declPtr(decl_index);
3194731791 if (decl.analysis == .in_progress) {
31948 const msg = try Module.ErrorMsg.create(sema.gpa, decl.srcLoc(mod), "dependency loop detected", .{});
31792 const msg = try sema.errMsg(.{
31793 .base_node_inst = decl.zir_decl_index.unwrap().?,
31794 .offset = LazySrcLoc.Offset.nodeOffset(0),
31795 }, "dependency loop detected", .{});
3194931796 return sema.failWithOwnedErrorMsg(null, msg);
3195031797 }
3195131798
......@@ -32440,10 +32287,9 @@ fn analyzeSlice(
3244032287 if (try sema.compareScalar(start_value, .neq, end_value, Type.comptime_int)) {
3244132288 if (try sema.compareScalar(start_value, .neq, Value.zero_comptime_int, Type.comptime_int)) {
3244232289 const msg = msg: {
32443 const msg = try sema.errMsg(block, start_src, bounds_error_message, .{});
32290 const msg = try sema.errMsg(start_src, bounds_error_message, .{});
3244432291 errdefer msg.destroy(sema.gpa);
3244532292 try sema.errNote(
32446 block,
3244732293 start_src,
3244832294 msg,
3244932295 "expected '{}', found '{}'",
......@@ -32457,10 +32303,9 @@ fn analyzeSlice(
3245732303 return sema.failWithOwnedErrorMsg(block, msg);
3245832304 } else if (try sema.compareScalar(end_value, .neq, Value.one_comptime_int, Type.comptime_int)) {
3245932305 const msg = msg: {
32460 const msg = try sema.errMsg(block, end_src, bounds_error_message, .{});
32306 const msg = try sema.errMsg(end_src, bounds_error_message, .{});
3246132307 errdefer msg.destroy(sema.gpa);
3246232308 try sema.errNote(
32463 block,
3246432309 end_src,
3246532310 msg,
3246632311 "expected '{}', found '{}'",
......@@ -32714,9 +32559,9 @@ fn analyzeSlice(
3271432559
3271532560 if (!actual_sentinel.eql(expected_sentinel, elem_ty, mod)) {
3271632561 const msg = msg: {
32717 const msg = try sema.errMsg(block, src, "value in memory does not match slice sentinel", .{});
32562 const msg = try sema.errMsg(src, "value in memory does not match slice sentinel", .{});
3271832563 errdefer msg.destroy(sema.gpa);
32719 try sema.errNote(block, src, msg, "expected '{}', found '{}'", .{
32564 try sema.errNote(src, msg, "expected '{}', found '{}'", .{
3272032565 expected_sentinel.fmtValue(mod, sema),
3272132566 actual_sentinel.fmtValue(mod, sema),
3272232567 });
......@@ -33588,6 +33433,31 @@ const PeerResolveStrategy = enum {
3358833433 }
3358933434};
3359033435
33436const PeerTypeCandidateSrc = union(enum) {
33437 /// Do not print out error notes for candidate sources
33438 none: void,
33439 /// When we want to know the the src of candidate i, look up at
33440 /// index i in this slice
33441 override: []const ?LazySrcLoc,
33442 /// resolvePeerTypes originates from a @TypeOf(...) call
33443 typeof_builtin_call_node_offset: i32,
33444
33445 pub fn resolve(
33446 self: PeerTypeCandidateSrc,
33447 block: *Block,
33448 candidate_i: usize,
33449 ) ?LazySrcLoc {
33450 return switch (self) {
33451 .none => null,
33452 .override => |candidate_srcs| if (candidate_i >= candidate_srcs.len)
33453 null
33454 else
33455 candidate_srcs[candidate_i],
33456 .typeof_builtin_call_node_offset => |node_offset| block.builtinCallArgSrc(node_offset, @intCast(candidate_i)),
33457 };
33458 }
33459};
33460
3359133461const PeerResolveResult = union(enum) {
3359233462 /// The peer type resolution was successful, and resulted in the given type.
3359333463 success: Type,
......@@ -33612,10 +33482,9 @@ const PeerResolveResult = union(enum) {
3361233482 block: *Block,
3361333483 src: LazySrcLoc,
3361433484 instructions: []const Air.Inst.Ref,
33615 candidate_srcs: Module.PeerTypeCandidateSrc,
33485 candidate_srcs: PeerTypeCandidateSrc,
3361633486 ) !*Module.ErrorMsg {
3361733487 const mod = sema.mod;
33618 const decl_ptr = mod.declPtr(block.src_decl);
3361933488
3362033489 var opt_msg: ?*Module.ErrorMsg = null;
3362133490 errdefer if (opt_msg) |msg| msg.destroy(sema.gpa);
......@@ -33643,9 +33512,9 @@ const PeerResolveResult = union(enum) {
3364333512 const fmt = "struct field '{}' has conflicting types";
3364433513 const args = .{field_error.field_name.fmt(&mod.intern_pool)};
3364533514 if (opt_msg) |msg| {
33646 try sema.errNote(block, src, msg, fmt, args);
33515 try sema.errNote(src, msg, fmt, args);
3364733516 } else {
33648 opt_msg = try sema.errMsg(block, src, fmt, args);
33517 opt_msg = try sema.errMsg(src, fmt, args);
3364933518 }
3365033519
3365133520 // Continue on to child error
......@@ -33667,8 +33536,8 @@ const PeerResolveResult = union(enum) {
3366733536 peer_tys[conflict_idx[1]],
3366833537 };
3366933538 const conflict_srcs: [2]?LazySrcLoc = .{
33670 candidate_srcs.resolve(mod, decl_ptr, conflict_idx[0]),
33671 candidate_srcs.resolve(mod, decl_ptr, conflict_idx[1]),
33539 candidate_srcs.resolve(block, conflict_idx[0]),
33540 candidate_srcs.resolve(block, conflict_idx[1]),
3367233541 };
3367333542
3367433543 const fmt = "incompatible types: '{}' and '{}'";
......@@ -33677,16 +33546,16 @@ const PeerResolveResult = union(enum) {
3367733546 conflict_tys[1].fmt(mod),
3367833547 };
3367933548 const msg = if (opt_msg) |msg| msg: {
33680 try sema.errNote(block, src, msg, fmt, args);
33549 try sema.errNote(src, msg, fmt, args);
3368133550 break :msg msg;
3368233551 } else msg: {
33683 const msg = try sema.errMsg(block, src, fmt, args);
33552 const msg = try sema.errMsg(src, fmt, args);
3368433553 opt_msg = msg;
3368533554 break :msg msg;
3368633555 };
3368733556
33688 if (conflict_srcs[0]) |src_loc| try sema.errNote(block, src_loc, msg, "type '{}' here", .{conflict_tys[0].fmt(mod)});
33689 if (conflict_srcs[1]) |src_loc| try sema.errNote(block, src_loc, msg, "type '{}' here", .{conflict_tys[1].fmt(mod)});
33557 if (conflict_srcs[0]) |src_loc| try sema.errNote(src_loc, msg, "type '{}' here", .{conflict_tys[0].fmt(mod)});
33558 if (conflict_srcs[1]) |src_loc| try sema.errNote(src_loc, msg, "type '{}' here", .{conflict_tys[1].fmt(mod)});
3369033559
3369133560 // No child error
3369233561 break;
......@@ -33701,7 +33570,7 @@ fn resolvePeerTypes(
3370133570 block: *Block,
3370233571 src: LazySrcLoc,
3370333572 instructions: []const Air.Inst.Ref,
33704 candidate_srcs: Module.PeerTypeCandidateSrc,
33573 candidate_srcs: PeerTypeCandidateSrc,
3370533574) !Type {
3370633575 switch (instructions.len) {
3370733576 0 => return Type.noreturn,
......@@ -35140,9 +35009,9 @@ pub fn resolveStructAlignment(
3514035009}
3514135010
3514235011fn resolveStructLayout(sema: *Sema, ty: Type) CompileError!void {
35143 const mod = sema.mod;
35144 const ip = &mod.intern_pool;
35145 const struct_type = mod.typeToStruct(ty) orelse return;
35012 const zcu = sema.mod;
35013 const ip = &zcu.intern_pool;
35014 const struct_type = zcu.typeToStruct(ty) orelse return;
3514635015
3514735016 if (struct_type.haveLayout(ip))
3514835017 return;
......@@ -35150,16 +35019,15 @@ fn resolveStructLayout(sema: *Sema, ty: Type) CompileError!void {
3515035019 try sema.resolveTypeFields(ty);
3515135020
3515235021 if (struct_type.layout == .@"packed") {
35153 try semaBackingIntType(mod, struct_type);
35022 try semaBackingIntType(zcu, struct_type);
3515435023 return;
3515535024 }
3515635025
3515735026 if (struct_type.setLayoutWip(ip)) {
35158 const msg = try Module.ErrorMsg.create(
35159 sema.gpa,
35160 mod.declPtr(struct_type.decl.unwrap().?).srcLoc(mod),
35027 const msg = try sema.errMsg(
35028 ty.srcLoc(zcu),
3516135029 "struct '{}' depends on itself",
35162 .{ty.fmt(mod)},
35030 .{ty.fmt(zcu)},
3516335031 );
3516435032 return sema.failWithOwnedErrorMsg(null, msg);
3516535033 }
......@@ -35196,9 +35064,8 @@ fn resolveStructLayout(sema: *Sema, ty: Type) CompileError!void {
3519635064 }
3519735065
3519835066 if (struct_type.flagsPtr(ip).assumed_runtime_bits and !(try sema.typeHasRuntimeBits(ty))) {
35199 const msg = try Module.ErrorMsg.create(
35200 sema.gpa,
35201 mod.declPtr(struct_type.decl.unwrap().?).srcLoc(mod),
35067 const msg = try sema.errMsg(
35068 ty.srcLoc(zcu),
3520235069 "struct layout depends on it having runtime bits",
3520335070 .{},
3520435071 );
......@@ -35206,11 +35073,10 @@ fn resolveStructLayout(sema: *Sema, ty: Type) CompileError!void {
3520635073 }
3520735074
3520835075 if (struct_type.flagsPtr(ip).assumed_pointer_aligned and
35209 big_align.compareStrict(.neq, Alignment.fromByteUnits(@divExact(mod.getTarget().ptrBitWidth(), 8))))
35076 big_align.compareStrict(.neq, Alignment.fromByteUnits(@divExact(zcu.getTarget().ptrBitWidth(), 8))))
3521035077 {
35211 const msg = try Module.ErrorMsg.create(
35212 sema.gpa,
35213 mod.declPtr(struct_type.decl.unwrap().?).srcLoc(mod),
35078 const msg = try sema.errMsg(
35079 ty.srcLoc(zcu),
3521435080 "struct layout depends on being pointer aligned",
3521535081 .{},
3521635082 );
......@@ -35242,7 +35108,7 @@ fn resolveStructLayout(sema: *Sema, ty: Type) CompileError!void {
3524235108 return a_align.compare(.gt, b_align);
3524335109 }
3524435110 };
35245 if (struct_type.isTuple(ip) or !mod.backendSupportsFeature(.field_reordering)) {
35111 if (struct_type.isTuple(ip) or !zcu.backendSupportsFeature(.field_reordering)) {
3524635112 // TODO: don't handle tuples differently. This logic exists only because it
3524735113 // uncovers latent bugs if removed. Fix the latent bugs and remove this logic!
3524835114 // Likewise, implement field reordering support in all the backends!
......@@ -35293,7 +35159,7 @@ fn semaBackingIntType(mod: *Module, struct_type: InternPool.LoadedStructType) Co
3529335159 var analysis_arena = std.heap.ArenaAllocator.init(gpa);
3529435160 defer analysis_arena.deinit();
3529535161
35296 var comptime_err_ret_trace = std.ArrayList(Module.SrcLoc).init(gpa);
35162 var comptime_err_ret_trace = std.ArrayList(LazySrcLoc).init(gpa);
3529735163 defer comptime_err_ret_trace.deinit();
3529835164
3529935165 var sema: Sema = .{
......@@ -35320,6 +35186,7 @@ fn semaBackingIntType(mod: *Module, struct_type: InternPool.LoadedStructType) Co
3532035186 .instructions = .{},
3532135187 .inlining = null,
3532235188 .is_comptime = true,
35189 .src_base_inst = struct_type.zir_index.unwrap().?,
3532335190 };
3532435191 defer assert(block.instructions.items.len == 0);
3532535192
......@@ -35352,7 +35219,10 @@ fn semaBackingIntType(mod: *Module, struct_type: InternPool.LoadedStructType) Co
3535235219 const backing_int_body_len = zir.extra[extra_index];
3535335220 extra_index += 1;
3535435221
35355 const backing_int_src: LazySrcLoc = .{ .node_offset_container_tag = 0 };
35222 const backing_int_src: LazySrcLoc = .{
35223 .base_node_inst = struct_type.zir_index.unwrap().?,
35224 .offset = .{ .node_offset_container_tag = 0 },
35225 };
3535635226 const backing_int_ty = blk: {
3535735227 if (backing_int_body_len == 0) {
3535835228 const backing_int_ref: Zir.Inst.Ref = @enumFromInt(zir.extra[extra_index]);
......@@ -35368,7 +35238,7 @@ fn semaBackingIntType(mod: *Module, struct_type: InternPool.LoadedStructType) Co
3536835238 struct_type.backingIntType(ip).* = backing_int_ty.toIntern();
3536935239 } else {
3537035240 if (fields_bit_sum > std.math.maxInt(u16)) {
35371 return sema.fail(&block, LazySrcLoc.nodeOffset(0), "size of packed struct '{d}' exceeds maximum bit width of 65535", .{fields_bit_sum});
35241 return sema.fail(&block, block.nodeOffset(0), "size of packed struct '{d}' exceeds maximum bit width of 65535", .{fields_bit_sum});
3537235242 }
3537335243 const backing_int_ty = try mod.intType(.unsigned, @intCast(fields_bit_sum));
3537435244 struct_type.backingIntType(ip).* = backing_int_ty.toIntern();
......@@ -35395,9 +35265,9 @@ fn checkIndexable(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) !void {
3539535265 const mod = sema.mod;
3539635266 if (!ty.isIndexable(mod)) {
3539735267 const msg = msg: {
35398 const msg = try sema.errMsg(block, src, "type '{}' does not support indexing", .{ty.fmt(sema.mod)});
35268 const msg = try sema.errMsg(src, "type '{}' does not support indexing", .{ty.fmt(sema.mod)});
3539935269 errdefer msg.destroy(sema.gpa);
35400 try sema.errNote(block, src, msg, "operand must be an array, slice, tuple, or vector", .{});
35270 try sema.errNote(src, msg, "operand must be an array, slice, tuple, or vector", .{});
3540135271 break :msg msg;
3540235272 };
3540335273 return sema.failWithOwnedErrorMsg(block, msg);
......@@ -35418,9 +35288,9 @@ fn checkMemOperand(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) !void
3541835288 }
3541935289 }
3542035290 const msg = msg: {
35421 const msg = try sema.errMsg(block, src, "type '{}' is not an indexable pointer", .{ty.fmt(sema.mod)});
35291 const msg = try sema.errMsg(src, "type '{}' is not an indexable pointer", .{ty.fmt(sema.mod)});
3542235292 errdefer msg.destroy(sema.gpa);
35423 try sema.errNote(block, src, msg, "operand must be a slice, a many pointer or a pointer to an array", .{});
35293 try sema.errNote(src, msg, "operand must be a slice, a many pointer or a pointer to an array", .{});
3542435294 break :msg msg;
3542535295 };
3542635296 return sema.failWithOwnedErrorMsg(block, msg);
......@@ -35471,8 +35341,8 @@ pub fn resolveUnionAlignment(
3547135341
3547235342/// This logic must be kept in sync with `Module.getUnionLayout`.
3547335343fn resolveUnionLayout(sema: *Sema, ty: Type) CompileError!void {
35474 const mod = sema.mod;
35475 const ip = &mod.intern_pool;
35344 const zcu = sema.mod;
35345 const ip = &zcu.intern_pool;
3547635346
3547735347 try sema.resolveTypeFieldsUnion(ty, ip.loadUnionType(ty.ip_index));
3547835348
......@@ -35482,11 +35352,10 @@ fn resolveUnionLayout(sema: *Sema, ty: Type) CompileError!void {
3548235352 switch (union_type.flagsPtr(ip).status) {
3548335353 .none, .have_field_types => {},
3548435354 .field_types_wip, .layout_wip => {
35485 const msg = try Module.ErrorMsg.create(
35486 sema.gpa,
35487 mod.declPtr(union_type.decl).srcLoc(mod),
35355 const msg = try sema.errMsg(
35356 ty.srcLoc(zcu),
3548835357 "union '{}' depends on itself",
35489 .{ty.fmt(mod)},
35358 .{ty.fmt(zcu)},
3549035359 );
3549135360 return sema.failWithOwnedErrorMsg(null, msg);
3549235361 },
......@@ -35505,7 +35374,7 @@ fn resolveUnionLayout(sema: *Sema, ty: Type) CompileError!void {
3550535374 for (0..union_type.field_types.len) |field_index| {
3550635375 const field_ty = Type.fromInterned(union_type.field_types.get(ip)[field_index]);
3550735376
35508 if (try sema.typeRequiresComptime(field_ty) or field_ty.zigTypeTag(mod) == .NoReturn) continue; // TODO: should this affect alignment?
35377 if (try sema.typeRequiresComptime(field_ty) or field_ty.zigTypeTag(zcu) == .NoReturn) continue; // TODO: should this affect alignment?
3550935378
3551035379 max_size = @max(max_size, sema.typeAbiSize(field_ty) catch |err| switch (err) {
3551135380 error.AnalysisFail => {
......@@ -35547,7 +35416,7 @@ fn resolveUnionLayout(sema: *Sema, ty: Type) CompileError!void {
3554735416 } else {
3554835417 // {Payload, Tag}
3554935418 size += max_size;
35550 size = switch (mod.getTarget().ofmt) {
35419 size = switch (zcu.getTarget().ofmt) {
3555135420 .c => max_align,
3555235421 else => tag_align,
3555335422 }.forward(size);
......@@ -35566,9 +35435,8 @@ fn resolveUnionLayout(sema: *Sema, ty: Type) CompileError!void {
3556635435 flags.status = .have_layout;
3556735436
3556835437 if (union_type.flagsPtr(ip).assumed_runtime_bits and !(try sema.typeHasRuntimeBits(ty))) {
35569 const msg = try Module.ErrorMsg.create(
35570 sema.gpa,
35571 mod.declPtr(union_type.decl).srcLoc(mod),
35438 const msg = try sema.errMsg(
35439 ty.srcLoc(zcu),
3557235440 "union layout depends on it having runtime bits",
3557335441 .{},
3557435442 );
......@@ -35576,11 +35444,10 @@ fn resolveUnionLayout(sema: *Sema, ty: Type) CompileError!void {
3557635444 }
3557735445
3557835446 if (union_type.flagsPtr(ip).assumed_pointer_aligned and
35579 alignment.compareStrict(.neq, Alignment.fromByteUnits(@divExact(mod.getTarget().ptrBitWidth(), 8))))
35447 alignment.compareStrict(.neq, Alignment.fromByteUnits(@divExact(zcu.getTarget().ptrBitWidth(), 8))))
3558035448 {
35581 const msg = try Module.ErrorMsg.create(
35582 sema.gpa,
35583 mod.declPtr(union_type.decl).srcLoc(mod),
35449 const msg = try sema.errMsg(
35450 ty.srcLoc(zcu),
3558435451 "union layout depends on being pointer aligned",
3558535452 .{},
3558635453 );
......@@ -35804,12 +35671,12 @@ pub fn resolveTypeFieldsStruct(
3580435671 ty: InternPool.Index,
3580535672 struct_type: InternPool.LoadedStructType,
3580635673) CompileError!void {
35807 const mod = sema.mod;
35808 const ip = &mod.intern_pool;
35674 const zcu = sema.mod;
35675 const ip = &zcu.intern_pool;
3580935676 // If there is no owner decl it means the struct has no fields.
3581035677 const owner_decl = struct_type.decl.unwrap() orelse return;
3581135678
35812 switch (mod.declPtr(owner_decl).analysis) {
35679 switch (zcu.declPtr(owner_decl).analysis) {
3581335680 .file_failure,
3581435681 .dependency_failure,
3581535682 .sema_failure,
......@@ -35823,20 +35690,19 @@ pub fn resolveTypeFieldsStruct(
3582335690 if (struct_type.haveFieldTypes(ip)) return;
3582435691
3582535692 if (struct_type.setTypesWip(ip)) {
35826 const msg = try Module.ErrorMsg.create(
35827 sema.gpa,
35828 mod.declPtr(owner_decl).srcLoc(mod),
35693 const msg = try sema.errMsg(
35694 Type.fromInterned(ty).srcLoc(zcu),
3582935695 "struct '{}' depends on itself",
35830 .{Type.fromInterned(ty).fmt(mod)},
35696 .{Type.fromInterned(ty).fmt(zcu)},
3583135697 );
3583235698 return sema.failWithOwnedErrorMsg(null, msg);
3583335699 }
3583435700 defer struct_type.clearTypesWip(ip);
3583535701
35836 semaStructFields(mod, sema.arena, struct_type) catch |err| switch (err) {
35702 semaStructFields(zcu, sema.arena, struct_type) catch |err| switch (err) {
3583735703 error.AnalysisFail => {
35838 if (mod.declPtr(owner_decl).analysis == .complete) {
35839 mod.declPtr(owner_decl).analysis = .dependency_failure;
35704 if (zcu.declPtr(owner_decl).analysis == .complete) {
35705 zcu.declPtr(owner_decl).analysis = .dependency_failure;
3584035706 }
3584135707 return error.AnalysisFail;
3584235708 },
......@@ -35845,9 +35711,9 @@ pub fn resolveTypeFieldsStruct(
3584535711}
3584635712
3584735713pub fn resolveStructFieldInits(sema: *Sema, ty: Type) CompileError!void {
35848 const mod = sema.mod;
35849 const ip = &mod.intern_pool;
35850 const struct_type = mod.typeToStruct(ty) orelse return;
35714 const zcu = sema.mod;
35715 const ip = &zcu.intern_pool;
35716 const struct_type = zcu.typeToStruct(ty) orelse return;
3585135717 const owner_decl = struct_type.decl.unwrap() orelse return;
3585235718
3585335719 // Inits can start as resolved
......@@ -35856,20 +35722,19 @@ pub fn resolveStructFieldInits(sema: *Sema, ty: Type) CompileError!void {
3585635722 try sema.resolveStructLayout(ty);
3585735723
3585835724 if (struct_type.setInitsWip(ip)) {
35859 const msg = try Module.ErrorMsg.create(
35860 sema.gpa,
35861 mod.declPtr(owner_decl).srcLoc(mod),
35725 const msg = try sema.errMsg(
35726 ty.srcLoc(zcu),
3586235727 "struct '{}' depends on itself",
35863 .{ty.fmt(mod)},
35728 .{ty.fmt(zcu)},
3586435729 );
3586535730 return sema.failWithOwnedErrorMsg(null, msg);
3586635731 }
3586735732 defer struct_type.clearInitsWip(ip);
3586835733
35869 semaStructFieldInits(mod, sema.arena, struct_type) catch |err| switch (err) {
35734 semaStructFieldInits(zcu, sema.arena, struct_type) catch |err| switch (err) {
3587035735 error.AnalysisFail => {
35871 if (mod.declPtr(owner_decl).analysis == .complete) {
35872 mod.declPtr(owner_decl).analysis = .dependency_failure;
35736 if (zcu.declPtr(owner_decl).analysis == .complete) {
35737 zcu.declPtr(owner_decl).analysis = .dependency_failure;
3587335738 }
3587435739 return error.AnalysisFail;
3587535740 },
......@@ -35879,9 +35744,9 @@ pub fn resolveStructFieldInits(sema: *Sema, ty: Type) CompileError!void {
3587935744}
3588035745
3588135746pub fn resolveTypeFieldsUnion(sema: *Sema, ty: Type, union_type: InternPool.LoadedUnionType) CompileError!void {
35882 const mod = sema.mod;
35883 const ip = &mod.intern_pool;
35884 const owner_decl = mod.declPtr(union_type.decl);
35747 const zcu = sema.mod;
35748 const ip = &zcu.intern_pool;
35749 const owner_decl = zcu.declPtr(union_type.decl);
3588535750 switch (owner_decl.analysis) {
3588635751 .file_failure,
3588735752 .dependency_failure,
......@@ -35895,11 +35760,10 @@ pub fn resolveTypeFieldsUnion(sema: *Sema, ty: Type, union_type: InternPool.Load
3589535760 switch (union_type.flagsPtr(ip).status) {
3589635761 .none => {},
3589735762 .field_types_wip => {
35898 const msg = try Module.ErrorMsg.create(
35899 sema.gpa,
35900 owner_decl.srcLoc(mod),
35763 const msg = try sema.errMsg(
35764 ty.srcLoc(zcu),
3590135765 "union '{}' depends on itself",
35902 .{ty.fmt(mod)},
35766 .{ty.fmt(zcu)},
3590335767 );
3590435768 return sema.failWithOwnedErrorMsg(null, msg);
3590535769 },
......@@ -35913,7 +35777,7 @@ pub fn resolveTypeFieldsUnion(sema: *Sema, ty: Type, union_type: InternPool.Load
3591335777
3591435778 union_type.flagsPtr(ip).status = .field_types_wip;
3591535779 errdefer union_type.flagsPtr(ip).status = .none;
35916 semaUnionFields(mod, sema.arena, union_type) catch |err| switch (err) {
35780 semaUnionFields(zcu, sema.arena, union_type) catch |err| switch (err) {
3591735781 error.AnalysisFail => {
3591835782 if (owner_decl.analysis == .complete) {
3591935783 owner_decl.analysis = .dependency_failure;
......@@ -35963,10 +35827,13 @@ fn resolveInferredErrorSet(
3596335827 } else if (ip.errorUnionSet(ies_func_info.return_type) == ies_index) {
3596435828 if (ies_func_info.is_generic) {
3596535829 const msg = msg: {
35966 const msg = try sema.errMsg(block, src, "unable to resolve inferred error set of generic function", .{});
35830 const msg = try sema.errMsg(src, "unable to resolve inferred error set of generic function", .{});
3596735831 errdefer msg.destroy(sema.gpa);
3596835832
35969 try sema.mod.errNoteNonLazy(ies_func_owner_decl.srcLoc(mod), msg, "generic function declared here", .{});
35833 try sema.errNote(.{
35834 .base_node_inst = ies_func_owner_decl.zir_decl_index.unwrap().?,
35835 .offset = LazySrcLoc.Offset.nodeOffset(0),
35836 }, msg, "generic function declared here", .{});
3597035837 break :msg msg;
3597135838 };
3597235839 return sema.failWithOwnedErrorMsg(block, msg);
......@@ -36147,7 +36014,7 @@ fn semaStructFields(
3614736014 },
3614836015 };
3614936016
36150 var comptime_err_ret_trace = std.ArrayList(Module.SrcLoc).init(gpa);
36017 var comptime_err_ret_trace = std.ArrayList(LazySrcLoc).init(gpa);
3615136018 defer comptime_err_ret_trace.deinit();
3615236019
3615336020 var sema: Sema = .{
......@@ -36174,6 +36041,7 @@ fn semaStructFields(
3617436041 .instructions = .{},
3617536042 .inlining = null,
3617636043 .is_comptime = true,
36044 .src_base_inst = struct_type.zir_index.unwrap().?,
3617736045 };
3617836046 defer assert(block_scope.instructions.items.len == 0);
3617936047
......@@ -36252,35 +36120,19 @@ fn semaStructFields(
3625236120 // so that init values may depend on type layout.
3625336121
3625436122 for (fields, 0..) |zir_field, field_i| {
36123 const ty_src: LazySrcLoc = .{
36124 .base_node_inst = struct_type.zir_index.unwrap().?,
36125 .offset = .{ .container_field_type = @intCast(field_i) },
36126 };
3625536127 const field_ty: Type = ty: {
3625636128 if (zir_field.type_ref != .none) {
36257 break :ty sema.resolveType(&block_scope, .unneeded, zir_field.type_ref) catch |err| switch (err) {
36258 error.NeededSourceLocation => {
36259 const ty_src = mod.fieldSrcLoc(decl_index, .{
36260 .index = field_i,
36261 .range = .type,
36262 }).lazy;
36263 _ = try sema.resolveType(&block_scope, ty_src, zir_field.type_ref);
36264 unreachable;
36265 },
36266 else => |e| return e,
36267 };
36129 break :ty try sema.resolveType(&block_scope, ty_src, zir_field.type_ref);
3626836130 }
3626936131 assert(zir_field.type_body_len != 0);
3627036132 const body = zir.bodySlice(extra_index, zir_field.type_body_len);
3627136133 extra_index += body.len;
3627236134 const ty_ref = try sema.resolveInlineBody(&block_scope, body, zir_index);
36273 break :ty sema.analyzeAsType(&block_scope, .unneeded, ty_ref) catch |err| switch (err) {
36274 error.NeededSourceLocation => {
36275 const ty_src = mod.fieldSrcLoc(decl_index, .{
36276 .index = field_i,
36277 .range = .type,
36278 }).lazy;
36279 _ = try sema.analyzeAsType(&block_scope, ty_src, ty_ref);
36280 unreachable;
36281 },
36282 else => |e| return e,
36283 };
36135 break :ty try sema.analyzeAsType(&block_scope, ty_src, ty_ref);
3628436136 };
3628536137 if (field_ty.isGenericPoison()) {
3628636138 return error.GenericPoison;
......@@ -36290,11 +36142,7 @@ fn semaStructFields(
3629036142
3629136143 if (field_ty.zigTypeTag(mod) == .Opaque) {
3629236144 const msg = msg: {
36293 const ty_src = mod.fieldSrcLoc(decl_index, .{
36294 .index = field_i,
36295 .range = .type,
36296 }).lazy;
36297 const msg = try sema.errMsg(&block_scope, ty_src, "opaque types have unknown size and therefore cannot be directly embedded in structs", .{});
36145 const msg = try sema.errMsg(ty_src, "opaque types have unknown size and therefore cannot be directly embedded in structs", .{});
3629836146 errdefer msg.destroy(sema.gpa);
3629936147
3630036148 try sema.addDeclaredHereNote(msg, field_ty);
......@@ -36304,11 +36152,7 @@ fn semaStructFields(
3630436152 }
3630536153 if (field_ty.zigTypeTag(mod) == .NoReturn) {
3630636154 const msg = msg: {
36307 const ty_src = mod.fieldSrcLoc(decl_index, .{
36308 .index = field_i,
36309 .range = .type,
36310 }).lazy;
36311 const msg = try sema.errMsg(&block_scope, ty_src, "struct fields cannot be 'noreturn'", .{});
36155 const msg = try sema.errMsg(ty_src, "struct fields cannot be 'noreturn'", .{});
3631236156 errdefer msg.destroy(sema.gpa);
3631336157
3631436158 try sema.addDeclaredHereNote(msg, field_ty);
......@@ -36319,11 +36163,7 @@ fn semaStructFields(
3631936163 switch (struct_type.layout) {
3632036164 .@"extern" => if (!try sema.validateExternType(field_ty, .struct_field)) {
3632136165 const msg = msg: {
36322 const ty_src = mod.fieldSrcLoc(decl_index, .{
36323 .index = field_i,
36324 .range = .type,
36325 });
36326 const msg = try sema.errMsg(&block_scope, ty_src.lazy, "extern structs cannot contain fields of type '{}'", .{field_ty.fmt(mod)});
36166 const msg = try sema.errMsg(ty_src, "extern structs cannot contain fields of type '{}'", .{field_ty.fmt(mod)});
3632736167 errdefer msg.destroy(sema.gpa);
3632836168
3632936169 try sema.explainWhyTypeIsNotExtern(msg, ty_src, field_ty, .struct_field);
......@@ -36335,11 +36175,7 @@ fn semaStructFields(
3633536175 },
3633636176 .@"packed" => if (!try sema.validatePackedType(field_ty)) {
3633736177 const msg = msg: {
36338 const ty_src = mod.fieldSrcLoc(decl_index, .{
36339 .index = field_i,
36340 .range = .type,
36341 });
36342 const msg = try sema.errMsg(&block_scope, ty_src.lazy, "packed structs cannot contain fields of type '{}'", .{field_ty.fmt(mod)});
36178 const msg = try sema.errMsg(ty_src, "packed structs cannot contain fields of type '{}'", .{field_ty.fmt(mod)});
3634336179 errdefer msg.destroy(sema.gpa);
3634436180
3634536181 try sema.explainWhyTypeIsNotPacked(msg, ty_src, field_ty);
......@@ -36356,17 +36192,11 @@ fn semaStructFields(
3635636192 const body = zir.bodySlice(extra_index, zir_field.align_body_len);
3635736193 extra_index += body.len;
3635836194 const align_ref = try sema.resolveInlineBody(&block_scope, body, zir_index);
36359 const field_align = sema.analyzeAsAlign(&block_scope, .unneeded, align_ref) catch |err| switch (err) {
36360 error.NeededSourceLocation => {
36361 const align_src = mod.fieldSrcLoc(decl_index, .{
36362 .index = field_i,
36363 .range = .alignment,
36364 }).lazy;
36365 _ = try sema.analyzeAsAlign(&block_scope, align_src, align_ref);
36366 unreachable;
36367 },
36368 else => |e| return e,
36195 const align_src: LazySrcLoc = .{
36196 .base_node_inst = struct_type.zir_index.unwrap().?,
36197 .offset = .{ .container_field_align = @intCast(field_i) },
3636936198 };
36199 const field_align = try sema.analyzeAsAlign(&block_scope, align_src, align_ref);
3637036200 struct_type.field_aligns.get(ip)[field_i] = field_align;
3637136201 }
3637236202
......@@ -36395,7 +36225,7 @@ fn semaStructFieldInits(
3639536225 const zir_index = struct_type.zir_index.unwrap().?.resolve(ip);
3639636226 const fields_len, const small, var extra_index = structZirInfo(zir, zir_index);
3639736227
36398 var comptime_err_ret_trace = std.ArrayList(Module.SrcLoc).init(gpa);
36228 var comptime_err_ret_trace = std.ArrayList(LazySrcLoc).init(gpa);
3639936229 defer comptime_err_ret_trace.deinit();
3640036230
3640136231 var sema: Sema = .{
......@@ -36422,6 +36252,7 @@ fn semaStructFieldInits(
3642236252 .instructions = .{},
3642336253 .inlining = null,
3642436254 .is_comptime = true,
36255 .src_base_inst = struct_type.zir_index.unwrap().?,
3642536256 };
3642636257 defer assert(block_scope.instructions.items.len == 0);
3642736258
......@@ -36495,33 +36326,20 @@ fn semaStructFieldInits(
3649536326 try sema.inst_map.ensureSpaceForInstructions(sema.gpa, &.{zir_index});
3649636327 sema.inst_map.putAssumeCapacity(zir_index, type_ref);
3649736328
36498 const init = try sema.resolveInlineBody(&block_scope, body, zir_index);
36499 const coerced = sema.coerce(&block_scope, field_ty, init, .unneeded) catch |err| switch (err) {
36500 error.NeededSourceLocation => {
36501 const init_src = mod.fieldSrcLoc(decl_index, .{
36502 .index = field_i,
36503 .range = .value,
36504 }).lazy;
36505 _ = try sema.coerce(&block_scope, field_ty, init, init_src);
36506 unreachable;
36507 },
36508 else => |e| return e,
36329 const init_src: LazySrcLoc = .{
36330 .base_node_inst = struct_type.zir_index.unwrap().?,
36331 .offset = .{ .container_field_value = @intCast(field_i) },
3650936332 };
36510 const default_val = (try sema.resolveValue(coerced)) orelse {
36511 const init_src = mod.fieldSrcLoc(decl_index, .{
36512 .index = field_i,
36513 .range = .value,
36514 }).lazy;
36333
36334 const init = try sema.resolveInlineBody(&block_scope, body, zir_index);
36335 const coerced = try sema.coerce(&block_scope, field_ty, init, init_src);
36336 const default_val = try sema.resolveValue(coerced) orelse {
3651536337 return sema.failWithNeededComptime(&block_scope, init_src, .{
3651636338 .needed_comptime_reason = "struct field default value must be comptime-known",
3651736339 });
3651836340 };
3651936341
3652036342 if (default_val.canMutateComptimeVarState(mod)) {
36521 const init_src = mod.fieldSrcLoc(decl_index, .{
36522 .index = field_i,
36523 .range = .value,
36524 }).lazy;
3652536343 return sema.fail(&block_scope, init_src, "field default value contains reference to comptime-mutable memory", .{});
3652636344 }
3652736345 struct_type.field_inits.get(ip)[field_i] = default_val.toIntern();
......@@ -36543,8 +36361,6 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded
3654336361 const small: Zir.Inst.UnionDecl.Small = @bitCast(extended.small);
3654436362 var extra_index: usize = extended.operand + @typeInfo(Zir.Inst.UnionDecl).Struct.fields.len;
3654536363
36546 const src = LazySrcLoc.nodeOffset(0);
36547
3654836364 const tag_type_ref: Zir.Inst.Ref = if (small.has_tag_type) blk: {
3654936365 const ty_ref: Zir.Inst.Ref = @enumFromInt(zir.extra[extra_index]);
3655036366 extra_index += 1;
......@@ -36583,7 +36399,7 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded
3658336399
3658436400 const decl = mod.declPtr(decl_index);
3658536401
36586 var comptime_err_ret_trace = std.ArrayList(Module.SrcLoc).init(gpa);
36402 var comptime_err_ret_trace = std.ArrayList(LazySrcLoc).init(gpa);
3658736403 defer comptime_err_ret_trace.deinit();
3658836404
3658936405 var sema: Sema = .{
......@@ -36610,9 +36426,12 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded
3661036426 .instructions = .{},
3661136427 .inlining = null,
3661236428 .is_comptime = true,
36429 .src_base_inst = union_type.zir_index,
3661336430 };
3661436431 defer assert(block_scope.instructions.items.len == 0);
3661536432
36433 const src = block_scope.nodeOffset(0);
36434
3661636435 if (body.len != 0) {
3661736436 _ = try sema.analyzeInlineBody(&block_scope, body, zir_index);
3661836437 }
......@@ -36622,7 +36441,10 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded
3662236441 var enum_field_vals: std.AutoArrayHashMapUnmanaged(InternPool.Index, void) = .{};
3662336442 var explicit_tags_seen: []bool = &.{};
3662436443 if (tag_type_ref != .none) {
36625 const tag_ty_src: LazySrcLoc = .{ .node_offset_container_tag = src.node_offset.x };
36444 const tag_ty_src: LazySrcLoc = .{
36445 .base_node_inst = union_type.zir_index,
36446 .offset = .{ .node_offset_container_tag = 0 },
36447 };
3662636448 const provided_ty = try sema.resolveType(&block_scope, tag_ty_src, tag_type_ref);
3662736449 if (small.auto_enum_tag) {
3662836450 // The provided type is an integer type and we must construct the enum tag type here.
......@@ -36635,9 +36457,9 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded
3663536457 const field_count_val = try mod.intValue(Type.comptime_int, fields_len - 1);
3663636458 if (!(try sema.intFitsInType(field_count_val, int_tag_ty, null))) {
3663736459 const msg = msg: {
36638 const msg = try sema.errMsg(&block_scope, tag_ty_src, "specified integer tag type cannot represent every field", .{});
36460 const msg = try sema.errMsg(tag_ty_src, "specified integer tag type cannot represent every field", .{});
3663936461 errdefer msg.destroy(sema.gpa);
36640 try sema.errNote(&block_scope, tag_ty_src, msg, "type '{}' cannot fit values in range 0...{d}", .{
36462 try sema.errNote(tag_ty_src, msg, "type '{}' cannot fit values in range 0...{d}", .{
3664136463 int_tag_ty.fmt(mod),
3664236464 fields_len - 1,
3664336465 });
......@@ -36722,19 +36544,26 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded
3672236544 break :blk try sema.resolveInst(tag_ref);
3672336545 } else .none;
3672436546
36547 const name_src: LazySrcLoc = .{
36548 .base_node_inst = union_type.zir_index,
36549 .offset = .{ .container_field_name = field_i },
36550 };
36551 const value_src: LazySrcLoc = .{
36552 .base_node_inst = union_type.zir_index,
36553 .offset = .{ .container_field_value = field_i },
36554 };
36555 const align_src: LazySrcLoc = .{
36556 .base_node_inst = union_type.zir_index,
36557 .offset = .{ .container_field_align = field_i },
36558 };
36559 const type_src: LazySrcLoc = .{
36560 .base_node_inst = union_type.zir_index,
36561 .offset = .{ .container_field_type = field_i },
36562 };
36563
3672536564 if (enum_field_vals.capacity() > 0) {
3672636565 const enum_tag_val = if (tag_ref != .none) blk: {
36727 const val = sema.semaUnionFieldVal(&block_scope, .unneeded, int_tag_ty, tag_ref) catch |err| switch (err) {
36728 error.NeededSourceLocation => {
36729 const val_src = mod.fieldSrcLoc(union_type.decl, .{
36730 .index = field_i,
36731 .range = .value,
36732 }).lazy;
36733 _ = try sema.semaUnionFieldVal(&block_scope, val_src, int_tag_ty, tag_ref);
36734 unreachable;
36735 },
36736 else => |e| return e,
36737 };
36566 const val = try sema.semaUnionFieldVal(&block_scope, value_src, int_tag_ty, tag_ref);
3673836567 last_tag_val = val;
3673936568
3674036569 break :blk val;
......@@ -36749,12 +36578,14 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded
3674936578 };
3675036579 const gop = enum_field_vals.getOrPutAssumeCapacity(enum_tag_val.toIntern());
3675136580 if (gop.found_existing) {
36752 const field_src = mod.fieldSrcLoc(union_type.decl, .{ .index = field_i }).lazy;
36753 const other_field_src = mod.fieldSrcLoc(union_type.decl, .{ .index = gop.index }).lazy;
36581 const other_value_src: LazySrcLoc = .{
36582 .base_node_inst = union_type.zir_index,
36583 .offset = .{ .container_field_value = @intCast(gop.index) },
36584 };
3675436585 const msg = msg: {
36755 const msg = try sema.errMsg(&block_scope, field_src, "enum tag value {} already taken", .{enum_tag_val.fmtValue(mod, &sema)});
36586 const msg = try sema.errMsg(value_src, "enum tag value {} already taken", .{enum_tag_val.fmtValue(mod, &sema)});
3675636587 errdefer msg.destroy(gpa);
36757 try sema.errNote(&block_scope, other_field_src, msg, "other occurrence here", .{});
36588 try sema.errNote(other_value_src, msg, "other occurrence here", .{});
3675836589 break :msg msg;
3675936590 };
3676036591 return sema.failWithOwnedErrorMsg(&block_scope, msg);
......@@ -36772,17 +36603,7 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded
3677236603 else if (field_type_ref == .none)
3677336604 Type.noreturn
3677436605 else
36775 sema.resolveType(&block_scope, .unneeded, field_type_ref) catch |err| switch (err) {
36776 error.NeededSourceLocation => {
36777 const ty_src = mod.fieldSrcLoc(union_type.decl, .{
36778 .index = field_i,
36779 .range = .type,
36780 }).lazy;
36781 _ = try sema.resolveType(&block_scope, ty_src, field_type_ref);
36782 unreachable;
36783 },
36784 else => |e| return e,
36785 };
36606 try sema.resolveType(&block_scope, type_src, field_type_ref);
3678636607
3678736608 if (field_ty.isGenericPoison()) {
3678836609 return error.GenericPoison;
......@@ -36791,11 +36612,7 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded
3679136612 if (explicit_tags_seen.len > 0) {
3679236613 const tag_info = ip.loadEnumType(union_type.tagTypePtr(ip).*);
3679336614 const enum_index = tag_info.nameIndex(ip, field_name) orelse {
36794 const ty_src = mod.fieldSrcLoc(union_type.decl, .{
36795 .index = field_i,
36796 .range = .name,
36797 }).lazy;
36798 return sema.fail(&block_scope, ty_src, "no field named '{}' in enum '{}'", .{
36615 return sema.fail(&block_scope, name_src, "no field named '{}' in enum '{}'", .{
3679936616 field_name.fmt(ip), Type.fromInterned(union_type.tagTypePtr(ip).*).fmt(mod),
3680036617 });
3680136618 };
......@@ -36808,17 +36625,15 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded
3680836625 // Enforce the enum fields and the union fields being in the same order.
3680936626 if (enum_index != field_i) {
3681036627 const msg = msg: {
36811 const ty_src = mod.fieldSrcLoc(union_type.decl, .{
36812 .index = field_i,
36813 .range = .name,
36814 }).lazy;
36815 const enum_field_src = mod.fieldSrcLoc(tag_info.decl, .{ .index = enum_index }).lazy;
36816 const msg = try sema.errMsg(&block_scope, ty_src, "union field '{}' ordered differently than corresponding enum field", .{
36628 const enum_field_src: LazySrcLoc = .{
36629 .base_node_inst = tag_info.zir_index.unwrap().?,
36630 .offset = .{ .container_field_name = enum_index },
36631 };
36632 const msg = try sema.errMsg(name_src, "union field '{}' ordered differently than corresponding enum field", .{
3681736633 field_name.fmt(ip),
3681836634 });
3681936635 errdefer msg.destroy(sema.gpa);
36820 const decl_ptr = mod.declPtr(tag_info.decl);
36821 try mod.errNoteNonLazy(decl_ptr.toSrcLoc(enum_field_src, mod), msg, "enum field here", .{});
36636 try sema.errNote(enum_field_src, msg, "enum field here", .{});
3682236637 break :msg msg;
3682336638 };
3682436639 return sema.failWithOwnedErrorMsg(&block_scope, msg);
......@@ -36827,11 +36642,7 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded
3682736642
3682836643 if (field_ty.zigTypeTag(mod) == .Opaque) {
3682936644 const msg = msg: {
36830 const ty_src = mod.fieldSrcLoc(union_type.decl, .{
36831 .index = field_i,
36832 .range = .type,
36833 }).lazy;
36834 const msg = try sema.errMsg(&block_scope, ty_src, "opaque types have unknown size and therefore cannot be directly embedded in unions", .{});
36645 const msg = try sema.errMsg(type_src, "opaque types have unknown size and therefore cannot be directly embedded in unions", .{});
3683536646 errdefer msg.destroy(sema.gpa);
3683636647
3683736648 try sema.addDeclaredHereNote(msg, field_ty);
......@@ -36844,14 +36655,10 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded
3684436655 !try sema.validateExternType(field_ty, .union_field))
3684536656 {
3684636657 const msg = msg: {
36847 const ty_src = mod.fieldSrcLoc(union_type.decl, .{
36848 .index = field_i,
36849 .range = .type,
36850 });
36851 const msg = try sema.errMsg(&block_scope, ty_src.lazy, "extern unions cannot contain fields of type '{}'", .{field_ty.fmt(mod)});
36658 const msg = try sema.errMsg(type_src, "extern unions cannot contain fields of type '{}'", .{field_ty.fmt(mod)});
3685236659 errdefer msg.destroy(sema.gpa);
3685336660
36854 try sema.explainWhyTypeIsNotExtern(msg, ty_src, field_ty, .union_field);
36661 try sema.explainWhyTypeIsNotExtern(msg, type_src, field_ty, .union_field);
3685536662
3685636663 try sema.addDeclaredHereNote(msg, field_ty);
3685736664 break :msg msg;
......@@ -36859,14 +36666,10 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded
3685936666 return sema.failWithOwnedErrorMsg(&block_scope, msg);
3686036667 } else if (layout == .@"packed" and !try sema.validatePackedType(field_ty)) {
3686136668 const msg = msg: {
36862 const ty_src = mod.fieldSrcLoc(union_type.decl, .{
36863 .index = field_i,
36864 .range = .type,
36865 });
36866 const msg = try sema.errMsg(&block_scope, ty_src.lazy, "packed unions cannot contain fields of type '{}'", .{field_ty.fmt(mod)});
36669 const msg = try sema.errMsg(type_src, "packed unions cannot contain fields of type '{}'", .{field_ty.fmt(mod)});
3686736670 errdefer msg.destroy(sema.gpa);
3686836671
36869 try sema.explainWhyTypeIsNotPacked(msg, ty_src, field_ty);
36672 try sema.explainWhyTypeIsNotPacked(msg, type_src, field_ty);
3687036673
3687136674 try sema.addDeclaredHereNote(msg, field_ty);
3687236675 break :msg msg;
......@@ -36878,17 +36681,7 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded
3687836681
3687936682 if (small.any_aligned_fields) {
3688036683 field_aligns.appendAssumeCapacity(if (align_ref != .none)
36881 sema.resolveAlign(&block_scope, .unneeded, align_ref) catch |err| switch (err) {
36882 error.NeededSourceLocation => {
36883 const align_src = mod.fieldSrcLoc(union_type.decl, .{
36884 .index = field_i,
36885 .range = .alignment,
36886 }).lazy;
36887 _ = try sema.resolveAlign(&block_scope, align_src, align_ref);
36888 unreachable;
36889 },
36890 else => |e| return e,
36891 }
36684 try sema.resolveAlign(&block_scope, align_src, align_ref)
3689236685 else
3689336686 .none);
3689436687 } else {
......@@ -36903,7 +36696,7 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded
3690336696 const tag_info = ip.loadEnumType(union_type.tagTypePtr(ip).*);
3690436697 if (tag_info.names.len > fields_len) {
3690536698 const msg = msg: {
36906 const msg = try sema.errMsg(&block_scope, src, "enum field(s) missing in union", .{});
36699 const msg = try sema.errMsg(src, "enum field(s) missing in union", .{});
3690736700 errdefer msg.destroy(sema.gpa);
3690836701
3690936702 for (tag_info.names.get(ip), 0..) |field_name, field_index| {
......@@ -36945,7 +36738,7 @@ fn generateUnionTagTypeNumbered(
3694536738 const ip = &mod.intern_pool;
3694636739
3694736740 const src_decl = mod.declPtr(block.src_decl);
36948 const new_decl_index = try mod.allocateNewDecl(block.namespace, src_decl.src_node);
36741 const new_decl_index = try mod.allocateNewDecl(block.namespace);
3694936742 errdefer mod.destroyDecl(new_decl_index);
3695036743 const fqn = try union_owner_decl.fullyQualifiedName(mod);
3695136744 const name = try ip.getOrPutStringFmt(
......@@ -36997,7 +36790,7 @@ fn generateUnionTagTypeSimple(
3699736790 const new_decl_index = new_decl_index: {
3699836791 const fqn = try union_owner_decl.fullyQualifiedName(mod);
3699936792 const src_decl = mod.declPtr(block.src_decl);
37000 const new_decl_index = try mod.allocateNewDecl(block.namespace, src_decl.src_node);
36793 const new_decl_index = try mod.allocateNewDecl(block.namespace);
3700136794 errdefer mod.destroyDecl(new_decl_index);
3700236795 const name = try ip.getOrPutStringFmt(
3700336796 gpa,
......@@ -37037,8 +36830,7 @@ fn generateUnionTagTypeSimple(
3703736830}
3703836831
3703936832fn getBuiltin(sema: *Sema, name: []const u8) CompileError!Air.Inst.Ref {
37040 const gpa = sema.gpa;
37041 const src = LazySrcLoc.nodeOffset(0);
36833 const zcu = sema.mod;
3704236834
3704336835 var block: Block = .{
3704436836 .parent = null,
......@@ -37048,8 +36840,23 @@ fn getBuiltin(sema: *Sema, name: []const u8) CompileError!Air.Inst.Ref {
3704836840 .instructions = .{},
3704936841 .inlining = null,
3705036842 .is_comptime = true,
36843 .src_base_inst = sema.owner_decl.zir_decl_index.unwrap() orelse owner: {
36844 assert(sema.owner_decl.has_tv);
36845 assert(sema.owner_decl.owns_tv);
36846 switch (sema.owner_decl.typeOf(zcu).zigTypeTag(zcu)) {
36847 .Type => break :owner sema.owner_decl.val.toType().typeDeclInst(zcu).?,
36848 .Fn => {
36849 const owner = zcu.funcInfo(sema.owner_decl.val.toIntern()).generic_owner;
36850 const generic_owner_decl = zcu.declPtr(zcu.funcInfo(owner).owner_decl);
36851 break :owner generic_owner_decl.zir_decl_index.unwrap().?;
36852 },
36853 else => unreachable,
36854 }
36855 },
3705136856 };
37052 defer block.instructions.deinit(gpa);
36857 defer block.instructions.deinit(sema.gpa);
36858
36859 const src = block.nodeOffset(0);
3705336860
3705436861 const decl_index = try getBuiltinDecl(sema, &block, name);
3705536862 return sema.analyzeDeclVal(&block, src, decl_index);
......@@ -37058,7 +36865,7 @@ fn getBuiltin(sema: *Sema, name: []const u8) CompileError!Air.Inst.Ref {
3705836865fn getBuiltinDecl(sema: *Sema, block: *Block, name: []const u8) CompileError!InternPool.DeclIndex {
3705936866 const gpa = sema.gpa;
3706036867
37061 const src = LazySrcLoc.nodeOffset(0);
36868 const src = block.nodeOffset(0);
3706236869
3706336870 const mod = sema.mod;
3706436871 const ip = &mod.intern_pool;
......@@ -37085,6 +36892,7 @@ fn getBuiltinDecl(sema: *Sema, block: *Block, name: []const u8) CompileError!Int
3708536892}
3708636893
3708736894fn getBuiltinType(sema: *Sema, name: []const u8) CompileError!Type {
36895 const zcu = sema.mod;
3708836896 const ty_inst = try sema.getBuiltin(name);
3708936897
3709036898 var block: Block = .{
......@@ -37095,9 +36903,23 @@ fn getBuiltinType(sema: *Sema, name: []const u8) CompileError!Type {
3709536903 .instructions = .{},
3709636904 .inlining = null,
3709736905 .is_comptime = true,
36906 .src_base_inst = sema.owner_decl.zir_decl_index.unwrap() orelse owner: {
36907 assert(sema.owner_decl.has_tv);
36908 assert(sema.owner_decl.owns_tv);
36909 switch (sema.owner_decl.typeOf(zcu).zigTypeTag(zcu)) {
36910 .Type => break :owner sema.owner_decl.val.toType().typeDeclInst(zcu).?,
36911 .Fn => {
36912 const owner = zcu.funcInfo(sema.owner_decl.val.toIntern()).generic_owner;
36913 const generic_owner_decl = zcu.declPtr(zcu.funcInfo(owner).owner_decl);
36914 break :owner generic_owner_decl.zir_decl_index.unwrap().?;
36915 },
36916 else => unreachable,
36917 }
36918 },
3709836919 };
3709936920 defer block.instructions.deinit(sema.gpa);
37100 const src = LazySrcLoc.nodeOffset(0);
36921
36922 const src = block.nodeOffset(0);
3710136923
3710236924 const result_ty = sema.analyzeAsType(&block, src, ty_inst) catch |err| switch (err) {
3710336925 error.AnalysisFail => std.debug.panic("std.builtin.{s} is corrupt", .{name}),
......@@ -37113,12 +36935,12 @@ fn getBuiltinType(sema: *Sema, name: []const u8) CompileError!Type {
3711336935/// that the types are already resolved.
3711436936/// TODO assert the return value matches `ty.onePossibleValue`
3711536937pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {
37116 const mod = sema.mod;
37117 const ip = &mod.intern_pool;
36938 const zcu = sema.mod;
36939 const ip = &zcu.intern_pool;
3711836940 return switch (ty.toIntern()) {
3711936941 .u0_type,
3712036942 .i0_type,
37121 => try mod.intValue(ty, 0),
36943 => try zcu.intValue(ty, 0),
3712236944 .u1_type,
3712336945 .u8_type,
3712436946 .i8_type,
......@@ -37181,7 +37003,7 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {
3718137003 .anyframe_type => unreachable,
3718237004 .null_type => Value.null,
3718337005 .undefined_type => Value.undef,
37184 .optional_noreturn_type => try mod.nullValue(ty),
37006 .optional_noreturn_type => try zcu.nullValue(ty),
3718537007 .generic_poison_type => error.GenericPoison,
3718637008 .empty_struct_type => Value.empty_struct,
3718737009 // values, not types
......@@ -37295,13 +37117,13 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {
3729537117 => switch (ip.indexToKey(ty.toIntern())) {
3729637118 inline .array_type, .vector_type => |seq_type, seq_tag| {
3729737119 const has_sentinel = seq_tag == .array_type and seq_type.sentinel != .none;
37298 if (seq_type.len + @intFromBool(has_sentinel) == 0) return Value.fromInterned((try mod.intern(.{ .aggregate = .{
37120 if (seq_type.len + @intFromBool(has_sentinel) == 0) return Value.fromInterned((try zcu.intern(.{ .aggregate = .{
3729937121 .ty = ty.toIntern(),
3730037122 .storage = .{ .elems = &.{} },
3730137123 } })));
3730237124
3730337125 if (try sema.typeHasOnePossibleValue(Type.fromInterned(seq_type.child))) |opv| {
37304 return Value.fromInterned((try mod.intern(.{ .aggregate = .{
37126 return Value.fromInterned((try zcu.intern(.{ .aggregate = .{
3730537127 .ty = ty.toIntern(),
3730637128 .storage = .{ .repeated_elem = opv.toIntern() },
3730737129 } })));
......@@ -37316,7 +37138,7 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {
3731637138 if (struct_type.field_types.len == 0) {
3731737139 // In this case the struct has no fields at all and
3731837140 // therefore has one possible value.
37319 return Value.fromInterned((try mod.intern(.{ .aggregate = .{
37141 return Value.fromInterned((try zcu.intern(.{ .aggregate = .{
3732037142 .ty = ty.toIntern(),
3732137143 .storage = .{ .elems = &.{} },
3732237144 } })));
......@@ -37333,12 +37155,11 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {
3733337155 continue;
3733437156 }
3733537157 const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[i]);
37336 if (field_ty.eql(ty, mod)) {
37337 const msg = try Module.ErrorMsg.create(
37338 sema.gpa,
37339 mod.declPtr(struct_type.decl.unwrap().?).srcLoc(mod),
37158 if (field_ty.eql(ty, zcu)) {
37159 const msg = try sema.errMsg(
37160 ty.srcLoc(zcu),
3734037161 "struct '{}' depends on itself",
37341 .{ty.fmt(mod)},
37162 .{ty.fmt(zcu)},
3734237163 );
3734337164 try sema.addFieldErrNote(ty, i, msg, "while checking this field", .{});
3734437165 return sema.failWithOwnedErrorMsg(null, msg);
......@@ -37350,7 +37171,7 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {
3735037171
3735137172 // In this case the struct has no runtime-known fields and
3735237173 // therefore has one possible value.
37353 return Value.fromInterned((try mod.intern(.{ .aggregate = .{
37174 return Value.fromInterned((try zcu.intern(.{ .aggregate = .{
3735437175 .ty = ty.toIntern(),
3735537176 .storage = .{ .elems = field_vals },
3735637177 } })));
......@@ -37363,7 +37184,7 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {
3736337184 // In this case the struct has all comptime-known fields and
3736437185 // therefore has one possible value.
3736537186 // TODO: write something like getCoercedInts to avoid needing to dupe
37366 return Value.fromInterned((try mod.intern(.{ .aggregate = .{
37187 return Value.fromInterned((try zcu.intern(.{ .aggregate = .{
3736737188 .ty = ty.toIntern(),
3736837189 .storage = .{ .elems = try sema.arena.dupe(InternPool.Index, tuple.values.get(ip)) },
3736937190 } })));
......@@ -37375,23 +37196,22 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {
3737537196 const tag_val = (try sema.typeHasOnePossibleValue(Type.fromInterned(union_obj.tagTypePtr(ip).*))) orelse
3737637197 return null;
3737737198 if (union_obj.field_types.len == 0) {
37378 const only = try mod.intern(.{ .empty_enum_value = ty.toIntern() });
37199 const only = try zcu.intern(.{ .empty_enum_value = ty.toIntern() });
3737937200 return Value.fromInterned(only);
3738037201 }
3738137202 const only_field_ty = Type.fromInterned(union_obj.field_types.get(ip)[0]);
37382 if (only_field_ty.eql(ty, mod)) {
37383 const msg = try Module.ErrorMsg.create(
37384 sema.gpa,
37385 mod.declPtr(union_obj.decl).srcLoc(mod),
37203 if (only_field_ty.eql(ty, zcu)) {
37204 const msg = try sema.errMsg(
37205 ty.srcLoc(zcu),
3738637206 "union '{}' depends on itself",
37387 .{ty.fmt(mod)},
37207 .{ty.fmt(zcu)},
3738837208 );
3738937209 try sema.addFieldErrNote(ty, 0, msg, "while checking this field", .{});
3739037210 return sema.failWithOwnedErrorMsg(null, msg);
3739137211 }
3739237212 const val_val = (try sema.typeHasOnePossibleValue(only_field_ty)) orelse
3739337213 return null;
37394 const only = try mod.intern(.{ .un = .{
37214 const only = try zcu.intern(.{ .un = .{
3739537215 .ty = ty.toIntern(),
3739637216 .tag = tag_val.toIntern(),
3739737217 .val = val_val.toIntern(),
......@@ -37406,7 +37226,7 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {
3740637226 if (enum_type.tag_ty == .comptime_int_type) return null;
3740737227
3740837228 if (try sema.typeHasOnePossibleValue(Type.fromInterned(enum_type.tag_ty))) |int_opv| {
37409 const only = try mod.intern(.{ .enum_tag = .{
37229 const only = try zcu.intern(.{ .enum_tag = .{
3741037230 .ty = ty.toIntern(),
3741137231 .int = int_opv.toIntern(),
3741237232 } });
......@@ -37416,18 +37236,18 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {
3741637236 return null;
3741737237 },
3741837238 .auto, .explicit => {
37419 if (Type.fromInterned(enum_type.tag_ty).hasRuntimeBits(mod)) return null;
37239 if (Type.fromInterned(enum_type.tag_ty).hasRuntimeBits(zcu)) return null;
3742037240
3742137241 return Value.fromInterned(switch (enum_type.names.len) {
37422 0 => try mod.intern(.{ .empty_enum_value = ty.toIntern() }),
37423 1 => try mod.intern(.{ .enum_tag = .{
37242 0 => try zcu.intern(.{ .empty_enum_value = ty.toIntern() }),
37243 1 => try zcu.intern(.{ .enum_tag = .{
3742437244 .ty = ty.toIntern(),
3742537245 .int = if (enum_type.values.len == 0)
37426 (try mod.intValue(Type.fromInterned(enum_type.tag_ty), 0)).toIntern()
37246 (try zcu.intValue(Type.fromInterned(enum_type.tag_ty), 0)).toIntern()
3742737247 else
37428 try mod.intern_pool.getCoercedInts(
37429 mod.gpa,
37430 mod.intern_pool.indexToKey(enum_type.values.get(ip)[0]).int,
37248 try zcu.intern_pool.getCoercedInts(
37249 zcu.gpa,
37250 zcu.intern_pool.indexToKey(enum_type.values.get(ip)[0]).int,
3743137251 enum_type.tag_ty,
3743237252 ),
3743337253 } }),
......@@ -37765,7 +37585,7 @@ fn unionFieldIndex(
3776537585 try sema.resolveTypeFields(union_ty);
3776637586 const union_obj = mod.typeToUnion(union_ty).?;
3776737587 const field_index = union_obj.loadTagType(ip).nameIndex(ip, field_name) orelse
37768 return sema.failWithBadUnionFieldAccess(block, union_obj, field_src, field_name);
37588 return sema.failWithBadUnionFieldAccess(block, union_ty, union_obj, field_src, field_name);
3776937589 return @intCast(field_index);
3777037590}
3777137591
......@@ -37784,7 +37604,7 @@ fn structFieldIndex(
3778437604 } else {
3778537605 const struct_type = mod.typeToStruct(struct_ty).?;
3778637606 return struct_type.nameIndex(ip, field_name) orelse
37787 return sema.failWithBadStructFieldAccess(block, struct_type, field_src, field_name);
37607 return sema.failWithBadStructFieldAccess(block, struct_ty, struct_type, field_src, field_name);
3778837608 }
3778937609}
3779037610
......@@ -38556,9 +38376,9 @@ fn checkRuntimeValue(sema: *Sema, ptr: Air.Inst.Ref) bool {
3855638376fn validateRuntimeValue(sema: *Sema, block: *Block, val_src: LazySrcLoc, val: Air.Inst.Ref) CompileError!void {
3855738377 if (sema.checkRuntimeValue(val)) return;
3855838378 return sema.failWithOwnedErrorMsg(block, msg: {
38559 const msg = try sema.errMsg(block, val_src, "runtime value contains reference to comptime var", .{});
38379 const msg = try sema.errMsg(val_src, "runtime value contains reference to comptime var", .{});
3856038380 errdefer msg.destroy(sema.gpa);
38561 try sema.errNote(block, val_src, msg, "comptime var pointers are not available at runtime", .{});
38381 try sema.errNote(val_src, msg, "comptime var pointers are not available at runtime", .{});
3856238382 break :msg msg;
3856338383 });
3856438384}
......@@ -38649,6 +38469,14 @@ fn maybeDerefSliceAsArray(
3864938469 return sema.pointerDeref(block, src, casted_ptr, ptr_ty);
3865038470}
3865138471
38472fn analyzeUnreachable(sema: *Sema, block: *Block, src: LazySrcLoc, safety_check: bool) !void {
38473 if (safety_check and block.wantSafety()) {
38474 try sema.safetyPanic(block, src, .unreach);
38475 } else {
38476 _ = try block.addNoOp(.unreach);
38477 }
38478}
38479
3865238480pub const bitCastVal = @import("Sema/bitcast.zig").bitCast;
3865338481pub const bitCastSpliceVal = @import("Sema/bitcast.zig").bitCastSplice;
3865438482
src/Sema/comptime_ptr_access.zig+4-4
......@@ -1025,18 +1025,18 @@ fn checkComptimeVarStore(
10251025 if (@intFromEnum(runtime_index) < @intFromEnum(block.runtime_index)) {
10261026 if (block.runtime_cond) |cond_src| {
10271027 const msg = msg: {
1028 const msg = try sema.errMsg(block, src, "store to comptime variable depends on runtime condition", .{});
1028 const msg = try sema.errMsg(src, "store to comptime variable depends on runtime condition", .{});
10291029 errdefer msg.destroy(sema.gpa);
1030 try sema.mod.errNoteNonLazy(cond_src, msg, "runtime condition here", .{});
1030 try sema.errNote(cond_src, msg, "runtime condition here", .{});
10311031 break :msg msg;
10321032 };
10331033 return sema.failWithOwnedErrorMsg(block, msg);
10341034 }
10351035 if (block.runtime_loop) |loop_src| {
10361036 const msg = msg: {
1037 const msg = try sema.errMsg(block, src, "cannot store to comptime variable in non-inline loop", .{});
1037 const msg = try sema.errMsg(src, "cannot store to comptime variable in non-inline loop", .{});
10381038 errdefer msg.destroy(sema.gpa);
1039 try sema.mod.errNoteNonLazy(loop_src, msg, "non-inline loop here", .{});
1039 try sema.errNote(loop_src, msg, "non-inline loop here", .{});
10401040 break :msg msg;
10411041 };
10421042 return sema.failWithOwnedErrorMsg(block, msg);
src/Value.zig-1
......@@ -4014,7 +4014,6 @@ pub fn pointerDerivation(ptr_val: Value, arena: Allocator, zcu: *Zcu) Allocator.
40144014 return ptr_val.pointerDerivationAdvanced(arena, zcu, null) catch |err| switch (err) {
40154015 error.OutOfMemory => |e| return e,
40164016 error.AnalysisFail,
4017 error.NeededSourceLocation,
40184017 error.GenericPoison,
40194018 error.ComptimeReturn,
40204019 error.ComptimeBreak,
src/arch/wasm/CodeGen.zig+2-3
......@@ -16,7 +16,6 @@ const Decl = Module.Decl;
1616const Type = @import("../../type.zig").Type;
1717const Value = @import("../../Value.zig");
1818const Compilation = @import("../../Compilation.zig");
19const LazySrcLoc = Module.LazySrcLoc;
2019const link = @import("../../link.zig");
2120const Air = @import("../../Air.zig");
2221const Liveness = @import("../../Liveness.zig");
......@@ -766,7 +765,7 @@ pub fn deinit(func: *CodeGen) void {
766765/// Sets `err_msg` on `CodeGen` and returns `error.CodegenFail` which is caught in link/Wasm.zig
767766fn fail(func: *CodeGen, comptime fmt: []const u8, args: anytype) InnerError {
768767 const mod = func.bin_file.base.comp.module.?;
769 const src_loc = func.decl.srcLoc(mod);
768 const src_loc = func.decl.navSrcLoc(mod).upgrade(mod);
770769 func.err_msg = try Module.ErrorMsg.create(func.gpa, src_loc, fmt, args);
771770 return error.CodegenFail;
772771}
......@@ -3123,7 +3122,7 @@ fn lowerAnonDeclRef(
31233122 }
31243123
31253124 const decl_align = mod.intern_pool.indexToKey(anon_decl.orig_ty).ptr_type.flags.alignment;
3126 const res = try func.bin_file.lowerAnonDecl(decl_val, decl_align, func.decl.srcLoc(mod));
3125 const res = try func.bin_file.lowerAnonDecl(decl_val, decl_align, func.decl.navSrcLoc(mod).upgrade(mod));
31273126 switch (res) {
31283127 .ok => {},
31293128 .fail => |em| {
src/arch/wasm/Emit.zig+1-1
......@@ -257,7 +257,7 @@ fn fail(emit: *Emit, comptime format: []const u8, args: anytype) InnerError {
257257 const comp = emit.bin_file.base.comp;
258258 const zcu = comp.module.?;
259259 const gpa = comp.gpa;
260 emit.error_msg = try Module.ErrorMsg.create(gpa, zcu.declPtr(emit.decl_index).srcLoc(zcu), format, args);
260 emit.error_msg = try Module.ErrorMsg.create(gpa, zcu.declPtr(emit.decl_index).navSrcLoc(zcu).upgrade(zcu), format, args);
261261 return error.EmitFail;
262262}
263263
src/codegen/c.zig+1-2
......@@ -13,7 +13,6 @@ const Type = @import("../type.zig").Type;
1313const C = link.File.C;
1414const Decl = Zcu.Decl;
1515const trace = @import("../tracy.zig").trace;
16const LazySrcLoc = Zcu.LazySrcLoc;
1716const Air = @import("../Air.zig");
1817const Liveness = @import("../Liveness.zig");
1918const InternPool = @import("../InternPool.zig");
......@@ -638,7 +637,7 @@ pub const DeclGen = struct {
638637 const zcu = dg.zcu;
639638 const decl_index = dg.pass.decl;
640639 const decl = zcu.declPtr(decl_index);
641 const src_loc = decl.srcLoc(zcu);
640 const src_loc = decl.navSrcLoc(zcu).upgrade(zcu);
642641 dg.error_msg = try Zcu.ErrorMsg.create(dg.gpa, src_loc, format, args);
643642 return error.AnalysisFail;
644643 }
src/codegen/llvm.zig+3-4
......@@ -22,7 +22,6 @@ const Air = @import("../Air.zig");
2222const Liveness = @import("../Liveness.zig");
2323const Value = @import("../Value.zig");
2424const Type = @import("../type.zig").Type;
25const LazySrcLoc = Zcu.LazySrcLoc;
2625const x86_64_abi = @import("../arch/x86_64/abi.zig");
2726const wasm_c_abi = @import("../arch/wasm/abi.zig");
2827const aarch64_c_abi = @import("../arch/aarch64/abi.zig");
......@@ -2066,7 +2065,7 @@ pub const Object = struct {
20662065 try o.builder.metadataString(name),
20672066 file,
20682067 scope,
2069 owner_decl.src_node + 1, // Line
2068 owner_decl.src_line + 1, // Line
20702069 try o.lowerDebugType(int_ty),
20712070 ty.abiSize(mod) * 8,
20722071 (ty.abiAlignment(mod).toByteUnits() orelse 0) * 8,
......@@ -2236,7 +2235,7 @@ pub const Object = struct {
22362235 try o.builder.metadataString(name),
22372236 try o.getDebugFile(mod.namespacePtr(owner_decl.src_namespace).file_scope),
22382237 try o.namespaceToDebugScope(owner_decl.src_namespace),
2239 owner_decl.src_node + 1, // Line
2238 owner_decl.src_line + 1, // Line
22402239 .none, // Underlying type
22412240 0, // Size
22422241 0, // Align
......@@ -4728,7 +4727,7 @@ pub const DeclGen = struct {
47284727 const o = dg.object;
47294728 const gpa = o.gpa;
47304729 const mod = o.module;
4731 const src_loc = dg.decl.srcLoc(mod);
4730 const src_loc = dg.decl.navSrcLoc(mod).upgrade(mod);
47324731 dg.err_msg = try Module.ErrorMsg.create(gpa, src_loc, "TODO (LLVM): " ++ format, args);
47334732 return error.CodegenFail;
47344733 }
src/codegen/spirv.zig+2-3
......@@ -9,7 +9,6 @@ const Module = @import("../Module.zig");
99const Decl = Module.Decl;
1010const Type = @import("../type.zig").Type;
1111const Value = @import("../Value.zig");
12const LazySrcLoc = Module.LazySrcLoc;
1312const Air = @import("../Air.zig");
1413const Liveness = @import("../Liveness.zig");
1514const InternPool = @import("../InternPool.zig");
......@@ -414,7 +413,7 @@ const DeclGen = struct {
414413 pub fn fail(self: *DeclGen, comptime format: []const u8, args: anytype) Error {
415414 @setCold(true);
416415 const mod = self.module;
417 const src_loc = self.module.declPtr(self.decl_index).srcLoc(mod);
416 const src_loc = self.module.declPtr(self.decl_index).navSrcLoc(mod).upgrade(mod);
418417 assert(self.error_msg == null);
419418 self.error_msg = try Module.ErrorMsg.create(self.module.gpa, src_loc, format, args);
420419 return error.CodegenFail;
......@@ -6433,7 +6432,7 @@ const DeclGen = struct {
64336432 // TODO: Translate proper error locations.
64346433 assert(as.errors.items.len != 0);
64356434 assert(self.error_msg == null);
6436 const src_loc = self.module.declPtr(self.decl_index).srcLoc(mod);
6435 const src_loc = self.module.declPtr(self.decl_index).navSrcLoc(mod).upgrade(mod);
64376436 self.error_msg = try Module.ErrorMsg.create(self.module.gpa, src_loc, "failed to assemble SPIR-V inline assembly", .{});
64386437 const notes = try self.module.gpa.alloc(Module.ErrorMsg, as.errors.items.len);
64396438
src/crash_report.zig+13-10
......@@ -10,6 +10,7 @@ const native_os = builtin.os.tag;
1010
1111const Module = @import("Module.zig");
1212const Sema = @import("Sema.zig");
13const InternPool = @import("InternPool.zig");
1314const Zir = std.zig.Zir;
1415const Decl = Module.Decl;
1516
......@@ -76,18 +77,19 @@ fn dumpStatusReport() !void {
7677 const stderr = io.getStdErr().writer();
7778 const block: *Sema.Block = anal.block;
7879 const mod = anal.sema.mod;
79 const block_src_decl = mod.declPtr(block.src_decl);
80
81 const file, const src_base_node = Module.LazySrcLoc.resolveBaseNode(block.src_base_inst, mod);
8082
8183 try stderr.writeAll("Analyzing ");
82 try writeFullyQualifiedDeclWithFile(mod, block_src_decl, stderr);
84 try writeFullyQualifiedDeclWithFile(mod, block.src_decl, stderr);
8385 try stderr.writeAll("\n");
8486
8587 print_zir.renderInstructionContext(
8688 allocator,
8789 anal.body,
8890 anal.body_index,
89 mod.namespacePtr(block.namespace).file_scope,
90 block_src_decl.src_node,
91 file,
92 src_base_node,
9193 6, // indent
9294 stderr,
9395 ) catch |err| switch (err) {
......@@ -95,21 +97,21 @@ fn dumpStatusReport() !void {
9597 else => |e| return e,
9698 };
9799 try stderr.writeAll(" For full context, use the command\n zig ast-check -t ");
98 try writeFilePath(mod.namespacePtr(block.namespace).file_scope, stderr);
100 try writeFilePath(file, stderr);
99101 try stderr.writeAll("\n\n");
100102
101103 var parent = anal.parent;
102104 while (parent) |curr| {
103105 fba.reset();
104106 try stderr.writeAll(" in ");
105 const curr_block_src_decl = mod.declPtr(curr.block.src_decl);
106 try writeFullyQualifiedDeclWithFile(mod, curr_block_src_decl, stderr);
107 const cur_block_file, const cur_block_src_base_node = Module.LazySrcLoc.resolveBaseNode(curr.block.src_base_inst, mod);
108 try writeFullyQualifiedDeclWithFile(mod, curr.block.src_decl, stderr);
107109 try stderr.writeAll("\n > ");
108110 print_zir.renderSingleInstruction(
109111 allocator,
110112 curr.body[curr.body_index],
111 mod.namespacePtr(curr.block.namespace).file_scope,
112 curr_block_src_decl.src_node,
113 cur_block_file,
114 cur_block_src_base_node,
113115 6, // indent
114116 stderr,
115117 ) catch |err| switch (err) {
......@@ -138,7 +140,8 @@ fn writeFilePath(file: *Module.File, writer: anytype) !void {
138140 try writer.writeAll(file.sub_file_path);
139141}
140142
141fn writeFullyQualifiedDeclWithFile(mod: *Module, decl: *Decl, writer: anytype) !void {
143fn writeFullyQualifiedDeclWithFile(mod: *Module, decl_index: InternPool.DeclIndex, writer: anytype) !void {
144 const decl = mod.declPtr(decl_index);
142145 try writeFilePath(decl.getFileScope(mod), writer);
143146 try writer.writeAll(": ");
144147 try decl.renderFullyQualifiedDebugName(mod, writer);
src/link/Coff.zig+6-6
......@@ -1144,7 +1144,7 @@ pub fn updateFunc(self: *Coff, mod: *Module, func_index: InternPool.Index, air:
11441144
11451145 const res = try codegen.generateFunction(
11461146 &self.base,
1147 decl.srcLoc(mod),
1147 decl.navSrcLoc(mod).upgrade(mod),
11481148 func_index,
11491149 air,
11501150 liveness,
......@@ -1181,7 +1181,7 @@ pub fn lowerUnnamedConst(self: *Coff, val: Value, decl_index: InternPool.DeclInd
11811181 const sym_name = try std.fmt.allocPrint(gpa, "__unnamed_{}_{d}", .{ decl_name.fmt(&mod.intern_pool), index });
11821182 defer gpa.free(sym_name);
11831183 const ty = val.typeOf(mod);
1184 const atom_index = switch (try self.lowerConst(sym_name, val, ty.abiAlignment(mod), self.rdata_section_index.?, decl.srcLoc(mod))) {
1184 const atom_index = switch (try self.lowerConst(sym_name, val, ty.abiAlignment(mod), self.rdata_section_index.?, decl.navSrcLoc(mod).upgrade(mod))) {
11851185 .ok => |atom_index| atom_index,
11861186 .fail => |em| {
11871187 decl.analysis = .codegen_failure;
......@@ -1272,7 +1272,7 @@ pub fn updateDecl(
12721272 defer code_buffer.deinit();
12731273
12741274 const decl_val = if (decl.val.getVariable(mod)) |variable| Value.fromInterned(variable.init) else decl.val;
1275 const res = try codegen.generateSymbol(&self.base, decl.srcLoc(mod), decl_val, &code_buffer, .none, .{
1275 const res = try codegen.generateSymbol(&self.base, decl.navSrcLoc(mod).upgrade(mod), decl_val, &code_buffer, .none, .{
12761276 .parent_atom_index = atom.getSymbolIndex().?,
12771277 });
12781278 const code = switch (res) {
......@@ -1313,12 +1313,12 @@ fn updateLazySymbolAtom(
13131313 const atom = self.getAtomPtr(atom_index);
13141314 const local_sym_index = atom.getSymbolIndex().?;
13151315
1316 const src = if (sym.ty.getOwnerDeclOrNull(mod)) |owner_decl|
1317 mod.declPtr(owner_decl).srcLoc(mod)
1316 const src = if (sym.ty.srcLocOrNull(mod)) |src|
1317 src.upgrade(mod)
13181318 else
13191319 Module.SrcLoc{
13201320 .file_scope = undefined,
1321 .parent_decl_node = undefined,
1321 .base_node = undefined,
13221322 .lazy = .unneeded,
13231323 };
13241324 const res = try codegen.generateLazySymbol(
src/link/Elf/ZigObject.zig+8-8
......@@ -1072,7 +1072,7 @@ pub fn updateFunc(
10721072 const res = if (decl_state) |*ds|
10731073 try codegen.generateFunction(
10741074 &elf_file.base,
1075 decl.srcLoc(mod),
1075 decl.navSrcLoc(mod).upgrade(mod),
10761076 func_index,
10771077 air,
10781078 liveness,
......@@ -1082,7 +1082,7 @@ pub fn updateFunc(
10821082 else
10831083 try codegen.generateFunction(
10841084 &elf_file.base,
1085 decl.srcLoc(mod),
1085 decl.navSrcLoc(mod).upgrade(mod),
10861086 func_index,
10871087 air,
10881088 liveness,
......@@ -1156,13 +1156,13 @@ pub fn updateDecl(
11561156 // TODO implement .debug_info for global variables
11571157 const decl_val = if (decl.val.getVariable(mod)) |variable| Value.fromInterned(variable.init) else decl.val;
11581158 const res = if (decl_state) |*ds|
1159 try codegen.generateSymbol(&elf_file.base, decl.srcLoc(mod), decl_val, &code_buffer, .{
1159 try codegen.generateSymbol(&elf_file.base, decl.navSrcLoc(mod).upgrade(mod), decl_val, &code_buffer, .{
11601160 .dwarf = ds,
11611161 }, .{
11621162 .parent_atom_index = sym_index,
11631163 })
11641164 else
1165 try codegen.generateSymbol(&elf_file.base, decl.srcLoc(mod), decl_val, &code_buffer, .none, .{
1165 try codegen.generateSymbol(&elf_file.base, decl.navSrcLoc(mod).upgrade(mod), decl_val, &code_buffer, .none, .{
11661166 .parent_atom_index = sym_index,
11671167 });
11681168
......@@ -1219,12 +1219,12 @@ fn updateLazySymbol(
12191219 break :blk try self.strtab.insert(gpa, name);
12201220 };
12211221
1222 const src = if (sym.ty.getOwnerDeclOrNull(mod)) |owner_decl|
1223 mod.declPtr(owner_decl).srcLoc(mod)
1222 const src = if (sym.ty.srcLocOrNull(mod)) |src|
1223 src.upgrade(mod)
12241224 else
12251225 Module.SrcLoc{
12261226 .file_scope = undefined,
1227 .parent_decl_node = undefined,
1227 .base_node = undefined,
12281228 .lazy = .unneeded,
12291229 };
12301230 const res = try codegen.generateLazySymbol(
......@@ -1304,7 +1304,7 @@ pub fn lowerUnnamedConst(
13041304 val,
13051305 ty.abiAlignment(mod),
13061306 elf_file.zig_data_rel_ro_section_index.?,
1307 decl.srcLoc(mod),
1307 decl.navSrcLoc(mod).upgrade(mod),
13081308 )) {
13091309 .ok => |sym_index| sym_index,
13101310 .fail => |em| {
src/link/MachO/ZigObject.zig+6-6
......@@ -682,7 +682,7 @@ pub fn updateFunc(
682682 const dio: codegen.DebugInfoOutput = if (decl_state) |*ds| .{ .dwarf = ds } else .none;
683683 const res = try codegen.generateFunction(
684684 &macho_file.base,
685 decl.srcLoc(mod),
685 decl.navSrcLoc(mod).upgrade(mod),
686686 func_index,
687687 air,
688688 liveness,
......@@ -756,7 +756,7 @@ pub fn updateDecl(
756756
757757 const decl_val = if (decl.val.getVariable(mod)) |variable| Value.fromInterned(variable.init) else decl.val;
758758 const dio: codegen.DebugInfoOutput = if (decl_state) |*ds| .{ .dwarf = ds } else .none;
759 const res = try codegen.generateSymbol(&macho_file.base, decl.srcLoc(mod), decl_val, &code_buffer, dio, .{
759 const res = try codegen.generateSymbol(&macho_file.base, decl.navSrcLoc(mod).upgrade(mod), decl_val, &code_buffer, dio, .{
760760 .parent_atom_index = sym_index,
761761 });
762762
......@@ -1104,7 +1104,7 @@ pub fn lowerUnnamedConst(
11041104 val,
11051105 val.typeOf(mod).abiAlignment(mod),
11061106 macho_file.zig_const_sect_index.?,
1107 decl.srcLoc(mod),
1107 decl.navSrcLoc(mod).upgrade(mod),
11081108 )) {
11091109 .ok => |sym_index| sym_index,
11101110 .fail => |em| {
......@@ -1294,12 +1294,12 @@ fn updateLazySymbol(
12941294 break :blk try self.strtab.insert(gpa, name);
12951295 };
12961296
1297 const src = if (lazy_sym.ty.getOwnerDeclOrNull(mod)) |owner_decl|
1298 mod.declPtr(owner_decl).srcLoc(mod)
1297 const src = if (lazy_sym.ty.srcLocOrNull(mod)) |src|
1298 src.upgrade(mod)
12991299 else
13001300 Module.SrcLoc{
13011301 .file_scope = undefined,
1302 .parent_decl_node = undefined,
1302 .base_node = undefined,
13031303 .lazy = .unneeded,
13041304 };
13051305 const res = try codegen.generateLazySymbol(
src/link/Plan9.zig+7-7
......@@ -433,7 +433,7 @@ pub fn updateFunc(self: *Plan9, mod: *Module, func_index: InternPool.Index, air:
433433
434434 const res = try codegen.generateFunction(
435435 &self.base,
436 decl.srcLoc(mod),
436 decl.navSrcLoc(mod).upgrade(mod),
437437 func_index,
438438 air,
439439 liveness,
......@@ -499,7 +499,7 @@ pub fn lowerUnnamedConst(self: *Plan9, val: Value, decl_index: InternPool.DeclIn
499499 };
500500 self.syms.items[info.sym_index.?] = sym;
501501
502 const res = try codegen.generateSymbol(&self.base, decl.srcLoc(mod), val, &code_buffer, .{
502 const res = try codegen.generateSymbol(&self.base, decl.navSrcLoc(mod).upgrade(mod), val, &code_buffer, .{
503503 .none = {},
504504 }, .{
505505 .parent_atom_index = new_atom_idx,
......@@ -538,7 +538,7 @@ pub fn updateDecl(self: *Plan9, mod: *Module, decl_index: InternPool.DeclIndex)
538538 defer code_buffer.deinit();
539539 const decl_val = if (decl.val.getVariable(mod)) |variable| Value.fromInterned(variable.init) else decl.val;
540540 // TODO we need the symbol index for symbol in the table of locals for the containing atom
541 const res = try codegen.generateSymbol(&self.base, decl.srcLoc(mod), decl_val, &code_buffer, .{ .none = {} }, .{
541 const res = try codegen.generateSymbol(&self.base, decl.navSrcLoc(mod).upgrade(mod), decl_val, &code_buffer, .{ .none = {} }, .{
542542 .parent_atom_index = @as(Atom.Index, @intCast(atom_idx)),
543543 });
544544 const code = switch (res) {
......@@ -1020,7 +1020,7 @@ fn addDeclExports(
10201020 {
10211021 try mod.failed_exports.put(mod.gpa, exp, try Module.ErrorMsg.create(
10221022 gpa,
1023 mod.declPtr(decl_index).srcLoc(mod),
1023 mod.declPtr(decl_index).navSrcLoc(mod).upgrade(mod),
10241024 "plan9 does not support extra sections",
10251025 .{},
10261026 ));
......@@ -1212,12 +1212,12 @@ fn updateLazySymbolAtom(self: *Plan9, sym: File.LazySymbol, atom_index: Atom.Ind
12121212 self.syms.items[self.getAtomPtr(atom_index).sym_index.?] = symbol;
12131213
12141214 // generate the code
1215 const src = if (sym.ty.getOwnerDeclOrNull(mod)) |owner_decl|
1216 mod.declPtr(owner_decl).srcLoc(mod)
1215 const src = if (sym.ty.srcLocOrNull(mod)) |src|
1216 src.upgrade(mod)
12171217 else
12181218 Module.SrcLoc{
12191219 .file_scope = undefined,
1220 .parent_decl_node = undefined,
1220 .base_node = undefined,
12211221 .lazy = .unneeded,
12221222 };
12231223 const res = try codegen.generateLazySymbol(
src/link/Wasm/ZigObject.zig+5-5
......@@ -269,7 +269,7 @@ pub fn updateDecl(
269269
270270 const res = try codegen.generateSymbol(
271271 &wasm_file.base,
272 decl.srcLoc(mod),
272 decl.navSrcLoc(mod).upgrade(mod),
273273 val,
274274 &code_writer,
275275 .none,
......@@ -308,7 +308,7 @@ pub fn updateFunc(
308308 defer code_writer.deinit();
309309 const result = try codegen.generateFunction(
310310 &wasm_file.base,
311 decl.srcLoc(mod),
311 decl.navSrcLoc(mod).upgrade(mod),
312312 func_index,
313313 air,
314314 liveness,
......@@ -484,7 +484,7 @@ pub fn lowerUnnamedConst(zig_object: *ZigObject, wasm_file: *Wasm, val: Value, d
484484 });
485485 defer gpa.free(name);
486486
487 switch (try zig_object.lowerConst(wasm_file, name, val, decl.srcLoc(mod))) {
487 switch (try zig_object.lowerConst(wasm_file, name, val, decl.navSrcLoc(mod).upgrade(mod))) {
488488 .ok => |atom_index| {
489489 try wasm_file.getAtomPtr(parent_atom_index).locals.append(gpa, atom_index);
490490 return @intFromEnum(wasm_file.getAtom(atom_index).sym_index);
......@@ -867,7 +867,7 @@ pub fn updateExports(
867867 if (exp.opts.section.toSlice(&mod.intern_pool)) |section| {
868868 try mod.failed_exports.putNoClobber(gpa, exp, try Module.ErrorMsg.create(
869869 gpa,
870 decl.srcLoc(mod),
870 decl.navSrcLoc(mod).upgrade(mod),
871871 "Unimplemented: ExportOptions.section '{s}'",
872872 .{section},
873873 ));
......@@ -900,7 +900,7 @@ pub fn updateExports(
900900 .link_once => {
901901 try mod.failed_exports.putNoClobber(gpa, exp, try Module.ErrorMsg.create(
902902 gpa,
903 decl.srcLoc(mod),
903 decl.navSrcLoc(mod).upgrade(mod),
904904 "Unimplemented: LinkOnce",
905905 .{},
906906 ));
src/print_value.zig+1-1
......@@ -32,7 +32,7 @@ pub fn format(
3232 return print(ctx.val, writer, ctx.depth, ctx.mod, ctx.opt_sema) catch |err| switch (err) {
3333 error.OutOfMemory => @panic("OOM"), // We're not allowed to return this from a format function
3434 error.ComptimeBreak, error.ComptimeReturn => unreachable,
35 error.AnalysisFail, error.NeededSourceLocation => unreachable, // TODO: re-evaluate when we use `opt_sema` more fully
35 error.AnalysisFail => unreachable, // TODO: re-evaluate when we use `opt_sema` more fully
3636 else => |e| return e,
3737 };
3838}
src/print_zir.zig+52-51
......@@ -48,12 +48,11 @@ pub fn renderAsTextToFile(
4848 const item = scope_file.zir.extraData(Zir.Inst.Imports.Item, extra_index);
4949 extra_index = item.end;
5050
51 const src: LazySrcLoc = .{ .token_abs = item.data.token };
5251 const import_path = scope_file.zir.nullTerminatedString(item.data.name);
5352 try stream.print(" @import(\"{}\") ", .{
5453 std.zig.fmtEscapes(import_path),
5554 });
56 try writer.writeSrc(stream, src);
55 try writer.writeSrcTokAbs(stream, item.data.token);
5756 try stream.writeAll("\n");
5857 }
5958 }
......@@ -188,7 +187,7 @@ const Writer = struct {
188187 } = .{},
189188
190189 fn relativeToNodeIndex(self: *Writer, offset: i32) Ast.Node.Index {
191 return @as(Ast.Node.Index, @bitCast(offset + @as(i32, @bitCast(self.parent_decl_node))));
190 return @bitCast(offset + @as(i32, @bitCast(self.parent_decl_node)));
192191 }
193192
194193 fn writeInstToStream(
......@@ -578,10 +577,9 @@ const Writer = struct {
578577 .work_group_id,
579578 => {
580579 const inst_data = self.code.extraData(Zir.Inst.UnNode, extended.operand).data;
581 const src = LazySrcLoc.nodeOffset(inst_data.node);
582580 try self.writeInstRef(stream, inst_data.operand);
583581 try stream.writeAll(")) ");
584 try self.writeSrc(stream, src);
582 try self.writeSrcNode(stream, inst_data.node);
585583 },
586584
587585 .builtin_extern,
......@@ -592,12 +590,11 @@ const Writer = struct {
592590 .c_va_arg,
593591 => {
594592 const inst_data = self.code.extraData(Zir.Inst.BinNode, extended.operand).data;
595 const src = LazySrcLoc.nodeOffset(inst_data.node);
596593 try self.writeInstRef(stream, inst_data.lhs);
597594 try stream.writeAll(", ");
598595 try self.writeInstRef(stream, inst_data.rhs);
599596 try stream.writeAll(")) ");
600 try self.writeSrc(stream, src);
597 try self.writeSrcNode(stream, inst_data.node);
601598 },
602599
603600 .builtin_async_call => try self.writeBuiltinAsyncCall(stream, extended),
......@@ -612,9 +609,8 @@ const Writer = struct {
612609 }
613610
614611 fn writeExtNode(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void {
615 const src = LazySrcLoc.nodeOffset(@as(i32, @bitCast(extended.operand)));
616612 try stream.writeAll(")) ");
617 try self.writeSrc(stream, src);
613 try self.writeSrcNode(stream, @bitCast(extended.operand));
618614 }
619615
620616 fn writeArrayInitElemType(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
......@@ -654,7 +650,7 @@ const Writer = struct {
654650 const extra = self.code.extraData(Zir.Inst.ValidateDestructure, inst_data.payload_index).data;
655651 try self.writeInstRef(stream, extra.operand);
656652 try stream.print(", {d}) (destructure=", .{extra.expect_len});
657 try self.writeSrc(stream, LazySrcLoc.nodeOffset(extra.destructure_node));
653 try self.writeSrcNode(stream, extra.destructure_node);
658654 try stream.writeAll(") ");
659655 try self.writeSrcNode(stream, inst_data.src_node);
660656 }
......@@ -729,7 +725,7 @@ const Writer = struct {
729725 try stream.writeAll(")");
730726 }
731727 try stream.writeAll(") ");
732 try self.writeSrc(stream, LazySrcLoc.nodeOffset(extra.data.src_node));
728 try self.writeSrcNode(stream, extra.data.src_node);
733729 }
734730
735731 fn writeInt(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
......@@ -868,7 +864,7 @@ const Writer = struct {
868864 try stream.writeAll(", ");
869865 try self.writeInstRef(stream, extra.b);
870866 try stream.writeAll(") ");
871 try self.writeSrc(stream, LazySrcLoc.nodeOffset(extra.node));
867 try self.writeSrcNode(stream, extra.node);
872868 }
873869
874870 fn writeMulAdd(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
......@@ -926,7 +922,7 @@ const Writer = struct {
926922 try stream.writeAll(", ");
927923 try self.writeInstRef(stream, extra.args);
928924 try stream.writeAll(") ");
929 try self.writeSrc(stream, LazySrcLoc.nodeOffset(extra.node));
925 try self.writeSrcNode(stream, extra.node);
930926 }
931927
932928 fn writeParam(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
......@@ -1056,7 +1052,6 @@ const Writer = struct {
10561052
10571053 fn writeCmpxchg(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void {
10581054 const extra = self.code.extraData(Zir.Inst.Cmpxchg, extended.operand).data;
1059 const src = LazySrcLoc.nodeOffset(extra.node);
10601055
10611056 try self.writeInstRef(stream, extra.ptr);
10621057 try stream.writeAll(", ");
......@@ -1068,14 +1063,13 @@ const Writer = struct {
10681063 try stream.writeAll(", ");
10691064 try self.writeInstRef(stream, extra.failure_order);
10701065 try stream.writeAll(") ");
1071 try self.writeSrc(stream, src);
1066 try self.writeSrcNode(stream, extra.node);
10721067 }
10731068
10741069 fn writePtrCastFull(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void {
10751070 const FlagsInt = @typeInfo(Zir.Inst.FullPtrCastFlags).Struct.backing_integer.?;
10761071 const flags: Zir.Inst.FullPtrCastFlags = @bitCast(@as(FlagsInt, @truncate(extended.small)));
10771072 const extra = self.code.extraData(Zir.Inst.BinNode, extended.operand).data;
1078 const src = LazySrcLoc.nodeOffset(extra.node);
10791073 if (flags.ptr_cast) try stream.writeAll("ptr_cast, ");
10801074 if (flags.align_cast) try stream.writeAll("align_cast, ");
10811075 if (flags.addrspace_cast) try stream.writeAll("addrspace_cast, ");
......@@ -1085,19 +1079,18 @@ const Writer = struct {
10851079 try stream.writeAll(", ");
10861080 try self.writeInstRef(stream, extra.rhs);
10871081 try stream.writeAll(")) ");
1088 try self.writeSrc(stream, src);
1082 try self.writeSrcNode(stream, extra.node);
10891083 }
10901084
10911085 fn writePtrCastNoDest(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void {
10921086 const FlagsInt = @typeInfo(Zir.Inst.FullPtrCastFlags).Struct.backing_integer.?;
10931087 const flags: Zir.Inst.FullPtrCastFlags = @bitCast(@as(FlagsInt, @truncate(extended.small)));
10941088 const extra = self.code.extraData(Zir.Inst.UnNode, extended.operand).data;
1095 const src = LazySrcLoc.nodeOffset(extra.node);
10961089 if (flags.const_cast) try stream.writeAll("const_cast, ");
10971090 if (flags.volatile_cast) try stream.writeAll("volatile_cast, ");
10981091 try self.writeInstRef(stream, extra.operand);
10991092 try stream.writeAll(")) ");
1100 try self.writeSrc(stream, src);
1093 try self.writeSrcNode(stream, extra.node);
11011094 }
11021095
11031096 fn writeAtomicLoad(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
......@@ -1183,7 +1176,6 @@ const Writer = struct {
11831176
11841177 fn writeNodeMultiOp(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void {
11851178 const extra = self.code.extraData(Zir.Inst.NodeMultiOp, extended.operand);
1186 const src = LazySrcLoc.nodeOffset(extra.data.src_node);
11871179 const operands = self.code.refSlice(extra.end, extended.small);
11881180
11891181 for (operands, 0..) |operand, i| {
......@@ -1191,7 +1183,7 @@ const Writer = struct {
11911183 try self.writeInstRef(stream, operand);
11921184 }
11931185 try stream.writeAll(")) ");
1194 try self.writeSrc(stream, src);
1186 try self.writeSrcNode(stream, extra.data.src_node);
11951187 }
11961188
11971189 fn writeInstNode(
......@@ -1212,7 +1204,6 @@ const Writer = struct {
12121204 tmpl_is_expr: bool,
12131205 ) !void {
12141206 const extra = self.code.extraData(Zir.Inst.Asm, extended.operand);
1215 const src = LazySrcLoc.nodeOffset(extra.data.src_node);
12161207 const outputs_len = @as(u5, @truncate(extended.small));
12171208 const inputs_len = @as(u5, @truncate(extended.small >> 5));
12181209 const clobbers_len = @as(u5, @truncate(extended.small >> 10));
......@@ -1283,18 +1274,17 @@ const Writer = struct {
12831274 }
12841275 }
12851276 try stream.writeAll(")) ");
1286 try self.writeSrc(stream, src);
1277 try self.writeSrcNode(stream, extra.data.src_node);
12871278 }
12881279
12891280 fn writeOverflowArithmetic(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void {
12901281 const extra = self.code.extraData(Zir.Inst.BinNode, extended.operand).data;
1291 const src = LazySrcLoc.nodeOffset(extra.node);
12921282
12931283 try self.writeInstRef(stream, extra.lhs);
12941284 try stream.writeAll(", ");
12951285 try self.writeInstRef(stream, extra.rhs);
12961286 try stream.writeAll(")) ");
1297 try self.writeSrc(stream, src);
1287 try self.writeSrcNode(stream, extra.node);
12981288 }
12991289
13001290 fn writeCall(
......@@ -2287,9 +2277,8 @@ const Writer = struct {
22872277 inst: Zir.Inst.Index,
22882278 ) (@TypeOf(stream).Error || error{OutOfMemory})!void {
22892279 const src_node = self.code.instructions.items(.data)[@intFromEnum(inst)].node;
2290 const src = LazySrcLoc.nodeOffset(src_node);
22912280 try stream.writeAll(") ");
2292 try self.writeSrc(stream, src);
2281 try self.writeSrcNode(stream, src_node);
22932282 }
22942283
22952284 fn writeStrTok(
......@@ -2507,7 +2496,6 @@ const Writer = struct {
25072496 fn writeAllocExtended(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void {
25082497 const extra = self.code.extraData(Zir.Inst.AllocExtended, extended.operand);
25092498 const small = @as(Zir.Inst.AllocExtended.Small, @bitCast(extended.small));
2510 const src = LazySrcLoc.nodeOffset(extra.data.src_node);
25112499
25122500 var extra_index: usize = extra.end;
25132501 const type_inst: Zir.Inst.Ref = if (!small.has_type) .none else blk: {
......@@ -2525,7 +2513,7 @@ const Writer = struct {
25252513 try self.writeOptionalInstRef(stream, ",ty=", type_inst);
25262514 try self.writeOptionalInstRef(stream, ",align=", align_inst);
25272515 try stream.writeAll(")) ");
2528 try self.writeSrc(stream, src);
2516 try self.writeSrcNode(stream, extra.data.src_node);
25292517 }
25302518
25312519 fn writeTypeofPeer(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void {
......@@ -2780,9 +2768,8 @@ const Writer = struct {
27802768 }
27812769
27822770 fn writeClosureGet(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void {
2783 const src = LazySrcLoc.nodeOffset(@bitCast(extended.operand));
27842771 try stream.print("{d})) ", .{extended.small});
2785 try self.writeSrc(stream, src);
2772 try self.writeSrcNode(stream, @bitCast(extended.operand));
27862773 }
27872774
27882775 fn writeInstRef(self: *Writer, stream: anytype, ref: Zir.Inst.Ref) !void {
......@@ -2858,30 +2845,44 @@ const Writer = struct {
28582845 try stream.writeAll(name);
28592846 }
28602847
2861 fn writeSrc(self: *Writer, stream: anytype, src: LazySrcLoc) !void {
2862 if (self.file.tree_loaded) {
2863 const tree = self.file.tree;
2864 const src_loc: Module.SrcLoc = .{
2865 .file_scope = self.file,
2866 .parent_decl_node = self.parent_decl_node,
2867 .lazy = src,
2868 };
2869 const src_span = src_loc.span(self.gpa) catch unreachable;
2870 const start = self.line_col_cursor.find(tree.source, src_span.start);
2871 const end = self.line_col_cursor.find(tree.source, src_span.end);
2872 try stream.print("{s}:{d}:{d} to :{d}:{d}", .{
2873 @tagName(src), start.line + 1, start.column + 1,
2874 end.line + 1, end.column + 1,
2875 });
2876 }
2877 }
2878
28792848 fn writeSrcNode(self: *Writer, stream: anytype, src_node: i32) !void {
2880 return self.writeSrc(stream, LazySrcLoc.nodeOffset(src_node));
2849 if (!self.file.tree_loaded) return;
2850 const tree = self.file.tree;
2851 const abs_node = self.relativeToNodeIndex(src_node);
2852 const src_span = tree.nodeToSpan(abs_node);
2853 const start = self.line_col_cursor.find(tree.source, src_span.start);
2854 const end = self.line_col_cursor.find(tree.source, src_span.end);
2855 try stream.print("node_offset:{d}:{d} to :{d}:{d}", .{
2856 start.line + 1, start.column + 1,
2857 end.line + 1, end.column + 1,
2858 });
28812859 }
28822860
28832861 fn writeSrcTok(self: *Writer, stream: anytype, src_tok: u32) !void {
2884 return self.writeSrc(stream, .{ .token_offset = src_tok });
2862 if (!self.file.tree_loaded) return;
2863 const tree = self.file.tree;
2864 const abs_tok = tree.firstToken(self.parent_decl_node) + src_tok;
2865 const span_start = tree.tokens.items(.start)[abs_tok];
2866 const span_end = span_start + @as(u32, @intCast(tree.tokenSlice(abs_tok).len));
2867 const start = self.line_col_cursor.find(tree.source, span_start);
2868 const end = self.line_col_cursor.find(tree.source, span_end);
2869 try stream.print("token_offset:{d}:{d} to :{d}:{d}", .{
2870 start.line + 1, start.column + 1,
2871 end.line + 1, end.column + 1,
2872 });
2873 }
2874
2875 fn writeSrcTokAbs(self: *Writer, stream: anytype, src_tok: u32) !void {
2876 if (!self.file.tree_loaded) return;
2877 const tree = self.file.tree;
2878 const span_start = tree.tokens.items(.start)[src_tok];
2879 const span_end = span_start + @as(u32, @intCast(tree.tokenSlice(src_tok).len));
2880 const start = self.line_col_cursor.find(tree.source, span_start);
2881 const end = self.line_col_cursor.find(tree.source, span_end);
2882 try stream.print("token_abs:{d}:{d} to :{d}:{d}", .{
2883 start.line + 1, start.column + 1,
2884 end.line + 1, end.column + 1,
2885 });
28852886 }
28862887
28872888 fn writeBracedDecl(self: *Writer, stream: anytype, body: []const Zir.Inst.Index) !void {
src/type.zig+31-9
......@@ -3317,15 +3317,6 @@ pub const Type = struct {
33173317 }
33183318 }
33193319
3320 pub fn declSrcLoc(ty: Type, mod: *Module) Module.SrcLoc {
3321 return declSrcLocOrNull(ty, mod).?;
3322 }
3323
3324 pub fn declSrcLocOrNull(ty: Type, mod: *Module) ?Module.SrcLoc {
3325 const decl = ty.getOwnerDeclOrNull(mod) orelse return null;
3326 return mod.declPtr(decl).srcLoc(mod);
3327 }
3328
33293320 pub fn getOwnerDecl(ty: Type, mod: *Module) InternPool.DeclIndex {
33303321 return ty.getOwnerDeclOrNull(mod) orelse unreachable;
33313322 }
......@@ -3341,6 +3332,37 @@ pub const Type = struct {
33413332 };
33423333 }
33433334
3335 pub fn srcLocOrNull(ty: Type, zcu: *Zcu) ?Module.LazySrcLoc {
3336 const ip = &zcu.intern_pool;
3337 return .{
3338 .base_node_inst = switch (ip.indexToKey(ty.toIntern())) {
3339 .struct_type => |info| switch (info) {
3340 .declared => ip.loadStructType(ty.toIntern()).zir_index.unwrap() orelse return null,
3341 else => return null,
3342 },
3343 .union_type => |info| switch (info) {
3344 .declared => ip.loadUnionType(ty.toIntern()).zir_index,
3345 else => return null,
3346 },
3347 .opaque_type => |info| switch (info) {
3348 .declared => ip.loadOpaqueType(ty.toIntern()).zir_index,
3349 else => return null,
3350 },
3351 .enum_type => |info| switch (info) {
3352 .declared => ip.loadEnumType(ty.toIntern()).zir_index.unwrap().?,
3353 .generated_tag => |gt| ip.loadUnionType(gt.union_type).zir_index, // must be declared since we can't generate tags when reifying
3354 else => return null,
3355 },
3356 else => return null,
3357 },
3358 .offset = Module.LazySrcLoc.Offset.nodeOffset(0),
3359 };
3360 }
3361
3362 pub fn srcLoc(ty: Type, zcu: *Zcu) Module.LazySrcLoc {
3363 return ty.srcLocOrNull(zcu).?;
3364 }
3365
33443366 pub fn isGenericPoison(ty: Type) bool {
33453367 return ty.toIntern() == .generic_poison_type;
33463368 }
test/cases/compile_errors/comptime_arg_to_generic_fn_callee_error.zig-1
......@@ -18,4 +18,3 @@ pub export fn entry() void {
1818// target=native
1919//
2020// :7:28: error: no field named 'c' in enum 'meta.FieldEnum(tmp.MyStruct)'
21// :?:?: note: enum declared here
test/cases/compile_errors/enum_value_already_taken.zig+1-1
......@@ -15,4 +15,4 @@ export fn entry() void {
1515// target=native
1616//
1717// :6:9: error: enum tag value 60 already taken
18// :4:5: note: other occurrence here
18// :4:9: note: other occurrence here
test/cases/compile_errors/export_function_with_comptime_parameter.zig+1-1
......@@ -6,4 +6,4 @@ export fn foo(comptime x: anytype, y: i32) i32 {
66// backend=stage2
77// target=native
88//
9// :1:27: error: comptime parameters not allowed in function with calling convention 'C'
9// :1:15: error: comptime parameters not allowed in function with calling convention 'C'
test/cases/compile_errors/export_generic_function.zig+1-1
......@@ -7,4 +7,4 @@ export fn foo(num: anytype) i32 {
77// backend=stage2
88// target=native
99//
10// :1:20: error: generic parameters not allowed in function with calling convention 'C'
10// :1:15: error: generic parameters not allowed in function with calling convention 'C'
test/cases/compile_errors/extern_function_with_comptime_parameter.zig+1-1
......@@ -19,5 +19,5 @@ comptime {
1919// target=native
2020//
2121// :5:30: error: comptime parameters not allowed in function with calling convention 'C'
22// :6:41: error: generic parameters not allowed in function with calling convention 'C'
22// :6:30: error: generic parameters not allowed in function with calling convention 'C'
2323// :1:15: error: comptime parameters not allowed in function with calling convention 'C'
test/cases/compile_errors/missing_field_in_struct_value_expression.zig+2-2
......@@ -27,9 +27,9 @@ export fn h() void {
2727// target=native
2828//
2929// :9:16: error: missing struct field: x
30// :1:11: note: struct 'tmp.A' declared here
30// :1:11: note: struct declared here
3131// :18:16: error: missing tuple field with index 1
3232// :16:11: note: struct declared here
3333// :22:16: error: missing tuple field with index 0
3434// :22:16: note: missing tuple field with index 1
35// :16:11: note: struct 'tmp.B' declared here
35// :16:11: note: struct declared here
test/cases/compile_errors/missing_struct_field_in_fn_called_at_comptime.zig+1-1
......@@ -14,5 +14,5 @@ comptime {
1414// target=native
1515//
1616// :5:17: error: missing struct field: b
17// :1:11: note: struct 'tmp.S' declared here
17// :1:11: note: struct declared here
1818// :9:15: note: called from here
test/cases/compile_errors/reify_type_for_tagged_union_with_extra_enum_field.zig-2
......@@ -31,5 +31,3 @@ export fn entry() void {
3131// target=native
3232//
3333// :13:16: error: enum fields missing in union
34// :1:13: note: field 'arst' missing, declared here
35// :1:13: note: enum declared here
test/cases/compile_errors/reify_type_for_tagged_union_with_extra_union_field.zig-1
......@@ -31,4 +31,3 @@ export fn entry() void {
3131// target=native
3232//
3333// :12:16: error: no field named 'arst' in enum 'tmp.Tag'
34// :1:13: note: enum declared here
test/cases/compile_errors/reify_type_for_tagged_union_with_no_enum_fields.zig-1
......@@ -27,4 +27,3 @@ export fn entry() void {
2727// target=native
2828//
2929// :9:16: error: no field named 'signed' in enum 'tmp.Tag'
30// :1:13: note: enum declared here
test/cases/compile_errors/reify_type_for_tagged_union_with_no_union_fields.zig-3
......@@ -27,6 +27,3 @@ export fn entry() void {
2727// target=native
2828//
2929// :12:16: error: enum fields missing in union
30// :1:13: note: field 'signed' missing, declared here
31// :1:13: note: field 'unsigned' missing, declared here
32// :1:13: note: enum declared here
test/cases/compile_errors/switch_ranges_endpoints_are_validated.zig+2-2
......@@ -17,5 +17,5 @@ pub export fn entr2() void {
1717// backend=stage2
1818// target=native
1919//
20// :4:9: error: range start value is greater than the end value
21// :11:9: error: range start value is greater than the end value
20// :4:10: error: range start value is greater than the end value
21// :11:11: error: range start value is greater than the end value
test/cases/compile_errors/union_auto-enum_value_already_taken.zig+2-2
......@@ -14,5 +14,5 @@ export fn entry() void {
1414// backend=stage2
1515// target=native
1616//
17// :6:5: error: enum tag value 60 already taken
18// :4:5: note: other occurrence here
17// :6:9: error: enum tag value 60 already taken
18// :4:9: note: other occurrence here