Skip to content

Commit 081b29c

Browse files
committed
stop using monomorphize::resolve()
1 parent 8a5800e commit 081b29c

File tree

7 files changed

+49
-128
lines changed

7 files changed

+49
-128
lines changed

src/librustc/ty/instance.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,10 @@ impl<'a, 'b, 'tcx> Instance<'tcx> {
118118

119119
/// The point where linking happens. Resolve a (def_id, substs)
120120
/// pair to an instance.
121-
pub fn resolve(tcx: TyCtxt<'a, 'tcx, 'tcx>, param_env: ty::ParamEnv<'tcx>, def_id: DefId, substs: &'tcx Substs<'tcx>) -> Option<Instance<'tcx>> {
121+
pub fn resolve(tcx: TyCtxt<'a, 'tcx, 'tcx>,
122+
param_env: ty::ParamEnv<'tcx>,
123+
def_id: DefId,
124+
substs: &'tcx Substs<'tcx>) -> Option<Instance<'tcx>> {
122125
debug!("resolve(def_id={:?}, substs={:?})", def_id, substs);
123126
let result = if let Some(trait_def_id) = tcx.trait_of_item(def_id) {
124127
debug!(" => associated item, attempting to find impl");
@@ -154,7 +157,7 @@ impl<'a, 'b, 'tcx> Instance<'tcx> {
154157
}
155158
}
156159
};
157-
Some(Instance {
160+
Some(Instance {
158161
def: def,
159162
substs: substs
160163
})

src/librustc_mir/transform/inline.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,10 @@ impl<'a, 'tcx> Inliner<'a, 'tcx> {
9191
let caller_def_id = self.tcx.hir.local_def_id(caller_id);
9292
let param_env = self.tcx.param_env(caller_def_id);
9393

94-
if let Some(instance) = Instance::resolve(self.tcx, param_env, callee_def_id, substs) {
94+
if let Some(instance) = Instance::resolve(self.tcx,
95+
param_env,
96+
callee_def_id,
97+
substs) {
9598
callsites.push_back(CallSite {
9699
callee: instance.def_id(),
97100
substs: instance.substs,

src/librustc_trans/callee.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@ use common::{self, CrateContext};
1919
use consts;
2020
use declare;
2121
use llvm::{self, ValueRef};
22-
use monomorphize::{self, Instance};
22+
use monomorphize::Instance;
2323
use rustc::hir::def_id::DefId;
24-
use rustc::ty::TypeFoldable;
24+
use rustc::ty::{self, TypeFoldable};
25+
use rustc::traits;
2526
use rustc::ty::subst::Substs;
2627
use type_of;
2728

@@ -179,5 +180,8 @@ pub fn resolve_and_get_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
179180
substs: &'tcx Substs<'tcx>)
180181
-> ValueRef
181182
{
182-
get_fn(ccx, monomorphize::resolve(ccx.tcx(), def_id, substs))
183+
get_fn(ccx, ty::Instance::resolve(ccx.tcx(),
184+
ty::ParamEnv::empty(traits::Reveal::All),
185+
def_id,
186+
substs).unwrap())
183187
}

src/librustc_trans/collector.rs

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,10 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirNeighborCollector<'a, 'tcx> {
566566
if let ConstVal::Unevaluated(def_id, substs) = constant.val {
567567
let substs = self.tcx.trans_apply_param_substs(self.param_substs,
568568
&substs);
569-
let instance = monomorphize::resolve(self.tcx, def_id, substs);
569+
let instance = ty::Instance::resolve(self.tcx,
570+
ty::ParamEnv::empty(traits::Reveal::All),
571+
def_id,
572+
substs).unwrap();
570573
collect_neighbours(self.tcx, instance, true, self.output);
571574
}
572575

@@ -587,7 +590,11 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirNeighborCollector<'a, 'tcx> {
587590

588591
let constness = match (self.const_context, &callee_ty.sty) {
589592
(true, &ty::TyFnDef(def_id, substs)) if self.tcx.is_const_fn(def_id) => {
590-
let instance = monomorphize::resolve(self.tcx, def_id, substs);
593+
let instance =
594+
ty::Instance::resolve(self.tcx,
595+
ty::ParamEnv::empty(traits::Reveal::All),
596+
def_id,
597+
substs).unwrap();
591598
Some(instance)
592599
}
593600
_ => None
@@ -657,7 +664,10 @@ fn visit_fn_use<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
657664
output: &mut Vec<TransItem<'tcx>>)
658665
{
659666
if let ty::TyFnDef(def_id, substs) = ty.sty {
660-
let instance = monomorphize::resolve(tcx, def_id, substs);
667+
let instance = ty::Instance::resolve(tcx,
668+
ty::ParamEnv::empty(traits::Reveal::All),
669+
def_id,
670+
substs).unwrap();
661671
visit_instance_use(tcx, instance, is_direct_call, output);
662672
}
663673
}
@@ -845,7 +855,11 @@ fn create_trans_items_for_vtable_methods<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
845855
// Walk all methods of the trait, including those of its supertraits
846856
let methods = traits::get_vtable_methods(tcx, poly_trait_ref);
847857
let methods = methods.filter_map(|method| method)
848-
.map(|(def_id, substs)| monomorphize::resolve(tcx, def_id, substs))
858+
.map(|(def_id, substs)| ty::Instance::resolve(
859+
tcx,
860+
ty::ParamEnv::empty(traits::Reveal::All),
861+
def_id,
862+
substs).unwrap())
849863
.filter(|&instance| should_trans_locally(tcx, &instance))
850864
.map(|instance| create_fn_trans_item(instance));
851865
output.extend(methods);
@@ -1000,8 +1014,10 @@ fn create_trans_items_for_default_impls<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
10001014
continue;
10011015
}
10021016

1003-
let instance =
1004-
monomorphize::resolve(tcx, method.def_id, callee_substs);
1017+
let instance = ty::Instance::resolve(tcx,
1018+
ty::ParamEnv::empty(traits::Reveal::All),
1019+
method.def_id,
1020+
callee_substs).unwrap();
10051021

10061022
let trans_item = create_fn_trans_item(instance);
10071023
if trans_item.is_instantiable(tcx) && should_trans_locally(tcx, &instance) {

src/librustc_trans/mir/block.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use rustc::middle::lang_items;
1313
use rustc::middle::const_val::{ConstEvalErr, ConstInt, ErrKind};
1414
use rustc::ty::{self, Ty, TypeFoldable};
1515
use rustc::ty::layout::{self, LayoutTyper};
16+
use rustc::traits;
1617
use rustc::mir;
1718
use abi::{Abi, FnType, ArgType};
1819
use adt;
@@ -429,7 +430,10 @@ impl<'a, 'tcx> MirContext<'a, 'tcx> {
429430

430431
let (instance, mut llfn) = match callee.ty.sty {
431432
ty::TyFnDef(def_id, substs) => {
432-
(Some(monomorphize::resolve(bcx.ccx.tcx(), def_id, substs)),
433+
(Some(ty::Instance::resolve(bcx.ccx.tcx(),
434+
ty::ParamEnv::empty(traits::Reveal::All),
435+
def_id,
436+
substs).unwrap()),
433437
None)
434438
}
435439
ty::TyFnPtr(_) => {

src/librustc_trans/mir/constant.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use rustc_const_math::ConstInt::*;
1414
use rustc_const_math::{ConstInt, ConstMathErr};
1515
use rustc::hir::def_id::DefId;
1616
use rustc::infer::TransNormalize;
17+
use rustc::traits;
1718
use rustc::mir;
1819
use rustc::mir::tcx::LvalueTy;
1920
use rustc::ty::{self, Ty, TyCtxt, TypeFoldable};
@@ -30,7 +31,6 @@ use common::{C_array, C_bool, C_bytes, C_int, C_uint, C_big_integral, C_u32, C_u
3031
use common::{C_null, C_struct, C_str_slice, C_undef, C_usize, C_vector, is_undef};
3132
use common::const_to_opt_u128;
3233
use consts;
33-
use monomorphize;
3434
use type_of;
3535
use type_::Type;
3636
use value::Value;
@@ -261,7 +261,10 @@ impl<'a, 'tcx> MirConstContext<'a, 'tcx> {
261261
substs: &'tcx Substs<'tcx>,
262262
args: IndexVec<mir::Local, Result<Const<'tcx>, ConstEvalErr<'tcx>>>)
263263
-> Result<Const<'tcx>, ConstEvalErr<'tcx>> {
264-
let instance = monomorphize::resolve(ccx.tcx(), def_id, substs);
264+
let instance = ty::Instance::resolve(ccx.tcx(),
265+
ty::ParamEnv::empty(traits::Reveal::All),
266+
def_id,
267+
substs).unwrap();
265268
let mir = ccx.tcx().instance_mir(instance.def);
266269
MirConstContext::new(ccx, &mir, instance.substs, args).trans()
267270
}

src/librustc_trans/monomorphize.rs

Lines changed: 1 addition & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
use abi::Abi;
12-
use common::*;
13-
1411
use rustc::hir::def_id::DefId;
1512
use rustc::middle::lang_items::DropInPlaceFnLangItem;
1613
use rustc::traits;
@@ -99,123 +96,14 @@ pub fn resolve_closure<'a, 'tcx> (
9996
}
10097
}
10198

102-
fn resolve_associated_item<'a, 'tcx>(
103-
tcx: TyCtxt<'a, 'tcx, 'tcx>,
104-
trait_item: &ty::AssociatedItem,
105-
trait_id: DefId,
106-
rcvr_substs: &'tcx Substs<'tcx>
107-
) -> Instance<'tcx> {
108-
let def_id = trait_item.def_id;
109-
debug!("resolve_associated_item(trait_item={:?}, \
110-
trait_id={:?}, \
111-
rcvr_substs={:?})",
112-
def_id, trait_id, rcvr_substs);
113-
114-
let trait_ref = ty::TraitRef::from_method(tcx, trait_id, rcvr_substs);
115-
let vtbl = tcx.trans_fulfill_obligation(
116-
DUMMY_SP, ty::ParamEnv::empty(traits::Reveal::All), ty::Binder(trait_ref));
117-
118-
// Now that we know which impl is being used, we can dispatch to
119-
// the actual function:
120-
match vtbl {
121-
traits::VtableImpl(impl_data) => {
122-
let (def_id, substs) = traits::find_associated_item(
123-
tcx, trait_item, rcvr_substs, &impl_data);
124-
let substs = tcx.erase_regions(&substs);
125-
ty::Instance::new(def_id, substs)
126-
}
127-
traits::VtableGenerator(closure_data) => {
128-
Instance {
129-
def: ty::InstanceDef::Item(closure_data.closure_def_id),
130-
substs: closure_data.substs.substs
131-
}
132-
}
133-
traits::VtableClosure(closure_data) => {
134-
let trait_closure_kind = tcx.lang_items().fn_trait_kind(trait_id).unwrap();
135-
resolve_closure(tcx, closure_data.closure_def_id, closure_data.substs,
136-
trait_closure_kind)
137-
}
138-
traits::VtableFnPointer(ref data) => {
139-
Instance {
140-
def: ty::InstanceDef::FnPtrShim(trait_item.def_id, data.fn_ty),
141-
substs: rcvr_substs
142-
}
143-
}
144-
traits::VtableObject(ref data) => {
145-
let index = tcx.get_vtable_index_of_object_method(data, def_id);
146-
Instance {
147-
def: ty::InstanceDef::Virtual(def_id, index),
148-
substs: rcvr_substs
149-
}
150-
}
151-
traits::VtableBuiltin(..) if Some(trait_id) == tcx.lang_items().clone_trait() => {
152-
Instance {
153-
def: ty::InstanceDef::CloneShim(def_id, trait_ref.self_ty()),
154-
substs: rcvr_substs
155-
}
156-
}
157-
_ => {
158-
bug!("static call to invalid vtable: {:?}", vtbl)
159-
}
160-
}
161-
}
162-
163-
/// The point where linking happens. Resolve a (def_id, substs)
164-
/// pair to an instance.
165-
pub fn resolve<'a, 'tcx>(
166-
tcx: TyCtxt<'a, 'tcx, 'tcx>,
167-
def_id: DefId,
168-
substs: &'tcx Substs<'tcx>
169-
) -> Instance<'tcx> {
170-
debug!("resolve(def_id={:?}, substs={:?})",
171-
def_id, substs);
172-
let result = if let Some(trait_def_id) = tcx.trait_of_item(def_id) {
173-
debug!(" => associated item, attempting to find impl");
174-
let item = tcx.associated_item(def_id);
175-
resolve_associated_item(tcx, &item, trait_def_id, substs)
176-
} else {
177-
let item_type = def_ty(tcx, def_id, substs);
178-
let def = match item_type.sty {
179-
ty::TyFnDef(..) if {
180-
let f = item_type.fn_sig(tcx);
181-
f.abi() == Abi::RustIntrinsic ||
182-
f.abi() == Abi::PlatformIntrinsic
183-
} =>
184-
{
185-
debug!(" => intrinsic");
186-
ty::InstanceDef::Intrinsic(def_id)
187-
}
188-
_ => {
189-
if Some(def_id) == tcx.lang_items().drop_in_place_fn() {
190-
let ty = substs.type_at(0);
191-
if type_needs_drop(tcx, ty) {
192-
debug!(" => nontrivial drop glue");
193-
ty::InstanceDef::DropGlue(def_id, Some(ty))
194-
} else {
195-
debug!(" => trivial drop glue");
196-
ty::InstanceDef::DropGlue(def_id, None)
197-
}
198-
} else {
199-
debug!(" => free item");
200-
ty::InstanceDef::Item(def_id)
201-
}
202-
}
203-
};
204-
Instance { def, substs }
205-
};
206-
debug!("resolve(def_id={:?}, substs={:?}) = {}",
207-
def_id, substs, result);
208-
result
209-
}
210-
21199
pub fn resolve_drop_in_place<'a, 'tcx>(
212100
tcx: TyCtxt<'a, 'tcx, 'tcx>,
213101
ty: Ty<'tcx>)
214102
-> ty::Instance<'tcx>
215103
{
216104
let def_id = tcx.require_lang_item(DropInPlaceFnLangItem);
217105
let substs = tcx.intern_substs(&[Kind::from(ty)]);
218-
resolve(tcx, def_id, substs)
106+
Instance::resolve(tcx, ty::ParamEnv::empty(traits::Reveal::All), def_id, substs).unwrap()
219107
}
220108

221109
pub fn custom_coerce_unsize_info<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,

0 commit comments

Comments
 (0)