Skip to content

Commit 57a5c3a

Browse files
committed
rustc: Factor derived tydesc construction out of get_tydesc()
1 parent 8e7aeed commit 57a5c3a

File tree

1 file changed

+44
-43
lines changed

1 file changed

+44
-43
lines changed

src/comp/middle/trans.rs

Lines changed: 44 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1612,6 +1612,49 @@ fn trans_stack_local_derived_tydesc(@block_ctxt cx, ValueRef llsz,
16121612
ret res(cx, lltydesc);
16131613
}
16141614

1615+
fn mk_derived_tydesc(@block_ctxt cx, ty.t t, bool escapes) -> result {
1616+
let uint n_params = ty.count_ty_params(cx.fcx.lcx.ccx.tcx, t);
1617+
auto tys = linearize_ty_params(cx, t);
1618+
1619+
assert (n_params == _vec.len[uint](tys._0));
1620+
assert (n_params == _vec.len[ValueRef](tys._1));
1621+
1622+
auto root = get_static_tydesc(cx, t, tys._0).tydesc;
1623+
1624+
auto tydescs = alloca(cx, T_array(T_ptr(T_tydesc(cx.fcx.lcx.ccx.tn)),
1625+
1u /* for root*/ + n_params));
1626+
1627+
auto i = 0;
1628+
auto tdp = cx.build.GEP(tydescs, vec(C_int(0), C_int(i)));
1629+
cx.build.Store(root, tdp);
1630+
i += 1;
1631+
for (ValueRef td in tys._1) {
1632+
auto tdp = cx.build.GEP(tydescs, vec(C_int(0), C_int(i)));
1633+
cx.build.Store(td, tdp);
1634+
i += 1;
1635+
}
1636+
1637+
auto bcx = cx;
1638+
auto sz = size_of(bcx, t);
1639+
bcx = sz.bcx;
1640+
auto align = align_of(bcx, t);
1641+
bcx = align.bcx;
1642+
1643+
auto v;
1644+
if (escapes) {
1645+
v = trans_upcall(bcx, "upcall_get_type_desc",
1646+
vec(p2i(bcx.fcx.lcx.ccx.crate_ptr),
1647+
sz.val,
1648+
align.val,
1649+
C_int((1u + n_params) as int),
1650+
vp2i(bcx, tydescs)), true);
1651+
} else {
1652+
v = trans_stack_local_derived_tydesc(bcx, sz.val, align.val, tydescs);
1653+
}
1654+
1655+
ret res(v.bcx, vi2p(v.bcx, v.val, T_ptr(T_tydesc(cx.fcx.lcx.ccx.tn))));
1656+
}
1657+
16151658
fn get_tydesc(&@block_ctxt cx, ty.t t, bool escapes) -> result {
16161659
// Is the supplied type a type param? If so, return the passed-in tydesc.
16171660
alt (ty.type_param(cx.fcx.lcx.ccx.tcx, t)) {
@@ -1622,49 +1665,7 @@ fn get_tydesc(&@block_ctxt cx, ty.t t, bool escapes) -> result {
16221665
// Does it contain a type param? If so, generate a derived tydesc.
16231666

16241667
if (ty.type_contains_params(cx.fcx.lcx.ccx.tcx, t)) {
1625-
1626-
let uint n_params = ty.count_ty_params(cx.fcx.lcx.ccx.tcx, t);
1627-
auto tys = linearize_ty_params(cx, t);
1628-
1629-
assert (n_params == _vec.len[uint](tys._0));
1630-
assert (n_params == _vec.len[ValueRef](tys._1));
1631-
1632-
auto root = get_static_tydesc(cx, t, tys._0).tydesc;
1633-
1634-
auto tydescs = alloca(cx, T_array(T_ptr(T_tydesc(cx.fcx.lcx.ccx.tn)),
1635-
1u /* for root*/ + n_params));
1636-
1637-
auto i = 0;
1638-
auto tdp = cx.build.GEP(tydescs, vec(C_int(0), C_int(i)));
1639-
cx.build.Store(root, tdp);
1640-
i += 1;
1641-
for (ValueRef td in tys._1) {
1642-
auto tdp = cx.build.GEP(tydescs, vec(C_int(0), C_int(i)));
1643-
cx.build.Store(td, tdp);
1644-
i += 1;
1645-
}
1646-
1647-
auto bcx = cx;
1648-
auto sz = size_of(bcx, t);
1649-
bcx = sz.bcx;
1650-
auto align = align_of(bcx, t);
1651-
bcx = align.bcx;
1652-
1653-
auto v;
1654-
if (escapes) {
1655-
v = trans_upcall(bcx, "upcall_get_type_desc",
1656-
vec(p2i(bcx.fcx.lcx.ccx.crate_ptr),
1657-
sz.val,
1658-
align.val,
1659-
C_int((1u + n_params) as int),
1660-
vp2i(bcx, tydescs)), true);
1661-
} else {
1662-
v = trans_stack_local_derived_tydesc(bcx, sz.val, align.val,
1663-
tydescs);
1664-
}
1665-
1666-
ret res(v.bcx, vi2p(v.bcx, v.val,
1667-
T_ptr(T_tydesc(cx.fcx.lcx.ccx.tn))));
1668+
ret mk_derived_tydesc(cx, t, escapes);
16681669
}
16691670

16701671
// Otherwise, generate a tydesc if necessary, and return it.

0 commit comments

Comments
 (0)