Skip to content

New ghost state for mutex spec & implementation; give up user ghost state. - #173

Draft
dkxb wants to merge 47 commits into
mainfrom
ke/mutex_impl
Draft

dkxb wants to merge 47 commits into
mainfrom
ke/mutex_impl

Conversation

@dkxb

@dkxb dkxb commented Sep 9, 2026

Copy link
Copy Markdown
Collaborator

Conflicts with #167; maybe easiest to cherry pick from #167 and then close #167 at this point.

Currently, only rocq-brick-libstdcpp/proof/mutex/spec/mutex.v and rocq-brick-libstdcpp/test/mutex/custom_mutex_hpp_proof.v compile.

There are so many commits, and it might be easier to review the diff of the two branches instead of reading the commits.

The changes mostly include these aspects:

  1. A MUTEX_PREDS interface, which includes predicates that mutex specs need and some of their rules. The proof that the mutex custom implementation meets the spec cannot solely depend on the interface; e.g., the instantiation of not_locked includes points-to of m_owner, and it needs to be exposed during verification.
  2. The instantiation of MUTEX_PREDS include 3 ghost state modules (defined in lock_ghost2.v, see comments in the file for how these modules work):
    • MUTEX_TOKENS defines token/given_token. This is for making sure no thread is holding the lock when destructor is called.
    • MUTEX_SETS defines my_mutexes for making sure a thread only gets resource once from a mutex invariant before it unlocks.
    • OWNER_TID for remembering the owner thread ID of the mutex.

@skylabs-ai-ci

skylabs-ai-ci Bot commented Sep 9, 2026

Copy link
Copy Markdown

CI summary (Details)

Active Repos

Repo Job Branch Job Commit Branch Tip Base branch Base commit PR
fmdeps/brick-libcpp/ ke/mutex_impl 72b7dde e4cbb0f main be863c8 #173

Passive Repos

Repo Job Branch Job Commit
./ main db1581e
fmdeps/BRiCk/ main e819c36
fmdeps/auto/ main bc4c71e
fmdeps/auto-docs/ main 6490c5f
bluerock/NOVA/ skylabs-proof f3533d2
bluerock/bhv/ skylabs-main e37df58
fmdeps/ci/ main e1ec839
vendored/elpi/ skylabs-master c0b9653
vendored/flocq/ skylabs-master cf9cc84
vendored/rocq/ skylabs-master bef7df5
fmdeps/rocq-agent-toolkit/ main 227bb83
vendored/rocq-elpi/ skylabs-master 7dee592
vendored/rocq-equations/ skylabs-main 9cf8471
vendored/rocq-iris/ skylabs-master a7af9f7
vendored/rocq-lsp/ skylabs-main 64ef78a
vendored/rocq-stdlib/ skylabs-master 00897b3
vendored/rocq-stdpp/ skylabs-master 0c5e505
fmdeps/skylabs-fm/ main 5c3d0ab
vendored/vsrocq/ skylabs-main ee79e7a

Changes in Warnings or Errors

Before New Fixed After
Errors 0 ${\color{red}7}$ 0 7
Warnings 91 ${\color{red}2}$ ${\color{green}2}$ 91

Performance

Relative Master MR Change Filename
+0.96% 198198.0 200098.2 +1900.2 total
-0.52% 1048.1 - -1048.1 ├ disappeared files (13)
+1.46% - 2936.7 +2936.7 ├ newly appeared files (10)
+0.01% 197149.8 197161.5 +11.7 └ common files
-0.00% 53108.6 53108.4 -0.2 ├ translation units
+0.01% 144041.3 144053.2 +11.9 └ proofs and tests
Full Results
Relative Master MR Change Filename
+41.01% 31.2 44.0 +12.8 fmdeps/brick-libcpp/rocq-brick-libstdcpp/proof/mutex/spec/mutex.v
+0.96% 198198.0 200098.2 +1900.2 total
-0.52% 1048.1 - -1048.1 ├ disappeared files (13)
+1.46% - 2936.7 +2936.7 ├ newly appeared files (10)
+0.01% 197149.8 197161.5 +11.7 └ common files
-0.00% 53108.6 53108.4 -0.2 ├ translation units
+0.01% 144041.3 144053.2 +11.9 └ proofs and tests

pgiarrusso-sl and others added 12 commits September 10, 2026 18:07
mutex.v now depends on a ghost state module
defined in lock_ghosts2.v instead of the user
ghost state. The usage is demonstrated in
custom_mutex_hpp_proof.v. It has 3 pieces:
- my_mutexes records the set of invariant gnames
  acquired by a thread, and should be allocated
  by spawn(). A singleton set should be given to
  a mutex invariant in exchange for the protected
  resources in it.
- a pair of token/given_token. A thread acquiring
  the resource stores a fraction of token inside
  the invariant and gets back the same fraction of
  given_token; destructing lock requires the
  entire token and thus no thread can hold the
  lock.
