[mypyc] Move private generator spills from environ to generator objects - #21955
Merged
Conversation
Keep the continuation label and the spill slots added by the post-IRBuild liveness pass for temporary operation results that remain live across a yield on the generator object, even when the generator needs a separate closure environment. Source-level generator variables remain in that shared environment, since nested functions may capture and access them independently. Spills emitted explicitly during IRBuild, including spillable registers, are also unchanged and remain in the environment. The helper-only state is protected by the generator running flag, unlike a closure environment that nested functions can access independently. Keeping it on the private generator frame lets free-threaded builds use plain attribute access safely. Include the owning class name in spill attributes as well, so spills from overriding generator methods cannot alias inherited fields with different native types.
p-sawicki
approved these changes
Sep 7, 2026
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Move the continuation label and the spill slots added by the
temp liveness pass (for temporary op results that survive
across a yield) to the generator object, even when the
generator needs a separate closure environment.
Locals still remain in the shared environment, since nested
functions may capture and access them independently. Spills
emitted explicitly during irbuild, are also unchanged and remain
in the environment. I'll fix some of these in follow-up PR(s).
The state migrated to the generator is protected by the generator
running flag, unlike a closure environment that nested functions
can access without restriction. Keeping it on the private generator
frame lets free-threaded builds use plain attribute access safely.
Include the owning class name in spill attributes as well, so spills
from overriding generator methods cannot alias inherited fields
with different native types.
I used a microbenchmark to validate that this makes spilled
values over suspends faster on free-threaded Python 3.14.
I used coding agent assist.