Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 34k
gh-115685: Type/values propagate for TO_BOOL in tier 2#115686
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
Uh oh!
There was an error while loading. Please reload this page.
Conversation
Fidget-Spinner commented Feb 19, 2024 • edited by bedevere-app bot
Loading Uh oh!
There was an error while loading. Please reload this page.
edited by bedevere-app bot
Uh oh!
There was an error while loading. Please reload this page.
markshannon 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.
All the res = sym_new_... assignments need to wrapped in OUT_OF_SPACE_IF_NULL
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
When you're done making the requested changes, leave the comment: And if you don't make the requested changes, you will be poked with soft cushions! |
gvanrossum commented Feb 21, 2024
Hey @Fidget-Spinner did you make the requested changes? You need to do the dance to make Bedevere happy. :-) |
Fidget-Spinner commented Feb 21, 2024
I have made the requested changes; please review again. |
gvanrossum commented Feb 21, 2024
Odd. That test is still failing?! |
markshannon 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.
Looks good in general.
There are a few optimizations that have been missed, and beware the side effects of C API calls.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
| assert(PyLong_CheckExact(get_const(right))); | ||
| PyObject*temp=_PyLong_Add((PyLongObject*)get_const(left), | ||
| (PyLongObject*)get_const(right)); |
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.
Maybe there should be s get_long_const() helper which returns (PyLongObject *)get_const(x) and also includes the assert(PyLong_CheckExact()) call, to make code like this more compact. (Same for float.)
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
gvanrossum 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.
One more thing.
Python/bytecodes.c Outdated
| pureop (_POP_TOP_LOAD_CONST_INLINE_BORROW, (ptr/4, pop--value)){ | ||
| TIER_TWO_ONLY; | ||
| DECREF_INPUTS(); | ||
| value=ptr; | ||
| } |
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.
Maybe there could be an even more specialized opcode that doesn't DECREF its input? That would be handy for the case where you introduced this -- the input is known to be None, so we don't really need to bother with the DECREF of the immortal 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.
The expectation is that the _POP_TOP part will be removed in a later pass.LOAD_CONST ; _POP_TOP_LOAD_CONST_INLINE_BORROW -> _LOAD_CONST_INLINE_BORROW
markshannon 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.
Two suggestions
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
gvanrossum 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, let's see if @markshannon agrees.
Python/optimizer_analysis.c Outdated
| { | ||
| sym_set_type(sym, Py_TYPE(const_val)); | ||
| sym_set_flag(sym, TRUE_CONST | KNOWN | NOT_NULL); | ||
| Py_XSETREF(sym->const_val, Py_NewRef(const_val)); |
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 temporary, just ignore this for now. I will remove it in #115817.
| op(_TO_BOOL_NONE, (value--res)){ | ||
| if (sym_get_const(value) ==Py_None){ | ||
| if (sym_is_const(value) && (sym_get_const(value) ==Py_None)){ |
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.
Why is this necessary? Shouldn't sym_get_const return NULL for anything that isn't a constant?
It does seem rather verbose to have to prefix every sys_get_const with a sys_is_const.
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.
In the code:
staticinlinePyObject*sym_get_const(_Py_UOpsSymType*sym){assert(sym_is_const(sym)); assert(sym->const_val); returnsym->const_val}So we assume there is always something there when there's sym_get_const. I think I can just change the contract to return NULL on non constants though.
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.
The new sym_get_const() indeed returns NULL in this case.
gvanrossum commented Feb 28, 2024
@Fidget-Spinner: It looks like this PR is totally out of date. It adds a new ERROR_IF() macro that should probably be done in a separate cleanup pass. I can do that next (once gh-116062 is merged). The key part of this PR is to add optimizer specializations for |
gvanrossum 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, with one nit (to make merging of my PR simpler).
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
gvanrossum 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.
Excellent!
gvanrossum commented Feb 29, 2024
Since you've addressed Mark's question I don't see a reason to wait for his explicit approval. |
TO_BOOL#115685