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