move the check for instantiation from metadata encoding to the actual decision site

before it was assumed that anything that had a MIR was fair game for local instatiation
This commit is contained in:
Oliver Schneider 2016-12-09 17:29:01 +01:00
parent 910c369c92
commit d74d15345c
No known key found for this signature in database
GPG Key ID: 56D6EEA0FC67AC46
4 changed files with 37 additions and 4 deletions

View File

@ -355,6 +355,11 @@ pub trait CrateStore<'tcx> {
fn get_item_mir<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId) -> Mir<'tcx>;
fn is_item_mir_available(&self, def: DefId) -> bool;
/// Take a look if we need to inline or monomorphize this. If so, we
/// will emit code for this item in the local crate, and thus
/// create a translation item for it.
fn can_have_local_instance<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId) -> bool;
// This is basically a 1-based range of ints, which is a little
// silly - I may fix that.
fn crates(&self) -> Vec<CrateNum>;
@ -528,6 +533,9 @@ impl<'tcx> CrateStore<'tcx> for DummyCrateStore {
fn is_item_mir_available(&self, def: DefId) -> bool {
bug!("is_item_mir_available")
}
fn can_have_local_instance<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId) -> bool {
bug!("can_have_local_instance")
}
// This is basically a 1-based range of ints, which is a little
// silly - I may fix that.

View File

@ -527,6 +527,11 @@ impl<'tcx> CrateStore<'tcx> for cstore::CStore {
self.get_crate_data(def.krate).is_item_mir_available(def.index)
}
fn can_have_local_instance<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId) -> bool {
self.dep_graph.read(DepNode::MetaData(def));
def.is_local() || self.get_crate_data(def.krate).can_have_local_instance(tcx, def.index)
}
fn crates(&self) -> Vec<CrateNum>
{
let mut result = vec![];

View File

@ -847,6 +847,29 @@ impl<'a, 'tcx> CrateMetadata {
self.maybe_entry(id).and_then(|item| item.decode(self).mir).is_some()
}
pub fn can_have_local_instance(&self,
tcx: TyCtxt<'a, 'tcx, 'tcx>,
id: DefIndex) -> bool {
self.maybe_entry(id).map_or(false, |item| {
let item = item.decode(self);
// if we don't have a MIR, then this item was never meant to be locally instantiated
// or we have a bug in the metadata serialization
item.mir.is_some() && (
// items with generics always can have local instances if monomorphized
item.generics.map_or(false, |generics| {
let generics = generics.decode((self, tcx));
generics.parent_types != 0 || !generics.types.is_empty()
}) ||
match item.kind {
EntryKind::Closure(_) => true,
_ => false,
} ||
item.kind.is_const_fn(self) ||
attr::requests_inline(&self.get_attributes(&item))
)
})
}
pub fn maybe_get_item_mir(&self,
tcx: TyCtxt<'a, 'tcx, 'tcx>,
id: DefIndex)

View File

@ -706,10 +706,7 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirNeighborCollector<'a, 'tcx> {
fn can_have_local_instance<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
def_id: DefId)
-> bool {
// Take a look if we have the definition available. If so, we
// will emit code for this item in the local crate, and thus
// create a translation item for it.
def_id.is_local() || tcx.sess.cstore.is_item_mir_available(def_id)
tcx.sess.cstore.can_have_local_instance(tcx, def_id)
}
fn find_drop_glue_neighbors<'a, 'tcx>(scx: &SharedCrateContext<'a, 'tcx>,