Skip to content

[mypyc] Move private generator spills from environ to generator objects - #21955

Merged
JukkaL merged 5 commits into
masterfrom
mypyc-async-5a
Sep 7, 2026
Merged

[mypyc] Move private generator spills from environ to generator objects#21955
JukkaL merged 5 commits into
masterfrom
mypyc-async-5a

Conversation

@JukkaL

@JukkaL JukkaL commented Sep 7, 2026

Copy link
Copy Markdown
Collaborator

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.

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.
@JukkaL JukkaL changed the title [mypyc] Move private generator spills from environments to generator objects [mypyc] Move private generator spills from environ to generator objects Sep 7, 2026
@JukkaL
JukkaL merged commit dea7b79 into master Sep 7, 2026
18 checks passed
@JukkaL
JukkaL deleted the mypyc-async-5a branch September 7, 2026 15:49
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