Skip to content

Commit

Permalink
typestate_check can now handle expr_block, expr_if, and expr_binary
Browse files Browse the repository at this point in the history
(caveat for the latter: it assumes that binary operations are strict;
a TODO is to detect or and and and correctly reflect that they're lazy
in the second argument). I had to add an ann field to ast.block,
resulting in the usual boilerplate changes.

Test cases that currently work (if you uncomment the typestate pass
in the driver) (all these are under test/compile-fail):

fru-typestate
ret-uninit
use-uninit
use-uninit-2
use-uninit-3
  • Loading branch information
catamorphism committed Apr 13, 2011
1 parent d3409f6 commit 63e87c1
Show file tree
Hide file tree
Showing 6 changed files with 358 additions and 161 deletions.
3 changes: 2 additions & 1 deletion src/comp/front/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ tag block_index_entry {
}
type block_ = rec(vec[@stmt] stmts,
option.t[@expr] expr,
hashmap[ident,block_index_entry] index);
hashmap[ident,block_index_entry] index,
ann a); /* ann is only meaningful for the ts_ann field */

type variant_def = tup(def_id /* tag */, def_id /* variant */);

Expand Down
2 changes: 1 addition & 1 deletion src/comp/front/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1598,7 +1598,7 @@ fn index_block(vec[@ast.stmt] stmts, option.t[@ast.expr] expr) -> ast.block_ {
for (@ast.stmt s in stmts) {
ast.index_stmt(index, s);
}
ret rec(stmts=stmts, expr=expr, index=index);
ret rec(stmts=stmts, expr=expr, index=index, a=ast.ann_none);
}

fn index_arm(@ast.pat pat) -> hashmap[ast.ident,ast.def_id] {
Expand Down
3 changes: 2 additions & 1 deletion src/comp/middle/fold.rs
Original file line number Diff line number Diff line change
Expand Up @@ -871,7 +871,8 @@ fn fold_block[ENV](&ENV env, ast_fold[ENV] fld, &block blk) -> block {
}
}

ret respan(blk.span, rec(stmts=stmts, expr=expr, index=index));
auto aa = fld.fold_ann(env, blk.node.a);
ret respan(blk.span, rec(stmts=stmts, expr=expr, index=index, a=aa));
}

fn fold_arm[ENV](&ENV env, ast_fold[ENV] fld, &arm a) -> arm {
Expand Down
6 changes: 4 additions & 2 deletions src/comp/middle/typeck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1399,7 +1399,8 @@ mod Pushdown {
auto e_1 = pushdown_expr(fcx, expected, e_0);
auto block_ = rec(stmts=bloc.node.stmts,
expr=some[@ast.expr](e_1),
index=bloc.node.index);
index=bloc.node.index,
a=boring_ann());
ret fold.respan[ast.block_](bloc.span, block_);
}
case (none[@ast.expr]) {
Expand Down Expand Up @@ -2569,7 +2570,8 @@ fn check_block(&@fn_ctxt fcx, &ast.block block) -> ast.block {

ret fold.respan[ast.block_](block.span,
rec(stmts=stmts, expr=expr,
index=block.node.index));
index=block.node.index,
a=boring_ann()));
}

fn check_const(&@crate_ctxt ccx, &span sp, ast.ident ident, @ast.ty t,
Expand Down
Loading

0 comments on commit 63e87c1

Please sign in to comment.