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

Memoize stable task creation #5654

Merged

Conversation

stuhood
Copy link
Sponsor Member

@stuhood stuhood commented Apr 4, 2018

Problem

After Goal.clear(), task subclasses created for the same superclasses and scopes will not be equal/identical to those from before Goal.clear().

As part of its maintenance of the task/goal lifecycle, pantsd clears the goals, which currently causes the creation of multiple non-identical but otherwise equal subclasses, and that caused me some confusion on #5639 where I was attempting to use task classes as dict keys.

Solution

Memoize creation of the stable task subclasses (similar to the strategy used in Collection.of).

Result

Task classes behave as expected in #5639.

…parate instances for separate runs of `Goal`.
@stuhood stuhood requested review from jsirois, benjyw and kwlzn April 4, 2018 19:23
@stuhood stuhood force-pushed the stuhood/memoize-stable-task-creation branch from d9cd10d to 2adf57c Compare April 4, 2018 19:26
Copy link
Member

@kwlzn kwlzn left a comment

Choose a reason for hiding this comment

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

lgtm

task1_pre, = install()
Goal.clear()
task1_post, = install()
self.assertEquals(task1_pre, task1_post)
Copy link
Sponsor Contributor

Choose a reason for hiding this comment

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

Do you want to check that they have the same id? Or is semantic equality all we actually care about anyway?

Copy link
Sponsor Member Author

Choose a reason for hiding this comment

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

Semantic equality is really what matters, yea. Although in theory I could/should have checked __hash__ as well.

@stuhood stuhood merged commit 899fb73 into pantsbuild:master Apr 4, 2018
@stuhood stuhood deleted the stuhood/memoize-stable-task-creation branch April 4, 2018 20:50
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.

4 participants