Skip to content

Commit 0f0ba33

Browse files
committed
Factor alloc_uniq from trans_uniq
Issue #409
1 parent f2b49b8 commit 0f0ba33

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

src/comp/middle/trans.rs

+21-6
Original file line numberDiff line numberDiff line change
@@ -2041,7 +2041,7 @@ fn copy_val_no_check(cx: @block_ctxt, action: copy_action, dst: ValueRef,
20412041
ret take_ty(bcx, dst, t);
20422042
}
20432043
if type_is_structural_or_param(ccx.tcx, t) || ty::type_is_vec(ccx.tcx, t)
2044-
{
2044+
{
20452045
let bcx = cx;
20462046
if action == DROP_EXISTING { bcx = drop_ty(cx, dst, t); }
20472047
bcx = memmove_ty(bcx, dst, src, t).bcx;
@@ -4518,7 +4518,24 @@ fn trans_uniq(cx: @block_ctxt, contents: @ast::expr,
45184518
let lv = trans_lval(bcx, contents);
45194519
bcx = lv.bcx;
45204520

4521-
let contents_ty = ty::expr_ty(bcx_tcx(bcx), contents);
4521+
let uniq_ty = node_id_type(bcx_ccx(cx), node_id);
4522+
let {bcx, val: llptr} = alloc_uniq(bcx, uniq_ty);
4523+
4524+
bcx = move_val_if_temp(bcx, INIT, llptr, lv,
4525+
ty_uniq_contents(bcx, uniq_ty));
4526+
4527+
ret rslt(bcx, llptr);
4528+
}
4529+
4530+
fn ty_uniq_contents(cx: @block_ctxt, uniq_ty: ty::t) -> ty::t {
4531+
alt ty::struct(bcx_tcx(cx), uniq_ty) {
4532+
ty::ty_uniq({ty: ct, _}) { ct }
4533+
}
4534+
}
4535+
4536+
fn alloc_uniq(cx: @block_ctxt, uniq_ty: ty::t) -> result {
4537+
let bcx = cx;
4538+
let contents_ty = ty_uniq_contents(cx, uniq_ty);
45224539
let r = size_of(bcx, contents_ty);
45234540
bcx = r.bcx;
45244541
let llsz = r.val;
@@ -4529,11 +4546,9 @@ fn trans_uniq(cx: @block_ctxt, contents: @ast::expr,
45294546
bcx = r.bcx;
45304547
let llptr = r.val;
45314548

4532-
bcx = move_val_if_temp(bcx, INIT, llptr, lv, contents_ty);
4549+
add_clean_temp(bcx, llptr, uniq_ty);
45334550

4534-
let uniq_ty = node_id_type(bcx_ccx(cx), node_id);
4535-
add_clean_temp(r.bcx, llptr, uniq_ty);
4536-
ret rslt(r.bcx, llptr);
4551+
ret rslt(bcx, llptr);
45374552
}
45384553

45394554
fn trans_break_cont(sp: span, cx: @block_ctxt, to_end: bool) -> result {

0 commit comments

Comments
 (0)