Skip to content

Commit 5cb915d

Browse files
miss-islingtonNekoAsakurasavannahostrowskiStanFromIreland
authored
[3.15] gh-149481: skip FOR_ITER inline specialization for Python __next__ (GH-149491) (#149523)
gh-149481: skip `FOR_ITER` inline specialization for Python `__next__` (GH-149491) (cherry picked from commit 49918f5) Co-authored-by: Neko Asakura <neko.asakura@outlook.com> Co-authored-by: Savannah Ostrowski <savannah@python.org> Co-authored-by: Stan Ulbrych <stan@python.org>
1 parent b311ea8 commit 5cb915d

5 files changed

Lines changed: 15 additions & 3 deletions

File tree

Include/internal/pycore_typeobject.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ extern PyObject* _Py_BaseObject_RichCompare(PyObject* self, PyObject* other, int
122122
extern PyObject* _Py_slot_tp_getattro(PyObject *self, PyObject *name);
123123
extern PyObject* _Py_slot_tp_getattr_hook(PyObject *self, PyObject *name);
124124

125+
extern int _PyType_HasSlotTpIternext(PyTypeObject *type);
126+
125127
extern PyTypeObject _PyBufferWrapper_Type;
126128

127129
PyAPI_FUNC(PyObject*) _PySuper_Lookup(PyTypeObject *su_type, PyObject *su_obj,

Lib/test/test_capi/test_opt.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -598,7 +598,8 @@ def testfunc(n, m):
598598
ex = get_first_executor(testfunc)
599599
self.assertIsNotNone(ex)
600600
uops = get_opnames(ex)
601-
self.assertIn("_ITER_NEXT_INLINE", uops)
601+
self.assertIn("_FOR_ITER_TIER_TWO", uops)
602+
self.assertNotIn("_ITER_NEXT_INLINE", uops)
602603

603604

604605
@requires_specialization

Objects/typeobject.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11079,6 +11079,12 @@ slot_tp_iternext(PyObject *self)
1107911079
return vectorcall_method(&_Py_ID(__next__), stack, 1);
1108011080
}
1108111081

11082+
int
11083+
_PyType_HasSlotTpIternext(PyTypeObject *type)
11084+
{
11085+
return type->tp_iternext == slot_tp_iternext;
11086+
}
11087+
1108211088
static PyObject *
1108311089
slot_tp_descr_get(PyObject *self, PyObject *obj, PyObject *type)
1108411090
{

Python/optimizer_bytecodes.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include "pycore_long.h"
33
#include "pycore_opcode_utils.h"
44
#include "pycore_optimizer.h"
5+
#include "pycore_typeobject.h"
56
#include "pycore_uops.h"
67
#include "pycore_uop_ids.h"
78
#include "internal/pycore_moduleobject.h"
@@ -1459,7 +1460,8 @@ dummy_func(void) {
14591460
type = sym_get_probable_type(iter);
14601461
definite = false;
14611462
}
1462-
if (type != NULL && type != &PyGen_Type && type->tp_iternext != NULL) {
1463+
if (type != NULL && type != &PyGen_Type && type->tp_iternext != NULL
1464+
&& !_PyType_HasSlotTpIternext(type)) {
14631465
PyType_Watch(TYPE_WATCHER_ID, (PyObject *)type);
14641466
_Py_BloomFilter_Add(dependencies, type);
14651467
if (!definite) {

Python/optimizer_cases.c.h

Lines changed: 2 additions & 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)