🌐 AI搜索 & 代理 主页
Skip to content

Commit a275385

Browse files
authored
gh-134584: Eliminate redundant refcounting from _CALL_LEN (gh-136104)
1 parent c433986 commit a275385

File tree

9 files changed

+54
-41
lines changed

9 files changed

+54
-41
lines changed

Include/internal/pycore_opcode_metadata.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.

Include/internal/pycore_uop_ids.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.

Include/internal/pycore_uop_metadata.h

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

Lib/test/test_capi/test_opt.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2066,6 +2066,7 @@ def testfunc(n):
20662066
self.assertIn("_CALL_LEN", uops)
20672067
self.assertNotIn("_GUARD_NOS_INT", uops)
20682068
self.assertNotIn("_GUARD_TOS_INT", uops)
2069+
self.assertIn("_POP_TOP_NOP", uops)
20692070

20702071
def test_call_len_known_length_small_int(self):
20712072
# Make sure that len(t) is optimized for a tuple of length 5.

Python/bytecodes.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4280,17 +4280,18 @@ dummy_func(
42804280
unused/2 +
42814281
_GUARD_NOS_NULL +
42824282
_GUARD_CALLABLE_LEN +
4283-
_CALL_LEN;
4283+
_CALL_LEN +
4284+
POP_TOP +
4285+
POP_TOP;
42844286

42854287
op(_GUARD_CALLABLE_LEN, (callable, unused, unused -- callable, unused, unused)){
42864288
PyObject *callable_o = PyStackRef_AsPyObjectBorrow(callable);
42874289
PyInterpreterState *interp = tstate->interp;
42884290
DEOPT_IF(callable_o != interp->callable_cache.len);
42894291
}
42904292

4291-
op(_CALL_LEN, (callable, null, arg -- res)) {
4293+
op(_CALL_LEN, (callable, null, arg -- res, a, c)) {
42924294
/* len(o) */
4293-
(void)null;
42944295
STAT_INC(CALL, hit);
42954296
PyObject *arg_o = PyStackRef_AsPyObjectBorrow(arg);
42964297
Py_ssize_t len_i = PyObject_Length(arg_o);
@@ -4302,9 +4303,9 @@ dummy_func(
43024303
if (res_o == NULL) {
43034304
ERROR_NO_POP();
43044305
}
4305-
PyStackRef_CLOSE(arg);
4306-
DEAD(null);
4307-
PyStackRef_CLOSE(callable);
4306+
a = arg;
4307+
c = callable;
4308+
INPUTS_DEAD();
43084309
res = PyStackRef_FromPyObjectSteal(res_o);
43094310
}
43104311

Python/executor_cases.c.h

Lines changed: 11 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Python/generated_cases.c.h

Lines changed: 19 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Python/optimizer_bytecodes.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1202,7 +1202,7 @@ dummy_func(void) {
12021202
sym_set_const(callable, (PyObject *)&PyUnicode_Type);
12031203
}
12041204

1205-
op(_CALL_LEN, (callable, null, arg -- res)) {
1205+
op(_CALL_LEN, (callable, null, arg -- res, a, c)) {
12061206
res = sym_new_type(ctx, &PyLong_Type);
12071207
Py_ssize_t tuple_length = sym_tuple_length(arg);
12081208
if (tuple_length >= 0) {
@@ -1217,6 +1217,8 @@ dummy_func(void) {
12171217
res = sym_new_const(ctx, temp);
12181218
Py_DECREF(temp);
12191219
}
1220+
a = arg;
1221+
c = callable;
12201222
}
12211223

12221224
op(_GET_LEN, (obj -- obj, len)) {

Python/optimizer_cases.c.h

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

0 commit comments

Comments
 (0)