Skip to content

Truly independent web browser

LibWeb: Fold style modules that hold a single item

Andreas Kling59f786d4a801
diff --git a/Libraries/LibWeb/Rust/src/css/style/component_matching.rs b/Libraries/LibWeb/Rust/src/css/style/component_matching.rs
index 299791af03f..b6281810255 100644
--- a/Libraries/LibWeb/Rust/src/css/style/component_matching.rs
+++ b/Libraries/LibWeb/Rust/src/css/style/component_matching.rs
@@ -780,7 +780,7 @@ impl<S: SelectorSubject> SelectorEvaluator<S> {
let mut matched = Ok(false);
// The anchor stands outside the tree a `:host:has()` reads, whose root it walks from.
let axis = match (within == anchor, axis) {
- (false, _) => super::relative_selector::RelativeAxis::Descendant,
+ (false, _) => super::selector::RelativeAxis::Descendant,
(true, axis) => axis,
};
super::selector_evaluation::walk_relative_axis(tree, axis, below_the_axis, within, |candidate| {
@@ -1452,8 +1452,8 @@ fn required_dispatch_bloom(compound: Selector<'_>, context: MatchContext<'_>) ->
/// The axis from the anchor the subject of the relative selector `selector` is found on, and whether the subject
/// stands strictly below the elements the axis reaches.
-pub(crate) fn relative_axis(selector: Selector<'_>) -> (super::relative_selector::RelativeAxis, bool) {
- use super::relative_selector::RelativeAxis;
+pub(crate) fn relative_axis(selector: Selector<'_>) -> (super::selector::RelativeAxis, bool) {
+ use super::selector::RelativeAxis;
let descends = |combinator: Combinator| matches!(combinator, Combinator::Descendant | Combinator::ImmediateChild);
// NB: Read from the subject leftwards, each compound's combinator relates it to the compound left of it: the
// leftmost one's is the leading combinator, and the one read right before it is the first written after it.
diff --git a/Libraries/LibWeb/Rust/src/css/style/container_queries.rs b/Libraries/LibWeb/Rust/src/css/style/container_queries.rs
index 8961a5b17e0..01e65e96461 100644
--- a/Libraries/LibWeb/Rust/src/css/style/container_queries.rs
+++ b/Libraries/LibWeb/Rust/src/css/style/container_queries.rs
@@ -8,8 +8,8 @@
//! container query inputs, the previous layout's boxes and the containers' style records.
use super::bridge::FfiContainerEffectKind;
+use super::input_types::TransactionFactSide;
use super::selector_evaluation::StructuralRead;
-use super::transaction_view::TransactionFactSide;
use super::tree::StyleNodeID;
use super::*;
use crate::css::computed_longhand_table::FONT_METRICS_DEPEND_ON_VIEWPORT_METRICS;
diff --git a/Libraries/LibWeb/Rust/src/css/style/engine.rs b/Libraries/LibWeb/Rust/src/css/style/engine.rs
index 6268aef1a2d..c320aace023 100644
--- a/Libraries/LibWeb/Rust/src/css/style/engine.rs
+++ b/Libraries/LibWeb/Rust/src/css/style/engine.rs
@@ -6,12 +6,14 @@
use super::*;
-// The engine may move to whichever thread runs a style stage. Every host object it keeps a
-// reference to says by its type whether it may be shared between threads, so one that cannot be
-// fails this rather than passing as an opaque pointer.
+// The engine may move to whichever thread runs a style stage, and many workers read its retained
+// state at once. Every host object it keeps a reference to says by its type whether it may be
+// shared between threads, so one that cannot be fails this rather than passing as an opaque pointer.
const _: () = {
const fn assert_send<T: Send>() {}
+ const fn assert_sync<T: Sync + ?Sized>() {}
assert_send::<StyleEngine>();
+ assert_sync::<RetainedState>();
};
impl StyleEngine {
diff --git a/Libraries/LibWeb/Rust/src/css/style/facts_types.rs b/Libraries/LibWeb/Rust/src/css/style/facts_types.rs
deleted file mode 100644
index 1e866d98577..00000000000
--- a/Libraries/LibWeb/Rust/src/css/style/facts_types.rs
+++ /dev/null
@@ -1,275 +0,0 @@
-/*
- * Copyright (c) 2026-present, the Ladybird developers.
- *
- * SPDX-License-Identifier: BSD-2-Clause
- */
-
-//! Atom identities, local feature keys and values, and dispatch keys shared by every reader of
-//! style node facts.
-
-use super::input_types::StateFact;
-
-define_id! {
- /// Document-local identity of an interned selector-mentioned feature. Obeys the same generation
- /// and non-reuse rules as [`super::tree::StyleNodeID`].
- #[repr(transparent)]
- default pub struct StyleAtomID(pub);
-}
-
-impl StyleAtomID {
- /// Reserved: no atom. Document-local atoms start at 1.
- pub const NONE: Self = Self(0);
-
- #[must_use]
- pub fn is_none(self) -> bool {
- self == Self::NONE
- }
-
- /// The atoms a list of raw atom words holds, read in place.
- #[must_use]
- pub fn slice_of_raw(raw: &[u32]) -> &[Self] {
- // SAFETY: `StyleAtomID` is a transparent `u32`, and every `u32` is a valid one.
- unsafe { ak::slice_from_raw_parts(raw.as_ptr().cast(), raw.len()) }
- }
-}
-
-/// Which local fact of a style node is being described.
-///
-/// Attribute presence and attribute value share one key: changing an attribute changes both facts
-/// at once, and splitting them would let a consumer handle one and miss the other.
-#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
-pub enum LocalFeatureKey {
- /// The element's qualified name, as a single interned tag/namespace atom.
- TagName,
- /// The ASCII-lowercase folding of that name, recorded only when it differs from it. A type
- /// selector dispatches on its own folded form, so an element whose local name is not already
- /// lowercase has to be reachable under both.
- FoldedTagName,
- /// The element's ID.
- Id,
- /// Membership of one class.
- Class(StyleAtomID),
- /// Exposure of one shadow part.
- Part(StyleAtomID),
- /// Membership of one custom state, which `:state()` tests.
- CustomState(StyleAtomID),
- /// Whether the element has no children. A text node arriving changes it and connects no
- /// element, so it cannot be carried by a tree delta.
- Emptiness,
- /// Presence and value of one attribute, named by its interned attribute-name atom.
- Attribute(StyleAtomID),
- /// The element's resolved language tag. `:lang()` compares extended language ranges, which a
- /// single atom cannot express, so the fact is the whole tag and every `:lang()` rule hears any
- /// change to it. What that costs is bounded by how rare `:lang()` is; what it buys is that the
- /// region stays exactly the elements whose tag moved.
- Language,
- /// The element's resolved directionality, which `:dir()` tests.
- Directionality,
- /// The element's computed heading level, which `:heading()` tests.
- HeadingLevel,
- /// The outermost host from whose scope a `::part()` rule can address this element.
- ///
- /// A part name says nothing on its own about how far out it reaches: `exportparts` forwards it
- /// through a host under a name that is often the same one, so the names an element carries can
- /// stay exactly as they were while the scopes able to address it change. The value is compared
- /// only against its own previous value, never against anything a selector names.
- PartExposure,
-}
-
-/// The value of a local fact.
-#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
-pub enum FeatureValue {
- /// The fact does not hold: no such class, no such attribute, no ID.
- Absent,
- /// The fact holds, but its payload is not internable, so an exact test reads the live DOM
- /// after cheaper atom and name checks have already passed.
- Present,
- /// The fact holds and its payload is not the one it held before. Distinct from [`Self::Present`]
- /// so that a value change is a change: a delta reporting presence on both sides cancels, which
- /// is right for a fact nothing can distinguish and wrong for one that moved.
- ChangedValue,
- /// The fact holds with an interned value.
- Atom(StyleAtomID),
- /// The fact holds with a numeric value.
- Number(u32),
-}
-
-impl FeatureValue {
- #[must_use]
- pub fn holds(self) -> bool {
- !matches!(self, Self::Absent)
- }
-}
-
-/// Element or document states, packed one bit per fact. One word covers every boolean
-/// pseudo-class the parser can produce.
-#[derive(Clone, Copy, Debug, Default, Hash, PartialEq, Eq)]
-pub struct StateSet(pub u64);
-
-impl StateSet {
- /// The facts this set holds, for routing an element that announced them all at once.
- pub fn facts(self) -> impl Iterator<Item = StateFact> {
- let valid_bits = 1_u64
- .checked_shl(u32::try_from(StateFact::ALL.len()).expect("state fact count exceeds u32"))
- .map_or(u64::MAX, |limit| limit - 1);
- let mut bits = self.0 & valid_bits;
- std::iter::from_fn(move || {
- if bits == 0 {
- return None;
- }
- let index = bits.trailing_zeros() as usize;
- bits &= bits - 1;
- Some(StateFact::ALL[index])
- })
- }
-
- #[must_use]
- pub fn contains(self, fact: StateFact) -> bool {
- self.0 & (1_u64 << fact as u32) != 0
- }
-
- pub fn insert(&mut self, fact: StateFact) {
- self.0 |= 1_u64 << fact as u32;
- }
-
- pub fn remove(&mut self, fact: StateFact) {
- self.0 &= !(1_u64 << fact as u32);
- }
-}
-
-/// One attribute of one style node.
-///
-/// `value` is the interned value when the value was worth interning. Derived name forms and value
-/// text live once in the batch's shared atom catalog rather than once per element.
-#[derive(Clone, Copy, Debug, PartialEq, Eq)]
-#[repr(C)]
-pub struct AttributeFact {
- pub name: StyleAtomID,
- pub value: StyleAtomID,
-}
-
-const _: () = assert!(size_of::<AttributeFact>() == size_of::<[u32; 2]>());
-const _: () = assert!(align_of::<AttributeFact>() == align_of::<[u32; 2]>());
-
-impl AttributeFact {
- /// The attributes a list of raw (name, value) atom words holds, read in place.
- #[must_use]
- pub fn slice_of_raw(raw: &[[u32; 2]]) -> &[Self] {
- // SAFETY: `AttributeFact` is two `StyleAtomID`s, each a transparent `u32`, laid out as `[u32; 2]`, as the
- // asserts above check, and any two `u32`s make a valid one.
- unsafe { ak::slice_from_raw_parts(raw.as_ptr().cast(), raw.len()) }
- }
-}
-
-/// The other names one attribute-name atom answers to.
-#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
-pub struct AttributeNameForms {
- pub local: StyleAtomID,
- pub folded_name: StyleAtomID,
- pub folded_local: StyleAtomID,
-}
-
-/// One compact key for selector dispatch and relational arrival keys.
-///
-/// Every atom-bearing variant has the same `(kind: u8, atom: u32)` representation. Variants without
-/// an atom retain the distinctions needed by routing and dispatch without introducing another key
-/// vocabulary or a conversion between equal semantic features.
-#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
-#[repr(u8)]
-pub enum FeatureKey {
- Part(StyleAtomID),
- CustomState(StyleAtomID),
- TagName(StyleAtomID),
- Id(StyleAtomID),
- Class(StyleAtomID),
- AttributeName(StyleAtomID),
- Directionality(StyleAtomID),
- Root,
- State(StateFact),
- Heading,
- Universal,
- Structural,
- Language,
-}
-
-impl FeatureKey {
- pub(crate) fn atom(self) -> Option<StyleAtomID> {
- match self {
- Self::Part(atom)
- | Self::CustomState(atom)
- | Self::TagName(atom)
- | Self::Id(atom)
- | Self::Class(atom)
- | Self::AttributeName(atom)
- | Self::Directionality(atom) => Some(atom),
- Self::Root | Self::State(_) | Self::Heading | Self::Universal | Self::Structural | Self::Language => None,
- }
- }
-}
-
-/// The rightmost distinguishing feature of one selector entry.
-pub type DispatchKey = FeatureKey;
-
-/// One lossy bit for a dispatch key.
-///
-/// A Bloom summary is used only to reject a selector when a necessary key is definitely absent.
-/// Collisions admit extra exact evaluation and can never change a selector answer.
-#[must_use]
-pub fn dispatch_bloom_bit(key: DispatchKey) -> u64 {
- 1_u64 << (dispatch_key_hash(key) & 63)
-}
-
-/// One well-mixed hash of a dispatch key, which both Bloom summaries take their bit positions from.
-#[must_use]
-fn dispatch_key_hash(key: DispatchKey) -> u64 {
- let (kind, value) = match key {
- DispatchKey::Part(atom) => (1_u64, u64::from(atom.0)),
- DispatchKey::CustomState(atom) => (2, u64::from(atom.0)),
- DispatchKey::Id(atom) => (3, u64::from(atom.0)),
- DispatchKey::Class(atom) => (4, u64::from(atom.0)),
- DispatchKey::AttributeName(atom) => (5, u64::from(atom.0)),
- DispatchKey::TagName(atom) => (6, u64::from(atom.0)),
- DispatchKey::Directionality(atom) => (7, u64::from(atom.0)),
- DispatchKey::Root => (8, 0),
- DispatchKey::State(fact) => (9, fact as u64),
- DispatchKey::Heading => (10, 0),
- DispatchKey::Universal => (11, 0),
- _ => unreachable!("non-dispatch feature key"),
- };
- let mut hash = value ^ kind.wrapping_mul(0x9e37_79b9_7f4a_7c15);
- hash = (hash ^ (hash >> 30)).wrapping_mul(0xbf58_476d_1ce4_e5b9);
- hash = (hash ^ (hash >> 27)).wrapping_mul(0x94d0_49bb_1331_11eb);
- hash ^ (hash >> 31)
-}
-
-#[cfg(test)]
-mod tests {
- use super::*;
-
- #[test]
- fn states_pack_into_one_word() {
- let mut states = StateSet::default();
- states.insert(StateFact::Hover);
- states.insert(StateFact::Checked);
- assert!(states.contains(StateFact::Hover));
- assert!(states.contains(StateFact::Checked));
- assert!(!states.contains(StateFact::Focus));
- assert_eq!(
- states.facts().collect::<Vec<_>>(),
- vec![StateFact::Checked, StateFact::Hover]
- );
- states.remove(StateFact::Hover);
- assert!(!states.contains(StateFact::Hover));
- assert_eq!(size_of::<StateSet>(), 8);
- }
-
- #[test]
- fn attribute_facts_keep_only_their_name_and_value_atoms() {
- assert_eq!(size_of::<AttributeFact>(), 8);
- }
-
- #[test]
- fn selector_feature_keys_are_eight_bytes() {
- assert_eq!(size_of::<FeatureKey>(), 8);
- }
-}
diff --git a/Libraries/LibWeb/Rust/src/css/style/index.rs b/Libraries/LibWeb/Rust/src/css/style/index.rs
index 659e460ae47..1e866d98577 100644
--- a/Libraries/LibWeb/Rust/src/css/style/index.rs
+++ b/Libraries/LibWeb/Rust/src/css/style/index.rs
@@ -4,26 +4,272 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
-//! Style feature atoms and the local facts selector evaluation reads.
-//!
-//! An atom is a document-local `u32` standing for a tag/namespace pair, an ID, a class, an
-//! attribute name, an attribute value, a namespace, or a state fact. C++ assigns the identities
-//! because it owns the authoritative string payloads; Rust stores only the `u32` in bytecode,
-//! postings, and input keys, and never a duplicate of the string. Interning a name on the C++
-//! side is a hash lookup plus a reference count bump on a string that already exists, so a feature
-//! comparison costs an integer compare and no conversion.
-//!
-//! Index keys are therefore semantic facts rather than strings. Substring and token attribute
-//! operators drive from an attribute-name posting and run their exact value test in compound
-//! bytecode instead of demanding a posting per substring, which is why a feature key names the
-//! attribute and not the shape of the test applied to it. Only those tests need the value as text,
-//! and only for the attributes an attached program actually mentions.
-
-pub use super::facts_types::AttributeFact;
-pub use super::facts_types::AttributeNameForms;
-pub use super::facts_types::DispatchKey;
-pub use super::facts_types::FeatureValue;
-pub use super::facts_types::LocalFeatureKey;
-pub use super::facts_types::StateSet;
-pub use super::facts_types::StyleAtomID;
-pub use super::facts_types::dispatch_bloom_bit;
+//! Atom identities, local feature keys and values, and dispatch keys shared by every reader of
+//! style node facts.
+
+use super::input_types::StateFact;
+
+define_id! {
+ /// Document-local identity of an interned selector-mentioned feature. Obeys the same generation
+ /// and non-reuse rules as [`super::tree::StyleNodeID`].
+ #[repr(transparent)]
+ default pub struct StyleAtomID(pub);
+}
+
+impl StyleAtomID {
+ /// Reserved: no atom. Document-local atoms start at 1.
+ pub const NONE: Self = Self(0);
+
+ #[must_use]
+ pub fn is_none(self) -> bool {
+ self == Self::NONE
+ }
+
+ /// The atoms a list of raw atom words holds, read in place.
+ #[must_use]
+ pub fn slice_of_raw(raw: &[u32]) -> &[Self] {
+ // SAFETY: `StyleAtomID` is a transparent `u32`, and every `u32` is a valid one.
+ unsafe { ak::slice_from_raw_parts(raw.as_ptr().cast(), raw.len()) }
+ }
+}
+
+/// Which local fact of a style node is being described.
+///
+/// Attribute presence and attribute value share one key: changing an attribute changes both facts
+/// at once, and splitting them would let a consumer handle one and miss the other.
+#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
+pub enum LocalFeatureKey {
+ /// The element's qualified name, as a single interned tag/namespace atom.
+ TagName,
+ /// The ASCII-lowercase folding of that name, recorded only when it differs from it. A type
+ /// selector dispatches on its own folded form, so an element whose local name is not already
+ /// lowercase has to be reachable under both.
+ FoldedTagName,
+ /// The element's ID.
+ Id,
+ /// Membership of one class.
+ Class(StyleAtomID),
+ /// Exposure of one shadow part.
+ Part(StyleAtomID),
+ /// Membership of one custom state, which `:state()` tests.
+ CustomState(StyleAtomID),
+ /// Whether the element has no children. A text node arriving changes it and connects no
+ /// element, so it cannot be carried by a tree delta.
+ Emptiness,
+ /// Presence and value of one attribute, named by its interned attribute-name atom.
+ Attribute(StyleAtomID),
+ /// The element's resolved language tag. `:lang()` compares extended language ranges, which a
+ /// single atom cannot express, so the fact is the whole tag and every `:lang()` rule hears any
+ /// change to it. What that costs is bounded by how rare `:lang()` is; what it buys is that the
+ /// region stays exactly the elements whose tag moved.
+ Language,
+ /// The element's resolved directionality, which `:dir()` tests.
+ Directionality,
+ /// The element's computed heading level, which `:heading()` tests.
+ HeadingLevel,
+ /// The outermost host from whose scope a `::part()` rule can address this element.
+ ///
+ /// A part name says nothing on its own about how far out it reaches: `exportparts` forwards it
+ /// through a host under a name that is often the same one, so the names an element carries can
+ /// stay exactly as they were while the scopes able to address it change. The value is compared
+ /// only against its own previous value, never against anything a selector names.
+ PartExposure,
+}
+
+/// The value of a local fact.
+#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
+pub enum FeatureValue {
+ /// The fact does not hold: no such class, no such attribute, no ID.
+ Absent,
+ /// The fact holds, but its payload is not internable, so an exact test reads the live DOM
+ /// after cheaper atom and name checks have already passed.
+ Present,
+ /// The fact holds and its payload is not the one it held before. Distinct from [`Self::Present`]
+ /// so that a value change is a change: a delta reporting presence on both sides cancels, which
+ /// is right for a fact nothing can distinguish and wrong for one that moved.
+ ChangedValue,
+ /// The fact holds with an interned value.
+ Atom(StyleAtomID),
+ /// The fact holds with a numeric value.
+ Number(u32),
+}
+
+impl FeatureValue {
+ #[must_use]
+ pub fn holds(self) -> bool {
+ !matches!(self, Self::Absent)
+ }
+}
+
+/// Element or document states, packed one bit per fact. One word covers every boolean
+/// pseudo-class the parser can produce.
+#[derive(Clone, Copy, Debug, Default, Hash, PartialEq, Eq)]
+pub struct StateSet(pub u64);
+
+impl StateSet {
+ /// The facts this set holds, for routing an element that announced them all at once.
+ pub fn facts(self) -> impl Iterator<Item = StateFact> {
+ let valid_bits = 1_u64
+ .checked_shl(u32::try_from(StateFact::ALL.len()).expect("state fact count exceeds u32"))
+ .map_or(u64::MAX, |limit| limit - 1);
+ let mut bits = self.0 & valid_bits;
+ std::iter::from_fn(move || {
+ if bits == 0 {
+ return None;
+ }
+ let index = bits.trailing_zeros() as usize;
+ bits &= bits - 1;
+ Some(StateFact::ALL[index])
+ })
+ }
+
+ #[must_use]
+ pub fn contains(self, fact: StateFact) -> bool {
+ self.0 & (1_u64 << fact as u32) != 0
+ }
+
+ pub fn insert(&mut self, fact: StateFact) {
+ self.0 |= 1_u64 << fact as u32;
+ }
+
+ pub fn remove(&mut self, fact: StateFact) {
+ self.0 &= !(1_u64 << fact as u32);
+ }
+}
+
+/// One attribute of one style node.
+///
+/// `value` is the interned value when the value was worth interning. Derived name forms and value
+/// text live once in the batch's shared atom catalog rather than once per element.
+#[derive(Clone, Copy, Debug, PartialEq, Eq)]
+#[repr(C)]
+pub struct AttributeFact {
+ pub name: StyleAtomID,
+ pub value: StyleAtomID,
+}
+
+const _: () = assert!(size_of::<AttributeFact>() == size_of::<[u32; 2]>());
+const _: () = assert!(align_of::<AttributeFact>() == align_of::<[u32; 2]>());
+
+impl AttributeFact {
+ /// The attributes a list of raw (name, value) atom words holds, read in place.
+ #[must_use]
+ pub fn slice_of_raw(raw: &[[u32; 2]]) -> &[Self] {
+ // SAFETY: `AttributeFact` is two `StyleAtomID`s, each a transparent `u32`, laid out as `[u32; 2]`, as the
+ // asserts above check, and any two `u32`s make a valid one.
+ unsafe { ak::slice_from_raw_parts(raw.as_ptr().cast(), raw.len()) }
+ }
+}
+
+/// The other names one attribute-name atom answers to.
+#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
+pub struct AttributeNameForms {
+ pub local: StyleAtomID,
+ pub folded_name: StyleAtomID,
+ pub folded_local: StyleAtomID,
+}
+
+/// One compact key for selector dispatch and relational arrival keys.
+///
+/// Every atom-bearing variant has the same `(kind: u8, atom: u32)` representation. Variants without
+/// an atom retain the distinctions needed by routing and dispatch without introducing another key
+/// vocabulary or a conversion between equal semantic features.
+#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
+#[repr(u8)]
+pub enum FeatureKey {
+ Part(StyleAtomID),
+ CustomState(StyleAtomID),
+ TagName(StyleAtomID),
+ Id(StyleAtomID),
+ Class(StyleAtomID),
+ AttributeName(StyleAtomID),
+ Directionality(StyleAtomID),
+ Root,
+ State(StateFact),
+ Heading,
+ Universal,
+ Structural,
+ Language,
+}
+
+impl FeatureKey {
+ pub(crate) fn atom(self) -> Option<StyleAtomID> {
+ match self {
+ Self::Part(atom)
+ | Self::CustomState(atom)
+ | Self::TagName(atom)
+ | Self::Id(atom)
+ | Self::Class(atom)
+ | Self::AttributeName(atom)
+ | Self::Directionality(atom) => Some(atom),
+ Self::Root | Self::State(_) | Self::Heading | Self::Universal | Self::Structural | Self::Language => None,
+ }
+ }
+}
+
+/// The rightmost distinguishing feature of one selector entry.
+pub type DispatchKey = FeatureKey;
+
+/// One lossy bit for a dispatch key.
+///
+/// A Bloom summary is used only to reject a selector when a necessary key is definitely absent.
+/// Collisions admit extra exact evaluation and can never change a selector answer.
+#[must_use]
+pub fn dispatch_bloom_bit(key: DispatchKey) -> u64 {
+ 1_u64 << (dispatch_key_hash(key) & 63)
+}
+
+/// One well-mixed hash of a dispatch key, which both Bloom summaries take their bit positions from.
+#[must_use]
+fn dispatch_key_hash(key: DispatchKey) -> u64 {
+ let (kind, value) = match key {
+ DispatchKey::Part(atom) => (1_u64, u64::from(atom.0)),
+ DispatchKey::CustomState(atom) => (2, u64::from(atom.0)),
+ DispatchKey::Id(atom) => (3, u64::from(atom.0)),
+ DispatchKey::Class(atom) => (4, u64::from(atom.0)),
+ DispatchKey::AttributeName(atom) => (5, u64::from(atom.0)),
+ DispatchKey::TagName(atom) => (6, u64::from(atom.0)),
+ DispatchKey::Directionality(atom) => (7, u64::from(atom.0)),
+ DispatchKey::Root => (8, 0),
+ DispatchKey::State(fact) => (9, fact as u64),
+ DispatchKey::Heading => (10, 0),
+ DispatchKey::Universal => (11, 0),
+ _ => unreachable!("non-dispatch feature key"),
+ };
+ let mut hash = value ^ kind.wrapping_mul(0x9e37_79b9_7f4a_7c15);
+ hash = (hash ^ (hash >> 30)).wrapping_mul(0xbf58_476d_1ce4_e5b9);
+ hash = (hash ^ (hash >> 27)).wrapping_mul(0x94d0_49bb_1331_11eb);
+ hash ^ (hash >> 31)
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ #[test]
+ fn states_pack_into_one_word() {
+ let mut states = StateSet::default();
+ states.insert(StateFact::Hover);
+ states.insert(StateFact::Checked);
+ assert!(states.contains(StateFact::Hover));
+ assert!(states.contains(StateFact::Checked));
+ assert!(!states.contains(StateFact::Focus));
+ assert_eq!(
+ states.facts().collect::<Vec<_>>(),
+ vec![StateFact::Checked, StateFact::Hover]
+ );
+ states.remove(StateFact::Hover);
+ assert!(!states.contains(StateFact::Hover));
+ assert_eq!(size_of::<StateSet>(), 8);
+ }
+
+ #[test]
+ fn attribute_facts_keep_only_their_name_and_value_atoms() {
+ assert_eq!(size_of::<AttributeFact>(), 8);
+ }
+
+ #[test]
+ fn selector_feature_keys_are_eight_bytes() {
+ assert_eq!(size_of::<FeatureKey>(), 8);
+ }
+}
diff --git a/Libraries/LibWeb/Rust/src/css/style/input_types.rs b/Libraries/LibWeb/Rust/src/css/style/input_types.rs
index 68390f9c7cb..16c88cadb21 100644
--- a/Libraries/LibWeb/Rust/src/css/style/input_types.rs
+++ b/Libraries/LibWeb/Rust/src/css/style/input_types.rs
@@ -21,6 +21,13 @@ use super::pipeline::rule_store::DeclarationBlockID;
use super::tree::StyleNodeID;
use super::tree::TreeScopeID;
+/// The sides of a transaction that its readers compare.
+#[derive(Clone, Copy, PartialEq, Eq)]
+pub(super) enum TransactionFactSide {
+ Before,
+ After,
+}
+
// -- Typed semantic inputs -------------------------------------------------------------------
// An element or document state fact.
diff --git a/Libraries/LibWeb/Rust/src/css/style/mod.rs b/Libraries/LibWeb/Rust/src/css/style/mod.rs
index fb1f4eb1105..9b159f6074c 100644
--- a/Libraries/LibWeb/Rust/src/css/style/mod.rs
+++ b/Libraries/LibWeb/Rust/src/css/style/mod.rs
@@ -72,7 +72,6 @@ pub mod engine_calls;
pub(crate) mod engine_sample;
#[cfg(test)]
pub mod exact_matcher;
-mod facts_types;
pub(crate) mod host_atoms;
pub(crate) mod style_job;
pub(crate) use crate::fast_hash;
@@ -112,10 +111,8 @@ pub(crate) use process_style::ProcessStyle;
pub(crate) use publication::RecordDemand;
pub(crate) use transition_baselines::{InheritedAnimatedValue, TransitionBaselines};
pub mod input_types;
-pub mod relative_selector;
pub mod selector;
pub mod selector_evaluation;
-mod shareable;
mod size_container_invalidation;
mod specified_value;
@@ -124,7 +121,6 @@ pub(crate) fn value_reads_attributes(value: &crate::css::style_value::StyleValue
custom_property_cascade::unresolved_reading_attributes(value).is_some()
}
-mod transaction_view;
pub mod tree;
mod weak_pool;
@@ -187,6 +183,7 @@ use input_types::InputValue;
use input_types::PendingElementInputs;
use input_types::StateFact;
use input_types::StyleUpdate;
+use input_types::TransactionFactSide;
use input_types::TreeRelations;
use pipeline::rule_store::CascadeLayerID;
use pipeline::rule_store::CustomDeclaration;
@@ -202,7 +199,6 @@ use pipeline::rule_store::StyleScopeID;
use selector::Incomplete;
use selector::MatchScratch;
use selector::Specificity;
-use transaction_view::TransactionFactSide;
use tree::HostTree;
use tree::SegmentedNodeColumn;
use tree::StyleNodeID;
diff --git a/Libraries/LibWeb/Rust/src/css/style/pipeline/invalidation.rs b/Libraries/LibWeb/Rust/src/css/style/pipeline/invalidation.rs
index 8c719de0e21..15919cee0b3 100644
--- a/Libraries/LibWeb/Rust/src/css/style/pipeline/invalidation.rs
+++ b/Libraries/LibWeb/Rust/src/css/style/pipeline/invalidation.rs
@@ -1441,7 +1441,7 @@ impl RelativeEntry {
in_shadow_tree: bool,
names: &mut AcquiredNames,
) -> Self {
- use super::super::relative_selector::RelativeAxis;
+ use super::super::selector::RelativeAxis;
let axis = match argument.is_relative_anchor() {
true => RelativeAxis::Descendant,
false => relative_axis(argument).0,
diff --git a/Libraries/LibWeb/Rust/src/css/style/pipeline/live.rs b/Libraries/LibWeb/Rust/src/css/style/pipeline/live.rs
index 93ee5f95449..a4e3f6ad15e 100644
--- a/Libraries/LibWeb/Rust/src/css/style/pipeline/live.rs
+++ b/Libraries/LibWeb/Rust/src/css/style/pipeline/live.rs
@@ -10,12 +10,12 @@
use super::super::component_matching::DocumentMatching;
use super::super::index::dispatch_bloom_bit;
+use super::super::input_types::TransactionFactSide;
use super::super::input_types::{
STYLE_REACTION_FONT_INPUTS_CHANGED, STYLE_REACTION_PUBLISHED_STYLE, STYLE_REACTION_RECOMPUTE_DESCENDANT_STYLES,
StyleEnvironment, StyleUpdate, TreeRelations,
};
use super::super::selector_evaluation::StructuralRead;
-use super::super::transaction_view::TransactionFactSide;
use super::super::*;
use super::drive::DriveRecords;
use super::invalidation::{
diff --git a/Libraries/LibWeb/Rust/src/css/style/pipeline/matching.rs b/Libraries/LibWeb/Rust/src/css/style/pipeline/matching.rs
index 69a0fc34895..454809cce73 100644
--- a/Libraries/LibWeb/Rust/src/css/style/pipeline/matching.rs
+++ b/Libraries/LibWeb/Rust/src/css/style/pipeline/matching.rs
@@ -8,8 +8,8 @@
//! reject those whose required ancestor keys the filter lacks, and evaluate the rest.
use super::super::component_matching::EntrySelector;
+use super::super::input_types::TransactionFactSide;
use super::super::selector_evaluation::StructuralRead;
-use super::super::transaction_view::TransactionFactSide;
use super::super::*;
use super::bloom::{AncestorFilter, SiblingFilter};
use super::projection::{ElementFacts, Projection, ProjectionEvaluator};
diff --git a/Libraries/LibWeb/Rust/src/css/style/pipeline/projection.rs b/Libraries/LibWeb/Rust/src/css/style/pipeline/projection.rs
index 6b87e9f6d20..5753d444e52 100644
--- a/Libraries/LibWeb/Rust/src/css/style/pipeline/projection.rs
+++ b/Libraries/LibWeb/Rust/src/css/style/pipeline/projection.rs
@@ -45,6 +45,7 @@ use super::super::index::StateSet;
use super::super::index::StyleAtomID;
use super::super::index::dispatch_bloom_bit;
use super::super::input_types::StateFact;
+use super::super::input_types::TransactionFactSide;
use super::super::input_types::TreeRelations;
use super::super::selector::Incomplete;
use super::super::selector::MatchScratch;
@@ -60,7 +61,6 @@ use super::super::selector_evaluation::SelectorEvaluator;
use super::super::selector_evaluation::SelectorSubject;
use super::super::selector_evaluation::SelectorTree;
use super::super::selector_evaluation::StructuralRead;
-use super::super::transaction_view::TransactionFactSide;
use super::super::tree::StyleNodeID;
use super::super::tree::TreeScopeID;
use crate::cow_column::ColumnSnapshot;
diff --git a/Libraries/LibWeb/Rust/src/css/style/pipeline/records.rs b/Libraries/LibWeb/Rust/src/css/style/pipeline/records.rs
index aca52692643..b65e6f5cf9b 100644
--- a/Libraries/LibWeb/Rust/src/css/style/pipeline/records.rs
+++ b/Libraries/LibWeb/Rust/src/css/style/pipeline/records.rs
@@ -10,8 +10,8 @@
use super::super::animations::DeclarationScope;
use super::super::container_queries::{ContainerRecords, ContainerVerdict};
+use super::super::input_types::TransactionFactSide;
use super::super::selector_evaluation::StructuralRead;
-use super::super::transaction_view::TransactionFactSide;
use super::super::*;
use super::drive::DriveRecords;
use super::traversal::InitialStyle;
diff --git a/Libraries/LibWeb/Rust/src/css/style/relative_selector.rs b/Libraries/LibWeb/Rust/src/css/style/relative_selector.rs
deleted file mode 100644
index f149e10203c..00000000000
--- a/Libraries/LibWeb/Rust/src/css/style/relative_selector.rs
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * Copyright (c) 2026-present, the Ladybird developers.
- *
- * SPDX-License-Identifier: BSD-2-Clause
- */
-
-//! Relational selector query descriptors and the candidate witnesses along their axes.
-//!
-//! A relative selector matches a witness along one axis from an anchor, and matching enumerates
-//! the candidates along that axis.
-
-/// The single axis a simple relative selector traverses from its anchor.
-#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
-pub enum RelativeAxis {
- /// `:has(.error)`
- Descendant,
- /// `:has(> .item)`
- Child,
- /// `:has(+ .selected)`
- NextSibling,
- /// `:has(~ .selected)`
- FollowingSibling,
- /// `:has(+ .row .cell)`: the witness is somewhere under the anchor's next sibling.
- NextSiblingSubtree,
- /// `:has(~ .row .cell)`: the witness is somewhere under one of the following siblings.
- FollowingSiblingSubtree,
-}
diff --git a/Libraries/LibWeb/Rust/src/css/style/selector.rs b/Libraries/LibWeb/Rust/src/css/style/selector.rs
index e8cde671d87..bda49b1e830 100644
--- a/Libraries/LibWeb/Rust/src/css/style/selector.rs
+++ b/Libraries/LibWeb/Rust/src/css/style/selector.rs
@@ -30,7 +30,22 @@ pub struct NthPosition {
pub of_type: bool,
}
-// -- Relational arrival keys -------------------------------------------------------------------
+/// The single axis a simple relative selector traverses from its anchor.
+#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
+pub enum RelativeAxis {
+ /// `:has(.error)`
+ Descendant,
+ /// `:has(> .item)`
+ Child,
+ /// `:has(+ .selected)`
+ NextSibling,
+ /// `:has(~ .selected)`
+ FollowingSibling,
+ /// `:has(+ .row .cell)`: the witness is somewhere under the anchor's next sibling.
+ NextSiblingSubtree,
+ /// `:has(~ .row .cell)`: the witness is somewhere under one of the following siblings.
+ FollowingSiblingSubtree,
+}
/// Why a match evaluation could not produce an exact answer.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
diff --git a/Libraries/LibWeb/Rust/src/css/style/selector_evaluation.rs b/Libraries/LibWeb/Rust/src/css/style/selector_evaluation.rs
index 4281ac73b01..b28bb49b6d8 100644
--- a/Libraries/LibWeb/Rust/src/css/style/selector_evaluation.rs
+++ b/Libraries/LibWeb/Rust/src/css/style/selector_evaluation.rs
@@ -18,8 +18,8 @@ use smallvec::SmallVec;
use super::index::StyleAtomID;
use super::input_types::StateFact;
-use super::relative_selector::RelativeAxis;
use super::selector::NthPosition;
+use super::selector::RelativeAxis;
use super::tree::StyleNodeID;
use crate::css::css_tokenizer::TokenizerInput;
diff --git a/Libraries/LibWeb/Rust/src/css/style/shareable.rs b/Libraries/LibWeb/Rust/src/css/style/shareable.rs
deleted file mode 100644
index 2ea56c5ec56..00000000000
--- a/Libraries/LibWeb/Rust/src/css/style/shareable.rs
+++ /dev/null
@@ -1,20 +0,0 @@
-/*
- * Copyright (c) 2026-present, the Ladybird developers.
- *
- * SPDX-License-Identifier: BSD-2-Clause
- */
-
-//! What an evaluation step may read, written down as compile-time witnesses.
-//!
-//! An evaluation step borrows the engine's retained state and the update's committed answers, and
-//! writes only this flush's scratch. For many workers to run the same step over one read side,
-//! everything the step reads has to be shareable across threads and the per-worker scratch has to
-//! be movable to one. None of this is a runtime check: a type that stops being shareable stops
-//! compiling.
-
-use super::*;
-
-const _: () = {
- const fn assert_sync<T: Sync + ?Sized>() {}
- assert_sync::<RetainedState>();
-};
diff --git a/Libraries/LibWeb/Rust/src/css/style/transaction_view.rs b/Libraries/LibWeb/Rust/src/css/style/transaction_view.rs
deleted file mode 100644
index f42ee4e9abf..00000000000
--- a/Libraries/LibWeb/Rust/src/css/style/transaction_view.rs
+++ /dev/null
@@ -1,13 +0,0 @@
-/*
- * Copyright (c) 2026-present, the Ladybird developers.
- *
- * SPDX-License-Identifier: BSD-2-Clause
- */
-
-//! The sides of a transaction that its readers compare.
-
-#[derive(Clone, Copy, PartialEq, Eq)]
-pub(super) enum TransactionFactSide {
- Before,
- After,
-}