mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-23 12:23:22 +00:00
Expose miri <-> ctfe differences
miri needs to start storing everything in the TyCtxt so we can have relocations and aggregates
This commit is contained in:
parent
ea35192d7c
commit
d4c442d65c
@ -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>(
|
||||
|
@ -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(
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user