From 691de6b4b36d3ada91a1e238904b065eec454188 Mon Sep 17 00:00:00 2001 From: Michael Sloan Date: Sun, 2 Feb 2025 12:20:17 -0700 Subject: [PATCH] Add `#[track_caller]` to gpui foreground executor spawn methods (#24103) Use of this location info was added in #21758 to help with diagnosing remote_server panics on drop of tasks on a different thread. Release Notes: - N/A --- crates/gpui/src/app.rs | 1 + crates/gpui/src/app/async_context.rs | 2 ++ crates/gpui/src/app/context.rs | 2 ++ crates/gpui/src/app/test_context.rs | 1 + crates/gpui/src/window.rs | 1 + 5 files changed, 7 insertions(+) diff --git a/crates/gpui/src/app.rs b/crates/gpui/src/app.rs index 828836efaddd74e1e92b1f4516168299ad77d524..1408f44a9397c8f34310d51214cb751c5e58b85a 100644 --- a/crates/gpui/src/app.rs +++ b/crates/gpui/src/app.rs @@ -1040,6 +1040,7 @@ impl App { /// Spawns the future returned by the given function on the thread pool. The closure will be invoked /// with [AsyncApp], which allows the application state to be accessed across await points. + #[track_caller] pub fn spawn(&self, f: impl FnOnce(AsyncApp) -> Fut) -> Task where Fut: Future + 'static, diff --git a/crates/gpui/src/app/async_context.rs b/crates/gpui/src/app/async_context.rs index 3e8f5cdd914b3efc8d570a54a806c247ed4eacf2..2375180e6f5512b48985bcc50af96036f3e197a0 100644 --- a/crates/gpui/src/app/async_context.rs +++ b/crates/gpui/src/app/async_context.rs @@ -172,6 +172,7 @@ impl AsyncApp { } /// Schedule a future to be polled in the background. + #[track_caller] pub fn spawn(&self, f: impl FnOnce(AsyncApp) -> Fut) -> Task where Fut: Future + 'static, @@ -297,6 +298,7 @@ impl AsyncWindowContext { /// Schedule a future to be executed on the main thread. This is used for collecting /// the results of background tasks and updating the UI. + #[track_caller] pub fn spawn(&self, f: impl FnOnce(AsyncWindowContext) -> Fut) -> Task where Fut: Future + 'static, diff --git a/crates/gpui/src/app/context.rs b/crates/gpui/src/app/context.rs index 5e892a6505a7b9be4e2786015ba22c937aac9c62..31f17cd9c89008475b55afd3e9af87e12e865f4b 100644 --- a/crates/gpui/src/app/context.rs +++ b/crates/gpui/src/app/context.rs @@ -183,6 +183,7 @@ impl<'a, T: 'static> Context<'a, T> { /// Spawn the future returned by the given function. /// The function is provided a weak handle to the entity owned by this context and a context that can be held across await points. /// The returned task must be held or detached. + #[track_caller] pub fn spawn(&self, f: impl FnOnce(WeakEntity, AsyncApp) -> Fut) -> Task where T: 'static, @@ -583,6 +584,7 @@ impl<'a, T: 'static> Context<'a, T> { /// The given callback is invoked with a [`WeakEntity`] to avoid leaking the view for a long-running process. /// It's also given an [`AsyncWindowContext`], which can be used to access the state of the view across await points. /// The returned future will be polled on the main thread. + #[track_caller] pub fn spawn_in( &self, window: &Window, diff --git a/crates/gpui/src/app/test_context.rs b/crates/gpui/src/app/test_context.rs index b14e572b505a6103da30573f12644b36dfadaf50..7ad7623d33fa7f0ee0a2cde74d796d12beea0687 100644 --- a/crates/gpui/src/app/test_context.rs +++ b/crates/gpui/src/app/test_context.rs @@ -317,6 +317,7 @@ impl TestAppContext { } /// Run the given task on the main thread. + #[track_caller] pub fn spawn(&self, f: impl FnOnce(AsyncApp) -> Fut) -> Task where Fut: Future + 'static, diff --git a/crates/gpui/src/window.rs b/crates/gpui/src/window.rs index 19254d280d1a7135592b51a485a6a29e71c14ed9..ffedaadb07fd6327a00ec0df01f4a8629f14894d 100644 --- a/crates/gpui/src/window.rs +++ b/crates/gpui/src/window.rs @@ -1307,6 +1307,7 @@ impl Window { /// Spawn the future returned by the given closure on the application thread pool. /// The closure is provided a handle to the current window and an `AsyncWindowContext` for /// use within your future. + #[track_caller] pub fn spawn(&self, cx: &App, f: impl FnOnce(AsyncWindowContext) -> Fut) -> Task where R: 'static,