1
Fork 0

Refactor local monomorphization logic to be easier to comprehend

This commit is contained in:
Oliver Scherer 2018-11-17 15:05:12 +01:00
parent 3d33d05c81
commit ef99b57b13

View file

@ -187,7 +187,6 @@
use rustc::hir::{self, CodegenFnAttrFlags};
use rustc::hir::itemlikevisit::ItemLikeVisitor;
use rustc::hir::Node;
use rustc::hir::def_id::DefId;
use rustc::mir::interpret::{AllocId, ConstValue};
use rustc::middle::lang_items::{ExchangeMallocFnLangItem, StartFnLangItem};
@ -737,27 +736,27 @@ fn should_monomorphize_locally<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, instance:
ty::InstanceDef::CloneShim(..) => return true
};
return match tcx.hir.get_if_local(def_id) {
Some(Node::ForeignItem(..)) => {
false // foreign items are linked against, not codegened.
if tcx.is_foreign_item(def_id) {
// We can always link to foreign items
return false;
}
Some(_) => true,
None => {
if def_id.is_local() {
// local items cannot be referred to locally without monomorphizing them locally
return true;
}
if tcx.is_reachable_non_generic(def_id) ||
tcx.is_foreign_item(def_id) ||
is_available_upstream_generic(tcx, def_id, instance.substs)
{
is_available_upstream_generic(tcx, def_id, instance.substs) {
// We can link to the item in question, no instance needed
// in this crate
false
} else {
return false;
}
if !tcx.is_mir_available(def_id) {
bug!("Cannot create local mono-item for {:?}", def_id)
}
true
}
}
};
return true;
fn is_available_upstream_generic<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
def_id: DefId,