diff options
| author | Oliver Schneider <git-spam-no-reply9815368754983@oli-obk.de> | 2017-09-19 09:08:48 +0200 |
|---|---|---|
| committer | Oliver Schneider <git-spam-no-reply9815368754983@oli-obk.de> | 2017-09-29 12:55:08 +0200 |
| commit | d4c442d65c150b99d18202a5cce4a2cbdbd4dc83 (patch) | |
| tree | 0b33d1660de756163b50fe278c6450e272e9870d | |
| parent | ea35192d7c3e64b8be7f694d0743d123b0c4563a (diff) | |
| download | rust-d4c442d65c150b99d18202a5cce4a2cbdbd4dc83.tar.gz rust-d4c442d65c150b99d18202a5cce4a2cbdbd4dc83.zip | |
Expose miri <-> ctfe differences
miri needs to start storing everything in the TyCtxt so we can have relocations and aggregates
| -rw-r--r-- | src/librustc/mir/interpret/const_eval.rs | 7 | ||||
| -rw-r--r-- | src/librustc/mir/interpret/eval_context.rs | 6 | ||||
| -rw-r--r-- | src/librustc_const_eval/eval.rs | 34 |
3 files changed, 26 insertions, 21 deletions
diff --git a/src/librustc/mir/interpret/const_eval.rs b/src/librustc/mir/interpret/const_eval.rs index f288767a644..10da2b9ded7 100644 --- a/src/librustc/mir/interpret/const_eval.rs +++ b/src/librustc/mir/interpret/const_eval.rs @@ -13,10 +13,10 @@ use rustc_const_math::ConstInt; use std::fmt; use std::error::Error; -pub fn eval_body_as_primval<'a, 'tcx>( +pub fn eval_body<'a, 'tcx>( tcx: TyCtxt<'a, 'tcx, 'tcx>, instance: Instance<'tcx>, -) -> EvalResult<'tcx, (PrimVal, Ty<'tcx>)> { +) -> EvalResult<'tcx, (Value, Ty<'tcx>)> { let limits = super::ResourceLimits::default(); let mut ecx = EvalContext::<CompileTimeFunctionEvaluator>::new(tcx, limits, (), ()); let cid = GlobalId { @@ -73,7 +73,8 @@ pub fn eval_body_as_primval<'a, 'tcx>( value, ty: mir.return_ty, }; - Ok((ecx.value_to_primval(valty)?, mir.return_ty)) + // FIXME: store cached value in TyCtxt + Ok(value, mir.return_ty)) } pub fn eval_body_as_integer<'a, 'tcx>( diff --git a/src/librustc/mir/interpret/eval_context.rs b/src/librustc/mir/interpret/eval_context.rs index 879bbf8fb7b..d9416c09699 100644 --- a/src/librustc/mir/interpret/eval_context.rs +++ b/src/librustc/mir/interpret/eval_context.rs @@ -1895,7 +1895,11 @@ impl<'a, 'tcx, M: Machine<'tcx>> EvalContext<'a, 'tcx, M> { } pub(super) fn substs(&self) -> &'tcx Substs<'tcx> { - self.frame().instance.substs + if let Some(frame) = self.stack.last() { + frame.instance.substs + } else { + Substs::empty() + } } fn unsize_into_ptr( diff --git a/src/librustc_const_eval/eval.rs b/src/librustc_const_eval/eval.rs index 492b3a13a41..20745c27838 100644 --- a/src/librustc_const_eval/eval.rs +++ b/src/librustc_const_eval/eval.rs @@ -793,68 +793,68 @@ fn const_eval<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, }; let instance = ty::Instance::new(def_id, substs); - let miri_result = ::rustc::interpret::eval_body_as_primval(tcx, instance); + let miri_result = ::rustc::mir::interpret::eval_body_as_primval(tcx, instance); let old_result = ConstContext::new(tcx, key.param_env.and(substs), tables).eval(&body.value); match (miri_result, old_result) { (Err(err), Ok(ok)) => { - warn!("miri fails to eval {:?} to {:?} with error {:?}", key, ok, err); - Ok(ok) + panic!("miri fails to eval {:?} to {:?} with error {:?}", key, ok, err); + //Ok(ok) }, (Ok(ok), Err(err)) => { - info!("miri can eval {:?} to {:?}, while old ctfe fails with {:?}", key, ok, err); - Err(err) + panic!("miri can eval {:?} to {:?}, while old ctfe fails with {:?}", key, ok, err); + //Err(err) }, (Err(_), Err(err)) => Err(err), (Ok((miri_val, miri_ty)), Ok(ctfe)) => { use rustc::ty::TypeVariants::*; - use rustc::interpret::PrimVal; + use rustc::mir::interpret::PrimVal; match (miri_val, &miri_ty.sty, ctfe.val) { (PrimVal::Undef, _, _) => { - warn!("miri produced an undef, while old ctfe produced {:?}", ctfe); + panic!("miri produced an undef, while old ctfe produced {:?}", ctfe); }, (PrimVal::Ptr(_), _, _) => { - warn!("miri produced a pointer, which isn't implemented yet"); + panic!("miri produced a pointer, which isn't implemented yet"); }, (PrimVal::Bytes(b), &TyInt(int_ty), ConstVal::Integral(ci)) => { let c = ConstInt::new_signed_truncating(b as i128, int_ty, tcx.sess.target.isize_ty); if c != ci { - warn!("miri evaluated to {}, but ctfe yielded {}", b as i128, ci); + panic!("miri evaluated to {}, but ctfe yielded {}", b as i128, ci); } } (PrimVal::Bytes(b), &TyUint(int_ty), ConstVal::Integral(ci)) => { let c = ConstInt::new_unsigned_truncating(b, int_ty, tcx.sess.target.usize_ty); if c != ci { - warn!("miri evaluated to {}, but ctfe yielded {}", b, ci); + panic!("miri evaluated to {}, but ctfe yielded {}", b, ci); } } (PrimVal::Bytes(bits), &TyFloat(ty), ConstVal::Float(cf)) => { let f = ConstFloat { bits, ty }; if f != cf { - warn!("miri evaluated to {}, but ctfe yielded {}", f, cf); + panic!("miri evaluated to {}, but ctfe yielded {}", f, cf); } } (PrimVal::Bytes(bits), &TyBool, ConstVal::Bool(b)) => { if bits == 0 && b { - warn!("miri evaluated to {}, but ctfe yielded {}", bits == 0, b); + panic!("miri evaluated to {}, but ctfe yielded {}", bits == 0, b); } else if bits == 1 && !b { - warn!("miri evaluated to {}, but ctfe yielded {}", bits == 1, b); + panic!("miri evaluated to {}, but ctfe yielded {}", bits == 1, b); } else { - warn!("miri evaluated to {}, but expected a bool {}", bits, b); + panic!("miri evaluated to {}, but expected a bool {}", bits, b); } } (PrimVal::Bytes(bits), &TyChar, ConstVal::Char(c)) => { if let Some(cm) = ::std::char::from_u32(bits as u32) { if cm != c { - warn!("miri evaluated to {:?}, but expected {:?}", cm, c); + panic!("miri evaluated to {:?}, but expected {:?}", cm, c); } } else { - warn!("miri evaluated to {}, but expected a char {:?}", bits, c); + panic!("miri evaluated to {}, but expected a char {:?}", bits, c); } } _ => { - info!("can't check whether miri's {:?} ({}) makes sense when ctfe yields {:?}", + panic!("can't check whether miri's {:?} ({}) makes sense when ctfe yields {:?}", miri_val, miri_ty, ctfe) |
