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

style: Rewrite the restyle hints code to allow different kinds of element snapshots. #12469

Merged
merged 2 commits into from Jul 22, 2016

Conversation

@emilio
Copy link
Member

emilio commented Jul 16, 2016


  • ./mach build -d does not report any errors
  • ./mach test-tidy does not report any errors
  • These changes do not require tests because refactoring.

This is a rewrite for how style interfaces with its consumers in order to allow
different representations for an element snapshot.

This also changes the requirements of an element snapshot, requiring them to
only implement MatchAttr, instead of MatchAttrGeneric. This is important for
stylo since implementing MatchAttrGeneric is way more difficult for us given the
atom limitations. This also allows for more performant implementations in the
Gecko side of things.

I don't want to get this merged just yet, mainly because the stylo part is not
implemented, but I'd like early feedback from @bholley and/or @heycam: How do
you see this approach? I don't think we'll have much problem to implement
MatchAttr for our element snapshots, but... worth checking.

r? @heycam


This change is Reviewable

@nox
Copy link
Member

nox commented Jul 16, 2016

Do we really need yet another "Servo" prefix? :(

@emilio emilio force-pushed the emilio:stylo branch from 08e6782 to a6d8307 Jul 19, 2016
@emilio emilio force-pushed the emilio:stylo branch from a6d8307 to 670b341 Jul 19, 2016
@emilio emilio changed the title [wip] style: Rewrite the restyle hints code to allow different kinds of element snapshots. style: Rewrite the restyle hints code to allow different kinds of element snapshots. Jul 19, 2016
@emilio
Copy link
Member Author

emilio commented Jul 19, 2016

This is basically ready for review... r? @bholley or @heycam

Relevant gecko bug: https://bugzilla.mozilla.org/show_bug.cgi?id=1287951

@emilio
Copy link
Member Author

emilio commented Jul 19, 2016

@SimonSapin: This kind of conflicts with your current efforts to use conditional compilation in style. I don't expect this to be a lot of breakage (the only relevant changes for that are the restyle_hints.rs file, and the implementation added in geckolib), though could you please check?

I don't mind holding this off for a bit and rebase if your changes are landing soon :)

@SimonSapin
Copy link
Member

SimonSapin commented Jul 19, 2016

I tried merging this PR into #12515 (which I just submitted) and got conflicts in:

  • ports/geckolib/wrapper.rs
  • ports/geckolib/glue.rs
  • components/style/selector_matching.rs
  • components/style/selector_impl.rs
  • components/style/restyle_hints.rs
  • components/script/dom/document.rs

I haven’t looked in more details than that.

@emilio
Copy link
Member Author

emilio commented Jul 19, 2016

@SimonSapin: Then don't bother about it, I'll do the rebase :)

@bors-servo
Copy link
Contributor

bors-servo commented Jul 20, 2016

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

@emilio emilio force-pushed the emilio:stylo branch 2 times, most recently from 5279d4b to 14374a8 Jul 20, 2016
@bholley bholley removed the S-needs-rebase label Jul 21, 2016
@bholley
Copy link
Contributor

bholley commented Jul 21, 2016

Reviewed 13 of 14 files at r1, 4 of 4 files at r2.
Review status: all files reviewed at latest revision, 9 unresolved discussions.


components/style/selector_impl.rs, line 82 [r2] (raw file):

// NB: The `Clone` trait is here for convenience due to:
// https://github.com/rust-lang/rust/issues/26925

This text appears twice...


ports/geckolib/glue.rs, line 452 [r2] (raw file):

    let element = unsafe { GeckoElement::from_raw(element) };

    // NB: This involves an FFI call, we can take rid of it easily if needed.

Nit: "get rid of".


ports/geckolib/glue.rs, line 459 [r2] (raw file):

                                                 current_state);

    // NB: Binaries representation match.

Do we have an enforcement mechanism for this somewhere? If not, please file a bug so that we remember to do that.


ports/geckolib/glue.rs, line 460 [r2] (raw file):

    // NB: Binaries representation match.
    unsafe { transmute(hint.bits() as u32) }

Does this really need to be a transmute? I don't remember if |as| works for repr(C) enums.


ports/geckolib/snapshot.rs, line 16 [r2] (raw file):

// NB: This is sound, in some sense, because during computation of restyle hints
// the snapshot is kept alive by the modified elements table.

Hm, so these are basically only valid in stack scope, right? Can we either use a lifetime or a strong reference here to make sure these don't escape? Happy for that to happen in a followup if that makes sense.


ports/geckolib/snapshot.rs, line 31 [r2] (raw file):

    fn has_any(&self, flags: Flags) -> bool {
        unsafe { (*self.0).mContains as u8 & flags as u8 != 0 }

Can you parenthesize a bit more here make the precedence clearer?


ports/geckolib/snapshot.rs, line 62 [r2] (raw file):

                                               attr.select_name(self.is_html_element_in_html_document()),
                                               value.as_ptr(),
                                               /* ignoreCase = */ false)

Don't you want ignoreCase = true here?


ports/geckolib/snapshot.rs, line 129 [r2] (raw file):

        } else {
            Some(Atom::from(value))
        }

Can you use .as_ref().map here instead?


ports/geckolib/snapshot.rs, line 132 [r2] (raw file):

    }

    // TODO: share logic with Element::{has_class, each_class}?

Yeah, the logic here is complicated enough that I think we should share these and just pass a function argument to the helper which invokes the appropriate FFI method.


