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

Stray RESUME opcode for unused lambda #90472

Closed
nedbat opened this issue Jan 9, 2022 · 9 comments
Closed

Stray RESUME opcode for unused lambda #90472

nedbat opened this issue Jan 9, 2022 · 9 comments
Assignees
Labels
3.11 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error

Comments

@nedbat
Copy link
Member

nedbat commented Jan 9, 2022

BPO 46314
Nosy @nedbat, @markshannon, @pablogsal, @erlend-aasland
PRs
  • bpo-46314: Remove extra RESUME when compiling a lamdba. #30513
  • bpo-46314: News item for GH-30513 #30515
  • 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/markshannon'
    closed_at = <Date 2022-01-12.16:33:23.019>
    created_at = <Date 2022-01-09.14:40:03.997>
    labels = ['interpreter-core', 'type-bug', '3.11']
    title = 'Stray RESUME opcode for unused lambda'
    updated_at = <Date 2022-01-12.16:33:23.018>
    user = 'https://github.com/nedbat'

    bugs.python.org fields:

    activity = <Date 2022-01-12.16:33:23.018>
    actor = 'Mark.Shannon'
    assignee = 'Mark.Shannon'
    closed = True
    closed_date = <Date 2022-01-12.16:33:23.019>
    closer = 'Mark.Shannon'
    components = ['Interpreter Core']
    creation = <Date 2022-01-09.14:40:03.997>
    creator = 'nedbat'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 46314
    keywords = ['patch', '3.11regression']
    message_count = 9.0
    messages = ['410151', '410200', '410202', '410205', '410206', '410208', '410393', '410394', '410412']
    nosy_count = 4.0
    nosy_names = ['nedbat', 'Mark.Shannon', 'pablogsal', 'erlendaasland']
    pr_nums = ['30513', '30515']
    priority = None
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue46314'
    versions = ['Python 3.11']

    @nedbat
    Copy link
    Member Author

    nedbat commented Jan 9, 2022

    This code seems to get a RESUME opcode where no function call is happening:

        a = 1
        fn = lambda 2
        b = 3

    Here is the disassembly. Offset 6 has a RESUME opcode for line 2:

    Python 3.11.0a3+ (heads/main:0fc58c1e05, Jan  8 2022, 19:45:58) [Clang 12.0.0 (clang-1200.0.32.29)] on darwin
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import dis
    >>> dis.dis("""\
    ... a = 1
    ... fn = lambda: 2
    ... b = 3
    ... """)
                  0 RESUME                   0

    1 2 LOAD_CONST 0 (1)
    4 STORE_NAME 0 (a)

    2 6 RESUME 0
    8 LOAD_CONST 1 (<code object <lambda> at 0x10772c2d0, file "<dis>", line 2>)
    10 MAKE_FUNCTION 0
    12 STORE_NAME 1 (fn)

    3 14 LOAD_CONST 2 (3)
    16 STORE_NAME 2 (b)
    18 LOAD_CONST 3 (None)
    20 RETURN_VALUE

    Disassembly of <code object <lambda> at 0x10772c2d0, file "<dis>", line 2>:
    2 0 RESUME 0
    2 LOAD_CONST 1 (2)
    4 RETURN_VALUE

    This causes an extra "call" event when tracing:

    ---< bug233.py >--------------------------------------------------------

    import linecache, os.path, sys
    
    def trace(frame, event, arg):
        if (event != "line") and ("bug233" in frame.f_code.co_filename):
            lineno = frame.f_lineno
            first = frame.f_code.co_firstlineno
            source = linecache.getline(frame.f_code.co_filename, lineno) if lineno else "******"
            file = os.path.basename(frame.f_code.co_filename)
            print("{} {}@{!s:4} (first={}): {}".format(event[:4], file, lineno, first, source.rstrip()))
        return trace
    
    print(sys.version)
    sys.settrace(trace)
    
    def f():
        a = 1
        fn = lambda: 2
        b = 3
    f()

    % python3.10 bug233.py
    3.10.1 (main, Dec 14 2021, 08:30:13) [Clang 12.0.0 (clang-1200.0.32.29)]
    call bug233.py@15 (first=15): def f():
    retu bug233.py@18 (first=15): b = 3

    % python3.11 bug233.py
    3.11.0a3+ (heads/main:0fc58c1e05, Jan 8 2022, 19:45:58) [Clang 12.0.0 (clang-1200.0.32.29)]
    call bug233.py@15 (first=15): def f():
    call bug233.py@17 (first=15): fn = lambda: 2
    retu bug233.py@18 (first=15): b = 3

    @nedbat nedbat added 3.11 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) labels Jan 9, 2022
    @markshannon
    Copy link
    Member

    Thanks, Ned.

    @markshannon markshannon added type-bug An unexpected behavior, bug, or error release-blocker labels Jan 10, 2022
    @markshannon markshannon self-assigned this Jan 10, 2022
    @markshannon
    Copy link
    Member

    Pablo, I've marked this as a release blocker so this bug doesn't get into 3.11a4.

    @pablogsal
    Copy link
    Member

    Unfortunately the release of 3.11.0a4 is already underway and we are waiting for Steve's windows binaries, so this will need to wait for alpha 5

    @markshannon
    Copy link
    Member

    New changeset ec0c392 by Mark Shannon in branch 'main':
    bpo-46314: Remove extra RESUME when compiling a lamdba. (GH-30513)
    ec0c392

    @markshannon
    Copy link
    Member

    Ok, I'll add a news item in that case.

    @alwaysasetup alwaysasetup mannequin added build The build process and cross-build stdlib Python modules in the Lib dir docs Documentation in the Doc dir extension-modules C modules in the Modules dir topic-IDLE topic-installation OS-mac topic-regex tests Tests in the Lib/test dir topic-tkinter topic-unicode labels Jan 12, 2022
    @nedbat
    Copy link
    Member Author

    nedbat commented Jan 12, 2022

    This fixes the problems I was seeing, thanks.

    @erlend-aasland
    Copy link
    Contributor

    This fixes the problems I was seeing, thanks.

    Good; removing release blocker status. Keeping this open until Mark has added a NEWS item.

    @markshannon
    Copy link
    Member

    The news item was added in PR 30515

    @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.11 only security fixes 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

    6 participants