Skip to content

Commit

Permalink
adopt new approach to unstable features
Browse files Browse the repository at this point in the history
  • Loading branch information
nikomatsakis committed Jun 14, 2017
1 parent a46de7a commit 20de1ff
Show file tree
Hide file tree
Showing 12 changed files with 59 additions and 61 deletions.
16 changes: 8 additions & 8 deletions .travis.yml
Expand Up @@ -15,24 +15,24 @@ env:
matrix:
include:
- rust: stable
env: FEATURES=unstable
env: RUSTFLAGS='--cfg rayon_unstable'
os: linux
- rust: stable
env: FEATURES=unstable
env: RUSTFLAGS='--cfg rayon_unstable'
os: osx
- rust: nightly
env: FEATURES=unstable
env: RUSTFLAGS='--cfg rayon_unstable'
os: linux
- rust: nightly
env: FEATURES=unstable
env: RUSTFLAGS='--cfg rayon_unstable'
os: osx

script:
- cargo build --features="$FEATURES"
- cargo build
- |
if [ $TRAVIS_RUST_VERSION == nightly ]; then
cargo test --features="$FEATURES" &&
cargo test --features="$FEATURES" -p rayon-core &&
cargo test --features="$FEATURES" -p rayon-demo &&
cargo test &&
cargo test -p rayon-core &&
cargo test -p rayon-demo &&
./ci/highlander.sh
fi
5 changes: 0 additions & 5 deletions Cargo.toml
Expand Up @@ -21,8 +21,3 @@ docopt = "0.7"
futures = "0.1.7"
rand = "0.3"
rustc-serialize = "0.3"

[features]
# Unstable APIs that have not yet
# proven their utility.
unstable = ["rayon-core/unstable"]
21 changes: 15 additions & 6 deletions README.md
Expand Up @@ -40,7 +40,7 @@ as:

```rust
[dependencies]
rayon = XXX # <-- insert latest version of Rayon from crates.io here
rayon = 0.8.0
```

and then add the following to to your `lib.rs`:
Expand All @@ -51,7 +51,7 @@ extern crate rayon;

