Skip to content

Commit 0e6f59c

Browse files
committed
---
yaml --- r: 1445 b: refs/heads/master c: 9c928fc h: refs/heads/master i: 1443: 2f4b931 v: v3
1 parent 2ddeef8 commit 0e6f59c

File tree

2 files changed

+43
-63
lines changed

2 files changed

+43
-63
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: b5081a6a825f23b45920cf72896076039f30386d
2+
refs/heads/master: 9c928fcf8c584659274bdb9095e47f2fa963d05c

trunk/src/comp/middle/trans.rs

Lines changed: 42 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1457,13 +1457,11 @@ fn type_of_variant(@crate_ctxt cx, &ast.variant v) -> TypeRef {
14571457
ret T_struct(lltys);
14581458
}
14591459

1460-
// Returns the number of variants in a tag.
1461-
fn tag_variant_count(@crate_ctxt cx, ast.def_id id) -> uint {
1460+
// Returns the variants in a tag.
1461+
fn tag_variants(@crate_ctxt cx, ast.def_id id) -> vec[ast.variant] {
14621462
check (cx.items.contains_key(id));
14631463
alt (cx.items.get(id).node) {
1464-
case (ast.item_tag(_, ?variants, _, _)) {
1465-
ret _vec.len[ast.variant](variants);
1466-
}
1464+
case (ast.item_tag(_, ?variants, _, _)) { ret variants; }
14671465
}
14681466
fail; // not reached
14691467
}
@@ -1519,21 +1517,9 @@ fn iter_structural_ty(@block_ctxt cx,
15191517
case (ty.ty_tag(?tid, ?tps)) {
15201518
check (cx.fcx.ccx.tags.contains_key(tid));
15211519
auto info = cx.fcx.ccx.tags.get(tid);
1522-
auto n_variants = tag_variant_count(cx.fcx.ccx, tid);
1523-
1524-
// Look up the tag in the typechecked AST.
1525-
check (cx.fcx.ccx.items.contains_key(tid));
1526-
auto tag_item = cx.fcx.ccx.items.get(tid);
1527-
let vec[ast.variant] variants = vec(); // FIXME: typestate bug
1528-
alt (tag_item.node) {
1529-
case (ast.item_tag(_, ?vs, _, _)) {
1530-
variants = vs;
1531-
}
1532-
case (_) {
1533-
log "trans: ty_tag doesn't actually refer to a tag";
1534-
fail;
1535-
}
1536-
}
1520+
1521+
auto variants = tag_variants(cx.fcx.ccx, tid);
1522+
auto n_variants = _vec.len[ast.variant](variants);
15371523

15381524
auto lldiscrim_ptr = cx.build.GEP(v, vec(C_int(0), C_int(0)));
15391525
auto llunion_ptr = cx.build.GEP(v, vec(C_int(0), C_int(1)));
@@ -1548,55 +1534,49 @@ fn iter_structural_ty(@block_ctxt cx,
15481534
auto next_cx = new_sub_block_ctxt(cx, "tag-iter-next");
15491535

15501536
auto i = 0u;
1551-
for (tup(ast.def_id,arity) variant in info.variants) {
1537+
for (ast.variant variant in variants) {
15521538
auto variant_cx = new_sub_block_ctxt(cx, "tag-iter-variant-" +
15531539
_uint.to_str(i, 10u));
15541540
llvm.LLVMAddCase(llswitch, C_int(i as int), variant_cx.llbb);
15551541

1556-
alt (variant._1) {
1557-
case (n_ary) {
1558-
let vec[ValueRef] vals = vec(C_int(0), C_int(1),
1559-
C_int(i as int));
1560-
auto llvar = variant_cx.build.GEP(v, vals);
1561-
auto llvarty = type_of_variant(cx.fcx.ccx,
1562-
variants.(i));
1563-
1564-
auto fn_ty = ty.ann_to_type(variants.(i).ann);
1565-
alt (fn_ty.struct) {
1566-
case (ty.ty_fn(_, ?args, _)) {
1567-
auto llvarp = variant_cx.build.
1568-
TruncOrBitCast(llunion_ptr,
1569-
T_ptr(llvarty));
1570-
1571-
auto j = 0u;
1572-
for (ty.arg a in args) {
1573-
auto v = vec(C_int(0),
1574-
C_int(j as int));
1575-
auto llfldp =
1576-
variant_cx.build.GEP(llvarp, v);
1577-
1578-
auto ty_subst = ty.substitute_ty_params(
1579-
info.ty_params, tps, a.ty);
1580-
1581-
auto llfld =
1582-
load_scalar_or_boxed(variant_cx,
1583-
llfldp,
1584-
ty_subst);
1585-
1586-
auto res = f(variant_cx, llfld, ty_subst);
1587-
variant_cx = res.bcx;
1588-
j += 1u;
1589-
}
1542+
if (_vec.len[ast.variant_arg](variant.args) > 0u) {
1543+
// N-ary variant.
1544+
let vec[ValueRef] vals = vec(C_int(0), C_int(1),
1545+
C_int(i as int));
1546+
auto llvar = variant_cx.build.GEP(v, vals);
1547+
auto llvarty = type_of_variant(cx.fcx.ccx, variants.(i));
1548+
1549+
auto fn_ty = ty.ann_to_type(variants.(i).ann);
1550+
alt (fn_ty.struct) {
1551+
case (ty.ty_fn(_, ?args, _)) {
1552+
auto llvarp = variant_cx.build.
1553+
TruncOrBitCast(llunion_ptr, T_ptr(llvarty));
1554+
1555+
auto j = 0u;
1556+
for (ty.arg a in args) {
1557+
auto v = vec(C_int(0), C_int(j as int));
1558+
auto llfldp = variant_cx.build.GEP(llvarp, v);
1559+
1560+
auto ty_subst = ty.substitute_ty_params(
1561+
info.ty_params, tps, a.ty);
1562+
1563+
auto llfld =
1564+
load_scalar_or_boxed(variant_cx,
1565+
llfldp,
1566+
ty_subst);
1567+
1568+
auto res = f(variant_cx, llfld, ty_subst);
1569+
variant_cx = res.bcx;
1570+
j += 1u;
15901571
}
1591-
case (_) { fail; }
15921572
}
1593-
1594-
variant_cx.build.Br(next_cx.llbb);
1595-
}
1596-
case (nullary) {
1597-
// Nothing to do.
1598-
variant_cx.build.Br(next_cx.llbb);
1573+
case (_) { fail; }
15991574
}
1575+
1576+
variant_cx.build.Br(next_cx.llbb);
1577+
} else {
1578+
// Nullary variant; nothing to do.
1579+
variant_cx.build.Br(next_cx.llbb);
16001580
}
16011581

16021582
i += 1u;

0 commit comments

Comments
 (0)