1
Fork 0

Replace f16 and f128 pattern matching stubs with real implementations

This section of code depends on `rustc_apfloat` rather than our internal
types, so this is one potential ICE that we should be able to melt now.

This also fixes some missing range and match handling in `rustc_middle`.
This commit is contained in:
Trevor Gross 2024-03-26 06:01:09 -04:00
parent acb62737ac
commit 6fb6c19c96
11 changed files with 311 additions and 40 deletions

View file

@ -1047,6 +1047,12 @@ impl<'tcx> PatRangeBoundary<'tcx> {
let b = other.eval_bits(ty, tcx, param_env);
match ty.kind() {
ty::Float(ty::FloatTy::F16) => {
use rustc_apfloat::Float;
let a = rustc_apfloat::ieee::Half::from_bits(a);
let b = rustc_apfloat::ieee::Half::from_bits(b);
a.partial_cmp(&b)
}
ty::Float(ty::FloatTy::F32) => {
use rustc_apfloat::Float;
let a = rustc_apfloat::ieee::Single::from_bits(a);
@ -1059,6 +1065,12 @@ impl<'tcx> PatRangeBoundary<'tcx> {
let b = rustc_apfloat::ieee::Double::from_bits(b);
a.partial_cmp(&b)
}
ty::Float(ty::FloatTy::F128) => {
use rustc_apfloat::Float;
let a = rustc_apfloat::ieee::Quad::from_bits(a);
let b = rustc_apfloat::ieee::Quad::from_bits(b);
a.partial_cmp(&b)
}
ty::Int(ity) => {
let size = rustc_target::abi::Integer::from_int_ty(&tcx, *ity).size();
let a = size.sign_extend(a) as i128;

View file

@ -1196,7 +1196,7 @@ impl<'tcx> Ty<'tcx> {
/// Returns the minimum and maximum values for the given numeric type (including `char`s) or
/// returns `None` if the type is not numeric.
pub fn numeric_min_and_max_as_bits(self, tcx: TyCtxt<'tcx>) -> Option<(u128, u128)> {
use rustc_apfloat::ieee::{Double, Single};
use rustc_apfloat::ieee::{Double, Half, Quad, Single};
Some(match self.kind() {
ty::Int(_) | ty::Uint(_) => {
let (size, signed) = self.int_size_and_signed(tcx);
@ -1206,12 +1206,14 @@ impl<'tcx> Ty<'tcx> {
(min, max)
}
ty::Char => (0, std::char::MAX as u128),
ty::Float(ty::FloatTy::F16) => ((-Half::INFINITY).to_bits(), Half::INFINITY.to_bits()),
ty::Float(ty::FloatTy::F32) => {
((-Single::INFINITY).to_bits(), Single::INFINITY.to_bits())
}
ty::Float(ty::FloatTy::F64) => {
((-Double::INFINITY).to_bits(), Double::INFINITY.to_bits())
}
ty::Float(ty::FloatTy::F128) => ((-Quad::INFINITY).to_bits(), Quad::INFINITY.to_bits()),
_ => return None,
})
}