-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
GH-132732: Use pure op machinery to optimize various instructions with _POP_TOP
and _POP_TWO
#137577
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
_POP_TOP
and _POP_TWO
relevant instructions_POP_TOP
and _POP_TWO
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.
This is super cool! Just a quick run-through for now:
Misc/NEWS.d/next/Core_and_Builtins/2025-08-09-04-07-05.gh-issue-132732.8BiIVJ.rst
Outdated
Show resolved
Hide resolved
When you're done making the requested changes, leave the 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.
Very cool, just one nit.
Python/optimizer_bytecodes.c
Outdated
@@ -412,6 +413,7 @@ dummy_func(void) { | |||
} | |||
|
|||
op(_UNARY_INVERT, (value -- res)) { | |||
REPLACE_OPCODE_IF_EVALUATES_PURE(value); |
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 this isn't pure for bool. ~True
raises a warning.
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.
Oof, nice catch.
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.
Does it make sense to guard against booleans? Or are we saying that we can't do that/it's not worth it?
Also, can one of you explain why ~True
isn't pure and how you discovered this/where the warning is raised?
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.
We could guard against booleans I think.
Anything that raises a warning isn't pure as that means the optimizer might cause a warning to be emitted during optimizing code, and we don't want that.
To test it out, try typing ~True into the current main's CPython repl. It's a recent deprecation so it wont show up on your system cpython probably, but a warning is emitted.
I found this out because I vaguely recalled reading about it somewhere https://discuss.python.org/t/bool-deprecation/62232
Uh oh!
There was an error while loading. Please reload this page.