| ... | ... | @@ -1741,7 +1741,7 @@ fn analyzeBodyInner( |
| 1741 | 1741 | } |
| 1742 | 1742 | const is_non_err = try sema.analyzeIsNonErrComptimeOnly(block, operand_src, err_union); |
| 1743 | 1743 | 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, .{ |
| 1745 | 1745 | .needed_comptime_reason = "try operand inside comptime block must be comptime-known", |
| 1746 | 1746 | .block_comptime_reason = block.comptime_reason, |
| 1747 | 1747 | }); |
| ... | ... | @@ -1767,7 +1767,7 @@ fn analyzeBodyInner( |
| 1767 | 1767 | const err_union = try sema.analyzeLoad(block, src, operand, operand_src); |
| 1768 | 1768 | const is_non_err = try sema.analyzeIsNonErrComptimeOnly(block, operand_src, err_union); |
| 1769 | 1769 | 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, .{ |
| 1771 | 1771 | .needed_comptime_reason = "try operand inside comptime block must be comptime-known", |
| 1772 | 1772 | .block_comptime_reason = block.comptime_reason, |
| 1773 | 1773 | }); |
| ... | ... | @@ -1866,7 +1866,7 @@ fn resolveConstBool( |
| 1866 | 1866 | const air_inst = try sema.resolveInst(zir_ref); |
| 1867 | 1867 | const wanted_type = Type.bool; |
| 1868 | 1868 | 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); |
| 1870 | 1870 | return val.toBool(); |
| 1871 | 1871 | } |
| 1872 | 1872 | |
| ... | ... | @@ -1880,7 +1880,7 @@ pub fn resolveConstString( |
| 1880 | 1880 | const air_inst = try sema.resolveInst(zir_ref); |
| 1881 | 1881 | const wanted_type = Type.slice_const_u8; |
| 1882 | 1882 | 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); |
| 1884 | 1884 | return val.toAllocatedBytes(wanted_type, sema.arena, sema.mod); |
| 1885 | 1885 | } |
| 1886 | 1886 | |
| ... | ... | @@ -1894,7 +1894,7 @@ pub fn resolveConstStringIntern( |
| 1894 | 1894 | const air_inst = try sema.resolveInst(zir_ref); |
| 1895 | 1895 | const wanted_type = Type.slice_const_u8; |
| 1896 | 1896 | 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); |
| 1898 | 1898 | return val.toIpString(wanted_type, sema.mod); |
| 1899 | 1899 | } |
| 1900 | 1900 | |
| ... | ... | @@ -2024,7 +2024,7 @@ fn analyzeAsType( |
| 2024 | 2024 | ) !Type { |
| 2025 | 2025 | const wanted_type = Type.type; |
| 2026 | 2026 | 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, .{ |
| 2028 | 2028 | .needed_comptime_reason = "types must be comptime-known", |
| 2029 | 2029 | }); |
| 2030 | 2030 | return val.toType(); |
| ... | ... | @@ -2071,44 +2071,30 @@ pub fn setupErrorReturnTrace(sema: *Sema, block: *Block, last_arg_index: usize) |
| 2071 | 2071 | try block.instructions.insertSlice(gpa, last_arg_index, err_trace_block.instructions.items); |
| 2072 | 2072 | } |
| 2073 | 2073 | |
| 2074 | | /// Return the Value corresponding to a given AIR ref, or `null` if it |
| 2075 | | /// refers to a runtime value. |
| 2074 | /// Return the Value corresponding to a given AIR ref, or `null` if it refers to a runtime value. |
| 2076 | 2075 | /// InternPool key `variable` is considered a runtime value. |
| 2077 | 2076 | /// Generic poison causes `error.GenericPoison` to be returned. |
| 2078 | | fn resolveMaybeUndefVal(sema: *Sema, inst: Air.Inst.Ref) CompileError!?Value { |
| 2079 | | const val = (try sema.resolveMaybeUndefValAllowVariables(inst)) orelse return null; |
| 2077 | fn resolveValue(sema: *Sema, inst: Air.Inst.Ref) CompileError!?Value { |
| 2078 | const val = (try sema.resolveValueAllowVariables(inst)) orelse return null; |
| 2080 | 2079 | if (val.isGenericPoison()) return error.GenericPoison; |
| 2081 | 2080 | if (sema.mod.intern_pool.isVariable(val.toIntern())) return null; |
| 2082 | 2081 | return val; |
| 2083 | 2082 | } |
| 2084 | 2083 | |
| 2085 | | /// Like `resolveMaybeUndefVal`, but emits an error if the value is not comptime-known. |
| 2086 | | fn resolveConstMaybeUndefVal( |
| 2084 | /// Like `resolveValue`, but emits an error if the value is not comptime-known. |
| 2085 | fn resolveConstValue( |
| 2087 | 2086 | sema: *Sema, |
| 2088 | 2087 | block: *Block, |
| 2089 | 2088 | src: LazySrcLoc, |
| 2090 | 2089 | inst: Air.Inst.Ref, |
| 2091 | 2090 | reason: NeededComptimeReason, |
| 2092 | 2091 | ) CompileError!Value { |
| 2093 | | return try sema.resolveMaybeUndefVal(inst) orelse { |
| 2092 | return try sema.resolveValue(inst) orelse { |
| 2094 | 2093 | return sema.failWithNeededComptime(block, src, reason); |
| 2095 | 2094 | }; |
| 2096 | 2095 | } |
| 2097 | 2096 | |
| 2098 | | /// Like `resolveMaybeUndefVal`, but emits an error if the value is not comptime-known or is undefined. |
| 2099 | | fn resolveConstValue( |
| 2100 | | sema: *Sema, |
| 2101 | | block: *Block, |
| 2102 | | src: LazySrcLoc, |
| 2103 | | air_ref: Air.Inst.Ref, |
| 2104 | | reason: NeededComptimeReason, |
| 2105 | | ) CompileError!Value { |
| 2106 | | const val = try sema.resolveConstMaybeUndefVal(block, src, air_ref, reason); |
| 2107 | | if (val.isUndef(sema.mod)) return sema.failWithUseOfUndef(block, src); |
| 2108 | | return val; |
| 2109 | | } |
| 2110 | | |
| 2111 | | /// Like `resolveMaybeUndefVal`, but emits an error if the value is comptime-known to be undefined. |
| 2097 | /// Like `resolveValue`, but emits an error if the value is comptime-known to be undefined. |
| 2112 | 2098 | fn resolveDefinedValue( |
| 2113 | 2099 | sema: *Sema, |
| 2114 | 2100 | block: *Block, |
| ... | ... | @@ -2116,7 +2102,7 @@ fn resolveDefinedValue( |
| 2116 | 2102 | air_ref: Air.Inst.Ref, |
| 2117 | 2103 | ) CompileError!?Value { |
| 2118 | 2104 | const mod = sema.mod; |
| 2119 | | const val = try sema.resolveMaybeUndefVal(air_ref) orelse return null; |
| 2105 | const val = try sema.resolveValue(air_ref) orelse return null; |
| 2120 | 2106 | if (val.isUndef(mod)) { |
| 2121 | 2107 | if (block.is_typeof) return null; |
| 2122 | 2108 | return sema.failWithUseOfUndef(block, src); |
| ... | ... | @@ -2124,16 +2110,29 @@ fn resolveDefinedValue( |
| 2124 | 2110 | return val; |
| 2125 | 2111 | } |
| 2126 | 2112 | |
| 2127 | | /// Like `resolveMaybeUndefVal`, but recursively resolves lazy values. |
| 2128 | | fn resolveMaybeUndefLazyVal(sema: *Sema, inst: Air.Inst.Ref) CompileError!?Value { |
| 2129 | | return try sema.resolveLazyValue((try sema.resolveMaybeUndefVal(inst)) orelse return null); |
| 2113 | /// Like `resolveValue`, but emits an error if the value is not comptime-known or is undefined. |
| 2114 | fn resolveConstDefinedValue( |
| 2115 | sema: *Sema, |
| 2116 | block: *Block, |
| 2117 | src: LazySrcLoc, |
| 2118 | air_ref: Air.Inst.Ref, |
| 2119 | reason: NeededComptimeReason, |
| 2120 | ) CompileError!Value { |
| 2121 | const val = try sema.resolveConstValue(block, src, air_ref, reason); |
| 2122 | if (val.isUndef(sema.mod)) return sema.failWithUseOfUndef(block, src); |
| 2123 | return val; |
| 2130 | 2124 | } |
| 2131 | 2125 | |
| 2132 | | /// Like `resolveMaybeUndefVal`, but any pointer value which does not correspond |
| 2126 | /// Like `resolveValue`, but recursively resolves lazy values before returning. |
| 2127 | fn resolveValueResolveLazy(sema: *Sema, inst: Air.Inst.Ref) CompileError!?Value { |
| 2128 | return try sema.resolveLazyValue((try sema.resolveValue(inst)) orelse return null); |
| 2129 | } |
| 2130 | |
| 2131 | /// Like `resolveValue`, but any pointer value which does not correspond |
| 2133 | 2132 | /// to a comptime-known integer (e.g. a decl pointer) returns `null`. |
| 2134 | 2133 | /// Lazy values are recursively resolved. |
| 2135 | | fn resolveMaybeUndefValIntable(sema: *Sema, inst: Air.Inst.Ref) CompileError!?Value { |
| 2136 | | const val = (try sema.resolveMaybeUndefVal(inst)) orelse return null; |
| 2134 | fn resolveValueIntable(sema: *Sema, inst: Air.Inst.Ref) CompileError!?Value { |
| 2135 | const val = (try sema.resolveValue(inst)) orelse return null; |
| 2137 | 2136 | if (sema.mod.intern_pool.getBackingAddrTag(val.toIntern())) |addr| switch (addr) { |
| 2138 | 2137 | .decl, .anon_decl, .mut_decl, .comptime_field => return null, |
| 2139 | 2138 | .int => {}, |
| ... | ... | @@ -2143,7 +2142,7 @@ fn resolveMaybeUndefValIntable(sema: *Sema, inst: Air.Inst.Ref) CompileError!?Va |
| 2143 | 2142 | } |
| 2144 | 2143 | |
| 2145 | 2144 | /// Returns all InternPool keys representing values, including `variable`, `undef`, and `generic_poison`. |
| 2146 | | fn resolveMaybeUndefValAllowVariables(sema: *Sema, inst: Air.Inst.Ref) CompileError!?Value { |
| 2145 | fn resolveValueAllowVariables(sema: *Sema, inst: Air.Inst.Ref) CompileError!?Value { |
| 2147 | 2146 | assert(inst != .none); |
| 2148 | 2147 | // First section of indexes correspond to a set number of constant values. |
| 2149 | 2148 | if (@intFromEnum(inst) < InternPool.static_len) { |
| ... | ... | @@ -2180,7 +2179,7 @@ pub fn resolveInstConst( |
| 2180 | 2179 | reason: NeededComptimeReason, |
| 2181 | 2180 | ) CompileError!TypedValue { |
| 2182 | 2181 | const air_ref = try sema.resolveInst(zir_ref); |
| 2183 | | const val = try sema.resolveConstValue(block, src, air_ref, reason); |
| 2182 | const val = try sema.resolveConstDefinedValue(block, src, air_ref, reason); |
| 2184 | 2183 | return .{ |
| 2185 | 2184 | .ty = sema.typeOf(air_ref), |
| 2186 | 2185 | .val = val, |
| ... | ... | @@ -2197,7 +2196,7 @@ pub fn resolveInstValueAllowVariables( |
| 2197 | 2196 | reason: NeededComptimeReason, |
| 2198 | 2197 | ) CompileError!TypedValue { |
| 2199 | 2198 | const air_ref = try sema.resolveInst(zir_ref); |
| 2200 | | const val = try sema.resolveMaybeUndefValAllowVariables(air_ref) orelse { |
| 2199 | const val = try sema.resolveValueAllowVariables(air_ref) orelse { |
| 2201 | 2200 | return sema.failWithNeededComptime(block, src, reason); |
| 2202 | 2201 | }; |
| 2203 | 2202 | if (val.isGenericPoison()) return error.GenericPoison; |
| ... | ... | @@ -2640,7 +2639,7 @@ fn analyzeAsInt( |
| 2640 | 2639 | ) !u64 { |
| 2641 | 2640 | const mod = sema.mod; |
| 2642 | 2641 | const coerced = try sema.coerce(block, dest_ty, air_ref, src); |
| 2643 | | const val = try sema.resolveConstValue(block, src, coerced, reason); |
| 2642 | const val = try sema.resolveConstDefinedValue(block, src, coerced, reason); |
| 2644 | 2643 | return (try val.getUnsignedIntAdvanced(mod, sema)).?; |
| 2645 | 2644 | } |
| 2646 | 2645 | |
| ... | ... | @@ -2811,7 +2810,7 @@ fn createAnonymousDeclTypeNamed( |
| 2811 | 2810 | // If not then this is a struct type being returned from a non-generic |
| 2812 | 2811 | // function and the name doesn't matter since it will later |
| 2813 | 2812 | // result in a compile error. |
| 2814 | | const arg_val = sema.resolveConstMaybeUndefVal(block, .unneeded, arg, undefined) catch |
| 2813 | const arg_val = sema.resolveConstValue(block, .unneeded, arg, undefined) catch |
| 2815 | 2814 | return sema.createAnonymousDeclTypeNamed(block, src, typed_value, .anon, anon_prefix, null); |
| 2816 | 2815 | |
| 2817 | 2816 | if (arg_i != 0) try writer.writeByte(','); |
| ... | ... | @@ -3055,13 +3054,13 @@ fn zirEnumDecl( |
| 3055 | 3054 | const tag_val_ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_index]); |
| 3056 | 3055 | extra_index += 1; |
| 3057 | 3056 | const tag_inst = try sema.resolveInst(tag_val_ref); |
| 3058 | | last_tag_val = sema.resolveConstValue(block, .unneeded, tag_inst, undefined) catch |err| switch (err) { |
| 3057 | last_tag_val = sema.resolveConstDefinedValue(block, .unneeded, tag_inst, undefined) catch |err| switch (err) { |
| 3059 | 3058 | error.NeededSourceLocation => { |
| 3060 | 3059 | const value_src = mod.fieldSrcLoc(new_decl_index, .{ |
| 3061 | 3060 | .index = field_i, |
| 3062 | 3061 | .range = .value, |
| 3063 | 3062 | }).lazy; |
| 3064 | | _ = try sema.resolveConstValue(block, value_src, tag_inst, .{ |
| 3063 | _ = try sema.resolveConstDefinedValue(block, value_src, tag_inst, .{ |
| 3065 | 3064 | .needed_comptime_reason = "enum tag value must be comptime-known", |
| 3066 | 3065 | }); |
| 3067 | 3066 | unreachable; |
| ... | ... | @@ -3608,7 +3607,7 @@ fn zirMakePtrConst(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro |
| 3608 | 3607 | // If this is already a comptime-known allocation, we don't want to emit an error - the stores |
| 3609 | 3608 | // were already performed at comptime! Just make the pointer constant as normal. |
| 3610 | 3609 | implicit_ct: { |
| 3611 | | const ptr_val = try sema.resolveMaybeUndefVal(alloc) orelse break :implicit_ct; |
| 3610 | const ptr_val = try sema.resolveValue(alloc) orelse break :implicit_ct; |
| 3612 | 3611 | if (!ptr_val.isComptimeMutablePtr(mod)) { |
| 3613 | 3612 | // It could still be a constant pointer to a decl. |
| 3614 | 3613 | switch (mod.intern_pool.indexToKey(ptr_val.toIntern()).ptr.addr) { |
| ... | ... | @@ -3750,7 +3749,7 @@ fn resolveComptimeKnownAllocValue(sema: *Sema, block: *Block, alloc: Air.Inst.Re |
| 3750 | 3749 | Air.Bin, |
| 3751 | 3750 | tmp_air.instructions.items(.data)[air_ptr].ty_pl.payload, |
| 3752 | 3751 | ).data; |
| 3753 | | const idx_val = (try sema.resolveMaybeUndefVal(data.rhs)).?; |
| 3752 | const idx_val = (try sema.resolveValue(data.rhs)).?; |
| 3754 | 3753 | break :blk .{ |
| 3755 | 3754 | data.lhs, |
| 3756 | 3755 | .{ .elem = idx_val.toUnsignedInt(mod) }, |
| ... | ... | @@ -3809,7 +3808,7 @@ fn resolveComptimeKnownAllocValue(sema: *Sema, block: *Block, alloc: Air.Inst.Re |
| 3809 | 3808 | // store instruction, so we must set the union payload now. |
| 3810 | 3809 | const bin_op = sema.air_instructions.items(.data)[store_inst].bin_op; |
| 3811 | 3810 | const air_ptr_inst = Air.refToIndex(bin_op.lhs).?; |
| 3812 | | const tag_val = (try sema.resolveMaybeUndefVal(bin_op.rhs)).?; |
| 3811 | const tag_val = (try sema.resolveValue(bin_op.rhs)).?; |
| 3813 | 3812 | const union_ty = sema.typeOf(bin_op.lhs).childType(mod); |
| 3814 | 3813 | const payload_ty = union_ty.unionFieldType(tag_val, mod).?; |
| 3815 | 3814 | if (try sema.typeHasOnePossibleValue(payload_ty)) |payload_val| { |
| ... | ... | @@ -3821,7 +3820,7 @@ fn resolveComptimeKnownAllocValue(sema: *Sema, block: *Block, alloc: Air.Inst.Re |
| 3821 | 3820 | .store, .store_safe => { |
| 3822 | 3821 | const bin_op = sema.air_instructions.items(.data)[store_inst].bin_op; |
| 3823 | 3822 | const air_ptr_inst = Air.refToIndex(bin_op.lhs).?; |
| 3824 | | const store_val = (try sema.resolveMaybeUndefVal(bin_op.rhs)).?; |
| 3823 | const store_val = (try sema.resolveValue(bin_op.rhs)).?; |
| 3825 | 3824 | const new_ptr = ptr_mapping.get(air_ptr_inst).?; |
| 3826 | 3825 | try sema.storePtrVal(block, .unneeded, new_ptr.toValue(), store_val, mod.intern_pool.typeOf(store_val.toIntern()).toType()); |
| 3827 | 3826 | }, |
| ... | ... | @@ -3872,7 +3871,7 @@ fn makePtrConst(sema: *Sema, block: *Block, alloc: Air.Inst.Ref) CompileError!Ai |
| 3872 | 3871 | const const_ptr_ty = try sema.makePtrTyConst(alloc_ty); |
| 3873 | 3872 | |
| 3874 | 3873 | // Detect if a comptime value simply needs to have its type changed. |
| 3875 | | if (try sema.resolveMaybeUndefVal(alloc)) |val| { |
| 3874 | if (try sema.resolveValue(alloc)) |val| { |
| 3876 | 3875 | return Air.internedToRef((try sema.mod.getCoerced(val, const_ptr_ty)).toIntern()); |
| 3877 | 3876 | } |
| 3878 | 3877 | |
| ... | ... | @@ -4596,7 +4595,7 @@ fn validateUnionInit( |
| 4596 | 4595 | ).? |
| 4597 | 4596 | else |
| 4598 | 4597 | block_index, first_block_index); |
| 4599 | | init_val = try sema.resolveMaybeUndefVal(bin_op.rhs); |
| 4598 | init_val = try sema.resolveValue(bin_op.rhs); |
| 4600 | 4599 | break; |
| 4601 | 4600 | } |
| 4602 | 4601 | |
| ... | ... | @@ -4830,7 +4829,7 @@ fn validateStructInit( |
| 4830 | 4829 | ).? |
| 4831 | 4830 | else |
| 4832 | 4831 | block_index, first_block_index); |
| 4833 | | if (try sema.resolveMaybeUndefVal(bin_op.rhs)) |val| { |
| 4832 | if (try sema.resolveValue(bin_op.rhs)) |val| { |
| 4834 | 4833 | field_values[i] = val.toIntern(); |
| 4835 | 4834 | } else if (require_comptime) { |
| 4836 | 4835 | const field_ptr_data = sema.code.instructions.items(.data)[field_ptr].pl_node; |
| ... | ... | @@ -5086,7 +5085,7 @@ fn zirValidatePtrArrayInit( |
| 5086 | 5085 | ).? |
| 5087 | 5086 | else |
| 5088 | 5087 | block_index, first_block_index); |
| 5089 | | if (try sema.resolveMaybeUndefVal(bin_op.rhs)) |val| { |
| 5088 | if (try sema.resolveValue(bin_op.rhs)) |val| { |
| 5090 | 5089 | element_vals[i] = val.toIntern(); |
| 5091 | 5090 | } else { |
| 5092 | 5091 | array_is_comptime = false; |
| ... | ... | @@ -5168,7 +5167,7 @@ fn zirValidateDeref(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr |
| 5168 | 5167 | } |
| 5169 | 5168 | |
| 5170 | 5169 | const elem_ty = operand_ty.elemType2(mod); |
| 5171 | | if (try sema.resolveMaybeUndefVal(operand)) |val| { |
| 5170 | if (try sema.resolveValue(operand)) |val| { |
| 5172 | 5171 | if (val.isUndef(mod)) { |
| 5173 | 5172 | return sema.fail(block, src, "cannot dereference undefined value", .{}); |
| 5174 | 5173 | } |
| ... | ... | @@ -5375,7 +5374,7 @@ fn storeToInferredAllocComptime( |
| 5375 | 5374 | const operand_ty = sema.typeOf(operand); |
| 5376 | 5375 | // There will be only one store_to_inferred_ptr because we are running at comptime. |
| 5377 | 5376 | // The alloc will turn into a Decl. |
| 5378 | | if (try sema.resolveMaybeUndefVal(operand)) |operand_val| { |
| 5377 | if (try sema.resolveValue(operand)) |operand_val| { |
| 5379 | 5378 | var anon_decl = try block.startAnonDecl(); // TODO: comptime value mutation without Decl |
| 5380 | 5379 | defer anon_decl.deinit(); |
| 5381 | 5380 | iac.decl_index = try anon_decl.finish(operand_ty, operand_val, iac.alignment); |
| ... | ... | @@ -5565,7 +5564,7 @@ fn zirCompileLog( |
| 5565 | 5564 | |
| 5566 | 5565 | const arg = try sema.resolveInst(arg_ref); |
| 5567 | 5566 | const arg_ty = sema.typeOf(arg); |
| 5568 | | if (try sema.resolveMaybeUndefLazyVal(arg)) |val| { |
| 5567 | if (try sema.resolveValueResolveLazy(arg)) |val| { |
| 5569 | 5568 | try writer.print("@as({}, {})", .{ |
| 5570 | 5569 | arg_ty.fmt(mod), val.fmtValue(arg_ty, mod), |
| 5571 | 5570 | }); |
| ... | ... | @@ -6479,7 +6478,7 @@ fn lookupInNamespace( |
| 6479 | 6478 | |
| 6480 | 6479 | fn funcDeclSrc(sema: *Sema, func_inst: Air.Inst.Ref) !?*Decl { |
| 6481 | 6480 | const mod = sema.mod; |
| 6482 | | const func_val = (try sema.resolveMaybeUndefVal(func_inst)) orelse return null; |
| 6481 | const func_val = (try sema.resolveValue(func_inst)) orelse return null; |
| 6483 | 6482 | if (func_val.isUndef(mod)) return null; |
| 6484 | 6483 | const owner_decl_index = switch (mod.intern_pool.indexToKey(func_val.toIntern())) { |
| 6485 | 6484 | .extern_func => |extern_func| extern_func.decl, |
| ... | ... | @@ -7225,7 +7224,7 @@ fn analyzeCall( |
| 7225 | 7224 | } |
| 7226 | 7225 | |
| 7227 | 7226 | const result: Air.Inst.Ref = if (is_inline_call) res: { |
| 7228 | | const func_val = try sema.resolveConstValue(block, func_src, func, .{ |
| 7227 | const func_val = try sema.resolveConstDefinedValue(block, func_src, func, .{ |
| 7229 | 7228 | .needed_comptime_reason = "function being called at comptime must be comptime-known", |
| 7230 | 7229 | .block_comptime_reason = comptime_reason, |
| 7231 | 7230 | }); |
| ... | ... | @@ -7475,7 +7474,7 @@ fn analyzeCall( |
| 7475 | 7474 | } |
| 7476 | 7475 | |
| 7477 | 7476 | if (should_memoize and is_comptime_call) { |
| 7478 | | const result_val = try sema.resolveConstMaybeUndefVal(block, .unneeded, result, undefined); |
| 7477 | const result_val = try sema.resolveConstValue(block, .unneeded, result, undefined); |
| 7479 | 7478 | const result_interned = try result_val.intern2(sema.fn_ret_ty, mod); |
| 7480 | 7479 | |
| 7481 | 7480 | // Transform ad-hoc inferred error set types into concrete error sets. |
| ... | ... | @@ -7492,7 +7491,7 @@ fn analyzeCall( |
| 7492 | 7491 | break :res2 Air.internedToRef(result_transformed); |
| 7493 | 7492 | } |
| 7494 | 7493 | |
| 7495 | | if (try sema.resolveMaybeUndefVal(result)) |result_val| { |
| 7494 | if (try sema.resolveValue(result)) |result_val| { |
| 7496 | 7495 | const result_interned = try result_val.intern2(sema.fn_ret_ty, mod); |
| 7497 | 7496 | const result_transformed = try sema.resolveAdHocInferredErrorSet(block, call_src, result_interned); |
| 7498 | 7497 | break :res2 Air.internedToRef(result_transformed); |
| ... | ... | @@ -7532,7 +7531,7 @@ fn analyzeCall( |
| 7532 | 7531 | ip.funcAnalysis(sema.owner_func_index).calls_or_awaits_errorable_fn = true; |
| 7533 | 7532 | } |
| 7534 | 7533 | |
| 7535 | | if (try sema.resolveMaybeUndefVal(func)) |func_val| { |
| 7534 | if (try sema.resolveValue(func)) |func_val| { |
| 7536 | 7535 | if (mod.intern_pool.isFuncBody(func_val.toIntern())) { |
| 7537 | 7536 | try mod.ensureFuncBodyAnalysisQueued(func_val.toIntern()); |
| 7538 | 7537 | } |
| ... | ... | @@ -7560,7 +7559,7 @@ fn analyzeCall( |
| 7560 | 7559 | if (block.wantSafety() and func_ty_info.return_type == .noreturn_type) skip_safety: { |
| 7561 | 7560 | // Function pointers and extern functions aren't guaranteed to |
| 7562 | 7561 | // actually be noreturn so we add a safety check for them. |
| 7563 | | if (try sema.resolveMaybeUndefVal(func)) |func_val| { |
| 7562 | if (try sema.resolveValue(func)) |func_val| { |
| 7564 | 7563 | switch (mod.intern_pool.indexToKey(func_val.toIntern())) { |
| 7565 | 7564 | .func => break :skip_safety, |
| 7566 | 7565 | .ptr => |ptr| switch (ptr.addr) { |
| ... | ... | @@ -7649,19 +7648,19 @@ fn analyzeInlineCallArg( |
| 7649 | 7648 | } |
| 7650 | 7649 | const arg_src = args_info.argSrc(arg_block, arg_i.*); |
| 7651 | 7650 | if (try ics.callee().typeRequiresComptime(param_ty.toType())) { |
| 7652 | | _ = try ics.caller().resolveConstMaybeUndefVal(arg_block, arg_src, casted_arg, .{ |
| 7651 | _ = try ics.caller().resolveConstValue(arg_block, arg_src, casted_arg, .{ |
| 7653 | 7652 | .needed_comptime_reason = "argument to parameter with comptime-only type must be comptime-known", |
| 7654 | 7653 | .block_comptime_reason = param_block.comptime_reason, |
| 7655 | 7654 | }); |
| 7656 | 7655 | } else if (!is_comptime_call and zir_tags[inst] == .param_comptime) { |
| 7657 | | _ = try ics.caller().resolveConstMaybeUndefVal(arg_block, arg_src, casted_arg, .{ |
| 7656 | _ = try ics.caller().resolveConstValue(arg_block, arg_src, casted_arg, .{ |
| 7658 | 7657 | .needed_comptime_reason = "parameter is comptime", |
| 7659 | 7658 | }); |
| 7660 | 7659 | } |
| 7661 | 7660 | |
| 7662 | 7661 | if (is_comptime_call) { |
| 7663 | 7662 | ics.callee().inst_map.putAssumeCapacityNoClobber(inst, casted_arg); |
| 7664 | | const arg_val = try ics.caller().resolveConstMaybeUndefVal(arg_block, arg_src, casted_arg, .{ |
| 7663 | const arg_val = try ics.caller().resolveConstValue(arg_block, arg_src, casted_arg, .{ |
| 7665 | 7664 | .needed_comptime_reason = "argument to function being called at comptime must be comptime-known", |
| 7666 | 7665 | .block_comptime_reason = param_block.comptime_reason, |
| 7667 | 7666 | }); |
| ... | ... | @@ -7683,7 +7682,7 @@ fn analyzeInlineCallArg( |
| 7683 | 7682 | ics.callee().inst_map.putAssumeCapacityNoClobber(inst, casted_arg); |
| 7684 | 7683 | } |
| 7685 | 7684 | |
| 7686 | | if (try ics.caller().resolveMaybeUndefVal(casted_arg)) |_| { |
| 7685 | if (try ics.caller().resolveValue(casted_arg)) |_| { |
| 7687 | 7686 | param_block.inlining.?.has_comptime_args = true; |
| 7688 | 7687 | } |
| 7689 | 7688 | |
| ... | ... | @@ -7700,7 +7699,7 @@ fn analyzeInlineCallArg( |
| 7700 | 7699 | |
| 7701 | 7700 | if (is_comptime_call) { |
| 7702 | 7701 | ics.callee().inst_map.putAssumeCapacityNoClobber(inst, uncasted_arg); |
| 7703 | | const arg_val = try ics.caller().resolveConstMaybeUndefVal(arg_block, arg_src, uncasted_arg, .{ |
| 7702 | const arg_val = try ics.caller().resolveConstValue(arg_block, arg_src, uncasted_arg, .{ |
| 7704 | 7703 | .needed_comptime_reason = "argument to function being called at comptime must be comptime-known", |
| 7705 | 7704 | .block_comptime_reason = param_block.comptime_reason, |
| 7706 | 7705 | }); |
| ... | ... | @@ -7720,14 +7719,14 @@ fn analyzeInlineCallArg( |
| 7720 | 7719 | memoized_arg_values[arg_i.*] = try resolved_arg_val.intern(ics.caller().typeOf(uncasted_arg), mod); |
| 7721 | 7720 | } else { |
| 7722 | 7721 | if (zir_tags[inst] == .param_anytype_comptime) { |
| 7723 | | _ = try ics.caller().resolveConstMaybeUndefVal(arg_block, arg_src, uncasted_arg, .{ |
| 7722 | _ = try ics.caller().resolveConstValue(arg_block, arg_src, uncasted_arg, .{ |
| 7724 | 7723 | .needed_comptime_reason = "parameter is comptime", |
| 7725 | 7724 | }); |
| 7726 | 7725 | } |
| 7727 | 7726 | ics.callee().inst_map.putAssumeCapacityNoClobber(inst, uncasted_arg); |
| 7728 | 7727 | } |
| 7729 | 7728 | |
| 7730 | | if (try ics.caller().resolveMaybeUndefVal(uncasted_arg)) |_| { |
| 7729 | if (try ics.caller().resolveValue(uncasted_arg)) |_| { |
| 7731 | 7730 | param_block.inlining.?.has_comptime_args = true; |
| 7732 | 7731 | } |
| 7733 | 7732 | |
| ... | ... | @@ -7769,7 +7768,7 @@ fn instantiateGenericCall( |
| 7769 | 7768 | const gpa = sema.gpa; |
| 7770 | 7769 | const ip = &mod.intern_pool; |
| 7771 | 7770 | |
| 7772 | | const func_val = try sema.resolveConstValue(block, func_src, func, .{ |
| 7771 | const func_val = try sema.resolveConstDefinedValue(block, func_src, func, .{ |
| 7773 | 7772 | .needed_comptime_reason = "generic function being called must be comptime-known", |
| 7774 | 7773 | }); |
| 7775 | 7774 | const generic_owner = switch (mod.intern_pool.indexToKey(func_val.toIntern())) { |
| ... | ... | @@ -7906,7 +7905,7 @@ fn instantiateGenericCall( |
| 7906 | 7905 | }; |
| 7907 | 7906 | |
| 7908 | 7907 | if (arg_is_comptime) { |
| 7909 | | if (try sema.resolveMaybeUndefVal(arg_ref)) |arg_val| { |
| 7908 | if (try sema.resolveValue(arg_ref)) |arg_val| { |
| 7910 | 7909 | comptime_args[arg_index] = arg_val.toIntern(); |
| 7911 | 7910 | child_sema.inst_map.putAssumeCapacityNoClobber( |
| 7912 | 7911 | param_inst, |
| ... | ... | @@ -7978,7 +7977,7 @@ fn instantiateGenericCall( |
| 7978 | 7977 | // We've already handled parameters, so don't resolve the whole body. Instead, just |
| 7979 | 7978 | // do the instructions after the params (i.e. the func itself). |
| 7980 | 7979 | const new_func_inst = try child_sema.resolveBody(&child_block, fn_info.param_body[args_info.count()..], fn_info.param_body_inst); |
| 7981 | | const callee_index = (child_sema.resolveConstValue(&child_block, .unneeded, new_func_inst, undefined) catch unreachable).toIntern(); |
| 7980 | const callee_index = (child_sema.resolveConstDefinedValue(&child_block, .unneeded, new_func_inst, undefined) catch unreachable).toIntern(); |
| 7982 | 7981 | |
| 7983 | 7982 | const callee = mod.funcInfo(callee_index); |
| 7984 | 7983 | callee.branchQuota(ip).* = @max(callee.branchQuota(ip).*, sema.branch_quota); |
| ... | ... | @@ -8229,7 +8228,7 @@ fn zirArrayTypeSentinel(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compil |
| 8229 | 8228 | try sema.validateArrayElemType(block, elem_type, elem_src); |
| 8230 | 8229 | const uncasted_sentinel = try sema.resolveInst(extra.sentinel); |
| 8231 | 8230 | const sentinel = try sema.coerce(block, elem_type, uncasted_sentinel, sentinel_src); |
| 8232 | | const sentinel_val = try sema.resolveConstValue(block, sentinel_src, sentinel, .{ |
| 8231 | const sentinel_val = try sema.resolveConstDefinedValue(block, sentinel_src, sentinel, .{ |
| 8233 | 8232 | .needed_comptime_reason = "array sentinel value must be comptime-known", |
| 8234 | 8233 | }); |
| 8235 | 8234 | const array_ty = try sema.mod.arrayType(.{ |
| ... | ... | @@ -8328,7 +8327,7 @@ fn zirIntFromError(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstD |
| 8328 | 8327 | const operand = try sema.coerce(block, Type.anyerror, uncasted_operand, operand_src); |
| 8329 | 8328 | const err_int_ty = try mod.errorIntType(); |
| 8330 | 8329 | |
| 8331 | | if (try sema.resolveMaybeUndefVal(operand)) |val| { |
| 8330 | if (try sema.resolveValue(operand)) |val| { |
| 8332 | 8331 | if (val.isUndef(mod)) { |
| 8333 | 8332 | return mod.undefRef(err_int_ty); |
| 8334 | 8333 | } |
| ... | ... | @@ -8501,7 +8500,7 @@ fn zirIntFromEnum(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 8501 | 8500 | return Air.internedToRef((try mod.getCoerced(opv, int_tag_ty)).toIntern()); |
| 8502 | 8501 | } |
| 8503 | 8502 | |
| 8504 | | if (try sema.resolveMaybeUndefVal(enum_tag)) |enum_tag_val| { |
| 8503 | if (try sema.resolveValue(enum_tag)) |enum_tag_val| { |
| 8505 | 8504 | const val = try enum_tag_val.intFromEnum(enum_tag_ty, mod); |
| 8506 | 8505 | return Air.internedToRef(val.toIntern()); |
| 8507 | 8506 | } |
| ... | ... | @@ -8524,7 +8523,7 @@ fn zirEnumFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 8524 | 8523 | } |
| 8525 | 8524 | _ = try sema.checkIntType(block, operand_src, sema.typeOf(operand)); |
| 8526 | 8525 | |
| 8527 | | if (try sema.resolveMaybeUndefVal(operand)) |int_val| { |
| 8526 | if (try sema.resolveValue(operand)) |int_val| { |
| 8528 | 8527 | if (dest_ty.isNonexhaustiveEnum(mod)) { |
| 8529 | 8528 | const int_tag_ty = dest_ty.intTagType(mod); |
| 8530 | 8529 | if (try sema.intFitsInType(int_val, int_tag_ty, null)) { |
| ... | ... | @@ -9032,7 +9031,7 @@ fn resolveGenericBody( |
| 9032 | 9031 | |
| 9033 | 9032 | const uncasted = sema.resolveBody(block, body, func_inst) catch |err| break :err err; |
| 9034 | 9033 | const result = sema.coerce(block, dest_ty, uncasted, src) catch |err| break :err err; |
| 9035 | | const val = sema.resolveConstValue(block, src, result, reason) catch |err| break :err err; |
| 9034 | const val = sema.resolveConstDefinedValue(block, src, result, reason) catch |err| break :err err; |
| 9036 | 9035 | return val; |
| 9037 | 9036 | }; |
| 9038 | 9037 | switch (err) { |
| ... | ... | @@ -9846,7 +9845,7 @@ fn zirIntFromPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! |
| 9846 | 9845 | }; |
| 9847 | 9846 | return sema.failWithOwnedErrorMsg(block, msg); |
| 9848 | 9847 | } |
| 9849 | | if (try sema.resolveMaybeUndefValIntable(operand)) |operand_val| ct: { |
| 9848 | if (try sema.resolveValueIntable(operand)) |operand_val| ct: { |
| 9850 | 9849 | if (!is_vector) { |
| 9851 | 9850 | return Air.internedToRef((try mod.intValue( |
| 9852 | 9851 | Type.usize, |
| ... | ... | @@ -10312,7 +10311,7 @@ fn zirFloatCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 10312 | 10311 | ), |
| 10313 | 10312 | } |
| 10314 | 10313 | |
| 10315 | | if (try sema.resolveMaybeUndefVal(operand)) |operand_val| { |
| 10314 | if (try sema.resolveValue(operand)) |operand_val| { |
| 10316 | 10315 | if (!is_vector) { |
| 10317 | 10316 | return Air.internedToRef((try operand_val.floatCast(dest_ty, mod)).toIntern()); |
| 10318 | 10317 | } |
| ... | ... | @@ -10710,7 +10709,7 @@ const SwitchProngAnalysis = struct { |
| 10710 | 10709 | const operand_src: LazySrcLoc = .{ .node_offset_switch_operand = switch_node_offset }; |
| 10711 | 10710 | |
| 10712 | 10711 | if (inline_case_capture != .none) { |
| 10713 | | const item_val = sema.resolveConstValue(block, .unneeded, inline_case_capture, undefined) catch unreachable; |
| 10712 | const item_val = sema.resolveConstDefinedValue(block, .unneeded, inline_case_capture, undefined) catch unreachable; |
| 10714 | 10713 | if (operand_ty.zigTypeTag(mod) == .Union) { |
| 10715 | 10714 | const field_index: u32 = @intCast(operand_ty.unionTagFieldIndex(item_val, mod).?); |
| 10716 | 10715 | const union_obj = mod.typeToUnion(operand_ty).?; |
| ... | ... | @@ -10767,14 +10766,14 @@ const SwitchProngAnalysis = struct { |
| 10767 | 10766 | switch (operand_ty.zigTypeTag(mod)) { |
| 10768 | 10767 | .Union => { |
| 10769 | 10768 | const union_obj = mod.typeToUnion(operand_ty).?; |
| 10770 | | const first_item_val = sema.resolveConstValue(block, .unneeded, case_vals[0], undefined) catch unreachable; |
| 10769 | const first_item_val = sema.resolveConstDefinedValue(block, .unneeded, case_vals[0], undefined) catch unreachable; |
| 10771 | 10770 | |
| 10772 | 10771 | const first_field_index: u32 = mod.unionTagFieldIndex(union_obj, first_item_val).?; |
| 10773 | 10772 | const first_field_ty = union_obj.field_types.get(ip)[first_field_index].toType(); |
| 10774 | 10773 | |
| 10775 | 10774 | const field_tys = try sema.arena.alloc(Type, case_vals.len); |
| 10776 | 10775 | for (case_vals, field_tys) |item, *field_ty| { |
| 10777 | | const item_val = sema.resolveConstValue(block, .unneeded, item, undefined) catch unreachable; |
| 10776 | const item_val = sema.resolveConstDefinedValue(block, .unneeded, item, undefined) catch unreachable; |
| 10778 | 10777 | const field_idx = mod.unionTagFieldIndex(union_obj, item_val).?; |
| 10779 | 10778 | field_ty.* = union_obj.field_types.get(ip)[field_idx].toType(); |
| 10780 | 10779 | } |
| ... | ... | @@ -11023,7 +11022,7 @@ const SwitchProngAnalysis = struct { |
| 11023 | 11022 | } |
| 11024 | 11023 | |
| 11025 | 11024 | if (case_vals.len == 1) { |
| 11026 | | const item_val = sema.resolveConstValue(block, .unneeded, case_vals[0], undefined) catch unreachable; |
| 11025 | const item_val = sema.resolveConstDefinedValue(block, .unneeded, case_vals[0], undefined) catch unreachable; |
| 11027 | 11026 | const item_ty = try mod.singleErrorSetType(item_val.getErrorName(mod).unwrap().?); |
| 11028 | 11027 | return sema.bitCast(block, item_ty, spa.operand, operand_src, null); |
| 11029 | 11028 | } |
| ... | ... | @@ -11031,7 +11030,7 @@ const SwitchProngAnalysis = struct { |
| 11031 | 11030 | var names: InferredErrorSet.NameMap = .{}; |
| 11032 | 11031 | try names.ensureUnusedCapacity(sema.arena, case_vals.len); |
| 11033 | 11032 | for (case_vals) |err| { |
| 11034 | | const err_val = sema.resolveConstValue(block, .unneeded, err, undefined) catch unreachable; |
| 11033 | const err_val = sema.resolveConstDefinedValue(block, .unneeded, err, undefined) catch unreachable; |
| 11035 | 11034 | names.putAssumeCapacityNoClobber(err_val.getErrorName(mod).unwrap().?, {}); |
| 11036 | 11035 | } |
| 11037 | 11036 | const error_ty = try mod.errorSetFromUnsortedNames(names.keys()); |
| ... | ... | @@ -11805,7 +11804,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 11805 | 11804 | extra_index += info.body_len; |
| 11806 | 11805 | |
| 11807 | 11806 | const item = case_vals.items[scalar_i]; |
| 11808 | | const item_val = sema.resolveConstValue(&child_block, .unneeded, item, undefined) catch unreachable; |
| 11807 | const item_val = sema.resolveConstDefinedValue(&child_block, .unneeded, item, undefined) catch unreachable; |
| 11809 | 11808 | if (operand_val.eql(item_val, operand_ty, sema.mod)) { |
| 11810 | 11809 | if (err_set) try sema.maybeErrorUnwrapComptime(&child_block, body, operand); |
| 11811 | 11810 | return spa.resolveProngComptime( |
| ... | ... | @@ -11839,7 +11838,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 11839 | 11838 | |
| 11840 | 11839 | for (items) |item| { |
| 11841 | 11840 | // Validation above ensured these will succeed. |
| 11842 | | const item_val = sema.resolveConstValue(&child_block, .unneeded, item, undefined) catch unreachable; |
| 11841 | const item_val = sema.resolveConstDefinedValue(&child_block, .unneeded, item, undefined) catch unreachable; |
| 11843 | 11842 | if (operand_val.eql(item_val, operand_ty, sema.mod)) { |
| 11844 | 11843 | if (err_set) try sema.maybeErrorUnwrapComptime(&child_block, body, operand); |
| 11845 | 11844 | return spa.resolveProngComptime( |
| ... | ... | @@ -11863,8 +11862,8 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 11863 | 11862 | case_val_idx += 2; |
| 11864 | 11863 | |
| 11865 | 11864 | // Validation above ensured these will succeed. |
| 11866 | | const first_val = sema.resolveConstValue(&child_block, .unneeded, range_items[0], undefined) catch unreachable; |
| 11867 | | const last_val = sema.resolveConstValue(&child_block, .unneeded, range_items[1], undefined) catch unreachable; |
| 11865 | const first_val = sema.resolveConstDefinedValue(&child_block, .unneeded, range_items[0], undefined) catch unreachable; |
| 11866 | const last_val = sema.resolveConstDefinedValue(&child_block, .unneeded, range_items[1], undefined) catch unreachable; |
| 11868 | 11867 | if ((try sema.compareAll(resolved_operand_val, .gte, first_val, operand_ty)) and |
| 11869 | 11868 | (try sema.compareAll(resolved_operand_val, .lte, last_val, operand_ty))) |
| 11870 | 11869 | { |
| ... | ... | @@ -11936,7 +11935,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 11936 | 11935 | } |
| 11937 | 11936 | |
| 11938 | 11937 | if (child_block.is_comptime) { |
| 11939 | | _ = try sema.resolveConstValue(&child_block, operand_src, operand, .{ |
| 11938 | _ = try sema.resolveConstDefinedValue(&child_block, operand_src, operand, .{ |
| 11940 | 11939 | .needed_comptime_reason = "condition in comptime switch must be comptime-known", |
| 11941 | 11940 | .block_comptime_reason = child_block.comptime_reason, |
| 11942 | 11941 | }); |
| ... | ... | @@ -11971,7 +11970,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 11971 | 11970 | // `item` is already guaranteed to be constant known. |
| 11972 | 11971 | |
| 11973 | 11972 | const analyze_body = if (union_originally) blk: { |
| 11974 | | const unresolved_item_val = sema.resolveConstValue(block, .unneeded, item, undefined) catch unreachable; |
| 11973 | const unresolved_item_val = sema.resolveConstDefinedValue(block, .unneeded, item, undefined) catch unreachable; |
| 11975 | 11974 | const item_val = sema.resolveLazyValue(unresolved_item_val) catch unreachable; |
| 11976 | 11975 | const field_ty = maybe_union_ty.unionFieldType(item_val, mod).?; |
| 11977 | 11976 | break :blk field_ty.zigTypeTag(mod) != .NoReturn; |
| ... | ... | @@ -12040,8 +12039,8 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 12040 | 12039 | const item_first_ref = range_items[0]; |
| 12041 | 12040 | const item_last_ref = range_items[1]; |
| 12042 | 12041 | |
| 12043 | | var item = sema.resolveConstValue(block, .unneeded, item_first_ref, undefined) catch unreachable; |
| 12044 | | const item_last = sema.resolveConstValue(block, .unneeded, item_last_ref, undefined) catch unreachable; |
| 12042 | var item = sema.resolveConstDefinedValue(block, .unneeded, item_first_ref, undefined) catch unreachable; |
| 12043 | const item_last = sema.resolveConstDefinedValue(block, .unneeded, item_last_ref, undefined) catch unreachable; |
| 12045 | 12044 | |
| 12046 | 12045 | while (item.compareScalar(.lte, item_last, operand_ty, mod)) : ({ |
| 12047 | 12046 | // Previous validation has resolved any possible lazy values. |
| ... | ... | @@ -12098,7 +12097,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 12098 | 12097 | case_block.wip_capture_scope = child_block.wip_capture_scope; |
| 12099 | 12098 | |
| 12100 | 12099 | const analyze_body = if (union_originally) blk: { |
| 12101 | | const item_val = sema.resolveConstValue(block, .unneeded, item, undefined) catch unreachable; |
| 12100 | const item_val = sema.resolveConstDefinedValue(block, .unneeded, item, undefined) catch unreachable; |
| 12102 | 12101 | const field_ty = maybe_union_ty.unionFieldType(item_val, mod).?; |
| 12103 | 12102 | break :blk field_ty.zigTypeTag(mod) != .NoReturn; |
| 12104 | 12103 | } else true; |
| ... | ... | @@ -12152,7 +12151,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 12152 | 12151 | |
| 12153 | 12152 | const analyze_body = if (union_originally) |
| 12154 | 12153 | for (items) |item| { |
| 12155 | | const item_val = sema.resolveConstValue(block, .unneeded, item, undefined) catch unreachable; |
| 12154 | const item_val = sema.resolveConstDefinedValue(block, .unneeded, item, undefined) catch unreachable; |
| 12156 | 12155 | const field_ty = maybe_union_ty.unionFieldType(item_val, mod).?; |
| 12157 | 12156 | if (field_ty.zigTypeTag(mod) != .NoReturn) break true; |
| 12158 | 12157 | } else false |
| ... | ... | @@ -12642,10 +12641,10 @@ fn resolveSwitchItemVal( |
| 12642 | 12641 | else => |e| return e, |
| 12643 | 12642 | }; |
| 12644 | 12643 | |
| 12645 | | const maybe_lazy = sema.resolveConstValue(block, .unneeded, item, undefined) catch |err| switch (err) { |
| 12644 | const maybe_lazy = sema.resolveConstDefinedValue(block, .unneeded, item, undefined) catch |err| switch (err) { |
| 12646 | 12645 | error.NeededSourceLocation => { |
| 12647 | 12646 | const src = switch_prong_src.resolve(mod, mod.declPtr(block.src_decl), switch_node_offset, range_expand); |
| 12648 | | _ = try sema.resolveConstValue(block, src, item, .{ |
| 12647 | _ = try sema.resolveConstDefinedValue(block, src, item, .{ |
| 12649 | 12648 | .needed_comptime_reason = "switch prong values must be comptime-known", |
| 12650 | 12649 | }); |
| 12651 | 12650 | unreachable; |
| ... | ... | @@ -13133,8 +13132,8 @@ fn zirShl( |
| 13133 | 13132 | // TODO coerce rhs if air_tag is not shl_sat |
| 13134 | 13133 | const rhs_is_comptime_int = try sema.checkIntType(block, rhs_src, scalar_rhs_ty); |
| 13135 | 13134 | |
| 13136 | | const maybe_lhs_val = try sema.resolveMaybeUndefValIntable(lhs); |
| 13137 | | const maybe_rhs_val = try sema.resolveMaybeUndefValIntable(rhs); |
| 13135 | const maybe_lhs_val = try sema.resolveValueIntable(lhs); |
| 13136 | const maybe_rhs_val = try sema.resolveValueIntable(rhs); |
| 13138 | 13137 | |
| 13139 | 13138 | if (maybe_rhs_val) |rhs_val| { |
| 13140 | 13139 | if (rhs_val.isUndef(mod)) { |
| ... | ... | @@ -13311,8 +13310,8 @@ fn zirShr( |
| 13311 | 13310 | try sema.checkVectorizableBinaryOperands(block, src, lhs_ty, rhs_ty, lhs_src, rhs_src); |
| 13312 | 13311 | const scalar_ty = lhs_ty.scalarType(mod); |
| 13313 | 13312 | |
| 13314 | | const maybe_lhs_val = try sema.resolveMaybeUndefValIntable(lhs); |
| 13315 | | const maybe_rhs_val = try sema.resolveMaybeUndefValIntable(rhs); |
| 13313 | const maybe_lhs_val = try sema.resolveValueIntable(lhs); |
| 13314 | const maybe_rhs_val = try sema.resolveValueIntable(rhs); |
| 13316 | 13315 | |
| 13317 | 13316 | const runtime_src = if (maybe_rhs_val) |rhs_val| rs: { |
| 13318 | 13317 | if (rhs_val.isUndef(mod)) { |
| ... | ... | @@ -13463,8 +13462,8 @@ fn zirBitwise( |
| 13463 | 13462 | const runtime_src = runtime: { |
| 13464 | 13463 | // TODO: ask the linker what kind of relocations are available, and |
| 13465 | 13464 | // in some cases emit a Value that means "this decl's address AND'd with this operand". |
| 13466 | | if (try sema.resolveMaybeUndefValIntable(casted_lhs)) |lhs_val| { |
| 13467 | | if (try sema.resolveMaybeUndefValIntable(casted_rhs)) |rhs_val| { |
| 13465 | if (try sema.resolveValueIntable(casted_lhs)) |lhs_val| { |
| 13466 | if (try sema.resolveValueIntable(casted_rhs)) |rhs_val| { |
| 13468 | 13467 | const result_val = switch (air_tag) { |
| 13469 | 13468 | .bit_and => try lhs_val.bitwiseAnd(rhs_val, resolved_type, sema.arena, mod), |
| 13470 | 13469 | .bit_or => try lhs_val.bitwiseOr(rhs_val, resolved_type, sema.arena, mod), |
| ... | ... | @@ -13503,7 +13502,7 @@ fn zirBitNot(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. |
| 13503 | 13502 | }); |
| 13504 | 13503 | } |
| 13505 | 13504 | |
| 13506 | | if (try sema.resolveMaybeUndefVal(operand)) |val| { |
| 13505 | if (try sema.resolveValue(operand)) |val| { |
| 13507 | 13506 | if (val.isUndef(mod)) { |
| 13508 | 13507 | return mod.undefRef(operand_type); |
| 13509 | 13508 | } else if (operand_type.zigTypeTag(mod) == .Vector) { |
| ... | ... | @@ -13673,10 +13672,10 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 13673 | 13672 | const rhs_sent = Air.internedToRef(rhs_sent_val.toIntern()); |
| 13674 | 13673 | const lhs_sent_casted = try sema.coerce(block, resolved_elem_ty, lhs_sent, lhs_src); |
| 13675 | 13674 | const rhs_sent_casted = try sema.coerce(block, resolved_elem_ty, rhs_sent, rhs_src); |
| 13676 | | const lhs_sent_casted_val = try sema.resolveConstValue(block, lhs_src, lhs_sent_casted, .{ |
| 13675 | const lhs_sent_casted_val = try sema.resolveConstDefinedValue(block, lhs_src, lhs_sent_casted, .{ |
| 13677 | 13676 | .needed_comptime_reason = "array sentinel value must be comptime-known", |
| 13678 | 13677 | }); |
| 13679 | | const rhs_sent_casted_val = try sema.resolveConstValue(block, rhs_src, rhs_sent_casted, .{ |
| 13678 | const rhs_sent_casted_val = try sema.resolveConstDefinedValue(block, rhs_src, rhs_sent_casted, .{ |
| 13680 | 13679 | .needed_comptime_reason = "array sentinel value must be comptime-known", |
| 13681 | 13680 | }); |
| 13682 | 13681 | if (try sema.valuesEqual(lhs_sent_casted_val, rhs_sent_casted_val, resolved_elem_ty)) { |
| ... | ... | @@ -13686,7 +13685,7 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 13686 | 13685 | } |
| 13687 | 13686 | } else { |
| 13688 | 13687 | const lhs_sent_casted = try sema.coerce(block, resolved_elem_ty, lhs_sent, lhs_src); |
| 13689 | | const lhs_sent_casted_val = try sema.resolveConstValue(block, lhs_src, lhs_sent_casted, .{ |
| 13688 | const lhs_sent_casted_val = try sema.resolveConstDefinedValue(block, lhs_src, lhs_sent_casted, .{ |
| 13690 | 13689 | .needed_comptime_reason = "array sentinel value must be comptime-known", |
| 13691 | 13690 | }); |
| 13692 | 13691 | break :s lhs_sent_casted_val; |
| ... | ... | @@ -13695,7 +13694,7 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 13695 | 13694 | if (rhs_info.sentinel) |rhs_sent_val| { |
| 13696 | 13695 | const rhs_sent = Air.internedToRef(rhs_sent_val.toIntern()); |
| 13697 | 13696 | const rhs_sent_casted = try sema.coerce(block, resolved_elem_ty, rhs_sent, rhs_src); |
| 13698 | | const rhs_sent_casted_val = try sema.resolveConstValue(block, rhs_src, rhs_sent_casted, .{ |
| 13697 | const rhs_sent_casted_val = try sema.resolveConstDefinedValue(block, rhs_src, rhs_sent_casted, .{ |
| 13699 | 13698 | .needed_comptime_reason = "array sentinel value must be comptime-known", |
| 13700 | 13699 | }); |
| 13701 | 13700 | break :s rhs_sent_casted_val; |
| ... | ... | @@ -13728,12 +13727,12 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 13728 | 13727 | }; |
| 13729 | 13728 | |
| 13730 | 13729 | const runtime_src = if (switch (lhs_ty.zigTypeTag(mod)) { |
| 13731 | | .Array, .Struct => try sema.resolveMaybeUndefVal(lhs), |
| 13730 | .Array, .Struct => try sema.resolveValue(lhs), |
| 13732 | 13731 | .Pointer => try sema.resolveDefinedValue(block, lhs_src, lhs), |
| 13733 | 13732 | else => unreachable, |
| 13734 | 13733 | }) |lhs_val| rs: { |
| 13735 | 13734 | if (switch (rhs_ty.zigTypeTag(mod)) { |
| 13736 | | .Array, .Struct => try sema.resolveMaybeUndefVal(rhs), |
| 13735 | .Array, .Struct => try sema.resolveValue(rhs), |
| 13737 | 13736 | .Pointer => try sema.resolveDefinedValue(block, rhs_src, rhs), |
| 13738 | 13737 | else => unreachable, |
| 13739 | 13738 | }) |rhs_val| { |
| ... | ... | @@ -13755,7 +13754,7 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 13755 | 13754 | const elem_val = if (elem_default_val.toIntern() == .unreachable_value) try lhs_sub_val.elemValue(mod, lhs_elem_i) else elem_default_val; |
| 13756 | 13755 | const elem_val_inst = Air.internedToRef(elem_val.toIntern()); |
| 13757 | 13756 | const coerced_elem_val_inst = try sema.coerce(block, resolved_elem_ty, elem_val_inst, .unneeded); |
| 13758 | | const coerced_elem_val = try sema.resolveConstMaybeUndefVal(block, .unneeded, coerced_elem_val_inst, undefined); |
| 13757 | const coerced_elem_val = try sema.resolveConstValue(block, .unneeded, coerced_elem_val_inst, undefined); |
| 13759 | 13758 | element_vals[elem_i] = try coerced_elem_val.intern(resolved_elem_ty, mod); |
| 13760 | 13759 | } |
| 13761 | 13760 | while (elem_i < result_len) : (elem_i += 1) { |
| ... | ... | @@ -13764,7 +13763,7 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 13764 | 13763 | const elem_val = if (elem_default_val.toIntern() == .unreachable_value) try rhs_sub_val.elemValue(mod, rhs_elem_i) else elem_default_val; |
| 13765 | 13764 | const elem_val_inst = Air.internedToRef(elem_val.toIntern()); |
| 13766 | 13765 | const coerced_elem_val_inst = try sema.coerce(block, resolved_elem_ty, elem_val_inst, .unneeded); |
| 13767 | | const coerced_elem_val = try sema.resolveConstMaybeUndefVal(block, .unneeded, coerced_elem_val_inst, undefined); |
| 13766 | const coerced_elem_val = try sema.resolveConstValue(block, .unneeded, coerced_elem_val_inst, undefined); |
| 13768 | 13767 | element_vals[elem_i] = try coerced_elem_val.intern(resolved_elem_ty, mod); |
| 13769 | 13768 | } |
| 13770 | 13769 | return sema.addConstantMaybeRef(block, result_ty, (try mod.intern(.{ .aggregate = .{ |
| ... | ... | @@ -13841,7 +13840,7 @@ fn getArrayCatInfo(sema: *Sema, block: *Block, src: LazySrcLoc, operand: Air.Ins |
| 13841 | 13840 | // has a sentinel, and this code should compute the length based |
| 13842 | 13841 | // on the sentinel value. |
| 13843 | 13842 | .Slice, .Many => { |
| 13844 | | const val = try sema.resolveConstValue(block, src, operand, .{ |
| 13843 | const val = try sema.resolveConstDefinedValue(block, src, operand, .{ |
| 13845 | 13844 | .needed_comptime_reason = "slice value being concatenated must be comptime-known", |
| 13846 | 13845 | }); |
| 13847 | 13846 | return Type.ArrayInfo{ |
| ... | ... | @@ -14109,7 +14108,7 @@ fn zirNegate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. |
| 14109 | 14108 | |
| 14110 | 14109 | if (rhs_scalar_ty.isAnyFloat()) { |
| 14111 | 14110 | // We handle float negation here to ensure negative zero is represented in the bits. |
| 14112 | | if (try sema.resolveMaybeUndefVal(rhs)) |rhs_val| { |
| 14111 | if (try sema.resolveValue(rhs)) |rhs_val| { |
| 14113 | 14112 | if (rhs_val.isUndef(mod)) return mod.undefRef(rhs_ty); |
| 14114 | 14113 | return Air.internedToRef((try rhs_val.floatNeg(rhs_ty, sema.arena, mod)).toIntern()); |
| 14115 | 14114 | } |
| ... | ... | @@ -14195,8 +14194,8 @@ fn zirDiv(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins |
| 14195 | 14194 | |
| 14196 | 14195 | try sema.checkArithmeticOp(block, src, scalar_tag, lhs_zig_ty_tag, rhs_zig_ty_tag, .div); |
| 14197 | 14196 | |
| 14198 | | const maybe_lhs_val = try sema.resolveMaybeUndefValIntable(casted_lhs); |
| 14199 | | const maybe_rhs_val = try sema.resolveMaybeUndefValIntable(casted_rhs); |
| 14197 | const maybe_lhs_val = try sema.resolveValueIntable(casted_lhs); |
| 14198 | const maybe_rhs_val = try sema.resolveValueIntable(casted_rhs); |
| 14200 | 14199 | |
| 14201 | 14200 | if ((lhs_ty.zigTypeTag(mod) == .ComptimeFloat and rhs_ty.zigTypeTag(mod) == .ComptimeInt) or |
| 14202 | 14201 | (lhs_ty.zigTypeTag(mod) == .ComptimeInt and rhs_ty.zigTypeTag(mod) == .ComptimeFloat)) |
| ... | ... | @@ -14360,8 +14359,8 @@ fn zirDivExact(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 14360 | 14359 | |
| 14361 | 14360 | try sema.checkArithmeticOp(block, src, scalar_tag, lhs_zig_ty_tag, rhs_zig_ty_tag, .div_exact); |
| 14362 | 14361 | |
| 14363 | | const maybe_lhs_val = try sema.resolveMaybeUndefValIntable(casted_lhs); |
| 14364 | | const maybe_rhs_val = try sema.resolveMaybeUndefValIntable(casted_rhs); |
| 14362 | const maybe_lhs_val = try sema.resolveValueIntable(casted_lhs); |
| 14363 | const maybe_rhs_val = try sema.resolveValueIntable(casted_rhs); |
| 14365 | 14364 | |
| 14366 | 14365 | const runtime_src = rs: { |
| 14367 | 14366 | // For integers: |
| ... | ... | @@ -14527,8 +14526,8 @@ fn zirDivFloor(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 14527 | 14526 | |
| 14528 | 14527 | try sema.checkArithmeticOp(block, src, scalar_tag, lhs_zig_ty_tag, rhs_zig_ty_tag, .div_floor); |
| 14529 | 14528 | |
| 14530 | | const maybe_lhs_val = try sema.resolveMaybeUndefValIntable(casted_lhs); |
| 14531 | | const maybe_rhs_val = try sema.resolveMaybeUndefValIntable(casted_rhs); |
| 14529 | const maybe_lhs_val = try sema.resolveValueIntable(casted_lhs); |
| 14530 | const maybe_rhs_val = try sema.resolveValueIntable(casted_rhs); |
| 14532 | 14531 | |
| 14533 | 14532 | const runtime_src = rs: { |
| 14534 | 14533 | // For integers: |
| ... | ... | @@ -14638,8 +14637,8 @@ fn zirDivTrunc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 14638 | 14637 | |
| 14639 | 14638 | try sema.checkArithmeticOp(block, src, scalar_tag, lhs_zig_ty_tag, rhs_zig_ty_tag, .div_trunc); |
| 14640 | 14639 | |
| 14641 | | const maybe_lhs_val = try sema.resolveMaybeUndefValIntable(casted_lhs); |
| 14642 | | const maybe_rhs_val = try sema.resolveMaybeUndefValIntable(casted_rhs); |
| 14640 | const maybe_lhs_val = try sema.resolveValueIntable(casted_lhs); |
| 14641 | const maybe_rhs_val = try sema.resolveValueIntable(casted_rhs); |
| 14643 | 14642 | |
| 14644 | 14643 | const runtime_src = rs: { |
| 14645 | 14644 | // For integers: |
| ... | ... | @@ -14882,8 +14881,8 @@ fn zirModRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. |
| 14882 | 14881 | |
| 14883 | 14882 | try sema.checkArithmeticOp(block, src, scalar_tag, lhs_zig_ty_tag, rhs_zig_ty_tag, .mod_rem); |
| 14884 | 14883 | |
| 14885 | | const maybe_lhs_val = try sema.resolveMaybeUndefValIntable(casted_lhs); |
| 14886 | | const maybe_rhs_val = try sema.resolveMaybeUndefValIntable(casted_rhs); |
| 14884 | const maybe_lhs_val = try sema.resolveValueIntable(casted_lhs); |
| 14885 | const maybe_rhs_val = try sema.resolveValueIntable(casted_rhs); |
| 14887 | 14886 | |
| 14888 | 14887 | const runtime_src = rs: { |
| 14889 | 14888 | // For integers: |
| ... | ... | @@ -15063,8 +15062,8 @@ fn zirMod(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins |
| 15063 | 15062 | |
| 15064 | 15063 | try sema.checkArithmeticOp(block, src, scalar_tag, lhs_zig_ty_tag, rhs_zig_ty_tag, .mod); |
| 15065 | 15064 | |
| 15066 | | const maybe_lhs_val = try sema.resolveMaybeUndefValIntable(casted_lhs); |
| 15067 | | const maybe_rhs_val = try sema.resolveMaybeUndefValIntable(casted_rhs); |
| 15065 | const maybe_lhs_val = try sema.resolveValueIntable(casted_lhs); |
| 15066 | const maybe_rhs_val = try sema.resolveValueIntable(casted_rhs); |
| 15068 | 15067 | |
| 15069 | 15068 | const runtime_src = rs: { |
| 15070 | 15069 | // For integers: |
| ... | ... | @@ -15159,8 +15158,8 @@ fn zirRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins |
| 15159 | 15158 | |
| 15160 | 15159 | try sema.checkArithmeticOp(block, src, scalar_tag, lhs_zig_ty_tag, rhs_zig_ty_tag, .rem); |
| 15161 | 15160 | |
| 15162 | | const maybe_lhs_val = try sema.resolveMaybeUndefValIntable(casted_lhs); |
| 15163 | | const maybe_rhs_val = try sema.resolveMaybeUndefValIntable(casted_rhs); |
| 15161 | const maybe_lhs_val = try sema.resolveValueIntable(casted_lhs); |
| 15162 | const maybe_rhs_val = try sema.resolveValueIntable(casted_rhs); |
| 15164 | 15163 | |
| 15165 | 15164 | const runtime_src = rs: { |
| 15166 | 15165 | // For integers: |
| ... | ... | @@ -15269,8 +15268,8 @@ fn zirOverflowArithmetic( |
| 15269 | 15268 | return sema.fail(block, src, "expected vector of integers or integer tag type, found '{}'", .{dest_ty.fmt(mod)}); |
| 15270 | 15269 | } |
| 15271 | 15270 | |
| 15272 | | const maybe_lhs_val = try sema.resolveMaybeUndefVal(lhs); |
| 15273 | | const maybe_rhs_val = try sema.resolveMaybeUndefVal(rhs); |
| 15271 | const maybe_lhs_val = try sema.resolveValue(lhs); |
| 15272 | const maybe_rhs_val = try sema.resolveValue(rhs); |
| 15274 | 15273 | |
| 15275 | 15274 | const tuple_ty = try sema.overflowArithmeticTupleType(dest_ty); |
| 15276 | 15275 | const overflow_ty = ip.indexToKey(tuple_ty.toIntern()).anon_struct_type.types.get(ip)[1].toType(); |
| ... | ... | @@ -15413,7 +15412,7 @@ fn zirOverflowArithmetic( |
| 15413 | 15412 | }; |
| 15414 | 15413 | |
| 15415 | 15414 | if (result.inst != .none) { |
| 15416 | | if (try sema.resolveMaybeUndefVal(result.inst)) |some| { |
| 15415 | if (try sema.resolveValue(result.inst)) |some| { |
| 15417 | 15416 | result.wrapped = some; |
| 15418 | 15417 | result.inst = .none; |
| 15419 | 15418 | } |
| ... | ... | @@ -15509,8 +15508,8 @@ fn analyzeArithmetic( |
| 15509 | 15508 | |
| 15510 | 15509 | try sema.checkArithmeticOp(block, src, scalar_tag, lhs_zig_ty_tag, rhs_zig_ty_tag, zir_tag); |
| 15511 | 15510 | |
| 15512 | | const maybe_lhs_val = try sema.resolveMaybeUndefValIntable(casted_lhs); |
| 15513 | | const maybe_rhs_val = try sema.resolveMaybeUndefValIntable(casted_rhs); |
| 15511 | const maybe_lhs_val = try sema.resolveValueIntable(casted_lhs); |
| 15512 | const maybe_rhs_val = try sema.resolveValueIntable(casted_rhs); |
| 15514 | 15513 | const runtime_src: LazySrcLoc, const air_tag: Air.Inst.Tag, const air_tag_safe: Air.Inst.Tag = rs: { |
| 15515 | 15514 | switch (zir_tag) { |
| 15516 | 15515 | .add, .add_unsafe => { |
| ... | ... | @@ -15959,7 +15958,7 @@ fn analyzePtrArithmetic( |
| 15959 | 15958 | // coerce to isize instead of usize. |
| 15960 | 15959 | const offset = try sema.coerce(block, Type.usize, uncasted_offset, offset_src); |
| 15961 | 15960 | const mod = sema.mod; |
| 15962 | | const opt_ptr_val = try sema.resolveMaybeUndefVal(ptr); |
| 15961 | const opt_ptr_val = try sema.resolveValue(ptr); |
| 15963 | 15962 | const opt_off_val = try sema.resolveDefinedValue(block, offset_src, offset); |
| 15964 | 15963 | const ptr_ty = sema.typeOf(ptr); |
| 15965 | 15964 | const ptr_info = ptr_ty.ptrInfo(mod); |
| ... | ... | @@ -16265,8 +16264,8 @@ fn zirCmpEq( |
| 16265 | 16264 | |
| 16266 | 16265 | if (lhs_ty_tag == .ErrorSet and rhs_ty_tag == .ErrorSet) { |
| 16267 | 16266 | const runtime_src: LazySrcLoc = src: { |
| 16268 | | if (try sema.resolveMaybeUndefVal(lhs)) |lval| { |
| 16269 | | if (try sema.resolveMaybeUndefVal(rhs)) |rval| { |
| 16267 | if (try sema.resolveValue(lhs)) |lval| { |
| 16268 | if (try sema.resolveValue(rhs)) |rval| { |
| 16270 | 16269 | if (lval.isUndef(mod) or rval.isUndef(mod)) { |
| 16271 | 16270 | return mod.undefRef(Type.bool); |
| 16272 | 16271 | } |
| ... | ... | @@ -16321,7 +16320,7 @@ fn analyzeCmpUnionTag( |
| 16321 | 16320 | const coerced_tag = try sema.coerce(block, union_tag_ty, tag, tag_src); |
| 16322 | 16321 | const coerced_union = try sema.coerce(block, union_tag_ty, un, un_src); |
| 16323 | 16322 | |
| 16324 | | if (try sema.resolveMaybeUndefVal(coerced_tag)) |enum_val| { |
| 16323 | if (try sema.resolveValue(coerced_tag)) |enum_val| { |
| 16325 | 16324 | if (enum_val.isUndef(mod)) return mod.undefRef(Type.bool); |
| 16326 | 16325 | const field_ty = union_ty.unionFieldType(enum_val, mod).?; |
| 16327 | 16326 | if (field_ty.zigTypeTag(mod) == .NoReturn) { |
| ... | ... | @@ -16423,9 +16422,9 @@ fn cmpSelf( |
| 16423 | 16422 | const mod = sema.mod; |
| 16424 | 16423 | const resolved_type = sema.typeOf(casted_lhs); |
| 16425 | 16424 | const runtime_src: LazySrcLoc = src: { |
| 16426 | | if (try sema.resolveMaybeUndefVal(casted_lhs)) |lhs_val| { |
| 16425 | if (try sema.resolveValue(casted_lhs)) |lhs_val| { |
| 16427 | 16426 | if (lhs_val.isUndef(mod)) return mod.undefRef(Type.bool); |
| 16428 | | if (try sema.resolveMaybeUndefVal(casted_rhs)) |rhs_val| { |
| 16427 | if (try sema.resolveValue(casted_rhs)) |rhs_val| { |
| 16429 | 16428 | if (rhs_val.isUndef(mod)) return mod.undefRef(Type.bool); |
| 16430 | 16429 | |
| 16431 | 16430 | if (resolved_type.zigTypeTag(mod) == .Vector) { |
| ... | ... | @@ -16448,7 +16447,7 @@ fn cmpSelf( |
| 16448 | 16447 | // For bools, we still check the other operand, because we can lower |
| 16449 | 16448 | // bool eq/neq more efficiently. |
| 16450 | 16449 | if (resolved_type.zigTypeTag(mod) == .Bool) { |
| 16451 | | if (try sema.resolveMaybeUndefVal(casted_rhs)) |rhs_val| { |
| 16450 | if (try sema.resolveValue(casted_rhs)) |rhs_val| { |
| 16452 | 16451 | if (rhs_val.isUndef(mod)) return mod.undefRef(Type.bool); |
| 16453 | 16452 | return sema.runtimeBoolCmp(block, src, op, casted_lhs, rhs_val.toBool(), lhs_src); |
| 16454 | 16453 | } |
| ... | ... | @@ -16594,7 +16593,7 @@ fn zirClosureCapture(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr |
| 16594 | 16593 | .zir_index = inst, |
| 16595 | 16594 | .index = block.wip_capture_scope, |
| 16596 | 16595 | }; |
| 16597 | | if (try sema.resolveMaybeUndefVal(operand)) |val| { |
| 16596 | if (try sema.resolveValue(operand)) |val| { |
| 16598 | 16597 | try mod.comptime_capture_scopes.put(gpa, key, try val.intern(ty, mod)); |
| 16599 | 16598 | } else { |
| 16600 | 16599 | try mod.runtime_capture_scopes.put(gpa, key, ty.toIntern()); |
| ... | ... | @@ -18079,7 +18078,7 @@ fn zirBoolNot(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 18079 | 18078 | const uncasted_operand = try sema.resolveInst(inst_data.operand); |
| 18080 | 18079 | |
| 18081 | 18080 | const operand = try sema.coerce(block, Type.bool, uncasted_operand, operand_src); |
| 18082 | | if (try sema.resolveMaybeUndefVal(operand)) |val| { |
| 18081 | if (try sema.resolveValue(operand)) |val| { |
| 18083 | 18082 | return if (val.isUndef(mod)) |
| 18084 | 18083 | mod.undefRef(Type.bool) |
| 18085 | 18084 | else if (val.toBool()) .bool_false else .bool_true; |
| ... | ... | @@ -18238,7 +18237,7 @@ fn zirIsNonNullPtr( |
| 18238 | 18237 | const src = inst_data.src(); |
| 18239 | 18238 | const ptr = try sema.resolveInst(inst_data.operand); |
| 18240 | 18239 | try sema.checkNullableType(block, src, sema.typeOf(ptr).elemType2(mod)); |
| 18241 | | if ((try sema.resolveMaybeUndefVal(ptr)) == null) { |
| 18240 | if ((try sema.resolveValue(ptr)) == null) { |
| 18242 | 18241 | return block.addUnOp(.is_non_null_ptr, ptr); |
| 18243 | 18242 | } |
| 18244 | 18243 | const loaded = try sema.analyzeLoad(block, src, ptr, src); |
| ... | ... | @@ -18833,7 +18832,7 @@ fn analyzeRet( |
| 18833 | 18832 | |
| 18834 | 18833 | if (block.inlining) |inlining| { |
| 18835 | 18834 | if (block.is_comptime) { |
| 18836 | | _ = try sema.resolveConstMaybeUndefVal(block, src, operand, .{ |
| 18835 | _ = try sema.resolveConstValue(block, src, operand, .{ |
| 18837 | 18836 | .needed_comptime_reason = "value being returned at comptime must be comptime-known", |
| 18838 | 18837 | }); |
| 18839 | 18838 | inlining.comptime_result = operand; |
| ... | ... | @@ -18915,7 +18914,7 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 18915 | 18914 | const ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_i]); |
| 18916 | 18915 | extra_i += 1; |
| 18917 | 18916 | const coerced = try sema.coerce(block, elem_ty, try sema.resolveInst(ref), sentinel_src); |
| 18918 | | const val = try sema.resolveConstValue(block, sentinel_src, coerced, .{ |
| 18917 | const val = try sema.resolveConstDefinedValue(block, sentinel_src, coerced, .{ |
| 18919 | 18918 | .needed_comptime_reason = "pointer sentinel value must be comptime-known", |
| 18920 | 18919 | }); |
| 18921 | 18920 | break :blk val.toIntern(); |
| ... | ... | @@ -18925,7 +18924,7 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 18925 | 18924 | const ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_i]); |
| 18926 | 18925 | extra_i += 1; |
| 18927 | 18926 | const coerced = try sema.coerce(block, Type.u32, try sema.resolveInst(ref), align_src); |
| 18928 | | const val = try sema.resolveConstValue(block, align_src, coerced, .{ |
| 18927 | const val = try sema.resolveConstDefinedValue(block, align_src, coerced, .{ |
| 18929 | 18928 | .needed_comptime_reason = "pointer alignment must be comptime-known", |
| 18930 | 18929 | }); |
| 18931 | 18930 | // Check if this happens to be the lazy alignment of our element type, in |
| ... | ... | @@ -19073,7 +19072,7 @@ fn zirStructInitEmptyResult(sema: *Sema, block: *Block, inst: Zir.Inst.Index, is |
| 19073 | 19072 | const init_ref = try sema.coerce(block, init_ty, empty_ref, src); |
| 19074 | 19073 | |
| 19075 | 19074 | if (is_byref) { |
| 19076 | | const init_val = (try sema.resolveMaybeUndefVal(init_ref)).?; |
| 19075 | const init_val = (try sema.resolveValue(init_ref)).?; |
| 19077 | 19076 | var anon_decl = try block.startAnonDecl(); |
| 19078 | 19077 | defer anon_decl.deinit(); |
| 19079 | 19078 | const decl = try anon_decl.finish(init_ty, init_val, .none); |
| ... | ... | @@ -19158,7 +19157,7 @@ fn unionInit( |
| 19158 | 19157 | const field_ty = mod.typeToUnion(union_ty).?.field_types.get(ip)[field_index].toType(); |
| 19159 | 19158 | const init = try sema.coerce(block, field_ty, uncasted_init, init_src); |
| 19160 | 19159 | |
| 19161 | | if (try sema.resolveMaybeUndefVal(init)) |init_val| { |
| 19160 | if (try sema.resolveValue(init)) |init_val| { |
| 19162 | 19161 | const tag_ty = union_ty.unionTagTypeHypothetical(mod); |
| 19163 | 19162 | const tag_val = try mod.enumValueFieldIndex(tag_ty, field_index); |
| 19164 | 19163 | return Air.internedToRef((try mod.intern(.{ .un = .{ |
| ... | ... | @@ -19247,7 +19246,7 @@ fn zirStructInit( |
| 19247 | 19246 | const field_ty = resolved_ty.structFieldType(field_index, mod); |
| 19248 | 19247 | field_inits[field_index] = try sema.coerce(block, field_ty, uncoerced_init, field_src); |
| 19249 | 19248 | if (!is_packed) if (try resolved_ty.structFieldValueComptime(mod, field_index)) |default_value| { |
| 19250 | | const init_val = (try sema.resolveMaybeUndefVal(field_inits[field_index])) orelse { |
| 19249 | const init_val = (try sema.resolveValue(field_inits[field_index])) orelse { |
| 19251 | 19250 | return sema.failWithNeededComptime(block, field_src, .{ |
| 19252 | 19251 | .needed_comptime_reason = "value stored in comptime field must be comptime-known", |
| 19253 | 19252 | }); |
| ... | ... | @@ -19292,14 +19291,14 @@ fn zirStructInit( |
| 19292 | 19291 | const uncoerced_init_inst = try sema.resolveInst(item.data.init); |
| 19293 | 19292 | const init_inst = try sema.coerce(block, field_ty, uncoerced_init_inst, field_src); |
| 19294 | 19293 | |
| 19295 | | if (try sema.resolveMaybeUndefVal(init_inst)) |val| { |
| 19294 | if (try sema.resolveValue(init_inst)) |val| { |
| 19296 | 19295 | const struct_val = (try mod.intern(.{ .un = .{ |
| 19297 | 19296 | .ty = resolved_ty.toIntern(), |
| 19298 | 19297 | .tag = try tag_val.intern(tag_ty, mod), |
| 19299 | 19298 | .val = try val.intern(field_ty, mod), |
| 19300 | 19299 | } })).toValue(); |
| 19301 | 19300 | const final_val_inst = try sema.coerce(block, result_ty, Air.internedToRef(struct_val.toIntern()), src); |
| 19302 | | const final_val = (try sema.resolveMaybeUndefVal(final_val_inst)).?; |
| 19301 | const final_val = (try sema.resolveValue(final_val_inst)).?; |
| 19303 | 19302 | return sema.addConstantMaybeRef(block, resolved_ty, final_val, is_ref); |
| 19304 | 19303 | } |
| 19305 | 19304 | |
| ... | ... | @@ -19452,14 +19451,14 @@ fn finishStructInit( |
| 19452 | 19451 | const runtime_index = opt_runtime_index orelse { |
| 19453 | 19452 | const elems = try sema.arena.alloc(InternPool.Index, field_inits.len); |
| 19454 | 19453 | for (elems, field_inits) |*elem, field_init| { |
| 19455 | | elem.* = (sema.resolveMaybeUndefVal(field_init) catch unreachable).?.toIntern(); |
| 19454 | elem.* = (sema.resolveValue(field_init) catch unreachable).?.toIntern(); |
| 19456 | 19455 | } |
| 19457 | 19456 | const struct_val = try mod.intern(.{ .aggregate = .{ |
| 19458 | 19457 | .ty = struct_ty.toIntern(), |
| 19459 | 19458 | .storage = .{ .elems = elems }, |
| 19460 | 19459 | } }); |
| 19461 | 19460 | const final_val_inst = try sema.coerce(block, result_ty, Air.internedToRef(struct_val), init_src); |
| 19462 | | const final_val = (try sema.resolveMaybeUndefVal(final_val_inst)).?; |
| 19461 | const final_val = (try sema.resolveValue(final_val_inst)).?; |
| 19463 | 19462 | return sema.addConstantMaybeRef(block, result_ty, final_val, is_ref); |
| 19464 | 19463 | }; |
| 19465 | 19464 | |
| ... | ... | @@ -19592,7 +19591,7 @@ fn structInitAnon( |
| 19592 | 19591 | }; |
| 19593 | 19592 | return sema.failWithOwnedErrorMsg(block, msg); |
| 19594 | 19593 | } |
| 19595 | | if (try sema.resolveMaybeUndefVal(init)) |init_val| { |
| 19594 | if (try sema.resolveValue(init)) |init_val| { |
| 19596 | 19595 | values[i] = try init_val.intern(field_ty.toType(), mod); |
| 19597 | 19596 | } else { |
| 19598 | 19597 | values[i] = .none; |
| ... | ... | @@ -19738,7 +19737,7 @@ fn zirArrayInit( |
| 19738 | 19737 | else => return err, |
| 19739 | 19738 | }; |
| 19740 | 19739 | if (is_tuple) if (try array_ty.structFieldValueComptime(mod, i)) |field_val| { |
| 19741 | | const init_val = try sema.resolveMaybeUndefVal(dest.*) orelse { |
| 19740 | const init_val = try sema.resolveValue(dest.*) orelse { |
| 19742 | 19741 | const decl = mod.declPtr(block.src_decl); |
| 19743 | 19742 | const elem_src = mod.initSrc(src.node_offset.x, decl, i); |
| 19744 | 19743 | return sema.failWithNeededComptime(block, elem_src, .{ |
| ... | ... | @@ -19772,14 +19771,14 @@ fn zirArrayInit( |
| 19772 | 19771 | else |
| 19773 | 19772 | array_ty.elemType2(mod); |
| 19774 | 19773 | // We checked that all args are comptime above. |
| 19775 | | val.* = try ((sema.resolveMaybeUndefVal(arg) catch unreachable).?).intern(elem_ty, mod); |
| 19774 | val.* = try ((sema.resolveValue(arg) catch unreachable).?).intern(elem_ty, mod); |
| 19776 | 19775 | } |
| 19777 | 19776 | const arr_val = try mod.intern(.{ .aggregate = .{ |
| 19778 | 19777 | .ty = array_ty.toIntern(), |
| 19779 | 19778 | .storage = .{ .elems = elem_vals }, |
| 19780 | 19779 | } }); |
| 19781 | 19780 | const result_ref = try sema.coerce(block, result_ty, Air.internedToRef(arr_val), src); |
| 19782 | | return sema.addConstantMaybeRef(block, result_ty, (try sema.resolveMaybeUndefVal(result_ref)).?, is_ref); |
| 19781 | return sema.addConstantMaybeRef(block, result_ty, (try sema.resolveValue(result_ref)).?, is_ref); |
| 19783 | 19782 | }; |
| 19784 | 19783 | |
| 19785 | 19784 | sema.requireRuntimeBlock(block, .unneeded, null) catch |err| switch (err) { |
| ... | ... | @@ -19877,7 +19876,7 @@ fn arrayInitAnon( |
| 19877 | 19876 | }; |
| 19878 | 19877 | return sema.failWithOwnedErrorMsg(block, msg); |
| 19879 | 19878 | } |
| 19880 | | if (try sema.resolveMaybeUndefVal(elem)) |val| { |
| 19879 | if (try sema.resolveValue(elem)) |val| { |
| 19881 | 19880 | values[i] = val.toIntern(); |
| 19882 | 19881 | } else { |
| 19883 | 19882 | values[i] = .none; |
| ... | ... | @@ -20100,7 +20099,7 @@ fn zirIntFromBool(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 20100 | 20099 | if (operand_scalar_ty.toIntern() != .bool_type) { |
| 20101 | 20100 | return sema.fail(block, src, "expected 'bool', found '{}'", .{operand_scalar_ty.zigTypeTag(mod)}); |
| 20102 | 20101 | } |
| 20103 | | if (try sema.resolveMaybeUndefVal(operand)) |val| { |
| 20102 | if (try sema.resolveValue(operand)) |val| { |
| 20104 | 20103 | if (!is_vector) { |
| 20105 | 20104 | if (val.isUndef(mod)) return mod.undefRef(Type.u1); |
| 20106 | 20105 | if (val.toBool()) return Air.internedToRef((try mod.intValue(Type.u1, 1)).toIntern()); |
| ... | ... | @@ -20191,7 +20190,7 @@ fn maybeConstantUnaryMath( |
| 20191 | 20190 | ) CompileError!?Air.Inst.Ref { |
| 20192 | 20191 | const mod = sema.mod; |
| 20193 | 20192 | switch (result_ty.zigTypeTag(mod)) { |
| 20194 | | .Vector => if (try sema.resolveMaybeUndefVal(operand)) |val| { |
| 20193 | .Vector => if (try sema.resolveValue(operand)) |val| { |
| 20195 | 20194 | const scalar_ty = result_ty.scalarType(mod); |
| 20196 | 20195 | const vec_len = result_ty.vectorLen(mod); |
| 20197 | 20196 | if (val.isUndef(mod)) |
| ... | ... | @@ -20207,7 +20206,7 @@ fn maybeConstantUnaryMath( |
| 20207 | 20206 | .storage = .{ .elems = elems }, |
| 20208 | 20207 | } }))); |
| 20209 | 20208 | }, |
| 20210 | | else => if (try sema.resolveMaybeUndefVal(operand)) |operand_val| { |
| 20209 | else => if (try sema.resolveValue(operand)) |operand_val| { |
| 20211 | 20210 | if (operand_val.isUndef(mod)) |
| 20212 | 20211 | return try mod.undefRef(result_ty); |
| 20213 | 20212 | const result_val = try eval(operand_val, result_ty, sema.arena, sema.mod); |
| ... | ... | @@ -20262,7 +20261,7 @@ fn zirTagName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 20262 | 20261 | try sema.resolveTypeLayout(operand_ty); |
| 20263 | 20262 | const enum_ty = switch (operand_ty.zigTypeTag(mod)) { |
| 20264 | 20263 | .EnumLiteral => { |
| 20265 | | const val = try sema.resolveConstValue(block, .unneeded, operand, undefined); |
| 20264 | const val = try sema.resolveConstDefinedValue(block, .unneeded, operand, undefined); |
| 20266 | 20265 | const tag_name = ip.indexToKey(val.toIntern()).enum_literal; |
| 20267 | 20266 | return sema.addStrLit(ip.stringToSlice(tag_name)); |
| 20268 | 20267 | }, |
| ... | ... | @@ -20335,7 +20334,7 @@ fn zirReify( |
| 20335 | 20334 | const uncasted_operand = try sema.resolveInst(extra.operand); |
| 20336 | 20335 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node }; |
| 20337 | 20336 | const type_info = try sema.coerce(block, type_info_ty, uncasted_operand, operand_src); |
| 20338 | | const val = try sema.resolveConstValue(block, operand_src, type_info, .{ |
| 20337 | const val = try sema.resolveConstDefinedValue(block, operand_src, type_info, .{ |
| 20339 | 20338 | .needed_comptime_reason = "operand to @Type must be comptime-known", |
| 20340 | 20339 | }); |
| 20341 | 20340 | const union_val = ip.indexToKey(val.toIntern()).un; |
| ... | ... | @@ -21486,7 +21485,7 @@ fn zirIntFromFloat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro |
| 21486 | 21485 | _ = try sema.checkIntType(block, src, dest_scalar_ty); |
| 21487 | 21486 | try sema.checkFloatType(block, operand_src, operand_scalar_ty); |
| 21488 | 21487 | |
| 21489 | | if (try sema.resolveMaybeUndefVal(operand)) |operand_val| { |
| 21488 | if (try sema.resolveValue(operand)) |operand_val| { |
| 21490 | 21489 | const result_val = try sema.intFromFloat(block, operand_src, operand_val, operand_ty, dest_ty, .truncate); |
| 21491 | 21490 | return Air.internedToRef(result_val.toIntern()); |
| 21492 | 21491 | } else if (dest_scalar_ty.zigTypeTag(mod) == .ComptimeInt) { |
| ... | ... | @@ -21568,7 +21567,7 @@ fn zirFloatFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro |
| 21568 | 21567 | try sema.checkFloatType(block, src, dest_scalar_ty); |
| 21569 | 21568 | _ = try sema.checkIntType(block, operand_src, operand_scalar_ty); |
| 21570 | 21569 | |
| 21571 | | if (try sema.resolveMaybeUndefVal(operand)) |operand_val| { |
| 21570 | if (try sema.resolveValue(operand)) |operand_val| { |
| 21572 | 21571 | const result_val = try operand_val.floatFromIntAdvanced(sema.arena, operand_ty, dest_ty, mod, sema); |
| 21573 | 21572 | return Air.internedToRef(result_val.toIntern()); |
| 21574 | 21573 | } else if (dest_scalar_ty.zigTypeTag(mod) == .ComptimeFloat) { |
| ... | ... | @@ -22158,7 +22157,7 @@ fn ptrCastFull( |
| 22158 | 22157 | |
| 22159 | 22158 | // Cannot do @addrSpaceCast at comptime |
| 22160 | 22159 | if (!flags.addrspace_cast) { |
| 22161 | | if (try sema.resolveMaybeUndefVal(ptr)) |ptr_val| { |
| 22160 | if (try sema.resolveValue(ptr)) |ptr_val| { |
| 22162 | 22161 | if (!dest_ty.ptrAllowsZero(mod) and ptr_val.isUndef(mod)) { |
| 22163 | 22162 | return sema.failWithUseOfUndef(block, operand_src); |
| 22164 | 22163 | } |
| ... | ... | @@ -22286,7 +22285,7 @@ fn zirPtrCastNoDest(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.Inst |
| 22286 | 22285 | if (flags.volatile_cast) ptr_info.flags.is_volatile = false; |
| 22287 | 22286 | const dest_ty = try sema.ptrType(ptr_info); |
| 22288 | 22287 | |
| 22289 | | if (try sema.resolveMaybeUndefVal(operand)) |operand_val| { |
| 22288 | if (try sema.resolveValue(operand)) |operand_val| { |
| 22290 | 22289 | return Air.internedToRef((try mod.getCoerced(operand_val, dest_ty)).toIntern()); |
| 22291 | 22290 | } |
| 22292 | 22291 | |
| ... | ... | @@ -22356,7 +22355,7 @@ fn zirTruncate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 22356 | 22355 | } |
| 22357 | 22356 | } |
| 22358 | 22357 | |
| 22359 | | if (try sema.resolveMaybeUndefValIntable(operand)) |val| { |
| 22358 | if (try sema.resolveValueIntable(operand)) |val| { |
| 22360 | 22359 | if (val.isUndef(mod)) return mod.undefRef(dest_ty); |
| 22361 | 22360 | if (!dest_is_vector) { |
| 22362 | 22361 | return Air.internedToRef((try mod.getCoerced( |
| ... | ... | @@ -22407,7 +22406,7 @@ fn zirBitCount( |
| 22407 | 22406 | .len = vec_len, |
| 22408 | 22407 | .child = result_scalar_ty.toIntern(), |
| 22409 | 22408 | }); |
| 22410 | | if (try sema.resolveMaybeUndefVal(operand)) |val| { |
| 22409 | if (try sema.resolveValue(operand)) |val| { |
| 22411 | 22410 | if (val.isUndef(mod)) return mod.undefRef(result_ty); |
| 22412 | 22411 | |
| 22413 | 22412 | const elems = try sema.arena.alloc(InternPool.Index, vec_len); |
| ... | ... | @@ -22427,7 +22426,7 @@ fn zirBitCount( |
| 22427 | 22426 | } |
| 22428 | 22427 | }, |
| 22429 | 22428 | .Int => { |
| 22430 | | if (try sema.resolveMaybeUndefLazyVal(operand)) |val| { |
| 22429 | if (try sema.resolveValueResolveLazy(operand)) |val| { |
| 22431 | 22430 | if (val.isUndef(mod)) return mod.undefRef(result_scalar_ty); |
| 22432 | 22431 | return mod.intRef(result_scalar_ty, comptimeOp(val, operand_ty, mod)); |
| 22433 | 22432 | } else { |
| ... | ... | @@ -22463,7 +22462,7 @@ fn zirByteSwap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 22463 | 22462 | |
| 22464 | 22463 | switch (operand_ty.zigTypeTag(mod)) { |
| 22465 | 22464 | .Int => { |
| 22466 | | const runtime_src = if (try sema.resolveMaybeUndefVal(operand)) |val| { |
| 22465 | const runtime_src = if (try sema.resolveValue(operand)) |val| { |
| 22467 | 22466 | if (val.isUndef(mod)) return mod.undefRef(operand_ty); |
| 22468 | 22467 | const result_val = try val.byteSwap(operand_ty, mod, sema.arena); |
| 22469 | 22468 | return Air.internedToRef(result_val.toIntern()); |
| ... | ... | @@ -22473,7 +22472,7 @@ fn zirByteSwap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 22473 | 22472 | return block.addTyOp(.byte_swap, operand_ty, operand); |
| 22474 | 22473 | }, |
| 22475 | 22474 | .Vector => { |
| 22476 | | const runtime_src = if (try sema.resolveMaybeUndefVal(operand)) |val| { |
| 22475 | const runtime_src = if (try sema.resolveValue(operand)) |val| { |
| 22477 | 22476 | if (val.isUndef(mod)) |
| 22478 | 22477 | return mod.undefRef(operand_ty); |
| 22479 | 22478 | |
| ... | ... | @@ -22511,7 +22510,7 @@ fn zirBitReverse(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! |
| 22511 | 22510 | const mod = sema.mod; |
| 22512 | 22511 | switch (operand_ty.zigTypeTag(mod)) { |
| 22513 | 22512 | .Int => { |
| 22514 | | const runtime_src = if (try sema.resolveMaybeUndefVal(operand)) |val| { |
| 22513 | const runtime_src = if (try sema.resolveValue(operand)) |val| { |
| 22515 | 22514 | if (val.isUndef(mod)) return mod.undefRef(operand_ty); |
| 22516 | 22515 | const result_val = try val.bitReverse(operand_ty, mod, sema.arena); |
| 22517 | 22516 | return Air.internedToRef(result_val.toIntern()); |
| ... | ... | @@ -22521,7 +22520,7 @@ fn zirBitReverse(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! |
| 22521 | 22520 | return block.addTyOp(.bit_reverse, operand_ty, operand); |
| 22522 | 22521 | }, |
| 22523 | 22522 | .Vector => { |
| 22524 | | const runtime_src = if (try sema.resolveMaybeUndefVal(operand)) |val| { |
| 22523 | const runtime_src = if (try sema.resolveValue(operand)) |val| { |
| 22525 | 22524 | if (val.isUndef(mod)) |
| 22526 | 22525 | return mod.undefRef(operand_ty); |
| 22527 | 22526 | |
| ... | ... | @@ -22967,8 +22966,8 @@ fn checkSimdBinOp( |
| 22967 | 22966 | .len = vec_len, |
| 22968 | 22967 | .lhs = lhs, |
| 22969 | 22968 | .rhs = rhs, |
| 22970 | | .lhs_val = try sema.resolveMaybeUndefVal(lhs), |
| 22971 | | .rhs_val = try sema.resolveMaybeUndefVal(rhs), |
| 22969 | .lhs_val = try sema.resolveValue(lhs), |
| 22970 | .rhs_val = try sema.resolveValue(rhs), |
| 22972 | 22971 | .result_ty = result_ty, |
| 22973 | 22972 | .scalar_ty = result_ty.scalarType(mod), |
| 22974 | 22973 | }; |
| ... | ... | @@ -23054,20 +23053,20 @@ fn resolveExportOptions( |
| 23054 | 23053 | const visibility_src = sema.maybeOptionsSrc(block, src, "visibility"); |
| 23055 | 23054 | |
| 23056 | 23055 | const name_operand = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "name"), name_src); |
| 23057 | | const name_val = try sema.resolveConstValue(block, name_src, name_operand, .{ |
| 23056 | const name_val = try sema.resolveConstDefinedValue(block, name_src, name_operand, .{ |
| 23058 | 23057 | .needed_comptime_reason = "name of exported value must be comptime-known", |
| 23059 | 23058 | }); |
| 23060 | 23059 | const name_ty = Type.slice_const_u8; |
| 23061 | 23060 | const name = try name_val.toAllocatedBytes(name_ty, sema.arena, mod); |
| 23062 | 23061 | |
| 23063 | 23062 | const linkage_operand = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "linkage"), linkage_src); |
| 23064 | | const linkage_val = try sema.resolveConstValue(block, linkage_src, linkage_operand, .{ |
| 23063 | const linkage_val = try sema.resolveConstDefinedValue(block, linkage_src, linkage_operand, .{ |
| 23065 | 23064 | .needed_comptime_reason = "linkage of exported value must be comptime-known", |
| 23066 | 23065 | }); |
| 23067 | 23066 | const linkage = mod.toEnum(std.builtin.GlobalLinkage, linkage_val); |
| 23068 | 23067 | |
| 23069 | 23068 | const section_operand = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "section"), section_src); |
| 23070 | | const section_opt_val = try sema.resolveConstValue(block, section_src, section_operand, .{ |
| 23069 | const section_opt_val = try sema.resolveConstDefinedValue(block, section_src, section_operand, .{ |
| 23071 | 23070 | .needed_comptime_reason = "linksection of exported value must be comptime-known", |
| 23072 | 23071 | }); |
| 23073 | 23072 | const section_ty = Type.slice_const_u8; |
| ... | ... | @@ -23077,7 +23076,7 @@ fn resolveExportOptions( |
| 23077 | 23076 | null; |
| 23078 | 23077 | |
| 23079 | 23078 | const visibility_operand = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "visibility"), visibility_src); |
| 23080 | | const visibility_val = try sema.resolveConstValue(block, visibility_src, visibility_operand, .{ |
| 23079 | const visibility_val = try sema.resolveConstDefinedValue(block, visibility_src, visibility_operand, .{ |
| 23081 | 23080 | .needed_comptime_reason = "visibility of exported value must be comptime-known", |
| 23082 | 23081 | }); |
| 23083 | 23082 | const visibility = mod.toEnum(std.builtin.SymbolVisibility, visibility_val); |
| ... | ... | @@ -23112,7 +23111,7 @@ fn resolveBuiltinEnum( |
| 23112 | 23111 | const ty = try sema.getBuiltinType(name); |
| 23113 | 23112 | const air_ref = try sema.resolveInst(zir_ref); |
| 23114 | 23113 | const coerced = try sema.coerce(block, ty, air_ref, src); |
| 23115 | | const val = try sema.resolveConstValue(block, src, coerced, reason); |
| 23114 | const val = try sema.resolveConstDefinedValue(block, src, coerced, reason); |
| 23116 | 23115 | return mod.toEnum(@field(std.builtin, name), val); |
| 23117 | 23116 | } |
| 23118 | 23117 | |
| ... | ... | @@ -23202,8 +23201,8 @@ fn zirCmpxchg( |
| 23202 | 23201 | } |
| 23203 | 23202 | |
| 23204 | 23203 | const runtime_src = if (try sema.resolveDefinedValue(block, ptr_src, ptr)) |ptr_val| rs: { |
| 23205 | | if (try sema.resolveMaybeUndefVal(expected_value)) |expected_val| { |
| 23206 | | if (try sema.resolveMaybeUndefVal(new_value)) |new_val| { |
| 23204 | if (try sema.resolveValue(expected_value)) |expected_val| { |
| 23205 | if (try sema.resolveValue(new_value)) |new_val| { |
| 23207 | 23206 | if (expected_val.isUndef(mod) or new_val.isUndef(mod)) { |
| 23208 | 23207 | // TODO: this should probably cause the memory stored at the pointer |
| 23209 | 23208 | // to become undef as well |
| ... | ... | @@ -23254,7 +23253,7 @@ fn zirSplat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.I |
| 23254 | 23253 | const operand = try sema.resolveInst(extra.rhs); |
| 23255 | 23254 | const scalar_ty = dest_ty.childType(mod); |
| 23256 | 23255 | const scalar = try sema.coerce(block, scalar_ty, operand, scalar_src); |
| 23257 | | if (try sema.resolveMaybeUndefVal(scalar)) |scalar_val| { |
| 23256 | if (try sema.resolveValue(scalar)) |scalar_val| { |
| 23258 | 23257 | if (scalar_val.isUndef(mod)) return mod.undefRef(dest_ty); |
| 23259 | 23258 | return Air.internedToRef((try sema.splat(dest_ty, scalar_val)).toIntern()); |
| 23260 | 23259 | } |
| ... | ... | @@ -23304,7 +23303,7 @@ fn zirReduce(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. |
| 23304 | 23303 | return sema.fail(block, operand_src, "@reduce operation requires a vector with nonzero length", .{}); |
| 23305 | 23304 | } |
| 23306 | 23305 | |
| 23307 | | if (try sema.resolveMaybeUndefVal(operand)) |operand_val| { |
| 23306 | if (try sema.resolveValue(operand)) |operand_val| { |
| 23308 | 23307 | if (operand_val.isUndef(mod)) return mod.undefRef(scalar_ty); |
| 23309 | 23308 | |
| 23310 | 23309 | var accum: Value = try operand_val.elemValue(mod, 0); |
| ... | ... | @@ -23357,7 +23356,7 @@ fn zirShuffle(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 23357 | 23356 | .child = .i32_type, |
| 23358 | 23357 | }); |
| 23359 | 23358 | mask = try sema.coerce(block, mask_ty, mask, mask_src); |
| 23360 | | const mask_val = try sema.resolveConstMaybeUndefVal(block, mask_src, mask, .{ |
| 23359 | const mask_val = try sema.resolveConstValue(block, mask_src, mask, .{ |
| 23361 | 23360 | .needed_comptime_reason = "shuffle mask must be comptime-known", |
| 23362 | 23361 | }); |
| 23363 | 23362 | return sema.analyzeShuffle(block, inst_data.src_node, elem_ty, a, b, mask_val, @intCast(mask_len)); |
| ... | ... | @@ -23457,8 +23456,8 @@ fn analyzeShuffle( |
| 23457 | 23456 | } |
| 23458 | 23457 | } |
| 23459 | 23458 | |
| 23460 | | if (try sema.resolveMaybeUndefVal(a)) |a_val| { |
| 23461 | | if (try sema.resolveMaybeUndefVal(b)) |b_val| { |
| 23459 | if (try sema.resolveValue(a)) |a_val| { |
| 23460 | if (try sema.resolveValue(b)) |b_val| { |
| 23462 | 23461 | const values = try sema.arena.alloc(InternPool.Index, mask_len); |
| 23463 | 23462 | for (values, 0..) |*value, i| { |
| 23464 | 23463 | const mask_elem_val = try mask.elemValue(sema.mod, i); |
| ... | ... | @@ -23556,9 +23555,9 @@ fn zirSelect(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) C |
| 23556 | 23555 | const a = try sema.coerce(block, vec_ty, try sema.resolveInst(extra.a), a_src); |
| 23557 | 23556 | const b = try sema.coerce(block, vec_ty, try sema.resolveInst(extra.b), b_src); |
| 23558 | 23557 | |
| 23559 | | const maybe_pred = try sema.resolveMaybeUndefVal(pred); |
| 23560 | | const maybe_a = try sema.resolveMaybeUndefVal(a); |
| 23561 | | const maybe_b = try sema.resolveMaybeUndefVal(b); |
| 23558 | const maybe_pred = try sema.resolveValue(pred); |
| 23559 | const maybe_a = try sema.resolveValue(a); |
| 23560 | const maybe_b = try sema.resolveValue(b); |
| 23562 | 23561 | |
| 23563 | 23562 | const runtime_src = if (maybe_pred) |pred_val| rs: { |
| 23564 | 23563 | if (pred_val.isUndef(mod)) return mod.undefRef(vec_ty); |
| ... | ... | @@ -23704,7 +23703,7 @@ fn zirAtomicRmw(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 23704 | 23703 | } |
| 23705 | 23704 | |
| 23706 | 23705 | const runtime_src = if (try sema.resolveDefinedValue(block, ptr_src, ptr)) |ptr_val| rs: { |
| 23707 | | const maybe_operand_val = try sema.resolveMaybeUndefVal(operand); |
| 23706 | const maybe_operand_val = try sema.resolveValue(operand); |
| 23708 | 23707 | const operand_val = maybe_operand_val orelse { |
| 23709 | 23708 | try sema.checkPtrIsNotComptimeMutable(block, ptr_val, ptr_src, operand_src); |
| 23710 | 23709 | break :rs operand_src; |
| ... | ... | @@ -23795,9 +23794,9 @@ fn zirMulAdd(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. |
| 23795 | 23794 | const mulend1 = try sema.coerce(block, ty, try sema.resolveInst(extra.mulend1), mulend1_src); |
| 23796 | 23795 | const mulend2 = try sema.coerce(block, ty, try sema.resolveInst(extra.mulend2), mulend2_src); |
| 23797 | 23796 | |
| 23798 | | const maybe_mulend1 = try sema.resolveMaybeUndefVal(mulend1); |
| 23799 | | const maybe_mulend2 = try sema.resolveMaybeUndefVal(mulend2); |
| 23800 | | const maybe_addend = try sema.resolveMaybeUndefVal(addend); |
| 23797 | const maybe_mulend1 = try sema.resolveValue(mulend1); |
| 23798 | const maybe_mulend2 = try sema.resolveValue(mulend2); |
| 23799 | const maybe_addend = try sema.resolveValue(addend); |
| 23801 | 23800 | const mod = sema.mod; |
| 23802 | 23801 | |
| 23803 | 23802 | switch (ty.scalarType(mod).zigTypeTag(mod)) { |
| ... | ... | @@ -23862,7 +23861,7 @@ fn zirBuiltinCall(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 23862 | 23861 | const modifier_ty = try sema.getBuiltinType("CallModifier"); |
| 23863 | 23862 | const air_ref = try sema.resolveInst(extra.modifier); |
| 23864 | 23863 | const modifier_ref = try sema.coerce(block, modifier_ty, air_ref, modifier_src); |
| 23865 | | const modifier_val = try sema.resolveConstValue(block, modifier_src, modifier_ref, .{ |
| 23864 | const modifier_val = try sema.resolveConstDefinedValue(block, modifier_src, modifier_ref, .{ |
| 23866 | 23865 | .needed_comptime_reason = "call modifier must be comptime-known", |
| 23867 | 23866 | }); |
| 23868 | 23867 | var modifier = mod.toEnum(std.builtin.CallModifier, modifier_val); |
| ... | ... | @@ -24146,7 +24145,7 @@ fn analyzeMinMax( |
| 24146 | 24145 | for (operands, operand_srcs, 0..) |operand, operand_src, operand_idx| { |
| 24147 | 24146 | // Resolve the value now to avoid redundant calls to `checkSimdBinOp` - we'll have to call |
| 24148 | 24147 | // it in the runtime path anyway since the result type may have been refined |
| 24149 | | const unresolved_uncoerced_val = try sema.resolveMaybeUndefVal(operand) orelse continue; |
| 24148 | const unresolved_uncoerced_val = try sema.resolveValue(operand) orelse continue; |
| 24150 | 24149 | const uncoerced_val = try sema.resolveLazyValue(unresolved_uncoerced_val); |
| 24151 | 24150 | |
| 24152 | 24151 | runtime_known.unset(operand_idx); |
| ... | ... | @@ -24222,7 +24221,7 @@ fn analyzeMinMax( |
| 24222 | 24221 | // as possible will allow us to emit more optimal AIR (if all the runtime operands have |
| 24223 | 24222 | // smaller types than the non-refined comptime type). |
| 24224 | 24223 | |
| 24225 | | const val = (try sema.resolveMaybeUndefVal(ct_minmax_ref)).?; |
| 24224 | const val = (try sema.resolveValue(ct_minmax_ref)).?; |
| 24226 | 24225 | const orig_ty = sema.typeOf(ct_minmax_ref); |
| 24227 | 24226 | |
| 24228 | 24227 | if (opt_runtime_idx == null and orig_ty.scalarType(mod).eql(Type.comptime_int, mod)) { |
| ... | ... | @@ -24257,7 +24256,7 @@ fn analyzeMinMax( |
| 24257 | 24256 | |
| 24258 | 24257 | // If the comptime-known part is undef we can avoid emitting actual instructions later |
| 24259 | 24258 | const known_undef = if (cur_minmax) |operand| blk: { |
| 24260 | | const val = (try sema.resolveMaybeUndefVal(operand)).?; |
| 24259 | const val = (try sema.resolveValue(operand)).?; |
| 24261 | 24260 | break :blk val.isUndef(mod); |
| 24262 | 24261 | } else false; |
| 24263 | 24262 | |
| ... | ... | @@ -24631,7 +24630,7 @@ fn zirMemset(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void |
| 24631 | 24630 | } |
| 24632 | 24631 | |
| 24633 | 24632 | if (!ptr_val.isComptimeMutablePtr(mod)) break :rs dest_src; |
| 24634 | | const elem_val = try sema.resolveMaybeUndefVal(elem) orelse break :rs value_src; |
| 24633 | const elem_val = try sema.resolveValue(elem) orelse break :rs value_src; |
| 24635 | 24634 | const array_ty = try mod.arrayType(.{ |
| 24636 | 24635 | .child = dest_elem_ty.toIntern(), |
| 24637 | 24636 | .len = len_u64, |
| ... | ... | @@ -24736,7 +24735,7 @@ fn zirVarExtended( |
| 24736 | 24735 | else |
| 24737 | 24736 | uncasted_init; |
| 24738 | 24737 | |
| 24739 | | break :blk ((try sema.resolveMaybeUndefVal(init)) orelse { |
| 24738 | break :blk ((try sema.resolveValue(init)) orelse { |
| 24740 | 24739 | return sema.failWithNeededComptime(block, init_src, .{ |
| 24741 | 24740 | .needed_comptime_reason = "container level variable initializers must be comptime-known", |
| 24742 | 24741 | }); |
| ... | ... | @@ -25097,17 +25096,17 @@ fn resolvePrefetchOptions( |
| 25097 | 25096 | const cache_src = sema.maybeOptionsSrc(block, src, "cache"); |
| 25098 | 25097 | |
| 25099 | 25098 | const rw = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "rw"), rw_src); |
| 25100 | | const rw_val = try sema.resolveConstValue(block, rw_src, rw, .{ |
| 25099 | const rw_val = try sema.resolveConstDefinedValue(block, rw_src, rw, .{ |
| 25101 | 25100 | .needed_comptime_reason = "prefetch read/write must be comptime-known", |
| 25102 | 25101 | }); |
| 25103 | 25102 | |
| 25104 | 25103 | const locality = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "locality"), locality_src); |
| 25105 | | const locality_val = try sema.resolveConstValue(block, locality_src, locality, .{ |
| 25104 | const locality_val = try sema.resolveConstDefinedValue(block, locality_src, locality, .{ |
| 25106 | 25105 | .needed_comptime_reason = "prefetch locality must be comptime-known", |
| 25107 | 25106 | }); |
| 25108 | 25107 | |
| 25109 | 25108 | const cache = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "cache"), cache_src); |
| 25110 | | const cache_val = try sema.resolveConstValue(block, cache_src, cache, .{ |
| 25109 | const cache_val = try sema.resolveConstDefinedValue(block, cache_src, cache, .{ |
| 25111 | 25110 | .needed_comptime_reason = "prefetch cache must be comptime-known", |
| 25112 | 25111 | }); |
| 25113 | 25112 | |
| ... | ... | @@ -25176,24 +25175,24 @@ fn resolveExternOptions( |
| 25176 | 25175 | const thread_local_src = sema.maybeOptionsSrc(block, src, "thread_local"); |
| 25177 | 25176 | |
| 25178 | 25177 | const name_ref = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "name"), name_src); |
| 25179 | | const name_val = try sema.resolveConstValue(block, name_src, name_ref, .{ |
| 25178 | const name_val = try sema.resolveConstDefinedValue(block, name_src, name_ref, .{ |
| 25180 | 25179 | .needed_comptime_reason = "name of the extern symbol must be comptime-known", |
| 25181 | 25180 | }); |
| 25182 | 25181 | const name = try name_val.toAllocatedBytes(Type.slice_const_u8, sema.arena, mod); |
| 25183 | 25182 | |
| 25184 | 25183 | const library_name_inst = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "library_name"), library_src); |
| 25185 | | const library_name_val = try sema.resolveConstValue(block, library_src, library_name_inst, .{ |
| 25184 | const library_name_val = try sema.resolveConstDefinedValue(block, library_src, library_name_inst, .{ |
| 25186 | 25185 | .needed_comptime_reason = "library in which extern symbol is must be comptime-known", |
| 25187 | 25186 | }); |
| 25188 | 25187 | |
| 25189 | 25188 | const linkage_ref = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "linkage"), linkage_src); |
| 25190 | | const linkage_val = try sema.resolveConstValue(block, linkage_src, linkage_ref, .{ |
| 25189 | const linkage_val = try sema.resolveConstDefinedValue(block, linkage_src, linkage_ref, .{ |
| 25191 | 25190 | .needed_comptime_reason = "linkage of the extern symbol must be comptime-known", |
| 25192 | 25191 | }); |
| 25193 | 25192 | const linkage = mod.toEnum(std.builtin.GlobalLinkage, linkage_val); |
| 25194 | 25193 | |
| 25195 | 25194 | const is_thread_local = try sema.fieldVal(block, src, options, try ip.getOrPutString(gpa, "is_thread_local"), thread_local_src); |
| 25196 | | const is_thread_local_val = try sema.resolveConstValue(block, thread_local_src, is_thread_local, .{ |
| 25195 | const is_thread_local_val = try sema.resolveConstDefinedValue(block, thread_local_src, is_thread_local, .{ |
| 25197 | 25196 | .needed_comptime_reason = "threadlocality of the extern symbol must be comptime-known", |
| 25198 | 25197 | }); |
| 25199 | 25198 | |
| ... | ... | @@ -26419,7 +26418,7 @@ fn fieldPtr( |
| 26419 | 26418 | } |
| 26420 | 26419 | }, |
| 26421 | 26420 | .Type => { |
| 26422 | | _ = try sema.resolveConstValue(block, .unneeded, object_ptr, undefined); |
| 26421 | _ = try sema.resolveConstDefinedValue(block, .unneeded, object_ptr, undefined); |
| 26423 | 26422 | const result = try sema.analyzeLoad(block, src, object_ptr, object_ptr_src); |
| 26424 | 26423 | const inner = if (is_pointer_to) |
| 26425 | 26424 | try sema.analyzeLoad(block, src, result, object_ptr_src) |
| ... | ... | @@ -26991,7 +26990,7 @@ fn structFieldVal( |
| 26991 | 26990 | |
| 26992 | 26991 | const field_ty = struct_type.field_types.get(ip)[field_index].toType(); |
| 26993 | 26992 | |
| 26994 | | if (try sema.resolveMaybeUndefVal(struct_byval)) |struct_val| { |
| 26993 | if (try sema.resolveValue(struct_byval)) |struct_val| { |
| 26995 | 26994 | if (struct_val.isUndef(mod)) return mod.undefRef(field_ty); |
| 26996 | 26995 | if ((try sema.typeHasOnePossibleValue(field_ty))) |opv| { |
| 26997 | 26996 | return Air.internedToRef(opv.toIntern()); |
| ... | ... | @@ -27069,7 +27068,7 @@ fn tupleFieldValByIndex( |
| 27069 | 27068 | return Air.internedToRef(default_value.toIntern()); |
| 27070 | 27069 | } |
| 27071 | 27070 | |
| 27072 | | if (try sema.resolveMaybeUndefVal(tuple_byval)) |tuple_val| { |
| 27071 | if (try sema.resolveValue(tuple_byval)) |tuple_val| { |
| 27073 | 27072 | if ((try sema.typeHasOnePossibleValue(field_ty))) |opv| { |
| 27074 | 27073 | return Air.internedToRef(opv.toIntern()); |
| 27075 | 27074 | } |
| ... | ... | @@ -27221,7 +27220,7 @@ fn unionFieldVal( |
| 27221 | 27220 | const field_ty = union_obj.field_types.get(ip)[field_index].toType(); |
| 27222 | 27221 | const enum_field_index: u32 = @intCast(union_obj.enum_tag_ty.toType().enumFieldIndex(field_name, mod).?); |
| 27223 | 27222 | |
| 27224 | | if (try sema.resolveMaybeUndefVal(union_byval)) |union_val| { |
| 27223 | if (try sema.resolveValue(union_byval)) |union_val| { |
| 27225 | 27224 | if (union_val.isUndef(mod)) return mod.undefRef(field_ty); |
| 27226 | 27225 | |
| 27227 | 27226 | const un = ip.indexToKey(union_val.toIntern()).un; |
| ... | ... | @@ -27303,7 +27302,7 @@ fn elemPtr( |
| 27303 | 27302 | .Array, .Vector => try sema.elemPtrArray(block, src, indexable_ptr_src, indexable_ptr, elem_index_src, elem_index, init, oob_safety), |
| 27304 | 27303 | .Struct => blk: { |
| 27305 | 27304 | // Tuple field access. |
| 27306 | | const index_val = try sema.resolveConstValue(block, elem_index_src, elem_index, .{ |
| 27305 | const index_val = try sema.resolveConstDefinedValue(block, elem_index_src, elem_index, .{ |
| 27307 | 27306 | .needed_comptime_reason = "tuple field access index must be comptime-known", |
| 27308 | 27307 | }); |
| 27309 | 27308 | const index: u32 = @intCast(index_val.toUnsignedInt(mod)); |
| ... | ... | @@ -27360,7 +27359,7 @@ fn elemPtrOneLayerOnly( |
| 27360 | 27359 | .Array, .Vector => try sema.elemPtrArray(block, src, indexable_src, indexable, elem_index_src, elem_index, init, oob_safety), |
| 27361 | 27360 | .Struct => blk: { |
| 27362 | 27361 | assert(child_ty.isTuple(mod)); |
| 27363 | | const index_val = try sema.resolveConstValue(block, elem_index_src, elem_index, .{ |
| 27362 | const index_val = try sema.resolveConstDefinedValue(block, elem_index_src, elem_index, .{ |
| 27364 | 27363 | .needed_comptime_reason = "tuple field access index must be comptime-known", |
| 27365 | 27364 | }); |
| 27366 | 27365 | const index: u32 = @intCast(index_val.toUnsignedInt(mod)); |
| ... | ... | @@ -27439,7 +27438,7 @@ fn elemVal( |
| 27439 | 27438 | }, |
| 27440 | 27439 | .Struct => { |
| 27441 | 27440 | // Tuple field access. |
| 27442 | | const index_val = try sema.resolveConstValue(block, elem_index_src, elem_index, .{ |
| 27441 | const index_val = try sema.resolveConstDefinedValue(block, elem_index_src, elem_index, .{ |
| 27443 | 27442 | .needed_comptime_reason = "tuple field access index must be comptime-known", |
| 27444 | 27443 | }); |
| 27445 | 27444 | const index: u32 = @intCast(index_val.toUnsignedInt(mod)); |
| ... | ... | @@ -27519,7 +27518,7 @@ fn tupleFieldPtr( |
| 27519 | 27518 | } }))); |
| 27520 | 27519 | } |
| 27521 | 27520 | |
| 27522 | | if (try sema.resolveMaybeUndefVal(tuple_ptr)) |tuple_ptr_val| { |
| 27521 | if (try sema.resolveValue(tuple_ptr)) |tuple_ptr_val| { |
| 27523 | 27522 | return Air.internedToRef((try mod.intern(.{ .ptr = .{ |
| 27524 | 27523 | .ty = ptr_field_ty.toIntern(), |
| 27525 | 27524 | .addr = .{ .field = .{ |
| ... | ... | @@ -27566,7 +27565,7 @@ fn tupleField( |
| 27566 | 27565 | return Air.internedToRef(default_value.toIntern()); // comptime field |
| 27567 | 27566 | } |
| 27568 | 27567 | |
| 27569 | | if (try sema.resolveMaybeUndefVal(tuple)) |tuple_val| { |
| 27568 | if (try sema.resolveValue(tuple)) |tuple_val| { |
| 27570 | 27569 | if (tuple_val.isUndef(mod)) return mod.undefRef(field_ty); |
| 27571 | 27570 | return Air.internedToRef((try tuple_val.fieldValue(mod, field_index)).toIntern()); |
| 27572 | 27571 | } |
| ... | ... | @@ -27599,7 +27598,7 @@ fn elemValArray( |
| 27599 | 27598 | return sema.fail(block, array_src, "indexing into empty array is not allowed", .{}); |
| 27600 | 27599 | } |
| 27601 | 27600 | |
| 27602 | | const maybe_undef_array_val = try sema.resolveMaybeUndefVal(array); |
| 27601 | const maybe_undef_array_val = try sema.resolveValue(array); |
| 27603 | 27602 | // index must be defined since it can access out of bounds |
| 27604 | 27603 | const maybe_index_val = try sema.resolveDefinedValue(block, elem_index_src, elem_index); |
| 27605 | 27604 | |
| ... | ... | @@ -27664,7 +27663,7 @@ fn elemPtrArray( |
| 27664 | 27663 | return sema.fail(block, array_ptr_src, "indexing into empty array is not allowed", .{}); |
| 27665 | 27664 | } |
| 27666 | 27665 | |
| 27667 | | const maybe_undef_array_ptr_val = try sema.resolveMaybeUndefVal(array_ptr); |
| 27666 | const maybe_undef_array_ptr_val = try sema.resolveValue(array_ptr); |
| 27668 | 27667 | // The index must not be undefined since it can be out of bounds. |
| 27669 | 27668 | const offset: ?usize = if (try sema.resolveDefinedValue(block, elem_index_src, elem_index)) |index_val| o: { |
| 27670 | 27669 | const index = try sema.usizeCast(block, elem_index_src, index_val.toUnsignedInt(mod)); |
| ... | ... | @@ -27776,7 +27775,7 @@ fn elemPtrSlice( |
| 27776 | 27775 | const slice_ty = sema.typeOf(slice); |
| 27777 | 27776 | const slice_sent = slice_ty.sentinel(mod) != null; |
| 27778 | 27777 | |
| 27779 | | const maybe_undef_slice_val = try sema.resolveMaybeUndefVal(slice); |
| 27778 | const maybe_undef_slice_val = try sema.resolveValue(slice); |
| 27780 | 27779 | // The index must not be undefined since it can be out of bounds. |
| 27781 | 27780 | const offset: ?usize = if (try sema.resolveDefinedValue(block, elem_index_src, elem_index)) |index_val| o: { |
| 27782 | 27781 | const index = try sema.usizeCast(block, elem_index_src, index_val.toUnsignedInt(mod)); |
| ... | ... | @@ -27888,7 +27887,7 @@ fn coerceExtra( |
| 27888 | 27887 | if (dest_ty.eql(inst_ty, mod)) |
| 27889 | 27888 | return inst; |
| 27890 | 27889 | |
| 27891 | | const maybe_inst_val = try sema.resolveMaybeUndefVal(inst); |
| 27890 | const maybe_inst_val = try sema.resolveValue(inst); |
| 27892 | 27891 | |
| 27893 | 27892 | var in_memory_result = try sema.coerceInMemoryAllowed(block, dest_ty, inst_ty, false, target, dest_ty_src, inst_src); |
| 27894 | 27893 | if (in_memory_result == .ok) { |
| ... | ... | @@ -27958,7 +27957,7 @@ fn coerceExtra( |
| 27958 | 27957 | |
| 27959 | 27958 | // Function body to function pointer. |
| 27960 | 27959 | if (inst_ty.zigTypeTag(mod) == .Fn) { |
| 27961 | | const fn_val = try sema.resolveConstValue(block, .unneeded, inst, undefined); |
| 27960 | const fn_val = try sema.resolveConstDefinedValue(block, .unneeded, inst, undefined); |
| 27962 | 27961 | const fn_decl = fn_val.pointerDecl(mod).?; |
| 27963 | 27962 | const inst_as_ptr = try sema.analyzeDeclRef(fn_decl); |
| 27964 | 27963 | return sema.coerce(block, dest_ty, inst_as_ptr, inst_src); |
| ... | ... | @@ -28303,7 +28302,7 @@ fn coerceExtra( |
| 28303 | 28302 | }, |
| 28304 | 28303 | .Float, .ComptimeFloat => switch (inst_ty.zigTypeTag(mod)) { |
| 28305 | 28304 | .ComptimeFloat => { |
| 28306 | | const val = try sema.resolveConstValue(block, .unneeded, inst, undefined); |
| 28305 | const val = try sema.resolveConstDefinedValue(block, .unneeded, inst, undefined); |
| 28307 | 28306 | const result_val = try val.floatCast(dest_ty, mod); |
| 28308 | 28307 | return Air.internedToRef(result_val.toIntern()); |
| 28309 | 28308 | }, |
| ... | ... | @@ -28362,7 +28361,7 @@ fn coerceExtra( |
| 28362 | 28361 | .Enum => switch (inst_ty.zigTypeTag(mod)) { |
| 28363 | 28362 | .EnumLiteral => { |
| 28364 | 28363 | // enum literal to enum |
| 28365 | | const val = try sema.resolveConstValue(block, .unneeded, inst, undefined); |
| 28364 | const val = try sema.resolveConstDefinedValue(block, .unneeded, inst, undefined); |
| 28366 | 28365 | const string = mod.intern_pool.indexToKey(val.toIntern()).enum_literal; |
| 28367 | 28366 | const field_index = dest_ty.enumFieldIndex(string, mod) orelse { |
| 28368 | 28367 | const msg = msg: { |
| ... | ... | @@ -29490,7 +29489,7 @@ fn coerceVarArgParam( |
| 29490 | 29489 | .{}, |
| 29491 | 29490 | ), |
| 29492 | 29491 | .Fn => blk: { |
| 29493 | | const fn_val = try sema.resolveConstValue(block, .unneeded, inst, undefined); |
| 29492 | const fn_val = try sema.resolveConstDefinedValue(block, .unneeded, inst, undefined); |
| 29494 | 29493 | const fn_decl = fn_val.pointerDecl(mod).?; |
| 29495 | 29494 | break :blk try sema.analyzeDeclRef(fn_decl); |
| 29496 | 29495 | }, |
| ... | ... | @@ -29602,7 +29601,7 @@ fn storePtr2( |
| 29602 | 29601 | error.NotCoercible => unreachable, |
| 29603 | 29602 | else => |e| return e, |
| 29604 | 29603 | }; |
| 29605 | | const maybe_operand_val = try sema.resolveMaybeUndefVal(operand); |
| 29604 | const maybe_operand_val = try sema.resolveValue(operand); |
| 29606 | 29605 | |
| 29607 | 29606 | const runtime_src = if (try sema.resolveDefinedValue(block, ptr_src, ptr)) |ptr_val| rs: { |
| 29608 | 29607 | const operand_val = maybe_operand_val orelse { |
| ... | ... | @@ -29670,7 +29669,7 @@ fn checkComptimeKnownStore(sema: *Sema, block: *Block, store_inst_ref: Air.Inst. |
| 29670 | 29669 | const maybe_comptime_alloc = sema.maybe_comptime_allocs.getPtr(maybe_base_alloc) orelse return; |
| 29671 | 29670 | |
| 29672 | 29671 | ct: { |
| 29673 | | if (null == try sema.resolveMaybeUndefVal(operand)) break :ct; |
| 29672 | if (null == try sema.resolveValue(operand)) break :ct; |
| 29674 | 29673 | if (maybe_comptime_alloc.runtime_index != block.runtime_index) break :ct; |
| 29675 | 29674 | return maybe_comptime_alloc.stores.append(sema.arena, store_inst); |
| 29676 | 29675 | } |
| ... | ... | @@ -29701,7 +29700,7 @@ fn checkKnownAllocPtr(sema: *Sema, base_ptr: Air.Inst.Ref, new_ptr: Air.Inst.Ref |
| 29701 | 29700 | |
| 29702 | 29701 | // If the index value is runtime-known, this pointer is also runtime-known, so |
| 29703 | 29702 | // we must in turn make the alloc value runtime-known. |
| 29704 | | if (null == try sema.resolveMaybeUndefVal(index_ref)) { |
| 29703 | if (null == try sema.resolveValue(index_ref)) { |
| 29705 | 29704 | _ = sema.maybe_comptime_allocs.remove(alloc_inst); |
| 29706 | 29705 | } |
| 29707 | 29706 | }, |
| ... | ... | @@ -30711,7 +30710,7 @@ fn bitCast( |
| 30711 | 30710 | }); |
| 30712 | 30711 | } |
| 30713 | 30712 | |
| 30714 | | if (try sema.resolveMaybeUndefVal(inst)) |val| { |
| 30713 | if (try sema.resolveValue(inst)) |val| { |
| 30715 | 30714 | if (try sema.bitCastVal(block, inst_src, val, old_ty, dest_ty, 0)) |result_val| { |
| 30716 | 30715 | return Air.internedToRef(result_val.toIntern()); |
| 30717 | 30716 | } |
| ... | ... | @@ -30817,7 +30816,7 @@ fn coerceArrayPtrToSlice( |
| 30817 | 30816 | inst_src: LazySrcLoc, |
| 30818 | 30817 | ) CompileError!Air.Inst.Ref { |
| 30819 | 30818 | const mod = sema.mod; |
| 30820 | | if (try sema.resolveMaybeUndefVal(inst)) |val| { |
| 30819 | if (try sema.resolveValue(inst)) |val| { |
| 30821 | 30820 | const ptr_array_ty = sema.typeOf(inst); |
| 30822 | 30821 | const array_ty = ptr_array_ty.childType(mod); |
| 30823 | 30822 | const slice_val = try mod.intern(.{ .ptr = .{ |
| ... | ... | @@ -30895,7 +30894,7 @@ fn coerceCompatiblePtrs( |
| 30895 | 30894 | ) !Air.Inst.Ref { |
| 30896 | 30895 | const mod = sema.mod; |
| 30897 | 30896 | const inst_ty = sema.typeOf(inst); |
| 30898 | | if (try sema.resolveMaybeUndefVal(inst)) |val| { |
| 30897 | if (try sema.resolveValue(inst)) |val| { |
| 30899 | 30898 | if (!val.isUndef(mod) and val.isNull(mod) and !dest_ty.isAllowzeroPtr(mod)) { |
| 30900 | 30899 | return sema.fail(block, inst_src, "null pointer casted to type '{}'", .{dest_ty.fmt(sema.mod)}); |
| 30901 | 30900 | } |
| ... | ... | @@ -31178,7 +31177,7 @@ fn coerceArrayLike( |
| 31178 | 31177 | // try coercion of the whole array |
| 31179 | 31178 | const in_memory_result = try sema.coerceInMemoryAllowed(block, dest_ty, inst_ty, false, target, dest_ty_src, inst_src); |
| 31180 | 31179 | if (in_memory_result == .ok) { |
| 31181 | | if (try sema.resolveMaybeUndefVal(inst)) |inst_val| { |
| 31180 | if (try sema.resolveValue(inst)) |inst_val| { |
| 31182 | 31181 | // These types share the same comptime value representation. |
| 31183 | 31182 | return sema.coerceInMemory(inst_val, dest_ty); |
| 31184 | 31183 | } |
| ... | ... | @@ -31215,7 +31214,7 @@ fn coerceArrayLike( |
| 31215 | 31214 | const coerced = try sema.coerce(block, dest_elem_ty, elem_ref, elem_src); |
| 31216 | 31215 | ref.* = coerced; |
| 31217 | 31216 | if (runtime_src == null) { |
| 31218 | | if (try sema.resolveMaybeUndefVal(coerced)) |elem_val| { |
| 31217 | if (try sema.resolveValue(coerced)) |elem_val| { |
| 31219 | 31218 | val.* = try elem_val.intern(dest_elem_ty, mod); |
| 31220 | 31219 | } else { |
| 31221 | 31220 | runtime_src = elem_src; |
| ... | ... | @@ -31280,7 +31279,7 @@ fn coerceTupleToArray( |
| 31280 | 31279 | const coerced = try sema.coerce(block, dest_elem_ty, elem_ref, elem_src); |
| 31281 | 31280 | ref.* = coerced; |
| 31282 | 31281 | if (runtime_src == null) { |
| 31283 | | if (try sema.resolveMaybeUndefVal(coerced)) |elem_val| { |
| 31282 | if (try sema.resolveValue(coerced)) |elem_val| { |
| 31284 | 31283 | val.* = try elem_val.intern(dest_elem_ty, mod); |
| 31285 | 31284 | } else { |
| 31286 | 31285 | runtime_src = elem_src; |
| ... | ... | @@ -31393,7 +31392,7 @@ fn coerceTupleToStruct( |
| 31393 | 31392 | const coerced = try sema.coerce(block, field_ty, elem_ref, field_src); |
| 31394 | 31393 | field_refs[field_index] = coerced; |
| 31395 | 31394 | if (struct_type.fieldIsComptime(ip, field_index)) { |
| 31396 | | const init_val = (try sema.resolveMaybeUndefVal(coerced)) orelse { |
| 31395 | const init_val = (try sema.resolveValue(coerced)) orelse { |
| 31397 | 31396 | return sema.failWithNeededComptime(block, field_src, .{ |
| 31398 | 31397 | .needed_comptime_reason = "value stored in comptime field must be comptime-known", |
| 31399 | 31398 | }); |
| ... | ... | @@ -31405,7 +31404,7 @@ fn coerceTupleToStruct( |
| 31405 | 31404 | } |
| 31406 | 31405 | } |
| 31407 | 31406 | if (runtime_src == null) { |
| 31408 | | if (try sema.resolveMaybeUndefVal(coerced)) |field_val| { |
| 31407 | if (try sema.resolveValue(coerced)) |field_val| { |
| 31409 | 31408 | field_vals[field_index] = field_val.toIntern(); |
| 31410 | 31409 | } else { |
| 31411 | 31410 | runtime_src = field_src; |
| ... | ... | @@ -31521,7 +31520,7 @@ fn coerceTupleToTuple( |
| 31521 | 31520 | const coerced = try sema.coerce(block, field_ty.toType(), elem_ref, field_src); |
| 31522 | 31521 | field_refs[field_index] = coerced; |
| 31523 | 31522 | if (default_val != .none) { |
| 31524 | | const init_val = (try sema.resolveMaybeUndefVal(coerced)) orelse { |
| 31523 | const init_val = (try sema.resolveValue(coerced)) orelse { |
| 31525 | 31524 | return sema.failWithNeededComptime(block, field_src, .{ |
| 31526 | 31525 | .needed_comptime_reason = "value stored in comptime field must be comptime-known", |
| 31527 | 31526 | }); |
| ... | ... | @@ -31532,7 +31531,7 @@ fn coerceTupleToTuple( |
| 31532 | 31531 | } |
| 31533 | 31532 | } |
| 31534 | 31533 | if (runtime_src == null) { |
| 31535 | | if (try sema.resolveMaybeUndefVal(coerced)) |field_val| { |
| 31534 | if (try sema.resolveValue(coerced)) |field_val| { |
| 31536 | 31535 | field_vals[field_index] = field_val.toIntern(); |
| 31537 | 31536 | } else { |
| 31538 | 31537 | runtime_src = field_src; |
| ... | ... | @@ -31753,7 +31752,7 @@ fn analyzeRef( |
| 31753 | 31752 | const mod = sema.mod; |
| 31754 | 31753 | const operand_ty = sema.typeOf(operand); |
| 31755 | 31754 | |
| 31756 | | if (try sema.resolveMaybeUndefVal(operand)) |val| { |
| 31755 | if (try sema.resolveValue(operand)) |val| { |
| 31757 | 31756 | switch (mod.intern_pool.indexToKey(val.toIntern())) { |
| 31758 | 31757 | .extern_func => |extern_func| return sema.analyzeDeclRef(extern_func.decl), |
| 31759 | 31758 | .func => |func| return sema.analyzeDeclRef(func.owner_decl), |
| ... | ... | @@ -31840,7 +31839,7 @@ fn analyzeSlicePtr( |
| 31840 | 31839 | ) CompileError!Air.Inst.Ref { |
| 31841 | 31840 | const mod = sema.mod; |
| 31842 | 31841 | const result_ty = slice_ty.slicePtrFieldType(mod); |
| 31843 | | if (try sema.resolveMaybeUndefVal(slice)) |val| { |
| 31842 | if (try sema.resolveValue(slice)) |val| { |
| 31844 | 31843 | if (val.isUndef(mod)) return mod.undefRef(result_ty); |
| 31845 | 31844 | return Air.internedToRef(val.slicePtr(mod).toIntern()); |
| 31846 | 31845 | } |
| ... | ... | @@ -31855,7 +31854,7 @@ fn analyzeSliceLen( |
| 31855 | 31854 | slice_inst: Air.Inst.Ref, |
| 31856 | 31855 | ) CompileError!Air.Inst.Ref { |
| 31857 | 31856 | const mod = sema.mod; |
| 31858 | | if (try sema.resolveMaybeUndefVal(slice_inst)) |slice_val| { |
| 31857 | if (try sema.resolveValue(slice_inst)) |slice_val| { |
| 31859 | 31858 | if (slice_val.isUndef(mod)) { |
| 31860 | 31859 | return mod.undefRef(Type.usize); |
| 31861 | 31860 | } |
| ... | ... | @@ -31874,7 +31873,7 @@ fn analyzeIsNull( |
| 31874 | 31873 | ) CompileError!Air.Inst.Ref { |
| 31875 | 31874 | const mod = sema.mod; |
| 31876 | 31875 | const result_ty = Type.bool; |
| 31877 | | if (try sema.resolveMaybeUndefVal(operand)) |opt_val| { |
| 31876 | if (try sema.resolveValue(operand)) |opt_val| { |
| 31878 | 31877 | if (opt_val.isUndef(mod)) { |
| 31879 | 31878 | return mod.undefRef(result_ty); |
| 31880 | 31879 | } |
| ... | ... | @@ -31950,7 +31949,7 @@ fn analyzeIsNonErrComptimeOnly( |
| 31950 | 31949 | return .bool_true; |
| 31951 | 31950 | } |
| 31952 | 31951 | |
| 31953 | | const maybe_operand_val = try sema.resolveMaybeUndefVal(operand); |
| 31952 | const maybe_operand_val = try sema.resolveValue(operand); |
| 31954 | 31953 | |
| 31955 | 31954 | // exception if the error union error set is known to be empty, |
| 31956 | 31955 | // we allow the comparison but always make it comptime-known. |
| ... | ... | @@ -32171,7 +32170,7 @@ fn analyzeSlice( |
| 32171 | 32170 | const uncasted_end = try sema.analyzeArithmetic(block, .add, start, len, src, start_src, end_src, false); |
| 32172 | 32171 | break :end try sema.coerce(block, Type.usize, uncasted_end, end_src); |
| 32173 | 32172 | } else try sema.coerce(block, Type.usize, uncasted_end_opt, end_src); |
| 32174 | | if (try sema.resolveMaybeUndefVal(end)) |end_val| { |
| 32173 | if (try sema.resolveValue(end)) |end_val| { |
| 32175 | 32174 | const len_s_val = try mod.intValue( |
| 32176 | 32175 | Type.usize, |
| 32177 | 32176 | array_ty.arrayLenIncludingSentinel(mod), |
| ... | ... | @@ -32213,7 +32212,7 @@ fn analyzeSlice( |
| 32213 | 32212 | break :end try sema.coerce(block, Type.usize, uncasted_end, end_src); |
| 32214 | 32213 | } else try sema.coerce(block, Type.usize, uncasted_end_opt, end_src); |
| 32215 | 32214 | if (try sema.resolveDefinedValue(block, end_src, end)) |end_val| { |
| 32216 | | if (try sema.resolveMaybeUndefVal(ptr_or_slice)) |slice_val| { |
| 32215 | if (try sema.resolveValue(ptr_or_slice)) |slice_val| { |
| 32217 | 32216 | if (slice_val.isUndef(mod)) { |
| 32218 | 32217 | return sema.fail(block, src, "slice of undefined", .{}); |
| 32219 | 32218 | } |
| ... | ... | @@ -32265,7 +32264,7 @@ fn analyzeSlice( |
| 32265 | 32264 | const sentinel = s: { |
| 32266 | 32265 | if (sentinel_opt != .none) { |
| 32267 | 32266 | const casted = try sema.coerce(block, elem_ty, sentinel_opt, sentinel_src); |
| 32268 | | break :s try sema.resolveConstValue(block, sentinel_src, casted, .{ |
| 32267 | break :s try sema.resolveConstDefinedValue(block, sentinel_src, casted, .{ |
| 32269 | 32268 | .needed_comptime_reason = "slice sentinel must be comptime-known", |
| 32270 | 32269 | }); |
| 32271 | 32270 | } |
| ... | ... | @@ -32298,7 +32297,7 @@ fn analyzeSlice( |
| 32298 | 32297 | ); |
| 32299 | 32298 | } |
| 32300 | 32299 | checked_start_lte_end = true; |
| 32301 | | if (try sema.resolveMaybeUndefVal(new_ptr)) |ptr_val| sentinel_check: { |
| 32300 | if (try sema.resolveValue(new_ptr)) |ptr_val| sentinel_check: { |
| 32302 | 32301 | const expected_sentinel = sentinel orelse break :sentinel_check; |
| 32303 | 32302 | const start_int = start_val.getUnsignedInt(mod).?; |
| 32304 | 32303 | const end_int = end_val.getUnsignedInt(mod).?; |
| ... | ... | @@ -32387,7 +32386,7 @@ fn analyzeSlice( |
| 32387 | 32386 | }, |
| 32388 | 32387 | }); |
| 32389 | 32388 | |
| 32390 | | const opt_new_ptr_val = try sema.resolveMaybeUndefVal(new_ptr); |
| 32389 | const opt_new_ptr_val = try sema.resolveValue(new_ptr); |
| 32391 | 32390 | const new_ptr_val = opt_new_ptr_val orelse { |
| 32392 | 32391 | const result = try block.addBitCast(return_ty, new_ptr); |
| 32393 | 32392 | if (block.wantSafety()) { |
| ... | ... | @@ -32534,8 +32533,8 @@ fn cmpNumeric( |
| 32534 | 32533 | uncasted_rhs; |
| 32535 | 32534 | |
| 32536 | 32535 | const runtime_src: LazySrcLoc = src: { |
| 32537 | | if (try sema.resolveMaybeUndefVal(lhs)) |lhs_val| { |
| 32538 | | if (try sema.resolveMaybeUndefVal(rhs)) |rhs_val| { |
| 32536 | if (try sema.resolveValue(lhs)) |lhs_val| { |
| 32537 | if (try sema.resolveValue(rhs)) |rhs_val| { |
| 32539 | 32538 | // Compare ints: const vs. undefined (or vice versa) |
| 32540 | 32539 | 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)) { |
| 32541 | 32540 | if (try sema.compareIntsOnlyPossibleResult(try sema.resolveLazyValue(lhs_val), op, rhs_ty)) |res| { |
| ... | ... | @@ -32567,7 +32566,7 @@ fn cmpNumeric( |
| 32567 | 32566 | break :src rhs_src; |
| 32568 | 32567 | } |
| 32569 | 32568 | } else { |
| 32570 | | if (try sema.resolveMaybeUndefLazyVal(rhs)) |rhs_val| { |
| 32569 | if (try sema.resolveValueResolveLazy(rhs)) |rhs_val| { |
| 32571 | 32570 | if (!rhs_val.isUndef(mod) and (rhs_ty.isInt(mod) or rhs_ty_tag == .ComptimeInt) and lhs_ty.isInt(mod)) { |
| 32572 | 32571 | // Compare ints: var vs. const |
| 32573 | 32572 | if (try sema.compareIntsOnlyPossibleResult(try sema.resolveLazyValue(rhs_val), op.reverse(), lhs_ty)) |res| { |
| ... | ... | @@ -32634,7 +32633,7 @@ fn cmpNumeric( |
| 32634 | 32633 | var dest_float_type: ?Type = null; |
| 32635 | 32634 | |
| 32636 | 32635 | var lhs_bits: usize = undefined; |
| 32637 | | if (try sema.resolveMaybeUndefLazyVal(lhs)) |lhs_val| { |
| 32636 | if (try sema.resolveValueResolveLazy(lhs)) |lhs_val| { |
| 32638 | 32637 | if (lhs_val.isUndef(mod)) |
| 32639 | 32638 | return mod.undefRef(Type.bool); |
| 32640 | 32639 | if (lhs_val.isNan(mod)) switch (op) { |
| ... | ... | @@ -32692,7 +32691,7 @@ fn cmpNumeric( |
| 32692 | 32691 | } |
| 32693 | 32692 | |
| 32694 | 32693 | var rhs_bits: usize = undefined; |
| 32695 | | if (try sema.resolveMaybeUndefLazyVal(rhs)) |rhs_val| { |
| 32694 | if (try sema.resolveValueResolveLazy(rhs)) |rhs_val| { |
| 32696 | 32695 | if (rhs_val.isUndef(mod)) |
| 32697 | 32696 | return mod.undefRef(Type.bool); |
| 32698 | 32697 | if (rhs_val.isNan(mod)) switch (op) { |
| ... | ... | @@ -32884,8 +32883,8 @@ fn cmpVector( |
| 32884 | 32883 | }); |
| 32885 | 32884 | |
| 32886 | 32885 | const runtime_src: LazySrcLoc = src: { |
| 32887 | | if (try sema.resolveMaybeUndefVal(casted_lhs)) |lhs_val| { |
| 32888 | | if (try sema.resolveMaybeUndefVal(casted_rhs)) |rhs_val| { |
| 32886 | if (try sema.resolveValue(casted_lhs)) |lhs_val| { |
| 32887 | if (try sema.resolveValue(casted_rhs)) |rhs_val| { |
| 32889 | 32888 | if (lhs_val.isUndef(mod) or rhs_val.isUndef(mod)) { |
| 32890 | 32889 | return mod.undefRef(result_ty); |
| 32891 | 32890 | } |
| ... | ... | @@ -32910,7 +32909,7 @@ fn wrapOptional( |
| 32910 | 32909 | inst: Air.Inst.Ref, |
| 32911 | 32910 | inst_src: LazySrcLoc, |
| 32912 | 32911 | ) !Air.Inst.Ref { |
| 32913 | | if (try sema.resolveMaybeUndefVal(inst)) |val| { |
| 32912 | if (try sema.resolveValue(inst)) |val| { |
| 32914 | 32913 | return Air.internedToRef((try sema.mod.intern(.{ .opt = .{ |
| 32915 | 32914 | .ty = dest_ty.toIntern(), |
| 32916 | 32915 | .val = val.toIntern(), |
| ... | ... | @@ -32931,7 +32930,7 @@ fn wrapErrorUnionPayload( |
| 32931 | 32930 | const mod = sema.mod; |
| 32932 | 32931 | const dest_payload_ty = dest_ty.errorUnionPayload(mod); |
| 32933 | 32932 | const coerced = try sema.coerceExtra(block, dest_payload_ty, inst, inst_src, .{ .report_err = false }); |
| 32934 | | if (try sema.resolveMaybeUndefVal(coerced)) |val| { |
| 32933 | if (try sema.resolveValue(coerced)) |val| { |
| 32935 | 32934 | return Air.internedToRef((try mod.intern(.{ .error_union = .{ |
| 32936 | 32935 | .ty = dest_ty.toIntern(), |
| 32937 | 32936 | .val = .{ .payload = try val.intern(dest_payload_ty, mod) }, |
| ... | ... | @@ -32953,7 +32952,7 @@ fn wrapErrorUnionSet( |
| 32953 | 32952 | const ip = &mod.intern_pool; |
| 32954 | 32953 | const inst_ty = sema.typeOf(inst); |
| 32955 | 32954 | const dest_err_set_ty = dest_ty.errorUnionSet(mod); |
| 32956 | | if (try sema.resolveMaybeUndefVal(inst)) |val| { |
| 32955 | if (try sema.resolveValue(inst)) |val| { |
| 32957 | 32956 | const expected_name = mod.intern_pool.indexToKey(val.toIntern()).err.name; |
| 32958 | 32957 | switch (dest_err_set_ty.toIntern()) { |
| 32959 | 32958 | .anyerror_type => {}, |
| ... | ... | @@ -33015,7 +33014,7 @@ fn unionToTag( |
| 33015 | 33014 | if ((try sema.typeHasOnePossibleValue(enum_ty))) |opv| { |
| 33016 | 33015 | return Air.internedToRef(opv.toIntern()); |
| 33017 | 33016 | } |
| 33018 | | if (try sema.resolveMaybeUndefVal(un)) |un_val| { |
| 33017 | if (try sema.resolveValue(un)) |un_val| { |
| 33019 | 33018 | return Air.internedToRef(un_val.unionTag(mod).?.toIntern()); |
| 33020 | 33019 | } |
| 33021 | 33020 | try sema.requireRuntimeBlock(block, un_src, null); |
| ... | ... | @@ -33324,7 +33323,7 @@ fn resolvePeerTypes( |
| 33324 | 33323 | |
| 33325 | 33324 | for (instructions, peer_tys, peer_vals) |inst, *ty, *val| { |
| 33326 | 33325 | ty.* = sema.typeOf(inst); |
| 33327 | | val.* = try sema.resolveMaybeUndefVal(inst); |
| 33326 | val.* = try sema.resolveValue(inst); |
| 33328 | 33327 | } |
| 33329 | 33328 | |
| 33330 | 33329 | switch (try sema.resolvePeerTypesInner(block, src, peer_tys, peer_vals)) { |
| ... | ... | @@ -34379,7 +34378,7 @@ fn resolvePeerTypesInner( |
| 34379 | 34378 | }, |
| 34380 | 34379 | else => |e| return e, |
| 34381 | 34380 | }; |
| 34382 | | const coerced_val = (try sema.resolveMaybeUndefVal(coerced_inst)) orelse continue; |
| 34381 | const coerced_val = (try sema.resolveValue(coerced_inst)) orelse continue; |
| 34383 | 34382 | const existing = comptime_val orelse { |
| 34384 | 34383 | comptime_val = coerced_val; |
| 34385 | 34384 | continue; |
| ... | ... | @@ -35827,7 +35826,7 @@ fn semaStructFields( |
| 35827 | 35826 | }, |
| 35828 | 35827 | else => |e| return e, |
| 35829 | 35828 | }; |
| 35830 | | const default_val = (try sema.resolveMaybeUndefVal(coerced)) orelse { |
| 35829 | const default_val = (try sema.resolveValue(coerced)) orelse { |
| 35831 | 35830 | const init_src = mod.fieldSrcLoc(decl_index, .{ |
| 35832 | 35831 | .index = field_i, |
| 35833 | 35832 | .range = .value, |
| ... | ... | @@ -36270,7 +36269,7 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Key.Un |
| 36270 | 36269 | |
| 36271 | 36270 | fn semaUnionFieldVal(sema: *Sema, block: *Block, src: LazySrcLoc, int_tag_ty: Type, tag_ref: Air.Inst.Ref) CompileError!Value { |
| 36272 | 36271 | const coerced = try sema.coerce(block, int_tag_ty, tag_ref, src); |
| 36273 | | return sema.resolveConstValue(block, src, coerced, .{ |
| 36272 | return sema.resolveConstDefinedValue(block, src, coerced, .{ |
| 36274 | 36273 | .needed_comptime_reason = "enum tag value must be comptime-known", |
| 36275 | 36274 | }); |
| 36276 | 36275 | } |
| ... | ... | @@ -36828,7 +36827,7 @@ fn isComptimeKnown( |
| 36828 | 36827 | sema: *Sema, |
| 36829 | 36828 | inst: Air.Inst.Ref, |
| 36830 | 36829 | ) !bool { |
| 36831 | | return (try sema.resolveMaybeUndefVal(inst)) != null; |
| 36830 | return (try sema.resolveValue(inst)) != null; |
| 36832 | 36831 | } |
| 36833 | 36832 | |
| 36834 | 36833 | fn analyzeComptimeAlloc( |