Skip to content

RwLock#303

Merged
rikosellic merged 69 commits intoasterinas:mainfrom
rikosellic:RwLock-invariants
Mar 6, 2026
Merged

RwLock#303
rikosellic merged 69 commits intoasterinas:mainfrom
rikosellic:RwLock-invariants

Conversation

@rikosellic
Copy link
Collaborator

KVerus Prompt:
You need to add the type invariant of RWLock in ostd\src\sync\rwlock.rs, which is defined in the function closed spec fn wf(self) -> bool.

The RwLock structure's lock field has the type of lock: AtomicUsize<_, Option<RwFrac<T>>,_>,, which extends the ordinary atomic usize with a ghost RwFrac permission. The RWFrac type is an alias of type Frac<pcell::PointsTo<T>,MAX_READER_U64>. Frac is the classical fraction permission, whose definition can be found in vstd/tokens/frac.rs; pcell::PointsTo is the permission to access a cell, which is defined in vstd/cell/pcell.rs.

You should analyze the behaviour of the SpinLock methods (commented in the same file), including new, read, write, upread, try_read, try_write, try_upread, and write the correct invariant between the AtomicaUsize's value and the ghost RwFrac permission. To learn the syntax of the invariant and how it is used, you can refer to the SpinLock inostd\src\sync\spin.rs as an example.

@rikosellic
Copy link
Collaborator Author

Very interesting, I will check it later.

@rikosellic rikosellic added exec code Proofs about execution code AI-assist AI-aided proof or generation labels Feb 9, 2026
@rikosellic
Copy link
Collaborator Author

rikosellic commented Feb 24, 2026

There are two issues in the code transformed by KVerus:

  • It added & before self.lock, which should be consistent with the source code.
  • It extracted the atomic_with_ghost into a separate assignment, which is actually unnecessary for compilation because one can directly use it in the if expression.

@rikosellic rikosellic changed the title RwLock invariant RwLock Mar 3, 2026
@rikosellic rikosellic marked this pull request as ready for review March 6, 2026 07:21
@rikosellic rikosellic merged commit 10a97de into asterinas:main Mar 6, 2026
3 checks passed
@rikosellic rikosellic deleted the RwLock-invariants branch March 6, 2026 07:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AI-assist AI-aided proof or generation exec code Proofs about execution code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants