Remove ty_to_primitive

This commit is contained in:
Oliver Schneider 2018-05-24 11:21:23 +02:00
parent 879d8f7070
commit f1ea9ef315
2 changed files with 12 additions and 13 deletions

View File

@ -1265,13 +1265,6 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M
}
}
pub fn ty_to_primitive(&self, ty: Ty<'tcx>) -> EvalResult<'tcx, layout::Primitive> {
match self.layout_of(ty)?.abi {
layout::Abi::Scalar(ref scalar) => Ok(scalar.value),
_ => err!(TypeNotPrimitive(ty)),
}
}
fn ensure_valid_value(&self, val: Scalar, ty: Ty<'tcx>) -> EvalResult<'tcx> {
match ty.sty {
ty::TyBool => val.to_bool().map(|_| ()),

View File

@ -1,5 +1,5 @@
use rustc::mir;
use rustc::ty::{self, Ty};
use rustc::ty::{self, Ty, layout};
use syntax::ast::FloatTy;
use rustc::ty::layout::LayoutOf;
use rustc_apfloat::ieee::{Double, Single};
@ -68,8 +68,17 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M> {
) -> EvalResult<'tcx, (Scalar, bool)> {
use rustc::mir::BinOp::*;
let left_kind = self.ty_to_primitive(left_ty)?;
let right_kind = self.ty_to_primitive(right_ty)?;
let left_layout = self.layout_of(left_ty)?;
let right_layout = self.layout_of(right_ty)?;
let left_kind = match left_layout.abi {
layout::Abi::Scalar(ref scalar) => scalar.value,
_ => return err!(TypeNotPrimitive(left_ty)),
};
let right_kind = match right_layout.abi {
layout::Abi::Scalar(ref scalar) => scalar.value,
_ => return err!(TypeNotPrimitive(right_ty)),
};
trace!("Running binary op {:?}: {:?} ({:?}), {:?} ({:?})", bin_op, left, left_kind, right, right_kind);
// I: Handle operations that support pointers
@ -79,9 +88,6 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M> {
}
}
let left_layout = self.layout_of(left_ty)?;
let right_layout = self.layout_of(right_ty)?;
// II: From now on, everything must be bytes, no pointers
let l = left.to_bits(left_layout.size)?;
let r = right.to_bits(right_layout.size)?;