Issue 17607: missed peephole optimization (unnecessary jump at end of function after yield) (original) (raw)

Issue17607

Created on 2013-04-01 04:45 by Neal.Norwitz, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (3)
msg185708 - (view) Author: Neal Norwitz (Neal.Norwitz) Date: 2013-04-01 04:45
>>> def foo(): ... if x: ... yield None ... >>> dis.dis(foo) 2 0 LOAD_GLOBAL 0 (x) 3 POP_JUMP_IF_FALSE 14 3 6 LOAD_CONST 0 (None) 9 YIELD_VALUE 10 POP_TOP 11 JUMP_FORWARD 0 (to 14) >> 14 LOAD_CONST 0 (None) 17 RETURN_VALUE The JUMP_FORWARD at 11 is not necessary and is not in place with a return in the code: >>> def foo(): ... if x: ... return None ... >>> dis.dis(foo) 2 0 LOAD_GLOBAL 0 (x) 3 POP_JUMP_IF_FALSE 10 3 6 LOAD_CONST 0 (None) 9 RETURN_VALUE >> 10 LOAD_CONST 0 (None) 13 RETURN_VALUE
msg185859 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2013-04-02 21:06
This issue is similar to #17430.
msg309519 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2018-01-05 19:57
This optimization already is implemented in 3.5+. Actually it is implemented as a part of code generation, not a peepholer.
History
Date User Action Args
2022-04-11 14:57:43 admin set github: 61807
2018-01-05 19:57:12 serhiy.storchaka set status: open -> closednosy: + serhiy.storchakamessages: + resolution: out of datestage: resolved
2013-04-10 14:38:12 ezio.melotti set nosy: + ezio.melottiversions: + Python 3.4, - Python 2.7
2013-04-02 21:06:41 vstinner set nosy: + vstinnermessages: +
2013-04-01 04:45:51 Neal.Norwitz create