From 62e779f82d7c9427c33484baa676c09a1917b0d6 Mon Sep 17 00:00:00 2001 From: Matt Mastracci Date: Wed, 17 May 2023 15:49:57 -0600 Subject: fix(runtime): Box the main future to avoid blowing up the stack (#19155) This fixes `Unhandled exception at [...] Stack overflow` on Windows, caused by the large size of the main future. --- core/task.rs | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'core') diff --git a/core/task.rs b/core/task.rs index 46a4c8c26..3e728a08f 100644 --- a/core/task.rs +++ b/core/task.rs @@ -44,6 +44,7 @@ impl Future for JoinHandle { /// Equivalent to [`tokio::task::spawn`], but does not require the future to be [`Send`]. Must only be /// used on a [`RuntimeFlavor::CurrentThread`] executor, though this is only checked when running with /// debug assertions. +#[inline(always)] pub fn spawn + 'static, R: 'static>( f: F, ) -> JoinHandle { @@ -60,6 +61,7 @@ pub fn spawn + 'static, R: 'static>( /// Equivalent to [`tokio::task::spawn_blocking`]. Currently a thin wrapper around the tokio API, but this /// may change in the future. +#[inline(always)] pub fn spawn_blocking< F: (FnOnce() -> R) + Send + 'static, R: Send + 'static, @@ -89,6 +91,7 @@ impl MaskResultAsSend { } } +#[repr(transparent)] pub struct MaskFutureAsSend { future: F, } @@ -102,6 +105,7 @@ impl MaskFutureAsSend { /// /// You must ensure that the future is actually used on the same /// thread, ie. always use current thread runtime flavor from Tokio. + #[inline(always)] pub unsafe fn new(future: F) -> Self { Self { future } } -- cgit v1.2.3