Skip to content

Further work on typestate. Handles expr_rec and expr_assign now. #326

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/comp/front/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,10 @@ tag mode {

type stmt = spanned[stmt_];
tag stmt_ {
stmt_decl(@decl, option.t[@ts_ann]);
stmt_expr(@expr, option.t[@ts_ann]);
/* Only the ts_ann field is meaningful for statements,
but we make it an ann to make traversals simpler */
stmt_decl(@decl, ann);
stmt_expr(@expr, ann);
// These only exist in crate-level blocks.
stmt_crate_directive(@crate_directive);
}
Expand Down
16 changes: 9 additions & 7 deletions src/comp/front/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import util.common;
import util.common.filename;
import util.common.span;
import util.common.new_str_hash;
import util.typestate_ann.ts_ann;
import util.common.plain_ann;

tag restriction {
UNRESTRICTED;
Expand Down Expand Up @@ -1562,14 +1562,15 @@ impure fn parse_source_stmt(parser p) -> @ast.stmt {

case (token.LET) {
auto decl = parse_let(p);
ret @spanned(lo, decl.span.hi,
ast.stmt_decl(decl, none[@ts_ann]));
auto hi = p.get_span();
ret @spanned
(lo, decl.span.hi, ast.stmt_decl(decl, plain_ann()));
}

case (token.AUTO) {
auto decl = parse_auto(p);
ret @spanned(lo, decl.span.hi,
ast.stmt_decl(decl, none[@ts_ann]));
auto hi = p.get_span();
ret @spanned(lo, decl.span.hi, ast.stmt_decl(decl, plain_ann()));
}

case (_) {
Expand All @@ -1578,12 +1579,13 @@ impure fn parse_source_stmt(parser p) -> @ast.stmt {
auto i = parse_item(p);
auto hi = i.span.hi;
auto decl = @spanned(lo, hi, ast.decl_item(i));
ret @spanned(lo, hi, ast.stmt_decl(decl, none[@ts_ann]));
ret @spanned(lo, hi, ast.stmt_decl(decl, plain_ann()));

} else {
// Remainder are line-expr stmts.
auto e = parse_expr(p);
ret @spanned(lo, e.span.hi, ast.stmt_expr(e, none[@ts_ann]));
auto hi = p.get_span();
ret @spanned(lo, e.span.hi, ast.stmt_expr(e, plain_ann()));
}
}
}
Expand Down
22 changes: 12 additions & 10 deletions src/comp/middle/fold.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,11 +232,11 @@ type ast_fold[ENV] =

// Stmt folds.
(fn(&ENV e, &span sp,
@decl decl, option.t[@ts_ann] a)
@decl decl, ann a)
-> @stmt) fold_stmt_decl,

(fn(&ENV e, &span sp,
@expr e, option.t[@ts_ann] a)
@expr e, ann a)
-> @stmt) fold_stmt_expr,

// Item folds.
Expand Down Expand Up @@ -470,7 +470,9 @@ fn fold_decl[ENV](&ENV env, ast_fold[ENV] fld, @decl d) -> @decl {
}
case (_) { /* fall through */ }
}
let @ast.local local_ = @rec(ty=ty_, init=init_ with *local);
auto ann_ = fld.fold_ann(env_, local.ann);
let @ast.local local_ =
@rec(ty=ty_, init=init_, ann=ann_ with *local);
ret fld.fold_decl_local(env_, d.span, local_);
}

Expand Down Expand Up @@ -830,12 +832,14 @@ fn fold_stmt[ENV](&ENV env, ast_fold[ENV] fld, &@stmt s) -> @stmt {
alt (s.node) {
case (ast.stmt_decl(?d, ?a)) {
auto dd = fold_decl(env_, fld, d);
ret fld.fold_stmt_decl(env_, s.span, dd, a);
auto aa = fld.fold_ann(env_, a);
ret fld.fold_stmt_decl(env_, s.span, dd, aa);
}

case (ast.stmt_expr(?e, ?a)) {
auto ee = fold_expr(env_, fld, e);
ret fld.fold_stmt_expr(env_, s.span, ee, a);
auto aa = fld.fold_ann(env_, a);
ret fld.fold_stmt_expr(env_, s.span, ee, aa);
}
}
fail;
Expand Down Expand Up @@ -1426,13 +1430,11 @@ fn identity_fold_pat_tag[ENV](&ENV e, &span sp, path p, vec[@pat] args,

// Stmt identities.

fn identity_fold_stmt_decl[ENV](&ENV env, &span sp, @decl d,
option.t[@ts_ann] a) -> @stmt {
fn identity_fold_stmt_decl[ENV](&ENV env, &span sp, @decl d, ann a) -> @stmt {
ret @respan(sp, ast.stmt_decl(d, a));
}

fn identity_fold_stmt_expr[ENV](&ENV e, &span sp, @expr x,
option.t[@ts_ann] a) -> @stmt {
fn identity_fold_stmt_expr[ENV](&ENV e, &span sp, @expr x, ann a) -> @stmt {
ret @respan(sp, ast.stmt_expr(x, a));
}

Expand Down Expand Up @@ -1705,7 +1707,7 @@ fn new_identity_fold[ENV]() -> ast_fold[ENV] {
bind identity_fold_native_item_ty[ENV](_,_,_,_),
fold_item_tag = bind identity_fold_item_tag[ENV](_,_,_,_,_,_,_),
fold_item_obj = bind identity_fold_item_obj[ENV](_,_,_,_,_,_,_),

fold_view_item_use =
bind identity_fold_view_item_use[ENV](_,_,_,_,_,_),
fold_view_item_import =
Expand Down
17 changes: 15 additions & 2 deletions src/comp/middle/typeck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1541,7 +1541,7 @@ fn resolve_local_types_in_block(&@fn_ctxt fcx, &ast.block block)
// FIXME: rustboot bug prevents us from using these functions directly
auto fld = fold.new_identity_fold[option.t[@fn_ctxt]]();
auto wbl = writeback_local;
auto rltia = resolve_local_types_in_annotation;
auto rltia = bind resolve_local_types_in_annotation(_,_);
auto uefi = update_env_for_item;
auto kg = keep_going;
fld = @rec(
Expand Down Expand Up @@ -2551,6 +2551,10 @@ fn check_decl_local(&@fn_ctxt fcx, &@ast.decl decl) -> @ast.decl {
alt (decl.node) {
case (ast.decl_local(?local)) {

auto t;

t = plain_ty(middle.ty.ty_nil);

alt (local.ty) {
case (none[@ast.ty]) {
// Auto slot. Do nothing for now.
Expand All @@ -2559,7 +2563,16 @@ fn check_decl_local(&@fn_ctxt fcx, &@ast.decl decl) -> @ast.decl {
case (some[@ast.ty](?ast_ty)) {
auto local_ty = ast_ty_to_ty_crate(fcx.ccx, ast_ty);
fcx.locals.insert(local.id, local_ty);
t = local_ty;
}
}

auto a_res = local.ann;
alt (a_res) {
case (ann_none) {
a_res = triv_ann(t);
}
case (_) {}
}

auto initopt = local.init;
Expand All @@ -2583,7 +2596,7 @@ fn check_decl_local(&@fn_ctxt fcx, &@ast.decl decl) -> @ast.decl {
}
case (_) { /* fall through */ }
}
auto local_1 = @rec(init = initopt with *local);
auto local_1 = @rec(init = initopt, ann = a_res with *local);
ret @rec(node=ast.decl_local(local_1)
with *decl);
}
Expand Down
Loading