Skip to content

Commit 304fa89

Browse files
committed
---
yaml --- r: 4513 b: refs/heads/master c: 8e6e6f5 h: refs/heads/master i: 4511: b603171 v: v3
1 parent ecb8434 commit 304fa89

File tree

2 files changed

+37
-71
lines changed

2 files changed

+37
-71
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: 044b16ad68984a1c99f88ddf6701f4eaefa15bf8
2+
refs/heads/master: 8e6e6f5f896e1dbc2fb124e7dad8750d8b9112ef

trunk/src/comp/middle/trans.rs

Lines changed: 36 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1639,21 +1639,18 @@ fn compare_scalar_values(cx: &@block_ctxt, lhs: ValueRef, rhs: ValueRef,
16391639
}
16401640

16411641
type val_pair_fn = fn(&@block_ctxt, ValueRef, ValueRef) -> result ;
1642-
1642+
type val_fn = fn(&@block_ctxt, ValueRef) -> result ;
16431643
type val_and_ty_fn = fn(&@block_ctxt, ValueRef, ty::t) -> result ;
16441644

1645-
type val_pair_and_ty_fn =
1646-
fn(&@block_ctxt, ValueRef, ValueRef, ty::t) -> result ;
1647-
16481645

16491646
// Iterates through the elements of a structural type.
16501647
fn iter_structural_ty(cx: &@block_ctxt, v: ValueRef, t: &ty::t,
16511648
f: val_and_ty_fn) -> result {
16521649
fn adaptor_fn(f: val_and_ty_fn, cx: &@block_ctxt, av: ValueRef,
1653-
bv: ValueRef, t: ty::t) -> result {
1650+
t: ty::t) -> result {
16541651
ret f(cx, av, t);
16551652
}
1656-
ret iter_structural_ty_full(cx, v, v, t, bind adaptor_fn(f, _, _, _, _));
1653+
ret iter_structural_ty_full(cx, v, t, bind adaptor_fn(f, _, _, _));
16571654
}
16581655

16591656
fn load_inbounds(cx: &@block_ctxt, p: ValueRef, idxs: &[ValueRef]) ->
@@ -1672,74 +1669,63 @@ fn incr_ptr(cx: &@block_ctxt, p: ValueRef, incr: ValueRef, pp: ValueRef) {
16721669
cx.build.Store(cx.build.InBoundsGEP(p, ~[incr]), pp);
16731670
}
16741671

