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

New attribute-based syntax for exec function specifications #1356

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Chris-Hawblitzel
Copy link
Collaborator

This follows up the discussion in #1297 to replace the exec function requires/ensures attributes from #1297 with a single general-purpose attribute for exec function specifications that uses the familiar verus! syntax inside the exec function attribute. This pull request also tries to consolidate some code that was duplicated between the verus! and attribute-based syntax implementations.

Note that, as with #1297, this attribute-based syntax is an alternative to the verus! syntax for those who want such an alternative (see, for example, #1100 ). We do not intend to remove the verus! syntax. In particular, spec functions and proof functions are still always written using verus!, while exec functions can use either syntax.

The new function attribute syntax looks like:

#[verus_spec(sum =>
    requires
        x < 100,
        y < 100,
    ensures
        sum < 200,
)]
fn my_exec_fun(x: u32, y: u32) -> u32 {
    x + y
}

See example/syntax_attr.rs for more complete examples.

The new attribute name verus_spec avoids conflicts with verus_verify, which can still be used independently for things like verus_verify(external_body).

The attribute syntax for loop invariants remains the same as in #1297 .

Copy link
Collaborator

@ziqiaozhou ziqiaozhou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change works well in both verification and non-verification build modes in my COCONUT change.


/// variables may be exec, tracked, or ghost
/// - exec: compiled
/// - tracked: erased before compilation, checked for lifetimes (advanced feature, discussed later)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The example below does not show how to use tracked/ghost ? Did I miss some changes to support tracked/ghost variable in verus_spec?

@ziqiaozhou
Copy link
Collaborator

I haven't used the invariant for loop in coconut code yet. But I am wondering whether the final format of loop specification will also be changed to

#[verus_spec(
invariant
   xxx
decreases
   xxx
)]?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants