-
Notifications
You must be signed in to change notification settings - Fork 2
Sketch of the lockable concept #56
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
Open
gmalecha-at-skylabs
wants to merge
12
commits into
main
Choose a base branch
from
gmalecha/concept-lockable
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
814597b
mutex/spec: extract do_lock and do_unlock
dkxb 106971c
Extract defer_lock_t.v
pgiarrusso-sl 8bb2827
Sketch of the lockable concept
gmalecha-at-skylabs 82c27ac
Unbundle CFracSplittable
pgiarrusso-sl 0368ecb
Tweak type signatures
pgiarrusso-sl 821b626
Generic unique_lock.R: fix Typed instance
pgiarrusso-sl d039f74
Add TODOs
pgiarrusso-sl 6322dc7
BasicLockable: Add TODO on Hint Mode
pgiarrusso-sl a18a8e3
Make Arguments #{global]
pgiarrusso-sl 485d425
unique_lock_generic: add side conditions to cfracsplittable
pgiarrusso-sl c37a947
attempt on instantiating BasicLockable interface for mutex (doesn't b…
pgiarrusso-sl 792280b
Candidate BasicLockable instance with problems
dkxb 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| Require Import skylabs.auto.cpp.prelude.proof. | ||
|
|
||
| (** This file captures the following "named requirements": | ||
| - [BasicLockable](https://cppreference.com/cpp/named_req/BasicLockable) | ||
| - [Lockable](https://cppreference.com/cpp/named_req/Lockable) | ||
|
|
||
| It proposes a pattern for capturing these using Rocq typeclasses such | ||
| that clients can use these to depend on | ||
| *) | ||
|
|
||
| Section with_cpp. | ||
| Context `{Σ : cpp_logic} {σ : genv}. | ||
|
|
||
| (* NOTE: This is *not* meant to be a statement about the way that | ||
| things should be packaged (bundled or unbundled), just a demonstration | ||
| of the way that specifications can be written in a higher-order way. | ||
| *) | ||
|
|
||
| (** This captures [BasicLockable](https://cppreference.com/cpp/named_req/BasicLockable) *) | ||
| Class BasicLockable (ty : type) {T : Type} (R : cQp.t -> T -> Rep) : Type := | ||
| { do_lock : ptr -> T -> mpred -> mpred | ||
| (* the WP for <ty::lock()> *) | ||
| ; do_unlock : ptr -> T -> mpred -> mpred | ||
| (* the WP for <ty::unlock()> *) | ||
| }. | ||
| (** TODO: consider adding a Hint Mode*) | ||
| (* | ||
| #[global] Hint Mode BasicLockable ! - ! : typeclass_instances. | ||
| #[global] Arguments do_lock ty {T} R {BL} _ _ _ : rename. | ||
| #[global] Arguments do_unlock ty {T} R {BL} _ _ _ : rename. | ||
| *) | ||
|
|
||
| Section with_BasicLockable. | ||
| Context (ty : type) {T: Type} (R : cQp.t -> T -> Rep) {BL : BasicLockable ty R}. | ||
|
|
||
| Definition lock_basic_lockable : ptr -> WpSpec mpred val val := | ||
| (\this this | ||
| \prepost{q m} this |-> R q m | ||
| \pre{K} do_lock this m K | ||
| \post K). | ||
|
|
||
| Definition unlock_basic_lockable : ptr -> WpSpec mpred val val := | ||
| (\this this | ||
| \prepost{q m} this |-> R q m | ||
| \pre{K} do_unlock this m K | ||
| \post K). | ||
| End with_BasicLockable. | ||
|
|
||
| (** This captures [Lockable](https://cppreference.com/cpp/named_req/Lockable) *) | ||
| Class Lockable (ty : type) {T : Type} (R : cQp.t -> T -> Rep) {BASIC_LOCKABLE : BasicLockable ty R} : Type := | ||
| { do_try_lock : ptr -> T -> (bool -> mpred) -> mpred }. | ||
| (* TODO: Hint Mode here too. *) | ||
|
|
||
| Section with_Lockable. | ||
| Context (ty : type) {T : Type} (R : cQp.t -> T -> Rep) `{LOCKABLE : Lockable (T:=T) ty R}. | ||
|
|
||
| Definition try_lock_lockable : ptr -> WpSpec mpred val val := | ||
| (\this this | ||
| \prepost{q m} this |-> R q m | ||
| \pre{K} do_try_lock this m K | ||
| \post{r}[Vbool r] K r). | ||
| End with_Lockable. | ||
|
|
||
| End with_cpp. |
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 |
|---|---|---|
| @@ -1,5 +1,8 @@ | ||
| Require Export skylabs.brick.libstdcpp.mutex.spec.mutex. | ||
| (* Export all specifications. | ||
| Keep them listed in alphabetical order. *) | ||
| Require Export skylabs.brick.libstdcpp.mutex.spec.defer_lock_t. | ||
| Require Export skylabs.brick.libstdcpp.mutex.spec.lock_guard. | ||
| Require Export skylabs.brick.libstdcpp.mutex.spec.mutex. | ||
| Require Export skylabs.brick.libstdcpp.mutex.spec.recursive_mutex. | ||
| Require Export skylabs.brick.libstdcpp.mutex.spec.scoped_lock. | ||
| Require Export skylabs.brick.libstdcpp.mutex.spec.unique_lock. |
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,23 @@ | ||
| Require Import skylabs.auto.cpp.prelude.proof. | ||
| Require Import skylabs.brick.libstdcpp.mutex.inc_hpp. | ||
|
|
||
| Module defer_lock_t. | ||
| Section with_cpp. | ||
| Context `{Σ : cpp_logic, σ : genv}. | ||
|
|
||
| Parameter R : forall {σ : genv}, cQp.t -> Rep. | ||
| #[only(cfracsplittable, type_ptr="std::defer_lock_t")] derive R. | ||
|
|
||
| cpp.spec "std::defer_lock_t::defer_lock_t(const std::defer_lock_t&)" as defer_lock_copy_ctor_spec from source with ( | ||
| \this this | ||
| \arg{other} "other" (Vptr other) | ||
| \prepost{q} other |-> R q | ||
| \post this |-> R 1$m | ||
| ). | ||
| cpp.spec "std::defer_lock_t::~defer_lock_t()" as defer_lock_dtor_spec from source with ( | ||
| \this this | ||
| \pre this |-> R 1$m | ||
| \post emp | ||
| ). | ||
| End with_cpp. | ||
| End defer_lock_t. |
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
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.
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.
This instance is awkward and makes us wonder about the interface.