Skip to content

Commit df3ca7e

Browse files
committed
---
yaml --- r: 2111 b: refs/heads/master c: cc6a9c8 h: refs/heads/master i: 2109: 3dfcc91 2107: b3902c3 2103: c4efcd5 2095: bbdd841 2079: 722cb34 2047: 92c572a v: v3
1 parent 4669723 commit df3ca7e

File tree

2 files changed

+33
-34
lines changed

2 files changed

+33
-34
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: 2214b6835d8bf5b33a3fb8b6a897abaea55ef368
2+
refs/heads/master: cc6a9c88766c3822522d48145d9f5778a21147a6

trunk/src/comp/middle/trans.rs

Lines changed: 32 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,7 @@ fn type_of(@crate_ctxt cx, @ty.t t) -> TypeRef {
532532
fail;
533533
}
534534

535-
ret type_of_inner(cx, t, false);
535+
ret type_of_inner(cx, t);
536536
}
537537

538538
fn type_of_explicit_args(@crate_ctxt cx,
@@ -546,10 +546,10 @@ fn type_of_explicit_args(@crate_ctxt cx,
546546
let TypeRef t;
547547
alt (arg.mode) {
548548
case (ast.alias) {
549-
t = T_ptr(type_of_inner(cx, arg.ty, true));
549+
t = T_ptr(type_of_inner(cx, arg.ty));
550550
}
551551
case (_) {
552-
t = type_of_inner(cx, arg.ty, false);
552+
t = type_of_inner(cx, arg.ty);
553553
}
554554
}
555555
atys += vec(t);
@@ -577,7 +577,7 @@ fn type_of_fn_full(@crate_ctxt cx,
577577
if (ty.type_has_dynamic_size(output)) {
578578
atys += vec(T_typaram_ptr(cx.tn));
579579
} else {
580-
atys += vec(T_ptr(type_of_inner(cx, output, false)));
580+
atys += vec(T_ptr(type_of_inner(cx, output)));
581581
}
582582

583583
// Arg 1: Task pointer.
@@ -644,10 +644,10 @@ fn type_of_native_fn(@crate_ctxt cx, ast.native_abi abi,
644644
}
645645
}
646646
atys += type_of_explicit_args(cx, inputs);
647-
ret T_fn(atys, type_of_inner(cx, output, false));
647+
ret T_fn(atys, type_of_inner(cx, output));
648648
}
649649

650-
fn type_of_inner(@crate_ctxt cx, @ty.t t, bool boxed) -> TypeRef {
650+
fn type_of_inner(@crate_ctxt cx, @ty.t t) -> TypeRef {
651651
let TypeRef llty = 0 as TypeRef;
652652

653653
alt (t.struct) {
@@ -682,28 +682,28 @@ fn type_of_inner(@crate_ctxt cx, @ty.t t, bool boxed) -> TypeRef {
682682
}
683683
}
684684
case (ty.ty_box(?mt)) {
685-
llty = T_ptr(T_box(type_of_inner(cx, mt.ty, true)));
685+
llty = T_ptr(T_box(type_of_inner(cx, mt.ty)));
686686
}
687687
case (ty.ty_vec(?mt)) {
688-
llty = T_ptr(T_vec(type_of_inner(cx, mt.ty, true)));
688+
llty = T_ptr(T_vec(type_of_inner(cx, mt.ty)));
689689
}
690690
case (ty.ty_port(?t)) {
691-
llty = T_ptr(T_port(type_of_inner(cx, t, true)));
691+
llty = T_ptr(T_port(type_of_inner(cx, t)));
692692
}
693693
case (ty.ty_chan(?t)) {
694-
llty = T_ptr(T_chan(type_of_inner(cx, t, true)));
694+
llty = T_ptr(T_chan(type_of_inner(cx, t)));
695695
}
696696
case (ty.ty_tup(?elts)) {
697697
let vec[TypeRef] tys = vec();
698698
for (ty.mt elt in elts) {
699-
tys += vec(type_of_inner(cx, elt.ty, boxed));
699+
tys += vec(type_of_inner(cx, elt.ty));
700700
}
701701
llty = T_struct(tys);
702702
}
703703
case (ty.ty_rec(?fields)) {
704704
let vec[TypeRef] tys = vec();
705705
for (ty.field f in fields) {
706-
tys += vec(type_of_inner(cx, f.mt.ty, boxed));
706+
tys += vec(type_of_inner(cx, f.mt.ty));
707707
}
708708
llty = T_struct(tys);
709709
}
@@ -768,9 +768,9 @@ fn type_of_arg(@crate_ctxt cx, &ty.arg arg) -> TypeRef {
768768

769769
auto typ;
770770
if (arg.mode == ast.alias) {
771-
typ = T_ptr(type_of_inner(cx, arg.ty, true));
771+
typ = T_ptr(type_of_inner(cx, arg.ty));
772772
} else {
773-
typ = type_of_inner(cx, arg.ty, false);
773+
typ = type_of_inner(cx, arg.ty);
774774
}
775775
ret typ;
776776
}
@@ -1099,6 +1099,23 @@ fn array_alloca(@block_ctxt cx, TypeRef t, ValueRef n) -> ValueRef {
10991099
}
11001100

11011101

1102+
// Creates a simpler, size-equivalent type. The resulting type is guaranteed
1103+
// to have (a) the same size as the type that was passed in; (b) to be non-
1104+
// recursive. This is done by replacing all boxes in a type with boxed unit
1105+
// types.
1106+
fn simplify_type(@ty.t typ) -> @ty.t {
1107+
fn simplifier(@ty.t typ) -> @ty.t {
1108+
alt (typ.struct) {
1109+
case (ty.ty_box(_)) {
1110+
ret ty.plain_box_ty(ty.plain_ty(ty.ty_nil), ast.imm);
1111+
}
1112+
case (_) { ret typ; }
1113+
}
1114+
}
1115+
auto f = simplifier;
1116+
ret ty.fold_ty(f, typ);
1117+
}
1118+
11021119
// Computes the size of the data part of a non-dynamically-sized tag.
11031120
fn static_size_of_tag(@crate_ctxt cx, @ty.t t) -> uint {
11041121
if (ty.type_has_dynamic_size(t)) {
@@ -1127,25 +1144,7 @@ fn static_size_of_tag(@crate_ctxt cx, @ty.t t) -> uint {
11271144
auto max_size = 0u;
11281145
auto variants = tag_variants(cx, tid);
11291146
for (variant_info variant in variants) {
1130-
1131-
let vec[@ty.t] args = vec();
1132-
for (@ty.t t in variant.args) {
1133-
alt (t.struct) {
1134-
// NB: We're just going for 'size' here, so we can do a little
1135-
// faking work here and substitute all boxes to boxed ints;
1136-
// this will break any tag cycles we might otherwise traverse
1137-
// (which would cause infinite recursion while measuring
1138-
// size).
1139-
case (ty.ty_box(_)) {
1140-
args += vec(ty.plain_box_ty(ty.plain_ty(ty.ty_int),
1141-
ast.imm));
1142-
}
1143-
case (_) {
1144-
args += vec(t);
1145-
}
1146-
}
1147-
}
1148-
auto tup_ty = ty.plain_tup_ty(args);
1147+
auto tup_ty = simplify_type(ty.plain_tup_ty(variant.args));
11491148

11501149
// Perform any type parameter substitutions.
11511150
tup_ty = ty.bind_params_in_type(tup_ty);

0 commit comments

Comments
 (0)