-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
gh-131798: Optimize _UNARY_NEGATIVE
#135223
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
base: main
Are you sure you want to change the base?
Conversation
Python/optimizer_bytecodes.c
Outdated
@@ -467,6 +467,15 @@ dummy_func(void) { | |||
res = sym_new_truthiness(ctx, value, false); | |||
} | |||
|
|||
op(_UNARY_NEGATIVE, (value -- res)) { | |||
if (sym_matches_type(value, &PyLong_Type) || sym_matches_type(value, &PyFloat_Type)) { |
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.
I think we can add a check for const, and we can setup the res by using sym_new_const
. Not sure this is worth here cc @brandtbucher @Fidget-Spinner
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.
I'd hold off on that, since our plan is to automatically constant-evaluate stuff like this. Let's stick with hand-writing type-based optimizations like this for now.
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.
I did not add a const clause for this since it felt more related to #132733.
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.
Looks good, just some suggested improvements. Thanks!
Misc/NEWS.d/next/Core_and_Builtins/2025-06-06-19-17-22.gh-issue-131798.XoV8Eb.rst
Outdated
Show resolved
Hide resolved
Python/optimizer_bytecodes.c
Outdated
@@ -467,6 +467,15 @@ dummy_func(void) { | |||
res = sym_new_truthiness(ctx, value, false); | |||
} | |||
|
|||
op(_UNARY_NEGATIVE, (value -- res)) { | |||
if (sym_matches_type(value, &PyLong_Type) || sym_matches_type(value, &PyFloat_Type)) { |
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.
I'd hold off on that, since our plan is to automatically constant-evaluate stuff like this. Let's stick with hand-writing type-based optimizations like this for now.
Thanks for the review! @brandtbucher @Zheaoli |
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.
Awesome! Can you just fix the merge conflict in the test file?
Uh oh!
There was an error while loading. Please reload this page.