Skip to content

Commit 5635c37

Browse files
committed
Merge branch 'master' into stable-tests
Forked the octillion test with `Range<u128>` vs. `flat_map` iterators. The `cfg(nightly)` is no longer needed with stable Rust 1.26, as we only used `i128` and `impl Trait` that are now stable.
2 parents aa6fdd3 + dea6b10 commit 5635c37

File tree

21 files changed

+795
-185
lines changed

21 files changed

+795
-185
lines changed

.travis.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,6 @@ matrix:
1515
- rust: 1.13.0
1616
os: linux
1717
#if: everything!
18-
before_script:
19-
# rand 0.4.2 requires rust 1.15, and rand-0.3.22 requires rand-0.4 :/
20-
# manually hacking the lockfile due to the limitations of cargo#2773
21-
- cargo generate-lockfile
22-
- sed -i -e 's/"rand 0.[34].[0-9]\+/"rand 0.3.20/' Cargo.lock
23-
- sed -i -e '/^name = "rand"/,/^$/s/version = "0.3.[0-9]\+"/version = "0.3.20"/' Cargo.lock
2418
script: cargo build
2519

2620
- rust: stable

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "rayon"
33
# Reminder to update html_rool_url in lib.rs when updating version
4-
version = "1.0.0"
4+
version = "1.0.1"
55
authors = ["Niko Matsakis <[email protected]>",
66
"Josh Stone <[email protected]>"]
77
description = "Simple work-stealing parallelism for Rust"
@@ -28,6 +28,6 @@ default-features = false
2828
[dev-dependencies]
2929
docopt = "0.8"
3030
lazy_static = "1"
31-
rand = ">= 0.3, < 0.5"
31+
rand = "0.4"
3232
serde = "1"
3333
serde_derive = "1"

FAQ.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ these are preferable to random failures in my experience.
196196
## But wait, isn't Rust supposed to free me from this kind of thinking?
197197

198198
You might think that Rust is supposed to mean that you don't have to
199-
think about atomicity at all. In fact, if you avoid inherent
199+
think about atomicity at all. In fact, if you avoid interior
200200
mutability (`Cell` and `RefCell` in a sequential setting, or
201201
`AtomicUsize`, `RwLock`, `Mutex`, et al. in parallel code), then this
202202
is true: the type system will basically guarantee that you don't have

RELEASES.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
# Release rayon 1.0.1
2+
3+
- Added more documentation for `rayon::iter::split()`.
4+
- Corrected links and typos in documentation.
5+
6+
## Contributors
7+
8+
Thanks to all of the contributors for this release!
9+
10+
- @cuviper
11+
- @HadrienG2
12+
- @matthiasbeyer
13+
- @nikomatsakis
14+
15+
116
# Release rayon 1.0.0 / rayon-core 1.4.0
217

318
- `ParallelIterator` added the `update` method which applies a function to

build.rs

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,33 @@
11
use std::env;
2-
use std::process::Command;
3-
use std::str;
2+
use std::io::Write;
3+
use std::process::{Command, Stdio};
44

55
fn main() {
6-
println!("cargo:rerun-if-changed=build.rs");
7-
println!("cargo:rerun-if-env-changed=RUSTC");
8-
9-
let rustc = env::var_os("RUSTC").unwrap();
10-
let version = Command::new(rustc).arg("-V").output().unwrap().stdout;
11-
let version = str::from_utf8(&version).unwrap();
12-
if version.contains("nightly") || version.contains("dev") {
13-
// a few tests want to use nightly features
14-
println!("cargo:rustc-cfg=nightly");
6+
if probe("fn main() { 0i128; }") {
7+
println!("cargo:rustc-cfg=has_i128");
158
}
169
}
10+
11+
/// Test if a code snippet can be compiled
12+
fn probe(code: &str) -> bool {
13+
let rustc = env::var_os("RUSTC").unwrap_or_else(|| "rustc".into());
14+
let out_dir = env::var_os("OUT_DIR").expect("environment variable OUT_DIR");
15+
16+
let mut child = Command::new(rustc)
17+
.arg("--out-dir")
18+
.arg(out_dir)
19+
.arg("--emit=obj")
20+
.arg("-")
21+
.stdin(Stdio::piped())
22+
.spawn()
23+
.expect("rustc probe");
24+
25+
child
26+
.stdin
27+
.as_mut()
28+
.expect("rustc stdin")
29+
.write_all(code.as_bytes())
30+
.expect("write rustc stdin");
31+
32+
child.wait().expect("rustc probe").success()
33+
}

rayon-core/Cargo.toml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,17 @@ keywords = ["parallel", "thread", "concurrency", "join", "performance"]
1414
categories = ["concurrency"]
1515

1616
[dependencies]
17-
rand = ">= 0.3, < 0.5"
1817
num_cpus = "1.2"
19-
crossbeam-deque = "0.2.0"
2018
libc = "0.2.16"
2119
lazy_static = "1"
2220

21+
# This is deliberately not the latest version, because we want
22+
# to support older rustc than crossbeam-deque 0.3+ does.
23+
[dependencies.crossbeam-deque]
24+
version = "0.2.0"
25+
2326
[dev-dependencies]
27+
rand = "0.4"
2428

2529
[[test]]
2630
name = "stack_overflow_crash"

rayon-core/src/join/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ mod test;
3939
/// sort for real, you should prefer [the `par_sort` method] offered
4040
/// by Rayon).
4141
///
42-
/// [the `par_sort` method]: ../slice/trait.ParallelSliceMut.html#method.par_sort
42+
/// [the `par_sort` method]: ../rayon/slice/trait.ParallelSliceMut.html#method.par_sort
4343
///
4444
/// ```rust
4545
/// # use rayon_core as rayon;

rayon-core/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ extern crate crossbeam_deque;
3636
extern crate lazy_static;
3737
extern crate libc;
3838
extern crate num_cpus;
39+
40+
#[cfg(test)]
3941
extern crate rand;
4042

4143
#[macro_use]

rayon-core/src/registry.rs

Lines changed: 48 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@ use job::Job;
77
use internal::task::Task;
88
use latch::{LatchProbe, Latch, CountLatch, LockLatch, SpinLatch, TickleLatch};
99
use log::Event::*;
10-
use rand::{self, Rng};
1110
use sleep::Sleep;
1211
use std::any::Any;
13-
use std::cell::{Cell, UnsafeCell};
12+
use std::cell::Cell;
13+
use std::collections::hash_map::DefaultHasher;
14+
use std::hash::Hasher;
1415
use std::sync::{Arc, Mutex, Once, ONCE_INIT};
16+
use std::sync::atomic::{AtomicUsize, ATOMIC_USIZE_INIT, Ordering};
1517
use std::thread;
1618
use std::mem;
17-
use std::u32;
1819
use std::usize;
1920
use unwind;
2021
use util::leak;
@@ -460,7 +461,7 @@ pub struct WorkerThread {
460461
breadth_first: bool,
461462

462463
/// A weak random number generator.
463-
rng: UnsafeCell<rand::XorShiftRng>,
464+
rng: XorShift64Star,
464465

465466
registry: Arc<Registry>,
466467
}
@@ -602,17 +603,8 @@ impl WorkerThread {
602603
if num_threads <= 1 {
603604
return None;
604605
}
605-
assert!(num_threads < (u32::MAX as usize),
606-
"we do not support more than u32::MAX worker threads");
607-
608-
let start = {
609-
// OK to use this UnsafeCell because (a) this data is
610-
// confined to current thread, as WorkerThread is not Send
611-
// nor Sync and (b) rand crate will not call back into
612-
// this method.
613-
let rng = &mut *self.rng.get();
614-
rng.next_u32() % num_threads as u32
615-
} as usize;
606+
607+
let start = self.rng.next_usize(num_threads);
616608
(start .. num_threads)
617609
.chain(0 .. start)
618610
.filter(|&i| i != self.index)
@@ -646,7 +638,7 @@ unsafe fn main_loop(worker: Deque<JobRef>,
646638
worker: worker,
647639
breadth_first: breadth_first,
648640
index: index,
649-
rng: UnsafeCell::new(rand::weak_rng()),
641+
rng: XorShift64Star::new(),
650642
registry: registry.clone(),
651643
};
652644
WorkerThread::set_current(&worker_thread);
@@ -716,3 +708,43 @@ pub fn in_worker<OP, R>(op: OP) -> R
716708
}
717709
}
718710
}
711+
712+
/// [xorshift*] is a fast pseudorandom number generator which will
713+
/// even tolerate weak seeding, as long as it's not zero.
714+
///
715+
/// [xorshift*]: https://en.wikipedia.org/wiki/Xorshift#xorshift*
716+
struct XorShift64Star {
717+
state: Cell<u64>,
718+
}
719+
720+
impl XorShift64Star {
721+
fn new() -> Self {
722+
// Any non-zero seed will do -- this uses the hash of a global counter.
723+
let mut seed = 0;
724+
while seed == 0 {
725+
let mut hasher = DefaultHasher::new();
726+
static COUNTER: AtomicUsize = ATOMIC_USIZE_INIT;
727+
hasher.write_usize(COUNTER.fetch_add(1, Ordering::Relaxed));
728+
seed = hasher.finish();
729+
}
730+
731+
XorShift64Star {
732+
state: Cell::new(seed),
733+
}
734+
}
735+
736+
fn next(&self) -> u64 {
737+
let mut x = self.state.get();
738+
debug_assert_ne!(x, 0);
739+
x ^= x >> 12;
740+
x ^= x << 25;
741+
x ^= x >> 27;
742+
self.state.set(x);
743+
x.wrapping_mul(0x2545_f491_4f6c_dd1d)
744+
}
745+
746+
/// Return a value from `0..n`.
747+
fn next_usize(&self, n: usize) -> usize {
748+
(self.next() % n as u64) as usize
749+
}
750+
}

rayon-demo/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ fixedbitset = "0.1.5"
1212
glium = "0.20"
1313
lazy_static = "1"
1414
odds = "0.3"
15-
rand = ">= 0.3, < 0.5"
15+
rand = "0.4"
1616
regex = "0.2"
1717
serde = "1"
1818
serde_derive = "1"

0 commit comments

Comments
 (0)