miri: move param_env from Machine to EvalContext.
This commit is contained in:
parent
bf5ec79725
commit
ff6152cdc8
5 changed files with 15 additions and 24 deletions
|
|
@ -20,7 +20,7 @@ pub fn eval_body<'a, 'tcx>(
|
|||
) -> (EvalResult<'tcx, (PtrAndAlign, Ty<'tcx>)>, EvalContext<'a, 'tcx, CompileTimeFunctionEvaluator>) {
|
||||
debug!("eval_body: {:?}, {:?}", instance, param_env);
|
||||
let limits = super::ResourceLimits::default();
|
||||
let mut ecx = EvalContext::<CompileTimeFunctionEvaluator>::new(tcx, limits, param_env, ());
|
||||
let mut ecx = EvalContext::<CompileTimeFunctionEvaluator>::new(tcx, param_env, limits, (), ());
|
||||
let cid = GlobalId {
|
||||
instance,
|
||||
promoted: None,
|
||||
|
|
@ -165,14 +165,9 @@ impl Error for ConstEvalError {
|
|||
}
|
||||
|
||||
impl<'tcx> super::Machine<'tcx> for CompileTimeFunctionEvaluator {
|
||||
type Data = ty::ParamEnv<'tcx>;
|
||||
type Data = ();
|
||||
type MemoryData = ();
|
||||
type MemoryKinds = !;
|
||||
fn param_env<'a>(
|
||||
ecx: &EvalContext<'a, 'tcx, Self>,
|
||||
) -> ty::ParamEnv<'tcx> {
|
||||
ecx.machine_data
|
||||
}
|
||||
fn eval_fn_call<'a>(
|
||||
ecx: &mut EvalContext<'a, 'tcx, Self>,
|
||||
instance: ty::Instance<'tcx>,
|
||||
|
|
|
|||
|
|
@ -25,6 +25,9 @@ pub struct EvalContext<'a, 'tcx: 'a, M: Machine<'tcx>> {
|
|||
/// The results of the type checker, from rustc.
|
||||
pub tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
|
||||
/// Bounds in scope for polymorphic evaluations.
|
||||
pub param_env: ty::ParamEnv<'tcx>,
|
||||
|
||||
/// The virtual memory system.
|
||||
pub memory: Memory<'a, 'tcx, M>,
|
||||
|
||||
|
|
@ -194,7 +197,7 @@ impl<'a, 'tcx, M: Machine<'tcx>> LayoutOf<Ty<'tcx>> for &'a EvalContext<'a, 'tcx
|
|||
type TyLayout = EvalResult<'tcx, TyLayout<'tcx>>;
|
||||
|
||||
fn layout_of(self, ty: Ty<'tcx>) -> Self::TyLayout {
|
||||
(self.tcx, M::param_env(self)).layout_of(ty)
|
||||
(self.tcx, self.param_env).layout_of(ty)
|
||||
.map_err(|layout| EvalErrorKind::Layout(layout).into())
|
||||
}
|
||||
}
|
||||
|
|
@ -212,6 +215,7 @@ impl<'c, 'b, 'a, 'tcx, M: Machine<'tcx>> LayoutOf<Ty<'tcx>>
|
|||
impl<'a, 'tcx, M: Machine<'tcx>> EvalContext<'a, 'tcx, M> {
|
||||
pub fn new(
|
||||
tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
param_env: ty::ParamEnv<'tcx>,
|
||||
limits: ResourceLimits,
|
||||
machine_data: M::Data,
|
||||
memory_data: M::MemoryData,
|
||||
|
|
@ -219,6 +223,7 @@ impl<'a, 'tcx, M: Machine<'tcx>> EvalContext<'a, 'tcx, M> {
|
|||
EvalContext {
|
||||
machine_data,
|
||||
tcx,
|
||||
param_env,
|
||||
memory: Memory::new(tcx, limits.memory_size, memory_data),
|
||||
suspended: HashMap::new(),
|
||||
stack: Vec::new(),
|
||||
|
|
@ -302,14 +307,14 @@ impl<'a, 'tcx, M: Machine<'tcx>> EvalContext<'a, 'tcx, M> {
|
|||
let substs = self.tcx.trans_apply_param_substs(self.substs(), &substs);
|
||||
ty::Instance::resolve(
|
||||
self.tcx,
|
||||
M::param_env(self),
|
||||
self.param_env,
|
||||
def_id,
|
||||
substs,
|
||||
).ok_or(EvalErrorKind::TypeckError.into()) // turn error prop into a panic to expose associated type in const issue
|
||||
}
|
||||
|
||||
pub(super) fn type_is_sized(&self, ty: Ty<'tcx>) -> bool {
|
||||
ty.is_sized(self.tcx, M::param_env(self), DUMMY_SP)
|
||||
ty.is_sized(self.tcx, self.param_env, DUMMY_SP)
|
||||
}
|
||||
|
||||
pub fn load_mir(
|
||||
|
|
|
|||
|
|
@ -21,11 +21,6 @@ pub trait Machine<'tcx>: Sized {
|
|||
/// Additional memory kinds a machine wishes to distinguish from the builtin ones
|
||||
type MemoryKinds: ::std::fmt::Debug + PartialEq + Copy + Clone;
|
||||
|
||||
/// Produces the param env for this computation.
|
||||
fn param_env<'a>(
|
||||
ecx: &EvalContext<'a, 'tcx, Self>,
|
||||
) -> ty::ParamEnv<'tcx>;
|
||||
|
||||
/// Entry point to all function calls.
|
||||
///
|
||||
/// Returns Ok(true) when the function was handled completely
|
||||
|
|
|
|||
|
|
@ -188,11 +188,7 @@ impl<'a, 'tcx, M: Machine<'tcx>> EvalContext<'a, 'tcx, M> {
|
|||
aligned: !layout.is_packed(),
|
||||
},
|
||||
);
|
||||
let internally_mutable = !layout.ty.is_freeze(
|
||||
self.tcx,
|
||||
M::param_env(self),
|
||||
span,
|
||||
);
|
||||
let internally_mutable = !layout.ty.is_freeze(self.tcx, self.param_env, span);
|
||||
let mutability = if mutability == Mutability::Mutable || internally_mutable {
|
||||
Mutability::Mutable
|
||||
} else {
|
||||
|
|
@ -245,10 +241,10 @@ impl<'a, 'b, 'tcx, M: Machine<'tcx>> Visitor<'tcx> for ConstantExtractor<'a, 'b,
|
|||
debug!("global_item: {:?}, {:#?}", def_id, substs);
|
||||
let substs = this.ecx.tcx.trans_apply_param_substs(this.instance.substs, &substs);
|
||||
debug!("global_item_new_substs: {:#?}", substs);
|
||||
debug!("global_item_param_env: {:#?}", M::param_env(this.ecx));
|
||||
debug!("global_item_param_env: {:#?}", this.ecx.param_env);
|
||||
let instance = Instance::resolve(
|
||||
this.ecx.tcx,
|
||||
M::param_env(this.ecx),
|
||||
this.ecx.param_env,
|
||||
def_id,
|
||||
substs,
|
||||
).ok_or(EvalErrorKind::TypeckError)?; // turn error prop into a panic to expose associated type in const issue
|
||||
|
|
|
|||
|
|
@ -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, Machine};
|
||||
use rustc::mir::interpret::{CompileTimeFunctionEvaluator, EvalContext};
|
||||
use rustc::mir::Field;
|
||||
use rustc::mir::interpret::{Place, PlaceExtra};
|
||||
use rustc_data_structures::indexed_vec::Idx;
|
||||
|
|
@ -937,7 +937,7 @@ fn check_ctfe_against_miri<'a, 'tcx>(
|
|||
ConstVal::Function(did, substs) => {
|
||||
let ctfe = ty::Instance::resolve(
|
||||
ecx.tcx,
|
||||
CompileTimeFunctionEvaluator::param_env(&ecx),
|
||||
ecx.param_env,
|
||||
did,
|
||||
substs,
|
||||
).unwrap();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue