Skip to content

Commit d40f49e

Browse files
bors[bot]gnzlbg
andcommitted
Merge #51
51: Test miri on CI r=Amanieu a=gnzlbg Co-authored-by: gnzlbg <[email protected]>
2 parents fe6400e + ff335ec commit d40f49e

File tree

6 files changed

+99
-22
lines changed

6 files changed

+99
-22
lines changed

.travis.yml

+9
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,15 @@ sudo: false
33

44
matrix:
55
include:
6+
- name: "miri"
7+
rust: nightly
8+
install:
9+
- rustup component add rust-src
10+
- cargo +nightly install --force --git https://github.com/rust-lang/miri miri
11+
- cargo install xargo
12+
script:
13+
- cargo clean
14+
- cargo +nightly miri test
615
- rust: 1.29.0
716
- rust: stable
817
- rust: beta

src/lib.rs

+3
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ extern crate serde;
4343
#[cfg_attr(test, macro_use)]
4444
extern crate std as alloc;
4545

46+
#[macro_use]
47+
mod macros;
48+
4649
mod external_trait_impls;
4750
mod fx;
4851
mod map;

src/macros.rs

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// See the cfg-if crate.
2+
macro_rules! cfg_if {
3+
// match if/else chains with a final `else`
4+
($(
5+
if #[cfg($($meta:meta),*)] { $($it:item)* }
6+
) else * else {
7+
$($it2:item)*
8+
}) => {
9+
cfg_if! {
10+
@__items
11+
() ;
12+
$( ( ($($meta),*) ($($it)*) ), )*
13+
( () ($($it2)*) ),
14+
}
15+
};
16+
17+
// match if/else chains lacking a final `else`
18+
(
19+
if #[cfg($($i_met:meta),*)] { $($i_it:item)* }
20+
$(
21+
else if #[cfg($($e_met:meta),*)] { $($e_it:item)* }
22+
)*
23+
) => {
24+
cfg_if! {
25+
@__items
26+
() ;
27+
( ($($i_met),*) ($($i_it)*) ),
28+
$( ( ($($e_met),*) ($($e_it)*) ), )*
29+
( () () ),
30+
}
31+
};
32+
33+
// Internal and recursive macro to emit all the items
34+
//
35+
// Collects all the negated cfgs in a list at the beginning and after the
36+
// semicolon is all the remaining items
37+
(@__items ($($not:meta,)*) ; ) => {};
38+
(@__items ($($not:meta,)*) ; ( ($($m:meta),*) ($($it:item)*) ), $($rest:tt)*) => {
39+
// Emit all items within one block, applying an approprate #[cfg]. The
40+
// #[cfg] will require all `$m` matchers specified and must also negate
41+
// all previous matchers.
42+
cfg_if! { @__apply cfg(all($($m,)* not(any($($not),*)))), $($it)* }
43+
44+
// Recurse to emit all other items in `$rest`, and when we do so add all
45+
// our `$m` matchers to the list of `$not` matchers as future emissions
46+
// will have to negate everything we just matched as well.
47+
cfg_if! { @__items ($($not,)* $($m,)*) ; $($rest)* }
48+
};
49+
50+
// Internal macro to Apply a cfg attribute to a list of items
51+
(@__apply $m:meta, $($it:item)*) => {
52+
$(#[$m] $it)*
53+
};
54+
}

src/map.rs

+11-2
Original file line numberDiff line numberDiff line change
@@ -2513,10 +2513,11 @@ mod test_map {
25132513
use super::DefaultHashBuilder;
25142514
use super::Entry::{Occupied, Vacant};
25152515
use super::HashMap;
2516-
use rand::{thread_rng, Rng};
2516+
use rand::{rngs::SmallRng, Rng, SeedableRng};
25172517
use std::cell::RefCell;
25182518
use std::usize;
25192519
use std::vec::Vec;
2520+
#[cfg(not(miri))]
25202521
use CollectionAllocErr::*;
25212522

25222523
#[test]
@@ -2770,6 +2771,7 @@ mod test_map {
27702771
}
27712772

27722773
#[test]
2774+
#[cfg(not(miri))] // FIXME: https://github.com/rust-lang/miri/issues/654
27732775
fn test_lots_of_insertions() {
27742776
let mut m = HashMap::new();
27752777

@@ -3191,6 +3193,7 @@ mod test_map {
31913193

31923194
#[test]
31933195
#[should_panic]
3196+
#[cfg(not(miri))] // FIXME: https://github.com/rust-lang/miri/issues/636
31943197
fn test_index_nonexistent() {
31953198
let mut map = HashMap::new();
31963199

@@ -3262,7 +3265,12 @@ mod test_map {
32623265
}
32633266

32643267
let mut m = HashMap::new();
3265-
let mut rng = thread_rng();
3268+
3269+
// FIXME: https://github.com/rust-lang/miri/issues/653
3270+
let mut rng = {
3271+
let seed = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16];
3272+
SmallRng::from_seed(seed)
3273+
};
32663274

32673275
// Populate the map with some items.
32683276
for _ in 0..50 {
@@ -3372,6 +3380,7 @@ mod test_map {
33723380
}
33733381

33743382
#[test]
3383+
#[cfg(not(miri))] // FIXME: https://github.com/rust-lang/miri/issues/655
33753384
fn test_try_reserve() {
33763385
let mut empty_bytes: HashMap<u8, u8> = HashMap::new();
33773386

src/raw/mod.rs

+21-20
Original file line numberDiff line numberDiff line change
@@ -36,26 +36,27 @@ unsafe fn offset_from<T>(to: *const T, from: *const T) -> usize {
3636
(to as usize - from as usize) / mem::size_of::<T>()
3737
}
3838

39-
// Use the SSE2 implementation if possible: it allows us to scan 16 buckets at
40-
// once instead of 8. We don't bother with AVX since it would require runtime
41-
// dispatch and wouldn't gain us much anyways: the probability of finding a
42-
// match drops off drastically after the first few buckets.
43-
//
44-
// I attempted an implementation on ARM using NEON instructions, but it turns
45-
// out that most NEON instructions have multi-cycle latency, which in the end
46-
// outweighs any gains over the generic implementation.
47-
#[cfg(all(
48-
target_feature = "sse2",
49-
any(target_arch = "x86", target_arch = "x86_64")
50-
))]
51-
#[path = "sse2.rs"]
52-
mod imp;
53-
#[cfg(not(all(
54-
target_feature = "sse2",
55-
any(target_arch = "x86", target_arch = "x86_64")
56-
)))]
57-
#[path = "generic.rs"]
58-
mod imp;
39+
cfg_if! {
40+
// Use the SSE2 implementation if possible: it allows us to scan 16 buckets
41+
// at once instead of 8. We don't bother with AVX since it would require
42+
// runtime dispatch and wouldn't gain us much anyways: the probability of
43+
// finding a match drops off drastically after the first few buckets.
44+
//
45+
// I attempted an implementation on ARM using NEON instructions, but it
46+
// turns out that most NEON instructions have multi-cycle latency, which in
47+
// the end outweighs any gains over the generic implementation.
48+
if #[cfg(all(
49+
target_feature = "sse2",
50+
any(target_arch = "x86", target_arch = "x86_64"),
51+
not(miri)
52+
))] {
53+
#[path = "sse2.rs"]
54+
mod imp;
55+
} else {
56+
#[path = "generic.rs"]
57+
mod imp;
58+
}
59+
}
5960

6061
mod bitmask;
6162

tests/set.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#![cfg(not(miri))] // FIXME: takes too long
12
extern crate hashbrown;
23
extern crate rand;
34

0 commit comments

Comments
 (0)