aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Walton <[email protected]>2011-03-08 11:27:36 -0800
committerPatrick Walton <[email protected]>2011-03-08 11:27:36 -0800
commit473a2425251f43ba6ba003db37ce1f03c964a831 (patch)
tree2c0b15970d5d328451ca2bd0d4a2e6b581f72280
parentrustc: Store the number of type parameters per item, which will be needed to ... (diff)
downloadrust-473a2425251f43ba6ba003db37ce1f03c964a831.tar.xz
rust-473a2425251f43ba6ba003db37ce1f03c964a831.zip
rustc: Store type parameter definition IDs instead of type parameter counts in the typechecker
-rw-r--r--src/comp/middle/typeck.rs36
1 files changed, 23 insertions, 13 deletions
diff --git a/src/comp/middle/typeck.rs b/src/comp/middle/typeck.rs
index ec04d684..002a011b 100644
--- a/src/comp/middle/typeck.rs
+++ b/src/comp/middle/typeck.rs
@@ -39,12 +39,12 @@ tag any_item {
}
type ty_item_table = hashmap[ast.def_id,any_item];
-type ty_param_count_table = hashmap[ast.def_id,uint];
+type ty_param_table = hashmap[ast.def_id,vec[ast.def_id]];
type crate_ctxt = rec(session.session sess,
@ty_table item_types,
@ty_item_table item_items,
- @ty_param_count_table ty_param_counts,
+ @ty_param_table item_ty_params,
vec[ast.obj_field] obj_fields,
mutable int next_var_id);
@@ -358,7 +358,7 @@ fn ty_of_native_fn_decl(@ty_item_table id_to_ty_item,
}
fn collect_item_types(session.session sess, @ast.crate crate)
- -> tup(@ast.crate, @ty_table, @ty_item_table, @ty_param_count_table) {
+ -> tup(@ast.crate, @ty_table, @ty_item_table, @ty_param_table) {
fn getter(@ty_item_table id_to_ty_item,
@ty_table item_to_ty,
@@ -602,19 +602,29 @@ fn collect_item_types(session.session sess, @ast.crate crate)
// Second pass: translate the types of all items.
let @ty_table item_to_ty = @common.new_def_hash[@ty.t]();
- let @ty_param_count_table ty_param_counts = @common.new_def_hash[uint]();
+ auto item_ty_params = @common.new_def_hash[vec[ast.def_id]]();
type env = rec(session.session sess,
@ty_item_table id_to_ty_item,
@ty_table item_to_ty,
- @ty_param_count_table ty_param_counts,
+ @ty_param_table item_ty_params,
ast.native_abi abi);
let @env e = @rec(sess=sess,
id_to_ty_item=id_to_ty_item,
item_to_ty=item_to_ty,
- ty_param_counts=ty_param_counts,
+ item_ty_params=item_ty_params,
abi=ast.native_abi_cdecl);
+ // Inserts the given type parameters into the type parameter table of the
+ // environment.
+ fn collect_ty_params(&@env e, &ast.def_id id, vec[ast.ty_param] tps) {
+ let vec[ast.def_id] result = vec();
+ for (ast.ty_param tp in tps) {
+ result += vec(tp.id);
+ }
+ e.item_ty_params.insert(id, result);
+ }
+
fn convert(&@env e, @ast.item i) -> @env {
auto abi = e.abi;
alt (i.node) {
@@ -652,7 +662,7 @@ fn collect_item_types(session.session sess, @ast.crate crate)
fn fold_item_fn(&@env e, &span sp, ast.ident i,
&ast._fn f, vec[ast.ty_param] ty_params,
ast.def_id id, ast.ann a) -> @ast.item {
- e.ty_param_counts.insert(id, _vec.len[ast.ty_param](ty_params));
+ collect_ty_params(e, id, ty_params);
check (e.item_to_ty.contains_key(id));
auto ty = e.item_to_ty.get(id);
@@ -664,7 +674,7 @@ fn collect_item_types(session.session sess, @ast.crate crate)
fn fold_native_item_fn(&@env e, &span sp, ast.ident i,
&ast.fn_decl d, vec[ast.ty_param] ty_params,
ast.def_id id, ast.ann a) -> @ast.native_item {
- e.ty_param_counts.insert(id, _vec.len[ast.ty_param](ty_params));
+ collect_ty_params(e, id, ty_params);
check (e.item_to_ty.contains_key(id));
auto ty = e.item_to_ty.get(id);
@@ -697,7 +707,7 @@ fn collect_item_types(session.session sess, @ast.crate crate)
fn fold_item_obj(&@env e, &span sp, ast.ident i,
&ast._obj ob, vec[ast.ty_param] ty_params,
ast.def_id id, ast.ann a) -> @ast.item {
- e.ty_param_counts.insert(id, _vec.len[ast.ty_param](ty_params));
+ collect_ty_params(e, id, ty_params);
check (e.item_to_ty.contains_key(id));
auto t = e.item_to_ty.get(id);
@@ -737,7 +747,7 @@ fn collect_item_types(session.session sess, @ast.crate crate)
fn fold_item_ty(&@env e, &span sp, ast.ident i,
@ast.ty t, vec[ast.ty_param] ty_params,
ast.def_id id, ast.ann a) -> @ast.item {
- e.ty_param_counts.insert(id, _vec.len[ast.ty_param](ty_params));
+ collect_ty_params(e, id, ty_params);
check (e.item_to_ty.contains_key(id));
auto ty = e.item_to_ty.get(id);
@@ -750,7 +760,7 @@ fn collect_item_types(session.session sess, @ast.crate crate)
vec[ast.variant] variants,
vec[ast.ty_param] ty_params,
ast.def_id id) -> @ast.item {
- e.ty_param_counts.insert(id, _vec.len[ast.ty_param](ty_params));
+ collect_ty_params(e, id, ty_params);
auto variants_t = get_tag_variant_types(e.id_to_ty_item,
e.item_to_ty,
@@ -773,7 +783,7 @@ fn collect_item_types(session.session sess, @ast.crate crate)
fold_item_tag = bind fold_item_tag(_,_,_,_,_,_)
with *fld_2);
auto crate_ = fold.fold_crate[@env](e, fld_2, crate);
- ret tup(crate_, item_to_ty, id_to_ty_item, ty_param_counts);
+ ret tup(crate_, item_to_ty, id_to_ty_item, item_ty_params);
}
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 {
auto ccx = @rec(sess=sess,
item_types=result._1,
item_items=result._2,
- ty_param_counts=result._3,
+ item_ty_params=result._3,
obj_fields=fields,
mutable next_var_id=0);