about summary refs log tree commit diff
diff options
context:
space:
mode:
authorOliver Scherer <github35764891676564198441@oli-obk.de>2018-11-17 15:05:12 +0100
committerOliver Scherer <github35764891676564198441@oli-obk.de>2018-11-17 15:05:12 +0100
commitef99b57b13f9ab04f44dd9c5c325be8f0b6b9dc1 (patch)
tree8e6c0bd0abe1236800ed0398e3398102d647d5c7
parent3d33d05c81f949f743b3441cc1e960f2dc2bd5ac (diff)
downloadrust-ef99b57b13f9ab04f44dd9c5c325be8f0b6b9dc1.tar.gz
rust-ef99b57b13f9ab04f44dd9c5c325be8f0b6b9dc1.zip
Refactor local monomorphization logic to be easier to comprehend
-rw-r--r--src/librustc_mir/monomorphize/collector.rs43
1 files changed, 21 insertions, 22 deletions
diff --git a/src/librustc_mir/monomorphize/collector.rs b/src/librustc_mir/monomorphize/collector.rs
index 92318755ff5..977285b27be 100644
--- a/src/librustc_mir/monomorphize/collector.rs
+++ b/src/librustc_mir/monomorphize/collector.rs
@@ -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.
-        }
-        Some(_) => true,
-        None => {
-            if tcx.is_reachable_non_generic(def_id) ||
-                tcx.is_foreign_item(def_id) ||
-                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 {
-                if !tcx.is_mir_available(def_id) {
-                    bug!("Cannot create local mono-item for {:?}", def_id)
-                }
-                true
-            }
-        }
-    };
+    if tcx.is_foreign_item(def_id) {
+        // We can always link to foreign items
+        return false;
+    }
+
+    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) ||
+       is_available_upstream_generic(tcx, def_id, instance.substs) {
+        // We can link to the item in question, no instance needed
+        // in this crate
+        return false;
+    }
+
+    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>,
                                                def_id: DefId,