-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
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
Conversation
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
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! |
Hey @Fidget-Spinner did you make the requested changes? You need to do the dance to make Bedevere happy. :-) |
I have made the requested changes; please review again. |
Odd. That test is still failing?! |
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.
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.)
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
pure op (_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
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
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.
@@ -220,7 +220,7 @@ dummy_func(void) { | |||
} | |||
|
|||
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:
static inline PyObject *
sym_get_const(_Py_UOpsSymType *sym)
{
assert(sym_is_const(sym));
assert(sym->const_val);
return sym->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.
@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 |
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).
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!
Since you've addressed Mark's question I don't see a reason to wait for his explicit approval. |
TO_BOOL
#115685