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

10933/shorthands #12572

Merged
merged 3 commits into from Aug 17, 2016
Merged

10933/shorthands #12572

merged 3 commits into from Aug 17, 2016

Conversation

@craftytrickster
Copy link
Contributor

craftytrickster commented Jul 23, 2016

This implements the serialization of nearly all of the css shorthand properties with the following exceptions:

  1. font - this may be implemented correctly, but I am not 100% sure
  2. border-radius - I do not know how to implement this, since I am not familiar with how the property works
  3. background - this is implemented, but I think that the implementation might be a tiny bit off.

  • ./mach build -d does not report any errors
  • ./mach test-tidy does not report any errors
  • These changes fix #10933 (github issue number if applicable). Also fixes issue #11448
  • There are tests for these changes OR
  • These changes do not require tests because _____

This change is Reviewable

@highfive
Copy link

highfive commented Jul 23, 2016

Heads up! This PR modifies the following files:

  • @bholley: components/style/properties/properties.mako.rs
@highfive
Copy link

highfive commented Jul 23, 2016

warning Warning warning

  • These commits modify style code, but no tests are modified. Please consider adding a test!
@emilio
Copy link
Member

emilio commented Jul 25, 2016

Awesome work!

I think it still needs some refactoring to keep things clean, but overall the approach looks good to me. What do you think about the comments suggested below?

Thanks again for doing this! :)

-S-awaiting-review +S-needs-code-changes


Reviewed 1 of 1 files at r11.
Review status: all files reviewed at latest revision, 4 unresolved discussions, some commit checks failed.


