authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-10-24 14:57:55-04:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2023-10-24 14:57:55-04:00
log22a6a5d93f000afd7e00450bb5a359f39bb598bf
tree65cae809bfc2edc9eb1642f2ace25313ec3a7193
parentd1230842ac882bbd6456081c474658b293aaf20a
parentf2814caaf04fc041a028d5ede4fb4db5ee2f19ae
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

Merge pull request #17691 from mlugg/no-interned-runtime-value

Remove `InternPool.Key.runtime_value`, clean up Sema value resolution functions

12 files changed, 328 insertions(+), 499 deletions(-)

lib/std/mem.zig+7-1
......@@ -3666,7 +3666,13 @@ fn ReverseIterator(comptime T: type) type {
36663666 @compileError("expected slice or pointer to array, found '" ++ @typeName(T) ++ "'");
36673667 };
36683668 const Element = std.meta.Elem(Pointer);
3669 const ElementPointer = @TypeOf(&@as(Pointer, undefined)[0]);
3669 const ElementPointer = @Type(.{ .Pointer = ptr: {
3670 var ptr = @typeInfo(Pointer).Pointer;
3671 ptr.size = .One;
3672 ptr.child = Element;
3673 ptr.sentinel = null;
3674 break :ptr ptr;
3675 } });
36703676 return struct {
36713677 ptr: Pointer,
36723678 index: usize,
src/InternPool.zig+1-31
......@@ -237,7 +237,6 @@ pub const Key = union(enum) {
237237 /// Typed `undefined`. This will never be `none`; untyped `undefined` is represented
238238 /// via `simple_value` and has a named `Index` tag for it.
239239 undef: Index,
240 runtime_value: TypeValue,
241240 simple_value: SimpleValue,
242241 variable: Variable,
243242 extern_func: ExternFunc,
......@@ -1181,8 +1180,6 @@ pub const Key = union(enum) {
11811180 .payload => |y| Hash.hash(seed + 1, asBytes(&x.ty) ++ asBytes(&y)),
11821181 },
11831182
1184 .runtime_value => |x| Hash.hash(seed, asBytes(&x.val)),
1185
11861183 inline .opaque_type,
11871184 .enum_type,
11881185 .variable,
......@@ -1413,10 +1410,6 @@ pub const Key = union(enum) {
14131410 const b_info = b.undef;
14141411 return a_info == b_info;
14151412 },
1416 .runtime_value => |a_info| {
1417 const b_info = b.runtime_value;
1418 return a_info.val == b_info.val;
1419 },
14201413 .opt => |a_info| {
14211414 const b_info = b.opt;
14221415 return std.meta.eql(a_info, b_info);
......@@ -1703,8 +1696,7 @@ pub const Key = union(enum) {
17031696 .func_type,
17041697 => .type_type,
17051698
1706 inline .runtime_value,
1707 .ptr,
1699 inline .ptr,
17081700 .int,
17091701 .float,
17101702 .opt,
......@@ -2138,7 +2130,6 @@ pub const Index = enum(u32) {
21382130 },
21392131
21402132 undef: DataIsIndex,
2141 runtime_value: struct { data: *Tag.TypeValue },
21422133 simple_value: struct { data: SimpleValue },
21432134 ptr_decl: struct { data: *PtrDecl },
21442135 ptr_mut_decl: struct { data: *PtrMutDecl },
......@@ -2580,10 +2571,6 @@ pub const Tag = enum(u8) {
25802571 /// `data` is `Index` of the type.
25812572 /// Untyped `undefined` is stored instead via `simple_value`.
25822573 undef,
2583 /// A wrapper for values which are comptime-known but should
2584 /// semantically be runtime-known.
2585 /// data is extra index of `TypeValue`.
2586 runtime_value,
25872574 /// A value that can be represented with only an enum tag.
25882575 /// data is SimpleValue enum value.
25892576 simple_value,
......@@ -2795,7 +2782,6 @@ pub const Tag = enum(u8) {
27952782 .type_function => TypeFunction,
27962783
27972784 .undef => unreachable,
2798 .runtime_value => TypeValue,
27992785 .simple_value => unreachable,
28002786 .ptr_decl => PtrDecl,
28012787 .ptr_mut_decl => PtrMutDecl,
......@@ -3730,7 +3716,6 @@ pub fn indexToKey(ip: *const InternPool, index: Index) Key {
37303716 .type_function => .{ .func_type = ip.extraFuncType(data) },
37313717
37323718 .undef => .{ .undef = @as(Index, @enumFromInt(data)) },
3733 .runtime_value => .{ .runtime_value = ip.extraData(Tag.TypeValue, data) },
37343719 .opt_null => .{ .opt = .{
37353720 .ty = @as(Index, @enumFromInt(data)),
37363721 .val = .none,
......@@ -4556,13 +4541,6 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {
45564541 .data = @intFromEnum(ty),
45574542 });
45584543 },
4559 .runtime_value => |runtime_value| {
4560 assert(runtime_value.ty == ip.typeOf(runtime_value.val));
4561 ip.items.appendAssumeCapacity(.{
4562 .tag = .runtime_value,
4563 .data = try ip.addExtra(gpa, runtime_value),
4564 });
4565 },
45664544
45674545 .struct_type => unreachable, // use getStructType() instead
45684546 .anon_struct_type => unreachable, // use getAnonStructType() instead
......@@ -7237,7 +7215,6 @@ fn dumpStatsFallible(ip: *const InternPool, arena: Allocator) anyerror!void {
72377215 },
72387216
72397217 .undef => 0,
7240 .runtime_value => @sizeOf(Tag.TypeValue),
72417218 .simple_type => 0,
72427219 .simple_value => 0,
72437220 .ptr_decl => @sizeOf(PtrDecl),
......@@ -7370,7 +7347,6 @@ fn dumpAllFallible(ip: *const InternPool) anyerror!void {
73707347 .type_union,
73717348 .type_function,
73727349 .undef,
7373 .runtime_value,
73747350 .ptr_decl,
73757351 .ptr_mut_decl,
73767352 .ptr_anon_decl,
......@@ -7793,7 +7769,6 @@ pub fn typeOf(ip: *const InternPool, index: Index) Index {
77937769 .ptr_slice,
77947770 .opt_payload,
77957771 .error_union_payload,
7796 .runtime_value,
77977772 .int_small,
77987773 .int_lazy_align,
77997774 .int_lazy_size,
......@@ -7906,10 +7881,6 @@ pub fn isUndef(ip: *const InternPool, val: Index) bool {
79067881 return val == .undef or ip.items.items(.tag)[@intFromEnum(val)] == .undef;
79077882}
79087883
7909pub fn isRuntimeValue(ip: *const InternPool, val: Index) bool {
7910 return ip.items.items(.tag)[@intFromEnum(val)] == .runtime_value;
7911}
7912
79137884pub fn isVariable(ip: *const InternPool, val: Index) bool {
79147885 return ip.items.items(.tag)[@intFromEnum(val)] == .variable;
79157886}
......@@ -8116,7 +8087,6 @@ pub fn zigTypeTagOrPoison(ip: *const InternPool, index: Index) error{GenericPois
81168087
81178088 // values, not types
81188089 .undef,
8119 .runtime_value,
81208090 .simple_value,
81218091 .ptr_decl,
81228092 .ptr_mut_decl,
src/Module.zig+1-1
......@@ -3757,7 +3757,7 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !bool {
37573757 const address_space_src: LazySrcLoc = .{ .node_offset_var_decl_addrspace = 0 };
37583758 const ty_src: LazySrcLoc = .{ .node_offset_var_decl_ty = 0 };
37593759 const init_src: LazySrcLoc = .{ .node_offset_var_decl_init = 0 };
3760 const decl_tv = try sema.resolveInstValue(&block_scope, init_src, result_ref, .{
3760 const decl_tv = try sema.resolveInstValueAllowVariables(&block_scope, init_src, result_ref, .{
37613761 .needed_comptime_reason = "global variable initializer must be comptime-known",
37623762 });
37633763
src/Sema.zig+305-385
......@@ -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,119 +2071,67 @@ 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/// May return Value Tags: `variable`, `undef`.
2075/// See `resolveConstValue` for an alternative.
2076/// Value Tag `generic_poison` causes `error.GenericPoison` to be returned.
2077fn resolveValue(
2078 sema: *Sema,
2079 block: *Block,
2080 src: LazySrcLoc,
2081 air_ref: Air.Inst.Ref,
2082 reason: NeededComptimeReason,
2083) CompileError!Value {
2084 if (try sema.resolveMaybeUndefValAllowVariables(air_ref)) |val| {
2085 if (val.isGenericPoison()) return error.GenericPoison;
2086 return val;
2087 }
2088 return sema.failWithNeededComptime(block, src, reason);
2074/// Return the Value corresponding to a given AIR ref, or `null` if it refers to a runtime value.
2075/// InternPool key `variable` is considered a runtime value.
2076/// Generic poison causes `error.GenericPoison` to be returned.
2077fn resolveValue(sema: *Sema, inst: Air.Inst.Ref) CompileError!?Value {
2078 const val = (try sema.resolveValueAllowVariables(inst)) orelse return null;
2079 if (val.isGenericPoison()) return error.GenericPoison;
2080 if (sema.mod.intern_pool.isVariable(val.toIntern())) return null;
2081 return val;
20892082}
20902083
2091/// Value Tag `variable` will cause a compile error.
2092/// Value Tag `undef` may be returned.
2093fn resolveConstMaybeUndefVal(
2084/// Like `resolveValue`, but emits an error if the value is not comptime-known.
2085fn resolveConstValue(
20942086 sema: *Sema,
20952087 block: *Block,
20962088 src: LazySrcLoc,
20972089 inst: Air.Inst.Ref,
20982090 reason: NeededComptimeReason,
20992091) CompileError!Value {
2100 if (try sema.resolveMaybeUndefValAllowVariables(inst)) |val| {
2101 if (val.isGenericPoison()) return error.GenericPoison;
2102 if (sema.mod.intern_pool.isVariable(val.toIntern()))
2103 return sema.failWithNeededComptime(block, src, reason);
2104 return val;
2105 }
2106 return sema.failWithNeededComptime(block, src, reason);
2092 return try sema.resolveValue(inst) orelse {
2093 return sema.failWithNeededComptime(block, src, reason);
2094 };
21072095}
21082096
2109/// Will not return Value Tags: `variable`, `undef`. Instead they will emit compile errors.
2110/// See `resolveValue` for an alternative.
2111fn resolveConstValue(
2097/// Like `resolveValue`, but emits an error if the value is comptime-known to be undefined.
2098fn resolveDefinedValue(
21122099 sema: *Sema,
21132100 block: *Block,
21142101 src: LazySrcLoc,
21152102 air_ref: Air.Inst.Ref,
2116 reason: NeededComptimeReason,
2117) CompileError!Value {
2118 if (try sema.resolveMaybeUndefValAllowVariables(air_ref)) |val| {
2119 if (val.isGenericPoison()) return error.GenericPoison;
2120 if (val.isUndef(sema.mod)) return sema.failWithUseOfUndef(block, src);
2121 if (sema.mod.intern_pool.isVariable(val.toIntern()))
2122 return sema.failWithNeededComptime(block, src, reason);
2123 return val;
2103) CompileError!?Value {
2104 const mod = sema.mod;
2105 const val = try sema.resolveValue(air_ref) orelse return null;
2106 if (val.isUndef(mod)) {
2107 return sema.failWithUseOfUndef(block, src);
21242108 }
2125 return sema.failWithNeededComptime(block, src, reason);
2109 return val;
21262110}
21272111
2128/// Will not return Value Tags: `variable`, `undef`. Instead they will emit compile errors.
2129/// Lazy values are recursively resolved.
2130fn resolveConstLazyValue(
2112/// Like `resolveValue`, but emits an error if the value is not comptime-known or is undefined.
2113fn resolveConstDefinedValue(
21312114 sema: *Sema,
21322115 block: *Block,
21332116 src: LazySrcLoc,
21342117 air_ref: Air.Inst.Ref,
21352118 reason: NeededComptimeReason,
21362119) CompileError!Value {
2137 return sema.resolveLazyValue(try sema.resolveConstValue(block, src, air_ref, reason));
2138}
2139
2140/// Value Tag `variable` causes this function to return `null`.
2141/// Value Tag `undef` causes this function to return a compile error.
2142fn resolveDefinedValue(
2143 sema: *Sema,
2144 block: *Block,
2145 src: LazySrcLoc,
2146 air_ref: Air.Inst.Ref,
2147) CompileError!?Value {
2148 const mod = sema.mod;
2149 if (try sema.resolveMaybeUndefVal(air_ref)) |val| {
2150 if (val.isUndef(mod)) {
2151 if (block.is_typeof) return null;
2152 return sema.failWithUseOfUndef(block, src);
2153 }
2154 return val;
2155 }
2156 return null;
2157}
2158
2159/// Value Tag `variable` causes this function to return `null`.
2160/// Value Tag `undef` causes this function to return the Value.
2161/// Value Tag `generic_poison` causes `error.GenericPoison` to be returned.
2162fn resolveMaybeUndefVal(sema: *Sema, inst: Air.Inst.Ref) CompileError!?Value {
2163 const val = (try sema.resolveMaybeUndefValAllowVariables(inst)) orelse return null;
2164 if (val.isGenericPoison()) return error.GenericPoison;
2165 if (val.ip_index != .none and sema.mod.intern_pool.isVariable(val.toIntern())) return null;
2120 const val = try sema.resolveConstValue(block, src, air_ref, reason);
2121 if (val.isUndef(sema.mod)) return sema.failWithUseOfUndef(block, src);
21662122 return val;
21672123}
21682124
2169/// Value Tag `variable` causes this function to return `null`.
2170/// Value Tag `undef` causes this function to return the Value.
2171/// Value Tag `generic_poison` causes `error.GenericPoison` to be returned.
2172/// Lazy values are recursively resolved.
2173fn resolveMaybeUndefLazyVal(sema: *Sema, inst: Air.Inst.Ref) CompileError!?Value {
2174 return try sema.resolveLazyValue((try sema.resolveMaybeUndefVal(inst)) orelse return null);
2125/// Like `resolveValue`, but recursively resolves lazy values before returning.
2126fn resolveValueResolveLazy(sema: *Sema, inst: Air.Inst.Ref) CompileError!?Value {
2127 return try sema.resolveLazyValue((try sema.resolveValue(inst)) orelse return null);
21752128}
21762129
2177/// Value Tag `variable` results in `null`.
2178/// Value Tag `undef` results in the Value.
2179/// Value Tag `generic_poison` causes `error.GenericPoison` to be returned.
2180/// Value Tag `decl_ref` and `decl_ref_mut` or any nested such value results in `null`.
2130/// Like `resolveValue`, but any pointer value which does not correspond
2131/// to a comptime-known integer (e.g. a decl pointer) returns `null`.
21812132/// Lazy values are recursively resolved.
2182fn resolveMaybeUndefValIntable(sema: *Sema, inst: Air.Inst.Ref) CompileError!?Value {
2183 const val = (try sema.resolveMaybeUndefValAllowVariables(inst)) orelse return null;
2184 if (val.isGenericPoison()) return error.GenericPoison;
2185 if (val.ip_index == .none) return val;
2186 if (sema.mod.intern_pool.isVariable(val.toIntern())) return null;
2133fn resolveValueIntable(sema: *Sema, inst: Air.Inst.Ref) CompileError!?Value {
2134 const val = (try sema.resolveValue(inst)) orelse return null;
21872135 if (sema.mod.intern_pool.getBackingAddrTag(val.toIntern())) |addr| switch (addr) {
21882136 .decl, .anon_decl, .mut_decl, .comptime_field => return null,
21892137 .int => {},
......@@ -2192,22 +2140,8 @@ fn resolveMaybeUndefValIntable(sema: *Sema, inst: Air.Inst.Ref) CompileError!?Va
21922140 return try sema.resolveLazyValue(val);
21932141}
21942142
2195/// Returns all Value tags including `variable` and `undef`.
2196fn resolveMaybeUndefValAllowVariables(sema: *Sema, inst: Air.Inst.Ref) CompileError!?Value {
2197 var make_runtime = false;
2198 if (try sema.resolveMaybeUndefValAllowVariablesMaybeRuntime(inst, &make_runtime)) |val| {
2199 if (make_runtime) return null;
2200 return val;
2201 }
2202 return null;
2203}
2204
2205/// Returns all Value tags including `variable`, `undef` and `runtime_value`.
2206fn resolveMaybeUndefValAllowVariablesMaybeRuntime(
2207 sema: *Sema,
2208 inst: Air.Inst.Ref,
2209 make_runtime: *bool,
2210) CompileError!?Value {
2143/// Returns all InternPool keys representing values, including `variable`, `undef`, and `generic_poison`.
2144fn resolveValueAllowVariables(sema: *Sema, inst: Air.Inst.Ref) CompileError!?Value {
22112145 assert(inst != .none);
22122146 // First section of indexes correspond to a set number of constant values.
22132147 if (@intFromEnum(inst) < InternPool.static_len) {
......@@ -2230,11 +2164,47 @@ fn resolveMaybeUndefValAllowVariablesMaybeRuntime(
22302164 }
22312165 };
22322166 const val = ip_index.toValue();
2233 if (val.isRuntimeValue(sema.mod)) make_runtime.* = true;
2234 if (val.isPtrToThreadLocal(sema.mod)) make_runtime.* = true;
2167 if (val.isPtrToThreadLocal(sema.mod)) return null;
22352168 return val;
22362169}
22372170
2171/// Returns a compile error if the value has tag `variable`. See `resolveInstValue` for
2172/// a function that does not.
2173pub fn resolveInstConst(
2174 sema: *Sema,
2175 block: *Block,
2176 src: LazySrcLoc,
2177 zir_ref: Zir.Inst.Ref,
2178 reason: NeededComptimeReason,
2179) CompileError!TypedValue {
2180 const air_ref = try sema.resolveInst(zir_ref);
2181 const val = try sema.resolveConstDefinedValue(block, src, air_ref, reason);
2182 return .{
2183 .ty = sema.typeOf(air_ref),
2184 .val = val,
2185 };
2186}
2187
2188/// Value Tag may be `undef` or `variable`.
2189/// See `resolveInstConst` for an alternative.
2190pub fn resolveInstValueAllowVariables(
2191 sema: *Sema,
2192 block: *Block,
2193 src: LazySrcLoc,
2194 zir_ref: Zir.Inst.Ref,
2195 reason: NeededComptimeReason,
2196) CompileError!TypedValue {
2197 const air_ref = try sema.resolveInst(zir_ref);
2198 const val = try sema.resolveValueAllowVariables(air_ref) orelse {
2199 return sema.failWithNeededComptime(block, src, reason);
2200 };
2201 if (val.isGenericPoison()) return error.GenericPoison;
2202 return .{
2203 .ty = sema.typeOf(air_ref),
2204 .val = val,
2205 };
2206}
2207
22382208fn failWithNeededComptime(sema: *Sema, block: *Block, src: LazySrcLoc, reason: NeededComptimeReason) CompileError {
22392209 const msg = msg: {
22402210 const msg = try sema.errMsg(block, src, "unable to resolve comptime value", .{});
......@@ -2668,44 +2638,10 @@ fn analyzeAsInt(
26682638) !u64 {
26692639 const mod = sema.mod;
26702640 const coerced = try sema.coerce(block, dest_ty, air_ref, src);
2671 const val = try sema.resolveConstValue(block, src, coerced, reason);
2641 const val = try sema.resolveConstDefinedValue(block, src, coerced, reason);
26722642 return (try val.getUnsignedIntAdvanced(mod, sema)).?;
26732643}
26742644
2675// Returns a compile error if the value has tag `variable`. See `resolveInstValue` for
2676// a function that does not.
2677pub fn resolveInstConst(
2678 sema: *Sema,
2679 block: *Block,
2680 src: LazySrcLoc,
2681 zir_ref: Zir.Inst.Ref,
2682 reason: NeededComptimeReason,
2683) CompileError!TypedValue {
2684 const air_ref = try sema.resolveInst(zir_ref);
2685 const val = try sema.resolveConstValue(block, src, air_ref, reason);
2686 return TypedValue{
2687 .ty = sema.typeOf(air_ref),
2688 .val = val,
2689 };
2690}
2691
2692// Value Tag may be `undef` or `variable`.
2693// See `resolveInstConst` for an alternative.
2694pub fn resolveInstValue(
2695 sema: *Sema,
2696 block: *Block,
2697 src: LazySrcLoc,
2698 zir_ref: Zir.Inst.Ref,
2699 reason: NeededComptimeReason,
2700) CompileError!TypedValue {
2701 const air_ref = try sema.resolveInst(zir_ref);
2702 const val = try sema.resolveValue(block, src, air_ref, reason);
2703 return TypedValue{
2704 .ty = sema.typeOf(air_ref),
2705 .val = val,
2706 };
2707}
2708
27092645pub fn getStructType(
27102646 sema: *Sema,
27112647 decl: Module.Decl.Index,
......@@ -2873,7 +2809,7 @@ fn createAnonymousDeclTypeNamed(
28732809 // If not then this is a struct type being returned from a non-generic
28742810 // function and the name doesn't matter since it will later
28752811 // result in a compile error.
2876 const arg_val = sema.resolveConstMaybeUndefVal(block, .unneeded, arg, undefined) catch
2812 const arg_val = sema.resolveConstValue(block, .unneeded, arg, undefined) catch
28772813 return sema.createAnonymousDeclTypeNamed(block, src, typed_value, .anon, anon_prefix, null);
28782814
28792815 if (arg_i != 0) try writer.writeByte(',');
......@@ -3117,13 +3053,13 @@ fn zirEnumDecl(
31173053 const tag_val_ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_index]);
31183054 extra_index += 1;
31193055 const tag_inst = try sema.resolveInst(tag_val_ref);
3120 last_tag_val = sema.resolveConstValue(block, .unneeded, tag_inst, undefined) catch |err| switch (err) {
3056 last_tag_val = sema.resolveConstDefinedValue(block, .unneeded, tag_inst, undefined) catch |err| switch (err) {
31213057 error.NeededSourceLocation => {
31223058 const value_src = mod.fieldSrcLoc(new_decl_index, .{
31233059 .index = field_i,
31243060 .range = .value,
31253061 }).lazy;
3126 _ = try sema.resolveConstValue(block, value_src, tag_inst, .{
3062 _ = try sema.resolveConstDefinedValue(block, value_src, tag_inst, .{
31273063 .needed_comptime_reason = "enum tag value must be comptime-known",
31283064 });
31293065 unreachable;
......@@ -3670,7 +3606,7 @@ fn zirMakePtrConst(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
36703606 // If this is already a comptime-known allocation, we don't want to emit an error - the stores
36713607 // were already performed at comptime! Just make the pointer constant as normal.
36723608 implicit_ct: {
3673 const ptr_val = try sema.resolveMaybeUndefVal(alloc) orelse break :implicit_ct;
3609 const ptr_val = try sema.resolveValue(alloc) orelse break :implicit_ct;
36743610 if (!ptr_val.isComptimeMutablePtr(mod)) {
36753611 // It could still be a constant pointer to a decl.
36763612 switch (mod.intern_pool.indexToKey(ptr_val.toIntern()).ptr.addr) {
......@@ -3681,7 +3617,7 @@ fn zirMakePtrConst(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
36813617 else => {
36823618 const decl_index = ptr_val.pointerDecl(mod) orelse break :implicit_ct;
36833619 const decl_val = mod.declPtr(decl_index).val.toIntern();
3684 if (mod.intern_pool.isRuntimeValue(decl_val)) break :implicit_ct;
3620 if (mod.intern_pool.isVariable(decl_val)) break :implicit_ct;
36853621 },
36863622 }
36873623 }
......@@ -3812,7 +3748,7 @@ fn resolveComptimeKnownAllocValue(sema: *Sema, block: *Block, alloc: Air.Inst.Re
38123748 Air.Bin,
38133749 tmp_air.instructions.items(.data)[air_ptr].ty_pl.payload,
38143750 ).data;
3815 const idx_val = (try sema.resolveMaybeUndefVal(data.rhs)).?;
3751 const idx_val = (try sema.resolveValue(data.rhs)).?;
38163752 break :blk .{
38173753 data.lhs,
38183754 .{ .elem = idx_val.toUnsignedInt(mod) },
......@@ -3871,7 +3807,7 @@ fn resolveComptimeKnownAllocValue(sema: *Sema, block: *Block, alloc: Air.Inst.Re
38713807 // store instruction, so we must set the union payload now.
38723808 const bin_op = sema.air_instructions.items(.data)[store_inst].bin_op;
38733809 const air_ptr_inst = Air.refToIndex(bin_op.lhs).?;
3874 const tag_val = (try sema.resolveMaybeUndefVal(bin_op.rhs)).?;
3810 const tag_val = (try sema.resolveValue(bin_op.rhs)).?;
38753811 const union_ty = sema.typeOf(bin_op.lhs).childType(mod);
38763812 const payload_ty = union_ty.unionFieldType(tag_val, mod).?;
38773813 if (try sema.typeHasOnePossibleValue(payload_ty)) |payload_val| {
......@@ -3883,7 +3819,7 @@ fn resolveComptimeKnownAllocValue(sema: *Sema, block: *Block, alloc: Air.Inst.Re
38833819 .store, .store_safe => {
38843820 const bin_op = sema.air_instructions.items(.data)[store_inst].bin_op;
38853821 const air_ptr_inst = Air.refToIndex(bin_op.lhs).?;
3886 const store_val = (try sema.resolveMaybeUndefVal(bin_op.rhs)).?;
3822 const store_val = (try sema.resolveValue(bin_op.rhs)).?;
38873823 const new_ptr = ptr_mapping.get(air_ptr_inst).?;
38883824 try sema.storePtrVal(block, .unneeded, new_ptr.toValue(), store_val, mod.intern_pool.typeOf(store_val.toIntern()).toType());
38893825 },
......@@ -3934,7 +3870,7 @@ fn makePtrConst(sema: *Sema, block: *Block, alloc: Air.Inst.Ref) CompileError!Ai
39343870 const const_ptr_ty = try sema.makePtrTyConst(alloc_ty);
39353871
39363872 // Detect if a comptime value simply needs to have its type changed.
3937 if (try sema.resolveMaybeUndefVal(alloc)) |val| {
3873 if (try sema.resolveValue(alloc)) |val| {
39383874 return Air.internedToRef((try sema.mod.getCoerced(val, const_ptr_ty)).toIntern());
39393875 }
39403876
......@@ -4637,7 +4573,6 @@ fn validateUnionInit(
46374573 var first_block_index = block.instructions.items.len;
46384574 var block_index = block.instructions.items.len - 1;
46394575 var init_val: ?Value = null;
4640 var make_runtime = false;
46414576 while (block_index > 0) : (block_index -= 1) {
46424577 const store_inst = block.instructions.items[block_index];
46434578 if (Air.indexToRef(store_inst) == field_ptr_ref) break;
......@@ -4659,7 +4594,7 @@ fn validateUnionInit(
46594594 ).?
46604595 else
46614596 block_index, first_block_index);
4662 init_val = try sema.resolveMaybeUndefValAllowVariablesMaybeRuntime(bin_op.rhs, &make_runtime);
4597 init_val = try sema.resolveValue(bin_op.rhs);
46634598 break;
46644599 }
46654600
......@@ -4693,15 +4628,11 @@ fn validateUnionInit(
46934628 }
46944629 block.instructions.shrinkRetainingCapacity(block_index);
46954630
4696 var union_val = try mod.intern(.{ .un = .{
4631 const union_val = try mod.intern(.{ .un = .{
46974632 .ty = union_ty.toIntern(),
46984633 .tag = tag_val.toIntern(),
46994634 .val = val.toIntern(),
47004635 } });
4701 if (make_runtime) union_val = try mod.intern(.{ .runtime_value = .{
4702 .ty = union_ty.toIntern(),
4703 .val = union_val,
4704 } });
47054636 const union_init = Air.internedToRef(union_val);
47064637 try sema.storePtr2(block, init_src, union_ptr, init_src, union_init, init_src, .store);
47074638 return;
......@@ -4830,7 +4761,6 @@ fn validateStructInit(
48304761
48314762 var struct_is_comptime = true;
48324763 var first_block_index = block.instructions.items.len;
4833 var make_runtime = false;
48344764
48354765 const require_comptime = try sema.typeRequiresComptime(struct_ty);
48364766 const air_tags = sema.air_instructions.items(.tag);
......@@ -4898,7 +4828,7 @@ fn validateStructInit(
48984828 ).?
48994829 else
49004830 block_index, first_block_index);
4901 if (try sema.resolveMaybeUndefValAllowVariablesMaybeRuntime(bin_op.rhs, &make_runtime)) |val| {
4831 if (try sema.resolveValue(bin_op.rhs)) |val| {
49024832 field_values[i] = val.toIntern();
49034833 } else if (require_comptime) {
49044834 const field_ptr_data = sema.code.instructions.items(.data)[field_ptr].pl_node;
......@@ -4989,14 +4919,10 @@ fn validateStructInit(
49894919 }
49904920 block.instructions.shrinkRetainingCapacity(block_index);
49914921
4992 var struct_val = try mod.intern(.{ .aggregate = .{
4922 const struct_val = try mod.intern(.{ .aggregate = .{
49934923 .ty = struct_ty.toIntern(),
49944924 .storage = .{ .elems = field_values },
49954925 } });
4996 if (make_runtime) struct_val = try mod.intern(.{ .runtime_value = .{
4997 .ty = struct_ty.toIntern(),
4998 .val = struct_val,
4999 } });
50004926 const struct_init = Air.internedToRef(struct_val);
50014927 try sema.storePtr2(block, init_src, struct_ptr, init_src, struct_init, init_src, .store);
50024928 return;
......@@ -5095,7 +5021,6 @@ fn zirValidatePtrArrayInit(
50955021
50965022 var array_is_comptime = true;
50975023 var first_block_index = block.instructions.items.len;
5098 var make_runtime = false;
50995024
51005025 // Collect the comptime element values in case the array literal ends up
51015026 // being comptime-known.
......@@ -5159,7 +5084,7 @@ fn zirValidatePtrArrayInit(
51595084 ).?
51605085 else
51615086 block_index, first_block_index);
5162 if (try sema.resolveMaybeUndefValAllowVariablesMaybeRuntime(bin_op.rhs, &make_runtime)) |val| {
5087 if (try sema.resolveValue(bin_op.rhs)) |val| {
51635088 element_vals[i] = val.toIntern();
51645089 } else {
51655090 array_is_comptime = false;
......@@ -5211,14 +5136,10 @@ fn zirValidatePtrArrayInit(
52115136 }
52125137 block.instructions.shrinkRetainingCapacity(block_index);
52135138
5214 var array_val = try mod.intern(.{ .aggregate = .{
5139 const array_val = try mod.intern(.{ .aggregate = .{
52155140 .ty = array_ty.toIntern(),
52165141 .storage = .{ .elems = element_vals },
52175142 } });
5218 if (make_runtime) array_val = try mod.intern(.{ .runtime_value = .{
5219 .ty = array_ty.toIntern(),
5220 .val = array_val,
5221 } });
52225143 const array_init = Air.internedToRef(array_val);
52235144 try sema.storePtr2(block, init_src, array_ptr, init_src, array_init, init_src, .store);
52245145 }
......@@ -5245,7 +5166,7 @@ fn zirValidateDeref(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr
52455166 }
52465167
52475168 const elem_ty = operand_ty.elemType2(mod);
5248 if (try sema.resolveMaybeUndefVal(operand)) |val| {
5169 if (try sema.resolveValue(operand)) |val| {
52495170 if (val.isUndef(mod)) {
52505171 return sema.fail(block, src, "cannot dereference undefined value", .{});
52515172 }
......@@ -5452,8 +5373,7 @@ fn storeToInferredAllocComptime(
54525373 const operand_ty = sema.typeOf(operand);
54535374 // There will be only one store_to_inferred_ptr because we are running at comptime.
54545375 // The alloc will turn into a Decl.
5455 if (try sema.resolveMaybeUndefValAllowVariables(operand)) |operand_val| store: {
5456 if (operand_val.getVariable(sema.mod) != null) break :store;
5376 if (try sema.resolveValue(operand)) |operand_val| {
54575377 var anon_decl = try block.startAnonDecl(); // TODO: comptime value mutation without Decl
54585378 defer anon_decl.deinit();
54595379 iac.decl_index = try anon_decl.finish(operand_ty, operand_val, iac.alignment);
......@@ -5643,7 +5563,7 @@ fn zirCompileLog(
56435563
56445564 const arg = try sema.resolveInst(arg_ref);
56455565 const arg_ty = sema.typeOf(arg);
5646 if (try sema.resolveMaybeUndefLazyVal(arg)) |val| {
5566 if (try sema.resolveValueResolveLazy(arg)) |val| {
56475567 try writer.print("@as({}, {})", .{
56485568 arg_ty.fmt(mod), val.fmtValue(arg_ty, mod),
56495569 });
......@@ -6557,7 +6477,7 @@ fn lookupInNamespace(
65576477
65586478fn funcDeclSrc(sema: *Sema, func_inst: Air.Inst.Ref) !?*Decl {
65596479 const mod = sema.mod;
6560 const func_val = (try sema.resolveMaybeUndefVal(func_inst)) orelse return null;
6480 const func_val = (try sema.resolveValue(func_inst)) orelse return null;
65616481 if (func_val.isUndef(mod)) return null;
65626482 const owner_decl_index = switch (mod.intern_pool.indexToKey(func_val.toIntern())) {
65636483 .extern_func => |extern_func| extern_func.decl,
......@@ -7303,7 +7223,7 @@ fn analyzeCall(
73037223 }
73047224
73057225 const result: Air.Inst.Ref = if (is_inline_call) res: {
7306 const func_val = try sema.resolveConstValue(block, func_src, func, .{
7226 const func_val = try sema.resolveConstDefinedValue(block, func_src, func, .{
73077227 .needed_comptime_reason = "function being called at comptime must be comptime-known",
73087228 .block_comptime_reason = comptime_reason,
73097229 });
......@@ -7553,7 +7473,7 @@ fn analyzeCall(
75537473 }
75547474
75557475 if (should_memoize and is_comptime_call) {
7556 const result_val = try sema.resolveConstMaybeUndefVal(block, .unneeded, result, undefined);
7476 const result_val = try sema.resolveConstValue(block, .unneeded, result, undefined);
75577477 const result_interned = try result_val.intern2(sema.fn_ret_ty, mod);
75587478
75597479 // Transform ad-hoc inferred error set types into concrete error sets.
......@@ -7570,7 +7490,7 @@ fn analyzeCall(
75707490 break :res2 Air.internedToRef(result_transformed);
75717491 }
75727492
7573 if (try sema.resolveMaybeUndefVal(result)) |result_val| {
7493 if (try sema.resolveValue(result)) |result_val| {
75747494 const result_interned = try result_val.intern2(sema.fn_ret_ty, mod);
75757495 const result_transformed = try sema.resolveAdHocInferredErrorSet(block, call_src, result_interned);
75767496 break :res2 Air.internedToRef(result_transformed);
......@@ -7610,7 +7530,7 @@ fn analyzeCall(
76107530 ip.funcAnalysis(sema.owner_func_index).calls_or_awaits_errorable_fn = true;
76117531 }
76127532
7613 if (try sema.resolveMaybeUndefVal(func)) |func_val| {
7533 if (try sema.resolveValue(func)) |func_val| {
76147534 if (mod.intern_pool.isFuncBody(func_val.toIntern())) {
76157535 try mod.ensureFuncBodyAnalysisQueued(func_val.toIntern());
76167536 }
......@@ -7638,7 +7558,7 @@ fn analyzeCall(
76387558 if (block.wantSafety() and func_ty_info.return_type == .noreturn_type) skip_safety: {
76397559 // Function pointers and extern functions aren't guaranteed to
76407560 // actually be noreturn so we add a safety check for them.
7641 if (try sema.resolveMaybeUndefVal(func)) |func_val| {
7561 if (try sema.resolveValue(func)) |func_val| {
76427562 switch (mod.intern_pool.indexToKey(func_val.toIntern())) {
76437563 .func => break :skip_safety,
76447564 .ptr => |ptr| switch (ptr.addr) {
......@@ -7727,19 +7647,19 @@ fn analyzeInlineCallArg(
77277647 }
77287648 const arg_src = args_info.argSrc(arg_block, arg_i.*);
77297649 if (try ics.callee().typeRequiresComptime(param_ty.toType())) {
7730 _ = try ics.caller().resolveConstMaybeUndefVal(arg_block, arg_src, casted_arg, .{
7650 _ = try ics.caller().resolveConstValue(arg_block, arg_src, casted_arg, .{
77317651 .needed_comptime_reason = "argument to parameter with comptime-only type must be comptime-known",
77327652 .block_comptime_reason = param_block.comptime_reason,
77337653 });
77347654 } else if (!is_comptime_call and zir_tags[inst] == .param_comptime) {
7735 _ = try ics.caller().resolveConstMaybeUndefVal(arg_block, arg_src, casted_arg, .{
7655 _ = try ics.caller().resolveConstValue(arg_block, arg_src, casted_arg, .{
77367656 .needed_comptime_reason = "parameter is comptime",
77377657 });
77387658 }
77397659
77407660 if (is_comptime_call) {
77417661 ics.callee().inst_map.putAssumeCapacityNoClobber(inst, casted_arg);
7742 const arg_val = try ics.caller().resolveConstMaybeUndefVal(arg_block, arg_src, casted_arg, .{
7662 const arg_val = try ics.caller().resolveConstValue(arg_block, arg_src, casted_arg, .{
77437663 .needed_comptime_reason = "argument to function being called at comptime must be comptime-known",
77447664 .block_comptime_reason = param_block.comptime_reason,
77457665 });
......@@ -7761,7 +7681,7 @@ fn analyzeInlineCallArg(
77617681 ics.callee().inst_map.putAssumeCapacityNoClobber(inst, casted_arg);
77627682 }
77637683
7764 if (try ics.caller().resolveMaybeUndefVal(casted_arg)) |_| {
7684 if (try ics.caller().resolveValue(casted_arg)) |_| {
77657685 param_block.inlining.?.has_comptime_args = true;
77667686 }
77677687
......@@ -7778,7 +7698,7 @@ fn analyzeInlineCallArg(
77787698
77797699 if (is_comptime_call) {
77807700 ics.callee().inst_map.putAssumeCapacityNoClobber(inst, uncasted_arg);
7781 const arg_val = try ics.caller().resolveConstMaybeUndefVal(arg_block, arg_src, uncasted_arg, .{
7701 const arg_val = try ics.caller().resolveConstValue(arg_block, arg_src, uncasted_arg, .{
77827702 .needed_comptime_reason = "argument to function being called at comptime must be comptime-known",
77837703 .block_comptime_reason = param_block.comptime_reason,
77847704 });
......@@ -7798,14 +7718,14 @@ fn analyzeInlineCallArg(
77987718 memoized_arg_values[arg_i.*] = try resolved_arg_val.intern(ics.caller().typeOf(uncasted_arg), mod);
77997719 } else {
78007720 if (zir_tags[inst] == .param_anytype_comptime) {
7801 _ = try ics.caller().resolveConstMaybeUndefVal(arg_block, arg_src, uncasted_arg, .{
7721 _ = try ics.caller().resolveConstValue(arg_block, arg_src, uncasted_arg, .{
78027722 .needed_comptime_reason = "parameter is comptime",
78037723 });
78047724 }
78057725 ics.callee().inst_map.putAssumeCapacityNoClobber(inst, uncasted_arg);
78067726 }
78077727
7808 if (try ics.caller().resolveMaybeUndefVal(uncasted_arg)) |_| {
7728 if (try ics.caller().resolveValue(uncasted_arg)) |_| {
78097729 param_block.inlining.?.has_comptime_args = true;
78107730 }
78117731
......@@ -7847,7 +7767,7 @@ fn instantiateGenericCall(
78477767 const gpa = sema.gpa;
78487768 const ip = &mod.intern_pool;
78497769
7850 const func_val = try sema.resolveConstValue(block, func_src, func, .{
7770 const func_val = try sema.resolveConstDefinedValue(block, func_src, func, .{
78517771 .needed_comptime_reason = "generic function being called must be comptime-known",
78527772 });
78537773 const generic_owner = switch (mod.intern_pool.indexToKey(func_val.toIntern())) {
......@@ -7984,7 +7904,7 @@ fn instantiateGenericCall(
79847904 };
79857905
79867906 if (arg_is_comptime) {
7987 if (try sema.resolveMaybeUndefVal(arg_ref)) |arg_val| {
7907 if (try sema.resolveValue(arg_ref)) |arg_val| {
79887908 comptime_args[arg_index] = arg_val.toIntern();
79897909 child_sema.inst_map.putAssumeCapacityNoClobber(
79907910 param_inst,
......@@ -8056,7 +7976,7 @@ fn instantiateGenericCall(
80567976 // We've already handled parameters, so don't resolve the whole body. Instead, just
80577977 // do the instructions after the params (i.e. the func itself).
80587978 const new_func_inst = try child_sema.resolveBody(&child_block, fn_info.param_body[args_info.count()..], fn_info.param_body_inst);
8059 const callee_index = (child_sema.resolveConstValue(&child_block, .unneeded, new_func_inst, undefined) catch unreachable).toIntern();
7979 const callee_index = (child_sema.resolveConstDefinedValue(&child_block, .unneeded, new_func_inst, undefined) catch unreachable).toIntern();
80607980
80617981 const callee = mod.funcInfo(callee_index);
80627982 callee.branchQuota(ip).* = @max(callee.branchQuota(ip).*, sema.branch_quota);
......@@ -8307,7 +8227,7 @@ fn zirArrayTypeSentinel(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compil
83078227 try sema.validateArrayElemType(block, elem_type, elem_src);
83088228 const uncasted_sentinel = try sema.resolveInst(extra.sentinel);
83098229 const sentinel = try sema.coerce(block, elem_type, uncasted_sentinel, sentinel_src);
8310 const sentinel_val = try sema.resolveConstValue(block, sentinel_src, sentinel, .{
8230 const sentinel_val = try sema.resolveConstDefinedValue(block, sentinel_src, sentinel, .{
83118231 .needed_comptime_reason = "array sentinel value must be comptime-known",
83128232 });
83138233 const array_ty = try sema.mod.arrayType(.{
......@@ -8406,7 +8326,7 @@ fn zirIntFromError(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstD
84068326 const operand = try sema.coerce(block, Type.anyerror, uncasted_operand, operand_src);
84078327 const err_int_ty = try mod.errorIntType();
84088328
8409 if (try sema.resolveMaybeUndefVal(operand)) |val| {
8329 if (try sema.resolveValue(operand)) |val| {
84108330 if (val.isUndef(mod)) {
84118331 return mod.undefRef(err_int_ty);
84128332 }
......@@ -8579,7 +8499,7 @@ fn zirIntFromEnum(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
85798499 return Air.internedToRef((try mod.getCoerced(opv, int_tag_ty)).toIntern());
85808500 }
85818501
8582 if (try sema.resolveMaybeUndefVal(enum_tag)) |enum_tag_val| {
8502 if (try sema.resolveValue(enum_tag)) |enum_tag_val| {
85838503 const val = try enum_tag_val.intFromEnum(enum_tag_ty, mod);
85848504 return Air.internedToRef(val.toIntern());
85858505 }
......@@ -8602,7 +8522,7 @@ fn zirEnumFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
86028522 }
86038523 _ = try sema.checkIntType(block, operand_src, sema.typeOf(operand));
86048524
8605 if (try sema.resolveMaybeUndefVal(operand)) |int_val| {
8525 if (try sema.resolveValue(operand)) |int_val| {
86068526 if (dest_ty.isNonexhaustiveEnum(mod)) {
86078527 const int_tag_ty = dest_ty.intTagType(mod);
86088528 if (try sema.intFitsInType(int_val, int_tag_ty, null)) {
......@@ -9110,7 +9030,7 @@ fn resolveGenericBody(
91109030
91119031 const uncasted = sema.resolveBody(block, body, func_inst) catch |err| break :err err;
91129032 const result = sema.coerce(block, dest_ty, uncasted, src) catch |err| break :err err;
9113 const val = sema.resolveConstValue(block, src, result, reason) catch |err| break :err err;
9033 const val = sema.resolveConstDefinedValue(block, src, result, reason) catch |err| break :err err;
91149034 return val;
91159035 };
91169036 switch (err) {
......@@ -9924,7 +9844,7 @@ fn zirIntFromPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
99249844 };
99259845 return sema.failWithOwnedErrorMsg(block, msg);
99269846 }
9927 if (try sema.resolveMaybeUndefValIntable(operand)) |operand_val| ct: {
9847 if (try sema.resolveValueIntable(operand)) |operand_val| ct: {
99289848 if (!is_vector) {
99299849 return Air.internedToRef((try mod.intValue(
99309850 Type.usize,
......@@ -10390,7 +10310,7 @@ fn zirFloatCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
1039010310 ),
1039110311 }
1039210312
10393 if (try sema.resolveMaybeUndefVal(operand)) |operand_val| {
10313 if (try sema.resolveValue(operand)) |operand_val| {
1039410314 if (!is_vector) {
1039510315 return Air.internedToRef((try operand_val.floatCast(dest_ty, mod)).toIntern());
1039610316 }
......@@ -10788,7 +10708,7 @@ const SwitchProngAnalysis = struct {
1078810708 const operand_src: LazySrcLoc = .{ .node_offset_switch_operand = switch_node_offset };
1078910709
1079010710 if (inline_case_capture != .none) {
10791 const item_val = sema.resolveConstValue(block, .unneeded, inline_case_capture, undefined) catch unreachable;
10711 const item_val = sema.resolveConstDefinedValue(block, .unneeded, inline_case_capture, undefined) catch unreachable;
1079210712 if (operand_ty.zigTypeTag(mod) == .Union) {
1079310713 const field_index: u32 = @intCast(operand_ty.unionTagFieldIndex(item_val, mod).?);
1079410714 const union_obj = mod.typeToUnion(operand_ty).?;
......@@ -10845,14 +10765,14 @@ const SwitchProngAnalysis = struct {
1084510765 switch (operand_ty.zigTypeTag(mod)) {
1084610766 .Union => {
1084710767 const union_obj = mod.typeToUnion(operand_ty).?;
10848 const first_item_val = sema.resolveConstValue(block, .unneeded, case_vals[0], undefined) catch unreachable;
10768 const first_item_val = sema.resolveConstDefinedValue(block, .unneeded, case_vals[0], undefined) catch unreachable;
1084910769
1085010770 const first_field_index: u32 = mod.unionTagFieldIndex(union_obj, first_item_val).?;
1085110771 const first_field_ty = union_obj.field_types.get(ip)[first_field_index].toType();
1085210772
1085310773 const field_tys = try sema.arena.alloc(Type, case_vals.len);
1085410774 for (case_vals, field_tys) |item, *field_ty| {
10855 const item_val = sema.resolveConstValue(block, .unneeded, item, undefined) catch unreachable;
10775 const item_val = sema.resolveConstDefinedValue(block, .unneeded, item, undefined) catch unreachable;
1085610776 const field_idx = mod.unionTagFieldIndex(union_obj, item_val).?;
1085710777 field_ty.* = union_obj.field_types.get(ip)[field_idx].toType();
1085810778 }
......@@ -11101,7 +11021,7 @@ const SwitchProngAnalysis = struct {
1110111021 }
1110211022
1110311023 if (case_vals.len == 1) {
11104 const item_val = sema.resolveConstValue(block, .unneeded, case_vals[0], undefined) catch unreachable;
11024 const item_val = sema.resolveConstDefinedValue(block, .unneeded, case_vals[0], undefined) catch unreachable;
1110511025 const item_ty = try mod.singleErrorSetType(item_val.getErrorName(mod).unwrap().?);
1110611026 return sema.bitCast(block, item_ty, spa.operand, operand_src, null);
1110711027 }
......@@ -11109,7 +11029,7 @@ const SwitchProngAnalysis = struct {
1110911029 var names: InferredErrorSet.NameMap = .{};
1111011030 try names.ensureUnusedCapacity(sema.arena, case_vals.len);
1111111031 for (case_vals) |err| {
11112 const err_val = sema.resolveConstValue(block, .unneeded, err, undefined) catch unreachable;
11032 const err_val = sema.resolveConstDefinedValue(block, .unneeded, err, undefined) catch unreachable;
1111311033 names.putAssumeCapacityNoClobber(err_val.getErrorName(mod).unwrap().?, {});
1111411034 }
1111511035 const error_ty = try mod.errorSetFromUnsortedNames(names.keys());
......@@ -11883,7 +11803,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1188311803 extra_index += info.body_len;
1188411804
1188511805 const item = case_vals.items[scalar_i];
11886 const item_val = sema.resolveConstValue(&child_block, .unneeded, item, undefined) catch unreachable;
11806 const item_val = sema.resolveConstDefinedValue(&child_block, .unneeded, item, undefined) catch unreachable;
1188711807 if (operand_val.eql(item_val, operand_ty, sema.mod)) {
1188811808 if (err_set) try sema.maybeErrorUnwrapComptime(&child_block, body, operand);
1188911809 return spa.resolveProngComptime(
......@@ -11917,7 +11837,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1191711837
1191811838 for (items) |item| {
1191911839 // Validation above ensured these will succeed.
11920 const item_val = sema.resolveConstValue(&child_block, .unneeded, item, undefined) catch unreachable;
11840 const item_val = sema.resolveConstDefinedValue(&child_block, .unneeded, item, undefined) catch unreachable;
1192111841 if (operand_val.eql(item_val, operand_ty, sema.mod)) {
1192211842 if (err_set) try sema.maybeErrorUnwrapComptime(&child_block, body, operand);
1192311843 return spa.resolveProngComptime(
......@@ -11941,8 +11861,8 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1194111861 case_val_idx += 2;
1194211862
1194311863 // Validation above ensured these will succeed.
11944 const first_val = sema.resolveConstValue(&child_block, .unneeded, range_items[0], undefined) catch unreachable;
11945 const last_val = sema.resolveConstValue(&child_block, .unneeded, range_items[1], undefined) catch unreachable;
11864 const first_val = sema.resolveConstDefinedValue(&child_block, .unneeded, range_items[0], undefined) catch unreachable;
11865 const last_val = sema.resolveConstDefinedValue(&child_block, .unneeded, range_items[1], undefined) catch unreachable;
1194611866 if ((try sema.compareAll(resolved_operand_val, .gte, first_val, operand_ty)) and
1194711867 (try sema.compareAll(resolved_operand_val, .lte, last_val, operand_ty)))
1194811868 {
......@@ -12014,7 +11934,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1201411934 }
1201511935
1201611936 if (child_block.is_comptime) {
12017 _ = try sema.resolveConstValue(&child_block, operand_src, operand, .{
11937 _ = try sema.resolveConstDefinedValue(&child_block, operand_src, operand, .{
1201811938 .needed_comptime_reason = "condition in comptime switch must be comptime-known",
1201911939 .block_comptime_reason = child_block.comptime_reason,
1202011940 });
......@@ -12049,7 +11969,8 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1204911969 // `item` is already guaranteed to be constant known.
1205011970
1205111971 const analyze_body = if (union_originally) blk: {
12052 const item_val = sema.resolveConstLazyValue(block, .unneeded, item, undefined) catch unreachable;
11972 const unresolved_item_val = sema.resolveConstDefinedValue(block, .unneeded, item, undefined) catch unreachable;
11973 const item_val = sema.resolveLazyValue(unresolved_item_val) catch unreachable;
1205311974 const field_ty = maybe_union_ty.unionFieldType(item_val, mod).?;
1205411975 break :blk field_ty.zigTypeTag(mod) != .NoReturn;
1205511976 } else true;
......@@ -12117,8 +12038,8 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1211712038 const item_first_ref = range_items[0];
1211812039 const item_last_ref = range_items[1];
1211912040
12120 var item = sema.resolveConstValue(block, .unneeded, item_first_ref, undefined) catch unreachable;
12121 const item_last = sema.resolveConstValue(block, .unneeded, item_last_ref, undefined) catch unreachable;
12041 var item = sema.resolveConstDefinedValue(block, .unneeded, item_first_ref, undefined) catch unreachable;
12042 const item_last = sema.resolveConstDefinedValue(block, .unneeded, item_last_ref, undefined) catch unreachable;
1212212043
1212312044 while (item.compareScalar(.lte, item_last, operand_ty, mod)) : ({
1212412045 // Previous validation has resolved any possible lazy values.
......@@ -12175,7 +12096,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1217512096 case_block.wip_capture_scope = child_block.wip_capture_scope;
1217612097
1217712098 const analyze_body = if (union_originally) blk: {
12178 const item_val = sema.resolveConstValue(block, .unneeded, item, undefined) catch unreachable;
12099 const item_val = sema.resolveConstDefinedValue(block, .unneeded, item, undefined) catch unreachable;
1217912100 const field_ty = maybe_union_ty.unionFieldType(item_val, mod).?;
1218012101 break :blk field_ty.zigTypeTag(mod) != .NoReturn;
1218112102 } else true;
......@@ -12229,7 +12150,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1222912150
1223012151 const analyze_body = if (union_originally)
1223112152 for (items) |item| {
12232 const item_val = sema.resolveConstValue(block, .unneeded, item, undefined) catch unreachable;
12153 const item_val = sema.resolveConstDefinedValue(block, .unneeded, item, undefined) catch unreachable;
1223312154 const field_ty = maybe_union_ty.unionFieldType(item_val, mod).?;
1223412155 if (field_ty.zigTypeTag(mod) != .NoReturn) break true;
1223512156 } else false
......@@ -12719,10 +12640,10 @@ fn resolveSwitchItemVal(
1271912640 else => |e| return e,
1272012641 };
1272112642
12722 const maybe_lazy = sema.resolveConstValue(block, .unneeded, item, undefined) catch |err| switch (err) {
12643 const maybe_lazy = sema.resolveConstDefinedValue(block, .unneeded, item, undefined) catch |err| switch (err) {
1272312644 error.NeededSourceLocation => {
1272412645 const src = switch_prong_src.resolve(mod, mod.declPtr(block.src_decl), switch_node_offset, range_expand);
12725 _ = try sema.resolveConstValue(block, src, item, .{
12646 _ = try sema.resolveConstDefinedValue(block, src, item, .{
1272612647 .needed_comptime_reason = "switch prong values must be comptime-known",
1272712648 });
1272812649 unreachable;
......@@ -13210,8 +13131,8 @@ fn zirShl(
1321013131 // TODO coerce rhs if air_tag is not shl_sat
1321113132 const rhs_is_comptime_int = try sema.checkIntType(block, rhs_src, scalar_rhs_ty);
1321213133
13213 const maybe_lhs_val = try sema.resolveMaybeUndefValIntable(lhs);
13214 const maybe_rhs_val = try sema.resolveMaybeUndefValIntable(rhs);
13134 const maybe_lhs_val = try sema.resolveValueIntable(lhs);
13135 const maybe_rhs_val = try sema.resolveValueIntable(rhs);
1321513136
1321613137 if (maybe_rhs_val) |rhs_val| {
1321713138 if (rhs_val.isUndef(mod)) {
......@@ -13388,8 +13309,8 @@ fn zirShr(
1338813309 try sema.checkVectorizableBinaryOperands(block, src, lhs_ty, rhs_ty, lhs_src, rhs_src);
1338913310 const scalar_ty = lhs_ty.scalarType(mod);
1339013311
13391 const maybe_lhs_val = try sema.resolveMaybeUndefValIntable(lhs);
13392 const maybe_rhs_val = try sema.resolveMaybeUndefValIntable(rhs);
13312 const maybe_lhs_val = try sema.resolveValueIntable(lhs);
13313 const maybe_rhs_val = try sema.resolveValueIntable(rhs);
1339313314
1339413315 const runtime_src = if (maybe_rhs_val) |rhs_val| rs: {
1339513316 if (rhs_val.isUndef(mod)) {
......@@ -13540,8 +13461,8 @@ fn zirBitwise(
1354013461 const runtime_src = runtime: {
1354113462 // TODO: ask the linker what kind of relocations are available, and
1354213463 // in some cases emit a Value that means "this decl's address AND'd with this operand".
13543 if (try sema.resolveMaybeUndefValIntable(casted_lhs)) |lhs_val| {
13544 if (try sema.resolveMaybeUndefValIntable(casted_rhs)) |rhs_val| {
13464 if (try sema.resolveValueIntable(casted_lhs)) |lhs_val| {
13465 if (try sema.resolveValueIntable(casted_rhs)) |rhs_val| {
1354513466 const result_val = switch (air_tag) {
1354613467 .bit_and => try lhs_val.bitwiseAnd(rhs_val, resolved_type, sema.arena, mod),
1354713468 .bit_or => try lhs_val.bitwiseOr(rhs_val, resolved_type, sema.arena, mod),
......@@ -13580,7 +13501,7 @@ fn zirBitNot(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
1358013501 });
1358113502 }
1358213503
13583 if (try sema.resolveMaybeUndefVal(operand)) |val| {
13504 if (try sema.resolveValue(operand)) |val| {
1358413505 if (val.isUndef(mod)) {
1358513506 return mod.undefRef(operand_type);
1358613507 } else if (operand_type.zigTypeTag(mod) == .Vector) {
......@@ -13750,10 +13671,10 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1375013671 const rhs_sent = Air.internedToRef(rhs_sent_val.toIntern());
1375113672 const lhs_sent_casted = try sema.coerce(block, resolved_elem_ty, lhs_sent, lhs_src);
1375213673 const rhs_sent_casted = try sema.coerce(block, resolved_elem_ty, rhs_sent, rhs_src);
13753 const lhs_sent_casted_val = try sema.resolveConstValue(block, lhs_src, lhs_sent_casted, .{
13674 const lhs_sent_casted_val = try sema.resolveConstDefinedValue(block, lhs_src, lhs_sent_casted, .{
1375413675 .needed_comptime_reason = "array sentinel value must be comptime-known",
1375513676 });
13756 const rhs_sent_casted_val = try sema.resolveConstValue(block, rhs_src, rhs_sent_casted, .{
13677 const rhs_sent_casted_val = try sema.resolveConstDefinedValue(block, rhs_src, rhs_sent_casted, .{
1375713678 .needed_comptime_reason = "array sentinel value must be comptime-known",
1375813679 });
1375913680 if (try sema.valuesEqual(lhs_sent_casted_val, rhs_sent_casted_val, resolved_elem_ty)) {
......@@ -13763,7 +13684,7 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1376313684 }
1376413685 } else {
1376513686 const lhs_sent_casted = try sema.coerce(block, resolved_elem_ty, lhs_sent, lhs_src);
13766 const lhs_sent_casted_val = try sema.resolveConstValue(block, lhs_src, lhs_sent_casted, .{
13687 const lhs_sent_casted_val = try sema.resolveConstDefinedValue(block, lhs_src, lhs_sent_casted, .{
1376713688 .needed_comptime_reason = "array sentinel value must be comptime-known",
1376813689 });
1376913690 break :s lhs_sent_casted_val;
......@@ -13772,7 +13693,7 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1377213693 if (rhs_info.sentinel) |rhs_sent_val| {
1377313694 const rhs_sent = Air.internedToRef(rhs_sent_val.toIntern());
1377413695 const rhs_sent_casted = try sema.coerce(block, resolved_elem_ty, rhs_sent, rhs_src);
13775 const rhs_sent_casted_val = try sema.resolveConstValue(block, rhs_src, rhs_sent_casted, .{
13696 const rhs_sent_casted_val = try sema.resolveConstDefinedValue(block, rhs_src, rhs_sent_casted, .{
1377613697 .needed_comptime_reason = "array sentinel value must be comptime-known",
1377713698 });
1377813699 break :s rhs_sent_casted_val;
......@@ -13805,12 +13726,12 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1380513726 };
1380613727
1380713728 const runtime_src = if (switch (lhs_ty.zigTypeTag(mod)) {
13808 .Array, .Struct => try sema.resolveMaybeUndefVal(lhs),
13729 .Array, .Struct => try sema.resolveValue(lhs),
1380913730 .Pointer => try sema.resolveDefinedValue(block, lhs_src, lhs),
1381013731 else => unreachable,
1381113732 }) |lhs_val| rs: {
1381213733 if (switch (rhs_ty.zigTypeTag(mod)) {
13813 .Array, .Struct => try sema.resolveMaybeUndefVal(rhs),
13734 .Array, .Struct => try sema.resolveValue(rhs),
1381413735 .Pointer => try sema.resolveDefinedValue(block, rhs_src, rhs),
1381513736 else => unreachable,
1381613737 }) |rhs_val| {
......@@ -13832,7 +13753,7 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1383213753 const elem_val = if (elem_default_val.toIntern() == .unreachable_value) try lhs_sub_val.elemValue(mod, lhs_elem_i) else elem_default_val;
1383313754 const elem_val_inst = Air.internedToRef(elem_val.toIntern());
1383413755 const coerced_elem_val_inst = try sema.coerce(block, resolved_elem_ty, elem_val_inst, .unneeded);
13835 const coerced_elem_val = try sema.resolveConstMaybeUndefVal(block, .unneeded, coerced_elem_val_inst, undefined);
13756 const coerced_elem_val = try sema.resolveConstValue(block, .unneeded, coerced_elem_val_inst, undefined);
1383613757 element_vals[elem_i] = try coerced_elem_val.intern(resolved_elem_ty, mod);
1383713758 }
1383813759 while (elem_i < result_len) : (elem_i += 1) {
......@@ -13841,7 +13762,7 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1384113762 const elem_val = if (elem_default_val.toIntern() == .unreachable_value) try rhs_sub_val.elemValue(mod, rhs_elem_i) else elem_default_val;
1384213763 const elem_val_inst = Air.internedToRef(elem_val.toIntern());
1384313764 const coerced_elem_val_inst = try sema.coerce(block, resolved_elem_ty, elem_val_inst, .unneeded);
13844 const coerced_elem_val = try sema.resolveConstMaybeUndefVal(block, .unneeded, coerced_elem_val_inst, undefined);
13765 const coerced_elem_val = try sema.resolveConstValue(block, .unneeded, coerced_elem_val_inst, undefined);
1384513766 element_vals[elem_i] = try coerced_elem_val.intern(resolved_elem_ty, mod);
1384613767 }
1384713768 return sema.addConstantMaybeRef(block, result_ty, (try mod.intern(.{ .aggregate = .{
......@@ -13918,7 +13839,7 @@ fn getArrayCatInfo(sema: *Sema, block: *Block, src: LazySrcLoc, operand: Air.Ins
1391813839 // has a sentinel, and this code should compute the length based
1391913840 // on the sentinel value.
1392013841 .Slice, .Many => {
13921 const val = try sema.resolveConstValue(block, src, operand, .{
13842 const val = try sema.resolveConstDefinedValue(block, src, operand, .{
1392213843 .needed_comptime_reason = "slice value being concatenated must be comptime-known",
1392313844 });
1392413845 return Type.ArrayInfo{
......@@ -14186,7 +14107,7 @@ fn zirNegate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
1418614107
1418714108 if (rhs_scalar_ty.isAnyFloat()) {
1418814109 // We handle float negation here to ensure negative zero is represented in the bits.
14189 if (try sema.resolveMaybeUndefVal(rhs)) |rhs_val| {
14110 if (try sema.resolveValue(rhs)) |rhs_val| {
1419014111 if (rhs_val.isUndef(mod)) return mod.undefRef(rhs_ty);
1419114112 return Air.internedToRef((try rhs_val.floatNeg(rhs_ty, sema.arena, mod)).toIntern());
1419214113 }
......@@ -14272,8 +14193,8 @@ fn zirDiv(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins
1427214193
1427314194 try sema.checkArithmeticOp(block, src, scalar_tag, lhs_zig_ty_tag, rhs_zig_ty_tag, .div);
1427414195
14275 const maybe_lhs_val = try sema.resolveMaybeUndefValIntable(casted_lhs);
14276 const maybe_rhs_val = try sema.resolveMaybeUndefValIntable(casted_rhs);
14196 const maybe_lhs_val = try sema.resolveValueIntable(casted_lhs);
14197 const maybe_rhs_val = try sema.resolveValueIntable(casted_rhs);
1427714198
1427814199 if ((lhs_ty.zigTypeTag(mod) == .ComptimeFloat and rhs_ty.zigTypeTag(mod) == .ComptimeInt) or
1427914200 (lhs_ty.zigTypeTag(mod) == .ComptimeInt and rhs_ty.zigTypeTag(mod) == .ComptimeFloat))
......@@ -14437,8 +14358,8 @@ fn zirDivExact(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1443714358
1443814359 try sema.checkArithmeticOp(block, src, scalar_tag, lhs_zig_ty_tag, rhs_zig_ty_tag, .div_exact);
1443914360
14440 const maybe_lhs_val = try sema.resolveMaybeUndefValIntable(casted_lhs);
14441 const maybe_rhs_val = try sema.resolveMaybeUndefValIntable(casted_rhs);
14361 const maybe_lhs_val = try sema.resolveValueIntable(casted_lhs);
14362 const maybe_rhs_val = try sema.resolveValueIntable(casted_rhs);
1444214363
1444314364 const runtime_src = rs: {
1444414365 // For integers:
......@@ -14604,8 +14525,8 @@ fn zirDivFloor(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1460414525
1460514526 try sema.checkArithmeticOp(block, src, scalar_tag, lhs_zig_ty_tag, rhs_zig_ty_tag, .div_floor);
1460614527
14607 const maybe_lhs_val = try sema.resolveMaybeUndefValIntable(casted_lhs);
14608 const maybe_rhs_val = try sema.resolveMaybeUndefValIntable(casted_rhs);
14528 const maybe_lhs_val = try sema.resolveValueIntable(casted_lhs);
14529 const maybe_rhs_val = try sema.resolveValueIntable(casted_rhs);
1460914530
1461014531 const runtime_src = rs: {
1461114532 // For integers:
......@@ -14715,8 +14636,8 @@ fn zirDivTrunc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1471514636
1471614637 try sema.checkArithmeticOp(block, src, scalar_tag, lhs_zig_ty_tag, rhs_zig_ty_tag, .div_trunc);
1471714638
14718 const maybe_lhs_val = try sema.resolveMaybeUndefValIntable(casted_lhs);
14719 const maybe_rhs_val = try sema.resolveMaybeUndefValIntable(casted_rhs);
14639 const maybe_lhs_val = try sema.resolveValueIntable(casted_lhs);
14640 const maybe_rhs_val = try sema.resolveValueIntable(casted_rhs);
1472014641
1472114642 const runtime_src = rs: {
1472214643 // For integers:
......@@ -14959,8 +14880,8 @@ fn zirModRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
1495914880
1496014881 try sema.checkArithmeticOp(block, src, scalar_tag, lhs_zig_ty_tag, rhs_zig_ty_tag, .mod_rem);
1496114882
14962 const maybe_lhs_val = try sema.resolveMaybeUndefValIntable(casted_lhs);
14963 const maybe_rhs_val = try sema.resolveMaybeUndefValIntable(casted_rhs);
14883 const maybe_lhs_val = try sema.resolveValueIntable(casted_lhs);
14884 const maybe_rhs_val = try sema.resolveValueIntable(casted_rhs);
1496414885
1496514886 const runtime_src = rs: {
1496614887 // For integers:
......@@ -15140,8 +15061,8 @@ fn zirMod(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins
1514015061
1514115062 try sema.checkArithmeticOp(block, src, scalar_tag, lhs_zig_ty_tag, rhs_zig_ty_tag, .mod);
1514215063
15143 const maybe_lhs_val = try sema.resolveMaybeUndefValIntable(casted_lhs);
15144 const maybe_rhs_val = try sema.resolveMaybeUndefValIntable(casted_rhs);
15064 const maybe_lhs_val = try sema.resolveValueIntable(casted_lhs);
15065 const maybe_rhs_val = try sema.resolveValueIntable(casted_rhs);
1514515066
1514615067 const runtime_src = rs: {
1514715068 // For integers:
......@@ -15236,8 +15157,8 @@ fn zirRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins
1523615157
1523715158 try sema.checkArithmeticOp(block, src, scalar_tag, lhs_zig_ty_tag, rhs_zig_ty_tag, .rem);
1523815159
15239 const maybe_lhs_val = try sema.resolveMaybeUndefValIntable(casted_lhs);
15240 const maybe_rhs_val = try sema.resolveMaybeUndefValIntable(casted_rhs);
15160 const maybe_lhs_val = try sema.resolveValueIntable(casted_lhs);
15161 const maybe_rhs_val = try sema.resolveValueIntable(casted_rhs);
1524115162
1524215163 const runtime_src = rs: {
1524315164 // For integers:
......@@ -15346,8 +15267,8 @@ fn zirOverflowArithmetic(
1534615267 return sema.fail(block, src, "expected vector of integers or integer tag type, found '{}'", .{dest_ty.fmt(mod)});
1534715268 }
1534815269
15349 const maybe_lhs_val = try sema.resolveMaybeUndefVal(lhs);
15350 const maybe_rhs_val = try sema.resolveMaybeUndefVal(rhs);
15270 const maybe_lhs_val = try sema.resolveValue(lhs);
15271 const maybe_rhs_val = try sema.resolveValue(rhs);
1535115272
1535215273 const tuple_ty = try sema.overflowArithmeticTupleType(dest_ty);
1535315274 const overflow_ty = ip.indexToKey(tuple_ty.toIntern()).anon_struct_type.types.get(ip)[1].toType();
......@@ -15490,7 +15411,7 @@ fn zirOverflowArithmetic(
1549015411 };
1549115412
1549215413 if (result.inst != .none) {
15493 if (try sema.resolveMaybeUndefVal(result.inst)) |some| {
15414 if (try sema.resolveValue(result.inst)) |some| {
1549415415 result.wrapped = some;
1549515416 result.inst = .none;
1549615417 }
......@@ -15586,8 +15507,8 @@ fn analyzeArithmetic(
1558615507
1558715508 try sema.checkArithmeticOp(block, src, scalar_tag, lhs_zig_ty_tag, rhs_zig_ty_tag, zir_tag);
1558815509
15589 const maybe_lhs_val = try sema.resolveMaybeUndefValIntable(casted_lhs);
15590 const maybe_rhs_val = try sema.resolveMaybeUndefValIntable(casted_rhs);
15510 const maybe_lhs_val = try sema.resolveValueIntable(casted_lhs);
15511 const maybe_rhs_val = try sema.resolveValueIntable(casted_rhs);
1559115512 const runtime_src: LazySrcLoc, const air_tag: Air.Inst.Tag, const air_tag_safe: Air.Inst.Tag = rs: {
1559215513 switch (zir_tag) {
1559315514 .add, .add_unsafe => {
......@@ -16036,7 +15957,7 @@ fn analyzePtrArithmetic(
1603615957 // coerce to isize instead of usize.
1603715958 const offset = try sema.coerce(block, Type.usize, uncasted_offset, offset_src);
1603815959 const mod = sema.mod;
16039 const opt_ptr_val = try sema.resolveMaybeUndefVal(ptr);
15960 const opt_ptr_val = try sema.resolveValue(ptr);
1604015961 const opt_off_val = try sema.resolveDefinedValue(block, offset_src, offset);
1604115962 const ptr_ty = sema.typeOf(ptr);
1604215963 const ptr_info = ptr_ty.ptrInfo(mod);
......@@ -16342,8 +16263,8 @@ fn zirCmpEq(
1634216263
1634316264 if (lhs_ty_tag == .ErrorSet and rhs_ty_tag == .ErrorSet) {
1634416265 const runtime_src: LazySrcLoc = src: {
16345 if (try sema.resolveMaybeUndefVal(lhs)) |lval| {
16346 if (try sema.resolveMaybeUndefVal(rhs)) |rval| {
16266 if (try sema.resolveValue(lhs)) |lval| {
16267 if (try sema.resolveValue(rhs)) |rval| {
1634716268 if (lval.isUndef(mod) or rval.isUndef(mod)) {
1634816269 return mod.undefRef(Type.bool);
1634916270 }
......@@ -16398,7 +16319,7 @@ fn analyzeCmpUnionTag(
1639816319 const coerced_tag = try sema.coerce(block, union_tag_ty, tag, tag_src);
1639916320 const coerced_union = try sema.coerce(block, union_tag_ty, un, un_src);
1640016321
16401 if (try sema.resolveMaybeUndefVal(coerced_tag)) |enum_val| {
16322 if (try sema.resolveValue(coerced_tag)) |enum_val| {
1640216323 if (enum_val.isUndef(mod)) return mod.undefRef(Type.bool);
1640316324 const field_ty = union_ty.unionFieldType(enum_val, mod).?;
1640416325 if (field_ty.zigTypeTag(mod) == .NoReturn) {
......@@ -16500,9 +16421,9 @@ fn cmpSelf(
1650016421 const mod = sema.mod;
1650116422 const resolved_type = sema.typeOf(casted_lhs);
1650216423 const runtime_src: LazySrcLoc = src: {
16503 if (try sema.resolveMaybeUndefVal(casted_lhs)) |lhs_val| {
16424 if (try sema.resolveValue(casted_lhs)) |lhs_val| {
1650416425 if (lhs_val.isUndef(mod)) return mod.undefRef(Type.bool);
16505 if (try sema.resolveMaybeUndefVal(casted_rhs)) |rhs_val| {
16426 if (try sema.resolveValue(casted_rhs)) |rhs_val| {
1650616427 if (rhs_val.isUndef(mod)) return mod.undefRef(Type.bool);
1650716428
1650816429 if (resolved_type.zigTypeTag(mod) == .Vector) {
......@@ -16525,7 +16446,7 @@ fn cmpSelf(
1652516446 // For bools, we still check the other operand, because we can lower
1652616447 // bool eq/neq more efficiently.
1652716448 if (resolved_type.zigTypeTag(mod) == .Bool) {
16528 if (try sema.resolveMaybeUndefVal(casted_rhs)) |rhs_val| {
16449 if (try sema.resolveValue(casted_rhs)) |rhs_val| {
1652916450 if (rhs_val.isUndef(mod)) return mod.undefRef(Type.bool);
1653016451 return sema.runtimeBoolCmp(block, src, op, casted_lhs, rhs_val.toBool(), lhs_src);
1653116452 }
......@@ -16671,7 +16592,7 @@ fn zirClosureCapture(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr
1667116592 .zir_index = inst,
1667216593 .index = block.wip_capture_scope,
1667316594 };
16674 if (try sema.resolveMaybeUndefValAllowVariables(operand)) |val| {
16595 if (try sema.resolveValue(operand)) |val| {
1667516596 try mod.comptime_capture_scopes.put(gpa, key, try val.intern(ty, mod));
1667616597 } else {
1667716598 try mod.runtime_capture_scopes.put(gpa, key, ty.toIntern());
......@@ -18156,7 +18077,7 @@ fn zirBoolNot(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1815618077 const uncasted_operand = try sema.resolveInst(inst_data.operand);
1815718078
1815818079 const operand = try sema.coerce(block, Type.bool, uncasted_operand, operand_src);
18159 if (try sema.resolveMaybeUndefVal(operand)) |val| {
18080 if (try sema.resolveValue(operand)) |val| {
1816018081 return if (val.isUndef(mod))
1816118082 mod.undefRef(Type.bool)
1816218083 else if (val.toBool()) .bool_false else .bool_true;
......@@ -18315,7 +18236,7 @@ fn zirIsNonNullPtr(
1831518236 const src = inst_data.src();
1831618237 const ptr = try sema.resolveInst(inst_data.operand);
1831718238 try sema.checkNullableType(block, src, sema.typeOf(ptr).elemType2(mod));
18318 if ((try sema.resolveMaybeUndefVal(ptr)) == null) {
18239 if ((try sema.resolveValue(ptr)) == null) {
1831918240 return block.addUnOp(.is_non_null_ptr, ptr);
1832018241 }
1832118242 const loaded = try sema.analyzeLoad(block, src, ptr, src);
......@@ -18910,7 +18831,7 @@ fn analyzeRet(
1891018831
1891118832 if (block.inlining) |inlining| {
1891218833 if (block.is_comptime) {
18913 _ = try sema.resolveConstMaybeUndefVal(block, src, operand, .{
18834 _ = try sema.resolveConstValue(block, src, operand, .{
1891418835 .needed_comptime_reason = "value being returned at comptime must be comptime-known",
1891518836 });
1891618837 inlining.comptime_result = operand;
......@@ -18992,7 +18913,7 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1899218913 const ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_i]);
1899318914 extra_i += 1;
1899418915 const coerced = try sema.coerce(block, elem_ty, try sema.resolveInst(ref), sentinel_src);
18995 const val = try sema.resolveConstValue(block, sentinel_src, coerced, .{
18916 const val = try sema.resolveConstDefinedValue(block, sentinel_src, coerced, .{
1899618917 .needed_comptime_reason = "pointer sentinel value must be comptime-known",
1899718918 });
1899818919 break :blk val.toIntern();
......@@ -19002,7 +18923,7 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1900218923 const ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_i]);
1900318924 extra_i += 1;
1900418925 const coerced = try sema.coerce(block, Type.u32, try sema.resolveInst(ref), align_src);
19005 const val = try sema.resolveConstValue(block, align_src, coerced, .{
18926 const val = try sema.resolveConstDefinedValue(block, align_src, coerced, .{
1900618927 .needed_comptime_reason = "pointer alignment must be comptime-known",
1900718928 });
1900818929 // Check if this happens to be the lazy alignment of our element type, in
......@@ -19150,7 +19071,7 @@ fn zirStructInitEmptyResult(sema: *Sema, block: *Block, inst: Zir.Inst.Index, is
1915019071 const init_ref = try sema.coerce(block, init_ty, empty_ref, src);
1915119072
1915219073 if (is_byref) {
19153 const init_val = (try sema.resolveMaybeUndefVal(init_ref)).?;
19074 const init_val = (try sema.resolveValue(init_ref)).?;
1915419075 var anon_decl = try block.startAnonDecl();
1915519076 defer anon_decl.deinit();
1915619077 const decl = try anon_decl.finish(init_ty, init_val, .none);
......@@ -19235,7 +19156,7 @@ fn unionInit(
1923519156 const field_ty = mod.typeToUnion(union_ty).?.field_types.get(ip)[field_index].toType();
1923619157 const init = try sema.coerce(block, field_ty, uncasted_init, init_src);
1923719158
19238 if (try sema.resolveMaybeUndefVal(init)) |init_val| {
19159 if (try sema.resolveValue(init)) |init_val| {
1923919160 const tag_ty = union_ty.unionTagTypeHypothetical(mod);
1924019161 const tag_val = try mod.enumValueFieldIndex(tag_ty, field_index);
1924119162 return Air.internedToRef((try mod.intern(.{ .un = .{
......@@ -19324,7 +19245,7 @@ fn zirStructInit(
1932419245 const field_ty = resolved_ty.structFieldType(field_index, mod);
1932519246 field_inits[field_index] = try sema.coerce(block, field_ty, uncoerced_init, field_src);
1932619247 if (!is_packed) if (try resolved_ty.structFieldValueComptime(mod, field_index)) |default_value| {
19327 const init_val = (try sema.resolveMaybeUndefVal(field_inits[field_index])) orelse {
19248 const init_val = (try sema.resolveValue(field_inits[field_index])) orelse {
1932819249 return sema.failWithNeededComptime(block, field_src, .{
1932919250 .needed_comptime_reason = "value stored in comptime field must be comptime-known",
1933019251 });
......@@ -19369,14 +19290,14 @@ fn zirStructInit(
1936919290 const uncoerced_init_inst = try sema.resolveInst(item.data.init);
1937019291 const init_inst = try sema.coerce(block, field_ty, uncoerced_init_inst, field_src);
1937119292
19372 if (try sema.resolveMaybeUndefVal(init_inst)) |val| {
19293 if (try sema.resolveValue(init_inst)) |val| {
1937319294 const struct_val = (try mod.intern(.{ .un = .{
1937419295 .ty = resolved_ty.toIntern(),
1937519296 .tag = try tag_val.intern(tag_ty, mod),
1937619297 .val = try val.intern(field_ty, mod),
1937719298 } })).toValue();
1937819299 const final_val_inst = try sema.coerce(block, result_ty, Air.internedToRef(struct_val.toIntern()), src);
19379 const final_val = (try sema.resolveMaybeUndefVal(final_val_inst)).?;
19300 const final_val = (try sema.resolveValue(final_val_inst)).?;
1938019301 return sema.addConstantMaybeRef(block, resolved_ty, final_val, is_ref);
1938119302 }
1938219303
......@@ -19529,14 +19450,14 @@ fn finishStructInit(
1952919450 const runtime_index = opt_runtime_index orelse {
1953019451 const elems = try sema.arena.alloc(InternPool.Index, field_inits.len);
1953119452 for (elems, field_inits) |*elem, field_init| {
19532 elem.* = (sema.resolveMaybeUndefVal(field_init) catch unreachable).?.toIntern();
19453 elem.* = (sema.resolveValue(field_init) catch unreachable).?.toIntern();
1953319454 }
1953419455 const struct_val = try mod.intern(.{ .aggregate = .{
1953519456 .ty = struct_ty.toIntern(),
1953619457 .storage = .{ .elems = elems },
1953719458 } });
1953819459 const final_val_inst = try sema.coerce(block, result_ty, Air.internedToRef(struct_val), init_src);
19539 const final_val = (try sema.resolveMaybeUndefVal(final_val_inst)).?;
19460 const final_val = (try sema.resolveValue(final_val_inst)).?;
1954019461 return sema.addConstantMaybeRef(block, result_ty, final_val, is_ref);
1954119462 };
1954219463
......@@ -19669,7 +19590,7 @@ fn structInitAnon(
1966919590 };
1967019591 return sema.failWithOwnedErrorMsg(block, msg);
1967119592 }
19672 if (try sema.resolveMaybeUndefVal(init)) |init_val| {
19593 if (try sema.resolveValue(init)) |init_val| {
1967319594 values[i] = try init_val.intern(field_ty.toType(), mod);
1967419595 } else {
1967519596 values[i] = .none;
......@@ -19815,7 +19736,7 @@ fn zirArrayInit(
1981519736 else => return err,
1981619737 };
1981719738 if (is_tuple) if (try array_ty.structFieldValueComptime(mod, i)) |field_val| {
19818 const init_val = try sema.resolveMaybeUndefVal(dest.*) orelse {
19739 const init_val = try sema.resolveValue(dest.*) orelse {
1981919740 const decl = mod.declPtr(block.src_decl);
1982019741 const elem_src = mod.initSrc(src.node_offset.x, decl, i);
1982119742 return sema.failWithNeededComptime(block, elem_src, .{
......@@ -19849,14 +19770,14 @@ fn zirArrayInit(
1984919770 else
1985019771 array_ty.elemType2(mod);
1985119772 // We checked that all args are comptime above.
19852 val.* = try ((sema.resolveMaybeUndefVal(arg) catch unreachable).?).intern(elem_ty, mod);
19773 val.* = try ((sema.resolveValue(arg) catch unreachable).?).intern(elem_ty, mod);
1985319774 }
1985419775 const arr_val = try mod.intern(.{ .aggregate = .{
1985519776 .ty = array_ty.toIntern(),
1985619777 .storage = .{ .elems = elem_vals },
1985719778 } });
1985819779 const result_ref = try sema.coerce(block, result_ty, Air.internedToRef(arr_val), src);
19859 return sema.addConstantMaybeRef(block, result_ty, (try sema.resolveMaybeUndefVal(result_ref)).?, is_ref);
19780 return sema.addConstantMaybeRef(block, result_ty, (try sema.resolveValue(result_ref)).?, is_ref);
1986019781 };
1986119782
1986219783 sema.requireRuntimeBlock(block, .unneeded, null) catch |err| switch (err) {
......@@ -19954,7 +19875,7 @@ fn arrayInitAnon(
1995419875 };
1995519876 return sema.failWithOwnedErrorMsg(block, msg);
1995619877 }
19957 if (try sema.resolveMaybeUndefVal(elem)) |val| {
19878 if (try sema.resolveValue(elem)) |val| {
1995819879 values[i] = val.toIntern();
1995919880 } else {
1996019881 values[i] = .none;
......@@ -20177,7 +20098,7 @@ fn zirIntFromBool(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
2017720098 if (operand_scalar_ty.toIntern() != .bool_type) {
2017820099 return sema.fail(block, src, "expected 'bool', found '{}'", .{operand_scalar_ty.zigTypeTag(mod)});
2017920100 }
20180 if (try sema.resolveMaybeUndefVal(operand)) |val| {
20101 if (try sema.resolveValue(operand)) |val| {
2018120102 if (!is_vector) {
2018220103 if (val.isUndef(mod)) return mod.undefRef(Type.u1);
2018320104 if (val.toBool()) return Air.internedToRef((try mod.intValue(Type.u1, 1)).toIntern());
......@@ -20268,7 +20189,7 @@ fn maybeConstantUnaryMath(
2026820189) CompileError!?Air.Inst.Ref {
2026920190 const mod = sema.mod;
2027020191 switch (result_ty.zigTypeTag(mod)) {
20271 .Vector => if (try sema.resolveMaybeUndefVal(operand)) |val| {
20192 .Vector => if (try sema.resolveValue(operand)) |val| {
2027220193 const scalar_ty = result_ty.scalarType(mod);
2027320194 const vec_len = result_ty.vectorLen(mod);
2027420195 if (val.isUndef(mod))
......@@ -20284,7 +20205,7 @@ fn maybeConstantUnaryMath(
2028420205 .storage = .{ .elems = elems },
2028520206 } })));
2028620207 },
20287 else => if (try sema.resolveMaybeUndefVal(operand)) |operand_val| {
20208 else => if (try sema.resolveValue(operand)) |operand_val| {
2028820209 if (operand_val.isUndef(mod))
2028920210 return try mod.undefRef(result_ty);
2029020211 const result_val = try eval(operand_val, result_ty, sema.arena, sema.mod);
......@@ -20339,7 +20260,7 @@ fn zirTagName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
2033920260 try sema.resolveTypeLayout(operand_ty);
2034020261 const enum_ty = switch (operand_ty.zigTypeTag(mod)) {
2034120262 .EnumLiteral => {
20342 const val = try sema.resolveConstValue(block, .unneeded, operand, undefined);
20263 const val = try sema.resolveConstDefinedValue(block, .unneeded, operand, undefined);
2034320264 const tag_name = ip.indexToKey(val.toIntern()).enum_literal;
2034420265 return sema.addStrLit(ip.stringToSlice(tag_name));
2034520266 },
......@@ -20412,7 +20333,7 @@ fn zirReify(
2041220333 const uncasted_operand = try sema.resolveInst(extra.operand);
2041320334 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node };
2041420335 const type_info = try sema.coerce(block, type_info_ty, uncasted_operand, operand_src);
20415 const val = try sema.resolveConstValue(block, operand_src, type_info, .{
20336 const val = try sema.resolveConstDefinedValue(block, operand_src, type_info, .{
2041620337 .needed_comptime_reason = "operand to @Type must be comptime-known",
2041720338 });
2041820339 const union_val = ip.indexToKey(val.toIntern()).un;
......@@ -21563,7 +21484,7 @@ fn zirIntFromFloat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
2156321484 _ = try sema.checkIntType(block, src, dest_scalar_ty);
2156421485 try sema.checkFloatType(block, operand_src, operand_scalar_ty);
2156521486
21566 if (try sema.resolveMaybeUndefVal(operand)) |operand_val| {
21487 if (try sema.resolveValue(operand)) |operand_val| {
2156721488 const result_val = try sema.intFromFloat(block, operand_src, operand_val, operand_ty, dest_ty, .truncate);
2156821489 return Air.internedToRef(result_val.toIntern());
2156921490 } else if (dest_scalar_ty.zigTypeTag(mod) == .ComptimeInt) {
......@@ -21645,7 +21566,7 @@ fn zirFloatFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
2164521566 try sema.checkFloatType(block, src, dest_scalar_ty);
2164621567 _ = try sema.checkIntType(block, operand_src, operand_scalar_ty);
2164721568
21648 if (try sema.resolveMaybeUndefVal(operand)) |operand_val| {
21569 if (try sema.resolveValue(operand)) |operand_val| {
2164921570 const result_val = try operand_val.floatFromIntAdvanced(sema.arena, operand_ty, dest_ty, mod, sema);
2165021571 return Air.internedToRef(result_val.toIntern());
2165121572 } else if (dest_scalar_ty.zigTypeTag(mod) == .ComptimeFloat) {
......@@ -22235,7 +22156,7 @@ fn ptrCastFull(
2223522156
2223622157 // Cannot do @addrSpaceCast at comptime
2223722158 if (!flags.addrspace_cast) {
22238 if (try sema.resolveMaybeUndefVal(ptr)) |ptr_val| {
22159 if (try sema.resolveValue(ptr)) |ptr_val| {
2223922160 if (!dest_ty.ptrAllowsZero(mod) and ptr_val.isUndef(mod)) {
2224022161 return sema.failWithUseOfUndef(block, operand_src);
2224122162 }
......@@ -22363,7 +22284,7 @@ fn zirPtrCastNoDest(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.Inst
2236322284 if (flags.volatile_cast) ptr_info.flags.is_volatile = false;
2236422285 const dest_ty = try sema.ptrType(ptr_info);
2236522286
22366 if (try sema.resolveMaybeUndefVal(operand)) |operand_val| {
22287 if (try sema.resolveValue(operand)) |operand_val| {
2236722288 return Air.internedToRef((try mod.getCoerced(operand_val, dest_ty)).toIntern());
2236822289 }
2236922290
......@@ -22433,7 +22354,7 @@ fn zirTruncate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
2243322354 }
2243422355 }
2243522356
22436 if (try sema.resolveMaybeUndefValIntable(operand)) |val| {
22357 if (try sema.resolveValueIntable(operand)) |val| {
2243722358 if (val.isUndef(mod)) return mod.undefRef(dest_ty);
2243822359 if (!dest_is_vector) {
2243922360 return Air.internedToRef((try mod.getCoerced(
......@@ -22484,7 +22405,7 @@ fn zirBitCount(
2248422405 .len = vec_len,
2248522406 .child = result_scalar_ty.toIntern(),
2248622407 });
22487 if (try sema.resolveMaybeUndefVal(operand)) |val| {
22408 if (try sema.resolveValue(operand)) |val| {
2248822409 if (val.isUndef(mod)) return mod.undefRef(result_ty);
2248922410
2249022411 const elems = try sema.arena.alloc(InternPool.Index, vec_len);
......@@ -22504,7 +22425,7 @@ fn zirBitCount(
2250422425 }
2250522426 },
2250622427 .Int => {
22507 if (try sema.resolveMaybeUndefLazyVal(operand)) |val| {
22428 if (try sema.resolveValueResolveLazy(operand)) |val| {
2250822429 if (val.isUndef(mod)) return mod.undefRef(result_scalar_ty);
2250922430 return mod.intRef(result_scalar_ty, comptimeOp(val, operand_ty, mod));
2251022431 } else {
......@@ -22540,7 +22461,7 @@ fn zirByteSwap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
2254022461
2254122462 switch (operand_ty.zigTypeTag(mod)) {
2254222463 .Int => {
22543 const runtime_src = if (try sema.resolveMaybeUndefVal(operand)) |val| {
22464 const runtime_src = if (try sema.resolveValue(operand)) |val| {
2254422465 if (val.isUndef(mod)) return mod.undefRef(operand_ty);
2254522466 const result_val = try val.byteSwap(operand_ty, mod, sema.arena);
2254622467 return Air.internedToRef(result_val.toIntern());
......@@ -22550,7 +22471,7 @@ fn zirByteSwap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
2255022471 return block.addTyOp(.byte_swap, operand_ty, operand);
2255122472 },
2255222473 .Vector => {
22553 const runtime_src = if (try sema.resolveMaybeUndefVal(operand)) |val| {
22474 const runtime_src = if (try sema.resolveValue(operand)) |val| {
2255422475 if (val.isUndef(mod))
2255522476 return mod.undefRef(operand_ty);
2255622477
......@@ -22588,7 +22509,7 @@ fn zirBitReverse(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
2258822509 const mod = sema.mod;
2258922510 switch (operand_ty.zigTypeTag(mod)) {
2259022511 .Int => {
22591 const runtime_src = if (try sema.resolveMaybeUndefVal(operand)) |val| {
22512 const runtime_src = if (try sema.resolveValue(operand)) |val| {
2259222513 if (val.isUndef(mod)) return mod.undefRef(operand_ty);
2259322514 const result_val = try val.bitReverse(operand_ty, mod, sema.arena);
2259422515 return Air.internedToRef(result_val.toIntern());
......@@ -22598,7 +22519,7 @@ fn zirBitReverse(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
2259822519 return block.addTyOp(.bit_reverse, operand_ty, operand);
2259922520 },
2260022521 .Vector => {
22601 const runtime_src = if (try sema.resolveMaybeUndefVal(operand)) |val| {
22522 const runtime_src = if (try sema.resolveValue(operand)) |val| {
2260222523 if (val.isUndef(mod))
2260322524 return mod.undefRef(operand_ty);
2260422525
......@@ -23044,8 +22965,8 @@ fn checkSimdBinOp(
2304422965 .len = vec_len,
2304522966 .lhs = lhs,
2304622967 .rhs = rhs,
23047 .lhs_val = try sema.resolveMaybeUndefVal(lhs),
23048 .rhs_val = try sema.resolveMaybeUndefVal(rhs),
22968 .lhs_val = try sema.resolveValue(lhs),
22969 .rhs_val = try sema.resolveValue(rhs),
2304922970 .result_ty = result_ty,
2305022971 .scalar_ty = result_ty.scalarType(mod),
2305122972 };
......@@ -23131,20 +23052,20 @@ fn resolveExportOptions(
2313123052 const visibility_src = sema.maybeOptionsSrc(block, src, "visibility");
2313223053
2313323054 const name_operand = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "name"), name_src);
23134 const name_val = try sema.resolveConstValue(block, name_src, name_operand, .{
23055 const name_val = try sema.resolveConstDefinedValue(block, name_src, name_operand, .{
2313523056 .needed_comptime_reason = "name of exported value must be comptime-known",
2313623057 });
2313723058 const name_ty = Type.slice_const_u8;
2313823059 const name = try name_val.toAllocatedBytes(name_ty, sema.arena, mod);
2313923060
2314023061 const linkage_operand = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "linkage"), linkage_src);
23141 const linkage_val = try sema.resolveConstValue(block, linkage_src, linkage_operand, .{
23062 const linkage_val = try sema.resolveConstDefinedValue(block, linkage_src, linkage_operand, .{
2314223063 .needed_comptime_reason = "linkage of exported value must be comptime-known",
2314323064 });
2314423065 const linkage = mod.toEnum(std.builtin.GlobalLinkage, linkage_val);
2314523066
2314623067 const section_operand = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "section"), section_src);
23147 const section_opt_val = try sema.resolveConstValue(block, section_src, section_operand, .{
23068 const section_opt_val = try sema.resolveConstDefinedValue(block, section_src, section_operand, .{
2314823069 .needed_comptime_reason = "linksection of exported value must be comptime-known",
2314923070 });
2315023071 const section_ty = Type.slice_const_u8;
......@@ -23154,7 +23075,7 @@ fn resolveExportOptions(
2315423075 null;
2315523076
2315623077 const visibility_operand = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "visibility"), visibility_src);
23157 const visibility_val = try sema.resolveConstValue(block, visibility_src, visibility_operand, .{
23078 const visibility_val = try sema.resolveConstDefinedValue(block, visibility_src, visibility_operand, .{
2315823079 .needed_comptime_reason = "visibility of exported value must be comptime-known",
2315923080 });
2316023081 const visibility = mod.toEnum(std.builtin.SymbolVisibility, visibility_val);
......@@ -23189,7 +23110,7 @@ fn resolveBuiltinEnum(
2318923110 const ty = try sema.getBuiltinType(name);
2319023111 const air_ref = try sema.resolveInst(zir_ref);
2319123112 const coerced = try sema.coerce(block, ty, air_ref, src);
23192 const val = try sema.resolveConstValue(block, src, coerced, reason);
23113 const val = try sema.resolveConstDefinedValue(block, src, coerced, reason);
2319323114 return mod.toEnum(@field(std.builtin, name), val);
2319423115}
2319523116
......@@ -23279,8 +23200,8 @@ fn zirCmpxchg(
2327923200 }
2328023201
2328123202 const runtime_src = if (try sema.resolveDefinedValue(block, ptr_src, ptr)) |ptr_val| rs: {
23282 if (try sema.resolveMaybeUndefVal(expected_value)) |expected_val| {
23283 if (try sema.resolveMaybeUndefVal(new_value)) |new_val| {
23203 if (try sema.resolveValue(expected_value)) |expected_val| {
23204 if (try sema.resolveValue(new_value)) |new_val| {
2328423205 if (expected_val.isUndef(mod) or new_val.isUndef(mod)) {
2328523206 // TODO: this should probably cause the memory stored at the pointer
2328623207 // to become undef as well
......@@ -23331,7 +23252,7 @@ fn zirSplat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.I
2333123252 const operand = try sema.resolveInst(extra.rhs);
2333223253 const scalar_ty = dest_ty.childType(mod);
2333323254 const scalar = try sema.coerce(block, scalar_ty, operand, scalar_src);
23334 if (try sema.resolveMaybeUndefVal(scalar)) |scalar_val| {
23255 if (try sema.resolveValue(scalar)) |scalar_val| {
2333523256 if (scalar_val.isUndef(mod)) return mod.undefRef(dest_ty);
2333623257 return Air.internedToRef((try sema.splat(dest_ty, scalar_val)).toIntern());
2333723258 }
......@@ -23381,7 +23302,7 @@ fn zirReduce(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
2338123302 return sema.fail(block, operand_src, "@reduce operation requires a vector with nonzero length", .{});
2338223303 }
2338323304
23384 if (try sema.resolveMaybeUndefVal(operand)) |operand_val| {
23305 if (try sema.resolveValue(operand)) |operand_val| {
2338523306 if (operand_val.isUndef(mod)) return mod.undefRef(scalar_ty);
2338623307
2338723308 var accum: Value = try operand_val.elemValue(mod, 0);
......@@ -23434,7 +23355,7 @@ fn zirShuffle(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
2343423355 .child = .i32_type,
2343523356 });
2343623357 mask = try sema.coerce(block, mask_ty, mask, mask_src);
23437 const mask_val = try sema.resolveConstMaybeUndefVal(block, mask_src, mask, .{
23358 const mask_val = try sema.resolveConstValue(block, mask_src, mask, .{
2343823359 .needed_comptime_reason = "shuffle mask must be comptime-known",
2343923360 });
2344023361 return sema.analyzeShuffle(block, inst_data.src_node, elem_ty, a, b, mask_val, @intCast(mask_len));
......@@ -23534,8 +23455,8 @@ fn analyzeShuffle(
2353423455 }
2353523456 }
2353623457
23537 if (try sema.resolveMaybeUndefVal(a)) |a_val| {
23538 if (try sema.resolveMaybeUndefVal(b)) |b_val| {
23458 if (try sema.resolveValue(a)) |a_val| {
23459 if (try sema.resolveValue(b)) |b_val| {
2353923460 const values = try sema.arena.alloc(InternPool.Index, mask_len);
2354023461 for (values, 0..) |*value, i| {
2354123462 const mask_elem_val = try mask.elemValue(sema.mod, i);
......@@ -23633,9 +23554,9 @@ fn zirSelect(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) C
2363323554 const a = try sema.coerce(block, vec_ty, try sema.resolveInst(extra.a), a_src);
2363423555 const b = try sema.coerce(block, vec_ty, try sema.resolveInst(extra.b), b_src);
2363523556
23636 const maybe_pred = try sema.resolveMaybeUndefVal(pred);
23637 const maybe_a = try sema.resolveMaybeUndefVal(a);
23638 const maybe_b = try sema.resolveMaybeUndefVal(b);
23557 const maybe_pred = try sema.resolveValue(pred);
23558 const maybe_a = try sema.resolveValue(a);
23559 const maybe_b = try sema.resolveValue(b);
2363923560
2364023561 const runtime_src = if (maybe_pred) |pred_val| rs: {
2364123562 if (pred_val.isUndef(mod)) return mod.undefRef(vec_ty);
......@@ -23781,7 +23702,7 @@ fn zirAtomicRmw(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
2378123702 }
2378223703
2378323704 const runtime_src = if (try sema.resolveDefinedValue(block, ptr_src, ptr)) |ptr_val| rs: {
23784 const maybe_operand_val = try sema.resolveMaybeUndefVal(operand);
23705 const maybe_operand_val = try sema.resolveValue(operand);
2378523706 const operand_val = maybe_operand_val orelse {
2378623707 try sema.checkPtrIsNotComptimeMutable(block, ptr_val, ptr_src, operand_src);
2378723708 break :rs operand_src;
......@@ -23872,9 +23793,9 @@ fn zirMulAdd(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
2387223793 const mulend1 = try sema.coerce(block, ty, try sema.resolveInst(extra.mulend1), mulend1_src);
2387323794 const mulend2 = try sema.coerce(block, ty, try sema.resolveInst(extra.mulend2), mulend2_src);
2387423795
23875 const maybe_mulend1 = try sema.resolveMaybeUndefVal(mulend1);
23876 const maybe_mulend2 = try sema.resolveMaybeUndefVal(mulend2);
23877 const maybe_addend = try sema.resolveMaybeUndefVal(addend);
23796 const maybe_mulend1 = try sema.resolveValue(mulend1);
23797 const maybe_mulend2 = try sema.resolveValue(mulend2);
23798 const maybe_addend = try sema.resolveValue(addend);
2387823799 const mod = sema.mod;
2387923800
2388023801 switch (ty.scalarType(mod).zigTypeTag(mod)) {
......@@ -23939,7 +23860,7 @@ fn zirBuiltinCall(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
2393923860 const modifier_ty = try sema.getBuiltinType("CallModifier");
2394023861 const air_ref = try sema.resolveInst(extra.modifier);
2394123862 const modifier_ref = try sema.coerce(block, modifier_ty, air_ref, modifier_src);
23942 const modifier_val = try sema.resolveConstValue(block, modifier_src, modifier_ref, .{
23863 const modifier_val = try sema.resolveConstDefinedValue(block, modifier_src, modifier_ref, .{
2394323864 .needed_comptime_reason = "call modifier must be comptime-known",
2394423865 });
2394523866 var modifier = mod.toEnum(std.builtin.CallModifier, modifier_val);
......@@ -24223,7 +24144,7 @@ fn analyzeMinMax(
2422324144 for (operands, operand_srcs, 0..) |operand, operand_src, operand_idx| {
2422424145 // Resolve the value now to avoid redundant calls to `checkSimdBinOp` - we'll have to call
2422524146 // it in the runtime path anyway since the result type may have been refined
24226 const unresolved_uncoerced_val = try sema.resolveMaybeUndefVal(operand) orelse continue;
24147 const unresolved_uncoerced_val = try sema.resolveValue(operand) orelse continue;
2422724148 const uncoerced_val = try sema.resolveLazyValue(unresolved_uncoerced_val);
2422824149
2422924150 runtime_known.unset(operand_idx);
......@@ -24299,7 +24220,7 @@ fn analyzeMinMax(
2429924220 // as possible will allow us to emit more optimal AIR (if all the runtime operands have
2430024221 // smaller types than the non-refined comptime type).
2430124222
24302 const val = (try sema.resolveMaybeUndefVal(ct_minmax_ref)).?;
24223 const val = (try sema.resolveValue(ct_minmax_ref)).?;
2430324224 const orig_ty = sema.typeOf(ct_minmax_ref);
2430424225
2430524226 if (opt_runtime_idx == null and orig_ty.scalarType(mod).eql(Type.comptime_int, mod)) {
......@@ -24334,7 +24255,7 @@ fn analyzeMinMax(
2433424255
2433524256 // If the comptime-known part is undef we can avoid emitting actual instructions later
2433624257 const known_undef = if (cur_minmax) |operand| blk: {
24337 const val = (try sema.resolveMaybeUndefVal(operand)).?;
24258 const val = (try sema.resolveValue(operand)).?;
2433824259 break :blk val.isUndef(mod);
2433924260 } else false;
2434024261
......@@ -24708,7 +24629,7 @@ fn zirMemset(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void
2470824629 }
2470924630
2471024631 if (!ptr_val.isComptimeMutablePtr(mod)) break :rs dest_src;
24711 const elem_val = try sema.resolveMaybeUndefVal(elem) orelse break :rs value_src;
24632 const elem_val = try sema.resolveValue(elem) orelse break :rs value_src;
2471224633 const array_ty = try mod.arrayType(.{
2471324634 .child = dest_elem_ty.toIntern(),
2471424635 .len = len_u64,
......@@ -24813,7 +24734,7 @@ fn zirVarExtended(
2481324734 else
2481424735 uncasted_init;
2481524736
24816 break :blk ((try sema.resolveMaybeUndefVal(init)) orelse {
24737 break :blk ((try sema.resolveValue(init)) orelse {
2481724738 return sema.failWithNeededComptime(block, init_src, .{
2481824739 .needed_comptime_reason = "container level variable initializers must be comptime-known",
2481924740 });
......@@ -25174,17 +25095,17 @@ fn resolvePrefetchOptions(
2517425095 const cache_src = sema.maybeOptionsSrc(block, src, "cache");
2517525096
2517625097 const rw = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "rw"), rw_src);
25177 const rw_val = try sema.resolveConstValue(block, rw_src, rw, .{
25098 const rw_val = try sema.resolveConstDefinedValue(block, rw_src, rw, .{
2517825099 .needed_comptime_reason = "prefetch read/write must be comptime-known",
2517925100 });
2518025101
2518125102 const locality = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "locality"), locality_src);
25182 const locality_val = try sema.resolveConstValue(block, locality_src, locality, .{
25103 const locality_val = try sema.resolveConstDefinedValue(block, locality_src, locality, .{
2518325104 .needed_comptime_reason = "prefetch locality must be comptime-known",
2518425105 });
2518525106
2518625107 const cache = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "cache"), cache_src);
25187 const cache_val = try sema.resolveConstValue(block, cache_src, cache, .{
25108 const cache_val = try sema.resolveConstDefinedValue(block, cache_src, cache, .{
2518825109 .needed_comptime_reason = "prefetch cache must be comptime-known",
2518925110 });
2519025111
......@@ -25253,24 +25174,24 @@ fn resolveExternOptions(
2525325174 const thread_local_src = sema.maybeOptionsSrc(block, src, "thread_local");
2525425175
2525525176 const name_ref = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "name"), name_src);
25256 const name_val = try sema.resolveConstValue(block, name_src, name_ref, .{
25177 const name_val = try sema.resolveConstDefinedValue(block, name_src, name_ref, .{
2525725178 .needed_comptime_reason = "name of the extern symbol must be comptime-known",
2525825179 });
2525925180 const name = try name_val.toAllocatedBytes(Type.slice_const_u8, sema.arena, mod);
2526025181
2526125182 const library_name_inst = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "library_name"), library_src);
25262 const library_name_val = try sema.resolveConstValue(block, library_src, library_name_inst, .{
25183 const library_name_val = try sema.resolveConstDefinedValue(block, library_src, library_name_inst, .{
2526325184 .needed_comptime_reason = "library in which extern symbol is must be comptime-known",
2526425185 });
2526525186
2526625187 const linkage_ref = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "linkage"), linkage_src);
25267 const linkage_val = try sema.resolveConstValue(block, linkage_src, linkage_ref, .{
25188 const linkage_val = try sema.resolveConstDefinedValue(block, linkage_src, linkage_ref, .{
2526825189 .needed_comptime_reason = "linkage of the extern symbol must be comptime-known",
2526925190 });
2527025191 const linkage = mod.toEnum(std.builtin.GlobalLinkage, linkage_val);
2527125192
2527225193 const is_thread_local = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "is_thread_local"), thread_local_src);
25273 const is_thread_local_val = try sema.resolveConstValue(block, thread_local_src, is_thread_local, .{
25194 const is_thread_local_val = try sema.resolveConstDefinedValue(block, thread_local_src, is_thread_local, .{
2527425195 .needed_comptime_reason = "threadlocality of the extern symbol must be comptime-known",
2527525196 });
2527625197
......@@ -26496,7 +26417,7 @@ fn fieldPtr(
2649626417 }
2649726418 },
2649826419 .Type => {
26499 _ = try sema.resolveConstValue(block, .unneeded, object_ptr, undefined);
26420 _ = try sema.resolveConstDefinedValue(block, .unneeded, object_ptr, undefined);
2650026421 const result = try sema.analyzeLoad(block, src, object_ptr, object_ptr_src);
2650126422 const inner = if (is_pointer_to)
2650226423 try sema.analyzeLoad(block, src, result, object_ptr_src)
......@@ -27068,7 +26989,7 @@ fn structFieldVal(
2706826989
2706926990 const field_ty = struct_type.field_types.get(ip)[field_index].toType();
2707026991
27071 if (try sema.resolveMaybeUndefVal(struct_byval)) |struct_val| {
26992 if (try sema.resolveValue(struct_byval)) |struct_val| {
2707226993 if (struct_val.isUndef(mod)) return mod.undefRef(field_ty);
2707326994 if ((try sema.typeHasOnePossibleValue(field_ty))) |opv| {
2707426995 return Air.internedToRef(opv.toIntern());
......@@ -27146,7 +27067,7 @@ fn tupleFieldValByIndex(
2714627067 return Air.internedToRef(default_value.toIntern());
2714727068 }
2714827069
27149 if (try sema.resolveMaybeUndefVal(tuple_byval)) |tuple_val| {
27070 if (try sema.resolveValue(tuple_byval)) |tuple_val| {
2715027071 if ((try sema.typeHasOnePossibleValue(field_ty))) |opv| {
2715127072 return Air.internedToRef(opv.toIntern());
2715227073 }
......@@ -27298,7 +27219,7 @@ fn unionFieldVal(
2729827219 const field_ty = union_obj.field_types.get(ip)[field_index].toType();
2729927220 const enum_field_index: u32 = @intCast(union_obj.enum_tag_ty.toType().enumFieldIndex(field_name, mod).?);
2730027221
27301 if (try sema.resolveMaybeUndefVal(union_byval)) |union_val| {
27222 if (try sema.resolveValue(union_byval)) |union_val| {
2730227223 if (union_val.isUndef(mod)) return mod.undefRef(field_ty);
2730327224
2730427225 const un = ip.indexToKey(union_val.toIntern()).un;
......@@ -27380,7 +27301,7 @@ fn elemPtr(
2738027301 .Array, .Vector => try sema.elemPtrArray(block, src, indexable_ptr_src, indexable_ptr, elem_index_src, elem_index, init, oob_safety),
2738127302 .Struct => blk: {
2738227303 // Tuple field access.
27383 const index_val = try sema.resolveConstValue(block, elem_index_src, elem_index, .{
27304 const index_val = try sema.resolveConstDefinedValue(block, elem_index_src, elem_index, .{
2738427305 .needed_comptime_reason = "tuple field access index must be comptime-known",
2738527306 });
2738627307 const index: u32 = @intCast(index_val.toUnsignedInt(mod));
......@@ -27437,7 +27358,7 @@ fn elemPtrOneLayerOnly(
2743727358 .Array, .Vector => try sema.elemPtrArray(block, src, indexable_src, indexable, elem_index_src, elem_index, init, oob_safety),
2743827359 .Struct => blk: {
2743927360 assert(child_ty.isTuple(mod));
27440 const index_val = try sema.resolveConstValue(block, elem_index_src, elem_index, .{
27361 const index_val = try sema.resolveConstDefinedValue(block, elem_index_src, elem_index, .{
2744127362 .needed_comptime_reason = "tuple field access index must be comptime-known",
2744227363 });
2744327364 const index: u32 = @intCast(index_val.toUnsignedInt(mod));
......@@ -27516,7 +27437,7 @@ fn elemVal(
2751627437 },
2751727438 .Struct => {
2751827439 // Tuple field access.
27519 const index_val = try sema.resolveConstValue(block, elem_index_src, elem_index, .{
27440 const index_val = try sema.resolveConstDefinedValue(block, elem_index_src, elem_index, .{
2752027441 .needed_comptime_reason = "tuple field access index must be comptime-known",
2752127442 });
2752227443 const index: u32 = @intCast(index_val.toUnsignedInt(mod));
......@@ -27596,7 +27517,7 @@ fn tupleFieldPtr(
2759627517 } })));
2759727518 }
2759827519
27599 if (try sema.resolveMaybeUndefVal(tuple_ptr)) |tuple_ptr_val| {
27520 if (try sema.resolveValue(tuple_ptr)) |tuple_ptr_val| {
2760027521 return Air.internedToRef((try mod.intern(.{ .ptr = .{
2760127522 .ty = ptr_field_ty.toIntern(),
2760227523 .addr = .{ .field = .{
......@@ -27643,7 +27564,7 @@ fn tupleField(
2764327564 return Air.internedToRef(default_value.toIntern()); // comptime field
2764427565 }
2764527566
27646 if (try sema.resolveMaybeUndefVal(tuple)) |tuple_val| {
27567 if (try sema.resolveValue(tuple)) |tuple_val| {
2764727568 if (tuple_val.isUndef(mod)) return mod.undefRef(field_ty);
2764827569 return Air.internedToRef((try tuple_val.fieldValue(mod, field_index)).toIntern());
2764927570 }
......@@ -27676,7 +27597,7 @@ fn elemValArray(
2767627597 return sema.fail(block, array_src, "indexing into empty array is not allowed", .{});
2767727598 }
2767827599
27679 const maybe_undef_array_val = try sema.resolveMaybeUndefVal(array);
27600 const maybe_undef_array_val = try sema.resolveValue(array);
2768027601 // index must be defined since it can access out of bounds
2768127602 const maybe_index_val = try sema.resolveDefinedValue(block, elem_index_src, elem_index);
2768227603
......@@ -27741,7 +27662,7 @@ fn elemPtrArray(
2774127662 return sema.fail(block, array_ptr_src, "indexing into empty array is not allowed", .{});
2774227663 }
2774327664
27744 const maybe_undef_array_ptr_val = try sema.resolveMaybeUndefVal(array_ptr);
27665 const maybe_undef_array_ptr_val = try sema.resolveValue(array_ptr);
2774527666 // The index must not be undefined since it can be out of bounds.
2774627667 const offset: ?usize = if (try sema.resolveDefinedValue(block, elem_index_src, elem_index)) |index_val| o: {
2774727668 const index = try sema.usizeCast(block, elem_index_src, index_val.toUnsignedInt(mod));
......@@ -27853,7 +27774,7 @@ fn elemPtrSlice(
2785327774 const slice_ty = sema.typeOf(slice);
2785427775 const slice_sent = slice_ty.sentinel(mod) != null;
2785527776
27856 const maybe_undef_slice_val = try sema.resolveMaybeUndefVal(slice);
27777 const maybe_undef_slice_val = try sema.resolveValue(slice);
2785727778 // The index must not be undefined since it can be out of bounds.
2785827779 const offset: ?usize = if (try sema.resolveDefinedValue(block, elem_index_src, elem_index)) |index_val| o: {
2785927780 const index = try sema.usizeCast(block, elem_index_src, index_val.toUnsignedInt(mod));
......@@ -27965,7 +27886,7 @@ fn coerceExtra(
2796527886 if (dest_ty.eql(inst_ty, mod))
2796627887 return inst;
2796727888
27968 const maybe_inst_val = try sema.resolveMaybeUndefVal(inst);
27889 const maybe_inst_val = try sema.resolveValue(inst);
2796927890
2797027891 var in_memory_result = try sema.coerceInMemoryAllowed(block, dest_ty, inst_ty, false, target, dest_ty_src, inst_src);
2797127892 if (in_memory_result == .ok) {
......@@ -28035,7 +27956,7 @@ fn coerceExtra(
2803527956
2803627957 // Function body to function pointer.
2803727958 if (inst_ty.zigTypeTag(mod) == .Fn) {
28038 const fn_val = try sema.resolveConstValue(block, .unneeded, inst, undefined);
27959 const fn_val = try sema.resolveConstDefinedValue(block, .unneeded, inst, undefined);
2803927960 const fn_decl = fn_val.pointerDecl(mod).?;
2804027961 const inst_as_ptr = try sema.analyzeDeclRef(fn_decl);
2804127962 return sema.coerce(block, dest_ty, inst_as_ptr, inst_src);
......@@ -28380,7 +28301,7 @@ fn coerceExtra(
2838028301 },
2838128302 .Float, .ComptimeFloat => switch (inst_ty.zigTypeTag(mod)) {
2838228303 .ComptimeFloat => {
28383 const val = try sema.resolveConstValue(block, .unneeded, inst, undefined);
28304 const val = try sema.resolveConstDefinedValue(block, .unneeded, inst, undefined);
2838428305 const result_val = try val.floatCast(dest_ty, mod);
2838528306 return Air.internedToRef(result_val.toIntern());
2838628307 },
......@@ -28439,7 +28360,7 @@ fn coerceExtra(
2843928360 .Enum => switch (inst_ty.zigTypeTag(mod)) {
2844028361 .EnumLiteral => {
2844128362 // enum literal to enum
28442 const val = try sema.resolveConstValue(block, .unneeded, inst, undefined);
28363 const val = try sema.resolveConstDefinedValue(block, .unneeded, inst, undefined);
2844328364 const string = mod.intern_pool.indexToKey(val.toIntern()).enum_literal;
2844428365 const field_index = dest_ty.enumFieldIndex(string, mod) orelse {
2844528366 const msg = msg: {
......@@ -29567,7 +29488,7 @@ fn coerceVarArgParam(
2956729488 .{},
2956829489 ),
2956929490 .Fn => blk: {
29570 const fn_val = try sema.resolveConstValue(block, .unneeded, inst, undefined);
29491 const fn_val = try sema.resolveConstDefinedValue(block, .unneeded, inst, undefined);
2957129492 const fn_decl = fn_val.pointerDecl(mod).?;
2957229493 break :blk try sema.analyzeDeclRef(fn_decl);
2957329494 },
......@@ -29679,7 +29600,7 @@ fn storePtr2(
2967929600 error.NotCoercible => unreachable,
2968029601 else => |e| return e,
2968129602 };
29682 const maybe_operand_val = try sema.resolveMaybeUndefVal(operand);
29603 const maybe_operand_val = try sema.resolveValue(operand);
2968329604
2968429605 const runtime_src = if (try sema.resolveDefinedValue(block, ptr_src, ptr)) |ptr_val| rs: {
2968529606 const operand_val = maybe_operand_val orelse {
......@@ -29747,7 +29668,7 @@ fn checkComptimeKnownStore(sema: *Sema, block: *Block, store_inst_ref: Air.Inst.
2974729668 const maybe_comptime_alloc = sema.maybe_comptime_allocs.getPtr(maybe_base_alloc) orelse return;
2974829669
2974929670 ct: {
29750 if (null == try sema.resolveMaybeUndefVal(operand)) break :ct;
29671 if (null == try sema.resolveValue(operand)) break :ct;
2975129672 if (maybe_comptime_alloc.runtime_index != block.runtime_index) break :ct;
2975229673 return maybe_comptime_alloc.stores.append(sema.arena, store_inst);
2975329674 }
......@@ -29778,7 +29699,7 @@ fn checkKnownAllocPtr(sema: *Sema, base_ptr: Air.Inst.Ref, new_ptr: Air.Inst.Ref
2977829699
2977929700 // If the index value is runtime-known, this pointer is also runtime-known, so
2978029701 // we must in turn make the alloc value runtime-known.
29781 if (null == try sema.resolveMaybeUndefVal(index_ref)) {
29702 if (null == try sema.resolveValue(index_ref)) {
2978229703 _ = sema.maybe_comptime_allocs.remove(alloc_inst);
2978329704 }
2978429705 },
......@@ -30788,7 +30709,7 @@ fn bitCast(
3078830709 });
3078930710 }
3079030711
30791 if (try sema.resolveMaybeUndefVal(inst)) |val| {
30712 if (try sema.resolveValue(inst)) |val| {
3079230713 if (try sema.bitCastVal(block, inst_src, val, old_ty, dest_ty, 0)) |result_val| {
3079330714 return Air.internedToRef(result_val.toIntern());
3079430715 }
......@@ -30894,7 +30815,7 @@ fn coerceArrayPtrToSlice(
3089430815 inst_src: LazySrcLoc,
3089530816) CompileError!Air.Inst.Ref {
3089630817 const mod = sema.mod;
30897 if (try sema.resolveMaybeUndefVal(inst)) |val| {
30818 if (try sema.resolveValue(inst)) |val| {
3089830819 const ptr_array_ty = sema.typeOf(inst);
3089930820 const array_ty = ptr_array_ty.childType(mod);
3090030821 const slice_val = try mod.intern(.{ .ptr = .{
......@@ -30972,7 +30893,7 @@ fn coerceCompatiblePtrs(
3097230893) !Air.Inst.Ref {
3097330894 const mod = sema.mod;
3097430895 const inst_ty = sema.typeOf(inst);
30975 if (try sema.resolveMaybeUndefVal(inst)) |val| {
30896 if (try sema.resolveValue(inst)) |val| {
3097630897 if (!val.isUndef(mod) and val.isNull(mod) and !dest_ty.isAllowzeroPtr(mod)) {
3097730898 return sema.fail(block, inst_src, "null pointer casted to type '{}'", .{dest_ty.fmt(sema.mod)});
3097830899 }
......@@ -31255,7 +31176,7 @@ fn coerceArrayLike(
3125531176 // try coercion of the whole array
3125631177 const in_memory_result = try sema.coerceInMemoryAllowed(block, dest_ty, inst_ty, false, target, dest_ty_src, inst_src);
3125731178 if (in_memory_result == .ok) {
31258 if (try sema.resolveMaybeUndefVal(inst)) |inst_val| {
31179 if (try sema.resolveValue(inst)) |inst_val| {
3125931180 // These types share the same comptime value representation.
3126031181 return sema.coerceInMemory(inst_val, dest_ty);
3126131182 }
......@@ -31292,7 +31213,7 @@ fn coerceArrayLike(
3129231213 const coerced = try sema.coerce(block, dest_elem_ty, elem_ref, elem_src);
3129331214 ref.* = coerced;
3129431215 if (runtime_src == null) {
31295 if (try sema.resolveMaybeUndefVal(coerced)) |elem_val| {
31216 if (try sema.resolveValue(coerced)) |elem_val| {
3129631217 val.* = try elem_val.intern(dest_elem_ty, mod);
3129731218 } else {
3129831219 runtime_src = elem_src;
......@@ -31357,7 +31278,7 @@ fn coerceTupleToArray(
3135731278 const coerced = try sema.coerce(block, dest_elem_ty, elem_ref, elem_src);
3135831279 ref.* = coerced;
3135931280 if (runtime_src == null) {
31360 if (try sema.resolveMaybeUndefVal(coerced)) |elem_val| {
31281 if (try sema.resolveValue(coerced)) |elem_val| {
3136131282 val.* = try elem_val.intern(dest_elem_ty, mod);
3136231283 } else {
3136331284 runtime_src = elem_src;
......@@ -31470,7 +31391,7 @@ fn coerceTupleToStruct(
3147031391 const coerced = try sema.coerce(block, field_ty, elem_ref, field_src);
3147131392 field_refs[field_index] = coerced;
3147231393 if (struct_type.fieldIsComptime(ip, field_index)) {
31473 const init_val = (try sema.resolveMaybeUndefVal(coerced)) orelse {
31394 const init_val = (try sema.resolveValue(coerced)) orelse {
3147431395 return sema.failWithNeededComptime(block, field_src, .{
3147531396 .needed_comptime_reason = "value stored in comptime field must be comptime-known",
3147631397 });
......@@ -31482,7 +31403,7 @@ fn coerceTupleToStruct(
3148231403 }
3148331404 }
3148431405 if (runtime_src == null) {
31485 if (try sema.resolveMaybeUndefVal(coerced)) |field_val| {
31406 if (try sema.resolveValue(coerced)) |field_val| {
3148631407 field_vals[field_index] = field_val.toIntern();
3148731408 } else {
3148831409 runtime_src = field_src;
......@@ -31598,7 +31519,7 @@ fn coerceTupleToTuple(
3159831519 const coerced = try sema.coerce(block, field_ty.toType(), elem_ref, field_src);
3159931520 field_refs[field_index] = coerced;
3160031521 if (default_val != .none) {
31601 const init_val = (try sema.resolveMaybeUndefVal(coerced)) orelse {
31522 const init_val = (try sema.resolveValue(coerced)) orelse {
3160231523 return sema.failWithNeededComptime(block, field_src, .{
3160331524 .needed_comptime_reason = "value stored in comptime field must be comptime-known",
3160431525 });
......@@ -31609,7 +31530,7 @@ fn coerceTupleToTuple(
3160931530 }
3161031531 }
3161131532 if (runtime_src == null) {
31612 if (try sema.resolveMaybeUndefVal(coerced)) |field_val| {
31533 if (try sema.resolveValue(coerced)) |field_val| {
3161331534 field_vals[field_index] = field_val.toIntern();
3161431535 } else {
3161531536 runtime_src = field_src;
......@@ -31830,7 +31751,7 @@ fn analyzeRef(
3183031751 const mod = sema.mod;
3183131752 const operand_ty = sema.typeOf(operand);
3183231753
31833 if (try sema.resolveMaybeUndefVal(operand)) |val| {
31754 if (try sema.resolveValue(operand)) |val| {
3183431755 switch (mod.intern_pool.indexToKey(val.toIntern())) {
3183531756 .extern_func => |extern_func| return sema.analyzeDeclRef(extern_func.decl),
3183631757 .func => |func| return sema.analyzeDeclRef(func.owner_decl),
......@@ -31917,7 +31838,7 @@ fn analyzeSlicePtr(
3191731838) CompileError!Air.Inst.Ref {
3191831839 const mod = sema.mod;
3191931840 const result_ty = slice_ty.slicePtrFieldType(mod);
31920 if (try sema.resolveMaybeUndefVal(slice)) |val| {
31841 if (try sema.resolveValue(slice)) |val| {
3192131842 if (val.isUndef(mod)) return mod.undefRef(result_ty);
3192231843 return Air.internedToRef(val.slicePtr(mod).toIntern());
3192331844 }
......@@ -31932,7 +31853,7 @@ fn analyzeSliceLen(
3193231853 slice_inst: Air.Inst.Ref,
3193331854) CompileError!Air.Inst.Ref {
3193431855 const mod = sema.mod;
31935 if (try sema.resolveMaybeUndefVal(slice_inst)) |slice_val| {
31856 if (try sema.resolveValue(slice_inst)) |slice_val| {
3193631857 if (slice_val.isUndef(mod)) {
3193731858 return mod.undefRef(Type.usize);
3193831859 }
......@@ -31951,7 +31872,7 @@ fn analyzeIsNull(
3195131872) CompileError!Air.Inst.Ref {
3195231873 const mod = sema.mod;
3195331874 const result_ty = Type.bool;
31954 if (try sema.resolveMaybeUndefVal(operand)) |opt_val| {
31875 if (try sema.resolveValue(operand)) |opt_val| {
3195531876 if (opt_val.isUndef(mod)) {
3195631877 return mod.undefRef(result_ty);
3195731878 }
......@@ -32027,7 +31948,7 @@ fn analyzeIsNonErrComptimeOnly(
3202731948 return .bool_true;
3202831949 }
3202931950
32030 const maybe_operand_val = try sema.resolveMaybeUndefVal(operand);
31951 const maybe_operand_val = try sema.resolveValue(operand);
3203131952
3203231953 // exception if the error union error set is known to be empty,
3203331954 // we allow the comparison but always make it comptime-known.
......@@ -32248,7 +32169,7 @@ fn analyzeSlice(
3224832169 const uncasted_end = try sema.analyzeArithmetic(block, .add, start, len, src, start_src, end_src, false);
3224932170 break :end try sema.coerce(block, Type.usize, uncasted_end, end_src);
3225032171 } else try sema.coerce(block, Type.usize, uncasted_end_opt, end_src);
32251 if (try sema.resolveMaybeUndefVal(end)) |end_val| {
32172 if (try sema.resolveValue(end)) |end_val| {
3225232173 const len_s_val = try mod.intValue(
3225332174 Type.usize,
3225432175 array_ty.arrayLenIncludingSentinel(mod),
......@@ -32290,7 +32211,7 @@ fn analyzeSlice(
3229032211 break :end try sema.coerce(block, Type.usize, uncasted_end, end_src);
3229132212 } else try sema.coerce(block, Type.usize, uncasted_end_opt, end_src);
3229232213 if (try sema.resolveDefinedValue(block, end_src, end)) |end_val| {
32293 if (try sema.resolveMaybeUndefVal(ptr_or_slice)) |slice_val| {
32214 if (try sema.resolveValue(ptr_or_slice)) |slice_val| {
3229432215 if (slice_val.isUndef(mod)) {
3229532216 return sema.fail(block, src, "slice of undefined", .{});
3229632217 }
......@@ -32342,7 +32263,7 @@ fn analyzeSlice(
3234232263 const sentinel = s: {
3234332264 if (sentinel_opt != .none) {
3234432265 const casted = try sema.coerce(block, elem_ty, sentinel_opt, sentinel_src);
32345 break :s try sema.resolveConstValue(block, sentinel_src, casted, .{
32266 break :s try sema.resolveConstDefinedValue(block, sentinel_src, casted, .{
3234632267 .needed_comptime_reason = "slice sentinel must be comptime-known",
3234732268 });
3234832269 }
......@@ -32375,7 +32296,7 @@ fn analyzeSlice(
3237532296 );
3237632297 }
3237732298 checked_start_lte_end = true;
32378 if (try sema.resolveMaybeUndefVal(new_ptr)) |ptr_val| sentinel_check: {
32299 if (try sema.resolveValue(new_ptr)) |ptr_val| sentinel_check: {
3237932300 const expected_sentinel = sentinel orelse break :sentinel_check;
3238032301 const start_int = start_val.getUnsignedInt(mod).?;
3238132302 const end_int = end_val.getUnsignedInt(mod).?;
......@@ -32464,7 +32385,7 @@ fn analyzeSlice(
3246432385 },
3246532386 });
3246632387
32467 const opt_new_ptr_val = try sema.resolveMaybeUndefVal(new_ptr);
32388 const opt_new_ptr_val = try sema.resolveValue(new_ptr);
3246832389 const new_ptr_val = opt_new_ptr_val orelse {
3246932390 const result = try block.addBitCast(return_ty, new_ptr);
3247032391 if (block.wantSafety()) {
......@@ -32611,8 +32532,8 @@ fn cmpNumeric(
3261132532 uncasted_rhs;
3261232533
3261332534 const runtime_src: LazySrcLoc = src: {
32614 if (try sema.resolveMaybeUndefVal(lhs)) |lhs_val| {
32615 if (try sema.resolveMaybeUndefVal(rhs)) |rhs_val| {
32535 if (try sema.resolveValue(lhs)) |lhs_val| {
32536 if (try sema.resolveValue(rhs)) |rhs_val| {
3261632537 // Compare ints: const vs. undefined (or vice versa)
3261732538 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)) {
3261832539 if (try sema.compareIntsOnlyPossibleResult(try sema.resolveLazyValue(lhs_val), op, rhs_ty)) |res| {
......@@ -32644,7 +32565,7 @@ fn cmpNumeric(
3264432565 break :src rhs_src;
3264532566 }
3264632567 } else {
32647 if (try sema.resolveMaybeUndefLazyVal(rhs)) |rhs_val| {
32568 if (try sema.resolveValueResolveLazy(rhs)) |rhs_val| {
3264832569 if (!rhs_val.isUndef(mod) and (rhs_ty.isInt(mod) or rhs_ty_tag == .ComptimeInt) and lhs_ty.isInt(mod)) {
3264932570 // Compare ints: var vs. const
3265032571 if (try sema.compareIntsOnlyPossibleResult(try sema.resolveLazyValue(rhs_val), op.reverse(), lhs_ty)) |res| {
......@@ -32711,7 +32632,7 @@ fn cmpNumeric(
3271132632 var dest_float_type: ?Type = null;
3271232633
3271332634 var lhs_bits: usize = undefined;
32714 if (try sema.resolveMaybeUndefLazyVal(lhs)) |lhs_val| {
32635 if (try sema.resolveValueResolveLazy(lhs)) |lhs_val| {
3271532636 if (lhs_val.isUndef(mod))
3271632637 return mod.undefRef(Type.bool);
3271732638 if (lhs_val.isNan(mod)) switch (op) {
......@@ -32769,7 +32690,7 @@ fn cmpNumeric(
3276932690 }
3277032691
3277132692 var rhs_bits: usize = undefined;
32772 if (try sema.resolveMaybeUndefLazyVal(rhs)) |rhs_val| {
32693 if (try sema.resolveValueResolveLazy(rhs)) |rhs_val| {
3277332694 if (rhs_val.isUndef(mod))
3277432695 return mod.undefRef(Type.bool);
3277532696 if (rhs_val.isNan(mod)) switch (op) {
......@@ -32961,8 +32882,8 @@ fn cmpVector(
3296132882 });
3296232883
3296332884 const runtime_src: LazySrcLoc = src: {
32964 if (try sema.resolveMaybeUndefVal(casted_lhs)) |lhs_val| {
32965 if (try sema.resolveMaybeUndefVal(casted_rhs)) |rhs_val| {
32885 if (try sema.resolveValue(casted_lhs)) |lhs_val| {
32886 if (try sema.resolveValue(casted_rhs)) |rhs_val| {
3296632887 if (lhs_val.isUndef(mod) or rhs_val.isUndef(mod)) {
3296732888 return mod.undefRef(result_ty);
3296832889 }
......@@ -32987,7 +32908,7 @@ fn wrapOptional(
3298732908 inst: Air.Inst.Ref,
3298832909 inst_src: LazySrcLoc,
3298932910) !Air.Inst.Ref {
32990 if (try sema.resolveMaybeUndefVal(inst)) |val| {
32911 if (try sema.resolveValue(inst)) |val| {
3299132912 return Air.internedToRef((try sema.mod.intern(.{ .opt = .{
3299232913 .ty = dest_ty.toIntern(),
3299332914 .val = val.toIntern(),
......@@ -33008,7 +32929,7 @@ fn wrapErrorUnionPayload(
3300832929 const mod = sema.mod;
3300932930 const dest_payload_ty = dest_ty.errorUnionPayload(mod);
3301032931 const coerced = try sema.coerceExtra(block, dest_payload_ty, inst, inst_src, .{ .report_err = false });
33011 if (try sema.resolveMaybeUndefVal(coerced)) |val| {
32932 if (try sema.resolveValue(coerced)) |val| {
3301232933 return Air.internedToRef((try mod.intern(.{ .error_union = .{
3301332934 .ty = dest_ty.toIntern(),
3301432935 .val = .{ .payload = try val.intern(dest_payload_ty, mod) },
......@@ -33030,7 +32951,7 @@ fn wrapErrorUnionSet(
3303032951 const ip = &mod.intern_pool;
3303132952 const inst_ty = sema.typeOf(inst);
3303232953 const dest_err_set_ty = dest_ty.errorUnionSet(mod);
33033 if (try sema.resolveMaybeUndefVal(inst)) |val| {
32954 if (try sema.resolveValue(inst)) |val| {
3303432955 const expected_name = mod.intern_pool.indexToKey(val.toIntern()).err.name;
3303532956 switch (dest_err_set_ty.toIntern()) {
3303632957 .anyerror_type => {},
......@@ -33092,7 +33013,7 @@ fn unionToTag(
3309233013 if ((try sema.typeHasOnePossibleValue(enum_ty))) |opv| {
3309333014 return Air.internedToRef(opv.toIntern());
3309433015 }
33095 if (try sema.resolveMaybeUndefVal(un)) |un_val| {
33016 if (try sema.resolveValue(un)) |un_val| {
3309633017 return Air.internedToRef(un_val.unionTag(mod).?.toIntern());
3309733018 }
3309833019 try sema.requireRuntimeBlock(block, un_src, null);
......@@ -33401,7 +33322,7 @@ fn resolvePeerTypes(
3340133322
3340233323 for (instructions, peer_tys, peer_vals) |inst, *ty, *val| {
3340333324 ty.* = sema.typeOf(inst);
33404 val.* = try sema.resolveMaybeUndefVal(inst);
33325 val.* = try sema.resolveValue(inst);
3340533326 }
3340633327
3340733328 switch (try sema.resolvePeerTypesInner(block, src, peer_tys, peer_vals)) {
......@@ -34456,7 +34377,7 @@ fn resolvePeerTypesInner(
3445634377 },
3445734378 else => |e| return e,
3445834379 };
34459 const coerced_val = (try sema.resolveMaybeUndefVal(coerced_inst)) orelse continue;
34380 const coerced_val = (try sema.resolveValue(coerced_inst)) orelse continue;
3446034381 const existing = comptime_val orelse {
3446134382 comptime_val = coerced_val;
3446234383 continue;
......@@ -35904,7 +35825,7 @@ fn semaStructFields(
3590435825 },
3590535826 else => |e| return e,
3590635827 };
35907 const default_val = (try sema.resolveMaybeUndefVal(coerced)) orelse {
35828 const default_val = (try sema.resolveValue(coerced)) orelse {
3590835829 const init_src = mod.fieldSrcLoc(decl_index, .{
3590935830 .index = field_i,
3591035831 .range = .value,
......@@ -36347,7 +36268,7 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Key.Un
3634736268
3634836269fn semaUnionFieldVal(sema: *Sema, block: *Block, src: LazySrcLoc, int_tag_ty: Type, tag_ref: Air.Inst.Ref) CompileError!Value {
3634936270 const coerced = try sema.coerce(block, int_tag_ty, tag_ref, src);
36350 return sema.resolveConstValue(block, src, coerced, .{
36271 return sema.resolveConstDefinedValue(block, src, coerced, .{
3635136272 .needed_comptime_reason = "enum tag value must be comptime-known",
3635236273 });
3635336274}
......@@ -36644,7 +36565,6 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {
3664436565 .simple_type, // handled above
3664536566 // values, not types
3664636567 .undef,
36647 .runtime_value,
3664836568 .simple_value,
3664936569 .ptr_decl,
3665036570 .ptr_anon_decl,
......@@ -36906,7 +36826,7 @@ fn isComptimeKnown(
3690636826 sema: *Sema,
3690736827 inst: Air.Inst.Ref,
3690836828) !bool {
36909 return (try sema.resolveMaybeUndefVal(inst)) != null;
36829 return (try sema.resolveValue(inst)) != null;
3691036830}
3691136831
3691236832fn analyzeComptimeAlloc(
src/TypedValue.zig-1
......@@ -206,7 +206,6 @@ pub fn print(
206206 .inferred_error_set_type,
207207 => return Type.print(val.toType(), writer, mod),
208208 .undef => return writer.writeAll("undefined"),
209 .runtime_value => return writer.writeAll("(runtime value)"),
210209 .simple_value => |simple_value| switch (simple_value) {
211210 .void => return writer.writeAll("{}"),
212211 .empty_struct => return printAggregate(ty, val, writer, level, mod),
src/arch/wasm/CodeGen.zig+2-7
......@@ -3224,16 +3224,11 @@ fn toTwosComplement(value: anytype, bits: u7) std.meta.Int(.unsigned, @typeInfo(
32243224
32253225/// This function is intended to assert that `isByRef` returns `false` for `ty`.
32263226/// However such an assertion fails on the behavior tests currently.
3227fn lowerConstant(func: *CodeGen, arg_val: Value, ty: Type) InnerError!WValue {
3227fn lowerConstant(func: *CodeGen, val: Value, ty: Type) InnerError!WValue {
32283228 const mod = func.bin_file.base.options.module.?;
32293229 // TODO: enable this assertion
32303230 //assert(!isByRef(ty, mod));
32313231 const ip = &mod.intern_pool;
3232 var val = arg_val;
3233 switch (ip.indexToKey(val.ip_index)) {
3234 .runtime_value => |rt| val = rt.val.toValue(),
3235 else => {},
3236 }
32373232 if (val.isUndefDeep(mod)) return func.emitUndefined(ty);
32383233
32393234 switch (ip.indexToKey(val.ip_index)) {
......@@ -3255,7 +3250,7 @@ fn lowerConstant(func: *CodeGen, arg_val: Value, ty: Type) InnerError!WValue {
32553250 .inferred_error_set_type,
32563251 => unreachable, // types, not values
32573252
3258 .undef, .runtime_value => unreachable, // handled above
3253 .undef => unreachable, // handled above
32593254 .simple_value => |simple_value| switch (simple_value) {
32603255 .undefined,
32613256 .void,
src/codegen.zig+3-11
......@@ -167,11 +167,7 @@ pub fn generateSymbol(
167167
168168 const mod = bin_file.options.module.?;
169169 const ip = &mod.intern_pool;
170 var typed_value = arg_tv;
171 switch (ip.indexToKey(typed_value.val.toIntern())) {
172 .runtime_value => |rt| typed_value.val = rt.val.toValue(),
173 else => {},
174 }
170 const typed_value = arg_tv;
175171
176172 const target = mod.getTarget();
177173 const endian = target.cpu.arch.endian();
......@@ -206,7 +202,7 @@ pub fn generateSymbol(
206202 .inferred_error_set_type,
207203 => unreachable, // types, not values
208204
209 .undef, .runtime_value => unreachable, // handled above
205 .undef => unreachable, // handled above
210206 .simple_value => |simple_value| switch (simple_value) {
211207 .undefined,
212208 .void,
......@@ -970,11 +966,7 @@ pub fn genTypedValue(
970966 owner_decl_index: Module.Decl.Index,
971967) CodeGenError!GenResult {
972968 const mod = bin_file.options.module.?;
973 var typed_value = arg_tv;
974 switch (mod.intern_pool.indexToKey(typed_value.val.toIntern())) {
975 .runtime_value => |rt| typed_value.val = rt.val.toValue(),
976 else => {},
977 }
969 const typed_value = arg_tv;
978970
979971 log.debug("genTypedValue: ty = {}, val = {}", .{
980972 typed_value.ty.fmt(mod),
src/codegen/c.zig+2-7
......@@ -772,17 +772,12 @@ pub const DeclGen = struct {
772772 dg: *DeclGen,
773773 writer: anytype,
774774 ty: Type,
775 arg_val: Value,
775 val: Value,
776776 location: ValueRenderLocation,
777777 ) error{ OutOfMemory, AnalysisFail }!void {
778778 const mod = dg.module;
779779 const ip = &mod.intern_pool;
780780
781 var val = arg_val;
782 switch (ip.indexToKey(val.ip_index)) {
783 .runtime_value => |rt| val = rt.val.toValue(),
784 else => {},
785 }
786781 const target = mod.getTarget();
787782 const initializer_type: ValueRenderLocation = switch (location) {
788783 .StaticInitializer => .StaticInitializer,
......@@ -1005,7 +1000,7 @@ pub const DeclGen = struct {
10051000 .memoized_call,
10061001 => unreachable,
10071002
1008 .undef, .runtime_value => unreachable, // handled above
1003 .undef => unreachable, // handled above
10091004 .simple_value => |simple_value| switch (simple_value) {
10101005 // non-runtime values
10111006 .undefined => unreachable,
src/codegen/llvm.zig+5-10
......@@ -3560,7 +3560,6 @@ pub const Object = struct {
35603560 .error_set_type, .inferred_error_set_type => try o.errorIntType(),
35613561 // values, not types
35623562 .undef,
3563 .runtime_value,
35643563 .simple_value,
35653564 .variable,
35663565 .extern_func,
......@@ -3672,17 +3671,13 @@ pub const Object = struct {
36723671 const ip = &mod.intern_pool;
36733672 const target = mod.getTarget();
36743673
3675 var val = arg_val.toValue();
3676 const arg_val_key = ip.indexToKey(arg_val);
3677 switch (arg_val_key) {
3678 .runtime_value => |rt| val = rt.val.toValue(),
3679 else => {},
3680 }
3674 const val = arg_val.toValue();
3675 const val_key = ip.indexToKey(val.toIntern());
3676
36813677 if (val.isUndefDeep(mod)) {
3682 return o.builder.undefConst(try o.lowerType(arg_val_key.typeOf().toType()));
3678 return o.builder.undefConst(try o.lowerType(val_key.typeOf().toType()));
36833679 }
36843680
3685 const val_key = ip.indexToKey(val.toIntern());
36863681 const ty = val_key.typeOf().toType();
36873682 return switch (val_key) {
36883683 .int_type,
......@@ -3703,7 +3698,7 @@ pub const Object = struct {
37033698 .inferred_error_set_type,
37043699 => unreachable, // types, not values
37053700
3706 .undef, .runtime_value => unreachable, // handled above
3701 .undef => unreachable, // handled above
37073702 .simple_value => |simple_value| switch (simple_value) {
37083703 .undefined,
37093704 .void,
src/codegen/spirv.zig+2-6
......@@ -644,11 +644,7 @@ const DeclGen = struct {
644644 const result_ty_ref = try self.resolveType(ty, repr);
645645 const ip = &mod.intern_pool;
646646
647 var val = arg_val;
648 switch (ip.indexToKey(val.toIntern())) {
649 .runtime_value => |rt| val = rt.val.toValue(),
650 else => {},
651 }
647 const val = arg_val;
652648
653649 log.debug("constant: ty = {}, val = {}", .{ ty.fmt(mod), val.fmtValue(ty, mod) });
654650 if (val.isUndefDeep(mod)) {
......@@ -674,7 +670,7 @@ const DeclGen = struct {
674670 .inferred_error_set_type,
675671 => unreachable, // types, not values
676672
677 .undef, .runtime_value => unreachable, // handled above
673 .undef => unreachable, // handled above
678674
679675 .variable,
680676 .extern_func,
src/type.zig-9
......@@ -414,7 +414,6 @@ pub const Type = struct {
414414
415415 // values, not types
416416 .undef,
417 .runtime_value,
418417 .simple_value,
419418 .variable,
420419 .extern_func,
......@@ -633,7 +632,6 @@ pub const Type = struct {
633632
634633 // values, not types
635634 .undef,
636 .runtime_value,
637635 .simple_value,
638636 .variable,
639637 .extern_func,
......@@ -741,7 +739,6 @@ pub const Type = struct {
741739
742740 // values, not types
743741 .undef,
744 .runtime_value,
745742 .simple_value,
746743 .variable,
747744 .extern_func,
......@@ -1103,7 +1100,6 @@ pub const Type = struct {
11031100
11041101 // values, not types
11051102 .undef,
1106 .runtime_value,
11071103 .simple_value,
11081104 .variable,
11091105 .extern_func,
......@@ -1461,7 +1457,6 @@ pub const Type = struct {
14611457
14621458 // values, not types
14631459 .undef,
1464 .runtime_value,
14651460 .simple_value,
14661461 .variable,
14671462 .extern_func,
......@@ -1681,7 +1676,6 @@ pub const Type = struct {
16811676
16821677 // values, not types
16831678 .undef,
1684 .runtime_value,
16851679 .simple_value,
16861680 .variable,
16871681 .extern_func,
......@@ -2217,7 +2211,6 @@ pub const Type = struct {
22172211
22182212 // values, not types
22192213 .undef,
2220 .runtime_value,
22212214 .simple_value,
22222215 .variable,
22232216 .extern_func,
......@@ -2560,7 +2553,6 @@ pub const Type = struct {
25602553
25612554 // values, not types
25622555 .undef,
2563 .runtime_value,
25642556 .simple_value,
25652557 .variable,
25662558 .extern_func,
......@@ -2754,7 +2746,6 @@ pub const Type = struct {
27542746
27552747 // values, not types
27562748 .undef,
2757 .runtime_value,
27582749 .simple_value,
27592750 .variable,
27602751 .extern_func,
src/value.zig-30
......@@ -364,7 +364,6 @@ pub const Value = struct {
364364 .inferred_error_set_type,
365365
366366 .undef,
367 .runtime_value,
368367 .simple_value,
369368 .variable,
370369 .extern_func,
......@@ -464,7 +463,6 @@ pub const Value = struct {
464463 .bool_true => BigIntMutable.init(&space.limbs, 1).toConst(),
465464 .null_value => BigIntMutable.init(&space.limbs, 0).toConst(),
466465 else => switch (mod.intern_pool.indexToKey(val.toIntern())) {
467 .runtime_value => |runtime_value| runtime_value.val.toValue().toBigIntAdvanced(space, mod, opt_sema),
468466 .int => |int| switch (int.storage) {
469467 .u64, .i64, .big_int => int.storage.toBigInt(space),
470468 .lazy_align, .lazy_size => |ty| {
......@@ -1657,34 +1655,6 @@ pub const Value = struct {
16571655 };
16581656 }
16591657
1660 pub fn isRuntimeValue(val: Value, mod: *Module) bool {
1661 return mod.intern_pool.isRuntimeValue(val.toIntern());
1662 }
1663
1664 /// Returns true if a Value is backed by a variable
1665 pub fn isVariable(val: Value, mod: *Module) bool {
1666 return val.ip_index != .none and switch (mod.intern_pool.indexToKey(val.toIntern())) {
1667 .variable => true,
1668 .ptr => |ptr| switch (ptr.addr) {
1669 .decl => |decl_index| {
1670 const decl = mod.declPtr(decl_index);
1671 assert(decl.has_tv);
1672 return decl.val.isVariable(mod);
1673 },
1674 .mut_decl => |mut_decl| {
1675 const decl = mod.declPtr(mut_decl.decl);
1676 assert(decl.has_tv);
1677 return decl.val.isVariable(mod);
1678 },
1679 .int => false,
1680 .eu_payload, .opt_payload => |base_ptr| base_ptr.toValue().isVariable(mod),
1681 .comptime_field => |comptime_field| comptime_field.toValue().isVariable(mod),
1682 .elem, .field => |base_index| base_index.base.toValue().isVariable(mod),
1683 },
1684 else => false,
1685 };
1686 }
1687
16881658 pub fn isPtrToThreadLocal(val: Value, mod: *Module) bool {
16891659 const backing_decl = mod.intern_pool.getBackingDecl(val.toIntern()).unwrap() orelse return false;
16901660 const variable = mod.declPtr(backing_decl).getOwnedVariable(mod) orelse return false;