Skip to content

Drop support for multiple generators yielding from one generator #6071

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 Sep 3, 2020

This drops support for having multiple generators yield from the same generator in parallel. Support for this requires the famous "doubly-linked refcounted generator tree" that is very hard to understand and serves a non-existent use-case.

A new use-after-free in this area has recently surfaced (oss-fuzz #25344), as triggered by the test case Zend/tests/generators/yield_from_multi_child_destroyed.phpt. I tried to find a fix, but it's really not simple. The code didn't really consider the possibility of a "child" generator (the one calling yield from) being destroyed before the "parent" generator (the one being yielded from) and the parent generator being used afterwards.

This PR only adds an exception. I would clean up the implementation in a separate commit.

@nikic
Copy link
Member Author

nikic commented Sep 3, 2020

cc @bwoebi @dstogov @sgolemon I would like to make this change for PHP 8. I don't think anyone uses this functionality and it's a big maintenance headache.

@morrisonlevi
Copy link
Contributor

Is there a known library or framework that makes heavy use of yield from that we could double-check with for any legitimate use cases?

@nikic
Copy link
Member Author

nikic commented Sep 3, 2020

I did check that https://github.com/amphp/amp doesn't break.

@dstogov
Copy link
Member

dstogov commented Sep 3, 2020

I'm not an expert in this area.
As I understand, yield from implements behavior similar to async/await.
I afraid, this PR may introduce a limitation that would break async frameworks.

@staabm
Copy link
Contributor

staabm commented Sep 3, 2020

//cc @kelunik @trowski from amphp

@trowski
Copy link
Member

trowski commented Sep 3, 2020

Amp never uses yield from on the same generator in parallel. yield from is only used with private methods as single-use coroutines. Here's an example in amphp/postgres. +1 for this change.

@staabm
Copy link
Contributor

staabm commented Sep 3, 2020

//cc @clue from reactphp

@kelunik
Copy link
Member

kelunik commented Sep 3, 2020

I also don't think the BC break potential is very large. I'm pretty sure Amp isn't affected, which is probably the heaviest user of Generators in PHP.

AFAIK yield from is just syntactic sugar and the same could be achieved without it, no? If so, do we have similar issues if it's implemented without yield from?

@clue
Copy link

clue commented Sep 3, 2020

No objections from my end, to the best of my knowledge this feature isn't used in any ReactPHP-related projects.

@nikic
Copy link
Member Author

nikic commented Oct 30, 2020

#6344 has at least partially addressed the implementation complexity issues here. And the ship has sailed for PHP 8.0 in either case...

@nikic nikic closed this Oct 30, 2020
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.

7 participants