Skip to content

Commit 5d5136d

Browse files
committed
Convert trans_uniq asserts to preconditions
Issue #409
1 parent c4f02a7 commit 5d5136d

File tree

2 files changed

+20
-11
lines changed

2 files changed

+20
-11
lines changed

src/comp/middle/trans.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1317,6 +1317,7 @@ fn make_free_glue(bcx: @block_ctxt, v0: ValueRef, t: ty::t) {
13171317
} else { bcx }
13181318
}
13191319
ty::ty_uniq(content_mt) {
1320+
check trans_uniq::type_is_unique_box(bcx, t);
13201321
trans_uniq::make_free_glue(bcx, v0, t)
13211322
}
13221323
ty::ty_obj(_) {
@@ -2029,7 +2030,7 @@ fn copy_val_no_check(cx: @block_ctxt, action: copy_action, dst: ValueRef,
20292030
ret take_ty(bcx, dst, t);
20302031
}
20312032
if ty::type_is_unique_box(ccx.tcx, t) {
2032-
let bcx = cx;
2033+
//let bcx = cx;
20332034
// FIXME (409): Write a test and uncomment
20342035
//if action == DROP_EXISTING { bcx = drop_ty(cx, dst, t); }
20352036
//ret trans_uniq::copy_val(bcx, dst, src, t);

src/comp/middle/trans_uniq.rs

+18-10
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,13 @@ import trans::{
1515
new_sub_block_ctxt
1616
};
1717

18-
export trans_uniq, make_free_glue;
18+
export trans_uniq, make_free_glue, type_is_unique_box;
19+
20+
pure fn type_is_unique_box(bcx: @block_ctxt, ty: ty::t) -> bool {
21+
unchecked {
22+
ty::type_is_unique_box(bcx_tcx(bcx), ty)
23+
}
24+
}
1925

2026
fn trans_uniq(cx: @block_ctxt, contents: @ast::expr,
2127
node_id: ast::node_id) -> result {
@@ -25,17 +31,18 @@ fn trans_uniq(cx: @block_ctxt, contents: @ast::expr,
2531
bcx = lv.bcx;
2632

2733
let uniq_ty = node_id_type(bcx_ccx(cx), node_id);
28-
assert ty::type_is_unique_box(bcx_tcx(cx), uniq_ty);
34+
check type_is_unique_box(bcx, uniq_ty);
35+
let content_ty = content_ty(bcx, uniq_ty);
2936
let {bcx, val: llptr} = alloc_uniq(bcx, uniq_ty);
3037

3138
bcx = move_val_if_temp(bcx, INIT, llptr, lv,
32-
content_ty(bcx, uniq_ty));
39+
content_ty);
3340

3441
ret rslt(bcx, llptr);
3542
}
3643

37-
fn alloc_uniq(cx: @block_ctxt, uniq_ty: ty::t) -> result {
38-
assert ty::type_is_unique_box(bcx_tcx(cx), uniq_ty);
44+
fn alloc_uniq(cx: @block_ctxt, uniq_ty: ty::t)
45+
: type_is_unique_box(cx, uniq_ty) -> result {
3946

4047
let bcx = cx;
4148
let contents_ty = content_ty(bcx, uniq_ty);
@@ -54,26 +61,27 @@ fn alloc_uniq(cx: @block_ctxt, uniq_ty: ty::t) -> result {
5461
ret rslt(bcx, llptr);
5562
}
5663

57-
fn make_free_glue(bcx: @block_ctxt, v: ValueRef, t: ty::t) -> @block_ctxt {
58-
assert ty::type_is_unique_box(bcx_tcx(bcx), t);
64+
fn make_free_glue(cx: @block_ctxt, v: ValueRef, t: ty::t)
65+
: type_is_unique_box(cx, t) -> @block_ctxt {
5966

67+
let bcx = cx;
6068
let free_cx = new_sub_block_ctxt(bcx, "uniq_free");
6169
let next_cx = new_sub_block_ctxt(bcx, "uniq_free_next");
6270
let vptr = Load(bcx, v);
6371
let null_test = IsNull(bcx, vptr);
6472
CondBr(bcx, null_test, next_cx.llbb, free_cx.llbb);
6573

6674
let bcx = free_cx;
67-
let bcx = drop_ty(bcx, vptr, content_ty(bcx, t));
75+
let bcx = drop_ty(bcx, vptr, content_ty(cx, t));
6876
let bcx = trans_shared_free(bcx, vptr);
6977
Store(bcx, C_null(val_ty(vptr)), v);
7078
Br(bcx, next_cx.llbb);
7179

7280
next_cx
7381
}
7482

75-
fn content_ty(bcx: @block_ctxt, t: ty::t) -> ty::t {
76-
assert ty::type_is_unique_box(bcx_tcx(bcx), t);
83+
fn content_ty(bcx: @block_ctxt, t: ty::t)
84+
: type_is_unique_box(bcx, t) -> ty::t {
7785

7886
alt ty::struct(bcx_tcx(bcx), t) {
7987
ty::ty_uniq({ty: ct, _}) { ct }

0 commit comments

Comments
 (0)