Skip to content

Commit 6b2c10d

Browse files
committed
gh-134584: Eliminate redundant refcounting from _CALL_LEN
1 parent 42ccac2 commit 6b2c10d

File tree

7 files changed

+51
-33
lines changed

7 files changed

+51
-33
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.

Lib/test/test_capi/test_opt.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1967,6 +1967,7 @@ def testfunc(n):
19671967
self.assertIn("_CALL_LEN", uops)
19681968
self.assertNotIn("_GUARD_NOS_INT", uops)
19691969
self.assertNotIn("_GUARD_TOS_INT", uops)
1970+
self.assertIn("_POP_TOP_NOP", uops)
19701971

19711972
def test_call_len_known_length_small_int(self):
19721973
def testfunc(n):

Python/bytecodes.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4315,18 +4315,20 @@ dummy_func(
43154315
unused/2 +
43164316
_GUARD_NOS_NULL +
43174317
_GUARD_CALLABLE_LEN +
4318-
_CALL_LEN;
4318+
_CALL_LEN +
4319+
POP_TOP +
4320+
POP_TOP;
43194321

43204322
op(_GUARD_CALLABLE_LEN, (callable, unused, unused -- callable, unused, unused)){
43214323
PyObject *callable_o = PyStackRef_AsPyObjectBorrow(callable);
43224324
PyInterpreterState *interp = tstate->interp;
43234325
DEOPT_IF(callable_o != interp->callable_cache.len);
43244326
}
43254327

4326-
op(_CALL_LEN, (callable, null, arg -- res)) {
4328+
op(_CALL_LEN, (callable, null, arg -- res, a, c)) {
43274329
/* len(o) */
4328-
(void)null;
43294330
STAT_INC(CALL, hit);
4331+
INPUTS_DEAD();
43304332
PyObject *arg_o = PyStackRef_AsPyObjectBorrow(arg);
43314333
Py_ssize_t len_i = PyObject_Length(arg_o);
43324334
if (len_i < 0) {
@@ -4337,10 +4339,9 @@ dummy_func(
43374339
if (res_o == NULL) {
43384340
ERROR_NO_POP();
43394341
}
4340-
PyStackRef_CLOSE(arg);
4341-
DEAD(null);
4342-
PyStackRef_CLOSE(callable);
43434342
res = PyStackRef_FromPyObjectSteal(res_o);
4343+
a = arg;
4344+
c = callable;
43444345
}
43454346

43464347
op(_GUARD_CALLABLE_ISINSTANCE, (callable, unused, unused, unused -- callable, unused, unused, unused)) {

Python/executor_cases.c.h

Lines changed: 9 additions & 14 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: 22 additions & 9 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
@@ -1178,7 +1178,7 @@ dummy_func(void) {
11781178
sym_set_const(callable, (PyObject *)&PyUnicode_Type);
11791179
}
11801180

1181-
op(_CALL_LEN, (callable, null, arg -- res)) {
1181+
op(_CALL_LEN, (callable, null, arg -- res, a, c)) {
11821182
res = sym_new_type(ctx, &PyLong_Type);
11831183
int tuple_length = sym_tuple_length(arg);
11841184
if (tuple_length >= 0) {
@@ -1193,6 +1193,8 @@ dummy_func(void) {
11931193
res = sym_new_const(ctx, temp);
11941194
Py_DECREF(temp);
11951195
}
1196+
a = arg;
1197+
c = callable;
11961198
}
11971199

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

Python/optimizer_cases.c.h

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

0 commit comments

Comments
 (0)