From 916ccc58ac6b409a9f2f987c46d3d08f89b55097 Mon Sep 17 00:00:00 2001 From: Douglas Campos Date: Wed, 13 Sep 2017 17:48:33 -0400 Subject: [PATCH] remove overzealous Box optimization --- src/librustc_trans/glue.rs | 39 +----------------------------- src/librustc_trans/monomorphize.rs | 3 +-- 2 files changed, 2 insertions(+), 40 deletions(-) diff --git a/src/librustc_trans/glue.rs b/src/librustc_trans/glue.rs index 8dd0b4e466ce4..3939497971337 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` 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 9a7f1524d209f..309177d9ff6a2 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 {