about summary refs log tree commit diff
diff options
context:
space:
mode:
authorTim Neumann <mail@timnn.me>2017-09-17 13:19:06 +0200
committerGitHub <noreply@github.com>2017-09-17 13:19:06 +0200
commiteab164842a07be9ca578e4a9c679c125250dcaca (patch)
tree015013ae735a3933526f6008980b865e6a6d0517
parentefdcd5efef53dd1fb781d4db7aea8834a8ebaffe (diff)
parent916ccc58ac6b409a9f2f987c46d3d08f89b55097 (diff)
downloadrust-eab164842a07be9ca578e4a9c679c125250dcaca.tar.gz
rust-eab164842a07be9ca578e4a9c679c125250dcaca.zip
Rollup merge of #44553 - qmx:refactor-remove-overzealous-box-szero-optimization, r=arielb1
remove overzealous Box<ZeroSizeType> optimization
-rw-r--r--src/librustc_trans/glue.rs39
-rw-r--r--src/librustc_trans/monomorphize.rs3
2 files changed, 2 insertions, 40 deletions
diff --git a/src/librustc_trans/glue.rs b/src/librustc_trans/glue.rs
index 8dd0b4e466c..39394979713 100644
--- a/src/librustc_trans/glue.rs
+++ b/src/librustc_trans/glue.rs
@@ -16,8 +16,7 @@ use std;
 
 use llvm;
 use llvm::{ValueRef};
-use rustc::traits;
-use rustc::ty::{self, Ty, TypeFoldable};
+use rustc::ty::{self, Ty};
 use rustc::ty::layout::LayoutTyper;
 use common::*;
 use meth;
@@ -25,42 +24,6 @@ use monomorphize;
 use value::Value;
 use builder::Builder;
 
-pub fn needs_drop_glue<'a, 'tcx>(scx: &SharedCrateContext<'a, 'tcx>, t: Ty<'tcx>) -> bool {
-    assert!(t.is_normalized_for_trans());
-
-    let t = scx.tcx().erase_regions(&t);
-
-    // FIXME (#22815): note that type_needs_drop conservatively
-    // approximates in some cases and may say a type expression
-    // requires drop glue when it actually does not.
-    //
-    // (In this case it is not clear whether any harm is done, i.e.
-    // erroneously returning `true` in some cases where we could have
-    // returned `false` does not appear unsound. The impact on
-    // code quality is unknown at this time.)
-
-    if !scx.type_needs_drop(t) {
-        return false;
-    }
-    match t.sty {
-        ty::TyAdt(def, _) if def.is_box() => {
-            let typ = t.boxed_ty();
-            if !scx.type_needs_drop(typ) && scx.type_is_sized(typ) {
-                let layout = t.layout(scx.tcx(), ty::ParamEnv::empty(traits::Reveal::All)).unwrap();
-                if layout.size(scx).bytes() == 0 {
-                    // `Box<ZeroSizeType>` does not allocate.
-                    false
-                } else {
-                    true
-                }
-            } else {
-                true
-            }
-        }
-        _ => true
-    }
-}
-
 pub fn size_and_align_of_dst<'a, 'tcx>(bcx: &Builder<'a, 'tcx>, t: Ty<'tcx>, info: ValueRef)
                                        -> (ValueRef, ValueRef) {
     debug!("calculate size of DST: {}; with lost info: {:?}",
diff --git a/src/librustc_trans/monomorphize.rs b/src/librustc_trans/monomorphize.rs
index 9a7f1524d20..309177d9ff6 100644
--- a/src/librustc_trans/monomorphize.rs
+++ b/src/librustc_trans/monomorphize.rs
@@ -10,7 +10,6 @@
 
 use abi::Abi;
 use common::*;
-use glue;
 
 use rustc::hir::def_id::DefId;
 use rustc::middle::lang_items::DropInPlaceFnLangItem;
@@ -189,7 +188,7 @@ pub fn resolve<'a, 'tcx>(
             _ => {
                 if Some(def_id) == scx.tcx().lang_items().drop_in_place_fn() {
                     let ty = substs.type_at(0);
-                    if glue::needs_drop_glue(scx, ty) {
+                    if scx.type_needs_drop(ty) {
                         debug!(" => nontrivial drop glue");
                         ty::InstanceDef::DropGlue(def_id, Some(ty))
                     } else {