diff --git a/Cargo.lock b/Cargo.lock index de5b3a7724b..32926a86a2c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5372,6 +5372,7 @@ dependencies = [ "phf_codegen", "precomputed-hash", "servo_arc", + "size_of_test", "smallvec", "to_shmem", "to_shmem_derive", @@ -5915,6 +5916,9 @@ checksum = "fa8f3741c7372e75519bd9346068370c9cdaabcc1f9599cbcf2a2719352286b7" [[package]] name = "size_of_test" version = "0.0.1" +dependencies = [ + "static_assertions", +] [[package]] name = "slab" @@ -6193,7 +6197,6 @@ dependencies = [ "servo_atoms", "servo_config", "servo_url", - "size_of_test", "std_test_override", "style", "style_traits", @@ -6215,6 +6218,7 @@ dependencies = [ "servo_arc", "servo_atoms", "servo_url", + "size_of_test", "to_shmem", "to_shmem_derive", "webrender_api", diff --git a/components/layout/Cargo.toml b/components/layout/Cargo.toml index d11f508c502..fe501517c6e 100644 --- a/components/layout/Cargo.toml +++ b/components/layout/Cargo.toml @@ -44,6 +44,7 @@ servo_atoms = { path = "../atoms" } servo_config = { path = "../config" } servo_geometry = { path = "../geometry" } servo_url = { path = "../url" } +size_of_test = { path = "../size_of_test" } smallvec = { workspace = true, features = ["union"] } style = { path = "../style", features = ["servo"] } style_traits = { path = "../style_traits" } @@ -52,6 +53,3 @@ unicode-script = { workspace = true } webrender_api = { workspace = true } xi-unicode = { workspace = true } -[dev-dependencies] -size_of_test = { path = "../size_of_test" } - diff --git a/components/layout/fragment.rs b/components/layout/fragment.rs index 5cf56b6cbdf..7f36e110499 100644 --- a/components/layout/fragment.rs +++ b/components/layout/fragment.rs @@ -158,6 +158,11 @@ pub struct Fragment { pub established_reference_frame: Option, } +#[cfg(debug_assertions)] +size_of_test!(Fragment, 176); +#[cfg(not(debug_assertions))] +size_of_test!(Fragment, 152); + impl Serialize for Fragment { fn serialize(&self, serializer: S) -> Result { let mut serializer = serializer.serialize_struct("fragment", 3)?; @@ -212,6 +217,8 @@ pub enum SpecificFragmentInfo { TruncatedFragment(Box), } +size_of_test!(SpecificFragmentInfo, 24); + impl SpecificFragmentInfo { fn restyle_damage(&self) -> RestyleDamage { let flow = match *self { diff --git a/components/layout/lib.rs b/components/layout/lib.rs index 3f41157c1cd..aab98048a54 100644 --- a/components/layout/lib.rs +++ b/components/layout/lib.rs @@ -16,6 +16,8 @@ extern crate log; extern crate range; #[macro_use] extern crate serde; +#[macro_use] +extern crate size_of_test; #[macro_use] pub mod layout_debug; diff --git a/components/layout/tests/size_of.rs b/components/layout/tests/size_of.rs deleted file mode 100644 index dec10937177..00000000000 --- a/components/layout/tests/size_of.rs +++ /dev/null @@ -1,21 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ - -#![cfg(target_pointer_width = "64")] - -#[macro_use] -extern crate size_of_test; - -use layout_2013::Fragment; -use layout_2013::SpecificFragmentInfo; - -#[cfg(debug_assertions)] -size_of_test!(test_size_of_fragment, Fragment, 176); -#[cfg(not(debug_assertions))] -size_of_test!(test_size_of_fragment, Fragment, 152); -size_of_test!( - test_size_of_specific_fragment_info, - SpecificFragmentInfo, - 24 -); diff --git a/components/msg/Cargo.toml b/components/msg/Cargo.toml index 8bcf5680a2d..49dfb7232bd 100644 --- a/components/msg/Cargo.toml +++ b/components/msg/Cargo.toml @@ -19,7 +19,5 @@ malloc_size_of = { path = "../malloc_size_of" } malloc_size_of_derive = { workspace = true } parking_lot = { workspace = true } serde = { workspace = true } -webrender_api = { workspace = true } - -[dev-dependencies] size_of_test = { path = "../size_of_test" } +webrender_api = { workspace = true } diff --git a/components/msg/constellation_msg.rs b/components/msg/constellation_msg.rs index 72223cdb387..3dcff217485 100644 --- a/components/msg/constellation_msg.rs +++ b/components/msg/constellation_msg.rs @@ -198,6 +198,9 @@ pub struct PipelineNamespaceId(pub u32); namespace_id! {PipelineId, PipelineIndex} +size_of_test!(PipelineId, 8); +size_of_test!(Option, 8); + impl PipelineId { pub fn new() -> PipelineId { PIPELINE_NAMESPACE.with(|tls| { @@ -240,6 +243,9 @@ impl fmt::Display for PipelineId { namespace_id! {BrowsingContextId, BrowsingContextIndex} +size_of_test!(BrowsingContextId, 8); +size_of_test!(Option, 8); + impl BrowsingContextId { pub fn new() -> BrowsingContextId { PIPELINE_NAMESPACE.with(|tls| { @@ -269,6 +275,9 @@ thread_local!(pub static TOP_LEVEL_BROWSING_CONTEXT_ID: Cell, 8); + impl TopLevelBrowsingContextId { pub fn new() -> TopLevelBrowsingContextId { TopLevelBrowsingContextId(BrowsingContextId::new()) diff --git a/components/msg/lib.rs b/components/msg/lib.rs index 4fe53230c46..03aa40eb8f1 100644 --- a/components/msg/lib.rs +++ b/components/msg/lib.rs @@ -12,5 +12,7 @@ extern crate malloc_size_of; extern crate malloc_size_of_derive; #[macro_use] extern crate serde; +#[macro_use] +extern crate size_of_test; pub mod constellation_msg; diff --git a/components/msg/tests/size_of.rs b/components/msg/tests/size_of.rs deleted file mode 100644 index 4fc1861ea31..00000000000 --- a/components/msg/tests/size_of.rs +++ /dev/null @@ -1,31 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ - -#![cfg(target_pointer_width = "64")] - -#[macro_use] -extern crate size_of_test; - -use msg::constellation_msg::BrowsingContextId; -use msg::constellation_msg::PipelineId; -use msg::constellation_msg::TopLevelBrowsingContextId; - -size_of_test!(test_size_of_pipeline_id, PipelineId, 8); -size_of_test!(test_size_of_optional_pipeline_id, Option, 8); -size_of_test!(test_size_of_browsing_context_id, BrowsingContextId, 8); -size_of_test!( - test_size_of_optional_browsing_context_id, - Option, - 8 -); -size_of_test!( - test_size_of_top_level_browsing_context_id, - TopLevelBrowsingContextId, - 8 -); -size_of_test!( - test_size_of_top_level_optional_browsing_context_id, - Option, - 8 -); diff --git a/components/selectors/Cargo.toml b/components/selectors/Cargo.toml index 2a91f50c636..880c4db0c61 100644 --- a/components/selectors/Cargo.toml +++ b/components/selectors/Cargo.toml @@ -28,6 +28,7 @@ log = "0.4" phf = "0.10" precomputed-hash = "0.1" servo_arc = { version = "0.2", path = "../servo_arc" } +size_of_test = { path = "../size_of_test" } smallvec = "1.0" to_shmem = { version = "0.0.0", path = "../to_shmem", optional = true } to_shmem_derive = { version = "0.0.0", path = "../to_shmem_derive", optional = true } diff --git a/components/selectors/lib.rs b/components/selectors/lib.rs index 17f81c535b6..2b785a8cd65 100644 --- a/components/selectors/lib.rs +++ b/components/selectors/lib.rs @@ -5,6 +5,9 @@ // Make |cargo bench| work. #![cfg_attr(feature = "bench", feature(test))] +#[macro_use] +extern crate size_of_test; + pub mod attr; pub mod bloom; mod builder; diff --git a/components/selectors/parser.rs b/components/selectors/parser.rs index c6650102616..cf342fc8ea8 100644 --- a/components/selectors/parser.rs +++ b/components/selectors/parser.rs @@ -160,6 +160,8 @@ impl SelectorParsingState { pub type SelectorParseError<'i> = ParseError<'i, SelectorParseErrorKind<'i>>; +size_of_test!(SelectorParseError, 48); + #[derive(Clone, Debug, PartialEq)] pub enum SelectorParseErrorKind<'i> { NoQualifiedNameInAttributeSelector(Token<'i>), @@ -184,6 +186,8 @@ pub enum SelectorParseErrorKind<'i> { ClassNeedsIdent(Token<'i>), } +size_of_test!(SelectorParseErrorKind, 40); + macro_rules! with_all_bounds { ( [ $( $InSelector: tt )* ] diff --git a/components/size_of_test/Cargo.toml b/components/size_of_test/Cargo.toml new file mode 100644 index 00000000000..faea55c5c1c --- /dev/null +++ b/components/size_of_test/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name = "size_of_test" +version = "0.0.1" +authors = ["The Servo Project Developers"] +license = "MPL-2.0" +edition = "2018" +publish = false + +[lib] +path = "lib.rs" + +[dependencies] +static_assertions = "1.1" diff --git a/components/size_of_test/lib.rs b/components/size_of_test/lib.rs new file mode 100644 index 00000000000..18e45175e8c --- /dev/null +++ b/components/size_of_test/lib.rs @@ -0,0 +1,14 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ + +pub use static_assertions::const_assert_eq; + +/// Asserts the size of a type at compile time. +#[macro_export] +macro_rules! size_of_test { + ($t: ty, $expected_size: expr) => { + #[cfg(target_pointer_width = "64")] + $crate::const_assert_eq!(std::mem::size_of::<$t>(), $expected_size); + }; +} diff --git a/components/style/invalidation/element/invalidation_map.rs b/components/style/invalidation/element/invalidation_map.rs index 0bba423a17f..f083225b4b7 100644 --- a/components/style/invalidation/element/invalidation_map.rs +++ b/components/style/invalidation/element/invalidation_map.rs @@ -67,6 +67,8 @@ pub struct Dependency { pub parent: Option>, } +size_of_test!(Dependency, 24); + /// The kind of elements down the tree this dependency may affect. #[derive(Debug, Eq, PartialEq)] pub enum DependencyInvalidationKind { diff --git a/components/style/properties/properties.mako.rs b/components/style/properties/properties.mako.rs index 1bc210fd6ff..09602f5a529 100644 --- a/components/style/properties/properties.mako.rs +++ b/components/style/properties/properties.mako.rs @@ -2609,7 +2609,7 @@ pub struct SourcePropertyDeclaration { // This is huge, but we allocate it on the stack and then never move it, // we only pass `&mut SourcePropertyDeclaration` references around. -size_of_test!(SourcePropertyDeclaration, 600); +size_of_test!(SourcePropertyDeclaration, 568); impl SourcePropertyDeclaration { /// Create one. It’s big, try not to move it around. @@ -4242,7 +4242,7 @@ macro_rules! longhand_properties_idents { } // Large pages generate tens of thousands of ComputedValues. -size_of_test!(ComputedValues, 232); +size_of_test!(ComputedValues, 192); // FFI relies on this. size_of_test!(Option>, 8); diff --git a/components/style/values/computed/image.rs b/components/style/values/computed/image.rs index c12cbd1a2a6..5f650631c89 100644 --- a/components/style/values/computed/image.rs +++ b/components/style/values/computed/image.rs @@ -32,7 +32,7 @@ pub type Image = generic::GenericImage; // Images should remain small, see https://github.com/servo/servo/pull/18430 -size_of_test!(Image, 16); +size_of_test!(Image, 40); /// Computed values for a CSS gradient. /// diff --git a/components/style/values/specified/image.rs b/components/style/values/specified/image.rs index 12dd5afdf86..d8dd3cd40db 100644 --- a/components/style/values/specified/image.rs +++ b/components/style/values/specified/image.rs @@ -40,7 +40,7 @@ pub type Image = generic::Image; // Images should remain small, see https://github.com/servo/servo/pull/18430 -size_of_test!(Image, 16); +size_of_test!(Image, 40); /// Specified values for a CSS gradient. /// diff --git a/components/style_traits/Cargo.toml b/components/style_traits/Cargo.toml index 779bb5487b5..8a135354cf8 100644 --- a/components/style_traits/Cargo.toml +++ b/components/style_traits/Cargo.toml @@ -27,6 +27,7 @@ serde = "1.0" servo_arc = { path = "../servo_arc" } servo_atoms = { path = "../atoms", optional = true } servo_url = { path = "../url", optional = true } +size_of_test = { path = "../size_of_test" } to_shmem = { path = "../to_shmem" } to_shmem_derive = { path = "../to_shmem_derive" } webrender_api = { workspace = true, optional = true } diff --git a/components/style_traits/lib.rs b/components/style_traits/lib.rs index 28260272d66..d7c7d8ad33d 100644 --- a/components/style_traits/lib.rs +++ b/components/style_traits/lib.rs @@ -10,6 +10,9 @@ #![crate_type = "rlib"] #![deny(unsafe_code, missing_docs)] +#[macro_use] +extern crate size_of_test; + use bitflags::bitflags; use malloc_size_of_derive::MallocSizeOf; use serde::{Deserialize, Serialize}; @@ -81,9 +84,11 @@ pub use crate::values::{ /// The error type for all CSS parsing routines. pub type ParseError<'i> = cssparser::ParseError<'i, StyleParseErrorKind<'i>>; +size_of_test!(ParseError, 64); /// Error in property value parsing pub type ValueParseError<'i> = cssparser::ParseError<'i, ValueParseErrorKind<'i>>; +size_of_test!(ValueParseError, 48); #[derive(Clone, Debug, PartialEq)] /// Errors that can be encountered while parsing CSS values. @@ -148,6 +153,7 @@ pub enum StyleParseErrorKind<'i> { /// The property is not allowed within a page rule. NotAllowedInPageRule, } +size_of_test!(StyleParseErrorKind, 56); impl<'i> From> for StyleParseErrorKind<'i> { fn from(this: ValueParseErrorKind<'i>) -> Self { @@ -169,6 +175,7 @@ pub enum ValueParseErrorKind<'i> { /// An invalid filter value was encountered. InvalidFilter(Token<'i>), } +size_of_test!(ValueParseErrorKind, 40); impl<'i> StyleParseErrorKind<'i> { /// Create an InvalidValue parse error diff --git a/tests/unit/style/Cargo.toml b/tests/unit/style/Cargo.toml index c9f17dcf973..38439c1f280 100644 --- a/tests/unit/style/Cargo.toml +++ b/tests/unit/style/Cargo.toml @@ -21,7 +21,6 @@ servo_arc = {path = "../../../components/servo_arc"} servo_atoms = {path = "../../../components/atoms"} servo_config = {path = "../../../components/config"} servo_url = {path = "../../../components/url"} -size_of_test = {path = "../../../components/size_of_test"} style = {path = "../../../components/style", features = ["servo"]} style_traits = {path = "../../../components/style_traits"} std_test_override = { path = "../../../components/std_test_override" } diff --git a/tests/unit/style/lib.rs b/tests/unit/style/lib.rs index 110e2e8ed6d..3ccb818dfcb 100644 --- a/tests/unit/style/lib.rs +++ b/tests/unit/style/lib.rs @@ -16,7 +16,6 @@ extern crate serde_json; extern crate servo_arc; extern crate servo_atoms; extern crate servo_url; -#[macro_use] extern crate style; extern crate style_traits; extern crate test; @@ -28,7 +27,6 @@ mod logical_geometry; mod parsing; mod properties; mod rule_tree; -mod size_of; mod str; mod stylesheets; mod stylist; diff --git a/tests/unit/style/size_of.rs b/tests/unit/style/size_of.rs deleted file mode 100644 index cb64495141b..00000000000 --- a/tests/unit/style/size_of.rs +++ /dev/null @@ -1,51 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ - -use selectors::parser::{SelectorParseError, SelectorParseErrorKind}; -use style::invalidation::element::invalidation_map::Dependency; -use style::properties; - -size_of_test!(test_size_of_dependency, Dependency, 24); - -size_of_test!( - test_size_of_property_declaration, - properties::PropertyDeclaration, - 32 -); - -// This is huge, but we allocate it on the stack and then never move it, -// we only pass `&mut SourcePropertyDeclaration` references around. -size_of_test!( - test_size_of_parsed_declaration, - properties::SourcePropertyDeclaration, - 568 -); - -size_of_test!( - test_size_of_selector_parse_error_kind, - SelectorParseErrorKind, - 40 -); -size_of_test!( - test_size_of_style_parse_error_kind, - ::style_traits::StyleParseErrorKind, - 56 -); -size_of_test!( - test_size_of_value_parse_error_kind, - ::style_traits::ValueParseErrorKind, - 40 -); - -size_of_test!(test_size_of_selector_parse_error, SelectorParseError, 48); -size_of_test!( - test_size_of_style_traits_parse_error, - ::style_traits::ParseError, - 64 -); -size_of_test!( - test_size_of_value_parse_error, - ::style_traits::ValueParseError, - 48 -);