Skip to content

Commit 3ecb70f

Browse files
bors[bot]taiki-e
andauthored
Merge #870
870: Fix miri test failure r=taiki-e a=taiki-e Split the non-breaking part from #796. Co-authored-by: Taiki Endo <[email protected]>
2 parents 4b949c2 + 1390418 commit 3ecb70f

File tree

14 files changed

+60
-22
lines changed

14 files changed

+60
-22
lines changed

crossbeam-channel/tests/golang.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1580,9 +1580,7 @@ mod race_chan_test {
15801580
}
15811581

15821582
// https://github.com/golang/go/blob/master/test/ken/chan.go
1583-
#[cfg(not(miri))] // Miri is too slow
15841583
mod chan {
1585-
15861584
use super::*;
15871585

15881586
const MESSAGES_PER_CHANEL: u32 = 76;
@@ -2052,6 +2050,7 @@ mod chan {
20522050
}
20532051

20542052
#[test]
2053+
#[cfg_attr(miri, ignore)] // Miri is too slow
20552054
fn main() {
20562055
let mut ctx = Context {
20572056
nproc: Arc::new(Mutex::new(0)),

crossbeam-channel/tests/list.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ fn len_empty_full() {
6767
}
6868

6969
#[test]
70+
#[cfg_attr(miri, ignore)] // this test makes timing assumptions, but Miri is so slow it violates them
7071
fn try_recv() {
7172
let (s, r) = unbounded();
7273

crossbeam-channel/tests/select.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,6 @@ fn both_ready() {
408408
.unwrap();
409409
}
410410

411-
#[cfg_attr(miri, ignore)] // Miri is too slow
412411
#[test]
413412
fn loop_try() {
414413
const RUNS: usize = 20;

crossbeam-channel/tests/select_macro.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,6 @@ fn both_ready() {
284284
.unwrap();
285285
}
286286

287-
#[cfg_attr(miri, ignore)] // Miri is too slow
288287
#[test]
289288
fn loop_try() {
290289
const RUNS: usize = 20;

crossbeam-channel/tests/zero.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -328,9 +328,11 @@ fn stress_oneshot() {
328328
}
329329
}
330330

331-
#[cfg_attr(miri, ignore)] // Miri is too slow
332331
#[test]
333332
fn stress_iter() {
333+
#[cfg(miri)]
334+
const COUNT: usize = 50;
335+
#[cfg(not(miri))]
334336
const COUNT: usize = 1000;
335337

336338
let (request_s, request_r) = bounded(0);
@@ -485,7 +487,7 @@ fn fairness() {
485487
#[test]
486488
fn fairness_duplicates() {
487489
#[cfg(miri)]
488-
const COUNT: usize = 50;
490+
const COUNT: usize = 100;
489491
#[cfg(not(miri))]
490492
const COUNT: usize = 10_000;
491493

crossbeam-deque/src/deque.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::cmp;
33
use std::fmt;
44
use std::iter::FromIterator;
55
use std::marker::PhantomData;
6-
use std::mem::{self, MaybeUninit};
6+
use std::mem::{self, ManuallyDrop, MaybeUninit};
77
use std::ptr;
88
use std::sync::atomic::{self, AtomicIsize, AtomicPtr, AtomicUsize, Ordering};
99
use std::sync::Arc;
@@ -38,9 +38,8 @@ impl<T> Buffer<T> {
3838
fn alloc(cap: usize) -> Buffer<T> {
3939
debug_assert_eq!(cap, cap.next_power_of_two());
4040

41-
let mut v = Vec::with_capacity(cap);
41+
let mut v = ManuallyDrop::new(Vec::with_capacity(cap));
4242
let ptr = v.as_mut_ptr();
43-
mem::forget(v);
4443

4544
Buffer { ptr, cap }
4645
}

crossbeam-epoch/src/atomic.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,7 @@ impl<T> Atomic<T> {
305305
/// use crossbeam_epoch::Atomic;
306306
///
307307
/// let a = Atomic::new(1234);
308+
/// # unsafe { drop(a.into_owned()); } // avoid leak
308309
/// ```
309310
pub fn new(init: T) -> Atomic<T> {
310311
Self::init(init)
@@ -320,6 +321,7 @@ impl<T: ?Sized + Pointable> Atomic<T> {
320321
/// use crossbeam_epoch::Atomic;
321322
///
322323
/// let a = Atomic::<i32>::init(1234);
324+
/// # unsafe { drop(a.into_owned()); } // avoid leak
323325
/// ```
324326
pub fn init(init: T::Init) -> Atomic<T> {
325327
Self::from(Owned::init(init))
@@ -373,6 +375,7 @@ impl<T: ?Sized + Pointable> Atomic<T> {
373375
/// let a = Atomic::new(1234);
374376
/// let guard = &epoch::pin();
375377
/// let p = a.load(SeqCst, guard);
378+
/// # unsafe { drop(a.into_owned()); } // avoid leak
376379
/// ```
377380
pub fn load<'g>(&self, ord: Ordering, _: &'g Guard) -> Shared<'g, T> {
378381
unsafe { Shared::from_usize(self.data.load(ord)) }
@@ -398,6 +401,7 @@ impl<T: ?Sized + Pointable> Atomic<T> {
398401
/// let a = Atomic::new(1234);
399402
/// let guard = &epoch::pin();
400403
/// let p = a.load_consume(guard);
404+
/// # unsafe { drop(a.into_owned()); } // avoid leak
401405
/// ```
402406
pub fn load_consume<'g>(&self, _: &'g Guard) -> Shared<'g, T> {
403407
unsafe { Shared::from_usize(self.data.load_consume()) }
@@ -415,8 +419,10 @@ impl<T: ?Sized + Pointable> Atomic<T> {
415419
/// use std::sync::atomic::Ordering::SeqCst;
416420
///
417421
/// let a = Atomic::new(1234);
422+
/// # unsafe { drop(a.load(SeqCst, &crossbeam_epoch::pin()).into_owned()); } // avoid leak
418423
/// a.store(Shared::null(), SeqCst);
419424
/// a.store(Owned::new(1234), SeqCst);
425+
/// # unsafe { drop(a.into_owned()); } // avoid leak
420426
/// ```
421427
pub fn store<P: Pointer<T>>(&self, new: P, ord: Ordering) {
422428
self.data.store(new.into_usize(), ord);
@@ -437,6 +443,7 @@ impl<T: ?Sized + Pointable> Atomic<T> {
437443
/// let a = Atomic::new(1234);
438444
/// let guard = &epoch::pin();
439445
/// let p = a.swap(Shared::null(), SeqCst, guard);
446+
/// # unsafe { drop(p.into_owned()); } // avoid leak
440447
/// ```
441448
pub fn swap<'g, P: Pointer<T>>(&self, new: P, ord: Ordering, _: &'g Guard) -> Shared<'g, T> {
442449
unsafe { Shared::from_usize(self.data.swap(new.into_usize(), ord)) }
@@ -471,6 +478,7 @@ impl<T: ?Sized + Pointable> Atomic<T> {
471478
/// let curr = a.load(SeqCst, guard);
472479
/// let res1 = a.compare_exchange(curr, Shared::null(), SeqCst, SeqCst, guard);
473480
/// let res2 = a.compare_exchange(curr, Owned::new(5678), SeqCst, SeqCst, guard);
481+
/// # unsafe { drop(curr.into_owned()); } // avoid leak
474482
/// ```
475483
pub fn compare_exchange<'g, P>(
476484
&self,
@@ -526,6 +534,7 @@ impl<T: ?Sized + Pointable> Atomic<T> {
526534
///
527535
/// let mut new = Owned::new(5678);
528536
/// let mut ptr = a.load(SeqCst, guard);
537+
/// # unsafe { drop(a.load(SeqCst, guard).into_owned()); } // avoid leak
529538
/// loop {
530539
/// match a.compare_exchange_weak(ptr, new, SeqCst, SeqCst, guard) {
531540
/// Ok(p) => {
@@ -546,6 +555,7 @@ impl<T: ?Sized + Pointable> Atomic<T> {
546555
/// Err(err) => curr = err.current,
547556
/// }
548557
/// }
558+
/// # unsafe { drop(curr.into_owned()); } // avoid leak
549559
/// ```
550560
pub fn compare_exchange_weak<'g, P>(
551561
&self,
@@ -608,6 +618,7 @@ impl<T: ?Sized + Pointable> Atomic<T> {
608618
///
609619
/// let res2 = a.fetch_update(SeqCst, SeqCst, guard, |x| None);
610620
/// assert!(res2.is_err());
621+
/// # unsafe { drop(a.into_owned()); } // avoid leak
611622
/// ```
612623
pub fn fetch_update<'g, F>(
613624
&self,
@@ -666,6 +677,7 @@ impl<T: ?Sized + Pointable> Atomic<T> {
666677
/// let curr = a.load(SeqCst, guard);
667678
/// let res1 = a.compare_and_set(curr, Shared::null(), SeqCst, guard);
668679
/// let res2 = a.compare_and_set(curr, Owned::new(5678), SeqCst, guard);
680+
/// # unsafe { drop(curr.into_owned()); } // avoid leak
669681
/// ```
670682
// TODO: remove in the next major version.
671683
#[allow(deprecated)]
@@ -723,6 +735,7 @@ impl<T: ?Sized + Pointable> Atomic<T> {
723735
///
724736
/// let mut new = Owned::new(5678);
725737
/// let mut ptr = a.load(SeqCst, guard);
738+
/// # unsafe { drop(a.load(SeqCst, guard).into_owned()); } // avoid leak
726739
/// loop {
727740
/// match a.compare_and_set_weak(ptr, new, SeqCst, guard) {
728741
/// Ok(p) => {
@@ -743,6 +756,7 @@ impl<T: ?Sized + Pointable> Atomic<T> {
743756
/// Err(err) => curr = err.current,
744757
/// }
745758
/// }
759+
/// # unsafe { drop(curr.into_owned()); } // avoid leak
746760
/// ```
747761
// TODO: remove in the next major version.
748762
#[allow(deprecated)]
@@ -925,6 +939,7 @@ impl<T: ?Sized + Pointable> From<Owned<T>> for Atomic<T> {
925939
/// use crossbeam_epoch::{Atomic, Owned};
926940
///
927941
/// let a = Atomic::<i32>::from(Owned::new(1234));
942+
/// # unsafe { drop(a.into_owned()); } // avoid leak
928943
/// ```
929944
fn from(owned: Owned<T>) -> Self {
930945
let data = owned.data;
@@ -1108,6 +1123,7 @@ impl<T: ?Sized + Pointable> Owned<T> {
11081123
/// let o = Owned::new(1234);
11091124
/// let guard = &epoch::pin();
11101125
/// let p = o.into_shared(guard);
1126+
/// # unsafe { drop(p.into_owned()); } // avoid leak
11111127
/// ```
11121128
#[allow(clippy::needless_lifetimes)]
11131129
pub fn into_shared<'g>(self, _: &'g Guard) -> Shared<'g, T> {
@@ -1291,6 +1307,7 @@ impl<'g, T> Shared<'g, T> {
12911307
/// let guard = &epoch::pin();
12921308
/// let p = a.load(SeqCst, guard);
12931309
/// assert_eq!(p.as_raw(), raw);
1310+
/// # unsafe { drop(a.into_owned()); } // avoid leak
12941311
/// ```
12951312
pub fn as_raw(&self) -> *const T {
12961313
let (raw, _) = decompose_tag::<T>(self.data);
@@ -1329,6 +1346,7 @@ impl<'g, T: ?Sized + Pointable> Shared<'g, T> {
13291346
/// assert!(a.load(SeqCst, guard).is_null());
13301347
/// a.store(Owned::new(1234), SeqCst);
13311348
/// assert!(!a.load(SeqCst, guard).is_null());
1349+
/// # unsafe { drop(a.into_owned()); } // avoid leak
13321350
/// ```
13331351
pub fn is_null(&self) -> bool {
13341352
let (raw, _) = decompose_tag::<T>(self.data);
@@ -1365,6 +1383,7 @@ impl<'g, T: ?Sized + Pointable> Shared<'g, T> {
13651383
/// unsafe {
13661384
/// assert_eq!(p.deref(), &1234);
13671385
/// }
1386+
/// # unsafe { drop(a.into_owned()); } // avoid leak
13681387
/// ```
13691388
pub unsafe fn deref(&self) -> &'g T {
13701389
let (raw, _) = decompose_tag::<T>(self.data);
@@ -1406,6 +1425,7 @@ impl<'g, T: ?Sized + Pointable> Shared<'g, T> {
14061425
/// unsafe {
14071426
/// assert_eq!(p.deref(), &vec![1, 2, 3, 4, 5]);
14081427
/// }
1428+
/// # unsafe { drop(a.into_owned()); } // avoid leak
14091429
/// ```
14101430
pub unsafe fn deref_mut(&mut self) -> &'g mut T {
14111431
let (raw, _) = decompose_tag::<T>(self.data);
@@ -1442,6 +1462,7 @@ impl<'g, T: ?Sized + Pointable> Shared<'g, T> {
14421462
/// unsafe {
14431463
/// assert_eq!(p.as_ref(), Some(&1234));
14441464
/// }
1465+
/// # unsafe { drop(a.into_owned()); } // avoid leak
14451466
/// ```
14461467
pub unsafe fn as_ref(&self) -> Option<&'g T> {
14471468
let (raw, _) = decompose_tag::<T>(self.data);
@@ -1493,6 +1514,7 @@ impl<'g, T: ?Sized + Pointable> Shared<'g, T> {
14931514
/// let guard = &epoch::pin();
14941515
/// let p = a.load(SeqCst, guard);
14951516
/// assert_eq!(p.tag(), 2);
1517+
/// # unsafe { drop(a.into_owned()); } // avoid leak
14961518
/// ```
14971519
pub fn tag(&self) -> usize {
14981520
let (_, tag) = decompose_tag::<T>(self.data);
@@ -1516,6 +1538,7 @@ impl<'g, T: ?Sized + Pointable> Shared<'g, T> {
15161538
/// assert_eq!(p1.tag(), 0);
15171539
/// assert_eq!(p2.tag(), 2);
15181540
/// assert_eq!(p1.as_raw(), p2.as_raw());
1541+
/// # unsafe { drop(a.into_owned()); } // avoid leak
15191542
/// ```
15201543
pub fn with_tag(&self, tag: usize) -> Shared<'g, T> {
15211544
unsafe { Self::from_usize(compose_tag::<T>(self.data, tag)) }
@@ -1536,6 +1559,7 @@ impl<T> From<*const T> for Shared<'_, T> {
15361559
///
15371560
/// let p = Shared::from(Box::into_raw(Box::new(1234)) as *const _);
15381561
/// assert!(!p.is_null());
1562+
/// # unsafe { drop(p.into_owned()); } // avoid leak
15391563
/// ```
15401564
fn from(raw: *const T) -> Self {
15411565
let raw = raw as usize;

crossbeam-epoch/src/collector.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -402,10 +402,10 @@ mod tests {
402402
v.push(i as i32);
403403
}
404404

405-
let ptr = v.as_mut_ptr() as usize;
405+
let ptr = v.as_mut_ptr();
406406
let len = v.len();
407407
guard.defer_unchecked(move || {
408-
drop(Vec::from_raw_parts(ptr as *const i32 as *mut i32, len, len));
408+
drop(Vec::from_raw_parts(ptr, len, len));
409409
DESTROYS.fetch_add(len, Ordering::Relaxed);
410410
});
411411
guard.flush();

crossbeam-epoch/src/guard.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ use crate::internal::Local;
4646
/// if let Some(num) = unsafe { p.as_ref() } {
4747
/// println!("The number is {}.", num);
4848
/// }
49+
/// # unsafe { drop(a.into_owned()); } // avoid leak
4950
/// ```
5051
///
5152
/// # Multiple guards
@@ -184,6 +185,7 @@ impl Guard {
184185
/// });
185186
/// }
186187
/// }
188+
/// # unsafe { drop(a.into_owned()); } // avoid leak
187189
/// ```
188190
pub unsafe fn defer_unchecked<F, R>(&self, f: F)
189191
where
@@ -263,6 +265,7 @@ impl Guard {
263265
/// guard.defer_destroy(p);
264266
/// }
265267
/// }
268+
/// # unsafe { drop(a.into_owned()); } // avoid leak
266269
/// ```
267270
pub unsafe fn defer_destroy<T>(&self, ptr: Shared<'_, T>) {
268271
self.defer_unchecked(move || ptr.into_owned());
@@ -320,6 +323,7 @@ impl Guard {
320323
/// let p = a.load(SeqCst, &guard);
321324
/// assert_eq!(unsafe { p.as_ref() }, Some(&777));
322325
/// }
326+
/// # unsafe { drop(a.into_owned()); } // avoid leak
323327
/// ```
324328
pub fn repin(&mut self) {
325329
if let Some(local) = unsafe { self.local.as_ref() } {
@@ -356,6 +360,7 @@ impl Guard {
356360
/// let p = a.load(SeqCst, &guard);
357361
/// assert_eq!(unsafe { p.as_ref() }, Some(&777));
358362
/// }
363+
/// # unsafe { drop(a.into_owned()); } // avoid leak
359364
/// ```
360365
pub fn repin_after<F, R>(&mut self, f: F) -> R
361366
where
@@ -451,6 +456,7 @@ impl fmt::Debug for Guard {
451456
///
452457
/// // Dropping `dummy` doesn't affect the current thread - it's just a noop.
453458
/// }
459+
/// # unsafe { drop(a.into_owned()); } // avoid leak
454460
/// ```
455461
///
456462
/// The most common use of this function is when constructing or destructing a data structure.

crossbeam-epoch/src/internal.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -610,14 +610,16 @@ impl Local {
610610

611611
impl IsElement<Local> for Local {
612612
fn entry_of(local: &Local) -> &Entry {
613-
let entry_ptr = (local as *const Local as usize + offset_of!(Local, entry)) as *const Entry;
614-
unsafe { &*entry_ptr }
613+
unsafe {
614+
let entry_ptr =
615+
(local as *const Local as *const u8).add(offset_of!(Local, entry)) as *const Entry;
616+
&*entry_ptr
617+
}
615618
}
616619

617620
unsafe fn element_of(entry: &Entry) -> &Local {
618-
// offset_of! macro uses unsafe, but it's unnecessary in this context.
619-
#[allow(unused_unsafe)]
620-
let local_ptr = (entry as *const Entry as usize - offset_of!(Local, entry)) as *const Local;
621+
let local_ptr =
622+
(entry as *const Entry as *const u8).sub(offset_of!(Local, entry)) as *const Local;
621623
&*local_ptr
622624
}
623625

0 commit comments

Comments
 (0)