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

bpo-46072: Include length in stats for UNPACK_SEQUENCE. #31254

Merged
merged 1 commit into from
Feb 14, 2022

Conversation

markshannon
Copy link
Member

@markshannon markshannon commented Feb 10, 2022

Copy link
Member

@brandtbucher brandtbucher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, I'm curious to see the results.

(I'm gonna be really surprised if anybody is out here unpacking zero-length iterables, though.)

@sweeneyde
Copy link
Member

(I'm gonna be really surprised if anybody is out here unpacking zero-length iterables, though.)

To my surprise, this works:

() = []

@brandtbucher
Copy link
Member

brandtbucher commented Feb 11, 2022

To my surprise, this works:

() = []

...for some definition of "works". The whole thing gets peepholed out. ;)

I think maybe once long ago I used something like this to "assert" that an iterator I used was completely exhausted (the idea being that it would raise a TypeError if not):

it = iter(something)

# ...do some stuff...

[] = it  # Fails if there are any remaining items.

I thought it was pretty clever at the time. :)

@markshannon
Copy link
Member Author

UNPACK_SEQUENCE 0 does occur. In this:

def f(x):
    match x:
        case T():
            pass
  1           0 RESUME                   0

  2           2 LOAD_FAST                0 (x)

  3           4 LOAD_GLOBAL              0 (T)
              6 LOAD_CONST               1 (())
              8 MATCH_CLASS              0
             10 COPY                     1
             12 POP_JUMP_IF_NONE        10 (to 20)
             14 UNPACK_SEQUENCE          0

  4          16 LOAD_CONST               0 (None)
             18 RETURN_VALUE

  3     >>   20 POP_TOP
             22 LOAD_CONST               0 (None)
             24 RETURN_VALUE

@markshannon markshannon merged commit 15ee555 into python:main Feb 14, 2022
@markshannon markshannon deleted the unpack-sequence-len-stats branch February 14, 2022 10:01
@brandtbucher
Copy link
Member

UNPACK_SEQUENCE 0 does occur.

Interesting. That's a common case that's worth improving.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants