Skip to content
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

support no_unwind clause #56

Merged
merged 2 commits into from
Apr 10, 2024
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

* Support attributes on `broadcast group` items
* Improve styling of `broadcast use`s, ensuring trailing newline
* Add support for the `no_unwind` clause on functions

# v0.2.11

Expand Down
4 changes: 4 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -771,8 +771,11 @@ fn to_doc<'a>(
| Rule::invariant_ensures_str
| Rule::opens_invariants_str
| Rule::recommends_str
| Rule::no_unwind_str
| Rule::requires_str => arena.hardline().append(s).nest(INDENT_SPACES),

Rule::no_unwind_when_str => arena.space().append(s).append(arena.space()),

Rule::any_str
| Rule::assert_str
| Rule::assume_str
Expand Down Expand Up @@ -1275,6 +1278,7 @@ fn to_doc<'a>(
Rule::invariant_ensures_clause => map_to_doc(ctx, arena, pair),
Rule::recommends_clause => map_to_doc(ctx, arena, pair),
Rule::decreases_clause => map_to_doc(ctx, arena, pair),
Rule::unwind_clause => map_to_doc(ctx, arena, pair),
Rule::opens_invariants_mode => arena.space().append(map_to_doc(ctx, arena, pair)),
Rule::opens_invariants_clause => map_to_doc(ctx, arena, pair),
Rule::assert_requires => map_to_doc(ctx, arena, pair).append(arena.line()),
Expand Down
8 changes: 7 additions & 1 deletion src/verus.pest
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,8 @@ move_str = ${ "move" ~ !("_" | ASCII_ALPHANUMERIC) }
mut_str = ${ "mut" ~ !("_" | ASCII_ALPHANUMERIC) }
nat_str = ${ "nat" ~ !("_" | ASCII_ALPHANUMERIC) }
none_str = ${ "none" ~ !("_" | ASCII_ALPHANUMERIC) }
no_unwind_str = ${ "no_unwind" ~ !("_" | ASCII_ALPHANUMERIC) }
no_unwind_when_str = ${ "when" ~ !("_" | ASCII_ALPHANUMERIC) }
opens_invariants_str = ${ "opens_invariants" ~ !("_" | ASCII_ALPHANUMERIC) }
open_str = ${ "open" ~ !("_" | ASCII_ALPHANUMERIC) }
proof_space_str = ${ "proof" ~ !("_" | ASCII_ALPHANUMERIC) }
Expand Down Expand Up @@ -652,7 +654,7 @@ use_tree_list = {
}

fn_qualifier = {
(requires_clause | recommends_clause | ensures_clause | decreases_clause | opens_invariants_clause)*
(requires_clause | recommends_clause | ensures_clause | decreases_clause | opens_invariants_clause | unwind_clause)*
}

fn_terminator = {
Expand Down Expand Up @@ -1691,6 +1693,10 @@ decreases_clause = {
decreases_str ~ groupable_comma_delimited_exprs_for_verus_clauses ~ (when_str ~ expr_no_struct)? ~ (via_str ~ expr_no_struct)?
}

unwind_clause = {
no_unwind_str ~ (no_unwind_when_str ~ expr_no_struct)?
}

opens_invariants_mode = {
any_str
| none_str
Expand Down
32 changes: 32 additions & 0 deletions tests/verus-consistency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2062,3 +2062,35 @@ proof fn to_multiset_build<A>(s: Seq<A>, a: A)
} // verus!
"###);
}

#[test]
fn verus_unwind() {
let file = r###"
verus! {
proof fn a()
no_unwind
{
}

proof fn b()
no_unwind when x >= 0
{
}
} // verus!
"###;
assert_snapshot!(parse_and_format(file).unwrap(), @r###"
verus! {

proof fn a()
no_unwind
{
}

proof fn b()
no_unwind when x >= 0
{
}

} // verus!
"###);
}
Loading