Skip to content

Commit 1238266

Browse files
authored
Auto merge of #37401 - eddyb:lazy-2, r=nikomatsakis
[2/n] rustc_metadata: move is_extern_item to trans. *This is part of a series ([prev](#37400) | [next](#37402)) of patches designed to rework rustc into an out-of-order on-demand pipeline model for both better feature support (e.g. [MIR-based](https://github.com/solson/miri) early constant evaluation) and incremental execution of compiler passes (e.g. type-checking), with beneficial consequences to IDE support as well. If any motivation is unclear, please ask for additional PR description clarifications or code comments.* <hr> Minor cleanup missed by #36551: `is_extern_item` is one of, if not the only `CrateStore` method who takes a `TyCtxt` but doesn't produce something cached in it, and such methods are going away.
2 parents ef6f743 + 3fb24c1 commit 1238266

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
@@ -164,7 +164,6 @@ pub trait CrateStore<'tcx> {
164164
fn is_const_fn(&self, did: DefId) -> bool;
165165
fn is_defaulted_trait(&self, did: DefId) -> bool;
166166
fn is_default_impl(&self, impl_did: DefId) -> bool;
167-
fn is_extern_item<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, did: DefId) -> bool;
168167
fn is_foreign_item(&self, did: DefId) -> bool;
169168
fn is_statically_included_foreign_item(&self, id: ast::NodeId) -> bool;
170169

@@ -331,8 +330,6 @@ impl<'tcx> CrateStore<'tcx> for DummyCrateStore {
331330
fn is_const_fn(&self, did: DefId) -> bool { bug!("is_const_fn") }
332331
fn is_defaulted_trait(&self, did: DefId) -> bool { bug!("is_defaulted_trait") }
333332
fn is_default_impl(&self, impl_did: DefId) -> bool { bug!("is_default_impl") }
334-
fn is_extern_item<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, did: DefId) -> bool
335-
{ bug!("is_extern_item") }
336333
fn is_foreign_item(&self, did: DefId) -> bool { bug!("is_foreign_item") }
337334
fn is_statically_included_foreign_item(&self, id: ast::NodeId) -> bool { false }
338335

src/librustc_metadata/cstore_impl.rs

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

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

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;
@@ -1712,8 +1713,21 @@ pub fn trans_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
17121713
// `reachable_symbols` list later on so it should be ok.
17131714
for cnum in sess.cstore.crates() {
17141715
let syms = sess.cstore.reachable_ids(cnum);
1715-
reachable_symbols.extend(syms.into_iter().filter(|did| {
1716-
sess.cstore.is_extern_item(shared_ccx.tcx(), *did)
1716+
reachable_symbols.extend(syms.into_iter().filter(|&def_id| {
1717+
let applicable = match sess.cstore.describe_def(def_id) {
1718+
Some(Def::Static(..)) => true,
1719+
Some(Def::Fn(_)) => {
1720+
shared_ccx.tcx().lookup_generics(def_id).types.is_empty()
1721+
}
1722+
_ => false
1723+
};
1724+
1725+
if applicable {
1726+
let attrs = shared_ccx.tcx().get_attrs(def_id);
1727+
attr::contains_extern_indicator(sess.diagnostic(), &attrs)
1728+
} else {
1729+
false
1730+
}
17171731
}).map(|did| {
17181732
symbol_for_def_id(did, &shared_ccx, &symbol_map)
17191733
}));

0 commit comments

Comments
 (0)