-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
Description
Bug report
Bug description:
In PEP 709, for the given example:
def f(lst):
return [x for x in lst]
The bytecode is generated this way:
1 0 RESUME 0
2 2 LOAD_FAST 0 (lst)
4 GET_ITER
6 LOAD_FAST_AND_CLEAR 1 (x)
8 SWAP 2
10 BUILD_LIST 0
...
FWIK, the first SWAP
after LOAD_FAST_AND_CLEAR
is used to perform the original implicitly passed .0
in co_varnames (the iterated target passed from the MAKE_FUNCTION's caller before PEP 709).
And this seems to 100% be the needed case (I'm not sure, but I suspect it should be) when LOAD_FAST_AND_CLEAR
is performed.
This makes me wonder if it's possible to merge the first SWAP operation under LOAD_FAST_AND_CLEAR
, this should provide a negligible performance gain + bytecode operation simplification.
(I've verified this with under MacOS 15.5 (24F74) + Python 3.13.3, this should be something reproducible after 3.12.)
More background (an idea from a talk I gave in EuroPython 2025): https://github.com/note35/about/blob/dev/public/slides/2025-bytecode.pdf
CPython versions tested on:
3.12
Operating systems tested on:
macOS