Skip to content

Commit 3a6f48d

Browse files
committed
Add FOR_ITER specialization for virtual iterators. Specialize GET_ITER.
* Add FOR_ITER_VIRTUAL to specialize FOR_ITER for virtual iterators * Add GET_ITER_SELF to specialize GET_ITER for iterators (including generators) * Add GET_ITER_VIRTUAL to specialize GET_ITER for iterables as virtual iterators
1 parent 473d2a3 commit 3a6f48d

33 files changed

+2953
-1499
lines changed

Include/cpython/object.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,8 @@ struct _typeobject {
229229

230230
destructor tp_finalize;
231231
vectorcallfunc tp_vectorcall;
232+
iteritemfunc tp_iteritem;
233+
232234

233235
/* bitset of which type-watchers care about this type */
234236
unsigned char tp_watched;

Include/internal/pycore_code.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,12 @@ typedef struct {
141141

142142
#define INLINE_CACHE_ENTRIES_FOR_ITER CACHE_ENTRIES(_PyForIterCache)
143143

144+
typedef struct {
145+
_Py_BackoffCounter counter;
146+
} _PyGetIterCache;
147+
148+
#define INLINE_CACHE_ENTRIES_GET_ITER CACHE_ENTRIES(_PyGetIterCache)
149+
144150
typedef struct {
145151
_Py_BackoffCounter counter;
146152
} _PySendCache;
@@ -324,6 +330,7 @@ PyAPI_FUNC(void) _Py_Specialize_ContainsOp(_PyStackRef value, _Py_CODEUNIT *inst
324330
PyAPI_FUNC(void) _Py_GatherStats_GetIter(_PyStackRef iterable);
325331
PyAPI_FUNC(void) _Py_Specialize_CallFunctionEx(_PyStackRef func_st, _Py_CODEUNIT *instr);
326332
PyAPI_FUNC(void) _Py_Specialize_Resume(_Py_CODEUNIT *instr, PyThreadState *tstate, _PyInterpreterFrame *frame);
333+
PyAPI_FUNC(void) _Py_Specialize_GetIter(_PyStackRef iterable, _Py_CODEUNIT *instr);
327334

328335
// Utility functions for reading/writing 32/64-bit values in the inline caches.
329336
// Great care should be taken to ensure that these functions remain correct and

Include/internal/pycore_magic_number.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,7 @@ Known values:
294294
Python 3.15a4 3661 (Lazy imports IMPORT_NAME opcode changes)
295295
Python 3.15a8 3662 (Add counter to RESUME)
296296
Python 3.15a8 3663 (Merge GET_ITER and GET_YIELD_FROM_ITER. Modify SEND to make it a bit more like FOR_ITER)
297+
Python 3.15a8 3664 (Add FOR_ITER_VIRTUAL and GET_ITER specializations)
297298
298299
299300
Python 3.16 will start with 3700
@@ -307,7 +308,7 @@ PC/launcher.c must also be updated.
307308
308309
*/
309310

310-
#define PYC_MAGIC_NUMBER 3663
311+
#define PYC_MAGIC_NUMBER 3664
311312
/* This is equivalent to converting PYC_MAGIC_NUMBER to 2 bytes
312313
(little-endian) and then appending b'\r\n'. */
313314
#define PYC_MAGIC_NUMBER_TOKEN \

Include/internal/pycore_opcode_metadata.h

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

0 commit comments

Comments
 (0)