Skip to content

Commit 1fc450a

Browse files
authored
runtime: stabilize LocalRuntime (#7557)
1 parent 324218f commit 1fc450a

6 files changed

Lines changed: 13 additions & 54 deletions

File tree

tokio-macros/src/entry.rs

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -476,12 +476,7 @@ fn parse_knobs(mut input: ItemFn, is_test: bool, config: FinalConfig) -> TokenSt
476476
},
477477
};
478478

479-
let mut checks = vec![];
480-
let mut errors = vec![];
481-
482479
let build = if let RuntimeFlavor::Local = config.flavor {
483-
checks.push(quote! { tokio_unstable });
484-
errors.push("The local runtime flavor is only available when `tokio_unstable` is set.");
485480
quote_spanned! {last_stmt_start_span=> build_local(Default::default())}
486481
} else {
487482
quote_spanned! {last_stmt_start_span=> build()}
@@ -509,23 +504,10 @@ fn parse_knobs(mut input: ItemFn, is_test: bool, config: FinalConfig) -> TokenSt
509504
quote! {}
510505
};
511506

512-
let do_checks: TokenStream = checks
513-
.iter()
514-
.zip(&errors)
515-
.map(|(check, error)| {
516-
quote! {
517-
#[cfg(not(#check))]
518-
compile_error!(#error);
519-
}
520-
})
521-
.collect();
522-
523507
let body_ident = quote! { body };
524508
// This explicit `return` is intentional. See tokio-rs/tokio#4636
525509
let last_block = quote_spanned! {last_stmt_end_span=>
526-
#do_checks
527510

528-
#[cfg(all(#(#checks),*))]
529511
#[allow(clippy::expect_used, clippy::diverging_sub_expression, clippy::needless_return, clippy::unwrap_in_result)]
530512
{
531513
#use_builder
@@ -537,10 +519,6 @@ fn parse_knobs(mut input: ItemFn, is_test: bool, config: FinalConfig) -> TokenSt
537519
.block_on(#body_ident);
538520
}
539521

540-
#[cfg(not(all(#(#checks),*)))]
541-
{
542-
panic!("fell through checks")
543-
}
544522
};
545523

546524
let body = input.body();

tokio-macros/src/lib.rs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -73,16 +73,11 @@ use proc_macro::TokenStream;
7373
///
7474
/// ## Local
7575
///
76-
/// [Unstable API][unstable] only.
77-
///
7876
/// To use the [local runtime], the macro can be configured using
7977
///
8078
/// ```rust
81-
/// # #[cfg(tokio_unstable)]
8279
/// #[tokio::main(flavor = "local")]
8380
/// # async fn main() {}
84-
/// # #[cfg(not(tokio_unstable))]
85-
/// # fn main() {}
8681
/// ```
8782
///
8883
/// # Function arguments
@@ -165,25 +160,19 @@ use proc_macro::TokenStream;
165160
///
166161
/// ## Using the local runtime
167162
///
168-
/// Available in the [unstable API][unstable] only.
169-
///
170163
/// The [local runtime] is similar to the current-thread runtime but
171164
/// supports [`task::spawn_local`](../tokio/task/fn.spawn_local.html).
172165
///
173166
/// ```rust
174-
/// # #[cfg(tokio_unstable)]
175167
/// #[tokio::main(flavor = "local")]
176168
/// async fn main() {
177169
/// println!("Hello world");
178170
/// }
179-
/// # #[cfg(not(tokio_unstable))]
180-
/// # fn main() {}
181171
/// ```
182172
///
183173
/// Equivalent code not using `#[tokio::main]`
184174
///
185175
/// ```rust
186-
/// # #[cfg(tokio_unstable)]
187176
/// fn main() {
188177
/// tokio::runtime::Builder::new_current_thread()
189178
/// .enable_all()
@@ -193,8 +182,6 @@ use proc_macro::TokenStream;
193182
/// println!("Hello world");
194183
/// })
195184
/// }
196-
/// # #[cfg(not(tokio_unstable))]
197-
/// # fn main() {}
198185
/// ```
199186
///
200187
///

tokio/src/runtime/builder.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ use crate::runtime::{
55
blocking, driver, Callback, HistogramBuilder, Runtime, TaskCallback, TimerFlavor,
66
};
77
#[cfg(tokio_unstable)]
8-
use crate::runtime::{metrics::HistogramConfiguration, LocalOptions, LocalRuntime, TaskMeta};
8+
use crate::runtime::{metrics::HistogramConfiguration, TaskMeta};
9+
10+
use crate::runtime::{LocalOptions, LocalRuntime};
911
use crate::util::rand::{RngSeed, RngSeedGenerator};
1012

1113
use crate::runtime::blocking::BlockingPool;
@@ -241,7 +243,7 @@ impl Builder {
241243
/// Configuration methods can be chained on the return value.
242244
///
243245
/// To spawn non-`Send` tasks on the resulting runtime, combine it with a
244-
/// [`LocalSet`], or call [`build_local`] to create a [`LocalRuntime`] (unstable).
246+
/// [`LocalSet`], or call [`build_local`] to create a [`LocalRuntime`].
245247
///
246248
/// [`LocalSet`]: crate::task::LocalSet
247249
/// [`LocalRuntime`]: crate::runtime::LocalRuntime
@@ -1048,8 +1050,6 @@ impl Builder {
10481050
/// });
10491051
/// ```
10501052
#[allow(unused_variables, unreachable_patterns)]
1051-
#[cfg(tokio_unstable)]
1052-
#[cfg_attr(docsrs, doc(cfg(tokio_unstable)))]
10531053
pub fn build_local(&mut self, options: LocalOptions) -> io::Result<LocalRuntime> {
10541054
match &self.kind {
10551055
Kind::CurrentThread => self.build_current_thread_local_runtime(),
@@ -1605,7 +1605,6 @@ impl Builder {
16051605
))
16061606
}
16071607

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

tokio/src/runtime/local_runtime/runtime.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ use std::time::Duration;
2929
/// [runtime]: crate::runtime::Runtime
3030
/// [module]: crate::runtime
3131
#[derive(Debug)]
32-
#[cfg_attr(docsrs, doc(cfg(tokio_unstable)))]
3332
pub struct LocalRuntime {
3433
/// Task scheduler
3534
scheduler: LocalRuntimeScheduler,

tokio/src/runtime/mod.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@
3636
//! | Yes | No
3737
//! | |
3838
//! V |
39-
//! +--------------------------+ |
40-
//! | Local Runtime (unstable) | |
41-
//! +--------------------------+ |
39+
//! +---------------+ |
40+
//! | Local Runtime | |
41+
//! +---------------+ |
4242
//! |
4343
//! v
4444
//! +------------------------+
@@ -575,9 +575,6 @@ cfg_rt! {
575575
pub use self::builder::UnhandledPanic;
576576
pub use crate::util::rand::RngSeed;
577577

578-
mod local_runtime;
579-
pub use local_runtime::{LocalRuntime, LocalOptions};
580-
581578
/// Returns the index of the current worker thread, if called from a
582579
/// runtime worker thread.
583580
///
@@ -635,6 +632,9 @@ cfg_rt! {
635632
mod runtime;
636633
pub use runtime::{Runtime, RuntimeFlavor, is_rt_shutdown_err};
637634

635+
mod local_runtime;
636+
pub use local_runtime::{LocalRuntime, LocalOptions};
637+
638638
mod id;
639639
pub use id::Id;
640640

tokio/src/task/local.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -328,9 +328,8 @@ impl<'a> Drop for LocalDataEnterGuard<'a> {
328328
cfg_rt! {
329329
/// Spawns a `!Send` future on the current [`LocalSet`] or [`LocalRuntime`].
330330
///
331-
/// This is possible when either using one of these types
332-
/// explicitly, or (with `tokio_unstable`) by opting to use the
333-
/// `"local"` runtime flavor in `tokio::main`:
331+
/// This is possible when either using one of these types explicitly, or by
332+
/// opting to use the `"local"` runtime flavor in `tokio::main`:
334333
///
335334
/// ```ignore
336335
/// #[tokio::main(flavor = "local")]
@@ -374,10 +373,9 @@ cfg_rt! {
374373
/// }).await;
375374
/// # }
376375
/// ```
377-
/// With local runtime flavor ([Unstable API][unstable] only).
376+
/// With local runtime flavor.
378377
///
379378
/// ```rust
380-
/// # #[cfg(tokio_unstable)]
381379
/// #[tokio::main(flavor = "local")]
382380
/// async fn main() {
383381
/// let join = tokio::task::spawn_local(async {
@@ -386,8 +384,6 @@ cfg_rt! {
386384
///
387385
/// join.await.unwrap()
388386
/// }
389-
/// # #[cfg(not(tokio_unstable))]
390-
/// # fn main() {}
391387
///
392388
/// ```
393389
///

0 commit comments

Comments
 (0)