Skip to content

Truly independent web browser

LibWeb: Record the inputs a run never observed in its outputs

Aliaksandr Kalenik375dd7ec0af9
diff --git a/Libraries/LibWeb/Rust/src/layout/fc_run_cache.rs b/Libraries/LibWeb/Rust/src/layout/fc_run_cache.rs
index 7f1a56810e0..31a47ee82ab 100644
--- a/Libraries/LibWeb/Rust/src/layout/fc_run_cache.rs
+++ b/Libraries/LibWeb/Rust/src/layout/fc_run_cache.rs
@@ -19,8 +19,9 @@ pub(super) struct FcRunCacheKey {
root_cells: used_values::RootInputCells,
}
+/// The inputs a run never observed, at which its stored outputs are reused as they are.
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
-pub(super) struct RunInputsTheStoredRunNeverObserved {
+pub(crate) struct RunInputsTheStoredRunNeverObserved {
pub(super) percentage_block_basis_and_block_size_definiteness: bool,
pub(super) definite_available_inline_sizes_at_or_above: Option<CssPixels>,
pub(super) percentage_inline_basis: bool,
@@ -28,28 +29,12 @@ pub(super) struct RunInputsTheStoredRunNeverObserved {
}
impl RunInputsTheStoredRunNeverObserved {
- fn proven_by_stored_run(outputs: &formatting_context::RunOutputs) -> Self {
- Self {
- percentage_block_basis_and_block_size_definiteness: !outputs.result.depends_on_percentage_block_size,
- definite_available_inline_sizes_at_or_above: outputs
- .atomic_root_sizing_repeats_for_available_inline_sizes_at_or_above,
- percentage_inline_basis: outputs
- .atomic_root_sizing_repeats_for_available_inline_sizes_at_or_above
- .is_some()
- || outputs.result.percentage_inline_basis_observation
- == formatting_context::PercentageInlineBasisObservation::Unobserved,
- own_block_size: outputs.result.own_block_size_observation,
- }
- }
-
- fn accepted_when_reusing_stale_line_data_after_structural_inline_damage(
- outputs: &formatting_context::RunOutputs,
- ) -> Self {
+ fn accepted_when_reusing_stale_line_data_after_structural_inline_damage(self) -> Self {
Self {
definite_available_inline_sizes_at_or_above: None,
percentage_inline_basis: false,
own_block_size: formatting_context::OwnBlockSizeObservation::Observed,
- ..Self::proven_by_stored_run(outputs)
+ ..self
}
}
@@ -317,7 +302,7 @@ impl FcRunCacheEntry {
self.outputs.root_outcome.line_data.as_ref(),
) && fragment.content_inline_size == content_inline_size
&& (fragment.content_block_size == content_block_size
- || self.outputs.result.own_block_size_observation
+ || self.outputs.inputs_never_observed.own_block_size
== formatting_context::OwnBlockSizeObservation::Unobserved)
})
.unwrap_or(false);
@@ -372,9 +357,7 @@ impl FcRunCacheEntry {
result: self.outputs.result,
root: None,
root_outcome: self.outputs.root_outcome.clone(),
- atomic_root_sizing_repeats_for_available_inline_sizes_at_or_above: self
- .outputs
- .atomic_root_sizing_repeats_for_available_inline_sizes_at_or_above,
+ inputs_never_observed: self.outputs.inputs_never_observed,
host_findings: self.outputs.host_findings.clone(),
}
}
@@ -404,7 +387,7 @@ impl FcRunCacheEntry {
}
fn answers_probe_for(&self, key: &FcRunCacheKey) -> bool {
- let unobserved = RunInputsTheStoredRunNeverObserved::proven_by_stored_run(&self.outputs);
+ let unobserved = self.outputs.inputs_never_observed;
self.key.matches(key, unobserved)
|| (self.table_cell_intrinsic_block_padding_unobserved
&& self
@@ -469,8 +452,7 @@ fn outputs_without_descendant_fragments(outputs: &formatting_context::RunOutputs
result: outputs.result,
root,
root_outcome: outputs.root_outcome.clone(),
- atomic_root_sizing_repeats_for_available_inline_sizes_at_or_above: outputs
- .atomic_root_sizing_repeats_for_available_inline_sizes_at_or_above,
+ inputs_never_observed: outputs.inputs_never_observed,
host_findings: outputs.host_findings.clone(),
}
}
@@ -616,9 +598,10 @@ impl FcRunCacheArenaStore {
&& entry.validity.slot_generation == validity.slot_generation
&& entry.key.matches(
key,
- RunInputsTheStoredRunNeverObserved::accepted_when_reusing_stale_line_data_after_structural_inline_damage(
- &entry.outputs,
- ),
+ entry
+ .outputs
+ .inputs_never_observed
+ .accepted_when_reusing_stale_line_data_after_structural_inline_damage(),
)
// Each child-list edit bumps once when topology changes and once
// when the parent is marked for layout-tree-update layout.
@@ -1087,7 +1070,11 @@ mod tests {
line_data: None,
rare: None,
},
- atomic_root_sizing_repeats_for_available_inline_sizes_at_or_above: None,
+ // NB: As a run whose result depends on no percentage block size proves.
+ inputs_never_observed: RunInputsTheStoredRunNeverObserved {
+ percentage_block_basis_and_block_size_definiteness: true,
+ ..RunInputsTheStoredRunNeverObserved::default()
+ },
host_findings: None,
},
table_cell_intrinsic_block_padding_unobserved: false,
@@ -1530,14 +1517,9 @@ mod tests {
key.input.containing_block_constraints.percentage_basis_inline_size = Some(px(basis));
key
};
- let mut outputs = entry(item_key(40, false), 1, None, 0).outputs;
- assert!(!at_percentage_inline_basis(400).matches(
- &at_percentage_inline_basis(300),
- RunInputsTheStoredRunNeverObserved::proven_by_stored_run(&outputs)
- ));
- outputs.result.percentage_inline_basis_observation =
- formatting_context::PercentageInlineBasisObservation::Unobserved;
- let unobserved = RunInputsTheStoredRunNeverObserved::proven_by_stored_run(&outputs);
+ let mut unobserved = entry(item_key(40, false), 1, None, 0).outputs.inputs_never_observed;
+ assert!(!at_percentage_inline_basis(400).matches(&at_percentage_inline_basis(300), unobserved));
+ unobserved.percentage_inline_basis = true;
assert!(at_percentage_inline_basis(400).matches(&at_percentage_inline_basis(300), unobserved));
let mut wider = at_percentage_inline_basis(300);
wider.root_cells.content_inline_size = px(320);
@@ -1548,9 +1530,7 @@ mod tests {
);
assert!(!at_percentage_inline_basis(400).matches(
&at_percentage_inline_basis(300),
- RunInputsTheStoredRunNeverObserved::accepted_when_reusing_stale_line_data_after_structural_inline_damage(
- &outputs
- )
+ unobserved.accepted_when_reusing_stale_line_data_after_structural_inline_damage()
));
}
@@ -1576,17 +1556,12 @@ mod tests {
#[test]
fn stale_line_data_after_structural_inline_damage_is_taken_only_at_the_same_own_block_size() {
- let mut outputs = entry(item_key(40, false), 1, None, 0).outputs;
- outputs.result.own_block_size_observation = formatting_context::OwnBlockSizeObservation::Unobserved;
- assert!(item_key(40, false).matches(
- &item_key(60, true),
- RunInputsTheStoredRunNeverObserved::proven_by_stored_run(&outputs)
- ));
+ let mut unobserved = entry(item_key(40, false), 1, None, 0).outputs.inputs_never_observed;
+ unobserved.own_block_size = formatting_context::OwnBlockSizeObservation::Unobserved;
+ assert!(item_key(40, false).matches(&item_key(60, true), unobserved));
assert!(!item_key(40, false).matches(
&item_key(60, true),
- RunInputsTheStoredRunNeverObserved::accepted_when_reusing_stale_line_data_after_structural_inline_damage(
- &outputs
- )
+ unobserved.accepted_when_reusing_stale_line_data_after_structural_inline_damage()
));
}
}
diff --git a/Libraries/LibWeb/Rust/src/layout/formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/formatting_context.rs
index 6f6b71d5b95..ed12b9004cc 100644
--- a/Libraries/LibWeb/Rust/src/layout/formatting_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/formatting_context.rs
@@ -979,8 +979,6 @@ pub(crate) struct ChildLayoutResult {
/// For a box with a preferred aspect ratio, the block size of its laid out content.
pub content_block_size_for_aspect_ratio_minimum: Option<CssPixels>,
pub depends_on_percentage_block_size: bool,
- pub own_block_size_observation: OwnBlockSizeObservation,
- pub percentage_inline_basis_observation: PercentageInlineBasisObservation,
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
@@ -990,13 +988,6 @@ pub(crate) enum OwnBlockSizeObservation {
Unobserved,
}
-#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
-pub(crate) enum PercentageInlineBasisObservation {
- #[default]
- Observed,
- Unobserved,
-}
-
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub(crate) enum RootCellsOutcome {
AllCells(used_values::UsedValuesCellState),
@@ -1058,7 +1049,7 @@ pub(crate) struct RunOutputs {
pub(crate) result: ChildLayoutResult,
pub(crate) root: Option<fragment_tree::UnplacedRootFragment>,
pub(crate) root_outcome: RunRootOutcome,
- pub(crate) atomic_root_sizing_repeats_for_available_inline_sizes_at_or_above: Option<CssPixels>,
+ pub(crate) inputs_never_observed: fc_run_cache::RunInputsTheStoredRunNeverObserved,
/// Boxed, as most runs find out nothing for the host.
pub(crate) host_findings: Option<Box<super::run_records::HostFindings>>,
}
@@ -1264,7 +1255,7 @@ impl<'pass> FormattingContextRun<'pass> {
&self,
result: ChildLayoutResult,
root: Option<fragment_tree::UnplacedRootFragment>,
- atomic_root_sizing_repeats_for_available_inline_sizes_at_or_above: Option<CssPixels>,
+ inputs_never_observed: fc_run_cache::RunInputsTheStoredRunNeverObserved,
parent_owns_root_input_cells: bool,
) -> RunOutputs {
let record = self.records.used_values(self.box_);
@@ -1278,7 +1269,7 @@ impl<'pass> FormattingContextRun<'pass> {
result,
root,
root_outcome,
- atomic_root_sizing_repeats_for_available_inline_sizes_at_or_above,
+ inputs_never_observed,
host_findings: self.records.take_host_findings(),
}
}
@@ -2273,12 +2264,20 @@ fn execute_formatting_context_run(
);
}
result.depends_on_percentage_block_size = run.sizing().resolve_percentage_block_size_dependency(run.box_);
- if !run_is_handed_table_inline_layout_outside_its_key {
- result.own_block_size_observation =
- own_block_size_observation_of_item_run(run, fc_type, &input, &result);
- result.percentage_inline_basis_observation =
- percentage_inline_basis_observation_of_item_run(run, fc_type, &input);
- }
+ let item_run_observations_are_known = !run_is_handed_table_inline_layout_outside_its_key;
+ let inputs_never_observed = fc_run_cache::RunInputsTheStoredRunNeverObserved {
+ percentage_block_basis_and_block_size_definiteness: !result.depends_on_percentage_block_size,
+ definite_available_inline_sizes_at_or_above:
+ atomic_root_sizing_repeats_for_available_inline_sizes_at_or_above,
+ percentage_inline_basis: atomic_root_sizing_repeats_for_available_inline_sizes_at_or_above.is_some()
+ || (item_run_observations_are_known
+ && item_run_never_observes_percentage_inline_basis(run, fc_type, &input)),
+ own_block_size: if item_run_observations_are_known {
+ own_block_size_observation_of_item_run(run, fc_type, &input, &result)
+ } else {
+ OwnBlockSizeObservation::Observed
+ },
+ };
// NB: The root's descendants are laid out in the frame the root establishes.
let take_run_fragments = || {
@@ -2292,7 +2291,7 @@ fn execute_formatting_context_run(
return run.outputs(
result,
take_run_fragments(),
- atomic_root_sizing_repeats_for_available_inline_sizes_at_or_above,
+ inputs_never_observed,
parent_owns_root_input_cells,
);
}
@@ -2320,7 +2319,7 @@ fn execute_formatting_context_run(
return run.outputs(
result,
take_run_fragments(),
- atomic_root_sizing_repeats_for_available_inline_sizes_at_or_above,
+ inputs_never_observed,
parent_owns_root_input_cells,
);
}
@@ -2330,7 +2329,7 @@ fn execute_formatting_context_run(
run.outputs(
result,
take_run_fragments(),
- atomic_root_sizing_repeats_for_available_inline_sizes_at_or_above,
+ inputs_never_observed,
parent_owns_root_input_cells,
)
},
@@ -2959,20 +2958,15 @@ fn root_content_includes_an_orthogonal_flow_sized_by_the_root_block_size(
false
}
-fn percentage_inline_basis_observation_of_item_run(
+/// Whether the run is of an item block container whose content resolves percentages against the container itself.
+fn item_run_never_observes_percentage_inline_basis(
run: &FormattingContextRun,
fc_type: FormattingContextType,
input: &LayoutInput,
-) -> PercentageInlineBasisObservation {
- let item_is_block_container_whose_content_resolves_percentages_against_itself = fc_type
- == FormattingContextType::Block
+) -> bool {
+ fc_type == FormattingContextType::Block
&& parent_owns_root_input_cells(&run.callbacks, run.box_, input)
- && !run.sizing().measurement_root_observes_percentage_inline_basis(run.box_);
- if item_is_block_container_whose_content_resolves_percentages_against_itself {
- PercentageInlineBasisObservation::Unobserved
- } else {
- PercentageInlineBasisObservation::Observed
- }
+ && !run.sizing().measurement_root_observes_percentage_inline_basis(run.box_)
}
pub(super) fn content_block_size_adopted_after_run(
@@ -3009,7 +3003,7 @@ fn absorb_run_outputs(
result,
root,
root_outcome,
- atomic_root_sizing_repeats_for_available_inline_sizes_at_or_above: _,
+ inputs_never_observed: _,
host_findings,
} = outputs;
callbacks.scratch().receive_host_findings(host_findings);
diff --git a/Libraries/LibWeb/Rust/src/layout/run_repeatability.rs b/Libraries/LibWeb/Rust/src/layout/run_repeatability.rs
index 9b95d7ef487..91c4ab80e8c 100644
--- a/Libraries/LibWeb/Rust/src/layout/run_repeatability.rs
+++ b/Libraries/LibWeb/Rust/src/layout/run_repeatability.rs
@@ -74,18 +74,18 @@ fn unobserved_own_block_size_verification_is_enabled() -> bool {
fn run_is_verified_at_other_unobserved_root_inputs(
root_cells: used_values::RootInputCells,
- result: &formatting_context::ChildLayoutResult,
+ own_block_size: formatting_context::OwnBlockSizeObservation,
) -> bool {
- result.own_block_size_observation == formatting_context::OwnBlockSizeObservation::Unobserved
- && !root_cells.has_content_offset
+ own_block_size == formatting_context::OwnBlockSizeObservation::Unobserved && !root_cells.has_content_offset
}
fn root_inputs_at_other_own_block_sizes(
root_cells: used_values::RootInputCells,
input: LayoutInput,
- result: &formatting_context::ChildLayoutResult,
+ own_block_size: formatting_context::OwnBlockSizeObservation,
+ automatic_content_block_size: CssPixels,
) -> Vec<(used_values::RootInputCells, LayoutInput)> {
- if !run_is_verified_at_other_unobserved_root_inputs(root_cells, result) {
+ if !run_is_verified_at_other_unobserved_root_inputs(root_cells, own_block_size) {
return Vec::new();
}
let mut other_definite_own_block_sizes = Vec::new();
@@ -93,7 +93,7 @@ fn root_inputs_at_other_own_block_sizes(
other_definite_own_block_sizes.push(None);
}
let definite_block_size_with_extra_space_beyond_assigned_and_automatic_sizes =
- root_cells.content_block_size.max(result.automatic_content_block_size) + CssPixels::from_integer(50);
+ root_cells.content_block_size.max(automatic_content_block_size) + CssPixels::from_integer(50);
if definite_block_size_with_extra_space_beyond_assigned_and_automatic_sizes.raw_value() != i32::MAX {
other_definite_own_block_sizes.push(Some(
definite_block_size_with_extra_space_beyond_assigned_and_automatic_sizes,
@@ -117,9 +117,9 @@ fn root_inputs_at_other_own_block_sizes(
fn root_cells_at_other_block_margins(
root_cells: used_values::RootInputCells,
- result: &formatting_context::ChildLayoutResult,
+ own_block_size: formatting_context::OwnBlockSizeObservation,
) -> Option<used_values::RootInputCells> {
- run_is_verified_at_other_unobserved_root_inputs(root_cells, result).then(|| used_values::RootInputCells {
+ run_is_verified_at_other_unobserved_root_inputs(root_cells, own_block_size).then(|| used_values::RootInputCells {
margin_top: root_cells.margin_top + CssPixels::from_integer(30),
margin_bottom: root_cells.margin_bottom - CssPixels::from_integer(20),
..root_cells
@@ -138,18 +138,24 @@ pub(super) fn verify_run_ignores_its_unobserved_own_block_size_and_block_margins
return;
}
let checked = format!("the run of {box_:?}, which never observed its own block size or block margins,");
- let mut reference_inputs = root_inputs_at_other_own_block_sizes(root_cells, input, &outputs.result)
- .into_iter()
- .map(|(cells, input)| {
- let reference = if cells.has_definite_block_size {
- format!("its layout at the definite block size {:?}", cells.content_block_size)
- } else {
- "its layout at an indefinite block size".to_owned()
- };
- (cells, input, reference)
- })
- .collect::<Vec<_>>();
- if let Some(cells) = root_cells_at_other_block_margins(root_cells, &outputs.result) {
+ let own_block_size = outputs.inputs_never_observed.own_block_size;
+ let mut reference_inputs = root_inputs_at_other_own_block_sizes(
+ root_cells,
+ input,
+ own_block_size,
+ outputs.result.automatic_content_block_size,
+ )
+ .into_iter()
+ .map(|(cells, input)| {
+ let reference = if cells.has_definite_block_size {
+ format!("its layout at the definite block size {:?}", cells.content_block_size)
+ } else {
+ "its layout at an indefinite block size".to_owned()
+ };
+ (cells, input, reference)
+ })
+ .collect::<Vec<_>>();
+ if let Some(cells) = root_cells_at_other_block_margins(root_cells, own_block_size) {
let reference = format!(
"its layout at the block margins {:?} and {:?}",
cells.margin_top, cells.margin_bottom
@@ -208,9 +214,8 @@ impl ComparedLayouts<'_> {
"{checked} left rare payloads {reference} does not"
);
assert_eq!(
- checked_outputs.atomic_root_sizing_repeats_for_available_inline_sizes_at_or_above,
- reference_outputs.atomic_root_sizing_repeats_for_available_inline_sizes_at_or_above,
- "{checked} claims an available inline size threshold {reference} does not"
+ checked_outputs.inputs_never_observed, reference_outputs.inputs_never_observed,
+ "{checked} claims to have never observed inputs {reference} does not"
);
assert!(
host_findings_match(
@@ -541,17 +546,6 @@ mod tests {
(used_values::RootInputCells::capture(&record), input)
}
- fn result_observing(
- observation: formatting_context::OwnBlockSizeObservation,
- automatic_content_block_size: i64,
- ) -> formatting_context::ChildLayoutResult {
- formatting_context::ChildLayoutResult {
- automatic_content_block_size: px(automatic_content_block_size),
- own_block_size_observation: observation,
- ..formatting_context::ChildLayoutResult::default()
- }
- }
-
fn own_block_sizes_verified_from(
(root_cells, input): (used_values::RootInputCells, LayoutInput),
automatic_content_block_size: i64,
@@ -559,10 +553,8 @@ mod tests {
root_inputs_at_other_own_block_sizes(
root_cells,
input,
- &result_observing(
- formatting_context::OwnBlockSizeObservation::Unobserved,
- automatic_content_block_size,
- ),
+ formatting_context::OwnBlockSizeObservation::Unobserved,
+ px(automatic_content_block_size),
)
.into_iter()
.map(|(cells, input)| {
@@ -582,7 +574,8 @@ mod tests {
root_inputs_at_other_own_block_sizes(
root_cells,
input,
- &result_observing(formatting_context::OwnBlockSizeObservation::Observed, 40)
+ formatting_context::OwnBlockSizeObservation::Observed,
+ px(40)
)
.is_empty()
);
@@ -611,17 +604,12 @@ mod tests {
fn unobserved_block_margins_are_verified_at_other_block_margins_only() {
let (root_cells, _) = item_root_inputs(40, true);
assert_eq!(
- root_cells_at_other_block_margins(
- root_cells,
- &result_observing(formatting_context::OwnBlockSizeObservation::Observed, 40)
- ),
+ root_cells_at_other_block_margins(root_cells, formatting_context::OwnBlockSizeObservation::Observed),
None
);
- let cells = root_cells_at_other_block_margins(
- root_cells,
- &result_observing(formatting_context::OwnBlockSizeObservation::Unobserved, 40),
- )
- .expect("an unobserved own block size is verified at other block margins");
+ let cells =
+ root_cells_at_other_block_margins(root_cells, formatting_context::OwnBlockSizeObservation::Unobserved)
+ .expect("an unobserved own block size is verified at other block margins");
assert_ne!(cells.margin_top, root_cells.margin_top);
assert_ne!(cells.margin_bottom, root_cells.margin_bottom);
assert_eq!(