-
Notifications
You must be signed in to change notification settings - Fork 8
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
Resourceful invariants and associated libraries #38
Conversation
…with_inv, annotating opens for with_inv, etc.
: Lemma (name_of_allocated_name (allocated_name_of_inv i) == name_of_inv i) | ||
[SMTPat (name_of_allocated_name (allocated_name_of_inv i))] | ||
[@@ erasable] | ||
val iref : Type0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new iref type and associated inv resource.
| EffectAnnotAtomic { opens:term } | ||
| EffectAnnotAtomicOrGhost { opens:term } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Effect annotation used to check with_invariants blocks, in case a post hint is not already present.
@@ -283,7 +284,7 @@ type st_term' = | |||
| Tm_WithInv { | |||
name : term; // invariant name is an F* term that is an Tm_fvar or Tm_name | |||
body : st_term; | |||
returns_inv : option (binder & vprop); | |||
returns_inv : option (binder & vprop & term); // returns _:t ensures p opens is |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
returns annotation on with_invariants contains an opens also (defaults to emp_inames if absent).
|
||
assume val f () : stt_atomic unit emp_inames (p ** q) (fun _ -> p ** r) | ||
|
||
```pulse |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A couple of examples.
With @nikswamy.
The PR adds support for resourceful invariants, getting rid of the reliance on the monotonicity-related axioms in Pulse Core. The use of these axioms for implementing invariants in Pulse Core has been troublesome because of how it interacts with strong excluded middle (see FStarLang/FStar#2814). To get around these issues, Pulse Core had to accommodate a new point "Unobservable" in its effect hierarchy and prohibit ghost code from allocating or using invariants.
Summary
Extending the stratified heap model in Pulse, this PR adds a new compartment to the heap that maps a new kind of reference, iref, to vprops. The compartment is monotonic (as in no freeing/updating of irefs once allocated) and an assertion of the form
inv i p
represents the knowledge that iref i points to vprop p. This is a duplicable invariant resource that may be eliminated with a with_invariant combinator.Building on this change in the memory model, the PR implements these resourceful invariants all the way up to the Pulse checker and associated libraries (e.g., locks, mutex, trade, pledge, etc.).
Changes
Pulse Core
Pulse semantics is now based on a preorder state monad, rather than a monotonic state monad.
Following are the new additions to Pulse Core:
The
stt_ghost
effect is also indexed with the set if inames to indicate that the computation may open these invariants. Due to the stratified nature of the underlying memory, new_invariant requires that p is "big". This essentially means that p should not be a (inv i p) assertion itself. The PR augments libraries with support to proveis_big
for common vprops.The Unobservable effect is no longer there in Pulse.
Pulse Checker
Pulse typechecks this as follows:
The annotations (returns, ensures, opens) are either present on the with_invariant block itself, or come from post hint propagation (via bidirectional typechecking).
To support both ghost and atomic with_invariant blocks with the same syntax, the checker has a EffectAnnotAtomicOrGhost expected effect.
Pulse Libraries and Examples
The main change is that working with invariants now requires explicit invariant resources. With the new design, the libaries now have: