mirror of
https://github.com/servo/servo.git
synced 2025-08-05 13:40:08 +01:00
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
This commit is contained in:
parent
5f75d29aac
commit
9a7e8006e1
4 changed files with 35 additions and 4 deletions
7
Cargo.lock
generated
7
Cargo.lock
generated
|
@ -6042,6 +6042,12 @@ version = "1.1.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "dba1a27d3efae4351c8051072d619e3ade2820635c3958d826bfea39d59b54c8"
|
checksum = "dba1a27d3efae4351c8051072d619e3ade2820635c3958d826bfea39d59b54c8"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "static_assertions"
|
||||||
|
version = "1.1.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "std_test_override"
|
name = "std_test_override"
|
||||||
version = "0.0.1"
|
version = "0.0.1"
|
||||||
|
@ -6145,6 +6151,7 @@ dependencies = [
|
||||||
"servo_url",
|
"servo_url",
|
||||||
"smallbitvec",
|
"smallbitvec",
|
||||||
"smallvec",
|
"smallvec",
|
||||||
|
"static_assertions",
|
||||||
"string_cache",
|
"string_cache",
|
||||||
"style_derive",
|
"style_derive",
|
||||||
"style_traits",
|
"style_traits",
|
||||||
|
|
|
@ -62,6 +62,7 @@ servo_config = { path = "../config", optional = true }
|
||||||
servo_url = { path = "../url", optional = true }
|
servo_url = { path = "../url", optional = true }
|
||||||
smallbitvec = "2.3.0"
|
smallbitvec = "2.3.0"
|
||||||
smallvec = "1.0"
|
smallvec = "1.0"
|
||||||
|
static_assertions = "1.1"
|
||||||
string_cache = { version = "0.8", optional = true }
|
string_cache = { version = "0.8", optional = true }
|
||||||
style_derive = { path = "../style_derive" }
|
style_derive = { path = "../style_derive" }
|
||||||
style_traits = { path = "../style_traits" }
|
style_traits = { path = "../style_traits" }
|
||||||
|
|
|
@ -63,6 +63,8 @@ pub use servo_arc;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate servo_atoms;
|
extern crate servo_atoms;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
|
extern crate static_assertions;
|
||||||
|
#[macro_use]
|
||||||
extern crate style_derive;
|
extern crate style_derive;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate to_shmem_derive;
|
extern crate to_shmem_derive;
|
||||||
|
@ -186,7 +188,7 @@ pub mod gecko_properties {
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! reexport_computed_values {
|
macro_rules! reexport_computed_values {
|
||||||
( $( { $name: ident, $boxed: expr } )+ ) => {
|
( $( { $name: ident } )+ ) => {
|
||||||
/// Types for [computed values][computed].
|
/// Types for [computed values][computed].
|
||||||
///
|
///
|
||||||
/// [computed]: https://drafts.csswg.org/css-cascade/#computed
|
/// [computed]: https://drafts.csswg.org/css-cascade/#computed
|
||||||
|
@ -200,7 +202,6 @@ macro_rules! reexport_computed_values {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
longhand_properties_idents!(reexport_computed_values);
|
longhand_properties_idents!(reexport_computed_values);
|
||||||
|
|
||||||
#[cfg(feature = "gecko")]
|
#[cfg(feature = "gecko")]
|
||||||
use crate::gecko_string_cache::WeakAtom;
|
use crate::gecko_string_cache::WeakAtom;
|
||||||
#[cfg(feature = "servo")]
|
#[cfg(feature = "servo")]
|
||||||
|
|
|
@ -4218,7 +4218,7 @@ macro_rules! css_properties_accessors {
|
||||||
/// Call the given macro with tokens like this for each longhand properties:
|
/// 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
|
/// … where the boolean indicates whether the property value type
|
||||||
|
@ -4228,12 +4228,34 @@ macro_rules! longhand_properties_idents {
|
||||||
($macro_name: ident) => {
|
($macro_name: ident) => {
|
||||||
$macro_name! {
|
$macro_name! {
|
||||||
% for property in data.longhands:
|
% for property in data.longhands:
|
||||||
{ ${property.ident}, ${"true" if property.boxed else "false"} }
|
{ ${property.ident} }
|
||||||
% endfor
|
% 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":
|
% if engine == "servo":
|
||||||
% for effect_name in ["repaint", "reflow_out_of_flow", "reflow", "rebuild_and_reflow_inline", "rebuild_and_reflow"]:
|
% for effect_name in ["repaint", "reflow_out_of_flow", "reflow", "rebuild_and_reflow_inline", "rebuild_and_reflow"]:
|
||||||
macro_rules! restyle_damage_${effect_name} {
|
macro_rules! restyle_damage_${effect_name} {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue