From 0abc0bc4b0aaeeb055d1110c95c347cdf4e1f0e3 Mon Sep 17 00:00:00 2001 From: Jon Gjengset Date: Fri, 10 Apr 2020 08:37:52 -0400 Subject: [PATCH 1/9] Stop ignoring miri leaks Now that https://github.com/rust-lang/miri/issues/940 has been fixed, and has landed in nightly (https://github.com/rust-lang/rust/pull/70897), we should be able to run miri with leak check enabled again! --- azure-pipelines.yml | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 37906772..7f86caab 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -57,11 +57,7 @@ jobs: - miri - script: cargo miri setup displayName: cargo miri setup - # ignore leaks due to - # https://github.com/crossbeam-rs/crossbeam/issues/464 - # which is - # https://github.com/rust-lang/miri/issues/940 - - script: cargo miri -Zmiri-ignore-leaks test + - script: cargo miri test displayName: cargo miri test - job: asan dependsOn: deny From 3551e2034f33407645751329c672f159956e6868 Mon Sep 17 00:00:00 2001 From: Jon Gjengset Date: Fri, 10 Apr 2020 08:54:46 -0400 Subject: [PATCH 2/9] Miri can't handle threads --- src/map.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/map.rs b/src/map.rs index 44822d61..115c8362 100644 --- a/src/map.rs +++ b/src/map.rs @@ -3383,6 +3383,7 @@ mod tree_bins { } #[test] + #[cfg(not(miri))] fn concurrent_tree_bin() { let map = HashMap::::with_hasher(ZeroHashBuilder); // first, ensure that we have a tree bin From 6d154be5a4fd2171447074eee28c795fd4f1d04d Mon Sep 17 00:00:00 2001 From: Jon Gjengset Date: Fri, 10 Apr 2020 10:18:17 -0400 Subject: [PATCH 3/9] Miri gets sad from the disallow_evil test as it should be ? --- src/map.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/map.rs b/src/map.rs index 115c8362..3057af38 100644 --- a/src/map.rs +++ b/src/map.rs @@ -3538,6 +3538,7 @@ mod tree_bins { } #[test] #[should_panic] + #[cfg(not(miri))] fn disallow_evil() { let map: HashMap<_, _> = HashMap::default(); map.insert(42, String::from("hello"), &crossbeam_epoch::pin()); From e4a044e79aca7c0ea59159cd3294a3917e52ab22 Mon Sep 17 00:00:00 2001 From: Jon Gjengset Date: Fri, 10 Apr 2020 10:39:12 -0400 Subject: [PATCH 4/9] Go back to ignoring miri leaks Let's wait until crossbeam is reported to be leak-free on its own. --- azure-pipelines.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 7f86caab..7a0a4cd7 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -58,7 +58,7 @@ jobs: - script: cargo miri setup displayName: cargo miri setup - script: cargo miri test - displayName: cargo miri test + displayName: cargo miri test -- -Zmiri-ignore-leaks - job: asan dependsOn: deny displayName: "Run address sanitizer on test suite" From 5bfc6e6cefb0b1cbdaa427c363c16944a91d35d5 Mon Sep 17 00:00:00 2001 From: Jon Gjengset Date: Fri, 10 Apr 2020 10:51:04 -0400 Subject: [PATCH 5/9] Err, actually ignore leaks --- azure-pipelines.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 7a0a4cd7..792290f9 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -57,8 +57,8 @@ jobs: - miri - script: cargo miri setup displayName: cargo miri setup - - script: cargo miri test - displayName: cargo miri test -- -Zmiri-ignore-leaks + - script: cargo miri test -- -Zmiri-ignore-leaks + displayName: cargo miri test - job: asan dependsOn: deny displayName: "Run address sanitizer on test suite" From dfc610470e2d1362e928e909bded3a264ecc1581 Mon Sep 17 00:00:00 2001 From: Jon Gjengset Date: Fri, 10 Apr 2020 11:00:19 -0400 Subject: [PATCH 6/9] Ignore all concurrent tests with miri --- tests/basic.rs | 4 ++++ tests/basic_ref.rs | 3 +++ tests/borrow.rs | 2 ++ tests/cuckoo/main.rs | 1 + tests/jdk/main.rs | 2 ++ tests/set.rs | 2 ++ 6 files changed, 14 insertions(+) diff --git a/tests/basic.rs b/tests/basic.rs index 07c18e5c..ac366a51 100644 --- a/tests/basic.rs +++ b/tests/basic.rs @@ -206,6 +206,7 @@ fn compute_if_present_remove() { } #[test] +#[cfg(not(miri))] fn concurrent_insert() { let map = Arc::new(HashMap::::new()); @@ -236,6 +237,7 @@ fn concurrent_insert() { } #[test] +#[cfg(not(miri))] fn concurrent_remove() { let map = Arc::new(HashMap::::new()); @@ -276,6 +278,7 @@ fn concurrent_remove() { } #[test] +#[cfg(not(miri))] fn concurrent_compute_if_present() { let map = Arc::new(HashMap::::new()); @@ -314,6 +317,7 @@ fn concurrent_compute_if_present() { } #[test] +#[cfg(not(miri))] fn concurrent_resize_and_get() { let map = Arc::new(HashMap::::new()); { diff --git a/tests/basic_ref.rs b/tests/basic_ref.rs index b2246d1b..77f296cc 100644 --- a/tests/basic_ref.rs +++ b/tests/basic_ref.rs @@ -413,6 +413,7 @@ fn retain_force_some() { } #[test] +#[cfg(not(miri))] fn concurrent_insert() { let map = Arc::new(HashMap::::new()); @@ -443,6 +444,7 @@ fn concurrent_insert() { } #[test] +#[cfg(not(miri))] fn concurrent_remove() { let map = Arc::new(HashMap::::new()); @@ -483,6 +485,7 @@ fn concurrent_remove() { } #[test] +#[cfg(not(miri))] fn concurrent_compute_if_present() { let map = Arc::new(HashMap::::new()); diff --git a/tests/borrow.rs b/tests/borrow.rs index 75522f61..ad81f6ee 100644 --- a/tests/borrow.rs +++ b/tests/borrow.rs @@ -67,6 +67,7 @@ fn update() { } #[test] +#[cfg(not(miri))] fn concurrent_insert() { let map = Arc::new(HashMap::::new()); let keys = Arc::new((0..64).map(|i| i.to_string()).collect::>()); @@ -97,6 +98,7 @@ fn concurrent_insert() { } #[test] +#[cfg(not(miri))] fn concurrent_remove() { let map = Arc::new(HashMap::::new()); let keys = Arc::new((0..64).map(|i| i.to_string()).collect::>()); diff --git a/tests/cuckoo/main.rs b/tests/cuckoo/main.rs index 9f571181..e26e938e 100644 --- a/tests/cuckoo/main.rs +++ b/tests/cuckoo/main.rs @@ -1 +1,2 @@ +#[cfg(not(miri))] mod stress; diff --git a/tests/jdk/main.rs b/tests/jdk/main.rs index 1de85a3b..d9805f83 100644 --- a/tests/jdk/main.rs +++ b/tests/jdk/main.rs @@ -1,3 +1,5 @@ +#[cfg(not(miri))] mod concurrent_associate; +#[cfg(not(miri))] mod concurrent_contains; mod map_check; diff --git a/tests/set.rs b/tests/set.rs index a3242af0..5803f19f 100644 --- a/tests/set.rs +++ b/tests/set.rs @@ -99,6 +99,7 @@ fn update() { } #[test] +#[cfg(not(miri))] fn concurrent_insert() { let set = Arc::new(HashSet::::new()); @@ -128,6 +129,7 @@ fn concurrent_insert() { } #[test] +#[cfg(not(miri))] fn concurrent_remove() { let set = Arc::new(HashSet::::new()); From e6ad4f82ecd13b6c218b9590cd7c8f1042902ed3 Mon Sep 17 00:00:00 2001 From: Jon Gjengset Date: Sun, 26 Apr 2020 11:46:48 -0400 Subject: [PATCH 7/9] Use preferred miri cfg pattern --- src/map.rs | 4 ++-- tests/basic.rs | 8 ++++---- tests/basic_ref.rs | 6 +++--- tests/borrow.rs | 4 ++-- tests/cuckoo/main.rs | 1 - tests/cuckoo/stress.rs | 1 + tests/jdk/concurrent_associate.rs | 1 + tests/jdk/concurrent_contains.rs | 1 + tests/jdk/main.rs | 2 -- tests/set.rs | 4 ++-- 10 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/map.rs b/src/map.rs index 3057af38..faafb023 100644 --- a/src/map.rs +++ b/src/map.rs @@ -3383,7 +3383,7 @@ mod tree_bins { } #[test] - #[cfg(not(miri))] + #[cfg_attr(miri, ignore)] fn concurrent_tree_bin() { let map = HashMap::::with_hasher(ZeroHashBuilder); // first, ensure that we have a tree bin @@ -3538,7 +3538,7 @@ mod tree_bins { } #[test] #[should_panic] - #[cfg(not(miri))] + #[cfg_attr(miri, ignore)] fn disallow_evil() { let map: HashMap<_, _> = HashMap::default(); map.insert(42, String::from("hello"), &crossbeam_epoch::pin()); diff --git a/tests/basic.rs b/tests/basic.rs index ac366a51..6bc02a1a 100644 --- a/tests/basic.rs +++ b/tests/basic.rs @@ -206,7 +206,7 @@ fn compute_if_present_remove() { } #[test] -#[cfg(not(miri))] +#[cfg_attr(miri, ignore)] fn concurrent_insert() { let map = Arc::new(HashMap::::new()); @@ -237,7 +237,7 @@ fn concurrent_insert() { } #[test] -#[cfg(not(miri))] +#[cfg_attr(miri, ignore)] fn concurrent_remove() { let map = Arc::new(HashMap::::new()); @@ -278,7 +278,7 @@ fn concurrent_remove() { } #[test] -#[cfg(not(miri))] +#[cfg_attr(miri, ignore)] fn concurrent_compute_if_present() { let map = Arc::new(HashMap::::new()); @@ -317,7 +317,7 @@ fn concurrent_compute_if_present() { } #[test] -#[cfg(not(miri))] +#[cfg_attr(miri, ignore)] fn concurrent_resize_and_get() { let map = Arc::new(HashMap::::new()); { diff --git a/tests/basic_ref.rs b/tests/basic_ref.rs index 77f296cc..9f2c786c 100644 --- a/tests/basic_ref.rs +++ b/tests/basic_ref.rs @@ -413,7 +413,7 @@ fn retain_force_some() { } #[test] -#[cfg(not(miri))] +#[cfg_attr(miri, ignore)] fn concurrent_insert() { let map = Arc::new(HashMap::::new()); @@ -444,7 +444,7 @@ fn concurrent_insert() { } #[test] -#[cfg(not(miri))] +#[cfg_attr(miri, ignore)] fn concurrent_remove() { let map = Arc::new(HashMap::::new()); @@ -485,7 +485,7 @@ fn concurrent_remove() { } #[test] -#[cfg(not(miri))] +#[cfg_attr(miri, ignore)] fn concurrent_compute_if_present() { let map = Arc::new(HashMap::::new()); diff --git a/tests/borrow.rs b/tests/borrow.rs index ad81f6ee..07277066 100644 --- a/tests/borrow.rs +++ b/tests/borrow.rs @@ -67,7 +67,7 @@ fn update() { } #[test] -#[cfg(not(miri))] +#[cfg_attr(miri, ignore)] fn concurrent_insert() { let map = Arc::new(HashMap::::new()); let keys = Arc::new((0..64).map(|i| i.to_string()).collect::>()); @@ -98,7 +98,7 @@ fn concurrent_insert() { } #[test] -#[cfg(not(miri))] +#[cfg_attr(miri, ignore)] fn concurrent_remove() { let map = Arc::new(HashMap::::new()); let keys = Arc::new((0..64).map(|i| i.to_string()).collect::>()); diff --git a/tests/cuckoo/main.rs b/tests/cuckoo/main.rs index e26e938e..9f571181 100644 --- a/tests/cuckoo/main.rs +++ b/tests/cuckoo/main.rs @@ -1,2 +1 @@ -#[cfg(not(miri))] mod stress; diff --git a/tests/cuckoo/stress.rs b/tests/cuckoo/stress.rs index d037144c..5bf401f7 100644 --- a/tests/cuckoo/stress.rs +++ b/tests/cuckoo/stress.rs @@ -147,6 +147,7 @@ fn stress_find_thread(env: Arc) { } #[test] +#[cfg_attr(miri, ignore)] fn stress_test() { let root = Arc::new(Environment::new()); let mut threads = Vec::new(); diff --git a/tests/jdk/concurrent_associate.rs b/tests/jdk/concurrent_associate.rs index 4f884dc8..d7458daf 100644 --- a/tests/jdk/concurrent_associate.rs +++ b/tests/jdk/concurrent_associate.rs @@ -25,6 +25,7 @@ fn insert(map: Arc>, k: KeyVal) { } #[test] +#[cfg_attr(miri, ignore)] fn test_concurrent_insert<'g>() { test(insert); } diff --git a/tests/jdk/concurrent_contains.rs b/tests/jdk/concurrent_contains.rs index 59bcd551..622a3480 100644 --- a/tests/jdk/concurrent_contains.rs +++ b/tests/jdk/concurrent_contains.rs @@ -11,6 +11,7 @@ const ITERATIONS: usize = 256; const ROUNDS: usize = 32; #[test] +#[cfg_attr(miri, ignore)] fn test_concurrent_contains_key() { let map = HashMap::new(); let mut content = [0; NUM_ENTRIES]; diff --git a/tests/jdk/main.rs b/tests/jdk/main.rs index d9805f83..1de85a3b 100644 --- a/tests/jdk/main.rs +++ b/tests/jdk/main.rs @@ -1,5 +1,3 @@ -#[cfg(not(miri))] mod concurrent_associate; -#[cfg(not(miri))] mod concurrent_contains; mod map_check; diff --git a/tests/set.rs b/tests/set.rs index 5803f19f..3dde617a 100644 --- a/tests/set.rs +++ b/tests/set.rs @@ -99,7 +99,7 @@ fn update() { } #[test] -#[cfg(not(miri))] +#[cfg_attr(miri, ignore)] fn concurrent_insert() { let set = Arc::new(HashSet::::new()); @@ -129,7 +129,7 @@ fn concurrent_insert() { } #[test] -#[cfg(not(miri))] +#[cfg_attr(miri, ignore)] fn concurrent_remove() { let set = Arc::new(HashSet::::new()); From d944731c21cef3766bc7ede8da00f586ddc2bbb0 Mon Sep 17 00:00:00 2001 From: Jon Gjengset Date: Wed, 6 May 2020 14:14:32 -0400 Subject: [PATCH 8/9] Avoid warnings under miri --- src/map.rs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/map.rs b/src/map.rs index faafb023..7975dbf2 100644 --- a/src/map.rs +++ b/src/map.rs @@ -7,10 +7,7 @@ use std::error::Error; use std::fmt::{self, Debug, Display, Formatter}; use std::hash::{BuildHasher, Hash, Hasher}; use std::iter::FromIterator; -use std::sync::{ - atomic::{AtomicIsize, AtomicUsize, Ordering}, - Once, -}; +use std::sync::atomic::{AtomicIsize, Ordering}; const ISIZE_BITS: usize = core::mem::size_of::() * 8; @@ -62,8 +59,10 @@ const MAX_RESIZERS: isize = (1 << (ISIZE_BITS - RESIZE_STAMP_BITS)) - 1; /// The bit shift for recording size stamp in `size_ctl`. const RESIZE_STAMP_SHIFT: usize = ISIZE_BITS - RESIZE_STAMP_BITS; -static NCPU_INITIALIZER: Once = Once::new(); -static NCPU: AtomicUsize = AtomicUsize::new(0); +#[cfg(not(miri))] +static NCPU_INITIALIZER: std::sync::Once = std::sync::Once::new(); +#[cfg(not(miri))] +static NCPU: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0); macro_rules! load_factor { ($n: expr) => { From d0f080b813a496dcc287348e786207bc0206d5da Mon Sep 17 00:00:00 2001 From: Jon Gjengset Date: Wed, 6 May 2020 15:16:39 -0400 Subject: [PATCH 9/9] miri can't handle lots of iterations --- tests/hasher.rs | 2 +- tests/jdk/map_check.rs | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/tests/hasher.rs b/tests/hasher.rs index c8489dd4..e11e8ca9 100644 --- a/tests/hasher.rs +++ b/tests/hasher.rs @@ -23,7 +23,7 @@ impl BuildHasher for ZeroHashBuilder { } fn check() { - let range = 0..1000; + let range = if cfg!(miri) { 0..16 } else { 0..1000 }; let guard = epoch::pin(); let map = HashMap::::default(); for i in range.clone() { diff --git a/tests/jdk/map_check.rs b/tests/jdk/map_check.rs index e376e3d4..385b2219 100644 --- a/tests/jdk/map_check.rs +++ b/tests/jdk/map_check.rs @@ -3,8 +3,17 @@ use flurry::*; use rand::prelude::*; use std::hash::Hash; +#[cfg(not(miri))] const SIZE: usize = 50_000; +#[cfg(miri)] +const SIZE: usize = 12; + +// there must be more things absent than present! +#[cfg(not(miri))] const ABSENT_SIZE: usize = 1 << 17; +#[cfg(miri)] +const ABSENT_SIZE: usize = 1 << 5; + const ABSENT_MASK: usize = ABSENT_SIZE - 1; fn t1(map: &HashMap, keys: &[K], expect: usize)