about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMaik Klein <maikklein@googlemail.com>2017-10-25 17:27:27 +0200
committerAriel Ben-Yehuda <ariel.byd@gmail.com>2017-12-18 17:08:48 +0200
commit531c27d80554e3d0c12a3177d02a4f287e7fc22c (patch)
treeb9e0ce744607665b2ff84143ec7feb1ac1708800
parent98b9eba316025ecd2fb2a2c9716f21813848ff03 (diff)
Move common.rs functionality into TyCtxt
-rw-r--r--src/librustc/ty/instance.rs9
-rw-r--r--src/librustc/ty/mod.rs5
-rw-r--r--src/librustc_mir/monomorphize/collector.rs5
-rw-r--r--src/librustc_mir/monomorphize/common.rs0
-rw-r--r--src/librustc_mir/monomorphize/mono_item.rs3
-rw-r--r--src/librustc_trans_utils/common.rs92
-rw-r--r--src/librustc_trans_utils/lib.rs3
7 files changed, 14 insertions, 103 deletions
diff --git a/src/librustc/ty/instance.rs b/src/librustc/ty/instance.rs
index 61b19227744..1f505a07dab 100644
--- a/src/librustc/ty/instance.rs
+++ b/src/librustc/ty/instance.rs
@@ -45,6 +45,15 @@ pub enum InstanceDef<'tcx> {
     CloneShim(DefId, Ty<'tcx>),
 }
 
+impl<'a, 'tcx> Instance<'tcx> {
+    pub fn ty(&self,
+              tcx: TyCtxt<'a, 'tcx, 'tcx>)
+              -> Ty<'tcx>
+    {
+        self.def.def_ty(tcx).subst(tcx, self.substs)
+    }
+}
+
 impl<'tcx> InstanceDef<'tcx> {
     #[inline]
     pub fn def_id(&self) -> DefId {
diff --git a/src/librustc/ty/mod.rs b/src/librustc/ty/mod.rs
index 76494df97d1..220e1e971ac 100644
--- a/src/librustc/ty/mod.rs
+++ b/src/librustc/ty/mod.rs
@@ -2471,11 +2471,6 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
     }
 }
 
-impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
-    pub fn is_sized(self, ty: Ty<'tcx>) -> bool {
-        ty.is_sized(self, ty::ParamEnv::empty(traits::Reveal::All), DUMMY_SP)
-    }
-}
 impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
     pub fn with_freevars<T, F>(self, fid: NodeId, f: F) -> T where
         F: FnOnce(&[hir::Freevar]) -> T,
diff --git a/src/librustc_mir/monomorphize/collector.rs b/src/librustc_mir/monomorphize/collector.rs
index 3cc0daf398a..a12553740ab 100644
--- a/src/librustc_mir/monomorphize/collector.rs
+++ b/src/librustc_mir/monomorphize/collector.rs
@@ -203,7 +203,6 @@ use rustc::ty::adjustment::CustomCoerceUnsized;
 use rustc::mir::{self, Location};
 use rustc::mir::visit::Visitor as MirVisitor;
 
-use common::{def_ty, instance_ty, type_has_metadata};
 use monomorphize::{self, Instance};
 use rustc::util::nodemap::{FxHashSet, FxHashMap, DefIdMap};
 
@@ -371,7 +370,7 @@ fn collect_items_rec<'a, 'tcx: 'a>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
             // Sanity check whether this ended up being collected accidentally
             debug_assert!(should_trans_locally(tcx, &instance));
 
-            let ty = instance_ty(tcx, &instance);
+            let ty = instance.ty(tcx);
             visit_drop_use(tcx, ty, true, &mut neighbors);
 
             recursion_depth_reset = None;
@@ -916,7 +915,7 @@ impl<'b, 'a, 'v> ItemLikeVisitor<'v> for RootCollector<'b, 'a, 'v> {
                         debug!("RootCollector: ADT drop-glue for {}",
                                def_id_to_string(self.tcx, def_id));
 
-                        let ty = def_ty(self.tcx, def_id, Substs::empty());
+                        let ty = Instance::new(def_id, Substs::empty()).ty(self.tcx);
                         visit_drop_use(self.tcx, ty, true, self.output);
                     }
                 }
