Skip to content

Commit 8685a1f

Browse files
committed
distinguish "any closure" and "stack closure" (block)
1 parent 47a534c commit 8685a1f

32 files changed

+102
-70
lines changed

src/comp/metadata/tydecode.rs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,17 @@ fn parse_ty_rust_fn(st: @pstate, conv: conv_did, p: ast::proto) -> ty::t {
161161
ret ty::mk_fn(st.tcx, {proto: p with parse_ty_fn(st, conv)});
162162
}
163163

164+
fn parse_proto(c: char) -> ast::proto {
165+
alt c {
166+
'~' { ast::proto_uniq }
167+
'@' { ast::proto_box }
168+
'*' { ast::proto_any }
169+
'&' { ast::proto_block }
170+
'n' { ast::proto_bare }
171+
_ { fail "illegal fn type kind " + str::from_char(c); }
172+
}
173+
}
174+
164175
fn parse_ty(st: @pstate, conv: conv_did) -> ty::t {
165176
alt next(st) as char {
166177
'n' { ret ty::mk_nil(st.tcx); }
@@ -230,17 +241,9 @@ fn parse_ty(st: @pstate, conv: conv_did) -> ty::t {
230241
st.pos = st.pos + 1u;
231242
ret ty::mk_tup(st.tcx, params);
232243
}
233-
's' {
234-
ret parse_ty_rust_fn(st, conv, ast::proto_uniq);
235-
}
236-
'F' {
237-
ret parse_ty_rust_fn(st, conv, ast::proto_box);
238-
}
239244
'f' {
240-
ret parse_ty_rust_fn(st, conv, ast::proto_bare);
241-
}
242-
'B' {
243-
ret parse_ty_rust_fn(st, conv, ast::proto_block);
245+
let proto = parse_proto(next(st) as char);
246+
parse_ty_rust_fn(st, conv, proto)
244247
}
245248
'N' {
246249
let func = parse_ty_fn(st, conv);

src/comp/metadata/tyencode.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -192,10 +192,11 @@ fn enc_sty(w: io::writer, cx: @ctxt, st: ty::sty) {
192192
}
193193
fn enc_proto(w: io::writer, proto: proto) {
194194
alt proto {
195-
proto_uniq. { w.write_char('s'); }
196-
proto_box. { w.write_char('F'); }
197-
proto_block. { w.write_char('B'); }
198-
proto_bare. { w.write_char('f'); }
195+
proto_uniq. { w.write_str("f~"); }
196+
proto_box. { w.write_str("f@"); }
197+
proto_block. { w.write_str("f&"); }
198+
proto_any. { w.write_str("f*"); }
199+
proto_bare. { w.write_str("fn"); }
199200
}
200201
}
201202

src/comp/middle/alias.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,14 @@ fn visit_fn(cx: @ctx, _fk: visit::fn_kind, decl: ast::fn_decl,
8888
// Blocks need to obey any restrictions from the enclosing scope, and may
8989
// be called multiple times.
9090
let proto = ty::ty_fn_proto(cx.tcx, fty);
91-
if proto == ast::proto_block {
91+
alt proto {
92+
ast::proto_block. | ast::proto_any. {
9293
check_loop(*cx, sc) {|| v.visit_block(body, sc, v);}
93-
} else {
94+
}
95+
ast::proto_box. | ast::proto_uniq. | ast::proto_bare. {
9496
let sc = {bs: [], invalid: @mutable list::nil};
9597
v.visit_block(body, sc, v);
98+
}
9699
}
97100
}
98101

src/comp/middle/block_use.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ fn check_crate(tcx: ty::ctxt, crate: @crate) {
1414
fn visit_expr(ex: @expr, cx: ctx, v: visit::vt<ctx>) {
1515
if !cx.allow_block {
1616
alt ty::struct(cx.tcx, ty::expr_ty(cx.tcx, ex)) {
17-
ty::ty_fn({proto: proto_block., _}) {
17+
ty::ty_fn({proto: p, _}) if is_blockish(p) {
1818
cx.tcx.sess.span_err(ex.span, "expressions with block type \
1919
can only appear in callee or (by-ref) argument position");
2020
}

src/comp/middle/capture.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ fn check_capture_clause(tcx: ty::ctxt,
7575
};
7676

7777
alt fn_proto {
78-
ast::proto_block. {
78+
ast::proto_any. | ast::proto_block. {
7979
check_block_captures(cap_clause.copies);
8080
check_block_captures(cap_clause.moves);
8181
}
@@ -113,7 +113,7 @@ fn compute_capture_vars(tcx: ty::ctxt,
113113
}
114114

115115
let implicit_mode = alt fn_proto {
116-
ast::proto_block. { cap_ref }
116+
ast::proto_any. | ast::proto_block. { cap_ref }
117117
ast::proto_bare. | ast::proto_box. | ast::proto_uniq. { cap_copy }
118118
};
119119

src/comp/middle/kind.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ fn with_appropriate_checker(cx: ctx, id: node_id,
6363
alt ty::ty_fn_proto(cx.tcx, fty) {
6464
proto_uniq. { b(check_send); }
6565
proto_box. { b(check_copy); }
66-
proto_block. { /* no check needed */ }
6766
proto_bare. { b(check_none); }
67+
proto_any. | proto_block. { /* no check needed */ }
6868
}
6969
}
7070

src/comp/middle/last_use.rs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@ fn find_last_uses(c: @crate, def_map: resolve::def_map,
6363
ret mini_table;
6464
}
6565

66-
fn is_block(cx: ctx, id: node_id) -> bool {
66+
fn ex_is_blockish(cx: ctx, id: node_id) -> bool {
6767
alt ty::struct(cx.tcx, ty::node_id_to_monotype(cx.tcx, id)) {
68-
ty::ty_fn({proto: proto_block., _}) { true }
68+
ty::ty_fn({proto: p, _}) if is_blockish(p) { true }
6969
_ { false }
7070
}
7171
}
@@ -152,8 +152,12 @@ fn visit_expr(ex: @expr, cx: ctx, v: visit::vt<ctx>) {
152152
let arg_ts = ty::ty_fn_args(cx.tcx, ty::expr_ty(cx.tcx, f));
153153
for arg in args {
154154
alt arg.node {
155-
expr_fn(proto_block., _, _, _) { fns += [arg]; }
156-
expr_fn_block(_, _) if is_block(cx, arg.id) { fns += [arg]; }
155+
expr_fn(p, _, _, _) if is_blockish(p) {
156+
fns += [arg];
157+
}
158+
expr_fn_block(_, _) if ex_is_blockish(cx, arg.id) {
159+
fns += [arg];
160+
}
157161
_ {
158162
alt arg_ts[i].mode {
159163
by_mut_ref. { clear_if_path(cx, arg, v, false); }
@@ -174,11 +178,13 @@ fn visit_fn(fk: visit::fn_kind, decl: fn_decl, body: blk,
174178
cx: ctx, v: visit::vt<ctx>) {
175179
let fty = ty::node_id_to_type(cx.tcx, id);
176180
let proto = ty::ty_fn_proto(cx.tcx, fty);
177-
if proto == proto_block {
181+
alt proto {
182+
proto_any. | proto_block. {
178183
visit_block(func, cx, {||
179184
visit::visit_fn(fk, decl, body, sp, id, cx, v);
180185
});
181-
} else {
186+
}
187+
proto_box. | proto_uniq. | proto_bare. {
182188
alt cx.tcx.freevars.find(id) {
183189
some(vars) {
184190
for v in *vars {
@@ -193,6 +199,7 @@ fn visit_fn(fk: visit::fn_kind, decl: fn_decl, body: blk,
193199
visit::visit_fn(fk, decl, body, sp, id, cx, v);
194200
cx.blocks <-> old;
195201
leave_fn(cx);
202+
}
196203
}
197204
}
198205

src/comp/middle/mut.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ fn is_immutable_def(cx: @ctx, def: def) -> option::t<str> {
269269
let ty = ty::node_id_to_monotype(cx.tcx, node_id);
270270
let proto = ty::ty_fn_proto(cx.tcx, ty);
271271
ret alt proto {
272-
proto_block. { is_immutable_def(cx, *inner) }
272+
proto_any. | proto_block. { is_immutable_def(cx, *inner) }
273273
_ { some("upvar") }
274274
};
275275
}

src/comp/middle/trans_closure.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,7 @@ fn trans_expr_fn(bcx: @block_ctxt,
523523
};
524524

525525
let closure = alt proto {
526+
ast::proto_any. { fail "proto_any cannot appear in an expr"; }
526527
ast::proto_block. { trans_closure_env(ty::ck_block) }
527528
ast::proto_box. { trans_closure_env(ty::ck_box) }
528529
ast::proto_uniq. { trans_closure_env(ty::ck_uniq) }
@@ -664,6 +665,7 @@ fn make_fn_glue(
664665
ret alt ty::struct(tcx, t) {
665666
ty::ty_native_fn(_, _) | ty::ty_fn({proto: ast::proto_bare., _}) { bcx }
666667
ty::ty_fn({proto: ast::proto_block., _}) { bcx }
668+
ty::ty_fn({proto: ast::proto_any., _}) { bcx }
667669
ty::ty_fn({proto: ast::proto_uniq., _}) { fn_env(ty::ck_uniq) }
668670
ty::ty_fn({proto: ast::proto_box., _}) { fn_env(ty::ck_box) }
669671
_ { fail "make_fn_glue invoked on non-function type" }

src/comp/middle/ty.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -993,6 +993,7 @@ pure fn kind_can_be_sent(k: kind) -> bool {
993993

994994
fn proto_kind(p: proto) -> kind {
995995
alt p {
996+
ast::proto_any. { kind_noncopyable }
996997
ast::proto_block. { kind_noncopyable }
997998
ast::proto_box. { kind_copyable }
998999
ast::proto_uniq. { kind_sendable }
@@ -1925,7 +1926,8 @@ mod unify {
19251926
// subtype).
19261927
fn sub_proto(p_sub: ast::proto, p_sup: ast::proto) -> bool {
19271928
ret alt (p_sub, p_sup) {
1928-
(_, ast::proto_block.) { true }
1929+
(_, ast::proto_any.) { true }
1930+
(_, ast::proto_block.) { true } /* NDM temporary */
19291931
(ast::proto_bare., _) { true }
19301932

19311933
// Equal prototypes are always subprotos:

0 commit comments

Comments
 (0)