authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2023-10-24 04:36:35+01:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2023-10-24 14:28:33+01:00
log20bb81166f36668413703e0d74b3e283c55ab8ca
treed68649f59e0899fbc49e7f9a188d3738f0ca1a3f
parentbb0419599aa93455f3ae0969f4bfd80204807596
signaturelock-open Commit is signed but in an unrecognized format.

InternPool: remove runtime_value representation

The main goal of this commit is to remove the `runtime_value` field from `InternPool.Key` (and its associated representation), but there are a few dominos. Specifically, this mostly eliminates the "maybe runtime" concept from value resolution in Sema: so some resolution functions like `resolveMaybeUndefValAllowVariablesMaybeRuntime` are gone. This required a small change to struct/union/array initializers, to no longer use `runtime_value` if a field was a `variable` - I'm not convinced this case was even reachable, as `variable` should only ever exist as the trivial value of a global runtime `var` decl. Now, the only case in which a `Sema.resolveMaybeUndefVal`-esque function can return the `variable` key is `resolveMaybeUndefValAllowVariables`, which is directly called from `Sema.resolveInstValueAllowVariables` (previously `Sema.resolveInstValue`), which is only used for resolving the value of a Decl from `Module.semaDecl`. While changing these functions, I also slightly reordered and restructured some of them, and updated their doc comments.

