Skip to content

Commit 0054efc

Browse files
committed
rustc: Store the number of type parameters per item, which will be needed to get unused type params working
1 parent 5aabe7e commit 0054efc

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

src/comp/middle/typeck.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,12 @@ tag any_item {
3939
}
4040

4141
type ty_item_table = hashmap[ast.def_id,any_item];
42+
type ty_param_count_table = hashmap[ast.def_id,uint];
4243

4344
type crate_ctxt = rec(session.session sess,
4445
@ty_table item_types,
4546
@ty_item_table item_items,
47+
@ty_param_count_table ty_param_counts,
4648
vec[ast.obj_field] obj_fields,
4749
mutable int next_var_id);
4850

@@ -356,7 +358,7 @@ fn ty_of_native_fn_decl(@ty_item_table id_to_ty_item,
356358
}
357359

358360
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) {
360362

361363
fn getter(@ty_item_table id_to_ty_item,
362364
@ty_table item_to_ty,
@@ -600,14 +602,17 @@ fn collect_item_types(session.session sess, @ast.crate crate)
600602

601603
// Second pass: translate the types of all items.
602604
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]();
603606

604607
type env = rec(session.session sess,
605608
@ty_item_table id_to_ty_item,
606609
@ty_table item_to_ty,
610+
@ty_param_count_table ty_param_counts,
607611
ast.native_abi abi);
608612
let @env e = @rec(sess=sess,
609613
id_to_ty_item=id_to_ty_item,
610614
item_to_ty=item_to_ty,
615+
ty_param_counts=ty_param_counts,
611616
abi=ast.native_abi_cdecl);
612617

613618
fn convert(&@env e, @ast.item i) -> @env {
@@ -647,6 +652,8 @@ fn collect_item_types(session.session sess, @ast.crate crate)
647652
fn fold_item_fn(&@env e, &span sp, ast.ident i,
648653
&ast._fn f, vec[ast.ty_param] ty_params,
649654
ast.def_id id, ast.ann a) -> @ast.item {
655+
e.ty_param_counts.insert(id, _vec.len[ast.ty_param](ty_params));
656+
650657
check (e.item_to_ty.contains_key(id));
651658
auto ty = e.item_to_ty.get(id);
652659
auto item = ast.item_fn(i, f, ty_params, id,
@@ -657,6 +664,8 @@ fn collect_item_types(session.session sess, @ast.crate crate)
657664
fn fold_native_item_fn(&@env e, &span sp, ast.ident i,
658665
&ast.fn_decl d, vec[ast.ty_param] ty_params,
659666
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+
660669
check (e.item_to_ty.contains_key(id));
661670
auto ty = e.item_to_ty.get(id);
662671
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)
688697
fn fold_item_obj(&@env e, &span sp, ast.ident i,
689698
&ast._obj ob, vec[ast.ty_param] ty_params,
690699
ast.def_id id, ast.ann a) -> @ast.item {
700+
e.ty_param_counts.insert(id, _vec.len[ast.ty_param](ty_params));
701+
691702
check (e.item_to_ty.contains_key(id));
692703
auto t = e.item_to_ty.get(id);
693704
let vec[method] meth_tys = get_ctor_obj_methods(t);
@@ -726,6 +737,8 @@ fn collect_item_types(session.session sess, @ast.crate crate)
726737
fn fold_item_ty(&@env e, &span sp, ast.ident i,
727738
@ast.ty t, vec[ast.ty_param] ty_params,
728739
ast.def_id id, ast.ann a) -> @ast.item {
740+
e.ty_param_counts.insert(id, _vec.len[ast.ty_param](ty_params));
741+
729742
check (e.item_to_ty.contains_key(id));
730743
auto ty = e.item_to_ty.get(id);
731744
auto item = ast.item_ty(i, t, ty_params, id,
@@ -737,6 +750,8 @@ fn collect_item_types(session.session sess, @ast.crate crate)
737750
vec[ast.variant] variants,
738751
vec[ast.ty_param] ty_params,
739752
ast.def_id id) -> @ast.item {
753+
e.ty_param_counts.insert(id, _vec.len[ast.ty_param](ty_params));
754+
740755
auto variants_t = get_tag_variant_types(e.id_to_ty_item,
741756
e.item_to_ty,
742757
id,
@@ -758,7 +773,7 @@ fn collect_item_types(session.session sess, @ast.crate crate)
758773
fold_item_tag = bind fold_item_tag(_,_,_,_,_,_)
759774
with *fld_2);
760775
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);
762777
}
763778

764779
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 {
22552270
auto ccx = @rec(sess=sess,
22562271
item_types=result._1,
22572272
item_items=result._2,
2273+
ty_param_counts=result._3,
22582274
obj_fields=fields,
22592275
mutable next_var_id=0);
22602276

0 commit comments

Comments
 (0)