Skip to content

Truly independent web browser

LibWeb: Assert that a run places every box with placed children

Aliaksandr Kalenikb6620fffa3b1
diff --git a/Libraries/LibWeb/Rust/src/layout/formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/formatting_context.rs
index a72b22f22bd..fe6741cfd46 100644
--- a/Libraries/LibWeb/Rust/src/layout/formatting_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/formatting_context.rs
@@ -2532,7 +2532,7 @@ fn lay_out_run_root_and_contents<'pass>(
let take_run_fragments = || {
run.fragments
.as_ref()
- .map(|fragments| fragments.take_unplaced_root(run.records, &body_run.callbacks))
+ .map(|fragments| fragments.take_unplaced_root(&body_run.callbacks))
};
let registered_abspos_children_could_never_be_laid_out = run.fragments.is_none();
@@ -3591,7 +3591,7 @@ fn finish_entry_pass(
should_collect_devtools_layout_data,
entry_fragments,
);
- let pass_fragments = entry_fragments.take_completed_pass(entry_records, callbacks);
+ let pass_fragments = entry_fragments.take_completed_pass(callbacks);
debug_assert!(
!pass_fragments.roots.is_empty(),
"an entry pass always produces the entry root's fragment"
diff --git a/Libraries/LibWeb/Rust/src/layout/fragment_tree.rs b/Libraries/LibWeb/Rust/src/layout/fragment_tree.rs
index 69471cd79c4..3e61a98a361 100644
--- a/Libraries/LibWeb/Rust/src/layout/fragment_tree.rs
+++ b/Libraries/LibWeb/Rust/src/layout/fragment_tree.rs
@@ -689,21 +689,6 @@ impl PlacementData {
frame,
)
}
-
- /// The placement data of a box `close()` hands on unplaced or placed as it is.
- fn of_box_as_this_run_left_it(
- records: &RunRecords,
- node: crate::layout::node_data::NodeSlotId,
- frame: geometry::Frame,
- ) -> Self {
- Self::of_box(
- &records.facts_decided_by_parent_of(node),
- None,
- None,
- records.content_offset_or_origin(node),
- frame,
- )
- }
}
fn link_fragment(fragment: std::sync::Arc<Fragment>, placement: PlacementData) -> FragmentLink {
@@ -1690,31 +1675,27 @@ impl RunFragmentBuilder {
.insert(containing_block.slot_index(), pending_fragment);
}
- pub(crate) fn take_unplaced_root(&self, records: &RunRecords, callbacks: &LayoutPass<'_>) -> UnplacedRootFragment {
+ pub(crate) fn take_unplaced_root(&self, callbacks: &LayoutPass<'_>) -> UnplacedRootFragment {
debug_assert!(
!self.is_entry_accumulator,
"an entry accumulator closes as a pass, not a run"
);
- self.close(records, callbacks)
+ self.close(callbacks)
}
- pub(crate) fn take_completed_pass(
- &self,
- records: &RunRecords,
- callbacks: &LayoutPass<'_>,
- ) -> CompletedPassFragments {
+ pub(crate) fn take_completed_pass(&self, callbacks: &LayoutPass<'_>) -> CompletedPassFragments {
debug_assert!(
self.is_entry_accumulator,
"an ordinary run closes as a singular unplaced root"
);
- let root = self.close(records, callbacks);
+ let root = self.close(callbacks);
CompletedPassFragments {
roots: root.scoped_descendants,
reused_subtree_roots: root.reused_subtree_roots,
}
}
- fn close(&self, records: &RunRecords, callbacks: &LayoutPass<'_>) -> UnplacedRootFragment {
+ fn close(&self, callbacks: &LayoutPass<'_>) -> UnplacedRootFragment {
let mut inner = self.inner.take();
let mut propagated_pending_abspos = std::mem::take(&mut inner.pending_abspos_at_root);
let mut propagated_anchor_candidates = std::mem::take(&mut inner.anchor_candidates_at_root);
@@ -1727,20 +1708,13 @@ impl RunFragmentBuilder {
propagated_pending_abspos.extend(pending_fragment.pending_abspos);
propagated_anchor_candidates.extend(pending_fragment.anchor_candidates);
propagated_inline_containing_block_rects.extend(pending_fragment.inline_containing_block_rects);
- if pending_fragment.children.is_empty() {
- continue;
- }
- inner.top_scope_links.push(link_fragment(
- snapshot_fragment(
- callbacks,
- pending_fragment.node,
- pending_fragment.children,
- records.fragment_geometry_of(pending_fragment.node, callbacks),
- records.facts_decided_by_parent_of(pending_fragment.node).fragment_facts,
- pending_fragment.payloads,
- ),
- PlacementData::of_box_as_this_run_left_it(records, pending_fragment.node, callbacks.frame),
- ));
+ // NB: Every formatting context places the containing blocks of the children it places, or leaves them
+ // unplaced with the children they contain.
+ assert!(
+ pending_fragment.children.is_empty(),
+ "{:?} contains placed children but was never placed",
+ pending_fragment.node
+ );
}
// NB: A reused subtree root its run never placed has no children of its own in this run, as an empty child run
// root has, and closes the same way.
diff --git a/Libraries/LibWeb/Rust/src/layout/run_records.rs b/Libraries/LibWeb/Rust/src/layout/run_records.rs
index 6cb1c294637..048a6bbcba4 100644
--- a/Libraries/LibWeb/Rust/src/layout/run_records.rs
+++ b/Libraries/LibWeb/Rust/src/layout/run_records.rs
@@ -623,16 +623,6 @@ impl<'arena> RunRecords<'arena> {
self.is_root_with_record(node) || self.held_boxes.borrow().contains_key(&node)
}
- #[track_caller]
- fn panic_for_box_read_outside_the_layout_owning_its_record(&self, node: Node) -> ! {
- panic!(
- "the run rooted at slot {} reads slot {}, whose layout keeps it in a record of its own (read at {})",
- self.root.slot_index(),
- node.slot_index(),
- std::panic::Location::caller(),
- )
- }
-
#[track_caller]
fn panic_for_box_not_held(&self, node: Node) -> ! {
panic!(
@@ -804,40 +794,6 @@ impl<'arena> RunRecords<'arena> {
kept.holding = KeptBoxHolding::ChildHandedBack;
}
- /// What the fragment of `node` shows of the box's own layout, which finishes the lines this run laid out in it.
- #[track_caller]
- pub(crate) fn fragment_geometry_of(
- &self,
- node: Node,
- callbacks: &LayoutPass<'_>,
- ) -> fragment_tree::FragmentGeometry {
- let geometry_of_record = |used: &UsedValues| {
- let line_data = used.finish_line_data(callbacks);
- fragment_tree::FragmentGeometry {
- cells: used_values::RecordInFrame::new(used, callbacks.frame).cells(),
- line_data,
- }
- };
- if self.is_root_with_record(node) {
- return geometry_of_record(self.used_values(node));
- }
- let holding = match self.held_boxes.borrow().get(&node) {
- Some(kept) => match &kept.holding {
- KeptBoxHolding::LaidOutByThisRun { record } => Ok(*record),
- KeptBoxHolding::ChildNotYetLaidOut | KeptBoxHolding::ChildHandedBack => Err(true),
- KeptBoxHolding::LaidOutInRecordItsLayoutOwns => Err(false),
- },
- None => self.panic_for_box_not_held(node),
- };
- let record = match holding {
- Ok(record) => record,
- Err(true) => panic!("the fragment of {node:?} is built from the box its run hands back to its parent"),
- Err(false) => self.panic_for_box_read_outside_the_layout_owning_its_record(node),
- };
- // SAFETY: The run keeps the record until it is dropped, which ends this borrow of the run.
- geometry_of_record(unsafe { record.as_ref() })
- }
-
pub(crate) fn store_table_inline_layout(&self, table: Node, layout: table_formatting_context::TableInlineLayout) {
self.table_inline_layouts.borrow_mut().insert(table, layout);
}