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

Dead code in wordcode #72703

Closed
serhiy-storchaka opened this issue Oct 24, 2016 · 8 comments
Closed

Dead code in wordcode #72703

serhiy-storchaka opened this issue Oct 24, 2016 · 8 comments
Assignees
Labels
3.7 (EOL) end of life interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error

Comments

@serhiy-storchaka
Copy link
Member

BPO 28517
Nosy @rhettinger, @gpshead, @serhiy-storchaka, @matrixise, @serprex
PRs
  • [Do Not Merge] Convert Misc/NEWS so that it is managed by towncrier #552
  • Files
  • peephole_remove_unreachable_code.patch
  • 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 = 'https://github.com/serhiy-storchaka'
    closed_at = <Date 2016-10-25.07:20:39.328>
    created_at = <Date 2016-10-24.05:16:39.388>
    labels = ['interpreter-core', 'type-bug', '3.7']
    title = 'Dead code in wordcode'
    updated_at = <Date 2018-11-08.21:09:05.632>
    user = 'https://github.com/serhiy-storchaka'

    bugs.python.org fields:

    activity = <Date 2018-11-08.21:09:05.632>
    actor = 'gregory.p.smith'
    assignee = 'serhiy.storchaka'
    closed = True
    closed_date = <Date 2016-10-25.07:20:39.328>
    closer = 'serhiy.storchaka'
    components = ['Interpreter Core']
    creation = <Date 2016-10-24.05:16:39.388>
    creator = 'serhiy.storchaka'
    dependencies = []
    files = ['45202']
    hgrepos = []
    issue_num = 28517
    keywords = ['patch']
    message_count = 8.0
    messages = ['279297', '279298', '279320', '279348', '279359', '279366', '279367', '329486']
    nosy_count = 6.0
    nosy_names = ['rhettinger', 'gregory.p.smith', 'python-dev', 'serhiy.storchaka', 'matrixise', 'Demur Rumed']
    pr_nums = ['552']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue28517'
    versions = ['Python 3.6', 'Python 3.7']

    @serhiy-storchaka
    Copy link
    Member Author

    >>> 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 LOAD_CONST 1 (1)
    6 COMPARE_OP 2 (==)
    9 POP_JUMP_IF_FALSE 16

    3 12 LOAD_CONST 1 (1)
    15 RETURN_VALUE

    4 >> 16 LOAD_FAST 0 (test)
    19 LOAD_CONST 2 (2)
    22 COMPARE_OP 2 (==)
    25 POP_JUMP_IF_FALSE 32

    5 28 LOAD_CONST 2 (2)
    31 RETURN_VALUE

    6 >> 32 LOAD_CONST 3 (3)
    35 RETURN_VALUE

    Python 3.6:

    2 0 LOAD_FAST 0 (test)
    2 LOAD_CONST 1 (1)
    4 COMPARE_OP 2 (==)
    6 POP_JUMP_IF_FALSE 14

    3 8 LOAD_CONST 1 (1)
    10 RETURN_VALUE
    12 JUMP_FORWARD 12 (to 26)

    4 >> 14 LOAD_FAST 0 (test)
    16 LOAD_CONST 2 (2)
    18 COMPARE_OP 2 (==)
    20 POP_JUMP_IF_FALSE 26

    5 22 LOAD_CONST 2 (2)
    24 RETURN_VALUE

    6 >> 26 LOAD_CONST 3 (3)
    28 RETURN_VALUE

    Note JUMP_FORWARD after RETURN_VALUE in 3.6 listing.

    @serhiy-storchaka serhiy-storchaka added 3.7 (EOL) end of life interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error labels Oct 24, 2016
    @serhiy-storchaka
    Copy link
    Member Author

    Proposed patch fixes removing unreachable code after RETURN_VALUE in peephole optimizer.

    @serhiy-storchaka serhiy-storchaka self-assigned this Oct 24, 2016
    @matrixise
    Copy link
    Member

    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.

    @rhettinger
    Copy link
    Contributor

    +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.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Oct 25, 2016

    New changeset 5784cc37b5f4 by Serhiy Storchaka in branch '3.6':
    Issue bpo-28517: Fixed of-by-one error in the peephole optimizer that caused
    https://hg.python.org/cpython/rev/5784cc37b5f4

    New changeset 8d571fab4d66 by Serhiy Storchaka in branch 'default':
    Issue bpo-28517: Fixed of-by-one error in the peephole optimizer that caused
    https://hg.python.org/cpython/rev/8d571fab4d66

    @serhiy-storchaka
    Copy link
    Member Author

    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.

    [1] https://github.com/haypo/bytecode

    @matrixise
    Copy link
    Member

    ah ok, thanks for the explanation.

    @gpshead
    Copy link
    Member

    gpshead commented Nov 8, 2018

    the off by one error fix here introduced a new off by one error. PR coming, follow https://bugs.python.org/issue35193 for that.

    @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.7 (EOL) end of life interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    4 participants