Skip to content

Commit ea19f53

Browse files
author
Lenny222
committed
---
yaml --- r: 6969 b: refs/heads/master c: ab2a643 h: refs/heads/master i: 6967: f1309ce v: v3
1 parent 30d4c5a commit ea19f53

37 files changed

+603
-490
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: aa5382bb13690ff183f6e94065dadf0524ce1c6e
2+
refs/heads/master: ab2a643f278d09c3fcc140ecb4c7cecbf1aff3c4

trunk/doc/rust.texi

Lines changed: 262 additions & 97 deletions
Large diffs are not rendered by default.

trunk/src/comp/front/test.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,8 @@ 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-
{inputs: [],
193+
{proto: ast::proto_bare,
194+
inputs: [],
194195
output: ret_ty,
195196
purity: ast::impure_fn,
196197
cf: ast::return_val,
@@ -321,6 +322,7 @@ fn mk_test_wrapper(cx: test_ctxt,
321322
ast::stmt_expr(@call_expr, cx.sess.next_node_id()));
322323

323324
let wrapper_decl: ast::fn_decl = {
325+
proto: ast::proto_bare,
324326
inputs: [],
325327
output: @nospan(ast::ty_nil),
326328
purity: ast::impure_fn,
@@ -343,8 +345,7 @@ fn mk_test_wrapper(cx: test_ctxt,
343345

344346
let wrapper_expr: ast::expr = {
345347
id: cx.sess.next_node_id(),
346-
node: ast::expr_fn(ast::proto_bare, wrapper_decl,
347-
wrapper_body, wrapper_capture),
348+
node: ast::expr_fn(wrapper_decl, wrapper_body, wrapper_capture),
348349
span: span
349350
};
350351

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

367368
let decl: ast::fn_decl =
368-
{inputs: [args_arg],
369+
{proto: ast::proto_bare,
370+
inputs: [args_arg],
369371
output: @ret_ty,
370372
purity: ast::impure_fn,
371373
cf: ast::return_val,

trunk/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, _fk: visit::fn_kind, decl: ast::fn_decl,
75-
body: ast::blk, sp: span,
74+
fn visit_fn(cx: @ctx, decl: ast::fn_decl, _ts: [ast::ty_param],
75+
body: ast::blk, sp: span, _name: ast::fn_ident,
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);

trunk/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, _fk: visit::fn_kind, decl: fn_decl, _body: blk,
44-
_sp: codemap::span, _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;

trunk/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, _) {

trunk/src/comp/middle/freevars.rs

Lines changed: 5 additions & 4 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(proto, decl, _, captures) {
42-
if proto != ast::proto_bare {
41+
ast::expr_fn(decl, _, captures) {
42+
if decl.proto != ast::proto_bare {
4343
visit::visit_expr(expr, depth + 1, v);
4444
}
4545
}
@@ -82,8 +82,9 @@ 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 (_fk: visit::fn_kind, _decl: ast::fn_decl,
86-
blk: ast::blk, _sp: span, 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) {
8788
let vars = collect_freevars(def_map, blk);
8889
freevars.insert(nid, vars);
8990
};

trunk/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(fk: visit::fn_kind, decl: fn_decl, body: blk, sp: span,
71-
id: node_id, cx: ctx, v: visit::vt<ctx>) {
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>) {
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(fk: visit::fn_kind, decl: fn_decl, body: blk, sp: span,
8888
}
8989
}
9090

91-
visit::visit_fn(fk, decl, body, sp, id, cx, v);
91+
visit::visit_fn(decl, tps, body, sp, i, 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
_ { }

trunk/src/comp/middle/last_use.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import syntax::{visit, ast_util};
22
import syntax::ast::*;
33
import syntax::codemap::span;
4-
import std::list::{list, nil, cons, tail};
4+
import std::list::{is_not_empty, list, nil, cons, tail};
55
import core::{vec, option};
66
import std::list;
77

@@ -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(fk: visit::fn_kind, decl: fn_decl, body: blk,
157-
sp: span, id: node_id,
156+
fn visit_fn(decl: fn_decl, tps: [ty_param], body: blk,
157+
sp: span, nm: fn_ident, 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(fk, decl, body, sp, 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(fk, decl, body, sp, id, cx, v);
168+
visit::visit_fn(decl, tps, body, sp, nm, id, cx, v);
169169
cx.blocks <-> old;
170170
leave_fn(cx);
171171
}
@@ -177,7 +177,9 @@ fn visit_block(tp: block_type, cx: ctx, visit: block()) {
177177
visit();
178178
local.second = true;
179179
visit();
180-
cx.blocks = tail(cx.blocks);
180+
let cx_blocks = cx.blocks;
181+
check is_not_empty(cx_blocks);
182+
cx.blocks = tail(cx_blocks);
181183
cx.current = join_branches(local.exits);
182184
}
183185

trunk/src/comp/middle/resolve.rs

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ fn map_crate(e: @env, c: @ast::crate) {
266266
let imp = follow_import(*e, sc, *path, vi.span);
267267
if option::is_some(imp) {
268268
let glob = {def: option::get(imp), item: vi};
269+
check list::is_not_empty(sc);
269270
alt list::head(sc) {
270271
scope_item(i) {
271272
e.mod_map.get(i.id).glob_imports += [glob];
@@ -336,7 +337,7 @@ fn resolve_names(e: @env, c: @ast::crate) {
336337
visit_expr: bind walk_expr(e, _, _, _),
337338
visit_ty: bind walk_ty(e, _, _, _),
338339
visit_constr: bind walk_constr(e, _, _, _, _, _),
339-
visit_fn: bind visit_fn_with_scope(e, _, _, _, _, _, _, _)
340+
visit_fn: bind visit_fn_with_scope(e, _, _, _, _, _, _, _, _)
340341
with *visit::default_visitor()};
341342
visit::visit_crate(*c, cons(scope_crate, @nil), visit::mk_vt(v));
342343
e.used_imports.track = false;
@@ -350,7 +351,7 @@ fn resolve_names(e: @env, c: @ast::crate) {
350351
lookup_path_strict(*e, sc, exp.span, p.node,
351352
ns_value));
352353
}
353-
ast::expr_fn(_, _, _, cap_clause) {
354+
ast::expr_fn(_, _, cap_clause) {
354355
let rci = bind resolve_capture_item(e, sc, _);
355356
vec::iter(cap_clause.copies, rci);
356357
vec::iter(cap_clause.moves, rci);
@@ -403,9 +404,8 @@ fn visit_item_with_scope(i: @ast::item, sc: scopes, v: vt<scopes>) {
403404
alt ifce { some(ty) { v.visit_ty(ty, sc, v); } _ {} }
404405
v.visit_ty(sty, sc, v);
405406
for m in methods {
406-
v.visit_fn(visit::fk_method(m.ident, tps + m.tps),
407-
m.decl, m.body, m.span,
408-
m.id, sc, v);
407+
v.visit_fn(m.decl, tps + m.tps, m.body, m.span,
408+
some(m.ident), m.id, sc, v);
409409
}
410410
}
411411
_ { visit::visit_item(i, sc, v); }
@@ -417,35 +417,30 @@ fn visit_native_item_with_scope(ni: @ast::native_item, sc: scopes,
417417
visit::visit_native_item(ni, cons(scope_native_item(ni), @sc), v);
418418
}
419419

420-
fn visit_fn_with_scope(e: @env, fk: visit::fn_kind, decl: ast::fn_decl,
421-
body: ast::blk, sp: span,
420+
fn visit_fn_with_scope(e: @env, decl: ast::fn_decl, tp: [ast::ty_param],
421+
body: ast::blk, sp: span, name: fn_ident,
422422
id: node_id, sc: scopes, v: vt<scopes>) {
423423
// is this a main fn declaration?
424-
alt fk {
425-
visit::fk_item_fn(nm, _) {
424+
alt name {
425+
some(nm) {
426426
if is_main_name([nm]) && !e.sess.building_library() {
427427
// This is a main function -- set it in the session
428428
// as the main ID
429429
e.sess.set_main_id(id);
430430
}
431431
}
432-
_ { /* fallthrough */ }
432+
_ { }
433433
}
434434

435435
// here's where we need to set up the mapping
436436
// for f's constrs in the table.
437437
for c: @ast::constr in decl.constraints { resolve_constr(e, c, sc, v); }
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-
}
438+
let scope = alt decl.proto {
439+
ast::proto_bare. { scope_bare_fn(decl, id, tp) }
440+
_ { scope_fn_expr(decl, id, tp) }
446441
};
447442

448-
visit::visit_fn(fk, decl, body, sp, id, cons(scope, @sc), v);
443+
visit::visit_fn(decl, tp, body, sp, name, id, cons(scope, @sc), v);
449444
}
450445

451446
fn visit_block_with_scope(b: ast::blk, sc: scopes, v: vt<scopes>) {
@@ -461,6 +456,7 @@ fn visit_block_with_scope(b: ast::blk, sc: scopes, v: vt<scopes>) {
461456
}
462457

463458
fn visit_decl_with_scope(d: @decl, sc: scopes, v: vt<scopes>) {
459+
check list::is_not_empty(sc);
464460
let loc_pos = alt list::head(sc) {
465461
scope_block(_, _, pos) { pos }
466462
_ { @mutable 0u }

trunk/src/comp/middle/trans.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3551,18 +3551,16 @@ 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(proto, decl, body, cap_clause) {
3554+
ast::expr_fn(decl, body, cap_clause) {
35553555
ret trans_closure::trans_expr_fn(
3556-
bcx, proto, decl, body, e.span, e.id, *cap_clause, dest);
3556+
bcx, 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)));
35633561
let cap_clause = { copies: [], moves: [] };
35643562
ret trans_closure::trans_expr_fn(
3565-
bcx, proto, decl, body, e.span, e.id, cap_clause, dest);
3563+
bcx, decl, body, e.span, e.id, cap_clause, dest);
35663564
}
35673565
_ {
35683566
fail "Type of fn block is not a function!";

trunk/src/comp/middle/trans_closure.rs

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

374374
fn trans_expr_fn(bcx: @block_ctxt,
375-
proto: ast::proto,
376375
decl: ast::fn_decl,
377376
body: ast::blk,
378377
sp: span,
@@ -391,15 +390,15 @@ fn trans_expr_fn(bcx: @block_ctxt,
391390

392391
let trans_closure_env = lambda(ck: ty::closure_kind) -> ValueRef {
393392
let cap_vars = capture::compute_capture_vars(
394-
ccx.tcx, id, proto, cap_clause);
393+
ccx.tcx, id, decl.proto, cap_clause);
395394
let {llbox, box_ty, bcx} = build_closure(bcx, cap_vars, ck);
396395
trans_closure(sub_cx, sp, decl, body, llfn, no_self, [], id, {|fcx|
397396
load_environment(bcx, fcx, box_ty, cap_vars, ck);
398397
});
399398
llbox
400399
};
401400

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

trunk/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, _fk: visit::fn_kind, _decl: fn_decl,
60-
body: blk, _sp: span, 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: 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
}

trunk/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>(_fk: visit::fn_kind, _decl: fn_decl, _body: blk,
1012-
_sp: span, _id: node_id,
1011+
fn do_nothing<T>(_decl: fn_decl, _ts: [ty_param], _body: blk,
1012+
_sp: span, _i: fn_ident, _id: node_id,
10131013
_t: T, _v: visit::vt<T>) {
10141014
}
10151015

trunk/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);

0 commit comments

Comments
 (0)