Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the style crate more concrete #12515

Merged
merged 9 commits into from Jul 20, 2016
Merged

Make the style crate more concrete #12515

merged 9 commits into from Jul 20, 2016

Conversation

@SimonSapin
Copy link
Member

SimonSapin commented Jul 19, 2016

Background:

The changes to Servo code to support Stylo began in the selectors crate with making pseudo-elements generic, defined be the user, so that different users (such as Servo and Gecko/Stylo) could have a different set of pseudo-elements supported and parsed. Adding a trait makes sense there since selectors is in its own repository and has others users (or at least one).

Then we kind of kept going with the same pattern and added a bunch of traits in the style crate to make everything generic, allowing Servo and Gecko/Stylo to do things differently. But we’ve also added a gecko Cargo feature to do conditional compilation, at first to enable or disable some CSS properties and values in the Mako templates. Since we’re doing conditional compilation anyway, it’s often easier and simpler to do it more (with #[cfg(feature = "gecko")] and #[cfg(feature = "servo")]) that to keep adding traits and making everything generic. When a type is generic, any method that we want to call on it needs to be part of some trait.


The first several commits move some code around, mostly from geckolib to style (with #[cfg(feature = "gecko")]) but otherwise don’t change much.

The following commits remove some traits and many type parameters through the style crate, replacing them with pairs of conditionally-compiled API-compatible items (types, methods, …).

Simplifying code is nice to make it more maintainable, but this is motivated by another change described in #12391 (comment). (Porting Servo for that change proved difficult because some code in the style crate was becoming generic over String vs Atom, and this PR will help make that concrete. That change, in turn, is motivated by removing geckolib’s [replace] override for string-cache, in order to enable using a single Cargo "workspace" in this repository.)

r? @bholley


  • ./mach build -d does not report any errors
  • ./mach test-tidy does not report any errors
  • These changes fix #__ (github issue number if applicable).
  • There are tests for these changes OR
  • These changes do not require new tests because refactoring

This change is Reviewable

@bholley
Copy link
Contributor

bholley commented Jul 19, 2016

I kinda skimmed parts of this because it's so enormous, but it's mechanical enough that this shouldn't be fine.

I'm a little worried about throwing away such a painstakingly-built abstraction layer, especially around the style structs traits. But I also agree that it's causing problems, and as long as we're building both configurations on CI, it's probably ok. Thanks for cleaning this stuff up!

@bors-servo r+

@bors-servo
Copy link
Contributor

bors-servo commented Jul 19, 2016

📌 Commit 6c2be50 has been approved by bholley

@bors-servo
Copy link
Contributor

bors-servo commented Jul 20, 2016

The latest upstream changes (presumably #12506) made this pull request unmergeable. Please resolve the merge conflicts.

@emilio
Copy link
Member

emilio commented Jul 20, 2016

Yes, the only "problem" this brings up IMO is that is too easy to forget that you're working with two different sets of types when you're touching style (i.e., rust won't blame you if you use the style structs fields directly when touching Servo, but then everything will break for Gecko, and vice versa).

I think the cleanup might be worth it though, those kind of errors would be caught on CI, and this should work just fine for new features. In case it doesn't, worst case is we could just learn from some mistakes we did (like putting the same type in two different traits, forcing to use a lot of extra where clauses), and make it better, but I can't find anything why this shouldn't work :)

So yeah, r=me too.

@SimonSapin SimonSapin force-pushed the concrete-style branch from 6c2be50 to 6d0e48f Jul 20, 2016
@SimonSapin
Copy link
Member Author

SimonSapin commented Jul 20, 2016

About that abstraction, I’m skeptical that it ever could support a third user without significant amount of work. We were already using conditional compilation for some things anyway.

Generics-everything can get hairy pretty quickly. In some of the code I touched there were more code in where clauses than method bodies.

@emilio That’s a fair point. I considered keeping the traits around to formally encode what API is supposed to be shared, but then decided to go with inherent methods that don’t need to be imported.


Rebased.

@bors-servo r=bholley

@bors-servo
Copy link
Contributor

bors-servo commented Jul 20, 2016

📌 Commit 6d0e48f has been approved by bholley

@SimonSapin
Copy link
Member Author

SimonSapin commented Jul 20, 2016

@bors-servo p=1

Large change somewhat likely to conflict with other PRs.

@bors-servo
Copy link
Contributor

bors-servo commented Jul 20, 2016

Testing commit 6d0e48f with merge 2d01d41...

bors-servo added a commit that referenced this pull request Jul 20, 2016
Make the style crate more concrete

Background:

The changes to Servo code to support Stylo began in the `selectors` crate with making pseudo-elements generic, defined be the user, so that different users (such as Servo and Gecko/Stylo) could have a different set of pseudo-elements supported and parsed. Adding a trait makes sense there since `selectors` is in its own repository and has others users (or at least [one](https://github.com/SimonSapin/kuchiki)).

Then we kind of kept going with the same pattern and added a bunch of traits in the `style` crate to make everything generic, allowing Servo and Gecko/Stylo to do things differently. But we’ve also added a `gecko` Cargo feature to do conditional compilation, at first to enable or disable some CSS properties and values in the Mako templates. Since we’re doing conditional compilation anyway, it’s often easier and simpler to do it more (with `#[cfg(feature = "gecko")]` and `#[cfg(feature = "servo")]`) that to keep adding traits and making everything generic. When a type is generic, any method that we want to call on it needs to be part of some trait.

----

The first several commits move some code around, mostly from `geckolib` to `style` (with `#[cfg(feature = "gecko")]`) but otherwise don’t change much.

The following commits remove some traits and many type parameters through the `style` crate, replacing them with pairs of conditionally-compiled API-compatible items (types, methods, …).

Simplifying code is nice to make it more maintainable, but this is motivated by another change described in #12391 (comment). (Porting Servo for that change proved difficult because some code in the `style` crate was becoming generic over `String` vs `Atom`, and this PR will help make that concrete. That change, in turn, is motivated by removing geckolib’s `[replace]` override for string-cache, in order to enable using a single Cargo "workspace" in this repository.)

r? @bholley

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes fix #__ (github issue number if applicable).

<!-- Either: -->
- [ ] There are tests for these changes OR
- [x] These changes do not require new tests because refactoring

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- 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/12515)
<!-- Reviewable:end -->
@bors-servo
Copy link
Contributor

bors-servo commented Jul 20, 2016

@bors-servo bors-servo merged commit 6d0e48f into master Jul 20, 2016
2 of 4 checks passed
2 of 4 checks passed
continuous-integration/appveyor/pr AppVeyor build failed
Details
dependency-ci Failed dependency checks
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
homu Test successful
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

5 participants
You can’t perform that action at this time.