Skip to content

Commit 7763fcf

Browse files
committed
---
yaml --- r: 6688 b: refs/heads/master c: c28ada0 h: refs/heads/master v: v3
1 parent aa69266 commit 7763fcf

File tree

15 files changed

+67
-68
lines changed

15 files changed

+67
-68
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: 941101a9cdcd45e674e8ef57201a99a9d454e89f
2+
refs/heads/master: c28ada0368de78034e0930e01406f5e03a70d610

trunk/Makefile.in

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,10 @@ $(foreach host,$(CFG_TARGET_TRIPLES), \
372372
$(eval $(foreach stage,1 2 3, \
373373
$(eval $(call DEF_RUSTC_STAGE_TARGET,$(host),$(stage))))))
374374

375+
rustc-stage1: rustc-stage1-H-$(CFG_HOST_TRIPLE)
376+
rustc-stage2: rustc-stage2-H-$(CFG_HOST_TRIPLE)
377+
rustc-stage3: rustc-stage3-H-$(CFG_HOST_TRIPLE)
378+
375379
define DEF_RUSTC_TARGET
376380
# $(1) == architecture
377381

trunk/src/comp/middle/fn_usage.rs

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ export check_crate_fn_usage;
77

88
type fn_usage_ctx = {
99
tcx: ty::ctxt,
10-
unsafe_fn_legal: bool,
11-
generic_bare_fn_legal: bool
10+
unsafe_fn_legal: bool
1211
};
1312

1413
fn fn_usage_expr(expr: @ast::expr,
@@ -29,44 +28,28 @@ fn fn_usage_expr(expr: @ast::expr,
2928
_ {}
3029
}
3130
}
32-
if !ctx.generic_bare_fn_legal
33-
&& ty::expr_has_ty_params(ctx.tcx, expr) {
34-
alt ty::struct(ctx.tcx, ty::expr_ty(ctx.tcx, expr)) {
35-
ty::ty_fn(ast::proto_bare., _, _, _, _) {
36-
ctx.tcx.sess.span_fatal(
37-
expr.span,
38-
"generic bare functions can only be called or bound");
39-
}
40-
_ { }
41-
}
42-
}
4331
}
4432

4533
ast::expr_call(f, args, _) {
46-
let f_ctx = {unsafe_fn_legal: true,
47-
generic_bare_fn_legal: true with ctx};
34+
let f_ctx = {unsafe_fn_legal: true with ctx};
4835
v.visit_expr(f, f_ctx, v);
4936

50-
let args_ctx = {unsafe_fn_legal: false,
51-
generic_bare_fn_legal: false with ctx};
37+
let args_ctx = {unsafe_fn_legal: false with ctx};
5238
visit::visit_exprs(args, args_ctx, v);
5339
}
5440

5541
ast::expr_bind(f, args) {
56-
let f_ctx = {unsafe_fn_legal: false,
57-
generic_bare_fn_legal: true with ctx};
42+
let f_ctx = {unsafe_fn_legal: false with ctx};
5843
v.visit_expr(f, f_ctx, v);
5944

60-
let args_ctx = {unsafe_fn_legal: false,
61-
generic_bare_fn_legal: false with ctx};
45+
let args_ctx = {unsafe_fn_legal: false with ctx};
6246
for arg in args {
6347
visit::visit_expr_opt(arg, args_ctx, v);
6448
}
6549
}
6650

6751
_ {
68-
let subctx = {unsafe_fn_legal: false,
69-
generic_bare_fn_legal: false with ctx};
52+
let subctx = {unsafe_fn_legal: false with ctx};
7053
visit::visit_expr(expr, subctx, v);
7154
}
7255
}
@@ -79,8 +62,7 @@ fn check_crate_fn_usage(tcx: ty::ctxt, crate: @ast::crate) {
7962
with *visit::default_visitor()});
8063
let ctx = {
8164
tcx: tcx,
82-
unsafe_fn_legal: false,
83-
generic_bare_fn_legal: false
65+
unsafe_fn_legal: false
8466
};
8567
visit::visit_crate(*crate, ctx, visit);
8668
}

