From e962ac365b73b7abd47345494bd4e9b113773faf Mon Sep 17 00:00:00 2001 From: Nathan Froyd Date: Fri, 4 Aug 2017 08:03:56 -0400 Subject: [PATCH 1/3] export boxedness of types from longhand_properties_idents The only piece of information about longhand SpecifiedValue types that we don't have outside of the properties module is whether the types are boxed or not. Provide that information in the longhand_properties_idents macro so we can move test_size_of_specified_values outside of the properties module. --- components/style/lib.rs | 2 +- components/style/properties/properties.mako.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/components/style/lib.rs b/components/style/lib.rs index b82d2fd3cc0..e1453706977 100644 --- a/components/style/lib.rs +++ b/components/style/lib.rs @@ -171,7 +171,7 @@ pub mod gecko_properties { } macro_rules! reexport_computed_values { - ( $( $name: ident )+ ) => { + ( $( { $name: ident, $boxed: expr } )+ ) => { /// Types for [computed values][computed]. /// /// [computed]: https://drafts.csswg.org/css-cascade/#computed diff --git a/components/style/properties/properties.mako.rs b/components/style/properties/properties.mako.rs index 0e11d2ac0ad..d6c6faf964d 100644 --- a/components/style/properties/properties.mako.rs +++ b/components/style/properties/properties.mako.rs @@ -3419,7 +3419,7 @@ macro_rules! longhand_properties_idents { ($macro_name: ident) => { $macro_name! { % for property in data.longhands: - ${property.ident} + { ${property.ident}, ${"true" if property.boxed else "false"} } % endfor } } From 018968877a696c03774f49b702e70f37665ed910 Mon Sep 17 00:00:00 2001 From: Nathan Froyd Date: Fri, 4 Aug 2017 08:34:36 -0400 Subject: [PATCH 2/3] move specified values size testing entirely into stylo_tests This change means that stylo_tests doesn't depend on a version of the style crate with the `testing` feature defined. --- .../style/properties/properties.mako.rs | 38 +------------- tests/unit/style/lib.rs | 4 +- tests/unit/style/size_of.rs | 5 -- tests/unit/stylo/lib.rs | 1 + tests/unit/stylo/size_of.rs | 5 -- tests/unit/stylo/specified_values.rs | 49 +++++++++++++++++++ 6 files changed, 54 insertions(+), 48 deletions(-) create mode 100644 tests/unit/stylo/specified_values.rs diff --git a/components/style/properties/properties.mako.rs b/components/style/properties/properties.mako.rs index d6c6faf964d..f8e4cd9e327 100644 --- a/components/style/properties/properties.mako.rs +++ b/components/style/properties/properties.mako.rs @@ -3414,7 +3414,7 @@ macro_rules! css_properties_accessors { } } - +#[macro_export] macro_rules! longhand_properties_idents { ($macro_name: ident) => { $macro_name! { @@ -3424,39 +3424,3 @@ macro_rules! longhand_properties_idents { } } } - -/// Testing function to check the size of all SpecifiedValues. -#[cfg(feature = "testing")] -pub fn test_size_of_specified_values() { - use std::mem::size_of; - let threshold = 24; - - let mut longhands = vec![]; - % for property in data.longhands: - longhands.push(("${property.name}", - size_of::(), - ${"true" if property.boxed else "false"})); - % endfor - - let mut failing_messages = vec![]; - - for specified_value in longhands { - if specified_value.1 > threshold && !specified_value.2 { - failing_messages.push( - format!("Your changes have increased the size of {} SpecifiedValue to {}. The threshold is \ - currently {}. SpecifiedValues affect size of PropertyDeclaration enum and \ - increasing the size may negative affect style system performance. Please consider \ - using `boxed=\"True\"` in this longhand.", - specified_value.0, specified_value.1, threshold)); - } else if specified_value.1 <= threshold && specified_value.2 { - failing_messages.push( - format!("Your changes have decreased the size of {} SpecifiedValue to {}. Good work! \ - The threshold is currently {}. Please consider removing `boxed=\"True\"` from this longhand.", - specified_value.0, specified_value.1, threshold)); - } - } - - if !failing_messages.is_empty() { - panic!("{}", failing_messages.join("\n\n")); - } -} diff --git a/tests/unit/style/lib.rs b/tests/unit/style/lib.rs index 0647a59251f..572a608d212 100644 --- a/tests/unit/style/lib.rs +++ b/tests/unit/style/lib.rs @@ -19,7 +19,7 @@ extern crate servo_atoms; extern crate servo_config; extern crate servo_url; #[macro_use] extern crate size_of_test; -extern crate style; +#[macro_use] extern crate style; extern crate style_traits; extern crate test; @@ -32,6 +32,8 @@ mod parsing; mod properties; mod rule_tree; mod size_of; +#[path = "../stylo/specified_values.rs"] +mod specified_values; mod str; mod stylesheets; mod stylist; diff --git a/tests/unit/style/size_of.rs b/tests/unit/style/size_of.rs index 486fecf4e25..3f15a8d24e4 100644 --- a/tests/unit/style/size_of.rs +++ b/tests/unit/style/size_of.rs @@ -12,8 +12,3 @@ size_of_test!(test_size_of_property_declaration, properties::PropertyDeclaration // 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, 576); - -#[test] -fn size_of_specified_values() { - ::style::properties::test_size_of_specified_values(); -} diff --git a/tests/unit/stylo/lib.rs b/tests/unit/stylo/lib.rs index 05a32869c4e..45b9d63a9fd 100644 --- a/tests/unit/stylo/lib.rs +++ b/tests/unit/stylo/lib.rs @@ -14,6 +14,7 @@ extern crate style_traits; mod sanity_checks; mod size_of; +mod specified_values; mod servo_function_signatures; diff --git a/tests/unit/stylo/size_of.rs b/tests/unit/stylo/size_of.rs index 4f4521df9e2..3a830e1c40a 100644 --- a/tests/unit/stylo/size_of.rs +++ b/tests/unit/stylo/size_of.rs @@ -47,8 +47,3 @@ size_of_test!(test_size_of_rule_node, RuleNode, 80); // 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, style::properties::SourcePropertyDeclaration, 704); - -#[test] -fn size_of_specified_values() { - ::style::properties::test_size_of_specified_values(); -} diff --git a/tests/unit/stylo/specified_values.rs b/tests/unit/stylo/specified_values.rs new file mode 100644 index 00000000000..484f9534502 --- /dev/null +++ b/tests/unit/stylo/specified_values.rs @@ -0,0 +1,49 @@ +/* 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 http://mozilla.org/MPL/2.0/. */ + +use style; + +#[test] +fn size_of_specified_values() { + use std::mem::size_of; + let threshold = 24; + + let mut bad_properties = vec![]; + + macro_rules! check_property { + ( $( { $name: ident, $boxed: expr } )+ ) => { + $( + let size = size_of::(); + let is_boxed = $boxed; + if (!is_boxed && size > threshold) || (is_boxed && size <= threshold) { + bad_properties.push(("$name", size, is_boxed)); + } + )+ + } + } + + longhand_properties_idents!(check_property); + + let mut failing_messages = vec![]; + + for bad_prop in bad_properties { + if !bad_prop.2 { + failing_messages.push( + format!("Your changes have increased the size of {} SpecifiedValue to {}. The threshold is \ + currently {}. SpecifiedValues affect size of PropertyDeclaration enum and \ + increasing the size may negative affect style system performance. Please consider \ + using `boxed=\"True\"` in this longhand.", + bad_prop.0, bad_prop.1, threshold)); + } else if bad_prop.2 { + failing_messages.push( + format!("Your changes have decreased the size of {} SpecifiedValue to {}. Good work! \ + The threshold is currently {}. Please consider removing `boxed=\"True\"` from this longhand.", + bad_prop.0, bad_prop.1, threshold)); + } + } + + if !failing_messages.is_empty() { + panic!("{}", failing_messages.join("\n\n")); + } +} From 43210e4755648b31485b40d6c12c69744906a2f2 Mon Sep 17 00:00:00 2001 From: Nathan Froyd Date: Fri, 4 Aug 2017 08:45:49 -0400 Subject: [PATCH 3/3] remove features from styl{e,o}_tests crate We no longer need to pass special features down to sub-crates. --- tests/unit/style/Cargo.toml | 3 --- tests/unit/stylo/Cargo.toml | 3 --- 2 files changed, 6 deletions(-) diff --git a/tests/unit/style/Cargo.toml b/tests/unit/style/Cargo.toml index 51a0278c989..53585feb667 100644 --- a/tests/unit/style/Cargo.toml +++ b/tests/unit/style/Cargo.toml @@ -9,9 +9,6 @@ name = "style_tests" path = "lib.rs" doctest = false -[features] -testing = ["style/testing"] - [dependencies] byteorder = "1.0" app_units = "0.5" diff --git a/tests/unit/stylo/Cargo.toml b/tests/unit/stylo/Cargo.toml index 21eab2958a1..b3381276ff1 100644 --- a/tests/unit/stylo/Cargo.toml +++ b/tests/unit/stylo/Cargo.toml @@ -11,9 +11,6 @@ name = "stylo_tests" path = "lib.rs" doctest = false -[features] -testing = ["style/testing"] - [dependencies] atomic_refcell = "0.1" cssparser = "0.18"