Skip to content

style: moved css longhand counter-reset out of mako - #19529

Merged
bors-servo merged 1 commit into
servo:masterfrom
DonatJR:counter-reset-out-of-mako
Feb 1, 2018
Merged

bors-servo merged 1 commit into
servo:masterfrom
DonatJR:counter-reset-out-of-mako

Conversation

@DonatJR

@DonatJR DonatJR commented Dec 8, 2017 •

Copy link
Copy Markdown
Contributor

This is a sub-PR of #19015
Code does not yet compile with build-geckolib.
r? emilio


  • These changes do not require tests

This change is Reviewable

@highfive

highfive commented Dec 8, 2017

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 Dec 8, 2017

Copy link
Copy Markdown

Heads up! This PR modifies the following files:

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

@highfive highfive added the S-awaiting-review There is new code that needs to be reviewed. label Dec 8, 2017
@highfive

highfive commented Dec 8, 2017

Copy link
Copy Markdown

warning Warning warning

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

@emilio

emilio commented Dec 8, 2017

Copy link
Copy Markdown
Member

Ok, so... First of all, nice work!

Here's the fix for the errors you're getting:

Details
diff --git a/components/style/properties/gecko.mako.rs b/components/style/properties/gecko.mako.rs
index 08516ed928..f0f4e60ae0 100644
--- a/components/style/properties/gecko.mako.rs
+++ b/components/style/properties/gecko.mako.rs
@@ -5691,7 +5691,7 @@ clip-path
     }
 
     % for counter_property in ["Increment", "Reset"]:
