Truly independent web browser
LibWeb: Stop tracking what rule versions already say
Andreas Kling911ffd331240
diff --git a/Libraries/LibWeb/Rust/src/css/style/pipeline/differential_tests.rs b/Libraries/LibWeb/Rust/src/css/style/pipeline/differential_tests.rsindex d57886b944c..f8df778bbc7 100644--- a/Libraries/LibWeb/Rust/src/css/style/pipeline/differential_tests.rs+++ b/Libraries/LibWeb/Rust/src/css/style/pipeline/differential_tests.rs@@ -353,7 +353,6 @@ impl Workload {rules.extend(add_rules(&mut engine, sheet, &rule_source(index)));if index % 3 == 0 {engine.set_rule_layer(rules[index], layers[index % 2]);- engine.set_rule_in_a_layer(rules[index]);}}@@ -1223,7 +1222,6 @@ fn a_cascade_order_change_restyles_only_the_elements_whose_rules_moved() {add_rules(&mut engine, third, ".y { width: 3px; }");for (rule, layer) in [(base[0], layers[0]), (base[1], layers[0]), (theme[0], layers[1])] {engine.set_rule_layer(rule, layer);- engine.set_rule_in_a_layer(rule);}add_class(&mut engine, nodes[1], "x");add_class(&mut engine, nodes[2], "unmoved");diff --git a/Libraries/LibWeb/Rust/src/css/style/pipeline/rule_store.rs b/Libraries/LibWeb/Rust/src/css/style/pipeline/rule_store.rsindex 37b41934011..bd0f509f356 100644--- a/Libraries/LibWeb/Rust/src/css/style/pipeline/rule_store.rs+++ b/Libraries/LibWeb/Rust/src/css/style/pipeline/rule_store.rs@@ -75,13 +75,9 @@ struct Sheet {/// sheets hold their rules alike share. An edit copies them first.rules_shared: bool,attachments: Vec<Attachment>,- /// A disabled sheet keeps its program, identities, and order tokens; only its activation- /// changes, which is why `disabled` is a predicate update rather than a detach.- enabled: bool,/// Whether the sheet's own conditions currently hold. A sheet whose media does not match/// contributes nothing, and a rule inside it can reach no element.conditions_hold: bool,- live: bool,/// The arenas the selector lists of the sheet's rules are in.selectors: SheetSelectors,/// The sheet of the process's user agent rules this one stands for, which holds its rules.@@ -180,9 +176,6 @@ struct Rule {/// `@media` that does not match keeps its identity, its position and its selectors; it/// simply decides nothing, which is the same shape a disabled sheet has.conditions_hold: bool,- /// Whether this rule sits in a cascade layer. Layer order decides between declarations that are- /// in layers, so a rule outside every layer cannot change hands when that order moves.- in_a_layer: bool,parent: Option<RuleID>,children_slot: Option<NonZeroU32>,nested_order: OrderToken,@@ -200,7 +193,6 @@ impl Rule {let Self {sheet,conditions_hold,- in_a_layer,parent,children_slot,nested_order,@@ -211,7 +203,6 @@ impl Rule {(sheet,conditions_hold,- in_a_layer,parent,children_slot,nested_order,@@ -390,7 +381,7 @@ impl PartialEq for RuleDeclarations {}/// The document's stylesheet program: identities, versions, order, and attachment.-#[derive(Clone)]+#[derive(Clone, Default)]pub struct RuleStore {/// What the host published of each rule beside its program: its declarations, the conditions of/// the container rules around it, and the identity of the rule object it came from.@@ -545,7 +536,7 @@ impl RuleStore {}// NB: What the host and the summaries read of a rule's selectors names the atoms of their// arena, which a sweep has to keep the document's names of.- for sheet in self.sheets.iter().filter(|sheet| sheet.live) {+ for sheet in &self.sheets {for (_, arena) in &sheet.selectors.arenas {let leased = arena.leased_atoms();visited += u64::try_from(leased.len()).expect("atom count exceeds u64");@@ -566,22 +557,7 @@ impl RuleStore {#[must_use]pub fn new() -> Self {- Self {- native: Default::default(),- custom_declarations: HashMap::default(),- sheets: Vec::new(),- rules: RuleRecordTable::default(),- rule_children: Vec::new(),- rules_declaring_custom_properties: 0,- rules_gated_by_container_query: 0,- rule_versions: RuleVersionTable::default(),- sheet_order: Column::default(),- sheets_by_scope: Column::default(),- layer_ranks: Column::default(),- scopes_using_document_sheets: BitColumn::default(),- scope_chains: Vec::new(),- user_agent: None,- }+ Self::default()}// -- Sheets ------------------------------------------------------------------------------@@ -594,9 +570,7 @@ impl RuleStore {rule_order: Arc::default(),rules_shared: false,attachments: Vec::new(),- enabled: true,conditions_hold: true,- live: true,selectors: SheetSelectors::default(),user_agent: None,});@@ -611,15 +585,6 @@ impl RuleStore {self.sheet_order[index].get_or_insert_with(OrderMaintenance::new)}- /// Enabling or disabling a sheet updates its activation, not its attachment: identities, order- /// tokens, and compiled programs all survive.- pub fn set_sheet_enabled(&mut self, sheet: SheetID, enabled: bool) {- if self.sheets[sheet.0 as usize].enabled == enabled {- return;- }- self.sheets[sheet.0 as usize].enabled = enabled;- }-/// Record whether a sheet's own conditions hold. This is activation, not attachment: the sheet/// keeps its program, its identities, and its position.pub fn set_sheet_conditions_hold(&mut self, sheet: SheetID, conditions_hold: bool) {@@ -638,7 +603,7 @@ impl RuleStore {#[must_use]pub fn sheet_contributes(&self, sheet: SheetID) -> bool {let sheet = &self.sheets[sheet.0 as usize];- sheet.live && sheet.enabled && sheet.conditions_hold+ sheet.conditions_hold}/// Whether a rule can decide anything right now: it is still in its sheet, and its sheet is@@ -681,18 +646,6 @@ impl RuleStore {self.rules[rule.0 as usize].conditions_hold}- pub fn set_rule_in_a_layer(&mut self, rule: RuleID, in_a_layer: bool) {- if self.rules[rule.0 as usize].in_a_layer == in_a_layer {- return;- }- self.rules[rule.0 as usize].in_a_layer = in_a_layer;- }-- #[must_use]- pub fn rule_is_in_a_layer(&self, rule: RuleID) -> bool {- self.record(rule).in_a_layer- }-#[must_use]pub fn sheet_origin(&self, sheet: SheetID) -> CascadeOrigin {self.sheets[sheet.0 as usize].origin@@ -835,7 +788,6 @@ impl RuleStore {self.rules.push(Rule {sheet,conditions_hold: true,- in_a_layer: false,parent,children_slot: None,nested_order: order,@@ -1447,12 +1399,6 @@ impl RuleStore {}}-impl Default for RuleStore {- fn default() -> Self {- Self::new()- }-}-#[cfg(test)]impl RuleStore {/// Attach a sheet to a style scope at the end of that scope's sheet order.@@ -1527,10 +1473,6 @@ impl RuleStore {self.attach_sheet_before(sheet, before);}- pub fn sheet_is_enabled(&self, sheet: SheetID) -> bool {- self.sheets[sheet.0 as usize].enabled- }-/// Append a rule to a sheet or to a grouping rule.pub fn append_rule(&mut self, sheet: SheetID, parent: Option<RuleID>, kind: RuleKind) -> RuleID {let order_axis = self.rule_order_mut(sheet);@@ -1788,18 +1730,6 @@ mod tests {);}- #[test]- fn disabling_a_sheet_keeps_its_program_and_position() {- let (mut program, sheet) = program_with_sheet();- let rule = program.append_rule(sheet, None, RuleKind::Style);- let version = program.rule_version(rule).clone();-- program.set_sheet_enabled(sheet, false);- assert!(!program.sheet_is_enabled(sheet));- assert_eq!(program.sheets_in_scope(TreeScopeID::DOCUMENT), vec![sheet]);- assert_eq!(*program.rule_version(rule), version);- }-#[test]fn layer_topology_changes_ranks_without_touching_rules() {let mut program = RuleStore::new();diff --git a/Libraries/LibWeb/Rust/src/css/style/pipeline/rule_store/identities.rs b/Libraries/LibWeb/Rust/src/css/style/pipeline/rule_store/identities.rsindex 6d749d9abea..61eea842adc 100644--- a/Libraries/LibWeb/Rust/src/css/style/pipeline/rule_store/identities.rs+++ b/Libraries/LibWeb/Rust/src/css/style/pipeline/rule_store/identities.rs@@ -11,7 +11,7 @@ pub use crate::css::cascaded_properties::CascadeOrigin;use crate::css::declaration_block::DeclarationEntry;use crate::css::style::cascade::CascadeOperator;use crate::css::style::index::StyleAtomID;-use std::hash::{Hash, Hasher};+use std::hash::Hash;define_id! {/// Semantic identity of a sheet, stable across edits to its contents.@@ -148,7 +148,7 @@ impl RuleKind {////// A version holds its selector list by where it starts among the selectors of its sheet, which no/// other list of the sheet ever starts at: a version whose selectors did not change keeps them.-#[derive(Clone)]+#[derive(Clone, PartialEq, Eq, Hash, Debug)]pub struct RuleVersion {pub kind: RuleKind,/// The name a rule declares, for the rules that reach their consumers by name rather than by@@ -166,18 +166,6 @@ pub struct RuleVersion {const _: () = assert!(size_of::<RuleVersion>() == 24);impl RuleVersion {- fn identity(&self) -> impl Eq + Hash + std::fmt::Debug + '_ {- let Self {- kind,- declared_name,- selectors,- declaration_block,- layer,- scope,- } = self;- (kind, declared_name, selectors, declaration_block, layer, scope)- }-#[must_use]pub const fn new(kind: RuleKind) -> Self {Self {@@ -200,23 +188,3 @@ impl RuleVersion {self.declared_name = name;}}--impl PartialEq for RuleVersion {- fn eq(&self, other: &Self) -> bool {- self.identity() == other.identity()- }-}--impl Eq for RuleVersion {}--impl Hash for RuleVersion {- fn hash<H: Hasher>(&self, state: &mut H) {- self.identity().hash(state);- }-}--impl std::fmt::Debug for RuleVersion {- fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {- self.identity().fmt(formatter)- }-}diff --git a/Libraries/LibWeb/Rust/src/css/style/pipeline/rule_store/staging.rs b/Libraries/LibWeb/Rust/src/css/style/pipeline/rule_store/staging.rsindex fbee55ecbac..8bd6ab7bc62 100644--- a/Libraries/LibWeb/Rust/src/css/style/pipeline/rule_store/staging.rs+++ b/Libraries/LibWeb/Rust/src/css/style/pipeline/rule_store/staging.rs@@ -126,10 +126,8 @@ impl<K: Copy + Eq + Hash + Ord, V: Clone> StagedField<K, V> {pub(in crate::css::style) struct ProgramStaging {rule_conditions: StagedField<RuleID, bool>,sheet_conditions: StagedField<SheetID, bool>,- sheet_enabled: StagedField<SheetID, bool>,rule_declarations: StagedField<RuleID, RuleDeclarations>,rule_versions: StagedField<RuleID, RuleVersion>,- rule_in_a_layer: StagedField<RuleID, bool>,rule_gated_by_container_query: StagedField<RuleID, bool>,rule_liveness: StagedField<RuleID, bool>,layer_orders: StagedField<TreeScopeID, HashMap<CascadeLayerID, u32>>,@@ -148,10 +146,8 @@ impl ProgramStaging {pub(in crate::css::style) fn is_dirty(&self) -> bool {!self.rule_conditions.is_empty()|| !self.sheet_conditions.is_empty()- || !self.sheet_enabled.is_empty()|| !self.rule_declarations.is_empty()|| !self.rule_versions.is_empty()- || !self.rule_in_a_layer.is_empty()|| !self.rule_gated_by_container_query.is_empty()|| !self.rule_liveness.is_empty()|| !self.layer_orders.is_empty()@@ -185,10 +181,8 @@ impl ProgramStaging {pub(in crate::css::style) fn clear(&mut self) {self.rule_conditions.clear();self.sheet_conditions.clear();- self.sheet_enabled.clear();self.rule_declarations.clear();self.rule_versions.clear();- self.rule_in_a_layer.clear();self.rule_gated_by_container_query.clear();self.rule_liveness.clear();self.layer_orders.clear();@@ -372,22 +366,6 @@ impl StyleEngine {);}- #[cfg(test)]- pub(in crate::css::style) fn set_sheet_enabled(&mut self, sheet: SheetID, enabled: bool) {- let previous = self- .host- .program_staging- .sheet_enabled- .current(sheet, || self.retained.rules.sheet_is_enabled(sheet));- if previous == enabled {- return;- }- self.host- .program_staging- .sheet_enabled- .stage(sheet, || self.retained.rules.sheet_is_enabled(sheet), enabled);- }-/// Begin rebuilding a sheet while retaining compatible style-rule identities by cascade/// position. The parsed CSSOM objects are new, but an unchanged semantic rule does not become a/// departure followed by an arrival merely because the whole sheet was reparsed.@@ -488,7 +466,6 @@ impl StyleEngine {self.set_rule_conditions_hold(rule, true);self.stage_rule_declarations(rule, RuleDeclarations::default());- self.stage_rule_in_a_layer(rule, false);self.stage_rule_gated_by_container_query(rule, false);let mut version = RuleVersion::new(RuleKind::Style);version.declaration_block = declaration_block;@@ -534,14 +511,6 @@ impl StyleEngine {);}- pub(in crate::css::style) fn stage_rule_in_a_layer(&mut self, rule: RuleID, in_a_layer: bool) {- self.host.program_staging.rule_in_a_layer.stage(- rule,- || self.retained.rules.rule_is_in_a_layer(rule),- in_a_layer,- );- }-/// What the staged program changes of the committed one, which has yet to take it.fn staged_rule_changes(&self) -> RuleChanges {fn moved<K: Copy, V: PartialEq>(pairs: impl Iterator<Item = (K, V, V)>) -> impl Iterator<Item = K> {@@ -554,7 +523,6 @@ impl StyleEngine {let attached = |rule: &RuleID| !program.sheet_scopes(program.rule_sheet(*rule)).is_empty();changes.rules_with_moved_contents = moved(staging.rule_declarations.pairs()).chain(moved(staging.rule_versions.pairs()))- .chain(moved(staging.rule_in_a_layer.pairs())).chain(moved(staging.rule_gated_by_container_query.pairs())).chain(moved(staging.rule_liveness.pairs())).filter(attached)@@ -569,9 +537,7 @@ impl StyleEngine {rules.dedup();changes.rules = rules;- changes.sheets = moved(staging.sheet_conditions.pairs())- .chain(moved(staging.sheet_enabled.pairs()))- .collect();+ changes.sheets = moved(staging.sheet_conditions.pairs()).collect();for (scope, before, after) in staging.sheets_in_scope.pairs() {let kept_before = before.iter().filter(|sheet| after.contains(sheet));let kept_after = after.iter().filter(|sheet| before.contains(sheet));@@ -607,17 +573,11 @@ impl StyleEngine {.add(Counter::CascadeTopologyDeltas, changes.reordered_scopes.len() as u64);let rule_conditions = self.host.program_staging.rule_conditions.take_dirty();let sheet_conditions = self.host.program_staging.sheet_conditions.take_dirty();- let sheet_enabled = self.host.program_staging.sheet_enabled.take_dirty();- if !rule_conditions.is_empty() || !sheet_conditions.is_empty() || !sheet_enabled.is_empty() {- for (rule, conditions_hold) in rule_conditions {- self.retained.rules.set_rule_conditions_hold(rule, conditions_hold);- }- for (sheet, conditions_hold) in sheet_conditions {- self.retained.rules.set_sheet_conditions_hold(sheet, conditions_hold);- }- for (sheet, enabled) in sheet_enabled {- self.retained.rules.set_sheet_enabled(sheet, enabled);- }+ for (rule, conditions_hold) in rule_conditions {+ self.retained.rules.set_rule_conditions_hold(rule, conditions_hold);+ }+ for (sheet, conditions_hold) in sheet_conditions {+ self.retained.rules.set_sheet_conditions_hold(sheet, conditions_hold);}let declarations = self.host.program_staging.rule_declarations.take_dirty();@@ -637,11 +597,7 @@ impl StyleEngine {}}- let in_a_layer = self.host.program_staging.rule_in_a_layer.take_dirty();let gated_by_container_query = self.host.program_staging.rule_gated_by_container_query.take_dirty();- for (rule, value) in in_a_layer {- self.retained.rules.set_rule_in_a_layer(rule, value);- }for (rule, value) in gated_by_container_query {self.retained.rules.set_rule_gated_by_container_query(rule, value);}@@ -735,10 +691,6 @@ impl StyleEngine {self.replace_rule_version(rule, version);}- pub fn set_rule_in_a_layer(&mut self, rule: RuleID) {- self.stage_rule_in_a_layer(rule, true);- }-pub(in crate::css::style) fn append_rule(&mut self,sheet: SheetID,diff --git a/Libraries/LibWeb/Rust/src/css/style/rule_writes.rs b/Libraries/LibWeb/Rust/src/css/style/rule_writes.rsindex b7117e4491a..cd14361cd63 100644--- a/Libraries/LibWeb/Rust/src/css/style/rule_writes.rs+++ b/Libraries/LibWeb/Rust/src/css/style/rule_writes.rs@@ -183,7 +183,6 @@ impl CompiledRule {}if self.in_a_layer {let layer = intern_native_text(engine, &self.layer_name).0;- engine.set_rule_in_a_layer(rule);engine.set_rule_layer(rule, CascadeLayerID(layer));}engine.register_native_rule(diff --git a/Libraries/LibWeb/Rust/src/css/style/tests.rs b/Libraries/LibWeb/Rust/src/css/style/tests.rsindex 87a930198d7..b35969af111 100644--- a/Libraries/LibWeb/Rust/src/css/style/tests.rs+++ b/Libraries/LibWeb/Rust/src/css/style/tests.rs@@ -771,7 +771,6 @@ fn a_selector_edit_changes_its_rule() {fn rule_metadata_commits_at_the_transaction_barrier() {let (mut engine, _, rule) = authoring_engine();engine.set_rule_gated_by_container_query(rule);- engine.set_rule_in_a_layer(rule);assert!(!engine.rules.rule_is_gated_by_container_query(rule));assert!(engine.current_rule_is_gated_by_container_query(rule));@@ -920,18 +919,6 @@ fn a_layer_order_change_reorders_its_scope() {engine.release_transaction(transaction);}-#[test]-fn disabling_a_sheet_is_an_activation_change() {- let (mut engine, sheet, _) = authoring_engine();- engine.set_sheet_enabled(sheet, false);- assert!(engine.rules.sheet_is_enabled(sheet));-- let transaction = engine.take_transaction();- assert!(!engine.rules.sheet_is_enabled(sheet));- assert_eq!(transaction.rule_changes.sheets, vec![sheet]);- engine.release_transaction(transaction);-}-#[test]fn releasing_a_flush_transaction_does_not_reclaim_atoms() {let mut engine = StyleEngine::new();