Since this is unrealistic code (why would you have a top-level expression without any side effects), what does it matter whether this code is optimized? Did you encounter this in a real use case? On Sun, Oct 10, 2021 at 9:59 AM Patrick Reader <_@pxeger.com> wrote:
Consider sequences of bytecode operations on fast locals like the following:
def f(x): # declare as parameter so that x is a fast local ... x ... dis(f) 2 0 LOAD_FAST 0 (x) 2 POP_TOP 4 LOAD_CONST 0 (None) 6 RETURN_VALUE
Given the following assumptions:
- a LOAD_FAST cannot possibly have any side-effects outside the interpreter stack [1]
- a POP_TOP immediately undoes LOAD_FAST's effects on the interpreter stack
I am wondering: why doesn't the peephole optimiser remove these opcode constructs?
Is it maybe because of PEP 626 - an introspection tool needs to know that the variable is being used there? Although surely in that case the peephole optimiser could just replace it with a single NOP? (c.f.: https://bugs.python.org/issue42719)
Or is one of my assumptions wrong?
[1]: global variables are probably supposed to have the same guarantee, but in practice this is not the case, which is why I'm focusing on the _FAST ones; see for example https://ato.pxeger.com/run?1=m72soLIkIz9vwYKlpSVpuhY3JyXnJBYXK_hWumQml2ikAAl...
_______________________________________________ Python-Dev mailing list -- python-dev@python.org To unsubscribe send an email to python-dev-leave@python.org https://mail.python.org/mailman3/lists/python-dev.python.org/ Message archived at https://mail.python.org/archives/list/python-dev@python.org/message/767FGRV4... Code of Conduct: http://python.org/psf/codeofconduct/
-- --Guido van Rossum (python.org/~guido) *Pronouns: he/him **(why is my pronoun here?)* http://feministing.com/2015/02/03/how-using-they-as-a-singular-pronoun-can-c...