Truly independent web browser
LibWeb: Leave a discarded run out of the layout trace by its pass view
Aliaksandr Kalenik009bf70a72e1
diff --git a/Libraries/LibWeb/Rust/src/layout/layout_pass.rs b/Libraries/LibWeb/Rust/src/layout/layout_pass.rsindex 167087ed7f1..6c8a5b6719b 100644--- a/Libraries/LibWeb/Rust/src/layout/layout_pass.rs+++ b/Libraries/LibWeb/Rust/src/layout/layout_pass.rs@@ -170,9 +170,13 @@ impl<'arena> LayoutPass<'arena> {None}- /// The document's layout trace, which records what the pass does while the document traces its layout.- pub(crate) fn layout_trace(&self) -> &'arena super::trace::LayoutTrace {- &self.scratch.layout_trace+ /// Where this pass view records what its runs do while the document traces its layout: the document's layout trace,+ /// or nowhere inside a run whose result is discarded.+ pub(crate) fn layout_trace(&self) -> super::trace::LayoutTraceTarget<'arena> {+ if self.reads_no_memoized_layout {+ return super::trace::LayoutTraceTarget::recording_nothing();+ }+ super::trace::LayoutTraceTarget::recording_into(&self.scratch.layout_trace)}/// The results of formatting context runs, kept for the runs and passes after them.diff --git a/Libraries/LibWeb/Rust/src/layout/run_repeatability.rs b/Libraries/LibWeb/Rust/src/layout/run_repeatability.rsindex f4ff294b3dd..149fa17413a 100644--- a/Libraries/LibWeb/Rust/src/layout/run_repeatability.rs+++ b/Libraries/LibWeb/Rust/src/layout/run_repeatability.rs@@ -43,11 +43,7 @@ pub(super) fn lay_out_discarded_run(if run_repeatability_verification() == RunRepeatabilityVerification::Off || callbacks.reads_no_memoized_layout() {return None;}- Some(- callbacks- .layout_trace()- .without_events(|| callbacks.lay_out_discarded_run(run)),- )+ Some(callbacks.lay_out_discarded_run(run))}/// Checks that the run of `box_` that produced `used` repeated what the discarded run that produced `discarded` did.@@ -162,9 +158,8 @@ pub(super) fn verify_run_ignores_its_unobserved_own_block_size_and_block_marginsreference_inputs.push((cells, input.clone(), reference));}for (reference_cells, reference_input, reference) in reference_inputs {- let reference_outputs = callbacks.layout_trace().without_events(|| {- callbacks.lay_out_discarded_run(|callbacks| lay_out(callbacks, reference_cells, reference_input))- });+ let reference_outputs =+ callbacks.lay_out_discarded_run(|callbacks| lay_out(callbacks, reference_cells, reference_input));ComparedLayouts {checked: &checked,reference: &reference,diff --git a/Libraries/LibWeb/Rust/src/layout/trace.rs b/Libraries/LibWeb/Rust/src/layout/trace.rsindex ac33480179c..bd1cc7d8eaa 100644--- a/Libraries/LibWeb/Rust/src/layout/trace.rs+++ b/Libraries/LibWeb/Rust/src/layout/trace.rs@@ -180,46 +180,62 @@ impl LayoutTrace {record.0 = self.0.take();}- /// Runs `untraced` with nothing it does traced.- pub(super) fn without_events<R>(&self, untraced: impl FnOnce() -> R) -> R {- let trace = self.0.take();- let result = untraced();- *self.0.borrow_mut() = trace;- result- }-pub(super) fn pass(&self, partial_root: Option<NodeSlotId>) -> Option<Scope<'_>> {match partial_root {Some(root) => self.scope("layout PARTIAL ", Some(root), String::new),None => self.scope("layout FULL", None, String::new),}}+}++/// Where a pass view records the events of its runs: the pass's trace, or nowhere for the view of a run whose result is+/// discarded.+#[derive(Clone, Copy)]+pub(crate) struct LayoutTraceTarget<'a>(Option<&'a LayoutTrace>);++impl<'a> LayoutTraceTarget<'a> {+ pub(super) fn recording_into(trace: &'a LayoutTrace) -> Self {+ Self(Some(trace))+ }++ pub(super) fn recording_nothing() -> Self {+ Self(None)+ }++ fn scope(+ self,+ prefix: &'static str,+ owner: Option<NodeSlotId>,+ text: impl FnOnce() -> String,+ ) -> Option<Scope<'a>> {+ self.0?.scope(prefix, owner, text)+ }/// An in-flow block whose subtree is reused from the previous layout, moved to where the flow now puts it.- pub(super) fn reused_in_flow_subtree(&self, node: NodeSlotId) {+ pub(super) fn reused_in_flow_subtree(self, node: NodeSlotId) {drop(self.scope("", Some(node), || " REUSE IN-FLOW SUBTREE".into()));}/// An intrinsic size of `node` that the measurement cache holds.- pub(super) fn intrinsic_size_hit(&self, node: NodeSlotId, kind: IntrinsicSizeCacheKind) {+ pub(super) fn intrinsic_size_hit(self, node: NodeSlotId, kind: IntrinsicSizeCacheKind) {drop(self.scope("", Some(node), || {format!(" MEASURE {} (cache=hit)", intrinsic_size_name(kind))}));}/// An intrinsic size of `node` that the measurement cache does not hold. The work that measures it nests under it.- pub(super) fn intrinsic_size_miss(&self, node: NodeSlotId, kind: IntrinsicSizeCacheKind) -> Option<Scope<'_>> {+ pub(super) fn intrinsic_size_miss(self, node: NodeSlotId, kind: IntrinsicSizeCacheKind) -> Option<Scope<'a>> {self.scope("", Some(node), || {format!(" MEASURE {} (cache=miss)", intrinsic_size_name(kind))})}pub(super) fn run(- &self,+ self,root: NodeSlotId,fc_type: FormattingContextType,action: impl FnOnce() -> &'static str,- ) -> Option<Scope<'_>> {+ ) -> Option<Scope<'a>> {self.scope("", Some(root), || {let context = match fc_type {FormattingContextType::Block => "block",@@ -381,14 +397,15 @@ mod tests {trace.begin();{let _pass = trace.scope("layout FULL", None, String::new);+ let target = LayoutTraceTarget::recording_into(&trace);{- let miss = trace+ let miss = target.intrinsic_size_miss(NodeSlotId::new(1, 1), IntrinsicSizeCacheKind::MaxContentInline).unwrap();- drop(trace.intrinsic_size_miss(NodeSlotId::new(2, 1), IntrinsicSizeCacheKind::MaxContentInline));+ drop(target.intrinsic_size_miss(NodeSlotId::new(2, 1), IntrinsicSizeCacheKind::MaxContentInline));miss.append(" FROM ITEMS");}- trace.intrinsic_size_hit(NodeSlotId::new(1, 1), IntrinsicSizeCacheKind::MinContentInline);+ target.intrinsic_size_hit(NodeSlotId::new(1, 1), IntrinsicSizeCacheKind::MinContentInline);}// The owners are not named, so each line starts with the indentation and the space before the event.assert_eq!(@@ -436,7 +453,7 @@ mod tests {arena.begin_active_layout_pass();let recorder = LayoutTrace::default();recorder.take_over_from(&mut arena.layout_trace);- drop(recorder.run(owner.slot, FormattingContextType::Block, || "RUN"));+ drop(LayoutTraceTarget::recording_into(&recorder).run(owner.slot, FormattingContextType::Block, || "RUN"));recorder.hand_back_to(&mut arena.layout_trace);assert!(arena.leave_active_layout_pass());let names = arena