authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2023-10-24 05:03:25+01:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2023-10-24 14:28:34+01:00
log67caf685056bcdbbe4e696cada927615b0dd6fe9
tree2f715cabde6864720c4943e006cab600c3416e5d
parent7882bdcb7e1b012ff388c4abe0b57aa048bb2ce3
signaturelock-open Commit is signed but in an unrecognized format.

Sema: rename value resolution functions

Having simplified these functions in a previous commit, I felt inclined to refactor their names, which were previously quite inconsistent. There are now 4 "core" functions: * `resolveValue` (previously `resolveMaybeUndefVal`) allows runtime-known and undef values. * `resolveConstValue` (previously `resolveConstMaybeUndefVal`) allows undef but not runtime-known values. * `resolveDefinedValue` (name unchanged) allows runtime-known values but not comptime-known undef. * `resolveConstDefinedValue` (previously `resolveConstValue`) does not allow runtime-known or undef values. You can see the inconsistencies in the old names here - sometimes we specified "maybe undef", and sometimes we went the other way by specifying "defined". With the new names, the most common function, `resolveValue`, has the shortest name and does the most general thing, and is the baseline that the other functions are adding logic to. Some other functions were also renamed: * `resolveMaybeUndefLazyVal` -> `resolveValueResolveLazy` * `resolveMaybeUndefValIntable` -> `resolveValueIntable` * `resolveMaybeUndefValAllowVariables` -> `resolveValueAllowVariables`

1 files changed, 258 insertions(+), 259 deletions(-)

