miri: don't use an associated constant for a Machine's own data.
This commit is contained in:
parent
ff6152cdc8
commit
9cb6499dde
5 changed files with 13 additions and 17 deletions
|
@ -17,10 +17,10 @@ pub fn eval_body<'a, 'tcx>(
|
|||
tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
instance: Instance<'tcx>,
|
||||
param_env: ty::ParamEnv<'tcx>,
|
||||
) -> (EvalResult<'tcx, (PtrAndAlign, Ty<'tcx>)>, EvalContext<'a, 'tcx, CompileTimeFunctionEvaluator>) {
|
||||
) -> (EvalResult<'tcx, (PtrAndAlign, Ty<'tcx>)>, EvalContext<'a, 'tcx, CompileTimeEvaluator>) {
|
||||
debug!("eval_body: {:?}, {:?}", instance, param_env);
|
||||
let limits = super::ResourceLimits::default();
|
||||
let mut ecx = EvalContext::<CompileTimeFunctionEvaluator>::new(tcx, param_env, limits, (), ());
|
||||
let mut ecx = EvalContext::new(tcx, param_env, limits, CompileTimeEvaluator, ());
|
||||
let cid = GlobalId {
|
||||
instance,
|
||||
promoted: None,
|
||||
|
@ -120,7 +120,7 @@ pub fn eval_body_as_integer<'a, 'tcx>(
|
|||
})
|
||||
}
|
||||
|
||||
pub struct CompileTimeFunctionEvaluator;
|
||||
pub struct CompileTimeEvaluator;
|
||||
|
||||
impl<'tcx> Into<EvalError<'tcx>> for ConstEvalError {
|
||||
fn into(self) -> EvalError<'tcx> {
|
||||
|
@ -164,8 +164,7 @@ impl Error for ConstEvalError {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'tcx> super::Machine<'tcx> for CompileTimeFunctionEvaluator {
|
||||
type Data = ();
|
||||
impl<'tcx> super::Machine<'tcx> for CompileTimeEvaluator {
|
||||
type MemoryData = ();
|
||||
type MemoryKinds = !;
|
||||
fn eval_fn_call<'a>(
|
||||
|
|
|
@ -19,8 +19,8 @@ use super::{EvalError, EvalResult, EvalErrorKind, GlobalId, Place, PlaceExtra, M
|
|||
ValidationQuery, Machine};
|
||||
|
||||
pub struct EvalContext<'a, 'tcx: 'a, M: Machine<'tcx>> {
|
||||
/// Stores data required by the `Machine`
|
||||
pub machine_data: M::Data,
|
||||
/// Stores the `Machine` instance.
|
||||
pub machine: M,
|
||||
|
||||
/// The results of the type checker, from rustc.
|
||||
pub tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
|
@ -217,11 +217,11 @@ impl<'a, 'tcx, M: Machine<'tcx>> EvalContext<'a, 'tcx, M> {
|
|||
tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
param_env: ty::ParamEnv<'tcx>,
|
||||
limits: ResourceLimits,
|
||||
machine_data: M::Data,
|
||||
machine: M,
|
||||
memory_data: M::MemoryData,
|
||||
) -> Self {
|
||||
EvalContext {
|
||||
machine_data,
|
||||
machine,
|
||||
tcx,
|
||||
param_env,
|
||||
memory: Memory::new(tcx, limits.memory_size, memory_data),
|
||||
|
|
|
@ -12,9 +12,6 @@ use syntax::ast::Mutability;
|
|||
/// Methods of this trait signifies a point where CTFE evaluation would fail
|
||||
/// and some use case dependent behaviour can instead be applied
|
||||
pub trait Machine<'tcx>: Sized {
|
||||
/// Additional data that can be accessed via the EvalContext
|
||||
type Data;
|
||||
|
||||
/// Additional data that can be accessed via the Memory
|
||||
type MemoryData;
|
||||
|
||||
|
|
|
@ -35,7 +35,7 @@ use self::range_map::RangeMap;
|
|||
|
||||
pub use self::value::{PrimVal, PrimValKind, Value, Pointer};
|
||||
|
||||
pub use self::const_eval::{eval_body_as_integer, eval_body, CompileTimeFunctionEvaluator};
|
||||
pub use self::const_eval::{eval_body_as_integer, eval_body, CompileTimeEvaluator};
|
||||
|
||||
pub use self::machine::Machine;
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@ use rustc::util::common::ErrorReported;
|
|||
use rustc::util::nodemap::NodeMap;
|
||||
|
||||
use rustc::mir::interpret::{PrimVal, Value, PtrAndAlign, HasMemory, EvalError};
|
||||
use rustc::mir::interpret::{CompileTimeFunctionEvaluator, EvalContext};
|
||||
use rustc::mir::interpret::{CompileTimeEvaluator, EvalContext};
|
||||
use rustc::mir::Field;
|
||||
use rustc::mir::interpret::{Place, PlaceExtra};
|
||||
use rustc_data_structures::indexed_vec::Idx;
|
||||
|
@ -754,7 +754,7 @@ pub(crate) fn const_eval<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
|||
}
|
||||
|
||||
fn check_ctfe_against_miri<'a, 'tcx>(
|
||||
ecx: &mut EvalContext<'a, 'tcx, CompileTimeFunctionEvaluator>,
|
||||
ecx: &mut EvalContext<'a, 'tcx, CompileTimeEvaluator>,
|
||||
miri_val: PtrAndAlign,
|
||||
miri_ty: Ty<'tcx>,
|
||||
ctfe: ConstVal<'tcx>,
|
||||
|
@ -950,7 +950,7 @@ fn check_ctfe_against_miri<'a, 'tcx>(
|
|||
}
|
||||
|
||||
fn get_prim<'a, 'tcx>(
|
||||
ecx: &mut EvalContext<'a, 'tcx, CompileTimeFunctionEvaluator>,
|
||||
ecx: &mut EvalContext<'a, 'tcx, CompileTimeEvaluator>,
|
||||
res: Result<Option<Value>, EvalError<'tcx>>,
|
||||
) -> u128 {
|
||||
match res {
|
||||
|
@ -961,7 +961,7 @@ fn get_prim<'a, 'tcx>(
|
|||
}
|
||||
|
||||
fn unwrap_miri<'a, 'tcx, T>(
|
||||
ecx: &EvalContext<'a, 'tcx, CompileTimeFunctionEvaluator>,
|
||||
ecx: &EvalContext<'a, 'tcx, CompileTimeEvaluator>,
|
||||
res: Result<T, EvalError<'tcx>>,
|
||||
) -> T {
|
||||
match res {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue