parent
404de4f4ae
commit
0cdb0a2189
4 changed files with 4 additions and 125 deletions
|
@ -13,15 +13,12 @@ use back::abi;
|
|||
use back::link::{mangle_internal_name_by_path_and_seq};
|
||||
use lib::llvm::{llvm, ValueRef};
|
||||
use middle::moves;
|
||||
use middle::lang_items::ClosureExchangeMallocFnLangItem;
|
||||
use middle::trans::base::*;
|
||||
use middle::trans::build::*;
|
||||
use middle::trans::callee;
|
||||
use middle::trans::common::*;
|
||||
use middle::trans::datum::{Datum, INIT, ByRef, ZeroMem};
|
||||
use middle::trans::expr;
|
||||
use middle::trans::glue;
|
||||
use middle::trans::machine;
|
||||
use middle::trans::type_of::*;
|
||||
use middle::ty;
|
||||
use util::ppaux::ty_to_str;
|
||||
|
@ -508,52 +505,9 @@ pub fn make_opaque_cbox_take_glue(
|
|||
return bcx;
|
||||
}
|
||||
ast::OwnedSigil => {
|
||||
/* hard case: fallthrough to code below */
|
||||
fail!("unique closures are not copyable")
|
||||
}
|
||||
}
|
||||
|
||||
// ~fn requires a deep copy.
|
||||
let ccx = bcx.ccx();
|
||||
let tcx = ccx.tcx;
|
||||
let llopaquecboxty = Type::opaque_box(ccx).ptr_to();
|
||||
let cbox_in = Load(bcx, cboxptr);
|
||||
do with_cond(bcx, IsNotNull(bcx, cbox_in)) |bcx| {
|
||||
// Load the size from the type descr found in the cbox
|
||||
let cbox_in = PointerCast(bcx, cbox_in, llopaquecboxty);
|
||||
let tydescptr = GEPi(bcx, cbox_in, [0u, abi::box_field_tydesc]);
|
||||
let tydesc = Load(bcx, tydescptr);
|
||||
let tydesc = PointerCast(bcx, tydesc, ccx.tydesc_type.ptr_to());
|
||||
let sz = Load(bcx, GEPi(bcx, tydesc, [0u, abi::tydesc_field_size]));
|
||||
|
||||
// Adjust sz to account for the rust_opaque_box header fields
|
||||
let sz = Add(bcx, sz, machine::llsize_of(ccx, Type::box_header(ccx)));
|
||||
|
||||
// Allocate memory, update original ptr, and copy existing data
|
||||
let opaque_tydesc = PointerCast(bcx, tydesc, Type::i8p());
|
||||
let mut bcx = bcx;
|
||||
let alloc_fn = langcall(bcx, None,
|
||||
fmt!("allocation of type with sigil `%s`",
|
||||
sigil.to_str()),
|
||||
ClosureExchangeMallocFnLangItem);
|
||||
let llresult = unpack_result!(bcx, callee::trans_lang_call(
|
||||
bcx,
|
||||
alloc_fn,
|
||||
[opaque_tydesc, sz],
|
||||
None));
|
||||
let cbox_out = PointerCast(bcx, llresult, llopaquecboxty);
|
||||
call_memcpy(bcx, cbox_out, cbox_in, sz, 1);
|
||||
Store(bcx, cbox_out, cboxptr);
|
||||
|
||||
// Take the (deeply cloned) type descriptor
|
||||
let tydesc_out = GEPi(bcx, cbox_out, [0u, abi::box_field_tydesc]);
|
||||
let bcx = glue::take_ty(bcx, tydesc_out, ty::mk_type(tcx));
|
||||
|
||||
// Take the data in the tuple
|
||||
let cdata_out = GEPi(bcx, cbox_out, [0u, abi::box_field_body]);
|
||||
glue::call_tydesc_glue_full(bcx, cdata_out, tydesc,
|
||||
abi::tydesc_field_take_glue, None);
|
||||
bcx
|
||||
}
|
||||
}
|
||||
|
||||
pub fn make_opaque_cbox_drop_glue(
|
||||
|
|
|
@ -93,26 +93,6 @@ pub fn drop_ty_immediate(bcx: block, v: ValueRef, t: ty::t) -> block {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn take_ty_immediate(bcx: block, v: ValueRef, t: ty::t) -> Result {
|
||||
let _icx = push_ctxt("take_ty_immediate");
|
||||
match ty::get(t).sty {
|
||||
ty::ty_box(_) | ty::ty_opaque_box |
|
||||
ty::ty_evec(_, ty::vstore_box) |
|
||||
ty::ty_estr(ty::vstore_box) => {
|
||||
incr_refcnt_of_boxed(bcx, v);
|
||||
rslt(bcx, v)
|
||||
}
|
||||
ty::ty_uniq(_) => {
|
||||
uniq::duplicate(bcx, v, t)
|
||||
}
|
||||
ty::ty_evec(_, ty::vstore_uniq) |
|
||||
ty::ty_estr(ty::vstore_uniq) => {
|
||||
tvec::duplicate_uniq(bcx, v, t)
|
||||
}
|
||||
_ => rslt(bcx, v)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn free_ty(cx: block, v: ValueRef, t: ty::t) -> block {
|
||||
// NB: v is an *alias* of type t here, not a direct value.
|
||||
let _icx = push_ctxt("free_ty");
|
||||
|
@ -589,23 +569,15 @@ pub fn make_take_glue(bcx: block, v: ValueRef, t: ty::t) -> block {
|
|||
ty::ty_evec(_, ty::vstore_box) | ty::ty_estr(ty::vstore_box) => {
|
||||
incr_refcnt_of_boxed(bcx, Load(bcx, v)); bcx
|
||||
}
|
||||
ty::ty_uniq(_) => {
|
||||
let Result {bcx, val} = uniq::duplicate(bcx, Load(bcx, v), t);
|
||||
Store(bcx, val, v);
|
||||
bcx
|
||||
}
|
||||
ty::ty_evec(_, ty::vstore_uniq) | ty::ty_estr(ty::vstore_uniq) => {
|
||||
let Result {bcx, val} = tvec::duplicate_uniq(bcx, Load(bcx, v), t);
|
||||
Store(bcx, val, v);
|
||||
bcx
|
||||
}
|
||||
ty::ty_evec(_, ty::vstore_slice(_))
|
||||
| ty::ty_estr(ty::vstore_slice(_)) => {
|
||||
bcx
|
||||
}
|
||||
ty::ty_closure(_) => {
|
||||
ty::ty_closure(ty::ClosureTy { sigil: ast::BorrowedSigil, _ }) |
|
||||
ty::ty_closure(ty::ClosureTy { sigil: ast::ManagedSigil, _ }) => {
|
||||
closure::make_closure_glue(bcx, v, t, take_ty)
|
||||
}
|
||||
ty::ty_closure(ty::ClosureTy { sigil: ast::OwnedSigil, _ }) => bcx,
|
||||
ty::ty_trait(_, _, ty::BoxTraitStore, _, _) => {
|
||||
let llbox = Load(bcx, GEPi(bcx, v, [0u, abi::trt_field_box]));
|
||||
incr_refcnt_of_boxed(bcx, llbox);
|
||||
|
|
|
@ -130,23 +130,6 @@ pub fn alloc_vec(bcx: block,
|
|||
return rslt(bcx, vptr);
|
||||
}
|
||||
|
||||
pub fn duplicate_uniq(bcx: block, vptr: ValueRef, vec_ty: ty::t) -> Result {
|
||||
let _icx = push_ctxt("tvec::duplicate_uniq");
|
||||
|
||||
let fill = get_fill(bcx, get_bodyptr(bcx, vptr, vec_ty));
|
||||
let unit_ty = ty::sequence_element_type(bcx.tcx(), vec_ty);
|
||||
let Result {bcx, val: newptr} = alloc_uniq_raw(bcx, unit_ty, fill, fill);
|
||||
|
||||
let data_ptr = get_dataptr(bcx, get_bodyptr(bcx, vptr, vec_ty));
|
||||
let new_data_ptr = get_dataptr(bcx, get_bodyptr(bcx, newptr, vec_ty));
|
||||
base::call_memcpy(bcx, new_data_ptr, data_ptr, fill, 1);
|
||||
|
||||
let bcx = if ty::type_needs_drop(bcx.tcx(), unit_ty) {
|
||||
iter_vec_raw(bcx, new_data_ptr, vec_ty, fill, glue::take_ty)
|
||||
} else { bcx };
|
||||
return rslt(bcx, newptr);
|
||||
}
|
||||
|
||||
pub fn make_drop_glue_unboxed(bcx: block, vptr: ValueRef, vec_ty: ty::t) ->
|
||||
block {
|
||||
let _icx = push_ctxt("tvec::make_drop_glue_unboxed");
|
||||
|
|
|
@ -14,11 +14,8 @@ use middle::trans::base::*;
|
|||
use middle::trans::build::*;
|
||||
use middle::trans::common::*;
|
||||
use middle::trans::datum::immediate_rvalue;
|
||||
use middle::trans::datum;
|
||||
use middle::trans::glue;
|
||||
use middle::ty;
|
||||
use middle::trans::machine::llsize_of;
|
||||
use middle::trans::type_of;
|
||||
|
||||
pub fn make_free_glue(bcx: block, vptrptr: ValueRef, box_ty: ty::t)
|
||||
-> block {
|
||||
|
@ -37,30 +34,3 @@ pub fn make_free_glue(bcx: block, vptrptr: ValueRef, box_ty: ty::t)
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn duplicate(bcx: block, src_box: ValueRef, src_ty: ty::t) -> Result {
|
||||
let _icx = push_ctxt("uniq::duplicate");
|
||||
|
||||
// Load the body of the source (*src)
|
||||
let src_datum = immediate_rvalue(src_box, src_ty);
|
||||
let body_datum = src_datum.box_body(bcx);
|
||||
|
||||
// Malloc space in exchange heap and copy src into it
|
||||
if ty::type_contents(bcx.tcx(), src_ty).contains_managed() {
|
||||
let MallocResult {
|
||||
bcx: bcx,
|
||||
box: dst_box,
|
||||
body: dst_body
|
||||
} = malloc_general(bcx, body_datum.ty, heap_managed_unique);
|
||||
body_datum.copy_to(bcx, datum::INIT, dst_body);
|
||||
|
||||
rslt(bcx, dst_box)
|
||||
} else {
|
||||
let body_datum = body_datum.to_value_datum(bcx);
|
||||
let llty = type_of(bcx.ccx(), body_datum.ty);
|
||||
let size = llsize_of(bcx.ccx(), llty);
|
||||
let Result { bcx: bcx, val: val } = malloc_raw_dyn(bcx, body_datum.ty, heap_exchange, size);
|
||||
body_datum.copy_to(bcx, datum::INIT, val);
|
||||
Result { bcx: bcx, val: val }
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue