Remove extra lang item, exchange_free; use box_free instead.
Trans used to insert code equivalent to box_free in a wrapper around exchange_free, and that code is now removed from trans.
This commit is contained in:
@@ -144,6 +144,7 @@ unsafe fn exchange_malloc(size: usize, align: usize) -> *mut u8 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(test))]
|
#[cfg(not(test))]
|
||||||
|
#[cfg(stage0)]
|
||||||
#[lang = "exchange_free"]
|
#[lang = "exchange_free"]
|
||||||
#[inline]
|
#[inline]
|
||||||
unsafe fn exchange_free(ptr: *mut u8, old_size: usize, align: usize) {
|
unsafe fn exchange_free(ptr: *mut u8, old_size: usize, align: usize) {
|
||||||
|
|||||||
@@ -328,7 +328,6 @@ language_item_table! {
|
|||||||
PanicFmtLangItem, "panic_fmt", panic_fmt;
|
PanicFmtLangItem, "panic_fmt", panic_fmt;
|
||||||
|
|
||||||
ExchangeMallocFnLangItem, "exchange_malloc", exchange_malloc_fn;
|
ExchangeMallocFnLangItem, "exchange_malloc", exchange_malloc_fn;
|
||||||
ExchangeFreeFnLangItem, "exchange_free", exchange_free_fn;
|
|
||||||
BoxFreeFnLangItem, "box_free", box_free_fn;
|
BoxFreeFnLangItem, "box_free", box_free_fn;
|
||||||
StrDupUniqFnLangItem, "strdup_uniq", strdup_uniq_fn;
|
StrDupUniqFnLangItem, "strdup_uniq", strdup_uniq_fn;
|
||||||
|
|
||||||
|
|||||||
@@ -193,9 +193,9 @@ use rustc::hir::itemlikevisit::ItemLikeVisitor;
|
|||||||
|
|
||||||
use rustc::hir::map as hir_map;
|
use rustc::hir::map as hir_map;
|
||||||
use rustc::hir::def_id::DefId;
|
use rustc::hir::def_id::DefId;
|
||||||
use rustc::middle::lang_items::{ExchangeFreeFnLangItem, ExchangeMallocFnLangItem};
|
use rustc::middle::lang_items::{BoxFreeFnLangItem, ExchangeMallocFnLangItem};
|
||||||
use rustc::traits;
|
use rustc::traits;
|
||||||
use rustc::ty::subst::{Substs, Subst};
|
use rustc::ty::subst::{Kind, Substs, Subst};
|
||||||
use rustc::ty::{self, TypeFoldable, TyCtxt};
|
use rustc::ty::{self, TypeFoldable, TyCtxt};
|
||||||
use rustc::ty::adjustment::CustomCoerceUnsized;
|
use rustc::ty::adjustment::CustomCoerceUnsized;
|
||||||
use rustc::mir::{self, Location};
|
use rustc::mir::{self, Location};
|
||||||
@@ -215,6 +215,8 @@ use util::nodemap::{FxHashSet, FxHashMap, DefIdMap};
|
|||||||
|
|
||||||
use trans_item::{TransItem, DefPathBasedNames};
|
use trans_item::{TransItem, DefPathBasedNames};
|
||||||
|
|
||||||
|
use std::iter;
|
||||||
|
|
||||||
#[derive(PartialEq, Eq, Hash, Clone, Copy, Debug)]
|
#[derive(PartialEq, Eq, Hash, Clone, Copy, Debug)]
|
||||||
pub enum TransItemCollectionMode {
|
pub enum TransItemCollectionMode {
|
||||||
Eager,
|
Eager,
|
||||||
@@ -723,23 +725,17 @@ fn find_drop_glue_neighbors<'a, 'tcx>(scx: &SharedCrateContext<'a, 'tcx>,
|
|||||||
|
|
||||||
debug!("find_drop_glue_neighbors: {}", type_to_string(scx.tcx(), ty));
|
debug!("find_drop_glue_neighbors: {}", type_to_string(scx.tcx(), ty));
|
||||||
|
|
||||||
// Make sure the exchange_free_fn() lang-item gets translated if
|
// Make sure the BoxFreeFn lang-item gets translated if there is a boxed value.
|
||||||
// there is a boxed value.
|
if let ty::TyBox(content_type) = ty.sty {
|
||||||
if let ty::TyBox(_) = ty.sty {
|
let def_id = scx.tcx().require_lang_item(BoxFreeFnLangItem);
|
||||||
let exchange_free_fn_def_id = scx.tcx()
|
assert!(can_have_local_instance(scx.tcx(), def_id));
|
||||||
.lang_items
|
let box_free_fn_trans_item =
|
||||||
.require(ExchangeFreeFnLangItem)
|
|
||||||
.unwrap_or_else(|e| scx.sess().fatal(&e));
|
|
||||||
|
|
||||||
assert!(can_have_local_instance(scx.tcx(), exchange_free_fn_def_id));
|
|
||||||
let fn_substs = scx.empty_substs_for_def_id(exchange_free_fn_def_id);
|
|
||||||
let exchange_free_fn_trans_item =
|
|
||||||
create_fn_trans_item(scx,
|
create_fn_trans_item(scx,
|
||||||
exchange_free_fn_def_id,
|
def_id,
|
||||||
fn_substs,
|
scx.tcx().mk_substs(iter::once(Kind::from(content_type))),
|
||||||
scx.tcx().intern_substs(&[]));
|
scx.tcx().intern_substs(&[]));
|
||||||
|
|
||||||
output.push(exchange_free_fn_trans_item);
|
output.push(box_free_fn_trans_item);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the type implements Drop, also add a translation item for the
|
// If the type implements Drop, also add a translation item for the
|
||||||
|
|||||||
@@ -13,13 +13,15 @@
|
|||||||
// Code relating to drop glue.
|
// Code relating to drop glue.
|
||||||
|
|
||||||
use std;
|
use std;
|
||||||
|
use std::iter;
|
||||||
|
|
||||||
use llvm;
|
use llvm;
|
||||||
use llvm::{ValueRef, get_param};
|
use llvm::{ValueRef, get_param};
|
||||||
use middle::lang_items::ExchangeFreeFnLangItem;
|
use middle::lang_items::BoxFreeFnLangItem;
|
||||||
use rustc::ty::subst::{Substs};
|
use rustc::ty::subst::{Substs};
|
||||||
use rustc::traits;
|
use rustc::traits;
|
||||||
use rustc::ty::{self, AdtKind, Ty, TypeFoldable};
|
use rustc::ty::{self, AdtKind, Ty, TypeFoldable};
|
||||||
|
use rustc::ty::subst::Kind;
|
||||||
use adt::{self, MaybeSizedValue};
|
use adt::{self, MaybeSizedValue};
|
||||||
use base::*;
|
use base::*;
|
||||||
use callee::Callee;
|
use callee::Callee;
|
||||||
@@ -36,36 +38,20 @@ use cleanup::CleanupScope;
|
|||||||
|
|
||||||
use syntax_pos::DUMMY_SP;
|
use syntax_pos::DUMMY_SP;
|
||||||
|
|
||||||
pub fn trans_exchange_free_dyn<'a, 'tcx>(
|
|
||||||
bcx: &BlockAndBuilder<'a, 'tcx>,
|
|
||||||
v: ValueRef,
|
|
||||||
size: ValueRef,
|
|
||||||
align: ValueRef
|
|
||||||
) {
|
|
||||||
let def_id = langcall(bcx.tcx(), None, "", ExchangeFreeFnLangItem);
|
|
||||||
let args = [bcx.pointercast(v, Type::i8p(bcx.ccx)), size, align];
|
|
||||||
let callee = Callee::def(bcx.ccx, def_id, bcx.tcx().intern_substs(&[]));
|
|
||||||
|
|
||||||
let ccx = bcx.ccx;
|
|
||||||
let fn_ty = callee.direct_fn_type(ccx, &[]);
|
|
||||||
|
|
||||||
let llret = bcx.call(callee.reify(ccx), &args[..], None);
|
|
||||||
fn_ty.apply_attrs_callsite(llret);
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn trans_exchange_free_ty<'a, 'tcx>(
|
pub fn trans_exchange_free_ty<'a, 'tcx>(
|
||||||
bcx: &BlockAndBuilder<'a, 'tcx>, ptr: ValueRef, content_ty: Ty<'tcx>
|
bcx: &BlockAndBuilder<'a, 'tcx>,
|
||||||
|
ptr: MaybeSizedValue,
|
||||||
|
content_ty: Ty<'tcx>
|
||||||
) {
|
) {
|
||||||
assert!(bcx.ccx.shared().type_is_sized(content_ty));
|
let def_id = langcall(bcx.tcx(), None, "", BoxFreeFnLangItem);
|
||||||
let sizing_type = sizing_type_of(bcx.ccx, content_ty);
|
let substs = bcx.tcx().mk_substs(iter::once(Kind::from(content_ty)));
|
||||||
let content_size = llsize_of_alloc(bcx.ccx, sizing_type);
|
let callee = Callee::def(bcx.ccx, def_id, substs);
|
||||||
|
|
||||||
// `Box<ZeroSizeType>` does not allocate.
|
let fn_ty = callee.direct_fn_type(bcx.ccx, &[]);
|
||||||
if content_size != 0 {
|
|
||||||
let content_align = align_of(bcx.ccx, content_ty);
|
let llret = bcx.call(callee.reify(bcx.ccx),
|
||||||
let ccx = bcx.ccx;
|
&[ptr.value, ptr.meta][..1 + ptr.has_meta() as usize], None);
|
||||||
trans_exchange_free_dyn(bcx, ptr, C_uint(ccx, content_size), C_uint(ccx, content_align));
|
fn_ty.apply_attrs_callsite(llret);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_drop_glue_type<'a, 'tcx>(scx: &SharedCrateContext<'a, 'tcx>, t: Ty<'tcx>) -> Ty<'tcx> {
|
pub fn get_drop_glue_type<'a, 'tcx>(scx: &SharedCrateContext<'a, 'tcx>, t: Ty<'tcx>) -> Ty<'tcx> {
|
||||||
@@ -224,30 +210,16 @@ pub fn implement_drop_glue<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, g: DropGlueKi
|
|||||||
// special. It may move to library and have Drop impl. As
|
// special. It may move to library and have Drop impl. As
|
||||||
// a safe-guard, assert TyBox not used with TyContents.
|
// a safe-guard, assert TyBox not used with TyContents.
|
||||||
assert!(!skip_dtor);
|
assert!(!skip_dtor);
|
||||||
if !bcx.ccx.shared().type_is_sized(content_ty) {
|
let ptr = if !bcx.ccx.shared().type_is_sized(content_ty) {
|
||||||
let llbox = bcx.load(get_dataptr(&bcx, ptr.value));
|
let llbox = bcx.load(get_dataptr(&bcx, ptr.value));
|
||||||
let info = bcx.load(get_meta(&bcx, ptr.value));
|
let info = bcx.load(get_meta(&bcx, ptr.value));
|
||||||
drop_ty(&bcx, MaybeSizedValue::unsized_(llbox, info), content_ty);
|
MaybeSizedValue::unsized_(llbox, info)
|
||||||
let (llsize, llalign) = size_and_align_of_dst(&bcx, content_ty, info);
|
|
||||||
|
|
||||||
// `Box<ZeroSizeType>` does not allocate.
|
|
||||||
let needs_free = bcx.icmp(llvm::IntNE, llsize, C_uint(bcx.ccx, 0u64));
|
|
||||||
if const_to_opt_uint(needs_free) == Some(0) {
|
|
||||||
bcx
|
|
||||||
} else {
|
|
||||||
let next_cx = bcx.fcx().build_new_block("next");
|
|
||||||
let cond_cx = bcx.fcx().build_new_block("cond");
|
|
||||||
bcx.cond_br(needs_free, cond_cx.llbb(), next_cx.llbb());
|
|
||||||
trans_exchange_free_dyn(&cond_cx, llbox, llsize, llalign);
|
|
||||||
cond_cx.br(next_cx.llbb());
|
|
||||||
next_cx
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
let llbox = bcx.load(ptr.value);
|
MaybeSizedValue::sized(bcx.load(ptr.value))
|
||||||
drop_ty(&bcx, MaybeSizedValue::sized(llbox), content_ty);
|
};
|
||||||
trans_exchange_free_ty(&bcx, llbox, content_ty);
|
drop_ty(&bcx, ptr, content_ty);
|
||||||
bcx
|
trans_exchange_free_ty(&bcx, ptr, content_ty);
|
||||||
}
|
bcx
|
||||||
}
|
}
|
||||||
ty::TyDynamic(..) => {
|
ty::TyDynamic(..) => {
|
||||||
// No support in vtable for distinguishing destroying with
|
// No support in vtable for distinguishing destroying with
|
||||||
|
|||||||
Reference in New Issue
Block a user