Give up on providing a by-value version of map, convert fold over to

passing pointers by ref

Issue #1008
This commit is contained in:
Marijn Haverbeke 2011-10-07 09:36:53 +02:00
parent f9fbd86f52
commit fe916fb9f0
9 changed files with 98 additions and 115 deletions

View file

@ -29,8 +29,8 @@ fn fold_mod(cfg: ast::crate_cfg, m: ast::_mod, fld: fold::ast_fold) ->
ast::_mod {
let filter = bind filter_item(cfg, _);
let filtered_items = vec::filter_map(filter, m.items);
ret {view_items: vec::map_imm(fld.fold_view_item, m.view_items),
items: vec::map_imm(fld.fold_item, filtered_items)};
ret {view_items: vec::map(fld.fold_view_item, m.view_items),
items: vec::map(fld.fold_item, filtered_items)};
}
fn filter_native_item(cfg: ast::crate_cfg, &&item: @ast::native_item) ->
@ -46,7 +46,7 @@ fn fold_native_mod(cfg: ast::crate_cfg, nm: ast::native_mod,
let filtered_items = vec::filter_map(filter, nm.items);
ret {native_name: nm.native_name,
abi: nm.abi,
view_items: vec::map_imm(fld.fold_view_item, nm.view_items),
view_items: vec::map(fld.fold_view_item, nm.view_items),
items: filtered_items};
}
@ -71,8 +71,8 @@ fn fold_block(cfg: ast::crate_cfg, b: ast::blk_, fld: fold::ast_fold) ->
ast::blk_ {
let filter = bind filter_stmt(cfg, _);
let filtered_stmts = vec::filter_map(filter, b.stmts);
ret {stmts: vec::map_imm(fld.fold_stmt, filtered_stmts),
expr: option::map_imm(fld.fold_expr, b.expr),
ret {stmts: vec::map(fld.fold_stmt, filtered_stmts),
expr: option::map(fld.fold_expr, b.expr),
id: b.id,
rules: b.rules};
}

View file

@ -82,7 +82,7 @@ fn fold_crate(cx: test_ctxt, c: ast::crate_, fld: fold::ast_fold) ->
}
fn fold_item(cx: test_ctxt, i: @ast::item, fld: fold::ast_fold) ->
fn fold_item(cx: test_ctxt, &&i: @ast::item, fld: fold::ast_fold) ->
@ast::item {
cx.path += [i.ident];

View file

@ -70,9 +70,9 @@ fn empty_ann(num_vars: uint) -> ts_ann {
states: empty_states(num_vars)};
}
fn get_pre(p: pre_and_post) -> precond { ret p.precondition; }
fn get_pre(&&p: pre_and_post) -> precond { ret p.precondition; }
fn get_post(p: pre_and_post) -> postcond { ret p.postcondition; }
fn get_post(&&p: pre_and_post) -> postcond { ret p.postcondition; }
fn difference(p1: precond, p2: precond) -> bool {
ret tritv_difference(p1, p2);

View file

@ -96,13 +96,13 @@ fn find_pre_post_exprs(fcx: fn_ctxt, args: [@expr], id: node_id) {
fn do_one(fcx: fn_ctxt, e: @expr) { find_pre_post_expr(fcx, e); }
for e: @expr in args { do_one(fcx, e); }
fn get_pp(ccx: crate_ctxt, e: @expr) -> pre_and_post {
fn get_pp(ccx: crate_ctxt, &&e: @expr) -> pre_and_post {
ret expr_pp(ccx, e);
}
let pps = vec::map_imm(bind get_pp(fcx.ccx, _), args);
let pps = vec::map(bind get_pp(fcx.ccx, _), args);
set_pre_and_post(fcx.ccx, id, seq_preconds(fcx, pps),
seq_postconds(fcx, vec::map_imm(get_post, pps)));
seq_postconds(fcx, vec::map(get_post, pps)));
}
fn find_pre_post_loop(fcx: fn_ctxt, l: @local, index: @expr, body: blk,

View file

@ -239,7 +239,8 @@ fn default_arg_mode_for_ty(tcx: ty::ctxt, m: ast::mode,
_ { m }
}
}
fn ast_ty_to_ty(tcx: ty::ctxt, getter: ty_getter, ast_ty: @ast::ty) -> ty::t {
fn ast_ty_to_ty(tcx: ty::ctxt, getter: ty_getter, &&ast_ty: @ast::ty)
-> ty::t {
fn ast_arg_to_arg(tcx: ty::ctxt, getter: ty_getter, arg: ast::ty_arg)
-> {mode: ty::mode, ty: ty::t} {
let ty = ast_ty_to_ty(tcx, getter, arg.node.ty);
@ -311,7 +312,7 @@ fn ast_ty_to_ty(tcx: ty::ctxt, getter: ty_getter, ast_ty: @ast::ty) -> ty::t {
typ = ty::mk_ptr(tcx, ast_mt_to_mt(tcx, getter, mt));
}
ast::ty_tup(fields) {
let flds = vec::map_imm(bind ast_ty_to_ty(tcx, getter, _), fields);
let flds = vec::map(bind ast_ty_to_ty(tcx, getter, _), fields);
typ = ty::mk_tup(tcx, flds);
}
ast::ty_rec(fields) {
@ -398,7 +399,7 @@ fn ast_ty_to_ty(tcx: ty::ctxt, getter: ty_getter, ast_ty: @ast::ty) -> ty::t {
// A convenience function to use a crate_ctxt to resolve names for
// ast_ty_to_ty.
fn ast_ty_to_ty_crate(ccx: @crate_ctxt, ast_ty: @ast::ty) -> ty::t {
fn ast_ty_to_ty_crate(ccx: @crate_ctxt, &&ast_ty: @ast::ty) -> ty::t {
fn getter(ccx: @crate_ctxt, id: ast::def_id) ->
ty::ty_param_kinds_and_ty {
ret ty::lookup_item_type(ccx.tcx, id);
@ -408,7 +409,7 @@ fn ast_ty_to_ty_crate(ccx: @crate_ctxt, ast_ty: @ast::ty) -> ty::t {
}
// A wrapper around ast_ty_to_ty_crate that handles ty_infer.
fn ast_ty_to_ty_crate_infer(ccx: @crate_ctxt, ast_ty: @ast::ty) ->
fn ast_ty_to_ty_crate_infer(ccx: @crate_ctxt, &&ast_ty: @ast::ty) ->
option::t<ty::t> {
alt ast_ty.node {
ast::ty_infer. { none }
@ -417,7 +418,7 @@ fn ast_ty_to_ty_crate_infer(ccx: @crate_ctxt, ast_ty: @ast::ty) ->
}
// A wrapper around ast_ty_to_ty_infer that generates a new type variable if
// there isn't a fixed type.
fn ast_ty_to_ty_crate_tyvar(fcx: @fn_ctxt, ast_ty: @ast::ty) -> ty::t {
fn ast_ty_to_ty_crate_tyvar(fcx: @fn_ctxt, &&ast_ty: @ast::ty) -> ty::t {
alt ast_ty_to_ty_crate_infer(fcx.ccx, ast_ty) {
some(ty) { ty }
none. { next_ty_var(fcx) }
@ -515,7 +516,7 @@ mod collect {
ret k;
}
fn ty_of_fn_decl(cx: @ctxt, convert: fn(@ast::ty) -> ty::t,
fn ty_of_fn_decl(cx: @ctxt, convert: fn(&&@ast::ty) -> ty::t,
ty_of_arg: fn(ast::arg) -> arg, decl: ast::fn_decl,
proto: ast::proto, ty_params: [ast::ty_param],
def_id: option::t<ast::def_id>) ->
@ -535,7 +536,7 @@ mod collect {
alt def_id { some(did) { cx.tcx.tcache.insert(did, tpt); } _ { } }
ret tpt;
}
fn ty_of_native_fn_decl(cx: @ctxt, convert: fn(@ast::ty) -> ty::t,
fn ty_of_native_fn_decl(cx: @ctxt, convert: fn(&&@ast::ty) -> ty::t,
ty_of_arg: fn(ast::arg) -> arg,
decl: ast::fn_decl, abi: ast::native_abi,
ty_params: [ast::ty_param], def_id: ast::def_id)

View file

@ -263,10 +263,10 @@ iter free_vars(b: bindings, e: @expr) -> ident {
/* handle sequences (anywhere in the AST) of exprs, either real or ...ed */
fn transcribe_exprs(cx: ext_ctxt, b: bindings, idx_path: @mutable [uint],
recur: fn(@expr) -> @expr, exprs: [@expr]) -> [@expr] {
recur: fn(&&@expr) -> @expr, exprs: [@expr]) -> [@expr] {
alt elts_to_ell(cx, exprs) {
{pre: pre, rep: repeat_me_maybe, post: post} {
let res = vec::map_imm(recur, pre);
let res = vec::map(recur, pre);
alt repeat_me_maybe {
none. { }
some(repeat_me) {
@ -315,7 +315,7 @@ fn transcribe_exprs(cx: ext_ctxt, b: bindings, idx_path: @mutable [uint],
}
}
}
res += vec::map_imm(recur, post);
res += vec::map(recur, post);
ret res;
}
}

View file

@ -23,8 +23,8 @@ type ast_fold_precursor =
{fold_crate: fn(crate_, ast_fold) -> crate_,
fold_crate_directive: fn(crate_directive_, ast_fold) -> crate_directive_,
fold_view_item: fn(view_item_, ast_fold) -> view_item_,
fold_native_item: fn(@native_item, ast_fold) -> @native_item,
fold_item: fn(@item, ast_fold) -> @item,
fold_native_item: fn(&&@native_item, ast_fold) -> @native_item,
fold_item: fn(&&@item, ast_fold) -> @item,
fold_item_underscore: fn(item_, ast_fold) -> item_,
fold_method: fn(method_, ast_fold) -> method_,
fold_block: fn(blk_, ast_fold) -> blk_,
@ -42,56 +42,56 @@ type ast_fold_precursor =
fold_ident: fn(ident, ast_fold) -> ident,
fold_path: fn(path_, ast_fold) -> path_,
fold_local: fn(local_, ast_fold) -> local_,
map_exprs: fn(fn(@expr) -> @expr, [@expr]) -> [@expr],
map_exprs: fn(fn(&&@expr) -> @expr, [@expr]) -> [@expr],
new_id: fn(node_id) -> node_id,
new_span: fn(span) -> span};
type a_f =
{fold_crate: fn(crate) -> crate,
fold_crate_directive: fn(@crate_directive) -> @crate_directive,
fold_view_item: fn(@view_item) -> @view_item,
fold_native_item: fn(@native_item) -> @native_item,
fold_item: fn(@item) -> @item,
fold_crate_directive: fn(&&@crate_directive) -> @crate_directive,
fold_view_item: fn(&&@view_item) -> @view_item,
fold_native_item: fn(&&@native_item) -> @native_item,
fold_item: fn(&&@item) -> @item,
fold_item_underscore: fn(item_) -> item_,
fold_method: fn(@method) -> @method,
fold_method: fn(&&@method) -> @method,
fold_block: fn(blk) -> blk,
fold_stmt: fn(@stmt) -> @stmt,
fold_stmt: fn(&&@stmt) -> @stmt,
fold_arm: fn(arm) -> arm,
fold_pat: fn(@pat) -> @pat,
fold_decl: fn(@decl) -> @decl,
fold_expr: fn(@expr) -> @expr,
fold_ty: fn(@ty) -> @ty,
fold_constr: fn(@constr) -> @constr,
fold_pat: fn(&&@pat) -> @pat,
fold_decl: fn(&&@decl) -> @decl,
fold_expr: fn(&&@expr) -> @expr,
fold_ty: fn(&&@ty) -> @ty,
fold_constr: fn(&&@constr) -> @constr,
fold_fn: fn(_fn) -> _fn,
fold_mod: fn(_mod) -> _mod,
fold_native_mod: fn(native_mod) -> native_mod,
fold_variant: fn(variant) -> variant,
fold_ident: fn(ident) -> ident,
fold_path: fn(path) -> path,
fold_local: fn(@local) -> @local,
map_exprs: fn(fn(@expr) -> @expr, [@expr]) -> [@expr],
fold_local: fn(&&@local) -> @local,
map_exprs: fn(fn(&&@expr) -> @expr, [@expr]) -> [@expr],
new_id: fn(node_id) -> node_id,
new_span: fn(span) -> span};
//fn nf_dummy<T>(&T node) -> T { fail; }
fn nf_crate_dummy(_c: crate) -> crate { fail; }
fn nf_crate_directive_dummy(_c: @crate_directive) -> @crate_directive {
fn nf_crate_directive_dummy(&&_c: @crate_directive) -> @crate_directive {
fail;
}
fn nf_view_item_dummy(_v: @view_item) -> @view_item { fail; }
fn nf_native_item_dummy(_n: @native_item) -> @native_item { fail; }
fn nf_item_dummy(_i: @item) -> @item { fail; }
fn nf_view_item_dummy(&&_v: @view_item) -> @view_item { fail; }
fn nf_native_item_dummy(&&_n: @native_item) -> @native_item { fail; }
fn nf_item_dummy(&&_i: @item) -> @item { fail; }
fn nf_item_underscore_dummy(_i: item_) -> item_ { fail; }
fn nf_method_dummy(_m: @method) -> @method { fail; }
fn nf_method_dummy(&&_m: @method) -> @method { fail; }
fn nf_blk_dummy(_b: blk) -> blk { fail; }
fn nf_stmt_dummy(_s: @stmt) -> @stmt { fail; }
fn nf_stmt_dummy(&&_s: @stmt) -> @stmt { fail; }
fn nf_arm_dummy(_a: arm) -> arm { fail; }
fn nf_pat_dummy(_p: @pat) -> @pat { fail; }
fn nf_decl_dummy(_d: @decl) -> @decl { fail; }
fn nf_expr_dummy(_e: @expr) -> @expr { fail; }
fn nf_ty_dummy(_t: @ty) -> @ty { fail; }
fn nf_constr_dummy(_c: @constr) -> @constr { fail; }
fn nf_pat_dummy(&&_p: @pat) -> @pat { fail; }
fn nf_decl_dummy(&&_d: @decl) -> @decl { fail; }
fn nf_expr_dummy(&&_e: @expr) -> @expr { fail; }
fn nf_ty_dummy(&&_t: @ty) -> @ty { fail; }
fn nf_constr_dummy(&&_c: @constr) -> @constr { fail; }
fn nf_fn_dummy(_f: _fn) -> _fn { fail; }
fn nf_mod_dummy(_m: _mod) -> _mod { fail; }
fn nf_native_mod_dummy(_n: native_mod) -> native_mod { fail; }
@ -99,18 +99,18 @@ fn nf_variant_dummy(_v: variant) -> variant { fail; }
fn nf_ident_dummy(_i: ident) -> ident { fail; }
fn nf_path_dummy(_p: path) -> path { fail; }
fn nf_obj_field_dummy(_o: obj_field) -> obj_field { fail; }
fn nf_local_dummy(_o: @local) -> @local { fail; }
fn nf_local_dummy(&&_o: @local) -> @local { fail; }
/* some little folds that probably aren't useful to have in ast_fold itself*/
//used in noop_fold_item and noop_fold_crate and noop_fold_crate_directive
fn fold_meta_item_(mi: @meta_item, fld: ast_fold) -> @meta_item {
fn fold_meta_item_(&&mi: @meta_item, fld: ast_fold) -> @meta_item {
ret @{node:
alt mi.node {
meta_word(id) { meta_word(fld.fold_ident(id)) }
meta_list(id, mis) {
let fold_meta_item = bind fold_meta_item_(_, fld);
meta_list(id, vec::map_imm(fold_meta_item, mis))
meta_list(id, vec::map(fold_meta_item, mis))
}
meta_name_value(id, s) {
meta_name_value(fld.fold_ident(id), s)
@ -119,7 +119,7 @@ fn fold_meta_item_(mi: @meta_item, fld: ast_fold) -> @meta_item {
span: mi.span};
}
//used in noop_fold_item and noop_fold_crate
fn fold_attribute_(at: attribute, fmi: fn(@meta_item) -> @meta_item) ->
fn fold_attribute_(at: attribute, fmi: fn(&&@meta_item) -> @meta_item) ->
attribute {
ret {node: {style: at.node.style, value: *fmi(@at.node.value)},
span: at.span};
@ -146,17 +146,14 @@ fn fold_mac_(m: mac, fld: ast_fold) -> mac {
}
fn noop_fold_crate(c: crate_, fld: ast_fold) -> crate_ {
let fold_meta_item = bind fold_meta_item_(_, fld);
let fold_attribute = bind fold_attribute_(_, fold_meta_item);
ret {directives: vec::map_imm(fld.fold_crate_directive, c.directives),
ret {directives: vec::map(fld.fold_crate_directive, c.directives),
module: fld.fold_mod(c.module),
attrs: vec::map(fold_attribute, c.attrs),
config: vec::map_imm(fold_meta_item, c.config)};
config: vec::map(fold_meta_item, c.config)};
}
fn noop_fold_crate_directive(cd: crate_directive_, fld: ast_fold) ->
@ -167,7 +164,7 @@ fn noop_fold_crate_directive(cd: crate_directive_, fld: ast_fold) ->
}
cdir_dir_mod(id, fname, cds, attrs) {
cdir_dir_mod(fld.fold_ident(id), fname,
vec::map_imm(fld.fold_crate_directive, cds), attrs)
vec::map(fld.fold_crate_directive, cds), attrs)
}
cdir_view_item(vi) { cdir_view_item(fld.fold_view_item(vi)) }
cdir_syntax(_) { cd }
@ -180,7 +177,7 @@ fn noop_fold_view_item(vi: view_item_, _fld: ast_fold) -> view_item_ {
}
fn noop_fold_native_item(ni: @native_item, fld: ast_fold) -> @native_item {
fn noop_fold_native_item(&&ni: @native_item, fld: ast_fold) -> @native_item {
let fold_arg = bind fold_arg_(_, fld);
let fold_meta_item = bind fold_meta_item_(_, fld);
let fold_attribute = bind fold_attribute_(_, fold_meta_item);
@ -198,7 +195,7 @@ fn noop_fold_native_item(ni: @native_item, fld: ast_fold) -> @native_item {
il: fdec.il,
cf: fdec.cf,
constraints:
vec::map_imm(fld.fold_constr,
vec::map(fld.fold_constr,
fdec.constraints)}, typms)
}
},
@ -206,7 +203,7 @@ fn noop_fold_native_item(ni: @native_item, fld: ast_fold) -> @native_item {
span: ni.span};
}
fn noop_fold_item(i: @item, fld: ast_fold) -> @item {
fn noop_fold_item(&&i: @item, fld: ast_fold) -> @item {
let fold_meta_item = bind fold_meta_item_(_, fld);
let fold_attribute = bind fold_attribute_(_, fold_meta_item);
@ -237,7 +234,7 @@ fn noop_fold_item_underscore(i: item_, fld: ast_fold) -> item_ {
}
item_obj(o, typms, d) {
item_obj({fields: vec::map(fold_obj_field, o.fields),
methods: vec::map_imm(fld.fold_method, o.methods)},
methods: vec::map(fld.fold_method, o.methods)},
typms, d)
}
item_res(dtor, did, typms, cid) {
@ -252,8 +249,8 @@ fn noop_fold_method(m: method_, fld: ast_fold) -> method_ {
fn noop_fold_block(b: blk_, fld: ast_fold) -> blk_ {
ret {stmts: vec::map_imm(fld.fold_stmt, b.stmts),
expr: option::map_imm(fld.fold_expr, b.expr),
ret {stmts: vec::map(fld.fold_stmt, b.stmts),
expr: option::map(fld.fold_expr, b.expr),
id: b.id,
rules: b.rules};
}
@ -269,8 +266,8 @@ fn noop_fold_stmt(s: stmt_, fld: ast_fold) -> stmt_ {
}
fn noop_fold_arm(a: arm, fld: ast_fold) -> arm {
ret {pats: vec::map_imm(fld.fold_pat, a.pats),
guard: option::map_imm(fld.fold_expr, a.guard),
ret {pats: vec::map(fld.fold_pat, a.pats),
guard: option::map(fld.fold_expr, a.guard),
body: fld.fold_block(a.body)};
}
@ -280,7 +277,7 @@ fn noop_fold_pat(p: pat_, fld: ast_fold) -> pat_ {
pat_bind(ident) { pat_bind(fld.fold_ident(ident)) }
pat_lit(_) { p }
pat_tag(pth, pats) {
pat_tag(fld.fold_path(pth), vec::map_imm(fld.fold_pat, pats))
pat_tag(fld.fold_path(pth), vec::map(fld.fold_pat, pats))
}
pat_rec(fields, etc) {
let fs = [];
@ -289,7 +286,7 @@ fn noop_fold_pat(p: pat_, fld: ast_fold) -> pat_ {
}
pat_rec(fs, etc)
}
pat_tup(elts) { pat_tup(vec::map_imm(fld.fold_pat, elts)) }
pat_tup(elts) { pat_tup(vec::map(fld.fold_pat, elts)) }
pat_box(inner) { pat_box(fld.fold_pat(inner)) }
pat_uniq(inner) { pat_uniq(fld.fold_pat(inner)) }
pat_range(_, _) { p }
@ -334,8 +331,8 @@ fn noop_fold_expr(e: expr_, fld: ast_fold) -> expr_ {
option::some(vec::map(fold_anon_obj_field, v))
}
},
methods: vec::map_imm(fld.fold_method, ao.methods),
inner_obj: option::map_imm(fld.fold_expr, ao.inner_obj)}
methods: vec::map(fld.fold_method, ao.methods),
inner_obj: option::map(fld.fold_expr, ao.inner_obj)}
}
let fold_anon_obj = bind fold_anon_obj_(_, fld);
@ -347,15 +344,15 @@ fn noop_fold_expr(e: expr_, fld: ast_fold) -> expr_ {
}
expr_rec(fields, maybe_expr) {
expr_rec(vec::map(fold_field, fields),
option::map_imm(fld.fold_expr, maybe_expr))
option::map(fld.fold_expr, maybe_expr))
}
expr_tup(elts) { expr_tup(vec::map_imm(fld.fold_expr, elts)) }
expr_tup(elts) { expr_tup(vec::map(fld.fold_expr, elts)) }
expr_call(f, args) {
expr_call(fld.fold_expr(f), fld.map_exprs(fld.fold_expr, args))
}
expr_self_method(id) { expr_self_method(fld.fold_ident(id)) }
expr_bind(f, args) {
let opt_map_se = bind option::map_imm(fld.fold_expr, _);
let opt_map_se = bind option::map(fld.fold_expr, _);
expr_bind(fld.fold_expr(f), vec::map(opt_map_se, args))
}
expr_binary(binop, lhs, rhs) {
@ -366,7 +363,7 @@ fn noop_fold_expr(e: expr_, fld: ast_fold) -> expr_ {
expr_cast(expr, ty) { expr_cast(fld.fold_expr(expr), ty) }
expr_if(cond, tr, fl) {
expr_if(fld.fold_expr(cond), fld.fold_block(tr),
option::map_imm(fld.fold_expr, fl))
option::map(fld.fold_expr, fl))
}
expr_ternary(cond, tr, fl) {
expr_ternary(fld.fold_expr(cond), fld.fold_expr(tr),
@ -411,18 +408,18 @@ fn noop_fold_expr(e: expr_, fld: ast_fold) -> expr_ {
expr_index(fld.fold_expr(el), fld.fold_expr(er))
}
expr_path(pth) { expr_path(fld.fold_path(pth)) }
expr_fail(e) { expr_fail(option::map_imm(fld.fold_expr, e)) }
expr_fail(e) { expr_fail(option::map(fld.fold_expr, e)) }
expr_break. { e }
expr_cont. { e }
expr_ret(e) { expr_ret(option::map_imm(fld.fold_expr, e)) }
expr_put(e) { expr_put(option::map_imm(fld.fold_expr, e)) }
expr_ret(e) { expr_ret(option::map(fld.fold_expr, e)) }
expr_put(e) { expr_put(option::map(fld.fold_expr, e)) }
expr_be(e) { expr_be(fld.fold_expr(e)) }
expr_log(lv, e) { expr_log(lv, fld.fold_expr(e)) }
expr_assert(e) { expr_assert(fld.fold_expr(e)) }
expr_check(m, e) { expr_check(m, fld.fold_expr(e)) }
expr_if_check(cond, tr, fl) {
expr_if_check(fld.fold_expr(cond), fld.fold_block(tr),
option::map_imm(fld.fold_expr, fl))
option::map(fld.fold_expr, fl))
}
expr_anon_obj(ao) { expr_anon_obj(fold_anon_obj(ao)) }
expr_mac(mac) { expr_mac(fold_mac(mac)) }
@ -448,22 +445,22 @@ fn noop_fold_fn(f: _fn, fld: ast_fold) -> _fn {
purity: f.decl.purity,
il: f.decl.il,
cf: f.decl.cf,
constraints: vec::map_imm(fld.fold_constr, f.decl.constraints)},
constraints: vec::map(fld.fold_constr, f.decl.constraints)},
proto: f.proto,
body: fld.fold_block(f.body)};
}
// ...nor do modules
fn noop_fold_mod(m: _mod, fld: ast_fold) -> _mod {
ret {view_items: vec::map_imm(fld.fold_view_item, m.view_items),
items: vec::map_imm(fld.fold_item, m.items)};
ret {view_items: vec::map(fld.fold_view_item, m.view_items),
items: vec::map(fld.fold_item, m.items)};
}
fn noop_fold_native_mod(nm: native_mod, fld: ast_fold) -> native_mod {
ret {native_name: nm.native_name,
abi: nm.abi,
view_items: vec::map_imm(fld.fold_view_item, nm.view_items),
items: vec::map_imm(fld.fold_native_item, nm.items)}
view_items: vec::map(fld.fold_view_item, nm.view_items),
items: vec::map(fld.fold_native_item, nm.items)}
}
fn noop_fold_variant(v: variant_, fld: ast_fold) -> variant_ {
@ -479,7 +476,7 @@ fn noop_fold_ident(i: ident, _fld: ast_fold) -> ident { ret i; }
fn noop_fold_path(p: path_, fld: ast_fold) -> path_ {
ret {global: p.global,
idents: vec::map(fld.fold_ident, p.idents),
types: vec::map_imm(fld.fold_ty, p.types)};
types: vec::map(fld.fold_ty, p.types)};
}
fn noop_fold_local(l: local_, fld: ast_fold) -> local_ {
@ -498,8 +495,8 @@ fn noop_fold_local(l: local_, fld: ast_fold) -> local_ {
/* temporarily eta-expand because of a compiler bug with using `fn<T>` as a
value */
fn noop_map_exprs(f: fn(@expr) -> @expr, es: [@expr]) -> [@expr] {
ret vec::map_imm(f, es);
fn noop_map_exprs(f: fn(&&@expr) -> @expr, es: [@expr]) -> [@expr] {
ret vec::map(f, es);
}
fn noop_id(i: node_id) -> node_id { ret i; }
@ -603,55 +600,56 @@ fn make_fold(afp: ast_fold_precursor) -> @foldres {
ret {node: afp.fold_crate(c.node, f), span: afp.new_span(c.span)};
}
fn f_crate_directive(afp: ast_fold_precursor, f: ast_fold,
c: @crate_directive) -> @crate_directive {
&&c: @crate_directive) -> @crate_directive {
ret @{node: afp.fold_crate_directive(c.node, f),
span: afp.new_span(c.span)};
}
fn f_view_item(afp: ast_fold_precursor, f: ast_fold, x: @view_item) ->
fn f_view_item(afp: ast_fold_precursor, f: ast_fold, &&x: @view_item) ->
@view_item {
ret @{node: afp.fold_view_item(x.node, f),
span: afp.new_span(x.span)};
}
fn f_native_item(afp: ast_fold_precursor, f: ast_fold, x: @native_item) ->
@native_item {
fn f_native_item(afp: ast_fold_precursor, f: ast_fold, &&x: @native_item)
-> @native_item {
ret afp.fold_native_item(x, f);
}
fn f_item(afp: ast_fold_precursor, f: ast_fold, i: @item) -> @item {
fn f_item(afp: ast_fold_precursor, f: ast_fold, &&i: @item) -> @item {
ret afp.fold_item(i, f);
}
fn f_item_underscore(afp: ast_fold_precursor, f: ast_fold, i: item_) ->
item_ {
ret afp.fold_item_underscore(i, f);
}
fn f_method(afp: ast_fold_precursor, f: ast_fold, x: @method) -> @method {
fn f_method(afp: ast_fold_precursor, f: ast_fold, &&x: @method)
-> @method {
ret @{node: afp.fold_method(x.node, f), span: afp.new_span(x.span)};
}
fn f_block(afp: ast_fold_precursor, f: ast_fold, x: blk) -> blk {
ret {node: afp.fold_block(x.node, f), span: afp.new_span(x.span)};
}
fn f_stmt(afp: ast_fold_precursor, f: ast_fold, x: @stmt) -> @stmt {
fn f_stmt(afp: ast_fold_precursor, f: ast_fold, &&x: @stmt) -> @stmt {
ret @{node: afp.fold_stmt(x.node, f), span: afp.new_span(x.span)};
}
fn f_arm(afp: ast_fold_precursor, f: ast_fold, x: arm) -> arm {
ret afp.fold_arm(x, f);
}
fn f_pat(afp: ast_fold_precursor, f: ast_fold, x: @pat) -> @pat {
fn f_pat(afp: ast_fold_precursor, f: ast_fold, &&x: @pat) -> @pat {
ret @{id: afp.new_id(x.id),
node: afp.fold_pat(x.node, f),
span: afp.new_span(x.span)};
}
fn f_decl(afp: ast_fold_precursor, f: ast_fold, x: @decl) -> @decl {
fn f_decl(afp: ast_fold_precursor, f: ast_fold, &&x: @decl) -> @decl {
ret @{node: afp.fold_decl(x.node, f), span: afp.new_span(x.span)};
}
fn f_expr(afp: ast_fold_precursor, f: ast_fold, x: @expr) -> @expr {
fn f_expr(afp: ast_fold_precursor, f: ast_fold, &&x: @expr) -> @expr {
ret @{id: afp.new_id(x.id),
node: afp.fold_expr(x.node, f),
span: afp.new_span(x.span)};
}
fn f_ty(afp: ast_fold_precursor, f: ast_fold, x: @ty) -> @ty {
fn f_ty(afp: ast_fold_precursor, f: ast_fold, &&x: @ty) -> @ty {
ret @{node: afp.fold_ty(x.node, f), span: afp.new_span(x.span)};
}
fn f_constr(afp: ast_fold_precursor, f: ast_fold, x: @ast::constr) ->
fn f_constr(afp: ast_fold_precursor, f: ast_fold, &&x: @ast::constr) ->
@ast::constr {
ret @{node: afp.fold_constr(x.node, f), span: afp.new_span(x.span)};
}
@ -675,7 +673,7 @@ fn make_fold(afp: ast_fold_precursor) -> @foldres {
fn f_path(afp: ast_fold_precursor, f: ast_fold, x: path) -> path {
ret {node: afp.fold_path(x.node, f), span: afp.new_span(x.span)};
}
fn f_local(afp: ast_fold_precursor, f: ast_fold, x: @local) -> @local {
fn f_local(afp: ast_fold_precursor, f: ast_fold, &&x: @local) -> @local {
ret @{node: afp.fold_local(x.node, f), span: afp.new_span(x.span)};
}

View file

@ -9,11 +9,6 @@ fn get<@T>(opt: t<T>) -> &T {
fn map<@T, @U>(f: block(T) -> U, opt: t<T>) -> t<U> {
alt opt { some(x) { some(f(x)) } none. { none } }
}
// FIXME This is needed to make working with by-value functions a bit less
// painful. We should come up with a better solution.
fn map_imm<@T, @U>(f: block(+T) -> U, opt: t<T>) -> t<U> {
alt opt { some(x) { some(f(x)) } none. { none } }
}
fn is_none<@T>(opt: t<T>) -> bool {
alt opt { none. { true } some(_) { false } }

View file

@ -191,17 +191,6 @@ fn map<@T, @U>(f: block(T) -> U, v: [mutable? T]) -> [U] {
}
ret result;
}
// FIXME This is needed to make working with by-value functions a bit less
// painful. We should come up with a better solution.
fn map_imm<@T, @U>(f: block(+T) -> U, v: [mutable? T]) -> [U] {
let result = [];
reserve(result, len(v));
for elem: T in v {
let elem2 = elem; // satisfies alias checker
result += [f(elem2)];
}
ret result;
}
fn map2<@T, @U, @V>(f: block(T, U) -> V, v0: [T], v1: [U]) -> [V] {
let v0_len = len::<T>(v0);