Skip to content

Truly independent web browser

LibWeb: Remove the dependencies of declaration blocks

Aliaksandr Kalenikb272bf6f08c0
diff --git a/Libraries/LibWeb/CSS/RustDeclarationBlock.cpp b/Libraries/LibWeb/CSS/RustDeclarationBlock.cpp
index b96d046ea26..581f8a5ebcf 100644
--- a/Libraries/LibWeb/CSS/RustDeclarationBlock.cpp
+++ b/Libraries/LibWeb/CSS/RustDeclarationBlock.cpp
@@ -54,11 +54,6 @@ RustDeclarationBlockSnapshot& RustDeclarationBlockSnapshot::operator=(RustDeclar
return *this;
}
-FfiDeclarationBlockDependencies RustDeclarationBlockSnapshot::dependencies() const
-{
- return rust_declaration_data_dependencies(m_data);
-}
-
RustDeclarationBlock::RustDeclarationBlock(Vector<StyleProperty> properties, OrderedHashMap<Utf16FlyString, StyleProperty> custom_properties)
: m_properties(move(properties))
, m_custom_properties(move(custom_properties))
@@ -181,11 +176,6 @@ OrderedHashMap<Utf16FlyString, StyleProperty> const& RustDeclarationBlock::custo
return m_custom_properties;
}
-FfiDeclarationBlockDependencies RustDeclarationBlock::dependencies() const
-{
- return rust_declaration_block_dependencies(m_block);
-}
-
size_t RustDeclarationBlock::external_memory_size() const
{
auto size = rust_declaration_block_external_memory_size(m_block);
diff --git a/Libraries/LibWeb/CSS/RustDeclarationBlock.h b/Libraries/LibWeb/CSS/RustDeclarationBlock.h
index d26141f865a..614021fe94d 100644
--- a/Libraries/LibWeb/CSS/RustDeclarationBlock.h
+++ b/Libraries/LibWeb/CSS/RustDeclarationBlock.h
@@ -23,7 +23,6 @@ public:
RustDeclarationBlockSnapshot(RustDeclarationBlockSnapshot&&);
RustDeclarationBlockSnapshot& operator=(RustDeclarationBlockSnapshot&&);
- Parser::ValueParserFFI::FfiDeclarationBlockDependencies dependencies() const;
Parser::ValueParserFFI::DeclarationBlockData const* data() const { return m_data; }
private:
@@ -55,7 +54,6 @@ public:
Vector<StyleProperty> const& properties() const;
OrderedHashMap<Utf16FlyString, StyleProperty> const& custom_properties() const;
size_t external_memory_size() const;
- Parser::ValueParserFFI::FfiDeclarationBlockDependencies dependencies() const;
bool set(PropertyID, StyleValue const&, Important);
void append(PropertyID, StyleValue const&, Important);
diff --git a/Libraries/LibWeb/Rust/src/css/declaration_block.rs b/Libraries/LibWeb/Rust/src/css/declaration_block.rs
index 1287a6b1c38..d4d571d5803 100644
--- a/Libraries/LibWeb/Rust/src/css/declaration_block.rs
+++ b/Libraries/LibWeb/Rust/src/css/declaration_block.rs
@@ -35,88 +35,12 @@ pub struct DeclarationBlockData {
custom_property_references: std::sync::OnceLock<(Vec<Vec<u16>>, bool)>,
}
-/// Facts used by style-sharing keys, read directly from the immutable declaration storage.
-#[derive(Debug, Default, PartialEq, Eq)]
-#[repr(C)]
-pub struct FfiDeclarationBlockDependencies {
- pub has_custom_properties: bool,
- pub has_unresolved_values: bool,
- pub has_custom_functions: bool,
- pub inherits_custom_properties_explicitly: bool,
- pub reads_style_scope: bool,
- pub declares_animation_name: bool,
-}
-
const _: () = {
const fn assert_send_sync<T: Send + Sync>() {}
assert_send_sync::<DeclarationBlockData>();
};
impl DeclarationBlockData {
- fn dependencies(&self) -> FfiDeclarationBlockDependencies {
- use crate::css::property_metadata::property_id;
- let mut dependencies = FfiDeclarationBlockDependencies {
- has_custom_properties: !self.custom_properties.is_empty(),
- ..Default::default()
- };
- for property in &self.properties {
- let unresolved = matches!(&*property.value, StyleValueData::Unresolved { .. });
- dependencies.has_unresolved_values |= unresolved;
- dependencies.inherits_custom_properties_explicitly |= matches!(
- &*property.value,
- StyleValueData::Unresolved {
- presence_inherit: true,
- ..
- }
- );
- dependencies.has_custom_functions |= matches!(
- &*property.value,
- StyleValueData::Unresolved {
- presence_dashed_function: true,
- ..
- }
- );
- dependencies.reads_style_scope |= unresolved
- || matches!(
- property.property_id,
- property_id::CONTENT | property_id::LIST_STYLE_TYPE
- );
- dependencies.declares_animation_name |= property.property_id == property_id::ANIMATION_NAME;
- }
- for custom_property in &self.custom_properties {
- // NB: Substitution can produce an inherit keyword, which reads even non-inheriting
- // registered properties from the full parent environment.
- dependencies.inherits_custom_properties_explicitly |= match &*custom_property.declaration.value {
- StyleValueData::Unresolved {
- presence_attr,
- presence_dashed_function,
- presence_env,
- presence_if,
- presence_inherit,
- presence_var,
- ..
- } => {
- *presence_attr
- || *presence_dashed_function
- || *presence_env
- || *presence_if
- || *presence_inherit
- || *presence_var
- }
- StyleValueData::Keyword { keyword } => *keyword == crate::css::style_compute::keyword::INHERIT,
- _ => false,
- };
- dependencies.has_custom_functions |= matches!(
- &*custom_property.declaration.value,
- StyleValueData::Unresolved {
- presence_dashed_function: true,
- ..
- }
- );
- }
- dependencies
- }
-
pub(crate) fn external_memory_size(&self) -> usize {
let mut size = size_of::<Self>()
.saturating_add(self.properties.capacity().saturating_mul(size_of::<DeclaredProperty>()))
@@ -510,19 +434,6 @@ pub extern "C" fn rust_declaration_data_release(data: OwnedArc<DeclarationBlockD
drop(data);
}
-#[unsafe(no_mangle)]
-pub extern "C" fn rust_declaration_data_dependencies(data: &DeclarationBlockData) -> FfiDeclarationBlockDependencies {
- data.dependencies()
-}
-
-#[unsafe(no_mangle)]
-pub extern "C" fn rust_declaration_block_dependencies(block: &DeclarationBlock) -> FfiDeclarationBlockDependencies {
- match &*block.state.borrow() {
- DeclarationBlockState::Immutable(data) => data.dependencies(),
- DeclarationBlockState::Mutable(owner) => owner.borrow().data.dependencies(),
- }
-}
-
/// Visit borrowed declaration values without materializing mutable owners or FFI arrays.
#[unsafe(no_mangle)]
pub extern "C" fn rust_declaration_data_visit(
@@ -666,37 +577,6 @@ mod tests {
assert_eq!(snapshot.custom_properties.len(), 1);
}
- #[test]
- fn dependency_reads_follow_mutation_without_changing_shared_snapshots() {
- let data = parsed_declarations("width: var(--幅); animation-name: movement; --幅: 13px");
- let original = DeclarationBlock::new(data.clone());
- let mut fork = unsafe { Box::from_raw(rust_declaration_block_share(&original)) };
- let expected = rust_declaration_data_dependencies(&data);
- assert!(rust_declaration_block_remove(&mut fork, property_id::WIDTH));
- assert!(rust_declaration_block_remove(&mut fork, property_id::ANIMATION_NAME));
- let mut retained = unsafe { Box::from_raw(rust_declaration_block_retain(&fork)) };
- let owners = DECLARATION_OWNER_ALLOCATIONS.with(|count| count.get());
- assert_eq!(
- rust_declaration_block_dependencies(&retained),
- FfiDeclarationBlockDependencies {
- has_custom_properties: true,
- ..Default::default()
- }
- );
- let name: Vec<_> = "--幅".encode_utf16().collect();
- assert!(rust_declaration_block_remove_custom(
- &mut retained,
- FfiUtf16View::from_utf16(&name),
- ));
- assert_eq!(
- rust_declaration_block_dependencies(&fork),
- FfiDeclarationBlockDependencies::default()
- );
- assert_eq!(rust_declaration_block_dependencies(&original), expected);
- assert_eq!(rust_declaration_data_dependencies(&data), expected);
- assert_eq!(DECLARATION_OWNER_ALLOCATIONS.with(|count| count.get()), owners);
- }
-
#[test]
fn native_nested_declarations_promote_only_for_live_handles_or_edits() {
let units: Vec<_> = ".親 { .子 {} width: 13px; --幅: 19px; }".encode_utf16().collect();