Add take glue for unique boxes

Closes #962
Issue #409
This commit is contained in:
Brian Anderson 2011-09-22 18:05:36 -07:00
parent 77fcab043e
commit 1a48023a79
3 changed files with 29 additions and 1 deletions

View file

@ -1295,6 +1295,9 @@ fn make_take_glue(cx: @block_ctxt, v: ValueRef, t: ty::t) {
// NB: v is an *alias* of type t here, not a direct value.
if ty::type_is_boxed(bcx_tcx(bcx), t) {
bcx = incr_refcnt_of_boxed(bcx, Load(bcx, v));
} else if ty::type_is_unique_box(bcx_tcx(bcx), t) {
check trans_uniq::type_is_unique_box(bcx, t);
bcx = trans_uniq::duplicate(bcx, v, t);
} else if ty::type_is_structural(bcx_tcx(bcx), t) {
bcx = iter_structural_ty(bcx, v, t, take_ty);
} else if ty::type_is_vec(bcx_tcx(bcx), t) {

View file

@ -15,7 +15,8 @@ import trans::{
new_sub_block_ctxt
};
export trans_uniq, make_free_glue, type_is_unique_box, copy_val, autoderef;
export trans_uniq, make_free_glue, type_is_unique_box, copy_val,
autoderef, duplicate;
pure fn type_is_unique_box(bcx: @block_ctxt, ty: ty::t) -> bool {
unchecked {
@ -106,4 +107,17 @@ fn autoderef(bcx: @block_ctxt, v: ValueRef, t: ty::t)
let content_ty = content_ty(bcx, t);
ret {v: v, t: content_ty};
}
fn duplicate(bcx: @block_ctxt, v: ValueRef, t: ty::t)
: type_is_unique_box(bcx, t) -> @block_ctxt {
let content_ty = content_ty(bcx, t);
let {bcx, val: llptr} = alloc_uniq(bcx, t);
let src = Load(bcx, Load(bcx, v));
let dst = llptr;
let bcx = trans::copy_val(bcx, INIT, dst, src, content_ty);
Store(bcx, dst, v);
ret bcx;
}