-
Notifications
You must be signed in to change notification settings - Fork 2
Refinement-based specifications for iostream #40
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
fed2e2e
Rename [iostream] -> [iostream_trace]
gmalecha-at-skylabs 0db042e
Refinement-based specifications of iostream
gmalecha-at-skylabs 5200a21
Split out [itree_prop] and do some cleanup
gmalecha-at-skylabs 8abcf43
Fix AnyStep (maybe?) and prove some syntactic properties for clarity
pgiarrusso-sl a06cac7
Some cleanup based on the review
gmalecha-at-skylabs 9d6a888
Upstream some lemmas
gmalecha-at-skylabs 7c6d954
Documentation
gmalecha-at-skylabs 7adf95f
FIX: do not enable atomic_wait
gmalecha-at-skylabs File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| # `<iostream>` | ||
|
|
||
| This directory captures the behavior of the `<iostream>` library using the refinement methodology | ||
| developed in the [Spectra](https://github.com/SkyLabsAI/BRiCk/blob/main/rocq-skylabs-iris/theories/base_logic/lib/spectra.md) library. | ||
|
|
||
| At the high level, the behavior of a program is described by a labled transition system (LTS** and the | ||
| *current state* of the LTS is embedded in separation logic (in Spectra this is done using `AuthSet.frag`). | ||
| Interactions with the outside world are captured via updating this state through the use of requesters | ||
| and committers which allow updating this state by emitting appropriate events. | ||
|
|
||
| ## Adequacy | ||
|
|
||
| See the Spectra docs for more information about establishing a formal refinement with this setup. | ||
|
|
||
| ## References | ||
|
|
||
| - [Spectra](https://github.com/SkyLabsAI/BRiCk/blob/main/rocq-skylabs-iris/theories/base_logic/lib/spectra.md) | ||
| - [A Separation Logic for Refining Concurrent Objects](https://dl.acm.org/doi/10.1145/1926385.1926415) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| (* TODO: replace this with the actual itree library *) | ||
| CoInductive itree {E : Type -> Type} {T : Type} : Type := | ||
| | Ret (_ : T) | ||
| | Tau (_ : itree) | ||
| | Do {U} (_ : E U) (_ : U -> itree). | ||
| #[global] Arguments itree E T : clear implicits. | ||
|
|
||
| Section with_E. | ||
| Context {E : Type -> Type}. | ||
|
|
||
| CoFixpoint bind {T U} (it : itree E T) (k : T -> itree E U) : itree E U := | ||
| match it with | ||
| | Ret v => k v | ||
| | Tau it => Tau (bind it k) | ||
| | Do e k' => Do e (fun x => bind (k' x) k) | ||
| end. | ||
|
|
||
| End with_E. | ||
|
|
||
| Require Import stdpp.base. | ||
| Require Import skylabs.prelude.sts. | ||
|
|
||
| Section as_lts. | ||
| Context {E : Type -> Type}. | ||
| Context {Evt : Type}. | ||
|
|
||
| Context {as_evt : forall {T}, E T -> T -> Evt}. | ||
|
|
||
| Variant itree_step : itree E unit -> option Evt -> itree E unit -> Prop := | ||
| | step_do {T} {act : E T} (r : T) k | ||
| : itree_step (Do act k) (Some $ as_evt _ act r) (k r) | ||
| | step_tau {k} | ||
| : itree_step (Tau k) None k. | ||
|
|
||
| Definition itree_lts (it : itree E unit) : LTS Evt := | ||
| {| Sts._state := itree E unit | ||
| ; Sts._init_state := eq it | ||
| ; Sts._step := itree_step |}. | ||
| End as_lts. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| Require Import skylabs.auto.cpp.prelude.proof. (* TODO: reduce dependency *) | ||
|
|
||
| Require Import skylabs.auto.hints.kont. | ||
|
|
||
| Require Export skylabs.brick.libstdcpp.iostream.itree. | ||
|
|
||
| (** A handler for events as a predicate transformer. | ||
|
|
||
| Generally, this will be an <AU> that proves that <evt> is a valid next event. | ||
| *) | ||
| Record SepHandler {PROP : bi} {evt : Type} : Type := | ||
| { do : propset evt -> (evt -> PROP) -> PROP | ||
| (** This is effectively an <<AU>> that performs the event and then continues *) | ||
| ; do_frame : forall evtP, ProperFrame (T:=[tele (_ : evt)]) (do evtP) | ||
| ; do_ne : forall n, Proper ((≡) ==> pointwise_relation _ (dist n) ==> (dist n)) do | ||
| }. | ||
| #[global] Arguments SepHandler _ _ : clear implicits. | ||
| #[global] Hint Opaque do : sl_opacity. | ||
|
|
||
|
|
||
| (* TODO: these should be replaced by library definitions *) | ||
| Section interp_itree. | ||
| Context {PROP : bi}. | ||
| Context {PROP_LATER : BiLaterContractive PROP}. | ||
|
|
||
| Context {E : Type -> Type}. | ||
| Context {Evt : Type}. | ||
| Variable as_evt : forall {T}, E T -> T -> Evt. | ||
|
|
||
| Context (SH : SepHandler PROP Evt). | ||
|
|
||
| #[local] | ||
| Definition interp_do_body {T} (K : T -> PROP) (rec : itree E T -d> PROP) : itree E T -d> PROP := | ||
| funI it => | ||
| match it with | ||
| | Ret v => K v | ||
| | Tau x => |> rec x | ||
| | Do act k => | ||
| letI* evt := SH.(do) {[ evt | exists r, evt = as_evt act r ]} in | ||
| ∃ r, [| evt = as_evt act r |] ∗ |> rec (k r) | ||
| end. | ||
|
|
||
| #[local] | ||
| Instance interp_do_body_contractive {T} {K : T -> PROP} : Contractive (interp_do_body K). | ||
| Proof using PROP_LATER. | ||
| repeat intro. | ||
| destruct x0; simpl; try eauto. | ||
| { apply later_contractive. constructor. | ||
| intros. apply H. done. } | ||
| { eapply do_ne. done. | ||
| intro. apply bi.exist_ne; intro. apply bi.sep_ne. done. apply later_contractive. | ||
| constructor; intros; apply H; done. } | ||
| Qed. | ||
|
|
||
| Definition interp_itree {T} (it : itree E T) (K : T -> PROP) : PROP := | ||
| fixpoint (A:=_ -d> PROP) (interp_do_body K) it. | ||
|
|
||
| End interp_itree. | ||
| #[global] Arguments interp_itree {PROP _ E Event} as_evt SH {_} it _%_I : rename. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.