| ... | @@ -20850,30 +20850,36 @@ fn zirRoundCast( | ... | @@ -20850,30 +20850,36 @@ fn zirRoundCast( |
| 20850 | const src = block.nodeOffset(extra.node); | 20850 | const src = block.nodeOffset(extra.node); |
| 20851 | const operand_src = block.builtinCallArgSrc(extra.node, 0); | 20851 | const operand_src = block.builtinCallArgSrc(extra.node, 0); |
| 20852 | | 20852 | |
| 20853 | const builtin_name = switch (mode) { | 20853 | const dest_ty_or_poison = try sema.resolveTypeOrPoison(block, src, extra.lhs) orelse Type.generic_poison; |
| 20854 | .round => "@round", | 20854 | var dest_ty = dest_ty_or_poison; |
| 20855 | .floor => "@floor", | 20855 | if (!dest_ty.isGenericPoison()) { |
| 20856 | .ceil => "@ceil", | 20856 | if (dest_ty.zigTypeTag(zcu) == .error_union) { |
| 20857 | .truncate => "@trunc", | 20857 | dest_ty = dest_ty.errorUnionPayload(zcu); |
| 20858 | .exact => unreachable, | 20858 | } |
| 20859 | }; | 20859 | if (dest_ty.zigTypeTag(zcu) == .optional) { |
| | 20860 | dest_ty = dest_ty.childType(zcu); |
| | 20861 | } |
| | 20862 | } |
| 20860 | | 20863 | |
| 20861 | const dest_ty = try sema.resolveDestType(block, src, extra.lhs, .remove_eu_opt, builtin_name); | | |
| 20862 | const operand = sema.resolveInst(extra.rhs); | 20864 | const operand = sema.resolveInst(extra.rhs); |
| 20863 | const operand_ty = sema.typeOf(operand); | 20865 | const operand_ty = sema.typeOf(operand); |
| 20864 | | 20866 | |
| 20865 | try sema.checkVectorizableBinaryOperands(block, operand_src, dest_ty, operand_ty, src, operand_src); | 20867 | const is_poison = dest_ty.isGenericPoison(); |
| 20866 | const dest_scalar_ty = dest_ty.scalarType(zcu); | 20868 | if (!is_poison) { |
| | 20869 | try sema.checkVectorizableBinaryOperands(block, operand_src, dest_ty, operand_ty, src, operand_src); |
| | 20870 | } |
| | 20871 | const dest_scalar_ty = if (is_poison) dest_ty else dest_ty.scalarType(zcu); |
| 20867 | const operand_scalar_ty = operand_ty.scalarType(zcu); | 20872 | const operand_scalar_ty = operand_ty.scalarType(zcu); |
| 20868 | | 20873 | |
| 20869 | if (dest_scalar_ty.zigTypeTag(zcu) == .float or dest_scalar_ty.zigTypeTag(zcu) == .comptime_float) { | 20874 | if (is_poison or dest_scalar_ty.zigTypeTag(zcu) == .float or dest_scalar_ty.zigTypeTag(zcu) == .comptime_float) { |
| 20870 | const coerced_operand = try sema.coerce(block, dest_ty, operand, operand_src); | 20875 | const coerced_operand = try sema.coerce(block, dest_ty, operand, operand_src); |
| | 20876 | const math_ty = if (is_poison) operand_ty else dest_ty; |
| 20871 | | 20877 | |
| 20872 | const result_ref = switch (mode) { | 20878 | const result_ref = switch (mode) { |
| 20873 | .round => try sema.maybeConstantUnaryMath(coerced_operand, dest_ty, Value.round), | 20879 | .round => try sema.maybeConstantUnaryMath(coerced_operand, math_ty, Value.round), |
| 20874 | .floor => try sema.maybeConstantUnaryMath(coerced_operand, dest_ty, Value.floor), | 20880 | .floor => try sema.maybeConstantUnaryMath(coerced_operand, math_ty, Value.floor), |
| 20875 | .ceil => try sema.maybeConstantUnaryMath(coerced_operand, dest_ty, Value.ceil), | 20881 | .ceil => try sema.maybeConstantUnaryMath(coerced_operand, math_ty, Value.ceil), |
| 20876 | .truncate => try sema.maybeConstantUnaryMath(coerced_operand, dest_ty, Value.trunc), | 20882 | .truncate => try sema.maybeConstantUnaryMath(coerced_operand, math_ty, Value.trunc), |
| 20877 | else => unreachable, | 20883 | else => unreachable, |
| 20878 | }; | 20884 | }; |
| 20879 | | 20885 | |
| ... | @@ -25122,9 +25128,11 @@ fn zirRoundOpType(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDa | ... | @@ -25122,9 +25128,11 @@ fn zirRoundOpType(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDa |
| 25122 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; | 25128 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; |
| 25123 | const operand_src = block.builtinCallArgSrc(extra.node, 0); | 25129 | const operand_src = block.builtinCallArgSrc(extra.node, 0); |
| 25124 | | 25130 | |
| 25125 | const dest_ty = try sema.resolveDestType(block, operand_src, extra.operand, .remove_eu_opt, "type hint"); | 25131 | const dest_ty_or_poison = try sema.resolveTypeOrPoison(block, operand_src, extra.operand) orelse Type.generic_poison; |
| | 25132 | |
| | 25133 | if (dest_ty_or_poison.isGenericPoison()) return .generic_poison_type; |
| 25126 | | 25134 | |
| 25127 | const float_ty = dest_ty.optEuBaseType(zcu); | 25135 | const float_ty = dest_ty_or_poison.optEuBaseType(zcu); |
| 25128 | switch (float_ty.scalarType(zcu).zigTypeTag(zcu)) { | 25136 | switch (float_ty.scalarType(zcu).zigTypeTag(zcu)) { |
| 25129 | .float, .comptime_float => return .fromType(float_ty), | 25137 | .float, .comptime_float => return .fromType(float_ty), |
| 25130 | else => return .comptime_float_type, | 25138 | else => return .comptime_float_type, |