Skip to content

Commit 9efdd0f

Browse files
committed
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'
1 parent 4b30a06 commit 9efdd0f

File tree

15 files changed

+62
-44
lines changed

15 files changed

+62
-44
lines changed

src/comp/front/test.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ fn mk_tests(cx: test_ctxt) -> @ast::item {
192192
il: ast::il_normal,
193193
cf: ast::return_val,
194194
constraints: []};
195-
let proto = ast::proto_shared;
195+
let proto = ast::proto_bare;
196196

197197
// The vector of test_descs for this crate
198198
let test_descs = mk_test_desc_vec(cx);
@@ -214,7 +214,7 @@ fn mk_tests(cx: test_ctxt) -> @ast::item {
214214
}
215215

216216
fn empty_fn_ty() -> ast::ty {
217-
let proto = ast::proto_shared;
217+
let proto = ast::proto_bare;
218218
let input_ty = [];
219219
let ret_ty = @nospan(ast::ty_nil);
220220
let cf = ast::return_val;

src/comp/metadata/tydecode.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,8 @@ fn parse_ty(st: @pstate, sd: str_def) -> ty::t {
242242
}
243243
'F' {
244244
let func = parse_ty_fn(st, sd);
245-
ret ty::mk_fn(st.tcx, ast::proto_shared, func.args, func.ty, func.cf,
245+
ret ty::mk_fn(st.tcx, ast::proto_shared(ast::sugar_normal),
246+
func.args, func.ty, func.cf,
246247
func.cs);
247248
}
248249
'f' {

src/comp/metadata/tyencode.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ fn enc_sty(w: io::writer, cx: @ctxt, st: ty::sty) {
195195
fn enc_proto(w: io::writer, proto: proto) {
196196
alt proto {
197197
proto_iter. { w.write_char('W'); }
198-
proto_shared. { w.write_char('F'); }
198+
proto_shared(_) { w.write_char('F'); }
199199
proto_block. { w.write_char('B'); }
200200
proto_bare. { w.write_char('f'); }
201201
}

src/comp/middle/alias.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ fn visit_fn(cx: @ctx, f: ast::_fn, _tp: [ast::ty_param], sp: span,
7171

7272
let bs = alt f.proto {
7373
// Blocks need to obey any restrictions from the enclosing scope.
74-
ast::proto_block. | ast::proto_closure. { sc.bs }
74+
ast::proto_block. | ast::proto_shared(_) { sc.bs }
7575
// Non capturing functions start out fresh.
7676
_ { [] }
7777
};

src/comp/middle/freevars.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ fn collect_freevars(def_map: resolve::def_map, walker: fn@(visit::vt<int>)) ->
3636
alt expr.node {
3737
ast::expr_fn(f) {
3838
if f.proto == ast::proto_block ||
39-
f.proto == ast::proto_closure {
39+
f.proto == ast::proto_shared(ast::sugar_normal) ||
40+
f.proto == ast::proto_shared(ast::sugar_sexy) {
4041
visit::visit_expr(expr, depth + 1, v);
4142
}
4243
}

src/comp/middle/resolve.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,6 @@ fn lookup_in_scope_strict(e: env, sc: scopes, sp: span, name: ident,
595595
fn scope_is_fn(sc: scope) -> bool {
596596
ret alt sc {
597597
scope_fn(_, ast::proto_iter., _) |
598-
scope_fn(_, ast::proto_shared., _) |
599598
scope_fn(_, ast::proto_bare., _) |
600599
scope_native_item(_) {
601600
true
@@ -607,7 +606,7 @@ fn scope_is_fn(sc: scope) -> bool {
607606
fn scope_closes(sc: scope) -> option::t<bool> {
608607
alt sc {
609608
scope_fn(_, ast::proto_block., _) | scope_loop(_, true) { some(true) }
610-
scope_fn(_, ast::proto_closure., _) { some(false) }
609+
scope_fn(_, ast::proto_shared(_), _) { some(false) }
611610
_ { none }
612611
}
613612
}

src/comp/middle/trans.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2250,10 +2250,12 @@ fn trans_expr_fn(bcx: @block_ctxt, f: ast::_fn, sp: span,
22502250
let s = mangle_internal_name_by_path(ccx, sub_cx.path);
22512251
let llfn = decl_internal_cdecl_fn(ccx.llmod, s, llfnty);
22522252

2253-
let copying = f.proto == ast::proto_closure;
2253+
let copying =
2254+
f.proto == ast::proto_shared(ast::sugar_normal)
2255+
|| f.proto == ast::proto_shared(ast::sugar_sexy);
22542256
let env;
22552257
alt f.proto {
2256-
ast::proto_block. | ast::proto_closure. {
2258+
ast::proto_block. | ast::proto_shared(_) {
22572259
let upvars = get_freevars(ccx.tcx, id);
22582260
let env_r = build_closure(bcx, upvars, copying);
22592261
env = env_r.ptr;
@@ -5349,7 +5351,8 @@ fn trans_res_ctor(cx: @local_ctxt, sp: span, dtor: ast::_fn,
53495351
}
53505352
let fcx = new_fn_ctxt(cx, sp, llctor_decl);
53515353
let ret_t = ty::ret_ty_of_fn(cx.ccx.tcx, ctor_id);
5352-
create_llargs_for_fn_args(fcx, ast::proto_shared, none::<ty::t>, ret_t,
5354+
create_llargs_for_fn_args(fcx, ast::proto_shared(ast::sugar_normal),
5355+
none::<ty::t>, ret_t,
53535356
dtor.decl.inputs, ty_params);
53545357
let bcx = new_top_block_ctxt(fcx);
53555358
let lltop = bcx.llbb;
@@ -5409,7 +5412,8 @@ fn trans_tag_variant(cx: @local_ctxt, tag_id: ast::node_id,
54095412
}
54105413
}
54115414
let fcx = new_fn_ctxt(cx, variant.span, llfndecl);
5412-
create_llargs_for_fn_args(fcx, ast::proto_shared, none::<ty::t>,
5415+
create_llargs_for_fn_args(fcx, ast::proto_shared(ast::sugar_normal),
5416+
none::<ty::t>,
54135417
ty::ret_ty_of_fn(cx.ccx.tcx, variant.node.id),
54145418
fn_args, ty_params);
54155419
let ty_param_substs: [ty::t] = [];
@@ -5616,7 +5620,8 @@ fn create_main_wrapper(ccx: @crate_ctxt, sp: span, main_llfn: ValueRef,
56165620
let nt = ty::mk_nil(ccx.tcx);
56175621
check non_ty_var(ccx, nt);
56185622

5619-
let llfty = type_of_fn(ccx, sp, ast::proto_shared, false, false,
5623+
let llfty = type_of_fn(ccx, sp, ast::proto_shared(ast::sugar_normal),
5624+
false, false,
56205625
[vecarg_ty], nt, 0u);
56215626
let llfdecl = decl_fn(ccx.llmod, "_rust_main",
56225627
lib::llvm::LLVMCCallConv, llfty);
@@ -5729,7 +5734,8 @@ fn native_fn_wrapper_type(cx: @crate_ctxt, sp: span, ty_param_count: uint,
57295734
alt ty::struct(cx.tcx, x) {
57305735
ty::ty_native_fn(abi, args, out) {
57315736
check non_ty_var(cx, out);
5732-
ret type_of_fn(cx, sp, ast::proto_shared, false, false, args, out,
5737+
ret type_of_fn(cx, sp, ast::proto_shared(ast::sugar_normal),
5738+
false, false, args, out,
57335739
ty_param_count);
57345740
}
57355741
}

src/comp/middle/trans_common.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,8 @@ fn get_res_dtor(ccx: @crate_ctxt, sp: span, did: ast::def_id, inner_t: ty::t)
340340
let nil_res = ty::mk_nil(ccx.tcx);
341341
// FIXME: Silly check -- mk_nil should have a postcondition
342342
check non_ty_var(ccx, nil_res);
343-
let f_t = type_of_fn(ccx, sp, ast::proto_shared, false, false,
343+
let f_t = type_of_fn(ccx, sp, ast::proto_shared(ast::sugar_normal),
344+
false, false,
344345
[{mode: ast::by_ref, ty: inner_t}],
345346
nil_res, params);
346347
ret trans::get_extern_const(ccx.externs, ccx.llmod,

src/comp/middle/trans_objects.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ fn trans_obj(cx: @local_ctxt, sp: span, ob: ast::_obj, ctor_id: ast::node_id,
5252
let lltop = bcx.llbb;
5353

5454
// Both regular arguments and type parameters are handled here.
55-
create_llargs_for_fn_args(fcx, ast::proto_shared, none::<ty::t>,
55+
create_llargs_for_fn_args(fcx, ast::proto_shared(ast::sugar_normal),
56+
none::<ty::t>,
5657
ty::ret_ty_of_fn(ccx.tcx, ctor_id), fn_args,
5758
ty_params);
5859
let arg_tys: [ty::arg] = arg_tys_of_fn(ccx, ctor_id);

src/comp/middle/ty.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,8 +1012,7 @@ fn type_kind(cx: ctxt, ty: t) -> ast::kind {
10121012
result = alt proto {
10131013
ast::proto_iter. { ast::kind_shared }
10141014
ast::proto_block. { ast::kind_pinned }
1015-
ast::proto_closure. { ast::kind_shared }
1016-
ast::proto_shared. { ast::kind_shared }
1015+
ast::proto_shared(_) { ast::kind_shared }
10171016
ast::proto_bare. { ast::kind_unique }
10181017
};
10191018
}
@@ -1616,7 +1615,10 @@ fn ty_fn_args(cx: ctxt, fty: t) -> [arg] {
16161615
fn ty_fn_proto(cx: ctxt, fty: t) -> ast::proto {
16171616
alt struct(cx, fty) {
16181617
ty::ty_fn(p, _, _, _, _) { ret p; }
1619-
ty::ty_native_fn(_, _, _) { ret ast::proto_shared; }
1618+
ty::ty_native_fn(_, _, _) {
1619+
// FIXME: This should probably be proto_bare
1620+
ret ast::proto_shared(ast::sugar_normal);
1621+
}
16201622
_ { cx.sess.bug("ty_fn_proto() called on non-fn type"); }
16211623
}
16221624
}
@@ -2031,7 +2033,7 @@ mod unify {
20312033
// Every function type is a subtype of block
20322034
false
20332035
}
2034-
ast::proto_closure. | ast::proto_shared. {
2036+
ast::proto_shared(_) {
20352037
a_proto == ast::proto_block
20362038
}
20372039
ast::proto_bare. {

src/comp/middle/typeck.rs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -477,10 +477,9 @@ mod write {
477477
// code. This is needed because fn and lambda have fn type while iter
478478
// has iter type and block has block type. This may end up changing.
479479
fn proto_to_ty_proto(proto: ast::proto) -> ast::proto {
480-
ret alt proto {
481-
ast::proto_iter. | ast::proto_block. | ast::proto_bare. { proto }
482-
_ { ast::proto_shared }
483-
};
480+
// FIXME: This is no longer needed since fn@ and lambda have
481+
// the same type
482+
proto
484483
}
485484

486485
// Item collection - a pair of bootstrap passes:
@@ -612,7 +611,8 @@ mod collect {
612611
}
613612

614613
let t_fn =
615-
ty::mk_fn(cx.tcx, ast::proto_shared, t_inputs, t_obj.ty,
614+
ty::mk_fn(cx.tcx, ast::proto_shared(ast::sugar_normal),
615+
t_inputs, t_obj.ty,
616616
ast::return_val, []);
617617
let tpt = {kinds: ty_param_kinds(ty_params), ty: t_fn};
618618
cx.tcx.tcache.insert(local_def(ctor_id), tpt);
@@ -723,7 +723,8 @@ mod collect {
723723
let tag_t = ty::mk_tag(cx.tcx, tag_id, ty_param_tys);
724724
// FIXME: this will be different for constrained types
725725
result_ty =
726-
ty::mk_fn(cx.tcx, ast::proto_shared, args, tag_t,
726+
ty::mk_fn(cx.tcx, ast::proto_shared(ast::sugar_normal),
727+
args, tag_t,
727728
ast::return_val, []);
728729
}
729730
let tpt = {kinds: ty_param_kinds(ty_params), ty: result_ty};
@@ -793,10 +794,12 @@ mod collect {
793794
ty::mk_res(cx.tcx, local_def(it.id), t_arg.ty,
794795
mk_ty_params(cx, tps));
795796
let t_ctor =
796-
ty::mk_fn(cx.tcx, ast::proto_shared, [t_arg], t_res,
797+
ty::mk_fn(cx.tcx, ast::proto_shared(ast::sugar_normal),
798+
[t_arg], t_res,
797799
ast::return_val, []);
798800
let t_dtor =
799-
ty::mk_fn(cx.tcx, ast::proto_shared, [t_arg],
801+
ty::mk_fn(cx.tcx, ast::proto_shared(ast::sugar_normal),
802+
[t_arg],
800803
ty::mk_nil(cx.tcx),
801804
ast::return_val, []);
802805
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,
20922095
constrs = constrs_;
20932096
}
20942097
ty::ty_native_fn(_, arg_tys_, rt_) {
2095-
proto = ast::proto_shared;
2098+
proto = ast::proto_shared(ast::sugar_normal);
20962099
arg_tys = arg_tys_;
20972100
rt = rt_;
20982101
cf = ast::return_val;
@@ -2117,7 +2120,7 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, expr: @ast::expr, unify: unifier,
21172120
fn lower_bound_proto(proto: ast::proto) -> ast::proto {
21182121
// FIXME: This is right for bare fns, possibly not others
21192122
alt proto {
2120-
ast::proto_bare. { ast::proto_shared }
2123+
ast::proto_bare. { ast::proto_shared(ast::sugar_normal) }
21212124
_ { proto }
21222125
}
21232126
}
@@ -2568,7 +2571,7 @@ fn check_const(ccx: @crate_ctxt, _sp: span, e: @ast::expr, id: ast::node_id) {
25682571
let fcx: @fn_ctxt =
25692572
@{ret_ty: rty,
25702573
purity: ast::pure_fn,
2571-
proto: ast::proto_shared,
2574+
proto: ast::proto_shared(ast::sugar_normal),
25722575
var_bindings: ty::unify::mk_var_bindings(),
25732576
locals: new_int_hash::<int>(),
25742577
local_names: new_int_hash::<ast::ident>(),

src/comp/syntax/ast.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,13 +103,16 @@ tag kind { kind_pinned; kind_shared; kind_unique; }
103103

104104
tag _auth { auth_unsafe; }
105105

106+
tag proto_sugar {
107+
sugar_normal;
108+
sugar_sexy;
109+
}
110+
106111
tag proto {
107112
proto_iter;
108-
proto_shared;
109-
proto_block;
110-
// FIXME: Merge with proto_shared
111-
proto_closure;
112113
proto_bare;
114+
proto_shared(proto_sugar);
115+
proto_block;
113116
}
114117

115118
tag binop {

src/comp/syntax/parse/parser.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -842,7 +842,7 @@ fn parse_bottom_expr(p: parser) -> @ast::expr {
842842
} else if eat_word(p, "block") {
843843
ret parse_fn_expr(p, ast::proto_block);
844844
} else if eat_word(p, "lambda") {
845-
ret parse_fn_expr(p, ast::proto_closure);
845+
ret parse_fn_expr(p, ast::proto_shared(ast::sugar_sexy));
846846
} else if eat_word(p, "unchecked") {
847847
ret parse_block_expr(p, lo, ast::unchecked_blk);
848848
} else if eat_word(p, "unsafe") {
@@ -1901,7 +1901,8 @@ fn parse_item_res(p: parser, attrs: [ast::attribute]) -> @ast::item {
19011901
il: ast::il_normal,
19021902
cf: ast::return_val,
19031903
constraints: []};
1904-
let f = {decl: decl, proto: ast::proto_shared, body: dtor};
1904+
let f = {decl: decl, proto: ast::proto_shared(ast::sugar_normal),
1905+
body: dtor};
19051906
ret mk_item(p, lo, dtor.span.hi, ident,
19061907
ast::item_res(f, p.get_id(), ty_params, p.get_id()), attrs);
19071908
}
@@ -2140,7 +2141,7 @@ fn parse_fn_item_proto(p: parser) -> ast::proto {
21402141
ast::proto_bare
21412142
} else if p.peek() == token::AT {
21422143
p.bump();
2143-
ast::proto_shared
2144+
ast::proto_shared(ast::sugar_normal)
21442145
} else {
21452146
ast::proto_bare
21462147
}
@@ -2152,7 +2153,7 @@ fn parse_fn_ty_proto(p: parser) -> ast::proto {
21522153
ast::proto_bare
21532154
} else if p.peek() == token::AT {
21542155
p.bump();
2155-
ast::proto_shared
2156+
ast::proto_shared(ast::sugar_normal)
21562157
} else {
21572158
ast::proto_bare
21582159
}
@@ -2164,7 +2165,7 @@ fn parse_fn_anon_proto(p: parser) -> ast::proto {
21642165
ast::proto_bare
21652166
} else if p.peek() == token::AT {
21662167
p.bump();
2167-
ast::proto_shared
2168+
ast::proto_shared(ast::sugar_normal)
21682169
} else {
21692170
ast::proto_bare
21702171
}

src/comp/syntax/print/pprust.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1643,11 +1643,11 @@ fn ast_fn_constrs_str(decl: ast::fn_decl, constrs: [@ast::constr]) -> str {
16431643

16441644
fn proto_to_str(p: ast::proto) -> str {
16451645
ret alt p {
1646-
ast::proto_shared. { "fn@" }
16471646
ast::proto_iter. { "iter" }
1648-
ast::proto_block. { "block" }
1649-
ast::proto_closure. { "lambda" }
16501647
ast::proto_bare. { "fn" }
1648+
ast::proto_block. { "block" }
1649+
ast::proto_shared(ast::sugar_normal.) { "fn@" }
1650+
ast::proto_shared(ast::sugar_sexy.) { "lambda" }
16511651
};
16521652
}
16531653

src/comp/util/ppaux.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ fn ty_to_str(cx: ctxt, typ: t) -> str {
129129
fn_to_str(cx, proto, none, inputs, output, cf, constrs)
130130
}
131131
ty_native_fn(_, inputs, output) {
132-
fn_to_str(cx, ast::proto_shared, none, inputs, output,
132+
fn_to_str(cx, ast::proto_bare, none, inputs, output,
133133
ast::return_val, [])
134134
}
135135
ty_obj(meths) {

0 commit comments

Comments
 (0)