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

Some fixes to selector serialization re: namespaces and universal selector #17537

Merged
merged 3 commits into from Jul 18, 2017

Conversation

jyc
Copy link
Contributor

@jyc jyc commented Jun 27, 2017

  • Fix eliding default namespace when serializing
  • Fix shortest serialization property when namespace prefix is *| and there is no default namespace
  • Omit universal selector when serializing to match cssom/serialize-namespaced-type-selectors (again so we get the shortest serialization)

I'd like to land #17501 first, because it allows some tests for this to work.

  • There are tests for these changes OR
  • These changes do not require tests because _____

This change is Reviewable

@highfive highfive added the S-awaiting-review There is new code that needs to be reviewed. label Jun 27, 2017
@emilio
Copy link
Member

emilio commented Jun 29, 2017

@bors-servo try

@jyc this looks good to me, is this waiting for anything in particular? Does it have tests?

@bors-servo
Copy link
Contributor

⌛ Trying commit eaa1d40 with merge 9e0d601178f6b39d92c9a71bf94b26c592f6c31b...

@bors-servo
Copy link
Contributor

💔 Test failed - mac-rel-wpt1

@highfive highfive added the S-tests-failed The changes caused existing tests to fail. label Jun 29, 2017
@jyc
Copy link
Contributor Author

jyc commented Jun 29, 2017

Hi @emilio! Thanks, sorry for not being clear; was planning to run it to see what tests changed. It looks like it failed due to something in the infrastructure--

@bors-servo retry

@bors-servo
Copy link
Contributor

⌛ Trying commit eaa1d40 with merge 5b7fc90...

bors-servo pushed a commit that referenced this pull request Jun 29, 2017
[WIP] Replace Namespace components which map to the default namespace with DefaultNamespace

It seems we don't need to preserve the original prefix name, and this
conveniently leads to_css to now implement CSSOM's requirement to elide
the namespace prefix during serialization when it maps to the default
namespace.

https://drafts.csswg.org/cssom/#serialize-a-simple-selector

<!-- 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
- [X] These changes is part of a series to fix #17182

<!-- Either: -->
I am running this to identify what tests will fail; as the other PRs in the series are merged, I believe the tests that pass will change as well.

- [ ] There are tests for these changes OR
- [ ] These changes do not require tests because _____

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

@jyc jyc mentioned this pull request Jul 6, 2017
5 tasks
@jyc
Copy link
Contributor Author

jyc commented Jul 12, 2017

@bors-servo: retry
now that #17501 is merged

EDIT: oops, misread. it's not merged!

@jyc jyc changed the title [WIP] Replace Namespace components which map to the default namespace with DefaultNamespace Replace Namespace components which map to the default namespace with DefaultNamespace Jul 12, 2017
@jdm jdm added the S-blocked-on-external Something, somewhere else, needs to happen before this PR can be merged. label Jul 12, 2017
@highfive highfive removed the S-tests-failed The changes caused existing tests to fail. label Jul 13, 2017
@jdm
Copy link
Member

jdm commented Jul 13, 2017

     Running /home/travis/build/servo/servo/target/debug/deps/selectors-a25afd58e67e341d

running 11 tests

test parser::tests::test_empty ... ok

test parser::tests::test_empty_pseudo_iter ... ok

test parser::tests::test_pseudo_iter ... ok

test bloom::create_and_insert_some_stuff ... ok

test size_of_tests::size_of_component ... ok

test size_of_tests::size_of_pseudo_class ... ok

test size_of_tests::size_of_pseudo_element ... ok

test size_of_tests::size_of_selector ... ok

test parser::tests::visitor ... ok

test parser::tests::test_parsing ... FAILED

test parser::tests::test_universal ... FAILED

@jdm jdm added the S-tests-failed The changes caused existing tests to fail. label Jul 13, 2017
@jyc jyc force-pushed the default-namespace-serialization branch from 914f7c8 to 3677587 Compare July 14, 2017 19:18
@highfive highfive removed the S-tests-failed The changes caused existing tests to fail. label Jul 14, 2017
…DefaultNamespace.

It seems we don't need to preserve the original prefix name, and this
conveniently leads to_css to now implement CSSOM's requirement to elide
the namespace prefix during serialization when it maps to the default
namespace.

https://drafts.csswg.org/cssom/#serialize-a-simple-selector
@jyc
Copy link
Contributor Author

jyc commented Jul 14, 2017

The tests used a parser with no default namespace but asserted that *| should be preserved in the output, which is contrary to the tests in serialize-namespaced-type-selectors.htm. Fixed those (and added tests for when there is a default namespace), and fixing the merge conflict now.

@jyc jyc force-pushed the default-namespace-serialization branch from 3677587 to 4269ce3 Compare July 14, 2017 19:40
@jyc
Copy link
Contributor Author

jyc commented Jul 14, 2017

