]> git.lizzy.rs Git - rust.git/commitdiff
Move instance related methods from TyCtxt to Instance
authorMaik Klein <maikklein@googlemail.com>
Fri, 27 Oct 2017 09:27:05 +0000 (11:27 +0200)
committerAriel Ben-Yehuda <ariel.byd@gmail.com>
Mon, 18 Dec 2017 15:08:49 +0000 (17:08 +0200)
src/librustc/ty/instance.rs
src/librustc_mir/monomorphize/item.rs

index 1f505a07dab5f61dd9d9cae0226d825981f29d8f..5259e790e925422000f995626b06bc459c25efaa 100644 (file)
@@ -77,6 +77,42 @@ pub fn def_ty<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>) -> Ty<'tcx> {
     pub fn attrs<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>) -> ty::Attributes<'tcx> {
         tcx.get_attrs(self.def_id())
     }
+
+    pub fn is_inline<'a>(
+        &self,
+        tcx: TyCtxt<'a, 'tcx, 'tcx>
+    ) -> bool {
+        use hir::map::DefPathData;
+        let def_id = match *self {
+            ty::InstanceDef::Item(def_id) => def_id,
+            ty::InstanceDef::DropGlue(_, Some(_)) => return false,
+            _ => return true
+        };
+        match tcx.def_key(def_id).disambiguated_data.data {
+            DefPathData::StructCtor |
+            DefPathData::EnumVariant(..) |
+            DefPathData::ClosureExpr => true,
+            _ => false
+        }
+    }
+
+    pub fn requires_local<'a>(
+        &self,
+        tcx: TyCtxt<'a, 'tcx, 'tcx>
+    ) -> bool {
+        use syntax::attr::requests_inline;
+        if self.is_inline(tcx) {
+            return true
+        }
+        if let ty::InstanceDef::DropGlue(..) = *self {
+            // Drop glue wants to be instantiated at every translation
+            // unit, but without an #[inline] hint. We should make this
+            // available to normal end-users.
+            return true
+        }
+        requests_inline(&self.attrs(tcx)[..]) ||
+            tcx.is_const_fn(self.def_id())
+    }
 }
 
 impl<'tcx> fmt::Display for Instance<'tcx> {
index a81808d8afc18f15090d619d878ed2cc01cbbfd4..72efe23f77bc97eacc120e77eb75464b4690a5f3 100644 (file)
@@ -96,7 +96,7 @@ fn instantiation_mode(&self,
                 // If this function isn't inlined or otherwise has explicit
                 // linkage, then we'll be creating a globally shared version.
                 if self.explicit_linkage(tcx).is_some() ||
-                    !tcx.requires_local_instance(instance)
+                    !instance.def.requires_local(tcx)
                 {
                     return InstantiationMode::GloballyShared  { may_conflict: false }
                 }