-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
gh-142961: Fix constant folding len(tuple) in JIT #142963
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
gh-142961: Fix constant folding len(tuple) in JIT #142963
Conversation
|
@corona10 I think this was introduced in the |
corona10
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm!
Python/bytecodes.c
Outdated
| value = PyStackRef_FromPyObjectBorrow(ptr); | ||
| } | ||
|
|
||
| tier2 op(_SWAP_CALL_ARG_LOAD_CONST_INLINE_BORROW, (ptr/4, callable, null, arg -- res, a, c)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you give this a name that describes what it does. It doesn't call anything, nor have an argument.
callable must be the builtin len function, so is immortal and can be dropped. Avoid the register shuffle:
| tier2 op(_SWAP_CALL_ARG_LOAD_CONST_INLINE_BORROW, (ptr/4, callable, null, arg -- res, a, c)) { | |
| tier2 op(_LOAD_CONST_INLINE_BORROW_SWAP4_DROP, (ptr/4, callable, null, arg -- res, n, a)) { | |
| assert(_Py_IsImmortal(callable)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not quite done. You don't need to shuffle the values around as much.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I dont shuffle them the following POP_TOP will segfault?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It won't on the default build, as NULL is immortal. You'd need to check on the FT build.
|
Actually, let's not pop the |
|
@markshannon |
|
Oh, I assumed it was. |
The optimization broke and causes segfaults now, but there were no tests so no one noticed. I added a test so we will catch it in the future.
binary_op1#142961