Skip to content

Commit 473a242

Browse files
committed
rustc: Store type parameter definition IDs instead of type parameter counts in the typechecker
1 parent 0054efc commit 473a242

File tree

1 file changed

+23
-13
lines changed

1 file changed

+23
-13
lines changed

src/comp/middle/typeck.rs

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +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];
42+
type ty_param_table = hashmap[ast.def_id,vec[ast.def_id]];
4343

4444
type crate_ctxt = rec(session.session sess,
4545
@ty_table item_types,
4646
@ty_item_table item_items,
47-
@ty_param_count_table ty_param_counts,
47+
@ty_param_table item_ty_params,
4848
vec[ast.obj_field] obj_fields,
4949
mutable int next_var_id);
5050

@@ -358,7 +358,7 @@ fn ty_of_native_fn_decl(@ty_item_table id_to_ty_item,
358358
}
359359

360360
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) {
362362

363363
fn getter(@ty_item_table id_to_ty_item,
364364
@ty_table item_to_ty,
@@ -602,19 +602,29 @@ fn collect_item_types(session.session sess, @ast.crate crate)
602602

603603
// Second pass: translate the types of all items.
604604
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]]();
606606

607607
type env = rec(session.session sess,
608608
@ty_item_table id_to_ty_item,
609609
@ty_table item_to_ty,
610-
@ty_param_count_table ty_param_counts,
610+
@ty_param_table item_ty_params,
611611
ast.native_abi abi);
612612
let @env e = @rec(sess=sess,
613613
id_to_ty_item=id_to_ty_item,
614614
item_to_ty=item_to_ty,
615-
ty_param_counts=ty_param_counts,
615+
item_ty_params=item_ty_params,
616616
abi=ast.native_abi_cdecl);
617617

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+
618628
fn convert(&@env e, @ast.item i) -> @env {
619629
auto abi = e.abi;
620630
alt (i.node) {
@@ -652,7 +662,7 @@ fn collect_item_types(session.session sess, @ast.crate crate)
652662
fn fold_item_fn(&@env e, &span sp, ast.ident i,
653663
&ast._fn f, vec[ast.ty_param] ty_params,
654664
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);
656666

657667
check (e.item_to_ty.contains_key(id));
658668
auto ty = e.item_to_ty.get(id);
@@ -664,7 +674,7 @@ fn collect_item_types(session.session sess, @ast.crate crate)
664674
fn fold_native_item_fn(&@env e, &span sp, ast.ident i,
665675
&ast.fn_decl d, vec[ast.ty_param] ty_params,
666676
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);
668678

669679
check (e.item_to_ty.contains_key(id));
670680
auto ty = e.item_to_ty.get(id);
@@ -697,7 +707,7 @@ fn collect_item_types(session.session sess, @ast.crate crate)
697707
fn fold_item_obj(&@env e, &span sp, ast.ident i,
698708
&ast._obj ob, vec[ast.ty_param] ty_params,
699709
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);
701711

702712
check (e.item_to_ty.contains_key(id));
703713
auto t = e.item_to_ty.get(id);
@@ -737,7 +747,7 @@ fn collect_item_types(session.session sess, @ast.crate crate)
737747
fn fold_item_ty(&@env e, &span sp, ast.ident i,
738748
@ast.ty t, vec[ast.ty_param] ty_params,
739749
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);
741751

742752
check (e.item_to_ty.contains_key(id));
743753
auto ty = e.item_to_ty.get(id);
@@ -750,7 +760,7 @@ fn collect_item_types(session.session sess, @ast.crate crate)
750760
vec[ast.variant] variants,
751761
vec[ast.ty_param] ty_params,
752762
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);
754764

755765
auto variants_t = get_tag_variant_types(e.id_to_ty_item,
756766
e.item_to_ty,
@@ -773,7 +783,7 @@ fn collect_item_types(session.session sess, @ast.crate crate)
773783
fold_item_tag = bind fold_item_tag(_,_,_,_,_,_)
774784
with *fld_2);
775785
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);
777787
}
778788

779789
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 {
22702280
auto ccx = @rec(sess=sess,
22712281
item_types=result._1,
22722282
item_items=result._2,
2273-
ty_param_counts=result._3,
2283+
item_ty_params=result._3,
22742284
obj_fields=fields,
22752285
mutable next_var_id=0);
22762286

0 commit comments

Comments
 (0)