Skip to content

Commit 8387896

Browse files
committed
Remove proto_sugar and 'lambda' as keyword, commit to fn@.
1 parent f6ecbe8 commit 8387896

30 files changed

+72
-79
lines changed

doc/keywords.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ do
77
else export
88
f32 f64 fail false float fn for
99
i16 i32 i64 i8 if import in int
10-
lambda let log
10+
let log
1111
mod mutable
1212
native note
1313
obj

src/comp/metadata/tydecode.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ fn parse_ty(st: @pstate, conv: conv_did) -> ty::t {
234234
ret parse_ty_rust_fn(st, conv, ast::proto_send);
235235
}
236236
'F' {
237-
ret parse_ty_rust_fn(st, conv, ast::proto_shared(ast::sugar_normal));
237+
ret parse_ty_rust_fn(st, conv, ast::proto_shared);
238238
}
239239
'f' {
240240
ret parse_ty_rust_fn(st, conv, ast::proto_bare);

src/comp/metadata/tyencode.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ fn enc_sty(w: io::writer, cx: @ctxt, st: ty::sty) {
203203
fn enc_proto(w: io::writer, proto: proto) {
204204
alt proto {
205205
proto_send. { w.write_char('s'); }
206-
proto_shared(_) { w.write_char('F'); }
206+
proto_shared. { w.write_char('F'); }
207207
proto_block. { w.write_char('B'); }
208208
proto_bare. { w.write_char('f'); }
209209
}

src/comp/middle/capture.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ fn check_capture_clause(tcx: ty::ctxt,
3434
let freevars = freevars::get_freevars(tcx, fn_expr_id);
3535
let seen_defs = map::new_int_hash();
3636

37-
let check_capture_item = lambda(&&cap_item: @ast::capture_item) {
37+
let check_capture_item = fn@(&&cap_item: @ast::capture_item) {
3838
let cap_def = tcx.def_map.get(cap_item.id);
3939
if !vec::any(*freevars, {|fv| fv.def == cap_def}) {
4040
tcx.sess.span_warn(
@@ -52,7 +52,7 @@ fn check_capture_clause(tcx: ty::ctxt,
5252
}
5353
};
5454

55-
let check_not_upvar = lambda(&&cap_item: @ast::capture_item) {
55+
let check_not_upvar = fn@(&&cap_item: @ast::capture_item) {
5656
alt tcx.def_map.get(cap_item.id) {
5757
ast::def_upvar(_, _, _) {
5858
tcx.sess.span_err(
@@ -64,7 +64,7 @@ fn check_capture_clause(tcx: ty::ctxt,
6464
}
6565
};
6666

67-
let check_block_captures = lambda(v: [@ast::capture_item]) {
67+
let check_block_captures = fn@(v: [@ast::capture_item]) {
6868
if check vec::is_not_empty(v) {
6969
let cap_item0 = vec::head(v);
7070
tcx.sess.span_err(
@@ -78,7 +78,7 @@ fn check_capture_clause(tcx: ty::ctxt,
7878
check_block_captures(cap_clause.copies);
7979
check_block_captures(cap_clause.moves);
8080
}
81-
ast::proto_bare. | ast::proto_shared(_) | ast::proto_send. {
81+
ast::proto_bare. | ast::proto_shared. | ast::proto_send. {
8282
vec::iter(cap_clause.copies, check_capture_item);
8383
vec::iter(cap_clause.moves, check_capture_item);
8484
vec::iter(cap_clause.moves, check_not_upvar);
@@ -113,7 +113,7 @@ fn compute_capture_vars(tcx: ty::ctxt,
113113

114114
let implicit_mode = alt fn_proto {
115115
ast::proto_block. { cap_ref }
116-
ast::proto_bare. | ast::proto_shared(_) | ast::proto_send. { cap_copy }
116+
ast::proto_bare. | ast::proto_shared. | ast::proto_send. { cap_copy }
117117
};
118118

119119
vec::iter(*freevars) { |fvar|

src/comp/middle/freevars.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ fn collect_freevars(def_map: resolve::def_map, blk: ast::blk)
3737
fn ignore_item(_i: @ast::item, &&_depth: int, _v: visit::vt<int>) { }
3838

3939
let walk_expr =
40-
lambda (expr: @ast::expr, &&depth: int, v: visit::vt<int>) {
40+
fn@ (expr: @ast::expr, &&depth: int, v: visit::vt<int>) {
4141
alt expr.node {
4242
ast::expr_fn(proto, decl, _, captures) {
4343
if proto != ast::proto_bare {
@@ -89,7 +89,7 @@ fn annotate_freevars(def_map: resolve::def_map, crate: @ast::crate) ->
8989
freevar_map {
9090
let freevars = new_int_hash();
9191

92-
let walk_fn = lambda (_fk: visit::fn_kind, _decl: ast::fn_decl,
92+
let walk_fn = fn@ (_fk: visit::fn_kind, _decl: ast::fn_decl,
9393
blk: ast::blk, _sp: span, nid: ast::node_id) {
9494
let vars = collect_freevars(def_map, blk);
9595
freevars.insert(nid, vars);

src/comp/middle/kind.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ fn with_appropriate_checker(cx: ctx, id: node_id,
6161
let fty = ty::node_id_to_monotype(cx.tcx, id);
6262
alt ty::ty_fn_proto(cx.tcx, fty) {
6363
proto_send. { b(check_send); }
64-
proto_shared(_) { b(check_copy); }
64+
proto_shared. { b(check_copy); }
6565
proto_block. { /* no check needed */ }
6666
proto_bare. { b(check_none); }
6767
}
@@ -106,7 +106,7 @@ fn check_fn_cap_clause(cx: ctx,
106106
});
107107
//log("freevar_ids", freevar_ids);
108108
with_appropriate_checker(cx, id) { |checker|
109-
let check_var = lambda(&&cap_item: @capture_item) {
109+
let check_var = fn@(&&cap_item: @capture_item) {
110110
let cap_def = cx.tcx.def_map.get(cap_item.id);
111111
let cap_def_id = ast_util::def_id_of_def(cap_def).node;
112112
if !vec::member(cap_def_id, freevar_ids) {

src/comp/middle/trans_closure.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ fn allocate_cbox(bcx: @block_ctxt,
208208

209209
let ccx = bcx_ccx(bcx);
210210

211-
let alloc_in_heap = lambda(bcx: @block_ctxt,
211+
let alloc_in_heap = fn@(bcx: @block_ctxt,
212212
xchgheap: bool,
213213
&temp_cleanups: [ValueRef])
214214
-> (@block_ctxt, ValueRef) {
@@ -520,7 +520,7 @@ fn trans_expr_fn(bcx: @block_ctxt,
520520
let llfn = decl_internal_cdecl_fn(ccx.llmod, s, llfnty);
521521
register_fn(ccx, sp, sub_cx.path, "anon fn", [], id);
522522

523-
let trans_closure_env = lambda(ck: ty::closure_kind) -> ValueRef {
523+
let trans_closure_env = fn@(ck: ty::closure_kind) -> ValueRef {
524524
let cap_vars = capture::compute_capture_vars(
525525
ccx.tcx, id, proto, cap_clause);
526526
let {llbox, cboxptr_ty, bcx} = build_closure(bcx, cap_vars, ck);
@@ -532,7 +532,7 @@ fn trans_expr_fn(bcx: @block_ctxt,
532532

533533
let closure = alt proto {
534534
ast::proto_block. { trans_closure_env(ty::closure_block) }
535-
ast::proto_shared(_) { trans_closure_env(ty::closure_shared) }
535+
ast::proto_shared. { trans_closure_env(ty::closure_shared) }
536536
ast::proto_send. { trans_closure_env(ty::closure_send) }
537537
ast::proto_bare. {
538538
let closure = C_null(T_opaque_cbox_ptr(ccx));
@@ -660,7 +660,7 @@ fn make_fn_glue(
660660
let bcx = cx;
661661
let tcx = bcx_tcx(cx);
662662

663-
let fn_env = lambda(ck: ty::closure_kind) -> @block_ctxt {
663+
let fn_env = fn@(ck: ty::closure_kind) -> @block_ctxt {
664664
let box_cell_v = GEPi(cx, v, [0, abi::fn_field_box]);
665665
let box_ptr_v = Load(cx, box_cell_v);
666666
make_null_test(cx, box_ptr_v) {|bcx|
@@ -675,7 +675,7 @@ fn make_fn_glue(
675675
ty::ty_fn({proto: ast::proto_send., _}) {
676676
fn_env(ty::closure_send)
677677
}
678-
ty::ty_fn({proto: ast::proto_shared(_), _}) {
678+
ty::ty_fn({proto: ast::proto_shared., _}) {
679679
fn_env(ty::closure_shared)
680680
}
681681
_ { fail "make_fn_glue invoked on non-function type" }

src/comp/middle/tstate/pre_post_conditions.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ fn find_pre_post_expr(fcx: fn_ctxt, e: @expr) {
348348
expr_fn(_, _, _, cap_clause) {
349349
find_pre_post_expr_fn_upvars(fcx, e);
350350

351-
let use_cap_item = lambda(&&cap_item: @capture_item) {
351+
let use_cap_item = fn@(&&cap_item: @capture_item) {
352352
let d = local_node_id_to_local_def_id(fcx, cap_item.id);
353353
option::may(d, { |id| use_var(fcx, id) });
354354
};

src/comp/middle/ty.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -1020,7 +1020,7 @@ pure fn kind_can_be_sent(k: kind) -> bool {
10201020
fn proto_kind(p: proto) -> kind {
10211021
alt p {
10221022
ast::proto_block. { kind_noncopyable }
1023-
ast::proto_shared(_) { kind_copyable }
1023+
ast::proto_shared. { kind_copyable }
10241024
ast::proto_send. { kind_sendable }
10251025
ast::proto_bare. { kind_sendable }
10261026
}
@@ -1563,7 +1563,7 @@ fn ty_fn_proto(cx: ctxt, fty: t) -> ast::proto {
15631563
ty::ty_fn(f) { ret f.proto; }
15641564
ty::ty_native_fn(_, _) {
15651565
// FIXME: This should probably be proto_bare
1566-
ret ast::proto_shared(ast::sugar_normal);
1566+
ret ast::proto_shared;
15671567
}
15681568
_ { cx.sess.bug("ty_fn_proto() called on non-fn type"); }
15691569
}
@@ -1947,8 +1947,7 @@ mod unify {
19471947
(_, ast::proto_block.) { true }
19481948
(ast::proto_bare., _) { true }
19491949

1950-
// Equal prototypes (modulo sugar) are always subprotos:
1951-
(ast::proto_shared(_), ast::proto_shared(_)) { true }
1950+
// Equal prototypes are always subprotos:
19521951
(_, _) { p_sub == p_sup }
19531952
};
19541953
}

src/comp/middle/typeck.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,7 @@ fn ty_of_obj_ctor(tcx: ty::ctxt, mode: mode, id: ast::ident, ob: ast::_obj,
553553
let t_field = ast_ty_to_ty(tcx, mode, f.ty);
554554
t_inputs += [{mode: ast::by_copy, ty: t_field}];
555555
}
556-
let t_fn = ty::mk_fn(tcx, {proto: ast::proto_shared(ast::sugar_normal),
556+
let t_fn = ty::mk_fn(tcx, {proto: ast::proto_shared,
557557
inputs: t_inputs, output: t_obj.ty,
558558
ret_style: ast::return_val, constraints: []});
559559
let tpt = {bounds: ty_param_bounds(tcx, mode, ty_params), ty: t_fn};
@@ -697,7 +697,7 @@ mod collect {
697697
}
698698
// FIXME: this will be different for constrained types
699699
ty::mk_fn(cx.tcx,
700-
{proto: ast::proto_shared(ast::sugar_normal),
700+
{proto: ast::proto_shared,
701701
inputs: args, output: tag_ty,
702702
ret_style: ast::return_val, constraints: []})
703703
};
@@ -799,13 +799,13 @@ mod collect {
799799
let t_res = ty::mk_res(cx.tcx, local_def(it.id), t_arg.ty,
800800
params);
801801
let t_ctor = ty::mk_fn(cx.tcx, {
802-
proto: ast::proto_shared(ast::sugar_normal),
802+
proto: ast::proto_shared,
803803
inputs: [{mode: ast::by_copy with t_arg}],
804804
output: t_res,
805805
ret_style: ast::return_val, constraints: []
806806
});
807807
let t_dtor = ty::mk_fn(cx.tcx, {
808-
proto: ast::proto_shared(ast::sugar_normal),
808+
proto: ast::proto_shared,
809809
inputs: [t_arg], output: ty::mk_nil(cx.tcx),
810810
ret_style: ast::return_val, constraints: []
811811
});
@@ -1172,9 +1172,9 @@ fn gather_locals(ccx: @crate_ctxt,
11721172
};
11731173
let tcx = ccx.tcx;
11741174

1175-
let next_var_id = lambda () -> int { let rv = *nvi; *nvi += 1; ret rv; };
1175+
let next_var_id = fn@ () -> int { let rv = *nvi; *nvi += 1; ret rv; };
11761176
let assign =
1177-
lambda (nid: ast::node_id, ty_opt: option::t<ty::t>) {
1177+
fn@ (nid: ast::node_id, ty_opt: option::t<ty::t>) {
11781178
let var_id = next_var_id();
11791179
locals.insert(nid, var_id);
11801180
alt ty_opt {
@@ -1206,15 +1206,15 @@ fn gather_locals(ccx: @crate_ctxt,
12061206

12071207
// Add explicitly-declared locals.
12081208
let visit_local =
1209-
lambda (local: @ast::local, &&e: (), v: visit::vt<()>) {
1209+
fn@ (local: @ast::local, &&e: (), v: visit::vt<()>) {
12101210
let local_ty = ast_ty_to_ty_crate_infer(ccx, local.node.ty);
12111211
assign(local.node.id, local_ty);
12121212
visit::visit_local(local, e, v);
12131213
};
12141214

12151215
// Add pattern bindings.
12161216
let visit_pat =
1217-
lambda (p: @ast::pat, &&e: (), v: visit::vt<()>) {
1217+
fn@ (p: @ast::pat, &&e: (), v: visit::vt<()>) {
12181218
alt p.node {
12191219
ast::pat_bind(_, _) { assign(p.id, none); }
12201220
_ {/* no-op */ }
@@ -1726,7 +1726,7 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, expr: @ast::expr, unify: unifier,
17261726
// of arguments when we typecheck the functions. This isn't really the
17271727
// right way to do this.
17281728
let check_args =
1729-
lambda (check_blocks: bool) -> bool {
1729+
fn@ (check_blocks: bool) -> bool {
17301730
let i = 0u;
17311731
let bot = false;
17321732
for a_opt: option::t<@ast::expr> in args {
@@ -2179,7 +2179,7 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, expr: @ast::expr, unify: unifier,
21792179
fn lower_bound_proto(proto: ast::proto) -> ast::proto {
21802180
// FIXME: This is right for bare fns, possibly not others
21812181
alt proto {
2182-
ast::proto_bare. { ast::proto_shared(ast::sugar_normal) }
2182+
ast::proto_bare. { ast::proto_shared }
21832183
_ { proto }
21842184
}
21852185
}
@@ -2632,7 +2632,7 @@ fn check_const(ccx: @crate_ctxt, _sp: span, e: @ast::expr, id: ast::node_id) {
26322632
let fcx: @fn_ctxt =
26332633
@{ret_ty: rty,
26342634
purity: ast::pure_fn,
2635-
proto: ast::proto_shared(ast::sugar_normal),
2635+
proto: ast::proto_shared,
26362636
var_bindings: ty::unify::mk_var_bindings(),
26372637
locals: new_int_hash::<int>(),
26382638
next_var_id: @mutable 0,

src/comp/syntax/ast.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -110,15 +110,10 @@ tag pat_ {
110110

111111
tag mutability { mut; imm; maybe_mut; }
112112

113-
tag proto_sugar {
114-
sugar_normal;
115-
sugar_sexy;
116-
}
117-
118113
tag proto {
119114
proto_bare;
120115
proto_send;
121-
proto_shared(proto_sugar);
116+
proto_shared;
122117
proto_block;
123118
}
124119

src/comp/syntax/parse/parser.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ fn bad_expr_word_table() -> hashmap<str, ()> {
168168
let words = new_str_hash();
169169
for word in ["mod", "if", "else", "while", "do", "alt", "for", "break",
170170
"cont", "ret", "be", "fail", "type", "resource", "check",
171-
"assert", "claim", "native", "fn", "lambda", "pure",
171+
"assert", "claim", "native", "fn", "fn@", "pure",
172172
"unsafe", "block", "import", "export", "let", "const",
173173
"log", "tag", "obj", "copy", "sendfn", "impl", "iface"] {
174174
words.insert(word, ());
@@ -514,8 +514,8 @@ fn parse_ty(p: parser, colons_before_params: bool) -> @ast::ty {
514514
t = parse_ty_fn(proto, p);
515515
} else if eat_word(p, "block") {
516516
t = parse_ty_fn(ast::proto_block, p);
517-
} else if eat_word(p, "lambda") {
518-
t = parse_ty_fn(ast::proto_shared(ast::sugar_sexy), p);
517+
} else if eat_word(p, "fn@") {
518+
t = parse_ty_fn(ast::proto_shared, p);
519519
} else if eat_word(p, "sendfn") {
520520
t = parse_ty_fn(ast::proto_send, p);
521521
} else if eat_word(p, "obj") {
@@ -821,8 +821,8 @@ fn parse_bottom_expr(p: parser) -> pexpr {
821821
ret pexpr(parse_fn_expr(p, proto));
822822
} else if eat_word(p, "block") {
823823
ret pexpr(parse_fn_expr(p, ast::proto_block));
824-
} else if eat_word(p, "lambda") {
825-
ret pexpr(parse_fn_expr(p, ast::proto_shared(ast::sugar_sexy)));
824+
} else if eat_word(p, "fn@") {
825+
ret pexpr(parse_fn_expr(p, ast::proto_shared));
826826
} else if eat_word(p, "sendfn") {
827827
ret pexpr(parse_fn_expr(p, ast::proto_send));
828828
} else if eat_word(p, "unchecked") {
@@ -2117,7 +2117,7 @@ fn parse_item_tag(p: parser, attrs: [ast::attribute]) -> @ast::item {
21172117
fn parse_fn_ty_proto(p: parser) -> ast::proto {
21182118
if p.peek() == token::AT {
21192119
p.bump();
2120-
ast::proto_shared(ast::sugar_normal)
2120+
ast::proto_shared
21212121
} else {
21222122
ast::proto_bare
21232123
}

src/comp/syntax/print/pprust.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1685,8 +1685,7 @@ fn proto_to_str(p: ast::proto) -> str {
16851685
ast::proto_bare. { "fn" }
16861686
ast::proto_block. { "block" }
16871687
ast::proto_send. { "sendfn" }
1688-
ast::proto_shared(ast::sugar_normal.) { "fn@" }
1689-
ast::proto_shared(ast::sugar_sexy.) { "lambda" }
1688+
ast::proto_shared. { "fn@" }
16901689
};
16911690
}
16921691

src/comp/syntax/visit.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ tag fn_kind {
1919
fk_item_fn(ident, [ty_param]); //< an item declared with fn()
2020
fk_method(ident, [ty_param]);
2121
fk_res(ident, [ty_param]);
22-
fk_anon(proto); //< an anonymous function like lambda(...)
22+
fk_anon(proto); //< an anonymous function like fn@(...)
2323
fk_fn_block; //< a block {||...}
2424
}
2525

src/test/compile-fail/block-arg-used-as-lambda-with-illegal-cap.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
// error-pattern: copying a noncopyable value
22

3-
fn to_lambda1(f: lambda(uint) -> uint) -> lambda(uint) -> uint {
3+
fn to_lambda1(f: fn@(uint) -> uint) -> fn@(uint) -> uint {
44
ret f;
55
}
66

7-
fn to_lambda2(b: block(uint) -> uint) -> lambda(uint) -> uint {
7+
fn to_lambda2(b: block(uint) -> uint) -> fn@(uint) -> uint {
88
ret to_lambda1({|x| b(x)});
99
}
1010

src/test/compile-fail/cap-clause-illegal-cap.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
// error-pattern: copying a noncopyable value
22

3-
fn to_lambda2(b: block(uint) -> uint) -> lambda(uint) -> uint {
3+
fn to_lambda2(b: block(uint) -> uint) -> fn@(uint) -> uint {
44
// test case where copy clause specifies a value that is not used
5-
// in lambda body, but value is illegal to copy:
6-
ret lambda[copy b](u: uint) -> uint { 22u };
5+
// in fn@ body, but value is illegal to copy:
6+
ret fn@[copy b](u: uint) -> uint { 22u };
77
}
88

99
fn main() {
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// error-pattern:Unsatisfied precondition
22

33
fn main() {
4-
// Typestate should work even in a lambda. we should reject this program.
4+
// Typestate should work even in a fn@. we should reject this program.
55
let f = fn () -> int { let i: int; ret i; };
66
log(error, f());
77
}

0 commit comments

Comments
 (0)