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 wilsoniya commented Nov 12, 2017

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



This change is Reviewable

@highfive
Copy link

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

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 highfive added the S-awaiting-review There is new code that needs to be reviewed. label Nov 12, 2017
@highfive
Copy link

warning Warning warning

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

Copy link
Member

@emilio emilio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Growing Component is not really acceptable I think :(

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto.

Other(String),
}

impl <'a> From<&'a str> for Direction {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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()?;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

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 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)?;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@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 :)

Copy link
Member

@emilio emilio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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("))?;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is there a need for concat! here?

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@jdm jdm added S-needs-code-changes Changes have not yet been made that were requested by a reviewer. and removed S-awaiting-review There is new code that needs to be reviewed. labels Nov 15, 2017
@jdm jdm assigned emilio and unassigned mbrubeck Nov 15, 2017
@highfive highfive added S-awaiting-review There is new code that needs to be reviewed. and removed S-needs-code-changes Changes have not yet been made that were requested by a reviewer. labels Nov 16, 2017
@wilsoniya
Copy link
Contributor Author

@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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📌 Commit 10f3ef4 has been approved by emilio

@highfive highfive added S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. and removed S-awaiting-review There is new code that needs to be reviewed. labels Nov 21, 2017
@emilio
Copy link
Member

emilio commented Nov 21, 2017

Looks great, thanks a lot!

@bors-servo
Copy link
Contributor

⌛ Testing commit 10f3ef4 with merge 0062027...

bors-servo pushed 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

☀️ Test successful - android, arm32, arm64, linux-dev, linux-rel-css, linux-rel-wpt, mac-dev-unit, mac-rel-css1, mac-rel-css2, mac-rel-wpt1, mac-rel-wpt2, mac-rel-wpt3, mac-rel-wpt4, windows-msvc-dev
Approved by: emilio
Pushing 0062027 to master...

@bors-servo bors-servo merged commit 10f3ef4 into servo:master Nov 21, 2017
@highfive highfive removed the S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. label Nov 21, 2017
bors-servo pushed 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 issue-16840 branch November 23, 2017 16:21
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
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Parse :dir into an enum with two values (ltr/rtl) as opposed to a string for the argument
6 participants