Move compare_const_vals out of eval
This commit is contained in:
parent
b75a828e2b
commit
0e2da01b91
3 changed files with 31 additions and 34 deletions
|
|
@ -13,13 +13,12 @@ use self::Usefulness::*;
|
|||
use self::WitnessPreference::*;
|
||||
|
||||
use rustc::middle::const_val::ConstVal;
|
||||
use const_eval::eval::{compare_const_vals};
|
||||
|
||||
use rustc_data_structures::fx::FxHashMap;
|
||||
use rustc_data_structures::indexed_vec::Idx;
|
||||
|
||||
use const_eval::pattern::{FieldPattern, Pattern, PatternKind};
|
||||
use const_eval::pattern::{PatternFoldable, PatternFolder};
|
||||
use const_eval::pattern::{PatternFoldable, PatternFolder, compare_const_vals};
|
||||
|
||||
use rustc::hir::def_id::DefId;
|
||||
use rustc::hir::RangeEnd;
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
use rustc::middle::const_val::ConstVal::*;
|
||||
use rustc::middle::const_val::ConstVal;
|
||||
|
||||
use rustc::hir::def_id::DefId;
|
||||
|
|
@ -17,8 +16,6 @@ use rustc::ty::subst::Substs;
|
|||
|
||||
use syntax::ast;
|
||||
|
||||
use std::cmp::Ordering;
|
||||
|
||||
use rustc_const_math::*;
|
||||
|
||||
/// * `DefId` is the id of the constant.
|
||||
|
|
@ -128,31 +125,3 @@ fn parse_float<'tcx>(num: &str, fty: ast::FloatTy)
|
|||
-> Result<ConstFloat, ()> {
|
||||
ConstFloat::from_str(num, fty).map_err(|_| ())
|
||||
}
|
||||
|
||||
pub fn compare_const_vals(a: &ConstVal, b: &ConstVal, ty: Ty) -> Option<Ordering> {
|
||||
trace!("compare_const_vals: {:?}, {:?}", a, b);
|
||||
use rustc::mir::interpret::{Value, PrimVal};
|
||||
match (a, b) {
|
||||
(&Value(Value::ByVal(PrimVal::Bytes(a))),
|
||||
&Value(Value::ByVal(PrimVal::Bytes(b)))) => {
|
||||
match ty.sty {
|
||||
ty::TyFloat(ty) => {
|
||||
let l = ConstFloat {
|
||||
bits: a,
|
||||
ty,
|
||||
};
|
||||
let r = ConstFloat {
|
||||
bits: b,
|
||||
ty,
|
||||
};
|
||||
// FIXME(oli-obk): report cmp errors?
|
||||
l.try_cmp(r).ok()
|
||||
},
|
||||
ty::TyInt(_) => Some((a as i128).cmp(&(b as i128))),
|
||||
_ => Some(a.cmp(&b)),
|
||||
}
|
||||
},
|
||||
_ if a == b => Some(Ordering::Equal),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,10 +18,10 @@ use rustc::ty::subst::{Substs, Kind};
|
|||
use rustc::hir::{self, PatKind, RangeEnd};
|
||||
use rustc::hir::def::{Def, CtorKind};
|
||||
use rustc::hir::pat_util::EnumerateAndAdjustIterator;
|
||||
use const_eval::eval::compare_const_vals;
|
||||
|
||||
use rustc_data_structures::indexed_vec::Idx;
|
||||
|
||||
use std::cmp::Ordering;
|
||||
use std::fmt;
|
||||
use syntax::ast;
|
||||
use syntax::ptr::P;
|
||||
|
|
@ -1060,3 +1060,32 @@ impl<'tcx> PatternFoldable<'tcx> for PatternKind<'tcx> {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn compare_const_vals(a: &ConstVal, b: &ConstVal, ty: Ty) -> Option<Ordering> {
|
||||
use rustc_const_math::ConstFloat;
|
||||
trace!("compare_const_vals: {:?}, {:?}", a, b);
|
||||
use rustc::mir::interpret::{Value, PrimVal};
|
||||
match (a, b) {
|
||||
(&ConstVal::Value(Value::ByVal(PrimVal::Bytes(a))),
|
||||
&ConstVal::Value(Value::ByVal(PrimVal::Bytes(b)))) => {
|
||||
match ty.sty {
|
||||
ty::TyFloat(ty) => {
|
||||
let l = ConstFloat {
|
||||
bits: a,
|
||||
ty,
|
||||
};
|
||||
let r = ConstFloat {
|
||||
bits: b,
|
||||
ty,
|
||||
};
|
||||
// FIXME(oli-obk): report cmp errors?
|
||||
l.try_cmp(r).ok()
|
||||
},
|
||||
ty::TyInt(_) => Some((a as i128).cmp(&(b as i128))),
|
||||
_ => Some(a.cmp(&b)),
|
||||
}
|
||||
},
|
||||
_ if a == b => Some(Ordering::Equal),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue