Skip to content

Simplify and fix generator tree management #6344

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

Closed
wants to merge 1 commit into from

Conversation

nikic
Copy link
Member

@nikic nikic commented Oct 16, 2020

This makes a number of related changes to the generator tree management, that should hopefully make it easier to understand, more robust and faster for the common linear-chain case. Fixes https://bugs.php.net/bug.php?id=80240, which was the original motivation here.

  • Generators now only add a ref to their direct parent.
  • Nodes only store their children, not their leafs, which avoids any need for leaf updating. This means it's no longer possible to fetch the child for a certain leaf, which is something we only needed in one place (update_current). If multi-children nodes are involved, this will require doing a walk in the other direction (from leaf to root). It does not affect the common case of single-child nodes.
  • The root/leaf pointers are now seen as a pair. One leaf generator can point to the current root. If a different leaf generator is used, we'll move the root pointer over to that one. Again, this is a cache to make the common linear chain case fast, trees may need to scan up the parent link.

@nikic nikic requested a review from bwoebi October 16, 2020 10:33
#0 gen() called at [%s:10]
#1 from(Generator Object ())
#2 Generator->next() called at [%s:19]
int(2)
Copy link
Member Author

Choose a reason for hiding this comment

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

Note that the output here is incorrect (only one next() call should be needed above). However, this is a pre-existing bug in PHP 7.4 and not related to this change.

Copy link
Member

@bwoebi bwoebi left a comment

Choose a reason for hiding this comment

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

I like it. Looks good to me and I cannot think right now of a scenario where this would break.
Feel free to merge :-)

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.

2 participants