logical atomicity #1538
tjhance
started this conversation in
Language design
Replies: 1 comment 1 reply
-
|
In our experience with logatom in Perennial, the angle-brackets sugar notation is convenient, but in many cases we need to then manipulate the logatom fupds (callbacks) explicitly, such as putting them in invariants, passing them to other threads or functions, associating them with data structures like a work queue, etc. What would be the tracked object that represents a logatom closure? |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Logical atomicity
Verus needs to support logical atomicity to be a serious concurrency-verification platform. It's possible to implement logical atomicity with traits or with "proof closures"; however, I think Verus should have logical atomicity as a built-in feature.
Background: Logical atomicity in Iris
Iris uses the following notation for logical atomicity:
The
atomic_preconditionandatomic_postconditioncanmanipulate resources owned by the atomic invariant, while the
private_preconditionandprivate_postconditionuse thread-owned resources.In Iris, "logical atomicity" can be accomplished by higher-order state: rather than opening an invariant "around" an operation, we can pass in a "ghost update" that is invoked at the "linearization point". This atomic update is therefore allowed to manipulate the resources in the atomic invariant.
Where:
(This is not quite right but close enough for now.)
Now, this can be emulated in Verus using proof closures (or traits), sort of. One limitation with Verus is that proof functions can't change the mask, though even if we had that capability, it would still be incredibly tedious to do all that setup.
Therefore, it would be nice to have a concise logically-atomic spec notation in Verus, like in Iris. However, unlike Iris, Verus lacks the higher-order capabilities to define Hoare triple specifications within its own logic. I believe we should add logical atomicity as a built-in feature.
Verus notation for calling a LA function
A more ergonomic approach would be one that doesn't require the caller to setup proof closures, instead letting them seemlessly integrate the proof code into the body of the caller function.
For example, suppose
latomic_fnis a logically atomic function. In order to capture the intuition that "a logically atomic function can be treated as if it were atomic", we would like to be able to write:For this to be sound, though, we need to put all the conditions in the right places. That should amount to the following:
Verus notation for declaring a logically atomic function
In order for Verus to generate these VCs automatically, we need Verus to have a dedicated notation for logically atomic specs.
In Iris, all private and atomic pre/postconditions are of course Iris propositions, thus allowing resources. Likewise in Verus, we need tracked inputs/outputs both for private and atomic conditions. This would be easiest to implement with better notation for tracked inputs and outputs like in this discussion.
We also need to include mask information.
Maybe something like this:
Examples
As an example, we can write
AtomicU64operations as logically atomic specs:(This operation is, of course, physically atomic, but in the long run I'd prefer to unify the notions, replacing our current
#[atomic]attribute with logically atomic specs).Example usage:
The
withsyntax is still fictional; here it's being used to transfer thetrackedstate that is part of the atomic precondition.Now, what if we want to verify a function with a logically atomic spec? We need an operation that can "open" the atomic update, which would behave similarly to
open_atomic_invariant!:Misc notes
I used the
open_atomic_invariant!notation above, since that's what's currently in Verus, but I'd actually like to change the notation:This would be a step towards supporting functions that change the mask, which would be useful. Also, I think it looks better.
Integrating logical atomicity with VerusSync
more on this later
Things to do
Beta Was this translation helpful? Give feedback.
All reactions