- a o_owner_tid, recording the thread ID of the
  current lock owner. The auth piece is in inv and
  frag is held by the current lock owner.
(mp : ptr * mutex.gname * Qp * Qp) (q : cQp.t) (P : mpred) : Rep :=
structR "std::lock_guard<std::mutex>" q **
let '(mp, g, q') := mp in
let '(mp, g, q', _) := mp in

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why are we adding a fraction that we're throwing away.

@skylabs-ai-ci

skylabs-ai-ci Bot commented Sep 10, 2026

Copy link
Copy Markdown

CI summary (Details)

Active Repos

Repo Job Branch Job Commit Branch Tip Base branch Base commit PR
fmdeps/brick-libcpp/ ke/mutex_impl 7f96c5d 250308e main be863c8 #173

Passive Repos

Repo Job Branch Job Commit
./ main db1581e
fmdeps/BRiCk/ main e819c36
fmdeps/auto/ main 0d2d68d
fmdeps/auto-docs/ main 6490c5f
bluerock/NOVA/ skylabs-proof f3533d2
bluerock/bhv/ skylabs-main e37df58
fmdeps/ci/ main e1ec839
vendored/elpi/ skylabs-master c0b9653
vendored/flocq/ skylabs-master cf9cc84
vendored/rocq/ skylabs-master bef7df5
fmdeps/rocq-agent-toolkit/ main 227bb83
vendored/rocq-elpi/ skylabs-master 7dee592
vendored/rocq-equations/ skylabs-main 9cf8471
vendored/rocq-iris/ skylabs-master a7af9f7
vendored/rocq-lsp/ skylabs-main 64ef78a
vendored/rocq-stdlib/ skylabs-master 00897b3
vendored/rocq-stdpp/ skylabs-master 0c5e505
fmdeps/skylabs-fm/ main 5c3d0ab
vendored/vsrocq/ skylabs-main ee79e7a

Changes in Warnings or Errors

Before New Fixed After
Errors 0 ${\color{red}7}$ 0 7
Warnings 91 ${\color{red}2}$ ${\color{green}2}$ 91

Performance

Relative Master MR Change Filename
+0.96% 198220.5 200120.6 +1900.1 total
-0.52% 1048.2 - -1048.2 ├ disappeared files (13)
+1.46% - 2936.7 +2936.7 ├ newly appeared files (10)
+0.01% 197172.3 197183.9 +11.7 └ common files
-0.00% 53108.6 53108.4 -0.2 ├ translation units
+0.01% 144063.7 144075.6 +11.9 └ proofs and tests
Full Results
Relative Master MR Change Filename
-1.95% 51.3 50.3 -1.0 fmdeps/brick-libcpp/rocq-brick-libstdcpp/proof/mutex/proof/unique_lock_recursive_mutex.v
+41.01% 31.2 44.0 +12.8 fmdeps/brick-libcpp/rocq-brick-libstdcpp/proof/mutex/spec/mutex.v
+0.96% 198220.5 200120.6 +1900.1 total
-0.52% 1048.2 - -1048.2 ├ disappeared files (13)
+1.46% - 2936.7 +2936.7 ├ newly appeared files (10)
+0.01% 197172.3 197183.9 +11.7 └ common files
-0.00% 53108.6 53108.4 -0.2 ├ translation units
+0.01% 144063.7 144075.6 +11.9 └ proofs and tests

(** Specialize the reusable specs to the standard mutex representation and
bind them to their C++ names. *)
Module StdMutex (Preds : MUTEX_PREDS with Definition cpp_ty := "std::mutex"%cpp_type).
Include Preds.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Worth a closer look.

Include Preds.
#[global] Hint Opaque token not_locked locked R : sl_opacity.

Module Spec := mutex_spec Preds.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Worth a closer look.


Initializing [this |-> R old 1$m emp] probably depends on the mutex
implementation. *)
Parameter init_R : forall (this : ptr) (old : gname)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Conventionally, things in Prop are Axiom and things in Type are Parameters.

Suggested change
Parameter init_R : forall (this : ptr) (old : gname)
Axiom init_R : forall (this : ptr) (old : gname)

(** Register a thread by consuming its handle for this mutex's namespace
and its token share. [my_mutexes_alloc_mutex_name] splits this handle
from the full namespace pool supplied when the thread is spawned. *)
Parameter register_thread : forall

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
Parameter register_thread : forall
Axiom register_thread : forall

try_lock_lockable cpp_ty (fun q gP => R gP.1 q gP.2).

Lemma try_lock_spec_equiv_try_lock_spec_alt
(Htry_lock : requirements.do_try_lock cpp_ty = do_try_lock) this xs K :

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Htry_lock seems odd — this should just be unfolding mutex_lockable?

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