Issue 33387: Simplify bytecodes for try-finally, try-except and with blocks. (original) (raw)

Created on 2018-04-29 18:28 by Mark.Shannon, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 6641 merged Mark.Shannon,2018-04-29 18:36
PR 17318 merged Mark.Shannon,2019-11-21 10:31
PR 18099 merged vstinner,2020-01-21 10:25
PR 22723 merged Mark.Shannon,2020-10-16 16:28
PR 22765 merged miss-islington,2020-10-19 13:08
PR 24334 merged iritkatriel,2021-01-25 21:03
Messages (14)
msg315905 - (view) Author: Mark Shannon (Mark.Shannon) * (Python committer) Date: 2018-04-29 18:28
The six complex bytecodes currently used for implementing 'with' and 'try' statements can be replaced with just two simpler bytecodes. The six bytecodes are WITH_CLEANUP_START, WITH_CLEANUP_FINISH, BEGIN_FINALLY, END_FINALLY, CALL_FINALLY and POP_FINALLY. They can be replaced with RERAISE and WITH_EXCEPT_FINISH. See https://bugs.python.org/issue32949 for more details of the new bytecodes and how they are used in the 'with' statement. The try-finally statement can be implemented broadly as SETUP_FINALLY except try-body POP_BLOCK finally-body JUMP exit except: finally-body exit:
msg339817 - (view) Author: Cheryl Sabella (cheryl.sabella) * (Python committer) Date: 2019-04-09 23:32
What would be the best way to resolve the discussion between this and issue 32949? Would it be good to try to get one of them into 3.8?
msg357147 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2019-11-21 10:06
Mark merged his PR 6641 but forgot to mention bpo-33387: commit fee552669f21ca294f57fe0df826945edc779090 Author: Mark Shannon <mark@hotpy.org> Date: Thu Nov 21 09:11:43 2019 +0000 Produce cleaner bytecode for 'with' and 'async with' by generating separate code for normal and exceptional paths. (#6641) Remove BEGIN_FINALLY, END_FINALLY, CALL_FINALLY and POP_FINALLY bytecodes. Implement finally blocks by code duplication. Reimplement frame.lineno setter using line numbers rather than bytecode offsets.
msg357148 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2019-11-21 10:07
The new doc seems to use Python version 3.8, but the change was merged into master which is the future Python 3.9, no? .. opcode:: RERAISE Re-raises the exception currently on top of the stack. .. versionadded:: 3.8
msg357155 - (view) Author: Mark Shannon (Mark.Shannon) * (Python committer) Date: 2019-11-21 10:32
Thanks for noticing. https://github.com/python/cpython/pull/17318
msg357172 - (view) Author: Mark Shannon (Mark.Shannon) * (Python committer) Date: 2019-11-21 14:47
New changeset 82f897bf8f72d09f537054d64a94e645ad23d8d6 by Mark Shannon in branch 'master': Correct release version to 3.9 for RERAISE and WITH_EXCEPT_START bytecodes. (#17318) https://github.com/python/cpython/commit/82f897bf8f72d09f537054d64a94e645ad23d8d6
msg357246 - (view) Author: Gregory P. Smith (gregory.p.smith) * (Python committer) Date: 2019-11-22 06:35
sweet! =)
msg357279 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2019-11-22 13:28
Can this issue be closed now?
msg360393 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2020-01-21 11:47
New changeset 629023c05be24fa2f01c914c739aaa5a61a0304c by Victor Stinner in branch 'master': bpo-33387: Fix compiler warning in frame_block_unwind() (GH-18099) https://github.com/python/cpython/commit/629023c05be24fa2f01c914c739aaa5a61a0304c
msg378715 - (view) Author: Xavier Morel (xmorel) * Date: 2020-10-16 14:06
The 3.9 changelog mentions WITH_EXCEPT_FINISH but that seems to have ultimately been called WITH_EXCEPT_START, maybe it shoudl be updated also?
msg378720 - (view) Author: Mark Shannon (Mark.Shannon) * (Python committer) Date: 2020-10-16 16:47
Yes, thanks for pointing that out.
msg385664 - (view) Author: Irit Katriel (iritkatriel) * (Python committer) Date: 2021-01-25 21:03
I'm reopening this to delete an obsolete comment left behind.
msg385679 - (view) Author: Irit Katriel (iritkatriel) * (Python committer) Date: 2021-01-25 23:23
There's another place that needs to be updated: https://docs.python.org/3/library/dis.html#opcode-SETUP_WITH need to replace WITH_CLEANUP_START by WITH_EXCEPT_START
msg385703 - (view) Author: Mark Shannon (Mark.Shannon) * (Python committer) Date: 2021-01-26 10:17
New changeset dea5bf9d15999bfcc58095b157c0678d45b00bdd by Irit Katriel in branch 'master': bpo-33387: update documentation for exception handling opcode changes (GH-24334) https://github.com/python/cpython/commit/dea5bf9d15999bfcc58095b157c0678d45b00bdd
History
Date User Action Args
2022-04-11 14:58:59 admin set github: 77568
2021-01-26 10:27:14 iritkatriel set status: open -> closed
2021-01-26 10:17:17 Mark.Shannon set messages: +
2021-01-25 23:23:07 iritkatriel set messages: +
2021-01-25 23:14:57 iritkatriel set status: closed -> open
2021-01-25 23:10:52 iritkatriel set status: open -> closedstage: patch review -> resolved
2021-01-25 21:03:21 iritkatriel set stage: resolved -> patch reviewpull_requests: + <pull%5Frequest23153>
2021-01-25 21:03:11 iritkatriel set status: closed -> opennosy: + iritkatrielmessages: +
2020-10-19 13:08:51 miss-islington set nosy: + miss-islingtonpull_requests: + <pull%5Frequest21729>
2020-10-16 16:47:32 Mark.Shannon set messages: +
2020-10-16 16:28:49 Mark.Shannon set pull_requests: + <pull%5Frequest21689>
2020-10-16 14:06:24 xmorel set nosy: + xmorelmessages: +
2020-01-21 11:47:33 vstinner set messages: +
2020-01-21 10:25:20 vstinner set pull_requests: + <pull%5Frequest17488>
2019-12-30 11:19:02 Mark.Shannon set status: open -> closedresolution: fixedstage: patch review -> resolved
2019-11-22 13:28:55 vstinner set messages: +
2019-11-22 06:35:20 gregory.p.smith set messages: + versions: + Python 3.9, - Python 3.8
2019-11-21 14:47:56 Mark.Shannon set messages: +
2019-11-21 10:32:28 Mark.Shannon set messages: +
2019-11-21 10:31:23 Mark.Shannon set pull_requests: + <pull%5Frequest16805>
2019-11-21 10:07:05 vstinner set messages: +
2019-11-21 10:06:22 vstinner set nosy: + vstinnermessages: +
2019-04-09 23:32:02 cheryl.sabella set nosy: + cheryl.sabellamessages: +
2018-07-08 19:44:06 gregory.p.smith set nosy: + gregory.p.smith, ncoghlan, serhiy.storchaka
2018-04-29 18:36:03 Mark.Shannon set keywords: + patchstage: patch reviewpull_requests: + <pull%5Frequest6337>
2018-04-29 18:31:10 Mark.Shannon set messages: -
2018-04-29 18:30:39 Mark.Shannon set messages: +
2018-04-29 18:28:42 Mark.Shannon create