Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove cfg_target_has_atomic! macro #2439

Merged
merged 1 commit into from May 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Expand Up @@ -246,8 +246,8 @@ jobs:
steps:
- uses: actions/checkout@v2
- name: Install Rust
run: rustup update stable && rustup default stable
- run: tools/fmt.sh
run: rustup update stable
- run: cargo fmt --all -- --check

docs:
name: cargo doc
Expand Down
5 changes: 5 additions & 0 deletions ci/no_atomic_cas.sh
@@ -1,5 +1,10 @@
#!/bin/bash

# Update the list of targets that do not support atomic CAS operations.
#
# Usage:
# ./ci/no_atomic_cas.sh

set -euo pipefail
IFS=$'\n\t'

Expand Down
2 changes: 1 addition & 1 deletion futures-channel/build.rs
Expand Up @@ -8,7 +8,7 @@ include!("no_atomic_cas.rs");
// and outside of the normal semver guarantees:
//
// - `futures_no_atomic_cas`
// Assume the target does not have atomic CAS (compare-and-swap).
// Assume the target does *not* support atomic CAS operations.
// This is usually detected automatically by the build script, but you may
// need to enable it manually when building for custom targets or using
// non-cargo build systems that don't run the build script.
Expand Down
29 changes: 12 additions & 17 deletions futures-channel/src/lib.rs
Expand Up @@ -18,21 +18,16 @@
#![warn(clippy::all)]
#![doc(test(attr(deny(warnings), allow(dead_code, unused_assignments, unused_variables))))]

macro_rules! cfg_target_has_atomic {
($($item:item)*) => {$(
#[cfg(not(futures_no_atomic_cas))]
$item
)*};
}
#[cfg(not(futures_no_atomic_cas))]
#[cfg(feature = "alloc")]
extern crate alloc;

cfg_target_has_atomic! {
#[cfg(feature = "alloc")]
extern crate alloc;

#[cfg(feature = "alloc")]
mod lock;
#[cfg(feature = "std")]
pub mod mpsc;
#[cfg(feature = "alloc")]
pub mod oneshot;
}
#[cfg(not(futures_no_atomic_cas))]
#[cfg(feature = "alloc")]
mod lock;
#[cfg(not(futures_no_atomic_cas))]
#[cfg(feature = "std")]
pub mod mpsc;
#[cfg(not(futures_no_atomic_cas))]
#[cfg(feature = "alloc")]
pub mod oneshot;
2 changes: 1 addition & 1 deletion futures-core/build.rs
Expand Up @@ -8,7 +8,7 @@ include!("no_atomic_cas.rs");
// and outside of the normal semver guarantees:
//
// - `futures_no_atomic_cas`
// Assume the target does not have atomic CAS (compare-and-swap).
// Assume the target does *not* support atomic CAS operations.
// This is usually detected automatically by the build script, but you may
// need to enable it manually when building for custom targets or using
// non-cargo build systems that don't run the build script.
Expand Down
2 changes: 1 addition & 1 deletion futures-task/build.rs
Expand Up @@ -8,7 +8,7 @@ include!("no_atomic_cas.rs");
// and outside of the normal semver guarantees:
//
// - `futures_no_atomic_cas`
// Assume the target does not have atomic CAS (compare-and-swap).
// Assume the target does *not* support atomic CAS operations.
// This is usually detected automatically by the build script, but you may
// need to enable it manually when building for custom targets or using
// non-cargo build systems that don't run the build script.
Expand Down
43 changes: 20 additions & 23 deletions futures-task/src/lib.rs
Expand Up @@ -10,32 +10,29 @@
#[cfg(feature = "alloc")]
extern crate alloc;

macro_rules! cfg_target_has_atomic {
($($item:item)*) => {$(
#[cfg(not(futures_no_atomic_cas))]
$item
)*};
}

mod spawn;
pub use crate::spawn::{LocalSpawn, Spawn, SpawnError};

cfg_target_has_atomic! {
#[cfg(feature = "alloc")]
mod arc_wake;
#[cfg(feature = "alloc")]
pub use crate::arc_wake::ArcWake;

#[cfg(feature = "alloc")]
mod waker;
#[cfg(feature = "alloc")]
pub use crate::waker::waker;

#[cfg(feature = "alloc")]
mod waker_ref;
#[cfg(feature = "alloc")]
pub use crate::waker_ref::{waker_ref, WakerRef};
}
#[cfg(not(futures_no_atomic_cas))]
#[cfg(feature = "alloc")]
mod arc_wake;
#[cfg(not(futures_no_atomic_cas))]
#[cfg(feature = "alloc")]
pub use crate::arc_wake::ArcWake;

