-
-
Notifications
You must be signed in to change notification settings - Fork 29.9k
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
Simplify MAKE_FUNCTION #71282
Comments
Implemented as per https://mail.python.org/pipermail/python-dev/2016-April/144135.html |
Attached are modifications to the patch based on feedback from Nikita. It produces a larger patch tho. The changes are to combine return branches in compiler_make_closure & to combine code between compiler_function & compiler_lambda into compiler_default_arguments |
At first look your patch looks good (I'll make more detailed review later), but you should wait until we have finished all work related to the conversion to wordcode. |
May've been best to wait on posting a patch, but long weekend yesterday made time available mkfu3 updates mkfu2 with wordcode. Includes fix to EXTENDED_ARG documentation |
In general the patch LGTM, besides few minor comments. But new implementation uses longer bytecode for annotations. Current code packs argument names in one constant tuple: $ ./python -m dis
def f(x: int, y: str, z: float): pass
1 0 LOAD_NAME 0 (int)
2 LOAD_NAME 1 (str)
4 LOAD_NAME 2 (float)
6 LOAD_CONST 0 (('x', 'y', 'z'))
8 LOAD_CONST 1 (<code object f at 0xb6fc1640, file "<stdin>", line 1>)
10 LOAD_CONST 2 ('f')
12 EXTENDED_ARG 4
14 EXTENDED_ARG 1024
16 MAKE_FUNCTION 262144
18 STORE_NAME 3 (f)
20 LOAD_CONST 3 (None)
22 RETURN_VALUE New code uses LOAD_CONST for every name: $ ./python -m dis
def f(x: int, y: str, z: float): pass
1 0 LOAD_CONST 0 ('x')
2 LOAD_NAME 0 (int)
4 LOAD_CONST 1 ('y')
6 LOAD_NAME 1 (str)
8 LOAD_CONST 2 ('z')
10 LOAD_NAME 2 (float)
12 BUILD_MAP 3
14 LOAD_CONST 3 (<code object f at 0xb7035a20, file "<stdin>", line 1>)
16 LOAD_CONST 4 ('f')
18 MAKE_FUNCTION 4
20 STORE_NAME 3 (f)
22 LOAD_CONST 5 (None)
24 RETURN_VALUE With new opcode that creates a dict from values and a tuple of keys (bpo-27140) new code would be only one instruction longer. |
Now with adding BUILD_CONST_KEY_MAP I think MAKE_FUNCTION can be more compact. |
mkfu4 implements bpo-27140. It doesn't special case 1-tuples into It may be easier to have I'm also noticing that it could've been suggested to go to the extreme with BUILD_CONST_KEY_MAP where instead of relying on peepholer to constant fold tuple, we implement constant folding const keys entirely there. Just a random thought, not a suggestion or anything else |
Added more comments on Rietveld. |
Kind of amusing how visit_argannoation logic went full circle. Makes sense considering pre-mkfu patch the ABI was quite similar on that front |
Yes, this is why I wanted first push the patch with BUILD_CONST_KEY_MAP. |
Regenerated for review. |
New changeset 8a0fe3481c91 by Serhiy Storchaka in branch 'default': |
Pushed with minor changes. Thank you for your contribution Demur! You change to the documentation of EXTENDED_ARG isn't pushed. I would prefer to see it as a part of larger documentation patch in bpo-26647. After pushing I found a bug (similar bug was existing) in compile.c. I'll open separate issue for this. |
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:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: