Skip to content

Commit 939d3ee

Browse files
bors[bot]cuviper
andcommitted
656: Rust 1.26 and assorted cleanups r=nikomatsakis a=cuviper In anticipation of [RFC 3](rayon-rs/rfcs#3), giving us a policy to soon raise our minimum to Rust 1.26, I started this branch to make the conversion. After the primary motivation of upgrading crossbeam, I also looked for ways to use newer language features. Throughout all of this, the public API should be completely unaffected. Closes rayon-rs#586 for newer crossbeam, even though we're not quite at the *newest*. Co-authored-by: Josh Stone <[email protected]>
2 parents 021d15f + bcfca1b commit 939d3ee

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

105 files changed

+996
-1305
lines changed

.travis.yml

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,13 @@ matrix:
99
fast_finish: true
1010
include:
1111
# NB: To help with CI delays, each `pull_request` is only tested on Linux,
12-
# with 1.13 for compatibility and stable+rayon_unstable for broad test
12+
# with 1.26 for compatibility and stable+rayon_unstable for broad test
1313
# coverage. The bors bot counts as a `push` type, which will run it all.
1414

15-
- rust: 1.13.0
15+
- rust: 1.26.0
1616
os: linux
1717
#if: everything!
1818
script: cargo build
19-
before_script:
20-
# lazy_static 1.1 requires Rust 1.21+, so downgrade it.
21-
# (and docopt 1.1 requires lazy_static 1.3)
22-
- cargo generate-lockfile
23-
- cargo update -p docopt --precise 1.0.2
24-
- cargo update -p lazy_static --precise 1.0.2
2519

2620
- rust: stable
2721
os: linux

Cargo.toml

Lines changed: 3 additions & 4 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.3"
4+
version = "1.1.0"
55
authors = ["Niko Matsakis <[email protected]>",
66
"Josh Stone <[email protected]>"]
77
description = "Simple work-stealing parallelism for Rust"
@@ -11,16 +11,15 @@ documentation = "https://docs.rs/rayon/"
1111
readme = "README.md"
1212
keywords = ["parallel", "thread", "concurrency", "join", "performance"]
1313
categories = ["concurrency"]
14-
build = "build.rs"
1514
exclude = ["/ci/*", "/scripts/*", "/.travis.yml", "/appveyor.yml", "/bors.toml"]
1615

1716
[workspace]
1817
members = ["rayon-demo", "rayon-core", "rayon-futures"]
1918
exclude = ["ci"]
2019

2120
[dependencies]
22-
rayon-core = { version = "1.4.1", path = "rayon-core" }
23-
crossbeam-deque = "0.2.0"
21+
rayon-core = { version = "1.5.0", path = "rayon-core" }
22+
crossbeam-deque = "0.6.3"
2423

2524
# This is a public dependency!
2625
[dependencies.either]

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ just add:
9090
use rayon::prelude::*;
9191
```
9292

93-
Rayon currently requires `rustc 1.13.0` or greater.
93+
Rayon currently requires `rustc 1.26.0` or greater.
9494

9595
## Contribution
9696

build.rs

Lines changed: 0 additions & 33 deletions
This file was deleted.

examples/cpu_monitor.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use docopt::Docopt;
88
use std::io;
99
use std::process;
1010

11-
const USAGE: &'static str = "
11+
const USAGE: &str = "
1212
Usage: cpu_monitor [options] <scenario>
1313
cpu_monitor --help
1414
@@ -76,7 +76,7 @@ fn tasks_ended(args: &Args) {
7676
}
7777

7878
fn task_stall_root(args: &Args) {
79-
rayon::join(|| task(args), || wait_for_user());
79+
rayon::join(|| task(args), wait_for_user);
8080
}
8181

8282
fn task_stall_scope(args: &Args) {

rayon-core/Cargo.toml

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "rayon-core"
3-
version = "1.4.1" # reminder to update html_root_url attribute
3+
version = "1.5.0" # reminder to update html_root_url attribute
44
authors = ["Niko Matsakis <[email protected]>",
55
"Josh Stone <[email protected]>"]
66
description = "Core APIs for Rayon"
@@ -13,24 +13,20 @@ readme = "README.md"
1313
keywords = ["parallel", "thread", "concurrency", "join", "performance"]
1414
categories = ["concurrency"]
1515

16+
# Some dependencies may not be their latest version, in order to support older rustc.
1617
[dependencies]
1718
num_cpus = "1.2"
18-
libc = "0.2.16"
1919
lazy_static = "1"
20-
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-
26-
# Also held back for rustc compatibility
27-
[dependencies.crossbeam]
28-
version = "0.3.0"
20+
crossbeam-deque = "0.6.3"
21+
crossbeam-queue = "0.1.2"
2922

3023
[dev-dependencies]
3124
rand = "0.6"
3225
rand_xorshift = "0.1"
3326

27+
[target.'cfg(unix)'.dev-dependencies]
28+
libc = "0.2"
29+
3430
[[test]]
3531
name = "stack_overflow_crash"
3632
path = "tests/stack_overflow_crash.rs"

rayon-core/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ Please see [Rayon Docs] for details about using Rayon.
88

99
[Rayon Docs]: https://docs.rs/rayon/
1010

11-
Rayon-core currently requires `rustc 1.13.0` or greater.
11+
Rayon-core currently requires `rustc 1.26.0` or greater.

rayon-core/src/internal/worker.rs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,8 @@ pub fn if_in_worker_thread<F, R>(if_true: F) -> Option<R>
6060
where
6161
F: FnOnce(&WorkerThread) -> R,
6262
{
63-
let worker_thread = registry::WorkerThread::current();
64-
if worker_thread.is_null() {
65-
None
66-
} else {
67-
unsafe {
68-
let wt = WorkerThread {
69-
thread: &*worker_thread,
70-
};
71-
Some(if_true(&wt))
72-
}
63+
unsafe {
64+
let thread = registry::WorkerThread::current().as_ref()?;
65+
Some(if_true(&WorkerThread { thread }))
7366
}
7467
}

rayon-core/src/job.rs

Lines changed: 23 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
use crossbeam::sync::SegQueue;
1+
use crossbeam_queue::SegQueue;
22
use latch::Latch;
33
use std::any::Any;
44
use std::cell::UnsafeCell;
55
use std::mem;
66
use unwind;
77

8-
pub enum JobResult<T> {
8+
pub(super) enum JobResult<T> {
99
None,
1010
Ok(T),
1111
Panic(Box<Any + Send>),
@@ -16,7 +16,7 @@ pub enum JobResult<T> {
1616
/// arranged in a deque, so that thieves can take from the top of the
1717
/// deque while the main worker manages the bottom of the deque. This
1818
/// deque is managed by the `thread_pool` module.
19-
pub trait Job {
19+
pub(super) trait Job {
2020
/// Unsafe: this may be called from a different thread than the one
2121
/// which scheduled the job, so the implementer must ensure the
2222
/// appropriate traits are met, whether `Send`, `Sync`, or both.
@@ -30,7 +30,7 @@ pub trait Job {
3030
/// true type is something like `*const StackJob<...>`, but we hide
3131
/// it. We also carry the "execute fn" from the `Job` trait.
3232
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
33-
pub struct JobRef {
33+
pub(super) struct JobRef {
3434
pointer: *const (),
3535
execute_fn: unsafe fn(*const ()),
3636
}
@@ -41,24 +41,21 @@ unsafe impl Sync for JobRef {}
4141
impl JobRef {
4242
/// Unsafe: caller asserts that `data` will remain valid until the
4343
/// job is executed.
44-
pub unsafe fn new<T>(data: *const T) -> JobRef
44+
pub(super) unsafe fn new<T>(data: *const T) -> JobRef
4545
where
4646
T: Job,
4747
{
4848
let fn_ptr: unsafe fn(*const T) = <T as Job>::execute;
4949

5050
// erase types:
51-
let fn_ptr: unsafe fn(*const ()) = mem::transmute(fn_ptr);
52-
let pointer = data as *const ();
53-
5451
JobRef {
55-
pointer: pointer,
56-
execute_fn: fn_ptr,
52+
pointer: data as *const (),
53+
execute_fn: mem::transmute(fn_ptr),
5754
}
5855
}
5956

6057
#[inline]
61-
pub unsafe fn execute(&self) {
58+
pub(super) unsafe fn execute(&self) {
6259
(self.execute_fn)(self.pointer)
6360
}
6461
}
@@ -67,13 +64,13 @@ impl JobRef {
6764
/// executes it need not free any heap data, the cleanup occurs when
6865
/// the stack frame is later popped. The function parameter indicates
6966
/// `true` if the job was stolen -- executed on a different thread.
70-
pub struct StackJob<L, F, R>
67+
pub(super) struct StackJob<L, F, R>
7168
where
7269
L: Latch + Sync,
7370
F: FnOnce(bool) -> R + Send,
7471
R: Send,
7572
{
76-
pub latch: L,
73+
pub(super) latch: L,
7774
func: UnsafeCell<Option<F>>,
7875
result: UnsafeCell<JobResult<R>>,
7976
}
@@ -84,23 +81,23 @@ where
8481
F: FnOnce(bool) -> R + Send,
8582
R: Send,
8683
{
87-
pub fn new(func: F, latch: L) -> StackJob<L, F, R> {
84+
pub(super) fn new(func: F, latch: L) -> StackJob<L, F, R> {
8885
StackJob {
89-
latch: latch,
86+
latch,
9087
func: UnsafeCell::new(Some(func)),
9188
result: UnsafeCell::new(JobResult::None),
9289
}
9390
}
9491

95-
pub unsafe fn as_job_ref(&self) -> JobRef {
92+
pub(super) unsafe fn as_job_ref(&self) -> JobRef {
9693
JobRef::new(self)
9794
}
9895

99-
pub unsafe fn run_inline(self, stolen: bool) -> R {
96+
pub(super) unsafe fn run_inline(self, stolen: bool) -> R {
10097
self.func.into_inner().unwrap()(stolen)
10198
}
10299

103-
pub unsafe fn into_result(self) -> R {
100+
pub(super) unsafe fn into_result(self) -> R {
104101
self.result.into_inner().into_return_value()
105102
}
106103
}
@@ -130,7 +127,7 @@ where
130127
/// signal that the job executed.
131128
///
132129
/// (Probably `StackJob` should be refactored in a similar fashion.)
133-
pub struct HeapJob<BODY>
130+
pub(super) struct HeapJob<BODY>
134131
where
135132
BODY: FnOnce() + Send,
136133
{
@@ -141,7 +138,7 @@ impl<BODY> HeapJob<BODY>
141138
where
142139
BODY: FnOnce() + Send,
143140
{
144-
pub fn new(func: BODY) -> Self {
141+
pub(super) fn new(func: BODY) -> Self {
145142
HeapJob {
146143
job: UnsafeCell::new(Some(func)),
147144
}
@@ -150,7 +147,7 @@ where
150147
/// Creates a `JobRef` from this job -- note that this hides all
151148
/// lifetimes, so it is up to you to ensure that this JobRef
152149
/// doesn't outlive any data that it closes over.
153-
pub unsafe fn as_job_ref(self: Box<Self>) -> JobRef {
150+
pub(super) unsafe fn as_job_ref(self: Box<Self>) -> JobRef {
154151
let this: *const Self = mem::transmute(self);
155152
JobRef::new(this)
156153
}
@@ -172,7 +169,7 @@ impl<T> JobResult<T> {
172169
/// its JobResult is populated) into its return value.
173170
///
174171
/// NB. This will panic if the job panicked.
175-
pub fn into_return_value(self) -> T {
172+
pub(super) fn into_return_value(self) -> T {
176173
match self {
177174
JobResult::None => unreachable!(),
178175
JobResult::Ok(x) => x,
@@ -182,18 +179,18 @@ impl<T> JobResult<T> {
182179
}
183180

184181
/// Indirect queue to provide FIFO job priority.
185-
pub struct JobFifo {
182+
pub(super) struct JobFifo {
186183
inner: SegQueue<JobRef>,
187184
}
188185

189186
impl JobFifo {
190-
pub fn new() -> Self {
187+
pub(super) fn new() -> Self {
191188
JobFifo {
192189
inner: SegQueue::new(),
193190
}
194191
}
195192

196-
pub unsafe fn push(&self, job_ref: JobRef) -> JobRef {
193+
pub(super) unsafe fn push(&self, job_ref: JobRef) -> JobRef {
197194
// A little indirection ensures that spawns are always prioritized in FIFO order. The
198195
// jobs in a thread's deque may be popped from the back (LIFO) or stolen from the front
199196
// (FIFO), but either way they will end up popping from the front of this queue.
@@ -205,10 +202,6 @@ impl JobFifo {
205202
impl Job for JobFifo {
206203
unsafe fn execute(this: *const Self) {
207204
// We "execute" a queue by executing its first job, FIFO.
208-
(*this)
209-
.inner
210-
.try_pop()
211-
.expect("job in fifo queue")
212-
.execute()
205+
(*this).inner.pop().expect("job in fifo queue").execute()
213206
}
214207
}

rayon-core/src/join/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ where
171171
}
172172
}
173173

174-
return (result_a, job_b.into_result());
174+
(result_a, job_b.into_result())
175175
})
176176
}
177177

0 commit comments

Comments
 (0)