@@ -532,7 +532,7 @@ fn type_of(@crate_ctxt cx, @ty.t t) -> TypeRef {
532
532
fail;
533
533
}
534
534
535
- ret type_of_inner ( cx, t, false ) ;
535
+ ret type_of_inner ( cx, t) ;
536
536
}
537
537
538
538
fn type_of_explicit_args ( @crate_ctxt cx ,
@@ -546,10 +546,10 @@ fn type_of_explicit_args(@crate_ctxt cx,
546
546
let TypeRef t;
547
547
alt ( arg. mode ) {
548
548
case ( ast. alias ) {
549
- t = T_ptr ( type_of_inner ( cx, arg. ty , true ) ) ;
549
+ t = T_ptr ( type_of_inner ( cx, arg. ty ) ) ;
550
550
}
551
551
case ( _) {
552
- t = type_of_inner ( cx, arg. ty , false ) ;
552
+ t = type_of_inner ( cx, arg. ty ) ;
553
553
}
554
554
}
555
555
atys += vec ( t) ;
@@ -577,7 +577,7 @@ fn type_of_fn_full(@crate_ctxt cx,
577
577
if ( ty. type_has_dynamic_size ( output) ) {
578
578
atys += vec ( T_typaram_ptr ( cx. tn ) ) ;
579
579
} else {
580
- atys += vec ( T_ptr ( type_of_inner ( cx, output, false ) ) ) ;
580
+ atys += vec ( T_ptr ( type_of_inner ( cx, output) ) ) ;
581
581
}
582
582
583
583
// Arg 1: Task pointer.
@@ -644,10 +644,10 @@ fn type_of_native_fn(@crate_ctxt cx, ast.native_abi abi,
644
644
}
645
645
}
646
646
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) ) ;
648
648
}
649
649
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 {
651
651
let TypeRef llty = 0 as TypeRef ;
652
652
653
653
alt ( t. struct ) {
@@ -682,28 +682,28 @@ fn type_of_inner(@crate_ctxt cx, @ty.t t, bool boxed) -> TypeRef {
682
682
}
683
683
}
684
684
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 ) ) ) ;
686
686
}
687
687
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 ) ) ) ;
689
689
}
690
690
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) ) ) ;
692
692
}
693
693
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) ) ) ;
695
695
}
696
696
case ( ty. ty_tup ( ?elts) ) {
697
697
let vec[ TypeRef ] tys = vec ( ) ;
698
698
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 ) ) ;
700
700
}
701
701
llty = T_struct ( tys) ;
702
702
}
703
703
case ( ty. ty_rec ( ?fields) ) {
704
704
let vec[ TypeRef ] tys = vec ( ) ;
705
705
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 ) ) ;
707
707
}
708
708
llty = T_struct ( tys) ;
709
709
}
@@ -768,9 +768,9 @@ fn type_of_arg(@crate_ctxt cx, &ty.arg arg) -> TypeRef {
768
768
769
769
auto typ;
770
770
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 ) ) ;
772
772
} else {
773
- typ = type_of_inner ( cx, arg. ty , false ) ;
773
+ typ = type_of_inner ( cx, arg. ty ) ;
774
774
}
775
775
ret typ;
776
776
}
@@ -1099,6 +1099,23 @@ fn array_alloca(@block_ctxt cx, TypeRef t, ValueRef n) -> ValueRef {
1099
1099
}
1100
1100
1101
1101
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
+
1102
1119
// Computes the size of the data part of a non-dynamically-sized tag.
1103
1120
fn static_size_of_tag( @crate_ctxt cx , @ty. t t ) -> uint {
1104
1121
if ( ty. type_has_dynamic_size ( t) ) {
@@ -1127,25 +1144,7 @@ fn static_size_of_tag(@crate_ctxt cx, @ty.t t) -> uint {
1127
1144
auto max_size = 0 u;
1128
1145
auto variants = tag_variants ( cx, tid) ;
1129
1146
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) ) ;
1149
1148
1150
1149
// Perform any type parameter substitutions.
1151
1150
tup_ty = ty. bind_params_in_type( tup_ty) ;
0 commit comments