Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[2/n] rustc_metadata: move is_extern_item to trans. #37401

Merged
merged 1 commit into from
Oct 30, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions src/librustc/middle/cstore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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 }

Expand Down
5 changes: 0 additions & 5 deletions src/librustc_metadata/cstore_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
24 changes: 0 additions & 24 deletions src/librustc_metadata/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down
18 changes: 16 additions & 2 deletions src/librustc_trans/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
}));
Expand Down