提交 8387896d 编写于 作者: G Graydon Hoare

Remove proto_sugar and 'lambda' as keyword, commit to fn@.

上级 f6ecbe88
......@@ -7,7 +7,7 @@ do
else export
f32 f64 fail false float fn for
i16 i32 i64 i8 if import in int
lambda let log
let log
mod mutable
native note
obj
......
......@@ -234,7 +234,7 @@ fn parse_ty(st: @pstate, conv: conv_did) -> ty::t {
ret parse_ty_rust_fn(st, conv, ast::proto_send);
}
'F' {
ret parse_ty_rust_fn(st, conv, ast::proto_shared(ast::sugar_normal));
ret parse_ty_rust_fn(st, conv, ast::proto_shared);
}
'f' {
ret parse_ty_rust_fn(st, conv, ast::proto_bare);
......
......@@ -203,7 +203,7 @@ fn enc_sty(w: io::writer, cx: @ctxt, st: ty::sty) {
fn enc_proto(w: io::writer, proto: proto) {
alt proto {
proto_send. { w.write_char('s'); }
proto_shared(_) { w.write_char('F'); }
proto_shared. { w.write_char('F'); }
proto_block. { w.write_char('B'); }
proto_bare. { w.write_char('f'); }
}
......
......@@ -34,7 +34,7 @@ fn check_capture_clause(tcx: ty::ctxt,
let freevars = freevars::get_freevars(tcx, fn_expr_id);
let seen_defs = map::new_int_hash();
let check_capture_item = lambda(&&cap_item: @ast::capture_item) {
let check_capture_item = fn@(&&cap_item: @ast::capture_item) {
let cap_def = tcx.def_map.get(cap_item.id);
if !vec::any(*freevars, {|fv| fv.def == cap_def}) {
tcx.sess.span_warn(
......@@ -52,7 +52,7 @@ fn check_capture_clause(tcx: ty::ctxt,
}
};
let check_not_upvar = lambda(&&cap_item: @ast::capture_item) {
let check_not_upvar = fn@(&&cap_item: @ast::capture_item) {
alt tcx.def_map.get(cap_item.id) {
ast::def_upvar(_, _, _) {
tcx.sess.span_err(
......@@ -64,7 +64,7 @@ fn check_capture_clause(tcx: ty::ctxt,
}
};
let check_block_captures = lambda(v: [@ast::capture_item]) {
let check_block_captures = fn@(v: [@ast::capture_item]) {
if check vec::is_not_empty(v) {
let cap_item0 = vec::head(v);
tcx.sess.span_err(
......@@ -78,7 +78,7 @@ fn check_capture_clause(tcx: ty::ctxt,
check_block_captures(cap_clause.copies);
check_block_captures(cap_clause.moves);
}
ast::proto_bare. | ast::proto_shared(_) | ast::proto_send. {
ast::proto_bare. | ast::proto_shared. | ast::proto_send. {
vec::iter(cap_clause.copies, check_capture_item);
vec::iter(cap_clause.moves, check_capture_item);
vec::iter(cap_clause.moves, check_not_upvar);
......@@ -113,7 +113,7 @@ fn compute_capture_vars(tcx: ty::ctxt,
let implicit_mode = alt fn_proto {
ast::proto_block. { cap_ref }
ast::proto_bare. | ast::proto_shared(_) | ast::proto_send. { cap_copy }
ast::proto_bare. | ast::proto_shared. | ast::proto_send. { cap_copy }
};
vec::iter(*freevars) { |fvar|
......
......@@ -37,7 +37,7 @@ fn collect_freevars(def_map: resolve::def_map, blk: ast::blk)
fn ignore_item(_i: @ast::item, &&_depth: int, _v: visit::vt<int>) { }
let walk_expr =
lambda (expr: @ast::expr, &&depth: int, v: visit::vt<int>) {
fn@ (expr: @ast::expr, &&depth: int, v: visit::vt<int>) {
alt expr.node {
ast::expr_fn(proto, decl, _, captures) {
if proto != ast::proto_bare {
......@@ -89,7 +89,7 @@ fn annotate_freevars(def_map: resolve::def_map, crate: @ast::crate) ->
freevar_map {
let freevars = new_int_hash();
let walk_fn = lambda (_fk: visit::fn_kind, _decl: ast::fn_decl,
let walk_fn = fn@ (_fk: visit::fn_kind, _decl: ast::fn_decl,
blk: ast::blk, _sp: span, nid: ast::node_id) {
let vars = collect_freevars(def_map, blk);
freevars.insert(nid, vars);
......
......@@ -61,7 +61,7 @@ fn with_appropriate_checker(cx: ctx, id: node_id,
let fty = ty::node_id_to_monotype(cx.tcx, id);
alt ty::ty_fn_proto(cx.tcx, fty) {
proto_send. { b(check_send); }
proto_shared(_) { b(check_copy); }
proto_shared. { b(check_copy); }
proto_block. { /* no check needed */ }
proto_bare. { b(check_none); }
}
......@@ -106,7 +106,7 @@ fn check_fn_cap_clause(cx: ctx,
});
//log("freevar_ids", freevar_ids);
with_appropriate_checker(cx, id) { |checker|
let check_var = lambda(&&cap_item: @capture_item) {
let check_var = fn@(&&cap_item: @capture_item) {
let cap_def = cx.tcx.def_map.get(cap_item.id);
let cap_def_id = ast_util::def_id_of_def(cap_def).node;
if !vec::member(cap_def_id, freevar_ids) {
......
......@@ -208,7 +208,7 @@ fn allocate_cbox(bcx: @block_ctxt,
let ccx = bcx_ccx(bcx);
let alloc_in_heap = lambda(bcx: @block_ctxt,
let alloc_in_heap = fn@(bcx: @block_ctxt,
xchgheap: bool,
&temp_cleanups: [ValueRef])
-> (@block_ctxt, ValueRef) {
......@@ -520,7 +520,7 @@ fn trans_expr_fn(bcx: @block_ctxt,
let llfn = decl_internal_cdecl_fn(ccx.llmod, s, llfnty);
register_fn(ccx, sp, sub_cx.path, "anon fn", [], id);
let trans_closure_env = lambda(ck: ty::closure_kind) -> ValueRef {
let trans_closure_env = fn@(ck: ty::closure_kind) -> ValueRef {
let cap_vars = capture::compute_capture_vars(
ccx.tcx, id, proto, cap_clause);
let {llbox, cboxptr_ty, bcx} = build_closure(bcx, cap_vars, ck);
......@@ -532,7 +532,7 @@ fn trans_expr_fn(bcx: @block_ctxt,
let closure = alt proto {
ast::proto_block. { trans_closure_env(ty::closure_block) }
ast::proto_shared(_) { trans_closure_env(ty::closure_shared) }
ast::proto_shared. { trans_closure_env(ty::closure_shared) }
ast::proto_send. { trans_closure_env(ty::closure_send) }
ast::proto_bare. {
let closure = C_null(T_opaque_cbox_ptr(ccx));
......@@ -660,7 +660,7 @@ fn make_fn_glue(
let bcx = cx;
let tcx = bcx_tcx(cx);
let fn_env = lambda(ck: ty::closure_kind) -> @block_ctxt {
let fn_env = fn@(ck: ty::closure_kind) -> @block_ctxt {
let box_cell_v = GEPi(cx, v, [0, abi::fn_field_box]);
let box_ptr_v = Load(cx, box_cell_v);
make_null_test(cx, box_ptr_v) {|bcx|
......@@ -675,7 +675,7 @@ fn make_fn_glue(
ty::ty_fn({proto: ast::proto_send., _}) {
fn_env(ty::closure_send)
}
ty::ty_fn({proto: ast::proto_shared(_), _}) {
ty::ty_fn({proto: ast::proto_shared., _}) {
fn_env(ty::closure_shared)
}
_ { fail "make_fn_glue invoked on non-function type" }
......
......@@ -348,7 +348,7 @@ fn find_pre_post_expr(fcx: fn_ctxt, e: @expr) {
expr_fn(_, _, _, cap_clause) {
find_pre_post_expr_fn_upvars(fcx, e);
let use_cap_item = lambda(&&cap_item: @capture_item) {
let use_cap_item = fn@(&&cap_item: @capture_item) {
let d = local_node_id_to_local_def_id(fcx, cap_item.id);
option::may(d, { |id| use_var(fcx, id) });
};
......
......@@ -1020,7 +1020,7 @@ fn type_needs_drop(cx: ctxt, ty: t) -> bool {
fn proto_kind(p: proto) -> kind {
alt p {
ast::proto_block. { kind_noncopyable }
ast::proto_shared(_) { kind_copyable }
ast::proto_shared. { kind_copyable }
ast::proto_send. { kind_sendable }
ast::proto_bare. { kind_sendable }
}
......@@ -1563,7 +1563,7 @@ fn ty_fn_proto(cx: ctxt, fty: t) -> ast::proto {
ty::ty_fn(f) { ret f.proto; }
ty::ty_native_fn(_, _) {
// FIXME: This should probably be proto_bare
ret ast::proto_shared(ast::sugar_normal);
ret ast::proto_shared;
}
_ { cx.sess.bug("ty_fn_proto() called on non-fn type"); }
}
......@@ -1947,8 +1947,7 @@ fn sub_proto(p_sub: ast::proto, p_sup: ast::proto) -> bool {
(_, ast::proto_block.) { true }
(ast::proto_bare., _) { true }
// Equal prototypes (modulo sugar) are always subprotos:
(ast::proto_shared(_), ast::proto_shared(_)) { true }
// Equal prototypes are always subprotos:
(_, _) { p_sub == p_sup }
};
}
......
......@@ -553,7 +553,7 @@ fn ty_of_obj_ctor(tcx: ty::ctxt, mode: mode, id: ast::ident, ob: ast::_obj,
let t_field = ast_ty_to_ty(tcx, mode, f.ty);
t_inputs += [{mode: ast::by_copy, ty: t_field}];
}
let t_fn = ty::mk_fn(tcx, {proto: ast::proto_shared(ast::sugar_normal),
let t_fn = ty::mk_fn(tcx, {proto: ast::proto_shared,
inputs: t_inputs, output: t_obj.ty,
ret_style: ast::return_val, constraints: []});
let tpt = {bounds: ty_param_bounds(tcx, mode, ty_params), ty: t_fn};
......@@ -697,7 +697,7 @@ fn get_tag_variant_types(cx: @ctxt, tag_ty: ty::t,
}
// FIXME: this will be different for constrained types
ty::mk_fn(cx.tcx,
{proto: ast::proto_shared(ast::sugar_normal),
{proto: ast::proto_shared,
inputs: args, output: tag_ty,
ret_style: ast::return_val, constraints: []})
};
......@@ -799,13 +799,13 @@ fn convert(cx: @ctxt, it: @ast::item) {
let t_res = ty::mk_res(cx.tcx, local_def(it.id), t_arg.ty,
params);
let t_ctor = ty::mk_fn(cx.tcx, {
proto: ast::proto_shared(ast::sugar_normal),
proto: ast::proto_shared,
inputs: [{mode: ast::by_copy with t_arg}],
output: t_res,
ret_style: ast::return_val, constraints: []
});
let t_dtor = ty::mk_fn(cx.tcx, {
proto: ast::proto_shared(ast::sugar_normal),
proto: ast::proto_shared,
inputs: [t_arg], output: ty::mk_nil(cx.tcx),
ret_style: ast::return_val, constraints: []
});
......@@ -1172,9 +1172,9 @@ fn gather_locals(ccx: @crate_ctxt,
};
let tcx = ccx.tcx;
let next_var_id = lambda () -> int { let rv = *nvi; *nvi += 1; ret rv; };
let next_var_id = fn@ () -> int { let rv = *nvi; *nvi += 1; ret rv; };
let assign =
lambda (nid: ast::node_id, ty_opt: option::t<ty::t>) {
fn@ (nid: ast::node_id, ty_opt: option::t<ty::t>) {
let var_id = next_var_id();
locals.insert(nid, var_id);
alt ty_opt {
......@@ -1206,7 +1206,7 @@ fn gather_locals(ccx: @crate_ctxt,
// Add explicitly-declared locals.
let visit_local =
lambda (local: @ast::local, &&e: (), v: visit::vt<()>) {
fn@ (local: @ast::local, &&e: (), v: visit::vt<()>) {
let local_ty = ast_ty_to_ty_crate_infer(ccx, local.node.ty);
assign(local.node.id, local_ty);
visit::visit_local(local, e, v);
......@@ -1214,7 +1214,7 @@ fn gather_locals(ccx: @crate_ctxt,
// Add pattern bindings.
let visit_pat =
lambda (p: @ast::pat, &&e: (), v: visit::vt<()>) {
fn@ (p: @ast::pat, &&e: (), v: visit::vt<()>) {
alt p.node {
ast::pat_bind(_, _) { assign(p.id, none); }
_ {/* no-op */ }
......@@ -1726,7 +1726,7 @@ fn check_call_or_bind(fcx: @fn_ctxt, sp: span, f: @ast::expr,
// of arguments when we typecheck the functions. This isn't really the
// right way to do this.
let check_args =
lambda (check_blocks: bool) -> bool {
fn@ (check_blocks: bool) -> bool {
let i = 0u;
let bot = false;
for a_opt: option::t<@ast::expr> in args {
......@@ -2179,7 +2179,7 @@ fn check_binop_type_compat(fcx: @fn_ctxt, span: span, ty: ty::t,
fn lower_bound_proto(proto: ast::proto) -> ast::proto {
// FIXME: This is right for bare fns, possibly not others
alt proto {
ast::proto_bare. { ast::proto_shared(ast::sugar_normal) }
ast::proto_bare. { ast::proto_shared }
_ { proto }
}
}
......@@ -2632,7 +2632,7 @@ fn check_const(ccx: @crate_ctxt, _sp: span, e: @ast::expr, id: ast::node_id) {
let fcx: @fn_ctxt =
@{ret_ty: rty,
purity: ast::pure_fn,
proto: ast::proto_shared(ast::sugar_normal),
proto: ast::proto_shared,
var_bindings: ty::unify::mk_var_bindings(),
locals: new_int_hash::<int>(),
next_var_id: @mutable 0,
......
......@@ -110,15 +110,10 @@
tag mutability { mut; imm; maybe_mut; }
tag proto_sugar {
sugar_normal;
sugar_sexy;
}
tag proto {
proto_bare;
proto_send;
proto_shared(proto_sugar);
proto_shared;
proto_block;
}
......
......@@ -168,7 +168,7 @@ fn bad_expr_word_table() -> hashmap<str, ()> {
let words = new_str_hash();
for word in ["mod", "if", "else", "while", "do", "alt", "for", "break",
"cont", "ret", "be", "fail", "type", "resource", "check",
"assert", "claim", "native", "fn", "lambda", "pure",
"assert", "claim", "native", "fn", "fn@", "pure",
"unsafe", "block", "import", "export", "let", "const",
"log", "tag", "obj", "copy", "sendfn", "impl", "iface"] {
words.insert(word, ());
......@@ -514,8 +514,8 @@ fn parse_ty(p: parser, colons_before_params: bool) -> @ast::ty {
t = parse_ty_fn(proto, p);
} else if eat_word(p, "block") {
t = parse_ty_fn(ast::proto_block, p);
} else if eat_word(p, "lambda") {
t = parse_ty_fn(ast::proto_shared(ast::sugar_sexy), p);
} else if eat_word(p, "fn@") {
t = parse_ty_fn(ast::proto_shared, p);
} else if eat_word(p, "sendfn") {
t = parse_ty_fn(ast::proto_send, p);
} else if eat_word(p, "obj") {
......@@ -821,8 +821,8 @@ fn parse_bottom_expr(p: parser) -> pexpr {
ret pexpr(parse_fn_expr(p, proto));
} else if eat_word(p, "block") {
ret pexpr(parse_fn_expr(p, ast::proto_block));
} else if eat_word(p, "lambda") {
ret pexpr(parse_fn_expr(p, ast::proto_shared(ast::sugar_sexy)));
} else if eat_word(p, "fn@") {
ret pexpr(parse_fn_expr(p, ast::proto_shared));
} else if eat_word(p, "sendfn") {
ret pexpr(parse_fn_expr(p, ast::proto_send));
} else if eat_word(p, "unchecked") {
......@@ -2117,7 +2117,7 @@ fn parse_item_tag(p: parser, attrs: [ast::attribute]) -> @ast::item {
fn parse_fn_ty_proto(p: parser) -> ast::proto {
if p.peek() == token::AT {
p.bump();
ast::proto_shared(ast::sugar_normal)
ast::proto_shared
} else {
ast::proto_bare
}
......
......@@ -1685,8 +1685,7 @@ fn proto_to_str(p: ast::proto) -> str {
ast::proto_bare. { "fn" }
ast::proto_block. { "block" }
ast::proto_send. { "sendfn" }
ast::proto_shared(ast::sugar_normal.) { "fn@" }
ast::proto_shared(ast::sugar_sexy.) { "lambda" }
ast::proto_shared. { "fn@" }
};
}
......
......@@ -19,7 +19,7 @@
fk_item_fn(ident, [ty_param]); //< an item declared with fn()
fk_method(ident, [ty_param]);
fk_res(ident, [ty_param]);
fk_anon(proto); //< an anonymous function like lambda(...)
fk_anon(proto); //< an anonymous function like fn@(...)
fk_fn_block; //< a block {||...}
}
......
// error-pattern: copying a noncopyable value
fn to_lambda1(f: lambda(uint) -> uint) -> lambda(uint) -> uint {
fn to_lambda1(f: fn@(uint) -> uint) -> fn@(uint) -> uint {
ret f;
}
fn to_lambda2(b: block(uint) -> uint) -> lambda(uint) -> uint {
fn to_lambda2(b: block(uint) -> uint) -> fn@(uint) -> uint {
ret to_lambda1({|x| b(x)});
}
......
// error-pattern: copying a noncopyable value
fn to_lambda2(b: block(uint) -> uint) -> lambda(uint) -> uint {
fn to_lambda2(b: block(uint) -> uint) -> fn@(uint) -> uint {
// test case where copy clause specifies a value that is not used
// in lambda body, but value is illegal to copy:
ret lambda[copy b](u: uint) -> uint { 22u };
// in fn@ body, but value is illegal to copy:
ret fn@[copy b](u: uint) -> uint { 22u };
}
fn main() {
......
// error-pattern:Unsatisfied precondition
fn main() {
// Typestate should work even in a lambda. we should reject this program.
// Typestate should work even in a fn@. we should reject this program.
let f = fn () -> int { let i: int; ret i; };
log(error, f());
}
// error-pattern:assigning to upvar
// Make sure that nesting a block within a lambda doesn't let us
// mutate upvars from a lambda.
// Make sure that nesting a block within a fn@ doesn't let us
// mutate upvars from a fn@.
fn f2(x: block()) { x(); }
fn main() {
let i = 0;
let ctr = lambda () -> int { f2({|| i = i + 1; }); ret i; };
let ctr = fn@ () -> int { f2({|| i = i + 1; }); ret i; };
log(error, ctr());
log(error, ctr());
log(error, ctr());
......
// error-pattern:assigning to upvar
// Make sure we can't write to upvars from lambdas
// Make sure we can't write to upvars from fn@s
fn main() {
let i = 0;
let ctr = lambda () -> int { i = i + 1; ret i; };
let ctr = fn@ () -> int { i = i + 1; ret i; };
log(error, ctr());
log(error, ctr());
log(error, ctr());
......
// error-pattern: mismatched types: expected `lambda(++uint) -> uint`
// error-pattern: mismatched types: expected `fn@(++uint) -> uint`
fn test(f: lambda(uint) -> uint) -> uint {
fn test(f: fn@(uint) -> uint) -> uint {
ret f(22u);
}
......
......@@ -4,9 +4,9 @@ fn main() {
let x = 1;
let y = 2;
let z = 3;
let l1 = lambda[copy x]() -> int { x + y };
let l2 = lambda[copy x; move y]() -> int { x + y };
let l3 = lambda[move z]() -> int { z };
let l1 = fn@[copy x]() -> int { x + y };
let l2 = fn@[copy x; move y]() -> int { x + y };
let l3 = fn@[move z]() -> int { z };
let x = 1;
let y = 2;
......
......@@ -8,7 +8,7 @@ fn (tasties: @str, macerate: block(str)) {
macerate(*tasties);
} (carrots, { |food|
let mush = food + cheese;
lambda() {
let _ = fn@() {
let chew = mush + cheese;
fail "so yummy"
} ();
......
......@@ -4,7 +4,7 @@ fn asSendfn( f : sendfn()->uint ) -> uint {
ret f();
}
fn asLambda( f : lambda()->uint ) -> uint {
fn asLambda( f : fn@()->uint ) -> uint {
ret f();
}
......
fn to_lambda(f: lambda(uint) -> uint) -> lambda(uint) -> uint {
fn to_lambda(f: fn@(uint) -> uint) -> fn@(uint) -> uint {
ret f;
}
fn main() {
let x: lambda(uint) -> uint = to_lambda({ |x| x * 2u });
let x: fn@(uint) -> uint = to_lambda({ |x| x * 2u });
let y = to_lambda(x);
let x_r = x(22u);
......
......@@ -2,8 +2,8 @@ fn main() {
let x = ~1;
let y = ptr::addr_of(*x) as uint;
let lam_copy = lambda[copy x]() -> uint { ptr::addr_of(*x) as uint };
let lam_move = lambda[move x]() -> uint { ptr::addr_of(*x) as uint };
let lam_copy = fn@[copy x]() -> uint { ptr::addr_of(*x) as uint };
let lam_move = fn@[move x]() -> uint { ptr::addr_of(*x) as uint };
assert lam_copy() != y;
assert lam_move() == y;
......
fn main() {
// We should be able to type infer inside of lambdas.
// We should be able to type infer inside of fn@s.
let f = fn () { let i = 10; };
}
// This should typecheck even though the type of e is not fully
// resolved when we finish typechecking the lambda.
// resolved when we finish typechecking the fn@.
fn main() {
let e = @{mutable refs: [], n: 0};
let f = lambda () { log(error, e.n); };
let f = fn@ () { log(error, e.n); };
e.refs += [1];
}
// Make sure we don't leak lambdas in silly ways.
// Make sure we don't leak fn@s in silly ways.
fn force(f: fn@()) { f() }
fn main() {
let x = 7;
lambda () { log(error, x); };
force(lambda () { log(error, x); });
let _ = fn@ () { log(error, x); };
force(fn@ () { log(error, x); });
}
// Make sure #1399 stays fixed
fn foo() -> lambda() -> int {
fn foo() -> fn@() -> int {
let k = ~22;
let _u = {a: k};
ret lambda[move k]() -> int { 22 };
ret fn@[move k]() -> int { 22 };
}
fn main() {
......
// Make sure #1399 stays fixed
fn main() {
fn invoke(f: lambda()) { f(); }
fn invoke(f: fn@()) { f(); }
let k = ~22;
let _u = {a: k};
invoke {||log(error, k);}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册