Alias-ify fold and its users, remove another 85kb.

This commit is contained in:
Graydon Hoare 2011-05-09 17:49:19 -07:00
parent cfcc8678e5
commit 4539f8a03c
6 changed files with 378 additions and 357 deletions

View File

@ -441,9 +441,10 @@ fn load_crate(session.session sess,
fail;
}
fn fold_view_item_use(&env e, &span sp, ast.ident ident,
vec[@ast.meta_item] meta_items, ast.def_id id, Option.t[int] cnum_opt)
-> @ast.view_item {
fn fold_view_item_use(&env e, &span sp, &ast.ident ident,
&vec[@ast.meta_item] meta_items,
&ast.def_id id, &Option.t[int] cnum_opt)
-> @ast.view_item {
auto cnum;
if (!e.crate_cache.contains_key(ident)) {
cnum = e.next_crate_num;

File diff suppressed because it is too large Load Diff

View File

@ -604,9 +604,9 @@ fn lookup_name_wrapped(&env e, ast.ident i, namespace ns, direction dir)
}
}
fn fold_pat_tag(&env e, &span sp, ast.path p, vec[@ast.pat] args,
Option.t[ast.variant_def] old_def,
ann a) -> @ast.pat {
fn fold_pat_tag(&env e, &span sp, &ast.path p, &vec[@ast.pat] args,
&Option.t[ast.variant_def] old_def,
&ann a) -> @ast.pat {
auto len = Vec.len[ast.ident](p.node.idents);
auto last_id = p.node.idents.(len - 1u);
auto new_def;
@ -647,7 +647,7 @@ fn fold_pat_tag(&env e, &span sp, ast.path p, vec[@ast.pat] args,
// expressions tacked on the end.
fn fold_expr_path(&env e, &span sp, &ast.path p, &Option.t[def] d,
ann a) -> @ast.expr {
&ann a) -> @ast.expr {
auto n_idents = Vec.len[ast.ident](p.node.idents);
assert (n_idents != 0u);
@ -683,9 +683,9 @@ fn fold_expr_path(&env e, &span sp, &ast.path p, &Option.t[def] d,
}
fn fold_view_item_import(&env e, &span sp,
import_map index, ident i,
vec[ident] is, ast.def_id id,
Option.t[def] target_id) -> @ast.view_item {
&import_map index, &ident i,
&vec[ident] is, &ast.def_id id,
&Option.t[def] target_id) -> @ast.view_item {
// Produce errors for invalid imports
auto len = Vec.len[ast.ident](is);
auto last_id = is.(len - 1u);
@ -703,7 +703,7 @@ fn fold_view_item_import(&env e, &span sp,
target_def));
}
fn fold_ty_path(&env e, &span sp, ast.path p, &Option.t[def] d) -> @ast.ty {
fn fold_ty_path(&env e, &span sp, &ast.path p, &Option.t[def] d) -> @ast.ty {
auto index = new_def_hash[def_wrap]();
auto d = find_final_def(e, index, sp, p.node.idents, ns_type,
none[ast.def_id]);
@ -711,22 +711,22 @@ fn fold_ty_path(&env e, &span sp, ast.path p, &Option.t[def] d) -> @ast.ty {
ret @fold.respan[ast.ty_](sp, ast.ty_path(p, some(unwrap_def(d))));
}
fn update_env_for_crate(&env e, @ast.crate c) -> env {
fn update_env_for_crate(&env e, &@ast.crate c) -> env {
ret rec(scopes = cons[scope](scope_crate(c), @e.scopes) with e);
}
fn update_env_for_item(&env e, @ast.item i) -> env {
fn update_env_for_item(&env e, &@ast.item i) -> env {
ret rec(scopes = cons[scope](scope_item(i), @e.scopes) with e);
}
fn update_env_for_native_item(&env e, @ast.native_item i) -> env {
fn update_env_for_native_item(&env e, &@ast.native_item i) -> env {
ret rec(scopes = cons[scope](scope_native_item(i), @e.scopes) with e);
}
// Not actually called by fold, but here since this is analogous to
// update_env_for_item() above and is called by find_final_def().
fn update_env_for_external_mod(&env e, ast.def_id mod_id,
vec[ast.ident] idents) -> env {
fn update_env_for_external_mod(&env e, &ast.def_id mod_id,
&vec[ast.ident] idents) -> env {
ret rec(scopes = cons[scope](scope_external_mod(mod_id, idents),
@e.scopes)
with e);
@ -736,7 +736,7 @@ fn update_env_for_block(&env e, &ast.block b) -> env {
ret rec(scopes = cons[scope](scope_block(b), @e.scopes) with e);
}
fn update_env_for_expr(&env e, @ast.expr x) -> env {
fn update_env_for_expr(&env e, &@ast.expr x) -> env {
alt (x.node) {
case (ast.expr_for(?d, _, _, _)) {
ret rec(scopes = cons[scope](scope_loop(d), @e.scopes) with e);
@ -753,7 +753,7 @@ fn update_env_for_arm(&env e, &ast.arm p) -> env {
ret rec(scopes = cons[scope](scope_arm(p), @e.scopes) with e);
}
fn resolve_imports(session.session sess, @ast.crate crate) -> @ast.crate {
fn resolve_imports(session.session sess, &@ast.crate crate) -> @ast.crate {
let fold.ast_fold[env] fld = fold.new_identity_fold[env]();
auto import_index = new_def_hash[def_wrap]();

View File

@ -631,7 +631,7 @@ mod Collect {
ret result;
}
fn collect(&@ty_item_table id_to_ty_item, @ast.item i) -> @ty_item_table {
fn collect(&@ty_item_table id_to_ty_item, &@ast.item i) -> @ty_item_table {
alt (i.node) {
case (ast.item_ty(_, _, _, ?def_id, _)) {
id_to_ty_item.insert(def_id, any_item_rust(i));
@ -647,7 +647,7 @@ mod Collect {
ret id_to_ty_item;
}
fn collect_native(&@ty_item_table id_to_ty_item, @ast.native_item i)
fn collect_native(&@ty_item_table id_to_ty_item, &@ast.native_item i)
-> @ty_item_table {
alt (i.node) {
case (ast.native_item_ty(_, ?def_id)) {
@ -662,7 +662,7 @@ mod Collect {
ret id_to_ty_item;
}
fn convert(&@env e, @ast.item i) -> @env {
fn convert(&@env e, &@ast.item i) -> @env {
auto abi = e.abi;
alt (i.node) {
case (ast.item_mod(_, _, _)) {
@ -681,32 +681,32 @@ mod Collect {
ret @rec(abi=abi with *e);
}
fn convert_native(&@env e, @ast.native_item i) -> @env {
fn convert_native(&@env e, &@ast.native_item i) -> @env {
ty_of_native_item(e.cx, i, e.abi);
ret e;
}
fn fold_item_const(&@env e, &span sp, ast.ident i,
@ast.ty t, @ast.expr ex,
ast.def_id id, ast.ann a) -> @ast.item {
fn fold_item_const(&@env e, &span sp, &ast.ident i,
&@ast.ty t, &@ast.expr ex,
&ast.def_id id, &ast.ann a) -> @ast.item {
// assert (e.cx.type_cache.contains_key(id));
auto typ = e.cx.type_cache.get(id)._1;
auto item = ast.item_const(i, t, ex, id, triv_ann(typ));
ret @fold.respan[ast.item_](sp, item);
}
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 {
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 {
// assert (e.cx.type_cache.contains_key(id));
auto typ = e.cx.type_cache.get(id)._1;
auto item = ast.item_fn(i, f, ty_params, id, triv_ann(typ));
ret @fold.respan[ast.item_](sp, item);
}
fn fold_native_item_fn(&@env e, &span sp, ast.ident i, Option.t[str] ln,
&ast.fn_decl d, vec[ast.ty_param] ty_params,
ast.def_id id, ast.ann a) -> @ast.native_item {
fn fold_native_item_fn(&@env e, &span sp, &ast.ident i, &Option.t[str] ln,
&ast.fn_decl d, &vec[ast.ty_param] ty_params,
&ast.def_id id, &ast.ann a) -> @ast.native_item {
// assert (e.cx.type_cache.contains_key(id));
auto typ = e.cx.type_cache.get(id)._1;
auto item = ast.native_item_fn(i, ln, d, ty_params, id,
@ -714,7 +714,7 @@ mod Collect {
ret @fold.respan[ast.native_item_](sp, item);
}
fn get_ctor_obj_methods(&@env e, ty.t t) -> vec[method] {
fn get_ctor_obj_methods(&@env e, &ty.t t) -> vec[method] {
alt (struct(e.cx.tcx, t)) {
case (ty.ty_fn(_,_,?tobj)) {
alt (struct(e.cx.tcx, tobj)) {
@ -735,9 +735,9 @@ mod Collect {
}
fn fold_item_obj(&@env e, &span sp, ast.ident i,
&ast._obj ob, vec[ast.ty_param] ty_params,
ast.obj_def_ids odid, ast.ann a) -> @ast.item {
fn fold_item_obj(&@env e, &span sp, &ast.ident i,
&ast._obj ob, &vec[ast.ty_param] ty_params,
&ast.obj_def_ids odid, &ast.ann a) -> @ast.item {
// assert (e.cx.type_cache.contains_key(odid.ctor));
auto t = e.cx.type_cache.get(odid.ctor)._1;
let vec[method] meth_tys = get_ctor_obj_methods(e, t);
@ -791,19 +791,19 @@ mod Collect {
ret @fold.respan[ast.item_](sp, item);
}
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 {
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 {
// assert (e.cx.type_cache.contains_key(id));
auto typ = e.cx.type_cache.get(id)._1;
auto item = ast.item_ty(i, t, ty_params, id, triv_ann(typ));
ret @fold.respan[ast.item_](sp, item);
}
fn fold_item_tag(&@env e, &span sp, ast.ident i,
vec[ast.variant] variants,
vec[ast.ty_param] ty_params,
ast.def_id id, ast.ann a) -> @ast.item {
fn fold_item_tag(&@env e, &span sp, &ast.ident i,
&vec[ast.variant] variants,
&vec[ast.ty_param] ty_params,
&ast.def_id id, &ast.ann a) -> @ast.item {
auto variants_t = get_tag_variant_types(e.cx, id, variants,
ty_params);
auto typ = e.cx.type_cache.get(id)._1;
@ -813,7 +813,8 @@ mod Collect {
ret @fold.respan[ast.item_](sp, item);
}
fn collect_item_types(session.session sess, ty.ctxt tcx, @ast.crate crate)
fn collect_item_types(&session.session sess, &ty.ctxt tcx,
&@ast.crate crate)
-> tup(@ast.crate, ty.type_cache, @ty_item_table) {
// First pass: collect all type item IDs.
auto module = crate.node.module;
@ -1523,7 +1524,7 @@ mod Pushdown {
// Local variable resolution: the phase that finds all the types in the AST
// and replaces opaque "ty_local" types with the resolved local types.
fn writeback_local(&Option.t[@fn_ctxt] env, &span sp, @ast.local local)
fn writeback_local(&Option.t[@fn_ctxt] env, &span sp, &@ast.local local)
-> @ast.decl {
auto fcx = Option.get[@fn_ctxt](env);
@ -1545,7 +1546,7 @@ fn writeback_local(&Option.t[@fn_ctxt] env, &span sp, @ast.local local)
ret @fold.respan[ast.decl_](sp, ast.decl_local(local_wb));
}
fn resolve_local_types_in_annotation(&Option.t[@fn_ctxt] env, ast.ann ann)
fn resolve_local_types_in_annotation(&Option.t[@fn_ctxt] env, &ast.ann ann)
-> ast.ann {
fn resolver(@fn_ctxt fcx, ty.t typ) -> ty.t {
alt (struct(fcx.ccx.tcx, typ)) {
@ -1574,7 +1575,7 @@ fn resolve_local_types_in_annotation(&Option.t[@fn_ctxt] env, ast.ann ann)
fn resolve_local_types_in_block(&@fn_ctxt fcx, &ast.block block)
-> ast.block {
fn update_env_for_item(&Option.t[@fn_ctxt] env, @ast.item i)
fn update_env_for_item(&Option.t[@fn_ctxt] env, &@ast.item i)
-> Option.t[@fn_ctxt] {
ret none[@fn_ctxt];
}
@ -1588,13 +1589,11 @@ fn resolve_local_types_in_block(&@fn_ctxt fcx, &ast.block block)
auto rltia = bind resolve_local_types_in_annotation(_,_);
auto uefi = update_env_for_item;
auto kg = keep_going;
fld = @rec(
fold_decl_local = wbl,
fold_ann = rltia,
update_env_for_item = uefi,
keep_going = kg
with *fld
);
fld = @rec(fold_decl_local = wbl,
fold_ann = rltia,
update_env_for_item = uefi,
keep_going = kg
with *fld);
ret fold.fold_block[Option.t[@fn_ctxt]](some[@fn_ctxt](fcx), fld, block);
}
@ -2872,9 +2871,9 @@ fn check_fn(&@crate_ctxt ccx, &ast.fn_decl decl, ast.proto proto,
ret fn_t;
}
fn check_item_fn(&@crate_ctxt ccx, &span sp, ast.ident ident, &ast._fn f,
vec[ast.ty_param] ty_params, ast.def_id id,
ast.ann ann) -> @ast.item {
fn check_item_fn(&@crate_ctxt ccx, &span sp, &ast.ident ident, &ast._fn f,
&vec[ast.ty_param] ty_params, &ast.def_id id,
&ast.ann ann) -> @ast.item {
// FIXME: duplicate work: the item annotation already has the arg types
// and return type translated to typeck.ty values. We don't need do to it
@ -2893,7 +2892,7 @@ fn check_item_fn(&@crate_ctxt ccx, &span sp, ast.ident ident, &ast._fn f,
ret @fold.respan[ast.item_](sp, item);
}
fn update_obj_fields(&@crate_ctxt ccx, @ast.item i) -> @crate_ctxt {
fn update_obj_fields(&@crate_ctxt ccx, &@ast.item i) -> @crate_ctxt {
alt (i.node) {
case (ast.item_obj(_, ?ob, _, ?obj_def_ids, _)) {
let ast.def_id di = obj_def_ids.ty;

View File

@ -309,7 +309,7 @@ fn num_locals(fn_info m) -> uint {
ret m.size();
}
fn collect_local(&@vec[tup(ident, def_id)] vars, &span sp, @ast.local loc)
fn collect_local(&@vec[tup(ident, def_id)] vars, &span sp, &@ast.local loc)
-> @decl {
log("collect_local: pushing " + loc.ident);
Vec.push[tup(ident, def_id)](*vars, tup(loc.ident, loc.id));
@ -351,19 +351,20 @@ fn mk_fn_info(_fn f) -> fn_info {
ret res;
}
/* extends mk_fn_info to a function item, side-effecting the map fi from
/* extends mk_fn_info to a function item, side-effecting the map fi from
function IDs to fn_info maps */
fn mk_fn_info_item_fn(&fn_info_map fi, &span sp, ident i, &ast._fn f,
vec[ast.ty_param] ty_params, def_id id, ann a) -> @item {
fn mk_fn_info_item_fn(&fn_info_map fi, &span sp, &ident i, &ast._fn f,
&vec[ast.ty_param] ty_params, &def_id id, &ann a) -> @item {
fi.insert(id, mk_fn_info(f));
log(i + " has " + uistr(num_locals(mk_fn_info(f))) + " local vars");
ret @respan(sp, item_fn(i, f, ty_params, id, a));
}
/* extends mk_fn_info to an obj item, side-effecting the map fi from
/* extends mk_fn_info to an obj item, side-effecting the map fi from
function IDs to fn_info maps */
fn mk_fn_info_item_obj(&fn_info_map fi, &span sp, ident i, &ast._obj o,
vec[ast.ty_param] ty_params, ast.obj_def_ids odid, ann a) -> @item {
fn mk_fn_info_item_obj(&fn_info_map fi, &span sp, &ident i, &ast._obj o,
&vec[ast.ty_param] ty_params,
&ast.obj_def_ids odid, &ann a) -> @item {
auto all_methods = Vec.clone[@method](o.methods);
plus_option[@method](all_methods, o.dtor);
for (@method m in all_methods) {
@ -1251,14 +1252,15 @@ fn find_pre_post_fn(&fn_info_map fm, &fn_info fi, &_fn f) -> () {
find_pre_post_block(fm, fi, f.body);
}
fn check_item_fn(&fn_info_map fm, &span sp, ident i, &ast._fn f,
vec[ast.ty_param] ty_params, def_id id, ann a) -> @item {
fn check_item_fn(&fn_info_map fm, &span sp, &ident i, &ast._fn f,
&vec[ast.ty_param] ty_params,
&def_id id, &ann a) -> @item {
log("check_item_fn:");
log_fn(f, i, ty_params);
assert (fm.contains_key(id));
find_pre_post_fn(fm, fm.get(id), f);
find_pre_post_fn(fm, fm.get(id), f);
ret @respan(sp, ast.item_fn(i, f, ty_params, id, a));
}
@ -2006,9 +2008,9 @@ fn check_fn_states(&fn_info_map f_info_map, &fn_info f_info, &ast._fn f)
check_states_against_conditions(f_info, f);
}
fn check_item_fn_state(&fn_info_map f_info_map, &span sp, ident i,
&ast._fn f, vec[ast.ty_param] ty_params, def_id id,
ann a) -> @item {
fn check_item_fn_state(&fn_info_map f_info_map, &span sp, &ident i,
&ast._fn f, &vec[ast.ty_param] ty_params,
&def_id id, &ann a) -> @item {
/* Look up the var-to-bit-num map for this function */
assert (f_info_map.contains_key(id));
@ -2026,8 +2028,9 @@ fn check_method_states(&fn_info_map f_info_map, @method m) -> () {
check_fn_states(f_info_map, f_info, m.node.meth);
}
fn check_obj_state(&fn_info_map f_info_map, vec[obj_field] fields,
vec[@method] methods, Option.t[@method] dtor) -> ast._obj {
fn check_obj_state(&fn_info_map f_info_map, &vec[obj_field] fields,
&vec[@method] methods,
&Option.t[@method] dtor) -> ast._obj {
fn one(fn_info_map fm, &@method m) -> () {
ret check_method_states(fm, m);
}
@ -2037,7 +2040,7 @@ fn check_obj_state(&fn_info_map f_info_map, vec[obj_field] fields,
ret rec(fields=fields, methods=methods, dtor=dtor);
}
fn init_ann(&fn_info fi, ann a) -> ann {
fn init_ann(&fn_info fi, &ann a) -> ann {
alt (a) {
case (ann_none) {
// log("init_ann: shouldn't see ann_none");
@ -2053,7 +2056,7 @@ fn init_ann(&fn_info fi, ann a) -> ann {
}
}
fn init_blank_ann(&() ignore, ann a) -> ann {
fn init_blank_ann(&() ignore, &ann a) -> ann {
alt (a) {
case (ann_none) {
// log("init_blank_ann: shouldn't see ann_none");
@ -2492,7 +2495,7 @@ fn annotate_crate(&fn_info_map fm, &@ast.crate crate) -> @ast.crate {
fn check_crate(@ast.crate crate) -> @ast.crate {
/* Build the global map from function id to var-to-bit-num-map */
auto fm = mk_f_to_fn_info(crate);
/* Add a blank ts_ann to every statement (and expression) */
auto with_anns = annotate_crate(fm, crate);

View File

@ -252,12 +252,12 @@ fn has_nonlocal_exits(&ast.block b) -> bool {
/* overkill, but just passing around a mutable bool doesn't seem
to work in rustboot */
auto has_exits = new_str_hash[()]();
fn set_break(&flag f, &span sp, ast.ann a) -> @ast.expr {
fn set_break(&flag f, &span sp, &ast.ann a) -> @ast.expr {
f.insert("foo", ());
ret @respan(sp, ast.expr_break(a));
}
fn set_cont(&flag f, &span sp, ast.ann a) -> @ast.expr {
fn set_cont(&flag f, &span sp, &ast.ann a) -> @ast.expr {
f.insert("foo", ());
ret @respan(sp, ast.expr_cont(a));
}