@@ -39,10 +39,12 @@ tag any_item {
39
39
}
40
40
41
41
type ty_item_table = hashmap [ ast. def_id , any_item] ;
42
+ type ty_param_count_table = hashmap [ ast. def_id , uint] ;
42
43
43
44
type crate_ctxt = rec ( session . session sess,
44
45
@ty_table item_types ,
45
46
@ty_item_table item_items ,
47
+ @ty_param_count_table ty_param_counts ,
46
48
vec[ ast. obj_field] obj_fields ,
47
49
mutable int next_var_id ) ;
48
50
@@ -356,7 +358,7 @@ fn ty_of_native_fn_decl(@ty_item_table id_to_ty_item,
356
358
}
357
359
358
360
fn collect_item_types( session. session sess, @ast. crate crate)
359
- -> tup( @ast. crate , @ty_table, @ty_item_table) {
361
+ -> tup( @ast. crate , @ty_table, @ty_item_table, @ty_param_count_table ) {
360
362
361
363
fn getter( @ty_item_table id_to_ty_item,
362
364
@ty_table item_to_ty,
@@ -600,14 +602,17 @@ fn collect_item_types(session.session sess, @ast.crate crate)
600
602
601
603
// Second pass: translate the types of all items.
602
604
let @ty_table item_to_ty = @common. new_def_hash[ @ty. t] ( ) ;
605
+ let @ty_param_count_table ty_param_counts = @common. new_def_hash[ uint] ( ) ;
603
606
604
607
type env = rec( session. session sess,
605
608
@ty_item_table id_to_ty_item,
606
609
@ty_table item_to_ty,
610
+ @ty_param_count_table ty_param_counts,
607
611
ast. native_abi abi) ;
608
612
let @env e = @rec( sess=sess,
609
613
id_to_ty_item=id_to_ty_item,
610
614
item_to_ty=item_to_ty,
615
+ ty_param_counts=ty_param_counts,
611
616
abi=ast. native_abi_cdecl) ;
612
617
613
618
fn convert( & @env e, @ast. item i) -> @env {
@@ -647,6 +652,8 @@ fn collect_item_types(session.session sess, @ast.crate crate)
647
652
fn fold_item_fn( & @env e, & span sp, ast. ident i,
648
653
& ast. _fn f, vec[ ast. ty_param] ty_params,
649
654
ast. def_id id, ast. ann a) -> @ast. item {
655
+ e. ty_param_counts. insert( id, _vec. len[ ast. ty_param] ( ty_params) ) ;
656
+
650
657
check ( e. item_to_ty. contains_key( id) ) ;
651
658
auto ty = e. item_to_ty. get( id) ;
652
659
auto item = ast. item_fn( i, f, ty_params, id,
@@ -657,6 +664,8 @@ fn collect_item_types(session.session sess, @ast.crate crate)
657
664
fn fold_native_item_fn( & @env e, & span sp, ast. ident i,
658
665
& ast. fn_decl d, vec[ ast. ty_param] ty_params,
659
666
ast. def_id id, ast. ann a) -> @ast. native_item {
667
+ e. ty_param_counts. insert( id, _vec. len[ ast. ty_param] ( ty_params) ) ;
668
+
660
669
check ( e. item_to_ty. contains_key( id) ) ;
661
670
auto ty = e. item_to_ty. get( id) ;
662
671
auto item = ast. native_item_fn( i, d, ty_params, id,
@@ -688,6 +697,8 @@ fn collect_item_types(session.session sess, @ast.crate crate)
688
697
fn fold_item_obj( & @env e, & span sp, ast. ident i,
689
698
& ast. _obj ob, vec[ ast. ty_param] ty_params,
690
699
ast. def_id id, ast. ann a) -> @ast. item {
700
+ e. ty_param_counts. insert( id, _vec. len[ ast. ty_param] ( ty_params) ) ;
701
+
691
702
check ( e. item_to_ty. contains_key( id) ) ;
692
703
auto t = e. item_to_ty. get( id) ;
693
704
let vec[ method] meth_tys = get_ctor_obj_methods( t) ;
@@ -726,6 +737,8 @@ fn collect_item_types(session.session sess, @ast.crate crate)
726
737
fn fold_item_ty ( & @env e , & span sp, ast . ident i,
727
738
@ast. ty t , vec[ ast. ty_param] ty_params ,
728
739
ast. def_id id , ast . ann a) -> @ast . item {
740
+ e. ty_param_counts . insert ( id, _vec. len [ ast. ty_param ] ( ty_params) ) ;
741
+
729
742
check ( e. item_to_ty . contains_key ( id) ) ;
730
743
auto ty = e. item_to_ty . get ( id) ;
731
744
auto item = ast. item_ty ( i, t, ty_params, id,
@@ -737,6 +750,8 @@ fn collect_item_types(session.session sess, @ast.crate crate)
737
750
vec[ ast. variant] variants ,
738
751
vec[ ast. ty_param] ty_params ,
739
752
ast. def_id id ) -> @ast . item {
753
+ e. ty_param_counts . insert ( id, _vec. len [ ast. ty_param ] ( ty_params) ) ;
754
+
740
755
auto variants_t = get_tag_variant_types ( e. id_to_ty_item ,
741
756
e. item_to_ty ,
742
757
id,
@@ -758,7 +773,7 @@ fn collect_item_types(session.session sess, @ast.crate crate)
758
773
fold_item_tag = bind fold_item_tag ( _, _, _, _, _, _)
759
774
with * fld_2) ;
760
775
auto crate_ = fold. fold_crate [ @env] ( e, fld_2, crate ) ;
761
- ret tup( crate_, item_to_ty, id_to_ty_item) ;
776
+ ret tup( crate_, item_to_ty, id_to_ty_item, ty_param_counts ) ;
762
777
}
763
778
764
779
fn unify ( & @fn_ctxt fcx , @ty. t expected , @ty. t actual ) -> ty. unify_result {
@@ -2255,6 +2270,7 @@ fn check_crate(session.session sess, @ast.crate crate) -> @ast.crate {
2255
2270
auto ccx = @rec ( sess=sess,
2256
2271
item_types=result. _1 ,
2257
2272
item_items=result. _2 ,
2273
+ ty_param_counts=result. _3 ,
2258
2274
obj_fields=fields,
2259
2275
mutable next_var_id=0 ) ;
2260
2276
0 commit comments