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

Move overflow-y outside of Mako #19183

Closed
PeterZhizhin opened this issue Nov 10, 2017 · 31 comments
Closed

Move overflow-y outside of Mako #19183

PeterZhizhin opened this issue Nov 10, 2017 · 31 comments
Labels

Comments

@PeterZhizhin
Copy link
Contributor

@PeterZhizhin PeterZhizhin commented Nov 10, 2017

I think that this should be an easy property to start with. This is a sub issue of #19015.

@jdm jdm added the A-content/css label Nov 10, 2017
@emilio emilio mentioned this issue Nov 11, 2017
48 of 49 tasks complete
@olmanz
Copy link
Contributor

@olmanz olmanz commented Nov 21, 2017

@jdm
If it's OK for you, I can try this one.

@KiChjang
Copy link
Member

@KiChjang KiChjang commented Nov 21, 2017

@olmanz I believe @PeterZhizhin is already working on this.

@emilio
Copy link
Member

@emilio emilio commented Nov 21, 2017

Yeah, note that this one is actually extra-tricky.

@KiChjang
Copy link
Member

@KiChjang KiChjang commented Nov 22, 2017

@PeterZhizhin Do you need any help? Any questions?

@KiChjang KiChjang added the E-easy label Nov 29, 2017
@highfive
Copy link

@highfive highfive commented Nov 29, 2017

Hi! If you have any questions regarding this issue, feel free to make a comment here, or ask it in the #servo channel in IRC.

If you intend to work on this issue, then add @highfive: assign me to your comment, and I'll assign this to you. 😄

@KiChjang
Copy link
Member

@KiChjang KiChjang commented Nov 29, 2017

Unassigning due to lack of response. This issue is now open for anyone to work on!

@olmanz
Copy link
Contributor

@olmanz olmanz commented Nov 29, 2017

@highfive: assign me

@highfive
Copy link

@highfive highfive commented Nov 29, 2017

Hey @olmanz! Thanks for your interest in working on this issue. It's now assigned to you!

@highfive highfive added the C-assigned label Nov 29, 2017
@olmanz
Copy link
Contributor

@olmanz olmanz commented Nov 30, 2017

@KiChjang @emilio
I already moved some stuff outside of Mako, as you can see in this commit on my fork:
olmanz@6f0e69f

However, I currently get this message when I build servo with ./mach build --dev:

   Compiling style v0.0.1 (file:///home/olmanz/Schreibtisch/workspaces/Rust/servo/components/style)
error[E0061]: this function takes 1 parameter but 2 parameters were supplied
    --> /home/olmanz/Schreibtisch/workspaces/Rust/servo/target/debug/build/style-fe2cedc35103ef47/out/properties.rs:7826:40
     |
7826 |               specified::Overflow::parse(context, input)
     |                                          ^^^^^^^^^^^^^^ expected 1 parameter
     | 
    ::: components/style/values/specified/box.rs
     |
128  | / define_css_keyword_enum! { Overflow:
129  | |     "visible" => Visible,
130  | |     "hidden" => Hidden,
131  | |     "scroll" => Scroll,
132  | |     "auto" => Auto,
133  | | }
     | |_- defined here
     |
     = note: this error originates in a macro outside of the current crate

error[E0061]: this function takes 1 parameter but 2 parameters were supplied
    --> /home/olmanz/Schreibtisch/workspaces/Rust/servo/target/debug/build/style-fe2cedc35103ef47/out/properties.rs:7937:40
     |
7937 |               specified::Overflow::parse(context, input)
     |                                          ^^^^^^^^^^^^^^ expected 1 parameter
     | 
    ::: components/style/values/specified/box.rs
     |
128  | / define_css_keyword_enum! { Overflow:
129  | |     "visible" => Visible,
130  | |     "hidden" => Hidden,
131  | |     "scroll" => Scroll,
132  | |     "auto" => Auto,
133  | | }
     | |_- defined here
     |
     = note: this error originates in a macro outside of the current crate

error: aborting due to 2 previous errors

error: Could not compile `style`.

To learn more, run the command again with --verbose.
[Warning] Could not generate notification! Optional Python module 'dbus' is not installed.
Build FAILED in 0:01:14

I found out that the file /target/debug/build/style-fe2cedc35103ef47/out/properties.rs is created by components/style/properties/build.py, but I'm not quite sure how to get rid of this error message.

@CYBAI
Copy link
Collaborator

@CYBAI CYBAI commented Dec 1, 2017

I think the root cause is the parse method duplicated between define_css_keyword_enum macro and add_impls_for_keyword_enum macro.

The define_css_keyword_enum is defined under style_traits/values.rs and it will impl your enum with a parse method with only one argument.

#[macro_export]
macro_rules! define_css_keyword_enum {
($name: ident: values { $( $css: expr => $variant: ident),+, }
aliases { $( $alias: expr => $alias_variant: ident ),+, }) => {
__define_css_keyword_enum__add_optional_traits!($name [ $( $css => $variant ),+ ]
[ $( $alias => $alias_variant ),+ ]);
};
($name: ident: values { $( $css: expr => $variant: ident),+, }
aliases { $( $alias: expr => $alias_variant: ident ),* }) => {
__define_css_keyword_enum__add_optional_traits!($name [ $( $css => $variant ),+ ]
[ $( $alias => $alias_variant ),* ]);
};
($name: ident: values { $( $css: expr => $variant: ident),+ }
aliases { $( $alias: expr => $alias_variant: ident ),+, }) => {
__define_css_keyword_enum__add_optional_traits!($name [ $( $css => $variant ),+ ]
[ $( $alias => $alias_variant ),+ ]);
};
($name: ident: values { $( $css: expr => $variant: ident),+ }
aliases { $( $alias: expr => $alias_variant: ident ),* }) => {
__define_css_keyword_enum__add_optional_traits!($name [ $( $css => $variant ),+ ]
[ $( $alias => $alias_variant ),* ]);
};
($name: ident: $( $css: expr => $variant: ident ),+,) => {
__define_css_keyword_enum__add_optional_traits!($name [ $( $css => $variant ),+ ] []);
};
($name: ident: $( $css: expr => $variant: ident ),+) => {
__define_css_keyword_enum__add_optional_traits!($name [ $( $css => $variant ),+ ] []);
};
}

The add_impls_for_keyword_enum is defined under macro.rs and it will impl Parse which will need two arguments.

/// A macro for implementing `ToComputedValue`, and `Parse` traits for
/// the enums defined using `define_css_keyword_enum` macro.
///
/// NOTE: We should either move `Parse` trait to `style_traits`
/// or `define_css_keyword_enum` macro to this crate, but that
/// may involve significant cleanup in both the crates.
macro_rules! add_impls_for_keyword_enum {
($name:ident) => {
impl $crate::parser::Parse for $name {
#[inline]
fn parse<'i, 't>(
_context: &$crate::parser::ParserContext,
input: &mut ::cssparser::Parser<'i, 't>,
) -> Result<Self, ::style_traits::ParseError<'i>> {
$name::parse(input)
}
}
trivial_to_computed_value!($name);
};
}

