@@ -39,12 +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
+ type ty_param_table = hashmap [ ast. def_id , vec [ ast . def_id ] ] ;
43
43
44
44
type crate_ctxt = rec ( session . session sess,
45
45
@ty_table item_types ,
46
46
@ty_item_table item_items ,
47
- @ty_param_count_table ty_param_counts ,
47
+ @ty_param_table item_ty_params ,
48
48
vec[ ast. obj_field] obj_fields ,
49
49
mutable int next_var_id ) ;
50
50
@@ -358,7 +358,7 @@ fn ty_of_native_fn_decl(@ty_item_table id_to_ty_item,
358
358
}
359
359
360
360
fn collect_item_types( session. session sess, @ast. crate crate)
361
- -> tup( @ast. crate , @ty_table, @ty_item_table, @ty_param_count_table ) {
361
+ -> tup( @ast. crate , @ty_table, @ty_item_table, @ty_param_table ) {
362
362
363
363
fn getter( @ty_item_table id_to_ty_item,
364
364
@ty_table item_to_ty,
@@ -602,19 +602,29 @@ fn collect_item_types(session.session sess, @ast.crate crate)
602
602
603
603
// Second pass: translate the types of all items.
604
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 ] ( ) ;
605
+ auto item_ty_params = @common. new_def_hash[ vec [ ast . def_id ] ] ( ) ;
606
606
607
607
type env = rec( session. session sess,
608
608
@ty_item_table id_to_ty_item,
609
609
@ty_table item_to_ty,
610
- @ty_param_count_table ty_param_counts ,
610
+ @ty_param_table item_ty_params ,
611
611
ast. native_abi abi) ;
612
612
let @env e = @rec( sess=sess,
613
613
id_to_ty_item=id_to_ty_item,
614
614
item_to_ty=item_to_ty,
615
- ty_param_counts=ty_param_counts ,
615
+ item_ty_params=item_ty_params ,
616
616
abi=ast. native_abi_cdecl) ;
617
617
618
+ // Inserts the given type parameters into the type parameter table of the
619
+ // environment.
620
+ fn collect_ty_params( & @env e, & ast. def_id id, vec[ ast. ty_param] tps) {
621
+ let vec[ ast. def_id] result = vec( ) ;
622
+ for ( ast. ty_param tp in tps) {
623
+ result += vec( tp. id) ;
624
+ }
625
+ e. item_ty_params. insert( id, result) ;
626
+ }
627
+
618
628
fn convert( & @env e, @ast. item i) -> @env {
619
629
auto abi = e. abi;
620
630
alt ( i. node) {
@@ -652,7 +662,7 @@ fn collect_item_types(session.session sess, @ast.crate crate)
652
662
fn fold_item_fn( & @env e, & span sp, ast. ident i,
653
663
& ast. _fn f, vec[ ast. ty_param] ty_params,
654
664
ast. def_id id, ast. ann a) -> @ast. item {
655
- e . ty_param_counts . insert ( id, _vec . len [ ast . ty_param ] ( ty_params) ) ;
665
+ collect_ty_params ( e , id, ty_params) ;
656
666
657
667
check ( e. item_to_ty. contains_key( id) ) ;
658
668
auto ty = e. item_to_ty. get( id) ;
@@ -664,7 +674,7 @@ fn collect_item_types(session.session sess, @ast.crate crate)
664
674
fn fold_native_item_fn( & @env e, & span sp, ast. ident i,
665
675
& ast. fn_decl d, vec[ ast. ty_param] ty_params,
666
676
ast. def_id id, ast. ann a) -> @ast. native_item {
667
- e . ty_param_counts . insert ( id, _vec . len [ ast . ty_param ] ( ty_params) ) ;
677
+ collect_ty_params ( e , id, ty_params) ;
668
678
669
679
check ( e. item_to_ty. contains_key( id) ) ;
670
680
auto ty = e. item_to_ty. get( id) ;
@@ -697,7 +707,7 @@ fn collect_item_types(session.session sess, @ast.crate crate)
697
707
fn fold_item_obj( & @env e, & span sp, ast. ident i,
698
708
& ast. _obj ob, vec[ ast. ty_param] ty_params,
699
709
ast. def_id id, ast. ann a) -> @ast. item {
700
- e . ty_param_counts . insert ( id, _vec . len [ ast . ty_param ] ( ty_params) ) ;
710
+ collect_ty_params ( e , id, ty_params) ;
701
711
702
712
check ( e. item_to_ty. contains_key( id) ) ;
703
713
auto t = e. item_to_ty. get( id) ;
@@ -737,7 +747,7 @@ fn collect_item_types(session.session sess, @ast.crate crate)
737
747
fn fold_item_ty( & @env e, & span sp, ast. ident i,
738
748
@ast. ty t, vec[ ast. ty_param] ty_params,
739
749
ast. def_id id, ast. ann a) -> @ast. item {
740
- e . ty_param_counts . insert ( id, _vec . len [ ast . ty_param ] ( ty_params) ) ;
750
+ collect_ty_params ( e , id, ty_params) ;
741
751
742
752
check ( e. item_to_ty. contains_key( id) ) ;
743
753
auto ty = e. item_to_ty. get( id) ;
@@ -750,7 +760,7 @@ fn collect_item_types(session.session sess, @ast.crate crate)
750
760
vec[ ast. variant] variants,
751
761
vec[ ast. ty_param] ty_params,
752
762
ast. def_id id) -> @ast. item {
753
- e . ty_param_counts . insert ( id, _vec . len [ ast . ty_param ] ( ty_params) ) ;
763
+ collect_ty_params ( e , id, ty_params) ;
754
764
755
765
auto variants_t = get_tag_variant_types( e. id_to_ty_item,
756
766
e. item_to_ty,
@@ -773,7 +783,7 @@ fn collect_item_types(session.session sess, @ast.crate crate)
773
783
fold_item_tag = bind fold_item_tag( _, _, _, _, _, _)
774
784
with * fld_2) ;
775
785
auto crate_ = fold. fold_crate[ @env] ( e, fld_2, crate ) ;
776
- ret tup( crate_, item_to_ty, id_to_ty_item, ty_param_counts ) ;
786
+ ret tup( crate_, item_to_ty, id_to_ty_item, item_ty_params ) ;
777
787
}
778
788
779
789
fn unify( & @fn_ctxt fcx, @ty. t expected, @ty. t actual) -> ty. unify_result {
@@ -2270,7 +2280,7 @@ fn check_crate(session.session sess, @ast.crate crate) -> @ast.crate {
2270
2280
auto ccx = @rec( sess=sess,
2271
2281
item_types=result. _1,
2272
2282
item_items=result. _2,
2273
- ty_param_counts =result. _3 ,
2283
+ item_ty_params =result. _3,
2274
2284
obj_fields=fields,
2275
2285
mutable next_var_id=0 ) ;
2276
2286
0 commit comments