Skip to content
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: 0 additions & 2 deletions tests-integration/tests/macros_main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ async fn spawning() -> usize {
join.await.unwrap()
}

#[cfg(tokio_unstable)]
#[tokio::main(flavor = "local")]
async fn local_main() -> usize {
let join = tokio::task::spawn_local(async { 1 });
Expand All @@ -33,6 +32,5 @@ fn shell() {
assert_eq!(1, basic_main());
assert_eq!(bool::default(), generic_fun::<bool>());

#[cfg(tokio_unstable)]
assert_eq!(1, local_main());
}
22 changes: 0 additions & 22 deletions tokio-macros/src/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -421,12 +421,7 @@ fn parse_knobs(mut input: ItemFn, is_test: bool, config: FinalConfig) -> TokenSt
},
};

let mut checks = vec![];
let mut errors = vec![];

let build = if let RuntimeFlavor::Local = config.flavor {
checks.push(quote! { tokio_unstable });
errors.push("The local runtime flavor is only available when `tokio_unstable` is set.");
quote_spanned! {last_stmt_start_span=> build_local(Default::default())}
} else {
quote_spanned! {last_stmt_start_span=> build()}
Expand All @@ -451,23 +446,10 @@ fn parse_knobs(mut input: ItemFn, is_test: bool, config: FinalConfig) -> TokenSt
quote! {}
};