components/style/properties/properties.mako.rs, line 462 [r11] (raw file):

                            where W: fmt::Write, I: Iterator<Item=&'a PropertyDeclaration> {
    match shorthand {
        Shorthand::Margin => try!(append_margin_shorthand(dest, declarations)),

This should probably be refactored to use a Mako loop.


components/style/properties/properties.mako.rs, line 481 [r11] (raw file):

        Shorthand::BorderTop => try!(append_border_top_shorthand(dest, declarations)),
        Shorthand::BorderRight => try!(append_border_right_shorthand(dest, declarations)),
        Shorthand::BorderBottom => try!(append_border_bottom_shorthand(dest, declarations)),

What about hoisting this to the shorthand module? That would keep things more self-contained, and we could do something like:

% for shorthand in data.shorthands:
    Shorthand::${shorthand.camel_case} => shorthands::{$shorthand.ident}::write(dest, declarations),
% endfor

Note that the write name is arbitrary, probably serialize is a better choice.


components/style/properties/properties.mako.rs, line 534 [r11] (raw file):

    for decl in declarations {
        match decl {

nit: I usually prefer matching the dereferenced value, looks cleaner:

match *decl {
    PropertyDeclaration::MarginTop(ref value) => // ...
    // ...
}

components/style/properties/properties.mako.rs, line 592 [r11] (raw file):

                   try!(single_value.to_css(dest));
               }
               else {

nit: keep the else if the same line of the rest of the closing brace: } else {.


Comments from Reviewable

@craftytrickster
Copy link
Contributor Author

craftytrickster commented Jul 26, 2016

Review status: 0 of 1 files reviewed at latest revision, 4 unresolved discussions, some commit checks failed.


components/style/properties/properties.mako.rs, line 462 [r11] (raw file):

Previously, emilio (Emilio Cobos Álvarez) wrote…

This should probably be refactored to use a Mako loop.

Done. It would appear that at some point I have to rebase from master, because two new shorthands have appeared in this mako loop (according to the travis build failure), that aren't on my current branch.

components/style/properties/properties.mako.rs, line 481 [r11] (raw file):

Previously, emilio (Emilio Cobos Álvarez) wrote…

What about hoisting this to the shorthand module? That would keep things more self-contained, and we could do something like:

% for shorthand in data.shorthands:
    Shorthand::${shorthand.camel_case} => shorthands::{$shorthand.ident}::write(dest, declarations),
% endfor

Note that the write name is arbitrary, probably serialize is a better choice.

Done.

components/style/properties/properties.mako.rs, line 534 [r11] (raw file):

Previously, emilio (Emilio Cobos Álvarez) wrote…

nit: I usually prefer matching the dereferenced value, looks cleaner:

match *decl {
    PropertyDeclaration::MarginTop(ref value) => // ...
    // ...
}
Done.

components/style/properties/properties.mako.rs, line 592 [r11] (raw file):

Previously, emilio (Emilio Cobos Álvarez) wrote…

nit: keep the else if the same line of the rest of the closing brace: } else {.

Although I personally strongly prefer the other way, I have swallowed my pride and made the change.

Comments from Reviewable

@emilio
Copy link
Member

emilio commented Jul 26, 2016

I'd strongly prefer to move these functions to its own files into their own submodules, though if for some reason you don't have enough time or something, just let me know and we could fill a followup :)


Reviewed 1 of 1 files at r12.
Review status: all files reviewed at latest revision, 2 unresolved discussions, some commit checks failed.


components/style/properties/properties.mako.rs, line 481 [r11] (raw file):

Previously, craftytrickster (David Raifaizen) wrote…

Done.

I meant hoisting the function to its own module (that is, in the `shorthand/xxx.mako.rs` file). I guess we could file a followup for this, but given you have to rebase already...

components/style/properties/properties.mako.rs, line 592 [r11] (raw file):

Previously, craftytrickster (David Raifaizen) wrote…

Although I personally strongly prefer the other way, I have swallowed my pride and made the change.

Not a big deal personally, but we try to adhere our code to the general rust convention. Actually I think test-tidy should have failed with a line starting by an `else {`.

Comments from Reviewable

@craftytrickster
Copy link
Contributor Author

craftytrickster commented Jul 26, 2016

I was just joking about the pride thing, it's not a big deal to me. I misunderstood what you meant about moving to a module, I thought you meant move it to the shorthands mod, not another file, so I will make that change as well, in addition to looking into those new shorthands that were added.

@craftytrickster craftytrickster force-pushed the craftytrickster:10933/shorthands branch from 87c9ffd to cd5ce86 Jul 28, 2016
@craftytrickster
Copy link
Contributor Author

craftytrickster commented Jul 28, 2016

Review status: all files reviewed at latest revision, 2 unresolved discussions, some commit checks failed.


components/style/properties/properties.mako.rs, line 481 [r11] (raw file):

Previously, emilio (Emilio Cobos Álvarez) wrote…

I meant hoisting the function to its own module (that is, in the shorthand/xxx.mako.rs file). I guess we could file a followup for this, but given you have to rebase already...

Done.

components/style/properties/properties.mako.rs, line 592 [r11] (raw file):

Previously, emilio (Emilio Cobos Álvarez) wrote…

Not a big deal personally, but we try to adhere our code to the general rust convention. Actually I think test-tidy should have failed with a line starting by an else {.

Done.

Comments from Reviewable

@craftytrickster
Copy link
Contributor Author

craftytrickster commented Jul 28, 2016

The Travis build is failing due to the the below "missing" shorthand, yet I just rebased the latest from master, and I was able to build without any issue, I am not sure why this shorthand only appears on the Travis build.

Should I add a _ => catchall generic serialization in the append_shorthand_value function to get around these kinds of issues? The only problem I see with doing that is that when new shorthands are added, the person adding them might not realize they have to add a custom serialization function, since the catchall will allow them to ignore it.

/home/travis/build/servo/servo/target/geckolib/debug/build/style-b398ea74b908472c/out/properties.rs:31583:26: 31583:65 error: unresolved name `serialize__moz_outline_radius_shorthand` [E0425]

/home/travis/build/servo/servo/target/geckolib/debug/build/style-b398ea74b908472c/out/properties.rs:31583                     try!(serialize__moz_outline_radius_shorthand(dest, declarations)),
@emilio
Copy link
Member

emilio commented Jul 28, 2016

I'd love to see the comment below addressed, that being said, it's not a huge deal. The problem with it as written is that it separates the code needed to add a longhand into two different places.

Also, you need to take into account geckolib (the build for it is failing now because of a gecko-only shorthand). You can conditionally add that serialization with the if product == "gecko": check, but moving everything to its own module will solve this problem for you :)

To check the geckolib build, you can use ./mach build-geckolib.

Thanks for everything, this looks great! :)

-S-awaiting-review +S-needs-code-changes


Reviewed 2 of 2 files at r24.
Review status: all files reviewed at latest revision, 1 unresolved discussion, some commit checks failed.


components/style/properties/properties.mako.rs, line 481 [r11] (raw file):

Previously, craftytrickster (David Raifaizen) wrote…

Done.

Heh, I meant to hoist that to the corresponding shorthand module, but I see it's engineered right now to declare a single function.

What would need to be done is something like changing the helpers.mako.rs file from:

pub fn parse_value(context: &ParserContext, input: &mut Parser) -> Result<Longhands, ()> {
    ${caller.body()}
}

to just:

${caller.body()}

and then change the uses of the helper to define both parse_value(..), with the current signature and contents, and serialize(..).

I'd love to see that done in this PR, but it's a bit tedious change though, so we might file a followup for it if you prefer.


Comments from Reviewable

@emilio
Copy link
Member

emilio commented Jul 28, 2016

@craftytrickster, sorry, just replied while you commented.

No, the build that is failing isn't servo's main build, it's the gecko port for servo's style system. Above is the command to build it. Let me know if you have any issues and I'll try to help :)


Review status: all files reviewed at latest revision, 1 unresolved discussion, some commit checks failed.


Comments from Reviewable

@emilio emilio assigned emilio and unassigned asajeffrey Jul 28, 2016
@craftytrickster
Copy link
Contributor Author

craftytrickster commented Jul 28, 2016

I am not sure if it is a lot of work for you, but, would it be possible for you to provide me with one concrete example of changing one of the serializations to using hoisting and the helpers.mako file? Once I see exactly what you mean, I can port the rest of the changes to follow that convention.

If it is not easy for you to do quickly, I will try to take more time to analyze what is going on in the helpers.mako file and see if I can figure it out.

Thank you once again for the help.

@emilio
Copy link
Member

emilio commented Jul 28, 2016

Oh, sure! So, given we have the change I said in the previous review comment, we should port code like:

<%helpers:shorthand name="overflow" sub_properties="overflow-x overflow-y">
    use properties::longhands::{overflow_x, overflow_y};

    let overflow = try!(overflow_x::parse(context, input));
    Ok(Longhands {
        overflow_x: Some(overflow),
        overflow_y: Some(overflow_y::SpecifiedValue(overflow)),
    })
</%helpers:shorthand>

to something like:

<%helpers:shorthand name="overflow" sub_properties="overflow-x overflow-y">
    use properties::longhands::{overflow_x, overflow_y};
    // Probably a few includes missing here.

    pub fn parse_value(context: &ParserContext, input: &mut Parser) -> Result<Longhands, ()> {
        let overflow = try!(overflow_x::parse(context, input));
        Ok(Longhands {
            overflow_x: Some(overflow),
            overflow_y: Some(overflow_y::SpecifiedValue(overflow)),
        })
    }

    pub fn serialize<'a, W, I>(dest: &mut W,
                               appendable_value: AppendableValue<'a, I>,
                               is_first_serialization: &mut bool)
                               -> fmt::Result
        where W: fmt::Write, I: Iterator<Item=&'a PropertyDeclaration>
    {
        let declarations = match appendable_value {
            AppendableValue::DeclarationsForShorthand(_, declarations) => declarations,
            _ => return Err(fmt::Error)
        };

        // snip snip...

        write!(dest, ";")
    }
