-
Notifications
You must be signed in to change notification settings - Fork 2
refactor: fix Miri violations and improve concurrency safety #22
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
Conversation
- Replace `Box` with `AliasableBox` to ensure pointer stability. - Use `AtomicU32` for `refcnt` and `UnsafeCell` for value storage in `State`. - Store raw pointers in `Entry` guards instead of `&mut` references to avoid Stacked Borrows violations during concurrent atomic operations. - Implement `Sync` for `State<V>` to explicitly define thread safety. - Update `README.md` to reflect that Miri tests now pass. - Optimize test constants for faster Miri execution.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #22 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 3 3
Lines 870 892 +22
=========================================
+ Hits 870 892 +22 ☔ View full report in Codecov by Sentry. |
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.
Pull request overview
This PR refactors the internal concurrency implementation to fix Miri violations related to Stacked Borrows and improve thread safety guarantees. The changes replace Box with AliasableBox for pointer stability, use AtomicU32 for reference counting, wrap values in UnsafeCell, and store raw pointers instead of mutable references in entry guards.
- Replaced
Box<State<V>>withAliasableBox<State<V>>to ensure heap stability when obtaining raw pointers - Changed
Stateto useAtomicU32forrefcntandUnsafeCellfor value storage to properly express interior mutability - Modified entry guards (
EntryByVal,EntryByRef) to store raw pointers instead of mutable references, avoiding Stacked Borrows violations during concurrent atomic operations - Added Miri testing to CI and optimized test constants for faster Miri execution
Reviewed changes
Copilot reviewed 4 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/lockmap.rs | Core refactoring: replaced Box with AliasableBox, added AtomicU32/UnsafeCell for State, changed entry guards to use raw pointers, added explicit Sync implementations, and optimized test constants for Miri |
| src/shards_map.rs | Removed trailing whitespace from documentation |
| src/futex.rs | Removed trailing whitespace from documentation |
| README.md | Removed FAQ section explaining Miri violations since they are now fixed |
| Cargo.toml | Added aliasable dependency version 0.1.3 |
| .github/workflows/rust.yml | Added new Miri CI job to run tests under Miri |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
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.
Pull request overview
Copilot reviewed 4 out of 6 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
May I ask why you're using a custom |
What I actually need is |
|
Ah, due to poisoning I assume? That makes sense. I think I was also wondering why you made In general, I was wondering what the purpose of |
Under the checking rules of
As for the |
|
Oh, I see now. The callbacks receive
Ah, I didn't realize there are two consumers.
Hmm, isn't this a race condition? If thread A That is, shouldn't the calls to global I think this is only ever a problem during removal, so the idea is something like "if the entry should remain present, only decrement refcount + unlock the entry; if the entry should be absent, only remove it from the map under a global lock". |
That makes sense, I'll give it a try. Done in #24. |
BoxwithAliasableBoxto ensure pointer stability.AtomicU32forrefcntandUnsafeCellfor value storage inState.Entryguards instead of&mutreferences to avoid Stacked Borrows violations during concurrent atomic operations.SyncforState<V>to explicitly define thread safety.README.mdto reflect that Miri tests now pass.