Comments from Reviewable

@bholley
Copy link
Contributor

bholley commented Jul 21, 2016

r=me with those addressed. @bors-servo delegate+

@bors-servo
Copy link
Contributor

bors-servo commented Jul 21, 2016

✌️ @emilio can now approve this pull request

emilio added 2 commits Jul 15, 2016
…ment snapshots, and use it for Gecko.

This is a rewrite for how style interfaces with its consumers in order to allow
different representations for an element snapshot.

This also changes the requirements of an element snapshot, requiring them to
only implement MatchAttr, instead of MatchAttrGeneric. This is important for
stylo since implementing MatchAttrGeneric is way more difficult for us given the
atom limitations. This also allows for more performant implementations in the
Gecko side of things.
@emilio
Copy link
Member Author

emilio commented Jul 21, 2016

Review status: all files reviewed at latest revision, 9 unresolved discussions.


components/style/selector_impl.rs, line 82 [r2] (raw file):

Previously, bholley (Bobby Holley) wrote…

This text appears twice...

Dammit, rebase maddness... For some reason git decided to automerge it this way, sigh.

ports/geckolib/glue.rs, line 452 [r2] (raw file):

Previously, bholley (Bobby Holley) wrote…

Nit: "get rid of".

Done.

ports/geckolib/glue.rs, line 459 [r2] (raw file):

Previously, bholley (Bobby Holley) wrote…

Do we have an enforcement mechanism for this somewhere? If not, please file a bug so that we remember to do that.

We don't. I can add it as a followup.

ports/geckolib/glue.rs, line 460 [r2] (raw file):

Previously, bholley (Bobby Holley) wrote…

Does this really need to be a transmute? I don't remember if |as| works for repr(C) enums.

It works in the enum to integer case, but not the opposite without transmute.

ports/geckolib/snapshot.rs, line 16 [r2] (raw file):

Previously, bholley (Bobby Holley) wrote…

Hm, so these are basically only valid in stack scope, right? Can we either use a lifetime or a strong reference here to make sure these don't escape? Happy for that to happen in a followup if that makes sense.

Hm... Not really, they are kept alive in the heap, but cleared just before the `DoProcessRestyles` function returns.

Nontheless, yeah, I can try to give it a lifetime, and use the lifetime of the scope of that function as a follow-up.


ports/geckolib/snapshot.rs, line 31 [r2] (raw file):

Previously, bholley (Bobby Holley) wrote…

Can you parenthesize a bit more here make the precedence clearer?

Sure.

ports/geckolib/snapshot.rs, line 62 [r2] (raw file):

Previously, bholley (Bobby Holley) wrote…

Don't you want ignoreCase = true here?

Good catch, as usual :)

ports/geckolib/snapshot.rs, line 129 [r2] (raw file):

Previously, bholley (Bobby Holley) wrote…

Can you use .as_ref().map here instead?

Nope, since it converts it into a reference, and then `Atom::from` doesn't know what to do. We can certainly add an impl like `From<'a> &'a nsIAtom for Atom`, but I don't quite love it that much.

ports/geckolib/snapshot.rs, line 132 [r2] (raw file):

Previously, bholley (Bobby Holley) wrote…

Yeah, the logic here is complicated enough that I think we should share these and just pass a function argument to the helper which invokes the appropriate FFI method.

Done.

Comments from Reviewable

@emilio emilio force-pushed the emilio:stylo branch from 14374a8 to f44e31a Jul 21, 2016
@emilio
Copy link
Member Author

emilio commented Jul 21, 2016

@bors-servo: r=bholley

@bors-servo
Copy link
Contributor

bors-servo commented Jul 21, 2016

📌 Commit f44e31a has been approved by bholley

@bors-servo
Copy link
Contributor

bors-servo commented Jul 21, 2016

Testing commit f44e31a with merge 1e0321f...

bors-servo added a commit that referenced this pull request Jul 21, 2016
style: Rewrite the restyle hints code to allow different kinds of element snapshots.

<!-- Please describe your changes on the following line: -->

---
<!-- 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

<!-- Either: -->
- [x] These changes do not require 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. -->

This is a rewrite for how style interfaces with its consumers in order to allow
different representations for an element snapshot.

This also changes the requirements of an element snapshot, requiring them to
only implement MatchAttr, instead of MatchAttrGeneric. This is important for
stylo since implementing MatchAttrGeneric is way more difficult for us given the
atom limitations. This also allows for more performant implementations in the
Gecko side of things.

I don't want to get this merged just yet, mainly because the stylo part is not
implemented, but I'd like early feedback from @bholley and/or @heycam: How do
you see this approach? I don't think we'll have much problem to implement
MatchAttr for our element snapshots, but... worth checking.

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

bors-servo commented Jul 21, 2016

💔 Test failed - linux-rel

@emilio
Copy link
Member Author

emilio commented Jul 21, 2016

@bors-servo
Copy link
Contributor

bors-servo commented Jul 21, 2016

Previous build results for android, arm32, arm64, linux-dev, mac-dev-unit, mac-rel-css, mac-rel-wpt, windows-dev are reusable. Rebuilding only linux-rel...

@bors-servo
Copy link
Contributor

bors-servo commented Jul 22, 2016

@bors-servo bors-servo merged commit f44e31a into servo:master Jul 22, 2016
2 checks passed
2 checks passed
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

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