Skip to content

style: Move contain outside of mako - #19682

Merged
bors-servo merged 1 commit into
servo:masterfrom
stevel98:moveContain
Jan 4, 2018
Merged

bors-servo merged 1 commit into
servo:masterfrom
stevel98:moveContain

Conversation

@stevel98

@stevel98 stevel98 commented Jan 4, 2018 •

Copy link
Copy Markdown
Contributor

Sub-PR for #19015.

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

This change is Reviewable

@highfive

highfive commented Jan 4, 2018

Copy link
Copy Markdown

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

@highfive

highfive commented Jan 4, 2018

Copy link
Copy Markdown

Heads up! This PR modifies the following files:

  • @bholley: components/style/values/specified/box.rs, components/style/properties/longhand/box.mako.rs, components/style/values/computed/box.rs, components/style/values/specified/mod.rs, components/style/values/computed/mod.rs
  • @canaltinova: components/style/values/specified/box.rs, components/style/properties/longhand/box.mako.rs, components/style/values/computed/box.rs, components/style/values/specified/mod.rs, components/style/values/computed/mod.rs
  • @emilio: components/style/values/specified/box.rs, components/style/properties/longhand/box.mako.rs, components/style/values/computed/box.rs, components/style/values/specified/mod.rs, components/style/values/computed/mod.rs

@highfive

highfive commented Jan 4, 2018

Copy link
Copy Markdown

warning Warning warning

  • These commits modify style code, but no tests are modified. Please consider adding a test!

@highfive highfive added the S-awaiting-review There is new code that needs to be reviewed. label Jan 4, 2018

@emilio emilio left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks great! Just minor nits and suggestions, other than that, r=me

Thanks a lot for doing this!


impl Parse for Contain {
/// none | strict | content | [ size || layout || style || paint ]
fn parse<'i, 't>(_context: &ParserContext, input: &mut Parser<'i, 't>)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: Indentation is off, let's do:

fn parse<'i, 't>(
    _context: &ParserContext,
    input: &mut Parser<'i, 't>,
) -> Result<Contain, ParseError<'i>> {

};
let flag = match flag {
Some(flag) if !result.contains(flag) => flag,
_ => return Err(input.new_custom_error(SelectorParseErrorKind::UnexpectedIdent(name.clone())))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm 99% sure this clone() call is not necessary.

/// none | strict | content | [ size || layout || style || paint ]
fn parse<'i, 't>(_context: &ParserContext, input: &mut Parser<'i, 't>)
-> Result<Contain, ParseError<'i>> {
let mut result = Contain::empty();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This function is kinda dumb, and could be rewritten to be faster / clearer. Can you file a followup for it?

In particular, I'm thinking of something like:

let mut result = Contain::empty();
while let Ok(name) = input.try(|i| i.expect_ident_cloned()) {
    match_ignore_ascii_case! { &name,
        "layout" => Some(Contain::LAYOUT),
        "style" => Some(Contain::STYLE),
        "paint" => Some(Contain::PAINT),
        // The following are only valid as the first value, thus the is_empty()
        // checks.
        "strict" => {
            if result.is_empty() {
                return Ok(Contain::STRICT | Contain::STRICT_BITS)
            }
            None
        }
        "none" => {
            if result.is_empty() {
                return Ok(result);
            }
            None
        }
        _ => None
    };

    // Same code as now.
}

Also fine to do it in a separate commit in this same PR.

That avoids having to tokenize twice for none and strict just to tokenize an identifier again below.

@stevel98 stevel98 Jan 4, 2018 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the feedback, I will file a followup commit soon.

}
if input.try(|input| input.expect_ident_matching("strict")).is_ok() {
result.insert(Contain::STRICT | Contain::STRICT_BITS);
return Ok(result)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: just return Ok(Contain::STRICT | Contain::STRICT_BITS) may be cleaner?

const PAINT = 0x04;
/// `strict` variant, turns on all types of containment
const STRICT = 0x8;
/// `strict bits` variant

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Just /// variant with all the bits that contain: strict turns on?

@stevel98

stevel98 commented Jan 4, 2018

Copy link
Copy Markdown
Contributor Author

I just pushed the changes, let me know if there need to be any more!

"style" => Some(Contain::STYLE),
"paint" => Some(Contain::PAINT),
"strict" if result.is_empty() => return Ok(Contain::STRICT | Contain::STRICT_BITS),
"none" if result.is_empty() => return Ok(result),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think you'll need to check if result.is_empty() inside the pattern instead of using it as a pattern matching guard. If putting if result.is_empty() as guard here, I think it will only get into the strict one?

IMO, just like @emilio commented in the comment, it might be fine to be like following

"strict" => {
    if result.is_empty() {
        return Ok(Contain::STRICT | Contain::STRICT_BITS)
     }
     None
},
"none" => {
    if result.is_empty() {
        return Ok(result);
    }
    None
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks, I changed it back to the previous version. I don't really understand why it won't get into the none arm though; how would rust evaluate the guard?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

FWIW the guard should work just fine, and it's more elegant indeed.

Wanna open a PR after this one merges simplifying it? Thanks!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Sure, I'd be glad to, assuming this one passes the tests.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ahhh... yes... sorry, I think it in a wrong way so using guard here should work fine.
Sorry for the misleading 😣

@CYBAI

CYBAI commented Jan 4, 2018

Copy link
Copy Markdown
Member

Besides, I think it would be great to squash the two commits into one 😀

@stevel98

stevel98 commented Jan 4, 2018

Copy link
Copy Markdown
Contributor Author

I'm not sure why this test failed after such a small change. Could someone please re-run it?

@CYBAI

CYBAI commented Jan 4, 2018

Copy link
Copy Markdown
Member

@stevel98 I think you can try to commit --amend and push -f to force Travis to re-run :)

@stevel98

stevel98 commented Jan 4, 2018

Copy link
Copy Markdown
Contributor Author

Thanks!

@emilio emilio left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM, thanks a lot!

@emilio

emilio commented Jan 4, 2018

Copy link
Copy Markdown
Member

@bors-servo r+

@bors-servo

Copy link
Copy Markdown
Contributor

📌 Commit 4c23f09 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 Jan 4, 2018
@bors-servo

Copy link
Copy Markdown
Contributor

⌛ Testing commit 4c23f09 with merge a25c526...

bors-servo pushed a commit that referenced this pull request Jan 4, 2018
style: Move contain outside of mako

<!-- Please describe your changes on the following line: -->
Sub-PR for #19015.
---
<!-- 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 #19656 (github issue number if applicable).

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

<!-- 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/19682)
<!-- Reviewable:end -->
@bors-servo

