Skip to content

Fix GH-11591: AppendIterator with generators that yield nothing - #23270

Open
matthiasgoergens wants to merge 8 commits into
php:masterfrom
matthiasgoergens:gh11591-appenditerator-empty-generators
Open

Fix GH-11591: AppendIterator with generators that yield nothing#23270
matthiasgoergens wants to merge 8 commits into
php:masterfrom
matthiasgoergens:gh11591-appenditerator-empty-generators

Conversation

@matthiasgoergens

Copy link
Copy Markdown
Contributor

Appending a generator probes it by rewinding, which runs an empty generator to
completion; traversing it later then throws "Cannot traverse an already closed
generator". Mark generators exhausted by this probe and skip them during
traversal, including after the inner array is modified. A deliberate behaviour
change: appending the same probed-empty generator twice now adds two empty
entries instead of throwing on the second append; consumed (once-yielded)
generators still throw on re-traversal.

Reinserting the same generator at the same outer key after an unset
inherited a stale empty marker keyed by (object, key), silently skipping
the entry where reinsertion at any other key threw. A generator can only
enter the iterator through append()'s own probe, so marking the object
itself is equivalent and cannot go stale.
Moving a probed-empty generator to another key previously threw, because
the marker followed the entry key rather than the generator object.
An empty generator appended after a valid entry was never probed by
append(), so its first exhaustion during traversal left it unmarked and a
second traversal still threw. Mark generators that finish while
initialising (they never yielded) at every exhaustion point, keyed by
object so reinsertion cannot inherit a stale marker.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant