diff options
Diffstat (limited to 'src/librustc_codegen_llvm')
| -rw-r--r-- | src/librustc_codegen_llvm/base.rs | 9 | ||||
| -rw-r--r-- | src/librustc_codegen_llvm/mir/constant.rs | 35 | ||||
| -rw-r--r-- | src/librustc_codegen_llvm/mir/operand.rs | 17 |
3 files changed, 27 insertions, 34 deletions
diff --git a/src/librustc_codegen_llvm/base.rs b/src/librustc_codegen_llvm/base.rs index 322924535d1..a4709739a23 100644 --- a/src/librustc_codegen_llvm/base.rs +++ b/src/librustc_codegen_llvm/base.rs @@ -1381,7 +1381,6 @@ mod temp_stable_hash_impls { fn fetch_wasm_section(tcx: TyCtxt, id: DefId) -> (String, Vec<u8>) { use rustc::mir::interpret::GlobalId; - use rustc::middle::const_val::ConstVal; info!("loading wasm section {:?}", id); @@ -1399,12 +1398,6 @@ fn fetch_wasm_section(tcx: TyCtxt, id: DefId) -> (String, Vec<u8>) { }; let param_env = ty::ParamEnv::reveal_all(); let val = tcx.const_eval(param_env.and(cid)).unwrap(); - - let const_val = match val.val { - ConstVal::Value(val) => val, - ConstVal::Unevaluated(..) => bug!("should be evaluated"), - }; - - let alloc = tcx.const_value_to_allocation((const_val, val.ty)); + let alloc = tcx.const_value_to_allocation(val); (section.to_string(), alloc.bytes.clone()) } diff --git a/src/librustc_codegen_llvm/mir/constant.rs b/src/librustc_codegen_llvm/mir/constant.rs index 7c1035e2fcb..bbe0e34b48f 100644 --- a/src/librustc_codegen_llvm/mir/constant.rs +++ b/src/librustc_codegen_llvm/mir/constant.rs @@ -9,11 +9,12 @@ // except according to those terms. use llvm::{self, ValueRef}; -use rustc::middle::const_val::{ConstVal, ConstEvalErr}; +use rustc::mir::interpret::ConstEvalErr; use rustc_mir::interpret::{read_target_uint, const_val_field}; use rustc::hir::def_id::DefId; use rustc::mir; use rustc_data_structures::indexed_vec::Idx; +use rustc_data_structures::sync::Lrc; use rustc::mir::interpret::{GlobalId, Pointer, Scalar, Allocation, ConstValue, AllocType}; use rustc::ty::{self, Ty}; use rustc::ty::layout::{self, HasDataLayout, LayoutOf, Size}; @@ -117,7 +118,7 @@ pub fn const_alloc_to_llvm(cx: &CodegenCx, alloc: &Allocation) -> ValueRef { pub fn codegen_static_initializer<'a, 'tcx>( cx: &CodegenCx<'a, 'tcx>, def_id: DefId) - -> Result<ValueRef, ConstEvalErr<'tcx>> + -> Result<ValueRef, Lrc<ConstEvalErr<'tcx>>> { let instance = ty::Instance::mono(cx.tcx, def_id); let cid = GlobalId { @@ -128,20 +129,20 @@ pub fn codegen_static_initializer<'a, 'tcx>( let static_ = cx.tcx.const_eval(param_env.and(cid))?; let alloc = match static_.val { - ConstVal::Value(ConstValue::ByRef(alloc, n)) if n.bytes() == 0 => alloc, + ConstValue::ByRef(alloc, n) if n.bytes() == 0 => alloc, _ => bug!("static const eval returned {:#?}", static_), }; Ok(const_alloc_to_llvm(cx, alloc)) } impl<'a, 'tcx> FunctionCx<'a, 'tcx> { - fn const_to_const_value( + fn fully_evaluate( &mut self, bx: &Builder<'a, 'tcx>, constant: &'tcx ty::Const<'tcx>, - ) -> Result<ConstValue<'tcx>, ConstEvalErr<'tcx>> { + ) -> Result<&'tcx ty::Const<'tcx>, Lrc<ConstEvalErr<'tcx>>> { match constant.val { - ConstVal::Unevaluated(def_id, ref substs) => { + ConstValue::Unevaluated(def_id, ref substs) => { let tcx = bx.tcx(); let param_env = ty::ParamEnv::reveal_all(); let instance = ty::Instance::resolve(tcx, param_env, def_id, substs).unwrap(); @@ -149,18 +150,17 @@ impl<'a, 'tcx> FunctionCx<'a, 'tcx> { instance, promoted: None, }; - let c = tcx.const_eval(param_env.and(cid))?; - self.const_to_const_value(bx, c) + tcx.const_eval(param_env.and(cid)) }, - ConstVal::Value(val) => Ok(val), + _ => Ok(constant), } } - pub fn mir_constant_to_const_value( + pub fn eval_mir_constant( &mut self, bx: &Builder<'a, 'tcx>, constant: &mir::Constant<'tcx>, - ) -> Result<ConstValue<'tcx>, ConstEvalErr<'tcx>> { + ) -> Result<&'tcx ty::Const<'tcx>, Lrc<ConstEvalErr<'tcx>>> { match constant.literal { mir::Literal::Promoted { index } => { let param_env = ty::ParamEnv::reveal_all(); @@ -173,7 +173,7 @@ impl<'a, 'tcx> FunctionCx<'a, 'tcx> { mir::Literal::Value { value } => { Ok(self.monomorphize(&value)) } - }.and_then(|c| self.const_to_const_value(bx, c)) + }.and_then(|c| self.fully_evaluate(bx, c)) } /// process constant containing SIMD shuffle indices @@ -182,14 +182,14 @@ impl<'a, 'tcx> FunctionCx<'a, 'tcx> { bx: &Builder<'a, 'tcx>, constant: &mir::Constant<'tcx>, ) -> (ValueRef, Ty<'tcx>) { - self.mir_constant_to_const_value(bx, constant) + self.eval_mir_constant(bx, constant) .and_then(|c| { - let field_ty = constant.ty.builtin_index().unwrap(); - let fields = match constant.ty.sty { + let field_ty = c.ty.builtin_index().unwrap(); + let fields = match c.ty.sty { ty::TyArray(_, n) => n.unwrap_usize(bx.tcx()), ref other => bug!("invalid simd shuffle type: {}", other), }; - let values: Result<Vec<ValueRef>, _> = (0..fields).map(|field| { + let values: Result<Vec<ValueRef>, Lrc<_>> = (0..fields).map(|field| { let field = const_val_field( bx.tcx(), ty::ParamEnv::reveal_all(), @@ -197,7 +197,6 @@ impl<'a, 'tcx> FunctionCx<'a, 'tcx> { None, mir::Field::new(field as usize), c, - constant.ty, )?; if let Some(prim) = field.to_scalar() { let layout = bx.cx.layout_of(field_ty); @@ -214,7 +213,7 @@ impl<'a, 'tcx> FunctionCx<'a, 'tcx> { } }).collect(); let llval = C_struct(bx.cx, &values?, false); - Ok((llval, constant.ty)) + Ok((llval, c.ty)) }) .unwrap_or_else(|e| { e.report_as_error( diff --git a/src/librustc_codegen_llvm/mir/operand.rs b/src/librustc_codegen_llvm/mir/operand.rs index 9f32b41cb13..3d3a4400bd8 100644 --- a/src/librustc_codegen_llvm/mir/operand.rs +++ b/src/librustc_codegen_llvm/mir/operand.rs @@ -9,12 +9,13 @@ // except according to those terms. use llvm::{ValueRef, LLVMConstInBoundsGEP}; -use rustc::middle::const_val::ConstEvalErr; +use rustc::mir::interpret::ConstEvalErr; use rustc::mir; use rustc::mir::interpret::ConstValue; use rustc::ty; use rustc::ty::layout::{self, Align, LayoutOf, TyLayout}; use rustc_data_structures::indexed_vec::Idx; +use rustc_data_structures::sync::Lrc; use base; use common::{self, CodegenCx, C_null, C_undef, C_usize}; @@ -95,16 +96,16 @@ impl<'a, 'tcx> OperandRef<'tcx> { } pub fn from_const(bx: &Builder<'a, 'tcx>, - val: ConstValue<'tcx>, - ty: ty::Ty<'tcx>) - -> Result<OperandRef<'tcx>, ConstEvalErr<'tcx>> { - let layout = bx.cx.layout_of(ty); + val: &'tcx ty::Const<'tcx>) + -> Result<OperandRef<'tcx>, Lrc<ConstEvalErr<'tcx>>> { + let layout = bx.cx.layout_of(val.ty); if layout.is_zst() { return Ok(OperandRef::new_zst(bx.cx, layout)); } - let val = match val { + let val = match val.val { + ConstValue::Unevaluated(..) => bug!(), ConstValue::Scalar(x) => { let scalar = match layout.abi { layout::Abi::Scalar(ref x) => x, @@ -408,8 +409,8 @@ impl<'a, 'tcx> FunctionCx<'a, 'tcx> { mir::Operand::Constant(ref constant) => { let ty = self.monomorphize(&constant.ty); - self.mir_constant_to_const_value(bx, constant) - .and_then(|c| OperandRef::from_const(bx, c, ty)) + self.eval_mir_constant(bx, constant) + .and_then(|c| OperandRef::from_const(bx, c)) .unwrap_or_else(|err| { match constant.literal { mir::Literal::Promoted { .. } => { |
