Skip to content

Commit

Permalink
miri: import ty::Ty directly.
Browse files Browse the repository at this point in the history
  • Loading branch information
eddyb committed Dec 6, 2017
1 parent 42a534c commit bf5ec79
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 15 deletions.
6 changes: 3 additions & 3 deletions src/librustc/mir/interpret/cast.rs
@@ -1,4 +1,4 @@
use ty::{self, Ty};
use ty::Ty;
use syntax::ast::{FloatTy, IntTy, UintTy};

use rustc_const_math::ConstFloat;
Expand Down Expand Up @@ -37,7 +37,7 @@ impl<'a, 'tcx, M: Machine<'tcx>> EvalContext<'a, 'tcx, M> {
}
}

fn cast_from_signed_int(&self, val: i128, ty: ty::Ty<'tcx>) -> EvalResult<'tcx, PrimVal> {
fn cast_from_signed_int(&self, val: i128, ty: Ty<'tcx>) -> EvalResult<'tcx, PrimVal> {
self.cast_from_int(val as u128, ty, val < 0)
}

Expand Down Expand Up @@ -71,7 +71,7 @@ impl<'a, 'tcx, M: Machine<'tcx>> EvalContext<'a, 'tcx, M> {
fn cast_from_int(
&self,
v: u128,
ty: ty::Ty<'tcx>,
ty: Ty<'tcx>,
negative: bool,
) -> EvalResult<'tcx, PrimVal> {
trace!("cast_from_int: {}, {}, {}", v, ty, negative);
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/mir/interpret/const_eval.rs
Expand Up @@ -274,7 +274,7 @@ impl<'tcx> super::Machine<'tcx> for CompileTimeFunctionEvaluator {

fn box_alloc<'a>(
_ecx: &mut EvalContext<'a, 'tcx, Self>,
_ty: ty::Ty<'tcx>,
_ty: Ty<'tcx>,
_dest: Place,
) -> EvalResult<'tcx> {
Err(
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/mir/interpret/eval_context.rs
Expand Up @@ -346,7 +346,7 @@ impl<'a, 'tcx, M: Machine<'tcx>> EvalContext<'a, 'tcx, M> {
/// the value has to be a fat pointer, and we only care about the "extra" data in it.
pub fn size_and_align_of_dst(
&mut self,
ty: ty::Ty<'tcx>,
ty: Ty<'tcx>,
value: Value,
) -> EvalResult<'tcx, (Size, Align)> {
let layout = self.layout_of(ty)?;
Expand Down
9 changes: 5 additions & 4 deletions src/librustc/mir/interpret/machine.rs
Expand Up @@ -4,7 +4,8 @@

use super::{EvalResult, EvalContext, Place, PrimVal, ValTy};

use {mir, ty};
use mir;
use ty::{self, Ty};
use syntax::codemap::Span;
use syntax::ast::Mutability;

Expand Down Expand Up @@ -60,9 +61,9 @@ pub trait Machine<'tcx>: Sized {
ecx: &EvalContext<'a, 'tcx, Self>,
bin_op: mir::BinOp,
left: PrimVal,
left_ty: ty::Ty<'tcx>,
left_ty: Ty<'tcx>,
right: PrimVal,
right_ty: ty::Ty<'tcx>,
right_ty: Ty<'tcx>,
) -> EvalResult<'tcx, Option<(PrimVal, bool)>>;

/// Called when trying to mark machine defined `MemoryKinds` as static
Expand All @@ -73,7 +74,7 @@ pub trait Machine<'tcx>: Sized {
/// Returns a pointer to the allocated memory
fn box_alloc<'a>(
ecx: &mut EvalContext<'a, 'tcx, Self>,
ty: ty::Ty<'tcx>,
ty: Ty<'tcx>,
dest: Place,
) -> EvalResult<'tcx>;

Expand Down
10 changes: 5 additions & 5 deletions src/librustc/mir/interpret/terminator/mod.rs
@@ -1,5 +1,5 @@
use mir;
use ty::{self, TypeVariants};
use ty::{self, Ty};
use ty::layout::LayoutOf;
use syntax::codemap::Span;
use syntax::abi::Abi;
Expand Down Expand Up @@ -177,16 +177,16 @@ impl<'a, 'tcx, M: Machine<'tcx>> EvalContext<'a, 'tcx, M> {
sig: ty::FnSig<'tcx>,
real_sig: ty::FnSig<'tcx>,
) -> EvalResult<'tcx, bool> {
fn check_ty_compat<'tcx>(ty: ty::Ty<'tcx>, real_ty: ty::Ty<'tcx>) -> bool {
fn check_ty_compat<'tcx>(ty: Ty<'tcx>, real_ty: Ty<'tcx>) -> bool {
if ty == real_ty {
return true;
} // This is actually a fast pointer comparison
return match (&ty.sty, &real_ty.sty) {
// Permit changing the pointer type of raw pointers and references as well as
// mutability of raw pointers.
// TODO: Should not be allowed when fat pointers are involved.
(&TypeVariants::TyRawPtr(_), &TypeVariants::TyRawPtr(_)) => true,
(&TypeVariants::TyRef(_, _), &TypeVariants::TyRef(_, _)) => {
(&ty::TyRawPtr(_), &ty::TyRawPtr(_)) => true,
(&ty::TyRef(_, _), &ty::TyRef(_, _)) => {
ty.is_mutable_pointer() == real_ty.is_mutable_pointer()
}
// rule out everything else
Expand Down Expand Up @@ -220,7 +220,7 @@ impl<'a, 'tcx, M: Machine<'tcx>> EvalContext<'a, 'tcx, M> {
// Second argument must be a tuple matching the argument list of sig
let snd_ty = real_sig.inputs_and_output[1];
match snd_ty.sty {
TypeVariants::TyTuple(tys, _) if sig.inputs().len() == tys.len() =>
ty::TyTuple(tys, _) if sig.inputs().len() == tys.len() =>
if sig.inputs().iter().zip(tys).all(|(ty, real_ty)| check_ty_compat(ty, real_ty)) {
return Ok(true)
},
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/mir/interpret/validation.rs
Expand Up @@ -337,7 +337,7 @@ impl<'a, 'tcx, M: Machine<'tcx>> EvalContext<'a, 'tcx, M> {
base: Place,
mut layout: ty::layout::TyLayout<'tcx>,
i: usize,
) -> EvalResult<'tcx, ty::Ty<'tcx>> {
) -> EvalResult<'tcx, Ty<'tcx>> {
match base {
Place::Ptr { extra: PlaceExtra::DowncastVariant(variant_index), .. } => {
layout = layout.for_variant(&self, variant_index);
Expand Down

0 comments on commit bf5ec79

Please sign in to comment.