Skip to content

gh-131798: JIT: Narrow the return type of _BINARY_SLICE to original container type #133527

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
17 changes: 17 additions & 0 deletions Lib/test/test_capi/test_opt.py
Original file line number Diff line number Diff line change
Expand Up @@ -1942,6 +1942,23 @@ def testfunc(n):
self.assertNotIn("_COMPARE_OP_INT", uops)
self.assertNotIn("_GUARD_IS_TRUE_POP", uops)

def test_binary_slice(self):
def testfunc(n):
a = [1, 2, 3, 4]
x = 1
y = 3
for _ in range(n):
b = a[x: y]
assert b == [2, 3]
_, ex = self._run_with_optimizer(testfunc, TIER2_THRESHOLD)
# self.assertEqual(res, TIER2_THRESHOLD)
self.assertIsNotNone(ex)
uops = get_opnames(ex)
print("-------")
for uop in uops:
print(uop)



def global_identity(x):
return x
Expand Down
4 changes: 4 additions & 0 deletions Python/optimizer_bytecodes.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,10 @@ dummy_func(void) {
sym_set_type(nos, &PyFloat_Type);
}

op(_BINARY_SLICE, (container, end, start -- res)) {
res = sym_new_type(ctx, sym_get_type(container));
}

op(_BINARY_OP, (left, right -- res)) {
bool lhs_int = sym_matches_type(left, &PyLong_Type);
bool rhs_int = sym_matches_type(right, &PyLong_Type);
Expand Down
4 changes: 3 additions & 1 deletion Python/optimizer_cases.c.h

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

Loading