Skip to content

Commit 1b60bba

Browse files
committed
Use typestate constraints for trans_be
trans_be now has a precondition that its expression argument is a call expr. Obviously this code may be going away soon, but I wanted to exercise typestate somehow and this was an easy one :-)
1 parent 844e2d7 commit 1b60bba

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

src/comp/middle/trans.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4450,7 +4450,14 @@ fn trans_expr_out(cx: &@block_ctxt, e: &@ast::expr, output: out_method) ->
44504450
ast::expr_cont. { ret trans_cont(e.span, cx); }
44514451
ast::expr_ret(ex) { ret trans_ret(cx, ex); }
44524452
ast::expr_put(ex) { ret trans_put(cx, ex); }
4453-
ast::expr_be(ex) { ret trans_be(cx, ex); }
4453+
ast::expr_be(ex) {
4454+
// Ideally, the expr_be tag would have a precondition
4455+
// that is_call_expr(ex) -- but we don't support that
4456+
// yet
4457+
// FIXME
4458+
check ast_util::is_call_expr(ex);
4459+
ret trans_be(cx, ex);
4460+
}
44544461
ast::expr_anon_obj(anon_obj) {
44554462
ret trans_anon_obj(cx, e.span, anon_obj, e.id);
44564463
}
@@ -4776,10 +4783,10 @@ fn trans_ret(cx: &@block_ctxt, e: &option::t<@ast::expr>) -> result {
47764783

47774784
fn build_return(bcx: &@block_ctxt) { bld::Br(bcx, bcx_fcx(bcx).llreturn); }
47784785

4779-
fn trans_be(cx: &@block_ctxt, e: &@ast::expr) -> result {
4780-
// FIXME: This should be a typestate precondition
4786+
// fn trans_be(cx: &@block_ctxt, e: &@ast::expr) -> result {
4787+
fn trans_be(cx: &@block_ctxt, e: &@ast::expr)
4788+
: ast_util::is_call_expr(e) -> result {
47814789

4782-
assert (ast_util::is_call_expr(e));
47834790
// FIXME: Turn this into a real tail call once
47844791
// calling convention issues are settled
47854792

src/comp/syntax/ast_util.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,8 @@ fn is_exported(i: ident, m: _mod) -> bool {
167167
ret count == 0u && !nonlocal;
168168
}
169169

170-
fn is_call_expr(e: @expr) -> bool {
171-
alt e.node { expr_call(_, _) { ret true; } _ { ret false; } }
170+
pure fn is_call_expr(e: @expr) -> bool {
171+
alt e.node { expr_call(_, _) { true } _ { false } }
172172
}
173173

174174
fn is_constraint_arg(e: @expr) -> bool {

0 commit comments

Comments
 (0)