Skip to content

Commit

Permalink
Rollup merge of rust-lang#44553 - qmx:refactor-remove-overzealous-box…
Browse files Browse the repository at this point in the history
…-szero-optimization, r=arielb1

remove overzealous Box<ZeroSizeType> optimization
  • Loading branch information
TimNN authored Sep 17, 2017
2 parents efdcd5e + 916ccc5 commit eab1648
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 40 deletions.
39 changes: 1 addition & 38 deletions src/librustc_trans/glue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,51 +16,14 @@ 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;
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: {:?}",
Expand Down
3 changes: 1 addition & 2 deletions src/librustc_trans/monomorphize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

use abi::Abi;
use common::*;
use glue;

use rustc::hir::def_id::DefId;
use rustc::middle::lang_items::DropInPlaceFnLangItem;
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit eab1648

Please sign in to comment.