Skip to content

Commit

Permalink
miri: move param_env from Machine to EvalContext.
Browse files Browse the repository at this point in the history
  • Loading branch information
eddyb committed Dec 6, 2017
1 parent bf5ec79 commit ff6152c
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 24 deletions.
9 changes: 2 additions & 7 deletions src/librustc/mir/interpret/const_eval.rs
Expand Up @@ -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,
Expand Down Expand Up @@ -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>,
Expand Down
11 changes: 8 additions & 3 deletions src/librustc/mir/interpret/eval_context.rs
Expand Up @@ -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>,

Expand Down Expand Up @@ -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())
}
}
Expand All @@ -212,13 +215,15 @@ 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,
) -> Self {
EvalContext {
machine_data,
tcx,
param_env,
memory: Memory::new(tcx, limits.memory_size, memory_data),
suspended: HashMap::new(),
stack: Vec::new(),
Expand Down Expand Up @@ -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(
Expand Down
5 changes: 0 additions & 5 deletions src/librustc/mir/interpret/machine.rs
Expand Up @@ -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
Expand Down
10 changes: 3 additions & 7 deletions src/librustc/mir/interpret/step.rs
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_const_eval/eval.rs
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit ff6152c

Please sign in to comment.