Merge ast::proto_shared and ast::proto_closure

Now they are both just proto_shared and proto_shared takes an
argument indicating that it is sugared as 'lambda'
This commit is contained in:
Brian Anderson 2011-10-18 21:18:55 -07:00
parent 4b30a06abe
commit 9efdd0f326
15 changed files with 62 additions and 44 deletions

View file

@ -192,7 +192,7 @@ fn mk_tests(cx: test_ctxt) -> @ast::item {
il: ast::il_normal, il: ast::il_normal,
cf: ast::return_val, cf: ast::return_val,
constraints: []}; constraints: []};
let proto = ast::proto_shared; let proto = ast::proto_bare;
// The vector of test_descs for this crate // The vector of test_descs for this crate
let test_descs = mk_test_desc_vec(cx); let test_descs = mk_test_desc_vec(cx);
@ -214,7 +214,7 @@ fn mk_tests(cx: test_ctxt) -> @ast::item {
} }
fn empty_fn_ty() -> ast::ty { fn empty_fn_ty() -> ast::ty {
let proto = ast::proto_shared; let proto = ast::proto_bare;
let input_ty = []; let input_ty = [];
let ret_ty = @nospan(ast::ty_nil); let ret_ty = @nospan(ast::ty_nil);
let cf = ast::return_val; let cf = ast::return_val;

View file

@ -242,7 +242,8 @@ fn parse_ty(st: @pstate, sd: str_def) -> ty::t {
} }
'F' { 'F' {
let func = parse_ty_fn(st, sd); let func = parse_ty_fn(st, sd);
ret ty::mk_fn(st.tcx, ast::proto_shared, func.args, func.ty, func.cf, ret ty::mk_fn(st.tcx, ast::proto_shared(ast::sugar_normal),
func.args, func.ty, func.cf,
func.cs); func.cs);
} }
'f' { 'f' {

View file

@ -195,7 +195,7 @@ fn enc_sty(w: io::writer, cx: @ctxt, st: ty::sty) {
fn enc_proto(w: io::writer, proto: proto) { fn enc_proto(w: io::writer, proto: proto) {
alt proto { alt proto {
proto_iter. { w.write_char('W'); } proto_iter. { w.write_char('W'); }
proto_shared. { w.write_char('F'); } proto_shared(_) { w.write_char('F'); }
proto_block. { w.write_char('B'); } proto_block. { w.write_char('B'); }
proto_bare. { w.write_char('f'); } proto_bare. { w.write_char('f'); }
} }

View file

@ -71,7 +71,7 @@ fn visit_fn(cx: @ctx, f: ast::_fn, _tp: [ast::ty_param], sp: span,
let bs = alt f.proto { let bs = alt f.proto {
// Blocks need to obey any restrictions from the enclosing scope. // Blocks need to obey any restrictions from the enclosing scope.
ast::proto_block. | ast::proto_closure. { sc.bs } ast::proto_block. | ast::proto_shared(_) { sc.bs }
// Non capturing functions start out fresh. // Non capturing functions start out fresh.
_ { [] } _ { [] }
}; };

View file

@ -36,7 +36,8 @@ fn collect_freevars(def_map: resolve::def_map, walker: fn@(visit::vt<int>)) ->
alt expr.node { alt expr.node {
ast::expr_fn(f) { ast::expr_fn(f) {
if f.proto == ast::proto_block || if f.proto == ast::proto_block ||
f.proto == ast::proto_closure { f.proto == ast::proto_shared(ast::sugar_normal) ||
f.proto == ast::proto_shared(ast::sugar_sexy) {
visit::visit_expr(expr, depth + 1, v); visit::visit_expr(expr, depth + 1, v);
} }
} }

View file

@ -595,7 +595,6 @@ fn lookup_in_scope_strict(e: env, sc: scopes, sp: span, name: ident,
fn scope_is_fn(sc: scope) -> bool { fn scope_is_fn(sc: scope) -> bool {
ret alt sc { ret alt sc {
scope_fn(_, ast::proto_iter., _) | scope_fn(_, ast::proto_iter., _) |
scope_fn(_, ast::proto_shared., _) |
scope_fn(_, ast::proto_bare., _) | scope_fn(_, ast::proto_bare., _) |
scope_native_item(_) { scope_native_item(_) {
true true
@ -607,7 +606,7 @@ fn scope_is_fn(sc: scope) -> bool {
fn scope_closes(sc: scope) -> option::t<bool> { fn scope_closes(sc: scope) -> option::t<bool> {
alt sc { alt sc {
scope_fn(_, ast::proto_block., _) | scope_loop(_, true) { some(true) } scope_fn(_, ast::proto_block., _) | scope_loop(_, true) { some(true) }
scope_fn(_, ast::proto_closure., _) { some(false) } scope_fn(_, ast::proto_shared(_), _) { some(false) }
_ { none } _ { none }
} }
} }

View file

@ -2250,10 +2250,12 @@ fn trans_expr_fn(bcx: @block_ctxt, f: ast::_fn, sp: span,
let s = mangle_internal_name_by_path(ccx, sub_cx.path); let s = mangle_internal_name_by_path(ccx, sub_cx.path);
let llfn = decl_internal_cdecl_fn(ccx.llmod, s, llfnty); let llfn = decl_internal_cdecl_fn(ccx.llmod, s, llfnty);
let copying = f.proto == ast::proto_closure; let copying =
f.proto == ast::proto_shared(ast::sugar_normal)
|| f.proto == ast::proto_shared(ast::sugar_sexy);
let env; let env;
alt f.proto { alt f.proto {
ast::proto_block. | ast::proto_closure. { ast::proto_block. | ast::proto_shared(_) {
let upvars = get_freevars(ccx.tcx, id); let upvars = get_freevars(ccx.tcx, id);
let env_r = build_closure(bcx, upvars, copying); let env_r = build_closure(bcx, upvars, copying);
env = env_r.ptr; env = env_r.ptr;
@ -5349,7 +5351,8 @@ fn trans_res_ctor(cx: @local_ctxt, sp: span, dtor: ast::_fn,
} }
let fcx = new_fn_ctxt(cx, sp, llctor_decl); let fcx = new_fn_ctxt(cx, sp, llctor_decl);
let ret_t = ty::ret_ty_of_fn(cx.ccx.tcx, ctor_id); let ret_t = ty::ret_ty_of_fn(cx.ccx.tcx, ctor_id);
create_llargs_for_fn_args(fcx, ast::proto_shared, none::<ty::t>, ret_t, create_llargs_for_fn_args(fcx, ast::proto_shared(ast::sugar_normal),
none::<ty::t>, ret_t,
dtor.decl.inputs, ty_params); dtor.decl.inputs, ty_params);
let bcx = new_top_block_ctxt(fcx); let bcx = new_top_block_ctxt(fcx);
let lltop = bcx.llbb; let lltop = bcx.llbb;
@ -5409,7 +5412,8 @@ fn trans_tag_variant(cx: @local_ctxt, tag_id: ast::node_id,
} }
} }
let fcx = new_fn_ctxt(cx, variant.span, llfndecl); let fcx = new_fn_ctxt(cx, variant.span, llfndecl);
create_llargs_for_fn_args(fcx, ast::proto_shared, none::<ty::t>, create_llargs_for_fn_args(fcx, ast::proto_shared(ast::sugar_normal),
none::<ty::t>,
ty::ret_ty_of_fn(cx.ccx.tcx, variant.node.id), ty::ret_ty_of_fn(cx.ccx.tcx, variant.node.id),
fn_args, ty_params); fn_args, ty_params);
let ty_param_substs: [ty::t] = []; let ty_param_substs: [ty::t] = [];
@ -5616,7 +5620,8 @@ fn create_main_wrapper(ccx: @crate_ctxt, sp: span, main_llfn: ValueRef,
let nt = ty::mk_nil(ccx.tcx); let nt = ty::mk_nil(ccx.tcx);
check non_ty_var(ccx, nt); check non_ty_var(ccx, nt);
let llfty = type_of_fn(ccx, sp, ast::proto_shared, false, false, let llfty = type_of_fn(ccx, sp, ast::proto_shared(ast::sugar_normal),
false, false,
[vecarg_ty], nt, 0u); [vecarg_ty], nt, 0u);
let llfdecl = decl_fn(ccx.llmod, "_rust_main", let llfdecl = decl_fn(ccx.llmod, "_rust_main",
lib::llvm::LLVMCCallConv, llfty); lib::llvm::LLVMCCallConv, llfty);
@ -5729,7 +5734,8 @@ fn native_fn_wrapper_type(cx: @crate_ctxt, sp: span, ty_param_count: uint,
alt ty::struct(cx.tcx, x) { alt ty::struct(cx.tcx, x) {
ty::ty_native_fn(abi, args, out) { ty::ty_native_fn(abi, args, out) {
check non_ty_var(cx, out); check non_ty_var(cx, out);
ret type_of_fn(cx, sp, ast::proto_shared, false, false, args, out, ret type_of_fn(cx, sp, ast::proto_shared(ast::sugar_normal),
false, false, args, out,
ty_param_count); ty_param_count);
} }
} }

View file

@ -340,7 +340,8 @@ fn get_res_dtor(ccx: @crate_ctxt, sp: span, did: ast::def_id, inner_t: ty::t)
let nil_res = ty::mk_nil(ccx.tcx); let nil_res = ty::mk_nil(ccx.tcx);
// FIXME: Silly check -- mk_nil should have a postcondition // FIXME: Silly check -- mk_nil should have a postcondition
check non_ty_var(ccx, nil_res); check non_ty_var(ccx, nil_res);
let f_t = type_of_fn(ccx, sp, ast::proto_shared, false, false, let f_t = type_of_fn(ccx, sp, ast::proto_shared(ast::sugar_normal),
false, false,
[{mode: ast::by_ref, ty: inner_t}], [{mode: ast::by_ref, ty: inner_t}],
nil_res, params); nil_res, params);
ret trans::get_extern_const(ccx.externs, ccx.llmod, ret trans::get_extern_const(ccx.externs, ccx.llmod,

View file

@ -52,7 +52,8 @@ fn trans_obj(cx: @local_ctxt, sp: span, ob: ast::_obj, ctor_id: ast::node_id,
let lltop = bcx.llbb; let lltop = bcx.llbb;
// Both regular arguments and type parameters are handled here. // Both regular arguments and type parameters are handled here.
create_llargs_for_fn_args(fcx, ast::proto_shared, none::<ty::t>, create_llargs_for_fn_args(fcx, ast::proto_shared(ast::sugar_normal),
none::<ty::t>,
ty::ret_ty_of_fn(ccx.tcx, ctor_id), fn_args, ty::ret_ty_of_fn(ccx.tcx, ctor_id), fn_args,
ty_params); ty_params);
let arg_tys: [ty::arg] = arg_tys_of_fn(ccx, ctor_id); let arg_tys: [ty::arg] = arg_tys_of_fn(ccx, ctor_id);

View file

@ -1012,8 +1012,7 @@ fn type_kind(cx: ctxt, ty: t) -> ast::kind {
result = alt proto { result = alt proto {
ast::proto_iter. { ast::kind_shared } ast::proto_iter. { ast::kind_shared }
ast::proto_block. { ast::kind_pinned } ast::proto_block. { ast::kind_pinned }
ast::proto_closure. { ast::kind_shared } ast::proto_shared(_) { ast::kind_shared }
ast::proto_shared. { ast::kind_shared }
ast::proto_bare. { ast::kind_unique } ast::proto_bare. { ast::kind_unique }
}; };
} }
@ -1616,7 +1615,10 @@ fn ty_fn_args(cx: ctxt, fty: t) -> [arg] {
fn ty_fn_proto(cx: ctxt, fty: t) -> ast::proto { fn ty_fn_proto(cx: ctxt, fty: t) -> ast::proto {
alt struct(cx, fty) { alt struct(cx, fty) {
ty::ty_fn(p, _, _, _, _) { ret p; } ty::ty_fn(p, _, _, _, _) { ret p; }
ty::ty_native_fn(_, _, _) { ret ast::proto_shared; } ty::ty_native_fn(_, _, _) {
// FIXME: This should probably be proto_bare
ret ast::proto_shared(ast::sugar_normal);
}
_ { cx.sess.bug("ty_fn_proto() called on non-fn type"); } _ { cx.sess.bug("ty_fn_proto() called on non-fn type"); }
} }
} }
@ -2031,7 +2033,7 @@ mod unify {
// Every function type is a subtype of block // Every function type is a subtype of block
false false
} }
ast::proto_closure. | ast::proto_shared. { ast::proto_shared(_) {
a_proto == ast::proto_block a_proto == ast::proto_block
} }
ast::proto_bare. { ast::proto_bare. {

View file

@ -477,10 +477,9 @@ mod write {
// code. This is needed because fn and lambda have fn type while iter // code. This is needed because fn and lambda have fn type while iter
// has iter type and block has block type. This may end up changing. // has iter type and block has block type. This may end up changing.
fn proto_to_ty_proto(proto: ast::proto) -> ast::proto { fn proto_to_ty_proto(proto: ast::proto) -> ast::proto {
ret alt proto { // FIXME: This is no longer needed since fn@ and lambda have
ast::proto_iter. | ast::proto_block. | ast::proto_bare. { proto } // the same type
_ { ast::proto_shared } proto
};
} }
// Item collection - a pair of bootstrap passes: // Item collection - a pair of bootstrap passes:
@ -612,7 +611,8 @@ mod collect {
} }
let t_fn = let t_fn =
ty::mk_fn(cx.tcx, ast::proto_shared, t_inputs, t_obj.ty, ty::mk_fn(cx.tcx, ast::proto_shared(ast::sugar_normal),
t_inputs, t_obj.ty,
ast::return_val, []); ast::return_val, []);
let tpt = {kinds: ty_param_kinds(ty_params), ty: t_fn}; let tpt = {kinds: ty_param_kinds(ty_params), ty: t_fn};
cx.tcx.tcache.insert(local_def(ctor_id), tpt); cx.tcx.tcache.insert(local_def(ctor_id), tpt);
@ -723,7 +723,8 @@ mod collect {
let tag_t = ty::mk_tag(cx.tcx, tag_id, ty_param_tys); let tag_t = ty::mk_tag(cx.tcx, tag_id, ty_param_tys);
// FIXME: this will be different for constrained types // FIXME: this will be different for constrained types
result_ty = result_ty =
ty::mk_fn(cx.tcx, ast::proto_shared, args, tag_t, ty::mk_fn(cx.tcx, ast::proto_shared(ast::sugar_normal),
args, tag_t,
ast::return_val, []); ast::return_val, []);
} }
let tpt = {kinds: ty_param_kinds(ty_params), ty: result_ty}; let tpt = {kinds: ty_param_kinds(ty_params), ty: result_ty};
@ -793,10 +794,12 @@ mod collect {
ty::mk_res(cx.tcx, local_def(it.id), t_arg.ty, ty::mk_res(cx.tcx, local_def(it.id), t_arg.ty,
mk_ty_params(cx, tps)); mk_ty_params(cx, tps));
let t_ctor = let t_ctor =
ty::mk_fn(cx.tcx, ast::proto_shared, [t_arg], t_res, ty::mk_fn(cx.tcx, ast::proto_shared(ast::sugar_normal),
[t_arg], t_res,
ast::return_val, []); ast::return_val, []);
let t_dtor = let t_dtor =
ty::mk_fn(cx.tcx, ast::proto_shared, [t_arg], ty::mk_fn(cx.tcx, ast::proto_shared(ast::sugar_normal),
[t_arg],
ty::mk_nil(cx.tcx), ty::mk_nil(cx.tcx),
ast::return_val, []); ast::return_val, []);
write::ty_only(cx.tcx, it.id, t_res); write::ty_only(cx.tcx, it.id, t_res);
@ -2092,7 +2095,7 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, expr: @ast::expr, unify: unifier,
constrs = constrs_; constrs = constrs_;
} }
ty::ty_native_fn(_, arg_tys_, rt_) { ty::ty_native_fn(_, arg_tys_, rt_) {
proto = ast::proto_shared; proto = ast::proto_shared(ast::sugar_normal);
arg_tys = arg_tys_; arg_tys = arg_tys_;
rt = rt_; rt = rt_;
cf = ast::return_val; cf = ast::return_val;
@ -2117,7 +2120,7 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, expr: @ast::expr, unify: unifier,
fn lower_bound_proto(proto: ast::proto) -> ast::proto { fn lower_bound_proto(proto: ast::proto) -> ast::proto {
// FIXME: This is right for bare fns, possibly not others // FIXME: This is right for bare fns, possibly not others
alt proto { alt proto {
ast::proto_bare. { ast::proto_shared } ast::proto_bare. { ast::proto_shared(ast::sugar_normal) }
_ { proto } _ { proto }
} }
} }
@ -2568,7 +2571,7 @@ fn check_const(ccx: @crate_ctxt, _sp: span, e: @ast::expr, id: ast::node_id) {
let fcx: @fn_ctxt = let fcx: @fn_ctxt =
@{ret_ty: rty, @{ret_ty: rty,
purity: ast::pure_fn, purity: ast::pure_fn,
proto: ast::proto_shared, proto: ast::proto_shared(ast::sugar_normal),
var_bindings: ty::unify::mk_var_bindings(), var_bindings: ty::unify::mk_var_bindings(),
locals: new_int_hash::<int>(), locals: new_int_hash::<int>(),
local_names: new_int_hash::<ast::ident>(), local_names: new_int_hash::<ast::ident>(),

View file

@ -103,13 +103,16 @@ tag kind { kind_pinned; kind_shared; kind_unique; }
tag _auth { auth_unsafe; } tag _auth { auth_unsafe; }
tag proto_sugar {
sugar_normal;
sugar_sexy;
}
tag proto { tag proto {
proto_iter; proto_iter;
proto_shared;
proto_block;
// FIXME: Merge with proto_shared
proto_closure;
proto_bare; proto_bare;
proto_shared(proto_sugar);
proto_block;
} }
tag binop { tag binop {

View file

@ -842,7 +842,7 @@ fn parse_bottom_expr(p: parser) -> @ast::expr {
} else if eat_word(p, "block") { } else if eat_word(p, "block") {
ret parse_fn_expr(p, ast::proto_block); ret parse_fn_expr(p, ast::proto_block);
} else if eat_word(p, "lambda") { } else if eat_word(p, "lambda") {
ret parse_fn_expr(p, ast::proto_closure); ret parse_fn_expr(p, ast::proto_shared(ast::sugar_sexy));
} else if eat_word(p, "unchecked") { } else if eat_word(p, "unchecked") {
ret parse_block_expr(p, lo, ast::unchecked_blk); ret parse_block_expr(p, lo, ast::unchecked_blk);
} else if eat_word(p, "unsafe") { } else if eat_word(p, "unsafe") {
@ -1901,7 +1901,8 @@ fn parse_item_res(p: parser, attrs: [ast::attribute]) -> @ast::item {
il: ast::il_normal, il: ast::il_normal,
cf: ast::return_val, cf: ast::return_val,
constraints: []}; constraints: []};
let f = {decl: decl, proto: ast::proto_shared, body: dtor}; let f = {decl: decl, proto: ast::proto_shared(ast::sugar_normal),
body: dtor};
ret mk_item(p, lo, dtor.span.hi, ident, ret mk_item(p, lo, dtor.span.hi, ident,
ast::item_res(f, p.get_id(), ty_params, p.get_id()), attrs); ast::item_res(f, p.get_id(), ty_params, p.get_id()), attrs);
} }
@ -2140,7 +2141,7 @@ fn parse_fn_item_proto(p: parser) -> ast::proto {
ast::proto_bare ast::proto_bare
} else if p.peek() == token::AT { } else if p.peek() == token::AT {
p.bump(); p.bump();
ast::proto_shared ast::proto_shared(ast::sugar_normal)
} else { } else {
ast::proto_bare ast::proto_bare
} }
@ -2152,7 +2153,7 @@ fn parse_fn_ty_proto(p: parser) -> ast::proto {
ast::proto_bare ast::proto_bare
} else if p.peek() == token::AT { } else if p.peek() == token::AT {
p.bump(); p.bump();
ast::proto_shared ast::proto_shared(ast::sugar_normal)
} else { } else {
ast::proto_bare ast::proto_bare
} }
@ -2164,7 +2165,7 @@ fn parse_fn_anon_proto(p: parser) -> ast::proto {
ast::proto_bare ast::proto_bare
} else if p.peek() == token::AT { } else if p.peek() == token::AT {
p.bump(); p.bump();
ast::proto_shared ast::proto_shared(ast::sugar_normal)
} else { } else {
ast::proto_bare ast::proto_bare
} }

View file

@ -1643,11 +1643,11 @@ fn ast_fn_constrs_str(decl: ast::fn_decl, constrs: [@ast::constr]) -> str {
fn proto_to_str(p: ast::proto) -> str { fn proto_to_str(p: ast::proto) -> str {
ret alt p { ret alt p {
ast::proto_shared. { "fn@" }
ast::proto_iter. { "iter" } ast::proto_iter. { "iter" }
ast::proto_block. { "block" }
ast::proto_closure. { "lambda" }
ast::proto_bare. { "fn" } ast::proto_bare. { "fn" }
ast::proto_block. { "block" }
ast::proto_shared(ast::sugar_normal.) { "fn@" }
ast::proto_shared(ast::sugar_sexy.) { "lambda" }
}; };
} }

View file

@ -129,7 +129,7 @@ fn ty_to_str(cx: ctxt, typ: t) -> str {
fn_to_str(cx, proto, none, inputs, output, cf, constrs) fn_to_str(cx, proto, none, inputs, output, cf, constrs)
} }
ty_native_fn(_, inputs, output) { ty_native_fn(_, inputs, output) {
fn_to_str(cx, ast::proto_shared, none, inputs, output, fn_to_str(cx, ast::proto_bare, none, inputs, output,
ast::return_val, []) ast::return_val, [])
} }
ty_obj(meths) { ty_obj(meths) {