11 files changed, 92 insertions(+), 243 deletions(-)

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+76-154
......@@ -2071,25 +2071,18 @@ 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
2075/// refers to a runtime value.
2076/// InternPool key `variable` is considered a runtime value.
2077/// Generic poison causes `error.GenericPoison` to be returned.
2078fn resolveMaybeUndefVal(sema: *Sema, inst: Air.Inst.Ref) CompileError!?Value {
2079 const val = (try sema.resolveMaybeUndefValAllowVariables(inst)) orelse return null;
2080 if (val.isGenericPoison()) return error.GenericPoison;
2081 if (sema.mod.intern_pool.isVariable(val.toIntern())) return null;
2082 return val;
20892083}
20902084
2091/// Value Tag `variable` will cause a compile error.
2092/// Value Tag `undef` may be returned.
2085/// Like `resolveMaybeUndefVal`, but emits an error if the value is not comptime-known.
20932086fn resolveConstMaybeUndefVal(
20942087 sema: *Sema,
20952088 block: *Block,
......@@ -2097,17 +2090,12 @@ fn resolveConstMaybeUndefVal(
20972090 inst: Air.Inst.Ref,
20982091 reason: NeededComptimeReason,
20992092) 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);
2093 return try sema.resolveMaybeUndefVal(inst) orelse {
2094 return sema.failWithNeededComptime(block, src, reason);
2095 };
21072096}
21082097
2109/// Will not return Value Tags: `variable`, `undef`. Instead they will emit compile errors.
2110/// See `resolveValue` for an alternative.
2098/// Like `resolveMaybeUndefVal`, but emits an error if the value is not comptime-known or is undefined.
21112099fn resolveConstValue(
21122100 sema: *Sema,
21132101 block: *Block,
......@@ -2115,30 +2103,12 @@ fn resolveConstValue(
21152103 air_ref: Air.Inst.Ref,
21162104 reason: NeededComptimeReason,
21172105) 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;
2124 }
2125 return sema.failWithNeededComptime(block, src, reason);
2126}
2127
2128/// Will not return Value Tags: `variable`, `undef`. Instead they will emit compile errors.
2129/// Lazy values are recursively resolved.
2130fn resolveConstLazyValue(
2131 sema: *Sema,
2132 block: *Block,
2133 src: LazySrcLoc,
2134 air_ref: Air.Inst.Ref,
2135 reason: NeededComptimeReason,
2136) CompileError!Value {
2137 return sema.resolveLazyValue(try sema.resolveConstValue(block, src, air_ref, reason));
2106 const val = try sema.resolveConstMaybeUndefVal(block, src, air_ref, reason);
2107 if (val.isUndef(sema.mod)) return sema.failWithUseOfUndef(block, src);
2108 return val;
21382109}
21392110
2140/// Value Tag `variable` causes this function to return `null`.
2141/// Value Tag `undef` causes this function to return a compile error.
2111/// Like `resolveMaybeUndefVal`, but emits an error if the value is comptime-known to be undefined.
21422112fn resolveDefinedValue(
21432113 sema: *Sema,
21442114 block: *Block,
......@@ -2146,44 +2116,24 @@ fn resolveDefinedValue(
21462116 air_ref: Air.Inst.Ref,
21472117) CompileError!?Value {
21482118 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;
2119 const val = try sema.resolveMaybeUndefVal(air_ref) orelse return null;
2120 if (val.isUndef(mod)) {
2121 if (block.is_typeof) return null;
2122 return sema.failWithUseOfUndef(block, src);
21552123 }
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;
21662124 return val;
21672125}
21682126
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.
2127/// Like `resolveMaybeUndefVal`, but recursively resolves lazy values.
21732128fn resolveMaybeUndefLazyVal(sema: *Sema, inst: Air.Inst.Ref) CompileError!?Value {
21742129 return try sema.resolveLazyValue((try sema.resolveMaybeUndefVal(inst)) orelse return null);
21752130}
21762131
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`.
2132/// Like `resolveMaybeUndefVal`, but any pointer value which does not correspond
2133/// to a comptime-known integer (e.g. a decl pointer) returns `null`.
21812134/// Lazy values are recursively resolved.
21822135fn 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;
2136 const val = (try sema.resolveMaybeUndefVal(inst)) orelse return null;
21872137 if (sema.mod.intern_pool.getBackingAddrTag(val.toIntern())) |addr| switch (addr) {
21882138 .decl, .anon_decl, .mut_decl, .comptime_field => return null,
21892139 .int => {},
......@@ -2192,22 +2142,8 @@ fn resolveMaybeUndefValIntable(sema: *Sema, inst: Air.Inst.Ref) CompileError!?Va
21922142 return try sema.resolveLazyValue(val);
21932143}
21942144
2195/// Returns all Value tags including `variable` and `undef`.
2145/// Returns all InternPool keys representing values, including `variable`, `undef`, and `generic_poison`.
21962146fn 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 {
22112147 assert(inst != .none);
22122148 // First section of indexes correspond to a set number of constant values.
22132149 if (@intFromEnum(inst) < InternPool.static_len) {
......@@ -2230,11 +2166,47 @@ fn resolveMaybeUndefValAllowVariablesMaybeRuntime(
22302166 }
22312167 };
22322168 const val = ip_index.toValue();
2233 if (val.isRuntimeValue(sema.mod)) make_runtime.* = true;
2234 if (val.isPtrToThreadLocal(sema.mod)) make_runtime.* = true;
2169 if (val.isPtrToThreadLocal(sema.mod)) return null;
22352170 return val;
22362171}
22372172
2173/// Returns a compile error if the value has tag `variable`. See `resolveInstValue` for
2174/// a function that does not.
2175pub fn resolveInstConst(
2176 sema: *Sema,
2177 block: *Block,
2178 src: LazySrcLoc,
2179 zir_ref: Zir.Inst.Ref,
2180 reason: NeededComptimeReason,
2181) CompileError!TypedValue {
2182 const air_ref = try sema.resolveInst(zir_ref);
2183 const val = try sema.resolveConstValue(block, src, air_ref, reason);
2184 return .{
2185 .ty = sema.typeOf(air_ref),
2186 .val = val,
2187 };
2188}
2189
2190/// Value Tag may be `undef` or `variable`.
2191/// See `resolveInstConst` for an alternative.
2192pub fn resolveInstValueAllowVariables(
2193 sema: *Sema,
2194 block: *Block,
2195 src: LazySrcLoc,
2196 zir_ref: Zir.Inst.Ref,
2197 reason: NeededComptimeReason,
2198) CompileError!TypedValue {
2199 const air_ref = try sema.resolveInst(zir_ref);
2200 const val = try sema.resolveMaybeUndefValAllowVariables(air_ref) orelse {
2201 return sema.failWithNeededComptime(block, src, reason);
2202 };
2203 if (val.isGenericPoison()) return error.GenericPoison;
2204 return .{
2205 .ty = sema.typeOf(air_ref),
2206 .val = val,
2207 };
2208}
2209
22382210fn failWithNeededComptime(sema: *Sema, block: *Block, src: LazySrcLoc, reason: NeededComptimeReason) CompileError {
22392211 const msg = msg: {
22402212 const msg = try sema.errMsg(block, src, "unable to resolve comptime value", .{});
......@@ -2672,40 +2644,6 @@ fn analyzeAsInt(
26722644 return (try val.getUnsignedIntAdvanced(mod, sema)).?;
26732645}
26742646
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
27092647pub fn getStructType(
27102648 sema: *Sema,
27112649 decl: Module.Decl.Index,
......@@ -3681,7 +3619,7 @@ fn zirMakePtrConst(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
36813619 else => {
36823620 const decl_index = ptr_val.pointerDecl(mod) orelse break :implicit_ct;
36833621 const decl_val = mod.declPtr(decl_index).val.toIntern();
3684 if (mod.intern_pool.isRuntimeValue(decl_val)) break :implicit_ct;
3622 if (mod.intern_pool.isVariable(decl_val)) break :implicit_ct;
36853623 },
36863624 }
36873625 }
......@@ -4637,7 +4575,6 @@ fn validateUnionInit(
46374575 var first_block_index = block.instructions.items.len;
46384576 var block_index = block.instructions.items.len - 1;
46394577 var init_val: ?Value = null;
4640 var make_runtime = false;
46414578 while (block_index > 0) : (block_index -= 1) {
46424579 const store_inst = block.instructions.items[block_index];
46434580 if (Air.indexToRef(store_inst) == field_ptr_ref) break;
......@@ -4659,7 +4596,7 @@ fn validateUnionInit(
46594596 ).?
46604597 else
46614598 block_index, first_block_index);
4662 init_val = try sema.resolveMaybeUndefValAllowVariablesMaybeRuntime(bin_op.rhs, &make_runtime);
4599 init_val = try sema.resolveMaybeUndefVal(bin_op.rhs);
46634600 break;
46644601 }
46654602
......@@ -4693,15 +4630,11 @@ fn validateUnionInit(
46934630 }
46944631 block.instructions.shrinkRetainingCapacity(block_index);
46954632
4696 var union_val = try mod.intern(.{ .un = .{
4633 const union_val = try mod.intern(.{ .un = .{
46974634 .ty = union_ty.toIntern(),
46984635 .tag = tag_val.toIntern(),
46994636 .val = val.toIntern(),
47004637 } });
4701 if (make_runtime) union_val = try mod.intern(.{ .runtime_value = .{
4702 .ty = union_ty.toIntern(),
4703 .val = union_val,
4704 } });
47054638 const union_init = Air.internedToRef(union_val);
47064639 try sema.storePtr2(block, init_src, union_ptr, init_src, union_init, init_src, .store);
47074640 return;
......@@ -4830,7 +4763,6 @@ fn validateStructInit(
48304763
48314764 var struct_is_comptime = true;
48324765 var first_block_index = block.instructions.items.len;
4833 var make_runtime = false;
48344766
48354767 const require_comptime = try sema.typeRequiresComptime(struct_ty);
48364768 const air_tags = sema.air_instructions.items(.tag);
......@@ -4898,7 +4830,7 @@ fn validateStructInit(
48984830 ).?
48994831 else
49004832 block_index, first_block_index);
4901 if (try sema.resolveMaybeUndefValAllowVariablesMaybeRuntime(bin_op.rhs, &make_runtime)) |val| {
4833 if (try sema.resolveMaybeUndefVal(bin_op.rhs)) |val| {
49024834 field_values[i] = val.toIntern();
49034835 } else if (require_comptime) {
49044836 const field_ptr_data = sema.code.instructions.items(.data)[field_ptr].pl_node;
......@@ -4989,14 +4921,10 @@ fn validateStructInit(
49894921 }
49904922 block.instructions.shrinkRetainingCapacity(block_index);
49914923
4992 var struct_val = try mod.intern(.{ .aggregate = .{
4924 const struct_val = try mod.intern(.{ .aggregate = .{
49934925 .ty = struct_ty.toIntern(),
49944926 .storage = .{ .elems = field_values },
49954927 } });
4996 if (make_runtime) struct_val = try mod.intern(.{ .runtime_value = .{
4997 .ty = struct_ty.toIntern(),
4998 .val = struct_val,
4999 } });
50004928 const struct_init = Air.internedToRef(struct_val);
50014929 try sema.storePtr2(block, init_src, struct_ptr, init_src, struct_init, init_src, .store);
50024930 return;
......@@ -5095,7 +5023,6 @@ fn zirValidatePtrArrayInit(
50955023
50965024 var array_is_comptime = true;
50975025 var first_block_index = block.instructions.items.len;
5098 var make_runtime = false;
50995026
51005027 // Collect the comptime element values in case the array literal ends up
51015028 // being comptime-known.
......@@ -5159,7 +5086,7 @@ fn zirValidatePtrArrayInit(
51595086 ).?
51605087 else
51615088 block_index, first_block_index);
5162 if (try sema.resolveMaybeUndefValAllowVariablesMaybeRuntime(bin_op.rhs, &make_runtime)) |val| {
5089 if (try sema.resolveMaybeUndefVal(bin_op.rhs)) |val| {
51635090 element_vals[i] = val.toIntern();
51645091 } else {
51655092 array_is_comptime = false;
......@@ -5211,14 +5138,10 @@ fn zirValidatePtrArrayInit(
52115138 }
52125139 block.instructions.shrinkRetainingCapacity(block_index);
52135140
5214 var array_val = try mod.intern(.{ .aggregate = .{
5141 const array_val = try mod.intern(.{ .aggregate = .{
52155142 .ty = array_ty.toIntern(),
52165143 .storage = .{ .elems = element_vals },
52175144 } });
5218 if (make_runtime) array_val = try mod.intern(.{ .runtime_value = .{
5219 .ty = array_ty.toIntern(),
5220 .val = array_val,
5221 } });
52225145 const array_init = Air.internedToRef(array_val);
52235146 try sema.storePtr2(block, init_src, array_ptr, init_src, array_init, init_src, .store);
52245147 }
......@@ -5452,8 +5375,7 @@ fn storeToInferredAllocComptime(
54525375 const operand_ty = sema.typeOf(operand);
54535376 // There will be only one store_to_inferred_ptr because we are running at comptime.
54545377 // 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;
5378 if (try sema.resolveMaybeUndefVal(operand)) |operand_val| {
54575379 var anon_decl = try block.startAnonDecl(); // TODO: comptime value mutation without Decl
54585380 defer anon_decl.deinit();
54595381 iac.decl_index = try anon_decl.finish(operand_ty, operand_val, iac.alignment);
......@@ -12049,7 +11971,8 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1204911971 // `item` is already guaranteed to be constant known.
1205011972
1205111973 const analyze_body = if (union_originally) blk: {
12052 const item_val = sema.resolveConstLazyValue(block, .unneeded, item, undefined) catch unreachable;
11974 const unresolved_item_val = sema.resolveConstValue(block, .unneeded, item, undefined) catch unreachable;
11975 const item_val = sema.resolveLazyValue(unresolved_item_val) catch unreachable;
1205311976 const field_ty = maybe_union_ty.unionFieldType(item_val, mod).?;
1205411977 break :blk field_ty.zigTypeTag(mod) != .NoReturn;
1205511978 } else true;
......@@ -16671,7 +16594,7 @@ fn zirClosureCapture(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr
1667116594 .zir_index = inst,
1667216595 .index = block.wip_capture_scope,
1667316596 };
16674 if (try sema.resolveMaybeUndefValAllowVariables(operand)) |val| {
16597 if (try sema.resolveMaybeUndefVal(operand)) |val| {
1667516598 try mod.comptime_capture_scopes.put(gpa, key, try val.intern(ty, mod));
1667616599 } else {
1667716600 try mod.runtime_capture_scopes.put(gpa, key, ty.toIntern());
......@@ -36644,7 +36567,6 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {
3664436567 .simple_type, // handled above
3664536568 // values, not types
3664636569 .undef,
36647 .runtime_value,
3664836570 .simple_value,
3664936571 .ptr_decl,
3665036572 .ptr_anon_decl,
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-6
......@@ -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,10 +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
16641658 /// Returns true if a Value is backed by a variable
16651659 pub fn isVariable(val: Value, mod: *Module) bool {
16661660 return val.ip_index != .none and switch (mod.intern_pool.indexToKey(val.toIntern())) {