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 {...@@ -2639,7 +2639,7 @@ fn reportMultiModuleErrors(mod: *Module) !void {
2639 .root => |pkg| blk: {2639 .root => |pkg| blk: {
2640 break :blk try Module.ErrorMsg.init(2640 break :blk try Module.ErrorMsg.init(
2641 mod.gpa,2641 mod.gpa,
2642 .{ .file_scope = file, .parent_decl_node = 0, .lazy = .entire_file },2642 .{ .file_scope = file, .base_node = 0, .lazy = .entire_file },
2643 "root of module {s}",2643 "root of module {s}",
2644 .{pkg.fully_qualified_name},2644 .{pkg.fully_qualified_name},
2645 );2645 );
...@@ -2651,7 +2651,7 @@ fn reportMultiModuleErrors(mod: *Module) !void {...@@ -2651,7 +2651,7 @@ fn reportMultiModuleErrors(mod: *Module) !void {
2651 if (omitted > 0) {2651 if (omitted > 0) {
2652 notes[num_notes] = try Module.ErrorMsg.init(2652 notes[num_notes] = try Module.ErrorMsg.init(
2653 mod.gpa,2653 mod.gpa,
2654 .{ .file_scope = file, .parent_decl_node = 0, .lazy = .entire_file },2654 .{ .file_scope = file, .base_node = 0, .lazy = .entire_file },
2655 "{} more references omitted",2655 "{} more references omitted",
2656 .{omitted},2656 .{omitted},
2657 );2657 );
...@@ -2660,7 +2660,7 @@ fn reportMultiModuleErrors(mod: *Module) !void {...@@ -2660,7 +2660,7 @@ fn reportMultiModuleErrors(mod: *Module) !void {
26602660
2661 const err = try Module.ErrorMsg.create(2661 const err = try Module.ErrorMsg.create(
2662 mod.gpa,2662 mod.gpa,
2663 .{ .file_scope = file, .parent_decl_node = 0, .lazy = .entire_file },2663 .{ .file_scope = file, .base_node = 0, .lazy = .entire_file },
2664 "file exists in multiple modules",2664 "file exists in multiple modules",
2665 .{},2665 .{},
2666 );2666 );
...@@ -3040,29 +3040,26 @@ pub fn getAllErrorsAlloc(comp: *Compilation) !ErrorBundle {...@@ -3040,29 +3040,26 @@ pub fn getAllErrorsAlloc(comp: *Compilation) !ErrorBundle {
3040 }3040 }
3041 }3041 }
30423042
3043 if (comp.module) |module| {3043 if (comp.module) |zcu| {
3044 if (bundle.root_list.items.len == 0 and module.compile_log_decls.count() != 0) {3044 if (bundle.root_list.items.len == 0 and zcu.compile_log_decls.count() != 0) {
3045 const keys = module.compile_log_decls.keys();3045 const values = zcu.compile_log_decls.values();
3046 const values = module.compile_log_decls.values();
3047 // First one will be the error; subsequent ones will be notes.3046 // First one will be the error; subsequent ones will be notes.
3048 const err_decl = module.declPtr(keys[0]);3047 const src_loc = values[0].src().upgrade(zcu);
3049 const src_loc = err_decl.nodeOffsetSrcLoc(values[0], module);3048 const err_msg: Module.ErrorMsg = .{
3050 const err_msg = Module.ErrorMsg{
3051 .src_loc = src_loc,3049 .src_loc = src_loc,
3052 .msg = "found compile log statement",3050 .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),
3054 };3052 };
3055 defer gpa.free(err_msg.notes);3053 defer gpa.free(err_msg.notes);
30563054
3057 for (keys[1..], 0..) |key, i| {3055 for (values[1..], err_msg.notes) |src_info, *note| {
3058 const note_decl = module.declPtr(key);3056 note.* = .{
3059 err_msg.notes[i] = .{3057 .src_loc = src_info.src().upgrade(zcu),
3060 .src_loc = note_decl.nodeOffsetSrcLoc(values[i + 1], module),
3061 .msg = "also here",3058 .msg = "also here",
3062 };3059 };
3063 }3060 }
30643061
3065 try addModuleErrorMsg(module, &bundle, err_msg);3062 try addModuleErrorMsg(zcu, &bundle, err_msg);
3066 }3063 }
3067 }3064 }
30683065
...@@ -3492,7 +3489,7 @@ fn processOneJob(comp: *Compilation, job: Job, prog_node: std.Progress.Node) !vo...@@ -3492,7 +3489,7 @@ fn processOneJob(comp: *Compilation, job: Job, prog_node: std.Progress.Node) !vo
3492 try module.failed_decls.ensureUnusedCapacity(gpa, 1);3489 try module.failed_decls.ensureUnusedCapacity(gpa, 1);
3493 module.failed_decls.putAssumeCapacityNoClobber(decl_index, try Module.ErrorMsg.create(3490 module.failed_decls.putAssumeCapacityNoClobber(decl_index, try Module.ErrorMsg.create(
3494 gpa,3491 gpa,
3495 decl.srcLoc(module),3492 decl.navSrcLoc(module).upgrade(module),
3496 "unable to update line number: {s}",3493 "unable to update line number: {s}",
3497 .{@errorName(err)},3494 .{@errorName(err)},
3498 ));3495 ));
...@@ -3993,7 +3990,7 @@ fn workerAstGenFile(...@@ -3993,7 +3990,7 @@ fn workerAstGenFile(
3993 if (!res.is_pkg) {3990 if (!res.is_pkg) {
3994 res.file.addReference(mod.*, .{ .import = .{3991 res.file.addReference(mod.*, .{ .import = .{
3995 .file_scope = file,3992 .file_scope = file,
3996 .parent_decl_node = 0,3993 .base_node = 0,
3997 .lazy = .{ .token_abs = item.data.token },3994 .lazy = .{ .token_abs = item.data.token },
3998 } }) catch continue;3995 } }) catch continue;
3999 }3996 }
...@@ -4370,7 +4367,7 @@ fn reportRetryableAstGenError(...@@ -4370,7 +4367,7 @@ fn reportRetryableAstGenError(
4370 const src_loc: Module.SrcLoc = switch (src) {4367 const src_loc: Module.SrcLoc = switch (src) {
4371 .root => .{4368 .root => .{
4372 .file_scope = file,4369 .file_scope = file,
4373 .parent_decl_node = 0,4370 .base_node = 0,
4374 .lazy = .entire_file,4371 .lazy = .entire_file,
4375 },4372 },
4376 .import => |info| blk: {4373 .import => |info| blk: {
...@@ -4378,7 +4375,7 @@ fn reportRetryableAstGenError(...@@ -4378,7 +4375,7 @@ fn reportRetryableAstGenError(
43784375
4379 break :blk .{4376 break :blk .{
4380 .file_scope = importing_file,4377 .file_scope = importing_file,
4381 .parent_decl_node = 0,4378 .base_node = 0,
4382 .lazy = .{ .token_abs = info.import_tok },4379 .lazy = .{ .token_abs = info.import_tok },
4383 };4380 };
4384 },4381 },
src/InternPool.zig+4-2
...@@ -101,8 +101,11 @@ pub const TrackedInst = extern struct {...@@ -101,8 +101,11 @@ pub const TrackedInst = extern struct {
101 }101 }
102 pub const Index = enum(u32) {102 pub const Index = enum(u32) {
103 _,103 _,
104 pub fn resolveFull(i: TrackedInst.Index, ip: *const InternPool) TrackedInst {
105 return ip.tracked_insts.keys()[@intFromEnum(i)];
106 }
104 pub fn resolve(i: TrackedInst.Index, ip: *const InternPool) Zir.Inst.Index {107 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;
106 }109 }
107 pub fn toOptional(i: TrackedInst.Index) Optional {110 pub fn toOptional(i: TrackedInst.Index) Optional {
108 return @enumFromInt(@intFromEnum(i));111 return @enumFromInt(@intFromEnum(i));
...@@ -6954,7 +6957,6 @@ fn finishFuncInstance(...@@ -6954,7 +6957,6 @@ fn finishFuncInstance(
6954 const decl_index = try ip.createDecl(gpa, .{6957 const decl_index = try ip.createDecl(gpa, .{
6955 .name = undefined,6958 .name = undefined,
6956 .src_namespace = fn_owner_decl.src_namespace,6959 .src_namespace = fn_owner_decl.src_namespace,
6957 .src_node = fn_owner_decl.src_node,
6958 .src_line = fn_owner_decl.src_line,6960 .src_line = fn_owner_decl.src_line,
6959 .has_tv = true,6961 .has_tv = true,
6960 .owns_tv = true,6962 .owns_tv = true,
src/Module.zig+772-1033
...@@ -107,8 +107,17 @@ intern_pool: InternPool = .{},...@@ -107,8 +107,17 @@ intern_pool: InternPool = .{},
107/// a Decl can have a failed_decls entry but have analysis status of success.107/// a Decl can have a failed_decls entry but have analysis status of success.
108failed_decls: std.AutoArrayHashMapUnmanaged(Decl.Index, *ErrorMsg) = .{},108failed_decls: std.AutoArrayHashMapUnmanaged(Decl.Index, *ErrorMsg) = .{},
109/// Keep track of one `@compileLog` callsite per owner Decl.109/// Keep track of one `@compileLog` callsite per owner Decl.
110/// The value is the AST node index offset from the Decl.110/// The value is the source location of the `@compileLog` call, convertible to a `LazySrcLoc`.
111compile_log_decls: std.AutoArrayHashMapUnmanaged(Decl.Index, i32) = .{},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}) = .{},
112/// Using a map here for consistency with the other fields here.121/// Using a map here for consistency with the other fields here.
113/// The ErrorMsg memory is owned by the `File`, using Module's general purpose allocator.122/// The ErrorMsg memory is owned by the `File`, using Module's general purpose allocator.
114failed_files: std.AutoArrayHashMapUnmanaged(*File, ?*ErrorMsg) = .{},123failed_files: std.AutoArrayHashMapUnmanaged(*File, ?*ErrorMsg) = .{},
...@@ -257,9 +266,6 @@ pub const Export = struct {...@@ -257,9 +266,6 @@ pub const Export = struct {
257 src: LazySrcLoc,266 src: LazySrcLoc,
258 /// The Decl that performs the export. Note that this is *not* the Decl being exported.267 /// The Decl that performs the export. Note that this is *not* the Decl being exported.
259 owner_decl: Decl.Index,268 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,
263 exported: Exported,269 exported: Exported,
264 status: enum {270 status: enum {
265 in_progress,271 in_progress,
...@@ -278,12 +284,7 @@ pub const Export = struct {...@@ -278,12 +284,7 @@ pub const Export = struct {
278 };284 };
279285
280 pub fn getSrcLoc(exp: Export, mod: *Module) SrcLoc {286 pub fn getSrcLoc(exp: Export, mod: *Module) SrcLoc {
281 const src_decl = mod.declPtr(exp.src_decl);287 return exp.src.upgrade(mod);
282 return .{
283 .file_scope = src_decl.getFileScope(mod),
284 .parent_decl_node = src_decl.src_node,
285 .lazy = exp.src,
286 };
287 }288 }
288};289};
289290
...@@ -343,9 +344,6 @@ pub const Decl = struct {...@@ -343,9 +344,6 @@ pub const Decl = struct {
343 /// there is no parent.344 /// there is no parent.
344 src_namespace: Namespace.Index,345 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,
349 /// Line number corresponding to `src_node`. Stored separately so that source files347 /// Line number corresponding to `src_node`. Stored separately so that source files
350 /// do not need to be loaded into memory in order to compute debug line numbers.348 /// do not need to be loaded into memory in order to compute debug line numbers.
351 /// This value is absolute.349 /// This value is absolute.
...@@ -417,26 +415,6 @@ pub const Decl = struct {...@@ -417,26 +415,6 @@ pub const Decl = struct {
417 return extra.data.getBodies(@intCast(extra.end), zir);415 return extra.data.getBodies(@intCast(extra.end), zir);
418 }416 }
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
440 pub fn renderFullyQualifiedName(decl: Decl, zcu: *Zcu, writer: anytype) !void {418 pub fn renderFullyQualifiedName(decl: Decl, zcu: *Zcu, writer: anytype) !void {
441 if (decl.name_fully_qualified) {419 if (decl.name_fully_qualified) {
442 try writer.print("{}", .{decl.name.fmt(&zcu.intern_pool)});420 try writer.print("{}", .{decl.name.fmt(&zcu.intern_pool)});
...@@ -551,101 +529,6 @@ pub const Decl = struct {...@@ -551,101 +529,6 @@ pub const Decl = struct {
551 return decl.typeOf(zcu).abiAlignment(zcu);529 return decl.typeOf(zcu).abiAlignment(zcu);
552 }530 }
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
649 pub fn declPtrType(decl: Decl, zcu: *Zcu) !Type {532 pub fn declPtrType(decl: Decl, zcu: *Zcu) !Type {
650 assert(decl.has_tv);533 assert(decl.has_tv);
651 const decl_ty = decl.typeOf(zcu);534 const decl_ty = decl.typeOf(zcu);
...@@ -661,6 +544,23 @@ pub const Decl = struct {...@@ -661,6 +544,23 @@ pub const Decl = struct {
661 },544 },
662 });545 });
663 }546 }
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 }
664};564};
665565
666/// This state is attached to every Decl when Module emit_h is non-null.566/// This state is attached to every Decl when Module emit_h is non-null.
...@@ -1137,18 +1037,17 @@ pub const ErrorMsg = struct {...@@ -1137,18 +1037,17 @@ pub const ErrorMsg = struct {
1137/// Canonical reference to a position within a source file.1037/// Canonical reference to a position within a source file.
1138pub const SrcLoc = struct {1038pub const SrcLoc = struct {
1139 file_scope: *File,1039 file_scope: *File,
1140 /// Might be 0 depending on tag of `lazy`.1040 base_node: Ast.Node.Index,
1141 parent_decl_node: Ast.Node.Index,1041 /// Relative to `base_node`.
1142 /// Relative to `parent_decl_node`.1042 lazy: LazySrcLoc.Offset,
1143 lazy: LazySrcLoc,
11441043
1145 pub fn declSrcToken(src_loc: SrcLoc) Ast.TokenIndex {1044 pub fn baseSrcToken(src_loc: SrcLoc) Ast.TokenIndex {
1146 const tree = src_loc.file_scope.tree;1045 const tree = src_loc.file_scope.tree;
1147 return tree.firstToken(src_loc.parent_decl_node);1046 return tree.firstToken(src_loc.base_node);
1148 }1047 }
11491048
1150 pub fn declRelativeToNodeIndex(src_loc: SrcLoc, offset: i32) Ast.Node.Index {1049 pub fn relativeToNodeIndex(src_loc: SrcLoc, offset: i32) Ast.Node.Index {
1151 return @bitCast(offset + @as(i32, @bitCast(src_loc.parent_decl_node)));1050 return @bitCast(offset + @as(i32, @bitCast(src_loc.base_node)));
1152 }1051 }
11531052
1154 pub const Span = Ast.Span;1053 pub const Span = Ast.Span;
...@@ -1172,14 +1071,14 @@ pub const SrcLoc = struct {...@@ -1172,14 +1071,14 @@ pub const SrcLoc = struct {
1172 },1071 },
1173 .byte_offset => |byte_off| {1072 .byte_offset => |byte_off| {
1174 const tree = try src_loc.file_scope.getTree(gpa);1073 const tree = try src_loc.file_scope.getTree(gpa);
1175 const tok_index = src_loc.declSrcToken();1074 const tok_index = src_loc.baseSrcToken();
1176 const start = tree.tokens.items(.start)[tok_index] + byte_off;1075 const start = tree.tokens.items(.start)[tok_index] + byte_off;
1177 const end = start + @as(u32, @intCast(tree.tokenSlice(tok_index).len));1076 const end = start + @as(u32, @intCast(tree.tokenSlice(tok_index).len));
1178 return Span{ .start = start, .end = end, .main = start };1077 return Span{ .start = start, .end = end, .main = start };
1179 },1078 },
1180 .token_offset => |tok_off| {1079 .token_offset => |tok_off| {
1181 const tree = try src_loc.file_scope.getTree(gpa);1080 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;
1183 const start = tree.tokens.items(.start)[tok_index];1082 const start = tree.tokens.items(.start)[tok_index];
1184 const end = start + @as(u32, @intCast(tree.tokenSlice(tok_index).len));1083 const end = start + @as(u32, @intCast(tree.tokenSlice(tok_index).len));
1185 return Span{ .start = start, .end = end, .main = start };1084 return Span{ .start = start, .end = end, .main = start };
...@@ -1187,25 +1086,25 @@ pub const SrcLoc = struct {...@@ -1187,25 +1086,25 @@ pub const SrcLoc = struct {
1187 .node_offset => |traced_off| {1086 .node_offset => |traced_off| {
1188 const node_off = traced_off.x;1087 const node_off = traced_off.x;
1189 const tree = try src_loc.file_scope.getTree(gpa);1088 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);
1191 assert(src_loc.file_scope.tree_loaded);1090 assert(src_loc.file_scope.tree_loaded);
1192 return tree.nodeToSpan(node);1091 return tree.nodeToSpan(node);
1193 },1092 },
1194 .node_offset_main_token => |node_off| {1093 .node_offset_main_token => |node_off| {
1195 const tree = try src_loc.file_scope.getTree(gpa);1094 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);
1197 const main_token = tree.nodes.items(.main_token)[node];1096 const main_token = tree.nodes.items(.main_token)[node];
1198 return tree.tokensToSpan(main_token, main_token, main_token);1097 return tree.tokensToSpan(main_token, main_token, main_token);
1199 },1098 },
1200 .node_offset_bin_op => |node_off| {1099 .node_offset_bin_op => |node_off| {
1201 const tree = try src_loc.file_scope.getTree(gpa);1100 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);
1203 assert(src_loc.file_scope.tree_loaded);1102 assert(src_loc.file_scope.tree_loaded);
1204 return tree.nodeToSpan(node);1103 return tree.nodeToSpan(node);
1205 },1104 },
1206 .node_offset_initializer => |node_off| {1105 .node_offset_initializer => |node_off| {
1207 const tree = try src_loc.file_scope.getTree(gpa);1106 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);
1209 return tree.tokensToSpan(1108 return tree.tokensToSpan(
1210 tree.firstToken(node) - 3,1109 tree.firstToken(node) - 3,
1211 tree.lastToken(node),1110 tree.lastToken(node),
...@@ -1214,7 +1113,7 @@ pub const SrcLoc = struct {...@@ -1214,7 +1113,7 @@ pub const SrcLoc = struct {
1214 },1113 },
1215 .node_offset_var_decl_ty => |node_off| {1114 .node_offset_var_decl_ty => |node_off| {
1216 const tree = try src_loc.file_scope.getTree(gpa);1115 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);
1218 const node_tags = tree.nodes.items(.tag);1117 const node_tags = tree.nodes.items(.tag);
1219 const full = switch (node_tags[node]) {1118 const full = switch (node_tags[node]) {
1220 .global_var_decl,1119 .global_var_decl,
...@@ -1238,41 +1137,51 @@ pub const SrcLoc = struct {...@@ -1238,41 +1137,51 @@ pub const SrcLoc = struct {
1238 },1137 },
1239 .node_offset_var_decl_align => |node_off| {1138 .node_offset_var_decl_align => |node_off| {
1240 const tree = try src_loc.file_scope.getTree(gpa);1139 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);
1242 const full = tree.fullVarDecl(node).?;1141 const full = tree.fullVarDecl(node).?;
1243 return tree.nodeToSpan(full.ast.align_node);1142 return tree.nodeToSpan(full.ast.align_node);
1244 },1143 },
1245 .node_offset_var_decl_section => |node_off| {1144 .node_offset_var_decl_section => |node_off| {
1246 const tree = try src_loc.file_scope.getTree(gpa);1145 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);
1248 const full = tree.fullVarDecl(node).?;1147 const full = tree.fullVarDecl(node).?;
1249 return tree.nodeToSpan(full.ast.section_node);1148 return tree.nodeToSpan(full.ast.section_node);
1250 },1149 },
1251 .node_offset_var_decl_addrspace => |node_off| {1150 .node_offset_var_decl_addrspace => |node_off| {
1252 const tree = try src_loc.file_scope.getTree(gpa);1151 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);
1254 const full = tree.fullVarDecl(node).?;1153 const full = tree.fullVarDecl(node).?;
1255 return tree.nodeToSpan(full.ast.addrspace_node);1154 return tree.nodeToSpan(full.ast.addrspace_node);
1256 },1155 },
1257 .node_offset_var_decl_init => |node_off| {1156 .node_offset_var_decl_init => |node_off| {
1258 const tree = try src_loc.file_scope.getTree(gpa);1157 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);
1260 const full = tree.fullVarDecl(node).?;1159 const full = tree.fullVarDecl(node).?;
1261 return tree.nodeToSpan(full.ast.init_node);1160 return tree.nodeToSpan(full.ast.init_node);
1262 },1161 },
1263 .node_offset_builtin_call_arg0 => |n| return src_loc.byteOffsetBuiltinCallArg(gpa, n, 0),1162 .node_offset_builtin_call_arg => |builtin_arg| {
1264 .node_offset_builtin_call_arg1 => |n| return src_loc.byteOffsetBuiltinCallArg(gpa, n, 1),1163 const tree = try src_loc.file_scope.getTree(gpa);
1265 .node_offset_builtin_call_arg2 => |n| return src_loc.byteOffsetBuiltinCallArg(gpa, n, 2),1164 const node_datas = tree.nodes.items(.data);
1266 .node_offset_builtin_call_arg3 => |n| return src_loc.byteOffsetBuiltinCallArg(gpa, n, 3),1165 const node_tags = tree.nodes.items(.tag);
1267 .node_offset_builtin_call_arg4 => |n| return src_loc.byteOffsetBuiltinCallArg(gpa, n, 4),1166 const node = src_loc.relativeToNodeIndex(builtin_arg.builtin_call_node);
1268 .node_offset_builtin_call_arg5 => |n| return src_loc.byteOffsetBuiltinCallArg(gpa, n, 5),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 },
1269 .node_offset_ptrcast_operand => |node_off| {1178 .node_offset_ptrcast_operand => |node_off| {
1270 const tree = try src_loc.file_scope.getTree(gpa);1179 const tree = try src_loc.file_scope.getTree(gpa);
1271 const main_tokens = tree.nodes.items(.main_token);1180 const main_tokens = tree.nodes.items(.main_token);
1272 const node_datas = tree.nodes.items(.data);1181 const node_datas = tree.nodes.items(.data);
1273 const node_tags = tree.nodes.items(.tag);1182 const node_tags = tree.nodes.items(.tag);
12741183
1275 var node = src_loc.declRelativeToNodeIndex(node_off);1184 var node = src_loc.relativeToNodeIndex(node_off);
1276 while (true) {1185 while (true) {
1277 switch (node_tags[node]) {1186 switch (node_tags[node]) {
1278 .builtin_call_two, .builtin_call_two_comma => {},1187 .builtin_call_two, .builtin_call_two_comma => {},
...@@ -1304,7 +1213,7 @@ pub const SrcLoc = struct {...@@ -1304,7 +1213,7 @@ pub const SrcLoc = struct {
1304 .node_offset_array_access_index => |node_off| {1213 .node_offset_array_access_index => |node_off| {
1305 const tree = try src_loc.file_scope.getTree(gpa);1214 const tree = try src_loc.file_scope.getTree(gpa);
1306 const node_datas = tree.nodes.items(.data);1215 const node_datas = tree.nodes.items(.data);
1307 const node = src_loc.declRelativeToNodeIndex(node_off);1216 const node = src_loc.relativeToNodeIndex(node_off);
1308 return tree.nodeToSpan(node_datas[node].rhs);1217 return tree.nodeToSpan(node_datas[node].rhs);
1309 },1218 },
1310 .node_offset_slice_ptr,1219 .node_offset_slice_ptr,
...@@ -1313,7 +1222,7 @@ pub const SrcLoc = struct {...@@ -1313,7 +1222,7 @@ pub const SrcLoc = struct {
1313 .node_offset_slice_sentinel,1222 .node_offset_slice_sentinel,
1314 => |node_off| {1223 => |node_off| {
1315 const tree = try src_loc.file_scope.getTree(gpa);1224 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);
1317 const full = tree.fullSlice(node).?;1226 const full = tree.fullSlice(node).?;
1318 const part_node = switch (src_loc.lazy) {1227 const part_node = switch (src_loc.lazy) {
1319 .node_offset_slice_ptr => full.ast.sliced,1228 .node_offset_slice_ptr => full.ast.sliced,
...@@ -1326,7 +1235,7 @@ pub const SrcLoc = struct {...@@ -1326,7 +1235,7 @@ pub const SrcLoc = struct {
1326 },1235 },
1327 .node_offset_call_func => |node_off| {1236 .node_offset_call_func => |node_off| {
1328 const tree = try src_loc.file_scope.getTree(gpa);1237 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);
1330 var buf: [1]Ast.Node.Index = undefined;1239 var buf: [1]Ast.Node.Index = undefined;
1331 const full = tree.fullCall(&buf, node).?;1240 const full = tree.fullCall(&buf, node).?;
1332 return tree.nodeToSpan(full.ast.fn_expr);1241 return tree.nodeToSpan(full.ast.fn_expr);
...@@ -1335,7 +1244,7 @@ pub const SrcLoc = struct {...@@ -1335,7 +1244,7 @@ pub const SrcLoc = struct {
1335 const tree = try src_loc.file_scope.getTree(gpa);1244 const tree = try src_loc.file_scope.getTree(gpa);
1336 const node_datas = tree.nodes.items(.data);1245 const node_datas = tree.nodes.items(.data);
1337 const node_tags = tree.nodes.items(.tag);1246 const node_tags = tree.nodes.items(.tag);
1338 const node = src_loc.declRelativeToNodeIndex(node_off);1247 const node = src_loc.relativeToNodeIndex(node_off);
1339 var buf: [1]Ast.Node.Index = undefined;1248 var buf: [1]Ast.Node.Index = undefined;
1340 const tok_index = switch (node_tags[node]) {1249 const tok_index = switch (node_tags[node]) {
1341 .field_access => node_datas[node].rhs,1250 .field_access => node_datas[node].rhs,
...@@ -1359,7 +1268,7 @@ pub const SrcLoc = struct {...@@ -1359,7 +1268,7 @@ pub const SrcLoc = struct {
1359 },1268 },
1360 .node_offset_field_name_init => |node_off| {1269 .node_offset_field_name_init => |node_off| {
1361 const tree = try src_loc.file_scope.getTree(gpa);1270 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);
1363 const tok_index = tree.firstToken(node) - 2;1272 const tok_index = tree.firstToken(node) - 2;
1364 const start = tree.tokens.items(.start)[tok_index];1273 const start = tree.tokens.items(.start)[tok_index];
1365 const end = start + @as(u32, @intCast(tree.tokenSlice(tok_index).len));1274 const end = start + @as(u32, @intCast(tree.tokenSlice(tok_index).len));
...@@ -1367,18 +1276,18 @@ pub const SrcLoc = struct {...@@ -1367,18 +1276,18 @@ pub const SrcLoc = struct {
1367 },1276 },
1368 .node_offset_deref_ptr => |node_off| {1277 .node_offset_deref_ptr => |node_off| {
1369 const tree = try src_loc.file_scope.getTree(gpa);1278 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);
1371 return tree.nodeToSpan(node);1280 return tree.nodeToSpan(node);
1372 },1281 },
1373 .node_offset_asm_source => |node_off| {1282 .node_offset_asm_source => |node_off| {
1374 const tree = try src_loc.file_scope.getTree(gpa);1283 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);
1376 const full = tree.fullAsm(node).?;1285 const full = tree.fullAsm(node).?;
1377 return tree.nodeToSpan(full.ast.template);1286 return tree.nodeToSpan(full.ast.template);
1378 },1287 },
1379 .node_offset_asm_ret_ty => |node_off| {1288 .node_offset_asm_ret_ty => |node_off| {
1380 const tree = try src_loc.file_scope.getTree(gpa);1289 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);
1382 const full = tree.fullAsm(node).?;1291 const full = tree.fullAsm(node).?;
1383 const asm_output = full.outputs[0];1292 const asm_output = full.outputs[0];
1384 const node_datas = tree.nodes.items(.data);1293 const node_datas = tree.nodes.items(.data);
...@@ -1387,7 +1296,7 @@ pub const SrcLoc = struct {...@@ -1387,7 +1296,7 @@ pub const SrcLoc = struct {
13871296
1388 .node_offset_if_cond => |node_off| {1297 .node_offset_if_cond => |node_off| {
1389 const tree = try src_loc.file_scope.getTree(gpa);1298 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);
1391 const node_tags = tree.nodes.items(.tag);1300 const node_tags = tree.nodes.items(.tag);
1392 const src_node = switch (node_tags[node]) {1301 const src_node = switch (node_tags[node]) {
1393 .if_simple,1302 .if_simple,
...@@ -1416,7 +1325,7 @@ pub const SrcLoc = struct {...@@ -1416,7 +1325,7 @@ pub const SrcLoc = struct {
1416 },1325 },
1417 .for_input => |for_input| {1326 .for_input => |for_input| {
1418 const tree = try src_loc.file_scope.getTree(gpa);1327 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);
1420 const for_full = tree.fullFor(node).?;1329 const for_full = tree.fullFor(node).?;
1421 const src_node = for_full.ast.inputs[for_input.input_index];1330 const src_node = for_full.ast.inputs[for_input.input_index];
1422 return tree.nodeToSpan(src_node);1331 return tree.nodeToSpan(src_node);
...@@ -1424,7 +1333,7 @@ pub const SrcLoc = struct {...@@ -1424,7 +1333,7 @@ pub const SrcLoc = struct {
1424 .for_capture_from_input => |node_off| {1333 .for_capture_from_input => |node_off| {
1425 const tree = try src_loc.file_scope.getTree(gpa);1334 const tree = try src_loc.file_scope.getTree(gpa);
1426 const token_tags = tree.tokens.items(.tag);1335 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);
1428 // We have to actually linear scan the whole AST to find the for loop1337 // We have to actually linear scan the whole AST to find the for loop
1429 // that contains this input.1338 // that contains this input.
1430 const node_tags = tree.nodes.items(.tag);1339 const node_tags = tree.nodes.items(.tag);
...@@ -1465,7 +1374,7 @@ pub const SrcLoc = struct {...@@ -1465,7 +1374,7 @@ pub const SrcLoc = struct {
1465 },1374 },
1466 .call_arg => |call_arg| {1375 .call_arg => |call_arg| {
1467 const tree = try src_loc.file_scope.getTree(gpa);1376 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);
1469 var buf: [2]Ast.Node.Index = undefined;1378 var buf: [2]Ast.Node.Index = undefined;
1470 const call_full = tree.fullCall(buf[0..1], node) orelse {1379 const call_full = tree.fullCall(buf[0..1], node) orelse {
1471 const node_tags = tree.nodes.items(.tag);1380 const node_tags = tree.nodes.items(.tag);
...@@ -1501,43 +1410,49 @@ pub const SrcLoc = struct {...@@ -1501,43 +1410,49 @@ pub const SrcLoc = struct {
1501 };1410 };
1502 return tree.nodeToSpan(call_full.ast.params[call_arg.arg_index]);1411 return tree.nodeToSpan(call_full.ast.params[call_arg.arg_index]);
1503 },1412 },
1504 .fn_proto_param => |fn_proto_param| {1413 .fn_proto_param, .fn_proto_param_type => |fn_proto_param| {
1505 const tree = try src_loc.file_scope.getTree(gpa);1414 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);
1507 var buf: [1]Ast.Node.Index = undefined;1416 var buf: [1]Ast.Node.Index = undefined;
1508 const full = tree.fullFnProto(&buf, node).?;1417 const full = tree.fullFnProto(&buf, node).?;
1509 var it = full.iterate(tree);1418 var it = full.iterate(tree);
1510 var i: usize = 0;1419 var i: usize = 0;
1511 while (it.next()) |param| : (i += 1) {1420 while (it.next()) |param| : (i += 1) {
1512 if (i == fn_proto_param.param_index) {1421 if (i != fn_proto_param.param_index) continue;
1513 if (param.anytype_ellipsis3) |token| return tree.tokenToSpan(token);1422
1514 const first_token = param.comptime_noalias orelse1423 switch (src_loc.lazy) {
1515 param.name_token orelse1424 .fn_proto_param_type => if (param.anytype_ellipsis3) |tok| {
1516 tree.firstToken(param.type_expr);1425 return tree.tokenToSpan(tok);
1517 return tree.tokensToSpan(1426 } else {
1518 first_token,1427 return tree.nodeToSpan(param.type_expr);
1519 tree.lastToken(param.type_expr),1428 },
1520 first_token,1429 .fn_proto_param => if (param.anytype_ellipsis3) |tok| {
1521 );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,
1522 }1437 }
1523 }1438 }
1524 unreachable;1439 unreachable;
1525 },1440 },
1526 .node_offset_bin_lhs => |node_off| {1441 .node_offset_bin_lhs => |node_off| {
1527 const tree = try src_loc.file_scope.getTree(gpa);1442 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);
1529 const node_datas = tree.nodes.items(.data);1444 const node_datas = tree.nodes.items(.data);
1530 return tree.nodeToSpan(node_datas[node].lhs);1445 return tree.nodeToSpan(node_datas[node].lhs);
1531 },1446 },
1532 .node_offset_bin_rhs => |node_off| {1447 .node_offset_bin_rhs => |node_off| {
1533 const tree = try src_loc.file_scope.getTree(gpa);1448 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);
1535 const node_datas = tree.nodes.items(.data);1450 const node_datas = tree.nodes.items(.data);
1536 return tree.nodeToSpan(node_datas[node].rhs);1451 return tree.nodeToSpan(node_datas[node].rhs);
1537 },1452 },
1538 .array_cat_lhs, .array_cat_rhs => |cat| {1453 .array_cat_lhs, .array_cat_rhs => |cat| {
1539 const tree = try src_loc.file_scope.getTree(gpa);1454 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);
1541 const node_datas = tree.nodes.items(.data);1456 const node_datas = tree.nodes.items(.data);
1542 const arr_node = if (src_loc.lazy == .array_cat_lhs)1457 const arr_node = if (src_loc.lazy == .array_cat_lhs)
1543 node_datas[node].lhs1458 node_datas[node].lhs
...@@ -1565,14 +1480,14 @@ pub const SrcLoc = struct {...@@ -1565,14 +1480,14 @@ pub const SrcLoc = struct {
15651480
1566 .node_offset_switch_operand => |node_off| {1481 .node_offset_switch_operand => |node_off| {
1567 const tree = try src_loc.file_scope.getTree(gpa);1482 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);
1569 const node_datas = tree.nodes.items(.data);1484 const node_datas = tree.nodes.items(.data);
1570 return tree.nodeToSpan(node_datas[node].lhs);1485 return tree.nodeToSpan(node_datas[node].lhs);
1571 },1486 },
15721487
1573 .node_offset_switch_special_prong => |node_off| {1488 .node_offset_switch_special_prong => |node_off| {
1574 const tree = try src_loc.file_scope.getTree(gpa);1489 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);
1576 const node_datas = tree.nodes.items(.data);1491 const node_datas = tree.nodes.items(.data);
1577 const node_tags = tree.nodes.items(.tag);1492 const node_tags = tree.nodes.items(.tag);
1578 const main_tokens = tree.nodes.items(.main_token);1493 const main_tokens = tree.nodes.items(.main_token);
...@@ -1592,7 +1507,7 @@ pub const SrcLoc = struct {...@@ -1592,7 +1507,7 @@ pub const SrcLoc = struct {
15921507
1593 .node_offset_switch_range => |node_off| {1508 .node_offset_switch_range => |node_off| {
1594 const tree = try src_loc.file_scope.getTree(gpa);1509 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);
1596 const node_datas = tree.nodes.items(.data);1511 const node_datas = tree.nodes.items(.data);
1597 const node_tags = tree.nodes.items(.tag);1512 const node_tags = tree.nodes.items(.tag);
1598 const main_tokens = tree.nodes.items(.main_token);1513 const main_tokens = tree.nodes.items(.main_token);
...@@ -1613,56 +1528,30 @@ pub const SrcLoc = struct {...@@ -1613,56 +1528,30 @@ pub const SrcLoc = struct {
1613 }1528 }
1614 } else unreachable;1529 } else unreachable;
1615 },1530 },
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 },
1642 .node_offset_fn_type_align => |node_off| {1531 .node_offset_fn_type_align => |node_off| {
1643 const tree = try src_loc.file_scope.getTree(gpa);1532 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);
1645 var buf: [1]Ast.Node.Index = undefined;1534 var buf: [1]Ast.Node.Index = undefined;
1646 const full = tree.fullFnProto(&buf, node).?;1535 const full = tree.fullFnProto(&buf, node).?;
1647 return tree.nodeToSpan(full.ast.align_expr);1536 return tree.nodeToSpan(full.ast.align_expr);
1648 },1537 },
1649 .node_offset_fn_type_addrspace => |node_off| {1538 .node_offset_fn_type_addrspace => |node_off| {
1650 const tree = try src_loc.file_scope.getTree(gpa);1539 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);
1652 var buf: [1]Ast.Node.Index = undefined;1541 var buf: [1]Ast.Node.Index = undefined;
1653 const full = tree.fullFnProto(&buf, node).?;1542 const full = tree.fullFnProto(&buf, node).?;
1654 return tree.nodeToSpan(full.ast.addrspace_expr);1543 return tree.nodeToSpan(full.ast.addrspace_expr);
1655 },1544 },
1656 .node_offset_fn_type_section => |node_off| {1545 .node_offset_fn_type_section => |node_off| {
1657 const tree = try src_loc.file_scope.getTree(gpa);1546 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);
1659 var buf: [1]Ast.Node.Index = undefined;1548 var buf: [1]Ast.Node.Index = undefined;
1660 const full = tree.fullFnProto(&buf, node).?;1549 const full = tree.fullFnProto(&buf, node).?;
1661 return tree.nodeToSpan(full.ast.section_expr);1550 return tree.nodeToSpan(full.ast.section_expr);
1662 },1551 },
1663 .node_offset_fn_type_cc => |node_off| {1552 .node_offset_fn_type_cc => |node_off| {
1664 const tree = try src_loc.file_scope.getTree(gpa);1553 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);
1666 var buf: [1]Ast.Node.Index = undefined;1555 var buf: [1]Ast.Node.Index = undefined;
1667 const full = tree.fullFnProto(&buf, node).?;1556 const full = tree.fullFnProto(&buf, node).?;
1668 return tree.nodeToSpan(full.ast.callconv_expr);1557 return tree.nodeToSpan(full.ast.callconv_expr);
...@@ -1670,7 +1559,7 @@ pub const SrcLoc = struct {...@@ -1670,7 +1559,7 @@ pub const SrcLoc = struct {
16701559
1671 .node_offset_fn_type_ret_ty => |node_off| {1560 .node_offset_fn_type_ret_ty => |node_off| {
1672 const tree = try src_loc.file_scope.getTree(gpa);1561 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);
1674 var buf: [1]Ast.Node.Index = undefined;1563 var buf: [1]Ast.Node.Index = undefined;
1675 const full = tree.fullFnProto(&buf, node).?;1564 const full = tree.fullFnProto(&buf, node).?;
1676 return tree.nodeToSpan(full.ast.return_type);1565 return tree.nodeToSpan(full.ast.return_type);
...@@ -1678,7 +1567,7 @@ pub const SrcLoc = struct {...@@ -1678,7 +1567,7 @@ pub const SrcLoc = struct {
1678 .node_offset_param => |node_off| {1567 .node_offset_param => |node_off| {
1679 const tree = try src_loc.file_scope.getTree(gpa);1568 const tree = try src_loc.file_scope.getTree(gpa);
1680 const token_tags = tree.tokens.items(.tag);1569 const token_tags = tree.tokens.items(.tag);
1681 const node = src_loc.declRelativeToNodeIndex(node_off);1570 const node = src_loc.relativeToNodeIndex(node_off);
16821571
1683 var first_tok = tree.firstToken(node);1572 var first_tok = tree.firstToken(node);
1684 while (true) switch (token_tags[first_tok - 1]) {1573 while (true) switch (token_tags[first_tok - 1]) {
...@@ -1694,7 +1583,7 @@ pub const SrcLoc = struct {...@@ -1694,7 +1583,7 @@ pub const SrcLoc = struct {
1694 .token_offset_param => |token_off| {1583 .token_offset_param => |token_off| {
1695 const tree = try src_loc.file_scope.getTree(gpa);1584 const tree = try src_loc.file_scope.getTree(gpa);
1696 const token_tags = tree.tokens.items(.tag);1585 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];
1698 const tok_index = @as(Ast.TokenIndex, @bitCast(token_off + @as(i32, @bitCast(main_token))));1587 const tok_index = @as(Ast.TokenIndex, @bitCast(token_off + @as(i32, @bitCast(main_token))));
16991588
1700 var first_tok = tok_index;1589 var first_tok = tok_index;
...@@ -1712,13 +1601,13 @@ pub const SrcLoc = struct {...@@ -1712,13 +1601,13 @@ pub const SrcLoc = struct {
1712 .node_offset_anyframe_type => |node_off| {1601 .node_offset_anyframe_type => |node_off| {
1713 const tree = try src_loc.file_scope.getTree(gpa);1602 const tree = try src_loc.file_scope.getTree(gpa);
1714 const node_datas = tree.nodes.items(.data);1603 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);
1716 return tree.nodeToSpan(node_datas[parent_node].rhs);1605 return tree.nodeToSpan(node_datas[parent_node].rhs);
1717 },1606 },
17181607
1719 .node_offset_lib_name => |node_off| {1608 .node_offset_lib_name => |node_off| {
1720 const tree = try src_loc.file_scope.getTree(gpa);1609 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);
1722 var buf: [1]Ast.Node.Index = undefined;1611 var buf: [1]Ast.Node.Index = undefined;
1723 const full = tree.fullFnProto(&buf, parent_node).?;1612 const full = tree.fullFnProto(&buf, parent_node).?;
1724 const tok_index = full.lib_name.?;1613 const tok_index = full.lib_name.?;
...@@ -1729,21 +1618,21 @@ pub const SrcLoc = struct {...@@ -1729,21 +1618,21 @@ pub const SrcLoc = struct {
17291618
1730 .node_offset_array_type_len => |node_off| {1619 .node_offset_array_type_len => |node_off| {
1731 const tree = try src_loc.file_scope.getTree(gpa);1620 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
1734 const full = tree.fullArrayType(parent_node).?;1623 const full = tree.fullArrayType(parent_node).?;
1735 return tree.nodeToSpan(full.ast.elem_count);1624 return tree.nodeToSpan(full.ast.elem_count);
1736 },1625 },
1737 .node_offset_array_type_sentinel => |node_off| {1626 .node_offset_array_type_sentinel => |node_off| {
1738 const tree = try src_loc.file_scope.getTree(gpa);1627 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
1741 const full = tree.fullArrayType(parent_node).?;1630 const full = tree.fullArrayType(parent_node).?;
1742 return tree.nodeToSpan(full.ast.sentinel);1631 return tree.nodeToSpan(full.ast.sentinel);
1743 },1632 },
1744 .node_offset_array_type_elem => |node_off| {1633 .node_offset_array_type_elem => |node_off| {
1745 const tree = try src_loc.file_scope.getTree(gpa);1634 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
1748 const full = tree.fullArrayType(parent_node).?;1637 const full = tree.fullArrayType(parent_node).?;
1749 return tree.nodeToSpan(full.ast.elem_type);1638 return tree.nodeToSpan(full.ast.elem_type);
...@@ -1751,48 +1640,48 @@ pub const SrcLoc = struct {...@@ -1751,48 +1640,48 @@ pub const SrcLoc = struct {
1751 .node_offset_un_op => |node_off| {1640 .node_offset_un_op => |node_off| {
1752 const tree = try src_loc.file_scope.getTree(gpa);1641 const tree = try src_loc.file_scope.getTree(gpa);
1753 const node_datas = tree.nodes.items(.data);1642 const node_datas = tree.nodes.items(.data);
1754 const node = src_loc.declRelativeToNodeIndex(node_off);1643 const node = src_loc.relativeToNodeIndex(node_off);
17551644
1756 return tree.nodeToSpan(node_datas[node].lhs);1645 return tree.nodeToSpan(node_datas[node].lhs);
1757 },1646 },
1758 .node_offset_ptr_elem => |node_off| {1647 .node_offset_ptr_elem => |node_off| {
1759 const tree = try src_loc.file_scope.getTree(gpa);1648 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
1762 const full = tree.fullPtrType(parent_node).?;1651 const full = tree.fullPtrType(parent_node).?;
1763 return tree.nodeToSpan(full.ast.child_type);1652 return tree.nodeToSpan(full.ast.child_type);
1764 },1653 },
1765 .node_offset_ptr_sentinel => |node_off| {1654 .node_offset_ptr_sentinel => |node_off| {
1766 const tree = try src_loc.file_scope.getTree(gpa);1655 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
1769 const full = tree.fullPtrType(parent_node).?;1658 const full = tree.fullPtrType(parent_node).?;
1770 return tree.nodeToSpan(full.ast.sentinel);1659 return tree.nodeToSpan(full.ast.sentinel);
1771 },1660 },
1772 .node_offset_ptr_align => |node_off| {1661 .node_offset_ptr_align => |node_off| {
1773 const tree = try src_loc.file_scope.getTree(gpa);1662 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
1776 const full = tree.fullPtrType(parent_node).?;1665 const full = tree.fullPtrType(parent_node).?;
1777 return tree.nodeToSpan(full.ast.align_node);1666 return tree.nodeToSpan(full.ast.align_node);
1778 },1667 },
1779 .node_offset_ptr_addrspace => |node_off| {1668 .node_offset_ptr_addrspace => |node_off| {
1780 const tree = try src_loc.file_scope.getTree(gpa);1669 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
1783 const full = tree.fullPtrType(parent_node).?;1672 const full = tree.fullPtrType(parent_node).?;
1784 return tree.nodeToSpan(full.ast.addrspace_node);1673 return tree.nodeToSpan(full.ast.addrspace_node);
1785 },1674 },
1786 .node_offset_ptr_bitoffset => |node_off| {1675 .node_offset_ptr_bitoffset => |node_off| {
1787 const tree = try src_loc.file_scope.getTree(gpa);1676 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
1790 const full = tree.fullPtrType(parent_node).?;1679 const full = tree.fullPtrType(parent_node).?;
1791 return tree.nodeToSpan(full.ast.bit_range_start);1680 return tree.nodeToSpan(full.ast.bit_range_start);
1792 },1681 },
1793 .node_offset_ptr_hostsize => |node_off| {1682 .node_offset_ptr_hostsize => |node_off| {
1794 const tree = try src_loc.file_scope.getTree(gpa);1683 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
1797 const full = tree.fullPtrType(parent_node).?;1686 const full = tree.fullPtrType(parent_node).?;
1798 return tree.nodeToSpan(full.ast.bit_range_end);1687 return tree.nodeToSpan(full.ast.bit_range_end);
...@@ -1800,7 +1689,7 @@ pub const SrcLoc = struct {...@@ -1800,7 +1689,7 @@ pub const SrcLoc = struct {
1800 .node_offset_container_tag => |node_off| {1689 .node_offset_container_tag => |node_off| {
1801 const tree = try src_loc.file_scope.getTree(gpa);1690 const tree = try src_loc.file_scope.getTree(gpa);
1802 const node_tags = tree.nodes.items(.tag);1691 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
1805 switch (node_tags[parent_node]) {1694 switch (node_tags[parent_node]) {
1806 .container_decl_arg, .container_decl_arg_trailing => {1695 .container_decl_arg, .container_decl_arg_trailing => {
...@@ -1822,7 +1711,7 @@ pub const SrcLoc = struct {...@@ -1822,7 +1711,7 @@ pub const SrcLoc = struct {
1822 .node_offset_field_default => |node_off| {1711 .node_offset_field_default => |node_off| {
1823 const tree = try src_loc.file_scope.getTree(gpa);1712 const tree = try src_loc.file_scope.getTree(gpa);
1824 const node_tags = tree.nodes.items(.tag);1713 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
1827 const full: Ast.full.ContainerField = switch (node_tags[parent_node]) {1716 const full: Ast.full.ContainerField = switch (node_tags[parent_node]) {
1828 .container_field => tree.containerField(parent_node),1717 .container_field => tree.containerField(parent_node),
...@@ -1833,7 +1722,7 @@ pub const SrcLoc = struct {...@@ -1833,7 +1722,7 @@ pub const SrcLoc = struct {
1833 },1722 },
1834 .node_offset_init_ty => |node_off| {1723 .node_offset_init_ty => |node_off| {
1835 const tree = try src_loc.file_scope.getTree(gpa);1724 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
1838 var buf: [2]Ast.Node.Index = undefined;1727 var buf: [2]Ast.Node.Index = undefined;
1839 const type_expr = if (tree.fullArrayInit(&buf, parent_node)) |array_init|1728 const type_expr = if (tree.fullArrayInit(&buf, parent_node)) |array_init|
...@@ -1846,7 +1735,7 @@ pub const SrcLoc = struct {...@@ -1846,7 +1735,7 @@ pub const SrcLoc = struct {
1846 const tree = try src_loc.file_scope.getTree(gpa);1735 const tree = try src_loc.file_scope.getTree(gpa);
1847 const node_tags = tree.nodes.items(.tag);1736 const node_tags = tree.nodes.items(.tag);
1848 const node_datas = tree.nodes.items(.data);1737 const node_datas = tree.nodes.items(.data);
1849 const node = src_loc.declRelativeToNodeIndex(node_off);1738 const node = src_loc.relativeToNodeIndex(node_off);
18501739
1851 switch (node_tags[node]) {1740 switch (node_tags[node]) {
1852 .assign => {1741 .assign => {
...@@ -1859,7 +1748,7 @@ pub const SrcLoc = struct {...@@ -1859,7 +1748,7 @@ pub const SrcLoc = struct {
1859 const tree = try src_loc.file_scope.getTree(gpa);1748 const tree = try src_loc.file_scope.getTree(gpa);
1860 const node_tags = tree.nodes.items(.tag);1749 const node_tags = tree.nodes.items(.tag);
1861 const node_datas = tree.nodes.items(.data);1750 const node_datas = tree.nodes.items(.data);
1862 const node = src_loc.declRelativeToNodeIndex(node_off);1751 const node = src_loc.relativeToNodeIndex(node_off);
18631752
1864 switch (node_tags[node]) {1753 switch (node_tags[node]) {
1865 .assign => {1754 .assign => {
...@@ -1870,7 +1759,7 @@ pub const SrcLoc = struct {...@@ -1870,7 +1759,7 @@ pub const SrcLoc = struct {
1870 },1759 },
1871 .node_offset_return_operand => |node_off| {1760 .node_offset_return_operand => |node_off| {
1872 const tree = try src_loc.file_scope.getTree(gpa);1761 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);
1874 const node_tags = tree.nodes.items(.tag);1763 const node_tags = tree.nodes.items(.tag);
1875 const node_datas = tree.nodes.items(.data);1764 const node_datas = tree.nodes.items(.data);
1876 if (node_tags[node] == .@"return" and node_datas[node].lhs != 0) {1765 if (node_tags[node] == .@"return" and node_datas[node].lhs != 0) {
...@@ -1878,381 +1767,629 @@ pub const SrcLoc = struct {...@@ -1878,381 +1767,629 @@ pub const SrcLoc = struct {
1878 }1767 }
1879 return tree.nodeToSpan(node);1768 return tree.nodeToSpan(node);
1880 },1769 },
1881 }1770 .container_field_name,
1882 }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(1883 const tree = try src_loc.file_scope.getTree(gpa);
1885 src_loc: SrcLoc,1884 const node_datas = tree.nodes.items(.data);
1886 gpa: Allocator,1885 const node_tags = tree.nodes.items(.tag);
1887 node_off: i32,1886 const main_tokens = tree.nodes.items(.main_token);
1888 arg_index: u32,1887 const switch_node = src_loc.relativeToNodeIndex(switch_node_offset);
1889 ) !Span {1888 const extra = tree.extraData(node_datas[switch_node].rhs, Ast.Node.SubRange);
1890 const tree = try src_loc.file_scope.getTree(gpa);1889 const case_nodes = tree.extra_data[extra.start..extra.end];
1891 const node_datas = tree.nodes.items(.data);1890
1892 const node_tags = tree.nodes.items(.tag);1891 var multi_i: u32 = 0;
1893 const node = src_loc.declRelativeToNodeIndex(node_off);1892 var scalar_i: u32 = 0;
1894 const param = switch (node_tags[node]) {1893 const case = for (case_nodes) |case_node| {
1895 .builtin_call_two, .builtin_call_two_comma => switch (arg_index) {1894 const case = tree.fullSwitchCase(case_node).?;
1896 0 => node_datas[node].lhs,1895 const is_special = special: {
1897 1 => node_datas[node].rhs,1896 if (case.ast.values.len == 0) break :special true;
1898 else => unreachable,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 }
1899 },1978 },
1900 .builtin_call, .builtin_call_comma => tree.extra_data[node_datas[node].lhs + arg_index],1979 }
1901 else => unreachable,
1902 };
1903 return tree.nodeToSpan(param);
1904 }1980 }
1905};1981};
19061982
1907/// Resolving a source location into a byte offset may require doing work1983pub const LazySrcLoc = struct {
1908/// that we would rather not do unless the error actually occurs.1984 /// This instruction provides the source node locations are resolved relative to.
1909/// Therefore we need a data structure that contains the information necessary1985 /// It is a `declaration`, `struct_decl`, `union_decl`, `enum_decl`, or `opaque_decl`.
1910/// to lazily produce a `SrcLoc` as required.1986 /// This must be valid even if `relative` is an absolute value, since it is required to
1911/// Most of the offsets in this data structure are relative to the containing Decl.1987 /// determine the file which the `LazySrcLoc` refers to.
1912/// This makes the source location resolve properly even when a Decl gets1988 base_node_inst: InternPool.TrackedInst.Index,
1913/// shifted up or down in the file, as long as the Decl's contents itself1989 /// This field determines the source location relative to `base_node_inst`.
1914/// do not change.1990 offset: Offset,
1915pub const LazySrcLoc = union(enum) {1991
1916 /// When this tag is set, the code that constructed this `LazySrcLoc` is asserting1992 pub const Offset = union(enum) {
1917 /// that all code paths which would need to resolve the source location are1993 /// When this tag is set, the code that constructed this `LazySrcLoc` is asserting
1918 /// unreachable. If you are debugging this tag incorrectly being this value,1994 /// that all code paths which would need to resolve the source location are
1919 /// look into using reverse-continue with a memory watchpoint to see where the1995 /// unreachable. If you are debugging this tag incorrectly being this value,
1920 /// value is being set to this tag.1996 /// look into using reverse-continue with a memory watchpoint to see where the
1921 unneeded,1997 /// value is being set to this tag.
1922 /// Means the source location points to an entire file; not any particular1998 /// `base_node_inst` is unused.
1923 /// location within the file. `file_scope` union field will be active.1999 unneeded,
1924 entire_file,2000 /// Means the source location points to an entire file; not any particular
1925 /// The source location points to a byte offset within a source file,2001 /// location within the file. `file_scope` union field will be active.
1926 /// offset from 0. The source file is determined contextually.2002 entire_file,
1927 /// Inside a `SrcLoc`, the `file_scope` union field will be active.2003 /// The source location points to a byte offset within a source file,
1928 byte_abs: u32,2004 /// offset from 0. The source file is determined contextually.
1929 /// The source location points to a token within a source file,2005 /// Inside a `SrcLoc`, the `file_scope` union field will be active.
1930 /// offset from 0. The source file is determined contextually.2006 byte_abs: u32,
1931 /// Inside a `SrcLoc`, the `file_scope` union field will be active.2007 /// The source location points to a token within a source file,
1932 token_abs: u32,2008 /// offset from 0. The source file is determined contextually.
1933 /// The source location points to an AST node within a source file,2009 /// Inside a `SrcLoc`, the `file_scope` union field will be active.
1934 /// offset from 0. The source file is determined contextually.2010 token_abs: u32,
1935 /// Inside a `SrcLoc`, the `file_scope` union field will be active.2011 /// The source location points to an AST node within a source file,
1936 node_abs: u32,2012 /// offset from 0. The source file is determined contextually.
1937 /// The source location points to a byte offset within a source file,2013 /// Inside a `SrcLoc`, the `file_scope` union field will be active.
1938 /// offset from the byte offset of the Decl within the file.2014 node_abs: u32,
1939 /// The Decl is determined contextually.2015 /// The source location points to a byte offset within a source file,
1940 byte_offset: u32,2016 /// offset from the byte offset of the base node within the file.
1941 /// This data is the offset into the token list from the Decl token.2017 byte_offset: u32,
1942 /// The Decl is determined contextually.2018 /// This data is the offset into the token list from the base node's first token.
1943 token_offset: u32,2019 token_offset: u32,
1944 /// The source location points to an AST node, which is this value offset2020 /// The source location points to an AST node, which is this value offset
1945 /// from its containing Decl node AST index.2021 /// from its containing base node AST index.
1946 /// The Decl is determined contextually.2022 node_offset: TracedOffset,
1947 node_offset: TracedOffset,2023 /// The source location points to the main token of an AST node, found
1948 /// The source location points to the main token of an AST node, found2024 /// by taking this AST node index offset from the containing base node.
1949 /// by taking this AST node index offset from the containing Decl AST node.2025 node_offset_main_token: i32,
1950 /// The Decl is determined contextually.2026 /// The source location points to the beginning of a struct initializer.
1951 node_offset_main_token: i32,2027 node_offset_initializer: i32,
1952 /// The source location points to the beginning of a struct initializer.2028 /// The source location points to a variable declaration type expression,
1953 /// The Decl is determined contextually.2029 /// found by taking this AST node index offset from the containing
1954 node_offset_initializer: i32,2030 /// base node, which points to a variable declaration AST node. Next, navigate
1955 /// The source location points to a variable declaration type expression,2031 /// to the type expression.
1956 /// found by taking this AST node index offset from the containing2032 node_offset_var_decl_ty: i32,
1957 /// Decl AST node, which points to a variable declaration AST node. Next, navigate2033 /// The source location points to the alignment expression of a var decl.
1958 /// to the type expression.2034 node_offset_var_decl_align: i32,
1959 /// The Decl is determined contextually.2035 /// The source location points to the linksection expression of a var decl.
1960 node_offset_var_decl_ty: i32,2036 node_offset_var_decl_section: i32,
1961 /// The source location points to the alignment expression of a var decl.2037 /// The source location points to the addrspace expression of a var decl.
1962 /// The Decl is determined contextually.2038 node_offset_var_decl_addrspace: i32,
1963 node_offset_var_decl_align: i32,2039 /// The source location points to the initializer of a var decl.
1964 /// The source location points to the linksection expression of a var decl.2040 node_offset_var_decl_init: i32,
1965 /// The Decl is determined contextually.2041 /// The source location points to the given argument of a builtin function call.
1966 node_offset_var_decl_section: i32,2042 /// `builtin_call_node` points to the builtin call.
1967 /// The source location points to the addrspace expression of a var decl.2043 /// `arg_index` is the index of the argument which hte source location refers to.
1968 /// The Decl is determined contextually.2044 node_offset_builtin_call_arg: struct {
1969 node_offset_var_decl_addrspace: i32,2045 builtin_call_node: i32,
1970 /// The source location points to the initializer of a var decl.2046 arg_index: u32,
1971 /// The Decl is determined contextually.2047 },
1972 node_offset_var_decl_init: i32,2048 /// Like `node_offset_builtin_call_arg` but recurses through arbitrarily many calls
1973 /// The source location points to the first parameter of a builtin2049 /// to pointer cast builtins (taking the first argument of the most nested).
1974 /// function call, found by taking this AST node index offset from the containing2050 node_offset_ptrcast_operand: i32,
1975 /// Decl AST node, which points to a builtin call AST node. Next, navigate2051 /// The source location points to the index expression of an array access
1976 /// to the first parameter.2052 /// expression, found by taking this AST node index offset from the containing
1977 /// The Decl is determined contextually.2053 /// base node, which points to an array access AST node. Next, navigate
1978 node_offset_builtin_call_arg0: i32,2054 /// to the index expression.
1979 /// Same as `node_offset_builtin_call_arg0` except arg index 1.2055 node_offset_array_access_index: i32,
1980 node_offset_builtin_call_arg1: i32,2056 /// The source location points to the LHS of a slice expression
1981 node_offset_builtin_call_arg2: i32,2057 /// expression, found by taking this AST node index offset from the containing
1982 node_offset_builtin_call_arg3: i32,2058 /// base node, which points to a slice AST node. Next, navigate
1983 node_offset_builtin_call_arg4: i32,2059 /// to the sentinel expression.
1984 node_offset_builtin_call_arg5: i32,2060 node_offset_slice_ptr: i32,
1985 /// Like `node_offset_builtin_call_arg0` but recurses through arbitrarily many calls2061 /// The source location points to start expression of a slice expression
1986 /// to pointer cast builtins.2062 /// expression, found by taking this AST node index offset from the containing
1987 node_offset_ptrcast_operand: i32,2063 /// base node, which points to a slice AST node. Next, navigate
1988 /// The source location points to the index expression of an array access2064 /// to the sentinel expression.
1989 /// expression, found by taking this AST node index offset from the containing2065 node_offset_slice_start: i32,
1990 /// Decl AST node, which points to an array access AST node. Next, navigate2066 /// The source location points to the end expression of a slice
1991 /// to the index expression.2067 /// expression, found by taking this AST node index offset from the containing
1992 /// The Decl is determined contextually.2068 /// base node, which points to a slice AST node. Next, navigate
1993 node_offset_array_access_index: i32,2069 /// to the sentinel expression.
1994 /// The source location points to the LHS of a slice expression2070 node_offset_slice_end: i32,
1995 /// expression, found by taking this AST node index offset from the containing2071 /// The source location points to the sentinel expression of a slice
1996 /// Decl AST node, which points to a slice AST node. Next, navigate2072 /// expression, found by taking this AST node index offset from the containing
1997 /// to the sentinel expression.2073 /// base node, which points to a slice AST node. Next, navigate
1998 /// The Decl is determined contextually.2074 /// to the sentinel expression.
1999 node_offset_slice_ptr: i32,2075 node_offset_slice_sentinel: i32,
2000 /// The source location points to start expression of a slice expression2076 /// The source location points to the callee expression of a function
2001 /// expression, found by taking this AST node index offset from the containing2077 /// call expression, found by taking this AST node index offset from the containing
2002 /// Decl AST node, which points to a slice AST node. Next, navigate2078 /// base node, which points to a function call AST node. Next, navigate
2003 /// to the sentinel expression.2079 /// to the callee expression.
2004 /// The Decl is determined contextually.2080 node_offset_call_func: i32,
2005 node_offset_slice_start: i32,2081 /// The payload is offset from the containing base node.
2006 /// The source location points to the end expression of a slice2082 /// The source location points to the field name of:
2007 /// expression, found by taking this AST node index offset from the containing2083 /// * a field access expression (`a.b`), or
2008 /// Decl AST node, which points to a slice AST node. Next, navigate2084 /// * the callee of a method call (`a.b()`)
2009 /// to the sentinel expression.2085 node_offset_field_name: i32,
2010 /// The Decl is determined contextually.2086 /// The payload is offset from the containing base node.
2011 node_offset_slice_end: i32,2087 /// The source location points to the field name of the operand ("b" node)
2012 /// The source location points to the sentinel expression of a slice2088 /// of a field initialization expression (`.a = b`)
2013 /// expression, found by taking this AST node index offset from the containing2089 node_offset_field_name_init: i32,
2014 /// Decl AST node, which points to a slice AST node. Next, navigate2090 /// The source location points to the pointer of a pointer deref expression,
2015 /// to the sentinel expression.2091 /// found by taking this AST node index offset from the containing
2016 /// The Decl is determined contextually.2092 /// base node, which points to a pointer deref AST node. Next, navigate
2017 node_offset_slice_sentinel: i32,2093 /// to the pointer expression.
2018 /// The source location points to the callee expression of a function2094 node_offset_deref_ptr: i32,
2019 /// call expression, found by taking this AST node index offset from the containing2095 /// The source location points to the assembly source code of an inline assembly
2020 /// Decl AST node, which points to a function call AST node. Next, navigate2096 /// expression, found by taking this AST node index offset from the containing
2021 /// to the callee expression.2097 /// base node, which points to inline assembly AST node. Next, navigate
2022 /// The Decl is determined contextually.2098 /// to the asm template source code.
2023 node_offset_call_func: i32,2099 node_offset_asm_source: i32,
2024 /// The payload is offset from the containing Decl AST node.2100 /// The source location points to the return type of an inline assembly
2025 /// The source location points to the field name of:2101 /// expression, found by taking this AST node index offset from the containing
2026 /// * a field access expression (`a.b`), or2102 /// base node, which points to inline assembly AST node. Next, navigate
2027 /// * the callee of a method call (`a.b()`)2103 /// to the return type expression.
2028 /// The Decl is determined contextually.2104 node_offset_asm_ret_ty: i32,
2029 node_offset_field_name: i32,2105 /// The source location points to the condition expression of an if
2030 /// The payload is offset from the containing Decl AST node.2106 /// expression, found by taking this AST node index offset from the containing
2031 /// The source location points to the field name of the operand ("b" node)2107 /// base node, which points to an if expression AST node. Next, navigate
2032 /// of a field initialization expression (`.a = b`)2108 /// to the condition expression.
2033 /// The Decl is determined contextually.2109 node_offset_if_cond: i32,
2034 node_offset_field_name_init: i32,2110 /// The source location points to a binary expression, such as `a + b`, found
2035 /// The source location points to the pointer of a pointer deref expression,2111 /// by taking this AST node index offset from the containing base node.
2036 /// found by taking this AST node index offset from the containing2112 node_offset_bin_op: i32,
2037 /// Decl AST node, which points to a pointer deref AST node. Next, navigate2113 /// The source location points to the LHS of a binary expression, found
2038 /// to the pointer expression.2114 /// by taking this AST node index offset from the containing base node,
2039 /// The Decl is determined contextually.2115 /// which points to a binary expression AST node. Next, navigate to the LHS.
2040 node_offset_deref_ptr: i32,2116 node_offset_bin_lhs: i32,
2041 /// The source location points to the assembly source code of an inline assembly2117 /// The source location points to the RHS of a binary expression, found
2042 /// expression, found by taking this AST node index offset from the containing2118 /// by taking this AST node index offset from the containing base node,
2043 /// Decl AST node, which points to inline assembly AST node. Next, navigate2119 /// which points to a binary expression AST node. Next, navigate to the RHS.
2044 /// to the asm template source code.2120 node_offset_bin_rhs: i32,
2045 /// The Decl is determined contextually.2121 /// The source location points to the operand of a switch expression, found
2046 node_offset_asm_source: i32,2122 /// by taking this AST node index offset from the containing base node,
2047 /// The source location points to the return type of an inline assembly2123 /// which points to a switch expression AST node. Next, navigate to the operand.
2048 /// expression, found by taking this AST node index offset from the containing2124 node_offset_switch_operand: i32,
2049 /// Decl AST node, which points to inline assembly AST node. Next, navigate2125 /// The source location points to the else/`_` prong of a switch expression, found
2050 /// to the return type expression.2126 /// by taking this AST node index offset from the containing base node,
2051 /// The Decl is determined contextually.2127 /// which points to a switch expression AST node. Next, navigate to the else/`_` prong.
2052 node_offset_asm_ret_ty: i32,2128 node_offset_switch_special_prong: i32,
2053 /// The source location points to the condition expression of an if2129 /// The source location points to all the ranges of a switch expression, found
2054 /// expression, found by taking this AST node index offset from the containing2130 /// by taking this AST node index offset from the containing base node,
2055 /// Decl AST node, which points to an if expression AST node. Next, navigate2131 /// which points to a switch expression AST node. Next, navigate to any of the
2056 /// to the condition expression.2132 /// range nodes. The error applies to all of them.
2057 /// The Decl is determined contextually.2133 node_offset_switch_range: i32,
2058 node_offset_if_cond: i32,2134 /// The source location points to the align expr of a function type
2059 /// The source location points to a binary expression, such as `a + b`, found2135 /// expression, found by taking this AST node index offset from the containing
2060 /// by taking this AST node index offset from the containing Decl AST node.2136 /// base node, which points to a function type AST node. Next, navigate to
2061 /// The Decl is determined contextually.2137 /// the calling convention node.
2062 node_offset_bin_op: i32,2138 node_offset_fn_type_align: i32,
2063 /// The source location points to the LHS of a binary expression, found2139 /// The source location points to the addrspace expr of a function type
2064 /// by taking this AST node index offset from the containing Decl AST node,2140 /// expression, found by taking this AST node index offset from the containing
2065 /// which points to a binary expression AST node. Next, navigate to the LHS.2141 /// base node, which points to a function type AST node. Next, navigate to
2066 /// The Decl is determined contextually.2142 /// the calling convention node.
2067 node_offset_bin_lhs: i32,2143 node_offset_fn_type_addrspace: i32,
2068 /// The source location points to the RHS of a binary expression, found2144 /// The source location points to the linksection expr of a function type
2069 /// by taking this AST node index offset from the containing Decl AST node,2145 /// expression, found by taking this AST node index offset from the containing
2070 /// which points to a binary expression AST node. Next, navigate to the RHS.2146 /// base node, which points to a function type AST node. Next, navigate to
2071 /// The Decl is determined contextually.2147 /// the calling convention node.
2072 node_offset_bin_rhs: i32,2148 node_offset_fn_type_section: i32,
2073 /// The source location points to the operand of a switch expression, found2149 /// The source location points to the calling convention of a function type
2074 /// by taking this AST node index offset from the containing Decl AST node,2150 /// expression, found by taking this AST node index offset from the containing
2075 /// which points to a switch expression AST node. Next, navigate to the operand.2151 /// base node, which points to a function type AST node. Next, navigate to
2076 /// The Decl is determined contextually.2152 /// the calling convention node.
2077 node_offset_switch_operand: i32,2153 node_offset_fn_type_cc: i32,
2078 /// The source location points to the else/`_` prong of a switch expression, found2154 /// The source location points to the return type of a function type
2079 /// by taking this AST node index offset from the containing Decl AST node,2155 /// expression, found by taking this AST node index offset from the containing
2080 /// which points to a switch expression AST node. Next, navigate to the else/`_` prong.2156 /// base node, which points to a function type AST node. Next, navigate to
2081 /// The Decl is determined contextually.2157 /// the return type node.
2082 node_offset_switch_special_prong: i32,2158 node_offset_fn_type_ret_ty: i32,
2083 /// The source location points to all the ranges of a switch expression, found2159 node_offset_param: i32,
2084 /// by taking this AST node index offset from the containing Decl AST node,2160 token_offset_param: i32,
2085 /// which points to a switch expression AST node. Next, navigate to any of the2161 /// The source location points to the type expression of an `anyframe->T`
2086 /// range nodes. The error applies to all of them.2162 /// expression, found by taking this AST node index offset from the containing
2087 /// The Decl is determined contextually.2163 /// base node, which points to a `anyframe->T` expression AST node. Next, navigate
2088 node_offset_switch_range: i32,2164 /// to the type expression.
2089 /// The source location points to the capture of a switch_prong.2165 node_offset_anyframe_type: i32,
2090 /// The Decl is determined contextually.2166 /// The source location points to the string literal of `extern "foo"`, found
2091 node_offset_switch_prong_capture: i32,2167 /// by taking this AST node index offset from the containing
2092 /// The source location points to the tag capture of a switch_prong.2168 /// base node, which points to a function prototype or variable declaration
2093 /// The Decl is determined contextually.2169 /// expression AST node. Next, navigate to the string literal of the `extern "foo"`.
2094 node_offset_switch_prong_tag_capture: i32,2170 node_offset_lib_name: i32,
2095 /// The source location points to the align expr of a function type2171 /// The source location points to the len expression of an `[N:S]T`
2096 /// expression, found by taking this AST node index offset from the containing2172 /// 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 to2173 /// base node, which points to an `[N:S]T` expression AST node. Next, navigate
2098 /// the calling convention node.2174 /// to the len expression.
2099 /// The Decl is determined contextually.2175 node_offset_array_type_len: i32,
2100 node_offset_fn_type_align: i32,2176 /// The source location points to the sentinel expression of an `[N:S]T`
2101 /// The source location points to the addrspace expr of a function type2177 /// expression, found by taking this AST node index offset from the containing
2102 /// expression, found by taking this AST node index offset from the containing2178 /// base node, which points to an `[N:S]T` expression AST node. Next, navigate
2103 /// Decl AST node, which points to a function type AST node. Next, navigate to2179 /// to the sentinel expression.
2104 /// the calling convention node.2180 node_offset_array_type_sentinel: i32,
2105 /// The Decl is determined contextually.2181 /// The source location points to the elem expression of an `[N:S]T`
2106 node_offset_fn_type_addrspace: i32,2182 /// expression, found by taking this AST node index offset from the containing
2107 /// The source location points to the linksection expr of a function type2183 /// base node, which points to an `[N:S]T` expression AST node. Next, navigate
2108 /// expression, found by taking this AST node index offset from the containing2184 /// to the elem expression.
2109 /// Decl AST node, which points to a function type AST node. Next, navigate to2185 node_offset_array_type_elem: i32,
2110 /// the calling convention node.2186 /// The source location points to the operand of an unary expression.
2111 /// The Decl is determined contextually.2187 node_offset_un_op: i32,
2112 node_offset_fn_type_section: i32,2188 /// The source location points to the elem type of a pointer.
2113 /// The source location points to the calling convention of a function type2189 node_offset_ptr_elem: i32,
2114 /// expression, found by taking this AST node index offset from the containing2190 /// The source location points to the sentinel of a pointer.
2115 /// Decl AST node, which points to a function type AST node. Next, navigate to2191 node_offset_ptr_sentinel: i32,
2116 /// the calling convention node.2192 /// The source location points to the align expr of a pointer.
2117 /// The Decl is determined contextually.2193 node_offset_ptr_align: i32,
2118 node_offset_fn_type_cc: i32,2194 /// The source location points to the addrspace expr of a pointer.
2119 /// The source location points to the return type of a function type2195 node_offset_ptr_addrspace: i32,
2120 /// expression, found by taking this AST node index offset from the containing2196 /// The source location points to the bit-offset of a pointer.
2121 /// Decl AST node, which points to a function type AST node. Next, navigate to2197 node_offset_ptr_bitoffset: i32,
2122 /// the return type node.2198 /// The source location points to the host size of a pointer.
2123 /// The Decl is determined contextually.2199 node_offset_ptr_hostsize: i32,
2124 node_offset_fn_type_ret_ty: i32,2200 /// The source location points to the tag type of an union or an enum.
2125 node_offset_param: i32,2201 node_offset_container_tag: i32,
2126 token_offset_param: i32,2202 /// The source location points to the default value of a field.
2127 /// The source location points to the type expression of an `anyframe->T`2203 node_offset_field_default: i32,
2128 /// expression, found by taking this AST node index offset from the containing2204 /// The source location points to the type of an array or struct initializer.
2129 /// Decl AST node, which points to a `anyframe->T` expression AST node. Next, navigate2205 node_offset_init_ty: i32,
2130 /// to the type expression.2206 /// The source location points to the LHS of an assignment.
2131 /// The Decl is determined contextually.2207 node_offset_store_ptr: i32,
2132 node_offset_anyframe_type: i32,2208 /// The source location points to the RHS of an assignment.
2133 /// The source location points to the string literal of `extern "foo"`, found2209 node_offset_store_operand: i32,
2134 /// by taking this AST node index offset from the containing2210 /// The source location points to the operand of a `return` statement, or
2135 /// Decl AST node, which points to a function prototype or variable declaration2211 /// the `return` itself if there is no explicit operand.
2136 /// expression AST node. Next, navigate to the string literal of the `extern "foo"`.2212 node_offset_return_operand: i32,
2137 /// The Decl is determined contextually.2213 /// The source location points to a for loop input.
2138 node_offset_lib_name: i32,2214 for_input: struct {
2139 /// The source location points to the len expression of an `[N:S]T`2215 /// Points to the for loop AST node.
2140 /// expression, found by taking this AST node index offset from the containing2216 for_node_offset: i32,
2141 /// Decl AST node, which points to an `[N:S]T` expression AST node. Next, navigate2217 /// Picks one of the inputs from the condition.
2142 /// to the len expression.2218 input_index: u32,
2143 /// The Decl is determined contextually.2219 },
2144 node_offset_array_type_len: i32,2220 /// The source location points to one of the captures of a for loop, found
2145 /// The source location points to the sentinel expression of an `[N:S]T`2221 /// by taking this AST node index offset from the containing
2146 /// expression, found by taking this AST node index offset from the containing2222 /// base node, which points to one of the input nodes of a for loop.
2147 /// Decl AST node, which points to an `[N:S]T` expression AST node. Next, navigate2223 /// Next, navigate to the corresponding capture.
2148 /// to the sentinel expression.2224 for_capture_from_input: i32,
2149 /// The Decl is determined contextually.2225 /// The source location points to the argument node of a function call.
2150 node_offset_array_type_sentinel: i32,2226 call_arg: struct {
2151 /// The source location points to the elem expression of an `[N:S]T`2227 /// Points to the function call AST node.
2152 /// expression, found by taking this AST node index offset from the containing2228 call_node_offset: i32,
2153 /// Decl AST node, which points to an `[N:S]T` expression AST node. Next, navigate2229 /// The index of the argument the source location points to.
2154 /// to the elem expression.2230 arg_index: u32,
2155 /// The Decl is determined contextually.2231 },
2156 node_offset_array_type_elem: i32,2232 fn_proto_param: FnProtoParam,
2157 /// The source location points to the operand of an unary expression.2233 fn_proto_param_type: FnProtoParam,
2158 /// The Decl is determined contextually.2234 array_cat_lhs: ArrayCat,
2159 node_offset_un_op: i32,2235 array_cat_rhs: ArrayCat,
2160 /// The source location points to the elem type of a pointer.2236 /// The source location points to the name of the field at the given index
2161 /// The Decl is determined contextually.2237 /// of the container type declaration at the base node.
2162 node_offset_ptr_elem: i32,2238 container_field_name: u32,
2163 /// The source location points to the sentinel of a pointer.2239 /// Like `continer_field_name`, but points at the field's default value.
2164 /// The Decl is determined contextually.2240 container_field_value: u32,
2165 node_offset_ptr_sentinel: i32,2241 /// Like `continer_field_name`, but points at the field's type.
2166 /// The source location points to the align expr of a pointer.2242 container_field_type: u32,
2167 /// The Decl is determined contextually.2243 /// Like `continer_field_name`, but points at the field's alignment.
2168 node_offset_ptr_align: i32,2244 container_field_align: u32,
2169 /// The source location points to the addrspace expr of a pointer.2245 /// The source location points to the given element/field of a struct or
2170 /// The Decl is determined contextually.2246 /// array initialization expression.
2171 node_offset_ptr_addrspace: i32,2247 init_elem: struct {
2172 /// The source location points to the bit-offset of a pointer.2248 /// Points to the AST node of the initialization expression.
2173 /// The Decl is determined contextually.2249 init_node_offset: i32,
2174 node_offset_ptr_bitoffset: i32,2250 /// The index of the field/element the source location points to.
2175 /// The source location points to the host size of a pointer.2251 elem_index: u32,
2176 /// The Decl is determined contextually.2252 },
2177 node_offset_ptr_hostsize: i32,2253 // The following source locations are like `init_elem`, but refer to a
2178 /// The source location points to the tag type of an union or an enum.2254 // field with a specific name. If such a field is not given, the entire
2179 /// The Decl is determined contextually.2255 // initialization expression is used instead.
2180 node_offset_container_tag: i32,2256 // The `i32` points to the AST node of a builtin call, whose *second*
2181 /// The source location points to the default value of a field.2257 // argument is the init expression.
2182 /// The Decl is determined contextually.2258 init_field_name: i32,
2183 node_offset_field_default: i32,2259 init_field_linkage: i32,
2184 /// The source location points to the type of an array or struct initializer.2260 init_field_section: i32,
2185 /// The Decl is determined contextually.2261 init_field_visibility: i32,
2186 node_offset_init_ty: i32,2262 init_field_rw: i32,
2187 /// The source location points to the LHS of an assignment.2263 init_field_locality: i32,
2188 /// The Decl is determined contextually.2264 init_field_cache: i32,
2189 node_offset_store_ptr: i32,2265 init_field_library: i32,
2190 /// The source location points to the RHS of an assignment.2266 init_field_thread_local: i32,
2191 /// The Decl is determined contextually.2267 /// The source location points to the value of an item in a specific
2192 node_offset_store_operand: i32,2268 /// case of a `switch`.
2193 /// The source location points to the operand of a `return` statement, or2269 switch_case_item: SwitchItem,
2194 /// the `return` itself if there is no explicit operand.2270 /// The source location points to the "first" value of a range item in
2195 /// The Decl is determined contextually.2271 /// a specific case of a `switch`.
2196 node_offset_return_operand: i32,2272 switch_case_item_range_first: SwitchItem,
2197 /// The source location points to a for loop input.2273 /// The source location points to the "last" value of a range item in
2198 /// The Decl is determined contextually.2274 /// a specific case of a `switch`.
2199 for_input: struct {2275 switch_case_item_range_last: SwitchItem,
2200 /// Points to the for loop AST node.2276 /// The source location points to the main capture of a specific case of
2201 for_node_offset: i32,2277 /// a `switch`.
2202 /// Picks one of the inputs from the condition.2278 switch_capture: SwitchCapture,
2203 input_index: u32,2279 /// The source location points to the "tag" capture (second capture) of
2204 },2280 /// a specific case of a `switch`.
2205 /// The source location points to one of the captures of a for loop, found2281 switch_tag_capture: SwitchCapture,
2206 /// by taking this AST node index offset from the containing2282
2207 /// Decl AST node, which points to one of the input nodes of a for loop.2283 pub const FnProtoParam = struct {
2208 /// Next, navigate to the corresponding capture.2284 /// The offset of the function prototype AST node.
2209 /// The Decl is determined contextually.2285 fn_proto_node_offset: i32,
2210 for_capture_from_input: i32,2286 /// The index of the parameter the source location points to.
2211 /// The source location points to the argument node of a function call.2287 param_index: u32,
2212 call_arg: struct {2288 };
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 };
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 {2299 pub const SwitchCapture = struct {
2239 var result: LazySrcLoc = .{ .node_offset = .{ .x = node_offset } };2300 /// The offset of the switch AST node.
2240 result.node_offset.trace.addAddr(@returnAddress(), "init");2301 switch_node_offset: i32,
2241 return result;2302 /// The index of the case whose capture to point to.
2242 }2303 case_idx: SwitchCaseIndex,
2304 };
22432305
2244 fn nodeOffsetRelease(node_offset: i32) LazySrcLoc {2306 pub const SwitchCaseIndex = packed struct(u32) {
2245 return .{ .node_offset = .{ .x = node_offset } };2307 kind: enum(u1) { scalar, multi },
2246 }2308 index: u31,
22472309
2248 /// This wraps a simple integer in debug builds so that later on we can find out2310 pub const special: SwitchCaseIndex = @bitCast(@as(u32, std.math.maxInt(u32)));
2249 /// where in semantic analysis the value got set.2311 pub fn isSpecial(idx: SwitchCaseIndex) bool {
2250 pub const TracedOffset = struct {2312 return @as(u32, @bitCast(idx)) == @as(u32, @bitCast(special));
2251 x: i32,2313 }
2252 trace: std.debug.Trace = std.debug.Trace.init,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 };
2255 };2348 };
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 }
2256};2393};
22572394
2258pub const SemaError = error{ OutOfMemory, AnalysisFail };2395pub const SemaError = error{ OutOfMemory, AnalysisFail };
...@@ -2260,11 +2397,6 @@ pub const CompileError = error{...@@ -2260,11 +2397,6 @@ pub const CompileError = error{
2260 OutOfMemory,2397 OutOfMemory,
2261 /// When this is returned, the compile error for the failure has already been recorded.2398 /// When this is returned, the compile error for the failure has already been recorded.
2262 AnalysisFail,2399 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,
2268 /// A Type or Value was needed to be used during semantic analysis, but it was not available2400 /// A Type or Value was needed to be used during semantic analysis, but it was not available
2269 /// because the function is generic. This is only seen when analyzing the body of a param2401 /// because the function is generic. This is only seen when analyzing the body of a param
2270 /// instruction.2402 /// instruction.
...@@ -3373,7 +3505,6 @@ pub fn ensureDeclAnalyzed(mod: *Module, decl_index: Decl.Index) SemaError!void {...@@ -3373,7 +3505,6 @@ pub fn ensureDeclAnalyzed(mod: *Module, decl_index: Decl.Index) SemaError!void {
3373 }3505 }
3374 return error.AnalysisFail;3506 return error.AnalysisFail;
3375 },3507 },
3376 error.NeededSourceLocation => unreachable,
3377 error.GenericPoison => unreachable,3508 error.GenericPoison => unreachable,
3378 else => |e| {3509 else => |e| {
3379 decl.analysis = .sema_failure;3510 decl.analysis = .sema_failure;
...@@ -3381,7 +3512,7 @@ pub fn ensureDeclAnalyzed(mod: *Module, decl_index: Decl.Index) SemaError!void {...@@ -3381,7 +3512,7 @@ pub fn ensureDeclAnalyzed(mod: *Module, decl_index: Decl.Index) SemaError!void {
3381 try mod.retryable_failures.append(mod.gpa, InternPool.Depender.wrap(.{ .decl = decl_index }));3512 try mod.retryable_failures.append(mod.gpa, InternPool.Depender.wrap(.{ .decl = decl_index }));
3382 mod.failed_decls.putAssumeCapacityNoClobber(decl_index, try ErrorMsg.create(3513 mod.failed_decls.putAssumeCapacityNoClobber(decl_index, try ErrorMsg.create(
3383 mod.gpa,3514 mod.gpa,
3384 decl.srcLoc(mod),3515 decl.navSrcLoc(mod).upgrade(mod),
3385 "unable to analyze: {s}",3516 "unable to analyze: {s}",
3386 .{@errorName(e)},3517 .{@errorName(e)},
3387 ));3518 ));
...@@ -3555,7 +3686,7 @@ pub fn ensureFuncBodyAnalyzed(zcu: *Zcu, maybe_coerced_func_index: InternPool.In...@@ -3555,7 +3686,7 @@ pub fn ensureFuncBodyAnalyzed(zcu: *Zcu, maybe_coerced_func_index: InternPool.In
3555 decl_index,3686 decl_index,
3556 try Module.ErrorMsg.create(3687 try Module.ErrorMsg.create(
3557 gpa,3688 gpa,
3558 decl.srcLoc(zcu),3689 decl.navSrcLoc(zcu).upgrade(zcu),
3559 "invalid liveness: {s}",3690 "invalid liveness: {s}",
3560 .{@errorName(err)},3691 .{@errorName(err)},
3561 ),3692 ),
...@@ -3579,7 +3710,7 @@ pub fn ensureFuncBodyAnalyzed(zcu: *Zcu, maybe_coerced_func_index: InternPool.In...@@ -3579,7 +3710,7 @@ pub fn ensureFuncBodyAnalyzed(zcu: *Zcu, maybe_coerced_func_index: InternPool.In
3579 try zcu.failed_decls.ensureUnusedCapacity(gpa, 1);3710 try zcu.failed_decls.ensureUnusedCapacity(gpa, 1);
3580 zcu.failed_decls.putAssumeCapacityNoClobber(decl_index, try Module.ErrorMsg.create(3711 zcu.failed_decls.putAssumeCapacityNoClobber(decl_index, try Module.ErrorMsg.create(
3581 gpa,3712 gpa,
3582 decl.srcLoc(zcu),3713 decl.navSrcLoc(zcu).upgrade(zcu),
3583 "unable to codegen: {s}",3714 "unable to codegen: {s}",
3584 .{@errorName(err)},3715 .{@errorName(err)},
3585 ));3716 ));
...@@ -3814,7 +3945,7 @@ fn semaFile(mod: *Module, file: *File) SemaError!void {...@@ -3814,7 +3945,7 @@ fn semaFile(mod: *Module, file: *File) SemaError!void {
3814 });3945 });
3815 errdefer mod.destroyNamespace(new_namespace_index);3946 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);
3818 const new_decl = mod.declPtr(new_decl_index);3949 const new_decl = mod.declPtr(new_decl_index);
3819 errdefer @panic("TODO error handling");3950 errdefer @panic("TODO error handling");
38203951
...@@ -3961,7 +4092,7 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !SemaDeclResult {...@@ -3961,7 +4092,7 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !SemaDeclResult {
3961 var analysis_arena = std.heap.ArenaAllocator.init(gpa);4092 var analysis_arena = std.heap.ArenaAllocator.init(gpa);
3962 defer analysis_arena.deinit();4093 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);
3965 defer comptime_err_ret_trace.deinit();4096 defer comptime_err_ret_trace.deinit();
39664097
3967 var sema: Sema = .{4098 var sema: Sema = .{
...@@ -3996,6 +4127,7 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !SemaDeclResult {...@@ -3996,6 +4127,7 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !SemaDeclResult {
3996 .instructions = .{},4127 .instructions = .{},
3997 .inlining = null,4128 .inlining = null,
3998 .is_comptime = true,4129 .is_comptime = true,
4130 .src_base_inst = decl.zir_decl_index.unwrap().?,
3999 };4131 };
4000 defer block_scope.instructions.deinit(gpa);4132 defer block_scope.instructions.deinit(gpa);
40014133
...@@ -4005,11 +4137,11 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !SemaDeclResult {...@@ -4005,11 +4137,11 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !SemaDeclResult {
4005 // We'll do some other bits with the Sema. Clear the type target index just4137 // We'll do some other bits with the Sema. Clear the type target index just
4006 // in case they analyze any type.4138 // in case they analyze any type.
4007 sema.builtin_type_target_index = .none;4139 sema.builtin_type_target_index = .none;
4008 const align_src: LazySrcLoc = .{ .node_offset_var_decl_align = 0 };4140 const align_src: LazySrcLoc = block_scope.src(.{ .node_offset_var_decl_align = 0 });
4009 const section_src: LazySrcLoc = .{ .node_offset_var_decl_section = 0 };4141 const section_src: LazySrcLoc = block_scope.src(.{ .node_offset_var_decl_section = 0 });
4010 const address_space_src: LazySrcLoc = .{ .node_offset_var_decl_addrspace = 0 };4142 const address_space_src: LazySrcLoc = block_scope.src(.{ .node_offset_var_decl_addrspace = 0 });
4011 const ty_src: LazySrcLoc = .{ .node_offset_var_decl_ty = 0 };4143 const ty_src: LazySrcLoc = block_scope.src(.{ .node_offset_var_decl_ty = 0 });
4012 const init_src: LazySrcLoc = .{ .node_offset_var_decl_init = 0 };4144 const init_src: LazySrcLoc = block_scope.src(.{ .node_offset_var_decl_init = 0 });
4013 const decl_val = try sema.resolveFinalDeclValue(&block_scope, init_src, result_ref);4145 const decl_val = try sema.resolveFinalDeclValue(&block_scope, init_src, result_ref);
4014 const decl_ty = decl_val.typeOf(mod);4146 const decl_ty = decl_val.typeOf(mod);
40154147
...@@ -4143,7 +4275,7 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !SemaDeclResult {...@@ -4143,7 +4275,7 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !SemaDeclResult {
4143 }4275 }
41444276
4145 if (decl.is_exported) {4277 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) });
4147 if (is_inline) return sema.fail(&block_scope, export_src, "export of inline function", .{});4279 if (is_inline) return sema.fail(&block_scope, export_src, "export of inline function", .{});
4148 // The scope needs to have the decl in it.4280 // The scope needs to have the decl in it.
4149 try sema.analyzeExport(&block_scope, export_src, .{ .name = decl.name }, decl_index);4281 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...@@ -4697,14 +4829,13 @@ fn scanDecl(iter: *ScanDeclIter, decl_inst: Zir.Inst.Index) Allocator.Error!void
4697 const was_exported = decl.is_exported;4829 const was_exported = decl.is_exported;
4698 assert(decl.kind == kind); // ZIR tracking should preserve this4830 assert(decl.kind == kind); // ZIR tracking should preserve this
4699 decl.name = decl_name;4831 decl.name = decl_name;
4700 decl.src_node = inst_data.src_node;
4701 decl.src_line = line;4832 decl.src_line = line;
4702 decl.is_pub = declaration.flags.is_pub;4833 decl.is_pub = declaration.flags.is_pub;
4703 decl.is_exported = declaration.flags.is_export;4834 decl.is_exported = declaration.flags.is_export;
4704 break :decl_index .{ was_exported, decl_index };4835 break :decl_index .{ was_exported, decl_index };
4705 } else decl_index: {4836 } else decl_index: {
4706 // Create and set up a new Decl.4837 // 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);
4708 const new_decl = zcu.declPtr(new_decl_index);4839 const new_decl = zcu.declPtr(new_decl_index);
4709 new_decl.kind = kind;4840 new_decl.kind = kind;
4710 new_decl.name = decl_name;4841 new_decl.name = decl_name;
...@@ -4858,7 +4989,7 @@ pub fn analyzeFnBody(mod: *Module, func_index: InternPool.Index, arena: Allocato...@@ -4858,7 +4989,7 @@ pub fn analyzeFnBody(mod: *Module, func_index: InternPool.Index, arena: Allocato
48584989
4859 mod.intern_pool.removeDependenciesForDepender(gpa, InternPool.Depender.wrap(.{ .func = func_index }));4990 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);
4862 defer comptime_err_ret_trace.deinit();4993 defer comptime_err_ret_trace.deinit();
48634994
4864 // In the case of a generic function instance, this is the type of the4995 // 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...@@ -4913,6 +5044,14 @@ pub fn analyzeFnBody(mod: *Module, func_index: InternPool.Index, arena: Allocato
4913 .instructions = .{},5044 .instructions = .{},
4914 .inlining = null,5045 .inlining = null,
4915 .is_comptime = false,5046 .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 },
4916 };5055 };
4917 defer inner_block.instructions.deinit(gpa);5056 defer inner_block.instructions.deinit(gpa);
49185057
...@@ -4954,7 +5093,6 @@ pub fn analyzeFnBody(mod: *Module, func_index: InternPool.Index, arena: Allocato...@@ -4954,7 +5093,6 @@ pub fn analyzeFnBody(mod: *Module, func_index: InternPool.Index, arena: Allocato
4954 runtime_param_index += 1;5093 runtime_param_index += 1;
49555094
4956 const opt_opv = sema.typeHasOnePossibleValue(Type.fromInterned(param_ty)) catch |err| switch (err) {5095 const opt_opv = sema.typeHasOnePossibleValue(Type.fromInterned(param_ty)) catch |err| switch (err) {
4957 error.NeededSourceLocation => unreachable,
4958 error.GenericPoison => unreachable,5096 error.GenericPoison => unreachable,
4959 error.ComptimeReturn => unreachable,5097 error.ComptimeReturn => unreachable,
4960 error.ComptimeBreak => unreachable,5098 error.ComptimeBreak => unreachable,
...@@ -4988,7 +5126,6 @@ pub fn analyzeFnBody(mod: *Module, func_index: InternPool.Index, arena: Allocato...@@ -4988,7 +5126,6 @@ pub fn analyzeFnBody(mod: *Module, func_index: InternPool.Index, arena: Allocato
49885126
4989 sema.analyzeFnBody(&inner_block, fn_info.body) catch |err| switch (err) {5127 sema.analyzeFnBody(&inner_block, fn_info.body) catch |err| switch (err) {
4990 // TODO make these unreachable instead of @panic5128 // TODO make these unreachable instead of @panic
4991 error.NeededSourceLocation => @panic("zig compiler bug: NeededSourceLocation"),
4992 error.GenericPoison => @panic("zig compiler bug: GenericPoison"),5129 error.GenericPoison => @panic("zig compiler bug: GenericPoison"),
4993 error.ComptimeReturn => @panic("zig compiler bug: ComptimeReturn"),5130 error.ComptimeReturn => @panic("zig compiler bug: ComptimeReturn"),
4994 else => |e| return e,5131 else => |e| return e,
...@@ -5010,7 +5147,6 @@ pub fn analyzeFnBody(mod: *Module, func_index: InternPool.Index, arena: Allocato...@@ -5010,7 +5147,6 @@ pub fn analyzeFnBody(mod: *Module, func_index: InternPool.Index, arena: Allocato
5010 {5147 {
5011 sema.setupErrorReturnTrace(&inner_block, last_arg_index) catch |err| switch (err) {5148 sema.setupErrorReturnTrace(&inner_block, last_arg_index) catch |err| switch (err) {
5012 // TODO make these unreachable instead of @panic5149 // TODO make these unreachable instead of @panic
5013 error.NeededSourceLocation => @panic("zig compiler bug: NeededSourceLocation"),
5014 error.GenericPoison => @panic("zig compiler bug: GenericPoison"),5150 error.GenericPoison => @panic("zig compiler bug: GenericPoison"),
5015 error.ComptimeReturn => @panic("zig compiler bug: ComptimeReturn"),5151 error.ComptimeReturn => @panic("zig compiler bug: ComptimeReturn"),
5016 error.ComptimeBreak => @panic("zig compiler bug: ComptimeBreak"),5152 error.ComptimeBreak => @panic("zig compiler bug: ComptimeBreak"),
...@@ -5031,8 +5167,10 @@ pub fn analyzeFnBody(mod: *Module, func_index: InternPool.Index, arena: Allocato...@@ -5031,8 +5167,10 @@ pub fn analyzeFnBody(mod: *Module, func_index: InternPool.Index, arena: Allocato
5031 // state to success, so that "unable to resolve inferred error set" errors5167 // state to success, so that "unable to resolve inferred error set" errors
5032 // can be emitted here.5168 // can be emitted here.
5033 if (sema.fn_ret_ty_ies) |ies| {5169 if (sema.fn_ret_ty_ies) |ies| {
5034 sema.resolveInferredErrorSetPtr(&inner_block, LazySrcLoc.nodeOffset(0), ies) catch |err| switch (err) {5170 sema.resolveInferredErrorSetPtr(&inner_block, .{
5035 error.NeededSourceLocation => unreachable,5171 .base_node_inst = inner_block.src_base_inst,
5172 .offset = LazySrcLoc.Offset.nodeOffset(0),
5173 }, ies) catch |err| switch (err) {
5036 error.GenericPoison => unreachable,5174 error.GenericPoison => unreachable,
5037 error.ComptimeReturn => unreachable,5175 error.ComptimeReturn => unreachable,
5038 error.ComptimeBreak => unreachable,5176 error.ComptimeBreak => unreachable,
...@@ -5056,7 +5194,6 @@ pub fn analyzeFnBody(mod: *Module, func_index: InternPool.Index, arena: Allocato...@@ -5056,7 +5194,6 @@ pub fn analyzeFnBody(mod: *Module, func_index: InternPool.Index, arena: Allocato
5056 // so that dependencies on the function body will now be satisfied rather than5194 // so that dependencies on the function body will now be satisfied rather than
5057 // result in circular dependency errors.5195 // result in circular dependency errors.
5058 sema.resolveFnTypes(fn_ty) catch |err| switch (err) {5196 sema.resolveFnTypes(fn_ty) catch |err| switch (err) {
5059 error.NeededSourceLocation => unreachable,
5060 error.GenericPoison => unreachable,5197 error.GenericPoison => unreachable,
5061 error.ComptimeReturn => unreachable,5198 error.ComptimeReturn => unreachable,
5062 error.ComptimeBreak => unreachable,5199 error.ComptimeBreak => unreachable,
...@@ -5073,7 +5210,6 @@ pub fn analyzeFnBody(mod: *Module, func_index: InternPool.Index, arena: Allocato...@@ -5073,7 +5210,6 @@ pub fn analyzeFnBody(mod: *Module, func_index: InternPool.Index, arena: Allocato
5073 // the backends.5210 // the backends.
5074 for (sema.types_to_resolve.keys()) |ty| {5211 for (sema.types_to_resolve.keys()) |ty| {
5075 sema.resolveTypeFully(Type.fromInterned(ty)) catch |err| switch (err) {5212 sema.resolveTypeFully(Type.fromInterned(ty)) catch |err| switch (err) {
5076 error.NeededSourceLocation => unreachable,
5077 error.GenericPoison => unreachable,5213 error.GenericPoison => unreachable,
5078 error.ComptimeReturn => unreachable,5214 error.ComptimeReturn => unreachable,
5079 error.ComptimeBreak => unreachable,5215 error.ComptimeBreak => unreachable,
...@@ -5101,17 +5237,11 @@ pub fn destroyNamespace(mod: *Module, index: Namespace.Index) void {...@@ -5101,17 +5237,11 @@ pub fn destroyNamespace(mod: *Module, index: Namespace.Index) void {
5101 return mod.intern_pool.destroyNamespace(mod.gpa, index);5237 return mod.intern_pool.destroyNamespace(mod.gpa, index);
5102}5238}
51035239
5104pub fn allocateNewDecl(5240pub fn allocateNewDecl(zcu: *Zcu, namespace: Namespace.Index) !Decl.Index {
5105 mod: *Module,5241 const gpa = zcu.gpa;
5106 namespace: Namespace.Index,5242 const decl_index = try zcu.intern_pool.createDecl(gpa, .{
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, .{
5112 .name = undefined,5243 .name = undefined,
5113 .src_namespace = namespace,5244 .src_namespace = namespace,
5114 .src_node = src_node,
5115 .src_line = undefined,5245 .src_line = undefined,
5116 .has_tv = false,5246 .has_tv = false,
5117 .owns_tv = false,5247 .owns_tv = false,
...@@ -5126,10 +5256,10 @@ pub fn allocateNewDecl(...@@ -5126,10 +5256,10 @@ pub fn allocateNewDecl(
5126 .kind = .anon,5256 .kind = .anon,
5127 });5257 });
51285258
5129 if (mod.emit_h) |mod_emit_h| {5259 if (zcu.emit_h) |zcu_emit_h| {
5130 if (@intFromEnum(decl_index) >= mod_emit_h.allocated_emit_h.len) {5260 if (@intFromEnum(decl_index) >= zcu_emit_h.allocated_emit_h.len) {
5131 try mod_emit_h.allocated_emit_h.append(gpa, .{});5261 try zcu_emit_h.allocated_emit_h.append(gpa, .{});
5132 assert(@intFromEnum(decl_index) == mod_emit_h.allocated_emit_h.len);5262 assert(@intFromEnum(decl_index) == zcu_emit_h.allocated_emit_h.len);
5133 }5263 }
5134 }5264 }
51355265
...@@ -5223,376 +5353,6 @@ fn lockAndClearFileCompileError(mod: *Module, file: *File) void {...@@ -5223,376 +5353,6 @@ fn lockAndClearFileCompileError(mod: *Module, file: *File) void {
5223 }5353 }
5224}5354}
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
5596/// Called from `Compilation.update`, after everything is done, just before5356/// Called from `Compilation.update`, after everything is done, just before
5597/// reporting compile errors. In this function we emit exported symbol collision5357/// reporting compile errors. In this function we emit exported symbol collision
5598/// errors and communicate exported symbols to the linker backend.5358/// errors and communicate exported symbols to the linker backend.
...@@ -5826,7 +5586,7 @@ pub fn linkerUpdateDecl(zcu: *Zcu, decl_index: Decl.Index) !void {...@@ -5826,7 +5586,7 @@ pub fn linkerUpdateDecl(zcu: *Zcu, decl_index: Decl.Index) !void {
5826 try zcu.failed_decls.ensureUnusedCapacity(gpa, 1);5586 try zcu.failed_decls.ensureUnusedCapacity(gpa, 1);
5827 zcu.failed_decls.putAssumeCapacityNoClobber(decl_index, try ErrorMsg.create(5587 zcu.failed_decls.putAssumeCapacityNoClobber(decl_index, try ErrorMsg.create(
5828 gpa,5588 gpa,
5829 decl.srcLoc(zcu),5589 decl.navSrcLoc(zcu).upgrade(zcu),
5830 "unable to codegen: {s}",5590 "unable to codegen: {s}",
5831 .{@errorName(err)},5591 .{@errorName(err)},
5832 ));5592 ));
...@@ -5857,7 +5617,7 @@ fn reportRetryableFileError(...@@ -5857,7 +5617,7 @@ fn reportRetryableFileError(
5857 mod.gpa,5617 mod.gpa,
5858 .{5618 .{
5859 .file_scope = file,5619 .file_scope = file,
5860 .parent_decl_node = 0,5620 .base_node = 0,
5861 .lazy = .entire_file,5621 .lazy = .entire_file,
5862 },5622 },
5863 format,5623 format,
...@@ -6432,27 +6192,6 @@ pub fn funcInfo(mod: *Module, func_index: InternPool.Index) InternPool.Key.Func...@@ -6432,27 +6192,6 @@ pub fn funcInfo(mod: *Module, func_index: InternPool.Index) InternPool.Key.Func
6432 return mod.intern_pool.indexToKey(func_index).func;6192 return mod.intern_pool.indexToKey(func_index).func;
6433}6193}
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
6456pub fn toEnum(mod: *Module, comptime E: type, val: Value) E {6195pub fn toEnum(mod: *Module, comptime E: type, val: Value) E {
6457 return mod.intern_pool.toEnum(E, val.toIntern());6196 return mod.intern_pool.toEnum(E, val.toIntern());
6458}6197}
src/RangeSet.zig+4-4
...@@ -7,7 +7,7 @@ const Type = @import("type.zig").Type;...@@ -7,7 +7,7 @@ const Type = @import("type.zig").Type;
7const Value = @import("Value.zig");7const Value = @import("Value.zig");
8const Module = @import("Module.zig");8const Module = @import("Module.zig");
9const RangeSet = @This();9const RangeSet = @This();
10const SwitchProngSrc = @import("Module.zig").SwitchProngSrc;10const LazySrcLoc = @import("Module.zig").LazySrcLoc;
1111
12ranges: std.ArrayList(Range),12ranges: std.ArrayList(Range),
13module: *Module,13module: *Module,
...@@ -15,7 +15,7 @@ module: *Module,...@@ -15,7 +15,7 @@ module: *Module,
15pub const Range = struct {15pub const Range = struct {
16 first: InternPool.Index,16 first: InternPool.Index,
17 last: InternPool.Index,17 last: InternPool.Index,
18 src: SwitchProngSrc,18 src: LazySrcLoc,
19};19};
2020
21pub fn init(allocator: std.mem.Allocator, module: *Module) RangeSet {21pub fn init(allocator: std.mem.Allocator, module: *Module) RangeSet {
...@@ -33,8 +33,8 @@ pub fn add(...@@ -33,8 +33,8 @@ pub fn add(
33 self: *RangeSet,33 self: *RangeSet,
34 first: InternPool.Index,34 first: InternPool.Index,
35 last: InternPool.Index,35 last: InternPool.Index,
36 src: SwitchProngSrc,36 src: LazySrcLoc,
37) !?SwitchProngSrc {37) !?LazySrcLoc {
38 const mod = self.module;38 const mod = self.module;
39 const ip = &mod.intern_pool;39 const ip = &mod.intern_pool;
4040
src/Sema.zig+1497-1669
...@@ -34,7 +34,7 @@ func_index: InternPool.Index,...@@ -34,7 +34,7 @@ func_index: InternPool.Index,
34func_is_naked: bool,34func_is_naked: bool,
35/// Used to restore the error return trace when returning a non-error from a function.35/// Used to restore the error return trace when returning a non-error from a function.
36error_return_trace_index_on_fn_entry: Air.Inst.Ref = .none,36error_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),
38/// When semantic analysis needs to know the return type of the function whose body38/// When semantic analysis needs to know the return type of the function whose body
39/// is being analyzed, this `Type` should be used instead of going through `func`.39/// is being analyzed, this `Type` should be used instead of going through `func`.
40/// This will correctly handle the case of a comptime/inline function call of a40/// This will correctly handle the case of a comptime/inline function call of a
...@@ -65,9 +65,7 @@ generic_owner: InternPool.Index = .none,...@@ -65,9 +65,7 @@ generic_owner: InternPool.Index = .none,
65/// instantiation callsite so that compile errors on the parameter types of the65/// instantiation callsite so that compile errors on the parameter types of the
66/// instantiation can point back to the instantiation site in addition to the66/// instantiation can point back to the instantiation site in addition to the
67/// declaration site.67/// declaration site.
68generic_call_src: LazySrcLoc = .unneeded,68generic_call_src: LazySrcLoc = LazySrcLoc.unneeded,
69/// Corresponds to `generic_call_src`.
70generic_call_decl: InternPool.OptionalDeclIndex = .none,
71/// The key is types that must be fully resolved prior to machine code69/// The key is types that must be fully resolved prior to machine code
72/// generation pass. Types are added to this set when resolving them70/// generation pass. Types are added to this set when resolving them
73/// immediately could cause a dependency loop, but they do need to be resolved71/// immediately could cause a dependency loop, but they do need to be resolved
...@@ -131,7 +129,6 @@ const MaybeComptimeAlloc = struct {...@@ -131,7 +129,6 @@ const MaybeComptimeAlloc = struct {
131 /// If the instruction is one of these three tags, `src` may be `.unneeded`.129 /// If the instruction is one of these three tags, `src` may be `.unneeded`.
132 stores: std.MultiArrayList(struct {130 stores: std.MultiArrayList(struct {
133 inst: Air.Inst.Index,131 inst: Air.Inst.Index,
134 src_decl: InternPool.DeclIndex,
135 src: LazySrcLoc,132 src: LazySrcLoc,
136 }) = .{},133 }) = .{},
137};134};
...@@ -361,8 +358,8 @@ pub const Block = struct {...@@ -361,8 +358,8 @@ pub const Block = struct {
361 label: ?*Label = null,358 label: ?*Label = null,
362 inlining: ?*Inlining,359 inlining: ?*Inlining,
363 /// If runtime_index is not 0 then one of these is guaranteed to be non null.360 /// If runtime_index is not 0 then one of these is guaranteed to be non null.
364 runtime_cond: ?Module.SrcLoc = null,361 runtime_cond: ?LazySrcLoc = null,
365 runtime_loop: ?Module.SrcLoc = null,362 runtime_loop: ?LazySrcLoc = null,
366 /// This Decl is the Decl according to the Zig source code corresponding to this Block.363 /// This Decl is the Decl according to the Zig source code corresponding to this Block.
367 /// This can vary during inline or comptime function calls. See `Sema.owner_decl`364 /// This can vary during inline or comptime function calls. See `Sema.owner_decl`
368 /// for the one that will be the same for all Block instances.365 /// for the one that will be the same for all Block instances.
...@@ -395,25 +392,39 @@ pub const Block = struct {...@@ -395,25 +392,39 @@ pub const Block = struct {
395 /// `block` in order for codegen to match lexical scoping for debug vars.392 /// `block` in order for codegen to match lexical scoping for debug vars.
396 need_debug_scope: ?*bool = null,393 need_debug_scope: ?*bool = null,
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
400 fn nodeOffset(block: Block, node_offset: i32) LazySrcLoc {415 fn nodeOffset(block: Block, node_offset: i32) LazySrcLoc {
401 _ = block;416 return block.src(LazySrcLoc.Offset.nodeOffset(node_offset));
402 return LazySrcLoc.nodeOffset(node_offset);
403 }417 }
404418
405 fn tokenOffset(block: Block, tok_offset: u32) LazySrcLoc {419 fn tokenOffset(block: Block, tok_offset: u32) LazySrcLoc {
406 _ = block;420 return block.src(.{ .token_offset = tok_offset });
407 return .{ .token_offset = tok_offset };
408 }421 }
409422
410 const ComptimeReason = union(enum) {423 const ComptimeReason = union(enum) {
411 c_import: struct {424 c_import: struct {
412 block: *Block,
413 src: LazySrcLoc,425 src: LazySrcLoc,
414 },426 },
415 comptime_ret_ty: struct {427 comptime_ret_ty: struct {
416 block: *Block,
417 func: Air.Inst.Ref,428 func: Air.Inst.Ref,
418 func_src: LazySrcLoc,429 func_src: LazySrcLoc,
419 return_ty: Type,430 return_ty: Type,
...@@ -425,27 +436,23 @@ pub const Block = struct {...@@ -425,27 +436,23 @@ pub const Block = struct {
425 const prefix = "expression is evaluated at comptime because ";436 const prefix = "expression is evaluated at comptime because ";
426 switch (cr) {437 switch (cr) {
427 .c_import => |ci| {438 .c_import => |ci| {
428 try sema.errNote(ci.block, ci.src, parent, prefix ++ "it is inside a @cImport", .{});439 try sema.errNote(ci.src, parent, prefix ++ "it is inside a @cImport", .{});
429 },440 },
430 .comptime_ret_ty => |rt| {441 .comptime_ret_ty => |rt| {
431 const src_loc = if (try sema.funcDeclSrc(rt.func)) |fn_decl| blk: {442 const ret_ty_src: LazySrcLoc = if (try sema.funcDeclSrc(rt.func)) |fn_decl| .{
432 var src_loc = fn_decl.srcLoc(mod);443 .base_node_inst = fn_decl.zir_decl_index.unwrap().?,
433 src_loc.lazy = .{ .node_offset_fn_type_ret_ty = 0 };444 .offset = .{ .node_offset_fn_type_ret_ty = 0 },
434 break :blk src_loc;445 } else rt.func_src;
435 } else blk: {
436 const src_decl = mod.declPtr(rt.block.src_decl);
437 break :blk src_decl.toSrcLoc(rt.func_src, mod);
438 };
439 if (rt.return_ty.isGenericPoison()) {446 if (rt.return_ty.isGenericPoison()) {
440 return mod.errNoteNonLazy(src_loc, parent, prefix ++ "the generic function was instantiated with a comptime-only return type", .{});447 return sema.errNote(ret_ty_src, parent, prefix ++ "the generic function was instantiated with a comptime-only return type", .{});
441 }448 }
442 try mod.errNoteNonLazy(449 try sema.errNote(
443 src_loc,450 ret_ty_src,
444 parent,451 parent,
445 prefix ++ "the function returns a comptime-only type '{}'",452 prefix ++ "the function returns a comptime-only type '{}'",
446 .{rt.return_ty.fmt(mod)},453 .{rt.return_ty.fmt(mod)},
447 );454 );
448 try sema.explainWhyTypeIsComptime(parent, src_loc, rt.return_ty);455 try sema.explainWhyTypeIsComptime(parent, ret_ty_src, rt.return_ty);
449 },456 },
450 }457 }
451 }458 }
...@@ -525,6 +532,7 @@ pub const Block = struct {...@@ -525,6 +532,7 @@ pub const Block = struct {
525 .c_import_buf = parent.c_import_buf,532 .c_import_buf = parent.c_import_buf,
526 .error_return_trace_index = parent.error_return_trace_index,533 .error_return_trace_index = parent.error_return_trace_index,
527 .need_debug_scope = parent.need_debug_scope,534 .need_debug_scope = parent.need_debug_scope,
535 .src_base_inst = parent.src_base_inst,
528 };536 };
529 }537 }
530538
...@@ -815,14 +823,6 @@ pub const Block = struct {...@@ -815,14 +823,6 @@ pub const Block = struct {
815 return result_index;823 return result_index;
816 }824 }
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
826 pub fn ownerModule(block: Block) *Package.Module {826 pub fn ownerModule(block: Block) *Package.Module {
827 const zcu = block.sema.mod;827 const zcu = block.sema.mod;
828 return zcu.namespacePtr(block.namespace).file_scope.mod;828 return zcu.namespacePtr(block.namespace).file_scope.mod;
...@@ -1237,7 +1237,7 @@ fn analyzeBodyInner(...@@ -1237,7 +1237,7 @@ fn analyzeBodyInner(
1237 .@"asm" => try sema.zirAsm( block, extended, false),1237 .@"asm" => try sema.zirAsm( block, extended, false),
1238 .asm_expr => try sema.zirAsm( block, extended, true),1238 .asm_expr => try sema.zirAsm( block, extended, true),
1239 .typeof_peer => try sema.zirTypeofPeer( block, extended, inst),1239 .typeof_peer => try sema.zirTypeofPeer( block, extended, inst),
1240 .compile_log => try sema.zirCompileLog( extended),1240 .compile_log => try sema.zirCompileLog( block, extended),
1241 .min_multi => try sema.zirMinMaxMulti( block, extended, .min),1241 .min_multi => try sema.zirMinMaxMulti( block, extended, .min),
1242 .max_multi => try sema.zirMinMaxMulti( block, extended, .max),1242 .max_multi => try sema.zirMinMaxMulti( block, extended, .max),
1243 .add_with_overflow => try sema.zirOverflowArithmetic(block, extended, extended.opcode),1243 .add_with_overflow => try sema.zirOverflowArithmetic(block, extended, extended.opcode),
...@@ -1475,10 +1475,9 @@ fn analyzeBodyInner(...@@ -1475,10 +1475,9 @@ fn analyzeBodyInner(
1475 if (@intFromEnum(target_runtime_index) < @intFromEnum(block.runtime_index)) {1475 if (@intFromEnum(target_runtime_index) < @intFromEnum(block.runtime_index)) {
1476 const runtime_src = block.runtime_cond orelse block.runtime_loop.?;1476 const runtime_src = block.runtime_cond orelse block.runtime_loop.?;
1477 const msg = msg: {1477 const msg = msg: {
1478 const msg = try sema.errMsg(block, src, "comptime control flow inside runtime block", .{});1478 const msg = try sema.errMsg(src, "comptime control flow inside runtime block", .{});
1479 errdefer msg.destroy(sema.gpa);1479 errdefer msg.destroy(sema.gpa);
14801480 try sema.errNote(runtime_src, msg, "runtime control flow here", .{});
1481 try mod.errNoteNonLazy(runtime_src, msg, "runtime control flow here", .{});
1482 break :msg msg;1481 break :msg msg;
1483 };1482 };
1484 return sema.failWithOwnedErrorMsg(block, msg);1483 return sema.failWithOwnedErrorMsg(block, msg);
...@@ -1522,7 +1521,7 @@ fn analyzeBodyInner(...@@ -1522,7 +1521,7 @@ fn analyzeBodyInner(
1522 .repeat => {1521 .repeat => {
1523 if (block.is_comptime) {1522 if (block.is_comptime) {
1524 // Send comptime control flow back to the beginning of this block.1523 // Send comptime control flow back to the beginning of this block.
1525 const src = LazySrcLoc.nodeOffset(datas[@intFromEnum(inst)].node);1524 const src = block.nodeOffset(datas[@intFromEnum(inst)].node);
1526 try sema.emitBackwardBranch(block, src);1525 try sema.emitBackwardBranch(block, src);
1527 i = 0;1526 i = 0;
1528 continue;1527 continue;
...@@ -1535,7 +1534,7 @@ fn analyzeBodyInner(...@@ -1535,7 +1534,7 @@ fn analyzeBodyInner(
1535 },1534 },
1536 .repeat_inline => {1535 .repeat_inline => {
1537 // Send comptime control flow back to the beginning of this block.1536 // Send comptime control flow back to the beginning of this block.
1538 const src = LazySrcLoc.nodeOffset(datas[@intFromEnum(inst)].node);1537 const src = block.nodeOffset(datas[@intFromEnum(inst)].node);
1539 try sema.emitBackwardBranch(block, src);1538 try sema.emitBackwardBranch(block, src);
1540 i = 0;1539 i = 0;
1541 continue;1540 continue;
...@@ -1705,7 +1704,7 @@ fn analyzeBodyInner(...@@ -1705,7 +1704,7 @@ fn analyzeBodyInner(
1705 }1704 }
1706 // Same as condbr_inline. TODO https://github.com/ziglang/zig/issues/82201705 // Same as condbr_inline. TODO https://github.com/ziglang/zig/issues/8220
1707 const inst_data = datas[@intFromEnum(inst)].pl_node;1706 const inst_data = datas[@intFromEnum(inst)].pl_node;
1708 const cond_src: LazySrcLoc = .{ .node_offset_if_cond = inst_data.src_node };1707 const cond_src = block.src(.{ .node_offset_if_cond = inst_data.src_node });
1709 const extra = sema.code.extraData(Zir.Inst.CondBr, inst_data.payload_index);1708 const extra = sema.code.extraData(Zir.Inst.CondBr, inst_data.payload_index);
1710 const then_body = sema.code.bodySlice(extra.end, extra.data.then_body_len);1709 const then_body = sema.code.bodySlice(extra.end, extra.data.then_body_len);
1711 const else_body = sema.code.bodySlice(1710 const else_body = sema.code.bodySlice(
...@@ -1725,7 +1724,7 @@ fn analyzeBodyInner(...@@ -1725,7 +1724,7 @@ fn analyzeBodyInner(
1725 },1724 },
1726 .condbr_inline => blk: {1725 .condbr_inline => blk: {
1727 const inst_data = datas[@intFromEnum(inst)].pl_node;1726 const inst_data = datas[@intFromEnum(inst)].pl_node;
1728 const cond_src: LazySrcLoc = .{ .node_offset_if_cond = inst_data.src_node };1727 const cond_src = block.src(.{ .node_offset_if_cond = inst_data.src_node });
1729 const extra = sema.code.extraData(Zir.Inst.CondBr, inst_data.payload_index);1728 const extra = sema.code.extraData(Zir.Inst.CondBr, inst_data.payload_index);
1730 const then_body = sema.code.bodySlice(extra.end, extra.data.then_body_len);1729 const then_body = sema.code.bodySlice(extra.end, extra.data.then_body_len);
1731 const else_body = sema.code.bodySlice(1730 const else_body = sema.code.bodySlice(
...@@ -1749,7 +1748,7 @@ fn analyzeBodyInner(...@@ -1749,7 +1748,7 @@ fn analyzeBodyInner(
1749 if (!block.is_comptime) break :blk try sema.zirTry(block, inst);1748 if (!block.is_comptime) break :blk try sema.zirTry(block, inst);
1750 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;1749 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
1751 const src = block.nodeOffset(inst_data.src_node);1750 const src = block.nodeOffset(inst_data.src_node);
1752 const operand_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };1751 const operand_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node });
1753 const extra = sema.code.extraData(Zir.Inst.Try, inst_data.payload_index);1752 const extra = sema.code.extraData(Zir.Inst.Try, inst_data.payload_index);
1754 const inline_body = sema.code.bodySlice(extra.end, extra.data.body_len);1753 const inline_body = sema.code.bodySlice(extra.end, extra.data.body_len);
1755 const err_union = try sema.resolveInst(extra.data.operand);1754 const err_union = try sema.resolveInst(extra.data.operand);
...@@ -1775,7 +1774,7 @@ fn analyzeBodyInner(...@@ -1775,7 +1774,7 @@ fn analyzeBodyInner(
1775 if (!block.is_comptime) break :blk try sema.zirTryPtr(block, inst);1774 if (!block.is_comptime) break :blk try sema.zirTryPtr(block, inst);
1776 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;1775 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
1777 const src = block.nodeOffset(inst_data.src_node);1776 const src = block.nodeOffset(inst_data.src_node);
1778 const operand_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };1777 const operand_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node });
1779 const extra = sema.code.extraData(Zir.Inst.Try, inst_data.payload_index);1778 const extra = sema.code.extraData(Zir.Inst.Try, inst_data.payload_index);
1780 const inline_body = sema.code.bodySlice(extra.end, extra.data.body_len);1779 const inline_body = sema.code.bodySlice(extra.end, extra.data.body_len);
1781 const operand = try sema.resolveInst(extra.data.operand);1780 const operand = try sema.resolveInst(extra.data.operand);
...@@ -1939,14 +1938,14 @@ fn resolveDestType(...@@ -1939,14 +1938,14 @@ fn resolveDestType(
1939 // Cast builtins use their result type as the destination type, but1938 // Cast builtins use their result type as the destination type, but
1940 // it could be an anytype argument, which we can't catch in AstGen.1939 // it could be an anytype argument, which we can't catch in AstGen.
1941 const msg = msg: {1940 const msg = msg: {
1942 const msg = try sema.errMsg(block, src, "{s} must have a known result type", .{builtin_name});1941 const msg = try sema.errMsg(src, "{s} must have a known result type", .{builtin_name});
1943 errdefer msg.destroy(sema.gpa);1942 errdefer msg.destroy(sema.gpa);
1944 switch (sema.genericPoisonReason(block, zir_ref)) {1943 switch (sema.genericPoisonReason(block, zir_ref)) {
1945 .anytype_param => |call_src| try sema.errNote(block, call_src, msg, "result type is unknown due to anytype parameter", .{}),1944 .anytype_param => |call_src| try sema.errNote(call_src, msg, "result type is unknown due to anytype parameter", .{}),
1946 .anyopaque_ptr => |ptr_src| try sema.errNote(block, ptr_src, msg, "result type is unknown due to opaque pointer type", .{}),1945 .anyopaque_ptr => |ptr_src| try sema.errNote(ptr_src, msg, "result type is unknown due to opaque pointer type", .{}),
1947 .unknown => {},1946 .unknown => {},
1948 }1947 }
1949 try sema.errNote(block, src, msg, "use @as to provide explicit result type", .{});1948 try sema.errNote(src, msg, "use @as to provide explicit result type", .{});
1950 break :msg msg;1949 break :msg msg;
1951 };1950 };
1952 return sema.failWithOwnedErrorMsg(block, msg);1951 return sema.failWithOwnedErrorMsg(block, msg);
...@@ -2051,7 +2050,7 @@ pub fn setupErrorReturnTrace(sema: *Sema, block: *Block, last_arg_index: usize)...@@ -2051,7 +2050,7 @@ pub fn setupErrorReturnTrace(sema: *Sema, block: *Block, last_arg_index: usize)
2051 var err_trace_block = block.makeSubBlock();2050 var err_trace_block = block.makeSubBlock();
2052 defer err_trace_block.instructions.deinit(gpa);2051 defer err_trace_block.instructions.deinit(gpa);
20532052
2054 const src: LazySrcLoc = .unneeded;2053 const src: LazySrcLoc = LazySrcLoc.unneeded;
20552054
2056 // var addrs: [err_return_trace_addr_count]usize = undefined;2055 // var addrs: [err_return_trace_addr_count]usize = undefined;
2057 const err_return_trace_addr_count = 32;2056 const err_return_trace_addr_count = 32;
...@@ -2212,9 +2211,9 @@ pub fn resolveFinalDeclValue(...@@ -2212,9 +2211,9 @@ pub fn resolveFinalDeclValue(
22122211
2213fn failWithNeededComptime(sema: *Sema, block: *Block, src: LazySrcLoc, reason: NeededComptimeReason) CompileError {2212fn failWithNeededComptime(sema: *Sema, block: *Block, src: LazySrcLoc, reason: NeededComptimeReason) CompileError {
2214 const msg = msg: {2213 const msg = msg: {
2215 const msg = try sema.errMsg(block, src, "unable to resolve comptime value", .{});2214 const msg = try sema.errMsg(src, "unable to resolve comptime value", .{});
2216 errdefer msg.destroy(sema.gpa);2215 errdefer msg.destroy(sema.gpa);
2217 try sema.errNote(block, src, msg, "{s}", .{reason.needed_comptime_reason});2216 try sema.errNote(src, msg, "{s}", .{reason.needed_comptime_reason});
22182217
2219 if (reason.block_comptime_reason) |block_comptime_reason| {2218 if (reason.block_comptime_reason) |block_comptime_reason| {
2220 try block_comptime_reason.explain(sema, msg);2219 try block_comptime_reason.explain(sema, msg);
...@@ -2241,12 +2240,12 @@ fn failWithModRemNegative(sema: *Sema, block: *Block, src: LazySrcLoc, lhs_ty: T...@@ -2241,12 +2240,12 @@ fn failWithModRemNegative(sema: *Sema, block: *Block, src: LazySrcLoc, lhs_ty: T
2241fn failWithExpectedOptionalType(sema: *Sema, block: *Block, src: LazySrcLoc, non_optional_ty: Type) CompileError {2240fn failWithExpectedOptionalType(sema: *Sema, block: *Block, src: LazySrcLoc, non_optional_ty: Type) CompileError {
2242 const mod = sema.mod;2241 const mod = sema.mod;
2243 const msg = msg: {2242 const msg = msg: {
2244 const msg = try sema.errMsg(block, src, "expected optional type, found '{}'", .{2243 const msg = try sema.errMsg(src, "expected optional type, found '{}'", .{
2245 non_optional_ty.fmt(mod),2244 non_optional_ty.fmt(mod),
2246 });2245 });
2247 errdefer msg.destroy(sema.gpa);2246 errdefer msg.destroy(sema.gpa);
2248 if (non_optional_ty.zigTypeTag(mod) == .ErrorUnion) {2247 if (non_optional_ty.zigTypeTag(mod) == .ErrorUnion) {
2249 try sema.errNote(block, src, msg, "consider using 'try', 'catch', or 'if'", .{});2248 try sema.errNote(src, msg, "consider using 'try', 'catch', or 'if'", .{});
2250 }2249 }
2251 try addDeclaredHereNote(sema, msg, non_optional_ty);2250 try addDeclaredHereNote(sema, msg, non_optional_ty);
2252 break :msg msg;2251 break :msg msg;
...@@ -2257,12 +2256,12 @@ fn failWithExpectedOptionalType(sema: *Sema, block: *Block, src: LazySrcLoc, non...@@ -2257,12 +2256,12 @@ fn failWithExpectedOptionalType(sema: *Sema, block: *Block, src: LazySrcLoc, non
2257fn failWithArrayInitNotSupported(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) CompileError {2256fn failWithArrayInitNotSupported(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) CompileError {
2258 const mod = sema.mod;2257 const mod = sema.mod;
2259 const msg = msg: {2258 const msg = msg: {
2260 const msg = try sema.errMsg(block, src, "type '{}' does not support array initialization syntax", .{2259 const msg = try sema.errMsg(src, "type '{}' does not support array initialization syntax", .{
2261 ty.fmt(mod),2260 ty.fmt(mod),
2262 });2261 });
2263 errdefer msg.destroy(sema.gpa);2262 errdefer msg.destroy(sema.gpa);
2264 if (ty.isSlice(mod)) {2263 if (ty.isSlice(mod)) {
2265 try sema.errNote(block, src, msg, "inferred array length is specified with an underscore: '[_]{}'", .{ty.elemType2(mod).fmt(mod)});2264 try sema.errNote(src, msg, "inferred array length is specified with an underscore: '[_]{}'", .{ty.elemType2(mod).fmt(mod)});
2266 }2265 }
2267 break :msg msg;2266 break :msg msg;
2268 };2267 };
...@@ -2291,11 +2290,11 @@ fn failWithIntegerOverflow(sema: *Sema, block: *Block, src: LazySrcLoc, int_ty:...@@ -2291,11 +2290,11 @@ fn failWithIntegerOverflow(sema: *Sema, block: *Block, src: LazySrcLoc, int_ty:
2291 const zcu = sema.mod;2290 const zcu = sema.mod;
2292 if (int_ty.zigTypeTag(zcu) == .Vector) {2291 if (int_ty.zigTypeTag(zcu) == .Vector) {
2293 const msg = msg: {2292 const msg = msg: {
2294 const msg = try sema.errMsg(block, src, "overflow of vector type '{}' with value '{}'", .{2293 const msg = try sema.errMsg(src, "overflow of vector type '{}' with value '{}'", .{
2295 int_ty.fmt(zcu), val.fmtValue(zcu, sema),2294 int_ty.fmt(zcu), val.fmtValue(zcu, sema),
2296 });2295 });
2297 errdefer msg.destroy(sema.gpa);2296 errdefer msg.destroy(sema.gpa);
2298 try sema.errNote(block, src, msg, "when computing vector element at index '{d}'", .{vector_index});2297 try sema.errNote(src, msg, "when computing vector element at index '{d}'", .{vector_index});
2299 break :msg msg;2298 break :msg msg;
2300 };2299 };
2301 return sema.failWithOwnedErrorMsg(block, msg);2300 return sema.failWithOwnedErrorMsg(block, msg);
...@@ -2308,15 +2307,14 @@ fn failWithIntegerOverflow(sema: *Sema, block: *Block, src: LazySrcLoc, int_ty:...@@ -2308,15 +2307,14 @@ fn failWithIntegerOverflow(sema: *Sema, block: *Block, src: LazySrcLoc, int_ty:
2308fn failWithInvalidComptimeFieldStore(sema: *Sema, block: *Block, init_src: LazySrcLoc, container_ty: Type, field_index: usize) CompileError {2307fn failWithInvalidComptimeFieldStore(sema: *Sema, block: *Block, init_src: LazySrcLoc, container_ty: Type, field_index: usize) CompileError {
2309 const mod = sema.mod;2308 const mod = sema.mod;
2310 const msg = msg: {2309 const msg = msg: {
2311 const msg = try sema.errMsg(block, init_src, "value stored in comptime field does not match the default value of the field", .{});2310 const msg = try sema.errMsg(init_src, "value stored in comptime field does not match the default value of the field", .{});
2312 errdefer msg.destroy(sema.gpa);2311 errdefer msg.destroy(sema.gpa);
23132312
2314 const struct_type = mod.typeToStruct(container_ty) orelse break :msg msg;2313 const struct_type = mod.typeToStruct(container_ty) orelse break :msg msg;
2315 const default_value_src = mod.fieldSrcLoc(struct_type.decl.unwrap().?, .{2314 try sema.errNote(.{
2316 .index = field_index,2315 .base_node_inst = struct_type.zir_index.unwrap().?,
2317 .range = .value,2316 .offset = .{ .container_field_value = @intCast(field_index) },
2318 });2317 }, msg, "default value set here", .{});
2319 try mod.errNoteNonLazy(default_value_src, msg, "default value set here", .{});
2320 break :msg msg;2318 break :msg msg;
2321 };2319 };
2322 return sema.failWithOwnedErrorMsg(block, msg);2320 return sema.failWithOwnedErrorMsg(block, msg);
...@@ -2324,7 +2322,7 @@ fn failWithInvalidComptimeFieldStore(sema: *Sema, block: *Block, init_src: LazyS...@@ -2324,7 +2322,7 @@ fn failWithInvalidComptimeFieldStore(sema: *Sema, block: *Block, init_src: LazyS
23242322
2325fn failWithUseOfAsync(sema: *Sema, block: *Block, src: LazySrcLoc) CompileError {2323fn failWithUseOfAsync(sema: *Sema, block: *Block, src: LazySrcLoc) CompileError {
2326 const msg = msg: {2324 const msg = msg: {
2327 const msg = try sema.errMsg(block, src, "async has not been implemented in the self-hosted compiler yet", .{});2325 const msg = try sema.errMsg(src, "async has not been implemented in the self-hosted compiler yet", .{});
2328 errdefer msg.destroy(sema.gpa);2326 errdefer msg.destroy(sema.gpa);
2329 break :msg msg;2327 break :msg msg;
2330 };2328 };
...@@ -2345,9 +2343,9 @@ fn failWithInvalidFieldAccess(...@@ -2345,9 +2343,9 @@ fn failWithInvalidFieldAccess(
2345 const child_ty = inner_ty.optionalChild(mod);2343 const child_ty = inner_ty.optionalChild(mod);
2346 if (!typeSupportsFieldAccess(mod, child_ty, field_name)) break :opt;2344 if (!typeSupportsFieldAccess(mod, child_ty, field_name)) break :opt;
2347 const msg = msg: {2345 const msg = msg: {
2348 const msg = try sema.errMsg(block, src, "optional type '{}' does not support field access", .{object_ty.fmt(sema.mod)});2346 const msg = try sema.errMsg(src, "optional type '{}' does not support field access", .{object_ty.fmt(sema.mod)});
2349 errdefer msg.destroy(sema.gpa);2347 errdefer msg.destroy(sema.gpa);
2350 try sema.errNote(block, src, msg, "consider using '.?', 'orelse', or 'if'", .{});2348 try sema.errNote(src, msg, "consider using '.?', 'orelse', or 'if'", .{});
2351 break :msg msg;2349 break :msg msg;
2352 };2350 };
2353 return sema.failWithOwnedErrorMsg(block, msg);2351 return sema.failWithOwnedErrorMsg(block, msg);
...@@ -2355,9 +2353,9 @@ fn failWithInvalidFieldAccess(...@@ -2355,9 +2353,9 @@ fn failWithInvalidFieldAccess(
2355 const child_ty = inner_ty.errorUnionPayload(mod);2353 const child_ty = inner_ty.errorUnionPayload(mod);
2356 if (!typeSupportsFieldAccess(mod, child_ty, field_name)) break :err;2354 if (!typeSupportsFieldAccess(mod, child_ty, field_name)) break :err;
2357 const msg = msg: {2355 const msg = msg: {
2358 const msg = try sema.errMsg(block, src, "error union type '{}' does not support field access", .{object_ty.fmt(sema.mod)});2356 const msg = try sema.errMsg(src, "error union type '{}' does not support field access", .{object_ty.fmt(sema.mod)});
2359 errdefer msg.destroy(sema.gpa);2357 errdefer msg.destroy(sema.gpa);
2360 try sema.errNote(block, src, msg, "consider using 'try', 'catch', or 'if'", .{});2358 try sema.errNote(src, msg, "consider using 'try', 'catch', or 'if'", .{});
2361 break :msg msg;2359 break :msg msg;
2362 };2360 };
2363 return sema.failWithOwnedErrorMsg(block, msg);2361 return sema.failWithOwnedErrorMsg(block, msg);
...@@ -2390,11 +2388,11 @@ fn failWithComptimeErrorRetTrace(...@@ -2390,11 +2388,11 @@ fn failWithComptimeErrorRetTrace(
2390) CompileError {2388) CompileError {
2391 const mod = sema.mod;2389 const mod = sema.mod;
2392 const msg = msg: {2390 const msg = msg: {
2393 const msg = try sema.errMsg(block, src, "caught unexpected error '{}'", .{name.fmt(&mod.intern_pool)});2391 const msg = try sema.errMsg(src, "caught unexpected error '{}'", .{name.fmt(&mod.intern_pool)});
2394 errdefer msg.destroy(sema.gpa);2392 errdefer msg.destroy(sema.gpa);
23952393
2396 for (sema.comptime_err_ret_trace.items) |src_loc| {2394 for (sema.comptime_err_ret_trace.items) |src_loc| {
2397 try mod.errNoteNonLazy(src_loc, msg, "error returned here", .{});2395 try sema.errNote(src_loc, msg, "error returned here", .{});
2398 }2396 }
2399 break :msg msg;2397 break :msg msg;
2400 };2398 };
...@@ -2403,17 +2401,15 @@ fn failWithComptimeErrorRetTrace(...@@ -2403,17 +2401,15 @@ fn failWithComptimeErrorRetTrace(
24032401
2404/// We don't return a pointer to the new error note because the pointer2402/// We don't return a pointer to the new error note because the pointer
2405/// becomes invalid when you add another one.2403/// becomes invalid when you add another one.
2406fn errNote(2404pub fn errNote(
2407 sema: *Sema,2405 sema: *Sema,
2408 block: *Block,
2409 src: LazySrcLoc,2406 src: LazySrcLoc,
2410 parent: *Module.ErrorMsg,2407 parent: *Module.ErrorMsg,
2411 comptime format: []const u8,2408 comptime format: []const u8,
2412 args: anytype,2409 args: anytype,
2413) error{OutOfMemory}!void {2410) error{OutOfMemory}!void {
2414 const mod = sema.mod;2411 const zcu = sema.mod;
2415 const src_decl = mod.declPtr(block.src_decl);2412 return zcu.errNoteNonLazy(src.upgrade(zcu), parent, format, args);
2416 return mod.errNoteNonLazy(src_decl.toSrcLoc(src, mod), parent, format, args);
2417}2413}
24182414
2419fn addFieldErrNote(2415fn addFieldErrNote(
...@@ -2425,52 +2421,23 @@ fn addFieldErrNote(...@@ -2425,52 +2421,23 @@ fn addFieldErrNote(
2425 args: anytype,2421 args: anytype,
2426) !void {2422) !void {
2427 @setCold(true);2423 @setCold(true);
2428 const mod = sema.mod;2424 const zcu = sema.mod;
2429 const decl_index = container_ty.getOwnerDecl(mod);2425 const type_src = container_ty.srcLocOrNull(zcu) orelse return;
2430 const decl = mod.declPtr(decl_index);2426 const field_src: LazySrcLoc = .{
24312427 .base_node_inst = type_src.base_node_inst,
2432 const field_src = blk: {2428 .offset = .{ .container_field_name = @intCast(field_index) },
2433 const tree = decl.getFileScope(mod).getTree(sema.gpa) catch |err| {
2434 log.err("unable to load AST to report compile error: {s}", .{@errorName(err)});
2435 break :blk decl.srcLoc(mod);
2436 };
2437
2438 const container_node = decl.relativeToNodeIndex(0);
2439 const node_tags = tree.nodes.items(.tag);
2440 var buf: [2]std.zig.Ast.Node.Index = undefined;
2441 const container_decl = tree.fullContainerDecl(&buf, container_node) orelse break :blk decl.srcLoc(mod);
2442
2443 var it_index: usize = 0;
2444 for (container_decl.ast.members) |member_node| {
2445 switch (node_tags[member_node]) {
2446 .container_field_init,
2447 .container_field_align,
2448 .container_field,
2449 => {
2450 if (it_index == field_index) {
2451 break :blk decl.nodeOffsetSrcLoc(decl.nodeIndexToRelative(member_node), mod);
2452 }
2453 it_index += 1;
2454 },
2455 else => continue,
2456 }
2457 }
2458 unreachable;
2459 };2429 };
2460 try mod.errNoteNonLazy(field_src, parent, format, args);2430 try sema.errNote(field_src, parent, format, args);
2461}2431}
24622432
2463pub fn errMsg(2433pub fn errMsg(
2464 sema: *Sema,2434 sema: *Sema,
2465 block: *Block,
2466 src: LazySrcLoc,2435 src: LazySrcLoc,
2467 comptime format: []const u8,2436 comptime format: []const u8,
2468 args: anytype,2437 args: anytype,
2469) error{ NeededSourceLocation, OutOfMemory }!*Module.ErrorMsg {2438) Allocator.Error!*Module.ErrorMsg {
2470 const mod = sema.mod;2439 assert(src.offset != .unneeded);
2471 if (src == .unneeded) return error.NeededSourceLocation;2440 return Module.ErrorMsg.create(sema.gpa, src.upgrade(sema.mod), format, args);
2472 const src_decl = mod.declPtr(block.src_decl);
2473 return Module.ErrorMsg.create(sema.gpa, src_decl.toSrcLoc(src, mod), format, args);
2474}2441}
24752442
2476pub fn fail(2443pub fn fail(
...@@ -2480,7 +2447,7 @@ pub fn fail(...@@ -2480,7 +2447,7 @@ pub fn fail(
2480 comptime format: []const u8,2447 comptime format: []const u8,
2481 args: anytype,2448 args: anytype,
2482) CompileError {2449) CompileError {
2483 const err_msg = try sema.errMsg(block, src, format, args);2450 const err_msg = try sema.errMsg(src, format, args);
2484 inline for (args) |arg| {2451 inline for (args) |arg| {
2485 if (@TypeOf(arg) == Type.Formatter) {2452 if (@TypeOf(arg) == Type.Formatter) {
2486 try addDeclaredHereNote(sema, err_msg, arg.data.ty);2453 try addDeclaredHereNote(sema, err_msg, arg.data.ty);
...@@ -2514,7 +2481,6 @@ pub fn failWithOwnedErrorMsg(sema: *Sema, block: ?*Block, err_msg: *Module.Error...@@ -2514,7 +2481,6 @@ pub fn failWithOwnedErrorMsg(sema: *Sema, block: ?*Block, err_msg: *Module.Error
2514 var block_it = start_block;2481 var block_it = start_block;
2515 while (block_it.inlining) |inlining| {2482 while (block_it.inlining) |inlining| {
2516 try sema.errNote(2483 try sema.errNote(
2517 inlining.call_block,
2518 inlining.call_src,2484 inlining.call_src,
2519 err_msg,2485 err_msg,
2520 "called from here",2486 "called from here",
...@@ -2548,7 +2514,7 @@ pub fn failWithOwnedErrorMsg(sema: *Sema, block: ?*Block, err_msg: *Module.Error...@@ -2548,7 +2514,7 @@ pub fn failWithOwnedErrorMsg(sema: *Sema, block: ?*Block, err_msg: *Module.Error
2548 const decl = mod.declPtr(ref.referencer);2514 const decl = mod.declPtr(ref.referencer);
2549 try reference_stack.append(.{2515 try reference_stack.append(.{
2550 .decl = decl.name,2516 .decl = decl.name,
2551 .src_loc = decl.toSrcLoc(ref.src, mod),2517 .src_loc = ref.src.upgrade(mod),
2552 });2518 });
2553 }2519 }
2554 referenced_by = ref.referencer;2520 referenced_by = ref.referencer;
...@@ -2583,15 +2549,13 @@ pub fn failWithOwnedErrorMsg(sema: *Sema, block: ?*Block, err_msg: *Module.Error...@@ -2583,15 +2549,13 @@ pub fn failWithOwnedErrorMsg(sema: *Sema, block: ?*Block, err_msg: *Module.Error
2583/// Reference trace is preserved.2549/// Reference trace is preserved.
2584fn reparentOwnedErrorMsg(2550fn reparentOwnedErrorMsg(
2585 sema: *Sema,2551 sema: *Sema,
2586 block: *Block,
2587 src: LazySrcLoc,2552 src: LazySrcLoc,
2588 msg: *Module.ErrorMsg,2553 msg: *Module.ErrorMsg,
2589 comptime format: []const u8,2554 comptime format: []const u8,
2590 args: anytype,2555 args: anytype,
2591) !void {2556) !void {
2592 const mod = sema.mod;2557 const mod = sema.mod;
2593 const src_decl = mod.declPtr(block.src_decl);2558 const resolved_src = src.upgrade(mod);
2594 const resolved_src = src_decl.toSrcLoc(src, mod);
2595 const msg_str = try std.fmt.allocPrint(mod.gpa, format, args);2559 const msg_str = try std.fmt.allocPrint(mod.gpa, format, args);
25962560
2597 const orig_notes = msg.notes.len;2561 const orig_notes = msg.notes.len;
...@@ -2728,7 +2692,7 @@ fn getCaptures(sema: *Sema, block: *Block, type_src: LazySrcLoc, extra_index: us...@@ -2728,7 +2692,7 @@ fn getCaptures(sema: *Sema, block: *Block, type_src: LazySrcLoc, extra_index: us
2728 sema.code.nullTerminatedString(str),2692 sema.code.nullTerminatedString(str),
2729 .no_embedded_nulls,2693 .no_embedded_nulls,
2730 );2694 );
2731 const decl = try sema.lookupIdentifier(block, .unneeded, decl_name); // TODO: could we need this src loc?2695 const decl = try sema.lookupIdentifier(block, LazySrcLoc.unneeded, decl_name); // TODO: could we need this src loc?
2732 break :capture InternPool.CaptureValue.wrap(.{ .decl_val = decl });2696 break :capture InternPool.CaptureValue.wrap(.{ .decl_val = decl });
2733 },2697 },
2734 .decl_ref => |str| capture: {2698 .decl_ref => |str| capture: {
...@@ -2737,7 +2701,7 @@ fn getCaptures(sema: *Sema, block: *Block, type_src: LazySrcLoc, extra_index: us...@@ -2737,7 +2701,7 @@ fn getCaptures(sema: *Sema, block: *Block, type_src: LazySrcLoc, extra_index: us
2737 sema.code.nullTerminatedString(str),2701 sema.code.nullTerminatedString(str),
2738 .no_embedded_nulls,2702 .no_embedded_nulls,
2739 );2703 );
2740 const decl = try sema.lookupIdentifier(block, .unneeded, decl_name); // TODO: could we need this src loc?2704 const decl = try sema.lookupIdentifier(block, LazySrcLoc.unneeded, decl_name); // TODO: could we need this src loc?
2741 break :capture InternPool.CaptureValue.wrap(.{ .decl_ref = decl });2705 break :capture InternPool.CaptureValue.wrap(.{ .decl_ref = decl });
2742 },2706 },
2743 };2707 };
...@@ -2788,7 +2752,13 @@ fn zirStructDecl(...@@ -2788,7 +2752,13 @@ fn zirStructDecl(
2788 const ip = &mod.intern_pool;2752 const ip = &mod.intern_pool;
2789 const small: Zir.Inst.StructDecl.Small = @bitCast(extended.small);2753 const small: Zir.Inst.StructDecl.Small = @bitCast(extended.small);
2790 const extra = sema.code.extraData(Zir.Inst.StructDecl, extended.operand);2754 const extra = sema.code.extraData(Zir.Inst.StructDecl, extended.operand);
2791 const src: LazySrcLoc = .{ .node_abs = extra.data.src_node };2755
2756 const tracked_inst = try ip.trackZir(gpa, block.getFileScope(mod), inst);
2757 const src: LazySrcLoc = .{
2758 .base_node_inst = tracked_inst,
2759 .offset = LazySrcLoc.Offset.nodeOffset(0),
2760 };
2761
2792 var extra_index = extra.end;2762 var extra_index = extra.end;
27932763
2794 const captures_len = if (small.has_captures_len) blk: {2764 const captures_len = if (small.has_captures_len) blk: {
...@@ -2832,7 +2802,7 @@ fn zirStructDecl(...@@ -2832,7 +2802,7 @@ fn zirStructDecl(
2832 .any_aligned_fields = small.any_aligned_fields,2802 .any_aligned_fields = small.any_aligned_fields,
2833 .has_namespace = true or decls_len > 0, // TODO: see below2803 .has_namespace = true or decls_len > 0, // TODO: see below
2834 .key = .{ .declared = .{2804 .key = .{ .declared = .{
2835 .zir_index = try ip.trackZir(gpa, block.getFileScope(mod), inst),2805 .zir_index = tracked_inst,
2836 .captures = captures,2806 .captures = captures,
2837 } },2807 } },
2838 };2808 };
...@@ -2847,7 +2817,6 @@ fn zirStructDecl(...@@ -2847,7 +2817,6 @@ fn zirStructDecl(
28472817
2848 const new_decl_index = try sema.createAnonymousDeclTypeNamed(2818 const new_decl_index = try sema.createAnonymousDeclTypeNamed(
2849 block,2819 block,
2850 extra.data.src_node,
2851 Value.fromInterned(wip_ty.index),2820 Value.fromInterned(wip_ty.index),
2852 small.name_strategy,2821 small.name_strategy,
2853 "struct",2822 "struct",
...@@ -2884,7 +2853,6 @@ fn zirStructDecl(...@@ -2884,7 +2853,6 @@ fn zirStructDecl(
2884fn createAnonymousDeclTypeNamed(2853fn createAnonymousDeclTypeNamed(
2885 sema: *Sema,2854 sema: *Sema,
2886 block: *Block,2855 block: *Block,
2887 src_node: std.zig.Ast.Node.Index,
2888 val: Value,2856 val: Value,
2889 name_strategy: Zir.Inst.NameStrategy,2857 name_strategy: Zir.Inst.NameStrategy,
2890 anon_prefix: []const u8,2858 anon_prefix: []const u8,
...@@ -2895,7 +2863,7 @@ fn createAnonymousDeclTypeNamed(...@@ -2895,7 +2863,7 @@ fn createAnonymousDeclTypeNamed(
2895 const gpa = sema.gpa;2863 const gpa = sema.gpa;
2896 const namespace = block.namespace;2864 const namespace = block.namespace;
2897 const src_decl = zcu.declPtr(block.src_decl);2865 const src_decl = zcu.declPtr(block.src_decl);
2898 const new_decl_index = try zcu.allocateNewDecl(namespace, src_node);2866 const new_decl_index = try zcu.allocateNewDecl(namespace);
2899 errdefer zcu.destroyDecl(new_decl_index);2867 errdefer zcu.destroyDecl(new_decl_index);
29002868
2901 switch (name_strategy) {2869 switch (name_strategy) {
...@@ -2924,8 +2892,7 @@ fn createAnonymousDeclTypeNamed(...@@ -2924,8 +2892,7 @@ fn createAnonymousDeclTypeNamed(
2924 // If not then this is a struct type being returned from a non-generic2892 // If not then this is a struct type being returned from a non-generic
2925 // function and the name doesn't matter since it will later2893 // function and the name doesn't matter since it will later
2926 // result in a compile error.2894 // result in a compile error.
2927 const arg_val = sema.resolveConstValue(block, .unneeded, arg, undefined) catch2895 const arg_val = try sema.resolveValue(arg) orelse break :func_strat; // fall through to anon strat
2928 break :func_strat; // fall through to anon strat
29292896
2930 if (arg_i != 0) try writer.writeByte(',');2897 if (arg_i != 0) try writer.writeByte(',');
29312898
...@@ -3003,7 +2970,9 @@ fn zirEnumDecl(...@@ -3003,7 +2970,9 @@ fn zirEnumDecl(
3003 const extra = sema.code.extraData(Zir.Inst.EnumDecl, extended.operand);2970 const extra = sema.code.extraData(Zir.Inst.EnumDecl, extended.operand);
3004 var extra_index: usize = extra.end;2971 var extra_index: usize = extra.end;
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
3008 const tag_type_ref = if (small.has_tag_type) blk: {2977 const tag_type_ref = if (small.has_tag_type) blk: {
3009 const tag_type_ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_index]);2978 const tag_type_ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_index]);
...@@ -3063,7 +3032,7 @@ fn zirEnumDecl(...@@ -3063,7 +3032,7 @@ fn zirEnumDecl(
3063 .explicit,3032 .explicit,
3064 .fields_len = fields_len,3033 .fields_len = fields_len,
3065 .key = .{ .declared = .{3034 .key = .{ .declared = .{
3066 .zir_index = try mod.intern_pool.trackZir(sema.gpa, block.getFileScope(mod), inst),3035 .zir_index = tracked_inst,
3067 .captures = captures,3036 .captures = captures,
3068 } },3037 } },
3069 };3038 };
...@@ -3083,7 +3052,6 @@ fn zirEnumDecl(...@@ -3083,7 +3052,6 @@ fn zirEnumDecl(
30833052
3084 const new_decl_index = try sema.createAnonymousDeclTypeNamed(3053 const new_decl_index = try sema.createAnonymousDeclTypeNamed(
3085 block,3054 block,
3086 extra.data.src_node,
3087 Value.fromInterned(wip_ty.index),3055 Value.fromInterned(wip_ty.index),
3088 small.name_strategy,3056 small.name_strategy,
3089 "enum",3057 "enum",
...@@ -3149,12 +3117,10 @@ fn zirEnumDecl(...@@ -3149,12 +3117,10 @@ fn zirEnumDecl(
3149 .instructions = .{},3117 .instructions = .{},
3150 .inlining = null,3118 .inlining = null,
3151 .is_comptime = true,3119 .is_comptime = true,
3120 .src_base_inst = tracked_inst,
3152 };3121 };
3153 defer enum_block.instructions.deinit(sema.gpa);3122 defer enum_block.instructions.deinit(sema.gpa);
31543123
3155 // This source location applies in the context of `enum_block`.
3156 const tag_ty_src: LazySrcLoc = .{ .node_offset_container_tag = 0 };
3157
3158 if (body.len != 0) {3124 if (body.len != 0) {
3159 _ = try sema.analyzeInlineBody(&enum_block, body, inst);3125 _ = try sema.analyzeInlineBody(&enum_block, body, inst);
3160 }3126 }
...@@ -3199,36 +3165,33 @@ fn zirEnumDecl(...@@ -3199,36 +3165,33 @@ fn zirEnumDecl(
31993165
3200 const field_name = try mod.intern_pool.getOrPutString(gpa, field_name_zir, .no_embedded_nulls);3166 const field_name = try mod.intern_pool.getOrPutString(gpa, field_name_zir, .no_embedded_nulls);
32013167
3168 const value_src: LazySrcLoc = .{
3169 .base_node_inst = tracked_inst,
3170 .offset = .{ .container_field_value = field_i },
3171 };
3172
3202 const tag_overflow = if (has_tag_value) overflow: {3173 const tag_overflow = if (has_tag_value) overflow: {
3203 const tag_val_ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_index]);3174 const tag_val_ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_index]);
3204 extra_index += 1;3175 extra_index += 1;
3205 const tag_inst = try sema.resolveInst(tag_val_ref);3176 const tag_inst = try sema.resolveInst(tag_val_ref);
3206 last_tag_val = sema.resolveConstDefinedValue(block, .unneeded, tag_inst, undefined) catch |err| switch (err) {3177 last_tag_val = try sema.resolveConstDefinedValue(block, .{
3207 error.NeededSourceLocation => {3178 .base_node_inst = tracked_inst,
3208 const value_src = mod.fieldSrcLoc(new_decl_index, .{3179 .offset = .{ .container_field_name = field_i },
3209 .index = field_i,3180 }, tag_inst, .{
3210 .range = .value,3181 .needed_comptime_reason = "enum tag value must be comptime-known",
3211 }).lazy;3182 });
3212 _ = try sema.resolveConstDefinedValue(block, value_src, tag_inst, .{
3213 .needed_comptime_reason = "enum tag value must be comptime-known",
3214 });
3215 unreachable;
3216 },
3217 else => |e| return e,
3218 };
3219 if (!(try sema.intFitsInType(last_tag_val.?, int_tag_ty, null))) break :overflow true;3183 if (!(try sema.intFitsInType(last_tag_val.?, int_tag_ty, null))) break :overflow true;
3220 last_tag_val = try mod.getCoerced(last_tag_val.?, int_tag_ty);3184 last_tag_val = try mod.getCoerced(last_tag_val.?, int_tag_ty);
3221 if (wip_ty.nextField(&mod.intern_pool, field_name, last_tag_val.?.toIntern())) |conflict| {3185 if (wip_ty.nextField(&mod.intern_pool, field_name, last_tag_val.?.toIntern())) |conflict| {
3222 assert(conflict.kind == .value); // AstGen validated names are unique3186 assert(conflict.kind == .value); // AstGen validated names are unique
3223 const value_src = mod.fieldSrcLoc(new_decl_index, .{3187 const other_field_src: LazySrcLoc = .{
3224 .index = field_i,3188 .base_node_inst = tracked_inst,
3225 .range = .value,3189 .offset = .{ .container_field_value = conflict.prev_field_idx },
3226 }).lazy;3190 };
3227 const other_field_src = mod.fieldSrcLoc(new_decl_index, .{ .index = conflict.prev_field_idx }).lazy;
3228 const msg = msg: {3191 const msg = msg: {
3229 const msg = try sema.errMsg(block, value_src, "enum tag value {} already taken", .{last_tag_val.?.fmtValue(sema.mod, sema)});3192 const msg = try sema.errMsg(value_src, "enum tag value {} already taken", .{last_tag_val.?.fmtValue(sema.mod, sema)});
3230 errdefer msg.destroy(gpa);3193 errdefer msg.destroy(gpa);
3231 try sema.errNote(block, other_field_src, msg, "other occurrence here", .{});3194 try sema.errNote(other_field_src, msg, "other occurrence here", .{});
3232 break :msg msg;3195 break :msg msg;
3233 };3196 };
3234 return sema.failWithOwnedErrorMsg(block, msg);3197 return sema.failWithOwnedErrorMsg(block, msg);
...@@ -3243,12 +3206,14 @@ fn zirEnumDecl(...@@ -3243,12 +3206,14 @@ fn zirEnumDecl(
3243 if (overflow != null) break :overflow true;3206 if (overflow != null) break :overflow true;
3244 if (wip_ty.nextField(&mod.intern_pool, field_name, last_tag_val.?.toIntern())) |conflict| {3207 if (wip_ty.nextField(&mod.intern_pool, field_name, last_tag_val.?.toIntern())) |conflict| {
3245 assert(conflict.kind == .value); // AstGen validated names are unique3208 assert(conflict.kind == .value); // AstGen validated names are unique
3246 const field_src = mod.fieldSrcLoc(new_decl_index, .{ .index = field_i }).lazy;3209 const other_field_src: LazySrcLoc = .{
3247 const other_field_src = mod.fieldSrcLoc(new_decl_index, .{ .index = conflict.prev_field_idx }).lazy;3210 .base_node_inst = tracked_inst,
3211 .offset = .{ .container_field_value = conflict.prev_field_idx },
3212 };
3248 const msg = msg: {3213 const msg = msg: {
3249 const msg = try sema.errMsg(block, field_src, "enum tag value {} already taken", .{last_tag_val.?.fmtValue(sema.mod, sema)});3214 const msg = try sema.errMsg(value_src, "enum tag value {} already taken", .{last_tag_val.?.fmtValue(sema.mod, sema)});
3250 errdefer msg.destroy(gpa);3215 errdefer msg.destroy(gpa);
3251 try sema.errNote(block, other_field_src, msg, "other occurrence here", .{});3216 try sema.errNote(other_field_src, msg, "other occurrence here", .{});
3252 break :msg msg;3217 break :msg msg;
3253 };3218 };
3254 return sema.failWithOwnedErrorMsg(block, msg);3219 return sema.failWithOwnedErrorMsg(block, msg);
...@@ -3263,11 +3228,7 @@ fn zirEnumDecl(...@@ -3263,11 +3228,7 @@ fn zirEnumDecl(
3263 };3228 };
32643229
3265 if (tag_overflow) {3230 if (tag_overflow) {
3266 const value_src = mod.fieldSrcLoc(new_decl_index, .{3231 const msg = try sema.errMsg(value_src, "enumeration value '{}' too large for type '{}'", .{
3267 .index = field_i,
3268 .range = if (has_tag_value) .value else .name,
3269 }).lazy;
3270 const msg = try sema.errMsg(block, value_src, "enumeration value '{}' too large for type '{}'", .{
3271 last_tag_val.?.fmtValue(mod, sema), int_tag_ty.fmt(mod),3232 last_tag_val.?.fmtValue(mod, sema), int_tag_ty.fmt(mod),
3272 });3233 });
3273 return sema.failWithOwnedErrorMsg(block, msg);3234 return sema.failWithOwnedErrorMsg(block, msg);
...@@ -3294,7 +3255,8 @@ fn zirUnionDecl(...@@ -3294,7 +3255,8 @@ fn zirUnionDecl(
3294 const extra = sema.code.extraData(Zir.Inst.UnionDecl, extended.operand);3255 const extra = sema.code.extraData(Zir.Inst.UnionDecl, extended.operand);
3295 var extra_index: usize = extra.end;3256 var extra_index: usize = extra.end;
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
3299 extra_index += @intFromBool(small.has_tag_type);3261 extra_index += @intFromBool(small.has_tag_type);
3300 const captures_len = if (small.has_captures_len) blk: {3262 const captures_len = if (small.has_captures_len) blk: {
...@@ -3342,7 +3304,7 @@ fn zirUnionDecl(...@@ -3342,7 +3304,7 @@ fn zirUnionDecl(
3342 .field_types = &.{}, // set later3304 .field_types = &.{}, // set later
3343 .field_aligns = &.{}, // set later3305 .field_aligns = &.{}, // set later
3344 .key = .{ .declared = .{3306 .key = .{ .declared = .{
3345 .zir_index = try ip.trackZir(gpa, block.getFileScope(mod), inst),3307 .zir_index = tracked_inst,
3346 .captures = captures,3308 .captures = captures,
3347 } },3309 } },
3348 };3310 };
...@@ -3357,7 +3319,6 @@ fn zirUnionDecl(...@@ -3357,7 +3319,6 @@ fn zirUnionDecl(
33573319
3358 const new_decl_index = try sema.createAnonymousDeclTypeNamed(3320 const new_decl_index = try sema.createAnonymousDeclTypeNamed(
3359 block,3321 block,
3360 extra.data.src_node,
3361 Value.fromInterned(wip_ty.index),3322 Value.fromInterned(wip_ty.index),
3362 small.name_strategy,3323 small.name_strategy,
3363 "union",3324 "union",
...@@ -3409,7 +3370,8 @@ fn zirOpaqueDecl(...@@ -3409,7 +3370,8 @@ fn zirOpaqueDecl(
3409 const extra = sema.code.extraData(Zir.Inst.OpaqueDecl, extended.operand);3370 const extra = sema.code.extraData(Zir.Inst.OpaqueDecl, extended.operand);
3410 var extra_index: usize = extra.end;3371 var extra_index: usize = extra.end;
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
3414 const captures_len = if (small.has_captures_len) blk: {3376 const captures_len = if (small.has_captures_len) blk: {
3415 const captures_len = sema.code.extra[extra_index];3377 const captures_len = sema.code.extra[extra_index];
...@@ -3429,7 +3391,7 @@ fn zirOpaqueDecl(...@@ -3429,7 +3391,7 @@ fn zirOpaqueDecl(
3429 const opaque_init: InternPool.OpaqueTypeInit = .{3391 const opaque_init: InternPool.OpaqueTypeInit = .{
3430 .has_namespace = decls_len != 0,3392 .has_namespace = decls_len != 0,
3431 .key = .{ .declared = .{3393 .key = .{ .declared = .{
3432 .zir_index = try ip.trackZir(gpa, block.getFileScope(mod), inst),3394 .zir_index = tracked_inst,
3433 .captures = captures,3395 .captures = captures,
3434 } },3396 } },
3435 };3397 };
...@@ -3445,7 +3407,6 @@ fn zirOpaqueDecl(...@@ -3445,7 +3407,6 @@ fn zirOpaqueDecl(
34453407
3446 const new_decl_index = try sema.createAnonymousDeclTypeNamed(3408 const new_decl_index = try sema.createAnonymousDeclTypeNamed(
3447 block,3409 block,
3448 extra.data.src_node,
3449 Value.fromInterned(wip_ty.index),3410 Value.fromInterned(wip_ty.index),
3450 small.name_strategy,3411 small.name_strategy,
3451 "opaque",3412 "opaque",
...@@ -3566,19 +3527,19 @@ fn ensureResultUsed(...@@ -3566,19 +3527,19 @@ fn ensureResultUsed(
3566 .ErrorSet => return sema.fail(block, src, "error set is ignored", .{}),3527 .ErrorSet => return sema.fail(block, src, "error set is ignored", .{}),
3567 .ErrorUnion => {3528 .ErrorUnion => {
3568 const msg = msg: {3529 const msg = msg: {
3569 const msg = try sema.errMsg(block, src, "error union is ignored", .{});3530 const msg = try sema.errMsg(src, "error union is ignored", .{});
3570 errdefer msg.destroy(sema.gpa);3531 errdefer msg.destroy(sema.gpa);
3571 try sema.errNote(block, src, msg, "consider using 'try', 'catch', or 'if'", .{});3532 try sema.errNote(src, msg, "consider using 'try', 'catch', or 'if'", .{});
3572 break :msg msg;3533 break :msg msg;
3573 };3534 };
3574 return sema.failWithOwnedErrorMsg(block, msg);3535 return sema.failWithOwnedErrorMsg(block, msg);
3575 },3536 },
3576 else => {3537 else => {
3577 const msg = msg: {3538 const msg = msg: {
3578 const msg = try sema.errMsg(block, src, "value of type '{}' ignored", .{ty.fmt(sema.mod)});3539 const msg = try sema.errMsg(src, "value of type '{}' ignored", .{ty.fmt(sema.mod)});
3579 errdefer msg.destroy(sema.gpa);3540 errdefer msg.destroy(sema.gpa);
3580 try sema.errNote(block, src, msg, "all non-void values must be used", .{});3541 try sema.errNote(src, msg, "all non-void values must be used", .{});
3581 try sema.errNote(block, src, msg, "to discard the value, assign it to '_'", .{});3542 try sema.errNote(src, msg, "to discard the value, assign it to '_'", .{});
3582 break :msg msg;3543 break :msg msg;
3583 };3544 };
3584 return sema.failWithOwnedErrorMsg(block, msg);3545 return sema.failWithOwnedErrorMsg(block, msg);
...@@ -3599,9 +3560,9 @@ fn zirEnsureResultNonError(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com...@@ -3599,9 +3560,9 @@ fn zirEnsureResultNonError(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com
3599 .ErrorSet => return sema.fail(block, src, "error set is discarded", .{}),3560 .ErrorSet => return sema.fail(block, src, "error set is discarded", .{}),
3600 .ErrorUnion => {3561 .ErrorUnion => {
3601 const msg = msg: {3562 const msg = msg: {
3602 const msg = try sema.errMsg(block, src, "error union is discarded", .{});3563 const msg = try sema.errMsg(src, "error union is discarded", .{});
3603 errdefer msg.destroy(sema.gpa);3564 errdefer msg.destroy(sema.gpa);
3604 try sema.errNote(block, src, msg, "consider using 'try', 'catch', or 'if'", .{});3565 try sema.errNote(src, msg, "consider using 'try', 'catch', or 'if'", .{});
3605 break :msg msg;3566 break :msg msg;
3606 };3567 };
3607 return sema.failWithOwnedErrorMsg(block, msg);3568 return sema.failWithOwnedErrorMsg(block, msg);
...@@ -3627,9 +3588,9 @@ fn zirEnsureErrUnionPayloadVoid(sema: *Sema, block: *Block, inst: Zir.Inst.Index...@@ -3627,9 +3588,9 @@ fn zirEnsureErrUnionPayloadVoid(sema: *Sema, block: *Block, inst: Zir.Inst.Index
3627 const payload_ty = err_union_ty.errorUnionPayload(mod).zigTypeTag(mod);3588 const payload_ty = err_union_ty.errorUnionPayload(mod).zigTypeTag(mod);
3628 if (payload_ty != .Void and payload_ty != .NoReturn) {3589 if (payload_ty != .Void and payload_ty != .NoReturn) {
3629 const msg = msg: {3590 const msg = msg: {
3630 const msg = try sema.errMsg(block, src, "error union payload is ignored", .{});3591 const msg = try sema.errMsg(src, "error union payload is ignored", .{});
3631 errdefer msg.destroy(sema.gpa);3592 errdefer msg.destroy(sema.gpa);
3632 try sema.errNote(block, src, msg, "payload value can be explicitly ignored with '|_|'", .{});3593 try sema.errNote(src, msg, "payload value can be explicitly ignored with '|_|'", .{});
3633 break :msg msg;3594 break :msg msg;
3634 };3595 };
3635 return sema.failWithOwnedErrorMsg(block, msg);3596 return sema.failWithOwnedErrorMsg(block, msg);
...@@ -3683,8 +3644,8 @@ fn zirAllocExtended(...@@ -3683,8 +3644,8 @@ fn zirAllocExtended(
3683) CompileError!Air.Inst.Ref {3644) CompileError!Air.Inst.Ref {
3684 const gpa = sema.gpa;3645 const gpa = sema.gpa;
3685 const extra = sema.code.extraData(Zir.Inst.AllocExtended, extended.operand);3646 const extra = sema.code.extraData(Zir.Inst.AllocExtended, extended.operand);
3686 const ty_src: LazySrcLoc = .{ .node_offset_var_decl_ty = extra.data.src_node };3647 const ty_src = block.src(.{ .node_offset_var_decl_ty = extra.data.src_node });
3687 const align_src: LazySrcLoc = .{ .node_offset_var_decl_align = extra.data.src_node };3648 const align_src = block.src(.{ .node_offset_var_decl_align = extra.data.src_node });
3688 const small: Zir.Inst.AllocExtended.Small = @bitCast(extended.small);3649 const small: Zir.Inst.AllocExtended.Small = @bitCast(extended.small);
36893650
3690 var extra_index: usize = extra.end;3651 var extra_index: usize = extra.end;
...@@ -3760,7 +3721,7 @@ fn zirAllocComptime(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr...@@ -3760,7 +3721,7 @@ fn zirAllocComptime(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr
3760 defer tracy.end();3721 defer tracy.end();
37613722
3762 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;3723 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
3763 const ty_src: LazySrcLoc = .{ .node_offset_var_decl_ty = inst_data.src_node };3724 const ty_src = block.src(.{ .node_offset_var_decl_ty = inst_data.src_node });
3764 const var_ty = try sema.resolveType(block, ty_src, inst_data.operand);3725 const var_ty = try sema.resolveType(block, ty_src, inst_data.operand);
3765 return sema.analyzeComptimeAlloc(block, var_ty, .none);3726 return sema.analyzeComptimeAlloc(block, var_ty, .none);
3766}3727}
...@@ -3826,7 +3787,7 @@ fn zirMakePtrConst(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro...@@ -3826,7 +3787,7 @@ fn zirMakePtrConst(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
3826 if (try sema.typeRequiresComptime(elem_ty)) {3787 if (try sema.typeRequiresComptime(elem_ty)) {
3827 // The value was initialized through RLS, so we didn't detect the runtime condition earlier.3788 // The value was initialized through RLS, so we didn't detect the runtime condition earlier.
3828 // TODO: source location of runtime control flow3789 // TODO: source location of runtime control flow
3829 const init_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };3790 const init_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node });
3830 return sema.fail(block, init_src, "value with comptime-only type '{}' depends on runtime control flow", .{elem_ty.fmt(mod)});3791 return sema.fail(block, init_src, "value with comptime-only type '{}' depends on runtime control flow", .{elem_ty.fmt(mod)});
3831 }3792 }
38323793
...@@ -3995,7 +3956,7 @@ fn resolveComptimeKnownAllocPtr(sema: *Sema, block: *Block, alloc: Air.Inst.Ref,...@@ -3995,7 +3956,7 @@ fn resolveComptimeKnownAllocPtr(sema: *Sema, block: *Block, alloc: Air.Inst.Ref,
3995 .ty = opt_ty.toIntern(),3956 .ty = opt_ty.toIntern(),
3996 .val = payload_val.toIntern(),3957 .val = payload_val.toIntern(),
3997 } });3958 } });
3998 try sema.storePtrVal(block, .unneeded, Value.fromInterned(decl_parent_ptr), Value.fromInterned(opt_val), opt_ty);3959 try sema.storePtrVal(block, LazySrcLoc.unneeded, Value.fromInterned(decl_parent_ptr), Value.fromInterned(opt_val), opt_ty);
3999 break :ptr (try Value.fromInterned(decl_parent_ptr).ptrOptPayload(sema)).toIntern();3960 break :ptr (try Value.fromInterned(decl_parent_ptr).ptrOptPayload(sema)).toIntern();
4000 },3961 },
4001 .eu_payload => ptr: {3962 .eu_payload => ptr: {
...@@ -4008,7 +3969,7 @@ fn resolveComptimeKnownAllocPtr(sema: *Sema, block: *Block, alloc: Air.Inst.Ref,...@@ -4008,7 +3969,7 @@ fn resolveComptimeKnownAllocPtr(sema: *Sema, block: *Block, alloc: Air.Inst.Ref,
4008 .ty = eu_ty.toIntern(),3969 .ty = eu_ty.toIntern(),
4009 .val = .{ .payload = payload_val.toIntern() },3970 .val = .{ .payload = payload_val.toIntern() },
4010 } });3971 } });
4011 try sema.storePtrVal(block, .unneeded, Value.fromInterned(decl_parent_ptr), Value.fromInterned(eu_val), eu_ty);3972 try sema.storePtrVal(block, LazySrcLoc.unneeded, Value.fromInterned(decl_parent_ptr), Value.fromInterned(eu_val), eu_ty);
4012 break :ptr (try Value.fromInterned(decl_parent_ptr).ptrEuPayload(sema)).toIntern();3973 break :ptr (try Value.fromInterned(decl_parent_ptr).ptrEuPayload(sema)).toIntern();
4013 },3974 },
4014 .field => |idx| ptr: {3975 .field => |idx| ptr: {
...@@ -4021,7 +3982,7 @@ fn resolveComptimeKnownAllocPtr(sema: *Sema, block: *Block, alloc: Air.Inst.Ref,...@@ -4021,7 +3982,7 @@ fn resolveComptimeKnownAllocPtr(sema: *Sema, block: *Block, alloc: Air.Inst.Ref,
4021 const payload_val = try sema.typeHasOnePossibleValue(payload_ty) orelse try zcu.undefValue(payload_ty);3982 const payload_val = try sema.typeHasOnePossibleValue(payload_ty) orelse try zcu.undefValue(payload_ty);
4022 const tag_val = try zcu.enumValueFieldIndex(Type.fromInterned(union_obj.enum_tag_ty), idx);3983 const tag_val = try zcu.enumValueFieldIndex(Type.fromInterned(union_obj.enum_tag_ty), idx);
4023 const store_val = try zcu.unionValue(maybe_union_ty, tag_val, payload_val);3984 const store_val = try zcu.unionValue(maybe_union_ty, tag_val, payload_val);
4024 try sema.storePtrVal(block, .unneeded, Value.fromInterned(decl_parent_ptr), store_val, maybe_union_ty);3985 try sema.storePtrVal(block, LazySrcLoc.unneeded, Value.fromInterned(decl_parent_ptr), store_val, maybe_union_ty);
4025 }3986 }
4026 break :ptr (try Value.fromInterned(decl_parent_ptr).ptrField(idx, sema)).toIntern();3987 break :ptr (try Value.fromInterned(decl_parent_ptr).ptrField(idx, sema)).toIntern();
4027 },3988 },
...@@ -4043,14 +4004,14 @@ fn resolveComptimeKnownAllocPtr(sema: *Sema, block: *Block, alloc: Air.Inst.Ref,...@@ -4043,14 +4004,14 @@ fn resolveComptimeKnownAllocPtr(sema: *Sema, block: *Block, alloc: Air.Inst.Ref,
4043 const air_ptr_inst = store_inst.data.bin_op.lhs.toIndex().?;4004 const air_ptr_inst = store_inst.data.bin_op.lhs.toIndex().?;
4044 const store_val = (try sema.resolveValue(store_inst.data.bin_op.rhs)).?;4005 const store_val = (try sema.resolveValue(store_inst.data.bin_op.rhs)).?;
4045 const new_ptr = ptr_mapping.get(air_ptr_inst).?;4006 const new_ptr = ptr_mapping.get(air_ptr_inst).?;
4046 try sema.storePtrVal(block, .unneeded, Value.fromInterned(new_ptr), store_val, Type.fromInterned(zcu.intern_pool.typeOf(store_val.toIntern())));4007 try sema.storePtrVal(block, LazySrcLoc.unneeded, Value.fromInterned(new_ptr), store_val, Type.fromInterned(zcu.intern_pool.typeOf(store_val.toIntern())));
4047 },4008 },
4048 else => unreachable,4009 else => unreachable,
4049 }4010 }
4050 }4011 }
40514012
4052 // The value is finalized - load it!4013 // The value is finalized - load it!
4053 const val = (try sema.pointerDeref(block, .unneeded, Value.fromInterned(alloc_ptr), alloc_ty)).?.toIntern();4014 const val = (try sema.pointerDeref(block, LazySrcLoc.unneeded, Value.fromInterned(alloc_ptr), alloc_ty)).?.toIntern();
4054 return sema.finishResolveComptimeKnownAllocPtr(block, alloc_ty, val, ct_alloc, alloc_inst, comptime_info.value);4015 return sema.finishResolveComptimeKnownAllocPtr(block, alloc_ty, val, ct_alloc, alloc_inst, comptime_info.value);
4055}4016}
40564017
...@@ -4153,7 +4114,7 @@ fn zirAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.I...@@ -4153,7 +4114,7 @@ fn zirAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.I
4153 defer tracy.end();4114 defer tracy.end();
41544115
4155 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;4116 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
4156 const ty_src: LazySrcLoc = .{ .node_offset_var_decl_ty = inst_data.src_node };4117 const ty_src = block.src(.{ .node_offset_var_decl_ty = inst_data.src_node });
4157 const var_ty = try sema.resolveType(block, ty_src, inst_data.operand);4118 const var_ty = try sema.resolveType(block, ty_src, inst_data.operand);
4158 if (block.is_comptime) {4119 if (block.is_comptime) {
4159 return sema.analyzeComptimeAlloc(block, var_ty, .none);4120 return sema.analyzeComptimeAlloc(block, var_ty, .none);
...@@ -4176,7 +4137,7 @@ fn zirAllocMut(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -4176,7 +4137,7 @@ fn zirAllocMut(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
4176 defer tracy.end();4137 defer tracy.end();
41774138
4178 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;4139 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
4179 const ty_src: LazySrcLoc = .{ .node_offset_var_decl_ty = inst_data.src_node };4140 const ty_src = block.src(.{ .node_offset_var_decl_ty = inst_data.src_node });
4180 const var_ty = try sema.resolveType(block, ty_src, inst_data.operand);4141 const var_ty = try sema.resolveType(block, ty_src, inst_data.operand);
4181 if (block.is_comptime) {4142 if (block.is_comptime) {
4182 return sema.analyzeComptimeAlloc(block, var_ty, .none);4143 return sema.analyzeComptimeAlloc(block, var_ty, .none);
...@@ -4236,7 +4197,7 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com...@@ -4236,7 +4197,7 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com
4236 const gpa = sema.gpa;4197 const gpa = sema.gpa;
4237 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;4198 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
4238 const src = block.nodeOffset(inst_data.src_node);4199 const src = block.nodeOffset(inst_data.src_node);
4239 const ty_src: LazySrcLoc = .{ .node_offset_var_decl_ty = inst_data.src_node };4200 const ty_src = block.src(.{ .node_offset_var_decl_ty = inst_data.src_node });
4240 const ptr = try sema.resolveInst(inst_data.operand);4201 const ptr = try sema.resolveInst(inst_data.operand);
4241 const ptr_inst = ptr.toIndex().?;4202 const ptr_inst = ptr.toIndex().?;
4242 const target = mod.getTarget();4203 const target = mod.getTarget();
...@@ -4399,20 +4360,20 @@ fn zirForLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air....@@ -4399,20 +4360,20 @@ fn zirForLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
4399 .Int, .ComptimeInt => true,4360 .Int, .ComptimeInt => true,
4400 else => false,4361 else => false,
4401 };4362 };
4402 const arg_src: LazySrcLoc = .{ .for_input = .{4363 const arg_src = block.src(.{ .for_input = .{
4403 .for_node_offset = inst_data.src_node,4364 .for_node_offset = inst_data.src_node,
4404 .input_index = i,4365 .input_index = i,
4405 } };4366 } });
4406 const arg_len_uncoerced = if (is_int) object else l: {4367 const arg_len_uncoerced = if (is_int) object else l: {
4407 if (!object_ty.isIndexable(mod)) {4368 if (!object_ty.isIndexable(mod)) {
4408 // Instead of using checkIndexable we customize this error.4369 // Instead of using checkIndexable we customize this error.
4409 const msg = msg: {4370 const msg = msg: {
4410 const msg = try sema.errMsg(block, arg_src, "type '{}' is not indexable and not a range", .{object_ty.fmt(sema.mod)});4371 const msg = try sema.errMsg(arg_src, "type '{}' is not indexable and not a range", .{object_ty.fmt(sema.mod)});
4411 errdefer msg.destroy(sema.gpa);4372 errdefer msg.destroy(sema.gpa);
4412 try sema.errNote(block, arg_src, msg, "for loop operand must be a range, array, slice, tuple, or vector", .{});4373 try sema.errNote(arg_src, msg, "for loop operand must be a range, array, slice, tuple, or vector", .{});
44134374
4414 if (object_ty.zigTypeTag(mod) == .ErrorUnion) {4375 if (object_ty.zigTypeTag(mod) == .ErrorUnion) {
4415 try sema.errNote(block, arg_src, msg, "consider using 'try', 'catch', or 'if'", .{});4376 try sema.errNote(arg_src, msg, "consider using 'try', 'catch', or 'if'", .{});
4416 }4377 }
44174378
4418 break :msg msg;4379 break :msg msg;
...@@ -4432,16 +4393,16 @@ fn zirForLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air....@@ -4432,16 +4393,16 @@ fn zirForLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
4432 if (len_val) |v| {4393 if (len_val) |v| {
4433 if (!(try sema.valuesEqual(arg_val, v, Type.usize))) {4394 if (!(try sema.valuesEqual(arg_val, v, Type.usize))) {
4434 const msg = msg: {4395 const msg = msg: {
4435 const msg = try sema.errMsg(block, src, "non-matching for loop lengths", .{});4396 const msg = try sema.errMsg(src, "non-matching for loop lengths", .{});
4436 errdefer msg.destroy(gpa);4397 errdefer msg.destroy(gpa);
4437 const a_src: LazySrcLoc = .{ .for_input = .{4398 const a_src = block.src(.{ .for_input = .{
4438 .for_node_offset = inst_data.src_node,4399 .for_node_offset = inst_data.src_node,
4439 .input_index = len_idx,4400 .input_index = len_idx,
4440 } };4401 } });
4441 try sema.errNote(block, a_src, msg, "length {} here", .{4402 try sema.errNote(a_src, msg, "length {} here", .{
4442 v.fmtValue(sema.mod, sema),4403 v.fmtValue(sema.mod, sema),
4443 });4404 });
4444 try sema.errNote(block, arg_src, msg, "length {} here", .{4405 try sema.errNote(arg_src, msg, "length {} here", .{
4445 arg_val.fmtValue(sema.mod, sema),4406 arg_val.fmtValue(sema.mod, sema),
4446 });4407 });
4447 break :msg msg;4408 break :msg msg;
...@@ -4461,7 +4422,7 @@ fn zirForLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air....@@ -4461,7 +4422,7 @@ fn zirForLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
44614422
4462 if (len == .none) {4423 if (len == .none) {
4463 const msg = msg: {4424 const msg = msg: {
4464 const msg = try sema.errMsg(block, src, "unbounded for loop", .{});4425 const msg = try sema.errMsg(src, "unbounded for loop", .{});
4465 errdefer msg.destroy(gpa);4426 errdefer msg.destroy(gpa);
4466 for (args, 0..) |zir_arg, i_usize| {4427 for (args, 0..) |zir_arg, i_usize| {
4467 const i: u32 = @intCast(i_usize);4428 const i: u32 = @intCast(i_usize);
...@@ -4474,11 +4435,11 @@ fn zirForLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air....@@ -4474,11 +4435,11 @@ fn zirForLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
4474 .Int, .ComptimeInt => continue,4435 .Int, .ComptimeInt => continue,
4475 else => {},4436 else => {},
4476 }4437 }
4477 const arg_src: LazySrcLoc = .{ .for_input = .{4438 const arg_src = block.src(.{ .for_input = .{
4478 .for_node_offset = inst_data.src_node,4439 .for_node_offset = inst_data.src_node,
4479 .input_index = i,4440 .input_index = i,
4480 } };4441 } });
4481 try sema.errNote(block, arg_src, msg, "type '{}' has no upper bound", .{4442 try sema.errNote(arg_src, msg, "type '{}' has no upper bound", .{
4482 object_ty.fmt(sema.mod),4443 object_ty.fmt(sema.mod),
4483 });4444 });
4484 }4445 }
...@@ -4528,7 +4489,7 @@ fn zirCoercePtrElemTy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE...@@ -4528,7 +4489,7 @@ fn zirCoercePtrElemTy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE
4528 const src = block.nodeOffset(pl_node.src_node);4489 const src = block.nodeOffset(pl_node.src_node);
4529 const extra = sema.code.extraData(Zir.Inst.Bin, pl_node.payload_index).data;4490 const extra = sema.code.extraData(Zir.Inst.Bin, pl_node.payload_index).data;
4530 const uncoerced_val = try sema.resolveInst(extra.rhs);4491 const uncoerced_val = try sema.resolveInst(extra.rhs);
4531 const maybe_wrapped_ptr_ty = sema.resolveType(block, .unneeded, extra.lhs) catch |err| switch (err) {4492 const maybe_wrapped_ptr_ty = sema.resolveType(block, LazySrcLoc.unneeded, extra.lhs) catch |err| switch (err) {
4532 error.GenericPoison => return uncoerced_val,4493 error.GenericPoison => return uncoerced_val,
4533 else => |e| return e,4494 else => |e| return e,
4534 };4495 };
...@@ -4590,9 +4551,9 @@ fn zirValidateRefTy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr...@@ -4590,9 +4551,9 @@ fn zirValidateRefTy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr
4590 if (ty_operand.isGenericPoison()) return;4551 if (ty_operand.isGenericPoison()) return;
4591 if (ty_operand.optEuBaseType(mod).zigTypeTag(mod) != .Pointer) {4552 if (ty_operand.optEuBaseType(mod).zigTypeTag(mod) != .Pointer) {
4592 return sema.failWithOwnedErrorMsg(block, msg: {4553 return sema.failWithOwnedErrorMsg(block, msg: {
4593 const msg = try sema.errMsg(block, src, "expected type '{}', found pointer", .{ty_operand.fmt(mod)});4554 const msg = try sema.errMsg(src, "expected type '{}', found pointer", .{ty_operand.fmt(mod)});
4594 errdefer msg.destroy(sema.gpa);4555 errdefer msg.destroy(sema.gpa);
4595 try sema.errNote(block, src, msg, "address-of operator always returns a pointer", .{});4556 try sema.errNote(src, msg, "address-of operator always returns a pointer", .{});
4596 break :msg msg;4557 break :msg msg;
4597 });4558 });
4598 }4559 }
...@@ -4607,7 +4568,7 @@ fn zirValidateArrayInitRefTy(...@@ -4607,7 +4568,7 @@ fn zirValidateArrayInitRefTy(
4607 const pl_node = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;4568 const pl_node = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
4608 const src = block.nodeOffset(pl_node.src_node);4569 const src = block.nodeOffset(pl_node.src_node);
4609 const extra = sema.code.extraData(Zir.Inst.ArrayInitRefTy, pl_node.payload_index).data;4570 const extra = sema.code.extraData(Zir.Inst.ArrayInitRefTy, pl_node.payload_index).data;
4610 const maybe_wrapped_ptr_ty = sema.resolveType(block, .unneeded, extra.ptr_ty) catch |err| switch (err) {4571 const maybe_wrapped_ptr_ty = sema.resolveType(block, LazySrcLoc.unneeded, extra.ptr_ty) catch |err| switch (err) {
4611 error.GenericPoison => return .generic_poison_type,4572 error.GenericPoison => return .generic_poison_type,
4612 else => |e| return e,4573 else => |e| return e,
4613 };4574 };
...@@ -4648,7 +4609,7 @@ fn zirValidateArrayInitTy(...@@ -4648,7 +4609,7 @@ fn zirValidateArrayInitTy(
4648 const mod = sema.mod;4609 const mod = sema.mod;
4649 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;4610 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
4650 const src = block.nodeOffset(inst_data.src_node);4611 const src = block.nodeOffset(inst_data.src_node);
4651 const ty_src: LazySrcLoc = if (is_result_ty) src else .{ .node_offset_init_ty = inst_data.src_node };4612 const ty_src: LazySrcLoc = if (is_result_ty) src else block.src(.{ .node_offset_init_ty = inst_data.src_node });
4652 const extra = sema.code.extraData(Zir.Inst.ArrayInit, inst_data.payload_index).data;4613 const extra = sema.code.extraData(Zir.Inst.ArrayInit, inst_data.payload_index).data;
4653 const ty = sema.resolveType(block, ty_src, extra.ty) catch |err| switch (err) {4614 const ty = sema.resolveType(block, ty_src, extra.ty) catch |err| switch (err) {
4654 // It's okay for the type to be unknown: this will result in an anonymous array init.4615 // It's okay for the type to be unknown: this will result in an anonymous array init.
...@@ -4774,7 +4735,6 @@ fn validateUnionInit(...@@ -4774,7 +4735,6 @@ fn validateUnionInit(
4774 if (instrs.len != 1) {4735 if (instrs.len != 1) {
4775 const msg = msg: {4736 const msg = msg: {
4776 const msg = try sema.errMsg(4737 const msg = try sema.errMsg(
4777 block,
4778 init_src,4738 init_src,
4779 "cannot initialize multiple union fields at once; unions can only have one active field",4739 "cannot initialize multiple union fields at once; unions can only have one active field",
4780 .{},4740 .{},
...@@ -4783,8 +4743,8 @@ fn validateUnionInit(...@@ -4783,8 +4743,8 @@ fn validateUnionInit(
47834743
4784 for (instrs[1..]) |inst| {4744 for (instrs[1..]) |inst| {
4785 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;4745 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
4786 const inst_src: LazySrcLoc = .{ .node_offset_initializer = inst_data.src_node };4746 const inst_src = block.src(.{ .node_offset_initializer = inst_data.src_node });
4787 try sema.errNote(block, inst_src, msg, "additional initializer here", .{});4747 try sema.errNote(inst_src, msg, "additional initializer here", .{});
4788 }4748 }
4789 try sema.addDeclaredHereNote(msg, union_ty);4749 try sema.addDeclaredHereNote(msg, union_ty);
4790 break :msg msg;4750 break :msg msg;
...@@ -4801,7 +4761,7 @@ fn validateUnionInit(...@@ -4801,7 +4761,7 @@ fn validateUnionInit(
48014761
4802 const field_ptr = instrs[0];4762 const field_ptr = instrs[0];
4803 const field_ptr_data = sema.code.instructions.items(.data)[@intFromEnum(field_ptr)].pl_node;4763 const field_ptr_data = sema.code.instructions.items(.data)[@intFromEnum(field_ptr)].pl_node;
4804 const field_src: LazySrcLoc = .{ .node_offset_initializer = field_ptr_data.src_node };4764 const field_src = block.src(.{ .node_offset_initializer = field_ptr_data.src_node });
4805 const field_ptr_extra = sema.code.extraData(Zir.Inst.Field, field_ptr_data.payload_index).data;4765 const field_ptr_extra = sema.code.extraData(Zir.Inst.Field, field_ptr_data.payload_index).data;
4806 const field_name = try mod.intern_pool.getOrPutString(4766 const field_name = try mod.intern_pool.getOrPutString(
4807 gpa,4767 gpa,
...@@ -4918,7 +4878,7 @@ fn validateUnionInit(...@@ -4918,7 +4878,7 @@ fn validateUnionInit(
49184878
4919 const new_tag = Air.internedToRef(tag_val.toIntern());4879 const new_tag = Air.internedToRef(tag_val.toIntern());
4920 const set_tag_inst = try block.addBinOp(.set_union_tag, union_ptr, new_tag);4880 const set_tag_inst = try block.addBinOp(.set_union_tag, union_ptr, new_tag);
4921 try sema.checkComptimeKnownStore(block, set_tag_inst, .unneeded); // `unneeded` since this isn't a "proper" store4881 try sema.checkComptimeKnownStore(block, set_tag_inst, LazySrcLoc.unneeded); // `unneeded` since this isn't a "proper" store
4922}4882}
49234883
4924fn validateStructInit(4884fn validateStructInit(
...@@ -4944,7 +4904,7 @@ fn validateStructInit(...@@ -4944,7 +4904,7 @@ fn validateStructInit(
49444904
4945 for (instrs, field_indices) |field_ptr, *field_index| {4905 for (instrs, field_indices) |field_ptr, *field_index| {
4946 const field_ptr_data = sema.code.instructions.items(.data)[@intFromEnum(field_ptr)].pl_node;4906 const field_ptr_data = sema.code.instructions.items(.data)[@intFromEnum(field_ptr)].pl_node;
4947 const field_src: LazySrcLoc = .{ .node_offset_initializer = field_ptr_data.src_node };4907 const field_src = block.src(.{ .node_offset_initializer = field_ptr_data.src_node });
4948 const field_ptr_extra = sema.code.extraData(Zir.Inst.Field, field_ptr_data.payload_index).data;4908 const field_ptr_extra = sema.code.extraData(Zir.Inst.Field, field_ptr_data.payload_index).data;
4949 struct_ptr_zir_ref = field_ptr_extra.lhs;4909 struct_ptr_zir_ref = field_ptr_extra.lhs;
4950 const field_name = try ip.getOrPutString(4910 const field_name = try ip.getOrPutString(
...@@ -4981,18 +4941,18 @@ fn validateStructInit(...@@ -4981,18 +4941,18 @@ fn validateStructInit(
4981 const field_name = struct_ty.structFieldName(i, mod).unwrap() orelse {4941 const field_name = struct_ty.structFieldName(i, mod).unwrap() orelse {
4982 const template = "missing tuple field with index {d}";4942 const template = "missing tuple field with index {d}";
4983 if (root_msg) |msg| {4943 if (root_msg) |msg| {
4984 try sema.errNote(block, init_src, msg, template, .{i});4944 try sema.errNote(init_src, msg, template, .{i});
4985 } else {4945 } else {
4986 root_msg = try sema.errMsg(block, init_src, template, .{i});4946 root_msg = try sema.errMsg(init_src, template, .{i});
4987 }4947 }
4988 continue;4948 continue;
4989 };4949 };
4990 const template = "missing struct field: {}";4950 const template = "missing struct field: {}";
4991 const args = .{field_name.fmt(ip)};4951 const args = .{field_name.fmt(ip)};
4992 if (root_msg) |msg| {4952 if (root_msg) |msg| {
4993 try sema.errNote(block, init_src, msg, template, args);4953 try sema.errNote(init_src, msg, template, args);
4994 } else {4954 } else {
4995 root_msg = try sema.errMsg(block, init_src, template, args);4955 root_msg = try sema.errMsg(init_src, template, args);
4996 }4956 }
4997 continue;4957 continue;
4998 }4958 }
...@@ -5007,16 +4967,7 @@ fn validateStructInit(...@@ -5007,16 +4967,7 @@ fn validateStructInit(
5007 }4967 }
50084968
5009 if (root_msg) |msg| {4969 if (root_msg) |msg| {
5010 if (mod.typeToStruct(struct_ty)) |struct_type| {4970 try sema.addDeclaredHereNote(msg, struct_ty);
5011 const decl = mod.declPtr(struct_type.decl.unwrap().?);
5012 const fqn = try decl.fullyQualifiedName(mod);
5013 try mod.errNoteNonLazy(
5014 decl.srcLoc(mod),
5015 msg,
5016 "struct '{}' declared here",
5017 .{fqn.fmt(ip)},
5018 );
5019 }
5020 root_msg = null;4971 root_msg = null;
5021 return sema.failWithOwnedErrorMsg(block, msg);4972 return sema.failWithOwnedErrorMsg(block, msg);
5022 }4973 }
...@@ -5118,18 +5069,18 @@ fn validateStructInit(...@@ -5118,18 +5069,18 @@ fn validateStructInit(
5118 const field_name = struct_ty.structFieldName(i, mod).unwrap() orelse {5069 const field_name = struct_ty.structFieldName(i, mod).unwrap() orelse {
5119 const template = "missing tuple field with index {d}";5070 const template = "missing tuple field with index {d}";
5120 if (root_msg) |msg| {5071 if (root_msg) |msg| {
5121 try sema.errNote(block, init_src, msg, template, .{i});5072 try sema.errNote(init_src, msg, template, .{i});
5122 } else {5073 } else {
5123 root_msg = try sema.errMsg(block, init_src, template, .{i});5074 root_msg = try sema.errMsg(init_src, template, .{i});
5124 }5075 }
5125 continue;5076 continue;
5126 };5077 };
5127 const template = "missing struct field: {}";5078 const template = "missing struct field: {}";
5128 const args = .{field_name.fmt(ip)};5079 const args = .{field_name.fmt(ip)};
5129 if (root_msg) |msg| {5080 if (root_msg) |msg| {
5130 try sema.errNote(block, init_src, msg, template, args);5081 try sema.errNote(init_src, msg, template, args);
5131 } else {5082 } else {
5132 root_msg = try sema.errMsg(block, init_src, template, args);5083 root_msg = try sema.errMsg(init_src, template, args);
5133 }5084 }
5134 continue;5085 continue;
5135 }5086 }
...@@ -5137,21 +5088,12 @@ fn validateStructInit(...@@ -5137,21 +5088,12 @@ fn validateStructInit(
5137 }5088 }
51385089
5139 if (!struct_is_comptime and !fields_allow_runtime and root_msg == null) {5090 if (!struct_is_comptime and !fields_allow_runtime and root_msg == null) {
5140 root_msg = try sema.errMsg(block, init_src, "runtime value contains reference to comptime var", .{});5091 root_msg = try sema.errMsg(init_src, "runtime value contains reference to comptime var", .{});
5141 try sema.errNote(block, init_src, root_msg.?, "comptime var pointers are not available at runtime", .{});5092 try sema.errNote(init_src, root_msg.?, "comptime var pointers are not available at runtime", .{});
5142 }5093 }
51435094
5144 if (root_msg) |msg| {5095 if (root_msg) |msg| {
5145 if (mod.typeToStruct(struct_ty)) |struct_type| {5096 try sema.addDeclaredHereNote(msg, struct_ty);
5146 const decl = mod.declPtr(struct_type.decl.unwrap().?);
5147 const fqn = try decl.fullyQualifiedName(mod);
5148 try mod.errNoteNonLazy(
5149 decl.srcLoc(mod),
5150 msg,
5151 "struct '{}' declared here",
5152 .{fqn.fmt(ip)},
5153 );
5154 }
5155 root_msg = null;5097 root_msg = null;
5156 return sema.failWithOwnedErrorMsg(block, msg);5098 return sema.failWithOwnedErrorMsg(block, msg);
5157 }5099 }
...@@ -5253,9 +5195,9 @@ fn zirValidatePtrArrayInit(...@@ -5253,9 +5195,9 @@ fn zirValidatePtrArrayInit(
5253 if (default_val == .unreachable_value) {5195 if (default_val == .unreachable_value) {
5254 const template = "missing tuple field with index {d}";5196 const template = "missing tuple field with index {d}";
5255 if (root_msg) |msg| {5197 if (root_msg) |msg| {
5256 try sema.errNote(block, init_src, msg, template, .{i});5198 try sema.errNote(init_src, msg, template, .{i});
5257 } else {5199 } else {
5258 root_msg = try sema.errMsg(block, init_src, template, .{i});5200 root_msg = try sema.errMsg(init_src, template, .{i});
5259 }5201 }
5260 continue;5202 continue;
5261 }5203 }
...@@ -5455,15 +5397,13 @@ fn zirValidateDeref(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr...@@ -5455,15 +5397,13 @@ fn zirValidateDeref(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr
5455 } else if (try sema.typeRequiresComptime(elem_ty)) {5397 } else if (try sema.typeRequiresComptime(elem_ty)) {
5456 const msg = msg: {5398 const msg = msg: {
5457 const msg = try sema.errMsg(5399 const msg = try sema.errMsg(
5458 block,
5459 src,5400 src,
5460 "values of type '{}' must be comptime-known, but operand value is runtime-known",5401 "values of type '{}' must be comptime-known, but operand value is runtime-known",
5461 .{elem_ty.fmt(mod)},5402 .{elem_ty.fmt(mod)},
5462 );5403 );
5463 errdefer msg.destroy(sema.gpa);5404 errdefer msg.destroy(sema.gpa);
54645405
5465 const src_decl = mod.declPtr(block.src_decl);5406 try sema.explainWhyTypeIsComptime(msg, src, elem_ty);
5466 try sema.explainWhyTypeIsComptime(msg, src_decl.toSrcLoc(src, mod), elem_ty);
5467 break :msg msg;5407 break :msg msg;
5468 };5408 };
5469 return sema.failWithOwnedErrorMsg(block, msg);5409 return sema.failWithOwnedErrorMsg(block, msg);
...@@ -5475,7 +5415,7 @@ fn zirValidateDestructure(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp...@@ -5475,7 +5415,7 @@ fn zirValidateDestructure(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp
5475 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;5415 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
5476 const extra = sema.code.extraData(Zir.Inst.ValidateDestructure, inst_data.payload_index).data;5416 const extra = sema.code.extraData(Zir.Inst.ValidateDestructure, inst_data.payload_index).data;
5477 const src = block.nodeOffset(inst_data.src_node);5417 const src = block.nodeOffset(inst_data.src_node);
5478 const destructure_src = LazySrcLoc.nodeOffset(extra.destructure_node);5418 const destructure_src = block.nodeOffset(extra.destructure_node);
5479 const operand = try sema.resolveInst(extra.operand);5419 const operand = try sema.resolveInst(extra.operand);
5480 const operand_ty = sema.typeOf(operand);5420 const operand_ty = sema.typeOf(operand);
54815421
...@@ -5487,21 +5427,21 @@ fn zirValidateDestructure(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp...@@ -5487,21 +5427,21 @@ fn zirValidateDestructure(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp
54875427
5488 if (!can_destructure) {5428 if (!can_destructure) {
5489 return sema.failWithOwnedErrorMsg(block, msg: {5429 return sema.failWithOwnedErrorMsg(block, msg: {
5490 const msg = try sema.errMsg(block, src, "type '{}' cannot be destructured", .{operand_ty.fmt(mod)});5430 const msg = try sema.errMsg(src, "type '{}' cannot be destructured", .{operand_ty.fmt(mod)});
5491 errdefer msg.destroy(sema.gpa);5431 errdefer msg.destroy(sema.gpa);
5492 try sema.errNote(block, destructure_src, msg, "result destructured here", .{});5432 try sema.errNote(destructure_src, msg, "result destructured here", .{});
5493 break :msg msg;5433 break :msg msg;
5494 });5434 });
5495 }5435 }
54965436
5497 if (operand_ty.arrayLen(mod) != extra.expect_len) {5437 if (operand_ty.arrayLen(mod) != extra.expect_len) {
5498 return sema.failWithOwnedErrorMsg(block, msg: {5438 return sema.failWithOwnedErrorMsg(block, msg: {
5499 const msg = try sema.errMsg(block, src, "expected {} elements for destructure, found {}", .{5439 const msg = try sema.errMsg(src, "expected {} elements for destructure, found {}", .{
5500 extra.expect_len,5440 extra.expect_len,
5501 operand_ty.arrayLen(mod),5441 operand_ty.arrayLen(mod),
5502 });5442 });
5503 errdefer msg.destroy(sema.gpa);5443 errdefer msg.destroy(sema.gpa);
5504 try sema.errNote(block, destructure_src, msg, "result destructured here", .{});5444 try sema.errNote(destructure_src, msg, "result destructured here", .{});
5505 break :msg msg;5445 break :msg msg;
5506 });5446 });
5507 }5447 }
...@@ -5536,24 +5476,24 @@ fn failWithBadMemberAccess(...@@ -5536,24 +5476,24 @@ fn failWithBadMemberAccess(
5536fn failWithBadStructFieldAccess(5476fn failWithBadStructFieldAccess(
5537 sema: *Sema,5477 sema: *Sema,
5538 block: *Block,5478 block: *Block,
5479 struct_ty: Type,
5539 struct_type: InternPool.LoadedStructType,5480 struct_type: InternPool.LoadedStructType,
5540 field_src: LazySrcLoc,5481 field_src: LazySrcLoc,
5541 field_name: InternPool.NullTerminatedString,5482 field_name: InternPool.NullTerminatedString,
5542) CompileError {5483) CompileError {
5543 const mod = sema.mod;5484 const zcu = sema.mod;
5544 const gpa = sema.gpa;5485 const gpa = sema.gpa;
5545 const decl = mod.declPtr(struct_type.decl.unwrap().?);5486 const decl = zcu.declPtr(struct_type.decl.unwrap().?);
5546 const fqn = try decl.fullyQualifiedName(mod);5487 const fqn = try decl.fullyQualifiedName(zcu);
55475488
5548 const msg = msg: {5489 const msg = msg: {
5549 const msg = try sema.errMsg(5490 const msg = try sema.errMsg(
5550 block,
5551 field_src,5491 field_src,
5552 "no field named '{}' in struct '{}'",5492 "no field named '{}' in struct '{}'",
5553 .{ field_name.fmt(&mod.intern_pool), fqn.fmt(&mod.intern_pool) },5493 .{ field_name.fmt(&zcu.intern_pool), fqn.fmt(&zcu.intern_pool) },
5554 );5494 );
5555 errdefer msg.destroy(gpa);5495 errdefer msg.destroy(gpa);
5556 try mod.errNoteNonLazy(decl.srcLoc(mod), msg, "struct declared here", .{});5496 try sema.errNote(struct_ty.srcLoc(zcu), msg, "struct declared here", .{});
5557 break :msg msg;5497 break :msg msg;
5558 };5498 };
5559 return sema.failWithOwnedErrorMsg(block, msg);5499 return sema.failWithOwnedErrorMsg(block, msg);
...@@ -5562,25 +5502,25 @@ fn failWithBadStructFieldAccess(...@@ -5562,25 +5502,25 @@ fn failWithBadStructFieldAccess(
5562fn failWithBadUnionFieldAccess(5502fn failWithBadUnionFieldAccess(
5563 sema: *Sema,5503 sema: *Sema,
5564 block: *Block,5504 block: *Block,
5505 union_ty: Type,
5565 union_obj: InternPool.LoadedUnionType,5506 union_obj: InternPool.LoadedUnionType,
5566 field_src: LazySrcLoc,5507 field_src: LazySrcLoc,
5567 field_name: InternPool.NullTerminatedString,5508 field_name: InternPool.NullTerminatedString,
5568) CompileError {5509) CompileError {
5569 const mod = sema.mod;5510 const zcu = sema.mod;
5570 const gpa = sema.gpa;5511 const gpa = sema.gpa;
55715512
5572 const decl = mod.declPtr(union_obj.decl);5513 const decl = zcu.declPtr(union_obj.decl);
5573 const fqn = try decl.fullyQualifiedName(mod);5514 const fqn = try decl.fullyQualifiedName(zcu);
55745515
5575 const msg = msg: {5516 const msg = msg: {
5576 const msg = try sema.errMsg(5517 const msg = try sema.errMsg(
5577 block,
5578 field_src,5518 field_src,
5579 "no field named '{}' in union '{}'",5519 "no field named '{}' in union '{}'",
5580 .{ field_name.fmt(&mod.intern_pool), fqn.fmt(&mod.intern_pool) },5520 .{ field_name.fmt(&zcu.intern_pool), fqn.fmt(&zcu.intern_pool) },
5581 );5521 );
5582 errdefer msg.destroy(gpa);5522 errdefer msg.destroy(gpa);
5583 try mod.errNoteNonLazy(decl.srcLoc(mod), msg, "union declared here", .{});5523 try sema.errNote(union_ty.srcLoc(zcu), msg, "union declared here", .{});
5584 break :msg msg;5524 break :msg msg;
5585 };5525 };
5586 return sema.failWithOwnedErrorMsg(block, msg);5526 return sema.failWithOwnedErrorMsg(block, msg);
...@@ -5588,16 +5528,15 @@ fn failWithBadUnionFieldAccess(...@@ -5588,16 +5528,15 @@ fn failWithBadUnionFieldAccess(
55885528
5589fn addDeclaredHereNote(sema: *Sema, parent: *Module.ErrorMsg, decl_ty: Type) !void {5529fn addDeclaredHereNote(sema: *Sema, parent: *Module.ErrorMsg, decl_ty: Type) !void {
5590 const mod = sema.mod;5530 const mod = sema.mod;
5591 const src_loc = decl_ty.declSrcLocOrNull(mod) orelse return;5531 const src_loc = decl_ty.srcLocOrNull(mod) orelse return;
5592 const category = switch (decl_ty.zigTypeTag(mod)) {5532 const category = switch (decl_ty.zigTypeTag(mod)) {
5593 .Union => "union",5533 .Union => "union",
5594 .Struct => "struct",5534 .Struct => "struct",
5595 .Enum => "enum",5535 .Enum => "enum",
5596 .Opaque => "opaque",5536 .Opaque => "opaque",
5597 .ErrorSet => "error set",
5598 else => unreachable,5537 else => unreachable,
5599 };5538 };
5600 try mod.errNoteNonLazy(src_loc, parent, "{s} declared here", .{category});5539 try sema.errNote(src_loc, parent, "{s} declared here", .{category});
5601}5540}
56025541
5603fn zirStoreToInferredPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void {5542fn zirStoreToInferredPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void {
...@@ -5722,8 +5661,8 @@ fn zirStoreNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!v...@@ -5722,8 +5661,8 @@ fn zirStoreNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!v
5722 else => {},5661 else => {},
5723 };5662 };
57245663
5725 const ptr_src: LazySrcLoc = .{ .node_offset_store_ptr = inst_data.src_node };5664 const ptr_src = block.src(.{ .node_offset_store_ptr = inst_data.src_node });
5726 const operand_src: LazySrcLoc = .{ .node_offset_store_operand = inst_data.src_node };5665 const operand_src = block.src(.{ .node_offset_store_operand = inst_data.src_node });
5727 const air_tag: Air.Inst.Tag = if (is_ret)5666 const air_tag: Air.Inst.Tag = if (is_ret)
5728 .ret_ptr5667 .ret_ptr
5729 else if (block.wantSafety())5668 else if (block.wantSafety())
...@@ -5837,7 +5776,7 @@ fn zirCompileError(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro...@@ -5837,7 +5776,7 @@ fn zirCompileError(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
58375776
5838 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;5777 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
5839 const src = block.nodeOffset(inst_data.src_node);5778 const src = block.nodeOffset(inst_data.src_node);
5840 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };5779 const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0);
5841 const msg = try sema.resolveConstString(block, operand_src, inst_data.operand, .{5780 const msg = try sema.resolveConstString(block, operand_src, inst_data.operand, .{
5842 .needed_comptime_reason = "compile error string must be comptime-known",5781 .needed_comptime_reason = "compile error string must be comptime-known",
5843 });5782 });
...@@ -5846,6 +5785,7 @@ fn zirCompileError(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro...@@ -5846,6 +5785,7 @@ fn zirCompileError(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
58465785
5847fn zirCompileLog(5786fn zirCompileLog(
5848 sema: *Sema,5787 sema: *Sema,
5788 block: *Block,
5849 extended: Zir.Inst.Extended.InstData,5789 extended: Zir.Inst.Extended.InstData,
5850) CompileError!Air.Inst.Ref {5790) CompileError!Air.Inst.Ref {
5851 const mod = sema.mod;5791 const mod = sema.mod;
...@@ -5878,9 +5818,10 @@ fn zirCompileLog(...@@ -5878,9 +5818,10 @@ fn zirCompileLog(
5878 else5818 else
5879 sema.owner_decl_index;5819 sema.owner_decl_index;
5880 const gop = try mod.compile_log_decls.getOrPut(sema.gpa, decl_index);5820 const gop = try mod.compile_log_decls.getOrPut(sema.gpa, decl_index);
5881 if (!gop.found_existing) {5821 if (!gop.found_existing) gop.value_ptr.* = .{
5882 gop.value_ptr.* = src_node;5822 .base_node_inst = block.src_base_inst,
5883 }5823 .node_offset = src_node,
5824 };
5884 return .void_value;5825 return .void_value;
5885}5826}
58865827
...@@ -5891,7 +5832,7 @@ fn zirPanic(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void...@@ -5891,7 +5832,7 @@ fn zirPanic(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void
58915832
5892 // `panicWithMsg` would perform this coercion for us, but we can get a better5833 // `panicWithMsg` would perform this coercion for us, but we can get a better
5893 // source location if we do it here.5834 // source location if we do it here.
5894 const coerced_msg = try sema.coerce(block, Type.slice_const_u8, msg_inst, .{ .node_offset_builtin_call_arg0 = inst_data.src_node });5835 const coerced_msg = try sema.coerce(block, Type.slice_const_u8, msg_inst, block.builtinCallArgSrc(inst_data.src_node, 0));
58955836
5896 if (block.is_comptime) {5837 if (block.is_comptime) {
5897 return sema.fail(block, src, "encountered @panic at comptime", .{});5838 return sema.fail(block, src, "encountered @panic at comptime", .{});
...@@ -5901,7 +5842,7 @@ fn zirPanic(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void...@@ -5901,7 +5842,7 @@ fn zirPanic(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void
59015842
5902fn zirTrap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void {5843fn zirTrap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void {
5903 const src_node = sema.code.instructions.items(.data)[@intFromEnum(inst)].node;5844 const src_node = sema.code.instructions.items(.data)[@intFromEnum(inst)].node;
5904 const src = LazySrcLoc.nodeOffset(src_node);5845 const src = block.nodeOffset(src_node);
5905 if (block.is_comptime)5846 if (block.is_comptime)
5906 return sema.fail(block, src, "encountered @trap at comptime", .{});5847 return sema.fail(block, src, "encountered @trap at comptime", .{});
5907 _ = try block.addNoOp(.trap);5848 _ = try block.addNoOp(.trap);
...@@ -5948,7 +5889,7 @@ fn zirLoop(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError...@@ -5948,7 +5889,7 @@ fn zirLoop(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError
5948 var child_block = parent_block.makeSubBlock();5889 var child_block = parent_block.makeSubBlock();
5949 child_block.label = &label;5890 child_block.label = &label;
5950 child_block.runtime_cond = null;5891 child_block.runtime_cond = null;
5951 child_block.runtime_loop = mod.declPtr(child_block.src_decl).toSrcLoc(src, mod);5892 child_block.runtime_loop = src;
5952 child_block.runtime_index.increment();5893 child_block.runtime_index.increment();
5953 const merges = &child_block.label.?.merges;5894 const merges = &child_block.label.?.merges;
59545895
...@@ -5997,10 +5938,7 @@ fn zirCImport(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileEr...@@ -5997,10 +5938,7 @@ fn zirCImport(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileEr
5997 var c_import_buf = std.ArrayList(u8).init(gpa);5938 var c_import_buf = std.ArrayList(u8).init(gpa);
5998 defer c_import_buf.deinit();5939 defer c_import_buf.deinit();
59995940
6000 var comptime_reason: Block.ComptimeReason = .{ .c_import = .{5941 const comptime_reason: Block.ComptimeReason = .{ .c_import = .{ .src = src } };
6001 .block = parent_block,
6002 .src = src,
6003 } };
6004 var child_block: Block = .{5942 var child_block: Block = .{
6005 .parent = parent_block,5943 .parent = parent_block,
6006 .sema = sema,5944 .sema = sema,
...@@ -6014,6 +5952,7 @@ fn zirCImport(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileEr...@@ -6014,6 +5952,7 @@ fn zirCImport(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileEr
6014 .runtime_cond = parent_block.runtime_cond,5952 .runtime_cond = parent_block.runtime_cond,
6015 .runtime_loop = parent_block.runtime_loop,5953 .runtime_loop = parent_block.runtime_loop,
6016 .runtime_index = parent_block.runtime_index,5954 .runtime_index = parent_block.runtime_index,
5955 .src_base_inst = parent_block.src_base_inst,
6017 };5956 };
6018 defer child_block.instructions.deinit(gpa);5957 defer child_block.instructions.deinit(gpa);
60195958
...@@ -6025,11 +5964,11 @@ fn zirCImport(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileEr...@@ -6025,11 +5964,11 @@ fn zirCImport(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileEr
60255964
6026 if (c_import_res.errors.errorMessageCount() != 0) {5965 if (c_import_res.errors.errorMessageCount() != 0) {
6027 const msg = msg: {5966 const msg = msg: {
6028 const msg = try sema.errMsg(&child_block, src, "C import failed", .{});5967 const msg = try sema.errMsg(src, "C import failed", .{});
6029 errdefer msg.destroy(gpa);5968 errdefer msg.destroy(gpa);
60305969
6031 if (!comp.config.link_libc)5970 if (!comp.config.link_libc)
6032 try sema.errNote(&child_block, src, msg, "libc headers not available; compilation does not link against libc", .{});5971 try sema.errNote(src, msg, "libc headers not available; compilation does not link against libc", .{});
60335972
6034 const gop = try mod.cimport_errors.getOrPut(gpa, sema.owner_decl_index);5973 const gop = try mod.cimport_errors.getOrPut(gpa, sema.owner_decl_index);
6035 if (!gop.found_existing) {5974 if (!gop.found_existing) {
...@@ -6139,6 +6078,7 @@ fn zirBlock(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index, force_compt...@@ -6139,6 +6078,7 @@ fn zirBlock(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index, force_compt
6139 .runtime_loop = parent_block.runtime_loop,6078 .runtime_loop = parent_block.runtime_loop,
6140 .runtime_index = parent_block.runtime_index,6079 .runtime_index = parent_block.runtime_index,
6141 .error_return_trace_index = parent_block.error_return_trace_index,6080 .error_return_trace_index = parent_block.error_return_trace_index,
6081 .src_base_inst = parent_block.src_base_inst,
6142 };6082 };
61436083
6144 defer child_block.instructions.deinit(gpa);6084 defer child_block.instructions.deinit(gpa);
...@@ -6333,14 +6273,13 @@ fn resolveAnalyzedBlock(...@@ -6333,14 +6273,13 @@ fn resolveAnalyzedBlock(
6333 const type_src = src; // TODO: better source location6273 const type_src = src; // TODO: better source location
6334 if (try sema.typeRequiresComptime(resolved_ty)) {6274 if (try sema.typeRequiresComptime(resolved_ty)) {
6335 const msg = msg: {6275 const msg = msg: {
6336 const msg = try sema.errMsg(child_block, type_src, "value with comptime-only type '{}' depends on runtime control flow", .{resolved_ty.fmt(mod)});6276 const msg = try sema.errMsg(type_src, "value with comptime-only type '{}' depends on runtime control flow", .{resolved_ty.fmt(mod)});
6337 errdefer msg.destroy(sema.gpa);6277 errdefer msg.destroy(sema.gpa);
63386278
6339 const runtime_src = child_block.runtime_cond orelse child_block.runtime_loop.?;6279 const runtime_src = child_block.runtime_cond orelse child_block.runtime_loop.?;
6340 try mod.errNoteNonLazy(runtime_src, msg, "runtime control flow here", .{});6280 try sema.errNote(runtime_src, msg, "runtime control flow here", .{});
63416281
6342 const child_src_decl = mod.declPtr(child_block.src_decl);6282 try sema.explainWhyTypeIsComptime(msg, type_src, resolved_ty);
6343 try sema.explainWhyTypeIsComptime(msg, child_src_decl.toSrcLoc(type_src, mod), resolved_ty);
63446283
6345 break :msg msg;6284 break :msg msg;
6346 };6285 };
...@@ -6433,8 +6372,8 @@ fn zirExport(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void...@@ -6433,8 +6372,8 @@ fn zirExport(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void
6433 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;6372 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
6434 const extra = sema.code.extraData(Zir.Inst.Export, inst_data.payload_index).data;6373 const extra = sema.code.extraData(Zir.Inst.Export, inst_data.payload_index).data;
6435 const src = block.nodeOffset(inst_data.src_node);6374 const src = block.nodeOffset(inst_data.src_node);
6436 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };6375 const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0);
6437 const options_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };6376 const options_src = block.builtinCallArgSrc(inst_data.src_node, 1);
6438 const decl_name = try mod.intern_pool.getOrPutString(6377 const decl_name = try mod.intern_pool.getOrPutString(
6439 mod.gpa,6378 mod.gpa,
6440 sema.code.nullTerminatedString(extra.decl_name),6379 sema.code.nullTerminatedString(extra.decl_name),
...@@ -6448,13 +6387,7 @@ fn zirExport(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void...@@ -6448,13 +6387,7 @@ fn zirExport(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void
6448 break :index_blk maybe_index orelse6387 break :index_blk maybe_index orelse
6449 return sema.failWithBadMemberAccess(block, container_ty, operand_src, decl_name);6388 return sema.failWithBadMemberAccess(block, container_ty, operand_src, decl_name);
6450 } else try sema.lookupIdentifier(block, operand_src, decl_name);6389 } else try sema.lookupIdentifier(block, operand_src, decl_name);
6451 const options = sema.resolveExportOptions(block, .unneeded, extra.options) catch |err| switch (err) {6390 const options = try sema.resolveExportOptions(block, options_src, extra.options);
6452 error.NeededSourceLocation => {
6453 _ = try sema.resolveExportOptions(block, options_src, extra.options);
6454 unreachable;
6455 },
6456 else => |e| return e,
6457 };
6458 {6391 {
6459 try sema.ensureDeclAnalyzed(decl_index);6392 try sema.ensureDeclAnalyzed(decl_index);
6460 const exported_decl = mod.declPtr(decl_index);6393 const exported_decl = mod.declPtr(decl_index);
...@@ -6473,8 +6406,8 @@ fn zirExportValue(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError...@@ -6473,8 +6406,8 @@ fn zirExportValue(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
6473 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;6406 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
6474 const extra = sema.code.extraData(Zir.Inst.ExportValue, inst_data.payload_index).data;6407 const extra = sema.code.extraData(Zir.Inst.ExportValue, inst_data.payload_index).data;
6475 const src = block.nodeOffset(inst_data.src_node);6408 const src = block.nodeOffset(inst_data.src_node);
6476 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };6409 const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0);
6477 const options_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };6410 const options_src = block.builtinCallArgSrc(inst_data.src_node, 1);
6478 const operand = try sema.resolveInstConst(block, operand_src, extra.operand, .{6411 const operand = try sema.resolveInstConst(block, operand_src, extra.operand, .{
6479 .needed_comptime_reason = "export target must be comptime-known",6412 .needed_comptime_reason = "export target must be comptime-known",
6480 });6413 });
...@@ -6490,7 +6423,6 @@ fn zirExportValue(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError...@@ -6490,7 +6423,6 @@ fn zirExportValue(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
6490 .opts = options,6423 .opts = options,
6491 .src = src,6424 .src = src,
6492 .owner_decl = sema.owner_decl_index,6425 .owner_decl = sema.owner_decl_index,
6493 .src_decl = block.src_decl,
6494 .exported = .{ .value = operand.toIntern() },6426 .exported = .{ .value = operand.toIntern() },
6495 .status = .in_progress,6427 .status = .in_progress,
6496 });6428 });
...@@ -6515,11 +6447,10 @@ pub fn analyzeExport(...@@ -6515,11 +6447,10 @@ pub fn analyzeExport(
65156447
6516 if (!try sema.validateExternType(export_ty, .other)) {6448 if (!try sema.validateExternType(export_ty, .other)) {
6517 const msg = msg: {6449 const msg = msg: {
6518 const msg = try sema.errMsg(block, src, "unable to export type '{}'", .{export_ty.fmt(mod)});6450 const msg = try sema.errMsg(src, "unable to export type '{}'", .{export_ty.fmt(mod)});
6519 errdefer msg.destroy(gpa);6451 errdefer msg.destroy(gpa);
65206452
6521 const src_decl = mod.declPtr(block.src_decl);6453 try sema.explainWhyTypeIsNotExtern(msg, src, export_ty, .other);
6522 try sema.explainWhyTypeIsNotExtern(msg, src_decl.toSrcLoc(src, mod), export_ty, .other);
65236454
6524 try sema.addDeclaredHereNote(msg, export_ty);6455 try sema.addDeclaredHereNote(msg, export_ty);
6525 break :msg msg;6456 break :msg msg;
...@@ -6538,7 +6469,6 @@ pub fn analyzeExport(...@@ -6538,7 +6469,6 @@ pub fn analyzeExport(
6538 .opts = options,6469 .opts = options,
6539 .src = src,6470 .src = src,
6540 .owner_decl = sema.owner_decl_index,6471 .owner_decl = sema.owner_decl_index,
6541 .src_decl = block.src_decl,
6542 .exported = .{ .decl_index = exported_decl_index },6472 .exported = .{ .decl_index = exported_decl_index },
6543 .status = .in_progress,6473 .status = .in_progress,
6544 });6474 });
...@@ -6578,8 +6508,8 @@ fn addExport(mod: *Module, export_init: Module.Export) error{OutOfMemory}!void {...@@ -6578,8 +6508,8 @@ fn addExport(mod: *Module, export_init: Module.Export) error{OutOfMemory}!void {
6578fn zirSetAlignStack(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!void {6508fn zirSetAlignStack(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!void {
6579 const mod = sema.mod;6509 const mod = sema.mod;
6580 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;6510 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;
6581 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node };6511 const operand_src = block.builtinCallArgSrc(extra.node, 0);
6582 const src = LazySrcLoc.nodeOffset(extra.node);6512 const src = block.nodeOffset(extra.node);
6583 const alignment = try sema.resolveAlign(block, operand_src, extra.operand);6513 const alignment = try sema.resolveAlign(block, operand_src, extra.operand);
6584 if (alignment.order(Alignment.fromNonzeroByteUnits(256)).compare(.gt)) {6514 if (alignment.order(Alignment.fromNonzeroByteUnits(256)).compare(.gt)) {
6585 return sema.fail(block, src, "attempt to @setAlignStack({d}); maximum is 256", .{6515 return sema.fail(block, src, "attempt to @setAlignStack({d}); maximum is 256", .{
...@@ -6598,9 +6528,9 @@ fn zirSetAlignStack(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.Inst...@@ -6598,9 +6528,9 @@ fn zirSetAlignStack(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.Inst
65986528
6599 if (sema.prev_stack_alignment_src) |prev_src| {6529 if (sema.prev_stack_alignment_src) |prev_src| {
6600 const msg = msg: {6530 const msg = msg: {
6601 const msg = try sema.errMsg(block, src, "multiple @setAlignStack in the same function body", .{});6531 const msg = try sema.errMsg(src, "multiple @setAlignStack in the same function body", .{});
6602 errdefer msg.destroy(sema.gpa);6532 errdefer msg.destroy(sema.gpa);
6603 try sema.errNote(block, prev_src, msg, "other instance here", .{});6533 try sema.errNote(prev_src, msg, "other instance here", .{});
6604 break :msg msg;6534 break :msg msg;
6605 };6535 };
6606 return sema.failWithOwnedErrorMsg(block, msg);6536 return sema.failWithOwnedErrorMsg(block, msg);
...@@ -6621,7 +6551,7 @@ fn zirSetCold(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData)...@@ -6621,7 +6551,7 @@ fn zirSetCold(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData)
6621 const mod = sema.mod;6551 const mod = sema.mod;
6622 const ip = &mod.intern_pool;6552 const ip = &mod.intern_pool;
6623 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;6553 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;
6624 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node };6554 const operand_src = block.builtinCallArgSrc(extra.node, 0);
6625 const is_cold = try sema.resolveConstBool(block, operand_src, extra.operand, .{6555 const is_cold = try sema.resolveConstBool(block, operand_src, extra.operand, .{
6626 .needed_comptime_reason = "operand to @setCold must be comptime-known",6556 .needed_comptime_reason = "operand to @setCold must be comptime-known",
6627 });6557 });
...@@ -6631,7 +6561,7 @@ fn zirSetCold(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData)...@@ -6631,7 +6561,7 @@ fn zirSetCold(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData)
66316561
6632fn zirSetFloatMode(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!void {6562fn zirSetFloatMode(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!void {
6633 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;6563 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;
6634 const src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node };6564 const src = block.builtinCallArgSrc(extra.node, 0);
6635 block.float_mode = try sema.resolveBuiltinEnum(block, src, extra.operand, "FloatMode", .{6565 block.float_mode = try sema.resolveBuiltinEnum(block, src, extra.operand, "FloatMode", .{
6636 .needed_comptime_reason = "operand to @setFloatMode must be comptime-known",6566 .needed_comptime_reason = "operand to @setFloatMode must be comptime-known",
6637 });6567 });
...@@ -6639,7 +6569,7 @@ fn zirSetFloatMode(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstD...@@ -6639,7 +6569,7 @@ fn zirSetFloatMode(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstD
66396569
6640fn zirSetRuntimeSafety(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void {6570fn zirSetRuntimeSafety(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void {
6641 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;6571 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
6642 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };6572 const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0);
6643 block.want_safety = try sema.resolveConstBool(block, operand_src, inst_data.operand, .{6573 block.want_safety = try sema.resolveConstBool(block, operand_src, inst_data.operand, .{
6644 .needed_comptime_reason = "operand to @setRuntimeSafety must be comptime-known",6574 .needed_comptime_reason = "operand to @setRuntimeSafety must be comptime-known",
6645 });6575 });
...@@ -6649,7 +6579,7 @@ fn zirFence(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) Co...@@ -6649,7 +6579,7 @@ fn zirFence(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) Co
6649 if (block.is_comptime) return;6579 if (block.is_comptime) return;
66506580
6651 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;6581 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;
6652 const order_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node };6582 const order_src = block.builtinCallArgSrc(extra.node, 0);
6653 const order = try sema.resolveAtomicOrder(block, order_src, extra.operand, .{6583 const order = try sema.resolveAtomicOrder(block, order_src, extra.operand, .{
6654 .needed_comptime_reason = "atomic order of @fence must be comptime-known",6584 .needed_comptime_reason = "atomic order of @fence must be comptime-known",
6655 });6585 });
...@@ -6679,7 +6609,7 @@ fn zirBreak(sema: *Sema, start_block: *Block, inst: Zir.Inst.Index) CompileError...@@ -6679,7 +6609,7 @@ fn zirBreak(sema: *Sema, start_block: *Block, inst: Zir.Inst.Index) CompileError
6679 if (label.zir_block == zir_block) {6609 if (label.zir_block == zir_block) {
6680 const br_ref = try start_block.addBr(label.merges.block_inst, operand);6610 const br_ref = try start_block.addBr(label.merges.block_inst, operand);
6681 const src_loc = if (extra.operand_src_node != Zir.Inst.Break.no_src_node)6611 const src_loc = if (extra.operand_src_node != Zir.Inst.Break.no_src_node)
6682 LazySrcLoc.nodeOffset(extra.operand_src_node)6612 start_block.nodeOffset(extra.operand_src_node)
6683 else6613 else
6684 null;6614 null;
6685 try label.merges.src_locs.append(sema.gpa, src_loc);6615 try label.merges.src_locs.append(sema.gpa, src_loc);
...@@ -6906,12 +6836,14 @@ fn lookupInNamespace(...@@ -6906,12 +6836,14 @@ fn lookupInNamespace(
6906 },6836 },
6907 else => {6837 else => {
6908 const msg = msg: {6838 const msg = msg: {
6909 const msg = try sema.errMsg(block, src, "ambiguous reference", .{});6839 const msg = try sema.errMsg(src, "ambiguous reference", .{});
6910 errdefer msg.destroy(gpa);6840 errdefer msg.destroy(gpa);
6911 for (candidates.items) |candidate_index| {6841 for (candidates.items) |candidate_index| {
6912 const candidate = mod.declPtr(candidate_index);6842 const candidate = mod.declPtr(candidate_index);
6913 const src_loc = candidate.srcLoc(mod);6843 try sema.errNote(.{
6914 try mod.errNoteNonLazy(src_loc, msg, "declared here", .{});6844 .base_node_inst = candidate.zir_decl_index.unwrap().?,
6845 .offset = LazySrcLoc.Offset.nodeOffset(0),
6846 }, msg, "declared here", .{});
6915 }6847 }
6916 break :msg msg;6848 break :msg msg;
6917 };6849 };
...@@ -6953,16 +6885,16 @@ pub fn analyzeSaveErrRetIndex(sema: *Sema, block: *Block) SemaError!Air.Inst.Ref...@@ -6953,16 +6885,16 @@ pub fn analyzeSaveErrRetIndex(sema: *Sema, block: *Block) SemaError!Air.Inst.Ref
6953 if (!block.ownerModule().error_tracing) return .none;6885 if (!block.ownerModule().error_tracing) return .none;
69546886
6955 const stack_trace_ty = sema.getBuiltinType("StackTrace") catch |err| switch (err) {6887 const stack_trace_ty = sema.getBuiltinType("StackTrace") catch |err| switch (err) {
6956 error.NeededSourceLocation, error.GenericPoison, error.ComptimeReturn, error.ComptimeBreak => unreachable,6888 error.GenericPoison, error.ComptimeReturn, error.ComptimeBreak => unreachable,
6957 else => |e| return e,6889 else => |e| return e,
6958 };6890 };
6959 sema.resolveTypeFields(stack_trace_ty) catch |err| switch (err) {6891 sema.resolveTypeFields(stack_trace_ty) catch |err| switch (err) {
6960 error.NeededSourceLocation, error.GenericPoison, error.ComptimeReturn, error.ComptimeBreak => unreachable,6892 error.GenericPoison, error.ComptimeReturn, error.ComptimeBreak => unreachable,
6961 else => |e| return e,6893 else => |e| return e,
6962 };6894 };
6963 const field_name = try mod.intern_pool.getOrPutString(gpa, "index", .no_embedded_nulls);6895 const field_name = try mod.intern_pool.getOrPutString(gpa, "index", .no_embedded_nulls);
6964 const field_index = sema.structFieldIndex(block, stack_trace_ty, field_name, .unneeded) catch |err| switch (err) {6896 const field_index = sema.structFieldIndex(block, stack_trace_ty, field_name, LazySrcLoc.unneeded) catch |err| switch (err) {
6965 error.AnalysisFail, error.NeededSourceLocation => @panic("std.builtin.StackTrace is corrupt"),6897 error.AnalysisFail => @panic("std.builtin.StackTrace is corrupt"),
6966 error.GenericPoison, error.ComptimeReturn, error.ComptimeBreak => unreachable,6898 error.GenericPoison, error.ComptimeReturn, error.ComptimeBreak => unreachable,
6967 error.OutOfMemory => |e| return e,6899 error.OutOfMemory => |e| return e,
6968 };6900 };
...@@ -7070,7 +7002,7 @@ fn zirCall(...@@ -7070,7 +7002,7 @@ fn zirCall(
70707002
7071 const mod = sema.mod;7003 const mod = sema.mod;
7072 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;7004 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
7073 const callee_src: LazySrcLoc = .{ .node_offset_call_func = inst_data.src_node };7005 const callee_src = block.src(.{ .node_offset_call_func = inst_data.src_node });
7074 const call_src = block.nodeOffset(inst_data.src_node);7006 const call_src = block.nodeOffset(inst_data.src_node);
7075 const ExtraType = switch (kind) {7007 const ExtraType = switch (kind) {
7076 .direct => Zir.Inst.Call,7008 .direct => Zir.Inst.Call,
...@@ -7092,7 +7024,7 @@ fn zirCall(...@@ -7092,7 +7024,7 @@ fn zirCall(
7092 sema.code.nullTerminatedString(extra.data.field_name_start),7024 sema.code.nullTerminatedString(extra.data.field_name_start),
7093 .no_embedded_nulls,7025 .no_embedded_nulls,
7094 );7026 );
7095 const field_name_src: LazySrcLoc = .{ .node_offset_field_name = inst_data.src_node };7027 const field_name_src = block.src(.{ .node_offset_field_name = inst_data.src_node });
7096 break :blk try sema.fieldCallBind(block, callee_src, object_ptr, field_name, field_name_src);7028 break :blk try sema.fieldCallBind(block, callee_src, object_ptr, field_name, field_name_src);
7097 },7029 },
7098 };7030 };
...@@ -7202,11 +7134,11 @@ fn checkCallArgumentCount(...@@ -7202,11 +7134,11 @@ fn checkCallArgumentCount(
7202 opt_child.childType(mod).zigTypeTag(mod) == .Fn))7134 opt_child.childType(mod).zigTypeTag(mod) == .Fn))
7203 {7135 {
7204 const msg = msg: {7136 const msg = msg: {
7205 const msg = try sema.errMsg(block, func_src, "cannot call optional type '{}'", .{7137 const msg = try sema.errMsg(func_src, "cannot call optional type '{}'", .{
7206 callee_ty.fmt(mod),7138 callee_ty.fmt(mod),
7207 });7139 });
7208 errdefer msg.destroy(sema.gpa);7140 errdefer msg.destroy(sema.gpa);
7209 try sema.errNote(block, func_src, msg, "consider using '.?', 'orelse' or 'if'", .{});7141 try sema.errNote(func_src, msg, "consider using '.?', 'orelse' or 'if'", .{});
7210 break :msg msg;7142 break :msg msg;
7211 };7143 };
7212 return sema.failWithOwnedErrorMsg(block, msg);7144 return sema.failWithOwnedErrorMsg(block, msg);
...@@ -7232,7 +7164,6 @@ fn checkCallArgumentCount(...@@ -7232,7 +7164,6 @@ fn checkCallArgumentCount(
7232 const variadic_str = if (func_ty_info.is_var_args) "at least " else "";7164 const variadic_str = if (func_ty_info.is_var_args) "at least " else "";
7233 const msg = msg: {7165 const msg = msg: {
7234 const msg = try sema.errMsg(7166 const msg = try sema.errMsg(
7235 block,
7236 func_src,7167 func_src,
7237 "{s}expected {s}{d} argument(s), found {d}",7168 "{s}expected {s}{d} argument(s), found {d}",
7238 .{7169 .{
...@@ -7244,7 +7175,12 @@ fn checkCallArgumentCount(...@@ -7244,7 +7175,12 @@ fn checkCallArgumentCount(
7244 );7175 );
7245 errdefer msg.destroy(sema.gpa);7176 errdefer msg.destroy(sema.gpa);
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 }
7248 break :msg msg;7184 break :msg msg;
7249 };7185 };
7250 return sema.failWithOwnedErrorMsg(block, msg);7186 return sema.failWithOwnedErrorMsg(block, msg);
...@@ -7352,18 +7288,16 @@ const CallArgsInfo = union(enum) {...@@ -7352,18 +7288,16 @@ const CallArgsInfo = union(enum) {
7352 fn argSrc(cai: CallArgsInfo, block: *Block, arg_index: usize) LazySrcLoc {7288 fn argSrc(cai: CallArgsInfo, block: *Block, arg_index: usize) LazySrcLoc {
7353 return switch (cai) {7289 return switch (cai) {
7354 .resolved => |resolved| resolved.src,7290 .resolved => |resolved| resolved.src,
7355 .call_builtin => |call_builtin| .{ .call_arg = .{7291 .call_builtin => |call_builtin| block.src(.{ .call_arg = .{
7356 .decl = block.src_decl,
7357 .call_node_offset = call_builtin.call_node_offset,7292 .call_node_offset = call_builtin.call_node_offset,
7358 .arg_index = @intCast(arg_index),7293 .arg_index = @intCast(arg_index),
7359 } },7294 } }),
7360 .zir_call => |zir_call| if (arg_index == 0 and zir_call.bound_arg != .none) {7295 .zir_call => |zir_call| if (arg_index == 0 and zir_call.bound_arg != .none) {
7361 return zir_call.bound_arg_src;7296 return zir_call.bound_arg_src;
7362 } else .{ .call_arg = .{7297 } else block.src(.{ .call_arg = .{
7363 .decl = block.src_decl,
7364 .call_node_offset = zir_call.call_node_offset,7298 .call_node_offset = zir_call.call_node_offset,
7365 .arg_index = @intCast(arg_index - @intFromBool(zir_call.bound_arg != .none)),7299 .arg_index = @intCast(arg_index - @intFromBool(zir_call.bound_arg != .none)),
7366 } },7300 } }),
7367 };7301 };
7368 }7302 }
73697303
...@@ -7475,7 +7409,6 @@ const InlineCallSema = struct {...@@ -7475,7 +7409,6 @@ const InlineCallSema = struct {
7475 other_error_return_trace_index_on_fn_entry: Air.Inst.Ref,7409 other_error_return_trace_index_on_fn_entry: Air.Inst.Ref,
7476 other_generic_owner: InternPool.Index,7410 other_generic_owner: InternPool.Index,
7477 other_generic_call_src: LazySrcLoc,7411 other_generic_call_src: LazySrcLoc,
7478 other_generic_call_decl: InternPool.OptionalDeclIndex,
74797412
7480 /// Sema should currently be set up for the caller (i.e. unchanged yet). This init will not7413 /// Sema should currently be set up for the caller (i.e. unchanged yet). This init will not
7481 /// change that. The other parameters contain data for the callee Sema. The other modified7414 /// change that. The other parameters contain data for the callee Sema. The other modified
...@@ -7497,8 +7430,7 @@ const InlineCallSema = struct {...@@ -7497,8 +7430,7 @@ const InlineCallSema = struct {
7497 .other_inst_map = .{},7430 .other_inst_map = .{},
7498 .other_error_return_trace_index_on_fn_entry = callee_error_return_trace_index_on_fn_entry,7431 .other_error_return_trace_index_on_fn_entry = callee_error_return_trace_index_on_fn_entry,
7499 .other_generic_owner = .none,7432 .other_generic_owner = .none,
7500 .other_generic_call_src = .unneeded,7433 .other_generic_call_src = LazySrcLoc.unneeded,
7501 .other_generic_call_decl = .none,
7502 };7434 };
7503 }7435 }
75047436
...@@ -7545,7 +7477,6 @@ const InlineCallSema = struct {...@@ -7545,7 +7477,6 @@ const InlineCallSema = struct {
7545 std.mem.swap(InstMap, &ics.sema.inst_map, &ics.other_inst_map);7477 std.mem.swap(InstMap, &ics.sema.inst_map, &ics.other_inst_map);
7546 std.mem.swap(InternPool.Index, &ics.sema.generic_owner, &ics.other_generic_owner);7478 std.mem.swap(InternPool.Index, &ics.sema.generic_owner, &ics.other_generic_owner);
7547 std.mem.swap(LazySrcLoc, &ics.sema.generic_call_src, &ics.other_generic_call_src);7479 std.mem.swap(LazySrcLoc, &ics.sema.generic_call_src, &ics.other_generic_call_src);
7548 std.mem.swap(InternPool.OptionalDeclIndex, &ics.sema.generic_call_decl, &ics.other_generic_call_decl);
7549 std.mem.swap(Air.Inst.Ref, &ics.sema.error_return_trace_index_on_fn_entry, &ics.other_error_return_trace_index_on_fn_entry);7480 std.mem.swap(Air.Inst.Ref, &ics.sema.error_return_trace_index_on_fn_entry, &ics.other_error_return_trace_index_on_fn_entry);
7550 // zig fmt: on7481 // zig fmt: on
7551 }7482 }
...@@ -7577,14 +7508,16 @@ fn analyzeCall(...@@ -7577,14 +7508,16 @@ fn analyzeCall(
7577 const maybe_decl = try sema.funcDeclSrc(func);7508 const maybe_decl = try sema.funcDeclSrc(func);
7578 const msg = msg: {7509 const msg = msg: {
7579 const msg = try sema.errMsg(7510 const msg = try sema.errMsg(
7580 block,
7581 func_src,7511 func_src,
7582 "unable to call function with naked calling convention",7512 "unable to call function with naked calling convention",
7583 .{},7513 .{},
7584 );7514 );
7585 errdefer msg.destroy(sema.gpa);7515 errdefer msg.destroy(sema.gpa);
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", .{});
7588 break :msg msg;7521 break :msg msg;
7589 };7522 };
7590 return sema.failWithOwnedErrorMsg(block, msg);7523 return sema.failWithOwnedErrorMsg(block, msg);
...@@ -7623,7 +7556,6 @@ fn analyzeCall(...@@ -7623,7 +7556,6 @@ fn analyzeCall(
7623 is_inline_call = ct;7556 is_inline_call = ct;
7624 if (ct) {7557 if (ct) {
7625 comptime_reason = &.{ .comptime_ret_ty = .{7558 comptime_reason = &.{ .comptime_ret_ty = .{
7626 .block = block,
7627 .func = func,7559 .func = func,
7628 .func_src = func_src,7560 .func_src = func_src,
7629 .return_ty = Type.fromInterned(func_ty_info.return_type),7561 .return_ty = Type.fromInterned(func_ty_info.return_type),
...@@ -7637,12 +7569,12 @@ fn analyzeCall(...@@ -7637,12 +7569,12 @@ fn analyzeCall(
76377569
7638 if (sema.func_is_naked and !is_inline_call and !is_comptime_call) {7570 if (sema.func_is_naked and !is_inline_call and !is_comptime_call) {
7639 const msg = msg: {7571 const msg = msg: {
7640 const msg = try sema.errMsg(block, call_src, "runtime {s} not allowed in naked function", .{@tagName(operation)});7572 const msg = try sema.errMsg(call_src, "runtime {s} not allowed in naked function", .{@tagName(operation)});
7641 errdefer msg.destroy(sema.gpa);7573 errdefer msg.destroy(sema.gpa);
76427574
7643 switch (operation) {7575 switch (operation) {
7644 .call, .@"@call", .@"@panic", .@"error return" => {},7576 .call, .@"@call", .@"@panic", .@"error return" => {},
7645 .@"safety check" => try sema.errNote(block, call_src, msg, "use @setRuntimeSafety to disable runtime safety", .{}),7577 .@"safety check" => try sema.errNote(call_src, msg, "use @setRuntimeSafety to disable runtime safety", .{}),
7646 }7578 }
7647 break :msg msg;7579 break :msg msg;
7648 };7580 };
...@@ -7669,7 +7601,6 @@ fn analyzeCall(...@@ -7669,7 +7601,6 @@ fn analyzeCall(
7669 is_inline_call = true;7601 is_inline_call = true;
7670 is_comptime_call = true;7602 is_comptime_call = true;
7671 comptime_reason = &.{ .comptime_ret_ty = .{7603 comptime_reason = &.{ .comptime_ret_ty = .{
7672 .block = block,
7673 .func = func,7604 .func = func,
7674 .func_src = func_src,7605 .func_src = func_src,
7675 .return_ty = Type.fromInterned(func_ty_info.return_type),7606 .return_ty = Type.fromInterned(func_ty_info.return_type),
...@@ -7776,6 +7707,7 @@ fn analyzeCall(...@@ -7776,6 +7707,7 @@ fn analyzeCall(
7776 .runtime_cond = block.runtime_cond,7707 .runtime_cond = block.runtime_cond,
7777 .runtime_loop = block.runtime_loop,7708 .runtime_loop = block.runtime_loop,
7778 .runtime_index = block.runtime_index,7709 .runtime_index = block.runtime_index,
7710 .src_base_inst = fn_owner_decl.zir_decl_index.unwrap().?,
7779 };7711 };
77807712
7781 const merges = &child_block.inlining.?.merges;7713 const merges = &child_block.inlining.?.merges;
...@@ -7849,7 +7781,7 @@ fn analyzeCall(...@@ -7849,7 +7781,7 @@ fn analyzeCall(
7849 var block_it = block;7781 var block_it = block;
7850 while (block_it.inlining) |parent_inlining| {7782 while (block_it.inlining) |parent_inlining| {
7851 if (!parent_inlining.has_comptime_args and parent_inlining.func == module_fn_index) {7783 if (!parent_inlining.has_comptime_args and parent_inlining.func == module_fn_index) {
7852 const err_msg = try sema.errMsg(block, call_src, "inline call is recursive", .{});7784 const err_msg = try sema.errMsg(call_src, "inline call is recursive", .{});
7853 return sema.failWithOwnedErrorMsg(null, err_msg);7785 return sema.failWithOwnedErrorMsg(null, err_msg);
7854 }7786 }
7855 block_it = parent_inlining.call_block;7787 block_it = parent_inlining.call_block;
...@@ -7864,7 +7796,7 @@ fn analyzeCall(...@@ -7864,7 +7796,7 @@ fn analyzeCall(
7864 try sema.resolveInlineBody(&child_block, fn_info.ret_ty_body, module_fn.zir_body_inst.resolve(ip))7796 try sema.resolveInlineBody(&child_block, fn_info.ret_ty_body, module_fn.zir_body_inst.resolve(ip))
7865 else7797 else
7866 try sema.resolveInst(fn_info.ret_ty_ref);7798 try sema.resolveInst(fn_info.ret_ty_ref);
7867 const ret_ty_src: LazySrcLoc = .{ .node_offset_fn_type_ret_ty = 0 };7799 const ret_ty_src: LazySrcLoc = .{ .base_node_inst = module_fn.zir_body_inst, .offset = .{ .node_offset_fn_type_ret_ty = 0 } };
7868 sema.fn_ret_ty = try sema.analyzeAsType(&child_block, ret_ty_src, ret_ty_inst);7800 sema.fn_ret_ty = try sema.analyzeAsType(&child_block, ret_ty_src, ret_ty_inst);
7869 if (module_fn.analysis(ip).inferred_error_set) {7801 if (module_fn.analysis(ip).inferred_error_set) {
7870 // Create a fresh inferred error set type for inline/comptime calls.7802 // Create a fresh inferred error set type for inline/comptime calls.
...@@ -7935,7 +7867,7 @@ fn analyzeCall(...@@ -7935,7 +7867,7 @@ fn analyzeCall(
7935 };7867 };
79367868
7937 if (is_comptime_call) {7869 if (is_comptime_call) {
7938 const result_val = try sema.resolveConstValue(block, .unneeded, result, undefined);7870 const result_val = try sema.resolveConstValue(block, LazySrcLoc.unneeded, result, undefined);
7939 const result_interned = result_val.toIntern();7871 const result_interned = result_val.toIntern();
79407872
7941 // Transform ad-hoc inferred error set types into concrete error sets.7873 // Transform ad-hoc inferred error set types into concrete error sets.
...@@ -8276,7 +8208,6 @@ fn instantiateGenericCall(...@@ -8276,7 +8208,6 @@ fn instantiateGenericCall(
8276 .comptime_args = comptime_args,8208 .comptime_args = comptime_args,
8277 .generic_owner = generic_owner,8209 .generic_owner = generic_owner,
8278 .generic_call_src = call_src,8210 .generic_call_src = call_src,
8279 .generic_call_decl = block.src_decl.toOptional(),
8280 .branch_quota = sema.branch_quota,8211 .branch_quota = sema.branch_quota,
8281 .branch_count = sema.branch_count,8212 .branch_count = sema.branch_count,
8282 .comptime_err_ret_trace = sema.comptime_err_ret_trace,8213 .comptime_err_ret_trace = sema.comptime_err_ret_trace,
...@@ -8291,6 +8222,7 @@ fn instantiateGenericCall(...@@ -8291,6 +8222,7 @@ fn instantiateGenericCall(
8291 .instructions = .{},8222 .instructions = .{},
8292 .inlining = null,8223 .inlining = null,
8293 .is_comptime = true,8224 .is_comptime = true,
8225 .src_base_inst = fn_owner_decl.zir_decl_index.unwrap().?,
8294 };8226 };
8295 defer child_block.instructions.deinit(gpa);8227 defer child_block.instructions.deinit(gpa);
82968228
...@@ -8321,18 +8253,15 @@ fn instantiateGenericCall(...@@ -8321,18 +8253,15 @@ fn instantiateGenericCall(
8321 const prev_no_partial_func_ty = child_sema.no_partial_func_ty;8253 const prev_no_partial_func_ty = child_sema.no_partial_func_ty;
8322 const prev_generic_owner = child_sema.generic_owner;8254 const prev_generic_owner = child_sema.generic_owner;
8323 const prev_generic_call_src = child_sema.generic_call_src;8255 const prev_generic_call_src = child_sema.generic_call_src;
8324 const prev_generic_call_decl = child_sema.generic_call_decl;
8325 child_block.params = .{};8256 child_block.params = .{};
8326 child_sema.no_partial_func_ty = true;8257 child_sema.no_partial_func_ty = true;
8327 child_sema.generic_owner = .none;8258 child_sema.generic_owner = .none;
8328 child_sema.generic_call_src = .unneeded;8259 child_sema.generic_call_src = LazySrcLoc.unneeded;
8329 child_sema.generic_call_decl = .none;
8330 defer {8260 defer {
8331 child_block.params = prev_params;8261 child_block.params = prev_params;
8332 child_sema.no_partial_func_ty = prev_no_partial_func_ty;8262 child_sema.no_partial_func_ty = prev_no_partial_func_ty;
8333 child_sema.generic_owner = prev_generic_owner;8263 child_sema.generic_owner = prev_generic_owner;
8334 child_sema.generic_call_src = prev_generic_call_src;8264 child_sema.generic_call_src = prev_generic_call_src;
8335 child_sema.generic_call_decl = prev_generic_call_decl;
8336 }8265 }
83378266
8338 const param_ty_inst = try child_sema.resolveInlineBody(&child_block, param_ty_body, param_inst);8267 const param_ty_inst = try child_sema.resolveInlineBody(&child_block, param_ty_body, param_inst);
...@@ -8372,14 +8301,14 @@ fn instantiateGenericCall(...@@ -8372,14 +8301,14 @@ fn instantiateGenericCall(
8372 .param_anytype_comptime,8301 .param_anytype_comptime,
8373 => return sema.failWithOwnedErrorMsg(block, msg: {8302 => return sema.failWithOwnedErrorMsg(block, msg: {
8374 const arg_src = args_info.argSrc(block, arg_index);8303 const arg_src = args_info.argSrc(block, arg_index);
8375 const msg = try sema.errMsg(block, arg_src, "runtime-known argument passed to comptime parameter", .{});8304 const msg = try sema.errMsg(arg_src, "runtime-known argument passed to comptime parameter", .{});
8376 errdefer msg.destroy(sema.gpa);8305 errdefer msg.destroy(sema.gpa);
8377 const param_src = child_block.tokenOffset(switch (param_tag) {8306 const param_src = child_block.tokenOffset(switch (param_tag) {
8378 .param_comptime => fn_zir.instructions.items(.data)[@intFromEnum(param_inst)].pl_tok.src_tok,8307 .param_comptime => fn_zir.instructions.items(.data)[@intFromEnum(param_inst)].pl_tok.src_tok,
8379 .param_anytype_comptime => fn_zir.instructions.items(.data)[@intFromEnum(param_inst)].str_tok.src_tok,8308 .param_anytype_comptime => fn_zir.instructions.items(.data)[@intFromEnum(param_inst)].str_tok.src_tok,
8380 else => unreachable,8309 else => unreachable,
8381 });8310 });
8382 try child_sema.errNote(&child_block, param_src, msg, "declared comptime here", .{});8311 try child_sema.errNote(param_src, msg, "declared comptime here", .{});
8383 break :msg msg;8312 break :msg msg;
8384 }),8313 }),
83858314
...@@ -8387,16 +8316,15 @@ fn instantiateGenericCall(...@@ -8387,16 +8316,15 @@ fn instantiateGenericCall(
8387 .param_anytype,8316 .param_anytype,
8388 => return sema.failWithOwnedErrorMsg(block, msg: {8317 => return sema.failWithOwnedErrorMsg(block, msg: {
8389 const arg_src = args_info.argSrc(block, arg_index);8318 const arg_src = args_info.argSrc(block, arg_index);
8390 const msg = try sema.errMsg(block, arg_src, "runtime-known argument passed to parameter of comptime-only type", .{});8319 const msg = try sema.errMsg(arg_src, "runtime-known argument passed to parameter of comptime-only type", .{});
8391 errdefer msg.destroy(sema.gpa);8320 errdefer msg.destroy(sema.gpa);
8392 const param_src = child_block.tokenOffset(switch (param_tag) {8321 const param_src = child_block.tokenOffset(switch (param_tag) {
8393 .param => fn_zir.instructions.items(.data)[@intFromEnum(param_inst)].pl_tok.src_tok,8322 .param => fn_zir.instructions.items(.data)[@intFromEnum(param_inst)].pl_tok.src_tok,
8394 .param_anytype => fn_zir.instructions.items(.data)[@intFromEnum(param_inst)].str_tok.src_tok,8323 .param_anytype => fn_zir.instructions.items(.data)[@intFromEnum(param_inst)].str_tok.src_tok,
8395 else => unreachable,8324 else => unreachable,
8396 });8325 });
8397 try child_sema.errNote(&child_block, param_src, msg, "declared here", .{});8326 try child_sema.errNote(param_src, msg, "declared here", .{});
8398 const src_decl = mod.declPtr(block.src_decl);8327 try sema.explainWhyTypeIsComptime(msg, arg_src, arg_ty);
8399 try sema.explainWhyTypeIsComptime(msg, src_decl.toSrcLoc(arg_src, mod), arg_ty);
8400 break :msg msg;8328 break :msg msg;
8401 }),8329 }),
84028330
...@@ -8433,7 +8361,7 @@ fn instantiateGenericCall(...@@ -8433,7 +8361,7 @@ fn instantiateGenericCall(
8433 // We've already handled parameters, so don't resolve the whole body. Instead, just8361 // We've already handled parameters, so don't resolve the whole body. Instead, just
8434 // do the instructions after the params (i.e. the func itself).8362 // do the instructions after the params (i.e. the func itself).
8435 const new_func_inst = try child_sema.resolveInlineBody(&child_block, fn_info.param_body[args_info.count()..], fn_info.param_body_inst);8363 const new_func_inst = try child_sema.resolveInlineBody(&child_block, fn_info.param_body[args_info.count()..], fn_info.param_body_inst);
8436 const callee_index = (child_sema.resolveConstDefinedValue(&child_block, .unneeded, new_func_inst, undefined) catch unreachable).toIntern();8364 const callee_index = (child_sema.resolveConstDefinedValue(&child_block, LazySrcLoc.unneeded, new_func_inst, undefined) catch unreachable).toIntern();
84378365
8438 const callee = mod.funcInfo(callee_index);8366 const callee = mod.funcInfo(callee_index);
8439 callee.branchQuota(ip).* = @max(callee.branchQuota(ip).*, sema.branch_quota);8367 callee.branchQuota(ip).* = @max(callee.branchQuota(ip).*, sema.branch_quota);
...@@ -8520,7 +8448,7 @@ fn zirOptionalType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro...@@ -8520,7 +8448,7 @@ fn zirOptionalType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
85208448
8521 const mod = sema.mod;8449 const mod = sema.mod;
8522 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;8450 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
8523 const operand_src: LazySrcLoc = .{ .node_offset_un_op = inst_data.src_node };8451 const operand_src = block.src(.{ .node_offset_un_op = inst_data.src_node });
8524 const child_type = try sema.resolveType(block, operand_src, inst_data.operand);8452 const child_type = try sema.resolveType(block, operand_src, inst_data.operand);
8525 if (child_type.zigTypeTag(mod) == .Opaque) {8453 if (child_type.zigTypeTag(mod) == .Opaque) {
8526 return sema.fail(block, operand_src, "opaque type '{}' cannot be optional", .{child_type.fmt(mod)});8454 return sema.fail(block, operand_src, "opaque type '{}' cannot be optional", .{child_type.fmt(mod)});
...@@ -8535,7 +8463,7 @@ fn zirOptionalType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro...@@ -8535,7 +8463,7 @@ fn zirOptionalType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
8535fn zirArrayInitElemType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {8463fn zirArrayInitElemType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
8536 const mod = sema.mod;8464 const mod = sema.mod;
8537 const bin = sema.code.instructions.items(.data)[@intFromEnum(inst)].bin;8465 const bin = sema.code.instructions.items(.data)[@intFromEnum(inst)].bin;
8538 const maybe_wrapped_indexable_ty = sema.resolveType(block, .unneeded, bin.lhs) catch |err| switch (err) {8466 const maybe_wrapped_indexable_ty = sema.resolveType(block, LazySrcLoc.unneeded, bin.lhs) catch |err| switch (err) {
8539 // Since this is a ZIR instruction that returns a type, encountering8467 // Since this is a ZIR instruction that returns a type, encountering
8540 // generic poison should not result in a failed compilation, but the8468 // generic poison should not result in a failed compilation, but the
8541 // generic poison type. This prevents unnecessary failures when8469 // generic poison type. This prevents unnecessary failures when
...@@ -8558,7 +8486,7 @@ fn zirArrayInitElemType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compil...@@ -8558,7 +8486,7 @@ fn zirArrayInitElemType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compil
8558fn zirElemType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {8486fn zirElemType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
8559 const mod = sema.mod;8487 const mod = sema.mod;
8560 const un_node = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;8488 const un_node = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
8561 const maybe_wrapped_ptr_ty = sema.resolveType(block, .unneeded, un_node.operand) catch |err| switch (err) {8489 const maybe_wrapped_ptr_ty = sema.resolveType(block, LazySrcLoc.unneeded, un_node.operand) catch |err| switch (err) {
8562 error.GenericPoison => return .generic_poison_type,8490 error.GenericPoison => return .generic_poison_type,
8563 else => |e| return e,8491 else => |e| return e,
8564 };8492 };
...@@ -8592,7 +8520,7 @@ fn zirIndexablePtrElemType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com...@@ -8592,7 +8520,7 @@ fn zirIndexablePtrElemType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com
8592fn zirVectorElemType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {8520fn zirVectorElemType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
8593 const mod = sema.mod;8521 const mod = sema.mod;
8594 const un_node = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;8522 const un_node = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
8595 const vec_ty = sema.resolveType(block, .unneeded, un_node.operand) catch |err| switch (err) {8523 const vec_ty = sema.resolveType(block, LazySrcLoc.unneeded, un_node.operand) catch |err| switch (err) {
8596 // Since this is a ZIR instruction that returns a type, encountering8524 // Since this is a ZIR instruction that returns a type, encountering
8597 // generic poison should not result in a failed compilation, but the8525 // generic poison should not result in a failed compilation, but the
8598 // generic poison type. This prevents unnecessary failures when8526 // generic poison type. This prevents unnecessary failures when
...@@ -8609,8 +8537,8 @@ fn zirVectorElemType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr...@@ -8609,8 +8537,8 @@ fn zirVectorElemType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr
8609fn zirVectorType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {8537fn zirVectorType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
8610 const mod = sema.mod;8538 const mod = sema.mod;
8611 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;8539 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
8612 const len_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };8540 const len_src = block.builtinCallArgSrc(inst_data.src_node, 0);
8613 const elem_type_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };8541 const elem_type_src = block.builtinCallArgSrc(inst_data.src_node, 1);
8614 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;8542 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
8615 const len: u32 = @intCast(try sema.resolveInt(block, len_src, extra.lhs, Type.u32, .{8543 const len: u32 = @intCast(try sema.resolveInt(block, len_src, extra.lhs, Type.u32, .{
8616 .needed_comptime_reason = "vector length must be comptime-known",8544 .needed_comptime_reason = "vector length must be comptime-known",
...@@ -8630,8 +8558,8 @@ fn zirArrayType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A...@@ -8630,8 +8558,8 @@ fn zirArrayType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
86308558
8631 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;8559 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
8632 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;8560 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
8633 const len_src: LazySrcLoc = .{ .node_offset_array_type_len = inst_data.src_node };8561 const len_src = block.src(.{ .node_offset_array_type_len = inst_data.src_node });
8634 const elem_src: LazySrcLoc = .{ .node_offset_array_type_elem = inst_data.src_node };8562 const elem_src = block.src(.{ .node_offset_array_type_elem = inst_data.src_node });
8635 const len = try sema.resolveInt(block, len_src, extra.lhs, Type.usize, .{8563 const len = try sema.resolveInt(block, len_src, extra.lhs, Type.usize, .{
8636 .needed_comptime_reason = "array length must be comptime-known",8564 .needed_comptime_reason = "array length must be comptime-known",
8637 });8565 });
...@@ -8651,9 +8579,9 @@ fn zirArrayTypeSentinel(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compil...@@ -8651,9 +8579,9 @@ fn zirArrayTypeSentinel(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compil
86518579
8652 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;8580 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
8653 const extra = sema.code.extraData(Zir.Inst.ArrayTypeSentinel, inst_data.payload_index).data;8581 const extra = sema.code.extraData(Zir.Inst.ArrayTypeSentinel, inst_data.payload_index).data;
8654 const len_src: LazySrcLoc = .{ .node_offset_array_type_len = inst_data.src_node };8582 const len_src = block.src(.{ .node_offset_array_type_len = inst_data.src_node });
8655 const sentinel_src: LazySrcLoc = .{ .node_offset_array_type_sentinel = inst_data.src_node };8583 const sentinel_src = block.src(.{ .node_offset_array_type_sentinel = inst_data.src_node });
8656 const elem_src: LazySrcLoc = .{ .node_offset_array_type_elem = inst_data.src_node };8584 const elem_src = block.src(.{ .node_offset_array_type_elem = inst_data.src_node });
8657 const len = try sema.resolveInt(block, len_src, extra.len, Type.usize, .{8585 const len = try sema.resolveInt(block, len_src, extra.len, Type.usize, .{
8658 .needed_comptime_reason = "array length must be comptime-known",8586 .needed_comptime_reason = "array length must be comptime-known",
8659 });8587 });
...@@ -8691,7 +8619,7 @@ fn zirAnyframeType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro...@@ -8691,7 +8619,7 @@ fn zirAnyframeType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
8691 return sema.failWithUseOfAsync(block, block.nodeOffset(inst_data.src_node));8619 return sema.failWithUseOfAsync(block, block.nodeOffset(inst_data.src_node));
8692 }8620 }
8693 const mod = sema.mod;8621 const mod = sema.mod;
8694 const operand_src: LazySrcLoc = .{ .node_offset_anyframe_type = inst_data.src_node };8622 const operand_src = block.src(.{ .node_offset_anyframe_type = inst_data.src_node });
8695 const return_type = try sema.resolveType(block, operand_src, inst_data.operand);8623 const return_type = try sema.resolveType(block, operand_src, inst_data.operand);
8696 const anyframe_type = try mod.anyframeType(return_type);8624 const anyframe_type = try mod.anyframeType(return_type);
86978625
...@@ -8705,8 +8633,8 @@ fn zirErrorUnionType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr...@@ -8705,8 +8633,8 @@ fn zirErrorUnionType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr
8705 const mod = sema.mod;8633 const mod = sema.mod;
8706 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;8634 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
8707 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;8635 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
8708 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };8636 const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node });
8709 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };8637 const rhs_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node });
8710 const error_set = try sema.resolveType(block, lhs_src, extra.lhs);8638 const error_set = try sema.resolveType(block, lhs_src, extra.lhs);
8711 const payload = try sema.resolveType(block, rhs_src, extra.rhs);8639 const payload = try sema.resolveType(block, rhs_src, extra.rhs);
87128640
...@@ -8758,8 +8686,8 @@ fn zirIntFromError(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstD...@@ -8758,8 +8686,8 @@ fn zirIntFromError(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstD
8758 const mod = sema.mod;8686 const mod = sema.mod;
8759 const ip = &mod.intern_pool;8687 const ip = &mod.intern_pool;
8760 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;8688 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;
8761 const src = LazySrcLoc.nodeOffset(extra.node);8689 const src = block.nodeOffset(extra.node);
8762 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node };8690 const operand_src = block.builtinCallArgSrc(extra.node, 0);
8763 const uncasted_operand = try sema.resolveInst(extra.operand);8691 const uncasted_operand = try sema.resolveInst(extra.operand);
8764 const operand = try sema.coerce(block, Type.anyerror, uncasted_operand, operand_src);8692 const operand = try sema.coerce(block, Type.anyerror, uncasted_operand, operand_src);
8765 const err_int_ty = try mod.errorIntType();8693 const err_int_ty = try mod.errorIntType();
...@@ -8801,8 +8729,8 @@ fn zirErrorFromInt(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstD...@@ -8801,8 +8729,8 @@ fn zirErrorFromInt(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstD
88018729
8802 const mod = sema.mod;8730 const mod = sema.mod;
8803 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;8731 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;
8804 const src = LazySrcLoc.nodeOffset(extra.node);8732 const src = block.nodeOffset(extra.node);
8805 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node };8733 const operand_src = block.builtinCallArgSrc(extra.node, 0);
8806 const uncasted_operand = try sema.resolveInst(extra.operand);8734 const uncasted_operand = try sema.resolveInst(extra.operand);
8807 const err_int_ty = try mod.errorIntType();8735 const err_int_ty = try mod.errorIntType();
8808 const operand = try sema.coerce(block, err_int_ty, uncasted_operand, operand_src);8736 const operand = try sema.coerce(block, err_int_ty, uncasted_operand, operand_src);
...@@ -8841,16 +8769,16 @@ fn zirMergeErrorSets(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr...@@ -8841,16 +8769,16 @@ fn zirMergeErrorSets(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr
8841 const ip = &mod.intern_pool;8769 const ip = &mod.intern_pool;
8842 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;8770 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
8843 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;8771 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
8844 const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node };8772 const src = block.src(.{ .node_offset_bin_op = inst_data.src_node });
8845 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };8773 const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node });
8846 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };8774 const rhs_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node });
8847 const lhs = try sema.resolveInst(extra.lhs);8775 const lhs = try sema.resolveInst(extra.lhs);
8848 const rhs = try sema.resolveInst(extra.rhs);8776 const rhs = try sema.resolveInst(extra.rhs);
8849 if (sema.typeOf(lhs).zigTypeTag(mod) == .Bool and sema.typeOf(rhs).zigTypeTag(mod) == .Bool) {8777 if (sema.typeOf(lhs).zigTypeTag(mod) == .Bool and sema.typeOf(rhs).zigTypeTag(mod) == .Bool) {
8850 const msg = msg: {8778 const msg = msg: {
8851 const msg = try sema.errMsg(block, lhs_src, "expected error set type, found 'bool'", .{});8779 const msg = try sema.errMsg(lhs_src, "expected error set type, found 'bool'", .{});
8852 errdefer msg.destroy(sema.gpa);8780 errdefer msg.destroy(sema.gpa);
8853 try sema.errNote(block, src, msg, "'||' merges error sets; 'or' performs boolean OR", .{});8781 try sema.errNote(src, msg, "'||' merges error sets; 'or' performs boolean OR", .{});
8854 break :msg msg;8782 break :msg msg;
8855 };8783 };
8856 return sema.failWithOwnedErrorMsg(block, msg);8784 return sema.failWithOwnedErrorMsg(block, msg);
...@@ -8905,7 +8833,7 @@ fn zirIntFromEnum(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError...@@ -8905,7 +8833,7 @@ fn zirIntFromEnum(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
8905 const mod = sema.mod;8833 const mod = sema.mod;
8906 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;8834 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
8907 const src = block.nodeOffset(inst_data.src_node);8835 const src = block.nodeOffset(inst_data.src_node);
8908 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };8836 const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0);
8909 const operand = try sema.resolveInst(inst_data.operand);8837 const operand = try sema.resolveInst(inst_data.operand);
8910 const operand_ty = sema.typeOf(operand);8838 const operand_ty = sema.typeOf(operand);
89118839
...@@ -8963,7 +8891,7 @@ fn zirEnumFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError...@@ -8963,7 +8891,7 @@ fn zirEnumFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
8963 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;8891 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
8964 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;8892 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
8965 const src = block.nodeOffset(inst_data.src_node);8893 const src = block.nodeOffset(inst_data.src_node);
8966 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };8894 const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0);
8967 const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu_opt, "@enumFromInt");8895 const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu_opt, "@enumFromInt");
8968 const operand = try sema.resolveInst(extra.rhs);8896 const operand = try sema.resolveInst(extra.rhs);
89698897
...@@ -9379,7 +9307,7 @@ fn zirFunc(...@@ -9379,7 +9307,7 @@ fn zirFunc(
9379 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;9307 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
9380 const extra = sema.code.extraData(Zir.Inst.Func, inst_data.payload_index);9308 const extra = sema.code.extraData(Zir.Inst.Func, inst_data.payload_index);
9381 const target = sema.mod.getTarget();9309 const target = sema.mod.getTarget();
9382 const ret_ty_src: LazySrcLoc = .{ .node_offset_fn_type_ret_ty = inst_data.src_node };9310 const ret_ty_src = block.src(.{ .node_offset_fn_type_ret_ty = inst_data.src_node });
93839311
9384 var extra_index = extra.end;9312 var extra_index = extra.end;
93859313
...@@ -9460,18 +9388,15 @@ fn resolveGenericBody(...@@ -9460,18 +9388,15 @@ fn resolveGenericBody(
9460 const prev_no_partial_func_type = sema.no_partial_func_ty;9388 const prev_no_partial_func_type = sema.no_partial_func_ty;
9461 const prev_generic_owner = sema.generic_owner;9389 const prev_generic_owner = sema.generic_owner;
9462 const prev_generic_call_src = sema.generic_call_src;9390 const prev_generic_call_src = sema.generic_call_src;
9463 const prev_generic_call_decl = sema.generic_call_decl;
9464 block.params = .{};9391 block.params = .{};
9465 sema.no_partial_func_ty = true;9392 sema.no_partial_func_ty = true;
9466 sema.generic_owner = .none;9393 sema.generic_owner = .none;
9467 sema.generic_call_src = .unneeded;9394 sema.generic_call_src = LazySrcLoc.unneeded;
9468 sema.generic_call_decl = .none;
9469 defer {9395 defer {
9470 block.params = prev_params;9396 block.params = prev_params;
9471 sema.no_partial_func_ty = prev_no_partial_func_type;9397 sema.no_partial_func_ty = prev_no_partial_func_type;
9472 sema.generic_owner = prev_generic_owner;9398 sema.generic_owner = prev_generic_owner;
9473 sema.generic_call_src = prev_generic_call_src;9399 sema.generic_call_src = prev_generic_call_src;
9474 sema.generic_call_decl = prev_generic_call_decl;
9475 }9400 }
94769401
9477 const uncasted = sema.resolveInlineBody(block, body, func_inst) catch |err| break :err err;9402 const uncasted = sema.resolveInlineBody(block, body, func_inst) catch |err| break :err err;
...@@ -9581,9 +9506,9 @@ fn checkCallConvSupportsVarArgs(sema: *Sema, block: *Block, src: LazySrcLoc, cc:...@@ -9581,9 +9506,9 @@ fn checkCallConvSupportsVarArgs(sema: *Sema, block: *Block, src: LazySrcLoc, cc:
95819506
9582 if (!callConvSupportsVarArgs(cc)) {9507 if (!callConvSupportsVarArgs(cc)) {
9583 const msg = msg: {9508 const msg = msg: {
9584 const msg = try sema.errMsg(block, src, "variadic function does not support '.{s}' calling convention", .{@tagName(cc)});9509 const msg = try sema.errMsg(src, "variadic function does not support '.{s}' calling convention", .{@tagName(cc)});
9585 errdefer msg.destroy(sema.gpa);9510 errdefer msg.destroy(sema.gpa);
9586 try sema.errNote(block, src, msg, "supported calling conventions: {}", .{CallingConventionsSupportingVarArgsList{}});9511 try sema.errNote(src, msg, "supported calling conventions: {}", .{CallingConventionsSupportingVarArgsList{}});
9587 break :msg msg;9512 break :msg msg;
9588 };9513 };
9589 return sema.failWithOwnedErrorMsg(block, msg);9514 return sema.failWithOwnedErrorMsg(block, msg);
...@@ -9623,9 +9548,9 @@ fn funcCommon(...@@ -9623,9 +9548,9 @@ fn funcCommon(
9623 const gpa = sema.gpa;9548 const gpa = sema.gpa;
9624 const target = mod.getTarget();9549 const target = mod.getTarget();
9625 const ip = &mod.intern_pool;9550 const ip = &mod.intern_pool;
9626 const ret_ty_src: LazySrcLoc = .{ .node_offset_fn_type_ret_ty = src_node_offset };9551 const ret_ty_src = block.src(.{ .node_offset_fn_type_ret_ty = src_node_offset });
9627 const cc_src: LazySrcLoc = .{ .node_offset_fn_type_cc = src_node_offset };9552 const cc_src = block.src(.{ .node_offset_fn_type_cc = src_node_offset });
9628 const func_src = LazySrcLoc.nodeOffset(src_node_offset);9553 const func_src = block.nodeOffset(src_node_offset);
96299554
9630 var is_generic = bare_return_type.isGenericPoison() or9555 var is_generic = bare_return_type.isGenericPoison() or
9631 alignment == null or9556 alignment == null or
...@@ -9654,11 +9579,10 @@ fn funcCommon(...@@ -9654,11 +9579,10 @@ fn funcCommon(
9654 const index = std.math.cast(u5, i) orelse break :blk false;9579 const index = std.math.cast(u5, i) orelse break :blk false;
9655 break :blk @as(u1, @truncate(noalias_bits >> index)) != 0;9580 break :blk @as(u1, @truncate(noalias_bits >> index)) != 0;
9656 };9581 };
9657 const param_src: LazySrcLoc = .{ .fn_proto_param = .{9582 const param_src = block.src(.{ .fn_proto_param = .{
9658 .decl = block.src_decl,
9659 .fn_proto_node_offset = src_node_offset,9583 .fn_proto_node_offset = src_node_offset,
9660 .param_index = @intCast(i),9584 .param_index = @intCast(i),
9661 } };9585 } });
9662 const requires_comptime = try sema.typeRequiresComptime(param_ty);9586 const requires_comptime = try sema.typeRequiresComptime(param_ty);
9663 if (param_is_comptime or requires_comptime) {9587 if (param_is_comptime or requires_comptime) {
9664 comptime_bits |= @as(u32, 1) << @intCast(i); // TODO: handle cast error9588 comptime_bits |= @as(u32, 1) << @intCast(i); // TODO: handle cast error
...@@ -9679,13 +9603,12 @@ fn funcCommon(...@@ -9679,13 +9603,12 @@ fn funcCommon(
9679 }9603 }
9680 if (!this_generic and !target_util.fnCallConvAllowsZigTypes(target, cc_resolved) and !try sema.validateExternType(param_ty, .param_ty)) {9604 if (!this_generic and !target_util.fnCallConvAllowsZigTypes(target, cc_resolved) and !try sema.validateExternType(param_ty, .param_ty)) {
9681 const msg = msg: {9605 const msg = msg: {
9682 const msg = try sema.errMsg(block, param_src, "parameter of type '{}' not allowed in function with calling convention '{s}'", .{9606 const msg = try sema.errMsg(param_src, "parameter of type '{}' not allowed in function with calling convention '{s}'", .{
9683 param_ty.fmt(mod), @tagName(cc_resolved),9607 param_ty.fmt(mod), @tagName(cc_resolved),
9684 });9608 });
9685 errdefer msg.destroy(sema.gpa);9609 errdefer msg.destroy(sema.gpa);
96869610
9687 const src_decl = mod.declPtr(block.src_decl);9611 try sema.explainWhyTypeIsNotExtern(msg, param_src, param_ty, .param_ty);
9688 try sema.explainWhyTypeIsNotExtern(msg, src_decl.toSrcLoc(param_src, mod), param_ty, .param_ty);
96899612
9690 try sema.addDeclaredHereNote(msg, param_ty);9613 try sema.addDeclaredHereNote(msg, param_ty);
9691 break :msg msg;9614 break :msg msg;
...@@ -9694,13 +9617,12 @@ fn funcCommon(...@@ -9694,13 +9617,12 @@ fn funcCommon(
9694 }9617 }
9695 if (is_source_decl and requires_comptime and !param_is_comptime and has_body and !block.is_comptime) {9618 if (is_source_decl and requires_comptime and !param_is_comptime and has_body and !block.is_comptime) {
9696 const msg = msg: {9619 const msg = msg: {
9697 const msg = try sema.errMsg(block, param_src, "parameter of type '{}' must be declared comptime", .{9620 const msg = try sema.errMsg(param_src, "parameter of type '{}' must be declared comptime", .{
9698 param_ty.fmt(mod),9621 param_ty.fmt(mod),
9699 });9622 });
9700 errdefer msg.destroy(sema.gpa);9623 errdefer msg.destroy(sema.gpa);
97019624
9702 const src_decl = mod.declPtr(block.src_decl);9625 try sema.explainWhyTypeIsComptime(msg, param_src, param_ty);
9703 try sema.explainWhyTypeIsComptime(msg, src_decl.toSrcLoc(param_src, mod), param_ty);
97049626
9705 try sema.addDeclaredHereNote(msg, param_ty);9627 try sema.addDeclaredHereNote(msg, param_ty);
9706 break :msg msg;9628 break :msg msg;
...@@ -9861,9 +9783,9 @@ fn funcCommon(...@@ -9861,9 +9783,9 @@ fn funcCommon(
9861 assert(section != .generic);9783 assert(section != .generic);
9862 assert(address_space != null);9784 assert(address_space != null);
9863 assert(!is_generic);9785 assert(!is_generic);
9864 if (opt_lib_name) |lib_name| try sema.handleExternLibName(block, .{9786 if (opt_lib_name) |lib_name| try sema.handleExternLibName(block, block.src(.{
9865 .node_offset_lib_name = src_node_offset,9787 .node_offset_lib_name = src_node_offset,
9866 }, lib_name);9788 }), lib_name);
9867 const func_index = try ip.getExternFunc(gpa, .{9789 const func_index = try ip.getExternFunc(gpa, .{
9868 .ty = func_ty,9790 .ty = func_ty,
9869 .decl = sema.owner_decl_index,9791 .decl = sema.owner_decl_index,
...@@ -9975,13 +9897,12 @@ fn finishFunc(...@@ -9975,13 +9897,12 @@ fn finishFunc(
9975 !try sema.validateExternType(return_type, .ret_ty))9897 !try sema.validateExternType(return_type, .ret_ty))
9976 {9898 {
9977 const msg = msg: {9899 const msg = msg: {
9978 const msg = try sema.errMsg(block, ret_ty_src, "return type '{}' not allowed in function with calling convention '{s}'", .{9900 const msg = try sema.errMsg(ret_ty_src, "return type '{}' not allowed in function with calling convention '{s}'", .{
9979 return_type.fmt(mod), @tagName(cc_resolved),9901 return_type.fmt(mod), @tagName(cc_resolved),
9980 });9902 });
9981 errdefer msg.destroy(gpa);9903 errdefer msg.destroy(gpa);
99829904
9983 const src_decl = mod.declPtr(block.src_decl);9905 try sema.explainWhyTypeIsNotExtern(msg, ret_ty_src, return_type, .ret_ty);
9984 try sema.explainWhyTypeIsNotExtern(msg, src_decl.toSrcLoc(ret_ty_src, mod), return_type, .ret_ty);
99859906
9986 try sema.addDeclaredHereNote(msg, return_type);9907 try sema.addDeclaredHereNote(msg, return_type);
9987 break :msg msg;9908 break :msg msg;
...@@ -9997,12 +9918,11 @@ fn finishFunc(...@@ -9997,12 +9918,11 @@ fn finishFunc(
9997 } else break :comptime_check;9918 } else break :comptime_check;
99989919
9999 const msg = try sema.errMsg(9920 const msg = try sema.errMsg(
10000 block,
10001 ret_ty_src,9921 ret_ty_src,
10002 "function with comptime-only return type '{}' requires all parameters to be comptime",9922 "function with comptime-only return type '{}' requires all parameters to be comptime",
10003 .{return_type.fmt(mod)},9923 .{return_type.fmt(mod)},
10004 );9924 );
10005 try sema.explainWhyTypeIsComptime(msg, sema.owner_decl.toSrcLoc(ret_ty_src, mod), return_type);9925 try sema.explainWhyTypeIsComptime(msg, ret_ty_src, return_type);
100069926
10007 const tags = sema.code.instructions.items(.tag);9927 const tags = sema.code.instructions.items(.tag);
10008 const data = sema.code.instructions.items(.data);9928 const data = sema.code.instructions.items(.data);
...@@ -10020,9 +9940,9 @@ fn finishFunc(...@@ -10020,9 +9940,9 @@ fn finishFunc(
10020 });9940 });
10021 const name = sema.code.nullTerminatedString(name_nts);9941 const name = sema.code.nullTerminatedString(name_nts);
10022 if (name.len != 0) {9942 if (name.len != 0) {
10023 try sema.errNote(block, param_src, msg, "param '{s}' is required to be comptime", .{name});9943 try sema.errNote(param_src, msg, "param '{s}' is required to be comptime", .{name});
10024 } else {9944 } else {
10025 try sema.errNote(block, param_src, msg, "param is required to be comptime", .{});9945 try sema.errNote(param_src, msg, "param is required to be comptime", .{});
10026 }9946 }
10027 }9947 }
10028 }9948 }
...@@ -10112,18 +10032,15 @@ fn zirParam(...@@ -10112,18 +10032,15 @@ fn zirParam(
10112 const prev_no_partial_func_type = sema.no_partial_func_ty;10032 const prev_no_partial_func_type = sema.no_partial_func_ty;
10113 const prev_generic_owner = sema.generic_owner;10033 const prev_generic_owner = sema.generic_owner;
10114 const prev_generic_call_src = sema.generic_call_src;10034 const prev_generic_call_src = sema.generic_call_src;
10115 const prev_generic_call_decl = sema.generic_call_decl;
10116 block.params = .{};10035 block.params = .{};
10117 sema.no_partial_func_ty = true;10036 sema.no_partial_func_ty = true;
10118 sema.generic_owner = .none;10037 sema.generic_owner = .none;
10119 sema.generic_call_src = .unneeded;10038 sema.generic_call_src = LazySrcLoc.unneeded;
10120 sema.generic_call_decl = .none;
10121 defer {10039 defer {
10122 block.params = prev_params;10040 block.params = prev_params;
10123 sema.no_partial_func_ty = prev_no_partial_func_type;10041 sema.no_partial_func_ty = prev_no_partial_func_type;
10124 sema.generic_owner = prev_generic_owner;10042 sema.generic_owner = prev_generic_owner;
10125 sema.generic_call_src = prev_generic_call_src;10043 sema.generic_call_src = prev_generic_call_src;
10126 sema.generic_call_decl = prev_generic_call_decl;
10127 }10044 }
1012810045
10129 if (sema.resolveInlineBody(block, body, inst)) |param_ty_inst| {10046 if (sema.resolveInlineBody(block, body, inst)) |param_ty_inst| {
...@@ -10265,7 +10182,7 @@ fn zirIntFromPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!...@@ -10265,7 +10182,7 @@ fn zirIntFromPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
1026510182
10266 const zcu = sema.mod;10183 const zcu = sema.mod;
10267 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;10184 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
10268 const ptr_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };10185 const ptr_src = block.builtinCallArgSrc(inst_data.src_node, 0);
10269 const operand = try sema.resolveInst(inst_data.operand);10186 const operand = try sema.resolveInst(inst_data.operand);
10270 const operand_ty = sema.typeOf(operand);10187 const operand_ty = sema.typeOf(operand);
10271 const ptr_ty = operand_ty.scalarType(zcu);10188 const ptr_ty = operand_ty.scalarType(zcu);
...@@ -10276,10 +10193,9 @@ fn zirIntFromPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!...@@ -10276,10 +10193,9 @@ fn zirIntFromPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
10276 const pointee_ty = ptr_ty.childType(zcu);10193 const pointee_ty = ptr_ty.childType(zcu);
10277 if (try sema.typeRequiresComptime(ptr_ty)) {10194 if (try sema.typeRequiresComptime(ptr_ty)) {
10278 const msg = msg: {10195 const msg = msg: {
10279 const msg = try sema.errMsg(block, ptr_src, "comptime-only type '{}' has no pointer address", .{pointee_ty.fmt(zcu)});10196 const msg = try sema.errMsg(ptr_src, "comptime-only type '{}' has no pointer address", .{pointee_ty.fmt(zcu)});
10280 errdefer msg.destroy(sema.gpa);10197 errdefer msg.destroy(sema.gpa);
10281 const src_decl = zcu.declPtr(block.src_decl);10198 try sema.explainWhyTypeIsComptime(msg, ptr_src, pointee_ty);
10282 try sema.explainWhyTypeIsComptime(msg, src_decl.toSrcLoc(ptr_src, zcu), pointee_ty);
10283 break :msg msg;10199 break :msg msg;
10284 };10200 };
10285 return sema.failWithOwnedErrorMsg(block, msg);10201 return sema.failWithOwnedErrorMsg(block, msg);
...@@ -10340,7 +10256,7 @@ fn zirFieldVal(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -10340,7 +10256,7 @@ fn zirFieldVal(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
10340 const mod = sema.mod;10256 const mod = sema.mod;
10341 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;10257 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
10342 const src = block.nodeOffset(inst_data.src_node);10258 const src = block.nodeOffset(inst_data.src_node);
10343 const field_name_src: LazySrcLoc = .{ .node_offset_field_name = inst_data.src_node };10259 const field_name_src = block.src(.{ .node_offset_field_name = inst_data.src_node });
10344 const extra = sema.code.extraData(Zir.Inst.Field, inst_data.payload_index).data;10260 const extra = sema.code.extraData(Zir.Inst.Field, inst_data.payload_index).data;
10345 const field_name = try mod.intern_pool.getOrPutString(10261 const field_name = try mod.intern_pool.getOrPutString(
10346 sema.gpa,10262 sema.gpa,
...@@ -10358,7 +10274,7 @@ fn zirFieldPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -10358,7 +10274,7 @@ fn zirFieldPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
10358 const mod = sema.mod;10274 const mod = sema.mod;
10359 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;10275 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
10360 const src = block.nodeOffset(inst_data.src_node);10276 const src = block.nodeOffset(inst_data.src_node);
10361 const field_name_src: LazySrcLoc = .{ .node_offset_field_name = inst_data.src_node };10277 const field_name_src = block.src(.{ .node_offset_field_name = inst_data.src_node });
10362 const extra = sema.code.extraData(Zir.Inst.Field, inst_data.payload_index).data;10278 const extra = sema.code.extraData(Zir.Inst.Field, inst_data.payload_index).data;
10363 const field_name = try mod.intern_pool.getOrPutString(10279 const field_name = try mod.intern_pool.getOrPutString(
10364 sema.gpa,10280 sema.gpa,
...@@ -10376,7 +10292,7 @@ fn zirStructInitFieldPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compi...@@ -10376,7 +10292,7 @@ fn zirStructInitFieldPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compi
10376 const mod = sema.mod;10292 const mod = sema.mod;
10377 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;10293 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
10378 const src = block.nodeOffset(inst_data.src_node);10294 const src = block.nodeOffset(inst_data.src_node);
10379 const field_name_src: LazySrcLoc = .{ .node_offset_field_name_init = inst_data.src_node };10295 const field_name_src = block.src(.{ .node_offset_field_name_init = inst_data.src_node });
10380 const extra = sema.code.extraData(Zir.Inst.Field, inst_data.payload_index).data;10296 const extra = sema.code.extraData(Zir.Inst.Field, inst_data.payload_index).data;
10381 const field_name = try mod.intern_pool.getOrPutString(10297 const field_name = try mod.intern_pool.getOrPutString(
10382 sema.gpa,10298 sema.gpa,
...@@ -10401,7 +10317,7 @@ fn zirFieldValNamed(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr...@@ -10401,7 +10317,7 @@ fn zirFieldValNamed(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr
1040110317
10402 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;10318 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
10403 const src = block.nodeOffset(inst_data.src_node);10319 const src = block.nodeOffset(inst_data.src_node);
10404 const field_name_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };10320 const field_name_src = block.builtinCallArgSrc(inst_data.src_node, 1);
10405 const extra = sema.code.extraData(Zir.Inst.FieldNamed, inst_data.payload_index).data;10321 const extra = sema.code.extraData(Zir.Inst.FieldNamed, inst_data.payload_index).data;
10406 const object = try sema.resolveInst(extra.lhs);10322 const object = try sema.resolveInst(extra.lhs);
10407 const field_name = try sema.resolveConstStringIntern(block, field_name_src, extra.field_name, .{10323 const field_name = try sema.resolveConstStringIntern(block, field_name_src, extra.field_name, .{
...@@ -10416,7 +10332,7 @@ fn zirFieldPtrNamed(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr...@@ -10416,7 +10332,7 @@ fn zirFieldPtrNamed(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr
1041610332
10417 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;10333 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
10418 const src = block.nodeOffset(inst_data.src_node);10334 const src = block.nodeOffset(inst_data.src_node);
10419 const field_name_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };10335 const field_name_src = block.builtinCallArgSrc(inst_data.src_node, 1);
10420 const extra = sema.code.extraData(Zir.Inst.FieldNamed, inst_data.payload_index).data;10336 const extra = sema.code.extraData(Zir.Inst.FieldNamed, inst_data.payload_index).data;
10421 const object_ptr = try sema.resolveInst(extra.lhs);10337 const object_ptr = try sema.resolveInst(extra.lhs);
10422 const field_name = try sema.resolveConstStringIntern(block, field_name_src, extra.field_name, .{10338 const field_name = try sema.resolveConstStringIntern(block, field_name_src, extra.field_name, .{
...@@ -10431,7 +10347,7 @@ fn zirIntCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air...@@ -10431,7 +10347,7 @@ fn zirIntCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1043110347
10432 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;10348 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
10433 const src = block.nodeOffset(inst_data.src_node);10349 const src = block.nodeOffset(inst_data.src_node);
10434 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };10350 const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0);
10435 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;10351 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
1043610352
10437 const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu_opt, "@intCast");10353 const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu_opt, "@intCast");
...@@ -10601,7 +10517,7 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air...@@ -10601,7 +10517,7 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
10601 const mod = sema.mod;10517 const mod = sema.mod;
10602 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;10518 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
10603 const src = block.nodeOffset(inst_data.src_node);10519 const src = block.nodeOffset(inst_data.src_node);
10604 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };10520 const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0);
10605 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;10521 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
1060610522
10607 const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu_opt, "@bitCast");10523 const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu_opt, "@bitCast");
...@@ -10627,10 +10543,10 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air...@@ -10627,10 +10543,10 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1062710543
10628 .Enum => {10544 .Enum => {
10629 const msg = msg: {10545 const msg = msg: {
10630 const msg = try sema.errMsg(block, src, "cannot @bitCast to '{}'", .{dest_ty.fmt(mod)});10546 const msg = try sema.errMsg(src, "cannot @bitCast to '{}'", .{dest_ty.fmt(mod)});
10631 errdefer msg.destroy(sema.gpa);10547 errdefer msg.destroy(sema.gpa);
10632 switch (operand_ty.zigTypeTag(mod)) {10548 switch (operand_ty.zigTypeTag(mod)) {
10633 .Int, .ComptimeInt => try sema.errNote(block, src, msg, "use @enumFromInt to cast from '{}'", .{operand_ty.fmt(mod)}),10549 .Int, .ComptimeInt => try sema.errNote(src, msg, "use @enumFromInt to cast from '{}'", .{operand_ty.fmt(mod)}),
10634 else => {},10550 else => {},
10635 }10551 }
1063610552
...@@ -10641,11 +10557,11 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air...@@ -10641,11 +10557,11 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1064110557
10642 .Pointer => {10558 .Pointer => {
10643 const msg = msg: {10559 const msg = msg: {
10644 const msg = try sema.errMsg(block, src, "cannot @bitCast to '{}'", .{dest_ty.fmt(mod)});10560 const msg = try sema.errMsg(src, "cannot @bitCast to '{}'", .{dest_ty.fmt(mod)});
10645 errdefer msg.destroy(sema.gpa);10561 errdefer msg.destroy(sema.gpa);
10646 switch (operand_ty.zigTypeTag(mod)) {10562 switch (operand_ty.zigTypeTag(mod)) {
10647 .Int, .ComptimeInt => try sema.errNote(block, src, msg, "use @ptrFromInt to cast from '{}'", .{operand_ty.fmt(mod)}),10563 .Int, .ComptimeInt => try sema.errNote(src, msg, "use @ptrFromInt to cast from '{}'", .{operand_ty.fmt(mod)}),
10648 .Pointer => try sema.errNote(block, src, msg, "use @ptrCast to cast from '{}'", .{operand_ty.fmt(mod)}),10564 .Pointer => try sema.errNote(src, msg, "use @ptrCast to cast from '{}'", .{operand_ty.fmt(mod)}),
10649 else => {},10565 else => {},
10650 }10566 }
1065110567
...@@ -10691,10 +10607,10 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air...@@ -10691,10 +10607,10 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1069110607
10692 .Enum => {10608 .Enum => {
10693 const msg = msg: {10609 const msg = msg: {
10694 const msg = try sema.errMsg(block, operand_src, "cannot @bitCast from '{}'", .{operand_ty.fmt(mod)});10610 const msg = try sema.errMsg(operand_src, "cannot @bitCast from '{}'", .{operand_ty.fmt(mod)});
10695 errdefer msg.destroy(sema.gpa);10611 errdefer msg.destroy(sema.gpa);
10696 switch (dest_ty.zigTypeTag(mod)) {10612 switch (dest_ty.zigTypeTag(mod)) {
10697 .Int, .ComptimeInt => try sema.errNote(block, operand_src, msg, "use @intFromEnum to cast to '{}'", .{dest_ty.fmt(mod)}),10613 .Int, .ComptimeInt => try sema.errNote(operand_src, msg, "use @intFromEnum to cast to '{}'", .{dest_ty.fmt(mod)}),
10698 else => {},10614 else => {},
10699 }10615 }
1070010616
...@@ -10704,11 +10620,11 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air...@@ -10704,11 +10620,11 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
10704 },10620 },
10705 .Pointer => {10621 .Pointer => {
10706 const msg = msg: {10622 const msg = msg: {
10707 const msg = try sema.errMsg(block, operand_src, "cannot @bitCast from '{}'", .{operand_ty.fmt(mod)});10623 const msg = try sema.errMsg(operand_src, "cannot @bitCast from '{}'", .{operand_ty.fmt(mod)});
10708 errdefer msg.destroy(sema.gpa);10624 errdefer msg.destroy(sema.gpa);
10709 switch (dest_ty.zigTypeTag(mod)) {10625 switch (dest_ty.zigTypeTag(mod)) {
10710 .Int, .ComptimeInt => try sema.errNote(block, operand_src, msg, "use @intFromPtr to cast to '{}'", .{dest_ty.fmt(mod)}),10626 .Int, .ComptimeInt => try sema.errNote(operand_src, msg, "use @intFromPtr to cast to '{}'", .{dest_ty.fmt(mod)}),
10711 .Pointer => try sema.errNote(block, operand_src, msg, "use @ptrCast to cast to '{}'", .{dest_ty.fmt(mod)}),10627 .Pointer => try sema.errNote(operand_src, msg, "use @ptrCast to cast to '{}'", .{dest_ty.fmt(mod)}),
10712 else => {},10628 else => {},
10713 }10629 }
1071410630
...@@ -10744,7 +10660,7 @@ fn zirFloatCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A...@@ -10744,7 +10660,7 @@ fn zirFloatCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
10744 const mod = sema.mod;10660 const mod = sema.mod;
10745 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;10661 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
10746 const src = block.nodeOffset(inst_data.src_node);10662 const src = block.nodeOffset(inst_data.src_node);
10747 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };10663 const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0);
10748 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;10664 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
1074910665
10750 const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu_opt, "@floatCast");10666 const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu_opt, "@floatCast");
...@@ -10835,7 +10751,7 @@ fn zirElemValNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError...@@ -10835,7 +10751,7 @@ fn zirElemValNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
1083510751
10836 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;10752 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
10837 const src = block.nodeOffset(inst_data.src_node);10753 const src = block.nodeOffset(inst_data.src_node);
10838 const elem_index_src: LazySrcLoc = .{ .node_offset_array_access_index = inst_data.src_node };10754 const elem_index_src = block.src(.{ .node_offset_array_access_index = inst_data.src_node });
10839 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;10755 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
10840 const array = try sema.resolveInst(extra.lhs);10756 const array = try sema.resolveInst(extra.lhs);
10841 const uncoerced_elem_index = try sema.resolveInst(extra.rhs);10757 const uncoerced_elem_index = try sema.resolveInst(extra.rhs);
...@@ -10851,7 +10767,7 @@ fn zirElemValImm(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!...@@ -10851,7 +10767,7 @@ fn zirElemValImm(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
10851 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].elem_val_imm;10767 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].elem_val_imm;
10852 const array = try sema.resolveInst(inst_data.operand);10768 const array = try sema.resolveInst(inst_data.operand);
10853 const elem_index = try mod.intRef(Type.usize, inst_data.idx);10769 const elem_index = try mod.intRef(Type.usize, inst_data.idx);
10854 return sema.elemVal(block, .unneeded, array, elem_index, .unneeded, false);10770 return sema.elemVal(block, LazySrcLoc.unneeded, array, elem_index, LazySrcLoc.unneeded, false);
10855}10771}
1085610772
10857fn zirElemPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {10773fn zirElemPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
...@@ -10866,14 +10782,14 @@ fn zirElemPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air...@@ -10866,14 +10782,14 @@ fn zirElemPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
10866 const elem_index = try sema.resolveInst(extra.rhs);10782 const elem_index = try sema.resolveInst(extra.rhs);
10867 const indexable_ty = sema.typeOf(array_ptr);10783 const indexable_ty = sema.typeOf(array_ptr);
10868 if (indexable_ty.zigTypeTag(mod) != .Pointer) {10784 if (indexable_ty.zigTypeTag(mod) != .Pointer) {
10869 const capture_src: LazySrcLoc = .{ .for_capture_from_input = inst_data.src_node };10785 const capture_src = block.src(.{ .for_capture_from_input = inst_data.src_node });
10870 const msg = msg: {10786 const msg = msg: {
10871 const msg = try sema.errMsg(block, capture_src, "pointer capture of non pointer type '{}'", .{10787 const msg = try sema.errMsg(capture_src, "pointer capture of non pointer type '{}'", .{
10872 indexable_ty.fmt(mod),10788 indexable_ty.fmt(mod),
10873 });10789 });
10874 errdefer msg.destroy(sema.gpa);10790 errdefer msg.destroy(sema.gpa);
10875 if (indexable_ty.isIndexable(mod)) {10791 if (indexable_ty.isIndexable(mod)) {
10876 try sema.errNote(block, src, msg, "consider using '&' here", .{});10792 try sema.errNote(src, msg, "consider using '&' here", .{});
10877 }10793 }
10878 break :msg msg;10794 break :msg msg;
10879 };10795 };
...@@ -10888,7 +10804,7 @@ fn zirElemPtrNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError...@@ -10888,7 +10804,7 @@ fn zirElemPtrNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
1088810804
10889 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;10805 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
10890 const src = block.nodeOffset(inst_data.src_node);10806 const src = block.nodeOffset(inst_data.src_node);
10891 const elem_index_src: LazySrcLoc = .{ .node_offset_array_access_index = inst_data.src_node };10807 const elem_index_src = block.src(.{ .node_offset_array_access_index = inst_data.src_node });
10892 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;10808 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
10893 const array_ptr = try sema.resolveInst(extra.lhs);10809 const array_ptr = try sema.resolveInst(extra.lhs);
10894 const uncoerced_elem_index = try sema.resolveInst(extra.rhs);10810 const uncoerced_elem_index = try sema.resolveInst(extra.rhs);
...@@ -10925,11 +10841,11 @@ fn zirSliceStart(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!...@@ -10925,11 +10841,11 @@ fn zirSliceStart(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
10925 const extra = sema.code.extraData(Zir.Inst.SliceStart, inst_data.payload_index).data;10841 const extra = sema.code.extraData(Zir.Inst.SliceStart, inst_data.payload_index).data;
10926 const array_ptr = try sema.resolveInst(extra.lhs);10842 const array_ptr = try sema.resolveInst(extra.lhs);
10927 const start = try sema.resolveInst(extra.start);10843 const start = try sema.resolveInst(extra.start);
10928 const ptr_src: LazySrcLoc = .{ .node_offset_slice_ptr = inst_data.src_node };10844 const ptr_src = block.src(.{ .node_offset_slice_ptr = inst_data.src_node });
10929 const start_src: LazySrcLoc = .{ .node_offset_slice_start = inst_data.src_node };10845 const start_src = block.src(.{ .node_offset_slice_start = inst_data.src_node });
10930 const end_src: LazySrcLoc = .{ .node_offset_slice_end = inst_data.src_node };10846 const end_src = block.src(.{ .node_offset_slice_end = inst_data.src_node });
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);
10933}10849}
1093410850
10935fn zirSliceEnd(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {10851fn zirSliceEnd(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
...@@ -10942,11 +10858,11 @@ fn zirSliceEnd(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -10942,11 +10858,11 @@ fn zirSliceEnd(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
10942 const array_ptr = try sema.resolveInst(extra.lhs);10858 const array_ptr = try sema.resolveInst(extra.lhs);
10943 const start = try sema.resolveInst(extra.start);10859 const start = try sema.resolveInst(extra.start);
10944 const end = try sema.resolveInst(extra.end);10860 const end = try sema.resolveInst(extra.end);
10945 const ptr_src: LazySrcLoc = .{ .node_offset_slice_ptr = inst_data.src_node };10861 const ptr_src = block.src(.{ .node_offset_slice_ptr = inst_data.src_node });
10946 const start_src: LazySrcLoc = .{ .node_offset_slice_start = inst_data.src_node };10862 const start_src = block.src(.{ .node_offset_slice_start = inst_data.src_node });
10947 const end_src: LazySrcLoc = .{ .node_offset_slice_end = inst_data.src_node };10863 const end_src = block.src(.{ .node_offset_slice_end = inst_data.src_node });
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);
10950}10866}
1095110867
10952fn zirSliceSentinel(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {10868fn zirSliceSentinel(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
...@@ -10955,15 +10871,15 @@ fn zirSliceSentinel(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr...@@ -10955,15 +10871,15 @@ fn zirSliceSentinel(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr
1095510871
10956 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;10872 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
10957 const src = block.nodeOffset(inst_data.src_node);10873 const src = block.nodeOffset(inst_data.src_node);
10958 const sentinel_src: LazySrcLoc = .{ .node_offset_slice_sentinel = inst_data.src_node };10874 const sentinel_src = block.src(.{ .node_offset_slice_sentinel = inst_data.src_node });
10959 const extra = sema.code.extraData(Zir.Inst.SliceSentinel, inst_data.payload_index).data;10875 const extra = sema.code.extraData(Zir.Inst.SliceSentinel, inst_data.payload_index).data;
10960 const array_ptr = try sema.resolveInst(extra.lhs);10876 const array_ptr = try sema.resolveInst(extra.lhs);
10961 const start = try sema.resolveInst(extra.start);10877 const start = try sema.resolveInst(extra.start);
10962 const end: Air.Inst.Ref = if (extra.end == .none) .none else try sema.resolveInst(extra.end);10878 const end: Air.Inst.Ref = if (extra.end == .none) .none else try sema.resolveInst(extra.end);
10963 const sentinel = try sema.resolveInst(extra.sentinel);10879 const sentinel = try sema.resolveInst(extra.sentinel);
10964 const ptr_src: LazySrcLoc = .{ .node_offset_slice_ptr = inst_data.src_node };10880 const ptr_src = block.src(.{ .node_offset_slice_ptr = inst_data.src_node });
10965 const start_src: LazySrcLoc = .{ .node_offset_slice_start = inst_data.src_node };10881 const start_src = block.src(.{ .node_offset_slice_start = inst_data.src_node });
10966 const end_src: LazySrcLoc = .{ .node_offset_slice_end = inst_data.src_node };10882 const end_src = block.src(.{ .node_offset_slice_end = inst_data.src_node });
1096710883
10968 return sema.analyzeSlice(block, src, array_ptr, start, end, sentinel, sentinel_src, ptr_src, start_src, end_src, false);10884 return sema.analyzeSlice(block, src, array_ptr, start, end, sentinel, sentinel_src, ptr_src, start_src, end_src, false);
10969}10885}
...@@ -10979,13 +10895,13 @@ fn zirSliceLength(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError...@@ -10979,13 +10895,13 @@ fn zirSliceLength(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
10979 const start = try sema.resolveInst(extra.start);10895 const start = try sema.resolveInst(extra.start);
10980 const len = try sema.resolveInst(extra.len);10896 const len = try sema.resolveInst(extra.len);
10981 const sentinel = if (extra.sentinel == .none) .none else try sema.resolveInst(extra.sentinel);10897 const sentinel = if (extra.sentinel == .none) .none else try sema.resolveInst(extra.sentinel);
10982 const ptr_src: LazySrcLoc = .{ .node_offset_slice_ptr = inst_data.src_node };10898 const ptr_src = block.src(.{ .node_offset_slice_ptr = inst_data.src_node });
10983 const start_src: LazySrcLoc = .{ .node_offset_slice_start = extra.start_src_node_offset };10899 const start_src = block.src(.{ .node_offset_slice_start = extra.start_src_node_offset });
10984 const end_src: LazySrcLoc = .{ .node_offset_slice_end = inst_data.src_node };10900 const end_src = block.src(.{ .node_offset_slice_end = inst_data.src_node });
10985 const sentinel_src: LazySrcLoc = if (sentinel == .none)10901 const sentinel_src: LazySrcLoc = if (sentinel == .none)
10986 .unneeded10902 LazySrcLoc.unneeded
10987 else10903 else
10988 .{ .node_offset_slice_sentinel = inst_data.src_node };10904 block.src(.{ .node_offset_slice_sentinel = inst_data.src_node });
1098910905
10990 return sema.analyzeSlice(block, src, array_ptr, start, len, sentinel, sentinel_src, ptr_src, start_src, end_src, true);10906 return sema.analyzeSlice(block, src, array_ptr, start, len, sentinel, sentinel_src, ptr_src, start_src, end_src, true);
10991}10907}
...@@ -11019,8 +10935,8 @@ const SwitchProngAnalysis = struct {...@@ -11019,8 +10935,8 @@ const SwitchProngAnalysis = struct {
11019 prong_type: enum { normal, special },10935 prong_type: enum { normal, special },
11020 prong_body: []const Zir.Inst.Index,10936 prong_body: []const Zir.Inst.Index,
11021 capture: Zir.Inst.SwitchBlock.ProngInfo.Capture,10937 capture: Zir.Inst.SwitchBlock.ProngInfo.Capture,
11022 /// Must use the `scalar_capture`, `special_capture`, or `multi_capture` union field.10938 /// Must use the `switch_capture` field in `offset`.
11023 raw_capture_src: Module.SwitchProngSrc,10939 capture_src: LazySrcLoc,
11024 /// The set of all values which can reach this prong. May be undefined10940 /// The set of all values which can reach this prong. May be undefined
11025 /// if the prong is special or contains ranges.10941 /// if the prong is special or contains ranges.
11026 case_vals: []const Air.Inst.Ref,10942 case_vals: []const Air.Inst.Ref,
...@@ -11038,7 +10954,7 @@ const SwitchProngAnalysis = struct {...@@ -11038,7 +10954,7 @@ const SwitchProngAnalysis = struct {
11038 );10954 );
1103910955
11040 if (has_tag_capture) {10956 if (has_tag_capture) {
11041 const tag_ref = try spa.analyzeTagCapture(child_block, raw_capture_src, inline_case_capture);10957 const tag_ref = try spa.analyzeTagCapture(child_block, capture_src, inline_case_capture);
11042 sema.inst_map.putAssumeCapacity(spa.tag_capture_inst, tag_ref);10958 sema.inst_map.putAssumeCapacity(spa.tag_capture_inst, tag_ref);
11043 }10959 }
11044 defer if (has_tag_capture) assert(sema.inst_map.remove(spa.tag_capture_inst));10960 defer if (has_tag_capture) assert(sema.inst_map.remove(spa.tag_capture_inst));
...@@ -11053,7 +10969,7 @@ const SwitchProngAnalysis = struct {...@@ -11053,7 +10969,7 @@ const SwitchProngAnalysis = struct {
11053 child_block,10969 child_block,
11054 capture == .by_ref,10970 capture == .by_ref,
11055 prong_type == .special,10971 prong_type == .special,
11056 raw_capture_src,10972 capture_src,
11057 case_vals,10973 case_vals,
11058 inline_case_capture,10974 inline_case_capture,
11059 );10975 );
...@@ -11079,8 +10995,8 @@ const SwitchProngAnalysis = struct {...@@ -11079,8 +10995,8 @@ const SwitchProngAnalysis = struct {
11079 prong_type: enum { normal, special },10995 prong_type: enum { normal, special },
11080 prong_body: []const Zir.Inst.Index,10996 prong_body: []const Zir.Inst.Index,
11081 capture: Zir.Inst.SwitchBlock.ProngInfo.Capture,10997 capture: Zir.Inst.SwitchBlock.ProngInfo.Capture,
11082 /// Must use the `scalar`, `special`, or `multi_capture` union field.10998 /// Must use the `switch_capture` field in `offset`.
11083 raw_capture_src: Module.SwitchProngSrc,10999 capture_src: LazySrcLoc,
11084 /// The set of all values which can reach this prong. May be undefined11000 /// The set of all values which can reach this prong. May be undefined
11085 /// if the prong is special or contains ranges.11001 /// if the prong is special or contains ranges.
11086 case_vals: []const Air.Inst.Ref,11002 case_vals: []const Air.Inst.Ref,
...@@ -11094,7 +11010,7 @@ const SwitchProngAnalysis = struct {...@@ -11094,7 +11010,7 @@ const SwitchProngAnalysis = struct {
11094 const sema = spa.sema;11010 const sema = spa.sema;
1109511011
11096 if (has_tag_capture) {11012 if (has_tag_capture) {
11097 const tag_ref = try spa.analyzeTagCapture(case_block, raw_capture_src, inline_case_capture);11013 const tag_ref = try spa.analyzeTagCapture(case_block, capture_src, inline_case_capture);
11098 sema.inst_map.putAssumeCapacity(spa.tag_capture_inst, tag_ref);11014 sema.inst_map.putAssumeCapacity(spa.tag_capture_inst, tag_ref);
11099 }11015 }
11100 defer if (has_tag_capture) assert(sema.inst_map.remove(spa.tag_capture_inst));11016 defer if (has_tag_capture) assert(sema.inst_map.remove(spa.tag_capture_inst));
...@@ -11109,7 +11025,7 @@ const SwitchProngAnalysis = struct {...@@ -11109,7 +11025,7 @@ const SwitchProngAnalysis = struct {
11109 case_block,11025 case_block,
11110 capture == .by_ref,11026 capture == .by_ref,
11111 prong_type == .special,11027 prong_type == .special,
11112 raw_capture_src,11028 capture_src,
11113 case_vals,11029 case_vals,
11114 inline_case_capture,11030 inline_case_capture,
11115 );11031 );
...@@ -11130,23 +11046,18 @@ const SwitchProngAnalysis = struct {...@@ -11130,23 +11046,18 @@ const SwitchProngAnalysis = struct {
11130 fn analyzeTagCapture(11046 fn analyzeTagCapture(
11131 spa: SwitchProngAnalysis,11047 spa: SwitchProngAnalysis,
11132 block: *Block,11048 block: *Block,
11133 raw_capture_src: Module.SwitchProngSrc,11049 capture_src: LazySrcLoc,
11134 inline_case_capture: Air.Inst.Ref,11050 inline_case_capture: Air.Inst.Ref,
11135 ) CompileError!Air.Inst.Ref {11051 ) CompileError!Air.Inst.Ref {
11136 const sema = spa.sema;11052 const sema = spa.sema;
11137 const mod = sema.mod;11053 const mod = sema.mod;
11138 const operand_ty = sema.typeOf(spa.operand);11054 const operand_ty = sema.typeOf(spa.operand);
11139 if (operand_ty.zigTypeTag(mod) != .Union) {11055 if (operand_ty.zigTypeTag(mod) != .Union) {
11140 const zir_datas = sema.code.instructions.items(.data);11056 const tag_capture_src: LazySrcLoc = .{
11141 const switch_node_offset = zir_datas[@intFromEnum(spa.switch_block_inst)].pl_node.src_node;11057 .base_node_inst = capture_src.base_node_inst,
11142 const raw_tag_capture_src: Module.SwitchProngSrc = switch (raw_capture_src) {11058 .offset = .{ .switch_tag_capture = capture_src.offset.switch_capture },
11143 .scalar_capture => |i| .{ .scalar_tag_capture = i },
11144 .multi_capture => |i| .{ .multi_tag_capture = i },
11145 .special_capture => .special_tag_capture,
11146 else => unreachable,
11147 };11059 };
11148 const capture_src = raw_tag_capture_src.resolve(mod, mod.declPtr(block.src_decl), switch_node_offset, .none);11060 return sema.fail(block, tag_capture_src, "cannot capture tag of non-union type '{}'", .{
11149 return sema.fail(block, capture_src, "cannot capture tag of non-union type '{}'", .{
11150 operand_ty.fmt(mod),11061 operand_ty.fmt(mod),
11151 });11062 });
11152 }11063 }
...@@ -11159,7 +11070,7 @@ const SwitchProngAnalysis = struct {...@@ -11159,7 +11070,7 @@ const SwitchProngAnalysis = struct {
11159 block: *Block,11070 block: *Block,
11160 capture_byref: bool,11071 capture_byref: bool,
11161 is_special_prong: bool,11072 is_special_prong: bool,
11162 raw_capture_src: Module.SwitchProngSrc,11073 capture_src: LazySrcLoc,
11163 case_vals: []const Air.Inst.Ref,11074 case_vals: []const Air.Inst.Ref,
11164 inline_case_capture: Air.Inst.Ref,11075 inline_case_capture: Air.Inst.Ref,
11165 ) CompileError!Air.Inst.Ref {11076 ) CompileError!Air.Inst.Ref {
...@@ -11172,10 +11083,10 @@ const SwitchProngAnalysis = struct {...@@ -11172,10 +11083,10 @@ const SwitchProngAnalysis = struct {
1117211083
11173 const operand_ty = sema.typeOf(spa.operand);11084 const operand_ty = sema.typeOf(spa.operand);
11174 const operand_ptr_ty = if (capture_byref) sema.typeOf(spa.operand_ptr) else undefined;11085 const operand_ptr_ty = if (capture_byref) sema.typeOf(spa.operand_ptr) else undefined;
11175 const operand_src: LazySrcLoc = .{ .node_offset_switch_operand = switch_node_offset };11086 const operand_src = block.src(.{ .node_offset_switch_operand = switch_node_offset });
1117611087
11177 if (inline_case_capture != .none) {11088 if (inline_case_capture != .none) {
11178 const item_val = sema.resolveConstDefinedValue(block, .unneeded, inline_case_capture, undefined) catch unreachable;11089 const item_val = sema.resolveConstDefinedValue(block, LazySrcLoc.unneeded, inline_case_capture, undefined) catch unreachable;
11179 if (operand_ty.zigTypeTag(zcu) == .Union) {11090 if (operand_ty.zigTypeTag(zcu) == .Union) {
11180 const field_index: u32 = @intCast(operand_ty.unionTagFieldIndex(item_val, zcu).?);11091 const field_index: u32 = @intCast(operand_ty.unionTagFieldIndex(item_val, zcu).?);
11181 const union_obj = zcu.typeToUnion(operand_ty).?;11092 const union_obj = zcu.typeToUnion(operand_ty).?;
...@@ -11216,7 +11127,7 @@ const SwitchProngAnalysis = struct {...@@ -11216,7 +11127,7 @@ const SwitchProngAnalysis = struct {
11216 .ErrorSet => if (spa.else_error_ty) |ty| {11127 .ErrorSet => if (spa.else_error_ty) |ty| {
11217 return sema.bitCast(block, ty, spa.operand, operand_src, null);11128 return sema.bitCast(block, ty, spa.operand, operand_src, null);
11218 } else {11129 } else {
11219 try block.addUnreachable(operand_src, false);11130 try sema.analyzeUnreachable(block, operand_src, false);
11220 return .unreachable_value;11131 return .unreachable_value;
11221 },11132 },
11222 else => return spa.operand,11133 else => return spa.operand,
...@@ -11226,14 +11137,14 @@ const SwitchProngAnalysis = struct {...@@ -11226,14 +11137,14 @@ const SwitchProngAnalysis = struct {
11226 switch (operand_ty.zigTypeTag(zcu)) {11137 switch (operand_ty.zigTypeTag(zcu)) {
11227 .Union => {11138 .Union => {
11228 const union_obj = zcu.typeToUnion(operand_ty).?;11139 const union_obj = zcu.typeToUnion(operand_ty).?;
11229 const first_item_val = sema.resolveConstDefinedValue(block, .unneeded, case_vals[0], undefined) catch unreachable;11140 const first_item_val = sema.resolveConstDefinedValue(block, LazySrcLoc.unneeded, case_vals[0], undefined) catch unreachable;
1123011141
11231 const first_field_index: u32 = zcu.unionTagFieldIndex(union_obj, first_item_val).?;11142 const first_field_index: u32 = zcu.unionTagFieldIndex(union_obj, first_item_val).?;
11232 const first_field_ty = Type.fromInterned(union_obj.field_types.get(ip)[first_field_index]);11143 const first_field_ty = Type.fromInterned(union_obj.field_types.get(ip)[first_field_index]);
1123311144
11234 const field_indices = try sema.arena.alloc(u32, case_vals.len);11145 const field_indices = try sema.arena.alloc(u32, case_vals.len);
11235 for (case_vals, field_indices) |item, *field_idx| {11146 for (case_vals, field_indices) |item, *field_idx| {
11236 const item_val = sema.resolveConstDefinedValue(block, .unneeded, item, undefined) catch unreachable;11147 const item_val = sema.resolveConstDefinedValue(block, LazySrcLoc.unneeded, item, undefined) catch unreachable;
11237 field_idx.* = zcu.unionTagFieldIndex(union_obj, item_val).?;11148 field_idx.* = zcu.unionTagFieldIndex(union_obj, item_val).?;
11238 }11149 }
1123911150
...@@ -11253,27 +11164,22 @@ const SwitchProngAnalysis = struct {...@@ -11253,27 +11164,22 @@ const SwitchProngAnalysis = struct {
11253 }11164 }
1125411165
11255 const case_srcs = try sema.arena.alloc(?LazySrcLoc, case_vals.len);11166 const case_srcs = try sema.arena.alloc(?LazySrcLoc, case_vals.len);
11256 @memset(case_srcs, .unneeded);11167 for (case_srcs, 0..) |*case_src, i| {
1125711168 case_src.* = .{
11258 break :capture_ty sema.resolvePeerTypes(block, .unneeded, dummy_captures, .{ .override = case_srcs }) catch |err| switch (err) {11169 .base_node_inst = capture_src.base_node_inst,
11259 error.NeededSourceLocation => {11170 .offset = .{ .switch_case_item = .{
11260 // This must be a multi-prong so this must be a `multi_capture` src11171 .switch_node_offset = switch_node_offset,
11261 const multi_idx = raw_capture_src.multi_capture;11172 .case_idx = capture_src.offset.switch_capture.case_idx,
11262 const src_decl_ptr = zcu.declPtr(block.src_decl);11173 .item_idx = .{ .kind = .single, .index = @intCast(i) },
11263 for (case_srcs, 0..) |*case_src, i| {11174 } },
11264 const raw_case_src: Module.SwitchProngSrc = .{ .multi = .{ .prong = multi_idx, .item = @intCast(i) } };11175 };
11265 case_src.* = raw_case_src.resolve(zcu, src_decl_ptr, switch_node_offset, .none);11176 }
11266 }11177
11267 const capture_src = raw_capture_src.resolve(zcu, src_decl_ptr, switch_node_offset, .none);11178 break :capture_ty sema.resolvePeerTypes(block, capture_src, dummy_captures, .{ .override = case_srcs }) catch |err| switch (err) {
11268 _ = sema.resolvePeerTypes(block, capture_src, dummy_captures, .{ .override = case_srcs }) catch |err1| switch (err1) {11179 error.AnalysisFail => {
11269 error.AnalysisFail => {11180 const msg = sema.err orelse return error.AnalysisFail;
11270 const msg = sema.err orelse return error.AnalysisFail;11181 try sema.reparentOwnedErrorMsg(capture_src, msg, "capture group with incompatible types", .{});
11271 try sema.reparentOwnedErrorMsg(block, capture_src, msg, "capture group with incompatible types", .{});11182 return error.AnalysisFail;
11272 return error.AnalysisFail;
11273 },
11274 else => |e| return e,
11275 };
11276 unreachable;
11277 },11183 },
11278 else => |e| return e,11184 else => |e| return e,
11279 };11185 };
...@@ -11301,28 +11207,23 @@ const SwitchProngAnalysis = struct {...@@ -11301,28 +11207,23 @@ const SwitchProngAnalysis = struct {
11301 dummy.* = try zcu.undefRef(field_ptr_ty);11207 dummy.* = try zcu.undefRef(field_ptr_ty);
11302 }11208 }
11303 const case_srcs = try sema.arena.alloc(?LazySrcLoc, case_vals.len);11209 const case_srcs = try sema.arena.alloc(?LazySrcLoc, case_vals.len);
11304 @memset(case_srcs, .unneeded);11210 for (case_srcs, 0..) |*case_src, i| {
1130511211 case_src.* = .{
11306 break :resolve sema.resolvePeerTypes(block, .unneeded, dummy_captures, .{ .override = case_srcs }) catch |err| switch (err) {11212 .base_node_inst = capture_src.base_node_inst,
11307 error.NeededSourceLocation => {11213 .offset = .{ .switch_case_item = .{
11308 // This must be a multi-prong so this must be a `multi_capture` src11214 .switch_node_offset = switch_node_offset,
11309 const multi_idx = raw_capture_src.multi_capture;11215 .case_idx = capture_src.offset.switch_capture.case_idx,
11310 const src_decl_ptr = zcu.declPtr(block.src_decl);11216 .item_idx = .{ .kind = .single, .index = @intCast(i) },
11311 for (case_srcs, 0..) |*case_src, i| {11217 } },
11312 const raw_case_src: Module.SwitchProngSrc = .{ .multi = .{ .prong = multi_idx, .item = @intCast(i) } };11218 };
11313 case_src.* = raw_case_src.resolve(zcu, src_decl_ptr, switch_node_offset, .none);11219 }
11314 }11220
11315 const capture_src = raw_capture_src.resolve(zcu, src_decl_ptr, switch_node_offset, .none);11221 break :resolve sema.resolvePeerTypes(block, capture_src, dummy_captures, .{ .override = case_srcs }) catch |err| switch (err) {
11316 _ = sema.resolvePeerTypes(block, capture_src, dummy_captures, .{ .override = case_srcs }) catch |err1| switch (err1) {11222 error.AnalysisFail => {
11317 error.AnalysisFail => {11223 const msg = sema.err orelse return error.AnalysisFail;
11318 const msg = sema.err orelse return error.AnalysisFail;11224 try sema.errNote(capture_src, msg, "this coercion is only possible when capturing by value", .{});
11319 try sema.errNote(block, capture_src, msg, "this coercion is only possible when capturing by value", .{});11225 try sema.reparentOwnedErrorMsg(capture_src, msg, "capture group with incompatible types", .{});
11320 try sema.reparentOwnedErrorMsg(block, capture_src, msg, "capture group with incompatible types", .{});11226 return error.AnalysisFail;
11321 return error.AnalysisFail;
11322 },
11323 else => |e| return e,
11324 };
11325 unreachable;
11326 },11227 },
11327 else => |e| return e,11228 else => |e| return e,
11328 };11229 };
...@@ -11357,7 +11258,7 @@ const SwitchProngAnalysis = struct {...@@ -11357,7 +11258,7 @@ const SwitchProngAnalysis = struct {
11357 const first_non_imc = in_mem: {11258 const first_non_imc = in_mem: {
11358 for (field_indices, 0..) |field_idx, i| {11259 for (field_indices, 0..) |field_idx, i| {
11359 const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[field_idx]);11260 const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[field_idx]);
11360 if (.ok != try sema.coerceInMemoryAllowed(block, capture_ty, field_ty, false, zcu.getTarget(), .unneeded, .unneeded)) {11261 if (.ok != try sema.coerceInMemoryAllowed(block, capture_ty, field_ty, false, zcu.getTarget(), LazySrcLoc.unneeded, LazySrcLoc.unneeded)) {
11361 break :in_mem i;11262 break :in_mem i;
11362 }11263 }
11363 }11264 }
...@@ -11380,7 +11281,7 @@ const SwitchProngAnalysis = struct {...@@ -11380,7 +11281,7 @@ const SwitchProngAnalysis = struct {
11380 const next = first_non_imc + 1;11281 const next = first_non_imc + 1;
11381 for (field_indices[next..], next..) |field_idx, i| {11282 for (field_indices[next..], next..) |field_idx, i| {
11382 const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[field_idx]);11283 const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[field_idx]);
11383 if (.ok != try sema.coerceInMemoryAllowed(block, capture_ty, field_ty, false, zcu.getTarget(), .unneeded, .unneeded)) {11284 if (.ok != try sema.coerceInMemoryAllowed(block, capture_ty, field_ty, false, zcu.getTarget(), LazySrcLoc.unneeded, LazySrcLoc.unneeded)) {
11384 in_mem_coercible.unset(i);11285 in_mem_coercible.unset(i);
11385 }11286 }
11386 }11287 }
...@@ -11409,20 +11310,19 @@ const SwitchProngAnalysis = struct {...@@ -11409,20 +11310,19 @@ const SwitchProngAnalysis = struct {
11409 var coerce_block = block.makeSubBlock();11310 var coerce_block = block.makeSubBlock();
11410 defer coerce_block.instructions.deinit(sema.gpa);11311 defer coerce_block.instructions.deinit(sema.gpa);
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
11412 const field_idx = field_indices[idx];11322 const field_idx = field_indices[idx];
11413 const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[field_idx]);11323 const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[field_idx]);
11414 const uncoerced = try coerce_block.addStructFieldVal(spa.operand, field_idx, field_ty);11324 const uncoerced = try coerce_block.addStructFieldVal(spa.operand, field_idx, field_ty);
11415 const coerced = sema.coerce(&coerce_block, capture_ty, uncoerced, .unneeded) catch |err| switch (err) {11325 const coerced = try sema.coerce(&coerce_block, capture_ty, uncoerced, case_src);
11416 error.NeededSourceLocation => {
11417 const multi_idx = raw_capture_src.multi_capture;
11418 const src_decl_ptr = zcu.declPtr(block.src_decl);
11419 const raw_case_src: Module.SwitchProngSrc = .{ .multi = .{ .prong = multi_idx, .item = @intCast(idx) } };
11420 const case_src = raw_case_src.resolve(zcu, src_decl_ptr, switch_node_offset, .none);
11421 _ = try sema.coerce(&coerce_block, capture_ty, uncoerced, case_src);
11422 unreachable;
11423 },
11424 else => |e| return e,
11425 };
11426 _ = try coerce_block.addBr(capture_block_inst, coerced);11326 _ = try coerce_block.addBr(capture_block_inst, coerced);
1142711327
11428 try cases_extra.ensureUnusedCapacity(3 + coerce_block.instructions.items.len);11328 try cases_extra.ensureUnusedCapacity(3 + coerce_block.instructions.items.len);
...@@ -11476,7 +11376,6 @@ const SwitchProngAnalysis = struct {...@@ -11476,7 +11376,6 @@ const SwitchProngAnalysis = struct {
11476 },11376 },
11477 .ErrorSet => {11377 .ErrorSet => {
11478 if (capture_byref) {11378 if (capture_byref) {
11479 const capture_src = raw_capture_src.resolve(zcu, zcu.declPtr(block.src_decl), switch_node_offset, .none);
11480 return sema.fail(11379 return sema.fail(
11481 block,11380 block,
11482 capture_src,11381 capture_src,
...@@ -11486,7 +11385,7 @@ const SwitchProngAnalysis = struct {...@@ -11486,7 +11385,7 @@ const SwitchProngAnalysis = struct {
11486 }11385 }
1148711386
11488 if (case_vals.len == 1) {11387 if (case_vals.len == 1) {
11489 const item_val = sema.resolveConstDefinedValue(block, .unneeded, case_vals[0], undefined) catch unreachable;11388 const item_val = sema.resolveConstDefinedValue(block, LazySrcLoc.unneeded, case_vals[0], undefined) catch unreachable;
11490 const item_ty = try zcu.singleErrorSetType(item_val.getErrorName(zcu).unwrap().?);11389 const item_ty = try zcu.singleErrorSetType(item_val.getErrorName(zcu).unwrap().?);
11491 return sema.bitCast(block, item_ty, spa.operand, operand_src, null);11390 return sema.bitCast(block, item_ty, spa.operand, operand_src, null);
11492 }11391 }
...@@ -11494,7 +11393,7 @@ const SwitchProngAnalysis = struct {...@@ -11494,7 +11393,7 @@ const SwitchProngAnalysis = struct {
11494 var names: InferredErrorSet.NameMap = .{};11393 var names: InferredErrorSet.NameMap = .{};
11495 try names.ensureUnusedCapacity(sema.arena, case_vals.len);11394 try names.ensureUnusedCapacity(sema.arena, case_vals.len);
11496 for (case_vals) |err| {11395 for (case_vals) |err| {
11497 const err_val = sema.resolveConstDefinedValue(block, .unneeded, err, undefined) catch unreachable;11396 const err_val = sema.resolveConstDefinedValue(block, LazySrcLoc.unneeded, err, undefined) catch unreachable;
11498 names.putAssumeCapacityNoClobber(err_val.getErrorName(zcu).unwrap().?, {});11397 names.putAssumeCapacityNoClobber(err_val.getErrorName(zcu).unwrap().?, {});
11499 }11398 }
11500 const error_ty = try zcu.errorSetFromUnsortedNames(names.keys());11399 const error_ty = try zcu.errorSetFromUnsortedNames(names.keys());
...@@ -11548,10 +11447,10 @@ fn switchCond(...@@ -11548,10 +11447,10 @@ fn switchCond(
11548 try sema.resolveTypeFields(operand_ty);11447 try sema.resolveTypeFields(operand_ty);
11549 const enum_ty = operand_ty.unionTagType(mod) orelse {11448 const enum_ty = operand_ty.unionTagType(mod) orelse {
11550 const msg = msg: {11449 const msg = msg: {
11551 const msg = try sema.errMsg(block, src, "switch on union with no attached enum", .{});11450 const msg = try sema.errMsg(src, "switch on union with no attached enum", .{});
11552 errdefer msg.destroy(sema.gpa);11451 errdefer msg.destroy(sema.gpa);
11553 if (operand_ty.declSrcLocOrNull(mod)) |union_src| {11452 if (operand_ty.srcLocOrNull(mod)) |union_src| {
11554 try mod.errNoteNonLazy(union_src, msg, "consider 'union(enum)' here", .{});11453 try sema.errNote(union_src, msg, "consider 'union(enum)' here", .{});
11555 }11454 }
11556 break :msg msg;11455 break :msg msg;
11557 };11456 };
...@@ -11575,7 +11474,7 @@ fn switchCond(...@@ -11575,7 +11474,7 @@ fn switchCond(
11575 }11474 }
11576}11475}
1157711476
11578const SwitchErrorSet = std.AutoHashMap(InternPool.NullTerminatedString, Module.SwitchProngSrc);11477const SwitchErrorSet = std.AutoHashMap(InternPool.NullTerminatedString, LazySrcLoc);
1157911478
11580fn zirSwitchBlockErrUnion(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {11479fn zirSwitchBlockErrUnion(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
11581 const tracy = trace(@src());11480 const tracy = trace(@src());
...@@ -11586,11 +11485,11 @@ fn zirSwitchBlockErrUnion(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp...@@ -11586,11 +11485,11 @@ fn zirSwitchBlockErrUnion(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp
11586 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;11485 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
11587 const switch_src = block.nodeOffset(inst_data.src_node);11486 const switch_src = block.nodeOffset(inst_data.src_node);
11588 const switch_src_node_offset = inst_data.src_node;11487 const switch_src_node_offset = inst_data.src_node;
11589 const switch_operand_src: LazySrcLoc = .{ .node_offset_switch_operand = switch_src_node_offset };11488 const switch_operand_src = block.src(.{ .node_offset_switch_operand = switch_src_node_offset });
11590 const else_prong_src: LazySrcLoc = .{ .node_offset_switch_special_prong = switch_src_node_offset };11489 const else_prong_src = block.src(.{ .node_offset_switch_special_prong = switch_src_node_offset });
11591 const extra = sema.code.extraData(Zir.Inst.SwitchBlockErrUnion, inst_data.payload_index);11490 const extra = sema.code.extraData(Zir.Inst.SwitchBlockErrUnion, inst_data.payload_index);
11592 const main_operand_src: LazySrcLoc = .{ .node_offset_if_cond = extra.data.main_src_node_offset };11491 const main_operand_src = block.src(.{ .node_offset_if_cond = extra.data.main_src_node_offset });
11593 const main_src: LazySrcLoc = .{ .node_offset_main_token = extra.data.main_src_node_offset };11492 const main_src = block.src(.{ .node_offset_main_token = extra.data.main_src_node_offset });
1159411493
11595 const raw_operand_val = try sema.resolveInst(extra.data.operand);11494 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...@@ -11710,6 +11609,7 @@ fn zirSwitchBlockErrUnion(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp
11710 .runtime_index = block.runtime_index,11609 .runtime_index = block.runtime_index,
11711 .error_return_trace_index = block.error_return_trace_index,11610 .error_return_trace_index = block.error_return_trace_index,
11712 .want_safety = block.want_safety,11611 .want_safety = block.want_safety,
11612 .src_base_inst = block.src_base_inst,
11713 };11613 };
11714 const merges = &child_block.label.?.merges;11614 const merges = &child_block.label.?.merges;
11715 defer child_block.instructions.deinit(gpa);11615 defer child_block.instructions.deinit(gpa);
...@@ -11776,6 +11676,7 @@ fn zirSwitchBlockErrUnion(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp...@@ -11776,6 +11676,7 @@ fn zirSwitchBlockErrUnion(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp
11776 try sema.switchCond(block, switch_operand_src, spa.operand),11676 try sema.switchCond(block, switch_operand_src, spa.operand),
11777 err_val,11677 err_val,
11778 operand_err_set_ty,11678 operand_err_set_ty,
11679 switch_src_node_offset,
11779 .{11680 .{
11780 .body = else_case.body,11681 .body = else_case.body,
11781 .end = else_case.end,11682 .end = else_case.end,
...@@ -11817,7 +11718,7 @@ fn zirSwitchBlockErrUnion(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp...@@ -11817,7 +11718,7 @@ fn zirSwitchBlockErrUnion(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp
1181711718
11818 var sub_block = child_block.makeSubBlock();11719 var sub_block = child_block.makeSubBlock();
11819 sub_block.runtime_loop = null;11720 sub_block.runtime_loop = null;
11820 sub_block.runtime_cond = mod.declPtr(child_block.src_decl).toSrcLoc(main_operand_src, mod);11721 sub_block.runtime_cond = main_operand_src;
11821 sub_block.runtime_index.increment();11722 sub_block.runtime_index.increment();
11822 sub_block.need_debug_scope = null; // this body is emitted regardless11723 sub_block.need_debug_scope = null; // this body is emitted regardless
11823 defer sub_block.instructions.deinit(gpa);11724 defer sub_block.instructions.deinit(gpa);
...@@ -11894,8 +11795,8 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r...@@ -11894,8 +11795,8 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
11894 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;11795 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
11895 const src = block.nodeOffset(inst_data.src_node);11796 const src = block.nodeOffset(inst_data.src_node);
11896 const src_node_offset = inst_data.src_node;11797 const src_node_offset = inst_data.src_node;
11897 const operand_src: LazySrcLoc = .{ .node_offset_switch_operand = src_node_offset };11798 const operand_src = block.src(.{ .node_offset_switch_operand = src_node_offset });
11898 const special_prong_src: LazySrcLoc = .{ .node_offset_switch_special_prong = src_node_offset };11799 const special_prong_src = block.src(.{ .node_offset_switch_special_prong = src_node_offset });
11899 const extra = sema.code.extraData(Zir.Inst.SwitchBlock, inst_data.payload_index);11800 const extra = sema.code.extraData(Zir.Inst.SwitchBlock, inst_data.payload_index);
1190011801
11901 const raw_operand_val: Air.Inst.Ref, const raw_operand_ptr: Air.Inst.Ref = blk: {11802 const raw_operand_val: Air.Inst.Ref, const raw_operand_ptr: Air.Inst.Ref = blk: {
...@@ -11962,7 +11863,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r...@@ -11962,7 +11863,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
11962 const union_originally = maybe_union_ty.zigTypeTag(mod) == .Union;11863 const union_originally = maybe_union_ty.zigTypeTag(mod) == .Union;
1196311864
11964 // Duplicate checking variables later also used for `inline else`.11865 // Duplicate checking variables later also used for `inline else`.
11965 var seen_enum_fields: []?Module.SwitchProngSrc = &.{};11866 var seen_enum_fields: []?LazySrcLoc = &.{};
11966 var seen_errors = SwitchErrorSet.init(gpa);11867 var seen_errors = SwitchErrorSet.init(gpa);
11967 var range_set = RangeSet.init(gpa, mod);11868 var range_set = RangeSet.init(gpa, mod);
11968 var true_count: u8 = 0;11869 var true_count: u8 = 0;
...@@ -11985,21 +11886,18 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r...@@ -11985,21 +11886,18 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
11985 if (special_prong == .under and (!operand_ty.isNonexhaustiveEnum(mod) or union_originally)) {11886 if (special_prong == .under and (!operand_ty.isNonexhaustiveEnum(mod) or union_originally)) {
11986 const msg = msg: {11887 const msg = msg: {
11987 const msg = try sema.errMsg(11888 const msg = try sema.errMsg(
11988 block,
11989 src,11889 src,
11990 "'_' prong only allowed when switching on non-exhaustive enums",11890 "'_' prong only allowed when switching on non-exhaustive enums",
11991 .{},11891 .{},
11992 );11892 );
11993 errdefer msg.destroy(gpa);11893 errdefer msg.destroy(gpa);
11994 try sema.errNote(11894 try sema.errNote(
11995 block,
11996 special_prong_src,11895 special_prong_src,
11997 msg,11896 msg,
11998 "'_' prong here",11897 "'_' prong here",
11999 .{},11898 .{},
12000 );11899 );
12001 try sema.errNote(11900 try sema.errNote(
12002 block,
12003 src,11901 src,
12004 msg,11902 msg,
12005 "consider using 'else'",11903 "consider using 'else'",
...@@ -12014,7 +11912,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r...@@ -12014,7 +11912,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
12014 switch (operand_ty.zigTypeTag(mod)) {11912 switch (operand_ty.zigTypeTag(mod)) {
12015 .Union => unreachable, // handled in `switchCond`11913 .Union => unreachable, // handled in `switchCond`
12016 .Enum => {11914 .Enum => {
12017 seen_enum_fields = try gpa.alloc(?Module.SwitchProngSrc, operand_ty.enumFieldCount(mod));11915 seen_enum_fields = try gpa.alloc(?LazySrcLoc, operand_ty.enumFieldCount(mod));
12018 empty_enum = seen_enum_fields.len == 0 and !operand_ty.isNonexhaustiveEnum(mod);11916 empty_enum = seen_enum_fields.len == 0 and !operand_ty.isNonexhaustiveEnum(mod);
12019 @memset(seen_enum_fields, null);11917 @memset(seen_enum_fields, null);
12020 // `range_set` is used for non-exhaustive enum values that do not correspond to any tags.11918 // `range_set` is used for non-exhaustive enum values that do not correspond to any tags.
...@@ -12034,8 +11932,11 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r...@@ -12034,8 +11932,11 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
12034 &range_set,11932 &range_set,
12035 item_ref,11933 item_ref,
12036 operand_ty,11934 operand_ty,
12037 src_node_offset,11935 block.src(.{ .switch_case_item = .{
12038 .{ .scalar = scalar_i },11936 .switch_node_offset = src_node_offset,
11937 .case_idx = .{ .kind = .scalar, .index = @intCast(scalar_i) },
11938 .item_idx = .{ .kind = .single, .index = 0 },
11939 } }),
12039 ));11940 ));
12040 }11941 }
12041 }11942 }
...@@ -12059,8 +11960,11 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r...@@ -12059,8 +11960,11 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
12059 &range_set,11960 &range_set,
12060 item_ref,11961 item_ref,
12061 operand_ty,11962 operand_ty,
12062 src_node_offset,11963 block.src(.{ .switch_case_item = .{
12063 .{ .multi = .{ .prong = multi_i, .item = @intCast(item_i) } },11964 .switch_node_offset = src_node_offset,
11965 .case_idx = .{ .kind = .multi, .index = @intCast(multi_i) },
11966 .item_idx = .{ .kind = .single, .index = @intCast(item_i) },
11967 } }),
12064 ));11968 ));
12065 }11969 }
1206611970
...@@ -12081,7 +11985,6 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r...@@ -12081,7 +11985,6 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
12081 } else if (!all_tags_handled) {11985 } else if (!all_tags_handled) {
12082 const msg = msg: {11986 const msg = msg: {
12083 const msg = try sema.errMsg(11987 const msg = try sema.errMsg(
12084 block,
12085 src,11988 src,
12086 "switch must handle all possibilities",11989 "switch must handle all possibilities",
12087 .{},11990 .{},
...@@ -12099,8 +12002,8 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r...@@ -12099,8 +12002,8 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
12099 .{field_name.fmt(&mod.intern_pool)},12002 .{field_name.fmt(&mod.intern_pool)},
12100 );12003 );
12101 }12004 }
12102 try mod.errNoteNonLazy(12005 try sema.errNote(
12103 operand_ty.declSrcLoc(mod),12006 operand_ty.srcLoc(mod),
12104 msg,12007 msg,
12105 "enum '{}' declared here",12008 "enum '{}' declared here",
12106 .{operand_ty.fmt(mod)},12009 .{operand_ty.fmt(mod)},
...@@ -12144,8 +12047,11 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r...@@ -12144,8 +12047,11 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
12144 &range_set,12047 &range_set,
12145 item_ref,12048 item_ref,
12146 operand_ty,12049 operand_ty,
12147 src_node_offset,12050 block.src(.{ .switch_case_item = .{
12148 .{ .scalar = scalar_i },12051 .switch_node_offset = src_node_offset,
12052 .case_idx = .{ .kind = .scalar, .index = @intCast(scalar_i) },
12053 .item_idx = .{ .kind = .single, .index = 0 },
12054 } }),
12149 ));12055 ));
12150 }12056 }
12151 }12057 }
...@@ -12168,8 +12074,11 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r...@@ -12168,8 +12074,11 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
12168 &range_set,12074 &range_set,
12169 item_ref,12075 item_ref,
12170 operand_ty,12076 operand_ty,
12171 src_node_offset,12077 block.src(.{ .switch_case_item = .{
12172 .{ .multi = .{ .prong = multi_i, .item = @intCast(item_i) } },12078 .switch_node_offset = src_node_offset,
12079 .case_idx = .{ .kind = .multi, .index = @intCast(multi_i) },
12080 .item_idx = .{ .kind = .single, .index = @intCast(item_i) },
12081 } }),
12173 ));12082 ));
12174 }12083 }
1217512084
...@@ -12187,8 +12096,11 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r...@@ -12187,8 +12096,11 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
12187 item_first,12096 item_first,
12188 item_last,12097 item_last,
12189 operand_ty,12098 operand_ty,
12190 src_node_offset,12099 block.src(.{ .switch_case_item = .{
12191 .{ .range = .{ .prong = multi_i, .item = range_i } },12100 .switch_node_offset = src_node_offset,
12101 .case_idx = .{ .kind = .multi, .index = @intCast(multi_i) },
12102 .item_idx = .{ .kind = .range, .index = @intCast(range_i) },
12103 } }),
12192 );12104 );
12193 case_vals.appendAssumeCapacity(vals[0]);12105 case_vals.appendAssumeCapacity(vals[0]);
12194 case_vals.appendAssumeCapacity(vals[1]);12106 case_vals.appendAssumeCapacity(vals[1]);
...@@ -12239,8 +12151,11 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r...@@ -12239,8 +12151,11 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
12239 &true_count,12151 &true_count,
12240 &false_count,12152 &false_count,
12241 item_ref,12153 item_ref,
12242 src_node_offset,12154 block.src(.{ .switch_case_item = .{
12243 .{ .scalar = scalar_i },12155 .switch_node_offset = src_node_offset,
12156 .case_idx = .{ .kind = .scalar, .index = @intCast(scalar_i) },
12157 .item_idx = .{ .kind = .single, .index = 0 },
12158 } }),
12244 ));12159 ));
12245 }12160 }
12246 }12161 }
...@@ -12263,8 +12178,11 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r...@@ -12263,8 +12178,11 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
12263 &true_count,12178 &true_count,
12264 &false_count,12179 &false_count,
12265 item_ref,12180 item_ref,
12266 src_node_offset,12181 block.src(.{ .switch_case_item = .{
12267 .{ .multi = .{ .prong = multi_i, .item = @intCast(item_i) } },12182 .switch_node_offset = src_node_offset,
12183 .case_idx = .{ .kind = .multi, .index = @intCast(multi_i) },
12184 .item_idx = .{ .kind = .single, .index = @intCast(item_i) },
12185 } }),
12268 ));12186 ));
12269 }12187 }
1227012188
...@@ -12322,8 +12240,11 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r...@@ -12322,8 +12240,11 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
12322 &seen_values,12240 &seen_values,
12323 item_ref,12241 item_ref,
12324 operand_ty,12242 operand_ty,
12325 src_node_offset,12243 block.src(.{ .switch_case_item = .{
12326 .{ .scalar = scalar_i },12244 .switch_node_offset = src_node_offset,
12245 .case_idx = .{ .kind = .scalar, .index = @intCast(scalar_i) },
12246 .item_idx = .{ .kind = .single, .index = 0 },
12247 } }),
12327 ));12248 ));
12328 }12249 }
12329 }12250 }
...@@ -12346,8 +12267,11 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r...@@ -12346,8 +12267,11 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
12346 &seen_values,12267 &seen_values,
12347 item_ref,12268 item_ref,
12348 operand_ty,12269 operand_ty,
12349 src_node_offset,12270 block.src(.{ .switch_case_item = .{
12350 .{ .multi = .{ .prong = multi_i, .item = @intCast(item_i) } },12271 .switch_node_offset = src_node_offset,
12272 .case_idx = .{ .kind = .multi, .index = @intCast(multi_i) },
12273 .item_idx = .{ .kind = .single, .index = @intCast(item_i) },
12274 } }),
12351 ));12275 ));
12352 }12276 }
1235312277
...@@ -12417,6 +12341,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r...@@ -12417,6 +12341,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
12417 .runtime_index = block.runtime_index,12341 .runtime_index = block.runtime_index,
12418 .want_safety = block.want_safety,12342 .want_safety = block.want_safety,
12419 .error_return_trace_index = block.error_return_trace_index,12343 .error_return_trace_index = block.error_return_trace_index,
12344 .src_base_inst = block.src_base_inst,
12420 };12345 };
12421 const merges = &child_block.label.?.merges;12346 const merges = &child_block.label.?.merges;
12422 defer child_block.instructions.deinit(gpa);12347 defer child_block.instructions.deinit(gpa);
...@@ -12430,6 +12355,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r...@@ -12430,6 +12355,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
12430 operand,12355 operand,
12431 operand_val,12356 operand_val,
12432 operand_ty,12357 operand_ty,
12358 src_node_offset,
12433 special,12359 special,
12434 case_vals,12360 case_vals,
12435 scalar_cases_len,12361 scalar_cases_len,
...@@ -12462,7 +12388,10 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r...@@ -12462,7 +12388,10 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
12462 .special,12388 .special,
12463 special.body,12389 special.body,
12464 special.capture,12390 special.capture,
12465 .special_capture,12391 block.src(.{ .switch_capture = .{
12392 .switch_node_offset = src_node_offset,
12393 .case_idx = LazySrcLoc.Offset.SwitchCaseIndex.special,
12394 } }),
12466 undefined, // case_vals may be undefined for special prongs12395 undefined, // case_vals may be undefined for special prongs
12467 .none,12396 .none,
12468 false,12397 false,
...@@ -12529,9 +12458,9 @@ fn analyzeSwitchRuntimeBlock(...@@ -12529,9 +12458,9 @@ fn analyzeSwitchRuntimeBlock(
12529 union_originally: bool,12458 union_originally: bool,
12530 maybe_union_ty: Type,12459 maybe_union_ty: Type,
12531 err_set: bool,12460 err_set: bool,
12532 src_node_offset: i32,12461 switch_node_offset: i32,
12533 special_prong_src: LazySrcLoc,12462 special_prong_src: LazySrcLoc,
12534 seen_enum_fields: []?Module.SwitchProngSrc,12463 seen_enum_fields: []?LazySrcLoc,
12535 seen_errors: SwitchErrorSet,12464 seen_errors: SwitchErrorSet,
12536 range_set: RangeSet,12465 range_set: RangeSet,
12537 true_count: u8,12466 true_count: u8,
...@@ -12552,7 +12481,7 @@ fn analyzeSwitchRuntimeBlock(...@@ -12552,7 +12481,7 @@ fn analyzeSwitchRuntimeBlock(
1255212481
12553 var case_block = child_block.makeSubBlock();12482 var case_block = child_block.makeSubBlock();
12554 case_block.runtime_loop = null;12483 case_block.runtime_loop = null;
12555 case_block.runtime_cond = mod.declPtr(child_block.src_decl).toSrcLoc(operand_src, mod);12484 case_block.runtime_cond = operand_src;
12556 case_block.runtime_index.increment();12485 case_block.runtime_index.increment();
12557 case_block.need_debug_scope = null; // this body is emitted regardless12486 case_block.need_debug_scope = null; // this body is emitted regardless
12558 defer case_block.instructions.deinit(gpa);12487 defer case_block.instructions.deinit(gpa);
...@@ -12574,7 +12503,7 @@ fn analyzeSwitchRuntimeBlock(...@@ -12574,7 +12503,7 @@ fn analyzeSwitchRuntimeBlock(
12574 // `item` is already guaranteed to be constant known.12503 // `item` is already guaranteed to be constant known.
1257512504
12576 const analyze_body = if (union_originally) blk: {12505 const analyze_body = if (union_originally) blk: {
12577 const unresolved_item_val = sema.resolveConstDefinedValue(block, .unneeded, item, undefined) catch unreachable;12506 const unresolved_item_val = sema.resolveConstDefinedValue(block, LazySrcLoc.unneeded, item, undefined) catch unreachable;
12578 const item_val = sema.resolveLazyValue(unresolved_item_val) catch unreachable;12507 const item_val = sema.resolveLazyValue(unresolved_item_val) catch unreachable;
12579 const field_ty = maybe_union_ty.unionFieldType(item_val, mod).?;12508 const field_ty = maybe_union_ty.unionFieldType(item_val, mod).?;
12580 break :blk field_ty.zigTypeTag(mod) != .NoReturn;12509 break :blk field_ty.zigTypeTag(mod) != .NoReturn;
...@@ -12588,7 +12517,10 @@ fn analyzeSwitchRuntimeBlock(...@@ -12588,7 +12517,10 @@ fn analyzeSwitchRuntimeBlock(
12588 .normal,12517 .normal,
12589 body,12518 body,
12590 info.capture,12519 info.capture,
12591 .{ .scalar_capture = @intCast(scalar_i) },12520 child_block.src(.{ .switch_capture = .{
12521 .switch_node_offset = switch_node_offset,
12522 .case_idx = .{ .kind = .scalar, .index = @intCast(scalar_i) },
12523 } }),
12592 &.{item},12524 &.{item},
12593 if (info.is_inline) item else .none,12525 if (info.is_inline) item else .none,
12594 info.has_tag_capture,12526 info.has_tag_capture,
...@@ -12643,8 +12575,8 @@ fn analyzeSwitchRuntimeBlock(...@@ -12643,8 +12575,8 @@ fn analyzeSwitchRuntimeBlock(
12643 const item_first_ref = range_items[0];12575 const item_first_ref = range_items[0];
12644 const item_last_ref = range_items[1];12576 const item_last_ref = range_items[1];
1264512577
12646 var item = sema.resolveConstDefinedValue(block, .unneeded, item_first_ref, undefined) catch unreachable;12578 var item = sema.resolveConstDefinedValue(block, LazySrcLoc.unneeded, item_first_ref, undefined) catch unreachable;
12647 const item_last = sema.resolveConstDefinedValue(block, .unneeded, item_last_ref, undefined) catch unreachable;12579 const item_last = sema.resolveConstDefinedValue(block, LazySrcLoc.unneeded, item_last_ref, undefined) catch unreachable;
1264812580
12649 while (item.compareScalar(.lte, item_last, operand_ty, mod)) : ({12581 while (item.compareScalar(.lte, item_last, operand_ty, mod)) : ({
12650 // Previous validation has resolved any possible lazy values.12582 // Previous validation has resolved any possible lazy values.
...@@ -12660,17 +12592,11 @@ fn analyzeSwitchRuntimeBlock(...@@ -12660,17 +12592,11 @@ fn analyzeSwitchRuntimeBlock(
12660 case_block.instructions.shrinkRetainingCapacity(0);12592 case_block.instructions.shrinkRetainingCapacity(0);
12661 case_block.error_return_trace_index = child_block.error_return_trace_index;12593 case_block.error_return_trace_index = child_block.error_return_trace_index;
1266212594
12663 if (emit_bb) sema.emitBackwardBranch(block, .unneeded) catch |err| switch (err) {12595 if (emit_bb) try sema.emitBackwardBranch(block, block.src(.{ .switch_case_item = .{
12664 error.NeededSourceLocation => {12596 .switch_node_offset = switch_node_offset,
12665 const case_src = Module.SwitchProngSrc{12597 .case_idx = .{ .kind = .multi, .index = @intCast(multi_i) },
12666 .range = .{ .prong = multi_i, .item = range_i },12598 .item_idx = .{ .kind = .range, .index = @intCast(range_i) },
12667 };12599 } }));
12668 const decl = mod.declPtr(case_block.src_decl);
12669 try sema.emitBackwardBranch(block, case_src.resolve(mod, decl, src_node_offset, .none));
12670 unreachable;
12671 },
12672 else => return err,
12673 };
12674 emit_bb = true;12600 emit_bb = true;
1267512601
12676 try spa.analyzeProngRuntime(12602 try spa.analyzeProngRuntime(
...@@ -12678,7 +12604,10 @@ fn analyzeSwitchRuntimeBlock(...@@ -12678,7 +12604,10 @@ fn analyzeSwitchRuntimeBlock(
12678 .normal,12604 .normal,
12679 body,12605 body,
12680 info.capture,12606 info.capture,
12681 .{ .multi_capture = multi_i },12607 child_block.src(.{ .switch_capture = .{
12608 .switch_node_offset = switch_node_offset,
12609 .case_idx = .{ .kind = .multi, .index = @intCast(multi_i) },
12610 } }),
12682 undefined, // case_vals may be undefined for ranges12611 undefined, // case_vals may be undefined for ranges
12683 item_ref,12612 item_ref,
12684 info.has_tag_capture,12613 info.has_tag_capture,
...@@ -12701,22 +12630,16 @@ fn analyzeSwitchRuntimeBlock(...@@ -12701,22 +12630,16 @@ fn analyzeSwitchRuntimeBlock(
12701 case_block.error_return_trace_index = child_block.error_return_trace_index;12630 case_block.error_return_trace_index = child_block.error_return_trace_index;
1270212631
12703 const analyze_body = if (union_originally) blk: {12632 const analyze_body = if (union_originally) blk: {
12704 const item_val = sema.resolveConstDefinedValue(block, .unneeded, item, undefined) catch unreachable;12633 const item_val = sema.resolveConstDefinedValue(block, LazySrcLoc.unneeded, item, undefined) catch unreachable;
12705 const field_ty = maybe_union_ty.unionFieldType(item_val, mod).?;12634 const field_ty = maybe_union_ty.unionFieldType(item_val, mod).?;
12706 break :blk field_ty.zigTypeTag(mod) != .NoReturn;12635 break :blk field_ty.zigTypeTag(mod) != .NoReturn;
12707 } else true;12636 } else true;
1270812637
12709 if (emit_bb) sema.emitBackwardBranch(block, .unneeded) catch |err| switch (err) {12638 if (emit_bb) try sema.emitBackwardBranch(block, block.src(.{ .switch_case_item = .{
12710 error.NeededSourceLocation => {12639 .switch_node_offset = switch_node_offset,
12711 const case_src = Module.SwitchProngSrc{12640 .case_idx = .{ .kind = .multi, .index = @intCast(multi_i) },
12712 .multi = .{ .prong = multi_i, .item = @intCast(item_i) },12641 .item_idx = .{ .kind = .single, .index = @intCast(item_i) },
12713 };12642 } }));
12714 const decl = mod.declPtr(case_block.src_decl);
12715 try sema.emitBackwardBranch(block, case_src.resolve(mod, decl, src_node_offset, .none));
12716 unreachable;
12717 },
12718 else => return err,
12719 };
12720 emit_bb = true;12643 emit_bb = true;
1272112644
12722 if (analyze_body) {12645 if (analyze_body) {
...@@ -12725,7 +12648,10 @@ fn analyzeSwitchRuntimeBlock(...@@ -12725,7 +12648,10 @@ fn analyzeSwitchRuntimeBlock(
12725 .normal,12648 .normal,
12726 body,12649 body,
12727 info.capture,12650 info.capture,
12728 .{ .multi_capture = multi_i },12651 child_block.src(.{ .switch_capture = .{
12652 .switch_node_offset = switch_node_offset,
12653 .case_idx = .{ .kind = .multi, .index = @intCast(multi_i) },
12654 } }),
12729 &.{item},12655 &.{item},
12730 item,12656 item,
12731 info.has_tag_capture,12657 info.has_tag_capture,
...@@ -12755,7 +12681,7 @@ fn analyzeSwitchRuntimeBlock(...@@ -12755,7 +12681,7 @@ fn analyzeSwitchRuntimeBlock(
1275512681
12756 const analyze_body = if (union_originally)12682 const analyze_body = if (union_originally)
12757 for (items) |item| {12683 for (items) |item| {
12758 const item_val = sema.resolveConstDefinedValue(block, .unneeded, item, undefined) catch unreachable;12684 const item_val = sema.resolveConstDefinedValue(block, LazySrcLoc.unneeded, item, undefined) catch unreachable;
12759 const field_ty = maybe_union_ty.unionFieldType(item_val, mod).?;12685 const field_ty = maybe_union_ty.unionFieldType(item_val, mod).?;
12760 if (field_ty.zigTypeTag(mod) != .NoReturn) break true;12686 if (field_ty.zigTypeTag(mod) != .NoReturn) break true;
12761 } else false12687 } else false
...@@ -12772,7 +12698,10 @@ fn analyzeSwitchRuntimeBlock(...@@ -12772,7 +12698,10 @@ fn analyzeSwitchRuntimeBlock(
12772 .normal,12698 .normal,
12773 body,12699 body,
12774 info.capture,12700 info.capture,
12775 .{ .multi_capture = multi_i },12701 child_block.src(.{ .switch_capture = .{
12702 .switch_node_offset = switch_node_offset,
12703 .case_idx = .{ .kind = .multi, .index = @intCast(multi_i) },
12704 } }),
12776 items,12705 items,
12777 .none,12706 .none,
12778 false,12707 false,
...@@ -12856,7 +12785,10 @@ fn analyzeSwitchRuntimeBlock(...@@ -12856,7 +12785,10 @@ fn analyzeSwitchRuntimeBlock(
12856 .normal,12785 .normal,
12857 body,12786 body,
12858 info.capture,12787 info.capture,
12859 .{ .multi_capture = multi_i },12788 child_block.src(.{ .switch_capture = .{
12789 .switch_node_offset = switch_node_offset,
12790 .case_idx = .{ .kind = .multi, .index = @intCast(multi_i) },
12791 } }),
12860 items,12792 items,
12861 .none,12793 .none,
12862 false,12794 false,
...@@ -12921,7 +12853,10 @@ fn analyzeSwitchRuntimeBlock(...@@ -12921,7 +12853,10 @@ fn analyzeSwitchRuntimeBlock(
12921 .special,12853 .special,
12922 special.body,12854 special.body,
12923 special.capture,12855 special.capture,
12924 .special_capture,12856 child_block.src(.{ .switch_capture = .{
12857 .switch_node_offset = switch_node_offset,
12858 .case_idx = LazySrcLoc.Offset.SwitchCaseIndex.special,
12859 } }),
12925 &.{item_ref},12860 &.{item_ref},
12926 item_ref,12861 item_ref,
12927 special.has_tag_capture,12862 special.has_tag_capture,
...@@ -12966,7 +12901,10 @@ fn analyzeSwitchRuntimeBlock(...@@ -12966,7 +12901,10 @@ fn analyzeSwitchRuntimeBlock(
12966 .special,12901 .special,
12967 special.body,12902 special.body,
12968 special.capture,12903 special.capture,
12969 .special_capture,12904 child_block.src(.{ .switch_capture = .{
12905 .switch_node_offset = switch_node_offset,
12906 .case_idx = LazySrcLoc.Offset.SwitchCaseIndex.special,
12907 } }),
12970 &.{item_ref},12908 &.{item_ref},
12971 item_ref,12909 item_ref,
12972 special.has_tag_capture,12910 special.has_tag_capture,
...@@ -12997,7 +12935,10 @@ fn analyzeSwitchRuntimeBlock(...@@ -12997,7 +12935,10 @@ fn analyzeSwitchRuntimeBlock(
12997 .special,12935 .special,
12998 special.body,12936 special.body,
12999 special.capture,12937 special.capture,
13000 .special_capture,12938 child_block.src(.{ .switch_capture = .{
12939 .switch_node_offset = switch_node_offset,
12940 .case_idx = LazySrcLoc.Offset.SwitchCaseIndex.special,
12941 } }),
13001 &.{item_ref},12942 &.{item_ref},
13002 item_ref,12943 item_ref,
13003 special.has_tag_capture,12944 special.has_tag_capture,
...@@ -13025,7 +12966,10 @@ fn analyzeSwitchRuntimeBlock(...@@ -13025,7 +12966,10 @@ fn analyzeSwitchRuntimeBlock(
13025 .special,12966 .special,
13026 special.body,12967 special.body,
13027 special.capture,12968 special.capture,
13028 .special_capture,12969 child_block.src(.{ .switch_capture = .{
12970 .switch_node_offset = switch_node_offset,
12971 .case_idx = LazySrcLoc.Offset.SwitchCaseIndex.special,
12972 } }),
13029 &.{.bool_true},12973 &.{.bool_true},
13030 .bool_true,12974 .bool_true,
13031 special.has_tag_capture,12975 special.has_tag_capture,
...@@ -13051,7 +12995,10 @@ fn analyzeSwitchRuntimeBlock(...@@ -13051,7 +12995,10 @@ fn analyzeSwitchRuntimeBlock(
13051 .special,12995 .special,
13052 special.body,12996 special.body,
13053 special.capture,12997 special.capture,
13054 .special_capture,12998 child_block.src(.{ .switch_capture = .{
12999 .switch_node_offset = switch_node_offset,
13000 .case_idx = LazySrcLoc.Offset.SwitchCaseIndex.special,
13001 } }),
13055 &.{.bool_false},13002 &.{.bool_false},
13056 .bool_false,13003 .bool_false,
13057 special.has_tag_capture,13004 special.has_tag_capture,
...@@ -13101,7 +13048,10 @@ fn analyzeSwitchRuntimeBlock(...@@ -13101,7 +13048,10 @@ fn analyzeSwitchRuntimeBlock(
13101 .special,13048 .special,
13102 special.body,13049 special.body,
13103 special.capture,13050 special.capture,
13104 .special_capture,13051 child_block.src(.{ .switch_capture = .{
13052 .switch_node_offset = switch_node_offset,
13053 .case_idx = LazySrcLoc.Offset.SwitchCaseIndex.special,
13054 } }),
13105 undefined, // case_vals may be undefined for special prongs13055 undefined, // case_vals may be undefined for special prongs
13106 .none,13056 .none,
13107 false,13057 false,
...@@ -13161,6 +13111,7 @@ fn resolveSwitchComptime(...@@ -13161,6 +13111,7 @@ fn resolveSwitchComptime(
13161 cond_operand: Air.Inst.Ref,13111 cond_operand: Air.Inst.Ref,
13162 operand_val: Value,13112 operand_val: Value,
13163 operand_ty: Type,13113 operand_ty: Type,
13114 switch_node_offset: i32,
13164 special: SpecialProng,13115 special: SpecialProng,
13165 case_vals: std.ArrayListUnmanaged(Air.Inst.Ref),13116 case_vals: std.ArrayListUnmanaged(Air.Inst.Ref),
13166 scalar_cases_len: u32,13117 scalar_cases_len: u32,
...@@ -13181,7 +13132,7 @@ fn resolveSwitchComptime(...@@ -13181,7 +13132,7 @@ fn resolveSwitchComptime(
13181 extra_index += info.body_len;13132 extra_index += info.body_len;
1318213133
13183 const item = case_vals.items[scalar_i];13134 const item = case_vals.items[scalar_i];
13184 const item_val = sema.resolveConstDefinedValue(child_block, .unneeded, item, undefined) catch unreachable;13135 const item_val = sema.resolveConstDefinedValue(child_block, LazySrcLoc.unneeded, item, undefined) catch unreachable;
13185 if (operand_val.eql(item_val, operand_ty, sema.mod)) {13136 if (operand_val.eql(item_val, operand_ty, sema.mod)) {
13186 if (err_set) try sema.maybeErrorUnwrapComptime(child_block, body, cond_operand);13137 if (err_set) try sema.maybeErrorUnwrapComptime(child_block, body, cond_operand);
13187 return spa.resolveProngComptime(13138 return spa.resolveProngComptime(
...@@ -13189,7 +13140,10 @@ fn resolveSwitchComptime(...@@ -13189,7 +13140,10 @@ fn resolveSwitchComptime(
13189 .normal,13140 .normal,
13190 body,13141 body,
13191 info.capture,13142 info.capture,
13192 .{ .scalar_capture = @intCast(scalar_i) },13143 child_block.src(.{ .switch_capture = .{
13144 .switch_node_offset = switch_node_offset,
13145 .case_idx = .{ .kind = .scalar, .index = @intCast(scalar_i) },
13146 } }),
13193 &.{item},13147 &.{item},
13194 if (info.is_inline) cond_operand else .none,13148 if (info.is_inline) cond_operand else .none,
13195 info.has_tag_capture,13149 info.has_tag_capture,
...@@ -13215,7 +13169,7 @@ fn resolveSwitchComptime(...@@ -13215,7 +13169,7 @@ fn resolveSwitchComptime(
1321513169
13216 for (items) |item| {13170 for (items) |item| {
13217 // Validation above ensured these will succeed.13171 // Validation above ensured these will succeed.
13218 const item_val = sema.resolveConstDefinedValue(child_block, .unneeded, item, undefined) catch unreachable;13172 const item_val = sema.resolveConstDefinedValue(child_block, LazySrcLoc.unneeded, item, undefined) catch unreachable;
13219 if (operand_val.eql(item_val, operand_ty, sema.mod)) {13173 if (operand_val.eql(item_val, operand_ty, sema.mod)) {
13220 if (err_set) try sema.maybeErrorUnwrapComptime(child_block, body, cond_operand);13174 if (err_set) try sema.maybeErrorUnwrapComptime(child_block, body, cond_operand);
13221 return spa.resolveProngComptime(13175 return spa.resolveProngComptime(
...@@ -13223,7 +13177,10 @@ fn resolveSwitchComptime(...@@ -13223,7 +13177,10 @@ fn resolveSwitchComptime(
13223 .normal,13177 .normal,
13224 body,13178 body,
13225 info.capture,13179 info.capture,
13226 .{ .multi_capture = @intCast(multi_i) },13180 child_block.src(.{ .switch_capture = .{
13181 .switch_node_offset = switch_node_offset,
13182 .case_idx = .{ .kind = .multi, .index = @intCast(multi_i) },
13183 } }),
13227 items,13184 items,
13228 if (info.is_inline) cond_operand else .none,13185 if (info.is_inline) cond_operand else .none,
13229 info.has_tag_capture,13186 info.has_tag_capture,
...@@ -13239,8 +13196,8 @@ fn resolveSwitchComptime(...@@ -13239,8 +13196,8 @@ fn resolveSwitchComptime(
13239 case_val_idx += 2;13196 case_val_idx += 2;
1324013197
13241 // Validation above ensured these will succeed.13198 // Validation above ensured these will succeed.
13242 const first_val = sema.resolveConstDefinedValue(child_block, .unneeded, range_items[0], undefined) catch unreachable;13199 const first_val = sema.resolveConstDefinedValue(child_block, LazySrcLoc.unneeded, range_items[0], undefined) catch unreachable;
13243 const last_val = sema.resolveConstDefinedValue(child_block, .unneeded, range_items[1], undefined) catch unreachable;13200 const last_val = sema.resolveConstDefinedValue(child_block, LazySrcLoc.unneeded, range_items[1], undefined) catch unreachable;
13244 if ((try sema.compareAll(resolved_operand_val, .gte, first_val, operand_ty)) and13201 if ((try sema.compareAll(resolved_operand_val, .gte, first_val, operand_ty)) and
13245 (try sema.compareAll(resolved_operand_val, .lte, last_val, operand_ty)))13202 (try sema.compareAll(resolved_operand_val, .lte, last_val, operand_ty)))
13246 {13203 {
...@@ -13250,7 +13207,10 @@ fn resolveSwitchComptime(...@@ -13250,7 +13207,10 @@ fn resolveSwitchComptime(
13250 .normal,13207 .normal,
13251 body,13208 body,
13252 info.capture,13209 info.capture,
13253 .{ .multi_capture = @intCast(multi_i) },13210 child_block.src(.{ .switch_capture = .{
13211 .switch_node_offset = switch_node_offset,
13212 .case_idx = .{ .kind = .multi, .index = @intCast(multi_i) },
13213 } }),
13254 undefined, // case_vals may be undefined for ranges13214 undefined, // case_vals may be undefined for ranges
13255 if (info.is_inline) cond_operand else .none,13215 if (info.is_inline) cond_operand else .none,
13256 info.has_tag_capture,13216 info.has_tag_capture,
...@@ -13272,7 +13232,10 @@ fn resolveSwitchComptime(...@@ -13272,7 +13232,10 @@ fn resolveSwitchComptime(
13272 .special,13232 .special,
13273 special.body,13233 special.body,
13274 special.capture,13234 special.capture,
13275 .special_capture,13235 child_block.src(.{ .switch_capture = .{
13236 .switch_node_offset = switch_node_offset,
13237 .case_idx = LazySrcLoc.Offset.SwitchCaseIndex.special,
13238 } }),
13276 undefined, // case_vals may be undefined for special prongs13239 undefined, // case_vals may be undefined for special prongs
13277 if (special.is_inline) cond_operand else .none,13240 if (special.is_inline) cond_operand else .none,
13278 special.has_tag_capture,13241 special.has_tag_capture,
...@@ -13358,36 +13321,19 @@ fn resolveSwitchItemVal(...@@ -13358,36 +13321,19 @@ fn resolveSwitchItemVal(
13358 item_ref: Zir.Inst.Ref,13321 item_ref: Zir.Inst.Ref,
13359 /// Coerce `item_ref` to this type.13322 /// Coerce `item_ref` to this type.
13360 coerce_ty: Type,13323 coerce_ty: Type,
13361 switch_node_offset: i32,13324 item_src: LazySrcLoc,
13362 switch_prong_src: Module.SwitchProngSrc,
13363 range_expand: Module.SwitchProngSrc.RangeExpand,
13364) CompileError!ResolvedSwitchItem {13325) CompileError!ResolvedSwitchItem {
13365 const mod = sema.mod;
13366 const uncoerced_item = try sema.resolveInst(item_ref);13326 const uncoerced_item = try sema.resolveInst(item_ref);
1336713327
13368 // Constructing a LazySrcLoc is costly because we only have the switch AST node.13328 // Constructing a LazySrcLoc is costly because we only have the switch AST node.
13369 // Only if we know for sure we need to report a compile error do we resolve the13329 // Only if we know for sure we need to report a compile error do we resolve the
13370 // full source locations.13330 // full source locations.
1337113331
13372 const item = sema.coerce(block, coerce_ty, uncoerced_item, .unneeded) catch |err| switch (err) {13332 const item = try sema.coerce(block, coerce_ty, uncoerced_item, item_src);
13373 error.NeededSourceLocation => {
13374 const src = switch_prong_src.resolve(mod, mod.declPtr(block.src_decl), switch_node_offset, range_expand);
13375 _ = try sema.coerce(block, coerce_ty, uncoerced_item, src);
13376 unreachable;
13377 },
13378 else => |e| return e,
13379 };
1338013333
13381 const maybe_lazy = sema.resolveConstDefinedValue(block, .unneeded, item, undefined) catch |err| switch (err) {13334 const maybe_lazy = try sema.resolveConstDefinedValue(block, item_src, item, .{
13382 error.NeededSourceLocation => {13335 .needed_comptime_reason = "switch prong values must be comptime-known",
13383 const src = switch_prong_src.resolve(mod, mod.declPtr(block.src_decl), switch_node_offset, range_expand);13336 });
13384 _ = try sema.resolveConstDefinedValue(block, src, item, .{
13385 .needed_comptime_reason = "switch prong values must be comptime-known",
13386 });
13387 unreachable;
13388 },
13389 else => |e| return e,
13390 };
1339113337
13392 const val = try sema.resolveLazyValue(maybe_lazy);13338 const val = try sema.resolveLazyValue(maybe_lazy);
13393 const new_item = if (val.toIntern() != maybe_lazy.toIntern()) blk: {13339 const new_item = if (val.toIntern() != maybe_lazy.toIntern()) blk: {
...@@ -13430,8 +13376,11 @@ fn validateErrSetSwitch(...@@ -13430,8 +13376,11 @@ fn validateErrSetSwitch(
13430 seen_errors,13376 seen_errors,
13431 item_ref,13377 item_ref,
13432 operand_ty,13378 operand_ty,
13433 src_node_offset,13379 block.src(.{ .switch_case_item = .{
13434 .{ .scalar = scalar_i },13380 .switch_node_offset = src_node_offset,
13381 .case_idx = .{ .kind = .scalar, .index = @intCast(scalar_i) },
13382 .item_idx = .{ .kind = .single, .index = 0 },
13383 } }),
13435 ));13384 ));
13436 }13385 }
13437 }13386 }
...@@ -13454,8 +13403,11 @@ fn validateErrSetSwitch(...@@ -13454,8 +13403,11 @@ fn validateErrSetSwitch(
13454 seen_errors,13403 seen_errors,
13455 item_ref,13404 item_ref,
13456 operand_ty,13405 operand_ty,
13457 src_node_offset,13406 block.src(.{ .switch_case_item = .{
13458 .{ .multi = .{ .prong = multi_i, .item = @intCast(item_i) } },13407 .switch_node_offset = src_node_offset,
13408 .case_idx = .{ .kind = .multi, .index = @intCast(multi_i) },
13409 .item_idx = .{ .kind = .single, .index = @intCast(item_i) },
13410 } }),
13459 ));13411 ));
13460 }13412 }
1346113413
...@@ -13484,7 +13436,6 @@ fn validateErrSetSwitch(...@@ -13484,7 +13436,6 @@ fn validateErrSetSwitch(
13484 if (!seen_errors.contains(error_name) and !has_else) {13436 if (!seen_errors.contains(error_name) and !has_else) {
13485 const msg = maybe_msg orelse blk: {13437 const msg = maybe_msg orelse blk: {
13486 maybe_msg = try sema.errMsg(13438 maybe_msg = try sema.errMsg(
13487 block,
13488 src,13439 src,
13489 "switch must handle all possibilities",13440 "switch must handle all possibilities",
13490 .{},13441 .{},
...@@ -13493,7 +13444,6 @@ fn validateErrSetSwitch(...@@ -13493,7 +13444,6 @@ fn validateErrSetSwitch(
13493 };13444 };
1349413445
13495 try sema.errNote(13446 try sema.errNote(
13496 block,
13497 src,13447 src,
13498 msg,13448 msg,
13499 "unhandled error value: 'error.{}'",13449 "unhandled error value: 'error.{}'",
...@@ -13571,18 +13521,24 @@ fn validateSwitchRange(...@@ -13571,18 +13521,24 @@ fn validateSwitchRange(
13571 first_ref: Zir.Inst.Ref,13521 first_ref: Zir.Inst.Ref,
13572 last_ref: Zir.Inst.Ref,13522 last_ref: Zir.Inst.Ref,
13573 operand_ty: Type,13523 operand_ty: Type,
13574 src_node_offset: i32,13524 item_src: LazySrcLoc,
13575 switch_prong_src: Module.SwitchProngSrc,
13576) CompileError![2]Air.Inst.Ref {13525) CompileError![2]Air.Inst.Ref {
13577 const mod = sema.mod;13526 const mod = sema.mod;
13578 const first = try sema.resolveSwitchItemVal(block, first_ref, operand_ty, src_node_offset, switch_prong_src, .first);13527 const first_src: LazySrcLoc = .{
13579 const last = try sema.resolveSwitchItemVal(block, last_ref, operand_ty, src_node_offset, switch_prong_src, .last);13528 .base_node_inst = item_src.base_node_inst,
13529 .offset = .{ .switch_case_item_range_first = item_src.offset.switch_case_item },
13530 };
13531 const last_src: LazySrcLoc = .{
13532 .base_node_inst = item_src.base_node_inst,
13533 .offset = .{ .switch_case_item_range_last = item_src.offset.switch_case_item },
13534 };
13535 const first = try sema.resolveSwitchItemVal(block, first_ref, operand_ty, first_src);
13536 const last = try sema.resolveSwitchItemVal(block, last_ref, operand_ty, last_src);
13580 if (try Value.fromInterned(first.val).compareAll(.gt, Value.fromInterned(last.val), operand_ty, mod)) {13537 if (try Value.fromInterned(first.val).compareAll(.gt, Value.fromInterned(last.val), operand_ty, mod)) {
13581 const src = switch_prong_src.resolve(mod, mod.declPtr(block.src_decl), src_node_offset, .first);13538 return sema.fail(block, item_src, "range start value is greater than the end value", .{});
13582 return sema.fail(block, src, "range start value is greater than the end value", .{});
13583 }13539 }
13584 const maybe_prev_src = try range_set.add(first.val, last.val, switch_prong_src);13540 const maybe_prev_src = try range_set.add(first.val, last.val, item_src);
13585 try sema.validateSwitchDupe(block, maybe_prev_src, switch_prong_src, src_node_offset);13541 try sema.validateSwitchDupe(block, maybe_prev_src, item_src);
13586 return .{ first.ref, last.ref };13542 return .{ first.ref, last.ref };
13587}13543}
1358813544
...@@ -13592,36 +13548,34 @@ fn validateSwitchItemInt(...@@ -13592,36 +13548,34 @@ fn validateSwitchItemInt(
13592 range_set: *RangeSet,13548 range_set: *RangeSet,
13593 item_ref: Zir.Inst.Ref,13549 item_ref: Zir.Inst.Ref,
13594 operand_ty: Type,13550 operand_ty: Type,
13595 src_node_offset: i32,13551 item_src: LazySrcLoc,
13596 switch_prong_src: Module.SwitchProngSrc,
13597) CompileError!Air.Inst.Ref {13552) CompileError!Air.Inst.Ref {
13598 const item = try sema.resolveSwitchItemVal(block, item_ref, operand_ty, src_node_offset, switch_prong_src, .none);13553 const item = try sema.resolveSwitchItemVal(block, item_ref, operand_ty, item_src);
13599 const maybe_prev_src = try range_set.add(item.val, item.val, switch_prong_src);13554 const maybe_prev_src = try range_set.add(item.val, item.val, item_src);
13600 try sema.validateSwitchDupe(block, maybe_prev_src, switch_prong_src, src_node_offset);13555 try sema.validateSwitchDupe(block, maybe_prev_src, item_src);
13601 return item.ref;13556 return item.ref;
13602}13557}
1360313558
13604fn validateSwitchItemEnum(13559fn validateSwitchItemEnum(
13605 sema: *Sema,13560 sema: *Sema,
13606 block: *Block,13561 block: *Block,
13607 seen_fields: []?Module.SwitchProngSrc,13562 seen_fields: []?LazySrcLoc,
13608 range_set: *RangeSet,13563 range_set: *RangeSet,
13609 item_ref: Zir.Inst.Ref,13564 item_ref: Zir.Inst.Ref,
13610 operand_ty: Type,13565 operand_ty: Type,
13611 src_node_offset: i32,13566 item_src: LazySrcLoc,
13612 switch_prong_src: Module.SwitchProngSrc,
13613) CompileError!Air.Inst.Ref {13567) CompileError!Air.Inst.Ref {
13614 const ip = &sema.mod.intern_pool;13568 const ip = &sema.mod.intern_pool;
13615 const item = try sema.resolveSwitchItemVal(block, item_ref, operand_ty, src_node_offset, switch_prong_src, .none);13569 const item = try sema.resolveSwitchItemVal(block, item_ref, operand_ty, item_src);
13616 const int = ip.indexToKey(item.val).enum_tag.int;13570 const int = ip.indexToKey(item.val).enum_tag.int;
13617 const field_index = ip.loadEnumType(ip.typeOf(item.val)).tagValueIndex(ip, int) orelse {13571 const field_index = ip.loadEnumType(ip.typeOf(item.val)).tagValueIndex(ip, int) orelse {
13618 const maybe_prev_src = try range_set.add(int, int, switch_prong_src);13572 const maybe_prev_src = try range_set.add(int, int, item_src);
13619 try sema.validateSwitchDupe(block, maybe_prev_src, switch_prong_src, src_node_offset);13573 try sema.validateSwitchDupe(block, maybe_prev_src, item_src);
13620 return item.ref;13574 return item.ref;
13621 };13575 };
13622 const maybe_prev_src = seen_fields[field_index];13576 const maybe_prev_src = seen_fields[field_index];
13623 seen_fields[field_index] = switch_prong_src;13577 seen_fields[field_index] = item_src;
13624 try sema.validateSwitchDupe(block, maybe_prev_src, switch_prong_src, src_node_offset);13578 try sema.validateSwitchDupe(block, maybe_prev_src, item_src);
13625 return item.ref;13579 return item.ref;
13626}13580}
1362713581
...@@ -13631,50 +13585,41 @@ fn validateSwitchItemError(...@@ -13631,50 +13585,41 @@ fn validateSwitchItemError(
13631 seen_errors: *SwitchErrorSet,13585 seen_errors: *SwitchErrorSet,
13632 item_ref: Zir.Inst.Ref,13586 item_ref: Zir.Inst.Ref,
13633 operand_ty: Type,13587 operand_ty: Type,
13634 src_node_offset: i32,13588 item_src: LazySrcLoc,
13635 switch_prong_src: Module.SwitchProngSrc,
13636) CompileError!Air.Inst.Ref {13589) CompileError!Air.Inst.Ref {
13637 const ip = &sema.mod.intern_pool;13590 const ip = &sema.mod.intern_pool;
13638 const item = try sema.resolveSwitchItemVal(block, item_ref, operand_ty, src_node_offset, switch_prong_src, .none);13591 const item = try sema.resolveSwitchItemVal(block, item_ref, operand_ty, item_src);
13639 const error_name = ip.indexToKey(item.val).err.name;13592 const error_name = ip.indexToKey(item.val).err.name;
13640 const maybe_prev_src = if (try seen_errors.fetchPut(error_name, switch_prong_src)) |prev|13593 const maybe_prev_src = if (try seen_errors.fetchPut(error_name, item_src)) |prev|
13641 prev.value13594 prev.value
13642 else13595 else
13643 null;13596 null;
13644 try sema.validateSwitchDupe(block, maybe_prev_src, switch_prong_src, src_node_offset);13597 try sema.validateSwitchDupe(block, maybe_prev_src, item_src);
13645 return item.ref;13598 return item.ref;
13646}13599}
1364713600
13648fn validateSwitchDupe(13601fn validateSwitchDupe(
13649 sema: *Sema,13602 sema: *Sema,
13650 block: *Block,13603 block: *Block,
13651 maybe_prev_src: ?Module.SwitchProngSrc,13604 maybe_prev_src: ?LazySrcLoc,
13652 switch_prong_src: Module.SwitchProngSrc,13605 item_src: LazySrcLoc,
13653 src_node_offset: i32,
13654) CompileError!void {13606) CompileError!void {
13655 const prev_prong_src = maybe_prev_src orelse return;13607 const prev_item_src = maybe_prev_src orelse return;
13656 const mod = sema.mod;13608 return sema.failWithOwnedErrorMsg(block, msg: {
13657 const block_src_decl = mod.declPtr(block.src_decl);
13658 const src = switch_prong_src.resolve(mod, block_src_decl, src_node_offset, .none);
13659 const prev_src = prev_prong_src.resolve(mod, block_src_decl, src_node_offset, .none);
13660 const msg = msg: {
13661 const msg = try sema.errMsg(13609 const msg = try sema.errMsg(
13662 block,13610 item_src,
13663 src,
13664 "duplicate switch value",13611 "duplicate switch value",
13665 .{},13612 .{},
13666 );13613 );
13667 errdefer msg.destroy(sema.gpa);13614 errdefer msg.destroy(sema.gpa);
13668 try sema.errNote(13615 try sema.errNote(
13669 block,13616 prev_item_src,
13670 prev_src,
13671 msg,13617 msg,
13672 "previous value here",13618 "previous value here",
13673 .{},13619 .{},
13674 );13620 );
13675 break :msg msg;13621 break :msg msg;
13676 };13622 });
13677 return sema.failWithOwnedErrorMsg(block, msg);
13678}13623}
1367913624
13680fn validateSwitchItemBool(13625fn validateSwitchItemBool(
...@@ -13683,25 +13628,21 @@ fn validateSwitchItemBool(...@@ -13683,25 +13628,21 @@ fn validateSwitchItemBool(
13683 true_count: *u8,13628 true_count: *u8,
13684 false_count: *u8,13629 false_count: *u8,
13685 item_ref: Zir.Inst.Ref,13630 item_ref: Zir.Inst.Ref,
13686 src_node_offset: i32,13631 item_src: LazySrcLoc,
13687 switch_prong_src: Module.SwitchProngSrc,
13688) CompileError!Air.Inst.Ref {13632) CompileError!Air.Inst.Ref {
13689 const mod = sema.mod;13633 const item = try sema.resolveSwitchItemVal(block, item_ref, Type.bool, item_src);
13690 const item = try sema.resolveSwitchItemVal(block, item_ref, Type.bool, src_node_offset, switch_prong_src, .none);
13691 if (Value.fromInterned(item.val).toBool()) {13634 if (Value.fromInterned(item.val).toBool()) {
13692 true_count.* += 1;13635 true_count.* += 1;
13693 } else {13636 } else {
13694 false_count.* += 1;13637 false_count.* += 1;
13695 }13638 }
13696 if (true_count.* > 1 or false_count.* > 1) {13639 if (true_count.* > 1 or false_count.* > 1) {
13697 const block_src_decl = sema.mod.declPtr(block.src_decl);13640 return sema.fail(block, item_src, "duplicate switch value", .{});
13698 const src = switch_prong_src.resolve(mod, block_src_decl, src_node_offset, .none);
13699 return sema.fail(block, src, "duplicate switch value", .{});
13700 }13641 }
13701 return item.ref;13642 return item.ref;
13702}13643}
1370313644
13704const ValueSrcMap = std.AutoHashMapUnmanaged(InternPool.Index, Module.SwitchProngSrc);13645const ValueSrcMap = std.AutoHashMapUnmanaged(InternPool.Index, LazySrcLoc);
1370513646
13706fn validateSwitchItemSparse(13647fn validateSwitchItemSparse(
13707 sema: *Sema,13648 sema: *Sema,
...@@ -13709,12 +13650,11 @@ fn validateSwitchItemSparse(...@@ -13709,12 +13650,11 @@ fn validateSwitchItemSparse(
13709 seen_values: *ValueSrcMap,13650 seen_values: *ValueSrcMap,
13710 item_ref: Zir.Inst.Ref,13651 item_ref: Zir.Inst.Ref,
13711 operand_ty: Type,13652 operand_ty: Type,
13712 src_node_offset: i32,13653 item_src: LazySrcLoc,
13713 switch_prong_src: Module.SwitchProngSrc,
13714) CompileError!Air.Inst.Ref {13654) CompileError!Air.Inst.Ref {
13715 const item = try sema.resolveSwitchItemVal(block, item_ref, operand_ty, src_node_offset, switch_prong_src, .none);13655 const item = try sema.resolveSwitchItemVal(block, item_ref, operand_ty, item_src);
13716 const kv = (try seen_values.fetchPut(sema.gpa, item.val, switch_prong_src)) orelse return item.ref;13656 const kv = try seen_values.fetchPut(sema.gpa, item.val, item_src) orelse return item.ref;
13717 try sema.validateSwitchDupe(block, kv.value, switch_prong_src, src_node_offset);13657 try sema.validateSwitchDupe(block, kv.value, item_src);
13718 unreachable;13658 unreachable;
13719}13659}
1372013660
...@@ -13728,19 +13668,17 @@ fn validateSwitchNoRange(...@@ -13728,19 +13668,17 @@ fn validateSwitchNoRange(
13728 if (ranges_len == 0)13668 if (ranges_len == 0)
13729 return;13669 return;
1373013670
13731 const operand_src: LazySrcLoc = .{ .node_offset_switch_operand = src_node_offset };13671 const operand_src = block.src(.{ .node_offset_switch_operand = src_node_offset });
13732 const range_src: LazySrcLoc = .{ .node_offset_switch_range = src_node_offset };13672 const range_src = block.src(.{ .node_offset_switch_range = src_node_offset });
1373313673
13734 const msg = msg: {13674 const msg = msg: {
13735 const msg = try sema.errMsg(13675 const msg = try sema.errMsg(
13736 block,
13737 operand_src,13676 operand_src,
13738 "ranges not allowed when switching on type '{}'",13677 "ranges not allowed when switching on type '{}'",
13739 .{operand_ty.fmt(sema.mod)},13678 .{operand_ty.fmt(sema.mod)},
13740 );13679 );
13741 errdefer msg.destroy(sema.gpa);13680 errdefer msg.destroy(sema.gpa);
13742 try sema.errNote(13681 try sema.errNote(
13743 block,
13744 range_src,13682 range_src,
13745 msg,13683 msg,
13746 "range here",13684 "range here",
...@@ -13867,8 +13805,8 @@ fn zirHasField(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -13867,8 +13805,8 @@ fn zirHasField(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
13867 const mod = sema.mod;13805 const mod = sema.mod;
13868 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;13806 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
13869 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;13807 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
13870 const ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };13808 const ty_src = block.builtinCallArgSrc(inst_data.src_node, 0);
13871 const name_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };13809 const name_src = block.builtinCallArgSrc(inst_data.src_node, 1);
13872 const ty = try sema.resolveType(block, ty_src, extra.lhs);13810 const ty = try sema.resolveType(block, ty_src, extra.lhs);
13873 const field_name = try sema.resolveConstStringIntern(block, name_src, extra.rhs, .{13811 const field_name = try sema.resolveConstStringIntern(block, name_src, extra.rhs, .{
13874 .needed_comptime_reason = "field name must be comptime-known",13812 .needed_comptime_reason = "field name must be comptime-known",
...@@ -13919,8 +13857,8 @@ fn zirHasDecl(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air...@@ -13919,8 +13857,8 @@ fn zirHasDecl(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
13919 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;13857 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
13920 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;13858 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
13921 const src = block.nodeOffset(inst_data.src_node);13859 const src = block.nodeOffset(inst_data.src_node);
13922 const lhs_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };13860 const lhs_src = block.builtinCallArgSrc(inst_data.src_node, 0);
13923 const rhs_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };13861 const rhs_src = block.builtinCallArgSrc(inst_data.src_node, 1);
13924 const container_type = try sema.resolveType(block, lhs_src, extra.lhs);13862 const container_type = try sema.resolveType(block, lhs_src, extra.lhs);
13925 const decl_name = try sema.resolveConstStringIntern(block, rhs_src, extra.rhs, .{13863 const decl_name = try sema.resolveConstStringIntern(block, rhs_src, extra.rhs, .{
13926 .needed_comptime_reason = "decl name must be comptime-known",13864 .needed_comptime_reason = "decl name must be comptime-known",
...@@ -13979,7 +13917,7 @@ fn zirEmbedFile(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A...@@ -13979,7 +13917,7 @@ fn zirEmbedFile(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
1397913917
13980 const mod = sema.mod;13918 const mod = sema.mod;
13981 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;13919 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
13982 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };13920 const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0);
13983 const name = try sema.resolveConstString(block, operand_src, inst_data.operand, .{13921 const name = try sema.resolveConstString(block, operand_src, inst_data.operand, .{
13984 .needed_comptime_reason = "file path name must be comptime-known",13922 .needed_comptime_reason = "file path name must be comptime-known",
13985 });13923 });
...@@ -13988,8 +13926,7 @@ fn zirEmbedFile(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A...@@ -13988,8 +13926,7 @@ fn zirEmbedFile(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
13988 return sema.fail(block, operand_src, "file path name cannot be empty", .{});13926 return sema.fail(block, operand_src, "file path name cannot be empty", .{});
13989 }13927 }
1399013928
13991 const src_loc = mod.declPtr(block.src_decl).toSrcLoc(operand_src, mod);13929 const val = mod.embedFile(block.getFileScope(mod), name, operand_src.upgrade(mod)) catch |err| switch (err) {
13992 const val = mod.embedFile(block.getFileScope(mod), name, src_loc) catch |err| switch (err) {
13993 error.ImportOutsideModulePath => {13930 error.ImportOutsideModulePath => {
13994 return sema.fail(block, operand_src, "embed of file outside package path: '{s}'", .{name});13931 return sema.fail(block, operand_src, "embed of file outside package path: '{s}'", .{name});
13995 },13932 },
...@@ -14031,8 +13968,8 @@ fn zirShl(...@@ -14031,8 +13968,8 @@ fn zirShl(
14031 const mod = sema.mod;13968 const mod = sema.mod;
14032 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;13969 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
14033 const src = block.nodeOffset(inst_data.src_node);13970 const src = block.nodeOffset(inst_data.src_node);
14034 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };13971 const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node });
14035 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };13972 const rhs_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node });
14036 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;13973 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
14037 const lhs = try sema.resolveInst(extra.lhs);13974 const lhs = try sema.resolveInst(extra.lhs);
14038 const rhs = try sema.resolveInst(extra.rhs);13975 const rhs = try sema.resolveInst(extra.rhs);
...@@ -14201,8 +14138,8 @@ fn zirShr(...@@ -14201,8 +14138,8 @@ fn zirShr(
14201 const mod = sema.mod;14138 const mod = sema.mod;
14202 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;14139 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
14203 const src = block.nodeOffset(inst_data.src_node);14140 const src = block.nodeOffset(inst_data.src_node);
14204 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };14141 const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node });
14205 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };14142 const rhs_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node });
14206 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;14143 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
14207 const lhs = try sema.resolveInst(extra.lhs);14144 const lhs = try sema.resolveInst(extra.lhs);
14208 const rhs = try sema.resolveInst(extra.rhs);14145 const rhs = try sema.resolveInst(extra.rhs);
...@@ -14335,9 +14272,9 @@ fn zirBitwise(...@@ -14335,9 +14272,9 @@ fn zirBitwise(
1433514272
14336 const mod = sema.mod;14273 const mod = sema.mod;
14337 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;14274 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
14338 const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node };14275 const src = block.src(.{ .node_offset_bin_op = inst_data.src_node });
14339 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };14276 const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node });
14340 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };14277 const rhs_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node });
14341 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;14278 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
14342 const lhs = try sema.resolveInst(extra.lhs);14279 const lhs = try sema.resolveInst(extra.lhs);
14343 const rhs = try sema.resolveInst(extra.rhs);14280 const rhs = try sema.resolveInst(extra.rhs);
...@@ -14390,7 +14327,7 @@ fn zirBitNot(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air....@@ -14390,7 +14327,7 @@ fn zirBitNot(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
14390 const mod = sema.mod;14327 const mod = sema.mod;
14391 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;14328 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
14392 const src = block.nodeOffset(inst_data.src_node);14329 const src = block.nodeOffset(inst_data.src_node);
14393 const operand_src: LazySrcLoc = .{ .node_offset_un_op = inst_data.src_node };14330 const operand_src = block.src(.{ .node_offset_un_op = inst_data.src_node });
1439414331
14395 const operand = try sema.resolveInst(inst_data.operand);14332 const operand = try sema.resolveInst(inst_data.operand);
14396 const operand_type = sema.typeOf(operand);14333 const operand_type = sema.typeOf(operand);
...@@ -14436,7 +14373,7 @@ fn analyzeTupleCat(...@@ -14436,7 +14373,7 @@ fn analyzeTupleCat(
14436 const mod = sema.mod;14373 const mod = sema.mod;
14437 const lhs_ty = sema.typeOf(lhs);14374 const lhs_ty = sema.typeOf(lhs);
14438 const rhs_ty = sema.typeOf(rhs);14375 const rhs_ty = sema.typeOf(rhs);
14439 const src = LazySrcLoc.nodeOffset(src_node);14376 const src = block.nodeOffset(src_node);
1444014377
14441 const lhs_len = lhs_ty.structFieldCount(mod);14378 const lhs_len = lhs_ty.structFieldCount(mod);
14442 const rhs_len = rhs_ty.structFieldCount(mod);14379 const rhs_len = rhs_ty.structFieldCount(mod);
...@@ -14463,10 +14400,10 @@ fn analyzeTupleCat(...@@ -14463,10 +14400,10 @@ fn analyzeTupleCat(
14463 types[i] = lhs_ty.structFieldType(i, mod).toIntern();14400 types[i] = lhs_ty.structFieldType(i, mod).toIntern();
14464 const default_val = lhs_ty.structFieldDefaultValue(i, mod);14401 const default_val = lhs_ty.structFieldDefaultValue(i, mod);
14465 values[i] = default_val.toIntern();14402 values[i] = default_val.toIntern();
14466 const operand_src: LazySrcLoc = .{ .array_cat_lhs = .{14403 const operand_src = block.src(.{ .array_cat_lhs = .{
14467 .array_cat_offset = src_node,14404 .array_cat_offset = src_node,
14468 .elem_index = i,14405 .elem_index = i,
14469 } };14406 } });
14470 if (default_val.toIntern() == .unreachable_value) {14407 if (default_val.toIntern() == .unreachable_value) {
14471 runtime_src = operand_src;14408 runtime_src = operand_src;
14472 values[i] = .none;14409 values[i] = .none;
...@@ -14477,10 +14414,10 @@ fn analyzeTupleCat(...@@ -14477,10 +14414,10 @@ fn analyzeTupleCat(
14477 types[i + lhs_len] = rhs_ty.structFieldType(i, mod).toIntern();14414 types[i + lhs_len] = rhs_ty.structFieldType(i, mod).toIntern();
14478 const default_val = rhs_ty.structFieldDefaultValue(i, mod);14415 const default_val = rhs_ty.structFieldDefaultValue(i, mod);
14479 values[i + lhs_len] = default_val.toIntern();14416 values[i + lhs_len] = default_val.toIntern();
14480 const operand_src: LazySrcLoc = .{ .array_cat_rhs = .{14417 const operand_src = block.src(.{ .array_cat_rhs = .{
14481 .array_cat_offset = src_node,14418 .array_cat_offset = src_node,
14482 .elem_index = i,14419 .elem_index = i,
14483 } };14420 } });
14484 if (default_val.toIntern() == .unreachable_value) {14421 if (default_val.toIntern() == .unreachable_value) {
14485 runtime_src = operand_src;14422 runtime_src = operand_src;
14486 values[i + lhs_len] = .none;14423 values[i + lhs_len] = .none;
...@@ -14508,18 +14445,18 @@ fn analyzeTupleCat(...@@ -14508,18 +14445,18 @@ fn analyzeTupleCat(
14508 const element_refs = try sema.arena.alloc(Air.Inst.Ref, final_len);14445 const element_refs = try sema.arena.alloc(Air.Inst.Ref, final_len);
14509 var i: u32 = 0;14446 var i: u32 = 0;
14510 while (i < lhs_len) : (i += 1) {14447 while (i < lhs_len) : (i += 1) {
14511 const operand_src: LazySrcLoc = .{ .array_cat_lhs = .{14448 const operand_src = block.src(.{ .array_cat_lhs = .{
14512 .array_cat_offset = src_node,14449 .array_cat_offset = src_node,
14513 .elem_index = i,14450 .elem_index = i,
14514 } };14451 } });
14515 element_refs[i] = try sema.tupleFieldValByIndex(block, operand_src, lhs, i, lhs_ty);14452 element_refs[i] = try sema.tupleFieldValByIndex(block, operand_src, lhs, i, lhs_ty);
14516 }14453 }
14517 i = 0;14454 i = 0;
14518 while (i < rhs_len) : (i += 1) {14455 while (i < rhs_len) : (i += 1) {
14519 const operand_src: LazySrcLoc = .{ .array_cat_rhs = .{14456 const operand_src = block.src(.{ .array_cat_rhs = .{
14520 .array_cat_offset = src_node,14457 .array_cat_offset = src_node,
14521 .elem_index = i,14458 .elem_index = i,
14522 } };14459 } });
14523 element_refs[i + lhs_len] =14460 element_refs[i + lhs_len] =
14524 try sema.tupleFieldValByIndex(block, operand_src, rhs, i, rhs_ty);14461 try sema.tupleFieldValByIndex(block, operand_src, rhs, i, rhs_ty);
14525 }14462 }
...@@ -14546,8 +14483,8 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -14546,8 +14483,8 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
14546 return sema.analyzeTupleCat(block, inst_data.src_node, lhs, rhs);14483 return sema.analyzeTupleCat(block, inst_data.src_node, lhs, rhs);
14547 }14484 }
1454814485
14549 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };14486 const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node });
14550 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };14487 const rhs_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node });
1455114488
14552 const lhs_info = try sema.getArrayCatInfo(block, lhs_src, lhs, rhs_ty) orelse lhs_info: {14489 const lhs_info = try sema.getArrayCatInfo(block, lhs_src, lhs, rhs_ty) orelse lhs_info: {
14553 if (lhs_is_tuple) break :lhs_info @as(Type.ArrayInfo, undefined);14490 if (lhs_is_tuple) break :lhs_info @as(Type.ArrayInfo, undefined);
...@@ -14659,10 +14596,10 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -14659,10 +14596,10 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
14659 const elem_default_val = if (lhs_is_tuple) lhs_ty.structFieldDefaultValue(lhs_elem_i, mod) else Value.@"unreachable";14596 const elem_default_val = if (lhs_is_tuple) lhs_ty.structFieldDefaultValue(lhs_elem_i, mod) else Value.@"unreachable";
14660 const elem_val = if (elem_default_val.toIntern() == .unreachable_value) try lhs_sub_val.elemValue(mod, lhs_elem_i) else elem_default_val;14597 const elem_val = if (elem_default_val.toIntern() == .unreachable_value) try lhs_sub_val.elemValue(mod, lhs_elem_i) else elem_default_val;
14661 const elem_val_inst = Air.internedToRef(elem_val.toIntern());14598 const elem_val_inst = Air.internedToRef(elem_val.toIntern());
14662 const operand_src: LazySrcLoc = .{ .array_cat_lhs = .{14599 const operand_src = block.src(.{ .array_cat_lhs = .{
14663 .array_cat_offset = inst_data.src_node,14600 .array_cat_offset = inst_data.src_node,
14664 .elem_index = elem_i,14601 .elem_index = elem_i,
14665 } };14602 } });
14666 const coerced_elem_val_inst = try sema.coerce(block, resolved_elem_ty, elem_val_inst, operand_src);14603 const coerced_elem_val_inst = try sema.coerce(block, resolved_elem_ty, elem_val_inst, operand_src);
14667 const coerced_elem_val = try sema.resolveConstValue(block, operand_src, coerced_elem_val_inst, undefined);14604 const coerced_elem_val = try sema.resolveConstValue(block, operand_src, coerced_elem_val_inst, undefined);
14668 element_vals[elem_i] = coerced_elem_val.toIntern();14605 element_vals[elem_i] = coerced_elem_val.toIntern();
...@@ -14672,10 +14609,10 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -14672,10 +14609,10 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
14672 const elem_default_val = if (rhs_is_tuple) rhs_ty.structFieldDefaultValue(rhs_elem_i, mod) else Value.@"unreachable";14609 const elem_default_val = if (rhs_is_tuple) rhs_ty.structFieldDefaultValue(rhs_elem_i, mod) else Value.@"unreachable";
14673 const elem_val = if (elem_default_val.toIntern() == .unreachable_value) try rhs_sub_val.elemValue(mod, rhs_elem_i) else elem_default_val;14610 const elem_val = if (elem_default_val.toIntern() == .unreachable_value) try rhs_sub_val.elemValue(mod, rhs_elem_i) else elem_default_val;
14674 const elem_val_inst = Air.internedToRef(elem_val.toIntern());14611 const elem_val_inst = Air.internedToRef(elem_val.toIntern());
14675 const operand_src: LazySrcLoc = .{ .array_cat_rhs = .{14612 const operand_src = block.src(.{ .array_cat_rhs = .{
14676 .array_cat_offset = inst_data.src_node,14613 .array_cat_offset = inst_data.src_node,
14677 .elem_index = @intCast(rhs_elem_i),14614 .elem_index = @intCast(rhs_elem_i),
14678 } };14615 } });
14679 const coerced_elem_val_inst = try sema.coerce(block, resolved_elem_ty, elem_val_inst, operand_src);14616 const coerced_elem_val_inst = try sema.coerce(block, resolved_elem_ty, elem_val_inst, operand_src);
14680 const coerced_elem_val = try sema.resolveConstValue(block, operand_src, coerced_elem_val_inst, undefined);14617 const coerced_elem_val = try sema.resolveConstValue(block, operand_src, coerced_elem_val_inst, undefined);
14681 element_vals[elem_i] = coerced_elem_val.toIntern();14618 element_vals[elem_i] = coerced_elem_val.toIntern();
...@@ -14704,10 +14641,10 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -14704,10 +14641,10 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
14704 while (elem_i < lhs_len) : (elem_i += 1) {14641 while (elem_i < lhs_len) : (elem_i += 1) {
14705 const elem_index = try mod.intRef(Type.usize, elem_i);14642 const elem_index = try mod.intRef(Type.usize, elem_i);
14706 const elem_ptr = try block.addPtrElemPtr(alloc, elem_index, elem_ptr_ty);14643 const elem_ptr = try block.addPtrElemPtr(alloc, elem_index, elem_ptr_ty);
14707 const operand_src: LazySrcLoc = .{ .array_cat_lhs = .{14644 const operand_src = block.src(.{ .array_cat_lhs = .{
14708 .array_cat_offset = inst_data.src_node,14645 .array_cat_offset = inst_data.src_node,
14709 .elem_index = elem_i,14646 .elem_index = elem_i,
14710 } };14647 } });
14711 const init = try sema.elemVal(block, operand_src, lhs, elem_index, src, true);14648 const init = try sema.elemVal(block, operand_src, lhs, elem_index, src, true);
14712 try sema.storePtr2(block, src, elem_ptr, src, init, operand_src, .store);14649 try sema.storePtr2(block, src, elem_ptr, src, init, operand_src, .store);
14713 }14650 }
...@@ -14716,10 +14653,10 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -14716,10 +14653,10 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
14716 const elem_index = try mod.intRef(Type.usize, elem_i);14653 const elem_index = try mod.intRef(Type.usize, elem_i);
14717 const rhs_index = try mod.intRef(Type.usize, rhs_elem_i);14654 const rhs_index = try mod.intRef(Type.usize, rhs_elem_i);
14718 const elem_ptr = try block.addPtrElemPtr(alloc, elem_index, elem_ptr_ty);14655 const elem_ptr = try block.addPtrElemPtr(alloc, elem_index, elem_ptr_ty);
14719 const operand_src: LazySrcLoc = .{ .array_cat_rhs = .{14656 const operand_src = block.src(.{ .array_cat_rhs = .{
14720 .array_cat_offset = inst_data.src_node,14657 .array_cat_offset = inst_data.src_node,
14721 .elem_index = @intCast(rhs_elem_i),14658 .elem_index = @intCast(rhs_elem_i),
14722 } };14659 } });
14723 const init = try sema.elemVal(block, operand_src, rhs, rhs_index, src, true);14660 const init = try sema.elemVal(block, operand_src, rhs, rhs_index, src, true);
14724 try sema.storePtr2(block, src, elem_ptr, src, init, operand_src, .store);14661 try sema.storePtr2(block, src, elem_ptr, src, init, operand_src, .store);
14725 }14662 }
...@@ -14738,20 +14675,20 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -14738,20 +14675,20 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
14738 var elem_i: u32 = 0;14675 var elem_i: u32 = 0;
14739 while (elem_i < lhs_len) : (elem_i += 1) {14676 while (elem_i < lhs_len) : (elem_i += 1) {
14740 const index = try mod.intRef(Type.usize, elem_i);14677 const index = try mod.intRef(Type.usize, elem_i);
14741 const operand_src: LazySrcLoc = .{ .array_cat_lhs = .{14678 const operand_src = block.src(.{ .array_cat_lhs = .{
14742 .array_cat_offset = inst_data.src_node,14679 .array_cat_offset = inst_data.src_node,
14743 .elem_index = elem_i,14680 .elem_index = elem_i,
14744 } };14681 } });
14745 const init = try sema.elemVal(block, operand_src, lhs, index, src, true);14682 const init = try sema.elemVal(block, operand_src, lhs, index, src, true);
14746 element_refs[elem_i] = try sema.coerce(block, resolved_elem_ty, init, operand_src);14683 element_refs[elem_i] = try sema.coerce(block, resolved_elem_ty, init, operand_src);
14747 }14684 }
14748 while (elem_i < result_len) : (elem_i += 1) {14685 while (elem_i < result_len) : (elem_i += 1) {
14749 const rhs_elem_i = elem_i - lhs_len;14686 const rhs_elem_i = elem_i - lhs_len;
14750 const index = try mod.intRef(Type.usize, rhs_elem_i);14687 const index = try mod.intRef(Type.usize, rhs_elem_i);
14751 const operand_src: LazySrcLoc = .{ .array_cat_rhs = .{14688 const operand_src = block.src(.{ .array_cat_rhs = .{
14752 .array_cat_offset = inst_data.src_node,14689 .array_cat_offset = inst_data.src_node,
14753 .elem_index = @intCast(rhs_elem_i),14690 .elem_index = @intCast(rhs_elem_i),
14754 } };14691 } });
14755 const init = try sema.elemVal(block, operand_src, rhs, index, src, true);14692 const init = try sema.elemVal(block, operand_src, rhs, index, src, true);
14756 element_refs[elem_i] = try sema.coerce(block, resolved_elem_ty, init, operand_src);14693 element_refs[elem_i] = try sema.coerce(block, resolved_elem_ty, init, operand_src);
14757 }14694 }
...@@ -14813,8 +14750,8 @@ fn analyzeTupleMul(...@@ -14813,8 +14750,8 @@ fn analyzeTupleMul(
14813) CompileError!Air.Inst.Ref {14750) CompileError!Air.Inst.Ref {
14814 const mod = sema.mod;14751 const mod = sema.mod;
14815 const operand_ty = sema.typeOf(operand);14752 const operand_ty = sema.typeOf(operand);
14816 const src = LazySrcLoc.nodeOffset(src_node);14753 const src = block.nodeOffset(src_node);
14817 const len_src: LazySrcLoc = .{ .node_offset_bin_rhs = src_node };14754 const len_src = block.src(.{ .node_offset_bin_rhs = src_node });
1481814755
14819 const tuple_len = operand_ty.structFieldCount(mod);14756 const tuple_len = operand_ty.structFieldCount(mod);
14820 const final_len = std.math.mul(usize, tuple_len, factor) catch14757 const final_len = std.math.mul(usize, tuple_len, factor) catch
...@@ -14831,10 +14768,10 @@ fn analyzeTupleMul(...@@ -14831,10 +14768,10 @@ fn analyzeTupleMul(
14831 for (0..tuple_len) |i| {14768 for (0..tuple_len) |i| {
14832 types[i] = operand_ty.structFieldType(i, mod).toIntern();14769 types[i] = operand_ty.structFieldType(i, mod).toIntern();
14833 values[i] = operand_ty.structFieldDefaultValue(i, mod).toIntern();14770 values[i] = operand_ty.structFieldDefaultValue(i, mod).toIntern();
14834 const operand_src: LazySrcLoc = .{ .array_cat_lhs = .{14771 const operand_src = block.src(.{ .array_cat_lhs = .{
14835 .array_cat_offset = src_node,14772 .array_cat_offset = src_node,
14836 .elem_index = @intCast(i),14773 .elem_index = @intCast(i),
14837 } };14774 } });
14838 if (values[i] == .unreachable_value) {14775 if (values[i] == .unreachable_value) {
14839 runtime_src = operand_src;14776 runtime_src = operand_src;
14840 values[i] = .none; // TODO don't treat unreachable_value as special14777 values[i] = .none; // TODO don't treat unreachable_value as special
...@@ -14866,10 +14803,10 @@ fn analyzeTupleMul(...@@ -14866,10 +14803,10 @@ fn analyzeTupleMul(
14866 const element_refs = try sema.arena.alloc(Air.Inst.Ref, final_len);14803 const element_refs = try sema.arena.alloc(Air.Inst.Ref, final_len);
14867 var i: u32 = 0;14804 var i: u32 = 0;
14868 while (i < tuple_len) : (i += 1) {14805 while (i < tuple_len) : (i += 1) {
14869 const operand_src: LazySrcLoc = .{ .array_cat_lhs = .{14806 const operand_src = block.src(.{ .array_cat_lhs = .{
14870 .array_cat_offset = src_node,14807 .array_cat_offset = src_node,
14871 .elem_index = i,14808 .elem_index = i,
14872 } };14809 } });
14873 element_refs[i] = try sema.tupleFieldValByIndex(block, operand_src, operand, @intCast(i), operand_ty);14810 element_refs[i] = try sema.tupleFieldValByIndex(block, operand_src, operand, @intCast(i), operand_ty);
14874 }14811 }
14875 i = 1;14812 i = 1;
...@@ -14890,9 +14827,9 @@ fn zirArrayMul(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -14890,9 +14827,9 @@ fn zirArrayMul(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
14890 const uncoerced_lhs = try sema.resolveInst(extra.lhs);14827 const uncoerced_lhs = try sema.resolveInst(extra.lhs);
14891 const uncoerced_lhs_ty = sema.typeOf(uncoerced_lhs);14828 const uncoerced_lhs_ty = sema.typeOf(uncoerced_lhs);
14892 const src: LazySrcLoc = block.nodeOffset(inst_data.src_node);14829 const src: LazySrcLoc = block.nodeOffset(inst_data.src_node);
14893 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };14830 const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node });
14894 const operator_src: LazySrcLoc = .{ .node_offset_main_token = inst_data.src_node };14831 const operator_src = block.src(.{ .node_offset_main_token = inst_data.src_node });
14895 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };14832 const rhs_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node });
1489614833
14897 const lhs, const lhs_ty = coerced_lhs: {14834 const lhs, const lhs_ty = coerced_lhs: {
14898 // If we have a result type, we might be able to do this more efficiently14835 // If we have a result type, we might be able to do this more efficiently
...@@ -14941,11 +14878,11 @@ fn zirArrayMul(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -14941,11 +14878,11 @@ fn zirArrayMul(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
14941 // Analyze the lhs first, to catch the case that someone tried to do exponentiation14878 // Analyze the lhs first, to catch the case that someone tried to do exponentiation
14942 const lhs_info = try sema.getArrayCatInfo(block, lhs_src, lhs, lhs_ty) orelse {14879 const lhs_info = try sema.getArrayCatInfo(block, lhs_src, lhs, lhs_ty) orelse {
14943 const msg = msg: {14880 const msg = msg: {
14944 const msg = try sema.errMsg(block, lhs_src, "expected indexable; found '{}'", .{lhs_ty.fmt(mod)});14881 const msg = try sema.errMsg(lhs_src, "expected indexable; found '{}'", .{lhs_ty.fmt(mod)});
14945 errdefer msg.destroy(sema.gpa);14882 errdefer msg.destroy(sema.gpa);
14946 switch (lhs_ty.zigTypeTag(mod)) {14883 switch (lhs_ty.zigTypeTag(mod)) {
14947 .Int, .Float, .ComptimeFloat, .ComptimeInt, .Vector => {14884 .Int, .Float, .ComptimeFloat, .ComptimeInt, .Vector => {
14948 try sema.errNote(block, operator_src, msg, "this operator multiplies arrays; use std.math.pow for exponentiation", .{});14885 try sema.errNote(operator_src, msg, "this operator multiplies arrays; use std.math.pow for exponentiation", .{});
14949 },14886 },
14950 else => {},14887 else => {},
14951 }14888 }
...@@ -15061,7 +14998,7 @@ fn zirNegate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air....@@ -15061,7 +14998,7 @@ fn zirNegate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
15061 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;14998 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
15062 const src = block.nodeOffset(inst_data.src_node);14999 const src = block.nodeOffset(inst_data.src_node);
15063 const lhs_src = src;15000 const lhs_src = src;
15064 const rhs_src: LazySrcLoc = .{ .node_offset_un_op = inst_data.src_node };15001 const rhs_src = block.src(.{ .node_offset_un_op = inst_data.src_node });
1506515002
15066 const rhs = try sema.resolveInst(inst_data.operand);15003 const rhs = try sema.resolveInst(inst_data.operand);
15067 const rhs_ty = sema.typeOf(rhs);15004 const rhs_ty = sema.typeOf(rhs);
...@@ -15093,7 +15030,7 @@ fn zirNegateWrap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!...@@ -15093,7 +15030,7 @@ fn zirNegateWrap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
15093 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;15030 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
15094 const src = block.nodeOffset(inst_data.src_node);15031 const src = block.nodeOffset(inst_data.src_node);
15095 const lhs_src = src;15032 const lhs_src = src;
15096 const rhs_src: LazySrcLoc = .{ .node_offset_un_op = inst_data.src_node };15033 const rhs_src = block.src(.{ .node_offset_un_op = inst_data.src_node });
1509715034
15098 const rhs = try sema.resolveInst(inst_data.operand);15035 const rhs = try sema.resolveInst(inst_data.operand);
15099 const rhs_ty = sema.typeOf(rhs);15036 const rhs_ty = sema.typeOf(rhs);
...@@ -15119,9 +15056,9 @@ fn zirArithmetic(...@@ -15119,9 +15056,9 @@ fn zirArithmetic(
15119 defer tracy.end();15056 defer tracy.end();
1512015057
15121 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;15058 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
15122 const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node };15059 const src = block.src(.{ .node_offset_bin_op = inst_data.src_node });
15123 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };15060 const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node });
15124 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };15061 const rhs_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node });
15125 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;15062 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
15126 const lhs = try sema.resolveInst(extra.lhs);15063 const lhs = try sema.resolveInst(extra.lhs);
15127 const rhs = try sema.resolveInst(extra.rhs);15064 const rhs = try sema.resolveInst(extra.rhs);
...@@ -15132,9 +15069,9 @@ fn zirArithmetic(...@@ -15132,9 +15069,9 @@ fn zirArithmetic(
15132fn zirDiv(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {15069fn zirDiv(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
15133 const mod = sema.mod;15070 const mod = sema.mod;
15134 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;15071 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
15135 const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node };15072 const src = block.src(.{ .node_offset_bin_op = inst_data.src_node });
15136 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };15073 const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node });
15137 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };15074 const rhs_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node });
15138 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;15075 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
15139 const lhs = try sema.resolveInst(extra.lhs);15076 const lhs = try sema.resolveInst(extra.lhs);
15140 const rhs = try sema.resolveInst(extra.rhs);15077 const rhs = try sema.resolveInst(extra.rhs);
...@@ -15297,9 +15234,9 @@ fn zirDiv(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins...@@ -15297,9 +15234,9 @@ fn zirDiv(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins
15297fn zirDivExact(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {15234fn zirDivExact(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
15298 const mod = sema.mod;15235 const mod = sema.mod;
15299 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;15236 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
15300 const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node };15237 const src = block.src(.{ .node_offset_bin_op = inst_data.src_node });
15301 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };15238 const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node });
15302 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };15239 const rhs_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node });
15303 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;15240 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
15304 const lhs = try sema.resolveInst(extra.lhs);15241 const lhs = try sema.resolveInst(extra.lhs);
15305 const rhs = try sema.resolveInst(extra.rhs);15242 const rhs = try sema.resolveInst(extra.rhs);
...@@ -15462,9 +15399,9 @@ fn zirDivExact(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -15462,9 +15399,9 @@ fn zirDivExact(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
15462fn zirDivFloor(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {15399fn zirDivFloor(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
15463 const mod = sema.mod;15400 const mod = sema.mod;
15464 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;15401 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
15465 const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node };15402 const src = block.src(.{ .node_offset_bin_op = inst_data.src_node });
15466 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };15403 const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node });
15467 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };15404 const rhs_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node });
15468 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;15405 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
15469 const lhs = try sema.resolveInst(extra.lhs);15406 const lhs = try sema.resolveInst(extra.lhs);
15470 const rhs = try sema.resolveInst(extra.rhs);15407 const rhs = try sema.resolveInst(extra.rhs);
...@@ -15572,9 +15509,9 @@ fn zirDivFloor(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -15572,9 +15509,9 @@ fn zirDivFloor(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
15572fn zirDivTrunc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {15509fn zirDivTrunc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
15573 const mod = sema.mod;15510 const mod = sema.mod;
15574 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;15511 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
15575 const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node };15512 const src = block.src(.{ .node_offset_bin_op = inst_data.src_node });
15576 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };15513 const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node });
15577 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };15514 const rhs_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node });
15578 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;15515 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
15579 const lhs = try sema.resolveInst(extra.lhs);15516 const lhs = try sema.resolveInst(extra.lhs);
15580 const rhs = try sema.resolveInst(extra.rhs);15517 const rhs = try sema.resolveInst(extra.rhs);
...@@ -15813,9 +15750,9 @@ fn airTag(block: *Block, is_int: bool, normal: Air.Inst.Tag, optimized: Air.Inst...@@ -15813,9 +15750,9 @@ fn airTag(block: *Block, is_int: bool, normal: Air.Inst.Tag, optimized: Air.Inst
15813fn zirModRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {15750fn zirModRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
15814 const mod = sema.mod;15751 const mod = sema.mod;
15815 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;15752 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
15816 const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node };15753 const src = block.src(.{ .node_offset_bin_op = inst_data.src_node });
15817 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };15754 const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node });
15818 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };15755 const rhs_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node });
15819 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;15756 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
15820 const lhs = try sema.resolveInst(extra.lhs);15757 const lhs = try sema.resolveInst(extra.lhs);
15821 const rhs = try sema.resolveInst(extra.rhs);15758 const rhs = try sema.resolveInst(extra.rhs);
...@@ -15997,9 +15934,9 @@ fn intRemScalar(sema: *Sema, lhs: Value, rhs: Value, scalar_ty: Type) CompileErr...@@ -15997,9 +15934,9 @@ fn intRemScalar(sema: *Sema, lhs: Value, rhs: Value, scalar_ty: Type) CompileErr
15997fn zirMod(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {15934fn zirMod(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
15998 const mod = sema.mod;15935 const mod = sema.mod;
15999 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;15936 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
16000 const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node };15937 const src = block.src(.{ .node_offset_bin_op = inst_data.src_node });
16001 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };15938 const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node });
16002 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };15939 const rhs_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node });
16003 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;15940 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
16004 const lhs = try sema.resolveInst(extra.lhs);15941 const lhs = try sema.resolveInst(extra.lhs);
16005 const rhs = try sema.resolveInst(extra.rhs);15942 const rhs = try sema.resolveInst(extra.rhs);
...@@ -16092,9 +16029,9 @@ fn zirMod(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins...@@ -16092,9 +16029,9 @@ fn zirMod(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins
16092fn zirRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {16029fn zirRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
16093 const mod = sema.mod;16030 const mod = sema.mod;
16094 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;16031 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
16095 const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node };16032 const src = block.src(.{ .node_offset_bin_op = inst_data.src_node });
16096 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };16033 const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node });
16097 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };16034 const rhs_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node });
16098 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;16035 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
16099 const lhs = try sema.resolveInst(extra.lhs);16036 const lhs = try sema.resolveInst(extra.lhs);
16100 const rhs = try sema.resolveInst(extra.rhs);16037 const rhs = try sema.resolveInst(extra.rhs);
...@@ -16194,10 +16131,10 @@ fn zirOverflowArithmetic(...@@ -16194,10 +16131,10 @@ fn zirOverflowArithmetic(
16194 defer tracy.end();16131 defer tracy.end();
1619516132
16196 const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data;16133 const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data;
16197 const src = LazySrcLoc.nodeOffset(extra.node);16134 const src = block.nodeOffset(extra.node);
1619816135
16199 const lhs_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node };16136 const lhs_src = block.builtinCallArgSrc(extra.node, 0);
16200 const rhs_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = extra.node };16137 const rhs_src = block.builtinCallArgSrc(extra.node, 1);
1620116138
16202 const uncasted_lhs = try sema.resolveInst(extra.lhs);16139 const uncasted_lhs = try sema.resolveInst(extra.lhs);
16203 const uncasted_rhs = try sema.resolveInst(extra.rhs);16140 const uncasted_rhs = try sema.resolveInst(extra.rhs);
...@@ -17025,8 +16962,8 @@ fn zirAsm(...@@ -17025,8 +16962,8 @@ fn zirAsm(
17025 defer tracy.end();16962 defer tracy.end();
1702616963
17027 const extra = sema.code.extraData(Zir.Inst.Asm, extended.operand);16964 const extra = sema.code.extraData(Zir.Inst.Asm, extended.operand);
17028 const src = LazySrcLoc.nodeOffset(extra.data.src_node);16965 const src = block.nodeOffset(extra.data.src_node);
17029 const ret_ty_src: LazySrcLoc = .{ .node_offset_asm_ret_ty = extra.data.src_node };16966 const ret_ty_src = block.src(.{ .node_offset_asm_ret_ty = extra.data.src_node });
17030 const outputs_len: u5 = @truncate(extended.small);16967 const outputs_len: u5 = @truncate(extended.small);
17031 const inputs_len: u5 = @truncate(extended.small >> 5);16968 const inputs_len: u5 = @truncate(extended.small >> 5);
17032 const clobbers_len: u5 = @truncate(extended.small >> 10);16969 const clobbers_len: u5 = @truncate(extended.small >> 10);
...@@ -17200,8 +17137,8 @@ fn zirCmpEq(...@@ -17200,8 +17137,8 @@ fn zirCmpEq(
17200 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;17137 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
17201 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;17138 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
17202 const src: LazySrcLoc = block.nodeOffset(inst_data.src_node);17139 const src: LazySrcLoc = block.nodeOffset(inst_data.src_node);
17203 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };17140 const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node });
17204 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };17141 const rhs_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node });
17205 const lhs = try sema.resolveInst(extra.lhs);17142 const lhs = try sema.resolveInst(extra.lhs);
17206 const rhs = try sema.resolveInst(extra.rhs);17143 const rhs = try sema.resolveInst(extra.rhs);
1720717144
...@@ -17280,9 +17217,9 @@ fn analyzeCmpUnionTag(...@@ -17280,9 +17217,9 @@ fn analyzeCmpUnionTag(
17280 try sema.resolveTypeFields(union_ty);17217 try sema.resolveTypeFields(union_ty);
17281 const union_tag_ty = union_ty.unionTagType(mod) orelse {17218 const union_tag_ty = union_ty.unionTagType(mod) orelse {
17282 const msg = msg: {17219 const msg = msg: {
17283 const msg = try sema.errMsg(block, un_src, "comparison of union and enum literal is only valid for tagged union types", .{});17220 const msg = try sema.errMsg(un_src, "comparison of union and enum literal is only valid for tagged union types", .{});
17284 errdefer msg.destroy(sema.gpa);17221 errdefer msg.destroy(sema.gpa);
17285 try mod.errNoteNonLazy(union_ty.declSrcLoc(mod), msg, "union '{}' is not a tagged union", .{union_ty.fmt(mod)});17222 try sema.errNote(union_ty.srcLoc(mod), msg, "union '{}' is not a tagged union", .{union_ty.fmt(mod)});
17286 break :msg msg;17223 break :msg msg;
17287 };17224 };
17288 return sema.failWithOwnedErrorMsg(block, msg);17225 return sema.failWithOwnedErrorMsg(block, msg);
...@@ -17316,8 +17253,8 @@ fn zirCmp(...@@ -17316,8 +17253,8 @@ fn zirCmp(
17316 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;17253 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
17317 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;17254 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
17318 const src: LazySrcLoc = block.nodeOffset(inst_data.src_node);17255 const src: LazySrcLoc = block.nodeOffset(inst_data.src_node);
17319 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };17256 const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node });
17320 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };17257 const rhs_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node });
17321 const lhs = try sema.resolveInst(extra.lhs);17258 const lhs = try sema.resolveInst(extra.lhs);
17322 const rhs = try sema.resolveInst(extra.rhs);17259 const rhs = try sema.resolveInst(extra.rhs);
17323 return sema.analyzeCmp(block, src, lhs, rhs, op, lhs_src, rhs_src, false);17260 return sema.analyzeCmp(block, src, lhs, rhs, op, lhs_src, rhs_src, false);
...@@ -17459,7 +17396,7 @@ fn runtimeBoolCmp(...@@ -17459,7 +17396,7 @@ fn runtimeBoolCmp(
17459fn zirSizeOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {17396fn zirSizeOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
17460 const mod = sema.mod;17397 const mod = sema.mod;
17461 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;17398 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
17462 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };17399 const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0);
17463 const ty = try sema.resolveType(block, operand_src, inst_data.operand);17400 const ty = try sema.resolveType(block, operand_src, inst_data.operand);
17464 switch (ty.zigTypeTag(mod)) {17401 switch (ty.zigTypeTag(mod)) {
17465 .Fn,17402 .Fn,
...@@ -17502,7 +17439,7 @@ fn zirSizeOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air....@@ -17502,7 +17439,7 @@ fn zirSizeOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
17502fn zirBitSizeOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {17439fn zirBitSizeOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
17503 const mod = sema.mod;17440 const mod = sema.mod;
17504 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;17441 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
17505 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };17442 const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0);
17506 const operand_ty = try sema.resolveType(block, operand_src, inst_data.operand);17443 const operand_ty = try sema.resolveType(block, operand_src, inst_data.operand);
17507 switch (operand_ty.zigTypeTag(mod)) {17444 switch (operand_ty.zigTypeTag(mod)) {
17508 .Fn,17445 .Fn,
...@@ -17546,7 +17483,7 @@ fn zirThis(...@@ -17546,7 +17483,7 @@ fn zirThis(
17546) CompileError!Air.Inst.Ref {17483) CompileError!Air.Inst.Ref {
17547 const mod = sema.mod;17484 const mod = sema.mod;
17548 const this_decl_index = mod.namespacePtr(block.namespace).decl_index;17485 const this_decl_index = mod.namespacePtr(block.namespace).decl_index;
17549 const src = LazySrcLoc.nodeOffset(@bitCast(extended.operand));17486 const src = block.nodeOffset(@bitCast(extended.operand));
17550 return sema.analyzeDeclVal(block, src, this_decl_index);17487 return sema.analyzeDeclVal(block, src, this_decl_index);
17551}17488}
1755217489
...@@ -17556,7 +17493,7 @@ fn zirClosureGet(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat...@@ -17556,7 +17493,7 @@ fn zirClosureGet(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat
17556 const captures = mod.namespacePtr(block.namespace).getType(mod).getCaptures(mod);17493 const captures = mod.namespacePtr(block.namespace).getType(mod).getCaptures(mod);
1755717494
17558 const src_node: i32 = @bitCast(extended.operand);17495 const src_node: i32 = @bitCast(extended.operand);
17559 const src = LazySrcLoc.nodeOffset(src_node);17496 const src = block.nodeOffset(src_node);
1756017497
17561 const capture_ty = switch (captures.get(ip)[extended.small].unwrap()) {17498 const capture_ty = switch (captures.get(ip)[extended.small].unwrap()) {
17562 .@"comptime" => |index| return Air.internedToRef(index),17499 .@"comptime" => |index| return Air.internedToRef(index),
...@@ -17570,7 +17507,8 @@ fn zirClosureGet(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat...@@ -17570,7 +17507,8 @@ fn zirClosureGet(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat
17570 if (!block.is_typeof and sema.func_index == .none) {17507 if (!block.is_typeof and sema.func_index == .none) {
17571 const msg = msg: {17508 const msg = msg: {
17572 const name = name: {17509 const name = name: {
17573 const file = sema.owner_decl.getFileScope(mod);17510 // TODO: we should probably store this name in the ZIR to avoid this complexity.
17511 const file, const src_base_node = Module.LazySrcLoc.resolveBaseNode(block.src_base_inst, mod);
17574 const tree = file.getTree(sema.gpa) catch |err| {17512 const tree = file.getTree(sema.gpa) catch |err| {
17575 // In this case we emit a warning + a less precise source location.17513 // In this case we emit a warning + a less precise source location.
17576 log.warn("unable to load {s}: {s}", .{17514 log.warn("unable to load {s}: {s}", .{
...@@ -17578,15 +17516,15 @@ fn zirClosureGet(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat...@@ -17578,15 +17516,15 @@ fn zirClosureGet(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat
17578 });17516 });
17579 break :name null;17517 break :name null;
17580 };17518 };
17581 const node = sema.owner_decl.relativeToNodeIndex(src_node);17519 const node: std.zig.Ast.Node.Index = @bitCast(src_node + @as(i32, @bitCast(src_base_node)));
17582 const token = tree.nodes.items(.main_token)[node];17520 const token = tree.nodes.items(.main_token)[node];
17583 break :name tree.tokenSlice(token);17521 break :name tree.tokenSlice(token);
17584 };17522 };
1758517523
17586 const msg = if (name) |some|17524 const msg = if (name) |some|
17587 try sema.errMsg(block, src, "'{s}' not accessible outside function scope", .{some})17525 try sema.errMsg(src, "'{s}' not accessible outside function scope", .{some})
17588 else17526 else
17589 try sema.errMsg(block, src, "variable not accessible outside function scope", .{});17527 try sema.errMsg(src, "variable not accessible outside function scope", .{});
17590 errdefer msg.destroy(sema.gpa);17528 errdefer msg.destroy(sema.gpa);
1759117529
17592 // TODO add "declared here" note17530 // TODO add "declared here" note
...@@ -17598,7 +17536,7 @@ fn zirClosureGet(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat...@@ -17598,7 +17536,7 @@ fn zirClosureGet(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat
17598 if (!block.is_typeof and !block.is_comptime and sema.func_index != .none) {17536 if (!block.is_typeof and !block.is_comptime and sema.func_index != .none) {
17599 const msg = msg: {17537 const msg = msg: {
17600 const name = name: {17538 const name = name: {
17601 const file = sema.owner_decl.getFileScope(mod);17539 const file, const src_base_node = Module.LazySrcLoc.resolveBaseNode(block.src_base_inst, mod);
17602 const tree = file.getTree(sema.gpa) catch |err| {17540 const tree = file.getTree(sema.gpa) catch |err| {
17603 // In this case we emit a warning + a less precise source location.17541 // In this case we emit a warning + a less precise source location.
17604 log.warn("unable to load {s}: {s}", .{17542 log.warn("unable to load {s}: {s}", .{
...@@ -17606,18 +17544,18 @@ fn zirClosureGet(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat...@@ -17606,18 +17544,18 @@ fn zirClosureGet(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat
17606 });17544 });
17607 break :name null;17545 break :name null;
17608 };17546 };
17609 const node = sema.owner_decl.relativeToNodeIndex(src_node);17547 const node: std.zig.Ast.Node.Index = @bitCast(src_node + @as(i32, @bitCast(src_base_node)));
17610 const token = tree.nodes.items(.main_token)[node];17548 const token = tree.nodes.items(.main_token)[node];
17611 break :name tree.tokenSlice(token);17549 break :name tree.tokenSlice(token);
17612 };17550 };
1761317551
17614 const msg = if (name) |some|17552 const msg = if (name) |some|
17615 try sema.errMsg(block, src, "'{s}' not accessible from inner function", .{some})17553 try sema.errMsg(src, "'{s}' not accessible from inner function", .{some})
17616 else17554 else
17617 try sema.errMsg(block, src, "variable not accessible from inner function", .{});17555 try sema.errMsg(src, "variable not accessible from inner function", .{});
17618 errdefer msg.destroy(sema.gpa);17556 errdefer msg.destroy(sema.gpa);
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
17622 // TODO add "declared here" note17560 // TODO add "declared here" note
17623 break :msg msg;17561 break :msg msg;
...@@ -17649,7 +17587,7 @@ fn zirFrameAddress(...@@ -17649,7 +17587,7 @@ fn zirFrameAddress(
17649 block: *Block,17587 block: *Block,
17650 extended: Zir.Inst.Extended.InstData,17588 extended: Zir.Inst.Extended.InstData,
17651) CompileError!Air.Inst.Ref {17589) CompileError!Air.Inst.Ref {
17652 const src = LazySrcLoc.nodeOffset(@bitCast(extended.operand));17590 const src = block.nodeOffset(@bitCast(extended.operand));
17653 try sema.requireRuntimeBlock(block, src, null);17591 try sema.requireRuntimeBlock(block, src, null);
17654 return try block.addNoOp(.frame_addr);17592 return try block.addNoOp(.frame_addr);
17655}17593}
...@@ -18913,6 +18851,7 @@ fn zirTypeofBuiltin(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr...@@ -18913,6 +18851,7 @@ fn zirTypeofBuiltin(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr
18913 .is_typeof = true,18851 .is_typeof = true,
18914 .want_safety = false,18852 .want_safety = false,
18915 .error_return_trace_index = block.error_return_trace_index,18853 .error_return_trace_index = block.error_return_trace_index,
18854 .src_base_inst = block.src_base_inst,
18916 };18855 };
18917 defer child_block.instructions.deinit(sema.gpa);18856 defer child_block.instructions.deinit(sema.gpa);
1891818857
...@@ -18977,7 +18916,7 @@ fn zirTypeofPeer(...@@ -18977,7 +18916,7 @@ fn zirTypeofPeer(
18977 defer tracy.end();18916 defer tracy.end();
1897818917
18979 const extra = sema.code.extraData(Zir.Inst.TypeOfPeer, extended.operand);18918 const extra = sema.code.extraData(Zir.Inst.TypeOfPeer, extended.operand);
18980 const src = LazySrcLoc.nodeOffset(extra.data.src_node);18919 const src = block.nodeOffset(extra.data.src_node);
18981 const body = sema.code.bodySlice(extra.data.body_index, extra.data.body_len);18920 const body = sema.code.bodySlice(extra.data.body_index, extra.data.body_len);
1898218921
18983 var child_block: Block = .{18922 var child_block: Block = .{
...@@ -18992,6 +18931,7 @@ fn zirTypeofPeer(...@@ -18992,6 +18931,7 @@ fn zirTypeofPeer(
18992 .runtime_cond = block.runtime_cond,18931 .runtime_cond = block.runtime_cond,
18993 .runtime_loop = block.runtime_loop,18932 .runtime_loop = block.runtime_loop,
18994 .runtime_index = block.runtime_index,18933 .runtime_index = block.runtime_index,
18934 .src_base_inst = block.src_base_inst,
18995 };18935 };
18996 defer child_block.instructions.deinit(sema.gpa);18936 defer child_block.instructions.deinit(sema.gpa);
18997 // Ignore the result, we only care about the instructions in `args`.18937 // Ignore the result, we only care about the instructions in `args`.
...@@ -19017,7 +18957,7 @@ fn zirBoolNot(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air...@@ -19017,7 +18957,7 @@ fn zirBoolNot(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
19017 const mod = sema.mod;18957 const mod = sema.mod;
19018 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;18958 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
19019 const src = block.nodeOffset(inst_data.src_node);18959 const src = block.nodeOffset(inst_data.src_node);
19020 const operand_src: LazySrcLoc = .{ .node_offset_un_op = inst_data.src_node };18960 const operand_src = block.src(.{ .node_offset_un_op = inst_data.src_node });
19021 const uncasted_operand = try sema.resolveInst(inst_data.operand);18961 const uncasted_operand = try sema.resolveInst(inst_data.operand);
1902218962
19023 const operand = try sema.coerce(block, Type.bool, uncasted_operand, operand_src);18963 const operand = try sema.coerce(block, Type.bool, uncasted_operand, operand_src);
...@@ -19048,8 +18988,8 @@ fn zirBoolBr(...@@ -19048,8 +18988,8 @@ fn zirBoolBr(
1904818988
19049 const uncoerced_lhs = try sema.resolveInst(extra.data.lhs);18989 const uncoerced_lhs = try sema.resolveInst(extra.data.lhs);
19050 const body = sema.code.bodySlice(extra.end, extra.data.body_len);18990 const body = sema.code.bodySlice(extra.end, extra.data.body_len);
19051 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };18991 const lhs_src = parent_block.src(.{ .node_offset_bin_lhs = inst_data.src_node });
19052 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };18992 const rhs_src = parent_block.src(.{ .node_offset_bin_rhs = inst_data.src_node });
1905318993
19054 const lhs = try sema.coerce(parent_block, Type.bool, uncoerced_lhs, lhs_src);18994 const lhs = try sema.coerce(parent_block, Type.bool, uncoerced_lhs, lhs_src);
1905518995
...@@ -19080,7 +19020,7 @@ fn zirBoolBr(...@@ -19080,7 +19020,7 @@ fn zirBoolBr(
1908019020
19081 var child_block = parent_block.makeSubBlock();19021 var child_block = parent_block.makeSubBlock();
19082 child_block.runtime_loop = null;19022 child_block.runtime_loop = null;
19083 child_block.runtime_cond = mod.declPtr(child_block.src_decl).toSrcLoc(lhs_src, mod);19023 child_block.runtime_cond = lhs_src;
19084 child_block.runtime_index.increment();19024 child_block.runtime_index.increment();
19085 defer child_block.instructions.deinit(gpa);19025 defer child_block.instructions.deinit(gpa);
1908619026
...@@ -19253,7 +19193,7 @@ fn zirCondbr(...@@ -19253,7 +19193,7 @@ fn zirCondbr(
1925319193
19254 const mod = sema.mod;19194 const mod = sema.mod;
19255 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;19195 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
19256 const cond_src: LazySrcLoc = .{ .node_offset_if_cond = inst_data.src_node };19196 const cond_src = parent_block.src(.{ .node_offset_if_cond = inst_data.src_node });
19257 const extra = sema.code.extraData(Zir.Inst.CondBr, inst_data.payload_index);19197 const extra = sema.code.extraData(Zir.Inst.CondBr, inst_data.payload_index);
1925819198
19259 const then_body = sema.code.bodySlice(extra.end, extra.data.then_body_len);19199 const then_body = sema.code.bodySlice(extra.end, extra.data.then_body_len);
...@@ -19276,7 +19216,7 @@ fn zirCondbr(...@@ -19276,7 +19216,7 @@ fn zirCondbr(
19276 // instructions array in between using it for the then block and else block.19216 // instructions array in between using it for the then block and else block.
19277 var sub_block = parent_block.makeSubBlock();19217 var sub_block = parent_block.makeSubBlock();
19278 sub_block.runtime_loop = null;19218 sub_block.runtime_loop = null;
19279 sub_block.runtime_cond = mod.declPtr(parent_block.src_decl).toSrcLoc(cond_src, mod);19219 sub_block.runtime_cond = cond_src;
19280 sub_block.runtime_index.increment();19220 sub_block.runtime_index.increment();
19281 sub_block.need_debug_scope = null; // this body is emitted regardless19221 sub_block.need_debug_scope = null; // this body is emitted regardless
19282 defer sub_block.instructions.deinit(gpa);19222 defer sub_block.instructions.deinit(gpa);
...@@ -19321,7 +19261,7 @@ fn zirCondbr(...@@ -19321,7 +19261,7 @@ fn zirCondbr(
19321fn zirTry(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {19261fn zirTry(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
19322 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;19262 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
19323 const src = parent_block.nodeOffset(inst_data.src_node);19263 const src = parent_block.nodeOffset(inst_data.src_node);
19324 const operand_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };19264 const operand_src = parent_block.src(.{ .node_offset_bin_lhs = inst_data.src_node });
19325 const extra = sema.code.extraData(Zir.Inst.Try, inst_data.payload_index);19265 const extra = sema.code.extraData(Zir.Inst.Try, inst_data.payload_index);
19326 const body = sema.code.bodySlice(extra.end, extra.data.body_len);19266 const body = sema.code.bodySlice(extra.end, extra.data.body_len);
19327 const err_union = try sema.resolveInst(extra.data.operand);19267 const err_union = try sema.resolveInst(extra.data.operand);
...@@ -19368,7 +19308,7 @@ fn zirTry(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError!...@@ -19368,7 +19308,7 @@ fn zirTry(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError!
19368fn zirTryPtr(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {19308fn zirTryPtr(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
19369 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;19309 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
19370 const src = parent_block.nodeOffset(inst_data.src_node);19310 const src = parent_block.nodeOffset(inst_data.src_node);
19371 const operand_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };19311 const operand_src = parent_block.src(.{ .node_offset_bin_lhs = inst_data.src_node });
19372 const extra = sema.code.extraData(Zir.Inst.Try, inst_data.payload_index);19312 const extra = sema.code.extraData(Zir.Inst.Try, inst_data.payload_index);
19373 const body = sema.code.bodySlice(extra.end, extra.data.body_len);19313 const body = sema.code.bodySlice(extra.end, extra.data.body_len);
19374 const operand = try sema.resolveInst(extra.data.operand);19314 const operand = try sema.resolveInst(extra.data.operand);
...@@ -19464,6 +19404,7 @@ fn ensurePostHoc(sema: *Sema, block: *Block, dest_block: Zir.Inst.Index) !*Label...@@ -19464,6 +19404,7 @@ fn ensurePostHoc(sema: *Sema, block: *Block, dest_block: Zir.Inst.Index) !*Label
19464 .label = &labeled_block.label,19404 .label = &labeled_block.label,
19465 .inlining = block.inlining,19405 .inlining = block.inlining,
19466 .is_comptime = block.is_comptime,19406 .is_comptime = block.is_comptime,
19407 .src_base_inst = block.src_base_inst,
19467 },19408 },
19468 };19409 };
19469 sema.post_hoc_blocks.putAssumeCapacityNoClobber(new_block_inst, labeled_block);19410 sema.post_hoc_blocks.putAssumeCapacityNoClobber(new_block_inst, labeled_block);
...@@ -19498,11 +19439,11 @@ fn zirUnreachable(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError...@@ -19498,11 +19439,11 @@ fn zirUnreachable(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
19498 return sema.fail(block, src, "reached unreachable code", .{});19439 return sema.fail(block, src, "reached unreachable code", .{});
19499 }19440 }
19500 // TODO Add compile error for @optimizeFor occurring too late in a scope.19441 // TODO Add compile error for @optimizeFor occurring too late in a scope.
19501 block.addUnreachable(src, true) catch |err| switch (err) {19442 sema.analyzeUnreachable(block, src, true) catch |err| switch (err) {
19502 error.AnalysisFail => {19443 error.AnalysisFail => {
19503 const msg = sema.err orelse return err;19444 const msg = sema.err orelse return err;
19504 if (!mem.eql(u8, msg.msg, "runtime safety check not allowed in naked function")) return err;19445 if (!mem.eql(u8, msg.msg, "runtime safety check not allowed in naked function")) return err;
19505 try sema.errNote(block, src, msg, "the end of a naked function is implicitly unreachable", .{});19446 try sema.errNote(src, msg, "the end of a naked function is implicitly unreachable", .{});
19506 return err;19447 return err;
19507 },19448 },
19508 else => |e| return e,19449 else => |e| return e,
...@@ -19549,31 +19490,31 @@ fn zirRetImplicit(...@@ -19549,31 +19490,31 @@ fn zirRetImplicit(
19549 // Calling a safety function from a naked function would not be legal.19490 // Calling a safety function from a naked function would not be legal.
19550 _ = try block.addNoOp(.trap);19491 _ = try block.addNoOp(.trap);
19551 } else {19492 } else {
19552 try block.addUnreachable(r_brace_src, false);19493 try sema.analyzeUnreachable(block, r_brace_src, false);
19553 }19494 }
19554 return;19495 return;
19555 }19496 }
1955619497
19557 const operand = try sema.resolveInst(inst_data.operand);19498 const operand = try sema.resolveInst(inst_data.operand);
19558 const ret_ty_src: LazySrcLoc = .{ .node_offset_fn_type_ret_ty = 0 };19499 const ret_ty_src = block.src(.{ .node_offset_fn_type_ret_ty = 0 });
19559 const base_tag = sema.fn_ret_ty.baseZigTypeTag(mod);19500 const base_tag = sema.fn_ret_ty.baseZigTypeTag(mod);
19560 if (base_tag == .NoReturn) {19501 if (base_tag == .NoReturn) {
19561 const msg = msg: {19502 const msg = msg: {
19562 const msg = try sema.errMsg(block, ret_ty_src, "function declared '{}' implicitly returns", .{19503 const msg = try sema.errMsg(ret_ty_src, "function declared '{}' implicitly returns", .{
19563 sema.fn_ret_ty.fmt(mod),19504 sema.fn_ret_ty.fmt(mod),
19564 });19505 });
19565 errdefer msg.destroy(sema.gpa);19506 errdefer msg.destroy(sema.gpa);
19566 try sema.errNote(block, r_brace_src, msg, "control flow reaches end of body here", .{});19507 try sema.errNote(r_brace_src, msg, "control flow reaches end of body here", .{});
19567 break :msg msg;19508 break :msg msg;
19568 };19509 };
19569 return sema.failWithOwnedErrorMsg(block, msg);19510 return sema.failWithOwnedErrorMsg(block, msg);
19570 } else if (base_tag != .Void) {19511 } else if (base_tag != .Void) {
19571 const msg = msg: {19512 const msg = msg: {
19572 const msg = try sema.errMsg(block, ret_ty_src, "function with non-void return type '{}' implicitly returns", .{19513 const msg = try sema.errMsg(ret_ty_src, "function with non-void return type '{}' implicitly returns", .{
19573 sema.fn_ret_ty.fmt(mod),19514 sema.fn_ret_ty.fmt(mod),
19574 });19515 });
19575 errdefer msg.destroy(sema.gpa);19516 errdefer msg.destroy(sema.gpa);
19576 try sema.errNote(block, r_brace_src, msg, "control flow reaches end of body here", .{});19517 try sema.errNote(r_brace_src, msg, "control flow reaches end of body here", .{});
19577 break :msg msg;19518 break :msg msg;
19578 };19519 };
19579 return sema.failWithOwnedErrorMsg(block, msg);19520 return sema.failWithOwnedErrorMsg(block, msg);
...@@ -19590,7 +19531,7 @@ fn zirRetNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!voi...@@ -19590,7 +19531,7 @@ fn zirRetNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!voi
19590 const operand = try sema.resolveInst(inst_data.operand);19531 const operand = try sema.resolveInst(inst_data.operand);
19591 const src = block.nodeOffset(inst_data.src_node);19532 const src = block.nodeOffset(inst_data.src_node);
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 }));
19594}19535}
1959519536
19596fn zirRetLoad(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void {19537fn zirRetLoad(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void {
...@@ -19603,7 +19544,7 @@ fn zirRetLoad(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!voi...@@ -19603,7 +19544,7 @@ fn zirRetLoad(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!voi
1960319544
19604 if (block.is_comptime or block.inlining != null or sema.func_is_naked) {19545 if (block.is_comptime or block.inlining != null or sema.func_is_naked) {
19605 const operand = try sema.analyzeLoad(block, src, ret_ptr, src);19546 const operand = try sema.analyzeLoad(block, src, ret_ptr, src);
19606 return sema.analyzeRet(block, operand, src, .{ .node_offset_return_operand = inst_data.src_node });19547 return sema.analyzeRet(block, operand, src, block.src(.{ .node_offset_return_operand = inst_data.src_node }));
19607 }19548 }
1960819549
19609 if (sema.wantErrorReturnTracing(sema.fn_ret_ty)) {19550 if (sema.wantErrorReturnTracing(sema.fn_ret_ty)) {
...@@ -19816,9 +19757,7 @@ fn analyzeRet(...@@ -19816,9 +19757,7 @@ fn analyzeRet(
19816 inlining.comptime_result = operand;19757 inlining.comptime_result = operand;
1981719758
19818 if (sema.fn_ret_ty.isError(mod) and ret_val.getErrorName(mod) != .none) {19759 if (sema.fn_ret_ty.isError(mod) and ret_val.getErrorName(mod) != .none) {
19819 const src_decl = mod.declPtr(block.src_decl);19760 try sema.comptime_err_ret_trace.append(src);
19820 const src_loc = src_decl.toSrcLoc(src, mod);
19821 try sema.comptime_err_ret_trace.append(src_loc);
19822 }19761 }
19823 return error.ComptimeReturn;19762 return error.ComptimeReturn;
19824 }19763 }
...@@ -19832,10 +19771,10 @@ fn analyzeRet(...@@ -19832,10 +19771,10 @@ fn analyzeRet(
19832 return sema.fail(block, src, "function called at runtime cannot return value at comptime", .{});19771 return sema.fail(block, src, "function called at runtime cannot return value at comptime", .{});
19833 } else if (sema.func_is_naked) {19772 } else if (sema.func_is_naked) {
19834 const msg = msg: {19773 const msg = msg: {
19835 const msg = try sema.errMsg(block, src, "cannot return from naked function", .{});19774 const msg = try sema.errMsg(src, "cannot return from naked function", .{});
19836 errdefer msg.destroy(sema.gpa);19775 errdefer msg.destroy(sema.gpa);
1983719776
19838 try sema.errNote(block, src, msg, "can only return using assembly", .{});19777 try sema.errNote(src, msg, "can only return using assembly", .{});
19839 break :msg msg;19778 break :msg msg;
19840 };19779 };
19841 return sema.failWithOwnedErrorMsg(block, msg);19780 return sema.failWithOwnedErrorMsg(block, msg);
...@@ -19871,18 +19810,18 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air...@@ -19871,18 +19810,18 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
19871 const mod = sema.mod;19810 const mod = sema.mod;
19872 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].ptr_type;19811 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].ptr_type;
19873 const extra = sema.code.extraData(Zir.Inst.PtrType, inst_data.payload_index);19812 const extra = sema.code.extraData(Zir.Inst.PtrType, inst_data.payload_index);
19874 const elem_ty_src: LazySrcLoc = .{ .node_offset_ptr_elem = extra.data.src_node };19813 const elem_ty_src = block.src(.{ .node_offset_ptr_elem = extra.data.src_node });
19875 const sentinel_src: LazySrcLoc = .{ .node_offset_ptr_sentinel = extra.data.src_node };19814 const sentinel_src = block.src(.{ .node_offset_ptr_sentinel = extra.data.src_node });
19876 const align_src: LazySrcLoc = .{ .node_offset_ptr_align = extra.data.src_node };19815 const align_src = block.src(.{ .node_offset_ptr_align = extra.data.src_node });
19877 const addrspace_src: LazySrcLoc = .{ .node_offset_ptr_addrspace = extra.data.src_node };19816 const addrspace_src = block.src(.{ .node_offset_ptr_addrspace = extra.data.src_node });
19878 const bitoffset_src: LazySrcLoc = .{ .node_offset_ptr_bitoffset = extra.data.src_node };19817 const bitoffset_src = block.src(.{ .node_offset_ptr_bitoffset = extra.data.src_node });
19879 const hostsize_src: LazySrcLoc = .{ .node_offset_ptr_hostsize = extra.data.src_node };19818 const hostsize_src = block.src(.{ .node_offset_ptr_hostsize = extra.data.src_node });
1988019819
19881 const elem_ty = blk: {19820 const elem_ty = blk: {
19882 const air_inst = try sema.resolveInst(extra.data.elem_type);19821 const air_inst = try sema.resolveInst(extra.data.elem_type);
19883 const ty = sema.analyzeAsType(block, elem_ty_src, air_inst) catch |err| {19822 const ty = sema.analyzeAsType(block, elem_ty_src, air_inst) catch |err| {
19884 if (err == error.AnalysisFail and sema.err != null and sema.typeOf(air_inst).isSinglePointer(mod)) {19823 if (err == error.AnalysisFail and sema.err != null and sema.typeOf(air_inst).isSinglePointer(mod)) {
19885 try sema.errNote(block, elem_ty_src, sema.err.?, "use '.*' to dereference pointer", .{});19824 try sema.errNote(elem_ty_src, sema.err.?, "use '.*' to dereference pointer", .{});
19886 }19825 }
19887 return err;19826 return err;
19888 };19827 };
...@@ -19974,11 +19913,10 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air...@@ -19974,11 +19913,10 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
19974 } else if (inst_data.size == .C) {19913 } else if (inst_data.size == .C) {
19975 if (!try sema.validateExternType(elem_ty, .other)) {19914 if (!try sema.validateExternType(elem_ty, .other)) {
19976 const msg = msg: {19915 const msg = msg: {
19977 const msg = try sema.errMsg(block, elem_ty_src, "C pointers cannot point to non-C-ABI-compatible type '{}'", .{elem_ty.fmt(mod)});19916 const msg = try sema.errMsg(elem_ty_src, "C pointers cannot point to non-C-ABI-compatible type '{}'", .{elem_ty.fmt(mod)});
19978 errdefer msg.destroy(sema.gpa);19917 errdefer msg.destroy(sema.gpa);
1997919918
19980 const src_decl = mod.declPtr(block.src_decl);19919 try sema.explainWhyTypeIsNotExtern(msg, elem_ty_src, elem_ty, .other);
19981 try sema.explainWhyTypeIsNotExtern(msg, src_decl.toSrcLoc(elem_ty_src, mod), elem_ty, .other);
1998219920
19983 try sema.addDeclaredHereNote(msg, elem_ty);19921 try sema.addDeclaredHereNote(msg, elem_ty);
19984 break :msg msg;19922 break :msg msg;
...@@ -19992,10 +19930,9 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air...@@ -19992,10 +19930,9 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1999219930
19993 if (host_size != 0 and !try sema.validatePackedType(elem_ty)) {19931 if (host_size != 0 and !try sema.validatePackedType(elem_ty)) {
19994 return sema.failWithOwnedErrorMsg(block, msg: {19932 return sema.failWithOwnedErrorMsg(block, msg: {
19995 const msg = try sema.errMsg(block, elem_ty_src, "bit-pointer cannot refer to value of type '{}'", .{elem_ty.fmt(mod)});19933 const msg = try sema.errMsg(elem_ty_src, "bit-pointer cannot refer to value of type '{}'", .{elem_ty.fmt(mod)});
19996 errdefer msg.destroy(sema.gpa);19934 errdefer msg.destroy(sema.gpa);
19997 const src_decl = mod.declPtr(block.src_decl);19935 try sema.explainWhyTypeIsNotPacked(msg, elem_ty_src, elem_ty);
19998 try sema.explainWhyTypeIsNotPacked(msg, src_decl.toSrcLoc(elem_ty_src, mod), elem_ty);
19999 break :msg msg;19936 break :msg msg;
20000 });19937 });
20001 }19938 }
...@@ -20025,7 +19962,7 @@ fn zirStructInitEmpty(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE...@@ -20025,7 +19962,7 @@ fn zirStructInitEmpty(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE
2002519962
20026 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;19963 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
20027 const src = block.nodeOffset(inst_data.src_node);19964 const src = block.nodeOffset(inst_data.src_node);
20028 const ty_src: LazySrcLoc = .{ .node_offset_init_ty = inst_data.src_node };19965 const ty_src = block.src(.{ .node_offset_init_ty = inst_data.src_node });
20029 const obj_ty = try sema.resolveType(block, ty_src, inst_data.operand);19966 const obj_ty = try sema.resolveType(block, ty_src, inst_data.operand);
20030 const mod = sema.mod;19967 const mod = sema.mod;
2003119968
...@@ -20119,9 +20056,9 @@ fn arrayInitEmpty(sema: *Sema, block: *Block, src: LazySrcLoc, obj_ty: Type) Com...@@ -20119,9 +20056,9 @@ fn arrayInitEmpty(sema: *Sema, block: *Block, src: LazySrcLoc, obj_ty: Type) Com
2011920056
20120fn zirUnionInit(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {20057fn zirUnionInit(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
20121 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;20058 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
20122 const ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };20059 const ty_src = block.builtinCallArgSrc(inst_data.src_node, 0);
20123 const field_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };20060 const field_src = block.builtinCallArgSrc(inst_data.src_node, 1);
20124 const init_src: LazySrcLoc = .{ .node_offset_builtin_call_arg2 = inst_data.src_node };20061 const init_src = block.builtinCallArgSrc(inst_data.src_node, 2);
20125 const extra = sema.code.extraData(Zir.Inst.UnionInit, inst_data.payload_index).data;20062 const extra = sema.code.extraData(Zir.Inst.UnionInit, inst_data.payload_index).data;
20126 const union_ty = try sema.resolveType(block, ty_src, extra.union_type);20063 const union_ty = try sema.resolveType(block, ty_src, extra.union_type);
20127 if (union_ty.zigTypeTag(sema.mod) != .Union) {20064 if (union_ty.zigTypeTag(sema.mod) != .Union) {
...@@ -20215,7 +20152,7 @@ fn zirStructInit(...@@ -20215,7 +20152,7 @@ fn zirStructInit(
20215 extra_index = item.end;20152 extra_index = item.end;
2021620153
20217 const field_type_data = zir_datas[@intFromEnum(item.data.field_type)].pl_node;20154 const field_type_data = zir_datas[@intFromEnum(item.data.field_type)].pl_node;
20218 const field_src: LazySrcLoc = .{ .node_offset_initializer = field_type_data.src_node };20155 const field_src = block.src(.{ .node_offset_initializer = field_type_data.src_node });
20219 const field_type_extra = sema.code.extraData(Zir.Inst.FieldType, field_type_data.payload_index).data;20156 const field_type_extra = sema.code.extraData(Zir.Inst.FieldType, field_type_data.payload_index).data;
20220 const field_name = try ip.getOrPutString(20157 const field_name = try ip.getOrPutString(
20221 gpa,20158 gpa,
...@@ -20256,7 +20193,7 @@ fn zirStructInit(...@@ -20256,7 +20193,7 @@ fn zirStructInit(
20256 const item = sema.code.extraData(Zir.Inst.StructInit.Item, extra.end);20193 const item = sema.code.extraData(Zir.Inst.StructInit.Item, extra.end);
2025720194
20258 const field_type_data = zir_datas[@intFromEnum(item.data.field_type)].pl_node;20195 const field_type_data = zir_datas[@intFromEnum(item.data.field_type)].pl_node;
20259 const field_src: LazySrcLoc = .{ .node_offset_initializer = field_type_data.src_node };20196 const field_src = block.src(.{ .node_offset_initializer = field_type_data.src_node });
20260 const field_type_extra = sema.code.extraData(Zir.Inst.FieldType, field_type_data.payload_index).data;20197 const field_type_extra = sema.code.extraData(Zir.Inst.FieldType, field_type_data.payload_index).data;
20261 const field_name = try ip.getOrPutString(20198 const field_name = try ip.getOrPutString(
20262 gpa,20199 gpa,
...@@ -20270,7 +20207,7 @@ fn zirStructInit(...@@ -20270,7 +20207,7 @@ fn zirStructInit(
2027020207
20271 if (field_ty.zigTypeTag(mod) == .NoReturn) {20208 if (field_ty.zigTypeTag(mod) == .NoReturn) {
20272 return sema.failWithOwnedErrorMsg(block, msg: {20209 return sema.failWithOwnedErrorMsg(block, msg: {
20273 const msg = try sema.errMsg(block, src, "cannot initialize 'noreturn' field of union", .{});20210 const msg = try sema.errMsg(src, "cannot initialize 'noreturn' field of union", .{});
20274 errdefer msg.destroy(sema.gpa);20211 errdefer msg.destroy(sema.gpa);
2027520212
20276 try sema.addFieldErrNote(resolved_ty, field_index, msg, "field '{}' declared here", .{20213 try sema.addFieldErrNote(resolved_ty, field_index, msg, "field '{}' declared here", .{
...@@ -20348,16 +20285,12 @@ fn finishStructInit(...@@ -20348,16 +20285,12 @@ fn finishStructInit(
20348 for (0..anon_struct.types.len) |i| {20285 for (0..anon_struct.types.len) |i| {
20349 if (field_inits[i] != .none) {20286 if (field_inits[i] != .none) {
20350 // Coerce the init value to the field type.20287 // Coerce the init value to the field type.
20288 const field_src = block.src(.{ .init_elem = .{
20289 .init_node_offset = init_src.offset.node_offset.x,
20290 .elem_index = @intCast(i),
20291 } });
20351 const field_ty = Type.fromInterned(anon_struct.types.get(ip)[i]);20292 const field_ty = Type.fromInterned(anon_struct.types.get(ip)[i]);
20352 field_inits[i] = sema.coerce(block, field_ty, field_inits[i], .unneeded) catch |err| switch (err) {20293 field_inits[i] = try sema.coerce(block, field_ty, field_inits[i], field_src);
20353 error.NeededSourceLocation => {
20354 const decl = mod.declPtr(block.src_decl);
20355 const field_src = mod.initSrc(init_src.node_offset.x, decl, i);
20356 _ = try sema.coerce(block, field_ty, field_inits[i], field_src);
20357 unreachable;
20358 },
20359 else => |e| return e,
20360 };
20361 continue;20294 continue;
20362 }20295 }
2036320296
...@@ -20367,18 +20300,18 @@ fn finishStructInit(...@@ -20367,18 +20300,18 @@ fn finishStructInit(
20367 if (anon_struct.names.len == 0) {20300 if (anon_struct.names.len == 0) {
20368 const template = "missing tuple field with index {d}";20301 const template = "missing tuple field with index {d}";
20369 if (root_msg) |msg| {20302 if (root_msg) |msg| {
20370 try sema.errNote(block, init_src, msg, template, .{i});20303 try sema.errNote(init_src, msg, template, .{i});
20371 } else {20304 } else {
20372 root_msg = try sema.errMsg(block, init_src, template, .{i});20305 root_msg = try sema.errMsg(init_src, template, .{i});
20373 }20306 }
20374 } else {20307 } else {
20375 const field_name = anon_struct.names.get(ip)[i];20308 const field_name = anon_struct.names.get(ip)[i];
20376 const template = "missing struct field: {}";20309 const template = "missing struct field: {}";
20377 const args = .{field_name.fmt(ip)};20310 const args = .{field_name.fmt(ip)};
20378 if (root_msg) |msg| {20311 if (root_msg) |msg| {
20379 try sema.errNote(block, init_src, msg, template, args);20312 try sema.errNote(init_src, msg, template, args);
20380 } else {20313 } else {
20381 root_msg = try sema.errMsg(block, init_src, template, args);20314 root_msg = try sema.errMsg(init_src, template, args);
20382 }20315 }
20383 }20316 }
20384 } else {20317 } else {
...@@ -20391,16 +20324,12 @@ fn finishStructInit(...@@ -20391,16 +20324,12 @@ fn finishStructInit(
20391 for (0..struct_type.field_types.len) |i| {20324 for (0..struct_type.field_types.len) |i| {
20392 if (field_inits[i] != .none) {20325 if (field_inits[i] != .none) {
20393 // Coerce the init value to the field type.20326 // Coerce the init value to the field type.
20327 const field_src = block.src(.{ .init_elem = .{
20328 .init_node_offset = init_src.offset.node_offset.x,
20329 .elem_index = @intCast(i),
20330 } });
20394 const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[i]);20331 const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[i]);
20395 field_inits[i] = sema.coerce(block, field_ty, field_inits[i], init_src) catch |err| switch (err) {20332 field_inits[i] = try sema.coerce(block, field_ty, field_inits[i], field_src);
20396 error.NeededSourceLocation => {
20397 const decl = mod.declPtr(block.src_decl);
20398 const field_src = mod.initSrc(init_src.node_offset.x, decl, i);
20399 _ = try sema.coerce(block, field_ty, field_inits[i], field_src);
20400 unreachable;
20401 },
20402 else => |e| return e,
20403 };
20404 continue;20333 continue;
20405 }20334 }
2040620335
...@@ -20413,16 +20342,16 @@ fn finishStructInit(...@@ -20413,16 +20342,16 @@ fn finishStructInit(
20413 const template = "missing struct field: {}";20342 const template = "missing struct field: {}";
20414 const args = .{field_name.fmt(ip)};20343 const args = .{field_name.fmt(ip)};
20415 if (root_msg) |msg| {20344 if (root_msg) |msg| {
20416 try sema.errNote(block, init_src, msg, template, args);20345 try sema.errNote(init_src, msg, template, args);
20417 } else {20346 } else {
20418 root_msg = try sema.errMsg(block, init_src, template, args);20347 root_msg = try sema.errMsg(init_src, template, args);
20419 }20348 }
20420 } else {20349 } else {
20421 const template = "missing tuple field with index {d}";20350 const template = "missing tuple field with index {d}";
20422 if (root_msg) |msg| {20351 if (root_msg) |msg| {
20423 try sema.errNote(block, init_src, msg, template, .{i});20352 try sema.errNote(init_src, msg, template, .{i});
20424 } else {20353 } else {
20425 root_msg = try sema.errMsg(block, init_src, template, .{i});20354 root_msg = try sema.errMsg(init_src, template, .{i});
20426 }20355 }
20427 }20356 }
20428 } else {20357 } else {
...@@ -20434,16 +20363,7 @@ fn finishStructInit(...@@ -20434,16 +20363,7 @@ fn finishStructInit(
20434 }20363 }
2043520364
20436 if (root_msg) |msg| {20365 if (root_msg) |msg| {
20437 if (mod.typeToStruct(struct_ty)) |struct_type| {20366 try sema.addDeclaredHereNote(msg, struct_ty);
20438 const decl = mod.declPtr(struct_type.decl.unwrap().?);
20439 const fqn = try decl.fullyQualifiedName(mod);
20440 try mod.errNoteNonLazy(
20441 decl.srcLoc(mod),
20442 msg,
20443 "struct '{}' declared here",
20444 .{fqn.fmt(ip)},
20445 );
20446 }
20447 root_msg = null;20367 root_msg = null;
20448 return sema.failWithOwnedErrorMsg(block, msg);20368 return sema.failWithOwnedErrorMsg(block, msg);
20449 }20369 }
...@@ -20470,9 +20390,10 @@ fn finishStructInit(...@@ -20470,9 +20390,10 @@ fn finishStructInit(
20470 };20390 };
2047120391
20472 if (try sema.typeRequiresComptime(struct_ty)) {20392 if (try sema.typeRequiresComptime(struct_ty)) {
20473 const decl = mod.declPtr(block.src_decl);20393 return sema.failWithNeededComptime(block, block.src(.{ .init_elem = .{
20474 const field_src = mod.initSrc(init_src.node_offset.x, decl, runtime_index);20394 .init_node_offset = init_src.offset.node_offset.x,
20475 return sema.failWithNeededComptime(block, field_src, .{20395 .elem_index = @intCast(runtime_index),
20396 } }), .{
20476 .needed_comptime_reason = "initializer of comptime only struct must be comptime-known",20397 .needed_comptime_reason = "initializer of comptime only struct must be comptime-known",
20477 });20398 });
20478 }20399 }
...@@ -20500,15 +20421,10 @@ fn finishStructInit(...@@ -20500,15 +20421,10 @@ fn finishStructInit(
20500 return sema.makePtrConst(block, alloc);20421 return sema.makePtrConst(block, alloc);
20501 }20422 }
2050220423
20503 sema.requireRuntimeBlock(block, .unneeded, null) catch |err| switch (err) {20424 try sema.requireRuntimeBlock(block, dest_src, block.src(.{ .init_elem = .{
20504 error.NeededSourceLocation => {20425 .init_node_offset = init_src.offset.node_offset.x,
20505 const decl = mod.declPtr(block.src_decl);20426 .elem_index = @intCast(runtime_index),
20506 const field_src = mod.initSrc(dest_src.node_offset.x, decl, runtime_index);20427 } }));
20507 try sema.requireRuntimeBlock(block, dest_src, field_src);
20508 unreachable;
20509 },
20510 else => |e| return e,
20511 };
20512 try sema.resolveStructFieldInits(struct_ty);20428 try sema.resolveStructFieldInits(struct_ty);
20513 try sema.queueFullTypeResolution(struct_ty);20429 try sema.queueFullTypeResolution(struct_ty);
20514 const struct_val = try block.addAggregateInit(struct_ty, field_inits);20430 const struct_val = try block.addAggregateInit(struct_ty, field_inits);
...@@ -20576,9 +20492,11 @@ fn structInitAnon(...@@ -20576,9 +20492,11 @@ fn structInitAnon(
20576 field_ty.* = sema.typeOf(init).toIntern();20492 field_ty.* = sema.typeOf(init).toIntern();
20577 if (Type.fromInterned(field_ty.*).zigTypeTag(mod) == .Opaque) {20493 if (Type.fromInterned(field_ty.*).zigTypeTag(mod) == .Opaque) {
20578 const msg = msg: {20494 const msg = msg: {
20579 const decl = mod.declPtr(block.src_decl);20495 const field_src = block.src(.{ .init_elem = .{
20580 const field_src = mod.initSrc(src.node_offset.x, decl, @intCast(i_usize));20496 .init_node_offset = src.offset.node_offset.x,
20581 const msg = try sema.errMsg(block, field_src, "opaque types have unknown size and therefore cannot be directly embedded in structs", .{});20497 .elem_index = @intCast(i_usize),
20498 } });
20499 const msg = try sema.errMsg(field_src, "opaque types have unknown size and therefore cannot be directly embedded in structs", .{});
20582 errdefer msg.destroy(sema.gpa);20500 errdefer msg.destroy(sema.gpa);
2058320501
20584 try sema.addDeclaredHereNote(msg, Type.fromInterned(field_ty.*));20502 try sema.addDeclaredHereNote(msg, Type.fromInterned(field_ty.*));
...@@ -20610,15 +20528,10 @@ fn structInitAnon(...@@ -20610,15 +20528,10 @@ fn structInitAnon(
20610 return sema.addConstantMaybeRef(tuple_val, is_ref);20528 return sema.addConstantMaybeRef(tuple_val, is_ref);
20611 };20529 };
2061220530
20613 sema.requireRuntimeBlock(block, .unneeded, null) catch |err| switch (err) {20531 try sema.requireRuntimeBlock(block, LazySrcLoc.unneeded, block.src(.{ .init_elem = .{
20614 error.NeededSourceLocation => {20532 .init_node_offset = src.offset.node_offset.x,
20615 const decl = mod.declPtr(block.src_decl);20533 .elem_index = @intCast(runtime_index),
20616 const field_src = mod.initSrc(src.node_offset.x, decl, runtime_index);20534 } }));
20617 try sema.requireRuntimeBlock(block, src, field_src);
20618 unreachable;
20619 },
20620 else => |e| return e,
20621 };
2062220535
20623 if (is_ref) {20536 if (is_ref) {
20624 const target = mod.getTarget();20537 const target = mod.getTarget();
...@@ -20697,15 +20610,19 @@ fn zirArrayInit(...@@ -20697,15 +20610,19 @@ fn zirArrayInit(
20697 const resolved_args = try gpa.alloc(Air.Inst.Ref, final_len);20610 const resolved_args = try gpa.alloc(Air.Inst.Ref, final_len);
20698 defer gpa.free(resolved_args);20611 defer gpa.free(resolved_args);
20699 for (resolved_args, 0..) |*dest, i| {20612 for (resolved_args, 0..) |*dest, i| {
20613 const elem_src = block.src(.{ .init_elem = .{
20614 .init_node_offset = src.offset.node_offset.x,
20615 .elem_index = @intCast(i),
20616 } });
20700 // Less inits than needed.20617 // Less inits than needed.
20701 if (i + 2 > args.len) if (is_tuple) {20618 if (i + 2 > args.len) if (is_tuple) {
20702 const default_val = array_ty.structFieldDefaultValue(i, mod).toIntern();20619 const default_val = array_ty.structFieldDefaultValue(i, mod).toIntern();
20703 if (default_val == .unreachable_value) {20620 if (default_val == .unreachable_value) {
20704 const template = "missing tuple field with index {d}";20621 const template = "missing tuple field with index {d}";
20705 if (root_msg) |msg| {20622 if (root_msg) |msg| {
20706 try sema.errNote(block, src, msg, template, .{i});20623 try sema.errNote(src, msg, template, .{i});
20707 } else {20624 } else {
20708 root_msg = try sema.errMsg(block, src, template, .{i});20625 root_msg = try sema.errMsg(src, template, .{i});
20709 }20626 }
20710 } else {20627 } else {
20711 dest.* = Air.internedToRef(default_val);20628 dest.* = Air.internedToRef(default_val);
...@@ -20722,29 +20639,17 @@ fn zirArrayInit(...@@ -20722,29 +20639,17 @@ fn zirArrayInit(
20722 array_ty.structFieldType(i, mod)20639 array_ty.structFieldType(i, mod)
20723 else20640 else
20724 array_ty.elemType2(mod);20641 array_ty.elemType2(mod);
20725 dest.* = sema.coerce(block, elem_ty, resolved_arg, .unneeded) catch |err| switch (err) {20642 dest.* = try sema.coerce(block, elem_ty, resolved_arg, elem_src);
20726 error.NeededSourceLocation => {
20727 const decl = mod.declPtr(block.src_decl);
20728 const elem_src = mod.initSrc(src.node_offset.x, decl, i);
20729 _ = try sema.coerce(block, elem_ty, resolved_arg, elem_src);
20730 unreachable;
20731 },
20732 else => return err,
20733 };
20734 if (is_tuple) {20643 if (is_tuple) {
20735 if (array_ty.structFieldIsComptime(i, mod))20644 if (array_ty.structFieldIsComptime(i, mod))
20736 try sema.resolveStructFieldInits(array_ty);20645 try sema.resolveStructFieldInits(array_ty);
20737 if (try array_ty.structFieldValueComptime(mod, i)) |field_val| {20646 if (try array_ty.structFieldValueComptime(mod, i)) |field_val| {
20738 const init_val = try sema.resolveValue(dest.*) orelse {20647 const init_val = try sema.resolveValue(dest.*) orelse {
20739 const decl = mod.declPtr(block.src_decl);
20740 const elem_src = mod.initSrc(src.node_offset.x, decl, i);
20741 return sema.failWithNeededComptime(block, elem_src, .{20648 return sema.failWithNeededComptime(block, elem_src, .{
20742 .needed_comptime_reason = "value stored in comptime field must be comptime-known",20649 .needed_comptime_reason = "value stored in comptime field must be comptime-known",
20743 });20650 });
20744 };20651 };
20745 if (!field_val.eql(init_val, elem_ty, mod)) {20652 if (!field_val.eql(init_val, elem_ty, mod)) {
20746 const decl = mod.declPtr(block.src_decl);
20747 const elem_src = mod.initSrc(src.node_offset.x, decl, i);
20748 return sema.failWithInvalidComptimeFieldStore(block, elem_src, array_ty, i);20653 return sema.failWithInvalidComptimeFieldStore(block, elem_src, array_ty, i);
20749 }20654 }
20750 }20655 }
...@@ -20777,15 +20682,10 @@ fn zirArrayInit(...@@ -20777,15 +20682,10 @@ fn zirArrayInit(
20777 return sema.addConstantMaybeRef(result_val.toIntern(), is_ref);20682 return sema.addConstantMaybeRef(result_val.toIntern(), is_ref);
20778 };20683 };
2077920684
20780 sema.requireRuntimeBlock(block, .unneeded, null) catch |err| switch (err) {20685 try sema.requireRuntimeBlock(block, LazySrcLoc.unneeded, block.src(.{ .init_elem = .{
20781 error.NeededSourceLocation => {20686 .init_node_offset = src.offset.node_offset.x,
20782 const decl = mod.declPtr(block.src_decl);20687 .elem_index = runtime_index,
20783 const elem_src = mod.initSrc(src.node_offset.x, decl, runtime_index);20688 } }));
20784 try sema.requireRuntimeBlock(block, src, elem_src);
20785 unreachable;
20786 },
20787 else => return err,
20788 };
20789 try sema.queueFullTypeResolution(array_ty);20689 try sema.queueFullTypeResolution(array_ty);
2079020690
20791 if (is_ref) {20691 if (is_ref) {
...@@ -20864,7 +20764,7 @@ fn arrayInitAnon(...@@ -20864,7 +20764,7 @@ fn arrayInitAnon(
20864 types[i] = sema.typeOf(elem).toIntern();20764 types[i] = sema.typeOf(elem).toIntern();
20865 if (Type.fromInterned(types[i]).zigTypeTag(mod) == .Opaque) {20765 if (Type.fromInterned(types[i]).zigTypeTag(mod) == .Opaque) {
20866 const msg = msg: {20766 const msg = msg: {
20867 const msg = try sema.errMsg(block, operand_src, "opaque types have unknown size and therefore cannot be directly embedded in structs", .{});20767 const msg = try sema.errMsg(operand_src, "opaque types have unknown size and therefore cannot be directly embedded in structs", .{});
20868 errdefer msg.destroy(gpa);20768 errdefer msg.destroy(gpa);
2086920769
20870 try sema.addDeclaredHereNote(msg, Type.fromInterned(types[i]));20770 try sema.addDeclaredHereNote(msg, Type.fromInterned(types[i]));
...@@ -20935,8 +20835,8 @@ fn addConstantMaybeRef(sema: *Sema, val: InternPool.Index, is_ref: bool) !Air.In...@@ -20935,8 +20835,8 @@ fn addConstantMaybeRef(sema: *Sema, val: InternPool.Index, is_ref: bool) !Air.In
20935fn zirFieldTypeRef(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {20835fn zirFieldTypeRef(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
20936 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;20836 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
20937 const extra = sema.code.extraData(Zir.Inst.FieldTypeRef, inst_data.payload_index).data;20837 const extra = sema.code.extraData(Zir.Inst.FieldTypeRef, inst_data.payload_index).data;
20938 const ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };20838 const ty_src = block.builtinCallArgSrc(inst_data.src_node, 0);
20939 const field_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };20839 const field_src = block.builtinCallArgSrc(inst_data.src_node, 1);
20940 const aggregate_ty = try sema.resolveType(block, ty_src, extra.container_type);20840 const aggregate_ty = try sema.resolveType(block, ty_src, extra.container_type);
20941 const field_name = try sema.resolveConstStringIntern(block, field_src, extra.field_name, .{20841 const field_name = try sema.resolveConstStringIntern(block, field_src, extra.field_name, .{
20942 .needed_comptime_reason = "field name must be comptime-known",20842 .needed_comptime_reason = "field name must be comptime-known",
...@@ -20950,7 +20850,7 @@ fn zirStructInitFieldType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp...@@ -20950,7 +20850,7 @@ fn zirStructInitFieldType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp
20950 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;20850 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
20951 const extra = sema.code.extraData(Zir.Inst.FieldType, inst_data.payload_index).data;20851 const extra = sema.code.extraData(Zir.Inst.FieldType, inst_data.payload_index).data;
20952 const ty_src = block.nodeOffset(inst_data.src_node);20852 const ty_src = block.nodeOffset(inst_data.src_node);
20953 const field_name_src: LazySrcLoc = .{ .node_offset_field_name_init = inst_data.src_node };20853 const field_name_src = block.src(.{ .node_offset_field_name_init = inst_data.src_node });
20954 const wrapped_aggregate_ty = sema.resolveType(block, ty_src, extra.container_type) catch |err| switch (err) {20854 const wrapped_aggregate_ty = sema.resolveType(block, ty_src, extra.container_type) catch |err| switch (err) {
20955 // Since this is a ZIR instruction that returns a type, encountering20855 // Since this is a ZIR instruction that returns a type, encountering
20956 // generic poison should not result in a failed compilation, but the20856 // generic poison should not result in a failed compilation, but the
...@@ -20990,7 +20890,7 @@ fn fieldType(...@@ -20990,7 +20890,7 @@ fn fieldType(
20990 .struct_type => {20890 .struct_type => {
20991 const struct_type = ip.loadStructType(cur_ty.toIntern());20891 const struct_type = ip.loadStructType(cur_ty.toIntern());
20992 const field_index = struct_type.nameIndex(ip, field_name) orelse20892 const field_index = struct_type.nameIndex(ip, field_name) orelse
20993 return sema.failWithBadStructFieldAccess(block, struct_type, field_src, field_name);20893 return sema.failWithBadStructFieldAccess(block, cur_ty, struct_type, field_src, field_name);
20994 const field_ty = struct_type.field_types.get(ip)[field_index];20894 const field_ty = struct_type.field_types.get(ip)[field_index];
20995 return Air.internedToRef(field_ty);20895 return Air.internedToRef(field_ty);
20996 },20896 },
...@@ -20999,7 +20899,7 @@ fn fieldType(...@@ -20999,7 +20899,7 @@ fn fieldType(
20999 .Union => {20899 .Union => {
21000 const union_obj = mod.typeToUnion(cur_ty).?;20900 const union_obj = mod.typeToUnion(cur_ty).?;
21001 const field_index = union_obj.loadTagType(ip).nameIndex(ip, field_name) orelse20901 const field_index = union_obj.loadTagType(ip).nameIndex(ip, field_name) orelse
21002 return sema.failWithBadUnionFieldAccess(block, union_obj, field_src, field_name);20902 return sema.failWithBadUnionFieldAccess(block, cur_ty, union_obj, field_src, field_name);
21003 const field_ty = union_obj.field_types.get(ip)[field_index];20903 const field_ty = union_obj.field_types.get(ip)[field_index];
21004 return Air.internedToRef(field_ty);20904 return Air.internedToRef(field_ty);
21005 },20905 },
...@@ -21050,14 +20950,14 @@ fn zirFrame(...@@ -21050,14 +20950,14 @@ fn zirFrame(
21050 block: *Block,20950 block: *Block,
21051 extended: Zir.Inst.Extended.InstData,20951 extended: Zir.Inst.Extended.InstData,
21052) CompileError!Air.Inst.Ref {20952) CompileError!Air.Inst.Ref {
21053 const src = LazySrcLoc.nodeOffset(@bitCast(extended.operand));20953 const src = block.nodeOffset(@bitCast(extended.operand));
21054 return sema.failWithUseOfAsync(block, src);20954 return sema.failWithUseOfAsync(block, src);
21055}20955}
2105620956
21057fn zirAlignOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {20957fn zirAlignOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
21058 const mod = sema.mod;20958 const mod = sema.mod;
21059 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;20959 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
21060 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };20960 const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0);
21061 const ty = try sema.resolveType(block, operand_src, inst_data.operand);20961 const ty = try sema.resolveType(block, operand_src, inst_data.operand);
21062 if (ty.isNoReturn(mod)) {20962 if (ty.isNoReturn(mod)) {
21063 return sema.fail(block, operand_src, "no align available for type '{}'", .{ty.fmt(sema.mod)});20963 return sema.fail(block, operand_src, "no align available for type '{}'", .{ty.fmt(sema.mod)});
...@@ -21121,7 +21021,7 @@ fn zirIntFromBool(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError...@@ -21121,7 +21021,7 @@ fn zirIntFromBool(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
2112121021
21122fn zirErrorName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {21022fn zirErrorName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
21123 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;21023 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
21124 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };21024 const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0);
21125 const uncoerced_operand = try sema.resolveInst(inst_data.operand);21025 const uncoerced_operand = try sema.resolveInst(inst_data.operand);
21126 const operand = try sema.coerce(block, Type.anyerror, uncoerced_operand, operand_src);21026 const operand = try sema.coerce(block, Type.anyerror, uncoerced_operand, operand_src);
2112721027
...@@ -21143,7 +21043,7 @@ fn zirAbs(...@@ -21143,7 +21043,7 @@ fn zirAbs(
21143 const mod = sema.mod;21043 const mod = sema.mod;
21144 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;21044 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
21145 const operand = try sema.resolveInst(inst_data.operand);21045 const operand = try sema.resolveInst(inst_data.operand);
21146 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };21046 const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0);
21147 const operand_ty = sema.typeOf(operand);21047 const operand_ty = sema.typeOf(operand);
21148 const scalar_ty = operand_ty.scalarType(mod);21048 const scalar_ty = operand_ty.scalarType(mod);
2114921049
...@@ -21211,7 +21111,7 @@ fn zirUnaryMath(...@@ -21211,7 +21111,7 @@ fn zirUnaryMath(
21211 const mod = sema.mod;21111 const mod = sema.mod;
21212 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;21112 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
21213 const operand = try sema.resolveInst(inst_data.operand);21113 const operand = try sema.resolveInst(inst_data.operand);
21214 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };21114 const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0);
21215 const operand_ty = sema.typeOf(operand);21115 const operand_ty = sema.typeOf(operand);
21216 const scalar_ty = operand_ty.scalarType(mod);21116 const scalar_ty = operand_ty.scalarType(mod);
2121721117
...@@ -21233,7 +21133,7 @@ fn zirUnaryMath(...@@ -21233,7 +21133,7 @@ fn zirUnaryMath(
2123321133
21234fn zirTagName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {21134fn zirTagName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
21235 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;21135 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
21236 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };21136 const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0);
21237 const src = block.nodeOffset(inst_data.src_node);21137 const src = block.nodeOffset(inst_data.src_node);
21238 const operand = try sema.resolveInst(inst_data.operand);21138 const operand = try sema.resolveInst(inst_data.operand);
21239 const operand_ty = sema.typeOf(operand);21139 const operand_ty = sema.typeOf(operand);
...@@ -21243,7 +21143,7 @@ fn zirTagName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air...@@ -21243,7 +21143,7 @@ fn zirTagName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
21243 try sema.resolveTypeLayout(operand_ty);21143 try sema.resolveTypeLayout(operand_ty);
21244 const enum_ty = switch (operand_ty.zigTypeTag(mod)) {21144 const enum_ty = switch (operand_ty.zigTypeTag(mod)) {
21245 .EnumLiteral => {21145 .EnumLiteral => {
21246 const val = try sema.resolveConstDefinedValue(block, .unneeded, operand, undefined);21146 const val = try sema.resolveConstDefinedValue(block, LazySrcLoc.unneeded, operand, undefined);
21247 const tag_name = ip.indexToKey(val.toIntern()).enum_literal;21147 const tag_name = ip.indexToKey(val.toIntern()).enum_literal;
21248 return sema.addNullTerminatedStrLit(tag_name);21148 return sema.addNullTerminatedStrLit(tag_name);
21249 },21149 },
...@@ -21266,13 +21166,12 @@ fn zirTagName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air...@@ -21266,13 +21166,12 @@ fn zirTagName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
21266 const casted_operand = try sema.coerce(block, enum_ty, operand, operand_src);21166 const casted_operand = try sema.coerce(block, enum_ty, operand, operand_src);
21267 if (try sema.resolveDefinedValue(block, operand_src, casted_operand)) |val| {21167 if (try sema.resolveDefinedValue(block, operand_src, casted_operand)) |val| {
21268 const field_index = enum_ty.enumTagFieldIndex(val, mod) orelse {21168 const field_index = enum_ty.enumTagFieldIndex(val, mod) orelse {
21269 const enum_decl = mod.declPtr(enum_decl_index);
21270 const msg = msg: {21169 const msg = msg: {
21271 const msg = try sema.errMsg(block, src, "no field with value '{}' in enum '{}'", .{21170 const msg = try sema.errMsg(src, "no field with value '{}' in enum '{}'", .{
21272 val.fmtValue(sema.mod, sema), enum_decl.name.fmt(ip),21171 val.fmtValue(sema.mod, sema), mod.declPtr(enum_decl_index).name.fmt(ip),
21273 });21172 });
21274 errdefer msg.destroy(sema.gpa);21173 errdefer msg.destroy(sema.gpa);
21275 try mod.errNoteNonLazy(enum_decl.srcLoc(mod), msg, "declared here", .{});21174 try sema.errNote(enum_ty.srcLoc(mod), msg, "declared here", .{});
21276 break :msg msg;21175 break :msg msg;
21277 };21176 };
21278 return sema.failWithOwnedErrorMsg(block, msg);21177 return sema.failWithOwnedErrorMsg(block, msg);
...@@ -21303,10 +21202,10 @@ fn zirReify(...@@ -21303,10 +21202,10 @@ fn zirReify(
21303 const ip = &mod.intern_pool;21202 const ip = &mod.intern_pool;
21304 const name_strategy: Zir.Inst.NameStrategy = @enumFromInt(extended.small);21203 const name_strategy: Zir.Inst.NameStrategy = @enumFromInt(extended.small);
21305 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;21204 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;
21306 const src = LazySrcLoc.nodeOffset(extra.node);21205 const src = block.nodeOffset(extra.node);
21307 const type_info_ty = try sema.getBuiltinType("Type");21206 const type_info_ty = try sema.getBuiltinType("Type");
21308 const uncasted_operand = try sema.resolveInst(extra.operand);21207 const uncasted_operand = try sema.resolveInst(extra.operand);
21309 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node };21208 const operand_src = block.builtinCallArgSrc(extra.node, 0);
21310 const type_info = try sema.coerce(block, type_info_ty, uncasted_operand, operand_src);21209 const type_info = try sema.coerce(block, type_info_ty, uncasted_operand, operand_src);
21311 const val = try sema.resolveConstDefinedValue(block, operand_src, type_info, .{21210 const val = try sema.resolveConstDefinedValue(block, operand_src, type_info, .{
21312 .needed_comptime_reason = "operand to @Type must be comptime-known",21211 .needed_comptime_reason = "operand to @Type must be comptime-known",
...@@ -21459,11 +21358,10 @@ fn zirReify(...@@ -21459,11 +21358,10 @@ fn zirReify(
21459 } else if (ptr_size == .C) {21358 } else if (ptr_size == .C) {
21460 if (!try sema.validateExternType(elem_ty, .other)) {21359 if (!try sema.validateExternType(elem_ty, .other)) {
21461 const msg = msg: {21360 const msg = msg: {
21462 const msg = try sema.errMsg(block, src, "C pointers cannot point to non-C-ABI-compatible type '{}'", .{elem_ty.fmt(mod)});21361 const msg = try sema.errMsg(src, "C pointers cannot point to non-C-ABI-compatible type '{}'", .{elem_ty.fmt(mod)});
21463 errdefer msg.destroy(gpa);21362 errdefer msg.destroy(gpa);
2146421363
21465 const src_decl = mod.declPtr(block.src_decl);21364 try sema.explainWhyTypeIsNotExtern(msg, src, elem_ty, .other);
21466 try sema.explainWhyTypeIsNotExtern(msg, src_decl.toSrcLoc(src, mod), elem_ty, .other);
2146721365
21468 try sema.addDeclaredHereNote(msg, elem_ty);21366 try sema.addDeclaredHereNote(msg, elem_ty);
21469 break :msg msg;21367 break :msg msg;
...@@ -21679,7 +21577,6 @@ fn zirReify(...@@ -21679,7 +21577,6 @@ fn zirReify(
2167921577
21680 const new_decl_index = try sema.createAnonymousDeclTypeNamed(21578 const new_decl_index = try sema.createAnonymousDeclTypeNamed(
21681 block,21579 block,
21682 mod.declPtr(block.src_decl).relativeToNodeIndex(src.node_offset.x),
21683 Value.fromInterned(wip_ty.index),21580 Value.fromInterned(wip_ty.index),
21684 name_strategy,21581 name_strategy,
21685 "opaque",21582 "opaque",
...@@ -21879,7 +21776,6 @@ fn reifyEnum(...@@ -21879,7 +21776,6 @@ fn reifyEnum(
2187921776
21880 const new_decl_index = try sema.createAnonymousDeclTypeNamed(21777 const new_decl_index = try sema.createAnonymousDeclTypeNamed(
21881 block,21778 block,
21882 mod.declPtr(block.src_decl).relativeToNodeIndex(src.node_offset.x),
21883 Value.fromInterned(wip_ty.index),21779 Value.fromInterned(wip_ty.index),
21884 name_strategy,21780 name_strategy,
21885 "enum",21781 "enum",
...@@ -21913,17 +21809,17 @@ fn reifyEnum(...@@ -21913,17 +21809,17 @@ fn reifyEnum(
21913 if (wip_ty.nextField(ip, field_name, coerced_field_val.toIntern())) |conflict| {21809 if (wip_ty.nextField(ip, field_name, coerced_field_val.toIntern())) |conflict| {
21914 return sema.failWithOwnedErrorMsg(block, switch (conflict.kind) {21810 return sema.failWithOwnedErrorMsg(block, switch (conflict.kind) {
21915 .name => msg: {21811 .name => msg: {
21916 const msg = try sema.errMsg(block, src, "duplicate enum field '{}'", .{field_name.fmt(ip)});21812 const msg = try sema.errMsg(src, "duplicate enum field '{}'", .{field_name.fmt(ip)});
21917 errdefer msg.destroy(gpa);21813 errdefer msg.destroy(gpa);
21918 _ = conflict.prev_field_idx; // TODO: this note is incorrect21814 _ = conflict.prev_field_idx; // TODO: this note is incorrect
21919 try sema.errNote(block, src, msg, "other field here", .{});21815 try sema.errNote(src, msg, "other field here", .{});
21920 break :msg msg;21816 break :msg msg;
21921 },21817 },
21922 .value => msg: {21818 .value => msg: {
21923 const msg = try sema.errMsg(block, src, "enum tag value {} already taken", .{field_value_val.fmtValue(mod, sema)});21819 const msg = try sema.errMsg(src, "enum tag value {} already taken", .{field_value_val.fmtValue(mod, sema)});
21924 errdefer msg.destroy(gpa);21820 errdefer msg.destroy(gpa);
21925 _ = conflict.prev_field_idx; // TODO: this note is incorrect21821 _ = conflict.prev_field_idx; // TODO: this note is incorrect
21926 try sema.errNote(block, src, msg, "other enum tag value here", .{});21822 try sema.errNote(src, msg, "other enum tag value here", .{});
21927 break :msg msg;21823 break :msg msg;
21928 },21824 },
21929 });21825 });
...@@ -22026,7 +21922,6 @@ fn reifyUnion(...@@ -22026,7 +21922,6 @@ fn reifyUnion(
2202621922
22027 const new_decl_index = try sema.createAnonymousDeclTypeNamed(21923 const new_decl_index = try sema.createAnonymousDeclTypeNamed(
22028 block,21924 block,
22029 mod.declPtr(block.src_decl).relativeToNodeIndex(src.node_offset.x),
22030 Value.fromInterned(wip_ty.index),21925 Value.fromInterned(wip_ty.index),
22031 name_strategy,21926 name_strategy,
22032 "union",21927 "union",
...@@ -22082,7 +21977,7 @@ fn reifyUnion(...@@ -22082,7 +21977,7 @@ fn reifyUnion(
22082 }21977 }
2208321978
22084 if (tag_ty_fields_len > fields_len) return sema.failWithOwnedErrorMsg(block, msg: {21979 if (tag_ty_fields_len > fields_len) return sema.failWithOwnedErrorMsg(block, msg: {
22085 const msg = try sema.errMsg(block, src, "enum fields missing in union", .{});21980 const msg = try sema.errMsg(src, "enum fields missing in union", .{});
22086 errdefer msg.destroy(gpa);21981 errdefer msg.destroy(gpa);
22087 var it = seen_tags.iterator(.{ .kind = .unset });21982 var it = seen_tags.iterator(.{ .kind = .unset });
22088 while (it.next()) |enum_index| {21983 while (it.next()) |enum_index| {
...@@ -22135,7 +22030,7 @@ fn reifyUnion(...@@ -22135,7 +22030,7 @@ fn reifyUnion(
22135 const field_ty = Type.fromInterned(field_ty_ip);22030 const field_ty = Type.fromInterned(field_ty_ip);
22136 if (field_ty.zigTypeTag(mod) == .Opaque) {22031 if (field_ty.zigTypeTag(mod) == .Opaque) {
22137 return sema.failWithOwnedErrorMsg(block, msg: {22032 return sema.failWithOwnedErrorMsg(block, msg: {
22138 const msg = try sema.errMsg(block, src, "opaque types have unknown size and therefore cannot be directly embedded in unions", .{});22033 const msg = try sema.errMsg(src, "opaque types have unknown size and therefore cannot be directly embedded in unions", .{});
22139 errdefer msg.destroy(gpa);22034 errdefer msg.destroy(gpa);
2214022035
22141 try sema.addDeclaredHereNote(msg, field_ty);22036 try sema.addDeclaredHereNote(msg, field_ty);
...@@ -22144,22 +22039,20 @@ fn reifyUnion(...@@ -22144,22 +22039,20 @@ fn reifyUnion(
22144 }22039 }
22145 if (layout == .@"extern" and !try sema.validateExternType(field_ty, .union_field)) {22040 if (layout == .@"extern" and !try sema.validateExternType(field_ty, .union_field)) {
22146 return sema.failWithOwnedErrorMsg(block, msg: {22041 return sema.failWithOwnedErrorMsg(block, msg: {
22147 const msg = try sema.errMsg(block, src, "extern unions cannot contain fields of type '{}'", .{field_ty.fmt(mod)});22042 const msg = try sema.errMsg(src, "extern unions cannot contain fields of type '{}'", .{field_ty.fmt(mod)});
22148 errdefer msg.destroy(gpa);22043 errdefer msg.destroy(gpa);
2214922044
22150 const src_decl = mod.declPtr(block.src_decl);22045 try sema.explainWhyTypeIsNotExtern(msg, src, field_ty, .union_field);
22151 try sema.explainWhyTypeIsNotExtern(msg, src_decl.toSrcLoc(src, mod), field_ty, .union_field);
2215222046
22153 try sema.addDeclaredHereNote(msg, field_ty);22047 try sema.addDeclaredHereNote(msg, field_ty);
22154 break :msg msg;22048 break :msg msg;
22155 });22049 });
22156 } else if (layout == .@"packed" and !try sema.validatePackedType(field_ty)) {22050 } else if (layout == .@"packed" and !try sema.validatePackedType(field_ty)) {
22157 return sema.failWithOwnedErrorMsg(block, msg: {22051 return sema.failWithOwnedErrorMsg(block, msg: {
22158 const msg = try sema.errMsg(block, src, "packed unions cannot contain fields of type '{}'", .{field_ty.fmt(mod)});22052 const msg = try sema.errMsg(src, "packed unions cannot contain fields of type '{}'", .{field_ty.fmt(mod)});
22159 errdefer msg.destroy(gpa);22053 errdefer msg.destroy(gpa);
2216022054
22161 const src_decl = mod.declPtr(block.src_decl);22055 try sema.explainWhyTypeIsNotPacked(msg, src, field_ty);
22162 try sema.explainWhyTypeIsNotPacked(msg, src_decl.toSrcLoc(src, mod), field_ty);
2216322056
22164 try sema.addDeclaredHereNote(msg, field_ty);22057 try sema.addDeclaredHereNote(msg, field_ty);
22165 break :msg msg;22058 break :msg msg;
...@@ -22285,7 +22178,6 @@ fn reifyStruct(...@@ -22285,7 +22178,6 @@ fn reifyStruct(
2228522178
22286 const new_decl_index = try sema.createAnonymousDeclTypeNamed(22179 const new_decl_index = try sema.createAnonymousDeclTypeNamed(
22287 block,22180 block,
22288 mod.declPtr(block.src_decl).relativeToNodeIndex(src.node_offset.x),
22289 Value.fromInterned(wip_ty.index),22181 Value.fromInterned(wip_ty.index),
22290 name_strategy,22182 name_strategy,
22291 "struct",22183 "struct",
...@@ -22376,7 +22268,7 @@ fn reifyStruct(...@@ -22376,7 +22268,7 @@ fn reifyStruct(
2237622268
22377 if (field_ty.zigTypeTag(mod) == .Opaque) {22269 if (field_ty.zigTypeTag(mod) == .Opaque) {
22378 return sema.failWithOwnedErrorMsg(block, msg: {22270 return sema.failWithOwnedErrorMsg(block, msg: {
22379 const msg = try sema.errMsg(block, src, "opaque types have unknown size and therefore cannot be directly embedded in structs", .{});22271 const msg = try sema.errMsg(src, "opaque types have unknown size and therefore cannot be directly embedded in structs", .{});
22380 errdefer msg.destroy(gpa);22272 errdefer msg.destroy(gpa);
2238122273
22382 try sema.addDeclaredHereNote(msg, field_ty);22274 try sema.addDeclaredHereNote(msg, field_ty);
...@@ -22385,7 +22277,7 @@ fn reifyStruct(...@@ -22385,7 +22277,7 @@ fn reifyStruct(
22385 }22277 }
22386 if (field_ty.zigTypeTag(mod) == .NoReturn) {22278 if (field_ty.zigTypeTag(mod) == .NoReturn) {
22387 return sema.failWithOwnedErrorMsg(block, msg: {22279 return sema.failWithOwnedErrorMsg(block, msg: {
22388 const msg = try sema.errMsg(block, src, "struct fields cannot be 'noreturn'", .{});22280 const msg = try sema.errMsg(src, "struct fields cannot be 'noreturn'", .{});
22389 errdefer msg.destroy(gpa);22281 errdefer msg.destroy(gpa);
2239022282
22391 try sema.addDeclaredHereNote(msg, field_ty);22283 try sema.addDeclaredHereNote(msg, field_ty);
...@@ -22394,22 +22286,20 @@ fn reifyStruct(...@@ -22394,22 +22286,20 @@ fn reifyStruct(
22394 }22286 }
22395 if (layout == .@"extern" and !try sema.validateExternType(field_ty, .struct_field)) {22287 if (layout == .@"extern" and !try sema.validateExternType(field_ty, .struct_field)) {
22396 return sema.failWithOwnedErrorMsg(block, msg: {22288 return sema.failWithOwnedErrorMsg(block, msg: {
22397 const msg = try sema.errMsg(block, src, "extern structs cannot contain fields of type '{}'", .{field_ty.fmt(sema.mod)});22289 const msg = try sema.errMsg(src, "extern structs cannot contain fields of type '{}'", .{field_ty.fmt(sema.mod)});
22398 errdefer msg.destroy(gpa);22290 errdefer msg.destroy(gpa);
2239922291
22400 const src_decl = sema.mod.declPtr(block.src_decl);22292 try sema.explainWhyTypeIsNotExtern(msg, src, field_ty, .struct_field);
22401 try sema.explainWhyTypeIsNotExtern(msg, src_decl.toSrcLoc(src, mod), field_ty, .struct_field);
2240222293
22403 try sema.addDeclaredHereNote(msg, field_ty);22294 try sema.addDeclaredHereNote(msg, field_ty);
22404 break :msg msg;22295 break :msg msg;
22405 });22296 });
22406 } else if (layout == .@"packed" and !try sema.validatePackedType(field_ty)) {22297 } else if (layout == .@"packed" and !try sema.validatePackedType(field_ty)) {
22407 return sema.failWithOwnedErrorMsg(block, msg: {22298 return sema.failWithOwnedErrorMsg(block, msg: {
22408 const msg = try sema.errMsg(block, src, "packed structs cannot contain fields of type '{}'", .{field_ty.fmt(sema.mod)});22299 const msg = try sema.errMsg(src, "packed structs cannot contain fields of type '{}'", .{field_ty.fmt(sema.mod)});
22409 errdefer msg.destroy(gpa);22300 errdefer msg.destroy(gpa);
2241022301
22411 const src_decl = sema.mod.declPtr(block.src_decl);22302 try sema.explainWhyTypeIsNotPacked(msg, src, field_ty);
22412 try sema.explainWhyTypeIsNotPacked(msg, src_decl.toSrcLoc(src, mod), field_ty);
2241322303
22414 try sema.addDeclaredHereNote(msg, field_ty);22304 try sema.addDeclaredHereNote(msg, field_ty);
22415 break :msg msg;22305 break :msg msg;
...@@ -22424,7 +22314,7 @@ fn reifyStruct(...@@ -22424,7 +22314,7 @@ fn reifyStruct(
22424 sema.resolveTypeLayout(field_ty) catch |err| switch (err) {22314 sema.resolveTypeLayout(field_ty) catch |err| switch (err) {
22425 error.AnalysisFail => {22315 error.AnalysisFail => {
22426 const msg = sema.err orelse return err;22316 const msg = sema.err orelse return err;
22427 try sema.errNote(block, src, msg, "while checking a field of this struct", .{});22317 try sema.errNote(src, msg, "while checking a field of this struct", .{});
22428 return err;22318 return err;
22429 },22319 },
22430 else => return err,22320 else => return err,
...@@ -22455,22 +22345,20 @@ fn resolveVaListRef(sema: *Sema, block: *Block, src: LazySrcLoc, zir_ref: Zir.In...@@ -22455,22 +22345,20 @@ fn resolveVaListRef(sema: *Sema, block: *Block, src: LazySrcLoc, zir_ref: Zir.In
22455}22345}
2245622346
22457fn zirCVaArg(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!Air.Inst.Ref {22347fn zirCVaArg(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!Air.Inst.Ref {
22458 const mod = sema.mod;
22459 const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data;22348 const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data;
22460 const src = LazySrcLoc.nodeOffset(extra.node);22349 const src = block.nodeOffset(extra.node);
22461 const va_list_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node };22350 const va_list_src = block.builtinCallArgSrc(extra.node, 0);
22462 const ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = extra.node };22351 const ty_src = block.builtinCallArgSrc(extra.node, 1);
2246322352
22464 const va_list_ref = try sema.resolveVaListRef(block, va_list_src, extra.lhs);22353 const va_list_ref = try sema.resolveVaListRef(block, va_list_src, extra.lhs);
22465 const arg_ty = try sema.resolveType(block, ty_src, extra.rhs);22354 const arg_ty = try sema.resolveType(block, ty_src, extra.rhs);
2246622355
22467 if (!try sema.validateExternType(arg_ty, .param_ty)) {22356 if (!try sema.validateExternType(arg_ty, .param_ty)) {
22468 const msg = msg: {22357 const msg = msg: {
22469 const msg = try sema.errMsg(block, ty_src, "cannot get '{}' from variadic argument", .{arg_ty.fmt(sema.mod)});22358 const msg = try sema.errMsg(ty_src, "cannot get '{}' from variadic argument", .{arg_ty.fmt(sema.mod)});
22470 errdefer msg.destroy(sema.gpa);22359 errdefer msg.destroy(sema.gpa);
2247122360
22472 const src_decl = sema.mod.declPtr(block.src_decl);22361 try sema.explainWhyTypeIsNotExtern(msg, ty_src, arg_ty, .param_ty);
22473 try sema.explainWhyTypeIsNotExtern(msg, src_decl.toSrcLoc(ty_src, mod), arg_ty, .param_ty);
2247422362
22475 try sema.addDeclaredHereNote(msg, arg_ty);22363 try sema.addDeclaredHereNote(msg, arg_ty);
22476 break :msg msg;22364 break :msg msg;
...@@ -22484,8 +22372,8 @@ fn zirCVaArg(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) C...@@ -22484,8 +22372,8 @@ fn zirCVaArg(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) C
2248422372
22485fn zirCVaCopy(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!Air.Inst.Ref {22373fn zirCVaCopy(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!Air.Inst.Ref {
22486 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;22374 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;
22487 const src = LazySrcLoc.nodeOffset(extra.node);22375 const src = block.nodeOffset(extra.node);
22488 const va_list_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node };22376 const va_list_src = block.builtinCallArgSrc(extra.node, 0);
2248922377
22490 const va_list_ref = try sema.resolveVaListRef(block, va_list_src, extra.operand);22378 const va_list_ref = try sema.resolveVaListRef(block, va_list_src, extra.operand);
22491 const va_list_ty = try sema.getBuiltinType("VaList");22379 const va_list_ty = try sema.getBuiltinType("VaList");
...@@ -22496,8 +22384,8 @@ fn zirCVaCopy(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData)...@@ -22496,8 +22384,8 @@ fn zirCVaCopy(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData)
2249622384
22497fn zirCVaEnd(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!Air.Inst.Ref {22385fn zirCVaEnd(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!Air.Inst.Ref {
22498 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;22386 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;
22499 const src = LazySrcLoc.nodeOffset(extra.node);22387 const src = block.nodeOffset(extra.node);
22500 const va_list_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node };22388 const va_list_src = block.builtinCallArgSrc(extra.node, 0);
2250122389
22502 const va_list_ref = try sema.resolveVaListRef(block, va_list_src, extra.operand);22390 const va_list_ref = try sema.resolveVaListRef(block, va_list_src, extra.operand);
2250322391
...@@ -22506,7 +22394,7 @@ fn zirCVaEnd(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) C...@@ -22506,7 +22394,7 @@ fn zirCVaEnd(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) C
22506}22394}
2250722395
22508fn zirCVaStart(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!Air.Inst.Ref {22396fn 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
22511 const va_list_ty = try sema.getBuiltinType("VaList");22399 const va_list_ty = try sema.getBuiltinType("VaList");
22512 try sema.requireRuntimeBlock(block, src, null);22400 try sema.requireRuntimeBlock(block, src, null);
...@@ -22521,7 +22409,7 @@ fn zirTypeName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -22521,7 +22409,7 @@ fn zirTypeName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
22521 const ip = &mod.intern_pool;22409 const ip = &mod.intern_pool;
2252222410
22523 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;22411 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
22524 const ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };22412 const ty_src = block.builtinCallArgSrc(inst_data.src_node, 0);
22525 const ty = try sema.resolveType(block, ty_src, inst_data.operand);22413 const ty = try sema.resolveType(block, ty_src, inst_data.operand);
2252622414
22527 const type_name = try ip.getOrPutStringFmt(sema.gpa, "{}", .{ty.fmt(mod)}, .no_embedded_nulls);22415 const type_name = try ip.getOrPutStringFmt(sema.gpa, "{}", .{ty.fmt(mod)}, .no_embedded_nulls);
...@@ -22545,7 +22433,7 @@ fn zirIntFromFloat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro...@@ -22545,7 +22433,7 @@ fn zirIntFromFloat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
22545 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;22433 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
22546 const src = block.nodeOffset(inst_data.src_node);22434 const src = block.nodeOffset(inst_data.src_node);
22547 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;22435 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
22548 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };22436 const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0);
22549 const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu_opt, "@intFromFloat");22437 const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu_opt, "@intFromFloat");
22550 const operand = try sema.resolveInst(extra.rhs);22438 const operand = try sema.resolveInst(extra.rhs);
22551 const operand_ty = sema.typeOf(operand);22439 const operand_ty = sema.typeOf(operand);
...@@ -22627,7 +22515,7 @@ fn zirFloatFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro...@@ -22627,7 +22515,7 @@ fn zirFloatFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
22627 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;22515 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
22628 const src = block.nodeOffset(inst_data.src_node);22516 const src = block.nodeOffset(inst_data.src_node);
22629 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;22517 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
22630 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };22518 const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0);
22631 const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu_opt, "@floatFromInt");22519 const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu_opt, "@floatFromInt");
22632 const operand = try sema.resolveInst(extra.rhs);22520 const operand = try sema.resolveInst(extra.rhs);
22633 const operand_ty = sema.typeOf(operand);22521 const operand_ty = sema.typeOf(operand);
...@@ -22671,7 +22559,7 @@ fn zirPtrFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!...@@ -22671,7 +22559,7 @@ fn zirPtrFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
2267122559
22672 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;22560 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
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);
22675 const operand_res = try sema.resolveInst(extra.rhs);22563 const operand_res = try sema.resolveInst(extra.rhs);
2267622564
22677 const uncoerced_operand_ty = sema.typeOf(operand_res);22565 const uncoerced_operand_ty = sema.typeOf(operand_res);
...@@ -22694,9 +22582,9 @@ fn zirPtrFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!...@@ -22694,9 +22582,9 @@ fn zirPtrFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
2269422582
22695 if (ptr_ty.isSlice(mod)) {22583 if (ptr_ty.isSlice(mod)) {
22696 const msg = msg: {22584 const msg = msg: {
22697 const msg = try sema.errMsg(block, src, "integer cannot be converted to slice type '{}'", .{ptr_ty.fmt(sema.mod)});22585 const msg = try sema.errMsg(src, "integer cannot be converted to slice type '{}'", .{ptr_ty.fmt(sema.mod)});
22698 errdefer msg.destroy(sema.gpa);22586 errdefer msg.destroy(sema.gpa);
22699 try sema.errNote(block, src, msg, "slice length cannot be inferred from address", .{});22587 try sema.errNote(src, msg, "slice length cannot be inferred from address", .{});
22700 break :msg msg;22588 break :msg msg;
22701 };22589 };
22702 return sema.failWithOwnedErrorMsg(block, msg);22590 return sema.failWithOwnedErrorMsg(block, msg);
...@@ -22721,11 +22609,10 @@ fn zirPtrFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!...@@ -22721,11 +22609,10 @@ fn zirPtrFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
22721 }22609 }
22722 if (try sema.typeRequiresComptime(ptr_ty)) {22610 if (try sema.typeRequiresComptime(ptr_ty)) {
22723 return sema.failWithOwnedErrorMsg(block, msg: {22611 return sema.failWithOwnedErrorMsg(block, msg: {
22724 const msg = try sema.errMsg(block, src, "pointer to comptime-only type '{}' must be comptime-known, but operand is runtime-known", .{ptr_ty.fmt(mod)});22612 const msg = try sema.errMsg(src, "pointer to comptime-only type '{}' must be comptime-known, but operand is runtime-known", .{ptr_ty.fmt(mod)});
22725 errdefer msg.destroy(sema.gpa);22613 errdefer msg.destroy(sema.gpa);
2272622614
22727 const src_decl = mod.declPtr(block.src_decl);22615 try sema.explainWhyTypeIsComptime(msg, src, ptr_ty);
22728 try sema.explainWhyTypeIsComptime(msg, src_decl.toSrcLoc(src, mod), ptr_ty);
22729 break :msg msg;22616 break :msg msg;
22730 });22617 });
22731 }22618 }
...@@ -22810,8 +22697,8 @@ fn zirErrorCast(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData...@@ -22810,8 +22697,8 @@ fn zirErrorCast(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData
22810 const mod = sema.mod;22697 const mod = sema.mod;
22811 const ip = &mod.intern_pool;22698 const ip = &mod.intern_pool;
22812 const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data;22699 const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data;
22813 const src = LazySrcLoc.nodeOffset(extra.node);22700 const src = block.nodeOffset(extra.node);
22814 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node };22701 const operand_src = block.builtinCallArgSrc(extra.node, 0);
22815 const base_dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_opt, "@errorCast");22702 const base_dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_opt, "@errorCast");
22816 const operand = try sema.resolveInst(extra.rhs);22703 const operand = try sema.resolveInst(extra.rhs);
22817 const base_operand_ty = sema.typeOf(operand);22704 const base_operand_ty = sema.typeOf(operand);
...@@ -22831,12 +22718,12 @@ fn zirErrorCast(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData...@@ -22831,12 +22718,12 @@ fn zirErrorCast(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData
22831 base_dest_ty.errorUnionPayload(mod).toIntern() != base_operand_ty.errorUnionPayload(mod).toIntern())22718 base_dest_ty.errorUnionPayload(mod).toIntern() != base_operand_ty.errorUnionPayload(mod).toIntern())
22832 {22719 {
22833 return sema.failWithOwnedErrorMsg(block, msg: {22720 return sema.failWithOwnedErrorMsg(block, msg: {
22834 const msg = try sema.errMsg(block, src, "payload types of error unions must match", .{});22721 const msg = try sema.errMsg(src, "payload types of error unions must match", .{});
22835 errdefer msg.destroy(sema.gpa);22722 errdefer msg.destroy(sema.gpa);
22836 const dest_ty = base_dest_ty.errorUnionPayload(mod);22723 const dest_ty = base_dest_ty.errorUnionPayload(mod);
22837 const operand_ty = base_operand_ty.errorUnionPayload(mod);22724 const operand_ty = base_operand_ty.errorUnionPayload(mod);
22838 try sema.errNote(block, src, msg, "destination payload is '{}'", .{dest_ty.fmt(mod)});22725 try sema.errNote(src, msg, "destination payload is '{}'", .{dest_ty.fmt(mod)});
22839 try sema.errNote(block, src, msg, "operand payload is '{}'", .{operand_ty.fmt(mod)});22726 try sema.errNote(src, msg, "operand payload is '{}'", .{operand_ty.fmt(mod)});
22840 try addDeclaredHereNote(sema, msg, dest_ty);22727 try addDeclaredHereNote(sema, msg, dest_ty);
22841 try addDeclaredHereNote(sema, msg, operand_ty);22728 try addDeclaredHereNote(sema, msg, operand_ty);
22842 break :msg msg;22729 break :msg msg;
...@@ -22935,8 +22822,8 @@ fn zirPtrCastFull(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDa...@@ -22935,8 +22822,8 @@ fn zirPtrCastFull(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDa
22935 const FlagsInt = @typeInfo(Zir.Inst.FullPtrCastFlags).Struct.backing_integer.?;22822 const FlagsInt = @typeInfo(Zir.Inst.FullPtrCastFlags).Struct.backing_integer.?;
22936 const flags: Zir.Inst.FullPtrCastFlags = @bitCast(@as(FlagsInt, @truncate(extended.small)));22823 const flags: Zir.Inst.FullPtrCastFlags = @bitCast(@as(FlagsInt, @truncate(extended.small)));
22937 const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data;22824 const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data;
22938 const src = LazySrcLoc.nodeOffset(extra.node);22825 const src = block.nodeOffset(extra.node);
22939 const operand_src: LazySrcLoc = .{ .node_offset_ptrcast_operand = extra.node };22826 const operand_src = block.src(.{ .node_offset_ptrcast_operand = extra.node });
22940 const operand = try sema.resolveInst(extra.rhs);22827 const operand = try sema.resolveInst(extra.rhs);
22941 const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu, flags.needResultTypeBuiltinName());22828 const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu, flags.needResultTypeBuiltinName());
22942 return sema.ptrCastFull(22829 return sema.ptrCastFull(
...@@ -22953,7 +22840,7 @@ fn zirPtrCastFull(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDa...@@ -22953,7 +22840,7 @@ fn zirPtrCastFull(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDa
22953fn zirPtrCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {22840fn zirPtrCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
22954 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;22841 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
22955 const src = block.nodeOffset(inst_data.src_node);22842 const src = block.nodeOffset(inst_data.src_node);
22956 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };22843 const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0);
22957 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;22844 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
22958 const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu, "@ptrCast");22845 const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu, "@ptrCast");
22959 const operand = try sema.resolveInst(extra.rhs);22846 const operand = try sema.resolveInst(extra.rhs);
...@@ -23023,7 +22910,7 @@ fn ptrCastFull(...@@ -23023,7 +22910,7 @@ fn ptrCastFull(
23023 if (src_info.flags.size == .C) break :check_size;22910 if (src_info.flags.size == .C) break :check_size;
23024 if (dest_info.flags.size == .C) break :check_size;22911 if (dest_info.flags.size == .C) break :check_size;
23025 return sema.failWithOwnedErrorMsg(block, msg: {22912 return sema.failWithOwnedErrorMsg(block, msg: {
23026 const msg = try sema.errMsg(block, src, "cannot implicitly convert {s} pointer to {s} pointer", .{22913 const msg = try sema.errMsg(src, "cannot implicitly convert {s} pointer to {s} pointer", .{
23027 pointerSizeString(src_info.flags.size),22914 pointerSizeString(src_info.flags.size),
23028 pointerSizeString(dest_info.flags.size),22915 pointerSizeString(dest_info.flags.size),
23029 });22916 });
...@@ -23032,9 +22919,9 @@ fn ptrCastFull(...@@ -23032,9 +22919,9 @@ fn ptrCastFull(
23032 (src_info.flags.size == .Slice or22919 (src_info.flags.size == .Slice or
23033 (src_info.flags.size == .One and Type.fromInterned(src_info.child).zigTypeTag(mod) == .Array)))22920 (src_info.flags.size == .One and Type.fromInterned(src_info.child).zigTypeTag(mod) == .Array)))
23034 {22921 {
23035 try sema.errNote(block, src, msg, "use 'ptr' field to convert slice to many pointer", .{});22922 try sema.errNote(src, msg, "use 'ptr' field to convert slice to many pointer", .{});
23036 } else {22923 } else {
23037 try sema.errNote(block, src, msg, "use @ptrCast to change pointer size", .{});22924 try sema.errNote(src, msg, "use @ptrCast to change pointer size", .{});
23038 }22925 }
23039 break :msg msg;22926 break :msg msg;
23040 });22927 });
...@@ -23059,13 +22946,13 @@ fn ptrCastFull(...@@ -23059,13 +22946,13 @@ fn ptrCastFull(
23059 );22946 );
23060 if (imc_res == .ok) break :check_child;22947 if (imc_res == .ok) break :check_child;
23061 return sema.failWithOwnedErrorMsg(block, msg: {22948 return sema.failWithOwnedErrorMsg(block, msg: {
23062 const msg = try sema.errMsg(block, src, "pointer element type '{}' cannot coerce into element type '{}'", .{22949 const msg = try sema.errMsg(src, "pointer element type '{}' cannot coerce into element type '{}'", .{
23063 src_child.fmt(mod),22950 src_child.fmt(mod),
23064 dest_child.fmt(mod),22951 dest_child.fmt(mod),
23065 });22952 });
23066 errdefer msg.destroy(sema.gpa);22953 errdefer msg.destroy(sema.gpa);
23067 try imc_res.report(sema, block, src, msg);22954 try imc_res.report(sema, src, msg);
23068 try sema.errNote(block, src, msg, "use @ptrCast to cast pointer element type", .{});22955 try sema.errNote(src, msg, "use @ptrCast to cast pointer element type", .{});
23069 break :msg msg;22956 break :msg msg;
23070 });22957 });
23071 }22958 }
...@@ -23087,41 +22974,41 @@ fn ptrCastFull(...@@ -23087,41 +22974,41 @@ fn ptrCastFull(
23087 }22974 }
23088 return sema.failWithOwnedErrorMsg(block, msg: {22975 return sema.failWithOwnedErrorMsg(block, msg: {
23089 const msg = if (src_info.sentinel == .none) blk: {22976 const msg = if (src_info.sentinel == .none) blk: {
23090 break :blk try sema.errMsg(block, src, "destination pointer requires '{}' sentinel", .{22977 break :blk try sema.errMsg(src, "destination pointer requires '{}' sentinel", .{
23091 Value.fromInterned(dest_info.sentinel).fmtValue(mod, sema),22978 Value.fromInterned(dest_info.sentinel).fmtValue(mod, sema),
23092 });22979 });
23093 } else blk: {22980 } else blk: {
23094 break :blk try sema.errMsg(block, src, "pointer sentinel '{}' cannot coerce into pointer sentinel '{}'", .{22981 break :blk try sema.errMsg(src, "pointer sentinel '{}' cannot coerce into pointer sentinel '{}'", .{
23095 Value.fromInterned(src_info.sentinel).fmtValue(mod, sema),22982 Value.fromInterned(src_info.sentinel).fmtValue(mod, sema),
23096 Value.fromInterned(dest_info.sentinel).fmtValue(mod, sema),22983 Value.fromInterned(dest_info.sentinel).fmtValue(mod, sema),
23097 });22984 });
23098 };22985 };
23099 errdefer msg.destroy(sema.gpa);22986 errdefer msg.destroy(sema.gpa);
23100 try sema.errNote(block, src, msg, "use @ptrCast to cast pointer sentinel", .{});22987 try sema.errNote(src, msg, "use @ptrCast to cast pointer sentinel", .{});
23101 break :msg msg;22988 break :msg msg;
23102 });22989 });
23103 }22990 }
2310422991
23105 if (src_info.packed_offset.host_size != dest_info.packed_offset.host_size) {22992 if (src_info.packed_offset.host_size != dest_info.packed_offset.host_size) {
23106 return sema.failWithOwnedErrorMsg(block, msg: {22993 return sema.failWithOwnedErrorMsg(block, msg: {
23107 const msg = try sema.errMsg(block, src, "pointer host size '{}' cannot coerce into pointer host size '{}'", .{22994 const msg = try sema.errMsg(src, "pointer host size '{}' cannot coerce into pointer host size '{}'", .{
23108 src_info.packed_offset.host_size,22995 src_info.packed_offset.host_size,
23109 dest_info.packed_offset.host_size,22996 dest_info.packed_offset.host_size,
23110 });22997 });
23111 errdefer msg.destroy(sema.gpa);22998 errdefer msg.destroy(sema.gpa);
23112 try sema.errNote(block, src, msg, "use @ptrCast to cast pointer host size", .{});22999 try sema.errNote(src, msg, "use @ptrCast to cast pointer host size", .{});
23113 break :msg msg;23000 break :msg msg;
23114 });23001 });
23115 }23002 }
2311623003
23117 if (src_info.packed_offset.bit_offset != dest_info.packed_offset.bit_offset) {23004 if (src_info.packed_offset.bit_offset != dest_info.packed_offset.bit_offset) {
23118 return sema.failWithOwnedErrorMsg(block, msg: {23005 return sema.failWithOwnedErrorMsg(block, msg: {
23119 const msg = try sema.errMsg(block, src, "pointer bit offset '{}' cannot coerce into pointer bit offset '{}'", .{23006 const msg = try sema.errMsg(src, "pointer bit offset '{}' cannot coerce into pointer bit offset '{}'", .{
23120 src_info.packed_offset.bit_offset,23007 src_info.packed_offset.bit_offset,
23121 dest_info.packed_offset.bit_offset,23008 dest_info.packed_offset.bit_offset,
23122 });23009 });
23123 errdefer msg.destroy(sema.gpa);23010 errdefer msg.destroy(sema.gpa);
23124 try sema.errNote(block, src, msg, "use @ptrCast to cast pointer bit offset", .{});23011 try sema.errNote(src, msg, "use @ptrCast to cast pointer bit offset", .{});
23125 break :msg msg;23012 break :msg msg;
23126 });23013 });
23127 }23014 }
...@@ -23133,12 +23020,12 @@ fn ptrCastFull(...@@ -23133,12 +23020,12 @@ fn ptrCastFull(
23133 if (dest_allows_zero) break :check_allowzero;23020 if (dest_allows_zero) break :check_allowzero;
2313423021
23135 return sema.failWithOwnedErrorMsg(block, msg: {23022 return sema.failWithOwnedErrorMsg(block, msg: {
23136 const msg = try sema.errMsg(block, src, "'{}' could have null values which are illegal in type '{}'", .{23023 const msg = try sema.errMsg(src, "'{}' could have null values which are illegal in type '{}'", .{
23137 operand_ty.fmt(mod),23024 operand_ty.fmt(mod),
23138 dest_ty.fmt(mod),23025 dest_ty.fmt(mod),
23139 });23026 });
23140 errdefer msg.destroy(sema.gpa);23027 errdefer msg.destroy(sema.gpa);
23141 try sema.errNote(block, src, msg, "use @ptrCast to assert the pointer is not null", .{});23028 try sema.errNote(src, msg, "use @ptrCast to assert the pointer is not null", .{});
23142 break :msg msg;23029 break :msg msg;
23143 });23030 });
23144 }23031 }
...@@ -23159,15 +23046,15 @@ fn ptrCastFull(...@@ -23159,15 +23046,15 @@ fn ptrCastFull(
23159 if (!flags.align_cast) {23046 if (!flags.align_cast) {
23160 if (dest_align.compare(.gt, src_align)) {23047 if (dest_align.compare(.gt, src_align)) {
23161 return sema.failWithOwnedErrorMsg(block, msg: {23048 return sema.failWithOwnedErrorMsg(block, msg: {
23162 const msg = try sema.errMsg(block, src, "{s} increases pointer alignment", .{operation});23049 const msg = try sema.errMsg(src, "{s} increases pointer alignment", .{operation});
23163 errdefer msg.destroy(sema.gpa);23050 errdefer msg.destroy(sema.gpa);
23164 try sema.errNote(block, operand_src, msg, "'{}' has alignment '{d}'", .{23051 try sema.errNote(operand_src, msg, "'{}' has alignment '{d}'", .{
23165 operand_ty.fmt(mod), src_align.toByteUnits() orelse 0,23052 operand_ty.fmt(mod), src_align.toByteUnits() orelse 0,
23166 });23053 });
23167 try sema.errNote(block, src, msg, "'{}' has alignment '{d}'", .{23054 try sema.errNote(src, msg, "'{}' has alignment '{d}'", .{
23168 dest_ty.fmt(mod), dest_align.toByteUnits() orelse 0,23055 dest_ty.fmt(mod), dest_align.toByteUnits() orelse 0,
23169 });23056 });
23170 try sema.errNote(block, src, msg, "use @alignCast to assert pointer alignment", .{});23057 try sema.errNote(src, msg, "use @alignCast to assert pointer alignment", .{});
23171 break :msg msg;23058 break :msg msg;
23172 });23059 });
23173 }23060 }
...@@ -23176,15 +23063,15 @@ fn ptrCastFull(...@@ -23176,15 +23063,15 @@ fn ptrCastFull(
23176 if (!flags.addrspace_cast) {23063 if (!flags.addrspace_cast) {
23177 if (src_info.flags.address_space != dest_info.flags.address_space) {23064 if (src_info.flags.address_space != dest_info.flags.address_space) {
23178 return sema.failWithOwnedErrorMsg(block, msg: {23065 return sema.failWithOwnedErrorMsg(block, msg: {
23179 const msg = try sema.errMsg(block, src, "{s} changes pointer address space", .{operation});23066 const msg = try sema.errMsg(src, "{s} changes pointer address space", .{operation});
23180 errdefer msg.destroy(sema.gpa);23067 errdefer msg.destroy(sema.gpa);
23181 try sema.errNote(block, operand_src, msg, "'{}' has address space '{s}'", .{23068 try sema.errNote(operand_src, msg, "'{}' has address space '{s}'", .{
23182 operand_ty.fmt(mod), @tagName(src_info.flags.address_space),23069 operand_ty.fmt(mod), @tagName(src_info.flags.address_space),
23183 });23070 });
23184 try sema.errNote(block, src, msg, "'{}' has address space '{s}'", .{23071 try sema.errNote(src, msg, "'{}' has address space '{s}'", .{
23185 dest_ty.fmt(mod), @tagName(dest_info.flags.address_space),23072 dest_ty.fmt(mod), @tagName(dest_info.flags.address_space),
23186 });23073 });
23187 try sema.errNote(block, src, msg, "use @addrSpaceCast to cast pointer address space", .{});23074 try sema.errNote(src, msg, "use @addrSpaceCast to cast pointer address space", .{});
23188 break :msg msg;23075 break :msg msg;
23189 });23076 });
23190 }23077 }
...@@ -23192,9 +23079,9 @@ fn ptrCastFull(...@@ -23192,9 +23079,9 @@ fn ptrCastFull(
23192 // Some address space casts are always disallowed23079 // Some address space casts are always disallowed
23193 if (!target_util.addrSpaceCastIsValid(mod.getTarget(), src_info.flags.address_space, dest_info.flags.address_space)) {23080 if (!target_util.addrSpaceCastIsValid(mod.getTarget(), src_info.flags.address_space, dest_info.flags.address_space)) {
23194 return sema.failWithOwnedErrorMsg(block, msg: {23081 return sema.failWithOwnedErrorMsg(block, msg: {
23195 const msg = try sema.errMsg(block, src, "invalid address space cast", .{});23082 const msg = try sema.errMsg(src, "invalid address space cast", .{});
23196 errdefer msg.destroy(sema.gpa);23083 errdefer msg.destroy(sema.gpa);
23197 try sema.errNote(block, operand_src, msg, "address space '{s}' is not compatible with address space '{s}'", .{23084 try sema.errNote(operand_src, msg, "address space '{s}' is not compatible with address space '{s}'", .{
23198 @tagName(src_info.flags.address_space),23085 @tagName(src_info.flags.address_space),
23199 @tagName(dest_info.flags.address_space),23086 @tagName(dest_info.flags.address_space),
23200 });23087 });
...@@ -23206,9 +23093,9 @@ fn ptrCastFull(...@@ -23206,9 +23093,9 @@ fn ptrCastFull(
23206 if (!flags.const_cast) {23093 if (!flags.const_cast) {
23207 if (src_info.flags.is_const and !dest_info.flags.is_const) {23094 if (src_info.flags.is_const and !dest_info.flags.is_const) {
23208 return sema.failWithOwnedErrorMsg(block, msg: {23095 return sema.failWithOwnedErrorMsg(block, msg: {
23209 const msg = try sema.errMsg(block, src, "{s} discards const qualifier", .{operation});23096 const msg = try sema.errMsg(src, "{s} discards const qualifier", .{operation});
23210 errdefer msg.destroy(sema.gpa);23097 errdefer msg.destroy(sema.gpa);
23211 try sema.errNote(block, src, msg, "use @constCast to discard const qualifier", .{});23098 try sema.errNote(src, msg, "use @constCast to discard const qualifier", .{});
23212 break :msg msg;23099 break :msg msg;
23213 });23100 });
23214 }23101 }
...@@ -23217,9 +23104,9 @@ fn ptrCastFull(...@@ -23217,9 +23104,9 @@ fn ptrCastFull(
23217 if (!flags.volatile_cast) {23104 if (!flags.volatile_cast) {
23218 if (src_info.flags.is_volatile and !dest_info.flags.is_volatile) {23105 if (src_info.flags.is_volatile and !dest_info.flags.is_volatile) {
23219 return sema.failWithOwnedErrorMsg(block, msg: {23106 return sema.failWithOwnedErrorMsg(block, msg: {
23220 const msg = try sema.errMsg(block, src, "{s} discards volatile qualifier", .{operation});23107 const msg = try sema.errMsg(src, "{s} discards volatile qualifier", .{operation});
23221 errdefer msg.destroy(sema.gpa);23108 errdefer msg.destroy(sema.gpa);
23222 try sema.errNote(block, src, msg, "use @volatileCast to discard volatile qualifier", .{});23109 try sema.errNote(src, msg, "use @volatileCast to discard volatile qualifier", .{});
23223 break :msg msg;23110 break :msg msg;
23224 });23111 });
23225 }23112 }
...@@ -23368,8 +23255,8 @@ fn zirPtrCastNoDest(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.Inst...@@ -23368,8 +23255,8 @@ fn zirPtrCastNoDest(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.Inst
23368 const FlagsInt = @typeInfo(Zir.Inst.FullPtrCastFlags).Struct.backing_integer.?;23255 const FlagsInt = @typeInfo(Zir.Inst.FullPtrCastFlags).Struct.backing_integer.?;
23369 const flags: Zir.Inst.FullPtrCastFlags = @bitCast(@as(FlagsInt, @truncate(extended.small)));23256 const flags: Zir.Inst.FullPtrCastFlags = @bitCast(@as(FlagsInt, @truncate(extended.small)));
23370 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;23257 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;
23371 const src = LazySrcLoc.nodeOffset(extra.node);23258 const src = block.nodeOffset(extra.node);
23372 const operand_src: LazySrcLoc = .{ .node_offset_ptrcast_operand = extra.node };23259 const operand_src = block.src(.{ .node_offset_ptrcast_operand = extra.node });
23373 const operand = try sema.resolveInst(extra.operand);23260 const operand = try sema.resolveInst(extra.operand);
23374 const operand_ty = sema.typeOf(operand);23261 const operand_ty = sema.typeOf(operand);
23375 try sema.checkPtrOperand(block, operand_src, operand_ty);23262 try sema.checkPtrOperand(block, operand_src, operand_ty);
...@@ -23400,7 +23287,7 @@ fn zirTruncate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -23400,7 +23287,7 @@ fn zirTruncate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
23400 const mod = sema.mod;23287 const mod = sema.mod;
23401 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;23288 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
23402 const src = block.nodeOffset(inst_data.src_node);23289 const src = block.nodeOffset(inst_data.src_node);
23403 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };23290 const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0);
23404 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;23291 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
23405 const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu_opt, "@truncate");23292 const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu_opt, "@truncate");
23406 const dest_scalar_ty = try sema.checkIntOrVectorAllowComptime(block, dest_ty, src);23293 const dest_scalar_ty = try sema.checkIntOrVectorAllowComptime(block, dest_ty, src);
...@@ -23438,16 +23325,15 @@ fn zirTruncate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -23438,16 +23325,15 @@ fn zirTruncate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
23438 if (operand_info.bits < dest_info.bits) {23325 if (operand_info.bits < dest_info.bits) {
23439 const msg = msg: {23326 const msg = msg: {
23440 const msg = try sema.errMsg(23327 const msg = try sema.errMsg(
23441 block,
23442 src,23328 src,
23443 "destination type '{}' has more bits than source type '{}'",23329 "destination type '{}' has more bits than source type '{}'",
23444 .{ dest_ty.fmt(mod), operand_ty.fmt(mod) },23330 .{ dest_ty.fmt(mod), operand_ty.fmt(mod) },
23445 );23331 );
23446 errdefer msg.destroy(sema.gpa);23332 errdefer msg.destroy(sema.gpa);
23447 try sema.errNote(block, src, msg, "destination type has {d} bits", .{23333 try sema.errNote(src, msg, "destination type has {d} bits", .{
23448 dest_info.bits,23334 dest_info.bits,
23449 });23335 });
23450 try sema.errNote(block, operand_src, msg, "operand type has {d} bits", .{23336 try sema.errNote(operand_src, msg, "operand type has {d} bits", .{
23451 operand_info.bits,23337 operand_info.bits,
23452 });23338 });
23453 break :msg msg;23339 break :msg msg;
...@@ -23490,7 +23376,7 @@ fn zirBitCount(...@@ -23490,7 +23376,7 @@ fn zirBitCount(
23490 const mod = sema.mod;23376 const mod = sema.mod;
23491 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;23377 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
23492 const src = block.nodeOffset(inst_data.src_node);23378 const src = block.nodeOffset(inst_data.src_node);
23493 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };23379 const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0);
23494 const operand = try sema.resolveInst(inst_data.operand);23380 const operand = try sema.resolveInst(inst_data.operand);
23495 const operand_ty = sema.typeOf(operand);23381 const operand_ty = sema.typeOf(operand);
23496 _ = try sema.checkIntOrVector(block, operand, operand_src);23382 _ = try sema.checkIntOrVector(block, operand, operand_src);
...@@ -23544,7 +23430,7 @@ fn zirByteSwap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -23544,7 +23430,7 @@ fn zirByteSwap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
23544 const mod = sema.mod;23430 const mod = sema.mod;
23545 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;23431 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
23546 const src = block.nodeOffset(inst_data.src_node);23432 const src = block.nodeOffset(inst_data.src_node);
23547 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };23433 const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0);
23548 const operand = try sema.resolveInst(inst_data.operand);23434 const operand = try sema.resolveInst(inst_data.operand);
23549 const operand_ty = sema.typeOf(operand);23435 const operand_ty = sema.typeOf(operand);
23550 const scalar_ty = try sema.checkIntOrVector(block, operand, operand_src);23436 const scalar_ty = try sema.checkIntOrVector(block, operand, operand_src);
...@@ -23600,7 +23486,7 @@ fn zirByteSwap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -23600,7 +23486,7 @@ fn zirByteSwap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
23600fn zirBitReverse(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {23486fn zirBitReverse(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
23601 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;23487 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node;
23602 const src = block.nodeOffset(inst_data.src_node);23488 const src = block.nodeOffset(inst_data.src_node);
23603 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };23489 const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0);
23604 const operand = try sema.resolveInst(inst_data.operand);23490 const operand = try sema.resolveInst(inst_data.operand);
23605 const operand_ty = sema.typeOf(operand);23491 const operand_ty = sema.typeOf(operand);
23606 const scalar_ty = try sema.checkIntOrVector(block, operand, operand_src);23492 const scalar_ty = try sema.checkIntOrVector(block, operand, operand_src);
...@@ -23658,9 +23544,9 @@ fn zirOffsetOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -23658,9 +23544,9 @@ fn zirOffsetOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
2365823544
23659fn bitOffsetOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!u64 {23545fn bitOffsetOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!u64 {
23660 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;23546 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
23661 const src: LazySrcLoc = .{ .node_offset_bin_op = inst_data.src_node };23547 const src = block.src(.{ .node_offset_bin_op = inst_data.src_node });
23662 const lhs_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };23548 const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node });
23663 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };23549 const rhs_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node });
23664 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;23550 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
2366523551
23666 const ty = try sema.resolveType(block, lhs_src, extra.lhs);23552 const ty = try sema.resolveType(block, lhs_src, extra.lhs);
...@@ -23773,14 +23659,13 @@ fn checkPtrOperand(...@@ -23773,14 +23659,13 @@ fn checkPtrOperand(
23773 .Fn => {23659 .Fn => {
23774 const msg = msg: {23660 const msg = msg: {
23775 const msg = try sema.errMsg(23661 const msg = try sema.errMsg(
23776 block,
23777 ty_src,23662 ty_src,
23778 "expected pointer, found '{}'",23663 "expected pointer, found '{}'",
23779 .{ty.fmt(mod)},23664 .{ty.fmt(mod)},
23780 );23665 );
23781 errdefer msg.destroy(sema.gpa);23666 errdefer msg.destroy(sema.gpa);
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
23785 break :msg msg;23670 break :msg msg;
23786 };23671 };
...@@ -23805,14 +23690,13 @@ fn checkPtrType(...@@ -23805,14 +23690,13 @@ fn checkPtrType(
23805 .Fn => {23690 .Fn => {
23806 const msg = msg: {23691 const msg = msg: {
23807 const msg = try sema.errMsg(23692 const msg = try sema.errMsg(
23808 block,
23809 ty_src,23693 ty_src,
23810 "expected pointer type, found '{}'",23694 "expected pointer type, found '{}'",
23811 .{ty.fmt(mod)},23695 .{ty.fmt(mod)},
23812 );23696 );
23813 errdefer msg.destroy(sema.gpa);23697 errdefer msg.destroy(sema.gpa);
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
23817 break :msg msg;23701 break :msg msg;
23818 };23702 };
...@@ -24066,26 +23950,26 @@ fn checkVectorizableBinaryOperands(...@@ -24066,26 +23950,26 @@ fn checkVectorizableBinaryOperands(
24066 const rhs_len = rhs_ty.arrayLen(mod);23950 const rhs_len = rhs_ty.arrayLen(mod);
24067 if (lhs_len != rhs_len) {23951 if (lhs_len != rhs_len) {
24068 const msg = msg: {23952 const msg = msg: {
24069 const msg = try sema.errMsg(block, src, "vector length mismatch", .{});23953 const msg = try sema.errMsg(src, "vector length mismatch", .{});
24070 errdefer msg.destroy(sema.gpa);23954 errdefer msg.destroy(sema.gpa);
24071 try sema.errNote(block, lhs_src, msg, "length {d} here", .{lhs_len});23955 try sema.errNote(lhs_src, msg, "length {d} here", .{lhs_len});
24072 try sema.errNote(block, rhs_src, msg, "length {d} here", .{rhs_len});23956 try sema.errNote(rhs_src, msg, "length {d} here", .{rhs_len});
24073 break :msg msg;23957 break :msg msg;
24074 };23958 };
24075 return sema.failWithOwnedErrorMsg(block, msg);23959 return sema.failWithOwnedErrorMsg(block, msg);
24076 }23960 }
24077 } else {23961 } else {
24078 const msg = msg: {23962 const msg = msg: {
24079 const msg = try sema.errMsg(block, src, "mixed scalar and vector operands: '{}' and '{}'", .{23963 const msg = try sema.errMsg(src, "mixed scalar and vector operands: '{}' and '{}'", .{
24080 lhs_ty.fmt(mod), rhs_ty.fmt(mod),23964 lhs_ty.fmt(mod), rhs_ty.fmt(mod),
24081 });23965 });
24082 errdefer msg.destroy(sema.gpa);23966 errdefer msg.destroy(sema.gpa);
24083 if (lhs_is_vector) {23967 if (lhs_is_vector) {
24084 try sema.errNote(block, lhs_src, msg, "vector here", .{});23968 try sema.errNote(lhs_src, msg, "vector here", .{});
24085 try sema.errNote(block, rhs_src, msg, "scalar here", .{});23969 try sema.errNote(rhs_src, msg, "scalar here", .{});
24086 } else {23970 } else {
24087 try sema.errNote(block, lhs_src, msg, "scalar here", .{});23971 try sema.errNote(lhs_src, msg, "scalar here", .{});
24088 try sema.errNote(block, rhs_src, msg, "vector here", .{});23972 try sema.errNote(rhs_src, msg, "vector here", .{});
24089 }23973 }
24090 break :msg msg;23974 break :msg msg;
24091 };23975 };
...@@ -24093,12 +23977,6 @@ fn checkVectorizableBinaryOperands(...@@ -24093,12 +23977,6 @@ fn checkVectorizableBinaryOperands(
24093 }23977 }
24094}23978}
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
24102fn resolveExportOptions(23980fn resolveExportOptions(
24103 sema: *Sema,23981 sema: *Sema,
24104 block: *Block,23982 block: *Block,
...@@ -24112,10 +23990,10 @@ fn resolveExportOptions(...@@ -24112,10 +23990,10 @@ fn resolveExportOptions(
24112 const air_ref = try sema.resolveInst(zir_ref);23990 const air_ref = try sema.resolveInst(zir_ref);
24113 const options = try sema.coerce(block, export_options_ty, air_ref, src);23991 const options = try sema.coerce(block, export_options_ty, air_ref, src);
2411423992
24115 const name_src = sema.maybeOptionsSrc(block, src, "name");23993 const name_src = block.src(.{ .init_field_name = src.offset.node_offset_builtin_call_arg.builtin_call_node });
24116 const linkage_src = sema.maybeOptionsSrc(block, src, "linkage");23994 const linkage_src = block.src(.{ .init_field_linkage = src.offset.node_offset_builtin_call_arg.builtin_call_node });
24117 const section_src = sema.maybeOptionsSrc(block, src, "section");23995 const section_src = block.src(.{ .init_field_section = src.offset.node_offset_builtin_call_arg.builtin_call_node });
24118 const visibility_src = sema.maybeOptionsSrc(block, src, "visibility");23996 const visibility_src = block.src(.{ .init_field_visibility = src.offset.node_offset_builtin_call_arg.builtin_call_node });
2411923997
24120 const name_operand = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "name", .no_embedded_nulls), name_src);23998 const name_operand = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "name", .no_embedded_nulls), name_src);
24121 const name = try sema.toConstString(block, name_src, name_operand, .{23999 const name = try sema.toConstString(block, name_src, name_operand, .{
...@@ -24212,14 +24090,14 @@ fn zirCmpxchg(...@@ -24212,14 +24090,14 @@ fn zirCmpxchg(
24212 1 => .cmpxchg_strong,24090 1 => .cmpxchg_strong,
24213 else => unreachable,24091 else => unreachable,
24214 };24092 };
24215 const src = LazySrcLoc.nodeOffset(extra.node);24093 const src = block.nodeOffset(extra.node);
24216 // zig fmt: off24094 // zig fmt: off
24217 const elem_ty_src : LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node };24095 const elem_ty_src = block.builtinCallArgSrc(extra.node, 0);
24218 const ptr_src : LazySrcLoc = .{ .node_offset_builtin_call_arg1 = extra.node };24096 const ptr_src = block.builtinCallArgSrc(extra.node, 1);
24219 const expected_src : LazySrcLoc = .{ .node_offset_builtin_call_arg2 = extra.node };24097 const expected_src = block.builtinCallArgSrc(extra.node, 2);
24220 const new_value_src : LazySrcLoc = .{ .node_offset_builtin_call_arg3 = extra.node };24098 const new_value_src = block.builtinCallArgSrc(extra.node, 3);
24221 const success_order_src: LazySrcLoc = .{ .node_offset_builtin_call_arg4 = extra.node };24099 const success_order_src = block.builtinCallArgSrc(extra.node, 4);
24222 const failure_order_src: LazySrcLoc = .{ .node_offset_builtin_call_arg5 = extra.node };24100 const failure_order_src = block.builtinCallArgSrc(extra.node, 5);
24223 // zig fmt: on24101 // zig fmt: on
24224 const expected_value = try sema.resolveInst(extra.expected_value);24102 const expected_value = try sema.resolveInst(extra.expected_value);
24225 const elem_ty = sema.typeOf(expected_value);24103 const elem_ty = sema.typeOf(expected_value);
...@@ -24309,7 +24187,7 @@ fn zirSplat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.I...@@ -24309,7 +24187,7 @@ fn zirSplat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.I
24309 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;24187 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
24310 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;24188 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
24311 const src = block.nodeOffset(inst_data.src_node);24189 const src = block.nodeOffset(inst_data.src_node);
24312 const scalar_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };24190 const scalar_src = block.builtinCallArgSrc(inst_data.src_node, 0);
24313 const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu_opt, "@splat");24191 const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu_opt, "@splat");
2431424192
24315 if (!dest_ty.isVector(mod)) return sema.fail(block, src, "expected vector type, found '{}'", .{dest_ty.fmt(mod)});24193 if (!dest_ty.isVector(mod)) return sema.fail(block, src, "expected vector type, found '{}'", .{dest_ty.fmt(mod)});
...@@ -24337,8 +24215,8 @@ fn zirSplat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.I...@@ -24337,8 +24215,8 @@ fn zirSplat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.I
24337fn zirReduce(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {24215fn zirReduce(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
24338 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;24216 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
24339 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;24217 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
24340 const op_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };24218 const op_src = block.builtinCallArgSrc(inst_data.src_node, 0);
24341 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };24219 const operand_src = block.builtinCallArgSrc(inst_data.src_node, 1);
24342 const operation = try sema.resolveBuiltinEnum(block, op_src, extra.lhs, "ReduceOp", .{24220 const operation = try sema.resolveBuiltinEnum(block, op_src, extra.lhs, "ReduceOp", .{
24343 .needed_comptime_reason = "@reduce operation must be comptime-known",24221 .needed_comptime_reason = "@reduce operation must be comptime-known",
24344 });24222 });
...@@ -24409,8 +24287,8 @@ fn zirShuffle(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air...@@ -24409,8 +24287,8 @@ fn zirShuffle(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
24409 const mod = sema.mod;24287 const mod = sema.mod;
24410 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;24288 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
24411 const extra = sema.code.extraData(Zir.Inst.Shuffle, inst_data.payload_index).data;24289 const extra = sema.code.extraData(Zir.Inst.Shuffle, inst_data.payload_index).data;
24412 const elem_ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };24290 const elem_ty_src = block.builtinCallArgSrc(inst_data.src_node, 0);
24413 const mask_src: LazySrcLoc = .{ .node_offset_builtin_call_arg3 = inst_data.src_node };24291 const mask_src = block.builtinCallArgSrc(inst_data.src_node, 3);
2441424292
24415 const elem_ty = try sema.resolveType(block, elem_ty_src, extra.elem_type);24293 const elem_ty = try sema.resolveType(block, elem_ty_src, extra.elem_type);
24416 try sema.checkVectorElemType(block, elem_ty_src, elem_ty);24294 try sema.checkVectorElemType(block, elem_ty_src, elem_ty);
...@@ -24445,9 +24323,9 @@ fn analyzeShuffle(...@@ -24445,9 +24323,9 @@ fn analyzeShuffle(
24445 mask_len: u32,24323 mask_len: u32,
24446) CompileError!Air.Inst.Ref {24324) CompileError!Air.Inst.Ref {
24447 const mod = sema.mod;24325 const mod = sema.mod;
24448 const a_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = src_node };24326 const a_src = block.builtinCallArgSrc(src_node, 1);
24449 const b_src: LazySrcLoc = .{ .node_offset_builtin_call_arg2 = src_node };24327 const b_src = block.builtinCallArgSrc(src_node, 2);
24450 const mask_src: LazySrcLoc = .{ .node_offset_builtin_call_arg3 = src_node };24328 const mask_src = block.builtinCallArgSrc(src_node, 3);
24451 var a = a_arg;24329 var a = a_arg;
24452 var b = b_arg;24330 var b = b_arg;
2445324331
...@@ -24511,16 +24389,16 @@ fn analyzeShuffle(...@@ -24511,16 +24389,16 @@ fn analyzeShuffle(
24511 }24389 }
24512 if (unsigned >= operand_info[chosen][0]) {24390 if (unsigned >= operand_info[chosen][0]) {
24513 const msg = msg: {24391 const msg = msg: {
24514 const msg = try sema.errMsg(block, mask_src, "mask index '{d}' has out-of-bounds selection", .{i});24392 const msg = try sema.errMsg(mask_src, "mask index '{d}' has out-of-bounds selection", .{i});
24515 errdefer msg.destroy(sema.gpa);24393 errdefer msg.destroy(sema.gpa);
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 '{}'", .{
24518 unsigned,24396 unsigned,
24519 operand_info[chosen][2].fmt(sema.mod),24397 operand_info[chosen][2].fmt(sema.mod),
24520 });24398 });
2452124399
24522 if (chosen == 0) {24400 if (chosen == 0) {
24523 try sema.errNote(block, b_src, msg, "selections from the second vector are specified with negative numbers", .{});24401 try sema.errNote(b_src, msg, "selections from the second vector are specified with negative numbers", .{});
24524 }24402 }
2452524403
24526 break :msg msg;24404 break :msg msg;
...@@ -24598,11 +24476,11 @@ fn zirSelect(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) C...@@ -24598,11 +24476,11 @@ fn zirSelect(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) C
24598 const mod = sema.mod;24476 const mod = sema.mod;
24599 const extra = sema.code.extraData(Zir.Inst.Select, extended.operand).data;24477 const extra = sema.code.extraData(Zir.Inst.Select, extended.operand).data;
2460024478
24601 const src = LazySrcLoc.nodeOffset(extra.node);24479 const src = block.nodeOffset(extra.node);
24602 const elem_ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node };24480 const elem_ty_src = block.builtinCallArgSrc(extra.node, 0);
24603 const pred_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = extra.node };24481 const pred_src = block.builtinCallArgSrc(extra.node, 1);
24604 const a_src: LazySrcLoc = .{ .node_offset_builtin_call_arg2 = extra.node };24482 const a_src = block.builtinCallArgSrc(extra.node, 2);
24605 const b_src: LazySrcLoc = .{ .node_offset_builtin_call_arg3 = extra.node };24483 const b_src = block.builtinCallArgSrc(extra.node, 3);
2460624484
24607 const elem_ty = try sema.resolveType(block, elem_ty_src, extra.elem_type);24485 const elem_ty = try sema.resolveType(block, elem_ty_src, extra.elem_type);
24608 try sema.checkVectorElemType(block, elem_ty_src, elem_ty);24486 try sema.checkVectorElemType(block, elem_ty_src, elem_ty);
...@@ -24689,9 +24567,9 @@ fn zirAtomicLoad(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!...@@ -24689,9 +24567,9 @@ fn zirAtomicLoad(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
24689 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;24567 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
24690 const extra = sema.code.extraData(Zir.Inst.AtomicLoad, inst_data.payload_index).data;24568 const extra = sema.code.extraData(Zir.Inst.AtomicLoad, inst_data.payload_index).data;
24691 // zig fmt: off24569 // zig fmt: off
24692 const elem_ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };24570 const elem_ty_src = block.builtinCallArgSrc(inst_data.src_node, 0);
24693 const ptr_src : LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };24571 const ptr_src = block.builtinCallArgSrc(inst_data.src_node, 1);
24694 const order_src : LazySrcLoc = .{ .node_offset_builtin_call_arg2 = inst_data.src_node };24572 const order_src = block.builtinCallArgSrc(inst_data.src_node, 2);
24695 // zig fmt: on24573 // zig fmt: on
24696 const elem_ty = try sema.resolveType(block, elem_ty_src, extra.elem_type);24574 const elem_ty = try sema.resolveType(block, elem_ty_src, extra.elem_type);
24697 const uncasted_ptr = try sema.resolveInst(extra.ptr);24575 const uncasted_ptr = try sema.resolveInst(extra.ptr);
...@@ -24738,11 +24616,11 @@ fn zirAtomicRmw(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A...@@ -24738,11 +24616,11 @@ fn zirAtomicRmw(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
24738 const extra = sema.code.extraData(Zir.Inst.AtomicRmw, inst_data.payload_index).data;24616 const extra = sema.code.extraData(Zir.Inst.AtomicRmw, inst_data.payload_index).data;
24739 const src = block.nodeOffset(inst_data.src_node);24617 const src = block.nodeOffset(inst_data.src_node);
24740 // zig fmt: off24618 // zig fmt: off
24741 const elem_ty_src : LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };24619 const elem_ty_src = block.builtinCallArgSrc(inst_data.src_node, 0);
24742 const ptr_src : LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };24620 const ptr_src = block.builtinCallArgSrc(inst_data.src_node, 1);
24743 const op_src : LazySrcLoc = .{ .node_offset_builtin_call_arg2 = inst_data.src_node };24621 const op_src = block.builtinCallArgSrc(inst_data.src_node, 2);
24744 const operand_src : LazySrcLoc = .{ .node_offset_builtin_call_arg3 = inst_data.src_node };24622 const operand_src = block.builtinCallArgSrc(inst_data.src_node, 3);
24745 const order_src : LazySrcLoc = .{ .node_offset_builtin_call_arg4 = inst_data.src_node };24623 const order_src = block.builtinCallArgSrc(inst_data.src_node, 4);
24746 // zig fmt: on24624 // zig fmt: on
24747 const operand = try sema.resolveInst(extra.operand);24625 const operand = try sema.resolveInst(extra.operand);
24748 const elem_ty = sema.typeOf(operand);24626 const elem_ty = sema.typeOf(operand);
...@@ -24823,10 +24701,10 @@ fn zirAtomicStore(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError...@@ -24823,10 +24701,10 @@ fn zirAtomicStore(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
24823 const extra = sema.code.extraData(Zir.Inst.AtomicStore, inst_data.payload_index).data;24701 const extra = sema.code.extraData(Zir.Inst.AtomicStore, inst_data.payload_index).data;
24824 const src = block.nodeOffset(inst_data.src_node);24702 const src = block.nodeOffset(inst_data.src_node);
24825 // zig fmt: off24703 // zig fmt: off
24826 const elem_ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };24704 const elem_ty_src = block.builtinCallArgSrc(inst_data.src_node, 0);
24827 const ptr_src : LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };24705 const ptr_src = block.builtinCallArgSrc(inst_data.src_node, 1);
24828 const operand_src : LazySrcLoc = .{ .node_offset_builtin_call_arg2 = inst_data.src_node };24706 const operand_src = block.builtinCallArgSrc(inst_data.src_node, 2);
24829 const order_src : LazySrcLoc = .{ .node_offset_builtin_call_arg3 = inst_data.src_node };24707 const order_src = block.builtinCallArgSrc(inst_data.src_node, 3);
24830 // zig fmt: on24708 // zig fmt: on
24831 const operand = try sema.resolveInst(extra.operand);24709 const operand = try sema.resolveInst(extra.operand);
24832 const elem_ty = sema.typeOf(operand);24710 const elem_ty = sema.typeOf(operand);
...@@ -24859,9 +24737,9 @@ fn zirMulAdd(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air....@@ -24859,9 +24737,9 @@ fn zirMulAdd(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
24859 const extra = sema.code.extraData(Zir.Inst.MulAdd, inst_data.payload_index).data;24737 const extra = sema.code.extraData(Zir.Inst.MulAdd, inst_data.payload_index).data;
24860 const src = block.nodeOffset(inst_data.src_node);24738 const src = block.nodeOffset(inst_data.src_node);
2486124739
24862 const mulend1_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };24740 const mulend1_src = block.builtinCallArgSrc(inst_data.src_node, 1);
24863 const mulend2_src: LazySrcLoc = .{ .node_offset_builtin_call_arg2 = inst_data.src_node };24741 const mulend2_src = block.builtinCallArgSrc(inst_data.src_node, 2);
24864 const addend_src: LazySrcLoc = .{ .node_offset_builtin_call_arg3 = inst_data.src_node };24742 const addend_src = block.builtinCallArgSrc(inst_data.src_node, 3);
2486524743
24866 const addend = try sema.resolveInst(extra.addend);24744 const addend = try sema.resolveInst(extra.addend);
24867 const ty = sema.typeOf(addend);24745 const ty = sema.typeOf(addend);
...@@ -24924,9 +24802,9 @@ fn zirBuiltinCall(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError...@@ -24924,9 +24802,9 @@ fn zirBuiltinCall(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
2492424802
24925 const mod = sema.mod;24803 const mod = sema.mod;
24926 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;24804 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
24927 const modifier_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };24805 const modifier_src = block.builtinCallArgSrc(inst_data.src_node, 0);
24928 const func_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };24806 const func_src = block.builtinCallArgSrc(inst_data.src_node, 1);
24929 const args_src: LazySrcLoc = .{ .node_offset_builtin_call_arg2 = inst_data.src_node };24807 const args_src = block.builtinCallArgSrc(inst_data.src_node, 2);
24930 const call_src = block.nodeOffset(inst_data.src_node);24808 const call_src = block.nodeOffset(inst_data.src_node);
2493124809
24932 const extra = sema.code.extraData(Zir.Inst.BuiltinCall, inst_data.payload_index).data;24810 const extra = sema.code.extraData(Zir.Inst.BuiltinCall, inst_data.payload_index).data;
...@@ -25022,8 +24900,8 @@ fn zirFieldParentPtr(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.Ins...@@ -25022,8 +24900,8 @@ fn zirFieldParentPtr(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.Ins
25022 const flags: Zir.Inst.FullPtrCastFlags = @bitCast(@as(FlagsInt, @truncate(extended.small)));24900 const flags: Zir.Inst.FullPtrCastFlags = @bitCast(@as(FlagsInt, @truncate(extended.small)));
25023 assert(!flags.ptr_cast);24901 assert(!flags.ptr_cast);
25024 const inst_src = block.nodeOffset(extra.src_node);24902 const inst_src = block.nodeOffset(extra.src_node);
25025 const field_name_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.src_node };24903 const field_name_src = block.builtinCallArgSrc(extra.src_node, 0);
25026 const field_ptr_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = extra.src_node };24904 const field_ptr_src = block.builtinCallArgSrc(extra.src_node, 1);
2502724905
25028 const parent_ptr_ty = try sema.resolveDestType(block, inst_src, extra.parent_ptr_type, .remove_eu, "@fieldParentPtr");24906 const parent_ptr_ty = try sema.resolveDestType(block, inst_src, extra.parent_ptr_type, .remove_eu, "@fieldParentPtr");
25029 try sema.checkPtrType(block, inst_src, parent_ptr_ty, true);24907 try sema.checkPtrType(block, inst_src, parent_ptr_ty, true);
...@@ -25212,9 +25090,9 @@ fn ptrSubtract(sema: *Sema, block: *Block, src: LazySrcLoc, ptr_val: Value, byte...@@ -25212,9 +25090,9 @@ fn ptrSubtract(sema: *Sema, block: *Block, src: LazySrcLoc, ptr_val: Value, byte
25212 };25090 };
25213 if (ptr.byte_offset < byte_subtract) {25091 if (ptr.byte_offset < byte_subtract) {
25214 return sema.failWithOwnedErrorMsg(block, msg: {25092 return sema.failWithOwnedErrorMsg(block, msg: {
25215 const msg = try sema.errMsg(block, src, "pointer computation here causes undefined behavior", .{});25093 const msg = try sema.errMsg(src, "pointer computation here causes undefined behavior", .{});
25216 errdefer msg.destroy(sema.gpa);25094 errdefer msg.destroy(sema.gpa);
25217 try sema.errNote(block, src, msg, "resulting pointer exceeds bounds of containing value which may trigger overflow", .{});25095 try sema.errNote(src, msg, "resulting pointer exceeds bounds of containing value which may trigger overflow", .{});
25218 break :msg msg;25096 break :msg msg;
25219 });25097 });
25220 }25098 }
...@@ -25232,8 +25110,8 @@ fn zirMinMax(...@@ -25232,8 +25110,8 @@ fn zirMinMax(
25232 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;25110 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
25233 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;25111 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
25234 const src = block.nodeOffset(inst_data.src_node);25112 const src = block.nodeOffset(inst_data.src_node);
25235 const lhs_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };25113 const lhs_src = block.builtinCallArgSrc(inst_data.src_node, 0);
25236 const rhs_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };25114 const rhs_src = block.builtinCallArgSrc(inst_data.src_node, 1);
25237 const lhs = try sema.resolveInst(extra.lhs);25115 const lhs = try sema.resolveInst(extra.lhs);
25238 const rhs = try sema.resolveInst(extra.rhs);25116 const rhs = try sema.resolveInst(extra.rhs);
25239 try sema.checkNumericType(block, lhs_src, sema.typeOf(lhs));25117 try sema.checkNumericType(block, lhs_src, sema.typeOf(lhs));
...@@ -25249,22 +25127,14 @@ fn zirMinMaxMulti(...@@ -25249,22 +25127,14 @@ fn zirMinMaxMulti(
25249) CompileError!Air.Inst.Ref {25127) CompileError!Air.Inst.Ref {
25250 const extra = sema.code.extraData(Zir.Inst.NodeMultiOp, extended.operand);25128 const extra = sema.code.extraData(Zir.Inst.NodeMultiOp, extended.operand);
25251 const src_node = extra.data.src_node;25129 const src_node = extra.data.src_node;
25252 const src = LazySrcLoc.nodeOffset(src_node);25130 const src = block.nodeOffset(src_node);
25253 const operands = sema.code.refSlice(extra.end, extended.small);25131 const operands = sema.code.refSlice(extra.end, extended.small);
2525425132
25255 const air_refs = try sema.arena.alloc(Air.Inst.Ref, operands.len);25133 const air_refs = try sema.arena.alloc(Air.Inst.Ref, operands.len);
25256 const operand_srcs = try sema.arena.alloc(LazySrcLoc, operands.len);25134 const operand_srcs = try sema.arena.alloc(LazySrcLoc, operands.len);
2525725135
25258 for (operands, air_refs, operand_srcs, 0..) |zir_ref, *air_ref, *op_src, i| {25136 for (operands, air_refs, operand_srcs, 0..) |zir_ref, *air_ref, *op_src, i| {
25259 op_src.* = switch (i) {25137 op_src.* = block.builtinCallArgSrc(src_node, @intCast(i));
25260 0 => .{ .node_offset_builtin_call_arg0 = src_node },
25261 1 => .{ .node_offset_builtin_call_arg1 = src_node },
25262 2 => .{ .node_offset_builtin_call_arg2 = src_node },
25263 3 => .{ .node_offset_builtin_call_arg3 = src_node },
25264 4 => .{ .node_offset_builtin_call_arg4 = src_node },
25265 5 => .{ .node_offset_builtin_call_arg5 = src_node },
25266 else => src, // TODO: better source location
25267 };
25268 air_ref.* = try sema.resolveInst(zir_ref);25138 air_ref.* = try sema.resolveInst(zir_ref);
25269 try sema.checkNumericType(block, op_src.*, sema.typeOf(air_ref.*));25139 try sema.checkNumericType(block, op_src.*, sema.typeOf(air_ref.*));
25270 }25140 }
...@@ -25533,8 +25403,8 @@ fn zirMemcpy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void...@@ -25533,8 +25403,8 @@ fn zirMemcpy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void
25533 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;25403 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
25534 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;25404 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
25535 const src = block.nodeOffset(inst_data.src_node);25405 const src = block.nodeOffset(inst_data.src_node);
25536 const dest_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };25406 const dest_src = block.builtinCallArgSrc(inst_data.src_node, 0);
25537 const src_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };25407 const src_src = block.builtinCallArgSrc(inst_data.src_node, 1);
25538 const dest_ptr = try sema.resolveInst(extra.lhs);25408 const dest_ptr = try sema.resolveInst(extra.lhs);
25539 const src_ptr = try sema.resolveInst(extra.rhs);25409 const src_ptr = try sema.resolveInst(extra.rhs);
25540 const dest_ty = sema.typeOf(dest_ptr);25410 const dest_ty = sema.typeOf(dest_ptr);
...@@ -25550,12 +25420,12 @@ fn zirMemcpy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void...@@ -25550,12 +25420,12 @@ fn zirMemcpy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void
2555025420
25551 if (dest_len == .none and src_len == .none) {25421 if (dest_len == .none and src_len == .none) {
25552 const msg = msg: {25422 const msg = msg: {
25553 const msg = try sema.errMsg(block, src, "unknown @memcpy length", .{});25423 const msg = try sema.errMsg(src, "unknown @memcpy length", .{});
25554 errdefer msg.destroy(sema.gpa);25424 errdefer msg.destroy(sema.gpa);
25555 try sema.errNote(block, dest_src, msg, "destination type '{}' provides no length", .{25425 try sema.errNote(dest_src, msg, "destination type '{}' provides no length", .{
25556 dest_ty.fmt(sema.mod),25426 dest_ty.fmt(sema.mod),
25557 });25427 });
25558 try sema.errNote(block, src_src, msg, "source type '{}' provides no length", .{25428 try sema.errNote(src_src, msg, "source type '{}' provides no length", .{
25559 src_ty.fmt(sema.mod),25429 src_ty.fmt(sema.mod),
25560 });25430 });
25561 break :msg msg;25431 break :msg msg;
...@@ -25572,12 +25442,12 @@ fn zirMemcpy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void...@@ -25572,12 +25442,12 @@ fn zirMemcpy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void
25572 if (try sema.resolveDefinedValue(block, src_src, src_len)) |src_len_val| {25442 if (try sema.resolveDefinedValue(block, src_src, src_len)) |src_len_val| {
25573 if (!(try sema.valuesEqual(dest_len_val, src_len_val, Type.usize))) {25443 if (!(try sema.valuesEqual(dest_len_val, src_len_val, Type.usize))) {
25574 const msg = msg: {25444 const msg = msg: {
25575 const msg = try sema.errMsg(block, src, "non-matching @memcpy lengths", .{});25445 const msg = try sema.errMsg(src, "non-matching @memcpy lengths", .{});
25576 errdefer msg.destroy(sema.gpa);25446 errdefer msg.destroy(sema.gpa);
25577 try sema.errNote(block, dest_src, msg, "length {} here", .{25447 try sema.errNote(dest_src, msg, "length {} here", .{
25578 dest_len_val.fmtValue(sema.mod, sema),25448 dest_len_val.fmtValue(sema.mod, sema),
25579 });25449 });
25580 try sema.errNote(block, src_src, msg, "length {} here", .{25450 try sema.errNote(src_src, msg, "length {} here", .{
25581 src_len_val.fmtValue(sema.mod, sema),25451 src_len_val.fmtValue(sema.mod, sema),
25582 });25452 });
25583 break :msg msg;25453 break :msg msg;
...@@ -25685,7 +25555,7 @@ fn zirMemcpy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void...@@ -25685,7 +25555,7 @@ fn zirMemcpy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void
25685 } else if (dest_len == .none and len_val == null) {25555 } else if (dest_len == .none and len_val == null) {
25686 // Change the dest to a slice, since its type must have the length.25556 // Change the dest to a slice, since its type must have the length.
25687 const dest_ptr_ptr = try sema.analyzeRef(block, dest_src, new_dest_ptr);25557 const dest_ptr_ptr = try sema.analyzeRef(block, dest_src, new_dest_ptr);
25688 new_dest_ptr = try sema.analyzeSlice(block, dest_src, dest_ptr_ptr, .zero, src_len, .none, .unneeded, dest_src, dest_src, dest_src, false);25558 new_dest_ptr = try sema.analyzeSlice(block, dest_src, dest_ptr_ptr, .zero, src_len, .none, LazySrcLoc.unneeded, dest_src, dest_src, dest_src, false);
25689 const new_src_ptr_ty = sema.typeOf(new_src_ptr);25559 const new_src_ptr_ty = sema.typeOf(new_src_ptr);
25690 if (new_src_ptr_ty.isSlice(mod)) {25560 if (new_src_ptr_ty.isSlice(mod)) {
25691 new_src_ptr = try sema.analyzeSlicePtr(block, src_src, new_src_ptr, new_src_ptr_ty);25561 new_src_ptr = try sema.analyzeSlicePtr(block, src_src, new_src_ptr, new_src_ptr_ty);
...@@ -25753,8 +25623,8 @@ fn zirMemset(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void...@@ -25753,8 +25623,8 @@ fn zirMemset(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void
25753 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;25623 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
25754 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;25624 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
25755 const src = block.nodeOffset(inst_data.src_node);25625 const src = block.nodeOffset(inst_data.src_node);
25756 const dest_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };25626 const dest_src = block.builtinCallArgSrc(inst_data.src_node, 0);
25757 const value_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };25627 const value_src = block.builtinCallArgSrc(inst_data.src_node, 1);
25758 const dest_ptr = try sema.resolveInst(extra.lhs);25628 const dest_ptr = try sema.resolveInst(extra.lhs);
25759 const uncoerced_elem = try sema.resolveInst(extra.rhs);25629 const uncoerced_elem = try sema.resolveInst(extra.rhs);
25760 const dest_ptr_ty = sema.typeOf(dest_ptr);25630 const dest_ptr_ty = sema.typeOf(dest_ptr);
...@@ -25776,9 +25646,9 @@ fn zirMemset(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void...@@ -25776,9 +25646,9 @@ fn zirMemset(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void
25776 .Many, .C => {},25646 .Many, .C => {},
25777 }25647 }
25778 return sema.failWithOwnedErrorMsg(block, msg: {25648 return sema.failWithOwnedErrorMsg(block, msg: {
25779 const msg = try sema.errMsg(block, src, "unknown @memset length", .{});25649 const msg = try sema.errMsg(src, "unknown @memset length", .{});
25780 errdefer msg.destroy(sema.gpa);25650 errdefer msg.destroy(sema.gpa);
25781 try sema.errNote(block, dest_src, msg, "destination type '{}' provides no length", .{25651 try sema.errNote(dest_src, msg, "destination type '{}' provides no length", .{
25782 dest_ptr_ty.fmt(mod),25652 dest_ptr_ty.fmt(mod),
25783 });25653 });
25784 break :msg msg;25654 break :msg msg;
...@@ -25831,7 +25701,7 @@ fn zirMemset(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void...@@ -25831,7 +25701,7 @@ fn zirMemset(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void
2583125701
25832fn zirBuiltinAsyncCall(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!Air.Inst.Ref {25702fn zirBuiltinAsyncCall(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!Air.Inst.Ref {
25833 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;25703 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;
25834 const src = LazySrcLoc.nodeOffset(extra.node);25704 const src = block.nodeOffset(extra.node);
25835 return sema.failWithUseOfAsync(block, src);25705 return sema.failWithUseOfAsync(block, src);
25836}25706}
2583725707
...@@ -25858,7 +25728,7 @@ fn zirAwaitNosuspend(...@@ -25858,7 +25728,7 @@ fn zirAwaitNosuspend(
25858 extended: Zir.Inst.Extended.InstData,25728 extended: Zir.Inst.Extended.InstData,
25859) CompileError!Air.Inst.Ref {25729) CompileError!Air.Inst.Ref {
25860 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;25730 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;
25861 const src = LazySrcLoc.nodeOffset(extra.node);25731 const src = block.nodeOffset(extra.node);
2586225732
25863 return sema.failWithUseOfAsync(block, src);25733 return sema.failWithUseOfAsync(block, src);
25864}25734}
...@@ -25870,8 +25740,8 @@ fn zirVarExtended(...@@ -25870,8 +25740,8 @@ fn zirVarExtended(
25870) CompileError!Air.Inst.Ref {25740) CompileError!Air.Inst.Ref {
25871 const mod = sema.mod;25741 const mod = sema.mod;
25872 const extra = sema.code.extraData(Zir.Inst.ExtendedVar, extended.operand);25742 const extra = sema.code.extraData(Zir.Inst.ExtendedVar, extended.operand);
25873 const ty_src: LazySrcLoc = .{ .node_offset_var_decl_ty = 0 };25743 const ty_src = block.src(.{ .node_offset_var_decl_ty = 0 });
25874 const init_src: LazySrcLoc = .{ .node_offset_var_decl_init = 0 };25744 const init_src = block.src(.{ .node_offset_var_decl_init = 0 });
25875 const small: Zir.Inst.ExtendedVar.Small = @bitCast(extended.small);25745 const small: Zir.Inst.ExtendedVar.Small = @bitCast(extended.small);
2587625746
25877 var extra_index: usize = extra.end;25747 var extra_index: usize = extra.end;
...@@ -25936,11 +25806,11 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A...@@ -25936,11 +25806,11 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
25936 const extra = sema.code.extraData(Zir.Inst.FuncFancy, inst_data.payload_index);25806 const extra = sema.code.extraData(Zir.Inst.FuncFancy, inst_data.payload_index);
25937 const target = mod.getTarget();25807 const target = mod.getTarget();
2593825808
25939 const align_src: LazySrcLoc = .{ .node_offset_fn_type_align = inst_data.src_node };25809 const align_src = block.src(.{ .node_offset_fn_type_align = inst_data.src_node });
25940 const addrspace_src: LazySrcLoc = .{ .node_offset_fn_type_addrspace = inst_data.src_node };25810 const addrspace_src = block.src(.{ .node_offset_fn_type_addrspace = inst_data.src_node });
25941 const section_src: LazySrcLoc = .{ .node_offset_fn_type_section = inst_data.src_node };25811 const section_src = block.src(.{ .node_offset_fn_type_section = inst_data.src_node });
25942 const cc_src: LazySrcLoc = .{ .node_offset_fn_type_cc = inst_data.src_node };25812 const cc_src = block.src(.{ .node_offset_fn_type_cc = inst_data.src_node });
25943 const ret_src: LazySrcLoc = .{ .node_offset_fn_type_ret_ty = inst_data.src_node };25813 const ret_src = block.src(.{ .node_offset_fn_type_ret_ty = inst_data.src_node });
25944 const has_body = extra.data.body_len != 0;25814 const has_body = extra.data.body_len != 0;
2594525815
25946 var extra_index: usize = extra.end;25816 var extra_index: usize = extra.end;
...@@ -26167,7 +26037,7 @@ fn zirCUndef(...@@ -26167,7 +26037,7 @@ fn zirCUndef(
26167 extended: Zir.Inst.Extended.InstData,26037 extended: Zir.Inst.Extended.InstData,
26168) CompileError!Air.Inst.Ref {26038) CompileError!Air.Inst.Ref {
26169 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;26039 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;
26170 const src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node };26040 const src = block.builtinCallArgSrc(extra.node, 0);
2617126041
26172 const name = try sema.resolveConstString(block, src, extra.operand, .{26042 const name = try sema.resolveConstString(block, src, extra.operand, .{
26173 .needed_comptime_reason = "name of macro being undefined must be comptime-known",26043 .needed_comptime_reason = "name of macro being undefined must be comptime-known",
...@@ -26182,7 +26052,7 @@ fn zirCInclude(...@@ -26182,7 +26052,7 @@ fn zirCInclude(
26182 extended: Zir.Inst.Extended.InstData,26052 extended: Zir.Inst.Extended.InstData,
26183) CompileError!Air.Inst.Ref {26053) CompileError!Air.Inst.Ref {
26184 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;26054 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;
26185 const src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node };26055 const src = block.builtinCallArgSrc(extra.node, 0);
2618626056
26187 const name = try sema.resolveConstString(block, src, extra.operand, .{26057 const name = try sema.resolveConstString(block, src, extra.operand, .{
26188 .needed_comptime_reason = "path being included must be comptime-known",26058 .needed_comptime_reason = "path being included must be comptime-known",
...@@ -26198,8 +26068,8 @@ fn zirCDefine(...@@ -26198,8 +26068,8 @@ fn zirCDefine(
26198) CompileError!Air.Inst.Ref {26068) CompileError!Air.Inst.Ref {
26199 const mod = sema.mod;26069 const mod = sema.mod;
26200 const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data;26070 const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data;
26201 const name_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node };26071 const name_src = block.builtinCallArgSrc(extra.node, 0);
26202 const val_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = extra.node };26072 const val_src = block.builtinCallArgSrc(extra.node, 1);
2620326073
26204 const name = try sema.resolveConstString(block, name_src, extra.lhs, .{26074 const name = try sema.resolveConstString(block, name_src, extra.lhs, .{
26205 .needed_comptime_reason = "name of macro being undefined must be comptime-known",26075 .needed_comptime_reason = "name of macro being undefined must be comptime-known",
...@@ -26222,8 +26092,8 @@ fn zirWasmMemorySize(...@@ -26222,8 +26092,8 @@ fn zirWasmMemorySize(
26222 extended: Zir.Inst.Extended.InstData,26092 extended: Zir.Inst.Extended.InstData,
26223) CompileError!Air.Inst.Ref {26093) CompileError!Air.Inst.Ref {
26224 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;26094 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;
26225 const index_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node };26095 const index_src = block.builtinCallArgSrc(extra.node, 0);
26226 const builtin_src = LazySrcLoc.nodeOffset(extra.node);26096 const builtin_src = block.nodeOffset(extra.node);
26227 const target = sema.mod.getTarget();26097 const target = sema.mod.getTarget();
26228 if (!target.isWasm()) {26098 if (!target.isWasm()) {
26229 return sema.fail(block, builtin_src, "builtin @wasmMemorySize is available when targeting WebAssembly; targeted CPU architecture is {s}", .{@tagName(target.cpu.arch)});26099 return sema.fail(block, builtin_src, "builtin @wasmMemorySize is available when targeting WebAssembly; targeted CPU architecture is {s}", .{@tagName(target.cpu.arch)});
...@@ -26248,9 +26118,9 @@ fn zirWasmMemoryGrow(...@@ -26248,9 +26118,9 @@ fn zirWasmMemoryGrow(
26248 extended: Zir.Inst.Extended.InstData,26118 extended: Zir.Inst.Extended.InstData,
26249) CompileError!Air.Inst.Ref {26119) CompileError!Air.Inst.Ref {
26250 const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data;26120 const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data;
26251 const builtin_src = LazySrcLoc.nodeOffset(extra.node);26121 const builtin_src = block.nodeOffset(extra.node);
26252 const index_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node };26122 const index_src = block.builtinCallArgSrc(extra.node, 0);
26253 const delta_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = extra.node };26123 const delta_src = block.builtinCallArgSrc(extra.node, 1);
26254 const target = sema.mod.getTarget();26124 const target = sema.mod.getTarget();
26255 if (!target.isWasm()) {26125 if (!target.isWasm()) {
26256 return sema.fail(block, builtin_src, "builtin @wasmMemoryGrow is available when targeting WebAssembly; targeted CPU architecture is {s}", .{@tagName(target.cpu.arch)});26126 return sema.fail(block, builtin_src, "builtin @wasmMemoryGrow is available when targeting WebAssembly; targeted CPU architecture is {s}", .{@tagName(target.cpu.arch)});
...@@ -26283,9 +26153,9 @@ fn resolvePrefetchOptions(...@@ -26283,9 +26153,9 @@ fn resolvePrefetchOptions(
26283 const options_ty = try sema.getBuiltinType("PrefetchOptions");26153 const options_ty = try sema.getBuiltinType("PrefetchOptions");
26284 const options = try sema.coerce(block, options_ty, try sema.resolveInst(zir_ref), src);26154 const options = try sema.coerce(block, options_ty, try sema.resolveInst(zir_ref), src);
2628526155
26286 const rw_src = sema.maybeOptionsSrc(block, src, "rw");26156 const rw_src = block.src(.{ .init_field_rw = src.offset.node_offset_builtin_call_arg.builtin_call_node });
26287 const locality_src = sema.maybeOptionsSrc(block, src, "locality");26157 const locality_src = block.src(.{ .init_field_locality = src.offset.node_offset_builtin_call_arg.builtin_call_node });
26288 const cache_src = sema.maybeOptionsSrc(block, src, "cache");26158 const cache_src = block.src(.{ .init_field_cache = src.offset.node_offset_builtin_call_arg.builtin_call_node });
2628926159
26290 const rw = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "rw", .no_embedded_nulls), rw_src);26160 const rw = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "rw", .no_embedded_nulls), rw_src);
26291 const rw_val = try sema.resolveConstDefinedValue(block, rw_src, rw, .{26161 const rw_val = try sema.resolveConstDefinedValue(block, rw_src, rw, .{
...@@ -26315,18 +26185,12 @@ fn zirPrefetch(...@@ -26315,18 +26185,12 @@ fn zirPrefetch(
26315 extended: Zir.Inst.Extended.InstData,26185 extended: Zir.Inst.Extended.InstData,
26316) CompileError!Air.Inst.Ref {26186) CompileError!Air.Inst.Ref {
26317 const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data;26187 const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data;
26318 const ptr_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node };26188 const ptr_src = block.builtinCallArgSrc(extra.node, 0);
26319 const opts_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = extra.node };26189 const opts_src = block.builtinCallArgSrc(extra.node, 1);
26320 const ptr = try sema.resolveInst(extra.lhs);26190 const ptr = try sema.resolveInst(extra.lhs);
26321 try sema.checkPtrOperand(block, ptr_src, sema.typeOf(ptr));26191 try sema.checkPtrOperand(block, ptr_src, sema.typeOf(ptr));
2632226192
26323 const options = sema.resolvePrefetchOptions(block, .unneeded, extra.rhs) catch |err| switch (err) {26193 const options = try sema.resolvePrefetchOptions(block, opts_src, extra.rhs);
26324 error.NeededSourceLocation => {
26325 _ = try sema.resolvePrefetchOptions(block, opts_src, extra.rhs);
26326 unreachable;
26327 },
26328 else => |e| return e,
26329 };
2633026194
26331 if (!block.is_comptime) {26195 if (!block.is_comptime) {
26332 _ = try block.addInst(.{26196 _ = try block.addInst(.{
...@@ -26361,10 +26225,10 @@ fn resolveExternOptions(...@@ -26361,10 +26225,10 @@ fn resolveExternOptions(
26361 const extern_options_ty = try sema.getBuiltinType("ExternOptions");26225 const extern_options_ty = try sema.getBuiltinType("ExternOptions");
26362 const options = try sema.coerce(block, extern_options_ty, options_inst, src);26226 const options = try sema.coerce(block, extern_options_ty, options_inst, src);
2636326227
26364 const name_src = sema.maybeOptionsSrc(block, src, "name");26228 const name_src = block.src(.{ .init_field_name = src.offset.node_offset_builtin_call_arg.builtin_call_node });
26365 const library_src = sema.maybeOptionsSrc(block, src, "library");26229 const library_src = block.src(.{ .init_field_library = src.offset.node_offset_builtin_call_arg.builtin_call_node });
26366 const linkage_src = sema.maybeOptionsSrc(block, src, "linkage");26230 const linkage_src = block.src(.{ .init_field_linkage = src.offset.node_offset_builtin_call_arg.builtin_call_node });
26367 const thread_local_src = sema.maybeOptionsSrc(block, src, "thread_local");26231 const thread_local_src = block.src(.{ .init_field_thread_local = src.offset.node_offset_builtin_call_arg.builtin_call_node });
2636826232
26369 const name_ref = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "name", .no_embedded_nulls), name_src);26233 const name_ref = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "name", .no_embedded_nulls), name_src);
26370 const name = try sema.toConstString(block, name_src, name_ref, .{26234 const name = try sema.toConstString(block, name_src, name_ref, .{
...@@ -26422,8 +26286,8 @@ fn zirBuiltinExtern(...@@ -26422,8 +26286,8 @@ fn zirBuiltinExtern(
26422 const mod = sema.mod;26286 const mod = sema.mod;
26423 const ip = &mod.intern_pool;26287 const ip = &mod.intern_pool;
26424 const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data;26288 const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data;
26425 const ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node };26289 const ty_src = block.builtinCallArgSrc(extra.node, 0);
26426 const options_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = extra.node };26290 const options_src = block.builtinCallArgSrc(extra.node, 1);
2642726291
26428 var ty = try sema.resolveType(block, ty_src, extra.lhs);26292 var ty = try sema.resolveType(block, ty_src, extra.lhs);
26429 if (!ty.isPtrAtRuntime(mod)) {26293 if (!ty.isPtrAtRuntime(mod)) {
...@@ -26431,29 +26295,22 @@ fn zirBuiltinExtern(...@@ -26431,29 +26295,22 @@ fn zirBuiltinExtern(
26431 }26295 }
26432 if (!try sema.validateExternType(ty, .other)) {26296 if (!try sema.validateExternType(ty, .other)) {
26433 const msg = msg: {26297 const msg = msg: {
26434 const msg = try sema.errMsg(block, ty_src, "extern symbol cannot have type '{}'", .{ty.fmt(mod)});26298 const msg = try sema.errMsg(ty_src, "extern symbol cannot have type '{}'", .{ty.fmt(mod)});
26435 errdefer msg.destroy(sema.gpa);26299 errdefer msg.destroy(sema.gpa);
26436 const src_decl = sema.mod.declPtr(block.src_decl);26300 try sema.explainWhyTypeIsNotExtern(msg, ty_src, ty, .other);
26437 try sema.explainWhyTypeIsNotExtern(msg, src_decl.toSrcLoc(ty_src, mod), ty, .other);
26438 break :msg msg;26301 break :msg msg;
26439 };26302 };
26440 return sema.failWithOwnedErrorMsg(block, msg);26303 return sema.failWithOwnedErrorMsg(block, msg);
26441 }26304 }
2644226305
26443 const options = sema.resolveExternOptions(block, .unneeded, extra.rhs) catch |err| switch (err) {26306 const options = try sema.resolveExternOptions(block, options_src, extra.rhs);
26444 error.NeededSourceLocation => {
26445 _ = try sema.resolveExternOptions(block, options_src, extra.rhs);
26446 unreachable;
26447 },
26448 else => |e| return e,
26449 };
2645026307
26451 if (options.linkage == .weak and !ty.ptrAllowsZero(mod)) {26308 if (options.linkage == .weak and !ty.ptrAllowsZero(mod)) {
26452 ty = try mod.optionalType(ty.toIntern());26309 ty = try mod.optionalType(ty.toIntern());
26453 }26310 }
26454 const ptr_info = ty.ptrInfo(mod);26311 const ptr_info = ty.ptrInfo(mod);
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);
26457 errdefer mod.destroyDecl(new_decl_index);26314 errdefer mod.destroyDecl(new_decl_index);
26458 const new_decl = mod.declPtr(new_decl_index);26315 const new_decl = mod.declPtr(new_decl_index);
26459 try mod.initNewAnonDecl(26316 try mod.initNewAnonDecl(
...@@ -26503,8 +26360,8 @@ fn zirWorkItem(...@@ -26503,8 +26360,8 @@ fn zirWorkItem(
26503 zir_tag: Zir.Inst.Extended,26360 zir_tag: Zir.Inst.Extended,
26504) CompileError!Air.Inst.Ref {26361) CompileError!Air.Inst.Ref {
26505 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;26362 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;
26506 const dimension_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node };26363 const dimension_src = block.builtinCallArgSrc(extra.node, 0);
26507 const builtin_src = LazySrcLoc.nodeOffset(extra.node);26364 const builtin_src = block.nodeOffset(extra.node);
26508 const target = sema.mod.getTarget();26365 const target = sema.mod.getTarget();
2650926366
26510 switch (target.cpu.arch) {26367 switch (target.cpu.arch) {
...@@ -26545,11 +26402,11 @@ fn zirInComptime(...@@ -26545,11 +26402,11 @@ fn zirInComptime(
26545fn requireRuntimeBlock(sema: *Sema, block: *Block, src: LazySrcLoc, runtime_src: ?LazySrcLoc) !void {26402fn requireRuntimeBlock(sema: *Sema, block: *Block, src: LazySrcLoc, runtime_src: ?LazySrcLoc) !void {
26546 if (block.is_comptime) {26403 if (block.is_comptime) {
26547 const msg = msg: {26404 const msg = msg: {
26548 const msg = try sema.errMsg(block, src, "unable to evaluate comptime expression", .{});26405 const msg = try sema.errMsg(src, "unable to evaluate comptime expression", .{});
26549 errdefer msg.destroy(sema.gpa);26406 errdefer msg.destroy(sema.gpa);
2655026407
26551 if (runtime_src) |some| {26408 if (runtime_src) |some| {
26552 try sema.errNote(block, some, msg, "operation is runtime due to this operand", .{});26409 try sema.errNote(some, msg, "operation is runtime due to this operand", .{});
26553 }26410 }
26554 if (block.comptime_reason) |some| {26411 if (block.comptime_reason) |some| {
26555 try some.explain(sema, msg);26412 try some.explain(sema, msg);
...@@ -26572,10 +26429,9 @@ fn validateVarType(...@@ -26572,10 +26429,9 @@ fn validateVarType(
26572 if (is_extern) {26429 if (is_extern) {
26573 if (!try sema.validateExternType(var_ty, .other)) {26430 if (!try sema.validateExternType(var_ty, .other)) {
26574 const msg = msg: {26431 const msg = msg: {
26575 const msg = try sema.errMsg(block, src, "extern variable cannot have type '{}'", .{var_ty.fmt(mod)});26432 const msg = try sema.errMsg(src, "extern variable cannot have type '{}'", .{var_ty.fmt(mod)});
26576 errdefer msg.destroy(sema.gpa);26433 errdefer msg.destroy(sema.gpa);
26577 const src_decl = mod.declPtr(block.src_decl);26434 try sema.explainWhyTypeIsNotExtern(msg, src, var_ty, .other);
26578 try sema.explainWhyTypeIsNotExtern(msg, src_decl.toSrcLoc(src, mod), var_ty, .other);
26579 break :msg msg;26435 break :msg msg;
26580 };26436 };
26581 return sema.failWithOwnedErrorMsg(block, msg);26437 return sema.failWithOwnedErrorMsg(block, msg);
...@@ -26594,13 +26450,12 @@ fn validateVarType(...@@ -26594,13 +26450,12 @@ fn validateVarType(
26594 if (!try sema.typeRequiresComptime(var_ty)) return;26450 if (!try sema.typeRequiresComptime(var_ty)) return;
2659526451
26596 const msg = msg: {26452 const msg = msg: {
26597 const msg = try sema.errMsg(block, src, "variable of type '{}' must be const or comptime", .{var_ty.fmt(mod)});26453 const msg = try sema.errMsg(src, "variable of type '{}' must be const or comptime", .{var_ty.fmt(mod)});
26598 errdefer msg.destroy(sema.gpa);26454 errdefer msg.destroy(sema.gpa);
2659926455
26600 const src_decl = mod.declPtr(block.src_decl);26456 try sema.explainWhyTypeIsComptime(msg, src, var_ty);
26601 try sema.explainWhyTypeIsComptime(msg, src_decl.toSrcLoc(src, mod), var_ty);
26602 if (var_ty.zigTypeTag(mod) == .ComptimeInt or var_ty.zigTypeTag(mod) == .ComptimeFloat) {26457 if (var_ty.zigTypeTag(mod) == .ComptimeInt or var_ty.zigTypeTag(mod) == .ComptimeFloat) {
26603 try sema.errNote(block, src, msg, "to modify this variable at runtime, it must be given an explicit fixed-size number type", .{});26458 try sema.errNote(src, msg, "to modify this variable at runtime, it must be given an explicit fixed-size number type", .{});
26604 }26459 }
2660526460
26606 break :msg msg;26461 break :msg msg;
...@@ -26613,7 +26468,7 @@ const TypeSet = std.AutoHashMapUnmanaged(InternPool.Index, void);...@@ -26613,7 +26468,7 @@ const TypeSet = std.AutoHashMapUnmanaged(InternPool.Index, void);
26613fn explainWhyTypeIsComptime(26468fn explainWhyTypeIsComptime(
26614 sema: *Sema,26469 sema: *Sema,
26615 msg: *Module.ErrorMsg,26470 msg: *Module.ErrorMsg,
26616 src_loc: Module.SrcLoc,26471 src_loc: LazySrcLoc,
26617 ty: Type,26472 ty: Type,
26618) CompileError!void {26473) CompileError!void {
26619 var type_set = TypeSet{};26474 var type_set = TypeSet{};
...@@ -26626,7 +26481,7 @@ fn explainWhyTypeIsComptime(...@@ -26626,7 +26481,7 @@ fn explainWhyTypeIsComptime(
26626fn explainWhyTypeIsComptimeInner(26481fn explainWhyTypeIsComptimeInner(
26627 sema: *Sema,26482 sema: *Sema,
26628 msg: *Module.ErrorMsg,26483 msg: *Module.ErrorMsg,
26629 src_loc: Module.SrcLoc,26484 src_loc: LazySrcLoc,
26630 ty: Type,26485 ty: Type,
26631 type_set: *TypeSet,26486 type_set: *TypeSet,
26632) CompileError!void {26487) CompileError!void {
...@@ -26644,13 +26499,13 @@ fn explainWhyTypeIsComptimeInner(...@@ -26644,13 +26499,13 @@ fn explainWhyTypeIsComptimeInner(
26644 => return,26499 => return,
2664526500
26646 .Fn => {26501 .Fn => {
26647 try mod.errNoteNonLazy(src_loc, msg, "use '*const {}' for a function pointer type", .{26502 try sema.errNote(src_loc, msg, "use '*const {}' for a function pointer type", .{
26648 ty.fmt(sema.mod),26503 ty.fmt(sema.mod),
26649 });26504 });
26650 },26505 },
2665126506
26652 .Type => {26507 .Type => {
26653 try mod.errNoteNonLazy(src_loc, msg, "types are not available at runtime", .{});26508 try sema.errNote(src_loc, msg, "types are not available at runtime", .{});
26654 },26509 },
2665526510
26656 .ComptimeFloat,26511 .ComptimeFloat,
...@@ -26662,7 +26517,7 @@ fn explainWhyTypeIsComptimeInner(...@@ -26662,7 +26517,7 @@ fn explainWhyTypeIsComptimeInner(
26662 => return,26517 => return,
2666326518
26664 .Opaque => {26519 .Opaque => {
26665 try mod.errNoteNonLazy(src_loc, msg, "opaque type '{}' has undefined size", .{ty.fmt(sema.mod)});26520 try sema.errNote(src_loc, msg, "opaque type '{}' has undefined size", .{ty.fmt(sema.mod)});
26666 },26521 },
2666726522
26668 .Array, .Vector => {26523 .Array, .Vector => {
...@@ -26673,14 +26528,14 @@ fn explainWhyTypeIsComptimeInner(...@@ -26673,14 +26528,14 @@ fn explainWhyTypeIsComptimeInner(
26673 if (elem_ty.zigTypeTag(mod) == .Fn) {26528 if (elem_ty.zigTypeTag(mod) == .Fn) {
26674 const fn_info = mod.typeToFunc(elem_ty).?;26529 const fn_info = mod.typeToFunc(elem_ty).?;
26675 if (fn_info.is_generic) {26530 if (fn_info.is_generic) {
26676 try mod.errNoteNonLazy(src_loc, msg, "function is generic", .{});26531 try sema.errNote(src_loc, msg, "function is generic", .{});
26677 }26532 }
26678 switch (fn_info.cc) {26533 switch (fn_info.cc) {
26679 .Inline => try mod.errNoteNonLazy(src_loc, msg, "function has inline calling convention", .{}),26534 .Inline => try sema.errNote(src_loc, msg, "function has inline calling convention", .{}),
26680 else => {},26535 else => {},
26681 }26536 }
26682 if (Type.fromInterned(fn_info.return_type).comptimeOnly(mod)) {26537 if (Type.fromInterned(fn_info.return_type).comptimeOnly(mod)) {
26683 try mod.errNoteNonLazy(src_loc, msg, "function has a comptime-only return type", .{});26538 try sema.errNote(src_loc, msg, "function has a comptime-only return type", .{});
26684 }26539 }
26685 return;26540 return;
26686 }26541 }
...@@ -26700,14 +26555,14 @@ fn explainWhyTypeIsComptimeInner(...@@ -26700,14 +26555,14 @@ fn explainWhyTypeIsComptimeInner(
26700 if (mod.typeToStruct(ty)) |struct_type| {26555 if (mod.typeToStruct(ty)) |struct_type| {
26701 for (0..struct_type.field_types.len) |i| {26556 for (0..struct_type.field_types.len) |i| {
26702 const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[i]);26557 const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[i]);
26703 const field_src_loc = mod.fieldSrcLoc(struct_type.decl.unwrap().?, .{26558 const field_src: LazySrcLoc = .{
26704 .index = i,26559 .base_node_inst = struct_type.zir_index.unwrap().?,
26705 .range = .type,26560 .offset = .{ .container_field_type = @intCast(i) },
26706 });26561 };
2670726562
26708 if (try sema.typeRequiresComptime(field_ty)) {26563 if (try sema.typeRequiresComptime(field_ty)) {
26709 try mod.errNoteNonLazy(field_src_loc, msg, "struct requires comptime because of this field", .{});26564 try sema.errNote(field_src, msg, "struct requires comptime because of this field", .{});
26710 try sema.explainWhyTypeIsComptimeInner(msg, field_src_loc, field_ty, type_set);26565 try sema.explainWhyTypeIsComptimeInner(msg, field_src, field_ty, type_set);
26711 }26566 }
26712 }26567 }
26713 }26568 }
...@@ -26720,14 +26575,14 @@ fn explainWhyTypeIsComptimeInner(...@@ -26720,14 +26575,14 @@ fn explainWhyTypeIsComptimeInner(
26720 if (mod.typeToUnion(ty)) |union_obj| {26575 if (mod.typeToUnion(ty)) |union_obj| {
26721 for (0..union_obj.field_types.len) |i| {26576 for (0..union_obj.field_types.len) |i| {
26722 const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[i]);26577 const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[i]);
26723 const field_src_loc = mod.fieldSrcLoc(union_obj.decl, .{26578 const field_src: LazySrcLoc = .{
26724 .index = i,26579 .base_node_inst = union_obj.zir_index,
26725 .range = .type,26580 .offset = .{ .container_field_type = @intCast(i) },
26726 });26581 };
2672726582
26728 if (try sema.typeRequiresComptime(field_ty)) {26583 if (try sema.typeRequiresComptime(field_ty)) {
26729 try mod.errNoteNonLazy(field_src_loc, msg, "union requires comptime because of this field", .{});26584 try sema.errNote(field_src, msg, "union requires comptime because of this field", .{});
26730 try sema.explainWhyTypeIsComptimeInner(msg, field_src_loc, field_ty, type_set);26585 try sema.explainWhyTypeIsComptimeInner(msg, field_src, field_ty, type_set);
26731 }26586 }
26732 }26587 }
26733 }26588 }
...@@ -26817,7 +26672,7 @@ fn validateExternType(...@@ -26817,7 +26672,7 @@ fn validateExternType(
26817fn explainWhyTypeIsNotExtern(26672fn explainWhyTypeIsNotExtern(
26818 sema: *Sema,26673 sema: *Sema,
26819 msg: *Module.ErrorMsg,26674 msg: *Module.ErrorMsg,
26820 src_loc: Module.SrcLoc,26675 src_loc: LazySrcLoc,
26821 ty: Type,26676 ty: Type,
26822 position: ExternPosition,26677 position: ExternPosition,
26823) CompileError!void {26678) CompileError!void {
...@@ -26842,55 +26697,55 @@ fn explainWhyTypeIsNotExtern(...@@ -26842,55 +26697,55 @@ fn explainWhyTypeIsNotExtern(
2684226697
26843 .Pointer => {26698 .Pointer => {
26844 if (ty.isSlice(mod)) {26699 if (ty.isSlice(mod)) {
26845 try mod.errNoteNonLazy(src_loc, msg, "slices have no guaranteed in-memory representation", .{});26700 try sema.errNote(src_loc, msg, "slices have no guaranteed in-memory representation", .{});
26846 } else {26701 } else {
26847 const pointee_ty = ty.childType(mod);26702 const pointee_ty = ty.childType(mod);
26848 if (!ty.isConstPtr(mod) and pointee_ty.zigTypeTag(mod) == .Fn) {26703 if (!ty.isConstPtr(mod) and pointee_ty.zigTypeTag(mod) == .Fn) {
26849 try mod.errNoteNonLazy(src_loc, msg, "pointer to extern function must be 'const'", .{});26704 try sema.errNote(src_loc, msg, "pointer to extern function must be 'const'", .{});
26850 } else if (try sema.typeRequiresComptime(ty)) {26705 } else if (try sema.typeRequiresComptime(ty)) {
26851 try mod.errNoteNonLazy(src_loc, msg, "pointer to comptime-only type '{}'", .{pointee_ty.fmt(sema.mod)});26706 try sema.errNote(src_loc, msg, "pointer to comptime-only type '{}'", .{pointee_ty.fmt(sema.mod)});
26852 try sema.explainWhyTypeIsComptime(msg, src_loc, ty);26707 try sema.explainWhyTypeIsComptime(msg, src_loc, ty);
26853 }26708 }
26854 try sema.explainWhyTypeIsNotExtern(msg, src_loc, pointee_ty, .other);26709 try sema.explainWhyTypeIsNotExtern(msg, src_loc, pointee_ty, .other);
26855 }26710 }
26856 },26711 },
26857 .Void => try mod.errNoteNonLazy(src_loc, msg, "'void' is a zero bit type; for C 'void' use 'anyopaque'", .{}),26712 .Void => try sema.errNote(src_loc, msg, "'void' is a zero bit type; for C 'void' use 'anyopaque'", .{}),
26858 .NoReturn => try mod.errNoteNonLazy(src_loc, msg, "'noreturn' is only allowed as a return type", .{}),26713 .NoReturn => try sema.errNote(src_loc, msg, "'noreturn' is only allowed as a return type", .{}),
26859 .Int => if (!std.math.isPowerOfTwo(ty.intInfo(mod).bits)) {26714 .Int => if (!std.math.isPowerOfTwo(ty.intInfo(mod).bits)) {
26860 try mod.errNoteNonLazy(src_loc, msg, "only integers with 0 or power of two bits are extern compatible", .{});26715 try sema.errNote(src_loc, msg, "only integers with 0 or power of two bits are extern compatible", .{});
26861 } else {26716 } else {
26862 try mod.errNoteNonLazy(src_loc, msg, "only integers with 0, 8, 16, 32, 64 and 128 bits are extern compatible", .{});26717 try sema.errNote(src_loc, msg, "only integers with 0, 8, 16, 32, 64 and 128 bits are extern compatible", .{});
26863 },26718 },
26864 .Fn => {26719 .Fn => {
26865 if (position != .other) {26720 if (position != .other) {
26866 try mod.errNoteNonLazy(src_loc, msg, "type has no guaranteed in-memory representation", .{});26721 try sema.errNote(src_loc, msg, "type has no guaranteed in-memory representation", .{});
26867 try mod.errNoteNonLazy(src_loc, msg, "use '*const ' to make a function pointer type", .{});26722 try sema.errNote(src_loc, msg, "use '*const ' to make a function pointer type", .{});
26868 return;26723 return;
26869 }26724 }
26870 switch (ty.fnCallingConvention(mod)) {26725 switch (ty.fnCallingConvention(mod)) {
26871 .Unspecified => try mod.errNoteNonLazy(src_loc, msg, "extern function must specify calling convention", .{}),26726 .Unspecified => try sema.errNote(src_loc, msg, "extern function must specify calling convention", .{}),
26872 .Async => try mod.errNoteNonLazy(src_loc, msg, "async function cannot be extern", .{}),26727 .Async => try sema.errNote(src_loc, msg, "async function cannot be extern", .{}),
26873 .Inline => try mod.errNoteNonLazy(src_loc, msg, "inline function cannot be extern", .{}),26728 .Inline => try sema.errNote(src_loc, msg, "inline function cannot be extern", .{}),
26874 else => return,26729 else => return,
26875 }26730 }
26876 },26731 },
26877 .Enum => {26732 .Enum => {
26878 const tag_ty = ty.intTagType(mod);26733 const tag_ty = ty.intTagType(mod);
26879 try mod.errNoteNonLazy(src_loc, msg, "enum tag type '{}' is not extern compatible", .{tag_ty.fmt(sema.mod)});26734 try sema.errNote(src_loc, msg, "enum tag type '{}' is not extern compatible", .{tag_ty.fmt(sema.mod)});
26880 try sema.explainWhyTypeIsNotExtern(msg, src_loc, tag_ty, position);26735 try sema.explainWhyTypeIsNotExtern(msg, src_loc, tag_ty, position);
26881 },26736 },
26882 .Struct => try mod.errNoteNonLazy(src_loc, msg, "only extern structs and ABI sized packed structs are extern compatible", .{}),26737 .Struct => try sema.errNote(src_loc, msg, "only extern structs and ABI sized packed structs are extern compatible", .{}),
26883 .Union => try mod.errNoteNonLazy(src_loc, msg, "only extern unions and ABI sized packed unions are extern compatible", .{}),26738 .Union => try sema.errNote(src_loc, msg, "only extern unions and ABI sized packed unions are extern compatible", .{}),
26884 .Array => {26739 .Array => {
26885 if (position == .ret_ty) {26740 if (position == .ret_ty) {
26886 return mod.errNoteNonLazy(src_loc, msg, "arrays are not allowed as a return type", .{});26741 return sema.errNote(src_loc, msg, "arrays are not allowed as a return type", .{});
26887 } else if (position == .param_ty) {26742 } else if (position == .param_ty) {
26888 return mod.errNoteNonLazy(src_loc, msg, "arrays are not allowed as a parameter type", .{});26743 return sema.errNote(src_loc, msg, "arrays are not allowed as a parameter type", .{});
26889 }26744 }
26890 try sema.explainWhyTypeIsNotExtern(msg, src_loc, ty.elemType2(mod), .element);26745 try sema.explainWhyTypeIsNotExtern(msg, src_loc, ty.elemType2(mod), .element);
26891 },26746 },
26892 .Vector => try sema.explainWhyTypeIsNotExtern(msg, src_loc, ty.elemType2(mod), .element),26747 .Vector => try sema.explainWhyTypeIsNotExtern(msg, src_loc, ty.elemType2(mod), .element),
26893 .Optional => try mod.errNoteNonLazy(src_loc, msg, "only pointer like optionals are extern compatible", .{}),26748 .Optional => try sema.errNote(src_loc, msg, "only pointer like optionals are extern compatible", .{}),
26894 }26749 }
26895}26750}
2689626751
...@@ -26933,7 +26788,7 @@ fn validatePackedType(sema: *Sema, ty: Type) !bool {...@@ -26933,7 +26788,7 @@ fn validatePackedType(sema: *Sema, ty: Type) !bool {
26933fn explainWhyTypeIsNotPacked(26788fn explainWhyTypeIsNotPacked(
26934 sema: *Sema,26789 sema: *Sema,
26935 msg: *Module.ErrorMsg,26790 msg: *Module.ErrorMsg,
26936 src_loc: Module.SrcLoc,26791 src_loc: LazySrcLoc,
26937 ty: Type,26792 ty: Type,
26938) CompileError!void {26793) CompileError!void {
26939 const mod = sema.mod;26794 const mod = sema.mod;
...@@ -26959,19 +26814,19 @@ fn explainWhyTypeIsNotPacked(...@@ -26959,19 +26814,19 @@ fn explainWhyTypeIsNotPacked(
26959 .AnyFrame,26814 .AnyFrame,
26960 .Optional,26815 .Optional,
26961 .Array,26816 .Array,
26962 => try mod.errNoteNonLazy(src_loc, msg, "type has no guaranteed in-memory representation", .{}),26817 => try sema.errNote(src_loc, msg, "type has no guaranteed in-memory representation", .{}),
26963 .Pointer => if (ty.isSlice(mod)) {26818 .Pointer => if (ty.isSlice(mod)) {
26964 try mod.errNoteNonLazy(src_loc, msg, "slices have no guaranteed in-memory representation", .{});26819 try sema.errNote(src_loc, msg, "slices have no guaranteed in-memory representation", .{});
26965 } else {26820 } else {
26966 try mod.errNoteNonLazy(src_loc, msg, "comptime-only pointer has no guaranteed in-memory representation", .{});26821 try sema.errNote(src_loc, msg, "comptime-only pointer has no guaranteed in-memory representation", .{});
26967 try sema.explainWhyTypeIsComptime(msg, src_loc, ty);26822 try sema.explainWhyTypeIsComptime(msg, src_loc, ty);
26968 },26823 },
26969 .Fn => {26824 .Fn => {
26970 try mod.errNoteNonLazy(src_loc, msg, "type has no guaranteed in-memory representation", .{});26825 try sema.errNote(src_loc, msg, "type has no guaranteed in-memory representation", .{});
26971 try mod.errNoteNonLazy(src_loc, msg, "use '*const ' to make a function pointer type", .{});26826 try sema.errNote(src_loc, msg, "use '*const ' to make a function pointer type", .{});
26972 },26827 },
26973 .Struct => try mod.errNoteNonLazy(src_loc, msg, "only packed structs layout are allowed in packed types", .{}),26828 .Struct => try sema.errNote(src_loc, msg, "only packed structs layout are allowed in packed types", .{}),
26974 .Union => try mod.errNoteNonLazy(src_loc, msg, "only packed unions layout are allowed in packed types", .{}),26829 .Union => try sema.errNote(src_loc, msg, "only packed unions layout are allowed in packed types", .{}),
26975 }26830 }
26976}26831}
2697726832
...@@ -27022,11 +26877,11 @@ fn preparePanicId(sema: *Sema, block: *Block, panic_id: Module.PanicId) !InternP...@@ -27022,11 +26877,11 @@ fn preparePanicId(sema: *Sema, block: *Block, panic_id: Module.PanicId) !InternP
27022 const panic_messages_ty = try sema.getBuiltinType("panic_messages");26877 const panic_messages_ty = try sema.getBuiltinType("panic_messages");
27023 const msg_decl_index = (sema.namespaceLookup(26878 const msg_decl_index = (sema.namespaceLookup(
27024 block,26879 block,
27025 .unneeded,26880 LazySrcLoc.unneeded,
27026 panic_messages_ty.getNamespaceIndex(mod),26881 panic_messages_ty.getNamespaceIndex(mod),
27027 try mod.intern_pool.getOrPutString(gpa, @tagName(panic_id), .no_embedded_nulls),26882 try mod.intern_pool.getOrPutString(gpa, @tagName(panic_id), .no_embedded_nulls),
27028 ) catch |err| switch (err) {26883 ) catch |err| switch (err) {
27029 error.AnalysisFail, error.NeededSourceLocation => @panic("std.builtin.panic_messages is corrupt"),26884 error.AnalysisFail => @panic("std.builtin.panic_messages is corrupt"),
27030 error.GenericPoison, error.ComptimeReturn, error.ComptimeBreak => unreachable,26885 error.GenericPoison, error.ComptimeReturn, error.ComptimeBreak => unreachable,
27031 error.OutOfMemory => |e| return e,26886 error.OutOfMemory => |e| return e,
27032 }).?;26887 }).?;
...@@ -27053,6 +26908,7 @@ fn addSafetyCheck(...@@ -27053,6 +26908,7 @@ fn addSafetyCheck(
27053 .instructions = .{},26908 .instructions = .{},
27054 .inlining = parent_block.inlining,26909 .inlining = parent_block.inlining,
27055 .is_comptime = false,26910 .is_comptime = false,
26911 .src_base_inst = parent_block.src_base_inst,
27056 };26912 };
2705726913
27058 defer fail_block.instructions.deinit(gpa);26914 defer fail_block.instructions.deinit(gpa);
...@@ -27161,6 +27017,7 @@ fn panicUnwrapError(...@@ -27161,6 +27017,7 @@ fn panicUnwrapError(
27161 .instructions = .{},27017 .instructions = .{},
27162 .inlining = parent_block.inlining,27018 .inlining = parent_block.inlining,
27163 .is_comptime = false,27019 .is_comptime = false,
27020 .src_base_inst = parent_block.src_base_inst,
27164 };27021 };
2716527022
27166 defer fail_block.instructions.deinit(gpa);27023 defer fail_block.instructions.deinit(gpa);
...@@ -27277,6 +27134,7 @@ fn safetyCheckFormatted(...@@ -27277,6 +27134,7 @@ fn safetyCheckFormatted(
27277 .instructions = .{},27134 .instructions = .{},
27278 .inlining = parent_block.inlining,27135 .inlining = parent_block.inlining,
27279 .is_comptime = false,27136 .is_comptime = false,
27137 .src_base_inst = parent_block.src_base_inst,
27280 };27138 };
2728127139
27282 defer fail_block.instructions.deinit(gpa);27140 defer fail_block.instructions.deinit(gpa);
...@@ -27300,13 +27158,11 @@ fn emitBackwardBranch(sema: *Sema, block: *Block, src: LazySrcLoc) !void {...@@ -27300,13 +27158,11 @@ fn emitBackwardBranch(sema: *Sema, block: *Block, src: LazySrcLoc) !void {
27300 sema.branch_count += 1;27158 sema.branch_count += 1;
27301 if (sema.branch_count > sema.branch_quota) {27159 if (sema.branch_count > sema.branch_quota) {
27302 const msg = try sema.errMsg(27160 const msg = try sema.errMsg(
27303 block,
27304 src,27161 src,
27305 "evaluation exceeded {d} backwards branches",27162 "evaluation exceeded {d} backwards branches",
27306 .{sema.branch_quota},27163 .{sema.branch_quota},
27307 );27164 );
27308 try sema.errNote(27165 try sema.errNote(
27309 block,
27310 src,27166 src,
27311 msg,27167 msg,
27312 "use @setEvalBranchQuota() to raise the branch limit from {d}",27168 "use @setEvalBranchQuota() to raise the branch limit from {d}",
...@@ -27472,10 +27328,10 @@ fn fieldVal(...@@ -27472,10 +27328,10 @@ fn fieldVal(
27472 },27328 },
27473 else => {27329 else => {
27474 const msg = msg: {27330 const msg = msg: {
27475 const msg = try sema.errMsg(block, src, "type '{}' has no members", .{child_type.fmt(mod)});27331 const msg = try sema.errMsg(src, "type '{}' has no members", .{child_type.fmt(mod)});
27476 errdefer msg.destroy(sema.gpa);27332 errdefer msg.destroy(sema.gpa);
27477 if (child_type.isSlice(mod)) try sema.errNote(block, src, msg, "slice values have 'len' and 'ptr' members", .{});27333 if (child_type.isSlice(mod)) try sema.errNote(src, msg, "slice values have 'len' and 'ptr' members", .{});
27478 if (child_type.zigTypeTag(mod) == .Array) try sema.errNote(block, src, msg, "array values have 'len' member", .{});27334 if (child_type.zigTypeTag(mod) == .Array) try sema.errNote(src, msg, "array values have 'len' member", .{});
27479 break :msg msg;27335 break :msg msg;
27480 };27336 };
27481 return sema.failWithOwnedErrorMsg(block, msg);27337 return sema.failWithOwnedErrorMsg(block, msg);
...@@ -27633,7 +27489,7 @@ fn fieldPtr(...@@ -27633,7 +27489,7 @@ fn fieldPtr(
27633 }27489 }
27634 },27490 },
27635 .Type => {27491 .Type => {
27636 _ = try sema.resolveConstDefinedValue(block, .unneeded, object_ptr, undefined);27492 _ = try sema.resolveConstDefinedValue(block, LazySrcLoc.unneeded, object_ptr, undefined);
27637 const result = try sema.analyzeLoad(block, src, object_ptr, object_ptr_src);27493 const result = try sema.analyzeLoad(block, src, object_ptr, object_ptr_src);
27638 const inner = if (is_pointer_to)27494 const inner = if (is_pointer_to)
27639 try sema.analyzeLoad(block, src, result, object_ptr_src)27495 try sema.analyzeLoad(block, src, result, object_ptr_src)
...@@ -27885,7 +27741,7 @@ fn fieldCallBind(...@@ -27885,7 +27741,7 @@ fn fieldCallBind(
27885 };27741 };
2788627742
27887 const msg = msg: {27743 const msg = msg: {
27888 const msg = try sema.errMsg(block, src, "no field or member function named '{}' in '{}'", .{27744 const msg = try sema.errMsg(src, "no field or member function named '{}' in '{}'", .{
27889 field_name.fmt(ip),27745 field_name.fmt(ip),
27890 concrete_ty.fmt(mod),27746 concrete_ty.fmt(mod),
27891 });27747 });
...@@ -27893,10 +27749,13 @@ fn fieldCallBind(...@@ -27893,10 +27749,13 @@ fn fieldCallBind(
27893 try sema.addDeclaredHereNote(msg, concrete_ty);27749 try sema.addDeclaredHereNote(msg, concrete_ty);
27894 if (found_decl) |decl_idx| {27750 if (found_decl) |decl_idx| {
27895 const decl = mod.declPtr(decl_idx);27751 const decl = mod.declPtr(decl_idx);
27896 try mod.errNoteNonLazy(decl.srcLoc(mod), msg, "'{}' is not a member function", .{field_name.fmt(ip)});27752 try sema.errNote(.{
27753 .base_node_inst = decl.zir_decl_index.unwrap().?,
27754 .offset = LazySrcLoc.Offset.nodeOffset(0),
27755 }, msg, "'{}' is not a member function", .{field_name.fmt(ip)});
27897 }27756 }
27898 if (concrete_ty.zigTypeTag(mod) == .ErrorUnion) {27757 if (concrete_ty.zigTypeTag(mod) == .ErrorUnion) {
27899 try sema.errNote(block, src, msg, "consider using 'try', 'catch', or 'if'", .{});27758 try sema.errNote(src, msg, "consider using 'try', 'catch', or 'if'", .{});
27900 }27759 }
27901 break :msg msg;27760 break :msg msg;
27902 };27761 };
...@@ -27954,11 +27813,14 @@ fn namespaceLookup(...@@ -27954,11 +27813,14 @@ fn namespaceLookup(
27954 const decl = mod.declPtr(decl_index);27813 const decl = mod.declPtr(decl_index);
27955 if (!decl.is_pub and decl.getFileScope(mod) != block.getFileScope(mod)) {27814 if (!decl.is_pub and decl.getFileScope(mod) != block.getFileScope(mod)) {
27956 const msg = msg: {27815 const msg = msg: {
27957 const msg = try sema.errMsg(block, src, "'{}' is not marked 'pub'", .{27816 const msg = try sema.errMsg(src, "'{}' is not marked 'pub'", .{
27958 decl_name.fmt(&mod.intern_pool),27817 decl_name.fmt(&mod.intern_pool),
27959 });27818 });
27960 errdefer msg.destroy(gpa);27819 errdefer msg.destroy(gpa);
27961 try mod.errNoteNonLazy(decl.srcLoc(mod), msg, "declared here", .{});27820 try sema.errNote(.{
27821 .base_node_inst = decl.zir_decl_index.unwrap().?,
27822 .offset = LazySrcLoc.Offset.nodeOffset(0),
27823 }, msg, "declared here", .{});
27962 break :msg msg;27824 break :msg msg;
27963 };27825 };
27964 return sema.failWithOwnedErrorMsg(block, msg);27826 return sema.failWithOwnedErrorMsg(block, msg);
...@@ -28023,7 +27885,7 @@ fn structFieldPtr(...@@ -28023,7 +27885,7 @@ fn structFieldPtr(
28023 const struct_type = mod.typeToStruct(struct_ty).?;27885 const struct_type = mod.typeToStruct(struct_ty).?;
2802427886
28025 const field_index = struct_type.nameIndex(ip, field_name) orelse27887 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
28028 return sema.structFieldPtrByIndex(block, src, struct_ptr, field_index, field_name_src, struct_ty, initializing);27890 return sema.structFieldPtrByIndex(block, src, struct_ptr, field_index, field_name_src, struct_ty, initializing);
28029}27891}
...@@ -28138,7 +28000,7 @@ fn structFieldVal(...@@ -28138,7 +28000,7 @@ fn structFieldVal(
28138 return sema.tupleFieldVal(block, src, struct_byval, field_name, field_name_src, struct_ty);28000 return sema.tupleFieldVal(block, src, struct_byval, field_name, field_name_src, struct_ty);
2813928001
28140 const field_index = struct_type.nameIndex(ip, field_name) orelse28002 const field_index = struct_type.nameIndex(ip, field_name) orelse
28141 return sema.failWithBadStructFieldAccess(block, struct_type, field_name_src, field_name);28003 return sema.failWithBadStructFieldAccess(block, struct_ty, struct_type, field_name_src, field_name);
28142 if (struct_type.fieldIsComptime(ip, field_index)) {28004 if (struct_type.fieldIsComptime(ip, field_index)) {
28143 try sema.resolveStructFieldInits(struct_ty);28005 try sema.resolveStructFieldInits(struct_ty);
28144 return Air.internedToRef(struct_type.field_inits.get(ip)[field_index]);28006 return Air.internedToRef(struct_type.field_inits.get(ip)[field_index]);
...@@ -28291,7 +28153,7 @@ fn unionFieldPtr(...@@ -28291,7 +28153,7 @@ fn unionFieldPtr(
2829128153
28292 if (initializing and field_ty.zigTypeTag(mod) == .NoReturn) {28154 if (initializing and field_ty.zigTypeTag(mod) == .NoReturn) {
28293 const msg = msg: {28155 const msg = msg: {
28294 const msg = try sema.errMsg(block, src, "cannot initialize 'noreturn' field of union", .{});28156 const msg = try sema.errMsg(src, "cannot initialize 'noreturn' field of union", .{});
28295 errdefer msg.destroy(sema.gpa);28157 errdefer msg.destroy(sema.gpa);
2829628158
28297 try sema.addFieldErrNote(union_ty, field_index, msg, "field '{}' declared here", .{28159 try sema.addFieldErrNote(union_ty, field_index, msg, "field '{}' declared here", .{
...@@ -28324,7 +28186,7 @@ fn unionFieldPtr(...@@ -28324,7 +28186,7 @@ fn unionFieldPtr(
28324 const msg = msg: {28186 const msg = msg: {
28325 const active_index = Type.fromInterned(union_obj.enum_tag_ty).enumTagFieldIndex(Value.fromInterned(un.tag), mod).?;28187 const active_index = Type.fromInterned(union_obj.enum_tag_ty).enumTagFieldIndex(Value.fromInterned(un.tag), mod).?;
28326 const active_field_name = Type.fromInterned(union_obj.enum_tag_ty).enumFieldName(active_index, mod);28188 const active_field_name = Type.fromInterned(union_obj.enum_tag_ty).enumFieldName(active_index, mod);
28327 const msg = try sema.errMsg(block, src, "access of union field '{}' while field '{}' is active", .{28189 const msg = try sema.errMsg(src, "access of union field '{}' while field '{}' is active", .{
28328 field_name.fmt(ip),28190 field_name.fmt(ip),
28329 active_field_name.fmt(ip),28191 active_field_name.fmt(ip),
28330 });28192 });
...@@ -28392,7 +28254,7 @@ fn unionFieldVal(...@@ -28392,7 +28254,7 @@ fn unionFieldVal(
28392 const msg = msg: {28254 const msg = msg: {
28393 const active_index = Type.fromInterned(union_obj.enum_tag_ty).enumTagFieldIndex(Value.fromInterned(un.tag), zcu).?;28255 const active_index = Type.fromInterned(union_obj.enum_tag_ty).enumTagFieldIndex(Value.fromInterned(un.tag), zcu).?;
28394 const active_field_name = Type.fromInterned(union_obj.enum_tag_ty).enumFieldName(active_index, zcu);28256 const active_field_name = Type.fromInterned(union_obj.enum_tag_ty).enumFieldName(active_index, zcu);
28395 const msg = try sema.errMsg(block, src, "access of union field '{}' while field '{}' is active", .{28257 const msg = try sema.errMsg(src, "access of union field '{}' while field '{}' is active", .{
28396 field_name.fmt(ip), active_field_name.fmt(ip),28258 field_name.fmt(ip), active_field_name.fmt(ip),
28397 });28259 });
28398 errdefer msg.destroy(sema.gpa);28260 errdefer msg.destroy(sema.gpa);
...@@ -28615,15 +28477,13 @@ fn validateRuntimeElemAccess(...@@ -28615,15 +28477,13 @@ fn validateRuntimeElemAccess(
28615 if (try sema.typeRequiresComptime(elem_ty)) {28477 if (try sema.typeRequiresComptime(elem_ty)) {
28616 const msg = msg: {28478 const msg = msg: {
28617 const msg = try sema.errMsg(28479 const msg = try sema.errMsg(
28618 block,
28619 elem_index_src,28480 elem_index_src,
28620 "values of type '{}' must be comptime-known, but index value is runtime-known",28481 "values of type '{}' must be comptime-known, but index value is runtime-known",
28621 .{parent_ty.fmt(mod)},28482 .{parent_ty.fmt(mod)},
28622 );28483 );
28623 errdefer msg.destroy(sema.gpa);28484 errdefer msg.destroy(sema.gpa);
2862428485
28625 const src_decl = mod.declPtr(block.src_decl);28486 try sema.explainWhyTypeIsComptime(msg, parent_src, parent_ty);
28626 try sema.explainWhyTypeIsComptime(msg, src_decl.toSrcLoc(parent_src, mod), parent_ty);
2862728487
28628 break :msg msg;28488 break :msg msg;
28629 };28489 };
...@@ -29011,21 +28871,18 @@ const CoerceOpts = struct {...@@ -29011,21 +28871,18 @@ const CoerceOpts = struct {
29011 func_inst: Air.Inst.Ref = .none,28871 func_inst: Air.Inst.Ref = .none,
29012 param_i: u32 = undefined,28872 param_i: u32 = undefined,
2901328873
29014 fn get(info: @This(), sema: *Sema) !?Module.SrcLoc {28874 fn get(info: @This(), sema: *Sema) !?LazySrcLoc {
29015 if (info.func_inst == .none) return null;28875 if (info.func_inst == .none) return null;
29016 const mod = sema.mod;28876 const fn_decl = try sema.funcDeclSrc(info.func_inst) orelse return null;
29017 const fn_decl = (try sema.funcDeclSrc(info.func_inst)) orelse return null;28877 return .{
29018 const param_src = Module.paramSrc(0, mod, fn_decl, info.param_i);28878 .base_node_inst = fn_decl.zir_decl_index.unwrap().?,
29019 if (param_src == .node_offset_param) {28879 .offset = .{ .fn_proto_param_type = .{
29020 return Module.SrcLoc{28880 .fn_proto_node_offset = 0,
29021 .file_scope = fn_decl.getFileScope(mod),28881 .param_index = info.param_i,
29022 .parent_decl_node = fn_decl.src_node,28882 } },
29023 .lazy = LazySrcLoc.nodeOffset(param_src.node_offset_param),28883 };
29024 };
29025 }
29026 return fn_decl.toSrcLoc(param_src, mod);
29027 }28884 }
29028 } = .{},28885 } = .{ .func_inst = .none, .param_i = undefined },
29029};28886};
2903028887
29031fn coerceExtra(28888fn coerceExtra(
...@@ -29118,7 +28975,7 @@ fn coerceExtra(...@@ -29118,7 +28975,7 @@ fn coerceExtra(
2911828975
29119 // Function body to function pointer.28976 // Function body to function pointer.
29120 if (inst_ty.zigTypeTag(zcu) == .Fn) {28977 if (inst_ty.zigTypeTag(zcu) == .Fn) {
29121 const fn_val = try sema.resolveConstDefinedValue(block, .unneeded, inst, undefined);28978 const fn_val = try sema.resolveConstDefinedValue(block, LazySrcLoc.unneeded, inst, undefined);
29122 const fn_decl = fn_val.pointerDecl(zcu).?;28979 const fn_decl = fn_val.pointerDecl(zcu).?;
29123 const inst_as_ptr = try sema.analyzeDeclRef(fn_decl);28980 const inst_as_ptr = try sema.analyzeDeclRef(fn_decl);
29124 return sema.coerce(block, dest_ty, inst_as_ptr, inst_src);28981 return sema.coerce(block, dest_ty, inst_as_ptr, inst_src);
...@@ -29366,9 +29223,9 @@ fn coerceExtra(...@@ -29366,9 +29223,9 @@ fn coerceExtra(
29366 // pointer to tuple to slice29223 // pointer to tuple to slice
29367 if (!dest_info.flags.is_const) {29224 if (!dest_info.flags.is_const) {
29368 const err_msg = err_msg: {29225 const err_msg = err_msg: {
29369 const err_msg = try sema.errMsg(block, inst_src, "cannot cast pointer to tuple to '{}'", .{dest_ty.fmt(zcu)});29226 const err_msg = try sema.errMsg(inst_src, "cannot cast pointer to tuple to '{}'", .{dest_ty.fmt(zcu)});
29370 errdefer err_msg.destroy(sema.gpa);29227 errdefer err_msg.destroy(sema.gpa);
29371 try sema.errNote(block, dest_ty_src, err_msg, "pointers to tuples can only coerce to constant pointers", .{});29228 try sema.errNote(dest_ty_src, err_msg, "pointers to tuples can only coerce to constant pointers", .{});
29372 break :err_msg err_msg;29229 break :err_msg err_msg;
29373 };29230 };
29374 return sema.failWithOwnedErrorMsg(block, err_msg);29231 return sema.failWithOwnedErrorMsg(block, err_msg);
...@@ -29455,7 +29312,7 @@ fn coerceExtra(...@@ -29455,7 +29312,7 @@ fn coerceExtra(
29455 },29312 },
29456 .Float, .ComptimeFloat => switch (inst_ty.zigTypeTag(zcu)) {29313 .Float, .ComptimeFloat => switch (inst_ty.zigTypeTag(zcu)) {
29457 .ComptimeFloat => {29314 .ComptimeFloat => {
29458 const val = try sema.resolveConstDefinedValue(block, .unneeded, inst, undefined);29315 const val = try sema.resolveConstDefinedValue(block, LazySrcLoc.unneeded, inst, undefined);
29459 const result_val = try val.floatCast(dest_ty, zcu);29316 const result_val = try val.floatCast(dest_ty, zcu);
29460 return Air.internedToRef(result_val.toIntern());29317 return Air.internedToRef(result_val.toIntern());
29461 },29318 },
...@@ -29514,7 +29371,7 @@ fn coerceExtra(...@@ -29514,7 +29371,7 @@ fn coerceExtra(
29514 .Enum => switch (inst_ty.zigTypeTag(zcu)) {29371 .Enum => switch (inst_ty.zigTypeTag(zcu)) {
29515 .EnumLiteral => {29372 .EnumLiteral => {
29516 // enum literal to enum29373 // enum literal to enum
29517 const val = try sema.resolveConstDefinedValue(block, .unneeded, inst, undefined);29374 const val = try sema.resolveConstDefinedValue(block, LazySrcLoc.unneeded, inst, undefined);
29518 const string = zcu.intern_pool.indexToKey(val.toIntern()).enum_literal;29375 const string = zcu.intern_pool.indexToKey(val.toIntern()).enum_literal;
29519 const field_index = dest_ty.enumFieldIndex(string, zcu) orelse {29376 const field_index = dest_ty.enumFieldIndex(string, zcu) orelse {
29520 return sema.fail(block, inst_src, "no field named '{}' in enum '{}'", .{29377 return sema.fail(block, inst_src, "no field named '{}' in enum '{}'", .{
...@@ -29648,54 +29505,58 @@ fn coerceExtra(...@@ -29648,54 +29505,58 @@ fn coerceExtra(
2964829505
29649 if (opts.is_ret and dest_ty.zigTypeTag(zcu) == .NoReturn) {29506 if (opts.is_ret and dest_ty.zigTypeTag(zcu) == .NoReturn) {
29650 const msg = msg: {29507 const msg = msg: {
29651 const msg = try sema.errMsg(block, inst_src, "function declared 'noreturn' returns", .{});29508 const msg = try sema.errMsg(inst_src, "function declared 'noreturn' returns", .{});
29652 errdefer msg.destroy(sema.gpa);29509 errdefer msg.destroy(sema.gpa);
2965329510
29654 const ret_ty_src: LazySrcLoc = .{ .node_offset_fn_type_ret_ty = 0 };29511 const ret_ty_src: LazySrcLoc = .{
29655 const src_decl = zcu.funcOwnerDeclPtr(sema.func_index);29512 .base_node_inst = zcu.funcOwnerDeclPtr(sema.func_index).zir_decl_index.unwrap().?,
29656 try zcu.errNoteNonLazy(src_decl.toSrcLoc(ret_ty_src, zcu), msg, "'noreturn' declared here", .{});29513 .offset = .{ .node_offset_fn_type_ret_ty = 0 },
29514 };
29515 try sema.errNote(ret_ty_src, msg, "'noreturn' declared here", .{});
29657 break :msg msg;29516 break :msg msg;
29658 };29517 };
29659 return sema.failWithOwnedErrorMsg(block, msg);29518 return sema.failWithOwnedErrorMsg(block, msg);
29660 }29519 }
2966129520
29662 const msg = msg: {29521 const msg = msg: {
29663 const msg = try sema.errMsg(block, inst_src, "expected type '{}', found '{}'", .{ dest_ty.fmt(zcu), inst_ty.fmt(zcu) });29522 const msg = try sema.errMsg(inst_src, "expected type '{}', found '{}'", .{ dest_ty.fmt(zcu), inst_ty.fmt(zcu) });
29664 errdefer msg.destroy(sema.gpa);29523 errdefer msg.destroy(sema.gpa);
2966529524
29666 // E!T to T29525 // E!T to T
29667 if (inst_ty.zigTypeTag(zcu) == .ErrorUnion and29526 if (inst_ty.zigTypeTag(zcu) == .ErrorUnion and
29668 (try sema.coerceInMemoryAllowed(block, inst_ty.errorUnionPayload(zcu), dest_ty, false, target, dest_ty_src, inst_src)) == .ok)29527 (try sema.coerceInMemoryAllowed(block, inst_ty.errorUnionPayload(zcu), dest_ty, false, target, dest_ty_src, inst_src)) == .ok)
29669 {29528 {
29670 try sema.errNote(block, inst_src, msg, "cannot convert error union to payload type", .{});29529 try sema.errNote(inst_src, msg, "cannot convert error union to payload type", .{});
29671 try sema.errNote(block, inst_src, msg, "consider using 'try', 'catch', or 'if'", .{});29530 try sema.errNote(inst_src, msg, "consider using 'try', 'catch', or 'if'", .{});
29672 }29531 }
2967329532
29674 // ?T to T29533 // ?T to T
29675 if (inst_ty.zigTypeTag(zcu) == .Optional and29534 if (inst_ty.zigTypeTag(zcu) == .Optional and
29676 (try sema.coerceInMemoryAllowed(block, inst_ty.optionalChild(zcu), dest_ty, false, target, dest_ty_src, inst_src)) == .ok)29535 (try sema.coerceInMemoryAllowed(block, inst_ty.optionalChild(zcu), dest_ty, false, target, dest_ty_src, inst_src)) == .ok)
29677 {29536 {
29678 try sema.errNote(block, inst_src, msg, "cannot convert optional to payload type", .{});29537 try sema.errNote(inst_src, msg, "cannot convert optional to payload type", .{});
29679 try sema.errNote(block, inst_src, msg, "consider using '.?', 'orelse', or 'if'", .{});29538 try sema.errNote(inst_src, msg, "consider using '.?', 'orelse', or 'if'", .{});
29680 }29539 }
2968129540
29682 try in_memory_result.report(sema, block, inst_src, msg);29541 try in_memory_result.report(sema, inst_src, msg);
2968329542
29684 // Add notes about function return type29543 // Add notes about function return type
29685 if (opts.is_ret and29544 if (opts.is_ret and
29686 zcu.test_functions.get(zcu.funcOwnerDeclIndex(sema.func_index)) == null)29545 zcu.test_functions.get(zcu.funcOwnerDeclIndex(sema.func_index)) == null)
29687 {29546 {
29688 const ret_ty_src: LazySrcLoc = .{ .node_offset_fn_type_ret_ty = 0 };29547 const ret_ty_src: LazySrcLoc = .{
29689 const src_decl = zcu.funcOwnerDeclPtr(sema.func_index);29548 .base_node_inst = zcu.funcOwnerDeclPtr(sema.func_index).zir_decl_index.unwrap().?,
29549 .offset = .{ .node_offset_fn_type_ret_ty = 0 },
29550 };
29690 if (inst_ty.isError(zcu) and !dest_ty.isError(zcu)) {29551 if (inst_ty.isError(zcu) and !dest_ty.isError(zcu)) {
29691 try zcu.errNoteNonLazy(src_decl.toSrcLoc(ret_ty_src, zcu), msg, "function cannot return an error", .{});29552 try sema.errNote(ret_ty_src, msg, "function cannot return an error", .{});
29692 } else {29553 } else {
29693 try zcu.errNoteNonLazy(src_decl.toSrcLoc(ret_ty_src, zcu), msg, "function return type declared here", .{});29554 try sema.errNote(ret_ty_src, msg, "function return type declared here", .{});
29694 }29555 }
29695 }29556 }
2969629557
29697 if (try opts.param_src.get(sema)) |param_src| {29558 if (try opts.param_src.get(sema)) |param_src| {
29698 try zcu.errNoteNonLazy(param_src, msg, "parameter type declared here", .{});29559 try sema.errNote(param_src, msg, "parameter type declared here", .{});
29699 }29560 }
2970029561
29701 // TODO maybe add "cannot store an error in type '{}'" note29562 // TODO maybe add "cannot store an error in type '{}'" note
...@@ -29830,7 +29691,7 @@ const InMemoryCoercionResult = union(enum) {...@@ -29830,7 +29691,7 @@ const InMemoryCoercionResult = union(enum) {
29830 return res;29691 return res;
29831 }29692 }
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 {
29834 const mod = sema.mod;29695 const mod = sema.mod;
29835 var cur = res;29696 var cur = res;
29836 while (true) switch (cur.*) {29697 while (true) switch (cur.*) {
...@@ -29841,93 +29702,93 @@ const InMemoryCoercionResult = union(enum) {...@@ -29841,93 +29702,93 @@ const InMemoryCoercionResult = union(enum) {
29841 break;29702 break;
29842 },29703 },
29843 .int_not_coercible => |int| {29704 .int_not_coercible => |int| {
29844 try sema.errNote(block, src, msg, "{s} {d}-bit int cannot represent all possible {s} {d}-bit values", .{29705 try sema.errNote(src, msg, "{s} {d}-bit int cannot represent all possible {s} {d}-bit values", .{
29845 @tagName(int.wanted_signedness), int.wanted_bits, @tagName(int.actual_signedness), int.actual_bits,29706 @tagName(int.wanted_signedness), int.wanted_bits, @tagName(int.actual_signedness), int.actual_bits,
29846 });29707 });
29847 break;29708 break;
29848 },29709 },
29849 .error_union_payload => |pair| {29710 .error_union_payload => |pair| {
29850 try sema.errNote(block, src, msg, "error union payload '{}' cannot cast into error union payload '{}'", .{29711 try sema.errNote(src, msg, "error union payload '{}' cannot cast into error union payload '{}'", .{
29851 pair.actual.fmt(mod), pair.wanted.fmt(mod),29712 pair.actual.fmt(mod), pair.wanted.fmt(mod),
29852 });29713 });
29853 cur = pair.child;29714 cur = pair.child;
29854 },29715 },
29855 .array_len => |lens| {29716 .array_len => |lens| {
29856 try sema.errNote(block, src, msg, "array of length {d} cannot cast into an array of length {d}", .{29717 try sema.errNote(src, msg, "array of length {d} cannot cast into an array of length {d}", .{
29857 lens.actual, lens.wanted,29718 lens.actual, lens.wanted,
29858 });29719 });
29859 break;29720 break;
29860 },29721 },
29861 .array_sentinel => |sentinel| {29722 .array_sentinel => |sentinel| {
29862 if (sentinel.actual.toIntern() != .unreachable_value) {29723 if (sentinel.actual.toIntern() != .unreachable_value) {
29863 try sema.errNote(block, src, msg, "array sentinel '{}' cannot cast into array sentinel '{}'", .{29724 try sema.errNote(src, msg, "array sentinel '{}' cannot cast into array sentinel '{}'", .{
29864 sentinel.actual.fmtValue(mod, sema), sentinel.wanted.fmtValue(mod, sema),29725 sentinel.actual.fmtValue(mod, sema), sentinel.wanted.fmtValue(mod, sema),
29865 });29726 });
29866 } else {29727 } else {
29867 try sema.errNote(block, src, msg, "destination array requires '{}' sentinel", .{29728 try sema.errNote(src, msg, "destination array requires '{}' sentinel", .{
29868 sentinel.wanted.fmtValue(mod, sema),29729 sentinel.wanted.fmtValue(mod, sema),
29869 });29730 });
29870 }29731 }
29871 break;29732 break;
29872 },29733 },
29873 .array_elem => |pair| {29734 .array_elem => |pair| {
29874 try sema.errNote(block, src, msg, "array element type '{}' cannot cast into array element type '{}'", .{29735 try sema.errNote(src, msg, "array element type '{}' cannot cast into array element type '{}'", .{
29875 pair.actual.fmt(mod), pair.wanted.fmt(mod),29736 pair.actual.fmt(mod), pair.wanted.fmt(mod),
29876 });29737 });
29877 cur = pair.child;29738 cur = pair.child;
29878 },29739 },
29879 .vector_len => |lens| {29740 .vector_len => |lens| {
29880 try sema.errNote(block, src, msg, "vector of length {d} cannot cast into a vector of length {d}", .{29741 try sema.errNote(src, msg, "vector of length {d} cannot cast into a vector of length {d}", .{
29881 lens.actual, lens.wanted,29742 lens.actual, lens.wanted,
29882 });29743 });
29883 break;29744 break;
29884 },29745 },
29885 .vector_elem => |pair| {29746 .vector_elem => |pair| {
29886 try sema.errNote(block, src, msg, "vector element type '{}' cannot cast into vector element type '{}'", .{29747 try sema.errNote(src, msg, "vector element type '{}' cannot cast into vector element type '{}'", .{
29887 pair.actual.fmt(mod), pair.wanted.fmt(mod),29748 pair.actual.fmt(mod), pair.wanted.fmt(mod),
29888 });29749 });
29889 cur = pair.child;29750 cur = pair.child;
29890 },29751 },
29891 .optional_shape => |pair| {29752 .optional_shape => |pair| {
29892 try sema.errNote(block, src, msg, "optional type child '{}' cannot cast into optional type child '{}'", .{29753 try sema.errNote(src, msg, "optional type child '{}' cannot cast into optional type child '{}'", .{
29893 pair.actual.optionalChild(mod).fmt(mod), pair.wanted.optionalChild(mod).fmt(mod),29754 pair.actual.optionalChild(mod).fmt(mod), pair.wanted.optionalChild(mod).fmt(mod),
29894 });29755 });
29895 break;29756 break;
29896 },29757 },
29897 .optional_child => |pair| {29758 .optional_child => |pair| {
29898 try sema.errNote(block, src, msg, "optional type child '{}' cannot cast into optional type child '{}'", .{29759 try sema.errNote(src, msg, "optional type child '{}' cannot cast into optional type child '{}'", .{
29899 pair.actual.fmt(mod), pair.wanted.fmt(mod),29760 pair.actual.fmt(mod), pair.wanted.fmt(mod),
29900 });29761 });
29901 cur = pair.child;29762 cur = pair.child;
29902 },29763 },
29903 .from_anyerror => {29764 .from_anyerror => {
29904 try sema.errNote(block, src, msg, "global error set cannot cast into a smaller set", .{});29765 try sema.errNote(src, msg, "global error set cannot cast into a smaller set", .{});
29905 break;29766 break;
29906 },29767 },
29907 .missing_error => |missing_errors| {29768 .missing_error => |missing_errors| {
29908 for (missing_errors) |err| {29769 for (missing_errors) |err| {
29909 try sema.errNote(block, src, msg, "'error.{}' not a member of destination error set", .{err.fmt(&mod.intern_pool)});29770 try sema.errNote(src, msg, "'error.{}' not a member of destination error set", .{err.fmt(&mod.intern_pool)});
29910 }29771 }
29911 break;29772 break;
29912 },29773 },
29913 .fn_var_args => |wanted_var_args| {29774 .fn_var_args => |wanted_var_args| {
29914 if (wanted_var_args) {29775 if (wanted_var_args) {
29915 try sema.errNote(block, src, msg, "non-variadic function cannot cast into a variadic function", .{});29776 try sema.errNote(src, msg, "non-variadic function cannot cast into a variadic function", .{});
29916 } else {29777 } else {
29917 try sema.errNote(block, src, msg, "variadic function cannot cast into a non-variadic function", .{});29778 try sema.errNote(src, msg, "variadic function cannot cast into a non-variadic function", .{});
29918 }29779 }
29919 break;29780 break;
29920 },29781 },
29921 .fn_generic => |wanted_generic| {29782 .fn_generic => |wanted_generic| {
29922 if (wanted_generic) {29783 if (wanted_generic) {
29923 try sema.errNote(block, src, msg, "non-generic function cannot cast into a generic function", .{});29784 try sema.errNote(src, msg, "non-generic function cannot cast into a generic function", .{});
29924 } else {29785 } else {
29925 try sema.errNote(block, src, msg, "generic function cannot cast into a non-generic function", .{});29786 try sema.errNote(src, msg, "generic function cannot cast into a non-generic function", .{});
29926 }29787 }
29927 break;29788 break;
29928 },29789 },
29929 .fn_param_count => |lens| {29790 .fn_param_count => |lens| {
29930 try sema.errNote(block, src, msg, "function with {d} parameters cannot cast into a function with {d} parameters", .{29791 try sema.errNote(src, msg, "function with {d} parameters cannot cast into a function with {d} parameters", .{
29931 lens.actual, lens.wanted,29792 lens.actual, lens.wanted,
29932 });29793 });
29933 break;29794 break;
...@@ -29944,69 +29805,69 @@ const InMemoryCoercionResult = union(enum) {...@@ -29944,69 +29805,69 @@ const InMemoryCoercionResult = union(enum) {
29944 }29805 }
29945 }29806 }
29946 if (!actual_noalias) {29807 if (!actual_noalias) {
29947 try sema.errNote(block, src, msg, "regular parameter {d} cannot cast into a noalias parameter", .{index});29808 try sema.errNote(src, msg, "regular parameter {d} cannot cast into a noalias parameter", .{index});
29948 } else {29809 } else {
29949 try sema.errNote(block, src, msg, "noalias parameter {d} cannot cast into a regular parameter", .{index});29810 try sema.errNote(src, msg, "noalias parameter {d} cannot cast into a regular parameter", .{index});
29950 }29811 }
29951 break;29812 break;
29952 },29813 },
29953 .fn_param_comptime => |param| {29814 .fn_param_comptime => |param| {
29954 if (param.wanted) {29815 if (param.wanted) {
29955 try sema.errNote(block, src, msg, "non-comptime parameter {d} cannot cast into a comptime parameter", .{param.index});29816 try sema.errNote(src, msg, "non-comptime parameter {d} cannot cast into a comptime parameter", .{param.index});
29956 } else {29817 } else {
29957 try sema.errNote(block, src, msg, "comptime parameter {d} cannot cast into a non-comptime parameter", .{param.index});29818 try sema.errNote(src, msg, "comptime parameter {d} cannot cast into a non-comptime parameter", .{param.index});
29958 }29819 }
29959 break;29820 break;
29960 },29821 },
29961 .fn_param => |param| {29822 .fn_param => |param| {
29962 try sema.errNote(block, src, msg, "parameter {d} '{}' cannot cast into '{}'", .{29823 try sema.errNote(src, msg, "parameter {d} '{}' cannot cast into '{}'", .{
29963 param.index, param.actual.fmt(mod), param.wanted.fmt(mod),29824 param.index, param.actual.fmt(mod), param.wanted.fmt(mod),
29964 });29825 });
29965 cur = param.child;29826 cur = param.child;
29966 },29827 },
29967 .fn_cc => |cc| {29828 .fn_cc => |cc| {
29968 try sema.errNote(block, src, msg, "calling convention '{s}' cannot cast into calling convention '{s}'", .{ @tagName(cc.actual), @tagName(cc.wanted) });29829 try sema.errNote(src, msg, "calling convention '{s}' cannot cast into calling convention '{s}'", .{ @tagName(cc.actual), @tagName(cc.wanted) });
29969 break;29830 break;
29970 },29831 },
29971 .fn_return_type => |pair| {29832 .fn_return_type => |pair| {
29972 try sema.errNote(block, src, msg, "return type '{}' cannot cast into return type '{}'", .{29833 try sema.errNote(src, msg, "return type '{}' cannot cast into return type '{}'", .{
29973 pair.actual.fmt(mod), pair.wanted.fmt(mod),29834 pair.actual.fmt(mod), pair.wanted.fmt(mod),
29974 });29835 });
29975 cur = pair.child;29836 cur = pair.child;
29976 },29837 },
29977 .ptr_child => |pair| {29838 .ptr_child => |pair| {
29978 try sema.errNote(block, src, msg, "pointer type child '{}' cannot cast into pointer type child '{}'", .{29839 try sema.errNote(src, msg, "pointer type child '{}' cannot cast into pointer type child '{}'", .{
29979 pair.actual.fmt(mod), pair.wanted.fmt(mod),29840 pair.actual.fmt(mod), pair.wanted.fmt(mod),
29980 });29841 });
29981 cur = pair.child;29842 cur = pair.child;
29982 },29843 },
29983 .ptr_addrspace => |@"addrspace"| {29844 .ptr_addrspace => |@"addrspace"| {
29984 try sema.errNote(block, src, msg, "address space '{s}' cannot cast into address space '{s}'", .{ @tagName(@"addrspace".actual), @tagName(@"addrspace".wanted) });29845 try sema.errNote(src, msg, "address space '{s}' cannot cast into address space '{s}'", .{ @tagName(@"addrspace".actual), @tagName(@"addrspace".wanted) });
29985 break;29846 break;
29986 },29847 },
29987 .ptr_sentinel => |sentinel| {29848 .ptr_sentinel => |sentinel| {
29988 if (sentinel.actual.toIntern() != .unreachable_value) {29849 if (sentinel.actual.toIntern() != .unreachable_value) {
29989 try sema.errNote(block, src, msg, "pointer sentinel '{}' cannot cast into pointer sentinel '{}'", .{29850 try sema.errNote(src, msg, "pointer sentinel '{}' cannot cast into pointer sentinel '{}'", .{
29990 sentinel.actual.fmtValue(mod, sema), sentinel.wanted.fmtValue(mod, sema),29851 sentinel.actual.fmtValue(mod, sema), sentinel.wanted.fmtValue(mod, sema),
29991 });29852 });
29992 } else {29853 } else {
29993 try sema.errNote(block, src, msg, "destination pointer requires '{}' sentinel", .{29854 try sema.errNote(src, msg, "destination pointer requires '{}' sentinel", .{
29994 sentinel.wanted.fmtValue(mod, sema),29855 sentinel.wanted.fmtValue(mod, sema),
29995 });29856 });
29996 }29857 }
29997 break;29858 break;
29998 },29859 },
29999 .ptr_size => |size| {29860 .ptr_size => |size| {
30000 try sema.errNote(block, src, msg, "a {s} pointer cannot cast into a {s} pointer", .{ pointerSizeString(size.actual), pointerSizeString(size.wanted) });29861 try sema.errNote(src, msg, "a {s} pointer cannot cast into a {s} pointer", .{ pointerSizeString(size.actual), pointerSizeString(size.wanted) });
30001 break;29862 break;
30002 },29863 },
30003 .ptr_qualifiers => |qualifiers| {29864 .ptr_qualifiers => |qualifiers| {
30004 const ok_const = !qualifiers.actual_const or qualifiers.wanted_const;29865 const ok_const = !qualifiers.actual_const or qualifiers.wanted_const;
30005 const ok_volatile = !qualifiers.actual_volatile or qualifiers.wanted_volatile;29866 const ok_volatile = !qualifiers.actual_volatile or qualifiers.wanted_volatile;
30006 if (!ok_const) {29867 if (!ok_const) {
30007 try sema.errNote(block, src, msg, "cast discards const qualifier", .{});29868 try sema.errNote(src, msg, "cast discards const qualifier", .{});
30008 } else if (!ok_volatile) {29869 } else if (!ok_volatile) {
30009 try sema.errNote(block, src, msg, "cast discards volatile qualifier", .{});29870 try sema.errNote(src, msg, "cast discards volatile qualifier", .{});
30010 }29871 }
30011 break;29872 break;
30012 },29873 },
...@@ -30014,11 +29875,11 @@ const InMemoryCoercionResult = union(enum) {...@@ -30014,11 +29875,11 @@ const InMemoryCoercionResult = union(enum) {
30014 const wanted_allow_zero = pair.wanted.ptrAllowsZero(mod);29875 const wanted_allow_zero = pair.wanted.ptrAllowsZero(mod);
30015 const actual_allow_zero = pair.actual.ptrAllowsZero(mod);29876 const actual_allow_zero = pair.actual.ptrAllowsZero(mod);
30016 if (actual_allow_zero and !wanted_allow_zero) {29877 if (actual_allow_zero and !wanted_allow_zero) {
30017 try sema.errNote(block, src, msg, "'{}' could have null values which are illegal in type '{}'", .{29878 try sema.errNote(src, msg, "'{}' could have null values which are illegal in type '{}'", .{
30018 pair.actual.fmt(mod), pair.wanted.fmt(mod),29879 pair.actual.fmt(mod), pair.wanted.fmt(mod),
30019 });29880 });
30020 } else {29881 } else {
30021 try sema.errNote(block, src, msg, "mutable '{}' allows illegal null values stored to type '{}'", .{29882 try sema.errNote(src, msg, "mutable '{}' allows illegal null values stored to type '{}'", .{
30022 pair.actual.fmt(mod), pair.wanted.fmt(mod),29883 pair.actual.fmt(mod), pair.wanted.fmt(mod),
30023 });29884 });
30024 }29885 }
...@@ -30026,34 +29887,34 @@ const InMemoryCoercionResult = union(enum) {...@@ -30026,34 +29887,34 @@ const InMemoryCoercionResult = union(enum) {
30026 },29887 },
30027 .ptr_bit_range => |bit_range| {29888 .ptr_bit_range => |bit_range| {
30028 if (bit_range.actual_host != bit_range.wanted_host) {29889 if (bit_range.actual_host != bit_range.wanted_host) {
30029 try sema.errNote(block, src, msg, "pointer host size '{}' cannot cast into pointer host size '{}'", .{29890 try sema.errNote(src, msg, "pointer host size '{}' cannot cast into pointer host size '{}'", .{
30030 bit_range.actual_host, bit_range.wanted_host,29891 bit_range.actual_host, bit_range.wanted_host,
30031 });29892 });
30032 }29893 }
30033 if (bit_range.actual_offset != bit_range.wanted_offset) {29894 if (bit_range.actual_offset != bit_range.wanted_offset) {
30034 try sema.errNote(block, src, msg, "pointer bit offset '{}' cannot cast into pointer bit offset '{}'", .{29895 try sema.errNote(src, msg, "pointer bit offset '{}' cannot cast into pointer bit offset '{}'", .{
30035 bit_range.actual_offset, bit_range.wanted_offset,29896 bit_range.actual_offset, bit_range.wanted_offset,
30036 });29897 });
30037 }29898 }
30038 break;29899 break;
30039 },29900 },
30040 .ptr_alignment => |pair| {29901 .ptr_alignment => |pair| {
30041 try sema.errNote(block, src, msg, "pointer alignment '{d}' cannot cast into pointer alignment '{d}'", .{29902 try sema.errNote(src, msg, "pointer alignment '{d}' cannot cast into pointer alignment '{d}'", .{
30042 pair.actual.toByteUnits() orelse 0, pair.wanted.toByteUnits() orelse 0,29903 pair.actual.toByteUnits() orelse 0, pair.wanted.toByteUnits() orelse 0,
30043 });29904 });
30044 break;29905 break;
30045 },29906 },
30046 .double_ptr_to_anyopaque => |pair| {29907 .double_ptr_to_anyopaque => |pair| {
30047 try sema.errNote(block, src, msg, "cannot implicitly cast double pointer '{}' to anyopaque pointer '{}'", .{29908 try sema.errNote(src, msg, "cannot implicitly cast double pointer '{}' to anyopaque pointer '{}'", .{
30048 pair.actual.fmt(mod), pair.wanted.fmt(mod),29909 pair.actual.fmt(mod), pair.wanted.fmt(mod),
30049 });29910 });
30050 break;29911 break;
30051 },29912 },
30052 .slice_to_anyopaque => |pair| {29913 .slice_to_anyopaque => |pair| {
30053 try sema.errNote(block, src, msg, "cannot implicitly cast slice '{}' to anyopaque pointer '{}'", .{29914 try sema.errNote(src, msg, "cannot implicitly cast slice '{}' to anyopaque pointer '{}'", .{
30054 pair.actual.fmt(mod), pair.wanted.fmt(mod),29915 pair.actual.fmt(mod), pair.wanted.fmt(mod),
30055 });29916 });
30056 try sema.errNote(block, src, msg, "consider using '.ptr'", .{});29917 try sema.errNote(src, msg, "consider using '.ptr'", .{});
30057 break;29918 break;
30058 },29919 },
30059 };29920 };
...@@ -30667,7 +30528,7 @@ fn coerceVarArgParam(...@@ -30667,7 +30528,7 @@ fn coerceVarArgParam(
30667 .{},30528 .{},
30668 ),30529 ),
30669 .Fn => fn_ptr: {30530 .Fn => fn_ptr: {
30670 const fn_val = try sema.resolveConstDefinedValue(block, .unneeded, inst, undefined);30531 const fn_val = try sema.resolveConstDefinedValue(block, LazySrcLoc.unneeded, inst, undefined);
30671 const fn_decl = fn_val.pointerDecl(mod).?;30532 const fn_decl = fn_val.pointerDecl(mod).?;
30672 break :fn_ptr try sema.analyzeDeclRef(fn_decl);30533 break :fn_ptr try sema.analyzeDeclRef(fn_decl);
30673 },30534 },
...@@ -30715,11 +30576,10 @@ fn coerceVarArgParam(...@@ -30715,11 +30576,10 @@ fn coerceVarArgParam(
30715 const coerced_ty = sema.typeOf(coerced);30576 const coerced_ty = sema.typeOf(coerced);
30716 if (!try sema.validateExternType(coerced_ty, .param_ty)) {30577 if (!try sema.validateExternType(coerced_ty, .param_ty)) {
30717 const msg = msg: {30578 const msg = msg: {
30718 const msg = try sema.errMsg(block, inst_src, "cannot pass '{}' to variadic function", .{coerced_ty.fmt(sema.mod)});30579 const msg = try sema.errMsg(inst_src, "cannot pass '{}' to variadic function", .{coerced_ty.fmt(sema.mod)});
30719 errdefer msg.destroy(sema.gpa);30580 errdefer msg.destroy(sema.gpa);
3072030581
30721 const src_decl = sema.mod.declPtr(block.src_decl);30582 try sema.explainWhyTypeIsNotExtern(msg, inst_src, coerced_ty, .param_ty);
30722 try sema.explainWhyTypeIsNotExtern(msg, src_decl.toSrcLoc(inst_src, mod), coerced_ty, .param_ty);
3072330583
30724 try sema.addDeclaredHereNote(msg, coerced_ty);30584 try sema.addDeclaredHereNote(msg, coerced_ty);
30725 break :msg msg;30585 break :msg msg;
...@@ -30879,7 +30739,6 @@ fn checkComptimeKnownStore(sema: *Sema, block: *Block, store_inst_ref: Air.Inst....@@ -30879,7 +30739,6 @@ fn checkComptimeKnownStore(sema: *Sema, block: *Block, store_inst_ref: Air.Inst.
30879 {30739 {
30880 try maybe_comptime_alloc.stores.append(sema.arena, .{30740 try maybe_comptime_alloc.stores.append(sema.arena, .{
30881 .inst = store_inst,30741 .inst = store_inst,
30882 .src_decl = block.src_decl,
30883 .src = store_src,30742 .src = store_src,
30884 });30743 });
30885 return;30744 return;
...@@ -30913,8 +30772,7 @@ fn checkKnownAllocPtr(sema: *Sema, block: *Block, base_ptr: Air.Inst.Ref, new_pt...@@ -30913,8 +30772,7 @@ fn checkKnownAllocPtr(sema: *Sema, block: *Block, base_ptr: Air.Inst.Ref, new_pt
3091330772
30914 try maybe_comptime_alloc.stores.append(sema.arena, .{30773 try maybe_comptime_alloc.stores.append(sema.arena, .{
30915 .inst = new_ptr_inst,30774 .inst = new_ptr_inst,
30916 .src_decl = block.src_decl,30775 .src = LazySrcLoc.unneeded,
30917 .src = .unneeded,
30918 });30776 });
30919 },30777 },
30920 .ptr_elem_ptr => {30778 .ptr_elem_ptr => {
...@@ -30937,10 +30795,9 @@ fn markMaybeComptimeAllocRuntime(sema: *Sema, block: *Block, alloc_inst: Air.Ins...@@ -30937,10 +30795,9 @@ fn markMaybeComptimeAllocRuntime(sema: *Sema, block: *Block, alloc_inst: Air.Ins
30937 const maybe_comptime_alloc = (sema.maybe_comptime_allocs.fetchRemove(alloc_inst) orelse return).value;30795 const maybe_comptime_alloc = (sema.maybe_comptime_allocs.fetchRemove(alloc_inst) orelse return).value;
30938 // Since the alloc has been determined to be runtime, we must check that30796 // Since the alloc has been determined to be runtime, we must check that
30939 // all other stores to it are permitted to be runtime values.30797 // all other stores to it are permitted to be runtime values.
30940 const mod = sema.mod;
30941 const slice = maybe_comptime_alloc.stores.slice();30798 const slice = maybe_comptime_alloc.stores.slice();
30942 for (slice.items(.inst), slice.items(.src_decl), slice.items(.src)) |other_inst, other_src_decl, other_src| {30799 for (slice.items(.inst), slice.items(.src)) |other_inst, other_src| {
30943 if (other_src == .unneeded) {30800 if (other_src.offset == .unneeded) {
30944 switch (sema.air_instructions.items(.tag)[@intFromEnum(other_inst)]) {30801 switch (sema.air_instructions.items(.tag)[@intFromEnum(other_inst)]) {
30945 .set_union_tag, .optional_payload_ptr_set, .errunion_payload_ptr_set => continue,30802 .set_union_tag, .optional_payload_ptr_set, .errunion_payload_ptr_set => continue,
30946 else => unreachable, // assertion failure30803 else => unreachable, // assertion failure
...@@ -30950,10 +30807,9 @@ fn markMaybeComptimeAllocRuntime(sema: *Sema, block: *Block, alloc_inst: Air.Ins...@@ -30950,10 +30807,9 @@ fn markMaybeComptimeAllocRuntime(sema: *Sema, block: *Block, alloc_inst: Air.Ins
30950 const other_operand = other_data.rhs;30807 const other_operand = other_data.rhs;
30951 if (!sema.checkRuntimeValue(other_operand)) {30808 if (!sema.checkRuntimeValue(other_operand)) {
30952 return sema.failWithOwnedErrorMsg(block, msg: {30809 return sema.failWithOwnedErrorMsg(block, msg: {
30953 const other_src_resolved = mod.declPtr(other_src_decl).toSrcLoc(other_src, mod);30810 const msg = try sema.errMsg(other_src, "runtime value contains reference to comptime var", .{});
30954 const msg = try Module.ErrorMsg.create(sema.gpa, other_src_resolved, "runtime value contains reference to comptime var", .{});
30955 errdefer msg.destroy(sema.gpa);30811 errdefer msg.destroy(sema.gpa);
30956 try mod.errNoteNonLazy(other_src_resolved, msg, "comptime var pointers are not available at runtime", .{});30812 try sema.errNote(other_src, msg, "comptime var pointers are not available at runtime", .{});
30957 break :msg msg;30813 break :msg msg;
30958 });30814 });
30959 }30815 }
...@@ -31215,11 +31071,11 @@ fn coerceEnumToUnion(...@@ -31215,11 +31071,11 @@ fn coerceEnumToUnion(
3121531071
31216 const tag_ty = union_ty.unionTagType(mod) orelse {31072 const tag_ty = union_ty.unionTagType(mod) orelse {
31217 const msg = msg: {31073 const msg = msg: {
31218 const msg = try sema.errMsg(block, inst_src, "expected type '{}', found '{}'", .{31074 const msg = try sema.errMsg(inst_src, "expected type '{}', found '{}'", .{
31219 union_ty.fmt(sema.mod), inst_ty.fmt(sema.mod),31075 union_ty.fmt(sema.mod), inst_ty.fmt(sema.mod),
31220 });31076 });
31221 errdefer msg.destroy(sema.gpa);31077 errdefer msg.destroy(sema.gpa);
31222 try sema.errNote(block, union_ty_src, msg, "cannot coerce enum to untagged union", .{});31078 try sema.errNote(union_ty_src, msg, "cannot coerce enum to untagged union", .{});
31223 try sema.addDeclaredHereNote(msg, union_ty);31079 try sema.addDeclaredHereNote(msg, union_ty);
31224 break :msg msg;31080 break :msg msg;
31225 };31081 };
...@@ -31239,7 +31095,7 @@ fn coerceEnumToUnion(...@@ -31239,7 +31095,7 @@ fn coerceEnumToUnion(
31239 try sema.resolveTypeFields(field_ty);31095 try sema.resolveTypeFields(field_ty);
31240 if (field_ty.zigTypeTag(mod) == .NoReturn) {31096 if (field_ty.zigTypeTag(mod) == .NoReturn) {
31241 const msg = msg: {31097 const msg = msg: {
31242 const msg = try sema.errMsg(block, inst_src, "cannot initialize 'noreturn' field of union", .{});31098 const msg = try sema.errMsg(inst_src, "cannot initialize 'noreturn' field of union", .{});
31243 errdefer msg.destroy(sema.gpa);31099 errdefer msg.destroy(sema.gpa);
3124431100
31245 const field_name = union_obj.loadTagType(ip).names.get(ip)[field_index];31101 const field_name = union_obj.loadTagType(ip).names.get(ip)[field_index];
...@@ -31254,7 +31110,7 @@ fn coerceEnumToUnion(...@@ -31254,7 +31110,7 @@ fn coerceEnumToUnion(
31254 const opv = (try sema.typeHasOnePossibleValue(field_ty)) orelse {31110 const opv = (try sema.typeHasOnePossibleValue(field_ty)) orelse {
31255 const msg = msg: {31111 const msg = msg: {
31256 const field_name = union_obj.loadTagType(ip).names.get(ip)[field_index];31112 const field_name = union_obj.loadTagType(ip).names.get(ip)[field_index];
31257 const msg = try sema.errMsg(block, inst_src, "coercion from enum '{}' to union '{}' must initialize '{}' field '{}'", .{31113 const msg = try sema.errMsg(inst_src, "coercion from enum '{}' to union '{}' must initialize '{}' field '{}'", .{
31258 inst_ty.fmt(sema.mod), union_ty.fmt(sema.mod),31114 inst_ty.fmt(sema.mod), union_ty.fmt(sema.mod),
31259 field_ty.fmt(sema.mod), field_name.fmt(ip),31115 field_ty.fmt(sema.mod), field_name.fmt(ip),
31260 });31116 });
...@@ -31276,7 +31132,7 @@ fn coerceEnumToUnion(...@@ -31276,7 +31132,7 @@ fn coerceEnumToUnion(
3127631132
31277 if (tag_ty.isNonexhaustiveEnum(mod)) {31133 if (tag_ty.isNonexhaustiveEnum(mod)) {
31278 const msg = msg: {31134 const msg = msg: {
31279 const msg = try sema.errMsg(block, inst_src, "runtime coercion to union '{}' from non-exhaustive enum", .{31135 const msg = try sema.errMsg(inst_src, "runtime coercion to union '{}' from non-exhaustive enum", .{
31280 union_ty.fmt(sema.mod),31136 union_ty.fmt(sema.mod),
31281 });31137 });
31282 errdefer msg.destroy(sema.gpa);31138 errdefer msg.destroy(sema.gpa);
...@@ -31294,7 +31150,6 @@ fn coerceEnumToUnion(...@@ -31294,7 +31150,6 @@ fn coerceEnumToUnion(
31294 for (union_obj.field_types.get(ip), 0..) |field_ty, field_index| {31150 for (union_obj.field_types.get(ip), 0..) |field_ty, field_index| {
31295 if (Type.fromInterned(field_ty).zigTypeTag(mod) == .NoReturn) {31151 if (Type.fromInterned(field_ty).zigTypeTag(mod) == .NoReturn) {
31296 const err_msg = msg orelse try sema.errMsg(31152 const err_msg = msg orelse try sema.errMsg(
31297 block,
31298 inst_src,31153 inst_src,
31299 "runtime coercion from enum '{}' to union '{}' which has a 'noreturn' field",31154 "runtime coercion from enum '{}' to union '{}' which has a 'noreturn' field",
31300 .{ tag_ty.fmt(sema.mod), union_ty.fmt(sema.mod) },31155 .{ tag_ty.fmt(sema.mod), union_ty.fmt(sema.mod) },
...@@ -31318,7 +31173,6 @@ fn coerceEnumToUnion(...@@ -31318,7 +31173,6 @@ fn coerceEnumToUnion(
3131831173
31319 const msg = msg: {31174 const msg = msg: {
31320 const msg = try sema.errMsg(31175 const msg = try sema.errMsg(
31321 block,
31322 inst_src,31176 inst_src,
31323 "runtime coercion from enum '{}' to union '{}' which has non-void fields",31177 "runtime coercion from enum '{}' to union '{}' which has non-void fields",
31324 .{ tag_ty.fmt(sema.mod), union_ty.fmt(sema.mod) },31178 .{ tag_ty.fmt(sema.mod), union_ty.fmt(sema.mod) },
...@@ -31377,12 +31231,10 @@ fn coerceAnonStructToUnion(...@@ -31377,12 +31231,10 @@ fn coerceAnonStructToUnion(
31377 assert(field_count != 1);31231 assert(field_count != 1);
31378 const msg = msg: {31232 const msg = msg: {
31379 const msg = if (field_count > 1) try sema.errMsg(31233 const msg = if (field_count > 1) try sema.errMsg(
31380 block,
31381 inst_src,31234 inst_src,
31382 "cannot initialize multiple union fields at once; unions can only have one active field",31235 "cannot initialize multiple union fields at once; unions can only have one active field",
31383 .{},31236 .{},
31384 ) else try sema.errMsg(31237 ) else try sema.errMsg(
31385 block,
31386 inst_src,31238 inst_src,
31387 "union initializer must initialize one field",31239 "union initializer must initialize one field",
31388 .{},31240 .{},
...@@ -31459,12 +31311,12 @@ fn coerceArrayLike(...@@ -31459,12 +31311,12 @@ fn coerceArrayLike(
31459 const dest_len = try sema.usizeCast(block, dest_ty_src, dest_ty.arrayLen(mod));31311 const dest_len = try sema.usizeCast(block, dest_ty_src, dest_ty.arrayLen(mod));
31460 if (dest_len != inst_len) {31312 if (dest_len != inst_len) {
31461 const msg = msg: {31313 const msg = msg: {
31462 const msg = try sema.errMsg(block, inst_src, "expected type '{}', found '{}'", .{31314 const msg = try sema.errMsg(inst_src, "expected type '{}', found '{}'", .{
31463 dest_ty.fmt(mod), inst_ty.fmt(mod),31315 dest_ty.fmt(mod), inst_ty.fmt(mod),
31464 });31316 });
31465 errdefer msg.destroy(sema.gpa);31317 errdefer msg.destroy(sema.gpa);
31466 try sema.errNote(block, dest_ty_src, msg, "destination has length {d}", .{dest_len});31318 try sema.errNote(dest_ty_src, msg, "destination has length {d}", .{dest_len});
31467 try sema.errNote(block, inst_src, msg, "source has length {d}", .{inst_len});31319 try sema.errNote(inst_src, msg, "source has length {d}", .{inst_len});
31468 break :msg msg;31320 break :msg msg;
31469 };31321 };
31470 return sema.failWithOwnedErrorMsg(block, msg);31322 return sema.failWithOwnedErrorMsg(block, msg);
...@@ -31546,12 +31398,12 @@ fn coerceTupleToArray(...@@ -31546,12 +31398,12 @@ fn coerceTupleToArray(
3154631398
31547 if (dest_len != inst_len) {31399 if (dest_len != inst_len) {
31548 const msg = msg: {31400 const msg = msg: {
31549 const msg = try sema.errMsg(block, inst_src, "expected type '{}', found '{}'", .{31401 const msg = try sema.errMsg(inst_src, "expected type '{}', found '{}'", .{
31550 dest_ty.fmt(sema.mod), inst_ty.fmt(sema.mod),31402 dest_ty.fmt(sema.mod), inst_ty.fmt(sema.mod),
31551 });31403 });
31552 errdefer msg.destroy(sema.gpa);31404 errdefer msg.destroy(sema.gpa);
31553 try sema.errNote(block, dest_ty_src, msg, "destination has length {d}", .{dest_len});31405 try sema.errNote(dest_ty_src, msg, "destination has length {d}", .{dest_len});
31554 try sema.errNote(block, inst_src, msg, "source has length {d}", .{inst_len});31406 try sema.errNote(inst_src, msg, "source has length {d}", .{inst_len});
31555 break :msg msg;31407 break :msg msg;
31556 };31408 };
31557 return sema.failWithOwnedErrorMsg(block, msg);31409 return sema.failWithOwnedErrorMsg(block, msg);
...@@ -31722,9 +31574,9 @@ fn coerceTupleToStruct(...@@ -31722,9 +31574,9 @@ fn coerceTupleToStruct(
31722 const template = "missing struct field: {}";31574 const template = "missing struct field: {}";
31723 const args = .{field_name.fmt(ip)};31575 const args = .{field_name.fmt(ip)};
31724 if (root_msg) |msg| {31576 if (root_msg) |msg| {
31725 try sema.errNote(block, field_src, msg, template, args);31577 try sema.errNote(field_src, msg, template, args);
31726 } else {31578 } else {
31727 root_msg = try sema.errMsg(block, field_src, template, args);31579 root_msg = try sema.errMsg(field_src, template, args);
31728 }31580 }
31729 continue;31581 continue;
31730 }31582 }
...@@ -31860,18 +31712,18 @@ fn coerceTupleToTuple(...@@ -31860,18 +31712,18 @@ fn coerceTupleToTuple(
31860 const field_name = tuple_ty.structFieldName(i, mod).unwrap() orelse {31712 const field_name = tuple_ty.structFieldName(i, mod).unwrap() orelse {
31861 const template = "missing tuple field: {d}";31713 const template = "missing tuple field: {d}";
31862 if (root_msg) |msg| {31714 if (root_msg) |msg| {
31863 try sema.errNote(block, field_src, msg, template, .{i});31715 try sema.errNote(field_src, msg, template, .{i});
31864 } else {31716 } else {
31865 root_msg = try sema.errMsg(block, field_src, template, .{i});31717 root_msg = try sema.errMsg(field_src, template, .{i});
31866 }31718 }
31867 continue;31719 continue;
31868 };31720 };
31869 const template = "missing struct field: {}";31721 const template = "missing struct field: {}";
31870 const args = .{field_name.fmt(ip)};31722 const args = .{field_name.fmt(ip)};
31871 if (root_msg) |msg| {31723 if (root_msg) |msg| {
31872 try sema.errNote(block, field_src, msg, template, args);31724 try sema.errNote(field_src, msg, template, args);
31873 } else {31725 } else {
31874 root_msg = try sema.errMsg(block, field_src, template, args);31726 root_msg = try sema.errMsg(field_src, template, args);
31875 }31727 }
31876 continue;31728 continue;
31877 }31729 }
...@@ -31926,14 +31778,6 @@ fn addReferencedBy(...@@ -31926,14 +31778,6 @@ fn addReferencedBy(
31926 decl_index: InternPool.DeclIndex,31778 decl_index: InternPool.DeclIndex,
31927) !void {31779) !void {
31928 if (sema.mod.comp.reference_trace == 0) return;31780 if (sema.mod.comp.reference_trace == 0) return;
31929 if (src == .unneeded) {
31930 // We can't use NeededSourceLocation, since sites handling that assume it means a compile
31931 // error. Our long-term strategy here is to gradually transition from NeededSourceLocation
31932 // into having more LazySrcLoc tags. In the meantime, let release compilers just ignore this
31933 // reference (a slightly-incomplete error is better than a crash!), but trigger a panic in
31934 // debug so we can fix this case.
31935 if (std.debug.runtime_safety) unreachable else return;
31936 }
31937 try sema.mod.reference_table.put(sema.gpa, decl_index, .{31781 try sema.mod.reference_table.put(sema.gpa, decl_index, .{
31938 .referencer = block.src_decl,31782 .referencer = block.src_decl,
31939 .src = src,31783 .src = src,
...@@ -31945,7 +31789,10 @@ pub fn ensureDeclAnalyzed(sema: *Sema, decl_index: InternPool.DeclIndex) Compile...@@ -31945,7 +31789,10 @@ pub fn ensureDeclAnalyzed(sema: *Sema, decl_index: InternPool.DeclIndex) Compile
31945 const ip = &mod.intern_pool;31789 const ip = &mod.intern_pool;
31946 const decl = mod.declPtr(decl_index);31790 const decl = mod.declPtr(decl_index);
31947 if (decl.analysis == .in_progress) {31791 if (decl.analysis == .in_progress) {
31948 const msg = try Module.ErrorMsg.create(sema.gpa, decl.srcLoc(mod), "dependency loop detected", .{});31792 const msg = try sema.errMsg(.{
31793 .base_node_inst = decl.zir_decl_index.unwrap().?,
31794 .offset = LazySrcLoc.Offset.nodeOffset(0),
31795 }, "dependency loop detected", .{});
31949 return sema.failWithOwnedErrorMsg(null, msg);31796 return sema.failWithOwnedErrorMsg(null, msg);
31950 }31797 }
3195131798
...@@ -32440,10 +32287,9 @@ fn analyzeSlice(...@@ -32440,10 +32287,9 @@ fn analyzeSlice(
32440 if (try sema.compareScalar(start_value, .neq, end_value, Type.comptime_int)) {32287 if (try sema.compareScalar(start_value, .neq, end_value, Type.comptime_int)) {
32441 if (try sema.compareScalar(start_value, .neq, Value.zero_comptime_int, Type.comptime_int)) {32288 if (try sema.compareScalar(start_value, .neq, Value.zero_comptime_int, Type.comptime_int)) {
32442 const msg = msg: {32289 const msg = msg: {
32443 const msg = try sema.errMsg(block, start_src, bounds_error_message, .{});32290 const msg = try sema.errMsg(start_src, bounds_error_message, .{});
32444 errdefer msg.destroy(sema.gpa);32291 errdefer msg.destroy(sema.gpa);
32445 try sema.errNote(32292 try sema.errNote(
32446 block,
32447 start_src,32293 start_src,
32448 msg,32294 msg,
32449 "expected '{}', found '{}'",32295 "expected '{}', found '{}'",
...@@ -32457,10 +32303,9 @@ fn analyzeSlice(...@@ -32457,10 +32303,9 @@ fn analyzeSlice(
32457 return sema.failWithOwnedErrorMsg(block, msg);32303 return sema.failWithOwnedErrorMsg(block, msg);
32458 } else if (try sema.compareScalar(end_value, .neq, Value.one_comptime_int, Type.comptime_int)) {32304 } else if (try sema.compareScalar(end_value, .neq, Value.one_comptime_int, Type.comptime_int)) {
32459 const msg = msg: {32305 const msg = msg: {
32460 const msg = try sema.errMsg(block, end_src, bounds_error_message, .{});32306 const msg = try sema.errMsg(end_src, bounds_error_message, .{});
32461 errdefer msg.destroy(sema.gpa);32307 errdefer msg.destroy(sema.gpa);
32462 try sema.errNote(32308 try sema.errNote(
32463 block,
32464 end_src,32309 end_src,
32465 msg,32310 msg,
32466 "expected '{}', found '{}'",32311 "expected '{}', found '{}'",
...@@ -32714,9 +32559,9 @@ fn analyzeSlice(...@@ -32714,9 +32559,9 @@ fn analyzeSlice(
3271432559
32715 if (!actual_sentinel.eql(expected_sentinel, elem_ty, mod)) {32560 if (!actual_sentinel.eql(expected_sentinel, elem_ty, mod)) {
32716 const msg = msg: {32561 const msg = msg: {
32717 const msg = try sema.errMsg(block, src, "value in memory does not match slice sentinel", .{});32562 const msg = try sema.errMsg(src, "value in memory does not match slice sentinel", .{});
32718 errdefer msg.destroy(sema.gpa);32563 errdefer msg.destroy(sema.gpa);
32719 try sema.errNote(block, src, msg, "expected '{}', found '{}'", .{32564 try sema.errNote(src, msg, "expected '{}', found '{}'", .{
32720 expected_sentinel.fmtValue(mod, sema),32565 expected_sentinel.fmtValue(mod, sema),
32721 actual_sentinel.fmtValue(mod, sema),32566 actual_sentinel.fmtValue(mod, sema),
32722 });32567 });
...@@ -33588,6 +33433,31 @@ const PeerResolveStrategy = enum {...@@ -33588,6 +33433,31 @@ const PeerResolveStrategy = enum {
33588 }33433 }
33589};33434};
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
33591const PeerResolveResult = union(enum) {33461const PeerResolveResult = union(enum) {
33592 /// The peer type resolution was successful, and resulted in the given type.33462 /// The peer type resolution was successful, and resulted in the given type.
33593 success: Type,33463 success: Type,
...@@ -33612,10 +33482,9 @@ const PeerResolveResult = union(enum) {...@@ -33612,10 +33482,9 @@ const PeerResolveResult = union(enum) {
33612 block: *Block,33482 block: *Block,
33613 src: LazySrcLoc,33483 src: LazySrcLoc,
33614 instructions: []const Air.Inst.Ref,33484 instructions: []const Air.Inst.Ref,
33615 candidate_srcs: Module.PeerTypeCandidateSrc,33485 candidate_srcs: PeerTypeCandidateSrc,
33616 ) !*Module.ErrorMsg {33486 ) !*Module.ErrorMsg {
33617 const mod = sema.mod;33487 const mod = sema.mod;
33618 const decl_ptr = mod.declPtr(block.src_decl);
3361933488
33620 var opt_msg: ?*Module.ErrorMsg = null;33489 var opt_msg: ?*Module.ErrorMsg = null;
33621 errdefer if (opt_msg) |msg| msg.destroy(sema.gpa);33490 errdefer if (opt_msg) |msg| msg.destroy(sema.gpa);
...@@ -33643,9 +33512,9 @@ const PeerResolveResult = union(enum) {...@@ -33643,9 +33512,9 @@ const PeerResolveResult = union(enum) {
33643 const fmt = "struct field '{}' has conflicting types";33512 const fmt = "struct field '{}' has conflicting types";
33644 const args = .{field_error.field_name.fmt(&mod.intern_pool)};33513 const args = .{field_error.field_name.fmt(&mod.intern_pool)};
33645 if (opt_msg) |msg| {33514 if (opt_msg) |msg| {
33646 try sema.errNote(block, src, msg, fmt, args);33515 try sema.errNote(src, msg, fmt, args);
33647 } else {33516 } else {
33648 opt_msg = try sema.errMsg(block, src, fmt, args);33517 opt_msg = try sema.errMsg(src, fmt, args);
33649 }33518 }
3365033519
33651 // Continue on to child error33520 // Continue on to child error
...@@ -33667,8 +33536,8 @@ const PeerResolveResult = union(enum) {...@@ -33667,8 +33536,8 @@ const PeerResolveResult = union(enum) {
33667 peer_tys[conflict_idx[1]],33536 peer_tys[conflict_idx[1]],
33668 };33537 };
33669 const conflict_srcs: [2]?LazySrcLoc = .{33538 const conflict_srcs: [2]?LazySrcLoc = .{
33670 candidate_srcs.resolve(mod, decl_ptr, conflict_idx[0]),33539 candidate_srcs.resolve(block, conflict_idx[0]),
33671 candidate_srcs.resolve(mod, decl_ptr, conflict_idx[1]),33540 candidate_srcs.resolve(block, conflict_idx[1]),
33672 };33541 };
3367333542
33674 const fmt = "incompatible types: '{}' and '{}'";33543 const fmt = "incompatible types: '{}' and '{}'";
...@@ -33677,16 +33546,16 @@ const PeerResolveResult = union(enum) {...@@ -33677,16 +33546,16 @@ const PeerResolveResult = union(enum) {
33677 conflict_tys[1].fmt(mod),33546 conflict_tys[1].fmt(mod),
33678 };33547 };
33679 const msg = if (opt_msg) |msg| msg: {33548 const msg = if (opt_msg) |msg| msg: {
33680 try sema.errNote(block, src, msg, fmt, args);33549 try sema.errNote(src, msg, fmt, args);
33681 break :msg msg;33550 break :msg msg;
33682 } else msg: {33551 } else msg: {
33683 const msg = try sema.errMsg(block, src, fmt, args);33552 const msg = try sema.errMsg(src, fmt, args);
33684 opt_msg = msg;33553 opt_msg = msg;
33685 break :msg msg;33554 break :msg msg;
33686 };33555 };
3368733556
33688 if (conflict_srcs[0]) |src_loc| try sema.errNote(block, src_loc, msg, "type '{}' here", .{conflict_tys[0].fmt(mod)});33557 if (conflict_srcs[0]) |src_loc| try sema.errNote(src_loc, msg, "type '{}' here", .{conflict_tys[0].fmt(mod)});
33689 if (conflict_srcs[1]) |src_loc| try sema.errNote(block, src_loc, msg, "type '{}' here", .{conflict_tys[1].fmt(mod)});33558 if (conflict_srcs[1]) |src_loc| try sema.errNote(src_loc, msg, "type '{}' here", .{conflict_tys[1].fmt(mod)});
3369033559
33691 // No child error33560 // No child error
33692 break;33561 break;
...@@ -33701,7 +33570,7 @@ fn resolvePeerTypes(...@@ -33701,7 +33570,7 @@ fn resolvePeerTypes(
33701 block: *Block,33570 block: *Block,
33702 src: LazySrcLoc,33571 src: LazySrcLoc,
33703 instructions: []const Air.Inst.Ref,33572 instructions: []const Air.Inst.Ref,
33704 candidate_srcs: Module.PeerTypeCandidateSrc,33573 candidate_srcs: PeerTypeCandidateSrc,
33705) !Type {33574) !Type {
33706 switch (instructions.len) {33575 switch (instructions.len) {
33707 0 => return Type.noreturn,33576 0 => return Type.noreturn,
...@@ -35140,9 +35009,9 @@ pub fn resolveStructAlignment(...@@ -35140,9 +35009,9 @@ pub fn resolveStructAlignment(
35140}35009}
3514135010
35142fn resolveStructLayout(sema: *Sema, ty: Type) CompileError!void {35011fn resolveStructLayout(sema: *Sema, ty: Type) CompileError!void {
35143 const mod = sema.mod;35012 const zcu = sema.mod;
35144 const ip = &mod.intern_pool;35013 const ip = &zcu.intern_pool;
35145 const struct_type = mod.typeToStruct(ty) orelse return;35014 const struct_type = zcu.typeToStruct(ty) orelse return;
3514635015
35147 if (struct_type.haveLayout(ip))35016 if (struct_type.haveLayout(ip))
35148 return;35017 return;
...@@ -35150,16 +35019,15 @@ fn resolveStructLayout(sema: *Sema, ty: Type) CompileError!void {...@@ -35150,16 +35019,15 @@ fn resolveStructLayout(sema: *Sema, ty: Type) CompileError!void {
35150 try sema.resolveTypeFields(ty);35019 try sema.resolveTypeFields(ty);
3515135020
35152 if (struct_type.layout == .@"packed") {35021 if (struct_type.layout == .@"packed") {
35153 try semaBackingIntType(mod, struct_type);35022 try semaBackingIntType(zcu, struct_type);
35154 return;35023 return;
35155 }35024 }
3515635025
35157 if (struct_type.setLayoutWip(ip)) {35026 if (struct_type.setLayoutWip(ip)) {
35158 const msg = try Module.ErrorMsg.create(35027 const msg = try sema.errMsg(
35159 sema.gpa,35028 ty.srcLoc(zcu),
35160 mod.declPtr(struct_type.decl.unwrap().?).srcLoc(mod),
35161 "struct '{}' depends on itself",35029 "struct '{}' depends on itself",
35162 .{ty.fmt(mod)},35030 .{ty.fmt(zcu)},
35163 );35031 );
35164 return sema.failWithOwnedErrorMsg(null, msg);35032 return sema.failWithOwnedErrorMsg(null, msg);
35165 }35033 }
...@@ -35196,9 +35064,8 @@ fn resolveStructLayout(sema: *Sema, ty: Type) CompileError!void {...@@ -35196,9 +35064,8 @@ fn resolveStructLayout(sema: *Sema, ty: Type) CompileError!void {
35196 }35064 }
3519735065
35198 if (struct_type.flagsPtr(ip).assumed_runtime_bits and !(try sema.typeHasRuntimeBits(ty))) {35066 if (struct_type.flagsPtr(ip).assumed_runtime_bits and !(try sema.typeHasRuntimeBits(ty))) {
35199 const msg = try Module.ErrorMsg.create(35067 const msg = try sema.errMsg(
35200 sema.gpa,35068 ty.srcLoc(zcu),
35201 mod.declPtr(struct_type.decl.unwrap().?).srcLoc(mod),
35202 "struct layout depends on it having runtime bits",35069 "struct layout depends on it having runtime bits",
35203 .{},35070 .{},
35204 );35071 );
...@@ -35206,11 +35073,10 @@ fn resolveStructLayout(sema: *Sema, ty: Type) CompileError!void {...@@ -35206,11 +35073,10 @@ fn resolveStructLayout(sema: *Sema, ty: Type) CompileError!void {
35206 }35073 }
3520735074
35208 if (struct_type.flagsPtr(ip).assumed_pointer_aligned and35075 if (struct_type.flagsPtr(ip).assumed_pointer_aligned and
35209 big_align.compareStrict(.neq, Alignment.fromByteUnits(@divExact(mod.getTarget().ptrBitWidth(), 8))))35076 big_align.compareStrict(.neq, Alignment.fromByteUnits(@divExact(zcu.getTarget().ptrBitWidth(), 8))))
35210 {35077 {
35211 const msg = try Module.ErrorMsg.create(35078 const msg = try sema.errMsg(
35212 sema.gpa,35079 ty.srcLoc(zcu),
35213 mod.declPtr(struct_type.decl.unwrap().?).srcLoc(mod),
35214 "struct layout depends on being pointer aligned",35080 "struct layout depends on being pointer aligned",
35215 .{},35081 .{},
35216 );35082 );
...@@ -35242,7 +35108,7 @@ fn resolveStructLayout(sema: *Sema, ty: Type) CompileError!void {...@@ -35242,7 +35108,7 @@ fn resolveStructLayout(sema: *Sema, ty: Type) CompileError!void {
35242 return a_align.compare(.gt, b_align);35108 return a_align.compare(.gt, b_align);
35243 }35109 }
35244 };35110 };
35245 if (struct_type.isTuple(ip) or !mod.backendSupportsFeature(.field_reordering)) {35111 if (struct_type.isTuple(ip) or !zcu.backendSupportsFeature(.field_reordering)) {
35246 // TODO: don't handle tuples differently. This logic exists only because it35112 // TODO: don't handle tuples differently. This logic exists only because it
35247 // uncovers latent bugs if removed. Fix the latent bugs and remove this logic!35113 // uncovers latent bugs if removed. Fix the latent bugs and remove this logic!
35248 // Likewise, implement field reordering support in all the backends!35114 // Likewise, implement field reordering support in all the backends!
...@@ -35293,7 +35159,7 @@ fn semaBackingIntType(mod: *Module, struct_type: InternPool.LoadedStructType) Co...@@ -35293,7 +35159,7 @@ fn semaBackingIntType(mod: *Module, struct_type: InternPool.LoadedStructType) Co
35293 var analysis_arena = std.heap.ArenaAllocator.init(gpa);35159 var analysis_arena = std.heap.ArenaAllocator.init(gpa);
35294 defer analysis_arena.deinit();35160 defer analysis_arena.deinit();
3529535161
35296 var comptime_err_ret_trace = std.ArrayList(Module.SrcLoc).init(gpa);35162 var comptime_err_ret_trace = std.ArrayList(LazySrcLoc).init(gpa);
35297 defer comptime_err_ret_trace.deinit();35163 defer comptime_err_ret_trace.deinit();
3529835164
35299 var sema: Sema = .{35165 var sema: Sema = .{
...@@ -35320,6 +35186,7 @@ fn semaBackingIntType(mod: *Module, struct_type: InternPool.LoadedStructType) Co...@@ -35320,6 +35186,7 @@ fn semaBackingIntType(mod: *Module, struct_type: InternPool.LoadedStructType) Co
35320 .instructions = .{},35186 .instructions = .{},
35321 .inlining = null,35187 .inlining = null,
35322 .is_comptime = true,35188 .is_comptime = true,
35189 .src_base_inst = struct_type.zir_index.unwrap().?,
35323 };35190 };
35324 defer assert(block.instructions.items.len == 0);35191 defer assert(block.instructions.items.len == 0);
3532535192
...@@ -35352,7 +35219,10 @@ fn semaBackingIntType(mod: *Module, struct_type: InternPool.LoadedStructType) Co...@@ -35352,7 +35219,10 @@ fn semaBackingIntType(mod: *Module, struct_type: InternPool.LoadedStructType) Co
35352 const backing_int_body_len = zir.extra[extra_index];35219 const backing_int_body_len = zir.extra[extra_index];
35353 extra_index += 1;35220 extra_index += 1;
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 };
35356 const backing_int_ty = blk: {35226 const backing_int_ty = blk: {
35357 if (backing_int_body_len == 0) {35227 if (backing_int_body_len == 0) {
35358 const backing_int_ref: Zir.Inst.Ref = @enumFromInt(zir.extra[extra_index]);35228 const backing_int_ref: Zir.Inst.Ref = @enumFromInt(zir.extra[extra_index]);
...@@ -35368,7 +35238,7 @@ fn semaBackingIntType(mod: *Module, struct_type: InternPool.LoadedStructType) Co...@@ -35368,7 +35238,7 @@ fn semaBackingIntType(mod: *Module, struct_type: InternPool.LoadedStructType) Co
35368 struct_type.backingIntType(ip).* = backing_int_ty.toIntern();35238 struct_type.backingIntType(ip).* = backing_int_ty.toIntern();
35369 } else {35239 } else {
35370 if (fields_bit_sum > std.math.maxInt(u16)) {35240 if (fields_bit_sum > std.math.maxInt(u16)) {
35371 return sema.fail(&block, LazySrcLoc.nodeOffset(0), "size of packed struct '{d}' exceeds maximum bit width of 65535", .{fields_bit_sum});35241 return sema.fail(&block, block.nodeOffset(0), "size of packed struct '{d}' exceeds maximum bit width of 65535", .{fields_bit_sum});
35372 }35242 }
35373 const backing_int_ty = try mod.intType(.unsigned, @intCast(fields_bit_sum));35243 const backing_int_ty = try mod.intType(.unsigned, @intCast(fields_bit_sum));
35374 struct_type.backingIntType(ip).* = backing_int_ty.toIntern();35244 struct_type.backingIntType(ip).* = backing_int_ty.toIntern();
...@@ -35395,9 +35265,9 @@ fn checkIndexable(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) !void {...@@ -35395,9 +35265,9 @@ fn checkIndexable(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) !void {
35395 const mod = sema.mod;35265 const mod = sema.mod;
35396 if (!ty.isIndexable(mod)) {35266 if (!ty.isIndexable(mod)) {
35397 const msg = msg: {35267 const msg = msg: {
35398 const msg = try sema.errMsg(block, src, "type '{}' does not support indexing", .{ty.fmt(sema.mod)});35268 const msg = try sema.errMsg(src, "type '{}' does not support indexing", .{ty.fmt(sema.mod)});
35399 errdefer msg.destroy(sema.gpa);35269 errdefer msg.destroy(sema.gpa);
35400 try sema.errNote(block, src, msg, "operand must be an array, slice, tuple, or vector", .{});35270 try sema.errNote(src, msg, "operand must be an array, slice, tuple, or vector", .{});
35401 break :msg msg;35271 break :msg msg;
35402 };35272 };
35403 return sema.failWithOwnedErrorMsg(block, msg);35273 return sema.failWithOwnedErrorMsg(block, msg);
...@@ -35418,9 +35288,9 @@ fn checkMemOperand(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) !void...@@ -35418,9 +35288,9 @@ fn checkMemOperand(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) !void
35418 }35288 }
35419 }35289 }
35420 const msg = msg: {35290 const msg = msg: {
35421 const msg = try sema.errMsg(block, src, "type '{}' is not an indexable pointer", .{ty.fmt(sema.mod)});35291 const msg = try sema.errMsg(src, "type '{}' is not an indexable pointer", .{ty.fmt(sema.mod)});
35422 errdefer msg.destroy(sema.gpa);35292 errdefer msg.destroy(sema.gpa);
35423 try sema.errNote(block, src, msg, "operand must be a slice, a many pointer or a pointer to an array", .{});35293 try sema.errNote(src, msg, "operand must be a slice, a many pointer or a pointer to an array", .{});
35424 break :msg msg;35294 break :msg msg;
35425 };35295 };
35426 return sema.failWithOwnedErrorMsg(block, msg);35296 return sema.failWithOwnedErrorMsg(block, msg);
...@@ -35471,8 +35341,8 @@ pub fn resolveUnionAlignment(...@@ -35471,8 +35341,8 @@ pub fn resolveUnionAlignment(
3547135341
35472/// This logic must be kept in sync with `Module.getUnionLayout`.35342/// This logic must be kept in sync with `Module.getUnionLayout`.
35473fn resolveUnionLayout(sema: *Sema, ty: Type) CompileError!void {35343fn resolveUnionLayout(sema: *Sema, ty: Type) CompileError!void {
35474 const mod = sema.mod;35344 const zcu = sema.mod;
35475 const ip = &mod.intern_pool;35345 const ip = &zcu.intern_pool;
3547635346
35477 try sema.resolveTypeFieldsUnion(ty, ip.loadUnionType(ty.ip_index));35347 try sema.resolveTypeFieldsUnion(ty, ip.loadUnionType(ty.ip_index));
3547835348
...@@ -35482,11 +35352,10 @@ fn resolveUnionLayout(sema: *Sema, ty: Type) CompileError!void {...@@ -35482,11 +35352,10 @@ fn resolveUnionLayout(sema: *Sema, ty: Type) CompileError!void {
35482 switch (union_type.flagsPtr(ip).status) {35352 switch (union_type.flagsPtr(ip).status) {
35483 .none, .have_field_types => {},35353 .none, .have_field_types => {},
35484 .field_types_wip, .layout_wip => {35354 .field_types_wip, .layout_wip => {
35485 const msg = try Module.ErrorMsg.create(35355 const msg = try sema.errMsg(
35486 sema.gpa,35356 ty.srcLoc(zcu),
35487 mod.declPtr(union_type.decl).srcLoc(mod),
35488 "union '{}' depends on itself",35357 "union '{}' depends on itself",
35489 .{ty.fmt(mod)},35358 .{ty.fmt(zcu)},
35490 );35359 );
35491 return sema.failWithOwnedErrorMsg(null, msg);35360 return sema.failWithOwnedErrorMsg(null, msg);
35492 },35361 },
...@@ -35505,7 +35374,7 @@ fn resolveUnionLayout(sema: *Sema, ty: Type) CompileError!void {...@@ -35505,7 +35374,7 @@ fn resolveUnionLayout(sema: *Sema, ty: Type) CompileError!void {
35505 for (0..union_type.field_types.len) |field_index| {35374 for (0..union_type.field_types.len) |field_index| {
35506 const field_ty = Type.fromInterned(union_type.field_types.get(ip)[field_index]);35375 const field_ty = Type.fromInterned(union_type.field_types.get(ip)[field_index]);
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
35510 max_size = @max(max_size, sema.typeAbiSize(field_ty) catch |err| switch (err) {35379 max_size = @max(max_size, sema.typeAbiSize(field_ty) catch |err| switch (err) {
35511 error.AnalysisFail => {35380 error.AnalysisFail => {
...@@ -35547,7 +35416,7 @@ fn resolveUnionLayout(sema: *Sema, ty: Type) CompileError!void {...@@ -35547,7 +35416,7 @@ fn resolveUnionLayout(sema: *Sema, ty: Type) CompileError!void {
35547 } else {35416 } else {
35548 // {Payload, Tag}35417 // {Payload, Tag}
35549 size += max_size;35418 size += max_size;
35550 size = switch (mod.getTarget().ofmt) {35419 size = switch (zcu.getTarget().ofmt) {
35551 .c => max_align,35420 .c => max_align,
35552 else => tag_align,35421 else => tag_align,
35553 }.forward(size);35422 }.forward(size);
...@@ -35566,9 +35435,8 @@ fn resolveUnionLayout(sema: *Sema, ty: Type) CompileError!void {...@@ -35566,9 +35435,8 @@ fn resolveUnionLayout(sema: *Sema, ty: Type) CompileError!void {
35566 flags.status = .have_layout;35435 flags.status = .have_layout;
3556735436
35568 if (union_type.flagsPtr(ip).assumed_runtime_bits and !(try sema.typeHasRuntimeBits(ty))) {35437 if (union_type.flagsPtr(ip).assumed_runtime_bits and !(try sema.typeHasRuntimeBits(ty))) {
35569 const msg = try Module.ErrorMsg.create(35438 const msg = try sema.errMsg(
35570 sema.gpa,35439 ty.srcLoc(zcu),
35571 mod.declPtr(union_type.decl).srcLoc(mod),
35572 "union layout depends on it having runtime bits",35440 "union layout depends on it having runtime bits",
35573 .{},35441 .{},
35574 );35442 );
...@@ -35576,11 +35444,10 @@ fn resolveUnionLayout(sema: *Sema, ty: Type) CompileError!void {...@@ -35576,11 +35444,10 @@ fn resolveUnionLayout(sema: *Sema, ty: Type) CompileError!void {
35576 }35444 }
3557735445
35578 if (union_type.flagsPtr(ip).assumed_pointer_aligned and35446 if (union_type.flagsPtr(ip).assumed_pointer_aligned and
35579 alignment.compareStrict(.neq, Alignment.fromByteUnits(@divExact(mod.getTarget().ptrBitWidth(), 8))))35447 alignment.compareStrict(.neq, Alignment.fromByteUnits(@divExact(zcu.getTarget().ptrBitWidth(), 8))))
35580 {35448 {
35581 const msg = try Module.ErrorMsg.create(35449 const msg = try sema.errMsg(
35582 sema.gpa,35450 ty.srcLoc(zcu),
35583 mod.declPtr(union_type.decl).srcLoc(mod),
35584 "union layout depends on being pointer aligned",35451 "union layout depends on being pointer aligned",
35585 .{},35452 .{},
35586 );35453 );
...@@ -35804,12 +35671,12 @@ pub fn resolveTypeFieldsStruct(...@@ -35804,12 +35671,12 @@ pub fn resolveTypeFieldsStruct(
35804 ty: InternPool.Index,35671 ty: InternPool.Index,
35805 struct_type: InternPool.LoadedStructType,35672 struct_type: InternPool.LoadedStructType,
35806) CompileError!void {35673) CompileError!void {
35807 const mod = sema.mod;35674 const zcu = sema.mod;
35808 const ip = &mod.intern_pool;35675 const ip = &zcu.intern_pool;
35809 // If there is no owner decl it means the struct has no fields.35676 // If there is no owner decl it means the struct has no fields.
35810 const owner_decl = struct_type.decl.unwrap() orelse return;35677 const owner_decl = struct_type.decl.unwrap() orelse return;
3581135678
35812 switch (mod.declPtr(owner_decl).analysis) {35679 switch (zcu.declPtr(owner_decl).analysis) {
35813 .file_failure,35680 .file_failure,
35814 .dependency_failure,35681 .dependency_failure,
35815 .sema_failure,35682 .sema_failure,
...@@ -35823,20 +35690,19 @@ pub fn resolveTypeFieldsStruct(...@@ -35823,20 +35690,19 @@ pub fn resolveTypeFieldsStruct(
35823 if (struct_type.haveFieldTypes(ip)) return;35690 if (struct_type.haveFieldTypes(ip)) return;
3582435691
35825 if (struct_type.setTypesWip(ip)) {35692 if (struct_type.setTypesWip(ip)) {
35826 const msg = try Module.ErrorMsg.create(35693 const msg = try sema.errMsg(
35827 sema.gpa,35694 Type.fromInterned(ty).srcLoc(zcu),
35828 mod.declPtr(owner_decl).srcLoc(mod),
35829 "struct '{}' depends on itself",35695 "struct '{}' depends on itself",
35830 .{Type.fromInterned(ty).fmt(mod)},35696 .{Type.fromInterned(ty).fmt(zcu)},
35831 );35697 );
35832 return sema.failWithOwnedErrorMsg(null, msg);35698 return sema.failWithOwnedErrorMsg(null, msg);
35833 }35699 }
35834 defer struct_type.clearTypesWip(ip);35700 defer struct_type.clearTypesWip(ip);
3583535701
35836 semaStructFields(mod, sema.arena, struct_type) catch |err| switch (err) {35702 semaStructFields(zcu, sema.arena, struct_type) catch |err| switch (err) {
35837 error.AnalysisFail => {35703 error.AnalysisFail => {
35838 if (mod.declPtr(owner_decl).analysis == .complete) {35704 if (zcu.declPtr(owner_decl).analysis == .complete) {
35839 mod.declPtr(owner_decl).analysis = .dependency_failure;35705 zcu.declPtr(owner_decl).analysis = .dependency_failure;
35840 }35706 }
35841 return error.AnalysisFail;35707 return error.AnalysisFail;
35842 },35708 },
...@@ -35845,9 +35711,9 @@ pub fn resolveTypeFieldsStruct(...@@ -35845,9 +35711,9 @@ pub fn resolveTypeFieldsStruct(
35845}35711}
3584635712
35847pub fn resolveStructFieldInits(sema: *Sema, ty: Type) CompileError!void {35713pub fn resolveStructFieldInits(sema: *Sema, ty: Type) CompileError!void {
35848 const mod = sema.mod;35714 const zcu = sema.mod;
35849 const ip = &mod.intern_pool;35715 const ip = &zcu.intern_pool;
35850 const struct_type = mod.typeToStruct(ty) orelse return;35716 const struct_type = zcu.typeToStruct(ty) orelse return;
35851 const owner_decl = struct_type.decl.unwrap() orelse return;35717 const owner_decl = struct_type.decl.unwrap() orelse return;
3585235718
35853 // Inits can start as resolved35719 // Inits can start as resolved
...@@ -35856,20 +35722,19 @@ pub fn resolveStructFieldInits(sema: *Sema, ty: Type) CompileError!void {...@@ -35856,20 +35722,19 @@ pub fn resolveStructFieldInits(sema: *Sema, ty: Type) CompileError!void {
35856 try sema.resolveStructLayout(ty);35722 try sema.resolveStructLayout(ty);
3585735723
35858 if (struct_type.setInitsWip(ip)) {35724 if (struct_type.setInitsWip(ip)) {
35859 const msg = try Module.ErrorMsg.create(35725 const msg = try sema.errMsg(
35860 sema.gpa,35726 ty.srcLoc(zcu),
35861 mod.declPtr(owner_decl).srcLoc(mod),
35862 "struct '{}' depends on itself",35727 "struct '{}' depends on itself",
35863 .{ty.fmt(mod)},35728 .{ty.fmt(zcu)},
35864 );35729 );
35865 return sema.failWithOwnedErrorMsg(null, msg);35730 return sema.failWithOwnedErrorMsg(null, msg);
35866 }35731 }
35867 defer struct_type.clearInitsWip(ip);35732 defer struct_type.clearInitsWip(ip);
3586835733
35869 semaStructFieldInits(mod, sema.arena, struct_type) catch |err| switch (err) {35734 semaStructFieldInits(zcu, sema.arena, struct_type) catch |err| switch (err) {
35870 error.AnalysisFail => {35735 error.AnalysisFail => {
35871 if (mod.declPtr(owner_decl).analysis == .complete) {35736 if (zcu.declPtr(owner_decl).analysis == .complete) {
35872 mod.declPtr(owner_decl).analysis = .dependency_failure;35737 zcu.declPtr(owner_decl).analysis = .dependency_failure;
35873 }35738 }
35874 return error.AnalysisFail;35739 return error.AnalysisFail;
35875 },35740 },
...@@ -35879,9 +35744,9 @@ pub fn resolveStructFieldInits(sema: *Sema, ty: Type) CompileError!void {...@@ -35879,9 +35744,9 @@ pub fn resolveStructFieldInits(sema: *Sema, ty: Type) CompileError!void {
35879}35744}
3588035745
35881pub fn resolveTypeFieldsUnion(sema: *Sema, ty: Type, union_type: InternPool.LoadedUnionType) CompileError!void {35746pub fn resolveTypeFieldsUnion(sema: *Sema, ty: Type, union_type: InternPool.LoadedUnionType) CompileError!void {
35882 const mod = sema.mod;35747 const zcu = sema.mod;
35883 const ip = &mod.intern_pool;35748 const ip = &zcu.intern_pool;
35884 const owner_decl = mod.declPtr(union_type.decl);35749 const owner_decl = zcu.declPtr(union_type.decl);
35885 switch (owner_decl.analysis) {35750 switch (owner_decl.analysis) {
35886 .file_failure,35751 .file_failure,
35887 .dependency_failure,35752 .dependency_failure,
...@@ -35895,11 +35760,10 @@ pub fn resolveTypeFieldsUnion(sema: *Sema, ty: Type, union_type: InternPool.Load...@@ -35895,11 +35760,10 @@ pub fn resolveTypeFieldsUnion(sema: *Sema, ty: Type, union_type: InternPool.Load
35895 switch (union_type.flagsPtr(ip).status) {35760 switch (union_type.flagsPtr(ip).status) {
35896 .none => {},35761 .none => {},
35897 .field_types_wip => {35762 .field_types_wip => {
35898 const msg = try Module.ErrorMsg.create(35763 const msg = try sema.errMsg(
35899 sema.gpa,35764 ty.srcLoc(zcu),
35900 owner_decl.srcLoc(mod),
35901 "union '{}' depends on itself",35765 "union '{}' depends on itself",
35902 .{ty.fmt(mod)},35766 .{ty.fmt(zcu)},
35903 );35767 );
35904 return sema.failWithOwnedErrorMsg(null, msg);35768 return sema.failWithOwnedErrorMsg(null, msg);
35905 },35769 },
...@@ -35913,7 +35777,7 @@ pub fn resolveTypeFieldsUnion(sema: *Sema, ty: Type, union_type: InternPool.Load...@@ -35913,7 +35777,7 @@ pub fn resolveTypeFieldsUnion(sema: *Sema, ty: Type, union_type: InternPool.Load
3591335777
35914 union_type.flagsPtr(ip).status = .field_types_wip;35778 union_type.flagsPtr(ip).status = .field_types_wip;
35915 errdefer union_type.flagsPtr(ip).status = .none;35779 errdefer union_type.flagsPtr(ip).status = .none;
35916 semaUnionFields(mod, sema.arena, union_type) catch |err| switch (err) {35780 semaUnionFields(zcu, sema.arena, union_type) catch |err| switch (err) {
35917 error.AnalysisFail => {35781 error.AnalysisFail => {
35918 if (owner_decl.analysis == .complete) {35782 if (owner_decl.analysis == .complete) {
35919 owner_decl.analysis = .dependency_failure;35783 owner_decl.analysis = .dependency_failure;
...@@ -35963,10 +35827,13 @@ fn resolveInferredErrorSet(...@@ -35963,10 +35827,13 @@ fn resolveInferredErrorSet(
35963 } else if (ip.errorUnionSet(ies_func_info.return_type) == ies_index) {35827 } else if (ip.errorUnionSet(ies_func_info.return_type) == ies_index) {
35964 if (ies_func_info.is_generic) {35828 if (ies_func_info.is_generic) {
35965 const msg = msg: {35829 const msg = msg: {
35966 const msg = try sema.errMsg(block, src, "unable to resolve inferred error set of generic function", .{});35830 const msg = try sema.errMsg(src, "unable to resolve inferred error set of generic function", .{});
35967 errdefer msg.destroy(sema.gpa);35831 errdefer msg.destroy(sema.gpa);
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", .{});
35970 break :msg msg;35837 break :msg msg;
35971 };35838 };
35972 return sema.failWithOwnedErrorMsg(block, msg);35839 return sema.failWithOwnedErrorMsg(block, msg);
...@@ -36147,7 +36014,7 @@ fn semaStructFields(...@@ -36147,7 +36014,7 @@ fn semaStructFields(
36147 },36014 },
36148 };36015 };
3614936016
36150 var comptime_err_ret_trace = std.ArrayList(Module.SrcLoc).init(gpa);36017 var comptime_err_ret_trace = std.ArrayList(LazySrcLoc).init(gpa);
36151 defer comptime_err_ret_trace.deinit();36018 defer comptime_err_ret_trace.deinit();
3615236019
36153 var sema: Sema = .{36020 var sema: Sema = .{
...@@ -36174,6 +36041,7 @@ fn semaStructFields(...@@ -36174,6 +36041,7 @@ fn semaStructFields(
36174 .instructions = .{},36041 .instructions = .{},
36175 .inlining = null,36042 .inlining = null,
36176 .is_comptime = true,36043 .is_comptime = true,
36044 .src_base_inst = struct_type.zir_index.unwrap().?,
36177 };36045 };
36178 defer assert(block_scope.instructions.items.len == 0);36046 defer assert(block_scope.instructions.items.len == 0);
3617936047
...@@ -36252,35 +36120,19 @@ fn semaStructFields(...@@ -36252,35 +36120,19 @@ fn semaStructFields(
36252 // so that init values may depend on type layout.36120 // so that init values may depend on type layout.
3625336121
36254 for (fields, 0..) |zir_field, field_i| {36122 for (fields, 0..) |zir_field, field_i| {
36123 const ty_src: LazySrcLoc = .{
36124 .base_node_inst = struct_type.zir_index.unwrap().?,
36125 .offset = .{ .container_field_type = @intCast(field_i) },
36126 };
36255 const field_ty: Type = ty: {36127 const field_ty: Type = ty: {
36256 if (zir_field.type_ref != .none) {36128 if (zir_field.type_ref != .none) {
36257 break :ty sema.resolveType(&block_scope, .unneeded, zir_field.type_ref) catch |err| switch (err) {36129 break :ty try sema.resolveType(&block_scope, ty_src, zir_field.type_ref);
36258 error.NeededSourceLocation => {
36259 const ty_src = mod.fieldSrcLoc(decl_index, .{
36260 .index = field_i,
36261 .range = .type,
36262 }).lazy;
36263 _ = try sema.resolveType(&block_scope, ty_src, zir_field.type_ref);
36264 unreachable;
36265 },
36266 else => |e| return e,
36267 };
36268 }36130 }
36269 assert(zir_field.type_body_len != 0);36131 assert(zir_field.type_body_len != 0);
36270 const body = zir.bodySlice(extra_index, zir_field.type_body_len);36132 const body = zir.bodySlice(extra_index, zir_field.type_body_len);
36271 extra_index += body.len;36133 extra_index += body.len;
36272 const ty_ref = try sema.resolveInlineBody(&block_scope, body, zir_index);36134 const ty_ref = try sema.resolveInlineBody(&block_scope, body, zir_index);
36273 break :ty sema.analyzeAsType(&block_scope, .unneeded, ty_ref) catch |err| switch (err) {36135 break :ty try sema.analyzeAsType(&block_scope, ty_src, ty_ref);
36274 error.NeededSourceLocation => {
36275 const ty_src = mod.fieldSrcLoc(decl_index, .{
36276 .index = field_i,
36277 .range = .type,
36278 }).lazy;
36279 _ = try sema.analyzeAsType(&block_scope, ty_src, ty_ref);
36280 unreachable;
36281 },
36282 else => |e| return e,
36283 };
36284 };36136 };
36285 if (field_ty.isGenericPoison()) {36137 if (field_ty.isGenericPoison()) {
36286 return error.GenericPoison;36138 return error.GenericPoison;
...@@ -36290,11 +36142,7 @@ fn semaStructFields(...@@ -36290,11 +36142,7 @@ fn semaStructFields(
3629036142
36291 if (field_ty.zigTypeTag(mod) == .Opaque) {36143 if (field_ty.zigTypeTag(mod) == .Opaque) {
36292 const msg = msg: {36144 const msg = msg: {
36293 const ty_src = mod.fieldSrcLoc(decl_index, .{36145 const msg = try sema.errMsg(ty_src, "opaque types have unknown size and therefore cannot be directly embedded in structs", .{});
36294 .index = field_i,
36295 .range = .type,
36296 }).lazy;
36297 const msg = try sema.errMsg(&block_scope, ty_src, "opaque types have unknown size and therefore cannot be directly embedded in structs", .{});
36298 errdefer msg.destroy(sema.gpa);36146 errdefer msg.destroy(sema.gpa);
3629936147
36300 try sema.addDeclaredHereNote(msg, field_ty);36148 try sema.addDeclaredHereNote(msg, field_ty);
...@@ -36304,11 +36152,7 @@ fn semaStructFields(...@@ -36304,11 +36152,7 @@ fn semaStructFields(
36304 }36152 }
36305 if (field_ty.zigTypeTag(mod) == .NoReturn) {36153 if (field_ty.zigTypeTag(mod) == .NoReturn) {
36306 const msg = msg: {36154 const msg = msg: {
36307 const ty_src = mod.fieldSrcLoc(decl_index, .{36155 const msg = try sema.errMsg(ty_src, "struct fields cannot be 'noreturn'", .{});
36308 .index = field_i,
36309 .range = .type,
36310 }).lazy;
36311 const msg = try sema.errMsg(&block_scope, ty_src, "struct fields cannot be 'noreturn'", .{});
36312 errdefer msg.destroy(sema.gpa);36156 errdefer msg.destroy(sema.gpa);
3631336157
36314 try sema.addDeclaredHereNote(msg, field_ty);36158 try sema.addDeclaredHereNote(msg, field_ty);
...@@ -36319,11 +36163,7 @@ fn semaStructFields(...@@ -36319,11 +36163,7 @@ fn semaStructFields(
36319 switch (struct_type.layout) {36163 switch (struct_type.layout) {
36320 .@"extern" => if (!try sema.validateExternType(field_ty, .struct_field)) {36164 .@"extern" => if (!try sema.validateExternType(field_ty, .struct_field)) {
36321 const msg = msg: {36165 const msg = msg: {
36322 const ty_src = mod.fieldSrcLoc(decl_index, .{36166 const msg = try sema.errMsg(ty_src, "extern structs cannot contain fields of type '{}'", .{field_ty.fmt(mod)});
36323 .index = field_i,
36324 .range = .type,
36325 });
36326 const msg = try sema.errMsg(&block_scope, ty_src.lazy, "extern structs cannot contain fields of type '{}'", .{field_ty.fmt(mod)});
36327 errdefer msg.destroy(sema.gpa);36167 errdefer msg.destroy(sema.gpa);
3632836168
36329 try sema.explainWhyTypeIsNotExtern(msg, ty_src, field_ty, .struct_field);36169 try sema.explainWhyTypeIsNotExtern(msg, ty_src, field_ty, .struct_field);
...@@ -36335,11 +36175,7 @@ fn semaStructFields(...@@ -36335,11 +36175,7 @@ fn semaStructFields(
36335 },36175 },
36336 .@"packed" => if (!try sema.validatePackedType(field_ty)) {36176 .@"packed" => if (!try sema.validatePackedType(field_ty)) {
36337 const msg = msg: {36177 const msg = msg: {
36338 const ty_src = mod.fieldSrcLoc(decl_index, .{36178 const msg = try sema.errMsg(ty_src, "packed structs cannot contain fields of type '{}'", .{field_ty.fmt(mod)});
36339 .index = field_i,
36340 .range = .type,
36341 });
36342 const msg = try sema.errMsg(&block_scope, ty_src.lazy, "packed structs cannot contain fields of type '{}'", .{field_ty.fmt(mod)});
36343 errdefer msg.destroy(sema.gpa);36179 errdefer msg.destroy(sema.gpa);
3634436180
36345 try sema.explainWhyTypeIsNotPacked(msg, ty_src, field_ty);36181 try sema.explainWhyTypeIsNotPacked(msg, ty_src, field_ty);
...@@ -36356,17 +36192,11 @@ fn semaStructFields(...@@ -36356,17 +36192,11 @@ fn semaStructFields(
36356 const body = zir.bodySlice(extra_index, zir_field.align_body_len);36192 const body = zir.bodySlice(extra_index, zir_field.align_body_len);
36357 extra_index += body.len;36193 extra_index += body.len;
36358 const align_ref = try sema.resolveInlineBody(&block_scope, body, zir_index);36194 const align_ref = try sema.resolveInlineBody(&block_scope, body, zir_index);
36359 const field_align = sema.analyzeAsAlign(&block_scope, .unneeded, align_ref) catch |err| switch (err) {36195 const align_src: LazySrcLoc = .{
36360 error.NeededSourceLocation => {36196 .base_node_inst = struct_type.zir_index.unwrap().?,
36361 const align_src = mod.fieldSrcLoc(decl_index, .{36197 .offset = .{ .container_field_align = @intCast(field_i) },
36362 .index = field_i,
36363 .range = .alignment,
36364 }).lazy;
36365 _ = try sema.analyzeAsAlign(&block_scope, align_src, align_ref);
36366 unreachable;
36367 },
36368 else => |e| return e,
36369 };36198 };
36199 const field_align = try sema.analyzeAsAlign(&block_scope, align_src, align_ref);
36370 struct_type.field_aligns.get(ip)[field_i] = field_align;36200 struct_type.field_aligns.get(ip)[field_i] = field_align;
36371 }36201 }
3637236202
...@@ -36395,7 +36225,7 @@ fn semaStructFieldInits(...@@ -36395,7 +36225,7 @@ fn semaStructFieldInits(
36395 const zir_index = struct_type.zir_index.unwrap().?.resolve(ip);36225 const zir_index = struct_type.zir_index.unwrap().?.resolve(ip);
36396 const fields_len, const small, var extra_index = structZirInfo(zir, zir_index);36226 const fields_len, const small, var extra_index = structZirInfo(zir, zir_index);
3639736227
36398 var comptime_err_ret_trace = std.ArrayList(Module.SrcLoc).init(gpa);36228 var comptime_err_ret_trace = std.ArrayList(LazySrcLoc).init(gpa);
36399 defer comptime_err_ret_trace.deinit();36229 defer comptime_err_ret_trace.deinit();
3640036230
36401 var sema: Sema = .{36231 var sema: Sema = .{
...@@ -36422,6 +36252,7 @@ fn semaStructFieldInits(...@@ -36422,6 +36252,7 @@ fn semaStructFieldInits(
36422 .instructions = .{},36252 .instructions = .{},
36423 .inlining = null,36253 .inlining = null,
36424 .is_comptime = true,36254 .is_comptime = true,
36255 .src_base_inst = struct_type.zir_index.unwrap().?,
36425 };36256 };
36426 defer assert(block_scope.instructions.items.len == 0);36257 defer assert(block_scope.instructions.items.len == 0);
3642736258
...@@ -36495,33 +36326,20 @@ fn semaStructFieldInits(...@@ -36495,33 +36326,20 @@ fn semaStructFieldInits(
36495 try sema.inst_map.ensureSpaceForInstructions(sema.gpa, &.{zir_index});36326 try sema.inst_map.ensureSpaceForInstructions(sema.gpa, &.{zir_index});
36496 sema.inst_map.putAssumeCapacity(zir_index, type_ref);36327 sema.inst_map.putAssumeCapacity(zir_index, type_ref);
3649736328
36498 const init = try sema.resolveInlineBody(&block_scope, body, zir_index);36329 const init_src: LazySrcLoc = .{
36499 const coerced = sema.coerce(&block_scope, field_ty, init, .unneeded) catch |err| switch (err) {36330 .base_node_inst = struct_type.zir_index.unwrap().?,
36500 error.NeededSourceLocation => {36331 .offset = .{ .container_field_value = @intCast(field_i) },
36501 const init_src = mod.fieldSrcLoc(decl_index, .{
36502 .index = field_i,
36503 .range = .value,
36504 }).lazy;
36505 _ = try sema.coerce(&block_scope, field_ty, init, init_src);
36506 unreachable;
36507 },
36508 else => |e| return e,
36509 };36332 };
36510 const default_val = (try sema.resolveValue(coerced)) orelse {36333
36511 const init_src = mod.fieldSrcLoc(decl_index, .{36334 const init = try sema.resolveInlineBody(&block_scope, body, zir_index);
36512 .index = field_i,36335 const coerced = try sema.coerce(&block_scope, field_ty, init, init_src);
36513 .range = .value,36336 const default_val = try sema.resolveValue(coerced) orelse {
36514 }).lazy;
36515 return sema.failWithNeededComptime(&block_scope, init_src, .{36337 return sema.failWithNeededComptime(&block_scope, init_src, .{
36516 .needed_comptime_reason = "struct field default value must be comptime-known",36338 .needed_comptime_reason = "struct field default value must be comptime-known",
36517 });36339 });
36518 };36340 };
3651936341
36520 if (default_val.canMutateComptimeVarState(mod)) {36342 if (default_val.canMutateComptimeVarState(mod)) {
36521 const init_src = mod.fieldSrcLoc(decl_index, .{
36522 .index = field_i,
36523 .range = .value,
36524 }).lazy;
36525 return sema.fail(&block_scope, init_src, "field default value contains reference to comptime-mutable memory", .{});36343 return sema.fail(&block_scope, init_src, "field default value contains reference to comptime-mutable memory", .{});
36526 }36344 }
36527 struct_type.field_inits.get(ip)[field_i] = default_val.toIntern();36345 struct_type.field_inits.get(ip)[field_i] = default_val.toIntern();
...@@ -36543,8 +36361,6 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded...@@ -36543,8 +36361,6 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded
36543 const small: Zir.Inst.UnionDecl.Small = @bitCast(extended.small);36361 const small: Zir.Inst.UnionDecl.Small = @bitCast(extended.small);
36544 var extra_index: usize = extended.operand + @typeInfo(Zir.Inst.UnionDecl).Struct.fields.len;36362 var extra_index: usize = extended.operand + @typeInfo(Zir.Inst.UnionDecl).Struct.fields.len;
3654536363
36546 const src = LazySrcLoc.nodeOffset(0);
36547
36548 const tag_type_ref: Zir.Inst.Ref = if (small.has_tag_type) blk: {36364 const tag_type_ref: Zir.Inst.Ref = if (small.has_tag_type) blk: {
36549 const ty_ref: Zir.Inst.Ref = @enumFromInt(zir.extra[extra_index]);36365 const ty_ref: Zir.Inst.Ref = @enumFromInt(zir.extra[extra_index]);
36550 extra_index += 1;36366 extra_index += 1;
...@@ -36583,7 +36399,7 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded...@@ -36583,7 +36399,7 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded
3658336399
36584 const decl = mod.declPtr(decl_index);36400 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);
36587 defer comptime_err_ret_trace.deinit();36403 defer comptime_err_ret_trace.deinit();
3658836404
36589 var sema: Sema = .{36405 var sema: Sema = .{
...@@ -36610,9 +36426,12 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded...@@ -36610,9 +36426,12 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded
36610 .instructions = .{},36426 .instructions = .{},
36611 .inlining = null,36427 .inlining = null,
36612 .is_comptime = true,36428 .is_comptime = true,
36429 .src_base_inst = union_type.zir_index,
36613 };36430 };
36614 defer assert(block_scope.instructions.items.len == 0);36431 defer assert(block_scope.instructions.items.len == 0);
3661536432
36433 const src = block_scope.nodeOffset(0);
36434
36616 if (body.len != 0) {36435 if (body.len != 0) {
36617 _ = try sema.analyzeInlineBody(&block_scope, body, zir_index);36436 _ = try sema.analyzeInlineBody(&block_scope, body, zir_index);
36618 }36437 }
...@@ -36622,7 +36441,10 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded...@@ -36622,7 +36441,10 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded
36622 var enum_field_vals: std.AutoArrayHashMapUnmanaged(InternPool.Index, void) = .{};36441 var enum_field_vals: std.AutoArrayHashMapUnmanaged(InternPool.Index, void) = .{};
36623 var explicit_tags_seen: []bool = &.{};36442 var explicit_tags_seen: []bool = &.{};
36624 if (tag_type_ref != .none) {36443 if (tag_type_ref != .none) {
36625 const tag_ty_src: LazySrcLoc = .{ .node_offset_container_tag = src.node_offset.x };36444 const tag_ty_src: LazySrcLoc = .{
36445 .base_node_inst = union_type.zir_index,
36446 .offset = .{ .node_offset_container_tag = 0 },
36447 };
36626 const provided_ty = try sema.resolveType(&block_scope, tag_ty_src, tag_type_ref);36448 const provided_ty = try sema.resolveType(&block_scope, tag_ty_src, tag_type_ref);
36627 if (small.auto_enum_tag) {36449 if (small.auto_enum_tag) {
36628 // The provided type is an integer type and we must construct the enum tag type here.36450 // The provided type is an integer type and we must construct the enum tag type here.
...@@ -36635,9 +36457,9 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded...@@ -36635,9 +36457,9 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded
36635 const field_count_val = try mod.intValue(Type.comptime_int, fields_len - 1);36457 const field_count_val = try mod.intValue(Type.comptime_int, fields_len - 1);
36636 if (!(try sema.intFitsInType(field_count_val, int_tag_ty, null))) {36458 if (!(try sema.intFitsInType(field_count_val, int_tag_ty, null))) {
36637 const msg = msg: {36459 const msg = msg: {
36638 const msg = try sema.errMsg(&block_scope, tag_ty_src, "specified integer tag type cannot represent every field", .{});36460 const msg = try sema.errMsg(tag_ty_src, "specified integer tag type cannot represent every field", .{});
36639 errdefer msg.destroy(sema.gpa);36461 errdefer msg.destroy(sema.gpa);
36640 try sema.errNote(&block_scope, tag_ty_src, msg, "type '{}' cannot fit values in range 0...{d}", .{36462 try sema.errNote(tag_ty_src, msg, "type '{}' cannot fit values in range 0...{d}", .{
36641 int_tag_ty.fmt(mod),36463 int_tag_ty.fmt(mod),
36642 fields_len - 1,36464 fields_len - 1,
36643 });36465 });
...@@ -36722,19 +36544,26 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded...@@ -36722,19 +36544,26 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded
36722 break :blk try sema.resolveInst(tag_ref);36544 break :blk try sema.resolveInst(tag_ref);
36723 } else .none;36545 } else .none;
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
36725 if (enum_field_vals.capacity() > 0) {36564 if (enum_field_vals.capacity() > 0) {
36726 const enum_tag_val = if (tag_ref != .none) blk: {36565 const enum_tag_val = if (tag_ref != .none) blk: {
36727 const val = sema.semaUnionFieldVal(&block_scope, .unneeded, int_tag_ty, tag_ref) catch |err| switch (err) {36566 const val = try sema.semaUnionFieldVal(&block_scope, value_src, int_tag_ty, tag_ref);
36728 error.NeededSourceLocation => {
36729 const val_src = mod.fieldSrcLoc(union_type.decl, .{
36730 .index = field_i,
36731 .range = .value,
36732 }).lazy;
36733 _ = try sema.semaUnionFieldVal(&block_scope, val_src, int_tag_ty, tag_ref);
36734 unreachable;
36735 },
36736 else => |e| return e,
36737 };
36738 last_tag_val = val;36567 last_tag_val = val;
3673936568
36740 break :blk val;36569 break :blk val;
...@@ -36749,12 +36578,14 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded...@@ -36749,12 +36578,14 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded
36749 };36578 };
36750 const gop = enum_field_vals.getOrPutAssumeCapacity(enum_tag_val.toIntern());36579 const gop = enum_field_vals.getOrPutAssumeCapacity(enum_tag_val.toIntern());
36751 if (gop.found_existing) {36580 if (gop.found_existing) {
36752 const field_src = mod.fieldSrcLoc(union_type.decl, .{ .index = field_i }).lazy;36581 const other_value_src: LazySrcLoc = .{
36753 const other_field_src = mod.fieldSrcLoc(union_type.decl, .{ .index = gop.index }).lazy;36582 .base_node_inst = union_type.zir_index,
36583 .offset = .{ .container_field_value = @intCast(gop.index) },
36584 };
36754 const msg = msg: {36585 const msg = msg: {
36755 const msg = try sema.errMsg(&block_scope, field_src, "enum tag value {} already taken", .{enum_tag_val.fmtValue(mod, &sema)});36586 const msg = try sema.errMsg(value_src, "enum tag value {} already taken", .{enum_tag_val.fmtValue(mod, &sema)});
36756 errdefer msg.destroy(gpa);36587 errdefer msg.destroy(gpa);
36757 try sema.errNote(&block_scope, other_field_src, msg, "other occurrence here", .{});36588 try sema.errNote(other_value_src, msg, "other occurrence here", .{});
36758 break :msg msg;36589 break :msg msg;
36759 };36590 };
36760 return sema.failWithOwnedErrorMsg(&block_scope, msg);36591 return sema.failWithOwnedErrorMsg(&block_scope, msg);
...@@ -36772,17 +36603,7 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded...@@ -36772,17 +36603,7 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded
36772 else if (field_type_ref == .none)36603 else if (field_type_ref == .none)
36773 Type.noreturn36604 Type.noreturn
36774 else36605 else
36775 sema.resolveType(&block_scope, .unneeded, field_type_ref) catch |err| switch (err) {36606 try sema.resolveType(&block_scope, type_src, field_type_ref);
36776 error.NeededSourceLocation => {
36777 const ty_src = mod.fieldSrcLoc(union_type.decl, .{
36778 .index = field_i,
36779 .range = .type,
36780 }).lazy;
36781 _ = try sema.resolveType(&block_scope, ty_src, field_type_ref);
36782 unreachable;
36783 },
36784 else => |e| return e,
36785 };
3678636607
36787 if (field_ty.isGenericPoison()) {36608 if (field_ty.isGenericPoison()) {
36788 return error.GenericPoison;36609 return error.GenericPoison;
...@@ -36791,11 +36612,7 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded...@@ -36791,11 +36612,7 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded
36791 if (explicit_tags_seen.len > 0) {36612 if (explicit_tags_seen.len > 0) {
36792 const tag_info = ip.loadEnumType(union_type.tagTypePtr(ip).*);36613 const tag_info = ip.loadEnumType(union_type.tagTypePtr(ip).*);
36793 const enum_index = tag_info.nameIndex(ip, field_name) orelse {36614 const enum_index = tag_info.nameIndex(ip, field_name) orelse {
36794 const ty_src = mod.fieldSrcLoc(union_type.decl, .{36615 return sema.fail(&block_scope, name_src, "no field named '{}' in enum '{}'", .{
36795 .index = field_i,
36796 .range = .name,
36797 }).lazy;
36798 return sema.fail(&block_scope, ty_src, "no field named '{}' in enum '{}'", .{
36799 field_name.fmt(ip), Type.fromInterned(union_type.tagTypePtr(ip).*).fmt(mod),36616 field_name.fmt(ip), Type.fromInterned(union_type.tagTypePtr(ip).*).fmt(mod),
36800 });36617 });
36801 };36618 };
...@@ -36808,17 +36625,15 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded...@@ -36808,17 +36625,15 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded
36808 // Enforce the enum fields and the union fields being in the same order.36625 // Enforce the enum fields and the union fields being in the same order.
36809 if (enum_index != field_i) {36626 if (enum_index != field_i) {
36810 const msg = msg: {36627 const msg = msg: {
36811 const ty_src = mod.fieldSrcLoc(union_type.decl, .{36628 const enum_field_src: LazySrcLoc = .{
36812 .index = field_i,36629 .base_node_inst = tag_info.zir_index.unwrap().?,
36813 .range = .name,36630 .offset = .{ .container_field_name = enum_index },
36814 }).lazy;36631 };
36815 const enum_field_src = mod.fieldSrcLoc(tag_info.decl, .{ .index = enum_index }).lazy;36632 const msg = try sema.errMsg(name_src, "union field '{}' ordered differently than corresponding enum field", .{
36816 const msg = try sema.errMsg(&block_scope, ty_src, "union field '{}' ordered differently than corresponding enum field", .{
36817 field_name.fmt(ip),36633 field_name.fmt(ip),
36818 });36634 });
36819 errdefer msg.destroy(sema.gpa);36635 errdefer msg.destroy(sema.gpa);
36820 const decl_ptr = mod.declPtr(tag_info.decl);36636 try sema.errNote(enum_field_src, msg, "enum field here", .{});
36821 try mod.errNoteNonLazy(decl_ptr.toSrcLoc(enum_field_src, mod), msg, "enum field here", .{});
36822 break :msg msg;36637 break :msg msg;
36823 };36638 };
36824 return sema.failWithOwnedErrorMsg(&block_scope, msg);36639 return sema.failWithOwnedErrorMsg(&block_scope, msg);
...@@ -36827,11 +36642,7 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded...@@ -36827,11 +36642,7 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded
3682736642
36828 if (field_ty.zigTypeTag(mod) == .Opaque) {36643 if (field_ty.zigTypeTag(mod) == .Opaque) {
36829 const msg = msg: {36644 const msg = msg: {
36830 const ty_src = mod.fieldSrcLoc(union_type.decl, .{36645 const msg = try sema.errMsg(type_src, "opaque types have unknown size and therefore cannot be directly embedded in unions", .{});
36831 .index = field_i,
36832 .range = .type,
36833 }).lazy;
36834 const msg = try sema.errMsg(&block_scope, ty_src, "opaque types have unknown size and therefore cannot be directly embedded in unions", .{});
36835 errdefer msg.destroy(sema.gpa);36646 errdefer msg.destroy(sema.gpa);
3683636647
36837 try sema.addDeclaredHereNote(msg, field_ty);36648 try sema.addDeclaredHereNote(msg, field_ty);
...@@ -36844,14 +36655,10 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded...@@ -36844,14 +36655,10 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded
36844 !try sema.validateExternType(field_ty, .union_field))36655 !try sema.validateExternType(field_ty, .union_field))
36845 {36656 {
36846 const msg = msg: {36657 const msg = msg: {
36847 const ty_src = mod.fieldSrcLoc(union_type.decl, .{36658 const msg = try sema.errMsg(type_src, "extern unions cannot contain fields of type '{}'", .{field_ty.fmt(mod)});
36848 .index = field_i,
36849 .range = .type,
36850 });
36851 const msg = try sema.errMsg(&block_scope, ty_src.lazy, "extern unions cannot contain fields of type '{}'", .{field_ty.fmt(mod)});
36852 errdefer msg.destroy(sema.gpa);36659 errdefer msg.destroy(sema.gpa);
3685336660
36854 try sema.explainWhyTypeIsNotExtern(msg, ty_src, field_ty, .union_field);36661 try sema.explainWhyTypeIsNotExtern(msg, type_src, field_ty, .union_field);
3685536662
36856 try sema.addDeclaredHereNote(msg, field_ty);36663 try sema.addDeclaredHereNote(msg, field_ty);
36857 break :msg msg;36664 break :msg msg;
...@@ -36859,14 +36666,10 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded...@@ -36859,14 +36666,10 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded
36859 return sema.failWithOwnedErrorMsg(&block_scope, msg);36666 return sema.failWithOwnedErrorMsg(&block_scope, msg);
36860 } else if (layout == .@"packed" and !try sema.validatePackedType(field_ty)) {36667 } else if (layout == .@"packed" and !try sema.validatePackedType(field_ty)) {
36861 const msg = msg: {36668 const msg = msg: {
36862 const ty_src = mod.fieldSrcLoc(union_type.decl, .{36669 const msg = try sema.errMsg(type_src, "packed unions cannot contain fields of type '{}'", .{field_ty.fmt(mod)});
36863 .index = field_i,
36864 .range = .type,
36865 });
36866 const msg = try sema.errMsg(&block_scope, ty_src.lazy, "packed unions cannot contain fields of type '{}'", .{field_ty.fmt(mod)});
36867 errdefer msg.destroy(sema.gpa);36670 errdefer msg.destroy(sema.gpa);
3686836671
36869 try sema.explainWhyTypeIsNotPacked(msg, ty_src, field_ty);36672 try sema.explainWhyTypeIsNotPacked(msg, type_src, field_ty);
3687036673
36871 try sema.addDeclaredHereNote(msg, field_ty);36674 try sema.addDeclaredHereNote(msg, field_ty);
36872 break :msg msg;36675 break :msg msg;
...@@ -36878,17 +36681,7 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded...@@ -36878,17 +36681,7 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded
3687836681
36879 if (small.any_aligned_fields) {36682 if (small.any_aligned_fields) {
36880 field_aligns.appendAssumeCapacity(if (align_ref != .none)36683 field_aligns.appendAssumeCapacity(if (align_ref != .none)
36881 sema.resolveAlign(&block_scope, .unneeded, align_ref) catch |err| switch (err) {36684 try sema.resolveAlign(&block_scope, align_src, align_ref)
36882 error.NeededSourceLocation => {
36883 const align_src = mod.fieldSrcLoc(union_type.decl, .{
36884 .index = field_i,
36885 .range = .alignment,
36886 }).lazy;
36887 _ = try sema.resolveAlign(&block_scope, align_src, align_ref);
36888 unreachable;
36889 },
36890 else => |e| return e,
36891 }
36892 else36685 else
36893 .none);36686 .none);
36894 } else {36687 } else {
...@@ -36903,7 +36696,7 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded...@@ -36903,7 +36696,7 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded
36903 const tag_info = ip.loadEnumType(union_type.tagTypePtr(ip).*);36696 const tag_info = ip.loadEnumType(union_type.tagTypePtr(ip).*);
36904 if (tag_info.names.len > fields_len) {36697 if (tag_info.names.len > fields_len) {
36905 const msg = msg: {36698 const msg = msg: {
36906 const msg = try sema.errMsg(&block_scope, src, "enum field(s) missing in union", .{});36699 const msg = try sema.errMsg(src, "enum field(s) missing in union", .{});
36907 errdefer msg.destroy(sema.gpa);36700 errdefer msg.destroy(sema.gpa);
3690836701
36909 for (tag_info.names.get(ip), 0..) |field_name, field_index| {36702 for (tag_info.names.get(ip), 0..) |field_name, field_index| {
...@@ -36945,7 +36738,7 @@ fn generateUnionTagTypeNumbered(...@@ -36945,7 +36738,7 @@ fn generateUnionTagTypeNumbered(
36945 const ip = &mod.intern_pool;36738 const ip = &mod.intern_pool;
3694636739
36947 const src_decl = mod.declPtr(block.src_decl);36740 const src_decl = mod.declPtr(block.src_decl);
36948 const new_decl_index = try mod.allocateNewDecl(block.namespace, src_decl.src_node);36741 const new_decl_index = try mod.allocateNewDecl(block.namespace);
36949 errdefer mod.destroyDecl(new_decl_index);36742 errdefer mod.destroyDecl(new_decl_index);
36950 const fqn = try union_owner_decl.fullyQualifiedName(mod);36743 const fqn = try union_owner_decl.fullyQualifiedName(mod);
36951 const name = try ip.getOrPutStringFmt(36744 const name = try ip.getOrPutStringFmt(
...@@ -36997,7 +36790,7 @@ fn generateUnionTagTypeSimple(...@@ -36997,7 +36790,7 @@ fn generateUnionTagTypeSimple(
36997 const new_decl_index = new_decl_index: {36790 const new_decl_index = new_decl_index: {
36998 const fqn = try union_owner_decl.fullyQualifiedName(mod);36791 const fqn = try union_owner_decl.fullyQualifiedName(mod);
36999 const src_decl = mod.declPtr(block.src_decl);36792 const src_decl = mod.declPtr(block.src_decl);
37000 const new_decl_index = try mod.allocateNewDecl(block.namespace, src_decl.src_node);36793 const new_decl_index = try mod.allocateNewDecl(block.namespace);
37001 errdefer mod.destroyDecl(new_decl_index);36794 errdefer mod.destroyDecl(new_decl_index);
37002 const name = try ip.getOrPutStringFmt(36795 const name = try ip.getOrPutStringFmt(
37003 gpa,36796 gpa,
...@@ -37037,8 +36830,7 @@ fn generateUnionTagTypeSimple(...@@ -37037,8 +36830,7 @@ fn generateUnionTagTypeSimple(
37037}36830}
3703836831
37039fn getBuiltin(sema: *Sema, name: []const u8) CompileError!Air.Inst.Ref {36832fn getBuiltin(sema: *Sema, name: []const u8) CompileError!Air.Inst.Ref {
37040 const gpa = sema.gpa;36833 const zcu = sema.mod;
37041 const src = LazySrcLoc.nodeOffset(0);
3704236834
37043 var block: Block = .{36835 var block: Block = .{
37044 .parent = null,36836 .parent = null,
...@@ -37048,8 +36840,23 @@ fn getBuiltin(sema: *Sema, name: []const u8) CompileError!Air.Inst.Ref {...@@ -37048,8 +36840,23 @@ fn getBuiltin(sema: *Sema, name: []const u8) CompileError!Air.Inst.Ref {
37048 .instructions = .{},36840 .instructions = .{},
37049 .inlining = null,36841 .inlining = null,
37050 .is_comptime = true,36842 .is_comptime = true,
36843 .src_base_inst = sema.owner_decl.zir_decl_index.unwrap() orelse owner: {
36844 assert(sema.owner_decl.has_tv);
36845 assert(sema.owner_decl.owns_tv);
36846 switch (sema.owner_decl.typeOf(zcu).zigTypeTag(zcu)) {
36847 .Type => break :owner sema.owner_decl.val.toType().typeDeclInst(zcu).?,
36848 .Fn => {
36849 const owner = zcu.funcInfo(sema.owner_decl.val.toIntern()).generic_owner;
36850 const generic_owner_decl = zcu.declPtr(zcu.funcInfo(owner).owner_decl);
36851 break :owner generic_owner_decl.zir_decl_index.unwrap().?;
36852 },
36853 else => unreachable,
36854 }
36855 },
37051 };36856 };
37052 defer block.instructions.deinit(gpa);36857 defer block.instructions.deinit(sema.gpa);
36858
36859 const src = block.nodeOffset(0);
3705336860
37054 const decl_index = try getBuiltinDecl(sema, &block, name);36861 const decl_index = try getBuiltinDecl(sema, &block, name);
37055 return sema.analyzeDeclVal(&block, src, decl_index);36862 return sema.analyzeDeclVal(&block, src, decl_index);
...@@ -37058,7 +36865,7 @@ fn getBuiltin(sema: *Sema, name: []const u8) CompileError!Air.Inst.Ref {...@@ -37058,7 +36865,7 @@ fn getBuiltin(sema: *Sema, name: []const u8) CompileError!Air.Inst.Ref {
37058fn getBuiltinDecl(sema: *Sema, block: *Block, name: []const u8) CompileError!InternPool.DeclIndex {36865fn getBuiltinDecl(sema: *Sema, block: *Block, name: []const u8) CompileError!InternPool.DeclIndex {
37059 const gpa = sema.gpa;36866 const gpa = sema.gpa;
3706036867
37061 const src = LazySrcLoc.nodeOffset(0);36868 const src = block.nodeOffset(0);
3706236869
37063 const mod = sema.mod;36870 const mod = sema.mod;
37064 const ip = &mod.intern_pool;36871 const ip = &mod.intern_pool;
...@@ -37085,6 +36892,7 @@ fn getBuiltinDecl(sema: *Sema, block: *Block, name: []const u8) CompileError!Int...@@ -37085,6 +36892,7 @@ fn getBuiltinDecl(sema: *Sema, block: *Block, name: []const u8) CompileError!Int
37085}36892}
3708636893
37087fn getBuiltinType(sema: *Sema, name: []const u8) CompileError!Type {36894fn getBuiltinType(sema: *Sema, name: []const u8) CompileError!Type {
36895 const zcu = sema.mod;
37088 const ty_inst = try sema.getBuiltin(name);36896 const ty_inst = try sema.getBuiltin(name);
3708936897
37090 var block: Block = .{36898 var block: Block = .{
...@@ -37095,9 +36903,23 @@ fn getBuiltinType(sema: *Sema, name: []const u8) CompileError!Type {...@@ -37095,9 +36903,23 @@ fn getBuiltinType(sema: *Sema, name: []const u8) CompileError!Type {
37095 .instructions = .{},36903 .instructions = .{},
37096 .inlining = null,36904 .inlining = null,
37097 .is_comptime = true,36905 .is_comptime = true,
36906 .src_base_inst = sema.owner_decl.zir_decl_index.unwrap() orelse owner: {
36907 assert(sema.owner_decl.has_tv);
36908 assert(sema.owner_decl.owns_tv);
36909 switch (sema.owner_decl.typeOf(zcu).zigTypeTag(zcu)) {
36910 .Type => break :owner sema.owner_decl.val.toType().typeDeclInst(zcu).?,
36911 .Fn => {
36912 const owner = zcu.funcInfo(sema.owner_decl.val.toIntern()).generic_owner;
36913 const generic_owner_decl = zcu.declPtr(zcu.funcInfo(owner).owner_decl);
36914 break :owner generic_owner_decl.zir_decl_index.unwrap().?;
36915 },
36916 else => unreachable,
36917 }
36918 },
37098 };36919 };
37099 defer block.instructions.deinit(sema.gpa);36920 defer block.instructions.deinit(sema.gpa);
37100 const src = LazySrcLoc.nodeOffset(0);36921
36922 const src = block.nodeOffset(0);
3710136923
37102 const result_ty = sema.analyzeAsType(&block, src, ty_inst) catch |err| switch (err) {36924 const result_ty = sema.analyzeAsType(&block, src, ty_inst) catch |err| switch (err) {
37103 error.AnalysisFail => std.debug.panic("std.builtin.{s} is corrupt", .{name}),36925 error.AnalysisFail => std.debug.panic("std.builtin.{s} is corrupt", .{name}),
...@@ -37113,12 +36935,12 @@ fn getBuiltinType(sema: *Sema, name: []const u8) CompileError!Type {...@@ -37113,12 +36935,12 @@ fn getBuiltinType(sema: *Sema, name: []const u8) CompileError!Type {
37113/// that the types are already resolved.36935/// that the types are already resolved.
37114/// TODO assert the return value matches `ty.onePossibleValue`36936/// TODO assert the return value matches `ty.onePossibleValue`
37115pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {36937pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {
37116 const mod = sema.mod;36938 const zcu = sema.mod;
37117 const ip = &mod.intern_pool;36939 const ip = &zcu.intern_pool;
37118 return switch (ty.toIntern()) {36940 return switch (ty.toIntern()) {
37119 .u0_type,36941 .u0_type,
37120 .i0_type,36942 .i0_type,
37121 => try mod.intValue(ty, 0),36943 => try zcu.intValue(ty, 0),
37122 .u1_type,36944 .u1_type,
37123 .u8_type,36945 .u8_type,
37124 .i8_type,36946 .i8_type,
...@@ -37181,7 +37003,7 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {...@@ -37181,7 +37003,7 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {
37181 .anyframe_type => unreachable,37003 .anyframe_type => unreachable,
37182 .null_type => Value.null,37004 .null_type => Value.null,
37183 .undefined_type => Value.undef,37005 .undefined_type => Value.undef,
37184 .optional_noreturn_type => try mod.nullValue(ty),37006 .optional_noreturn_type => try zcu.nullValue(ty),
37185 .generic_poison_type => error.GenericPoison,37007 .generic_poison_type => error.GenericPoison,
37186 .empty_struct_type => Value.empty_struct,37008 .empty_struct_type => Value.empty_struct,
37187 // values, not types37009 // values, not types
...@@ -37295,13 +37117,13 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {...@@ -37295,13 +37117,13 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {
37295 => switch (ip.indexToKey(ty.toIntern())) {37117 => switch (ip.indexToKey(ty.toIntern())) {
37296 inline .array_type, .vector_type => |seq_type, seq_tag| {37118 inline .array_type, .vector_type => |seq_type, seq_tag| {
37297 const has_sentinel = seq_tag == .array_type and seq_type.sentinel != .none;37119 const has_sentinel = seq_tag == .array_type and seq_type.sentinel != .none;
37298 if (seq_type.len + @intFromBool(has_sentinel) == 0) return Value.fromInterned((try mod.intern(.{ .aggregate = .{37120 if (seq_type.len + @intFromBool(has_sentinel) == 0) return Value.fromInterned((try zcu.intern(.{ .aggregate = .{
37299 .ty = ty.toIntern(),37121 .ty = ty.toIntern(),
37300 .storage = .{ .elems = &.{} },37122 .storage = .{ .elems = &.{} },
37301 } })));37123 } })));
3730237124
37303 if (try sema.typeHasOnePossibleValue(Type.fromInterned(seq_type.child))) |opv| {37125 if (try sema.typeHasOnePossibleValue(Type.fromInterned(seq_type.child))) |opv| {
37304 return Value.fromInterned((try mod.intern(.{ .aggregate = .{37126 return Value.fromInterned((try zcu.intern(.{ .aggregate = .{
37305 .ty = ty.toIntern(),37127 .ty = ty.toIntern(),
37306 .storage = .{ .repeated_elem = opv.toIntern() },37128 .storage = .{ .repeated_elem = opv.toIntern() },
37307 } })));37129 } })));
...@@ -37316,7 +37138,7 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {...@@ -37316,7 +37138,7 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {
37316 if (struct_type.field_types.len == 0) {37138 if (struct_type.field_types.len == 0) {
37317 // In this case the struct has no fields at all and37139 // In this case the struct has no fields at all and
37318 // therefore has one possible value.37140 // therefore has one possible value.
37319 return Value.fromInterned((try mod.intern(.{ .aggregate = .{37141 return Value.fromInterned((try zcu.intern(.{ .aggregate = .{
37320 .ty = ty.toIntern(),37142 .ty = ty.toIntern(),
37321 .storage = .{ .elems = &.{} },37143 .storage = .{ .elems = &.{} },
37322 } })));37144 } })));
...@@ -37333,12 +37155,11 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {...@@ -37333,12 +37155,11 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {
37333 continue;37155 continue;
37334 }37156 }
37335 const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[i]);37157 const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[i]);
37336 if (field_ty.eql(ty, mod)) {37158 if (field_ty.eql(ty, zcu)) {
37337 const msg = try Module.ErrorMsg.create(37159 const msg = try sema.errMsg(
37338 sema.gpa,37160 ty.srcLoc(zcu),
37339 mod.declPtr(struct_type.decl.unwrap().?).srcLoc(mod),
37340 "struct '{}' depends on itself",37161 "struct '{}' depends on itself",
37341 .{ty.fmt(mod)},37162 .{ty.fmt(zcu)},
37342 );37163 );
37343 try sema.addFieldErrNote(ty, i, msg, "while checking this field", .{});37164 try sema.addFieldErrNote(ty, i, msg, "while checking this field", .{});
37344 return sema.failWithOwnedErrorMsg(null, msg);37165 return sema.failWithOwnedErrorMsg(null, msg);
...@@ -37350,7 +37171,7 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {...@@ -37350,7 +37171,7 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {
3735037171
37351 // In this case the struct has no runtime-known fields and37172 // In this case the struct has no runtime-known fields and
37352 // therefore has one possible value.37173 // therefore has one possible value.
37353 return Value.fromInterned((try mod.intern(.{ .aggregate = .{37174 return Value.fromInterned((try zcu.intern(.{ .aggregate = .{
37354 .ty = ty.toIntern(),37175 .ty = ty.toIntern(),
37355 .storage = .{ .elems = field_vals },37176 .storage = .{ .elems = field_vals },
37356 } })));37177 } })));
...@@ -37363,7 +37184,7 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {...@@ -37363,7 +37184,7 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {
37363 // In this case the struct has all comptime-known fields and37184 // In this case the struct has all comptime-known fields and
37364 // therefore has one possible value.37185 // therefore has one possible value.
37365 // TODO: write something like getCoercedInts to avoid needing to dupe37186 // TODO: write something like getCoercedInts to avoid needing to dupe
37366 return Value.fromInterned((try mod.intern(.{ .aggregate = .{37187 return Value.fromInterned((try zcu.intern(.{ .aggregate = .{
37367 .ty = ty.toIntern(),37188 .ty = ty.toIntern(),
37368 .storage = .{ .elems = try sema.arena.dupe(InternPool.Index, tuple.values.get(ip)) },37189 .storage = .{ .elems = try sema.arena.dupe(InternPool.Index, tuple.values.get(ip)) },
37369 } })));37190 } })));
...@@ -37375,23 +37196,22 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {...@@ -37375,23 +37196,22 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {
37375 const tag_val = (try sema.typeHasOnePossibleValue(Type.fromInterned(union_obj.tagTypePtr(ip).*))) orelse37196 const tag_val = (try sema.typeHasOnePossibleValue(Type.fromInterned(union_obj.tagTypePtr(ip).*))) orelse
37376 return null;37197 return null;
37377 if (union_obj.field_types.len == 0) {37198 if (union_obj.field_types.len == 0) {
37378 const only = try mod.intern(.{ .empty_enum_value = ty.toIntern() });37199 const only = try zcu.intern(.{ .empty_enum_value = ty.toIntern() });
37379 return Value.fromInterned(only);37200 return Value.fromInterned(only);
37380 }37201 }
37381 const only_field_ty = Type.fromInterned(union_obj.field_types.get(ip)[0]);37202 const only_field_ty = Type.fromInterned(union_obj.field_types.get(ip)[0]);
37382 if (only_field_ty.eql(ty, mod)) {37203 if (only_field_ty.eql(ty, zcu)) {
37383 const msg = try Module.ErrorMsg.create(37204 const msg = try sema.errMsg(
37384 sema.gpa,37205 ty.srcLoc(zcu),
37385 mod.declPtr(union_obj.decl).srcLoc(mod),
37386 "union '{}' depends on itself",37206 "union '{}' depends on itself",
37387 .{ty.fmt(mod)},37207 .{ty.fmt(zcu)},
37388 );37208 );
37389 try sema.addFieldErrNote(ty, 0, msg, "while checking this field", .{});37209 try sema.addFieldErrNote(ty, 0, msg, "while checking this field", .{});
37390 return sema.failWithOwnedErrorMsg(null, msg);37210 return sema.failWithOwnedErrorMsg(null, msg);
37391 }37211 }
37392 const val_val = (try sema.typeHasOnePossibleValue(only_field_ty)) orelse37212 const val_val = (try sema.typeHasOnePossibleValue(only_field_ty)) orelse
37393 return null;37213 return null;
37394 const only = try mod.intern(.{ .un = .{37214 const only = try zcu.intern(.{ .un = .{
37395 .ty = ty.toIntern(),37215 .ty = ty.toIntern(),
37396 .tag = tag_val.toIntern(),37216 .tag = tag_val.toIntern(),
37397 .val = val_val.toIntern(),37217 .val = val_val.toIntern(),
...@@ -37406,7 +37226,7 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {...@@ -37406,7 +37226,7 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {
37406 if (enum_type.tag_ty == .comptime_int_type) return null;37226 if (enum_type.tag_ty == .comptime_int_type) return null;
3740737227
37408 if (try sema.typeHasOnePossibleValue(Type.fromInterned(enum_type.tag_ty))) |int_opv| {37228 if (try sema.typeHasOnePossibleValue(Type.fromInterned(enum_type.tag_ty))) |int_opv| {
37409 const only = try mod.intern(.{ .enum_tag = .{37229 const only = try zcu.intern(.{ .enum_tag = .{
37410 .ty = ty.toIntern(),37230 .ty = ty.toIntern(),
37411 .int = int_opv.toIntern(),37231 .int = int_opv.toIntern(),
37412 } });37232 } });
...@@ -37416,18 +37236,18 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {...@@ -37416,18 +37236,18 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {
37416 return null;37236 return null;
37417 },37237 },
37418 .auto, .explicit => {37238 .auto, .explicit => {
37419 if (Type.fromInterned(enum_type.tag_ty).hasRuntimeBits(mod)) return null;37239 if (Type.fromInterned(enum_type.tag_ty).hasRuntimeBits(zcu)) return null;
3742037240
37421 return Value.fromInterned(switch (enum_type.names.len) {37241 return Value.fromInterned(switch (enum_type.names.len) {
37422 0 => try mod.intern(.{ .empty_enum_value = ty.toIntern() }),37242 0 => try zcu.intern(.{ .empty_enum_value = ty.toIntern() }),
37423 1 => try mod.intern(.{ .enum_tag = .{37243 1 => try zcu.intern(.{ .enum_tag = .{
37424 .ty = ty.toIntern(),37244 .ty = ty.toIntern(),
37425 .int = if (enum_type.values.len == 0)37245 .int = if (enum_type.values.len == 0)
37426 (try mod.intValue(Type.fromInterned(enum_type.tag_ty), 0)).toIntern()37246 (try zcu.intValue(Type.fromInterned(enum_type.tag_ty), 0)).toIntern()
37427 else37247 else
37428 try mod.intern_pool.getCoercedInts(37248 try zcu.intern_pool.getCoercedInts(
37429 mod.gpa,37249 zcu.gpa,
37430 mod.intern_pool.indexToKey(enum_type.values.get(ip)[0]).int,37250 zcu.intern_pool.indexToKey(enum_type.values.get(ip)[0]).int,
37431 enum_type.tag_ty,37251 enum_type.tag_ty,
37432 ),37252 ),
37433 } }),37253 } }),
...@@ -37765,7 +37585,7 @@ fn unionFieldIndex(...@@ -37765,7 +37585,7 @@ fn unionFieldIndex(
37765 try sema.resolveTypeFields(union_ty);37585 try sema.resolveTypeFields(union_ty);
37766 const union_obj = mod.typeToUnion(union_ty).?;37586 const union_obj = mod.typeToUnion(union_ty).?;
37767 const field_index = union_obj.loadTagType(ip).nameIndex(ip, field_name) orelse37587 const field_index = union_obj.loadTagType(ip).nameIndex(ip, field_name) orelse
37768 return sema.failWithBadUnionFieldAccess(block, union_obj, field_src, field_name);37588 return sema.failWithBadUnionFieldAccess(block, union_ty, union_obj, field_src, field_name);
37769 return @intCast(field_index);37589 return @intCast(field_index);
37770}37590}
3777137591
...@@ -37784,7 +37604,7 @@ fn structFieldIndex(...@@ -37784,7 +37604,7 @@ fn structFieldIndex(
37784 } else {37604 } else {
37785 const struct_type = mod.typeToStruct(struct_ty).?;37605 const struct_type = mod.typeToStruct(struct_ty).?;
37786 return struct_type.nameIndex(ip, field_name) orelse37606 return struct_type.nameIndex(ip, field_name) orelse
37787 return sema.failWithBadStructFieldAccess(block, struct_type, field_src, field_name);37607 return sema.failWithBadStructFieldAccess(block, struct_ty, struct_type, field_src, field_name);
37788 }37608 }
37789}37609}
3779037610
...@@ -38556,9 +38376,9 @@ fn checkRuntimeValue(sema: *Sema, ptr: Air.Inst.Ref) bool {...@@ -38556,9 +38376,9 @@ fn checkRuntimeValue(sema: *Sema, ptr: Air.Inst.Ref) bool {
38556fn validateRuntimeValue(sema: *Sema, block: *Block, val_src: LazySrcLoc, val: Air.Inst.Ref) CompileError!void {38376fn validateRuntimeValue(sema: *Sema, block: *Block, val_src: LazySrcLoc, val: Air.Inst.Ref) CompileError!void {
38557 if (sema.checkRuntimeValue(val)) return;38377 if (sema.checkRuntimeValue(val)) return;
38558 return sema.failWithOwnedErrorMsg(block, msg: {38378 return sema.failWithOwnedErrorMsg(block, msg: {
38559 const msg = try sema.errMsg(block, val_src, "runtime value contains reference to comptime var", .{});38379 const msg = try sema.errMsg(val_src, "runtime value contains reference to comptime var", .{});
38560 errdefer msg.destroy(sema.gpa);38380 errdefer msg.destroy(sema.gpa);
38561 try sema.errNote(block, val_src, msg, "comptime var pointers are not available at runtime", .{});38381 try sema.errNote(val_src, msg, "comptime var pointers are not available at runtime", .{});
38562 break :msg msg;38382 break :msg msg;
38563 });38383 });
38564}38384}
...@@ -38649,6 +38469,14 @@ fn maybeDerefSliceAsArray(...@@ -38649,6 +38469,14 @@ fn maybeDerefSliceAsArray(
38649 return sema.pointerDeref(block, src, casted_ptr, ptr_ty);38469 return sema.pointerDeref(block, src, casted_ptr, ptr_ty);
38650}38470}
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
38652pub const bitCastVal = @import("Sema/bitcast.zig").bitCast;38480pub const bitCastVal = @import("Sema/bitcast.zig").bitCast;
38653pub const bitCastSpliceVal = @import("Sema/bitcast.zig").bitCastSplice;38481pub const bitCastSpliceVal = @import("Sema/bitcast.zig").bitCastSplice;
3865438482
src/Sema/comptime_ptr_access.zig+4-4
...@@ -1025,18 +1025,18 @@ fn checkComptimeVarStore(...@@ -1025,18 +1025,18 @@ fn checkComptimeVarStore(
1025 if (@intFromEnum(runtime_index) < @intFromEnum(block.runtime_index)) {1025 if (@intFromEnum(runtime_index) < @intFromEnum(block.runtime_index)) {
1026 if (block.runtime_cond) |cond_src| {1026 if (block.runtime_cond) |cond_src| {
1027 const msg = msg: {1027 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", .{});
1029 errdefer msg.destroy(sema.gpa);1029 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", .{});
1031 break :msg msg;1031 break :msg msg;
1032 };1032 };
1033 return sema.failWithOwnedErrorMsg(block, msg);1033 return sema.failWithOwnedErrorMsg(block, msg);
1034 }1034 }
1035 if (block.runtime_loop) |loop_src| {1035 if (block.runtime_loop) |loop_src| {
1036 const msg = msg: {1036 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", .{});
1038 errdefer msg.destroy(sema.gpa);1038 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", .{});
1040 break :msg msg;1040 break :msg msg;
1041 };1041 };
1042 return sema.failWithOwnedErrorMsg(block, msg);1042 return sema.failWithOwnedErrorMsg(block, msg);
src/Value.zig-1
...@@ -4014,7 +4014,6 @@ pub fn pointerDerivation(ptr_val: Value, arena: Allocator, zcu: *Zcu) Allocator....@@ -4014,7 +4014,6 @@ pub fn pointerDerivation(ptr_val: Value, arena: Allocator, zcu: *Zcu) Allocator.
4014 return ptr_val.pointerDerivationAdvanced(arena, zcu, null) catch |err| switch (err) {4014 return ptr_val.pointerDerivationAdvanced(arena, zcu, null) catch |err| switch (err) {
4015 error.OutOfMemory => |e| return e,4015 error.OutOfMemory => |e| return e,
4016 error.AnalysisFail,4016 error.AnalysisFail,
4017 error.NeededSourceLocation,
4018 error.GenericPoison,4017 error.GenericPoison,
4019 error.ComptimeReturn,4018 error.ComptimeReturn,
4020 error.ComptimeBreak,4019 error.ComptimeBreak,
src/arch/wasm/CodeGen.zig+2-3
...@@ -16,7 +16,6 @@ const Decl = Module.Decl;...@@ -16,7 +16,6 @@ const Decl = Module.Decl;
16const Type = @import("../../type.zig").Type;16const Type = @import("../../type.zig").Type;
17const Value = @import("../../Value.zig");17const Value = @import("../../Value.zig");
18const Compilation = @import("../../Compilation.zig");18const Compilation = @import("../../Compilation.zig");
19const LazySrcLoc = Module.LazySrcLoc;
20const link = @import("../../link.zig");19const link = @import("../../link.zig");
21const Air = @import("../../Air.zig");20const Air = @import("../../Air.zig");
22const Liveness = @import("../../Liveness.zig");21const Liveness = @import("../../Liveness.zig");
...@@ -766,7 +765,7 @@ pub fn deinit(func: *CodeGen) void {...@@ -766,7 +765,7 @@ pub fn deinit(func: *CodeGen) void {
766/// Sets `err_msg` on `CodeGen` and returns `error.CodegenFail` which is caught in link/Wasm.zig765/// Sets `err_msg` on `CodeGen` and returns `error.CodegenFail` which is caught in link/Wasm.zig
767fn fail(func: *CodeGen, comptime fmt: []const u8, args: anytype) InnerError {766fn fail(func: *CodeGen, comptime fmt: []const u8, args: anytype) InnerError {
768 const mod = func.bin_file.base.comp.module.?;767 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);
770 func.err_msg = try Module.ErrorMsg.create(func.gpa, src_loc, fmt, args);769 func.err_msg = try Module.ErrorMsg.create(func.gpa, src_loc, fmt, args);
771 return error.CodegenFail;770 return error.CodegenFail;
772}771}
...@@ -3123,7 +3122,7 @@ fn lowerAnonDeclRef(...@@ -3123,7 +3122,7 @@ fn lowerAnonDeclRef(
3123 }3122 }
31243123
3125 const decl_align = mod.intern_pool.indexToKey(anon_decl.orig_ty).ptr_type.flags.alignment;3124 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));
3127 switch (res) {3126 switch (res) {
3128 .ok => {},3127 .ok => {},
3129 .fail => |em| {3128 .fail => |em| {
src/arch/wasm/Emit.zig+1-1
...@@ -257,7 +257,7 @@ fn fail(emit: *Emit, comptime format: []const u8, args: anytype) InnerError {...@@ -257,7 +257,7 @@ fn fail(emit: *Emit, comptime format: []const u8, args: anytype) InnerError {
257 const comp = emit.bin_file.base.comp;257 const comp = emit.bin_file.base.comp;
258 const zcu = comp.module.?;258 const zcu = comp.module.?;
259 const gpa = comp.gpa;259 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);
261 return error.EmitFail;261 return error.EmitFail;
262}262}
263263
src/codegen/c.zig+1-2
...@@ -13,7 +13,6 @@ const Type = @import("../type.zig").Type;...@@ -13,7 +13,6 @@ const Type = @import("../type.zig").Type;
13const C = link.File.C;13const C = link.File.C;
14const Decl = Zcu.Decl;14const Decl = Zcu.Decl;
15const trace = @import("../tracy.zig").trace;15const trace = @import("../tracy.zig").trace;
16const LazySrcLoc = Zcu.LazySrcLoc;
17const Air = @import("../Air.zig");16const Air = @import("../Air.zig");
18const Liveness = @import("../Liveness.zig");17const Liveness = @import("../Liveness.zig");
19const InternPool = @import("../InternPool.zig");18const InternPool = @import("../InternPool.zig");
...@@ -638,7 +637,7 @@ pub const DeclGen = struct {...@@ -638,7 +637,7 @@ pub const DeclGen = struct {
638 const zcu = dg.zcu;637 const zcu = dg.zcu;
639 const decl_index = dg.pass.decl;638 const decl_index = dg.pass.decl;
640 const decl = zcu.declPtr(decl_index);639 const decl = zcu.declPtr(decl_index);
641 const src_loc = decl.srcLoc(zcu);640 const src_loc = decl.navSrcLoc(zcu).upgrade(zcu);
642 dg.error_msg = try Zcu.ErrorMsg.create(dg.gpa, src_loc, format, args);641 dg.error_msg = try Zcu.ErrorMsg.create(dg.gpa, src_loc, format, args);
643 return error.AnalysisFail;642 return error.AnalysisFail;
644 }643 }
src/codegen/llvm.zig+3-4
...@@ -22,7 +22,6 @@ const Air = @import("../Air.zig");...@@ -22,7 +22,6 @@ const Air = @import("../Air.zig");
22const Liveness = @import("../Liveness.zig");22const Liveness = @import("../Liveness.zig");
23const Value = @import("../Value.zig");23const Value = @import("../Value.zig");
24const Type = @import("../type.zig").Type;24const Type = @import("../type.zig").Type;
25const LazySrcLoc = Zcu.LazySrcLoc;
26const x86_64_abi = @import("../arch/x86_64/abi.zig");25const x86_64_abi = @import("../arch/x86_64/abi.zig");
27const wasm_c_abi = @import("../arch/wasm/abi.zig");26const wasm_c_abi = @import("../arch/wasm/abi.zig");
28const aarch64_c_abi = @import("../arch/aarch64/abi.zig");27const aarch64_c_abi = @import("../arch/aarch64/abi.zig");
...@@ -2066,7 +2065,7 @@ pub const Object = struct {...@@ -2066,7 +2065,7 @@ pub const Object = struct {
2066 try o.builder.metadataString(name),2065 try o.builder.metadataString(name),
2067 file,2066 file,
2068 scope,2067 scope,
2069 owner_decl.src_node + 1, // Line2068 owner_decl.src_line + 1, // Line
2070 try o.lowerDebugType(int_ty),2069 try o.lowerDebugType(int_ty),
2071 ty.abiSize(mod) * 8,2070 ty.abiSize(mod) * 8,
2072 (ty.abiAlignment(mod).toByteUnits() orelse 0) * 8,2071 (ty.abiAlignment(mod).toByteUnits() orelse 0) * 8,
...@@ -2236,7 +2235,7 @@ pub const Object = struct {...@@ -2236,7 +2235,7 @@ pub const Object = struct {
2236 try o.builder.metadataString(name),2235 try o.builder.metadataString(name),
2237 try o.getDebugFile(mod.namespacePtr(owner_decl.src_namespace).file_scope),2236 try o.getDebugFile(mod.namespacePtr(owner_decl.src_namespace).file_scope),
2238 try o.namespaceToDebugScope(owner_decl.src_namespace),2237 try o.namespaceToDebugScope(owner_decl.src_namespace),
2239 owner_decl.src_node + 1, // Line2238 owner_decl.src_line + 1, // Line
2240 .none, // Underlying type2239 .none, // Underlying type
2241 0, // Size2240 0, // Size
2242 0, // Align2241 0, // Align
...@@ -4728,7 +4727,7 @@ pub const DeclGen = struct {...@@ -4728,7 +4727,7 @@ pub const DeclGen = struct {
4728 const o = dg.object;4727 const o = dg.object;
4729 const gpa = o.gpa;4728 const gpa = o.gpa;
4730 const mod = o.module;4729 const mod = o.module;
4731 const src_loc = dg.decl.srcLoc(mod);4730 const src_loc = dg.decl.navSrcLoc(mod).upgrade(mod);
4732 dg.err_msg = try Module.ErrorMsg.create(gpa, src_loc, "TODO (LLVM): " ++ format, args);4731 dg.err_msg = try Module.ErrorMsg.create(gpa, src_loc, "TODO (LLVM): " ++ format, args);
4733 return error.CodegenFail;4732 return error.CodegenFail;
4734 }4733 }
src/codegen/spirv.zig+2-3
...@@ -9,7 +9,6 @@ const Module = @import("../Module.zig");...@@ -9,7 +9,6 @@ const Module = @import("../Module.zig");
9const Decl = Module.Decl;9const Decl = Module.Decl;
10const Type = @import("../type.zig").Type;10const Type = @import("../type.zig").Type;
11const Value = @import("../Value.zig");11const Value = @import("../Value.zig");
12const LazySrcLoc = Module.LazySrcLoc;
13const Air = @import("../Air.zig");12const Air = @import("../Air.zig");
14const Liveness = @import("../Liveness.zig");13const Liveness = @import("../Liveness.zig");
15const InternPool = @import("../InternPool.zig");14const InternPool = @import("../InternPool.zig");
...@@ -414,7 +413,7 @@ const DeclGen = struct {...@@ -414,7 +413,7 @@ const DeclGen = struct {
414 pub fn fail(self: *DeclGen, comptime format: []const u8, args: anytype) Error {413 pub fn fail(self: *DeclGen, comptime format: []const u8, args: anytype) Error {
415 @setCold(true);414 @setCold(true);
416 const mod = self.module;415 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);
418 assert(self.error_msg == null);417 assert(self.error_msg == null);
419 self.error_msg = try Module.ErrorMsg.create(self.module.gpa, src_loc, format, args);418 self.error_msg = try Module.ErrorMsg.create(self.module.gpa, src_loc, format, args);
420 return error.CodegenFail;419 return error.CodegenFail;
...@@ -6433,7 +6432,7 @@ const DeclGen = struct {...@@ -6433,7 +6432,7 @@ const DeclGen = struct {
6433 // TODO: Translate proper error locations.6432 // TODO: Translate proper error locations.
6434 assert(as.errors.items.len != 0);6433 assert(as.errors.items.len != 0);
6435 assert(self.error_msg == null);6434 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);
6437 self.error_msg = try Module.ErrorMsg.create(self.module.gpa, src_loc, "failed to assemble SPIR-V inline assembly", .{});6436 self.error_msg = try Module.ErrorMsg.create(self.module.gpa, src_loc, "failed to assemble SPIR-V inline assembly", .{});
6438 const notes = try self.module.gpa.alloc(Module.ErrorMsg, as.errors.items.len);6437 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;...@@ -10,6 +10,7 @@ const native_os = builtin.os.tag;
1010
11const Module = @import("Module.zig");11const Module = @import("Module.zig");
12const Sema = @import("Sema.zig");12const Sema = @import("Sema.zig");
13const InternPool = @import("InternPool.zig");
13const Zir = std.zig.Zir;14const Zir = std.zig.Zir;
14const Decl = Module.Decl;15const Decl = Module.Decl;
1516
...@@ -76,18 +77,19 @@ fn dumpStatusReport() !void {...@@ -76,18 +77,19 @@ fn dumpStatusReport() !void {
76 const stderr = io.getStdErr().writer();77 const stderr = io.getStdErr().writer();
77 const block: *Sema.Block = anal.block;78 const block: *Sema.Block = anal.block;
78 const mod = anal.sema.mod;79 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
81 try stderr.writeAll("Analyzing ");83 try stderr.writeAll("Analyzing ");
82 try writeFullyQualifiedDeclWithFile(mod, block_src_decl, stderr);84 try writeFullyQualifiedDeclWithFile(mod, block.src_decl, stderr);
83 try stderr.writeAll("\n");85 try stderr.writeAll("\n");
8486
85 print_zir.renderInstructionContext(87 print_zir.renderInstructionContext(
86 allocator,88 allocator,
87 anal.body,89 anal.body,
88 anal.body_index,90 anal.body_index,
89 mod.namespacePtr(block.namespace).file_scope,91 file,
90 block_src_decl.src_node,92 src_base_node,
91 6, // indent93 6, // indent
92 stderr,94 stderr,
93 ) catch |err| switch (err) {95 ) catch |err| switch (err) {
...@@ -95,21 +97,21 @@ fn dumpStatusReport() !void {...@@ -95,21 +97,21 @@ fn dumpStatusReport() !void {
95 else => |e| return e,97 else => |e| return e,
96 };98 };
97 try stderr.writeAll(" For full context, use the command\n zig ast-check -t ");99 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);
99 try stderr.writeAll("\n\n");101 try stderr.writeAll("\n\n");
100102
101 var parent = anal.parent;103 var parent = anal.parent;
102 while (parent) |curr| {104 while (parent) |curr| {
103 fba.reset();105 fba.reset();
104 try stderr.writeAll(" in ");106 try stderr.writeAll(" in ");
105 const curr_block_src_decl = mod.declPtr(curr.block.src_decl);107 const cur_block_file, const cur_block_src_base_node = Module.LazySrcLoc.resolveBaseNode(curr.block.src_base_inst, mod);
106 try writeFullyQualifiedDeclWithFile(mod, curr_block_src_decl, stderr);108 try writeFullyQualifiedDeclWithFile(mod, curr.block.src_decl, stderr);
107 try stderr.writeAll("\n > ");109 try stderr.writeAll("\n > ");
108 print_zir.renderSingleInstruction(110 print_zir.renderSingleInstruction(
109 allocator,111 allocator,
110 curr.body[curr.body_index],112 curr.body[curr.body_index],
111 mod.namespacePtr(curr.block.namespace).file_scope,113 cur_block_file,
112 curr_block_src_decl.src_node,114 cur_block_src_base_node,
113 6, // indent115 6, // indent
114 stderr,116 stderr,
115 ) catch |err| switch (err) {117 ) catch |err| switch (err) {
...@@ -138,7 +140,8 @@ fn writeFilePath(file: *Module.File, writer: anytype) !void {...@@ -138,7 +140,8 @@ fn writeFilePath(file: *Module.File, writer: anytype) !void {
138 try writer.writeAll(file.sub_file_path);140 try writer.writeAll(file.sub_file_path);
139}141}
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);
142 try writeFilePath(decl.getFileScope(mod), writer);145 try writeFilePath(decl.getFileScope(mod), writer);
143 try writer.writeAll(": ");146 try writer.writeAll(": ");
144 try decl.renderFullyQualifiedDebugName(mod, writer);147 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:...@@ -1144,7 +1144,7 @@ pub fn updateFunc(self: *Coff, mod: *Module, func_index: InternPool.Index, air:
11441144
1145 const res = try codegen.generateFunction(1145 const res = try codegen.generateFunction(
1146 &self.base,1146 &self.base,
1147 decl.srcLoc(mod),1147 decl.navSrcLoc(mod).upgrade(mod),
1148 func_index,1148 func_index,
1149 air,1149 air,
1150 liveness,1150 liveness,
...@@ -1181,7 +1181,7 @@ pub fn lowerUnnamedConst(self: *Coff, val: Value, decl_index: InternPool.DeclInd...@@ -1181,7 +1181,7 @@ pub fn lowerUnnamedConst(self: *Coff, val: Value, decl_index: InternPool.DeclInd
1181 const sym_name = try std.fmt.allocPrint(gpa, "__unnamed_{}_{d}", .{ decl_name.fmt(&mod.intern_pool), index });1181 const sym_name = try std.fmt.allocPrint(gpa, "__unnamed_{}_{d}", .{ decl_name.fmt(&mod.intern_pool), index });
1182 defer gpa.free(sym_name);1182 defer gpa.free(sym_name);
1183 const ty = val.typeOf(mod);1183 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))) {
1185 .ok => |atom_index| atom_index,1185 .ok => |atom_index| atom_index,
1186 .fail => |em| {1186 .fail => |em| {
1187 decl.analysis = .codegen_failure;1187 decl.analysis = .codegen_failure;
...@@ -1272,7 +1272,7 @@ pub fn updateDecl(...@@ -1272,7 +1272,7 @@ pub fn updateDecl(
1272 defer code_buffer.deinit();1272 defer code_buffer.deinit();
12731273
1274 const decl_val = if (decl.val.getVariable(mod)) |variable| Value.fromInterned(variable.init) else decl.val;1274 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, .{
1276 .parent_atom_index = atom.getSymbolIndex().?,1276 .parent_atom_index = atom.getSymbolIndex().?,
1277 });1277 });
1278 const code = switch (res) {1278 const code = switch (res) {
...@@ -1313,12 +1313,12 @@ fn updateLazySymbolAtom(...@@ -1313,12 +1313,12 @@ fn updateLazySymbolAtom(
1313 const atom = self.getAtomPtr(atom_index);1313 const atom = self.getAtomPtr(atom_index);
1314 const local_sym_index = atom.getSymbolIndex().?;1314 const local_sym_index = atom.getSymbolIndex().?;
13151315
1316 const src = if (sym.ty.getOwnerDeclOrNull(mod)) |owner_decl|1316 const src = if (sym.ty.srcLocOrNull(mod)) |src|
1317 mod.declPtr(owner_decl).srcLoc(mod)1317 src.upgrade(mod)
1318 else1318 else
1319 Module.SrcLoc{1319 Module.SrcLoc{
1320 .file_scope = undefined,1320 .file_scope = undefined,
1321 .parent_decl_node = undefined,1321 .base_node = undefined,
1322 .lazy = .unneeded,1322 .lazy = .unneeded,
1323 };1323 };
1324 const res = try codegen.generateLazySymbol(1324 const res = try codegen.generateLazySymbol(
src/link/Elf/ZigObject.zig+8-8
...@@ -1072,7 +1072,7 @@ pub fn updateFunc(...@@ -1072,7 +1072,7 @@ pub fn updateFunc(
1072 const res = if (decl_state) |*ds|1072 const res = if (decl_state) |*ds|
1073 try codegen.generateFunction(1073 try codegen.generateFunction(
1074 &elf_file.base,1074 &elf_file.base,
1075 decl.srcLoc(mod),1075 decl.navSrcLoc(mod).upgrade(mod),
1076 func_index,1076 func_index,
1077 air,1077 air,
1078 liveness,1078 liveness,
...@@ -1082,7 +1082,7 @@ pub fn updateFunc(...@@ -1082,7 +1082,7 @@ pub fn updateFunc(
1082 else1082 else
1083 try codegen.generateFunction(1083 try codegen.generateFunction(
1084 &elf_file.base,1084 &elf_file.base,
1085 decl.srcLoc(mod),1085 decl.navSrcLoc(mod).upgrade(mod),
1086 func_index,1086 func_index,
1087 air,1087 air,
1088 liveness,1088 liveness,
...@@ -1156,13 +1156,13 @@ pub fn updateDecl(...@@ -1156,13 +1156,13 @@ pub fn updateDecl(
1156 // TODO implement .debug_info for global variables1156 // TODO implement .debug_info for global variables
1157 const decl_val = if (decl.val.getVariable(mod)) |variable| Value.fromInterned(variable.init) else decl.val;1157 const decl_val = if (decl.val.getVariable(mod)) |variable| Value.fromInterned(variable.init) else decl.val;
1158 const res = if (decl_state) |*ds|1158 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, .{
1160 .dwarf = ds,1160 .dwarf = ds,
1161 }, .{1161 }, .{
1162 .parent_atom_index = sym_index,1162 .parent_atom_index = sym_index,
1163 })1163 })
1164 else1164 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, .{
1166 .parent_atom_index = sym_index,1166 .parent_atom_index = sym_index,
1167 });1167 });
11681168
...@@ -1219,12 +1219,12 @@ fn updateLazySymbol(...@@ -1219,12 +1219,12 @@ fn updateLazySymbol(
1219 break :blk try self.strtab.insert(gpa, name);1219 break :blk try self.strtab.insert(gpa, name);
1220 };1220 };
12211221
1222 const src = if (sym.ty.getOwnerDeclOrNull(mod)) |owner_decl|1222 const src = if (sym.ty.srcLocOrNull(mod)) |src|
1223 mod.declPtr(owner_decl).srcLoc(mod)1223 src.upgrade(mod)
1224 else1224 else
1225 Module.SrcLoc{1225 Module.SrcLoc{
1226 .file_scope = undefined,1226 .file_scope = undefined,
1227 .parent_decl_node = undefined,1227 .base_node = undefined,
1228 .lazy = .unneeded,1228 .lazy = .unneeded,
1229 };1229 };
1230 const res = try codegen.generateLazySymbol(1230 const res = try codegen.generateLazySymbol(
...@@ -1304,7 +1304,7 @@ pub fn lowerUnnamedConst(...@@ -1304,7 +1304,7 @@ pub fn lowerUnnamedConst(
1304 val,1304 val,
1305 ty.abiAlignment(mod),1305 ty.abiAlignment(mod),
1306 elf_file.zig_data_rel_ro_section_index.?,1306 elf_file.zig_data_rel_ro_section_index.?,
1307 decl.srcLoc(mod),1307 decl.navSrcLoc(mod).upgrade(mod),
1308 )) {1308 )) {
1309 .ok => |sym_index| sym_index,1309 .ok => |sym_index| sym_index,
1310 .fail => |em| {1310 .fail => |em| {
src/link/MachO/ZigObject.zig+6-6
...@@ -682,7 +682,7 @@ pub fn updateFunc(...@@ -682,7 +682,7 @@ pub fn updateFunc(
682 const dio: codegen.DebugInfoOutput = if (decl_state) |*ds| .{ .dwarf = ds } else .none;682 const dio: codegen.DebugInfoOutput = if (decl_state) |*ds| .{ .dwarf = ds } else .none;
683 const res = try codegen.generateFunction(683 const res = try codegen.generateFunction(
684 &macho_file.base,684 &macho_file.base,
685 decl.srcLoc(mod),685 decl.navSrcLoc(mod).upgrade(mod),
686 func_index,686 func_index,
687 air,687 air,
688 liveness,688 liveness,
...@@ -756,7 +756,7 @@ pub fn updateDecl(...@@ -756,7 +756,7 @@ pub fn updateDecl(
756756
757 const decl_val = if (decl.val.getVariable(mod)) |variable| Value.fromInterned(variable.init) else decl.val;757 const decl_val = if (decl.val.getVariable(mod)) |variable| Value.fromInterned(variable.init) else decl.val;
758 const dio: codegen.DebugInfoOutput = if (decl_state) |*ds| .{ .dwarf = ds } else .none;758 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, .{
760 .parent_atom_index = sym_index,760 .parent_atom_index = sym_index,
761 });761 });
762762
...@@ -1104,7 +1104,7 @@ pub fn lowerUnnamedConst(...@@ -1104,7 +1104,7 @@ pub fn lowerUnnamedConst(
1104 val,1104 val,
1105 val.typeOf(mod).abiAlignment(mod),1105 val.typeOf(mod).abiAlignment(mod),
1106 macho_file.zig_const_sect_index.?,1106 macho_file.zig_const_sect_index.?,
1107 decl.srcLoc(mod),1107 decl.navSrcLoc(mod).upgrade(mod),
1108 )) {1108 )) {
1109 .ok => |sym_index| sym_index,1109 .ok => |sym_index| sym_index,
1110 .fail => |em| {1110 .fail => |em| {
...@@ -1294,12 +1294,12 @@ fn updateLazySymbol(...@@ -1294,12 +1294,12 @@ fn updateLazySymbol(
1294 break :blk try self.strtab.insert(gpa, name);1294 break :blk try self.strtab.insert(gpa, name);
1295 };1295 };
12961296
1297 const src = if (lazy_sym.ty.getOwnerDeclOrNull(mod)) |owner_decl|1297 const src = if (lazy_sym.ty.srcLocOrNull(mod)) |src|
1298 mod.declPtr(owner_decl).srcLoc(mod)1298 src.upgrade(mod)
1299 else1299 else
1300 Module.SrcLoc{1300 Module.SrcLoc{
1301 .file_scope = undefined,1301 .file_scope = undefined,
1302 .parent_decl_node = undefined,1302 .base_node = undefined,
1303 .lazy = .unneeded,1303 .lazy = .unneeded,
1304 };1304 };
1305 const res = try codegen.generateLazySymbol(1305 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:...@@ -433,7 +433,7 @@ pub fn updateFunc(self: *Plan9, mod: *Module, func_index: InternPool.Index, air:
433433
434 const res = try codegen.generateFunction(434 const res = try codegen.generateFunction(
435 &self.base,435 &self.base,
436 decl.srcLoc(mod),436 decl.navSrcLoc(mod).upgrade(mod),
437 func_index,437 func_index,
438 air,438 air,
439 liveness,439 liveness,
...@@ -499,7 +499,7 @@ pub fn lowerUnnamedConst(self: *Plan9, val: Value, decl_index: InternPool.DeclIn...@@ -499,7 +499,7 @@ pub fn lowerUnnamedConst(self: *Plan9, val: Value, decl_index: InternPool.DeclIn
499 };499 };
500 self.syms.items[info.sym_index.?] = sym;500 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, .{
503 .none = {},503 .none = {},
504 }, .{504 }, .{
505 .parent_atom_index = new_atom_idx,505 .parent_atom_index = new_atom_idx,
...@@ -538,7 +538,7 @@ pub fn updateDecl(self: *Plan9, mod: *Module, decl_index: InternPool.DeclIndex)...@@ -538,7 +538,7 @@ pub fn updateDecl(self: *Plan9, mod: *Module, decl_index: InternPool.DeclIndex)
538 defer code_buffer.deinit();538 defer code_buffer.deinit();
539 const decl_val = if (decl.val.getVariable(mod)) |variable| Value.fromInterned(variable.init) else decl.val;539 const decl_val = if (decl.val.getVariable(mod)) |variable| Value.fromInterned(variable.init) else decl.val;
540 // TODO we need the symbol index for symbol in the table of locals for the containing atom540 // 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 = {} }, .{
542 .parent_atom_index = @as(Atom.Index, @intCast(atom_idx)),542 .parent_atom_index = @as(Atom.Index, @intCast(atom_idx)),
543 });543 });
544 const code = switch (res) {544 const code = switch (res) {
...@@ -1020,7 +1020,7 @@ fn addDeclExports(...@@ -1020,7 +1020,7 @@ fn addDeclExports(
1020 {1020 {
1021 try mod.failed_exports.put(mod.gpa, exp, try Module.ErrorMsg.create(1021 try mod.failed_exports.put(mod.gpa, exp, try Module.ErrorMsg.create(
1022 gpa,1022 gpa,
1023 mod.declPtr(decl_index).srcLoc(mod),1023 mod.declPtr(decl_index).navSrcLoc(mod).upgrade(mod),
1024 "plan9 does not support extra sections",1024 "plan9 does not support extra sections",
1025 .{},1025 .{},
1026 ));1026 ));
...@@ -1212,12 +1212,12 @@ fn updateLazySymbolAtom(self: *Plan9, sym: File.LazySymbol, atom_index: Atom.Ind...@@ -1212,12 +1212,12 @@ fn updateLazySymbolAtom(self: *Plan9, sym: File.LazySymbol, atom_index: Atom.Ind
1212 self.syms.items[self.getAtomPtr(atom_index).sym_index.?] = symbol;1212 self.syms.items[self.getAtomPtr(atom_index).sym_index.?] = symbol;
12131213
1214 // generate the code1214 // generate the code
1215 const src = if (sym.ty.getOwnerDeclOrNull(mod)) |owner_decl|1215 const src = if (sym.ty.srcLocOrNull(mod)) |src|
1216 mod.declPtr(owner_decl).srcLoc(mod)1216 src.upgrade(mod)
1217 else1217 else
1218 Module.SrcLoc{1218 Module.SrcLoc{
1219 .file_scope = undefined,1219 .file_scope = undefined,
1220 .parent_decl_node = undefined,1220 .base_node = undefined,
1221 .lazy = .unneeded,1221 .lazy = .unneeded,
1222 };1222 };
1223 const res = try codegen.generateLazySymbol(1223 const res = try codegen.generateLazySymbol(
src/link/Wasm/ZigObject.zig+5-5
...@@ -269,7 +269,7 @@ pub fn updateDecl(...@@ -269,7 +269,7 @@ pub fn updateDecl(
269269
270 const res = try codegen.generateSymbol(270 const res = try codegen.generateSymbol(
271 &wasm_file.base,271 &wasm_file.base,
272 decl.srcLoc(mod),272 decl.navSrcLoc(mod).upgrade(mod),
273 val,273 val,
274 &code_writer,274 &code_writer,
275 .none,275 .none,
...@@ -308,7 +308,7 @@ pub fn updateFunc(...@@ -308,7 +308,7 @@ pub fn updateFunc(
308 defer code_writer.deinit();308 defer code_writer.deinit();
309 const result = try codegen.generateFunction(309 const result = try codegen.generateFunction(
310 &wasm_file.base,310 &wasm_file.base,
311 decl.srcLoc(mod),311 decl.navSrcLoc(mod).upgrade(mod),
312 func_index,312 func_index,
313 air,313 air,
314 liveness,314 liveness,
...@@ -484,7 +484,7 @@ pub fn lowerUnnamedConst(zig_object: *ZigObject, wasm_file: *Wasm, val: Value, d...@@ -484,7 +484,7 @@ pub fn lowerUnnamedConst(zig_object: *ZigObject, wasm_file: *Wasm, val: Value, d
484 });484 });
485 defer gpa.free(name);485 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))) {
488 .ok => |atom_index| {488 .ok => |atom_index| {
489 try wasm_file.getAtomPtr(parent_atom_index).locals.append(gpa, atom_index);489 try wasm_file.getAtomPtr(parent_atom_index).locals.append(gpa, atom_index);
490 return @intFromEnum(wasm_file.getAtom(atom_index).sym_index);490 return @intFromEnum(wasm_file.getAtom(atom_index).sym_index);
...@@ -867,7 +867,7 @@ pub fn updateExports(...@@ -867,7 +867,7 @@ pub fn updateExports(
867 if (exp.opts.section.toSlice(&mod.intern_pool)) |section| {867 if (exp.opts.section.toSlice(&mod.intern_pool)) |section| {
868 try mod.failed_exports.putNoClobber(gpa, exp, try Module.ErrorMsg.create(868 try mod.failed_exports.putNoClobber(gpa, exp, try Module.ErrorMsg.create(
869 gpa,869 gpa,
870 decl.srcLoc(mod),870 decl.navSrcLoc(mod).upgrade(mod),
871 "Unimplemented: ExportOptions.section '{s}'",871 "Unimplemented: ExportOptions.section '{s}'",
872 .{section},872 .{section},
873 ));873 ));
...@@ -900,7 +900,7 @@ pub fn updateExports(...@@ -900,7 +900,7 @@ pub fn updateExports(
900 .link_once => {900 .link_once => {
901 try mod.failed_exports.putNoClobber(gpa, exp, try Module.ErrorMsg.create(901 try mod.failed_exports.putNoClobber(gpa, exp, try Module.ErrorMsg.create(
902 gpa,902 gpa,
903 decl.srcLoc(mod),903 decl.navSrcLoc(mod).upgrade(mod),
904 "Unimplemented: LinkOnce",904 "Unimplemented: LinkOnce",
905 .{},905 .{},
906 ));906 ));
src/print_value.zig+1-1
...@@ -32,7 +32,7 @@ pub fn format(...@@ -32,7 +32,7 @@ pub fn format(
32 return print(ctx.val, writer, ctx.depth, ctx.mod, ctx.opt_sema) catch |err| switch (err) {32 return print(ctx.val, writer, ctx.depth, ctx.mod, ctx.opt_sema) catch |err| switch (err) {
33 error.OutOfMemory => @panic("OOM"), // We're not allowed to return this from a format function33 error.OutOfMemory => @panic("OOM"), // We're not allowed to return this from a format function
34 error.ComptimeBreak, error.ComptimeReturn => unreachable,34 error.ComptimeBreak, error.ComptimeReturn => unreachable,
35 error.AnalysisFail, error.NeededSourceLocation => unreachable, // TODO: re-evaluate when we use `opt_sema` more fully35 error.AnalysisFail => unreachable, // TODO: re-evaluate when we use `opt_sema` more fully
36 else => |e| return e,36 else => |e| return e,
37 };37 };
38}38}
src/print_zir.zig+52-51
...@@ -48,12 +48,11 @@ pub fn renderAsTextToFile(...@@ -48,12 +48,11 @@ pub fn renderAsTextToFile(
48 const item = scope_file.zir.extraData(Zir.Inst.Imports.Item, extra_index);48 const item = scope_file.zir.extraData(Zir.Inst.Imports.Item, extra_index);
49 extra_index = item.end;49 extra_index = item.end;
5050
51 const src: LazySrcLoc = .{ .token_abs = item.data.token };
52 const import_path = scope_file.zir.nullTerminatedString(item.data.name);51 const import_path = scope_file.zir.nullTerminatedString(item.data.name);
53 try stream.print(" @import(\"{}\") ", .{52 try stream.print(" @import(\"{}\") ", .{
54 std.zig.fmtEscapes(import_path),53 std.zig.fmtEscapes(import_path),
55 });54 });
56 try writer.writeSrc(stream, src);55 try writer.writeSrcTokAbs(stream, item.data.token);
57 try stream.writeAll("\n");56 try stream.writeAll("\n");
58 }57 }
59 }58 }
...@@ -188,7 +187,7 @@ const Writer = struct {...@@ -188,7 +187,7 @@ const Writer = struct {
188 } = .{},187 } = .{},
189188
190 fn relativeToNodeIndex(self: *Writer, offset: i32) Ast.Node.Index {189 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)));
192 }191 }
193192
194 fn writeInstToStream(193 fn writeInstToStream(
...@@ -578,10 +577,9 @@ const Writer = struct {...@@ -578,10 +577,9 @@ const Writer = struct {
578 .work_group_id,577 .work_group_id,
579 => {578 => {
580 const inst_data = self.code.extraData(Zir.Inst.UnNode, extended.operand).data;579 const inst_data = self.code.extraData(Zir.Inst.UnNode, extended.operand).data;
581 const src = LazySrcLoc.nodeOffset(inst_data.node);
582 try self.writeInstRef(stream, inst_data.operand);580 try self.writeInstRef(stream, inst_data.operand);
583 try stream.writeAll(")) ");581 try stream.writeAll(")) ");
584 try self.writeSrc(stream, src);582 try self.writeSrcNode(stream, inst_data.node);
585 },583 },
586584
587 .builtin_extern,585 .builtin_extern,
...@@ -592,12 +590,11 @@ const Writer = struct {...@@ -592,12 +590,11 @@ const Writer = struct {
592 .c_va_arg,590 .c_va_arg,
593 => {591 => {
594 const inst_data = self.code.extraData(Zir.Inst.BinNode, extended.operand).data;592 const inst_data = self.code.extraData(Zir.Inst.BinNode, extended.operand).data;
595 const src = LazySrcLoc.nodeOffset(inst_data.node);
596 try self.writeInstRef(stream, inst_data.lhs);593 try self.writeInstRef(stream, inst_data.lhs);
597 try stream.writeAll(", ");594 try stream.writeAll(", ");
598 try self.writeInstRef(stream, inst_data.rhs);595 try self.writeInstRef(stream, inst_data.rhs);
599 try stream.writeAll(")) ");596 try stream.writeAll(")) ");
600 try self.writeSrc(stream, src);597 try self.writeSrcNode(stream, inst_data.node);
601 },598 },
602599
603 .builtin_async_call => try self.writeBuiltinAsyncCall(stream, extended),600 .builtin_async_call => try self.writeBuiltinAsyncCall(stream, extended),
...@@ -612,9 +609,8 @@ const Writer = struct {...@@ -612,9 +609,8 @@ const Writer = struct {
612 }609 }
613610
614 fn writeExtNode(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void {611 fn writeExtNode(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void {
615 const src = LazySrcLoc.nodeOffset(@as(i32, @bitCast(extended.operand)));
616 try stream.writeAll(")) ");612 try stream.writeAll(")) ");
617 try self.writeSrc(stream, src);613 try self.writeSrcNode(stream, @bitCast(extended.operand));
618 }614 }
619615
620 fn writeArrayInitElemType(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {616 fn writeArrayInitElemType(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
...@@ -654,7 +650,7 @@ const Writer = struct {...@@ -654,7 +650,7 @@ const Writer = struct {
654 const extra = self.code.extraData(Zir.Inst.ValidateDestructure, inst_data.payload_index).data;650 const extra = self.code.extraData(Zir.Inst.ValidateDestructure, inst_data.payload_index).data;
655 try self.writeInstRef(stream, extra.operand);651 try self.writeInstRef(stream, extra.operand);
656 try stream.print(", {d}) (destructure=", .{extra.expect_len});652 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);
658 try stream.writeAll(") ");654 try stream.writeAll(") ");
659 try self.writeSrcNode(stream, inst_data.src_node);655 try self.writeSrcNode(stream, inst_data.src_node);
660 }656 }
...@@ -729,7 +725,7 @@ const Writer = struct {...@@ -729,7 +725,7 @@ const Writer = struct {
729 try stream.writeAll(")");725 try stream.writeAll(")");
730 }726 }
731 try stream.writeAll(") ");727 try stream.writeAll(") ");
732 try self.writeSrc(stream, LazySrcLoc.nodeOffset(extra.data.src_node));728 try self.writeSrcNode(stream, extra.data.src_node);
733 }729 }
734730
735 fn writeInt(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {731 fn writeInt(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
...@@ -868,7 +864,7 @@ const Writer = struct {...@@ -868,7 +864,7 @@ const Writer = struct {
868 try stream.writeAll(", ");864 try stream.writeAll(", ");
869 try self.writeInstRef(stream, extra.b);865 try self.writeInstRef(stream, extra.b);
870 try stream.writeAll(") ");866 try stream.writeAll(") ");
871 try self.writeSrc(stream, LazySrcLoc.nodeOffset(extra.node));867 try self.writeSrcNode(stream, extra.node);
872 }868 }
873869
874 fn writeMulAdd(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {870 fn writeMulAdd(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
...@@ -926,7 +922,7 @@ const Writer = struct {...@@ -926,7 +922,7 @@ const Writer = struct {
926 try stream.writeAll(", ");922 try stream.writeAll(", ");
927 try self.writeInstRef(stream, extra.args);923 try self.writeInstRef(stream, extra.args);
928 try stream.writeAll(") ");924 try stream.writeAll(") ");
929 try self.writeSrc(stream, LazySrcLoc.nodeOffset(extra.node));925 try self.writeSrcNode(stream, extra.node);
930 }926 }
931927
932 fn writeParam(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {928 fn writeParam(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
...@@ -1056,7 +1052,6 @@ const Writer = struct {...@@ -1056,7 +1052,6 @@ const Writer = struct {
10561052
1057 fn writeCmpxchg(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void {1053 fn writeCmpxchg(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void {
1058 const extra = self.code.extraData(Zir.Inst.Cmpxchg, extended.operand).data;1054 const extra = self.code.extraData(Zir.Inst.Cmpxchg, extended.operand).data;
1059 const src = LazySrcLoc.nodeOffset(extra.node);
10601055
1061 try self.writeInstRef(stream, extra.ptr);1056 try self.writeInstRef(stream, extra.ptr);
1062 try stream.writeAll(", ");1057 try stream.writeAll(", ");
...@@ -1068,14 +1063,13 @@ const Writer = struct {...@@ -1068,14 +1063,13 @@ const Writer = struct {
1068 try stream.writeAll(", ");1063 try stream.writeAll(", ");
1069 try self.writeInstRef(stream, extra.failure_order);1064 try self.writeInstRef(stream, extra.failure_order);
1070 try stream.writeAll(") ");1065 try stream.writeAll(") ");
1071 try self.writeSrc(stream, src);1066 try self.writeSrcNode(stream, extra.node);
1072 }1067 }
10731068
1074 fn writePtrCastFull(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void {1069 fn writePtrCastFull(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void {
1075 const FlagsInt = @typeInfo(Zir.Inst.FullPtrCastFlags).Struct.backing_integer.?;1070 const FlagsInt = @typeInfo(Zir.Inst.FullPtrCastFlags).Struct.backing_integer.?;
1076 const flags: Zir.Inst.FullPtrCastFlags = @bitCast(@as(FlagsInt, @truncate(extended.small)));1071 const flags: Zir.Inst.FullPtrCastFlags = @bitCast(@as(FlagsInt, @truncate(extended.small)));
1077 const extra = self.code.extraData(Zir.Inst.BinNode, extended.operand).data;1072 const extra = self.code.extraData(Zir.Inst.BinNode, extended.operand).data;
1078 const src = LazySrcLoc.nodeOffset(extra.node);
1079 if (flags.ptr_cast) try stream.writeAll("ptr_cast, ");1073 if (flags.ptr_cast) try stream.writeAll("ptr_cast, ");
1080 if (flags.align_cast) try stream.writeAll("align_cast, ");1074 if (flags.align_cast) try stream.writeAll("align_cast, ");
1081 if (flags.addrspace_cast) try stream.writeAll("addrspace_cast, ");1075 if (flags.addrspace_cast) try stream.writeAll("addrspace_cast, ");
...@@ -1085,19 +1079,18 @@ const Writer = struct {...@@ -1085,19 +1079,18 @@ const Writer = struct {
1085 try stream.writeAll(", ");1079 try stream.writeAll(", ");
1086 try self.writeInstRef(stream, extra.rhs);1080 try self.writeInstRef(stream, extra.rhs);
1087 try stream.writeAll(")) ");1081 try stream.writeAll(")) ");
1088 try self.writeSrc(stream, src);1082 try self.writeSrcNode(stream, extra.node);
1089 }1083 }
10901084
1091 fn writePtrCastNoDest(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void {1085 fn writePtrCastNoDest(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void {
1092 const FlagsInt = @typeInfo(Zir.Inst.FullPtrCastFlags).Struct.backing_integer.?;1086 const FlagsInt = @typeInfo(Zir.Inst.FullPtrCastFlags).Struct.backing_integer.?;
1093 const flags: Zir.Inst.FullPtrCastFlags = @bitCast(@as(FlagsInt, @truncate(extended.small)));1087 const flags: Zir.Inst.FullPtrCastFlags = @bitCast(@as(FlagsInt, @truncate(extended.small)));
1094 const extra = self.code.extraData(Zir.Inst.UnNode, extended.operand).data;1088 const extra = self.code.extraData(Zir.Inst.UnNode, extended.operand).data;
1095 const src = LazySrcLoc.nodeOffset(extra.node);
1096 if (flags.const_cast) try stream.writeAll("const_cast, ");1089 if (flags.const_cast) try stream.writeAll("const_cast, ");
1097 if (flags.volatile_cast) try stream.writeAll("volatile_cast, ");1090 if (flags.volatile_cast) try stream.writeAll("volatile_cast, ");
1098 try self.writeInstRef(stream, extra.operand);1091 try self.writeInstRef(stream, extra.operand);
1099 try stream.writeAll(")) ");1092 try stream.writeAll(")) ");
1100 try self.writeSrc(stream, src);1093 try self.writeSrcNode(stream, extra.node);
1101 }1094 }
11021095
1103 fn writeAtomicLoad(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {1096 fn writeAtomicLoad(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
...@@ -1183,7 +1176,6 @@ const Writer = struct {...@@ -1183,7 +1176,6 @@ const Writer = struct {
11831176
1184 fn writeNodeMultiOp(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void {1177 fn writeNodeMultiOp(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void {
1185 const extra = self.code.extraData(Zir.Inst.NodeMultiOp, extended.operand);1178 const extra = self.code.extraData(Zir.Inst.NodeMultiOp, extended.operand);
1186 const src = LazySrcLoc.nodeOffset(extra.data.src_node);
1187 const operands = self.code.refSlice(extra.end, extended.small);1179 const operands = self.code.refSlice(extra.end, extended.small);
11881180
1189 for (operands, 0..) |operand, i| {1181 for (operands, 0..) |operand, i| {
...@@ -1191,7 +1183,7 @@ const Writer = struct {...@@ -1191,7 +1183,7 @@ const Writer = struct {
1191 try self.writeInstRef(stream, operand);1183 try self.writeInstRef(stream, operand);
1192 }1184 }
1193 try stream.writeAll(")) ");1185 try stream.writeAll(")) ");
1194 try self.writeSrc(stream, src);1186 try self.writeSrcNode(stream, extra.data.src_node);
1195 }1187 }
11961188
1197 fn writeInstNode(1189 fn writeInstNode(
...@@ -1212,7 +1204,6 @@ const Writer = struct {...@@ -1212,7 +1204,6 @@ const Writer = struct {
1212 tmpl_is_expr: bool,1204 tmpl_is_expr: bool,
1213 ) !void {1205 ) !void {
1214 const extra = self.code.extraData(Zir.Inst.Asm, extended.operand);1206 const extra = self.code.extraData(Zir.Inst.Asm, extended.operand);
1215 const src = LazySrcLoc.nodeOffset(extra.data.src_node);
1216 const outputs_len = @as(u5, @truncate(extended.small));1207 const outputs_len = @as(u5, @truncate(extended.small));
1217 const inputs_len = @as(u5, @truncate(extended.small >> 5));1208 const inputs_len = @as(u5, @truncate(extended.small >> 5));
1218 const clobbers_len = @as(u5, @truncate(extended.small >> 10));1209 const clobbers_len = @as(u5, @truncate(extended.small >> 10));
...@@ -1283,18 +1274,17 @@ const Writer = struct {...@@ -1283,18 +1274,17 @@ const Writer = struct {
1283 }1274 }
1284 }1275 }
1285 try stream.writeAll(")) ");1276 try stream.writeAll(")) ");
1286 try self.writeSrc(stream, src);1277 try self.writeSrcNode(stream, extra.data.src_node);
1287 }1278 }
12881279
1289 fn writeOverflowArithmetic(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void {1280 fn writeOverflowArithmetic(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void {
1290 const extra = self.code.extraData(Zir.Inst.BinNode, extended.operand).data;1281 const extra = self.code.extraData(Zir.Inst.BinNode, extended.operand).data;
1291 const src = LazySrcLoc.nodeOffset(extra.node);
12921282
1293 try self.writeInstRef(stream, extra.lhs);1283 try self.writeInstRef(stream, extra.lhs);
1294 try stream.writeAll(", ");1284 try stream.writeAll(", ");
1295 try self.writeInstRef(stream, extra.rhs);1285 try self.writeInstRef(stream, extra.rhs);
1296 try stream.writeAll(")) ");1286 try stream.writeAll(")) ");
1297 try self.writeSrc(stream, src);1287 try self.writeSrcNode(stream, extra.node);
1298 }1288 }
12991289
1300 fn writeCall(1290 fn writeCall(
...@@ -2287,9 +2277,8 @@ const Writer = struct {...@@ -2287,9 +2277,8 @@ const Writer = struct {
2287 inst: Zir.Inst.Index,2277 inst: Zir.Inst.Index,
2288 ) (@TypeOf(stream).Error || error{OutOfMemory})!void {2278 ) (@TypeOf(stream).Error || error{OutOfMemory})!void {
2289 const src_node = self.code.instructions.items(.data)[@intFromEnum(inst)].node;2279 const src_node = self.code.instructions.items(.data)[@intFromEnum(inst)].node;
2290 const src = LazySrcLoc.nodeOffset(src_node);
2291 try stream.writeAll(") ");2280 try stream.writeAll(") ");
2292 try self.writeSrc(stream, src);2281 try self.writeSrcNode(stream, src_node);
2293 }2282 }
22942283
2295 fn writeStrTok(2284 fn writeStrTok(
...@@ -2507,7 +2496,6 @@ const Writer = struct {...@@ -2507,7 +2496,6 @@ const Writer = struct {
2507 fn writeAllocExtended(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void {2496 fn writeAllocExtended(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void {
2508 const extra = self.code.extraData(Zir.Inst.AllocExtended, extended.operand);2497 const extra = self.code.extraData(Zir.Inst.AllocExtended, extended.operand);
2509 const small = @as(Zir.Inst.AllocExtended.Small, @bitCast(extended.small));2498 const small = @as(Zir.Inst.AllocExtended.Small, @bitCast(extended.small));
2510 const src = LazySrcLoc.nodeOffset(extra.data.src_node);
25112499
2512 var extra_index: usize = extra.end;2500 var extra_index: usize = extra.end;
2513 const type_inst: Zir.Inst.Ref = if (!small.has_type) .none else blk: {2501 const type_inst: Zir.Inst.Ref = if (!small.has_type) .none else blk: {
...@@ -2525,7 +2513,7 @@ const Writer = struct {...@@ -2525,7 +2513,7 @@ const Writer = struct {
2525 try self.writeOptionalInstRef(stream, ",ty=", type_inst);2513 try self.writeOptionalInstRef(stream, ",ty=", type_inst);
2526 try self.writeOptionalInstRef(stream, ",align=", align_inst);2514 try self.writeOptionalInstRef(stream, ",align=", align_inst);
2527 try stream.writeAll(")) ");2515 try stream.writeAll(")) ");
2528 try self.writeSrc(stream, src);2516 try self.writeSrcNode(stream, extra.data.src_node);
2529 }2517 }
25302518
2531 fn writeTypeofPeer(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void {2519 fn writeTypeofPeer(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void {
...@@ -2780,9 +2768,8 @@ const Writer = struct {...@@ -2780,9 +2768,8 @@ const Writer = struct {
2780 }2768 }
27812769
2782 fn writeClosureGet(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void {2770 fn writeClosureGet(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void {
2783 const src = LazySrcLoc.nodeOffset(@bitCast(extended.operand));
2784 try stream.print("{d})) ", .{extended.small});2771 try stream.print("{d})) ", .{extended.small});
2785 try self.writeSrc(stream, src);2772 try self.writeSrcNode(stream, @bitCast(extended.operand));
2786 }2773 }
27872774
2788 fn writeInstRef(self: *Writer, stream: anytype, ref: Zir.Inst.Ref) !void {2775 fn writeInstRef(self: *Writer, stream: anytype, ref: Zir.Inst.Ref) !void {
...@@ -2858,30 +2845,44 @@ const Writer = struct {...@@ -2858,30 +2845,44 @@ const Writer = struct {
2858 try stream.writeAll(name);2845 try stream.writeAll(name);
2859 }2846 }
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
2879 fn writeSrcNode(self: *Writer, stream: anytype, src_node: i32) !void {2848 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 });
2881 }2859 }
28822860
2883 fn writeSrcTok(self: *Writer, stream: anytype, src_tok: u32) !void {2861 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 });
2885 }2886 }
28862887
2887 fn writeBracedDecl(self: *Writer, stream: anytype, body: []const Zir.Inst.Index) !void {2888 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 {...@@ -3317,15 +3317,6 @@ pub const Type = struct {
3317 }3317 }
3318 }3318 }
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
3329 pub fn getOwnerDecl(ty: Type, mod: *Module) InternPool.DeclIndex {3320 pub fn getOwnerDecl(ty: Type, mod: *Module) InternPool.DeclIndex {
3330 return ty.getOwnerDeclOrNull(mod) orelse unreachable;3321 return ty.getOwnerDeclOrNull(mod) orelse unreachable;
3331 }3322 }
...@@ -3341,6 +3332,37 @@ pub const Type = struct {...@@ -3341,6 +3332,37 @@ pub const Type = struct {
3341 };3332 };
3342 }3333 }
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
3344 pub fn isGenericPoison(ty: Type) bool {3366 pub fn isGenericPoison(ty: Type) bool {
3345 return ty.toIntern() == .generic_poison_type;3367 return ty.toIntern() == .generic_poison_type;
3346 }3368 }
test/cases/compile_errors/comptime_arg_to_generic_fn_callee_error.zig-1
...@@ -18,4 +18,3 @@ pub export fn entry() void {...@@ -18,4 +18,3 @@ pub export fn entry() void {
18// target=native18// target=native
19//19//
20// :7:28: error: no field named 'c' in enum 'meta.FieldEnum(tmp.MyStruct)'20// :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 {...@@ -15,4 +15,4 @@ export fn entry() void {
15// target=native15// target=native
16//16//
17// :6:9: error: enum tag value 60 already taken17// :6:9: error: enum tag value 60 already taken
18// :4:5: note: other occurrence here18// :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 {...@@ -6,4 +6,4 @@ export fn foo(comptime x: anytype, y: i32) i32 {
6// backend=stage26// backend=stage2
7// target=native7// target=native
8//8//
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 {...@@ -7,4 +7,4 @@ export fn foo(num: anytype) i32 {
7// backend=stage27// backend=stage2
8// target=native8// target=native
9//9//
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 {...@@ -19,5 +19,5 @@ comptime {
19// target=native19// target=native
20//20//
21// :5:30: error: comptime parameters not allowed in function with calling convention 'C'21// :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'
23// :1:15: error: comptime parameters not allowed in function with calling convention 'C'23// :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 {...@@ -27,9 +27,9 @@ export fn h() void {
27// target=native27// target=native
28//28//
29// :9:16: error: missing struct field: x29// :9:16: error: missing struct field: x
30// :1:11: note: struct 'tmp.A' declared here30// :1:11: note: struct declared here
31// :18:16: error: missing tuple field with index 131// :18:16: error: missing tuple field with index 1
32// :16:11: note: struct declared here32// :16:11: note: struct declared here
33// :22:16: error: missing tuple field with index 033// :22:16: error: missing tuple field with index 0
34// :22:16: note: missing tuple field with index 134// :22:16: note: missing tuple field with index 1
35// :16:11: note: struct 'tmp.B' declared here35// :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 {...@@ -14,5 +14,5 @@ comptime {
14// target=native14// target=native
15//15//
16// :5:17: error: missing struct field: b16// :5:17: error: missing struct field: b
17// :1:11: note: struct 'tmp.S' declared here17// :1:11: note: struct declared here
18// :9:15: note: called from here18// :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 {...@@ -31,5 +31,3 @@ export fn entry() void {
31// target=native31// target=native
32//32//
33// :13:16: error: enum fields missing in union33// :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 {...@@ -31,4 +31,3 @@ export fn entry() void {
31// target=native31// target=native
32//32//
33// :12:16: error: no field named 'arst' in enum 'tmp.Tag'33// :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 {...@@ -27,4 +27,3 @@ export fn entry() void {
27// target=native27// target=native
28//28//
29// :9:16: error: no field named 'signed' in enum 'tmp.Tag'29// :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 {...@@ -27,6 +27,3 @@ export fn entry() void {
27// target=native27// target=native
28//28//
29// :12:16: error: enum fields missing in union29// :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 {...@@ -17,5 +17,5 @@ pub export fn entr2() void {
17// backend=stage217// backend=stage2
18// target=native18// target=native
19//19//
20// :4:9: error: range start value is greater than the end value20// :4:10: error: range start value is greater than the end value
21// :11:9: error: range start value is greater than the end value21// :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 {...@@ -14,5 +14,5 @@ export fn entry() void {
14// backend=stage214// backend=stage2
15// target=native15// target=native
16//16//
17// :6:5: error: enum tag value 60 already taken17// :6:9: error: enum tag value 60 already taken
18// :4:5: note: other occurrence here18// :4:9: note: other occurrence here