Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
gpui: Make stacker opt-in (#63187)
Lukas Wirth41d72f6c1d90
diff --git a/crates/gpui/Cargo.toml b/crates/gpui/Cargo.tomlindex e9c4d98b973..13cd4e8ef60 100644--- a/crates/gpui/Cargo.toml+++ b/crates/gpui/Cargo.toml@@ -38,6 +38,7 @@ screen-capture = []windows-manifest = ["dep:embed-resource"]profiler = ["dep:hdrhistogram"]+stacker = ["dep:stacksafe"][lib]path = "src/gpui.rs"@@ -87,7 +88,7 @@ serde_json.workspace = trueslotmap.workspace = truesmallvec.workspace = trueasync-channel.workspace = true-stacksafe.workspace = true+stacksafe = { workspace = true, optional = true }strum.workspace = truesum_tree.workspace = truetaffy = "=0.13.0"diff --git a/crates/gpui/src/elements/div.rs b/crates/gpui/src/elements/div.rsindex 308263e15d2..70e63d73210 100644--- a/crates/gpui/src/elements/div.rs+++ b/crates/gpui/src/elements/div.rs@@ -30,7 +30,6 @@ use collections::HashMap;use gpui_util::ResultExt;use refineable::Refineable;use smallvec::SmallVec;-use stacksafe::{StackSafe, stacksafe};use std::{any::{Any, TypeId},cell::RefCell,@@ -45,6 +44,11 @@ use std::{use super::ImageCacheProvider;+#[cfg(feature = "stacker")]+type StackSafe<T> = stacksafe::StackSafe<T>;+#[cfg(not(feature = "stacker"))]+type StackSafe<T> = T;+const DRAG_THRESHOLD: f64 = 2.;const DEFAULT_TOOLTIP_SHOW_DELAY: Duration = Duration::from_millis(500);const HOVERABLE_TOOLTIP_HIDE_DELAY: Duration = Duration::from_millis(500);@@ -1777,8 +1781,11 @@ impl InteractiveElement for Div {impl ParentElement for Div {fn extend(&mut self, elements: impl IntoIterator<Item = AnyElement>) {+ #[cfg(feature = "stacker")]self.children- .extend(elements.into_iter().map(StackSafe::new))+ .extend(elements.into_iter().map(StackSafe::new));+ #[cfg(not(feature = "stacker"))]+ self.children.extend(elements);}}@@ -1816,7 +1823,7 @@ impl Element for Div {}}- #[stacksafe]+ #[cfg_attr(feature = "stacker", stacksafe::stacksafe)]fn request_layout(&mut self,global_id: Option<&GlobalElementId>,@@ -1852,7 +1859,7 @@ impl Element for Div {(layout_id, DivFrameState { child_layout_ids })}- #[stacksafe]+ #[cfg_attr(feature = "stacker", stacksafe::stacksafe)]fn prepaint(&mut self,global_id: Option<&GlobalElementId>,@@ -1947,7 +1954,7 @@ impl Element for Div {)}- #[stacksafe]+ #[cfg_attr(feature = "stacker", stacksafe::stacksafe)]fn paint(&mut self,global_id: Option<&GlobalElementId>,diff --git a/crates/gpui/src/taffy.rs b/crates/gpui/src/taffy.rsindex 13d3bc4079b..b9e583a8df4 100644--- a/crates/gpui/src/taffy.rs+++ b/crates/gpui/src/taffy.rs@@ -7,7 +7,6 @@ use crate::{},};use collections::{FxHashMap, FxHashSet};-use stacksafe::{StackSafe, stacksafe};use std::{fmt::Debug, ops::Range};use taffy::{TaffyTree, TraversePartialTree as _,@@ -17,16 +16,14 @@ use taffy::{tree::NodeId,};-type NodeMeasureFn = StackSafe<- Box<- dyn FnMut(- Size<Option<Pixels>>,- Size<AvailableSpace>,- &mut Window,- &mut App,- ) -> Size<Pixels>,- >,->;+#[cfg(feature = "stacker")]+type StackSafe<T> = stacksafe::StackSafe<T>;+#[cfg(not(feature = "stacker"))]+type StackSafe<T> = T;++type MeasureFn =+ dyn FnMut(Size<Option<Pixels>>, Size<AvailableSpace>, &mut Window, &mut App) -> Size<Pixels>;+type NodeMeasureFn = StackSafe<Box<MeasureFn>>;struct NodeContext {measure: NodeMeasureFn,@@ -99,14 +96,12 @@ impl TaffyLayoutEngine {+ 'static,) -> LayoutId {let taffy_style = style.to_taffy(rem_size, scale_factor);+ let measure = Box::new(measure) as Box<MeasureFn>;+ #[cfg(feature = "stacker")]+ let measure = StackSafe::new(measure);self.taffy- .new_leaf_with_context(- taffy_style,- NodeContext {- measure: StackSafe::new(Box::new(measure)),- },- )+ .new_leaf_with_context(taffy_style, NodeContext { measure }).expect(EXPECT_MESSAGE).into()}@@ -188,7 +183,7 @@ impl TaffyLayoutEngine {Ok(edges)}- #[stacksafe]+ #[cfg_attr(feature = "stacker", stacksafe::stacksafe)]pub fn compute_layout(&mut self,id: LayoutId,diff --git a/crates/zed/Cargo.toml b/crates/zed/Cargo.tomlindex f8675c37615..b2571214911 100644--- a/crates/zed/Cargo.toml+++ b/crates/zed/Cargo.toml@@ -124,7 +124,7 @@ git_hosting_providers.workspace = truegit_ui = { workspace = true, features = ["call"] }git_ui_core.workspace = truego_to_line.workspace = true-gpui = { workspace = true, features = ["profiler"] }+gpui = { workspace = true, features = ["profiler", "stacker"] }gpui_platform = { workspace = true, features = ["screen-capture","font-kit",