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: :dir() pseudo class now represented by enum #19195

Merged
merged 1 commit into from Nov 21, 2017

Conversation

@wilsoniya
Copy link
Contributor

wilsoniya commented Nov 12, 2017

:dir() pseudo class param now represented as enum variants.


  • ./mach build -d does not report any errors
  • ./mach test-tidy does not report any errors
  • These changes fix #16840
  • There are tests for these changes

This change is Reviewable

@highfive
Copy link

highfive commented Nov 12, 2017

Thanks for the pull request, and welcome! The Servo team is excited to review your changes, and you should hear from @mbrubeck (or someone else) soon.

@highfive
Copy link

highfive commented Nov 12, 2017

Heads up! This PR modifies the following files:

  • @bholley: components/selectors/size_of_tests.rs, components/style/invalidation/element/invalidation_map.rs, components/style/gecko/selector_parser.rs, components/style/invalidation/element/element_wrapper.rs, components/style/gecko/wrapper.rs and 2 more
  • @canaltinova: components/style/invalidation/element/invalidation_map.rs, components/style/gecko/selector_parser.rs, components/style/invalidation/element/element_wrapper.rs, components/style/gecko/wrapper.rs, components/style/gecko/non_ts_pseudo_class_list.rs
  • @emilio: components/style/invalidation/element/invalidation_map.rs, components/style/gecko/selector_parser.rs, components/style/invalidation/element/element_wrapper.rs, components/style/gecko/wrapper.rs, components/style/gecko/non_ts_pseudo_class_list.rs
@highfive
Copy link

highfive commented Nov 12, 2017

warning Warning warning

  • These commits modify unsafe code. Please review it carefully!
Copy link
Member

emilio left a comment

Good start!

I have a bunch of comments, let me know if any of those is unclear and I'm happy to clarify or help out.

Thanks for working on this!