trunk/src/comp/middle/freevars.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ fn collect_freevars(def_map: resolve::def_map, walker: fn@(visit::vt<int>)) ->
3333
let walk_expr =
3434
lambda (expr: @ast::expr, &&depth: int, v: visit::vt<int>) {
3535
alt expr.node {
36-
ast::expr_fn(f) {
36+
ast::expr_fn(f, captures) {
3737
if f.proto == ast::proto_block ||
3838
f.proto == ast::proto_shared(ast::sugar_normal) ||
3939
f.proto == ast::proto_shared(ast::sugar_sexy) {

trunk/src/comp/middle/kind.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,14 @@ fn check_expr(e: @expr, cx: ctx, v: visit::vt<ctx>) {
107107
none. {}
108108
}
109109
}
110-
expr_fn({proto: proto_shared(_), _}) {
110+
expr_fn({proto: proto_send, _}, captures) {
111+
for free in *freevars::get_freevars(cx.tcx, e.id) {
112+
let id = ast_util::def_id_of_def(free).node;
113+
let ty = ty::node_id_to_type(cx.tcx, id);
114+
check_copy(cx, ty, e.span);
115+
}
116+
}
117+
expr_fn({proto: proto_shared(_), _}, captures) {
111118
for free in *freevars::get_freevars(cx.tcx, e.id) {
112119
let id = ast_util::def_id_of_def(free).node;
113120
let ty = ty::node_id_to_type(cx.tcx, id);

trunk/src/comp/middle/last_use.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,8 @@ fn visit_expr(ex: @expr, cx: ctx, v: visit::vt<ctx>) {
134134
let arg_ts = ty::ty_fn_args(cx.tcx, ty::expr_ty(cx.tcx, f));
135135
for arg in args {
136136
alt arg.node {
137-
expr_fn(_) { fns += [arg]; }
137+
//NDM--register captured as uses
138+
expr_fn(_, captured) { fns += [arg]; }
138139
_ {
139140
alt arg_ts[i].mode {
140141
by_mut_ref. { clear_if_path(cx, arg, v, false); }

trunk/src/comp/middle/trans.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4047,7 +4047,8 @@ fn trans_expr(bcx: @block_ctxt, e: @ast::expr, dest: dest) -> @block_ctxt {
40474047
assert op != ast::deref; // lvals are handled above
40484048
ret trans_unary(bcx, op, x, e.id, dest);
40494049
}
4050-
ast::expr_fn(f) { ret trans_expr_fn(bcx, f, e.span, e.id, dest); }
4050+
// NDM captures
4051+
ast::expr_fn(f, cap) { ret trans_expr_fn(bcx, f, e.span, e.id, dest); }
40514052
ast::expr_bind(f, args) { ret trans_bind(bcx, f, args, e.id, dest); }
40524053
ast::expr_copy(a) {
40534054
if !ty::expr_is_lval(tcx, a) { ret trans_expr(bcx, a, dest); }

trunk/src/comp/middle/tstate/pre_post_conditions.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ fn find_pre_post_expr(fcx: fn_ctxt, e: @expr) {
341341
find_pre_post_expr(fcx, arg);
342342
copy_pre_post(fcx.ccx, e.id, arg);
343343
}
344-
expr_fn(f) {
344+
expr_fn(f, _) { // NDM captures
345345
let rslt = expr_pp(fcx.ccx, e);
346346
clear_pp(rslt);
347347
for def in *freevars::get_freevars(fcx.ccx.tcx, e.id) {

trunk/src/comp/middle/tstate/states.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ fn find_pre_post_state_expr(fcx: fn_ctxt, pres: prestate, e: @expr) -> bool {
358358
}
359359
expr_mac(_) { fcx.ccx.tcx.sess.bug("unexpanded macro"); }
360360
expr_lit(l) { ret pure_exp(fcx.ccx, e.id, pres); }
361-
expr_fn(f) { ret pure_exp(fcx.ccx, e.id, pres); }
361+
expr_fn(f, _) { ret pure_exp(fcx.ccx, e.id, pres); } // NDM Captures
362362
expr_block(b) {
363363
ret find_pre_post_state_block(fcx, pres, b) |
364364
set_prestate_ann(fcx.ccx, e.id, pres) |

trunk/src/comp/middle/typeck.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1001,7 +1001,7 @@ mod writeback {
10011001
if !wbcx.success { ret; }
10021002
resolve_type_vars_for_node(wbcx, e.span, e.id);
10031003
alt e.node {
1004-
ast::expr_fn(f) {
1004+
ast::expr_fn(f, _) { // NDM captures?
10051005
for input in f.decl.inputs {
10061006
resolve_type_vars_for_node(wbcx, e.span, input.id);
10071007
}
@@ -1526,7 +1526,7 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, expr: @ast::expr, unify: unifier,
15261526
some(a) {
15271527
let is_block =
15281528
alt a.node {
1529-
ast::expr_fn(_) { true }
1529+
ast::expr_fn(_, _) { true }
15301530
_ { false }
15311531
};
15321532
if is_block == check_blocks {
@@ -1902,7 +1902,7 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, expr: @ast::expr, unify: unifier,
19021902
if !arm_non_bot { result_ty = ty::mk_bot(tcx); }
19031903
write::ty_only_fixup(fcx, id, result_ty);
19041904
}
1905-
ast::expr_fn(f) {
1905+
ast::expr_fn(f, captures) { // NDM captures
19061906
let cx = @{tcx: tcx};
19071907
let fty = ty_of_fn_decl(cx.tcx, m_check_tyvar(fcx), f.decl,
19081908
f.proto, [], none).ty;

trunk/src/comp/syntax/ast.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,8 @@ tag expr_ {
237237
// At the moment, one can only capture local variables.
238238
type capture_ = {
239239
is_send: bool,
240-
copies: [ident],
241-
moves: [ident]
240+
copies: [spanned<ident>],
241+
moves: [spanned<ident>]
242242
};
243243

244244
type capture = spanned<capture_>;

trunk/src/comp/syntax/fold.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,8 @@ fn noop_fold_expr(e: expr_, fld: ast_fold) -> expr_ {
381381
expr_alt(expr, arms) {
382382
expr_alt(fld.fold_expr(expr), vec::map(fld.fold_arm, arms))
383383
}
384-
expr_fn(f) { expr_fn(fld.fold_fn(f)) }
384+
// NDM fold_captures
385+
expr_fn(f, captures) { expr_fn(fld.fold_fn(f), captures) }
385386
expr_block(blk) { expr_block(fld.fold_block(blk)) }
386387
expr_move(el, er) {
387388
expr_move(fld.fold_expr(el), fld.fold_expr(er))

trunk/src/comp/syntax/parse/parser.rs

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ tag fn_kw {
1818
fn_kw_fn;
1919
fn_kw_lambda;
2020
fn_kw_block;
21-
};
21+
}
2222

2323
type parse_sess = @{cm: codemap::codemap, mutable next_id: node_id};
2424

@@ -1292,7 +1292,7 @@ fn parse_if_expr(p: parser) -> @ast::expr {
12921292
// CC := [send; copy ID*; move ID*]
12931293
//
12941294
// where any part is optional and trailing ; is permitted.
1295-
fn parse_capture_clause(p: parser) -> (bool, @ast::capture) {
1295+
fn parse_capture_clause(p: parser) -> @ast::capture {
12961296
fn expect_opt_trailing_semi(p: parser) {
12971297
if !eat(p, token::SEMI) {
12981298
if p.peek() != token::RBRACE {
@@ -1301,12 +1301,13 @@ fn parse_capture_clause(p: parser) -> (bool, @ast::capture) {
13011301
}
13021302
}
13031303

1304-
fn eat_ident_list(p: parser) -> [ast::ident] {
1304+
fn eat_ident_list(p: parser) -> [ast::spanned<ast::ident>] {
13051305
let res = [];
13061306
while true {
13071307
alt p.peek() {
13081308
token::IDENT(_, _) {
1309-
res += parse_ident(p);
1309+
let i = spanned(p.get_lo_pos(), p.get_hi_pos(), parse_ident(p));
1310+
res += [i];
13101311
if !eat(p, token::COMMA) {
13111312
ret res;
13121313
}
@@ -1321,52 +1322,53 @@ fn parse_capture_clause(p: parser) -> (bool, @ast::capture) {
13211322
let copies = [];
13221323
let moves = [];
13231324

1324-
if p.peek() != token::LBRACE {
1325-
ret (is_send, captures);
1326-
}
1327-
1328-
expect(p, token::LBRACE);
1329-
while p.peek() != token::RBRACE {
1330-
if eat_word(p, "send") {
1331-
is_send = true;
1332-
expect_opt_trailing_semi(p);
1333-
} else if eat_word(p, "copy") {
1334-
copies += eat_ident_list();
1335-
expect_opt_trailing_semi(p);
1336-
} else if eat_word(p, "move") {
1337-
moves += eat_ident_list();
1338-
expect_opt_trailing_semi(p);
1339-
} else {
1340-
let s: str = "expecting send, copy, or move clause";
1341-
p.fatal(s);
1325+
let lo = p.get_lo_pos();
1326+
if eat(p, token::LBRACE) {
1327+
while !eat(p, token::RBRACE) {
1328+
if eat_word(p, "send") {
1329+
is_send = true;
1330+
expect_opt_trailing_semi(p);
1331+
} else if eat_word(p, "copy") {
1332+
copies += eat_ident_list(p);
1333+
expect_opt_trailing_semi(p);
1334+
} else if eat_word(p, "move") {
1335+
moves += eat_ident_list(p);
1336+
expect_opt_trailing_semi(p);
1337+
} else {
1338+
let s: str = "expecting send, copy, or move clause";
1339+
p.fatal(s);
1340+
}
13421341
}
13431342
}
1343+
let hi = p.get_last_hi_pos();
13441344

1345-
ret @{is_send: is_send, copies: copies, moves: moves};
1345+
ret @spanned(lo, hi, {is_send: is_send, copies: copies, moves: moves});
13461346
}
13471347

13481348
fn parse_fn_expr(p: parser, kw: fn_kw) -> @ast::expr {
13491349
let lo = p.get_last_lo_pos();
1350-
let cap = parse_capture_clause(p);
1350+
let captures = parse_capture_clause(p);
13511351
let decl = parse_fn_decl(p, ast::impure_fn, ast::il_normal);
13521352
let body = parse_block(p);
1353-
let proto = alt (kw, cap.is_send) {
1353+
let proto = alt (kw, captures.node.is_send) {
13541354
(fn_kw_fn., true) { ast::proto_bare }
13551355
(fn_kw_lambda., true) { ast::proto_send }
13561356
(fn_kw_lambda., false) { ast::proto_shared(ast::sugar_sexy) }
13571357
(fn_kw_block., false) { ast::proto_block }
13581358
(_, true) { p.fatal("only lambda can be declared sendable"); }
1359-
}
1359+
};
13601360
let _fn = {decl: decl, proto: proto, body: body};
1361-
ret mk_expr(p, lo, body.span.hi, ast::expr_fn(_fn, cap));
1361+
ret mk_expr(p, lo, body.span.hi, ast::expr_fn(_fn, captures));
13621362
}
13631363

13641364
fn parse_fn_block_expr(p: parser) -> @ast::expr {
13651365
let lo = p.get_last_lo_pos();
13661366
let decl = parse_fn_block_decl(p);
1367+
let mid = p.get_last_hi_pos();
13671368
let body = parse_block_tail(p, lo, ast::default_blk);
13681369
let _fn = {decl: decl, proto: ast::proto_block, body: body};
1369-
ret mk_expr(p, lo, body.span.hi, ast::expr_fn(_fn));
1370+
let captures = @spanned(lo, mid, {is_send: false, copies: [], moves: []});
1371+
ret mk_expr(p, lo, body.span.hi, ast::expr_fn(_fn, captures));
13701372
}
13711373

13721374
fn parse_else_expr(p: parser) -> @ast::expr {

trunk/src/comp/syntax/print/pprust.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -818,7 +818,7 @@ fn print_expr(s: ps, &&expr: @ast::expr) {
818818
}
819819
bclose_(s, expr.span, alt_indent_unit);
820820
}
821-
ast::expr_fn(f) {
821+
ast::expr_fn(f, captures) { // NDM captures
822822

823823
// If the return type is the magic ty_infer, then we need to
824824
// pretty print as a lambda-block

trunk/src/comp/syntax/visit.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,8 @@ fn visit_expr<E>(ex: @expr, e: E, v: vt<E>) {
273273
v.visit_expr(x, e, v);
274274
for a: arm in arms { v.visit_arm(a, e, v); }
275275
}
276-
expr_fn(f) { v.visit_fn(f, [], ex.span, none, ex.id, e, v); }
276+
// NDM add visit routine?
277+
expr_fn(f, captures) { v.visit_fn(f, [], ex.span, none, ex.id, e, v); }
277278
expr_block(b) { v.visit_block(b, e, v); }
278279
expr_assign(a, b) { v.visit_expr(b, e, v); v.visit_expr(a, e, v); }
279280
expr_copy(a) { v.visit_expr(a, e, v); }

0 commit comments

Comments
 (0)