Initialize unique box locals from other locals

Issue #409
This commit is contained in:
Brian Anderson 2011-09-22 13:22:53 -07:00
parent 5d5136df9f
commit 268a9fe5fb
4 changed files with 34 additions and 6 deletions

View File

@ -2030,11 +2030,11 @@ fn copy_val_no_check(cx: @block_ctxt, action: copy_action, dst: ValueRef,
ret take_ty(bcx, dst, t);
}
if ty::type_is_unique_box(ccx.tcx, t) {
//let bcx = cx;
let bcx = cx;
// FIXME (409): Write a test and uncomment
//if action == DROP_EXISTING { bcx = drop_ty(cx, dst, t); }
//ret trans_uniq::copy_val(bcx, dst, src, t);
fail;
check trans_uniq::type_is_unique_box(bcx, t);
ret trans_uniq::copy_val(bcx, dst, src, t);
}
if type_is_structural_or_param(ccx.tcx, t) || ty::type_is_vec(ccx.tcx, t)
{

View File

@ -15,7 +15,7 @@ import trans::{
new_sub_block_ctxt
};
export trans_uniq, make_free_glue, type_is_unique_box;
export trans_uniq, make_free_glue, type_is_unique_box, copy_val;
pure fn type_is_unique_box(bcx: @block_ctxt, ty: ty::t) -> bool {
unchecked {
@ -35,6 +35,8 @@ fn trans_uniq(cx: @block_ctxt, contents: @ast::expr,
let content_ty = content_ty(bcx, uniq_ty);
let {bcx, val: llptr} = alloc_uniq(bcx, uniq_ty);
add_clean_temp(bcx, llptr, uniq_ty);
bcx = move_val_if_temp(bcx, INIT, llptr, lv,
content_ty);
@ -56,8 +58,6 @@ fn alloc_uniq(cx: @block_ctxt, uniq_ty: ty::t)
bcx = r.bcx;
let llptr = r.val;
add_clean_temp(bcx, llptr, uniq_ty);
ret rslt(bcx, llptr);
}
@ -86,4 +86,18 @@ fn content_ty(bcx: @block_ctxt, t: ty::t)
alt ty::struct(bcx_tcx(bcx), t) {
ty::ty_uniq({ty: ct, _}) { ct }
}
}
fn copy_val(cx: @block_ctxt, dst: ValueRef, src: ValueRef,
ty: ty::t) : type_is_unique_box(cx, ty) -> @block_ctxt {
let content_ty = content_ty(cx, ty);
let {bcx, val: llptr} = alloc_uniq(cx, ty);
Store(bcx, llptr, dst);
let src = Load(bcx, src);
let dst = Load(bcx, dst);
let bcx = trans::copy_val(bcx, INIT, dst, src, content_ty);
Store(bcx, src, llptr);
ret bcx;
}

View File

@ -0,0 +1,9 @@
fn main() {
let i = ~mutable 1;
// Should be a copy
let j = i;
*i = 2;
*j = 3;
assert *i == 2;
assert *j == 3;
}

View File

@ -0,0 +1,5 @@
fn main() {
let i = ~1;
let j = i;
assert *j == 1;
}