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 04cecad
Show file tree
Hide file tree
Showing 11 changed files with 49 additions and 51 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"]
19 changes: 14 additions & 5 deletions README.md
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 open an issue about stabilizing them!**

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 All @@ -441,7 +450,7 @@ features). The intention is that multiple semver-incompatible versions
of the rayon crate can peacefully coexist; they will all share one
global thread-pool through the `rayon-core` crate.

## License
## Unstable features## License

Rayon is distributed under the terms of both the MIT license and the
Apache License (Version 2.0). See [LICENSE-APACHE](LICENSE-APACHE) and
Expand Down
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 04cecad

Please sign in to comment.