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](https://github.com/rust-lang/rust/pull/37400) | [next](https://github.com/rust-lang/rust/pull/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.
This commit is contained in:
commit
12382665a9
@ -164,7 +164,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;
|
||||
|
||||
@ -331,8 +330,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 }
|
||||
|
||||
|
@ -206,11 +206,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)
|
||||
}
|
||||
|
@ -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 |
|
||||
|
@ -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;
|
||||
@ -1712,8 +1713,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)
|
||||
}));
|
||||
|
Loading…
x
Reference in New Issue
Block a user