| ... | ... | @@ -1086,7 +1086,7 @@ fn analyzeInlineBody( |
| 1086 | 1086 | // This control flow goes further up the stack. |
| 1087 | 1087 | return error.ComptimeBreak; |
| 1088 | 1088 | } |
| 1089 | | return try sema.resolveInst(break_inst.data.@"break".operand); |
| 1089 | return sema.resolveInst(break_inst.data.@"break".operand); |
| 1090 | 1090 | } |
| 1091 | 1091 | |
| 1092 | 1092 | /// Like `analyzeInlineBody`, but if the body does not break with a value, returns |
| ... | ... | @@ -1873,7 +1873,7 @@ fn analyzeBodyInner( |
| 1873 | 1873 | |
| 1874 | 1874 | const break_data = opt_break_data orelse break; |
| 1875 | 1875 | if (inst == break_data.block_inst) { |
| 1876 | | break :blk try sema.resolveInst(break_data.operand); |
| 1876 | break :blk sema.resolveInst(break_data.operand); |
| 1877 | 1877 | } else { |
| 1878 | 1878 | // `comptime_break_inst` preserved from `analyzeBodyInner` above. |
| 1879 | 1879 | return error.ComptimeBreak; |
| ... | ... | @@ -1894,7 +1894,7 @@ fn analyzeBodyInner( |
| 1894 | 1894 | extra.end + then_body.len, |
| 1895 | 1895 | extra.data.else_body_len, |
| 1896 | 1896 | ); |
| 1897 | | const uncasted_cond = try sema.resolveInst(extra.data.condition); |
| 1897 | const uncasted_cond = sema.resolveInst(extra.data.condition); |
| 1898 | 1898 | const cond = try sema.coerce(block, .bool, uncasted_cond, cond_src); |
| 1899 | 1899 | const cond_val = try sema.resolveConstDefinedValue( |
| 1900 | 1900 | block, |
| ... | ... | @@ -1920,7 +1920,7 @@ fn analyzeBodyInner( |
| 1920 | 1920 | const operand_src = block.src(.{ .node_offset_try_operand = inst_data.src_node }); |
| 1921 | 1921 | const extra = sema.code.extraData(Zir.Inst.Try, inst_data.payload_index); |
| 1922 | 1922 | const inline_body = sema.code.bodySlice(extra.end, extra.data.body_len); |
| 1923 | | const err_union = try sema.resolveInst(extra.data.operand); |
| 1923 | const err_union = sema.resolveInst(extra.data.operand); |
| 1924 | 1924 | const err_union_ty = sema.typeOf(err_union); |
| 1925 | 1925 | if (err_union_ty.zigTypeTag(zcu) != .error_union) { |
| 1926 | 1926 | return sema.failWithOwnedErrorMsg(block, msg: { |
| ... | ... | @@ -1946,7 +1946,7 @@ fn analyzeBodyInner( |
| 1946 | 1946 | const operand_src = block.src(.{ .node_offset_try_operand = inst_data.src_node }); |
| 1947 | 1947 | const extra = sema.code.extraData(Zir.Inst.Try, inst_data.payload_index); |
| 1948 | 1948 | const inline_body = sema.code.bodySlice(extra.end, extra.data.body_len); |
| 1949 | | const operand = try sema.resolveInst(extra.data.operand); |
| 1949 | const operand = sema.resolveInst(extra.data.operand); |
| 1950 | 1950 | const err_union = try sema.analyzeLoad(block, src, operand, operand_src); |
| 1951 | 1951 | const is_non_err_val = (try sema.resolveIsNonErrVal(block, operand_src, err_union)).?; |
| 1952 | 1952 | if (is_non_err_val.isUndef(zcu)) return sema.failWithUseOfUndef(block, operand_src, null); |
| ... | ... | @@ -1975,7 +1975,7 @@ fn analyzeBodyInner( |
| 1975 | 1975 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].defer_err_code; |
| 1976 | 1976 | const extra = sema.code.extraData(Zir.Inst.DeferErrCode, inst_data.payload_index).data; |
| 1977 | 1977 | const defer_body = sema.code.bodySlice(extra.index, extra.len); |
| 1978 | | const err_code = try sema.resolveInst(inst_data.err_code); |
| 1978 | const err_code = sema.resolveInst(inst_data.err_code); |
| 1979 | 1979 | try map.ensureSpaceForInstructions(sema.gpa, defer_body); |
| 1980 | 1980 | map.putAssumeCapacity(extra.remapped_err_code, err_code); |
| 1981 | 1981 | if (sema.analyzeBodyInner(block, defer_body)) { |
| ... | ... | @@ -2022,7 +2022,7 @@ fn analyzeBodyInner( |
| 2022 | 2022 | } |
| 2023 | 2023 | } |
| 2024 | 2024 | |
| 2025 | | pub fn resolveInstAllowNone(sema: *Sema, zir_ref: Zir.Inst.Ref) !Air.Inst.Ref { |
| 2025 | fn resolveInstAllowNone(sema: *Sema, zir_ref: Zir.Inst.Ref) Air.Inst.Ref { |
| 2026 | 2026 | if (zir_ref == .none) { |
| 2027 | 2027 | return .none; |
| 2028 | 2028 | } else { |
| ... | ... | @@ -2030,7 +2030,7 @@ pub fn resolveInstAllowNone(sema: *Sema, zir_ref: Zir.Inst.Ref) !Air.Inst.Ref { |
| 2030 | 2030 | } |
| 2031 | 2031 | } |
| 2032 | 2032 | |
| 2033 | | pub fn resolveInst(sema: *Sema, zir_ref: Zir.Inst.Ref) !Air.Inst.Ref { |
| 2033 | fn resolveInst(sema: *Sema, zir_ref: Zir.Inst.Ref) Air.Inst.Ref { |
| 2034 | 2034 | assert(zir_ref != .none); |
| 2035 | 2035 | if (zir_ref.toIndex()) |i| { |
| 2036 | 2036 | return sema.inst_map.get(i).?; |
| ... | ... | @@ -2047,7 +2047,7 @@ fn resolveConstBool( |
| 2047 | 2047 | zir_ref: Zir.Inst.Ref, |
| 2048 | 2048 | reason: ComptimeReason, |
| 2049 | 2049 | ) !bool { |
| 2050 | | const air_inst = try sema.resolveInst(zir_ref); |
| 2050 | const air_inst = sema.resolveInst(zir_ref); |
| 2051 | 2051 | const wanted_type: Type = .bool; |
| 2052 | 2052 | const coerced_inst = try sema.coerce(block, wanted_type, air_inst, src); |
| 2053 | 2053 | const val = try sema.resolveConstDefinedValue(block, src, coerced_inst, reason); |
| ... | ... | @@ -2063,7 +2063,7 @@ fn resolveConstString( |
| 2063 | 2063 | /// being comptime-resolved is that the block is being comptime-evaluated. |
| 2064 | 2064 | reason: ?ComptimeReason, |
| 2065 | 2065 | ) ![]u8 { |
| 2066 | | const air_inst = try sema.resolveInst(zir_ref); |
| 2066 | const air_inst = sema.resolveInst(zir_ref); |
| 2067 | 2067 | return sema.toConstString(block, src, air_inst, reason); |
| 2068 | 2068 | } |
| 2069 | 2069 | |
| ... | ... | @@ -2090,7 +2090,7 @@ pub fn resolveConstStringIntern( |
| 2090 | 2090 | zir_ref: Zir.Inst.Ref, |
| 2091 | 2091 | reason: ComptimeReason, |
| 2092 | 2092 | ) !InternPool.NullTerminatedString { |
| 2093 | | const air_inst = try sema.resolveInst(zir_ref); |
| 2093 | const air_inst = sema.resolveInst(zir_ref); |
| 2094 | 2094 | const wanted_type: Type = .slice_const_u8; |
| 2095 | 2095 | const coerced_inst = try sema.coerce(block, wanted_type, air_inst, src); |
| 2096 | 2096 | const val = try sema.resolveConstDefinedValue(block, src, coerced_inst, reason); |
| ... | ... | @@ -2098,7 +2098,7 @@ pub fn resolveConstStringIntern( |
| 2098 | 2098 | } |
| 2099 | 2099 | |
| 2100 | 2100 | fn resolveTypeOrPoison(sema: *Sema, block: *Block, src: LazySrcLoc, zir_ref: Zir.Inst.Ref) !?Type { |
| 2101 | | const air_inst = try sema.resolveInst(zir_ref); |
| 2101 | const air_inst = sema.resolveInst(zir_ref); |
| 2102 | 2102 | const ty = try sema.analyzeAsType(block, src, .type, air_inst); |
| 2103 | 2103 | if (ty.isGenericPoison()) return null; |
| 2104 | 2104 | return ty; |
| ... | ... | @@ -2192,7 +2192,7 @@ fn genericPoisonReason(sema: *Sema, block: *Block, ref: Zir.Inst.Ref) GenericPoi |
| 2192 | 2192 | // There are two cases here: the pointer type may already have been |
| 2193 | 2193 | // generic poison, or it may have been an anyopaque pointer. |
| 2194 | 2194 | const un_node = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 2195 | | const operand_ref = try sema.resolveInst(un_node.operand); |
| 2195 | const operand_ref = sema.resolveInst(un_node.operand); |
| 2196 | 2196 | const operand_val = operand_ref.toInterned() orelse return .unknown; |
| 2197 | 2197 | if (operand_val == .generic_poison_type) { |
| 2198 | 2198 | // The pointer was generic poison - keep looking. |
| ... | ... | @@ -2271,8 +2271,7 @@ pub fn setupErrorReturnTrace(sema: *Sema, block: *Block, last_arg_index: usize) |
| 2271 | 2271 | } |
| 2272 | 2272 | |
| 2273 | 2273 | /// Return the Value corresponding to a given AIR ref, or `null` if it refers to a runtime value. |
| 2274 | | /// TODO MLUGG: remove the error union return! |
| 2275 | | fn resolveValue(sema: *Sema, inst: Air.Inst.Ref) error{}!?Value { |
| 2274 | fn resolveValue(sema: *Sema, inst: Air.Inst.Ref) ?Value { |
| 2276 | 2275 | const zcu = sema.pt.zcu; |
| 2277 | 2276 | assert(inst != .none); |
| 2278 | 2277 | |
| ... | ... | @@ -2308,7 +2307,7 @@ pub fn resolveConstValue( |
| 2308 | 2307 | /// being comptime-resolved is that the block is being comptime-evaluated. |
| 2309 | 2308 | reason: ?ComptimeReason, |
| 2310 | 2309 | ) CompileError!Value { |
| 2311 | | return try sema.resolveValue(inst) orelse { |
| 2310 | return sema.resolveValue(inst) orelse { |
| 2312 | 2311 | return sema.failWithNeededComptime(block, src, reason); |
| 2313 | 2312 | }; |
| 2314 | 2313 | } |
| ... | ... | @@ -2322,7 +2321,7 @@ fn resolveDefinedValue( |
| 2322 | 2321 | ) CompileError!?Value { |
| 2323 | 2322 | const pt = sema.pt; |
| 2324 | 2323 | const zcu = pt.zcu; |
| 2325 | | const val = try sema.resolveValue(air_ref) orelse return null; |
| 2324 | const val = sema.resolveValue(air_ref) orelse return null; |
| 2326 | 2325 | if (val.isUndef(zcu)) return sema.failWithUseOfUndef(block, src, null); |
| 2327 | 2326 | return val; |
| 2328 | 2327 | } |
| ... | ... | @@ -2795,7 +2794,7 @@ fn resolveAlign( |
| 2795 | 2794 | src: LazySrcLoc, |
| 2796 | 2795 | zir_ref: Zir.Inst.Ref, |
| 2797 | 2796 | ) !Alignment { |
| 2798 | | const air_ref = try sema.resolveInst(zir_ref); |
| 2797 | const air_ref = sema.resolveInst(zir_ref); |
| 2799 | 2798 | return sema.analyzeAsAlign(block, src, air_ref); |
| 2800 | 2799 | } |
| 2801 | 2800 | |
| ... | ... | @@ -2807,7 +2806,7 @@ fn resolveInt( |
| 2807 | 2806 | dest_ty: Type, |
| 2808 | 2807 | reason: ComptimeReason, |
| 2809 | 2808 | ) !u64 { |
| 2810 | | const air_ref = try sema.resolveInst(zir_ref); |
| 2809 | const air_ref = sema.resolveInst(zir_ref); |
| 2811 | 2810 | return sema.analyzeAsInt(block, src, air_ref, dest_ty, reason); |
| 2812 | 2811 | } |
| 2813 | 2812 | |
| ... | ... | @@ -2886,7 +2885,7 @@ fn zirTupleDecl( |
| 2886 | 2885 | field_ty.* = field_type.toIntern(); |
| 2887 | 2886 | field_init.* = init: { |
| 2888 | 2887 | if (zir_field_init != .none) { |
| 2889 | | const uncoerced_field_init = try sema.resolveInst(zir_field_init); |
| 2888 | const uncoerced_field_init = sema.resolveInst(zir_field_init); |
| 2890 | 2889 | const coerced_field_init = try sema.coerce(block, field_type, uncoerced_field_init, init_src); |
| 2891 | 2890 | const field_init_val = try sema.resolveConstDefinedValue(block, init_src, coerced_field_init, .{ .simple = .tuple_field_default_value }); |
| 2892 | 2891 | if (field_init_val.canMutateComptimeVarState(zcu)) { |
| ... | ... | @@ -2959,8 +2958,8 @@ fn getCaptures( |
| 2959 | 2958 | capture.* = switch (zir_capture.unwrap()) { |
| 2960 | 2959 | .nested => |parent_idx| parent_captures.get(ip)[parent_idx], |
| 2961 | 2960 | .instruction_load => |ptr_inst| capture: { |
| 2962 | | const ptr_ref = try sema.resolveInst(ptr_inst.toRef()); |
| 2963 | | const ptr_val = try sema.resolveValue(ptr_ref) orelse { |
| 2961 | const ptr_ref = sema.resolveInst(ptr_inst.toRef()); |
| 2962 | const ptr_val = sema.resolveValue(ptr_ref) orelse { |
| 2964 | 2963 | break :capture .wrap(.{ .runtime = sema.typeOf(ptr_ref).childType(zcu).toIntern() }); |
| 2965 | 2964 | }; |
| 2966 | 2965 | // TODO: better source location |
| ... | ... | @@ -2974,8 +2973,8 @@ fn getCaptures( |
| 2974 | 2973 | break :capture .wrap(.{ .@"comptime" = loaded_val.toIntern() }); |
| 2975 | 2974 | }, |
| 2976 | 2975 | .instruction => |inst| capture: { |
| 2977 | | const air_ref = try sema.resolveInst(inst.toRef()); |
| 2978 | | if (try sema.resolveValue(air_ref)) |val| { |
| 2976 | const air_ref = sema.resolveInst(inst.toRef()); |
| 2977 | if (sema.resolveValue(air_ref)) |val| { |
| 2979 | 2978 | if (val.canMutateComptimeVarState(zcu)) { |
| 2980 | 2979 | const field_name = try ip.getOrPutString(gpa, io, pt.tid, zir_name_slice, .no_embedded_nulls); |
| 2981 | 2980 | return sema.failWithContainsReferenceToComptimeVar(block, type_src, field_name, "captured value", val); |
| ... | ... | @@ -3079,7 +3078,7 @@ fn zirRef(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins |
| 3079 | 3078 | defer tracy.end(); |
| 3080 | 3079 | |
| 3081 | 3080 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_tok; |
| 3082 | | const operand = try sema.resolveInst(inst_data.operand); |
| 3081 | const operand = sema.resolveInst(inst_data.operand); |
| 3083 | 3082 | return sema.analyzeRef(block, block.tokenOffset(inst_data.src_tok), operand); |
| 3084 | 3083 | } |
| 3085 | 3084 | |
| ... | ... | @@ -3088,7 +3087,7 @@ fn zirEnsureResultUsed(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compile |
| 3088 | 3087 | defer tracy.end(); |
| 3089 | 3088 | |
| 3090 | 3089 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 3091 | | const operand = try sema.resolveInst(inst_data.operand); |
| 3090 | const operand = sema.resolveInst(inst_data.operand); |
| 3092 | 3091 | const src = block.nodeOffset(inst_data.src_node); |
| 3093 | 3092 | |
| 3094 | 3093 | return sema.ensureResultUsed(block, sema.typeOf(operand), src); |
| ... | ... | @@ -3134,7 +3133,7 @@ fn zirEnsureResultNonError(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com |
| 3134 | 3133 | const pt = sema.pt; |
| 3135 | 3134 | const zcu = pt.zcu; |
| 3136 | 3135 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 3137 | | const operand = try sema.resolveInst(inst_data.operand); |
| 3136 | const operand = sema.resolveInst(inst_data.operand); |
| 3138 | 3137 | const src = block.nodeOffset(inst_data.src_node); |
| 3139 | 3138 | const operand_ty = sema.typeOf(operand); |
| 3140 | 3139 | switch (operand_ty.zigTypeTag(zcu)) { |
| ... | ... | @@ -3160,7 +3159,7 @@ fn zirEnsureErrUnionPayloadVoid(sema: *Sema, block: *Block, inst: Zir.Inst.Index |
| 3160 | 3159 | const zcu = pt.zcu; |
| 3161 | 3160 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 3162 | 3161 | const src = block.nodeOffset(inst_data.src_node); |
| 3163 | | const operand = try sema.resolveInst(inst_data.operand); |
| 3162 | const operand = sema.resolveInst(inst_data.operand); |
| 3164 | 3163 | const operand_ty = sema.typeOf(operand); |
| 3165 | 3164 | const err_union_ty = if (operand_ty.zigTypeTag(zcu) == .pointer) |
| 3166 | 3165 | operand_ty.childType(zcu) |
| ... | ... | @@ -3185,7 +3184,7 @@ fn zirIndexablePtrLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE |
| 3185 | 3184 | |
| 3186 | 3185 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 3187 | 3186 | const src = block.nodeOffset(inst_data.src_node); |
| 3188 | | const object = try sema.resolveInst(inst_data.operand); |
| 3187 | const object = sema.resolveInst(inst_data.operand); |
| 3189 | 3188 | |
| 3190 | 3189 | return indexablePtrLen(sema, block, src, object); |
| 3191 | 3190 | } |
| ... | ... | @@ -3331,7 +3330,7 @@ fn zirMakePtrConst(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro |
| 3331 | 3330 | const pt = sema.pt; |
| 3332 | 3331 | const zcu = pt.zcu; |
| 3333 | 3332 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 3334 | | const alloc = try sema.resolveInst(inst_data.operand); |
| 3333 | const alloc = sema.resolveInst(inst_data.operand); |
| 3335 | 3334 | const alloc_ty = sema.typeOf(alloc); |
| 3336 | 3335 | const ptr_info = alloc_ty.ptrInfo(zcu); |
| 3337 | 3336 | const elem_ty: Type = .fromInterned(ptr_info.child); |
| ... | ... | @@ -3340,7 +3339,7 @@ fn zirMakePtrConst(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro |
| 3340 | 3339 | // However, if the final constructed value does not reference comptime-mutable memory, we wish |
| 3341 | 3340 | // to promote it to an anon decl. |
| 3342 | 3341 | already_ct: { |
| 3343 | | const ptr_val = try sema.resolveValue(alloc) orelse break :already_ct; |
| 3342 | const ptr_val = sema.resolveValue(alloc) orelse break :already_ct; |
| 3344 | 3343 | |
| 3345 | 3344 | // If this was a comptime inferred alloc, then `storeToInferredAllocComptime` |
| 3346 | 3345 | // might have already done our job and created an anon decl ref. |
| ... | ... | @@ -3526,7 +3525,7 @@ fn resolveComptimeKnownAllocPtr(sema: *Sema, block: *Block, alloc: Air.Inst.Ref, |
| 3526 | 3525 | Air.Bin, |
| 3527 | 3526 | tmp_air.instructions.items(.data)[@intFromEnum(air_ptr)].ty_pl.payload, |
| 3528 | 3527 | ).data; |
| 3529 | | const idx_val = (try sema.resolveValue(data.rhs)).?; |
| 3528 | const idx_val = sema.resolveValue(data.rhs).?; |
| 3530 | 3529 | break :blk .{ |
| 3531 | 3530 | data.lhs, |
| 3532 | 3531 | .{ .elem = idx_val.toUnsignedInt(zcu) }, |
| ... | ... | @@ -3625,7 +3624,7 @@ fn resolveComptimeKnownAllocPtr(sema: *Sema, block: *Block, alloc: Air.Inst.Ref, |
| 3625 | 3624 | }, |
| 3626 | 3625 | .store, .store_safe => { |
| 3627 | 3626 | const air_ptr_inst = store_inst.data.bin_op.lhs.toIndex().?; |
| 3628 | | const store_val = (try sema.resolveValue(store_inst.data.bin_op.rhs)).?; |
| 3627 | const store_val = sema.resolveValue(store_inst.data.bin_op.rhs).?; |
| 3629 | 3628 | const new_ptr = ptr_mapping.get(air_ptr_inst).?; |
| 3630 | 3629 | try sema.storePtrVal(block, .unneeded, .fromInterned(new_ptr), store_val, store_val.typeOf(zcu)); |
| 3631 | 3630 | }, |
| ... | ... | @@ -3708,7 +3707,7 @@ fn makePtrConst(sema: *Sema, block: *Block, alloc: Air.Inst.Ref) CompileError!Ai |
| 3708 | 3707 | const const_ptr_ty = try sema.makePtrTyConst(alloc_ty); |
| 3709 | 3708 | |
| 3710 | 3709 | // Detect if a comptime value simply needs to have its type changed. |
| 3711 | | if (try sema.resolveValue(alloc)) |val| { |
| 3710 | if (sema.resolveValue(alloc)) |val| { |
| 3712 | 3711 | return Air.internedToRef((try sema.pt.getCoerced(val, const_ptr_ty)).toIntern()); |
| 3713 | 3712 | } |
| 3714 | 3713 | |
| ... | ... | @@ -3840,7 +3839,7 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com |
| 3840 | 3839 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 3841 | 3840 | const src = block.nodeOffset(inst_data.src_node); |
| 3842 | 3841 | const ty_src = block.src(.{ .node_offset_var_decl_ty = inst_data.src_node }); |
| 3843 | | const ptr = try sema.resolveInst(inst_data.operand); |
| 3842 | const ptr = sema.resolveInst(inst_data.operand); |
| 3844 | 3843 | const ptr_inst = ptr.toIndex().?; |
| 3845 | 3844 | const target = zcu.getTarget(); |
| 3846 | 3845 | |
| ... | ... | @@ -4005,7 +4004,7 @@ fn zirForLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. |
| 4005 | 4004 | |
| 4006 | 4005 | const arg_len_uncoerced = if (zir_arg_pair[1] == .none) l: { |
| 4007 | 4006 | // This argument is an indexable. |
| 4008 | | const object = try sema.resolveInst(zir_arg_pair[0]); |
| 4007 | const object = sema.resolveInst(zir_arg_pair[0]); |
| 4009 | 4008 | const object_ty = sema.typeOf(object); |
| 4010 | 4009 | if (!object_ty.isIndexable(zcu)) { |
| 4011 | 4010 | // Instead of using checkIndexable we customize this error. |
| ... | ... | @@ -4026,8 +4025,8 @@ fn zirForLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. |
| 4026 | 4025 | break :l try sema.fieldVal(block, arg_src, object, try ip.getOrPutString(gpa, io, pt.tid, "len", .no_embedded_nulls), arg_src); |
| 4027 | 4026 | } else l: { |
| 4028 | 4027 | // This argument is a range. |
| 4029 | | const range_start = try sema.resolveInst(zir_arg_pair[0]); |
| 4030 | | const range_end = try sema.resolveInst(zir_arg_pair[1]); |
| 4028 | const range_start = sema.resolveInst(zir_arg_pair[0]); |
| 4029 | const range_end = sema.resolveInst(zir_arg_pair[1]); |
| 4031 | 4030 | if (try sema.resolveDefinedValue(block, arg_src, range_start)) |start| { |
| 4032 | 4031 | if (try sema.valuesEqual(start, .zero_usize, .usize)) break :l range_end; |
| 4033 | 4032 | } |
| ... | ... | @@ -4077,7 +4076,7 @@ fn zirForLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. |
| 4077 | 4076 | const i: u32 = @intCast(i_usize); |
| 4078 | 4077 | if (zir_arg_pair[0] == .none) continue; |
| 4079 | 4078 | if (zir_arg_pair[1] != .none) continue; |
| 4080 | | const object = try sema.resolveInst(zir_arg_pair[0]); |
| 4079 | const object = sema.resolveInst(zir_arg_pair[0]); |
| 4081 | 4080 | const object_ty = sema.typeOf(object); |
| 4082 | 4081 | const arg_src = block.src(.{ .for_input = .{ |
| 4083 | 4082 | .for_node_offset = inst_data.src_node, |
| ... | ... | @@ -4132,7 +4131,7 @@ fn optEuBasePtrInit(sema: *Sema, block: *Block, ptr: Air.Inst.Ref, src: LazySrcL |
| 4132 | 4131 | |
| 4133 | 4132 | fn zirOptEuBasePtrInit(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 4134 | 4133 | const un_node = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 4135 | | const ptr = try sema.resolveInst(un_node.operand); |
| 4134 | const ptr = sema.resolveInst(un_node.operand); |
| 4136 | 4135 | try sema.ensureLayoutResolved(sema.typeOf(ptr).childType(sema.pt.zcu)); |
| 4137 | 4136 | return sema.optEuBasePtrInit(block, ptr, block.nodeOffset(un_node.src_node)); |
| 4138 | 4137 | } |
| ... | ... | @@ -4143,7 +4142,7 @@ fn zirCoercePtrElemTy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE |
| 4143 | 4142 | const pl_node = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 4144 | 4143 | const src = block.nodeOffset(pl_node.src_node); |
| 4145 | 4144 | const extra = sema.code.extraData(Zir.Inst.Bin, pl_node.payload_index).data; |
| 4146 | | const uncoerced_val = try sema.resolveInst(extra.rhs); |
| 4145 | const uncoerced_val = sema.resolveInst(extra.rhs); |
| 4147 | 4146 | const maybe_wrapped_ptr_ty = try sema.resolveTypeOrPoison(block, LazySrcLoc.unneeded, extra.lhs) orelse return uncoerced_val; |
| 4148 | 4147 | const ptr_ty = maybe_wrapped_ptr_ty.optEuBaseType(zcu); |
| 4149 | 4148 | assert(ptr_ty.zigTypeTag(zcu) == .pointer); // validated by a previous instruction |
| ... | ... | @@ -4259,7 +4258,7 @@ fn zirValidateConst(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr |
| 4259 | 4258 | |
| 4260 | 4259 | const un_node = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 4261 | 4260 | const src = block.nodeOffset(un_node.src_node); |
| 4262 | | const init_ref = try sema.resolveInst(un_node.operand); |
| 4261 | const init_ref = sema.resolveInst(un_node.operand); |
| 4263 | 4262 | if (!try sema.isComptimeKnown(init_ref)) { |
| 4264 | 4263 | return sema.failWithNeededComptime(block, src, null); |
| 4265 | 4264 | } |
| ... | ... | @@ -4402,7 +4401,7 @@ fn zirValidatePtrStructInit( |
| 4402 | 4401 | const instrs = sema.code.bodySlice(validate_extra.end, validate_extra.data.body_len); |
| 4403 | 4402 | const field_ptr_data = sema.code.instructions.items(.data)[@intFromEnum(instrs[0])].pl_node; |
| 4404 | 4403 | const field_ptr_extra = sema.code.extraData(Zir.Inst.Field, field_ptr_data.payload_index).data; |
| 4405 | | const object_ptr = try sema.resolveInst(field_ptr_extra.lhs); |
| 4404 | const object_ptr = sema.resolveInst(field_ptr_extra.lhs); |
| 4406 | 4405 | const agg_ty = sema.typeOf(object_ptr).childType(zcu).optEuBaseType(zcu); |
| 4407 | 4406 | switch (agg_ty.zigTypeTag(zcu)) { |
| 4408 | 4407 | .@"struct" => return sema.validateStructInit( |
| ... | ... | @@ -4571,7 +4570,7 @@ fn zirValidatePtrArrayInit( |
| 4571 | 4570 | const instrs = sema.code.bodySlice(validate_extra.end, validate_extra.data.body_len); |
| 4572 | 4571 | const first_elem_ptr_data = sema.code.instructions.items(.data)[@intFromEnum(instrs[0])].pl_node; |
| 4573 | 4572 | const elem_ptr_extra = sema.code.extraData(Zir.Inst.ElemPtrImm, first_elem_ptr_data.payload_index).data; |
| 4574 | | const array_ptr = try sema.resolveInst(elem_ptr_extra.ptr); |
| 4573 | const array_ptr = sema.resolveInst(elem_ptr_extra.ptr); |
| 4575 | 4574 | const array_ty = sema.typeOf(array_ptr).childType(zcu).optEuBaseType(zcu); |
| 4576 | 4575 | const array_len = array_ty.arrayLen(zcu); |
| 4577 | 4576 | |
| ... | ... | @@ -4631,7 +4630,7 @@ fn zirValidateDeref(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr |
| 4631 | 4630 | const zcu = pt.zcu; |
| 4632 | 4631 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 4633 | 4632 | const src = block.nodeOffset(inst_data.src_node); |
| 4634 | | const operand = try sema.resolveInst(inst_data.operand); |
| 4633 | const operand = sema.resolveInst(inst_data.operand); |
| 4635 | 4634 | const operand_ty = sema.typeOf(operand); |
| 4636 | 4635 | |
| 4637 | 4636 | if (operand_ty.zigTypeTag(zcu) != .pointer) { |
| ... | ... | @@ -4650,7 +4649,7 @@ fn zirValidateDeref(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr |
| 4650 | 4649 | return; |
| 4651 | 4650 | } |
| 4652 | 4651 | |
| 4653 | | if (try sema.resolveValue(operand)) |val| { |
| 4652 | if (sema.resolveValue(operand)) |val| { |
| 4654 | 4653 | if (val.isUndef(zcu)) { |
| 4655 | 4654 | return sema.fail(block, src, "cannot dereference undefined value", .{}); |
| 4656 | 4655 | } |
| ... | ... | @@ -4685,7 +4684,7 @@ fn zirValidateDestructure(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp |
| 4685 | 4684 | const extra = sema.code.extraData(Zir.Inst.ValidateDestructure, inst_data.payload_index).data; |
| 4686 | 4685 | const src = block.nodeOffset(inst_data.src_node); |
| 4687 | 4686 | const destructure_src = block.nodeOffset(extra.destructure_node); |
| 4688 | | const operand = try sema.resolveInst(extra.operand); |
| 4687 | const operand = sema.resolveInst(extra.operand); |
| 4689 | 4688 | const operand_ty = sema.typeOf(operand); |
| 4690 | 4689 | |
| 4691 | 4690 | if (!typeIsDestructurable(operand_ty, zcu)) { |
| ... | ... | @@ -4813,8 +4812,8 @@ fn zirStoreToInferredPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compi |
| 4813 | 4812 | const pl_node = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 4814 | 4813 | const src = block.nodeOffset(pl_node.src_node); |
| 4815 | 4814 | const bin = sema.code.extraData(Zir.Inst.Bin, pl_node.payload_index).data; |
| 4816 | | const ptr = try sema.resolveInst(bin.lhs); |
| 4817 | | const operand = try sema.resolveInst(bin.rhs); |
| 4815 | const ptr = sema.resolveInst(bin.lhs); |
| 4816 | const operand = sema.resolveInst(bin.rhs); |
| 4818 | 4817 | const ptr_inst = ptr.toIndex().?; |
| 4819 | 4818 | const air_datas = sema.air_instructions.items(.data); |
| 4820 | 4819 | |
| ... | ... | @@ -4860,7 +4859,7 @@ fn storeToInferredAllocComptime( |
| 4860 | 4859 | const operand_ty = sema.typeOf(operand); |
| 4861 | 4860 | // There will be only one store_to_inferred_ptr because we are running at comptime. |
| 4862 | 4861 | // The alloc will turn into a Decl or a ComptimeAlloc. |
| 4863 | | const operand_val = try sema.resolveValue(operand) orelse { |
| 4862 | const operand_val = sema.resolveValue(operand) orelse { |
| 4864 | 4863 | return sema.failWithNeededComptime(block, src, .{ .simple = .stored_to_comptime_var }); |
| 4865 | 4864 | }; |
| 4866 | 4865 | const alloc_ty = try pt.ptrType(.{ |
| ... | ... | @@ -4909,8 +4908,8 @@ fn zirStoreNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!v |
| 4909 | 4908 | const inst_data = zir_datas[@intFromEnum(inst)].pl_node; |
| 4910 | 4909 | const src = block.nodeOffset(inst_data.src_node); |
| 4911 | 4910 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 4912 | | const ptr = try sema.resolveInst(extra.lhs); |
| 4913 | | const operand = try sema.resolveInst(extra.rhs); |
| 4911 | const ptr = sema.resolveInst(extra.lhs); |
| 4912 | const operand = sema.resolveInst(extra.rhs); |
| 4914 | 4913 | |
| 4915 | 4914 | const is_ret = if (extra.lhs.toIndex()) |ptr_index| |
| 4916 | 4915 | zir_tags[@intFromEnum(ptr_index)] == .ret_ptr |
| ... | ... | @@ -5044,9 +5043,9 @@ fn zirCompileLog( |
| 5044 | 5043 | for (args, 0..) |arg_ref, i| { |
| 5045 | 5044 | if (i != 0) writer.writeAll(", ") catch return error.OutOfMemory; |
| 5046 | 5045 | |
| 5047 | | const arg = try sema.resolveInst(arg_ref); |
| 5046 | const arg = sema.resolveInst(arg_ref); |
| 5048 | 5047 | const arg_ty = sema.typeOf(arg); |
| 5049 | | if (try sema.resolveValue(arg)) |val| { |
| 5048 | if (sema.resolveValue(arg)) |val| { |
| 5050 | 5049 | writer.print("@as({f}, {f})", .{ |
| 5051 | 5050 | arg_ty.fmt(pt), val.fmtValueSema(pt, sema), |
| 5052 | 5051 | }) catch return error.OutOfMemory; |
| ... | ... | @@ -5094,7 +5093,7 @@ fn zirPanic(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void |
| 5094 | 5093 | |
| 5095 | 5094 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 5096 | 5095 | const src = block.nodeOffset(inst_data.src_node); |
| 5097 | | const msg_inst = try sema.resolveInst(inst_data.operand); |
| 5096 | const msg_inst = sema.resolveInst(inst_data.operand); |
| 5098 | 5097 | |
| 5099 | 5098 | const arg_src = block.builtinCallArgSrc(inst_data.src_node, 0); |
| 5100 | 5099 | const coerced_msg = try sema.coerce(block, .slice_const_u8, msg_inst, arg_src); |
| ... | ... | @@ -5464,7 +5463,7 @@ fn resolveBlockBody( |
| 5464 | 5463 | const break_data = sema.code.instructions.items(.data)[@intFromEnum(break_inst)].@"break"; |
| 5465 | 5464 | const extra = sema.code.extraData(Zir.Inst.Break, break_data.payload_index).data; |
| 5466 | 5465 | if (extra.block_inst == body_inst) { |
| 5467 | | return try sema.resolveInst(break_data.operand); |
| 5466 | return sema.resolveInst(break_data.operand); |
| 5468 | 5467 | } else { |
| 5469 | 5468 | return error.ComptimeBreak; |
| 5470 | 5469 | } |
| ... | ... | @@ -5555,7 +5554,7 @@ fn resolveAnalyzedBlock( |
| 5555 | 5554 | // Okay, we need a runtime block. If the value is comptime-known, the |
| 5556 | 5555 | // block should just return void, and we return the merge result |
| 5557 | 5556 | // directly. Otherwise, we can defer to the logic below. |
| 5558 | | if (try sema.resolveValue(merges.results.items[0])) |result_val| { |
| 5557 | if (sema.resolveValue(merges.results.items[0])) |result_val| { |
| 5559 | 5558 | // Create a block containing all instruction from the body. |
| 5560 | 5559 | try parent_block.instructions.append(gpa, merges.block_inst); |
| 5561 | 5560 | switch (block_tag) { |
| ... | ... | @@ -5714,7 +5713,7 @@ fn zirExport(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void |
| 5714 | 5713 | const ptr_src = block.builtinCallArgSrc(inst_data.src_node, 0); |
| 5715 | 5714 | const options_src = block.builtinCallArgSrc(inst_data.src_node, 1); |
| 5716 | 5715 | |
| 5717 | | const ptr = try sema.resolveInst(extra.exported); |
| 5716 | const ptr = sema.resolveInst(extra.exported); |
| 5718 | 5717 | const ptr_val = try sema.resolveConstDefinedValue(block, ptr_src, ptr, .{ .simple = .export_target }); |
| 5719 | 5718 | const ptr_ty = ptr_val.typeOf(zcu); |
| 5720 | 5719 | |
| ... | ... | @@ -5878,7 +5877,7 @@ fn zirBreak(sema: *Sema, start_block: *Block, inst: Zir.Inst.Index) CompileError |
| 5878 | 5877 | |
| 5879 | 5878 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].@"break"; |
| 5880 | 5879 | const extra = sema.code.extraData(Zir.Inst.Break, inst_data.payload_index).data; |
| 5881 | | const operand = try sema.resolveInst(inst_data.operand); |
| 5880 | const operand = sema.resolveInst(inst_data.operand); |
| 5882 | 5881 | const zir_block = extra.block_inst; |
| 5883 | 5882 | |
| 5884 | 5883 | var block = start_block; |
| ... | ... | @@ -5912,7 +5911,7 @@ fn zirSwitchContinue(sema: *Sema, start_block: *Block, inst: Zir.Inst.Index) Com |
| 5912 | 5911 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].@"break"; |
| 5913 | 5912 | const extra = sema.code.extraData(Zir.Inst.Break, inst_data.payload_index).data; |
| 5914 | 5913 | const operand_src = start_block.nodeOffset(extra.operand_src_node.unwrap().?); |
| 5915 | | const uncoerced_operand = try sema.resolveInst(inst_data.operand); |
| 5914 | const uncoerced_operand = sema.resolveInst(inst_data.operand); |
| 5916 | 5915 | const switch_inst = extra.block_inst; |
| 5917 | 5916 | |
| 5918 | 5917 | switch (sema.code.instructions.items(.tag)[@intFromEnum(switch_inst)]) { |
| ... | ... | @@ -5921,7 +5920,7 @@ fn zirSwitchContinue(sema: *Sema, start_block: *Block, inst: Zir.Inst.Index) Com |
| 5921 | 5920 | else => unreachable, // assertion failure |
| 5922 | 5921 | } |
| 5923 | 5922 | |
| 5924 | | const operand_ty = (try sema.resolveInst(switch_inst.toRef())).toType(); |
| 5923 | const operand_ty = (sema.resolveInst(switch_inst.toRef())).toType(); |
| 5925 | 5924 | const operand = try sema.coerce(start_block, operand_ty, uncoerced_operand, operand_src); |
| 5926 | 5925 | try sema.validateRuntimeValue(start_block, operand_src, operand); |
| 5927 | 5926 | |
| ... | ... | @@ -5988,7 +5987,7 @@ fn zirDbgVar( |
| 5988 | 5987 | air_tag: Air.Inst.Tag, |
| 5989 | 5988 | ) CompileError!void { |
| 5990 | 5989 | const str_op = sema.code.instructions.items(.data)[@intFromEnum(inst)].str_op; |
| 5991 | | const operand = try sema.resolveInst(str_op.operand); |
| 5990 | const operand = sema.resolveInst(str_op.operand); |
| 5992 | 5991 | const name = str_op.getStr(sema.code); |
| 5993 | 5992 | try sema.addDbgVar(block, operand, air_tag, name); |
| 5994 | 5993 | } |
| ... | ... | @@ -6012,7 +6011,7 @@ fn addDbgVar( |
| 6012 | 6011 | }; |
| 6013 | 6012 | if (val_ty.comptimeOnly(zcu)) return; |
| 6014 | 6013 | if (!val_ty.hasRuntimeBits(zcu)) return; |
| 6015 | | if (try sema.resolveValue(operand)) |operand_val| { |
| 6014 | if (sema.resolveValue(operand)) |operand_val| { |
| 6016 | 6015 | if (operand_val.canMutateComptimeVarState(zcu)) return; |
| 6017 | 6016 | } |
| 6018 | 6017 | |
| ... | ... | @@ -6151,7 +6150,7 @@ fn funcDeclSrcInst(sema: *Sema, func_inst: Air.Inst.Ref) !?InternPool.TrackedIns |
| 6151 | 6150 | const pt = sema.pt; |
| 6152 | 6151 | const zcu = pt.zcu; |
| 6153 | 6152 | const ip = &zcu.intern_pool; |
| 6154 | | const func_val = try sema.resolveValue(func_inst) orelse return null; |
| 6153 | const func_val = sema.resolveValue(func_inst) orelse return null; |
| 6155 | 6154 | if (func_val.isUndef(zcu)) return null; |
| 6156 | 6155 | const nav = switch (ip.indexToKey(func_val.toIntern())) { |
| 6157 | 6156 | .@"extern" => |e| e.owner_nav, |
| ... | ... | @@ -6323,9 +6322,9 @@ fn zirCall( |
| 6323 | 6322 | const pop_error_return_trace = extra.data.flags.pop_error_return_trace; |
| 6324 | 6323 | |
| 6325 | 6324 | const callee: ResolvedFieldCallee = switch (kind) { |
| 6326 | | .direct => .{ .direct = try sema.resolveInst(extra.data.callee) }, |
| 6325 | .direct => .{ .direct = sema.resolveInst(extra.data.callee) }, |
| 6327 | 6326 | .field => blk: { |
| 6328 | | const object_ptr = try sema.resolveInst(extra.data.obj_ptr); |
| 6327 | const object_ptr = sema.resolveInst(extra.data.obj_ptr); |
| 6329 | 6328 | const field_name = try zcu.intern_pool.getOrPutString( |
| 6330 | 6329 | gpa, |
| 6331 | 6330 | io, |
| ... | ... | @@ -7097,7 +7096,7 @@ fn analyzeCall( |
| 7097 | 7096 | |
| 7098 | 7097 | if (is_comptime) { |
| 7099 | 7098 | // We already emitted an error if the argument isn't comptime-known. |
| 7100 | | comptime_arg.* = (try sema.resolveValue(arg)).?.toIntern(); |
| 7099 | comptime_arg.* = sema.resolveValue(arg).?.toIntern(); |
| 7101 | 7100 | } else { |
| 7102 | 7101 | comptime_arg.* = .none; |
| 7103 | 7102 | if (is_noalias) { |
| ... | ... | @@ -7139,7 +7138,7 @@ fn analyzeCall( |
| 7139 | 7138 | }; |
| 7140 | 7139 | |
| 7141 | 7140 | ref_func: { |
| 7142 | | const runtime_func_val = try sema.resolveValue(runtime_func) orelse break :ref_func; |
| 7141 | const runtime_func_val = sema.resolveValue(runtime_func) orelse break :ref_func; |
| 7143 | 7142 | if (!ip.isFuncBody(runtime_func_val.toIntern())) break :ref_func; |
| 7144 | 7143 | const orig_fn_index = ip.unwrapCoercedFunc(runtime_func_val.toIntern()); |
| 7145 | 7144 | try sema.addReferenceEntry(block, call_src, .wrap(.{ .func = orig_fn_index })); |
| ... | ... | @@ -7285,14 +7284,14 @@ fn analyzeCall( |
| 7285 | 7284 | if (zcu.comp.config.incremental) break :m false; |
| 7286 | 7285 | if (!block.isComptime()) break :m false; |
| 7287 | 7286 | for (args) |a| { |
| 7288 | | const val = (try sema.resolveValue(a)).?; |
| 7287 | const val = sema.resolveValue(a).?; |
| 7289 | 7288 | if (val.canMutateComptimeVarState(zcu)) break :m false; |
| 7290 | 7289 | } |
| 7291 | 7290 | break :m true; |
| 7292 | 7291 | }; |
| 7293 | 7292 | const memoized_arg_values: []const InternPool.Index = if (want_memoize) arg_vals: { |
| 7294 | 7293 | const vals = try sema.arena.alloc(InternPool.Index, args.len); |
| 7295 | | for (vals, args) |*v, a| v.* = (try sema.resolveValue(a)).?.toIntern(); |
| 7294 | for (vals, args) |*v, a| v.* = sema.resolveValue(a).?.toIntern(); |
| 7296 | 7295 | break :arg_vals vals; |
| 7297 | 7296 | } else undefined; |
| 7298 | 7297 | if (want_memoize) memoize: { |
| ... | ... | @@ -7453,7 +7452,7 @@ fn analyzeCall( |
| 7453 | 7452 | return .unreachable_value; |
| 7454 | 7453 | } |
| 7455 | 7454 | |
| 7456 | | const maybe_opv: Air.Inst.Ref = if (try sema.resolveValue(result_raw)) |result_val| r: { |
| 7455 | const maybe_opv: Air.Inst.Ref = if (sema.resolveValue(result_raw)) |result_val| r: { |
| 7457 | 7456 | const val_resolved = try sema.resolveAdHocInferredErrorSet(block, call_src, result_val.toIntern()); |
| 7458 | 7457 | break :r Air.internedToRef(val_resolved); |
| 7459 | 7458 | } else r: { |
| ... | ... | @@ -7465,7 +7464,7 @@ fn analyzeCall( |
| 7465 | 7464 | }; |
| 7466 | 7465 | |
| 7467 | 7466 | if (block.isComptime()) { |
| 7468 | | const result_val = (try sema.resolveValue(maybe_opv)).?; |
| 7467 | const result_val = sema.resolveValue(maybe_opv).?; |
| 7469 | 7468 | if (want_memoize and sema.allow_memoize and !result_val.canMutateComptimeVarState(zcu)) { |
| 7470 | 7469 | _ = try pt.intern(.{ .memoized_call = .{ |
| 7471 | 7470 | .func = func_val.?.toIntern(), |
| ... | ... | @@ -7641,7 +7640,7 @@ fn zirArrayTypeSentinel(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compil |
| 7641 | 7640 | const len = try sema.resolveInt(block, len_src, extra.len, .usize, .{ .simple = .array_length }); |
| 7642 | 7641 | const elem_type = try sema.resolveType(block, elem_src, extra.elem_type); |
| 7643 | 7642 | try sema.validateArrayElemType(block, elem_type, elem_src); |
| 7644 | | const uncasted_sentinel = try sema.resolveInst(extra.sentinel); |
| 7643 | const uncasted_sentinel = sema.resolveInst(extra.sentinel); |
| 7645 | 7644 | const sentinel = try sema.coerce(block, elem_type, uncasted_sentinel, sentinel_src); |
| 7646 | 7645 | const sentinel_val = try sema.resolveConstDefinedValue(block, sentinel_src, sentinel, .{ .simple = .array_sentinel }); |
| 7647 | 7646 | if (sentinel_val.canMutateComptimeVarState(zcu)) { |
| ... | ... | @@ -7757,11 +7756,11 @@ fn zirIntFromError(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstD |
| 7757 | 7756 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; |
| 7758 | 7757 | const src = block.nodeOffset(extra.node); |
| 7759 | 7758 | const operand_src = block.builtinCallArgSrc(extra.node, 0); |
| 7760 | | const uncasted_operand = try sema.resolveInst(extra.operand); |
| 7759 | const uncasted_operand = sema.resolveInst(extra.operand); |
| 7761 | 7760 | const operand = try sema.coerce(block, .anyerror, uncasted_operand, operand_src); |
| 7762 | 7761 | const err_int_ty = try pt.errorIntType(); |
| 7763 | 7762 | |
| 7764 | | if (try sema.resolveValue(operand)) |val| { |
| 7763 | if (sema.resolveValue(operand)) |val| { |
| 7765 | 7764 | if (val.isUndef(zcu)) { |
| 7766 | 7765 | return pt.undefRef(err_int_ty); |
| 7767 | 7766 | } |
| ... | ... | @@ -7801,7 +7800,7 @@ fn zirErrorFromInt(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstD |
| 7801 | 7800 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; |
| 7802 | 7801 | const src = block.nodeOffset(extra.node); |
| 7803 | 7802 | const operand_src = block.builtinCallArgSrc(extra.node, 0); |
| 7804 | | const uncasted_operand = try sema.resolveInst(extra.operand); |
| 7803 | const uncasted_operand = sema.resolveInst(extra.operand); |
| 7805 | 7804 | const err_int_ty = try pt.errorIntType(); |
| 7806 | 7805 | const operand = try sema.coerce(block, err_int_ty, uncasted_operand, operand_src); |
| 7807 | 7806 | |
| ... | ... | @@ -7848,8 +7847,8 @@ fn zirMergeErrorSets(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr |
| 7848 | 7847 | const src = block.src(.{ .node_offset_bin_op = inst_data.src_node }); |
| 7849 | 7848 | const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node }); |
| 7850 | 7849 | const rhs_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node }); |
| 7851 | | const lhs = try sema.resolveInst(extra.lhs); |
| 7852 | | const rhs = try sema.resolveInst(extra.rhs); |
| 7850 | const lhs = sema.resolveInst(extra.lhs); |
| 7851 | const rhs = sema.resolveInst(extra.rhs); |
| 7853 | 7852 | if (sema.typeOf(lhs).zigTypeTag(zcu) == .bool and sema.typeOf(rhs).zigTypeTag(zcu) == .bool) { |
| 7854 | 7853 | const msg = msg: { |
| 7855 | 7854 | const msg = try sema.errMsg(lhs_src, "expected error set type, found 'bool'", .{}); |
| ... | ... | @@ -7984,7 +7983,7 @@ fn zirIntFromEnum(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 7984 | 7983 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 7985 | 7984 | const src = block.nodeOffset(inst_data.src_node); |
| 7986 | 7985 | const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0); |
| 7987 | | const operand = try sema.resolveInst(inst_data.operand); |
| 7986 | const operand = sema.resolveInst(inst_data.operand); |
| 7988 | 7987 | const operand_ty = sema.typeOf(operand); |
| 7989 | 7988 | |
| 7990 | 7989 | const enum_tag: Air.Inst.Ref = switch (operand_ty.zigTypeTag(zcu)) { |
| ... | ... | @@ -8018,7 +8017,7 @@ fn zirIntFromEnum(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 8018 | 8017 | }); |
| 8019 | 8018 | } |
| 8020 | 8019 | |
| 8021 | | if (try sema.resolveValue(enum_tag)) |enum_tag_val| { |
| 8020 | if (sema.resolveValue(enum_tag)) |enum_tag_val| { |
| 8022 | 8021 | if (enum_tag_val.isUndef(zcu)) return pt.undefRef(int_tag_ty); |
| 8023 | 8022 | return .fromValue(enum_tag_val.intFromEnum(zcu)); |
| 8024 | 8023 | } |
| ... | ... | @@ -8035,7 +8034,7 @@ fn zirEnumFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 8035 | 8034 | const src = block.nodeOffset(inst_data.src_node); |
| 8036 | 8035 | const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0); |
| 8037 | 8036 | const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu_opt, "@enumFromInt"); |
| 8038 | | const operand = try sema.resolveInst(extra.rhs); |
| 8037 | const operand = sema.resolveInst(extra.rhs); |
| 8039 | 8038 | const operand_ty = sema.typeOf(operand); |
| 8040 | 8039 | |
| 8041 | 8040 | if (dest_ty.zigTypeTag(zcu) != .@"enum") { |
| ... | ... | @@ -8044,7 +8043,7 @@ fn zirEnumFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 8044 | 8043 | try sema.ensureLayoutResolved(dest_ty); |
| 8045 | 8044 | _ = try sema.checkIntType(block, operand_src, operand_ty); |
| 8046 | 8045 | |
| 8047 | | if (try sema.resolveValue(operand)) |int_val| { |
| 8046 | if (sema.resolveValue(operand)) |int_val| { |
| 8048 | 8047 | if (dest_ty.isNonexhaustiveEnum(zcu)) { |
| 8049 | 8048 | const int_tag_ty = dest_ty.intTagType(zcu); |
| 8050 | 8049 | if (int_val.intFitsInType(int_tag_ty, null, zcu)) { |
| ... | ... | @@ -8099,7 +8098,7 @@ fn zirOptionalPayloadPtr( |
| 8099 | 8098 | defer tracy.end(); |
| 8100 | 8099 | |
| 8101 | 8100 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 8102 | | const optional_ptr = try sema.resolveInst(inst_data.operand); |
| 8101 | const optional_ptr = sema.resolveInst(inst_data.operand); |
| 8103 | 8102 | const src = block.nodeOffset(inst_data.src_node); |
| 8104 | 8103 | |
| 8105 | 8104 | const ptr_ty = sema.typeOf(optional_ptr); |
| ... | ... | @@ -8193,7 +8192,7 @@ fn zirOptionalPayload( |
| 8193 | 8192 | const zcu = pt.zcu; |
| 8194 | 8193 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 8195 | 8194 | const src = block.nodeOffset(inst_data.src_node); |
| 8196 | | const operand = try sema.resolveInst(inst_data.operand); |
| 8195 | const operand = sema.resolveInst(inst_data.operand); |
| 8197 | 8196 | const operand_ty = sema.typeOf(operand); |
| 8198 | 8197 | const result_ty = switch (operand_ty.zigTypeTag(zcu)) { |
| 8199 | 8198 | .optional => operand_ty.optionalChild(zcu), |
| ... | ... | @@ -8253,7 +8252,7 @@ fn zirErrUnionPayload( |
| 8253 | 8252 | const zcu = pt.zcu; |
| 8254 | 8253 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 8255 | 8254 | const src = block.nodeOffset(inst_data.src_node); |
| 8256 | | const operand = try sema.resolveInst(inst_data.operand); |
| 8255 | const operand = sema.resolveInst(inst_data.operand); |
| 8257 | 8256 | const operand_src = src; |
| 8258 | 8257 | const err_union_ty = sema.typeOf(operand); |
| 8259 | 8258 | if (err_union_ty.zigTypeTag(zcu) != .error_union) { |
| ... | ... | @@ -8309,7 +8308,7 @@ fn zirErrUnionPayloadPtr( |
| 8309 | 8308 | defer tracy.end(); |
| 8310 | 8309 | |
| 8311 | 8310 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 8312 | | const operand = try sema.resolveInst(inst_data.operand); |
| 8311 | const operand = sema.resolveInst(inst_data.operand); |
| 8313 | 8312 | const src = block.nodeOffset(inst_data.src_node); |
| 8314 | 8313 | |
| 8315 | 8314 | const ptr_ty = sema.typeOf(operand); |
| ... | ... | @@ -8402,7 +8401,7 @@ fn zirErrUnionCode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro |
| 8402 | 8401 | |
| 8403 | 8402 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 8404 | 8403 | const src = block.nodeOffset(inst_data.src_node); |
| 8405 | | const operand = try sema.resolveInst(inst_data.operand); |
| 8404 | const operand = sema.resolveInst(inst_data.operand); |
| 8406 | 8405 | return sema.analyzeErrUnionCode(block, src, operand); |
| 8407 | 8406 | } |
| 8408 | 8407 | |
| ... | ... | @@ -8438,7 +8437,7 @@ fn zirErrUnionCodePtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE |
| 8438 | 8437 | |
| 8439 | 8438 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 8440 | 8439 | const src = block.nodeOffset(inst_data.src_node); |
| 8441 | | const operand = try sema.resolveInst(inst_data.operand); |
| 8440 | const operand = sema.resolveInst(inst_data.operand); |
| 8442 | 8441 | return sema.analyzeErrUnionCodePtr(block, src, operand); |
| 8443 | 8442 | } |
| 8444 | 8443 | |
| ... | ... | @@ -9201,7 +9200,7 @@ fn analyzeAs( |
| 9201 | 9200 | ) CompileError!Air.Inst.Ref { |
| 9202 | 9201 | const pt = sema.pt; |
| 9203 | 9202 | const zcu = pt.zcu; |
| 9204 | | const operand = try sema.resolveInst(zir_operand); |
| 9203 | const operand = sema.resolveInst(zir_operand); |
| 9205 | 9204 | const dest_ty = try sema.resolveTypeOrPoison(block, src, zir_dest_type) orelse return operand; |
| 9206 | 9205 | switch (dest_ty.zigTypeTag(zcu)) { |
| 9207 | 9206 | .@"opaque" => return sema.fail(block, src, "cannot cast to opaque type '{f}'", .{dest_ty.fmt(pt)}), |
| ... | ... | @@ -9227,7 +9226,7 @@ fn zirIntFromPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! |
| 9227 | 9226 | const zcu = pt.zcu; |
| 9228 | 9227 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 9229 | 9228 | const ptr_src = block.builtinCallArgSrc(inst_data.src_node, 0); |
| 9230 | | const operand = try sema.resolveInst(inst_data.operand); |
| 9229 | const operand = sema.resolveInst(inst_data.operand); |
| 9231 | 9230 | const operand_ty = sema.typeOf(operand); |
| 9232 | 9231 | const ptr_ty = operand_ty.scalarType(zcu); |
| 9233 | 9232 | const is_vector = operand_ty.zigTypeTag(zcu) == .vector; |
| ... | ... | @@ -9238,7 +9237,7 @@ fn zirIntFromPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! |
| 9238 | 9237 | const len = if (is_vector) operand_ty.vectorLen(zcu) else undefined; |
| 9239 | 9238 | const dest_ty: Type = if (is_vector) try pt.vectorType(.{ .child = .usize_type, .len = len }) else .usize; |
| 9240 | 9239 | |
| 9241 | | if (try sema.resolveValue(operand)) |operand_val| ct: { |
| 9240 | if (sema.resolveValue(operand)) |operand_val| ct: { |
| 9242 | 9241 | if (!is_vector) { |
| 9243 | 9242 | if (operand_val.isUndef(zcu)) { |
| 9244 | 9243 | return .undef_usize; |
| ... | ... | @@ -9297,7 +9296,7 @@ fn zirFieldPtrLoad(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro |
| 9297 | 9296 | sema.code.nullTerminatedString(extra.field_name_start), |
| 9298 | 9297 | .no_embedded_nulls, |
| 9299 | 9298 | ); |
| 9300 | | const object_ptr = try sema.resolveInst(extra.lhs); |
| 9299 | const object_ptr = sema.resolveInst(extra.lhs); |
| 9301 | 9300 | return fieldPtrLoad(sema, block, src, object_ptr, field_name, field_name_src); |
| 9302 | 9301 | } |
| 9303 | 9302 | |
| ... | ... | @@ -9322,7 +9321,7 @@ fn zirFieldPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 9322 | 9321 | sema.code.nullTerminatedString(extra.field_name_start), |
| 9323 | 9322 | .no_embedded_nulls, |
| 9324 | 9323 | ); |
| 9325 | | const object_ptr = try sema.resolveInst(extra.lhs); |
| 9324 | const object_ptr = sema.resolveInst(extra.lhs); |
| 9326 | 9325 | return sema.fieldPtr(block, src, object_ptr, field_name, field_name_src, false); |
| 9327 | 9326 | } |
| 9328 | 9327 | |
| ... | ... | @@ -9347,7 +9346,7 @@ fn zirStructInitFieldPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compi |
| 9347 | 9346 | sema.code.nullTerminatedString(extra.field_name_start), |
| 9348 | 9347 | .no_embedded_nulls, |
| 9349 | 9348 | ); |
| 9350 | | const object_ptr = try sema.resolveInst(extra.lhs); |
| 9349 | const object_ptr = sema.resolveInst(extra.lhs); |
| 9351 | 9350 | const struct_ty = sema.typeOf(object_ptr).childType(zcu); |
| 9352 | 9351 | switch (struct_ty.zigTypeTag(zcu)) { |
| 9353 | 9352 | .@"struct", .@"union" => { |
| ... | ... | @@ -9367,7 +9366,7 @@ fn zirFieldPtrNamedLoad(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compil |
| 9367 | 9366 | const src = block.nodeOffset(inst_data.src_node); |
| 9368 | 9367 | const field_name_src = block.builtinCallArgSrc(inst_data.src_node, 1); |
| 9369 | 9368 | const extra = sema.code.extraData(Zir.Inst.FieldNamed, inst_data.payload_index).data; |
| 9370 | | const object_ptr = try sema.resolveInst(extra.lhs); |
| 9369 | const object_ptr = sema.resolveInst(extra.lhs); |
| 9371 | 9370 | const field_name = try sema.resolveConstStringIntern(block, field_name_src, extra.field_name, .{ .simple = .field_name }); |
| 9372 | 9371 | return fieldPtrLoad(sema, block, src, object_ptr, field_name, field_name_src); |
| 9373 | 9372 | } |
| ... | ... | @@ -9380,7 +9379,7 @@ fn zirFieldPtrNamed(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr |
| 9380 | 9379 | const src = block.nodeOffset(inst_data.src_node); |
| 9381 | 9380 | const field_name_src = block.builtinCallArgSrc(inst_data.src_node, 1); |
| 9382 | 9381 | const extra = sema.code.extraData(Zir.Inst.FieldNamed, inst_data.payload_index).data; |
| 9383 | | const object_ptr = try sema.resolveInst(extra.lhs); |
| 9382 | const object_ptr = sema.resolveInst(extra.lhs); |
| 9384 | 9383 | const field_name = try sema.resolveConstStringIntern(block, field_name_src, extra.field_name, .{ .simple = .field_name }); |
| 9385 | 9384 | return sema.fieldPtr(block, src, object_ptr, field_name, field_name_src, false); |
| 9386 | 9385 | } |
| ... | ... | @@ -9395,7 +9394,7 @@ fn zirIntCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 9395 | 9394 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 9396 | 9395 | |
| 9397 | 9396 | const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu_opt, "@intCast"); |
| 9398 | | const operand = try sema.resolveInst(extra.rhs); |
| 9397 | const operand = sema.resolveInst(extra.rhs); |
| 9399 | 9398 | |
| 9400 | 9399 | return sema.intCast(block, block.nodeOffset(inst_data.src_node), dest_ty, src, operand, operand_src); |
| 9401 | 9400 | } |
| ... | ... | @@ -9470,7 +9469,7 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 9470 | 9469 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 9471 | 9470 | |
| 9472 | 9471 | const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu_opt, "@bitCast"); |
| 9473 | | const operand = try sema.resolveInst(extra.rhs); |
| 9472 | const operand = sema.resolveInst(extra.rhs); |
| 9474 | 9473 | const operand_ty = sema.typeOf(operand); |
| 9475 | 9474 | switch (dest_ty.zigTypeTag(zcu)) { |
| 9476 | 9475 | .@"anyframe", |
| ... | ... | @@ -9638,7 +9637,7 @@ fn zirFloatCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 9638 | 9637 | const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu_opt, "@floatCast"); |
| 9639 | 9638 | const dest_scalar_ty = dest_ty.scalarType(zcu); |
| 9640 | 9639 | |
| 9641 | | const operand = try sema.resolveInst(extra.rhs); |
| 9640 | const operand = sema.resolveInst(extra.rhs); |
| 9642 | 9641 | const operand_ty = sema.typeOf(operand); |
| 9643 | 9642 | const operand_scalar_ty = operand_ty.scalarType(zcu); |
| 9644 | 9643 | |
| ... | ... | @@ -9667,7 +9666,7 @@ fn zirFloatCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 9667 | 9666 | ), |
| 9668 | 9667 | } |
| 9669 | 9668 | |
| 9670 | | if (try sema.resolveValue(operand)) |operand_val| { |
| 9669 | if (sema.resolveValue(operand)) |operand_val| { |
| 9671 | 9670 | if (!is_vector) { |
| 9672 | 9671 | return Air.internedToRef((try operand_val.floatCast(dest_ty, pt)).toIntern()); |
| 9673 | 9672 | } |
| ... | ... | @@ -9699,8 +9698,8 @@ fn zirElemVal(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 9699 | 9698 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 9700 | 9699 | const src = block.nodeOffset(inst_data.src_node); |
| 9701 | 9700 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 9702 | | const array = try sema.resolveInst(extra.lhs); |
| 9703 | | const elem_index = try sema.resolveInst(extra.rhs); |
| 9701 | const array = sema.resolveInst(extra.lhs); |
| 9702 | const elem_index = sema.resolveInst(extra.rhs); |
| 9704 | 9703 | return sema.elemVal(block, src, array, elem_index, src, false); |
| 9705 | 9704 | } |
| 9706 | 9705 | |
| ... | ... | @@ -9712,8 +9711,8 @@ fn zirElemPtrLoad(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 9712 | 9711 | const src = block.nodeOffset(inst_data.src_node); |
| 9713 | 9712 | const elem_index_src = block.src(.{ .node_offset_array_access_index = inst_data.src_node }); |
| 9714 | 9713 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 9715 | | const array_ptr = try sema.resolveInst(extra.lhs); |
| 9716 | | const uncoerced_elem_index = try sema.resolveInst(extra.rhs); |
| 9714 | const array_ptr = sema.resolveInst(extra.lhs); |
| 9715 | const uncoerced_elem_index = sema.resolveInst(extra.rhs); |
| 9717 | 9716 | if (try sema.resolveDefinedValue(block, src, array_ptr)) |array_ptr_val| { |
| 9718 | 9717 | const array_ptr_ty = sema.typeOf(array_ptr); |
| 9719 | 9718 | if (try sema.pointerDeref(block, src, array_ptr_val, array_ptr_ty)) |array_val| { |
| ... | ... | @@ -9731,7 +9730,7 @@ fn zirElemValImm(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! |
| 9731 | 9730 | defer tracy.end(); |
| 9732 | 9731 | |
| 9733 | 9732 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].elem_val_imm; |
| 9734 | | const array = try sema.resolveInst(inst_data.operand); |
| 9733 | const array = sema.resolveInst(inst_data.operand); |
| 9735 | 9734 | const elem_index = try sema.pt.intRef(.usize, inst_data.idx); |
| 9736 | 9735 | return sema.elemVal(block, LazySrcLoc.unneeded, array, elem_index, LazySrcLoc.unneeded, false); |
| 9737 | 9736 | } |
| ... | ... | @@ -9745,8 +9744,8 @@ fn zirElemPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 9745 | 9744 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 9746 | 9745 | const src = block.nodeOffset(inst_data.src_node); |
| 9747 | 9746 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 9748 | | const array_ptr = try sema.resolveInst(extra.lhs); |
| 9749 | | const elem_index = try sema.resolveInst(extra.rhs); |
| 9747 | const array_ptr = sema.resolveInst(extra.lhs); |
| 9748 | const elem_index = sema.resolveInst(extra.rhs); |
| 9750 | 9749 | const indexable_ty = sema.typeOf(array_ptr); |
| 9751 | 9750 | if (indexable_ty.zigTypeTag(zcu) != .pointer) { |
| 9752 | 9751 | const capture_src = block.src(.{ .for_capture_from_input = inst_data.src_node }); |
| ... | ... | @@ -9775,8 +9774,8 @@ fn zirElemPtrNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 9775 | 9774 | const src = block.nodeOffset(inst_data.src_node); |
| 9776 | 9775 | const elem_index_src = block.src(.{ .node_offset_array_access_index = inst_data.src_node }); |
| 9777 | 9776 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 9778 | | const array_ptr = try sema.resolveInst(extra.lhs); |
| 9779 | | const uncoerced_elem_index = try sema.resolveInst(extra.rhs); |
| 9777 | const array_ptr = sema.resolveInst(extra.lhs); |
| 9778 | const uncoerced_elem_index = sema.resolveInst(extra.rhs); |
| 9780 | 9779 | const elem_index = try sema.coerce(block, .usize, uncoerced_elem_index, elem_index_src); |
| 9781 | 9780 | return sema.elemPtr(block, src, array_ptr, elem_index, elem_index_src, false, true); |
| 9782 | 9781 | } |
| ... | ... | @@ -9790,7 +9789,7 @@ fn zirArrayInitElemPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compile |
| 9790 | 9789 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 9791 | 9790 | const src = block.nodeOffset(inst_data.src_node); |
| 9792 | 9791 | const extra = sema.code.extraData(Zir.Inst.ElemPtrImm, inst_data.payload_index).data; |
| 9793 | | const array_ptr = try sema.resolveInst(extra.ptr); |
| 9792 | const array_ptr = sema.resolveInst(extra.ptr); |
| 9794 | 9793 | const elem_index = try pt.intRef(.usize, extra.index); |
| 9795 | 9794 | const array_ty = sema.typeOf(array_ptr).childType(zcu); |
| 9796 | 9795 | switch (array_ty.zigTypeTag(zcu)) { |
| ... | ... | @@ -9809,8 +9808,8 @@ fn zirSliceStart(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! |
| 9809 | 9808 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 9810 | 9809 | const src = block.nodeOffset(inst_data.src_node); |
| 9811 | 9810 | const extra = sema.code.extraData(Zir.Inst.SliceStart, inst_data.payload_index).data; |
| 9812 | | const array_ptr = try sema.resolveInst(extra.lhs); |
| 9813 | | const start = try sema.resolveInst(extra.start); |
| 9811 | const array_ptr = sema.resolveInst(extra.lhs); |
| 9812 | const start = sema.resolveInst(extra.start); |
| 9814 | 9813 | const ptr_src = block.src(.{ .node_offset_slice_ptr = inst_data.src_node }); |
| 9815 | 9814 | const start_src = block.src(.{ .node_offset_slice_start = inst_data.src_node }); |
| 9816 | 9815 | const end_src = block.src(.{ .node_offset_slice_end = inst_data.src_node }); |
| ... | ... | @@ -9825,9 +9824,9 @@ fn zirSliceEnd(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 9825 | 9824 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 9826 | 9825 | const src = block.nodeOffset(inst_data.src_node); |
| 9827 | 9826 | const extra = sema.code.extraData(Zir.Inst.SliceEnd, inst_data.payload_index).data; |
| 9828 | | const array_ptr = try sema.resolveInst(extra.lhs); |
| 9829 | | const start = try sema.resolveInst(extra.start); |
| 9830 | | const end = try sema.resolveInst(extra.end); |
| 9827 | const array_ptr = sema.resolveInst(extra.lhs); |
| 9828 | const start = sema.resolveInst(extra.start); |
| 9829 | const end = sema.resolveInst(extra.end); |
| 9831 | 9830 | const ptr_src = block.src(.{ .node_offset_slice_ptr = inst_data.src_node }); |
| 9832 | 9831 | const start_src = block.src(.{ .node_offset_slice_start = inst_data.src_node }); |
| 9833 | 9832 | const end_src = block.src(.{ .node_offset_slice_end = inst_data.src_node }); |
| ... | ... | @@ -9843,10 +9842,10 @@ fn zirSliceSentinel(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr |
| 9843 | 9842 | const src = block.nodeOffset(inst_data.src_node); |
| 9844 | 9843 | const sentinel_src = block.src(.{ .node_offset_slice_sentinel = inst_data.src_node }); |
| 9845 | 9844 | const extra = sema.code.extraData(Zir.Inst.SliceSentinel, inst_data.payload_index).data; |
| 9846 | | const array_ptr = try sema.resolveInst(extra.lhs); |
| 9847 | | const start = try sema.resolveInst(extra.start); |
| 9848 | | const end: Air.Inst.Ref = if (extra.end == .none) .none else try sema.resolveInst(extra.end); |
| 9849 | | const sentinel = try sema.resolveInst(extra.sentinel); |
| 9845 | const array_ptr = sema.resolveInst(extra.lhs); |
| 9846 | const start = sema.resolveInst(extra.start); |
| 9847 | const end: Air.Inst.Ref = if (extra.end == .none) .none else sema.resolveInst(extra.end); |
| 9848 | const sentinel = sema.resolveInst(extra.sentinel); |
| 9850 | 9849 | const ptr_src = block.src(.{ .node_offset_slice_ptr = inst_data.src_node }); |
| 9851 | 9850 | const start_src = block.src(.{ .node_offset_slice_start = inst_data.src_node }); |
| 9852 | 9851 | const end_src = block.src(.{ .node_offset_slice_end = inst_data.src_node }); |
| ... | ... | @@ -9861,10 +9860,10 @@ fn zirSliceLength(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 9861 | 9860 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 9862 | 9861 | const src = block.nodeOffset(inst_data.src_node); |
| 9863 | 9862 | const extra = sema.code.extraData(Zir.Inst.SliceLength, inst_data.payload_index).data; |
| 9864 | | const array_ptr = try sema.resolveInst(extra.lhs); |
| 9865 | | const start = try sema.resolveInst(extra.start); |
| 9866 | | const len = try sema.resolveInst(extra.len); |
| 9867 | | const sentinel = if (extra.sentinel == .none) .none else try sema.resolveInst(extra.sentinel); |
| 9863 | const array_ptr = sema.resolveInst(extra.lhs); |
| 9864 | const start = sema.resolveInst(extra.start); |
| 9865 | const len = sema.resolveInst(extra.len); |
| 9866 | const sentinel = if (extra.sentinel == .none) .none else sema.resolveInst(extra.sentinel); |
| 9868 | 9867 | const ptr_src = block.src(.{ .node_offset_slice_ptr = inst_data.src_node }); |
| 9869 | 9868 | const start_src = block.src(.{ .node_offset_slice_start = extra.start_src_node_offset }); |
| 9870 | 9869 | const end_src = block.src(.{ .node_offset_slice_end = inst_data.src_node }); |
| ... | ... | @@ -9892,7 +9891,7 @@ fn zirSliceSentinelTy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE |
| 9892 | 9891 | // This is like the logic in `analyzeSlice`; since we've evaluated the LHS as an lvalue, we will |
| 9893 | 9892 | // have a double pointer if it was already a pointer. |
| 9894 | 9893 | |
| 9895 | | const lhs_ptr_ty = sema.typeOf(try sema.resolveInst(inst_data.operand)); |
| 9894 | const lhs_ptr_ty = sema.typeOf(sema.resolveInst(inst_data.operand)); |
| 9896 | 9895 | const lhs_ty = switch (lhs_ptr_ty.zigTypeTag(zcu)) { |
| 9897 | 9896 | .pointer => lhs_ptr_ty.childType(zcu), |
| 9898 | 9897 | else => return sema.fail(block, ptr_src, "expected pointer, found '{f}'", .{lhs_ptr_ty.fmt(pt)}), |
| ... | ... | @@ -9972,7 +9971,7 @@ fn zirSwitchBlockErrUnion(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp |
| 9972 | 9971 | // Lastly, we analyze the error prong(s) as a regular switch. |
| 9973 | 9972 | |
| 9974 | 9973 | const raw_switch_operand, const non_err_cond, const non_err_hint = non_err: { |
| 9975 | | const eu_maybe_ptr = try sema.resolveInst(zir_switch.main_operand); |
| 9974 | const eu_maybe_ptr = sema.resolveInst(zir_switch.main_operand); |
| 9976 | 9975 | const err_union_ty: Type = err_union_ty: { |
| 9977 | 9976 | const raw_operand_ty = sema.typeOf(eu_maybe_ptr); |
| 9978 | 9977 | if (!non_err_case.operand_is_ref) break :err_union_ty raw_operand_ty; |
| ... | ... | @@ -10106,7 +10105,7 @@ fn zirSwitchBlock( |
| 10106 | 10105 | defer child_block.instructions.deinit(sema.gpa); |
| 10107 | 10106 | defer merges.deinit(sema.gpa); |
| 10108 | 10107 | |
| 10109 | | const raw_operand = try sema.resolveInst(zir_switch.main_operand); |
| 10108 | const raw_operand = sema.resolveInst(zir_switch.main_operand); |
| 10110 | 10109 | const validated_switch = try sema.validateSwitchBlock(block, raw_operand, operand_is_ref, inst, &zir_switch); |
| 10111 | 10110 | const maybe_ref = try sema.analyzeSwitchBlock(block, &child_block, raw_operand, operand_is_ref, merges, inst, &zir_switch, &validated_switch); |
| 10112 | 10111 | return maybe_ref orelse { |
| ... | ... | @@ -10234,7 +10233,7 @@ fn analyzeSwitchBlock( |
| 10234 | 10233 | if (extra.block_inst != switch_inst) return error.ComptimeBreak; |
| 10235 | 10234 | // This is a `switch_continue` targeting this block. Change the operand and start over. |
| 10236 | 10235 | const new_operand_src = child_block.nodeOffset(extra.operand_src_node.unwrap().?); |
| 10237 | | const new_operand_uncoerced = try sema.resolveInst(break_inst.data.@"break".operand); |
| 10236 | const new_operand_uncoerced = sema.resolveInst(break_inst.data.@"break".operand); |
| 10238 | 10237 | const new_operand = try sema.coerce(child_block, raw_operand_ty, new_operand_uncoerced, new_operand_src); |
| 10239 | 10238 | |
| 10240 | 10239 | try sema.emitBackwardBranch(child_block, src); |
| ... | ... | @@ -12641,7 +12640,7 @@ fn resolveSwitchItem( |
| 12641 | 12640 | // We allow prongs with errors which are not part of the error set |
| 12642 | 12641 | // being switched on if their prong body is `=> comptime unreachable,`. |
| 12643 | 12642 | switch (try sema.coerceInMemoryAllowedErrorSets(block, item_ty, uncoerced_ty, item_src, item_src)) { |
| 12644 | | .ok => if (try sema.resolveValue(uncoerced)) |uncoerced_val| { |
| 12643 | .ok => if (sema.resolveValue(uncoerced)) |uncoerced_val| { |
| 12645 | 12644 | break :item_ref try sema.coerceInMemory(uncoerced_val, item_ty); |
| 12646 | 12645 | }, |
| 12647 | 12646 | .missing_error => if (prong_is_comptime_unreach) { |
| ... | ... | @@ -12805,7 +12804,7 @@ fn maybeErrorUnwrap( |
| 12805 | 12804 | }, |
| 12806 | 12805 | .panic => { |
| 12807 | 12806 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 12808 | | const msg_inst = try sema.resolveInst(inst_data.operand); |
| 12807 | const msg_inst = sema.resolveInst(inst_data.operand); |
| 12809 | 12808 | |
| 12810 | 12809 | const panic_fn = try getBuiltin(sema, operand_src, .@"panic.call"); |
| 12811 | 12810 | const args: [2]Air.Inst.Ref = .{ msg_inst, .null_value }; |
| ... | ... | @@ -12828,7 +12827,7 @@ fn maybeErrorUnwrapCondbr(sema: *Sema, block: *Block, body: []const Zir.Inst.Ind |
| 12828 | 12827 | if (sema.code.instructions.items(.tag)[@intFromEnum(index)] != .is_non_err) return; |
| 12829 | 12828 | |
| 12830 | 12829 | const err_inst_data = sema.code.instructions.items(.data)[@intFromEnum(index)].un_node; |
| 12831 | | const err_operand = try sema.resolveInst(err_inst_data.operand); |
| 12830 | const err_operand = sema.resolveInst(err_inst_data.operand); |
| 12832 | 12831 | const operand_ty = sema.typeOf(err_operand); |
| 12833 | 12832 | if (operand_ty.zigTypeTag(zcu) == .error_set) { |
| 12834 | 12833 | try sema.maybeErrorUnwrapComptime(block, body, err_operand); |
| ... | ... | @@ -12960,7 +12959,7 @@ fn zirImport(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. |
| 12960 | 12959 | .zon => { |
| 12961 | 12960 | const res_ty: InternPool.Index = b: { |
| 12962 | 12961 | if (extra.res_ty == .none) break :b .none; |
| 12963 | | const res_ty_inst = try sema.resolveInst(extra.res_ty); |
| 12962 | const res_ty_inst = sema.resolveInst(extra.res_ty); |
| 12964 | 12963 | const res_ty = try sema.analyzeAsType(block, operand_src, .type, res_ty_inst); |
| 12965 | 12964 | if (res_ty.isGenericPoison()) break :b .none; |
| 12966 | 12965 | break :b res_ty.toIntern(); |
| ... | ... | @@ -13048,8 +13047,8 @@ fn zirShl( |
| 13048 | 13047 | const zcu = pt.zcu; |
| 13049 | 13048 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 13050 | 13049 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 13051 | | const lhs = try sema.resolveInst(extra.lhs); |
| 13052 | | const rhs = try sema.resolveInst(extra.rhs); |
| 13050 | const lhs = sema.resolveInst(extra.lhs); |
| 13051 | const rhs = sema.resolveInst(extra.rhs); |
| 13053 | 13052 | const lhs_ty = sema.typeOf(lhs); |
| 13054 | 13053 | const rhs_ty = sema.typeOf(rhs); |
| 13055 | 13054 | |
| ... | ... | @@ -13075,8 +13074,8 @@ fn zirShl( |
| 13075 | 13074 | // we already know `scalar_rhs_ty` is valid for `.shl` -- we only need to validate for `.shl_sat`. |
| 13076 | 13075 | if (air_tag == .shl_sat) _ = try sema.checkIntType(block, rhs_src, scalar_rhs_ty); |
| 13077 | 13076 | |
| 13078 | | const maybe_lhs_val = try sema.resolveValue(lhs); |
| 13079 | | const maybe_rhs_val = try sema.resolveValue(rhs); |
| 13077 | const maybe_lhs_val = sema.resolveValue(lhs); |
| 13078 | const maybe_rhs_val = sema.resolveValue(rhs); |
| 13080 | 13079 | |
| 13081 | 13080 | const runtime_src = rs: { |
| 13082 | 13081 | if (maybe_rhs_val) |rhs_val| { |
| ... | ... | @@ -13238,8 +13237,8 @@ fn zirShr( |
| 13238 | 13237 | const zcu = pt.zcu; |
| 13239 | 13238 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 13240 | 13239 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 13241 | | const lhs = try sema.resolveInst(extra.lhs); |
| 13242 | | const rhs = try sema.resolveInst(extra.rhs); |
| 13240 | const lhs = sema.resolveInst(extra.lhs); |
| 13241 | const rhs = sema.resolveInst(extra.rhs); |
| 13243 | 13242 | const lhs_ty = sema.typeOf(lhs); |
| 13244 | 13243 | const rhs_ty = sema.typeOf(rhs); |
| 13245 | 13244 | |
| ... | ... | @@ -13258,8 +13257,8 @@ fn zirShr( |
| 13258 | 13257 | try sema.checkVectorizableBinaryOperands(block, src, lhs_ty, rhs_ty, lhs_src, rhs_src); |
| 13259 | 13258 | const scalar_ty = lhs_ty.scalarType(zcu); |
| 13260 | 13259 | |
| 13261 | | const maybe_lhs_val = try sema.resolveValue(lhs); |
| 13262 | | const maybe_rhs_val = try sema.resolveValue(rhs); |
| 13260 | const maybe_lhs_val = sema.resolveValue(lhs); |
| 13261 | const maybe_rhs_val = sema.resolveValue(rhs); |
| 13263 | 13262 | |
| 13264 | 13263 | const runtime_src = rs: { |
| 13265 | 13264 | if (maybe_rhs_val) |rhs_val| { |
| ... | ... | @@ -13371,8 +13370,8 @@ fn zirBitwise( |
| 13371 | 13370 | const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node }); |
| 13372 | 13371 | const rhs_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node }); |
| 13373 | 13372 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 13374 | | const lhs = try sema.resolveInst(extra.lhs); |
| 13375 | | const rhs = try sema.resolveInst(extra.rhs); |
| 13373 | const lhs = sema.resolveInst(extra.lhs); |
| 13374 | const rhs = sema.resolveInst(extra.rhs); |
| 13376 | 13375 | const lhs_ty = sema.typeOf(lhs); |
| 13377 | 13376 | const rhs_ty = sema.typeOf(rhs); |
| 13378 | 13377 | try sema.checkVectorizableBinaryOperands(block, src, lhs_ty, rhs_ty, lhs_src, rhs_src); |
| ... | ... | @@ -13394,8 +13393,8 @@ fn zirBitwise( |
| 13394 | 13393 | const runtime_src = runtime: { |
| 13395 | 13394 | // TODO: ask the linker what kind of relocations are available, and |
| 13396 | 13395 | // in some cases emit a Value that means "this decl's address AND'd with this operand". |
| 13397 | | if (try sema.resolveValue(casted_lhs)) |lhs_val| { |
| 13398 | | if (try sema.resolveValue(casted_rhs)) |rhs_val| { |
| 13396 | if (sema.resolveValue(casted_lhs)) |lhs_val| { |
| 13397 | if (sema.resolveValue(casted_rhs)) |rhs_val| { |
| 13399 | 13398 | const result_val = switch (air_tag) { |
| 13400 | 13399 | // zig fmt: off |
| 13401 | 13400 | .bit_and => try arith.bitwiseBin(sema, resolved_type, lhs_val, rhs_val, .@"and"), |
| ... | ... | @@ -13423,7 +13422,7 @@ fn zirBitNot(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. |
| 13423 | 13422 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 13424 | 13423 | const operand_src = block.src(.{ .node_offset_un_op = inst_data.src_node }); |
| 13425 | 13424 | const src = block.nodeOffset(inst_data.src_node); |
| 13426 | | const operand = try sema.resolveInst(inst_data.operand); |
| 13425 | const operand = sema.resolveInst(inst_data.operand); |
| 13427 | 13426 | const operand_ty = sema.typeOf(operand); |
| 13428 | 13427 | const scalar_ty = operand_ty.scalarType(zcu); |
| 13429 | 13428 | const scalar_tag = scalar_ty.zigTypeTag(zcu); |
| ... | ... | @@ -13441,7 +13440,7 @@ fn analyzeBitNot( |
| 13441 | 13440 | src: LazySrcLoc, |
| 13442 | 13441 | ) CompileError!Air.Inst.Ref { |
| 13443 | 13442 | const operand_ty = sema.typeOf(operand); |
| 13444 | | if (try sema.resolveValue(operand)) |operand_val| { |
| 13443 | if (sema.resolveValue(operand)) |operand_val| { |
| 13445 | 13444 | const result_val = try arith.bitwiseNot(sema, operand_ty, operand_val); |
| 13446 | 13445 | return Air.internedToRef(result_val.toIntern()); |
| 13447 | 13446 | } |
| ... | ... | @@ -13551,8 +13550,8 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 13551 | 13550 | const zcu = pt.zcu; |
| 13552 | 13551 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 13553 | 13552 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 13554 | | const lhs = try sema.resolveInst(extra.lhs); |
| 13555 | | const rhs = try sema.resolveInst(extra.rhs); |
| 13553 | const lhs = sema.resolveInst(extra.lhs); |
| 13554 | const rhs = sema.resolveInst(extra.rhs); |
| 13556 | 13555 | const lhs_ty = sema.typeOf(lhs); |
| 13557 | 13556 | const rhs_ty = sema.typeOf(rhs); |
| 13558 | 13557 | const src = block.nodeOffset(inst_data.src_node); |
| ... | ... | @@ -13646,12 +13645,12 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 13646 | 13645 | }; |
| 13647 | 13646 | |
| 13648 | 13647 | const runtime_src = if (switch (lhs_ty.zigTypeTag(zcu)) { |
| 13649 | | .array, .@"struct" => try sema.resolveValue(lhs), |
| 13648 | .array, .@"struct" => sema.resolveValue(lhs), |
| 13650 | 13649 | .pointer => try sema.resolveDefinedValue(block, lhs_src, lhs), |
| 13651 | 13650 | else => unreachable, |
| 13652 | 13651 | }) |lhs_val| rs: { |
| 13653 | 13652 | if (switch (rhs_ty.zigTypeTag(zcu)) { |
| 13654 | | .array, .@"struct" => try sema.resolveValue(rhs), |
| 13653 | .array, .@"struct" => sema.resolveValue(rhs), |
| 13655 | 13654 | .pointer => try sema.resolveDefinedValue(block, rhs_src, rhs), |
| 13656 | 13655 | else => unreachable, |
| 13657 | 13656 | }) |rhs_val| { |
| ... | ... | @@ -13989,7 +13988,7 @@ fn zirArrayMul(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 13989 | 13988 | const zcu = pt.zcu; |
| 13990 | 13989 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 13991 | 13990 | const extra = sema.code.extraData(Zir.Inst.ArrayMul, inst_data.payload_index).data; |
| 13992 | | const uncoerced_lhs = try sema.resolveInst(extra.lhs); |
| 13991 | const uncoerced_lhs = sema.resolveInst(extra.lhs); |
| 13993 | 13992 | const uncoerced_lhs_ty = sema.typeOf(uncoerced_lhs); |
| 13994 | 13993 | const src: LazySrcLoc = block.nodeOffset(inst_data.src_node); |
| 13995 | 13994 | const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node }); |
| ... | ... | @@ -14068,7 +14067,7 @@ fn zirArrayMul(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 14068 | 14067 | const ptr_addrspace = if (lhs_ty.zigTypeTag(zcu) == .pointer) lhs_ty.ptrAddressSpace(zcu) else null; |
| 14069 | 14068 | const lhs_len = try sema.usizeCast(block, lhs_src, lhs_info.len); |
| 14070 | 14069 | |
| 14071 | | if (try sema.resolveValue(lhs)) |lhs_val| ct: { |
| 14070 | if (sema.resolveValue(lhs)) |lhs_val| ct: { |
| 14072 | 14071 | const lhs_sub_val = if (lhs_ty.isSinglePointer(zcu)) |
| 14073 | 14072 | try sema.pointerDeref(block, lhs_src, lhs_val, lhs_ty) orelse break :ct |
| 14074 | 14073 | else if (lhs_ty.isSlice(zcu)) |
| ... | ... | @@ -14157,7 +14156,7 @@ fn zirNegate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. |
| 14157 | 14156 | const lhs_src = src; |
| 14158 | 14157 | const rhs_src = block.src(.{ .node_offset_un_op = inst_data.src_node }); |
| 14159 | 14158 | |
| 14160 | | const rhs = try sema.resolveInst(inst_data.operand); |
| 14159 | const rhs = sema.resolveInst(inst_data.operand); |
| 14161 | 14160 | const rhs_ty = sema.typeOf(rhs); |
| 14162 | 14161 | const rhs_scalar_ty = rhs_ty.scalarType(zcu); |
| 14163 | 14162 | |
| ... | ... | @@ -14170,7 +14169,7 @@ fn zirNegate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. |
| 14170 | 14169 | |
| 14171 | 14170 | if (rhs_scalar_ty.isAnyFloat()) { |
| 14172 | 14171 | // We handle float negation here to ensure negative zero is represented in the bits. |
| 14173 | | if (try sema.resolveValue(rhs)) |rhs_val| { |
| 14172 | if (sema.resolveValue(rhs)) |rhs_val| { |
| 14174 | 14173 | const result = try arith.negateFloat(sema, rhs_ty, rhs_val); |
| 14175 | 14174 | return Air.internedToRef(result.toIntern()); |
| 14176 | 14175 | } |
| ... | ... | @@ -14190,7 +14189,7 @@ fn zirNegateWrap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! |
| 14190 | 14189 | const lhs_src = src; |
| 14191 | 14190 | const rhs_src = block.src(.{ .node_offset_un_op = inst_data.src_node }); |
| 14192 | 14191 | |
| 14193 | | const rhs = try sema.resolveInst(inst_data.operand); |
| 14192 | const rhs = sema.resolveInst(inst_data.operand); |
| 14194 | 14193 | const rhs_ty = sema.typeOf(rhs); |
| 14195 | 14194 | const rhs_scalar_ty = rhs_ty.scalarType(zcu); |
| 14196 | 14195 | |
| ... | ... | @@ -14218,8 +14217,8 @@ fn zirArithmetic( |
| 14218 | 14217 | const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node }); |
| 14219 | 14218 | const rhs_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node }); |
| 14220 | 14219 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 14221 | | const lhs = try sema.resolveInst(extra.lhs); |
| 14222 | | const rhs = try sema.resolveInst(extra.rhs); |
| 14220 | const lhs = sema.resolveInst(extra.lhs); |
| 14221 | const rhs = sema.resolveInst(extra.rhs); |
| 14223 | 14222 | |
| 14224 | 14223 | return sema.analyzeArithmetic(block, zir_tag, lhs, rhs, src, lhs_src, rhs_src, safety); |
| 14225 | 14224 | } |
| ... | ... | @@ -14232,8 +14231,8 @@ fn zirDiv(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins |
| 14232 | 14231 | const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node }); |
| 14233 | 14232 | const rhs_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node }); |
| 14234 | 14233 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 14235 | | const lhs = try sema.resolveInst(extra.lhs); |
| 14236 | | const rhs = try sema.resolveInst(extra.rhs); |
| 14234 | const lhs = sema.resolveInst(extra.lhs); |
| 14235 | const rhs = sema.resolveInst(extra.rhs); |
| 14237 | 14236 | const lhs_ty = sema.typeOf(lhs); |
| 14238 | 14237 | const rhs_ty = sema.typeOf(rhs); |
| 14239 | 14238 | const lhs_zig_ty_tag = lhs_ty.zigTypeTag(zcu); |
| ... | ... | @@ -14255,8 +14254,8 @@ fn zirDiv(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins |
| 14255 | 14254 | |
| 14256 | 14255 | try sema.checkArithmeticOp(block, src, scalar_tag, lhs_zig_ty_tag, rhs_zig_ty_tag, .div); |
| 14257 | 14256 | |
| 14258 | | const maybe_lhs_val = try sema.resolveValue(casted_lhs); |
| 14259 | | const maybe_rhs_val = try sema.resolveValue(casted_rhs); |
| 14257 | const maybe_lhs_val = sema.resolveValue(casted_lhs); |
| 14258 | const maybe_rhs_val = sema.resolveValue(casted_rhs); |
| 14260 | 14259 | |
| 14261 | 14260 | if ((lhs_ty.zigTypeTag(zcu) == .comptime_float and rhs_ty.zigTypeTag(zcu) == .comptime_int) or |
| 14262 | 14261 | (lhs_ty.zigTypeTag(zcu) == .comptime_int and rhs_ty.zigTypeTag(zcu) == .comptime_float)) |
| ... | ... | @@ -14341,8 +14340,8 @@ fn zirDivExact(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 14341 | 14340 | const lhs_src = block.builtinCallArgSrc(inst_data.src_node, 0); |
| 14342 | 14341 | const rhs_src = block.builtinCallArgSrc(inst_data.src_node, 1); |
| 14343 | 14342 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 14344 | | const lhs = try sema.resolveInst(extra.lhs); |
| 14345 | | const rhs = try sema.resolveInst(extra.rhs); |
| 14343 | const lhs = sema.resolveInst(extra.lhs); |
| 14344 | const rhs = sema.resolveInst(extra.rhs); |
| 14346 | 14345 | const lhs_ty = sema.typeOf(lhs); |
| 14347 | 14346 | const rhs_ty = sema.typeOf(rhs); |
| 14348 | 14347 | const lhs_zig_ty_tag = lhs_ty.zigTypeTag(zcu); |
| ... | ... | @@ -14364,8 +14363,8 @@ fn zirDivExact(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 14364 | 14363 | |
| 14365 | 14364 | try sema.checkArithmeticOp(block, src, scalar_tag, lhs_zig_ty_tag, rhs_zig_ty_tag, .div_exact); |
| 14366 | 14365 | |
| 14367 | | const maybe_lhs_val = try sema.resolveValue(casted_lhs); |
| 14368 | | const maybe_rhs_val = try sema.resolveValue(casted_rhs); |
| 14366 | const maybe_lhs_val = sema.resolveValue(casted_lhs); |
| 14367 | const maybe_rhs_val = sema.resolveValue(casted_rhs); |
| 14369 | 14368 | |
| 14370 | 14369 | // Because `@divExact` can trigger Illegal Behavior, undefined operands trigger Illegal Behavior. |
| 14371 | 14370 | |
| ... | ... | @@ -14437,8 +14436,8 @@ fn zirDivFloor(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 14437 | 14436 | const lhs_src = block.builtinCallArgSrc(inst_data.src_node, 0); |
| 14438 | 14437 | const rhs_src = block.builtinCallArgSrc(inst_data.src_node, 1); |
| 14439 | 14438 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 14440 | | const lhs = try sema.resolveInst(extra.lhs); |
| 14441 | | const rhs = try sema.resolveInst(extra.rhs); |
| 14439 | const lhs = sema.resolveInst(extra.lhs); |
| 14440 | const rhs = sema.resolveInst(extra.rhs); |
| 14442 | 14441 | const lhs_ty = sema.typeOf(lhs); |
| 14443 | 14442 | const rhs_ty = sema.typeOf(rhs); |
| 14444 | 14443 | const lhs_zig_ty_tag = lhs_ty.zigTypeTag(zcu); |
| ... | ... | @@ -14460,8 +14459,8 @@ fn zirDivFloor(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 14460 | 14459 | |
| 14461 | 14460 | try sema.checkArithmeticOp(block, src, scalar_tag, lhs_zig_ty_tag, rhs_zig_ty_tag, .div_floor); |
| 14462 | 14461 | |
| 14463 | | const maybe_lhs_val = try sema.resolveValue(casted_lhs); |
| 14464 | | const maybe_rhs_val = try sema.resolveValue(casted_rhs); |
| 14462 | const maybe_lhs_val = sema.resolveValue(casted_lhs); |
| 14463 | const maybe_rhs_val = sema.resolveValue(casted_rhs); |
| 14465 | 14464 | |
| 14466 | 14465 | const allow_div_zero = !is_int and |
| 14467 | 14466 | resolved_type.toIntern() != .comptime_float_type and |
| ... | ... | @@ -14502,8 +14501,8 @@ fn zirDivTrunc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 14502 | 14501 | const lhs_src = block.builtinCallArgSrc(inst_data.src_node, 0); |
| 14503 | 14502 | const rhs_src = block.builtinCallArgSrc(inst_data.src_node, 1); |
| 14504 | 14503 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 14505 | | const lhs = try sema.resolveInst(extra.lhs); |
| 14506 | | const rhs = try sema.resolveInst(extra.rhs); |
| 14504 | const lhs = sema.resolveInst(extra.lhs); |
| 14505 | const rhs = sema.resolveInst(extra.rhs); |
| 14507 | 14506 | const lhs_ty = sema.typeOf(lhs); |
| 14508 | 14507 | const rhs_ty = sema.typeOf(rhs); |
| 14509 | 14508 | const lhs_zig_ty_tag = lhs_ty.zigTypeTag(zcu); |
| ... | ... | @@ -14525,8 +14524,8 @@ fn zirDivTrunc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 14525 | 14524 | |
| 14526 | 14525 | try sema.checkArithmeticOp(block, src, scalar_tag, lhs_zig_ty_tag, rhs_zig_ty_tag, .div_trunc); |
| 14527 | 14526 | |
| 14528 | | const maybe_lhs_val = try sema.resolveValue(casted_lhs); |
| 14529 | | const maybe_rhs_val = try sema.resolveValue(casted_rhs); |
| 14527 | const maybe_lhs_val = sema.resolveValue(casted_lhs); |
| 14528 | const maybe_rhs_val = sema.resolveValue(casted_rhs); |
| 14530 | 14529 | |
| 14531 | 14530 | const allow_div_zero = !is_int and |
| 14532 | 14531 | resolved_type.toIntern() != .comptime_float_type and |
| ... | ... | @@ -14713,8 +14712,8 @@ fn zirModRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. |
| 14713 | 14712 | const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node }); |
| 14714 | 14713 | const rhs_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node }); |
| 14715 | 14714 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 14716 | | const lhs = try sema.resolveInst(extra.lhs); |
| 14717 | | const rhs = try sema.resolveInst(extra.rhs); |
| 14715 | const lhs = sema.resolveInst(extra.lhs); |
| 14716 | const rhs = sema.resolveInst(extra.rhs); |
| 14718 | 14717 | const lhs_ty = sema.typeOf(lhs); |
| 14719 | 14718 | const rhs_ty = sema.typeOf(rhs); |
| 14720 | 14719 | const lhs_zig_ty_tag = lhs_ty.zigTypeTag(zcu); |
| ... | ... | @@ -14737,8 +14736,8 @@ fn zirModRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. |
| 14737 | 14736 | |
| 14738 | 14737 | try sema.checkArithmeticOp(block, src, scalar_tag, lhs_zig_ty_tag, rhs_zig_ty_tag, .mod_rem); |
| 14739 | 14738 | |
| 14740 | | const maybe_lhs_val = try sema.resolveValue(casted_lhs); |
| 14741 | | const maybe_rhs_val = try sema.resolveValue(casted_rhs); |
| 14739 | const maybe_lhs_val = sema.resolveValue(casted_lhs); |
| 14740 | const maybe_rhs_val = sema.resolveValue(casted_rhs); |
| 14742 | 14741 | |
| 14743 | 14742 | const lhs_maybe_negative = a: { |
| 14744 | 14743 | if (lhs_scalar_ty.isUnsignedInt(zcu)) break :a false; |
| ... | ... | @@ -14814,8 +14813,8 @@ fn zirMod(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins |
| 14814 | 14813 | const lhs_src = block.builtinCallArgSrc(inst_data.src_node, 0); |
| 14815 | 14814 | const rhs_src = block.builtinCallArgSrc(inst_data.src_node, 1); |
| 14816 | 14815 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 14817 | | const lhs = try sema.resolveInst(extra.lhs); |
| 14818 | | const rhs = try sema.resolveInst(extra.rhs); |
| 14816 | const lhs = sema.resolveInst(extra.lhs); |
| 14817 | const rhs = sema.resolveInst(extra.rhs); |
| 14819 | 14818 | const lhs_ty = sema.typeOf(lhs); |
| 14820 | 14819 | const rhs_ty = sema.typeOf(rhs); |
| 14821 | 14820 | const lhs_zig_ty_tag = lhs_ty.zigTypeTag(zcu); |
| ... | ... | @@ -14836,8 +14835,8 @@ fn zirMod(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins |
| 14836 | 14835 | |
| 14837 | 14836 | try sema.checkArithmeticOp(block, src, scalar_tag, lhs_zig_ty_tag, rhs_zig_ty_tag, .mod); |
| 14838 | 14837 | |
| 14839 | | const maybe_lhs_val = try sema.resolveValue(casted_lhs); |
| 14840 | | const maybe_rhs_val = try sema.resolveValue(casted_rhs); |
| 14838 | const maybe_lhs_val = sema.resolveValue(casted_lhs); |
| 14839 | const maybe_rhs_val = sema.resolveValue(casted_rhs); |
| 14841 | 14840 | |
| 14842 | 14841 | const allow_div_zero = !is_int and |
| 14843 | 14842 | resolved_type.toIntern() != .comptime_float_type and |
| ... | ... | @@ -14878,8 +14877,8 @@ fn zirRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins |
| 14878 | 14877 | const lhs_src = block.builtinCallArgSrc(inst_data.src_node, 0); |
| 14879 | 14878 | const rhs_src = block.builtinCallArgSrc(inst_data.src_node, 1); |
| 14880 | 14879 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 14881 | | const lhs = try sema.resolveInst(extra.lhs); |
| 14882 | | const rhs = try sema.resolveInst(extra.rhs); |
| 14880 | const lhs = sema.resolveInst(extra.lhs); |
| 14881 | const rhs = sema.resolveInst(extra.rhs); |
| 14883 | 14882 | const lhs_ty = sema.typeOf(lhs); |
| 14884 | 14883 | const rhs_ty = sema.typeOf(rhs); |
| 14885 | 14884 | const lhs_zig_ty_tag = lhs_ty.zigTypeTag(zcu); |
| ... | ... | @@ -14900,8 +14899,8 @@ fn zirRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins |
| 14900 | 14899 | |
| 14901 | 14900 | try sema.checkArithmeticOp(block, src, scalar_tag, lhs_zig_ty_tag, rhs_zig_ty_tag, .rem); |
| 14902 | 14901 | |
| 14903 | | const maybe_lhs_val = try sema.resolveValue(casted_lhs); |
| 14904 | | const maybe_rhs_val = try sema.resolveValue(casted_rhs); |
| 14902 | const maybe_lhs_val = sema.resolveValue(casted_lhs); |
| 14903 | const maybe_rhs_val = sema.resolveValue(casted_rhs); |
| 14905 | 14904 | |
| 14906 | 14905 | const allow_div_zero = !is_int and |
| 14907 | 14906 | resolved_type.toIntern() != .comptime_float_type and |
| ... | ... | @@ -14949,8 +14948,8 @@ fn zirOverflowArithmetic( |
| 14949 | 14948 | const lhs_src = block.builtinCallArgSrc(extra.node, 0); |
| 14950 | 14949 | const rhs_src = block.builtinCallArgSrc(extra.node, 1); |
| 14951 | 14950 | |
| 14952 | | const uncasted_lhs = try sema.resolveInst(extra.lhs); |
| 14953 | | const uncasted_rhs = try sema.resolveInst(extra.rhs); |
| 14951 | const uncasted_lhs = sema.resolveInst(extra.lhs); |
| 14952 | const uncasted_rhs = sema.resolveInst(extra.rhs); |
| 14954 | 14953 | |
| 14955 | 14954 | const lhs_ty = sema.typeOf(uncasted_lhs); |
| 14956 | 14955 | const rhs_ty = sema.typeOf(uncasted_rhs); |
| ... | ... | @@ -14980,8 +14979,8 @@ fn zirOverflowArithmetic( |
| 14980 | 14979 | return sema.fail(block, src, "expected vector of integers or integer tag type, found '{f}'", .{dest_ty.fmt(pt)}); |
| 14981 | 14980 | } |
| 14982 | 14981 | |
| 14983 | | const maybe_lhs_val = try sema.resolveValue(lhs); |
| 14984 | | const maybe_rhs_val = try sema.resolveValue(rhs); |
| 14982 | const maybe_lhs_val = sema.resolveValue(lhs); |
| 14983 | const maybe_rhs_val = sema.resolveValue(rhs); |
| 14985 | 14984 | |
| 14986 | 14985 | const tuple_ty = try pt.overflowArithmeticTupleType(dest_ty); |
| 14987 | 14986 | const overflow_ty: Type = .fromInterned(ip.indexToKey(tuple_ty.toIntern()).tuple_type.types.get(ip)[1]); |
| ... | ... | @@ -15163,7 +15162,7 @@ fn zirOverflowArithmetic( |
| 15163 | 15162 | }; |
| 15164 | 15163 | |
| 15165 | 15164 | if (result.inst != .none) { |
| 15166 | | if (try sema.resolveValue(result.inst)) |some| { |
| 15165 | if (sema.resolveValue(result.inst)) |some| { |
| 15167 | 15166 | result.wrapped = some; |
| 15168 | 15167 | result.inst = .none; |
| 15169 | 15168 | } |
| ... | ... | @@ -15227,8 +15226,8 @@ fn analyzeArithmetic( |
| 15227 | 15226 | } |
| 15228 | 15227 | |
| 15229 | 15228 | const runtime_src = runtime_src: { |
| 15230 | | if (try sema.resolveValue(lhs)) |lhs_value| { |
| 15231 | | if (try sema.resolveValue(rhs)) |rhs_value| { |
| 15229 | if (sema.resolveValue(lhs)) |lhs_value| { |
| 15230 | if (sema.resolveValue(rhs)) |rhs_value| { |
| 15232 | 15231 | const lhs_ptr = switch (zcu.intern_pool.indexToKey(lhs_value.toIntern())) { |
| 15233 | 15232 | .undef => return sema.failWithUseOfUndef(block, lhs_src, null), |
| 15234 | 15233 | .ptr => |ptr| ptr, |
| ... | ... | @@ -15307,8 +15306,8 @@ fn analyzeArithmetic( |
| 15307 | 15306 | else => unreachable, |
| 15308 | 15307 | }; |
| 15309 | 15308 | |
| 15310 | | const maybe_lhs_val = try sema.resolveValue(casted_lhs); |
| 15311 | | const maybe_rhs_val = try sema.resolveValue(casted_rhs); |
| 15309 | const maybe_lhs_val = sema.resolveValue(casted_lhs); |
| 15310 | const maybe_rhs_val = sema.resolveValue(casted_rhs); |
| 15312 | 15311 | |
| 15313 | 15312 | if (maybe_lhs_val) |lhs_val| { |
| 15314 | 15313 | if (maybe_rhs_val) |rhs_val| { |
| ... | ... | @@ -15380,7 +15379,7 @@ fn analyzePtrArithmetic( |
| 15380 | 15379 | const offset = try sema.coerce(block, .usize, uncasted_offset, offset_src); |
| 15381 | 15380 | const pt = sema.pt; |
| 15382 | 15381 | const zcu = pt.zcu; |
| 15383 | | const opt_ptr_val = try sema.resolveValue(ptr); |
| 15382 | const opt_ptr_val = sema.resolveValue(ptr); |
| 15384 | 15383 | const opt_off_val = try sema.resolveDefinedValue(block, offset_src, offset); |
| 15385 | 15384 | const ptr_ty = sema.typeOf(ptr); |
| 15386 | 15385 | const ptr_info = ptr_ty.ptrInfo(zcu); |
| ... | ... | @@ -15473,7 +15472,7 @@ fn zirLoad(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.In |
| 15473 | 15472 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 15474 | 15473 | const src = block.nodeOffset(inst_data.src_node); |
| 15475 | 15474 | const ptr_src = src; // TODO better source location |
| 15476 | | const ptr = try sema.resolveInst(inst_data.operand); |
| 15475 | const ptr = sema.resolveInst(inst_data.operand); |
| 15477 | 15476 | return sema.analyzeLoad(block, src, ptr, ptr_src); |
| 15478 | 15477 | } |
| 15479 | 15478 | |
| ... | ... | @@ -15547,7 +15546,7 @@ fn zirAsm( |
| 15547 | 15546 | const out_ty = try sema.resolveType(block, ret_ty_src, output.data.operand); |
| 15548 | 15547 | expr_ty = Air.internedToRef(out_ty.toIntern()); |
| 15549 | 15548 | } else { |
| 15550 | | const inst = try sema.resolveInst(output.data.operand); |
| 15549 | const inst = sema.resolveInst(output.data.operand); |
| 15551 | 15550 | if (!sema.checkRuntimeValue(inst)) { |
| 15552 | 15551 | const output_name = try ip.getOrPutString(gpa, io, pt.tid, name, .no_embedded_nulls); |
| 15553 | 15552 | return sema.failWithContainsReferenceToComptimeVar(block, output_src, output_name, "assembly output", .fromInterned(inst.toInterned().?)); |
| ... | ... | @@ -15577,7 +15576,7 @@ fn zirAsm( |
| 15577 | 15576 | } }); |
| 15578 | 15577 | extra_i = input.end; |
| 15579 | 15578 | |
| 15580 | | const uncasted_arg = try sema.resolveInst(input.data.operand); |
| 15579 | const uncasted_arg = sema.resolveInst(input.data.operand); |
| 15581 | 15580 | const name = sema.code.nullTerminatedString(input.data.name); |
| 15582 | 15581 | if (!sema.checkRuntimeValue(uncasted_arg)) { |
| 15583 | 15582 | const input_name = try ip.getOrPutString(gpa, io, pt.tid, name, .no_embedded_nulls); |
| ... | ... | @@ -15600,7 +15599,7 @@ fn zirAsm( |
| 15600 | 15599 | const clobbers = if (extra.data.clobbers == .none) empty: { |
| 15601 | 15600 | const clobbers_ty = try sema.getBuiltinType(src, .@"assembly.Clobbers"); |
| 15602 | 15601 | break :empty try sema.structInitEmpty(block, clobbers_ty, src, src); |
| 15603 | | } else try sema.resolveInst(extra.data.clobbers); // Already coerced by AstGen. |
| 15602 | } else sema.resolveInst(extra.data.clobbers); // Already coerced by AstGen. |
| 15604 | 15603 | const clobbers_val = try sema.resolveConstDefinedValue(block, src, clobbers, .{ .simple = .clobber }); |
| 15605 | 15604 | needed_capacity += asm_source.len / 4 + 1; |
| 15606 | 15605 | |
| ... | ... | @@ -15666,8 +15665,8 @@ fn zirCmpEq( |
| 15666 | 15665 | const src: LazySrcLoc = block.nodeOffset(inst_data.src_node); |
| 15667 | 15666 | const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node }); |
| 15668 | 15667 | const rhs_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node }); |
| 15669 | | const lhs = try sema.resolveInst(extra.lhs); |
| 15670 | | const rhs = try sema.resolveInst(extra.rhs); |
| 15668 | const lhs = sema.resolveInst(extra.lhs); |
| 15669 | const rhs = sema.resolveInst(extra.rhs); |
| 15671 | 15670 | |
| 15672 | 15671 | const lhs_ty = sema.typeOf(lhs); |
| 15673 | 15672 | const rhs_ty = sema.typeOf(rhs); |
| ... | ... | @@ -15700,8 +15699,8 @@ fn zirCmpEq( |
| 15700 | 15699 | |
| 15701 | 15700 | if (lhs_ty_tag == .error_set and rhs_ty_tag == .error_set) { |
| 15702 | 15701 | const runtime_src: LazySrcLoc = src: { |
| 15703 | | if (try sema.resolveValue(lhs)) |lval| { |
| 15704 | | if (try sema.resolveValue(rhs)) |rval| { |
| 15702 | if (sema.resolveValue(lhs)) |lval| { |
| 15703 | if (sema.resolveValue(rhs)) |rval| { |
| 15705 | 15704 | if (lval.isUndef(zcu) or rval.isUndef(zcu)) return .undef_bool; |
| 15706 | 15705 | const lkey = zcu.intern_pool.indexToKey(lval.toIntern()); |
| 15707 | 15706 | const rkey = zcu.intern_pool.indexToKey(rval.toIntern()); |
| ... | ... | @@ -15754,7 +15753,7 @@ fn analyzeCmpUnionTag( |
| 15754 | 15753 | const coerced_tag = try sema.coerce(block, union_tag_ty, tag, tag_src); |
| 15755 | 15754 | const coerced_union = try sema.coerce(block, union_tag_ty, un, un_src); |
| 15756 | 15755 | |
| 15757 | | if (try sema.resolveValue(coerced_tag)) |enum_val| { |
| 15756 | if (sema.resolveValue(coerced_tag)) |enum_val| { |
| 15758 | 15757 | if (enum_val.isUndef(zcu)) return .undef_bool; |
| 15759 | 15758 | const field_ty = union_ty.unionFieldType(enum_val, zcu).?; |
| 15760 | 15759 | if (field_ty.zigTypeTag(zcu) == .noreturn) { |
| ... | ... | @@ -15780,8 +15779,8 @@ fn zirCmp( |
| 15780 | 15779 | const src: LazySrcLoc = block.nodeOffset(inst_data.src_node); |
| 15781 | 15780 | const lhs_src = block.src(.{ .node_offset_bin_lhs = inst_data.src_node }); |
| 15782 | 15781 | const rhs_src = block.src(.{ .node_offset_bin_rhs = inst_data.src_node }); |
| 15783 | | const lhs = try sema.resolveInst(extra.lhs); |
| 15784 | | const rhs = try sema.resolveInst(extra.rhs); |
| 15782 | const lhs = sema.resolveInst(extra.lhs); |
| 15783 | const rhs = sema.resolveInst(extra.rhs); |
| 15785 | 15784 | return sema.analyzeCmp(block, src, lhs, rhs, op, lhs_src, rhs_src, false); |
| 15786 | 15785 | } |
| 15787 | 15786 | |
| ... | ... | @@ -15864,8 +15863,8 @@ fn cmpSelf( |
| 15864 | 15863 | const zcu = pt.zcu; |
| 15865 | 15864 | const resolved_type = sema.typeOf(casted_lhs); |
| 15866 | 15865 | |
| 15867 | | const maybe_lhs_val = try sema.resolveValue(casted_lhs); |
| 15868 | | const maybe_rhs_val = try sema.resolveValue(casted_rhs); |
| 15866 | const maybe_lhs_val = sema.resolveValue(casted_lhs); |
| 15867 | const maybe_rhs_val = sema.resolveValue(casted_rhs); |
| 15869 | 15868 | if (maybe_lhs_val) |v| if (v.isUndef(zcu)) return .undef_bool; |
| 15870 | 15869 | if (maybe_rhs_val) |v| if (v.isUndef(zcu)) return .undef_bool; |
| 15871 | 15870 | |
| ... | ... | @@ -17118,7 +17117,7 @@ fn zirTypeof(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. |
| 17118 | 17117 | _ = block; |
| 17119 | 17118 | const zir_datas = sema.code.instructions.items(.data); |
| 17120 | 17119 | const inst_data = zir_datas[@intFromEnum(inst)].un_node; |
| 17121 | | const operand = try sema.resolveInst(inst_data.operand); |
| 17120 | const operand = sema.resolveInst(inst_data.operand); |
| 17122 | 17121 | const operand_ty = sema.typeOf(operand); |
| 17123 | 17122 | return Air.internedToRef(operand_ty.toIntern()); |
| 17124 | 17123 | } |
| ... | ... | @@ -17150,7 +17149,7 @@ fn zirTypeofBuiltin(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr |
| 17150 | 17149 | fn zirTypeofLog2IntType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 17151 | 17150 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 17152 | 17151 | const src = block.nodeOffset(inst_data.src_node); |
| 17153 | | const operand = try sema.resolveInst(inst_data.operand); |
| 17152 | const operand = sema.resolveInst(inst_data.operand); |
| 17154 | 17153 | const operand_ty = sema.typeOf(operand); |
| 17155 | 17154 | const res_ty = try sema.log2IntType(block, operand_ty, src); |
| 17156 | 17155 | return Air.internedToRef(res_ty.toIntern()); |
| ... | ... | @@ -17220,7 +17219,7 @@ fn zirTypeofPeer( |
| 17220 | 17219 | defer sema.gpa.free(inst_list); |
| 17221 | 17220 | |
| 17222 | 17221 | for (args, 0..) |arg_ref, i| { |
| 17223 | | inst_list[i] = try sema.resolveInst(arg_ref); |
| 17222 | inst_list[i] = sema.resolveInst(arg_ref); |
| 17224 | 17223 | } |
| 17225 | 17224 | |
| 17226 | 17225 | const result_type = try sema.resolvePeerTypes(block, src, inst_list, .{ .typeof_builtin_call_node_offset = extra.data.src_node }); |
| ... | ... | @@ -17233,7 +17232,7 @@ fn zirBoolNot(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 17233 | 17232 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 17234 | 17233 | const src = block.nodeOffset(inst_data.src_node); |
| 17235 | 17234 | const operand_src = block.src(.{ .node_offset_un_op = inst_data.src_node }); |
| 17236 | | const uncasted_operand = try sema.resolveInst(inst_data.operand); |
| 17235 | const uncasted_operand = sema.resolveInst(inst_data.operand); |
| 17237 | 17236 | const uncasted_ty = sema.typeOf(uncasted_operand); |
| 17238 | 17237 | if (uncasted_ty.isVector(zcu)) { |
| 17239 | 17238 | if (uncasted_ty.scalarType(zcu).zigTypeTag(zcu) != .bool) { |
| ... | ... | @@ -17244,7 +17243,7 @@ fn zirBoolNot(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 17244 | 17243 | return analyzeBitNot(sema, block, uncasted_operand, src); |
| 17245 | 17244 | } |
| 17246 | 17245 | const operand = try sema.coerce(block, .bool, uncasted_operand, operand_src); |
| 17247 | | if (try sema.resolveValue(operand)) |val| { |
| 17246 | if (sema.resolveValue(operand)) |val| { |
| 17248 | 17247 | return if (val.isUndef(zcu)) .undef_bool else if (val.toBool()) .bool_false else .bool_true; |
| 17249 | 17248 | } |
| 17250 | 17249 | try sema.requireRuntimeBlock(block, src, null); |
| ... | ... | @@ -17268,7 +17267,7 @@ fn zirBoolBr( |
| 17268 | 17267 | const inst_data = datas[@intFromEnum(inst)].pl_node; |
| 17269 | 17268 | const extra = sema.code.extraData(Zir.Inst.BoolBr, inst_data.payload_index); |
| 17270 | 17269 | |
| 17271 | | const uncoerced_lhs = try sema.resolveInst(extra.data.lhs); |
| 17270 | const uncoerced_lhs = sema.resolveInst(extra.data.lhs); |
| 17272 | 17271 | const body = sema.code.bodySlice(extra.end, extra.data.body_len); |
| 17273 | 17272 | const lhs_src = parent_block.src(.{ .node_offset_bin_lhs = inst_data.src_node }); |
| 17274 | 17273 | const rhs_src = parent_block.src(.{ .node_offset_bin_rhs = inst_data.src_node }); |
| ... | ... | @@ -17431,7 +17430,7 @@ fn zirIsNonNull( |
| 17431 | 17430 | |
| 17432 | 17431 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 17433 | 17432 | const src = block.nodeOffset(inst_data.src_node); |
| 17434 | | const operand = try sema.resolveInst(inst_data.operand); |
| 17433 | const operand = sema.resolveInst(inst_data.operand); |
| 17435 | 17434 | try sema.checkNullableType(block, src, sema.typeOf(operand)); |
| 17436 | 17435 | return sema.analyzeIsNull(block, operand, true); |
| 17437 | 17436 | } |
| ... | ... | @@ -17448,12 +17447,12 @@ fn zirIsNonNullPtr( |
| 17448 | 17447 | const zcu = pt.zcu; |
| 17449 | 17448 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 17450 | 17449 | const src = block.nodeOffset(inst_data.src_node); |
| 17451 | | const ptr = try sema.resolveInst(inst_data.operand); |
| 17450 | const ptr = sema.resolveInst(inst_data.operand); |
| 17452 | 17451 | const ptr_ty = sema.typeOf(ptr); |
| 17453 | 17452 | assert(ptr_ty.zigTypeTag(zcu) == .pointer); |
| 17454 | 17453 | const nullable_ty = ptr_ty.childType(zcu); |
| 17455 | 17454 | try sema.checkNullableType(block, src, nullable_ty); |
| 17456 | | if (try sema.resolveValue(ptr)) |ptr_val| { |
| 17455 | if (sema.resolveValue(ptr)) |ptr_val| { |
| 17457 | 17456 | if (try sema.pointerDeref(block, src, ptr_val, ptr_ty)) |nullable_val| { |
| 17458 | 17457 | return sema.analyzeIsNull(block, .fromValue(nullable_val), true); |
| 17459 | 17458 | } |
| ... | ... | @@ -17481,7 +17480,7 @@ fn zirIsNonErr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 17481 | 17480 | |
| 17482 | 17481 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 17483 | 17482 | const src = block.nodeOffset(inst_data.src_node); |
| 17484 | | const operand = try sema.resolveInst(inst_data.operand); |
| 17483 | const operand = sema.resolveInst(inst_data.operand); |
| 17485 | 17484 | try sema.checkErrorType(block, src, sema.typeOf(operand)); |
| 17486 | 17485 | return sema.analyzeIsNonErr(block, src, operand); |
| 17487 | 17486 | } |
| ... | ... | @@ -17494,7 +17493,7 @@ fn zirIsNonErrPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 17494 | 17493 | const zcu = pt.zcu; |
| 17495 | 17494 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 17496 | 17495 | const src = block.nodeOffset(inst_data.src_node); |
| 17497 | | const ptr = try sema.resolveInst(inst_data.operand); |
| 17496 | const ptr = sema.resolveInst(inst_data.operand); |
| 17498 | 17497 | const ptr_ty = sema.typeOf(ptr); |
| 17499 | 17498 | assert(ptr_ty.zigTypeTag(zcu) == .pointer); |
| 17500 | 17499 | const error_ty = ptr_ty.childType(zcu); |
| ... | ... | @@ -17509,7 +17508,7 @@ fn zirRetIsNonErr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 17509 | 17508 | |
| 17510 | 17509 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 17511 | 17510 | const src = block.nodeOffset(inst_data.src_node); |
| 17512 | | const operand = try sema.resolveInst(inst_data.operand); |
| 17511 | const operand = sema.resolveInst(inst_data.operand); |
| 17513 | 17512 | return sema.analyzeIsNonErr(block, src, operand); |
| 17514 | 17513 | } |
| 17515 | 17514 | |
| ... | ... | @@ -17530,7 +17529,7 @@ fn zirCondbr( |
| 17530 | 17529 | const then_body = sema.code.bodySlice(extra.end, extra.data.then_body_len); |
| 17531 | 17530 | const else_body = sema.code.bodySlice(extra.end + then_body.len, extra.data.else_body_len); |
| 17532 | 17531 | |
| 17533 | | const uncasted_cond = try sema.resolveInst(extra.data.condition); |
| 17532 | const uncasted_cond = sema.resolveInst(extra.data.condition); |
| 17534 | 17533 | const cond = try sema.coerce(parent_block, .bool, uncasted_cond, cond_src); |
| 17535 | 17534 | |
| 17536 | 17535 | if (try sema.resolveDefinedValue(parent_block, cond_src, cond)) |cond_val| { |
| ... | ... | @@ -17566,7 +17565,7 @@ fn zirCondbr( |
| 17566 | 17565 | if (sema.code.instructions.items(.tag)[@intFromEnum(index)] != .is_non_err) break :blk null; |
| 17567 | 17566 | |
| 17568 | 17567 | const err_inst_data = sema.code.instructions.items(.data)[@intFromEnum(index)].un_node; |
| 17569 | | const err_operand = try sema.resolveInst(err_inst_data.operand); |
| 17568 | const err_operand = sema.resolveInst(err_inst_data.operand); |
| 17570 | 17569 | const operand_ty = sema.typeOf(err_operand); |
| 17571 | 17570 | assert(operand_ty.zigTypeTag(zcu) == .error_union); |
| 17572 | 17571 | const result_ty = operand_ty.errorUnionSet(zcu); |
| ... | ... | @@ -17614,7 +17613,7 @@ fn zirTry(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileError! |
| 17614 | 17613 | const operand_src = parent_block.src(.{ .node_offset_try_operand = inst_data.src_node }); |
| 17615 | 17614 | const extra = sema.code.extraData(Zir.Inst.Try, inst_data.payload_index); |
| 17616 | 17615 | const body = sema.code.bodySlice(extra.end, extra.data.body_len); |
| 17617 | | const err_union = try sema.resolveInst(extra.data.operand); |
| 17616 | const err_union = sema.resolveInst(extra.data.operand); |
| 17618 | 17617 | const err_union_ty = sema.typeOf(err_union); |
| 17619 | 17618 | const pt = sema.pt; |
| 17620 | 17619 | const zcu = pt.zcu; |
| ... | ... | @@ -17681,7 +17680,7 @@ fn zirTryPtr(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileErr |
| 17681 | 17680 | const operand_src = parent_block.src(.{ .node_offset_try_operand = inst_data.src_node }); |
| 17682 | 17681 | const extra = sema.code.extraData(Zir.Inst.Try, inst_data.payload_index); |
| 17683 | 17682 | const body = sema.code.bodySlice(extra.end, extra.data.body_len); |
| 17684 | | const operand = try sema.resolveInst(extra.data.operand); |
| 17683 | const operand = sema.resolveInst(extra.data.operand); |
| 17685 | 17684 | const err_union = try sema.analyzeLoad(parent_block, src, operand, operand_src); |
| 17686 | 17685 | const err_union_ty = sema.typeOf(err_union); |
| 17687 | 17686 | const pt = sema.pt; |
| ... | ... | @@ -17802,7 +17801,7 @@ fn ensurePostHoc(sema: *Sema, block: *Block, dest_block: Zir.Inst.Index) !*Label |
| 17802 | 17801 | fn addRuntimeBreak(sema: *Sema, child_block: *Block, block_inst: Zir.Inst.Index, break_operand: Zir.Inst.Ref) !void { |
| 17803 | 17802 | const labeled_block = try sema.ensurePostHoc(child_block, block_inst); |
| 17804 | 17803 | |
| 17805 | | const operand = try sema.resolveInst(break_operand); |
| 17804 | const operand = sema.resolveInst(break_operand); |
| 17806 | 17805 | const br_ref = try child_block.addBr(labeled_block.label.merges.block_inst, operand); |
| 17807 | 17806 | |
| 17808 | 17807 | try labeled_block.label.merges.results.append(sema.gpa, operand); |
| ... | ... | @@ -17888,7 +17887,7 @@ fn zirRetImplicit( |
| 17888 | 17887 | return; |
| 17889 | 17888 | } |
| 17890 | 17889 | |
| 17891 | | const operand = try sema.resolveInst(inst_data.operand); |
| 17890 | const operand = sema.resolveInst(inst_data.operand); |
| 17892 | 17891 | const ret_ty_src = block.src(.{ .node_offset_fn_type_ret_ty = .zero }); |
| 17893 | 17892 | const base_tag = sema.fn_ret_ty.optEuBaseType(zcu).zigTypeTag(zcu); |
| 17894 | 17893 | if (base_tag == .noreturn) { |
| ... | ... | @@ -17921,7 +17920,7 @@ fn zirRetNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!voi |
| 17921 | 17920 | defer tracy.end(); |
| 17922 | 17921 | |
| 17923 | 17922 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 17924 | | const operand = try sema.resolveInst(inst_data.operand); |
| 17923 | const operand = sema.resolveInst(inst_data.operand); |
| 17925 | 17924 | const src = block.nodeOffset(inst_data.src_node); |
| 17926 | 17925 | |
| 17927 | 17926 | return sema.analyzeRet(block, operand, src, block.src(.{ .node_offset_return_operand = inst_data.src_node })); |
| ... | ... | @@ -17933,7 +17932,7 @@ fn zirRetLoad(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!voi |
| 17933 | 17932 | |
| 17934 | 17933 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 17935 | 17934 | const src = block.nodeOffset(inst_data.src_node); |
| 17936 | | const ret_ptr = try sema.resolveInst(inst_data.operand); |
| 17935 | const ret_ptr = sema.resolveInst(inst_data.operand); |
| 17937 | 17936 | |
| 17938 | 17937 | if (block.isComptime() or block.inlining != null or sema.func_is_naked) { |
| 17939 | 17938 | const operand = try sema.analyzeLoad(block, src, ret_ptr, src); |
| ... | ... | @@ -18030,7 +18029,7 @@ fn zirSaveErrRetIndex(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE |
| 18030 | 18029 | if (block.isComptime() or block.is_typeof) return; |
| 18031 | 18030 | |
| 18032 | 18031 | const save_index = inst_data.operand == .none or b: { |
| 18033 | | const operand = try sema.resolveInst(inst_data.operand); |
| 18032 | const operand = sema.resolveInst(inst_data.operand); |
| 18034 | 18033 | const operand_ty = sema.typeOf(operand); |
| 18035 | 18034 | break :b operand_ty.isError(zcu); |
| 18036 | 18035 | }; |
| ... | ... | @@ -18079,7 +18078,7 @@ fn restoreErrRetIndex(sema: *Sema, start_block: *Block, src: LazySrcLoc, target_ |
| 18079 | 18078 | return; // No need to restore |
| 18080 | 18079 | }; |
| 18081 | 18080 | |
| 18082 | | const operand = try sema.resolveInstAllowNone(operand_zir); |
| 18081 | const operand = sema.resolveInstAllowNone(operand_zir); |
| 18083 | 18082 | |
| 18084 | 18083 | if (start_block.isComptime() or start_block.is_typeof) { |
| 18085 | 18084 | const is_non_error = if (operand != .none) blk: { |
| ... | ... | @@ -18229,7 +18228,7 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 18229 | 18228 | const hostsize_src = block.src(.{ .node_offset_ptr_hostsize = extra.data.src_node }); |
| 18230 | 18229 | |
| 18231 | 18230 | const elem_ty = blk: { |
| 18232 | | const air_inst = try sema.resolveInst(extra.data.elem_type); |
| 18231 | const air_inst = sema.resolveInst(extra.data.elem_type); |
| 18233 | 18232 | const ty = sema.analyzeAsType(block, elem_ty_src, .type, air_inst) catch |err| { |
| 18234 | 18233 | if (err == error.AnalysisFail and sema.err != null and sema.typeOf(air_inst).isSinglePointer(zcu)) { |
| 18235 | 18234 | try sema.errNote(elem_ty_src, sema.err.?, "use '.*' to dereference pointer", .{}); |
| ... | ... | @@ -18250,7 +18249,7 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 18250 | 18249 | const sentinel = if (inst_data.flags.has_sentinel) blk: { |
| 18251 | 18250 | const ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_i]); |
| 18252 | 18251 | extra_i += 1; |
| 18253 | | const coerced = try sema.coerce(block, elem_ty, try sema.resolveInst(ref), sentinel_src); |
| 18252 | const coerced = try sema.coerce(block, elem_ty, sema.resolveInst(ref), sentinel_src); |
| 18254 | 18253 | const val = try sema.resolveConstDefinedValue(block, sentinel_src, coerced, .{ .simple = .pointer_sentinel }); |
| 18255 | 18254 | try checkSentinelType(sema, block, sentinel_src, elem_ty); |
| 18256 | 18255 | if (val.canMutateComptimeVarState(zcu)) { |
| ... | ... | @@ -18263,7 +18262,7 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 18263 | 18262 | const abi_align: Alignment = if (inst_data.flags.has_align) blk: { |
| 18264 | 18263 | const ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_i]); |
| 18265 | 18264 | extra_i += 1; |
| 18266 | | const coerced = try sema.coerce(block, align_ty, try sema.resolveInst(ref), align_src); |
| 18265 | const coerced = try sema.coerce(block, align_ty, sema.resolveInst(ref), align_src); |
| 18267 | 18266 | const val = try sema.resolveConstDefinedValue(block, align_src, coerced, .{ .simple = .@"align" }); |
| 18268 | 18267 | const align_bytes = val.toUnsignedInt(zcu); |
| 18269 | 18268 | break :blk try sema.validateAlign(block, align_src, align_bytes); |
| ... | ... | @@ -18442,7 +18441,7 @@ fn zirStructInitEmptyResult(sema: *Sema, block: *Block, inst: Zir.Inst.Index, is |
| 18442 | 18441 | const init_ref = try sema.coerce(block, init_ty, empty_ref, src); |
| 18443 | 18442 | |
| 18444 | 18443 | if (is_byref) { |
| 18445 | | const init_val = (try sema.resolveValue(init_ref)).?; |
| 18444 | const init_val = sema.resolveValue(init_ref).?; |
| 18446 | 18445 | return sema.uavRef(init_val.toIntern()); |
| 18447 | 18446 | } else { |
| 18448 | 18447 | return init_ref; |
| ... | ... | @@ -18508,9 +18507,9 @@ fn zirUnionInit(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 18508 | 18507 | const field_index = try sema.unionFieldIndex(block, union_ty, field_name, field_src); |
| 18509 | 18508 | const field_ty: Type = .fromInterned(zcu.typeToUnion(union_ty).?.field_types.get(ip)[field_index]); |
| 18510 | 18509 | |
| 18511 | | const payload = try sema.coerce(block, field_ty, try sema.resolveInst(extra.init), payload_src); |
| 18510 | const payload = try sema.coerce(block, field_ty, sema.resolveInst(extra.init), payload_src); |
| 18512 | 18511 | |
| 18513 | | if (try sema.resolveValue(payload)) |payload_val| { |
| 18512 | if (sema.resolveValue(payload)) |payload_val| { |
| 18514 | 18513 | const tag_ty = union_ty.unionTagTypeHypothetical(zcu); |
| 18515 | 18514 | const tag_val = try pt.enumValueFieldIndex(tag_ty, field_index); |
| 18516 | 18515 | return .fromValue(try pt.unionValue(union_ty, tag_val, payload_val)); |
| ... | ... | @@ -18590,12 +18589,12 @@ fn zirStructInit( |
| 18590 | 18589 | assert(field_inits[field_index] == .none); |
| 18591 | 18590 | field_assign_idxs[field_index] = field_i; |
| 18592 | 18591 | found_fields[field_index] = item.data.field_type; |
| 18593 | | const uncoerced_init = try sema.resolveInst(item.data.init); |
| 18592 | const uncoerced_init = sema.resolveInst(item.data.init); |
| 18594 | 18593 | const field_ty = resolved_ty.fieldType(field_index, zcu); |
| 18595 | 18594 | field_inits[field_index] = try sema.coerce(block, field_ty, uncoerced_init, field_src); |
| 18596 | 18595 | if (resolved_ty.structFieldIsComptime(field_index, zcu)) { |
| 18597 | 18596 | const default_value = (try resolved_ty.structFieldValueComptime(pt, field_index)).?; |
| 18598 | | const init_val = (try sema.resolveValue(field_inits[field_index])) orelse { |
| 18597 | const init_val = sema.resolveValue(field_inits[field_index]) orelse { |
| 18599 | 18598 | return sema.failWithNeededComptime(block, field_src, .{ .simple = .stored_to_comptime_field }); |
| 18600 | 18599 | }; |
| 18601 | 18600 | if (!init_val.eql(default_value, resolved_ty.fieldType(field_index, zcu), zcu)) { |
| ... | ... | @@ -18640,17 +18639,17 @@ fn zirStructInit( |
| 18640 | 18639 | }); |
| 18641 | 18640 | } |
| 18642 | 18641 | |
| 18643 | | const uncoerced_init_inst = try sema.resolveInst(item.data.init); |
| 18642 | const uncoerced_init_inst = sema.resolveInst(item.data.init); |
| 18644 | 18643 | const init_inst = try sema.coerce(block, field_ty, uncoerced_init_inst, field_src); |
| 18645 | 18644 | |
| 18646 | | if (try sema.resolveValue(init_inst)) |val| { |
| 18645 | if (sema.resolveValue(init_inst)) |val| { |
| 18647 | 18646 | const struct_val = Value.fromInterned(try pt.internUnion(.{ |
| 18648 | 18647 | .ty = resolved_ty.toIntern(), |
| 18649 | 18648 | .tag = tag_val.toIntern(), |
| 18650 | 18649 | .val = val.toIntern(), |
| 18651 | 18650 | })); |
| 18652 | 18651 | const final_val_inst = try sema.coerce(block, result_ty, Air.internedToRef(struct_val.toIntern()), src); |
| 18653 | | const final_val = (try sema.resolveValue(final_val_inst)).?; |
| 18652 | const final_val = sema.resolveValue(final_val_inst).?; |
| 18654 | 18653 | return sema.addConstantMaybeRef(final_val.toIntern(), is_ref); |
| 18655 | 18654 | } |
| 18656 | 18655 | |
| ... | ... | @@ -18792,11 +18791,11 @@ fn finishStructInit( |
| 18792 | 18791 | const runtime_index = opt_runtime_index orelse { |
| 18793 | 18792 | const elems = try sema.arena.alloc(InternPool.Index, field_inits.len); |
| 18794 | 18793 | for (elems, field_inits) |*elem, field_init| { |
| 18795 | | elem.* = (sema.resolveValue(field_init) catch unreachable).?.toIntern(); |
| 18794 | elem.* = sema.resolveValue(field_init).?.toIntern(); |
| 18796 | 18795 | } |
| 18797 | 18796 | const struct_val = try pt.aggregateValue(struct_ty, elems); |
| 18798 | 18797 | const final_val_inst = try sema.coerce(block, result_ty, Air.internedToRef(struct_val.toIntern()), init_src); |
| 18799 | | const final_val = (try sema.resolveValue(final_val_inst)).?; |
| 18798 | const final_val = sema.resolveValue(final_val_inst).?; |
| 18800 | 18799 | return sema.addConstantMaybeRef(final_val.toIntern(), is_ref); |
| 18801 | 18800 | }; |
| 18802 | 18801 | |
| ... | ... | @@ -18903,7 +18902,7 @@ fn structInitAnon( |
| 18903 | 18902 | |
| 18904 | 18903 | field_name.* = try zcu.intern_pool.getOrPutString(gpa, io, pt.tid, name, .no_embedded_nulls); |
| 18905 | 18904 | |
| 18906 | | const init = try sema.resolveInst(item.data.init); |
| 18905 | const init = sema.resolveInst(item.data.init); |
| 18907 | 18906 | field_ty.* = sema.typeOf(init).toIntern(); |
| 18908 | 18907 | if (Type.fromInterned(field_ty.*).zigTypeTag(zcu) == .@"opaque") { |
| 18909 | 18908 | const msg = msg: { |
| ... | ... | @@ -18919,7 +18918,7 @@ fn structInitAnon( |
| 18919 | 18918 | }; |
| 18920 | 18919 | return sema.failWithOwnedErrorMsg(block, msg); |
| 18921 | 18920 | } |
| 18922 | | if (try sema.resolveValue(init)) |init_val| { |
| 18921 | if (sema.resolveValue(init)) |init_val| { |
| 18923 | 18922 | field_val.* = init_val.toIntern(); |
| 18924 | 18923 | any_values = true; |
| 18925 | 18924 | } else { |
| ... | ... | @@ -19018,7 +19017,7 @@ fn structInitAnon( |
| 19018 | 19017 | .flags = .{ .address_space = target_util.defaultAddressSpace(target, .local) }, |
| 19019 | 19018 | }); |
| 19020 | 19019 | if (values[i] == .none) { |
| 19021 | | const init = try sema.resolveInst(item.data.init); |
| 19020 | const init = sema.resolveInst(item.data.init); |
| 19022 | 19021 | const field_ptr = try block.addStructFieldPtr(alloc, i, field_ptr_ty); |
| 19023 | 19022 | _ = try block.addBinOp(.store, field_ptr, init); |
| 19024 | 19023 | } |
| ... | ... | @@ -19035,7 +19034,7 @@ fn structInitAnon( |
| 19035 | 19034 | .typed_init => sema.code.extraData(Zir.Inst.StructInit.Item, extra_index), |
| 19036 | 19035 | }; |
| 19037 | 19036 | extra_index = item.end; |
| 19038 | | element_refs[i] = try sema.resolveInst(item.data.init); |
| 19037 | element_refs[i] = sema.resolveInst(item.data.init); |
| 19039 | 19038 | } |
| 19040 | 19039 | |
| 19041 | 19040 | return block.addAggregateInit(struct_ty, element_refs); |
| ... | ... | @@ -19095,7 +19094,7 @@ fn zirArrayInit( |
| 19095 | 19094 | }; |
| 19096 | 19095 | |
| 19097 | 19096 | const arg = args[i + 1]; |
| 19098 | | const resolved_arg = try sema.resolveInst(arg); |
| 19097 | const resolved_arg = sema.resolveInst(arg); |
| 19099 | 19098 | const elem_ty = if (is_tuple) |
| 19100 | 19099 | array_ty.fieldType(i, zcu) |
| 19101 | 19100 | else |
| ... | ... | @@ -19126,11 +19125,11 @@ fn zirArrayInit( |
| 19126 | 19125 | const elem_vals = try sema.arena.alloc(InternPool.Index, resolved_args.len); |
| 19127 | 19126 | for (elem_vals, resolved_args) |*val, arg| { |
| 19128 | 19127 | // We checked that all args are comptime above. |
| 19129 | | val.* = (sema.resolveValue(arg) catch unreachable).?.toIntern(); |
| 19128 | val.* = sema.resolveValue(arg).?.toIntern(); |
| 19130 | 19129 | } |
| 19131 | 19130 | const arr_val = try pt.aggregateValue(array_ty, elem_vals); |
| 19132 | 19131 | const result_ref = try sema.coerce(block, result_ty, Air.internedToRef(arr_val.toIntern()), src); |
| 19133 | | const result_val = (try sema.resolveValue(result_ref)).?; |
| 19132 | const result_val = (sema.resolveValue(result_ref)).?; |
| 19134 | 19133 | return sema.addConstantMaybeRef(result_val.toIntern(), is_ref); |
| 19135 | 19134 | }; |
| 19136 | 19135 | |
| ... | ... | @@ -19213,7 +19212,7 @@ fn arrayInitAnon( |
| 19213 | 19212 | .init_node_offset = src.offset.node_offset.x, |
| 19214 | 19213 | .elem_index = @intCast(i), |
| 19215 | 19214 | } }); |
| 19216 | | const elem = try sema.resolveInst(operand); |
| 19215 | const elem = sema.resolveInst(operand); |
| 19217 | 19216 | types[i] = sema.typeOf(elem).toIntern(); |
| 19218 | 19217 | if (Type.fromInterned(types[i]).zigTypeTag(zcu) == .@"opaque") { |
| 19219 | 19218 | const msg = msg: { |
| ... | ... | @@ -19225,7 +19224,7 @@ fn arrayInitAnon( |
| 19225 | 19224 | }; |
| 19226 | 19225 | return sema.failWithOwnedErrorMsg(block, msg); |
| 19227 | 19226 | } |
| 19228 | | if (try sema.resolveValue(elem)) |val| { |
| 19227 | if (sema.resolveValue(elem)) |val| { |
| 19229 | 19228 | values[i] = val.toIntern(); |
| 19230 | 19229 | any_comptime = true; |
| 19231 | 19230 | } else { |
| ... | ... | @@ -19265,7 +19264,7 @@ fn arrayInitAnon( |
| 19265 | 19264 | .init_node_offset = src.offset.node_offset.x, |
| 19266 | 19265 | .elem_index = @intCast(i), |
| 19267 | 19266 | } }); |
| 19268 | | try sema.validateRuntimeValue(block, operand_src, try sema.resolveInst(operand)); |
| 19267 | try sema.validateRuntimeValue(block, operand_src, sema.resolveInst(operand)); |
| 19269 | 19268 | } |
| 19270 | 19269 | |
| 19271 | 19270 | if (is_ref) { |
| ... | ... | @@ -19283,7 +19282,7 @@ fn arrayInitAnon( |
| 19283 | 19282 | }); |
| 19284 | 19283 | if (values[i] == .none) { |
| 19285 | 19284 | const field_ptr = try block.addStructFieldPtr(alloc, i, field_ptr_ty); |
| 19286 | | _ = try block.addBinOp(.store, field_ptr, try sema.resolveInst(operand)); |
| 19285 | _ = try block.addBinOp(.store, field_ptr, sema.resolveInst(operand)); |
| 19287 | 19286 | } |
| 19288 | 19287 | } |
| 19289 | 19288 | |
| ... | ... | @@ -19292,7 +19291,7 @@ fn arrayInitAnon( |
| 19292 | 19291 | |
| 19293 | 19292 | const element_refs = try sema.arena.alloc(Air.Inst.Ref, operands.len); |
| 19294 | 19293 | for (operands, 0..) |operand, i| { |
| 19295 | | element_refs[i] = try sema.resolveInst(operand); |
| 19294 | element_refs[i] = sema.resolveInst(operand); |
| 19296 | 19295 | } |
| 19297 | 19296 | |
| 19298 | 19297 | return block.addAggregateInit(tuple_ty, element_refs); |
| ... | ... | @@ -19441,7 +19440,7 @@ fn zirIntFromBool(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 19441 | 19440 | const zcu = pt.zcu; |
| 19442 | 19441 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 19443 | 19442 | const src = block.nodeOffset(inst_data.src_node); |
| 19444 | | const operand = try sema.resolveInst(inst_data.operand); |
| 19443 | const operand = sema.resolveInst(inst_data.operand); |
| 19445 | 19444 | const operand_ty = sema.typeOf(operand); |
| 19446 | 19445 | const is_vector = operand_ty.zigTypeTag(zcu) == .vector; |
| 19447 | 19446 | const operand_scalar_ty = operand_ty.scalarType(zcu); |
| ... | ... | @@ -19450,7 +19449,7 @@ fn zirIntFromBool(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 19450 | 19449 | } |
| 19451 | 19450 | const len = if (is_vector) operand_ty.vectorLen(zcu) else undefined; |
| 19452 | 19451 | const dest_ty: Type = if (is_vector) try pt.vectorType(.{ .child = .u1_type, .len = len }) else .u1; |
| 19453 | | if (try sema.resolveValue(operand)) |val| { |
| 19452 | if (sema.resolveValue(operand)) |val| { |
| 19454 | 19453 | if (!is_vector) { |
| 19455 | 19454 | return if (val.isUndef(zcu)) .undef_u1 else if (val.toBool()) .one_u1 else .zero_u1; |
| 19456 | 19455 | } |
| ... | ... | @@ -19473,7 +19472,7 @@ fn zirIntFromBool(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 19473 | 19472 | fn zirErrorName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 19474 | 19473 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 19475 | 19474 | const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0); |
| 19476 | | const uncoerced_operand = try sema.resolveInst(inst_data.operand); |
| 19475 | const uncoerced_operand = sema.resolveInst(inst_data.operand); |
| 19477 | 19476 | const operand = try sema.coerce(block, .anyerror, uncoerced_operand, operand_src); |
| 19478 | 19477 | |
| 19479 | 19478 | if (try sema.resolveDefinedValue(block, operand_src, operand)) |val| { |
| ... | ... | @@ -19494,7 +19493,7 @@ fn zirAbs( |
| 19494 | 19493 | const pt = sema.pt; |
| 19495 | 19494 | const zcu = pt.zcu; |
| 19496 | 19495 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 19497 | | const operand = try sema.resolveInst(inst_data.operand); |
| 19496 | const operand = sema.resolveInst(inst_data.operand); |
| 19498 | 19497 | const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0); |
| 19499 | 19498 | const operand_ty = sema.typeOf(operand); |
| 19500 | 19499 | const scalar_ty = operand_ty.scalarType(zcu); |
| ... | ... | @@ -19525,7 +19524,7 @@ fn maybeConstantUnaryMath( |
| 19525 | 19524 | const pt = sema.pt; |
| 19526 | 19525 | const zcu = pt.zcu; |
| 19527 | 19526 | switch (result_ty.zigTypeTag(zcu)) { |
| 19528 | | .vector => if (try sema.resolveValue(operand)) |val| { |
| 19527 | .vector => if (sema.resolveValue(operand)) |val| { |
| 19529 | 19528 | const scalar_ty = result_ty.scalarType(zcu); |
| 19530 | 19529 | const vec_len = result_ty.vectorLen(zcu); |
| 19531 | 19530 | if (val.isUndef(zcu)) |
| ... | ... | @@ -19538,7 +19537,7 @@ fn maybeConstantUnaryMath( |
| 19538 | 19537 | } |
| 19539 | 19538 | return Air.internedToRef((try pt.aggregateValue(result_ty, elems)).toIntern()); |
| 19540 | 19539 | }, |
| 19541 | | else => if (try sema.resolveValue(operand)) |operand_val| { |
| 19540 | else => if (sema.resolveValue(operand)) |operand_val| { |
| 19542 | 19541 | if (operand_val.isUndef(zcu)) |
| 19543 | 19542 | return try pt.undefRef(result_ty); |
| 19544 | 19543 | const result_val = try eval(operand_val, result_ty, sema.arena, pt); |
| ... | ... | @@ -19561,7 +19560,7 @@ fn zirUnaryMath( |
| 19561 | 19560 | const pt = sema.pt; |
| 19562 | 19561 | const zcu = pt.zcu; |
| 19563 | 19562 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 19564 | | const operand = try sema.resolveInst(inst_data.operand); |
| 19563 | const operand = sema.resolveInst(inst_data.operand); |
| 19565 | 19564 | const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0); |
| 19566 | 19565 | const operand_ty = sema.typeOf(operand); |
| 19567 | 19566 | const scalar_ty = operand_ty.scalarType(zcu); |
| ... | ... | @@ -19586,7 +19585,7 @@ fn zirTagName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 19586 | 19585 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 19587 | 19586 | const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0); |
| 19588 | 19587 | const src = block.nodeOffset(inst_data.src_node); |
| 19589 | | const operand = try sema.resolveInst(inst_data.operand); |
| 19588 | const operand = sema.resolveInst(inst_data.operand); |
| 19590 | 19589 | const operand_ty = sema.typeOf(operand); |
| 19591 | 19590 | const pt = sema.pt; |
| 19592 | 19591 | const zcu = pt.zcu; |
| ... | ... | @@ -19678,7 +19677,7 @@ fn zirReifySliceArgTy( |
| 19678 | 19677 | .flags = .{ .size = .slice, .is_const = true }, |
| 19679 | 19678 | }); |
| 19680 | 19679 | |
| 19681 | | const operand_uncoerced = try sema.resolveInst(extra.operand); |
| 19680 | const operand_uncoerced = sema.resolveInst(extra.operand); |
| 19682 | 19681 | const operand_coerced = try sema.coerce(block, operand_ty, operand_uncoerced, src); |
| 19683 | 19682 | const operand_val = try sema.resolveConstDefinedValue(block, src, operand_coerced, .{ .simple = comptime_reason }); |
| 19684 | 19683 | const len_val: Value = .fromInterned(zcu.intern_pool.indexToKey(operand_val.toIntern()).slice.len); |
| ... | ... | @@ -19706,7 +19705,7 @@ fn zirReifyEnumValueSliceTy( |
| 19706 | 19705 | |
| 19707 | 19706 | const int_tag_ty = try sema.resolveType(block, int_tag_ty_src, extra.lhs); |
| 19708 | 19707 | |
| 19709 | | const operand_uncoerced = try sema.resolveInst(extra.rhs); |
| 19708 | const operand_uncoerced = sema.resolveInst(extra.rhs); |
| 19710 | 19709 | const operand_coerced = try sema.coerce(block, .slice_const_slice_const_u8, operand_uncoerced, field_names_src); |
| 19711 | 19710 | const operand_val = try sema.resolveConstDefinedValue(block, field_names_src, operand_coerced, .{ .simple = .enum_field_names }); |
| 19712 | 19711 | const len_val: Value = .fromInterned(zcu.intern_pool.indexToKey(operand_val.toIntern()).slice.len); |
| ... | ... | @@ -19751,7 +19750,7 @@ fn zirReifyTuple( |
| 19751 | 19750 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; |
| 19752 | 19751 | const operand_src = block.builtinCallArgSrc(extra.node, 0); |
| 19753 | 19752 | |
| 19754 | | const types_uncoerced = try sema.resolveInst(extra.operand); |
| 19753 | const types_uncoerced = sema.resolveInst(extra.operand); |
| 19755 | 19754 | const types_coerced = try sema.coerce(block, .slice_const_type, types_uncoerced, operand_src); |
| 19756 | 19755 | const types_slice_val = try sema.resolveConstDefinedValue(block, operand_src, types_coerced, .{ .simple = .tuple_field_types }); |
| 19757 | 19756 | const types_array_val = try sema.derefSliceAsArray(block, operand_src, types_slice_val, .{ .simple = .tuple_field_types }); |
| ... | ... | @@ -19798,12 +19797,12 @@ fn zirReifyPointer( |
| 19798 | 19797 | const size_ty = try sema.getBuiltinType(size_src, .@"Type.Pointer.Size"); |
| 19799 | 19798 | const attrs_ty = try sema.getBuiltinType(attrs_src, .@"Type.Pointer.Attributes"); |
| 19800 | 19799 | |
| 19801 | | const size_uncoerced = try sema.resolveInst(extra.size); |
| 19800 | const size_uncoerced = sema.resolveInst(extra.size); |
| 19802 | 19801 | const size_coerced = try sema.coerce(block, size_ty, size_uncoerced, size_src); |
| 19803 | 19802 | const size_val = try sema.resolveConstDefinedValue(block, size_src, size_coerced, .{ .simple = .pointer_size }); |
| 19804 | 19803 | const size = try sema.interpretBuiltinType(block, size_src, size_val, std.builtin.Type.Pointer.Size); |
| 19805 | 19804 | |
| 19806 | | const attrs_uncoerced = try sema.resolveInst(extra.attrs); |
| 19805 | const attrs_uncoerced = sema.resolveInst(extra.attrs); |
| 19807 | 19806 | const attrs_coerced = try sema.coerce(block, attrs_ty, attrs_uncoerced, attrs_src); |
| 19808 | 19807 | const attrs_val = try sema.resolveConstDefinedValue(block, attrs_src, attrs_coerced, .{ .simple = .pointer_attrs }); |
| 19809 | 19808 | const attrs = try sema.interpretBuiltinType(block, attrs_src, attrs_val, std.builtin.Type.Pointer.Attributes); |
| ... | ... | @@ -19842,7 +19841,7 @@ fn zirReifyPointer( |
| 19842 | 19841 | } |
| 19843 | 19842 | |
| 19844 | 19843 | const sentinel_ty = try pt.optionalType(elem_ty.toIntern()); |
| 19845 | | const sentinel_uncoerced = try sema.resolveInst(extra.sentinel); |
| 19844 | const sentinel_uncoerced = sema.resolveInst(extra.sentinel); |
| 19846 | 19845 | const sentinel_coerced = try sema.coerce(block, sentinel_ty, sentinel_uncoerced, sentinel_src); |
| 19847 | 19846 | const sentinel_val = try sema.resolveConstDefinedValue(block, sentinel_src, sentinel_coerced, .{ .simple = .pointer_sentinel }); |
| 19848 | 19847 | const opt_sentinel = sentinel_val.optionalValue(zcu); |
| ... | ... | @@ -19896,7 +19895,7 @@ fn zirReifyFn( |
| 19896 | 19895 | const single_param_attrs_ty = try sema.getBuiltinType(param_attrs_src, .@"Type.Fn.Param.Attributes"); |
| 19897 | 19896 | const fn_attrs_ty = try sema.getBuiltinType(fn_attrs_src, .@"Type.Fn.Attributes"); |
| 19898 | 19897 | |
| 19899 | | const param_types_uncoerced = try sema.resolveInst(extra.param_types); |
| 19898 | const param_types_uncoerced = sema.resolveInst(extra.param_types); |
| 19900 | 19899 | const param_types_coerced = try sema.coerce(block, .slice_const_type, param_types_uncoerced, param_types_src); |
| 19901 | 19900 | const param_types_slice = try sema.resolveConstDefinedValue(block, param_types_src, param_types_coerced, .{ .simple = .fn_param_types }); |
| 19902 | 19901 | const param_types_arr = try sema.derefSliceAsArray(block, param_types_src, param_types_slice, .{ .simple = .fn_param_types }); |
| ... | ... | @@ -19907,7 +19906,7 @@ fn zirReifyFn( |
| 19907 | 19906 | .len = params_len, |
| 19908 | 19907 | .child = single_param_attrs_ty.toIntern(), |
| 19909 | 19908 | })); |
| 19910 | | const param_attrs_uncoerced = try sema.resolveInst(extra.param_attrs); |
| 19909 | const param_attrs_uncoerced = sema.resolveInst(extra.param_attrs); |
| 19911 | 19910 | const param_attrs_coerced = try sema.coerce(block, param_attrs_ty, param_attrs_uncoerced, param_attrs_src); |
| 19912 | 19911 | const param_attrs_slice = try sema.resolveConstDefinedValue(block, param_attrs_src, param_attrs_coerced, .{ .simple = .fn_param_attrs }); |
| 19913 | 19912 | const param_attrs_arr = try sema.derefSliceAsArray(block, param_attrs_src, param_attrs_slice, .{ .simple = .fn_param_attrs }); |
| ... | ... | @@ -19915,7 +19914,7 @@ fn zirReifyFn( |
| 19915 | 19914 | const ret_ty = try sema.resolveType(block, ret_ty_src, extra.ret_ty); |
| 19916 | 19915 | try sema.ensureLayoutResolved(ret_ty); |
| 19917 | 19916 | |
| 19918 | | const fn_attrs_uncoerced = try sema.resolveInst(extra.fn_attrs); |
| 19917 | const fn_attrs_uncoerced = sema.resolveInst(extra.fn_attrs); |
| 19919 | 19918 | const fn_attrs_coerced = try sema.coerce(block, fn_attrs_ty, fn_attrs_uncoerced, fn_attrs_src); |
| 19920 | 19919 | const fn_attrs_val = try sema.resolveConstDefinedValue(block, fn_attrs_src, fn_attrs_coerced, .{ .simple = .fn_attrs }); |
| 19921 | 19920 | const fn_attrs = try sema.interpretBuiltinType(block, fn_attrs_src, fn_attrs_val, std.builtin.Type.Fn.Attributes); |
| ... | ... | @@ -20041,16 +20040,16 @@ fn zirReifyStruct( |
| 20041 | 20040 | const container_layout_ty = try sema.getBuiltinType(layout_src, .@"Type.ContainerLayout"); |
| 20042 | 20041 | const single_field_attrs_ty = try sema.getBuiltinType(field_attrs_src, .@"Type.StructField.Attributes"); |
| 20043 | 20042 | |
| 20044 | | const layout_uncoerced = try sema.resolveInst(extra.layout); |
| 20043 | const layout_uncoerced = sema.resolveInst(extra.layout); |
| 20045 | 20044 | const layout_coerced = try sema.coerce(block, container_layout_ty, layout_uncoerced, layout_src); |
| 20046 | 20045 | const layout_val = try sema.resolveConstDefinedValue(block, layout_src, layout_coerced, .{ .simple = .struct_layout }); |
| 20047 | 20046 | const layout = try sema.interpretBuiltinType(block, layout_src, layout_val, std.builtin.Type.ContainerLayout); |
| 20048 | 20047 | |
| 20049 | | const backing_int_ty_uncoerced = try sema.resolveInst(extra.backing_ty); |
| 20048 | const backing_int_ty_uncoerced = sema.resolveInst(extra.backing_ty); |
| 20050 | 20049 | const backing_int_ty_coerced = try sema.coerce(block, .optional_type, backing_int_ty_uncoerced, backing_ty_src); |
| 20051 | 20050 | const backing_int_ty_val = try sema.resolveConstDefinedValue(block, backing_ty_src, backing_int_ty_coerced, .{ .simple = .packed_struct_backing_int_type }); |
| 20052 | 20051 | |
| 20053 | | const field_names_uncoerced = try sema.resolveInst(extra.field_names); |
| 20052 | const field_names_uncoerced = sema.resolveInst(extra.field_names); |
| 20054 | 20053 | const field_names_coerced = try sema.coerce(block, .slice_const_slice_const_u8, field_names_uncoerced, field_names_src); |
| 20055 | 20054 | const field_names_slice = try sema.resolveConstDefinedValue(block, field_names_src, field_names_coerced, .{ .simple = .struct_field_names }); |
| 20056 | 20055 | const field_names_arr = try sema.derefSliceAsArray(block, field_names_src, field_names_slice, .{ .simple = .struct_field_names }); |
| ... | ... | @@ -20066,12 +20065,12 @@ fn zirReifyStruct( |
| 20066 | 20065 | .child = single_field_attrs_ty.toIntern(), |
| 20067 | 20066 | })); |
| 20068 | 20067 | |
| 20069 | | const field_types_uncoerced = try sema.resolveInst(extra.field_types); |
| 20068 | const field_types_uncoerced = sema.resolveInst(extra.field_types); |
| 20070 | 20069 | const field_types_coerced = try sema.coerce(block, field_types_ty, field_types_uncoerced, field_types_src); |
| 20071 | 20070 | const field_types_slice = try sema.resolveConstDefinedValue(block, field_types_src, field_types_coerced, .{ .simple = .struct_field_types }); |
| 20072 | 20071 | const field_types_arr = try sema.derefSliceAsArray(block, field_types_src, field_types_slice, .{ .simple = .struct_field_types }); |
| 20073 | 20072 | |
| 20074 | | const field_attrs_uncoerced = try sema.resolveInst(extra.field_attrs); |
| 20073 | const field_attrs_uncoerced = sema.resolveInst(extra.field_attrs); |
| 20075 | 20074 | const field_attrs_coerced = try sema.coerce(block, field_attrs_ty, field_attrs_uncoerced, field_attrs_src); |
| 20076 | 20075 | const field_attrs_slice = try sema.resolveConstDefinedValue(block, field_attrs_src, field_attrs_coerced, .{ .simple = .struct_field_attrs }); |
| 20077 | 20076 | const field_attrs_arr = try sema.derefSliceAsArray(block, field_attrs_src, field_attrs_slice, .{ .simple = .struct_field_attrs }); |
| ... | ... | @@ -20328,19 +20327,19 @@ fn zirReifyUnion( |
| 20328 | 20327 | const container_layout_ty = try sema.getBuiltinType(layout_src, .@"Type.ContainerLayout"); |
| 20329 | 20328 | const single_field_attrs_ty = try sema.getBuiltinType(field_attrs_src, .@"Type.UnionField.Attributes"); |
| 20330 | 20329 | |
| 20331 | | const layout_uncoerced = try sema.resolveInst(extra.layout); |
| 20330 | const layout_uncoerced = sema.resolveInst(extra.layout); |
| 20332 | 20331 | const layout_coerced = try sema.coerce(block, container_layout_ty, layout_uncoerced, layout_src); |
| 20333 | 20332 | const layout_val = try sema.resolveConstDefinedValue(block, layout_src, layout_coerced, .{ .simple = .union_layout }); |
| 20334 | 20333 | const layout = try sema.interpretBuiltinType(block, layout_src, layout_val, std.builtin.Type.ContainerLayout); |
| 20335 | 20334 | |
| 20336 | | const arg_ty_uncoerced = try sema.resolveInst(extra.arg_ty); |
| 20335 | const arg_ty_uncoerced = sema.resolveInst(extra.arg_ty); |
| 20337 | 20336 | const arg_ty_coerced = try sema.coerce(block, .optional_type, arg_ty_uncoerced, arg_ty_src); |
| 20338 | 20337 | const arg_ty_val = try sema.resolveConstDefinedValue(block, arg_ty_src, arg_ty_coerced, switch (layout) { |
| 20339 | 20338 | .@"packed" => .{ .simple = .packed_union_backing_int_type }, |
| 20340 | 20339 | .auto, .@"extern" => .{ .simple = .union_enum_tag_type }, |
| 20341 | 20340 | }); |
| 20342 | 20341 | |
| 20343 | | const field_names_uncoerced = try sema.resolveInst(extra.field_names); |
| 20342 | const field_names_uncoerced = sema.resolveInst(extra.field_names); |
| 20344 | 20343 | const field_names_coerced = try sema.coerce(block, .slice_const_slice_const_u8, field_names_uncoerced, field_names_src); |
| 20345 | 20344 | const field_names_slice = try sema.resolveConstDefinedValue(block, field_names_src, field_names_coerced, .{ .simple = .union_field_names }); |
| 20346 | 20345 | const field_names_arr = try sema.derefSliceAsArray(block, field_names_src, field_names_slice, .{ .simple = .union_field_names }); |
| ... | ... | @@ -20356,12 +20355,12 @@ fn zirReifyUnion( |
| 20356 | 20355 | .child = single_field_attrs_ty.toIntern(), |
| 20357 | 20356 | })); |
| 20358 | 20357 | |
| 20359 | | const field_types_uncoerced = try sema.resolveInst(extra.field_types); |
| 20358 | const field_types_uncoerced = sema.resolveInst(extra.field_types); |
| 20360 | 20359 | const field_types_coerced = try sema.coerce(block, field_types_ty, field_types_uncoerced, field_types_src); |
| 20361 | 20360 | const field_types_slice = try sema.resolveConstDefinedValue(block, field_types_src, field_types_coerced, .{ .simple = .union_field_types }); |
| 20362 | 20361 | const field_types_arr = try sema.derefSliceAsArray(block, field_types_src, field_types_slice, .{ .simple = .union_field_types }); |
| 20363 | 20362 | |
| 20364 | | const field_attrs_uncoerced = try sema.resolveInst(extra.field_attrs); |
| 20363 | const field_attrs_uncoerced = sema.resolveInst(extra.field_attrs); |
| 20365 | 20364 | const field_attrs_coerced = try sema.coerce(block, field_attrs_ty, field_attrs_uncoerced, field_attrs_src); |
| 20366 | 20365 | const field_attrs_slice = try sema.resolveConstDefinedValue(block, field_attrs_src, field_attrs_coerced, .{ .simple = .union_field_attrs }); |
| 20367 | 20366 | const field_attrs_arr = try sema.derefSliceAsArray(block, field_attrs_src, field_attrs_slice, .{ .simple = .union_field_attrs }); |
| ... | ... | @@ -20549,12 +20548,12 @@ fn zirReifyEnum( |
| 20549 | 20548 | |
| 20550 | 20549 | const enum_mode_ty = try sema.getBuiltinType(mode_src, .@"Type.Enum.Mode"); |
| 20551 | 20550 | |
| 20552 | | const tag_ty_uncoerced = try sema.resolveInst(extra.tag_ty); |
| 20551 | const tag_ty_uncoerced = sema.resolveInst(extra.tag_ty); |
| 20553 | 20552 | const tag_ty_coerced = try sema.coerce(block, .type, tag_ty_uncoerced, tag_ty_src); |
| 20554 | 20553 | const tag_ty_val = try sema.resolveConstDefinedValue(block, tag_ty_src, tag_ty_coerced, .{ .simple = .enum_int_tag_type }); |
| 20555 | 20554 | const tag_ty = tag_ty_val.toType(); |
| 20556 | 20555 | |
| 20557 | | const mode_uncoerced = try sema.resolveInst(extra.mode); |
| 20556 | const mode_uncoerced = sema.resolveInst(extra.mode); |
| 20558 | 20557 | const mode_coerced = try sema.coerce(block, enum_mode_ty, mode_uncoerced, mode_src); |
| 20559 | 20558 | const mode_val = try sema.resolveConstDefinedValue(block, mode_src, mode_coerced, .{ .simple = .type }); |
| 20560 | 20559 | const nonexhaustive = switch (try sema.interpretBuiltinType(block, mode_src, mode_val, std.builtin.Type.Enum.Mode)) { |
| ... | ... | @@ -20562,7 +20561,7 @@ fn zirReifyEnum( |
| 20562 | 20561 | .nonexhaustive => true, |
| 20563 | 20562 | }; |
| 20564 | 20563 | |
| 20565 | | const field_names_uncoerced = try sema.resolveInst(extra.field_names); |
| 20564 | const field_names_uncoerced = sema.resolveInst(extra.field_names); |
| 20566 | 20565 | const field_names_coerced = try sema.coerce(block, .slice_const_slice_const_u8, field_names_uncoerced, field_names_src); |
| 20567 | 20566 | const field_names_slice = try sema.resolveConstDefinedValue(block, field_names_src, field_names_coerced, .{ .simple = .enum_field_names }); |
| 20568 | 20567 | const field_names_arr = try sema.derefSliceAsArray(block, field_names_src, field_names_slice, .{ .simple = .enum_field_names }); |
| ... | ... | @@ -20574,7 +20573,7 @@ fn zirReifyEnum( |
| 20574 | 20573 | .child = tag_ty.toIntern(), |
| 20575 | 20574 | })); |
| 20576 | 20575 | |
| 20577 | | const field_values_uncoerced = try sema.resolveInst(extra.field_values); |
| 20576 | const field_values_uncoerced = sema.resolveInst(extra.field_values); |
| 20578 | 20577 | const field_values_coerced = try sema.coerce(block, field_values_ty, field_values_uncoerced, field_values_src); |
| 20579 | 20578 | const field_values_slice = try sema.resolveConstDefinedValue(block, field_values_src, field_values_coerced, .{ .simple = .enum_field_values }); |
| 20580 | 20579 | const field_values_arr = try sema.derefSliceAsArray(block, field_values_src, field_values_slice, .{ .simple = .enum_field_values }); |
| ... | ... | @@ -20663,7 +20662,7 @@ fn resolveVaListRef(sema: *Sema, block: *Block, src: LazySrcLoc, zir_ref: Zir.In |
| 20663 | 20662 | const va_list_ty = try sema.getBuiltinType(src, .VaList); |
| 20664 | 20663 | const va_list_ptr = try pt.singleMutPtrType(va_list_ty); |
| 20665 | 20664 | |
| 20666 | | const inst = try sema.resolveInst(zir_ref); |
| 20665 | const inst = sema.resolveInst(zir_ref); |
| 20667 | 20666 | return sema.coerce(block, va_list_ptr, inst, src); |
| 20668 | 20667 | } |
| 20669 | 20668 | |
| ... | ... | @@ -20759,7 +20758,7 @@ fn zirIntFromFloat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro |
| 20759 | 20758 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 20760 | 20759 | const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0); |
| 20761 | 20760 | const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu_opt, "@intFromFloat"); |
| 20762 | | const operand = try sema.resolveInst(extra.rhs); |
| 20761 | const operand = sema.resolveInst(extra.rhs); |
| 20763 | 20762 | const operand_ty = sema.typeOf(operand); |
| 20764 | 20763 | |
| 20765 | 20764 | try sema.checkVectorizableBinaryOperands(block, operand_src, dest_ty, operand_ty, src, operand_src); |
| ... | ... | @@ -20771,7 +20770,7 @@ fn zirIntFromFloat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro |
| 20771 | 20770 | _ = try sema.checkIntType(block, src, dest_scalar_ty); |
| 20772 | 20771 | try sema.checkFloatType(block, operand_src, operand_scalar_ty); |
| 20773 | 20772 | |
| 20774 | | if (try sema.resolveValue(operand)) |operand_val| { |
| 20773 | if (sema.resolveValue(operand)) |operand_val| { |
| 20775 | 20774 | const result_val = try sema.intFromFloat(block, operand_src, operand_val, operand_ty, dest_ty, .truncate); |
| 20776 | 20775 | return Air.internedToRef(result_val.toIntern()); |
| 20777 | 20776 | } else if (dest_scalar_ty.zigTypeTag(zcu) == .comptime_int) { |
| ... | ... | @@ -20812,7 +20811,7 @@ fn zirFloatFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro |
| 20812 | 20811 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 20813 | 20812 | const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0); |
| 20814 | 20813 | const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu_opt, "@floatFromInt"); |
| 20815 | | const operand = try sema.resolveInst(extra.rhs); |
| 20814 | const operand = sema.resolveInst(extra.rhs); |
| 20816 | 20815 | const operand_ty = sema.typeOf(operand); |
| 20817 | 20816 | |
| 20818 | 20817 | try sema.checkVectorizableBinaryOperands(block, operand_src, dest_ty, operand_ty, src, operand_src); |
| ... | ... | @@ -20823,7 +20822,7 @@ fn zirFloatFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro |
| 20823 | 20822 | try sema.checkFloatType(block, src, dest_scalar_ty); |
| 20824 | 20823 | _ = try sema.checkIntType(block, operand_src, operand_scalar_ty); |
| 20825 | 20824 | |
| 20826 | | if (try sema.resolveValue(operand)) |operand_val| { |
| 20825 | if (sema.resolveValue(operand)) |operand_val| { |
| 20827 | 20826 | if (operand_val.isUndef(zcu)) return .fromValue(try pt.undefValue(dest_ty)); |
| 20828 | 20827 | if (dest_ty.zigTypeTag(zcu) != .vector) { |
| 20829 | 20828 | return .fromValue(try pt.floatValue(dest_ty, operand_val.toFloat(f128, zcu))); |
| ... | ... | @@ -20855,7 +20854,7 @@ fn zirPtrFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! |
| 20855 | 20854 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 20856 | 20855 | |
| 20857 | 20856 | const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0); |
| 20858 | | const operand_res = try sema.resolveInst(extra.rhs); |
| 20857 | const operand_res = sema.resolveInst(extra.rhs); |
| 20859 | 20858 | |
| 20860 | 20859 | const uncoerced_operand_ty = sema.typeOf(operand_res); |
| 20861 | 20860 | const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu, "@ptrFromInt"); |
| ... | ... | @@ -20983,7 +20982,7 @@ fn zirErrorCast(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData |
| 20983 | 20982 | const src = block.nodeOffset(extra.node); |
| 20984 | 20983 | const operand_src = block.builtinCallArgSrc(extra.node, 0); |
| 20985 | 20984 | const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_opt, "@errorCast"); |
| 20986 | | const operand = try sema.resolveInst(extra.rhs); |
| 20985 | const operand = sema.resolveInst(extra.rhs); |
| 20987 | 20986 | const operand_ty = sema.typeOf(operand); |
| 20988 | 20987 | |
| 20989 | 20988 | const dest_tag = dest_ty.zigTypeTag(zcu); |
| ... | ... | @@ -21134,7 +21133,7 @@ fn zirPtrCastFull(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDa |
| 21134 | 21133 | const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data; |
| 21135 | 21134 | const src = block.nodeOffset(extra.node); |
| 21136 | 21135 | const operand_src = block.src(.{ .node_offset_ptrcast_operand = extra.node }); |
| 21137 | | const operand = try sema.resolveInst(extra.rhs); |
| 21136 | const operand = sema.resolveInst(extra.rhs); |
| 21138 | 21137 | const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu, flags.needResultTypeBuiltinName()); |
| 21139 | 21138 | return sema.ptrCastFull( |
| 21140 | 21139 | block, |
| ... | ... | @@ -21153,7 +21152,7 @@ fn zirPtrCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 21153 | 21152 | const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0); |
| 21154 | 21153 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 21155 | 21154 | const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu, "@ptrCast"); |
| 21156 | | const operand = try sema.resolveInst(extra.rhs); |
| 21155 | const operand = sema.resolveInst(extra.rhs); |
| 21157 | 21156 | |
| 21158 | 21157 | return sema.ptrCastFull( |
| 21159 | 21158 | block, |
| ... | ... | @@ -21219,7 +21218,7 @@ fn ptrCastFull( |
| 21219 | 21218 | }; |
| 21220 | 21219 | }, |
| 21221 | 21220 | .slice => src: { |
| 21222 | | const operand_val = try sema.resolveValue(operand) orelse break :src .{ .fromInterned(src_info.child), null }; |
| 21221 | const operand_val = sema.resolveValue(operand) orelse break :src .{ .fromInterned(src_info.child), null }; |
| 21223 | 21222 | if (operand_val.isUndef(zcu)) break :len .undef; |
| 21224 | 21223 | const slice_val = switch (operand_ty.zigTypeTag(zcu)) { |
| 21225 | 21224 | .optional => operand_val.optionalValue(zcu) orelse break :len .undef, |
| ... | ... | @@ -21516,7 +21515,7 @@ fn ptrCastFull( |
| 21516 | 21515 | |
| 21517 | 21516 | ct: { |
| 21518 | 21517 | if (flags.addrspace_cast) break :ct; // cannot `@addrSpaceCast` at comptime |
| 21519 | | const operand_val = try sema.resolveValue(operand) orelse break :ct; |
| 21518 | const operand_val = sema.resolveValue(operand) orelse break :ct; |
| 21520 | 21519 | |
| 21521 | 21520 | if (operand_val.isUndef(zcu)) { |
| 21522 | 21521 | if (!dest_ty.ptrAllowsZero(zcu)) { |
| ... | ... | @@ -21776,7 +21775,7 @@ fn zirPtrCastNoDest(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.Inst |
| 21776 | 21775 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; |
| 21777 | 21776 | const src = block.nodeOffset(extra.node); |
| 21778 | 21777 | const operand_src = block.src(.{ .node_offset_ptrcast_operand = extra.node }); |
| 21779 | | const operand = try sema.resolveInst(extra.operand); |
| 21778 | const operand = sema.resolveInst(extra.operand); |
| 21780 | 21779 | const operand_ty = sema.typeOf(operand); |
| 21781 | 21780 | try sema.checkPtrOperand(block, operand_src, operand_ty); |
| 21782 | 21781 | |
| ... | ... | @@ -21792,7 +21791,7 @@ fn zirPtrCastNoDest(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.Inst |
| 21792 | 21791 | break :blk dest_ty; |
| 21793 | 21792 | }; |
| 21794 | 21793 | |
| 21795 | | if (try sema.resolveValue(operand)) |operand_val| { |
| 21794 | if (sema.resolveValue(operand)) |operand_val| { |
| 21796 | 21795 | return Air.internedToRef((try pt.getCoerced(operand_val, dest_ty)).toIntern()); |
| 21797 | 21796 | } |
| 21798 | 21797 | |
| ... | ... | @@ -21811,7 +21810,7 @@ fn zirTruncate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 21811 | 21810 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 21812 | 21811 | const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu_opt, "@truncate"); |
| 21813 | 21812 | const dest_scalar_ty = try sema.checkIntOrVectorAllowComptime(block, dest_ty, src); |
| 21814 | | const operand = try sema.resolveInst(extra.rhs); |
| 21813 | const operand = sema.resolveInst(extra.rhs); |
| 21815 | 21814 | const operand_ty = sema.typeOf(operand); |
| 21816 | 21815 | const operand_scalar_ty = try sema.checkIntOrVectorAllowComptime(block, operand_ty, operand_src); |
| 21817 | 21816 | |
| ... | ... | @@ -21842,7 +21841,7 @@ fn zirTruncate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 21842 | 21841 | } |
| 21843 | 21842 | } |
| 21844 | 21843 | |
| 21845 | | if (try sema.resolveValue(operand)) |val| { |
| 21844 | if (sema.resolveValue(operand)) |val| { |
| 21846 | 21845 | const result_val = try arith.truncate(sema, val, operand_ty, dest_ty, dest_info.signedness, dest_info.bits); |
| 21847 | 21846 | return Air.internedToRef(result_val.toIntern()); |
| 21848 | 21847 | } |
| ... | ... | @@ -21863,7 +21862,7 @@ fn zirBitCount( |
| 21863 | 21862 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 21864 | 21863 | const src = block.nodeOffset(inst_data.src_node); |
| 21865 | 21864 | const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0); |
| 21866 | | const operand = try sema.resolveInst(inst_data.operand); |
| 21865 | const operand = sema.resolveInst(inst_data.operand); |
| 21867 | 21866 | const operand_ty = sema.typeOf(operand); |
| 21868 | 21867 | _ = try sema.checkIntOrVector(block, operand, operand_src); |
| 21869 | 21868 | const bits = operand_ty.intInfo(zcu).bits; |
| ... | ... | @@ -21876,7 +21875,7 @@ fn zirBitCount( |
| 21876 | 21875 | .len = vec_len, |
| 21877 | 21876 | .child = result_scalar_ty.toIntern(), |
| 21878 | 21877 | }); |
| 21879 | | if (try sema.resolveValue(operand)) |val| { |
| 21878 | if (sema.resolveValue(operand)) |val| { |
| 21880 | 21879 | if (val.isUndef(zcu)) return pt.undefRef(result_ty); |
| 21881 | 21880 | |
| 21882 | 21881 | const elems = try sema.arena.alloc(InternPool.Index, vec_len); |
| ... | ... | @@ -21893,7 +21892,7 @@ fn zirBitCount( |
| 21893 | 21892 | } |
| 21894 | 21893 | }, |
| 21895 | 21894 | .int => { |
| 21896 | | if (try sema.resolveValue(operand)) |val| { |
| 21895 | if (sema.resolveValue(operand)) |val| { |
| 21897 | 21896 | if (val.isUndef(zcu)) return pt.undefRef(result_scalar_ty); |
| 21898 | 21897 | return pt.intRef(result_scalar_ty, comptimeOp(val, operand_ty, zcu)); |
| 21899 | 21898 | } else { |
| ... | ... | @@ -21910,7 +21909,7 @@ fn zirByteSwap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 21910 | 21909 | const zcu = pt.zcu; |
| 21911 | 21910 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 21912 | 21911 | const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0); |
| 21913 | | const operand = try sema.resolveInst(inst_data.operand); |
| 21912 | const operand = sema.resolveInst(inst_data.operand); |
| 21914 | 21913 | const operand_ty = sema.typeOf(operand); |
| 21915 | 21914 | const scalar_ty = try sema.checkIntOrVector(block, operand, operand_src); |
| 21916 | 21915 | const bits = scalar_ty.intInfo(zcu).bits; |
| ... | ... | @@ -21922,7 +21921,7 @@ fn zirByteSwap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 21922 | 21921 | .{ scalar_ty.fmt(pt), bits }, |
| 21923 | 21922 | ); |
| 21924 | 21923 | } |
| 21925 | | if (try sema.resolveValue(operand)) |operand_val| { |
| 21924 | if (sema.resolveValue(operand)) |operand_val| { |
| 21926 | 21925 | return .fromValue(try arith.byteSwap(sema, operand_val, operand_ty)); |
| 21927 | 21926 | } |
| 21928 | 21927 | return block.addTyOp(.byte_swap, operand_ty, operand); |
| ... | ... | @@ -21931,11 +21930,11 @@ fn zirByteSwap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 21931 | 21930 | fn zirBitReverse(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 21932 | 21931 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 21933 | 21932 | const operand_src = block.builtinCallArgSrc(inst_data.src_node, 0); |
| 21934 | | const operand = try sema.resolveInst(inst_data.operand); |
| 21933 | const operand = sema.resolveInst(inst_data.operand); |
| 21935 | 21934 | const operand_ty = sema.typeOf(operand); |
| 21936 | 21935 | _ = try sema.checkIntOrVector(block, operand, operand_src); |
| 21937 | 21936 | |
| 21938 | | if (try sema.resolveValue(operand)) |operand_val| { |
| 21937 | if (sema.resolveValue(operand)) |operand_val| { |
| 21939 | 21938 | return .fromValue(try arith.bitReverse(sema, operand_val, operand_ty)); |
| 21940 | 21939 | } |
| 21941 | 21940 | return block.addTyOp(.bit_reverse, operand_ty, operand); |
| ... | ... | @@ -22359,8 +22358,8 @@ fn checkSimdBinOp( |
| 22359 | 22358 | .len = vec_len, |
| 22360 | 22359 | .lhs = lhs, |
| 22361 | 22360 | .rhs = rhs, |
| 22362 | | .lhs_val = try sema.resolveValue(lhs), |
| 22363 | | .rhs_val = try sema.resolveValue(rhs), |
| 22361 | .lhs_val = sema.resolveValue(lhs), |
| 22362 | .rhs_val = sema.resolveValue(rhs), |
| 22364 | 22363 | .result_ty = result_ty, |
| 22365 | 22364 | .scalar_ty = result_ty.scalarType(zcu), |
| 22366 | 22365 | }; |
| ... | ... | @@ -22452,7 +22451,7 @@ fn resolveExportOptions( |
| 22452 | 22451 | const ip = &zcu.intern_pool; |
| 22453 | 22452 | |
| 22454 | 22453 | const export_options_ty = try sema.getBuiltinType(src, .ExportOptions); |
| 22455 | | const air_ref = try sema.resolveInst(zir_ref); |
| 22454 | const air_ref = sema.resolveInst(zir_ref); |
| 22456 | 22455 | const options = try sema.coerce(block, export_options_ty, air_ref, src); |
| 22457 | 22456 | |
| 22458 | 22457 | const name_src = block.src(.{ .init_field_name = src.offset.node_offset_builtin_call_arg.builtin_call_node }); |
| ... | ... | @@ -22505,7 +22504,7 @@ fn resolveBuiltinEnum( |
| 22505 | 22504 | reason: ComptimeReason, |
| 22506 | 22505 | ) CompileError!@field(std.builtin, @tagName(name)) { |
| 22507 | 22506 | const ty = try sema.getBuiltinType(src, name); |
| 22508 | | const air_ref = try sema.resolveInst(zir_ref); |
| 22507 | const air_ref = sema.resolveInst(zir_ref); |
| 22509 | 22508 | const coerced = try sema.coerce(block, ty, air_ref, src); |
| 22510 | 22509 | const val = try sema.resolveConstDefinedValue(block, src, coerced, reason); |
| 22511 | 22510 | return sema.interpretBuiltinType(block, src, val, @field(std.builtin, @tagName(name))); |
| ... | ... | @@ -22552,7 +22551,7 @@ fn zirCmpxchg( |
| 22552 | 22551 | const success_order_src = block.builtinCallArgSrc(extra.node, 4); |
| 22553 | 22552 | const failure_order_src = block.builtinCallArgSrc(extra.node, 5); |
| 22554 | 22553 | // zig fmt: on |
| 22555 | | const expected_value = try sema.resolveInst(extra.expected_value); |
| 22554 | const expected_value = sema.resolveInst(extra.expected_value); |
| 22556 | 22555 | const elem_ty = sema.typeOf(expected_value); |
| 22557 | 22556 | if (elem_ty.zigTypeTag(zcu) == .float) { |
| 22558 | 22557 | return sema.fail( |
| ... | ... | @@ -22562,9 +22561,9 @@ fn zirCmpxchg( |
| 22562 | 22561 | .{elem_ty.fmt(pt)}, |
| 22563 | 22562 | ); |
| 22564 | 22563 | } |
| 22565 | | const uncasted_ptr = try sema.resolveInst(extra.ptr); |
| 22564 | const uncasted_ptr = sema.resolveInst(extra.ptr); |
| 22566 | 22565 | const ptr = try sema.checkAtomicPtrOperand(block, elem_ty, elem_ty_src, uncasted_ptr, ptr_src, false); |
| 22567 | | const new_value = try sema.coerce(block, elem_ty, try sema.resolveInst(extra.new_value), new_value_src); |
| 22566 | const new_value = try sema.coerce(block, elem_ty, sema.resolveInst(extra.new_value), new_value_src); |
| 22568 | 22567 | const success_order = try sema.resolveAtomicOrder(block, success_order_src, extra.success_order, .{ .simple = .atomic_order }); |
| 22569 | 22568 | const failure_order = try sema.resolveAtomicOrder(block, failure_order_src, extra.failure_order, .{ .simple = .atomic_order }); |
| 22570 | 22569 | |
| ... | ... | @@ -22589,8 +22588,8 @@ fn zirCmpxchg( |
| 22589 | 22588 | } |
| 22590 | 22589 | |
| 22591 | 22590 | const runtime_src = if (try sema.resolveDefinedValue(block, ptr_src, ptr)) |ptr_val| rs: { |
| 22592 | | if (try sema.resolveValue(expected_value)) |expected_val| { |
| 22593 | | if (try sema.resolveValue(new_value)) |new_val| { |
| 22591 | if (sema.resolveValue(expected_value)) |expected_val| { |
| 22592 | if (sema.resolveValue(new_value)) |new_val| { |
| 22594 | 22593 | if (expected_val.isUndef(zcu) or new_val.isUndef(zcu)) { |
| 22595 | 22594 | // TODO: this should probably cause the memory stored at the pointer |
| 22596 | 22595 | // to become undef as well |
| ... | ... | @@ -22642,7 +22641,7 @@ fn zirSplat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.I |
| 22642 | 22641 | else => return sema.fail(block, src, "expected array or vector type, found '{f}'", .{dest_ty.fmt(pt)}), |
| 22643 | 22642 | } |
| 22644 | 22643 | |
| 22645 | | const operand = try sema.resolveInst(extra.rhs); |
| 22644 | const operand = sema.resolveInst(extra.rhs); |
| 22646 | 22645 | const scalar_ty = dest_ty.childType(zcu); |
| 22647 | 22646 | const scalar = try sema.coerce(block, scalar_ty, operand, scalar_src); |
| 22648 | 22647 | |
| ... | ... | @@ -22653,7 +22652,7 @@ fn zirSplat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.I |
| 22653 | 22652 | |
| 22654 | 22653 | const maybe_sentinel = dest_ty.sentinel(zcu); |
| 22655 | 22654 | |
| 22656 | | if (try sema.resolveValue(scalar)) |scalar_val| { |
| 22655 | if (sema.resolveValue(scalar)) |scalar_val| { |
| 22657 | 22656 | full: { |
| 22658 | 22657 | if (dest_ty.zigTypeTag(zcu) == .vector) break :full; |
| 22659 | 22658 | const sentinel = maybe_sentinel orelse break :full; |
| ... | ... | @@ -22688,7 +22687,7 @@ fn zirReduce(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. |
| 22688 | 22687 | const op_src = block.builtinCallArgSrc(inst_data.src_node, 0); |
| 22689 | 22688 | const operand_src = block.builtinCallArgSrc(inst_data.src_node, 1); |
| 22690 | 22689 | const operation = try sema.resolveBuiltinEnum(block, op_src, extra.lhs, .ReduceOp, .{ .simple = .operand_reduce_operation }); |
| 22691 | | const operand = try sema.resolveInst(extra.rhs); |
| 22690 | const operand = sema.resolveInst(extra.rhs); |
| 22692 | 22691 | const operand_ty = sema.typeOf(operand); |
| 22693 | 22692 | const pt = sema.pt; |
| 22694 | 22693 | const zcu = pt.zcu; |
| ... | ... | @@ -22722,7 +22721,7 @@ fn zirReduce(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. |
| 22722 | 22721 | return sema.fail(block, operand_src, "@reduce operation requires a vector with nonzero length", .{}); |
| 22723 | 22722 | } |
| 22724 | 22723 | |
| 22725 | | if (try sema.resolveValue(operand)) |operand_val| { |
| 22724 | if (sema.resolveValue(operand)) |operand_val| { |
| 22726 | 22725 | if (operand_val.isUndef(zcu)) return pt.undefRef(scalar_ty); |
| 22727 | 22726 | |
| 22728 | 22727 | var accum: Value = try operand_val.elemValue(pt, 0); |
| ... | ... | @@ -22758,9 +22757,9 @@ fn zirShuffle(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 22758 | 22757 | |
| 22759 | 22758 | const elem_ty = try sema.resolveType(block, elem_ty_src, extra.elem_type); |
| 22760 | 22759 | try sema.checkVectorElemType(block, elem_ty_src, elem_ty); |
| 22761 | | const a = try sema.resolveInst(extra.a); |
| 22762 | | const b = try sema.resolveInst(extra.b); |
| 22763 | | var mask = try sema.resolveInst(extra.mask); |
| 22760 | const a = sema.resolveInst(extra.a); |
| 22761 | const b = sema.resolveInst(extra.b); |
| 22762 | var mask = sema.resolveInst(extra.mask); |
| 22764 | 22763 | var mask_ty = sema.typeOf(mask); |
| 22765 | 22764 | |
| 22766 | 22765 | const mask_len = switch (sema.typeOf(mask).zigTypeTag(zcu)) { |
| ... | ... | @@ -22867,8 +22866,8 @@ fn analyzeShuffle( |
| 22867 | 22866 | } |
| 22868 | 22867 | } |
| 22869 | 22868 | |
| 22870 | | const maybe_a_val = try sema.resolveValue(a_coerced); |
| 22871 | | const maybe_b_val = try sema.resolveValue(b_coerced); |
| 22869 | const maybe_a_val = sema.resolveValue(a_coerced); |
| 22870 | const maybe_b_val = sema.resolveValue(b_coerced); |
| 22872 | 22871 | |
| 22873 | 22872 | const a_rt = a_used and maybe_a_val == null; |
| 22874 | 22873 | const b_rt = b_used and maybe_b_val == null; |
| ... | ... | @@ -22956,7 +22955,7 @@ fn zirSelect(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) C |
| 22956 | 22955 | |
| 22957 | 22956 | const elem_ty = try sema.resolveType(block, elem_ty_src, extra.elem_type); |
| 22958 | 22957 | try sema.checkVectorElemType(block, elem_ty_src, elem_ty); |
| 22959 | | const pred_uncoerced = try sema.resolveInst(extra.pred); |
| 22958 | const pred_uncoerced = sema.resolveInst(extra.pred); |
| 22960 | 22959 | const pred_ty = sema.typeOf(pred_uncoerced); |
| 22961 | 22960 | |
| 22962 | 22961 | const vec_len_u64 = switch (pred_ty.zigTypeTag(zcu)) { |
| ... | ... | @@ -22975,12 +22974,12 @@ fn zirSelect(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) C |
| 22975 | 22974 | .len = vec_len, |
| 22976 | 22975 | .child = elem_ty.toIntern(), |
| 22977 | 22976 | }); |
| 22978 | | const a = try sema.coerce(block, vec_ty, try sema.resolveInst(extra.a), a_src); |
| 22979 | | const b = try sema.coerce(block, vec_ty, try sema.resolveInst(extra.b), b_src); |
| 22977 | const a = try sema.coerce(block, vec_ty, sema.resolveInst(extra.a), a_src); |
| 22978 | const b = try sema.coerce(block, vec_ty, sema.resolveInst(extra.b), b_src); |
| 22980 | 22979 | |
| 22981 | | const maybe_pred = try sema.resolveValue(pred); |
| 22982 | | const maybe_a = try sema.resolveValue(a); |
| 22983 | | const maybe_b = try sema.resolveValue(b); |
| 22980 | const maybe_pred = sema.resolveValue(pred); |
| 22981 | const maybe_a = sema.resolveValue(a); |
| 22982 | const maybe_b = sema.resolveValue(b); |
| 22984 | 22983 | |
| 22985 | 22984 | const runtime_src = if (maybe_pred) |pred_val| rs: { |
| 22986 | 22985 | if (pred_val.isUndef(zcu)) return pt.undefRef(vec_ty); |
| ... | ... | @@ -23041,7 +23040,7 @@ fn zirAtomicLoad(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! |
| 23041 | 23040 | const order_src = block.builtinCallArgSrc(inst_data.src_node, 2); |
| 23042 | 23041 | // zig fmt: on |
| 23043 | 23042 | const elem_ty = try sema.resolveType(block, elem_ty_src, extra.elem_type); |
| 23044 | | const uncasted_ptr = try sema.resolveInst(extra.ptr); |
| 23043 | const uncasted_ptr = sema.resolveInst(extra.ptr); |
| 23045 | 23044 | const ptr = try sema.checkAtomicPtrOperand(block, elem_ty, elem_ty_src, uncasted_ptr, ptr_src, true); |
| 23046 | 23045 | const order = try sema.resolveAtomicOrder(block, order_src, extra.ordering, .{ .simple = .atomic_order }); |
| 23047 | 23046 | |
| ... | ... | @@ -23090,9 +23089,9 @@ fn zirAtomicRmw(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 23090 | 23089 | const operand_src = block.builtinCallArgSrc(inst_data.src_node, 3); |
| 23091 | 23090 | const order_src = block.builtinCallArgSrc(inst_data.src_node, 4); |
| 23092 | 23091 | // zig fmt: on |
| 23093 | | const operand = try sema.resolveInst(extra.operand); |
| 23092 | const operand = sema.resolveInst(extra.operand); |
| 23094 | 23093 | const elem_ty = sema.typeOf(operand); |
| 23095 | | const uncasted_ptr = try sema.resolveInst(extra.ptr); |
| 23094 | const uncasted_ptr = sema.resolveInst(extra.ptr); |
| 23096 | 23095 | const ptr = try sema.checkAtomicPtrOperand(block, elem_ty, elem_ty_src, uncasted_ptr, ptr_src, false); |
| 23097 | 23096 | const op = try sema.resolveAtomicRmwOp(block, op_src, extra.operation); |
| 23098 | 23097 | |
| ... | ... | @@ -23119,7 +23118,7 @@ fn zirAtomicRmw(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 23119 | 23118 | if (try elem_ty.onePossibleValue(pt)) |opv| return .fromValue(opv); |
| 23120 | 23119 | |
| 23121 | 23120 | const runtime_src = if (try sema.resolveDefinedValue(block, ptr_src, ptr)) |ptr_val| rs: { |
| 23122 | | const maybe_operand_val = try sema.resolveValue(operand); |
| 23121 | const maybe_operand_val = sema.resolveValue(operand); |
| 23123 | 23122 | const operand_val = maybe_operand_val orelse { |
| 23124 | 23123 | try sema.checkPtrIsNotComptimeMutable(block, ptr_val, ptr_src, operand_src); |
| 23125 | 23124 | break :rs operand_src; |
| ... | ... | @@ -23170,9 +23169,9 @@ fn zirAtomicStore(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 23170 | 23169 | const operand_src = block.builtinCallArgSrc(inst_data.src_node, 2); |
| 23171 | 23170 | const order_src = block.builtinCallArgSrc(inst_data.src_node, 3); |
| 23172 | 23171 | // zig fmt: on |
| 23173 | | const operand = try sema.resolveInst(extra.operand); |
| 23172 | const operand = sema.resolveInst(extra.operand); |
| 23174 | 23173 | const elem_ty = sema.typeOf(operand); |
| 23175 | | const uncasted_ptr = try sema.resolveInst(extra.ptr); |
| 23174 | const uncasted_ptr = sema.resolveInst(extra.ptr); |
| 23176 | 23175 | const ptr = try sema.checkAtomicPtrOperand(block, elem_ty, elem_ty_src, uncasted_ptr, ptr_src, false); |
| 23177 | 23176 | const order = try sema.resolveAtomicOrder(block, order_src, extra.ordering, .{ .simple = .atomic_order }); |
| 23178 | 23177 | |
| ... | ... | @@ -23203,14 +23202,14 @@ fn zirMulAdd(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. |
| 23203 | 23202 | const mulend2_src = block.builtinCallArgSrc(inst_data.src_node, 2); |
| 23204 | 23203 | const addend_src = block.builtinCallArgSrc(inst_data.src_node, 3); |
| 23205 | 23204 | |
| 23206 | | const addend = try sema.resolveInst(extra.addend); |
| 23205 | const addend = sema.resolveInst(extra.addend); |
| 23207 | 23206 | const ty = sema.typeOf(addend); |
| 23208 | | const mulend1 = try sema.coerce(block, ty, try sema.resolveInst(extra.mulend1), mulend1_src); |
| 23209 | | const mulend2 = try sema.coerce(block, ty, try sema.resolveInst(extra.mulend2), mulend2_src); |
| 23207 | const mulend1 = try sema.coerce(block, ty, sema.resolveInst(extra.mulend1), mulend1_src); |
| 23208 | const mulend2 = try sema.coerce(block, ty, sema.resolveInst(extra.mulend2), mulend2_src); |
| 23210 | 23209 | |
| 23211 | | const maybe_mulend1 = try sema.resolveValue(mulend1); |
| 23212 | | const maybe_mulend2 = try sema.resolveValue(mulend2); |
| 23213 | | const maybe_addend = try sema.resolveValue(addend); |
| 23210 | const maybe_mulend1 = sema.resolveValue(mulend1); |
| 23211 | const maybe_mulend2 = sema.resolveValue(mulend2); |
| 23212 | const maybe_addend = sema.resolveValue(addend); |
| 23214 | 23213 | const pt = sema.pt; |
| 23215 | 23214 | const zcu = pt.zcu; |
| 23216 | 23215 | |
| ... | ... | @@ -23272,10 +23271,10 @@ fn zirBuiltinCall(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 23272 | 23271 | const call_src = block.nodeOffset(inst_data.src_node); |
| 23273 | 23272 | |
| 23274 | 23273 | const extra = sema.code.extraData(Zir.Inst.BuiltinCall, inst_data.payload_index).data; |
| 23275 | | const func = try sema.resolveInst(extra.callee); |
| 23274 | const func = sema.resolveInst(extra.callee); |
| 23276 | 23275 | |
| 23277 | 23276 | const modifier_ty = try sema.getBuiltinType(call_src, .CallModifier); |
| 23278 | | const air_ref = try sema.resolveInst(extra.modifier); |
| 23277 | const air_ref = sema.resolveInst(extra.modifier); |
| 23279 | 23278 | const modifier_ref = try sema.coerce(block, modifier_ty, air_ref, modifier_src); |
| 23280 | 23279 | const modifier_val = try sema.resolveConstDefinedValue(block, modifier_src, modifier_ref, .{ .simple = .call_modifier }); |
| 23281 | 23280 | var modifier = try sema.interpretBuiltinType(block, modifier_src, modifier_val, std.builtin.CallModifier); |
| ... | ... | @@ -23313,7 +23312,7 @@ fn zirBuiltinCall(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 23313 | 23312 | }, |
| 23314 | 23313 | } |
| 23315 | 23314 | |
| 23316 | | const args = try sema.resolveInst(extra.args); |
| 23315 | const args = sema.resolveInst(extra.args); |
| 23317 | 23316 | |
| 23318 | 23317 | const args_ty = sema.typeOf(args); |
| 23319 | 23318 | if (!args_ty.isTuple(zcu)) { |
| ... | ... | @@ -23390,7 +23389,7 @@ fn zirFieldParentPtr(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.Ins |
| 23390 | 23389 | return sema.fail(block, field_name_src, "cannot get @fieldParentPtr of a comptime field", .{}); |
| 23391 | 23390 | } |
| 23392 | 23391 | |
| 23393 | | const field_ptr = try sema.resolveInst(extra.field_ptr); |
| 23392 | const field_ptr = sema.resolveInst(extra.field_ptr); |
| 23394 | 23393 | const field_ptr_ty = sema.typeOf(field_ptr); |
| 23395 | 23394 | try sema.checkPtrOperand(block, field_ptr_src, field_ptr_ty); |
| 23396 | 23395 | const field_ptr_info = field_ptr_ty.ptrInfo(zcu); |
| ... | ... | @@ -23555,8 +23554,8 @@ fn zirMinMax( |
| 23555 | 23554 | const src = block.nodeOffset(inst_data.src_node); |
| 23556 | 23555 | const lhs_src = block.builtinCallArgSrc(inst_data.src_node, 0); |
| 23557 | 23556 | const rhs_src = block.builtinCallArgSrc(inst_data.src_node, 1); |
| 23558 | | const lhs = try sema.resolveInst(extra.lhs); |
| 23559 | | const rhs = try sema.resolveInst(extra.rhs); |
| 23557 | const lhs = sema.resolveInst(extra.lhs); |
| 23558 | const rhs = sema.resolveInst(extra.rhs); |
| 23560 | 23559 | return sema.analyzeMinMax(block, src, air_tag, &.{ lhs, rhs }, &.{ lhs_src, rhs_src }); |
| 23561 | 23560 | } |
| 23562 | 23561 | |
| ... | ... | @@ -23576,7 +23575,7 @@ fn zirMinMaxMulti( |
| 23576 | 23575 | |
| 23577 | 23576 | for (operands, air_refs, operand_srcs, 0..) |zir_ref, *air_ref, *op_src, i| { |
| 23578 | 23577 | op_src.* = block.builtinCallArgSrc(src_node, @intCast(i)); |
| 23579 | | air_ref.* = try sema.resolveInst(zir_ref); |
| 23578 | air_ref.* = sema.resolveInst(zir_ref); |
| 23580 | 23579 | } |
| 23581 | 23580 | |
| 23582 | 23581 | return sema.analyzeMinMax(block, src, air_tag, air_refs, operand_srcs); |
| ... | ... | @@ -23679,7 +23678,7 @@ fn analyzeMinMax( |
| 23679 | 23678 | const operand_scalar_ty = sema.typeOf(operand).scalarType(zcu); |
| 23680 | 23679 | const want_strat: TypeStrat = switch (operand_scalar_ty.zigTypeTag(zcu)) { |
| 23681 | 23680 | .comptime_int => s: { |
| 23682 | | const val = (try sema.resolveValue(operand)).?; |
| 23681 | const val = sema.resolveValue(operand).?; |
| 23683 | 23682 | if (val.isUndef(zcu)) break :s .none; |
| 23684 | 23683 | break :s .{ .int = .{ |
| 23685 | 23684 | .all_comptime_int = true, |
| ... | ... | @@ -23698,7 +23697,7 @@ fn analyzeMinMax( |
| 23698 | 23697 | // (replaced with just the simple calls to `Type.minInt`/`Type.maxInt`) so that we only |
| 23699 | 23698 | // use the input *types* to determine the result type. |
| 23700 | 23699 | const min: Value, const max: Value = bounds: { |
| 23701 | | if (try sema.resolveValue(operand)) |operand_val| { |
| 23700 | if (sema.resolveValue(operand)) |operand_val| { |
| 23702 | 23701 | if (vector_len) |len| { |
| 23703 | 23702 | var min = try operand_val.elemValue(pt, 0); |
| 23704 | 23703 | var max = min; |
| ... | ... | @@ -23804,7 +23803,7 @@ fn analyzeMinMax( |
| 23804 | 23803 | var opt_runtime_src: ?LazySrcLoc = null; |
| 23805 | 23804 | |
| 23806 | 23805 | for (operands, operand_srcs) |operand, operand_src| { |
| 23807 | | const operand_val = try sema.resolveValue(operand) orelse { |
| 23806 | const operand_val = sema.resolveValue(operand) orelse { |
| 23808 | 23807 | if (opt_runtime_src == null) opt_runtime_src = operand_src; |
| 23809 | 23808 | continue; |
| 23810 | 23809 | }; |
| ... | ... | @@ -23944,8 +23943,8 @@ fn zirMemcpy( |
| 23944 | 23943 | const src = block.nodeOffset(inst_data.src_node); |
| 23945 | 23944 | const dest_src = block.builtinCallArgSrc(inst_data.src_node, 0); |
| 23946 | 23945 | const src_src = block.builtinCallArgSrc(inst_data.src_node, 1); |
| 23947 | | const dest_ptr = try sema.resolveInst(extra.lhs); |
| 23948 | | const src_ptr = try sema.resolveInst(extra.rhs); |
| 23946 | const dest_ptr = sema.resolveInst(extra.lhs); |
| 23947 | const src_ptr = sema.resolveInst(extra.rhs); |
| 23949 | 23948 | const dest_ty = sema.typeOf(dest_ptr); |
| 23950 | 23949 | const src_ty = sema.typeOf(src_ptr); |
| 23951 | 23950 | const dest_len = try indexablePtrLenOrNone(sema, block, dest_src, dest_ptr); |
| ... | ... | @@ -24208,8 +24207,8 @@ fn zirMemset(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void |
| 24208 | 24207 | const src = block.nodeOffset(inst_data.src_node); |
| 24209 | 24208 | const dest_src = block.builtinCallArgSrc(inst_data.src_node, 0); |
| 24210 | 24209 | const value_src = block.builtinCallArgSrc(inst_data.src_node, 1); |
| 24211 | | const dest_ptr = try sema.resolveInst(extra.lhs); |
| 24212 | | const uncoerced_elem = try sema.resolveInst(extra.rhs); |
| 24210 | const dest_ptr = sema.resolveInst(extra.lhs); |
| 24211 | const uncoerced_elem = sema.resolveInst(extra.rhs); |
| 24213 | 24212 | const dest_ptr_ty = sema.typeOf(dest_ptr); |
| 24214 | 24213 | try checkMemOperand(sema, block, dest_src, dest_ptr_ty); |
| 24215 | 24214 | |
| ... | ... | @@ -24252,7 +24251,7 @@ fn zirMemset(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void |
| 24252 | 24251 | |
| 24253 | 24252 | const ptr_val = try sema.resolveDefinedValue(block, dest_src, dest_ptr) orelse break :rs dest_src; |
| 24254 | 24253 | if (!sema.isComptimeMutablePtr(ptr_val)) break :rs dest_src; |
| 24255 | | const elem_val = try sema.resolveValue(elem) orelse break :rs value_src; |
| 24254 | const elem_val = sema.resolveValue(elem) orelse break :rs value_src; |
| 24256 | 24255 | const array_ty = try pt.arrayType(.{ |
| 24257 | 24256 | .child = dest_elem_ty.toIntern(), |
| 24258 | 24257 | .len = len_u64, |
| ... | ... | @@ -24322,7 +24321,7 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 24322 | 24321 | const cc_ref: Zir.Inst.Ref = @enumFromInt(sema.code.extra[extra_index]); |
| 24323 | 24322 | extra_index += 1; |
| 24324 | 24323 | const cc_ty = try sema.getBuiltinType(cc_src, .CallingConvention); |
| 24325 | | const uncoerced_cc = try sema.resolveInst(cc_ref); |
| 24324 | const uncoerced_cc = sema.resolveInst(cc_ref); |
| 24326 | 24325 | const coerced_cc = try sema.coerce(block, cc_ty, uncoerced_cc, cc_src); |
| 24327 | 24326 | const cc_val = try sema.resolveConstDefinedValue(block, cc_src, coerced_cc, .{ .simple = .@"callconv" }); |
| 24328 | 24327 | break :blk try sema.analyzeValueAsCallconv(block, cc_src, cc_val); |
| ... | ... | @@ -24439,7 +24438,7 @@ fn zirCDefine( |
| 24439 | 24438 | const val_src = block.builtinCallArgSrc(extra.node, 1); |
| 24440 | 24439 | |
| 24441 | 24440 | const name = try sema.resolveConstString(block, name_src, extra.lhs, .{ .simple = .operand_cDefine_macro_name }); |
| 24442 | | const rhs = try sema.resolveInst(extra.rhs); |
| 24441 | const rhs = sema.resolveInst(extra.rhs); |
| 24443 | 24442 | if (sema.typeOf(rhs).zigTypeTag(zcu) != .void) { |
| 24444 | 24443 | const value = try sema.resolveConstString(block, val_src, extra.rhs, .{ .simple = .operand_cDefine_macro_value }); |
| 24445 | 24444 | try block.c_import_buf.?.print("#define {s} {s}\n", .{ name, value }); |
| ... | ... | @@ -24488,7 +24487,7 @@ fn zirWasmMemoryGrow( |
| 24488 | 24487 | } |
| 24489 | 24488 | |
| 24490 | 24489 | const index: u32 = @intCast(try sema.resolveInt(block, index_src, extra.lhs, .u32, .{ .simple = .wasm_memory_index })); |
| 24491 | | const delta = try sema.coerce(block, .usize, try sema.resolveInst(extra.rhs), delta_src); |
| 24490 | const delta = try sema.coerce(block, .usize, sema.resolveInst(extra.rhs), delta_src); |
| 24492 | 24491 | |
| 24493 | 24492 | try sema.requireRuntimeBlock(block, builtin_src, null); |
| 24494 | 24493 | return block.addInst(.{ |
| ... | ... | @@ -24514,7 +24513,7 @@ fn resolvePrefetchOptions( |
| 24514 | 24513 | const ip = &zcu.intern_pool; |
| 24515 | 24514 | |
| 24516 | 24515 | const options_ty = try sema.getBuiltinType(src, .PrefetchOptions); |
| 24517 | | const options = try sema.coerce(block, options_ty, try sema.resolveInst(zir_ref), src); |
| 24516 | const options = try sema.coerce(block, options_ty, sema.resolveInst(zir_ref), src); |
| 24518 | 24517 | |
| 24519 | 24518 | const rw_src = block.src(.{ .init_field_rw = src.offset.node_offset_builtin_call_arg.builtin_call_node }); |
| 24520 | 24519 | const locality_src = block.src(.{ .init_field_locality = src.offset.node_offset_builtin_call_arg.builtin_call_node }); |
| ... | ... | @@ -24544,7 +24543,7 @@ fn zirPrefetch( |
| 24544 | 24543 | const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data; |
| 24545 | 24544 | const ptr_src = block.builtinCallArgSrc(extra.node, 0); |
| 24546 | 24545 | const opts_src = block.builtinCallArgSrc(extra.node, 1); |
| 24547 | | const ptr = try sema.resolveInst(extra.lhs); |
| 24546 | const ptr = sema.resolveInst(extra.lhs); |
| 24548 | 24547 | try sema.checkPtrOperand(block, ptr_src, sema.typeOf(ptr)); |
| 24549 | 24548 | |
| 24550 | 24549 | const options = try sema.resolvePrefetchOptions(block, opts_src, extra.rhs); |
| ... | ... | @@ -24586,7 +24585,7 @@ fn resolveExternOptions( |
| 24586 | 24585 | const io = comp.io; |
| 24587 | 24586 | const ip = &zcu.intern_pool; |
| 24588 | 24587 | |
| 24589 | | const options_inst = try sema.resolveInst(zir_ref); |
| 24588 | const options_inst = sema.resolveInst(zir_ref); |
| 24590 | 24589 | const extern_options_ty = try sema.getBuiltinType(src, .ExternOptions); |
| 24591 | 24590 | const options = try sema.coerce(block, extern_options_ty, options_inst, src); |
| 24592 | 24591 | |
| ... | ... | @@ -24738,7 +24737,7 @@ fn zirBuiltinExtern( |
| 24738 | 24737 | |
| 24739 | 24738 | const uncasted_ptr = try sema.analyzeNavRef(block, src, ip.indexToKey(extern_val).@"extern".owner_nav); |
| 24740 | 24739 | // We want to cast to `ty`, but that isn't necessarily an allowed coercion. |
| 24741 | | if (try sema.resolveValue(uncasted_ptr)) |uncasted_ptr_val| { |
| 24740 | if (sema.resolveValue(uncasted_ptr)) |uncasted_ptr_val| { |
| 24742 | 24741 | const casted_ptr_val = try pt.getCoerced(uncasted_ptr_val, ty); |
| 24743 | 24742 | return Air.internedToRef(casted_ptr_val.toIntern()); |
| 24744 | 24743 | } else { |
| ... | ... | @@ -24854,7 +24853,7 @@ fn zirInplaceArithResultTy(sema: *Sema, extended: Zir.Inst.Extended.InstData) Co |
| 24854 | 24853 | const pt = sema.pt; |
| 24855 | 24854 | const zcu = pt.zcu; |
| 24856 | 24855 | |
| 24857 | | const lhs = try sema.resolveInst(@enumFromInt(extended.operand)); |
| 24856 | const lhs = sema.resolveInst(@enumFromInt(extended.operand)); |
| 24858 | 24857 | const lhs_ty = sema.typeOf(lhs); |
| 24859 | 24858 | |
| 24860 | 24859 | const op: Zir.Inst.InplaceOp = @enumFromInt(extended.small); |
| ... | ... | @@ -24879,7 +24878,7 @@ fn zirInplaceArithResultTy(sema: *Sema, extended: Zir.Inst.Extended.InstData) Co |
| 24879 | 24878 | |
| 24880 | 24879 | fn zirBranchHint(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!void { |
| 24881 | 24880 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; |
| 24882 | | const uncoerced_hint = try sema.resolveInst(extra.operand); |
| 24881 | const uncoerced_hint = sema.resolveInst(extra.operand); |
| 24883 | 24882 | const operand_src = block.builtinCallArgSrc(extra.node, 0); |
| 24884 | 24883 | |
| 24885 | 24884 | const hint_ty = try sema.getBuiltinType(operand_src, .BranchHint); |
| ... | ... | @@ -26333,7 +26332,7 @@ fn structFieldVal( |
| 26333 | 26332 | if (try field_ty.onePossibleValue(pt)) |field_val| |
| 26334 | 26333 | return .fromValue(field_val); |
| 26335 | 26334 | |
| 26336 | | if (try sema.resolveValue(struct_byval)) |struct_val| { |
| 26335 | if (sema.resolveValue(struct_byval)) |struct_val| { |
| 26337 | 26336 | if (struct_val.isUndef(zcu)) return pt.undefRef(field_ty); |
| 26338 | 26337 | return .fromValue(try struct_val.fieldValue(pt, field_index)); |
| 26339 | 26338 | } |
| ... | ... | @@ -26404,7 +26403,7 @@ fn tupleFieldValByIndex( |
| 26404 | 26403 | |
| 26405 | 26404 | if (try field_ty.onePossibleValue(pt)) |opv| return .fromValue(opv); |
| 26406 | 26405 | |
| 26407 | | if (try sema.resolveValue(tuple_byval)) |tuple_val| { |
| 26406 | if (sema.resolveValue(tuple_byval)) |tuple_val| { |
| 26408 | 26407 | return switch (zcu.intern_pool.indexToKey(tuple_val.toIntern())) { |
| 26409 | 26408 | .undef => pt.undefRef(field_ty), |
| 26410 | 26409 | .aggregate => |aggregate| Air.internedToRef(switch (aggregate.storage) { |
| ... | ... | @@ -26564,7 +26563,7 @@ fn unionFieldVal( |
| 26564 | 26563 | const field_ty: Type = .fromInterned(union_obj.field_types.get(ip)[field_index]); |
| 26565 | 26564 | const enum_field_index: u32 = @intCast(Type.fromInterned(union_obj.enum_tag_type).enumFieldIndex(field_name, zcu).?); |
| 26566 | 26565 | |
| 26567 | | if (try sema.resolveValue(union_byval)) |union_val| { |
| 26566 | if (sema.resolveValue(union_byval)) |union_val| { |
| 26568 | 26567 | if (union_val.isUndef(zcu)) return pt.undefRef(field_ty); |
| 26569 | 26568 | |
| 26570 | 26569 | const un = ip.indexToKey(union_val.toIntern()).un; |
| ... | ... | @@ -26895,7 +26894,7 @@ fn tupleFieldPtr( |
| 26895 | 26894 | } }))); |
| 26896 | 26895 | } |
| 26897 | 26896 | |
| 26898 | | if (try sema.resolveValue(tuple_ptr)) |tuple_ptr_val| { |
| 26897 | if (sema.resolveValue(tuple_ptr)) |tuple_ptr_val| { |
| 26899 | 26898 | const field_ptr_val = try tuple_ptr_val.ptrField(field_index, pt); |
| 26900 | 26899 | return Air.internedToRef(field_ptr_val.toIntern()); |
| 26901 | 26900 | } |
| ... | ... | @@ -26936,7 +26935,7 @@ fn tupleField( |
| 26936 | 26935 | return Air.internedToRef(default_value.toIntern()); // comptime field |
| 26937 | 26936 | } |
| 26938 | 26937 | |
| 26939 | | if (try sema.resolveValue(tuple)) |tuple_val| { |
| 26938 | if (sema.resolveValue(tuple)) |tuple_val| { |
| 26940 | 26939 | if (tuple_val.isUndef(zcu)) return pt.undefRef(field_ty); |
| 26941 | 26940 | return Air.internedToRef((try tuple_val.fieldValue(pt, field_index)).toIntern()); |
| 26942 | 26941 | } |
| ... | ... | @@ -26968,7 +26967,7 @@ fn elemValArray( |
| 26968 | 26967 | return sema.fail(block, array_src, "indexing into empty array is not allowed", .{}); |
| 26969 | 26968 | } |
| 26970 | 26969 | |
| 26971 | | const maybe_undef_array_val = try sema.resolveValue(array); |
| 26970 | const maybe_undef_array_val = sema.resolveValue(array); |
| 26972 | 26971 | // index must be defined since it can access out of bounds |
| 26973 | 26972 | const maybe_index_val = try sema.resolveDefinedValue(block, elem_index_src, elem_index); |
| 26974 | 26973 | |
| ... | ... | @@ -27035,7 +27034,7 @@ fn elemPtrArray( |
| 27035 | 27034 | return sema.fail(block, array_ptr_src, "indexing into empty array is not allowed", .{}); |
| 27036 | 27035 | } |
| 27037 | 27036 | |
| 27038 | | const maybe_undef_array_ptr_val = try sema.resolveValue(array_ptr); |
| 27037 | const maybe_undef_array_ptr_val = sema.resolveValue(array_ptr); |
| 27039 | 27038 | // The index must not be undefined since it can be out of bounds. |
| 27040 | 27039 | const offset: ?usize = if (try sema.resolveDefinedValue(block, elem_index_src, elem_index)) |index_val| o: { |
| 27041 | 27040 | const index = try sema.usizeCast(block, elem_index_src, index_val.toUnsignedInt(zcu)); |
| ... | ... | @@ -27159,7 +27158,7 @@ fn elemPtrSlice( |
| 27159 | 27158 | |
| 27160 | 27159 | slice_ty.childType(zcu).assertHasLayout(zcu); |
| 27161 | 27160 | |
| 27162 | | const maybe_undef_slice_val = try sema.resolveValue(slice); |
| 27161 | const maybe_undef_slice_val = sema.resolveValue(slice); |
| 27163 | 27162 | // The index must not be undefined since it can be out of bounds. |
| 27164 | 27163 | const offset: ?usize = if (try sema.resolveDefinedValue(block, elem_index_src, elem_index)) |index_val| o: { |
| 27165 | 27164 | break :o try sema.usizeCast(block, elem_index_src, index_val.toUnsignedInt(zcu)); |
| ... | ... | @@ -27280,7 +27279,7 @@ fn coerceExtra( |
| 27280 | 27279 | if (dest_ty.eql(inst_ty, zcu)) |
| 27281 | 27280 | return inst; |
| 27282 | 27281 | |
| 27283 | | const maybe_inst_val = try sema.resolveValue(inst); |
| 27282 | const maybe_inst_val = sema.resolveValue(inst); |
| 27284 | 27283 | |
| 27285 | 27284 | var in_memory_result = try sema.coerceInMemoryAllowed(block, dest_ty, inst_ty, false, target, dest_ty_src, inst_src, maybe_inst_val); |
| 27286 | 27285 | if (in_memory_result == .ok) { |
| ... | ... | @@ -29104,7 +29103,7 @@ fn storePtr2( |
| 29104 | 29103 | error.NotCoercible => unreachable, |
| 29105 | 29104 | else => |e| return e, |
| 29106 | 29105 | }; |
| 29107 | | const maybe_operand_val = try sema.resolveValue(operand); |
| 29106 | const maybe_operand_val = sema.resolveValue(operand); |
| 29108 | 29107 | |
| 29109 | 29108 | const runtime_src = rs: { |
| 29110 | 29109 | const ptr_val = try sema.resolveDefinedValue(block, ptr_src, ptr) orelse break :rs ptr_src; |
| ... | ... | @@ -29157,7 +29156,7 @@ fn checkComptimeKnownStore(sema: *Sema, block: *Block, store_inst_ref: Air.Inst. |
| 29157 | 29156 | const maybe_base_alloc = sema.base_allocs.get(ptr) orelse break :known; |
| 29158 | 29157 | const maybe_comptime_alloc = sema.maybe_comptime_allocs.getPtr(maybe_base_alloc) orelse break :known; |
| 29159 | 29158 | |
| 29160 | | if ((try sema.resolveValue(operand)) != null and |
| 29159 | if (sema.resolveValue(operand) != null and |
| 29161 | 29160 | block.runtime_index == maybe_comptime_alloc.runtime_index) |
| 29162 | 29161 | { |
| 29163 | 29162 | try maybe_comptime_alloc.stores.append(sema.arena, .{ |
| ... | ... | @@ -29206,7 +29205,7 @@ fn checkKnownAllocPtr(sema: *Sema, block: *Block, base_ptr: Air.Inst.Ref, new_pt |
| 29206 | 29205 | |
| 29207 | 29206 | // If the index value is runtime-known, this pointer is also runtime-known, so |
| 29208 | 29207 | // we must in turn make the alloc value runtime-known. |
| 29209 | | if (null == try sema.resolveValue(index_ref)) { |
| 29208 | if (null == sema.resolveValue(index_ref)) { |
| 29210 | 29209 | try sema.markMaybeComptimeAllocRuntime(block, alloc_inst); |
| 29211 | 29210 | } |
| 29212 | 29211 | }, |
| ... | ... | @@ -29312,7 +29311,7 @@ fn bitCast( |
| 29312 | 29311 | }); |
| 29313 | 29312 | } |
| 29314 | 29313 | |
| 29315 | | if (try sema.resolveValue(inst)) |val| { |
| 29314 | if (sema.resolveValue(inst)) |val| { |
| 29316 | 29315 | if (val.isUndef(zcu)) |
| 29317 | 29316 | return pt.undefRef(dest_ty); |
| 29318 | 29317 | if (old_ty.zigTypeTag(zcu) == .error_set and dest_ty.zigTypeTag(zcu) == .error_set) { |
| ... | ... | @@ -29338,7 +29337,7 @@ fn coerceArrayPtrToSlice( |
| 29338 | 29337 | ) CompileError!Air.Inst.Ref { |
| 29339 | 29338 | const pt = sema.pt; |
| 29340 | 29339 | const zcu = pt.zcu; |
| 29341 | | if (try sema.resolveValue(inst)) |val| { |
| 29340 | if (sema.resolveValue(inst)) |val| { |
| 29342 | 29341 | const ptr_array_ty = sema.typeOf(inst); |
| 29343 | 29342 | const array_ty = ptr_array_ty.childType(zcu); |
| 29344 | 29343 | const slice_ptr_ty = dest_ty.slicePtrFieldType(zcu); |
| ... | ... | @@ -29433,7 +29432,7 @@ fn coerceCompatiblePtrs( |
| 29433 | 29432 | const pt = sema.pt; |
| 29434 | 29433 | const zcu = pt.zcu; |
| 29435 | 29434 | const inst_ty = sema.typeOf(inst); |
| 29436 | | if (try sema.resolveValue(inst)) |val| { |
| 29435 | if (sema.resolveValue(inst)) |val| { |
| 29437 | 29436 | if (!val.isUndef(zcu) and val.isNull(zcu) and !dest_ty.isAllowzeroPtr(zcu)) { |
| 29438 | 29437 | return sema.fail(block, inst_src, "null pointer casted to type '{f}'", .{dest_ty.fmt(pt)}); |
| 29439 | 29438 | } |
| ... | ... | @@ -29611,7 +29610,7 @@ fn coerceArrayLike( |
| 29611 | 29610 | // try coercion of the whole array |
| 29612 | 29611 | const in_memory_result = try sema.coerceInMemoryAllowed(block, dest_ty, inst_ty, false, target, dest_ty_src, inst_src, null); |
| 29613 | 29612 | if (in_memory_result == .ok) { |
| 29614 | | if (try sema.resolveValue(inst)) |inst_val| { |
| 29613 | if (sema.resolveValue(inst)) |inst_val| { |
| 29615 | 29614 | // These types share the same comptime value representation. |
| 29616 | 29615 | return sema.coerceInMemory(inst_val, dest_ty); |
| 29617 | 29616 | } |
| ... | ... | @@ -29634,7 +29633,7 @@ fn coerceArrayLike( |
| 29634 | 29633 | } |
| 29635 | 29634 | |
| 29636 | 29635 | const dest_elem_ty = dest_ty.childType(zcu); |
| 29637 | | if (dest_ty.isVector(zcu) and inst_ty.isVector(zcu) and (try sema.resolveValue(inst)) == null) { |
| 29636 | if (dest_ty.isVector(zcu) and inst_ty.isVector(zcu) and sema.resolveValue(inst) == null) { |
| 29638 | 29637 | const inst_elem_ty = inst_ty.childType(zcu); |
| 29639 | 29638 | switch (dest_elem_ty.zigTypeTag(zcu)) { |
| 29640 | 29639 | .int => if (inst_elem_ty.isInt(zcu)) { |
| ... | ... | @@ -29674,7 +29673,7 @@ fn coerceArrayLike( |
| 29674 | 29673 | const coerced = try sema.coerce(block, dest_elem_ty, elem_ref, elem_src); |
| 29675 | 29674 | ref.* = coerced; |
| 29676 | 29675 | if (runtime_src == null) { |
| 29677 | | if (try sema.resolveValue(coerced)) |elem_val| { |
| 29676 | if (sema.resolveValue(coerced)) |elem_val| { |
| 29678 | 29677 | val.* = elem_val.toIntern(); |
| 29679 | 29678 | } else { |
| 29680 | 29679 | runtime_src = elem_src; |
| ... | ... | @@ -29735,7 +29734,7 @@ fn coerceTupleToArray( |
| 29735 | 29734 | const coerced = try sema.coerce(block, dest_elem_ty, elem_ref, elem_src); |
| 29736 | 29735 | ref.* = coerced; |
| 29737 | 29736 | if (runtime_src == null) { |
| 29738 | | if (try sema.resolveValue(coerced)) |elem_val| { |
| 29737 | if (sema.resolveValue(coerced)) |elem_val| { |
| 29739 | 29738 | val.* = elem_val.toIntern(); |
| 29740 | 29739 | } else { |
| 29741 | 29740 | runtime_src = elem_src; |
| ... | ... | @@ -29844,7 +29843,7 @@ fn coerceTupleToTuple( |
| 29844 | 29843 | const coerced = try sema.coerce(block, .fromInterned(field_ty), elem_ref, field_src); |
| 29845 | 29844 | field_refs[field_index] = coerced; |
| 29846 | 29845 | if (default_val != .none) { |
| 29847 | | const init_val = (try sema.resolveValue(coerced)) orelse { |
| 29846 | const init_val = sema.resolveValue(coerced) orelse { |
| 29848 | 29847 | return sema.failWithNeededComptime(block, field_src, .{ .simple = .stored_to_comptime_field }); |
| 29849 | 29848 | }; |
| 29850 | 29849 | |
| ... | ... | @@ -29853,7 +29852,7 @@ fn coerceTupleToTuple( |
| 29853 | 29852 | } |
| 29854 | 29853 | } |
| 29855 | 29854 | if (runtime_src == null) { |
| 29856 | | if (try sema.resolveValue(coerced)) |field_val| { |
| 29855 | if (sema.resolveValue(coerced)) |field_val| { |
| 29857 | 29856 | field_vals[field_index] = field_val.toIntern(); |
| 29858 | 29857 | } else { |
| 29859 | 29858 | runtime_src = field_src; |
| ... | ... | @@ -30125,7 +30124,7 @@ fn analyzeRef( |
| 30125 | 30124 | const zcu = pt.zcu; |
| 30126 | 30125 | const operand_ty = sema.typeOf(operand); |
| 30127 | 30126 | |
| 30128 | | if (try sema.resolveValue(operand)) |val| { |
| 30127 | if (sema.resolveValue(operand)) |val| { |
| 30129 | 30128 | switch (zcu.intern_pool.indexToKey(val.toIntern())) { |
| 30130 | 30129 | .@"extern" => |e| return sema.analyzeNavRef(block, src, e.owner_nav), |
| 30131 | 30130 | .func => |f| return sema.analyzeNavRef(block, src, f.owner_nav), |
| ... | ... | @@ -30209,7 +30208,7 @@ fn analyzeSlicePtr( |
| 30209 | 30208 | const pt = sema.pt; |
| 30210 | 30209 | const zcu = pt.zcu; |
| 30211 | 30210 | const result_ty = slice_ty.slicePtrFieldType(zcu); |
| 30212 | | if (try sema.resolveValue(slice)) |val| { |
| 30211 | if (sema.resolveValue(slice)) |val| { |
| 30213 | 30212 | if (val.isUndef(zcu)) return pt.undefRef(result_ty); |
| 30214 | 30213 | return Air.internedToRef(val.slicePtr(zcu).toIntern()); |
| 30215 | 30214 | } |
| ... | ... | @@ -30229,7 +30228,7 @@ fn analyzeOptionalSlicePtr( |
| 30229 | 30228 | const slice_ty = opt_slice_ty.optionalChild(zcu); |
| 30230 | 30229 | const result_ty = slice_ty.slicePtrFieldType(zcu); |
| 30231 | 30230 | |
| 30232 | | if (try sema.resolveValue(opt_slice)) |opt_val| { |
| 30231 | if (sema.resolveValue(opt_slice)) |opt_val| { |
| 30233 | 30232 | if (opt_val.isUndef(zcu)) return pt.undefRef(result_ty); |
| 30234 | 30233 | const slice_ptr: InternPool.Index = if (opt_val.optionalValue(zcu)) |val| |
| 30235 | 30234 | val.slicePtr(zcu).toIntern() |
| ... | ... | @@ -30253,7 +30252,7 @@ fn analyzeSliceLen( |
| 30253 | 30252 | ) CompileError!Air.Inst.Ref { |
| 30254 | 30253 | const pt = sema.pt; |
| 30255 | 30254 | const zcu = pt.zcu; |
| 30256 | | if (try sema.resolveValue(slice_inst)) |slice_val| { |
| 30255 | if (sema.resolveValue(slice_inst)) |slice_val| { |
| 30257 | 30256 | if (slice_val.isUndef(zcu)) { |
| 30258 | 30257 | return .undef_usize; |
| 30259 | 30258 | } |
| ... | ... | @@ -30272,7 +30271,7 @@ fn analyzeIsNull( |
| 30272 | 30271 | const pt = sema.pt; |
| 30273 | 30272 | const zcu = pt.zcu; |
| 30274 | 30273 | const result_ty: Type = .bool; |
| 30275 | | if (try sema.resolveValue(operand)) |opt_val| { |
| 30274 | if (sema.resolveValue(operand)) |opt_val| { |
| 30276 | 30275 | if (opt_val.isUndef(zcu)) { |
| 30277 | 30276 | return pt.undefRef(result_ty); |
| 30278 | 30277 | } |
| ... | ... | @@ -30306,7 +30305,7 @@ fn resolvePtrIsNonErrVal( |
| 30306 | 30305 | } |
| 30307 | 30306 | assert(child_ty.zigTypeTag(zcu) == .error_union); |
| 30308 | 30307 | |
| 30309 | | if (try sema.resolveValue(operand)) |eu_ptr_val| { |
| 30308 | if (sema.resolveValue(operand)) |eu_ptr_val| { |
| 30310 | 30309 | if (eu_ptr_val.isUndef(zcu)) return .undef_bool; |
| 30311 | 30310 | if (try sema.pointerDeref(block, src, eu_ptr_val, ptr_ty)) |err_union| { |
| 30312 | 30311 | if (err_union.isUndef(zcu)) return .undef_bool; |
| ... | ... | @@ -30329,7 +30328,7 @@ fn resolveIsNonErrVal( |
| 30329 | 30328 | } |
| 30330 | 30329 | assert(sema.typeOf(operand).zigTypeTag(zcu) == .error_union); |
| 30331 | 30330 | |
| 30332 | | if (try sema.resolveValue(operand)) |err_union| { |
| 30331 | if (sema.resolveValue(operand)) |err_union| { |
| 30333 | 30332 | if (err_union.isUndef(zcu)) return .undef_bool; |
| 30334 | 30333 | return .makeBool(err_union.getErrorName(zcu) == .none); |
| 30335 | 30334 | } |
| ... | ... | @@ -30681,7 +30680,7 @@ fn analyzeSlice( |
| 30681 | 30680 | break :end try sema.coerce(block, .usize, uncasted_end, end_src); |
| 30682 | 30681 | } else try sema.coerce(block, .usize, uncasted_end_opt, end_src); |
| 30683 | 30682 | if (try sema.resolveDefinedValue(block, end_src, end)) |end_val| { |
| 30684 | | if (try sema.resolveValue(ptr_or_slice)) |slice_val| { |
| 30683 | if (sema.resolveValue(ptr_or_slice)) |slice_val| { |
| 30685 | 30684 | if (slice_val.isUndef(zcu)) { |
| 30686 | 30685 | return sema.fail(block, src, "slice of undefined", .{}); |
| 30687 | 30686 | } |
| ... | ... | @@ -30803,7 +30802,7 @@ fn analyzeSlice( |
| 30803 | 30802 | ); |
| 30804 | 30803 | } |
| 30805 | 30804 | checked_start_lte_end = true; |
| 30806 | | if (try sema.resolveValue(new_ptr)) |ptr_val| sentinel_check: { |
| 30805 | if (sema.resolveValue(new_ptr)) |ptr_val| sentinel_check: { |
| 30807 | 30806 | const expected_sentinel = sentinel orelse break :sentinel_check; |
| 30808 | 30807 | const start_int = start_val.toUnsignedInt(zcu); |
| 30809 | 30808 | const end_int = end_val.toUnsignedInt(zcu); |
| ... | ... | @@ -30887,7 +30886,7 @@ fn analyzeSlice( |
| 30887 | 30886 | }, |
| 30888 | 30887 | }); |
| 30889 | 30888 | |
| 30890 | | const opt_new_ptr_val = try sema.resolveValue(new_ptr); |
| 30889 | const opt_new_ptr_val = sema.resolveValue(new_ptr); |
| 30891 | 30890 | const new_ptr_val = opt_new_ptr_val orelse { |
| 30892 | 30891 | const result = try block.addBitCast(return_ty, new_ptr); |
| 30893 | 30892 | if (block.wantSafety()) { |
| ... | ... | @@ -31034,8 +31033,8 @@ fn cmpNumeric( |
| 31034 | 31033 | else |
| 31035 | 31034 | uncasted_rhs; |
| 31036 | 31035 | |
| 31037 | | const maybe_lhs_val = try sema.resolveValue(lhs); |
| 31038 | | const maybe_rhs_val = try sema.resolveValue(rhs); |
| 31036 | const maybe_lhs_val = sema.resolveValue(lhs); |
| 31037 | const maybe_rhs_val = sema.resolveValue(rhs); |
| 31039 | 31038 | |
| 31040 | 31039 | // If the LHS is const, check if there is a guaranteed result which does not depend on ths RHS value. |
| 31041 | 31040 | if (maybe_lhs_val) |lhs_val| { |
| ... | ... | @@ -31320,8 +31319,8 @@ fn cmpVector( |
| 31320 | 31319 | .child = .bool_type, |
| 31321 | 31320 | }); |
| 31322 | 31321 | |
| 31323 | | const maybe_lhs_val = try sema.resolveValue(casted_lhs); |
| 31324 | | const maybe_rhs_val = try sema.resolveValue(casted_rhs); |
| 31322 | const maybe_lhs_val = sema.resolveValue(casted_lhs); |
| 31323 | const maybe_rhs_val = sema.resolveValue(casted_rhs); |
| 31325 | 31324 | if (maybe_lhs_val) |v| if (v.isUndef(zcu)) return pt.undefRef(result_ty); |
| 31326 | 31325 | if (maybe_rhs_val) |v| if (v.isUndef(zcu)) return pt.undefRef(result_ty); |
| 31327 | 31326 | |
| ... | ... | @@ -31343,7 +31342,7 @@ fn wrapOptional( |
| 31343 | 31342 | inst: Air.Inst.Ref, |
| 31344 | 31343 | inst_src: LazySrcLoc, |
| 31345 | 31344 | ) !Air.Inst.Ref { |
| 31346 | | if (try sema.resolveValue(inst)) |val| { |
| 31345 | if (sema.resolveValue(inst)) |val| { |
| 31347 | 31346 | return Air.internedToRef((try sema.pt.intern(.{ .opt = .{ |
| 31348 | 31347 | .ty = dest_ty.toIntern(), |
| 31349 | 31348 | .val = val.toIntern(), |
| ... | ... | @@ -31365,7 +31364,7 @@ fn wrapErrorUnionPayload( |
| 31365 | 31364 | const zcu = pt.zcu; |
| 31366 | 31365 | const dest_payload_ty = dest_ty.errorUnionPayload(zcu); |
| 31367 | 31366 | const coerced = try sema.coerceExtra(block, dest_payload_ty, inst, inst_src, .{ .report_err = false }); |
| 31368 | | if (try sema.resolveValue(coerced)) |val| { |
| 31367 | if (sema.resolveValue(coerced)) |val| { |
| 31369 | 31368 | return Air.internedToRef((try pt.intern(.{ .error_union = .{ |
| 31370 | 31369 | .ty = dest_ty.toIntern(), |
| 31371 | 31370 | .val = .{ .payload = val.toIntern() }, |
| ... | ... | @@ -31387,7 +31386,7 @@ fn wrapErrorUnionSet( |
| 31387 | 31386 | const ip = &zcu.intern_pool; |
| 31388 | 31387 | const inst_ty = sema.typeOf(inst); |
| 31389 | 31388 | const dest_err_set_ty = dest_ty.errorUnionSet(zcu); |
| 31390 | | if (try sema.resolveValue(inst)) |val| { |
| 31389 | if (sema.resolveValue(inst)) |val| { |
| 31391 | 31390 | const expected_name = zcu.intern_pool.indexToKey(val.toIntern()).err.name; |
| 31392 | 31391 | switch (dest_err_set_ty.toIntern()) { |
| 31393 | 31392 | .anyerror_type => {}, |
| ... | ... | @@ -31449,7 +31448,7 @@ fn unionToTag( |
| 31449 | 31448 | const pt = sema.pt; |
| 31450 | 31449 | const zcu = pt.zcu; |
| 31451 | 31450 | if (try enum_ty.onePossibleValue(pt)) |opv| return .fromValue(opv); |
| 31452 | | if (try sema.resolveValue(un)) |un_val| { |
| 31451 | if (sema.resolveValue(un)) |un_val| { |
| 31453 | 31452 | const tag_val = un_val.unionTag(zcu).?; |
| 31454 | 31453 | if (tag_val.isUndef(zcu)) |
| 31455 | 31454 | return try pt.undefRef(enum_ty); |
| ... | ... | @@ -31796,7 +31795,7 @@ fn resolvePeerTypes( |
| 31796 | 31795 | |
| 31797 | 31796 | for (instructions, peer_tys, peer_vals) |inst, *ty, *val| { |
| 31798 | 31797 | ty.* = sema.typeOf(inst); |
| 31799 | | val.* = try sema.resolveValue(inst); |
| 31798 | val.* = sema.resolveValue(inst); |
| 31800 | 31799 | } |
| 31801 | 31800 | |
| 31802 | 31801 | switch (try sema.resolvePeerTypesInner(block, src, peer_tys, peer_vals)) { |
| ... | ... | @@ -32863,7 +32862,7 @@ fn resolvePeerTypesInner( |
| 32863 | 32862 | }, |
| 32864 | 32863 | else => |e| return e, |
| 32865 | 32864 | }; |
| 32866 | | const coerced_val = (try sema.resolveValue(coerced_inst)) orelse continue; |
| 32865 | const coerced_val = sema.resolveValue(coerced_inst) orelse continue; |
| 32867 | 32866 | const existing = comptime_val orelse { |
| 32868 | 32867 | comptime_val = coerced_val; |
| 32869 | 32868 | continue; |
| ... | ... | @@ -33225,7 +33224,7 @@ fn isComptimeKnown( |
| 33225 | 33224 | sema: *Sema, |
| 33226 | 33225 | inst: Air.Inst.Ref, |
| 33227 | 33226 | ) !bool { |
| 33228 | | return (try sema.resolveValue(inst)) != null; |
| 33227 | return sema.resolveValue(inst) != null; |
| 33229 | 33228 | } |
| 33230 | 33229 | |
| 33231 | 33230 | /// Asserts that the layout of `var_type` has already been resolved. |
| ... | ... | @@ -33275,7 +33274,7 @@ fn resolveAddressSpace( |
| 33275 | 33274 | zir_ref: Zir.Inst.Ref, |
| 33276 | 33275 | ctx: std.Target.AddressSpaceContext, |
| 33277 | 33276 | ) !std.builtin.AddressSpace { |
| 33278 | | const air_ref = try sema.resolveInst(zir_ref); |
| 33277 | const air_ref = sema.resolveInst(zir_ref); |
| 33279 | 33278 | return sema.analyzeAsAddressSpace(block, src, air_ref, ctx); |
| 33280 | 33279 | } |
| 33281 | 33280 | |
| ... | ... | @@ -34305,7 +34304,7 @@ fn setTypeName( |
| 34305 | 34304 | // If not then this is a struct type being returned from a non-generic |
| 34306 | 34305 | // function and the name doesn't matter since it will later |
| 34307 | 34306 | // result in a compile error. |
| 34308 | | const arg_val = try sema.resolveValue(arg) orelse { |
| 34307 | const arg_val = sema.resolveValue(arg) orelse { |
| 34309 | 34308 | continue :strat .anon; |
| 34310 | 34309 | }; |
| 34311 | 34310 | |