mirror of
https://github.com/rust-lang/rust.git
synced 2024-12-05 21:24:12 +00:00
start cleaning up subst mess
fix an ICE fix method name
This commit is contained in:
parent
cdff918955
commit
d4196a7673
@ -67,7 +67,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
||||
// The src operand does not matter, just its type
|
||||
match src.layout.ty.sty {
|
||||
ty::Closure(def_id, substs) => {
|
||||
let substs = self.subst_and_normalize_erasing_regions(substs)?;
|
||||
let substs = self.subst_from_frame_and_normalize_erasing_regions(substs)?;
|
||||
let instance = ty::Instance::resolve_closure(
|
||||
*self.tcx,
|
||||
def_id,
|
||||
|
@ -9,7 +9,7 @@ use rustc::mir;
|
||||
use rustc::ty::layout::{
|
||||
self, Size, Align, HasDataLayout, LayoutOf, TyLayout
|
||||
};
|
||||
use rustc::ty::subst::{Subst, SubstsRef};
|
||||
use rustc::ty::subst::SubstsRef;
|
||||
use rustc::ty::{self, Ty, TyCtxt, TypeFoldable};
|
||||
use rustc::ty::query::TyCtxtAt;
|
||||
use rustc_data_structures::indexed_vec::IndexVec;
|
||||
@ -291,41 +291,6 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
||||
ty.is_freeze(*self.tcx, self.param_env, DUMMY_SP)
|
||||
}
|
||||
|
||||
pub(super) fn subst_and_normalize_erasing_regions<T: TypeFoldable<'tcx>>(
|
||||
&self,
|
||||
substs: T,
|
||||
) -> InterpResult<'tcx, T> {
|
||||
match self.stack.last() {
|
||||
Some(frame) => Ok(self.tcx.subst_and_normalize_erasing_regions(
|
||||
frame.instance.substs,
|
||||
self.param_env,
|
||||
&substs,
|
||||
)),
|
||||
None => if substs.needs_subst() {
|
||||
throw_inval!(TooGeneric)
|
||||
} else {
|
||||
Ok(substs)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn resolve(
|
||||
&self,
|
||||
def_id: DefId,
|
||||
substs: SubstsRef<'tcx>
|
||||
) -> InterpResult<'tcx, ty::Instance<'tcx>> {
|
||||
trace!("resolve: {:?}, {:#?}", def_id, substs);
|
||||
trace!("param_env: {:#?}", self.param_env);
|
||||
let substs = self.subst_and_normalize_erasing_regions(substs)?;
|
||||
trace!("substs: {:#?}", substs);
|
||||
ty::Instance::resolve(
|
||||
*self.tcx,
|
||||
self.param_env,
|
||||
def_id,
|
||||
substs,
|
||||
).ok_or_else(|| err_inval!(TooGeneric).into())
|
||||
}
|
||||
|
||||
pub fn load_mir(
|
||||
&self,
|
||||
instance: ty::InstanceDef<'tcx>,
|
||||
@ -349,12 +314,18 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn monomorphize<T: TypeFoldable<'tcx> + Subst<'tcx>>(
|
||||
/// Call this on things you got out of the MIR (so it is as generic as the current
|
||||
/// stack rameframe), to bring it into the proper environment for this interpreter.
|
||||
pub(super) fn subst_from_frame_and_normalize_erasing_regions<T: TypeFoldable<'tcx>>(
|
||||
&self,
|
||||
t: T,
|
||||
) -> InterpResult<'tcx, T> {
|
||||
match self.stack.last() {
|
||||
Some(frame) => Ok(self.monomorphize_with_substs(t, frame.instance.substs)?),
|
||||
Some(frame) => Ok(self.tcx.subst_and_normalize_erasing_regions(
|
||||
frame.instance.substs,
|
||||
self.param_env,
|
||||
&t,
|
||||
)),
|
||||
None => if t.needs_subst() {
|
||||
throw_inval!(TooGeneric)
|
||||
} else {
|
||||
@ -363,20 +334,21 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
||||
}
|
||||
}
|
||||
|
||||
fn monomorphize_with_substs<T: TypeFoldable<'tcx> + Subst<'tcx>>(
|
||||
/// The `substs` are assumed to already be in our interpreter "universe" (param_env).
|
||||
pub(super) fn resolve(
|
||||
&self,
|
||||
t: T,
|
||||
def_id: DefId,
|
||||
substs: SubstsRef<'tcx>
|
||||
) -> InterpResult<'tcx, T> {
|
||||
// miri doesn't care about lifetimes, and will choke on some crazy ones
|
||||
// let's simply get rid of them
|
||||
let substituted = t.subst(*self.tcx, substs);
|
||||
|
||||
if substituted.needs_subst() {
|
||||
throw_inval!(TooGeneric)
|
||||
}
|
||||
|
||||
Ok(self.tcx.normalize_erasing_regions(ty::ParamEnv::reveal_all(), substituted))
|
||||
) -> InterpResult<'tcx, ty::Instance<'tcx>> {
|
||||
trace!("resolve: {:?}, {:#?}", def_id, substs);
|
||||
trace!("param_env: {:#?}", self.param_env);
|
||||
trace!("substs: {:#?}", substs);
|
||||
ty::Instance::resolve(
|
||||
*self.tcx,
|
||||
self.param_env,
|
||||
def_id,
|
||||
substs,
|
||||
).ok_or_else(|| err_inval!(TooGeneric).into())
|
||||
}
|
||||
|
||||
pub fn layout_of_local(
|
||||
@ -391,7 +363,11 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
||||
None => {
|
||||
let layout = crate::interpret::operand::from_known_layout(layout, || {
|
||||
let local_ty = frame.body.local_decls[local].ty;
|
||||
let local_ty = self.monomorphize_with_substs(local_ty, frame.instance.substs)?;
|
||||
let local_ty = self.tcx.subst_and_normalize_erasing_regions(
|
||||
frame.instance.substs,
|
||||
self.param_env,
|
||||
&local_ty,
|
||||
);
|
||||
self.layout_of(local_ty)
|
||||
})?;
|
||||
if let Some(state) = frame.locals.get(local) {
|
||||
|
@ -540,6 +540,8 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
||||
|
||||
// Used when the miri-engine runs into a constant and for extracting information from constants
|
||||
// in patterns via the `const_eval` module
|
||||
/// The `val` and `layout` are assumed to already be in our interpreter
|
||||
/// "universe" (param_env).
|
||||
crate fn eval_const_to_op(
|
||||
&self,
|
||||
val: &'tcx ty::Const<'tcx>,
|
||||
@ -552,7 +554,6 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
||||
// Early-return cases.
|
||||
match val.val {
|
||||
ConstValue::Param(_) =>
|
||||
// FIXME(oli-obk): try to monomorphize
|
||||
throw_inval!(TooGeneric),
|
||||
ConstValue::Unevaluated(def_id, substs) => {
|
||||
let instance = self.resolve(def_id, substs)?;
|
||||
@ -565,7 +566,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
||||
}
|
||||
// Other cases need layout.
|
||||
let layout = from_known_layout(layout, || {
|
||||
self.layout_of(self.monomorphize(val.ty)?)
|
||||
self.layout_of(val.ty)
|
||||
})?;
|
||||
let op = match val.val {
|
||||
ConstValue::ByRef { alloc, offset } => {
|
||||
|
@ -640,8 +640,11 @@ where
|
||||
// their layout on return.
|
||||
PlaceTy {
|
||||
place: *return_place,
|
||||
layout: self
|
||||
.layout_of(self.monomorphize(self.frame().body.return_ty())?)?,
|
||||
layout: self.layout_of(
|
||||
self.subst_from_frame_and_normalize_erasing_regions(
|
||||
self.frame().body.return_ty()
|
||||
)?
|
||||
)?,
|
||||
}
|
||||
}
|
||||
None => throw_unsup!(InvalidNullPointerUsage),
|
||||
|
@ -254,7 +254,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
||||
}
|
||||
|
||||
NullaryOp(mir::NullOp::SizeOf, ty) => {
|
||||
let ty = self.monomorphize(ty)?;
|
||||
let ty = self.subst_from_frame_and_normalize_erasing_regions(ty)?;
|
||||
let layout = self.layout_of(ty)?;
|
||||
assert!(!layout.is_unsized(),
|
||||
"SizeOf nullary MIR operator called for unsized type");
|
||||
|
@ -77,7 +77,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
||||
for (i, method) in methods.iter().enumerate() {
|
||||
if let Some((def_id, substs)) = *method {
|
||||
// resolve for vtable: insert shims where needed
|
||||
let substs = self.subst_and_normalize_erasing_regions(substs)?;
|
||||
let substs = self.subst_from_frame_and_normalize_erasing_regions(substs)?;
|
||||
let instance = ty::Instance::resolve_for_vtable(
|
||||
*self.tcx,
|
||||
self.param_env,
|
||||
|
Loading…
Reference in New Issue
Block a user