Skip to content

Commit ff6152c

Browse files
committed
miri: move param_env from Machine to EvalContext.
1 parent bf5ec79 commit ff6152c

File tree

5 files changed

+15
-24
lines changed

5 files changed

+15
-24
lines changed

src/librustc/mir/interpret/const_eval.rs

+2-7
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ pub fn eval_body<'a, 'tcx>(
2020
) -> (EvalResult<'tcx, (PtrAndAlign, Ty<'tcx>)>, EvalContext<'a, 'tcx, CompileTimeFunctionEvaluator>) {
2121
debug!("eval_body: {:?}, {:?}", instance, param_env);
2222
let limits = super::ResourceLimits::default();
23-
let mut ecx = EvalContext::<CompileTimeFunctionEvaluator>::new(tcx, limits, param_env, ());
23+
let mut ecx = EvalContext::<CompileTimeFunctionEvaluator>::new(tcx, param_env, limits, (), ());
2424
let cid = GlobalId {
2525
instance,
2626
promoted: None,
@@ -165,14 +165,9 @@ impl Error for ConstEvalError {
165165
}
166166

167167
impl<'tcx> super::Machine<'tcx> for CompileTimeFunctionEvaluator {
168-
type Data = ty::ParamEnv<'tcx>;
168+
type Data = ();
169169
type MemoryData = ();
170170
type MemoryKinds = !;
171-
fn param_env<'a>(
172-
ecx: &EvalContext<'a, 'tcx, Self>,
173-
) -> ty::ParamEnv<'tcx> {
174-
ecx.machine_data
175-
}
176171
fn eval_fn_call<'a>(
177172
ecx: &mut EvalContext<'a, 'tcx, Self>,
178173
instance: ty::Instance<'tcx>,

src/librustc/mir/interpret/eval_context.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ pub struct EvalContext<'a, 'tcx: 'a, M: Machine<'tcx>> {
2525
/// The results of the type checker, from rustc.
2626
pub tcx: TyCtxt<'a, 'tcx, 'tcx>,
2727

28+
/// Bounds in scope for polymorphic evaluations.
29+
pub param_env: ty::ParamEnv<'tcx>,
30+
2831
/// The virtual memory system.
2932
pub memory: Memory<'a, 'tcx, M>,
3033

@@ -194,7 +197,7 @@ impl<'a, 'tcx, M: Machine<'tcx>> LayoutOf<Ty<'tcx>> for &'a EvalContext<'a, 'tcx
194197
type TyLayout = EvalResult<'tcx, TyLayout<'tcx>>;
195198

196199
fn layout_of(self, ty: Ty<'tcx>) -> Self::TyLayout {
197-
(self.tcx, M::param_env(self)).layout_of(ty)
200+
(self.tcx, self.param_env).layout_of(ty)
198201
.map_err(|layout| EvalErrorKind::Layout(layout).into())
199202
}
200203
}
@@ -212,13 +215,15 @@ impl<'c, 'b, 'a, 'tcx, M: Machine<'tcx>> LayoutOf<Ty<'tcx>>
212215
impl<'a, 'tcx, M: Machine<'tcx>> EvalContext<'a, 'tcx, M> {
213216
pub fn new(
214217
tcx: TyCtxt<'a, 'tcx, 'tcx>,
218+
param_env: ty::ParamEnv<'tcx>,
215219
limits: ResourceLimits,
216220
machine_data: M::Data,
217221
memory_data: M::MemoryData,
218222
) -> Self {
219223
EvalContext {
220224
machine_data,
221225
tcx,
226+
param_env,
222227
memory: Memory::new(tcx, limits.memory_size, memory_data),
223228
suspended: HashMap::new(),
224229
stack: Vec::new(),
@@ -302,14 +307,14 @@ impl<'a, 'tcx, M: Machine<'tcx>> EvalContext<'a, 'tcx, M> {
302307
let substs = self.tcx.trans_apply_param_substs(self.substs(), &substs);
303308
ty::Instance::resolve(
304309
self.tcx,
305-
M::param_env(self),
310+
self.param_env,
306311
def_id,
307312
substs,
308313
).ok_or(EvalErrorKind::TypeckError.into()) // turn error prop into a panic to expose associated type in const issue
309314
}
310315

311316
pub(super) fn type_is_sized(&self, ty: Ty<'tcx>) -> bool {
312-
ty.is_sized(self.tcx, M::param_env(self), DUMMY_SP)
317+
ty.is_sized(self.tcx, self.param_env, DUMMY_SP)
313318
}
314319

315320
pub fn load_mir(

src/librustc/mir/interpret/machine.rs

-5
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,6 @@ pub trait Machine<'tcx>: Sized {
2121
/// Additional memory kinds a machine wishes to distinguish from the builtin ones
2222
type MemoryKinds: ::std::fmt::Debug + PartialEq + Copy + Clone;
2323

24-
/// Produces the param env for this computation.
25-
fn param_env<'a>(
26-
ecx: &EvalContext<'a, 'tcx, Self>,
27-
) -> ty::ParamEnv<'tcx>;
28-
2924
/// Entry point to all function calls.
3025
///
3126
/// Returns Ok(true) when the function was handled completely

src/librustc/mir/interpret/step.rs

+3-7
Original file line numberDiff line numberDiff line change
@@ -188,11 +188,7 @@ impl<'a, 'tcx, M: Machine<'tcx>> EvalContext<'a, 'tcx, M> {
188188
aligned: !layout.is_packed(),
189189
},
190190
);
191-
let internally_mutable = !layout.ty.is_freeze(
192-
self.tcx,
193-
M::param_env(self),
194-
span,
195-
);
191+
let internally_mutable = !layout.ty.is_freeze(self.tcx, self.param_env, span);
196192
let mutability = if mutability == Mutability::Mutable || internally_mutable {
197193
Mutability::Mutable
198194
} else {
@@ -245,10 +241,10 @@ impl<'a, 'b, 'tcx, M: Machine<'tcx>> Visitor<'tcx> for ConstantExtractor<'a, 'b,
245241
debug!("global_item: {:?}, {:#?}", def_id, substs);
246242
let substs = this.ecx.tcx.trans_apply_param_substs(this.instance.substs, &substs);
247243
debug!("global_item_new_substs: {:#?}", substs);
248-
debug!("global_item_param_env: {:#?}", M::param_env(this.ecx));
244+
debug!("global_item_param_env: {:#?}", this.ecx.param_env);
249245
let instance = Instance::resolve(
250246
this.ecx.tcx,
251-
M::param_env(this.ecx),
247+
this.ecx.param_env,
252248
def_id,
253249
substs,
254250
).ok_or(EvalErrorKind::TypeckError)?; // turn error prop into a panic to expose associated type in const issue

src/librustc_const_eval/eval.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use rustc::util::common::ErrorReported;
2424
use rustc::util::nodemap::NodeMap;
2525

2626
use rustc::mir::interpret::{PrimVal, Value, PtrAndAlign, HasMemory, EvalError};
27-
use rustc::mir::interpret::{CompileTimeFunctionEvaluator, EvalContext, Machine};
27+
use rustc::mir::interpret::{CompileTimeFunctionEvaluator, EvalContext};
2828
use rustc::mir::Field;
2929
use rustc::mir::interpret::{Place, PlaceExtra};
3030
use rustc_data_structures::indexed_vec::Idx;
@@ -937,7 +937,7 @@ fn check_ctfe_against_miri<'a, 'tcx>(
937937
ConstVal::Function(did, substs) => {
938938
let ctfe = ty::Instance::resolve(
939939
ecx.tcx,
940-
CompileTimeFunctionEvaluator::param_env(&ecx),
940+
ecx.param_env,
941941
did,
942942
substs,
943943
).unwrap();

0 commit comments

Comments
 (0)