Skip to content

Commit 0eb56e6

Browse files
committed
Get rid of trans::iter_sequence, use tvec::iter_vec instead
1 parent 9fb3ec9 commit 0eb56e6

File tree

1 file changed

+15
-97
lines changed

1 file changed

+15
-97
lines changed

src/comp/middle/trans.rs

Lines changed: 15 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -1744,90 +1744,6 @@ fn iter_structural_ty(cx: @block_ctxt, av: ValueRef, t: ty::t,
17441744
ret cx;
17451745
}
17461746

1747-
1748-
// Iterates through a pointer range, until the src* hits the src_lim*.
1749-
fn iter_sequence_raw(cx: @block_ctxt, dst: ValueRef, src: ValueRef,
1750-
src_lim: ValueRef, elt_sz: ValueRef, f: &val_pair_fn) ->
1751-
@block_ctxt {
1752-
let bcx = cx;
1753-
let dst_int: ValueRef = vp2i(bcx, dst);
1754-
let src_int: ValueRef = vp2i(bcx, src);
1755-
let src_lim_int: ValueRef = vp2i(bcx, src_lim);
1756-
let cond_cx = new_scope_block_ctxt(cx, "sequence-iter cond");
1757-
let body_cx = new_scope_block_ctxt(cx, "sequence-iter body");
1758-
let next_cx = new_sub_block_ctxt(cx, "next");
1759-
Br(bcx, cond_cx.llbb);
1760-
let dst_curr: ValueRef = Phi(cond_cx, T_int(), [dst_int], [bcx.llbb]);
1761-
let src_curr: ValueRef = Phi(cond_cx, T_int(), [src_int], [bcx.llbb]);
1762-
let end_test =
1763-
ICmp(cond_cx, lib::llvm::LLVMIntULT, src_curr, src_lim_int);
1764-
CondBr(cond_cx, end_test, body_cx.llbb, next_cx.llbb);
1765-
let dst_curr_ptr = vi2p(body_cx, dst_curr, T_ptr(T_i8()));
1766-
let src_curr_ptr = vi2p(body_cx, src_curr, T_ptr(T_i8()));
1767-
let body_cx = f(body_cx, dst_curr_ptr, src_curr_ptr);
1768-
let dst_next = Add(body_cx, dst_curr, elt_sz);
1769-
let src_next = Add(body_cx, src_curr, elt_sz);
1770-
Br(body_cx, cond_cx.llbb);
1771-
AddIncomingToPhi(dst_curr, [dst_next], [body_cx.llbb]);
1772-
AddIncomingToPhi(src_curr, [src_next], [body_cx.llbb]);
1773-
ret next_cx;
1774-
}
1775-
1776-
fn iter_sequence_inner(cx: &@block_ctxt, src: ValueRef, src_lim: ValueRef,
1777-
elt_ty: &ty::t, f: &val_and_ty_fn) -> @block_ctxt {
1778-
fn adaptor_fn(f: val_and_ty_fn, elt_ty: ty::t, cx: &@block_ctxt,
1779-
_dst: ValueRef, src: ValueRef) -> @block_ctxt {
1780-
let ccx = bcx_ccx(cx);
1781-
let sp = cx.sp;
1782-
let llptrty =
1783-
if check type_has_static_size(ccx, elt_ty) {
1784-
let llty = type_of(ccx, sp, elt_ty);
1785-
T_ptr(llty)
1786-
}
1787-
else { T_ptr(T_ptr(T_i8())) };
1788-
1789-
let p = PointerCast(cx, src, llptrty);
1790-
ret f(cx, load_if_immediate(cx, p, elt_ty), elt_ty);
1791-
}
1792-
let elt_sz = size_of(cx, elt_ty);
1793-
ret iter_sequence_raw(elt_sz.bcx, src, src, src_lim, elt_sz.val,
1794-
bind adaptor_fn(f, elt_ty, _, _, _));
1795-
}
1796-
1797-
1798-
// Iterates through the elements of a vec or str.
1799-
fn iter_sequence(cx: @block_ctxt, v: ValueRef, t: ty::t, f: &val_and_ty_fn) ->
1800-
@block_ctxt {
1801-
fn iter_sequence_body(bcx: @block_ctxt, v: ValueRef, elt_ty: ty::t,
1802-
f: &val_and_ty_fn, trailing_null: bool) ->
1803-
@block_ctxt {
1804-
let llunit_ty = type_of_or_i8(bcx, elt_ty);
1805-
let p0 = tvec::get_dataptr(bcx, v, llunit_ty);
1806-
let len = tvec::get_fill(bcx, v);
1807-
1808-
if trailing_null {
1809-
let unit_sz = size_of(bcx, elt_ty);
1810-
bcx = unit_sz.bcx;
1811-
len = Sub(bcx, len, unit_sz.val);
1812-
}
1813-
let p1 = vi2p(bcx, Add(bcx, vp2i(bcx, p0), len), T_ptr(llunit_ty));
1814-
ret iter_sequence_inner(bcx, p0, p1, elt_ty, f);
1815-
}
1816-
1817-
1818-
alt ty::struct(bcx_tcx(cx), t) {
1819-
ty::ty_vec(elt) { ret iter_sequence_body(cx, v, elt.ty, f, false); }
1820-
ty::ty_str. {
1821-
let et = ty::mk_mach(bcx_tcx(cx), ast::ty_u8);
1822-
ret iter_sequence_body(cx, v, et, f, true);
1823-
}
1824-
_ {
1825-
bcx_ccx(cx).sess.bug("unexpected type in trans::iter_sequence: " +
1826-
ty_to_str(cx.fcx.lcx.ccx.tcx, t));
1827-
}
1828-
}
1829-
}
1830-
18311747
fn lazily_emit_all_tydesc_glue(cx: &@block_ctxt,
18321748
static_ti: &option::t<@tydesc_info>) {
18331749
lazily_emit_tydesc_glue(cx, abi::tydesc_field_take_glue, static_ti);
@@ -2559,8 +2475,6 @@ fn trans_if(cx: &@block_ctxt, cond: &@ast::expr, thn: &ast::blk,
25592475

25602476
fn trans_for(cx: &@block_ctxt, local: &@ast::local, seq: &@ast::expr,
25612477
body: &ast::blk) -> result {
2562-
// FIXME: We bind to an alias here to avoid a segfault... this is
2563-
// obviously a bug.
25642478
fn inner(cx: &@block_ctxt, local: @ast::local, curr: ValueRef, t: ty::t,
25652479
body: &ast::blk, outer_next_cx: @block_ctxt) -> @block_ctxt {
25662480
let next_cx = new_sub_block_ctxt(cx, "next");
@@ -2569,13 +2483,13 @@ fn trans_for(cx: &@block_ctxt, local: &@ast::local, seq: &@ast::expr,
25692483
option::some::<@block_ctxt>(next_cx),
25702484
outer_next_cx, "for loop scope");
25712485
Br(cx, scope_cx.llbb);
2572-
let local_res = alloc_local(scope_cx, local);
2573-
let bcx = copy_val(local_res.bcx, INIT, local_res.val, curr, t);
2574-
add_clean(scope_cx, local_res.val, t);
2575-
let bcx =
2576-
trans_alt::bind_irrefutable_pat(bcx, local.node.pat,
2577-
local_res.val, cx.fcx.lllocals,
2578-
false);
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,
2492+
cx.fcx.lllocals, false);
25792493
bcx = trans_block(bcx, body, return).bcx;
25802494
if !is_terminated(bcx) {
25812495
Br(bcx, next_cx.llbb);
@@ -2585,10 +2499,14 @@ fn trans_for(cx: &@block_ctxt, local: &@ast::local, seq: &@ast::expr,
25852499
}
25862500
let next_cx = new_sub_block_ctxt(cx, "next");
25872501
let seq_ty = ty::expr_ty(bcx_tcx(cx), seq);
2588-
let seq_res = trans_expr(cx, seq);
2589-
let bcx =
2590-
iter_sequence(seq_res.bcx, seq_res.val, seq_ty,
2591-
bind inner(_, local, _, _, body, next_cx));
2502+
let {bcx, val: seq} = trans_expr(cx, seq);
2503+
let seq = PointerCast(bcx, seq, T_ptr(T_ptr(T_opaque_vec())));
2504+
let fill = tvec::get_fill(bcx, seq);
2505+
if ty::type_is_str(bcx_tcx(bcx), seq_ty) {
2506+
fill = Sub(bcx, fill, C_int(1));
2507+
}
2508+
let bcx = tvec::iter_vec_raw(bcx, seq, seq_ty, fill,
2509+
bind inner(_, local, _, _, body, next_cx));
25922510
Br(bcx, next_cx.llbb);
25932511
ret rslt(next_cx, C_nil());
25942512
}

0 commit comments

Comments
 (0)