Skip to content

Commit f33f672

Browse files
committed
Compiler checks correctly
1 parent 146c075 commit f33f672

File tree

5 files changed

+2473
-1
lines changed

5 files changed

+2473
-1
lines changed

compiler/rustc_codegen_ssa/src/traits/type_.rs

+2
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@ pub trait BaseTypeMethods<'tcx>: Backend<'tcx> {
1919
fn type_i128(&self) -> Self::Type;
2020
fn type_isize(&self) -> Self::Type;
2121

22+
fn type_f16(&self) -> Self::Type;
2223
fn type_f32(&self) -> Self::Type;
2324
fn type_f64(&self) -> Self::Type;
25+
fn type_f128(&self) -> Self::Type;
2426

2527
fn type_array(&self, ty: Self::Type, len: u64) -> Self::Type;
2628
fn type_func(&self, args: &[Self::Type], ret: Self::Type) -> Self::Type;

compiler/rustc_lint/src/types.rs

+4
Original file line numberDiff line numberDiff line change
@@ -525,8 +525,12 @@ fn lint_literal<'tcx>(
525525
ty::Float(t) => {
526526
let is_infinite = match lit.node {
527527
ast::LitKind::Float(v, _) => match t {
528+
// v.as_str().parse().map(f16::is_infinite)
529+
ty::FloatTy::F16 => todo!("f16::is_infinite"),
528530
ty::FloatTy::F32 => v.as_str().parse().map(f32::is_infinite),
529531
ty::FloatTy::F64 => v.as_str().parse().map(f64::is_infinite),
532+
// v.as_str().parse().map(f128::is_infinite),
533+
ty::FloatTy::F128 => todo!("f128::is_infinite"),
530534
},
531535
_ => bug!(),
532536
};

compiler/rustc_mir_build/src/build/mod.rs

+71-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::build::expr::as_place::PlaceBuilder;
22
use crate::build::scope::DropKind;
3-
use rustc_apfloat::ieee::{Double, Single};
3+
use rustc_apfloat::ieee::{Double, Half, Quad, Single};
44
use rustc_apfloat::Float;
55
use rustc_ast::attr;
66
use rustc_data_structures::fx::FxHashMap;
@@ -967,13 +967,60 @@ fn parse_float_into_constval<'tcx>(
967967
parse_float_into_scalar(num, float_ty, neg).map(ConstValue::Scalar)
968968
}
969969

970+
// #[cfg(not(bootstrap))]
971+
// fn parse_f16(num: &str) -> Option<f16> {
972+
// num.parse().ok()
973+
// }
974+
975+
// FIXME: bootstrap `f16` parsing via `f32`
976+
// #[cfg(bootstrap)]
977+
fn parse_f16(num: &str) -> Option<f32> {
978+
num.parse().ok()
979+
}
980+
981+
// #[cfg(not(bootstrap))]
982+
// fn parse_f128(num: &str) -> Option<f128> {
983+
// num.parse().ok()
984+
// }
985+
986+
// FIXME: bootstrap `f16` parsing via `f32`
987+
// #[cfg(bootstrap)]
988+
fn parse_f128(num: &str) -> Option<f64> {
989+
num.parse().ok()
990+
}
991+
970992
pub(crate) fn parse_float_into_scalar(
971993
num: Symbol,
972994
float_ty: ty::FloatTy,
973995
neg: bool,
974996
) -> Option<Scalar> {
975997
let num = num.as_str();
998+
976999
match float_ty {
1000+
ty::FloatTy::F16 => {
1001+
let rust_f = parse_f16(num)?;
1002+
1003+
let mut f = num
1004+
.parse::<Half>()
1005+
.unwrap_or_else(|e| panic!("apfloat::ieee::Half failed to parse `{num}`: {e:?}"));
1006+
1007+
assert!(
1008+
u128::from(rust_f.to_bits()) == f.to_bits(),
1009+
"apfloat::ieee::Half gave different result for `{}`: \
1010+
{}({:#x}) vs Rust's {}({:#x})",
1011+
rust_f,
1012+
f,
1013+
f.to_bits(),
1014+
Half::from_bits(rust_f.to_bits().into()),
1015+
rust_f.to_bits()
1016+
);
1017+
1018+
if neg {
1019+
f = -f;
1020+
}
1021+
1022+
Some(Scalar::from_f16(f))
1023+
}
9771024
ty::FloatTy::F32 => {
9781025
let Ok(rust_f) = num.parse::<f32>() else { return None };
9791026
let mut f = num
@@ -1020,6 +1067,29 @@ pub(crate) fn parse_float_into_scalar(
10201067

10211068
Some(Scalar::from_f64(f))
10221069
}
1070+
ty::FloatTy::F128 => {
1071+
let rust_f = parse_f128(num)?;
1072+
let mut f = num
1073+
.parse::<Quad>()
1074+
.unwrap_or_else(|e| panic!("apfloat::ieee::Quad failed to parse `{num}`: {e:?}"));
1075+
1076+
assert!(
1077+
u128::from(rust_f.to_bits()) == f.to_bits(),
1078+
"apfloat::ieee::Quad gave different result for `{}`: \
1079+
{}({:#x}) vs Rust's {}({:#x})",
1080+
rust_f,
1081+
f,
1082+
f.to_bits(),
1083+
Quad::from_bits(rust_f.to_bits().into()),
1084+
rust_f.to_bits()
1085+
);
1086+
1087+
if neg {
1088+
f = -f;
1089+
}
1090+
1091+
Some(Scalar::from_f128(f))
1092+
}
10231093
}
10241094
}
10251095

0 commit comments

Comments
 (0)