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

Convert OptionStore from a dict to a full class with named methods #13307

Merged
merged 4 commits into from
Jun 14, 2024

Conversation

jpakkane
Copy link
Member

@jpakkane jpakkane commented Jun 8, 2024

Does not work yet, but there are not that many failing tests any more. Posted for early review comments.

@jpakkane jpakkane marked this pull request as draft June 9, 2024 11:16
@jpakkane jpakkane marked this pull request as ready for review June 9, 2024 13:57
@jpakkane
Copy link
Member Author

jpakkane commented Jun 9, 2024

Now passes all tests on my machine. Will almost certainly fail on others, especially for mypy & lint.

@jpakkane jpakkane force-pushed the optstorerefactor branch 10 times, most recently from ae72298 to f0fa698 Compare June 9, 2024 22:30
@jpakkane
Copy link
Member Author

jpakkane commented Jun 9, 2024

Ignoring linter checks this is now mostly working. The Cuda error is a bit strange and I don't even have a Cuda toolchain installed for local testing. Maybe @SoapGentoo would have an idea?

@SoapGentoo
Copy link
Member

I'm not seeing an obvious point of failure. Why have you replaced the direct indexing syntax though?

@jpakkane
Copy link
Member Author

Why have you replaced the direct indexing syntax though?

Because indexing is used both for "read the value of this thingy" and "set the value of this thingy" so it is impossible to tell where in the code values are written and where they are only read. That is needed as a prerequisite for the option refactor MR.

@jpakkane jpakkane force-pushed the optstorerefactor branch 3 times, most recently from 076099c to 0a70d30 Compare June 10, 2024 19:35
@jpakkane
Copy link
Member Author

Yes! This should fix all functional code. I still need to fix typing issues, but other than that this should be ready for review.

@@ -473,8 +474,66 @@ def add_to_argparse(self, name: str, parser: argparse.ArgumentParser, help_suffi
OptionKey('purelibdir', module='python'): {},
}


class OptionStore:
Copy link
Member

Choose a reason for hiding this comment

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

Why not derive this class directly from dict ? That would simplify it a little bit, and remove one indirection.

Copy link
Member Author

Choose a reason for hiding this comment

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

The entire point of the class is that it has only the methods explicitly written. That is, it does not have an indexing operation so users are forced to use the semantically meaningful named methods. At the moment they are simple direct accesses but in the future (actually already in the present in the optionrefactor branch) they do more like do per-subproject overrides transparently in one centralised place.

This also allows you to add breakpoints to the accessor methods which is exremely useful.

@jpakkane jpakkane force-pushed the optstorerefactor branch 4 times, most recently from fd83439 to b7d5109 Compare June 11, 2024 19:28
@jpakkane
Copy link
Member Author

And now, finally, all green!

key = self.ensure_key(key)
return self.d[key].set_value(new_value)

# FIXME, this should be removed.
Copy link
Member

Choose a reason for hiding this comment

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

Is this FIXME still relevant?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes. There should be separate methods for A) creating a new option with the given option and B) changing the type of an existing option. Due to reasons I can't remember I needed this but which will go away after some more refactoring.

In the end it might just need renaming, not removing so updating.

@@ -182,7 +182,7 @@ def _add_languages(self, raw_langs: T.List[TYPE_var], required: bool, for_machin
if self.subproject:
options = {}
for k in comp.get_options():
v = copy.copy(self.coredata.options[k])
v = copy.copy(self.coredata.optstore.get_value_object(k))
Copy link
Member

Choose a reason for hiding this comment

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

I see this pattern 3 times. Why not to have a get_value_object_copy() method?

Copy link
Member Author

Choose a reason for hiding this comment

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

Because these will all go away. They will be replaced with named methods that have a proper semantic name. If any copying is to be done it should happen inside the OptionStore object.

@@ -656,8 +656,8 @@ def generate(self, capture: bool = False, vslite_ctx: T.Optional[T.Dict] = None)
self.generate_dist()
mlog.log_timestamp("Dist generated")
key = OptionKey('b_coverage')
if (key in self.environment.coredata.options and
self.environment.coredata.options[key].value):
if (key in self.environment.coredata.optstore and
Copy link
Member

Choose a reason for hiding this comment

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

Maybe a has_value() -> bool method?

@@ -3597,7 +3597,7 @@ def generate_gcov_clean(self) -> None:

def get_user_option_args(self):
cmds = []
for (k, v) in self.environment.coredata.options.items():
for (k, v) in self.environment.coredata.optstore.items():
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
for (k, v) in self.environment.coredata.optstore.items():
for k, v in self.environment.coredata.optstore.items():

mesonbuild/options.py Show resolved Hide resolved
@jpakkane jpakkane merged commit ce889d6 into master Jun 14, 2024
39 checks passed
@jpakkane jpakkane deleted the optstorerefactor branch June 14, 2024 16:25
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.

3 participants