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

rt: simplify rt-* features #2949

Merged
merged 4 commits into from Oct 12, 2020
Merged
Show file tree
Hide file tree
Changes from 3 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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Expand Up @@ -110,7 +110,7 @@ jobs:
rm -rf tokio/tests

- name: miri
run: cargo miri test --features rt-core,rt-threaded,rt-util,sync task
run: cargo miri test --features rt,rt-multi-thread,sync task
working-directory: tokio

cross:
Expand Down
2 changes: 1 addition & 1 deletion tests-build/Cargo.toml
Expand Up @@ -7,7 +7,7 @@ publish = false

[features]
full = ["tokio/full"]
rt-core = ["tokio/rt-core", "tokio/macros"]
rt = ["tokio/rt", "tokio/macros"]

[dependencies]
tokio = { path = "../tokio", optional = true }
Expand Down
2 changes: 1 addition & 1 deletion tests-build/tests/fail/macros_core_no_default.stderr
@@ -1,4 +1,4 @@
error: The default runtime flavor is `multi_thread`, but the `rt-threaded` feature is disabled.
error: The default runtime flavor is `multi_thread`, but the `rt-multi-thread` feature is disabled.
--> $DIR/macros_core_no_default.rs:3:1
|
3 | #[tokio::main]
Expand Down
2 changes: 1 addition & 1 deletion tests-build/tests/macros.rs
Expand Up @@ -5,7 +5,7 @@ fn compile_fail_full() {
#[cfg(feature = "full")]
t.compile_fail("tests/fail/macros_invalid_input.rs");

#[cfg(all(feature = "rt-core", not(feature = "full")))]
#[cfg(all(feature = "rt", not(feature = "full")))]
t.compile_fail("tests/fail/macros_core_no_default.rs");

drop(t);
Expand Down
8 changes: 4 additions & 4 deletions tests-integration/Cargo.toml
Expand Up @@ -8,16 +8,16 @@ publish = false
[features]
full = [
"macros",
"rt-core",
"rt-threaded",
"rt",
"rt-multi-thread",

"tokio/full",
"tokio-test"
]
macros = ["tokio/macros"]
sync = ["tokio/sync"]
rt-core = ["tokio/rt-core"]
rt-threaded = ["rt-core", "tokio/rt-threaded"]
rt = ["tokio/rt"]
rt-multi-thread = ["rt", "tokio/rt-multi-thread"]

[dependencies]
tokio = { path = "../tokio" }
Expand Down
2 changes: 1 addition & 1 deletion tests-integration/tests/macros_main.rs
@@ -1,4 +1,4 @@
#![cfg(all(feature = "macros", feature = "rt-core"))]
#![cfg(all(feature = "macros", feature = "rt"))]

#[tokio::main]
async fn basic_main() -> usize {
Expand Down
24 changes: 12 additions & 12 deletions tokio-macros/src/entry.rs
Expand Up @@ -28,16 +28,16 @@ struct FinalConfig {
}

struct Configuration {
rt_threaded_available: bool,
rt_multi_thread_available: bool,
default_flavor: RuntimeFlavor,
flavor: Option<RuntimeFlavor>,
worker_threads: Option<(usize, Span)>,
}

impl Configuration {
fn new(is_test: bool, rt_threaded: bool) -> Self {
fn new(is_test: bool, rt_multi_thread: bool) -> Self {
Configuration {
rt_threaded_available: rt_threaded,
rt_multi_thread_available: rt_multi_thread,
default_flavor: match is_test {
true => RuntimeFlavor::CurrentThread,
false => RuntimeFlavor::Threaded,
Expand Down Expand Up @@ -91,15 +91,15 @@ impl Configuration {
flavor,
worker_threads: None,
}),
(Threaded, worker_threads) if self.rt_threaded_available => Ok(FinalConfig {
(Threaded, worker_threads) if self.rt_multi_thread_available => Ok(FinalConfig {
flavor,
worker_threads: worker_threads.map(|(val, _span)| val),
}),
(Threaded, _) => {
let msg = if self.flavor.is_none() {
"The default runtime flavor is `multi_thread`, but the `rt-threaded` feature is disabled."
"The default runtime flavor is `multi_thread`, but the `rt-multi-thread` feature is disabled."
} else {
"The runtime flavor `multi_thread` requires the `rt-threaded` feature."
"The runtime flavor `multi_thread` requires the `rt-multi-thread` feature."
};
Err(syn::Error::new(Span::call_site(), msg))
}
Expand Down Expand Up @@ -138,7 +138,7 @@ fn parse_knobs(
mut input: syn::ItemFn,
args: syn::AttributeArgs,
is_test: bool,
rt_threaded: bool,
rt_multi_thread: bool,
) -> Result<TokenStream, syn::Error> {
let sig = &mut input.sig;
let body = &input.block;
Expand All @@ -157,7 +157,7 @@ fn parse_knobs(
} else {
"tokio::main"
};
let mut config = Configuration::new(is_test, rt_threaded);
let mut config = Configuration::new(is_test, rt_multi_thread);

for arg in args {
match arg {
Expand Down Expand Up @@ -256,7 +256,7 @@ fn parse_knobs(
}

#[cfg(not(test))] // Work around for rust-lang/rust#62127
pub(crate) fn main(args: TokenStream, item: TokenStream, rt_threaded: bool) -> TokenStream {
pub(crate) fn main(args: TokenStream, item: TokenStream, rt_multi_thread: bool) -> TokenStream {
let input = syn::parse_macro_input!(item as syn::ItemFn);
let args = syn::parse_macro_input!(args as syn::AttributeArgs);

Expand All @@ -267,10 +267,10 @@ pub(crate) fn main(args: TokenStream, item: TokenStream, rt_threaded: bool) -> T
.into();
}

parse_knobs(input, args, false, rt_threaded).unwrap_or_else(|e| e.to_compile_error().into())
parse_knobs(input, args, false, rt_multi_thread).unwrap_or_else(|e| e.to_compile_error().into())
}

pub(crate) fn test(args: TokenStream, item: TokenStream, rt_threaded: bool) -> TokenStream {
pub(crate) fn test(args: TokenStream, item: TokenStream, rt_multi_thread: bool) -> TokenStream {
let input = syn::parse_macro_input!(item as syn::ItemFn);
let args = syn::parse_macro_input!(args as syn::AttributeArgs);

Expand All @@ -290,5 +290,5 @@ pub(crate) fn test(args: TokenStream, item: TokenStream, rt_threaded: bool) -> T
.into();
}

parse_knobs(input, args, true, rt_threaded).unwrap_or_else(|e| e.to_compile_error().into())
parse_knobs(input, args, true, rt_multi_thread).unwrap_or_else(|e| e.to_compile_error().into())
}
12 changes: 6 additions & 6 deletions tokio-macros/src/lib.rs
Expand Up @@ -189,7 +189,7 @@ pub fn main(args: TokenStream, item: TokenStream) -> TokenStream {
/// macro is expanded.
#[proc_macro_attribute]
#[cfg(not(test))] // Work around for rust-lang/rust#62127
pub fn main_rt_core(args: TokenStream, item: TokenStream) -> TokenStream {
pub fn main_rt(args: TokenStream, item: TokenStream) -> TokenStream {
entry::main(args, item, false)
}

Expand Down Expand Up @@ -252,33 +252,33 @@ pub fn test(args: TokenStream, item: TokenStream) -> TokenStream {
/// tokio 0.2 crate available as `tokio` in the module where this
/// macro is expanded.
#[proc_macro_attribute]
pub fn test_rt_core(args: TokenStream, item: TokenStream) -> TokenStream {
pub fn test_rt(args: TokenStream, item: TokenStream) -> TokenStream {
entry::test(args, item, false)
}

/// Always fails with the error message below.
/// ```text
/// The #[tokio::main] macro requires rt-core or rt-threaded.
/// The #[tokio::main] macro requires rt or rt-multi-thread.
/// ```
#[proc_macro_attribute]
pub fn main_fail(_args: TokenStream, _item: TokenStream) -> TokenStream {
syn::Error::new(
proc_macro2::Span::call_site(),
"The #[tokio::main] macro requires rt-core or rt-threaded.",
"The #[tokio::main] macro requires rt or rt-multi-thread.",
)
.to_compile_error()
.into()
}

/// Always fails with the error message below.
/// ```text
/// The #[tokio::test] macro requires rt-core or rt-threaded.
/// The #[tokio::test] macro requires rt or rt-multi-thread.
/// ```
#[proc_macro_attribute]
pub fn test_fail(_args: TokenStream, _item: TokenStream) -> TokenStream {
syn::Error::new(
proc_macro2::Span::call_site(),
"The #[tokio::test] macro requires rt-core or rt-threaded.",
"The #[tokio::test] macro requires rt or rt-multi-thread.",
)
.to_compile_error()
.into()
Expand Down
2 changes: 1 addition & 1 deletion tokio-test/Cargo.toml
Expand Up @@ -21,7 +21,7 @@ categories = ["asynchronous", "testing"]
publish = false

[dependencies]
tokio = { version = "0.3.0", path = "../tokio", features = ["rt-core", "stream", "sync", "time", "test-util"] }
tokio = { version = "0.3.0", path = "../tokio", features = ["rt", "stream", "sync", "time", "test-util"] }

bytes = "0.5.0"
futures-core = "0.3.0"
Expand Down
2 changes: 1 addition & 1 deletion tokio-util/Cargo.toml
Expand Up @@ -31,7 +31,7 @@ compat = ["futures-io",]
codec = ["tokio/stream"]
time = ["tokio/time","slab"]
io = []
rt-core = ["tokio/rt-core"]
rt = ["tokio/rt"]

[dependencies]
tokio = { version = "0.3.0", path = "../tokio" }
Expand Down
6 changes: 3 additions & 3 deletions tokio-util/src/cfg.rs
Expand Up @@ -40,11 +40,11 @@ macro_rules! cfg_io {
}
}

macro_rules! cfg_rt_core {
macro_rules! cfg_rt {
($($item:item)*) => {
$(
#[cfg(feature = "rt-core")]
#[cfg_attr(docsrs, doc(cfg(feature = "rt-core")))]
#[cfg(feature = "rt")]
#[cfg_attr(docsrs, doc(cfg(feature = "rt")))]
$item
)*
}
Expand Down
2 changes: 1 addition & 1 deletion tokio-util/src/lib.rs
Expand Up @@ -47,7 +47,7 @@ cfg_io! {
pub mod io;
}

cfg_rt_core! {
cfg_rt! {
pub mod context;
}

Expand Down
2 changes: 1 addition & 1 deletion tokio-util/tests/context.rs
@@ -1,4 +1,4 @@
#![cfg(feature = "rt-core")]
#![cfg(feature = "rt")]
#![warn(rust_2018_idioms)]

use tokio::runtime::Builder;
Expand Down
12 changes: 5 additions & 7 deletions tokio/Cargo.toml
Expand Up @@ -37,9 +37,8 @@ full = [
"macros",
"net",
"process",
"rt-core",
"rt-util",
"rt-threaded",
"rt",
"rt-multi-thread",
"signal",
"stream",
"sync",
Expand Down Expand Up @@ -71,11 +70,10 @@ process = [
"winapi/threadpoollegacyapiset",
]
# Includes basic task execution capabilities
rt-core = ["slab"]
rt-util = []
rt-threaded = [
rt = ["slab"]
rt-multi-thread = [
"num_cpus",
"rt-core",
"rt",
]
signal = [
"lazy_static",
Expand Down
6 changes: 3 additions & 3 deletions tokio/src/blocking.rs
@@ -1,9 +1,9 @@
cfg_rt_core! {
cfg_rt! {
pub(crate) use crate::runtime::spawn_blocking;
pub(crate) use crate::task::JoinHandle;
}

cfg_not_rt_core! {
cfg_not_rt! {
use std::fmt;
use std::future::Future;
use std::pin::Pin;
Expand All @@ -15,7 +15,7 @@ cfg_not_rt_core! {
R: Send + 'static,
{
assert_send_sync::<JoinHandle<std::cell::Cell<()>>>();
panic!("requires the `rt-core` Tokio feature flag")
panic!("requires the `rt` Tokio feature flag")

}

Expand Down
6 changes: 3 additions & 3 deletions tokio/src/coop.rs
Expand Up @@ -83,7 +83,7 @@ impl Budget {
}
}

cfg_rt_threaded! {
cfg_rt_multi_thread! {
impl Budget {
fn has_remaining(self) -> bool {
self.0.map(|budget| budget > 0).unwrap_or(true)
Expand Down Expand Up @@ -122,7 +122,7 @@ fn with_budget<R>(budget: Budget, f: impl FnOnce() -> R) -> R {
})
}

cfg_rt_threaded! {
cfg_rt_multi_thread! {
/// Set the current task's budget
pub(crate) fn set(budget: Budget) {
CURRENT.with(|cell| cell.set(budget))
Expand All @@ -134,7 +134,7 @@ cfg_rt_threaded! {
}
}

cfg_rt_core! {
cfg_rt! {
/// Forcibly remove the budgeting constraints early.
///
/// Returns the remaining budget
Expand Down
4 changes: 2 additions & 2 deletions tokio/src/future/block_on.rs
@@ -1,13 +1,13 @@
use std::future::Future;

cfg_rt_core! {
cfg_rt! {
pub(crate) fn block_on<F: Future>(f: F) -> F::Output {
let mut e = crate::runtime::enter::enter(false);
e.block_on(f).unwrap()
}
}

cfg_not_rt_core! {
cfg_not_rt! {
pub(crate) fn block_on<F: Future>(f: F) -> F::Output {
let mut park = crate::park::thread::CachedParkThread::new();
park.block_on(f).unwrap()
Expand Down
12 changes: 6 additions & 6 deletions tokio/src/io/driver/mod.rs
@@ -1,4 +1,4 @@
#![cfg_attr(not(feature = "rt-core"), allow(dead_code))]
#![cfg_attr(not(feature = "rt"), allow(dead_code))]

mod ready;
use ready::Ready;
Expand Down Expand Up @@ -219,13 +219,13 @@ impl fmt::Debug for Driver {

// ===== impl Handle =====

cfg_rt_core! {
cfg_rt! {
impl Handle {
/// Returns a handle to the current reactor
///
/// # Panics
///
/// This function panics if there is no current reactor set and `rt-core` feature
/// This function panics if there is no current reactor set and `rt` feature
/// flag is not enabled.
pub(super) fn current() -> Self {
crate::runtime::context::io_handle()
Expand All @@ -234,16 +234,16 @@ cfg_rt_core! {
}
}

cfg_not_rt_core! {
cfg_not_rt! {
impl Handle {
/// Returns a handle to the current reactor
///
/// # Panics
///
/// This function panics if there is no current reactor set, or if the `rt-core`
/// This function panics if there is no current reactor set, or if the `rt`
/// feature flag is not enabled.
pub(super) fn current() -> Self {
panic!("there is no reactor running, must be called from the context of Tokio runtime with `rt-core` enabled.")
panic!("there is no reactor running, must be called from the context of Tokio runtime with `rt` enabled.")
}
}
}
Expand Down