trans_apply_param_substs
=> subst_and_normalize_erasing_regions
Consolidate `trans_apply_param_substs` and `trans_apply_param_substs_env`. Also remove `trans_impl_self_ty`
This commit is contained in:
parent
0d17f95465
commit
6288faa3a3
@ -16,7 +16,6 @@
|
||||
use dep_graph::{DepKind, DepTrackingMapConfig};
|
||||
use std::marker::PhantomData;
|
||||
use syntax_pos::DUMMY_SP;
|
||||
use hir::def_id::DefId;
|
||||
use infer::InferCtxt;
|
||||
use syntax_pos::Span;
|
||||
use traits::{FulfillmentContext, Obligation, ObligationCause, SelectionContext, Vtable};
|
||||
@ -88,30 +87,23 @@ pub fn trans_fulfill_obligation<'a, 'tcx>(ty: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
|
||||
/// Monomorphizes a type from the AST by first applying the in-scope
|
||||
/// substitutions and then normalizing any associated types.
|
||||
pub fn trans_apply_param_substs<T>(self,
|
||||
param_substs: &Substs<'tcx>,
|
||||
value: &T)
|
||||
-> T
|
||||
where T: TypeFoldable<'tcx>
|
||||
{
|
||||
debug!("apply_param_substs(param_substs={:?}, value={:?})", param_substs, value);
|
||||
let substituted = value.subst(self, param_substs);
|
||||
self.normalize_erasing_regions(ty::ParamEnv::reveal_all(), substituted)
|
||||
}
|
||||
|
||||
pub fn trans_apply_param_substs_env<T>(
|
||||
/// Monomorphizes a type from the AST by first applying the
|
||||
/// in-scope substitutions and then normalizing any associated
|
||||
/// types.
|
||||
pub fn subst_and_normalize_erasing_regions<T>(
|
||||
self,
|
||||
param_substs: &Substs<'tcx>,
|
||||
param_env: ty::ParamEnv<'tcx>,
|
||||
value: &T,
|
||||
value: &T
|
||||
) -> T
|
||||
where
|
||||
T: TypeFoldable<'tcx>,
|
||||
{
|
||||
debug!(
|
||||
"apply_param_substs_env(param_substs={:?}, value={:?}, param_env={:?})",
|
||||
"subst_and_normalize_erasing_regions(\
|
||||
param_substs={:?}, \
|
||||
value={:?}, \
|
||||
param_env={:?})",
|
||||
param_substs,
|
||||
value,
|
||||
param_env,
|
||||
@ -119,12 +111,6 @@ impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
|
||||
let substituted = value.subst(self, param_substs);
|
||||
self.normalize_erasing_regions(param_env, substituted)
|
||||
}
|
||||
|
||||
pub fn trans_impl_self_ty(&self, def_id: DefId, substs: &'tcx Substs<'tcx>)
|
||||
-> Ty<'tcx>
|
||||
{
|
||||
self.trans_apply_param_substs(substs, &self.type_of(def_id))
|
||||
}
|
||||
}
|
||||
|
||||
// Implement DepTrackingMapConfig for `trait_cache`
|
||||
|
@ -51,7 +51,11 @@ impl<'a, 'tcx> Instance<'tcx> {
|
||||
-> Ty<'tcx>
|
||||
{
|
||||
let ty = tcx.type_of(self.def.def_id());
|
||||
tcx.trans_apply_param_substs(self.substs, &ty)
|
||||
tcx.subst_and_normalize_erasing_regions(
|
||||
self.substs,
|
||||
ty::ParamEnv::reveal_all(),
|
||||
&ty,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@ -184,7 +188,11 @@ impl<'a, 'b, 'tcx> Instance<'tcx> {
|
||||
resolve_associated_item(tcx, &item, param_env, trait_def_id, substs)
|
||||
} else {
|
||||
let ty = tcx.type_of(def_id);
|
||||
let item_type = tcx.trans_apply_param_substs_env(substs, param_env, &ty);
|
||||
let item_type = tcx.subst_and_normalize_erasing_regions(
|
||||
substs,
|
||||
param_env,
|
||||
&ty,
|
||||
);
|
||||
|
||||
let def = match item_type.sty {
|
||||
ty::TyFnDef(..) if {
|
||||
|
@ -249,7 +249,11 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M
|
||||
trace!("resolve: {:?}, {:#?}", def_id, substs);
|
||||
trace!("substs: {:#?}", self.substs());
|
||||
trace!("param_env: {:#?}", self.param_env);
|
||||
let substs = self.tcx.trans_apply_param_substs_env(self.substs(), self.param_env, &substs);
|
||||
let substs = self.tcx.subst_and_normalize_erasing_regions(
|
||||
self.substs(),
|
||||
self.param_env,
|
||||
&substs,
|
||||
);
|
||||
ty::Instance::resolve(
|
||||
*self.tcx,
|
||||
self.param_env,
|
||||
@ -722,7 +726,11 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M
|
||||
ClosureFnPointer => {
|
||||
match self.eval_operand(operand)?.ty.sty {
|
||||
ty::TyClosure(def_id, substs) => {
|
||||
let substs = self.tcx.trans_apply_param_substs(self.substs(), &substs);
|
||||
let substs = self.tcx.subst_and_normalize_erasing_regions(
|
||||
self.substs(),
|
||||
ty::ParamEnv::reveal_all(),
|
||||
&substs,
|
||||
);
|
||||
let instance = ty::Instance::resolve_closure(
|
||||
*self.tcx,
|
||||
def_id,
|
||||
|
@ -122,7 +122,11 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M> {
|
||||
// FIXME(CTFE): forbid drop in const eval
|
||||
let place = self.eval_place(location)?;
|
||||
let ty = self.place_ty(location);
|
||||
let ty = self.tcx.trans_apply_param_substs(self.substs(), &ty);
|
||||
let ty = self.tcx.subst_and_normalize_erasing_regions(
|
||||
self.substs(),
|
||||
ty::ParamEnv::reveal_all(),
|
||||
&ty,
|
||||
);
|
||||
trace!("TerminatorKind::drop: {:?}, type {}", location, ty);
|
||||
|
||||
let instance = ::monomorphize::resolve_drop_in_place(*self.tcx, ty);
|
||||
|
@ -523,11 +523,17 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirNeighborCollector<'a, 'tcx> {
|
||||
// have to instantiate all methods of the trait being cast to, so we
|
||||
// can build the appropriate vtable.
|
||||
mir::Rvalue::Cast(mir::CastKind::Unsize, ref operand, target_ty) => {
|
||||
let target_ty = self.tcx.trans_apply_param_substs(self.param_substs,
|
||||
&target_ty);
|
||||
let target_ty = self.tcx.subst_and_normalize_erasing_regions(
|
||||
self.param_substs,
|
||||
ty::ParamEnv::reveal_all(),
|
||||
&target_ty,
|
||||
);
|
||||
let source_ty = operand.ty(self.mir, self.tcx);
|
||||
let source_ty = self.tcx.trans_apply_param_substs(self.param_substs,
|
||||
&source_ty);
|
||||
let source_ty = self.tcx.subst_and_normalize_erasing_regions(
|
||||
self.param_substs,
|
||||
ty::ParamEnv::reveal_all(),
|
||||
&source_ty,
|
||||
);
|
||||
let (source_ty, target_ty) = find_vtable_types_for_unsizing(self.tcx,
|
||||
source_ty,
|
||||
target_ty);
|
||||
@ -543,14 +549,20 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirNeighborCollector<'a, 'tcx> {
|
||||
}
|
||||
mir::Rvalue::Cast(mir::CastKind::ReifyFnPointer, ref operand, _) => {
|
||||
let fn_ty = operand.ty(self.mir, self.tcx);
|
||||
let fn_ty = self.tcx.trans_apply_param_substs(self.param_substs,
|
||||
&fn_ty);
|
||||
let fn_ty = self.tcx.subst_and_normalize_erasing_regions(
|
||||
self.param_substs,
|
||||
ty::ParamEnv::reveal_all(),
|
||||
&fn_ty,
|
||||
);
|
||||
visit_fn_use(self.tcx, fn_ty, false, &mut self.output);
|
||||
}
|
||||
mir::Rvalue::Cast(mir::CastKind::ClosureFnPointer, ref operand, _) => {
|
||||
let source_ty = operand.ty(self.mir, self.tcx);
|
||||
let source_ty = self.tcx.trans_apply_param_substs(self.param_substs,
|
||||
&source_ty);
|
||||
let source_ty = self.tcx.subst_and_normalize_erasing_regions(
|
||||
self.param_substs,
|
||||
ty::ParamEnv::reveal_all(),
|
||||
&source_ty,
|
||||
);
|
||||
match source_ty.sty {
|
||||
ty::TyClosure(def_id, substs) => {
|
||||
let instance = monomorphize::resolve_closure(
|
||||
@ -595,14 +607,22 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirNeighborCollector<'a, 'tcx> {
|
||||
match *kind {
|
||||
mir::TerminatorKind::Call { ref func, .. } => {
|
||||
let callee_ty = func.ty(self.mir, tcx);
|
||||
let callee_ty = tcx.trans_apply_param_substs(self.param_substs, &callee_ty);
|
||||
let callee_ty = tcx.subst_and_normalize_erasing_regions(
|
||||
self.param_substs,
|
||||
ty::ParamEnv::reveal_all(),
|
||||
&callee_ty,
|
||||
);
|
||||
visit_fn_use(self.tcx, callee_ty, true, &mut self.output);
|
||||
}
|
||||
mir::TerminatorKind::Drop { ref location, .. } |
|
||||
mir::TerminatorKind::DropAndReplace { ref location, .. } => {
|
||||
let ty = location.ty(self.mir, self.tcx)
|
||||
.to_ty(self.tcx);
|
||||
let ty = tcx.trans_apply_param_substs(self.param_substs, &ty);
|
||||
let ty = tcx.subst_and_normalize_erasing_regions(
|
||||
self.param_substs,
|
||||
ty::ParamEnv::reveal_all(),
|
||||
&ty,
|
||||
);
|
||||
visit_drop_use(self.tcx, ty, true, self.output);
|
||||
}
|
||||
mir::TerminatorKind::Goto { .. } |
|
||||
@ -1155,8 +1175,11 @@ fn collect_const<'a, 'tcx>(
|
||||
let val = match constant.val {
|
||||
ConstVal::Unevaluated(def_id, substs) => {
|
||||
let param_env = ty::ParamEnv::reveal_all();
|
||||
let substs = tcx.trans_apply_param_substs(param_substs,
|
||||
&substs);
|
||||
let substs = tcx.subst_and_normalize_erasing_regions(
|
||||
param_substs,
|
||||
param_env,
|
||||
&substs,
|
||||
);
|
||||
let instance = ty::Instance::resolve(tcx,
|
||||
param_env,
|
||||
def_id,
|
||||
|
@ -645,7 +645,11 @@ fn characteristic_def_id_of_trans_item<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
if let Some(impl_def_id) = tcx.impl_of_method(def_id) {
|
||||
// This is a method within an inherent impl, find out what the
|
||||
// self-type is:
|
||||
let impl_self_ty = tcx.trans_impl_self_ty(impl_def_id, instance.substs);
|
||||
let impl_self_ty = tcx.subst_and_normalize_erasing_regions(
|
||||
instance.substs,
|
||||
ty::ParamEnv::reveal_all(),
|
||||
&tcx.type_of(impl_def_id),
|
||||
);
|
||||
if let Some(def_id) = characteristic_def_id_of_type(impl_self_ty) {
|
||||
return Some(def_id);
|
||||
}
|
||||
|
@ -19,7 +19,7 @@ use rustc_data_structures::indexed_vec::{Idx, IndexVec};
|
||||
|
||||
use rustc::mir::*;
|
||||
use rustc::mir::visit::*;
|
||||
use rustc::ty::{self, Instance, Ty, TyCtxt, TypeFoldable};
|
||||
use rustc::ty::{self, Instance, Ty, TyCtxt};
|
||||
use rustc::ty::subst::{Subst,Substs};
|
||||
|
||||
use std::collections::VecDeque;
|
||||
@ -129,8 +129,12 @@ impl<'a, 'tcx> Inliner<'a, 'tcx> {
|
||||
let callee_mir = match ty::queries::optimized_mir::try_get(self.tcx,
|
||||
callsite.location.span,
|
||||
callsite.callee) {
|
||||
Ok(ref callee_mir) if self.should_inline(callsite, callee_mir) => {
|
||||
subst_and_normalize(callee_mir, self.tcx, &callsite.substs, param_env)
|
||||
Ok(callee_mir) if self.should_inline(callsite, callee_mir) => {
|
||||
self.tcx.subst_and_normalize_erasing_regions(
|
||||
&callsite.substs,
|
||||
param_env,
|
||||
callee_mir,
|
||||
)
|
||||
}
|
||||
Ok(_) => continue,
|
||||
|
||||
@ -664,30 +668,6 @@ fn type_size_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
tcx.layout_of(param_env.and(ty)).ok().map(|layout| layout.size.bytes())
|
||||
}
|
||||
|
||||
fn subst_and_normalize<'a, 'tcx: 'a>(
|
||||
mir: &Mir<'tcx>,
|
||||
tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
substs: &'tcx ty::subst::Substs<'tcx>,
|
||||
param_env: ty::ParamEnv<'tcx>,
|
||||
) -> Mir<'tcx> {
|
||||
struct Folder<'a, 'tcx: 'a> {
|
||||
tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
param_env: ty::ParamEnv<'tcx>,
|
||||
substs: &'tcx ty::subst::Substs<'tcx>,
|
||||
}
|
||||
impl<'a, 'tcx: 'a> ty::fold::TypeFolder<'tcx, 'tcx> for Folder<'a, 'tcx> {
|
||||
fn tcx<'b>(&'b self) -> TyCtxt<'b, 'tcx, 'tcx> {
|
||||
self.tcx
|
||||
}
|
||||
|
||||
fn fold_ty(&mut self, t: Ty<'tcx>) -> Ty<'tcx> {
|
||||
self.tcx.trans_apply_param_substs_env(&self.substs, self.param_env, &t)
|
||||
}
|
||||
}
|
||||
let mut f = Folder { tcx, param_env, substs };
|
||||
mir.fold_with(&mut f)
|
||||
}
|
||||
|
||||
/**
|
||||
* Integrator.
|
||||
*
|
||||
|
@ -429,7 +429,11 @@ pub fn create_function_debug_context<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
|
||||
let self_type = cx.tcx.impl_of_method(instance.def_id()).and_then(|impl_def_id| {
|
||||
// If the method does *not* belong to a trait, proceed
|
||||
if cx.tcx.trait_id_of_impl(impl_def_id).is_none() {
|
||||
let impl_self_ty = cx.tcx.trans_impl_self_ty(impl_def_id, instance.substs);
|
||||
let impl_self_ty = cx.tcx.subst_and_normalize_erasing_regions(
|
||||
instance.substs,
|
||||
ty::ParamEnv::reveal_all(),
|
||||
&cx.tcx.type_of(impl_def_id),
|
||||
);
|
||||
|
||||
// Only "class" methods are generally understood by LLVM,
|
||||
// so avoid methods on other types (e.g. `<*mut T>::null`).
|
||||
|
@ -109,7 +109,11 @@ impl<'a, 'tcx> FunctionCx<'a, 'tcx> {
|
||||
pub fn monomorphize<T>(&self, value: &T) -> T
|
||||
where T: TypeFoldable<'tcx>
|
||||
{
|
||||
self.cx.tcx.trans_apply_param_substs(self.param_substs, value)
|
||||
self.cx.tcx.subst_and_normalize_erasing_regions(
|
||||
self.param_substs,
|
||||
ty::ParamEnv::reveal_all(),
|
||||
value,
|
||||
)
|
||||
}
|
||||
|
||||
pub fn set_debug_loc(&mut self, bx: &Builder, source_info: mir::SourceInfo) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user