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

feat: decompose macros feature as macros-decl and macros-proc #4804

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tests-integration/tests/macros_main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![cfg(all(feature = "macros", feature = "rt"))]
#![cfg(all(feature = "macros-proc", feature = "rt"))]

#[tokio::main]
async fn basic_main() -> usize {
Expand Down
6 changes: 5 additions & 1 deletion tokio/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@ fs = []
io-util = ["memchr", "bytes"]
# stdin, stdout, stderr
io-std = []
macros = ["tokio-macros"]

macros = ["macros-decl", "macros-proc"]
macros-decl = [] # Declarative Macros
macros-proc = ["tokio-macros"] # Procedural Marcos

net = [
"libc",
"mio/os-poll",
Expand Down
4 changes: 2 additions & 2 deletions tokio/src/future/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#![cfg_attr(not(feature = "macros"), allow(unreachable_pub))]
#![cfg_attr(not(feature = "macros-decl"), allow(unreachable_pub))]

//! Asynchronous values.

#[cfg(any(feature = "macros", feature = "process"))]
#[cfg(any(feature = "macros-decl", feature = "process"))]
pub(crate) mod maybe_done;

mod poll_fn;
Expand Down
10 changes: 6 additions & 4 deletions tokio/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,9 @@
//! - `time`: Enables `tokio::time` types and allows the schedulers to enable
//! the built in timer.
//! - `process`: Enables `tokio::process` types.
//! - `macros`: Enables `#[tokio::main]` and `#[tokio::test]` macros.
//! - `macros`: Enables both `macros-decl` and `macros-proc` features (for convenience).
//! - `macros-decl`: Enables the `join!`, `try_join!`, and `select!` declarative macros.
//! - `macros-proc`: Enables `#[tokio::main]` and `#[tokio::test]` attribute macros.
//! - `sync`: Enables all `tokio::sync` types.
//! - `signal`: Enables all `tokio::signal` types.
//! - `fs`: Enables `tokio::fs` types.
Expand Down Expand Up @@ -516,7 +518,7 @@ pub(crate) use self::doc::winapi;
#[allow(unused)]
pub(crate) use winapi;

cfg_macros! {
cfg_macros_proc! {
/// Implementation detail of the `select!` macro. This macro is **not**
/// intended to be used as part of the public API and is permitted to
/// change.
Expand All @@ -532,12 +534,12 @@ cfg_macros! {
cfg_rt! {
#[cfg(feature = "rt-multi-thread")]
#[cfg(not(test))] // Work around for rust-lang/rust#62127
#[cfg_attr(docsrs, doc(cfg(feature = "macros")))]
#[cfg_attr(docsrs, doc(cfg(feature = "macros-proc")))]
#[doc(inline)]
pub use tokio_macros::main;

#[cfg(feature = "rt-multi-thread")]
#[cfg_attr(docsrs, doc(cfg(feature = "macros")))]
#[cfg_attr(docsrs, doc(cfg(feature = "macros-proc")))]
#[doc(inline)]
pub use tokio_macros::test;

Expand Down
16 changes: 13 additions & 3 deletions tokio/src/macros/cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,21 @@ macro_rules! cfg_not_loom {
}
}

macro_rules! cfg_macros {
macro_rules! cfg_macros_decl {
($($item:item)*) => {
$(
#[cfg(feature = "macros")]
#[cfg_attr(docsrs, doc(cfg(feature = "macros")))]
#[cfg(feature = "macros-decl")]
#[cfg_attr(docsrs, doc(cfg(feature = "macros-decl")))]
$item
)*
}
}

macro_rules! cfg_macros_proc {
($($item:item)*) => {
$(
#[cfg(feature = "macros-proc")]
#[cfg_attr(docsrs, doc(cfg(feature = "macros-proc")))]
$item
)*
}
Expand Down
2 changes: 1 addition & 1 deletion tokio/src/macros/join.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
/// }
/// ```
#[macro_export]
#[cfg_attr(docsrs, doc(cfg(feature = "macros")))]
#[cfg_attr(docsrs, doc(cfg(feature = "macros-decl")))]
macro_rules! join {
(@ {
// One `_` for each branch in the `join!` macro. This is not used once
Expand Down
2 changes: 1 addition & 1 deletion tokio/src/macros/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ cfg_trace! {
#[cfg(feature = "rt")]
pub(crate) mod scoped_tls;

cfg_macros! {
cfg_macros_decl! {
#[macro_use]
mod select;

Expand Down
2 changes: 1 addition & 1 deletion tokio/src/macros/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@
/// }
/// ```
#[macro_export]
#[cfg_attr(docsrs, doc(cfg(feature = "macros")))]
#[cfg_attr(docsrs, doc(cfg(feature = "macros-decl")))]
macro_rules! select {
// Uses a declarative macro to do **most** of the work. While it is possible
// to implement fully with a declarative macro, a procedural macro is used
Expand Down
2 changes: 1 addition & 1 deletion tokio/src/macros/support.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cfg_macros! {
cfg_macros_decl! {
pub use crate::future::poll_fn;
pub use crate::future::maybe_done::maybe_done;
pub use crate::util::thread_rng_n;
Expand Down
2 changes: 1 addition & 1 deletion tokio/src/macros/try_join.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
/// }
/// ```
#[macro_export]
#[cfg_attr(docsrs, doc(cfg(feature = "macros")))]
#[cfg_attr(docsrs, doc(cfg(feature = "macros-decl")))]
macro_rules! try_join {
(@ {
// One `_` for each branch in the `try_join!` macro. This is not used once
Expand Down
6 changes: 3 additions & 3 deletions tokio/src/util/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ pub(crate) use wake_list::WakeList;
))]
pub(crate) mod linked_list;

#[cfg(any(feature = "rt-multi-thread", feature = "macros"))]
#[cfg(any(feature = "rt-multi-thread", feature = "macros-decl"))]
mod rand;

cfg_rt! {
Expand Down Expand Up @@ -69,8 +69,8 @@ cfg_rt_multi_thread! {

pub(crate) mod trace;

#[cfg(any(feature = "macros"))]
#[cfg_attr(not(feature = "macros"), allow(unreachable_pub))]
#[cfg(any(feature = "macros-decl"))]
#[cfg_attr(not(feature = "macros-decl"), allow(unreachable_pub))]
pub use self::rand::thread_rng_n;

#[cfg(any(
Expand Down
4 changes: 2 additions & 2 deletions tokio/src/util/rand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ impl FastRand {
}

// Used by the select macro and `StreamMap`
#[cfg(any(feature = "macros"))]
#[cfg(any(feature = "macros-decl"))]
#[doc(hidden)]
#[cfg_attr(not(feature = "macros"), allow(unreachable_pub))]
#[cfg_attr(not(feature = "macros-decl"), allow(unreachable_pub))]
pub fn thread_rng_n(n: u32) -> u32 {
thread_local! {
static THREAD_RNG: FastRand = FastRand::new(crate::loom::rand::seed());
Expand Down