Skip to content

Commit eef9a0b

Browse files
committed
Evaluate alt expressions in their own block context
Closes #785
1 parent d8d35e7 commit eef9a0b

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/comp/middle/trans_alt.rs

+10-3
Original file line numberDiff line numberDiff line change
@@ -624,7 +624,10 @@ fn trans_alt(cx: @block_ctxt, expr: @ast::expr, arms: [ast::arm],
624624
dest: trans::dest) -> @block_ctxt {
625625
let bodies = [];
626626
let match: match = [];
627-
let er = trans::trans_temp_expr(cx, expr);
627+
let alt_cx = new_scope_block_ctxt(cx, "alt");
628+
Br(cx, alt_cx.llbb);
629+
630+
let er = trans::trans_temp_expr(alt_cx, expr);
628631
if er.bcx.unreachable { ret er.bcx; }
629632

630633
for a: ast::arm in arms {
@@ -654,7 +657,7 @@ fn trans_alt(cx: @block_ctxt, expr: @ast::expr, arms: [ast::arm],
654657
let t = trans::node_id_type(cx.fcx.lcx.ccx, expr.id);
655658
let vr = trans::spill_if_immediate(er.bcx, er.val, t);
656659
compile_submatch(vr.bcx, match, [vr.val],
657-
bind mk_fail(cx, expr.span, fail_cx), exit_map);
660+
bind mk_fail(alt_cx, expr.span, fail_cx), exit_map);
658661

659662
let arm_cxs = [], arm_dests = [], i = 0u;
660663
for a: ast::arm in arms {
@@ -667,7 +670,11 @@ fn trans_alt(cx: @block_ctxt, expr: @ast::expr, arms: [ast::arm],
667670
}
668671
i += 1u;
669672
}
670-
ret trans::join_returns(cx, arm_cxs, arm_dests, dest);
673+
let after_cx = trans::join_returns(cx, arm_cxs, arm_dests, dest);
674+
after_cx = trans::trans_block_cleanups(after_cx, alt_cx);
675+
let next_cx = new_sub_block_ctxt(after_cx, "next");
676+
Br(after_cx, next_cx.llbb);
677+
ret next_cx;
671678
}
672679

673680
// Not alt-related, but similar to the pattern-munging code above

0 commit comments

Comments
 (0)