Copy link
Copy Markdown
Contributor

💔 Test failed - mac-dev-unit

@highfive highfive added S-tests-failed The changes caused existing tests to fail. and removed S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. labels Jan 4, 2018
@emilio

emilio commented Jan 4, 2018

Copy link
Copy Markdown
Member

@bors-servo retry

@bors-servo

Copy link
Copy Markdown
Contributor

⌛ Testing commit 4c23f09 with merge 7a9f99e...

bors-servo pushed a commit that referenced this pull request Jan 4, 2018
style: Move contain outside of mako

<!-- Please describe your changes on the following line: -->
Sub-PR for #19015.
---
<!-- 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 #19656 (github issue number if applicable).

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

<!-- 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/19682)
<!-- Reviewable:end -->
@highfive highfive added S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. and removed S-tests-failed The changes caused existing tests to fail. labels Jan 4, 2018
@bors-servo

Copy link
Copy Markdown
Contributor

💔 Test failed - mac-dev-unit

@highfive highfive added S-tests-failed The changes caused existing tests to fail. and removed S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. labels Jan 4, 2018
@emilio

emilio commented Jan 4, 2018 •

Copy link
Copy Markdown
Member

@bors-servo retry

  • Intermittent gecko-media failure.

@bors-servo

Copy link
Copy Markdown
Contributor

⚡ Previous build results for android, arm32, arm64, linux-dev, linux-rel-css, linux-rel-wpt, mac-rel-wpt1, mac-rel-wpt3, windows-msvc-dev are reusable. Rebuilding only mac-dev-unit, mac-rel-css1, mac-rel-css2, mac-rel-wpt2, mac-rel-wpt4...

@bors-servo

Copy link
Copy Markdown
Contributor

⚡ Previous build results for android, arm32, arm64, linux-dev, linux-rel-css, linux-rel-wpt, mac-rel-wpt1, mac-rel-wpt3, windows-msvc-dev are reusable. Rebuilding only mac-dev-unit, mac-rel-css1, mac-rel-css2, mac-rel-wpt2, mac-rel-wpt4...

@bors-servo

Copy link
Copy Markdown
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 7a9f99e to master...

@bors-servo
bors-servo merged commit 4c23f09 into servo:master Jan 4, 2018
@stevel98
stevel98 deleted the moveContain branch January 4, 2018 21:15
@stevel98 stevel98 mentioned this pull request Jan 4, 2018
4 of 5 tasks
bors-servo pushed a commit that referenced this pull request Jan 5, 2018
style: Make Contain::parse simpler

<!-- Please describe your changes on the following line: -->
---
Makes Contain::parse slightly simpler, as discussed in #19682

- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [X] These changes fix #19682 (github issue number if applicable).

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

<!-- 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/19692)
<!-- Reviewable:end -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-tests-failed The changes caused existing tests to fail.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Move contain outside of mako.

5 participants