Skip to content

Commit c1436ca

Browse files
committed
gh-131798: JIT: Narrow the return type of _GET_LEN to int
Signed-off-by: Manjusaka <[email protected]>
1 parent cb31741 commit c1436ca

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

Lib/test/test_capi/test_opt.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1923,6 +1923,19 @@ def testfunc(n):
19231923
self.assertNotIn("_GUARD_TOS_INT", uops)
19241924
self.assertIn("_CALL_LEN", uops)
19251925

1926+
def test_get_len(self):
1927+
def testfunc(n):
1928+
a = [1, 2, 3, 4]
1929+
for _ in range(n):
1930+
match a:
1931+
case [1,2]:
1932+
_ = len(a) - 1
1933+
_, ex = self._run_with_optimizer(testfunc, TIER2_THRESHOLD)
1934+
uops = get_opnames(ex)
1935+
self.assertNotIn("_GUARD_NOS_INT", uops)
1936+
self.assertNotIn("_GUARD_TOS_INT", uops)
1937+
self.assertIn("_GET_LEN", uops)
1938+
19261939
def test_binary_op_subscr_tuple_int(self):
19271940
def testfunc(n):
19281941
x = 0

Python/optimizer_bytecodes.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ dummy_func(void) {
480480
res = sym_new_const(ctx, tmp);
481481
Py_DECREF(tmp);
482482
}
483-
else {
483+
else {
484484
res = sym_new_type(ctx, &PyBool_Type);
485485
}
486486
}
@@ -1088,6 +1088,10 @@ dummy_func(void) {
10881088
res = sym_new_type(ctx, &PyLong_Type);
10891089
}
10901090

1091+
op(_GET_LEN, (-- len)) {
1092+
len = sym_new_type(ctx, &PyLong_Type);
1093+
}
1094+
10911095
// END BYTECODES //
10921096

10931097
}

Python/optimizer_cases.c.h

Lines changed: 1 addition & 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)