rustc: Store type parameter definition IDs instead of type parameter counts in the typechecker
This commit is contained in:
parent
0054efc412
commit
473a242525
1 changed files with 23 additions and 13 deletions
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue