servo/components
bors-servo 4a77cbdbb2 Auto merge of #12521 - Manishearth:safer-coord, r=bholley
Introduce safer layer of sugar for nsStyleUnion

This routes (almost) all access to nsStyleUnion through a largely safe interface, CoordData.

It also introduces a corresponding Rust enum, CoordDataValue, which can be used when interacting with CoordData

LLVM should optimize the costs away in release mode. eddyb tested this a bit, and LLVM has no trouble threading matches together with inlining -- so all of the matches using enums here will have the same generated code as the old matches on the units.

Some unresolved questions:

Should I provide convenience methods like `set_coord`, `set_auto`, etc on CoordData? `.set_enum(CoordDataValue::Something)` should optimize down to the same thing, but the convenience methods look cleaner and won't load the optimizer as much.

Also, we're converting immutable references to mutable ones, which can be used to cause unsafety using some acrobatics. Perhaps a trait-based approach is better?
The issue is that in some places we only have a `&CoordData` (eg copy_from), but CoordData internally is `*mut`. It would be nice if CoordData could parametrize over its mutability, but Rust doesn't let us do that.

The alternate approach is to make CoordData a trait (also CoordDataMut). The trait requires you to implement `get_union()` and `get_unit()`, and gives you the rest of the functions for free. `nsStyleCoord` would directly implement both traits. `nsStyleSides` would have `data_at(idx)` and `data_at_mut(idx)` methods which return a struct `SidesData` containing a reference to the Sides and the index, which itself implements the `CoordData` and `CoordDataMut` trait (we need two traits here because there will have to be two `SidesData` structs).

I decided not to implement the traits approach first since it's pretty trivial to change this code to use traits, and the current design is more straightforward.

Thoughts?

r? @bholley

cc @emilio @heycam

<!-- 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/12521)
<!-- Reviewable:end -->
2016-07-21 03:05:56 -05:00
..
canvas Remove dependency on util::opts from canvas crate 2016-07-20 07:38:18 +00:00
canvas_traits All our Cargo.toml files should contain an MPL-2.0 license field. 2016-07-14 10:26:34 -05:00
compositing Replace any errors caused by content-provided URLs by warnings. 2016-07-15 09:50:40 -05:00
constellation Auto merge of #12507 - larsbergstrom:remove_clipboard, r=metajack 2016-07-20 11:53:04 -05:00
devtools All our Cargo.toml files should contain an MPL-2.0 license field. 2016-07-14 10:26:34 -05:00
devtools_traits All our Cargo.toml files should contain an MPL-2.0 license field. 2016-07-14 10:26:34 -05:00
gfx Remove the ComputedValue traits and style_struct_traits 2016-07-20 08:42:40 +02:00
gfx_traits All our Cargo.toml files should contain an MPL-2.0 license field. 2016-07-14 10:26:34 -05:00
layout style: Add a new Timer structure to the shared style context, and basic infrastructure for controlling animations. 2016-07-20 09:05:53 -07:00
layout_thread style: Add a new Timer structure to the shared style context, and basic infrastructure for controlling animations. 2016-07-20 09:05:53 -07:00
layout_traits All our Cargo.toml files should contain an MPL-2.0 license field. 2016-07-14 10:26:34 -05:00
msg msg: Rename ReferrerPolicy::NoRefWhenDowngrade NoReferrerWhenDowngrade 2016-07-15 08:13:57 -07:00
net make resource_thread talk to sw-manager 2016-07-18 19:06:48 +05:30
net_traits Integrate service worker manager thread 2016-07-16 23:29:44 +05:30
plugins All our Cargo.toml files should contain an MPL-2.0 license field. 2016-07-14 10:26:34 -05:00
profile All our Cargo.toml files should contain an MPL-2.0 license field. 2016-07-14 10:26:34 -05:00
profile_traits All our Cargo.toml files should contain an MPL-2.0 license field. 2016-07-14 10:26:34 -05:00
range All our Cargo.toml files should contain an MPL-2.0 license field. 2016-07-14 10:26:34 -05:00
script Auto merge of #12467 - jeenalee:jeena-headersAPI, r=jdm 2016-07-20 16:24:48 -05:00
script_layout_interface style: Add a new Timer structure to the shared style context, and basic infrastructure for controlling animations. 2016-07-20 09:05:53 -07:00
script_traits script: Implement Debug on ConstellationControlMsg to simplify script_thread.rs 2016-07-20 09:03:56 -07:00
servo Auto merge of #12392 - emilio:test-animations, r=SimonSapin 2016-07-20 13:38:31 -05:00
style Auto merge of #12521 - Manishearth:safer-coord, r=bholley 2016-07-21 03:05:56 -05:00
style_traits All our Cargo.toml files should contain an MPL-2.0 license field. 2016-07-14 10:26:34 -05:00
util Auto merge of #12137 - ConnorGBrewster:resources_case_sensitive, r=aneeshusa 2016-07-15 10:29:55 -07:00
webdriver_server All our Cargo.toml files should contain an MPL-2.0 license field. 2016-07-14 10:26:34 -05:00