@@ -1120,8 +1120,8 @@ fn static_size_of_tag(@crate_ctxt cx, @ty.t t) -> uint {
1120
1120
// Compute max(variant sizes).
1121
1121
auto max_size = 0 u;
1122
1122
auto variants = tag_variants ( cx, tid) ;
1123
- for ( ast . variant variant in variants) {
1124
- auto tup_ty = ty. plain_tup_ty( variant_types ( cx , variant) ) ;
1123
+ for ( variant_info variant in variants) {
1124
+ auto tup_ty = ty. plain_tup_ty( variant. args ) ;
1125
1125
1126
1126
// Perform any type parameter substitutions.
1127
1127
tup_ty = ty. substitute_ty_params( ty_params, subtys, tup_ty) ;
@@ -1192,9 +1192,9 @@ fn dynamic_size_of(@block_ctxt cx, @ty.t t) -> result {
1192
1192
1193
1193
auto ty_params = tag_ty_params( bcx. fcx. ccx, tid) ;
1194
1194
auto variants = tag_variants( bcx. fcx. ccx, tid) ;
1195
- for ( ast . variant variant in variants) {
1196
- // Perform type substitution on the raw variant types.
1197
- let vec[ @ty. t] raw_tys = variant_types ( bcx . fcx . ccx , variant) ;
1195
+ for ( variant_info variant in variants) {
1196
+ // Perform type substitution on the raw argument types.
1197
+ let vec[ @ty. t] raw_tys = variant. args ;
1198
1198
let vec[ @ty. t] tys = vec( ) ;
1199
1199
for ( @ty. t raw_ty in raw_tys) {
1200
1200
auto t = ty. substitute_ty_params( ty_params, tps, raw_ty) ;
@@ -1367,12 +1367,12 @@ fn GEP_tag(@block_ctxt cx,
1367
1367
1368
1368
// Synthesize a tuple type so that GEP_tup_like() can work its magic.
1369
1369
// Separately, store the type of the element we're interested in.
1370
- auto arg_tys = arg_tys_of_fn ( variant. node . ann ) ;
1370
+ auto arg_tys = variant. args ;
1371
1371
auto elem_ty = ty. plain_ty ( ty. ty_nil ) ; // typestate infelicity
1372
1372
auto i = 0 ;
1373
1373
let vec[ @ty. t] true_arg_tys = vec ( ) ;
1374
- for ( ty. arg a in arg_tys) {
1375
- auto arg_ty = ty. substitute_ty_params( ty_params, ty_substs, a . ty ) ;
1374
+ for ( @ ty. t aty in arg_tys) {
1375
+ auto arg_ty = ty. substitute_ty_params( ty_params, ty_substs, aty ) ;
1376
1376
true_arg_tys += vec( arg_ty) ;
1377
1377
if ( i == ix) {
1378
1378
elem_ty = arg_ty;
@@ -1902,44 +1902,47 @@ fn decr_refcnt_and_if_zero(@block_ctxt cx,
1902
1902
1903
1903
// Tag information
1904
1904
1905
- fn variant_types( @crate_ctxt cx, & ast. variant v) -> vec[ @ty. t] {
1906
- let vec[ @ty. t] tys = vec( ) ;
1907
- alt ( ty. ann_to_type( v. node. ann) . struct ) {
1908
- case ( ty. ty_fn( _, ?args, _) ) {
1909
- for ( ty. arg arg in args) {
1910
- tys += vec( arg. ty) ;
1911
- }
1912
- }
1913
- case ( ty. ty_tag( _, _) ) { /* nothing */ }
1914
- case ( _) { fail; }
1915
- }
1916
- ret tys;
1917
- }
1918
-
1919
1905
// Returns the type parameters of a tag.
1920
1906
fn tag_ty_params( @crate_ctxt cx, ast. def_id id) -> vec[ ast. def_id] {
1921
1907
ret ty. lookup_generic_item_type( cx. sess, cx. type_cache, id) . _0;
1922
1908
}
1923
1909
1924
- // Returns the variants in a tag.
1925
- fn tag_variants( @crate_ctxt cx, ast. def_id id) -> vec[ ast. variant] {
1910
+ type variant_info = rec( vec[ @ty. t] args, @ty. t ctor_ty, ast. def_id id) ;
1911
+
1912
+ // Returns information about the variants in a tag.
1913
+ fn tag_variants( @crate_ctxt cx, ast. def_id id) -> vec[ variant_info] {
1914
+ // FIXME: This doesn't work for external variants.
1926
1915
check ( cx. items. contains_key( id) ) ;
1927
1916
alt ( cx. items. get( id) . node) {
1928
- case ( ast. item_tag( _, ?variants, _, _, _) ) { ret variants; }
1917
+ case ( ast. item_tag( _, ?variants, _, _, _) ) {
1918
+ let vec[ variant_info] result = vec( ) ;
1919
+ for ( ast. variant variant in variants) {
1920
+ auto ctor_ty = node_ann_type( cx, variant. node. ann) ;
1921
+ let vec[ @ty. t] arg_tys = vec( ) ;
1922
+ if ( _vec. len[ ast. variant_arg] ( variant. node. args) > 0 u) {
1923
+ for ( ty. arg a in ty. ty_fn_args ( ctor_ty) ) {
1924
+ arg_tys += vec ( a. ty ) ;
1925
+ }
1926
+ }
1927
+ auto did = variant. node . id ;
1928
+ result += vec ( rec ( args=arg_tys, ctor_ty=ctor_ty, id=did) ) ;
1929
+ }
1930
+ ret result;
1931
+ }
1929
1932
}
1930
1933
fail; // not reached
1931
1934
}
1932
1935
1933
- // Returns the tag variant with the given ID.
1936
+ // Returns information about the tag variant with the given ID.
1934
1937
fn tag_variant_with_id( @crate_ctxt cx,
1935
1938
& ast. def_id tag_id ,
1936
- & ast. def_id variant_id) -> ast . variant {
1939
+ & ast. def_id variant_id) -> variant_info {
1937
1940
auto variants = tag_variants ( cx, tag_id) ;
1938
1941
1939
1942
auto i = 0 u;
1940
- while ( i < _vec. len[ ast . variant ] ( variants) ) {
1943
+ while ( i < _vec. len [ variant_info ] ( variants) ) {
1941
1944
auto variant = variants. ( i) ;
1942
- if ( common. def_eq( variant. node . id, variant_id) ) {
1945
+ if ( common. def_eq ( variant. id , variant_id) ) {
1943
1946
ret variant;
1944
1947
}
1945
1948
i += 1 u;
@@ -2040,7 +2043,7 @@ fn iter_structural_ty_full(@block_ctxt cx,
2040
2043
}
2041
2044
case ( ty. ty_tag ( ?tid, ?tps) ) {
2042
2045
auto variants = tag_variants ( cx. fcx . ccx , tid) ;
2043
- auto n_variants = _vec. len[ ast . variant ] ( variants) ;
2046
+ auto n_variants = _vec. len [ variant_info ] ( variants) ;
2044
2047
2045
2048
// Cast the tags to types we can GEP into.
2046
2049
auto lltagty = T_opaque_tag_ptr ( cx. fcx . ccx . tn ) ;
@@ -2076,28 +2079,28 @@ fn iter_structural_ty_full(@block_ctxt cx,
2076
2079
auto ty_params = tag_ty_params ( bcx. fcx . ccx , tid) ;
2077
2080
2078
2081
auto i = 0 u;
2079
- for ( ast . variant variant in variants) {
2082
+ for ( variant_info variant in variants) {
2080
2083
auto variant_cx = new_sub_block_ctxt( bcx,
2081
2084
"tag-iter-variant-" +
2082
2085
_uint. to_str( i, 10 u) ) ;
2083
2086
llvm. LLVMAddCase ( llswitch, C_int ( i as int) , variant_cx. llbb) ;
2084
2087
2085
- if ( _vec. len[ ast . variant_arg ] ( variant. node . args) > 0 u) {
2088
+ if ( _vec. len[ @ty . t ] ( variant. args) > 0 u) {
2086
2089
// N-ary variant.
2087
- auto fn_ty = ty . ann_to_type ( variants . ( i ) . node . ann ) ;
2090
+ auto fn_ty = variant . ctor_ty ;
2088
2091
alt ( fn_ty. struct ) {
2089
2092
case ( ty. ty_fn( _, ?args, _) ) {
2090
2093
auto j = 0 ;
2091
2094
for ( ty. arg a in args) {
2092
2095
auto v = vec( C_int ( 0 ) , C_int ( j as int) ) ;
2093
2096
2094
2097
auto rslt = GEP_tag ( variant_cx, llunion_a_ptr,
2095
- tid, variants . ( i ) . node . id, tps, j) ;
2098
+ tid, variant . id, tps, j) ;
2096
2099
auto llfldp_a = rslt. val;
2097
2100
variant_cx = rslt. bcx;
2098
2101
2099
2102
rslt = GEP_tag ( variant_cx, llunion_b_ptr, tid,
2100
- variants . ( i ) . node . id, tps, j) ;
2103
+ variant . id, tps, j) ;
2101
2104
auto llfldp_b = rslt. val;
2102
2105
variant_cx = rslt. bcx;
2103
2106
@@ -3454,8 +3457,8 @@ fn trans_pat_match(@block_ctxt cx, @ast.pat pat, ValueRef llval,
3454
3457
3455
3458
auto variants = tag_variants( cx. fcx. ccx, vdef. _0) ;
3456
3459
auto i = 0 ;
3457
- for ( ast . variant v in variants) {
3458
- auto this_variant_id = v. node . id;
3460
+ for ( variant_info v in variants) {
3461
+ auto this_variant_id = v. id;
3459
3462
if ( variant_id. _0 == this_variant_id. _0 &&
3460
3463
variant_id. _1 == this_variant_id. _1) {
3461
3464
variant_tag = i;
0 commit comments