Skip to content

Commit 2325366

Browse files
committed
---
yaml --- r: 1461 b: refs/heads/master c: 71f853b h: refs/heads/master i: 1459: a913290 v: v3
1 parent fd1938b commit 2325366

File tree

2 files changed

+33
-4
lines changed

2 files changed

+33
-4
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: bdbaf0c7897366f17e36797e5c9fc7ef12fa9fce
2+
refs/heads/master: 71f853b3fdaede022ac9b680ff2a3767379faacd

trunk/src/comp/middle/trans.rs

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -891,6 +891,26 @@ fn dynamic_size_of(@block_ctxt cx, @ty.t t) -> result {
891891
}
892892
ret align_elements(cx, tys);
893893
}
894+
case (ty.ty_tag(?tid, ?tps)) {
895+
auto bcx = cx;
896+
897+
// Compute max(variant sizes).
898+
let ValueRef max_size = bcx.build.Alloca(T_int());
899+
bcx.build.Store(C_int(0), max_size);
900+
901+
auto variants = tag_variants(bcx.fcx.ccx, tid);
902+
for (ast.variant variant in variants) {
903+
let vec[@ty.t] tys = variant_types(bcx.fcx.ccx, variant);
904+
auto rslt = align_elements(bcx, tys);
905+
bcx = rslt.bcx;
906+
907+
auto this_size = rslt.val;
908+
auto old_max_size = bcx.build.Load(max_size);
909+
bcx.build.Store(umax(bcx, this_size, old_max_size), max_size);
910+
}
911+
912+
ret res(bcx, bcx.build.Load(max_size));
913+
}
894914
}
895915
}
896916

@@ -1450,16 +1470,25 @@ fn decr_refcnt_and_if_zero(@block_ctxt cx,
14501470

14511471
// Tag information
14521472

1453-
fn type_of_variant(@crate_ctxt cx, &ast.variant v) -> TypeRef {
1454-
let vec[TypeRef] lltys = vec();
1473+
fn variant_types(@crate_ctxt cx, &ast.variant v) -> vec[@ty.t] {
1474+
let vec[@ty.t] tys = vec();
14551475
alt (ty.ann_to_type(v.ann).struct) {
14561476
case (ty.ty_fn(_, ?args, _)) {
14571477
for (ty.arg arg in args) {
1458-
lltys += vec(type_of(cx, arg.ty));
1478+
tys += vec(arg.ty);
14591479
}
14601480
}
14611481
case (_) { fail; }
14621482
}
1483+
ret tys;
1484+
}
1485+
1486+
fn type_of_variant(@crate_ctxt cx, &ast.variant v) -> TypeRef {
1487+
let vec[TypeRef] lltys = vec();
1488+
auto tys = variant_types(cx, v);
1489+
for (@ty.t typ in tys) {
1490+
lltys += vec(type_of(cx, typ));
1491+
}
14631492
ret T_struct(lltys);
14641493
}
14651494

0 commit comments

Comments
 (0)