Skip to content

Commit

Permalink
Fix Miri tests
Browse files Browse the repository at this point in the history
- Miri was catching what I now know to be a legitimate leak, so I've
  fixed that.
- The deadlock doesn't appear to be legitimate; replacing the futures
  with their blocking equivalents passes. I've marked these tests as
  skipped on MIRI for now.

Signed-off-by: John Nunley <dev@notgull.net>
  • Loading branch information
notgull committed Jan 31, 2024
1 parent d28bdb0 commit 1d97f8a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
11 changes: 8 additions & 3 deletions src/rwlock/futures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -426,13 +426,18 @@ pin_project_lite::pin_project! {
impl<T: ?Sized> PinnedDrop for UpgradeArcInner<T> {
fn drop(this: Pin<&mut Self>) {
let this = this.project();
if !this.raw.is_ready() {
let is_ready = this.raw.is_ready();

// SAFETY: The drop impl for raw assumes that it is pinned.
unsafe {
ManuallyDrop::drop(this.raw.get_unchecked_mut());
}

if !is_ready {
// SAFETY: we drop the `Arc` (decrementing the reference count)
// only if this future was cancelled before returning an
// upgraded lock.
unsafe {
// SAFETY: The drop impl for raw assumes that it is pinned.
ManuallyDrop::drop(this.raw.get_unchecked_mut());
ManuallyDrop::drop(this.lock);
};
}
Expand Down
6 changes: 4 additions & 2 deletions tests/rwlock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ fn get_mut() {
assert_eq!(lock.into_inner(), 20);
}

#[cfg(not(target_family = "wasm"))]
// Miri bug; this works when async is replaced with blocking
#[cfg(not(any(target_family = "wasm", miri)))]
#[test]
fn contention() {
const N: u32 = 10;
Expand Down Expand Up @@ -154,7 +155,8 @@ fn contention() {
});
}

#[cfg(not(target_family = "wasm"))]
// Miri bug; this works when async is replaced with blocking
#[cfg(not(any(target_family = "wasm", miri)))]
#[test]
fn contention_arc() {
const N: u32 = 10;
Expand Down

0 comments on commit 1d97f8a

Please sign in to comment.