diff options
author | Emilio Cobos Álvarez <emilio@crisal.io> | 2023-08-14 21:56:49 +0200 |
---|---|---|
committer | Martin Robinson <mrobinson@igalia.com> | 2023-08-16 17:46:41 +0200 |
commit | 9a7e8006e11491d2908b6c7c2bd82bf8d9d23294 (patch) | |
tree | 8b5c007e0693fe443cac5a812ecf4562991cc03d | |
parent | 5f75d29aac5f6889af58e7a0769bea8842c58771 (diff) | |
download | servo-9a7e8006e11491d2908b6c7c2bd82bf8d9d23294.tar.gz servo-9a7e8006e11491d2908b6c7c2bd82bf8d9d23294.zip |
style: Convert specified value tests to compile-time tests
These were written at a time where std::mem::size_of wasn't a `const fn` in
Rust.
Now that it is, we can make these tests live in the style crate, and the build
not to compile if they fail.
Differential Revision: https://phabricator.services.mozilla.com/D146103
-rw-r--r-- | Cargo.lock | 7 | ||||
-rw-r--r-- | components/style/Cargo.toml | 1 | ||||
-rw-r--r-- | components/style/lib.rs | 5 | ||||
-rw-r--r-- | components/style/properties/properties.mako.rs | 26 |
4 files changed, 35 insertions, 4 deletions
diff --git a/Cargo.lock b/Cargo.lock index dd4158caf11..de5b3a7724b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6043,6 +6043,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dba1a27d3efae4351c8051072d619e3ade2820635c3958d826bfea39d59b54c8" [[package]] +name = "static_assertions" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" + +[[package]] name = "std_test_override" version = "0.0.1" dependencies = [ @@ -6145,6 +6151,7 @@ dependencies = [ "servo_url", "smallbitvec", "smallvec", + "static_assertions", "string_cache", "style_derive", "style_traits", diff --git a/components/style/Cargo.toml b/components/style/Cargo.toml index 6c5196d93f8..2fb75c2fbad 100644 --- a/components/style/Cargo.toml +++ b/components/style/Cargo.toml @@ -62,6 +62,7 @@ servo_config = { path = "../config", optional = true } servo_url = { path = "../url", optional = true } smallbitvec = "2.3.0" smallvec = "1.0" +static_assertions = "1.1" string_cache = { version = "0.8", optional = true } style_derive = { path = "../style_derive" } style_traits = { path = "../style_traits" } diff --git a/components/style/lib.rs b/components/style/lib.rs index f4f0a2792b6..b1cec716fcf 100644 --- a/components/style/lib.rs +++ b/components/style/lib.rs @@ -63,6 +63,8 @@ pub use servo_arc; #[macro_use] extern crate servo_atoms; #[macro_use] +extern crate static_assertions; +#[macro_use] extern crate style_derive; #[macro_use] extern crate to_shmem_derive; @@ -186,7 +188,7 @@ pub mod gecko_properties { } macro_rules! reexport_computed_values { - ( $( { $name: ident, $boxed: expr } )+ ) => { + ( $( { $name: ident } )+ ) => { /// Types for [computed values][computed]. /// /// [computed]: https://drafts.csswg.org/css-cascade/#computed @@ -200,7 +202,6 @@ macro_rules! reexport_computed_values { } } longhand_properties_idents!(reexport_computed_values); - #[cfg(feature = "gecko")] use crate::gecko_string_cache::WeakAtom; #[cfg(feature = "servo")] diff --git a/components/style/properties/properties.mako.rs b/components/style/properties/properties.mako.rs index ff6146ed0d6..979d6718226 100644 --- a/components/style/properties/properties.mako.rs +++ b/components/style/properties/properties.mako.rs @@ -4218,7 +4218,7 @@ macro_rules! css_properties_accessors { /// Call the given macro with tokens like this for each longhand properties: /// /// ``` -/// { snake_case_ident, true } +/// { snake_case_ident } /// ``` /// /// … where the boolean indicates whether the property value type @@ -4228,12 +4228,34 @@ macro_rules! longhand_properties_idents { ($macro_name: ident) => { $macro_name! { % for property in data.longhands: - { ${property.ident}, ${"true" if property.boxed else "false"} } + { ${property.ident} } % endfor } } } +// There are two reasons for this test to fail: +// +// * Your changes made a specified value type for a given property go +// over the threshold. In that case, you should try to shrink it again +// or, if not possible, mark the property as boxed in the property +// definition. +// +// * Your changes made a specified value type smaller, so that it no +// longer needs to be boxed. In this case you just need to remove +// boxed=True from the property definition. Nice job! +#[cfg(target_pointer_width = "64")] +#[allow(dead_code)] // https://github.com/rust-lang/rust/issues/96952 +const BOX_THRESHOLD: usize = 24; +% for longhand in data.longhands: +#[cfg(target_pointer_width = "64")] +% if longhand.boxed: +const_assert!(std::mem::size_of::<longhands::${longhand.ident}::SpecifiedValue>() > BOX_THRESHOLD); +% else: +const_assert!(std::mem::size_of::<longhands::${longhand.ident}::SpecifiedValue>() <= BOX_THRESHOLD); +% endif +% endfor + % if engine == "servo": % for effect_name in ["repaint", "reflow_out_of_flow", "reflow", "rebuild_and_reflow_inline", "rebuild_and_reflow"]: macro_rules! restyle_damage_${effect_name} { |