8000 gh-131798: JIT: Propagate the result in `_BINARY_OP_SUBSCR_TUPLE_INT` by tomasr8 · Pull Request #133003 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

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

Merged
merged 4 commits into from
Apr 26, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix a case when the tuple length is not known
  • Loading branch information
tomasr8 committed Apr 26, 2025
commit dddd56ff271e69215bea67516a88d3dfe99b5db7
11 changes: 9 additions & 2 deletions Python/optimizer_bytecodes.c
Original file line number Diff line number Diff line change
Expand Up @@ -376,8 +376,15 @@ dummy_func(void) {
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);
int tuple_length = sym_tuple_length(left);
if (tuple_length == -1) {
// Unknown length
res = sym_new_not_null(ctx);
}
Comment on lines +380 to +383
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@brandtbucher
Following the previous discussion, I'm wondering if it is correct to return sym_new_not_null here rather than sym_new_unknown?

We have an abstract tuple and we don't know its length so it is impossible to be sure that the index is not out of bounds for the tuple. Given that, I think it is incorrect to return sym_new_not_null here as regular Python code could raise an IndexError. Should we change this to sym_new_unknown?

else {
assert(index < tuple_length);
res = sym_tuple_getitem(ctx, left, index);
}
}
else {
res = sym_new_not_null(ctx);
Expand Down
10 changes: 8 additions & 2 deletions Python/optimizer_cases.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0