Skip to content

Commit 40b118c

Browse files
Oliver Schneideroli-obk
Oliver Schneider
authored andcommitted
Remove ConstFloat
1 parent f45d0f3 commit 40b118c

File tree

9 files changed

+85
-309
lines changed

9 files changed

+85
-309
lines changed

src/librustc/ich/impls_const_math.rs

-5
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,6 @@
1111
//! This module contains `HashStable` implementations for various data types
1212
//! from `rustc_const_math` in no particular order.
1313
14-
impl_stable_hash_for!(struct ::rustc_const_math::ConstFloat {
15-
ty,
16-
bits
17-
});
18-
1914
impl_stable_hash_for!(enum ::rustc_const_math::ConstMathErr {
2015
Overflow(op),
2116
DivisionByZero,

src/librustc/mir/mod.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ use std::vec::IntoIter;
4343
use syntax::ast::{self, Name};
4444
use syntax::symbol::InternedString;
4545
use syntax_pos::{Span, DUMMY_SP};
46+
use rustc_apfloat::ieee::{Single, Double};
47+
use rustc_apfloat::Float;
4648

4749
mod cache;
4850
pub mod tcx;
@@ -1915,12 +1917,13 @@ fn fmt_const_val<W: Write>(fmt: &mut W, const_val: &ty::Const) -> fmt::Result {
19151917

19161918
pub fn print_miri_value<W: Write>(value: Value, ty: Ty, f: &mut W) -> fmt::Result {
19171919
use ty::TypeVariants::*;
1918-
use rustc_const_math::ConstFloat;
19191920
match (value, &ty.sty) {
19201921
(Value::ByVal(PrimVal::Bytes(0)), &TyBool) => write!(f, "false"),
19211922
(Value::ByVal(PrimVal::Bytes(1)), &TyBool) => write!(f, "true"),
1922-
(Value::ByVal(PrimVal::Bytes(bits)), &TyFloat(fty)) =>
1923-
write!(f, "{}", ConstFloat { bits, ty: fty }),
1923+
(Value::ByVal(PrimVal::Bytes(bits)), &TyFloat(ast::FloatTy::F32)) =>
1924+
write!(f, "{}", Single::from_bits(bits)),
1925+
(Value::ByVal(PrimVal::Bytes(bits)), &TyFloat(ast::FloatTy::F64)) =>
1926+
write!(f, "{}", Double::from_bits(bits)),
19241927
(Value::ByVal(PrimVal::Bytes(n)), &TyUint(ui)) => write!(f, "{:?}{}", n, ui),
19251928
(Value::ByVal(PrimVal::Bytes(n)), &TyInt(i)) => write!(f, "{:?}{}", n as i128, i),
19261929
(Value::ByVal(PrimVal::Bytes(n)), &TyChar) =>

src/librustc_const_math/float.rs

-217
This file was deleted.

src/librustc_const_math/lib.rs

-5
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,9 @@
1818
html_favicon_url = "https://doc.rust-lang.org/favicon.ico",
1919
html_root_url = "https://doc.rust-lang.org/nightly/")]
2020

21-
extern crate rustc_apfloat;
22-
23-
extern crate syntax;
2421

2522
extern crate serialize as rustc_serialize; // used by deriving
2623

27-
mod float;
2824
mod err;
2925

30-
pub use float::*;
3126
pub use err::{ConstMathErr, Op};

src/librustc_mir/hair/cx/mod.rs

+3-21
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ use syntax::ast::{self, LitKind};
3030
use syntax::attr;
3131
use syntax::symbol::Symbol;
3232
use rustc::hir;
33-
use rustc_const_math::ConstFloat;
3433
use rustc_data_structures::sync::Lrc;
3534
use rustc::mir::interpret::{Value, PrimVal};
35+
use hair::pattern::parse_float;
3636

3737
#[derive(Clone)]
3838
pub struct Cx<'a, 'gcx: 'a + 'tcx, 'tcx: 'a> {
@@ -170,14 +170,6 @@ impl<'a, 'gcx, 'tcx> Cx<'a, 'gcx, 'tcx> {
170170
neg: bool,
171171
) -> Literal<'tcx> {
172172
trace!("const_eval_literal: {:#?}, {:?}, {:?}, {:?}", lit, ty, sp, neg);
173-
let tcx = self.tcx.global_tcx();
174-
175-
let parse_float = |num: &str, fty| -> ConstFloat {
176-
ConstFloat::from_str(num, fty).unwrap_or_else(|_| {
177-
// FIXME(#31407) this is only necessary because float parsing is buggy
178-
tcx.sess.span_fatal(sp, "could not evaluate float literal (see issue #31407)");
179-
})
180-
};
181173

182174
let clamp = |n| {
183175
let size = self.integer_bit_width(ty);
@@ -214,25 +206,15 @@ impl<'a, 'gcx, 'tcx> Cx<'a, 'gcx, 'tcx> {
214206
LitKind::Int(n, _) => Value::ByVal(PrimVal::Bytes(clamp(n))),
215207
LitKind::Float(n, fty) => {
216208
let n = n.as_str();
217-
let mut f = parse_float(&n, fty);
218-
if neg {
219-
f = -f;
220-
}
221-
let bits = f.bits;
222-
Value::ByVal(PrimVal::Bytes(bits))
209+
parse_float(&n, fty, neg).expect("apfloat parsing failed")
223210
}
224211
LitKind::FloatUnsuffixed(n) => {
225212
let fty = match ty.sty {
226213
ty::TyFloat(fty) => fty,
227214
_ => bug!()
228215
};
229216
let n = n.as_str();
230-
let mut f = parse_float(&n, fty);
231-
if neg {
232-
f = -f;
233-
}
234-
let bits = f.bits;
235-
Value::ByVal(PrimVal::Bytes(bits))
217+
parse_float(&n, fty, neg).expect("apfloat parsing failed")
236218
}
237219
LitKind::Bool(b) => Value::ByVal(PrimVal::Bytes(b as u128)),
238220
LitKind::Char(c) => Value::ByVal(PrimVal::Bytes(c as u128)),

0 commit comments

Comments
 (0)