authorgravatar for spexguy070@gmail.comMartin Wickham <spexguy070@gmail.com> 2021-10-01 15:02:49-05:00
committergravatar for spexguy070@gmail.comMartin Wickham <spexguy070@gmail.com> 2021-10-02 15:21:49-05:00
logfd60012c21360202a74b17d87d230a18d56edc88
tree32ef5e9f386c0fedcb71b825e90029879ebd7628
parent01e08c92b3d1a7895762e7b8f8a7913d08c3fa6c

Change *Scope to *Scope.Block, use Sema when required


2 files changed, 584 insertions(+), 634 deletions(-)

src/Module.zig+9-172
......@@ -2372,7 +2372,7 @@ pub const LazySrcLoc = union(enum) {
23722372 node_offset_lib_name: i32,
23732373
23742374 /// Upgrade to a `SrcLoc` based on the `Decl` or file in the provided scope.
2375 pub fn toSrcLoc(lazy: LazySrcLoc, scope: *Scope) SrcLoc {
2375 pub fn toSrcLoc(lazy: LazySrcLoc, block: *Scope.Block) SrcLoc {
23762376 return switch (lazy) {
23772377 .unneeded,
23782378 .entire_file,
......@@ -2380,7 +2380,7 @@ pub const LazySrcLoc = union(enum) {
23802380 .token_abs,
23812381 .node_abs,
23822382 => .{
2383 .file_scope = scope.getFileScope(),
2383 .file_scope = block.getFileScope(),
23842384 .parent_decl_node = 0,
23852385 .lazy = lazy,
23862386 },
......@@ -2416,8 +2416,8 @@ pub const LazySrcLoc = union(enum) {
24162416 .node_offset_anyframe_type,
24172417 .node_offset_lib_name,
24182418 => .{
2419 .file_scope = scope.getFileScope(),
2420 .parent_decl_node = scope.srcDecl().?.src_node,
2419 .file_scope = block.getFileScope(),
2420 .parent_decl_node = block.src_decl.src_node,
24212421 .lazy = lazy,
24222422 },
24232423 };
......@@ -3464,12 +3464,12 @@ fn semaDecl(mod: *Module, decl: *Decl) !bool {
34643464 if (decl.is_usingnamespace) {
34653465 const ty_ty = Type.initTag(.type);
34663466 if (!decl_tv.ty.eql(ty_ty)) {
3467 return mod.fail(&block_scope.base, src, "expected type, found {}", .{decl_tv.ty});
3467 return sema.fail(&block_scope, src, "expected type, found {}", .{decl_tv.ty});
34683468 }
34693469 var buffer: Value.ToTypeBuffer = undefined;
34703470 const ty = decl_tv.val.toType(&buffer);
34713471 if (ty.getNamespace() == null) {
3472 return mod.fail(&block_scope.base, src, "type {} has no namespace", .{ty});
3472 return sema.fail(&block_scope, src, "type {} has no namespace", .{ty});
34733473 }
34743474
34753475 decl.ty = ty_ty;
......@@ -3532,11 +3532,11 @@ fn semaDecl(mod: *Module, decl: *Decl) !bool {
35323532 if (decl.is_exported) {
35333533 const export_src = src; // TODO make this point at `export` token
35343534 if (is_inline) {
3535 return mod.fail(&block_scope.base, export_src, "export of inline function", .{});
3535 return sema.fail(&block_scope, export_src, "export of inline function", .{});
35363536 }
35373537 // The scope needs to have the decl in it.
35383538 const options: std.builtin.ExportOptions = .{ .name = mem.spanZ(decl.name) };
3539 try mod.analyzeExport(&block_scope, export_src, options, decl);
3539 try sema.analyzeExport(&block_scope, export_src, options, decl);
35403540 }
35413541 return type_changed or is_inline != prev_is_inline;
35423542 }
......@@ -3590,7 +3590,7 @@ fn semaDecl(mod: *Module, decl: *Decl) !bool {
35903590 const export_src = src; // TODO point to the export token
35913591 // The scope needs to have the decl in it.
35923592 const options: std.builtin.ExportOptions = .{ .name = mem.spanZ(decl.name) };
3593 try mod.analyzeExport(&block_scope, export_src, options, decl);
3593 try sema.analyzeExport(&block_scope, export_src, options, decl);
35943594 }
35953595
35963596 return type_changed;
......@@ -4347,81 +4347,6 @@ pub fn getErrorValue(mod: *Module, name: []const u8) !std.StringHashMapUnmanaged
43474347 };
43484348}
43494349
4350pub fn analyzeExport(
4351 mod: *Module,
4352 block: *Scope.Block,
4353 src: LazySrcLoc,
4354 borrowed_options: std.builtin.ExportOptions,
4355 exported_decl: *Decl,
4356) !void {
4357 try mod.ensureDeclAnalyzed(exported_decl);
4358 switch (exported_decl.ty.zigTypeTag()) {
4359 .Fn => {},
4360 else => return mod.fail(&block.base, src, "unable to export type '{}'", .{exported_decl.ty}),
4361 }
4362
4363 const gpa = mod.gpa;
4364
4365 try mod.decl_exports.ensureUnusedCapacity(gpa, 1);
4366 try mod.export_owners.ensureUnusedCapacity(gpa, 1);
4367
4368 const new_export = try gpa.create(Export);
4369 errdefer gpa.destroy(new_export);
4370
4371 const symbol_name = try gpa.dupe(u8, borrowed_options.name);
4372 errdefer gpa.free(symbol_name);
4373
4374 const section: ?[]const u8 = if (borrowed_options.section) |s| try gpa.dupe(u8, s) else null;
4375 errdefer if (section) |s| gpa.free(s);
4376
4377 const src_decl = block.src_decl;
4378 const owner_decl = block.sema.owner_decl;
4379
4380 log.debug("exporting Decl '{s}' as symbol '{s}' from Decl '{s}'", .{
4381 exported_decl.name, symbol_name, owner_decl.name,
4382 });
4383
4384 new_export.* = .{
4385 .options = .{
4386 .name = symbol_name,
4387 .linkage = borrowed_options.linkage,
4388 .section = section,
4389 },
4390 .src = src,
4391 .link = switch (mod.comp.bin_file.tag) {
4392 .coff => .{ .coff = {} },
4393 .elf => .{ .elf = link.File.Elf.Export{} },
4394 .macho => .{ .macho = link.File.MachO.Export{} },
4395 .plan9 => .{ .plan9 = null },
4396 .c => .{ .c = {} },
4397 .wasm => .{ .wasm = {} },
4398 .spirv => .{ .spirv = {} },
4399 },
4400 .owner_decl = owner_decl,
4401 .src_decl = src_decl,
4402 .exported_decl = exported_decl,
4403 .status = .in_progress,
4404 };
4405
4406 // Add to export_owners table.
4407 const eo_gop = mod.export_owners.getOrPutAssumeCapacity(owner_decl);
4408 if (!eo_gop.found_existing) {
4409 eo_gop.value_ptr.* = &[0]*Export{};
4410 }
4411 eo_gop.value_ptr.* = try gpa.realloc(eo_gop.value_ptr.*, eo_gop.value_ptr.len + 1);
4412 eo_gop.value_ptr.*[eo_gop.value_ptr.len - 1] = new_export;
4413 errdefer eo_gop.value_ptr.* = gpa.shrink(eo_gop.value_ptr.*, eo_gop.value_ptr.len - 1);
4414
4415 // Add to exported_decl table.
4416 const de_gop = mod.decl_exports.getOrPutAssumeCapacity(exported_decl);
4417 if (!de_gop.found_existing) {
4418 de_gop.value_ptr.* = &[0]*Export{};
4419 }
4420 de_gop.value_ptr.* = try gpa.realloc(de_gop.value_ptr.*, de_gop.value_ptr.len + 1);
4421 de_gop.value_ptr.*[de_gop.value_ptr.len - 1] = new_export;
4422 errdefer de_gop.value_ptr.* = gpa.shrink(de_gop.value_ptr.*, de_gop.value_ptr.len - 1);
4423}
4424
44254350/// Takes ownership of `name` even if it returns an error.
44264351pub fn createAnonymousDeclNamed(
44274352 mod: *Module,
......@@ -4506,19 +4431,6 @@ pub fn makeIntType(arena: *Allocator, signedness: std.builtin.Signedness, bits:
45064431 return Type.initPayload(&int_payload.base);
45074432}
45084433
4509/// We don't return a pointer to the new error note because the pointer
4510/// becomes invalid when you add another one.
4511pub fn errNote(
4512 mod: *Module,
4513 scope: *Scope,
4514 src: LazySrcLoc,
4515 parent: *ErrorMsg,
4516 comptime format: []const u8,
4517 args: anytype,
4518) error{OutOfMemory}!void {
4519 return mod.errNoteNonLazy(src.toSrcLoc(scope), parent, format, args);
4520}
4521
45224434pub fn errNoteNonLazy(
45234435 mod: *Module,
45244436 src_loc: SrcLoc,
......@@ -4536,81 +4448,6 @@ pub fn errNoteNonLazy(
45364448 };
45374449}
45384450
4539pub fn errMsg(
4540 mod: *Module,
4541 scope: *Scope,
4542 src: LazySrcLoc,
4543 comptime format: []const u8,
4544 args: anytype,
4545) error{OutOfMemory}!*ErrorMsg {
4546 return ErrorMsg.create(mod.gpa, src.toSrcLoc(scope), format, args);
4547}
4548
4549pub fn fail(
4550 mod: *Module,
4551 scope: *Scope,
4552 src: LazySrcLoc,
4553 comptime format: []const u8,
4554 args: anytype,
4555) CompileError {
4556 const err_msg = try mod.errMsg(scope, src, format, args);
4557 return mod.failWithOwnedErrorMsg(scope, err_msg);
4558}
4559
4560/// Same as `fail`, except given a token index, and the function sets up the `LazySrcLoc`
4561/// for pointing at it relatively by subtracting from the containing `Decl`.
4562pub fn failTok(
4563 mod: *Module,
4564 scope: *Scope,
4565 token_index: Ast.TokenIndex,
4566 comptime format: []const u8,
4567 args: anytype,
4568) CompileError {
4569 const src = scope.srcDecl().?.tokSrcLoc(token_index);
4570 return mod.fail(scope, src, format, args);
4571}
4572
4573/// Same as `fail`, except given an AST node index, and the function sets up the `LazySrcLoc`
4574/// for pointing at it relatively by subtracting from the containing `Decl`.
4575pub fn failNode(
4576 mod: *Module,
4577 scope: *Scope,
4578 node_index: Ast.Node.Index,
4579 comptime format: []const u8,
4580 args: anytype,
4581) CompileError {
4582 const src = scope.srcDecl().?.nodeSrcLoc(node_index);
4583 return mod.fail(scope, src, format, args);
4584}
4585
4586pub fn failWithOwnedErrorMsg(mod: *Module, scope: *Scope, err_msg: *ErrorMsg) CompileError {
4587 @setCold(true);
4588
4589 {
4590 errdefer err_msg.destroy(mod.gpa);
4591 if (err_msg.src_loc.lazy == .unneeded) {
4592 return error.NeededSourceLocation;
4593 }
4594 try mod.failed_decls.ensureUnusedCapacity(mod.gpa, 1);
4595 try mod.failed_files.ensureUnusedCapacity(mod.gpa, 1);
4596 }
4597 switch (scope.tag) {
4598 .block => {
4599 const block = scope.cast(Scope.Block).?;
4600 if (block.sema.owner_func) |func| {
4601 func.state = .sema_failure;
4602 } else {
4603 block.sema.owner_decl.analysis = .sema_failure;
4604 block.sema.owner_decl.generation = mod.generation;
4605 }
4606 mod.failed_decls.putAssumeCapacityNoClobber(block.sema.owner_decl, err_msg);
4607 },
4608 .file => unreachable,
4609 .namespace => unreachable,
4610 }
4611 return error.AnalysisFail;
4612}
4613
46144451pub fn optionalType(arena: *Allocator, child_type: Type) Allocator.Error!Type {
46154452 switch (child_type.tag()) {
46164453 .single_const_pointer => return Type.Tag.optional_single_const_pointer.create(
src/Sema.zig+575-462
......@@ -880,19 +880,76 @@ fn resolveMaybeUndefValAllowVariables(
880880}
881881
882882fn failWithNeededComptime(sema: *Sema, block: *Scope.Block, src: LazySrcLoc) CompileError {
883 return sema.mod.fail(&block.base, src, "unable to resolve comptime value", .{});
883 return sema.fail(block, src, "unable to resolve comptime value", .{});
884884}
885885
886886fn failWithUseOfUndef(sema: *Sema, block: *Scope.Block, src: LazySrcLoc) CompileError {
887 return sema.mod.fail(&block.base, src, "use of undefined value here causes undefined behavior", .{});
887 return sema.fail(block, src, "use of undefined value here causes undefined behavior", .{});
888888}
889889
890890fn failWithDivideByZero(sema: *Sema, block: *Scope.Block, src: LazySrcLoc) CompileError {
891 return sema.mod.fail(&block.base, src, "division by zero here causes undefined behavior", .{});
891 return sema.fail(block, src, "division by zero here causes undefined behavior", .{});
892892}
893893
894894fn failWithModRemNegative(sema: *Sema, block: *Scope.Block, src: LazySrcLoc, lhs_ty: Type, rhs_ty: Type) CompileError {
895 return sema.mod.fail(&block.base, src, "remainder division with '{}' and '{}': signed integers and floats must use @rem or @mod", .{ lhs_ty, rhs_ty });
895 return sema.fail(block, src, "remainder division with '{}' and '{}': signed integers and floats must use @rem or @mod", .{ lhs_ty, rhs_ty });
896}
897
898/// We don't return a pointer to the new error note because the pointer
899/// becomes invalid when you add another one.
900fn errNote(
901 sema: *Sema,
902 block: *Scope.Block,
903 src: LazySrcLoc,
904 parent: *Module.ErrorMsg,
905 comptime format: []const u8,
906 args: anytype,
907) error{OutOfMemory}!void {
908 return sema.mod.errNoteNonLazy(src.toSrcLoc(block), parent, format, args);
909}
910
911fn errMsg(
912 sema: *Sema,
913 block: *Scope.Block,
914 src: LazySrcLoc,
915 comptime format: []const u8,
916 args: anytype,
917) error{OutOfMemory}!*Module.ErrorMsg {
918 return Module.ErrorMsg.create(sema.gpa, src.toSrcLoc(block), format, args);
919}
920
921pub fn fail(
922 sema: *Sema,
923 block: *Scope.Block,
924 src: LazySrcLoc,
925 comptime format: []const u8,
926 args: anytype,
927) CompileError {
928 const err_msg = try sema.errMsg(block, src, format, args);
929 return sema.failWithOwnedErrorMsg(err_msg);
930}
931
932fn failWithOwnedErrorMsg(sema: *Sema, err_msg: *Module.ErrorMsg) CompileError {
933 @setCold(true);
934
935 const mod = sema.mod;
936
937 {
938 errdefer err_msg.destroy(mod.gpa);
939 if (err_msg.src_loc.lazy == .unneeded) {
940 return error.NeededSourceLocation;
941 }
942 try mod.failed_decls.ensureUnusedCapacity(mod.gpa, 1);
943 try mod.failed_files.ensureUnusedCapacity(mod.gpa, 1);
944 }
945 if (sema.owner_func) |func| {
946 func.state = .sema_failure;
947 } else {
948 sema.owner_decl.analysis = .sema_failure;
949 sema.owner_decl.generation = mod.generation;
950 }
951 mod.failed_decls.putAssumeCapacityNoClobber(sema.owner_decl, err_msg);
952 return error.AnalysisFail;
896953}
897954
898955/// Appropriate to call when the coercion has already been done by result
......@@ -923,9 +980,9 @@ fn resolveAlign(
923980) !u16 {
924981 const alignment_big = try sema.resolveInt(block, src, zir_ref, Type.initTag(.u16));
925982 const alignment = @intCast(u16, alignment_big); // We coerce to u16 in the prev line.
926 if (alignment == 0) return sema.mod.fail(&block.base, src, "alignment must be >= 1", .{});
983 if (alignment == 0) return sema.fail(block, src, "alignment must be >= 1", .{});
927984 if (!std.math.isPowerOfTwo(alignment)) {
928 return sema.mod.fail(&block.base, src, "alignment value {d} is not a power of two", .{
985 return sema.fail(block, src, "alignment value {d} is not a power of two", .{
929986 alignment,
930987 });
931988 }
......@@ -981,7 +1038,7 @@ pub fn resolveInstValue(
9811038fn zirBitcastResultPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
9821039 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
9831040 const src = inst_data.src();
984 return sema.mod.fail(&block.base, src, "TODO implement zir_sema.zirBitcastResultPtr", .{});
1041 return sema.fail(block, src, "TODO implement zir_sema.zirBitcastResultPtr", .{});
9851042}
9861043
9871044fn zirCoerceResultPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
......@@ -1177,7 +1234,7 @@ fn zirEnumDecl(
11771234 .val = enum_val,
11781235 }, type_name);
11791236 new_decl.owns_tv = true;
1180 errdefer sema.mod.abortAnonDecl(new_decl);
1237 errdefer mod.abortAnonDecl(new_decl);
11811238
11821239 enum_obj.* = .{
11831240 .owner_decl = new_decl,
......@@ -1292,12 +1349,12 @@ fn zirEnumDecl(
12921349 const field_src = enumFieldSrcLoc(block.src_decl, tree.*, src.node_offset, field_i);
12931350 const other_tag_src = enumFieldSrcLoc(block.src_decl, tree.*, src.node_offset, gop.index);
12941351 const msg = msg: {
1295 const msg = try mod.errMsg(&block.base, field_src, "duplicate enum tag", .{});
1352 const msg = try sema.errMsg(block, field_src, "duplicate enum tag", .{});
12961353 errdefer msg.destroy(gpa);
1297 try mod.errNote(&block.base, other_tag_src, msg, "other tag here", .{});
1354 try sema.errNote(block, other_tag_src, msg, "other tag here", .{});
12981355 break :msg msg;
12991356 };
1300 return mod.failWithOwnedErrorMsg(&block.base, msg);
1357 return sema.failWithOwnedErrorMsg(msg);
13011358 }
13021359
13031360 if (has_tag_value) {
......@@ -1400,7 +1457,7 @@ fn zirOpaqueDecl(
14001457
14011458 _ = extended;
14021459 _ = inst;
1403 return sema.mod.fail(&block.base, sema.src, "TODO implement zirOpaqueDecl", .{});
1460 return sema.fail(block, sema.src, "TODO implement zirOpaqueDecl", .{});
14041461}
14051462
14061463fn zirErrorSetDecl(
......@@ -1509,7 +1566,7 @@ fn ensureResultUsed(
15091566 const operand_ty = sema.typeOf(operand);
15101567 switch (operand_ty.zigTypeTag()) {
15111568 .Void, .NoReturn => return,
1512 else => return sema.mod.fail(&block.base, src, "expression value is ignored", .{}),
1569 else => return sema.fail(block, src, "expression value is ignored", .{}),
15131570 }
15141571}
15151572
......@@ -1522,7 +1579,7 @@ fn zirEnsureResultNonError(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Inde
15221579 const src = inst_data.src();
15231580 const operand_ty = sema.typeOf(operand);
15241581 switch (operand_ty.zigTypeTag()) {
1525 .ErrorSet, .ErrorUnion => return sema.mod.fail(&block.base, src, "error is discarded", .{}),
1582 .ErrorSet, .ErrorUnion => return sema.fail(block, src, "error is discarded", .{}),
15261583 else => return,
15271584 }
15281585}
......@@ -1548,15 +1605,15 @@ fn zirIndexablePtrLen(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Co
15481605 }
15491606 if (!elem_ty.isIndexable()) {
15501607 const msg = msg: {
1551 const msg = try sema.mod.errMsg(
1552 &block.base,
1608 const msg = try sema.errMsg(
1609 block,
15531610 src,
15541611 "type '{}' does not support indexing",
15551612 .{elem_ty},
15561613 );
15571614 errdefer msg.destroy(sema.gpa);
1558 try sema.mod.errNote(
1559 &block.base,
1615 try sema.errNote(
1616 block,
15601617 src,
15611618 msg,
15621619 "for loop operand must be an array, slice, tuple, or vector",
......@@ -1564,13 +1621,13 @@ fn zirIndexablePtrLen(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Co
15641621 );
15651622 break :msg msg;
15661623 };
1567 return sema.mod.failWithOwnedErrorMsg(&block.base, msg);
1624 return sema.failWithOwnedErrorMsg(msg);
15681625 }
15691626 const result_ptr = try sema.fieldPtr(block, src, array, "len", src);
15701627 return sema.analyzeLoad(block, src, result_ptr, src);
15711628 }
15721629
1573 return sema.mod.fail(&block.base, src, "TODO implement Sema.zirIndexablePtrLen", .{});
1630 return sema.fail(block, src, "TODO implement Sema.zirIndexablePtrLen", .{});
15741631}
15751632
15761633fn zirAllocExtended(
......@@ -1591,7 +1648,7 @@ fn zirAllocExtended(
15911648 extra_index += 1;
15921649 break :blk try sema.resolveType(block, ty_src, type_ref);
15931650 } else {
1594 return sema.mod.fail(&block.base, src, "TODO implement Sema.zirAllocExtended inferred", .{});
1651 return sema.fail(block, src, "TODO implement Sema.zirAllocExtended inferred", .{});
15951652 };
15961653
15971654 const alignment: u16 = if (small.has_align) blk: {
......@@ -1602,11 +1659,11 @@ fn zirAllocExtended(
16021659 } else 0;
16031660
16041661 if (small.is_comptime) {
1605 return sema.mod.fail(&block.base, src, "TODO implement Sema.zirAllocExtended comptime", .{});
1662 return sema.fail(block, src, "TODO implement Sema.zirAllocExtended comptime", .{});
16061663 }
16071664
16081665 if (!small.is_const) {
1609 return sema.mod.fail(&block.base, src, "TODO implement Sema.zirAllocExtended var", .{});
1666 return sema.fail(block, src, "TODO implement Sema.zirAllocExtended var", .{});
16101667 }
16111668
16121669 const ptr_type = try Type.ptr(sema.arena, .{
......@@ -1804,12 +1861,10 @@ fn validateUnionInitPtr(
18041861 instrs: []const Zir.Inst.Index,
18051862 union_ptr: Air.Inst.Ref,
18061863) CompileError!void {
1807 const mod = sema.mod;
1808
18091864 if (instrs.len != 1) {
18101865 // TODO add note for other field
18111866 // TODO add note for union declared here
1812 return mod.fail(&block.base, init_src, "only one union field can be active at once", .{});
1867 return sema.fail(block, init_src, "only one union field can be active at once", .{});
18131868 }
18141869
18151870 const field_ptr = instrs[0];
......@@ -1845,7 +1900,6 @@ fn validateStructInitPtr(
18451900 instrs: []const Zir.Inst.Index,
18461901) CompileError!void {
18471902 const gpa = sema.gpa;
1848 const mod = sema.mod;
18491903
18501904 // Maps field index to field_ptr index of where it was already initialized.
18511905 const found_fields = try gpa.alloc(Zir.Inst.Index, struct_obj.fields.count());
......@@ -1864,12 +1918,12 @@ fn validateStructInitPtr(
18641918 const other_field_ptr_data = sema.code.instructions.items(.data)[other_field_ptr].pl_node;
18651919 const other_field_src: LazySrcLoc = .{ .node_offset_back2tok = other_field_ptr_data.src_node };
18661920 const msg = msg: {
1867 const msg = try mod.errMsg(&block.base, field_src, "duplicate field", .{});
1921 const msg = try sema.errMsg(block, field_src, "duplicate field", .{});
18681922 errdefer msg.destroy(gpa);
1869 try mod.errNote(&block.base, other_field_src, msg, "other field here", .{});
1923 try sema.errNote(block, other_field_src, msg, "other field here", .{});
18701924 break :msg msg;
18711925 };
1872 return mod.failWithOwnedErrorMsg(&block.base, msg);
1926 return sema.failWithOwnedErrorMsg(msg);
18731927 }
18741928 found_fields[field_index] = field_ptr;
18751929 }
......@@ -1884,28 +1938,28 @@ fn validateStructInitPtr(
18841938 const template = "missing struct field: {s}";
18851939 const args = .{field_name};
18861940 if (root_msg) |msg| {
1887 try mod.errNote(&block.base, init_src, msg, template, args);
1941 try sema.errNote(block, init_src, msg, template, args);
18881942 } else {
1889 root_msg = try mod.errMsg(&block.base, init_src, template, args);
1943 root_msg = try sema.errMsg(block, init_src, template, args);
18901944 }
18911945 }
18921946 if (root_msg) |msg| {
18931947 const fqn = try struct_obj.getFullyQualifiedName(gpa);
18941948 defer gpa.free(fqn);
1895 try mod.errNoteNonLazy(
1949 try sema.mod.errNoteNonLazy(
18961950 struct_obj.srcLoc(),
18971951 msg,
18981952 "struct '{s}' declared here",
18991953 .{fqn},
19001954 );
1901 return mod.failWithOwnedErrorMsg(&block.base, msg);
1955 return sema.failWithOwnedErrorMsg(msg);
19021956 }
19031957}
19041958
19051959fn zirValidateArrayInitPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!void {
19061960 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
19071961 const src = inst_data.src();
1908 return sema.mod.fail(&block.base, src, "TODO implement Sema.zirValidateArrayInitPtr", .{});
1962 return sema.fail(block, src, "TODO implement Sema.zirValidateArrayInitPtr", .{});
19091963}
19101964
19111965fn failWithBadFieldAccess(
......@@ -1915,24 +1969,23 @@ fn failWithBadFieldAccess(
19151969 field_src: LazySrcLoc,
19161970 field_name: []const u8,
19171971) CompileError {
1918 const mod = sema.mod;
19191972 const gpa = sema.gpa;
19201973
19211974 const fqn = try struct_obj.getFullyQualifiedName(gpa);
19221975 defer gpa.free(fqn);
19231976
19241977 const msg = msg: {
1925 const msg = try mod.errMsg(
1926 &block.base,
1978 const msg = try sema.errMsg(
1979 block,
19271980 field_src,
19281981 "no field named '{s}' in struct '{s}'",
19291982 .{ field_name, fqn },
19301983 );
19311984 errdefer msg.destroy(gpa);
1932 try mod.errNoteNonLazy(struct_obj.srcLoc(), msg, "struct declared here", .{});
1985 try sema.mod.errNoteNonLazy(struct_obj.srcLoc(), msg, "struct declared here", .{});
19331986 break :msg msg;
19341987 };
1935 return mod.failWithOwnedErrorMsg(&block.base, msg);
1988 return sema.failWithOwnedErrorMsg(msg);
19361989}
19371990
19381991fn failWithBadUnionFieldAccess(
......@@ -1942,24 +1995,23 @@ fn failWithBadUnionFieldAccess(
19421995 field_src: LazySrcLoc,
19431996 field_name: []const u8,
19441997) CompileError {
1945 const mod = sema.mod;
19461998 const gpa = sema.gpa;
19471999
19482000 const fqn = try union_obj.getFullyQualifiedName(gpa);
19492001 defer gpa.free(fqn);
19502002
19512003 const msg = msg: {
1952 const msg = try mod.errMsg(
1953 &block.base,
2004 const msg = try sema.errMsg(
2005 block,
19542006 field_src,
19552007 "no field named '{s}' in union '{s}'",
19562008 .{ field_name, fqn },
19572009 );
19582010 errdefer msg.destroy(gpa);
1959 try mod.errNoteNonLazy(union_obj.srcLoc(), msg, "union declared here", .{});
2011 try sema.mod.errNoteNonLazy(union_obj.srcLoc(), msg, "union declared here", .{});
19602012 break :msg msg;
19612013 };
1962 return mod.failWithOwnedErrorMsg(&block.base, msg);
2014 return sema.failWithOwnedErrorMsg(msg);
19632015}
19642016
19652017fn zirStoreToBlockPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!void {
......@@ -2150,7 +2202,7 @@ fn zirCompileError(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Compi
21502202 const src = inst_data.src();
21512203 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
21522204 const msg = try sema.resolveConstString(block, operand_src, inst_data.operand);
2153 return sema.mod.fail(&block.base, src, "{s}", .{msg});
2205 return sema.fail(block, src, "{s}", .{msg});
21542206}
21552207
21562208fn zirCompileLog(
......@@ -2269,7 +2321,7 @@ fn zirCImport(sema: *Sema, parent_block: *Scope.Block, inst: Zir.Inst.Index) Com
22692321
22702322 // we check this here to avoid undefined symbols
22712323 if (!@import("build_options").have_llvm)
2272 return sema.mod.fail(&parent_block.base, src, "cannot do C import on Zig compiler not built with LLVM-extension", .{});
2324 return sema.fail(&parent_block, src, "cannot do C import on Zig compiler not built with LLVM-extension", .{});
22732325
22742326 var c_import_buf = std.ArrayList(u8).init(sema.gpa);
22752327 defer c_import_buf.deinit();
......@@ -2290,15 +2342,15 @@ fn zirCImport(sema: *Sema, parent_block: *Scope.Block, inst: Zir.Inst.Index) Com
22902342 _ = try sema.analyzeBody(&child_block, body);
22912343
22922344 const c_import_res = sema.mod.comp.cImport(c_import_buf.items) catch |err|
2293 return sema.mod.fail(&child_block.base, src, "C import failed: {s}", .{@errorName(err)});
2345 return sema.fail(&child_block, src, "C import failed: {s}", .{@errorName(err)});
22942346
22952347 if (c_import_res.errors.len != 0) {
22962348 const msg = msg: {
2297 const msg = try sema.mod.errMsg(&child_block.base, src, "C import failed", .{});
2349 const msg = try sema.errMsg(&child_block, src, "C import failed", .{});
22982350 errdefer msg.destroy(sema.gpa);
22992351
23002352 if (!sema.mod.comp.bin_file.options.link_libc)
2301 try sema.mod.errNote(&child_block.base, src, msg, "libc headers not available; compilation does not link against libc", .{});
2353 try sema.errNote(&child_block, src, msg, "libc headers not available; compilation does not link against libc", .{});
23022354
23032355 for (c_import_res.errors) |_| {
23042356 // TODO integrate with LazySrcLoc
......@@ -2310,7 +2362,7 @@ fn zirCImport(sema: *Sema, parent_block: *Scope.Block, inst: Zir.Inst.Index) Com
23102362 @import("clang.zig").Stage2ErrorMsg.delete(c_import_res.errors.ptr, c_import_res.errors.len);
23112363 break :msg msg;
23122364 };
2313 return sema.mod.failWithOwnedErrorMsg(&child_block.base, msg);
2365 return sema.failWithOwnedErrorMsg(msg);
23142366 }
23152367 const c_import_pkg = Package.create(
23162368 sema.gpa,
......@@ -2326,10 +2378,10 @@ fn zirCImport(sema: *Sema, parent_block: *Scope.Block, inst: Zir.Inst.Index) Com
23262378 try c_import_pkg.add(sema.gpa, "std", std_pkg);
23272379
23282380 const result = sema.mod.importPkg(c_import_pkg) catch |err|
2329 return sema.mod.fail(&child_block.base, src, "C import failed: {s}", .{@errorName(err)});
2381 return sema.fail(&child_block, src, "C import failed: {s}", .{@errorName(err)});
23302382
23312383 sema.mod.astGenFile(result.file) catch |err|
2332 return sema.mod.fail(&child_block.base, src, "C import failed: {s}", .{@errorName(err)});
2384 return sema.fail(&child_block, src, "C import failed: {s}", .{@errorName(err)});
23332385
23342386 try sema.mod.semaFile(result.file);
23352387 const file_root_decl = result.file.root_decl.?;
......@@ -2340,7 +2392,7 @@ fn zirCImport(sema: *Sema, parent_block: *Scope.Block, inst: Zir.Inst.Index) Com
23402392fn zirSuspendBlock(sema: *Sema, parent_block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
23412393 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
23422394 const src = inst_data.src();
2343 return sema.mod.fail(&parent_block.base, src, "TODO: implement Sema.zirSuspendBlock", .{});
2395 return sema.fail(parent_block, src, "TODO: implement Sema.zirSuspendBlock", .{});
23442396}
23452397
23462398fn zirBlock(
......@@ -2527,11 +2579,11 @@ fn zirExport(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErro
25272579 const options_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };
25282580 const decl_name = sema.code.nullTerminatedString(extra.decl_name);
25292581 if (extra.namespace != .none) {
2530 return sema.mod.fail(&block.base, src, "TODO: implement exporting with field access", .{});
2582 return sema.fail(block, src, "TODO: implement exporting with field access", .{});
25312583 }
25322584 const decl = try sema.lookupIdentifier(block, operand_src, decl_name);
25332585 const options = try sema.resolveExportOptions(block, options_src, extra.options);
2534 try sema.mod.analyzeExport(block, src, options, decl);
2586 try sema.analyzeExport(block, src, options, decl);
25352587}
25362588
25372589fn zirExportValue(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!void {
......@@ -2547,40 +2599,117 @@ fn zirExportValue(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Compil
25472599 const options = try sema.resolveExportOptions(block, options_src, extra.options);
25482600 const decl = switch (operand.val.tag()) {
25492601 .function => operand.val.castTag(.function).?.data.owner_decl,
2550 else => return sema.mod.fail(&block.base, operand_src, "TODO implement exporting arbitrary Value objects", .{}), // TODO put this Value into an anonymous Decl and then export it.
2602 else => return sema.fail(block, operand_src, "TODO implement exporting arbitrary Value objects", .{}), // TODO put this Value into an anonymous Decl and then export it.
25512603 };
2552 try sema.mod.analyzeExport(block, src, options, decl);
2604 try sema.analyzeExport(block, src, options, decl);
25532605}
25542606
2555fn zirSetAlignStack(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!void {
2607pub fn analyzeExport(
2608 sema: *Sema,
2609 block: *Scope.Block,
2610 src: LazySrcLoc,
2611 borrowed_options: std.builtin.ExportOptions,
2612 exported_decl: *Decl,
2613) !void {
2614 const Export = Module.Export;
25562615 const mod = sema.mod;
2616
2617 try mod.ensureDeclAnalyzed(exported_decl);
2618 switch (exported_decl.ty.zigTypeTag()) {
2619 .Fn => {},
2620 else => return sema.fail(block, src, "unable to export type '{}'", .{exported_decl.ty}),
2621 }
2622
2623 const gpa = mod.gpa;
2624
2625 try mod.decl_exports.ensureUnusedCapacity(gpa, 1);
2626 try mod.export_owners.ensureUnusedCapacity(gpa, 1);
2627
2628 const new_export = try gpa.create(Export);
2629 errdefer gpa.destroy(new_export);
2630
2631 const symbol_name = try gpa.dupe(u8, borrowed_options.name);
2632 errdefer gpa.free(symbol_name);
2633
2634 const section: ?[]const u8 = if (borrowed_options.section) |s| try gpa.dupe(u8, s) else null;
2635 errdefer if (section) |s| gpa.free(s);
2636
2637 const src_decl = block.src_decl;
2638 const owner_decl = sema.owner_decl;
2639
2640 log.debug("exporting Decl '{s}' as symbol '{s}' from Decl '{s}'", .{
2641 exported_decl.name, symbol_name, owner_decl.name,
2642 });
2643
2644 new_export.* = .{
2645 .options = .{
2646 .name = symbol_name,
2647 .linkage = borrowed_options.linkage,
2648 .section = section,
2649 },
2650 .src = src,
2651 .link = switch (mod.comp.bin_file.tag) {
2652 .coff => .{ .coff = {} },
2653 .elf => .{ .elf = .{} },
2654 .macho => .{ .macho = .{} },
2655 .plan9 => .{ .plan9 = null },
2656 .c => .{ .c = {} },
2657 .wasm => .{ .wasm = {} },
2658 .spirv => .{ .spirv = {} },
2659 },
2660 .owner_decl = owner_decl,
2661 .src_decl = src_decl,
2662 .exported_decl = exported_decl,
2663 .status = .in_progress,
2664 };
2665
2666 // Add to export_owners table.
2667 const eo_gop = mod.export_owners.getOrPutAssumeCapacity(owner_decl);
2668 if (!eo_gop.found_existing) {
2669 eo_gop.value_ptr.* = &[0]*Export{};
2670 }
2671 eo_gop.value_ptr.* = try gpa.realloc(eo_gop.value_ptr.*, eo_gop.value_ptr.len + 1);
2672 eo_gop.value_ptr.*[eo_gop.value_ptr.len - 1] = new_export;
2673 errdefer eo_gop.value_ptr.* = gpa.shrink(eo_gop.value_ptr.*, eo_gop.value_ptr.len - 1);
2674
2675 // Add to exported_decl table.
2676 const de_gop = mod.decl_exports.getOrPutAssumeCapacity(exported_decl);
2677 if (!de_gop.found_existing) {
2678 de_gop.value_ptr.* = &[0]*Export{};
2679 }
2680 de_gop.value_ptr.* = try gpa.realloc(de_gop.value_ptr.*, de_gop.value_ptr.len + 1);
2681 de_gop.value_ptr.*[de_gop.value_ptr.len - 1] = new_export;
2682 errdefer de_gop.value_ptr.* = gpa.shrink(de_gop.value_ptr.*, de_gop.value_ptr.len - 1);
2683}
2684
2685fn zirSetAlignStack(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!void {
25572686 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
25582687 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
25592688 const src: LazySrcLoc = inst_data.src();
25602689 const alignment = try sema.resolveAlign(block, operand_src, inst_data.operand);
25612690 if (alignment > 256) {
2562 return mod.fail(&block.base, src, "attempt to @setAlignStack({d}); maximum is 256", .{
2691 return sema.fail(block, src, "attempt to @setAlignStack({d}); maximum is 256", .{
25632692 alignment,
25642693 });
25652694 }
25662695 const func = sema.owner_func orelse
2567 return mod.fail(&block.base, src, "@setAlignStack outside function body", .{});
2696 return sema.fail(block, src, "@setAlignStack outside function body", .{});
25682697
25692698 switch (func.owner_decl.ty.fnCallingConvention()) {
2570 .Naked => return mod.fail(&block.base, src, "@setAlignStack in naked function", .{}),
2571 .Inline => return mod.fail(&block.base, src, "@setAlignStack in inline function", .{}),
2699 .Naked => return sema.fail(block, src, "@setAlignStack in naked function", .{}),
2700 .Inline => return sema.fail(block, src, "@setAlignStack in inline function", .{}),
25722701 else => {},
25732702 }
25742703
2575 const gop = try mod.align_stack_fns.getOrPut(mod.gpa, func);
2704 const gop = try sema.mod.align_stack_fns.getOrPut(sema.mod.gpa, func);
25762705 if (gop.found_existing) {
25772706 const msg = msg: {
2578 const msg = try mod.errMsg(&block.base, src, "multiple @setAlignStack in the same function body", .{});
2579 errdefer msg.destroy(mod.gpa);
2580 try mod.errNote(&block.base, src, msg, "other instance here", .{});
2707 const msg = try sema.errMsg(block, src, "multiple @setAlignStack in the same function body", .{});
2708 errdefer msg.destroy(sema.gpa);
2709 try sema.errNote(block, src, msg, "other instance here", .{});
25812710 break :msg msg;
25822711 };
2583 return mod.failWithOwnedErrorMsg(&block.base, msg);
2712 return sema.failWithOwnedErrorMsg(msg);
25842713 }
25852714 gop.value_ptr.* = .{ .alignment = alignment, .src = src };
25862715}
......@@ -2596,7 +2725,7 @@ fn zirSetCold(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErr
25962725fn zirSetFloatMode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!void {
25972726 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
25982727 const src: LazySrcLoc = inst_data.src();
2599 return sema.mod.fail(&block.base, src, "TODO: implement Sema.zirSetFloatMode", .{});
2728 return sema.fail(block, src, "TODO: implement Sema.zirSetFloatMode", .{});
26002729}
26012730
26022731fn zirSetRuntimeSafety(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!void {
......@@ -2613,7 +2742,7 @@ fn zirFence(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError
26132742 const order = try sema.resolveAtomicOrder(block, order_src, inst_data.operand);
26142743
26152744 if (@enumToInt(order) < @enumToInt(std.builtin.AtomicOrder.Acquire)) {
2616 return sema.mod.fail(&block.base, order_src, "atomic ordering must be Acquire or stricter", .{});
2745 return sema.fail(block, order_src, "atomic ordering must be Acquire or stricter", .{});
26172746 }
26182747
26192748 _ = try block.addInst(.{
......@@ -2757,7 +2886,7 @@ fn lookupInNamespace(
27572886 },
27582887 else => {
27592888 const msg = msg: {
2760 const msg = try mod.errMsg(&block.base, src, "ambiguous reference", .{});
2889 const msg = try sema.errMsg(block, src, "ambiguous reference", .{});
27612890 errdefer msg.destroy(gpa);
27622891 for (candidates.items) |candidate| {
27632892 const src_loc = candidate.srcLoc();
......@@ -2765,7 +2894,7 @@ fn lookupInNamespace(
27652894 }
27662895 break :msg msg;
27672896 };
2768 return mod.failWithOwnedErrorMsg(&block.base, msg);
2897 return sema.failWithOwnedErrorMsg(msg);
27692898 },
27702899 }
27712900 } else if (namespace.decls.get(ident_name)) |decl| {
......@@ -2899,14 +3028,14 @@ fn analyzeCall(
28993028
29003029 const func_ty = sema.typeOf(func);
29013030 if (func_ty.zigTypeTag() != .Fn)
2902 return mod.fail(&block.base, func_src, "type '{}' not a function", .{func_ty});
3031 return sema.fail(block, func_src, "type '{}' not a function", .{func_ty});
29033032
29043033 const func_ty_info = func_ty.fnInfo();
29053034 const cc = func_ty_info.cc;
29063035 if (cc == .Naked) {
29073036 // TODO add error note: declared here
2908 return mod.fail(
2909 &block.base,
3037 return sema.fail(
3038 block,
29103039 func_src,
29113040 "unable to call function with naked calling convention",
29123041 .{},
......@@ -2917,8 +3046,8 @@ fn analyzeCall(
29173046 assert(cc == .C);
29183047 if (uncasted_args.len < fn_params_len) {
29193048 // TODO add error note: declared here
2920 return mod.fail(
2921 &block.base,
3049 return sema.fail(
3050 block,
29223051 func_src,
29233052 "expected at least {d} argument(s), found {d}",
29243053 .{ fn_params_len, uncasted_args.len },
......@@ -2926,8 +3055,8 @@ fn analyzeCall(
29263055 }
29273056 } else if (fn_params_len != uncasted_args.len) {
29283057 // TODO add error note: declared here
2929 return mod.fail(
2930 &block.base,
3058 return sema.fail(
3059 block,
29313060 func_src,
29323061 "expected {d} argument(s), found {d}",
29333062 .{ fn_params_len, uncasted_args.len },
......@@ -2945,7 +3074,7 @@ fn analyzeCall(
29453074 .never_inline,
29463075 .no_async,
29473076 .always_tail,
2948 => return mod.fail(&block.base, call_src, "TODO implement call with modifier {}", .{
3077 => return sema.fail(block, call_src, "TODO implement call with modifier {}", .{
29493078 modifier,
29503079 }),
29513080 }
......@@ -2960,7 +3089,7 @@ fn analyzeCall(
29603089 const func_val = try sema.resolveConstValue(block, func_src, func);
29613090 const module_fn = switch (func_val.tag()) {
29623091 .function => func_val.castTag(.function).?.data,
2963 .extern_fn => return mod.fail(&block.base, call_src, "{s} call of extern function", .{
3092 .extern_fn => return sema.fail(block, call_src, "{s} call of extern function", .{
29643093 @as([]const u8, if (is_comptime_call) "comptime" else "inline"),
29653094 }),
29663095 else => unreachable,
......@@ -3633,7 +3762,7 @@ fn zirErrorUnionType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Com
36333762 const payload = try sema.resolveType(block, rhs_src, extra.rhs);
36343763
36353764 if (error_union.zigTypeTag() != .ErrorSet) {
3636 return sema.mod.fail(&block.base, lhs_src, "expected error set type, found {}", .{
3765 return sema.fail(block, lhs_src, "expected error set type, found {}", .{
36373766 error_union.elemType(),
36383767 });
36393768 }
......@@ -3699,7 +3828,7 @@ fn zirIntToError(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Compile
36993828 if (try sema.resolveDefinedValue(block, operand_src, op)) |value| {
37003829 const int = value.toUnsignedInt();
37013830 if (int > sema.mod.global_error_set.count() or int == 0)
3702 return sema.mod.fail(&block.base, operand_src, "integer value {d} represents no error", .{int});
3831 return sema.fail(block, operand_src, "integer value {d} represents no error", .{int});
37033832 const payload = try sema.arena.create(Value.Payload.Error);
37043833 payload.* = .{
37053834 .base = .{ .tag = .@"error" },
......@@ -3709,7 +3838,7 @@ fn zirIntToError(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Compile
37093838 }
37103839 try sema.requireRuntimeBlock(block, src);
37113840 if (block.wantSafety()) {
3712 return sema.mod.fail(&block.base, src, "TODO: get max errors in compilation", .{});
3841 return sema.fail(block, src, "TODO: get max errors in compilation", .{});
37133842 // const is_gt_max = @panic("TODO get max errors in compilation");
37143843 // try sema.addSafetyCheck(block, is_gt_max, .invalid_error_code);
37153844 }
......@@ -3729,19 +3858,19 @@ fn zirMergeErrorSets(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Com
37293858 const rhs = sema.resolveInst(extra.rhs);
37303859 if (sema.typeOf(lhs).zigTypeTag() == .Bool and sema.typeOf(rhs).zigTypeTag() == .Bool) {
37313860 const msg = msg: {
3732 const msg = try sema.mod.errMsg(&block.base, lhs_src, "expected error set type, found 'bool'", .{});
3861 const msg = try sema.errMsg(block, lhs_src, "expected error set type, found 'bool'", .{});
37333862 errdefer msg.destroy(sema.gpa);
3734 try sema.mod.errNote(&block.base, src, msg, "'||' merges error sets; 'or' performs boolean OR", .{});
3863 try sema.errNote(block, src, msg, "'||' merges error sets; 'or' performs boolean OR", .{});
37353864 break :msg msg;
37363865 };
3737 return sema.mod.failWithOwnedErrorMsg(&block.base, msg);
3866 return sema.failWithOwnedErrorMsg(msg);
37383867 }
37393868 const lhs_ty = try sema.analyzeAsType(block, lhs_src, lhs);
37403869 const rhs_ty = try sema.analyzeAsType(block, rhs_src, rhs);
37413870 if (lhs_ty.zigTypeTag() != .ErrorSet)
3742 return sema.mod.fail(&block.base, lhs_src, "expected error set type, found {}", .{lhs_ty});
3871 return sema.fail(block, lhs_src, "expected error set type, found {}", .{lhs_ty});
37433872 if (rhs_ty.zigTypeTag() != .ErrorSet)
3744 return sema.mod.fail(&block.base, rhs_src, "expected error set type, found {}", .{rhs_ty});
3873 return sema.fail(block, rhs_src, "expected error set type, found {}", .{rhs_ty});
37453874
37463875 // Anything merged with anyerror is anyerror.
37473876 if (lhs_ty.tag() == .anyerror or rhs_ty.tag() == .anyerror) {
......@@ -3814,7 +3943,6 @@ fn zirEnumLiteral(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Compil
38143943}
38153944
38163945fn zirEnumToInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
3817 const mod = sema.mod;
38183946 const arena = sema.arena;
38193947 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
38203948 const src = inst_data.src();
......@@ -3826,17 +3954,17 @@ fn zirEnumToInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileE
38263954 .Enum => operand,
38273955 .Union => {
38283956 //if (!operand_ty.unionHasTag()) {
3829 // return mod.fail(
3830 // &block.base,
3957 // return sema.fail(
3958 // block,
38313959 // operand_src,
38323960 // "untagged union '{}' cannot be converted to integer",
38333961 // .{dest_ty_src},
38343962 // );
38353963 //}
3836 return mod.fail(&block.base, operand_src, "TODO zirEnumToInt for tagged unions", .{});
3964 return sema.fail(block, operand_src, "TODO zirEnumToInt for tagged unions", .{});
38373965 },
38383966 else => {
3839 return mod.fail(&block.base, operand_src, "expected enum or tagged union, found {}", .{
3967 return sema.fail(block, operand_src, "expected enum or tagged union, found {}", .{
38403968 operand_ty,
38413969 });
38423970 },
......@@ -3861,8 +3989,7 @@ fn zirEnumToInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileE
38613989}
38623990
38633991fn zirIntToEnum(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
3864 const mod = sema.mod;
3865 const target = mod.getTarget();
3992 const target = sema.mod.getTarget();
38663993 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
38673994 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
38683995 const src = inst_data.src();
......@@ -3872,7 +3999,7 @@ fn zirIntToEnum(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileE
38723999 const operand = sema.resolveInst(extra.rhs);
38734000
38744001 if (dest_ty.zigTypeTag() != .Enum) {
3875 return mod.fail(&block.base, dest_ty_src, "expected enum, found {}", .{dest_ty});
4002 return sema.fail(block, dest_ty_src, "expected enum, found {}", .{dest_ty});
38764003 }
38774004
38784005 if (try sema.resolveMaybeUndefVal(block, operand_src, operand)) |int_val| {
......@@ -3884,14 +4011,14 @@ fn zirIntToEnum(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileE
38844011 }
38854012 if (!dest_ty.enumHasInt(int_val, target)) {
38864013 const msg = msg: {
3887 const msg = try mod.errMsg(
3888 &block.base,
4014 const msg = try sema.errMsg(
4015 block,
38894016 src,
38904017 "enum '{}' has no tag with value {}",
38914018 .{ dest_ty, int_val },
38924019 );
38934020 errdefer msg.destroy(sema.gpa);
3894 try mod.errNoteNonLazy(
4021 try sema.mod.errNoteNonLazy(
38954022 dest_ty.declSrcLoc(),
38964023 msg,
38974024 "enum declared here",
......@@ -3899,7 +4026,7 @@ fn zirIntToEnum(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileE
38994026 );
39004027 break :msg msg;
39014028 };
3902 return mod.failWithOwnedErrorMsg(&block.base, msg);
4029 return sema.failWithOwnedErrorMsg(msg);
39034030 }
39044031 return sema.addConstant(dest_ty, int_val);
39054032 }
......@@ -3926,7 +4053,7 @@ fn zirOptionalPayloadPtr(
39264053
39274054 const opt_type = optional_ptr_ty.elemType();
39284055 if (opt_type.zigTypeTag() != .Optional) {
3929 return sema.mod.fail(&block.base, src, "expected optional type, found {}", .{opt_type});
4056 return sema.fail(block, src, "expected optional type, found {}", .{opt_type});
39304057 }
39314058
39324059 const child_type = try opt_type.optionalChildAlloc(sema.arena);
......@@ -3939,7 +4066,7 @@ fn zirOptionalPayloadPtr(
39394066 if (try sema.resolveDefinedValue(block, src, optional_ptr)) |pointer_val| {
39404067 if (try pointer_val.pointerDeref(sema.arena)) |val| {
39414068 if (val.isNull()) {
3942 return sema.mod.fail(&block.base, src, "unable to unwrap null", .{});
4069 return sema.fail(block, src, "unable to unwrap null", .{});
39434070 }
39444071 // The same Value represents the pointer to the optional and the payload.
39454072 return sema.addConstant(
......@@ -3973,14 +4100,14 @@ fn zirOptionalPayload(
39734100 const operand_ty = sema.typeOf(operand);
39744101 const opt_type = operand_ty;
39754102 if (opt_type.zigTypeTag() != .Optional) {
3976 return sema.mod.fail(&block.base, src, "expected optional type, found {}", .{opt_type});
4103 return sema.fail(block, src, "expected optional type, found {}", .{opt_type});
39774104 }
39784105
39794106 const child_type = try opt_type.optionalChildAlloc(sema.arena);
39804107
39814108 if (try sema.resolveDefinedValue(block, src, operand)) |val| {
39824109 if (val.isNull()) {
3983 return sema.mod.fail(&block.base, src, "unable to unwrap null", .{});
4110 return sema.fail(block, src, "unable to unwrap null", .{});
39844111 }
39854112 const sub_val = val.castTag(.opt_payload).?.data;
39864113 return sema.addConstant(child_type, sub_val);
......@@ -4010,11 +4137,11 @@ fn zirErrUnionPayload(
40104137 const operand_src = src;
40114138 const operand_ty = sema.typeOf(operand);
40124139 if (operand_ty.zigTypeTag() != .ErrorUnion)
4013 return sema.mod.fail(&block.base, operand_src, "expected error union type, found '{}'", .{operand_ty});
4140 return sema.fail(block, operand_src, "expected error union type, found '{}'", .{operand_ty});
40144141
40154142 if (try sema.resolveDefinedValue(block, src, operand)) |val| {
40164143 if (val.getError()) |name| {
4017 return sema.mod.fail(&block.base, src, "caught unexpected error '{s}'", .{name});
4144 return sema.fail(block, src, "caught unexpected error '{s}'", .{name});
40184145 }
40194146 const data = val.castTag(.eu_payload).?.data;
40204147 const result_ty = operand_ty.errorUnionPayload();
......@@ -4046,7 +4173,7 @@ fn zirErrUnionPayloadPtr(
40464173 assert(operand_ty.zigTypeTag() == .Pointer);
40474174
40484175 if (operand_ty.elemType().zigTypeTag() != .ErrorUnion)
4049 return sema.mod.fail(&block.base, src, "expected error union type, found {}", .{operand_ty.elemType()});
4176 return sema.fail(block, src, "expected error union type, found {}", .{operand_ty.elemType()});
40504177
40514178 const payload_ty = operand_ty.elemType().errorUnionPayload();
40524179 const operand_pointer_ty = try Type.ptr(sema.arena, .{
......@@ -4058,7 +4185,7 @@ fn zirErrUnionPayloadPtr(
40584185 if (try sema.resolveDefinedValue(block, src, operand)) |pointer_val| {
40594186 if (try pointer_val.pointerDeref(sema.arena)) |val| {
40604187 if (val.getError()) |name| {
4061 return sema.mod.fail(&block.base, src, "caught unexpected error '{s}'", .{name});
4188 return sema.fail(block, src, "caught unexpected error '{s}'", .{name});
40624189 }
40634190 return sema.addConstant(
40644191 operand_pointer_ty,
......@@ -4085,7 +4212,7 @@ fn zirErrUnionCode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Compi
40854212 const operand = sema.resolveInst(inst_data.operand);
40864213 const operand_ty = sema.typeOf(operand);
40874214 if (operand_ty.zigTypeTag() != .ErrorUnion)
4088 return sema.mod.fail(&block.base, src, "expected error union type, found '{}'", .{operand_ty});
4215 return sema.fail(block, src, "expected error union type, found '{}'", .{operand_ty});
40894216
40904217 const result_ty = operand_ty.errorUnionSet();
40914218
......@@ -4110,7 +4237,7 @@ fn zirErrUnionCodePtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Co
41104237 assert(operand_ty.zigTypeTag() == .Pointer);
41114238
41124239 if (operand_ty.elemType().zigTypeTag() != .ErrorUnion)
4113 return sema.mod.fail(&block.base, src, "expected error union type, found {}", .{operand_ty.elemType()});
4240 return sema.fail(block, src, "expected error union type, found {}", .{operand_ty.elemType()});
41144241
41154242 const result_ty = operand_ty.elemType().errorUnionSet();
41164243
......@@ -4134,9 +4261,9 @@ fn zirEnsureErrPayloadVoid(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Inde
41344261 const operand = sema.resolveInst(inst_data.operand);
41354262 const operand_ty = sema.typeOf(operand);
41364263 if (operand_ty.zigTypeTag() != .ErrorUnion)
4137 return sema.mod.fail(&block.base, src, "expected error union type, found '{}'", .{operand_ty});
4264 return sema.fail(block, src, "expected error union type, found '{}'", .{operand_ty});
41384265 if (operand_ty.errorUnionPayload().zigTypeTag() != .Void) {
4139 return sema.mod.fail(&block.base, src, "expression value is ignored", .{});
4266 return sema.fail(block, src, "expression value is ignored", .{});
41404267 }
41414268}
41424269
......@@ -4277,7 +4404,7 @@ fn funcCommon(
42774404 }
42784405
42794406 if (align_val.tag() != .null_value) {
4280 return mod.fail(&block.base, src, "TODO implement support for function prototypes to have alignment specified", .{});
4407 return sema.fail(block, src, "TODO implement support for function prototypes to have alignment specified", .{});
42814408 }
42824409
42834410 is_generic = is_generic or bare_return_type.requiresComptime();
......@@ -4309,15 +4436,15 @@ fn funcCommon(
43094436 const lib_name_src: LazySrcLoc = .{ .node_offset_lib_name = src_node_offset };
43104437 log.debug("extern fn symbol expected in lib '{s}'", .{lib_name});
43114438 mod.comp.stage1AddLinkLib(lib_name) catch |err| {
4312 return mod.fail(&block.base, lib_name_src, "unable to add link lib '{s}': {s}", .{
4439 return sema.fail(block, lib_name_src, "unable to add link lib '{s}': {s}", .{
43134440 lib_name, @errorName(err),
43144441 });
43154442 };
43164443 const target = mod.getTarget();
43174444 if (target_util.is_libc_lib_name(target, lib_name)) {
43184445 if (!mod.comp.bin_file.options.link_libc) {
4319 return mod.fail(
4320 &block.base,
4446 return sema.fail(
4447 block,
43214448 lib_name_src,
43224449 "dependency on libc must be explicitly specified in the build command",
43234450 .{},
......@@ -4327,8 +4454,8 @@ fn funcCommon(
43274454 }
43284455 if (target_util.is_libcpp_lib_name(target, lib_name)) {
43294456 if (!mod.comp.bin_file.options.link_libcpp) {
4330 return mod.fail(
4331 &block.base,
4457 return sema.fail(
4458 block,
43324459 lib_name_src,
43334460 "dependency on libc++ must be explicitly specified in the build command",
43344461 .{},
......@@ -4337,8 +4464,8 @@ fn funcCommon(
43374464 break :blk;
43384465 }
43394466 if (!target.isWasm() and !mod.comp.bin_file.options.pic) {
4340 return mod.fail(
4341 &block.base,
4467 return sema.fail(
4468 block,
43424469 lib_name_src,
43434470 "dependency on dynamic library '{s}' requires enabling Position Independent Code. Fixed by `-l{s}` or `-fPIC`.",
43444471 .{ lib_name, lib_name },
......@@ -4528,7 +4655,7 @@ fn zirPtrToInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileEr
45284655 const ptr_ty = sema.typeOf(ptr);
45294656 if (ptr_ty.zigTypeTag() != .Pointer) {
45304657 const ptr_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
4531 return sema.mod.fail(&block.base, ptr_src, "expected pointer, found '{}'", .{ptr_ty});
4658 return sema.fail(block, ptr_src, "expected pointer, found '{}'", .{ptr_ty});
45324659 }
45334660 // TODO handle known-pointer-address
45344661 const src = inst_data.src();
......@@ -4639,7 +4766,7 @@ fn zirIntCast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErr
46394766 if (try sema.isComptimeKnown(block, operand_src, operand)) {
46404767 return sema.coerce(block, dest_type, operand, operand_src);
46414768 } else if (dest_is_comptime_int) {
4642 return sema.mod.fail(&block.base, src, "unable to cast runtime value to 'comptime_int'", .{});
4769 return sema.fail(block, src, "unable to cast runtime value to 'comptime_int'", .{});
46434770 }
46444771
46454772 try sema.requireRuntimeBlock(block, operand_src);
......@@ -4676,8 +4803,8 @@ fn zirFloatCast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileE
46764803 const dest_is_comptime_float = switch (dest_type.zigTypeTag()) {
46774804 .ComptimeFloat => true,
46784805 .Float => false,
4679 else => return sema.mod.fail(
4680 &block.base,
4806 else => return sema.fail(
4807 block,
46814808 dest_ty_src,
46824809 "expected float type, found '{}'",
46834810 .{dest_type},
......@@ -4687,8 +4814,8 @@ fn zirFloatCast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileE
46874814 const operand_ty = sema.typeOf(operand);
46884815 switch (operand_ty.zigTypeTag()) {
46894816 .ComptimeFloat, .Float, .ComptimeInt => {},
4690 else => return sema.mod.fail(
4691 &block.base,
4817 else => return sema.fail(
4818 block,
46924819 operand_src,
46934820 "expected float type, found '{}'",
46944821 .{operand_ty},
......@@ -4699,7 +4826,7 @@ fn zirFloatCast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileE
46994826 return sema.coerce(block, dest_type, operand, operand_src);
47004827 }
47014828 if (dest_is_comptime_float) {
4702 return sema.mod.fail(&block.base, src, "unable to cast runtime value to 'comptime_float'", .{});
4829 return sema.fail(block, src, "unable to cast runtime value to 'comptime_float'", .{});
47034830 }
47044831 const target = sema.mod.getTarget();
47054832 const src_bits = operand_ty.floatBits(target);
......@@ -4817,7 +4944,7 @@ fn zirSwitchCapture(
48174944
48184945 _ = is_ref;
48194946 _ = is_multi;
4820 return sema.mod.fail(&block.base, src, "TODO implement Sema for zirSwitchCapture", .{});
4947 return sema.fail(block, src, "TODO implement Sema for zirSwitchCapture", .{});
48214948}
48224949
48234950fn zirSwitchCaptureElse(
......@@ -4835,7 +4962,7 @@ fn zirSwitchCaptureElse(
48354962 const src = switch_info.src();
48364963
48374964 _ = is_ref;
4838 return sema.mod.fail(&block.base, src, "TODO implement Sema for zirSwitchCaptureElse", .{});
4965 return sema.fail(block, src, "TODO implement Sema for zirSwitchCaptureElse", .{});
48394966}
48404967
48414968fn zirSwitchBlock(
......@@ -4916,7 +5043,6 @@ fn analyzeSwitch(
49165043 src_node_offset: i32,
49175044) CompileError!Air.Inst.Ref {
49185045 const gpa = sema.gpa;
4919 const mod = sema.mod;
49205046
49215047 const special: struct { body: []const Zir.Inst.Index, end: usize } = switch (special_prong) {
49225048 .none => .{ .body = &.{}, .end = extra_end },
......@@ -4938,15 +5064,15 @@ fn analyzeSwitch(
49385064 // Validate usage of '_' prongs.
49395065 if (special_prong == .under and !operand_ty.isNonexhaustiveEnum()) {
49405066 const msg = msg: {
4941 const msg = try mod.errMsg(
4942 &block.base,
5067 const msg = try sema.errMsg(
5068 block,
49435069 src,
49445070 "'_' prong only allowed when switching on non-exhaustive enums",
49455071 .{},
49465072 );
49475073 errdefer msg.destroy(gpa);
4948 try mod.errNote(
4949 &block.base,
5074 try sema.errNote(
5075 block,
49505076 special_prong_src,
49515077 msg,
49525078 "'_' prong here",
......@@ -4954,7 +5080,7 @@ fn analyzeSwitch(
49545080 );
49555081 break :msg msg;
49565082 };
4957 return mod.failWithOwnedErrorMsg(&block.base, msg);
5083 return sema.failWithOwnedErrorMsg(msg);
49585084 }
49595085
49605086 // Validate for duplicate items, missing else prong, and invalid range.
......@@ -5017,8 +5143,8 @@ fn analyzeSwitch(
50175143 .none => {
50185144 if (!all_tags_handled) {
50195145 const msg = msg: {
5020 const msg = try mod.errMsg(
5021 &block.base,
5146 const msg = try sema.errMsg(
5147 block,
50225148 src,
50235149 "switch must handle all possibilities",
50245150 .{},
......@@ -5030,15 +5156,15 @@ fn analyzeSwitch(
50305156 const field_name = operand_ty.enumFieldName(i);
50315157
50325158 // TODO have this point to the tag decl instead of here
5033 try mod.errNote(
5034 &block.base,
5159 try sema.errNote(
5160 block,
50355161 src,
50365162 msg,
50375163 "unhandled enumeration value: '{s}'",
50385164 .{field_name},
50395165 );
50405166 }
5041 try mod.errNoteNonLazy(
5167 try sema.mod.errNoteNonLazy(
50425168 operand_ty.declSrcLoc(),
50435169 msg,
50445170 "enum '{}' declared here",
......@@ -5046,20 +5172,20 @@ fn analyzeSwitch(
50465172 );
50475173 break :msg msg;
50485174 };
5049 return mod.failWithOwnedErrorMsg(&block.base, msg);
5175 return sema.failWithOwnedErrorMsg(msg);
50505176 }
50515177 },
50525178 .under => {
5053 if (all_tags_handled) return mod.fail(
5054 &block.base,
5179 if (all_tags_handled) return sema.fail(
5180 block,
50555181 special_prong_src,
50565182 "unreachable '_' prong; all cases already handled",
50575183 .{},
50585184 );
50595185 },
50605186 .@"else" => {
5061 if (all_tags_handled) return mod.fail(
5062 &block.base,
5187 if (all_tags_handled) return sema.fail(
5188 block,
50635189 special_prong_src,
50645190 "unreachable else prong; all cases already handled",
50655191 .{},
......@@ -5068,8 +5194,8 @@ fn analyzeSwitch(
50685194 }
50695195 },
50705196
5071 .ErrorSet => return mod.fail(&block.base, src, "TODO validate switch .ErrorSet", .{}),
5072 .Union => return mod.fail(&block.base, src, "TODO validate switch .Union", .{}),
5197 .ErrorSet => return sema.fail(block, src, "TODO validate switch .ErrorSet", .{}),
5198 .Union => return sema.fail(block, src, "TODO validate switch .Union", .{}),
50735199 .Int, .ComptimeInt => {
50745200 var range_set = RangeSet.init(gpa);
50755201 defer range_set.deinit();
......@@ -5144,12 +5270,13 @@ fn analyzeSwitch(
51445270 var arena = std.heap.ArenaAllocator.init(gpa);
51455271 defer arena.deinit();
51465272
5147 const min_int = try operand_ty.minInt(&arena.allocator, mod.getTarget());
5148 const max_int = try operand_ty.maxInt(&arena.allocator, mod.getTarget());
5273 const target = sema.mod.getTarget();
5274 const min_int = try operand_ty.minInt(&arena.allocator, target);
5275 const max_int = try operand_ty.maxInt(&arena.allocator, target);
51495276 if (try range_set.spans(min_int, max_int, operand_ty)) {
51505277 if (special_prong == .@"else") {
5151 return mod.fail(
5152 &block.base,
5278 return sema.fail(
5279 block,
51535280 special_prong_src,
51545281 "unreachable else prong; all cases already handled",
51555282 .{},
......@@ -5159,8 +5286,8 @@ fn analyzeSwitch(
51595286 }
51605287 }
51615288 if (special_prong != .@"else") {
5162 return mod.fail(
5163 &block.base,
5289 return sema.fail(
5290 block,
51645291 src,
51655292 "switch must handle all possibilities",
51665293 .{},
......@@ -5221,8 +5348,8 @@ fn analyzeSwitch(
52215348 switch (special_prong) {
52225349 .@"else" => {
52235350 if (true_count + false_count == 2) {
5224 return mod.fail(
5225 &block.base,
5351 return sema.fail(
5352 block,
52265353 src,
52275354 "unreachable else prong; all cases already handled",
52285355 .{},
......@@ -5231,8 +5358,8 @@ fn analyzeSwitch(
52315358 },
52325359 .under, .none => {
52335360 if (true_count + false_count < 2) {
5234 return mod.fail(
5235 &block.base,
5361 return sema.fail(
5362 block,
52365363 src,
52375364 "switch must handle all possibilities",
52385365 .{},
......@@ -5243,8 +5370,8 @@ fn analyzeSwitch(
52435370 },
52445371 .EnumLiteral, .Void, .Fn, .Pointer, .Type => {
52455372 if (special_prong != .@"else") {
5246 return mod.fail(
5247 &block.base,
5373 return sema.fail(
5374 block,
52485375 src,
52495376 "else prong required when switching on type '{}'",
52505377 .{operand_ty},
......@@ -5314,7 +5441,7 @@ fn analyzeSwitch(
53145441 .AnyFrame,
53155442 .ComptimeFloat,
53165443 .Float,
5317 => return mod.fail(&block.base, operand_src, "invalid switch operand type '{}'", .{
5444 => return sema.fail(block, operand_src, "invalid switch operand type '{}'", .{
53185445 operand_ty,
53195446 }),
53205447 }
......@@ -5707,19 +5834,18 @@ fn validateSwitchItemEnum(
57075834 src_node_offset: i32,
57085835 switch_prong_src: Module.SwitchProngSrc,
57095836) CompileError!void {
5710 const mod = sema.mod;
57115837 const item_tv = try sema.resolveSwitchItemVal(block, item_ref, src_node_offset, switch_prong_src, .none);
57125838 const field_index = item_tv.ty.enumTagFieldIndex(item_tv.val) orelse {
57135839 const msg = msg: {
57145840 const src = switch_prong_src.resolve(sema.gpa, block.src_decl, src_node_offset, .none);
5715 const msg = try mod.errMsg(
5716 &block.base,
5841 const msg = try sema.errMsg(
5842 block,
57175843 src,
57185844 "enum '{}' has no tag with value '{}'",
57195845 .{ item_tv.ty, item_tv.val },
57205846 );
57215847 errdefer msg.destroy(sema.gpa);
5722 try mod.errNoteNonLazy(
5848 try sema.mod.errNoteNonLazy(
57235849 item_tv.ty.declSrcLoc(),
57245850 msg,
57255851 "enum declared here",
......@@ -5727,7 +5853,7 @@ fn validateSwitchItemEnum(
57275853 );
57285854 break :msg msg;
57295855 };
5730 return mod.failWithOwnedErrorMsg(&block.base, msg);
5856 return sema.failWithOwnedErrorMsg(msg);
57315857 };
57325858 const maybe_prev_src = seen_fields[field_index];
57335859 seen_fields[field_index] = switch_prong_src;
......@@ -5742,20 +5868,19 @@ fn validateSwitchDupe(
57425868 src_node_offset: i32,
57435869) CompileError!void {
57445870 const prev_prong_src = maybe_prev_src orelse return;
5745 const mod = sema.mod;
57465871 const gpa = sema.gpa;
57475872 const src = switch_prong_src.resolve(gpa, block.src_decl, src_node_offset, .none);
57485873 const prev_src = prev_prong_src.resolve(gpa, block.src_decl, src_node_offset, .none);
57495874 const msg = msg: {
5750 const msg = try mod.errMsg(
5751 &block.base,
5875 const msg = try sema.errMsg(
5876 block,
57525877 src,
57535878 "duplicate switch value",
57545879 .{},
57555880 );
57565881 errdefer msg.destroy(sema.gpa);
5757 try mod.errNote(
5758 &block.base,
5882 try sema.errNote(
5883 block,
57595884 prev_src,
57605885 msg,
57615886 "previous value here",
......@@ -5763,7 +5888,7 @@ fn validateSwitchDupe(
57635888 );
57645889 break :msg msg;
57655890 };
5766 return mod.failWithOwnedErrorMsg(&block.base, msg);
5891 return sema.failWithOwnedErrorMsg(msg);
57675892}
57685893
57695894fn validateSwitchItemBool(
......@@ -5783,7 +5908,7 @@ fn validateSwitchItemBool(
57835908 }
57845909 if (true_count.* + false_count.* > 2) {
57855910 const src = switch_prong_src.resolve(sema.gpa, block.src_decl, src_node_offset, .none);
5786 return sema.mod.fail(&block.base, src, "duplicate switch value", .{});
5911 return sema.fail(block, src, "duplicate switch value", .{});
57875912 }
57885913}
57895914
......@@ -5816,15 +5941,15 @@ fn validateSwitchNoRange(
58165941 const range_src: LazySrcLoc = .{ .node_offset_switch_range = src_node_offset };
58175942
58185943 const msg = msg: {
5819 const msg = try sema.mod.errMsg(
5820 &block.base,
5944 const msg = try sema.errMsg(
5945 block,
58215946 operand_src,
58225947 "ranges not allowed when switching on type '{}'",
58235948 .{operand_ty},
58245949 );
58255950 errdefer msg.destroy(sema.gpa);
5826 try sema.mod.errNote(
5827 &block.base,
5951 try sema.errNote(
5952 block,
58285953 range_src,
58295954 msg,
58305955 "range here",
......@@ -5832,7 +5957,7 @@ fn validateSwitchNoRange(
58325957 );
58335958 break :msg msg;
58345959 };
5835 return sema.mod.failWithOwnedErrorMsg(&block.base, msg);
5960 return sema.failWithOwnedErrorMsg(msg);
58365961}
58375962
58385963fn zirHasField(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
......@@ -5841,7 +5966,7 @@ fn zirHasField(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileEr
58415966 _ = extra;
58425967 const src = inst_data.src();
58435968
5844 return sema.mod.fail(&block.base, src, "TODO implement zirHasField", .{});
5969 return sema.fail(block, src, "TODO implement zirHasField", .{});
58455970}
58465971
58475972fn zirHasDecl(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
......@@ -5852,10 +5977,9 @@ fn zirHasDecl(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErr
58525977 const rhs_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };
58535978 const container_type = try sema.resolveType(block, lhs_src, extra.lhs);
58545979 const decl_name = try sema.resolveConstString(block, rhs_src, extra.rhs);
5855 const mod = sema.mod;
58565980
5857 const namespace = container_type.getNamespace() orelse return mod.fail(
5858 &block.base,
5981 const namespace = container_type.getNamespace() orelse return sema.fail(
5982 block,
58595983 lhs_src,
58605984 "expected struct, enum, union, or opaque, found '{}'",
58615985 .{container_type},
......@@ -5879,24 +6003,24 @@ fn zirImport(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErro
58796003
58806004 const result = mod.importFile(block.getFileScope(), operand) catch |err| switch (err) {
58816005 error.ImportOutsidePkgPath => {
5882 return mod.fail(&block.base, src, "import of file outside package path: '{s}'", .{operand});
6006 return sema.fail(block, src, "import of file outside package path: '{s}'", .{operand});
58836007 },
58846008 else => {
58856009 // TODO: these errors are file system errors; make sure an update() will
58866010 // retry this and not cache the file system error, which may be transient.
5887 return mod.fail(&block.base, src, "unable to open '{s}': {s}", .{ operand, @errorName(err) });
6011 return sema.fail(block, src, "unable to open '{s}': {s}", .{ operand, @errorName(err) });
58886012 },
58896013 };
58906014 try mod.semaFile(result.file);
58916015 const file_root_decl = result.file.root_decl.?;
5892 try sema.mod.declareDeclDependency(sema.owner_decl, file_root_decl);
6016 try mod.declareDeclDependency(sema.owner_decl, file_root_decl);
58936017 return sema.addConstant(file_root_decl.ty, file_root_decl.val);
58946018}
58956019
58966020fn zirRetErrValueCode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
58976021 _ = block;
58986022 _ = inst;
5899 return sema.mod.fail(&block.base, sema.src, "TODO implement zirRetErrValueCode", .{});
6023 return sema.fail(block, sema.src, "TODO implement zirRetErrValueCode", .{});
59006024}
59016025
59026026fn zirShl(
......@@ -5933,8 +6057,8 @@ fn zirShl(
59336057 }
59346058 const val = try lhs_val.shl(rhs_val, sema.arena);
59356059 switch (air_tag) {
5936 .shl_exact => return sema.mod.fail(&block.base, lhs_src, "TODO implement Sema for comptime shl_exact", .{}),
5937 .shl_sat => return sema.mod.fail(&block.base, lhs_src, "TODO implement Sema for comptime shl_sat", .{}),
6060 .shl_exact => return sema.fail(block, lhs_src, "TODO implement Sema for comptime shl_exact", .{}),
6061 .shl_sat => return sema.fail(block, lhs_src, "TODO implement Sema for comptime shl_sat", .{}),
59386062 .shl => {},
59396063 else => unreachable,
59406064 }
......@@ -6016,14 +6140,14 @@ fn zirBitwise(
60166140
60176141 if (lhs_ty.zigTypeTag() == .Vector and rhs_ty.zigTypeTag() == .Vector) {
60186142 if (lhs_ty.arrayLen() != rhs_ty.arrayLen()) {
6019 return sema.mod.fail(&block.base, src, "vector length mismatch: {d} and {d}", .{
6143 return sema.fail(block, src, "vector length mismatch: {d} and {d}", .{
60206144 lhs_ty.arrayLen(),
60216145 rhs_ty.arrayLen(),
60226146 });
60236147 }
6024 return sema.mod.fail(&block.base, src, "TODO implement support for vectors in zirBitwise", .{});
6148 return sema.fail(block, src, "TODO implement support for vectors in zirBitwise", .{});
60256149 } else if (lhs_ty.zigTypeTag() == .Vector or rhs_ty.zigTypeTag() == .Vector) {
6026 return sema.mod.fail(&block.base, src, "mixed scalar and vector operands to binary expression: '{}' and '{}'", .{
6150 return sema.fail(block, src, "mixed scalar and vector operands to binary expression: '{}' and '{}'", .{
60276151 lhs_ty,
60286152 rhs_ty,
60296153 });
......@@ -6032,7 +6156,7 @@ fn zirBitwise(
60326156 const is_int = scalar_tag == .Int or scalar_tag == .ComptimeInt;
60336157
60346158 if (!is_int) {
6035 return sema.mod.fail(&block.base, src, "invalid operands to binary bitwise expression: '{s}' and '{s}'", .{ @tagName(lhs_ty.zigTypeTag()), @tagName(rhs_ty.zigTypeTag()) });
6159 return sema.fail(block, src, "invalid operands to binary bitwise expression: '{s}' and '{s}'", .{ @tagName(lhs_ty.zigTypeTag()), @tagName(rhs_ty.zigTypeTag()) });
60366160 }
60376161
60386162 if (try sema.resolveMaybeUndefVal(block, lhs_src, casted_lhs)) |lhs_val| {
......@@ -6056,7 +6180,7 @@ fn zirBitNot(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErro
60566180 defer tracy.end();
60576181
60586182 _ = inst;
6059 return sema.mod.fail(&block.base, sema.src, "TODO implement zirBitNot", .{});
6183 return sema.fail(block, sema.src, "TODO implement zirBitNot", .{});
60606184}
60616185
60626186fn zirArrayCat(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
......@@ -6073,11 +6197,11 @@ fn zirArrayCat(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileEr
60736197 const rhs_src: LazySrcLoc = .{ .node_offset_bin_rhs = inst_data.src_node };
60746198
60756199 const lhs_info = getArrayCatInfo(lhs_ty) orelse
6076 return sema.mod.fail(&block.base, lhs_src, "expected array, found '{}'", .{lhs_ty});
6200 return sema.fail(block, lhs_src, "expected array, found '{}'", .{lhs_ty});
60776201 const rhs_info = getArrayCatInfo(rhs_ty) orelse
6078 return sema.mod.fail(&block.base, rhs_src, "expected array, found '{}'", .{rhs_ty});
6202 return sema.fail(block, rhs_src, "expected array, found '{}'", .{rhs_ty});
60796203 if (!lhs_info.elem_type.eql(rhs_info.elem_type)) {
6080 return sema.mod.fail(&block.base, rhs_src, "expected array of type '{}', found '{}'", .{ lhs_info.elem_type, rhs_ty });
6204 return sema.fail(block, rhs_src, "expected array of type '{}', found '{}'", .{ lhs_info.elem_type, rhs_ty });
60816205 }
60826206
60836207 // When there is a sentinel mismatch, no sentinel on the result. The type system
......@@ -6123,10 +6247,10 @@ fn zirArrayCat(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileEr
61236247 else
61246248 sema.analyzeDeclVal(block, .unneeded, try anon_decl.finish(ty, val));
61256249 } else {
6126 return sema.mod.fail(&block.base, lhs_src, "TODO runtime array_cat", .{});
6250 return sema.fail(block, lhs_src, "TODO runtime array_cat", .{});
61276251 }
61286252 } else {
6129 return sema.mod.fail(&block.base, lhs_src, "TODO runtime array_cat", .{});
6253 return sema.fail(block, lhs_src, "TODO runtime array_cat", .{});
61306254 }
61316255}
61326256
......@@ -6157,9 +6281,9 @@ fn zirArrayMul(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileEr
61576281 // In `**` rhs has to be comptime-known, but lhs can be runtime-known
61586282 const tomulby = try sema.resolveInt(block, rhs_src, extra.rhs, Type.initTag(.usize));
61596283 const mulinfo = getArrayCatInfo(lhs_ty) orelse
6160 return sema.mod.fail(&block.base, lhs_src, "expected array, found '{}'", .{lhs_ty});
6284 return sema.fail(block, lhs_src, "expected array, found '{}'", .{lhs_ty});
61616285
6162 const final_len = std.math.mul(u64, mulinfo.len, tomulby) catch return sema.mod.fail(&block.base, rhs_src, "operation results in overflow", .{});
6286 const final_len = std.math.mul(u64, mulinfo.len, tomulby) catch return sema.fail(block, rhs_src, "operation results in overflow", .{});
61636287 if (try sema.resolveDefinedValue(block, lhs_src, lhs)) |lhs_val| {
61646288 var anon_decl = try block.startAnonDecl();
61656289 defer anon_decl.deinit();
......@@ -6192,7 +6316,7 @@ fn zirArrayMul(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileEr
61926316 return sema.analyzeDeclVal(block, .unneeded, try anon_decl.finish(final_ty, val));
61936317 }
61946318 }
6195 return sema.mod.fail(&block.base, lhs_src, "TODO runtime array_mul", .{});
6319 return sema.fail(block, lhs_src, "TODO runtime array_mul", .{});
61966320}
61976321
61986322fn zirNegate(
......@@ -6245,7 +6369,7 @@ fn zirOverflowArithmetic(
62456369 const extra = sema.code.extraData(Zir.Inst.OverflowArithmetic, extended.operand).data;
62466370 const src: LazySrcLoc = .{ .node_offset = extra.node };
62476371
6248 return sema.mod.fail(&block.base, src, "TODO implement Sema.zirOverflowArithmetic", .{});
6372 return sema.fail(block, src, "TODO implement Sema.zirOverflowArithmetic", .{});
62496373}
62506374
62516375fn analyzeArithmetic(
......@@ -6265,13 +6389,13 @@ fn analyzeArithmetic(
62656389 const rhs_zig_ty_tag = try rhs_ty.zigTypeTagOrPoison();
62666390 if (lhs_zig_ty_tag == .Vector and rhs_zig_ty_tag == .Vector) {
62676391 if (lhs_ty.arrayLen() != rhs_ty.arrayLen()) {
6268 return sema.mod.fail(&block.base, src, "vector length mismatch: {d} and {d}", .{
6392 return sema.fail(block, src, "vector length mismatch: {d} and {d}", .{
62696393 lhs_ty.arrayLen(), rhs_ty.arrayLen(),
62706394 });
62716395 }
6272 return sema.mod.fail(&block.base, src, "TODO implement support for vectors in Sema.analyzeArithmetic", .{});
6396 return sema.fail(block, src, "TODO implement support for vectors in Sema.analyzeArithmetic", .{});
62736397 } else if (lhs_zig_ty_tag == .Vector or rhs_zig_ty_tag == .Vector) {
6274 return sema.mod.fail(&block.base, src, "mixed scalar and vector operands to binary expression: '{}' and '{}'", .{
6398 return sema.fail(block, src, "mixed scalar and vector operands to binary expression: '{}' and '{}'", .{
62756399 lhs_ty, rhs_ty,
62766400 });
62776401 }
......@@ -6283,8 +6407,8 @@ fn analyzeArithmetic(
62836407 const air_tag: Air.Inst.Tag = switch (zir_tag) {
62846408 .add => .ptr_add,
62856409 .sub => .ptr_sub,
6286 else => return sema.mod.fail(
6287 &block.base,
6410 else => return sema.fail(
6411 block,
62886412 op_src,
62896413 "invalid pointer arithmetic operand: '{s}''",
62906414 .{@tagName(zir_tag)},
......@@ -6298,7 +6422,7 @@ fn analyzeArithmetic(
62986422 if (try sema.resolveDefinedValue(block, rhs_src, casted_rhs)) |rhs_val| {
62996423 _ = lhs_val;
63006424 _ = rhs_val;
6301 return sema.mod.fail(&block.base, src, "TODO implement Sema for comptime pointer arithmetic", .{});
6425 return sema.fail(block, src, "TODO implement Sema for comptime pointer arithmetic", .{});
63026426 } else {
63036427 break :runtime_src rhs_src;
63046428 }
......@@ -6329,7 +6453,7 @@ fn analyzeArithmetic(
63296453 const is_float = scalar_tag == .Float or scalar_tag == .ComptimeFloat;
63306454
63316455 if (!is_int and !(is_float and floatOpAllowed(zir_tag))) {
6332 return sema.mod.fail(&block.base, src, "invalid operands to binary expression: '{s}' and '{s}'", .{
6456 return sema.fail(block, src, "invalid operands to binary expression: '{s}' and '{s}'", .{
63336457 @tagName(lhs_zig_ty_tag), @tagName(rhs_zig_ty_tag),
63346458 });
63356459 }
......@@ -6939,7 +7063,7 @@ fn zirAsm(
69397063 const clobbers_len = @truncate(u5, extended.small >> 10);
69407064
69417065 if (outputs_len > 1) {
6942 return sema.mod.fail(&block.base, src, "TODO implement Sema for asm with more than 1 output", .{});
7066 return sema.fail(block, src, "TODO implement Sema for asm with more than 1 output", .{});
69437067 }
69447068
69457069 var extra_i = extra.end;
......@@ -6954,7 +7078,7 @@ fn zirAsm(
69547078 output_type_bits >>= 1;
69557079
69567080 if (!is_type) {
6957 return sema.mod.fail(&block.base, src, "TODO implement Sema for asm with non `->` output", .{});
7081 return sema.fail(block, src, "TODO implement Sema for asm with non `->` output", .{});
69587082 }
69597083
69607084 const constraint = sema.code.nullTerminatedString(output.data.constraint);
......@@ -7011,7 +7135,6 @@ fn zirCmpEq(
70117135 const tracy = trace(@src());
70127136 defer tracy.end();
70137137
7014 const mod = sema.mod;
70157138 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
70167139 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
70177140 const src: LazySrcLoc = inst_data.src();
......@@ -7040,11 +7163,11 @@ fn zirCmpEq(
70407163 return sema.analyzeIsNull(block, src, opt_operand, op == .neq);
70417164 }
70427165 if (((lhs_ty_tag == .Null and rhs_ty.isCPtr()) or (rhs_ty_tag == .Null and lhs_ty.isCPtr()))) {
7043 return mod.fail(&block.base, src, "TODO implement C pointer cmp", .{});
7166 return sema.fail(block, src, "TODO implement C pointer cmp", .{});
70447167 }
70457168 if (lhs_ty_tag == .Null or rhs_ty_tag == .Null) {
70467169 const non_null_type = if (lhs_ty_tag == .Null) rhs_ty else lhs_ty;
7047 return mod.fail(&block.base, src, "comparison of '{}' with null", .{non_null_type});
7170 return sema.fail(block, src, "comparison of '{}' with null", .{non_null_type});
70487171 }
70497172 if (lhs_ty_tag == .EnumLiteral and rhs_ty_tag == .Union) {
70507173 return sema.analyzeCmpUnionTag(block, rhs, rhs_src, lhs, lhs_src, op);
......@@ -7103,7 +7226,7 @@ fn analyzeCmpUnionTag(
71037226 const union_ty = sema.typeOf(un);
71047227 const union_tag_ty = union_ty.unionTagType() orelse {
71057228 // TODO note at declaration site that says "union foo is not tagged"
7106 return sema.mod.fail(&block.base, un_src, "comparison of union and enum literal is only valid for tagged union types", .{});
7229 return sema.fail(block, un_src, "comparison of union and enum literal is only valid for tagged union types", .{});
71077230 };
71087231 // Coerce both the union and the tag to the union's tag type, and then execute the
71097232 // enum comparison codepath.
......@@ -7155,7 +7278,7 @@ fn analyzeCmp(
71557278 const instructions = &[_]Air.Inst.Ref{ lhs, rhs };
71567279 const resolved_type = try sema.resolvePeerTypes(block, src, instructions, .{ .override = &[_]LazySrcLoc{ lhs_src, rhs_src } });
71577280 if (!resolved_type.isSelfComparable(is_equality_cmp)) {
7158 return sema.mod.fail(&block.base, src, "{s} operator not allowed for type '{}'", .{
7281 return sema.fail(block, src, "{s} operator not allowed for type '{}'", .{
71597282 @tagName(op), resolved_type,
71607283 });
71617284 }
......@@ -7252,7 +7375,7 @@ fn zirSizeOf(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErro
72527375 .Null,
72537376 .BoundFn,
72547377 .Opaque,
7255 => return sema.mod.fail(&block.base, src, "no size available for type '{}'", .{operand_ty}),
7378 => return sema.fail(block, src, "no size available for type '{}'", .{operand_ty}),
72567379 .Type,
72577380 .EnumLiteral,
72587381 .ComptimeFloat,
......@@ -7340,7 +7463,7 @@ fn zirRetAddr(
73407463 extended: Zir.Inst.Extended.InstData,
73417464) CompileError!Air.Inst.Ref {
73427465 const src: LazySrcLoc = .{ .node_offset = @bitCast(i32, extended.operand) };
7343 return sema.mod.fail(&block.base, src, "TODO: implement Sema.zirRetAddr", .{});
7466 return sema.fail(block, src, "TODO: implement Sema.zirRetAddr", .{});
73447467}
73457468
73467469fn zirBuiltinSrc(
......@@ -7349,7 +7472,7 @@ fn zirBuiltinSrc(
73497472 extended: Zir.Inst.Extended.InstData,
73507473) CompileError!Air.Inst.Ref {
73517474 const src: LazySrcLoc = .{ .node_offset = @bitCast(i32, extended.operand) };
7352 return sema.mod.fail(&block.base, src, "TODO: implement Sema.zirBuiltinSrc", .{});
7475 return sema.fail(block, src, "TODO: implement Sema.zirBuiltinSrc", .{});
73537476}
73547477
73557478fn zirTypeInfo(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
......@@ -7551,7 +7674,7 @@ fn zirTypeInfo(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileEr
75517674 }),
75527675 );
75537676 },
7554 else => |t| return sema.mod.fail(&block.base, src, "TODO: implement zirTypeInfo for {s}", .{
7677 else => |t| return sema.fail(block, src, "TODO: implement zirTypeInfo for {s}", .{
75557678 @tagName(t),
75567679 }),
75577680 }
......@@ -7601,8 +7724,8 @@ fn log2IntType(sema: *Sema, block: *Scope.Block, operand: Type, src: LazySrcLoc)
76017724 const res = try Module.makeIntType(sema.arena, .unsigned, count);
76027725 return sema.addType(res);
76037726 },
7604 else => return sema.mod.fail(
7605 &block.base,
7727 else => return sema.fail(
7728 block,
76067729 src,
76077730 "bit shifting operation expected integer type, found '{}'",
76087731 .{operand},
......@@ -8026,7 +8149,7 @@ fn zirPtrType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErr
80268149 } else 0;
80278150
80288151 if (bit_end != 0 and bit_start >= bit_end * 8)
8029 return sema.mod.fail(&block.base, src, "bit offset starts after end of host integer", .{});
8152 return sema.fail(block, src, "bit offset starts after end of host integer", .{});
80308153
80318154 const elem_type = try sema.resolveType(block, .unneeded, extra.data.elem_type);
80328155
......@@ -8059,11 +8182,10 @@ fn zirStructInitEmpty(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Co
80598182fn zirUnionInitPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
80608183 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
80618184 const src = inst_data.src();
8062 return sema.mod.fail(&block.base, src, "TODO: Sema.zirUnionInitPtr", .{});
8185 return sema.fail(block, src, "TODO: Sema.zirUnionInitPtr", .{});
80638186}
80648187
80658188fn zirStructInit(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index, is_ref: bool) CompileError!Air.Inst.Ref {
8066 const mod = sema.mod;
80678189 const gpa = sema.gpa;
80688190 const zir_datas = sema.code.instructions.items(.data);
80698191 const inst_data = zir_datas[inst].pl_node;
......@@ -8107,12 +8229,12 @@ fn zirStructInit(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index, is_ref:
81078229 const other_field_type_data = zir_datas[other_field_type].pl_node;
81088230 const other_field_src: LazySrcLoc = .{ .node_offset_back2tok = other_field_type_data.src_node };
81098231 const msg = msg: {
8110 const msg = try mod.errMsg(&block.base, field_src, "duplicate field", .{});
8232 const msg = try sema.errMsg(block, field_src, "duplicate field", .{});
81118233 errdefer msg.destroy(gpa);
8112 try mod.errNote(&block.base, other_field_src, msg, "other field here", .{});
8234 try sema.errNote(block, other_field_src, msg, "other field here", .{});
81138235 break :msg msg;
81148236 };
8115 return mod.failWithOwnedErrorMsg(&block.base, msg);
8237 return sema.failWithOwnedErrorMsg(msg);
81168238 }
81178239 found_fields[field_index] = item.data.field_type;
81188240 field_inits[field_index] = sema.resolveInst(item.data.init);
......@@ -8130,9 +8252,9 @@ fn zirStructInit(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index, is_ref:
81308252 const template = "missing struct field: {s}";
81318253 const args = .{field_name};
81328254 if (root_msg) |msg| {
8133 try mod.errNote(&block.base, src, msg, template, args);
8255 try sema.errNote(block, src, msg, template, args);
81348256 } else {
8135 root_msg = try mod.errMsg(&block.base, src, template, args);
8257 root_msg = try sema.errMsg(block, src, template, args);
81368258 }
81378259 } else {
81388260 field_inits[i] = try sema.addConstant(field.ty, field.default_val);
......@@ -8141,17 +8263,17 @@ fn zirStructInit(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index, is_ref:
81418263 if (root_msg) |msg| {
81428264 const fqn = try struct_obj.getFullyQualifiedName(gpa);
81438265 defer gpa.free(fqn);
8144 try mod.errNoteNonLazy(
8266 try sema.mod.errNoteNonLazy(
81458267 struct_obj.srcLoc(),
81468268 msg,
81478269 "struct '{s}' declared here",
81488270 .{fqn},
81498271 );
8150 return mod.failWithOwnedErrorMsg(&block.base, msg);
8272 return sema.failWithOwnedErrorMsg(msg);
81518273 }
81528274
81538275 if (is_ref) {
8154 return mod.fail(&block.base, src, "TODO: Sema.zirStructInit is_ref=true", .{});
8276 return sema.fail(block, src, "TODO: Sema.zirStructInit is_ref=true", .{});
81558277 }
81568278
81578279 const is_comptime = for (field_inits) |field_init| {
......@@ -8168,12 +8290,12 @@ fn zirStructInit(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index, is_ref:
81688290 return sema.addConstant(resolved_ty, try Value.Tag.@"struct".create(sema.arena, values));
81698291 }
81708292
8171 return mod.fail(&block.base, src, "TODO: Sema.zirStructInit for runtime-known struct values", .{});
8293 return sema.fail(block, src, "TODO: Sema.zirStructInit for runtime-known struct values", .{});
81728294 } else if (resolved_ty.cast(Type.Payload.Union)) |union_payload| {
81738295 const union_obj = union_payload.data;
81748296
81758297 if (extra.data.fields_len != 1) {
8176 return sema.mod.fail(&block.base, src, "union initialization expects exactly one field", .{});
8298 return sema.fail(block, src, "union initialization expects exactly one field", .{});
81778299 }
81788300
81798301 const item = sema.code.extraData(Zir.Inst.StructInit.Item, extra.end);
......@@ -8186,7 +8308,7 @@ fn zirStructInit(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index, is_ref:
81868308 return sema.failWithBadUnionFieldAccess(block, union_obj, field_src, field_name);
81878309
81888310 if (is_ref) {
8189 return mod.fail(&block.base, src, "TODO: Sema.zirStructInit is_ref=true union", .{});
8311 return sema.fail(block, src, "TODO: Sema.zirStructInit is_ref=true union", .{});
81908312 }
81918313
81928314 const init_inst = sema.resolveInst(item.data.init);
......@@ -8199,7 +8321,7 @@ fn zirStructInit(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index, is_ref:
81998321 }),
82008322 );
82018323 }
8202 return mod.fail(&block.base, src, "TODO: Sema.zirStructInit for runtime-known union values", .{});
8324 return sema.fail(block, src, "TODO: Sema.zirStructInit for runtime-known union values", .{});
82038325 }
82048326 unreachable;
82058327}
......@@ -8209,7 +8331,7 @@ fn zirStructInitAnon(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index, is_
82098331 const src = inst_data.src();
82108332
82118333 _ = is_ref;
8212 return sema.mod.fail(&block.base, src, "TODO: Sema.zirStructInitAnon", .{});
8334 return sema.fail(block, src, "TODO: Sema.zirStructInitAnon", .{});
82138335}
82148336
82158337fn zirArrayInit(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index, is_ref: bool) CompileError!Air.Inst.Ref {
......@@ -8269,13 +8391,13 @@ fn zirArrayInitAnon(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index, is_r
82698391 const src = inst_data.src();
82708392
82718393 _ = is_ref;
8272 return sema.mod.fail(&block.base, src, "TODO: Sema.zirArrayInitAnon", .{});
8394 return sema.fail(block, src, "TODO: Sema.zirArrayInitAnon", .{});
82738395}
82748396
82758397fn zirFieldTypeRef(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
82768398 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
82778399 const src = inst_data.src();
8278 return sema.mod.fail(&block.base, src, "TODO: Sema.zirFieldTypeRef", .{});
8400 return sema.fail(block, src, "TODO: Sema.zirFieldTypeRef", .{});
82798401}
82808402
82818403fn zirFieldType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
......@@ -8298,7 +8420,7 @@ fn zirFieldType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileE
82988420 return sema.failWithBadUnionFieldAccess(block, union_obj, src, field_name);
82998421 return sema.addType(field.ty);
83008422 },
8301 else => return sema.mod.fail(&block.base, src, "expected struct or union; found '{}'", .{
8423 else => return sema.fail(block, src, "expected struct or union; found '{}'", .{
83028424 resolved_ty,
83038425 }),
83048426 }
......@@ -8310,7 +8432,7 @@ fn zirErrorReturnTrace(
83108432 extended: Zir.Inst.Extended.InstData,
83118433) CompileError!Air.Inst.Ref {
83128434 const src: LazySrcLoc = .{ .node_offset = @bitCast(i32, extended.operand) };
8313 return sema.mod.fail(&block.base, src, "TODO: Sema.zirErrorReturnTrace", .{});
8435 return sema.fail(block, src, "TODO: Sema.zirErrorReturnTrace", .{});
83148436}
83158437
83168438fn zirFrame(
......@@ -8319,7 +8441,7 @@ fn zirFrame(
83198441 extended: Zir.Inst.Extended.InstData,
83208442) CompileError!Air.Inst.Ref {
83218443 const src: LazySrcLoc = .{ .node_offset = @bitCast(i32, extended.operand) };
8322 return sema.mod.fail(&block.base, src, "TODO: Sema.zirFrame", .{});
8444 return sema.fail(block, src, "TODO: Sema.zirFrame", .{});
83238445}
83248446
83258447fn zirFrameAddress(
......@@ -8328,7 +8450,7 @@ fn zirFrameAddress(
83288450 extended: Zir.Inst.Extended.InstData,
83298451) CompileError!Air.Inst.Ref {
83308452 const src: LazySrcLoc = .{ .node_offset = @bitCast(i32, extended.operand) };
8331 return sema.mod.fail(&block.base, src, "TODO: Sema.zirFrameAddress", .{});
8453 return sema.fail(block, src, "TODO: Sema.zirFrameAddress", .{});
83328454}
83338455
83348456fn zirAlignOf(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
......@@ -8355,25 +8477,25 @@ fn zirBoolToInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileE
83558477fn zirEmbedFile(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
83568478 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
83578479 const src = inst_data.src();
8358 return sema.mod.fail(&block.base, src, "TODO: Sema.zirEmbedFile", .{});
8480 return sema.fail(block, src, "TODO: Sema.zirEmbedFile", .{});
83598481}
83608482
83618483fn zirErrorName(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
83628484 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
83638485 const src = inst_data.src();
8364 return sema.mod.fail(&block.base, src, "TODO: Sema.zirErrorName", .{});
8486 return sema.fail(block, src, "TODO: Sema.zirErrorName", .{});
83658487}
83668488
83678489fn zirUnaryMath(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
83688490 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
83698491 const src = inst_data.src();
8370 return sema.mod.fail(&block.base, src, "TODO: Sema.zirUnaryMath", .{});
8492 return sema.fail(block, src, "TODO: Sema.zirUnaryMath", .{});
83718493}
83728494
83738495fn zirTagName(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
83748496 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
83758497 const src = inst_data.src();
8376 return sema.mod.fail(&block.base, src, "TODO: Sema.zirTagName", .{});
8498 return sema.fail(block, src, "TODO: Sema.zirTagName", .{});
83778499}
83788500
83798501fn zirReify(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
......@@ -8406,25 +8528,25 @@ fn zirReify(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError
84068528 };
84078529 return sema.addType(ty);
84088530 },
8409 .Float => return sema.mod.fail(&block.base, src, "TODO: Sema.zirReify for Float", .{}),
8410 .Pointer => return sema.mod.fail(&block.base, src, "TODO: Sema.zirReify for Pointer", .{}),
8411 .Array => return sema.mod.fail(&block.base, src, "TODO: Sema.zirReify for Array", .{}),
8412 .Struct => return sema.mod.fail(&block.base, src, "TODO: Sema.zirReify for Struct", .{}),
8531 .Float => return sema.fail(block, src, "TODO: Sema.zirReify for Float", .{}),
8532 .Pointer => return sema.fail(block, src, "TODO: Sema.zirReify for Pointer", .{}),
8533 .Array => return sema.fail(block, src, "TODO: Sema.zirReify for Array", .{}),
8534 .Struct => return sema.fail(block, src, "TODO: Sema.zirReify for Struct", .{}),
84138535 .ComptimeFloat => return Air.Inst.Ref.comptime_float_type,
84148536 .ComptimeInt => return Air.Inst.Ref.comptime_int_type,
84158537 .Undefined => return Air.Inst.Ref.undefined_type,
84168538 .Null => return Air.Inst.Ref.null_type,
8417 .Optional => return sema.mod.fail(&block.base, src, "TODO: Sema.zirReify for Optional", .{}),
8418 .ErrorUnion => return sema.mod.fail(&block.base, src, "TODO: Sema.zirReify for ErrorUnion", .{}),
8419 .ErrorSet => return sema.mod.fail(&block.base, src, "TODO: Sema.zirReify for ErrorSet", .{}),
8420 .Enum => return sema.mod.fail(&block.base, src, "TODO: Sema.zirReify for Enum", .{}),
8421 .Union => return sema.mod.fail(&block.base, src, "TODO: Sema.zirReify for Union", .{}),
8422 .Fn => return sema.mod.fail(&block.base, src, "TODO: Sema.zirReify for Fn", .{}),
8539 .Optional => return sema.fail(block, src, "TODO: Sema.zirReify for Optional", .{}),
8540 .ErrorUnion => return sema.fail(block, src, "TODO: Sema.zirReify for ErrorUnion", .{}),
8541 .ErrorSet => return sema.fail(block, src, "TODO: Sema.zirReify for ErrorSet", .{}),
8542 .Enum => return sema.fail(block, src, "TODO: Sema.zirReify for Enum", .{}),
8543 .Union => return sema.fail(block, src, "TODO: Sema.zirReify for Union", .{}),
8544 .Fn => return sema.fail(block, src, "TODO: Sema.zirReify for Fn", .{}),
84238545 .BoundFn => @panic("TODO delete BoundFn from the language"),
8424 .Opaque => return sema.mod.fail(&block.base, src, "TODO: Sema.zirReify for Opaque", .{}),
8425 .Frame => return sema.mod.fail(&block.base, src, "TODO: Sema.zirReify for Frame", .{}),
8546 .Opaque => return sema.fail(block, src, "TODO: Sema.zirReify for Opaque", .{}),
8547 .Frame => return sema.fail(block, src, "TODO: Sema.zirReify for Frame", .{}),
84268548 .AnyFrame => return Air.Inst.Ref.anyframe_type,
8427 .Vector => return sema.mod.fail(&block.base, src, "TODO: Sema.zirReify for Vector", .{}),
8549 .Vector => return sema.fail(block, src, "TODO: Sema.zirReify for Vector", .{}),
84288550 .EnumLiteral => return Air.Inst.Ref.enum_literal_type,
84298551 }
84308552}
......@@ -8432,26 +8554,26 @@ fn zirReify(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError
84328554fn zirTypeName(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
84338555 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
84348556 const src = inst_data.src();
8435 return sema.mod.fail(&block.base, src, "TODO: Sema.zirTypeName", .{});
8557 return sema.fail(block, src, "TODO: Sema.zirTypeName", .{});
84368558}
84378559
84388560fn zirFrameType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
84398561 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
84408562 const src = inst_data.src();
8441 return sema.mod.fail(&block.base, src, "TODO: Sema.zirFrameType", .{});
8563 return sema.fail(block, src, "TODO: Sema.zirFrameType", .{});
84428564}
84438565
84448566fn zirFrameSize(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
84458567 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
84468568 const src = inst_data.src();
8447 return sema.mod.fail(&block.base, src, "TODO: Sema.zirFrameSize", .{});
8569 return sema.fail(block, src, "TODO: Sema.zirFrameSize", .{});
84488570}
84498571
84508572fn zirFloatToInt(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
84518573 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
84528574 const src = inst_data.src();
84538575 // TODO don't forget the safety check!
8454 return sema.mod.fail(&block.base, src, "TODO: Sema.zirFloatToInt", .{});
8576 return sema.fail(block, src, "TODO: Sema.zirFloatToInt", .{});
84558577}
84568578
84578579fn zirIntToFloat(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
......@@ -8489,15 +8611,15 @@ fn zirIntToPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileEr
84898611 const type_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
84908612 const type_res = try sema.resolveType(block, src, extra.lhs);
84918613 if (type_res.zigTypeTag() != .Pointer)
8492 return sema.mod.fail(&block.base, type_src, "expected pointer, found '{}'", .{type_res});
8614 return sema.fail(block, type_src, "expected pointer, found '{}'", .{type_res});
84938615 const ptr_align = type_res.ptrAlignment(sema.mod.getTarget());
84948616
84958617 if (try sema.resolveDefinedValue(block, operand_src, operand_coerced)) |val| {
84968618 const addr = val.toUnsignedInt();
84978619 if (!type_res.isAllowzeroPtr() and addr == 0)
8498 return sema.mod.fail(&block.base, operand_src, "pointer type '{}' does not allow address zero", .{type_res});
8620 return sema.fail(block, operand_src, "pointer type '{}' does not allow address zero", .{type_res});
84998621 if (addr != 0 and addr % ptr_align != 0)
8500 return sema.mod.fail(&block.base, operand_src, "pointer type '{}' requires aligned address", .{type_res});
8622 return sema.fail(block, operand_src, "pointer type '{}' requires aligned address", .{type_res});
85018623
85028624 const val_payload = try sema.arena.create(Value.Payload.U64);
85038625 val_payload.* = .{
......@@ -8535,7 +8657,7 @@ fn zirIntToPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileEr
85358657fn zirErrSetCast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
85368658 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
85378659 const src = inst_data.src();
8538 return sema.mod.fail(&block.base, src, "TODO: Sema.zirErrSetCast", .{});
8660 return sema.fail(block, src, "TODO: Sema.zirErrSetCast", .{});
85398661}
85408662
85418663fn zirPtrCast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
......@@ -8547,12 +8669,12 @@ fn zirPtrCast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErr
85478669 const operand = sema.resolveInst(extra.rhs);
85488670 const operand_ty = sema.typeOf(operand);
85498671 if (operand_ty.zigTypeTag() != .Pointer) {
8550 return sema.mod.fail(&block.base, operand_src, "expected pointer, found {s} type '{}'", .{
8672 return sema.fail(block, operand_src, "expected pointer, found {s} type '{}'", .{
85518673 @tagName(operand_ty.zigTypeTag()), operand_ty,
85528674 });
85538675 }
85548676 if (dest_ty.zigTypeTag() != .Pointer) {
8555 return sema.mod.fail(&block.base, dest_ty_src, "expected pointer, found {s} type '{}'", .{
8677 return sema.fail(block, dest_ty_src, "expected pointer, found {s} type '{}'", .{
85568678 @tagName(dest_ty.zigTypeTag()), dest_ty,
85578679 });
85588680 }
......@@ -8571,7 +8693,6 @@ fn zirTruncate(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileEr
85718693 const dest_ty = try sema.resolveType(block, dest_ty_src, extra.lhs);
85728694 const operand = sema.resolveInst(extra.rhs);
85738695 const operand_ty = sema.typeOf(operand);
8574 const mod = sema.mod;
85758696 const dest_is_comptime_int = try sema.checkIntType(block, dest_ty_src, dest_ty);
85768697 const src_is_comptime_int = try sema.checkIntType(block, operand_src, operand_ty);
85778698
......@@ -8579,7 +8700,7 @@ fn zirTruncate(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileEr
85798700 return sema.coerce(block, dest_ty, operand, operand_src);
85808701 }
85818702
8582 const target = mod.getTarget();
8703 const target = sema.mod.getTarget();
85838704 const src_info = operand_ty.intInfo(target);
85848705 const dest_info = dest_ty.intInfo(target);
85858706
......@@ -8589,28 +8710,28 @@ fn zirTruncate(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileEr
85898710
85908711 if (!src_is_comptime_int) {
85918712 if (src_info.signedness != dest_info.signedness) {
8592 return mod.fail(&block.base, operand_src, "expected {s} integer type, found '{}'", .{
8713 return sema.fail(block, operand_src, "expected {s} integer type, found '{}'", .{
85938714 @tagName(dest_info.signedness), operand_ty,
85948715 });
85958716 }
85968717 if (src_info.bits > 0 and src_info.bits < dest_info.bits) {
85978718 const msg = msg: {
8598 const msg = try mod.errMsg(
8599 &block.base,
8719 const msg = try sema.errMsg(
8720 block,
86008721 src,
86018722 "destination type '{}' has more bits than source type '{}'",
86028723 .{ dest_ty, operand_ty },
86038724 );
8604 errdefer msg.destroy(mod.gpa);
8605 try mod.errNote(&block.base, dest_ty_src, msg, "destination type has {d} bits", .{
8725 errdefer msg.destroy(sema.gpa);
8726 try sema.errNote(block, dest_ty_src, msg, "destination type has {d} bits", .{
86068727 dest_info.bits,
86078728 });
8608 try mod.errNote(&block.base, operand_src, msg, "source type has {d} bits", .{
8729 try sema.errNote(block, operand_src, msg, "source type has {d} bits", .{
86098730 src_info.bits,
86108731 });
86118732 break :msg msg;
86128733 };
8613 return mod.failWithOwnedErrorMsg(&block.base, msg);
8734 return sema.failWithOwnedErrorMsg(msg);
86148735 }
86158736 }
86168737
......@@ -8626,7 +8747,7 @@ fn zirTruncate(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileEr
86268747fn zirAlignCast(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
86278748 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
86288749 const src = inst_data.src();
8629 return sema.mod.fail(&block.base, src, "TODO: Sema.zirAlignCast", .{});
8750 return sema.fail(block, src, "TODO: Sema.zirAlignCast", .{});
86308751}
86318752
86328753fn zirClz(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
......@@ -8637,7 +8758,7 @@ fn zirClz(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!A
86378758 const operand_ty = sema.typeOf(operand);
86388759 // TODO implement support for vectors
86398760 if (operand_ty.zigTypeTag() != .Int) {
8640 return sema.mod.fail(&block.base, ty_src, "expected integer type, found '{}'", .{
8761 return sema.fail(block, ty_src, "expected integer type, found '{}'", .{
86418762 operand_ty,
86428763 });
86438764 }
......@@ -8664,7 +8785,7 @@ fn zirCtz(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!A
86648785 const operand_ty = sema.typeOf(operand);
86658786 // TODO implement support for vectors
86668787 if (operand_ty.zigTypeTag() != .Int) {
8667 return sema.mod.fail(&block.base, ty_src, "expected integer type, found '{}'", .{
8788 return sema.fail(block, ty_src, "expected integer type, found '{}'", .{
86688789 operand_ty,
86698790 });
86708791 }
......@@ -8676,7 +8797,7 @@ fn zirCtz(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!A
86768797
86778798 const runtime_src = if (try sema.resolveMaybeUndefVal(block, operand_src, operand)) |val| {
86788799 if (val.isUndef()) return sema.addConstUndef(result_ty);
8679 return sema.mod.fail(&block.base, operand_src, "TODO: implement comptime @ctz", .{});
8800 return sema.fail(block, operand_src, "TODO: implement comptime @ctz", .{});
86808801 } else operand_src;
86818802
86828803 try sema.requireRuntimeBlock(block, runtime_src);
......@@ -8686,55 +8807,55 @@ fn zirCtz(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!A
86868807fn zirPopCount(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
86878808 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
86888809 const src = inst_data.src();
8689 return sema.mod.fail(&block.base, src, "TODO: Sema.zirPopCount", .{});
8810 return sema.fail(block, src, "TODO: Sema.zirPopCount", .{});
86908811}
86918812
86928813fn zirByteSwap(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
86938814 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
86948815 const src = inst_data.src();
8695 return sema.mod.fail(&block.base, src, "TODO: Sema.zirByteSwap", .{});
8816 return sema.fail(block, src, "TODO: Sema.zirByteSwap", .{});
86968817}
86978818
86988819fn zirBitReverse(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
86998820 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
87008821 const src = inst_data.src();
8701 return sema.mod.fail(&block.base, src, "TODO: Sema.zirBitReverse", .{});
8822 return sema.fail(block, src, "TODO: Sema.zirBitReverse", .{});
87028823}
87038824
87048825fn zirDivExact(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
87058826 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
87068827 const src = inst_data.src();
8707 return sema.mod.fail(&block.base, src, "TODO: Sema.zirDivExact", .{});
8828 return sema.fail(block, src, "TODO: Sema.zirDivExact", .{});
87088829}
87098830
87108831fn zirDivFloor(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
87118832 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
87128833 const src = inst_data.src();
8713 return sema.mod.fail(&block.base, src, "TODO: Sema.zirDivFloor", .{});
8834 return sema.fail(block, src, "TODO: Sema.zirDivFloor", .{});
87148835}
87158836
87168837fn zirDivTrunc(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
87178838 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
87188839 const src = inst_data.src();
8719 return sema.mod.fail(&block.base, src, "TODO: Sema.zirDivTrunc", .{});
8840 return sema.fail(block, src, "TODO: Sema.zirDivTrunc", .{});
87208841}
87218842
87228843fn zirShrExact(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
87238844 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
87248845 const src = inst_data.src();
8725 return sema.mod.fail(&block.base, src, "TODO: Sema.zirShrExact", .{});
8846 return sema.fail(block, src, "TODO: Sema.zirShrExact", .{});
87268847}
87278848
87288849fn zirBitOffsetOf(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
87298850 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
87308851 const src = inst_data.src();
8731 return sema.mod.fail(&block.base, src, "TODO: Sema.zirBitOffsetOf", .{});
8852 return sema.fail(block, src, "TODO: Sema.zirBitOffsetOf", .{});
87328853}
87338854
87348855fn zirOffsetOf(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
87358856 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
87368857 const src = inst_data.src();
8737 return sema.mod.fail(&block.base, src, "TODO: Sema.zirOffsetOf", .{});
8858 return sema.fail(block, src, "TODO: Sema.zirOffsetOf", .{});
87388859}
87398860
87408861/// Returns `true` if the type was a comptime_int.
......@@ -8742,7 +8863,7 @@ fn checkIntType(sema: *Sema, block: *Scope.Block, src: LazySrcLoc, ty: Type) Com
87428863 switch (ty.zigTypeTag()) {
87438864 .ComptimeInt => return true,
87448865 .Int => return false,
8745 else => return sema.mod.fail(&block.base, src, "expected integer type, found '{}'", .{ty}),
8866 else => return sema.fail(block, src, "expected integer type, found '{}'", .{ty}),
87468867 }
87478868}
87488869
......@@ -8754,7 +8875,7 @@ fn checkFloatType(
87548875) CompileError!void {
87558876 switch (ty.zigTypeTag()) {
87568877 .ComptimeFloat, .Float => {},
8757 else => return sema.mod.fail(&block.base, ty_src, "expected float type, found '{}'", .{
8878 else => return sema.fail(block, ty_src, "expected float type, found '{}'", .{
87588879 ty,
87598880 }),
87608881 }
......@@ -8775,8 +8896,8 @@ fn checkAtomicOperandType(
87758896 .Float => {
87768897 const bit_count = ty.floatBits(target);
87778898 if (bit_count > max_atomic_bits) {
8778 return sema.mod.fail(
8779 &block.base,
8899 return sema.fail(
8900 block,
87808901 ty_src,
87818902 "expected {d}-bit float type or smaller; found {d}-bit float type",
87828903 .{ max_atomic_bits, bit_count },
......@@ -8788,8 +8909,8 @@ fn checkAtomicOperandType(
87888909 else => {
87898910 if (ty.isPtrAtRuntime()) return;
87908911
8791 return sema.mod.fail(
8792 &block.base,
8912 return sema.fail(
8913 block,
87938914 ty_src,
87948915 "expected bool, integer, float, enum, or pointer type; found {}",
87958916 .{ty},
......@@ -8798,8 +8919,8 @@ fn checkAtomicOperandType(
87988919 };
87998920 const bit_count = int_ty.intInfo(target).bits;
88008921 if (bit_count > max_atomic_bits) {
8801 return sema.mod.fail(
8802 &block.base,
8922 return sema.fail(
8923 block,
88038924 ty_src,
88048925 "expected {d}-bit integer type or smaller; found {d}-bit integer type",
88058926 .{ max_atomic_bits, bit_count },
......@@ -8823,7 +8944,7 @@ fn resolveExportOptions(
88238944 const linkage_index = struct_obj.fields.getIndex("linkage").?;
88248945 const section_index = struct_obj.fields.getIndex("section").?;
88258946 if (!fields[section_index].isNull()) {
8826 return sema.mod.fail(&block.base, src, "TODO: implement exporting with linksection", .{});
8947 return sema.fail(block, src, "TODO: implement exporting with linksection", .{});
88278948 }
88288949 return std.builtin.ExportOptions{
88298950 .name = try fields[name_index].toAllocatedBytes(sema.arena),
......@@ -8864,7 +8985,6 @@ fn zirCmpxchg(
88648985 inst: Zir.Inst.Index,
88658986 air_tag: Air.Inst.Tag,
88668987) CompileError!Air.Inst.Ref {
8867 const mod = sema.mod;
88688988 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
88698989 const extra = sema.code.extraData(Zir.Inst.Cmpxchg, inst_data.payload_index).data;
88708990 const src = inst_data.src();
......@@ -8880,8 +9000,8 @@ fn zirCmpxchg(
88809000 const elem_ty = sema.typeOf(ptr).elemType();
88819001 try sema.checkAtomicOperandType(block, elem_ty_src, elem_ty);
88829002 if (elem_ty.zigTypeTag() == .Float) {
8883 return mod.fail(
8884 &block.base,
9003 return sema.fail(
9004 block,
88859005 elem_ty_src,
88869006 "expected bool, integer, enum, or pointer type; found '{}'",
88879007 .{elem_ty},
......@@ -8893,16 +9013,16 @@ fn zirCmpxchg(
88939013 const failure_order = try sema.resolveAtomicOrder(block, failure_order_src, extra.failure_order);
88949014
88959015 if (@enumToInt(success_order) < @enumToInt(std.builtin.AtomicOrder.Monotonic)) {
8896 return mod.fail(&block.base, success_order_src, "success atomic ordering must be Monotonic or stricter", .{});
9016 return sema.fail(block, success_order_src, "success atomic ordering must be Monotonic or stricter", .{});
88979017 }
88989018 if (@enumToInt(failure_order) < @enumToInt(std.builtin.AtomicOrder.Monotonic)) {
8899 return mod.fail(&block.base, failure_order_src, "failure atomic ordering must be Monotonic or stricter", .{});
9019 return sema.fail(block, failure_order_src, "failure atomic ordering must be Monotonic or stricter", .{});
89009020 }
89019021 if (@enumToInt(failure_order) > @enumToInt(success_order)) {
8902 return mod.fail(&block.base, failure_order_src, "failure atomic ordering must be no stricter than success", .{});
9022 return sema.fail(block, failure_order_src, "failure atomic ordering must be no stricter than success", .{});
89039023 }
89049024 if (failure_order == .Release or failure_order == .AcqRel) {
8905 return mod.fail(&block.base, failure_order_src, "failure atomic ordering must not be Release or AcqRel", .{});
9025 return sema.fail(block, failure_order_src, "failure atomic ordering must not be Release or AcqRel", .{});
89069026 }
89079027
89089028 const result_ty = try Module.optionalType(sema.arena, elem_ty);
......@@ -8952,25 +9072,25 @@ fn zirCmpxchg(
89529072fn zirSplat(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
89539073 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
89549074 const src = inst_data.src();
8955 return sema.mod.fail(&block.base, src, "TODO: Sema.zirSplat", .{});
9075 return sema.fail(block, src, "TODO: Sema.zirSplat", .{});
89569076}
89579077
89589078fn zirReduce(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
89599079 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
89609080 const src = inst_data.src();
8961 return sema.mod.fail(&block.base, src, "TODO: Sema.zirReduce", .{});
9081 return sema.fail(block, src, "TODO: Sema.zirReduce", .{});
89629082}
89639083
89649084fn zirShuffle(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
89659085 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
89669086 const src = inst_data.src();
8967 return sema.mod.fail(&block.base, src, "TODO: Sema.zirShuffle", .{});
9087 return sema.fail(block, src, "TODO: Sema.zirShuffle", .{});
89689088}
89699089
89709090fn zirSelect(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
89719091 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
89729092 const src = inst_data.src();
8973 return sema.mod.fail(&block.base, src, "TODO: Sema.zirSelect", .{});
9093 return sema.fail(block, src, "TODO: Sema.zirSelect", .{});
89749094}
89759095
89769096fn zirAtomicLoad(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
......@@ -8988,8 +9108,8 @@ fn zirAtomicLoad(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Compile
89889108
89899109 switch (order) {
89909110 .Release, .AcqRel => {
8991 return sema.mod.fail(
8992 &block.base,
9111 return sema.fail(
9112 block,
89939113 order_src,
89949114 "@atomicLoad atomic ordering must not be Release or AcqRel",
89959115 .{},
......@@ -9019,7 +9139,6 @@ fn zirAtomicLoad(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Compile
90199139}
90209140
90219141fn zirAtomicRmw(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
9022 const mod = sema.mod;
90239142 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
90249143 const extra = sema.code.extraData(Zir.Inst.AtomicRmw, inst_data.payload_index).data;
90259144 const src = inst_data.src();
......@@ -9037,14 +9156,14 @@ fn zirAtomicRmw(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileE
90379156
90389157 switch (operand_ty.zigTypeTag()) {
90399158 .Enum => if (op != .Xchg) {
9040 return mod.fail(&block.base, op_src, "@atomicRmw with enum only allowed with .Xchg", .{});
9159 return sema.fail(block, op_src, "@atomicRmw with enum only allowed with .Xchg", .{});
90419160 },
90429161 .Bool => if (op != .Xchg) {
9043 return mod.fail(&block.base, op_src, "@atomicRmw with bool only allowed with .Xchg", .{});
9162 return sema.fail(block, op_src, "@atomicRmw with bool only allowed with .Xchg", .{});
90449163 },
90459164 .Float => switch (op) {
90469165 .Xchg, .Add, .Sub => {},
9047 else => return mod.fail(&block.base, op_src, "@atomicRmw with float only allowed with .Xchg, .Add, and .Sub", .{}),
9166 else => return sema.fail(block, op_src, "@atomicRmw with float only allowed with .Xchg, .Add, and .Sub", .{}),
90489167 },
90499168 else => {},
90509169 }
......@@ -9052,7 +9171,7 @@ fn zirAtomicRmw(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileE
90529171 const order = try sema.resolveAtomicOrder(block, order_src, extra.ordering);
90539172
90549173 if (order == .Unordered) {
9055 return mod.fail(&block.base, order_src, "@atomicRmw atomic ordering must not be Unordered", .{});
9174 return sema.fail(block, order_src, "@atomicRmw atomic ordering must not be Unordered", .{});
90569175 }
90579176
90589177 // special case zero bit types
......@@ -9115,8 +9234,8 @@ fn zirAtomicStore(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Compil
91159234
91169235 const air_tag: Air.Inst.Tag = switch (order) {
91179236 .Acquire, .AcqRel => {
9118 return sema.mod.fail(
9119 &block.base,
9237 return sema.fail(
9238 block,
91209239 order_src,
91219240 "@atomicStore atomic ordering must not be Acquire or AcqRel",
91229241 .{},
......@@ -9134,31 +9253,31 @@ fn zirAtomicStore(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Compil
91349253fn zirMulAdd(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
91359254 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
91369255 const src = inst_data.src();
9137 return sema.mod.fail(&block.base, src, "TODO: Sema.zirMulAdd", .{});
9256 return sema.fail(block, src, "TODO: Sema.zirMulAdd", .{});
91389257}
91399258
91409259fn zirBuiltinCall(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
91419260 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
91429261 const src = inst_data.src();
9143 return sema.mod.fail(&block.base, src, "TODO: Sema.zirBuiltinCall", .{});
9262 return sema.fail(block, src, "TODO: Sema.zirBuiltinCall", .{});
91449263}
91459264
91469265fn zirFieldPtrType(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
91479266 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
91489267 const src = inst_data.src();
9149 return sema.mod.fail(&block.base, src, "TODO: Sema.zirFieldPtrType", .{});
9268 return sema.fail(block, src, "TODO: Sema.zirFieldPtrType", .{});
91509269}
91519270
91529271fn zirFieldParentPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
91539272 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
91549273 const src = inst_data.src();
9155 return sema.mod.fail(&block.base, src, "TODO: Sema.zirFieldParentPtr", .{});
9274 return sema.fail(block, src, "TODO: Sema.zirFieldParentPtr", .{});
91569275}
91579276
91589277fn zirMaximum(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
91599278 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
91609279 const src = inst_data.src();
9161 return sema.mod.fail(&block.base, src, "TODO: Sema.zirMaximum", .{});
9280 return sema.fail(block, src, "TODO: Sema.zirMaximum", .{});
91629281}
91639282
91649283fn zirMemcpy(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!void {
......@@ -9172,16 +9291,16 @@ fn zirMemcpy(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErro
91729291 const dest_ptr_ty = sema.typeOf(dest_ptr);
91739292
91749293 if (dest_ptr_ty.zigTypeTag() != .Pointer) {
9175 return sema.mod.fail(&block.base, dest_src, "expected pointer, found '{}'", .{dest_ptr_ty});
9294 return sema.fail(block, dest_src, "expected pointer, found '{}'", .{dest_ptr_ty});
91769295 }
91779296 if (dest_ptr_ty.isConstPtr()) {
9178 return sema.mod.fail(&block.base, dest_src, "cannot store through const pointer '{}'", .{dest_ptr_ty});
9297 return sema.fail(block, dest_src, "cannot store through const pointer '{}'", .{dest_ptr_ty});
91799298 }
91809299
91819300 const uncasted_src_ptr = sema.resolveInst(extra.source);
91829301 const uncasted_src_ptr_ty = sema.typeOf(uncasted_src_ptr);
91839302 if (uncasted_src_ptr_ty.zigTypeTag() != .Pointer) {
9184 return sema.mod.fail(&block.base, src_src, "expected pointer, found '{}'", .{
9303 return sema.fail(block, src_src, "expected pointer, found '{}'", .{
91859304 uncasted_src_ptr_ty,
91869305 });
91879306 }
......@@ -9208,7 +9327,7 @@ fn zirMemcpy(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErro
92089327 _ = dest_ptr_val;
92099328 _ = src_ptr_val;
92109329 _ = len_val;
9211 return sema.mod.fail(&block.base, src, "TODO: Sema.zirMemcpy at comptime", .{});
9330 return sema.fail(block, src, "TODO: Sema.zirMemcpy at comptime", .{});
92129331 } else break :rs len_src;
92139332 } else break :rs src_src;
92149333 } else dest_src;
......@@ -9236,10 +9355,10 @@ fn zirMemset(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErro
92369355 const dest_ptr = sema.resolveInst(extra.dest);
92379356 const dest_ptr_ty = sema.typeOf(dest_ptr);
92389357 if (dest_ptr_ty.zigTypeTag() != .Pointer) {
9239 return sema.mod.fail(&block.base, dest_src, "expected pointer, found '{}'", .{dest_ptr_ty});
9358 return sema.fail(block, dest_src, "expected pointer, found '{}'", .{dest_ptr_ty});
92409359 }
92419360 if (dest_ptr_ty.isConstPtr()) {
9242 return sema.mod.fail(&block.base, dest_src, "cannot store through const pointer '{}'", .{dest_ptr_ty});
9361 return sema.fail(block, dest_src, "cannot store through const pointer '{}'", .{dest_ptr_ty});
92439362 }
92449363 const elem_ty = dest_ptr_ty.elemType2();
92459364 const value = try sema.coerce(block, elem_ty, sema.resolveInst(extra.byte), value_src);
......@@ -9254,7 +9373,7 @@ fn zirMemset(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErro
92549373 _ = ptr_val;
92559374 _ = len_val;
92569375 _ = val;
9257 return sema.mod.fail(&block.base, src, "TODO: Sema.zirMemset at comptime", .{});
9376 return sema.fail(block, src, "TODO: Sema.zirMemset at comptime", .{});
92589377 } else break :rs value_src;
92599378 } else break :rs len_src;
92609379 } else dest_src;
......@@ -9275,19 +9394,19 @@ fn zirMemset(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileErro
92759394fn zirMinimum(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
92769395 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
92779396 const src = inst_data.src();
9278 return sema.mod.fail(&block.base, src, "TODO: Sema.zirMinimum", .{});
9397 return sema.fail(block, src, "TODO: Sema.zirMinimum", .{});
92799398}
92809399
92819400fn zirBuiltinAsyncCall(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
92829401 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
92839402 const src = inst_data.src();
9284 return sema.mod.fail(&block.base, src, "TODO: Sema.zirBuiltinAsyncCall", .{});
9403 return sema.fail(block, src, "TODO: Sema.zirBuiltinAsyncCall", .{});
92859404}
92869405
92879406fn zirResume(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
92889407 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
92899408 const src = inst_data.src();
9290 return sema.mod.fail(&block.base, src, "TODO: Sema.zirResume", .{});
9409 return sema.fail(block, src, "TODO: Sema.zirResume", .{});
92919410}
92929411
92939412fn zirAwait(
......@@ -9300,7 +9419,7 @@ fn zirAwait(
93009419 const src = inst_data.src();
93019420
93029421 _ = is_nosuspend;
9303 return sema.mod.fail(&block.base, src, "TODO: Sema.zirAwait", .{});
9422 return sema.fail(block, src, "TODO: Sema.zirAwait", .{});
93049423}
93059424
93069425fn zirVarExtended(
......@@ -9360,7 +9479,7 @@ fn zirVarExtended(
93609479 if (lib_name != null) {
93619480 // Look at the sema code for functions which has this logic, it just needs to
93629481 // be extracted and shared by both var and func
9363 return sema.mod.fail(&block.base, src, "TODO: handle var with lib_name in Sema", .{});
9482 return sema.fail(block, src, "TODO: handle var with lib_name in Sema", .{});
93649483 }
93659484
93669485 const new_var = try sema.gpa.create(Module.Var);
......@@ -9496,7 +9615,7 @@ fn zirWasmMemorySize(
94969615) CompileError!Air.Inst.Ref {
94979616 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;
94989617 const src: LazySrcLoc = .{ .node_offset = extra.node };
9499 return sema.mod.fail(&block.base, src, "TODO: implement Sema.zirWasmMemorySize", .{});
9618 return sema.fail(block, src, "TODO: implement Sema.zirWasmMemorySize", .{});
95009619}
95019620
95029621fn zirWasmMemoryGrow(
......@@ -9506,7 +9625,7 @@ fn zirWasmMemoryGrow(
95069625) CompileError!Air.Inst.Ref {
95079626 const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data;
95089627 const src: LazySrcLoc = .{ .node_offset = extra.node };
9509 return sema.mod.fail(&block.base, src, "TODO: implement Sema.zirWasmMemoryGrow", .{});
9628 return sema.fail(block, src, "TODO: implement Sema.zirWasmMemoryGrow", .{});
95109629}
95119630
95129631fn zirBuiltinExtern(
......@@ -9516,12 +9635,12 @@ fn zirBuiltinExtern(
95169635) CompileError!Air.Inst.Ref {
95179636 const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data;
95189637 const src: LazySrcLoc = .{ .node_offset = extra.node };
9519 return sema.mod.fail(&block.base, src, "TODO: implement Sema.zirBuiltinExtern", .{});
9638 return sema.fail(block, src, "TODO: implement Sema.zirBuiltinExtern", .{});
95209639}
95219640
95229641fn requireFunctionBlock(sema: *Sema, block: *Scope.Block, src: LazySrcLoc) !void {
95239642 if (sema.func == null) {
9524 return sema.mod.fail(&block.base, src, "instruction illegal outside function body", .{});
9643 return sema.fail(block, src, "instruction illegal outside function body", .{});
95259644 }
95269645}
95279646
......@@ -9579,7 +9698,7 @@ fn validateVarType(
95799698 },
95809699 } else unreachable; // TODO should not need else unreachable
95819700 if (!ok) {
9582 return sema.mod.fail(&block.base, src, "variable of type '{}' must be const or comptime", .{var_ty});
9701 return sema.fail(block, src, "variable of type '{}' must be const or comptime", .{var_ty});
95839702 }
95849703}
95859704
......@@ -9684,7 +9803,7 @@ fn panicWithMsg(
96849803 const stack_trace_ty = try sema.resolveTypeFields(block, src, unresolved_stack_trace_ty);
96859804 const ptr_stack_trace_ty = try Type.ptr(arena, .{
96869805 .pointee_type = stack_trace_ty,
9687 .@"addrspace" = target_util.defaultAddressSpace(sema.mod.getTarget(), .global_constant), // TODO might need a place that is more dynamic
9806 .@"addrspace" = target_util.defaultAddressSpace(mod.getTarget(), .global_constant), // TODO might need a place that is more dynamic
96889807 });
96899808 const null_stack_trace = try sema.addConstant(
96909809 try Module.optionalType(arena, ptr_stack_trace_ty),
......@@ -9730,7 +9849,7 @@ fn emitBackwardBranch(sema: *Sema, block: *Scope.Block, src: LazySrcLoc) !void {
97309849 sema.branch_count += 1;
97319850 if (sema.branch_count > sema.branch_quota) {
97329851 // TODO show the "called from here" stack
9733 return sema.mod.fail(&block.base, src, "evaluation exceeded {d} backwards branches", .{sema.branch_quota});
9852 return sema.fail(block, src, "evaluation exceeded {d} backwards branches", .{sema.branch_quota});
97349853 }
97359854}
97369855
......@@ -9745,7 +9864,6 @@ fn fieldVal(
97459864 // When editing this function, note that there is corresponding logic to be edited
97469865 // in `fieldPtr`. This function takes a value and returns a value.
97479866
9748 const mod = sema.mod;
97499867 const arena = sema.arena;
97509868 const object_src = src; // TODO better source location
97519869 const object_ty = sema.typeOf(object);
......@@ -9758,8 +9876,8 @@ fn fieldVal(
97589876 try Value.Tag.int_u64.create(arena, object_ty.arrayLen()),
97599877 );
97609878 } else {
9761 return mod.fail(
9762 &block.base,
9879 return sema.fail(
9880 block,
97639881 field_name_src,
97649882 "no member named '{s}' in '{}'",
97659883 .{ field_name, object_ty },
......@@ -9773,8 +9891,8 @@ fn fieldVal(
97739891 const result_ty = object_ty.slicePtrFieldType(buf);
97749892 if (try sema.resolveMaybeUndefVal(block, object_src, object)) |val| {
97759893 if (val.isUndef()) return sema.addConstUndef(result_ty);
9776 return mod.fail(
9777 &block.base,
9894 return sema.fail(
9895 block,
97789896 field_name_src,
97799897 "TODO implement comptime slice ptr",
97809898 .{},
......@@ -9794,8 +9912,8 @@ fn fieldVal(
97949912 try sema.requireRuntimeBlock(block, src);
97959913 return block.addTyOp(.slice_len, result_ty, object);
97969914 } else {
9797 return mod.fail(
9798 &block.base,
9915 return sema.fail(
9916 block,
97999917 field_name_src,
98009918 "no member named '{s}' in '{}'",
98019919 .{ field_name, object_ty },
......@@ -9812,8 +9930,8 @@ fn fieldVal(
98129930 try Value.Tag.int_u64.create(arena, ptr_child.arrayLen()),
98139931 );
98149932 } else {
9815 return mod.fail(
9816 &block.base,
9933 return sema.fail(
9934 block,
98179935 field_name_src,
98189936 "no member named '{s}' in '{}'",
98199937 .{ field_name, object_ty },
......@@ -9850,10 +9968,10 @@ fn fieldVal(
98509968 break :blk name;
98519969 }
98529970 }
9853 return mod.fail(&block.base, src, "no error named '{s}' in '{}'", .{
9971 return sema.fail(block, src, "no error named '{s}' in '{}'", .{
98549972 field_name, child_type,
98559973 });
9856 } else (try mod.getErrorValue(field_name)).key;
9974 } else (try sema.mod.getErrorValue(field_name)).key;
98579975
98589976 return sema.addConstant(
98599977 try child_type.copy(arena),
......@@ -9873,7 +9991,7 @@ fn fieldVal(
98739991 .Union => "union",
98749992 else => unreachable,
98759993 };
9876 return mod.fail(&block.base, src, "{s} '{}' has no member named '{s}'", .{
9994 return sema.fail(block, src, "{s} '{}' has no member named '{s}'", .{
98779995 kw_name, child_type, field_name,
98789996 });
98799997 },
......@@ -9885,14 +10003,14 @@ fn fieldVal(
988510003 }
988610004 const field_index = child_type.enumFieldIndex(field_name) orelse {
988710005 const msg = msg: {
9888 const msg = try mod.errMsg(
9889 &block.base,
10006 const msg = try sema.errMsg(
10007 block,
989010008 src,
989110009 "enum '{}' has no member named '{s}'",
989210010 .{ child_type, field_name },
989310011 );
989410012 errdefer msg.destroy(sema.gpa);
9895 try mod.errNoteNonLazy(
10013 try sema.mod.errNoteNonLazy(
989610014 child_type.declSrcLoc(),
989710015 msg,
989810016 "enum declared here",
......@@ -9900,20 +10018,20 @@ fn fieldVal(
990010018 );
990110019 break :msg msg;
990210020 };
9903 return mod.failWithOwnedErrorMsg(&block.base, msg);
10021 return sema.failWithOwnedErrorMsg(msg);
990410022 };
990510023 const field_index_u32 = @intCast(u32, field_index);
990610024 const enum_val = try Value.Tag.enum_field_index.create(arena, field_index_u32);
990710025 return sema.addConstant(try child_type.copy(arena), enum_val);
990810026 },
9909 else => return mod.fail(&block.base, src, "type '{}' has no members", .{child_type}),
10027 else => return sema.fail(block, src, "type '{}' has no members", .{child_type}),
991010028 }
991110029 },
991210030 .Struct => return sema.structFieldVal(block, src, object, field_name, field_name_src, object_ty),
991310031 .Union => return sema.unionFieldVal(block, src, object, field_name, field_name_src, object_ty),
991410032 else => {},
991510033 }
9916 return mod.fail(&block.base, src, "type '{}' does not support field access", .{object_ty});
10034 return sema.fail(block, src, "type '{}' does not support field access", .{object_ty});
991710035}
991810036
991910037fn fieldPtr(
......@@ -9927,12 +10045,11 @@ fn fieldPtr(
992710045 // When editing this function, note that there is corresponding logic to be edited
992810046 // in `fieldVal`. This function takes a pointer and returns a pointer.
992910047
9930 const mod = sema.mod;
993110048 const object_ptr_src = src; // TODO better source location
993210049 const object_ptr_ty = sema.typeOf(object_ptr);
993310050 const object_ty = switch (object_ptr_ty.zigTypeTag()) {
993410051 .Pointer => object_ptr_ty.elemType(),
9935 else => return mod.fail(&block.base, object_ptr_src, "expected pointer, found '{}'", .{object_ptr_ty}),
10052 else => return sema.fail(block, object_ptr_src, "expected pointer, found '{}'", .{object_ptr_ty}),
993610053 };
993710054 switch (object_ty.zigTypeTag()) {
993810055 .Array => {
......@@ -9944,8 +10061,8 @@ fn fieldPtr(
994410061 try Value.Tag.int_u64.create(anon_decl.arena(), object_ty.arrayLen()),
994510062 ));
994610063 } else {
9947 return mod.fail(
9948 &block.base,
10064 return sema.fail(
10065 block,
994910066 field_name_src,
995010067 "no member named '{s}' in '{}'",
995110068 .{ field_name, object_ty },
......@@ -9962,22 +10079,22 @@ fn fieldPtr(
996210079 // the runtime value to it, and then return the `alloc`.
996310080 // In both cases the pointer should be const.
996410081 if (mem.eql(u8, field_name, "ptr")) {
9965 return mod.fail(
9966 &block.base,
10082 return sema.fail(
10083 block,
996710084 field_name_src,
996810085 "TODO: implement reference to 'ptr' field of slice '{}'",
996910086 .{object_ty},
997010087 );
997110088 } else if (mem.eql(u8, field_name, "len")) {
9972 return mod.fail(
9973 &block.base,
10089 return sema.fail(
10090 block,
997410091 field_name_src,
997510092 "TODO: implement reference to 'len' field of slice '{}'",
997610093 .{object_ty},
997710094 );
997810095 } else {
9979 return mod.fail(
9980 &block.base,
10096 return sema.fail(
10097 block,
998110098 field_name_src,
998210099 "no member named '{s}' in '{}'",
998310100 .{ field_name, object_ty },
......@@ -9996,8 +10113,8 @@ fn fieldPtr(
999610113 try Value.Tag.int_u64.create(anon_decl.arena(), ptr_child.arrayLen()),
999710114 ));
999810115 } else {
9999 return mod.fail(
10000 &block.base,
10116 return sema.fail(
10117 block,
1000110118 field_name_src,
1000210119 "no member named '{s}' in '{}'",
1000310120 .{ field_name, object_ty },
......@@ -10036,10 +10153,10 @@ fn fieldPtr(
1003610153 break :blk name;
1003710154 }
1003810155 }
10039 return mod.fail(&block.base, src, "no error named '{s}' in '{}'", .{
10156 return sema.fail(block, src, "no error named '{s}' in '{}'", .{
1004010157 field_name, child_type,
1004110158 });
10042 } else (try mod.getErrorValue(field_name)).key;
10159 } else (try sema.mod.getErrorValue(field_name)).key;
1004310160
1004410161 var anon_decl = try block.startAnonDecl();
1004510162 defer anon_decl.deinit();
......@@ -10061,7 +10178,7 @@ fn fieldPtr(
1006110178 .Union => "union",
1006210179 else => unreachable,
1006310180 };
10064 return mod.fail(&block.base, src, "{s} '{}' has no member named '{s}'", .{
10181 return sema.fail(block, src, "{s} '{}' has no member named '{s}'", .{
1006510182 kw_name, child_type, field_name,
1006610183 });
1006710184 },
......@@ -10073,14 +10190,14 @@ fn fieldPtr(
1007310190 }
1007410191 const field_index = child_type.enumFieldIndex(field_name) orelse {
1007510192 const msg = msg: {
10076 const msg = try mod.errMsg(
10077 &block.base,
10193 const msg = try sema.errMsg(
10194 block,
1007810195 src,
1007910196 "enum '{}' has no member named '{s}'",
1008010197 .{ child_type, field_name },
1008110198 );
1008210199 errdefer msg.destroy(sema.gpa);
10083 try mod.errNoteNonLazy(
10200 try sema.mod.errNoteNonLazy(
1008410201 child_type.declSrcLoc(),
1008510202 msg,
1008610203 "enum declared here",
......@@ -10088,7 +10205,7 @@ fn fieldPtr(
1008810205 );
1008910206 break :msg msg;
1009010207 };
10091 return mod.failWithOwnedErrorMsg(&block.base, msg);
10208 return sema.failWithOwnedErrorMsg(msg);
1009210209 };
1009310210 const field_index_u32 = @intCast(u32, field_index);
1009410211 var anon_decl = try block.startAnonDecl();
......@@ -10098,14 +10215,14 @@ fn fieldPtr(
1009810215 try Value.Tag.enum_field_index.create(anon_decl.arena(), field_index_u32),
1009910216 ));
1010010217 },
10101 else => return mod.fail(&block.base, src, "type '{}' has no members", .{child_type}),
10218 else => return sema.fail(block, src, "type '{}' has no members", .{child_type}),
1010210219 }
1010310220 },
1010410221 .Struct => return sema.structFieldPtr(block, src, object_ptr, field_name, field_name_src, object_ty),
1010510222 .Union => return sema.unionFieldPtr(block, src, object_ptr, field_name, field_name_src, object_ty),
1010610223 else => {},
1010710224 }
10108 return mod.fail(&block.base, src, "type '{}' does not support field access", .{object_ty});
10225 return sema.fail(block, src, "type '{}' does not support field access", .{object_ty});
1010910226}
1011010227
1011110228fn fieldCallBind(
......@@ -10119,13 +10236,12 @@ fn fieldCallBind(
1011910236 // When editing this function, note that there is corresponding logic to be edited
1012010237 // in `fieldVal`. This function takes a pointer and returns a pointer.
1012110238
10122 const mod = sema.mod;
1012310239 const raw_ptr_src = src; // TODO better source location
1012410240 const raw_ptr_ty = sema.typeOf(raw_ptr);
1012510241 const inner_ty = if (raw_ptr_ty.zigTypeTag() == .Pointer and raw_ptr_ty.ptrSize() == .One)
1012610242 raw_ptr_ty.childType()
1012710243 else
10128 return mod.fail(&block.base, raw_ptr_src, "expected single pointer, found '{}'", .{raw_ptr_ty});
10244 return sema.fail(block, raw_ptr_src, "expected single pointer, found '{}'", .{raw_ptr_ty});
1012910245
1013010246 // Optionally dereference a second pointer to get the concrete type.
1013110247 const is_double_ptr = inner_ty.zigTypeTag() == .Pointer and inner_ty.ptrSize() == .One;
......@@ -10194,7 +10310,7 @@ fn fieldCallBind(
1019410310 };
1019510311 return sema.analyzeLoad(block, src, ptr_inst, src);
1019610312 },
10197 .Union => return sema.mod.fail(&block.base, src, "TODO implement field calls on unions", .{}),
10313 .Union => return sema.fail(block, src, "TODO implement field calls on unions", .{}),
1019810314 .Type => {
1019910315 const namespace = try sema.analyzeLoad(block, src, object_ptr, src);
1020010316 return sema.fieldVal(block, src, namespace, field_name, field_name_src);
......@@ -10247,7 +10363,7 @@ fn fieldCallBind(
1024710363 else => {},
1024810364 }
1024910365
10250 return mod.fail(&block.base, src, "type '{}' has no field or member function named '{s}'", .{ concrete_ty, field_name });
10366 return sema.fail(block, src, "type '{}' has no field or member function named '{s}'", .{ concrete_ty, field_name });
1025110367}
1025210368
1025310369fn namespaceLookup(
......@@ -10257,19 +10373,18 @@ fn namespaceLookup(
1025710373 namespace: *Scope.Namespace,
1025810374 decl_name: []const u8,
1025910375) CompileError!?*Decl {
10260 const mod = sema.mod;
1026110376 const gpa = sema.gpa;
1026210377 if (try sema.lookupInNamespace(block, src, namespace, decl_name, true)) |decl| {
1026310378 if (!decl.is_pub and decl.getFileScope() != block.getFileScope()) {
1026410379 const msg = msg: {
10265 const msg = try mod.errMsg(&block.base, src, "'{s}' is not marked 'pub'", .{
10380 const msg = try sema.errMsg(block, src, "'{s}' is not marked 'pub'", .{
1026610381 decl_name,
1026710382 });
1026810383 errdefer msg.destroy(gpa);
10269 try mod.errNoteNonLazy(decl.srcLoc(), msg, "declared here", .{});
10384 try sema.mod.errNoteNonLazy(decl.srcLoc(), msg, "declared here", .{});
1027010385 break :msg msg;
1027110386 };
10272 return mod.failWithOwnedErrorMsg(&block.base, msg);
10387 return sema.failWithOwnedErrorMsg(msg);
1027310388 }
1027410389 return decl;
1027510390 }
......@@ -10435,7 +10550,7 @@ fn unionFieldVal(
1043510550 }
1043610551
1043710552 try sema.requireRuntimeBlock(block, src);
10438 return sema.mod.fail(&block.base, src, "TODO implement runtime union field access", .{});
10553 return sema.fail(block, src, "TODO implement runtime union field access", .{});
1043910554}
1044010555
1044110556fn elemPtr(
......@@ -10450,10 +10565,10 @@ fn elemPtr(
1045010565 const array_ptr_ty = sema.typeOf(array_ptr);
1045110566 const array_ty = switch (array_ptr_ty.zigTypeTag()) {
1045210567 .Pointer => array_ptr_ty.elemType(),
10453 else => return sema.mod.fail(&block.base, array_ptr_src, "expected pointer, found '{}'", .{array_ptr_ty}),
10568 else => return sema.fail(block, array_ptr_src, "expected pointer, found '{}'", .{array_ptr_ty}),
1045410569 };
1045510570 if (!array_ty.isIndexable()) {
10456 return sema.mod.fail(&block.base, src, "array access of non-array type '{}'", .{array_ty});
10571 return sema.fail(block, src, "array access of non-array type '{}'", .{array_ty});
1045710572 }
1045810573 if (array_ty.isSinglePointer() and array_ty.elemType().zigTypeTag() == .Array) {
1045910574 // we have to deref the ptr operand to get the actual array pointer
......@@ -10464,7 +10579,7 @@ fn elemPtr(
1046410579 return sema.elemPtrArray(block, src, array_ptr, elem_index, elem_index_src);
1046510580 }
1046610581
10467 return sema.mod.fail(&block.base, src, "TODO implement more analyze elemptr", .{});
10582 return sema.fail(block, src, "TODO implement more analyze elemptr", .{});
1046810583}
1046910584
1047010585fn elemVal(
......@@ -10482,7 +10597,7 @@ fn elemVal(
1048210597 .Slice => {
1048310598 if (try sema.resolveDefinedValue(block, src, array_maybe_ptr)) |slice_val| {
1048410599 _ = slice_val;
10485 return sema.mod.fail(&block.base, src, "TODO implement Sema for elemVal for comptime known slice", .{});
10600 return sema.fail(block, src, "TODO implement Sema for elemVal for comptime known slice", .{});
1048610601 }
1048710602 try sema.requireRuntimeBlock(block, src);
1048810603 return block.addBinOp(.slice_elem_val, array_maybe_ptr, elem_index);
......@@ -10490,7 +10605,7 @@ fn elemVal(
1049010605 .Many, .C => {
1049110606 if (try sema.resolveDefinedValue(block, src, array_maybe_ptr)) |ptr_val| {
1049210607 _ = ptr_val;
10493 return sema.mod.fail(&block.base, src, "TODO implement Sema for elemVal for comptime known pointer", .{});
10608 return sema.fail(block, src, "TODO implement Sema for elemVal for comptime known pointer", .{});
1049410609 }
1049510610 try sema.requireRuntimeBlock(block, src);
1049610611 return block.addBinOp(.ptr_elem_val, array_maybe_ptr, elem_index);
......@@ -10505,7 +10620,7 @@ fn elemVal(
1050510620 const slice = try sema.analyzeLoad(block, src, array_maybe_ptr, array_ptr_src);
1050610621 if (try sema.resolveDefinedValue(block, src, slice)) |slice_val| {
1050710622 _ = slice_val;
10508 return sema.mod.fail(&block.base, src, "TODO implement Sema for elemVal for comptime known slice", .{});
10623 return sema.fail(block, src, "TODO implement Sema for elemVal for comptime known slice", .{});
1050910624 }
1051010625 try sema.requireRuntimeBlock(block, src);
1051110626 return block.addBinOp(.slice_elem_val, slice, elem_index);
......@@ -10519,7 +10634,7 @@ fn elemVal(
1051910634 const ptr = try sema.analyzeLoad(block, src, array_maybe_ptr, array_ptr_src);
1052010635 if (try sema.resolveDefinedValue(block, src, ptr)) |ptr_val| {
1052110636 _ = ptr_val;
10522 return sema.mod.fail(&block.base, src, "TODO implement Sema for elemVal for comptime known pointer", .{});
10637 return sema.fail(block, src, "TODO implement Sema for elemVal for comptime known pointer", .{});
1052310638 }
1052410639 try sema.requireRuntimeBlock(block, src);
1052510640 return block.addBinOp(.ptr_elem_val, ptr, elem_index);
......@@ -10527,8 +10642,8 @@ fn elemVal(
1052710642 try sema.requireRuntimeBlock(block, src);
1052810643 return block.addBinOp(.ptr_ptr_elem_val, array_maybe_ptr, elem_index);
1052910644 },
10530 .One => return sema.mod.fail(
10531 &block.base,
10645 .One => return sema.fail(
10646 block,
1053210647 array_ptr_src,
1053310648 "expected pointer, found '{}'",
1053410649 .{indexable_ty.elemType()},
......@@ -10538,8 +10653,8 @@ fn elemVal(
1053810653 const ptr = try sema.elemPtr(block, src, array_maybe_ptr, elem_index, elem_index_src);
1053910654 return sema.analyzeLoad(block, src, ptr, elem_index_src);
1054010655 },
10541 else => return sema.mod.fail(
10542 &block.base,
10656 else => return sema.fail(
10657 block,
1054310658 array_ptr_src,
1054410659 "expected pointer, found '{}'",
1054510660 .{indexable_ty},
......@@ -10547,8 +10662,8 @@ fn elemVal(
1054710662 }
1054810663 },
1054910664 },
10550 else => return sema.mod.fail(
10551 &block.base,
10665 else => return sema.fail(
10666 block,
1055210667 array_ptr_src,
1055310668 "expected pointer, found '{}'",
1055410669 .{maybe_ptr_ty},
......@@ -10616,10 +10731,10 @@ fn coerce(
1061610731 if (dest_type.eql(inst_ty))
1061710732 return inst;
1061810733
10619 const mod = sema.mod;
1062010734 const arena = sema.arena;
10735 const target = sema.mod.getTarget();
1062110736
10622 const in_memory_result = coerceInMemoryAllowed(dest_type, inst_ty, false, mod.getTarget());
10737 const in_memory_result = coerceInMemoryAllowed(dest_type, inst_ty, false, target);
1062310738 if (in_memory_result == .ok) {
1062410739 return sema.bitcast(block, dest_type, inst, inst_src);
1062510740 }
......@@ -10636,8 +10751,6 @@ fn coerce(
1063610751 if (try sema.coerceNum(block, dest_type, inst, inst_src)) |some|
1063710752 return some;
1063810753
10639 const target = mod.getTarget();
10640
1064110754 switch (dest_type.zigTypeTag()) {
1064210755 .Optional => {
1064310756 // null to ?T
......@@ -10664,7 +10777,7 @@ fn coerce(
1066410777 if (inst_ty.ptrAddressSpace() != dest_type.ptrAddressSpace()) break :src_array_ptr;
1066510778
1066610779 const dst_elem_type = dest_type.elemType();
10667 switch (coerceInMemoryAllowed(dst_elem_type, array_elem_type, dest_is_mut, mod.getTarget())) {
10780 switch (coerceInMemoryAllowed(dst_elem_type, array_elem_type, dest_is_mut, target)) {
1066810781 .ok => {},
1066910782 .no_match => break :src_array_ptr,
1067010783 }
......@@ -10733,14 +10846,14 @@ fn coerce(
1073310846 const resolved_dest_type = try sema.resolveTypeFields(block, inst_src, dest_type);
1073410847 const field_index = resolved_dest_type.enumFieldIndex(bytes) orelse {
1073510848 const msg = msg: {
10736 const msg = try mod.errMsg(
10737 &block.base,
10849 const msg = try sema.errMsg(
10850 block,
1073810851 inst_src,
1073910852 "enum '{}' has no field named '{s}'",
1074010853 .{ resolved_dest_type, bytes },
1074110854 );
1074210855 errdefer msg.destroy(sema.gpa);
10743 try mod.errNoteNonLazy(
10856 try sema.mod.errNoteNonLazy(
1074410857 resolved_dest_type.declSrcLoc(),
1074510858 msg,
1074610859 "enum declared here",
......@@ -10748,7 +10861,7 @@ fn coerce(
1074810861 );
1074910862 break :msg msg;
1075010863 };
10751 return mod.failWithOwnedErrorMsg(&block.base, msg);
10864 return sema.failWithOwnedErrorMsg(msg);
1075210865 };
1075310866 return sema.addConstant(
1075410867 resolved_dest_type,
......@@ -10771,7 +10884,7 @@ fn coerce(
1077110884 else => {},
1077210885 }
1077310886
10774 return mod.fail(&block.base, inst_src, "expected {}, found {}", .{ dest_type, inst_ty });
10887 return sema.fail(block, inst_src, "expected {}, found {}", .{ dest_type, inst_ty });
1077510888}
1077610889
1077710890const InMemoryCoercionResult = enum {
......@@ -10888,13 +11001,13 @@ fn coerceNum(
1088811001 .ComptimeInt, .Int => switch (src_zig_tag) {
1088911002 .Float, .ComptimeFloat => {
1089011003 if (val.floatHasFraction()) {
10891 return sema.mod.fail(&block.base, inst_src, "fractional component prevents float value {} from coercion to type '{}'", .{ val, dest_type });
11004 return sema.fail(block, inst_src, "fractional component prevents float value {} from coercion to type '{}'", .{ val, dest_type });
1089211005 }
10893 return sema.mod.fail(&block.base, inst_src, "TODO float to int", .{});
11006 return sema.fail(block, inst_src, "TODO float to int", .{});
1089411007 },
1089511008 .Int, .ComptimeInt => {
1089611009 if (!val.intFitsInType(dest_type, target)) {
10897 return sema.mod.fail(&block.base, inst_src, "type {} cannot represent integer value {}", .{ dest_type, val });
11010 return sema.fail(block, inst_src, "type {} cannot represent integer value {}", .{ dest_type, val });
1089811011 }
1089911012 return try sema.addConstant(dest_type, val);
1090011013 },
......@@ -10908,8 +11021,8 @@ fn coerceNum(
1090811021 .Float => {
1090911022 const result_val = try val.floatCast(sema.arena, dest_type);
1091011023 if (!val.eql(result_val, dest_type)) {
10911 return sema.mod.fail(
10912 &block.base,
11024 return sema.fail(
11025 block,
1091311026 inst_src,
1091411027 "type {} cannot represent float value {}",
1091511028 .{ dest_type, val },
......@@ -10922,8 +11035,8 @@ fn coerceNum(
1092211035 // TODO implement this compile error
1092311036 //const int_again_val = try result_val.floatToInt(sema.arena, inst_ty);
1092411037 //if (!int_again_val.eql(val, inst_ty)) {
10925 // return sema.mod.fail(
10926 // &block.base,
11038 // return sema.fail(
11039 // block,
1092711040 // inst_src,
1092811041 // "type {} cannot represent integer value {}",
1092911042 // .{ dest_type, val },
......@@ -10946,7 +11059,7 @@ fn coerceVarArgParam(
1094611059) !Air.Inst.Ref {
1094711060 const inst_ty = sema.typeOf(inst);
1094811061 switch (inst_ty.zigTypeTag()) {
10949 .ComptimeInt, .ComptimeFloat => return sema.mod.fail(&block.base, inst_src, "integer and float literals in var args function must be casted", .{}),
11062 .ComptimeInt, .ComptimeFloat => return sema.fail(block, inst_src, "integer and float literals in var args function must be casted", .{}),
1095011063 else => {},
1095111064 }
1095211065 // TODO implement more of this function.
......@@ -10960,7 +11073,7 @@ fn storePtr(
1096011073 src: LazySrcLoc,
1096111074 ptr: Air.Inst.Ref,
1096211075 uncasted_operand: Air.Inst.Ref,
10963) !void {
11076) CompileError!void {
1096411077 return sema.storePtr2(block, src, ptr, src, uncasted_operand, src, .store);
1096511078}
1096611079
......@@ -10976,7 +11089,7 @@ fn storePtr2(
1097611089) !void {
1097711090 const ptr_ty = sema.typeOf(ptr);
1097811091 if (ptr_ty.isConstPtr())
10979 return sema.mod.fail(&block.base, src, "cannot assign to constant", .{});
11092 return sema.fail(block, src, "cannot assign to constant", .{});
1098011093
1098111094 const elem_ty = ptr_ty.elemType();
1098211095 const operand = try sema.coerce(block, elem_ty, uncasted_operand, operand_src);
......@@ -10985,7 +11098,7 @@ fn storePtr2(
1098511098
1098611099 const runtime_src = if (try sema.resolveDefinedValue(block, ptr_src, ptr)) |ptr_val| rs: {
1098711100 const operand_val = (try sema.resolveMaybeUndefVal(block, operand_src, operand)) orelse
10988 return sema.mod.fail(&block.base, src, "cannot store runtime value in compile time variable", .{});
11101 return sema.fail(block, src, "cannot store runtime value in compile time variable", .{});
1098911102 if (ptr_val.tag() == .decl_ref_mut) {
1099011103 try sema.storePtrVal(block, src, ptr_val, operand_val, elem_ty);
1099111104 return;
......@@ -11013,21 +11126,21 @@ fn storePtrVal(
1101311126 if (decl_ref_mut.data.runtime_index < block.runtime_index) {
1101411127 if (block.runtime_cond) |cond_src| {
1101511128 const msg = msg: {
11016 const msg = try sema.mod.errMsg(&block.base, src, "store to comptime variable depends on runtime condition", .{});
11129 const msg = try sema.errMsg(block, src, "store to comptime variable depends on runtime condition", .{});
1101711130 errdefer msg.destroy(sema.gpa);
11018 try sema.mod.errNote(&block.base, cond_src, msg, "runtime condition here", .{});
11131 try sema.errNote(block, cond_src, msg, "runtime condition here", .{});
1101911132 break :msg msg;
1102011133 };
11021 return sema.mod.failWithOwnedErrorMsg(&block.base, msg);
11134 return sema.failWithOwnedErrorMsg(msg);
1102211135 }
1102311136 if (block.runtime_loop) |loop_src| {
1102411137 const msg = msg: {
11025 const msg = try sema.mod.errMsg(&block.base, src, "cannot store to comptime variable in non-inline loop", .{});
11138 const msg = try sema.errMsg(block, src, "cannot store to comptime variable in non-inline loop", .{});
1102611139 errdefer msg.destroy(sema.gpa);
11027 try sema.mod.errNote(&block.base, loop_src, msg, "non-inline loop here", .{});
11140 try sema.errNote(block, loop_src, msg, "non-inline loop here", .{});
1102811141 break :msg msg;
1102911142 };
11030 return sema.mod.failWithOwnedErrorMsg(&block.base, msg);
11143 return sema.failWithOwnedErrorMsg(msg);
1103111144 }
1103211145 unreachable;
1103311146 }
......@@ -11191,7 +11304,7 @@ fn analyzeLoad(
1119111304 const ptr_ty = sema.typeOf(ptr);
1119211305 const elem_ty = switch (ptr_ty.zigTypeTag()) {
1119311306 .Pointer => ptr_ty.elemType(),
11194 else => return sema.mod.fail(&block.base, ptr_src, "expected pointer, found '{}'", .{ptr_ty}),
11307 else => return sema.fail(block, ptr_src, "expected pointer, found '{}'", .{ptr_ty}),
1119511308 };
1119611309 if (try sema.resolveDefinedValue(block, ptr_src, ptr)) |ptr_val| {
1119711310 if (try ptr_val.pointerDeref(sema.arena)) |elem_val| {
......@@ -11213,7 +11326,7 @@ fn analyzeSliceLen(
1121311326 if (slice_val.isUndef()) {
1121411327 return sema.addConstUndef(Type.initTag(.usize));
1121511328 }
11216 return sema.mod.fail(&block.base, src, "TODO implement Sema analyzeSliceLen on comptime slice", .{});
11329 return sema.fail(block, src, "TODO implement Sema analyzeSliceLen on comptime slice", .{});
1121711330 }
1121811331 try sema.requireRuntimeBlock(block, src);
1121911332 return block.addTyOp(.slice_len, Type.initTag(.usize), slice_inst);
......@@ -11283,7 +11396,7 @@ fn analyzeSlice(
1128311396 const array_ptr_ty = sema.typeOf(array_ptr);
1128411397 const ptr_child = switch (array_ptr_ty.zigTypeTag()) {
1128511398 .Pointer => array_ptr_ty.elemType(),
11286 else => return sema.mod.fail(&block.base, src, "expected pointer, found '{}'", .{array_ptr_ty}),
11399 else => return sema.fail(block, src, "expected pointer, found '{}'", .{array_ptr_ty}),
1128711400 };
1128811401
1128911402 var array_type = ptr_child;
......@@ -11296,11 +11409,11 @@ fn analyzeSlice(
1129611409 break :blk ptr_child.elemType().elemType();
1129711410 }
1129811411
11299 return sema.mod.fail(&block.base, src, "slice of single-item pointer", .{});
11412 return sema.fail(block, src, "slice of single-item pointer", .{});
1130011413 }
1130111414 break :blk ptr_child.elemType();
1130211415 },
11303 else => return sema.mod.fail(&block.base, src, "slice of non-array type '{}'", .{ptr_child}),
11416 else => return sema.fail(block, src, "slice of non-array type '{}'", .{ptr_child}),
1130411417 };
1130511418
1130611419 const slice_sentinel = if (sentinel_opt != .none) blk: {
......@@ -11316,7 +11429,7 @@ fn analyzeSlice(
1131611429 const start_u64 = start_val.toUnsignedInt();
1131711430 const end_u64 = end_val.toUnsignedInt();
1131811431 if (start_u64 > end_u64) {
11319 return sema.mod.fail(&block.base, src, "out of bounds slice", .{});
11432 return sema.fail(block, src, "out of bounds slice", .{});
1132011433 }
1132111434
1132211435 const len = end_u64 - start_u64;
......@@ -11341,7 +11454,7 @@ fn analyzeSlice(
1134111454 });
1134211455 _ = return_type;
1134311456
11344 return sema.mod.fail(&block.base, src, "TODO implement analysis of slice", .{});
11457 return sema.fail(block, src, "TODO implement analysis of slice", .{});
1134511458}
1134611459
1134711460/// Asserts that lhs and rhs types are both numeric.
......@@ -11366,13 +11479,13 @@ fn cmpNumeric(
1136611479
1136711480 if (lhs_ty_tag == .Vector and rhs_ty_tag == .Vector) {
1136811481 if (lhs_ty.arrayLen() != rhs_ty.arrayLen()) {
11369 return sema.mod.fail(&block.base, src, "vector length mismatch: {d} and {d}", .{
11482 return sema.fail(block, src, "vector length mismatch: {d} and {d}", .{
1137011483 lhs_ty.arrayLen(), rhs_ty.arrayLen(),
1137111484 });
1137211485 }
11373 return sema.mod.fail(&block.base, src, "TODO implement support for vectors in cmpNumeric", .{});
11486 return sema.fail(block, src, "TODO implement support for vectors in cmpNumeric", .{});
1137411487 } else if (lhs_ty_tag == .Vector or rhs_ty_tag == .Vector) {
11375 return sema.mod.fail(&block.base, src, "mixed scalar and vector operands to comparison operator: '{}' and '{}'", .{
11488 return sema.fail(block, src, "mixed scalar and vector operands to comparison operator: '{}' and '{}'", .{
1137611489 lhs_ty, rhs_ty,
1137711490 });
1137811491 }
......@@ -11522,7 +11635,7 @@ fn cmpNumeric(
1152211635 const dest_type = if (dest_float_type) |ft| ft else blk: {
1152311636 const max_bits = std.math.max(lhs_bits, rhs_bits);
1152411637 const casted_bits = std.math.cast(u16, max_bits) catch |err| switch (err) {
11525 error.Overflow => return sema.mod.fail(&block.base, src, "{d} exceeds maximum integer bit count", .{max_bits}),
11638 error.Overflow => return sema.fail(block, src, "{d} exceeds maximum integer bit count", .{max_bits}),
1152611639 };
1152711640 const signedness: std.builtin.Signedness = if (dest_int_is_signed) .signed else .unsigned;
1152811641 break :blk try Module.makeIntType(sema.arena, signedness, casted_bits);
......@@ -11569,8 +11682,8 @@ fn wrapErrorUnion(
1156911682 const expected_name = val.castTag(.@"error").?.data.name;
1157011683 const n = dest_err_set_ty.castTag(.error_set_single).?.data;
1157111684 if (!mem.eql(u8, expected_name, n)) {
11572 return sema.mod.fail(
11573 &block.base,
11685 return sema.fail(
11686 block,
1157411687 inst_src,
1157511688 "expected type '{}', found type '{}'",
1157611689 .{ dest_err_set_ty, inst_ty },
......@@ -11587,8 +11700,8 @@ fn wrapErrorUnion(
1158711700 if (mem.eql(u8, expected_name, name)) break true;
1158811701 } else false;
1158911702 if (!found) {
11590 return sema.mod.fail(
11591 &block.base,
11703 return sema.fail(
11704 block,
1159211705 inst_src,
1159311706 "expected type '{}', found type '{}'",
1159411707 .{ dest_err_set_ty, inst_ty },
......@@ -11599,8 +11712,8 @@ fn wrapErrorUnion(
1159911712 const expected_name = val.castTag(.@"error").?.data.name;
1160011713 const map = &dest_err_set_ty.castTag(.error_set_inferred).?.data.map;
1160111714 if (!map.contains(expected_name)) {
11602 return sema.mod.fail(
11603 &block.base,
11715 return sema.fail(
11716 block,
1160411717 inst_src,
1160511718 "expected type '{}', found type '{}'",
1160611719 .{ dest_err_set_ty, inst_ty },
......@@ -11735,18 +11848,18 @@ fn resolvePeerTypes(
1173511848 );
1173611849
1173711850 const msg = msg: {
11738 const msg = try sema.mod.errMsg(&block.base, src, "incompatible types: '{}' and '{}'", .{ chosen_ty, candidate_ty });
11851 const msg = try sema.errMsg(block, src, "incompatible types: '{}' and '{}'", .{ chosen_ty, candidate_ty });
1173911852 errdefer msg.destroy(sema.gpa);
1174011853
1174111854 if (chosen_src) |src_loc|
11742 try sema.mod.errNote(&block.base, src_loc, msg, "type '{}' here", .{chosen_ty});
11855 try sema.errNote(block, src_loc, msg, "type '{}' here", .{chosen_ty});
1174311856
1174411857 if (candidate_src) |src_loc|
11745 try sema.mod.errNote(&block.base, src_loc, msg, "type '{}' here", .{candidate_ty});
11858 try sema.errNote(block, src_loc, msg, "type '{}' here", .{candidate_ty});
1174611859
1174711860 break :msg msg;
1174811861 };
11749 return sema.mod.failWithOwnedErrorMsg(&block.base, msg);
11862 return sema.failWithOwnedErrorMsg(msg);
1175011863 }
1175111864
1175211865 return sema.typeOf(chosen);
......@@ -11765,7 +11878,7 @@ pub fn resolveTypeLayout(
1176511878 switch (struct_obj.status) {
1176611879 .none, .have_field_types => {},
1176711880 .field_types_wip, .layout_wip => {
11768 return sema.mod.fail(&block.base, src, "struct {} depends on itself", .{ty});
11881 return sema.fail(block, src, "struct {} depends on itself", .{ty});
1176911882 },
1177011883 .have_layout => return,
1177111884 }
......@@ -11786,7 +11899,7 @@ fn resolveTypeFields(sema: *Sema, block: *Scope.Block, src: LazySrcLoc, ty: Type
1178611899 switch (struct_obj.status) {
1178711900 .none => {},
1178811901 .field_types_wip => {
11789 return sema.mod.fail(&block.base, src, "struct {} depends on itself", .{ty});
11902 return sema.fail(block, src, "struct {} depends on itself", .{ty});
1179011903 },
1179111904 .have_field_types, .have_layout, .layout_wip => return ty,
1179211905 }
......@@ -11813,7 +11926,7 @@ fn resolveTypeFields(sema: *Sema, block: *Scope.Block, src: LazySrcLoc, ty: Type
1181311926 switch (union_obj.status) {
1181411927 .none => {},
1181511928 .field_types_wip => {
11816 return sema.mod.fail(&block.base, src, "union {} depends on itself", .{ty});
11929 return sema.fail(block, src, "union {} depends on itself", .{ty});
1181711930 },
1181811931 .have_field_types, .have_layout, .layout_wip => return ty,
1181911932 }
......@@ -12232,7 +12345,7 @@ fn generateUnionTagTypeNumbered(
1223212345 .val = enum_val,
1223312346 });
1223412347 new_decl.owns_tv = true;
12235 errdefer sema.mod.abortAnonDecl(new_decl);
12348 errdefer mod.abortAnonDecl(new_decl);
1223612349
1223712350 enum_obj.* = .{
1223812351 .owner_decl = new_decl,
......@@ -12268,7 +12381,7 @@ fn generateUnionTagTypeSimple(sema: *Sema, block: *Scope.Block, fields_len: u32)
1226812381 .val = enum_val,
1226912382 });
1227012383 new_decl.owns_tv = true;
12271 errdefer sema.mod.abortAnonDecl(new_decl);
12384 errdefer mod.abortAnonDecl(new_decl);
1227212385
1227312386 enum_obj.* = .{
1227412387 .owner_decl = new_decl,
......@@ -12752,8 +12865,8 @@ pub fn analyzeAddrspace(
1275212865 .pointer => "pointers",
1275312866 };
1275412867
12755 return sema.mod.fail(
12756 &block.base,
12868 return sema.fail(
12869 block,
1275712870 src,
1275812871 "{s} with address space '{s}' are not supported on {s}",
1275912872 .{ entity, @tagName(address_space), arch.genericName() },