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

Remove lifetimes from Style/Layout traits #9976

Merged
merged 3 commits into from Mar 14, 2016

Conversation

@bholley
Copy link
Contributor

bholley commented Mar 12, 2016

Right now, there's a huge amount of complexity in T{Node,Element,Document} and friends because of the lifetime parameter.

Before I started generalizing this code for use by Gecko, these wrappers were plain structs. They had (and still have) a phantom lifetime associated with them to prevent references to DOM nodes from leaking past the end of restyle, when they might be invalidated by a GC.

When I generalized them, I decided to put the lifetime on the trait as well, since there are some situations where the lifetime is, in fact, necessary. Specifically, they are necessary for the compiler to understand that all the things borrowed from all the nodes and elements and so on have the same lifetime (the lifetime of the restyle), rather than the lifetime of whichever particular element or node pointer the value was borrowed from. This come up in situations where we do |let el = node.as_element()| or |let n = el.as_node()| and then borrow something from the result. The compiler thinks the borrow lifetime is that of |el| or |n|, when it's actually longer.

In practice though, I think the style and layout algorithms we use don't run into this issue much, and we can hack around it where it comes up. So I think we should remove the lifetimes from the traits, which will let us aggregate the embedding-provided traits together onto a single meta-trait and significantly simplify the code.


This change is Review on Reviewable

@highfive
Copy link

highfive commented Mar 12, 2016

Heads up! This PR modifies the following files:

  • @bholley: components/style/parallel.rs, components/style/traversal.rs, components/style/selector_matching.rs, components/style/sequential.rs, components/style/dom.rs, components/style/matching.rs
@highfive
Copy link

highfive commented Mar 12, 2016

warning Warning warning

  • These commits modify unsafe code. Please review it carefully!
  • These commits modify style and layout code, but no tests are modified. Please consider adding a test!
@bholley
Copy link
Contributor Author

bholley commented Mar 12, 2016

@bholley
Copy link
Contributor Author

bholley commented Mar 12, 2016

@highfive highfive assigned SimonSapin and unassigned metajack Mar 12, 2016
@pcwalton
Copy link
Contributor

pcwalton commented Mar 14, 2016

Very nice.

@SimonSapin
Copy link
Member

SimonSapin commented Mar 14, 2016

Looks good!

@bors-servo delegate+


Reviewed 16 of 16 files at r1.
Review status: all files reviewed at latest revision, 3 unresolved discussions.


components/layout/wrapper.rs, line 409 [r1] (raw file):
Nit: 'a can probably be elided here.


components/style/dom.rs, line 196 [r1] (raw file):
Nit: 'a can probably be elided here.


ports/geckolib/wrapper.rs, line 320 [r1] (raw file):
Nit: 'a can probably be elided here.


Comments from the review on Reviewable.io

@bors-servo
Copy link
Contributor

bors-servo commented Mar 14, 2016

✌️ @bholley can now approve this pull request

@bholley bholley force-pushed the bholley:remove_trait_lifetimes branch from 35cf34f to 539f839 Mar 14, 2016
@bholley
Copy link
Contributor Author

bholley commented Mar 14, 2016

@bors-servo r=SimonSapin

@bors-servo
Copy link
Contributor

bors-servo commented Mar 14, 2016

📌 Commit 539f839 has been approved by SimonSapin

@bors-servo
Copy link
Contributor

bors-servo commented Mar 14, 2016

Testing commit 539f839 with merge aea8d89...

bors-servo added a commit that referenced this pull request Mar 14, 2016
Remove lifetimes from Style/Layout traits

Right now, there's a huge amount of complexity in T{Node,Element,Document} and friends because of the lifetime parameter.

Before I started generalizing this code for use by Gecko, these wrappers were plain structs. They had (and still have) a phantom lifetime associated with them to prevent references to DOM nodes from leaking past the end of restyle, when they might be invalidated by a GC.

When I generalized them, I decided to put the lifetime on the trait as well, since there are some situations where the lifetime is, in fact, necessary. Specifically, they are necessary for the compiler to understand that all the things borrowed from all the nodes and elements and so on have the same lifetime (the lifetime of the restyle), rather than the lifetime of whichever particular element or node pointer the value was borrowed from. This come up in situations where we do |let el = node.as_element()| or |let n = el.as_node()| and then borrow something from the result. The compiler thinks the borrow lifetime is that of |el| or |n|, when it's actually longer.

In practice though, I think the style and layout algorithms we use don't run into this issue much, and we can hack around it where it comes up. So I think we should remove the lifetimes from the traits, which will let us aggregate the embedding-provided traits together onto a single meta-trait and significantly simplify the code.

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/9976)
<!-- Reviewable:end -->
@bors-servo
Copy link
Contributor

bors-servo commented Mar 14, 2016

@bors-servo bors-servo merged commit 539f839 into servo:master Mar 14, 2016
3 checks passed
3 checks passed
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
homu Test successful
Details
@bors-servo bors-servo mentioned this pull request Mar 14, 2016
@bholley bholley deleted the bholley:remove_trait_lifetimes branch Oct 30, 2016
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

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