Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
gpui: Reduce amount of monomorphizations taking place (#48014)
Piotr Osiewicz45455dbd0620
diff --git a/crates/gpui/src/app.rs b/crates/gpui/src/app.rsindex 94fdab8927a..4e2cf10ebfc 100644--- a/crates/gpui/src/app.rs+++ b/crates/gpui/src/app.rs@@ -1462,29 +1462,33 @@ impl App {cx.window_update_stack.push(window.handle.id);let result = update(root_view, &mut window, cx);- cx.window_update_stack.pop();+ fn trail(id: WindowId, window: Box<Window>, cx: &mut App) -> Option<()> {+ cx.window_update_stack.pop();- if window.removed {- cx.window_handles.remove(&id);- cx.windows.remove(id);+ if window.removed {+ cx.window_handles.remove(&id);+ cx.windows.remove(id);- cx.window_closed_observers.clone().retain(&(), |callback| {- callback(cx);- true- });+ cx.window_closed_observers.clone().retain(&(), |callback| {+ callback(cx);+ true+ });- let quit_on_empty = match cx.quit_mode {- QuitMode::Explicit => false,- QuitMode::LastWindowClosed => true,- QuitMode::Default => cfg!(not(target_os = "macos")),- };+ let quit_on_empty = match cx.quit_mode {+ QuitMode::Explicit => false,+ QuitMode::LastWindowClosed => true,+ QuitMode::Default => cfg!(not(target_os = "macos")),+ };- if quit_on_empty && cx.windows.is_empty() {- cx.quit();+ if quit_on_empty && cx.windows.is_empty() {+ cx.quit();+ }+ } else {+ cx.windows.get_mut(id)?.replace(window);}- } else {- cx.windows.get_mut(id)?.replace(window);+ Some(())}+ trail(id, window, cx)?;Some(result)})@@ -1529,7 +1533,7 @@ impl App {let mut cx = self.to_async();self.foreground_executor- .spawn(async move { f(&mut cx).await })+ .spawn(async move { f(&mut cx).await }.boxed_local())}/// Spawns the future returned by the given function on the main thread with@@ -1547,7 +1551,7 @@ impl App {let mut cx = self.to_async();self.foreground_executor- .spawn_with_priority(priority, async move { f(&mut cx).await })+ .spawn_with_priority(priority, async move { f(&mut cx).await }.boxed_local())}/// Schedules the given function to be run at the end of the current effect cycle, allowing entitiesdiff --git a/crates/gpui/src/app/async_context.rs b/crates/gpui/src/app/async_context.rsindex ed202f6b86b..c770e8c03ab 100644--- a/crates/gpui/src/app/async_context.rs+++ b/crates/gpui/src/app/async_context.rs@@ -7,6 +7,7 @@ use crate::{use anyhow::Context as _;use derive_more::{Deref, DerefMut};use futures::channel::oneshot;+use smol::future::FutureExt;use std::{future::Future, rc::Weak};use super::{Context, WeakEntity};@@ -184,7 +185,7 @@ impl AsyncApp {{let mut cx = self.clone();self.foreground_executor- .spawn(async move { f(&mut cx).await })+ .spawn(async move { f(&mut cx).await }.boxed_local())}/// Determine whether global state of the specified type has been assigned.@@ -322,7 +323,7 @@ impl AsyncWindowContext {{let mut cx = self.clone();self.foreground_executor- .spawn(async move { f(&mut cx).await })+ .spawn(async move { f(&mut cx).await }.boxed_local())}/// Present a platform dialog.diff --git a/crates/gpui/src/executor.rs b/crates/gpui/src/executor.rsindex 9ff4a9e196d..36faf52e74e 100644--- a/crates/gpui/src/executor.rs+++ b/crates/gpui/src/executor.rs@@ -145,7 +145,7 @@ impl BackgroundExecutor {whereR: Send + 'static,{- self.spawn_with_priority(Priority::default(), future)+ self.spawn_with_priority(Priority::default(), future.boxed())}/// Enqueues the given future to be run to completion on a background thread with the given priority.@@ -409,7 +409,7 @@ impl ForegroundExecutor {whereR: 'static,{- Task::from_scheduler(self.inner.spawn(future))+ Task::from_scheduler(self.inner.spawn(future.boxed_local()))}/// Enqueues the given Task to run on the main thread with the given priority.