Skip to content

Commit b7dd75c

Browse files
catamorphismgraydon
authored andcommitted
Handle nested items correctly in typestate_check
Summary says it all. Actually, only nested objects and functions are handled, but that's better than before. The fold that I was using before to traverse a crate wasn't working correctly, because annotations have to reflect the number of local variables of the nearest enclosing function (in turn, because annotations are represented as bit vectors). The fold was traversing the AST in the wrong order, first filling in the annotations correctly, but then re-traversing them with the bit vector length for any outer nested functions, and so on. Remedying this required writing a lot of tedious boilerplate code because I scrapped the idea of using a fold altogether. I also made typestate_check handle unary, field, alt, and fail. Also, some miscellaneous changes: * added annotations to blocks in typeck * fix pprust so it can handle spawn * added more logging functions in util.common * fixed _vec.or * added maybe and from_maybe in option * removed fold_block field from ast_fold, since it was never used
1 parent 3d9cf15 commit b7dd75c

File tree

9 files changed

+833
-99
lines changed

9 files changed

+833
-99
lines changed

src/comp/middle/fold.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -291,8 +291,6 @@ type ast_fold[ENV] =
291291
(fn(&ENV e, ann a) -> ann) fold_ann,
292292

293293
// Additional nodes.
294-
(fn(&ENV e, &span sp,
295-
&ast.block_) -> block) fold_block,
296294

297295
(fn(&ENV e, &fn_decl decl,
298296
ast.proto proto,
@@ -1716,7 +1714,6 @@ fn new_identity_fold[ENV]() -> ast_fold[ENV] {
17161714

17171715
fold_ann = bind identity_fold_ann[ENV](_,_),
17181716

1719-
fold_block = bind identity_fold_block[ENV](_,_,_),
17201717
fold_fn = bind identity_fold_fn[ENV](_,_,_,_),
17211718
fold_fn_decl = bind identity_fold_fn_decl[ENV](_,_,_),
17221719
fold_mod = bind identity_fold_mod[ENV](_,_),

src/comp/middle/typeck.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1469,7 +1469,8 @@ mod Pushdown {
14691469
}
14701470
case (none[@ast.expr]) {
14711471
Demand.simple(fcx, bloc.span, expected, plain_ty(ty.ty_nil));
1472-
ret bloc;
1472+
ret fold.respan[ast.block_](bloc.span,
1473+
rec(a = boring_ann() with bloc.node));
14731474
}
14741475
}
14751476
}

0 commit comments

Comments
 (0)