Skip to content

Commit 46cddff

Browse files
committed
Go back to a single visit_fn function in visit.rs
1 parent 711ff65 commit 46cddff

File tree

14 files changed

+75
-101
lines changed

14 files changed

+75
-101
lines changed

src/comp/middle/alias.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ fn check_crate(tcx: ty::ctxt, crate: @ast::crate) -> (copy_map, ref_map) {
6161
copy_map: std::map::new_int_hash(),
6262
ref_map: std::map::new_int_hash(),
6363
mutable silent: false};
64-
let v = @{visit_fn_body: bind visit_fn_body(cx, _, _, _, _, _, _, _),
64+
let v = @{visit_fn: bind visit_fn(cx, _, _, _, _, _, _, _, _),
6565
visit_expr: bind visit_expr(cx, _, _, _),
6666
visit_block: bind visit_block(cx, _, _, _)
6767
with *visit::default_visitor::<scope>()};
@@ -71,9 +71,9 @@ fn check_crate(tcx: ty::ctxt, crate: @ast::crate) -> (copy_map, ref_map) {
7171
ret (cx.copy_map, cx.ref_map);
7272
}
7373

74-
fn visit_fn_body(cx: @ctx, decl: ast::fn_decl, body: ast::blk,
75-
sp: span, _name: ast::fn_ident,
76-
id: ast::node_id, sc: scope, v: vt<scope>) {
74+
fn visit_fn(cx: @ctx, decl: ast::fn_decl, _ts: [ast::ty_param],
75+
body: ast::blk, sp: span, _name: ast::fn_ident,
76+
id: ast::node_id, sc: scope, v: vt<scope>) {
7777
visit::visit_fn_decl(decl, sc, v);
7878
let fty = ty::node_id_to_type(cx.tcx, id);
7979
let args = ty::ty_fn_args(cx.tcx, fty);

src/comp/middle/ast_map.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,16 @@ fn map_crate(c: crate) -> map {
3232
(@{visit_item: bind map_item(cx, _),
3333
visit_native_item: bind map_native_item(cx, _),
3434
visit_expr: bind map_expr(cx, _),
35-
visit_fn_body: bind map_fn_body(cx, _, _, _, _, _),
35+
visit_fn: bind map_fn(cx, _, _, _, _, _, _),
3636
visit_local: bind map_local(cx, _),
3737
visit_arm: bind map_arm(cx, _)
3838
with *visit::default_simple_visitor()});
3939
visit::visit_crate(c, (), v_map);
4040
ret cx.map;
4141
}
4242

43-
fn map_fn_body(cx: ctx, decl: fn_decl, _body: blk,
44-
_sp: codemap::span, _n: fn_ident, _id: node_id) {
43+
fn map_fn(cx: ctx, decl: fn_decl, _tps: [ty_param], _body: blk,
44+
_sp: codemap::span, _n: fn_ident, _id: node_id) {
4545
for a in decl.inputs {
4646
cx.map.insert(a.id, node_arg(a, cx.local_id));
4747
cx.local_id += 1u;

src/comp/middle/freevars.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,15 @@ fn annotate_freevars(def_map: resolve::def_map, crate: @ast::crate) ->
8282
freevar_map {
8383
let freevars = new_int_hash();
8484

85-
let walk_fn_body = lambda (_decl: ast::fn_decl, blk: ast::blk,
86-
_sp: span, _nm: ast::fn_ident,
87-
nid: ast::node_id) {
85+
let walk_fn = lambda (_decl: ast::fn_decl, _tps: [ast::ty_param],
86+
blk: ast::blk, _sp: span, _nm: ast::fn_ident,
87+
nid: ast::node_id) {
8888
let vars = collect_freevars(def_map, blk);
8989
freevars.insert(nid, vars);
9090
};
9191

9292
let visitor =
93-
visit::mk_simple_visitor(@{visit_fn_body: walk_fn_body
93+
visit::mk_simple_visitor(@{visit_fn: walk_fn
9494
with *visit::default_simple_visitor()});
9595
visit::visit_crate(*crate, (), visitor);
9696

src/comp/middle/kind.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ fn check_crate(tcx: ty::ctxt, method_map: typeck::method_map,
4343
let visit = visit::mk_vt(@{
4444
visit_expr: check_expr,
4545
visit_stmt: check_stmt,
46-
visit_fn_body: check_fn_body
46+
visit_fn: check_fn
4747
with *visit::default_visitor()
4848
});
4949
visit::visit_crate(*crate, ctx, visit);
@@ -66,8 +66,8 @@ fn with_closure_check_fn(cx: ctx, id: node_id,
6666

6767
// Check that the free variables used in a shared/sendable closure conform
6868
// to the copy/move kind bounds. Then recursively check the function body.
69-
fn check_fn_body(decl: fn_decl, body: blk, sp: span, i: fn_ident, id: node_id,
70-
cx: ctx, v: visit::vt<ctx>) {
69+
fn check_fn(decl: fn_decl, tps: [ty_param], body: blk, sp: span,
70+
i: fn_ident, id: node_id, cx: ctx, v: visit::vt<ctx>) {
7171

7272
// n.b.: This could be the body of either a fn decl or a fn expr. In the
7373
// former case, the prototype will be proto_bare and no check occurs. In
@@ -87,7 +87,7 @@ fn check_fn_body(decl: fn_decl, body: blk, sp: span, i: fn_ident, id: node_id,
8787
}
8888
}
8989

90-
visit::visit_fn_body(decl, body, sp, i, id, cx, v);
90+
visit::visit_fn(decl, tps, body, sp, i, id, cx, v);
9191
}
9292

9393
fn check_fn_cap_clause(cx: ctx,

src/comp/middle/last_use.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ type ctx = {last_uses: std::map::hashmap<node_id, bool>,
4343
fn find_last_uses(c: @crate, def_map: resolve::def_map,
4444
ref_map: alias::ref_map, tcx: ty::ctxt) -> last_uses {
4545
let v = visit::mk_vt(@{visit_expr: visit_expr,
46-
visit_fn_body: visit_fn_body
46+
visit_fn: visit_fn
4747
with *visit::default_visitor()});
4848
let cx = {last_uses: std::map::new_int_hash(),
4949
def_map: def_map,
@@ -153,19 +153,19 @@ fn visit_expr(ex: @expr, cx: ctx, v: visit::vt<ctx>) {
153153
}
154154
}
155155

156-
fn visit_fn_body(decl: fn_decl, body: blk,
157-
sp: span, nm: fn_ident, id: node_id,
158-
cx: ctx, v: visit::vt<ctx>) {
156+
fn visit_fn(decl: fn_decl, tps: [ty_param], body: blk,
157+
sp: span, nm: fn_ident, id: node_id,
158+
cx: ctx, v: visit::vt<ctx>) {
159159
let fty = ty::node_id_to_type(cx.tcx, id);
160160
let proto = ty::ty_fn_proto(cx.tcx, fty);
161161
if proto == proto_block {
162162
visit_block(func, cx, {||
163-
visit::visit_fn_body(decl, body, sp, nm, id, cx, v);
163+
visit::visit_fn(decl, tps, body, sp, nm, id, cx, v);
164164
});
165165
} else {
166166
let old = nil;
167167
cx.blocks <-> old;
168-
visit::visit_fn_body(decl, body, sp, nm, id, cx, v);
168+
visit::visit_fn(decl, tps, body, sp, nm, id, cx, v);
169169
cx.blocks <-> old;
170170
leave_fn(cx);
171171
}

src/comp/middle/resolve.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -336,8 +336,7 @@ fn resolve_names(e: @env, c: @ast::crate) {
336336
visit_expr: bind walk_expr(e, _, _, _),
337337
visit_ty: bind walk_ty(e, _, _, _),
338338
visit_constr: bind walk_constr(e, _, _, _, _, _),
339-
visit_fn_proto:
340-
bind visit_fn_proto_with_scope(e, _, _, _, _, _, _, _, _)
339+
visit_fn: bind visit_fn_with_scope(e, _, _, _, _, _, _, _, _)
341340
with *visit::default_visitor()};
342341
visit::visit_crate(*c, cons(scope_crate, @nil), visit::mk_vt(v));
343342
e.used_imports.track = false;
@@ -403,8 +402,8 @@ fn visit_item_with_scope(i: @ast::item, sc: scopes, v: vt<scopes>) {
403402
alt ifce { some(ty) { v.visit_ty(ty, sc, v); } _ {} }
404403
v.visit_ty(sty, sc, v);
405404
for m in methods {
406-
v.visit_fn_proto(m.decl, tps + m.tps, m.body, m.span,
407-
some(m.ident), m.id, sc, v);
405+
v.visit_fn(m.decl, tps + m.tps, m.body, m.span,
406+
some(m.ident), m.id, sc, v);
408407
}
409408
}
410409
_ { visit::visit_item(i, sc, v); }
@@ -416,9 +415,9 @@ fn visit_native_item_with_scope(ni: @ast::native_item, sc: scopes,
416415
visit::visit_native_item(ni, cons(scope_native_item(ni), @sc), v);
417416
}
418417

419-
fn visit_fn_proto_with_scope(e: @env, decl: ast::fn_decl, tp: [ast::ty_param],
420-
body: ast::blk, sp: span, name: fn_ident,
421-
id: node_id, sc: scopes, v: vt<scopes>) {
418+
fn visit_fn_with_scope(e: @env, decl: ast::fn_decl, tp: [ast::ty_param],
419+
body: ast::blk, sp: span, name: fn_ident,
420+
id: node_id, sc: scopes, v: vt<scopes>) {
422421
// is this a main fn declaration?
423422
alt name {
424423
some(nm) {
@@ -439,7 +438,7 @@ fn visit_fn_proto_with_scope(e: @env, decl: ast::fn_decl, tp: [ast::ty_param],
439438
_ { scope_fn_expr(decl, id, tp) }
440439
};
441440

442-
visit::visit_fn_proto(decl, tp, body, sp, name, id, cons(scope, @sc), v);
441+
visit::visit_fn(decl, tp, body, sp, name, id, cons(scope, @sc), v);
443442
}
444443

445444
fn visit_block_with_scope(b: ast::blk, sc: scopes, v: vt<scopes>) {

src/comp/middle/tstate/annotate.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,16 @@ fn visit_fn(ccx: crate_ctxt, num_constraints: uint, body: blk) {
5656
init_vecs(ccx, node_id_vec, num_constraints);
5757
}
5858

59-
fn annotate_in_fn_body(ccx: crate_ctxt, _decl: fn_decl, body: blk,
60-
_sp: span, _n: fn_ident, id: node_id) {
59+
fn annotate_in_fn(ccx: crate_ctxt, _decl: fn_decl, _ts: [ty_param], body: blk,
60+
_sp: span, _n: fn_ident, id: node_id) {
6161
let f_info = get_fn_info(ccx, id);
6262
visit_fn(ccx, num_constraints(f_info), body);
6363
}
6464

6565
fn annotate_crate(ccx: crate_ctxt, crate: crate) {
6666
let do_ann =
6767
visit::mk_simple_visitor(
68-
@{visit_fn_body: bind annotate_in_fn_body(ccx, _, _, _, _, _)
68+
@{visit_fn: bind annotate_in_fn(ccx, _, _, _, _, _, _)
6969
with *visit::default_simple_visitor()});
7070
visit::visit_crate(crate, (), do_ann);
7171
}

src/comp/middle/tstate/auxiliary.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1008,7 +1008,7 @@ fn op_to_oper_ty(io: init_op) -> oper_type {
10081008
}
10091009

10101010
// default function visitor
1011-
fn do_nothing<T>(_decl: fn_decl, _body: blk,
1011+
fn do_nothing<T>(_decl: fn_decl, _ts: [ty_param], _body: blk,
10121012
_sp: span, _i: fn_ident, _id: node_id,
10131013
_t: T, _v: visit::vt<T>) {
10141014
}

src/comp/middle/tstate/bitvectors.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ fn relax_precond_block(fcx: fn_ctxt, i: node_id, b: blk) {
151151
visit_stmt: relax_precond_stmt,
152152
visit_item:
153153
fn (_i: @item, _cx: relax_ctxt, _vt: visit::vt<relax_ctxt>) { },
154-
visit_fn_body: bind do_nothing(_, _, _, _, _, _, _)
154+
visit_fn: bind do_nothing(_, _, _, _, _, _, _, _)
155155
with *visitor};
156156
let v1 = visit::mk_vt(visitor);
157157
v1.visit_block(b, cx, v1);

src/comp/middle/tstate/ck.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,9 @@ fn check_states_against_conditions(fcx: fn_ctxt,
106106
let visitor = visit::mk_vt(
107107
@{visit_stmt: check_states_stmt,
108108
visit_expr: check_states_expr,
109-
visit_fn_body: bind do_nothing::<fn_ctxt>(_, _, _, _, _, _, _)
109+
visit_fn: bind do_nothing::<fn_ctxt>(_, _, _, _, _, _, _, _)
110110
with *visit::default_visitor::<fn_ctxt>()});
111-
visit::visit_fn_body(f_decl, f_body, sp, nm, id, fcx, visitor);
111+
visit::visit_fn(f_decl, [], f_body, sp, nm, id, fcx, visitor);
112112

113113
/* Check that the return value is initialized */
114114
let post = aux::block_poststate(fcx.ccx, f_body);
@@ -158,10 +158,10 @@ fn check_fn_states(fcx: fn_ctxt,
158158
check_states_against_conditions(fcx, f_decl, f_body, sp, nm, id);
159159
}
160160

161-
fn fn_states(f_decl: ast::fn_decl, f_body: ast::blk,
161+
fn fn_states(f_decl: ast::fn_decl, tps: [ast::ty_param], f_body: ast::blk,
162162
sp: span, i: ast::fn_ident, id: node_id,
163163
ccx: crate_ctxt, v: visit::vt<crate_ctxt>) {
164-
visit::visit_fn_body(f_decl, f_body, sp, i, id, ccx, v);
164+
visit::visit_fn(f_decl, tps, f_body, sp, i, id, ccx, v);
165165
/* Look up the var-to-bit-num map for this function */
166166

167167
assert (ccx.fm.contains_key(id));
@@ -182,13 +182,13 @@ fn check_crate(cx: ty::ctxt, crate: @crate) {
182182
/* Compute the pre and postcondition for every subexpression */
183183

184184
let vtor = visit::default_visitor::<crate_ctxt>();
185-
vtor = @{visit_fn_body: fn_pre_post with *vtor};
185+
vtor = @{visit_fn: fn_pre_post with *vtor};
186186
visit::visit_crate(*crate, ccx, visit::mk_vt(vtor));
187187

188188
/* Check the pre- and postcondition against the pre- and poststate
189189
for every expression */
190190
let vtor = visit::default_visitor::<crate_ctxt>();
191-
vtor = @{visit_fn_body: fn_states with *vtor};
191+
vtor = @{visit_fn: fn_states with *vtor};
192192
visit::visit_crate(*crate, ccx, visit::mk_vt(vtor));
193193
}
194194
//

src/comp/middle/tstate/collect_locals.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ fn collect_pred(e: @expr, cx: ctxt, v: visit::vt<ctxt>) {
4646

4747
fn find_locals(tcx: ty::ctxt,
4848
f_decl: fn_decl,
49+
tps: [ty_param],
4950
f_body: blk,
5051
sp: span,
5152
n: fn_ident,
@@ -56,10 +57,10 @@ fn find_locals(tcx: ty::ctxt,
5657
visitor =
5758
@{visit_local: collect_local,
5859
visit_expr: collect_pred,
59-
visit_fn_body: bind do_nothing(_, _, _, _, _, _, _)
60+
visit_fn: bind do_nothing(_, _, _, _, _, _, _, _)
6061
with *visitor};
61-
visit::visit_fn_body(f_decl, f_body, sp,
62-
n, id, cx, visit::mk_vt(visitor));
62+
visit::visit_fn(f_decl, tps, f_body, sp,
63+
n, id, cx, visit::mk_vt(visitor));
6364
ret cx;
6465
}
6566

@@ -98,6 +99,7 @@ fn add_constraint(tcx: ty::ctxt, c: sp_constr, next: uint, tbl: constr_map) ->
9899
to a bit number in the precondition/postcondition vectors */
99100
fn mk_fn_info(ccx: crate_ctxt,
100101
f_decl: fn_decl,
102+
tps: [ty_param],
101103
f_body: blk,
102104
f_sp: span,
103105
f_name: fn_ident,
@@ -106,7 +108,8 @@ fn mk_fn_info(ccx: crate_ctxt,
106108
let res_map = @new_def_hash::<constraint>();
107109
let next: uint = 0u;
108110

109-
let cx: ctxt = find_locals(ccx.tcx, f_decl, f_body, f_sp, f_name, id);
111+
let cx: ctxt = find_locals(ccx.tcx, f_decl, tps, f_body, f_sp,
112+
f_name, id);
110113
/* now we have to add bit nums for both the constraints
111114
and the variables... */
112115

@@ -163,8 +166,8 @@ fn mk_fn_info(ccx: crate_ctxt,
163166
to bit number) */
164167
fn mk_f_to_fn_info(ccx: crate_ctxt, c: @crate) {
165168
let visitor =
166-
visit::mk_simple_visitor(@{visit_fn_body:
167-
bind mk_fn_info(ccx, _, _, _, _, _)
169+
visit::mk_simple_visitor(@{visit_fn:
170+
bind mk_fn_info(ccx, _, _, _, _, _, _)
168171
with *visit::default_simple_visitor()});
169172
visit::visit_crate(*c, (), visitor);
170173
}

src/comp/middle/tstate/pre_post_conditions.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -727,10 +727,10 @@ fn find_pre_post_fn(fcx: fn_ctxt, body: blk) {
727727
}
728728
}
729729

730-
fn fn_pre_post(decl: fn_decl, body: blk, sp: span,
730+
fn fn_pre_post(decl: fn_decl, tps: [ty_param], body: blk, sp: span,
731731
i: fn_ident, id: node_id,
732732
ccx: crate_ctxt, v: visit::vt<crate_ctxt>) {
733-
visit::visit_fn_body(decl, body, sp, i, id, ccx, v);
733+
visit::visit_fn(decl, tps, body, sp, i, id, ccx, v);
734734
assert (ccx.fm.contains_key(id));
735735
let fcx =
736736
{enclosing: ccx.fm.get(id),

src/comp/middle/typeck.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1124,16 +1124,16 @@ fn gather_locals(ccx: @crate_ctxt,
11241124
};
11251125

11261126
// Don't descend into fns and items
1127-
fn visit_fn_body<T>(_decl: ast::fn_decl, _body: ast::blk,
1128-
_sp: span, _nm: ast::fn_ident, _id: ast::node_id,
1129-
_t: T, _v: visit::vt<T>) {
1127+
fn visit_fn<T>(_decl: ast::fn_decl, _ts: [ast::ty_param], _body: ast::blk,
1128+
_sp: span, _nm: ast::fn_ident, _id: ast::node_id,
1129+
_t: T, _v: visit::vt<T>) {
11301130
}
11311131
fn visit_item<E>(_i: @ast::item, _e: E, _v: visit::vt<E>) { }
11321132

11331133
let visit =
11341134
@{visit_local: visit_local,
11351135
visit_pat: visit_pat,
1136-
visit_fn_body: bind visit_fn_body(_, _, _, _, _, _, _),
1136+
visit_fn: bind visit_fn(_, _, _, _, _, _, _, _),
11371137
visit_item: bind visit_item(_, _, _)
11381138
with *visit::default_visitor()};
11391139

0 commit comments

Comments
 (0)