rustc_metadata: move is_extern_item to trans.

This commit is contained in:
Eduard Burtescu 2016-10-25 18:18:17 +03:00
parent affc3b7552
commit 3fb24c18ab
4 changed files with 16 additions and 34 deletions

View File

@ -165,7 +165,6 @@ pub trait CrateStore<'tcx> {
fn is_const_fn(&self, did: DefId) -> bool;
fn is_defaulted_trait(&self, did: DefId) -> bool;
fn is_default_impl(&self, impl_did: DefId) -> bool;
fn is_extern_item<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, did: DefId) -> bool;
fn is_foreign_item(&self, did: DefId) -> bool;
fn is_statically_included_foreign_item(&self, id: ast::NodeId) -> bool;
@ -334,8 +333,6 @@ impl<'tcx> CrateStore<'tcx> for DummyCrateStore {
fn is_const_fn(&self, did: DefId) -> bool { bug!("is_const_fn") }
fn is_defaulted_trait(&self, did: DefId) -> bool { bug!("is_defaulted_trait") }
fn is_default_impl(&self, impl_did: DefId) -> bool { bug!("is_default_impl") }
fn is_extern_item<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, did: DefId) -> bool
{ bug!("is_extern_item") }
fn is_foreign_item(&self, did: DefId) -> bool { bug!("is_foreign_item") }
fn is_statically_included_foreign_item(&self, id: ast::NodeId) -> bool { false }

View File

@ -207,11 +207,6 @@ impl<'tcx> CrateStore<'tcx> for cstore::CStore {
self.get_crate_data(impl_did.krate).is_default_impl(impl_did.index)
}
fn is_extern_item<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, did: DefId) -> bool {
self.dep_graph.read(DepNode::MetaData(did));
self.get_crate_data(did.krate).is_extern_item(did.index, tcx)
}
fn is_foreign_item(&self, did: DefId) -> bool {
self.get_crate_data(did.krate).is_foreign_item(did.index)
}

View File

@ -1009,30 +1009,6 @@ impl<'a, 'tcx> CrateMetadata {
constness == hir::Constness::Const
}
pub fn is_extern_item(&self, id: DefIndex, tcx: TyCtxt<'a, 'tcx, 'tcx>) -> bool {
let item = match self.maybe_entry(id) {
Some(item) => item.decode(self),
None => return false,
};
let applicable = match item.kind {
EntryKind::ImmStatic |
EntryKind::MutStatic |
EntryKind::ForeignImmStatic |
EntryKind::ForeignMutStatic => true,
EntryKind::Fn(_) |
EntryKind::ForeignFn(_) => self.get_generics(id, tcx).types.is_empty(),
_ => false,
};
if applicable {
attr::contains_extern_indicator(tcx.sess.diagnostic(), &self.get_attributes(&item))
} else {
false
}
}
pub fn is_foreign_item(&self, id: DefIndex) -> bool {
match self.entry(id).kind {
EntryKind::ForeignImmStatic |

View File

@ -35,6 +35,7 @@ use back::link;
use back::linker::LinkerInfo;
use llvm::{Linkage, ValueRef, Vector, get_param};
use llvm;
use rustc::hir::def::Def;
use rustc::hir::def_id::DefId;
use middle::lang_items::{LangItem, ExchangeMallocFnLangItem, StartFnLangItem};
use rustc::ty::subst::Substs;
@ -1716,8 +1717,21 @@ pub fn trans_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
// `reachable_symbols` list later on so it should be ok.
for cnum in sess.cstore.crates() {
let syms = sess.cstore.reachable_ids(cnum);
reachable_symbols.extend(syms.into_iter().filter(|did| {
sess.cstore.is_extern_item(shared_ccx.tcx(), *did)
reachable_symbols.extend(syms.into_iter().filter(|&def_id| {
let applicable = match sess.cstore.describe_def(def_id) {
Some(Def::Static(..)) => true,
Some(Def::Fn(_)) => {
shared_ccx.tcx().lookup_generics(def_id).types.is_empty()
}
_ => false
};
if applicable {
let attrs = shared_ccx.tcx().get_attrs(def_id);
attr::contains_extern_indicator(sess.diagnostic(), &attrs)
} else {
false
}
}).map(|did| {
symbol_for_def_id(did, &shared_ccx, &symbol_map)
}));