Skip to content

Commit f85fbcb

Browse files
committed
Revert "Clean up a bunch of box related code."
This reverts commit bacf9e9.
1 parent 6141f5c commit f85fbcb

File tree

2 files changed

+38
-27
lines changed

2 files changed

+38
-27
lines changed

src/rustc/middle/trans/base.rs

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -398,16 +398,18 @@ fn malloc_general_dyn(bcx: block, t: ty::t, heap: heap, size: ValueRef) ->
398398
ret {box: box, body: body};
399399
}
400400

401-
fn malloc_general(bcx: block, t: ty::t, heap: heap) ->
402-
{box: ValueRef, body: ValueRef} {
403-
malloc_general_dyn(bcx, t, heap,
404-
llsize_of(bcx.ccx(), type_of(bcx.ccx(), t)))
405-
}
406401
fn malloc_boxed(bcx: block, t: ty::t) -> {box: ValueRef, body: ValueRef} {
407-
malloc_general(bcx, t, heap_shared)
402+
malloc_general_dyn(bcx, t, heap_shared,
403+
llsize_of(bcx.ccx(), type_of(bcx.ccx(), t)))
408404
}
409405
fn malloc_unique(bcx: block, t: ty::t) -> {box: ValueRef, body: ValueRef} {
410-
malloc_general(bcx, t, heap_exchange)
406+
malloc_general_dyn(bcx, t, heap_exchange,
407+
llsize_of(bcx.ccx(), type_of(bcx.ccx(), t)))
408+
}
409+
410+
fn malloc_unique_dyn(bcx: block, t: ty::t, size: ValueRef
411+
) -> {box: ValueRef, body: ValueRef} {
412+
malloc_general_dyn(bcx, t, heap_exchange, size)
411413
}
412414

413415
// Type descriptor and type glue stuff
@@ -1485,19 +1487,6 @@ fn trans_lit(cx: block, e: @ast::expr, lit: ast::lit, dest: dest) -> block {
14851487
}
14861488
}
14871489

1488-
1489-
fn trans_boxed_expr(bcx: block, contents: @ast::expr,
1490-
t: ty::t, heap: heap,
1491-
dest: dest) -> block {
1492-
let _icx = bcx.insn_ctxt("trans_boxed_expr");
1493-
let {box, body} = malloc_general(bcx, t, heap);
1494-
add_clean_free(bcx, box, true);
1495-
let bcx = trans_expr_save_in(bcx, contents, body);
1496-
revoke_clean(bcx, box);
1497-
ret store_in_dest(bcx, box, dest);
1498-
}
1499-
1500-
15011490
fn trans_unary(bcx: block, op: ast::unop, e: @ast::expr,
15021491
un_expr: @ast::expr, dest: dest) -> block {
15031492
let _icx = bcx.insn_ctxt("trans_unary");
@@ -1520,25 +1509,35 @@ fn trans_unary(bcx: block, op: ast::unop, e: @ast::expr,
15201509
alt op {
15211510
ast::not {
15221511
let {bcx, val} = trans_temp_expr(bcx, e);
1523-
store_in_dest(bcx, Not(bcx, val), dest)
1512+
ret store_in_dest(bcx, Not(bcx, val), dest);
15241513
}
15251514
ast::neg {
15261515
let {bcx, val} = trans_temp_expr(bcx, e);
15271516
let neg = if ty::type_is_fp(e_ty) {
15281517
FNeg(bcx, val)
15291518
} else { Neg(bcx, val) };
1530-
store_in_dest(bcx, neg, dest)
1519+
ret store_in_dest(bcx, neg, dest);
15311520
}
15321521
ast::box(_) {
1533-
trans_boxed_expr(bcx, e, e_ty, heap_shared, dest)
1522+
let mut {box, body} = malloc_boxed(bcx, e_ty);
1523+
add_clean_free(bcx, box, false);
1524+
// Cast the body type to the type of the value. This is needed to
1525+
// make enums work, since enums have a different LLVM type depending
1526+
// on whether they're boxed or not
1527+
let ccx = bcx.ccx();
1528+
let llety = T_ptr(type_of(ccx, e_ty));
1529+
body = PointerCast(bcx, body, llety);
1530+
let bcx = trans_expr_save_in(bcx, e, body);
1531+
revoke_clean(bcx, box);
1532+
ret store_in_dest(bcx, box, dest);
15341533
}
15351534
ast::uniq(_) {
1536-
trans_boxed_expr(bcx, e, e_ty, heap_exchange, dest)
1535+
ret uniq::trans_uniq(bcx, e, un_expr.id, dest);
15371536
}
15381537
ast::deref {
15391538
bcx.sess().bug("deref expressions should have been \
15401539
translated using trans_lval(), not \
1541-
trans_unary()")
1540+
trans_unary()");
15421541
}
15431542
}
15441543
}

src/rustc/middle/trans/uniq.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,19 @@ import build::*;
55
import base::*;
66
import shape::llsize_of;
77

8-
export make_free_glue, autoderef, duplicate;
8+
export trans_uniq, make_free_glue, autoderef, duplicate;
9+
10+
fn trans_uniq(bcx: block, contents: @ast::expr,
11+
node_id: ast::node_id, dest: dest) -> block {
12+
let _icx = bcx.insn_ctxt("uniq::trans_uniq");
13+
let uniq_ty = node_id_type(bcx, node_id);
14+
let contents_ty = content_ty(uniq_ty);
15+
let {box, body} = malloc_unique(bcx, contents_ty);
16+
add_clean_free(bcx, box, true);
17+
let bcx = trans_expr_save_in(bcx, contents, body);
18+
revoke_clean(bcx, box);
19+
ret store_in_dest(bcx, box, dest);
20+
}
921

1022
fn make_free_glue(bcx: block, vptr: ValueRef, t: ty::t)
1123
-> block {
@@ -52,4 +64,4 @@ fn duplicate(bcx: block, v: ValueRef, t: ty::t) -> result {
5264
Store(bcx, td, dst_tydesc_ptr);
5365

5466
ret rslt(bcx, dst_box);
55-
}
67+
}

0 commit comments

Comments
 (0)