1675-
fn iter_structural_ty_full(cx: &@block_ctxt, av: ValueRef, bv: ValueRef,
1676-
t: &ty::t, f: &val_pair_and_ty_fn) -> result {
1677-
fn iter_boxpp(cx: @block_ctxt, box_a_cell: ValueRef, box_b_cell: ValueRef,
1678-
f: &val_pair_and_ty_fn) -> result {
1679-
let box_a_ptr = cx.build.Load(box_a_cell);
1680-
let box_b_ptr = cx.build.Load(box_b_cell);
1672+
fn iter_structural_ty_full(cx: &@block_ctxt, av: ValueRef, t: &ty::t,
1673+
f: &val_and_ty_fn) -> result {
1674+
fn iter_boxpp(cx: @block_ctxt, box_cell: ValueRef, f: &val_and_ty_fn)
1675+
-> result {
1676+
let box_ptr = cx.build.Load(box_cell);
16811677
let tnil = ty::mk_nil(bcx_tcx(cx));
16821678
let tbox = ty::mk_imm_box(bcx_tcx(cx), tnil);
16831679
let inner_cx = new_sub_block_ctxt(cx, "iter box");
16841680
let next_cx = new_sub_block_ctxt(cx, "next");
1685-
let null_test = cx.build.IsNull(box_a_ptr);
1681+
let null_test = cx.build.IsNull(box_ptr);
16861682
cx.build.CondBr(null_test, next_cx.llbb, inner_cx.llbb);
1687-
let r = f(inner_cx, box_a_ptr, box_b_ptr, tbox);
1683+
let r = f(inner_cx, box_ptr, tbox);
16881684
r.bcx.build.Br(next_cx.llbb);
16891685
ret rslt(next_cx, C_nil());
16901686
}
16911687

1692-
fn iter_ivec(bcx: @block_ctxt, av: ValueRef, bv: ValueRef, unit_ty: ty::t,
1693-
f: &val_pair_and_ty_fn) -> result {
1688+
fn iter_ivec(bcx: @block_ctxt, av: ValueRef, unit_ty: ty::t,
1689+
f: &val_and_ty_fn) -> result {
16941690
// FIXME: "unimplemented rebinding existing function" workaround
16951691

1696-
fn adapter(bcx: &@block_ctxt, av: ValueRef, bv: ValueRef,
1697-
unit_ty: ty::t, f: val_pair_and_ty_fn) -> result {
1698-
ret f(bcx, av, bv, unit_ty);
1692+
fn adapter(bcx: &@block_ctxt, av: ValueRef, unit_ty: ty::t,
1693+
f: val_and_ty_fn) -> result {
1694+
ret f(bcx, av, unit_ty);
16991695
}
17001696
let llunitty = type_of_or_i8(bcx, unit_ty);
17011697
let rs = size_of(bcx, unit_ty);
17021698
let unit_sz = rs.val;
17031699
bcx = rs.bcx;
17041700
let a_len_and_data = ivec::get_len_and_data(bcx, av, unit_ty);
1705-
let a_len = a_len_and_data.len;
1701+
let len = a_len_and_data.len;
17061702
let a_elem = a_len_and_data.data;
17071703
bcx = a_len_and_data.bcx;
1708-
let b_len_and_data = ivec::get_len_and_data(bcx, bv, unit_ty);
1709-
let b_len = b_len_and_data.len;
1710-
let b_elem = b_len_and_data.data;
1711-
bcx = b_len_and_data.bcx;
17121704
// Calculate the last pointer address we want to handle.
17131705
// TODO: Optimize this when the size of the unit type is statically
17141706
// known to not use pointer casts, which tend to confuse LLVM.
17151707

1716-
let len = umin(bcx, a_len, b_len);
1717-
let b_elem_i8 = bcx.build.PointerCast(b_elem, T_ptr(T_i8()));
1718-
let b_end_i8 = bcx.build.GEP(b_elem_i8, ~[len]);
1719-
let b_end = bcx.build.PointerCast(b_end_i8, T_ptr(llunitty));
1708+
let a_elem_i8 = bcx.build.PointerCast(a_elem, T_ptr(T_i8()));
1709+
let a_end_i8 = bcx.build.GEP(a_elem_i8, ~[len]);
1710+
let a_end = bcx.build.PointerCast(a_end_i8, T_ptr(llunitty));
17201711

17211712
let dest_elem_ptr = alloca(bcx, T_ptr(llunitty));
1722-
let src_elem_ptr = alloca(bcx, T_ptr(llunitty));
17231713
bcx.build.Store(a_elem, dest_elem_ptr);
1724-
bcx.build.Store(b_elem, src_elem_ptr);
17251714

17261715
// Now perform the iteration.
17271716
let loop_header_cx = new_sub_block_ctxt(bcx, "iter_ivec_loop_header");
17281717
bcx.build.Br(loop_header_cx.llbb);
17291718
let dest_elem = loop_header_cx.build.Load(dest_elem_ptr);
1730-
let src_elem = loop_header_cx.build.Load(src_elem_ptr);
17311719
let not_yet_at_end =
17321720
loop_header_cx.build.ICmp(lib::llvm::LLVMIntULT, dest_elem,
1733-
b_end);
1721+
a_end);
17341722
let loop_body_cx = new_sub_block_ctxt(bcx, "iter_ivec_loop_body");
17351723
let next_cx = new_sub_block_ctxt(bcx, "iter_ivec_next");
17361724
loop_header_cx.build.CondBr(not_yet_at_end, loop_body_cx.llbb,
17371725
next_cx.llbb);
17381726

1739-
rs =
1740-
f(loop_body_cx,
1741-
load_if_immediate(loop_body_cx, dest_elem, unit_ty),
1742-
load_if_immediate(loop_body_cx, src_elem, unit_ty), unit_ty);
1727+
rs = f(loop_body_cx,
1728+
load_if_immediate(loop_body_cx, dest_elem, unit_ty), unit_ty);
17431729

17441730
loop_body_cx = rs.bcx;
17451731

@@ -1749,15 +1735,14 @@ fn iter_structural_ty_full(cx: &@block_ctxt, av: ValueRef, bv: ValueRef,
17491735
} else { increment = C_int(1); }
17501736

17511737
incr_ptr(loop_body_cx, dest_elem, increment, dest_elem_ptr);
1752-
incr_ptr(loop_body_cx, src_elem, increment, src_elem_ptr);
17531738
loop_body_cx.build.Br(loop_header_cx.llbb);
17541739

17551740
ret rslt(next_cx, C_nil());
17561741
}
17571742

1758-
fn iter_variant(cx: @block_ctxt, a_tup: ValueRef, b_tup: ValueRef,
1743+
fn iter_variant(cx: @block_ctxt, a_tup: ValueRef,
17591744
variant: &ty::variant_info, tps: &[ty::t],
1760-
tid: &ast::def_id, f: &val_pair_and_ty_fn) -> result {
1745+
tid: &ast::def_id, f: &val_and_ty_fn) -> result {
17611746
if std::ivec::len[ty::t](variant.args) == 0u {
17621747
ret rslt(cx, C_nil());
17631748
}
@@ -1770,13 +1755,9 @@ fn iter_structural_ty_full(cx: &@block_ctxt, av: ValueRef, bv: ValueRef,
17701755
let rslt = GEP_tag(cx, a_tup, tid, variant.id, tps, j);
17711756
let llfldp_a = rslt.val;
17721757
cx = rslt.bcx;
1773-
rslt = GEP_tag(cx, b_tup, tid, variant.id, tps, j);
1774-
let llfldp_b = rslt.val;
1775-
cx = rslt.bcx;
17761758
let ty_subst = ty::substitute_type_params(ccx.tcx, tps, a.ty);
17771759
let llfld_a = load_if_immediate(cx, llfldp_a, ty_subst);
1778-
let llfld_b = load_if_immediate(cx, llfldp_b, ty_subst);
1779-
rslt = f(cx, llfld_a, llfld_b, ty_subst);
1760+
rslt = f(cx, llfld_a, ty_subst);
17801761
cx = rslt.bcx;
17811762
j += 1;
17821763
}
@@ -1792,11 +1773,8 @@ fn iter_structural_ty_full(cx: &@block_ctxt, av: ValueRef, bv: ValueRef,
17921773
for fld: ty::field in fields {
17931774
r = GEP_tup_like(r.bcx, t, av, ~[0, i]);
17941775
let llfld_a = r.val;
1795-
r = GEP_tup_like(r.bcx, t, bv, ~[0, i]);
1796-
let llfld_b = r.val;
1797-
r =
1798-
f(r.bcx, load_if_immediate(r.bcx, llfld_a, fld.mt.ty),
1799-
load_if_immediate(r.bcx, llfld_b, fld.mt.ty), fld.mt.ty);
1776+
r = f(r.bcx, load_if_immediate(r.bcx, llfld_a, fld.mt.ty),
1777+
fld.mt.ty);
18001778
i += 1;
18011779
}
18021780
}
@@ -1807,34 +1785,27 @@ fn iter_structural_ty_full(cx: &@block_ctxt, av: ValueRef, bv: ValueRef,
18071785
let tup_t = ty::mk_imm_tup(tcx, ~[ty::mk_int(tcx), inner_t_s]);
18081786
r = GEP_tup_like(r.bcx, tup_t, av, ~[0, 1]);
18091787
let llfld_a = r.val;
1810-
r = GEP_tup_like(r.bcx, tup_t, bv, ~[0, 1]);
1811-
let llfld_b = r.val;
1812-
r = f(r.bcx, load_if_immediate(r.bcx, llfld_a, inner1),
1813-
load_if_immediate(r.bcx, llfld_b, inner1), inner1);
1788+
r = f(r.bcx, load_if_immediate(r.bcx, llfld_a, inner1), inner1);
18141789
}
18151790
ty::ty_tag(tid, tps) {
18161791
let variants = ty::tag_variants(bcx_tcx(cx), tid);
18171792
let n_variants = std::ivec::len(variants);
18181793

18191794
// Cast the tags to types we can GEP into.
18201795
if n_variants == 1u {
1821-
ret iter_variant(cx, av, bv, variants.(0), tps, tid, f);
1796+
ret iter_variant(cx, av, variants.(0), tps, tid, f);
18221797
}
18231798

18241799
let lltagty = T_opaque_tag_ptr(bcx_ccx(cx).tn);
18251800
let av_tag = cx.build.PointerCast(av, lltagty);
1826-
let bv_tag = cx.build.PointerCast(bv, lltagty);
18271801
let lldiscrim_a_ptr = cx.build.GEP(av_tag, ~[C_int(0), C_int(0)]);
18281802
let llunion_a_ptr = cx.build.GEP(av_tag, ~[C_int(0), C_int(1)]);
18291803
let lldiscrim_a = cx.build.Load(lldiscrim_a_ptr);
1830-
let lldiscrim_b_ptr = cx.build.GEP(bv_tag, ~[C_int(0), C_int(0)]);
1831-
let llunion_b_ptr = cx.build.GEP(bv_tag, ~[C_int(0), C_int(1)]);
1832-
let lldiscrim_b = cx.build.Load(lldiscrim_b_ptr);
18331804

18341805
// NB: we must hit the discriminant first so that structural
18351806
// comparison know not to proceed when the discriminants differ.
18361807
let bcx = cx;
1837-
bcx = f(bcx, lldiscrim_a, lldiscrim_b, ty::mk_int(bcx_tcx(cx))).bcx;
1808+
bcx = f(bcx, lldiscrim_a, ty::mk_int(bcx_tcx(cx))).bcx;
18381809
let unr_cx = new_sub_block_ctxt(bcx, "tag-iter-unr");
18391810
unr_cx.build.Unreachable();
18401811
let llswitch = bcx.build.Switch(lldiscrim_a, unr_cx.llbb, n_variants);
@@ -1846,9 +1817,8 @@ fn iter_structural_ty_full(cx: &@block_ctxt, av: ValueRef, bv: ValueRef,
18461817
"tag-iter-variant-" +
18471818
uint::to_str(i, 10u));
18481819
llvm::LLVMAddCase(llswitch, C_int(i as int), variant_cx.llbb);
1849-
variant_cx =
1850-
iter_variant(variant_cx, llunion_a_ptr, llunion_b_ptr,
1851-
variant, tps, tid, f).bcx;
1820+
variant_cx = iter_variant(variant_cx, llunion_a_ptr, variant, tps,
1821+
tid, f).bcx;
18521822
variant_cx.build.Br(next_cx.llbb);
18531823
i += 1u;
18541824
}
@@ -1857,21 +1827,17 @@ fn iter_structural_ty_full(cx: &@block_ctxt, av: ValueRef, bv: ValueRef,
18571827
ty::ty_fn(_, _, _, _, _) {
18581828
let box_cell_a =
18591829
cx.build.GEP(av, ~[C_int(0), C_int(abi::fn_field_box)]);
1860-
let box_cell_b =
1861-
cx.build.GEP(bv, ~[C_int(0), C_int(abi::fn_field_box)]);
1862-
ret iter_boxpp(cx, box_cell_a, box_cell_b, f);
1830+
ret iter_boxpp(cx, box_cell_a, f);
18631831
}
18641832
ty::ty_obj(_) {
18651833
let box_cell_a =
18661834
cx.build.GEP(av, ~[C_int(0), C_int(abi::obj_field_box)]);
1867-
let box_cell_b =
1868-
cx.build.GEP(bv, ~[C_int(0), C_int(abi::obj_field_box)]);
1869-
ret iter_boxpp(cx, box_cell_a, box_cell_b, f);
1835+
ret iter_boxpp(cx, box_cell_a, f);
18701836
}
1871-
ty::ty_ivec(unit_tm) { ret iter_ivec(cx, av, bv, unit_tm.ty, f); }
1837+
ty::ty_ivec(unit_tm) { ret iter_ivec(cx, av, unit_tm.ty, f); }
18721838
ty::ty_istr. {
18731839
let unit_ty = ty::mk_mach(bcx_tcx(cx), ast::ty_u8);
1874-
ret iter_ivec(cx, av, bv, unit_ty, f);
1840+
ret iter_ivec(cx, av, unit_ty, f);
18751841
}
18761842
_ { bcx_ccx(cx).sess.unimpl("type in iter_structural_ty_full"); }
18771843
}

0 commit comments

Comments
 (0)