Skip to content

Commit 01c36df

Browse files
Address Mark's comments
1 parent f3b579b commit 01c36df

File tree

5 files changed

+12
-23
lines changed

5 files changed

+12
-23
lines changed

Include/internal/pycore_code.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,8 +311,8 @@ PyAPI_FUNC(void) _Py_Specialize_LoadGlobal(PyObject *globals, PyObject *builtins
311311
_Py_CODEUNIT *instr, PyObject *name);
312312
PyAPI_FUNC(void) _Py_Specialize_StoreSubscr(_PyStackRef container, _PyStackRef sub,
313313
_Py_CODEUNIT *instr);
314-
PyAPI_FUNC(void) _Py_Specialize_Call(_PyStackRef callable, _Py_CODEUNIT *instr,
315-
int nargs);
314+
PyAPI_FUNC(void) _Py_Specialize_Call(_PyStackRef callable, _PyStackRef self_or_null,
315+
_Py_CODEUNIT *instr, int nargs);
316316
PyAPI_FUNC(void) _Py_Specialize_CallKw(_PyStackRef callable, _Py_CODEUNIT *instr,
317317
int nargs);
318318
PyAPI_FUNC(void) _Py_Specialize_BinaryOp(_PyStackRef lhs, _PyStackRef rhs, _Py_CODEUNIT *instr,

Python/bytecodes.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3689,7 +3689,7 @@ dummy_func(
36893689
#if ENABLE_SPECIALIZATION_FT
36903690
if (ADAPTIVE_COUNTER_TRIGGERS(counter)) {
36913691
next_instr = this_instr;
3692-
_Py_Specialize_Call(callable, next_instr, oparg + !PyStackRef_IsNull(self_or_null));
3692+
_Py_Specialize_Call(callable, self_or_null, next_instr, oparg + !PyStackRef_IsNull(self_or_null));
36933693
DISPATCH_SAME_OPARG();
36943694
}
36953695
OPCODE_DEFERRED_INC(CALL);
@@ -4395,7 +4395,6 @@ dummy_func(
43954395
assert(oparg == 1);
43964396
PyObject *self_o = PyStackRef_AsPyObjectBorrow(self);
43974397

4398-
DEOPT_IF(!PyList_CheckExact(self_o));
43994398
DEOPT_IF(!LOCK_OBJECT(self_o));
44004399
STAT_INC(CALL, hit);
44014400
int err = _PyList_AppendTakeRef((PyListObject *)self_o, PyStackRef_AsPyObjectSteal(arg));

Python/executor_cases.c.h

Lines changed: 0 additions & 4 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: 1 addition & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Python/specialize.c

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
#include "pycore_pylifecycle.h" // _PyOS_URandomNonblock()
2020
#include "pycore_runtime.h" // _Py_ID()
2121
#include "pycore_unicodeobject.h" // _PyUnicodeASCIIIter_Type
22-
#include "pycore_pystate.h" // _PyThreadState_GET()
2322

2423
#include <stdlib.h> // rand()
2524

@@ -1603,8 +1602,8 @@ specialize_class_call(PyObject *callable, _Py_CODEUNIT *instr, int nargs)
16031602
}
16041603

16051604
static int
1606-
specialize_method_descriptor(PyMethodDescrObject *descr, _Py_CODEUNIT *instr,
1607-
int nargs)
1605+
specialize_method_descriptor(PyMethodDescrObject *descr, PyObject *self_or_null,
1606+
_Py_CODEUNIT *instr, int nargs)
16081607
{
16091608
switch (descr->d_method->ml_flags &
16101609
(METH_VARARGS | METH_FASTCALL | METH_NOARGS | METH_O |
@@ -1628,10 +1627,8 @@ specialize_method_descriptor(PyMethodDescrObject *descr, _Py_CODEUNIT *instr,
16281627
bool pop = (next.op.code == POP_TOP);
16291628
int oparg = instr->op.arg;
16301629
if ((PyObject *)descr == list_append && oparg == 1 && pop) {
1631-
PyThreadState *tstate = _PyThreadState_GET();
1632-
_PyStackRef *stack_pointer = tstate->current_frame->stackpointer;
1633-
PyObject *self = PyStackRef_AsPyObjectBorrow(stack_pointer[-2]);
1634-
if (PyList_CheckExact(self)) {
1630+
assert(self_or_null != NULL);
1631+
if (PyList_CheckExact(self_or_null)) {
16351632
specialize(instr, CALL_LIST_APPEND);
16361633
return 0;
16371634
}
@@ -1772,7 +1769,7 @@ specialize_c_call(PyObject *callable, _Py_CODEUNIT *instr, int nargs)
17721769
}
17731770

17741771
Py_NO_INLINE void
1775-
_Py_Specialize_Call(_PyStackRef callable_st, _Py_CODEUNIT *instr, int nargs)
1772+
_Py_Specialize_Call(_PyStackRef callable_st, _PyStackRef self_or_null_st, _Py_CODEUNIT *instr, int nargs)
17761773
{
17771774
PyObject *callable = PyStackRef_AsPyObjectBorrow(callable_st);
17781775

@@ -1790,7 +1787,9 @@ _Py_Specialize_Call(_PyStackRef callable_st, _Py_CODEUNIT *instr, int nargs)
17901787
fail = specialize_class_call(callable, instr, nargs);
17911788
}
17921789
else if (Py_IS_TYPE(callable, &PyMethodDescr_Type)) {
1793-
fail = specialize_method_descriptor((PyMethodDescrObject *)callable, instr, nargs);
1790+
PyObject *self_or_null = PyStackRef_AsPyObjectBorrow(self_or_null_st);
1791+
fail = specialize_method_descriptor((PyMethodDescrObject *)callable,
1792+
self_or_null, instr, nargs);
17941793
}
17951794
else if (PyMethod_Check(callable)) {
17961795
PyObject *func = ((PyMethodObject *)callable)->im_func;

0 commit comments

Comments
 (0)