| author | |
| committer | |
| log | 20bb81166f36668413703e0d74b3e283c55ab8ca |
| tree | d68649f59e0899fbc49e7f9a188d3738f0ca1a3f |
| parent | bb0419599aa93455f3ae0969f4bfd80204807596 |
| signature |
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) { | ... | @@ -237,7 +237,6 @@ pub const Key = union(enum) { |
| 237 | /// Typed `undefined`. This will never be `none`; untyped `undefined` is represented | 237 | /// Typed `undefined`. This will never be `none`; untyped `undefined` is represented |
| 238 | /// via `simple_value` and has a named `Index` tag for it. | 238 | /// via `simple_value` and has a named `Index` tag for it. |
| 239 | undef: Index, | 239 | undef: Index, |
| 240 | runtime_value: TypeValue, | ||
| 241 | simple_value: SimpleValue, | 240 | simple_value: SimpleValue, |
| 242 | variable: Variable, | 241 | variable: Variable, |
| 243 | extern_func: ExternFunc, | 242 | extern_func: ExternFunc, |
| ... | @@ -1181,8 +1180,6 @@ pub const Key = union(enum) { | ... | @@ -1181,8 +1180,6 @@ pub const Key = union(enum) { |
| 1181 | .payload => |y| Hash.hash(seed + 1, asBytes(&x.ty) ++ asBytes(&y)), | 1180 | .payload => |y| Hash.hash(seed + 1, asBytes(&x.ty) ++ asBytes(&y)), |
| 1182 | }, | 1181 | }, |
| 1183 | 1182 | ||
| 1184 | .runtime_value => |x| Hash.hash(seed, asBytes(&x.val)), | ||
| 1185 | |||
| 1186 | inline .opaque_type, | 1183 | inline .opaque_type, |
| 1187 | .enum_type, | 1184 | .enum_type, |
| 1188 | .variable, | 1185 | .variable, |
| ... | @@ -1413,10 +1410,6 @@ pub const Key = union(enum) { | ... | @@ -1413,10 +1410,6 @@ pub const Key = union(enum) { |
| 1413 | const b_info = b.undef; | 1410 | const b_info = b.undef; |
| 1414 | return a_info == b_info; | 1411 | return a_info == b_info; |
| 1415 | }, | 1412 | }, |
| 1416 | .runtime_value => |a_info| { | ||
| 1417 | const b_info = b.runtime_value; | ||
| 1418 | return a_info.val == b_info.val; | ||
| 1419 | }, | ||
| 1420 | .opt => |a_info| { | 1413 | .opt => |a_info| { |
| 1421 | const b_info = b.opt; | 1414 | const b_info = b.opt; |
| 1422 | return std.meta.eql(a_info, b_info); | 1415 | return std.meta.eql(a_info, b_info); |
| ... | @@ -1703,8 +1696,7 @@ pub const Key = union(enum) { | ... | @@ -1703,8 +1696,7 @@ pub const Key = union(enum) { |
| 1703 | .func_type, | 1696 | .func_type, |
| 1704 | => .type_type, | 1697 | => .type_type, |
| 1705 | 1698 | ||
| 1706 | inline .runtime_value, | 1699 | inline .ptr, |
| 1707 | .ptr, | ||
| 1708 | .int, | 1700 | .int, |
| 1709 | .float, | 1701 | .float, |
| 1710 | .opt, | 1702 | .opt, |
| ... | @@ -2138,7 +2130,6 @@ pub const Index = enum(u32) { | ... | @@ -2138,7 +2130,6 @@ pub const Index = enum(u32) { |
| 2138 | }, | 2130 | }, |
| 2139 | 2131 | ||
| 2140 | undef: DataIsIndex, | 2132 | undef: DataIsIndex, |
| 2141 | runtime_value: struct { data: *Tag.TypeValue }, | ||
| 2142 | simple_value: struct { data: SimpleValue }, | 2133 | simple_value: struct { data: SimpleValue }, |
| 2143 | ptr_decl: struct { data: *PtrDecl }, | 2134 | ptr_decl: struct { data: *PtrDecl }, |
| 2144 | ptr_mut_decl: struct { data: *PtrMutDecl }, | 2135 | ptr_mut_decl: struct { data: *PtrMutDecl }, |
| ... | @@ -2580,10 +2571,6 @@ pub const Tag = enum(u8) { | ... | @@ -2580,10 +2571,6 @@ pub const Tag = enum(u8) { |
| 2580 | /// `data` is `Index` of the type. | 2571 | /// `data` is `Index` of the type. |
| 2581 | /// Untyped `undefined` is stored instead via `simple_value`. | 2572 | /// Untyped `undefined` is stored instead via `simple_value`. |
| 2582 | undef, | 2573 | 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, | ||
| 2587 | /// A value that can be represented with only an enum tag. | 2574 | /// A value that can be represented with only an enum tag. |
| 2588 | /// data is SimpleValue enum value. | 2575 | /// data is SimpleValue enum value. |
| 2589 | simple_value, | 2576 | simple_value, |
| ... | @@ -2795,7 +2782,6 @@ pub const Tag = enum(u8) { | ... | @@ -2795,7 +2782,6 @@ pub const Tag = enum(u8) { |
| 2795 | .type_function => TypeFunction, | 2782 | .type_function => TypeFunction, |
| 2796 | 2783 | ||
| 2797 | .undef => unreachable, | 2784 | .undef => unreachable, |
| 2798 | .runtime_value => TypeValue, | ||
| 2799 | .simple_value => unreachable, | 2785 | .simple_value => unreachable, |
| 2800 | .ptr_decl => PtrDecl, | 2786 | .ptr_decl => PtrDecl, |
| 2801 | .ptr_mut_decl => PtrMutDecl, | 2787 | .ptr_mut_decl => PtrMutDecl, |
| ... | @@ -3730,7 +3716,6 @@ pub fn indexToKey(ip: *const InternPool, index: Index) Key { | ... | @@ -3730,7 +3716,6 @@ pub fn indexToKey(ip: *const InternPool, index: Index) Key { |
| 3730 | .type_function => .{ .func_type = ip.extraFuncType(data) }, | 3716 | .type_function => .{ .func_type = ip.extraFuncType(data) }, |
| 3731 | 3717 | ||
| 3732 | .undef => .{ .undef = @as(Index, @enumFromInt(data)) }, | 3718 | .undef => .{ .undef = @as(Index, @enumFromInt(data)) }, |
| 3733 | .runtime_value => .{ .runtime_value = ip.extraData(Tag.TypeValue, data) }, | ||
| 3734 | .opt_null => .{ .opt = .{ | 3719 | .opt_null => .{ .opt = .{ |
| 3735 | .ty = @as(Index, @enumFromInt(data)), | 3720 | .ty = @as(Index, @enumFromInt(data)), |
| 3736 | .val = .none, | 3721 | .val = .none, |
| ... | @@ -4556,13 +4541,6 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index { | ... | @@ -4556,13 +4541,6 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index { |
| 4556 | .data = @intFromEnum(ty), | 4541 | .data = @intFromEnum(ty), |
| 4557 | }); | 4542 | }); |
| 4558 | }, | 4543 | }, |
| 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 | }, | ||
| 4566 | 4544 | ||
| 4567 | .struct_type => unreachable, // use getStructType() instead | 4545 | .struct_type => unreachable, // use getStructType() instead |
| 4568 | .anon_struct_type => unreachable, // use getAnonStructType() instead | 4546 | .anon_struct_type => unreachable, // use getAnonStructType() instead |
| ... | @@ -7237,7 +7215,6 @@ fn dumpStatsFallible(ip: *const InternPool, arena: Allocator) anyerror!void { | ... | @@ -7237,7 +7215,6 @@ fn dumpStatsFallible(ip: *const InternPool, arena: Allocator) anyerror!void { |
| 7237 | }, | 7215 | }, |
| 7238 | 7216 | ||
| 7239 | .undef => 0, | 7217 | .undef => 0, |
| 7240 | .runtime_value => @sizeOf(Tag.TypeValue), | ||
| 7241 | .simple_type => 0, | 7218 | .simple_type => 0, |
| 7242 | .simple_value => 0, | 7219 | .simple_value => 0, |
| 7243 | .ptr_decl => @sizeOf(PtrDecl), | 7220 | .ptr_decl => @sizeOf(PtrDecl), |
| ... | @@ -7370,7 +7347,6 @@ fn dumpAllFallible(ip: *const InternPool) anyerror!void { | ... | @@ -7370,7 +7347,6 @@ fn dumpAllFallible(ip: *const InternPool) anyerror!void { |
| 7370 | .type_union, | 7347 | .type_union, |
| 7371 | .type_function, | 7348 | .type_function, |
| 7372 | .undef, | 7349 | .undef, |
| 7373 | .runtime_value, | ||
| 7374 | .ptr_decl, | 7350 | .ptr_decl, |
| 7375 | .ptr_mut_decl, | 7351 | .ptr_mut_decl, |
| 7376 | .ptr_anon_decl, | 7352 | .ptr_anon_decl, |
| ... | @@ -7793,7 +7769,6 @@ pub fn typeOf(ip: *const InternPool, index: Index) Index { | ... | @@ -7793,7 +7769,6 @@ pub fn typeOf(ip: *const InternPool, index: Index) Index { |
| 7793 | .ptr_slice, | 7769 | .ptr_slice, |
| 7794 | .opt_payload, | 7770 | .opt_payload, |
| 7795 | .error_union_payload, | 7771 | .error_union_payload, |
| 7796 | .runtime_value, | ||
| 7797 | .int_small, | 7772 | .int_small, |
| 7798 | .int_lazy_align, | 7773 | .int_lazy_align, |
| 7799 | .int_lazy_size, | 7774 | .int_lazy_size, |
| ... | @@ -7906,10 +7881,6 @@ pub fn isUndef(ip: *const InternPool, val: Index) bool { | ... | @@ -7906,10 +7881,6 @@ pub fn isUndef(ip: *const InternPool, val: Index) bool { |
| 7906 | return val == .undef or ip.items.items(.tag)[@intFromEnum(val)] == .undef; | 7881 | return val == .undef or ip.items.items(.tag)[@intFromEnum(val)] == .undef; |
| 7907 | } | 7882 | } |
| 7908 | 7883 | ||
| 7909 | pub fn isRuntimeValue(ip: *const InternPool, val: Index) bool { | ||
| 7910 | return ip.items.items(.tag)[@intFromEnum(val)] == .runtime_value; | ||
| 7911 | } | ||
| 7912 | |||
| 7913 | pub fn isVariable(ip: *const InternPool, val: Index) bool { | 7884 | pub fn isVariable(ip: *const InternPool, val: Index) bool { |
| 7914 | return ip.items.items(.tag)[@intFromEnum(val)] == .variable; | 7885 | return ip.items.items(.tag)[@intFromEnum(val)] == .variable; |
| 7915 | } | 7886 | } |
| ... | @@ -8116,7 +8087,6 @@ pub fn zigTypeTagOrPoison(ip: *const InternPool, index: Index) error{GenericPois | ... | @@ -8116,7 +8087,6 @@ pub fn zigTypeTagOrPoison(ip: *const InternPool, index: Index) error{GenericPois |
| 8116 | 8087 | ||
| 8117 | // values, not types | 8088 | // values, not types |
| 8118 | .undef, | 8089 | .undef, |
| 8119 | .runtime_value, | ||
| 8120 | .simple_value, | 8090 | .simple_value, |
| 8121 | .ptr_decl, | 8091 | .ptr_decl, |
| 8122 | .ptr_mut_decl, | 8092 | .ptr_mut_decl, |
src/Module.zig+1-1| ... | @@ -3757,7 +3757,7 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !bool { | ... | @@ -3757,7 +3757,7 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !bool { |
| 3757 | const address_space_src: LazySrcLoc = .{ .node_offset_var_decl_addrspace = 0 }; | 3757 | const address_space_src: LazySrcLoc = .{ .node_offset_var_decl_addrspace = 0 }; |
| 3758 | const ty_src: LazySrcLoc = .{ .node_offset_var_decl_ty = 0 }; | 3758 | const ty_src: LazySrcLoc = .{ .node_offset_var_decl_ty = 0 }; |
| 3759 | const init_src: LazySrcLoc = .{ .node_offset_var_decl_init = 0 }; | 3759 | 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, .{ |
| 3761 | .needed_comptime_reason = "global variable initializer must be comptime-known", | 3761 | .needed_comptime_reason = "global variable initializer must be comptime-known", |
| 3762 | }); | 3762 | }); |
| 3763 | 3763 |
src/Sema.zig+76-154| ... | @@ -2071,25 +2071,18 @@ pub fn setupErrorReturnTrace(sema: *Sema, block: *Block, last_arg_index: usize) | ... | @@ -2071,25 +2071,18 @@ pub fn setupErrorReturnTrace(sema: *Sema, block: *Block, last_arg_index: usize) |
| 2071 | try block.instructions.insertSlice(gpa, last_arg_index, err_trace_block.instructions.items); | 2071 | try block.instructions.insertSlice(gpa, last_arg_index, err_trace_block.instructions.items); |
| 2072 | } | 2072 | } |
| 2073 | 2073 | ||
| 2074 | /// May return Value Tags: `variable`, `undef`. | 2074 | /// Return the Value corresponding to a given AIR ref, or `null` if it |
| 2075 | /// See `resolveConstValue` for an alternative. | 2075 | /// refers to a runtime value. |
| 2076 | /// Value Tag `generic_poison` causes `error.GenericPoison` to be returned. | 2076 | /// InternPool key `variable` is considered a runtime value. |
| 2077 | fn resolveValue( | 2077 | /// Generic poison causes `error.GenericPoison` to be returned. |
| 2078 | sema: *Sema, | 2078 | fn resolveMaybeUndefVal(sema: *Sema, inst: Air.Inst.Ref) CompileError!?Value { |
| 2079 | block: *Block, | 2079 | const val = (try sema.resolveMaybeUndefValAllowVariables(inst)) orelse return null; |
| 2080 | src: LazySrcLoc, | 2080 | if (val.isGenericPoison()) return error.GenericPoison; |
| 2081 | air_ref: Air.Inst.Ref, | 2081 | if (sema.mod.intern_pool.isVariable(val.toIntern())) return null; |
| 2082 | reason: NeededComptimeReason, | 2082 | return val; |
| 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); | ||
| 2089 | } | 2083 | } |
| 2090 | 2084 | ||
| 2091 | /// Value Tag `variable` will cause a compile error. | 2085 | /// Like `resolveMaybeUndefVal`, but emits an error if the value is not comptime-known. |
| 2092 | /// Value Tag `undef` may be returned. | ||
| 2093 | fn resolveConstMaybeUndefVal( | 2086 | fn resolveConstMaybeUndefVal( |
| 2094 | sema: *Sema, | 2087 | sema: *Sema, |
| 2095 | block: *Block, | 2088 | block: *Block, |
| ... | @@ -2097,17 +2090,12 @@ fn resolveConstMaybeUndefVal( | ... | @@ -2097,17 +2090,12 @@ fn resolveConstMaybeUndefVal( |
| 2097 | inst: Air.Inst.Ref, | 2090 | inst: Air.Inst.Ref, |
| 2098 | reason: NeededComptimeReason, | 2091 | reason: NeededComptimeReason, |
| 2099 | ) CompileError!Value { | 2092 | ) CompileError!Value { |
| 2100 | if (try sema.resolveMaybeUndefValAllowVariables(inst)) |val| { | 2093 | return try sema.resolveMaybeUndefVal(inst) orelse { |
| 2101 | if (val.isGenericPoison()) return error.GenericPoison; | 2094 | return sema.failWithNeededComptime(block, src, reason); |
| 2102 | if (sema.mod.intern_pool.isVariable(val.toIntern())) | 2095 | }; |
| 2103 | return sema.failWithNeededComptime(block, src, reason); | ||
| 2104 | return val; | ||
| 2105 | } | ||
| 2106 | return sema.failWithNeededComptime(block, src, reason); | ||
| 2107 | } | 2096 | } |
| 2108 | 2097 | ||
| 2109 | /// Will not return Value Tags: `variable`, `undef`. Instead they will emit compile errors. | 2098 | /// Like `resolveMaybeUndefVal`, but emits an error if the value is not comptime-known or is undefined. |
| 2110 | /// See `resolveValue` for an alternative. | ||
| 2111 | fn resolveConstValue( | 2099 | fn resolveConstValue( |
| 2112 | sema: *Sema, | 2100 | sema: *Sema, |
| 2113 | block: *Block, | 2101 | block: *Block, |
| ... | @@ -2115,30 +2103,12 @@ fn resolveConstValue( | ... | @@ -2115,30 +2103,12 @@ fn resolveConstValue( |
| 2115 | air_ref: Air.Inst.Ref, | 2103 | air_ref: Air.Inst.Ref, |
| 2116 | reason: NeededComptimeReason, | 2104 | reason: NeededComptimeReason, |
| 2117 | ) CompileError!Value { | 2105 | ) CompileError!Value { |
| 2118 | if (try sema.resolveMaybeUndefValAllowVariables(air_ref)) |val| { | 2106 | const val = try sema.resolveConstMaybeUndefVal(block, src, air_ref, reason); |
| 2119 | if (val.isGenericPoison()) return error.GenericPoison; | 2107 | if (val.isUndef(sema.mod)) return sema.failWithUseOfUndef(block, src); |
| 2120 | if (val.isUndef(sema.mod)) return sema.failWithUseOfUndef(block, src); | 2108 | return val; |
| 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. | ||
| 2130 | fn 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)); | ||
| 2138 | } | 2109 | } |
| 2139 | 2110 | ||
| 2140 | /// Value Tag `variable` causes this function to return `null`. | 2111 | /// Like `resolveMaybeUndefVal`, but emits an error if the value is comptime-known to be undefined. |
| 2141 | /// Value Tag `undef` causes this function to return a compile error. | ||
| 2142 | fn resolveDefinedValue( | 2112 | fn resolveDefinedValue( |
| 2143 | sema: *Sema, | 2113 | sema: *Sema, |
| 2144 | block: *Block, | 2114 | block: *Block, |
| ... | @@ -2146,44 +2116,24 @@ fn resolveDefinedValue( | ... | @@ -2146,44 +2116,24 @@ fn resolveDefinedValue( |
| 2146 | air_ref: Air.Inst.Ref, | 2116 | air_ref: Air.Inst.Ref, |
| 2147 | ) CompileError!?Value { | 2117 | ) CompileError!?Value { |
| 2148 | const mod = sema.mod; | 2118 | const mod = sema.mod; |
| 2149 | if (try sema.resolveMaybeUndefVal(air_ref)) |val| { | 2119 | const val = try sema.resolveMaybeUndefVal(air_ref) orelse return null; |
| 2150 | if (val.isUndef(mod)) { | 2120 | if (val.isUndef(mod)) { |
| 2151 | if (block.is_typeof) return null; | 2121 | if (block.is_typeof) return null; |
| 2152 | return sema.failWithUseOfUndef(block, src); | 2122 | return sema.failWithUseOfUndef(block, src); |
| 2153 | } | ||
| 2154 | return val; | ||
| 2155 | } | 2123 | } |
| 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. | ||
| 2162 | fn 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; | ||
| 2166 | return val; | 2124 | return val; |
| 2167 | } | 2125 | } |
| 2168 | 2126 | ||
| 2169 | /// Value Tag `variable` causes this function to return `null`. | 2127 | /// Like `resolveMaybeUndefVal`, but recursively resolves lazy values. |
| 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. | ||
| 2173 | fn resolveMaybeUndefLazyVal(sema: *Sema, inst: Air.Inst.Ref) CompileError!?Value { | 2128 | fn resolveMaybeUndefLazyVal(sema: *Sema, inst: Air.Inst.Ref) CompileError!?Value { |
| 2174 | return try sema.resolveLazyValue((try sema.resolveMaybeUndefVal(inst)) orelse return null); | 2129 | return try sema.resolveLazyValue((try sema.resolveMaybeUndefVal(inst)) orelse return null); |
| 2175 | } | 2130 | } |
| 2176 | 2131 | ||
| 2177 | /// Value Tag `variable` results in `null`. | 2132 | /// Like `resolveMaybeUndefVal`, but any pointer value which does not correspond |
| 2178 | /// Value Tag `undef` results in the Value. | 2133 | /// to a comptime-known integer (e.g. a decl pointer) returns `null`. |
| 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`. | ||
| 2181 | /// Lazy values are recursively resolved. | 2134 | /// Lazy values are recursively resolved. |
| 2182 | fn resolveMaybeUndefValIntable(sema: *Sema, inst: Air.Inst.Ref) CompileError!?Value { | 2135 | fn resolveMaybeUndefValIntable(sema: *Sema, inst: Air.Inst.Ref) CompileError!?Value { |
| 2183 | const val = (try sema.resolveMaybeUndefValAllowVariables(inst)) orelse return null; | 2136 | const val = (try sema.resolveMaybeUndefVal(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; | ||
| 2187 | if (sema.mod.intern_pool.getBackingAddrTag(val.toIntern())) |addr| switch (addr) { | 2137 | if (sema.mod.intern_pool.getBackingAddrTag(val.toIntern())) |addr| switch (addr) { |
| 2188 | .decl, .anon_decl, .mut_decl, .comptime_field => return null, | 2138 | .decl, .anon_decl, .mut_decl, .comptime_field => return null, |
| 2189 | .int => {}, | 2139 | .int => {}, |
| ... | @@ -2192,22 +2142,8 @@ fn resolveMaybeUndefValIntable(sema: *Sema, inst: Air.Inst.Ref) CompileError!?Va | ... | @@ -2192,22 +2142,8 @@ fn resolveMaybeUndefValIntable(sema: *Sema, inst: Air.Inst.Ref) CompileError!?Va |
| 2192 | return try sema.resolveLazyValue(val); | 2142 | return try sema.resolveLazyValue(val); |
| 2193 | } | 2143 | } |
| 2194 | 2144 | ||
| 2195 | /// Returns all Value tags including `variable` and `undef`. | 2145 | /// Returns all InternPool keys representing values, including `variable`, `undef`, and `generic_poison`. |
| 2196 | fn resolveMaybeUndefValAllowVariables(sema: *Sema, inst: Air.Inst.Ref) CompileError!?Value { | 2146 | fn 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`. | ||
| 2206 | fn resolveMaybeUndefValAllowVariablesMaybeRuntime( | ||
| 2207 | sema: *Sema, | ||
| 2208 | inst: Air.Inst.Ref, | ||
| 2209 | make_runtime: *bool, | ||
| 2210 | ) CompileError!?Value { | ||
| 2211 | assert(inst != .none); | 2147 | assert(inst != .none); |
| 2212 | // First section of indexes correspond to a set number of constant values. | 2148 | // First section of indexes correspond to a set number of constant values. |
| 2213 | if (@intFromEnum(inst) < InternPool.static_len) { | 2149 | if (@intFromEnum(inst) < InternPool.static_len) { |
| ... | @@ -2230,11 +2166,47 @@ fn resolveMaybeUndefValAllowVariablesMaybeRuntime( | ... | @@ -2230,11 +2166,47 @@ fn resolveMaybeUndefValAllowVariablesMaybeRuntime( |
| 2230 | } | 2166 | } |
| 2231 | }; | 2167 | }; |
| 2232 | const val = ip_index.toValue(); | 2168 | const val = ip_index.toValue(); |
| 2233 | if (val.isRuntimeValue(sema.mod)) make_runtime.* = true; | 2169 | if (val.isPtrToThreadLocal(sema.mod)) return null; |
| 2234 | if (val.isPtrToThreadLocal(sema.mod)) make_runtime.* = true; | ||
| 2235 | return val; | 2170 | return val; |
| 2236 | } | 2171 | } |
| 2237 | 2172 | ||
| 2173 | /// Returns a compile error if the value has tag `variable`. See `resolveInstValue` for | ||
| 2174 | /// a function that does not. | ||
| 2175 | pub 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. | ||
| 2192 | pub 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 | |||
| 2238 | fn failWithNeededComptime(sema: *Sema, block: *Block, src: LazySrcLoc, reason: NeededComptimeReason) CompileError { | 2210 | fn failWithNeededComptime(sema: *Sema, block: *Block, src: LazySrcLoc, reason: NeededComptimeReason) CompileError { |
| 2239 | const msg = msg: { | 2211 | const msg = msg: { |
| 2240 | const msg = try sema.errMsg(block, src, "unable to resolve comptime value", .{}); | 2212 | const msg = try sema.errMsg(block, src, "unable to resolve comptime value", .{}); |
| ... | @@ -2672,40 +2644,6 @@ fn analyzeAsInt( | ... | @@ -2672,40 +2644,6 @@ fn analyzeAsInt( |
| 2672 | return (try val.getUnsignedIntAdvanced(mod, sema)).?; | 2644 | return (try val.getUnsignedIntAdvanced(mod, sema)).?; |
| 2673 | } | 2645 | } |
| 2674 | 2646 | ||
| 2675 | // Returns a compile error if the value has tag `variable`. See `resolveInstValue` for | ||
| 2676 | // a function that does not. | ||
| 2677 | pub 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. | ||
| 2694 | pub 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 | |||
| 2709 | pub fn getStructType( | 2647 | pub fn getStructType( |
| 2710 | sema: *Sema, | 2648 | sema: *Sema, |
| 2711 | decl: Module.Decl.Index, | 2649 | decl: Module.Decl.Index, |
| ... | @@ -3681,7 +3619,7 @@ fn zirMakePtrConst(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro | ... | @@ -3681,7 +3619,7 @@ fn zirMakePtrConst(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro |
| 3681 | else => { | 3619 | else => { |
| 3682 | const decl_index = ptr_val.pointerDecl(mod) orelse break :implicit_ct; | 3620 | const decl_index = ptr_val.pointerDecl(mod) orelse break :implicit_ct; |
| 3683 | const decl_val = mod.declPtr(decl_index).val.toIntern(); | 3621 | 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; |
| 3685 | }, | 3623 | }, |
| 3686 | } | 3624 | } |
| 3687 | } | 3625 | } |
| ... | @@ -4637,7 +4575,6 @@ fn validateUnionInit( | ... | @@ -4637,7 +4575,6 @@ fn validateUnionInit( |
| 4637 | var first_block_index = block.instructions.items.len; | 4575 | var first_block_index = block.instructions.items.len; |
| 4638 | var block_index = block.instructions.items.len - 1; | 4576 | var block_index = block.instructions.items.len - 1; |
| 4639 | var init_val: ?Value = null; | 4577 | var init_val: ?Value = null; |
| 4640 | var make_runtime = false; | ||
| 4641 | while (block_index > 0) : (block_index -= 1) { | 4578 | while (block_index > 0) : (block_index -= 1) { |
| 4642 | const store_inst = block.instructions.items[block_index]; | 4579 | const store_inst = block.instructions.items[block_index]; |
| 4643 | if (Air.indexToRef(store_inst) == field_ptr_ref) break; | 4580 | if (Air.indexToRef(store_inst) == field_ptr_ref) break; |
| ... | @@ -4659,7 +4596,7 @@ fn validateUnionInit( | ... | @@ -4659,7 +4596,7 @@ fn validateUnionInit( |
| 4659 | ).? | 4596 | ).? |
| 4660 | else | 4597 | else |
| 4661 | block_index, first_block_index); | 4598 | 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); |
| 4663 | break; | 4600 | break; |
| 4664 | } | 4601 | } |
| 4665 | 4602 | ||
| ... | @@ -4693,15 +4630,11 @@ fn validateUnionInit( | ... | @@ -4693,15 +4630,11 @@ fn validateUnionInit( |
| 4693 | } | 4630 | } |
| 4694 | block.instructions.shrinkRetainingCapacity(block_index); | 4631 | block.instructions.shrinkRetainingCapacity(block_index); |
| 4695 | 4632 | ||
| 4696 | var union_val = try mod.intern(.{ .un = .{ | 4633 | const union_val = try mod.intern(.{ .un = .{ |
| 4697 | .ty = union_ty.toIntern(), | 4634 | .ty = union_ty.toIntern(), |
| 4698 | .tag = tag_val.toIntern(), | 4635 | .tag = tag_val.toIntern(), |
| 4699 | .val = val.toIntern(), | 4636 | .val = val.toIntern(), |
| 4700 | } }); | 4637 | } }); |
| 4701 | if (make_runtime) union_val = try mod.intern(.{ .runtime_value = .{ | ||
| 4702 | .ty = union_ty.toIntern(), | ||
| 4703 | .val = union_val, | ||
| 4704 | } }); | ||
| 4705 | const union_init = Air.internedToRef(union_val); | 4638 | const union_init = Air.internedToRef(union_val); |
| 4706 | try sema.storePtr2(block, init_src, union_ptr, init_src, union_init, init_src, .store); | 4639 | try sema.storePtr2(block, init_src, union_ptr, init_src, union_init, init_src, .store); |
| 4707 | return; | 4640 | return; |
| ... | @@ -4830,7 +4763,6 @@ fn validateStructInit( | ... | @@ -4830,7 +4763,6 @@ fn validateStructInit( |
| 4830 | 4763 | ||
| 4831 | var struct_is_comptime = true; | 4764 | var struct_is_comptime = true; |
| 4832 | var first_block_index = block.instructions.items.len; | 4765 | var first_block_index = block.instructions.items.len; |
| 4833 | var make_runtime = false; | ||
| 4834 | 4766 | ||
| 4835 | const require_comptime = try sema.typeRequiresComptime(struct_ty); | 4767 | const require_comptime = try sema.typeRequiresComptime(struct_ty); |
| 4836 | const air_tags = sema.air_instructions.items(.tag); | 4768 | const air_tags = sema.air_instructions.items(.tag); |
| ... | @@ -4898,7 +4830,7 @@ fn validateStructInit( | ... | @@ -4898,7 +4830,7 @@ fn validateStructInit( |
| 4898 | ).? | 4830 | ).? |
| 4899 | else | 4831 | else |
| 4900 | block_index, first_block_index); | 4832 | 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| { |
| 4902 | field_values[i] = val.toIntern(); | 4834 | field_values[i] = val.toIntern(); |
| 4903 | } else if (require_comptime) { | 4835 | } else if (require_comptime) { |
| 4904 | const field_ptr_data = sema.code.instructions.items(.data)[field_ptr].pl_node; | 4836 | const field_ptr_data = sema.code.instructions.items(.data)[field_ptr].pl_node; |
| ... | @@ -4989,14 +4921,10 @@ fn validateStructInit( | ... | @@ -4989,14 +4921,10 @@ fn validateStructInit( |
| 4989 | } | 4921 | } |
| 4990 | block.instructions.shrinkRetainingCapacity(block_index); | 4922 | block.instructions.shrinkRetainingCapacity(block_index); |
| 4991 | 4923 | ||
| 4992 | var struct_val = try mod.intern(.{ .aggregate = .{ | 4924 | const struct_val = try mod.intern(.{ .aggregate = .{ |
| 4993 | .ty = struct_ty.toIntern(), | 4925 | .ty = struct_ty.toIntern(), |
| 4994 | .storage = .{ .elems = field_values }, | 4926 | .storage = .{ .elems = field_values }, |
| 4995 | } }); | 4927 | } }); |
| 4996 | if (make_runtime) struct_val = try mod.intern(.{ .runtime_value = .{ | ||
| 4997 | .ty = struct_ty.toIntern(), | ||
| 4998 | .val = struct_val, | ||
| 4999 | } }); | ||
| 5000 | const struct_init = Air.internedToRef(struct_val); | 4928 | const struct_init = Air.internedToRef(struct_val); |
| 5001 | try sema.storePtr2(block, init_src, struct_ptr, init_src, struct_init, init_src, .store); | 4929 | try sema.storePtr2(block, init_src, struct_ptr, init_src, struct_init, init_src, .store); |
| 5002 | return; | 4930 | return; |
| ... | @@ -5095,7 +5023,6 @@ fn zirValidatePtrArrayInit( | ... | @@ -5095,7 +5023,6 @@ fn zirValidatePtrArrayInit( |
| 5095 | 5023 | ||
| 5096 | var array_is_comptime = true; | 5024 | var array_is_comptime = true; |
| 5097 | var first_block_index = block.instructions.items.len; | 5025 | var first_block_index = block.instructions.items.len; |
| 5098 | var make_runtime = false; | ||
| 5099 | 5026 | ||
| 5100 | // Collect the comptime element values in case the array literal ends up | 5027 | // Collect the comptime element values in case the array literal ends up |
| 5101 | // being comptime-known. | 5028 | // being comptime-known. |
| ... | @@ -5159,7 +5086,7 @@ fn zirValidatePtrArrayInit( | ... | @@ -5159,7 +5086,7 @@ fn zirValidatePtrArrayInit( |
| 5159 | ).? | 5086 | ).? |
| 5160 | else | 5087 | else |
| 5161 | block_index, first_block_index); | 5088 | 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| { |
| 5163 | element_vals[i] = val.toIntern(); | 5090 | element_vals[i] = val.toIntern(); |
| 5164 | } else { | 5091 | } else { |
| 5165 | array_is_comptime = false; | 5092 | array_is_comptime = false; |
| ... | @@ -5211,14 +5138,10 @@ fn zirValidatePtrArrayInit( | ... | @@ -5211,14 +5138,10 @@ fn zirValidatePtrArrayInit( |
| 5211 | } | 5138 | } |
| 5212 | block.instructions.shrinkRetainingCapacity(block_index); | 5139 | block.instructions.shrinkRetainingCapacity(block_index); |
| 5213 | 5140 | ||
| 5214 | var array_val = try mod.intern(.{ .aggregate = .{ | 5141 | const array_val = try mod.intern(.{ .aggregate = .{ |
| 5215 | .ty = array_ty.toIntern(), | 5142 | .ty = array_ty.toIntern(), |
| 5216 | .storage = .{ .elems = element_vals }, | 5143 | .storage = .{ .elems = element_vals }, |
| 5217 | } }); | 5144 | } }); |
| 5218 | if (make_runtime) array_val = try mod.intern(.{ .runtime_value = .{ | ||
| 5219 | .ty = array_ty.toIntern(), | ||
| 5220 | .val = array_val, | ||
| 5221 | } }); | ||
| 5222 | const array_init = Air.internedToRef(array_val); | 5145 | const array_init = Air.internedToRef(array_val); |
| 5223 | try sema.storePtr2(block, init_src, array_ptr, init_src, array_init, init_src, .store); | 5146 | try sema.storePtr2(block, init_src, array_ptr, init_src, array_init, init_src, .store); |
| 5224 | } | 5147 | } |
| ... | @@ -5452,8 +5375,7 @@ fn storeToInferredAllocComptime( | ... | @@ -5452,8 +5375,7 @@ fn storeToInferredAllocComptime( |
| 5452 | const operand_ty = sema.typeOf(operand); | 5375 | const operand_ty = sema.typeOf(operand); |
| 5453 | // There will be only one store_to_inferred_ptr because we are running at comptime. | 5376 | // There will be only one store_to_inferred_ptr because we are running at comptime. |
| 5454 | // The alloc will turn into a Decl. | 5377 | // The alloc will turn into a Decl. |
| 5455 | if (try sema.resolveMaybeUndefValAllowVariables(operand)) |operand_val| store: { | 5378 | if (try sema.resolveMaybeUndefVal(operand)) |operand_val| { |
| 5456 | if (operand_val.getVariable(sema.mod) != null) break :store; | ||
| 5457 | var anon_decl = try block.startAnonDecl(); // TODO: comptime value mutation without Decl | 5379 | var anon_decl = try block.startAnonDecl(); // TODO: comptime value mutation without Decl |
| 5458 | defer anon_decl.deinit(); | 5380 | defer anon_decl.deinit(); |
| 5459 | iac.decl_index = try anon_decl.finish(operand_ty, operand_val, iac.alignment); | 5381 | 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 | ... | @@ -12049,7 +11971,8 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 12049 | // `item` is already guaranteed to be constant known. | 11971 | // `item` is already guaranteed to be constant known. |
| 12050 | 11972 | ||
| 12051 | const analyze_body = if (union_originally) blk: { | 11973 | 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; | ||
| 12053 | const field_ty = maybe_union_ty.unionFieldType(item_val, mod).?; | 11976 | const field_ty = maybe_union_ty.unionFieldType(item_val, mod).?; |
| 12054 | break :blk field_ty.zigTypeTag(mod) != .NoReturn; | 11977 | break :blk field_ty.zigTypeTag(mod) != .NoReturn; |
| 12055 | } else true; | 11978 | } else true; |
| ... | @@ -16671,7 +16594,7 @@ fn zirClosureCapture(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr | ... | @@ -16671,7 +16594,7 @@ fn zirClosureCapture(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr |
| 16671 | .zir_index = inst, | 16594 | .zir_index = inst, |
| 16672 | .index = block.wip_capture_scope, | 16595 | .index = block.wip_capture_scope, |
| 16673 | }; | 16596 | }; |
| 16674 | if (try sema.resolveMaybeUndefValAllowVariables(operand)) |val| { | 16597 | if (try sema.resolveMaybeUndefVal(operand)) |val| { |
| 16675 | try mod.comptime_capture_scopes.put(gpa, key, try val.intern(ty, mod)); | 16598 | try mod.comptime_capture_scopes.put(gpa, key, try val.intern(ty, mod)); |
| 16676 | } else { | 16599 | } else { |
| 16677 | try mod.runtime_capture_scopes.put(gpa, key, ty.toIntern()); | 16600 | try mod.runtime_capture_scopes.put(gpa, key, ty.toIntern()); |
| ... | @@ -36644,7 +36567,6 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value { | ... | @@ -36644,7 +36567,6 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value { |
| 36644 | .simple_type, // handled above | 36567 | .simple_type, // handled above |
| 36645 | // values, not types | 36568 | // values, not types |
| 36646 | .undef, | 36569 | .undef, |
| 36647 | .runtime_value, | ||
| 36648 | .simple_value, | 36570 | .simple_value, |
| 36649 | .ptr_decl, | 36571 | .ptr_decl, |
| 36650 | .ptr_anon_decl, | 36572 | .ptr_anon_decl, |
src/TypedValue.zig-1| ... | @@ -206,7 +206,6 @@ pub fn print( | ... | @@ -206,7 +206,6 @@ pub fn print( |
| 206 | .inferred_error_set_type, | 206 | .inferred_error_set_type, |
| 207 | => return Type.print(val.toType(), writer, mod), | 207 | => return Type.print(val.toType(), writer, mod), |
| 208 | .undef => return writer.writeAll("undefined"), | 208 | .undef => return writer.writeAll("undefined"), |
| 209 | .runtime_value => return writer.writeAll("(runtime value)"), | ||
| 210 | .simple_value => |simple_value| switch (simple_value) { | 209 | .simple_value => |simple_value| switch (simple_value) { |
| 211 | .void => return writer.writeAll("{}"), | 210 | .void => return writer.writeAll("{}"), |
| 212 | .empty_struct => return printAggregate(ty, val, writer, level, mod), | 211 | .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( | ... | @@ -3224,16 +3224,11 @@ fn toTwosComplement(value: anytype, bits: u7) std.meta.Int(.unsigned, @typeInfo( |
| 3224 | 3224 | ||
| 3225 | /// This function is intended to assert that `isByRef` returns `false` for `ty`. | 3225 | /// This function is intended to assert that `isByRef` returns `false` for `ty`. |
| 3226 | /// However such an assertion fails on the behavior tests currently. | 3226 | /// However such an assertion fails on the behavior tests currently. |
| 3227 | fn lowerConstant(func: *CodeGen, arg_val: Value, ty: Type) InnerError!WValue { | 3227 | fn lowerConstant(func: *CodeGen, val: Value, ty: Type) InnerError!WValue { |
| 3228 | const mod = func.bin_file.base.options.module.?; | 3228 | const mod = func.bin_file.base.options.module.?; |
| 3229 | // TODO: enable this assertion | 3229 | // TODO: enable this assertion |
| 3230 | //assert(!isByRef(ty, mod)); | 3230 | //assert(!isByRef(ty, mod)); |
| 3231 | const ip = &mod.intern_pool; | 3231 | 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 | } | ||
| 3237 | if (val.isUndefDeep(mod)) return func.emitUndefined(ty); | 3232 | if (val.isUndefDeep(mod)) return func.emitUndefined(ty); |
| 3238 | 3233 | ||
| 3239 | switch (ip.indexToKey(val.ip_index)) { | 3234 | switch (ip.indexToKey(val.ip_index)) { |
| ... | @@ -3255,7 +3250,7 @@ fn lowerConstant(func: *CodeGen, arg_val: Value, ty: Type) InnerError!WValue { | ... | @@ -3255,7 +3250,7 @@ fn lowerConstant(func: *CodeGen, arg_val: Value, ty: Type) InnerError!WValue { |
| 3255 | .inferred_error_set_type, | 3250 | .inferred_error_set_type, |
| 3256 | => unreachable, // types, not values | 3251 | => unreachable, // types, not values |
| 3257 | 3252 | ||
| 3258 | .undef, .runtime_value => unreachable, // handled above | 3253 | .undef => unreachable, // handled above |
| 3259 | .simple_value => |simple_value| switch (simple_value) { | 3254 | .simple_value => |simple_value| switch (simple_value) { |
| 3260 | .undefined, | 3255 | .undefined, |
| 3261 | .void, | 3256 | .void, |
src/codegen.zig+3-11| ... | @@ -167,11 +167,7 @@ pub fn generateSymbol( | ... | @@ -167,11 +167,7 @@ pub fn generateSymbol( |
| 167 | 167 | ||
| 168 | const mod = bin_file.options.module.?; | 168 | const mod = bin_file.options.module.?; |
| 169 | const ip = &mod.intern_pool; | 169 | const ip = &mod.intern_pool; |
| 170 | var typed_value = arg_tv; | 170 | const 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 | } | ||
| 175 | 171 | ||
| 176 | const target = mod.getTarget(); | 172 | const target = mod.getTarget(); |
| 177 | const endian = target.cpu.arch.endian(); | 173 | const endian = target.cpu.arch.endian(); |
| ... | @@ -206,7 +202,7 @@ pub fn generateSymbol( | ... | @@ -206,7 +202,7 @@ pub fn generateSymbol( |
| 206 | .inferred_error_set_type, | 202 | .inferred_error_set_type, |
| 207 | => unreachable, // types, not values | 203 | => unreachable, // types, not values |
| 208 | 204 | ||
| 209 | .undef, .runtime_value => unreachable, // handled above | 205 | .undef => unreachable, // handled above |
| 210 | .simple_value => |simple_value| switch (simple_value) { | 206 | .simple_value => |simple_value| switch (simple_value) { |
| 211 | .undefined, | 207 | .undefined, |
| 212 | .void, | 208 | .void, |
| ... | @@ -970,11 +966,7 @@ pub fn genTypedValue( | ... | @@ -970,11 +966,7 @@ pub fn genTypedValue( |
| 970 | owner_decl_index: Module.Decl.Index, | 966 | owner_decl_index: Module.Decl.Index, |
| 971 | ) CodeGenError!GenResult { | 967 | ) CodeGenError!GenResult { |
| 972 | const mod = bin_file.options.module.?; | 968 | const mod = bin_file.options.module.?; |
| 973 | var typed_value = arg_tv; | 969 | const 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 | } | ||
| 978 | 970 | ||
| 979 | log.debug("genTypedValue: ty = {}, val = {}", .{ | 971 | log.debug("genTypedValue: ty = {}, val = {}", .{ |
| 980 | typed_value.ty.fmt(mod), | 972 | typed_value.ty.fmt(mod), |
src/codegen/c.zig+2-7| ... | @@ -772,17 +772,12 @@ pub const DeclGen = struct { | ... | @@ -772,17 +772,12 @@ pub const DeclGen = struct { |
| 772 | dg: *DeclGen, | 772 | dg: *DeclGen, |
| 773 | writer: anytype, | 773 | writer: anytype, |
| 774 | ty: Type, | 774 | ty: Type, |
| 775 | arg_val: Value, | 775 | val: Value, |
| 776 | location: ValueRenderLocation, | 776 | location: ValueRenderLocation, |
| 777 | ) error{ OutOfMemory, AnalysisFail }!void { | 777 | ) error{ OutOfMemory, AnalysisFail }!void { |
| 778 | const mod = dg.module; | 778 | const mod = dg.module; |
| 779 | const ip = &mod.intern_pool; | 779 | const ip = &mod.intern_pool; |
| 780 | 780 | ||
| 781 | var val = arg_val; | ||
| 782 | switch (ip.indexToKey(val.ip_index)) { | ||
| 783 | .runtime_value => |rt| val = rt.val.toValue(), | ||
| 784 | else => {}, | ||
| 785 | } | ||
| 786 | const target = mod.getTarget(); | 781 | const target = mod.getTarget(); |
| 787 | const initializer_type: ValueRenderLocation = switch (location) { | 782 | const initializer_type: ValueRenderLocation = switch (location) { |
| 788 | .StaticInitializer => .StaticInitializer, | 783 | .StaticInitializer => .StaticInitializer, |
| ... | @@ -1005,7 +1000,7 @@ pub const DeclGen = struct { | ... | @@ -1005,7 +1000,7 @@ pub const DeclGen = struct { |
| 1005 | .memoized_call, | 1000 | .memoized_call, |
| 1006 | => unreachable, | 1001 | => unreachable, |
| 1007 | 1002 | ||
| 1008 | .undef, .runtime_value => unreachable, // handled above | 1003 | .undef => unreachable, // handled above |
| 1009 | .simple_value => |simple_value| switch (simple_value) { | 1004 | .simple_value => |simple_value| switch (simple_value) { |
| 1010 | // non-runtime values | 1005 | // non-runtime values |
| 1011 | .undefined => unreachable, | 1006 | .undefined => unreachable, |
src/codegen/llvm.zig+5-10| ... | @@ -3560,7 +3560,6 @@ pub const Object = struct { | ... | @@ -3560,7 +3560,6 @@ pub const Object = struct { |
| 3560 | .error_set_type, .inferred_error_set_type => try o.errorIntType(), | 3560 | .error_set_type, .inferred_error_set_type => try o.errorIntType(), |
| 3561 | // values, not types | 3561 | // values, not types |
| 3562 | .undef, | 3562 | .undef, |
| 3563 | .runtime_value, | ||
| 3564 | .simple_value, | 3563 | .simple_value, |
| 3565 | .variable, | 3564 | .variable, |
| 3566 | .extern_func, | 3565 | .extern_func, |
| ... | @@ -3672,17 +3671,13 @@ pub const Object = struct { | ... | @@ -3672,17 +3671,13 @@ pub const Object = struct { |
| 3672 | const ip = &mod.intern_pool; | 3671 | const ip = &mod.intern_pool; |
| 3673 | const target = mod.getTarget(); | 3672 | const target = mod.getTarget(); |
| 3674 | 3673 | ||
| 3675 | var val = arg_val.toValue(); | 3674 | const val = arg_val.toValue(); |
| 3676 | const arg_val_key = ip.indexToKey(arg_val); | 3675 | const val_key = ip.indexToKey(val.toIntern()); |
| 3677 | switch (arg_val_key) { | 3676 | |
| 3678 | .runtime_value => |rt| val = rt.val.toValue(), | ||
| 3679 | else => {}, | ||
| 3680 | } | ||
| 3681 | if (val.isUndefDeep(mod)) { | 3677 | 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())); |
| 3683 | } | 3679 | } |
| 3684 | 3680 | ||
| 3685 | const val_key = ip.indexToKey(val.toIntern()); | ||
| 3686 | const ty = val_key.typeOf().toType(); | 3681 | const ty = val_key.typeOf().toType(); |
| 3687 | return switch (val_key) { | 3682 | return switch (val_key) { |
| 3688 | .int_type, | 3683 | .int_type, |
| ... | @@ -3703,7 +3698,7 @@ pub const Object = struct { | ... | @@ -3703,7 +3698,7 @@ pub const Object = struct { |
| 3703 | .inferred_error_set_type, | 3698 | .inferred_error_set_type, |
| 3704 | => unreachable, // types, not values | 3699 | => unreachable, // types, not values |
| 3705 | 3700 | ||
| 3706 | .undef, .runtime_value => unreachable, // handled above | 3701 | .undef => unreachable, // handled above |
| 3707 | .simple_value => |simple_value| switch (simple_value) { | 3702 | .simple_value => |simple_value| switch (simple_value) { |
| 3708 | .undefined, | 3703 | .undefined, |
| 3709 | .void, | 3704 | .void, |
src/codegen/spirv.zig+2-6| ... | @@ -644,11 +644,7 @@ const DeclGen = struct { | ... | @@ -644,11 +644,7 @@ const DeclGen = struct { |
| 644 | const result_ty_ref = try self.resolveType(ty, repr); | 644 | const result_ty_ref = try self.resolveType(ty, repr); |
| 645 | const ip = &mod.intern_pool; | 645 | const ip = &mod.intern_pool; |
| 646 | 646 | ||
| 647 | var val = arg_val; | 647 | const val = arg_val; |
| 648 | switch (ip.indexToKey(val.toIntern())) { | ||
| 649 | .runtime_value => |rt| val = rt.val.toValue(), | ||
| 650 | else => {}, | ||
| 651 | } | ||
| 652 | 648 | ||
| 653 | log.debug("constant: ty = {}, val = {}", .{ ty.fmt(mod), val.fmtValue(ty, mod) }); | 649 | log.debug("constant: ty = {}, val = {}", .{ ty.fmt(mod), val.fmtValue(ty, mod) }); |
| 654 | if (val.isUndefDeep(mod)) { | 650 | if (val.isUndefDeep(mod)) { |
| ... | @@ -674,7 +670,7 @@ const DeclGen = struct { | ... | @@ -674,7 +670,7 @@ const DeclGen = struct { |
| 674 | .inferred_error_set_type, | 670 | .inferred_error_set_type, |
| 675 | => unreachable, // types, not values | 671 | => unreachable, // types, not values |
| 676 | 672 | ||
| 677 | .undef, .runtime_value => unreachable, // handled above | 673 | .undef => unreachable, // handled above |
| 678 | 674 | ||
| 679 | .variable, | 675 | .variable, |
| 680 | .extern_func, | 676 | .extern_func, |
src/type.zig-9| ... | @@ -414,7 +414,6 @@ pub const Type = struct { | ... | @@ -414,7 +414,6 @@ pub const Type = struct { |
| 414 | 414 | ||
| 415 | // values, not types | 415 | // values, not types |
| 416 | .undef, | 416 | .undef, |
| 417 | .runtime_value, | ||
| 418 | .simple_value, | 417 | .simple_value, |
| 419 | .variable, | 418 | .variable, |
| 420 | .extern_func, | 419 | .extern_func, |
| ... | @@ -633,7 +632,6 @@ pub const Type = struct { | ... | @@ -633,7 +632,6 @@ pub const Type = struct { |
| 633 | 632 | ||
| 634 | // values, not types | 633 | // values, not types |
| 635 | .undef, | 634 | .undef, |
| 636 | .runtime_value, | ||
| 637 | .simple_value, | 635 | .simple_value, |
| 638 | .variable, | 636 | .variable, |
| 639 | .extern_func, | 637 | .extern_func, |
| ... | @@ -741,7 +739,6 @@ pub const Type = struct { | ... | @@ -741,7 +739,6 @@ pub const Type = struct { |
| 741 | 739 | ||
| 742 | // values, not types | 740 | // values, not types |
| 743 | .undef, | 741 | .undef, |
| 744 | .runtime_value, | ||
| 745 | .simple_value, | 742 | .simple_value, |
| 746 | .variable, | 743 | .variable, |
| 747 | .extern_func, | 744 | .extern_func, |
| ... | @@ -1103,7 +1100,6 @@ pub const Type = struct { | ... | @@ -1103,7 +1100,6 @@ pub const Type = struct { |
| 1103 | 1100 | ||
| 1104 | // values, not types | 1101 | // values, not types |
| 1105 | .undef, | 1102 | .undef, |
| 1106 | .runtime_value, | ||
| 1107 | .simple_value, | 1103 | .simple_value, |
| 1108 | .variable, | 1104 | .variable, |
| 1109 | .extern_func, | 1105 | .extern_func, |
| ... | @@ -1461,7 +1457,6 @@ pub const Type = struct { | ... | @@ -1461,7 +1457,6 @@ pub const Type = struct { |
| 1461 | 1457 | ||
| 1462 | // values, not types | 1458 | // values, not types |
| 1463 | .undef, | 1459 | .undef, |
| 1464 | .runtime_value, | ||
| 1465 | .simple_value, | 1460 | .simple_value, |
| 1466 | .variable, | 1461 | .variable, |
| 1467 | .extern_func, | 1462 | .extern_func, |
| ... | @@ -1681,7 +1676,6 @@ pub const Type = struct { | ... | @@ -1681,7 +1676,6 @@ pub const Type = struct { |
| 1681 | 1676 | ||
| 1682 | // values, not types | 1677 | // values, not types |
| 1683 | .undef, | 1678 | .undef, |
| 1684 | .runtime_value, | ||
| 1685 | .simple_value, | 1679 | .simple_value, |
| 1686 | .variable, | 1680 | .variable, |
| 1687 | .extern_func, | 1681 | .extern_func, |
| ... | @@ -2217,7 +2211,6 @@ pub const Type = struct { | ... | @@ -2217,7 +2211,6 @@ pub const Type = struct { |
| 2217 | 2211 | ||
| 2218 | // values, not types | 2212 | // values, not types |
| 2219 | .undef, | 2213 | .undef, |
| 2220 | .runtime_value, | ||
| 2221 | .simple_value, | 2214 | .simple_value, |
| 2222 | .variable, | 2215 | .variable, |
| 2223 | .extern_func, | 2216 | .extern_func, |
| ... | @@ -2560,7 +2553,6 @@ pub const Type = struct { | ... | @@ -2560,7 +2553,6 @@ pub const Type = struct { |
| 2560 | 2553 | ||
| 2561 | // values, not types | 2554 | // values, not types |
| 2562 | .undef, | 2555 | .undef, |
| 2563 | .runtime_value, | ||
| 2564 | .simple_value, | 2556 | .simple_value, |
| 2565 | .variable, | 2557 | .variable, |
| 2566 | .extern_func, | 2558 | .extern_func, |
| ... | @@ -2754,7 +2746,6 @@ pub const Type = struct { | ... | @@ -2754,7 +2746,6 @@ pub const Type = struct { |
| 2754 | 2746 | ||
| 2755 | // values, not types | 2747 | // values, not types |
| 2756 | .undef, | 2748 | .undef, |
| 2757 | .runtime_value, | ||
| 2758 | .simple_value, | 2749 | .simple_value, |
| 2759 | .variable, | 2750 | .variable, |
| 2760 | .extern_func, | 2751 | .extern_func, |
src/value.zig-6| ... | @@ -364,7 +364,6 @@ pub const Value = struct { | ... | @@ -364,7 +364,6 @@ pub const Value = struct { |
| 364 | .inferred_error_set_type, | 364 | .inferred_error_set_type, |
| 365 | 365 | ||
| 366 | .undef, | 366 | .undef, |
| 367 | .runtime_value, | ||
| 368 | .simple_value, | 367 | .simple_value, |
| 369 | .variable, | 368 | .variable, |
| 370 | .extern_func, | 369 | .extern_func, |
| ... | @@ -464,7 +463,6 @@ pub const Value = struct { | ... | @@ -464,7 +463,6 @@ pub const Value = struct { |
| 464 | .bool_true => BigIntMutable.init(&space.limbs, 1).toConst(), | 463 | .bool_true => BigIntMutable.init(&space.limbs, 1).toConst(), |
| 465 | .null_value => BigIntMutable.init(&space.limbs, 0).toConst(), | 464 | .null_value => BigIntMutable.init(&space.limbs, 0).toConst(), |
| 466 | else => switch (mod.intern_pool.indexToKey(val.toIntern())) { | 465 | else => switch (mod.intern_pool.indexToKey(val.toIntern())) { |
| 467 | .runtime_value => |runtime_value| runtime_value.val.toValue().toBigIntAdvanced(space, mod, opt_sema), | ||
| 468 | .int => |int| switch (int.storage) { | 466 | .int => |int| switch (int.storage) { |
| 469 | .u64, .i64, .big_int => int.storage.toBigInt(space), | 467 | .u64, .i64, .big_int => int.storage.toBigInt(space), |
| 470 | .lazy_align, .lazy_size => |ty| { | 468 | .lazy_align, .lazy_size => |ty| { |
| ... | @@ -1657,10 +1655,6 @@ pub const Value = struct { | ... | @@ -1657,10 +1655,6 @@ pub const Value = struct { |
| 1657 | }; | 1655 | }; |
| 1658 | } | 1656 | } |
| 1659 | 1657 | ||
| 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 | 1658 | /// Returns true if a Value is backed by a variable |
| 1665 | pub fn isVariable(val: Value, mod: *Module) bool { | 1659 | pub fn isVariable(val: Value, mod: *Module) bool { |
| 1666 | return val.ip_index != .none and switch (mod.intern_pool.indexToKey(val.toIntern())) { | 1660 | return val.ip_index != .none and switch (mod.intern_pool.indexToKey(val.toIntern())) { |