8000 gh-131798: JIT: Narrow the return type of `_GET_LEN` to int by Zheaoli · Pull Request #133345 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-131798: JIT: Narrow the return type of _GET_LEN to int #133345

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 23 commits into from
May 20, 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 review idea
Signed-off-by: Manjusaka <me@manjusaka.me>
  • Loading branch information
Zheaoli committed May 8, 2025
commit cf17d92c012232dee27e786c1b07b5e8e31e6736
21 changes: 17 additions & 4 deletions Lib/test/test_capi/test_opt.py
Original file line number Diff line number Diff line change
Expand Up @@ -1926,19 +1926,32 @@ def testfunc(n):
self.assertNotIn("_GUARD_TOS_INT", uops)

def test_get_len(self):
def testfunc(n):
def testfunc1(n):
x = 0
a = [1, 2, 3, 4]
for _ in range(n):
match a:
match (1, 2, 3, 4):
case [_, _, _, _]:
x += 1
return x
res, ex = self._run_with_optimizer(testfunc, TIER2_THRESHOLD)
res, ex = self._run_with_optimizer(testfunc1, TIER2_THRESHOLD)
self.assertEqual(res, TIER2_THRESHOLD)
uops = get_opnames(ex)
self.assertNotIn("_GUARD_TOS_INT", uops)
self.assertIn("_GET_LEN", uops)
self.assertIn("_POP_TOP_LOAD_CONST_INLINE_BORROW", uops)
def testfunc1(n):
x = 0
for _ in range(n):
match [1, 2, 3, 4]:
case [_, _, _, _]:
x += 1
return x
res, ex = self._run_with_optimizer(testfunc1, TIER2_THRESHOLD)
self.assertEqual(res, TIER2_THRESHOLD)
uops = get_opnames(ex)
self.assertNotIn("_GUARD_TOS_INT", uops)
self.assertIn("_GET_LEN", uops)
self.assertNotIn("_POP_TOP_LOAD_CONST_INLINE_BORROW", uops)

def test_binary_op_subscr_tuple_int(self):
def testfunc(n):
Expand Down
8 changes: 7 additions & 1 deletion Python/optimizer_bytecodes.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "pycore_uops.h"
#include "pycore_uop_ids.h"
#include "internal/pycore_moduleobject.h"
#include "tupleobject.h"

#define op(name, ...) /* NAME is ignored */

Expand Down Expand Up @@ -1095,7 +1096,12 @@ dummy_func(void) {
}
else {
assert(tuple_length >= 0);
len = sym_new_const(ctx, PyLong_FromLong(tuple_length));
PyObject *temp = PyLong_FromLong(tuple_length);
if (temp == NULL) {
goto error;
}
len = sym_new_const(ctx, temp);
Py_DECREF(temp);
}
}

Expand Down
11 changes: 10 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
0