let do_checks: TokenStream = checks
.iter()
.zip(&errors)
.map(|(check, error)| {
quote! {
#[cfg(not(#check))]
compile_error!(#error);
}
})
.collect();

let body_ident = quote! { body };
// This explicit `return` is intentional. See tokio-rs/tokio#4636
let last_block = quote_spanned! {last_stmt_end_span=>
#do_checks

#[cfg(all(#(#checks),*))]
#[allow(clippy::expect_used, clippy::diverging_sub_expression, clippy::needless_return)]
{
return #rt
Expand All @@ -477,10 +459,6 @@ fn parse_knobs(mut input: ItemFn, is_test: bool, config: FinalConfig) -> TokenSt
.block_on(#body_ident);
}

#[cfg(not(all(#(#checks),*)))]
{
panic!("fell through checks")
}
};

let body = input.body();
Expand Down
13 changes: 0 additions & 13 deletions tokio-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,11 @@ use proc_macro::TokenStream;
///
/// ## Local
///
/// [Unstable API][unstable] only.
///
/// To use the [local runtime], the macro can be configured using
///
/// ```rust
/// # #[cfg(tokio_unstable)]
/// #[tokio::main(flavor = "local")]
/// # async fn main() {}
/// # #[cfg(not(tokio_unstable))]
/// # fn main() {}
/// ```
///
/// # Function arguments
Expand Down Expand Up @@ -146,25 +141,19 @@ use proc_macro::TokenStream;
///
/// ## Using the local runtime
///
/// Available in the [unstable API][unstable] only.
///
/// The [local runtime] is similar to the current-thread runtime but
/// supports [`task::spawn_local`](../tokio/task/fn.spawn_local.html).
///
/// ```rust
/// # #[cfg(tokio_unstable)]
/// #[tokio::main(flavor = "local")]
/// async fn main() {
/// println!("Hello world");
/// }
/// # #[cfg(not(tokio_unstable))]
/// # fn main() {}
/// ```
///
/// Equivalent code not using `#[tokio::main]`
///
/// ```rust
/// # #[cfg(tokio_unstable)]
/// fn main() {
/// tokio::runtime::Builder::new_current_thread()
/// .enable_all()
Expand All @@ -174,8 +163,6 @@ use proc_macro::TokenStream;
/// println!("Hello world");
/// })
/// }
/// # #[cfg(not(tokio_unstable))]
/// # fn main() {}
/// ```
///
///
Expand Down
8 changes: 4 additions & 4 deletions tokio/src/runtime/builder.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#![cfg_attr(loom, allow(unused_imports))]

use crate::runtime::handle::Handle;
use crate::runtime::{blocking, driver, Callback, HistogramBuilder, Runtime, TaskCallback};
use crate::runtime::{
blocking, driver, Callback, HistogramBuilder, LocalOptions, LocalRuntime, Runtime, TaskCallback,
};
#[cfg(tokio_unstable)]
use crate::runtime::{metrics::HistogramConfiguration, LocalOptions, LocalRuntime, TaskMeta};
use crate::runtime::{metrics::HistogramConfiguration, TaskMeta};
use crate::util::rand::{RngSeed, RngSeedGenerator};

use crate::runtime::blocking::BlockingPool;
Expand Down Expand Up @@ -923,7 +925,6 @@ impl Builder {
/// });
/// ```
#[allow(unused_variables, unreachable_patterns)]
#[cfg(tokio_unstable)]
#[cfg_attr(docsrs, doc(cfg(tokio_unstable)))]
pub fn build_local(&mut self, options: LocalOptions) -> io::Result<LocalRuntime> {
match &self.kind {
Expand Down Expand Up @@ -1438,7 +1439,6 @@ impl Builder {
))
}

#[cfg(tokio_unstable)]
fn build_current_thread_local_runtime(&mut self) -> io::Result<LocalRuntime> {
use crate::runtime::local_runtime::LocalRuntimeScheduler;

Expand Down
3 changes: 1 addition & 2 deletions tokio/src/runtime/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -361,14 +361,13 @@ impl Handle {
{
let id = crate::runtime::task::Id::next();
#[cfg(all(
tokio_unstable,
tokio_taskdump,
feature = "rt",
target_os = "linux",
any(target_arch = "aarch64", target_arch = "x86", target_arch = "x86_64")
))]
let future = super::task::trace::Trace::root(future);
#[cfg(all(tokio_unstable, feature = "tracing"))]
#[cfg(feature = "tracing")]
let future = crate::util::trace::task(future, "task", meta, id.as_u64());
self.inner.spawn_local(future, id, meta.spawned_at)
}
Expand Down
5 changes: 2 additions & 3 deletions tokio/src/runtime/local_runtime/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ use std::time::Duration;
/// [runtime]: crate::runtime::Runtime
/// [module]: crate::runtime
#[derive(Debug)]
#[cfg_attr(docsrs, doc(cfg(tokio_unstable)))]
pub struct LocalRuntime {
/// Task scheduler
scheduler: LocalRuntimeScheduler,
Expand Down Expand Up @@ -231,15 +230,14 @@ impl LocalRuntime {
#[track_caller]
fn block_on_inner<F: Future>(&self, future: F, _meta: SpawnMeta<'_>) -> F::Output {
#[cfg(all(
tokio_unstable,
tokio_taskdump,
feature = "rt",
target_os = "linux",
any(target_arch = "aarch64", target_arch = "x86", target_arch = "x86_64")
))]
let future = crate::runtime::task::trace::Trace::root(future);

#[cfg(all(tokio_unstable, feature = "tracing"))]
#[cfg(feature = "tracing")]
let future = crate::util::trace::task(
future,
"block_on",
Expand Down Expand Up @@ -320,6 +318,7 @@ impl LocalRuntime {
/// use std::time::Duration;
///
/// fn main() {
/// # if cfg!(miri) { return } // Miri reports error when main thread terminated without waiting all remaining threads.
/// let runtime = LocalRuntime::new().unwrap();
///
/// runtime.block_on(async move {
Expand Down
5 changes: 3 additions & 2 deletions tokio/src/runtime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,8 +371,6 @@ cfg_rt! {
pub use self::builder::UnhandledPanic;
pub use crate::util::rand::RngSeed;

mod local_runtime;
pub use local_runtime::{LocalRuntime, LocalOptions};
}

cfg_taskdump! {
Expand All @@ -394,6 +392,9 @@ cfg_rt! {
mod runtime;
pub use runtime::{Runtime, RuntimeFlavor};

mod local_runtime;
pub use local_runtime::{LocalRuntime, LocalOptions};

/// Boundary value to prevent stack overflow caused by a large-sized
/// Future being placed in the stack.
pub(crate) const BOX_FUTURE_THRESHOLD: usize = if cfg!(debug_assertions) {
Expand Down
3 changes: 1 addition & 2 deletions tokio/src/task/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ cfg_rt! {
/// Spawns a `!Send` future on the current [`LocalSet`] or [`LocalRuntime`].
///
/// This is possible when either using one of these types
/// explicitly, or (with `tokio_unstable`) by opting to use the
/// explicitly by opting to use the
/// `"local"` runtime flavor in `tokio::main`:
///
/// ```ignore
Expand Down Expand Up @@ -407,7 +407,6 @@ cfg_rt! {
let future = future.take().unwrap();

#[cfg(all(
tokio_unstable,
tokio_taskdump,
feature = "rt",
target_os = "linux",
Expand Down
11 changes: 3 additions & 8 deletions tokio/tests/async_send_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,9 @@ assert_value!(tokio::runtime::EnterGuard<'_>: !Send & Sync & Unpin);
assert_value!(tokio::runtime::Handle: Send & Sync & Unpin);
assert_value!(tokio::runtime::Runtime: Send & Sync & Unpin);

assert_value!(tokio::runtime::LocalRuntime: !Send & !Sync & Unpin);
assert_value!(tokio::runtime::LocalOptions: !Send & !Sync & Unpin);

assert_value!(tokio::time::Interval: Send & Sync & Unpin);
assert_value!(tokio::time::Instant: Send & Sync & Unpin);
assert_value!(tokio::time::Sleep: Send & Sync & !Unpin);
Expand Down Expand Up @@ -768,11 +771,3 @@ mod unix_asyncfd {
async_assert_fn!(AsyncFd<ImplsFd<NN>>::writable(_): !Send & !Sync & !Unpin);
async_assert_fn!(AsyncFd<ImplsFd<NN>>::writable_mut(_): !Send & !Sync & !Unpin);
}

#[cfg(tokio_unstable)]
mod unstable {
use super::*;

assert_value!(tokio::runtime::LocalRuntime: !Send & !Sync & Unpin);
assert_value!(tokio::runtime::LocalOptions: !Send & !Sync & Unpin);
}
2 changes: 1 addition & 1 deletion tokio/tests/rt_local.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#![warn(rust_2018_idioms)]
#![cfg(all(feature = "full", tokio_unstable))]
#![cfg(feature = "full")]

use tokio::runtime::LocalOptions;
use tokio::task::spawn_local;
Expand Down
Loading