pub enum Direction {
Rtl,
Ltr,
Other(String),

This comment has been minimized.

@emilio

emilio Nov 13, 2017

Member

This should still be Box<[u16]>, or Box<str> at least. That may avoid Component growing.

@@ -14,8 +14,8 @@ use visitor::SelectorVisitor;
size_of_test!(size_of_selector, Selector<Impl>, 8);
size_of_test!(size_of_pseudo_element, gecko_like_types::PseudoElement, 24);

size_of_test!(size_of_component, Component<Impl>, 32);
size_of_test!(size_of_pseudo_class, PseudoClass, 24);
size_of_test!(size_of_component, Component<Impl>, 48);

This comment has been minimized.

@emilio

emilio Nov 13, 2017

Member

Growing Component is not really acceptable I think :(

/// left-to-right semantic directionality
Ltr,
/// Some other provided directionality value
Other(String),

This comment has been minimized.

@emilio

emilio Nov 13, 2017

Member

Ditto.

Other(String),
}

impl <'a> From<&'a str> for Direction {

This comment has been minimized.

@emilio

emilio Nov 13, 2017

Member

No need for From<&'a str>, let's use the Parse trait.


impl <'a> From<&'a str> for Direction {
fn from(string: &'a str) -> Direction {
match string.to_lowercase().as_str() {

This comment has been minimized.

@emilio

emilio Nov 13, 2017

Member

No need to allocate here, let's use match_ignore_ascii_case.

@@ -360,6 +417,10 @@ impl<'a, 'i> ::selectors::Parser<'i> for SelectorParser<'a> {
.chain(Some(0u16)).collect();
NonTSPseudoClass::$k_name(utf16.into_boxed_slice())
}, )*
"dir" => {
let name: &str = parser.expect_ident()?;

This comment has been minimized.

@emilio

emilio Nov 13, 2017

Member

Let's add the match here instead of the From impl.

@@ -2066,6 +2065,15 @@ impl<'le> ::selectors::Element for GeckoElement<'le> {
)
}
}
NonTSPseudoClass::Dir(ref dir) => {
unsafe {
Gecko_MatchStringArgPseudo(

This comment has been minimized.

@emilio

emilio Nov 13, 2017

Member

The point of converting to an enum is not having to go through Gecko_MatchStringArgPseudo.

Instead of that, we can just do:

match *dir {
   Direction::Ltr => self.get_state().intersects(element_state::IN_HAS_DIR_ATTR_LTR_STATE),
   Direction::Rtl => self.get_state().intersects(element_state::IN_HAS_DIR_ATTR_RTL_STATE),
   Direction::Other(..) => false,
}
use invalidation::element::invalidation_map::dir_selector_to_state;
let selector_flag = dir_selector_to_state(s);

This comment has been minimized.

@emilio

emilio Nov 13, 2017

Member

Similarly, we can simplify dir_selector_to_state to take &Direction, instead of comparing the string.

This comment has been minimized.

@emilio

emilio Nov 13, 2017

Member

That should make the Box<[u16]> impl unnecessary.

@@ -0,0 +1,31 @@
/* This Source Code Form is subject to the terms of the Mozilla Public

This comment has been minimized.

@emilio

emilio Nov 13, 2017

Member

No need for this, we have tests in mozilla-central for this :)

@@ -14,8 +14,8 @@ use visitor::SelectorVisitor;
size_of_test!(size_of_selector, Selector<Impl>, 8);
size_of_test!(size_of_pseudo_element, gecko_like_types::PseudoElement, 24);

size_of_test!(size_of_component, Component<Impl>, 32);
size_of_test!(size_of_pseudo_class, PseudoClass, 24);
size_of_test!(size_of_component, Component<Impl>, 40);

This comment has been minimized.

@wilsoniya

wilsoniya Nov 14, 2017

Author Contributor

Even using the Other<Box[u16]> enum variant type, the size of these structs is increased :(

This comment has been minimized.

@emilio

emilio Nov 14, 2017

Member

Hmm, that's pretty unfortunate, let's box the Direction then:

Dir(Box<Direction>)

Mentioning that it allows not growing Component, even though it's slightly unfortunate.

This comment has been minimized.

@emilio

emilio Nov 14, 2017

Member

Oh, the other thing we can do instead, and it'll fix the serialization bug I just noted below too, I think, is using CustomIdent, which should just be one word and allow us not to box it:

enum Direction {
    Rtl,
    Ltr,
    Other(CustomIdent),
}

Then you don't even need to manually write the serialization code, and you can just #[derive(ToCss)] on it.

@wilsoniya
Copy link
Contributor Author

wilsoniya commented Nov 14, 2017

Hey, @emilio, thanks for the review! I think I've addressed your comments, with the exception of the change in size of Component.

Do you have ideas regarding how to eliminate the size increase on that struct?

Other(Box<[u16]>),
}

impl<'a> From<&'a Direction> for String {

This comment has been minimized.

@emilio

emilio Nov 14, 2017

Member

Given we don't use the utf16 impl anyway, this could be Box<str>, and there'd be no need to allocate a String for serialization.

@@ -14,8 +14,8 @@ use visitor::SelectorVisitor;
size_of_test!(size_of_selector, Selector<Impl>, 8);
size_of_test!(size_of_pseudo_element, gecko_like_types::PseudoElement, 24);

size_of_test!(size_of_component, Component<Impl>, 32);
size_of_test!(size_of_pseudo_class, PseudoClass, 24);
size_of_test!(size_of_component, Component<Impl>, 40);

This comment has been minimized.

@emilio

emilio Nov 14, 2017

Member

Hmm, that's pretty unfortunate, let's box the Direction then:

Dir(Box<Direction>)

Mentioning that it allows not growing Component, even though it's slightly unfortunate.

@@ -92,6 +94,12 @@ impl ToCss for NonTSPseudoClass {
dest.write_str(&value)?;
return dest.write_char(')')
}, )*
NonTSPseudoClass::Dir(ref dir) => {

This comment has been minimized.

@emilio

emilio Nov 14, 2017

Member

Let's impl ToCss for Direction, and use that here, doing just:

dest.write_str(":dir(")?;
dir.to_css(dest)?;
dest.write_char(')')
NonTSPseudoClass::Dir(ref dir) => {
let value: String = dir.into();
dest.write_str(concat!(":dir("))?;
dest.write_str(&value)?;

This comment has been minimized.

@emilio

emilio Nov 14, 2017

Member

Also, I believe this is not correct, and should do escaping for the identifier... Though it's an existing bug.

@@ -14,8 +14,8 @@ use visitor::SelectorVisitor;
size_of_test!(size_of_selector, Selector<Impl>, 8);
size_of_test!(size_of_pseudo_element, gecko_like_types::PseudoElement, 24);

size_of_test!(size_of_component, Component<Impl>, 32);
size_of_test!(size_of_pseudo_class, PseudoClass, 24);
size_of_test!(size_of_component, Component<Impl>, 40);

This comment has been minimized.

@emilio

emilio Nov 14, 2017

Member

Oh, the other thing we can do instead, and it'll fix the serialization bug I just noted below too, I think, is using CustomIdent, which should just be one word and allow us not to box it:

enum Direction {
    Rtl,
    Ltr,
    Other(CustomIdent),
}

Then you don't even need to manually write the serialization code, and you can just #[derive(ToCss)] on it.

@wilsoniya
Copy link
Contributor Author

wilsoniya commented Nov 15, 2017

@emilio Thanks for the follow-up. Regarding your comment regarding escaping: do you have a link to an issue about existing escaping shortcomings and/or thoughts on how to proceed?

Your attention and patience on this PR is much appreciated! At this point it probably would have been faster for you to implement a fix yourself than to explain all these things to me :)

@emilio
emilio approved these changes Nov 15, 2017
Copy link
Member

emilio left a comment

Looks great!

r=me with these two nits and the commits squashed. Thanks a lot for working on this!

@@ -92,6 +94,11 @@ impl ToCss for NonTSPseudoClass {
dest.write_str(&value)?;
return dest.write_char(')')
}, )*
NonTSPseudoClass::Dir(ref dir) => {
dest.write_str(concat!(":dir("))?;

This comment has been minimized.

@emilio

emilio Nov 15, 2017

Member

Why is there a need for concat! here?

let dir_str = match *self {
Direction::Rtl => "rtl",
Direction::Ltr => "ltr",
Direction::Other(ref other) => other,

This comment has been minimized.

@emilio

emilio Nov 15, 2017

Member

Please add a FIXME here saying:

FIXME: This should be escaped as an identifier.

That can be a followup if you want, since that's a bugfix, requires tests and all that.

The short version is that it should use serialize_identifier, in order to properly handle escapes. I believe we have tests that test this where you could grab an example... But looking at what serialize_identifier handles, something like this:

:dir(\-) { .. }

Should be a valid rule, but serializes back to:

:dir(-) { .. }

Which isn't an identifier token IIRC.

This comment has been minimized.

@wilsoniya

wilsoniya Nov 15, 2017

Author Contributor

Created #19231 which I can pick up as a followup.

@wilsoniya wilsoniya force-pushed the wilsoniya:issue-16840 branch from d0b0a6b to 10f3ef4 Nov 16, 2017
@wilsoniya
Copy link
Contributor Author

wilsoniya commented Nov 21, 2017

@emilio are there any other changes you'd like to see before this is mergeable?

@@ -92,6 +94,12 @@ impl ToCss for NonTSPseudoClass {
dest.write_str(&value)?;
return dest.write_char(')')
}, )*
NonTSPseudoClass::Dir(ref dir) => {
dest.write_str(":dir(")?;
// FIXME: This should be escaped as an identifier; see #19231

This comment has been minimized.

@emilio

emilio Nov 21, 2017

Member

This comment should probably go in the to_css impl, but that can be done in a followup PR.

@emilio
Copy link
Member

emilio commented Nov 21, 2017

Nope, sorry! I had missed the latest update. Feel free to ping me sooner if this happens again.

@bors-servo r+

@bors-servo
Copy link
Contributor

bors-servo commented Nov 21, 2017

📌 Commit 10f3ef4 has been approved by emilio

@emilio
Copy link
Member

emilio commented Nov 21, 2017

Looks great, thanks a lot!

@bors-servo
Copy link
Contributor

bors-servo commented Nov 21, 2017

Testing commit 10f3ef4 with merge 0062027...

bors-servo added a commit that referenced this pull request Nov 21, 2017
style: :dir() pseudo class now represented by enum

`:dir()` pseudo class param now represented as enum variants.

---
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [X] These changes fix #16840
- [X] There are tests for these changes

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

bors-servo commented Nov 21, 2017

@bors-servo bors-servo merged commit 10f3ef4 into servo:master Nov 21, 2017
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
@wilsoniya wilsoniya mentioned this pull request Nov 22, 2017
3 of 3 tasks complete
bors-servo added a commit that referenced this pull request Nov 22, 2017
moving :dir() param serialization FIXME

<!-- Please describe your changes on the following line: -->
Per emilio's comment, #19195 (comment), a `FIXME` regarding `:dir()` parameter serialization has been moved.

---
<!-- 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 do not require tests because they only modify comment lines

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- 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/19332)
<!-- Reviewable:end -->
moz-v2v-gh pushed a commit to mozilla/gecko-dev that referenced this pull request Nov 22, 2017
…ilsoniya:moving-fixme); r=emilio

<!-- Please describe your changes on the following line: -->
Per emilio's comment, servo/servo#19195 (comment), a `FIXME` regarding `:dir()` parameter serialization has been moved.

---
<!-- 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 do not require tests because they only modify comment lines

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

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

Source-Repo: https://github.com/servo/servo
Source-Revision: 3ecd0174cc7817cdd2007850c29b8b069a845b46

--HG--
extra : subtree_source : https%3A//hg.mozilla.org/projects/converted-servo-linear
extra : subtree_revision : bd40b06fc49360f0a8ac206558734ec557c741cc
weilonge pushed a commit to weilonge/gecko that referenced this pull request Nov 23, 2017
…ilsoniya:moving-fixme); r=emilio

<!-- Please describe your changes on the following line: -->
Per emilio's comment, servo/servo#19195 (comment), a `FIXME` regarding `:dir()` parameter serialization has been moved.

---
<!-- 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 do not require tests because they only modify comment lines

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

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

Source-Repo: https://github.com/servo/servo
Source-Revision: 3ecd0174cc7817cdd2007850c29b8b069a845b46
aethanyc pushed a commit to aethanyc/gecko-dev that referenced this pull request Nov 23, 2017
…ilsoniya:moving-fixme); r=emilio

<!-- Please describe your changes on the following line: -->
Per emilio's comment, servo/servo#19195 (comment), a `FIXME` regarding `:dir()` parameter serialization has been moved.

---
<!-- 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 do not require tests because they only modify comment lines

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

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

Source-Repo: https://github.com/servo/servo
Source-Revision: 3ecd0174cc7817cdd2007850c29b8b069a845b46
@wilsoniya wilsoniya deleted the wilsoniya:issue-16840 branch Nov 23, 2017
JerryShih pushed a commit to JerryShih/gecko-dev that referenced this pull request Nov 28, 2017
…ilsoniya:moving-fixme); r=emilio

<!-- Please describe your changes on the following line: -->
Per emilio's comment, servo/servo#19195 (comment), a `FIXME` regarding `:dir()` parameter serialization has been moved.

---
<!-- 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 do not require tests because they only modify comment lines

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

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

Source-Repo: https://github.com/servo/servo
Source-Revision: 3ecd0174cc7817cdd2007850c29b8b069a845b46
gecko-dev-updater pushed a commit to marco-c/gecko-dev-wordified-and-comments-removed that referenced this pull request Oct 2, 2019
…ilsoniya:moving-fixme); r=emilio

<!-- Please describe your changes on the following line: -->
Per emilio's comment, servo/servo#19195 (comment), a `FIXME` regarding `:dir()` parameter serialization has been moved.

---
<!-- 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 do not require tests because they only modify comment lines

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

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

Source-Repo: https://github.com/servo/servo
Source-Revision: 3ecd0174cc7817cdd2007850c29b8b069a845b46

UltraBlame original commit: 84b90d871c2c14c24356f2840b5bbe9413a5e729
gecko-dev-updater pushed a commit to marco-c/gecko-dev-comments-removed that referenced this pull request Oct 2, 2019
…ilsoniya:moving-fixme); r=emilio

<!-- Please describe your changes on the following line: -->
Per emilio's comment, servo/servo#19195 (comment), a `FIXME` regarding `:dir()` parameter serialization has been moved.

---
<!-- 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 do not require tests because they only modify comment lines

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

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

Source-Repo: https://github.com/servo/servo
Source-Revision: 3ecd0174cc7817cdd2007850c29b8b069a845b46

UltraBlame original commit: 84b90d871c2c14c24356f2840b5bbe9413a5e729
gecko-dev-updater pushed a commit to marco-c/gecko-dev-wordified that referenced this pull request Oct 2, 2019
…ilsoniya:moving-fixme); r=emilio

<!-- Please describe your changes on the following line: -->
Per emilio's comment, servo/servo#19195 (comment), a `FIXME` regarding `:dir()` parameter serialization has been moved.

---
<!-- 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 do not require tests because they only modify comment lines

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

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

Source-Repo: https://github.com/servo/servo
Source-Revision: 3ecd0174cc7817cdd2007850c29b8b069a845b46

UltraBlame original commit: 84b90d871c2c14c24356f2840b5bbe9413a5e729
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.

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