Skip to content

Commit

Permalink
Auto merge of #15953 - bholley:size_of_stylo, r=<try>
Browse files Browse the repository at this point in the history
Make size_of tests measure stylo

Right now they don't, which means that we have four properties making PropertyDeclaration 16 bytes bigger than it should be.

I'm not sure if there's a better way to get these tests to run against stylo than to hoist them into the properties file, but I couldn't figure it out. This seems good enough.

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/15953)
<!-- Reviewable:end -->
  • Loading branch information
bors-servo committed Mar 15, 2017
2 parents 6a2a5be + 502e393 commit 537cd0e
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 54 deletions.
3 changes: 3 additions & 0 deletions components/style/properties/longhand/inherited_svg.mako.rs
Expand Up @@ -119,16 +119,19 @@ ${helpers.single_keyword("clip-rule", "nonzero evenodd",

${helpers.predefined_type("marker-start", "UrlOrNone", "Either::Second(None_)",
products="gecko",
boxed="True",
animatable="False",
spec="https://www.w3.org/TR/SVG2/painting.html#VertexMarkerProperties")}

${helpers.predefined_type("marker-mid", "UrlOrNone", "Either::Second(None_)",
products="gecko",
boxed="True",
animatable="False",
spec="https://www.w3.org/TR/SVG2/painting.html#VertexMarkerProperties")}

${helpers.predefined_type("marker-end", "UrlOrNone", "Either::Second(None_)",
products="gecko",
boxed="True",
animatable="False",
spec="https://www.w3.org/TR/SVG2/painting.html#VertexMarkerProperties")}

Expand Down
1 change: 1 addition & 0 deletions components/style/properties/longhand/list.mako.rs
Expand Up @@ -38,6 +38,7 @@ ${helpers.single_keyword("list-style-type", """
spec="https://drafts.csswg.org/css-lists/#propdef-list-style-type")}

${helpers.predefined_type("list-style-image", "UrlOrNone", "Either::Second(None_)",
boxed = product == "gecko",
initial_specified_value="Either::Second(None_)", animatable=False,
spec="https://drafts.csswg.org/css-lists/#propdef-list-style-image")}

Expand Down
49 changes: 48 additions & 1 deletion components/style/properties/properties.mako.rs
Expand Up @@ -2388,7 +2388,6 @@ macro_rules! longhand_properties_idents {
}

/// Retuns all longhands SpecifiedValue sizes. This is used in unit tests.
#[cfg(feature = "testing")]
pub fn specified_value_sizes() -> Vec<(&'static str, usize, bool)> {
use std::mem::size_of;
let mut sizes = vec![];
Expand All @@ -2401,3 +2400,51 @@ pub fn specified_value_sizes() -> Vec<(&'static str, usize, bool)> {

sizes
}

#[test]
fn size_of_property_declaration() {
use std::mem::size_of;

let old = 48;
let new = size_of::<PropertyDeclaration>();
if new < old {
panic!("Your changes have decreased the stack size of PropertyDeclaration enum from {} to {}. \
Good work! Please update the size in tests/unit/style/size_of.rs.",
old, new)
} else if new > old {
panic!("Your changes have increased the stack size of PropertyDeclaration enum from {} to {}. \
These enum is present in large quantities in the style, and increasing the size \
may negatively affect style system performance. Please consider using `boxed=\"True\"` in \
the longhand If you feel that the increase is necessary, update to the new size in \
tests/unit/style/size_of.rs.",
old, new)
}
}

#[test]
fn size_of_specified_values() {
let threshold = 32;
let longhands = specified_value_sizes();

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"));
}
}
1 change: 0 additions & 1 deletion tests/unit/style/lib.rs
Expand Up @@ -30,7 +30,6 @@ mod owning_handle;
mod parsing;
mod properties;
mod rule_tree;
mod size_of;
mod str;
mod stylesheets;
mod stylist;
Expand Down
52 changes: 0 additions & 52 deletions tests/unit/style/size_of.rs

This file was deleted.

0 comments on commit 537cd0e

Please sign in to comment.