-
-
Notifications
You must be signed in to change notification settings - Fork 34.4k
gh-131798: JIT: Propagate the result in _BINARY_OP_SUBSCR_TUPLE_INT
#133003
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| Propagate the return type of ``_BINARY_OP_SUBSCR_TUPLE_INT`` in JIT. Patch | ||
| by Tomas Roun |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -370,6 +370,20 @@ dummy_func(void) { | |||||||||||||||||||||||||||||||||||||||||||
| res = sym_new_type(ctx, &PyUnicode_Type); | ||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| op(_BINARY_OP_SUBSCR_TUPLE_INT, (left, right -- res)) { | ||||||||||||||||||||||||||||||||||||||||||||
| assert(sym_matches_type(left, &PyTuple_Type)); | ||||||||||||||||||||||||||||||||||||||||||||
| if (sym_is_const(ctx, right)) { | ||||||||||||||||||||||||||||||||||||||||||||
| assert(PyLong_CheckExact(sym_get_const(ctx, right))); | ||||||||||||||||||||||||||||||||||||||||||||
| long index = PyLong_AsLong(sym_get_const(ctx, right)); | ||||||||||||||||||||||||||||||||||||||||||||
| assert(index >= 0); | ||||||||||||||||||||||||||||||||||||||||||||
| assert(index < sym_tuple_length(left)); | ||||||||||||||||||||||||||||||||||||||||||||
| res = sym_tuple_getitem(ctx, left, index); | ||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
| else { | ||||||||||||||||||||||||||||||||||||||||||||
| res = sym_new_not_null(ctx); | ||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+375
to
+391
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @tomasr8, this can be improved to handle abstract tuples that may not be constant (and it cleans things up, since it includes a length check):
Suggested change
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
@brandtbucher, I think this already handles abstract tuples? Assuming that abstract means those that have But yeah, we can simplify the code since
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Your current code is gated on
Sounds like you found your next PR. :)
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, I completely misunderstood, sorry. I thought you were checking whether the tuple was const, not the index. Disregard!
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no worries :) I think we can still simplify the code a bit though! |
||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| op(_TO_BOOL, (value -- res)) { | ||||||||||||||||||||||||||||||||||||||||||||
| int already_bool = optimize_to_bool(this_instr, ctx, value, &res); | ||||||||||||||||||||||||||||||||||||||||||||
| if (!already_bool) { | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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'm not sure these asserts are actually needed. The instruction will deopt when this is not true so perhaps we can remove them?
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.
Interesting, we are actually hitting the assertion:
I guess I need to move the
DEOPT_IFchecks into a separate guard for it to work?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.
Check out the code for
sym_tuple_length. It can return -1 if the length is not known. So for example if you propagate a PyTuple_Type, but not the length, it will fail.You need to check that the length is not -1.
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.
Got it, thanks! I somehow didn't realize you can know something is a tuple but not know its length..