This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Stray RESUME opcode for unused lambda
Type: behavior Stage: resolved
Components: Interpreter Core Versions: Python 3.11
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Mark.Shannon Nosy List: Mark.Shannon, erlendaasland, nedbat, pablogsal
Priority: Keywords: 3.11regression, patch

Created on 2022-01-09 14:40 by nedbat, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 30513 merged Mark.Shannon, 2022-01-10 11:41
PR 30515 merged Mark.Shannon, 2022-01-10 12:35
Messages (9)
msg410151 - (view) Author: Ned Batchelder (nedbat) * (Python triager) Date: 2022-01-09 14:40
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
msg410200 - (view) Author: Mark Shannon (Mark.Shannon) * (Python committer) Date: 2022-01-10 11:14
Thanks, Ned.
msg410202 - (view) Author: Mark Shannon (Mark.Shannon) * (Python committer) Date: 2022-01-10 11:44
Pablo, I've marked this as a release blocker so this bug doesn't get into 3.11a4.
msg410205 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2022-01-10 11:55
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
msg410206 - (view) Author: Mark Shannon (Mark.Shannon) * (Python committer) Date: 2022-01-10 12:29
New changeset ec0c392f34ee2474ceacf66881f05546b540e2d1 by Mark Shannon in branch 'main':
bpo-46314: Remove extra RESUME when compiling a lamdba. (GH-30513)
https://github.com/python/cpython/commit/ec0c392f34ee2474ceacf66881f05546b540e2d1
msg410208 - (view) Author: Mark Shannon (Mark.Shannon) * (Python committer) Date: 2022-01-10 12:30
Ok, I'll add a news item in that case.
msg410393 - (view) Author: Ned Batchelder (nedbat) * (Python triager) Date: 2022-01-12 12:14
This fixes the problems I was seeing, thanks.
msg410394 - (view) Author: Erlend E. Aasland (erlendaasland) * (Python triager) Date: 2022-01-12 13:19
> This fixes the problems I was seeing, thanks.

Good; removing release blocker status. Keeping this open until Mark has added a NEWS item.
msg410412 - (view) Author: Mark Shannon (Mark.Shannon) * (Python committer) Date: 2022-01-12 16:33
The news item was added in PR 30515
History
Date User Action Args
2022-04-11 14:59:54adminsetgithub: 90472
2022-01-12 16:33:23Mark.Shannonsetstatus: open -> closed
resolution: fixed
messages: + msg410412

stage: patch review -> resolved
2022-01-12 13:19:03erlendaaslandsetpriority: release blocker ->
nosy: + erlendaasland
messages: + msg410394

2022-01-12 12:14:06nedbatsetmessages: + msg410393
2022-01-12 04:44:22zach.waresetnosy: - barry, terry.reedy, paul.moore, ronaldoussoren, vstinner, tim.golden, ned.deily, ezio.melotti, eric.araujo, mrabarnett, r.david.murray, asvetlov, zach.ware, yselivanov, koobs, steve.dower, dstufft, Alex.Willmer, lys.nikolaou
type: security -> behavior
2022-01-12 04:28:24larrysetnosy: - larry
components: - Build, Demos and Tools, Distutils, Documentation, Extension Modules, IDLE, Installation, Library (Lib), macOS, Regular Expressions, Tests, Tkinter, Unicode, Windows, XML, 2to3 (2.x to 3.x conversion tool), ctypes, IO, Cross-Build, email, asyncio, Argument Clinic, FreeBSD, SSL, C API, Subinterpreters, Parser
2022-01-12 04:25:46alwaysasetupsetnosy: + terry.reedy, larry, paul.moore, tim.golden, lys.nikolaou, asvetlov, ezio.melotti, koobs, r.david.murray, zach.ware, steve.dower, ned.deily, barry, Alex.Willmer, eric.araujo, ronaldoussoren, dstufft, yselivanov, vstinner, mrabarnett
type: behavior -> security
components: + Build, Demos and Tools, Distutils, Documentation, Extension Modules, IDLE, Installation, Library (Lib), macOS, Regular Expressions, Tests, Tkinter, Unicode, Windows, XML, 2to3 (2.x to 3.x conversion tool), ctypes, IO, Cross-Build, email, asyncio, Argument Clinic, FreeBSD, SSL, C API, Subinterpreters, Parser
2022-01-10 12:35:43Mark.Shannonsetkeywords: + patch
stage: patch review
pull_requests: + pull_request28718
2022-01-10 12:30:42Mark.Shannonsetmessages: + msg410208
2022-01-10 12:29:16Mark.Shannonsetmessages: + msg410206
2022-01-10 11:55:53pablogsalsetmessages: + msg410205
2022-01-10 11:44:38Mark.Shannonsetnosy: + pablogsal
messages: + msg410202

keywords: - patch
stage: patch review -> (no value)
2022-01-10 11:41:27Mark.Shannonsetkeywords: + patch
stage: patch review
pull_requests: + pull_request28716
2022-01-10 11:14:04Mark.Shannonsetpriority: normal -> release blocker
assignee: Mark.Shannon
type: behavior
messages: + msg410200
2022-01-09 14:40:04nedbatcreate