Skip to content

Commit 3fb24c1

Browse files
committed
rustc_metadata: move is_extern_item to trans.
1 parent affc3b7 commit 3fb24c1

File tree

4 files changed

+16
-34
lines changed

4 files changed

+16
-34
lines changed

src/librustc/middle/cstore.rs

-3
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,6 @@ pub trait CrateStore<'tcx> {
165165
fn is_const_fn(&self, did: DefId) -> bool;
166166
fn is_defaulted_trait(&self, did: DefId) -> bool;
167167
fn is_default_impl(&self, impl_did: DefId) -> bool;
168-
fn is_extern_item<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, did: DefId) -> bool;
169168
fn is_foreign_item(&self, did: DefId) -> bool;
170169
fn is_statically_included_foreign_item(&self, id: ast::NodeId) -> bool;
171170

@@ -334,8 +333,6 @@ impl<'tcx> CrateStore<'tcx> for DummyCrateStore {
334333
fn is_const_fn(&self, did: DefId) -> bool { bug!("is_const_fn") }
335334
fn is_defaulted_trait(&self, did: DefId) -> bool { bug!("is_defaulted_trait") }
336335
fn is_default_impl(&self, impl_did: DefId) -> bool { bug!("is_default_impl") }
337-
fn is_extern_item<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, did: DefId) -> bool
338-
{ bug!("is_extern_item") }
339336
fn is_foreign_item(&self, did: DefId) -> bool { bug!("is_foreign_item") }
340337
fn is_statically_included_foreign_item(&self, id: ast::NodeId) -> bool { false }
341338

src/librustc_metadata/cstore_impl.rs

-5
Original file line numberDiff line numberDiff line change
@@ -207,11 +207,6 @@ impl<'tcx> CrateStore<'tcx> for cstore::CStore {
207207
self.get_crate_data(impl_did.krate).is_default_impl(impl_did.index)
208208
}
209209

210-
fn is_extern_item<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, did: DefId) -> bool {
211-
self.dep_graph.read(DepNode::MetaData(did));
212-
self.get_crate_data(did.krate).is_extern_item(did.index, tcx)
213-
}
214-
215210
fn is_foreign_item(&self, did: DefId) -> bool {
216211
self.get_crate_data(did.krate).is_foreign_item(did.index)
217212
}

src/librustc_metadata/decoder.rs

-24
Original file line numberDiff line numberDiff line change
@@ -1009,30 +1009,6 @@ impl<'a, 'tcx> CrateMetadata {
10091009
constness == hir::Constness::Const
10101010
}
10111011

1012-
pub fn is_extern_item(&self, id: DefIndex, tcx: TyCtxt<'a, 'tcx, 'tcx>) -> bool {
1013-
let item = match self.maybe_entry(id) {
1014-
Some(item) => item.decode(self),
1015-
None => return false,
1016-
};
1017-
let applicable = match item.kind {
1018-
EntryKind::ImmStatic |
1019-
EntryKind::MutStatic |
1020-
EntryKind::ForeignImmStatic |
1021-
EntryKind::ForeignMutStatic => true,
1022-
1023-
EntryKind::Fn(_) |
1024-
EntryKind::ForeignFn(_) => self.get_generics(id, tcx).types.is_empty(),
1025-
1026-
_ => false,
1027-
};
1028-
1029-
if applicable {
1030-
attr::contains_extern_indicator(tcx.sess.diagnostic(), &self.get_attributes(&item))
1031-
} else {
1032-
false
1033-
}
1034-
}
1035-
10361012
pub fn is_foreign_item(&self, id: DefIndex) -> bool {
10371013
match self.entry(id).kind {
10381014
EntryKind::ForeignImmStatic |

src/librustc_trans/base.rs

+16-2
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ use back::link;
3535
use back::linker::LinkerInfo;
3636
use llvm::{Linkage, ValueRef, Vector, get_param};
3737
use llvm;
38+
use rustc::hir::def::Def;
3839
use rustc::hir::def_id::DefId;
3940
use middle::lang_items::{LangItem, ExchangeMallocFnLangItem, StartFnLangItem};
4041
use rustc::ty::subst::Substs;
@@ -1716,8 +1717,21 @@ pub fn trans_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
17161717
// `reachable_symbols` list later on so it should be ok.
17171718
for cnum in sess.cstore.crates() {
17181719
let syms = sess.cstore.reachable_ids(cnum);
1719-
reachable_symbols.extend(syms.into_iter().filter(|did| {
1720-
sess.cstore.is_extern_item(shared_ccx.tcx(), *did)
1720+
reachable_symbols.extend(syms.into_iter().filter(|&def_id| {
1721+
let applicable = match sess.cstore.describe_def(def_id) {
1722+
Some(Def::Static(..)) => true,
1723+
Some(Def::Fn(_)) => {
1724+
shared_ccx.tcx().lookup_generics(def_id).types.is_empty()
1725+
}
1726+
_ => false
1727+
};
1728+
1729+
if applicable {
1730+
let attrs = shared_ccx.tcx().get_attrs(def_id);
1731+
attr::contains_extern_indicator(sess.diagnostic(), &attrs)
1732+
} else {
1733+
false
1734+
}
17211735
}).map(|did| {
17221736
symbol_for_def_id(did, &shared_ccx, &symbol_map)
17231737
}));

0 commit comments

Comments
 (0)