Thus, when the predefined_type create the file,

#[allow(unused_variables)]
#[inline]
pub fn parse<'i, 't>(context: &ParserContext,
input: &mut Parser<'i, 't>)
-> Result<SpecifiedValue, ParseError<'i>> {
% if allow_quirks:
specified::${type}::${parse_method}_quirky(context, input, AllowQuirks::Yes)
% elif needs_context:
specified::${type}::${parse_method}(context, input)
% else:
specified::${type}::${parse_method}(input)
% endif
}

it will generate the file with specified::Overflow::parse(context, input).

So, all you need is passing needs_context=False in predefined_type.

You can reference to ScrollSnapType or OverscrollBehavior which are also in box.mako.rs.

@olmanz
Copy link
Contributor

@olmanz olmanz commented Dec 1, 2017

Thanks, that worked!

@olmanz olmanz mentioned this issue Dec 1, 2017
3 of 5 tasks complete
@olmanz
Copy link
Contributor

@olmanz olmanz commented Dec 1, 2017

Pull Request is out.
#19448

@jdm
Copy link
Member

@jdm jdm commented Jan 26, 2018

The previous author is busy in school right now. If anybody would like to tackle this, it is available. See #19448 for prior work.

@nicknadeau
Copy link

@nicknadeau nicknadeau commented Feb 4, 2018

I'd like to work on this one if it's still open!

@jdm
Copy link
Member

@jdm jdm commented Feb 4, 2018

@nicknadeau Please do!

@jdm jdm added the C-assigned label Feb 4, 2018
@nicknadeau
Copy link

@nicknadeau nicknadeau commented Feb 8, 2018

So I've done some investigating and just want to make sure I understand correctly.
I'm essentially taking lines 212-216 of box.mako.rs, the overflow-y bit, and feeding it into helpers.predefined_type(...)?
Am I doing the same with overflow-x?

@jdm
Copy link
Member

@jdm jdm commented Feb 8, 2018

It's a combination of changing those mako lines to use predefined_type, as well as extracting the actual types that used to be generated by mako into proper Rust definitions in style/values, and ensuring that ./mach build-geckolib continues to work (based on #19448 (comment)).

@emilio
Copy link
Member

@emilio emilio commented Feb 18, 2018

Hi @nicknadeau, have you managed to make any progress on this?

Thanks!

@nicknadeau
Copy link

