]> git.lizzy.rs Git - rust.git/commitdiff
Rustup part 2/2
authorOliver Schneider <git-spam-no-reply9815368754983@oli-obk.de>
Wed, 13 Sep 2017 11:46:54 +0000 (13:46 +0200)
committerOliver Schneider <git-spam-no-reply9815368754983@oli-obk.de>
Wed, 13 Sep 2017 11:46:54 +0000 (13:46 +0200)
src/librustc_mir/interpret/cast.rs
src/librustc_mir/interpret/eval_context.rs
src/librustc_mir/interpret/step.rs
src/librustc_mir/interpret/validation.rs

index f9a771c7af7c2176507b785fa5c47314240bd0a4..5ae7c9da31c09b939878bc8815f5a924df46e9f6 100644 (file)
@@ -38,36 +38,45 @@ fn cast_from_signed_int(&self, val: i128, ty: ty::Ty<'tcx>) -> EvalResult<'tcx,
         self.cast_from_int(val as u128, ty, val < 0)
     }
 
+    fn int_to_int(&self, v: i128, ty: IntTy) -> u128 {
+        match ty {
+            IntTy::I8 => v as i8 as u128,
+            IntTy::I16 => v as i16 as u128,
+            IntTy::I32 => v as i32 as u128,
+            IntTy::I64 => v as i64 as u128,
+            IntTy::I128 => v as u128,
+            IntTy::Is => {
+                let ty = self.tcx.sess.target.isize_ty;
+                self.int_to_int(v, ty)
+            }
+        }
+    }
+    fn int_to_uint(&self, v: u128, ty: UintTy) -> u128 {
+        match ty {
+            UintTy::U8 => v as u8 as u128,
+            UintTy::U16 => v as u16 as u128,
+            UintTy::U32 => v as u32 as u128,
+            UintTy::U64 => v as u64 as u128,
+            UintTy::U128 => v,
+            UintTy::Us => {
+                let ty = self.tcx.sess.target.usize_ty;
+                self.int_to_uint(v, ty)
+            }
+        }
+    }
+
     fn cast_from_int(
         &self,
         v: u128,
         ty: ty::Ty<'tcx>,
         negative: bool,
     ) -> EvalResult<'tcx, PrimVal> {
