Skip to content
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

Simplify bytecodes for try-finally, try-except and with blocks. #77568

Closed
markshannon opened this issue Apr 29, 2018 · 14 comments
Closed

Simplify bytecodes for try-finally, try-except and with blocks. #77568

markshannon opened this issue Apr 29, 2018 · 14 comments
Labels
3.9 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs)

Comments

@markshannon
Copy link
Member

BPO 33387
Nosy @gpshead, @ncoghlan, @vstinner, @masklinn, @markshannon, @serhiy-storchaka, @csabella, @miss-islington, @iritkatriel
PRs
  • bpo-33387: Simplify bytecodes for try-finally, try-except and with blocks. #6641
  • bpo-33387: Correct release version to 3.9 for new bytecodes #17318
  • bpo-33387: Fix compiler warning in frame_block_unwind() #18099
  • bpo-33387: Correct name of bytecode in change note. #22723
  • [3.9] bpo-33387: Correct name of bytecode in change note. (GH-22723) #22765
  • bpo-33387: update documentation for exception handling opcode changes #24334
  • Note: 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:

    assignee = None
    closed_at = <Date 2021-01-26.10:27:14.384>
    created_at = <Date 2018-04-29.18:28:42.198>
    labels = ['interpreter-core', '3.9']
    title = 'Simplify bytecodes for try-finally, try-except and with blocks.'
    updated_at = <Date 2021-01-26.10:27:14.384>
    user = 'https://github.com/markshannon'

    bugs.python.org fields:

    activity = <Date 2021-01-26.10:27:14.384>
    actor = 'iritkatriel'
    assignee = 'none'
    closed = True
    closed_date = <Date 2021-01-26.10:27:14.384>
    closer = 'iritkatriel'
    components = ['Interpreter Core']
    creation = <Date 2018-04-29.18:28:42.198>
    creator = 'Mark.Shannon'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 33387
    keywords = ['patch']
    message_count = 14.0
    messages = ['315905', '339817', '357147', '357148', '357155', '357172', '357246', '357279', '360393', '378715', '378720', '385664', '385679', '385703']
    nosy_count = 9.0
    nosy_names = ['gregory.p.smith', 'ncoghlan', 'vstinner', 'xmorel', 'Mark.Shannon', 'serhiy.storchaka', 'cheryl.sabella', 'miss-islington', 'iritkatriel']
    pr_nums = ['6641', '17318', '18099', '22723', '22765', '24334']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue33387'
    versions = ['Python 3.9']

    @markshannon
    Copy link
    Member Author

    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:

    @markshannon markshannon added 3.8 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) labels Apr 29, 2018
    @csabella
    Copy link
    Contributor

    csabella commented Apr 9, 2019

    What would be the best way to resolve the discussion between this and bpo-32949? Would it be good to try to get one of them into 3.8?

    @vstinner
    Copy link
    Member

    Mark merged his PR 6641 but forgot to mention bpo-33387:

    commit fee5526
    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. (bpo-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.
    

    @vstinner
    Copy link
    Member

    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
    

    @markshannon
    Copy link
    Member Author

    Thanks for noticing.
    #17318

    @markshannon
    Copy link
    Member Author

    New changeset 82f897b by Mark Shannon in branch 'master':
    Correct release version to 3.9 for RERAISE and WITH_EXCEPT_START bytecodes. (bpo-17318)
    82f897b

    @gpshead
    Copy link
    Member

    gpshead commented Nov 22, 2019

    sweet! =)

    @gpshead gpshead added 3.9 only security fixes and removed 3.8 only security fixes labels Nov 22, 2019
    @vstinner
    Copy link
    Member

    Can this issue be closed now?

    @vstinner
    Copy link
    Member

    New changeset 629023c by Victor Stinner in branch 'master':
    bpo-33387: Fix compiler warning in frame_block_unwind() (GH-18099)
    629023c

    @masklinn
    Copy link
    Mannequin

    masklinn mannequin commented Oct 16, 2020

    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?

    @markshannon
    Copy link
    Member Author

    Yes, thanks for pointing that out.

    @iritkatriel
    Copy link
    Member

    I'm reopening this to delete an obsolete comment left behind.

    @iritkatriel
    Copy link
    Member

    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

    @markshannon
    Copy link
    Member Author

    New changeset dea5bf9 by Irit Katriel in branch 'master':
    bpo-33387: update documentation for exception handling opcode changes (GH-24334)
    dea5bf9

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.9 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs)
    Projects
    None yet
    Development

    No branches or pull requests

    5 participants