src/Sema.zig+258-259
......@@ -1741,7 +1741,7 @@ fn analyzeBodyInner(
17411741 }
17421742 const is_non_err = try sema.analyzeIsNonErrComptimeOnly(block, operand_src, err_union);
17431743 assert(is_non_err != .none);
1744 const is_non_err_val = try sema.resolveConstValue(block, operand_src, is_non_err, .{
1744 const is_non_err_val = try sema.resolveConstDefinedValue(block, operand_src, is_non_err, .{
17451745 .needed_comptime_reason = "try operand inside comptime block must be comptime-known",
17461746 .block_comptime_reason = block.comptime_reason,
17471747 });
......@@ -1767,7 +1767,7 @@ fn analyzeBodyInner(
17671767 const err_union = try sema.analyzeLoad(block, src, operand, operand_src);
17681768 const is_non_err = try sema.analyzeIsNonErrComptimeOnly(block, operand_src, err_union);
17691769 assert(is_non_err != .none);
1770 const is_non_err_val = try sema.resolveConstValue(block, operand_src, is_non_err, .{
1770 const is_non_err_val = try sema.resolveConstDefinedValue(block, operand_src, is_non_err, .{
17711771 .needed_comptime_reason = "try operand inside comptime block must be comptime-known",
17721772 .block_comptime_reason = block.comptime_reason,
17731773 });
......@@ -1866,7 +1866,7 @@ fn resolveConstBool(
18661866 const air_inst = try sema.resolveInst(zir_ref);
18671867 const wanted_type = Type.bool;
18681868 const coerced_inst = try sema.coerce(block, wanted_type, air_inst, src);
1869 const val = try sema.resolveConstValue(block, src, coerced_inst, reason);
1869 const val = try sema.resolveConstDefinedValue(block, src, coerced_inst, reason);
18701870 return val.toBool();
18711871}
18721872
......@@ -1880,7 +1880,7 @@ pub fn resolveConstString(
18801880 const air_inst = try sema.resolveInst(zir_ref);
18811881 const wanted_type = Type.slice_const_u8;
18821882 const coerced_inst = try sema.coerce(block, wanted_type, air_inst, src);
1883 const val = try sema.resolveConstValue(block, src, coerced_inst, reason);
1883 const val = try sema.resolveConstDefinedValue(block, src, coerced_inst, reason);
18841884 return val.toAllocatedBytes(wanted_type, sema.arena, sema.mod);
18851885}
18861886
......@@ -1894,7 +1894,7 @@ pub fn resolveConstStringIntern(
18941894 const air_inst = try sema.resolveInst(zir_ref);
18951895 const wanted_type = Type.slice_const_u8;
18961896 const coerced_inst = try sema.coerce(block, wanted_type, air_inst, src);
1897 const val = try sema.resolveConstValue(block, src, coerced_inst, reason);
1897 const val = try sema.resolveConstDefinedValue(block, src, coerced_inst, reason);
18981898 return val.toIpString(wanted_type, sema.mod);
18991899}
19001900
......@@ -2024,7 +2024,7 @@ fn analyzeAsType(
20242024) !Type {
20252025 const wanted_type = Type.type;
20262026 const coerced_inst = try sema.coerce(block, wanted_type, air_inst, src);
2027 const val = try sema.resolveConstValue(block, src, coerced_inst, .{
2027 const val = try sema.resolveConstDefinedValue(block, src, coerced_inst, .{
20282028 .needed_comptime_reason = "types must be comptime-known",
20292029 });
20302030 return val.toType();
......@@ -2071,44 +2071,30 @@ pub fn setupErrorReturnTrace(sema: *Sema, block: *Block, last_arg_index: usize)
20712071 try block.instructions.insertSlice(gpa, last_arg_index, err_trace_block.instructions.items);
20722072}
20732073
2074/// Return the Value corresponding to a given AIR ref, or `null` if it
2075/// refers to a runtime value.
2074/// Return the Value corresponding to a given AIR ref, or `null` if it refers to a runtime value.
20762075/// InternPool key `variable` is considered a runtime value.
20772076/// Generic poison causes `error.GenericPoison` to be returned.
2078fn resolveMaybeUndefVal(sema: *Sema, inst: Air.Inst.Ref) CompileError!?Value {
2079 const val = (try sema.resolveMaybeUndefValAllowVariables(inst)) orelse return null;
2077fn resolveValue(sema: *Sema, inst: Air.Inst.Ref) CompileError!?Value {
2078 const val = (try sema.resolveValueAllowVariables(inst)) orelse return null;
20802079 if (val.isGenericPoison()) return error.GenericPoison;
20812080 if (sema.mod.intern_pool.isVariable(val.toIntern())) return null;
20822081 return val;
20832082}
20842083
2085/// Like `resolveMaybeUndefVal`, but emits an error if the value is not comptime-known.
2086fn resolveConstMaybeUndefVal(
2084/// Like `resolveValue`, but emits an error if the value is not comptime-known.
2085fn resolveConstValue(
20872086 sema: *Sema,
20882087 block: *Block,
20892088 src: LazySrcLoc,
20902089 inst: Air.Inst.Ref,
20912090 reason: NeededComptimeReason,
20922091) CompileError!Value {
2093 return try sema.resolveMaybeUndefVal(inst) orelse {
2092 return try sema.resolveValue(inst) orelse {
20942093 return sema.failWithNeededComptime(block, src, reason);
20952094 };
20962095}
20972096
2098/// Like `resolveMaybeUndefVal`, but emits an error if the value is not comptime-known or is undefined.
2099fn resolveConstValue(
2100 sema: *Sema,
2101 block: *Block,
2102 src: LazySrcLoc,
2103 air_ref: Air.Inst.Ref,
2104 reason: NeededComptimeReason,
2105) CompileError!Value {
2106 const val = try sema.resolveConstMaybeUndefVal(block, src, air_ref, reason);
2107 if (val.isUndef(sema.mod)) return sema.failWithUseOfUndef(block, src);
2108 return val;
2109}
2110
2111/// Like `resolveMaybeUndefVal`, but emits an error if the value is comptime-known to be undefined.
2097/// Like `resolveValue`, but emits an error if the value is comptime-known to be undefined.
21122098fn resolveDefinedValue(
21132099 sema: *Sema,
21142100 block: *Block,
......@@ -2116,7 +2102,7 @@ fn resolveDefinedValue(
21162102 air_ref: Air.Inst.Ref,
21172103) CompileError!?Value {
21182104 const mod = sema.mod;
2119 const val = try sema.resolveMaybeUndefVal(air_ref) orelse return null;
2105 const val = try sema.resolveValue(air_ref) orelse return null;
21202106 if (val.isUndef(mod)) {
21212107 if (block.is_typeof) return null;
21222108 return sema.failWithUseOfUndef(block, src);
......@@ -2124,16 +2110,29 @@ fn resolveDefinedValue(
21242110 return val;
21252111}
21262112
2127/// Like `resolveMaybeUndefVal`, but recursively resolves lazy values.
2128fn resolveMaybeUndefLazyVal(sema: *Sema, inst: Air.Inst.Ref) CompileError!?Value {
2129 return try sema.resolveLazyValue((try sema.resolveMaybeUndefVal(inst)) orelse return null);
2113/// Like `resolveValue`, but emits an error if the value is not comptime-known or is undefined.
2114fn resolveConstDefinedValue(
2115 sema: *Sema,
2116 block: *Block,
2117 src: LazySrcLoc,
2118 air_ref: Air.Inst.Ref,
2119 reason: NeededComptimeReason,
2120) CompileError!Value {
2121 const val = try sema.resolveConstValue(block, src, air_ref, reason);
2122 if (val.isUndef(sema.mod)) return sema.failWithUseOfUndef(block, src);
2123 return val;
21302124}
21312125
2132/// Like `resolveMaybeUndefVal`, but any pointer value which does not correspond
2126/// Like `resolveValue`, but recursively resolves lazy values before returning.
2127fn resolveValueResolveLazy(sema: *Sema, inst: Air.Inst.Ref) CompileError!?Value {
2128 return try sema.resolveLazyValue((try sema.resolveValue(inst)) orelse return null);
2129}
2130
2131/// Like `resolveValue`, but any pointer value which does not correspond
21332132/// to a comptime-known integer (e.g. a decl pointer) returns `null`.
21342133/// Lazy values are recursively resolved.
2135fn resolveMaybeUndefValIntable(sema: *Sema, inst: Air.Inst.Ref) CompileError!?Value {
2136 const val = (try sema.resolveMaybeUndefVal(inst)) orelse return null;
2134fn resolveValueIntable(sema: *Sema, inst: Air.Inst.Ref) CompileError!?Value {
2135 const val = (try sema.resolveValue(inst)) orelse return null;
21372136 if (sema.mod.intern_pool.getBackingAddrTag(val.toIntern())) |addr| switch (addr) {
21382137 .decl, .anon_decl, .mut_decl, .comptime_field => return null,
21392138 .int => {},
......@@ -2143,7 +2142,7 @@ fn resolveMaybeUndefValIntable(sema: *Sema, inst: Air.Inst.Ref) CompileError!?Va
21432142}
21442143
21452144/// Returns all InternPool keys representing values, including `variable`, `undef`, and `generic_poison`.
2146fn resolveMaybeUndefValAllowVariables(sema: *Sema, inst: Air.Inst.Ref) CompileError!?Value {
2145fn resolveValueAllowVariables(sema: *Sema, inst: Air.Inst.Ref) CompileError!?Value {
21472146 assert(inst != .none);
21482147 // First section of indexes correspond to a set number of constant values.
21492148 if (@intFromEnum(inst) < InternPool.static_len) {
......@@ -2180,7 +2179,7 @@ pub fn resolveInstConst(
21802179 reason: NeededComptimeReason,
21812180) CompileError!TypedValue {
21822181 const air_ref = try sema.resolveInst(zir_ref);
2183 const val = try sema.resolveConstValue(block, src, air_ref, reason);
2182 const val = try sema.resolveConstDefinedValue(block, src, air_ref, reason);
21842183 return .{
21852184 .ty = sema.typeOf(air_ref),
21862185 .val = val,
......@@ -2197,7 +2196,7 @@ pub fn resolveInstValueAllowVariables(
21972196 reason: NeededComptimeReason,
21982197) CompileError!TypedValue {
21992198 const air_ref = try sema.resolveInst(zir_ref);
2200 const val = try sema.resolveMaybeUndefValAllowVariables(air_ref) orelse {
2199 const val = try sema.resolveValueAllowVariables(air_ref) orelse {
22012200 return sema.failWithNeededComptime(block, src, reason);
22022201 };
22032202 if (val.isGenericPoison()) return error.GenericPoison;
......@@ -2640,7 +2639,7 @@ fn analyzeAsInt(
26402639) !u64 {
26412640 const mod = sema.mod;
26422641 const coerced = try sema.coerce(block, dest_ty, air_ref, src);
2643 const val = try sema.resolveConstValue(block, src, coerced, reason);
2642 const val = try sema.resolveConstDefinedValue(block, src, coerced, reason);
26442643 return (try val.getUnsignedIntAdvanced(mod, sema)).?;
26452644}
26462645
......@@ -2811,7 +2810,7 @@ fn createAnonymousDeclTypeNamed(
28112810 // If not then this is a struct type being returned from a non-generic
28122811 // function and the name doesn't matter since it will later
28132812 // result in a compile error.
2814 const arg_val = sema.resolveConstMaybeUndefVal(block, .unneeded, arg, undefined) catch
2813 const arg_val = sema.resolveConstValue(block, .unneeded, arg, undefined) catch
28152814 return sema.createAnonymousDeclTypeNamed(block, src, typed_value, .anon, anon_prefix, null);
28162815
28172816 if (arg_i != 0) try writer.writeByte(',');
......@@ -3055,13 +3054,13 @@ fn zirEnumDecl(
30553054 const tag_val_ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_index]);
30563055 extra_index += 1;
30573056 const tag_inst = try sema.resolveInst(tag_val_ref);
3058 last_tag_val = sema.resolveConstValue(block, .unneeded, tag_inst, undefined) catch |err| switch (err) {
3057 last_tag_val = sema.resolveConstDefinedValue(block, .unneeded, tag_inst, undefined) catch |err| switch (err) {
30593058 error.NeededSourceLocation => {
30603059 const value_src = mod.fieldSrcLoc(new_decl_index, .{
30613060 .index = field_i,
30623061 .range = .value,
30633062 }).lazy;
3064 _ = try sema.resolveConstValue(block, value_src, tag_inst, .{
3063 _ = try sema.resolveConstDefinedValue(block, value_src, tag_inst, .{
30653064 .needed_comptime_reason = "enum tag value must be comptime-known",
30663065 });
30673066 unreachable;
......@@ -3608,7 +3607,7 @@ fn zirMakePtrConst(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
36083607 // If this is already a comptime-known allocation, we don't want to emit an error - the stores
36093608 // were already performed at comptime! Just make the pointer constant as normal.
36103609 implicit_ct: {
3611 const ptr_val = try sema.resolveMaybeUndefVal(alloc) orelse break :implicit_ct;
3610 const ptr_val = try sema.resolveValue(alloc) orelse break :implicit_ct;
36123611 if (!ptr_val.isComptimeMutablePtr(mod)) {
36133612 // It could still be a constant pointer to a decl.
36143613 switch (mod.intern_pool.indexToKey(ptr_val.toIntern()).ptr.addr) {
......@@ -3750,7 +3749,7 @@ fn resolveComptimeKnownAllocValue(sema: *Sema, block: *Block, alloc: Air.Inst.Re
37503749 Air.Bin,
37513750 tmp_air.instructions.items(.data)[air_ptr].ty_pl.payload,
37523751 ).data;
3753 const idx_val = (try sema.resolveMaybeUndefVal(data.rhs)).?;
3752 const idx_val = (try sema.resolveValue(data.rhs)).?;
37543753 break :blk .{
37553754 data.lhs,
37563755 .{ .elem = idx_val.toUnsignedInt(mod) },
......@@ -3809,7 +3808,7 @@ fn resolveComptimeKnownAllocValue(sema: *Sema, block: *Block, alloc: Air.Inst.Re
38093808 // store instruction, so we must set the union payload now.
38103809 const bin_op = sema.air_instructions.items(.data)[store_inst].bin_op;
38113810 const air_ptr_inst = Air.refToIndex(bin_op.lhs).?;
3812 const tag_val = (try sema.resolveMaybeUndefVal(bin_op.rhs)).?;
3811 const tag_val = (try sema.resolveValue(bin_op.rhs)).?;
38133812 const union_ty = sema.typeOf(bin_op.lhs).childType(mod);
38143813 const payload_ty = union_ty.unionFieldType(tag_val, mod).?;
38153814 if (try sema.typeHasOnePossibleValue(payload_ty)) |payload_val| {
......@@ -3821,7 +3820,7 @@ fn resolveComptimeKnownAllocValue(sema: *Sema, block: *Block, alloc: Air.Inst.Re
38213820 .store, .store_safe => {
38223821 const bin_op = sema.air_instructions.items(.data)[store_inst].bin_op;
38233822 const air_ptr_inst = Air.refToIndex(bin_op.lhs).?;
3824 const store_val = (try sema.resolveMaybeUndefVal(bin_op.rhs)).?;
3823 const store_val = (try sema.resolveValue(bin_op.rhs)).?;
38253824 const new_ptr = ptr_mapping.get(air_ptr_inst).?;
38263825 try sema.storePtrVal(block, .unneeded, new_ptr.toValue(), store_val, mod.intern_pool.typeOf(store_val.toIntern()).toType());
38273826 },
......@@ -3872,7 +3871,7 @@ fn makePtrConst(sema: *Sema, block: *Block, alloc: Air.Inst.Ref) CompileError!Ai
38723871 const const_ptr_ty = try sema.makePtrTyConst(alloc_ty);
38733872
38743873 // Detect if a comptime value simply needs to have its type changed.
3875 if (try sema.resolveMaybeUndefVal(alloc)) |val| {
3874 if (try sema.resolveValue(alloc)) |val| {
38763875 return Air.internedToRef((try sema.mod.getCoerced(val, const_ptr_ty)).toIntern());
38773876 }
38783877
......@@ -4596,7 +4595,7 @@ fn validateUnionInit(
45964595 ).?
45974596 else
45984597 block_index, first_block_index);
4599 init_val = try sema.resolveMaybeUndefVal(bin_op.rhs);
4598 init_val = try sema.resolveValue(bin_op.rhs);
46004599 break;
46014600 }
46024601
......@@ -4830,7 +4829,7 @@ fn validateStructInit(
48304829 ).?
48314830 else
48324831 block_index, first_block_index);
4833 if (try sema.resolveMaybeUndefVal(bin_op.rhs)) |val| {
4832 if (try sema.resolveValue(bin_op.rhs)) |val| {
48344833 field_values[i] = val.toIntern();
48354834 } else if (require_comptime) {
48364835 const field_ptr_data = sema.code.instructions.items(.data)[field_ptr].pl_node;
......@@ -5086,7 +5085,7 @@ fn zirValidatePtrArrayInit(
50865085 ).?
50875086 else
50885087 block_index, first_block_index);
5089 if (try sema.resolveMaybeUndefVal(bin_op.rhs)) |val| {
5088 if (try sema.resolveValue(bin_op.rhs)) |val| {
50905089 element_vals[i] = val.toIntern();
50915090 } else {
50925091 array_is_comptime = false;
......@@ -5168,7 +5167,7 @@ fn zirValidateDeref(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr
51685167 }
51695168
51705169 const elem_ty = operand_ty.elemType2(mod);
5171 if (try sema.resolveMaybeUndefVal(operand)) |val| {
5170 if (try sema.resolveValue(operand)) |val| {
51725171 if (val.isUndef(mod)) {
51735172 return sema.fail(block, src, "cannot dereference undefined value", .{});
51745173 }
......@@ -5375,7 +5374,7 @@ fn storeToInferredAllocComptime(
53755374 const operand_ty = sema.typeOf(operand);
53765375 // There will be only one store_to_inferred_ptr because we are running at comptime.
53775376 // The alloc will turn into a Decl.
5378 if (try sema.resolveMaybeUndefVal(operand)) |operand_val| {
5377 if (try sema.resolveValue(operand)) |operand_val| {
53795378 var anon_decl = try block.startAnonDecl(); // TODO: comptime value mutation without Decl
53805379 defer anon_decl.deinit();
53815380 iac.decl_index = try anon_decl.finish(operand_ty, operand_val, iac.alignment);
......@@ -5565,7 +5564,7 @@ fn zirCompileLog(
55655564
55665565 const arg = try sema.resolveInst(arg_ref);
55675566 const arg_ty = sema.typeOf(arg);
5568 if (try sema.resolveMaybeUndefLazyVal(arg)) |val| {
5567 if (try sema.resolveValueResolveLazy(arg)) |val| {
55695568 try writer.print("@as({}, {})", .{
55705569 arg_ty.fmt(mod), val.fmtValue(arg_ty, mod),
55715570 });
......@@ -6479,7 +6478,7 @@ fn lookupInNamespace(
64796478
64806479fn funcDeclSrc(sema: *Sema, func_inst: Air.Inst.Ref) !?*Decl {
64816480 const mod = sema.mod;
6482 const func_val = (try sema.resolveMaybeUndefVal(func_inst)) orelse return null;
6481 const func_val = (try sema.resolveValue(func_inst)) orelse return null;
64836482 if (func_val.isUndef(mod)) return null;
64846483 const owner_decl_index = switch (mod.intern_pool.indexToKey(func_val.toIntern())) {
64856484 .extern_func => |extern_func| extern_func.decl,
......@@ -7225,7 +7224,7 @@ fn analyzeCall(
72257224 }
72267225
72277226 const result: Air.Inst.Ref = if (is_inline_call) res: {
7228 const func_val = try sema.resolveConstValue(block, func_src, func, .{
7227 const func_val = try sema.resolveConstDefinedValue(block, func_src, func, .{
72297228 .needed_comptime_reason = "function being called at comptime must be comptime-known",
72307229 .block_comptime_reason = comptime_reason,
72317230 });
......@@ -7475,7 +7474,7 @@ fn analyzeCall(
74757474 }
74767475
74777476 if (should_memoize and is_comptime_call) {
7478 const result_val = try sema.resolveConstMaybeUndefVal(block, .unneeded, result, undefined);
7477 const result_val = try sema.resolveConstValue(block, .unneeded, result, undefined);
74797478 const result_interned = try result_val.intern2(sema.fn_ret_ty, mod);
74807479
74817480 // Transform ad-hoc inferred error set types into concrete error sets.
......@@ -7492,7 +7491,7 @@ fn analyzeCall(
74927491 break :res2 Air.internedToRef(result_transformed);
74937492 }
74947493
7495 if (try sema.resolveMaybeUndefVal(result)) |result_val| {
7494 if (try sema.resolveValue(result)) |result_val| {
74967495 const result_interned = try result_val.intern2(sema.fn_ret_ty, mod);
74977496 const result_transformed = try sema.resolveAdHocInferredErrorSet(block, call_src, result_interned);
74987497 break :res2 Air.internedToRef(result_transformed);
......@@ -7532,7 +7531,7 @@ fn analyzeCall(
75327531 ip.funcAnalysis(sema.owner_func_index).calls_or_awaits_errorable_fn = true;
75337532 }
75347533
7535 if (try sema.resolveMaybeUndefVal(func)) |func_val| {
7534 if (try sema.resolveValue(func)) |func_val| {
75367535 if (mod.intern_pool.isFuncBody(func_val.toIntern())) {
75377536 try mod.ensureFuncBodyAnalysisQueued(func_val.toIntern());
75387537 }
......@@ -7560,7 +7559,7 @@ fn analyzeCall(
75607559 if (block.wantSafety() and func_ty_info.return_type == .noreturn_type) skip_safety: {
75617560 // Function pointers and extern functions aren't guaranteed to
75627561 // actually be noreturn so we add a safety check for them.
7563 if (try sema.resolveMaybeUndefVal(func)) |func_val| {
7562 if (try sema.resolveValue(func)) |func_val| {
75647563 switch (mod.intern_pool.indexToKey(func_val.toIntern())) {
75657564 .func => break :skip_safety,
75667565 .ptr => |ptr| switch (ptr.addr) {
......@@ -7649,19 +7648,19 @@ fn analyzeInlineCallArg(
76497648 }
76507649 const arg_src = args_info.argSrc(arg_block, arg_i.*);
76517650 if (try ics.callee().typeRequiresComptime(param_ty.toType())) {
7652 _ = try ics.caller().resolveConstMaybeUndefVal(arg_block, arg_src, casted_arg, .{
7651 _ = try ics.caller().resolveConstValue(arg_block, arg_src, casted_arg, .{
76537652 .needed_comptime_reason = "argument to parameter with comptime-only type must be comptime-known",
76547653 .block_comptime_reason = param_block.comptime_reason,
76557654 });
76567655 } else if (!is_comptime_call and zir_tags[inst] == .param_comptime) {
7657 _ = try ics.caller().resolveConstMaybeUndefVal(arg_block, arg_src, casted_arg, .{
7656 _ = try ics.caller().resolveConstValue(arg_block, arg_src, casted_arg, .{
76587657 .needed_comptime_reason = "parameter is comptime",
76597658 });
76607659 }
76617660
76627661 if (is_comptime_call) {
76637662 ics.callee().inst_map.putAssumeCapacityNoClobber(inst, casted_arg);
7664 const arg_val = try ics.caller().resolveConstMaybeUndefVal(arg_block, arg_src, casted_arg, .{
7663 const arg_val = try ics.caller().resolveConstValue(arg_block, arg_src, casted_arg, .{
76657664 .needed_comptime_reason = "argument to function being called at comptime must be comptime-known",
76667665 .block_comptime_reason = param_block.comptime_reason,
76677666 });
......@@ -7683,7 +7682,7 @@ fn analyzeInlineCallArg(
76837682 ics.callee().inst_map.putAssumeCapacityNoClobber(inst, casted_arg);
76847683 }
76857684
7686 if (try ics.caller().resolveMaybeUndefVal(casted_arg)) |_| {
7685 if (try ics.caller().resolveValue(casted_arg)) |_| {
76877686 param_block.inlining.?.has_comptime_args = true;
76887687 }
76897688
......@@ -7700,7 +7699,7 @@ fn analyzeInlineCallArg(
77007699
77017700 if (is_comptime_call) {
77027701 ics.callee().inst_map.putAssumeCapacityNoClobber(inst, uncasted_arg);
7703 const arg_val = try ics.caller().resolveConstMaybeUndefVal(arg_block, arg_src, uncasted_arg, .{
7702 const arg_val = try ics.caller().resolveConstValue(arg_block, arg_src, uncasted_arg, .{
77047703 .needed_comptime_reason = "argument to function being called at comptime must be comptime-known",
77057704 .block_comptime_reason = param_block.comptime_reason,
77067705 });
......@@ -7720,14 +7719,14 @@ fn analyzeInlineCallArg(
77207719 memoized_arg_values[arg_i.*] = try resolved_arg_val.intern(ics.caller().typeOf(uncasted_arg), mod);
77217720 } else {
77227721 if (zir_tags[inst] == .param_anytype_comptime) {
7723 _ = try ics.caller().resolveConstMaybeUndefVal(arg_block, arg_src, uncasted_arg, .{
7722 _ = try ics.caller().resolveConstValue(arg_block, arg_src, uncasted_arg, .{
77247723 .needed_comptime_reason = "parameter is comptime",
77257724 });
77267725 }
77277726 ics.callee().inst_map.putAssumeCapacityNoClobber(inst, uncasted_arg);
77287727 }
77297728
7730 if (try ics.caller().resolveMaybeUndefVal(uncasted_arg)) |_| {
7729 if (try ics.caller().resolveValue(uncasted_arg)) |_| {
77317730 param_block.inlining.?.has_comptime_args = true;
77327731 }
77337732
......@@ -7769,7 +7768,7 @@ fn instantiateGenericCall(
77697768 const gpa = sema.gpa;
77707769 const ip = &mod.intern_pool;
77717770
7772 const func_val = try sema.resolveConstValue(block, func_src, func, .{
7771 const func_val = try sema.resolveConstDefinedValue(block, func_src, func, .{
77737772 .needed_comptime_reason = "generic function being called must be comptime-known",
77747773 });
77757774 const generic_owner = switch (mod.intern_pool.indexToKey(func_val.toIntern())) {
......@@ -7906,7 +7905,7 @@ fn instantiateGenericCall(
79067905 };
79077906
79087907 if (arg_is_comptime) {
7909 if (try sema.resolveMaybeUndefVal(arg_ref)) |arg_val| {
7908 if (try sema.resolveValue(arg_ref)) |arg_val| {
79107909 comptime_args[arg_index] = arg_val.toIntern();
79117910 child_sema.inst_map.putAssumeCapacityNoClobber(
79127911 param_inst,
......@@ -7978,7 +7977,7 @@ fn instantiateGenericCall(
79787977 // We've already handled parameters, so don't resolve the whole body. Instead, just
79797978 // do the instructions after the params (i.e. the func itself).
79807979 const new_func_inst = try child_sema.resolveBody(&child_block, fn_info.param_body[args_info.count()..], fn_info.param_body_inst);
7981 const callee_index = (child_sema.resolveConstValue(&child_block, .unneeded, new_func_inst, undefined) catch unreachable).toIntern();
7980 const callee_index = (child_sema.resolveConstDefinedValue(&child_block, .unneeded, new_func_inst, undefined) catch unreachable).toIntern();
79827981
79837982 const callee = mod.funcInfo(callee_index);
79847983 callee.branchQuota(ip).* = @max(callee.branchQuota(ip).*, sema.branch_quota);
......@@ -8229,7 +8228,7 @@ fn zirArrayTypeSentinel(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compil
82298228 try sema.validateArrayElemType(block, elem_type, elem_src);
82308229 const uncasted_sentinel = try sema.resolveInst(extra.sentinel);
82318230 const sentinel = try sema.coerce(block, elem_type, uncasted_sentinel, sentinel_src);
8232 const sentinel_val = try sema.resolveConstValue(block, sentinel_src, sentinel, .{
8231 const sentinel_val = try sema.resolveConstDefinedValue(block, sentinel_src, sentinel, .{
82338232 .needed_comptime_reason = "array sentinel value must be comptime-known",
82348233 });
82358234 const array_ty = try sema.mod.arrayType(.{
......@@ -8328,7 +8327,7 @@ fn zirIntFromError(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstD
83288327 const operand = try sema.coerce(block, Type.anyerror, uncasted_operand, operand_src);
83298328 const err_int_ty = try mod.errorIntType();
83308329
8331 if (try sema.resolveMaybeUndefVal(operand)) |val| {
8330 if (try sema.resolveValue(operand)) |val| {
83328331 if (val.isUndef(mod)) {
83338332 return mod.undefRef(err_int_ty);
83348333 }
......@@ -8501,7 +8500,7 @@ fn zirIntFromEnum(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
85018500 return Air.internedToRef((try mod.getCoerced(opv, int_tag_ty)).toIntern());
85028501 }
85038502
8504 if (try sema.resolveMaybeUndefVal(enum_tag)) |enum_tag_val| {
8503 if (try sema.resolveValue(enum_tag)) |enum_tag_val| {
85058504 const val = try enum_tag_val.intFromEnum(enum_tag_ty, mod);
85068505 return Air.internedToRef(val.toIntern());
85078506 }
......@@ -8524,7 +8523,7 @@ fn zirEnumFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
85248523 }
85258524 _ = try sema.checkIntType(block, operand_src, sema.typeOf(operand));
85268525
8527 if (try sema.resolveMaybeUndefVal(operand)) |int_val| {
8526 if (try sema.resolveValue(operand)) |int_val| {
85288527 if (dest_ty.isNonexhaustiveEnum(mod)) {
85298528 const int_tag_ty = dest_ty.intTagType(mod);
85308529 if (try sema.intFitsInType(int_val, int_tag_ty, null)) {
......@@ -9032,7 +9031,7 @@ fn resolveGenericBody(
90329031
90339032 const uncasted = sema.resolveBody(block, body, func_inst) catch |err| break :err err;
90349033 const result = sema.coerce(block, dest_ty, uncasted, src) catch |err| break :err err;
9035 const val = sema.resolveConstValue(block, src, result, reason) catch |err| break :err err;
9034 const val = sema.resolveConstDefinedValue(block, src, result, reason) catch |err| break :err err;
90369035 return val;
90379036 };
90389037 switch (err) {
......@@ -9846,7 +9845,7 @@ fn zirIntFromPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
98469845 };
98479846 return sema.failWithOwnedErrorMsg(block, msg);
98489847 }
9849 if (try sema.resolveMaybeUndefValIntable(operand)) |operand_val| ct: {
9848 if (try sema.resolveValueIntable(operand)) |operand_val| ct: {
98509849 if (!is_vector) {
98519850 return Air.internedToRef((try mod.intValue(
98529851 Type.usize,
......@@ -10312,7 +10311,7 @@ fn zirFloatCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
1031210311 ),
1031310312 }
1031410313
10315 if (try sema.resolveMaybeUndefVal(operand)) |operand_val| {
10314 if (try sema.resolveValue(operand)) |operand_val| {
1031610315 if (!is_vector) {
1031710316 return Air.internedToRef((try operand_val.floatCast(dest_ty, mod)).toIntern());
1031810317 }
......@@ -10710,7 +10709,7 @@ const SwitchProngAnalysis = struct {
1071010709 const operand_src: LazySrcLoc = .{ .node_offset_switch_operand = switch_node_offset };
1071110710
1071210711 if (inline_case_capture != .none) {
10713 const item_val = sema.resolveConstValue(block, .unneeded, inline_case_capture, undefined) catch unreachable;
10712 const item_val = sema.resolveConstDefinedValue(block, .unneeded, inline_case_capture, undefined) catch unreachable;
1071410713 if (operand_ty.zigTypeTag(mod) == .Union) {
1071510714 const field_index: u32 = @intCast(operand_ty.unionTagFieldIndex(item_val, mod).?);
1071610715 const union_obj = mod.typeToUnion(operand_ty).?;
......@@ -10767,14 +10766,14 @@ const SwitchProngAnalysis = struct {
1076710766 switch (operand_ty.zigTypeTag(mod)) {
1076810767 .Union => {
1076910768 const union_obj = mod.typeToUnion(operand_ty).?;
10770 const first_item_val = sema.resolveConstValue(block, .unneeded, case_vals[0], undefined) catch unreachable;
10769 const first_item_val = sema.resolveConstDefinedValue(block, .unneeded, case_vals[0], undefined) catch unreachable;
1077110770
1077210771 const first_field_index: u32 = mod.unionTagFieldIndex(union_obj, first_item_val).?;
1077310772 const first_field_ty = union_obj.field_types.get(ip)[first_field_index].toType();
1077410773
1077510774 const field_tys = try sema.arena.alloc(Type, case_vals.len);
1077610775 for (case_vals, field_tys) |item, *field_ty| {
10777 const item_val = sema.resolveConstValue(block, .unneeded, item, undefined) catch unreachable;
10776 const item_val = sema.resolveConstDefinedValue(block, .unneeded, item, undefined) catch unreachable;
1077810777 const field_idx = mod.unionTagFieldIndex(union_obj, item_val).?;
1077910778 field_ty.* = union_obj.field_types.get(ip)[field_idx].toType();
1078010779 }
......@@ -11023,7 +11022,7 @@ const SwitchProngAnalysis = struct {
1102311022 }
1102411023
1102511024 if (case_vals.len == 1) {
11026 const item_val = sema.resolveConstValue(block, .unneeded, case_vals[0], undefined) catch unreachable;
11025 const item_val = sema.resolveConstDefinedValue(block, .unneeded, case_vals[0], undefined) catch unreachable;
1102711026 const item_ty = try mod.singleErrorSetType(item_val.getErrorName(mod).unwrap().?);
1102811027 return sema.bitCast(block, item_ty, spa.operand, operand_src, null);
1102911028 }
......@@ -11031,7 +11030,7 @@ const SwitchProngAnalysis = struct {
1103111030 var names: InferredErrorSet.NameMap = .{};
1103211031 try names.ensureUnusedCapacity(sema.arena, case_vals.len);
1103311032 for (case_vals) |err| {
11034 const err_val = sema.resolveConstValue(block, .unneeded, err, undefined) catch unreachable;
11033 const err_val = sema.resolveConstDefinedValue(block, .unneeded, err, undefined) catch unreachable;
1103511034 names.putAssumeCapacityNoClobber(err_val.getErrorName(mod).unwrap().?, {});
1103611035 }
1103711036 const error_ty = try mod.errorSetFromUnsortedNames(names.keys());
......@@ -11805,7 +11804,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1180511804 extra_index += info.body_len;
1180611805
1180711806 const item = case_vals.items[scalar_i];
11808 const item_val = sema.resolveConstValue(&child_block, .unneeded, item, undefined) catch unreachable;
11807 const item_val = sema.resolveConstDefinedValue(&child_block, .unneeded, item, undefined) catch unreachable;
1180911808 if (operand_val.eql(item_val, operand_ty, sema.mod)) {
1181011809 if (err_set) try sema.maybeErrorUnwrapComptime(&child_block, body, operand);
1181111810 return spa.resolveProngComptime(
......@@ -11839,7 +11838,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1183911838
1184011839 for (items) |item| {
1184111840 // Validation above ensured these will succeed.
11842 const item_val = sema.resolveConstValue(&child_block, .unneeded, item, undefined) catch unreachable;
11841 const item_val = sema.resolveConstDefinedValue(&child_block, .unneeded, item, undefined) catch unreachable;
1184311842 if (operand_val.eql(item_val, operand_ty, sema.mod)) {
1184411843 if (err_set) try sema.maybeErrorUnwrapComptime(&child_block, body, operand);
1184511844 return spa.resolveProngComptime(
......@@ -11863,8 +11862,8 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1186311862 case_val_idx += 2;
1186411863
1186511864 // Validation above ensured these will succeed.
11866 const first_val = sema.resolveConstValue(&child_block, .unneeded, range_items[0], undefined) catch unreachable;
11867 const last_val = sema.resolveConstValue(&child_block, .unneeded, range_items[1], undefined) catch unreachable;
11865 const first_val = sema.resolveConstDefinedValue(&child_block, .unneeded, range_items[0], undefined) catch unreachable;
11866 const last_val = sema.resolveConstDefinedValue(&child_block, .unneeded, range_items[1], undefined) catch unreachable;
1186811867 if ((try sema.compareAll(resolved_operand_val, .gte, first_val, operand_ty)) and
1186911868 (try sema.compareAll(resolved_operand_val, .lte, last_val, operand_ty)))
1187011869 {
......@@ -11936,7 +11935,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1193611935 }
1193711936
1193811937 if (child_block.is_comptime) {
11939 _ = try sema.resolveConstValue(&child_block, operand_src, operand, .{
11938 _ = try sema.resolveConstDefinedValue(&child_block, operand_src, operand, .{
1194011939 .needed_comptime_reason = "condition in comptime switch must be comptime-known",
1194111940 .block_comptime_reason = child_block.comptime_reason,
1194211941 });
......@@ -11971,7 +11970,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1197111970 // `item` is already guaranteed to be constant known.
1197211971
1197311972 const analyze_body = if (union_originally) blk: {
11974 const unresolved_item_val = sema.resolveConstValue(block, .unneeded, item, undefined) catch unreachable;
11973 const unresolved_item_val = sema.resolveConstDefinedValue(block, .unneeded, item, undefined) catch unreachable;
1197511974 const item_val = sema.resolveLazyValue(unresolved_item_val) catch unreachable;
1197611975 const field_ty = maybe_union_ty.unionFieldType(item_val, mod).?;
1197711976 break :blk field_ty.zigTypeTag(mod) != .NoReturn;
......@@ -12040,8 +12039,8 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1204012039 const item_first_ref = range_items[0];
1204112040 const item_last_ref = range_items[1];
1204212041
12043 var item = sema.resolveConstValue(block, .unneeded, item_first_ref, undefined) catch unreachable;
12044 const item_last = sema.resolveConstValue(block, .unneeded, item_last_ref, undefined) catch unreachable;
12042 var item = sema.resolveConstDefinedValue(block, .unneeded, item_first_ref, undefined) catch unreachable;
12043 const item_last = sema.resolveConstDefinedValue(block, .unneeded, item_last_ref, undefined) catch unreachable;
1204512044
1204612045 while (item.compareScalar(.lte, item_last, operand_ty, mod)) : ({
1204712046 // Previous validation has resolved any possible lazy values.
......@@ -12098,7 +12097,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1209812097 case_block.wip_capture_scope = child_block.wip_capture_scope;
1209912098
1210012099 const analyze_body = if (union_originally) blk: {
12101 const item_val = sema.resolveConstValue(block, .unneeded, item, undefined) catch unreachable;
12100 const item_val = sema.resolveConstDefinedValue(block, .unneeded, item, undefined) catch unreachable;
1210212101 const field_ty = maybe_union_ty.unionFieldType(item_val, mod).?;
1210312102 break :blk field_ty.zigTypeTag(mod) != .NoReturn;
1210412103 } else true;
......@@ -12152,7 +12151,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1215212151
1215312152 const analyze_body = if (union_originally)
1215412153 for (items) |item| {
12155 const item_val = sema.resolveConstValue(block, .unneeded, item, undefined) catch unreachable;
12154 const item_val = sema.resolveConstDefinedValue(block, .unneeded, item, undefined) catch unreachable;
1215612155 const field_ty = maybe_union_ty.unionFieldType(item_val, mod).?;
1215712156 if (field_ty.zigTypeTag(mod) != .NoReturn) break true;
1215812157 } else false
......@@ -12642,10 +12641,10 @@ fn resolveSwitchItemVal(
1264212641 else => |e| return e,
1264312642 };
1264412643
12645 const maybe_lazy = sema.resolveConstValue(block, .unneeded, item, undefined) catch |err| switch (err) {
12644 const maybe_lazy = sema.resolveConstDefinedValue(block, .unneeded, item, undefined) catch |err| switch (err) {
1264612645 error.NeededSourceLocation => {
1264712646 const src = switch_prong_src.resolve(mod, mod.declPtr(block.src_decl), switch_node_offset, range_expand);
12648 _ = try sema.resolveConstValue(block, src, item, .{
12647 _ = try sema.resolveConstDefinedValue(block, src, item, .{
1264912648 .needed_comptime_reason = "switch prong values must be comptime-known",
1265012649 });
1265112650 unreachable;
......@@ -13133,8 +13132,8 @@ fn zirShl(
1313313132 // TODO coerce rhs if air_tag is not shl_sat
1313413133 const rhs_is_comptime_int = try sema.checkIntType(block, rhs_src, scalar_rhs_ty);
1313513134
13136 const maybe_lhs_val = try sema.resolveMaybeUndefValIntable(lhs);
13137 const maybe_rhs_val = try sema.resolveMaybeUndefValIntable(rhs);
13135 const maybe_lhs_val = try sema.resolveValueIntable(lhs);
13136 const maybe_rhs_val = try sema.resolveValueIntable(rhs);
1313813137
1313913138 if (maybe_rhs_val) |rhs_val| {
1314013139 if (rhs_val.isUndef(mod)) {
......@@ -13311,8 +13310,8 @@ fn zirShr(
1331113310 try sema.checkVectorizableBinaryOperands(block, src, lhs_ty, rhs_ty, lhs_src, rhs_src);
1331213311 const scalar_ty = lhs_ty.scalarType(mod);
1331313312
13314 const maybe_lhs_val = try sema.resolveMaybeUndefValIntable(lhs);
13315 const maybe_rhs_val = try sema.resolveMaybeUndefValIntable(rhs);
13313 const maybe_lhs_val = try sema.resolveValueIntable(lhs);
13314 const maybe_rhs_val = try sema.resolveValueIntable(rhs);
1331613315
1331713316 const runtime_src = if (maybe_rhs_val) |rhs_val| rs: {
1331813317 if (rhs_val.isUndef(mod)) {
......@@ -13463,8 +13462,8 @@ fn zirBitwise(
1346313462 const runtime_src = runtime: {
1346413463 // TODO: ask the linker what kind of relocations are available, and
1346513464 // in some cases emit a Value that means "this decl's address AND'd with this operand".
13466 if (try sema.resolveMaybeUndefValIntable(casted_lhs)) |lhs_val| {
13467 if (try sema.resolveMaybeUndefValIntable(casted_rhs)) |rhs_val| {
13465 if (try sema.resolveValueIntable(casted_lhs)) |lhs_val| {
13466 if (try sema.resolveValueIntable(casted_rhs)) |rhs_val| {
1346813467 const result_val = switch (air_tag) {
1346913468 .bit_and => try lhs_val.bitwiseAnd(rhs_val, resolved_type, sema.arena, mod),
1347013469 .bit_or => try lhs_val.bitwiseOr(rhs_val, resolved_type, sema.arena, mod),
......@@ -13503,7 +13502,7 @@ fn zirBitNot(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
1350313502 });
1350413503 }
1350513504
13506 if (try sema.resolveMaybeUndefVal(operand)) |val| {
13505 if (try sema.resolveValue(operand)) |val| {
1350713506 if (val.isUndef(mod)) {
1350813507 return mod.undefRef(operand_type);
1350913508 } else if (operand_type.zigTypeTag(mod) == .Vector) {
......@@ -13673,10 +13672,10 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1367313672 const rhs_sent = Air.internedToRef(rhs_sent_val.toIntern());
1367413673 const lhs_sent_casted = try sema.coerce(block, resolved_elem_ty, lhs_sent, lhs_src);
1367513674 const rhs_sent_casted = try sema.coerce(block, resolved_elem_ty, rhs_sent, rhs_src);
13676 const lhs_sent_casted_val = try sema.resolveConstValue(block, lhs_src, lhs_sent_casted, .{
13675 const lhs_sent_casted_val = try sema.resolveConstDefinedValue(block, lhs_src, lhs_sent_casted, .{
1367713676 .needed_comptime_reason = "array sentinel value must be comptime-known",
1367813677 });
13679 const rhs_sent_casted_val = try sema.resolveConstValue(block, rhs_src, rhs_sent_casted, .{
13678 const rhs_sent_casted_val = try sema.resolveConstDefinedValue(block, rhs_src, rhs_sent_casted, .{
1368013679 .needed_comptime_reason = "array sentinel value must be comptime-known",
1368113680 });
1368213681 if (try sema.valuesEqual(lhs_sent_casted_val, rhs_sent_casted_val, resolved_elem_ty)) {
......@@ -13686,7 +13685,7 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1368613685 }
1368713686 } else {
1368813687 const lhs_sent_casted = try sema.coerce(block, resolved_elem_ty, lhs_sent, lhs_src);
13689 const lhs_sent_casted_val = try sema.resolveConstValue(block, lhs_src, lhs_sent_casted, .{
13688 const lhs_sent_casted_val = try sema.resolveConstDefinedValue(block, lhs_src, lhs_sent_casted, .{
1369013689 .needed_comptime_reason = "array sentinel value must be comptime-known",
1369113690 });
1369213691 break :s lhs_sent_casted_val;
......@@ -13695,7 +13694,7 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1369513694 if (rhs_info.sentinel) |rhs_sent_val| {
1369613695 const rhs_sent = Air.internedToRef(rhs_sent_val.toIntern());
1369713696 const rhs_sent_casted = try sema.coerce(block, resolved_elem_ty, rhs_sent, rhs_src);
13698 const rhs_sent_casted_val = try sema.resolveConstValue(block, rhs_src, rhs_sent_casted, .{
13697 const rhs_sent_casted_val = try sema.resolveConstDefinedValue(block, rhs_src, rhs_sent_casted, .{
1369913698 .needed_comptime_reason = "array sentinel value must be comptime-known",
1370013699 });
1370113700 break :s rhs_sent_casted_val;
......@@ -13728,12 +13727,12 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1372813727 };
1372913728
1373013729 const runtime_src = if (switch (lhs_ty.zigTypeTag(mod)) {
13731 .Array, .Struct => try sema.resolveMaybeUndefVal(lhs),
13730 .Array, .Struct => try sema.resolveValue(lhs),
1373213731 .Pointer => try sema.resolveDefinedValue(block, lhs_src, lhs),
1373313732 else => unreachable,
1373413733 }) |lhs_val| rs: {
1373513734 if (switch (rhs_ty.zigTypeTag(mod)) {
13736 .Array, .Struct => try sema.resolveMaybeUndefVal(rhs),
13735 .Array, .Struct => try sema.resolveValue(rhs),
1373713736 .Pointer => try sema.resolveDefinedValue(block, rhs_src, rhs),
1373813737 else => unreachable,
1373913738 }) |rhs_val| {
......@@ -13755,7 +13754,7 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1375513754 const elem_val = if (elem_default_val.toIntern() == .unreachable_value) try lhs_sub_val.elemValue(mod, lhs_elem_i) else elem_default_val;
1375613755 const elem_val_inst = Air.internedToRef(elem_val.toIntern());
1375713756 const coerced_elem_val_inst = try sema.coerce(block, resolved_elem_ty, elem_val_inst, .unneeded);
13758 const coerced_elem_val = try sema.resolveConstMaybeUndefVal(block, .unneeded, coerced_elem_val_inst, undefined);
13757 const coerced_elem_val = try sema.resolveConstValue(block, .unneeded, coerced_elem_val_inst, undefined);
1375913758 element_vals[elem_i] = try coerced_elem_val.intern(resolved_elem_ty, mod);
1376013759 }
1376113760 while (elem_i < result_len) : (elem_i += 1) {
......@@ -13764,7 +13763,7 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1376413763 const elem_val = if (elem_default_val.toIntern() == .unreachable_value) try rhs_sub_val.elemValue(mod, rhs_elem_i) else elem_default_val;
1376513764 const elem_val_inst = Air.internedToRef(elem_val.toIntern());
1376613765 const coerced_elem_val_inst = try sema.coerce(block, resolved_elem_ty, elem_val_inst, .unneeded);
13767 const coerced_elem_val = try sema.resolveConstMaybeUndefVal(block, .unneeded, coerced_elem_val_inst, undefined);
13766 const coerced_elem_val = try sema.resolveConstValue(block, .unneeded, coerced_elem_val_inst, undefined);
1376813767 element_vals[elem_i] = try coerced_elem_val.intern(resolved_elem_ty, mod);
1376913768 }
1377013769 return sema.addConstantMaybeRef(block, result_ty, (try mod.intern(.{ .aggregate = .{
......@@ -13841,7 +13840,7 @@ fn getArrayCatInfo(sema: *Sema, block: *Block, src: LazySrcLoc, operand: Air.Ins
1384113840 // has a sentinel, and this code should compute the length based
1384213841 // on the sentinel value.
1384313842 .Slice, .Many => {
13844 const val = try sema.resolveConstValue(block, src, operand, .{
13843 const val = try sema.resolveConstDefinedValue(block, src, operand, .{
1384513844 .needed_comptime_reason = "slice value being concatenated must be comptime-known",
1384613845 });
1384713846 return Type.ArrayInfo{
......@@ -14109,7 +14108,7 @@ fn zirNegate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
1410914108
1411014109 if (rhs_scalar_ty.isAnyFloat()) {
1411114110 // We handle float negation here to ensure negative zero is represented in the bits.
14112 if (try sema.resolveMaybeUndefVal(rhs)) |rhs_val| {
14111 if (try sema.resolveValue(rhs)) |rhs_val| {
1411314112 if (rhs_val.isUndef(mod)) return mod.undefRef(rhs_ty);
1411414113 return Air.internedToRef((try rhs_val.floatNeg(rhs_ty, sema.arena, mod)).toIntern());
1411514114 }
......@@ -14195,8 +14194,8 @@ fn zirDiv(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins
1419514194
1419614195 try sema.checkArithmeticOp(block, src, scalar_tag, lhs_zig_ty_tag, rhs_zig_ty_tag, .div);
1419714196
14198 const maybe_lhs_val = try sema.resolveMaybeUndefValIntable(casted_lhs);
14199 const maybe_rhs_val = try sema.resolveMaybeUndefValIntable(casted_rhs);
14197 const maybe_lhs_val = try sema.resolveValueIntable(casted_lhs);
14198 const maybe_rhs_val = try sema.resolveValueIntable(casted_rhs);
1420014199
1420114200 if ((lhs_ty.zigTypeTag(mod) == .ComptimeFloat and rhs_ty.zigTypeTag(mod) == .ComptimeInt) or
1420214201 (lhs_ty.zigTypeTag(mod) == .ComptimeInt and rhs_ty.zigTypeTag(mod) == .ComptimeFloat))
......@@ -14360,8 +14359,8 @@ fn zirDivExact(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1436014359
1436114360 try sema.checkArithmeticOp(block, src, scalar_tag, lhs_zig_ty_tag, rhs_zig_ty_tag, .div_exact);
1436214361
14363 const maybe_lhs_val = try sema.resolveMaybeUndefValIntable(casted_lhs);
14364 const maybe_rhs_val = try sema.resolveMaybeUndefValIntable(casted_rhs);
14362 const maybe_lhs_val = try sema.resolveValueIntable(casted_lhs);
14363 const maybe_rhs_val = try sema.resolveValueIntable(casted_rhs);
1436514364
1436614365 const runtime_src = rs: {
1436714366 // For integers:
......@@ -14527,8 +14526,8 @@ fn zirDivFloor(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1452714526
1452814527 try sema.checkArithmeticOp(block, src, scalar_tag, lhs_zig_ty_tag, rhs_zig_ty_tag, .div_floor);
1452914528
14530 const maybe_lhs_val = try sema.resolveMaybeUndefValIntable(casted_lhs);
14531 const maybe_rhs_val = try sema.resolveMaybeUndefValIntable(casted_rhs);
14529 const maybe_lhs_val = try sema.resolveValueIntable(casted_lhs);
14530 const maybe_rhs_val = try sema.resolveValueIntable(casted_rhs);
1453214531
1453314532 const runtime_src = rs: {
1453414533 // For integers:
......@@ -14638,8 +14637,8 @@ fn zirDivTrunc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1463814637
1463914638 try sema.checkArithmeticOp(block, src, scalar_tag, lhs_zig_ty_tag, rhs_zig_ty_tag, .div_trunc);
1464014639
14641 const maybe_lhs_val = try sema.resolveMaybeUndefValIntable(casted_lhs);
14642 const maybe_rhs_val = try sema.resolveMaybeUndefValIntable(casted_rhs);
14640 const maybe_lhs_val = try sema.resolveValueIntable(casted_lhs);
14641 const maybe_rhs_val = try sema.resolveValueIntable(casted_rhs);
1464314642
1464414643 const runtime_src = rs: {
1464514644 // For integers:
......@@ -14882,8 +14881,8 @@ fn zirModRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
1488214881
1488314882 try sema.checkArithmeticOp(block, src, scalar_tag, lhs_zig_ty_tag, rhs_zig_ty_tag, .mod_rem);
1488414883
14885 const maybe_lhs_val = try sema.resolveMaybeUndefValIntable(casted_lhs);
14886 const maybe_rhs_val = try sema.resolveMaybeUndefValIntable(casted_rhs);
14884 const maybe_lhs_val = try sema.resolveValueIntable(casted_lhs);
14885 const maybe_rhs_val = try sema.resolveValueIntable(casted_rhs);
1488714886
1488814887 const runtime_src = rs: {
1488914888 // For integers:
......@@ -15063,8 +15062,8 @@ fn zirMod(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins
1506315062
1506415063 try sema.checkArithmeticOp(block, src, scalar_tag, lhs_zig_ty_tag, rhs_zig_ty_tag, .mod);
1506515064
15066 const maybe_lhs_val = try sema.resolveMaybeUndefValIntable(casted_lhs);
15067 const maybe_rhs_val = try sema.resolveMaybeUndefValIntable(casted_rhs);
15065 const maybe_lhs_val = try sema.resolveValueIntable(casted_lhs);
15066 const maybe_rhs_val = try sema.resolveValueIntable(casted_rhs);
1506815067
1506915068 const runtime_src = rs: {
1507015069 // For integers:
......@@ -15159,8 +15158,8 @@ fn zirRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins
1515915158
1516015159 try sema.checkArithmeticOp(block, src, scalar_tag, lhs_zig_ty_tag, rhs_zig_ty_tag, .rem);
1516115160
15162 const maybe_lhs_val = try sema.resolveMaybeUndefValIntable(casted_lhs);
15163 const maybe_rhs_val = try sema.resolveMaybeUndefValIntable(casted_rhs);
15161 const maybe_lhs_val = try sema.resolveValueIntable(casted_lhs);
15162 const maybe_rhs_val = try sema.resolveValueIntable(casted_rhs);
1516415163
1516515164 const runtime_src = rs: {
1516615165 // For integers:
......@@ -15269,8 +15268,8 @@ fn zirOverflowArithmetic(
1526915268 return sema.fail(block, src, "expected vector of integers or integer tag type, found '{}'", .{dest_ty.fmt(mod)});
1527015269 }
1527115270
15272 const maybe_lhs_val = try sema.resolveMaybeUndefVal(lhs);
15273 const maybe_rhs_val = try sema.resolveMaybeUndefVal(rhs);
15271 const maybe_lhs_val = try sema.resolveValue(lhs);
15272 const maybe_rhs_val = try sema.resolveValue(rhs);
1527415273
1527515274 const tuple_ty = try sema.overflowArithmeticTupleType(dest_ty);
1527615275 const overflow_ty = ip.indexToKey(tuple_ty.toIntern()).anon_struct_type.types.get(ip)[1].toType();
......@@ -15413,7 +15412,7 @@ fn zirOverflowArithmetic(
1541315412 };
1541415413
1541515414 if (result.inst != .none) {
15416 if (try sema.resolveMaybeUndefVal(result.inst)) |some| {
15415 if (try sema.resolveValue(result.inst)) |some| {
1541715416 result.wrapped = some;
1541815417 result.inst = .none;
1541915418 }
......@@ -15509,8 +15508,8 @@ fn analyzeArithmetic(
1550915508
1551015509 try sema.checkArithmeticOp(block, src, scalar_tag, lhs_zig_ty_tag, rhs_zig_ty_tag, zir_tag);
1551115510
15512 const maybe_lhs_val = try sema.resolveMaybeUndefValIntable(casted_lhs);
15513 const maybe_rhs_val = try sema.resolveMaybeUndefValIntable(casted_rhs);
15511 const maybe_lhs_val = try sema.resolveValueIntable(casted_lhs);
15512 const maybe_rhs_val = try sema.resolveValueIntable(casted_rhs);
1551415513 const runtime_src: LazySrcLoc, const air_tag: Air.Inst.Tag, const air_tag_safe: Air.Inst.Tag = rs: {
1551515514 switch (zir_tag) {
1551615515 .add, .add_unsafe => {
......@@ -15959,7 +15958,7 @@ fn analyzePtrArithmetic(
1595915958 // coerce to isize instead of usize.
1596015959 const offset = try sema.coerce(block, Type.usize, uncasted_offset, offset_src);
1596115960 const mod = sema.mod;
15962 const opt_ptr_val = try sema.resolveMaybeUndefVal(ptr);
15961 const opt_ptr_val = try sema.resolveValue(ptr);
1596315962 const opt_off_val = try sema.resolveDefinedValue(block, offset_src, offset);
1596415963 const ptr_ty = sema.typeOf(ptr);
1596515964 const ptr_info = ptr_ty.ptrInfo(mod);
......@@ -16265,8 +16264,8 @@ fn zirCmpEq(
1626516264
1626616265 if (lhs_ty_tag == .ErrorSet and rhs_ty_tag == .ErrorSet) {
1626716266 const runtime_src: LazySrcLoc = src: {
16268 if (try sema.resolveMaybeUndefVal(lhs)) |lval| {
16269 if (try sema.resolveMaybeUndefVal(rhs)) |rval| {
16267 if (try sema.resolveValue(lhs)) |lval| {
16268 if (try sema.resolveValue(rhs)) |rval| {
1627016269 if (lval.isUndef(mod) or rval.isUndef(mod)) {
1627116270 return mod.undefRef(Type.bool);
1627216271 }
......@@ -16321,7 +16320,7 @@ fn analyzeCmpUnionTag(
1632116320 const coerced_tag = try sema.coerce(block, union_tag_ty, tag, tag_src);
1632216321 const coerced_union = try sema.coerce(block, union_tag_ty, un, un_src);
1632316322
16324 if (try sema.resolveMaybeUndefVal(coerced_tag)) |enum_val| {
16323 if (try sema.resolveValue(coerced_tag)) |enum_val| {
1632516324 if (enum_val.isUndef(mod)) return mod.undefRef(Type.bool);
1632616325 const field_ty = union_ty.unionFieldType(enum_val, mod).?;
1632716326 if (field_ty.zigTypeTag(mod) == .NoReturn) {
......@@ -16423,9 +16422,9 @@ fn cmpSelf(
1642316422 const mod = sema.mod;
1642416423 const resolved_type = sema.typeOf(casted_lhs);
1642516424 const runtime_src: LazySrcLoc = src: {
16426 if (try sema.resolveMaybeUndefVal(casted_lhs)) |lhs_val| {
16425 if (try sema.resolveValue(casted_lhs)) |lhs_val| {
1642716426 if (lhs_val.isUndef(mod)) return mod.undefRef(Type.bool);
16428 if (try sema.resolveMaybeUndefVal(casted_rhs)) |rhs_val| {
16427 if (try sema.resolveValue(casted_rhs)) |rhs_val| {
1642916428 if (rhs_val.isUndef(mod)) return mod.undefRef(Type.bool);
1643016429
1643116430 if (resolved_type.zigTypeTag(mod) == .Vector) {
......@@ -16448,7 +16447,7 @@ fn cmpSelf(
1644816447 // For bools, we still check the other operand, because we can lower
1644916448 // bool eq/neq more efficiently.
1645016449 if (resolved_type.zigTypeTag(mod) == .Bool) {
16451 if (try sema.resolveMaybeUndefVal(casted_rhs)) |rhs_val| {
16450 if (try sema.resolveValue(casted_rhs)) |rhs_val| {
1645216451 if (rhs_val.isUndef(mod)) return mod.undefRef(Type.bool);
1645316452 return sema.runtimeBoolCmp(block, src, op, casted_lhs, rhs_val.toBool(), lhs_src);
1645416453 }
......@@ -16594,7 +16593,7 @@ fn zirClosureCapture(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr
1659416593 .zir_index = inst,
1659516594 .index = block.wip_capture_scope,
1659616595 };
16597 if (try sema.resolveMaybeUndefVal(operand)) |val| {
16596 if (try sema.resolveValue(operand)) |val| {
1659816597 try mod.comptime_capture_scopes.put(gpa, key, try val.intern(ty, mod));
1659916598 } else {
1660016599 try mod.runtime_capture_scopes.put(gpa, key, ty.toIntern());
......@@ -18079,7 +18078,7 @@ fn zirBoolNot(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1807918078 const uncasted_operand = try sema.resolveInst(inst_data.operand);
1808018079
1808118080 const operand = try sema.coerce(block, Type.bool, uncasted_operand, operand_src);
18082 if (try sema.resolveMaybeUndefVal(operand)) |val| {
18081 if (try sema.resolveValue(operand)) |val| {
1808318082 return if (val.isUndef(mod))
1808418083 mod.undefRef(Type.bool)
1808518084 else if (val.toBool()) .bool_false else .bool_true;
......@@ -18238,7 +18237,7 @@ fn zirIsNonNullPtr(
1823818237 const src = inst_data.src();
1823918238 const ptr = try sema.resolveInst(inst_data.operand);
1824018239 try sema.checkNullableType(block, src, sema.typeOf(ptr).elemType2(mod));
18241 if ((try sema.resolveMaybeUndefVal(ptr)) == null) {
18240 if ((try sema.resolveValue(ptr)) == null) {
1824218241 return block.addUnOp(.is_non_null_ptr, ptr);
1824318242 }
1824418243 const loaded = try sema.analyzeLoad(block, src, ptr, src);
......@@ -18833,7 +18832,7 @@ fn analyzeRet(
1883318832
1883418833 if (block.inlining) |inlining| {
1883518834 if (block.is_comptime) {
18836 _ = try sema.resolveConstMaybeUndefVal(block, src, operand, .{
18835 _ = try sema.resolveConstValue(block, src, operand, .{
1883718836 .needed_comptime_reason = "value being returned at comptime must be comptime-known",
1883818837 });
1883918838 inlining.comptime_result = operand;
......@@ -18915,7 +18914,7 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1891518914 const ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_i]);
1891618915 extra_i += 1;
1891718916 const coerced = try sema.coerce(block, elem_ty, try sema.resolveInst(ref), sentinel_src);
18918 const val = try sema.resolveConstValue(block, sentinel_src, coerced, .{
18917 const val = try sema.resolveConstDefinedValue(block, sentinel_src, coerced, .{
1891918918 .needed_comptime_reason = "pointer sentinel value must be comptime-known",
1892018919 });
1892118920 break :blk val.toIntern();
......@@ -18925,7 +18924,7 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1892518924 const ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_i]);
1892618925 extra_i += 1;
1892718926 const coerced = try sema.coerce(block, Type.u32, try sema.resolveInst(ref), align_src);
18928 const val = try sema.resolveConstValue(block, align_src, coerced, .{
18927 const val = try sema.resolveConstDefinedValue(block, align_src, coerced, .{
1892918928 .needed_comptime_reason = "pointer alignment must be comptime-known",
1893018929 });
1893118930 // Check if this happens to be the lazy alignment of our element type, in
......@@ -19073,7 +19072,7 @@ fn zirStructInitEmptyResult(sema: *Sema, block: *Block, inst: Zir.Inst.Index, is
1907319072 const init_ref = try sema.coerce(block, init_ty, empty_ref, src);
1907419073
1907519074 if (is_byref) {
19076 const init_val = (try sema.resolveMaybeUndefVal(init_ref)).?;
19075 const init_val = (try sema.resolveValue(init_ref)).?;
1907719076 var anon_decl = try block.startAnonDecl();
1907819077 defer anon_decl.deinit();
1907919078 const decl = try anon_decl.finish(init_ty, init_val, .none);
......@@ -19158,7 +19157,7 @@ fn unionInit(
1915819157 const field_ty = mod.typeToUnion(union_ty).?.field_types.get(ip)[field_index].toType();
1915919158 const init = try sema.coerce(block, field_ty, uncasted_init, init_src);
1916019159
19161 if (try sema.resolveMaybeUndefVal(init)) |init_val| {
19160 if (try sema.resolveValue(init)) |init_val| {
1916219161 const tag_ty = union_ty.unionTagTypeHypothetical(mod);
1916319162 const tag_val = try mod.enumValueFieldIndex(tag_ty, field_index);
1916419163 return Air.internedToRef((try mod.intern(.{ .un = .{
......@@ -19247,7 +19246,7 @@ fn zirStructInit(
1924719246 const field_ty = resolved_ty.structFieldType(field_index, mod);
1924819247 field_inits[field_index] = try sema.coerce(block, field_ty, uncoerced_init, field_src);
1924919248 if (!is_packed) if (try resolved_ty.structFieldValueComptime(mod, field_index)) |default_value| {
19250 const init_val = (try sema.resolveMaybeUndefVal(field_inits[field_index])) orelse {
19249 const init_val = (try sema.resolveValue(field_inits[field_index])) orelse {
1925119250 return sema.failWithNeededComptime(block, field_src, .{
1925219251 .needed_comptime_reason = "value stored in comptime field must be comptime-known",
1925319252 });
......@@ -19292,14 +19291,14 @@ fn zirStructInit(
1929219291 const uncoerced_init_inst = try sema.resolveInst(item.data.init);
1929319292 const init_inst = try sema.coerce(block, field_ty, uncoerced_init_inst, field_src);
1929419293
19295 if (try sema.resolveMaybeUndefVal(init_inst)) |val| {
19294 if (try sema.resolveValue(init_inst)) |val| {
1929619295 const struct_val = (try mod.intern(.{ .un = .{
1929719296 .ty = resolved_ty.toIntern(),
1929819297 .tag = try tag_val.intern(tag_ty, mod),
1929919298 .val = try val.intern(field_ty, mod),
1930019299 } })).toValue();
1930119300 const final_val_inst = try sema.coerce(block, result_ty, Air.internedToRef(struct_val.toIntern()), src);
19302 const final_val = (try sema.resolveMaybeUndefVal(final_val_inst)).?;
19301 const final_val = (try sema.resolveValue(final_val_inst)).?;
1930319302 return sema.addConstantMaybeRef(block, resolved_ty, final_val, is_ref);
1930419303 }
1930519304
......@@ -19452,14 +19451,14 @@ fn finishStructInit(
1945219451 const runtime_index = opt_runtime_index orelse {
1945319452 const elems = try sema.arena.alloc(InternPool.Index, field_inits.len);
1945419453 for (elems, field_inits) |*elem, field_init| {
19455 elem.* = (sema.resolveMaybeUndefVal(field_init) catch unreachable).?.toIntern();
19454 elem.* = (sema.resolveValue(field_init) catch unreachable).?.toIntern();
1945619455 }
1945719456 const struct_val = try mod.intern(.{ .aggregate = .{
1945819457 .ty = struct_ty.toIntern(),
1945919458 .storage = .{ .elems = elems },
1946019459 } });
1946119460 const final_val_inst = try sema.coerce(block, result_ty, Air.internedToRef(struct_val), init_src);
19462 const final_val = (try sema.resolveMaybeUndefVal(final_val_inst)).?;
19461 const final_val = (try sema.resolveValue(final_val_inst)).?;
1946319462 return sema.addConstantMaybeRef(block, result_ty, final_val, is_ref);
1946419463 };
1946519464
......@@ -19592,7 +19591,7 @@ fn structInitAnon(
1959219591 };
1959319592 return sema.failWithOwnedErrorMsg(block, msg);
1959419593 }
19595 if (try sema.resolveMaybeUndefVal(init)) |init_val| {
19594 if (try sema.resolveValue(init)) |init_val| {
1959619595 values[i] = try init_val.intern(field_ty.toType(), mod);
1959719596 } else {
1959819597 values[i] = .none;
......@@ -19738,7 +19737,7 @@ fn zirArrayInit(
1973819737 else => return err,
1973919738 };
1974019739 if (is_tuple) if (try array_ty.structFieldValueComptime(mod, i)) |field_val| {
19741 const init_val = try sema.resolveMaybeUndefVal(dest.*) orelse {
19740 const init_val = try sema.resolveValue(dest.*) orelse {
1974219741 const decl = mod.declPtr(block.src_decl);
1974319742 const elem_src = mod.initSrc(src.node_offset.x, decl, i);
1974419743 return sema.failWithNeededComptime(block, elem_src, .{
......@@ -19772,14 +19771,14 @@ fn zirArrayInit(
1977219771 else
1977319772 array_ty.elemType2(mod);
1977419773 // We checked that all args are comptime above.
19775 val.* = try ((sema.resolveMaybeUndefVal(arg) catch unreachable).?).intern(elem_ty, mod);
19774 val.* = try ((sema.resolveValue(arg) catch unreachable).?).intern(elem_ty, mod);
1977619775 }
1977719776 const arr_val = try mod.intern(.{ .aggregate = .{
1977819777 .ty = array_ty.toIntern(),
1977919778 .storage = .{ .elems = elem_vals },
1978019779 } });
1978119780 const result_ref = try sema.coerce(block, result_ty, Air.internedToRef(arr_val), src);
19782 return sema.addConstantMaybeRef(block, result_ty, (try sema.resolveMaybeUndefVal(result_ref)).?, is_ref);
19781 return sema.addConstantMaybeRef(block, result_ty, (try sema.resolveValue(result_ref)).?, is_ref);
1978319782 };
1978419783
1978519784 sema.requireRuntimeBlock(block, .unneeded, null) catch |err| switch (err) {
......@@ -19877,7 +19876,7 @@ fn arrayInitAnon(
1987719876 };
1987819877 return sema.failWithOwnedErrorMsg(block, msg);
1987919878 }
19880 if (try sema.resolveMaybeUndefVal(elem)) |val| {
19879 if (try sema.resolveValue(elem)) |val| {
1988119880 values[i] = val.toIntern();
1988219881 } else {
1988319882 values[i] = .none;
......@@ -20100,7 +20099,7 @@ fn zirIntFromBool(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
2010020099 if (operand_scalar_ty.toIntern() != .bool_type) {
2010120100 return sema.fail(block, src, "expected 'bool', found '{}'", .{operand_scalar_ty.zigTypeTag(mod)});
2010220101 }
20103 if (try sema.resolveMaybeUndefVal(operand)) |val| {
20102 if (try sema.resolveValue(operand)) |val| {
2010420103 if (!is_vector) {
2010520104 if (val.isUndef(mod)) return mod.undefRef(Type.u1);
2010620105 if (val.toBool()) return Air.internedToRef((try mod.intValue(Type.u1, 1)).toIntern());
......@@ -20191,7 +20190,7 @@ fn maybeConstantUnaryMath(
2019120190) CompileError!?Air.Inst.Ref {
2019220191 const mod = sema.mod;
2019320192 switch (result_ty.zigTypeTag(mod)) {
20194 .Vector => if (try sema.resolveMaybeUndefVal(operand)) |val| {
20193 .Vector => if (try sema.resolveValue(operand)) |val| {
2019520194 const scalar_ty = result_ty.scalarType(mod);
2019620195 const vec_len = result_ty.vectorLen(mod);
2019720196 if (val.isUndef(mod))
......@@ -20207,7 +20206,7 @@ fn maybeConstantUnaryMath(
2020720206 .storage = .{ .elems = elems },
2020820207 } })));
2020920208 },
20210 else => if (try sema.resolveMaybeUndefVal(operand)) |operand_val| {
20209 else => if (try sema.resolveValue(operand)) |operand_val| {
2021120210 if (operand_val.isUndef(mod))
2021220211 return try mod.undefRef(result_ty);
2021320212 const result_val = try eval(operand_val, result_ty, sema.arena, sema.mod);
......@@ -20262,7 +20261,7 @@ fn zirTagName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
2026220261 try sema.resolveTypeLayout(operand_ty);
2026320262 const enum_ty = switch (operand_ty.zigTypeTag(mod)) {
2026420263 .EnumLiteral => {
20265 const val = try sema.resolveConstValue(block, .unneeded, operand, undefined);
20264 const val = try sema.resolveConstDefinedValue(block, .unneeded, operand, undefined);
2026620265 const tag_name = ip.indexToKey(val.toIntern()).enum_literal;
2026720266 return sema.addStrLit(ip.stringToSlice(tag_name));
2026820267 },
......@@ -20335,7 +20334,7 @@ fn zirReify(
2033520334 const uncasted_operand = try sema.resolveInst(extra.operand);
2033620335 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node };
2033720336 const type_info = try sema.coerce(block, type_info_ty, uncasted_operand, operand_src);
20338 const val = try sema.resolveConstValue(block, operand_src, type_info, .{
20337 const val = try sema.resolveConstDefinedValue(block, operand_src, type_info, .{
2033920338 .needed_comptime_reason = "operand to @Type must be comptime-known",
2034020339 });
2034120340 const union_val = ip.indexToKey(val.toIntern()).un;
......@@ -21486,7 +21485,7 @@ fn zirIntFromFloat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
2148621485 _ = try sema.checkIntType(block, src, dest_scalar_ty);
2148721486 try sema.checkFloatType(block, operand_src, operand_scalar_ty);
2148821487
21489 if (try sema.resolveMaybeUndefVal(operand)) |operand_val| {
21488 if (try sema.resolveValue(operand)) |operand_val| {
2149021489 const result_val = try sema.intFromFloat(block, operand_src, operand_val, operand_ty, dest_ty, .truncate);
2149121490 return Air.internedToRef(result_val.toIntern());
2149221491 } else if (dest_scalar_ty.zigTypeTag(mod) == .ComptimeInt) {
......@@ -21568,7 +21567,7 @@ fn zirFloatFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
2156821567 try sema.checkFloatType(block, src, dest_scalar_ty);
2156921568 _ = try sema.checkIntType(block, operand_src, operand_scalar_ty);
2157021569
21571 if (try sema.resolveMaybeUndefVal(operand)) |operand_val| {
21570 if (try sema.resolveValue(operand)) |operand_val| {
2157221571 const result_val = try operand_val.floatFromIntAdvanced(sema.arena, operand_ty, dest_ty, mod, sema);
2157321572 return Air.internedToRef(result_val.toIntern());
2157421573 } else if (dest_scalar_ty.zigTypeTag(mod) == .ComptimeFloat) {
......@@ -22158,7 +22157,7 @@ fn ptrCastFull(
2215822157
2215922158 // Cannot do @addrSpaceCast at comptime
2216022159 if (!flags.addrspace_cast) {
22161 if (try sema.resolveMaybeUndefVal(ptr)) |ptr_val| {
22160 if (try sema.resolveValue(ptr)) |ptr_val| {
2216222161 if (!dest_ty.ptrAllowsZero(mod) and ptr_val.isUndef(mod)) {
2216322162 return sema.failWithUseOfUndef(block, operand_src);
2216422163 }
......@@ -22286,7 +22285,7 @@ fn zirPtrCastNoDest(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.Inst
2228622285 if (flags.volatile_cast) ptr_info.flags.is_volatile = false;
2228722286 const dest_ty = try sema.ptrType(ptr_info);
2228822287
22289 if (try sema.resolveMaybeUndefVal(operand)) |operand_val| {
22288 if (try sema.resolveValue(operand)) |operand_val| {
2229022289 return Air.internedToRef((try mod.getCoerced(operand_val, dest_ty)).toIntern());
2229122290 }
2229222291
......@@ -22356,7 +22355,7 @@ fn zirTruncate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
2235622355 }
2235722356 }
2235822357
22359 if (try sema.resolveMaybeUndefValIntable(operand)) |val| {
22358 if (try sema.resolveValueIntable(operand)) |val| {
2236022359 if (val.isUndef(mod)) return mod.undefRef(dest_ty);
2236122360 if (!dest_is_vector) {
2236222361 return Air.internedToRef((try mod.getCoerced(
......@@ -22407,7 +22406,7 @@ fn zirBitCount(
2240722406 .len = vec_len,
2240822407 .child = result_scalar_ty.toIntern(),
2240922408 });
22410 if (try sema.resolveMaybeUndefVal(operand)) |val| {
22409 if (try sema.resolveValue(operand)) |val| {
2241122410 if (val.isUndef(mod)) return mod.undefRef(result_ty);
2241222411
2241322412 const elems = try sema.arena.alloc(InternPool.Index, vec_len);
......@@ -22427,7 +22426,7 @@ fn zirBitCount(
2242722426 }
2242822427 },
2242922428 .Int => {
22430 if (try sema.resolveMaybeUndefLazyVal(operand)) |val| {
22429 if (try sema.resolveValueResolveLazy(operand)) |val| {
2243122430 if (val.isUndef(mod)) return mod.undefRef(result_scalar_ty);
2243222431 return mod.intRef(result_scalar_ty, comptimeOp(val, operand_ty, mod));
2243322432 } else {
......@@ -22463,7 +22462,7 @@ fn zirByteSwap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
2246322462
2246422463 switch (operand_ty.zigTypeTag(mod)) {
2246522464 .Int => {
22466 const runtime_src = if (try sema.resolveMaybeUndefVal(operand)) |val| {
22465 const runtime_src = if (try sema.resolveValue(operand)) |val| {
2246722466 if (val.isUndef(mod)) return mod.undefRef(operand_ty);
2246822467 const result_val = try val.byteSwap(operand_ty, mod, sema.arena);
2246922468 return Air.internedToRef(result_val.toIntern());
......@@ -22473,7 +22472,7 @@ fn zirByteSwap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
2247322472 return block.addTyOp(.byte_swap, operand_ty, operand);
2247422473 },
2247522474 .Vector => {
22476 const runtime_src = if (try sema.resolveMaybeUndefVal(operand)) |val| {
22475 const runtime_src = if (try sema.resolveValue(operand)) |val| {
2247722476 if (val.isUndef(mod))
2247822477 return mod.undefRef(operand_ty);
2247922478
......@@ -22511,7 +22510,7 @@ fn zirBitReverse(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
2251122510 const mod = sema.mod;
2251222511 switch (operand_ty.zigTypeTag(mod)) {
2251322512 .Int => {
22514 const runtime_src = if (try sema.resolveMaybeUndefVal(operand)) |val| {
22513 const runtime_src = if (try sema.resolveValue(operand)) |val| {
2251522514 if (val.isUndef(mod)) return mod.undefRef(operand_ty);
2251622515 const result_val = try val.bitReverse(operand_ty, mod, sema.arena);
2251722516 return Air.internedToRef(result_val.toIntern());
......@@ -22521,7 +22520,7 @@ fn zirBitReverse(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
2252122520 return block.addTyOp(.bit_reverse, operand_ty, operand);
2252222521 },
2252322522 .Vector => {
22524 const runtime_src = if (try sema.resolveMaybeUndefVal(operand)) |val| {
22523 const runtime_src = if (try sema.resolveValue(operand)) |val| {
2252522524 if (val.isUndef(mod))
2252622525 return mod.undefRef(operand_ty);
2252722526
......@@ -22967,8 +22966,8 @@ fn checkSimdBinOp(
2296722966 .len = vec_len,
2296822967 .lhs = lhs,
2296922968 .rhs = rhs,
22970 .lhs_val = try sema.resolveMaybeUndefVal(lhs),
22971 .rhs_val = try sema.resolveMaybeUndefVal(rhs),
22969 .lhs_val = try sema.resolveValue(lhs),
22970 .rhs_val = try sema.resolveValue(rhs),
2297222971 .result_ty = result_ty,
2297322972 .scalar_ty = result_ty.scalarType(mod),
2297422973 };
......@@ -23054,20 +23053,20 @@ fn resolveExportOptions(
2305423053 const visibility_src = sema.maybeOptionsSrc(block, src, "visibility");
2305523054
2305623055 const name_operand = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "name"), name_src);
23057 const name_val = try sema.resolveConstValue(block, name_src, name_operand, .{
23056 const name_val = try sema.resolveConstDefinedValue(block, name_src, name_operand, .{
2305823057 .needed_comptime_reason = "name of exported value must be comptime-known",
2305923058 });
2306023059 const name_ty = Type.slice_const_u8;
2306123060 const name = try name_val.toAllocatedBytes(name_ty, sema.arena, mod);
2306223061
2306323062 const linkage_operand = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "linkage"), linkage_src);
23064 const linkage_val = try sema.resolveConstValue(block, linkage_src, linkage_operand, .{
23063 const linkage_val = try sema.resolveConstDefinedValue(block, linkage_src, linkage_operand, .{
2306523064 .needed_comptime_reason = "linkage of exported value must be comptime-known",
2306623065 });
2306723066 const linkage = mod.toEnum(std.builtin.GlobalLinkage, linkage_val);
2306823067
2306923068 const section_operand = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "section"), section_src);
23070 const section_opt_val = try sema.resolveConstValue(block, section_src, section_operand, .{
23069 const section_opt_val = try sema.resolveConstDefinedValue(block, section_src, section_operand, .{
2307123070 .needed_comptime_reason = "linksection of exported value must be comptime-known",
2307223071 });
2307323072 const section_ty = Type.slice_const_u8;
......@@ -23077,7 +23076,7 @@ fn resolveExportOptions(
2307723076 null;
2307823077
2307923078 const visibility_operand = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "visibility"), visibility_src);
23080 const visibility_val = try sema.resolveConstValue(block, visibility_src, visibility_operand, .{
23079 const visibility_val = try sema.resolveConstDefinedValue(block, visibility_src, visibility_operand, .{
2308123080 .needed_comptime_reason = "visibility of exported value must be comptime-known",
2308223081 });
2308323082 const visibility = mod.toEnum(std.builtin.SymbolVisibility, visibility_val);
......@@ -23112,7 +23111,7 @@ fn resolveBuiltinEnum(
2311223111 const ty = try sema.getBuiltinType(name);
2311323112 const air_ref = try sema.resolveInst(zir_ref);
2311423113 const coerced = try sema.coerce(block, ty, air_ref, src);
23115 const val = try sema.resolveConstValue(block, src, coerced, reason);
23114 const val = try sema.resolveConstDefinedValue(block, src, coerced, reason);
2311623115 return mod.toEnum(@field(std.builtin, name), val);
2311723116}
2311823117
......@@ -23202,8 +23201,8 @@ fn zirCmpxchg(
2320223201 }
2320323202
2320423203 const runtime_src = if (try sema.resolveDefinedValue(block, ptr_src, ptr)) |ptr_val| rs: {
23205 if (try sema.resolveMaybeUndefVal(expected_value)) |expected_val| {
23206 if (try sema.resolveMaybeUndefVal(new_value)) |new_val| {
23204 if (try sema.resolveValue(expected_value)) |expected_val| {
23205 if (try sema.resolveValue(new_value)) |new_val| {
2320723206 if (expected_val.isUndef(mod) or new_val.isUndef(mod)) {
2320823207 // TODO: this should probably cause the memory stored at the pointer
2320923208 // to become undef as well
......@@ -23254,7 +23253,7 @@ fn zirSplat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.I
2325423253 const operand = try sema.resolveInst(extra.rhs);
2325523254 const scalar_ty = dest_ty.childType(mod);
2325623255 const scalar = try sema.coerce(block, scalar_ty, operand, scalar_src);
23257 if (try sema.resolveMaybeUndefVal(scalar)) |scalar_val| {
23256 if (try sema.resolveValue(scalar)) |scalar_val| {
2325823257 if (scalar_val.isUndef(mod)) return mod.undefRef(dest_ty);
2325923258 return Air.internedToRef((try sema.splat(dest_ty, scalar_val)).toIntern());
2326023259 }
......@@ -23304,7 +23303,7 @@ fn zirReduce(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
2330423303 return sema.fail(block, operand_src, "@reduce operation requires a vector with nonzero length", .{});
2330523304 }
2330623305
23307 if (try sema.resolveMaybeUndefVal(operand)) |operand_val| {
23306 if (try sema.resolveValue(operand)) |operand_val| {
2330823307 if (operand_val.isUndef(mod)) return mod.undefRef(scalar_ty);
2330923308
2331023309 var accum: Value = try operand_val.elemValue(mod, 0);
......@@ -23357,7 +23356,7 @@ fn zirShuffle(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
2335723356 .child = .i32_type,
2335823357 });
2335923358 mask = try sema.coerce(block, mask_ty, mask, mask_src);
23360 const mask_val = try sema.resolveConstMaybeUndefVal(block, mask_src, mask, .{
23359 const mask_val = try sema.resolveConstValue(block, mask_src, mask, .{
2336123360 .needed_comptime_reason = "shuffle mask must be comptime-known",
2336223361 });
2336323362 return sema.analyzeShuffle(block, inst_data.src_node, elem_ty, a, b, mask_val, @intCast(mask_len));
......@@ -23457,8 +23456,8 @@ fn analyzeShuffle(
2345723456 }
2345823457 }
2345923458
23460 if (try sema.resolveMaybeUndefVal(a)) |a_val| {
23461 if (try sema.resolveMaybeUndefVal(b)) |b_val| {
23459 if (try sema.resolveValue(a)) |a_val| {
23460 if (try sema.resolveValue(b)) |b_val| {
2346223461 const values = try sema.arena.alloc(InternPool.Index, mask_len);
2346323462 for (values, 0..) |*value, i| {
2346423463 const mask_elem_val = try mask.elemValue(sema.mod, i);
......@@ -23556,9 +23555,9 @@ fn zirSelect(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) C
2355623555 const a = try sema.coerce(block, vec_ty, try sema.resolveInst(extra.a), a_src);
2355723556 const b = try sema.coerce(block, vec_ty, try sema.resolveInst(extra.b), b_src);
2355823557
23559 const maybe_pred = try sema.resolveMaybeUndefVal(pred);
23560 const maybe_a = try sema.resolveMaybeUndefVal(a);
23561 const maybe_b = try sema.resolveMaybeUndefVal(b);
23558 const maybe_pred = try sema.resolveValue(pred);
23559 const maybe_a = try sema.resolveValue(a);
23560 const maybe_b = try sema.resolveValue(b);
2356223561
2356323562 const runtime_src = if (maybe_pred) |pred_val| rs: {
2356423563 if (pred_val.isUndef(mod)) return mod.undefRef(vec_ty);
......@@ -23704,7 +23703,7 @@ fn zirAtomicRmw(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
2370423703 }
2370523704
2370623705 const runtime_src = if (try sema.resolveDefinedValue(block, ptr_src, ptr)) |ptr_val| rs: {
23707 const maybe_operand_val = try sema.resolveMaybeUndefVal(operand);
23706 const maybe_operand_val = try sema.resolveValue(operand);
2370823707 const operand_val = maybe_operand_val orelse {
2370923708 try sema.checkPtrIsNotComptimeMutable(block, ptr_val, ptr_src, operand_src);
2371023709 break :rs operand_src;
......@@ -23795,9 +23794,9 @@ fn zirMulAdd(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
2379523794 const mulend1 = try sema.coerce(block, ty, try sema.resolveInst(extra.mulend1), mulend1_src);
2379623795 const mulend2 = try sema.coerce(block, ty, try sema.resolveInst(extra.mulend2), mulend2_src);
2379723796
23798 const maybe_mulend1 = try sema.resolveMaybeUndefVal(mulend1);
23799 const maybe_mulend2 = try sema.resolveMaybeUndefVal(mulend2);
23800 const maybe_addend = try sema.resolveMaybeUndefVal(addend);
23797 const maybe_mulend1 = try sema.resolveValue(mulend1);
23798 const maybe_mulend2 = try sema.resolveValue(mulend2);
23799 const maybe_addend = try sema.resolveValue(addend);
2380123800 const mod = sema.mod;
2380223801
2380323802 switch (ty.scalarType(mod).zigTypeTag(mod)) {
......@@ -23862,7 +23861,7 @@ fn zirBuiltinCall(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
2386223861 const modifier_ty = try sema.getBuiltinType("CallModifier");
2386323862 const air_ref = try sema.resolveInst(extra.modifier);
2386423863 const modifier_ref = try sema.coerce(block, modifier_ty, air_ref, modifier_src);
23865 const modifier_val = try sema.resolveConstValue(block, modifier_src, modifier_ref, .{
23864 const modifier_val = try sema.resolveConstDefinedValue(block, modifier_src, modifier_ref, .{
2386623865 .needed_comptime_reason = "call modifier must be comptime-known",
2386723866 });
2386823867 var modifier = mod.toEnum(std.builtin.CallModifier, modifier_val);
......@@ -24146,7 +24145,7 @@ fn analyzeMinMax(
2414624145 for (operands, operand_srcs, 0..) |operand, operand_src, operand_idx| {
2414724146 // Resolve the value now to avoid redundant calls to `checkSimdBinOp` - we'll have to call
2414824147 // it in the runtime path anyway since the result type may have been refined
24149 const unresolved_uncoerced_val = try sema.resolveMaybeUndefVal(operand) orelse continue;
24148 const unresolved_uncoerced_val = try sema.resolveValue(operand) orelse continue;
2415024149 const uncoerced_val = try sema.resolveLazyValue(unresolved_uncoerced_val);
2415124150
2415224151 runtime_known.unset(operand_idx);
......@@ -24222,7 +24221,7 @@ fn analyzeMinMax(
2422224221 // as possible will allow us to emit more optimal AIR (if all the runtime operands have
2422324222 // smaller types than the non-refined comptime type).
2422424223
24225 const val = (try sema.resolveMaybeUndefVal(ct_minmax_ref)).?;
24224 const val = (try sema.resolveValue(ct_minmax_ref)).?;
2422624225 const orig_ty = sema.typeOf(ct_minmax_ref);
2422724226
2422824227 if (opt_runtime_idx == null and orig_ty.scalarType(mod).eql(Type.comptime_int, mod)) {
......@@ -24257,7 +24256,7 @@ fn analyzeMinMax(
2425724256
2425824257 // If the comptime-known part is undef we can avoid emitting actual instructions later
2425924258 const known_undef = if (cur_minmax) |operand| blk: {
24260 const val = (try sema.resolveMaybeUndefVal(operand)).?;
24259 const val = (try sema.resolveValue(operand)).?;
2426124260 break :blk val.isUndef(mod);
2426224261 } else false;
2426324262
......@@ -24631,7 +24630,7 @@ fn zirMemset(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void
2463124630 }
2463224631
2463324632 if (!ptr_val.isComptimeMutablePtr(mod)) break :rs dest_src;
24634 const elem_val = try sema.resolveMaybeUndefVal(elem) orelse break :rs value_src;
24633 const elem_val = try sema.resolveValue(elem) orelse break :rs value_src;
2463524634 const array_ty = try mod.arrayType(.{
2463624635 .child = dest_elem_ty.toIntern(),
2463724636 .len = len_u64,
......@@ -24736,7 +24735,7 @@ fn zirVarExtended(
2473624735 else
2473724736 uncasted_init;
2473824737
24739 break :blk ((try sema.resolveMaybeUndefVal(init)) orelse {
24738 break :blk ((try sema.resolveValue(init)) orelse {
2474024739 return sema.failWithNeededComptime(block, init_src, .{
2474124740 .needed_comptime_reason = "container level variable initializers must be comptime-known",
2474224741 });
......@@ -25097,17 +25096,17 @@ fn resolvePrefetchOptions(
2509725096 const cache_src = sema.maybeOptionsSrc(block, src, "cache");
2509825097
2509925098 const rw = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "rw"), rw_src);
25100 const rw_val = try sema.resolveConstValue(block, rw_src, rw, .{
25099 const rw_val = try sema.resolveConstDefinedValue(block, rw_src, rw, .{
2510125100 .needed_comptime_reason = "prefetch read/write must be comptime-known",
2510225101 });
2510325102
2510425103 const locality = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "locality"), locality_src);
25105 const locality_val = try sema.resolveConstValue(block, locality_src, locality, .{
25104 const locality_val = try sema.resolveConstDefinedValue(block, locality_src, locality, .{
2510625105 .needed_comptime_reason = "prefetch locality must be comptime-known",
2510725106 });
2510825107
2510925108 const cache = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "cache"), cache_src);
25110 const cache_val = try sema.resolveConstValue(block, cache_src, cache, .{
25109 const cache_val = try sema.resolveConstDefinedValue(block, cache_src, cache, .{
2511125110 .needed_comptime_reason = "prefetch cache must be comptime-known",
2511225111 });
2511325112
......@@ -25176,24 +25175,24 @@ fn resolveExternOptions(
2517625175 const thread_local_src = sema.maybeOptionsSrc(block, src, "thread_local");
2517725176
2517825177 const name_ref = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "name"), name_src);
25179 const name_val = try sema.resolveConstValue(block, name_src, name_ref, .{
25178 const name_val = try sema.resolveConstDefinedValue(block, name_src, name_ref, .{
2518025179 .needed_comptime_reason = "name of the extern symbol must be comptime-known",
2518125180 });
2518225181 const name = try name_val.toAllocatedBytes(Type.slice_const_u8, sema.arena, mod);
2518325182
2518425183 const library_name_inst = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "library_name"), library_src);
25185 const library_name_val = try sema.resolveConstValue(block, library_src, library_name_inst, .{
25184 const library_name_val = try sema.resolveConstDefinedValue(block, library_src, library_name_inst, .{
2518625185 .needed_comptime_reason = "library in which extern symbol is must be comptime-known",
2518725186 });
2518825187
2518925188 const linkage_ref = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "linkage"), linkage_src);
25190 const linkage_val = try sema.resolveConstValue(block, linkage_src, linkage_ref, .{
25189 const linkage_val = try sema.resolveConstDefinedValue(block, linkage_src, linkage_ref, .{
2519125190 .needed_comptime_reason = "linkage of the extern symbol must be comptime-known",
2519225191 });
2519325192 const linkage = mod.toEnum(std.builtin.GlobalLinkage, linkage_val);
2519425193
2519525194 const is_thread_local = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "is_thread_local"), thread_local_src);
25196 const is_thread_local_val = try sema.resolveConstValue(block, thread_local_src, is_thread_local, .{
25195 const is_thread_local_val = try sema.resolveConstDefinedValue(block, thread_local_src, is_thread_local, .{
2519725196 .needed_comptime_reason = "threadlocality of the extern symbol must be comptime-known",
2519825197 });
2519925198
......@@ -26419,7 +26418,7 @@ fn fieldPtr(
2641926418 }
2642026419 },
2642126420 .Type => {
26422 _ = try sema.resolveConstValue(block, .unneeded, object_ptr, undefined);
26421 _ = try sema.resolveConstDefinedValue(block, .unneeded, object_ptr, undefined);
2642326422 const result = try sema.analyzeLoad(block, src, object_ptr, object_ptr_src);
2642426423 const inner = if (is_pointer_to)
2642526424 try sema.analyzeLoad(block, src, result, object_ptr_src)
......@@ -26991,7 +26990,7 @@ fn structFieldVal(
2699126990
2699226991 const field_ty = struct_type.field_types.get(ip)[field_index].toType();
2699326992
26994 if (try sema.resolveMaybeUndefVal(struct_byval)) |struct_val| {
26993 if (try sema.resolveValue(struct_byval)) |struct_val| {
2699526994 if (struct_val.isUndef(mod)) return mod.undefRef(field_ty);
2699626995 if ((try sema.typeHasOnePossibleValue(field_ty))) |opv| {
2699726996 return Air.internedToRef(opv.toIntern());
......@@ -27069,7 +27068,7 @@ fn tupleFieldValByIndex(
2706927068 return Air.internedToRef(default_value.toIntern());
2707027069 }
2707127070
27072 if (try sema.resolveMaybeUndefVal(tuple_byval)) |tuple_val| {
27071 if (try sema.resolveValue(tuple_byval)) |tuple_val| {
2707327072 if ((try sema.typeHasOnePossibleValue(field_ty))) |opv| {
2707427073 return Air.internedToRef(opv.toIntern());
2707527074 }
......@@ -27221,7 +27220,7 @@ fn unionFieldVal(
2722127220 const field_ty = union_obj.field_types.get(ip)[field_index].toType();
2722227221 const enum_field_index: u32 = @intCast(union_obj.enum_tag_ty.toType().enumFieldIndex(field_name, mod).?);
2722327222
27224 if (try sema.resolveMaybeUndefVal(union_byval)) |union_val| {
27223 if (try sema.resolveValue(union_byval)) |union_val| {
2722527224 if (union_val.isUndef(mod)) return mod.undefRef(field_ty);
2722627225
2722727226 const un = ip.indexToKey(union_val.toIntern()).un;
......@@ -27303,7 +27302,7 @@ fn elemPtr(
2730327302 .Array, .Vector => try sema.elemPtrArray(block, src, indexable_ptr_src, indexable_ptr, elem_index_src, elem_index, init, oob_safety),
2730427303 .Struct => blk: {
2730527304 // Tuple field access.
27306 const index_val = try sema.resolveConstValue(block, elem_index_src, elem_index, .{
27305 const index_val = try sema.resolveConstDefinedValue(block, elem_index_src, elem_index, .{
2730727306 .needed_comptime_reason = "tuple field access index must be comptime-known",
2730827307 });
2730927308 const index: u32 = @intCast(index_val.toUnsignedInt(mod));
......@@ -27360,7 +27359,7 @@ fn elemPtrOneLayerOnly(
2736027359 .Array, .Vector => try sema.elemPtrArray(block, src, indexable_src, indexable, elem_index_src, elem_index, init, oob_safety),
2736127360 .Struct => blk: {
2736227361 assert(child_ty.isTuple(mod));
27363 const index_val = try sema.resolveConstValue(block, elem_index_src, elem_index, .{
27362 const index_val = try sema.resolveConstDefinedValue(block, elem_index_src, elem_index, .{
2736427363 .needed_comptime_reason = "tuple field access index must be comptime-known",
2736527364 });
2736627365 const index: u32 = @intCast(index_val.toUnsignedInt(mod));
......@@ -27439,7 +27438,7 @@ fn elemVal(
2743927438 },
2744027439 .Struct => {
2744127440 // Tuple field access.
27442 const index_val = try sema.resolveConstValue(block, elem_index_src, elem_index, .{
27441 const index_val = try sema.resolveConstDefinedValue(block, elem_index_src, elem_index, .{
2744327442 .needed_comptime_reason = "tuple field access index must be comptime-known",
2744427443 });
2744527444 const index: u32 = @intCast(index_val.toUnsignedInt(mod));
......@@ -27519,7 +27518,7 @@ fn tupleFieldPtr(
2751927518 } })));
2752027519 }
2752127520
27522 if (try sema.resolveMaybeUndefVal(tuple_ptr)) |tuple_ptr_val| {
27521 if (try sema.resolveValue(tuple_ptr)) |tuple_ptr_val| {
2752327522 return Air.internedToRef((try mod.intern(.{ .ptr = .{
2752427523 .ty = ptr_field_ty.toIntern(),
2752527524 .addr = .{ .field = .{
......@@ -27566,7 +27565,7 @@ fn tupleField(
2756627565 return Air.internedToRef(default_value.toIntern()); // comptime field
2756727566 }
2756827567
27569 if (try sema.resolveMaybeUndefVal(tuple)) |tuple_val| {
27568 if (try sema.resolveValue(tuple)) |tuple_val| {
2757027569 if (tuple_val.isUndef(mod)) return mod.undefRef(field_ty);
2757127570 return Air.internedToRef((try tuple_val.fieldValue(mod, field_index)).toIntern());
2757227571 }
......@@ -27599,7 +27598,7 @@ fn elemValArray(
2759927598 return sema.fail(block, array_src, "indexing into empty array is not allowed", .{});
2760027599 }
2760127600
27602 const maybe_undef_array_val = try sema.resolveMaybeUndefVal(array);
27601 const maybe_undef_array_val = try sema.resolveValue(array);
2760327602 // index must be defined since it can access out of bounds
2760427603 const maybe_index_val = try sema.resolveDefinedValue(block, elem_index_src, elem_index);
2760527604
......@@ -27664,7 +27663,7 @@ fn elemPtrArray(
2766427663 return sema.fail(block, array_ptr_src, "indexing into empty array is not allowed", .{});
2766527664 }
2766627665
27667 const maybe_undef_array_ptr_val = try sema.resolveMaybeUndefVal(array_ptr);
27666 const maybe_undef_array_ptr_val = try sema.resolveValue(array_ptr);
2766827667 // The index must not be undefined since it can be out of bounds.
2766927668 const offset: ?usize = if (try sema.resolveDefinedValue(block, elem_index_src, elem_index)) |index_val| o: {
2767027669 const index = try sema.usizeCast(block, elem_index_src, index_val.toUnsignedInt(mod));
......@@ -27776,7 +27775,7 @@ fn elemPtrSlice(
2777627775 const slice_ty = sema.typeOf(slice);
2777727776 const slice_sent = slice_ty.sentinel(mod) != null;
2777827777
27779 const maybe_undef_slice_val = try sema.resolveMaybeUndefVal(slice);
27778 const maybe_undef_slice_val = try sema.resolveValue(slice);
2778027779 // The index must not be undefined since it can be out of bounds.
2778127780 const offset: ?usize = if (try sema.resolveDefinedValue(block, elem_index_src, elem_index)) |index_val| o: {
2778227781 const index = try sema.usizeCast(block, elem_index_src, index_val.toUnsignedInt(mod));
......@@ -27888,7 +27887,7 @@ fn coerceExtra(
2788827887 if (dest_ty.eql(inst_ty, mod))
2788927888 return inst;
2789027889
27891 const maybe_inst_val = try sema.resolveMaybeUndefVal(inst);
27890 const maybe_inst_val = try sema.resolveValue(inst);
2789227891
2789327892 var in_memory_result = try sema.coerceInMemoryAllowed(block, dest_ty, inst_ty, false, target, dest_ty_src, inst_src);
2789427893 if (in_memory_result == .ok) {
......@@ -27958,7 +27957,7 @@ fn coerceExtra(
2795827957
2795927958 // Function body to function pointer.
2796027959 if (inst_ty.zigTypeTag(mod) == .Fn) {
27961 const fn_val = try sema.resolveConstValue(block, .unneeded, inst, undefined);
27960 const fn_val = try sema.resolveConstDefinedValue(block, .unneeded, inst, undefined);
2796227961 const fn_decl = fn_val.pointerDecl(mod).?;
2796327962 const inst_as_ptr = try sema.analyzeDeclRef(fn_decl);
2796427963 return sema.coerce(block, dest_ty, inst_as_ptr, inst_src);
......@@ -28303,7 +28302,7 @@ fn coerceExtra(
2830328302 },
2830428303 .Float, .ComptimeFloat => switch (inst_ty.zigTypeTag(mod)) {
2830528304 .ComptimeFloat => {
28306 const val = try sema.resolveConstValue(block, .unneeded, inst, undefined);
28305 const val = try sema.resolveConstDefinedValue(block, .unneeded, inst, undefined);
2830728306 const result_val = try val.floatCast(dest_ty, mod);
2830828307 return Air.internedToRef(result_val.toIntern());
2830928308 },
......@@ -28362,7 +28361,7 @@ fn coerceExtra(
2836228361 .Enum => switch (inst_ty.zigTypeTag(mod)) {
2836328362 .EnumLiteral => {
2836428363 // enum literal to enum
28365 const val = try sema.resolveConstValue(block, .unneeded, inst, undefined);
28364 const val = try sema.resolveConstDefinedValue(block, .unneeded, inst, undefined);
2836628365 const string = mod.intern_pool.indexToKey(val.toIntern()).enum_literal;
2836728366 const field_index = dest_ty.enumFieldIndex(string, mod) orelse {
2836828367 const msg = msg: {
......@@ -29490,7 +29489,7 @@ fn coerceVarArgParam(
2949029489 .{},
2949129490 ),
2949229491 .Fn => blk: {
29493 const fn_val = try sema.resolveConstValue(block, .unneeded, inst, undefined);
29492 const fn_val = try sema.resolveConstDefinedValue(block, .unneeded, inst, undefined);
2949429493 const fn_decl = fn_val.pointerDecl(mod).?;
2949529494 break :blk try sema.analyzeDeclRef(fn_decl);
2949629495 },
......@@ -29602,7 +29601,7 @@ fn storePtr2(
2960229601 error.NotCoercible => unreachable,
2960329602 else => |e| return e,
2960429603 };
29605 const maybe_operand_val = try sema.resolveMaybeUndefVal(operand);
29604 const maybe_operand_val = try sema.resolveValue(operand);
2960629605
2960729606 const runtime_src = if (try sema.resolveDefinedValue(block, ptr_src, ptr)) |ptr_val| rs: {
2960829607 const operand_val = maybe_operand_val orelse {
......@@ -29670,7 +29669,7 @@ fn checkComptimeKnownStore(sema: *Sema, block: *Block, store_inst_ref: Air.Inst.
2967029669 const maybe_comptime_alloc = sema.maybe_comptime_allocs.getPtr(maybe_base_alloc) orelse return;
2967129670
2967229671 ct: {
29673 if (null == try sema.resolveMaybeUndefVal(operand)) break :ct;
29672 if (null == try sema.resolveValue(operand)) break :ct;
2967429673 if (maybe_comptime_alloc.runtime_index != block.runtime_index) break :ct;
2967529674 return maybe_comptime_alloc.stores.append(sema.arena, store_inst);
2967629675 }
......@@ -29701,7 +29700,7 @@ fn checkKnownAllocPtr(sema: *Sema, base_ptr: Air.Inst.Ref, new_ptr: Air.Inst.Ref
2970129700
2970229701 // If the index value is runtime-known, this pointer is also runtime-known, so
2970329702 // we must in turn make the alloc value runtime-known.
29704 if (null == try sema.resolveMaybeUndefVal(index_ref)) {
29703 if (null == try sema.resolveValue(index_ref)) {
2970529704 _ = sema.maybe_comptime_allocs.remove(alloc_inst);
2970629705 }
2970729706 },
......@@ -30711,7 +30710,7 @@ fn bitCast(
3071130710 });
3071230711 }
3071330712
30714 if (try sema.resolveMaybeUndefVal(inst)) |val| {
30713 if (try sema.resolveValue(inst)) |val| {
3071530714 if (try sema.bitCastVal(block, inst_src, val, old_ty, dest_ty, 0)) |result_val| {
3071630715 return Air.internedToRef(result_val.toIntern());
3071730716 }
......@@ -30817,7 +30816,7 @@ fn coerceArrayPtrToSlice(
3081730816 inst_src: LazySrcLoc,
3081830817) CompileError!Air.Inst.Ref {
3081930818 const mod = sema.mod;
30820 if (try sema.resolveMaybeUndefVal(inst)) |val| {
30819 if (try sema.resolveValue(inst)) |val| {
3082130820 const ptr_array_ty = sema.typeOf(inst);
3082230821 const array_ty = ptr_array_ty.childType(mod);
3082330822 const slice_val = try mod.intern(.{ .ptr = .{
......@@ -30895,7 +30894,7 @@ fn coerceCompatiblePtrs(
3089530894) !Air.Inst.Ref {
3089630895 const mod = sema.mod;
3089730896 const inst_ty = sema.typeOf(inst);
30898 if (try sema.resolveMaybeUndefVal(inst)) |val| {
30897 if (try sema.resolveValue(inst)) |val| {
3089930898 if (!val.isUndef(mod) and val.isNull(mod) and !dest_ty.isAllowzeroPtr(mod)) {
3090030899 return sema.fail(block, inst_src, "null pointer casted to type '{}'", .{dest_ty.fmt(sema.mod)});
3090130900 }
......@@ -31178,7 +31177,7 @@ fn coerceArrayLike(
3117831177 // try coercion of the whole array
3117931178 const in_memory_result = try sema.coerceInMemoryAllowed(block, dest_ty, inst_ty, false, target, dest_ty_src, inst_src);
3118031179 if (in_memory_result == .ok) {
31181 if (try sema.resolveMaybeUndefVal(inst)) |inst_val| {
31180 if (try sema.resolveValue(inst)) |inst_val| {
3118231181 // These types share the same comptime value representation.
3118331182 return sema.coerceInMemory(inst_val, dest_ty);
3118431183 }
......@@ -31215,7 +31214,7 @@ fn coerceArrayLike(
3121531214 const coerced = try sema.coerce(block, dest_elem_ty, elem_ref, elem_src);
3121631215 ref.* = coerced;
3121731216 if (runtime_src == null) {
31218 if (try sema.resolveMaybeUndefVal(coerced)) |elem_val| {
31217 if (try sema.resolveValue(coerced)) |elem_val| {
3121931218 val.* = try elem_val.intern(dest_elem_ty, mod);
3122031219 } else {
3122131220 runtime_src = elem_src;
......@@ -31280,7 +31279,7 @@ fn coerceTupleToArray(
3128031279 const coerced = try sema.coerce(block, dest_elem_ty, elem_ref, elem_src);
3128131280 ref.* = coerced;
3128231281 if (runtime_src == null) {
31283 if (try sema.resolveMaybeUndefVal(coerced)) |elem_val| {
31282 if (try sema.resolveValue(coerced)) |elem_val| {
3128431283 val.* = try elem_val.intern(dest_elem_ty, mod);
3128531284 } else {
3128631285 runtime_src = elem_src;
......@@ -31393,7 +31392,7 @@ fn coerceTupleToStruct(
3139331392 const coerced = try sema.coerce(block, field_ty, elem_ref, field_src);
3139431393 field_refs[field_index] = coerced;
3139531394 if (struct_type.fieldIsComptime(ip, field_index)) {
31396 const init_val = (try sema.resolveMaybeUndefVal(coerced)) orelse {
31395 const init_val = (try sema.resolveValue(coerced)) orelse {
3139731396 return sema.failWithNeededComptime(block, field_src, .{
3139831397 .needed_comptime_reason = "value stored in comptime field must be comptime-known",
3139931398 });
......@@ -31405,7 +31404,7 @@ fn coerceTupleToStruct(
3140531404 }
3140631405 }
3140731406 if (runtime_src == null) {
31408 if (try sema.resolveMaybeUndefVal(coerced)) |field_val| {
31407 if (try sema.resolveValue(coerced)) |field_val| {
3140931408 field_vals[field_index] = field_val.toIntern();
3141031409 } else {
3141131410 runtime_src = field_src;
......@@ -31521,7 +31520,7 @@ fn coerceTupleToTuple(
3152131520 const coerced = try sema.coerce(block, field_ty.toType(), elem_ref, field_src);
3152231521 field_refs[field_index] = coerced;
3152331522 if (default_val != .none) {
31524 const init_val = (try sema.resolveMaybeUndefVal(coerced)) orelse {
31523 const init_val = (try sema.resolveValue(coerced)) orelse {
3152531524 return sema.failWithNeededComptime(block, field_src, .{
3152631525 .needed_comptime_reason = "value stored in comptime field must be comptime-known",
3152731526 });
......@@ -31532,7 +31531,7 @@ fn coerceTupleToTuple(
3153231531 }
3153331532 }
3153431533 if (runtime_src == null) {
31535 if (try sema.resolveMaybeUndefVal(coerced)) |field_val| {
31534 if (try sema.resolveValue(coerced)) |field_val| {
3153631535 field_vals[field_index] = field_val.toIntern();
3153731536 } else {
3153831537 runtime_src = field_src;
......@@ -31753,7 +31752,7 @@ fn analyzeRef(
3175331752 const mod = sema.mod;
3175431753 const operand_ty = sema.typeOf(operand);
3175531754
31756 if (try sema.resolveMaybeUndefVal(operand)) |val| {
31755 if (try sema.resolveValue(operand)) |val| {
3175731756 switch (mod.intern_pool.indexToKey(val.toIntern())) {
3175831757 .extern_func => |extern_func| return sema.analyzeDeclRef(extern_func.decl),
3175931758 .func => |func| return sema.analyzeDeclRef(func.owner_decl),
......@@ -31840,7 +31839,7 @@ fn analyzeSlicePtr(
3184031839) CompileError!Air.Inst.Ref {
3184131840 const mod = sema.mod;
3184231841 const result_ty = slice_ty.slicePtrFieldType(mod);
31843 if (try sema.resolveMaybeUndefVal(slice)) |val| {
31842 if (try sema.resolveValue(slice)) |val| {
3184431843 if (val.isUndef(mod)) return mod.undefRef(result_ty);
3184531844 return Air.internedToRef(val.slicePtr(mod).toIntern());
3184631845 }
......@@ -31855,7 +31854,7 @@ fn analyzeSliceLen(
3185531854 slice_inst: Air.Inst.Ref,
3185631855) CompileError!Air.Inst.Ref {
3185731856 const mod = sema.mod;
31858 if (try sema.resolveMaybeUndefVal(slice_inst)) |slice_val| {
31857 if (try sema.resolveValue(slice_inst)) |slice_val| {
3185931858 if (slice_val.isUndef(mod)) {
3186031859 return mod.undefRef(Type.usize);
3186131860 }
......@@ -31874,7 +31873,7 @@ fn analyzeIsNull(
3187431873) CompileError!Air.Inst.Ref {
3187531874 const mod = sema.mod;
3187631875 const result_ty = Type.bool;
31877 if (try sema.resolveMaybeUndefVal(operand)) |opt_val| {
31876 if (try sema.resolveValue(operand)) |opt_val| {
3187831877 if (opt_val.isUndef(mod)) {
3187931878 return mod.undefRef(result_ty);
3188031879 }
......@@ -31950,7 +31949,7 @@ fn analyzeIsNonErrComptimeOnly(
3195031949 return .bool_true;
3195131950 }
3195231951
31953 const maybe_operand_val = try sema.resolveMaybeUndefVal(operand);
31952 const maybe_operand_val = try sema.resolveValue(operand);
3195431953
3195531954 // exception if the error union error set is known to be empty,
3195631955 // we allow the comparison but always make it comptime-known.
......@@ -32171,7 +32170,7 @@ fn analyzeSlice(
3217132170 const uncasted_end = try sema.analyzeArithmetic(block, .add, start, len, src, start_src, end_src, false);
3217232171 break :end try sema.coerce(block, Type.usize, uncasted_end, end_src);
3217332172 } else try sema.coerce(block, Type.usize, uncasted_end_opt, end_src);
32174 if (try sema.resolveMaybeUndefVal(end)) |end_val| {
32173 if (try sema.resolveValue(end)) |end_val| {
3217532174 const len_s_val = try mod.intValue(
3217632175 Type.usize,
3217732176 array_ty.arrayLenIncludingSentinel(mod),
......@@ -32213,7 +32212,7 @@ fn analyzeSlice(
3221332212 break :end try sema.coerce(block, Type.usize, uncasted_end, end_src);
3221432213 } else try sema.coerce(block, Type.usize, uncasted_end_opt, end_src);
3221532214 if (try sema.resolveDefinedValue(block, end_src, end)) |end_val| {
32216 if (try sema.resolveMaybeUndefVal(ptr_or_slice)) |slice_val| {
32215 if (try sema.resolveValue(ptr_or_slice)) |slice_val| {
3221732216 if (slice_val.isUndef(mod)) {
3221832217 return sema.fail(block, src, "slice of undefined", .{});
3221932218 }
......@@ -32265,7 +32264,7 @@ fn analyzeSlice(
3226532264 const sentinel = s: {
3226632265 if (sentinel_opt != .none) {
3226732266 const casted = try sema.coerce(block, elem_ty, sentinel_opt, sentinel_src);
32268 break :s try sema.resolveConstValue(block, sentinel_src, casted, .{
32267 break :s try sema.resolveConstDefinedValue(block, sentinel_src, casted, .{
3226932268 .needed_comptime_reason = "slice sentinel must be comptime-known",
3227032269 });
3227132270 }
......@@ -32298,7 +32297,7 @@ fn analyzeSlice(
3229832297 );
3229932298 }
3230032299 checked_start_lte_end = true;
32301 if (try sema.resolveMaybeUndefVal(new_ptr)) |ptr_val| sentinel_check: {
32300 if (try sema.resolveValue(new_ptr)) |ptr_val| sentinel_check: {
3230232301 const expected_sentinel = sentinel orelse break :sentinel_check;
3230332302 const start_int = start_val.getUnsignedInt(mod).?;
3230432303 const end_int = end_val.getUnsignedInt(mod).?;
......@@ -32387,7 +32386,7 @@ fn analyzeSlice(
3238732386 },
3238832387 });
3238932388
32390 const opt_new_ptr_val = try sema.resolveMaybeUndefVal(new_ptr);
32389 const opt_new_ptr_val = try sema.resolveValue(new_ptr);
3239132390 const new_ptr_val = opt_new_ptr_val orelse {
3239232391 const result = try block.addBitCast(return_ty, new_ptr);
3239332392 if (block.wantSafety()) {
......@@ -32534,8 +32533,8 @@ fn cmpNumeric(
3253432533 uncasted_rhs;
3253532534
3253632535 const runtime_src: LazySrcLoc = src: {
32537 if (try sema.resolveMaybeUndefVal(lhs)) |lhs_val| {
32538 if (try sema.resolveMaybeUndefVal(rhs)) |rhs_val| {
32536 if (try sema.resolveValue(lhs)) |lhs_val| {
32537 if (try sema.resolveValue(rhs)) |rhs_val| {
3253932538 // Compare ints: const vs. undefined (or vice versa)
3254032539 if (!lhs_val.isUndef(mod) and (lhs_ty.isInt(mod) or lhs_ty_tag == .ComptimeInt) and rhs_ty.isInt(mod) and rhs_val.isUndef(mod)) {
3254132540 if (try sema.compareIntsOnlyPossibleResult(try sema.resolveLazyValue(lhs_val), op, rhs_ty)) |res| {
......@@ -32567,7 +32566,7 @@ fn cmpNumeric(
3256732566 break :src rhs_src;
3256832567 }
3256932568 } else {
32570 if (try sema.resolveMaybeUndefLazyVal(rhs)) |rhs_val| {
32569 if (try sema.resolveValueResolveLazy(rhs)) |rhs_val| {
3257132570 if (!rhs_val.isUndef(mod) and (rhs_ty.isInt(mod) or rhs_ty_tag == .ComptimeInt) and lhs_ty.isInt(mod)) {
3257232571 // Compare ints: var vs. const
3257332572 if (try sema.compareIntsOnlyPossibleResult(try sema.resolveLazyValue(rhs_val), op.reverse(), lhs_ty)) |res| {
......@@ -32634,7 +32633,7 @@ fn cmpNumeric(
3263432633 var dest_float_type: ?Type = null;
3263532634
3263632635 var lhs_bits: usize = undefined;
32637 if (try sema.resolveMaybeUndefLazyVal(lhs)) |lhs_val| {
32636 if (try sema.resolveValueResolveLazy(lhs)) |lhs_val| {
3263832637 if (lhs_val.isUndef(mod))
3263932638 return mod.undefRef(Type.bool);
3264032639 if (lhs_val.isNan(mod)) switch (op) {
......@@ -32692,7 +32691,7 @@ fn cmpNumeric(
3269232691 }
3269332692
3269432693 var rhs_bits: usize = undefined;
32695 if (try sema.resolveMaybeUndefLazyVal(rhs)) |rhs_val| {
32694 if (try sema.resolveValueResolveLazy(rhs)) |rhs_val| {
3269632695 if (rhs_val.isUndef(mod))
3269732696 return mod.undefRef(Type.bool);
3269832697 if (rhs_val.isNan(mod)) switch (op) {
......@@ -32884,8 +32883,8 @@ fn cmpVector(
3288432883 });
3288532884
3288632885 const runtime_src: LazySrcLoc = src: {
32887 if (try sema.resolveMaybeUndefVal(casted_lhs)) |lhs_val| {
32888 if (try sema.resolveMaybeUndefVal(casted_rhs)) |rhs_val| {
32886 if (try sema.resolveValue(casted_lhs)) |lhs_val| {
32887 if (try sema.resolveValue(casted_rhs)) |rhs_val| {
3288932888 if (lhs_val.isUndef(mod) or rhs_val.isUndef(mod)) {
3289032889 return mod.undefRef(result_ty);
3289132890 }
......@@ -32910,7 +32909,7 @@ fn wrapOptional(
3291032909 inst: Air.Inst.Ref,
3291132910 inst_src: LazySrcLoc,
3291232911) !Air.Inst.Ref {
32913 if (try sema.resolveMaybeUndefVal(inst)) |val| {
32912 if (try sema.resolveValue(inst)) |val| {
3291432913 return Air.internedToRef((try sema.mod.intern(.{ .opt = .{
3291532914 .ty = dest_ty.toIntern(),
3291632915 .val = val.toIntern(),
......@@ -32931,7 +32930,7 @@ fn wrapErrorUnionPayload(
3293132930 const mod = sema.mod;
3293232931 const dest_payload_ty = dest_ty.errorUnionPayload(mod);
3293332932 const coerced = try sema.coerceExtra(block, dest_payload_ty, inst, inst_src, .{ .report_err = false });
32934 if (try sema.resolveMaybeUndefVal(coerced)) |val| {
32933 if (try sema.resolveValue(coerced)) |val| {
3293532934 return Air.internedToRef((try mod.intern(.{ .error_union = .{
3293632935 .ty = dest_ty.toIntern(),
3293732936 .val = .{ .payload = try val.intern(dest_payload_ty, mod) },
......@@ -32953,7 +32952,7 @@ fn wrapErrorUnionSet(
3295332952 const ip = &mod.intern_pool;
3295432953 const inst_ty = sema.typeOf(inst);
3295532954 const dest_err_set_ty = dest_ty.errorUnionSet(mod);
32956 if (try sema.resolveMaybeUndefVal(inst)) |val| {
32955 if (try sema.resolveValue(inst)) |val| {
3295732956 const expected_name = mod.intern_pool.indexToKey(val.toIntern()).err.name;
3295832957 switch (dest_err_set_ty.toIntern()) {
3295932958 .anyerror_type => {},
......@@ -33015,7 +33014,7 @@ fn unionToTag(
3301533014 if ((try sema.typeHasOnePossibleValue(enum_ty))) |opv| {
3301633015 return Air.internedToRef(opv.toIntern());
3301733016 }
33018 if (try sema.resolveMaybeUndefVal(un)) |un_val| {
33017 if (try sema.resolveValue(un)) |un_val| {
3301933018 return Air.internedToRef(un_val.unionTag(mod).?.toIntern());
3302033019 }
3302133020 try sema.requireRuntimeBlock(block, un_src, null);
......@@ -33324,7 +33323,7 @@ fn resolvePeerTypes(
3332433323
3332533324 for (instructions, peer_tys, peer_vals) |inst, *ty, *val| {
3332633325 ty.* = sema.typeOf(inst);
33327 val.* = try sema.resolveMaybeUndefVal(inst);
33326 val.* = try sema.resolveValue(inst);
3332833327 }
3332933328
3333033329 switch (try sema.resolvePeerTypesInner(block, src, peer_tys, peer_vals)) {
......@@ -34379,7 +34378,7 @@ fn resolvePeerTypesInner(
3437934378 },
3438034379 else => |e| return e,
3438134380 };
34382 const coerced_val = (try sema.resolveMaybeUndefVal(coerced_inst)) orelse continue;
34381 const coerced_val = (try sema.resolveValue(coerced_inst)) orelse continue;
3438334382 const existing = comptime_val orelse {
3438434383 comptime_val = coerced_val;
3438534384 continue;
......@@ -35827,7 +35826,7 @@ fn semaStructFields(
3582735826 },
3582835827 else => |e| return e,
3582935828 };
35830 const default_val = (try sema.resolveMaybeUndefVal(coerced)) orelse {
35829 const default_val = (try sema.resolveValue(coerced)) orelse {
3583135830 const init_src = mod.fieldSrcLoc(decl_index, .{
3583235831 .index = field_i,
3583335832 .range = .value,
......@@ -36270,7 +36269,7 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Key.Un
3627036269
3627136270fn semaUnionFieldVal(sema: *Sema, block: *Block, src: LazySrcLoc, int_tag_ty: Type, tag_ref: Air.Inst.Ref) CompileError!Value {
3627236271 const coerced = try sema.coerce(block, int_tag_ty, tag_ref, src);
36273 return sema.resolveConstValue(block, src, coerced, .{
36272 return sema.resolveConstDefinedValue(block, src, coerced, .{
3627436273 .needed_comptime_reason = "enum tag value must be comptime-known",
3627536274 });
3627636275}
......@@ -36828,7 +36827,7 @@ fn isComptimeKnown(
3682836827 sema: *Sema,
3682936828 inst: Air.Inst.Ref,
3683036829) !bool {
36831 return (try sema.resolveMaybeUndefVal(inst)) != null;
36830 return (try sema.resolveValue(inst)) != null;
3683236831}
3683336832
3683436833fn analyzeComptimeAlloc(