Skip to content

Commit 6ccc255

Browse files
committed
Specialize __setitem__ dunder method for STORE_SUBSCR
This is precursuor for JIT improvements but also results in standard improvements due to specializing the bytecode
1 parent af49df9 commit 6ccc255

22 files changed

Lines changed: 419 additions & 57 deletions

Include/internal/pycore_call.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,13 @@ extern PyObject* _PyObject_Call_Prepend(
3939
PyObject *args,
4040
PyObject *kwargs);
4141

42+
PyAPI_FUNC(int) _PyObject_CallSetItemDunder(
43+
PyThreadState *tstate,
44+
PyObject *func,
45+
PyObject *self,
46+
PyObject *key,
47+
PyObject *value);
48+
4249
extern PyObject* _PyObject_VectorcallDictTstate(
4350
PyThreadState *tstate,
4451
PyObject *callable,

Include/internal/pycore_code.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ typedef struct {
131131

132132
typedef struct {
133133
_Py_BackoffCounter counter;
134+
uint16_t version[2];
134135
} _PyStoreSubscrCache;
135136

136137
#define INLINE_CACHE_ENTRIES_STORE_SUBSCR CACHE_ENTRIES(_PyStoreSubscrCache)

Include/internal/pycore_magic_number.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,7 @@ Known values:
303303
Python 3.16a1 3703 (Replace DELETE_GLOBAL with PUSH_NULL; STORE_GLOBAL)
304304
Python 3.16a1 3704 (Replace DELETE_ATTR with PUSH_NULL; STORE_ATTR)
305305
Python 3.16a1 3705 (Add INTRINSIC_ADD_CONDITIONAL_ANNOTATION)
306+
Python 3.16a1 3706 (Add STORE_SUBSCR_PY_DUNDER)
306307
307308
Python 3.17 will start with 3750
308309
@@ -312,7 +313,7 @@ Known values:
312313
313314
*/
314315

315-
#define PYC_MAGIC_NUMBER 3705
316+
#define PYC_MAGIC_NUMBER 3706
316317
/* This is equivalent to converting PYC_MAGIC_NUMBER to 2 bytes
317318
(little-endian) and then appending b'\r\n'. */
318319
#define PYC_MAGIC_NUMBER_TOKEN \

Include/internal/pycore_opcode_metadata.h

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

Include/opcode_ids.h

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

Lib/_opcode_metadata.py

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

Lib/opcode.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@
102102
),
103103
STORE_SUBSCR=frozendict(
104104
counter=1,
105+
version=2,
105106
),
106107
SEND=frozendict(
107108
counter=1,

Lib/test/test_dis.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,8 @@ def wrap_func_w_kwargs():
410410
LOAD_SMALL_INT 0
411411
CALL 1
412412
STORE_SUBSCR
413+
CACHE
414+
CACHE
413415
LOAD_COMMON_CONSTANT 7 (None)
414416
RETURN_VALUE
415417
"""

0 commit comments

Comments
 (0)