gpui: Introduce stacker to address stack overflows with deep layout trees (#35813)

Co-authored-by: Anthony Eid <hello@anthonyeid.me>
Co-authored-by: Lukas Wirth <lukas@zed.dev>
Co-authored-by: Ben Kunkle <ben@zed.dev>

Release Notes:

- N/A

Co-authored-by: Anthony Eid <hello@anthonyeid.me>
Co-authored-by: Lukas Wirth <lukas@zed.dev>
Co-authored-by: Ben Kunkle <ben@zed.dev>
This commit is contained in:
Piotr Osiewicz 2025-08-19 10:26:37 +02:00 committed by GitHub
parent 1fbb318714
commit ed14ab8c02
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 56 additions and 5 deletions

View file

@ -3,6 +3,7 @@ use crate::{
};
use collections::{FxHashMap, FxHashSet};
use smallvec::SmallVec;
use stacksafe::{StackSafe, stacksafe};
use std::{fmt::Debug, ops::Range};
use taffy::{
TaffyTree, TraversePartialTree as _,
@ -11,8 +12,15 @@ use taffy::{
tree::NodeId,
};
type NodeMeasureFn = Box<
dyn FnMut(Size<Option<Pixels>>, Size<AvailableSpace>, &mut Window, &mut App) -> Size<Pixels>,
type NodeMeasureFn = StackSafe<
Box<
dyn FnMut(
Size<Option<Pixels>>,
Size<AvailableSpace>,
&mut Window,
&mut App,
) -> Size<Pixels>,
>,
>;
struct NodeContext {
@ -88,7 +96,7 @@ impl TaffyLayoutEngine {
.new_leaf_with_context(
taffy_style,
NodeContext {
measure: Box::new(measure),
measure: StackSafe::new(Box::new(measure)),
},
)
.expect(EXPECT_MESSAGE)
@ -143,6 +151,7 @@ impl TaffyLayoutEngine {
Ok(edges)
}
#[stacksafe]
pub fn compute_layout(
&mut self,
id: LayoutId,