Skip to content

Commit 6862b01

Browse files
committed
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.
1 parent 73476d4 commit 6862b01

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

compiler/rustc_pattern_analysis/src/constructor.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ use std::iter::once;
154154

155155
use smallvec::SmallVec;
156156

157-
use rustc_apfloat::ieee::{DoubleS, IeeeFloat, SingleS};
157+
use rustc_apfloat::ieee::{DoubleS, HalfS, IeeeFloat, QuadS, SingleS};
158158
use rustc_index::bit_set::GrowableBitSet;
159159

160160
use self::Constructor::*;
@@ -664,8 +664,10 @@ pub enum Constructor<Cx: PatCx> {
664664
/// Ranges of integer literal values (`2`, `2..=5` or `2..5`).
665665
IntRange(IntRange),
666666
/// Ranges of floating-point literal values (`2.0..=5.2`).
667+
F16Range(IeeeFloat<HalfS>, IeeeFloat<HalfS>, RangeEnd),
667668
F32Range(IeeeFloat<SingleS>, IeeeFloat<SingleS>, RangeEnd),
668669
F64Range(IeeeFloat<DoubleS>, IeeeFloat<DoubleS>, RangeEnd),
670+
F128Range(IeeeFloat<QuadS>, IeeeFloat<QuadS>, RangeEnd),
669671
/// String literals. Strings are not quite the same as `&[u8]` so we treat them separately.
670672
Str(Cx::StrLit),
671673
/// Constants that must not be matched structurally. They are treated as black boxes for the

compiler/rustc_pattern_analysis/src/rustc.rs

+12-2
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,12 @@ impl<'p, 'tcx: 'p> RustcPatCtxt<'p, 'tcx> {
610610
let lo = lo.as_finite().map(|c| c.eval_bits(cx.tcx, cx.param_env));
611611
let hi = hi.as_finite().map(|c| c.eval_bits(cx.tcx, cx.param_env));
612612
match fty {
613-
ty::FloatTy::F16 => unimplemented!("f16_f128"),
613+
ty::FloatTy::F16 => {
614+
use rustc_apfloat::ieee::Half;
615+
let lo = lo.map(Half::from_bits).unwrap_or(-Half::INFINITY);
616+
let hi = hi.map(Half::from_bits).unwrap_or(Half::INFINITY);
617+
F16Range(lo, hi, end)
618+
}
614619
ty::FloatTy::F32 => {
615620
use rustc_apfloat::ieee::Single;
616621
let lo = lo.map(Single::from_bits).unwrap_or(-Single::INFINITY);
@@ -623,7 +628,12 @@ impl<'p, 'tcx: 'p> RustcPatCtxt<'p, 'tcx> {
623628
let hi = hi.map(Double::from_bits).unwrap_or(Double::INFINITY);
624629
F64Range(lo, hi, end)
625630
}
626-
ty::FloatTy::F128 => unimplemented!("f16_f128"),
631+
ty::FloatTy::F128 => {
632+
use rustc_apfloat::ieee::Quad;
633+
let lo = lo.map(Quad::from_bits).unwrap_or(-Quad::INFINITY);
634+
let hi = hi.map(Quad::from_bits).unwrap_or(Quad::INFINITY);
635+
F128Range(lo, hi, end)
636+
}
627637
}
628638
}
629639
_ => bug!("invalid type for range pattern: {}", ty.inner()),

0 commit comments

Comments
 (0)