To use the Parallel Iterator APIs, a number of traits have to be in
scope. The easiest way to bring those things into scope is to use the
[Rayon prelude](https://docs.rs/rayon/0.8.0/rayon/prelude/index.html).
[Rayon prelude](https://docs.rs/rayon/*/rayon/prelude/index.html).
In each module where you would like to use the parallel iterator APIs,
just add:

Expand Down Expand Up @@ -426,10 +426,19 @@ interjected into our execution!

Rayon follows semver versioning. However, we also have APIs that are
still in the process of development and which may break from release
to release -- those APIs are not subject to semver. They are
accessible with the "unstable" cargo feature. Please do give them a
try -- but if you are using them, be aware that you (and all of your
dependencies!) will have to stay current with Rayon.
to release -- those APIs are not subject to semver. To use them,
you have to set the cfg flag `rayon_unstable`. The easiest way to do this
is to use the `RUSTFLAGS` environment variable:

```
RUSTFLAGS='--cfg rayon_unstable' cargo build
```

Note that this must not only be done for your crate, but for any crate
that depends on your crate. This infectious nature is intentional, as
it serves as a reminder that you are outside of the normal semver
guarantees. **If you see unstable APIs that you would like to use,
please request stabilization on the correspond tracking issue!**

Rayon itself is internally split into two crates. The `rayon` crate is
intended to be the main, user-facing crate, and hence all the
Expand Down
18 changes: 9 additions & 9 deletions appveyor.yml
Expand Up @@ -8,19 +8,19 @@ environment:
CHANNEL: stable
- TARGET: x86_64-pc-windows-gnu
CHANNEL: stable
FEATURES: unstable
RUSTFLAGS: --cfg rayon_unstable

- TARGET: x86_64-pc-windows-gnu
CHANNEL: beta
- TARGET: x86_64-pc-windows-gnu
CHANNEL: beta
FEATURES: unstable
RUSTFLAGS: --cfg rayon_unstable

- TARGET: x86_64-pc-windows-gnu
CHANNEL: nightly
- TARGET: x86_64-pc-windows-gnu
CHANNEL: nightly
FEATURES: unstable
RUSTFLAGS: --cfg rayon_unstable


- TARGET: x86_64-pc-windows-msvc
Expand All @@ -30,19 +30,19 @@ environment:
CHANNEL: stable
- TARGET: x86_64-pc-windows-msvc
CHANNEL: stable
FEATURES: unstable
RUSTFLAGS: --cfg rayon_unstable

- TARGET: x86_64-pc-windows-msvc
CHANNEL: beta
- TARGET: x86_64-pc-windows-msvc
CHANNEL: beta
FEATURES: unstable
RUSTFLAGS: --cfg rayon_unstable

- TARGET: x86_64-pc-windows-msvc
CHANNEL: nightly
- TARGET: x86_64-pc-windows-msvc
CHANNEL: nightly
FEATURES: unstable
RUSTFLAGS: --cfg rayon_unstable

install:
- curl -sSf -o rustup-init.exe https://win.rustup.rs
Expand All @@ -54,8 +54,8 @@ install:
build: false

test_script:
- cargo build --features="%FEATURES%"
- cargo build
- if [%CHANNEL%]==[nightly] (
cargo test --features="%FEATURES%" -p rayon-core &&
cargo test --features="%FEATURES%" -p rayon-demo
cargo test -p rayon-core &&
cargo test -p rayon-demo
)
6 changes: 3 additions & 3 deletions examples/cpu_monitor.rs
Expand Up @@ -77,16 +77,16 @@ fn task_stall_root(args: &Args) {
rayon::join(|| task(args), || wait_for_user());
}

#[cfg(feature = "unstable")]
#[cfg(rayon_unstable)]
fn task_stall_scope(args: &Args) {
rayon::scope(|scope| {
scope.spawn(move |_| task(args));
scope.spawn(move |_| wait_for_user());
});
}

#[cfg(not(feature = "unstable"))]
#[cfg(not(rayon_unstable))]
fn task_stall_scope(_args: &Args) {
println!("try `cargo run` with `--features unstable`");
println!("try `RUSTFLAGS='--cfg rayon_unstable' cargo run`");
process::exit(1);
}
9 changes: 3 additions & 6 deletions rayon-core/Cargo.toml
Expand Up @@ -16,11 +16,8 @@ num_cpus = "1.2"
coco = "0.1.1"
libc = "0.2.16"
lazy_static = "0.2.2"
futures = { version = "0.1.7", optional = true }

[dev-dependencies]
# only if #[cfg(rayon_unstable)], will be removed eventually
futures = "0.1.7"

[features]
# Unstable APIs that have not yet
# proven their utility.
unstable = ["futures"]
[dev-dependencies]
12 changes: 6 additions & 6 deletions rayon-core/src/lib.rs
Expand Up @@ -38,7 +38,7 @@ use std::fmt;
extern crate coco;
#[macro_use]
extern crate lazy_static;
#[cfg(feature = "unstable")]
#[cfg(rayon_unstable)]
extern crate futures;
extern crate libc;
extern crate num_cpus;
Expand All @@ -51,11 +51,11 @@ mod latch;
mod join;
mod job;
mod registry;
#[cfg(feature = "unstable")]
#[cfg(rayon_unstable)]
mod future;
mod scope;
mod sleep;
#[cfg(feature = "unstable")]
#[cfg(rayon_unstable)]
mod spawn;
mod test;
mod thread_pool;
Expand All @@ -67,11 +67,11 @@ pub use thread_pool::current_thread_index;
pub use thread_pool::current_thread_has_pending_tasks;
pub use join::join;
pub use scope::{scope, Scope};
#[cfg(feature = "unstable")]
#[cfg(rayon_unstable)]
pub use spawn::spawn;
#[cfg(feature = "unstable")]
#[cfg(rayon_unstable)]
pub use spawn::spawn_future;
#[cfg(feature = "unstable")]
#[cfg(rayon_unstable)]
pub use future::RayonFuture;

/// Returns the number of threads in the current registry. If this
Expand Down
4 changes: 2 additions & 2 deletions rayon-core/src/scope/mod.rs
@@ -1,4 +1,4 @@
#[cfg(feature = "unstable")]
#[cfg(rayon_unstable)]
use future::{self, Future, RayonFuture};
use latch::{Latch, CountLatch};
use log::Event::*;
Expand Down Expand Up @@ -284,7 +284,7 @@ impl<'scope> Scope<'scope> {
}
}

#[cfg(feature = "unstable")]
#[cfg(rayon_unstable)]
pub fn spawn_future<F>(&self, future: F) -> RayonFuture<F::Item, F::Error>
where F: Future + Send + 'scope
{
Expand Down
14 changes: 7 additions & 7 deletions rayon-core/src/thread_pool/mod.rs
@@ -1,13 +1,13 @@
use Configuration;
#[cfg(feature = "unstable")]
#[cfg(rayon_unstable)]
use future::{Future, RayonFuture};
use latch::LockLatch;
#[allow(unused_imports)]
use log::Event::*;
use job::StackJob;
use join;
use {scope, Scope};
#[cfg(feature = "unstable")]
#[cfg(rayon_unstable)]
use spawn;
use std::sync::Arc;
use std::error::Error;
Expand Down Expand Up @@ -68,7 +68,7 @@ impl ThreadPool {
/// `rayon::initialize()` function][f] to do so.
///
/// [f]: fn.initialize.html
#[cfg(feature = "unstable")]
#[cfg(rayon_unstable)]
pub fn global() -> &'static Arc<ThreadPool> {
lazy_static! {
static ref DEFAULT_THREAD_POOL: Arc<ThreadPool> =
Expand Down Expand Up @@ -208,7 +208,7 @@ impl ThreadPool {
/// Execute `oper_a` and `oper_b` in the thread-pool and return
/// the results. Equivalent to `self.install(|| join(oper_a,
/// oper_b))`.
#[cfg(feature = "unstable")]
#[cfg(rayon_unstable)]
pub fn join<A, B, RA, RB>(&self, oper_a: A, oper_b: B) -> (RA, RB)
where A: FnOnce() -> RA + Send,
B: FnOnce() -> RB + Send,
Expand All @@ -224,7 +224,7 @@ impl ThreadPool {
/// See also: [the `scope()` function][scope].
///
/// [scope]: fn.scope.html
#[cfg(feature = "unstable")]
#[cfg(rayon_unstable)]
pub fn scope<'scope, OP, R>(&self, op: OP) -> R
where OP: for<'s> FnOnce(&'s Scope<'scope>) -> R + 'scope + Send, R: Send
{
Expand All @@ -239,7 +239,7 @@ impl ThreadPool {
/// See also: [the `spawn()` function defined on scopes][spawn].
///
/// [spawn]: struct.Scope.html#method.spawn
#[cfg(feature = "unstable")]
#[cfg(rayon_unstable)]
pub fn spawn<OP>(&self, op: OP)
where OP: FnOnce() + Send + 'static
{
Expand Down Expand Up @@ -278,7 +278,7 @@ impl ThreadPool {
/// See also: [the `spawn_future()` function defined on scopes][spawn_future].
///
/// [spawn_future]: struct.Scope.html#method.spawn_future
#[cfg(feature = "unstable")]
#[cfg(rayon_unstable)]
pub fn spawn_future<F>(&self, future: F) -> RayonFuture<F::Item, F::Error>
where F: Future + Send + 'static
{
Expand Down
3 changes: 0 additions & 3 deletions rayon-demo/Cargo.toml
Expand Up @@ -18,6 +18,3 @@ regex = "0.2"

[dev-dependencies]
num = "0.1.30"

[features]
unstable = ["rayon/unstable"]
6 changes: 3 additions & 3 deletions src/lib.rs
Expand Up @@ -39,9 +39,9 @@ pub use rayon_core::initialize;
pub use rayon_core::ThreadPool;
pub use rayon_core::join;
pub use rayon_core::{scope, Scope};
#[cfg(feature = "unstable")]
#[cfg(rayon_unstable)]
pub use rayon_core::spawn;
#[cfg(feature = "unstable")]
#[cfg(rayon_unstable)]
pub use rayon_core::spawn_future;
#[cfg(feature = "unstable")]
#[cfg(rayon_unstable)]
pub use rayon_core::RayonFuture;
6 changes: 3 additions & 3 deletions src/test.rs
Expand Up @@ -19,7 +19,7 @@ fn negative_tests_compile_fail() {
}

#[test]
#[cfg(feature = "unstable")]
#[cfg(rayon_unstable)]
fn negative_tests_compile_fail_unstable() {
run_compiletest("compile-fail", "tests/compile-fail-unstable");
}
Expand All @@ -30,7 +30,7 @@ fn negative_tests_run_fail() {
}

#[test]
#[cfg(feature = "unstable")]
#[cfg(rayon_unstable)]
fn negative_tests_run_fail_unstable() {
run_compiletest("run-fail", "tests/run-fail-unstable");
}
Expand All @@ -41,7 +41,7 @@ fn positive_test_run_pass() {
}

#[test]
#[cfg(feature = "unstable")]
#[cfg(rayon_unstable)]
fn positive_test_run_pass_unstable() {
run_compiletest("run-pass", "tests/run-pass-unstable");
}

0 comments on commit 20de1ff

Please sign in to comment.