@nicknadeau nicknadeau commented Feb 18, 2018

Hi @emilio, progress has been a little slow, just got out of midterms. I'll be giving this bug a go over the next few days and I'll update my status by mid-late week and let you know if I have any questions.

I hope that's alright, sorry for the slow start.

@emilio
Copy link
Member

@emilio emilio commented Feb 18, 2018

Sounds great, no worries, and thanks! :)

@nicknadeau
Copy link

@nicknadeau nicknadeau commented Feb 22, 2018

Ok I've started out on a similar foot to olmanz and used overscroll-behaviour as an example to mimic.
So far I'm passing only a subset of the params into predefined_type and ./mach build seems to work fine but of course I've not taken care of the gecko bit yet so the gecko build breaks.

I'm just stuck here, I'm really not sure how to deal with some of these params. For instance, I've tried sending gecko_constant_prefix into predefined_type and I get:
TypeError: __init__() got an unexpected keyword argument 'gecko_constant_prefix' - triggered by line 455 in declare_longhand.
(sorry I'm working on another PC and don't have the full error msg with me)

So I'm wondering, am I trying to get things like gecko_constant_prefix, custom_consts etc. into predefined_type as well? Is it appropriate to use the single_keyword function to handle the gecko stuff? Sorry, still trying to understand how the code is working.

@62mkv
Copy link

@62mkv 62mkv commented Feb 22, 2018

maybe someone removes E-easy label ? judging by history it's "anything but" easy

@jdm jdm removed the E-easy label Feb 22, 2018
@nicknadeau
Copy link

@nicknadeau nicknadeau commented Feb 22, 2018

Well to be fair I've only spent ~2 hours on this so far, I'll keep tracing things and see what I can figure out.

@emilio
Copy link
Member

@emilio emilio commented Feb 22, 2018

maybe someone removes E-easy label ? judging by history it's "anything but" easy

FWIW, it should be easier now, the relevant prerequisites have already landed, like #19578.

@emilio
Copy link
Member

@emilio emilio commented Feb 22, 2018

So I'm wondering, am I trying to get things like gecko_constant_prefix, custom_consts etc. into predefined_type as well? Is it appropriate to use the single_keyword function to handle the gecko stuff? Sorry, still trying to understand how the code is working.

Sorry I missed this before, you should stop using gecko_constant_prefix into predefined_type, and then write the conversion manually like we do for other keywords, like overscroll-behavior.

@nicknadeau
Copy link

@nicknadeau nicknadeau commented Feb 25, 2018

My progress so far:
https://github.com/nicknadeau/servo/commit/97d138dc370e542e5ec0ef04b31541da37238732
https://github.com/nicknadeau/servo/commit/ed6524aa94b03d248bbd90885c7f117e06c66098

In gecko build I get the following error coming from set_overflow_y in gecko.mako.rs
Still trying to figure out what overflow_x.keyword is doing

Traceback (most recent call last):
...
File "/home/nick/Desktop/servo/components/style/properties/gecko.mako.rs", line 1535, in render_impl_trait
${caller.body().strip()}
File "/home/nick/Desktop/servo/components/style/properties/gecko.mako.rs", line 3105, in body
$ for value in overflow_x.keyword.values_for('gecko'):
AttributeError: 'NoneType' object has no attribute 'values_for

@nicknadeau
Copy link

@nicknadeau nicknadeau commented Mar 21, 2018

I'm sorry guys, I really don't know how to progress from here, I don't understand enough of this code base in terms of the gecko stuff

@jdm
Copy link
Member

@jdm jdm commented Mar 22, 2018

@emilio This is probably going to need your attention to answer the previous question.

@emilio
Copy link
Member

@emilio emilio commented Mar 22, 2018

Oh, sorry, thanks!

@nicknadeau: So that error means that overflow_x.keyword is None, which is expected because we're using predefined_type instead of keyword. That's fine, and the only thing that needs to happen is defining the keyword ourselves like overflow_behavior does:

https://searchfox.org/mozilla-central/rev/c217fbde244344fedfd07b57a740c694a456dbca/servo/components/style/properties/gecko.mako.rs#3423

@KiChjang KiChjang removed the C-assigned label Oct 6, 2018
@PhilParisot
Copy link

@PhilParisot PhilParisot commented Jul 2, 2020

Hey @emilio and @jdm, I'd like to try and attempt this issue if that's OK with you. I just finished reading the book.

I'll say hi on #servo on Matrix.

Let me know!

Thanks!

@emilio
Copy link
Member

@emilio emilio commented Jul 2, 2020

I think this was effectively done in https://bugzilla.mozilla.org/show_bug.cgi?id=1470695. @jdm do you have any other potential good first issue for @PhilParisot?

@emilio emilio closed this Jul 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

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