diff --git a/src/librustc_mir/monomorphize/common.rs b/src/librustc_mir/monomorphize/common.rs
deleted file mode 100644
index e69de29bb2d..00000000000
--- a/src/librustc_mir/monomorphize/common.rs
+++ /dev/null
diff --git a/src/librustc_mir/monomorphize/mono_item.rs b/src/librustc_mir/monomorphize/mono_item.rs
index a37a6420353..3b449d69e9c 100644
--- a/src/librustc_mir/monomorphize/mono_item.rs
+++ b/src/librustc_mir/monomorphize/mono_item.rs
@@ -14,7 +14,6 @@
 //! item-path. This is used for unit testing the code that generates
 //! paths etc in all kinds of annoying scenarios.
 
-use rustc_trans_utils::common;
 use monomorphize::Instance;
 use rustc::hir;
 use rustc::hir::def_id::DefId;
@@ -98,7 +97,7 @@ pub trait TransItemExt<'a, 'tcx>: fmt::Debug {
                 // 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() ||
-                    !common::requests_inline(tcx, instance)
+                    !tcx.requires_local_instance(instance)
                 {
                     return InstantiationMode::GloballyShared  { may_conflict: false }
                 }
diff --git a/src/librustc_trans_utils/common.rs b/src/librustc_trans_utils/common.rs
deleted file mode 100644
index 47968afd70d..00000000000
--- a/src/librustc_trans_utils/common.rs
+++ /dev/null
@@ -1,92 +0,0 @@
-// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-#![allow(non_camel_case_types, non_snake_case)]
-
-//! Code that is useful in various trans modules.
-
-use rustc::hir::def_id::DefId;
-use rustc::hir::map::DefPathData;
-use rustc::traits;
-use rustc::ty::{self, Ty, TyCtxt};
-use rustc::ty::subst::Substs;
-
-use syntax::attr;
-use syntax_pos::DUMMY_SP;
-
-pub fn type_is_sized<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, ty: Ty<'tcx>) -> bool {
-    ty.is_sized(tcx, ty::ParamEnv::empty(traits::Reveal::All), DUMMY_SP)
-}
-
-pub fn type_has_metadata<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, ty: Ty<'tcx>) -> bool {
-    if type_is_sized(tcx, ty) {
-        return false;
-    }
-
-    let tail = tcx.struct_tail(ty);
-    match tail.sty {
-        ty::TyForeign(..) => false,
-        ty::TyStr | ty::TySlice(..) | ty::TyDynamic(..) => true,
-        _ => bug!("unexpected unsized tail: {:?}", tail.sty),
-    }
-}
-
-pub fn requests_inline<'a, 'tcx>(
-    tcx: TyCtxt<'a, 'tcx, 'tcx>,
-    instance: &ty::Instance<'tcx>
-) -> bool {
-    if is_inline_instance(tcx, instance) {
-        return true
-    }
-    if let ty::InstanceDef::DropGlue(..) = instance.def {
-        // 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
-    }
-    attr::requests_inline(&instance.def.attrs(tcx)[..]) ||
-        tcx.is_const_fn(instance.def.def_id())
-}
-
-pub fn is_inline_instance<'a, 'tcx>(
-    tcx: TyCtxt<'a, 'tcx, 'tcx>,
-    instance: &ty::Instance<'tcx>
-) -> bool {
-    let def_id = match instance.def {
-        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
-    }
-}
-
-/// Given a DefId and some Substs, produces the monomorphic item type.
-pub fn def_ty<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
-                        def_id: DefId,
-                        substs: &'tcx Substs<'tcx>)
-                        -> Ty<'tcx>
-{
-    let ty = tcx.type_of(def_id);
-    tcx.trans_apply_param_substs(substs, &ty)
-}
-
-/// Return the substituted type of an instance.
-pub fn instance_ty<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
-                             instance: &ty::Instance<'tcx>)
-                             -> Ty<'tcx>
-{
-    let ty = instance.def.def_ty(tcx);
-    tcx.trans_apply_param_substs(instance.substs, &ty)
-}
diff --git a/src/librustc_trans_utils/lib.rs b/src/librustc_trans_utils/lib.rs
index 6de8aa76577..9298547e383 100644
--- a/src/librustc_trans_utils/lib.rs
+++ b/src/librustc_trans_utils/lib.rs
@@ -44,7 +44,8 @@ use rustc::hir::def_id::LOCAL_CRATE;
 use rustc::hir::map as hir_map;
 use rustc::util::nodemap::NodeSet;
 
-pub mod common;
+use syntax::attr;
+
 pub mod link;
 pub mod trans_crate;