-        pub fn set_counter_${counter_property.lower()}(&mut self, v: longhands::counter_increment::computed_value::T) {
+        pub fn set_counter_${counter_property.lower()}(&mut self, v: longhands::counter_${counter_property.lower()}::computed_value::T) {
             unsafe {
                 bindings::Gecko_ClearAndResizeCounter${counter_property}s(&mut self.gecko,
                                                                       v.0.len() as u32);
@@ -5712,11 +5712,11 @@ clip-path
             self.copy_counter_${counter_property.lower()}_from(other)
         }
 
-        pub fn clone_counter_${counter_property.lower()}(&self) -> longhands::counter_increment::computed_value::T {
+        pub fn clone_counter_${counter_property.lower()}(&self) -> longhands::counter_${counter_property.lower()}::computed_value::T {
             use values::CustomIdent;
             use gecko_string_cache::Atom;
 
-            longhands::counter_increment::computed_value::T(
+            longhands::counter_${counter_property.lower()}::computed_value::T(
                 self.gecko.m${counter_property}s.iter().map(|ref gecko_counter| {
                     (CustomIdent(Atom::from(gecko_counter.mCounter.to_string())), gecko_counter.mValue)
                 }).collect()

There was some code assuming that the types for counter-reset and counter-increment were the same, so that needs to be fixed too.

@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.

Nice start!

This does add a lot of code, any chance we can also move counter-increment at the same time to deduplicate it? (Maybe renaming it to CounterIntegerList or something like that?)

Once that's done, this is ok to land. It'd be even nicer to add something to the generics module, and do something like:

struct CounterIntegerList<Integer>(Vec<(CustomIdent, Integer)>);

Then in computed and specified, you just need to specify computed::Integer or specified::Integer as you please.

That should allow you to not duplicate the ToCss implementation, and to avoid writing ToComputedValue too, I think.

Anyway, that can be a followup.

Nice start, thanks for the patch!

/// A specified value for the `counter-reset` property.
#[cfg_attr(feature = "gecko", derive(MallocSizeOf))]
#[derive(Clone, Debug, PartialEq)]
pub struct CounterReset(pub Vec<(CustomIdent, super::Integer)>);

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: No need to use super::Integer, just use Integer, since you're importing it too.

pub struct CounterReset(pub Vec<(CustomIdent, super::Integer)>);

impl Parse for CounterReset {
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 here looks odd, let's do:

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

return Ok(CounterReset(Vec::new()))
}

let mut counters: Vec<(CustomIdent, super::Integer)> = Vec::new();

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.

similarly, no need for super::.

}
}

impl ToComputedValue for CounterReset {

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.

Let's move ToComputedValue to the computed module.

@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 Dec 8, 2017
@DonatJR

DonatJR commented Dec 9, 2017

Copy link
Copy Markdown
Contributor Author

Thank you for the feedback! I will implement your proposed changes as soon as I have a little more time on my hands. :)

@DonatJR

DonatJR commented Dec 11, 2017

Copy link
Copy Markdown
Contributor Author

Hey, I have now moved counter-increment as well and created the generic type. Specified values are now declared as

type CounterIncrement = CounterIntegerList<Integer>;
type CounterReset = CounterIntegerList<Integer>

(computed values respectively with i32).

The issue I'm having right now is that both CounterIncrement and CounterReset implement the Parse trait differently in the original mako code (they have a different default values if parsing failes, 1 for CounterIncrement and 0 for CounterReset).
I'm not sure what the best (read: Rust-y) way to provide this default value to the two structs would be, since they are the same type. In other languages I would probably make two derived types and I'm still a little stuck with thinking in classes and with inheritance.

Can you give me some hint how to best achieve this? Thanks!

@emilio

emilio commented Jan 4, 2018 •

Copy link
Copy Markdown
Member

Hey, sorry for the huge lag, I missed that comment :(.

You would wrap the type in a newtype and implement parse for that type, like:

pub struct CounterIncrement(CounterIntegerList<Integer>);
impl Parse for CounterIncrement {
    fn parse(..) -> .. {
         Ok(CounterIncrement(CounterIntegerList::parse_with_default(1)?))
    }
}

// .. 

@emilio

emilio commented Jan 4, 2018

Copy link
Copy Markdown
Member

(Or something of the sort).

Thanks a lot again @DonatJR, and sorry again for the huge lag. If you're busy or whatever feel free to push your changes without that and I can finish it up.

@DonatJR

DonatJR commented Jan 4, 2018

Copy link
Copy Markdown
Contributor Author

@emilio No worries and thanks for the tip, I will probably get to it in the next few days. :)

@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 Jan 30, 2018
@DonatJR

DonatJR commented Jan 30, 2018

Copy link
Copy Markdown
Contributor Author

hey @emilio sorry this took so long, I implemented the two properties by wrapping the generic type like you suggested, unfortunately this required me to add and change a few lines / files more than previously

@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.

Over all looks good, thank you!

I need to maybe take a closer look tomorrow, but there are some nits I'd rather point out now.

Thank you!


/// Returns a clone of the values of the CounterIntegerList object.
pub fn get_values(&self) -> Vec<(CustomIdent, I)> where I: Copy {
self.0.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.

Let's make this return a reference, please, instead of a vector by value, which implies allocating and copying

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.

Hmm, and actually, I wonder if there are a few places (like in gecko.mako.rs, where we'd benefit / need from take_values().

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.

I don't think it is needed (at least I got the geckolib to build without it), but I'm not sure about there being a benefit at some point...

pub struct CounterIncrement<Integer>(Box<[(CustomIdent, Integer)]);
/// Keyword `none` is represented by an empty vector.
#[derive(Clone, Debug, MallocSizeOf, PartialEq)]
pub struct CounterIntegerList<I>(Vec<(CustomIdent, I)>);

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 was a Box<[]> very intentionally, to save a word of memory.

use values::CustomIdent;

/// A generic value for the `counter-increment` property.
// use values::computed::{Context, CounterReset as ComputedValue, ToComputedValue};

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: Needs need to go away


impl ToCss for CounterReset {
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
where W: fmt::Write,

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 looks off here.

@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 good! Just noticed we can clean it up a bit more to avoid duplication.

}
}

impl ToCss for CounterIncrement {

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 can be derived.

type ComputedValue = CounterIncrement;

fn to_computed_value(&self, context: &Context) -> Self::ComputedValue {
CounterIncrement::new(self.get_values().iter().map(|&(ref name, ref value)| {

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 doesn't need to do this, instead, let's use self.0.to_computed_value() and derive(ToComputedValue).

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 CounterIntegerList already implements ToComputedValue, so you'd only need to call it here).

pub struct CounterReset(ComputedIntegerList);

impl ToCss for CounterReset {
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::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.

This can also be derived.


fn to_computed_value(&self, context: &Context) -> Self::ComputedValue {
CounterReset::new(self.get_values().iter().map(|&(ref name, ref value)| {
(name.clone(), value.to_computed_value(context))

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 needs the same change as CounterIncrement.

}
}

impl ToCss for CounterIncrement {

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 can be derived.

}
}

impl ToCss for CounterReset {

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.

So is this.

@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, thank you! mind squashing your commits?

@DonatJR

DonatJR commented Feb 1, 2018

Copy link
Copy Markdown
Contributor Author

not at all, go ahead! and thanks again for all the great feedback

@emilio

emilio commented Feb 1, 2018

Copy link
Copy Markdown
Member

Since this ended up being somewhat non-trivial, just for sanity I pushed a Gecko try run: https://treeherder.mozilla.org/#/jobs?repo=try&revision=3da82ff05b6c418a530524910aaa0957011284a0

Assuming everything is green there we can go ahead and merge this. Thanks a lot again!

@emilio emilio changed the title WIP: moved css longhand counter-reset out of mako style: moved css longhand counter-reset out of mako Feb 1, 2018
@emilio
emilio force-pushed the counter-reset-out-of-mako branch from f02fc0f to d24301b Compare February 1, 2018 14:43
@emilio

emilio commented Feb 1, 2018

Copy link
Copy Markdown
Member

Looks green!

@bors-servo r+

@bors-servo

Copy link
Copy Markdown
Contributor

📌 Commit d24301b 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 Feb 1, 2018
@bors-servo

Copy link
Copy Markdown
Contributor

⌛ Testing commit d24301b with merge 38ef515...

bors-servo pushed a commit that referenced this pull request Feb 1, 2018
style: moved css longhand counter-reset out of mako

<!-- Please describe your changes on the following line: -->
This is a sub-PR of #19015
Code does not yet compile with `build-geckolib`.
r? emilio

---
<!-- 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 #19387

<!-- Either: -->
- [x] These changes do not require tests

<!-- 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/19529)
<!-- Reviewable:end -->
@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 38ef515 to master...

@bors-servo
bors-servo merged commit d24301b into servo:master Feb 1, 2018
@highfive highfive removed the S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. label Feb 1, 2018
@emilio emilio mentioned this pull request Feb 3, 2018
48 of 49 tasks
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.

Move counter-reset outside of mako

5 participants