@bors-servo: retry

@jyc
Copy link
Contributor Author

jyc commented Jul 14, 2017

@bors-servo: try

@bors-servo
Copy link
Contributor

⌛ Trying commit 4269ce3 with merge c098745...

bors-servo pushed a commit that referenced this pull request Jul 14, 2017
Replace Namespace components which map to the default namespace with DefaultNamespace

- Fix eliding default namespace when serializing
- Fix shortest serialization property when namespace prefix is `*|` and there is no default namespace

<!-- 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
- [X] These changes is part of a series to fix #17182

<!-- Either: -->

I'd like to land #17501 first, because it allows some tests for this to work.

- [ ] There are tests for these changes OR
- [ ] These changes do not require tests because _____

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

💔 Test failed - mac-rel-wpt1

@highfive highfive added the S-tests-failed The changes caused existing tests to fail. label Jul 14, 2017
bors-servo pushed a commit that referenced this pull request Jul 17, 2017
Some fixes to selector serialization re: namespaces and universal selector

- Fix eliding default namespace when serializing
- Fix shortest serialization property when namespace prefix is `*|` and there is no default namespace
- Omit universal selector when serializing to match `cssom/serialize-namespaced-type-selectors` (again so we get the shortest serialization)

<!-- 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
- [X] These changes is part of a series to fix #17182

<!-- Either: -->

I'd like to land #17501 first, because it allows some tests for this to work.

- [ ] There are tests for these changes OR
- [ ] These changes do not require tests because _____

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

@jyc
Copy link
Contributor Author

jyc commented Jul 17, 2017

Problem was the fake combinators we have for pseudo element selectors. Should be good now!

@bors-servo r?emilio

@KiChjang
Copy link
Contributor

r? @emilio

@highfive highfive assigned emilio and unassigned KiChjang Jul 17, 2017
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 good! Mostly nits.

Also maybe @SimonSapin wants to take a look.

