remove overzealous Box<ZeroSizeType> optimization

This commit is contained in:
Douglas Campos 2017-09-13 17:48:33 -04:00
parent 539f2083de
commit 916ccc58ac
2 changed files with 2 additions and 40 deletions

View File

@ -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: {:?}",

View File

@ -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 {