</%helpers:shorthand>

Does that make sense? :)

Also, don't thank me, thank you for all the work you're doing, it's awesome! :)

@craftytrickster
Copy link
Contributor Author

craftytrickster commented Jul 28, 2016

@emilio thanks for the pointers above. When I have some free time over the next several days I will make the changes.

@craftytrickster craftytrickster force-pushed the craftytrickster:10933/shorthands branch from cd5ce86 to ff03405 Aug 1, 2016
@craftytrickster
Copy link
Contributor Author

craftytrickster commented Aug 1, 2016

Looks like it failed because I did not rebase master, the Url::parse method looks to have been changed. Should be an easy fix.

@emilio
Copy link
Member

emilio commented Aug 1, 2016

The approach looks so much cleaner now! Thanks!

I still need to do a bit more thorough review going through the spec for each property, but this looks good to me. Can you rebase so we can make a try run and see which tests need to change?

-S-awaiting-review +S-needs-rebase


Review status: 0 of 18 files reviewed at latest revision, 1 unresolved discussion, some commit checks failed.


Comments from Reviewable

@bors-servo
Copy link
Contributor

bors-servo commented Aug 17, 2016

Testing commit 3085433 with merge d1ebcd5...

bors-servo added a commit that referenced this pull request Aug 17, 2016
10933/shorthands

<!-- Please describe your changes on the following line: -->
This implements the serialization of nearly all of the css shorthand properties with the following exceptions:

1. font - this may be implemented correctly, but I am not 100% sure
2. border-radius - I do not know how to implement this, since I am not familiar with how the property works
3. background - this is implemented, but I think that the implementation might be a tiny bit off.

---
<!-- 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 fix #10933  (github issue number if applicable). Also fixes issue #11448

<!-- Either: -->
- [X] There are tests for these changes OR
- [ ] These changes do not require tests because _____

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

bors-servo commented Aug 17, 2016

💔 Test failed - mac-rel-css

@highfive
Copy link

highfive commented Aug 17, 2016

  ▶ FAIL [expected PASS] /css21_dev/html4/run-in-listitem-between-001.htm
  └   → /css21_dev/html4/run-in-listitem-between-001.htm af34c20eed63b2636b8a0a97c5c77991e2039bc1
/css21_dev/html4/reference/run-in-text-ref.htm 638e3ddce4ea49b428602b944937bb27f420bd63
Testing af34c20eed63b2636b8a0a97c5c77991e2039bc1 == 638e3ddce4ea49b428602b944937bb27f420bd63

  ▶ FAIL [expected PASS] /css21_dev/html4/run-in-listitem-between-002.htm
  └   → /css21_dev/html4/run-in-listitem-between-002.htm af34c20eed63b2636b8a0a97c5c77991e2039bc1