for item in compound.iter() {
item.to_css(dest)?;

// https://www.w3.org/TR/cssom-1/#serializing-selectors
Copy link
Member

Choose a reason for hiding this comment

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

nit: We usually link to drafts.csswg.org.

//
// If we are in this case, we continue to the next iteration of the
// `for compound in compound_selectors` loop.
let namespace = if compound.len() > 0 {
Copy link
Member

Choose a reason for hiding this comment

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

nit: if !compound.is_empty().

// If we are in this case, we continue to the next iteration of the
// `for compound in compound_selectors` loop.
let namespace = if compound.len() > 0 {
let (namespace, first_non_namespace) = match &compound[0] {
Copy link
Member

Choose a reason for hiding this comment

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

nit: Why the reference? I think it'd be clearer to do:

let has_namespace = matches!(compound[0], Component::ExplicitAnyNamespace | ...);

And derive the rest from that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hm, I think it is clearer to keep the logic as close to where it is used as possible. Also, we don't quite want has_namespace, I think we instead want something like can_elide_namespace. Going to include proposed change, though.

// in cssom/serialize-namespaced-type-selectors.html, which the
// following code tries to match.
for simple in compound.iter() {
if let &Component::ExplicitUniversalType = simple {
Copy link
Member

Choose a reason for hiding this comment

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

nit: we usually do:

if let Component::ExplicitUniversalType = *simple {

or,

if matches!(*simple, Component::ExplicitUniversalType) {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Didn't know about the matches! macro, thanks!

// compound selector, so we don't have to worry about the
// real namespace being in a different `compound`.
match namespace {
Some(&Component::DefaultNamespace(_)) | None => continue,
Copy link
Member

Choose a reason for hiding this comment

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

nit: You can also use matches! here if you prefer, and avoid the _ => () thing.

input: &'i str,
parser: &DummyParser,
expected: Option<&'a str>
) -> Result<SelectorList<DummySelectorImpl>, ParseError<'i, SelectorParseError<'i, ()>>>
Copy link
Member

Choose a reason for hiding this comment

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

nit: I think the brace should be in the previous line per https://github.com/rust-lang-nursery/fmt-rfcs

@@ -2060,7 +2211,10 @@ pub mod tests {

#[test]
fn test_universal() {
let selector = &parse("*|*::before").unwrap().0[0];
let selector = &parse_ns("*|*::before", &DummyParser {
default_ns: Some(DummyAtom::from("https://mozilla.org")),
Copy link
Member

Choose a reason for hiding this comment

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

nit: Maybe having a DummyParser::default() or something like that would be nice, to avoid some duplication here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea!

Copy link
Member

@SimonSapin SimonSapin left a comment

Choose a reason for hiding this comment

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

Looks fine to me, with @emilio’s comment addressed.

fn parse<'i>(input: &'i str) -> Result<SelectorList<DummySelectorImpl>,
ParseError<'i, SelectorParseError<'i, ()>>> {
fn parse<'i>(input: &'i str)
-> Result<SelectorList<DummySelectorImpl>, ParseError<'i, SelectorParseError<'i, ()>>>
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 change this now, but next time you’d like to make whitespace-only changes please make them in a separate commit.

jyc added 2 commits July 17, 2017 10:43
Once again it seems we don't need to preserve the original prefix name,
and this lets to_css serialize to the shortest form when there is no
default namespace and the *| prefix is used.

Selectors § 6.1.1 says:

    Element type selectors that have no namespace component (no namespace
    separator) represent elements without regard to the element's namespace
    (equivalent to "*|") unless a default namespace has been declared for
    namespaced selectors (e.g. in CSS, in the style sheet). If a default
    namespace has been declared, such selectors will represent only elements
    in the default namespace.

Then if there is no default namespace, *| (which we write as
QNamePrefix::ExplicitAnyNamespace) is equivalent to what we write as
QNamePrefix::ImplicitAnyNamespace; the latter has a shorter
serialization, so we should use that.
If omitting the universal selector in the serialization is possible, we
should do it so we obtain a shorter serialization (to match the behavior
asserted in cssom/serialize-namespaced-type-selectors.html).

For example, if someone writes *|*::before and there is no default
namespace, we should serialize to ::before; however, if there is a
default namespace, we should serialize to *|*::before.
(This is the test case "Universal selector in any namespace followed by
pseudo element).

This matches the behavior implemented by WebKit; that one case in
particular isn't implemented by Gecko, but other cases where the
universal selector should be elided are implemented by Gecko but were not
previously by Servo.
@jyc jyc force-pushed the default-namespace-serialization branch from b19434b to 1301bcd Compare July 17, 2017 17:55
@jyc
Copy link
Contributor Author

jyc commented Jul 17, 2017

@bors-servo: try

@bors-servo
Copy link
Contributor

⌛ Trying commit 1301bcd with merge c157029...

bors-servo pushed a commit that referenced this pull request Jul 17, 2017
Some fixes to selector serialization re: namespaces and universal selector

- Fix eliding default namespace when serializing
- Fix shortest serialization property when namespace prefix is `*|` and there is no default namespace
- Omit universal selector when serializing to match `cssom/serialize-namespaced-type-selectors` (again so we get the shortest serialization)

<!-- 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
- [X] These changes is part of a series to fix #17182

<!-- Either: -->

I'd like to land #17501 first, because it allows some tests for this to work.

- [ ] There are tests for these changes OR
- [ ] These changes do not require tests because _____

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

💔 Test failed - linux-rel-wpt

@highfive highfive added the S-tests-failed The changes caused existing tests to fail. label Jul 17, 2017
@jyc
Copy link
Contributor Author

jyc commented Jul 17, 2017

@bors-servo retry

@bors-servo
Copy link
Contributor

⌛ Trying commit 1301bcd with merge 2320d59...

bors-servo pushed a commit that referenced this pull request Jul 17, 2017
Some fixes to selector serialization re: namespaces and universal selector

- Fix eliding default namespace when serializing
- Fix shortest serialization property when namespace prefix is `*|` and there is no default namespace
- Omit universal selector when serializing to match `cssom/serialize-namespaced-type-selectors` (again so we get the shortest serialization)

<!-- 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
- [X] These changes is part of a series to fix #17182

<!-- Either: -->

I'd like to land #17501 first, because it allows some tests for this to work.

- [ ] There are tests for these changes OR
- [ ] These changes do not require tests because _____

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

@emilio
Copy link
Member

emilio commented Jul 17, 2017

@bors-servo r+

Awesome, thanks!

@bors-servo
Copy link
Contributor

📌 Commit 1301bcd 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. S-tests-failed The changes caused existing tests to fail. labels Jul 17, 2017
@bors-servo
Copy link
Contributor

⌛ Testing commit 1301bcd with merge 97023f1...

bors-servo pushed a commit that referenced this pull request Jul 17, 2017
Some fixes to selector serialization re: namespaces and universal selector

- Fix eliding default namespace when serializing
- Fix shortest serialization property when namespace prefix is `*|` and there is no default namespace
- Omit universal selector when serializing to match `cssom/serialize-namespaced-type-selectors` (again so we get the shortest serialization)

<!-- 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
- [X] These changes is part of a series to fix #17182

<!-- Either: -->

I'd like to land #17501 first, because it allows some tests for this to work.

- [ ] There are tests for these changes OR
- [ ] These changes do not require tests because _____

<!-- 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/17537)
<!-- 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 97023f1 to master...

@bors-servo bors-servo merged commit 1301bcd into servo:master Jul 18, 2017
@highfive highfive removed the S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. label Jul 18, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-blocked-on-external Something, somewhere else, needs to happen before this PR can be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Simplify an+b when serializing
7 participants