authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-08-29 16:13:39-04:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2023-08-29 16:13:39-04:00
log49075d20557994da4eb341e7431de38a6df2088b
tree6c56a36b2d6e96612dd8beff36f5852816c6782f
parent4635179857999a64ce8350c9b3cbe90cede9ea8c
parent7a251c4cb8082d080e23fb86fe20be6bf4c745a4
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

Merge pull request #16969 from jacobly0/no-clear-ref-trace

Sema: refactor to use fewer catch expressions

4 files changed, 1042 insertions(+), 836 deletions(-)

src/Compilation.zig+24-23
......@@ -2858,51 +2858,52 @@ pub fn addModuleErrorMsg(mod: *Module, eb: *ErrorBundle.Wip, module_err_msg: Mod
28582858 var ref_traces: std.ArrayListUnmanaged(ErrorBundle.ReferenceTrace) = .{};
28592859 defer ref_traces.deinit(gpa);
28602860
2861 for (module_err_msg.reference_trace) |module_reference| {
2862 if (module_reference.hidden != 0) {
2863 try ref_traces.append(gpa, .{
2864 .decl_name = module_reference.hidden,
2865 .src_loc = .none,
2866 });
2867 break;
2868 } else if (module_reference.decl == .none) {
2869 try ref_traces.append(gpa, .{
2870 .decl_name = 0,
2871 .src_loc = .none,
2872 });
2873 break;
2861 const remaining_references: ?u32 = remaining: {
2862 if (mod.comp.reference_trace) |_| {
2863 if (module_err_msg.hidden_references > 0) break :remaining module_err_msg.hidden_references;
2864 } else {
2865 if (module_err_msg.reference_trace.len > 0) break :remaining 0;
28742866 }
2867 break :remaining null;
2868 };
2869 try ref_traces.ensureTotalCapacityPrecise(gpa, module_err_msg.reference_trace.len +
2870 @intFromBool(remaining_references != null));
2871
2872 for (module_err_msg.reference_trace) |module_reference| {
28752873 const source = try module_reference.src_loc.file_scope.getSource(gpa);
28762874 const span = try module_reference.src_loc.span(gpa);
28772875 const loc = std.zig.findLineColumn(source.bytes, span.main);
28782876 const rt_file_path = try module_reference.src_loc.file_scope.fullPath(gpa);
28792877 defer gpa.free(rt_file_path);
2880 try ref_traces.append(gpa, .{
2881 .decl_name = try eb.addString(ip.stringToSliceUnwrap(module_reference.decl).?),
2878 ref_traces.appendAssumeCapacity(.{
2879 .decl_name = try eb.addString(ip.stringToSlice(module_reference.decl)),
28822880 .src_loc = try eb.addSourceLocation(.{
28832881 .src_path = try eb.addString(rt_file_path),
28842882 .span_start = span.start,
28852883 .span_main = span.main,
28862884 .span_end = span.end,
2887 .line = @as(u32, @intCast(loc.line)),
2888 .column = @as(u32, @intCast(loc.column)),
2885 .line = @intCast(loc.line),
2886 .column = @intCast(loc.column),
28892887 .source_line = 0,
28902888 }),
28912889 });
28922890 }
2891 if (remaining_references) |remaining| ref_traces.appendAssumeCapacity(
2892 .{ .decl_name = remaining, .src_loc = .none },
2893 );
28932894
28942895 const src_loc = try eb.addSourceLocation(.{
28952896 .src_path = try eb.addString(file_path),
28962897 .span_start = err_span.start,
28972898 .span_main = err_span.main,
28982899 .span_end = err_span.end,
2899 .line = @as(u32, @intCast(err_loc.line)),
2900 .column = @as(u32, @intCast(err_loc.column)),
2900 .line = @intCast(err_loc.line),
2901 .column = @intCast(err_loc.column),
29012902 .source_line = if (module_err_msg.src_loc.lazy == .entire_file)
29022903 0
29032904 else
29042905 try eb.addString(err_loc.source_line),
2905 .reference_trace_len = @as(u32, @intCast(ref_traces.items.len)),
2906 .reference_trace_len = @intCast(ref_traces.items.len),
29062907 });
29072908
29082909 for (ref_traces.items) |rt| {
......@@ -2928,8 +2929,8 @@ pub fn addModuleErrorMsg(mod: *Module, eb: *ErrorBundle.Wip, module_err_msg: Mod
29282929 .span_start = span.start,
29292930 .span_main = span.main,
29302931 .span_end = span.end,
2931 .line = @as(u32, @intCast(loc.line)),
2932 .column = @as(u32, @intCast(loc.column)),
2932 .line = @intCast(loc.line),
2933 .column = @intCast(loc.column),
29332934 .source_line = if (err_loc.eql(loc)) 0 else try eb.addString(loc.source_line),
29342935 }),
29352936 }, .{ .eb = eb });
......@@ -2938,7 +2939,7 @@ pub fn addModuleErrorMsg(mod: *Module, eb: *ErrorBundle.Wip, module_err_msg: Mod
29382939 }
29392940 }
29402941
2941 const notes_len = @as(u32, @intCast(notes.entries.len));
2942 const notes_len: u32 = @intCast(notes.entries.len);
29422943
29432944 try eb.addRootErrorMessage(.{
29442945 .msg = try eb.addString(module_err_msg.msg),
src/Module.zig+8-4
......@@ -1519,11 +1519,11 @@ pub const ErrorMsg = struct {
15191519 msg: []const u8,
15201520 notes: []ErrorMsg = &.{},
15211521 reference_trace: []Trace = &.{},
1522 hidden_references: u32 = 0,
15221523
15231524 pub const Trace = struct {
1524 decl: InternPool.OptionalNullTerminatedString,
1525 decl: InternPool.NullTerminatedString,
15251526 src_loc: SrcLoc,
1526 hidden: u32 = 0,
15271527 };
15281528
15291529 pub fn create(
......@@ -4147,7 +4147,9 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !bool {
41474147 const address_space_src: LazySrcLoc = .{ .node_offset_var_decl_addrspace = 0 };
41484148 const ty_src: LazySrcLoc = .{ .node_offset_var_decl_ty = 0 };
41494149 const init_src: LazySrcLoc = .{ .node_offset_var_decl_init = 0 };
4150 const decl_tv = try sema.resolveInstValue(&block_scope, init_src, result_ref, "global variable initializer must be comptime-known");
4150 const decl_tv = try sema.resolveInstValue(&block_scope, init_src, result_ref, .{
4151 .needed_comptime_reason = "global variable initializer must be comptime-known",
4152 });
41514153
41524154 // Note this resolves the type of the Decl, not the value; if this Decl
41534155 // is a struct, for example, this resolves `type` (which needs no resolution),
......@@ -4257,7 +4259,9 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !bool {
42574259 decl.@"linksection" = blk: {
42584260 const linksection_ref = decl.zirLinksectionRef(mod);
42594261 if (linksection_ref == .none) break :blk .none;
4260 const bytes = try sema.resolveConstString(&block_scope, section_src, linksection_ref, "linksection must be comptime-known");
4262 const bytes = try sema.resolveConstString(&block_scope, section_src, linksection_ref, .{
4263 .needed_comptime_reason = "linksection must be comptime-known",
4264 });
42614265 if (mem.indexOfScalar(u8, bytes, 0) != null) {
42624266 return sema.fail(&block_scope, section_src, "linksection cannot contain null bytes", .{});
42634267 } else if (bytes.len == 0) {
src/Sema.zig+993-809
......@@ -269,7 +269,7 @@ pub const InstMap = struct {
269269 while (true) {
270270 const extra_capacity = better_capacity / 2 + 16;
271271 better_capacity += extra_capacity;
272 better_start -|= @as(Zir.Inst.Index, @intCast(extra_capacity / 2));
272 better_start -|= @intCast(extra_capacity / 2);
273273 if (better_start <= start and end < better_capacity + better_start)
274274 break;
275275 }
......@@ -282,7 +282,7 @@ pub const InstMap = struct {
282282
283283 allocator.free(map.items);
284284 map.items = new_items;
285 map.start = @as(Zir.Inst.Index, @intCast(better_start));
285 map.start = @intCast(better_start);
286286 }
287287};
288288
......@@ -405,7 +405,9 @@ pub const Block = struct {
405405 /// It is shared among all the blocks in an inline or comptime called
406406 /// function.
407407 pub const Inlining = struct {
408 /// Might be `none`.
408 call_block: *Block,
409 call_src: LazySrcLoc,
410 has_comptime_args: bool,
409411 func: InternPool.Index,
410412 comptime_result: Air.Inst.Ref,
411413 merges: Merges,
......@@ -681,7 +683,7 @@ pub const Block = struct {
681683 const sema = block.sema;
682684 const ty_ref = Air.internedToRef(aggregate_ty.toIntern());
683685 try sema.air_extra.ensureUnusedCapacity(sema.gpa, elements.len);
684 const extra_index = @as(u32, @intCast(sema.air_extra.items.len));
686 const extra_index: u32 = @intCast(sema.air_extra.items.len);
685687 sema.appendRefsAssumeCapacity(elements);
686688
687689 return block.addInst(.{
......@@ -722,7 +724,7 @@ pub const Block = struct {
722724 try sema.air_instructions.ensureUnusedCapacity(gpa, 1);
723725 try block.instructions.ensureUnusedCapacity(gpa, 1);
724726
725 const result_index = @as(Air.Inst.Index, @intCast(sema.air_instructions.len));
727 const result_index: Air.Inst.Index = @intCast(sema.air_instructions.len);
726728 sema.air_instructions.appendAssumeCapacity(inst);
727729 block.instructions.appendAssumeCapacity(result_index);
728730 return result_index;
......@@ -740,7 +742,7 @@ pub const Block = struct {
740742
741743 try sema.air_instructions.ensureUnusedCapacity(gpa, 1);
742744
743 const result_index = @as(Air.Inst.Index, @intCast(sema.air_instructions.len));
745 const result_index: Air.Inst.Index = @intCast(sema.air_instructions.len);
744746 sema.air_instructions.appendAssumeCapacity(inst);
745747
746748 try block.instructions.insert(gpa, index, result_index);
......@@ -818,6 +820,11 @@ const InferredAlloc = struct {
818820 }) = .{},
819821};
820822
823const NeededComptimeReason = struct {
824 needed_comptime_reason: []const u8,
825 block_comptime_reason: ?*const Block.ComptimeReason = null,
826};
827
821828pub fn deinit(sema: *Sema) void {
822829 const gpa = sema.gpa;
823830 sema.air_instructions.deinit(gpa);
......@@ -849,7 +856,7 @@ fn resolveBody(
849856 body_inst: Zir.Inst.Index,
850857) CompileError!Air.Inst.Ref {
851858 const break_data = (try sema.analyzeBodyBreak(block, body)) orelse
852 return Air.Inst.Ref.unreachable_value;
859 return .unreachable_value;
853860 // For comptime control flow, we need to detect when `analyzeBody` reports
854861 // that we need to break from an outer block. In such case we
855862 // use Zig's error mechanism to send control flow up the stack until
......@@ -1455,7 +1462,7 @@ fn analyzeBodyInner(
14551462 try sema.errNote(block, runtime_src, msg, "runtime control flow here", .{});
14561463 break :msg msg;
14571464 };
1458 return sema.failWithOwnedErrorMsg(msg);
1465 return sema.failWithOwnedErrorMsg(block, msg);
14591466 }
14601467 }
14611468 i += 1;
......@@ -1654,10 +1661,10 @@ fn analyzeBodyInner(
16541661 const extra = sema.code.extraData(Zir.Inst.CondBr, inst_data.payload_index);
16551662 const then_body = sema.code.extra[extra.end..][0..extra.data.then_body_len];
16561663 const else_body = sema.code.extra[extra.end + then_body.len ..][0..extra.data.else_body_len];
1657 const cond = sema.resolveInstConst(block, cond_src, extra.data.condition, "condition in comptime branch must be comptime-known") catch |err| {
1658 if (err == error.AnalysisFail and block.comptime_reason != null) try block.comptime_reason.?.explain(sema, sema.err);
1659 return err;
1660 };
1664 const cond = try sema.resolveInstConst(block, cond_src, extra.data.condition, .{
1665 .needed_comptime_reason = "condition in comptime branch must be comptime-known",
1666 .block_comptime_reason = block.comptime_reason,
1667 });
16611668 const inline_body = if (cond.val.toBool()) then_body else else_body;
16621669
16631670 try sema.maybeErrorUnwrapCondbr(block, inline_body, extra.data.condition, cond_src);
......@@ -1675,10 +1682,10 @@ fn analyzeBodyInner(
16751682 const extra = sema.code.extraData(Zir.Inst.CondBr, inst_data.payload_index);
16761683 const then_body = sema.code.extra[extra.end..][0..extra.data.then_body_len];
16771684 const else_body = sema.code.extra[extra.end + then_body.len ..][0..extra.data.else_body_len];
1678 const cond = sema.resolveInstConst(block, cond_src, extra.data.condition, "condition in comptime branch must be comptime-known") catch |err| {
1679 if (err == error.AnalysisFail and block.comptime_reason != null) try block.comptime_reason.?.explain(sema, sema.err);
1680 return err;
1681 };
1685 const cond = try sema.resolveInstConst(block, cond_src, extra.data.condition, .{
1686 .needed_comptime_reason = "condition in comptime branch must be comptime-known",
1687 .block_comptime_reason = block.comptime_reason,
1688 });
16821689 const inline_body = if (cond.val.toBool()) then_body else else_body;
16831690
16841691 try sema.maybeErrorUnwrapCondbr(block, inline_body, extra.data.condition, cond_src);
......@@ -1708,10 +1715,10 @@ fn analyzeBodyInner(
17081715 }
17091716 const is_non_err = try sema.analyzeIsNonErrComptimeOnly(block, operand_src, err_union);
17101717 assert(is_non_err != .none);
1711 const is_non_err_val = sema.resolveConstValue(block, operand_src, is_non_err, "try operand inside comptime block must be comptime-known") catch |err| {
1712 if (err == error.AnalysisFail and block.comptime_reason != null) try block.comptime_reason.?.explain(sema, sema.err);
1713 return err;
1714 };
1718 const is_non_err_val = try sema.resolveConstValue(block, operand_src, is_non_err, .{
1719 .needed_comptime_reason = "try operand inside comptime block must be comptime-known",
1720 .block_comptime_reason = block.comptime_reason,
1721 });
17151722 if (is_non_err_val.toBool()) {
17161723 break :blk try sema.analyzeErrUnionPayload(block, src, err_union_ty, err_union, operand_src, false);
17171724 }
......@@ -1734,10 +1741,10 @@ fn analyzeBodyInner(
17341741 const err_union = try sema.analyzeLoad(block, src, operand, operand_src);
17351742 const is_non_err = try sema.analyzeIsNonErrComptimeOnly(block, operand_src, err_union);
17361743 assert(is_non_err != .none);
1737 const is_non_err_val = sema.resolveConstValue(block, operand_src, is_non_err, "try operand inside comptime block must be comptime-known") catch |err| {
1738 if (err == error.AnalysisFail and block.comptime_reason != null) try block.comptime_reason.?.explain(sema, sema.err);
1739 return err;
1740 };
1744 const is_non_err_val = try sema.resolveConstValue(block, operand_src, is_non_err, .{
1745 .needed_comptime_reason = "try operand inside comptime block must be comptime-known",
1746 .block_comptime_reason = block.comptime_reason,
1747 });
17411748 if (is_non_err_val.toBool()) {
17421749 break :blk try sema.analyzeErrUnionPayloadPtr(block, src, operand, false, false);
17431750 }
......@@ -1757,7 +1764,7 @@ fn analyzeBodyInner(
17571764 else => |e| return e,
17581765 };
17591766 if (break_inst != defer_body[defer_body.len - 1]) break always_noreturn;
1760 break :blk Air.Inst.Ref.void_value;
1767 break :blk .void_value;
17611768 },
17621769 .defer_err_code => blk: {
17631770 const inst_data = sema.code.instructions.items(.data)[inst].defer_err_code;
......@@ -1770,7 +1777,7 @@ fn analyzeBodyInner(
17701777 else => |e| return e,
17711778 };
17721779 if (break_inst != defer_body[defer_body.len - 1]) break always_noreturn;
1773 break :blk Air.Inst.Ref.void_value;
1780 break :blk .void_value;
17741781 },
17751782 };
17761783 if (sema.isNoReturn(air_inst)) {
......@@ -1819,7 +1826,7 @@ pub fn resolveInst(sema: *Sema, zir_ref: Zir.Inst.Ref) !Air.Inst.Ref {
18191826 const i = @intFromEnum(zir_ref);
18201827 // First section of indexes correspond to a set number of constant values.
18211828 // We intentionally map the same indexes to the same values between ZIR and AIR.
1822 if (i < InternPool.static_len) return @as(Air.Inst.Ref, @enumFromInt(i));
1829 if (i < InternPool.static_len) return @enumFromInt(i);
18231830 // The last section of indexes refers to the map of ZIR => AIR.
18241831 const inst = sema.inst_map.get(i - InternPool.static_len).?;
18251832 if (inst == .generic_poison) return error.GenericPoison;
......@@ -1831,7 +1838,7 @@ fn resolveConstBool(
18311838 block: *Block,
18321839 src: LazySrcLoc,
18331840 zir_ref: Zir.Inst.Ref,
1834 reason: []const u8,
1841 reason: NeededComptimeReason,
18351842) !bool {
18361843 const air_inst = try sema.resolveInst(zir_ref);
18371844 const wanted_type = Type.bool;
......@@ -1845,7 +1852,7 @@ pub fn resolveConstString(
18451852 block: *Block,
18461853 src: LazySrcLoc,
18471854 zir_ref: Zir.Inst.Ref,
1848 reason: []const u8,
1855 reason: NeededComptimeReason,
18491856) ![]u8 {
18501857 const air_inst = try sema.resolveInst(zir_ref);
18511858 const wanted_type = Type.slice_const_u8;
......@@ -1859,7 +1866,7 @@ pub fn resolveConstStringIntern(
18591866 block: *Block,
18601867 src: LazySrcLoc,
18611868 zir_ref: Zir.Inst.Ref,
1862 reason: []const u8,
1869 reason: NeededComptimeReason,
18631870) !InternPool.NullTerminatedString {
18641871 const air_inst = try sema.resolveInst(zir_ref);
18651872 const wanted_type = Type.slice_const_u8;
......@@ -1905,7 +1912,7 @@ fn resolveDestType(
19051912 try sema.errNote(block, src, msg, "use @as to provide explicit result type", .{});
19061913 break :msg msg;
19071914 };
1908 return sema.failWithOwnedErrorMsg(msg);
1915 return sema.failWithOwnedErrorMsg(block, msg);
19091916 },
19101917 else => |e| return e,
19111918 };
......@@ -1931,7 +1938,9 @@ fn analyzeAsType(
19311938) !Type {
19321939 const wanted_type = Type.type;
19331940 const coerced_inst = try sema.coerce(block, wanted_type, air_inst, src);
1934 const val = try sema.resolveConstValue(block, src, coerced_inst, "types must be comptime-known");
1941 const val = try sema.resolveConstValue(block, src, coerced_inst, .{
1942 .needed_comptime_reason = "types must be comptime-known",
1943 });
19351944 return val.toType();
19361945}
19371946
......@@ -1984,7 +1993,7 @@ fn resolveValue(
19841993 block: *Block,
19851994 src: LazySrcLoc,
19861995 air_ref: Air.Inst.Ref,
1987 reason: []const u8,
1996 reason: NeededComptimeReason,
19881997) CompileError!Value {
19891998 if (try sema.resolveMaybeUndefValAllowVariables(air_ref)) |val| {
19901999 if (val.isGenericPoison()) return error.GenericPoison;
......@@ -2000,7 +2009,7 @@ fn resolveConstMaybeUndefVal(
20002009 block: *Block,
20012010 src: LazySrcLoc,
20022011 inst: Air.Inst.Ref,
2003 reason: []const u8,
2012 reason: NeededComptimeReason,
20042013) CompileError!Value {
20052014 if (try sema.resolveMaybeUndefValAllowVariables(inst)) |val| {
20062015 if (val.isGenericPoison()) return error.GenericPoison;
......@@ -2018,7 +2027,7 @@ fn resolveConstValue(
20182027 block: *Block,
20192028 src: LazySrcLoc,
20202029 air_ref: Air.Inst.Ref,
2021 reason: []const u8,
2030 reason: NeededComptimeReason,
20222031) CompileError!Value {
20232032 if (try sema.resolveMaybeUndefValAllowVariables(air_ref)) |val| {
20242033 if (val.isGenericPoison()) return error.GenericPoison;
......@@ -2037,7 +2046,7 @@ fn resolveConstLazyValue(
20372046 block: *Block,
20382047 src: LazySrcLoc,
20392048 air_ref: Air.Inst.Ref,
2040 reason: []const u8,
2049 reason: NeededComptimeReason,
20412050) CompileError!Value {
20422051 return sema.resolveLazyValue(try sema.resolveConstValue(block, src, air_ref, reason));
20432052}
......@@ -2140,15 +2149,18 @@ fn resolveMaybeUndefValAllowVariablesMaybeRuntime(
21402149 return val;
21412150}
21422151
2143fn failWithNeededComptime(sema: *Sema, block: *Block, src: LazySrcLoc, reason: []const u8) CompileError {
2152fn failWithNeededComptime(sema: *Sema, block: *Block, src: LazySrcLoc, reason: NeededComptimeReason) CompileError {
21442153 const msg = msg: {
21452154 const msg = try sema.errMsg(block, src, "unable to resolve comptime value", .{});
21462155 errdefer msg.destroy(sema.gpa);
2156 try sema.errNote(block, src, msg, "{s}", .{reason.needed_comptime_reason});
21472157
2148 try sema.errNote(block, src, msg, "{s}", .{reason});
2158 if (reason.block_comptime_reason) |block_comptime_reason| {
2159 try block_comptime_reason.explain(sema, msg);
2160 }
21492161 break :msg msg;
21502162 };
2151 return sema.failWithOwnedErrorMsg(msg);
2163 return sema.failWithOwnedErrorMsg(block, msg);
21522164}
21532165
21542166fn failWithUseOfUndef(sema: *Sema, block: *Block, src: LazySrcLoc) CompileError {
......@@ -2181,7 +2193,7 @@ fn failWithArrayInitNotSupported(sema: *Sema, block: *Block, src: LazySrcLoc, ty
21812193 }
21822194 break :msg msg;
21832195 };
2184 return sema.failWithOwnedErrorMsg(msg);
2196 return sema.failWithOwnedErrorMsg(block, msg);
21852197}
21862198
21872199fn failWithStructInitNotSupported(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) CompileError {
......@@ -2213,7 +2225,7 @@ fn failWithIntegerOverflow(sema: *Sema, block: *Block, src: LazySrcLoc, int_ty:
22132225 try sema.errNote(block, src, msg, "when computing vector element at index '{d}'", .{vector_index});
22142226 break :msg msg;
22152227 };
2216 return sema.failWithOwnedErrorMsg(msg);
2228 return sema.failWithOwnedErrorMsg(block, msg);
22172229 }
22182230 return sema.fail(block, src, "overflow of integer type '{}' with value '{}'", .{
22192231 int_ty.fmt(sema.mod), val.fmtValue(int_ty, sema.mod),
......@@ -2234,7 +2246,7 @@ fn failWithInvalidComptimeFieldStore(sema: *Sema, block: *Block, init_src: LazyS
22342246 try mod.errNoteNonLazy(default_value_src, msg, "default value set here", .{});
22352247 break :msg msg;
22362248 };
2237 return sema.failWithOwnedErrorMsg(msg);
2249 return sema.failWithOwnedErrorMsg(block, msg);
22382250}
22392251
22402252fn failWithUseOfAsync(sema: *Sema, block: *Block, src: LazySrcLoc) CompileError {
......@@ -2243,7 +2255,7 @@ fn failWithUseOfAsync(sema: *Sema, block: *Block, src: LazySrcLoc) CompileError
22432255 errdefer msg.destroy(sema.gpa);
22442256 break :msg msg;
22452257 };
2246 return sema.failWithOwnedErrorMsg(msg);
2258 return sema.failWithOwnedErrorMsg(block, msg);
22472259}
22482260
22492261fn failWithInvalidFieldAccess(
......@@ -2265,7 +2277,7 @@ fn failWithInvalidFieldAccess(
22652277 try sema.errNote(block, src, msg, "consider using '.?', 'orelse', or 'if'", .{});
22662278 break :msg msg;
22672279 };
2268 return sema.failWithOwnedErrorMsg(msg);
2280 return sema.failWithOwnedErrorMsg(block, msg);
22692281 } else if (inner_ty.zigTypeTag(mod) == .ErrorUnion) err: {
22702282 const child_ty = inner_ty.errorUnionPayload(mod);
22712283 if (!typeSupportsFieldAccess(mod, child_ty, field_name)) break :err;
......@@ -2275,7 +2287,7 @@ fn failWithInvalidFieldAccess(
22752287 try sema.errNote(block, src, msg, "consider using 'try', 'catch', or 'if'", .{});
22762288 break :msg msg;
22772289 };
2278 return sema.failWithOwnedErrorMsg(msg);
2290 return sema.failWithOwnedErrorMsg(block, msg);
22792291 }
22802292 return sema.fail(block, src, "type '{}' does not support field access", .{object_ty.fmt(sema.mod)});
22812293}
......@@ -2376,78 +2388,77 @@ pub fn fail(
23762388 args: anytype,
23772389) CompileError {
23782390 const err_msg = try sema.errMsg(block, src, format, args);
2379 return sema.failWithOwnedErrorMsg(err_msg);
2391 return sema.failWithOwnedErrorMsg(block, err_msg);
23802392}
23812393
2382fn failWithOwnedErrorMsg(sema: *Sema, err_msg: *Module.ErrorMsg) CompileError {
2394fn failWithOwnedErrorMsg(sema: *Sema, block: ?*Block, err_msg: *Module.ErrorMsg) CompileError {
23832395 @setCold(true);
23842396 const gpa = sema.gpa;
23852397 const mod = sema.mod;
23862398
2387 if (crash_report.is_enabled and mod.comp.debug_compile_errors) {
2388 if (err_msg.src_loc.lazy == .unneeded) return error.NeededSourceLocation;
2389 var wip_errors: std.zig.ErrorBundle.Wip = undefined;
2390 wip_errors.init(gpa) catch unreachable;
2391 Compilation.addModuleErrorMsg(mod, &wip_errors, err_msg.*) catch unreachable;
2392 std.debug.print("compile error during Sema:\n", .{});
2393 var error_bundle = wip_errors.toOwnedBundle("") catch unreachable;
2394 error_bundle.renderToStdErr(.{ .ttyconf = .no_color });
2395 crash_report.compilerPanic("unexpected compile error occurred", null, null);
2396 }
2397
23982399 ref: {
23992400 errdefer err_msg.destroy(gpa);
2400 if (err_msg.src_loc.lazy == .unneeded) {
2401 return error.NeededSourceLocation;
2401 if (err_msg.src_loc.lazy == .unneeded) return error.NeededSourceLocation;
2402
2403 if (crash_report.is_enabled and mod.comp.debug_compile_errors) {
2404 var wip_errors: std.zig.ErrorBundle.Wip = undefined;
2405 wip_errors.init(gpa) catch unreachable;
2406 Compilation.addModuleErrorMsg(mod, &wip_errors, err_msg.*) catch unreachable;
2407 std.debug.print("compile error during Sema:\n", .{});
2408 var error_bundle = wip_errors.toOwnedBundle("") catch unreachable;
2409 error_bundle.renderToStdErr(.{ .ttyconf = .no_color });
2410 crash_report.compilerPanic("unexpected compile error occurred", null, null);
24022411 }
2412
24032413 try mod.failed_decls.ensureUnusedCapacity(gpa, 1);
24042414 try mod.failed_files.ensureUnusedCapacity(gpa, 1);
24052415
2406 const max_references = blk: {
2407 if (mod.comp.reference_trace) |num| break :blk num;
2408 // Do not add multiple traces without explicit request.
2409 if (mod.failed_decls.count() != 0) break :ref;
2410 break :blk default_reference_trace_len;
2411 };
2416 if (block) |start_block| {
2417 var block_it = start_block;
2418 while (block_it.inlining) |inlining| {
2419 try sema.errNote(
2420 inlining.call_block,
2421 inlining.call_src,
2422 err_msg,
2423 "called from here",
2424 .{},
2425 );
2426 block_it = inlining.call_block;
2427 }
24122428
2413 var referenced_by = if (sema.owner_func_index != .none)
2414 mod.funcOwnerDeclIndex(sema.owner_func_index)
2415 else
2416 sema.owner_decl_index;
2417 var reference_stack = std.ArrayList(Module.ErrorMsg.Trace).init(gpa);
2418 defer reference_stack.deinit();
2419
2420 // Avoid infinite loops.
2421 var seen = std.AutoHashMap(Decl.Index, void).init(gpa);
2422 defer seen.deinit();
2423
2424 var cur_reference_trace: u32 = 0;
2425 while (sema.mod.reference_table.get(referenced_by)) |ref| : (cur_reference_trace += 1) {
2426 const gop = try seen.getOrPut(ref.referencer);
2427 if (gop.found_existing) break;
2428 if (cur_reference_trace < max_references) {
2429 const decl = sema.mod.declPtr(ref.referencer);
2430 try reference_stack.append(.{
2431 .decl = decl.name.toOptional(),
2432 .src_loc = ref.src.toSrcLoc(decl, mod),
2433 });
2429 const max_references = refs: {
2430 if (mod.comp.reference_trace) |num| break :refs num;
2431 // Do not add multiple traces without explicit request.
2432 if (mod.failed_decls.count() > 0) break :ref;
2433 break :refs default_reference_trace_len;
2434 };
2435
2436 var referenced_by = if (sema.owner_func_index != .none)
2437 mod.funcOwnerDeclIndex(sema.owner_func_index)
2438 else
2439 sema.owner_decl_index;
2440 var reference_stack = std.ArrayList(Module.ErrorMsg.Trace).init(gpa);
2441 defer reference_stack.deinit();
2442
2443 // Avoid infinite loops.
2444 var seen = std.AutoHashMap(Decl.Index, void).init(gpa);
2445 defer seen.deinit();
2446
2447 while (mod.reference_table.get(referenced_by)) |ref| {
2448 const gop = try seen.getOrPut(ref.referencer);
2449 if (gop.found_existing) break;
2450 if (reference_stack.items.len < max_references) {
2451 const decl = mod.declPtr(ref.referencer);
2452 try reference_stack.append(.{
2453 .decl = decl.name,
2454 .src_loc = ref.src.toSrcLoc(decl, mod),
2455 });
2456 }
2457 referenced_by = ref.referencer;
24342458 }
2435 referenced_by = ref.referencer;
2436 }
2437 if (sema.mod.comp.reference_trace == null and cur_reference_trace > 0) {
2438 try reference_stack.append(.{
2439 .decl = .none,
2440 .src_loc = undefined,
2441 .hidden = 0,
2442 });
2443 } else if (cur_reference_trace > max_references) {
2444 try reference_stack.append(.{
2445 .decl = undefined,
2446 .src_loc = undefined,
2447 .hidden = cur_reference_trace - max_references,
2448 });
2459 err_msg.reference_trace = try reference_stack.toOwnedSlice();
2460 err_msg.hidden_references = @intCast(seen.count() -| max_references);
24492461 }
2450 err_msg.reference_trace = try reference_stack.toOwnedSlice();
24512462 }
24522463 const ip = &mod.intern_pool;
24532464 if (sema.owner_func_index != .none) {
......@@ -2507,8 +2518,10 @@ fn analyzeAsAlign(
25072518 src: LazySrcLoc,
25082519 air_ref: Air.Inst.Ref,
25092520) !Alignment {
2510 const alignment_big = try sema.analyzeAsInt(block, src, air_ref, align_ty, "alignment must be comptime-known");
2511 const alignment = @as(u32, @intCast(alignment_big)); // We coerce to u29 in the prev line.
2521 const alignment_big = try sema.analyzeAsInt(block, src, air_ref, align_ty, .{
2522 .needed_comptime_reason = "alignment must be comptime-known",
2523 });
2524 const alignment: u32 = @intCast(alignment_big); // We coerce to u29 in the prev line.
25122525 try sema.validateAlign(block, src, alignment);
25132526 return Alignment.fromNonzeroByteUnits(alignment);
25142527}
......@@ -2543,7 +2556,7 @@ fn resolveInt(
25432556 src: LazySrcLoc,
25442557 zir_ref: Zir.Inst.Ref,
25452558 dest_ty: Type,
2546 reason: []const u8,
2559 reason: NeededComptimeReason,
25472560) !u64 {
25482561 const air_ref = try sema.resolveInst(zir_ref);
25492562 return sema.analyzeAsInt(block, src, air_ref, dest_ty, reason);
......@@ -2555,7 +2568,7 @@ fn analyzeAsInt(
25552568 src: LazySrcLoc,
25562569 air_ref: Air.Inst.Ref,
25572570 dest_ty: Type,
2558 reason: []const u8,
2571 reason: NeededComptimeReason,
25592572) !u64 {
25602573 const mod = sema.mod;
25612574 const coerced = try sema.coerce(block, dest_ty, air_ref, src);
......@@ -2570,7 +2583,7 @@ pub fn resolveInstConst(
25702583 block: *Block,
25712584 src: LazySrcLoc,
25722585 zir_ref: Zir.Inst.Ref,
2573 reason: []const u8,
2586 reason: NeededComptimeReason,
25742587) CompileError!TypedValue {
25752588 const air_ref = try sema.resolveInst(zir_ref);
25762589 const val = try sema.resolveConstValue(block, src, air_ref, reason);
......@@ -2587,7 +2600,7 @@ pub fn resolveInstValue(
25872600 block: *Block,
25882601 src: LazySrcLoc,
25892602 zir_ref: Zir.Inst.Ref,
2590 reason: []const u8,
2603 reason: NeededComptimeReason,
25912604) CompileError!TypedValue {
25922605 const air_ref = try sema.resolveInst(zir_ref);
25932606 const val = try sema.resolveValue(block, src, air_ref, reason);
......@@ -2742,7 +2755,7 @@ fn coerceResultPtr(
27422755 if (pointee_ty.eql(Type.null, sema.mod)) {
27432756 const null_inst = Air.internedToRef(Value.null.toIntern());
27442757 _ = try block.addBinOp(.store, new_ptr, null_inst);
2745 return Air.Inst.Ref.void_value;
2758 return .void_value;
27462759 }
27472760 return sema.bitCast(block, ptr_ty, new_ptr, src, null);
27482761 }
......@@ -2815,7 +2828,7 @@ pub fn analyzeStructDecl(
28152828 const struct_obj = mod.structPtr(struct_index);
28162829 const extended = sema.code.instructions.items(.data)[inst].extended;
28172830 assert(extended.opcode == .struct_decl);
2818 const small = @as(Zir.Inst.StructDecl.Small, @bitCast(extended.small));
2831 const small: Zir.Inst.StructDecl.Small = @bitCast(extended.small);
28192832
28202833 struct_obj.known_non_opv = small.known_non_opv;
28212834 if (small.known_comptime_only) {
......@@ -2852,9 +2865,9 @@ fn zirStructDecl(
28522865) CompileError!Air.Inst.Ref {
28532866 const mod = sema.mod;
28542867 const gpa = sema.gpa;
2855 const small = @as(Zir.Inst.StructDecl.Small, @bitCast(extended.small));
2868 const small: Zir.Inst.StructDecl.Small = @bitCast(extended.small);
28562869 const src: LazySrcLoc = if (small.has_src_node) blk: {
2857 const node_offset = @as(i32, @bitCast(sema.code.extra[extended.operand]));
2870 const node_offset: i32 = @bitCast(sema.code.extra[extended.operand]);
28582871 break :blk LazySrcLoc.nodeOffset(node_offset);
28592872 } else sema.src;
28602873
......@@ -2972,7 +2985,7 @@ fn createAnonymousDeclTypeNamed(
29722985 // If not then this is a struct type being returned from a non-generic
29732986 // function and the name doesn't matter since it will later
29742987 // result in a compile error.
2975 const arg_val = sema.resolveConstMaybeUndefVal(block, .unneeded, arg, "") catch
2988 const arg_val = sema.resolveConstMaybeUndefVal(block, .unneeded, arg, undefined) catch
29762989 return sema.createAnonymousDeclTypeNamed(block, src, typed_value, .anon, anon_prefix, null);
29772990
29782991 if (arg_i != 0) try writer.writeByte(',');
......@@ -3214,20 +3227,22 @@ fn zirEnumDecl(
32143227 try sema.errNote(block, other_field_src, msg, "other field here", .{});
32153228 break :msg msg;
32163229 };
3217 return sema.failWithOwnedErrorMsg(msg);
3230 return sema.failWithOwnedErrorMsg(block, msg);
32183231 }
32193232
32203233 const tag_overflow = if (has_tag_value) overflow: {
3221 const tag_val_ref = @as(Zir.Inst.Ref, @enumFromInt(sema.code.extra[extra_index]));
3234 const tag_val_ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_index]);
32223235 extra_index += 1;
32233236 const tag_inst = try sema.resolveInst(tag_val_ref);
3224 last_tag_val = sema.resolveConstValue(block, .unneeded, tag_inst, "") catch |err| switch (err) {
3237 last_tag_val = sema.resolveConstValue(block, .unneeded, tag_inst, undefined) catch |err| switch (err) {
32253238 error.NeededSourceLocation => {
32263239 const value_src = mod.fieldSrcLoc(new_decl_index, .{
32273240 .index = field_i,
32283241 .range = .value,
32293242 }).lazy;
3230 _ = try sema.resolveConstValue(block, value_src, tag_inst, "enum tag value must be comptime-known");
3243 _ = try sema.resolveConstValue(block, value_src, tag_inst, .{
3244 .needed_comptime_reason = "enum tag value must be comptime-known",
3245 });
32313246 unreachable;
32323247 },
32333248 else => |e| return e,
......@@ -3246,7 +3261,7 @@ fn zirEnumDecl(
32463261 try sema.errNote(block, other_field_src, msg, "other occurrence here", .{});
32473262 break :msg msg;
32483263 };
3249 return sema.failWithOwnedErrorMsg(msg);
3264 return sema.failWithOwnedErrorMsg(block, msg);
32503265 }
32513266 break :overflow false;
32523267 } else if (any_values) overflow: {
......@@ -3265,7 +3280,7 @@ fn zirEnumDecl(
32653280 try sema.errNote(block, other_field_src, msg, "other occurrence here", .{});
32663281 break :msg msg;
32673282 };
3268 return sema.failWithOwnedErrorMsg(msg);
3283 return sema.failWithOwnedErrorMsg(block, msg);
32693284 }
32703285 break :overflow false;
32713286 } else overflow: {
......@@ -3283,7 +3298,7 @@ fn zirEnumDecl(
32833298 const msg = try sema.errMsg(block, value_src, "enumeration value '{}' too large for type '{}'", .{
32843299 last_tag_val.?.fmtValue(int_tag_ty, mod), int_tag_ty.fmt(mod),
32853300 });
3286 return sema.failWithOwnedErrorMsg(msg);
3301 return sema.failWithOwnedErrorMsg(block, msg);
32873302 }
32883303 }
32893304 return decl_val;
......@@ -3300,11 +3315,11 @@ fn zirUnionDecl(
33003315
33013316 const mod = sema.mod;
33023317 const gpa = sema.gpa;
3303 const small = @as(Zir.Inst.UnionDecl.Small, @bitCast(extended.small));
3318 const small: Zir.Inst.UnionDecl.Small = @bitCast(extended.small);
33043319 var extra_index: usize = extended.operand;
33053320
33063321 const src: LazySrcLoc = if (small.has_src_node) blk: {
3307 const node_offset = @as(i32, @bitCast(sema.code.extra[extra_index]));
3322 const node_offset: i32 = @bitCast(sema.code.extra[extra_index]);
33083323 extra_index += 1;
33093324 break :blk LazySrcLoc.nodeOffset(node_offset);
33103325 } else sema.src;
......@@ -3398,11 +3413,11 @@ fn zirOpaqueDecl(
33983413 defer tracy.end();
33993414
34003415 const mod = sema.mod;
3401 const small = @as(Zir.Inst.OpaqueDecl.Small, @bitCast(extended.small));
3416 const small: Zir.Inst.OpaqueDecl.Small = @bitCast(extended.small);
34023417 var extra_index: usize = extended.operand;
34033418
34043419 const src: LazySrcLoc = if (small.has_src_node) blk: {
3405 const node_offset = @as(i32, @bitCast(sema.code.extra[extra_index]));
3420 const node_offset: i32 = @bitCast(sema.code.extra[extra_index]);
34063421 extra_index += 1;
34073422 break :blk LazySrcLoc.nodeOffset(node_offset);
34083423 } else sema.src;
......@@ -3469,7 +3484,7 @@ fn zirErrorSetDecl(
34693484 var names: InferredErrorSet.NameMap = .{};
34703485 try names.ensureUnusedCapacity(sema.arena, extra.data.fields_len);
34713486
3472 var extra_index = @as(u32, @intCast(extra.end));
3487 var extra_index: u32 = @intCast(extra.end);
34733488 const extra_index_end = extra_index + (extra.data.fields_len * 2);
34743489 while (extra_index < extra_index_end) : (extra_index += 2) { // +2 to skip over doc_string
34753490 const str_index = sema.code.extra[extra_index];
......@@ -3556,7 +3571,7 @@ fn ensureResultUsed(
35563571 try sema.errNote(block, src, msg, "consider using 'try', 'catch', or 'if'", .{});
35573572 break :msg msg;
35583573 };
3559 return sema.failWithOwnedErrorMsg(msg);
3574 return sema.failWithOwnedErrorMsg(block, msg);
35603575 },
35613576 else => {
35623577 const msg = msg: {
......@@ -3566,7 +3581,7 @@ fn ensureResultUsed(
35663581 try sema.errNote(block, src, msg, "this error can be suppressed by assigning the value to '_'", .{});
35673582 break :msg msg;
35683583 };
3569 return sema.failWithOwnedErrorMsg(msg);
3584 return sema.failWithOwnedErrorMsg(block, msg);
35703585 },
35713586 }
35723587}
......@@ -3588,7 +3603,7 @@ fn zirEnsureResultNonError(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com
35883603 try sema.errNote(block, src, msg, "consider using 'try', 'catch', or 'if'", .{});
35893604 break :msg msg;
35903605 };
3591 return sema.failWithOwnedErrorMsg(msg);
3606 return sema.failWithOwnedErrorMsg(block, msg);
35923607 },
35933608 else => return,
35943609 }
......@@ -3616,7 +3631,7 @@ fn zirEnsureErrUnionPayloadVoid(sema: *Sema, block: *Block, inst: Zir.Inst.Index
36163631 try sema.errNote(block, src, msg, "payload value can be explicitly ignored with '|_|'", .{});
36173632 break :msg msg;
36183633 };
3619 return sema.failWithOwnedErrorMsg(msg);
3634 return sema.failWithOwnedErrorMsg(block, msg);
36203635 }
36213636}
36223637
......@@ -3669,18 +3684,18 @@ fn zirAllocExtended(
36693684 const extra = sema.code.extraData(Zir.Inst.AllocExtended, extended.operand);
36703685 const ty_src: LazySrcLoc = .{ .node_offset_var_decl_ty = extra.data.src_node };
36713686 const align_src: LazySrcLoc = .{ .node_offset_var_decl_align = extra.data.src_node };
3672 const small = @as(Zir.Inst.AllocExtended.Small, @bitCast(extended.small));
3687 const small: Zir.Inst.AllocExtended.Small = @bitCast(extended.small);
36733688
36743689 var extra_index: usize = extra.end;
36753690
36763691 const var_ty: Type = if (small.has_type) blk: {
3677 const type_ref = @as(Zir.Inst.Ref, @enumFromInt(sema.code.extra[extra_index]));
3692 const type_ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_index]);
36783693 extra_index += 1;
36793694 break :blk try sema.resolveType(block, ty_src, type_ref);
36803695 } else undefined;
36813696
36823697 const alignment = if (small.has_align) blk: {
3683 const align_ref = @as(Zir.Inst.Ref, @enumFromInt(sema.code.extra[extra_index]));
3698 const align_ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_index]);
36843699 extra_index += 1;
36853700 const alignment = try sema.resolveAlign(block, align_src, align_ref);
36863701 break :blk alignment;
......@@ -3698,7 +3713,7 @@ fn zirAllocExtended(
36983713 .is_const = small.is_const,
36993714 } },
37003715 });
3701 return Air.indexToRef(@as(u32, @intCast(sema.air_instructions.len - 1)));
3716 return Air.indexToRef(@intCast(sema.air_instructions.len - 1));
37023717 }
37033718 }
37043719
......@@ -3830,7 +3845,7 @@ fn zirAllocInferredComptime(
38303845 .is_const = is_const,
38313846 } },
38323847 });
3833 return Air.indexToRef(@as(u32, @intCast(sema.air_instructions.len - 1)));
3848 return Air.indexToRef(@intCast(sema.air_instructions.len - 1));
38343849}
38353850
38363851fn zirAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
......@@ -3895,7 +3910,7 @@ fn zirAllocInferred(
38953910 .is_const = is_const,
38963911 } },
38973912 });
3898 return Air.indexToRef(@as(u32, @intCast(sema.air_instructions.len - 1)));
3913 return Air.indexToRef(@intCast(sema.air_instructions.len - 1));
38993914 }
39003915
39013916 const result_index = try block.addInstAsIndex(.{
......@@ -4147,7 +4162,7 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com
41474162 .data = .{ .ty_pl = .{
41484163 .ty = ty_inst,
41494164 .payload = sema.addExtraAssumeCapacity(Air.Block{
4150 .body_len = @as(u32, @intCast(replacement_block.instructions.items.len)),
4165 .body_len = @intCast(replacement_block.instructions.items.len),
41514166 }),
41524167 } },
41534168 });
......@@ -4231,7 +4246,7 @@ fn zirForLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
42314246
42324247 // First pass to look for comptime values.
42334248 for (args, 0..) |zir_arg, i_usize| {
4234 const i = @as(u32, @intCast(i_usize));
4249 const i: u32 = @intCast(i_usize);
42354250 runtime_arg_lens[i] = .none;
42364251 if (zir_arg == .none) continue;
42374252 const object = try sema.resolveInst(zir_arg);
......@@ -4255,7 +4270,7 @@ fn zirForLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
42554270 try sema.errNote(block, arg_src, msg, "for loop operand must be a range, array, slice, tuple, or vector", .{});
42564271 break :msg msg;
42574272 };
4258 return sema.failWithOwnedErrorMsg(msg);
4273 return sema.failWithOwnedErrorMsg(block, msg);
42594274 }
42604275 if (!object_ty.indexableHasLen(mod)) continue;
42614276
......@@ -4284,7 +4299,7 @@ fn zirForLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
42844299 });
42854300 break :msg msg;
42864301 };
4287 return sema.failWithOwnedErrorMsg(msg);
4302 return sema.failWithOwnedErrorMsg(block, msg);
42884303 }
42894304 } else {
42904305 len = arg_len;
......@@ -4302,7 +4317,7 @@ fn zirForLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
43024317 const msg = try sema.errMsg(block, src, "unbounded for loop", .{});
43034318 errdefer msg.destroy(gpa);
43044319 for (args, 0..) |zir_arg, i_usize| {
4305 const i = @as(u32, @intCast(i_usize));
4320 const i: u32 = @intCast(i_usize);
43064321 if (zir_arg == .none) continue;
43074322 const object = try sema.resolveInst(zir_arg);
43084323 const object_ty = sema.typeOf(object);
......@@ -4322,7 +4337,7 @@ fn zirForLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
43224337 }
43234338 break :msg msg;
43244339 };
4325 return sema.failWithOwnedErrorMsg(msg);
4340 return sema.failWithOwnedErrorMsg(block, msg);
43264341 }
43274342
43284343 // Now for the runtime checks.
......@@ -4497,7 +4512,7 @@ fn validateUnionInit(
44974512 try sema.addDeclaredHereNote(msg, union_ty);
44984513 break :msg msg;
44994514 };
4500 return sema.failWithOwnedErrorMsg(msg);
4515 return sema.failWithOwnedErrorMsg(block, msg);
45014516 }
45024517
45034518 if (block.is_comptime and
......@@ -4611,7 +4626,9 @@ fn validateUnionInit(
46114626 try sema.storePtr2(block, init_src, union_ptr, init_src, union_init, init_src, .store);
46124627 return;
46134628 } else if (try sema.typeRequiresComptime(union_ty)) {
4614 return sema.failWithNeededComptime(block, field_ptr_data.src(), "initializer of comptime only union must be comptime-known");
4629 return sema.failWithNeededComptime(block, field_ptr_data.src(), .{
4630 .needed_comptime_reason = "initializer of comptime only union must be comptime-known",
4631 });
46154632 }
46164633
46174634 const new_tag = Air.internedToRef(tag_val.toIntern());
......@@ -4662,7 +4679,7 @@ fn validateStructInit(
46624679 try sema.errNote(block, other_field_src, msg, "other field here", .{});
46634680 break :msg msg;
46644681 };
4665 return sema.failWithOwnedErrorMsg(msg);
4682 return sema.failWithOwnedErrorMsg(block, msg);
46664683 }
46674684 found_fields[field_index.*] = field_ptr;
46684685 }
......@@ -4705,9 +4722,9 @@ fn validateStructInit(
47054722
47064723 const field_src = init_src; // TODO better source location
47074724 const default_field_ptr = if (struct_ty.isTuple(mod))
4708 try sema.tupleFieldPtr(block, init_src, struct_ptr, field_src, @as(u32, @intCast(i)), true)
4725 try sema.tupleFieldPtr(block, init_src, struct_ptr, field_src, @intCast(i), true)
47094726 else
4710 try sema.structFieldPtrByIndex(block, init_src, struct_ptr, @as(u32, @intCast(i)), field_src, struct_ty, true);
4727 try sema.structFieldPtrByIndex(block, init_src, struct_ptr, @intCast(i), field_src, struct_ty, true);
47114728 const init = Air.internedToRef(default_val.toIntern());
47124729 try sema.storePtr2(block, init_src, default_field_ptr, init_src, init, field_src, .store);
47134730 }
......@@ -4723,7 +4740,7 @@ fn validateStructInit(
47234740 );
47244741 }
47254742 root_msg = null;
4726 return sema.failWithOwnedErrorMsg(msg);
4743 return sema.failWithOwnedErrorMsg(block, msg);
47274744 }
47284745
47294746 return;
......@@ -4806,7 +4823,9 @@ fn validateStructInit(
48064823 field_values[i] = val.toIntern();
48074824 } else if (require_comptime) {
48084825 const field_ptr_data = sema.code.instructions.items(.data)[field_ptr].pl_node;
4809 return sema.failWithNeededComptime(block, field_ptr_data.src(), "initializer of comptime only struct must be comptime-known");
4826 return sema.failWithNeededComptime(block, field_ptr_data.src(), .{
4827 .needed_comptime_reason = "initializer of comptime only struct must be comptime-known",
4828 });
48104829 } else {
48114830 struct_is_comptime = false;
48124831 }
......@@ -4851,7 +4870,7 @@ fn validateStructInit(
48514870 );
48524871 }
48534872 root_msg = null;
4854 return sema.failWithOwnedErrorMsg(msg);
4873 return sema.failWithOwnedErrorMsg(block, msg);
48554874 }
48564875
48574876 if (struct_is_comptime) {
......@@ -4911,9 +4930,9 @@ fn validateStructInit(
49114930
49124931 const field_src = init_src; // TODO better source location
49134932 const default_field_ptr = if (struct_ty.isTuple(mod))
4914 try sema.tupleFieldPtr(block, init_src, struct_ptr, field_src, @as(u32, @intCast(i)), true)
4933 try sema.tupleFieldPtr(block, init_src, struct_ptr, field_src, @intCast(i), true)
49154934 else
4916 try sema.structFieldPtrByIndex(block, init_src, struct_ptr, @as(u32, @intCast(i)), field_src, struct_ty, true);
4935 try sema.structFieldPtrByIndex(block, init_src, struct_ptr, @intCast(i), field_src, struct_ty, true);
49174936 const init = Air.internedToRef(field_values[i]);
49184937 try sema.storePtr2(block, init_src, default_field_ptr, init_src, init, field_src, .store);
49194938 }
......@@ -4955,7 +4974,7 @@ fn zirValidateArrayInit(
49554974
49564975 if (root_msg) |msg| {
49574976 root_msg = null;
4958 return sema.failWithOwnedErrorMsg(msg);
4977 return sema.failWithOwnedErrorMsg(block, msg);
49594978 }
49604979 },
49614980 .Array => {
......@@ -5168,7 +5187,7 @@ fn zirValidateDeref(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr
51685187 try sema.explainWhyTypeIsComptime(msg, src.toSrcLoc(src_decl, mod), elem_ty);
51695188 break :msg msg;
51705189 };
5171 return sema.failWithOwnedErrorMsg(msg);
5190 return sema.failWithOwnedErrorMsg(block, msg);
51725191 }
51735192}
51745193
......@@ -5200,7 +5219,7 @@ fn failWithBadMemberAccess(
52005219 try sema.addDeclaredHereNote(msg, agg_ty);
52015220 break :msg msg;
52025221 };
5203 return sema.failWithOwnedErrorMsg(msg);
5222 return sema.failWithOwnedErrorMsg(block, msg);
52045223}
52055224
52065225fn failWithBadStructFieldAccess(
......@@ -5226,7 +5245,7 @@ fn failWithBadStructFieldAccess(
52265245 try mod.errNoteNonLazy(struct_obj.srcLoc(mod), msg, "struct declared here", .{});
52275246 break :msg msg;
52285247 };
5229 return sema.failWithOwnedErrorMsg(msg);
5248 return sema.failWithOwnedErrorMsg(block, msg);
52305249}
52315250
52325251fn failWithBadUnionFieldAccess(
......@@ -5253,7 +5272,7 @@ fn failWithBadUnionFieldAccess(
52535272 try mod.errNoteNonLazy(decl.srcLoc(mod), msg, "union declared here", .{});
52545273 break :msg msg;
52555274 };
5256 return sema.failWithOwnedErrorMsg(msg);
5275 return sema.failWithOwnedErrorMsg(block, msg);
52575276}
52585277
52595278fn addDeclaredHereNote(sema: *Sema, parent: *Module.ErrorMsg, decl_ty: Type) !void {
......@@ -5331,13 +5350,17 @@ fn storeToInferredAllocComptime(
53315350 return;
53325351 }
53335352
5334 return sema.failWithNeededComptime(block, src, "value being stored to a comptime variable must be comptime-known");
5353 return sema.failWithNeededComptime(block, src, .{
5354 .needed_comptime_reason = "value being stored to a comptime variable must be comptime-known",
5355 });
53355356}
53365357
53375358fn zirSetEvalBranchQuota(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void {
53385359 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
53395360 const src = inst_data.src();
5340 const quota = @as(u32, @intCast(try sema.resolveInt(block, src, inst_data.operand, Type.u32, "eval branch quota must be comptime-known")));
5361 const quota: u32 = @intCast(try sema.resolveInt(block, src, inst_data.operand, Type.u32, .{
5362 .needed_comptime_reason = "eval branch quota must be comptime-known",
5363 }));
53415364 sema.branch_quota = @max(sema.branch_quota, quota);
53425365}
53435366
......@@ -5479,7 +5502,9 @@ fn zirCompileError(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
54795502 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
54805503 const src = inst_data.src();
54815504 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
5482 const msg = try sema.resolveConstString(block, operand_src, inst_data.operand, "compile error string must be comptime-known");
5505 const msg = try sema.resolveConstString(block, operand_src, inst_data.operand, .{
5506 .needed_comptime_reason = "compile error string must be comptime-known",
5507 });
54835508 return sema.fail(block, src, "{s}", .{msg});
54845509}
54855510
......@@ -5520,7 +5545,7 @@ fn zirCompileLog(
55205545 if (!gop.found_existing) {
55215546 gop.value_ptr.* = src_node;
55225547 }
5523 return Air.Inst.Ref.void_value;
5548 return .void_value;
55245549}
55255550
55265551fn zirPanic(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Zir.Inst.Index {
......@@ -5558,7 +5583,7 @@ fn zirLoop(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError
55585583 // Reserve space for a Loop instruction so that generated Break instructions can
55595584 // point to it, even if it doesn't end up getting used because the code ends up being
55605585 // comptime evaluated.
5561 const block_inst = @as(Air.Inst.Index, @intCast(sema.air_instructions.len));
5586 const block_inst: Air.Inst.Index = @intCast(sema.air_instructions.len);
55625587 const loop_inst = block_inst + 1;
55635588 try sema.air_instructions.ensureUnusedCapacity(gpa, 2);
55645589 sema.air_instructions.appendAssumeCapacity(.{
......@@ -5606,7 +5631,7 @@ fn zirLoop(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError
56065631
56075632 try sema.air_extra.ensureUnusedCapacity(gpa, @typeInfo(Air.Block).Struct.fields.len + loop_block_len);
56085633 sema.air_instructions.items(.data)[loop_inst].ty_pl.payload = sema.addExtraAssumeCapacity(
5609 Air.Block{ .body_len = @as(u32, @intCast(loop_block_len)) },
5634 Air.Block{ .body_len = @intCast(loop_block_len) },
56105635 );
56115636 sema.air_extra.appendSliceAssumeCapacity(loop_block.instructions.items);
56125637 }
......@@ -5713,7 +5738,7 @@ fn zirCImport(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileEr
57135738 }
57145739 break :msg msg;
57155740 };
5716 return sema.failWithOwnedErrorMsg(msg);
5741 return sema.failWithOwnedErrorMsg(&child_block, msg);
57175742 }
57185743 const c_import_pkg = Package.create(
57195744 sema.gpa,
......@@ -5756,7 +5781,7 @@ fn zirBlock(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index, force_compt
57565781 // Reserve space for a Block instruction so that generated Break instructions can
57575782 // point to it, even if it doesn't end up getting used because the code ends up being
57585783 // comptime evaluated or is an unlabeled block.
5759 const block_inst = @as(Air.Inst.Index, @intCast(sema.air_instructions.len));
5784 const block_inst: Air.Inst.Index = @intCast(sema.air_instructions.len);
57605785 try sema.air_instructions.append(gpa, .{
57615786 .tag = .block,
57625787 .data = undefined,
......@@ -5894,7 +5919,7 @@ fn analyzeBlockBody(
58945919
58955920 break :msg msg;
58965921 };
5897 return sema.failWithOwnedErrorMsg(msg);
5922 return sema.failWithOwnedErrorMsg(child_block, msg);
58985923 }
58995924 const ty_inst = Air.internedToRef(resolved_ty.toIntern());
59005925 try sema.air_extra.ensureUnusedCapacity(gpa, @typeInfo(Air.Block).Struct.fields.len +
......@@ -5902,7 +5927,7 @@ fn analyzeBlockBody(
59025927 sema.air_instructions.items(.data)[merges.block_inst] = .{ .ty_pl = .{
59035928 .ty = ty_inst,
59045929 .payload = sema.addExtraAssumeCapacity(Air.Block{
5905 .body_len = @as(u32, @intCast(child_block.instructions.items.len)),
5930 .body_len = @intCast(child_block.instructions.items.len),
59065931 }),
59075932 } };
59085933 sema.air_extra.appendSliceAssumeCapacity(child_block.instructions.items);
......@@ -5929,15 +5954,15 @@ fn analyzeBlockBody(
59295954
59305955 // Convert the br instruction to a block instruction that has the coercion
59315956 // and then a new br inside that returns the coerced instruction.
5932 const sub_block_len = @as(u32, @intCast(coerce_block.instructions.items.len + 1));
5957 const sub_block_len: u32 = @intCast(coerce_block.instructions.items.len + 1);
59335958 try sema.air_extra.ensureUnusedCapacity(gpa, @typeInfo(Air.Block).Struct.fields.len +
59345959 sub_block_len);
59355960 try sema.air_instructions.ensureUnusedCapacity(gpa, 1);
5936 const sub_br_inst = @as(Air.Inst.Index, @intCast(sema.air_instructions.len));
5961 const sub_br_inst: Air.Inst.Index = @intCast(sema.air_instructions.len);
59375962
59385963 sema.air_instructions.items(.tag)[br] = .block;
59395964 sema.air_instructions.items(.data)[br] = .{ .ty_pl = .{
5940 .ty = Air.Inst.Ref.noreturn_type,
5965 .ty = .noreturn_type,
59415966 .payload = sema.addExtraAssumeCapacity(Air.Block{
59425967 .body_len = sub_block_len,
59435968 }),
......@@ -6001,7 +6026,9 @@ fn zirExportValue(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
60016026 const src = inst_data.src();
60026027 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
60036028 const options_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };
6004 const operand = try sema.resolveInstConst(block, operand_src, extra.operand, "export target must be comptime-known");
6029 const operand = try sema.resolveInstConst(block, operand_src, extra.operand, .{
6030 .needed_comptime_reason = "export target must be comptime-known",
6031 });
60056032 const options = sema.resolveExportOptions(block, .unneeded, extra.options) catch |err| switch (err) {
60066033 error.NeededSourceLocation => {
60076034 _ = try sema.resolveExportOptions(block, options_src, extra.options);
......@@ -6045,7 +6072,7 @@ pub fn analyzeExport(
60456072 try sema.addDeclaredHereNote(msg, exported_decl.ty);
60466073 break :msg msg;
60476074 };
6048 return sema.failWithOwnedErrorMsg(msg);
6075 return sema.failWithOwnedErrorMsg(block, msg);
60496076 }
60506077
60516078 // TODO: some backends might support re-exporting extern decls
......@@ -6122,7 +6149,7 @@ fn zirSetAlignStack(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.Inst
61226149 try sema.errNote(block, prev_src, msg, "other instance here", .{});
61236150 break :msg msg;
61246151 };
6125 return sema.failWithOwnedErrorMsg(msg);
6152 return sema.failWithOwnedErrorMsg(block, msg);
61266153 }
61276154
61286155 const ip = &mod.intern_pool;
......@@ -6140,7 +6167,9 @@ fn zirSetCold(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData)
61406167 const ip = &mod.intern_pool;
61416168 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;
61426169 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node };
6143 const is_cold = try sema.resolveConstBool(block, operand_src, extra.operand, "operand to @setCold must be comptime-known");
6170 const is_cold = try sema.resolveConstBool(block, operand_src, extra.operand, .{
6171 .needed_comptime_reason = "operand to @setCold must be comptime-known",
6172 });
61446173 if (sema.func_index == .none) return; // does nothing outside a function
61456174 ip.funcAnalysis(sema.func_index).is_cold = is_cold;
61466175}
......@@ -6148,13 +6177,17 @@ fn zirSetCold(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData)
61486177fn zirSetFloatMode(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!void {
61496178 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;
61506179 const src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node };
6151 block.float_mode = try sema.resolveBuiltinEnum(block, src, extra.operand, "FloatMode", "operand to @setFloatMode must be comptime-known");
6180 block.float_mode = try sema.resolveBuiltinEnum(block, src, extra.operand, "FloatMode", .{
6181 .needed_comptime_reason = "operand to @setFloatMode must be comptime-known",
6182 });
61526183}
61536184
61546185fn zirSetRuntimeSafety(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void {
61556186 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
61566187 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
6157 block.want_safety = try sema.resolveConstBool(block, operand_src, inst_data.operand, "operand to @setRuntimeSafety must be comptime-known");
6188 block.want_safety = try sema.resolveConstBool(block, operand_src, inst_data.operand, .{
6189 .needed_comptime_reason = "operand to @setRuntimeSafety must be comptime-known",
6190 });
61586191}
61596192
61606193fn zirFence(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!void {
......@@ -6162,7 +6195,9 @@ fn zirFence(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) Co
61626195
61636196 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;
61646197 const order_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node };
6165 const order = try sema.resolveAtomicOrder(block, order_src, extra.operand, "atomic order of @fence must be comptime-known");
6198 const order = try sema.resolveAtomicOrder(block, order_src, extra.operand, .{
6199 .needed_comptime_reason = "atomic order of @fence must be comptime-known",
6200 });
61666201
61676202 if (@intFromEnum(order) < @intFromEnum(std.builtin.AtomicOrder.Acquire)) {
61686203 return sema.fail(block, order_src, "atomic ordering must be Acquire or stricter", .{});
......@@ -6291,7 +6326,7 @@ fn addDbgVar(
62916326 try sema.queueFullTypeResolution(operand_ty);
62926327
62936328 // Add the name to the AIR.
6294 const name_extra_index = @as(u32, @intCast(sema.air_extra.items.len));
6329 const name_extra_index: u32 = @intCast(sema.air_extra.items.len);
62956330 const elements_used = name.len / 4 + 1;
62966331 try sema.air_extra.ensureUnusedCapacity(sema.gpa, elements_used);
62976332 const buffer = mem.sliceAsBytes(sema.air_extra.unusedCapacitySlice());
......@@ -6431,7 +6466,7 @@ fn lookupInNamespace(
64316466 }
64326467 break :msg msg;
64336468 };
6434 return sema.failWithOwnedErrorMsg(msg);
6469 return sema.failWithOwnedErrorMsg(block, msg);
64356470 },
64366471 }
64376472 } else if (namespace.decls.getKeyAdapted(ident_name, Module.DeclAdapter{ .mod = mod })) |decl_index| {
......@@ -6491,7 +6526,7 @@ pub fn analyzeSaveErrRetIndex(sema: *Sema, block: *Block) SemaError!Air.Inst.Ref
64916526 .tag = .save_err_return_trace_index,
64926527 .data = .{ .ty_pl = .{
64936528 .ty = Air.internedToRef(stack_trace_ty.toIntern()),
6494 .payload = @as(u32, @intCast(field_index)),
6529 .payload = @intCast(field_index),
64956530 } },
64966531 });
64976532}
......@@ -6535,7 +6570,7 @@ fn popErrorReturnTrace(
65356570 .tag = .block,
65366571 .data = .{
65376572 .ty_pl = .{
6538 .ty = Air.Inst.Ref.void_type,
6573 .ty = .void_type,
65396574 .payload = undefined, // updated below
65406575 },
65416576 },
......@@ -6552,23 +6587,23 @@ fn popErrorReturnTrace(
65526587 const field_name = try mod.intern_pool.getOrPutString(gpa, "index");
65536588 const field_ptr = try sema.structFieldPtr(&then_block, src, err_return_trace, field_name, src, stack_trace_ty, true);
65546589 try sema.storePtr2(&then_block, src, field_ptr, src, saved_error_trace_index, src, .store);
6555 _ = try then_block.addBr(cond_block_inst, Air.Inst.Ref.void_value);
6590 _ = try then_block.addBr(cond_block_inst, .void_value);
65566591
65576592 // Otherwise, do nothing
65586593 var else_block = block.makeSubBlock();
65596594 defer else_block.instructions.deinit(gpa);
6560 _ = try else_block.addBr(cond_block_inst, Air.Inst.Ref.void_value);
6595 _ = try else_block.addBr(cond_block_inst, .void_value);
65616596
65626597 try sema.air_extra.ensureUnusedCapacity(gpa, @typeInfo(Air.CondBr).Struct.fields.len +
65636598 then_block.instructions.items.len + else_block.instructions.items.len +
65646599 @typeInfo(Air.Block).Struct.fields.len + 1); // +1 for the sole .cond_br instruction in the .block
65656600
6566 const cond_br_inst = @as(Air.Inst.Index, @intCast(sema.air_instructions.len));
6601 const cond_br_inst: Air.Inst.Index = @intCast(sema.air_instructions.len);
65676602 try sema.air_instructions.append(gpa, .{ .tag = .cond_br, .data = .{ .pl_op = .{
65686603 .operand = is_non_error_inst,
65696604 .payload = sema.addExtraAssumeCapacity(Air.CondBr{
6570 .then_body_len = @as(u32, @intCast(then_block.instructions.items.len)),
6571 .else_body_len = @as(u32, @intCast(else_block.instructions.items.len)),
6605 .then_body_len = @intCast(then_block.instructions.items.len),
6606 .else_body_len = @intCast(else_block.instructions.items.len),
65726607 }),
65736608 } } });
65746609 sema.air_extra.appendSliceAssumeCapacity(then_block.instructions.items);
......@@ -6599,7 +6634,7 @@ fn zirCall(
65996634 const extra = sema.code.extraData(ExtraType, inst_data.payload_index);
66006635 const args_len = extra.data.flags.args_len;
66016636
6602 const modifier = @as(std.builtin.CallModifier, @enumFromInt(extra.data.flags.packed_modifier));
6637 const modifier: std.builtin.CallModifier = @enumFromInt(extra.data.flags.packed_modifier);
66036638 const ensure_result_used = extra.data.flags.ensure_result_used;
66046639 const pop_error_return_trace = extra.data.flags.pop_error_return_trace;
66056640
......@@ -6678,7 +6713,7 @@ fn zirCall(
66786713 .tag = .save_err_return_trace_index,
66796714 .data = .{ .ty_pl = .{
66806715 .ty = Air.internedToRef(stack_trace_ty.toIntern()),
6681 .payload = @as(u32, @intCast(field_index)),
6716 .payload = @intCast(field_index),
66826717 } },
66836718 });
66846719
......@@ -6725,7 +6760,7 @@ fn checkCallArgumentCount(
67256760 try sema.errNote(block, func_src, msg, "consider using '.?', 'orelse' or 'if'", .{});
67266761 break :msg msg;
67276762 };
6728 return sema.failWithOwnedErrorMsg(msg);
6763 return sema.failWithOwnedErrorMsg(block, msg);
67296764 }
67306765 },
67316766 else => {},
......@@ -6763,7 +6798,7 @@ fn checkCallArgumentCount(
67636798 if (maybe_decl) |fn_decl| try mod.errNoteNonLazy(fn_decl.srcLoc(mod), msg, "function declared here", .{});
67646799 break :msg msg;
67656800 };
6766 return sema.failWithOwnedErrorMsg(msg);
6801 return sema.failWithOwnedErrorMsg(block, msg);
67676802}
67686803
67696804fn callBuiltin(
......@@ -7097,7 +7132,7 @@ fn analyzeCall(
70977132 if (maybe_decl) |fn_decl| try mod.errNoteNonLazy(fn_decl.srcLoc(mod), msg, "function declared here", .{});
70987133 break :msg msg;
70997134 };
7100 return sema.failWithOwnedErrorMsg(msg);
7135 return sema.failWithOwnedErrorMsg(block, msg);
71017136 }
71027137
71037138 const call_tag: Air.Inst.Tag = switch (modifier) {
......@@ -7156,7 +7191,7 @@ fn analyzeCall(
71567191 }
71577192 break :msg msg;
71587193 };
7159 return sema.failWithOwnedErrorMsg(msg);
7194 return sema.failWithOwnedErrorMsg(block, msg);
71607195 }
71617196
71627197 if (!is_inline_call and is_generic_call) {
......@@ -7194,10 +7229,10 @@ fn analyzeCall(
71947229 }
71957230
71967231 const result: Air.Inst.Ref = if (is_inline_call) res: {
7197 const func_val = sema.resolveConstValue(block, func_src, func, "function being called at comptime must be comptime-known") catch |err| {
7198 if (err == error.AnalysisFail and comptime_reason != null) try comptime_reason.?.explain(sema, sema.err);
7199 return err;
7200 };
7232 const func_val = try sema.resolveConstValue(block, func_src, func, .{
7233 .needed_comptime_reason = "function being called at comptime must be comptime-known",
7234 .block_comptime_reason = comptime_reason,
7235 });
72017236 const module_fn_index = switch (mod.intern_pool.indexToKey(func_val.toIntern())) {
72027237 .extern_func => return sema.fail(block, call_src, "{s} call of extern function", .{
72037238 @as([]const u8, if (is_comptime_call) "comptime" else "inline"),
......@@ -7225,7 +7260,7 @@ fn analyzeCall(
72257260 // set to in the `Block`.
72267261 // This block instruction will be used to capture the return value from the
72277262 // inlined function.
7228 const block_inst = @as(Air.Inst.Index, @intCast(sema.air_instructions.len));
7263 const block_inst: Air.Inst.Index = @intCast(sema.air_instructions.len);
72297264 try sema.air_instructions.append(gpa, .{
72307265 .tag = .block,
72317266 .data = undefined,
......@@ -7233,7 +7268,10 @@ fn analyzeCall(
72337268 // This one is shared among sub-blocks within the same callee, but not
72347269 // shared among the entire inline/comptime call stack.
72357270 var inlining: Block.Inlining = .{
7236 .func = .none,
7271 .call_block = block,
7272 .call_src = call_src,
7273 .has_comptime_args = false,
7274 .func = module_fn_index,
72377275 .comptime_result = undefined,
72387276 .merges = .{
72397277 .src_locs = .{},
......@@ -7317,7 +7355,6 @@ fn analyzeCall(
73177355 const fn_info = ics.callee().code.getFnInfo(module_fn.zir_body_inst);
73187356 try ics.callee().inst_map.ensureSpaceForInstructions(gpa, fn_info.param_body);
73197357
7320 var has_comptime_args = false;
73217358 var arg_i: u32 = 0;
73227359 for (fn_info.param_body) |inst| {
73237360 const opt_noreturn_ref = try analyzeInlineCallArg(
......@@ -7333,7 +7370,6 @@ fn analyzeCall(
73337370 memoized_arg_values,
73347371 func_ty_info,
73357372 func,
7336 &has_comptime_args,
73377373 );
73387374 if (opt_noreturn_ref) |ref| {
73397375 // Analyzing this argument gave a ref of a noreturn type. Terminate argument analysis here.
......@@ -7345,19 +7381,19 @@ fn analyzeCall(
73457381 // can just use `sema` directly.
73467382 _ = ics.callee();
73477383
7348 if (!has_comptime_args and module_fn.analysis(ip).state == .sema_failure)
7349 return error.AnalysisFail;
7384 if (!inlining.has_comptime_args) {
7385 if (module_fn.analysis(ip).state == .sema_failure)
7386 return error.AnalysisFail;
73507387
7351 const recursive_msg = "inline call is recursive";
7352 var head = if (!has_comptime_args) block else null;
7353 while (head) |some| {
7354 const parent_inlining = some.inlining orelse break;
7355 if (parent_inlining.func == module_fn_index) {
7356 return sema.fail(block, call_src, recursive_msg, .{});
7388 var block_it = block;
7389 while (block_it.inlining) |parent_inlining| {
7390 if (!parent_inlining.has_comptime_args and parent_inlining.func == module_fn_index) {
7391 const err_msg = try sema.errMsg(block, call_src, "inline call is recursive", .{});
7392 return sema.failWithOwnedErrorMsg(null, err_msg);
7393 }
7394 block_it = parent_inlining.call_block;
73577395 }
7358 head = some.parent;
73597396 }
7360 if (!has_comptime_args) inlining.func = module_fn_index;
73617397
73627398 // In case it is a generic function with an expression for the return type that depends
73637399 // on parameters, we must now do the same for the return type as we just did with
......@@ -7427,12 +7463,6 @@ fn analyzeCall(
74277463 const result = result: {
74287464 sema.analyzeBody(&child_block, fn_info.body) catch |err| switch (err) {
74297465 error.ComptimeReturn => break :result inlining.comptime_result,
7430 error.AnalysisFail => {
7431 const err_msg = sema.err orelse return err;
7432 if (mem.eql(u8, err_msg.msg, recursive_msg)) return err;
7433 try sema.errNote(block, call_src, err_msg, "called from here", .{});
7434 return err;
7435 },
74367466 else => |e| return e,
74377467 };
74387468 break :result try sema.analyzeBlockBody(block, call_src, &child_block, merges);
......@@ -7451,7 +7481,7 @@ fn analyzeCall(
74517481 }
74527482
74537483 if (should_memoize and is_comptime_call) {
7454 const result_val = try sema.resolveConstMaybeUndefVal(block, .unneeded, result, "");
7484 const result_val = try sema.resolveConstMaybeUndefVal(block, .unneeded, result, undefined);
74557485 const result_interned = try result_val.intern2(sema.fn_ret_ty, mod);
74567486
74577487 // Transform ad-hoc inferred error set types into concrete error sets.
......@@ -7523,7 +7553,7 @@ fn analyzeCall(
75237553 .data = .{ .pl_op = .{
75247554 .operand = func,
75257555 .payload = sema.addExtraAssumeCapacity(Air.Call{
7526 .args_len = @as(u32, @intCast(args.len)),
7556 .args_len = @intCast(args.len),
75277557 }),
75287558 } },
75297559 });
......@@ -7549,11 +7579,11 @@ fn analyzeCall(
75497579 }
75507580 }
75517581 try sema.safetyPanic(block, call_src, .noreturn_returned);
7552 return Air.Inst.Ref.unreachable_value;
7582 return .unreachable_value;
75537583 }
75547584 if (func_ty_info.return_type == .noreturn_type) {
75557585 _ = try block.addNoOp(.unreach);
7556 return Air.Inst.Ref.unreachable_value;
7586 return .unreachable_value;
75577587 }
75587588 break :res func_inst;
75597589 };
......@@ -7580,7 +7610,7 @@ fn handleTailCall(sema: *Sema, block: *Block, call_src: LazySrcLoc, func_ty: Typ
75807610 });
75817611 }
75827612 _ = try block.addUnOp(.ret, result);
7583 return Air.Inst.Ref.unreachable_value;
7613 return .unreachable_value;
75847614}
75857615
75867616/// Usually, returns null. If an argument was noreturn, returns that ref (which should become the call result).
......@@ -7597,13 +7627,12 @@ fn analyzeInlineCallArg(
75977627 memoized_arg_values: []InternPool.Index,
75987628 func_ty_info: InternPool.Key.FuncType,
75997629 func_inst: Air.Inst.Ref,
7600 has_comptime_args: *bool,
76017630) !?Air.Inst.Ref {
76027631 const mod = ics.sema.mod;
76037632 const ip = &mod.intern_pool;
76047633 const zir_tags = ics.callee().code.instructions.items(.tag);
76057634 switch (zir_tags[inst]) {
7606 .param_comptime, .param_anytype_comptime => has_comptime_args.* = true,
7635 .param_comptime, .param_anytype_comptime => param_block.inlining.?.has_comptime_args = true,
76077636 else => {},
76087637 }
76097638 switch (zir_tags[inst]) {
......@@ -7628,20 +7657,22 @@ fn analyzeInlineCallArg(
76287657 }
76297658 const arg_src = args_info.argSrc(arg_block, arg_i.*);
76307659 if (try ics.callee().typeRequiresComptime(param_ty.toType())) {
7631 _ = ics.caller().resolveConstMaybeUndefVal(arg_block, arg_src, casted_arg, "argument to parameter with comptime-only type must be comptime-known") catch |err| {
7632 if (err == error.AnalysisFail and param_block.comptime_reason != null) try param_block.comptime_reason.?.explain(ics.caller(), ics.caller().err);
7633 return err;
7634 };
7660 _ = try ics.caller().resolveConstMaybeUndefVal(arg_block, arg_src, casted_arg, .{
7661 .needed_comptime_reason = "argument to parameter with comptime-only type must be comptime-known",
7662 .block_comptime_reason = param_block.comptime_reason,
7663 });
76357664 } else if (!is_comptime_call and zir_tags[inst] == .param_comptime) {
7636 _ = try ics.caller().resolveConstMaybeUndefVal(arg_block, arg_src, casted_arg, "parameter is comptime");
7665 _ = try ics.caller().resolveConstMaybeUndefVal(arg_block, arg_src, casted_arg, .{
7666 .needed_comptime_reason = "parameter is comptime",
7667 });
76377668 }
76387669
76397670 if (is_comptime_call) {
76407671 ics.callee().inst_map.putAssumeCapacityNoClobber(inst, casted_arg);
7641 const arg_val = ics.caller().resolveConstMaybeUndefVal(arg_block, arg_src, casted_arg, "argument to function being called at comptime must be comptime-known") catch |err| {
7642 if (err == error.AnalysisFail and param_block.comptime_reason != null) try param_block.comptime_reason.?.explain(ics.caller(), ics.caller().err);
7643 return err;
7644 };
7672 const arg_val = try ics.caller().resolveConstMaybeUndefVal(arg_block, arg_src, casted_arg, .{
7673 .needed_comptime_reason = "argument to function being called at comptime must be comptime-known",
7674 .block_comptime_reason = param_block.comptime_reason,
7675 });
76457676 switch (arg_val.toIntern()) {
76467677 .generic_poison, .generic_poison_type => {
76477678 // This function is currently evaluated as part of an as-of-yet unresolvable
......@@ -7661,7 +7692,7 @@ fn analyzeInlineCallArg(
76617692 }
76627693
76637694 if (try ics.caller().resolveMaybeUndefVal(casted_arg)) |_| {
7664 has_comptime_args.* = true;
7695 param_block.inlining.?.has_comptime_args = true;
76657696 }
76667697
76677698 arg_i.* += 1;
......@@ -7677,10 +7708,10 @@ fn analyzeInlineCallArg(
76777708
76787709 if (is_comptime_call) {
76797710 ics.callee().inst_map.putAssumeCapacityNoClobber(inst, uncasted_arg);
7680 const arg_val = ics.caller().resolveConstMaybeUndefVal(arg_block, arg_src, uncasted_arg, "argument to function being called at comptime must be comptime-known") catch |err| {
7681 if (err == error.AnalysisFail and param_block.comptime_reason != null) try param_block.comptime_reason.?.explain(ics.caller(), ics.caller().err);
7682 return err;
7683 };
7711 const arg_val = try ics.caller().resolveConstMaybeUndefVal(arg_block, arg_src, uncasted_arg, .{
7712 .needed_comptime_reason = "argument to function being called at comptime must be comptime-known",
7713 .block_comptime_reason = param_block.comptime_reason,
7714 });
76847715 switch (arg_val.toIntern()) {
76857716 .generic_poison, .generic_poison_type => {
76867717 // This function is currently evaluated as part of an as-of-yet unresolvable
......@@ -7697,13 +7728,15 @@ fn analyzeInlineCallArg(
76977728 memoized_arg_values[arg_i.*] = try resolved_arg_val.intern(ics.caller().typeOf(uncasted_arg), mod);
76987729 } else {
76997730 if (zir_tags[inst] == .param_anytype_comptime) {
7700 _ = try ics.caller().resolveConstMaybeUndefVal(arg_block, arg_src, uncasted_arg, "parameter is comptime");
7731 _ = try ics.caller().resolveConstMaybeUndefVal(arg_block, arg_src, uncasted_arg, .{
7732 .needed_comptime_reason = "parameter is comptime",
7733 });
77017734 }
77027735 ics.callee().inst_map.putAssumeCapacityNoClobber(inst, uncasted_arg);
77037736 }
77047737
77057738 if (try ics.caller().resolveMaybeUndefVal(uncasted_arg)) |_| {
7706 has_comptime_args.* = true;
7739 param_block.inlining.?.has_comptime_args = true;
77077740 }
77087741
77097742 arg_i.* += 1;
......@@ -7744,7 +7777,9 @@ fn instantiateGenericCall(
77447777 const gpa = sema.gpa;
77457778 const ip = &mod.intern_pool;
77467779
7747 const func_val = try sema.resolveConstValue(block, func_src, func, "generic function being called must be comptime-known");
7780 const func_val = try sema.resolveConstValue(block, func_src, func, .{
7781 .needed_comptime_reason = "generic function being called must be comptime-known",
7782 });
77487783 const generic_owner = switch (mod.intern_pool.indexToKey(func_val.toIntern())) {
77497784 .func => func_val.toIntern(),
77507785 .ptr => |ptr| mod.declPtr(ptr.addr.decl).val.toIntern(),
......@@ -7891,7 +7926,7 @@ fn instantiateGenericCall(
78917926 } else switch (param_tag) {
78927927 .param_comptime,
78937928 .param_anytype_comptime,
7894 => return sema.failWithOwnedErrorMsg(msg: {
7929 => return sema.failWithOwnedErrorMsg(block, msg: {
78957930 const arg_src = args_info.argSrc(block, arg_index);
78967931 const msg = try sema.errMsg(block, arg_src, "runtime-known argument passed to comptime parameter", .{});
78977932 errdefer msg.destroy(sema.gpa);
......@@ -7906,7 +7941,7 @@ fn instantiateGenericCall(
79067941
79077942 .param,
79087943 .param_anytype,
7909 => return sema.failWithOwnedErrorMsg(msg: {
7944 => return sema.failWithOwnedErrorMsg(block, msg: {
79107945 const arg_src = args_info.argSrc(block, arg_index);
79117946 const msg = try sema.errMsg(block, arg_src, "runtime-known argument passed to parameter of comptime-only type", .{});
79127947 errdefer msg.destroy(sema.gpa);
......@@ -8010,7 +8045,7 @@ fn instantiateGenericCall(
80108045 }
80118046 if (func_ty.fnReturnType(mod).isNoReturn(mod)) {
80128047 _ = try block.addNoOp(.unreach);
8013 return Air.Inst.Ref.unreachable_value;
8048 return .unreachable_value;
80148049 }
80158050 return result;
80168051}
......@@ -8146,7 +8181,9 @@ fn zirVectorType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
81468181 const elem_type_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
81478182 const len_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };
81488183 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
8149 const len = @as(u32, @intCast(try sema.resolveInt(block, len_src, extra.lhs, Type.u32, "vector length must be comptime-known")));
8184 const len: u32 = @intCast(try sema.resolveInt(block, len_src, extra.lhs, Type.u32, .{
8185 .needed_comptime_reason = "vector length must be comptime-known",
8186 }));
81508187 const elem_type = try sema.resolveType(block, elem_type_src, extra.rhs);
81518188 try sema.checkVectorElemType(block, elem_type_src, elem_type);
81528189 const vector_type = try mod.vectorType(.{
......@@ -8164,7 +8201,9 @@ fn zirArrayType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
81648201 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
81658202 const len_src: LazySrcLoc = .{ .node_offset_array_type_len = inst_data.src_node };
81668203 const elem_src: LazySrcLoc = .{ .node_offset_array_type_elem = inst_data.src_node };
8167 const len = try sema.resolveInt(block, len_src, extra.lhs, Type.usize, "array length must be comptime-known");
8204 const len = try sema.resolveInt(block, len_src, extra.lhs, Type.usize, .{
8205 .needed_comptime_reason = "array length must be comptime-known",
8206 });
81688207 const elem_type = try sema.resolveType(block, elem_src, extra.rhs);
81698208 try sema.validateArrayElemType(block, elem_type, elem_src);
81708209 const array_ty = try sema.mod.arrayType(.{
......@@ -8184,12 +8223,16 @@ fn zirArrayTypeSentinel(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compil
81848223 const len_src: LazySrcLoc = .{ .node_offset_array_type_len = inst_data.src_node };
81858224 const sentinel_src: LazySrcLoc = .{ .node_offset_array_type_sentinel = inst_data.src_node };
81868225 const elem_src: LazySrcLoc = .{ .node_offset_array_type_elem = inst_data.src_node };
8187 const len = try sema.resolveInt(block, len_src, extra.len, Type.usize, "array length must be comptime-known");
8226 const len = try sema.resolveInt(block, len_src, extra.len, Type.usize, .{
8227 .needed_comptime_reason = "array length must be comptime-known",
8228 });
81888229 const elem_type = try sema.resolveType(block, elem_src, extra.elem_type);
81898230 try sema.validateArrayElemType(block, elem_type, elem_src);
81908231 const uncasted_sentinel = try sema.resolveInst(extra.sentinel);
81918232 const sentinel = try sema.coerce(block, elem_type, uncasted_sentinel, sentinel_src);
8192 const sentinel_val = try sema.resolveConstValue(block, sentinel_src, sentinel, "array sentinel value must be comptime-known");
8233 const sentinel_val = try sema.resolveConstValue(block, sentinel_src, sentinel, .{
8234 .needed_comptime_reason = "array sentinel value must be comptime-known",
8235 });
81938236 const array_ty = try sema.mod.arrayType(.{
81948237 .len = len,
81958238 .sentinel = sentinel_val.toIntern(),
......@@ -8347,7 +8390,7 @@ fn zirErrorFromInt(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstD
83478390 return block.addInst(.{
83488391 .tag = .bitcast,
83498392 .data = .{ .ty_op = .{
8350 .ty = Air.Inst.Ref.anyerror_type,
8393 .ty = .anyerror_type,
83518394 .operand = operand,
83528395 } },
83538396 });
......@@ -8373,7 +8416,7 @@ fn zirMergeErrorSets(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr
83738416 try sema.errNote(block, src, msg, "'||' merges error sets; 'or' performs boolean OR", .{});
83748417 break :msg msg;
83758418 };
8376 return sema.failWithOwnedErrorMsg(msg);
8419 return sema.failWithOwnedErrorMsg(block, msg);
83778420 }
83788421 const lhs_ty = try sema.analyzeAsType(block, lhs_src, lhs);
83798422 const rhs_ty = try sema.analyzeAsType(block, rhs_src, rhs);
......@@ -8384,7 +8427,7 @@ fn zirMergeErrorSets(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr
83848427
83858428 // Anything merged with anyerror is anyerror.
83868429 if (lhs_ty.toIntern() == .anyerror_type or rhs_ty.toIntern() == .anyerror_type) {
8387 return Air.Inst.Ref.anyerror_type;
8430 return .anyerror_type;
83888431 }
83898432
83908433 if (ip.isInferredErrorSetType(lhs_ty.toIntern())) {
......@@ -8497,7 +8540,7 @@ fn zirEnumFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
84978540 try sema.addDeclaredHereNote(msg, dest_ty);
84988541 break :msg msg;
84998542 };
8500 return sema.failWithOwnedErrorMsg(msg);
8543 return sema.failWithOwnedErrorMsg(block, msg);
85018544 }
85028545 if (int_val.isUndef(mod)) {
85038546 return sema.failWithUseOfUndef(block, operand_src);
......@@ -8514,7 +8557,7 @@ fn zirEnumFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
85148557 try sema.addDeclaredHereNote(msg, dest_ty);
85158558 break :msg msg;
85168559 };
8517 return sema.failWithOwnedErrorMsg(msg);
8560 return sema.failWithOwnedErrorMsg(block, msg);
85188561 }
85198562 return Air.internedToRef((try mod.getCoerced(int_val, dest_ty)).toIntern());
85208563 }
......@@ -8891,7 +8934,7 @@ fn zirFunc(
88918934 const ret_ty: Type = switch (extra.data.ret_body_len) {
88928935 0 => Type.void,
88938936 1 => blk: {
8894 const ret_ty_ref = @as(Zir.Inst.Ref, @enumFromInt(sema.code.extra[extra_index]));
8937 const ret_ty_ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_index]);
88958938 extra_index += 1;
88968939 if (sema.resolveType(block, ret_ty_src, ret_ty_ref)) |ret_ty| {
88978940 break :blk ret_ty;
......@@ -8906,7 +8949,9 @@ fn zirFunc(
89068949 const ret_ty_body = sema.code.extra[extra_index..][0..extra.data.ret_body_len];
89078950 extra_index += ret_ty_body.len;
89088951
8909 const ret_ty_val = try sema.resolveGenericBody(block, ret_ty_src, ret_ty_body, inst, Type.type, "return type must be comptime-known");
8952 const ret_ty_val = try sema.resolveGenericBody(block, ret_ty_src, ret_ty_body, inst, Type.type, .{
8953 .needed_comptime_reason = "return type must be comptime-known",
8954 });
89108955 break :blk ret_ty_val.toType();
89118956 },
89128957 };
......@@ -8953,7 +8998,7 @@ fn resolveGenericBody(
89538998 body: []const Zir.Inst.Index,
89548999 func_inst: Zir.Inst.Index,
89559000 dest_ty: Type,
8956 reason: []const u8,
9001 reason: NeededComptimeReason,
89579002) !Value {
89589003 assert(body.len != 0);
89599004
......@@ -9089,7 +9134,7 @@ fn checkCallConvSupportsVarArgs(sema: *Sema, block: *Block, src: LazySrcLoc, cc:
90899134 try sema.errNote(block, src, msg, "supported calling conventions: {}", .{CallingConventionsSupportingVarArgsList{}});
90909135 break :msg msg;
90919136 };
9092 return sema.failWithOwnedErrorMsg(msg);
9137 return sema.failWithOwnedErrorMsg(block, msg);
90939138 }
90949139}
90959140
......@@ -9185,7 +9230,7 @@ fn funcCommon(
91859230 try sema.addDeclaredHereNote(msg, param_ty);
91869231 break :msg msg;
91879232 };
9188 return sema.failWithOwnedErrorMsg(msg);
9233 return sema.failWithOwnedErrorMsg(block, msg);
91899234 }
91909235 if (!this_generic and !target_util.fnCallConvAllowsZigTypes(target, cc_resolved) and !try sema.validateExternType(param_ty, .param_ty)) {
91919236 const msg = msg: {
......@@ -9200,7 +9245,7 @@ fn funcCommon(
92009245 try sema.addDeclaredHereNote(msg, param_ty);
92019246 break :msg msg;
92029247 };
9203 return sema.failWithOwnedErrorMsg(msg);
9248 return sema.failWithOwnedErrorMsg(block, msg);
92049249 }
92059250 if (is_source_decl and requires_comptime and !param_is_comptime and has_body) {
92069251 const msg = msg: {
......@@ -9215,7 +9260,7 @@ fn funcCommon(
92159260 try sema.addDeclaredHereNote(msg, param_ty);
92169261 break :msg msg;
92179262 };
9218 return sema.failWithOwnedErrorMsg(msg);
9263 return sema.failWithOwnedErrorMsg(block, msg);
92199264 }
92209265 if (is_source_decl and !this_generic and is_noalias and
92219266 !(param_ty.zigTypeTag(mod) == .Pointer or param_ty.isPtrLikeOptional(mod)))
......@@ -9477,7 +9522,7 @@ fn finishFunc(
94779522 try sema.addDeclaredHereNote(msg, return_type);
94789523 break :msg msg;
94799524 };
9480 return sema.failWithOwnedErrorMsg(msg);
9525 return sema.failWithOwnedErrorMsg(block, msg);
94819526 }
94829527 if (!ret_poison and !target_util.fnCallConvAllowsZigTypes(target, cc_resolved) and
94839528 !try sema.validateExternType(return_type, .ret_ty))
......@@ -9494,7 +9539,7 @@ fn finishFunc(
94949539 try sema.addDeclaredHereNote(msg, return_type);
94959540 break :msg msg;
94969541 };
9497 return sema.failWithOwnedErrorMsg(msg);
9542 return sema.failWithOwnedErrorMsg(block, msg);
94989543 }
94999544
95009545 // If the return type is comptime-only but not dependent on parameters then
......@@ -9534,41 +9579,41 @@ fn finishFunc(
95349579 }
95359580 }
95369581 }
9537 return sema.failWithOwnedErrorMsg(msg);
9582 return sema.failWithOwnedErrorMsg(block, msg);
95389583 }
95399584
95409585 const arch = target.cpu.arch;
9541 if (switch (cc_resolved) {
9586 if (@as(?[]const u8, switch (cc_resolved) {
95429587 .Unspecified, .C, .Naked, .Async, .Inline => null,
95439588 .Interrupt => switch (arch) {
95449589 .x86, .x86_64, .avr, .msp430 => null,
9545 else => @as([]const u8, "x86, x86_64, AVR, and MSP430"),
9590 else => "x86, x86_64, AVR, and MSP430",
95469591 },
95479592 .Signal => switch (arch) {
95489593 .avr => null,
9549 else => @as([]const u8, "AVR"),
9594 else => "AVR",
95509595 },
95519596 .Stdcall, .Fastcall, .Thiscall => switch (arch) {
95529597 .x86 => null,
9553 else => @as([]const u8, "x86"),
9598 else => "x86",
95549599 },
95559600 .Vectorcall => switch (arch) {
95569601 .x86, .aarch64, .aarch64_be, .aarch64_32 => null,
9557 else => @as([]const u8, "x86 and AArch64"),
9602 else => "x86 and AArch64",
95589603 },
95599604 .APCS, .AAPCS, .AAPCSVFP => switch (arch) {
95609605 .arm, .armeb, .aarch64, .aarch64_be, .aarch64_32, .thumb, .thumbeb => null,
9561 else => @as([]const u8, "ARM"),
9606 else => "ARM",
95629607 },
95639608 .SysV, .Win64 => switch (arch) {
95649609 .x86_64 => null,
9565 else => @as([]const u8, "x86_64"),
9610 else => "x86_64",
95669611 },
95679612 .Kernel => switch (arch) {
95689613 .nvptx, .nvptx64, .amdgcn, .spirv32, .spirv64 => null,
9569 else => @as([]const u8, "nvptx, amdgcn and SPIR-V"),
9614 else => "nvptx, amdgcn and SPIR-V",
95709615 },
9571 }) |allowed_platform| {
9616 })) |allowed_platform| {
95729617 return sema.fail(block, cc_src, "callconv '{s}' is only available on {s}, not {s}", .{
95739618 @tagName(cc_resolved),
95749619 allowed_platform,
......@@ -9852,7 +9897,9 @@ fn zirFieldValNamed(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr
98529897 const field_name_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };
98539898 const extra = sema.code.extraData(Zir.Inst.FieldNamed, inst_data.payload_index).data;
98549899 const object = try sema.resolveInst(extra.lhs);
9855 const field_name = try sema.resolveConstStringIntern(block, field_name_src, extra.field_name, "field name must be comptime-known");
9900 const field_name = try sema.resolveConstStringIntern(block, field_name_src, extra.field_name, .{
9901 .needed_comptime_reason = "field name must be comptime-known",
9902 });
98569903 return sema.fieldVal(block, src, object, field_name, field_name_src);
98579904}
98589905
......@@ -9865,7 +9912,9 @@ fn zirFieldPtrNamed(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr
98659912 const field_name_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };
98669913 const extra = sema.code.extraData(Zir.Inst.FieldNamed, inst_data.payload_index).data;
98679914 const object_ptr = try sema.resolveInst(extra.lhs);
9868 const field_name = try sema.resolveConstStringIntern(block, field_name_src, extra.field_name, "field name must be comptime-known");
9915 const field_name = try sema.resolveConstStringIntern(block, field_name_src, extra.field_name, .{
9916 .needed_comptime_reason = "field name must be comptime-known",
9917 });
98699918 return sema.fieldPtr(block, src, object_ptr, field_name, field_name_src, false);
98709919}
98719920
......@@ -10071,7 +10120,7 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1007110120
1007210121 break :msg msg;
1007310122 };
10074 return sema.failWithOwnedErrorMsg(msg);
10123 return sema.failWithOwnedErrorMsg(block, msg);
1007510124 },
1007610125
1007710126 .Pointer => {
......@@ -10086,7 +10135,7 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1008610135
1008710136 break :msg msg;
1008810137 };
10089 return sema.failWithOwnedErrorMsg(msg);
10138 return sema.failWithOwnedErrorMsg(block, msg);
1009010139 },
1009110140 .Struct, .Union => if (dest_ty.containerLayout(mod) == .Auto) {
1009210141 const container = switch (dest_ty.zigTypeTag(mod)) {
......@@ -10135,7 +10184,7 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1013510184
1013610185 break :msg msg;
1013710186 };
10138 return sema.failWithOwnedErrorMsg(msg);
10187 return sema.failWithOwnedErrorMsg(block, msg);
1013910188 },
1014010189 .Pointer => {
1014110190 const msg = msg: {
......@@ -10149,7 +10198,7 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1014910198
1015010199 break :msg msg;
1015110200 };
10152 return sema.failWithOwnedErrorMsg(msg);
10201 return sema.failWithOwnedErrorMsg(block, msg);
1015310202 },
1015410203 .Struct, .Union => if (operand_ty.containerLayout(mod) == .Auto) {
1015510204 const container = switch (operand_ty.zigTypeTag(mod)) {
......@@ -10300,7 +10349,7 @@ fn zirElemPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1030010349 }
1030110350 break :msg msg;
1030210351 };
10303 return sema.failWithOwnedErrorMsg(msg);
10352 return sema.failWithOwnedErrorMsg(block, msg);
1030410353 }
1030510354 return sema.elemPtrOneLayerOnly(block, src, array_ptr, elem_index, src, false, false);
1030610355}
......@@ -10472,7 +10521,7 @@ const SwitchProngAnalysis = struct {
1047210521
1047310522 if (sema.typeOf(capture_ref).isNoReturn(sema.mod)) {
1047410523 // This prong should be unreachable!
10475 return Air.Inst.Ref.unreachable_value;
10524 return .unreachable_value;
1047610525 }
1047710526
1047810527 sema.inst_map.putAssumeCapacity(spa.switch_block_inst, capture_ref);
......@@ -10566,7 +10615,7 @@ const SwitchProngAnalysis = struct {
1056610615 try sema.addDeclaredHereNote(msg, operand_ty);
1056710616 break :msg msg;
1056810617 };
10569 return sema.failWithOwnedErrorMsg(msg);
10618 return sema.failWithOwnedErrorMsg(block, msg);
1057010619 }
1057110620 assert(inline_case_capture != .none);
1057210621 return inline_case_capture;
......@@ -10593,7 +10642,7 @@ const SwitchProngAnalysis = struct {
1059310642 const operand_src: LazySrcLoc = .{ .node_offset_switch_operand = switch_node_offset };
1059410643
1059510644 if (inline_case_capture != .none) {
10596 const item_val = sema.resolveConstValue(block, .unneeded, inline_case_capture, "") catch unreachable;
10645 const item_val = sema.resolveConstValue(block, .unneeded, inline_case_capture, undefined) catch unreachable;
1059710646 if (operand_ty.zigTypeTag(mod) == .Union) {
1059810647 const field_index: u32 = @intCast(operand_ty.unionTagFieldIndex(item_val, mod).?);
1059910648 const union_obj = mod.typeToUnion(operand_ty).?;
......@@ -10641,7 +10690,7 @@ const SwitchProngAnalysis = struct {
1064110690 return sema.bitCast(block, ty, spa.operand, operand_src, null);
1064210691 } else {
1064310692 try block.addUnreachable(operand_src, false);
10644 return Air.Inst.Ref.unreachable_value;
10693 return .unreachable_value;
1064510694 },
1064610695 else => return spa.operand,
1064710696 }
......@@ -10650,14 +10699,14 @@ const SwitchProngAnalysis = struct {
1065010699 switch (operand_ty.zigTypeTag(mod)) {
1065110700 .Union => {
1065210701 const union_obj = mod.typeToUnion(operand_ty).?;
10653 const first_item_val = sema.resolveConstValue(block, .unneeded, case_vals[0], "") catch unreachable;
10702 const first_item_val = sema.resolveConstValue(block, .unneeded, case_vals[0], undefined) catch unreachable;
1065410703
1065510704 const first_field_index: u32 = mod.unionTagFieldIndex(union_obj, first_item_val).?;
1065610705 const first_field_ty = union_obj.field_types.get(ip)[first_field_index].toType();
1065710706
1065810707 const field_tys = try sema.arena.alloc(Type, case_vals.len);
1065910708 for (case_vals, field_tys) |item, *field_ty| {
10660 const item_val = sema.resolveConstValue(block, .unneeded, item, "") catch unreachable;
10709 const item_val = sema.resolveConstValue(block, .unneeded, item, undefined) catch unreachable;
1066110710 const field_idx = mod.unionTagFieldIndex(union_obj, item_val).?;
1066210711 field_ty.* = union_obj.field_types.get(ip)[field_idx].toType();
1066310712 }
......@@ -10684,7 +10733,7 @@ const SwitchProngAnalysis = struct {
1068410733 const multi_idx = raw_capture_src.multi_capture;
1068510734 const src_decl_ptr = sema.mod.declPtr(block.src_decl);
1068610735 for (case_srcs, 0..) |*case_src, i| {
10687 const raw_case_src: Module.SwitchProngSrc = .{ .multi = .{ .prong = multi_idx, .item = @as(u32, @intCast(i)) } };
10736 const raw_case_src: Module.SwitchProngSrc = .{ .multi = .{ .prong = multi_idx, .item = @intCast(i) } };
1068810737 case_src.* = raw_case_src.resolve(mod, src_decl_ptr, switch_node_offset, .none);
1068910738 }
1069010739 const capture_src = raw_capture_src.resolve(mod, src_decl_ptr, switch_node_offset, .none);
......@@ -10732,7 +10781,7 @@ const SwitchProngAnalysis = struct {
1073210781 const multi_idx = raw_capture_src.multi_capture;
1073310782 const src_decl_ptr = sema.mod.declPtr(block.src_decl);
1073410783 const capture_src = raw_capture_src.resolve(mod, src_decl_ptr, switch_node_offset, .none);
10735 const raw_case_src: Module.SwitchProngSrc = .{ .multi = .{ .prong = multi_idx, .item = @as(u32, @intCast(i)) } };
10784 const raw_case_src: Module.SwitchProngSrc = .{ .multi = .{ .prong = multi_idx, .item = @intCast(i) } };
1073610785 const case_src = raw_case_src.resolve(mod, src_decl_ptr, switch_node_offset, .none);
1073710786 const msg = msg: {
1073810787 const msg = try sema.errMsg(block, capture_src, "capture group with incompatible types", .{});
......@@ -10744,7 +10793,7 @@ const SwitchProngAnalysis = struct {
1074410793 try sema.errNote(block, capture_src, msg, "this coercion is only possible when capturing by value", .{});
1074510794 break :msg msg;
1074610795 };
10747 return sema.failWithOwnedErrorMsg(msg);
10796 return sema.failWithOwnedErrorMsg(block, msg);
1074810797 }
1074910798 }
1075010799 }
......@@ -10833,12 +10882,12 @@ const SwitchProngAnalysis = struct {
1083310882 var coerce_block = block.makeSubBlock();
1083410883 defer coerce_block.instructions.deinit(sema.gpa);
1083510884
10836 const uncoerced = try coerce_block.addStructFieldVal(spa.operand, @as(u32, @intCast(idx)), field_tys[idx]);
10885 const uncoerced = try coerce_block.addStructFieldVal(spa.operand, @intCast(idx), field_tys[idx]);
1083710886 const coerced = sema.coerce(&coerce_block, capture_ty, uncoerced, .unneeded) catch |err| switch (err) {
1083810887 error.NeededSourceLocation => {
1083910888 const multi_idx = raw_capture_src.multi_capture;
1084010889 const src_decl_ptr = sema.mod.declPtr(block.src_decl);
10841 const raw_case_src: Module.SwitchProngSrc = .{ .multi = .{ .prong = multi_idx, .item = @as(u32, @intCast(idx)) } };
10890 const raw_case_src: Module.SwitchProngSrc = .{ .multi = .{ .prong = multi_idx, .item = @intCast(idx) } };
1084210891 const case_src = raw_case_src.resolve(mod, src_decl_ptr, switch_node_offset, .none);
1084310892 _ = try sema.coerce(&coerce_block, capture_ty, uncoerced, case_src);
1084410893 unreachable;
......@@ -10849,7 +10898,7 @@ const SwitchProngAnalysis = struct {
1084910898
1085010899 try cases_extra.ensureUnusedCapacity(3 + coerce_block.instructions.items.len);
1085110900 cases_extra.appendAssumeCapacity(1); // items_len
10852 cases_extra.appendAssumeCapacity(@as(u32, @intCast(coerce_block.instructions.items.len))); // body_len
10901 cases_extra.appendAssumeCapacity(@intCast(coerce_block.instructions.items.len)); // body_len
1085310902 cases_extra.appendAssumeCapacity(@intFromEnum(case_vals[idx])); // item
1085410903 cases_extra.appendSliceAssumeCapacity(coerce_block.instructions.items); // body
1085510904 }
......@@ -10860,7 +10909,7 @@ const SwitchProngAnalysis = struct {
1086010909 defer coerce_block.instructions.deinit(sema.gpa);
1086110910
1086210911 const first_imc = in_mem_coercible.findFirstSet().?;
10863 const uncoerced = try coerce_block.addStructFieldVal(spa.operand, @as(u32, @intCast(first_imc)), field_tys[first_imc]);
10912 const uncoerced = try coerce_block.addStructFieldVal(spa.operand, @intCast(first_imc), field_tys[first_imc]);
1086410913 const coerced = try coerce_block.addBitCast(capture_ty, uncoerced);
1086510914 _ = try coerce_block.addBr(capture_block_inst, coerced);
1086610915
......@@ -10873,14 +10922,14 @@ const SwitchProngAnalysis = struct {
1087310922 @typeInfo(Air.Block).Struct.fields.len +
1087410923 1);
1087510924
10876 const switch_br_inst = @as(u32, @intCast(sema.air_instructions.len));
10925 const switch_br_inst: u32 = @intCast(sema.air_instructions.len);
1087710926 try sema.air_instructions.append(sema.gpa, .{
1087810927 .tag = .switch_br,
1087910928 .data = .{ .pl_op = .{
1088010929 .operand = spa.cond,
1088110930 .payload = sema.addExtraAssumeCapacity(Air.SwitchBr{
10882 .cases_len = @as(u32, @intCast(prong_count)),
10883 .else_body_len = @as(u32, @intCast(else_body_len)),
10931 .cases_len = @intCast(prong_count),
10932 .else_body_len = @intCast(else_body_len),
1088410933 }),
1088510934 } },
1088610935 });
......@@ -10906,7 +10955,7 @@ const SwitchProngAnalysis = struct {
1090610955 }
1090710956
1090810957 if (case_vals.len == 1) {
10909 const item_val = sema.resolveConstValue(block, .unneeded, case_vals[0], "") catch unreachable;
10958 const item_val = sema.resolveConstValue(block, .unneeded, case_vals[0], undefined) catch unreachable;
1091010959 const item_ty = try mod.singleErrorSetType(item_val.getErrorName(mod).unwrap().?);
1091110960 return sema.bitCast(block, item_ty, spa.operand, operand_src, null);
1091210961 }
......@@ -10914,7 +10963,7 @@ const SwitchProngAnalysis = struct {
1091410963 var names: InferredErrorSet.NameMap = .{};
1091510964 try names.ensureUnusedCapacity(sema.arena, case_vals.len);
1091610965 for (case_vals) |err| {
10917 const err_val = sema.resolveConstValue(block, .unneeded, err, "") catch unreachable;
10966 const err_val = sema.resolveConstValue(block, .unneeded, err, undefined) catch unreachable;
1091810967 names.putAssumeCapacityNoClobber(err_val.getErrorName(mod).unwrap().?, {});
1091910968 }
1092010969 const error_ty = try mod.errorSetFromUnsortedNames(names.keys());
......@@ -10975,7 +11024,7 @@ fn switchCond(
1097511024 }
1097611025 break :msg msg;
1097711026 };
10978 return sema.failWithOwnedErrorMsg(msg);
11027 return sema.failWithOwnedErrorMsg(block, msg);
1097911028 };
1098011029 return sema.unionToTag(block, enum_ty, operand, src);
1098111030 },
......@@ -11067,7 +11116,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1106711116 .has_tag_capture = false,
1106811117 },
1106911118 .under, .@"else" => blk: {
11070 const info = @as(Zir.Inst.SwitchBlock.ProngInfo, @bitCast(sema.code.extra[header_extra_index]));
11119 const info: Zir.Inst.SwitchBlock.ProngInfo = @bitCast(sema.code.extra[header_extra_index]);
1107111120 const extra_body_start = header_extra_index + 1;
1107211121 break :blk .{
1107311122 .body = sema.code.extra[extra_body_start..][0..info.body_len],
......@@ -11128,7 +11177,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1112811177 );
1112911178 break :msg msg;
1113011179 };
11131 return sema.failWithOwnedErrorMsg(msg);
11180 return sema.failWithOwnedErrorMsg(block, msg);
1113211181 }
1113311182
1113411183 // Validate for duplicate items, missing else prong, and invalid range.
......@@ -11144,9 +11193,9 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1114411193 {
1114511194 var scalar_i: u32 = 0;
1114611195 while (scalar_i < scalar_cases_len) : (scalar_i += 1) {
11147 const item_ref = @as(Zir.Inst.Ref, @enumFromInt(sema.code.extra[extra_index]));
11196 const item_ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_index]);
1114811197 extra_index += 1;
11149 const info = @as(Zir.Inst.SwitchBlock.ProngInfo, @bitCast(sema.code.extra[extra_index]));
11198 const info: Zir.Inst.SwitchBlock.ProngInfo = @bitCast(sema.code.extra[extra_index]);
1115011199 extra_index += 1 + info.body_len;
1115111200
1115211201 case_vals.appendAssumeCapacity(try sema.validateSwitchItemEnum(
......@@ -11167,7 +11216,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1116711216 extra_index += 1;
1116811217 const ranges_len = sema.code.extra[extra_index];
1116911218 extra_index += 1;
11170 const info = @as(Zir.Inst.SwitchBlock.ProngInfo, @bitCast(sema.code.extra[extra_index]));
11219 const info: Zir.Inst.SwitchBlock.ProngInfo = @bitCast(sema.code.extra[extra_index]);
1117111220 extra_index += 1;
1117211221 const items = sema.code.refSlice(extra_index, items_len);
1117311222 extra_index += items_len + info.body_len;
......@@ -11181,7 +11230,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1118111230 item_ref,
1118211231 operand_ty,
1118311232 src_node_offset,
11184 .{ .multi = .{ .prong = multi_i, .item = @as(u32, @intCast(item_i)) } },
11233 .{ .multi = .{ .prong = multi_i, .item = @intCast(item_i) } },
1118511234 ));
1118611235 }
1118711236
......@@ -11228,7 +11277,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1122811277 );
1122911278 break :msg msg;
1123011279 };
11231 return sema.failWithOwnedErrorMsg(msg);
11280 return sema.failWithOwnedErrorMsg(block, msg);
1123211281 } else if (special_prong == .none and operand_ty.isNonexhaustiveEnum(mod) and !union_originally) {
1123311282 return sema.fail(
1123411283 block,
......@@ -11243,9 +11292,9 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1124311292 {
1124411293 var scalar_i: u32 = 0;
1124511294 while (scalar_i < scalar_cases_len) : (scalar_i += 1) {
11246 const item_ref = @as(Zir.Inst.Ref, @enumFromInt(sema.code.extra[extra_index]));
11295 const item_ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_index]);
1124711296 extra_index += 1;
11248 const info = @as(Zir.Inst.SwitchBlock.ProngInfo, @bitCast(sema.code.extra[extra_index]));
11297 const info: Zir.Inst.SwitchBlock.ProngInfo = @bitCast(sema.code.extra[extra_index]);
1124911298 extra_index += 1 + info.body_len;
1125011299
1125111300 case_vals.appendAssumeCapacity(try sema.validateSwitchItemError(
......@@ -11265,7 +11314,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1126511314 extra_index += 1;
1126611315 const ranges_len = sema.code.extra[extra_index];
1126711316 extra_index += 1;
11268 const info = @as(Zir.Inst.SwitchBlock.ProngInfo, @bitCast(sema.code.extra[extra_index]));
11317 const info: Zir.Inst.SwitchBlock.ProngInfo = @bitCast(sema.code.extra[extra_index]);
1126911318 extra_index += 1;
1127011319 const items = sema.code.refSlice(extra_index, items_len);
1127111320 extra_index += items_len + info.body_len;
......@@ -11278,7 +11327,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1127811327 item_ref,
1127911328 operand_ty,
1128011329 src_node_offset,
11281 .{ .multi = .{ .prong = multi_i, .item = @as(u32, @intCast(item_i)) } },
11330 .{ .multi = .{ .prong = multi_i, .item = @intCast(item_i) } },
1128211331 ));
1128311332 }
1128411333
......@@ -11328,7 +11377,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1132811377 if (maybe_msg) |msg| {
1132911378 maybe_msg = null;
1133011379 try sema.addDeclaredHereNote(msg, operand_ty);
11331 return sema.failWithOwnedErrorMsg(msg);
11380 return sema.failWithOwnedErrorMsg(block, msg);
1133211381 }
1133311382
1133411383 if (special_prong == .@"else" and
......@@ -11387,9 +11436,9 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1138711436 {
1138811437 var scalar_i: u32 = 0;
1138911438 while (scalar_i < scalar_cases_len) : (scalar_i += 1) {
11390 const item_ref = @as(Zir.Inst.Ref, @enumFromInt(sema.code.extra[extra_index]));
11439 const item_ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_index]);
1139111440 extra_index += 1;
11392 const info = @as(Zir.Inst.SwitchBlock.ProngInfo, @bitCast(sema.code.extra[extra_index]));
11441 const info: Zir.Inst.SwitchBlock.ProngInfo = @bitCast(sema.code.extra[extra_index]);
1139311442 extra_index += 1 + info.body_len;
1139411443
1139511444 case_vals.appendAssumeCapacity(try sema.validateSwitchItemInt(
......@@ -11409,7 +11458,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1140911458 extra_index += 1;
1141011459 const ranges_len = sema.code.extra[extra_index];
1141111460 extra_index += 1;
11412 const info = @as(Zir.Inst.SwitchBlock.ProngInfo, @bitCast(sema.code.extra[extra_index]));
11461 const info: Zir.Inst.SwitchBlock.ProngInfo = @bitCast(sema.code.extra[extra_index]);
1141311462 extra_index += 1;
1141411463 const items = sema.code.refSlice(extra_index, items_len);
1141511464 extra_index += items_len;
......@@ -11422,16 +11471,16 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1142211471 item_ref,
1142311472 operand_ty,
1142411473 src_node_offset,
11425 .{ .multi = .{ .prong = multi_i, .item = @as(u32, @intCast(item_i)) } },
11474 .{ .multi = .{ .prong = multi_i, .item = @intCast(item_i) } },
1142611475 ));
1142711476 }
1142811477
1142911478 try case_vals.ensureUnusedCapacity(gpa, 2 * ranges_len);
1143011479 var range_i: u32 = 0;
1143111480 while (range_i < ranges_len) : (range_i += 1) {
11432 const item_first = @as(Zir.Inst.Ref, @enumFromInt(sema.code.extra[extra_index]));
11481 const item_first: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_index]);
1143311482 extra_index += 1;
11434 const item_last = @as(Zir.Inst.Ref, @enumFromInt(sema.code.extra[extra_index]));
11483 const item_last: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_index]);
1143511484 extra_index += 1;
1143611485
1143711486 const vals = try sema.validateSwitchRange(
......@@ -11482,9 +11531,9 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1148211531 {
1148311532 var scalar_i: u32 = 0;
1148411533 while (scalar_i < scalar_cases_len) : (scalar_i += 1) {
11485 const item_ref = @as(Zir.Inst.Ref, @enumFromInt(sema.code.extra[extra_index]));
11534 const item_ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_index]);
1148611535 extra_index += 1;
11487 const info = @as(Zir.Inst.SwitchBlock.ProngInfo, @bitCast(sema.code.extra[extra_index]));
11536 const info: Zir.Inst.SwitchBlock.ProngInfo = @bitCast(sema.code.extra[extra_index]);
1148811537 extra_index += 1 + info.body_len;
1148911538
1149011539 case_vals.appendAssumeCapacity(try sema.validateSwitchItemBool(
......@@ -11504,7 +11553,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1150411553 extra_index += 1;
1150511554 const ranges_len = sema.code.extra[extra_index];
1150611555 extra_index += 1;
11507 const info = @as(Zir.Inst.SwitchBlock.ProngInfo, @bitCast(sema.code.extra[extra_index]));
11556 const info: Zir.Inst.SwitchBlock.ProngInfo = @bitCast(sema.code.extra[extra_index]);
1150811557 extra_index += 1;
1150911558 const items = sema.code.refSlice(extra_index, items_len);
1151011559 extra_index += items_len + info.body_len;
......@@ -11517,7 +11566,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1151711566 &false_count,
1151811567 item_ref,
1151911568 src_node_offset,
11520 .{ .multi = .{ .prong = multi_i, .item = @as(u32, @intCast(item_i)) } },
11569 .{ .multi = .{ .prong = multi_i, .item = @intCast(item_i) } },
1152111570 ));
1152211571 }
1152311572
......@@ -11564,9 +11613,9 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1156411613 {
1156511614 var scalar_i: u32 = 0;
1156611615 while (scalar_i < scalar_cases_len) : (scalar_i += 1) {
11567 const item_ref = @as(Zir.Inst.Ref, @enumFromInt(sema.code.extra[extra_index]));
11616 const item_ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_index]);
1156811617 extra_index += 1;
11569 const info = @as(Zir.Inst.SwitchBlock.ProngInfo, @bitCast(sema.code.extra[extra_index]));
11618 const info: Zir.Inst.SwitchBlock.ProngInfo = @bitCast(sema.code.extra[extra_index]);
1157011619 extra_index += 1;
1157111620 extra_index += info.body_len;
1157211621
......@@ -11587,7 +11636,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1158711636 extra_index += 1;
1158811637 const ranges_len = sema.code.extra[extra_index];
1158911638 extra_index += 1;
11590 const info = @as(Zir.Inst.SwitchBlock.ProngInfo, @bitCast(sema.code.extra[extra_index]));
11639 const info: Zir.Inst.SwitchBlock.ProngInfo = @bitCast(sema.code.extra[extra_index]);
1159111640 extra_index += 1;
1159211641 const items = sema.code.refSlice(extra_index, items_len);
1159311642 extra_index += items_len + info.body_len;
......@@ -11600,7 +11649,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1160011649 item_ref,
1160111650 operand_ty,
1160211651 src_node_offset,
11603 .{ .multi = .{ .prong = multi_i, .item = @as(u32, @intCast(item_i)) } },
11652 .{ .multi = .{ .prong = multi_i, .item = @intCast(item_i) } },
1160411653 ));
1160511654 }
1160611655
......@@ -11638,7 +11687,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1163811687 .tag_capture_inst = tag_capture_inst,
1163911688 };
1164011689
11641 const block_inst = @as(Air.Inst.Index, @intCast(sema.air_instructions.len));
11690 const block_inst: Air.Inst.Index = @intCast(sema.air_instructions.len);
1164211691 try sema.air_instructions.append(gpa, .{
1164311692 .tag = .block,
1164411693 .data = undefined,
......@@ -11682,13 +11731,13 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1168211731 var scalar_i: usize = 0;
1168311732 while (scalar_i < scalar_cases_len) : (scalar_i += 1) {
1168411733 extra_index += 1;
11685 const info = @as(Zir.Inst.SwitchBlock.ProngInfo, @bitCast(sema.code.extra[extra_index]));
11734 const info: Zir.Inst.SwitchBlock.ProngInfo = @bitCast(sema.code.extra[extra_index]);
1168611735 extra_index += 1;
1168711736 const body = sema.code.extra[extra_index..][0..info.body_len];
1168811737 extra_index += info.body_len;
1168911738
1169011739 const item = case_vals.items[scalar_i];
11691 const item_val = sema.resolveConstValue(&child_block, .unneeded, item, "") catch unreachable;
11740 const item_val = sema.resolveConstValue(&child_block, .unneeded, item, undefined) catch unreachable;
1169211741 if (operand_val.eql(item_val, operand_ty, sema.mod)) {
1169311742 if (err_set) try sema.maybeErrorUnwrapComptime(&child_block, body, operand);
1169411743 return spa.resolveProngComptime(
......@@ -11696,7 +11745,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1169611745 .normal,
1169711746 body,
1169811747 info.capture,
11699 .{ .scalar_capture = @as(u32, @intCast(scalar_i)) },
11748 .{ .scalar_capture = @intCast(scalar_i) },
1170011749 &.{item},
1170111750 if (info.is_inline) operand else .none,
1170211751 info.has_tag_capture,
......@@ -11713,7 +11762,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1171311762 extra_index += 1;
1171411763 const ranges_len = sema.code.extra[extra_index];
1171511764 extra_index += 1;
11716 const info = @as(Zir.Inst.SwitchBlock.ProngInfo, @bitCast(sema.code.extra[extra_index]));
11765 const info: Zir.Inst.SwitchBlock.ProngInfo = @bitCast(sema.code.extra[extra_index]);
1171711766 extra_index += 1 + items_len;
1171811767 const body = sema.code.extra[extra_index + 2 * ranges_len ..][0..info.body_len];
1171911768
......@@ -11722,7 +11771,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1172211771
1172311772 for (items) |item| {
1172411773 // Validation above ensured these will succeed.
11725 const item_val = sema.resolveConstValue(&child_block, .unneeded, item, "") catch unreachable;
11774 const item_val = sema.resolveConstValue(&child_block, .unneeded, item, undefined) catch unreachable;
1172611775 if (operand_val.eql(item_val, operand_ty, sema.mod)) {
1172711776 if (err_set) try sema.maybeErrorUnwrapComptime(&child_block, body, operand);
1172811777 return spa.resolveProngComptime(
......@@ -11730,7 +11779,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1173011779 .normal,
1173111780 body,
1173211781 info.capture,
11733 .{ .multi_capture = @as(u32, @intCast(multi_i)) },
11782 .{ .multi_capture = @intCast(multi_i) },
1173411783 items,
1173511784 if (info.is_inline) operand else .none,
1173611785 info.has_tag_capture,
......@@ -11746,8 +11795,8 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1174611795 case_val_idx += 2;
1174711796
1174811797 // Validation above ensured these will succeed.
11749 const first_val = sema.resolveConstValue(&child_block, .unneeded, range_items[0], "") catch unreachable;
11750 const last_val = sema.resolveConstValue(&child_block, .unneeded, range_items[1], "") catch unreachable;
11798 const first_val = sema.resolveConstValue(&child_block, .unneeded, range_items[0], undefined) catch unreachable;
11799 const last_val = sema.resolveConstValue(&child_block, .unneeded, range_items[1], undefined) catch unreachable;
1175111800 if ((try sema.compareAll(resolved_operand_val, .gte, first_val, operand_ty)) and
1175211801 (try sema.compareAll(resolved_operand_val, .lte, last_val, operand_ty)))
1175311802 {
......@@ -11757,7 +11806,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1175711806 .normal,
1175811807 body,
1175911808 info.capture,
11760 .{ .multi_capture = @as(u32, @intCast(multi_i)) },
11809 .{ .multi_capture = @intCast(multi_i) },
1176111810 undefined, // case_vals may be undefined for ranges
1176211811 if (info.is_inline) operand else .none,
1176311812 info.has_tag_capture,
......@@ -11771,7 +11820,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1177111820 }
1177211821 if (err_set) try sema.maybeErrorUnwrapComptime(&child_block, special.body, operand);
1177311822 if (empty_enum) {
11774 return Air.Inst.Ref.void_value;
11823 return .void_value;
1177511824 }
1177611825
1177711826 return spa.resolveProngComptime(
......@@ -11789,13 +11838,13 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1178911838
1179011839 if (scalar_cases_len + multi_cases_len == 0 and !special.is_inline) {
1179111840 if (empty_enum) {
11792 return Air.Inst.Ref.void_value;
11841 return .void_value;
1179311842 }
1179411843 if (special_prong == .none) {
1179511844 return sema.fail(block, src, "switch must handle all possibilities", .{});
1179611845 }
1179711846 if (err_set and try sema.maybeErrorUnwrap(block, special.body, operand, operand_src)) {
11798 return Air.Inst.Ref.unreachable_value;
11847 return .unreachable_value;
1179911848 }
1180011849 if (mod.backendSupportsFeature(.is_named_enum_value) and block.wantSafety() and operand_ty.zigTypeTag(mod) == .Enum and
1180111850 (!operand_ty.isNonexhaustiveEnum(mod) or union_originally))
......@@ -11819,10 +11868,10 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1181911868 }
1182011869
1182111870 if (child_block.is_comptime) {
11822 _ = sema.resolveConstValue(&child_block, operand_src, operand, "condition in comptime switch must be comptime-known") catch |err| {
11823 if (err == error.AnalysisFail and child_block.comptime_reason != null) try child_block.comptime_reason.?.explain(sema, sema.err);
11824 return err;
11825 };
11871 _ = try sema.resolveConstValue(&child_block, operand_src, operand, .{
11872 .needed_comptime_reason = "condition in comptime switch must be comptime-known",
11873 .block_comptime_reason = child_block.comptime_reason,
11874 });
1182611875 unreachable;
1182711876 }
1182811877
......@@ -11842,7 +11891,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1184211891 var scalar_i: usize = 0;
1184311892 while (scalar_i < scalar_cases_len) : (scalar_i += 1) {
1184411893 extra_index += 1;
11845 const info = @as(Zir.Inst.SwitchBlock.ProngInfo, @bitCast(sema.code.extra[extra_index]));
11894 const info: Zir.Inst.SwitchBlock.ProngInfo = @bitCast(sema.code.extra[extra_index]);
1184611895 extra_index += 1;
1184711896 const body = sema.code.extra[extra_index..][0..info.body_len];
1184811897 extra_index += info.body_len;
......@@ -11857,7 +11906,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1185711906 // `item` is already guaranteed to be constant known.
1185811907
1185911908 const analyze_body = if (union_originally) blk: {
11860 const item_val = sema.resolveConstLazyValue(block, .unneeded, item, "") catch unreachable;
11909 const item_val = sema.resolveConstLazyValue(block, .unneeded, item, undefined) catch unreachable;
1186111910 const field_ty = maybe_union_ty.unionFieldType(item_val, mod);
1186211911 break :blk field_ty.zigTypeTag(mod) != .NoReturn;
1186311912 } else true;
......@@ -11870,7 +11919,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1187011919 .normal,
1187111920 body,
1187211921 info.capture,
11873 .{ .scalar_capture = @as(u32, @intCast(scalar_i)) },
11922 .{ .scalar_capture = @intCast(scalar_i) },
1187411923 &.{item},
1187511924 if (info.is_inline) item else .none,
1187611925 info.has_tag_capture,
......@@ -11883,7 +11932,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1188311932
1188411933 try cases_extra.ensureUnusedCapacity(gpa, 3 + case_block.instructions.items.len);
1188511934 cases_extra.appendAssumeCapacity(1); // items_len
11886 cases_extra.appendAssumeCapacity(@as(u32, @intCast(case_block.instructions.items.len)));
11935 cases_extra.appendAssumeCapacity(@intCast(case_block.instructions.items.len));
1188711936 cases_extra.appendAssumeCapacity(@intFromEnum(item));
1188811937 cases_extra.appendSliceAssumeCapacity(case_block.instructions.items);
1188911938 }
......@@ -11903,7 +11952,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1190311952 extra_index += 1;
1190411953 const ranges_len = sema.code.extra[extra_index];
1190511954 extra_index += 1;
11906 const info = @as(Zir.Inst.SwitchBlock.ProngInfo, @bitCast(sema.code.extra[extra_index]));
11955 const info: Zir.Inst.SwitchBlock.ProngInfo = @bitCast(sema.code.extra[extra_index]);
1190711956 extra_index += 1 + items_len;
1190811957
1190911958 const items = case_vals.items[case_val_idx..][0..items_len];
......@@ -11946,7 +11995,9 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1194611995
1194711996 if (emit_bb) sema.emitBackwardBranch(block, .unneeded) catch |err| switch (err) {
1194811997 error.NeededSourceLocation => {
11949 const case_src = Module.SwitchProngSrc{ .range = .{ .prong = multi_i, .item = range_i } };
11998 const case_src = Module.SwitchProngSrc{
11999 .range = .{ .prong = multi_i, .item = range_i },
12000 };
1195012001 const decl = mod.declPtr(case_block.src_decl);
1195112002 try sema.emitBackwardBranch(block, case_src.resolve(mod, decl, src_node_offset, .none));
1195212003 unreachable;
......@@ -11968,7 +12019,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1196812019
1196912020 try cases_extra.ensureUnusedCapacity(gpa, 3 + case_block.instructions.items.len);
1197012021 cases_extra.appendAssumeCapacity(1); // items_len
11971 cases_extra.appendAssumeCapacity(@as(u32, @intCast(case_block.instructions.items.len)));
12022 cases_extra.appendAssumeCapacity(@intCast(case_block.instructions.items.len));
1197212023 cases_extra.appendAssumeCapacity(@intFromEnum(item_ref));
1197312024 cases_extra.appendSliceAssumeCapacity(case_block.instructions.items);
1197412025
......@@ -11990,7 +12041,9 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1199012041
1199112042 if (emit_bb) sema.emitBackwardBranch(block, .unneeded) catch |err| switch (err) {
1199212043 error.NeededSourceLocation => {
11993 const case_src = Module.SwitchProngSrc{ .multi = .{ .prong = multi_i, .item = @as(u32, @intCast(item_i)) } };
12044 const case_src = Module.SwitchProngSrc{
12045 .multi = .{ .prong = multi_i, .item = @intCast(item_i) },
12046 };
1199412047 const decl = mod.declPtr(case_block.src_decl);
1199512048 try sema.emitBackwardBranch(block, case_src.resolve(mod, decl, src_node_offset, .none));
1199612049 unreachable;
......@@ -12016,7 +12069,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1201612069
1201712070 try cases_extra.ensureUnusedCapacity(gpa, 3 + case_block.instructions.items.len);
1201812071 cases_extra.appendAssumeCapacity(1); // items_len
12019 cases_extra.appendAssumeCapacity(@as(u32, @intCast(case_block.instructions.items.len)));
12072 cases_extra.appendAssumeCapacity(@intCast(case_block.instructions.items.len));
1202012073 cases_extra.appendAssumeCapacity(@intFromEnum(item));
1202112074 cases_extra.appendSliceAssumeCapacity(case_block.instructions.items);
1202212075 }
......@@ -12035,7 +12088,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1203512088
1203612089 const analyze_body = if (union_originally)
1203712090 for (items) |item| {
12038 const item_val = sema.resolveConstValue(block, .unneeded, item, "") catch unreachable;
12091 const item_val = sema.resolveConstValue(block, .unneeded, item, undefined) catch unreachable;
1203912092 const field_ty = maybe_union_ty.unionFieldType(item_val, mod);
1204012093 if (field_ty.zigTypeTag(mod) != .NoReturn) break true;
1204112094 } else false
......@@ -12064,8 +12117,8 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1206412117 try cases_extra.ensureUnusedCapacity(gpa, 2 + items.len +
1206512118 case_block.instructions.items.len);
1206612119
12067 cases_extra.appendAssumeCapacity(@as(u32, @intCast(items.len)));
12068 cases_extra.appendAssumeCapacity(@as(u32, @intCast(case_block.instructions.items.len)));
12120 cases_extra.appendAssumeCapacity(@intCast(items.len));
12121 cases_extra.appendAssumeCapacity(@intCast(case_block.instructions.items.len));
1206912122
1207012123 for (items) |item| {
1207112124 cases_extra.appendAssumeCapacity(@intFromEnum(item));
......@@ -12160,8 +12213,8 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1216012213
1216112214 sema.air_instructions.items(.data)[prev_cond_br].pl_op.payload =
1216212215 sema.addExtraAssumeCapacity(Air.CondBr{
12163 .then_body_len = @as(u32, @intCast(prev_then_body.len)),
12164 .else_body_len = @as(u32, @intCast(cond_body.len)),
12216 .then_body_len = @intCast(prev_then_body.len),
12217 .else_body_len = @intCast(cond_body.len),
1216512218 });
1216612219 sema.air_extra.appendSliceAssumeCapacity(prev_then_body);
1216712220 sema.air_extra.appendSliceAssumeCapacity(cond_body);
......@@ -12186,7 +12239,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1218612239 if (f != null) continue;
1218712240 cases_len += 1;
1218812241
12189 const item_val = try mod.enumValueFieldIndex(operand_ty, @as(u32, @intCast(i)));
12242 const item_val = try mod.enumValueFieldIndex(operand_ty, @intCast(i));
1219012243 const item_ref = Air.internedToRef(item_val.toIntern());
1219112244
1219212245 case_block.instructions.shrinkRetainingCapacity(0);
......@@ -12217,7 +12270,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1221712270
1221812271 try cases_extra.ensureUnusedCapacity(gpa, 3 + case_block.instructions.items.len);
1221912272 cases_extra.appendAssumeCapacity(1); // items_len
12220 cases_extra.appendAssumeCapacity(@as(u32, @intCast(case_block.instructions.items.len)));
12273 cases_extra.appendAssumeCapacity(@intCast(case_block.instructions.items.len));
1222112274 cases_extra.appendAssumeCapacity(@intFromEnum(item_ref));
1222212275 cases_extra.appendSliceAssumeCapacity(case_block.instructions.items);
1222312276 }
......@@ -12258,7 +12311,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1225812311
1225912312 try cases_extra.ensureUnusedCapacity(gpa, 3 + case_block.instructions.items.len);
1226012313 cases_extra.appendAssumeCapacity(1); // items_len
12261 cases_extra.appendAssumeCapacity(@as(u32, @intCast(case_block.instructions.items.len)));
12314 cases_extra.appendAssumeCapacity(@intCast(case_block.instructions.items.len));
1226212315 cases_extra.appendAssumeCapacity(@intFromEnum(item_ref));
1226312316 cases_extra.appendSliceAssumeCapacity(case_block.instructions.items);
1226412317 }
......@@ -12289,7 +12342,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1228912342
1229012343 try cases_extra.ensureUnusedCapacity(gpa, 3 + case_block.instructions.items.len);
1229112344 cases_extra.appendAssumeCapacity(1); // items_len
12292 cases_extra.appendAssumeCapacity(@as(u32, @intCast(case_block.instructions.items.len)));
12345 cases_extra.appendAssumeCapacity(@intCast(case_block.instructions.items.len));
1229312346 cases_extra.appendAssumeCapacity(@intFromEnum(item_ref));
1229412347 cases_extra.appendSliceAssumeCapacity(case_block.instructions.items);
1229512348 }
......@@ -12310,14 +12363,14 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1231012363 special.body,
1231112364 special.capture,
1231212365 .special_capture,
12313 &.{Air.Inst.Ref.bool_true},
12314 Air.Inst.Ref.bool_true,
12366 &.{.bool_true},
12367 .bool_true,
1231512368 special.has_tag_capture,
1231612369 );
1231712370
1231812371 try cases_extra.ensureUnusedCapacity(gpa, 3 + case_block.instructions.items.len);
1231912372 cases_extra.appendAssumeCapacity(1); // items_len
12320 cases_extra.appendAssumeCapacity(@as(u32, @intCast(case_block.instructions.items.len)));
12373 cases_extra.appendAssumeCapacity(@intCast(case_block.instructions.items.len));
1232112374 cases_extra.appendAssumeCapacity(@intFromEnum(Air.Inst.Ref.bool_true));
1232212375 cases_extra.appendSliceAssumeCapacity(case_block.instructions.items);
1232312376 }
......@@ -12336,14 +12389,14 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1233612389 special.body,
1233712390 special.capture,
1233812391 .special_capture,
12339 &.{Air.Inst.Ref.bool_false},
12340 Air.Inst.Ref.bool_false,
12392 &.{.bool_false},
12393 .bool_false,
1234112394 special.has_tag_capture,
1234212395 );
1234312396
1234412397 try cases_extra.ensureUnusedCapacity(gpa, 3 + case_block.instructions.items.len);
1234512398 cases_extra.appendAssumeCapacity(1); // items_len
12346 cases_extra.appendAssumeCapacity(@as(u32, @intCast(case_block.instructions.items.len)));
12399 cases_extra.appendAssumeCapacity(@intCast(case_block.instructions.items.len));
1234712400 cases_extra.appendAssumeCapacity(@intFromEnum(Air.Inst.Ref.bool_false));
1234812401 cases_extra.appendSliceAssumeCapacity(case_block.instructions.items);
1234912402 }
......@@ -12412,8 +12465,8 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1241212465
1241312466 sema.air_instructions.items(.data)[prev_cond_br].pl_op.payload =
1241412467 sema.addExtraAssumeCapacity(Air.CondBr{
12415 .then_body_len = @as(u32, @intCast(prev_then_body.len)),
12416 .else_body_len = @as(u32, @intCast(case_block.instructions.items.len)),
12468 .then_body_len = @intCast(prev_then_body.len),
12469 .else_body_len = @intCast(case_block.instructions.items.len),
1241712470 });
1241812471 sema.air_extra.appendSliceAssumeCapacity(prev_then_body);
1241912472 sema.air_extra.appendSliceAssumeCapacity(case_block.instructions.items);
......@@ -12427,8 +12480,8 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1242712480 _ = try child_block.addInst(.{ .tag = .switch_br, .data = .{ .pl_op = .{
1242812481 .operand = operand,
1242912482 .payload = sema.addExtraAssumeCapacity(Air.SwitchBr{
12430 .cases_len = @as(u32, @intCast(cases_len)),
12431 .else_body_len = @as(u32, @intCast(final_else_body.len)),
12483 .cases_len = @intCast(cases_len),
12484 .else_body_len = @intCast(final_else_body.len),
1243212485 }),
1243312486 } } });
1243412487 sema.air_extra.appendSliceAssumeCapacity(cases_extra.items);
......@@ -12535,10 +12588,12 @@ fn resolveSwitchItemVal(
1253512588 else => |e| return e,
1253612589 };
1253712590
12538 const maybe_lazy = sema.resolveConstValue(block, .unneeded, item, "") catch |err| switch (err) {
12591 const maybe_lazy = sema.resolveConstValue(block, .unneeded, item, undefined) catch |err| switch (err) {
1253912592 error.NeededSourceLocation => {
1254012593 const src = switch_prong_src.resolve(mod, mod.declPtr(block.src_decl), switch_node_offset, range_expand);
12541 _ = try sema.resolveConstValue(block, src, item, "switch prong values must be comptime-known");
12594 _ = try sema.resolveConstValue(block, src, item, .{
12595 .needed_comptime_reason = "switch prong values must be comptime-known",
12596 });
1254212597 unreachable;
1254312598 },
1254412599 else => |e| return e,
......@@ -12662,7 +12717,7 @@ fn validateSwitchDupe(
1266212717 );
1266312718 break :msg msg;
1266412719 };
12665 return sema.failWithOwnedErrorMsg(msg);
12720 return sema.failWithOwnedErrorMsg(block, msg);
1266612721}
1266712722
1266812723fn validateSwitchItemBool(
......@@ -12736,7 +12791,7 @@ fn validateSwitchNoRange(
1273612791 );
1273712792 break :msg msg;
1273812793 };
12739 return sema.failWithOwnedErrorMsg(msg);
12794 return sema.failWithOwnedErrorMsg(block, msg);
1274012795}
1274112796
1274212797fn maybeErrorUnwrap(sema: *Sema, block: *Block, body: []const Zir.Inst.Index, operand: Air.Inst.Ref, operand_src: LazySrcLoc) !bool {
......@@ -12856,7 +12911,9 @@ fn zirHasField(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1285612911 const ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
1285712912 const name_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };
1285812913 const ty = try sema.resolveType(block, ty_src, extra.lhs);
12859 const field_name = try sema.resolveConstStringIntern(block, name_src, extra.rhs, "field name must be comptime-known");
12914 const field_name = try sema.resolveConstStringIntern(block, name_src, extra.rhs, .{
12915 .needed_comptime_reason = "field name must be comptime-known",
12916 });
1286012917 try sema.resolveTypeFields(ty);
1286112918 const ip = &mod.intern_pool;
1286212919
......@@ -12897,11 +12954,7 @@ fn zirHasField(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1289712954 ty.fmt(mod),
1289812955 });
1289912956 };
12900 if (has_field) {
12901 return Air.Inst.Ref.bool_true;
12902 } else {
12903 return Air.Inst.Ref.bool_false;
12904 }
12957 return if (has_field) .bool_true else .bool_false;
1290512958}
1290612959
1290712960fn zirHasDecl(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
......@@ -12912,19 +12965,21 @@ fn zirHasDecl(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1291212965 const lhs_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
1291312966 const rhs_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };
1291412967 const container_type = try sema.resolveType(block, lhs_src, extra.lhs);
12915 const decl_name = try sema.resolveConstStringIntern(block, rhs_src, extra.rhs, "decl name must be comptime-known");
12968 const decl_name = try sema.resolveConstStringIntern(block, rhs_src, extra.rhs, .{
12969 .needed_comptime_reason = "decl name must be comptime-known",
12970 });
1291612971
1291712972 try sema.checkNamespaceType(block, lhs_src, container_type);
1291812973
1291912974 const namespace = container_type.getNamespaceIndex(mod).unwrap() orelse
12920 return Air.Inst.Ref.bool_false;
12975 return .bool_false;
1292112976 if (try sema.lookupInNamespace(block, src, namespace, decl_name, true)) |decl_index| {
1292212977 const decl = mod.declPtr(decl_index);
1292312978 if (decl.is_pub or decl.getFileScope(mod) == block.getFileScope(mod)) {
12924 return Air.Inst.Ref.bool_true;
12979 return .bool_true;
1292512980 }
1292612981 }
12927 return Air.Inst.Ref.bool_false;
12982 return .bool_false;
1292812983}
1292912984
1293012985fn zirImport(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
......@@ -12965,7 +13020,9 @@ fn zirEmbedFile(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
1296513020 const mod = sema.mod;
1296613021 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
1296713022 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
12968 const name = try sema.resolveConstString(block, operand_src, inst_data.operand, "file path name must be comptime-known");
13023 const name = try sema.resolveConstString(block, operand_src, inst_data.operand, .{
13024 .needed_comptime_reason = "file path name must be comptime-known",
13025 });
1296913026
1297013027 if (name.len == 0) {
1297113028 return sema.fail(block, operand_src, "file path name cannot be empty", .{});
......@@ -13588,8 +13645,12 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1358813645 const rhs_sent = Air.internedToRef(rhs_sent_val.toIntern());
1358913646 const lhs_sent_casted = try sema.coerce(block, resolved_elem_ty, lhs_sent, lhs_src);
1359013647 const rhs_sent_casted = try sema.coerce(block, resolved_elem_ty, rhs_sent, rhs_src);
13591 const lhs_sent_casted_val = try sema.resolveConstValue(block, lhs_src, lhs_sent_casted, "array sentinel value must be comptime-known");
13592 const rhs_sent_casted_val = try sema.resolveConstValue(block, rhs_src, rhs_sent_casted, "array sentinel value must be comptime-known");
13648 const lhs_sent_casted_val = try sema.resolveConstValue(block, lhs_src, lhs_sent_casted, .{
13649 .needed_comptime_reason = "array sentinel value must be comptime-known",
13650 });
13651 const rhs_sent_casted_val = try sema.resolveConstValue(block, rhs_src, rhs_sent_casted, .{
13652 .needed_comptime_reason = "array sentinel value must be comptime-known",
13653 });
1359313654 if (try sema.valuesEqual(lhs_sent_casted_val, rhs_sent_casted_val, resolved_elem_ty)) {
1359413655 break :s lhs_sent_casted_val;
1359513656 } else {
......@@ -13597,14 +13658,18 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1359713658 }
1359813659 } else {
1359913660 const lhs_sent_casted = try sema.coerce(block, resolved_elem_ty, lhs_sent, lhs_src);
13600 const lhs_sent_casted_val = try sema.resolveConstValue(block, lhs_src, lhs_sent_casted, "array sentinel value must be comptime-known");
13661 const lhs_sent_casted_val = try sema.resolveConstValue(block, lhs_src, lhs_sent_casted, .{
13662 .needed_comptime_reason = "array sentinel value must be comptime-known",
13663 });
1360113664 break :s lhs_sent_casted_val;
1360213665 }
1360313666 } else {
1360413667 if (rhs_info.sentinel) |rhs_sent_val| {
1360513668 const rhs_sent = Air.internedToRef(rhs_sent_val.toIntern());
1360613669 const rhs_sent_casted = try sema.coerce(block, resolved_elem_ty, rhs_sent, rhs_src);
13607 const rhs_sent_casted_val = try sema.resolveConstValue(block, rhs_src, rhs_sent_casted, "array sentinel value must be comptime-known");
13670 const rhs_sent_casted_val = try sema.resolveConstValue(block, rhs_src, rhs_sent_casted, .{
13671 .needed_comptime_reason = "array sentinel value must be comptime-known",
13672 });
1360813673 break :s rhs_sent_casted_val;
1360913674 } else {
1361013675 break :s null;
......@@ -13662,7 +13727,7 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1366213727 const elem_val = if (elem_default_val.toIntern() == .unreachable_value) try lhs_sub_val.elemValue(mod, lhs_elem_i) else elem_default_val;
1366313728 const elem_val_inst = Air.internedToRef(elem_val.toIntern());
1366413729 const coerced_elem_val_inst = try sema.coerce(block, resolved_elem_ty, elem_val_inst, .unneeded);
13665 const coerced_elem_val = try sema.resolveConstMaybeUndefVal(block, .unneeded, coerced_elem_val_inst, "");
13730 const coerced_elem_val = try sema.resolveConstMaybeUndefVal(block, .unneeded, coerced_elem_val_inst, undefined);
1366613731 element_vals[elem_i] = try coerced_elem_val.intern(resolved_elem_ty, mod);
1366713732 }
1366813733 while (elem_i < result_len) : (elem_i += 1) {
......@@ -13671,7 +13736,7 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1367113736 const elem_val = if (elem_default_val.toIntern() == .unreachable_value) try rhs_sub_val.elemValue(mod, rhs_elem_i) else elem_default_val;
1367213737 const elem_val_inst = Air.internedToRef(elem_val.toIntern());
1367313738 const coerced_elem_val_inst = try sema.coerce(block, resolved_elem_ty, elem_val_inst, .unneeded);
13674 const coerced_elem_val = try sema.resolveConstMaybeUndefVal(block, .unneeded, coerced_elem_val_inst, "");
13739 const coerced_elem_val = try sema.resolveConstMaybeUndefVal(block, .unneeded, coerced_elem_val_inst, undefined);
1367513740 element_vals[elem_i] = try coerced_elem_val.intern(resolved_elem_ty, mod);
1367613741 }
1367713742 return sema.addConstantMaybeRef(block, result_ty, (try mod.intern(.{ .aggregate = .{
......@@ -13748,7 +13813,9 @@ fn getArrayCatInfo(sema: *Sema, block: *Block, src: LazySrcLoc, operand: Air.Ins
1374813813 // has a sentinel, and this code should compute the length based
1374913814 // on the sentinel value.
1375013815 .Slice, .Many => {
13751 const val = try sema.resolveConstValue(block, src, operand, "slice value being concatenated must be comptime-known");
13816 const val = try sema.resolveConstValue(block, src, operand, .{
13817 .needed_comptime_reason = "slice value being concatenated must be comptime-known",
13818 });
1375213819 return Type.ArrayInfo{
1375313820 .elem_type = ptr_info.child.toType(),
1375413821 .sentinel = switch (ptr_info.sentinel) {
......@@ -13842,7 +13909,7 @@ fn analyzeTupleMul(
1384213909 var i: u32 = 0;
1384313910 while (i < tuple_len) : (i += 1) {
1384413911 const operand_src = lhs_src; // TODO better source location
13845 element_refs[i] = try sema.tupleFieldValByIndex(block, operand_src, operand, @as(u32, @intCast(i)), operand_ty);
13912 element_refs[i] = try sema.tupleFieldValByIndex(block, operand_src, operand, @intCast(i), operand_ty);
1384613913 }
1384713914 i = 1;
1384813915 while (i < factor) : (i += 1) {
......@@ -13868,7 +13935,9 @@ fn zirArrayMul(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1386813935
1386913936 if (lhs_ty.isTuple(mod)) {
1387013937 // In `**` rhs must be comptime-known, but lhs can be runtime-known
13871 const factor = try sema.resolveInt(block, rhs_src, extra.rhs, Type.usize, "array multiplication factor must be comptime-known");
13938 const factor = try sema.resolveInt(block, rhs_src, extra.rhs, Type.usize, .{
13939 .needed_comptime_reason = "array multiplication factor must be comptime-known",
13940 });
1387213941 const factor_casted = try sema.usizeCast(block, rhs_src, factor);
1387313942 return sema.analyzeTupleMul(block, inst_data.src_node, lhs, factor_casted);
1387413943 }
......@@ -13886,11 +13955,13 @@ fn zirArrayMul(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1388613955 }
1388713956 break :msg msg;
1388813957 };
13889 return sema.failWithOwnedErrorMsg(msg);
13958 return sema.failWithOwnedErrorMsg(block, msg);
1389013959 };
1389113960
1389213961 // In `**` rhs must be comptime-known, but lhs can be runtime-known
13893 const factor = try sema.resolveInt(block, rhs_src, extra.rhs, Type.usize, "array multiplication factor must be comptime-known");
13962 const factor = try sema.resolveInt(block, rhs_src, extra.rhs, Type.usize, .{
13963 .needed_comptime_reason = "array multiplication factor must be comptime-known",
13964 });
1389413965
1389513966 const result_len_u64 = std.math.mul(u64, lhs_info.len, factor) catch
1389613967 return sema.fail(block, rhs_src, "operation results in overflow", .{});
......@@ -15886,10 +15957,10 @@ fn analyzePtrArithmetic(
1588615957 // The resulting pointer is aligned to the lcd between the offset (an
1588715958 // arbitrary number) and the alignment factor (always a power of two,
1588815959 // non zero).
15889 const new_align = @as(Alignment, @enumFromInt(@min(
15960 const new_align: Alignment = @enumFromInt(@min(
1589015961 @ctz(addend),
1589115962 @intFromEnum(ptr_info.flags.alignment),
15892 )));
15963 ));
1589315964 assert(new_align != .none);
1589415965
1589515966 break :t try mod.ptrType(.{
......@@ -15968,15 +16039,17 @@ fn zirAsm(
1596816039 const extra = sema.code.extraData(Zir.Inst.Asm, extended.operand);
1596916040 const src = LazySrcLoc.nodeOffset(extra.data.src_node);
1597016041 const ret_ty_src: LazySrcLoc = .{ .node_offset_asm_ret_ty = extra.data.src_node };
15971 const outputs_len = @as(u5, @truncate(extended.small));
15972 const inputs_len = @as(u5, @truncate(extended.small >> 5));
15973 const clobbers_len = @as(u5, @truncate(extended.small >> 10));
16042 const outputs_len: u5 = @truncate(extended.small);
16043 const inputs_len: u5 = @truncate(extended.small >> 5);
16044 const clobbers_len: u5 = @truncate(extended.small >> 10);
1597416045 const is_volatile = @as(u1, @truncate(extended.small >> 15)) != 0;
1597516046 const is_global_assembly = sema.func_index == .none;
1597616047
1597716048 const asm_source: []const u8 = if (tmpl_is_expr) blk: {
15978 const tmpl = @as(Zir.Inst.Ref, @enumFromInt(extra.data.asm_source));
15979 const s: []const u8 = try sema.resolveConstString(block, src, tmpl, "assembly code must be comptime-known");
16049 const tmpl: Zir.Inst.Ref = @enumFromInt(extra.data.asm_source);
16050 const s: []const u8 = try sema.resolveConstString(block, src, tmpl, .{
16051 .needed_comptime_reason = "assembly code must be comptime-known",
16052 });
1598016053 break :blk s;
1598116054 } else sema.code.nullTerminatedString(extra.data.asm_source);
1598216055
......@@ -15994,7 +16067,7 @@ fn zirAsm(
1599416067 return sema.fail(block, src, "volatile keyword is redundant on module-level assembly", .{});
1599516068 }
1599616069 try sema.mod.addGlobalAssembly(sema.owner_decl_index, asm_source);
15997 return Air.Inst.Ref.void_value;
16070 return .void_value;
1599816071 }
1599916072
1600016073 if (block.is_comptime) {
......@@ -16076,9 +16149,9 @@ fn zirAsm(
1607616149 .data = .{ .ty_pl = .{
1607716150 .ty = expr_ty,
1607816151 .payload = sema.addExtraAssumeCapacity(Air.Asm{
16079 .source_len = @as(u32, @intCast(asm_source.len)),
16152 .source_len = @intCast(asm_source.len),
1608016153 .outputs_len = outputs_len,
16081 .inputs_len = @as(u32, @intCast(args.len)),
16154 .inputs_len = @intCast(args.len),
1608216155 .flags = (@as(u32, @intFromBool(is_volatile)) << 31) | @as(u32, @intCast(clobbers.len)),
1608316156 }),
1608416157 } },
......@@ -16141,11 +16214,7 @@ fn zirCmpEq(
1614116214 const rhs_ty_tag = rhs_ty.zigTypeTag(mod);
1614216215 if (lhs_ty_tag == .Null and rhs_ty_tag == .Null) {
1614316216 // null == null, null != null
16144 if (op == .eq) {
16145 return Air.Inst.Ref.bool_true;
16146 } else {
16147 return Air.Inst.Ref.bool_false;
16148 }
16217 return if (op == .eq) .bool_true else .bool_false;
1614916218 }
1615016219
1615116220 // comparing null with optionals
......@@ -16177,11 +16246,10 @@ fn zirCmpEq(
1617716246 }
1617816247 const lkey = mod.intern_pool.indexToKey(lval.toIntern());
1617916248 const rkey = mod.intern_pool.indexToKey(rval.toIntern());
16180 if ((lkey.err.name == rkey.err.name) == (op == .eq)) {
16181 return Air.Inst.Ref.bool_true;
16182 } else {
16183 return Air.Inst.Ref.bool_false;
16184 }
16249 return if ((lkey.err.name == rkey.err.name) == (op == .eq))
16250 .bool_true
16251 else
16252 .bool_false;
1618516253 } else {
1618616254 break :src rhs_src;
1618716255 }
......@@ -16195,11 +16263,7 @@ fn zirCmpEq(
1619516263 if (lhs_ty_tag == .Type and rhs_ty_tag == .Type) {
1619616264 const lhs_as_type = try sema.analyzeAsType(block, lhs_src, lhs);
1619716265 const rhs_as_type = try sema.analyzeAsType(block, rhs_src, rhs);
16198 if (lhs_as_type.eql(rhs_as_type, mod) == (op == .eq)) {
16199 return Air.Inst.Ref.bool_true;
16200 } else {
16201 return Air.Inst.Ref.bool_false;
16202 }
16266 return if (lhs_as_type.eql(rhs_as_type, mod) == (op == .eq)) .bool_true else .bool_false;
1620316267 }
1620416268 return sema.analyzeCmp(block, src, lhs, rhs, op, lhs_src, rhs_src, true);
1620516269}
......@@ -16224,7 +16288,7 @@ fn analyzeCmpUnionTag(
1622416288 try mod.errNoteNonLazy(union_ty.declSrcLoc(mod), msg, "union '{}' is not a tagged union", .{union_ty.fmt(mod)});
1622516289 break :msg msg;
1622616290 };
16227 return sema.failWithOwnedErrorMsg(msg);
16291 return sema.failWithOwnedErrorMsg(block, msg);
1622816292 };
1622916293 // Coerce both the union and the tag to the union's tag type, and then execute the
1623016294 // enum comparison codepath.
......@@ -16235,7 +16299,7 @@ fn analyzeCmpUnionTag(
1623516299 if (enum_val.isUndef(mod)) return mod.undefRef(Type.bool);
1623616300 const field_ty = union_ty.unionFieldType(enum_val, mod);
1623716301 if (field_ty.zigTypeTag(mod) == .NoReturn) {
16238 return Air.Inst.Ref.bool_false;
16302 return .bool_false;
1623916303 }
1624016304 }
1624116305
......@@ -16343,11 +16407,10 @@ fn cmpSelf(
1634316407 return Air.internedToRef(cmp_val.toIntern());
1634416408 }
1634516409
16346 if (try sema.compareAll(lhs_val, op, rhs_val, resolved_type)) {
16347 return Air.Inst.Ref.bool_true;
16348 } else {
16349 return Air.Inst.Ref.bool_false;
16350 }
16410 return if (try sema.compareAll(lhs_val, op, rhs_val, resolved_type))
16411 .bool_true
16412 else
16413 .bool_false;
1635116414 } else {
1635216415 if (resolved_type.zigTypeTag(mod) == .Bool) {
1635316416 // We can lower bool eq/neq more efficiently.
......@@ -16486,7 +16549,7 @@ fn zirThis(
1648616549) CompileError!Air.Inst.Ref {
1648716550 const mod = sema.mod;
1648816551 const this_decl_index = mod.namespaceDeclIndex(block.namespace);
16489 const src = LazySrcLoc.nodeOffset(@as(i32, @bitCast(extended.operand)));
16552 const src = LazySrcLoc.nodeOffset(@bitCast(extended.operand));
1649016553 return sema.analyzeDeclVal(block, src, this_decl_index);
1649116554}
1649216555
......@@ -16560,7 +16623,7 @@ fn zirClosureGet(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
1656016623 // TODO add "declared here" note
1656116624 break :msg msg;
1656216625 };
16563 return sema.failWithOwnedErrorMsg(msg);
16626 return sema.failWithOwnedErrorMsg(block, msg);
1656416627 }
1656516628
1656616629 if (capture == .runtime_val and !block.is_typeof and !block.is_comptime and sema.func_index != .none) {
......@@ -16590,7 +16653,7 @@ fn zirClosureGet(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
1659016653 // TODO add "declared here" note
1659116654 break :msg msg;
1659216655 };
16593 return sema.failWithOwnedErrorMsg(msg);
16656 return sema.failWithOwnedErrorMsg(block, msg);
1659416657 }
1659516658
1659616659 switch (capture) {
......@@ -16624,7 +16687,7 @@ fn zirFrameAddress(
1662416687 block: *Block,
1662516688 extended: Zir.Inst.Extended.InstData,
1662616689) CompileError!Air.Inst.Ref {
16627 const src = LazySrcLoc.nodeOffset(@as(i32, @bitCast(extended.operand)));
16690 const src = LazySrcLoc.nodeOffset(@bitCast(extended.operand));
1662816691 try sema.requireRuntimeBlock(block, src, null);
1662916692 return try block.addNoOp(.frame_addr);
1663016693}
......@@ -17223,7 +17286,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1722317286 else
1722417287 try mod.intern(.{ .int = .{
1722517288 .ty = .comptime_int_type,
17226 .storage = .{ .u64 = @as(u64, @intCast(i)) },
17289 .storage = .{ .u64 = @intCast(i) },
1722717290 } });
1722817291 // TODO: write something like getCoercedInts to avoid needing to dupe
1722917292 const name = try sema.arena.dupe(u8, ip.stringToSlice(enum_type.names.get(ip)[i]));
......@@ -17996,10 +18059,7 @@ fn zirBoolNot(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1799618059 if (try sema.resolveMaybeUndefVal(operand)) |val| {
1799718060 return if (val.isUndef(mod))
1799818061 mod.undefRef(Type.bool)
17999 else if (val.toBool())
18000 Air.Inst.Ref.bool_false
18001 else
18002 Air.Inst.Ref.bool_true;
18062 else if (val.toBool()) .bool_false else .bool_true;
1800318063 }
1800418064 try sema.requireRuntimeBlock(block, src, null);
1800518065 return block.addTyOp(.not, Type.bool, operand);
......@@ -18025,9 +18085,9 @@ fn zirBoolBr(
1802518085
1802618086 if (try sema.resolveDefinedValue(parent_block, lhs_src, lhs)) |lhs_val| {
1802718087 if (is_bool_or and lhs_val.toBool()) {
18028 return Air.Inst.Ref.bool_true;
18088 return .bool_true;
1802918089 } else if (!is_bool_or and !lhs_val.toBool()) {
18030 return Air.Inst.Ref.bool_false;
18090 return .bool_false;
1803118091 }
1803218092 // comptime-known left-hand side. No need for a block here; the result
1803318093 // is simply the rhs expression. Here we rely on there only being 1
......@@ -18035,7 +18095,7 @@ fn zirBoolBr(
1803518095 return sema.resolveBody(parent_block, body, inst);
1803618096 }
1803718097
18038 const block_inst = @as(Air.Inst.Index, @intCast(sema.air_instructions.len));
18098 const block_inst: Air.Inst.Index = @intCast(sema.air_instructions.len);
1803918099 try sema.air_instructions.append(gpa, .{
1804018100 .tag = .block,
1804118101 .data = .{ .ty_pl = .{
......@@ -18071,9 +18131,9 @@ fn zirBoolBr(
1807118131 if (!sema.typeOf(rhs_result).isNoReturn(mod)) {
1807218132 if (try sema.resolveDefinedValue(rhs_block, sema.src, rhs_result)) |rhs_val| {
1807318133 if (is_bool_or and rhs_val.toBool()) {
18074 return Air.Inst.Ref.bool_true;
18134 return .bool_true;
1807518135 } else if (!is_bool_or and !rhs_val.toBool()) {
18076 return Air.Inst.Ref.bool_false;
18136 return .bool_false;
1807718137 }
1807818138 }
1807918139 }
......@@ -18097,8 +18157,8 @@ fn finishCondBr(
1809718157 @typeInfo(Air.Block).Struct.fields.len + child_block.instructions.items.len + 1);
1809818158
1809918159 const cond_br_payload = sema.addExtraAssumeCapacity(Air.CondBr{
18100 .then_body_len = @as(u32, @intCast(then_block.instructions.items.len)),
18101 .else_body_len = @as(u32, @intCast(else_block.instructions.items.len)),
18160 .then_body_len = @intCast(then_block.instructions.items.len),
18161 .else_body_len = @intCast(else_block.instructions.items.len),
1810218162 });
1810318163 sema.air_extra.appendSliceAssumeCapacity(then_block.instructions.items);
1810418164 sema.air_extra.appendSliceAssumeCapacity(else_block.instructions.items);
......@@ -18109,7 +18169,7 @@ fn finishCondBr(
1810918169 } } });
1811018170
1811118171 sema.air_instructions.items(.data)[block_inst].ty_pl.payload = sema.addExtraAssumeCapacity(
18112 Air.Block{ .body_len = @as(u32, @intCast(child_block.instructions.items.len)) },
18172 Air.Block{ .body_len = @intCast(child_block.instructions.items.len) },
1811318173 );
1811418174 sema.air_extra.appendSliceAssumeCapacity(child_block.instructions.items);
1811518175
......@@ -18272,8 +18332,8 @@ fn zirCondbr(
1827218332 .data = .{ .pl_op = .{
1827318333 .operand = cond,
1827418334 .payload = sema.addExtraAssumeCapacity(Air.CondBr{
18275 .then_body_len = @as(u32, @intCast(true_instructions.len)),
18276 .else_body_len = @as(u32, @intCast(sub_block.instructions.items.len)),
18335 .then_body_len = @intCast(true_instructions.len),
18336 .else_body_len = @intCast(sub_block.instructions.items.len),
1827718337 }),
1827818338 } },
1827918339 });
......@@ -18320,7 +18380,7 @@ fn zirTry(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError!
1832018380 .data = .{ .pl_op = .{
1832118381 .operand = err_union,
1832218382 .payload = sema.addExtraAssumeCapacity(Air.Try{
18323 .body_len = @as(u32, @intCast(sub_block.instructions.items.len)),
18383 .body_len = @intCast(sub_block.instructions.items.len),
1832418384 }),
1832518385 } },
1832618386 });
......@@ -18380,7 +18440,7 @@ fn zirTryPtr(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileErr
1838018440 .ty = res_ty_ref,
1838118441 .payload = sema.addExtraAssumeCapacity(Air.TryPtr{
1838218442 .ptr = operand,
18383 .body_len = @as(u32, @intCast(sub_block.instructions.items.len)),
18443 .body_len = @intCast(sub_block.instructions.items.len),
1838418444 }),
1838518445 } },
1838618446 });
......@@ -18396,7 +18456,7 @@ fn addRuntimeBreak(sema: *Sema, child_block: *Block, break_data: BreakData) !voi
1839618456 const labeled_block = if (!gop.found_existing) blk: {
1839718457 try sema.post_hoc_blocks.ensureUnusedCapacity(sema.gpa, 1);
1839818458
18399 const new_block_inst = @as(Air.Inst.Index, @intCast(sema.air_instructions.len));
18459 const new_block_inst: Air.Inst.Index = @intCast(sema.air_instructions.len);
1840018460 gop.value_ptr.* = Air.indexToRef(new_block_inst);
1840118461 try sema.air_instructions.append(sema.gpa, .{
1840218462 .tag = .block,
......@@ -18517,7 +18577,7 @@ fn zirRetImplicit(
1851718577 try sema.errNote(block, r_brace_src, msg, "control flow reaches end of body here", .{});
1851818578 break :msg msg;
1851918579 };
18520 return sema.failWithOwnedErrorMsg(msg);
18580 return sema.failWithOwnedErrorMsg(block, msg);
1852118581 } else if (base_tag != .Void) {
1852218582 const msg = msg: {
1852318583 const msg = try sema.errMsg(block, ret_ty_src, "function with non-void return type '{}' implicitly returns", .{
......@@ -18527,7 +18587,7 @@ fn zirRetImplicit(
1852718587 try sema.errNote(block, r_brace_src, msg, "control flow reaches end of body here", .{});
1852818588 break :msg msg;
1852918589 };
18530 return sema.failWithOwnedErrorMsg(msg);
18590 return sema.failWithOwnedErrorMsg(block, msg);
1853118591 }
1853218592
1853318593 return sema.analyzeRet(block, operand, r_brace_src);
......@@ -18611,8 +18671,8 @@ fn retWithErrTracing(
1861118671 @typeInfo(Air.Block).Struct.fields.len + 1);
1861218672
1861318673 const cond_br_payload = sema.addExtraAssumeCapacity(Air.CondBr{
18614 .then_body_len = @as(u32, @intCast(then_block.instructions.items.len)),
18615 .else_body_len = @as(u32, @intCast(else_block.instructions.items.len)),
18674 .then_body_len = @intCast(then_block.instructions.items.len),
18675 .else_body_len = @intCast(else_block.instructions.items.len),
1861618676 });
1861718677 sema.air_extra.appendSliceAssumeCapacity(then_block.instructions.items);
1861818678 sema.air_extra.appendSliceAssumeCapacity(else_block.instructions.items);
......@@ -18749,7 +18809,9 @@ fn analyzeRet(
1874918809
1875018810 if (block.inlining) |inlining| {
1875118811 if (block.is_comptime) {
18752 _ = try sema.resolveConstMaybeUndefVal(block, src, operand, "value being returned at comptime must be comptime-known");
18812 _ = try sema.resolveConstMaybeUndefVal(block, src, operand, .{
18813 .needed_comptime_reason = "value being returned at comptime must be comptime-known",
18814 });
1875318815 inlining.comptime_result = operand;
1875418816 return error.ComptimeReturn;
1875518817 }
......@@ -18767,7 +18829,7 @@ fn analyzeRet(
1876718829 try sema.errNote(block, src, msg, "can only return using assembly", .{});
1876818830 break :msg msg;
1876918831 };
18770 return sema.failWithOwnedErrorMsg(msg);
18832 return sema.failWithOwnedErrorMsg(block, msg);
1877118833 }
1877218834
1877318835 try sema.resolveTypeLayout(sema.fn_ret_ty);
......@@ -18826,18 +18888,22 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1882618888 var extra_i = extra.end;
1882718889
1882818890 const sentinel = if (inst_data.flags.has_sentinel) blk: {
18829 const ref = @as(Zir.Inst.Ref, @enumFromInt(sema.code.extra[extra_i]));
18891 const ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_i]);
1883018892 extra_i += 1;
1883118893 const coerced = try sema.coerce(block, elem_ty, try sema.resolveInst(ref), sentinel_src);
18832 const val = try sema.resolveConstValue(block, sentinel_src, coerced, "pointer sentinel value must be comptime-known");
18894 const val = try sema.resolveConstValue(block, sentinel_src, coerced, .{
18895 .needed_comptime_reason = "pointer sentinel value must be comptime-known",
18896 });
1883318897 break :blk val.toIntern();
1883418898 } else .none;
1883518899
1883618900 const abi_align: Alignment = if (inst_data.flags.has_align) blk: {
18837 const ref = @as(Zir.Inst.Ref, @enumFromInt(sema.code.extra[extra_i]));
18901 const ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_i]);
1883818902 extra_i += 1;
1883918903 const coerced = try sema.coerce(block, Type.u32, try sema.resolveInst(ref), align_src);
18840 const val = try sema.resolveConstValue(block, align_src, coerced, "pointer alignment must be comptime-known");
18904 const val = try sema.resolveConstValue(block, align_src, coerced, .{
18905 .needed_comptime_reason = "pointer alignment must be comptime-known",
18906 });
1884118907 // Check if this happens to be the lazy alignment of our element type, in
1884218908 // which case we can make this 0 without resolving it.
1884318909 switch (mod.intern_pool.indexToKey(val.toIntern())) {
......@@ -18847,29 +18913,33 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1884718913 },
1884818914 else => {},
1884918915 }
18850 const abi_align = @as(u32, @intCast((try val.getUnsignedIntAdvanced(mod, sema)).?));
18916 const abi_align: u32 = @intCast((try val.getUnsignedIntAdvanced(mod, sema)).?);
1885118917 try sema.validateAlign(block, align_src, abi_align);
1885218918 break :blk Alignment.fromByteUnits(abi_align);
1885318919 } else .none;
1885418920
1885518921 const address_space: std.builtin.AddressSpace = if (inst_data.flags.has_addrspace) blk: {
18856 const ref = @as(Zir.Inst.Ref, @enumFromInt(sema.code.extra[extra_i]));
18922 const ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_i]);
1885718923 extra_i += 1;
1885818924 break :blk try sema.analyzeAddressSpace(block, addrspace_src, ref, .pointer);
1885918925 } else if (elem_ty.zigTypeTag(mod) == .Fn and target.cpu.arch == .avr) .flash else .generic;
1886018926
18861 const bit_offset = if (inst_data.flags.has_bit_range) blk: {
18862 const ref = @as(Zir.Inst.Ref, @enumFromInt(sema.code.extra[extra_i]));
18927 const bit_offset: u16 = if (inst_data.flags.has_bit_range) blk: {
18928 const ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_i]);
1886318929 extra_i += 1;
18864 const bit_offset = try sema.resolveInt(block, bitoffset_src, ref, Type.u16, "pointer bit-offset must be comptime-known");
18865 break :blk @as(u16, @intCast(bit_offset));
18930 const bit_offset = try sema.resolveInt(block, bitoffset_src, ref, Type.u16, .{
18931 .needed_comptime_reason = "pointer bit-offset must be comptime-known",
18932 });
18933 break :blk @intCast(bit_offset);
1886618934 } else 0;
1886718935
1886818936 const host_size: u16 = if (inst_data.flags.has_bit_range) blk: {
18869 const ref = @as(Zir.Inst.Ref, @enumFromInt(sema.code.extra[extra_i]));
18937 const ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_i]);
1887018938 extra_i += 1;
18871 const host_size = try sema.resolveInt(block, hostsize_src, ref, Type.u16, "pointer host size must be comptime-known");
18872 break :blk @as(u16, @intCast(host_size));
18939 const host_size = try sema.resolveInt(block, hostsize_src, ref, Type.u16, .{
18940 .needed_comptime_reason = "pointer host size must be comptime-known",
18941 });
18942 break :blk @intCast(host_size);
1887318943 } else 0;
1887418944
1887518945 if (host_size != 0 and bit_offset >= host_size * 8) {
......@@ -18900,7 +18970,7 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1890018970 try sema.addDeclaredHereNote(msg, elem_ty);
1890118971 break :msg msg;
1890218972 };
18903 return sema.failWithOwnedErrorMsg(msg);
18973 return sema.failWithOwnedErrorMsg(block, msg);
1890418974 }
1890518975 if (elem_ty.zigTypeTag(mod) == .Opaque) {
1890618976 return sema.fail(block, elem_ty_src, "C pointers cannot point to opaque types", .{});
......@@ -18994,9 +19064,11 @@ fn zirUnionInit(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
1899419064 try sema.addDeclaredHereNote(msg, union_ty);
1899519065 break :msg msg;
1899619066 };
18997 return sema.failWithOwnedErrorMsg(msg);
19067 return sema.failWithOwnedErrorMsg(block, msg);
1899819068 }
18999 const field_name = try sema.resolveConstStringIntern(block, field_src, extra.field_name, "name of field being initialized must be comptime-known");
19069 const field_name = try sema.resolveConstStringIntern(block, field_src, extra.field_name, .{
19070 .needed_comptime_reason = "name of field being initialized must be comptime-known",
19071 });
1900019072 const init = try sema.resolveInst(extra.init);
1900119073 return sema.unionInit(block, init, init_src, union_ty, ty_src, field_name, field_src);
1900219074}
......@@ -19098,13 +19170,15 @@ fn zirStructInit(
1909819170 try sema.errNote(block, other_field_src, msg, "other field here", .{});
1909919171 break :msg msg;
1910019172 };
19101 return sema.failWithOwnedErrorMsg(msg);
19173 return sema.failWithOwnedErrorMsg(block, msg);
1910219174 }
1910319175 found_fields[field_index] = item.data.field_type;
1910419176 field_inits[field_index] = try sema.resolveInst(item.data.init);
1910519177 if (!is_packed) if (try resolved_ty.structFieldValueComptime(mod, field_index)) |default_value| {
1910619178 const init_val = (try sema.resolveMaybeUndefVal(field_inits[field_index])) orelse {
19107 return sema.failWithNeededComptime(block, field_src, "value stored in comptime field must be comptime-known");
19179 return sema.failWithNeededComptime(block, field_src, .{
19180 .needed_comptime_reason = "value stored in comptime field must be comptime-known",
19181 });
1910819182 };
1910919183
1911019184 if (!init_val.eql(default_value, resolved_ty.structFieldType(field_index, mod), mod)) {
......@@ -19238,7 +19312,7 @@ fn finishStructInit(
1923819312 );
1923919313 }
1924019314 root_msg = null;
19241 return sema.failWithOwnedErrorMsg(msg);
19315 return sema.failWithOwnedErrorMsg(block, msg);
1924219316 }
1924319317
1924419318 // Find which field forces the expression to be runtime, if any.
......@@ -19270,7 +19344,7 @@ fn finishStructInit(
1927019344 });
1927119345 const alloc = try block.addTy(.alloc, alloc_ty);
1927219346 for (field_inits, 0..) |field_init, i_usize| {
19273 const i = @as(u32, @intCast(i_usize));
19347 const i: u32 = @intCast(i_usize);
1927419348 const field_src = dest_src;
1927519349 const field_ptr = try sema.structFieldPtrByIndex(block, dest_src, alloc, i, field_src, struct_ty, true);
1927619350 try sema.storePtr(block, dest_src, field_ptr, field_init);
......@@ -19362,7 +19436,7 @@ fn structInitAnon(
1936219436 try sema.errNote(block, prev_source, msg, "other field here", .{});
1936319437 break :msg msg;
1936419438 };
19365 return sema.failWithOwnedErrorMsg(msg);
19439 return sema.failWithOwnedErrorMsg(block, msg);
1936619440 }
1936719441 gop.value_ptr.* = i;
1936819442
......@@ -19378,7 +19452,7 @@ fn structInitAnon(
1937819452 try sema.addDeclaredHereNote(msg, field_ty.toType());
1937919453 break :msg msg;
1938019454 };
19381 return sema.failWithOwnedErrorMsg(msg);
19455 return sema.failWithOwnedErrorMsg(block, msg);
1938219456 }
1938319457 if (try sema.resolveMaybeUndefVal(init)) |init_val| {
1938419458 values[i] = try init_val.intern(field_ty.toType(), mod);
......@@ -19423,7 +19497,7 @@ fn structInitAnon(
1942319497 const alloc = try block.addTy(.alloc, alloc_ty);
1942419498 var extra_index = extra_end;
1942519499 for (types, 0..) |field_ty, i_usize| {
19426 const i = @as(u32, @intCast(i_usize));
19500 const i: u32 = @intCast(i_usize);
1942719501 const item = switch (kind) {
1942819502 .anon_init => sema.code.extraData(Zir.Inst.StructInitAnon.Item, extra_index),
1942919503 .typed_init => sema.code.extraData(Zir.Inst.StructInit.Item, extra_index),
......@@ -19504,7 +19578,9 @@ fn zirArrayInit(
1950419578 const init_val = try sema.resolveMaybeUndefVal(resolved_args[i]) orelse {
1950519579 const decl = mod.declPtr(block.src_decl);
1950619580 const elem_src = mod.initSrc(src.node_offset.x, decl, i);
19507 return sema.failWithNeededComptime(block, elem_src, "value stored in comptime field must be comptime-known");
19581 return sema.failWithNeededComptime(block, elem_src, .{
19582 .needed_comptime_reason = "value stored in comptime field must be comptime-known",
19583 });
1950819584 };
1950919585 if (!field_val.eql(init_val, elem_ty, mod)) {
1951019586 const decl = mod.declPtr(block.src_decl);
......@@ -19520,7 +19596,7 @@ fn zirArrayInit(
1952019596
1952119597 const opt_runtime_index: ?u32 = for (resolved_args, 0..) |arg, i| {
1952219598 const comptime_known = try sema.isComptimeKnown(arg);
19523 if (!comptime_known) break @as(u32, @intCast(i));
19599 if (!comptime_known) break @intCast(i);
1952419600 } else null;
1952519601
1952619602 const runtime_index = opt_runtime_index orelse {
......@@ -19629,7 +19705,7 @@ fn arrayInitAnon(
1962919705 try sema.addDeclaredHereNote(msg, types[i].toType());
1963019706 break :msg msg;
1963119707 };
19632 return sema.failWithOwnedErrorMsg(msg);
19708 return sema.failWithOwnedErrorMsg(block, msg);
1963319709 }
1963419710 if (try sema.resolveMaybeUndefVal(elem)) |val| {
1963519711 values[i] = val.toIntern();
......@@ -19665,7 +19741,7 @@ fn arrayInitAnon(
1966519741 });
1966619742 const alloc = try block.addTy(.alloc, alloc_ty);
1966719743 for (operands, 0..) |operand, i_usize| {
19668 const i = @as(u32, @intCast(i_usize));
19744 const i: u32 = @intCast(i_usize);
1966919745 const field_ptr_ty = try mod.ptrType(.{
1967019746 .child = types[i],
1967119747 .flags = .{ .address_space = target_util.defaultAddressSpace(target, .local) },
......@@ -19712,7 +19788,9 @@ fn zirFieldTypeRef(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
1971219788 const ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
1971319789 const field_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };
1971419790 const aggregate_ty = try sema.resolveType(block, ty_src, extra.container_type);
19715 const field_name = try sema.resolveConstStringIntern(block, field_src, extra.field_name, "field name must be comptime-known");
19791 const field_name = try sema.resolveConstStringIntern(block, field_src, extra.field_name, .{
19792 .needed_comptime_reason = "field name must be comptime-known",
19793 });
1971619794 return sema.fieldType(block, aggregate_ty, field_name, field_src, ty_src);
1971719795}
1971819796
......@@ -19728,7 +19806,7 @@ fn zirFieldType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
1972819806 // generic poison should not result in a failed compilation, but the
1972919807 // generic poison type. This prevents unnecessary failures when
1973019808 // constructing types at compile-time.
19731 error.GenericPoison => return Air.Inst.Ref.generic_poison_type,
19809 error.GenericPoison => return .generic_poison_type,
1973219810 else => |e| return e,
1973319811 };
1973419812 const zir_field_name = sema.code.nullTerminatedString(extra.name_start);
......@@ -19818,7 +19896,7 @@ fn zirFrame(
1981819896 block: *Block,
1981919897 extended: Zir.Inst.Extended.InstData,
1982019898) CompileError!Air.Inst.Ref {
19821 const src = LazySrcLoc.nodeOffset(@as(i32, @bitCast(extended.operand)));
19899 const src = LazySrcLoc.nodeOffset(@bitCast(extended.operand));
1982219900 return sema.failWithUseOfAsync(block, src);
1982319901}
1982419902
......@@ -19983,7 +20061,7 @@ fn zirTagName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1998320061 try sema.resolveTypeLayout(operand_ty);
1998420062 const enum_ty = switch (operand_ty.zigTypeTag(mod)) {
1998520063 .EnumLiteral => {
19986 const val = try sema.resolveConstValue(block, .unneeded, operand, "");
20064 const val = try sema.resolveConstValue(block, .unneeded, operand, undefined);
1998720065 const tag_name = ip.indexToKey(val.toIntern()).enum_literal;
1998820066 return sema.addStrLit(block, ip.stringToSlice(tag_name));
1998920067 },
......@@ -19997,7 +20075,7 @@ fn zirTagName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1999720075 try sema.addDeclaredHereNote(msg, operand_ty);
1999820076 break :msg msg;
1999920077 };
20000 return sema.failWithOwnedErrorMsg(msg);
20078 return sema.failWithOwnedErrorMsg(block, msg);
2000120079 },
2000220080 else => return sema.fail(block, operand_src, "expected enum or union; found '{}'", .{
2000320081 operand_ty.fmt(mod),
......@@ -20023,7 +20101,7 @@ fn zirTagName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
2002320101 try mod.errNoteNonLazy(enum_decl.srcLoc(mod), msg, "declared here", .{});
2002420102 break :msg msg;
2002520103 };
20026 return sema.failWithOwnedErrorMsg(msg);
20104 return sema.failWithOwnedErrorMsg(block, msg);
2002720105 };
2002820106 // TODO: write something like getCoercedInts to avoid needing to dupe
2002920107 const field_name = enum_ty.enumFieldName(field_index, mod);
......@@ -20049,29 +20127,31 @@ fn zirReify(
2004920127 const mod = sema.mod;
2005020128 const gpa = sema.gpa;
2005120129 const ip = &mod.intern_pool;
20052 const name_strategy = @as(Zir.Inst.NameStrategy, @enumFromInt(extended.small));
20130 const name_strategy: Zir.Inst.NameStrategy = @enumFromInt(extended.small);
2005320131 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;
2005420132 const src = LazySrcLoc.nodeOffset(extra.node);
2005520133 const type_info_ty = try sema.getBuiltinType("Type");
2005620134 const uncasted_operand = try sema.resolveInst(extra.operand);
2005720135 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node };
2005820136 const type_info = try sema.coerce(block, type_info_ty, uncasted_operand, operand_src);
20059 const val = try sema.resolveConstValue(block, operand_src, type_info, "operand to @Type must be comptime-known");
20137 const val = try sema.resolveConstValue(block, operand_src, type_info, .{
20138 .needed_comptime_reason = "operand to @Type must be comptime-known",
20139 });
2006020140 const union_val = ip.indexToKey(val.toIntern()).un;
2006120141 const target = mod.getTarget();
2006220142 if (try union_val.val.toValue().anyUndef(mod)) return sema.failWithUseOfUndef(block, src);
2006320143 const tag_index = type_info_ty.unionTagFieldIndex(union_val.tag.toValue(), mod).?;
2006420144 switch (@as(std.builtin.TypeId, @enumFromInt(tag_index))) {
20065 .Type => return Air.Inst.Ref.type_type,
20066 .Void => return Air.Inst.Ref.void_type,
20067 .Bool => return Air.Inst.Ref.bool_type,
20068 .NoReturn => return Air.Inst.Ref.noreturn_type,
20069 .ComptimeFloat => return Air.Inst.Ref.comptime_float_type,
20070 .ComptimeInt => return Air.Inst.Ref.comptime_int_type,
20071 .Undefined => return Air.Inst.Ref.undefined_type,
20072 .Null => return Air.Inst.Ref.null_type,
20145 .Type => return .type_type,
20146 .Void => return .void_type,
20147 .Bool => return .bool_type,
20148 .NoReturn => return .noreturn_type,
20149 .ComptimeFloat => return .comptime_float_type,
20150 .ComptimeInt => return .comptime_int_type,
20151 .Undefined => return .undefined_type,
20152 .Null => return .null_type,
2007320153 .AnyFrame => return sema.failWithUseOfAsync(block, src),
20074 .EnumLiteral => return Air.Inst.Ref.enum_literal_type,
20154 .EnumLiteral => return .enum_literal_type,
2007520155 .Int => {
2007620156 const fields = ip.typeOf(union_val.val).toType().structFields(mod);
2007720157 const signedness_val = try union_val.val.toValue().fieldValue(
......@@ -20084,7 +20164,7 @@ fn zirReify(
2008420164 );
2008520165
2008620166 const signedness = mod.toEnum(std.builtin.Signedness, signedness_val);
20087 const bits = @as(u16, @intCast(bits_val.toUnsignedInt(mod)));
20167 const bits: u16 = @intCast(bits_val.toUnsignedInt(mod));
2008820168 const ty = try mod.intType(signedness, bits);
2008920169 return Air.internedToRef(ty.toIntern());
2009020170 },
......@@ -20097,7 +20177,7 @@ fn zirReify(
2009720177 try ip.getOrPutString(gpa, "child"),
2009820178 ).?);
2009920179
20100 const len = @as(u32, @intCast(len_val.toUnsignedInt(mod)));
20180 const len: u32 = @intCast(len_val.toUnsignedInt(mod));
2010120181 const child_ty = child_val.toType();
2010220182
2010320183 try sema.checkVectorElemType(block, src, child_ty);
......@@ -20114,7 +20194,7 @@ fn zirReify(
2011420194 try ip.getOrPutString(gpa, "bits"),
2011520195 ).?);
2011620196
20117 const bits = @as(u16, @intCast(bits_val.toUnsignedInt(mod)));
20197 const bits: u16 = @intCast(bits_val.toUnsignedInt(mod));
2011820198 const ty = switch (bits) {
2011920199 16 => Type.f16,
2012020200 32 => Type.f32,
......@@ -20206,7 +20286,7 @@ fn zirReify(
2020620286 try sema.addDeclaredHereNote(msg, elem_ty);
2020720287 break :msg msg;
2020820288 };
20209 return sema.failWithOwnedErrorMsg(msg);
20289 return sema.failWithOwnedErrorMsg(block, msg);
2021020290 }
2021120291 if (elem_ty.zigTypeTag(mod) == .Opaque) {
2021220292 return sema.fail(block, src, "C pointers cannot point to opaque types", .{});
......@@ -20382,7 +20462,7 @@ fn zirReify(
2038220462 }
2038320463
2038420464 // Define our empty enum decl
20385 const fields_len = @as(u32, @intCast(try sema.usizeCast(block, src, fields_val.sliceLen(mod))));
20465 const fields_len: u32 = @intCast(try sema.usizeCast(block, src, fields_val.sliceLen(mod)));
2038620466 const incomplete_enum = try ip.getIncompleteEnum(gpa, .{
2038720467 .decl = new_decl_index,
2038820468 .namespace = .none,
......@@ -20431,7 +20511,7 @@ fn zirReify(
2043120511 try sema.errNote(block, src, msg, "other field here", .{});
2043220512 break :msg msg;
2043320513 };
20434 return sema.failWithOwnedErrorMsg(msg);
20514 return sema.failWithOwnedErrorMsg(block, msg);
2043520515 }
2043620516
2043720517 if (try incomplete_enum.addFieldValue(ip, gpa, (try mod.getCoerced(value_val, int_tag_ty)).toIntern())) |other| {
......@@ -20442,7 +20522,7 @@ fn zirReify(
2044220522 try sema.errNote(block, src, msg, "other enum tag value here", .{});
2044320523 break :msg msg;
2044420524 };
20445 return sema.failWithOwnedErrorMsg(msg);
20525 return sema.failWithOwnedErrorMsg(block, msg);
2044620526 }
2044720527 }
2044820528
......@@ -20579,7 +20659,7 @@ fn zirReify(
2057920659 try sema.addDeclaredHereNote(msg, enum_tag_ty.toType());
2058020660 break :msg msg;
2058120661 };
20582 return sema.failWithOwnedErrorMsg(msg);
20662 return sema.failWithOwnedErrorMsg(block, msg);
2058320663 };
2058420664 // No check for duplicate because the check already happened in order
2058520665 // to create the enum type in the first place.
......@@ -20610,7 +20690,7 @@ fn zirReify(
2061020690 try sema.addDeclaredHereNote(msg, field_ty);
2061120691 break :msg msg;
2061220692 };
20613 return sema.failWithOwnedErrorMsg(msg);
20693 return sema.failWithOwnedErrorMsg(block, msg);
2061420694 }
2061520695 if (layout == .Extern and !try sema.validateExternType(field_ty, .union_field)) {
2061620696 const msg = msg: {
......@@ -20623,7 +20703,7 @@ fn zirReify(
2062320703 try sema.addDeclaredHereNote(msg, field_ty);
2062420704 break :msg msg;
2062520705 };
20626 return sema.failWithOwnedErrorMsg(msg);
20706 return sema.failWithOwnedErrorMsg(block, msg);
2062720707 } else if (layout == .Packed and !(validatePackedType(field_ty, mod))) {
2062820708 const msg = msg: {
2062920709 const msg = try sema.errMsg(block, src, "packed unions cannot contain fields of type '{}'", .{field_ty.fmt(mod)});
......@@ -20635,7 +20715,7 @@ fn zirReify(
2063520715 try sema.addDeclaredHereNote(msg, field_ty);
2063620716 break :msg msg;
2063720717 };
20638 return sema.failWithOwnedErrorMsg(msg);
20718 return sema.failWithOwnedErrorMsg(block, msg);
2063920719 }
2064020720 }
2064120721
......@@ -20655,7 +20735,7 @@ fn zirReify(
2065520735 try sema.addDeclaredHereNote(msg, enum_tag_ty.toType());
2065620736 break :msg msg;
2065720737 };
20658 return sema.failWithOwnedErrorMsg(msg);
20738 return sema.failWithOwnedErrorMsg(block, msg);
2065920739 }
2066020740 } else {
2066120741 enum_tag_ty = try sema.generateUnionTagTypeSimple(block, enum_field_names, .none);
......@@ -20753,7 +20833,7 @@ fn zirReify(
2075320833 if (!try sema.intFitsInType(alignment_val, Type.u32, null)) {
2075420834 return sema.fail(block, src, "alignment must fit in 'u32'", .{});
2075520835 }
20756 const alignment = @as(u29, @intCast(alignment_val.toUnsignedInt(mod)));
20836 const alignment: u29 = @intCast(alignment_val.toUnsignedInt(mod));
2075720837 if (alignment == target_util.defaultFunctionAlignment(target)) {
2075820838 break :alignment .none;
2075920839 } else {
......@@ -20948,7 +21028,9 @@ fn reifyStruct(
2094821028 const field_ty = type_val.toType();
2094921029 const default_val = if (default_value_val.optionalValue(mod)) |opt_val|
2095021030 (try sema.pointerDeref(block, src, opt_val, try mod.singleConstPtrType(field_ty)) orelse
20951 return sema.failWithNeededComptime(block, src, "struct field default value must be comptime-known")).toIntern()
21031 return sema.failWithNeededComptime(block, src, .{
21032 .needed_comptime_reason = "struct field default value must be comptime-known",
21033 })).toIntern()
2095221034 else
2095321035 .none;
2095421036 if (is_comptime_val.toBool() and default_val == .none) {
......@@ -20971,7 +21053,7 @@ fn reifyStruct(
2097121053 try sema.addDeclaredHereNote(msg, field_ty);
2097221054 break :msg msg;
2097321055 };
20974 return sema.failWithOwnedErrorMsg(msg);
21056 return sema.failWithOwnedErrorMsg(block, msg);
2097521057 }
2097621058 if (field_ty.zigTypeTag(mod) == .NoReturn) {
2097721059 const msg = msg: {
......@@ -20981,7 +21063,7 @@ fn reifyStruct(
2098121063 try sema.addDeclaredHereNote(msg, field_ty);
2098221064 break :msg msg;
2098321065 };
20984 return sema.failWithOwnedErrorMsg(msg);
21066 return sema.failWithOwnedErrorMsg(block, msg);
2098521067 }
2098621068 if (struct_obj.layout == .Extern and !try sema.validateExternType(field_ty, .struct_field)) {
2098721069 const msg = msg: {
......@@ -20994,7 +21076,7 @@ fn reifyStruct(
2099421076 try sema.addDeclaredHereNote(msg, field_ty);
2099521077 break :msg msg;
2099621078 };
20997 return sema.failWithOwnedErrorMsg(msg);
21079 return sema.failWithOwnedErrorMsg(block, msg);
2099821080 } else if (struct_obj.layout == .Packed and !(validatePackedType(field_ty, mod))) {
2099921081 const msg = msg: {
2100021082 const msg = try sema.errMsg(block, src, "packed structs cannot contain fields of type '{}'", .{field_ty.fmt(sema.mod)});
......@@ -21006,7 +21088,7 @@ fn reifyStruct(
2100621088 try sema.addDeclaredHereNote(msg, field_ty);
2100721089 break :msg msg;
2100821090 };
21009 return sema.failWithOwnedErrorMsg(msg);
21091 return sema.failWithOwnedErrorMsg(block, msg);
2101021092 }
2101121093 }
2101221094
......@@ -21034,7 +21116,7 @@ fn reifyStruct(
2103421116 try sema.checkBackingIntType(block, src, backing_int_ty, fields_bit_sum);
2103521117 struct_obj.backing_int_ty = backing_int_ty;
2103621118 } else {
21037 struct_obj.backing_int_ty = try mod.intType(.unsigned, @as(u16, @intCast(fields_bit_sum)));
21119 struct_obj.backing_int_ty = try mod.intType(.unsigned, @intCast(fields_bit_sum));
2103821120 }
2103921121
2104021122 struct_obj.status = .have_layout;
......@@ -21074,7 +21156,7 @@ fn zirCVaArg(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) C
2107421156 try sema.addDeclaredHereNote(msg, arg_ty);
2107521157 break :msg msg;
2107621158 };
21077 return sema.failWithOwnedErrorMsg(msg);
21159 return sema.failWithOwnedErrorMsg(block, msg);
2107821160 }
2107921161
2108021162 try sema.requireRuntimeBlock(block, src, null);
......@@ -21105,7 +21187,7 @@ fn zirCVaEnd(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) C
2110521187}
2110621188
2110721189fn zirCVaStart(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!Air.Inst.Ref {
21108 const src = LazySrcLoc.nodeOffset(@as(i32, @bitCast(extended.operand)));
21190 const src = LazySrcLoc.nodeOffset(@bitCast(extended.operand));
2110921191
2111021192 const va_list_ty = try sema.getBuiltinType("VaList");
2111121193 try sema.requireRuntimeBlock(block, src, null);
......@@ -21180,7 +21262,9 @@ fn zirIntFromFloat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
2118021262 const result_val = try sema.intFromFloat(block, operand_src, operand_val, operand_ty, dest_ty);
2118121263 return Air.internedToRef(result_val.toIntern());
2118221264 } else if (dest_scalar_ty.zigTypeTag(mod) == .ComptimeInt) {
21183 return sema.failWithNeededComptime(block, operand_src, "value being casted to 'comptime_int' must be comptime-known");
21265 return sema.failWithNeededComptime(block, operand_src, .{
21266 .needed_comptime_reason = "value being casted to 'comptime_int' must be comptime-known",
21267 });
2118421268 }
2118521269
2118621270 try sema.requireRuntimeBlock(block, inst_data.src(), operand_src);
......@@ -21260,7 +21344,9 @@ fn zirFloatFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
2126021344 const result_val = try operand_val.floatFromIntAdvanced(sema.arena, operand_ty, dest_ty, mod, sema);
2126121345 return Air.internedToRef(result_val.toIntern());
2126221346 } else if (dest_scalar_ty.zigTypeTag(mod) == .ComptimeFloat) {
21263 return sema.failWithNeededComptime(block, operand_src, "value being casted to 'comptime_float' must be comptime-known");
21347 return sema.failWithNeededComptime(block, operand_src, .{
21348 .needed_comptime_reason = "value being casted to 'comptime_float' must be comptime-known",
21349 });
2126421350 }
2126521351
2126621352 try sema.requireRuntimeBlock(block, src, operand_src);
......@@ -21311,7 +21397,7 @@ fn zirPtrFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
2131121397 try sema.errNote(block, src, msg, "slice length cannot be inferred from address", .{});
2131221398 break :msg msg;
2131321399 };
21314 return sema.failWithOwnedErrorMsg(msg);
21400 return sema.failWithOwnedErrorMsg(block, msg);
2131521401 }
2131621402
2131721403 if (try sema.resolveDefinedValue(block, operand_src, operand_coerced)) |val| {
......@@ -21447,7 +21533,7 @@ fn zirErrSetCast(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat
2144721533 try sema.addDeclaredHereNote(msg, dest_ty);
2144821534 break :msg msg;
2144921535 };
21450 return sema.failWithOwnedErrorMsg(msg);
21536 return sema.failWithOwnedErrorMsg(block, msg);
2145121537 }
2145221538
2145321539 if (maybe_operand_val) |val| {
......@@ -21465,7 +21551,7 @@ fn zirErrSetCast(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat
2146521551 try sema.addDeclaredHereNote(msg, dest_ty);
2146621552 break :msg msg;
2146721553 };
21468 return sema.failWithOwnedErrorMsg(msg);
21554 return sema.failWithOwnedErrorMsg(block, msg);
2146921555 }
2147021556 }
2147121557
......@@ -21482,7 +21568,10 @@ fn zirErrSetCast(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat
2148221568}
2148321569
2148421570fn zirPtrCastFull(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!Air.Inst.Ref {
21485 const flags: Zir.Inst.FullPtrCastFlags = @bitCast(@as(u5, @truncate(extended.small)));
21571 const flags: Zir.Inst.FullPtrCastFlags = @bitCast(@as(
21572 @typeInfo(Zir.Inst.FullPtrCastFlags).Struct.backing_integer.?,
21573 @truncate(extended.small),
21574 ));
2148621575 const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data;
2148721576 const src = LazySrcLoc.nodeOffset(extra.node);
2148821577 const operand_src: LazySrcLoc = .{ .node_offset_ptrcast_operand = extra.node };
......@@ -21568,7 +21657,7 @@ fn ptrCastFull(
2156821657 if (src_slice_like and dest_slice_like) break :check_size;
2156921658 if (src_info.flags.size == .C) break :check_size;
2157021659 if (dest_info.flags.size == .C) break :check_size;
21571 return sema.failWithOwnedErrorMsg(msg: {
21660 return sema.failWithOwnedErrorMsg(block, msg: {
2157221661 const msg = try sema.errMsg(block, src, "cannot implicitly convert {s} pointer to {s} pointer", .{
2157321662 pointerSizeString(src_info.flags.size),
2157421663 pointerSizeString(dest_info.flags.size),
......@@ -21604,7 +21693,7 @@ fn ptrCastFull(
2160421693 operand_src,
2160521694 );
2160621695 if (imc_res == .ok) break :check_child;
21607 return sema.failWithOwnedErrorMsg(msg: {
21696 return sema.failWithOwnedErrorMsg(block, msg: {
2160821697 const msg = try sema.errMsg(block, src, "pointer element type '{}' cannot coerce into element type '{}'", .{
2160921698 src_child.fmt(mod),
2161021699 dest_child.fmt(mod),
......@@ -21631,7 +21720,7 @@ fn ptrCastFull(
2163121720 if (dest_info.sentinel == coerced_sent) break :check_sent;
2163221721 }
2163321722 }
21634 return sema.failWithOwnedErrorMsg(msg: {
21723 return sema.failWithOwnedErrorMsg(block, msg: {
2163521724 const msg = if (src_info.sentinel == .none) blk: {
2163621725 break :blk try sema.errMsg(block, src, "destination pointer requires '{}' sentinel", .{
2163721726 dest_info.sentinel.toValue().fmtValue(dest_info.child.toType(), mod),
......@@ -21649,7 +21738,7 @@ fn ptrCastFull(
2164921738 }
2165021739
2165121740 if (src_info.packed_offset.host_size != dest_info.packed_offset.host_size) {
21652 return sema.failWithOwnedErrorMsg(msg: {
21741 return sema.failWithOwnedErrorMsg(block, msg: {
2165321742 const msg = try sema.errMsg(block, src, "pointer host size '{}' cannot coerce into pointer host size '{}'", .{
2165421743 src_info.packed_offset.host_size,
2165521744 dest_info.packed_offset.host_size,
......@@ -21661,7 +21750,7 @@ fn ptrCastFull(
2166121750 }
2166221751
2166321752 if (src_info.packed_offset.bit_offset != dest_info.packed_offset.bit_offset) {
21664 return sema.failWithOwnedErrorMsg(msg: {
21753 return sema.failWithOwnedErrorMsg(block, msg: {
2166521754 const msg = try sema.errMsg(block, src, "pointer bit offset '{}' cannot coerce into pointer bit offset '{}'", .{
2166621755 src_info.packed_offset.bit_offset,
2166721756 dest_info.packed_offset.bit_offset,
......@@ -21678,7 +21767,7 @@ fn ptrCastFull(
2167821767 if (!src_allows_zero) break :check_allowzero;
2167921768 if (dest_allows_zero) break :check_allowzero;
2168021769
21681 return sema.failWithOwnedErrorMsg(msg: {
21770 return sema.failWithOwnedErrorMsg(block, msg: {
2168221771 const msg = try sema.errMsg(block, src, "'{}' could have null values which are illegal in type '{}'", .{
2168321772 operand_ty.fmt(mod),
2168421773 dest_ty.fmt(mod),
......@@ -21696,7 +21785,7 @@ fn ptrCastFull(
2169621785 const dest_align = dest_info.flags.alignment.toByteUnitsOptional() orelse dest_info.child.toType().abiAlignment(mod);
2169721786 if (!flags.align_cast) {
2169821787 if (dest_align > src_align) {
21699 return sema.failWithOwnedErrorMsg(msg: {
21788 return sema.failWithOwnedErrorMsg(block, msg: {
2170021789 const msg = try sema.errMsg(block, src, "cast increases pointer alignment", .{});
2170121790 errdefer msg.destroy(sema.gpa);
2170221791 try sema.errNote(block, operand_src, msg, "'{}' has alignment '{d}'", .{
......@@ -21713,7 +21802,7 @@ fn ptrCastFull(
2171321802
2171421803 if (!flags.addrspace_cast) {
2171521804 if (src_info.flags.address_space != dest_info.flags.address_space) {
21716 return sema.failWithOwnedErrorMsg(msg: {
21805 return sema.failWithOwnedErrorMsg(block, msg: {
2171721806 const msg = try sema.errMsg(block, src, "cast changes pointer address space", .{});
2171821807 errdefer msg.destroy(sema.gpa);
2171921808 try sema.errNote(block, operand_src, msg, "'{}' has address space '{s}'", .{
......@@ -21729,7 +21818,7 @@ fn ptrCastFull(
2172921818 } else {
2173021819 // Some address space casts are always disallowed
2173121820 if (!target_util.addrSpaceCastIsValid(mod.getTarget(), src_info.flags.address_space, dest_info.flags.address_space)) {
21732 return sema.failWithOwnedErrorMsg(msg: {
21821 return sema.failWithOwnedErrorMsg(block, msg: {
2173321822 const msg = try sema.errMsg(block, src, "invalid address space cast", .{});
2173421823 errdefer msg.destroy(sema.gpa);
2173521824 try sema.errNote(block, operand_src, msg, "address space '{s}' is not compatible with address space '{s}'", .{
......@@ -21743,7 +21832,7 @@ fn ptrCastFull(
2174321832
2174421833 if (!flags.const_cast) {
2174521834 if (src_info.flags.is_const and !dest_info.flags.is_const) {
21746 return sema.failWithOwnedErrorMsg(msg: {
21835 return sema.failWithOwnedErrorMsg(block, msg: {
2174721836 const msg = try sema.errMsg(block, src, "cast discards const qualifier", .{});
2174821837 errdefer msg.destroy(sema.gpa);
2174921838 try sema.errNote(block, src, msg, "use @constCast to discard const qualifier", .{});
......@@ -21754,7 +21843,7 @@ fn ptrCastFull(
2175421843
2175521844 if (!flags.volatile_cast) {
2175621845 if (src_info.flags.is_volatile and !dest_info.flags.is_volatile) {
21757 return sema.failWithOwnedErrorMsg(msg: {
21846 return sema.failWithOwnedErrorMsg(block, msg: {
2175821847 const msg = try sema.errMsg(block, src, "cast discards volatile qualifier", .{});
2175921848 errdefer msg.destroy(sema.gpa);
2176021849 try sema.errNote(block, src, msg, "use @volatileCast to discard volatile qualifier", .{});
......@@ -21885,7 +21974,10 @@ fn ptrCastFull(
2188521974
2188621975fn zirPtrCastNoDest(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!Air.Inst.Ref {
2188721976 const mod = sema.mod;
21888 const flags = @as(Zir.Inst.FullPtrCastFlags, @bitCast(@as(u5, @truncate(extended.small))));
21977 const flags: Zir.Inst.FullPtrCastFlags = @bitCast(@as(
21978 @typeInfo(Zir.Inst.FullPtrCastFlags).Struct.backing_integer.?,
21979 @truncate(extended.small),
21980 ));
2188921981 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;
2189021982 const src = LazySrcLoc.nodeOffset(extra.node);
2189121983 const operand_src: LazySrcLoc = .{ .node_offset_ptrcast_operand = extra.node };
......@@ -21962,7 +22054,7 @@ fn zirTruncate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
2196222054 });
2196322055 break :msg msg;
2196422056 };
21965 return sema.failWithOwnedErrorMsg(msg);
22057 return sema.failWithOwnedErrorMsg(block, msg);
2196622058 }
2196722059 }
2196822060
......@@ -22174,7 +22266,9 @@ fn bitOffsetOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!u6
2217422266 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
2217522267
2217622268 const ty = try sema.resolveType(block, lhs_src, extra.lhs);
22177 const field_name = try sema.resolveConstStringIntern(block, rhs_src, extra.rhs, "name of field must be comptime-known");
22269 const field_name = try sema.resolveConstStringIntern(block, rhs_src, extra.rhs, .{
22270 .needed_comptime_reason = "name of field must be comptime-known",
22271 });
2217822272
2217922273 const mod = sema.mod;
2218022274 try sema.resolveTypeLayout(ty);
......@@ -22187,7 +22281,7 @@ fn bitOffsetOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!u6
2218722281 try sema.addDeclaredHereNote(msg, ty);
2218822282 break :msg msg;
2218922283 };
22190 return sema.failWithOwnedErrorMsg(msg);
22284 return sema.failWithOwnedErrorMsg(block, msg);
2219122285 },
2219222286 }
2219322287
......@@ -22298,7 +22392,7 @@ fn checkPtrOperand(
2229822392
2229922393 break :msg msg;
2230022394 };
22301 return sema.failWithOwnedErrorMsg(msg);
22395 return sema.failWithOwnedErrorMsg(block, msg);
2230222396 },
2230322397 .Optional => if (ty.childType(mod).zigTypeTag(mod) == .Pointer) return,
2230422398 else => {},
......@@ -22329,7 +22423,7 @@ fn checkPtrType(
2232922423
2233022424 break :msg msg;
2233122425 };
22332 return sema.failWithOwnedErrorMsg(msg);
22426 return sema.failWithOwnedErrorMsg(block, msg);
2233322427 },
2233422428 .Optional => if (ty.childType(mod).zigTypeTag(mod) == .Pointer) return,
2233522429 else => {},
......@@ -22470,7 +22564,7 @@ fn checkComptimeVarStore(
2247022564 try sema.errNote(block, cond_src, msg, "runtime condition here", .{});
2247122565 break :msg msg;
2247222566 };
22473 return sema.failWithOwnedErrorMsg(msg);
22567 return sema.failWithOwnedErrorMsg(block, msg);
2247422568 }
2247522569 if (block.runtime_loop) |loop_src| {
2247622570 const msg = msg: {
......@@ -22479,7 +22573,7 @@ fn checkComptimeVarStore(
2247922573 try sema.errNote(block, loop_src, msg, "non-inline loop here", .{});
2248022574 break :msg msg;
2248122575 };
22482 return sema.failWithOwnedErrorMsg(msg);
22576 return sema.failWithOwnedErrorMsg(block, msg);
2248322577 }
2248422578 unreachable;
2248522579 }
......@@ -22621,7 +22715,7 @@ fn checkVectorizableBinaryOperands(
2262122715 try sema.errNote(block, rhs_src, msg, "length {d} here", .{rhs_len});
2262222716 break :msg msg;
2262322717 };
22624 return sema.failWithOwnedErrorMsg(msg);
22718 return sema.failWithOwnedErrorMsg(block, msg);
2262522719 }
2262622720 } else {
2262722721 const msg = msg: {
......@@ -22638,7 +22732,7 @@ fn checkVectorizableBinaryOperands(
2263822732 }
2263922733 break :msg msg;
2264022734 };
22641 return sema.failWithOwnedErrorMsg(msg);
22735 return sema.failWithOwnedErrorMsg(block, msg);
2264222736 }
2264322737}
2264422738
......@@ -22667,16 +22761,22 @@ fn resolveExportOptions(
2266722761 const visibility_src = sema.maybeOptionsSrc(block, src, "visibility");
2266822762
2266922763 const name_operand = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "name"), name_src);
22670 const name_val = try sema.resolveConstValue(block, name_src, name_operand, "name of exported value must be comptime-known");
22764 const name_val = try sema.resolveConstValue(block, name_src, name_operand, .{
22765 .needed_comptime_reason = "name of exported value must be comptime-known",
22766 });
2267122767 const name_ty = Type.slice_const_u8;
2267222768 const name = try name_val.toAllocatedBytes(name_ty, sema.arena, mod);
2267322769
2267422770 const linkage_operand = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "linkage"), linkage_src);
22675 const linkage_val = try sema.resolveConstValue(block, linkage_src, linkage_operand, "linkage of exported value must be comptime-known");
22771 const linkage_val = try sema.resolveConstValue(block, linkage_src, linkage_operand, .{
22772 .needed_comptime_reason = "linkage of exported value must be comptime-known",
22773 });
2267622774 const linkage = mod.toEnum(std.builtin.GlobalLinkage, linkage_val);
2267722775
2267822776 const section_operand = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "section"), section_src);
22679 const section_opt_val = try sema.resolveConstValue(block, section_src, section_operand, "linksection of exported value must be comptime-known");
22777 const section_opt_val = try sema.resolveConstValue(block, section_src, section_operand, .{
22778 .needed_comptime_reason = "linksection of exported value must be comptime-known",
22779 });
2268022780 const section_ty = Type.slice_const_u8;
2268122781 const section = if (section_opt_val.optionalValue(mod)) |section_val|
2268222782 try section_val.toAllocatedBytes(section_ty, sema.arena, mod)
......@@ -22684,7 +22784,9 @@ fn resolveExportOptions(
2268422784 null;
2268522785
2268622786 const visibility_operand = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "visibility"), visibility_src);
22687 const visibility_val = try sema.resolveConstValue(block, visibility_src, visibility_operand, "visibility of exported value must be comptime-known");
22787 const visibility_val = try sema.resolveConstValue(block, visibility_src, visibility_operand, .{
22788 .needed_comptime_reason = "visibility of exported value must be comptime-known",
22789 });
2268822790 const visibility = mod.toEnum(std.builtin.SymbolVisibility, visibility_val);
2268922791
2269022792 if (name.len < 1) {
......@@ -22711,7 +22813,7 @@ fn resolveBuiltinEnum(
2271122813 src: LazySrcLoc,
2271222814 zir_ref: Zir.Inst.Ref,
2271322815 comptime name: []const u8,
22714 reason: []const u8,
22816 reason: NeededComptimeReason,
2271522817) CompileError!@field(std.builtin, name) {
2271622818 const mod = sema.mod;
2271722819 const ty = try sema.getBuiltinType(name);
......@@ -22726,7 +22828,7 @@ fn resolveAtomicOrder(
2272622828 block: *Block,
2272722829 src: LazySrcLoc,
2272822830 zir_ref: Zir.Inst.Ref,
22729 reason: []const u8,
22831 reason: NeededComptimeReason,
2273022832) CompileError!std.builtin.AtomicOrder {
2273122833 return sema.resolveBuiltinEnum(block, src, zir_ref, "AtomicOrder", reason);
2273222834}
......@@ -22737,7 +22839,9 @@ fn resolveAtomicRmwOp(
2273722839 src: LazySrcLoc,
2273822840 zir_ref: Zir.Inst.Ref,
2273922841) CompileError!std.builtin.AtomicRmwOp {
22740 return sema.resolveBuiltinEnum(block, src, zir_ref, "AtomicRmwOp", "@atomicRmW operation must be comptime-known");
22842 return sema.resolveBuiltinEnum(block, src, zir_ref, "AtomicRmwOp", .{
22843 .needed_comptime_reason = "@atomicRmW operation must be comptime-known",
22844 });
2274122845}
2274222846
2274322847fn zirCmpxchg(
......@@ -22774,8 +22878,12 @@ fn zirCmpxchg(
2277422878 const uncasted_ptr = try sema.resolveInst(extra.ptr);
2277522879 const ptr = try sema.checkAtomicPtrOperand(block, elem_ty, elem_ty_src, uncasted_ptr, ptr_src, false);
2277622880 const new_value = try sema.coerce(block, elem_ty, try sema.resolveInst(extra.new_value), new_value_src);
22777 const success_order = try sema.resolveAtomicOrder(block, success_order_src, extra.success_order, "atomic order of cmpxchg success must be comptime-known");
22778 const failure_order = try sema.resolveAtomicOrder(block, failure_order_src, extra.failure_order, "atomic order of cmpxchg failure must be comptime-known");
22881 const success_order = try sema.resolveAtomicOrder(block, success_order_src, extra.success_order, .{
22882 .needed_comptime_reason = "atomic order of cmpxchg success must be comptime-known",
22883 });
22884 const failure_order = try sema.resolveAtomicOrder(block, failure_order_src, extra.failure_order, .{
22885 .needed_comptime_reason = "atomic order of cmpxchg failure must be comptime-known",
22886 });
2277922887
2278022888 if (@intFromEnum(success_order) < @intFromEnum(std.builtin.AtomicOrder.Monotonic)) {
2278122889 return sema.fail(block, success_order_src, "success atomic ordering must be Monotonic or stricter", .{});
......@@ -22867,7 +22975,9 @@ fn zirReduce(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
2286722975 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
2286822976 const op_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
2286922977 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };
22870 const operation = try sema.resolveBuiltinEnum(block, op_src, extra.lhs, "ReduceOp", "@reduce operation must be comptime-known");
22978 const operation = try sema.resolveBuiltinEnum(block, op_src, extra.lhs, "ReduceOp", .{
22979 .needed_comptime_reason = "@reduce operation must be comptime-known",
22980 });
2287122981 const operand = try sema.resolveInst(extra.rhs);
2287222982 const operand_ty = sema.typeOf(operand);
2287322983 const mod = sema.mod;
......@@ -22950,12 +23060,14 @@ fn zirShuffle(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
2295023060 else => return sema.fail(block, mask_src, "expected vector or array, found '{}'", .{sema.typeOf(mask).fmt(sema.mod)}),
2295123061 };
2295223062 mask_ty = try mod.vectorType(.{
22953 .len = @as(u32, @intCast(mask_len)),
23063 .len = @intCast(mask_len),
2295423064 .child = .i32_type,
2295523065 });
2295623066 mask = try sema.coerce(block, mask_ty, mask, mask_src);
22957 const mask_val = try sema.resolveConstMaybeUndefVal(block, mask_src, mask, "shuffle mask must be comptime-known");
22958 return sema.analyzeShuffle(block, inst_data.src_node, elem_ty, a, b, mask_val, @as(u32, @intCast(mask_len)));
23067 const mask_val = try sema.resolveConstMaybeUndefVal(block, mask_src, mask, .{
23068 .needed_comptime_reason = "shuffle mask must be comptime-known",
23069 });
23070 return sema.analyzeShuffle(block, inst_data.src_node, elem_ty, a, b, mask_val, @intCast(mask_len));
2295923071}
2296023072
2296123073fn analyzeShuffle(
......@@ -22999,8 +23111,8 @@ fn analyzeShuffle(
2299923111 if (maybe_a_len == null and maybe_b_len == null) {
2300023112 return mod.undefRef(res_ty);
2300123113 }
23002 const a_len = @as(u32, @intCast(maybe_a_len orelse maybe_b_len.?));
23003 const b_len = @as(u32, @intCast(maybe_b_len orelse a_len));
23114 const a_len: u32 = @intCast(maybe_a_len orelse maybe_b_len.?);
23115 const b_len: u32 = @intCast(maybe_b_len orelse a_len);
2300423116
2300523117 const a_ty = try mod.vectorType(.{
2300623118 .len = a_len,
......@@ -23019,17 +23131,17 @@ fn analyzeShuffle(
2301923131 .{ b_len, b_src, b_ty },
2302023132 };
2302123133
23022 for (0..@as(usize, @intCast(mask_len))) |i| {
23134 for (0..@intCast(mask_len)) |i| {
2302323135 const elem = try mask.elemValue(sema.mod, i);
2302423136 if (elem.isUndef(mod)) continue;
2302523137 const int = elem.toSignedInt(mod);
2302623138 var unsigned: u32 = undefined;
2302723139 var chosen: u32 = undefined;
2302823140 if (int >= 0) {
23029 unsigned = @as(u32, @intCast(int));
23141 unsigned = @intCast(int);
2303023142 chosen = 0;
2303123143 } else {
23032 unsigned = @as(u32, @intCast(~int));
23144 unsigned = @intCast(~int);
2303323145 chosen = 1;
2303423146 }
2303523147 if (unsigned >= operand_info[chosen][0]) {
......@@ -23048,7 +23160,7 @@ fn analyzeShuffle(
2304823160
2304923161 break :msg msg;
2305023162 };
23051 return sema.failWithOwnedErrorMsg(msg);
23163 return sema.failWithOwnedErrorMsg(block, msg);
2305223164 }
2305323165 }
2305423166
......@@ -23062,7 +23174,7 @@ fn analyzeShuffle(
2306223174 continue;
2306323175 }
2306423176 const int = mask_elem_val.toSignedInt(mod);
23065 const unsigned = if (int >= 0) @as(u32, @intCast(int)) else @as(u32, @intCast(~int));
23177 const unsigned: u32 = @intCast(if (int >= 0) int else ~int);
2306623178 values[i] = try (try (if (int >= 0) a_val else b_val).elemValue(mod, unsigned)).intern(elem_ty, mod);
2306723179 }
2306823180 return Air.internedToRef((try mod.intern(.{ .aggregate = .{
......@@ -23083,23 +23195,23 @@ fn analyzeShuffle(
2308323195 const max_len = try sema.usizeCast(block, max_src, @max(a_len, b_len));
2308423196
2308523197 const expand_mask_values = try sema.arena.alloc(InternPool.Index, max_len);
23086 for (@as(usize, @intCast(0))..@as(usize, @intCast(min_len))) |i| {
23198 for (@intCast(0)..@intCast(min_len)) |i| {
2308723199 expand_mask_values[i] = (try mod.intValue(Type.comptime_int, i)).toIntern();
2308823200 }
23089 for (@as(usize, @intCast(min_len))..@as(usize, @intCast(max_len))) |i| {
23201 for (@intCast(min_len)..@intCast(max_len)) |i| {
2309023202 expand_mask_values[i] = (try mod.intValue(Type.comptime_int, -1)).toIntern();
2309123203 }
2309223204 const expand_mask = try mod.intern(.{ .aggregate = .{
23093 .ty = (try mod.vectorType(.{ .len = @as(u32, @intCast(max_len)), .child = .comptime_int_type })).toIntern(),
23205 .ty = (try mod.vectorType(.{ .len = @intCast(max_len), .child = .comptime_int_type })).toIntern(),
2309423206 .storage = .{ .elems = expand_mask_values },
2309523207 } });
2309623208
2309723209 if (a_len < b_len) {
2309823210 const undef = try mod.undefRef(a_ty);
23099 a = try sema.analyzeShuffle(block, src_node, elem_ty, a, undef, expand_mask.toValue(), @as(u32, @intCast(max_len)));
23211 a = try sema.analyzeShuffle(block, src_node, elem_ty, a, undef, expand_mask.toValue(), @intCast(max_len));
2310023212 } else {
2310123213 const undef = try mod.undefRef(b_ty);
23102 b = try sema.analyzeShuffle(block, src_node, elem_ty, b, undef, expand_mask.toValue(), @as(u32, @intCast(max_len)));
23214 b = try sema.analyzeShuffle(block, src_node, elem_ty, b, undef, expand_mask.toValue(), @intCast(max_len));
2310323215 }
2310423216 }
2310523217
......@@ -23136,7 +23248,7 @@ fn zirSelect(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) C
2313623248 .Vector, .Array => pred_ty.arrayLen(mod),
2313723249 else => return sema.fail(block, pred_src, "expected vector or array, found '{}'", .{pred_ty.fmt(mod)}),
2313823250 };
23139 const vec_len = @as(u32, @intCast(try sema.usizeCast(block, pred_src, vec_len_u64)));
23251 const vec_len: u32 = @intCast(try sema.usizeCast(block, pred_src, vec_len_u64));
2314023252
2314123253 const bool_vec_ty = try mod.vectorType(.{
2314223254 .len = vec_len,
......@@ -23218,7 +23330,9 @@ fn zirAtomicLoad(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
2321823330 const elem_ty = try sema.resolveType(block, elem_ty_src, extra.elem_type);
2321923331 const uncasted_ptr = try sema.resolveInst(extra.ptr);
2322023332 const ptr = try sema.checkAtomicPtrOperand(block, elem_ty, elem_ty_src, uncasted_ptr, ptr_src, true);
23221 const order = try sema.resolveAtomicOrder(block, order_src, extra.ordering, "atomic order of @atomicLoad must be comptime-known");
23333 const order = try sema.resolveAtomicOrder(block, order_src, extra.ordering, .{
23334 .needed_comptime_reason = "atomic order of @atomicLoad must be comptime-known",
23335 });
2322223336
2322323337 switch (order) {
2322423338 .Release, .AcqRel => {
......@@ -23283,7 +23397,9 @@ fn zirAtomicRmw(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
2328323397 },
2328423398 else => {},
2328523399 }
23286 const order = try sema.resolveAtomicOrder(block, order_src, extra.ordering, "atomic order of @atomicRmW must be comptime-known");
23400 const order = try sema.resolveAtomicOrder(block, order_src, extra.ordering, .{
23401 .needed_comptime_reason = "atomic order of @atomicRmW must be comptime-known",
23402 });
2328723403
2328823404 if (order == .Unordered) {
2328923405 return sema.fail(block, order_src, "@atomicRmw atomic ordering must not be Unordered", .{});
......@@ -23350,7 +23466,9 @@ fn zirAtomicStore(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
2335023466 const elem_ty = sema.typeOf(operand);
2335123467 const uncasted_ptr = try sema.resolveInst(extra.ptr);
2335223468 const ptr = try sema.checkAtomicPtrOperand(block, elem_ty, elem_ty_src, uncasted_ptr, ptr_src, false);
23353 const order = try sema.resolveAtomicOrder(block, order_src, extra.ordering, "atomic order of @atomicStore must be comptime-known");
23469 const order = try sema.resolveAtomicOrder(block, order_src, extra.ordering, .{
23470 .needed_comptime_reason = "atomic order of @atomicStore must be comptime-known",
23471 });
2335423472
2335523473 const air_tag: Air.Inst.Tag = switch (order) {
2335623474 .Acquire, .AcqRel => {
......@@ -23451,7 +23569,9 @@ fn zirBuiltinCall(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
2345123569 const modifier_ty = try sema.getBuiltinType("CallModifier");
2345223570 const air_ref = try sema.resolveInst(extra.modifier);
2345323571 const modifier_ref = try sema.coerce(block, modifier_ty, air_ref, modifier_src);
23454 const modifier_val = try sema.resolveConstValue(block, modifier_src, modifier_ref, "call modifier must be comptime-known");
23572 const modifier_val = try sema.resolveConstValue(block, modifier_src, modifier_ref, .{
23573 .needed_comptime_reason = "call modifier must be comptime-known",
23574 });
2345523575 var modifier = mod.toEnum(std.builtin.CallModifier, modifier_val);
2345623576 switch (modifier) {
2345723577 // These can be upgraded to comptime or nosuspend calls.
......@@ -23504,7 +23624,7 @@ fn zirBuiltinCall(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
2350423624
2350523625 var resolved_args: []Air.Inst.Ref = try sema.arena.alloc(Air.Inst.Ref, args_ty.structFieldCount(mod));
2350623626 for (resolved_args, 0..) |*resolved, i| {
23507 resolved.* = try sema.tupleFieldValByIndex(block, args_src, args, @as(u32, @intCast(i)), args_ty);
23627 resolved.* = try sema.tupleFieldValByIndex(block, args_src, args, @intCast(i), args_ty);
2350823628 }
2350923629
2351023630 const callee_ty = sema.typeOf(func);
......@@ -23536,7 +23656,9 @@ fn zirFieldParentPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr
2353623656 const ptr_src: LazySrcLoc = .{ .node_offset_builtin_call_arg2 = inst_data.src_node };
2353723657
2353823658 const parent_ty = try sema.resolveType(block, ty_src, extra.parent_type);
23539 const field_name = try sema.resolveConstStringIntern(block, name_src, extra.field_name, "field name must be comptime-known");
23659 const field_name = try sema.resolveConstStringIntern(block, name_src, extra.field_name, .{
23660 .needed_comptime_reason = "field name must be comptime-known",
23661 });
2354023662 const field_ptr = try sema.resolveInst(extra.field_ptr);
2354123663 const field_ptr_ty = sema.typeOf(field_ptr);
2354223664 const mod = sema.mod;
......@@ -23623,7 +23745,7 @@ fn zirFieldParentPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr
2362323745 try sema.addDeclaredHereNote(msg, parent_ty);
2362423746 break :msg msg;
2362523747 };
23626 return sema.failWithOwnedErrorMsg(msg);
23748 return sema.failWithOwnedErrorMsg(block, msg);
2362723749 }
2362823750 return Air.internedToRef(field.base);
2362923751 }
......@@ -23636,7 +23758,7 @@ fn zirFieldParentPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr
2363623758 .ty = Air.internedToRef(result_ptr.toIntern()),
2363723759 .payload = try block.sema.addExtra(Air.FieldParentPtr{
2363823760 .field_ptr = casted_field_ptr,
23639 .field_index = @as(u32, @intCast(field_index)),
23761 .field_index = @intCast(field_index),
2364023762 }),
2364123763 } },
2364223764 });
......@@ -23977,7 +24099,7 @@ fn zirMemcpy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void
2397724099 });
2397824100 break :msg msg;
2397924101 };
23980 return sema.failWithOwnedErrorMsg(msg);
24102 return sema.failWithOwnedErrorMsg(block, msg);
2398124103 }
2398224104
2398324105 var len_val: ?Value = null;
......@@ -23999,7 +24121,7 @@ fn zirMemcpy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void
2399924121 });
2400024122 break :msg msg;
2400124123 };
24002 return sema.failWithOwnedErrorMsg(msg);
24124 return sema.failWithOwnedErrorMsg(block, msg);
2400324125 }
2400424126 break :check;
2400524127 }
......@@ -24192,7 +24314,7 @@ fn zirMemset(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void
2419224314 },
2419324315 .Many, .C => {},
2419424316 }
24195 return sema.failWithOwnedErrorMsg(msg: {
24317 return sema.failWithOwnedErrorMsg(block, msg: {
2419624318 const msg = try sema.errMsg(block, src, "unknown @memset length", .{});
2419724319 errdefer msg.destroy(sema.gpa);
2419824320 try sema.errNote(block, dest_src, msg, "destination type '{}' provides no length", .{
......@@ -24295,7 +24417,7 @@ fn zirVarExtended(
2429524417 const extra = sema.code.extraData(Zir.Inst.ExtendedVar, extended.operand);
2429624418 const ty_src: LazySrcLoc = .{ .node_offset_var_decl_ty = 0 };
2429724419 const init_src: LazySrcLoc = .{ .node_offset_var_decl_init = 0 };
24298 const small = @as(Zir.Inst.ExtendedVar.Small, @bitCast(extended.small));
24420 const small: Zir.Inst.ExtendedVar.Small = @bitCast(extended.small);
2429924421
2430024422 var extra_index: usize = extra.end;
2430124423
......@@ -24310,7 +24432,7 @@ fn zirVarExtended(
2431024432 assert(!small.has_align);
2431124433
2431224434 const uncasted_init: Air.Inst.Ref = if (small.has_init) blk: {
24313 const init_ref = @as(Zir.Inst.Ref, @enumFromInt(sema.code.extra[extra_index]));
24435 const init_ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_index]);
2431424436 extra_index += 1;
2431524437 break :blk try sema.resolveInst(init_ref);
2431624438 } else .none;
......@@ -24327,8 +24449,11 @@ fn zirVarExtended(
2432724449 else
2432824450 uncasted_init;
2432924451
24330 break :blk ((try sema.resolveMaybeUndefVal(init)) orelse
24331 return sema.failWithNeededComptime(block, init_src, "container level variable initializers must be comptime-known")).toIntern();
24452 break :blk ((try sema.resolveMaybeUndefVal(init)) orelse {
24453 return sema.failWithNeededComptime(block, init_src, .{
24454 .needed_comptime_reason = "container level variable initializers must be comptime-known",
24455 });
24456 }).toIntern();
2433224457 } else .none;
2433324458
2433424459 try sema.validateVarType(block, ty_src, var_ty, small.is_extern);
......@@ -24383,11 +24508,13 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
2438324508 const body = sema.code.extra[extra_index..][0..body_len];
2438424509 extra_index += body.len;
2438524510
24386 const val = try sema.resolveGenericBody(block, align_src, body, inst, Type.u29, "alignment must be comptime-known");
24511 const val = try sema.resolveGenericBody(block, align_src, body, inst, Type.u29, .{
24512 .needed_comptime_reason = "alignment must be comptime-known",
24513 });
2438724514 if (val.isGenericPoison()) {
2438824515 break :blk null;
2438924516 }
24390 const alignment = @as(u32, @intCast(val.toUnsignedInt(mod)));
24517 const alignment: u32 = @intCast(val.toUnsignedInt(mod));
2439124518 try sema.validateAlign(block, align_src, alignment);
2439224519 if (alignment == target_util.defaultFunctionAlignment(target)) {
2439324520 break :blk .none;
......@@ -24395,15 +24522,17 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
2439524522 break :blk Alignment.fromNonzeroByteUnits(alignment);
2439624523 }
2439724524 } else if (extra.data.bits.has_align_ref) blk: {
24398 const align_ref = @as(Zir.Inst.Ref, @enumFromInt(sema.code.extra[extra_index]));
24525 const align_ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_index]);
2439924526 extra_index += 1;
24400 const align_tv = sema.resolveInstConst(block, align_src, align_ref, "alignment must be comptime-known") catch |err| switch (err) {
24527 const align_tv = sema.resolveInstConst(block, align_src, align_ref, .{
24528 .needed_comptime_reason = "alignment must be comptime-known",
24529 }) catch |err| switch (err) {
2440124530 error.GenericPoison => {
2440224531 break :blk null;
2440324532 },
2440424533 else => |e| return e,
2440524534 };
24406 const alignment = @as(u32, @intCast(align_tv.val.toUnsignedInt(mod)));
24535 const alignment: u32 = @intCast(align_tv.val.toUnsignedInt(mod));
2440724536 try sema.validateAlign(block, align_src, alignment);
2440824537 if (alignment == target_util.defaultFunctionAlignment(target)) {
2440924538 break :blk .none;
......@@ -24419,15 +24548,19 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
2441924548 extra_index += body.len;
2442024549
2442124550 const addrspace_ty = try sema.getBuiltinType("AddressSpace");
24422 const val = try sema.resolveGenericBody(block, addrspace_src, body, inst, addrspace_ty, "addrespace must be comptime-known");
24551 const val = try sema.resolveGenericBody(block, addrspace_src, body, inst, addrspace_ty, .{
24552 .needed_comptime_reason = "addrspace must be comptime-known",
24553 });
2442324554 if (val.isGenericPoison()) {
2442424555 break :blk null;
2442524556 }
2442624557 break :blk mod.toEnum(std.builtin.AddressSpace, val);
2442724558 } else if (extra.data.bits.has_addrspace_ref) blk: {
24428 const addrspace_ref = @as(Zir.Inst.Ref, @enumFromInt(sema.code.extra[extra_index]));
24559 const addrspace_ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_index]);
2442924560 extra_index += 1;
24430 const addrspace_tv = sema.resolveInstConst(block, addrspace_src, addrspace_ref, "addrespace must be comptime-known") catch |err| switch (err) {
24561 const addrspace_tv = sema.resolveInstConst(block, addrspace_src, addrspace_ref, .{
24562 .needed_comptime_reason = "addrspace must be comptime-known",
24563 }) catch |err| switch (err) {
2443124564 error.GenericPoison => {
2443224565 break :blk null;
2443324566 },
......@@ -24443,15 +24576,19 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
2444324576 extra_index += body.len;
2444424577
2444524578 const ty = Type.slice_const_u8;
24446 const val = try sema.resolveGenericBody(block, section_src, body, inst, ty, "linksection must be comptime-known");
24579 const val = try sema.resolveGenericBody(block, section_src, body, inst, ty, .{
24580 .needed_comptime_reason = "linksection must be comptime-known",
24581 });
2444724582 if (val.isGenericPoison()) {
2444824583 break :blk .generic;
2444924584 }
2445024585 break :blk .{ .explicit = try val.toIpString(ty, mod) };
2445124586 } else if (extra.data.bits.has_section_ref) blk: {
24452 const section_ref = @as(Zir.Inst.Ref, @enumFromInt(sema.code.extra[extra_index]));
24587 const section_ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_index]);
2445324588 extra_index += 1;
24454 const section_name = sema.resolveConstStringIntern(block, section_src, section_ref, "linksection must be comptime-known") catch |err| switch (err) {
24589 const section_name = sema.resolveConstStringIntern(block, section_src, section_ref, .{
24590 .needed_comptime_reason = "linksection must be comptime-known",
24591 }) catch |err| switch (err) {
2445524592 error.GenericPoison => {
2445624593 break :blk .generic;
2445724594 },
......@@ -24467,15 +24604,19 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
2446724604 extra_index += body.len;
2446824605
2446924606 const cc_ty = try sema.getBuiltinType("CallingConvention");
24470 const val = try sema.resolveGenericBody(block, cc_src, body, inst, cc_ty, "calling convention must be comptime-known");
24607 const val = try sema.resolveGenericBody(block, cc_src, body, inst, cc_ty, .{
24608 .needed_comptime_reason = "calling convention must be comptime-known",
24609 });
2447124610 if (val.isGenericPoison()) {
2447224611 break :blk null;
2447324612 }
2447424613 break :blk mod.toEnum(std.builtin.CallingConvention, val);
2447524614 } else if (extra.data.bits.has_cc_ref) blk: {
24476 const cc_ref = @as(Zir.Inst.Ref, @enumFromInt(sema.code.extra[extra_index]));
24615 const cc_ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_index]);
2447724616 extra_index += 1;
24478 const cc_tv = sema.resolveInstConst(block, cc_src, cc_ref, "calling convention must be comptime-known") catch |err| switch (err) {
24617 const cc_tv = sema.resolveInstConst(block, cc_src, cc_ref, .{
24618 .needed_comptime_reason = "calling convention must be comptime-known",
24619 }) catch |err| switch (err) {
2447924620 error.GenericPoison => {
2448024621 break :blk null;
2448124622 },
......@@ -24493,13 +24634,17 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
2449324634 const body = sema.code.extra[extra_index..][0..body_len];
2449424635 extra_index += body.len;
2449524636
24496 const val = try sema.resolveGenericBody(block, ret_src, body, inst, Type.type, "return type must be comptime-known");
24637 const val = try sema.resolveGenericBody(block, ret_src, body, inst, Type.type, .{
24638 .needed_comptime_reason = "return type must be comptime-known",
24639 });
2449724640 const ty = val.toType();
2449824641 break :blk ty;
2449924642 } else if (extra.data.bits.has_ret_ty_ref) blk: {
24500 const ret_ty_ref = @as(Zir.Inst.Ref, @enumFromInt(sema.code.extra[extra_index]));
24643 const ret_ty_ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_index]);
2450124644 extra_index += 1;
24502 const ret_ty_tv = sema.resolveInstConst(block, ret_src, ret_ty_ref, "return type must be comptime-known") catch |err| switch (err) {
24645 const ret_ty_tv = sema.resolveInstConst(block, ret_src, ret_ty_ref, .{
24646 .needed_comptime_reason = "return type must be comptime-known",
24647 }) catch |err| switch (err) {
2450324648 error.GenericPoison => {
2450424649 break :blk Type.generic_poison;
2450524650 },
......@@ -24554,9 +24699,11 @@ fn zirCUndef(
2455424699 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;
2455524700 const src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node };
2455624701
24557 const name = try sema.resolveConstString(block, src, extra.operand, "name of macro being undefined must be comptime-known");
24702 const name = try sema.resolveConstString(block, src, extra.operand, .{
24703 .needed_comptime_reason = "name of macro being undefined must be comptime-known",
24704 });
2455824705 try block.c_import_buf.?.writer().print("#undef {s}\n", .{name});
24559 return Air.Inst.Ref.void_value;
24706 return .void_value;
2456024707}
2456124708
2456224709fn zirCInclude(
......@@ -24567,9 +24714,11 @@ fn zirCInclude(
2456724714 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;
2456824715 const src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node };
2456924716
24570 const name = try sema.resolveConstString(block, src, extra.operand, "path being included must be comptime-known");
24717 const name = try sema.resolveConstString(block, src, extra.operand, .{
24718 .needed_comptime_reason = "path being included must be comptime-known",
24719 });
2457124720 try block.c_import_buf.?.writer().print("#include <{s}>\n", .{name});
24572 return Air.Inst.Ref.void_value;
24721 return .void_value;
2457324722}
2457424723
2457524724fn zirCDefine(
......@@ -24582,15 +24731,19 @@ fn zirCDefine(
2458224731 const name_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node };
2458324732 const val_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = extra.node };
2458424733
24585 const name = try sema.resolveConstString(block, name_src, extra.lhs, "name of macro being undefined must be comptime-known");
24734 const name = try sema.resolveConstString(block, name_src, extra.lhs, .{
24735 .needed_comptime_reason = "name of macro being undefined must be comptime-known",
24736 });
2458624737 const rhs = try sema.resolveInst(extra.rhs);
2458724738 if (sema.typeOf(rhs).zigTypeTag(mod) != .Void) {
24588 const value = try sema.resolveConstString(block, val_src, extra.rhs, "value of macro being undefined must be comptime-known");
24739 const value = try sema.resolveConstString(block, val_src, extra.rhs, .{
24740 .needed_comptime_reason = "value of macro being undefined must be comptime-known",
24741 });
2458924742 try block.c_import_buf.?.writer().print("#define {s} {s}\n", .{ name, value });
2459024743 } else {
2459124744 try block.c_import_buf.?.writer().print("#define {s}\n", .{name});
2459224745 }
24593 return Air.Inst.Ref.void_value;
24746 return .void_value;
2459424747}
2459524748
2459624749fn zirWasmMemorySize(
......@@ -24606,7 +24759,9 @@ fn zirWasmMemorySize(
2460624759 return sema.fail(block, builtin_src, "builtin @wasmMemorySize is available when targeting WebAssembly; targeted CPU architecture is {s}", .{@tagName(target.cpu.arch)});
2460724760 }
2460824761
24609 const index = @as(u32, @intCast(try sema.resolveInt(block, index_src, extra.operand, Type.u32, "wasm memory size index must be comptime-known")));
24762 const index: u32 = @intCast(try sema.resolveInt(block, index_src, extra.operand, Type.u32, .{
24763 .needed_comptime_reason = "wasm memory size index must be comptime-known",
24764 }));
2461024765 try sema.requireRuntimeBlock(block, builtin_src, null);
2461124766 return block.addInst(.{
2461224767 .tag = .wasm_memory_size,
......@@ -24631,7 +24786,9 @@ fn zirWasmMemoryGrow(
2463124786 return sema.fail(block, builtin_src, "builtin @wasmMemoryGrow is available when targeting WebAssembly; targeted CPU architecture is {s}", .{@tagName(target.cpu.arch)});
2463224787 }
2463324788
24634 const index = @as(u32, @intCast(try sema.resolveInt(block, index_src, extra.lhs, Type.u32, "wasm memory size index must be comptime-known")));
24789 const index: u32 = @intCast(try sema.resolveInt(block, index_src, extra.lhs, Type.u32, .{
24790 .needed_comptime_reason = "wasm memory size index must be comptime-known",
24791 }));
2463524792 const delta = try sema.coerce(block, Type.u32, try sema.resolveInst(extra.rhs), delta_src);
2463624793
2463724794 try sema.requireRuntimeBlock(block, builtin_src, null);
......@@ -24661,17 +24818,23 @@ fn resolvePrefetchOptions(
2466124818 const cache_src = sema.maybeOptionsSrc(block, src, "cache");
2466224819
2466324820 const rw = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "rw"), rw_src);
24664 const rw_val = try sema.resolveConstValue(block, rw_src, rw, "prefetch read/write must be comptime-known");
24821 const rw_val = try sema.resolveConstValue(block, rw_src, rw, .{
24822 .needed_comptime_reason = "prefetch read/write must be comptime-known",
24823 });
2466524824
2466624825 const locality = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "locality"), locality_src);
24667 const locality_val = try sema.resolveConstValue(block, locality_src, locality, "prefetch locality must be comptime-known");
24826 const locality_val = try sema.resolveConstValue(block, locality_src, locality, .{
24827 .needed_comptime_reason = "prefetch locality must be comptime-known",
24828 });
2466824829
2466924830 const cache = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "cache"), cache_src);
24670 const cache_val = try sema.resolveConstValue(block, cache_src, cache, "prefetch cache must be comptime-known");
24831 const cache_val = try sema.resolveConstValue(block, cache_src, cache, .{
24832 .needed_comptime_reason = "prefetch cache must be comptime-known",
24833 });
2467124834
2467224835 return std.builtin.PrefetchOptions{
2467324836 .rw = mod.toEnum(std.builtin.PrefetchOptions.Rw, rw_val),
24674 .locality = @as(u2, @intCast(locality_val.toUnsignedInt(mod))),
24837 .locality = @intCast(locality_val.toUnsignedInt(mod)),
2467524838 .cache = mod.toEnum(std.builtin.PrefetchOptions.Cache, cache_val),
2467624839 };
2467724840}
......@@ -24707,7 +24870,7 @@ fn zirPrefetch(
2470724870 });
2470824871 }
2470924872
24710 return Air.Inst.Ref.void_value;
24873 return .void_value;
2471124874}
2471224875
2471324876fn resolveExternOptions(
......@@ -24734,18 +24897,26 @@ fn resolveExternOptions(
2473424897 const thread_local_src = sema.maybeOptionsSrc(block, src, "thread_local");
2473524898
2473624899 const name_ref = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "name"), name_src);
24737 const name_val = try sema.resolveConstValue(block, name_src, name_ref, "name of the extern symbol must be comptime-known");
24900 const name_val = try sema.resolveConstValue(block, name_src, name_ref, .{
24901 .needed_comptime_reason = "name of the extern symbol must be comptime-known",
24902 });
2473824903 const name = try name_val.toAllocatedBytes(Type.slice_const_u8, sema.arena, mod);
2473924904
2474024905 const library_name_inst = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "library_name"), library_src);
24741 const library_name_val = try sema.resolveConstValue(block, library_src, library_name_inst, "library in which extern symbol is must be comptime-known");
24906 const library_name_val = try sema.resolveConstValue(block, library_src, library_name_inst, .{
24907 .needed_comptime_reason = "library in which extern symbol is must be comptime-known",
24908 });
2474224909
2474324910 const linkage_ref = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "linkage"), linkage_src);
24744 const linkage_val = try sema.resolveConstValue(block, linkage_src, linkage_ref, "linkage of the extern symbol must be comptime-known");
24911 const linkage_val = try sema.resolveConstValue(block, linkage_src, linkage_ref, .{
24912 .needed_comptime_reason = "linkage of the extern symbol must be comptime-known",
24913 });
2474524914 const linkage = mod.toEnum(std.builtin.GlobalLinkage, linkage_val);
2474624915
2474724916 const is_thread_local = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "is_thread_local"), thread_local_src);
24748 const is_thread_local_val = try sema.resolveConstValue(block, thread_local_src, is_thread_local, "threadlocality of the extern symbol must be comptime-known");
24917 const is_thread_local_val = try sema.resolveConstValue(block, thread_local_src, is_thread_local, .{
24918 .needed_comptime_reason = "threadlocality of the extern symbol must be comptime-known",
24919 });
2474924920
2475024921 const library_name = if (library_name_val.optionalValue(mod)) |payload| blk: {
2475124922 const library_name = try payload.toAllocatedBytes(Type.slice_const_u8, sema.arena, mod);
......@@ -24793,7 +24964,7 @@ fn zirBuiltinExtern(
2479324964 try sema.explainWhyTypeIsNotExtern(msg, ty_src.toSrcLoc(src_decl, mod), ty, .other);
2479424965 break :msg msg;
2479524966 };
24796 return sema.failWithOwnedErrorMsg(msg);
24967 return sema.failWithOwnedErrorMsg(block, msg);
2479724968 }
2479824969
2479924970 const options = sema.resolveExternOptions(block, .unneeded, extra.rhs) catch |err| switch (err) {
......@@ -24870,7 +25041,9 @@ fn zirWorkItem(
2487025041 },
2487125042 }
2487225043
24873 const dimension = @as(u32, @intCast(try sema.resolveInt(block, dimension_src, extra.operand, Type.u32, "dimension must be comptime-known")));
25044 const dimension: u32 = @intCast(try sema.resolveInt(block, dimension_src, extra.operand, Type.u32, .{
25045 .needed_comptime_reason = "dimension must be comptime-known",
25046 }));
2487425047 try sema.requireRuntimeBlock(block, builtin_src, null);
2487525048
2487625049 return block.addInst(.{
......@@ -24892,11 +25065,7 @@ fn zirInComptime(
2489225065 block: *Block,
2489325066) CompileError!Air.Inst.Ref {
2489425067 _ = sema;
24895 if (block.is_comptime) {
24896 return Air.Inst.Ref.bool_true;
24897 } else {
24898 return Air.Inst.Ref.bool_false;
24899 }
25068 return if (block.is_comptime) .bool_true else .bool_false;
2490025069}
2490125070
2490225071fn requireRuntimeBlock(sema: *Sema, block: *Block, src: LazySrcLoc, runtime_src: ?LazySrcLoc) !void {
......@@ -24913,7 +25082,7 @@ fn requireRuntimeBlock(sema: *Sema, block: *Block, src: LazySrcLoc, runtime_src:
2491325082 }
2491425083 break :msg msg;
2491525084 };
24916 return sema.failWithOwnedErrorMsg(msg);
25085 return sema.failWithOwnedErrorMsg(block, msg);
2491725086 }
2491825087}
2491925088
......@@ -24935,7 +25104,7 @@ fn validateVarType(
2493525104 try sema.explainWhyTypeIsNotExtern(msg, src.toSrcLoc(src_decl, mod), var_ty, .other);
2493625105 break :msg msg;
2493725106 };
24938 return sema.failWithOwnedErrorMsg(msg);
25107 return sema.failWithOwnedErrorMsg(block, msg);
2493925108 }
2494025109 } else {
2494125110 if (var_ty.zigTypeTag(mod) == .Opaque) {
......@@ -24962,7 +25131,7 @@ fn validateVarType(
2496225131
2496325132 break :msg msg;
2496425133 };
24965 return sema.failWithOwnedErrorMsg(msg);
25134 return sema.failWithOwnedErrorMsg(block, msg);
2496625135}
2496725136
2496825137const TypeSet = std.AutoHashMapUnmanaged(InternPool.Index, void);
......@@ -25412,7 +25581,7 @@ fn addSafetyCheckExtra(
2541225581 fail_block.instructions.items.len);
2541325582
2541425583 try sema.air_instructions.ensureUnusedCapacity(gpa, 3);
25415 const block_inst = @as(Air.Inst.Index, @intCast(sema.air_instructions.len));
25584 const block_inst: Air.Inst.Index = @intCast(sema.air_instructions.len);
2541625585 const cond_br_inst = block_inst + 1;
2541725586 const br_inst = cond_br_inst + 1;
2541825587 sema.air_instructions.appendAssumeCapacity(.{
......@@ -25432,7 +25601,7 @@ fn addSafetyCheckExtra(
2543225601 .operand = ok,
2543325602 .payload = sema.addExtraAssumeCapacity(Air.CondBr{
2543425603 .then_body_len = 1,
25435 .else_body_len = @as(u32, @intCast(fail_block.instructions.items.len)),
25604 .else_body_len = @intCast(fail_block.instructions.items.len),
2543625605 }),
2543725606 } },
2543825607 });
......@@ -25648,7 +25817,7 @@ fn emitBackwardBranch(sema: *Sema, block: *Block, src: LazySrcLoc) !void {
2564825817 "use @setEvalBranchQuota() to raise the branch limit from {d}",
2564925818 .{sema.branch_quota},
2565025819 );
25651 return sema.failWithOwnedErrorMsg(msg);
25820 return sema.failWithOwnedErrorMsg(block, msg);
2565225821 }
2565325822}
2565425823
......@@ -25755,7 +25924,7 @@ fn fieldVal(
2575525924 try sema.addDeclaredHereNote(msg, child_type);
2575625925 break :msg msg;
2575725926 };
25758 return sema.failWithOwnedErrorMsg(msg);
25927 return sema.failWithOwnedErrorMsg(block, msg);
2575925928 },
2576025929 .inferred_error_set_type => {
2576125930 return sema.fail(block, src, "TODO handle inferred error sets here", .{});
......@@ -25785,7 +25954,7 @@ fn fieldVal(
2578525954 try sema.resolveTypeFields(child_type);
2578625955 if (child_type.unionTagType(mod)) |enum_ty| {
2578725956 if (enum_ty.enumFieldIndex(field_name, mod)) |field_index_usize| {
25788 const field_index = @as(u32, @intCast(field_index_usize));
25957 const field_index: u32 = @intCast(field_index_usize);
2578925958 return Air.internedToRef((try mod.enumValueFieldIndex(enum_ty, field_index)).toIntern());
2579025959 }
2579125960 }
......@@ -25799,7 +25968,7 @@ fn fieldVal(
2579925968 }
2580025969 const field_index_usize = child_type.enumFieldIndex(field_name, mod) orelse
2580125970 return sema.failWithBadMemberAccess(block, child_type, field_name_src, field_name);
25802 const field_index = @as(u32, @intCast(field_index_usize));
25971 const field_index: u32 = @intCast(field_index_usize);
2580325972 const enum_val = try mod.enumValueFieldIndex(child_type, field_index);
2580425973 return Air.internedToRef(enum_val.toIntern());
2580525974 },
......@@ -25819,7 +25988,7 @@ fn fieldVal(
2581925988 if (child_type.zigTypeTag(mod) == .Array) try sema.errNote(block, src, msg, "array values have 'len' member", .{});
2582025989 break :msg msg;
2582125990 };
25822 return sema.failWithOwnedErrorMsg(msg);
25991 return sema.failWithOwnedErrorMsg(block, msg);
2582325992 },
2582425993 }
2582525994 },
......@@ -25956,7 +26125,7 @@ fn fieldPtr(
2595626125 }
2595726126 },
2595826127 .Type => {
25959 _ = try sema.resolveConstValue(block, .unneeded, object_ptr, "");
26128 _ = try sema.resolveConstValue(block, .unneeded, object_ptr, undefined);
2596026129 const result = try sema.analyzeLoad(block, src, object_ptr, object_ptr_src);
2596126130 const inner = if (is_pointer_to)
2596226131 try sema.analyzeLoad(block, src, result, object_ptr_src)
......@@ -26011,7 +26180,7 @@ fn fieldPtr(
2601126180 try sema.resolveTypeFields(child_type);
2601226181 if (child_type.unionTagType(mod)) |enum_ty| {
2601326182 if (enum_ty.enumFieldIndex(field_name, mod)) |field_index| {
26014 const field_index_u32 = @as(u32, @intCast(field_index));
26183 const field_index_u32: u32 = @intCast(field_index);
2601526184 var anon_decl = try block.startAnonDecl();
2601626185 defer anon_decl.deinit();
2601726186 return sema.analyzeDeclRef(try anon_decl.finish(
......@@ -26032,7 +26201,7 @@ fn fieldPtr(
2603226201 const field_index = child_type.enumFieldIndex(field_name, mod) orelse {
2603326202 return sema.failWithBadMemberAccess(block, child_type, field_name_src, field_name);
2603426203 };
26035 const field_index_u32 = @as(u32, @intCast(field_index));
26204 const field_index_u32: u32 = @intCast(field_index);
2603626205 var anon_decl = try block.startAnonDecl();
2603726206 defer anon_decl.deinit();
2603826207 return sema.analyzeDeclRef(try anon_decl.finish(
......@@ -26117,7 +26286,7 @@ fn fieldCallBind(
2611726286 if (mod.typeToStruct(concrete_ty)) |struct_obj| {
2611826287 const field_index_usize = struct_obj.fields.getIndex(field_name) orelse
2611926288 break :find_field;
26120 const field_index = @as(u32, @intCast(field_index_usize));
26289 const field_index: u32 = @intCast(field_index_usize);
2612126290 const field = struct_obj.fields.values()[field_index];
2612226291
2612326292 return sema.finishFieldCallBind(block, src, ptr_ty, field.ty, field_index, object_ptr);
......@@ -26132,7 +26301,7 @@ fn fieldCallBind(
2613226301 } else {
2613326302 const max = concrete_ty.structFieldCount(mod);
2613426303 for (0..max) |i_usize| {
26135 const i = @as(u32, @intCast(i_usize));
26304 const i: u32 = @intCast(i_usize);
2613626305 if (field_name == concrete_ty.structFieldName(i, mod)) {
2613726306 return sema.finishFieldCallBind(block, src, ptr_ty, concrete_ty.structFieldType(i, mod), i, object_ptr);
2613826307 }
......@@ -26238,7 +26407,7 @@ fn fieldCallBind(
2623826407 }
2623926408 break :msg msg;
2624026409 };
26241 return sema.failWithOwnedErrorMsg(msg);
26410 return sema.failWithOwnedErrorMsg(block, msg);
2624226411}
2624326412
2624426413fn finishFieldCallBind(
......@@ -26302,7 +26471,7 @@ fn namespaceLookup(
2630226471 try mod.errNoteNonLazy(decl.srcLoc(mod), msg, "declared here", .{});
2630326472 break :msg msg;
2630426473 };
26305 return sema.failWithOwnedErrorMsg(msg);
26474 return sema.failWithOwnedErrorMsg(block, msg);
2630626475 }
2630726476 return decl_index;
2630826477 }
......@@ -26364,7 +26533,7 @@ fn structFieldPtr(
2636426533
2636526534 const field_index_big = struct_obj.fields.getIndex(field_name) orelse
2636626535 return sema.failWithBadStructFieldAccess(block, struct_obj, field_name_src, field_name);
26367 const field_index = @as(u32, @intCast(field_index_big));
26536 const field_index: u32 = @intCast(field_index_big);
2636826537
2636926538 return sema.structFieldPtrByIndex(block, src, struct_ptr, field_index, field_name_src, struct_ty, initializing);
2637026539}
......@@ -26413,7 +26582,7 @@ fn structFieldPtrByIndex(
2641326582 if (i == field_index) {
2641426583 ptr_ty_data.packed_offset.bit_offset = running_bits;
2641526584 }
26416 running_bits += @as(u16, @intCast(f.ty.bitSize(mod)));
26585 running_bits += @intCast(f.ty.bitSize(mod));
2641726586 }
2641826587 ptr_ty_data.packed_offset.host_size = (running_bits + 7) / 8;
2641926588
......@@ -26441,7 +26610,7 @@ fn structFieldPtrByIndex(
2644126610 const elem_size_bits = ptr_ty_data.child.toType().bitSize(mod);
2644226611 if (elem_size_bytes * 8 == elem_size_bits) {
2644326612 const byte_offset = ptr_ty_data.packed_offset.bit_offset / 8;
26444 const new_align = @as(Alignment, @enumFromInt(@ctz(byte_offset | parent_align)));
26613 const new_align: Alignment = @enumFromInt(@ctz(byte_offset | parent_align));
2644526614 assert(new_align != .none);
2644626615 ptr_ty_data.flags.alignment = new_align;
2644726616 ptr_ty_data.packed_offset = .{ .host_size = 0, .bit_offset = 0 };
......@@ -26505,7 +26674,7 @@ fn structFieldVal(
2650526674
2650626675 const field_index_usize = struct_obj.fields.getIndex(field_name) orelse
2650726676 return sema.failWithBadStructFieldAccess(block, struct_obj, field_name_src, field_name);
26508 const field_index = @as(u32, @intCast(field_index_usize));
26677 const field_index: u32 = @intCast(field_index_usize);
2650926678 const field = struct_obj.fields.values()[field_index];
2651026679
2651126680 if (field.is_comptime) {
......@@ -26660,7 +26829,7 @@ fn unionFieldPtr(
2666026829 try sema.addDeclaredHereNote(msg, union_ty);
2666126830 break :msg msg;
2666226831 };
26663 return sema.failWithOwnedErrorMsg(msg);
26832 return sema.failWithOwnedErrorMsg(block, msg);
2666426833 }
2666526834
2666626835 if (try sema.resolveDefinedValue(block, src, union_ptr)) |union_ptr_val| ct: {
......@@ -26686,7 +26855,7 @@ fn unionFieldPtr(
2668626855 try sema.addDeclaredHereNote(msg, union_ty);
2668726856 break :msg msg;
2668826857 };
26689 return sema.failWithOwnedErrorMsg(msg);
26858 return sema.failWithOwnedErrorMsg(block, msg);
2669026859 }
2669126860 },
2669226861 .Packed, .Extern => {},
......@@ -26713,7 +26882,7 @@ fn unionFieldPtr(
2671326882 }
2671426883 if (field_ty.zigTypeTag(mod) == .NoReturn) {
2671526884 _ = try block.addNoOp(.unreach);
26716 return Air.Inst.Ref.unreachable_value;
26885 return .unreachable_value;
2671726886 }
2671826887 return block.addStructFieldPtr(union_ptr, field_index, ptr_field_ty);
2671926888}
......@@ -26758,7 +26927,7 @@ fn unionFieldVal(
2675826927 try sema.addDeclaredHereNote(msg, union_ty);
2675926928 break :msg msg;
2676026929 };
26761 return sema.failWithOwnedErrorMsg(msg);
26930 return sema.failWithOwnedErrorMsg(block, msg);
2676226931 }
2676326932 },
2676426933 .Packed, .Extern => {
......@@ -26785,7 +26954,7 @@ fn unionFieldVal(
2678526954 }
2678626955 if (field_ty.zigTypeTag(mod) == .NoReturn) {
2678726956 _ = try block.addNoOp(.unreach);
26788 return Air.Inst.Ref.unreachable_value;
26957 return .unreachable_value;
2678926958 }
2679026959 return block.addStructFieldVal(union_byval, field_index, field_ty);
2679126960}
......@@ -26814,8 +26983,10 @@ fn elemPtr(
2681426983 .Array, .Vector => return sema.elemPtrArray(block, src, indexable_ptr_src, indexable_ptr, elem_index_src, elem_index, init, oob_safety),
2681526984 .Struct => {
2681626985 // Tuple field access.
26817 const index_val = try sema.resolveConstValue(block, elem_index_src, elem_index, "tuple field access index must be comptime-known");
26818 const index = @as(u32, @intCast(index_val.toUnsignedInt(mod)));
26986 const index_val = try sema.resolveConstValue(block, elem_index_src, elem_index, .{
26987 .needed_comptime_reason = "tuple field access index must be comptime-known",
26988 });
26989 const index: u32 = @intCast(index_val.toUnsignedInt(mod));
2681926990 return sema.tupleFieldPtr(block, src, indexable_ptr, elem_index_src, index, init);
2682026991 },
2682126992 else => {
......@@ -26850,7 +27021,7 @@ fn elemPtrOneLayerOnly(
2685027021 const runtime_src = rs: {
2685127022 const ptr_val = maybe_ptr_val orelse break :rs indexable_src;
2685227023 const index_val = maybe_index_val orelse break :rs elem_index_src;
26853 const index = @as(usize, @intCast(index_val.toUnsignedInt(mod)));
27024 const index: usize = @intCast(index_val.toUnsignedInt(mod));
2685427025 const result_ty = try sema.elemPtrType(indexable_ty, index);
2685527026 const elem_ptr = try ptr_val.elemPtr(result_ty, index, mod);
2685627027 return Air.internedToRef(elem_ptr.toIntern());
......@@ -26868,8 +27039,10 @@ fn elemPtrOneLayerOnly(
2686827039 },
2686927040 .Struct => {
2687027041 assert(child_ty.isTuple(mod));
26871 const index_val = try sema.resolveConstValue(block, elem_index_src, elem_index, "tuple field access index must be comptime-known");
26872 const index = @as(u32, @intCast(index_val.toUnsignedInt(mod)));
27042 const index_val = try sema.resolveConstValue(block, elem_index_src, elem_index, .{
27043 .needed_comptime_reason = "tuple field access index must be comptime-known",
27044 });
27045 const index: u32 = @intCast(index_val.toUnsignedInt(mod));
2687327046 return sema.tupleFieldPtr(block, indexable_src, indexable, elem_index_src, index, false);
2687427047 },
2687527048 else => unreachable, // Guaranteed by checkIndexable
......@@ -26907,7 +27080,7 @@ fn elemVal(
2690727080 const runtime_src = rs: {
2690827081 const indexable_val = maybe_indexable_val orelse break :rs indexable_src;
2690927082 const index_val = maybe_index_val orelse break :rs elem_index_src;
26910 const index = @as(usize, @intCast(index_val.toUnsignedInt(mod)));
27083 const index: usize = @intCast(index_val.toUnsignedInt(mod));
2691127084 const elem_ty = indexable_ty.elemType2(mod);
2691227085 const many_ptr_ty = try mod.manyConstPtrType(elem_ty);
2691327086 const many_ptr_val = try mod.getCoerced(indexable_val, many_ptr_ty);
......@@ -26943,8 +27116,10 @@ fn elemVal(
2694327116 },
2694427117 .Struct => {
2694527118 // Tuple field access.
26946 const index_val = try sema.resolveConstValue(block, elem_index_src, elem_index, "tuple field access index must be comptime-known");
26947 const index = @as(u32, @intCast(index_val.toUnsignedInt(mod)));
27119 const index_val = try sema.resolveConstValue(block, elem_index_src, elem_index, .{
27120 .needed_comptime_reason = "tuple field access index must be comptime-known",
27121 });
27122 const index: u32 = @intCast(index_val.toUnsignedInt(mod));
2694827123 return sema.tupleField(block, indexable_src, indexable, elem_index_src, index);
2694927124 },
2695027125 else => unreachable,
......@@ -26975,7 +27150,7 @@ fn validateRuntimeElemAccess(
2697527150
2697627151 break :msg msg;
2697727152 };
26978 return sema.failWithOwnedErrorMsg(msg);
27153 return sema.failWithOwnedErrorMsg(block, msg);
2697927154 }
2698027155}
2698127156
......@@ -27105,7 +27280,7 @@ fn elemValArray(
2710527280 const maybe_index_val = try sema.resolveDefinedValue(block, elem_index_src, elem_index);
2710627281
2710727282 if (maybe_index_val) |index_val| {
27108 const index = @as(usize, @intCast(index_val.toUnsignedInt(mod)));
27283 const index: usize = @intCast(index_val.toUnsignedInt(mod));
2710927284 if (array_sent) |s| {
2711027285 if (index == array_len) {
2711127286 return Air.internedToRef(s.toIntern());
......@@ -27121,7 +27296,7 @@ fn elemValArray(
2712127296 return mod.undefRef(elem_ty);
2712227297 }
2712327298 if (maybe_index_val) |index_val| {
27124 const index = @as(usize, @intCast(index_val.toUnsignedInt(mod)));
27299 const index: usize = @intCast(index_val.toUnsignedInt(mod));
2712527300 const elem_val = try array_val.elemValue(mod, index);
2712627301 return Air.internedToRef(elem_val.toIntern());
2712727302 }
......@@ -27234,7 +27409,7 @@ fn elemValSlice(
2723427409 return sema.fail(block, slice_src, "indexing into empty slice is not allowed", .{});
2723527410 }
2723627411 if (maybe_index_val) |index_val| {
27237 const index = @as(usize, @intCast(index_val.toUnsignedInt(mod)));
27412 const index: usize = @intCast(index_val.toUnsignedInt(mod));
2723827413 if (index >= slice_len_s) {
2723927414 const sentinel_label: []const u8 = if (slice_sent) " +1 (sentinel)" else "";
2724027415 return sema.fail(block, elem_index_src, "index {d} outside slice of length {d}{s}", .{ index, slice_len, sentinel_label });
......@@ -27457,7 +27632,7 @@ fn coerceExtra(
2745727632
2745827633 // Function body to function pointer.
2745927634 if (inst_ty.zigTypeTag(mod) == .Fn) {
27460 const fn_val = try sema.resolveConstValue(block, .unneeded, inst, "");
27635 const fn_val = try sema.resolveConstValue(block, .unneeded, inst, undefined);
2746127636 const fn_decl = fn_val.pointerDecl(mod).?;
2746227637 const inst_as_ptr = try sema.analyzeDeclRef(fn_decl);
2746327638 return sema.coerce(block, dest_ty, inst_as_ptr, inst_src);
......@@ -27706,7 +27881,7 @@ fn coerceExtra(
2770627881 try sema.errNote(block, dest_ty_src, err_msg, "pointers to tuples can only coerce to constant pointers", .{});
2770727882 break :err_msg err_msg;
2770827883 };
27709 return sema.failWithOwnedErrorMsg(err_msg);
27884 return sema.failWithOwnedErrorMsg(block, err_msg);
2771027885 }
2771127886 return sema.coerceTupleToSlicePtrs(block, dest_ty, dest_ty_src, inst, inst_src);
2771227887 },
......@@ -27746,7 +27921,9 @@ fn coerceExtra(
2774627921 const val = (try sema.resolveMaybeUndefVal(inst)) orelse {
2774727922 if (dest_ty.zigTypeTag(mod) == .ComptimeInt) {
2774827923 if (!opts.report_err) return error.NotCoercible;
27749 return sema.failWithNeededComptime(block, inst_src, "value being casted to 'comptime_int' must be comptime-known");
27924 return sema.failWithNeededComptime(block, inst_src, .{
27925 .needed_comptime_reason = "value being casted to 'comptime_int' must be comptime-known",
27926 });
2775027927 }
2775127928 break :float;
2775227929 };
......@@ -27777,7 +27954,9 @@ fn coerceExtra(
2777727954 if (dest_ty.zigTypeTag(mod) == .ComptimeInt) {
2777827955 if (!opts.report_err) return error.NotCoercible;
2777927956 if (opts.no_cast_to_comptime_int) return inst;
27780 return sema.failWithNeededComptime(block, inst_src, "value being casted to 'comptime_int' must be comptime-known");
27957 return sema.failWithNeededComptime(block, inst_src, .{
27958 .needed_comptime_reason = "value being casted to 'comptime_int' must be comptime-known",
27959 });
2778127960 }
2778227961
2778327962 // integer widening
......@@ -27798,7 +27977,7 @@ fn coerceExtra(
2779827977 },
2779927978 .Float, .ComptimeFloat => switch (inst_ty.zigTypeTag(mod)) {
2780027979 .ComptimeFloat => {
27801 const val = try sema.resolveConstValue(block, .unneeded, inst, "");
27980 const val = try sema.resolveConstValue(block, .unneeded, inst, undefined);
2780227981 const result_val = try val.floatCast(dest_ty, mod);
2780327982 return Air.internedToRef(result_val.toIntern());
2780427983 },
......@@ -27819,7 +27998,9 @@ fn coerceExtra(
2781927998 return Air.internedToRef(result_val.toIntern());
2782027999 } else if (dest_ty.zigTypeTag(mod) == .ComptimeFloat) {
2782128000 if (!opts.report_err) return error.NotCoercible;
27822 return sema.failWithNeededComptime(block, inst_src, "value being casted to 'comptime_float' must be comptime-known");
28001 return sema.failWithNeededComptime(block, inst_src, .{
28002 .needed_comptime_reason = "value being casted to 'comptime_float' must be comptime-known",
28003 });
2782328004 }
2782428005
2782528006 // float widening
......@@ -27837,7 +28018,9 @@ fn coerceExtra(
2783728018 const val = (try sema.resolveMaybeUndefVal(inst)) orelse {
2783828019 if (dest_ty.zigTypeTag(mod) == .ComptimeFloat) {
2783928020 if (!opts.report_err) return error.NotCoercible;
27840 return sema.failWithNeededComptime(block, inst_src, "value being casted to 'comptime_float' must be comptime-known");
28021 return sema.failWithNeededComptime(block, inst_src, .{
28022 .needed_comptime_reason = "value being casted to 'comptime_float' must be comptime-known",
28023 });
2784128024 }
2784228025 break :int;
2784328026 };
......@@ -27862,7 +28045,7 @@ fn coerceExtra(
2786228045 .Enum => switch (inst_ty.zigTypeTag(mod)) {
2786328046 .EnumLiteral => {
2786428047 // enum literal to enum
27865 const val = try sema.resolveConstValue(block, .unneeded, inst, "");
28048 const val = try sema.resolveConstValue(block, .unneeded, inst, undefined);
2786628049 const string = mod.intern_pool.indexToKey(val.toIntern()).enum_literal;
2786728050 const field_index = dest_ty.enumFieldIndex(string, mod) orelse {
2786828051 const msg = msg: {
......@@ -27876,9 +28059,9 @@ fn coerceExtra(
2787628059 try sema.addDeclaredHereNote(msg, dest_ty);
2787728060 break :msg msg;
2787828061 };
27879 return sema.failWithOwnedErrorMsg(msg);
28062 return sema.failWithOwnedErrorMsg(block, msg);
2788028063 };
27881 return Air.internedToRef((try mod.enumValueFieldIndex(dest_ty, @as(u32, @intCast(field_index)))).toIntern());
28064 return Air.internedToRef((try mod.enumValueFieldIndex(dest_ty, @intCast(field_index))).toIntern());
2788228065 },
2788328066 .Union => blk: {
2788428067 // union to its own tag type
......@@ -28007,7 +28190,7 @@ fn coerceExtra(
2800728190 try mod.errNoteNonLazy(ret_ty_src.toSrcLoc(src_decl, mod), msg, "'noreturn' declared here", .{});
2800828191 break :msg msg;
2800928192 };
28010 return sema.failWithOwnedErrorMsg(msg);
28193 return sema.failWithOwnedErrorMsg(block, msg);
2801128194 }
2801228195
2801328196 const msg = msg: {
......@@ -28053,7 +28236,7 @@ fn coerceExtra(
2805328236
2805428237 break :msg msg;
2805528238 };
28056 return sema.failWithOwnedErrorMsg(msg);
28239 return sema.failWithOwnedErrorMsg(block, msg);
2805728240}
2805828241
2805928242fn coerceInMemory(
......@@ -28282,8 +28465,8 @@ const InMemoryCoercionResult = union(enum) {
2828228465 var index: u6 = 0;
2828328466 var actual_noalias = false;
2828428467 while (true) : (index += 1) {
28285 const actual = @as(u1, @truncate(param.actual >> index));
28286 const wanted = @as(u1, @truncate(param.wanted >> index));
28468 const actual: u1 = @truncate(param.actual >> index);
28469 const wanted: u1 = @truncate(param.wanted >> index);
2828728470 if (actual != wanted) {
2828828471 actual_noalias = actual == 1;
2828928472 break;
......@@ -28998,7 +29181,7 @@ fn coerceVarArgParam(
2899829181 .{},
2899929182 ),
2900029183 .Fn => blk: {
29001 const fn_val = try sema.resolveConstValue(block, .unneeded, inst, "");
29184 const fn_val = try sema.resolveConstValue(block, .unneeded, inst, undefined);
2900229185 const fn_decl = fn_val.pointerDecl(mod).?;
2900329186 break :blk try sema.analyzeDeclRef(fn_decl);
2900429187 },
......@@ -29029,7 +29212,7 @@ fn coerceVarArgParam(
2902929212 try sema.addDeclaredHereNote(msg, coerced_ty);
2903029213 break :msg msg;
2903129214 };
29032 return sema.failWithOwnedErrorMsg(msg);
29215 return sema.failWithOwnedErrorMsg(block, msg);
2903329216 }
2903429217 return coerced;
2903529218}
......@@ -29446,7 +29629,7 @@ fn beginComptimePtrMutation(
2944629629 // bytes.len may be one greater than dest_len because of the case when
2944729630 // assigning `[N:S]T` to `[N]T`. This is allowed; the sentinel is omitted.
2944829631 assert(bytes.len >= dest_len);
29449 const elems = try arena.alloc(Value, @as(usize, @intCast(dest_len)));
29632 const elems = try arena.alloc(Value, @intCast(dest_len));
2945029633 for (elems, 0..) |*elem, i| {
2945129634 elem.* = try mod.intValue(elem_ty, bytes[i]);
2945229635 }
......@@ -29458,7 +29641,7 @@ fn beginComptimePtrMutation(
2945829641 block,
2945929642 src,
2946029643 elem_ty,
29461 &elems[@as(usize, @intCast(elem_ptr.index))],
29644 &elems[@intCast(elem_ptr.index)],
2946229645 ptr_elem_ty,
2946329646 parent.mut_decl,
2946429647 );
......@@ -29486,7 +29669,7 @@ fn beginComptimePtrMutation(
2948629669 block,
2948729670 src,
2948829671 elem_ty,
29489 &elems[@as(usize, @intCast(elem_ptr.index))],
29672 &elems[@intCast(elem_ptr.index)],
2949029673 ptr_elem_ty,
2949129674 parent.mut_decl,
2949229675 );
......@@ -29497,7 +29680,7 @@ fn beginComptimePtrMutation(
2949729680 block,
2949829681 src,
2949929682 elem_ty,
29500 &val_ptr.castTag(.aggregate).?.data[@as(usize, @intCast(elem_ptr.index))],
29683 &val_ptr.castTag(.aggregate).?.data[@intCast(elem_ptr.index)],
2950129684 ptr_elem_ty,
2950229685 parent.mut_decl,
2950329686 ),
......@@ -29523,7 +29706,7 @@ fn beginComptimePtrMutation(
2952329706 block,
2952429707 src,
2952529708 elem_ty,
29526 &elems[@as(usize, @intCast(elem_ptr.index))],
29709 &elems[@intCast(elem_ptr.index)],
2952729710 ptr_elem_ty,
2952829711 parent.mut_decl,
2952929712 );
......@@ -29578,7 +29761,7 @@ fn beginComptimePtrMutation(
2957829761 },
2957929762 .field => |field_ptr| {
2958029763 const base_child_ty = mod.intern_pool.typeOf(field_ptr.base).toType().childType(mod);
29581 const field_index = @as(u32, @intCast(field_ptr.index));
29764 const field_index: u32 = @intCast(field_ptr.index);
2958229765
2958329766 var parent = try sema.beginComptimePtrMutation(block, src, field_ptr.base.toValue(), base_child_ty);
2958429767 switch (parent.pointee) {
......@@ -30015,12 +30198,12 @@ fn beginComptimePtrLoad(
3001530198 }
3001630199 deref.pointee = TypedValue{
3001730200 .ty = elem_ty,
30018 .val = try array_tv.val.elemValue(mod, @as(usize, @intCast(elem_ptr.index))),
30201 .val = try array_tv.val.elemValue(mod, @intCast(elem_ptr.index)),
3001930202 };
3002030203 break :blk deref;
3002130204 },
3002230205 .field => |field_ptr| blk: {
30023 const field_index = @as(u32, @intCast(field_ptr.index));
30206 const field_index: u32 = @intCast(field_ptr.index);
3002430207 const container_ty = mod.intern_pool.typeOf(field_ptr.base).toType().childType(mod);
3002530208 var deref = try sema.beginComptimePtrLoad(block, src, field_ptr.base.toValue(), container_ty);
3002630209
......@@ -30284,7 +30467,7 @@ fn coerceEnumToUnion(
3028430467 try sema.addDeclaredHereNote(msg, union_ty);
3028530468 break :msg msg;
3028630469 };
30287 return sema.failWithOwnedErrorMsg(msg);
30470 return sema.failWithOwnedErrorMsg(block, msg);
3028830471 };
3028930472
3029030473 const enum_tag = try sema.coerce(block, tag_ty, inst, inst_src);
......@@ -30298,7 +30481,7 @@ fn coerceEnumToUnion(
3029830481 try sema.addDeclaredHereNote(msg, union_ty);
3029930482 break :msg msg;
3030030483 };
30301 return sema.failWithOwnedErrorMsg(msg);
30484 return sema.failWithOwnedErrorMsg(block, msg);
3030230485 };
3030330486
3030430487 const union_obj = mod.typeToUnion(union_ty).?;
......@@ -30316,7 +30499,7 @@ fn coerceEnumToUnion(
3031630499 try sema.addDeclaredHereNote(msg, union_ty);
3031730500 break :msg msg;
3031830501 };
30319 return sema.failWithOwnedErrorMsg(msg);
30502 return sema.failWithOwnedErrorMsg(block, msg);
3032030503 }
3032130504 const opv = (try sema.typeHasOnePossibleValue(field_ty)) orelse {
3032230505 const msg = msg: {
......@@ -30333,7 +30516,7 @@ fn coerceEnumToUnion(
3033330516 try sema.addDeclaredHereNote(msg, union_ty);
3033430517 break :msg msg;
3033530518 };
30336 return sema.failWithOwnedErrorMsg(msg);
30519 return sema.failWithOwnedErrorMsg(block, msg);
3033730520 };
3033830521
3033930522 return Air.internedToRef((try mod.unionValue(union_ty, val, opv)).toIntern());
......@@ -30350,7 +30533,7 @@ fn coerceEnumToUnion(
3035030533 try sema.addDeclaredHereNote(msg, tag_ty);
3035130534 break :msg msg;
3035230535 };
30353 return sema.failWithOwnedErrorMsg(msg);
30536 return sema.failWithOwnedErrorMsg(block, msg);
3035430537 }
3035530538
3035630539 const union_obj = mod.typeToUnion(union_ty).?;
......@@ -30374,7 +30557,7 @@ fn coerceEnumToUnion(
3037430557 if (msg) |some| {
3037530558 msg = null;
3037630559 try sema.addDeclaredHereNote(some, union_ty);
30377 return sema.failWithOwnedErrorMsg(some);
30560 return sema.failWithOwnedErrorMsg(block, some);
3037830561 }
3037930562 }
3038030563
......@@ -30404,7 +30587,7 @@ fn coerceEnumToUnion(
3040430587 try sema.addDeclaredHereNote(msg, union_ty);
3040530588 break :msg msg;
3040630589 };
30407 return sema.failWithOwnedErrorMsg(msg);
30590 return sema.failWithOwnedErrorMsg(block, msg);
3040830591}
3040930592
3041030593fn coerceAnonStructToUnion(
......@@ -30461,7 +30644,7 @@ fn coerceAnonStructToUnion(
3046130644 try sema.addDeclaredHereNote(msg, union_ty);
3046230645 break :msg msg;
3046330646 };
30464 return sema.failWithOwnedErrorMsg(msg);
30647 return sema.failWithOwnedErrorMsg(block, msg);
3046530648 },
3046630649 }
3046730650}
......@@ -30533,7 +30716,7 @@ fn coerceArrayLike(
3053330716 try sema.errNote(block, inst_src, msg, "source has length {d}", .{inst_len});
3053430717 break :msg msg;
3053530718 };
30536 return sema.failWithOwnedErrorMsg(msg);
30719 return sema.failWithOwnedErrorMsg(block, msg);
3053730720 }
3053830721
3053930722 const dest_elem_ty = dest_ty.childType(mod);
......@@ -30592,7 +30775,7 @@ fn coerceTupleToArray(
3059230775 try sema.errNote(block, inst_src, msg, "source has length {d}", .{inst_len});
3059330776 break :msg msg;
3059430777 };
30595 return sema.failWithOwnedErrorMsg(msg);
30778 return sema.failWithOwnedErrorMsg(block, msg);
3059630779 }
3059730780
3059830781 const dest_elems = try sema.usizeCast(block, dest_ty_src, dest_len);
......@@ -30602,7 +30785,7 @@ fn coerceTupleToArray(
3060230785
3060330786 var runtime_src: ?LazySrcLoc = null;
3060430787 for (element_vals, element_refs, 0..) |*val, *ref, i_usize| {
30605 const i = @as(u32, @intCast(i_usize));
30788 const i: u32 = @intCast(i_usize);
3060630789 if (i_usize == inst_len) {
3060730790 const sentinel_val = dest_ty.sentinel(mod).?;
3060830791 val.* = sentinel_val.toIntern();
......@@ -30713,7 +30896,7 @@ fn coerceTupleToStruct(
3071330896 else => unreachable,
3071430897 };
3071530898 for (0..field_count) |field_index_usize| {
30716 const field_i = @as(u32, @intCast(field_index_usize));
30899 const field_i: u32 = @intCast(field_index_usize);
3071730900 const field_src = inst_src; // TODO better source location
3071830901 // https://github.com/ziglang/zig/issues/15709
3071930902 const field_name: InternPool.NullTerminatedString = switch (ip.indexToKey(inst_ty.toIntern())) {
......@@ -30731,7 +30914,9 @@ fn coerceTupleToStruct(
3073130914 field_refs[field_index] = coerced;
3073230915 if (field.is_comptime) {
3073330916 const init_val = (try sema.resolveMaybeUndefVal(coerced)) orelse {
30734 return sema.failWithNeededComptime(block, field_src, "value stored in comptime field must be comptime-known");
30917 return sema.failWithNeededComptime(block, field_src, .{
30918 .needed_comptime_reason = "value stored in comptime field must be comptime-known",
30919 });
3073530920 };
3073630921
3073730922 if (!init_val.eql(field.default_val.toValue(), field.ty, sema.mod)) {
......@@ -30777,7 +30962,7 @@ fn coerceTupleToStruct(
3077730962 if (root_msg) |msg| {
3077830963 try sema.addDeclaredHereNote(msg, struct_ty);
3077930964 root_msg = null;
30780 return sema.failWithOwnedErrorMsg(msg);
30965 return sema.failWithOwnedErrorMsg(block, msg);
3078130966 }
3078230967
3078330968 if (runtime_src) |rs| {
......@@ -30829,7 +31014,7 @@ fn coerceTupleToTuple(
3082931014
3083031015 var runtime_src: ?LazySrcLoc = null;
3083131016 for (0..dest_field_count) |field_index_usize| {
30832 const field_i = @as(u32, @intCast(field_index_usize));
31017 const field_i: u32 = @intCast(field_index_usize);
3083331018 const field_src = inst_src; // TODO better source location
3083431019 // https://github.com/ziglang/zig/issues/15709
3083531020 const field_name: InternPool.NullTerminatedString = switch (ip.indexToKey(inst_ty.toIntern())) {
......@@ -30862,7 +31047,9 @@ fn coerceTupleToTuple(
3086231047 field_refs[field_index] = coerced;
3086331048 if (default_val != .none) {
3086431049 const init_val = (try sema.resolveMaybeUndefVal(coerced)) orelse {
30865 return sema.failWithNeededComptime(block, field_src, "value stored in comptime field must be comptime-known");
31050 return sema.failWithNeededComptime(block, field_src, .{
31051 .needed_comptime_reason = "value stored in comptime field must be comptime-known",
31052 });
3086631053 };
3086731054
3086831055 if (!init_val.eql(default_val.toValue(), field_ty, sema.mod)) {
......@@ -30921,7 +31108,7 @@ fn coerceTupleToTuple(
3092131108 if (root_msg) |msg| {
3092231109 try sema.addDeclaredHereNote(msg, tuple_ty);
3092331110 root_msg = null;
30924 return sema.failWithOwnedErrorMsg(msg);
31111 return sema.failWithOwnedErrorMsg(block, msg);
3092531112 }
3092631113
3092731114 if (runtime_src) |rs| {
......@@ -30982,7 +31169,7 @@ fn ensureDeclAnalyzed(sema: *Sema, decl_index: Decl.Index) CompileError!void {
3098231169 const decl = mod.declPtr(decl_index);
3098331170 if (decl.analysis == .in_progress) {
3098431171 const msg = try Module.ErrorMsg.create(sema.gpa, decl.srcLoc(mod), "dependency loop detected", .{});
30985 return sema.failWithOwnedErrorMsg(msg);
31172 return sema.failWithOwnedErrorMsg(null, msg);
3098631173 }
3098731174
3098831175 mod.ensureDeclAnalyzed(decl_index) catch |err| {
......@@ -31217,14 +31404,10 @@ fn analyzeIsNull(
3121731404 }
3121831405 const is_null = opt_val.isNull(mod);
3121931406 const bool_value = if (invert_logic) !is_null else is_null;
31220 if (bool_value) {
31221 return Air.Inst.Ref.bool_true;
31222 } else {
31223 return Air.Inst.Ref.bool_false;
31224 }
31407 return if (bool_value) .bool_true else .bool_false;
3122531408 }
3122631409
31227 const inverted_non_null_res = if (invert_logic) Air.Inst.Ref.bool_true else Air.Inst.Ref.bool_false;
31410 const inverted_non_null_res: Air.Inst.Ref = if (invert_logic) .bool_true else .bool_false;
3122831411 const operand_ty = sema.typeOf(operand);
3122931412 if (operand_ty.zigTypeTag(mod) == .Optional and operand_ty.optionalChild(mod).zigTypeTag(mod) == .NoReturn) {
3123031413 return inverted_non_null_res;
......@@ -31249,14 +31432,14 @@ fn analyzePtrIsNonErrComptimeOnly(
3124931432 const child_ty = ptr_ty.childType(mod);
3125031433
3125131434 const child_tag = child_ty.zigTypeTag(mod);
31252 if (child_tag != .ErrorSet and child_tag != .ErrorUnion) return Air.Inst.Ref.bool_true;
31253 if (child_tag == .ErrorSet) return Air.Inst.Ref.bool_false;
31435 if (child_tag != .ErrorSet and child_tag != .ErrorUnion) return .bool_true;
31436 if (child_tag == .ErrorSet) return .bool_false;
3125431437 assert(child_tag == .ErrorUnion);
3125531438
3125631439 _ = block;
3125731440 _ = src;
3125831441
31259 return Air.Inst.Ref.none;
31442 return .none;
3126031443}
3126131444
3126231445fn analyzeIsNonErrComptimeOnly(
......@@ -31606,7 +31789,9 @@ fn analyzeSlice(
3160631789 const sentinel = s: {
3160731790 if (sentinel_opt != .none) {
3160831791 const casted = try sema.coerce(block, elem_ty, sentinel_opt, sentinel_src);
31609 break :s try sema.resolveConstValue(block, sentinel_src, casted, "slice sentinel must be comptime-known");
31792 break :s try sema.resolveConstValue(block, sentinel_src, casted, .{
31793 .needed_comptime_reason = "slice sentinel must be comptime-known",
31794 });
3161031795 }
3161131796 // If we are slicing to the end of something that is sentinel-terminated
3161231797 // then the resulting slice type is also sentinel-terminated.
......@@ -31676,7 +31861,7 @@ fn analyzeSlice(
3167631861
3167731862 break :msg msg;
3167831863 };
31679 return sema.failWithOwnedErrorMsg(msg);
31864 return sema.failWithOwnedErrorMsg(block, msg);
3168031865 }
3168131866 } else {
3168231867 runtime_src = ptr_src;
......@@ -31878,11 +32063,11 @@ fn cmpNumeric(
3187832063 // Compare ints: const vs. undefined (or vice versa)
3187932064 if (!lhs_val.isUndef(mod) and (lhs_ty.isInt(mod) or lhs_ty_tag == .ComptimeInt) and rhs_ty.isInt(mod) and rhs_val.isUndef(mod)) {
3188032065 if (try sema.compareIntsOnlyPossibleResult(try sema.resolveLazyValue(lhs_val), op, rhs_ty)) |res| {
31881 return if (res) Air.Inst.Ref.bool_true else Air.Inst.Ref.bool_false;
32066 return if (res) .bool_true else .bool_false;
3188232067 }
3188332068 } else if (!rhs_val.isUndef(mod) and (rhs_ty.isInt(mod) or rhs_ty_tag == .ComptimeInt) and lhs_ty.isInt(mod) and lhs_val.isUndef(mod)) {
3188432069 if (try sema.compareIntsOnlyPossibleResult(try sema.resolveLazyValue(rhs_val), op.reverse(), lhs_ty)) |res| {
31885 return if (res) Air.Inst.Ref.bool_true else Air.Inst.Ref.bool_false;
32070 return if (res) .bool_true else .bool_false;
3188632071 }
3188732072 }
3188832073
......@@ -31890,22 +32075,17 @@ fn cmpNumeric(
3189032075 return mod.undefRef(Type.bool);
3189132076 }
3189232077 if (lhs_val.isNan(mod) or rhs_val.isNan(mod)) {
31893 if (op == std.math.CompareOperator.neq) {
31894 return Air.Inst.Ref.bool_true;
31895 } else {
31896 return Air.Inst.Ref.bool_false;
31897 }
31898 }
31899 if (try Value.compareHeteroAdvanced(lhs_val, op, rhs_val, mod, sema)) {
31900 return Air.Inst.Ref.bool_true;
31901 } else {
31902 return Air.Inst.Ref.bool_false;
32078 return if (op == std.math.CompareOperator.neq) .bool_true else .bool_false;
3190332079 }
32080 return if (try Value.compareHeteroAdvanced(lhs_val, op, rhs_val, mod, sema))
32081 .bool_true
32082 else
32083 .bool_false;
3190432084 } else {
3190532085 if (!lhs_val.isUndef(mod) and (lhs_ty.isInt(mod) or lhs_ty_tag == .ComptimeInt) and rhs_ty.isInt(mod)) {
3190632086 // Compare ints: const vs. var
3190732087 if (try sema.compareIntsOnlyPossibleResult(try sema.resolveLazyValue(lhs_val), op, rhs_ty)) |res| {
31908 return if (res) Air.Inst.Ref.bool_true else Air.Inst.Ref.bool_false;
32088 return if (res) .bool_true else .bool_false;
3190932089 }
3191032090 }
3191132091 break :src rhs_src;
......@@ -31915,7 +32095,7 @@ fn cmpNumeric(
3191532095 if (!rhs_val.isUndef(mod) and (rhs_ty.isInt(mod) or rhs_ty_tag == .ComptimeInt) and lhs_ty.isInt(mod)) {
3191632096 // Compare ints: var vs. const
3191732097 if (try sema.compareIntsOnlyPossibleResult(try sema.resolveLazyValue(rhs_val), op.reverse(), lhs_ty)) |res| {
31918 return if (res) Air.Inst.Ref.bool_true else Air.Inst.Ref.bool_false;
32098 return if (res) .bool_true else .bool_false;
3191932099 }
3192032100 }
3192132101 }
......@@ -31982,34 +32162,34 @@ fn cmpNumeric(
3198232162 if (lhs_val.isUndef(mod))
3198332163 return mod.undefRef(Type.bool);
3198432164 if (lhs_val.isNan(mod)) switch (op) {
31985 .neq => return Air.Inst.Ref.bool_true,
31986 else => return Air.Inst.Ref.bool_false,
32165 .neq => return .bool_true,
32166 else => return .bool_false,
3198732167 };
3198832168 if (lhs_val.isInf(mod)) switch (op) {
31989 .neq => return Air.Inst.Ref.bool_true,
31990 .eq => return Air.Inst.Ref.bool_false,
31991 .gt, .gte => return if (lhs_val.isNegativeInf(mod)) Air.Inst.Ref.bool_false else Air.Inst.Ref.bool_true,
31992 .lt, .lte => return if (lhs_val.isNegativeInf(mod)) Air.Inst.Ref.bool_true else Air.Inst.Ref.bool_false,
32169 .neq => return .bool_true,
32170 .eq => return .bool_false,
32171 .gt, .gte => return if (lhs_val.isNegativeInf(mod)) .bool_false else .bool_true,
32172 .lt, .lte => return if (lhs_val.isNegativeInf(mod)) .bool_true else .bool_false,
3199332173 };
3199432174 if (!rhs_is_signed) {
3199532175 switch (lhs_val.orderAgainstZero(mod)) {
3199632176 .gt => {},
3199732177 .eq => switch (op) { // LHS = 0, RHS is unsigned
31998 .lte => return Air.Inst.Ref.bool_true,
31999 .gt => return Air.Inst.Ref.bool_false,
32178 .lte => return .bool_true,
32179 .gt => return .bool_false,
3200032180 else => {},
3200132181 },
3200232182 .lt => switch (op) { // LHS < 0, RHS is unsigned
32003 .neq, .lt, .lte => return Air.Inst.Ref.bool_true,
32004 .eq, .gt, .gte => return Air.Inst.Ref.bool_false,
32183 .neq, .lt, .lte => return .bool_true,
32184 .eq, .gt, .gte => return .bool_false,
3200532185 },
3200632186 }
3200732187 }
3200832188 if (lhs_is_float) {
3200932189 if (lhs_val.floatHasFraction(mod)) {
3201032190 switch (op) {
32011 .eq => return Air.Inst.Ref.bool_false,
32012 .neq => return Air.Inst.Ref.bool_true,
32191 .eq => return .bool_false,
32192 .neq => return .bool_true,
3201332193 else => {},
3201432194 }
3201532195 }
......@@ -32040,34 +32220,34 @@ fn cmpNumeric(
3204032220 if (rhs_val.isUndef(mod))
3204132221 return mod.undefRef(Type.bool);
3204232222 if (rhs_val.isNan(mod)) switch (op) {
32043 .neq => return Air.Inst.Ref.bool_true,
32044 else => return Air.Inst.Ref.bool_false,
32223 .neq => return .bool_true,
32224 else => return .bool_false,
3204532225 };
3204632226 if (rhs_val.isInf(mod)) switch (op) {
32047 .neq => return Air.Inst.Ref.bool_true,
32048 .eq => return Air.Inst.Ref.bool_false,
32049 .gt, .gte => return if (rhs_val.isNegativeInf(mod)) Air.Inst.Ref.bool_true else Air.Inst.Ref.bool_false,
32050 .lt, .lte => return if (rhs_val.isNegativeInf(mod)) Air.Inst.Ref.bool_false else Air.Inst.Ref.bool_true,
32227 .neq => return .bool_true,
32228 .eq => return .bool_false,
32229 .gt, .gte => return if (rhs_val.isNegativeInf(mod)) .bool_true else .bool_false,
32230 .lt, .lte => return if (rhs_val.isNegativeInf(mod)) .bool_false else .bool_true,
3205132231 };
3205232232 if (!lhs_is_signed) {
3205332233 switch (rhs_val.orderAgainstZero(mod)) {
3205432234 .gt => {},
3205532235 .eq => switch (op) { // RHS = 0, LHS is unsigned
32056 .gte => return Air.Inst.Ref.bool_true,
32057 .lt => return Air.Inst.Ref.bool_false,
32236 .gte => return .bool_true,
32237 .lt => return .bool_false,
3205832238 else => {},
3205932239 },
3206032240 .lt => switch (op) { // RHS < 0, LHS is unsigned
32061 .neq, .gt, .gte => return Air.Inst.Ref.bool_true,
32062 .eq, .lt, .lte => return Air.Inst.Ref.bool_false,
32241 .neq, .gt, .gte => return .bool_true,
32242 .eq, .lt, .lte => return .bool_false,
3206332243 },
3206432244 }
3206532245 }
3206632246 if (rhs_is_float) {
3206732247 if (rhs_val.floatHasFraction(mod)) {
3206832248 switch (op) {
32069 .eq => return Air.Inst.Ref.bool_false,
32070 .neq => return Air.Inst.Ref.bool_true,
32249 .eq => return .bool_false,
32250 .neq => return .bool_true,
3207132251 else => {},
3207232252 }
3207332253 }
......@@ -32185,7 +32365,7 @@ fn compareIntsOnlyPossibleResult(
3218532365
3218632366 const ty = try mod.intType(
3218732367 if (is_negative) .signed else .unsigned,
32188 @as(u16, @intCast(req_bits)),
32368 @intCast(req_bits),
3218932369 );
3219032370 const pop_count = lhs_val.popCount(ty, mod);
3219132371
......@@ -32687,7 +32867,7 @@ fn resolvePeerTypes(
3268732867 .success => |ty| return ty,
3268832868 else => |result| {
3268932869 const msg = try result.report(sema, block, src, instructions, candidate_srcs);
32690 return sema.failWithOwnedErrorMsg(msg);
32870 return sema.failWithOwnedErrorMsg(block, msg);
3269132871 },
3269232872 }
3269332873}
......@@ -32960,7 +33140,7 @@ fn resolvePeerTypesInner(
3296033140 };
3296133141
3296233142 return .{ .success = try mod.vectorType(.{
32963 .len = @as(u32, @intCast(len.?)),
33143 .len = @intCast(len.?),
3296433144 .child = child_ty.toIntern(),
3296533145 }) };
3296633146 },
......@@ -34045,7 +34225,7 @@ fn resolveStructLayout(sema: *Sema, ty: Type) CompileError!void {
3404534225 "struct '{}' depends on itself",
3404634226 .{ty.fmt(mod)},
3404734227 );
34048 return sema.failWithOwnedErrorMsg(msg);
34228 return sema.failWithOwnedErrorMsg(null, msg);
3404934229 },
3405034230 .have_layout, .fully_resolved_wip, .fully_resolved => return,
3405134231 }
......@@ -34080,7 +34260,7 @@ fn resolveStructLayout(sema: *Sema, ty: Type) CompileError!void {
3408034260 "struct layout depends on it having runtime bits",
3408134261 .{},
3408234262 );
34083 return sema.failWithOwnedErrorMsg(msg);
34263 return sema.failWithOwnedErrorMsg(null, msg);
3408434264 }
3408534265
3408634266 if (struct_obj.layout == .Auto and !struct_obj.is_tuple and
......@@ -34090,7 +34270,7 @@ fn resolveStructLayout(sema: *Sema, ty: Type) CompileError!void {
3409034270
3409134271 for (struct_obj.fields.values(), 0..) |field, i| {
3409234272 optimized_order[i] = if (try sema.typeHasRuntimeBits(field.ty))
34093 @as(u32, @intCast(i))
34273 @intCast(i)
3409434274 else
3409534275 Module.Struct.omitted_field;
3409634276 }
......@@ -34131,7 +34311,7 @@ fn semaBackingIntType(mod: *Module, struct_obj: *Module.Struct) CompileError!voi
3413134311 const zir = mod.namespacePtr(struct_obj.namespace).file_scope.zir;
3413234312 const extended = zir.instructions.items(.data)[struct_obj.zir_index].extended;
3413334313 assert(extended.opcode == .struct_decl);
34134 const small = @as(Zir.Inst.StructDecl.Small, @bitCast(extended.small));
34314 const small: Zir.Inst.StructDecl.Small = @bitCast(extended.small);
3413534315
3413634316 if (small.has_backing_int) {
3413734317 var extra_index: usize = extended.operand;
......@@ -34182,7 +34362,7 @@ fn semaBackingIntType(mod: *Module, struct_obj: *Module.Struct) CompileError!voi
3418234362 const backing_int_src: LazySrcLoc = .{ .node_offset_container_tag = 0 };
3418334363 const backing_int_ty = blk: {
3418434364 if (backing_int_body_len == 0) {
34185 const backing_int_ref = @as(Zir.Inst.Ref, @enumFromInt(zir.extra[extra_index]));
34365 const backing_int_ref: Zir.Inst.Ref = @enumFromInt(zir.extra[extra_index]);
3418634366 break :blk try sema.resolveType(&block, backing_int_src, backing_int_ref);
3418734367 } else {
3418834368 const body = zir.extra[extra_index..][0..backing_int_body_len];
......@@ -34228,7 +34408,7 @@ fn semaBackingIntType(mod: *Module, struct_obj: *Module.Struct) CompileError!voi
3422834408 };
3422934409 return sema.fail(&block, LazySrcLoc.nodeOffset(0), "size of packed struct '{d}' exceeds maximum bit width of 65535", .{fields_bit_sum});
3423034410 }
34231 struct_obj.backing_int_ty = try mod.intType(.unsigned, @as(u16, @intCast(fields_bit_sum)));
34411 struct_obj.backing_int_ty = try mod.intType(.unsigned, @intCast(fields_bit_sum));
3423234412 }
3423334413}
3423434414
......@@ -34257,7 +34437,7 @@ fn checkIndexable(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) !void {
3425734437 try sema.errNote(block, src, msg, "operand must be an array, slice, tuple, or vector", .{});
3425834438 break :msg msg;
3425934439 };
34260 return sema.failWithOwnedErrorMsg(msg);
34440 return sema.failWithOwnedErrorMsg(block, msg);
3426134441 }
3426234442}
3426334443
......@@ -34280,7 +34460,7 @@ fn checkMemOperand(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) !void
3428034460 try sema.errNote(block, src, msg, "operand must be a slice, a many pointer or a pointer to an array", .{});
3428134461 break :msg msg;
3428234462 };
34283 return sema.failWithOwnedErrorMsg(msg);
34463 return sema.failWithOwnedErrorMsg(block, msg);
3428434464}
3428534465
3428634466fn resolveUnionLayout(sema: *Sema, ty: Type) CompileError!void {
......@@ -34297,7 +34477,7 @@ fn resolveUnionLayout(sema: *Sema, ty: Type) CompileError!void {
3429734477 "union '{}' depends on itself",
3429834478 .{ty.fmt(mod)},
3429934479 );
34300 return sema.failWithOwnedErrorMsg(msg);
34480 return sema.failWithOwnedErrorMsg(null, msg);
3430134481 },
3430234482 .have_layout, .fully_resolved_wip, .fully_resolved => return,
3430334483 }
......@@ -34328,7 +34508,7 @@ fn resolveUnionLayout(sema: *Sema, ty: Type) CompileError!void {
3432834508 "union layout depends on it having runtime bits",
3432934509 .{},
3433034510 );
34331 return sema.failWithOwnedErrorMsg(msg);
34511 return sema.failWithOwnedErrorMsg(null, msg);
3433234512 }
3433334513}
3433434514
......@@ -34586,7 +34766,7 @@ fn resolveTypeFieldsStruct(
3458634766 "struct '{}' depends on itself",
3458734767 .{ty.fmt(sema.mod)},
3458834768 );
34589 return sema.failWithOwnedErrorMsg(msg);
34769 return sema.failWithOwnedErrorMsg(null, msg);
3459034770 },
3459134771 .have_field_types,
3459234772 .have_layout,
......@@ -34626,7 +34806,7 @@ fn resolveTypeFieldsUnion(sema: *Sema, ty: Type, union_type: InternPool.Key.Unio
3462634806 "union '{}' depends on itself",
3462734807 .{ty.fmt(mod)},
3462834808 );
34629 return sema.failWithOwnedErrorMsg(msg);
34809 return sema.failWithOwnedErrorMsg(null, msg);
3463034810 },
3463134811 .have_field_types,
3463234812 .have_layout,
......@@ -34680,7 +34860,7 @@ fn resolveInferredErrorSet(
3468034860 try sema.mod.errNoteNonLazy(ies_func_owner_decl.srcLoc(mod), msg, "generic function declared here", .{});
3468134861 break :msg msg;
3468234862 };
34683 return sema.failWithOwnedErrorMsg(msg);
34863 return sema.failWithOwnedErrorMsg(block, msg);
3468434864 }
3468534865 // In this case we are dealing with the actual InferredErrorSet object that
3468634866 // corresponds to the function, not one created to track an inline/comptime call.
......@@ -34789,7 +34969,7 @@ fn semaStructFields(mod: *Module, struct_obj: *Module.Struct) CompileError!void
3478934969 const zir = mod.namespacePtr(struct_obj.namespace).file_scope.zir;
3479034970 const extended = zir.instructions.items(.data)[struct_obj.zir_index].extended;
3479134971 assert(extended.opcode == .struct_decl);
34792 const small = @as(Zir.Inst.StructDecl.Small, @bitCast(extended.small));
34972 const small: Zir.Inst.StructDecl.Small = @bitCast(extended.small);
3479334973 var extra_index: usize = extended.operand;
3479434974
3479534975 const src = LazySrcLoc.nodeOffset(0);
......@@ -34917,7 +35097,7 @@ fn semaStructFields(mod: *Module, struct_obj: *Module.Struct) CompileError!void
3491735097 if (has_type_body) {
3491835098 fields[field_i].type_body_len = zir.extra[extra_index];
3491935099 } else {
34920 fields[field_i].type_ref = @as(Zir.Inst.Ref, @enumFromInt(zir.extra[extra_index]));
35100 fields[field_i].type_ref = @enumFromInt(zir.extra[extra_index]);
3492135101 }
3492235102 extra_index += 1;
3492335103
......@@ -34940,7 +35120,7 @@ fn semaStructFields(mod: *Module, struct_obj: *Module.Struct) CompileError!void
3494035120 try sema.errNote(&block_scope, src, msg, "struct declared here", .{});
3494135121 break :msg msg;
3494235122 };
34943 return sema.failWithOwnedErrorMsg(msg);
35123 return sema.failWithOwnedErrorMsg(&block_scope, msg);
3494435124 }
3494535125 gop.value_ptr.* = .{
3494635126 .ty = Type.noreturn,
......@@ -35016,7 +35196,7 @@ fn semaStructFields(mod: *Module, struct_obj: *Module.Struct) CompileError!void
3501635196 try sema.addDeclaredHereNote(msg, field_ty);
3501735197 break :msg msg;
3501835198 };
35019 return sema.failWithOwnedErrorMsg(msg);
35199 return sema.failWithOwnedErrorMsg(&block_scope, msg);
3502035200 }
3502135201 if (field_ty.zigTypeTag(mod) == .NoReturn) {
3502235202 const msg = msg: {
......@@ -35030,7 +35210,7 @@ fn semaStructFields(mod: *Module, struct_obj: *Module.Struct) CompileError!void
3503035210 try sema.addDeclaredHereNote(msg, field_ty);
3503135211 break :msg msg;
3503235212 };
35033 return sema.failWithOwnedErrorMsg(msg);
35213 return sema.failWithOwnedErrorMsg(&block_scope, msg);
3503435214 }
3503535215 if (struct_obj.layout == .Extern and !try sema.validateExternType(field.ty, .struct_field)) {
3503635216 const msg = msg: {
......@@ -35046,7 +35226,7 @@ fn semaStructFields(mod: *Module, struct_obj: *Module.Struct) CompileError!void
3504635226 try sema.addDeclaredHereNote(msg, field.ty);
3504735227 break :msg msg;
3504835228 };
35049 return sema.failWithOwnedErrorMsg(msg);
35229 return sema.failWithOwnedErrorMsg(&block_scope, msg);
3505035230 } else if (struct_obj.layout == .Packed and !(validatePackedType(field.ty, mod))) {
3505135231 const msg = msg: {
3505235232 const ty_src = mod.fieldSrcLoc(struct_obj.owner_decl, .{
......@@ -35061,7 +35241,7 @@ fn semaStructFields(mod: *Module, struct_obj: *Module.Struct) CompileError!void
3506135241 try sema.addDeclaredHereNote(msg, field.ty);
3506235242 break :msg msg;
3506335243 };
35064 return sema.failWithOwnedErrorMsg(msg);
35244 return sema.failWithOwnedErrorMsg(&block_scope, msg);
3506535245 }
3506635246
3506735247 if (zir_field.align_body_len > 0) {
......@@ -35112,7 +35292,9 @@ fn semaStructFields(mod: *Module, struct_obj: *Module.Struct) CompileError!void
3511235292 .index = field_i,
3511335293 .range = .value,
3511435294 }).lazy;
35115 return sema.failWithNeededComptime(&block_scope, init_src, "struct field default value must be comptime-known");
35295 return sema.failWithNeededComptime(&block_scope, init_src, .{
35296 .needed_comptime_reason = "struct field default value must be comptime-known",
35297 });
3511635298 };
3511735299 field.default_val = try default_val.intern(field.ty, mod);
3511835300 }
......@@ -35247,7 +35429,7 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Key.Un
3524735429 });
3524835430 break :msg msg;
3524935431 };
35250 return sema.failWithOwnedErrorMsg(msg);
35432 return sema.failWithOwnedErrorMsg(&block_scope, msg);
3525135433 }
3525235434 enum_field_names = try sema.arena.alloc(InternPool.NullTerminatedString, fields_len);
3525335435 try enum_field_vals.ensureTotalCapacity(sema.arena, fields_len);
......@@ -35362,7 +35544,7 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Key.Un
3536235544 try sema.errNote(&block_scope, other_field_src, msg, "other occurrence here", .{});
3536335545 break :msg msg;
3536435546 };
35365 return sema.failWithOwnedErrorMsg(msg);
35547 return sema.failWithOwnedErrorMsg(&block_scope, msg);
3536635548 }
3536735549 }
3536835550
......@@ -35407,7 +35589,7 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Key.Un
3540735589 try sema.errNote(&block_scope, src, msg, "union declared here", .{});
3540835590 break :msg msg;
3540935591 };
35410 return sema.failWithOwnedErrorMsg(msg);
35592 return sema.failWithOwnedErrorMsg(&block_scope, msg);
3541135593 }
3541235594
3541335595 if (explicit_tags_seen.len > 0) {
......@@ -35425,7 +35607,7 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Key.Un
3542535607 try sema.addDeclaredHereNote(msg, union_type.tagTypePtr(ip).toType());
3542635608 break :msg msg;
3542735609 };
35428 return sema.failWithOwnedErrorMsg(msg);
35610 return sema.failWithOwnedErrorMsg(&block_scope, msg);
3542935611 };
3543035612 // No check for duplicate because the check already happened in order
3543135613 // to create the enum type in the first place.
......@@ -35447,7 +35629,7 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Key.Un
3544735629 try sema.errNote(&block_scope, enum_field_src, msg, "enum field here", .{});
3544835630 break :msg msg;
3544935631 };
35450 return sema.failWithOwnedErrorMsg(msg);
35632 return sema.failWithOwnedErrorMsg(&block_scope, msg);
3545135633 }
3545235634 }
3545335635
......@@ -35463,7 +35645,7 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Key.Un
3546335645 try sema.addDeclaredHereNote(msg, field_ty);
3546435646 break :msg msg;
3546535647 };
35466 return sema.failWithOwnedErrorMsg(msg);
35648 return sema.failWithOwnedErrorMsg(&block_scope, msg);
3546735649 }
3546835650 const layout = union_type.getLayout(ip);
3546935651 if (layout == .Extern and
......@@ -35482,7 +35664,7 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Key.Un
3548235664 try sema.addDeclaredHereNote(msg, field_ty);
3548335665 break :msg msg;
3548435666 };
35485 return sema.failWithOwnedErrorMsg(msg);
35667 return sema.failWithOwnedErrorMsg(&block_scope, msg);
3548635668 } else if (layout == .Packed and !validatePackedType(field_ty, mod)) {
3548735669 const msg = msg: {
3548835670 const ty_src = mod.fieldSrcLoc(union_type.decl, .{
......@@ -35497,7 +35679,7 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Key.Un
3549735679 try sema.addDeclaredHereNote(msg, field_ty);
3549835680 break :msg msg;
3549935681 };
35500 return sema.failWithOwnedErrorMsg(msg);
35682 return sema.failWithOwnedErrorMsg(&block_scope, msg);
3550135683 }
3550235684
3550335685 field_types.appendAssumeCapacity(field_ty.toIntern());
......@@ -35541,7 +35723,7 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Key.Un
3554135723 try sema.addDeclaredHereNote(msg, union_type.tagTypePtr(ip).toType());
3554235724 break :msg msg;
3554335725 };
35544 return sema.failWithOwnedErrorMsg(msg);
35726 return sema.failWithOwnedErrorMsg(&block_scope, msg);
3554535727 }
3554635728 } else if (enum_field_vals.count() > 0) {
3554735729 const enum_ty = try sema.generateUnionTagTypeNumbered(&block_scope, enum_field_names, enum_field_vals.keys(), mod.declPtr(union_type.decl));
......@@ -35554,7 +35736,9 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Key.Un
3555435736
3555535737fn semaUnionFieldVal(sema: *Sema, block: *Block, src: LazySrcLoc, int_tag_ty: Type, tag_ref: Air.Inst.Ref) CompileError!Value {
3555635738 const coerced = try sema.coerce(block, int_tag_ty, tag_ref, src);
35557 return sema.resolveConstValue(block, src, coerced, "enum tag value must be comptime-known");
35739 return sema.resolveConstValue(block, src, coerced, .{
35740 .needed_comptime_reason = "enum tag value must be comptime-known",
35741 });
3555835742}
3555935743
3556035744fn generateUnionTagTypeNumbered(
......@@ -35950,7 +36134,7 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {
3595036134 .{ty.fmt(mod)},
3595136135 );
3595236136 try sema.addFieldErrNote(ty, i, msg, "while checking this field", .{});
35953 return sema.failWithOwnedErrorMsg(msg);
36137 return sema.failWithOwnedErrorMsg(null, msg);
3595436138 }
3595536139 if (try sema.typeHasOnePossibleValue(field.ty)) |field_opv| {
3595636140 field_val.* = try field_opv.intern(field.ty, mod);
......@@ -36004,7 +36188,7 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {
3600436188 .{ty.fmt(mod)},
3600536189 );
3600636190 try sema.addFieldErrNote(ty, 0, msg, "while checking this field", .{});
36007 return sema.failWithOwnedErrorMsg(msg);
36191 return sema.failWithOwnedErrorMsg(null, msg);
3600836192 }
3600936193 const val_val = (try sema.typeHasOnePossibleValue(only_field_ty)) orelse
3601036194 return null;
......@@ -36076,13 +36260,12 @@ pub fn addExtra(sema: *Sema, extra: anytype) Allocator.Error!u32 {
3607636260
3607736261pub fn addExtraAssumeCapacity(sema: *Sema, extra: anytype) u32 {
3607836262 const fields = std.meta.fields(@TypeOf(extra));
36079 const result = @as(u32, @intCast(sema.air_extra.items.len));
36263 const result: u32 = @intCast(sema.air_extra.items.len);
3608036264 inline for (fields) |field| {
3608136265 sema.air_extra.appendAssumeCapacity(switch (field.type) {
3608236266 u32 => @field(extra, field.name),
36083 Air.Inst.Ref => @intFromEnum(@field(extra, field.name)),
36084 i32 => @as(u32, @bitCast(@field(extra, field.name))),
36085 InternPool.Index => @intFromEnum(@field(extra, field.name)),
36267 i32 => @bitCast(@field(extra, field.name)),
36268 Air.Inst.Ref, InternPool.Index => @intFromEnum(@field(extra, field.name)),
3608636269 else => @compileError("bad field type: " ++ @typeName(field.type)),
3608736270 });
3608836271 }
......@@ -36090,8 +36273,7 @@ pub fn addExtraAssumeCapacity(sema: *Sema, extra: anytype) u32 {
3609036273}
3609136274
3609236275fn appendRefsAssumeCapacity(sema: *Sema, refs: []const Air.Inst.Ref) void {
36093 const coerced = @as([]const u32, @ptrCast(refs));
36094 sema.air_extra.appendSliceAssumeCapacity(coerced);
36276 sema.air_extra.appendSliceAssumeCapacity(@ptrCast(refs));
3609536277}
3609636278
3609736279fn getBreakBlock(sema: *Sema, inst_index: Air.Inst.Index) ?Air.Inst.Index {
......@@ -36180,7 +36362,9 @@ pub fn analyzeAddressSpace(
3618036362 ctx: AddressSpaceContext,
3618136363) !std.builtin.AddressSpace {
3618236364 const mod = sema.mod;
36183 const addrspace_tv = try sema.resolveInstConst(block, src, zir_ref, "address space must be comptime-known");
36365 const addrspace_tv = try sema.resolveInstConst(block, src, zir_ref, .{
36366 .needed_comptime_reason = "address space must be comptime-known",
36367 });
3618436368 const address_space = mod.toEnum(std.builtin.AddressSpace, addrspace_tv.val);
3618536369 const target = sema.mod.getTarget();
3618636370 const arch = target.cpu.arch;
......@@ -36547,7 +36731,7 @@ fn structFieldAlignment(sema: *Sema, field: Module.Struct.Field, layout: std.bui
3654736731 const mod = sema.mod;
3654836732 if (field.abi_align.toByteUnitsOptional()) |a| {
3654936733 assert(layout != .Packed);
36550 return @as(u32, @intCast(a));
36734 return @intCast(a);
3655136735 }
3655236736 switch (layout) {
3655336737 .Packed => return 0,
......@@ -36612,7 +36796,7 @@ fn structFieldIndex(
3661236796 const struct_obj = mod.typeToStruct(struct_ty).?;
3661336797 const field_index_usize = struct_obj.fields.getIndex(field_name) orelse
3661436798 return sema.failWithBadStructFieldAccess(block, struct_obj, field_src, field_name);
36615 return @as(u32, @intCast(field_index_usize));
36799 return @intCast(field_index_usize);
3661636800 }
3661736801}
3661836802
......@@ -36626,12 +36810,12 @@ fn anonStructFieldIndex(
3662636810 const mod = sema.mod;
3662736811 switch (mod.intern_pool.indexToKey(struct_ty.toIntern())) {
3662836812 .anon_struct_type => |anon_struct_type| for (anon_struct_type.names, 0..) |name, i| {
36629 if (name == field_name) return @as(u32, @intCast(i));
36813 if (name == field_name) return @intCast(i);
3663036814 },
3663136815 .struct_type => |struct_type| if (mod.structPtrUnwrap(struct_type.index)) |struct_obj| {
3663236816 for (struct_obj.fields.keys(), 0..) |name, i| {
3663336817 if (name == field_name) {
36634 return @as(u32, @intCast(i));
36818 return @intCast(i);
3663536819 }
3663636820 }
3663736821 },
......@@ -37229,9 +37413,9 @@ fn elemPtrType(sema: *Sema, ptr_ty: Type, offset: ?usize) !Type {
3722937413 if (!is_packed) break :blk .{};
3723037414
3723137415 break :blk .{
37232 .host_size = @as(u16, @intCast(parent_ty.arrayLen(mod))),
37233 .alignment = @as(u32, @intCast(parent_ty.abiAlignment(mod))),
37234 .vector_index = if (offset) |some| @as(VI, @enumFromInt(some)) else .runtime,
37416 .host_size = @intCast(parent_ty.arrayLen(mod)),
37417 .alignment = @intCast(parent_ty.abiAlignment(mod)),
37418 .vector_index = if (offset) |some| @enumFromInt(some) else .runtime,
3723537419 };
3723637420 } else .{};
3723737421
......@@ -37250,10 +37434,10 @@ fn elemPtrType(sema: *Sema, ptr_ty: Type, offset: ?usize) !Type {
3725037434 // The resulting pointer is aligned to the lcd between the offset (an
3725137435 // arbitrary number) and the alignment factor (always a power of two,
3725237436 // non zero).
37253 const new_align = @as(Alignment, @enumFromInt(@min(
37437 const new_align: Alignment = @enumFromInt(@min(
3725437438 @ctz(addend),
3725537439 @intFromEnum(ptr_info.flags.alignment),
37256 )));
37440 ));
3725737441 assert(new_align != .none);
3725837442 break :a new_align;
3725937443 };
test/cases/compile_errors/recursive_inline_fn.zig+17
......@@ -11,8 +11,25 @@ pub export fn entry() void {
1111 _ = foo(x) == 20;
1212}
1313
14inline fn first() void {
15 second();
16}
17
18inline fn second() void {
19 third();
20}
21
22inline fn third() void {
23 first();
24}
25
26pub export fn entry2() void {
27 first();
28}
29
1430// error
1531// backend=stage2
1632// target=native
1733//
1834// :5:27: error: inline call is recursive
35// :23:10: error: inline call is recursive