Skip to content

Commit 41b3cff

Browse files
committed
gh-131798: JIT: Narrow the return type of _BINARY_SLICE to original container type
Signed-off-by: Manjusaka <me@manjusaka.me>
1 parent 3dfed23 commit 41b3cff

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

Lib/test/test_capi/test_opt.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1942,6 +1942,23 @@ def testfunc(n):
19421942
self.assertNotIn("_COMPARE_OP_INT", uops)
19431943
self.assertNotIn("_GUARD_IS_TRUE_POP", uops)
19441944

1945+
def test_binary_slice(self):
1946+
def testfunc(n):
1947+
a = [1, 2, 3, 4]
1948+
x = 1
1949+
y = 3
1950+
for _ in range(n):
1951+
b = a[x: y]
1952+
assert b == [2, 3]
1953+
_, ex = self._run_with_optimizer(testfunc, TIER2_THRESHOLD)
1954+
# self.assertEqual(res, TIER2_THRESHOLD)
1955+
self.assertIsNotNone(ex)
1956+
uops = get_opnames(ex)
1957+
print("-------")
1958+
for uop in uops:
1959+
print(uop)
1960+
1961+
19451962

19461963
def global_identity(x):
19471964
return x

Python/optimizer_bytecodes.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,10 @@ dummy_func(void) {
155155
sym_set_type(nos, &PyFloat_Type);
156156
}
157157

158+
op(_BINARY_SLICE, (container, end, start -- res)) {
159+
res = sym_new_type(ctx, sym_get_type(container));
160+
}
161+
158162
op(_BINARY_OP, (left, right -- res)) {
159163
bool lhs_int = sym_matches_type(left, &PyLong_Type);
160164
bool rhs_int = sym_matches_type(right, &PyLong_Type);

Python/optimizer_cases.c.h

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)