Skip to content

Commit

Permalink
Auto merge of #37401 - eddyb:lazy-2, r=nikomatsakis
Browse files Browse the repository at this point in the history
[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.
  • Loading branch information
bors committed Oct 30, 2016
2 parents ef6f743 + 3fb24c1 commit 1238266
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 34 deletions.
3 changes: 0 additions & 3 deletions src/librustc/middle/cstore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

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

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

0 comments on commit 1238266

Please sign in to comment.