]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc_trans/mir/constant.rs
refactor `ParamEnv::empty(Reveal)` into two distinct methods
[rust.git] / src / librustc_trans / mir / constant.rs
index 1b470665cd9c5f2fdeee644df27d929afac141eb..977c7c983d6f2458dd4eb0e08b54897de84f2837 100644 (file)
@@ -12,7 +12,6 @@
 use rustc::middle::const_val::{ConstVal, ConstEvalErr};
 use rustc_mir::interpret::{read_target_uint, const_val_field};
 use rustc::hir::def_id::DefId;
-use rustc::traits;
 use rustc::mir;
 use rustc_data_structures::indexed_vec::Idx;
 use rustc::mir::interpret::{Allocation, GlobalId, MemoryPointer, PrimVal, Value as MiriValue};
@@ -24,6 +23,7 @@
 use consts;
 use type_of::LayoutLlvmExt;
 use type_::Type;
+use syntax::ast::Mutability;
 
 use super::super::callee;
 use super::FunctionCx;
@@ -57,7 +57,7 @@ pub fn primval_to_llvm(cx: &CodegenCx,
                 } else if let Some(alloc) = cx.tcx.interpret_interner
                                               .get_alloc(ptr.alloc_id) {
                     let init = global_initializer(cx, alloc);
-                    if alloc.mutable {
+                    if alloc.runtime_mutability == Mutability::Mutable {
                         consts::addr_of_mut(cx, init, alloc.align, "byte_str")
                     } else {
                         consts::addr_of(cx, init, alloc.align, "byte_str")
@@ -125,7 +125,7 @@ pub fn trans_static_initializer<'a, 'tcx>(
         instance,
         promoted: None
     };
-    let param_env = ty::ParamEnv::empty(traits::Reveal::All);
+    let param_env = ty::ParamEnv::reveal_all();
     cx.tcx.const_eval(param_env.and(cid))?;
 
     let alloc_id = cx
@@ -151,7 +151,7 @@ fn const_to_miri_value(
         match constant.val {
             ConstVal::Unevaluated(def_id, ref substs) => {
                 let tcx = bx.tcx();
-                let param_env = ty::ParamEnv::empty(traits::Reveal::All);
+                let param_env = ty::ParamEnv::reveal_all();
                 let instance = ty::Instance::resolve(tcx, param_env, def_id, substs).unwrap();
                 let cid = GlobalId {
                     instance,
@@ -171,7 +171,7 @@ pub fn mir_constant_to_miri_value(
     ) -> Result<MiriValue, ConstEvalErr<'tcx>> {
         match constant.literal {
             mir::Literal::Promoted { index } => {
-                let param_env = ty::ParamEnv::empty(traits::Reveal::All);
+                let param_env = ty::ParamEnv::reveal_all();
                 let cid = mir::interpret::GlobalId {
                     instance: self.instance,
                     promoted: Some(index),
@@ -190,70 +190,39 @@ pub fn simd_shuffle_indices(
         bx: &Builder<'a, 'tcx>,
         constant: &mir::Constant<'tcx>,
     ) -> (ValueRef, Ty<'tcx>) {
-        let layout = bx.cx.layout_of(constant.ty);
         self.mir_constant_to_miri_value(bx, constant)
             .and_then(|c| {
-                let llval = match c {
-                    MiriValue::ByVal(val) => {
-                        let scalar = match layout.abi {
-                            layout::Abi::Scalar(ref x) => x,
-                            _ => bug!("from_const: invalid ByVal layout: {:#?}", layout)
-                        };
-                        primval_to_llvm(bx.cx, val, scalar, layout.immediate_llvm_type(bx.cx))
-                    },
-                    MiriValue::ByValPair(a_val, b_val) => {
-                        let (a_scalar, b_scalar) = match layout.abi {
-                            layout::Abi::ScalarPair(ref a, ref b) => (a, b),
-                            _ => bug!("from_const: invalid ByValPair layout: {:#?}", layout)
-                        };
-                        let a_llval = primval_to_llvm(
-                            bx.cx,
-                            a_val,
-                            a_scalar,
-                            layout.scalar_pair_element_llvm_type(bx.cx, 0),
-                        );
-                        let b_llval = primval_to_llvm(
-                            bx.cx,
-                            b_val,
-                            b_scalar,
-                            layout.scalar_pair_element_llvm_type(bx.cx, 1),
-                        );
-                        C_struct(bx.cx, &[a_llval, b_llval], false)
-                    },
-                    MiriValue::ByRef(..) => {
-                        let field_ty = constant.ty.builtin_index().unwrap();
-                        let fields = match constant.ty.sty {
-                            ty::TyArray(_, n) => n.val.unwrap_u64(),
-                            ref other => bug!("invalid simd shuffle type: {}", other),
-                        };
-                        let values: Result<Vec<ValueRef>, _> = (0..fields).map(|field| {
-                            let field = const_val_field(
-                                bx.tcx(),
-                                ty::ParamEnv::empty(traits::Reveal::All),
-                                self.instance,
-                                None,
-                                mir::Field::new(field as usize),
-                                c,
-                                constant.ty,
-                            )?;
-                            match field.val {
-                                ConstVal::Value(MiriValue::ByVal(prim)) => {
-                                    let layout = bx.cx.layout_of(field_ty);
-                                    let scalar = match layout.abi {
-                                        layout::Abi::Scalar(ref x) => x,
-                                        _ => bug!("from_const: invalid ByVal layout: {:#?}", layout)
-                                    };
-                                    Ok(primval_to_llvm(
-                                        bx.cx, prim, scalar,
-                                        layout.immediate_llvm_type(bx.cx),
-                                    ))
-                                },
-                                other => bug!("simd shuffle field {:?}, {}", other, constant.ty),
-                            }
-                        }).collect();
-                        C_struct(bx.cx, &values?, false)
-                    },
+                let field_ty = constant.ty.builtin_index().unwrap();
+                let fields = match constant.ty.sty {
+                    ty::TyArray(_, n) => n.val.unwrap_u64(),
+                    ref other => bug!("invalid simd shuffle type: {}", other),
                 };
+                let values: Result<Vec<ValueRef>, _> = (0..fields).map(|field| {
+                    let field = const_val_field(
+                        bx.tcx(),
+                        ty::ParamEnv::reveal_all(),
+                        self.instance,
+                        None,
+                        mir::Field::new(field as usize),
+                        c,
+                        constant.ty,
+                    )?;
+                    match field.val {
+                        ConstVal::Value(MiriValue::ByVal(prim)) => {
+                            let layout = bx.cx.layout_of(field_ty);
+                            let scalar = match layout.abi {
+                                layout::Abi::Scalar(ref x) => x,
+                                _ => bug!("from_const: invalid ByVal layout: {:#?}", layout)
+                            };
+                            Ok(primval_to_llvm(
+                                bx.cx, prim, scalar,
+                                layout.immediate_llvm_type(bx.cx),
+                            ))
+                        },
+                        other => bug!("simd shuffle field {:?}, {}", other, constant.ty),
+                    }
+                }).collect();
+                let llval = C_struct(bx.cx, &values?, false);
                 Ok((llval, constant.ty))
             })
             .unwrap_or_else(|e| {