Skip to content

Commit

Permalink
Remove ConstFloat
Browse files Browse the repository at this point in the history
  • Loading branch information
Oliver Schneider authored and oli-obk committed Apr 30, 2018
1 parent f45d0f3 commit 40b118c
Show file tree
Hide file tree
Showing 9 changed files with 85 additions and 309 deletions.
5 changes: 0 additions & 5 deletions src/librustc/ich/impls_const_math.rs
Expand Up @@ -11,11 +11,6 @@
//! This module contains `HashStable` implementations for various data types
//! from `rustc_const_math` in no particular order.

impl_stable_hash_for!(struct ::rustc_const_math::ConstFloat {
ty,
bits
});

impl_stable_hash_for!(enum ::rustc_const_math::ConstMathErr {
Overflow(op),
DivisionByZero,
Expand Down
9 changes: 6 additions & 3 deletions src/librustc/mir/mod.rs
Expand Up @@ -43,6 +43,8 @@ use std::vec::IntoIter;
use syntax::ast::{self, Name};
use syntax::symbol::InternedString;
use syntax_pos::{Span, DUMMY_SP};
use rustc_apfloat::ieee::{Single, Double};
use rustc_apfloat::Float;

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

pub fn print_miri_value<W: Write>(value: Value, ty: Ty, f: &mut W) -> fmt::Result {
use ty::TypeVariants::*;
use rustc_const_math::ConstFloat;
match (value, &ty.sty) {
(Value::ByVal(PrimVal::Bytes(0)), &TyBool) => write!(f, "false"),
(Value::ByVal(PrimVal::Bytes(1)), &TyBool) => write!(f, "true"),
(Value::ByVal(PrimVal::Bytes(bits)), &TyFloat(fty)) =>
write!(f, "{}", ConstFloat { bits, ty: fty }),
(Value::ByVal(PrimVal::Bytes(bits)), &TyFloat(ast::FloatTy::F32)) =>
write!(f, "{}", Single::from_bits(bits)),
(Value::ByVal(PrimVal::Bytes(bits)), &TyFloat(ast::FloatTy::F64)) =>
write!(f, "{}", Double::from_bits(bits)),
(Value::ByVal(PrimVal::Bytes(n)), &TyUint(ui)) => write!(f, "{:?}{}", n, ui),
(Value::ByVal(PrimVal::Bytes(n)), &TyInt(i)) => write!(f, "{:?}{}", n as i128, i),
(Value::ByVal(PrimVal::Bytes(n)), &TyChar) =>
Expand Down
217 changes: 0 additions & 217 deletions src/librustc_const_math/float.rs

This file was deleted.

5 changes: 0 additions & 5 deletions src/librustc_const_math/lib.rs
Expand Up @@ -18,14 +18,9 @@
html_favicon_url = "https://doc.rust-lang.org/favicon.ico",
html_root_url = "https://doc.rust-lang.org/nightly/")]

extern crate rustc_apfloat;

extern crate syntax;

extern crate serialize as rustc_serialize; // used by deriving

mod float;
mod err;

pub use float::*;
pub use err::{ConstMathErr, Op};
24 changes: 3 additions & 21 deletions src/librustc_mir/hair/cx/mod.rs
Expand Up @@ -30,9 +30,9 @@ use syntax::ast::{self, LitKind};
use syntax::attr;
use syntax::symbol::Symbol;
use rustc::hir;
use rustc_const_math::ConstFloat;
use rustc_data_structures::sync::Lrc;
use rustc::mir::interpret::{Value, PrimVal};
use hair::pattern::parse_float;

#[derive(Clone)]
pub struct Cx<'a, 'gcx: 'a + 'tcx, 'tcx: 'a> {
Expand Down Expand Up @@ -170,14 +170,6 @@ impl<'a, 'gcx, 'tcx> Cx<'a, 'gcx, 'tcx> {
neg: bool,
) -> Literal<'tcx> {
trace!("const_eval_literal: {:#?}, {:?}, {:?}, {:?}", lit, ty, sp, neg);
let tcx = self.tcx.global_tcx();

let parse_float = |num: &str, fty| -> ConstFloat {
ConstFloat::from_str(num, fty).unwrap_or_else(|_| {
// FIXME(#31407) this is only necessary because float parsing is buggy
tcx.sess.span_fatal(sp, "could not evaluate float literal (see issue #31407)");
})
};

let clamp = |n| {
let size = self.integer_bit_width(ty);
Expand Down Expand Up @@ -214,25 +206,15 @@ impl<'a, 'gcx, 'tcx> Cx<'a, 'gcx, 'tcx> {
LitKind::Int(n, _) => Value::ByVal(PrimVal::Bytes(clamp(n))),
LitKind::Float(n, fty) => {
let n = n.as_str();
let mut f = parse_float(&n, fty);
if neg {
f = -f;
}
let bits = f.bits;
Value::ByVal(PrimVal::Bytes(bits))
parse_float(&n, fty, neg).expect("apfloat parsing failed")
}
LitKind::FloatUnsuffixed(n) => {
let fty = match ty.sty {
ty::TyFloat(fty) => fty,
_ => bug!()
};
let n = n.as_str();
let mut f = parse_float(&n, fty);
if neg {
f = -f;
}
let bits = f.bits;
Value::ByVal(PrimVal::Bytes(bits))
parse_float(&n, fty, neg).expect("apfloat parsing failed")
}
LitKind::Bool(b) => Value::ByVal(PrimVal::Bytes(b as u128)),
LitKind::Char(c) => Value::ByVal(PrimVal::Bytes(c as u128)),
Expand Down

0 comments on commit 40b118c

Please sign in to comment.