From 86f02173a4b3a518aeff0826fa0373e9ee8d3b20 Mon Sep 17 00:00:00 2001 From: Martin Robinson Date: Thu, 21 Nov 2024 17:46:16 +0000 Subject: [PATCH] Bug 1932588 - Remove as much Gecko-specific and Servo-specific code as possible from `malloc_size_of` r=emilio Servo is going to maintain a fork of `malloc_size_of` internally so that Stylo does not need to have an implicit dependency on all of the crates that need an implementation of `MallocSizeOf`. In order to prepare for this, implementations that are only used in Servo should be removed (unless they are used in Stylo itself). In addition, we can remove some Gecko-specific implementations as well in order to make downstream Stylo a bit cleaner. Differential Revision: https://phabricator.services.mozilla.com/D229764 --- Cargo.lock | 2 +- dom/base/rust/Cargo.toml | 1 + dom/base/rust/lib.rs | 3 + servo/components/malloc_size_of/Cargo.toml | 33 +---- servo/components/malloc_size_of/lib.rs | 163 --------------------- servo/components/style/Cargo.toml | 2 +- 6 files changed, 9 insertions(+), 195 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 46f46abbc329..fa27cc1a2354 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1607,6 +1607,7 @@ name = "dom" version = "0.1.0" dependencies = [ "bitflags 2.6.0", + "malloc_size_of", ] [[package]] @@ -3733,7 +3734,6 @@ version = "0.0.1" dependencies = [ "app_units", "cssparser", - "dom", "euclid", "selectors", "servo_arc", diff --git a/dom/base/rust/Cargo.toml b/dom/base/rust/Cargo.toml index 38828c3f0f8e..a03eca1c3414 100644 --- a/dom/base/rust/Cargo.toml +++ b/dom/base/rust/Cargo.toml @@ -12,3 +12,4 @@ path = "lib.rs" [dependencies] bitflags = "2" +malloc_size_of = { path = "../../../servo/components/malloc_size_of" } diff --git a/dom/base/rust/lib.rs b/dom/base/rust/lib.rs index 228d77f12963..134fbe99d052 100644 --- a/dom/base/rust/lib.rs +++ b/dom/base/rust/lib.rs @@ -5,6 +5,7 @@ //! DOM types to be shared between Rust and C++. use bitflags::bitflags; +use malloc_size_of::malloc_size_of_is_0; bitflags! { /// Event-based element states. @@ -163,3 +164,5 @@ bitflags! { const ALL_LOCALEDIR_BITS = Self::LTR_LOCALE.bits() | Self::RTL_LOCALE.bits(); } } + +malloc_size_of_is_0!(ElementState, DocumentState); diff --git a/servo/components/malloc_size_of/Cargo.toml b/servo/components/malloc_size_of/Cargo.toml index e9dca7ce5913..eefd6cd89a6e 100644 --- a/servo/components/malloc_size_of/Cargo.toml +++ b/servo/components/malloc_size_of/Cargo.toml @@ -10,44 +10,17 @@ publish = false path = "lib.rs" [features] -servo = [ - "accountable-refcell", - "content-security-policy", - "crossbeam-channel", - "http", - "indexmap", - "keyboard-types", - "serde", - "serde_bytes", - "string_cache", - "url", - "uuid", - "webrender_api", - "xml5ever", -] -gecko = [] +gecko = ["thin-vec/gecko-ffi"] +servo = ["string_cache"] [dependencies] -accountable-refcell = { version = "0.2.0", optional = true } app_units = "0.7" -content-security-policy = { version = "0.4.0", features = ["serde"], optional = true } -crossbeam-channel = { version = "0.4", optional = true } cssparser = "0.34" -dom = { path = "../../../dom/base/rust" } euclid = "0.22" -http = { version = "0.2", optional = true } -indexmap = { version = "2.2", optional = true } -keyboard-types = { version = "0.4.3", optional = true } selectors = { path = "../selectors" } -serde = { version = "1.0.27", optional = true } -serde_bytes = { version = "0.11", optional = true } servo_arc = { path = "../servo_arc" } smallbitvec = "2.3.0" smallvec = "1.0" string_cache = { version = "0.8", optional = true } -thin-vec = { version = "0.2.1", features = ["gecko-ffi"] } -url = { version = "2.4", optional = true } -uuid = { version = "0.8", features = ["v4"], optional = true } +thin-vec = { version = "0.2.1" } void = "1.0.2" -webrender_api = { git = "https://github.com/servo/webrender", optional = true } -xml5ever = { version = "0.16", optional = true } diff --git a/servo/components/malloc_size_of/lib.rs b/servo/components/malloc_size_of/lib.rs index d23f9e33ef5f..b17c0756830d 100644 --- a/servo/components/malloc_size_of/lib.rs +++ b/servo/components/malloc_size_of/lib.rs @@ -46,50 +46,20 @@ //! Note: WebRender has a reduced fork of this crate, so that we can avoid //! publishing this crate on crates.io. -#[cfg(feature = "servo")] -extern crate accountable_refcell; extern crate app_units; -#[cfg(feature = "servo")] -extern crate content_security_policy; -#[cfg(feature = "servo")] -extern crate crossbeam_channel; extern crate cssparser; extern crate euclid; -#[cfg(feature = "servo")] -extern crate http; -#[cfg(feature = "servo")] -extern crate keyboard_types; extern crate selectors; -#[cfg(feature = "servo")] -extern crate serde; -#[cfg(feature = "servo")] -extern crate serde_bytes; extern crate servo_arc; extern crate smallbitvec; extern crate smallvec; -#[cfg(feature = "servo")] -extern crate string_cache; -#[cfg(feature = "url")] -extern crate url; -#[cfg(feature = "servo")] -extern crate uuid; extern crate void; -#[cfg(feature = "webrender_api")] -extern crate webrender_api; -#[cfg(feature = "servo")] -extern crate xml5ever; -#[cfg(feature = "servo")] -use content_security_policy as csp; -#[cfg(feature = "servo")] -use serde_bytes::ByteBuf; use std::hash::{BuildHasher, Hash}; use std::mem::size_of; use std::ops::Range; use std::ops::{Deref, DerefMut}; use std::os::raw::c_void; -#[cfg(feature = "servo")] -use uuid::Uuid; use void::Void; /// A C function that takes a pointer to a heap allocation and returns its size. @@ -338,24 +308,6 @@ impl MallocSizeOf for [T] { } } -#[cfg(feature = "servo")] -impl MallocShallowSizeOf for ByteBuf { - fn shallow_size_of(&self, ops: &mut MallocSizeOfOps) -> usize { - unsafe { ops.malloc_size_of(self.as_ptr()) } - } -} - -#[cfg(feature = "servo")] -impl MallocSizeOf for ByteBuf { - fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize { - let mut n = self.shallow_size_of(ops); - for elem in self.iter() { - n += elem.size_of(ops); - } - n - } -} - impl MallocShallowSizeOf for Vec { fn shallow_size_of(&self, ops: &mut MallocSizeOfOps) -> usize { unsafe { ops.malloc_size_of(self.as_ptr()) } @@ -863,116 +815,8 @@ malloc_size_of_is_0!(app_units::Au); malloc_size_of_is_0!(cssparser::TokenSerializationType, cssparser::SourceLocation, cssparser::SourcePosition); -#[cfg(feature = "gecko")] -malloc_size_of_is_0!(dom::ElementState, dom::DocumentState); - malloc_size_of_is_0!(selectors::OpaqueElement); -#[cfg(feature = "servo")] -malloc_size_of_is_0!(csp::Destination); - -#[cfg(feature = "servo")] -malloc_size_of_is_0!(Uuid); - -#[cfg(feature = "url")] -impl MallocSizeOf for url::Host { - fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize { - match *self { - url::Host::Domain(ref s) => s.size_of(ops), - _ => 0, - } - } -} -#[cfg(feature = "webrender_api")] -malloc_size_of_is_0!(webrender_api::BorderRadius); -#[cfg(feature = "webrender_api")] -malloc_size_of_is_0!(webrender_api::BorderStyle); -#[cfg(feature = "webrender_api")] -malloc_size_of_is_0!(webrender_api::BoxShadowClipMode); -#[cfg(feature = "webrender_api")] -malloc_size_of_is_0!(webrender_api::ColorF); -#[cfg(feature = "webrender_api")] -malloc_size_of_is_0!(webrender_api::ComplexClipRegion); -#[cfg(feature = "webrender_api")] -malloc_size_of_is_0!(webrender_api::ExtendMode); -#[cfg(feature = "webrender_api")] -malloc_size_of_is_0!(webrender_api::FilterOp); -#[cfg(feature = "webrender_api")] -malloc_size_of_is_0!(webrender_api::ExternalScrollId); -#[cfg(feature = "webrender_api")] -malloc_size_of_is_0!(webrender_api::FontInstanceKey); -#[cfg(feature = "webrender_api")] -malloc_size_of_is_0!(webrender_api::GradientStop); -#[cfg(feature = "webrender_api")] -malloc_size_of_is_0!(webrender_api::GlyphInstance); -#[cfg(feature = "webrender_api")] -malloc_size_of_is_0!(webrender_api::NinePatchBorder); -#[cfg(feature = "webrender_api")] -malloc_size_of_is_0!(webrender_api::ImageKey); -#[cfg(feature = "webrender_api")] -malloc_size_of_is_0!(webrender_api::ImageRendering); -#[cfg(feature = "webrender_api")] -malloc_size_of_is_0!(webrender_api::LineStyle); -#[cfg(feature = "webrender_api")] -malloc_size_of_is_0!(webrender_api::MixBlendMode); -#[cfg(feature = "webrender_api")] -malloc_size_of_is_0!(webrender_api::NormalBorder); -#[cfg(feature = "webrender_api")] -malloc_size_of_is_0!(webrender_api::RepeatMode); -#[cfg(feature = "webrender_api")] -malloc_size_of_is_0!(webrender_api::StickyOffsetBounds); -#[cfg(feature = "webrender_api")] -malloc_size_of_is_0!(webrender_api::TransformStyle); - -#[cfg(feature = "servo")] -impl MallocSizeOf for keyboard_types::Key { - fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize { - match self { - keyboard_types::Key::Character(ref s) => s.size_of(ops), - _ => 0, - } - } -} - -#[cfg(feature = "servo")] -malloc_size_of_is_0!(keyboard_types::Modifiers); - -#[cfg(feature = "servo")] -impl MallocSizeOf for xml5ever::QualName { - fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize { - self.prefix.size_of(ops) + self.ns.size_of(ops) + self.local.size_of(ops) - } -} - -#[cfg(feature = "servo")] -malloc_size_of_is_0!(std::time::Duration); -#[cfg(feature = "servo")] -malloc_size_of_is_0!(std::time::SystemTime); -#[cfg(feature = "servo")] -malloc_size_of_is_0!(std::time::Instant); -#[cfg(feature = "servo")] -malloc_size_of_hash_set!(indexmap::IndexSet); -#[cfg(feature = "servo")] -malloc_size_of_hash_map!(indexmap::IndexMap); -#[cfg(feature = "servo")] -malloc_size_of_is_0!(http::StatusCode); - -// Placeholder for unique case where internals of Sender cannot be measured. -// malloc size of is 0 macro complains about type supplied! -#[cfg(feature = "servo")] -impl MallocSizeOf for crossbeam_channel::Sender { - fn size_of(&self, _ops: &mut MallocSizeOfOps) -> usize { - 0 - } -} - -#[cfg(feature = "servo")] -impl MallocSizeOf for tokio::sync::mpsc::UnboundedSender { - fn size_of(&self, _ops: &mut MallocSizeOfOps) -> usize { - 0 - } -} - /// Measurable that defers to inner value and used to verify MallocSizeOf implementation in a /// struct. #[derive(Clone)] @@ -991,10 +835,3 @@ impl DerefMut for Measurable { &mut self.0 } } - -#[cfg(feature = "servo")] -impl MallocSizeOf for accountable_refcell::RefCell { - fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize { - self.borrow().size_of(ops) - } -} diff --git a/servo/components/style/Cargo.toml b/servo/components/style/Cargo.toml index 7b5db7b3e805..58de5ba26aa6 100644 --- a/servo/components/style/Cargo.toml +++ b/servo/components/style/Cargo.toml @@ -100,7 +100,7 @@ uluru = "3.0" unicode-bidi = { version = "0.3", default-features = false } void = "1.0.2" gecko-profiler = { path = "../../../tools/profiler/rust-api" } -url = { version = "2.5", optional = true } +url = { version = "2.5", optional = true, features = ["serde"] } [build-dependencies] lazy_static = "1"