Skip to content

Commit d7a1d6a

Browse files
committed
Make trans understand by-ref bindings
Issue #918
1 parent 8aad161 commit d7a1d6a

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

src/comp/middle/trans.rs

+19-8
Original file line numberDiff line numberDiff line change
@@ -4444,7 +4444,7 @@ fn trans_be(cx: @block_ctxt, e: @ast::expr) : ast_util::is_call_expr(e) ->
44444444
ret trans_ret(cx, some(e));
44454445
}
44464446

4447-
fn init_local(bcx: @block_ctxt, local: @ast::local) -> result {
4447+
fn init_local(bcx: @block_ctxt, local: @ast::local) -> @block_ctxt {
44484448
let ty = node_id_type(bcx_ccx(bcx), local.node.id);
44494449
let llptr = bcx.fcx.lllocals.get(local.node.id);
44504450
// Make a note to drop this slot on the way out.
@@ -4476,7 +4476,7 @@ fn init_local(bcx: @block_ctxt, local: @ast::local) -> result {
44764476
bcx =
44774477
trans_alt::bind_irrefutable_pat(bcx, local.node.pat, llptr,
44784478
bcx.fcx.lllocals, false);
4479-
ret rslt(bcx, llptr);
4479+
ret bcx;
44804480

44814481
fn must_zero(ccx: @crate_ctxt, local: @ast::local) -> bool {
44824482
alt local.node.init {
@@ -4513,6 +4513,14 @@ fn init_local(bcx: @block_ctxt, local: @ast::local) -> result {
45134513
}
45144514
}
45154515

4516+
fn init_ref_local(bcx: @block_ctxt, local: @ast::local) -> @block_ctxt {
4517+
let init_expr = option::get(local.node.init).expr;
4518+
let val = trans_lval(bcx, init_expr);
4519+
assert val.is_mem;
4520+
ret trans_alt::bind_irrefutable_pat(bcx, local.node.pat, val.res.val,
4521+
bcx.fcx.lllocals, false);
4522+
}
4523+
45164524
fn zero_alloca(cx: @block_ctxt, llptr: ValueRef, t: ty::t) -> result {
45174525
let bcx = cx;
45184526
let ccx = bcx_ccx(cx);
@@ -4538,8 +4546,12 @@ fn trans_stmt(cx: @block_ctxt, s: ast::stmt) -> result {
45384546
ast::stmt_decl(d, _) {
45394547
alt d.node {
45404548
ast::decl_local(locals) {
4541-
for (_, local) in locals {
4542-
bcx = init_local(bcx, local).bcx;
4549+
for (style, local) in locals {
4550+
if style == ast::let_copy {
4551+
bcx = init_local(bcx, local);
4552+
} else {
4553+
bcx = init_ref_local(bcx, local);
4554+
}
45434555
}
45444556
}
45454557
ast::decl_item(i) { trans_item(cx.fcx.lcx, *i); }
@@ -4646,15 +4658,14 @@ fn trans_fn_cleanups(fcx: @fn_ctxt, cx: @block_ctxt) {
46464658
}
46474659

46484660
iter block_locals(b: ast::blk) -> @ast::local {
4649-
4650-
// FIXME: putting from inside an iter block doesn't work, so we can't
4651-
// use the index here.
46524661
for s: @ast::stmt in b.node.stmts {
46534662
alt s.node {
46544663
ast::stmt_decl(d, _) {
46554664
alt d.node {
46564665
ast::decl_local(locals) {
4657-
for (_, local) in locals { put local; }
4666+
for (style, local) in locals {
4667+
if style == ast::let_copy { put local; }
4668+
}
46584669
}
46594670
_ {/* fall through */ }
46604671
}

0 commit comments

Comments
 (0)