Skip to content

Truly independent web browser

LibWeb: Keep the host findings noted outside runs on the pass's stack

Aliaksandr Kalenik7aad9d98d18b
diff --git a/Libraries/LibWeb/Rust/src/layout/flex_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/flex_formatting_context.rs
index 6b1f3740695..b6855cdf12f 100644
--- a/Libraries/LibWeb/Rust/src/layout/flex_formatting_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/flex_formatting_context.rs
@@ -4738,7 +4738,8 @@ mod stretch_cross_limit_tests {
arena.set_node_flag(child, NodeFlag::IsFlexItem, true);
arena.insert_child(container, child, Node::INVALID);
}
- let callbacks = LayoutPass::for_test(&arena, &scratch);
+ let host_findings_outside_runs = RefCell::default();
+ let callbacks = LayoutPass::for_test(&arena, &scratch, &host_findings_outside_runs);
let px = |value: i32| CssPixels::from_integer(i64::from(value));
let constraints = ContainingBlockConstraints {
percentage_basis_inline_size: (!column || definite_cross_basis).then_some(px(100)),
diff --git a/Libraries/LibWeb/Rust/src/layout/formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/formatting_context.rs
index 97cf0e1b519..dd4ace0cdd1 100644
--- a/Libraries/LibWeb/Rust/src/layout/formatting_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/formatting_context.rs
@@ -3681,7 +3681,8 @@ fn compute_root_layout(input: LayoutStageInput<'_>, should_collect_devtools_layo
root,
stage,
} = input;
- let callbacks = LayoutPass::new(arena, scratch, stage);
+ let host_findings_outside_runs = RefCell::default();
+ let callbacks = LayoutPass::new(arena, scratch, &host_findings_outside_runs, stage);
let viewport_inline_size = stage.viewport_inline_size;
let viewport_block_size = stage.viewport_block_size;
@@ -3769,7 +3770,7 @@ fn compute_root_layout(input: LayoutStageInput<'_>, should_collect_devtools_layo
entry_run_state,
entry_fragments,
&callbacks,
- scratch,
+ &host_findings_outside_runs,
should_collect_devtools_layout_data,
)
},
@@ -3792,7 +3793,7 @@ fn finish_entry_pass(
entry_run_state: &RunState,
entry_fragments: &fragment_tree::RunFragmentBuilder,
callbacks: &LayoutPass<'_>,
- scratch: &super::run_state::LayoutScratch,
+ host_findings_outside_runs: &RefCell<super::run_state::HostFindings>,
should_collect_devtools_layout_data: bool,
) -> LayoutStageOutput {
abspos_engine::drain_abspos_with_placed_containing_blocks(
@@ -3806,7 +3807,7 @@ fn finish_entry_pass(
!pass_fragments.roots.is_empty(),
"an entry pass always produces the entry root's fragment"
);
- let mut host_findings = scratch.take_host_findings_outside_runs();
+ let mut host_findings = host_findings_outside_runs.take();
if let Some(found_by_entry_run) = entry_run_state.take_host_findings() {
host_findings.receive(*found_by_entry_run);
}
@@ -3825,7 +3826,8 @@ fn compute_subtree_layout_fragments(input: LayoutStageInput<'_>, containing_bloc
root,
stage,
} = input;
- let callbacks = LayoutPass::new(arena, scratch, stage);
+ let host_findings_outside_runs = RefCell::default();
+ let callbacks = LayoutPass::new(arena, scratch, &host_findings_outside_runs, stage);
// NB: Either way, the boundary root's own geometry lies in the frame of its containing block.
let callbacks = if containing_block.is_invalid() {
@@ -3869,7 +3871,13 @@ fn compute_subtree_layout_fragments(input: LayoutStageInput<'_>, containing_bloc
} else {
layout_subtree_with_frozen_root_geometry(&entry_run);
}
- finish_entry_pass(entry_run_state, entry_fragments, &callbacks, scratch, false)
+ finish_entry_pass(
+ entry_run_state,
+ entry_fragments,
+ &callbacks,
+ &host_findings_outside_runs,
+ false,
+ )
},
)
}
@@ -3992,9 +4000,11 @@ mod baseline_tests {
arena.set_node_style(parent, 0, Some(parent_style.style()));
arena.set_node_style(child, 0, Some(child_style.style()));
arena.insert_child(parent, child, Node::INVALID);
+ let host_findings_outside_runs = RefCell::default();
let callbacks = LayoutPass::new(
&arena,
&scratch,
+ &host_findings_outside_runs,
LayoutStageFacts {
viewport_inline_size: CssPixels::from_integer(800),
viewport_block_size: CssPixels::from_integer(600),
diff --git a/Libraries/LibWeb/Rust/src/layout/layout_pass.rs b/Libraries/LibWeb/Rust/src/layout/layout_pass.rs
index 6c8a5b6719b..d6dd9f853d5 100644
--- a/Libraries/LibWeb/Rust/src/layout/layout_pass.rs
+++ b/Libraries/LibWeb/Rust/src/layout/layout_pass.rs
@@ -54,9 +54,12 @@ struct PositionOptionStyle<'pass> {
}
impl<'arena> LayoutPass<'arena> {
+ /// A pass over `arena` and `scratch`, which notes what it finds out for the host outside any run in
+ /// `host_findings_outside_runs`.
pub(crate) fn new(
arena: &'arena LayoutNodeArena,
scratch: &'arena super::run_state::LayoutScratch,
+ host_findings_outside_runs: &'arena RefCell<super::run_state::HostFindings>,
stage: super::formatting_context::LayoutStageFacts,
) -> Self {
Self {
@@ -67,7 +70,7 @@ impl<'arena> LayoutPass<'arena> {
document_in_quirks_mode: stage.document_in_quirks_mode,
frame: super::geometry::Frame::PHYSICAL,
innermost_run: (NodeSlotId::INVALID, NodeSlotId::INVALID),
- host_findings: &scratch.host_findings_outside_runs,
+ host_findings: host_findings_outside_runs,
intrinsic_size_caches: &scratch.intrinsic_size_caches,
reads_no_memoized_layout: false,
position_option_styles: None,
@@ -76,10 +79,15 @@ impl<'arena> LayoutPass<'arena> {
/// A pass over `arena` and `scratch` with no viewport, in no-quirks mode.
#[cfg(test)]
- pub(crate) fn for_test(arena: &'arena LayoutNodeArena, scratch: &'arena super::run_state::LayoutScratch) -> Self {
+ pub(crate) fn for_test(
+ arena: &'arena LayoutNodeArena,
+ scratch: &'arena super::run_state::LayoutScratch,
+ host_findings_outside_runs: &'arena RefCell<super::run_state::HostFindings>,
+ ) -> Self {
Self::new(
arena,
scratch,
+ host_findings_outside_runs,
super::formatting_context::LayoutStageFacts {
viewport_inline_size: CssPixels::default(),
viewport_block_size: CssPixels::default(),
diff --git a/Libraries/LibWeb/Rust/src/layout/rendered_text.rs b/Libraries/LibWeb/Rust/src/layout/rendered_text.rs
index e643b40b6d6..06bd19155e4 100644
--- a/Libraries/LibWeb/Rust/src/layout/rendered_text.rs
+++ b/Libraries/LibWeb/Rust/src/layout/rendered_text.rs
@@ -665,7 +665,11 @@ mod tests {
let block = arena.allocate_for_test().slot;
scratch.apply_memo_invalidations(&mut arena);
let keep = |arena: &LayoutNodeArena, scratch: &LayoutScratch| {
- let validity = run_root_validity(&LayoutPass::for_test(arena, scratch), block);
+ let host_findings_outside_runs = RefCell::default();
+ let validity = run_root_validity(
+ &LayoutPass::for_test(arena, scratch, &host_findings_outside_runs),
+ block,
+ );
let prepared = Arc::new(PreparedInlineContent {
validity,
items: Box::default(),
diff --git a/Libraries/LibWeb/Rust/src/layout/run_state.rs b/Libraries/LibWeb/Rust/src/layout/run_state.rs
index a6f59b89f36..239f251a5e3 100644
--- a/Libraries/LibWeb/Rust/src/layout/run_state.rs
+++ b/Libraries/LibWeb/Rust/src/layout/run_state.rs
@@ -9,11 +9,10 @@ use super::*;
/// What the layout stage keeps for itself besides what each of its runs keeps: what the runs of a layout pass share. It
/// is the stage's scratch rather than arena columns: nothing outside a running pass reads it, but for the memos it
/// keeps for later passes.
+#[derive(Default)]
pub(crate) struct LayoutScratch {
/// The intrinsic sizes passes measured, kept for the passes after them.
pub(super) intrinsic_size_caches: super::layout_node_arena::IntrinsicSizeCaches,
- /// What the pass found out for the host outside any run, which its driver reports itself.
- pub(super) host_findings_outside_runs: RefCell<HostFindings>,
/// The results of formatting context runs, kept for the runs after them in this pass and the passes after it.
fc_run_cache_store: super::fc_run_cache::FcRunCacheStore,
/// The layouts of in-flow blocks, kept for the passes after the one that laid them out.
@@ -91,22 +90,6 @@ const _: () = {
assert_send::<LayoutScratch>();
};
-impl Default for LayoutScratch {
- fn default() -> Self {
- Self {
- intrinsic_size_caches: Default::default(),
- host_findings_outside_runs: RefCell::new(HostFindings::default()),
- fc_run_cache_store: Default::default(),
- in_flow_block_cache_store: Default::default(),
- layout_trace: Default::default(),
- text_memos: Default::default(),
- inline_content_preparation_buffers: Default::default(),
- prepared_inline_content_memos: Default::default(),
- fragment_builder_scratch: Default::default(),
- }
- }
-}
-
impl LayoutScratch {
/// The scratch of a fork of the arena, which keeps the run memos the arena's entries were stored for and starts
/// the rest anew.
@@ -157,11 +140,6 @@ impl LayoutScratch {
);
}
- /// What the pass found out outside any run, which its driver reports itself.
- pub(crate) fn take_host_findings_outside_runs(&self) -> HostFindings {
- std::mem::take(&mut self.host_findings_outside_runs.borrow_mut())
- }
-
/// Brings the run memos up to date with what the commit into `arena` did to their boxes, and sweeps the run cache.
pub(crate) fn end_layout_pass(&self, arena: &mut LayoutNodeArena) {
self.apply_memo_invalidations(arena);
@@ -500,10 +478,11 @@ mod tests {
fn a_nested_run_keeps_its_own_root_and_host_findings() {
let mut arena = LayoutNodeArena::new();
let scratch = LayoutScratch::default();
+ let host_findings_outside_runs = RefCell::default();
let root = arena.allocate_for_test().slot;
let child = arena.allocate_for_test().slot;
RunState::with_root(
- LayoutPass::for_test(&arena, &scratch),
+ LayoutPass::for_test(&arena, &scratch, &host_findings_outside_runs),
root,
NodeSlotId::INVALID,
None,
@@ -529,6 +508,6 @@ mod tests {
);
},
);
- assert!(scratch.take_host_findings_outside_runs().is_empty());
+ assert!(host_findings_outside_runs.borrow().is_empty());
}
}
diff --git a/Libraries/LibWeb/Rust/src/layout/sizing_context.rs b/Libraries/LibWeb/Rust/src/layout/sizing_context.rs
index aead65c8aca..55cd30d28fd 100644
--- a/Libraries/LibWeb/Rust/src/layout/sizing_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/sizing_context.rs
@@ -4428,9 +4428,11 @@ mod replaced_ratio_tests {
..Default::default()
},
);
+ let host_findings_outside_runs = RefCell::default();
let callbacks = LayoutPass::new(
&arena,
&scratch,
+ &host_findings_outside_runs,
LayoutStageFacts {
viewport_inline_size: CssPixels::from_integer(800),
viewport_block_size: CssPixels::from_integer(600),