Skip to content

[mypyc] Free coroutine after await encounters StopIteration #19231

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 1 commit into from
Jun 4, 2025

Conversation

JukkaL
Copy link
Collaborator

@JukkaL JukkaL commented Jun 4, 2025

Previously the awaited coroutine could stay alive until the coroutine that performed the await was freed, delaying object reclamation. The reference counting analysis doesn't understand registers spilled to the environment, so we need to manually clear the value.

Consider code like this:

async def foo() -> None:
    await bar()
    await zar()

Previously, the bar() coroutine was only freed at end of foo(). Now we release it before await zar(), as expected.

Previously the awaited generator could stay alive until the generator
that performed the await was freed, delaying object reclamation. The
refcount analysis doesn't understand registers spilled to the
environment, so we need to manually clear the value.

Consider code like this:
```
async def foo() -> None:
    await bar()
    await zar()
```
Previously, the `bar()` generator was only freed at end of `foo()`. Now
we release it before `await zar()`, as expected.
@JukkaL JukkaL changed the title [mypyc] Free generator after await encounters StopIteration [mypyc] Free coroutine after await encounters StopIteration Jun 4, 2025
@JukkaL JukkaL merged commit ab61ec2 into master Jun 4, 2025
13 checks passed
@JukkaL JukkaL deleted the mypyc-async-temp-free branch June 4, 2025 12:31
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