Skip to content

Commit 6288faa

Browse files
committed
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`
1 parent 0d17f95 commit 6288faa

File tree

9 files changed

+91
-70
lines changed

9 files changed

+91
-70
lines changed

src/librustc/traits/trans/mod.rs

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
use dep_graph::{DepKind, DepTrackingMapConfig};
1717
use std::marker::PhantomData;
1818
use syntax_pos::DUMMY_SP;
19-
use hir::def_id::DefId;
2019
use infer::InferCtxt;
2120
use syntax_pos::Span;
2221
use traits::{FulfillmentContext, Obligation, ObligationCause, SelectionContext, Vtable};
@@ -88,43 +87,30 @@ pub fn trans_fulfill_obligation<'a, 'tcx>(ty: TyCtxt<'a, 'tcx, 'tcx>,
8887
}
8988

9089
impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
91-
/// Monomorphizes a type from the AST by first applying the in-scope
92-
/// substitutions and then normalizing any associated types.
93-
pub fn trans_apply_param_substs<T>(self,
94-
param_substs: &Substs<'tcx>,
95-
value: &T)
96-
-> T
97-
where T: TypeFoldable<'tcx>
98-
{
99-
debug!("apply_param_substs(param_substs={:?}, value={:?})", param_substs, value);
100-
let substituted = value.subst(self, param_substs);
101-
self.normalize_erasing_regions(ty::ParamEnv::reveal_all(), substituted)
102-
}
103-
104-
pub fn trans_apply_param_substs_env<T>(
90+
/// Monomorphizes a type from the AST by first applying the
91+
/// in-scope substitutions and then normalizing any associated
92+
/// types.
93+
pub fn subst_and_normalize_erasing_regions<T>(
10594
self,
10695
param_substs: &Substs<'tcx>,
10796
param_env: ty::ParamEnv<'tcx>,
108-
value: &T,
97+
value: &T
10998
) -> T
11099
where
111100
T: TypeFoldable<'tcx>,
112101
{
113102
debug!(
114-
"apply_param_substs_env(param_substs={:?}, value={:?}, param_env={:?})",
103+
"subst_and_normalize_erasing_regions(\
104+
param_substs={:?}, \
105+
value={:?}, \
106+
param_env={:?})",
115107
param_substs,
116108
value,
117109
param_env,
118110
);
119111
let substituted = value.subst(self, param_substs);
120112
self.normalize_erasing_regions(param_env, substituted)
121113
}
122-
123-
pub fn trans_impl_self_ty(&self, def_id: DefId, substs: &'tcx Substs<'tcx>)
124-
-> Ty<'tcx>
125-
{
126-
self.trans_apply_param_substs(substs, &self.type_of(def_id))
127-
}
128114
}
129115

130116
// Implement DepTrackingMapConfig for `trait_cache`

src/librustc/ty/instance.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,11 @@ impl<'a, 'tcx> Instance<'tcx> {
5151
-> Ty<'tcx>
5252
{
5353
let ty = tcx.type_of(self.def.def_id());
54-
tcx.trans_apply_param_substs(self.substs, &ty)
54+
tcx.subst_and_normalize_erasing_regions(
55+
self.substs,
56+
ty::ParamEnv::reveal_all(),
57+
&ty,
58+
)
5559
}
5660
}
5761

@@ -184,7 +188,11 @@ impl<'a, 'b, 'tcx> Instance<'tcx> {
184188
resolve_associated_item(tcx, &item, param_env, trait_def_id, substs)
185189
} else {
186190
let ty = tcx.type_of(def_id);
187-
let item_type = tcx.trans_apply_param_substs_env(substs, param_env, &ty);
191+
let item_type = tcx.subst_and_normalize_erasing_regions(
192+
substs,
193+
param_env,
194+
&ty,
195+
);
188196

189197
let def = match item_type.sty {
190198
ty::TyFnDef(..) if {

src/librustc_mir/interpret/eval_context.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,11 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M
249249
trace!("resolve: {:?}, {:#?}", def_id, substs);
250250
trace!("substs: {:#?}", self.substs());
251251
trace!("param_env: {:#?}", self.param_env);
252-
let substs = self.tcx.trans_apply_param_substs_env(self.substs(), self.param_env, &substs);
252+
let substs = self.tcx.subst_and_normalize_erasing_regions(
253+
self.substs(),
254+
self.param_env,
255+
&substs,
256+
);
253257
ty::Instance::resolve(
254258
*self.tcx,
255259
self.param_env,
@@ -722,7 +726,11 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M
722726
ClosureFnPointer => {
723727
match self.eval_operand(operand)?.ty.sty {
724728
ty::TyClosure(def_id, substs) => {
725-
let substs = self.tcx.trans_apply_param_substs(self.substs(), &substs);
729+
let substs = self.tcx.subst_and_normalize_erasing_regions(
730+
self.substs(),
731+
ty::ParamEnv::reveal_all(),
732+
&substs,
733+
);
726734
let instance = ty::Instance::resolve_closure(
727735
*self.tcx,
728736
def_id,

src/librustc_mir/interpret/terminator/mod.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,11 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M> {
122122
// FIXME(CTFE): forbid drop in const eval
123123
let place = self.eval_place(location)?;
124124
let ty = self.place_ty(location);
125-
let ty = self.tcx.trans_apply_param_substs(self.substs(), &ty);
125+
let ty = self.tcx.subst_and_normalize_erasing_regions(
126+
self.substs(),
127+
ty::ParamEnv::reveal_all(),
128+
&ty,
129+
);
126130
trace!("TerminatorKind::drop: {:?}, type {}", location, ty);
127131

128132
let instance = ::monomorphize::resolve_drop_in_place(*self.tcx, ty);

src/librustc_mir/monomorphize/collector.rs

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -523,11 +523,17 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirNeighborCollector<'a, 'tcx> {
523523
// have to instantiate all methods of the trait being cast to, so we
524524
// can build the appropriate vtable.
525525
mir::Rvalue::Cast(mir::CastKind::Unsize, ref operand, target_ty) => {
526-
let target_ty = self.tcx.trans_apply_param_substs(self.param_substs,
527-
&target_ty);
526+
let target_ty = self.tcx.subst_and_normalize_erasing_regions(
527+
self.param_substs,
528+
ty::ParamEnv::reveal_all(),
529+
&target_ty,
530+
);
528531
let source_ty = operand.ty(self.mir, self.tcx);
529-
let source_ty = self.tcx.trans_apply_param_substs(self.param_substs,
530-
&source_ty);
532+
let source_ty = self.tcx.subst_and_normalize_erasing_regions(
533+
self.param_substs,
534+
ty::ParamEnv::reveal_all(),
535+
&source_ty,
536+
);
531537
let (source_ty, target_ty) = find_vtable_types_for_unsizing(self.tcx,
532538
source_ty,
533539
target_ty);
@@ -543,14 +549,20 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirNeighborCollector<'a, 'tcx> {
543549
}
544550
mir::Rvalue::Cast(mir::CastKind::ReifyFnPointer, ref operand, _) => {
545551
let fn_ty = operand.ty(self.mir, self.tcx);
546-
let fn_ty = self.tcx.trans_apply_param_substs(self.param_substs,
547-
&fn_ty);
552+
let fn_ty = self.tcx.subst_and_normalize_erasing_regions(
553+
self.param_substs,
554+
ty::ParamEnv::reveal_all(),
555+
&fn_ty,
556+
);
548557
visit_fn_use(self.tcx, fn_ty, false, &mut self.output);
549558
}
550559
mir::Rvalue::Cast(mir::CastKind::ClosureFnPointer, ref operand, _) => {
551560
let source_ty = operand.ty(self.mir, self.tcx);
552-
let source_ty = self.tcx.trans_apply_param_substs(self.param_substs,
553-
&source_ty);
561+
let source_ty = self.tcx.subst_and_normalize_erasing_regions(
562+
self.param_substs,
563+
ty::ParamEnv::reveal_all(),
564+
&source_ty,
565+
);
554566
match source_ty.sty {
555567
ty::TyClosure(def_id, substs) => {
556568
let instance = monomorphize::resolve_closure(
@@ -595,14 +607,22 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirNeighborCollector<'a, 'tcx> {
595607
match *kind {
596608
mir::TerminatorKind::Call { ref func, .. } => {
597609
let callee_ty = func.ty(self.mir, tcx);
598-
let callee_ty = tcx.trans_apply_param_substs(self.param_substs, &callee_ty);
610+
let callee_ty = tcx.subst_and_normalize_erasing_regions(
611+
self.param_substs,
612+
ty::ParamEnv::reveal_all(),
613+
&callee_ty,
614+
);
599615
visit_fn_use(self.tcx, callee_ty, true, &mut self.output);
600616
}
601617
mir::TerminatorKind::Drop { ref location, .. } |
602618
mir::TerminatorKind::DropAndReplace { ref location, .. } => {
603619
let ty = location.ty(self.mir, self.tcx)
604620
.to_ty(self.tcx);
605-
let ty = tcx.trans_apply_param_substs(self.param_substs, &ty);
621+
let ty = tcx.subst_and_normalize_erasing_regions(
622+
self.param_substs,
623+
ty::ParamEnv::reveal_all(),
624+
&ty,
625+
);
606626
visit_drop_use(self.tcx, ty, true, self.output);
607627
}
608628
mir::TerminatorKind::Goto { .. } |
@@ -1155,8 +1175,11 @@ fn collect_const<'a, 'tcx>(
11551175
let val = match constant.val {
11561176
ConstVal::Unevaluated(def_id, substs) => {
11571177
let param_env = ty::ParamEnv::reveal_all();
1158-
let substs = tcx.trans_apply_param_substs(param_substs,
1159-
&substs);
1178+
let substs = tcx.subst_and_normalize_erasing_regions(
1179+
param_substs,
1180+
param_env,
1181+
&substs,
1182+
);
11601183
let instance = ty::Instance::resolve(tcx,
11611184
param_env,
11621185
def_id,

src/librustc_mir/monomorphize/partitioning.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -645,7 +645,11 @@ fn characteristic_def_id_of_trans_item<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
645645
if let Some(impl_def_id) = tcx.impl_of_method(def_id) {
646646
// This is a method within an inherent impl, find out what the
647647
// self-type is:
648-
let impl_self_ty = tcx.trans_impl_self_ty(impl_def_id, instance.substs);
648+
let impl_self_ty = tcx.subst_and_normalize_erasing_regions(
649+
instance.substs,
650+
ty::ParamEnv::reveal_all(),
651+
&tcx.type_of(impl_def_id),
652+
);
649653
if let Some(def_id) = characteristic_def_id_of_type(impl_self_ty) {
650654
return Some(def_id);
651655
}

src/librustc_mir/transform/inline.rs

Lines changed: 7 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use rustc_data_structures::indexed_vec::{Idx, IndexVec};
1919

2020
use rustc::mir::*;
2121
use rustc::mir::visit::*;
22-
use rustc::ty::{self, Instance, Ty, TyCtxt, TypeFoldable};
22+
use rustc::ty::{self, Instance, Ty, TyCtxt};
2323
use rustc::ty::subst::{Subst,Substs};
2424

2525
use std::collections::VecDeque;
@@ -129,8 +129,12 @@ impl<'a, 'tcx> Inliner<'a, 'tcx> {
129129
let callee_mir = match ty::queries::optimized_mir::try_get(self.tcx,
130130
callsite.location.span,
131131
callsite.callee) {
132-
Ok(ref callee_mir) if self.should_inline(callsite, callee_mir) => {
133-
subst_and_normalize(callee_mir, self.tcx, &callsite.substs, param_env)
132+
Ok(callee_mir) if self.should_inline(callsite, callee_mir) => {
133+
self.tcx.subst_and_normalize_erasing_regions(
134+
&callsite.substs,
135+
param_env,
136+
callee_mir,
137+
)
134138
}
135139
Ok(_) => continue,
136140

@@ -664,30 +668,6 @@ fn type_size_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
664668
tcx.layout_of(param_env.and(ty)).ok().map(|layout| layout.size.bytes())
665669
}
666670

667-
fn subst_and_normalize<'a, 'tcx: 'a>(
668-
mir: &Mir<'tcx>,
669-
tcx: TyCtxt<'a, 'tcx, 'tcx>,
670-
substs: &'tcx ty::subst::Substs<'tcx>,
671-
param_env: ty::ParamEnv<'tcx>,
672-
) -> Mir<'tcx> {
673-
struct Folder<'a, 'tcx: 'a> {
674-
tcx: TyCtxt<'a, 'tcx, 'tcx>,
675-
param_env: ty::ParamEnv<'tcx>,
676-
substs: &'tcx ty::subst::Substs<'tcx>,
677-
}
678-
impl<'a, 'tcx: 'a> ty::fold::TypeFolder<'tcx, 'tcx> for Folder<'a, 'tcx> {
679-
fn tcx<'b>(&'b self) -> TyCtxt<'b, 'tcx, 'tcx> {
680-
self.tcx
681-
}
682-
683-
fn fold_ty(&mut self, t: Ty<'tcx>) -> Ty<'tcx> {
684-
self.tcx.trans_apply_param_substs_env(&self.substs, self.param_env, &t)
685-
}
686-
}
687-
let mut f = Folder { tcx, param_env, substs };
688-
mir.fold_with(&mut f)
689-
}
690-
691671
/**
692672
* Integrator.
693673
*

src/librustc_trans/debuginfo/mod.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,11 @@ pub fn create_function_debug_context<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
429429
let self_type = cx.tcx.impl_of_method(instance.def_id()).and_then(|impl_def_id| {
430430
// If the method does *not* belong to a trait, proceed
431431
if cx.tcx.trait_id_of_impl(impl_def_id).is_none() {
432-
let impl_self_ty = cx.tcx.trans_impl_self_ty(impl_def_id, instance.substs);
432+
let impl_self_ty = cx.tcx.subst_and_normalize_erasing_regions(
433+
instance.substs,
434+
ty::ParamEnv::reveal_all(),
435+
&cx.tcx.type_of(impl_def_id),
436+
);
433437

434438
// Only "class" methods are generally understood by LLVM,
435439
// so avoid methods on other types (e.g. `<*mut T>::null`).

src/librustc_trans/mir/mod.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,11 @@ impl<'a, 'tcx> FunctionCx<'a, 'tcx> {
109109
pub fn monomorphize<T>(&self, value: &T) -> T
110110
where T: TypeFoldable<'tcx>
111111
{
112-
self.cx.tcx.trans_apply_param_substs(self.param_substs, value)
112+
self.cx.tcx.subst_and_normalize_erasing_regions(
113+
self.param_substs,
114+
ty::ParamEnv::reveal_all(),
115+
value,
116+
)
113117
}
114118

115119
pub fn set_debug_loc(&mut self, bx: &Builder, source_info: mir::SourceInfo) {

0 commit comments

Comments
 (0)