#[cfg(not(futures_no_atomic_cas))]
#[cfg(feature = "alloc")]
mod waker;
#[cfg(not(futures_no_atomic_cas))]
#[cfg(feature = "alloc")]
pub use crate::waker::waker;

#[cfg(not(futures_no_atomic_cas))]
#[cfg(feature = "alloc")]
mod waker_ref;
#[cfg(not(futures_no_atomic_cas))]
#[cfg(feature = "alloc")]
pub use crate::waker_ref::{waker_ref, WakerRef};

mod future_obj;
pub use crate::future_obj::{FutureObj, LocalFutureObj, UnsafeFutureObj};
Expand Down
32 changes: 15 additions & 17 deletions futures-task/src/spawn.rs
Expand Up @@ -168,27 +168,25 @@ mod if_alloc {
}
}

cfg_target_has_atomic! {
use alloc::{ sync::Arc };

impl<Sp: ?Sized + Spawn> Spawn for Arc<Sp> {
fn spawn_obj(&self, future: FutureObj<'static, ()>) -> Result<(), SpawnError> {
(**self).spawn_obj(future)
}
#[cfg(not(futures_no_atomic_cas))]
impl<Sp: ?Sized + Spawn> Spawn for alloc::sync::Arc<Sp> {
fn spawn_obj(&self, future: FutureObj<'static, ()>) -> Result<(), SpawnError> {
(**self).spawn_obj(future)
}

fn status(&self) -> Result<(), SpawnError> {
(**self).status()
}
fn status(&self) -> Result<(), SpawnError> {
(**self).status()
}
}

impl<Sp: ?Sized + LocalSpawn> LocalSpawn for Arc<Sp> {
fn spawn_local_obj(&self, future: LocalFutureObj<'static, ()>) -> Result<(), SpawnError> {
(**self).spawn_local_obj(future)
}
#[cfg(not(futures_no_atomic_cas))]
impl<Sp: ?Sized + LocalSpawn> LocalSpawn for alloc::sync::Arc<Sp> {
fn spawn_local_obj(&self, future: LocalFutureObj<'static, ()>) -> Result<(), SpawnError> {
(**self).spawn_local_obj(future)
}

fn status_local(&self) -> Result<(), SpawnError> {
(**self).status_local()
}
fn status_local(&self) -> Result<(), SpawnError> {
(**self).status_local()
}
}
}
2 changes: 1 addition & 1 deletion futures-util/build.rs
Expand Up @@ -9,7 +9,7 @@ include!("no_atomic_cas.rs");
// and outside of the normal semver guarantees:
//
// - `futures_no_atomic_cas`
// Assume the target does not have atomic CAS (compare-and-swap).
// Assume the target does *not* support atomic CAS operations.
// This is usually detected automatically by the build script, but you may
// need to enable it manually when building for custom targets or using
// non-cargo build systems that don't run the build script.
Expand Down
17 changes: 9 additions & 8 deletions futures-util/src/future/mod.rs
Expand Up @@ -106,14 +106,15 @@ pub use self::select_ok::{select_ok, SelectOk};
mod either;
pub use self::either::Either;

cfg_target_has_atomic! {
#[cfg(feature = "alloc")]
mod abortable;
#[cfg(feature = "alloc")]
pub use crate::abortable::{Abortable, AbortHandle, AbortRegistration, Aborted};
#[cfg(feature = "alloc")]
pub use abortable::abortable;
}
#[cfg(not(futures_no_atomic_cas))]
#[cfg(feature = "alloc")]
mod abortable;
#[cfg(not(futures_no_atomic_cas))]
#[cfg(feature = "alloc")]
pub use crate::abortable::{AbortHandle, AbortRegistration, Abortable, Aborted};
#[cfg(not(futures_no_atomic_cas))]
#[cfg(feature = "alloc")]
pub use abortable::abortable;

// Just a helper function to ensure the futures we're returning all have the
// right implementations.
Expand Down
14 changes: 3 additions & 11 deletions futures-util/src/lib.rs
Expand Up @@ -47,13 +47,6 @@ pub mod __private {
}
}

macro_rules! cfg_target_has_atomic {
($($item:item)*) => {$(
#[cfg(not(futures_no_atomic_cas))]
$item
)*};
}

#[cfg(feature = "sink")]
macro_rules! delegate_sink {
($field:ident, $item:ty) => {
Expand Down Expand Up @@ -334,10 +327,9 @@ pub use crate::io::{
#[cfg(feature = "alloc")]
pub mod lock;

cfg_target_has_atomic! {
#[cfg(feature = "alloc")]
mod abortable;
}
#[cfg(not(futures_no_atomic_cas))]
#[cfg(feature = "alloc")]
mod abortable;

mod fns;
mod unfold_state;
35 changes: 19 additions & 16 deletions futures-util/src/lock/mod.rs
Expand Up @@ -3,20 +3,23 @@
//! This module is only available when the `std` or `alloc` feature of this
//! library is activated, and it is activated by default.

cfg_target_has_atomic! {
#[cfg(feature = "std")]
mod mutex;
#[cfg(feature = "std")]
pub use self::mutex::{MappedMutexGuard, Mutex, MutexLockFuture, MutexGuard};
#[cfg(not(futures_no_atomic_cas))]
#[cfg(feature = "std")]
mod mutex;
#[cfg(not(futures_no_atomic_cas))]
#[cfg(feature = "std")]
pub use self::mutex::{MappedMutexGuard, Mutex, MutexGuard, MutexLockFuture};

#[cfg(any(feature = "bilock", feature = "sink", feature = "io"))]
#[cfg_attr(docsrs, doc(cfg(feature = "bilock")))]
#[cfg_attr(not(feature = "bilock"), allow(unreachable_pub))]
mod bilock;
#[cfg(feature = "bilock")]
#[cfg_attr(docsrs, doc(cfg(feature = "bilock")))]
pub use self::bilock::{BiLock, BiLockAcquire, BiLockGuard, ReuniteError};
#[cfg(any(feature = "sink", feature = "io"))]
#[cfg(not(feature = "bilock"))]
pub(crate) use self::bilock::BiLock;
}
#[cfg(not(futures_no_atomic_cas))]
#[cfg(any(feature = "bilock", feature = "sink", feature = "io"))]
#[cfg_attr(docsrs, doc(cfg(feature = "bilock")))]
#[cfg_attr(not(feature = "bilock"), allow(unreachable_pub))]
mod bilock;
#[cfg(not(futures_no_atomic_cas))]
#[cfg(any(feature = "sink", feature = "io"))]
#[cfg(not(feature = "bilock"))]
pub(crate) use self::bilock::BiLock;
#[cfg(not(futures_no_atomic_cas))]
#[cfg(feature = "bilock")]
#[cfg_attr(docsrs, doc(cfg(feature = "bilock")))]
pub use self::bilock::{BiLock, BiLockAcquire, BiLockGuard, ReuniteError};
55 changes: 31 additions & 24 deletions futures-util/src/stream/mod.rs
Expand Up @@ -92,30 +92,37 @@ pub use self::select::{select, Select};
mod unfold;
pub use self::unfold::{unfold, Unfold};

cfg_target_has_atomic! {
#[cfg(feature = "alloc")]
mod futures_ordered;
#[cfg(feature = "alloc")]
pub use self::futures_ordered::FuturesOrdered;

#[cfg(feature = "alloc")]
pub mod futures_unordered;
#[cfg(feature = "alloc")]
#[doc(inline)]
pub use self::futures_unordered::FuturesUnordered;

#[cfg(feature = "alloc")]
pub mod select_all;
#[cfg(feature = "alloc")]
pub use self::select_all::{select_all, SelectAll};

#[cfg(feature = "alloc")]
mod abortable;
#[cfg(feature = "alloc")]
pub use crate::abortable::{Abortable, AbortHandle, AbortRegistration, Aborted};
#[cfg(feature = "alloc")]
pub use abortable::abortable;
}
#[cfg(not(futures_no_atomic_cas))]
#[cfg(feature = "alloc")]
mod futures_ordered;
#[cfg(not(futures_no_atomic_cas))]
#[cfg(feature = "alloc")]
pub use self::futures_ordered::FuturesOrdered;

#[cfg(not(futures_no_atomic_cas))]
#[cfg(feature = "alloc")]
pub mod futures_unordered;
#[cfg(not(futures_no_atomic_cas))]
#[cfg(feature = "alloc")]
#[doc(inline)]
pub use self::futures_unordered::FuturesUnordered;

#[cfg(not(futures_no_atomic_cas))]
#[cfg(feature = "alloc")]
pub mod select_all;
#[cfg(not(futures_no_atomic_cas))]
#[cfg(feature = "alloc")]
pub use self::select_all::{select_all, SelectAll};

#[cfg(not(futures_no_atomic_cas))]
#[cfg(feature = "alloc")]
mod abortable;
#[cfg(not(futures_no_atomic_cas))]
#[cfg(feature = "alloc")]
pub use crate::abortable::{AbortHandle, AbortRegistration, Abortable, Aborted};
#[cfg(not(futures_no_atomic_cas))]
#[cfg(feature = "alloc")]
pub use abortable::abortable;

// Just a helper function to ensure the streams we're returning all have the
// right implementations.
Expand Down