+        trace!("cast_from_int: {}, {}, {}", v, ty, negative);
         use rustc::ty::TypeVariants::*;
         match ty.sty {
             // Casts to bool are not permitted by rustc, no need to handle them here.
-            TyInt(IntTy::I8) => Ok(PrimVal::Bytes(v as i128 as i8 as u128)),
-            TyInt(IntTy::I16) => Ok(PrimVal::Bytes(v as i128 as i16 as u128)),
-            TyInt(IntTy::I32) => Ok(PrimVal::Bytes(v as i128 as i32 as u128)),
-            TyInt(IntTy::I64) => Ok(PrimVal::Bytes(v as i128 as i64 as u128)),
-            TyInt(IntTy::I128) => Ok(PrimVal::Bytes(v as u128)),
-
-            TyUint(UintTy::U8) => Ok(PrimVal::Bytes(v as u8 as u128)),
-            TyUint(UintTy::U16) => Ok(PrimVal::Bytes(v as u16 as u128)),
-            TyUint(UintTy::U32) => Ok(PrimVal::Bytes(v as u32 as u128)),
-            TyUint(UintTy::U64) => Ok(PrimVal::Bytes(v as u64 as u128)),
-            TyUint(UintTy::U128) => Ok(PrimVal::Bytes(v)),
-
-            TyInt(IntTy::Is) => {
-                let ty = self.tcx.types.isize;
-                self.cast_from_int(v, ty, negative)
-            }
-
-            TyUint(UintTy::Us) => {
-                let ty = self.tcx.types.usize;
-                self.cast_from_int(v, ty, negative)
-            }
+            TyInt(ty) => Ok(PrimVal::Bytes(self.int_to_int(v as i128, ty))),
+            TyUint(ty) => Ok(PrimVal::Bytes(self.int_to_uint(v, ty))),
 
             TyFloat(FloatTy::F64) if negative => Ok(PrimVal::from_f64(v as i128 as f64)),
             TyFloat(FloatTy::F64) => Ok(PrimVal::from_f64(v as f64)),
index 231bfa92ccd7cd0f4f1d9262bc9d1e834e19be45..0a23e0569313de5935ed0c258717afb6a9709da9 100644 (file)
@@ -240,10 +240,20 @@ pub(super) fn const_to_value(&mut self, const_val: &ConstVal<'tcx>) -> EvalResul
             Str(ref s) => return self.str_to_value(s),
 
             ByteStr(ref bs) => {
-                let ptr = self.memory.allocate_cached(bs)?;
+                let ptr = self.memory.allocate_cached(bs.data)?;
                 PrimVal::Ptr(ptr)
             }
 
+            Unevaluated(def_id, substs) => {
+                let instance = self.resolve_associated_const(def_id, substs);
+                let cid = GlobalId {
+                    instance,
+                    promoted: None,
+                };
+                return Ok(Value::ByRef(*self.globals.get(&cid).expect("static/const not cached")));
+            }
+
+            Aggregate(..) |
             Variant(_) => unimplemented!(),
             // function items are zero sized and thus have no readable value
             Function(..) => PrimVal::Undef,
@@ -1284,16 +1294,7 @@ pub fn eval_operand(&mut self, op: &mir::Operand<'tcx>) -> EvalResult<'tcx, ValT
                 use rustc::mir::Literal;
                 let mir::Constant { ref literal, .. } = **constant;
                 let value = match *literal {
-                    Literal::Value { ref value } => self.const_to_value(value)?,
-
-                    Literal::Item { def_id, substs } => {
-                        let instance = self.resolve_associated_const(def_id, substs);
-                        let cid = GlobalId {
-                            instance,
-                            promoted: None,
-                        };
-                        Value::ByRef(*self.globals.get(&cid).expect("static/const not cached"))
-                    }
+                    Literal::Value { ref value } => self.const_to_value(&value.val)?,
 
                     Literal::Promoted { index } => {
                         let cid = GlobalId {
@@ -2501,7 +2502,7 @@ struct AssociatedTypeNormalizer<'a, 'tcx: 'a> {
 
 impl<'a, 'tcx> AssociatedTypeNormalizer<'a, 'tcx> {
     fn fold<T: TypeFoldable<'tcx>>(&mut self, value: &T) -> T {
-        if !value.has_projection_types() {
+        if !value.has_projections() {
             value.clone()
         } else {
             value.fold_with(self)
@@ -2515,7 +2516,7 @@ fn tcx<'c>(&'c self) -> TyCtxt<'c, 'tcx, 'tcx> {
     }
 
     fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> {
-        if !ty.has_projection_types() {
+        if !ty.has_projections() {
             ty
         } else {
             self.tcx.normalize_associated_type(&ty)
index 3dc74368fe830ef9bf051819ddadfd3623a67b99..05f1bd10e87e85efac1f516f15896001a9f38c05 100644 (file)
@@ -10,6 +10,7 @@
 use rustc::ty;
 use rustc::ty::layout::Layout;
 use rustc::ty::subst::Substs;
+use rustc::middle::const_val::ConstVal;
 
 use super::{EvalResult, EvalContext, StackPopCleanup, PtrAndAlign, GlobalId, Lvalue,
             MemoryKind, Machine, PrimVal};
@@ -300,8 +301,7 @@ fn visit_constant(&mut self, constant: &mir::Constant<'tcx>, location: mir::Loca
         self.super_constant(constant, location);
         match constant.literal {
             // already computed by rustc
-            mir::Literal::Value { .. } => {}
-            mir::Literal::Item { def_id, substs } => {
+            mir::Literal::Value { value: &ty::Const { val: ConstVal::Unevaluated(def_id, substs), .. } } => {
                 self.try(|this| {
                     this.ecx.global_item(
                         def_id,
@@ -311,6 +311,7 @@ fn visit_constant(&mut self, constant: &mir::Constant<'tcx>, location: mir::Loca
                     )
                 });
             }
+            mir::Literal::Value { .. } => {}
             mir::Literal::Promoted { index } => {
                 let cid = GlobalId {
                     instance: self.instance,
index 1f9de6785fd2546c1602d22f8f0d5d1afe384ee2..2477001bec49ab8c14b4a8d7f858a1a18932ac09 100644 (file)
@@ -246,7 +246,7 @@ fn normalize_associated_type<'a, 'tcx, T>(self_: TyCtxt<'a, 'tcx, 'tcx>, value:
         {
             let param_env = ty::ParamEnv::empty(Reveal::All);
 
-            if !value.has_projection_types() {
+            if !value.has_projections() {
                 return value.clone();
             }