Skip to content

Commit 985ef59

Browse files
committed
Make for loops alias the vec elements, rather than copy them
The alias analysis was already assuming that it worked like this.
1 parent 0eb56e6 commit 985ef59

File tree

1 file changed

+6
-12
lines changed

1 file changed

+6
-12
lines changed

src/comp/middle/trans.rs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2478,19 +2478,13 @@ fn trans_for(cx: &@block_ctxt, local: &@ast::local, seq: &@ast::expr,
24782478
fn inner(cx: &@block_ctxt, local: @ast::local, curr: ValueRef, t: ty::t,
24792479
body: &ast::blk, outer_next_cx: @block_ctxt) -> @block_ctxt {
24802480
let next_cx = new_sub_block_ctxt(cx, "next");
2481-
let scope_cx =
2482-
new_loop_scope_block_ctxt(cx,
2483-
option::some::<@block_ctxt>(next_cx),
2484-
outer_next_cx, "for loop scope");
2485-
Br(cx, scope_cx.llbb);
2486-
let {bcx, val: dst} = alloc_local(scope_cx, local);
2487-
let val = load_if_immediate(bcx, PointerCast(bcx, curr,
2488-
val_ty(dst)), t);
2489-
let bcx = copy_val(bcx, INIT, dst, val, t);
2490-
add_clean(scope_cx, dst, t);
2491-
let bcx = trans_alt::bind_irrefutable_pat(bcx, local.node.pat, dst,
2481+
let bcx = new_loop_scope_block_ctxt(cx, option::some(next_cx),
2482+
outer_next_cx, "for loop scope");
2483+
Br(cx, bcx.llbb);
2484+
let val = PointerCast(bcx, curr, T_ptr(type_of_or_i8(cx, t)));
2485+
let bcx = trans_alt::bind_irrefutable_pat(bcx, local.node.pat, val,
24922486
cx.fcx.lllocals, false);
2493-
bcx = trans_block(bcx, body, return).bcx;
2487+
let bcx = trans_block(bcx, body, return).bcx;
24942488
if !is_terminated(bcx) {
24952489
Br(bcx, next_cx.llbb);
24962490
// otherwise, this code is unreachable

0 commit comments

Comments
 (0)