-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Do not scan generator frames more than once #15330
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
--TEST-- | ||
GH-15330 001: Do not scan generator frames more than once | ||
--FILE-- | ||
<?php | ||
|
||
class It implements \IteratorAggregate | ||
{ | ||
public function getIterator(): \Generator | ||
{ | ||
yield 'foo'; | ||
Fiber::suspend(); | ||
var_dump("not executed"); | ||
} | ||
} | ||
|
||
function f() { | ||
var_dump(yield from new It()); | ||
} | ||
|
||
$iterable = f(); | ||
|
||
$fiber = new Fiber(function () use ($iterable) { | ||
var_dump($iterable->current()); | ||
$iterable->next(); | ||
var_dump("not executed"); | ||
}); | ||
|
||
$ref = $fiber; | ||
|
||
$fiber->start(); | ||
|
||
gc_collect_cycles(); | ||
|
||
?> | ||
==DONE== | ||
--EXPECT-- | ||
string(3) "foo" | ||
==DONE== |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
--TEST-- | ||
GH-15330 002: Do not scan generator frames more than once | ||
--FILE-- | ||
<?php | ||
|
||
function g() { | ||
yield 'foo'; | ||
Fiber::suspend(); | ||
} | ||
|
||
function f() { | ||
var_dump(yield from g()); | ||
} | ||
|
||
$iterable = f(); | ||
|
||
$fiber = new Fiber(function () use ($iterable) { | ||
var_dump($iterable->current()); | ||
$iterable->next(); | ||
var_dump("not executed"); | ||
}); | ||
|
||
$ref = $fiber; | ||
|
||
$fiber->start(); | ||
|
||
gc_collect_cycles(); | ||
|
||
?> | ||
==DONE== | ||
--EXPECT-- | ||
string(3) "foo" | ||
==DONE== |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
--TEST-- | ||
GH-15330 003: Do not scan generator frames more than once | ||
--FILE-- | ||
<?php | ||
|
||
class It implements \IteratorAggregate | ||
{ | ||
public function getIterator(): \Generator | ||
{ | ||
yield 'foo'; | ||
Fiber::suspend(); | ||
var_dump("not executed"); | ||
} | ||
} | ||
|
||
class Canary { | ||
public function __construct(public mixed $value) {} | ||
public function __destruct() { | ||
var_dump(__METHOD__); | ||
} | ||
} | ||
|
||
function f($canary) { | ||
var_dump(yield from new It()); | ||
} | ||
|
||
$canary = new Canary(null); | ||
|
||
$iterable = f($canary); | ||
|
||
$fiber = new Fiber(function () use ($iterable, $canary) { | ||
var_dump($canary, $iterable->current()); | ||
$iterable->next(); | ||
var_dump("not executed"); | ||
}); | ||
|
||
$canary->value = $fiber; | ||
|
||
$fiber->start(); | ||
|
||
$iterable->current(); | ||
|
||
$fiber = $iterable = $canary = null; | ||
|
||
gc_collect_cycles(); | ||
|
||
?> | ||
==DONE== | ||
--EXPECTF-- | ||
object(Canary)#%d (1) { | ||
["value"]=> | ||
object(Fiber)#%d (0) { | ||
} | ||
} | ||
string(3) "foo" | ||
string(18) "Canary::__destruct" | ||
==DONE== |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
--TEST-- | ||
GH-15330 004: Do not scan generator frames more than once | ||
--FILE-- | ||
<?php | ||
|
||
class Canary { | ||
public function __construct(public mixed $value) {} | ||
public function __destruct() { | ||
var_dump(__METHOD__); | ||
} | ||
} | ||
|
||
function g() { | ||
yield 'foo'; | ||
Fiber::suspend(); | ||
} | ||
|
||
function f($canary) { | ||
var_dump(yield from g()); | ||
} | ||
|
||
$canary = new Canary(null); | ||
|
||
$iterable = f($canary); | ||
|
||
$fiber = new Fiber(function () use ($iterable, $canary) { | ||
var_dump($canary, $iterable->current()); | ||
$iterable->next(); | ||
var_dump("not executed"); | ||
}); | ||
|
||
$canary->value = $fiber; | ||
|
||
$fiber->start(); | ||
|
||
$iterable->current(); | ||
|
||
$fiber = $iterable = $canary = null; | ||
|
||
gc_collect_cycles(); | ||
|
||
?> | ||
==DONE== | ||
--EXPECTF-- | ||
object(Canary)#%d (1) { | ||
["value"]=> | ||
object(Fiber)#%d (0) { | ||
} | ||
} | ||
string(3) "foo" | ||
string(18) "Canary::__destruct" | ||
==DONE== |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
--TEST-- | ||
GH-15330 005: Do not scan generator frames more than once | ||
--FILE-- | ||
<?php | ||
|
||
class Canary { | ||
public function __construct(public mixed $value) {} | ||
public function __destruct() { | ||
var_dump(__METHOD__); | ||
} | ||
} | ||
|
||
function g() { | ||
yield 'foo'; | ||
Fiber::suspend(); | ||
} | ||
|
||
function f($canary) { | ||
var_dump(yield from g()); | ||
} | ||
|
||
$canary = new Canary(null); | ||
|
||
$iterable = f($canary); | ||
|
||
$fiber = new Fiber(function () use ($iterable, $canary) { | ||
var_dump($canary, $iterable->current()); | ||
$f = $iterable->next(...); | ||
$f(); | ||
var_dump("not executed"); | ||
}); | ||
|
||
$canary->value = $fiber; | ||
|
||
$fiber->start(); | ||
|
||
$iterable->current(); | ||
|
||
$fiber = $iterable = $canary = null; | ||
|
||
gc_collect_cycles(); | ||
|
||
?> | ||
==DONE== | ||
--EXPECTF-- | ||
object(Canary)#%d (1) { | ||
["value"]=> | ||
object(Fiber)#%d (0) { | ||
} | ||
} | ||
string(3) "foo" | ||
string(18) "Canary::__destruct" | ||
==DONE== |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
--TEST-- | ||
GH-15330 006: Do not scan generator frames more than once | ||
--FILE-- | ||
<?php | ||
|
||
class Canary { | ||
public function __construct(public mixed $value) {} | ||
public function __destruct() { | ||
var_dump(__METHOD__); | ||
} | ||
} | ||
|
||
function h() { | ||
yield 'foo'; | ||
Fiber::suspend(); | ||
} | ||
|
||
function g() { | ||
yield from h(); | ||
} | ||
|
||
function f($canary) { | ||
var_dump(yield from g()); | ||
} | ||
|
||
$canary = new Canary(null); | ||
|
||
$iterable = f($canary); | ||
|
||
$fiber = new Fiber(function () use ($iterable, $canary) { | ||
var_dump($canary, $iterable->current()); | ||
$iterable->next(); | ||
var_dump("not executed"); | ||
}); | ||
|
||
$canary->value = $fiber; | ||
|
||
$fiber->start(); | ||
|
||
$iterable->current(); | ||
|
||
$fiber = $iterable = $canary = null; | ||
|
||
gc_collect_cycles(); | ||
|
||
?> | ||
==DONE== | ||
--EXPECTF-- | ||
object(Canary)#%d (1) { | ||
["value"]=> | ||
object(Fiber)#%d (0) { | ||
} | ||
} | ||
string(3) "foo" | ||
string(18) "Canary::__destruct" | ||
==DONE== |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How can a generator be not running and on the fiber stacktrace at the same time? As far as I'm know, running generator <=> generator exists on exactly one stacktrace?
Isn't that check redundant?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generators stopped in
yield from
do not have theZEND_GENERATOR_CURRENTLY_RUNNING
flag. We consider them to be running in most places because we checkzend_generator_get_current(generator)->flags
instead ofgenerator->flags
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, right, I forgot about the placeholder frame.