authorgravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2023-08-26 16:55:32-04:00
committergravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2023-08-28 17:25:39-04:00
logacd35a1aa75c78dc24859fa658f6d3e25e330b8a
tree974281bb9fcca0dd474138bf14f71508e8107f00
parentbdbe16c47a1a7bb7412bcfbf39c9f32d22a7e2cb

Sema: factor out `NeededComptimeReason` from comptime value resolution

This makes the call sites easier to read, reduces the number of `catch` expressions required, and prepares for comptime reasons to appear earlier in the list of notes.

2 files changed, 394 insertions(+), 179 deletions(-)

src/Module.zig+6-2
......@@ -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+388-177
......@@ -818,6 +818,11 @@ const InferredAlloc = struct {
818818 }) = .{},
819819};
820820
821const NeededComptimeReason = struct {
822 needed_comptime_reason: []const u8,
823 block_comptime_reason: ?*const Block.ComptimeReason = null,
824};
825
821826pub fn deinit(sema: *Sema) void {
822827 const gpa = sema.gpa;
823828 sema.air_instructions.deinit(gpa);
......@@ -1654,10 +1659,10 @@ fn analyzeBodyInner(
16541659 const extra = sema.code.extraData(Zir.Inst.CondBr, inst_data.payload_index);
16551660 const then_body = sema.code.extra[extra.end..][0..extra.data.then_body_len];
16561661 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 };
1662 const cond = try sema.resolveInstConst(block, cond_src, extra.data.condition, .{
1663 .needed_comptime_reason = "condition in comptime branch must be comptime-known",
1664 .block_comptime_reason = block.comptime_reason,
1665 });
16611666 const inline_body = if (cond.val.toBool()) then_body else else_body;
16621667
16631668 try sema.maybeErrorUnwrapCondbr(block, inline_body, extra.data.condition, cond_src);
......@@ -1675,10 +1680,10 @@ fn analyzeBodyInner(
16751680 const extra = sema.code.extraData(Zir.Inst.CondBr, inst_data.payload_index);
16761681 const then_body = sema.code.extra[extra.end..][0..extra.data.then_body_len];
16771682 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 };
1683 const cond = try sema.resolveInstConst(block, cond_src, extra.data.condition, .{
1684 .needed_comptime_reason = "condition in comptime branch must be comptime-known",
1685 .block_comptime_reason = block.comptime_reason,
1686 });
16821687 const inline_body = if (cond.val.toBool()) then_body else else_body;
16831688
16841689 try sema.maybeErrorUnwrapCondbr(block, inline_body, extra.data.condition, cond_src);
......@@ -1708,10 +1713,10 @@ fn analyzeBodyInner(
17081713 }
17091714 const is_non_err = try sema.analyzeIsNonErrComptimeOnly(block, operand_src, err_union);
17101715 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 };
1716 const is_non_err_val = try sema.resolveConstValue(block, operand_src, is_non_err, .{
1717 .needed_comptime_reason = "try operand inside comptime block must be comptime-known",
1718 .block_comptime_reason = block.comptime_reason,
1719 });
17151720 if (is_non_err_val.toBool()) {
17161721 break :blk try sema.analyzeErrUnionPayload(block, src, err_union_ty, err_union, operand_src, false);
17171722 }
......@@ -1734,10 +1739,10 @@ fn analyzeBodyInner(
17341739 const err_union = try sema.analyzeLoad(block, src, operand, operand_src);
17351740 const is_non_err = try sema.analyzeIsNonErrComptimeOnly(block, operand_src, err_union);
17361741 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 };
1742 const is_non_err_val = try sema.resolveConstValue(block, operand_src, is_non_err, .{
1743 .needed_comptime_reason = "try operand inside comptime block must be comptime-known",
1744 .block_comptime_reason = block.comptime_reason,
1745 });
17411746 if (is_non_err_val.toBool()) {
17421747 break :blk try sema.analyzeErrUnionPayloadPtr(block, src, operand, false, false);
17431748 }
......@@ -1831,7 +1836,7 @@ fn resolveConstBool(
18311836 block: *Block,
18321837 src: LazySrcLoc,
18331838 zir_ref: Zir.Inst.Ref,
1834 reason: []const u8,
1839 reason: NeededComptimeReason,
18351840) !bool {
18361841 const air_inst = try sema.resolveInst(zir_ref);
18371842 const wanted_type = Type.bool;
......@@ -1845,7 +1850,7 @@ pub fn resolveConstString(
18451850 block: *Block,
18461851 src: LazySrcLoc,
18471852 zir_ref: Zir.Inst.Ref,
1848 reason: []const u8,
1853 reason: NeededComptimeReason,
18491854) ![]u8 {
18501855 const air_inst = try sema.resolveInst(zir_ref);
18511856 const wanted_type = Type.slice_const_u8;
......@@ -1859,7 +1864,7 @@ pub fn resolveConstStringIntern(
18591864 block: *Block,
18601865 src: LazySrcLoc,
18611866 zir_ref: Zir.Inst.Ref,
1862 reason: []const u8,
1867 reason: NeededComptimeReason,
18631868) !InternPool.NullTerminatedString {
18641869 const air_inst = try sema.resolveInst(zir_ref);
18651870 const wanted_type = Type.slice_const_u8;
......@@ -1931,7 +1936,9 @@ fn analyzeAsType(
19311936) !Type {
19321937 const wanted_type = Type.type;
19331938 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");
1939 const val = try sema.resolveConstValue(block, src, coerced_inst, .{
1940 .needed_comptime_reason = "types must be comptime-known",
1941 });
19351942 return val.toType();
19361943}
19371944
......@@ -1984,7 +1991,7 @@ fn resolveValue(
19841991 block: *Block,
19851992 src: LazySrcLoc,
19861993 air_ref: Air.Inst.Ref,
1987 reason: []const u8,
1994 reason: NeededComptimeReason,
19881995) CompileError!Value {
19891996 if (try sema.resolveMaybeUndefValAllowVariables(air_ref)) |val| {
19901997 if (val.isGenericPoison()) return error.GenericPoison;
......@@ -2000,7 +2007,7 @@ fn resolveConstMaybeUndefVal(
20002007 block: *Block,
20012008 src: LazySrcLoc,
20022009 inst: Air.Inst.Ref,
2003 reason: []const u8,
2010 reason: NeededComptimeReason,
20042011) CompileError!Value {
20052012 if (try sema.resolveMaybeUndefValAllowVariables(inst)) |val| {
20062013 if (val.isGenericPoison()) return error.GenericPoison;
......@@ -2018,7 +2025,7 @@ fn resolveConstValue(
20182025 block: *Block,
20192026 src: LazySrcLoc,
20202027 air_ref: Air.Inst.Ref,
2021 reason: []const u8,
2028 reason: NeededComptimeReason,
20222029) CompileError!Value {
20232030 if (try sema.resolveMaybeUndefValAllowVariables(air_ref)) |val| {
20242031 if (val.isGenericPoison()) return error.GenericPoison;
......@@ -2037,7 +2044,7 @@ fn resolveConstLazyValue(
20372044 block: *Block,
20382045 src: LazySrcLoc,
20392046 air_ref: Air.Inst.Ref,
2040 reason: []const u8,
2047 reason: NeededComptimeReason,
20412048) CompileError!Value {
20422049 return sema.resolveLazyValue(try sema.resolveConstValue(block, src, air_ref, reason));
20432050}
......@@ -2140,12 +2147,15 @@ fn resolveMaybeUndefValAllowVariablesMaybeRuntime(
21402147 return val;
21412148}
21422149
2143fn failWithNeededComptime(sema: *Sema, block: *Block, src: LazySrcLoc, reason: []const u8) CompileError {
2150fn failWithNeededComptime(sema: *Sema, block: *Block, src: LazySrcLoc, reason: NeededComptimeReason) CompileError {
21442151 const msg = msg: {
21452152 const msg = try sema.errMsg(block, src, "unable to resolve comptime value", .{});
21462153 errdefer msg.destroy(sema.gpa);
2154 try sema.errNote(block, src, msg, "{s}", .{reason.needed_comptime_reason});
21472155
2148 try sema.errNote(block, src, msg, "{s}", .{reason});
2156 if (reason.block_comptime_reason) |block_comptime_reason| {
2157 try block_comptime_reason.explain(sema, msg);
2158 }
21492159 break :msg msg;
21502160 };
21512161 return sema.failWithOwnedErrorMsg(msg);
......@@ -2507,7 +2517,9 @@ fn analyzeAsAlign(
25072517 src: LazySrcLoc,
25082518 air_ref: Air.Inst.Ref,
25092519) !Alignment {
2510 const alignment_big = try sema.analyzeAsInt(block, src, air_ref, align_ty, "alignment must be comptime-known");
2520 const alignment_big = try sema.analyzeAsInt(block, src, air_ref, align_ty, .{
2521 .needed_comptime_reason = "alignment must be comptime-known",
2522 });
25112523 const alignment: u32 = @intCast(alignment_big); // We coerce to u29 in the prev line.
25122524 try sema.validateAlign(block, src, alignment);
25132525 return Alignment.fromNonzeroByteUnits(alignment);
......@@ -2543,7 +2555,7 @@ fn resolveInt(
25432555 src: LazySrcLoc,
25442556 zir_ref: Zir.Inst.Ref,
25452557 dest_ty: Type,
2546 reason: []const u8,
2558 reason: NeededComptimeReason,
25472559) !u64 {
25482560 const air_ref = try sema.resolveInst(zir_ref);
25492561 return sema.analyzeAsInt(block, src, air_ref, dest_ty, reason);
......@@ -2555,7 +2567,7 @@ fn analyzeAsInt(
25552567 src: LazySrcLoc,
25562568 air_ref: Air.Inst.Ref,
25572569 dest_ty: Type,
2558 reason: []const u8,
2570 reason: NeededComptimeReason,
25592571) !u64 {
25602572 const mod = sema.mod;
25612573 const coerced = try sema.coerce(block, dest_ty, air_ref, src);
......@@ -2570,7 +2582,7 @@ pub fn resolveInstConst(
25702582 block: *Block,
25712583 src: LazySrcLoc,
25722584 zir_ref: Zir.Inst.Ref,
2573 reason: []const u8,
2585 reason: NeededComptimeReason,
25742586) CompileError!TypedValue {
25752587 const air_ref = try sema.resolveInst(zir_ref);
25762588 const val = try sema.resolveConstValue(block, src, air_ref, reason);
......@@ -2587,7 +2599,7 @@ pub fn resolveInstValue(
25872599 block: *Block,
25882600 src: LazySrcLoc,
25892601 zir_ref: Zir.Inst.Ref,
2590 reason: []const u8,
2602 reason: NeededComptimeReason,
25912603) CompileError!TypedValue {
25922604 const air_ref = try sema.resolveInst(zir_ref);
25932605 const val = try sema.resolveValue(block, src, air_ref, reason);
......@@ -2972,7 +2984,7 @@ fn createAnonymousDeclTypeNamed(
29722984 // If not then this is a struct type being returned from a non-generic
29732985 // function and the name doesn't matter since it will later
29742986 // result in a compile error.
2975 const arg_val = sema.resolveConstMaybeUndefVal(block, .unneeded, arg, "") catch
2987 const arg_val = sema.resolveConstMaybeUndefVal(block, .unneeded, arg, undefined) catch
29762988 return sema.createAnonymousDeclTypeNamed(block, src, typed_value, .anon, anon_prefix, null);
29772989
29782990 if (arg_i != 0) try writer.writeByte(',');
......@@ -3221,13 +3233,15 @@ fn zirEnumDecl(
32213233 const tag_val_ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_index]);
32223234 extra_index += 1;
32233235 const tag_inst = try sema.resolveInst(tag_val_ref);
3224 last_tag_val = sema.resolveConstValue(block, .unneeded, tag_inst, "") catch |err| switch (err) {
3236 last_tag_val = sema.resolveConstValue(block, .unneeded, tag_inst, undefined) catch |err| switch (err) {
32253237 error.NeededSourceLocation => {
32263238 const value_src = mod.fieldSrcLoc(new_decl_index, .{
32273239 .index = field_i,
32283240 .range = .value,
32293241 }).lazy;
3230 _ = try sema.resolveConstValue(block, value_src, tag_inst, "enum tag value must be comptime-known");
3242 _ = try sema.resolveConstValue(block, value_src, tag_inst, .{
3243 .needed_comptime_reason = "enum tag value must be comptime-known",
3244 });
32313245 unreachable;
32323246 },
32333247 else => |e| return e,
......@@ -4611,7 +4625,9 @@ fn validateUnionInit(
46114625 try sema.storePtr2(block, init_src, union_ptr, init_src, union_init, init_src, .store);
46124626 return;
46134627 } 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");
4628 return sema.failWithNeededComptime(block, field_ptr_data.src(), .{
4629 .needed_comptime_reason = "initializer of comptime only union must be comptime-known",
4630 });
46154631 }
46164632
46174633 const new_tag = Air.internedToRef(tag_val.toIntern());
......@@ -4806,7 +4822,9 @@ fn validateStructInit(
48064822 field_values[i] = val.toIntern();
48074823 } else if (require_comptime) {
48084824 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");
4825 return sema.failWithNeededComptime(block, field_ptr_data.src(), .{
4826 .needed_comptime_reason = "initializer of comptime only struct must be comptime-known",
4827 });
48104828 } else {
48114829 struct_is_comptime = false;
48124830 }
......@@ -5331,13 +5349,17 @@ fn storeToInferredAllocComptime(
53315349 return;
53325350 }
53335351
5334 return sema.failWithNeededComptime(block, src, "value being stored to a comptime variable must be comptime-known");
5352 return sema.failWithNeededComptime(block, src, .{
5353 .needed_comptime_reason = "value being stored to a comptime variable must be comptime-known",
5354 });
53355355}
53365356
53375357fn zirSetEvalBranchQuota(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void {
53385358 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
53395359 const src = inst_data.src();
5340 const quota: u32 = @intCast(try sema.resolveInt(block, src, inst_data.operand, Type.u32, "eval branch quota must be comptime-known"));
5360 const quota: u32 = @intCast(try sema.resolveInt(block, src, inst_data.operand, Type.u32, .{
5361 .needed_comptime_reason = "eval branch quota must be comptime-known",
5362 }));
53415363 sema.branch_quota = @max(sema.branch_quota, quota);
53425364}
53435365
......@@ -5479,7 +5501,9 @@ fn zirCompileError(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
54795501 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
54805502 const src = inst_data.src();
54815503 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");
5504 const msg = try sema.resolveConstString(block, operand_src, inst_data.operand, .{
5505 .needed_comptime_reason = "compile error string must be comptime-known",
5506 });
54835507 return sema.fail(block, src, "{s}", .{msg});
54845508}
54855509
......@@ -6001,7 +6025,9 @@ fn zirExportValue(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
60016025 const src = inst_data.src();
60026026 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
60036027 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");
6028 const operand = try sema.resolveInstConst(block, operand_src, extra.operand, .{
6029 .needed_comptime_reason = "export target must be comptime-known",
6030 });
60056031 const options = sema.resolveExportOptions(block, .unneeded, extra.options) catch |err| switch (err) {
60066032 error.NeededSourceLocation => {
60076033 _ = try sema.resolveExportOptions(block, options_src, extra.options);
......@@ -6140,7 +6166,9 @@ fn zirSetCold(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData)
61406166 const ip = &mod.intern_pool;
61416167 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;
61426168 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");
6169 const is_cold = try sema.resolveConstBool(block, operand_src, extra.operand, .{
6170 .needed_comptime_reason = "operand to @setCold must be comptime-known",
6171 });
61446172 if (sema.func_index == .none) return; // does nothing outside a function
61456173 ip.funcAnalysis(sema.func_index).is_cold = is_cold;
61466174}
......@@ -6148,13 +6176,17 @@ fn zirSetCold(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData)
61486176fn zirSetFloatMode(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!void {
61496177 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;
61506178 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");
6179 block.float_mode = try sema.resolveBuiltinEnum(block, src, extra.operand, "FloatMode", .{
6180 .needed_comptime_reason = "operand to @setFloatMode must be comptime-known",
6181 });
61526182}
61536183
61546184fn zirSetRuntimeSafety(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void {
61556185 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
61566186 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");
6187 block.want_safety = try sema.resolveConstBool(block, operand_src, inst_data.operand, .{
6188 .needed_comptime_reason = "operand to @setRuntimeSafety must be comptime-known",
6189 });
61586190}
61596191
61606192fn zirFence(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!void {
......@@ -6162,7 +6194,9 @@ fn zirFence(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) Co
61626194
61636195 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;
61646196 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");
6197 const order = try sema.resolveAtomicOrder(block, order_src, extra.operand, .{
6198 .needed_comptime_reason = "atomic order of @fence must be comptime-known",
6199 });
61666200
61676201 if (@intFromEnum(order) < @intFromEnum(std.builtin.AtomicOrder.Acquire)) {
61686202 return sema.fail(block, order_src, "atomic ordering must be Acquire or stricter", .{});
......@@ -7194,10 +7228,10 @@ fn analyzeCall(
71947228 }
71957229
71967230 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 };
7231 const func_val = try sema.resolveConstValue(block, func_src, func, .{
7232 .needed_comptime_reason = "function being called at comptime must be comptime-known",
7233 .block_comptime_reason = comptime_reason,
7234 });
72017235 const module_fn_index = switch (mod.intern_pool.indexToKey(func_val.toIntern())) {
72027236 .extern_func => return sema.fail(block, call_src, "{s} call of extern function", .{
72037237 @as([]const u8, if (is_comptime_call) "comptime" else "inline"),
......@@ -7451,7 +7485,7 @@ fn analyzeCall(
74517485 }
74527486
74537487 if (should_memoize and is_comptime_call) {
7454 const result_val = try sema.resolveConstMaybeUndefVal(block, .unneeded, result, "");
7488 const result_val = try sema.resolveConstMaybeUndefVal(block, .unneeded, result, undefined);
74557489 const result_interned = try result_val.intern2(sema.fn_ret_ty, mod);
74567490
74577491 // Transform ad-hoc inferred error set types into concrete error sets.
......@@ -7628,20 +7662,22 @@ fn analyzeInlineCallArg(
76287662 }
76297663 const arg_src = args_info.argSrc(arg_block, arg_i.*);
76307664 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 };
7665 _ = try ics.caller().resolveConstMaybeUndefVal(arg_block, arg_src, casted_arg, .{
7666 .needed_comptime_reason = "argument to parameter with comptime-only type must be comptime-known",
7667 .block_comptime_reason = param_block.comptime_reason,
7668 });
76357669 } 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");
7670 _ = try ics.caller().resolveConstMaybeUndefVal(arg_block, arg_src, casted_arg, .{
7671 .needed_comptime_reason = "parameter is comptime",
7672 });
76377673 }
76387674
76397675 if (is_comptime_call) {
76407676 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 };
7677 const arg_val = try ics.caller().resolveConstMaybeUndefVal(arg_block, arg_src, casted_arg, .{
7678 .needed_comptime_reason = "argument to function being called at comptime must be comptime-known",
7679 .block_comptime_reason = param_block.comptime_reason,
7680 });
76457681 switch (arg_val.toIntern()) {
76467682 .generic_poison, .generic_poison_type => {
76477683 // This function is currently evaluated as part of an as-of-yet unresolvable
......@@ -7677,10 +7713,10 @@ fn analyzeInlineCallArg(
76777713
76787714 if (is_comptime_call) {
76797715 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 };
7716 const arg_val = try ics.caller().resolveConstMaybeUndefVal(arg_block, arg_src, uncasted_arg, .{
7717 .needed_comptime_reason = "argument to function being called at comptime must be comptime-known",
7718 .block_comptime_reason = param_block.comptime_reason,
7719 });
76847720 switch (arg_val.toIntern()) {
76857721 .generic_poison, .generic_poison_type => {
76867722 // This function is currently evaluated as part of an as-of-yet unresolvable
......@@ -7697,7 +7733,9 @@ fn analyzeInlineCallArg(
76977733 memoized_arg_values[arg_i.*] = try resolved_arg_val.intern(ics.caller().typeOf(uncasted_arg), mod);
76987734 } else {
76997735 if (zir_tags[inst] == .param_anytype_comptime) {
7700 _ = try ics.caller().resolveConstMaybeUndefVal(arg_block, arg_src, uncasted_arg, "parameter is comptime");
7736 _ = try ics.caller().resolveConstMaybeUndefVal(arg_block, arg_src, uncasted_arg, .{
7737 .needed_comptime_reason = "parameter is comptime",
7738 });
77017739 }
77027740 ics.callee().inst_map.putAssumeCapacityNoClobber(inst, uncasted_arg);
77037741 }
......@@ -7744,7 +7782,9 @@ fn instantiateGenericCall(
77447782 const gpa = sema.gpa;
77457783 const ip = &mod.intern_pool;
77467784
7747 const func_val = try sema.resolveConstValue(block, func_src, func, "generic function being called must be comptime-known");
7785 const func_val = try sema.resolveConstValue(block, func_src, func, .{
7786 .needed_comptime_reason = "generic function being called must be comptime-known",
7787 });
77487788 const generic_owner = switch (mod.intern_pool.indexToKey(func_val.toIntern())) {
77497789 .func => func_val.toIntern(),
77507790 .ptr => |ptr| mod.declPtr(ptr.addr.decl).val.toIntern(),
......@@ -8146,7 +8186,9 @@ fn zirVectorType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
81468186 const elem_type_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
81478187 const len_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };
81488188 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
8149 const len: u32 = @intCast(try sema.resolveInt(block, len_src, extra.lhs, Type.u32, "vector length must be comptime-known"));
8189 const len: u32 = @intCast(try sema.resolveInt(block, len_src, extra.lhs, Type.u32, .{
8190 .needed_comptime_reason = "vector length must be comptime-known",
8191 }));
81508192 const elem_type = try sema.resolveType(block, elem_type_src, extra.rhs);
81518193 try sema.checkVectorElemType(block, elem_type_src, elem_type);
81528194 const vector_type = try mod.vectorType(.{
......@@ -8164,7 +8206,9 @@ fn zirArrayType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
81648206 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
81658207 const len_src: LazySrcLoc = .{ .node_offset_array_type_len = inst_data.src_node };
81668208 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");
8209 const len = try sema.resolveInt(block, len_src, extra.lhs, Type.usize, .{
8210 .needed_comptime_reason = "array length must be comptime-known",
8211 });
81688212 const elem_type = try sema.resolveType(block, elem_src, extra.rhs);
81698213 try sema.validateArrayElemType(block, elem_type, elem_src);
81708214 const array_ty = try sema.mod.arrayType(.{
......@@ -8184,12 +8228,16 @@ fn zirArrayTypeSentinel(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compil
81848228 const len_src: LazySrcLoc = .{ .node_offset_array_type_len = inst_data.src_node };
81858229 const sentinel_src: LazySrcLoc = .{ .node_offset_array_type_sentinel = inst_data.src_node };
81868230 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");
8231 const len = try sema.resolveInt(block, len_src, extra.len, Type.usize, .{
8232 .needed_comptime_reason = "array length must be comptime-known",
8233 });
81888234 const elem_type = try sema.resolveType(block, elem_src, extra.elem_type);
81898235 try sema.validateArrayElemType(block, elem_type, elem_src);
81908236 const uncasted_sentinel = try sema.resolveInst(extra.sentinel);
81918237 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");
8238 const sentinel_val = try sema.resolveConstValue(block, sentinel_src, sentinel, .{
8239 .needed_comptime_reason = "array sentinel value must be comptime-known",
8240 });
81938241 const array_ty = try sema.mod.arrayType(.{
81948242 .len = len,
81958243 .sentinel = sentinel_val.toIntern(),
......@@ -8906,7 +8954,9 @@ fn zirFunc(
89068954 const ret_ty_body = sema.code.extra[extra_index..][0..extra.data.ret_body_len];
89078955 extra_index += ret_ty_body.len;
89088956
8909 const ret_ty_val = try sema.resolveGenericBody(block, ret_ty_src, ret_ty_body, inst, Type.type, "return type must be comptime-known");
8957 const ret_ty_val = try sema.resolveGenericBody(block, ret_ty_src, ret_ty_body, inst, Type.type, .{
8958 .needed_comptime_reason = "return type must be comptime-known",
8959 });
89108960 break :blk ret_ty_val.toType();
89118961 },
89128962 };
......@@ -8953,7 +9003,7 @@ fn resolveGenericBody(
89539003 body: []const Zir.Inst.Index,
89549004 func_inst: Zir.Inst.Index,
89559005 dest_ty: Type,
8956 reason: []const u8,
9006 reason: NeededComptimeReason,
89579007) !Value {
89589008 assert(body.len != 0);
89599009
......@@ -9852,7 +9902,9 @@ fn zirFieldValNamed(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr
98529902 const field_name_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };
98539903 const extra = sema.code.extraData(Zir.Inst.FieldNamed, inst_data.payload_index).data;
98549904 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");
9905 const field_name = try sema.resolveConstStringIntern(block, field_name_src, extra.field_name, .{
9906 .needed_comptime_reason = "field name must be comptime-known",
9907 });
98569908 return sema.fieldVal(block, src, object, field_name, field_name_src);
98579909}
98589910
......@@ -9865,7 +9917,9 @@ fn zirFieldPtrNamed(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr
98659917 const field_name_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };
98669918 const extra = sema.code.extraData(Zir.Inst.FieldNamed, inst_data.payload_index).data;
98679919 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");
9920 const field_name = try sema.resolveConstStringIntern(block, field_name_src, extra.field_name, .{
9921 .needed_comptime_reason = "field name must be comptime-known",
9922 });
98699923 return sema.fieldPtr(block, src, object_ptr, field_name, field_name_src, false);
98709924}
98719925
......@@ -10593,7 +10647,7 @@ const SwitchProngAnalysis = struct {
1059310647 const operand_src: LazySrcLoc = .{ .node_offset_switch_operand = switch_node_offset };
1059410648
1059510649 if (inline_case_capture != .none) {
10596 const item_val = sema.resolveConstValue(block, .unneeded, inline_case_capture, "") catch unreachable;
10650 const item_val = sema.resolveConstValue(block, .unneeded, inline_case_capture, undefined) catch unreachable;
1059710651 if (operand_ty.zigTypeTag(mod) == .Union) {
1059810652 const field_index: u32 = @intCast(operand_ty.unionTagFieldIndex(item_val, mod).?);
1059910653 const union_obj = mod.typeToUnion(operand_ty).?;
......@@ -10650,14 +10704,14 @@ const SwitchProngAnalysis = struct {
1065010704 switch (operand_ty.zigTypeTag(mod)) {
1065110705 .Union => {
1065210706 const union_obj = mod.typeToUnion(operand_ty).?;
10653 const first_item_val = sema.resolveConstValue(block, .unneeded, case_vals[0], "") catch unreachable;
10707 const first_item_val = sema.resolveConstValue(block, .unneeded, case_vals[0], undefined) catch unreachable;
1065410708
1065510709 const first_field_index: u32 = mod.unionTagFieldIndex(union_obj, first_item_val).?;
1065610710 const first_field_ty = union_obj.field_types.get(ip)[first_field_index].toType();
1065710711
1065810712 const field_tys = try sema.arena.alloc(Type, case_vals.len);
1065910713 for (case_vals, field_tys) |item, *field_ty| {
10660 const item_val = sema.resolveConstValue(block, .unneeded, item, "") catch unreachable;
10714 const item_val = sema.resolveConstValue(block, .unneeded, item, undefined) catch unreachable;
1066110715 const field_idx = mod.unionTagFieldIndex(union_obj, item_val).?;
1066210716 field_ty.* = union_obj.field_types.get(ip)[field_idx].toType();
1066310717 }
......@@ -10906,7 +10960,7 @@ const SwitchProngAnalysis = struct {
1090610960 }
1090710961
1090810962 if (case_vals.len == 1) {
10909 const item_val = sema.resolveConstValue(block, .unneeded, case_vals[0], "") catch unreachable;
10963 const item_val = sema.resolveConstValue(block, .unneeded, case_vals[0], undefined) catch unreachable;
1091010964 const item_ty = try mod.singleErrorSetType(item_val.getErrorName(mod).unwrap().?);
1091110965 return sema.bitCast(block, item_ty, spa.operand, operand_src, null);
1091210966 }
......@@ -10914,7 +10968,7 @@ const SwitchProngAnalysis = struct {
1091410968 var names: InferredErrorSet.NameMap = .{};
1091510969 try names.ensureUnusedCapacity(sema.arena, case_vals.len);
1091610970 for (case_vals) |err| {
10917 const err_val = sema.resolveConstValue(block, .unneeded, err, "") catch unreachable;
10971 const err_val = sema.resolveConstValue(block, .unneeded, err, undefined) catch unreachable;
1091810972 names.putAssumeCapacityNoClobber(err_val.getErrorName(mod).unwrap().?, {});
1091910973 }
1092010974 const error_ty = try mod.errorSetFromUnsortedNames(names.keys());
......@@ -11688,7 +11742,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1168811742 extra_index += info.body_len;
1168911743
1169011744 const item = case_vals.items[scalar_i];
11691 const item_val = sema.resolveConstValue(&child_block, .unneeded, item, "") catch unreachable;
11745 const item_val = sema.resolveConstValue(&child_block, .unneeded, item, undefined) catch unreachable;
1169211746 if (operand_val.eql(item_val, operand_ty, sema.mod)) {
1169311747 if (err_set) try sema.maybeErrorUnwrapComptime(&child_block, body, operand);
1169411748 return spa.resolveProngComptime(
......@@ -11722,7 +11776,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1172211776
1172311777 for (items) |item| {
1172411778 // Validation above ensured these will succeed.
11725 const item_val = sema.resolveConstValue(&child_block, .unneeded, item, "") catch unreachable;
11779 const item_val = sema.resolveConstValue(&child_block, .unneeded, item, undefined) catch unreachable;
1172611780 if (operand_val.eql(item_val, operand_ty, sema.mod)) {
1172711781 if (err_set) try sema.maybeErrorUnwrapComptime(&child_block, body, operand);
1172811782 return spa.resolveProngComptime(
......@@ -11746,8 +11800,8 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1174611800 case_val_idx += 2;
1174711801
1174811802 // 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;
11803 const first_val = sema.resolveConstValue(&child_block, .unneeded, range_items[0], undefined) catch unreachable;
11804 const last_val = sema.resolveConstValue(&child_block, .unneeded, range_items[1], undefined) catch unreachable;
1175111805 if ((try sema.compareAll(resolved_operand_val, .gte, first_val, operand_ty)) and
1175211806 (try sema.compareAll(resolved_operand_val, .lte, last_val, operand_ty)))
1175311807 {
......@@ -11819,10 +11873,10 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1181911873 }
1182011874
1182111875 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 };
11876 _ = try sema.resolveConstValue(&child_block, operand_src, operand, .{
11877 .needed_comptime_reason = "condition in comptime switch must be comptime-known",
11878 .block_comptime_reason = child_block.comptime_reason,
11879 });
1182611880 unreachable;
1182711881 }
1182811882
......@@ -11857,7 +11911,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1185711911 // `item` is already guaranteed to be constant known.
1185811912
1185911913 const analyze_body = if (union_originally) blk: {
11860 const item_val = sema.resolveConstLazyValue(block, .unneeded, item, "") catch unreachable;
11914 const item_val = sema.resolveConstLazyValue(block, .unneeded, item, undefined) catch unreachable;
1186111915 const field_ty = maybe_union_ty.unionFieldType(item_val, mod);
1186211916 break :blk field_ty.zigTypeTag(mod) != .NoReturn;
1186311917 } else true;
......@@ -12039,7 +12093,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1203912093
1204012094 const analyze_body = if (union_originally)
1204112095 for (items) |item| {
12042 const item_val = sema.resolveConstValue(block, .unneeded, item, "") catch unreachable;
12096 const item_val = sema.resolveConstValue(block, .unneeded, item, undefined) catch unreachable;
1204312097 const field_ty = maybe_union_ty.unionFieldType(item_val, mod);
1204412098 if (field_ty.zigTypeTag(mod) != .NoReturn) break true;
1204512099 } else false
......@@ -12539,10 +12593,12 @@ fn resolveSwitchItemVal(
1253912593 else => |e| return e,
1254012594 };
1254112595
12542 const maybe_lazy = sema.resolveConstValue(block, .unneeded, item, "") catch |err| switch (err) {
12596 const maybe_lazy = sema.resolveConstValue(block, .unneeded, item, undefined) catch |err| switch (err) {
1254312597 error.NeededSourceLocation => {
1254412598 const src = switch_prong_src.resolve(mod, mod.declPtr(block.src_decl), switch_node_offset, range_expand);
12545 _ = try sema.resolveConstValue(block, src, item, "switch prong values must be comptime-known");
12599 _ = try sema.resolveConstValue(block, src, item, .{
12600 .needed_comptime_reason = "switch prong values must be comptime-known",
12601 });
1254612602 unreachable;
1254712603 },
1254812604 else => |e| return e,
......@@ -12860,7 +12916,9 @@ fn zirHasField(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1286012916 const ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
1286112917 const name_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };
1286212918 const ty = try sema.resolveType(block, ty_src, extra.lhs);
12863 const field_name = try sema.resolveConstStringIntern(block, name_src, extra.rhs, "field name must be comptime-known");
12919 const field_name = try sema.resolveConstStringIntern(block, name_src, extra.rhs, .{
12920 .needed_comptime_reason = "field name must be comptime-known",
12921 });
1286412922 try sema.resolveTypeFields(ty);
1286512923 const ip = &mod.intern_pool;
1286612924
......@@ -12912,7 +12970,9 @@ fn zirHasDecl(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1291212970 const lhs_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
1291312971 const rhs_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };
1291412972 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");
12973 const decl_name = try sema.resolveConstStringIntern(block, rhs_src, extra.rhs, .{
12974 .needed_comptime_reason = "decl name must be comptime-known",
12975 });
1291612976
1291712977 try sema.checkNamespaceType(block, lhs_src, container_type);
1291812978
......@@ -12965,7 +13025,9 @@ fn zirEmbedFile(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
1296513025 const mod = sema.mod;
1296613026 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
1296713027 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");
13028 const name = try sema.resolveConstString(block, operand_src, inst_data.operand, .{
13029 .needed_comptime_reason = "file path name must be comptime-known",
13030 });
1296913031
1297013032 if (name.len == 0) {
1297113033 return sema.fail(block, operand_src, "file path name cannot be empty", .{});
......@@ -13588,8 +13650,12 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1358813650 const rhs_sent = Air.internedToRef(rhs_sent_val.toIntern());
1358913651 const lhs_sent_casted = try sema.coerce(block, resolved_elem_ty, lhs_sent, lhs_src);
1359013652 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");
13653 const lhs_sent_casted_val = try sema.resolveConstValue(block, lhs_src, lhs_sent_casted, .{
13654 .needed_comptime_reason = "array sentinel value must be comptime-known",
13655 });
13656 const rhs_sent_casted_val = try sema.resolveConstValue(block, rhs_src, rhs_sent_casted, .{
13657 .needed_comptime_reason = "array sentinel value must be comptime-known",
13658 });
1359313659 if (try sema.valuesEqual(lhs_sent_casted_val, rhs_sent_casted_val, resolved_elem_ty)) {
1359413660 break :s lhs_sent_casted_val;
1359513661 } else {
......@@ -13597,14 +13663,18 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1359713663 }
1359813664 } else {
1359913665 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");
13666 const lhs_sent_casted_val = try sema.resolveConstValue(block, lhs_src, lhs_sent_casted, .{
13667 .needed_comptime_reason = "array sentinel value must be comptime-known",
13668 });
1360113669 break :s lhs_sent_casted_val;
1360213670 }
1360313671 } else {
1360413672 if (rhs_info.sentinel) |rhs_sent_val| {
1360513673 const rhs_sent = Air.internedToRef(rhs_sent_val.toIntern());
1360613674 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");
13675 const rhs_sent_casted_val = try sema.resolveConstValue(block, rhs_src, rhs_sent_casted, .{
13676 .needed_comptime_reason = "array sentinel value must be comptime-known",
13677 });
1360813678 break :s rhs_sent_casted_val;
1360913679 } else {
1361013680 break :s null;
......@@ -13662,7 +13732,7 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1366213732 const elem_val = if (elem_default_val.toIntern() == .unreachable_value) try lhs_sub_val.elemValue(mod, lhs_elem_i) else elem_default_val;
1366313733 const elem_val_inst = Air.internedToRef(elem_val.toIntern());
1366413734 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, "");
13735 const coerced_elem_val = try sema.resolveConstMaybeUndefVal(block, .unneeded, coerced_elem_val_inst, undefined);
1366613736 element_vals[elem_i] = try coerced_elem_val.intern(resolved_elem_ty, mod);
1366713737 }
1366813738 while (elem_i < result_len) : (elem_i += 1) {
......@@ -13671,7 +13741,7 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1367113741 const elem_val = if (elem_default_val.toIntern() == .unreachable_value) try rhs_sub_val.elemValue(mod, rhs_elem_i) else elem_default_val;
1367213742 const elem_val_inst = Air.internedToRef(elem_val.toIntern());
1367313743 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, "");
13744 const coerced_elem_val = try sema.resolveConstMaybeUndefVal(block, .unneeded, coerced_elem_val_inst, undefined);
1367513745 element_vals[elem_i] = try coerced_elem_val.intern(resolved_elem_ty, mod);
1367613746 }
1367713747 return sema.addConstantMaybeRef(block, result_ty, (try mod.intern(.{ .aggregate = .{
......@@ -13748,7 +13818,9 @@ fn getArrayCatInfo(sema: *Sema, block: *Block, src: LazySrcLoc, operand: Air.Ins
1374813818 // has a sentinel, and this code should compute the length based
1374913819 // on the sentinel value.
1375013820 .Slice, .Many => {
13751 const val = try sema.resolveConstValue(block, src, operand, "slice value being concatenated must be comptime-known");
13821 const val = try sema.resolveConstValue(block, src, operand, .{
13822 .needed_comptime_reason = "slice value being concatenated must be comptime-known",
13823 });
1375213824 return Type.ArrayInfo{
1375313825 .elem_type = ptr_info.child.toType(),
1375413826 .sentinel = switch (ptr_info.sentinel) {
......@@ -13868,7 +13940,9 @@ fn zirArrayMul(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1386813940
1386913941 if (lhs_ty.isTuple(mod)) {
1387013942 // 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");
13943 const factor = try sema.resolveInt(block, rhs_src, extra.rhs, Type.usize, .{
13944 .needed_comptime_reason = "array multiplication factor must be comptime-known",
13945 });
1387213946 const factor_casted = try sema.usizeCast(block, rhs_src, factor);
1387313947 return sema.analyzeTupleMul(block, inst_data.src_node, lhs, factor_casted);
1387413948 }
......@@ -13890,7 +13964,9 @@ fn zirArrayMul(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1389013964 };
1389113965
1389213966 // 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");
13967 const factor = try sema.resolveInt(block, rhs_src, extra.rhs, Type.usize, .{
13968 .needed_comptime_reason = "array multiplication factor must be comptime-known",
13969 });
1389413970
1389513971 const result_len_u64 = std.math.mul(u64, lhs_info.len, factor) catch
1389613972 return sema.fail(block, rhs_src, "operation results in overflow", .{});
......@@ -15976,7 +16052,9 @@ fn zirAsm(
1597616052
1597716053 const asm_source: []const u8 = if (tmpl_is_expr) blk: {
1597816054 const tmpl: 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");
16055 const s: []const u8 = try sema.resolveConstString(block, src, tmpl, .{
16056 .needed_comptime_reason = "assembly code must be comptime-known",
16057 });
1598016058 break :blk s;
1598116059 } else sema.code.nullTerminatedString(extra.data.asm_source);
1598216060
......@@ -18736,7 +18814,9 @@ fn analyzeRet(
1873618814
1873718815 if (block.inlining) |inlining| {
1873818816 if (block.is_comptime) {
18739 _ = try sema.resolveConstMaybeUndefVal(block, src, operand, "value being returned at comptime must be comptime-known");
18817 _ = try sema.resolveConstMaybeUndefVal(block, src, operand, .{
18818 .needed_comptime_reason = "value being returned at comptime must be comptime-known",
18819 });
1874018820 inlining.comptime_result = operand;
1874118821 return error.ComptimeReturn;
1874218822 }
......@@ -18816,7 +18896,9 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1881618896 const ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_i]);
1881718897 extra_i += 1;
1881818898 const coerced = try sema.coerce(block, elem_ty, try sema.resolveInst(ref), sentinel_src);
18819 const val = try sema.resolveConstValue(block, sentinel_src, coerced, "pointer sentinel value must be comptime-known");
18899 const val = try sema.resolveConstValue(block, sentinel_src, coerced, .{
18900 .needed_comptime_reason = "pointer sentinel value must be comptime-known",
18901 });
1882018902 break :blk val.toIntern();
1882118903 } else .none;
1882218904
......@@ -18824,7 +18906,9 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1882418906 const ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_i]);
1882518907 extra_i += 1;
1882618908 const coerced = try sema.coerce(block, Type.u32, try sema.resolveInst(ref), align_src);
18827 const val = try sema.resolveConstValue(block, align_src, coerced, "pointer alignment must be comptime-known");
18909 const val = try sema.resolveConstValue(block, align_src, coerced, .{
18910 .needed_comptime_reason = "pointer alignment must be comptime-known",
18911 });
1882818912 // Check if this happens to be the lazy alignment of our element type, in
1882918913 // which case we can make this 0 without resolving it.
1883018914 switch (mod.intern_pool.indexToKey(val.toIntern())) {
......@@ -18848,14 +18932,18 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1884818932 const bit_offset: u16 = if (inst_data.flags.has_bit_range) blk: {
1884918933 const ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_i]);
1885018934 extra_i += 1;
18851 const bit_offset = try sema.resolveInt(block, bitoffset_src, ref, Type.u16, "pointer bit-offset must be comptime-known");
18935 const bit_offset = try sema.resolveInt(block, bitoffset_src, ref, Type.u16, .{
18936 .needed_comptime_reason = "pointer bit-offset must be comptime-known",
18937 });
1885218938 break :blk @intCast(bit_offset);
1885318939 } else 0;
1885418940
1885518941 const host_size: u16 = if (inst_data.flags.has_bit_range) blk: {
1885618942 const ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_i]);
1885718943 extra_i += 1;
18858 const host_size = try sema.resolveInt(block, hostsize_src, ref, Type.u16, "pointer host size must be comptime-known");
18944 const host_size = try sema.resolveInt(block, hostsize_src, ref, Type.u16, .{
18945 .needed_comptime_reason = "pointer host size must be comptime-known",
18946 });
1885918947 break :blk @intCast(host_size);
1886018948 } else 0;
1886118949
......@@ -18983,7 +19071,9 @@ fn zirUnionInit(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
1898319071 };
1898419072 return sema.failWithOwnedErrorMsg(msg);
1898519073 }
18986 const field_name = try sema.resolveConstStringIntern(block, field_src, extra.field_name, "name of field being initialized must be comptime-known");
19074 const field_name = try sema.resolveConstStringIntern(block, field_src, extra.field_name, .{
19075 .needed_comptime_reason = "name of field being initialized must be comptime-known",
19076 });
1898719077 const init = try sema.resolveInst(extra.init);
1898819078 return sema.unionInit(block, init, init_src, union_ty, ty_src, field_name, field_src);
1898919079}
......@@ -19091,7 +19181,9 @@ fn zirStructInit(
1909119181 field_inits[field_index] = try sema.resolveInst(item.data.init);
1909219182 if (!is_packed) if (try resolved_ty.structFieldValueComptime(mod, field_index)) |default_value| {
1909319183 const init_val = (try sema.resolveMaybeUndefVal(field_inits[field_index])) orelse {
19094 return sema.failWithNeededComptime(block, field_src, "value stored in comptime field must be comptime-known");
19184 return sema.failWithNeededComptime(block, field_src, .{
19185 .needed_comptime_reason = "value stored in comptime field must be comptime-known",
19186 });
1909519187 };
1909619188
1909719189 if (!init_val.eql(default_value, resolved_ty.structFieldType(field_index, mod), mod)) {
......@@ -19491,7 +19583,9 @@ fn zirArrayInit(
1949119583 const init_val = try sema.resolveMaybeUndefVal(resolved_args[i]) orelse {
1949219584 const decl = mod.declPtr(block.src_decl);
1949319585 const elem_src = mod.initSrc(src.node_offset.x, decl, i);
19494 return sema.failWithNeededComptime(block, elem_src, "value stored in comptime field must be comptime-known");
19586 return sema.failWithNeededComptime(block, elem_src, .{
19587 .needed_comptime_reason = "value stored in comptime field must be comptime-known",
19588 });
1949519589 };
1949619590 if (!field_val.eql(init_val, elem_ty, mod)) {
1949719591 const decl = mod.declPtr(block.src_decl);
......@@ -19699,7 +19793,9 @@ fn zirFieldTypeRef(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
1969919793 const ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
1970019794 const field_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };
1970119795 const aggregate_ty = try sema.resolveType(block, ty_src, extra.container_type);
19702 const field_name = try sema.resolveConstStringIntern(block, field_src, extra.field_name, "field name must be comptime-known");
19796 const field_name = try sema.resolveConstStringIntern(block, field_src, extra.field_name, .{
19797 .needed_comptime_reason = "field name must be comptime-known",
19798 });
1970319799 return sema.fieldType(block, aggregate_ty, field_name, field_src, ty_src);
1970419800}
1970519801
......@@ -19970,7 +20066,7 @@ fn zirTagName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1997020066 try sema.resolveTypeLayout(operand_ty);
1997120067 const enum_ty = switch (operand_ty.zigTypeTag(mod)) {
1997220068 .EnumLiteral => {
19973 const val = try sema.resolveConstValue(block, .unneeded, operand, "");
20069 const val = try sema.resolveConstValue(block, .unneeded, operand, undefined);
1997420070 const tag_name = ip.indexToKey(val.toIntern()).enum_literal;
1997520071 return sema.addStrLit(block, ip.stringToSlice(tag_name));
1997620072 },
......@@ -20043,7 +20139,9 @@ fn zirReify(
2004320139 const uncasted_operand = try sema.resolveInst(extra.operand);
2004420140 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node };
2004520141 const type_info = try sema.coerce(block, type_info_ty, uncasted_operand, operand_src);
20046 const val = try sema.resolveConstValue(block, operand_src, type_info, "operand to @Type must be comptime-known");
20142 const val = try sema.resolveConstValue(block, operand_src, type_info, .{
20143 .needed_comptime_reason = "operand to @Type must be comptime-known",
20144 });
2004720145 const union_val = ip.indexToKey(val.toIntern()).un;
2004820146 const target = mod.getTarget();
2004920147 if (try union_val.val.toValue().anyUndef(mod)) return sema.failWithUseOfUndef(block, src);
......@@ -20935,7 +21033,9 @@ fn reifyStruct(
2093521033 const field_ty = type_val.toType();
2093621034 const default_val = if (default_value_val.optionalValue(mod)) |opt_val|
2093721035 (try sema.pointerDeref(block, src, opt_val, try mod.singleConstPtrType(field_ty)) orelse
20938 return sema.failWithNeededComptime(block, src, "struct field default value must be comptime-known")).toIntern()
21036 return sema.failWithNeededComptime(block, src, .{
21037 .needed_comptime_reason = "struct field default value must be comptime-known",
21038 })).toIntern()
2093921039 else
2094021040 .none;
2094121041 if (is_comptime_val.toBool() and default_val == .none) {
......@@ -21167,7 +21267,9 @@ fn zirIntFromFloat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
2116721267 const result_val = try sema.intFromFloat(block, operand_src, operand_val, operand_ty, dest_ty);
2116821268 return Air.internedToRef(result_val.toIntern());
2116921269 } else if (dest_scalar_ty.zigTypeTag(mod) == .ComptimeInt) {
21170 return sema.failWithNeededComptime(block, operand_src, "value being casted to 'comptime_int' must be comptime-known");
21270 return sema.failWithNeededComptime(block, operand_src, .{
21271 .needed_comptime_reason = "value being casted to 'comptime_int' must be comptime-known",
21272 });
2117121273 }
2117221274
2117321275 try sema.requireRuntimeBlock(block, inst_data.src(), operand_src);
......@@ -21247,7 +21349,9 @@ fn zirFloatFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
2124721349 const result_val = try operand_val.floatFromIntAdvanced(sema.arena, operand_ty, dest_ty, mod, sema);
2124821350 return Air.internedToRef(result_val.toIntern());
2124921351 } else if (dest_scalar_ty.zigTypeTag(mod) == .ComptimeFloat) {
21250 return sema.failWithNeededComptime(block, operand_src, "value being casted to 'comptime_float' must be comptime-known");
21352 return sema.failWithNeededComptime(block, operand_src, .{
21353 .needed_comptime_reason = "value being casted to 'comptime_float' must be comptime-known",
21354 });
2125121355 }
2125221356
2125321357 try sema.requireRuntimeBlock(block, src, operand_src);
......@@ -22167,7 +22271,9 @@ fn bitOffsetOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!u6
2216722271 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
2216822272
2216922273 const ty = try sema.resolveType(block, lhs_src, extra.lhs);
22170 const field_name = try sema.resolveConstStringIntern(block, rhs_src, extra.rhs, "name of field must be comptime-known");
22274 const field_name = try sema.resolveConstStringIntern(block, rhs_src, extra.rhs, .{
22275 .needed_comptime_reason = "name of field must be comptime-known",
22276 });
2217122277
2217222278 const mod = sema.mod;
2217322279 try sema.resolveTypeLayout(ty);
......@@ -22660,16 +22766,22 @@ fn resolveExportOptions(
2266022766 const visibility_src = sema.maybeOptionsSrc(block, src, "visibility");
2266122767
2266222768 const name_operand = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "name"), name_src);
22663 const name_val = try sema.resolveConstValue(block, name_src, name_operand, "name of exported value must be comptime-known");
22769 const name_val = try sema.resolveConstValue(block, name_src, name_operand, .{
22770 .needed_comptime_reason = "name of exported value must be comptime-known",
22771 });
2266422772 const name_ty = Type.slice_const_u8;
2266522773 const name = try name_val.toAllocatedBytes(name_ty, sema.arena, mod);
2266622774
2266722775 const linkage_operand = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "linkage"), linkage_src);
22668 const linkage_val = try sema.resolveConstValue(block, linkage_src, linkage_operand, "linkage of exported value must be comptime-known");
22776 const linkage_val = try sema.resolveConstValue(block, linkage_src, linkage_operand, .{
22777 .needed_comptime_reason = "linkage of exported value must be comptime-known",
22778 });
2266922779 const linkage = mod.toEnum(std.builtin.GlobalLinkage, linkage_val);
2267022780
2267122781 const section_operand = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "section"), section_src);
22672 const section_opt_val = try sema.resolveConstValue(block, section_src, section_operand, "linksection of exported value must be comptime-known");
22782 const section_opt_val = try sema.resolveConstValue(block, section_src, section_operand, .{
22783 .needed_comptime_reason = "linksection of exported value must be comptime-known",
22784 });
2267322785 const section_ty = Type.slice_const_u8;
2267422786 const section = if (section_opt_val.optionalValue(mod)) |section_val|
2267522787 try section_val.toAllocatedBytes(section_ty, sema.arena, mod)
......@@ -22677,7 +22789,9 @@ fn resolveExportOptions(
2267722789 null;
2267822790
2267922791 const visibility_operand = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "visibility"), visibility_src);
22680 const visibility_val = try sema.resolveConstValue(block, visibility_src, visibility_operand, "visibility of exported value must be comptime-known");
22792 const visibility_val = try sema.resolveConstValue(block, visibility_src, visibility_operand, .{
22793 .needed_comptime_reason = "visibility of exported value must be comptime-known",
22794 });
2268122795 const visibility = mod.toEnum(std.builtin.SymbolVisibility, visibility_val);
2268222796
2268322797 if (name.len < 1) {
......@@ -22704,7 +22818,7 @@ fn resolveBuiltinEnum(
2270422818 src: LazySrcLoc,
2270522819 zir_ref: Zir.Inst.Ref,
2270622820 comptime name: []const u8,
22707 reason: []const u8,
22821 reason: NeededComptimeReason,
2270822822) CompileError!@field(std.builtin, name) {
2270922823 const mod = sema.mod;
2271022824 const ty = try sema.getBuiltinType(name);
......@@ -22719,7 +22833,7 @@ fn resolveAtomicOrder(
2271922833 block: *Block,
2272022834 src: LazySrcLoc,
2272122835 zir_ref: Zir.Inst.Ref,
22722 reason: []const u8,
22836 reason: NeededComptimeReason,
2272322837) CompileError!std.builtin.AtomicOrder {
2272422838 return sema.resolveBuiltinEnum(block, src, zir_ref, "AtomicOrder", reason);
2272522839}
......@@ -22730,7 +22844,9 @@ fn resolveAtomicRmwOp(
2273022844 src: LazySrcLoc,
2273122845 zir_ref: Zir.Inst.Ref,
2273222846) CompileError!std.builtin.AtomicRmwOp {
22733 return sema.resolveBuiltinEnum(block, src, zir_ref, "AtomicRmwOp", "@atomicRmW operation must be comptime-known");
22847 return sema.resolveBuiltinEnum(block, src, zir_ref, "AtomicRmwOp", .{
22848 .needed_comptime_reason = "@atomicRmW operation must be comptime-known",
22849 });
2273422850}
2273522851
2273622852fn zirCmpxchg(
......@@ -22767,8 +22883,12 @@ fn zirCmpxchg(
2276722883 const uncasted_ptr = try sema.resolveInst(extra.ptr);
2276822884 const ptr = try sema.checkAtomicPtrOperand(block, elem_ty, elem_ty_src, uncasted_ptr, ptr_src, false);
2276922885 const new_value = try sema.coerce(block, elem_ty, try sema.resolveInst(extra.new_value), new_value_src);
22770 const success_order = try sema.resolveAtomicOrder(block, success_order_src, extra.success_order, "atomic order of cmpxchg success must be comptime-known");
22771 const failure_order = try sema.resolveAtomicOrder(block, failure_order_src, extra.failure_order, "atomic order of cmpxchg failure must be comptime-known");
22886 const success_order = try sema.resolveAtomicOrder(block, success_order_src, extra.success_order, .{
22887 .needed_comptime_reason = "atomic order of cmpxchg success must be comptime-known",
22888 });
22889 const failure_order = try sema.resolveAtomicOrder(block, failure_order_src, extra.failure_order, .{
22890 .needed_comptime_reason = "atomic order of cmpxchg failure must be comptime-known",
22891 });
2277222892
2277322893 if (@intFromEnum(success_order) < @intFromEnum(std.builtin.AtomicOrder.Monotonic)) {
2277422894 return sema.fail(block, success_order_src, "success atomic ordering must be Monotonic or stricter", .{});
......@@ -22860,7 +22980,9 @@ fn zirReduce(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
2286022980 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
2286122981 const op_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
2286222982 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };
22863 const operation = try sema.resolveBuiltinEnum(block, op_src, extra.lhs, "ReduceOp", "@reduce operation must be comptime-known");
22983 const operation = try sema.resolveBuiltinEnum(block, op_src, extra.lhs, "ReduceOp", .{
22984 .needed_comptime_reason = "@reduce operation must be comptime-known",
22985 });
2286422986 const operand = try sema.resolveInst(extra.rhs);
2286522987 const operand_ty = sema.typeOf(operand);
2286622988 const mod = sema.mod;
......@@ -22947,7 +23069,9 @@ fn zirShuffle(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
2294723069 .child = .i32_type,
2294823070 });
2294923071 mask = try sema.coerce(block, mask_ty, mask, mask_src);
22950 const mask_val = try sema.resolveConstMaybeUndefVal(block, mask_src, mask, "shuffle mask must be comptime-known");
23072 const mask_val = try sema.resolveConstMaybeUndefVal(block, mask_src, mask, .{
23073 .needed_comptime_reason = "shuffle mask must be comptime-known",
23074 });
2295123075 return sema.analyzeShuffle(block, inst_data.src_node, elem_ty, a, b, mask_val, @intCast(mask_len));
2295223076}
2295323077
......@@ -23211,7 +23335,9 @@ fn zirAtomicLoad(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
2321123335 const elem_ty = try sema.resolveType(block, elem_ty_src, extra.elem_type);
2321223336 const uncasted_ptr = try sema.resolveInst(extra.ptr);
2321323337 const ptr = try sema.checkAtomicPtrOperand(block, elem_ty, elem_ty_src, uncasted_ptr, ptr_src, true);
23214 const order = try sema.resolveAtomicOrder(block, order_src, extra.ordering, "atomic order of @atomicLoad must be comptime-known");
23338 const order = try sema.resolveAtomicOrder(block, order_src, extra.ordering, .{
23339 .needed_comptime_reason = "atomic order of @atomicLoad must be comptime-known",
23340 });
2321523341
2321623342 switch (order) {
2321723343 .Release, .AcqRel => {
......@@ -23276,7 +23402,9 @@ fn zirAtomicRmw(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
2327623402 },
2327723403 else => {},
2327823404 }
23279 const order = try sema.resolveAtomicOrder(block, order_src, extra.ordering, "atomic order of @atomicRmW must be comptime-known");
23405 const order = try sema.resolveAtomicOrder(block, order_src, extra.ordering, .{
23406 .needed_comptime_reason = "atomic order of @atomicRmW must be comptime-known",
23407 });
2328023408
2328123409 if (order == .Unordered) {
2328223410 return sema.fail(block, order_src, "@atomicRmw atomic ordering must not be Unordered", .{});
......@@ -23343,7 +23471,9 @@ fn zirAtomicStore(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
2334323471 const elem_ty = sema.typeOf(operand);
2334423472 const uncasted_ptr = try sema.resolveInst(extra.ptr);
2334523473 const ptr = try sema.checkAtomicPtrOperand(block, elem_ty, elem_ty_src, uncasted_ptr, ptr_src, false);
23346 const order = try sema.resolveAtomicOrder(block, order_src, extra.ordering, "atomic order of @atomicStore must be comptime-known");
23474 const order = try sema.resolveAtomicOrder(block, order_src, extra.ordering, .{
23475 .needed_comptime_reason = "atomic order of @atomicStore must be comptime-known",
23476 });
2334723477
2334823478 const air_tag: Air.Inst.Tag = switch (order) {
2334923479 .Acquire, .AcqRel => {
......@@ -23444,7 +23574,9 @@ fn zirBuiltinCall(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
2344423574 const modifier_ty = try sema.getBuiltinType("CallModifier");
2344523575 const air_ref = try sema.resolveInst(extra.modifier);
2344623576 const modifier_ref = try sema.coerce(block, modifier_ty, air_ref, modifier_src);
23447 const modifier_val = try sema.resolveConstValue(block, modifier_src, modifier_ref, "call modifier must be comptime-known");
23577 const modifier_val = try sema.resolveConstValue(block, modifier_src, modifier_ref, .{
23578 .needed_comptime_reason = "call modifier must be comptime-known",
23579 });
2344823580 var modifier = mod.toEnum(std.builtin.CallModifier, modifier_val);
2344923581 switch (modifier) {
2345023582 // These can be upgraded to comptime or nosuspend calls.
......@@ -23529,7 +23661,9 @@ fn zirFieldParentPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr
2352923661 const ptr_src: LazySrcLoc = .{ .node_offset_builtin_call_arg2 = inst_data.src_node };
2353023662
2353123663 const parent_ty = try sema.resolveType(block, ty_src, extra.parent_type);
23532 const field_name = try sema.resolveConstStringIntern(block, name_src, extra.field_name, "field name must be comptime-known");
23664 const field_name = try sema.resolveConstStringIntern(block, name_src, extra.field_name, .{
23665 .needed_comptime_reason = "field name must be comptime-known",
23666 });
2353323667 const field_ptr = try sema.resolveInst(extra.field_ptr);
2353423668 const field_ptr_ty = sema.typeOf(field_ptr);
2353523669 const mod = sema.mod;
......@@ -24320,8 +24454,11 @@ fn zirVarExtended(
2432024454 else
2432124455 uncasted_init;
2432224456
24323 break :blk ((try sema.resolveMaybeUndefVal(init)) orelse
24324 return sema.failWithNeededComptime(block, init_src, "container level variable initializers must be comptime-known")).toIntern();
24457 break :blk ((try sema.resolveMaybeUndefVal(init)) orelse {
24458 return sema.failWithNeededComptime(block, init_src, .{
24459 .needed_comptime_reason = "container level variable initializers must be comptime-known",
24460 });
24461 }).toIntern();
2432524462 } else .none;
2432624463
2432724464 try sema.validateVarType(block, ty_src, var_ty, small.is_extern);
......@@ -24376,7 +24513,9 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
2437624513 const body = sema.code.extra[extra_index..][0..body_len];
2437724514 extra_index += body.len;
2437824515
24379 const val = try sema.resolveGenericBody(block, align_src, body, inst, Type.u29, "alignment must be comptime-known");
24516 const val = try sema.resolveGenericBody(block, align_src, body, inst, Type.u29, .{
24517 .needed_comptime_reason = "alignment must be comptime-known",
24518 });
2438024519 if (val.isGenericPoison()) {
2438124520 break :blk null;
2438224521 }
......@@ -24390,7 +24529,9 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
2439024529 } else if (extra.data.bits.has_align_ref) blk: {
2439124530 const align_ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_index]);
2439224531 extra_index += 1;
24393 const align_tv = sema.resolveInstConst(block, align_src, align_ref, "alignment must be comptime-known") catch |err| switch (err) {
24532 const align_tv = sema.resolveInstConst(block, align_src, align_ref, .{
24533 .needed_comptime_reason = "alignment must be comptime-known",
24534 }) catch |err| switch (err) {
2439424535 error.GenericPoison => {
2439524536 break :blk null;
2439624537 },
......@@ -24412,7 +24553,9 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
2441224553 extra_index += body.len;
2441324554
2441424555 const addrspace_ty = try sema.getBuiltinType("AddressSpace");
24415 const val = try sema.resolveGenericBody(block, addrspace_src, body, inst, addrspace_ty, "addrespace must be comptime-known");
24556 const val = try sema.resolveGenericBody(block, addrspace_src, body, inst, addrspace_ty, .{
24557 .needed_comptime_reason = "addrspace must be comptime-known",
24558 });
2441624559 if (val.isGenericPoison()) {
2441724560 break :blk null;
2441824561 }
......@@ -24420,7 +24563,9 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
2442024563 } else if (extra.data.bits.has_addrspace_ref) blk: {
2442124564 const addrspace_ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_index]);
2442224565 extra_index += 1;
24423 const addrspace_tv = sema.resolveInstConst(block, addrspace_src, addrspace_ref, "addrespace must be comptime-known") catch |err| switch (err) {
24566 const addrspace_tv = sema.resolveInstConst(block, addrspace_src, addrspace_ref, .{
24567 .needed_comptime_reason = "addrspace must be comptime-known",
24568 }) catch |err| switch (err) {
2442424569 error.GenericPoison => {
2442524570 break :blk null;
2442624571 },
......@@ -24436,7 +24581,9 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
2443624581 extra_index += body.len;
2443724582
2443824583 const ty = Type.slice_const_u8;
24439 const val = try sema.resolveGenericBody(block, section_src, body, inst, ty, "linksection must be comptime-known");
24584 const val = try sema.resolveGenericBody(block, section_src, body, inst, ty, .{
24585 .needed_comptime_reason = "linksection must be comptime-known",
24586 });
2444024587 if (val.isGenericPoison()) {
2444124588 break :blk .generic;
2444224589 }
......@@ -24444,7 +24591,9 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
2444424591 } else if (extra.data.bits.has_section_ref) blk: {
2444524592 const section_ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_index]);
2444624593 extra_index += 1;
24447 const section_name = sema.resolveConstStringIntern(block, section_src, section_ref, "linksection must be comptime-known") catch |err| switch (err) {
24594 const section_name = sema.resolveConstStringIntern(block, section_src, section_ref, .{
24595 .needed_comptime_reason = "linksection must be comptime-known",
24596 }) catch |err| switch (err) {
2444824597 error.GenericPoison => {
2444924598 break :blk .generic;
2445024599 },
......@@ -24460,7 +24609,9 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
2446024609 extra_index += body.len;
2446124610
2446224611 const cc_ty = try sema.getBuiltinType("CallingConvention");
24463 const val = try sema.resolveGenericBody(block, cc_src, body, inst, cc_ty, "calling convention must be comptime-known");
24612 const val = try sema.resolveGenericBody(block, cc_src, body, inst, cc_ty, .{
24613 .needed_comptime_reason = "calling convention must be comptime-known",
24614 });
2446424615 if (val.isGenericPoison()) {
2446524616 break :blk null;
2446624617 }
......@@ -24468,7 +24619,9 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
2446824619 } else if (extra.data.bits.has_cc_ref) blk: {
2446924620 const cc_ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_index]);
2447024621 extra_index += 1;
24471 const cc_tv = sema.resolveInstConst(block, cc_src, cc_ref, "calling convention must be comptime-known") catch |err| switch (err) {
24622 const cc_tv = sema.resolveInstConst(block, cc_src, cc_ref, .{
24623 .needed_comptime_reason = "calling convention must be comptime-known",
24624 }) catch |err| switch (err) {
2447224625 error.GenericPoison => {
2447324626 break :blk null;
2447424627 },
......@@ -24486,13 +24639,17 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
2448624639 const body = sema.code.extra[extra_index..][0..body_len];
2448724640 extra_index += body.len;
2448824641
24489 const val = try sema.resolveGenericBody(block, ret_src, body, inst, Type.type, "return type must be comptime-known");
24642 const val = try sema.resolveGenericBody(block, ret_src, body, inst, Type.type, .{
24643 .needed_comptime_reason = "return type must be comptime-known",
24644 });
2449024645 const ty = val.toType();
2449124646 break :blk ty;
2449224647 } else if (extra.data.bits.has_ret_ty_ref) blk: {
2449324648 const ret_ty_ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_index]);
2449424649 extra_index += 1;
24495 const ret_ty_tv = sema.resolveInstConst(block, ret_src, ret_ty_ref, "return type must be comptime-known") catch |err| switch (err) {
24650 const ret_ty_tv = sema.resolveInstConst(block, ret_src, ret_ty_ref, .{
24651 .needed_comptime_reason = "return type must be comptime-known",
24652 }) catch |err| switch (err) {
2449624653 error.GenericPoison => {
2449724654 break :blk Type.generic_poison;
2449824655 },
......@@ -24547,7 +24704,9 @@ fn zirCUndef(
2454724704 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;
2454824705 const src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node };
2454924706
24550 const name = try sema.resolveConstString(block, src, extra.operand, "name of macro being undefined must be comptime-known");
24707 const name = try sema.resolveConstString(block, src, extra.operand, .{
24708 .needed_comptime_reason = "name of macro being undefined must be comptime-known",
24709 });
2455124710 try block.c_import_buf.?.writer().print("#undef {s}\n", .{name});
2455224711 return .void_value;
2455324712}
......@@ -24560,7 +24719,9 @@ fn zirCInclude(
2456024719 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;
2456124720 const src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node };
2456224721
24563 const name = try sema.resolveConstString(block, src, extra.operand, "path being included must be comptime-known");
24722 const name = try sema.resolveConstString(block, src, extra.operand, .{
24723 .needed_comptime_reason = "path being included must be comptime-known",
24724 });
2456424725 try block.c_import_buf.?.writer().print("#include <{s}>\n", .{name});
2456524726 return .void_value;
2456624727}
......@@ -24575,10 +24736,14 @@ fn zirCDefine(
2457524736 const name_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node };
2457624737 const val_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = extra.node };
2457724738
24578 const name = try sema.resolveConstString(block, name_src, extra.lhs, "name of macro being undefined must be comptime-known");
24739 const name = try sema.resolveConstString(block, name_src, extra.lhs, .{
24740 .needed_comptime_reason = "name of macro being undefined must be comptime-known",
24741 });
2457924742 const rhs = try sema.resolveInst(extra.rhs);
2458024743 if (sema.typeOf(rhs).zigTypeTag(mod) != .Void) {
24581 const value = try sema.resolveConstString(block, val_src, extra.rhs, "value of macro being undefined must be comptime-known");
24744 const value = try sema.resolveConstString(block, val_src, extra.rhs, .{
24745 .needed_comptime_reason = "value of macro being undefined must be comptime-known",
24746 });
2458224747 try block.c_import_buf.?.writer().print("#define {s} {s}\n", .{ name, value });
2458324748 } else {
2458424749 try block.c_import_buf.?.writer().print("#define {s}\n", .{name});
......@@ -24599,7 +24764,9 @@ fn zirWasmMemorySize(
2459924764 return sema.fail(block, builtin_src, "builtin @wasmMemorySize is available when targeting WebAssembly; targeted CPU architecture is {s}", .{@tagName(target.cpu.arch)});
2460024765 }
2460124766
24602 const index: u32 = @intCast(try sema.resolveInt(block, index_src, extra.operand, Type.u32, "wasm memory size index must be comptime-known"));
24767 const index: u32 = @intCast(try sema.resolveInt(block, index_src, extra.operand, Type.u32, .{
24768 .needed_comptime_reason = "wasm memory size index must be comptime-known",
24769 }));
2460324770 try sema.requireRuntimeBlock(block, builtin_src, null);
2460424771 return block.addInst(.{
2460524772 .tag = .wasm_memory_size,
......@@ -24624,7 +24791,9 @@ fn zirWasmMemoryGrow(
2462424791 return sema.fail(block, builtin_src, "builtin @wasmMemoryGrow is available when targeting WebAssembly; targeted CPU architecture is {s}", .{@tagName(target.cpu.arch)});
2462524792 }
2462624793
24627 const index: u32 = @intCast(try sema.resolveInt(block, index_src, extra.lhs, Type.u32, "wasm memory size index must be comptime-known"));
24794 const index: u32 = @intCast(try sema.resolveInt(block, index_src, extra.lhs, Type.u32, .{
24795 .needed_comptime_reason = "wasm memory size index must be comptime-known",
24796 }));
2462824797 const delta = try sema.coerce(block, Type.u32, try sema.resolveInst(extra.rhs), delta_src);
2462924798
2463024799 try sema.requireRuntimeBlock(block, builtin_src, null);
......@@ -24654,13 +24823,19 @@ fn resolvePrefetchOptions(
2465424823 const cache_src = sema.maybeOptionsSrc(block, src, "cache");
2465524824
2465624825 const rw = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "rw"), rw_src);
24657 const rw_val = try sema.resolveConstValue(block, rw_src, rw, "prefetch read/write must be comptime-known");
24826 const rw_val = try sema.resolveConstValue(block, rw_src, rw, .{
24827 .needed_comptime_reason = "prefetch read/write must be comptime-known",
24828 });
2465824829
2465924830 const locality = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "locality"), locality_src);
24660 const locality_val = try sema.resolveConstValue(block, locality_src, locality, "prefetch locality must be comptime-known");
24831 const locality_val = try sema.resolveConstValue(block, locality_src, locality, .{
24832 .needed_comptime_reason = "prefetch locality must be comptime-known",
24833 });
2466124834
2466224835 const cache = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "cache"), cache_src);
24663 const cache_val = try sema.resolveConstValue(block, cache_src, cache, "prefetch cache must be comptime-known");
24836 const cache_val = try sema.resolveConstValue(block, cache_src, cache, .{
24837 .needed_comptime_reason = "prefetch cache must be comptime-known",
24838 });
2466424839
2466524840 return std.builtin.PrefetchOptions{
2466624841 .rw = mod.toEnum(std.builtin.PrefetchOptions.Rw, rw_val),
......@@ -24727,18 +24902,26 @@ fn resolveExternOptions(
2472724902 const thread_local_src = sema.maybeOptionsSrc(block, src, "thread_local");
2472824903
2472924904 const name_ref = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "name"), name_src);
24730 const name_val = try sema.resolveConstValue(block, name_src, name_ref, "name of the extern symbol must be comptime-known");
24905 const name_val = try sema.resolveConstValue(block, name_src, name_ref, .{
24906 .needed_comptime_reason = "name of the extern symbol must be comptime-known",
24907 });
2473124908 const name = try name_val.toAllocatedBytes(Type.slice_const_u8, sema.arena, mod);
2473224909
2473324910 const library_name_inst = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "library_name"), library_src);
24734 const library_name_val = try sema.resolveConstValue(block, library_src, library_name_inst, "library in which extern symbol is must be comptime-known");
24911 const library_name_val = try sema.resolveConstValue(block, library_src, library_name_inst, .{
24912 .needed_comptime_reason = "library in which extern symbol is must be comptime-known",
24913 });
2473524914
2473624915 const linkage_ref = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "linkage"), linkage_src);
24737 const linkage_val = try sema.resolveConstValue(block, linkage_src, linkage_ref, "linkage of the extern symbol must be comptime-known");
24916 const linkage_val = try sema.resolveConstValue(block, linkage_src, linkage_ref, .{
24917 .needed_comptime_reason = "linkage of the extern symbol must be comptime-known",
24918 });
2473824919 const linkage = mod.toEnum(std.builtin.GlobalLinkage, linkage_val);
2473924920
2474024921 const is_thread_local = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "is_thread_local"), thread_local_src);
24741 const is_thread_local_val = try sema.resolveConstValue(block, thread_local_src, is_thread_local, "threadlocality of the extern symbol must be comptime-known");
24922 const is_thread_local_val = try sema.resolveConstValue(block, thread_local_src, is_thread_local, .{
24923 .needed_comptime_reason = "threadlocality of the extern symbol must be comptime-known",
24924 });
2474224925
2474324926 const library_name = if (library_name_val.optionalValue(mod)) |payload| blk: {
2474424927 const library_name = try payload.toAllocatedBytes(Type.slice_const_u8, sema.arena, mod);
......@@ -24863,7 +25046,9 @@ fn zirWorkItem(
2486325046 },
2486425047 }
2486525048
24866 const dimension: u32 = @intCast(try sema.resolveInt(block, dimension_src, extra.operand, Type.u32, "dimension must be comptime-known"));
25049 const dimension: u32 = @intCast(try sema.resolveInt(block, dimension_src, extra.operand, Type.u32, .{
25050 .needed_comptime_reason = "dimension must be comptime-known",
25051 }));
2486725052 try sema.requireRuntimeBlock(block, builtin_src, null);
2486825053
2486925054 return block.addInst(.{
......@@ -25945,7 +26130,7 @@ fn fieldPtr(
2594526130 }
2594626131 },
2594726132 .Type => {
25948 _ = try sema.resolveConstValue(block, .unneeded, object_ptr, "");
26133 _ = try sema.resolveConstValue(block, .unneeded, object_ptr, undefined);
2594926134 const result = try sema.analyzeLoad(block, src, object_ptr, object_ptr_src);
2595026135 const inner = if (is_pointer_to)
2595126136 try sema.analyzeLoad(block, src, result, object_ptr_src)
......@@ -26803,7 +26988,9 @@ fn elemPtr(
2680326988 .Array, .Vector => return sema.elemPtrArray(block, src, indexable_ptr_src, indexable_ptr, elem_index_src, elem_index, init, oob_safety),
2680426989 .Struct => {
2680526990 // Tuple field access.
26806 const index_val = try sema.resolveConstValue(block, elem_index_src, elem_index, "tuple field access index must be comptime-known");
26991 const index_val = try sema.resolveConstValue(block, elem_index_src, elem_index, .{
26992 .needed_comptime_reason = "tuple field access index must be comptime-known",
26993 });
2680726994 const index: u32 = @intCast(index_val.toUnsignedInt(mod));
2680826995 return sema.tupleFieldPtr(block, src, indexable_ptr, elem_index_src, index, init);
2680926996 },
......@@ -26857,7 +27044,9 @@ fn elemPtrOneLayerOnly(
2685727044 },
2685827045 .Struct => {
2685927046 assert(child_ty.isTuple(mod));
26860 const index_val = try sema.resolveConstValue(block, elem_index_src, elem_index, "tuple field access index must be comptime-known");
27047 const index_val = try sema.resolveConstValue(block, elem_index_src, elem_index, .{
27048 .needed_comptime_reason = "tuple field access index must be comptime-known",
27049 });
2686127050 const index: u32 = @intCast(index_val.toUnsignedInt(mod));
2686227051 return sema.tupleFieldPtr(block, indexable_src, indexable, elem_index_src, index, false);
2686327052 },
......@@ -26932,7 +27121,9 @@ fn elemVal(
2693227121 },
2693327122 .Struct => {
2693427123 // Tuple field access.
26935 const index_val = try sema.resolveConstValue(block, elem_index_src, elem_index, "tuple field access index must be comptime-known");
27124 const index_val = try sema.resolveConstValue(block, elem_index_src, elem_index, .{
27125 .needed_comptime_reason = "tuple field access index must be comptime-known",
27126 });
2693627127 const index: u32 = @intCast(index_val.toUnsignedInt(mod));
2693727128 return sema.tupleField(block, indexable_src, indexable, elem_index_src, index);
2693827129 },
......@@ -27446,7 +27637,7 @@ fn coerceExtra(
2744627637
2744727638 // Function body to function pointer.
2744827639 if (inst_ty.zigTypeTag(mod) == .Fn) {
27449 const fn_val = try sema.resolveConstValue(block, .unneeded, inst, "");
27640 const fn_val = try sema.resolveConstValue(block, .unneeded, inst, undefined);
2745027641 const fn_decl = fn_val.pointerDecl(mod).?;
2745127642 const inst_as_ptr = try sema.analyzeDeclRef(fn_decl);
2745227643 return sema.coerce(block, dest_ty, inst_as_ptr, inst_src);
......@@ -27735,7 +27926,9 @@ fn coerceExtra(
2773527926 const val = (try sema.resolveMaybeUndefVal(inst)) orelse {
2773627927 if (dest_ty.zigTypeTag(mod) == .ComptimeInt) {
2773727928 if (!opts.report_err) return error.NotCoercible;
27738 return sema.failWithNeededComptime(block, inst_src, "value being casted to 'comptime_int' must be comptime-known");
27929 return sema.failWithNeededComptime(block, inst_src, .{
27930 .needed_comptime_reason = "value being casted to 'comptime_int' must be comptime-known",
27931 });
2773927932 }
2774027933 break :float;
2774127934 };
......@@ -27766,7 +27959,9 @@ fn coerceExtra(
2776627959 if (dest_ty.zigTypeTag(mod) == .ComptimeInt) {
2776727960 if (!opts.report_err) return error.NotCoercible;
2776827961 if (opts.no_cast_to_comptime_int) return inst;
27769 return sema.failWithNeededComptime(block, inst_src, "value being casted to 'comptime_int' must be comptime-known");
27962 return sema.failWithNeededComptime(block, inst_src, .{
27963 .needed_comptime_reason = "value being casted to 'comptime_int' must be comptime-known",
27964 });
2777027965 }
2777127966
2777227967 // integer widening
......@@ -27787,7 +27982,7 @@ fn coerceExtra(
2778727982 },
2778827983 .Float, .ComptimeFloat => switch (inst_ty.zigTypeTag(mod)) {
2778927984 .ComptimeFloat => {
27790 const val = try sema.resolveConstValue(block, .unneeded, inst, "");
27985 const val = try sema.resolveConstValue(block, .unneeded, inst, undefined);
2779127986 const result_val = try val.floatCast(dest_ty, mod);
2779227987 return Air.internedToRef(result_val.toIntern());
2779327988 },
......@@ -27808,7 +28003,9 @@ fn coerceExtra(
2780828003 return Air.internedToRef(result_val.toIntern());
2780928004 } else if (dest_ty.zigTypeTag(mod) == .ComptimeFloat) {
2781028005 if (!opts.report_err) return error.NotCoercible;
27811 return sema.failWithNeededComptime(block, inst_src, "value being casted to 'comptime_float' must be comptime-known");
28006 return sema.failWithNeededComptime(block, inst_src, .{
28007 .needed_comptime_reason = "value being casted to 'comptime_float' must be comptime-known",
28008 });
2781228009 }
2781328010
2781428011 // float widening
......@@ -27826,7 +28023,9 @@ fn coerceExtra(
2782628023 const val = (try sema.resolveMaybeUndefVal(inst)) orelse {
2782728024 if (dest_ty.zigTypeTag(mod) == .ComptimeFloat) {
2782828025 if (!opts.report_err) return error.NotCoercible;
27829 return sema.failWithNeededComptime(block, inst_src, "value being casted to 'comptime_float' must be comptime-known");
28026 return sema.failWithNeededComptime(block, inst_src, .{
28027 .needed_comptime_reason = "value being casted to 'comptime_float' must be comptime-known",
28028 });
2783028029 }
2783128030 break :int;
2783228031 };
......@@ -27851,7 +28050,7 @@ fn coerceExtra(
2785128050 .Enum => switch (inst_ty.zigTypeTag(mod)) {
2785228051 .EnumLiteral => {
2785328052 // enum literal to enum
27854 const val = try sema.resolveConstValue(block, .unneeded, inst, "");
28053 const val = try sema.resolveConstValue(block, .unneeded, inst, undefined);
2785528054 const string = mod.intern_pool.indexToKey(val.toIntern()).enum_literal;
2785628055 const field_index = dest_ty.enumFieldIndex(string, mod) orelse {
2785728056 const msg = msg: {
......@@ -28987,7 +29186,7 @@ fn coerceVarArgParam(
2898729186 .{},
2898829187 ),
2898929188 .Fn => blk: {
28990 const fn_val = try sema.resolveConstValue(block, .unneeded, inst, "");
29189 const fn_val = try sema.resolveConstValue(block, .unneeded, inst, undefined);
2899129190 const fn_decl = fn_val.pointerDecl(mod).?;
2899229191 break :blk try sema.analyzeDeclRef(fn_decl);
2899329192 },
......@@ -30720,7 +30919,9 @@ fn coerceTupleToStruct(
3072030919 field_refs[field_index] = coerced;
3072130920 if (field.is_comptime) {
3072230921 const init_val = (try sema.resolveMaybeUndefVal(coerced)) orelse {
30723 return sema.failWithNeededComptime(block, field_src, "value stored in comptime field must be comptime-known");
30922 return sema.failWithNeededComptime(block, field_src, .{
30923 .needed_comptime_reason = "value stored in comptime field must be comptime-known",
30924 });
3072430925 };
3072530926
3072630927 if (!init_val.eql(field.default_val.toValue(), field.ty, sema.mod)) {
......@@ -30851,7 +31052,9 @@ fn coerceTupleToTuple(
3085131052 field_refs[field_index] = coerced;
3085231053 if (default_val != .none) {
3085331054 const init_val = (try sema.resolveMaybeUndefVal(coerced)) orelse {
30854 return sema.failWithNeededComptime(block, field_src, "value stored in comptime field must be comptime-known");
31055 return sema.failWithNeededComptime(block, field_src, .{
31056 .needed_comptime_reason = "value stored in comptime field must be comptime-known",
31057 });
3085531058 };
3085631059
3085731060 if (!init_val.eql(default_val.toValue(), field_ty, sema.mod)) {
......@@ -31591,7 +31794,9 @@ fn analyzeSlice(
3159131794 const sentinel = s: {
3159231795 if (sentinel_opt != .none) {
3159331796 const casted = try sema.coerce(block, elem_ty, sentinel_opt, sentinel_src);
31594 break :s try sema.resolveConstValue(block, sentinel_src, casted, "slice sentinel must be comptime-known");
31797 break :s try sema.resolveConstValue(block, sentinel_src, casted, .{
31798 .needed_comptime_reason = "slice sentinel must be comptime-known",
31799 });
3159531800 }
3159631801 // If we are slicing to the end of something that is sentinel-terminated
3159731802 // then the resulting slice type is also sentinel-terminated.
......@@ -35092,7 +35297,9 @@ fn semaStructFields(mod: *Module, struct_obj: *Module.Struct) CompileError!void
3509235297 .index = field_i,
3509335298 .range = .value,
3509435299 }).lazy;
35095 return sema.failWithNeededComptime(&block_scope, init_src, "struct field default value must be comptime-known");
35300 return sema.failWithNeededComptime(&block_scope, init_src, .{
35301 .needed_comptime_reason = "struct field default value must be comptime-known",
35302 });
3509635303 };
3509735304 field.default_val = try default_val.intern(field.ty, mod);
3509835305 }
......@@ -35534,7 +35741,9 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Key.Un
3553435741
3553535742fn semaUnionFieldVal(sema: *Sema, block: *Block, src: LazySrcLoc, int_tag_ty: Type, tag_ref: Air.Inst.Ref) CompileError!Value {
3553635743 const coerced = try sema.coerce(block, int_tag_ty, tag_ref, src);
35537 return sema.resolveConstValue(block, src, coerced, "enum tag value must be comptime-known");
35744 return sema.resolveConstValue(block, src, coerced, .{
35745 .needed_comptime_reason = "enum tag value must be comptime-known",
35746 });
3553835747}
3553935748
3554035749fn generateUnionTagTypeNumbered(
......@@ -36158,7 +36367,9 @@ pub fn analyzeAddressSpace(
3615836367 ctx: AddressSpaceContext,
3615936368) !std.builtin.AddressSpace {
3616036369 const mod = sema.mod;
36161 const addrspace_tv = try sema.resolveInstConst(block, src, zir_ref, "address space must be comptime-known");
36370 const addrspace_tv = try sema.resolveInstConst(block, src, zir_ref, .{
36371 .needed_comptime_reason = "address space must be comptime-known",
36372 });
3616236373 const address_space = mod.toEnum(std.builtin.AddressSpace, addrspace_tv.val);
3616336374 const target = sema.mod.getTarget();
3616436375 const arch = target.cpu.arch;