From 0f0ba33d82f441257d013623b94288d366706edf Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Thu, 22 Sep 2011 11:37:02 -0700 Subject: [PATCH] Factor alloc_uniq from trans_uniq Issue #409 --- src/comp/middle/trans.rs | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/src/comp/middle/trans.rs b/src/comp/middle/trans.rs index 3f29c757aaf..8655dd28360 100644 --- a/src/comp/middle/trans.rs +++ b/src/comp/middle/trans.rs @@ -2041,7 +2041,7 @@ fn copy_val_no_check(cx: @block_ctxt, action: copy_action, dst: ValueRef, ret take_ty(bcx, dst, t); } if type_is_structural_or_param(ccx.tcx, t) || ty::type_is_vec(ccx.tcx, t) - { + { let bcx = cx; if action == DROP_EXISTING { bcx = drop_ty(cx, dst, t); } bcx = memmove_ty(bcx, dst, src, t).bcx; @@ -4518,7 +4518,24 @@ fn trans_uniq(cx: @block_ctxt, contents: @ast::expr, let lv = trans_lval(bcx, contents); bcx = lv.bcx; - let contents_ty = ty::expr_ty(bcx_tcx(bcx), contents); + let uniq_ty = node_id_type(bcx_ccx(cx), node_id); + let {bcx, val: llptr} = alloc_uniq(bcx, uniq_ty); + + bcx = move_val_if_temp(bcx, INIT, llptr, lv, + ty_uniq_contents(bcx, uniq_ty)); + + ret rslt(bcx, llptr); +} + +fn ty_uniq_contents(cx: @block_ctxt, uniq_ty: ty::t) -> ty::t { + alt ty::struct(bcx_tcx(cx), uniq_ty) { + ty::ty_uniq({ty: ct, _}) { ct } + } +} + +fn alloc_uniq(cx: @block_ctxt, uniq_ty: ty::t) -> result { + let bcx = cx; + let contents_ty = ty_uniq_contents(cx, uniq_ty); let r = size_of(bcx, contents_ty); bcx = r.bcx; let llsz = r.val; @@ -4529,11 +4546,9 @@ fn trans_uniq(cx: @block_ctxt, contents: @ast::expr, bcx = r.bcx; let llptr = r.val; - bcx = move_val_if_temp(bcx, INIT, llptr, lv, contents_ty); + add_clean_temp(bcx, llptr, uniq_ty); - let uniq_ty = node_id_type(bcx_ccx(cx), node_id); - add_clean_temp(r.bcx, llptr, uniq_ty); - ret rslt(r.bcx, llptr); + ret rslt(bcx, llptr); } fn trans_break_cont(sp: span, cx: @block_ctxt, to_end: bool) -> result {