/css21_dev/html4/reference/run-in-text-ref.htm 638e3ddce4ea49b428602b944937bb27f420bd63
Testing af34c</span><span class="stdout">20eed63b2636b8a0a97c5c77991e2039bc1 == 638e3ddce4ea49b428602b944937bb27f420bd63
@emilio
Copy link
Member

emilio commented Aug 17, 2016

These seem intermittents, I filled #12901.

@bors-servo: retry

@bors-servo
Copy link
Contributor

bors-servo commented Aug 17, 2016

Testing commit 3085433 with merge 9d26d26...

bors-servo added a commit that referenced this pull request Aug 17, 2016
10933/shorthands

<!-- Please describe your changes on the following line: -->
This implements the serialization of nearly all of the css shorthand properties with the following exceptions:

1. font - this may be implemented correctly, but I am not 100% sure
2. border-radius - I do not know how to implement this, since I am not familiar with how the property works
3. background - this is implemented, but I think that the implementation might be a tiny bit off.

---
<!-- 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 fix #10933  (github issue number if applicable). Also fixes issue #11448

<!-- Either: -->
- [X] There are tests for these changes OR
- [ ] These changes do not require tests because _____

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

bors-servo commented Aug 17, 2016

💔 Test failed - linux-rel

@highfive
Copy link

highfive commented Aug 17, 2016

  ▶ FAIL [expected PASS] /css-flexbox-1_dev/html/flex-flexitem-percentage-prescation.htm
  └   → /css-flexbox-1_dev/html/flex-flexitem-percentage-prescation.htm 549dc2995e7de786feb6065fc8fc76b53746d920
/css-flexbox-1_dev/html/reference/flex-flexitem-percentage-prescation-ref.htm 516cbcf7b447cf7d5a568a4f8b57f030555e6525
Testing 549dc2995e7de786feb6065fc8fc76b53746d920 == 516cbcf7b447cf7d5a568a4f8b57f030555e6525

  ▶ FAIL [expected PASS] /css21_dev/html4/run-in-listitem-between-001.htm
  └   → /css21_dev/html4/run-in-listitem-between-001.htm ef608dda75ea29fbec3a0a32f64cc80292e62d82
/css21_dev/html4/reference/run-in-text-ref.htm d068883ccfce1b3fdf24f9ea6b401c9a047b593c
Testing ef608dda75ea29fbec3a0a32f64cc80292e62d82 == d068883ccfce1b3fdf24f9ea6b401c9a047b593c

  ▶ FAIL [expected PASS] /css21_dev/html4/run-in-listitem-between-002.htm
  └   → /css21_dev/html4/run-in-listitem-between-002.htm ef608dda75ea29fbec3a0a32f64cc80292e62d82
/css21_dev/html4/reference/run-in-text-ref.htm d068883ccfce1b3fdf24f9ea6b401c9a047b593c
Testing ef608dda75ea29fbec3a0a32f64cc80292e62d82 == d068883ccfce1b3fdf24f9ea6b401c9a047b593c
@craftytrickster
Copy link
Contributor Author

craftytrickster commented Aug 17, 2016

For some reason my local only passes when I remove the 3 .ini files corresponding to those failures. However, since Travis CI seems to disagree, I have added them back. Can someone please test the merge commit, hopefully it should go through now.

@emilio
Copy link
Member

emilio commented Aug 17, 2016

Oh, yeah, @shinglyu had the same problem, let's see.

@bors-servo: r+

@bors-servo
Copy link
Contributor

bors-servo commented Aug 17, 2016

📌 Commit d8c042a has been approved by emilio

@bors-servo
Copy link
Contributor

bors-servo commented Aug 17, 2016

Testing commit d8c042a with merge b61c456...

bors-servo added a commit that referenced this pull request Aug 17, 2016
10933/shorthands

<!-- Please describe your changes on the following line: -->
This implements the serialization of nearly all of the css shorthand properties with the following exceptions:

1. font - this may be implemented correctly, but I am not 100% sure
2. border-radius - I do not know how to implement this, since I am not familiar with how the property works
3. background - this is implemented, but I think that the implementation might be a tiny bit off.

---
<!-- 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 fix #10933  (github issue number if applicable). Also fixes issue #11448

<!-- Either: -->
- [X] There are tests for these changes OR
- [ ] These changes do not require tests because _____

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

bors-servo commented Aug 17, 2016

@bors-servo bors-servo merged commit d8c042a into servo:master Aug 17, 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
@craftytrickster
Copy link
Contributor Author

craftytrickster commented Aug 17, 2016

Finally!

@upsuper upsuper mentioned this pull request Feb 25, 2017
3 of 4 tasks complete
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.

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