Skip to content

Commit f17a342

Browse files
brsongraydon
authored andcommitted
Cleanup for 'be' statement and comments about future typestate
1 parent 6461cf3 commit f17a342

File tree

6 files changed

+30
-16
lines changed

6 files changed

+30
-16
lines changed

src/comp/front/ast.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,17 @@ fn index_native_item(native_mod_index index, @native_item it) {
315315
}
316316
}
317317

318+
fn is_call_expr(@expr e) -> bool {
319+
alt (e.node) {
320+
case (expr_call(_, _, _)) {
321+
ret true;
322+
}
323+
case (_) {
324+
ret false;
325+
}
326+
}
327+
}
328+
318329
//
319330
// Local Variables:
320331
// mode: rust

src/comp/front/parser.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1203,7 +1203,13 @@ impure fn parse_stmt(parser p) -> @ast.stmt {
12031203
case (token.BE) {
12041204
p.bump();
12051205
auto e = parse_expr(p);
1206-
ret @spanned(lo, e.span, ast.stmt_be(e));
1206+
// FIXME: Is this the right place for this check?
1207+
if /*check*/ (ast.is_call_expr(e)) {
1208+
ret @spanned(lo, e.span, ast.stmt_be(e));
1209+
}
1210+
else {
1211+
p.err("Non-call expression in tail call");
1212+
}
12071213
}
12081214

12091215
case (token.LET) {

src/comp/middle/trans.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3129,7 +3129,10 @@ fn trans_ret(@block_ctxt cx, &option.t[@ast.expr] e) -> result {
31293129
}
31303130

31313131
fn trans_be(@block_ctxt cx, @ast.expr e) -> result {
3132-
// FIXME: So this isn't actually a tail call
3132+
// FIXME: This should be a typestate precondition
3133+
check ast.is_call_expr(e);
3134+
// FIXME: Turn this into a real tail call once
3135+
// calling convention issues are settled
31333136
ret trans_ret(cx, some(e));
31343137
}
31353138

src/comp/middle/typeck.rs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1720,18 +1720,12 @@ fn check_stmt(&@fn_ctxt fcx, &@ast.stmt stmt) -> @ast.stmt {
17201720
}
17211721

17221722
case (ast.stmt_be(?expr)) {
1723-
alt (expr.node) {
1724-
case (ast.expr_call(_, _, _)) {
1725-
auto expr_0 = check_expr(fcx, expr);
1726-
auto expr_1 = demand_expr(fcx, fcx.ret_ty, expr_0);
1727-
ret @fold.respan[ast.stmt_](stmt.span,
1728-
ast.stmt_be(expr_1));
1729-
}
1730-
case (_) {
1731-
fcx.ccx.sess.err("Non-call expression in tail call");
1732-
fail;
1733-
}
1734-
}
1723+
/* FIXME: prove instead of check */
1724+
check ast.is_call_expr(expr);
1725+
auto expr_0 = check_expr(fcx, expr);
1726+
auto expr_1 = demand_expr(fcx, fcx.ret_ty, expr_0);
1727+
ret @fold.respan[ast.stmt_](stmt.span,
1728+
ast.stmt_be(expr_1));
17351729
}
17361730

17371731
case (ast.stmt_log(?expr)) {

src/test/compile-fail/tail-non-call.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ fn f() -> int {
77

88
fn main() {
99
auto y = f();
10-
}
10+
}

src/test/compile-fail/tail-typeck.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ fn g() -> uint {
1010

1111
fn main() {
1212
auto y = f();
13-
}
13+
}

0 commit comments

Comments
 (0)