1
Fork 0

rustc_trans: Refactor collection to use tcx

This commit refactors the `collect_crate_translation_items` function to only
require the `TyCtxt` instead of a `SharedCrateContext` in preparation for
query-ifying this portion of trans.
This commit is contained in:
Alex Crichton 2017-09-12 08:28:17 -07:00
parent 1cdd68922d
commit c72240acf7
17 changed files with 166 additions and 155 deletions

View file

@ -612,7 +612,7 @@ pub struct FnType<'tcx> {
impl<'a, 'tcx> FnType<'tcx> { impl<'a, 'tcx> FnType<'tcx> {
pub fn of_instance(ccx: &CrateContext<'a, 'tcx>, instance: &ty::Instance<'tcx>) pub fn of_instance(ccx: &CrateContext<'a, 'tcx>, instance: &ty::Instance<'tcx>)
-> Self { -> Self {
let fn_ty = instance_ty(ccx.shared(), &instance); let fn_ty = instance_ty(ccx.tcx(), &instance);
let sig = ty_fn_sig(ccx, fn_ty); let sig = ty_fn_sig(ccx, fn_ty);
let sig = ccx.tcx().erase_late_bound_regions_and_normalize(&sig); let sig = ccx.tcx().erase_late_bound_regions_and_normalize(&sig);
Self::new(ccx, sig, &[]) Self::new(ccx, sig, &[])

View file

@ -578,7 +578,7 @@ pub fn trans_instance<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, instance: Instance
// release builds. // release builds.
info!("trans_instance({})", instance); info!("trans_instance({})", instance);
let fn_ty = common::instance_ty(ccx.shared(), &instance); let fn_ty = common::instance_ty(ccx.tcx(), &instance);
let sig = common::ty_fn_sig(ccx, fn_ty); let sig = common::ty_fn_sig(ccx, fn_ty);
let sig = ccx.tcx().erase_late_bound_regions_and_normalize(&sig); let sig = ccx.tcx().erase_late_bound_regions_and_normalize(&sig);
@ -1424,7 +1424,7 @@ fn collect_and_partition_translation_items<'a, 'tcx>(scx: &SharedCrateContext<'a
let (items, inlining_map) = let (items, inlining_map) =
time(time_passes, "translation item collection", || { time(time_passes, "translation item collection", || {
collector::collect_crate_translation_items(&scx, collector::collect_crate_translation_items(scx.tcx(),
exported_symbols, exported_symbols,
collection_mode) collection_mode)
}); });

View file

@ -45,7 +45,7 @@ pub fn get_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
assert!(!instance.substs.has_escaping_regions()); assert!(!instance.substs.has_escaping_regions());
assert!(!instance.substs.has_param_types()); assert!(!instance.substs.has_param_types());
let fn_ty = common::instance_ty(ccx.shared(), &instance); let fn_ty = common::instance_ty(ccx.tcx(), &instance);
if let Some(&llfn) = ccx.instances().borrow().get(&instance) { if let Some(&llfn) = ccx.instances().borrow().get(&instance) {
return llfn; return llfn;
} }
@ -148,5 +148,5 @@ pub fn resolve_and_get_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
substs: &'tcx Substs<'tcx>) substs: &'tcx Substs<'tcx>)
-> ValueRef -> ValueRef
{ {
get_fn(ccx, monomorphize::resolve(ccx.shared(), def_id, substs)) get_fn(ccx, monomorphize::resolve(ccx.tcx(), def_id, substs))
} }

View file

@ -202,8 +202,7 @@ use rustc::ty::adjustment::CustomCoerceUnsized;
use rustc::mir::{self, Location}; use rustc::mir::{self, Location};
use rustc::mir::visit::Visitor as MirVisitor; use rustc::mir::visit::Visitor as MirVisitor;
use context::SharedCrateContext; use common::{def_ty, instance_ty, type_is_sized};
use common::{def_ty, instance_ty};
use monomorphize::{self, Instance}; use monomorphize::{self, Instance};
use rustc::util::nodemap::{FxHashSet, FxHashMap, DefIdMap}; use rustc::util::nodemap::{FxHashSet, FxHashMap, DefIdMap};
@ -294,15 +293,15 @@ impl<'tcx> InliningMap<'tcx> {
} }
} }
pub fn collect_crate_translation_items<'a, 'tcx>(scx: &SharedCrateContext<'a, 'tcx>, pub fn collect_crate_translation_items<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
exported_symbols: &ExportedSymbols, exported_symbols: &ExportedSymbols,
mode: TransItemCollectionMode) mode: TransItemCollectionMode)
-> (FxHashSet<TransItem<'tcx>>, -> (FxHashSet<TransItem<'tcx>>,
InliningMap<'tcx>) { InliningMap<'tcx>) {
// We are not tracking dependencies of this pass as it has to be re-executed // We are not tracking dependencies of this pass as it has to be re-executed
// every time no matter what. // every time no matter what.
scx.tcx().dep_graph.with_ignore(|| { tcx.dep_graph.with_ignore(|| {
let roots = collect_roots(scx, exported_symbols, mode); let roots = collect_roots(tcx, exported_symbols, mode);
debug!("Building translation item graph, beginning at roots"); debug!("Building translation item graph, beginning at roots");
let mut visited = FxHashSet(); let mut visited = FxHashSet();
@ -310,7 +309,7 @@ pub fn collect_crate_translation_items<'a, 'tcx>(scx: &SharedCrateContext<'a, 't
let mut inlining_map = InliningMap::new(); let mut inlining_map = InliningMap::new();
for root in roots { for root in roots {
collect_items_rec(scx, collect_items_rec(tcx,
root, root,
&mut visited, &mut visited,
&mut recursion_depths, &mut recursion_depths,
@ -323,7 +322,7 @@ pub fn collect_crate_translation_items<'a, 'tcx>(scx: &SharedCrateContext<'a, 't
// Find all non-generic items by walking the HIR. These items serve as roots to // Find all non-generic items by walking the HIR. These items serve as roots to
// start monomorphizing from. // start monomorphizing from.
fn collect_roots<'a, 'tcx>(scx: &SharedCrateContext<'a, 'tcx>, fn collect_roots<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
exported_symbols: &ExportedSymbols, exported_symbols: &ExportedSymbols,
mode: TransItemCollectionMode) mode: TransItemCollectionMode)
-> Vec<TransItem<'tcx>> { -> Vec<TransItem<'tcx>> {
@ -332,25 +331,25 @@ fn collect_roots<'a, 'tcx>(scx: &SharedCrateContext<'a, 'tcx>,
{ {
let mut visitor = RootCollector { let mut visitor = RootCollector {
scx, tcx,
mode, mode,
exported_symbols, exported_symbols,
output: &mut roots, output: &mut roots,
}; };
scx.tcx().hir.krate().visit_all_item_likes(&mut visitor); tcx.hir.krate().visit_all_item_likes(&mut visitor);
} }
// We can only translate items that are instantiable - items all of // We can only translate items that are instantiable - items all of
// whose predicates hold. Luckily, items that aren't instantiable // whose predicates hold. Luckily, items that aren't instantiable
// can't actually be used, so we can just skip translating them. // can't actually be used, so we can just skip translating them.
roots.retain(|root| root.is_instantiable(scx.tcx())); roots.retain(|root| root.is_instantiable(tcx));
roots roots
} }
// Collect all monomorphized translation items reachable from `starting_point` // Collect all monomorphized translation items reachable from `starting_point`
fn collect_items_rec<'a, 'tcx: 'a>(scx: &SharedCrateContext<'a, 'tcx>, fn collect_items_rec<'a, 'tcx: 'a>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
starting_point: TransItem<'tcx>, starting_point: TransItem<'tcx>,
visited: &mut FxHashSet<TransItem<'tcx>>, visited: &mut FxHashSet<TransItem<'tcx>>,
recursion_depths: &mut DefIdMap<usize>, recursion_depths: &mut DefIdMap<usize>,
@ -359,54 +358,54 @@ fn collect_items_rec<'a, 'tcx: 'a>(scx: &SharedCrateContext<'a, 'tcx>,
// We've been here already, no need to search again. // We've been here already, no need to search again.
return; return;
} }
debug!("BEGIN collect_items_rec({})", starting_point.to_string(scx.tcx())); debug!("BEGIN collect_items_rec({})", starting_point.to_string(tcx));
let mut neighbors = Vec::new(); let mut neighbors = Vec::new();
let recursion_depth_reset; let recursion_depth_reset;
match starting_point { match starting_point {
TransItem::Static(node_id) => { TransItem::Static(node_id) => {
let def_id = scx.tcx().hir.local_def_id(node_id); let def_id = tcx.hir.local_def_id(node_id);
let instance = Instance::mono(scx.tcx(), def_id); let instance = Instance::mono(tcx, def_id);
// Sanity check whether this ended up being collected accidentally // Sanity check whether this ended up being collected accidentally
debug_assert!(should_trans_locally(scx.tcx(), &instance)); debug_assert!(should_trans_locally(tcx, &instance));
let ty = instance_ty(scx, &instance); let ty = instance_ty(tcx, &instance);
visit_drop_use(scx, ty, true, &mut neighbors); visit_drop_use(tcx, ty, true, &mut neighbors);
recursion_depth_reset = None; recursion_depth_reset = None;
collect_neighbours(scx, instance, true, &mut neighbors); collect_neighbours(tcx, instance, true, &mut neighbors);
} }
TransItem::Fn(instance) => { TransItem::Fn(instance) => {
// Sanity check whether this ended up being collected accidentally // Sanity check whether this ended up being collected accidentally
debug_assert!(should_trans_locally(scx.tcx(), &instance)); debug_assert!(should_trans_locally(tcx, &instance));
// Keep track of the monomorphization recursion depth // Keep track of the monomorphization recursion depth
recursion_depth_reset = Some(check_recursion_limit(scx.tcx(), recursion_depth_reset = Some(check_recursion_limit(tcx,
instance, instance,
recursion_depths)); recursion_depths));
check_type_length_limit(scx.tcx(), instance); check_type_length_limit(tcx, instance);
collect_neighbours(scx, instance, false, &mut neighbors); collect_neighbours(tcx, instance, false, &mut neighbors);
} }
TransItem::GlobalAsm(..) => { TransItem::GlobalAsm(..) => {
recursion_depth_reset = None; recursion_depth_reset = None;
} }
} }
record_accesses(scx.tcx(), starting_point, &neighbors[..], inlining_map); record_accesses(tcx, starting_point, &neighbors[..], inlining_map);
for neighbour in neighbors { for neighbour in neighbors {
collect_items_rec(scx, neighbour, visited, recursion_depths, inlining_map); collect_items_rec(tcx, neighbour, visited, recursion_depths, inlining_map);
} }
if let Some((def_id, depth)) = recursion_depth_reset { if let Some((def_id, depth)) = recursion_depth_reset {
recursion_depths.insert(def_id, depth); recursion_depths.insert(def_id, depth);
} }
debug!("END collect_items_rec({})", starting_point.to_string(scx.tcx())); debug!("END collect_items_rec({})", starting_point.to_string(tcx));
} }
fn record_accesses<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, fn record_accesses<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
@ -494,7 +493,7 @@ fn check_type_length_limit<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
} }
struct MirNeighborCollector<'a, 'tcx: 'a> { struct MirNeighborCollector<'a, 'tcx: 'a> {
scx: &'a SharedCrateContext<'a, 'tcx>, tcx: TyCtxt<'a, 'tcx, 'tcx>,
mir: &'a mir::Mir<'tcx>, mir: &'a mir::Mir<'tcx>,
output: &'a mut Vec<TransItem<'tcx>>, output: &'a mut Vec<TransItem<'tcx>>,
param_substs: &'tcx Substs<'tcx>, param_substs: &'tcx Substs<'tcx>,
@ -511,49 +510,49 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirNeighborCollector<'a, 'tcx> {
// have to instantiate all methods of the trait being cast to, so we // have to instantiate all methods of the trait being cast to, so we
// can build the appropriate vtable. // can build the appropriate vtable.
mir::Rvalue::Cast(mir::CastKind::Unsize, ref operand, target_ty) => { mir::Rvalue::Cast(mir::CastKind::Unsize, ref operand, target_ty) => {
let target_ty = self.scx.tcx().trans_apply_param_substs(self.param_substs, let target_ty = self.tcx.trans_apply_param_substs(self.param_substs,
&target_ty); &target_ty);
let source_ty = operand.ty(self.mir, self.scx.tcx()); let source_ty = operand.ty(self.mir, self.tcx);
let source_ty = self.scx.tcx().trans_apply_param_substs(self.param_substs, let source_ty = self.tcx.trans_apply_param_substs(self.param_substs,
&source_ty); &source_ty);
let (source_ty, target_ty) = find_vtable_types_for_unsizing(self.scx, let (source_ty, target_ty) = find_vtable_types_for_unsizing(self.tcx,
source_ty, source_ty,
target_ty); target_ty);
// This could also be a different Unsize instruction, like // This could also be a different Unsize instruction, like
// from a fixed sized array to a slice. But we are only // from a fixed sized array to a slice. But we are only
// interested in things that produce a vtable. // interested in things that produce a vtable.
if target_ty.is_trait() && !source_ty.is_trait() { if target_ty.is_trait() && !source_ty.is_trait() {
create_trans_items_for_vtable_methods(self.scx, create_trans_items_for_vtable_methods(self.tcx,
target_ty, target_ty,
source_ty, source_ty,
self.output); self.output);
} }
} }
mir::Rvalue::Cast(mir::CastKind::ReifyFnPointer, ref operand, _) => { mir::Rvalue::Cast(mir::CastKind::ReifyFnPointer, ref operand, _) => {
let fn_ty = operand.ty(self.mir, self.scx.tcx()); let fn_ty = operand.ty(self.mir, self.tcx);
let fn_ty = self.scx.tcx().trans_apply_param_substs(self.param_substs, let fn_ty = self.tcx.trans_apply_param_substs(self.param_substs,
&fn_ty); &fn_ty);
visit_fn_use(self.scx, fn_ty, false, &mut self.output); visit_fn_use(self.tcx, fn_ty, false, &mut self.output);
} }
mir::Rvalue::Cast(mir::CastKind::ClosureFnPointer, ref operand, _) => { mir::Rvalue::Cast(mir::CastKind::ClosureFnPointer, ref operand, _) => {
let source_ty = operand.ty(self.mir, self.scx.tcx()); let source_ty = operand.ty(self.mir, self.tcx);
let source_ty = self.scx.tcx().trans_apply_param_substs(self.param_substs, let source_ty = self.tcx.trans_apply_param_substs(self.param_substs,
&source_ty); &source_ty);
match source_ty.sty { match source_ty.sty {
ty::TyClosure(def_id, substs) => { ty::TyClosure(def_id, substs) => {
let instance = monomorphize::resolve_closure( let instance = monomorphize::resolve_closure(
self.scx, def_id, substs, ty::ClosureKind::FnOnce); self.tcx, def_id, substs, ty::ClosureKind::FnOnce);
self.output.push(create_fn_trans_item(instance)); self.output.push(create_fn_trans_item(instance));
} }
_ => bug!(), _ => bug!(),
} }
} }
mir::Rvalue::NullaryOp(mir::NullOp::Box, _) => { mir::Rvalue::NullaryOp(mir::NullOp::Box, _) => {
let tcx = self.scx.tcx(); let tcx = self.tcx;
let exchange_malloc_fn_def_id = tcx let exchange_malloc_fn_def_id = tcx
.lang_items() .lang_items()
.require(ExchangeMallocFnLangItem) .require(ExchangeMallocFnLangItem)
.unwrap_or_else(|e| self.scx.sess().fatal(&e)); .unwrap_or_else(|e| tcx.sess.fatal(&e));
let instance = Instance::mono(tcx, exchange_malloc_fn_def_id); let instance = Instance::mono(tcx, exchange_malloc_fn_def_id);
if should_trans_locally(tcx, &instance) { if should_trans_locally(tcx, &instance) {
self.output.push(create_fn_trans_item(instance)); self.output.push(create_fn_trans_item(instance));
@ -569,10 +568,10 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirNeighborCollector<'a, 'tcx> {
debug!("visiting const {:?} @ {:?}", *constant, location); debug!("visiting const {:?} @ {:?}", *constant, location);
if let ConstVal::Unevaluated(def_id, substs) = constant.val { if let ConstVal::Unevaluated(def_id, substs) = constant.val {
let substs = self.scx.tcx().trans_apply_param_substs(self.param_substs, let substs = self.tcx.trans_apply_param_substs(self.param_substs,
&substs); &substs);
let instance = monomorphize::resolve(self.scx, def_id, substs); let instance = monomorphize::resolve(self.tcx, def_id, substs);
collect_neighbours(self.scx, instance, true, self.output); collect_neighbours(self.tcx, instance, true, self.output);
} }
self.super_const(constant); self.super_const(constant);
@ -584,15 +583,15 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirNeighborCollector<'a, 'tcx> {
location: Location) { location: Location) {
debug!("visiting terminator {:?} @ {:?}", kind, location); debug!("visiting terminator {:?} @ {:?}", kind, location);
let tcx = self.scx.tcx(); let tcx = self.tcx;
match *kind { match *kind {
mir::TerminatorKind::Call { ref func, .. } => { mir::TerminatorKind::Call { ref func, .. } => {
let callee_ty = func.ty(self.mir, tcx); 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.trans_apply_param_substs(self.param_substs, &callee_ty);
let constness = match (self.const_context, &callee_ty.sty) { let constness = match (self.const_context, &callee_ty.sty) {
(true, &ty::TyFnDef(def_id, substs)) if self.scx.tcx().is_const_fn(def_id) => { (true, &ty::TyFnDef(def_id, substs)) if self.tcx.is_const_fn(def_id) => {
let instance = monomorphize::resolve(self.scx, def_id, substs); let instance = monomorphize::resolve(self.tcx, def_id, substs);
Some(instance) Some(instance)
} }
_ => None _ => None
@ -602,20 +601,20 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirNeighborCollector<'a, 'tcx> {
// If this is a const fn, called from a const context, we // If this is a const fn, called from a const context, we
// have to visit its body in order to find any fn reifications // have to visit its body in order to find any fn reifications
// it might contain. // it might contain.
collect_neighbours(self.scx, collect_neighbours(self.tcx,
const_fn_instance, const_fn_instance,
true, true,
self.output); self.output);
} else { } else {
visit_fn_use(self.scx, callee_ty, true, &mut self.output); visit_fn_use(self.tcx, callee_ty, true, &mut self.output);
} }
} }
mir::TerminatorKind::Drop { ref location, .. } | mir::TerminatorKind::Drop { ref location, .. } |
mir::TerminatorKind::DropAndReplace { ref location, .. } => { mir::TerminatorKind::DropAndReplace { ref location, .. } => {
let ty = location.ty(self.mir, self.scx.tcx()) let ty = location.ty(self.mir, self.tcx)
.to_ty(self.scx.tcx()); .to_ty(self.tcx);
let ty = tcx.trans_apply_param_substs(self.param_substs, &ty); let ty = tcx.trans_apply_param_substs(self.param_substs, &ty);
visit_drop_use(self.scx, ty, true, self.output); visit_drop_use(self.tcx, ty, true, self.output);
} }
mir::TerminatorKind::Goto { .. } | mir::TerminatorKind::Goto { .. } |
mir::TerminatorKind::SwitchInt { .. } | mir::TerminatorKind::SwitchInt { .. } |
@ -636,7 +635,7 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirNeighborCollector<'a, 'tcx> {
location: Location) { location: Location) {
debug!("visiting static {:?} @ {:?}", static_.def_id, location); debug!("visiting static {:?} @ {:?}", static_.def_id, location);
let tcx = self.scx.tcx(); let tcx = self.tcx;
let instance = Instance::mono(tcx, static_.def_id); let instance = Instance::mono(tcx, static_.def_id);
if should_trans_locally(tcx, &instance) { if should_trans_locally(tcx, &instance) {
let node_id = tcx.hir.as_local_node_id(static_.def_id).unwrap(); let node_id = tcx.hir.as_local_node_id(static_.def_id).unwrap();
@ -647,33 +646,33 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirNeighborCollector<'a, 'tcx> {
} }
} }
fn visit_drop_use<'a, 'tcx>(scx: &SharedCrateContext<'a, 'tcx>, fn visit_drop_use<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
ty: Ty<'tcx>, ty: Ty<'tcx>,
is_direct_call: bool, is_direct_call: bool,
output: &mut Vec<TransItem<'tcx>>) output: &mut Vec<TransItem<'tcx>>)
{ {
let instance = monomorphize::resolve_drop_in_place(scx, ty); let instance = monomorphize::resolve_drop_in_place(tcx, ty);
visit_instance_use(scx, instance, is_direct_call, output); visit_instance_use(tcx, instance, is_direct_call, output);
} }
fn visit_fn_use<'a, 'tcx>(scx: &SharedCrateContext<'a, 'tcx>, fn visit_fn_use<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
ty: Ty<'tcx>, ty: Ty<'tcx>,
is_direct_call: bool, is_direct_call: bool,
output: &mut Vec<TransItem<'tcx>>) output: &mut Vec<TransItem<'tcx>>)
{ {
if let ty::TyFnDef(def_id, substs) = ty.sty { if let ty::TyFnDef(def_id, substs) = ty.sty {
let instance = monomorphize::resolve(scx, def_id, substs); let instance = monomorphize::resolve(tcx, def_id, substs);
visit_instance_use(scx, instance, is_direct_call, output); visit_instance_use(tcx, instance, is_direct_call, output);
} }
} }
fn visit_instance_use<'a, 'tcx>(scx: &SharedCrateContext<'a, 'tcx>, fn visit_instance_use<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
instance: ty::Instance<'tcx>, instance: ty::Instance<'tcx>,
is_direct_call: bool, is_direct_call: bool,
output: &mut Vec<TransItem<'tcx>>) output: &mut Vec<TransItem<'tcx>>)
{ {
debug!("visit_item_use({:?}, is_direct_call={:?})", instance, is_direct_call); debug!("visit_item_use({:?}, is_direct_call={:?})", instance, is_direct_call);
if !should_trans_locally(scx.tcx(), &instance) { if !should_trans_locally(tcx, &instance) {
return return
} }
@ -775,15 +774,15 @@ fn should_trans_locally<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, instance: &Instan
/// ///
/// Finally, there is also the case of custom unsizing coercions, e.g. for /// Finally, there is also the case of custom unsizing coercions, e.g. for
/// smart pointers such as `Rc` and `Arc`. /// smart pointers such as `Rc` and `Arc`.
fn find_vtable_types_for_unsizing<'a, 'tcx>(scx: &SharedCrateContext<'a, 'tcx>, fn find_vtable_types_for_unsizing<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
source_ty: Ty<'tcx>, source_ty: Ty<'tcx>,
target_ty: Ty<'tcx>) target_ty: Ty<'tcx>)
-> (Ty<'tcx>, Ty<'tcx>) { -> (Ty<'tcx>, Ty<'tcx>) {
let ptr_vtable = |inner_source: Ty<'tcx>, inner_target: Ty<'tcx>| { let ptr_vtable = |inner_source: Ty<'tcx>, inner_target: Ty<'tcx>| {
if !scx.type_is_sized(inner_source) { if !type_is_sized(tcx, inner_source) {
(inner_source, inner_target) (inner_source, inner_target)
} else { } else {
scx.tcx().struct_lockstep_tails(inner_source, inner_target) tcx.struct_lockstep_tails(inner_source, inner_target)
} }
}; };
match (&source_ty.sty, &target_ty.sty) { match (&source_ty.sty, &target_ty.sty) {
@ -804,7 +803,7 @@ fn find_vtable_types_for_unsizing<'a, 'tcx>(scx: &SharedCrateContext<'a, 'tcx>,
assert_eq!(source_adt_def, target_adt_def); assert_eq!(source_adt_def, target_adt_def);
let kind = let kind =
monomorphize::custom_coerce_unsize_info(scx, source_ty, target_ty); monomorphize::custom_coerce_unsize_info(tcx, source_ty, target_ty);
let coerce_index = match kind { let coerce_index = match kind {
CustomCoerceUnsized::Struct(i) => i CustomCoerceUnsized::Struct(i) => i
@ -816,10 +815,10 @@ fn find_vtable_types_for_unsizing<'a, 'tcx>(scx: &SharedCrateContext<'a, 'tcx>,
assert!(coerce_index < source_fields.len() && assert!(coerce_index < source_fields.len() &&
source_fields.len() == target_fields.len()); source_fields.len() == target_fields.len());
find_vtable_types_for_unsizing(scx, find_vtable_types_for_unsizing(tcx,
source_fields[coerce_index].ty(scx.tcx(), source_fields[coerce_index].ty(tcx,
source_substs), source_substs),
target_fields[coerce_index].ty(scx.tcx(), target_fields[coerce_index].ty(tcx,
target_substs)) target_substs))
} }
_ => bug!("find_vtable_types_for_unsizing: invalid coercion {:?} -> {:?}", _ => bug!("find_vtable_types_for_unsizing: invalid coercion {:?} -> {:?}",
@ -835,7 +834,7 @@ fn create_fn_trans_item<'a, 'tcx>(instance: Instance<'tcx>) -> TransItem<'tcx> {
/// Creates a `TransItem` for each method that is referenced by the vtable for /// Creates a `TransItem` for each method that is referenced by the vtable for
/// the given trait/impl pair. /// the given trait/impl pair.
fn create_trans_items_for_vtable_methods<'a, 'tcx>(scx: &SharedCrateContext<'a, 'tcx>, fn create_trans_items_for_vtable_methods<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
trait_ty: Ty<'tcx>, trait_ty: Ty<'tcx>,
impl_ty: Ty<'tcx>, impl_ty: Ty<'tcx>,
output: &mut Vec<TransItem<'tcx>>) { output: &mut Vec<TransItem<'tcx>>) {
@ -844,19 +843,19 @@ fn create_trans_items_for_vtable_methods<'a, 'tcx>(scx: &SharedCrateContext<'a,
if let ty::TyDynamic(ref trait_ty, ..) = trait_ty.sty { if let ty::TyDynamic(ref trait_ty, ..) = trait_ty.sty {
if let Some(principal) = trait_ty.principal() { if let Some(principal) = trait_ty.principal() {
let poly_trait_ref = principal.with_self_ty(scx.tcx(), impl_ty); let poly_trait_ref = principal.with_self_ty(tcx, impl_ty);
assert!(!poly_trait_ref.has_escaping_regions()); assert!(!poly_trait_ref.has_escaping_regions());
// Walk all methods of the trait, including those of its supertraits // Walk all methods of the trait, including those of its supertraits
let methods = traits::get_vtable_methods(scx.tcx(), poly_trait_ref); let methods = traits::get_vtable_methods(tcx, poly_trait_ref);
let methods = methods.filter_map(|method| method) let methods = methods.filter_map(|method| method)
.map(|(def_id, substs)| monomorphize::resolve(scx, def_id, substs)) .map(|(def_id, substs)| monomorphize::resolve(tcx, def_id, substs))
.filter(|&instance| should_trans_locally(scx.tcx(), &instance)) .filter(|&instance| should_trans_locally(tcx, &instance))
.map(|instance| create_fn_trans_item(instance)); .map(|instance| create_fn_trans_item(instance));
output.extend(methods); output.extend(methods);
} }
// Also add the destructor // Also add the destructor
visit_drop_use(scx, impl_ty, false, output); visit_drop_use(tcx, impl_ty, false, output);
} }
} }
@ -865,7 +864,7 @@ fn create_trans_items_for_vtable_methods<'a, 'tcx>(scx: &SharedCrateContext<'a,
//=----------------------------------------------------------------------------- //=-----------------------------------------------------------------------------
struct RootCollector<'b, 'a: 'b, 'tcx: 'a + 'b> { struct RootCollector<'b, 'a: 'b, 'tcx: 'a + 'b> {
scx: &'b SharedCrateContext<'a, 'tcx>, tcx: TyCtxt<'a, 'tcx, 'tcx>,
exported_symbols: &'b ExportedSymbols, exported_symbols: &'b ExportedSymbols,
mode: TransItemCollectionMode, mode: TransItemCollectionMode,
output: &'b mut Vec<TransItem<'tcx>>, output: &'b mut Vec<TransItem<'tcx>>,
@ -886,7 +885,7 @@ impl<'b, 'a, 'v> ItemLikeVisitor<'v> for RootCollector<'b, 'a, 'v> {
hir::ItemImpl(..) => { hir::ItemImpl(..) => {
if self.mode == TransItemCollectionMode::Eager { if self.mode == TransItemCollectionMode::Eager {
create_trans_items_for_default_impls(self.scx, create_trans_items_for_default_impls(self.tcx,
item, item,
self.output); self.output);
} }
@ -897,25 +896,25 @@ impl<'b, 'a, 'v> ItemLikeVisitor<'v> for RootCollector<'b, 'a, 'v> {
hir::ItemUnion(_, ref generics) => { hir::ItemUnion(_, ref generics) => {
if !generics.is_parameterized() { if !generics.is_parameterized() {
if self.mode == TransItemCollectionMode::Eager { if self.mode == TransItemCollectionMode::Eager {
let def_id = self.scx.tcx().hir.local_def_id(item.id); let def_id = self.tcx.hir.local_def_id(item.id);
debug!("RootCollector: ADT drop-glue for {}", debug!("RootCollector: ADT drop-glue for {}",
def_id_to_string(self.scx.tcx(), def_id)); def_id_to_string(self.tcx, def_id));
let ty = def_ty(self.scx, def_id, Substs::empty()); let ty = def_ty(self.tcx, def_id, Substs::empty());
visit_drop_use(self.scx, ty, true, self.output); visit_drop_use(self.tcx, ty, true, self.output);
} }
} }
} }
hir::ItemGlobalAsm(..) => { hir::ItemGlobalAsm(..) => {
debug!("RootCollector: ItemGlobalAsm({})", debug!("RootCollector: ItemGlobalAsm({})",
def_id_to_string(self.scx.tcx(), def_id_to_string(self.tcx,
self.scx.tcx().hir.local_def_id(item.id))); self.tcx.hir.local_def_id(item.id)));
self.output.push(TransItem::GlobalAsm(item.id)); self.output.push(TransItem::GlobalAsm(item.id));
} }
hir::ItemStatic(..) => { hir::ItemStatic(..) => {
debug!("RootCollector: ItemStatic({})", debug!("RootCollector: ItemStatic({})",
def_id_to_string(self.scx.tcx(), def_id_to_string(self.tcx,
self.scx.tcx().hir.local_def_id(item.id))); self.tcx.hir.local_def_id(item.id)));
self.output.push(TransItem::Static(item.id)); self.output.push(TransItem::Static(item.id));
} }
hir::ItemConst(..) => { hir::ItemConst(..) => {
@ -923,7 +922,7 @@ impl<'b, 'a, 'v> ItemLikeVisitor<'v> for RootCollector<'b, 'a, 'v> {
// actually used somewhere. Just declaring them is insufficient. // actually used somewhere. Just declaring them is insufficient.
} }
hir::ItemFn(..) => { hir::ItemFn(..) => {
let tcx = self.scx.tcx(); let tcx = self.tcx;
let def_id = tcx.hir.local_def_id(item.id); let def_id = tcx.hir.local_def_id(item.id);
if (self.mode == TransItemCollectionMode::Eager || if (self.mode == TransItemCollectionMode::Eager ||
@ -949,7 +948,7 @@ impl<'b, 'a, 'v> ItemLikeVisitor<'v> for RootCollector<'b, 'a, 'v> {
fn visit_impl_item(&mut self, ii: &'v hir::ImplItem) { fn visit_impl_item(&mut self, ii: &'v hir::ImplItem) {
match ii.node { match ii.node {
hir::ImplItemKind::Method(hir::MethodSig { .. }, _) => { hir::ImplItemKind::Method(hir::MethodSig { .. }, _) => {
let tcx = self.scx.tcx(); let tcx = self.tcx;
let def_id = tcx.hir.local_def_id(ii.id); let def_id = tcx.hir.local_def_id(ii.id);
if (self.mode == TransItemCollectionMode::Eager || if (self.mode == TransItemCollectionMode::Eager ||
@ -973,10 +972,9 @@ fn item_has_type_parameters<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId
generics.parent_types as usize + generics.types.len() > 0 generics.parent_types as usize + generics.types.len() > 0
} }
fn create_trans_items_for_default_impls<'a, 'tcx>(scx: &SharedCrateContext<'a, 'tcx>, fn create_trans_items_for_default_impls<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
item: &'tcx hir::Item, item: &'tcx hir::Item,
output: &mut Vec<TransItem<'tcx>>) { output: &mut Vec<TransItem<'tcx>>) {
let tcx = scx.tcx();
match item.node { match item.node {
hir::ItemImpl(_, hir::ItemImpl(_,
_, _,
@ -1009,7 +1007,7 @@ fn create_trans_items_for_default_impls<'a, 'tcx>(scx: &SharedCrateContext<'a, '
} }
let instance = let instance =
monomorphize::resolve(scx, method.def_id, callee_substs); monomorphize::resolve(tcx, method.def_id, callee_substs);
let trans_item = create_fn_trans_item(instance); let trans_item = create_fn_trans_item(instance);
if trans_item.is_instantiable(tcx) && should_trans_locally(tcx, &instance) { if trans_item.is_instantiable(tcx) && should_trans_locally(tcx, &instance) {
@ -1025,15 +1023,15 @@ fn create_trans_items_for_default_impls<'a, 'tcx>(scx: &SharedCrateContext<'a, '
} }
/// Scan the MIR in order to find function calls, closures, and drop-glue /// Scan the MIR in order to find function calls, closures, and drop-glue
fn collect_neighbours<'a, 'tcx>(scx: &SharedCrateContext<'a, 'tcx>, fn collect_neighbours<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
instance: Instance<'tcx>, instance: Instance<'tcx>,
const_context: bool, const_context: bool,
output: &mut Vec<TransItem<'tcx>>) output: &mut Vec<TransItem<'tcx>>)
{ {
let mir = scx.tcx().instance_mir(instance.def); let mir = tcx.instance_mir(instance.def);
let mut visitor = MirNeighborCollector { let mut visitor = MirNeighborCollector {
scx, tcx,
mir: &mir, mir: &mir,
output, output,
param_substs: instance.substs, param_substs: instance.substs,

View file

@ -26,6 +26,7 @@ use machine;
use monomorphize; use monomorphize;
use type_::Type; use type_::Type;
use value::Value; use value::Value;
use rustc::traits;
use rustc::ty::{self, Ty, TyCtxt}; use rustc::ty::{self, Ty, TyCtxt};
use rustc::ty::layout::{Layout, LayoutTyper}; use rustc::ty::layout::{Layout, LayoutTyper};
use rustc::ty::subst::{Kind, Subst, Substs}; use rustc::ty::subst::{Kind, Subst, Substs};
@ -37,7 +38,7 @@ use std::iter;
use syntax::abi::Abi; use syntax::abi::Abi;
use syntax::attr; use syntax::attr;
use syntax::symbol::InternedString; use syntax::symbol::InternedString;
use syntax_pos::Span; use syntax_pos::{Span, DUMMY_SP};
pub use context::{CrateContext, SharedCrateContext}; pub use context::{CrateContext, SharedCrateContext};
@ -140,6 +141,18 @@ pub fn type_is_zero_size<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, ty: Ty<'tcx>) -
!layout.is_unsized() && layout.size(ccx).bytes() == 0 !layout.is_unsized() && layout.size(ccx).bytes() == 0
} }
pub fn type_needs_drop<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, ty: Ty<'tcx>) -> bool {
ty.needs_drop(tcx, ty::ParamEnv::empty(traits::Reveal::All))
}
pub fn type_is_sized<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, ty: Ty<'tcx>) -> bool {
ty.is_sized(tcx, ty::ParamEnv::empty(traits::Reveal::All), DUMMY_SP)
}
pub fn type_is_freeze<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, ty: Ty<'tcx>) -> bool {
ty.is_freeze(tcx, ty::ParamEnv::empty(traits::Reveal::All), DUMMY_SP)
}
/* /*
* A note on nomenclature of linking: "extern", "foreign", and "upcall". * A note on nomenclature of linking: "extern", "foreign", and "upcall".
* *
@ -573,20 +586,20 @@ pub fn is_inline_instance<'a, 'tcx>(
} }
/// Given a DefId and some Substs, produces the monomorphic item type. /// Given a DefId and some Substs, produces the monomorphic item type.
pub fn def_ty<'a, 'tcx>(shared: &SharedCrateContext<'a, 'tcx>, pub fn def_ty<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
def_id: DefId, def_id: DefId,
substs: &'tcx Substs<'tcx>) substs: &'tcx Substs<'tcx>)
-> Ty<'tcx> -> Ty<'tcx>
{ {
let ty = shared.tcx().type_of(def_id); let ty = tcx.type_of(def_id);
shared.tcx().trans_apply_param_substs(substs, &ty) tcx.trans_apply_param_substs(substs, &ty)
} }
/// Return the substituted type of an instance. /// Return the substituted type of an instance.
pub fn instance_ty<'a, 'tcx>(shared: &SharedCrateContext<'a, 'tcx>, pub fn instance_ty<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
instance: &ty::Instance<'tcx>) instance: &ty::Instance<'tcx>)
-> Ty<'tcx> -> Ty<'tcx>
{ {
let ty = instance.def.def_ty(shared.tcx()); let ty = instance.def.def_ty(tcx);
shared.tcx().trans_apply_param_substs(instance.substs, &ty) tcx.trans_apply_param_substs(instance.substs, &ty)
} }

View file

@ -109,7 +109,7 @@ pub fn get_static(ccx: &CrateContext, def_id: DefId) -> ValueRef {
return g; return g;
} }
let ty = common::instance_ty(ccx.shared(), &instance); let ty = common::instance_ty(ccx.tcx(), &instance);
let g = if let Some(id) = ccx.tcx().hir.as_local_node_id(def_id) { let g = if let Some(id) = ccx.tcx().hir.as_local_node_id(def_id) {
let llty = type_of::type_of(ccx, ty); let llty = type_of::type_of(ccx, ty);
@ -269,7 +269,7 @@ pub fn trans_static<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
}; };
let instance = Instance::mono(ccx.tcx(), def_id); let instance = Instance::mono(ccx.tcx(), def_id);
let ty = common::instance_ty(ccx.shared(), &instance); let ty = common::instance_ty(ccx.tcx(), &instance);
let llty = type_of::type_of(ccx, ty); let llty = type_of::type_of(ccx, ty);
let g = if val_llty == llty { let g = if val_llty == llty {
g g

View file

@ -8,6 +8,7 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
use common;
use llvm; use llvm;
use llvm::{ContextRef, ModuleRef, ValueRef}; use llvm::{ContextRef, ModuleRef, ValueRef};
use rustc::dep_graph::{DepGraph, DepGraphSafe}; use rustc::dep_graph::{DepGraph, DepGraphSafe};
@ -39,7 +40,6 @@ use std::str;
use std::sync::Arc; use std::sync::Arc;
use std::marker::PhantomData; use std::marker::PhantomData;
use syntax::symbol::InternedString; use syntax::symbol::InternedString;
use syntax_pos::DUMMY_SP;
use abi::Abi; use abi::Abi;
#[derive(Clone, Default)] #[derive(Clone, Default)]
@ -319,15 +319,15 @@ impl<'b, 'tcx> SharedCrateContext<'b, 'tcx> {
} }
pub fn type_needs_drop(&self, ty: Ty<'tcx>) -> bool { pub fn type_needs_drop(&self, ty: Ty<'tcx>) -> bool {
ty.needs_drop(self.tcx, ty::ParamEnv::empty(traits::Reveal::All)) common::type_needs_drop(self.tcx, ty)
} }
pub fn type_is_sized(&self, ty: Ty<'tcx>) -> bool { pub fn type_is_sized(&self, ty: Ty<'tcx>) -> bool {
ty.is_sized(self.tcx, ty::ParamEnv::empty(traits::Reveal::All), DUMMY_SP) common::type_is_sized(self.tcx, ty)
} }
pub fn type_is_freeze(&self, ty: Ty<'tcx>) -> bool { pub fn type_is_freeze(&self, ty: Ty<'tcx>) -> bool {
ty.is_freeze(self.tcx, ty::ParamEnv::empty(traits::Reveal::All), DUMMY_SP) common::type_is_freeze(self.tcx, ty)
} }
pub fn tcx<'a>(&'a self) -> TyCtxt<'a, 'tcx, 'tcx> { pub fn tcx<'a>(&'a self) -> TyCtxt<'a, 'tcx, 'tcx> {

View file

@ -1803,7 +1803,7 @@ pub fn create_global_var_metadata(cx: &CrateContext,
}; };
let is_local_to_unit = is_node_local_to_unit(cx, node_id); let is_local_to_unit = is_node_local_to_unit(cx, node_id);
let variable_type = common::def_ty(cx.shared(), node_def_id, Substs::empty()); let variable_type = common::def_ty(cx.tcx(), node_def_id, Substs::empty());
let type_metadata = type_metadata(cx, variable_type, span); let type_metadata = type_metadata(cx, variable_type, span);
let var_name = tcx.item_name(node_def_id).to_string(); let var_name = tcx.item_name(node_def_id).to_string();
let linkage_name = mangled_name_of_item(cx, node_def_id, ""); let linkage_name = mangled_name_of_item(cx, node_def_id, "");

View file

@ -428,7 +428,7 @@ pub fn create_function_debug_context<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
// If the method does *not* belong to a trait, proceed // If the method does *not* belong to a trait, proceed
if cx.tcx().trait_id_of_impl(impl_def_id).is_none() { if cx.tcx().trait_id_of_impl(impl_def_id).is_none() {
let impl_self_ty = let impl_self_ty =
common::def_ty(cx.shared(), impl_def_id, instance.substs); common::def_ty(cx.tcx(), impl_def_id, instance.substs);
// Only "class" methods are generally understood by LLVM, // Only "class" methods are generally understood by LLVM,
// so avoid methods on other types (e.g. `<*mut T>::null`). // so avoid methods on other types (e.g. `<*mut T>::null`).

View file

@ -14,15 +14,16 @@
use std; use std;
use llvm; use builder::Builder;
use llvm::{ValueRef};
use rustc::ty::{self, Ty};
use rustc::ty::layout::LayoutTyper;
use common::*; use common::*;
use llvm::{ValueRef};
use llvm;
use meth; use meth;
use monomorphize; use monomorphize;
use rustc::traits;
use rustc::ty::layout::LayoutTyper;
use rustc::ty::{self, Ty, TypeFoldable, TyCtxt};
use value::Value; use value::Value;
use builder::Builder;
pub fn size_and_align_of_dst<'a, 'tcx>(bcx: &Builder<'a, 'tcx>, t: Ty<'tcx>, info: ValueRef) pub fn size_and_align_of_dst<'a, 'tcx>(bcx: &Builder<'a, 'tcx>, t: Ty<'tcx>, info: ValueRef)
-> (ValueRef, ValueRef) { -> (ValueRef, ValueRef) {

View file

@ -80,7 +80,7 @@ pub fn get_vtable<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
let nullptr = C_null(Type::nil(ccx).ptr_to()); let nullptr = C_null(Type::nil(ccx).ptr_to());
let mut components: Vec<_> = [ let mut components: Vec<_> = [
callee::get_fn(ccx, monomorphize::resolve_drop_in_place(ccx.shared(), ty)), callee::get_fn(ccx, monomorphize::resolve_drop_in_place(ccx.tcx(), ty)),
C_usize(ccx, ccx.size_of(ty)), C_usize(ccx, ccx.size_of(ty)),
C_usize(ccx, ccx.align_of(ty) as u64) C_usize(ccx, ccx.align_of(ty) as u64)
].iter().cloned().collect(); ].iter().cloned().collect();

View file

@ -265,7 +265,7 @@ impl<'a, 'tcx> MirContext<'a, 'tcx> {
mir::TerminatorKind::Drop { ref location, target, unwind } => { mir::TerminatorKind::Drop { ref location, target, unwind } => {
let ty = location.ty(self.mir, bcx.tcx()).to_ty(bcx.tcx()); let ty = location.ty(self.mir, bcx.tcx()).to_ty(bcx.tcx());
let ty = self.monomorphize(&ty); let ty = self.monomorphize(&ty);
let drop_fn = monomorphize::resolve_drop_in_place(bcx.ccx.shared(), ty); let drop_fn = monomorphize::resolve_drop_in_place(bcx.ccx.tcx(), ty);
if let ty::InstanceDef::DropGlue(_, None) = drop_fn.def { if let ty::InstanceDef::DropGlue(_, None) = drop_fn.def {
// we don't actually need to drop anything. // we don't actually need to drop anything.
@ -429,7 +429,7 @@ impl<'a, 'tcx> MirContext<'a, 'tcx> {
let (instance, mut llfn) = match callee.ty.sty { let (instance, mut llfn) = match callee.ty.sty {
ty::TyFnDef(def_id, substs) => { ty::TyFnDef(def_id, substs) => {
(Some(monomorphize::resolve(bcx.ccx.shared(), def_id, substs)), (Some(monomorphize::resolve(bcx.ccx.tcx(), def_id, substs)),
None) None)
} }
ty::TyFnPtr(_) => { ty::TyFnPtr(_) => {
@ -546,7 +546,7 @@ impl<'a, 'tcx> MirContext<'a, 'tcx> {
}; };
let callee_ty = common::instance_ty( let callee_ty = common::instance_ty(
bcx.ccx.shared(), instance.as_ref().unwrap()); bcx.ccx.tcx(), instance.as_ref().unwrap());
trans_intrinsic_call(&bcx, callee_ty, &fn_ty, &llargs, dest, trans_intrinsic_call(&bcx, callee_ty, &fn_ty, &llargs, dest,
terminator.source_info.span); terminator.source_info.span);

View file

@ -261,7 +261,7 @@ impl<'a, 'tcx> MirConstContext<'a, 'tcx> {
substs: &'tcx Substs<'tcx>, substs: &'tcx Substs<'tcx>,
args: IndexVec<mir::Local, Result<Const<'tcx>, ConstEvalErr<'tcx>>>) args: IndexVec<mir::Local, Result<Const<'tcx>, ConstEvalErr<'tcx>>>)
-> Result<Const<'tcx>, ConstEvalErr<'tcx>> { -> Result<Const<'tcx>, ConstEvalErr<'tcx>> {
let instance = monomorphize::resolve(ccx.shared(), def_id, substs); let instance = monomorphize::resolve(ccx.tcx(), def_id, substs);
let mir = ccx.tcx().instance_mir(instance.def); let mir = ccx.tcx().instance_mir(instance.def);
MirConstContext::new(ccx, &mir, instance.substs, args).trans() MirConstContext::new(ccx, &mir, instance.substs, args).trans()
} }

View file

@ -222,7 +222,7 @@ impl<'a, 'tcx> MirContext<'a, 'tcx> {
match operand.ty.sty { match operand.ty.sty {
ty::TyClosure(def_id, substs) => { ty::TyClosure(def_id, substs) => {
let instance = monomorphize::resolve_closure( let instance = monomorphize::resolve_closure(
bcx.ccx.shared(), def_id, substs, ty::ClosureKind::FnOnce); bcx.ccx.tcx(), def_id, substs, ty::ClosureKind::FnOnce);
OperandValue::Immediate(callee::get_fn(bcx.ccx, instance)) OperandValue::Immediate(callee::get_fn(bcx.ccx, instance))
} }
_ => { _ => {

View file

@ -85,27 +85,26 @@ fn needs_fn_once_adapter_shim(actual_closure_kind: ty::ClosureKind,
} }
pub fn resolve_closure<'a, 'tcx> ( pub fn resolve_closure<'a, 'tcx> (
scx: &SharedCrateContext<'a, 'tcx>, tcx: TyCtxt<'a, 'tcx, 'tcx>,
def_id: DefId, def_id: DefId,
substs: ty::ClosureSubsts<'tcx>, substs: ty::ClosureSubsts<'tcx>,
requested_kind: ty::ClosureKind) requested_kind: ty::ClosureKind)
-> Instance<'tcx> -> Instance<'tcx>
{ {
let actual_kind = scx.tcx().closure_kind(def_id); let actual_kind = tcx.closure_kind(def_id);
match needs_fn_once_adapter_shim(actual_kind, requested_kind) { match needs_fn_once_adapter_shim(actual_kind, requested_kind) {
Ok(true) => fn_once_adapter_instance(scx.tcx(), def_id, substs), Ok(true) => fn_once_adapter_instance(tcx, def_id, substs),
_ => Instance::new(def_id, substs.substs) _ => Instance::new(def_id, substs.substs)
} }
} }
fn resolve_associated_item<'a, 'tcx>( fn resolve_associated_item<'a, 'tcx>(
scx: &SharedCrateContext<'a, 'tcx>, tcx: TyCtxt<'a, 'tcx, 'tcx>,
trait_item: &ty::AssociatedItem, trait_item: &ty::AssociatedItem,
trait_id: DefId, trait_id: DefId,
rcvr_substs: &'tcx Substs<'tcx> rcvr_substs: &'tcx Substs<'tcx>
) -> Instance<'tcx> { ) -> Instance<'tcx> {
let tcx = scx.tcx();
let def_id = trait_item.def_id; let def_id = trait_item.def_id;
debug!("resolve_associated_item(trait_item={:?}, \ debug!("resolve_associated_item(trait_item={:?}, \
trait_id={:?}, \ trait_id={:?}, \
@ -132,7 +131,7 @@ fn resolve_associated_item<'a, 'tcx>(
} }
traits::VtableClosure(closure_data) => { traits::VtableClosure(closure_data) => {
let trait_closure_kind = tcx.lang_items().fn_trait_kind(trait_id).unwrap(); let trait_closure_kind = tcx.lang_items().fn_trait_kind(trait_id).unwrap();
resolve_closure(scx, closure_data.closure_def_id, closure_data.substs, resolve_closure(tcx, closure_data.closure_def_id, closure_data.substs,
trait_closure_kind) trait_closure_kind)
} }
traits::VtableFnPointer(ref data) => { traits::VtableFnPointer(ref data) => {
@ -163,21 +162,21 @@ fn resolve_associated_item<'a, 'tcx>(
/// The point where linking happens. Resolve a (def_id, substs) /// The point where linking happens. Resolve a (def_id, substs)
/// pair to an instance. /// pair to an instance.
pub fn resolve<'a, 'tcx>( pub fn resolve<'a, 'tcx>(
scx: &SharedCrateContext<'a, 'tcx>, tcx: TyCtxt<'a, 'tcx, 'tcx>,
def_id: DefId, def_id: DefId,
substs: &'tcx Substs<'tcx> substs: &'tcx Substs<'tcx>
) -> Instance<'tcx> { ) -> Instance<'tcx> {
debug!("resolve(def_id={:?}, substs={:?})", debug!("resolve(def_id={:?}, substs={:?})",
def_id, substs); def_id, substs);
let result = if let Some(trait_def_id) = scx.tcx().trait_of_item(def_id) { let result = if let Some(trait_def_id) = tcx.trait_of_item(def_id) {
debug!(" => associated item, attempting to find impl"); debug!(" => associated item, attempting to find impl");
let item = scx.tcx().associated_item(def_id); let item = tcx.associated_item(def_id);
resolve_associated_item(scx, &item, trait_def_id, substs) resolve_associated_item(tcx, &item, trait_def_id, substs)
} else { } else {
let item_type = def_ty(scx, def_id, substs); let item_type = def_ty(tcx, def_id, substs);
let def = match item_type.sty { let def = match item_type.sty {
ty::TyFnDef(..) if { ty::TyFnDef(..) if {
let f = item_type.fn_sig(scx.tcx()); let f = item_type.fn_sig(tcx);
f.abi() == Abi::RustIntrinsic || f.abi() == Abi::RustIntrinsic ||
f.abi() == Abi::PlatformIntrinsic f.abi() == Abi::PlatformIntrinsic
} => } =>
@ -186,9 +185,9 @@ pub fn resolve<'a, 'tcx>(
ty::InstanceDef::Intrinsic(def_id) ty::InstanceDef::Intrinsic(def_id)
} }
_ => { _ => {
if Some(def_id) == scx.tcx().lang_items().drop_in_place_fn() { if Some(def_id) == tcx.lang_items().drop_in_place_fn() {
let ty = substs.type_at(0); let ty = substs.type_at(0);
if scx.type_needs_drop(ty) { if common::type_needs_drop(tcx, ty) {
debug!(" => nontrivial drop glue"); debug!(" => nontrivial drop glue");
ty::InstanceDef::DropGlue(def_id, Some(ty)) ty::InstanceDef::DropGlue(def_id, Some(ty))
} else { } else {
@ -209,27 +208,27 @@ pub fn resolve<'a, 'tcx>(
} }
pub fn resolve_drop_in_place<'a, 'tcx>( pub fn resolve_drop_in_place<'a, 'tcx>(
scx: &SharedCrateContext<'a, 'tcx>, tcx: TyCtxt<'a, 'tcx, 'tcx>,
ty: Ty<'tcx>) ty: Ty<'tcx>)
-> ty::Instance<'tcx> -> ty::Instance<'tcx>
{ {
let def_id = scx.tcx().require_lang_item(DropInPlaceFnLangItem); let def_id = tcx.require_lang_item(DropInPlaceFnLangItem);
let substs = scx.tcx().intern_substs(&[Kind::from(ty)]); let substs = tcx.intern_substs(&[Kind::from(ty)]);
resolve(scx, def_id, substs) resolve(tcx, def_id, substs)
} }
pub fn custom_coerce_unsize_info<'scx, 'tcx>(scx: &SharedCrateContext<'scx, 'tcx>, pub fn custom_coerce_unsize_info<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
source_ty: Ty<'tcx>, source_ty: Ty<'tcx>,
target_ty: Ty<'tcx>) target_ty: Ty<'tcx>)
-> CustomCoerceUnsized { -> CustomCoerceUnsized {
let trait_ref = ty::Binder(ty::TraitRef { let trait_ref = ty::Binder(ty::TraitRef {
def_id: scx.tcx().lang_items().coerce_unsized_trait().unwrap(), def_id: tcx.lang_items().coerce_unsized_trait().unwrap(),
substs: scx.tcx().mk_substs_trait(source_ty, &[target_ty]) substs: tcx.mk_substs_trait(source_ty, &[target_ty])
}); });
match scx.tcx().trans_fulfill_obligation(DUMMY_SP, trait_ref) { match tcx.trans_fulfill_obligation(DUMMY_SP, trait_ref) {
traits::VtableImpl(traits::VtableImplData { impl_def_id, .. }) => { traits::VtableImpl(traits::VtableImplData { impl_def_id, .. }) => {
scx.tcx().coerce_unsized_info(impl_def_id).custom_kind.unwrap() tcx.coerce_unsized_info(impl_def_id).custom_kind.unwrap()
} }
vtable => { vtable => {
bug!("invalid CoerceUnsized vtable: {:?}", vtable); bug!("invalid CoerceUnsized vtable: {:?}", vtable);

View file

@ -621,7 +621,7 @@ fn characteristic_def_id_of_trans_item<'a, 'tcx>(scx: &SharedCrateContext<'a, 't
if let Some(impl_def_id) = tcx.impl_of_method(def_id) { if let Some(impl_def_id) = tcx.impl_of_method(def_id) {
// This is a method within an inherent impl, find out what the // This is a method within an inherent impl, find out what the
// self-type is: // self-type is:
let impl_self_ty = common::def_ty(scx, impl_def_id, instance.substs); let impl_self_ty = common::def_ty(scx.tcx(), impl_def_id, instance.substs);
if let Some(def_id) = characteristic_def_id_of_type(impl_self_ty) { if let Some(def_id) = characteristic_def_id_of_type(impl_self_ty) {
return Some(def_id); return Some(def_id);
} }

View file

@ -133,7 +133,7 @@ impl<'a, 'tcx> TransItem<'tcx> {
symbol_name: &str) { symbol_name: &str) {
let def_id = ccx.tcx().hir.local_def_id(node_id); let def_id = ccx.tcx().hir.local_def_id(node_id);
let instance = Instance::mono(ccx.tcx(), def_id); let instance = Instance::mono(ccx.tcx(), def_id);
let ty = common::instance_ty(ccx.shared(), &instance); let ty = common::instance_ty(ccx.tcx(), &instance);
let llty = type_of::type_of(ccx, ty); let llty = type_of::type_of(ccx, ty);
let g = declare::define_global(ccx, symbol_name, llty).unwrap_or_else(|| { let g = declare::define_global(ccx, symbol_name, llty).unwrap_or_else(|| {
@ -158,7 +158,7 @@ impl<'a, 'tcx> TransItem<'tcx> {
assert!(!instance.substs.needs_infer() && assert!(!instance.substs.needs_infer() &&
!instance.substs.has_param_types()); !instance.substs.has_param_types());
let mono_ty = common::instance_ty(ccx.shared(), &instance); let mono_ty = common::instance_ty(ccx.tcx(), &instance);
let attrs = instance.def.attrs(ccx.tcx()); let attrs = instance.def.attrs(ccx.tcx());
let lldecl = declare::declare_fn(ccx, symbol_name, mono_ty); let lldecl = declare::declare_fn(ccx, symbol_name, mono_ty);
unsafe { llvm::LLVMRustSetLinkage(lldecl, linkage) }; unsafe { llvm::LLVMRustSetLinkage(lldecl, linkage) };