-// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
+// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
use syntax::ast_util::{local_def, PostExpansionMethod};
use syntax::ast_util;
-pub fn maybe_instantiate_inline(ccx: &CrateContext, fn_id: ast::DefId)
- -> ast::DefId {
+fn instantiate_inline(ccx: &CrateContext, fn_id: ast::DefId)
+ -> Option<ast::DefId> {
let _icx = push_ctxt("maybe_instantiate_inline");
match ccx.external().borrow().find(&fn_id) {
Some(&Some(node_id)) => {
// Already inline
debug!("maybe_instantiate_inline({}): already inline as node id {}",
ty::item_path_str(ccx.tcx(), fn_id), node_id);
- return local_def(node_id);
+ return Some(local_def(node_id));
}
Some(&None) => {
- return fn_id; // Not inlinable
+ return None; // Not inlinable
}
None => {
// Not seen yet
csearch::maybe_get_item_ast(
ccx.tcx(), fn_id,
|a,b,c,d| astencode::decode_inlined_item(a, b, c, d));
- return match csearch_result {
+
+ let inline_def = match csearch_result {
csearch::not_found => {
ccx.external().borrow_mut().insert(fn_id, None);
- fn_id
+ return None;
}
- csearch::found(ast::IIItem(item)) => {
+ csearch::found(&ast::IIItem(ref item)) => {
ccx.external().borrow_mut().insert(fn_id, Some(item.id));
ccx.external_srcs().borrow_mut().insert(item.id, fn_id);
ccx.stats().n_inlines.set(ccx.stats().n_inlines.get() + 1);
- trans_item(ccx, &*item);
+ trans_item(ccx, &**item);
let linkage = match item.node {
ast::ItemFn(_, _, _, ref generics, _) => {
local_def(item.id)
}
- csearch::found(ast::IIForeign(item)) => {
+ csearch::found(&ast::IIForeign(ref item)) => {
ccx.external().borrow_mut().insert(fn_id, Some(item.id));
ccx.external_srcs().borrow_mut().insert(item.id, fn_id);
local_def(item.id)
}
- csearch::found_parent(parent_id, ast::IIItem(item)) => {
+ csearch::found_parent(parent_id, &ast::IIItem(ref item)) => {
ccx.external().borrow_mut().insert(parent_id, Some(item.id));
ccx.external_srcs().borrow_mut().insert(item.id, parent_id);
_ => ccx.sess().bug("maybe_instantiate_inline: item has a \
non-enum, non-struct parent")
}
- trans_item(ccx, &*item);
+ trans_item(ccx, &**item);
local_def(my_id)
}
csearch::found_parent(_, _) => {
ccx.sess().bug("maybe_get_item_ast returned a found_parent \
with a non-item parent");
}
- csearch::found(ast::IITraitItem(impl_did, impl_item)) => {
- match impl_item {
- ast::ProvidedInlinedTraitItem(mth) |
- ast::RequiredInlinedTraitItem(mth) => {
+ csearch::found(&ast::IITraitItem(_, ref trait_item)) => {
+ match *trait_item {
+ ast::RequiredMethod(_) => ccx.sess().bug("found RequiredMethod IITraitItem"),
+ ast::ProvidedMethod(ref mth) => {
ccx.external().borrow_mut().insert(fn_id, Some(mth.id));
ccx.external_srcs().borrow_mut().insert(mth.id, fn_id);
ccx.stats().n_inlines.set(ccx.stats().n_inlines.get() + 1);
- }
- }
- match impl_item {
- ast::ProvidedInlinedTraitItem(mth) => {
// If this is a default method, we can't look up the
// impl type. But we aren't going to translate anyways, so
// don't.
local_def(mth.id)
}
- ast::RequiredInlinedTraitItem(mth) => {
+ ast::TypeTraitItem(_) => {
+ ccx.sess().bug("found TypeTraitItem IITraitItem")
+ }
+ }
+ }
+ csearch::found(&ast::IIImplItem(impl_did, ref impl_item)) => {
+ match *impl_item {
+ ast::MethodImplItem(ref mth) => {
+ ccx.external().borrow_mut().insert(fn_id, Some(mth.id));
+ ccx.external_srcs().borrow_mut().insert(mth.id, fn_id);
+
+ ccx.stats().n_inlines.set(ccx.stats().n_inlines.get() + 1);
+
let impl_tpt = ty::lookup_item_type(ccx.tcx(), impl_did);
let unparameterized = impl_tpt.generics.types.is_empty() &&
mth.pe_generics().ty_params.is_empty();
}
local_def(mth.id)
}
+ ast::TypeImplItem(_) => {
+ ccx.sess().bug("found TypeImplItem IIImplItem")
+ }
}
}
};
+
+ return Some(inline_def);
+}
+
+pub fn get_local_instance(ccx: &CrateContext, fn_id: ast::DefId)
+ -> Option<ast::DefId> {
+ if fn_id.krate == ast::LOCAL_CRATE {
+ Some(fn_id)
+ } else {
+ instantiate_inline(ccx, fn_id)
+ }
+}
+
+pub fn maybe_instantiate_inline(ccx: &CrateContext, fn_id: ast::DefId) -> ast::DefId {
+ get_local_instance(ccx, fn_id).unwrap_or(fn_id)
}