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

Disassembly of Lambdas in 3.11.1 missing stack values and args #102403

Open
jrmccluskey opened this issue Mar 3, 2023 · 0 comments
Open

Disassembly of Lambdas in 3.11.1 missing stack values and args #102403

jrmccluskey opened this issue Mar 3, 2023 · 0 comments
Labels
type-bug An unexpected behavior, bug, or error

Comments

@jrmccluskey
Copy link

Bug report

I'm working on updating a type hinting and inference module in Apache Beam to support CPython 3.11 opcodes and have hit a snag working with test cases involving lambdas. The line dis.dis(lambda: {x for x in ()}, show_caches=True, adaptive=False) return the following in 3.10:

1          0 LOAD_CONST               1   (<code object <setcomp> at 0x7fd2f2b1f5d0, file "<stdin>", line 1>)
              2 LOAD_CONST               2 ('TrivialInferenceTest.testSet.<locals>.<lambda>.<locals>.<setcomp>')
              4 MAKE_FUNCTION            0
              6 LOAD_CONST               3 (())
              8 GET_ITER
             10 CALL_FUNCTION            1
             12 RETURN_VALUE

Disassembly of <code object <setcomp> at 0x7fd2f2b1f5d0, file "<stdin>", line 1>:
346           0 BUILD_SET                0
              2 LOAD_FAST                0 (.0)
        >>    4 FOR_ITER                 4 (to 14)
              6 STORE_FAST               1 (x)
              8 LOAD_FAST                1 (x)
             10 SET_ADD                  2
             12 JUMP_ABSOLUTE            2 (to 4)
        >>   14 RETURN_VALUE

But in 3.11 we get:

  1           0 RESUME                   0
              2 LOAD_CONST               1 (<code object <setcomp> at 0x7fd2f2b1f5d0, file "<stdin>", line 1>)
              4 MAKE_FUNCTION            0
              6 LOAD_CONST               2 (())
              8 GET_ITER
             10 PRECALL                  0
             12 CACHE                    0
             14 CALL                     0
             16 CACHE                    0
             18 CACHE                    0
             20 CACHE                    0
             22 CACHE                    0
             24 RETURN_VALUE

Disassembly of <code object <setcomp> at 0x7fd2f2b1f5d0, file "<stdin>", line 1>:
  1           0 RESUME                   0
              2 BUILD_SET                0
              4 LOAD_FAST                0 (.0)
        >>    6 FOR_ITER                 4 (to 16)
              8 STORE_FAST               1 (x)
             10 LOAD_FAST                1 (x)
             12 SET_ADD                  2
             14 JUMP_BACKWARD            5 (to 6)
        >>   16 RETURN_VALUE

The 3.11 output has two distinct difference: it isn't pushing a qualified name for the lambda onto the stack for MAKE_FUNCTION, and the PRECALL and CALL opcodes have args of 0 indicating that there are no args to be passed to the function despite there being a constant on the top of the stack when CALL is executed. Is this expected behavior? I haven't been able to find any documentation around lambda handling being changed, and the existing documentation for the opcodes leads me to believe this is unintended.

Your environment

  • CPython versions tested on: 3.10, 3.11
  • Operating system and architecture: Linux, x86
@jrmccluskey jrmccluskey added the type-bug An unexpected behavior, bug, or error label Mar 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

1 participant