Skip to content

Commit

Permalink
Give up on providing a by-value version of map, convert fold over to
Browse files Browse the repository at this point in the history
passing pointers by ref

Issue #1008
  • Loading branch information
marijnh committed Oct 7, 2011
1 parent f9fbd86 commit fe916fb
Show file tree
Hide file tree
Showing 9 changed files with 98 additions and 115 deletions.
10 changes: 5 additions & 5 deletions src/comp/front/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) ->
Expand All @@ -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};
}

Expand All @@ -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};
}
Expand Down
2 changes: 1 addition & 1 deletion src/comp/front/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
4 changes: 2 additions & 2 deletions src/comp/middle/tstate/ann.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions src/comp/middle/tstate/pre_post_conditions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
15 changes: 8 additions & 7 deletions src/comp/middle/typeck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand All @@ -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 }
Expand All @@ -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) }
Expand Down Expand Up @@ -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>) ->
Expand All @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions src/comp/syntax/ext/simplext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}
}
Expand Down
Loading

0 comments on commit fe916fb

Please sign in to comment.