1
Fork 0

Convert trans_uniq asserts to preconditions

Issue #409
This commit is contained in:
Brian Anderson 2011-09-22 12:22:23 -07:00
parent c4f02a7925
commit 5d5136df9f
2 changed files with 20 additions and 11 deletions

View file

@ -1317,6 +1317,7 @@ fn make_free_glue(bcx: @block_ctxt, v0: ValueRef, t: ty::t) {
} else { bcx } } else { bcx }
} }
ty::ty_uniq(content_mt) { ty::ty_uniq(content_mt) {
check trans_uniq::type_is_unique_box(bcx, t);
trans_uniq::make_free_glue(bcx, v0, t) trans_uniq::make_free_glue(bcx, v0, t)
} }
ty::ty_obj(_) { ty::ty_obj(_) {
@ -2029,7 +2030,7 @@ fn copy_val_no_check(cx: @block_ctxt, action: copy_action, dst: ValueRef,
ret take_ty(bcx, dst, t); ret take_ty(bcx, dst, t);
} }
if ty::type_is_unique_box(ccx.tcx, t) { if ty::type_is_unique_box(ccx.tcx, t) {
let bcx = cx; //let bcx = cx;
// FIXME (409): Write a test and uncomment // FIXME (409): Write a test and uncomment
//if action == DROP_EXISTING { bcx = drop_ty(cx, dst, t); } //if action == DROP_EXISTING { bcx = drop_ty(cx, dst, t); }
//ret trans_uniq::copy_val(bcx, dst, src, t); //ret trans_uniq::copy_val(bcx, dst, src, t);

View file

@ -15,7 +15,13 @@ import trans::{
new_sub_block_ctxt new_sub_block_ctxt
}; };
export trans_uniq, make_free_glue; export trans_uniq, make_free_glue, type_is_unique_box;
pure fn type_is_unique_box(bcx: @block_ctxt, ty: ty::t) -> bool {
unchecked {
ty::type_is_unique_box(bcx_tcx(bcx), ty)
}
}
fn trans_uniq(cx: @block_ctxt, contents: @ast::expr, fn trans_uniq(cx: @block_ctxt, contents: @ast::expr,
node_id: ast::node_id) -> result { node_id: ast::node_id) -> result {
@ -25,17 +31,18 @@ fn trans_uniq(cx: @block_ctxt, contents: @ast::expr,
bcx = lv.bcx; bcx = lv.bcx;
let uniq_ty = node_id_type(bcx_ccx(cx), node_id); let uniq_ty = node_id_type(bcx_ccx(cx), node_id);
assert ty::type_is_unique_box(bcx_tcx(cx), uniq_ty); check type_is_unique_box(bcx, uniq_ty);
let content_ty = content_ty(bcx, uniq_ty);
let {bcx, val: llptr} = alloc_uniq(bcx, uniq_ty); let {bcx, val: llptr} = alloc_uniq(bcx, uniq_ty);
bcx = move_val_if_temp(bcx, INIT, llptr, lv, bcx = move_val_if_temp(bcx, INIT, llptr, lv,
content_ty(bcx, uniq_ty)); content_ty);
ret rslt(bcx, llptr); ret rslt(bcx, llptr);
} }
fn alloc_uniq(cx: @block_ctxt, uniq_ty: ty::t) -> result { fn alloc_uniq(cx: @block_ctxt, uniq_ty: ty::t)
assert ty::type_is_unique_box(bcx_tcx(cx), uniq_ty); : type_is_unique_box(cx, uniq_ty) -> result {
let bcx = cx; let bcx = cx;
let contents_ty = content_ty(bcx, uniq_ty); let contents_ty = content_ty(bcx, uniq_ty);
@ -54,9 +61,10 @@ fn alloc_uniq(cx: @block_ctxt, uniq_ty: ty::t) -> result {
ret rslt(bcx, llptr); ret rslt(bcx, llptr);
} }
fn make_free_glue(bcx: @block_ctxt, v: ValueRef, t: ty::t) -> @block_ctxt { fn make_free_glue(cx: @block_ctxt, v: ValueRef, t: ty::t)
assert ty::type_is_unique_box(bcx_tcx(bcx), t); : type_is_unique_box(cx, t) -> @block_ctxt {
let bcx = cx;
let free_cx = new_sub_block_ctxt(bcx, "uniq_free"); let free_cx = new_sub_block_ctxt(bcx, "uniq_free");
let next_cx = new_sub_block_ctxt(bcx, "uniq_free_next"); let next_cx = new_sub_block_ctxt(bcx, "uniq_free_next");
let vptr = Load(bcx, v); let vptr = Load(bcx, v);
@ -64,7 +72,7 @@ fn make_free_glue(bcx: @block_ctxt, v: ValueRef, t: ty::t) -> @block_ctxt {
CondBr(bcx, null_test, next_cx.llbb, free_cx.llbb); CondBr(bcx, null_test, next_cx.llbb, free_cx.llbb);
let bcx = free_cx; let bcx = free_cx;
let bcx = drop_ty(bcx, vptr, content_ty(bcx, t)); let bcx = drop_ty(bcx, vptr, content_ty(cx, t));
let bcx = trans_shared_free(bcx, vptr); let bcx = trans_shared_free(bcx, vptr);
Store(bcx, C_null(val_ty(vptr)), v); Store(bcx, C_null(val_ty(vptr)), v);
Br(bcx, next_cx.llbb); Br(bcx, next_cx.llbb);
@ -72,8 +80,8 @@ fn make_free_glue(bcx: @block_ctxt, v: ValueRef, t: ty::t) -> @block_ctxt {
next_cx next_cx
} }
fn content_ty(bcx: @block_ctxt, t: ty::t) -> ty::t { fn content_ty(bcx: @block_ctxt, t: ty::t)
assert ty::type_is_unique_box(bcx_tcx(bcx), t); : type_is_unique_box(bcx, t) -> ty::t {
alt ty::struct(bcx_tcx(bcx), t) { alt ty::struct(bcx_tcx(bcx), t) {
ty::ty_uniq({ty: ct, _}) { ct } ty::ty_uniq({ty: ct, _}) { ct }