Skip to content

Commit aa5382b

Browse files
committed
split proto from fn_decl, as not all fn_decls know the proto.
this will address the (crashing) new test added.
1 parent d6db950 commit aa5382b

25 files changed

+229
-200
lines changed

src/comp/front/test.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,7 @@ fn mk_tests(cx: test_ctxt) -> @ast::item {
190190
let ret_ty = mk_test_desc_vec_ty(cx);
191191

192192
let decl: ast::fn_decl =
193-
{proto: ast::proto_bare,
194-
inputs: [],
193+
{inputs: [],
195194
output: ret_ty,
196195
purity: ast::impure_fn,
197196
cf: ast::return_val,
@@ -322,7 +321,6 @@ fn mk_test_wrapper(cx: test_ctxt,
322321
ast::stmt_expr(@call_expr, cx.sess.next_node_id()));
323322

324323
let wrapper_decl: ast::fn_decl = {
325-
proto: ast::proto_bare,
326324
inputs: [],
327325
output: @nospan(ast::ty_nil),
328326
purity: ast::impure_fn,
@@ -345,7 +343,8 @@ fn mk_test_wrapper(cx: test_ctxt,
345343

346344
let wrapper_expr: ast::expr = {
347345
id: cx.sess.next_node_id(),
348-
node: ast::expr_fn(wrapper_decl, wrapper_body, wrapper_capture),
346+
node: ast::expr_fn(ast::proto_bare, wrapper_decl,
347+
wrapper_body, wrapper_capture),
349348
span: span
350349
};
351350

@@ -366,8 +365,7 @@ fn mk_main(cx: test_ctxt) -> @ast::item {
366365
let ret_ty = nospan(ast::ty_nil);
367366

368367
let decl: ast::fn_decl =
369-
{proto: ast::proto_bare,
370-
inputs: [args_arg],
368+
{inputs: [args_arg],
371369
output: @ret_ty,
372370
purity: ast::impure_fn,
373371
cf: ast::return_val,

src/comp/middle/alias.rs

Lines changed: 3 additions & 3 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: bind visit_fn(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,8 +71,8 @@ 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(cx: @ctx, decl: ast::fn_decl, _ts: [ast::ty_param],
75-
body: ast::blk, sp: span, _name: ast::fn_ident,
74+
fn visit_fn(cx: @ctx, _fk: visit::fn_kind, decl: ast::fn_decl,
75+
body: ast::blk, sp: span,
7676
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);

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: bind map_fn(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(cx: ctx, decl: fn_decl, _tps: [ty_param], _body: blk,
44-
_sp: codemap::span, _n: fn_ident, _id: node_id) {
43+
fn map_fn(cx: ctx, _fk: visit::fn_kind, decl: fn_decl, _body: blk,
44+
_sp: codemap::span, _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/debuginfo.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -736,7 +736,7 @@ fn create_function(fcx: @fn_ctxt) -> @metadata<subprogram_md> {
736736
}
737737
ast_map::node_expr(expr) {
738738
alt expr.node {
739-
ast::expr_fn(decl, _, _) {
739+
ast::expr_fn(_, decl, _, _) {
740740
(dbg_cx.names.next("fn"), decl.output, expr.id)
741741
}
742742
ast::expr_fn_block(decl, _) {

src/comp/middle/freevars.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ fn collect_freevars(def_map: resolve::def_map, blk: ast::blk)
3838
let walk_expr =
3939
lambda (expr: @ast::expr, &&depth: int, v: visit::vt<int>) {
4040
alt expr.node {
41-
ast::expr_fn(decl, _, captures) {
42-
if decl.proto != ast::proto_bare {
41+
ast::expr_fn(proto, decl, _, captures) {
42+
if proto != ast::proto_bare {
4343
visit::visit_expr(expr, depth + 1, v);
4444
}
4545
}
@@ -82,9 +82,8 @@ 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 = lambda (_decl: ast::fn_decl, _tps: [ast::ty_param],
86-
blk: ast::blk, _sp: span, _nm: ast::fn_ident,
87-
nid: ast::node_id) {
85+
let walk_fn = lambda (_fk: visit::fn_kind, _decl: ast::fn_decl,
86+
blk: ast::blk, _sp: span, nid: ast::node_id) {
8887
let vars = collect_freevars(def_map, blk);
8988
freevars.insert(nid, vars);
9089
};

src/comp/middle/kind.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ fn with_closure_check_fn(cx: ctx, id: node_id,
6767

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

7373
// n.b.: This could be the body of either a fn decl or a fn expr. In the
7474
// former case, the prototype will be proto_bare and no check occurs. In
@@ -88,7 +88,7 @@ fn check_fn(decl: fn_decl, tps: [ty_param], body: blk, sp: span,
8888
}
8989
}
9090

91-
visit::visit_fn(decl, tps, body, sp, i, id, cx, v);
91+
visit::visit_fn(fk, decl, body, sp, id, cx, v);
9292
}
9393

9494
fn check_fn_cap_clause(cx: ctx,
@@ -181,7 +181,7 @@ fn check_expr(e: @expr, cx: ctx, v: visit::vt<ctx>) {
181181
}
182182
}
183183
expr_ternary(_, a, b) { maybe_copy(cx, a); maybe_copy(cx, b); }
184-
expr_fn(_, _, cap_clause) {
184+
expr_fn(_, _, _, cap_clause) {
185185
check_fn_cap_clause(cx, e.id, *cap_clause);
186186
}
187187
_ { }

src/comp/middle/last_use.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ fn visit_expr(ex: @expr, cx: ctx, v: visit::vt<ctx>) {
136136
for arg in args {
137137
alt arg.node {
138138
//NDM--register captured as uses
139-
expr_fn(_, _, captured) { fns += [arg]; }
139+
expr_fn(_, _, _, captured) { fns += [arg]; }
140140
expr_fn_block(_, _) { fns += [arg]; }
141141
_ {
142142
alt arg_ts[i].mode {
@@ -153,19 +153,19 @@ fn visit_expr(ex: @expr, cx: ctx, v: visit::vt<ctx>) {
153153
}
154154
}
155155

156-
fn visit_fn(decl: fn_decl, tps: [ty_param], body: blk,
157-
sp: span, nm: fn_ident, id: node_id,
156+
fn visit_fn(fk: visit::fn_kind, decl: fn_decl, body: blk,
157+
sp: span, id: node_id,
158158
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(decl, tps, body, sp, nm, id, cx, v);
163+
visit::visit_fn(fk, decl, body, sp, id, cx, v);
164164
});
165165
} else {
166166
let old = nil;
167167
cx.blocks <-> old;
168-
visit::visit_fn(decl, tps, body, sp, nm, id, cx, v);
168+
visit::visit_fn(fk, decl, body, sp, id, cx, v);
169169
cx.blocks <-> old;
170170
leave_fn(cx);
171171
}

src/comp/middle/resolve.rs

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -336,7 +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: bind visit_fn_with_scope(e, _, _, _, _, _, _, _, _)
339+
visit_fn: bind visit_fn_with_scope(e, _, _, _, _, _, _, _)
340340
with *visit::default_visitor()};
341341
visit::visit_crate(*c, cons(scope_crate, @nil), visit::mk_vt(v));
342342
e.used_imports.track = false;
@@ -350,7 +350,7 @@ fn resolve_names(e: @env, c: @ast::crate) {
350350
lookup_path_strict(*e, sc, exp.span, p.node,
351351
ns_value));
352352
}
353-
ast::expr_fn(_, _, cap_clause) {
353+
ast::expr_fn(_, _, _, cap_clause) {
354354
let rci = bind resolve_capture_item(e, sc, _);
355355
vec::iter(cap_clause.copies, rci);
356356
vec::iter(cap_clause.moves, rci);
@@ -403,8 +403,9 @@ fn visit_item_with_scope(i: @ast::item, sc: scopes, v: vt<scopes>) {
403403
alt ifce { some(ty) { v.visit_ty(ty, sc, v); } _ {} }
404404
v.visit_ty(sty, sc, v);
405405
for m in methods {
406-
v.visit_fn(m.decl, tps + m.tps, m.body, m.span,
407-
some(m.ident), m.id, sc, v);
406+
v.visit_fn(visit::fk_method(m.ident, tps + m.tps),
407+
m.decl, m.body, m.span,
408+
m.id, sc, v);
408409
}
409410
}
410411
_ { visit::visit_item(i, sc, v); }
@@ -416,30 +417,35 @@ fn visit_native_item_with_scope(ni: @ast::native_item, sc: scopes,
416417
visit::visit_native_item(ni, cons(scope_native_item(ni), @sc), v);
417418
}
418419

419-
fn visit_fn_with_scope(e: @env, decl: ast::fn_decl, tp: [ast::ty_param],
420-
body: ast::blk, sp: span, name: fn_ident,
420+
fn visit_fn_with_scope(e: @env, fk: visit::fn_kind, decl: ast::fn_decl,
421+
body: ast::blk, sp: span,
421422
id: node_id, sc: scopes, v: vt<scopes>) {
422423
// is this a main fn declaration?
423-
alt name {
424-
some(nm) {
424+
alt fk {
425+
visit::fk_item_fn(nm, _) {
425426
if is_main_name([nm]) && !e.sess.building_library() {
426427
// This is a main function -- set it in the session
427428
// as the main ID
428429
e.sess.set_main_id(id);
429430
}
430431
}
431-
_ { }
432+
_ { /* fallthrough */ }
432433
}
433434

434435
// here's where we need to set up the mapping
435436
// for f's constrs in the table.
436437
for c: @ast::constr in decl.constraints { resolve_constr(e, c, sc, v); }
437-
let scope = alt decl.proto {
438-
ast::proto_bare. { scope_bare_fn(decl, id, tp) }
439-
_ { scope_fn_expr(decl, id, tp) }
438+
let scope = alt fk {
439+
visit::fk_item_fn(_, tps) | visit::fk_method(_, tps) |
440+
visit::fk_res(_, tps) {
441+
scope_bare_fn(decl, id, tps)
442+
}
443+
visit::fk_anon(_) | visit::fk_fn_block. {
444+
scope_fn_expr(decl, id, [])
445+
}
440446
};
441447

442-
visit::visit_fn(decl, tp, body, sp, name, id, cons(scope, @sc), v);
448+
visit::visit_fn(fk, decl, body, sp, id, cons(scope, @sc), v);
443449
}
444450

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

src/comp/middle/trans.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3551,16 +3551,18 @@ fn trans_expr(bcx: @block_ctxt, e: @ast::expr, dest: dest) -> @block_ctxt {
35513551
assert op != ast::deref; // lvals are handled above
35523552
ret trans_unary(bcx, op, x, e.id, dest);
35533553
}
3554-
ast::expr_fn(decl, body, cap_clause) {
3554+
ast::expr_fn(proto, decl, body, cap_clause) {
35553555
ret trans_closure::trans_expr_fn(
3556-
bcx, decl, body, e.span, e.id, *cap_clause, dest);
3556+
bcx, proto, decl, body, e.span, e.id, *cap_clause, dest);
35573557
}
35583558
ast::expr_fn_block(decl, body) {
35593559
alt ty::struct(tcx, ty::expr_ty(tcx, e)) {
35603560
ty::ty_fn({proto, _}) {
3561+
#debug("translating fn_block %s with type %s",
3562+
expr_to_str(e), ty_to_str(tcx, ty::expr_ty(tcx, e)));
35613563
let cap_clause = { copies: [], moves: [] };
35623564
ret trans_closure::trans_expr_fn(
3563-
bcx, decl, body, e.span, e.id, cap_clause, dest);
3565+
bcx, proto, decl, body, e.span, e.id, cap_clause, dest);
35643566
}
35653567
_ {
35663568
fail "Type of fn block is not a function!";

src/comp/middle/trans_closure.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,7 @@ fn load_environment(enclosing_cx: @block_ctxt,
372372
}
373373

374374
fn trans_expr_fn(bcx: @block_ctxt,
375+
proto: ast::proto,
375376
decl: ast::fn_decl,
376377
body: ast::blk,
377378
sp: span,
@@ -390,15 +391,15 @@ fn trans_expr_fn(bcx: @block_ctxt,
390391

391392
let trans_closure_env = lambda(ck: ty::closure_kind) -> ValueRef {
392393
let cap_vars = capture::compute_capture_vars(
393-
ccx.tcx, id, decl.proto, cap_clause);
394+
ccx.tcx, id, proto, cap_clause);
394395
let {llbox, box_ty, bcx} = build_closure(bcx, cap_vars, ck);
395396
trans_closure(sub_cx, sp, decl, body, llfn, no_self, [], id, {|fcx|
396397
load_environment(bcx, fcx, box_ty, cap_vars, ck);
397398
});
398399
llbox
399400
};
400401

401-
let closure = alt decl.proto {
402+
let closure = alt proto {
402403
ast::proto_block. { trans_closure_env(ty::closure_block) }
403404
ast::proto_shared(_) { trans_closure_env(ty::closure_shared) }
404405
ast::proto_send. { trans_closure_env(ty::closure_send) }

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(ccx: crate_ctxt, _decl: fn_decl, _ts: [ty_param], body: blk,
60-
_sp: span, _n: fn_ident, id: node_id) {
59+
fn annotate_in_fn(ccx: crate_ctxt, _fk: visit::fn_kind, _decl: fn_decl,
60+
body: blk, _sp: span, 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: bind annotate_in_fn(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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,8 +1008,8 @@ fn op_to_oper_ty(io: init_op) -> oper_type {
10081008
}
10091009

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

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: 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: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -94,21 +94,20 @@ fn check_states_stmt(s: @stmt, fcx: fn_ctxt, v: visit::vt<fn_ctxt>) {
9494
}
9595

9696
fn check_states_against_conditions(fcx: fn_ctxt,
97+
fk: visit::fn_kind,
9798
f_decl: ast::fn_decl,
9899
f_body: ast::blk,
99100
sp: span,
100-
nm: fn_ident,
101101
id: node_id) {
102102
/* Postorder traversal instead of pre is important
103103
because we want the smallest possible erroneous statement
104104
or expression. */
105-
106105
let visitor = visit::mk_vt(
107106
@{visit_stmt: check_states_stmt,
108107
visit_expr: check_states_expr,
109-
visit_fn: bind do_nothing::<fn_ctxt>(_, _, _, _, _, _, _, _)
108+
visit_fn: bind do_nothing::<fn_ctxt>(_, _, _, _, _, _, _)
110109
with *visit::default_visitor::<fn_ctxt>()});
111-
visit::visit_fn(f_decl, [], f_body, sp, nm, id, fcx, visitor);
110+
visit::visit_fn(fk, f_decl, f_body, sp, id, fcx, visitor);
112111

113112
/* Check that the return value is initialized */
114113
let post = aux::block_poststate(fcx.ccx, f_body);
@@ -142,10 +141,10 @@ fn check_states_against_conditions(fcx: fn_ctxt,
142141
}
143142

144143
fn check_fn_states(fcx: fn_ctxt,
144+
fk: visit::fn_kind,
145145
f_decl: ast::fn_decl,
146146
f_body: ast::blk,
147147
sp: span,
148-
nm: fn_ident,
149148
id: node_id) {
150149
/* Compute the pre- and post-states for this function */
151150

@@ -155,20 +154,20 @@ fn check_fn_states(fcx: fn_ctxt,
155154
/* Now compare each expr's pre-state to its precondition
156155
and post-state to its postcondition */
157156

158-
check_states_against_conditions(fcx, f_decl, f_body, sp, nm, id);
157+
check_states_against_conditions(fcx, fk, f_decl, f_body, sp, id);
159158
}
160159

161-
fn fn_states(f_decl: ast::fn_decl, tps: [ast::ty_param], f_body: ast::blk,
162-
sp: span, i: ast::fn_ident, id: node_id,
160+
fn fn_states(fk: visit::fn_kind, f_decl: ast::fn_decl, f_body: ast::blk,
161+
sp: span, id: node_id,
163162
ccx: crate_ctxt, v: visit::vt<crate_ctxt>) {
164-
visit::visit_fn(f_decl, tps, f_body, sp, i, id, ccx, v);
163+
visit::visit_fn(fk, f_decl, f_body, sp, id, ccx, v);
165164
/* Look up the var-to-bit-num map for this function */
166165

167166
assert (ccx.fm.contains_key(id));
168167
let f_info = ccx.fm.get(id);
169-
let name = option::from_maybe("anon", i); // XXXX
168+
let name = visit::name_of_fn(fk);
170169
let fcx = {enclosing: f_info, id: id, name: name, ccx: ccx};
171-
check_fn_states(fcx, f_decl, f_body, sp, i, id)
170+
check_fn_states(fcx, fk, f_decl, f_body, sp, id)
172171
}
173172

174173
fn check_crate(cx: ty::ctxt, crate: @crate) {

0 commit comments

Comments
 (0)