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
Dead code in wordcode #72703
Comments
>>> def func(test):
... if test == 1:
... return 1
... elif test == 2:
... return 2
... return 3
...
>>> import dis
>>> dis.dis(func) Python 3.5: 2 0 LOAD_FAST 0 (test) 3 12 LOAD_CONST 1 (1) 4 >> 16 LOAD_FAST 0 (test) 5 28 LOAD_CONST 2 (2) 6 >> 32 LOAD_CONST 3 (3) Python 3.6: 2 0 LOAD_FAST 0 (test) 3 8 LOAD_CONST 1 (1) 4 >> 14 LOAD_FAST 0 (test) 5 22 LOAD_CONST 2 (2) 6 >> 26 LOAD_CONST 3 (3) Note JUMP_FORWARD after RETURN_VALUE in 3.6 listing. |
Proposed patch fixes removing unreachable code after RETURN_VALUE in peephole optimizer. |
Hi Serhiy, Could you help me, because I don't understand your patch ? because a RETURN_VALUE will go to the end of the block, and in this case, I don't understand why there is a JUMP_FORWARD at 12 in Python 3.6. |
+0 The situation this addresses isn't common and the patch will rarely produce a perceptable benefit (just making the disassembly look a little nicer). That said, change looks simple enough and doesn't add any overhead. |
New changeset 5784cc37b5f4 by Serhiy Storchaka in branch '3.6': New changeset 8d571fab4d66 by Serhiy Storchaka in branch 'default': |
The main problem was that this bug caused unnecessary breakage of tests in Victor's bytecode [1]. Stéphane, the number of opcodes to the end of the block was counted incorrectly. Just off-by-one error. One unreachable opcode always was left. |
ah ok, thanks for the explanation. |
the off by one error fix here introduced a new off by one error. PR coming, follow https://bugs.python.org/issue35193 for that. |
Misc/NEWS
so that it is managed by towncrier #552Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: