Skip to content

Commit fb47955

Browse files
committed
Merge branch 'main' into supermon
* main: pythongh-104057: Fix direct invocation of test_support (pythonGH-104069) pythongh-87729: improve hit rate of LOAD_SUPER_ATTR specialization (python#104270) pythongh-101819: Fix inverted debug preprocessor check in winconsoleio.c (python#104388)
2 parents 19b3d9e + 27419a7 commit fb47955

15 files changed

+376
-354
lines changed

Include/internal/pycore_code.h

+2-5
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,6 @@ typedef struct {
5353

5454
typedef struct {
5555
uint16_t counter;
56-
uint16_t class_version[2];
57-
uint16_t self_type_version[2];
58-
uint16_t method[4];
5956
} _PySuperAttrCache;
6057

6158
#define INLINE_CACHE_ENTRIES_LOAD_SUPER_ATTR CACHE_ENTRIES(_PySuperAttrCache)
@@ -227,8 +224,8 @@ extern int _PyLineTable_PreviousAddressRange(PyCodeAddressRange *range);
227224

228225
/* Specialization functions */
229226

230-
extern void _Py_Specialize_LoadSuperAttr(PyObject *global_super, PyObject *cls, PyObject *self,
231-
_Py_CODEUNIT *instr, PyObject *name, int load_method);
227+
extern void _Py_Specialize_LoadSuperAttr(PyObject *global_super, PyObject *cls,
228+
_Py_CODEUNIT *instr, int load_method);
232229
extern void _Py_Specialize_LoadAttr(PyObject *owner, _Py_CODEUNIT *instr,
233230
PyObject *name);
234231
extern void _Py_Specialize_StoreAttr(PyObject *owner, _Py_CODEUNIT *instr,

Include/internal/pycore_opcode.h

+12-12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Include/internal/pycore_typeobject.h

-2
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,6 @@ PyAPI_DATA(PyTypeObject) _PyBufferWrapper_Type;
142142

143143
PyObject *
144144
_PySuper_Lookup(PyTypeObject *su_type, PyObject *su_obj, PyObject *name, int *meth_found);
145-
PyObject *
146-
_PySuper_LookupDescr(PyTypeObject *su_type, PyObject *su_obj, PyObject *name);
147145

148146
#ifdef __cplusplus
149147
}

Include/opcode.h

+28-27
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Lib/importlib/_bootstrap_external.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,7 @@ def _write_atomic(path, data, mode=0o666):
443443
# Python 3.12b1 3527 (Add LOAD_SUPER_ATTR)
444444
# Python 3.12b1 3528 (Add LOAD_SUPER_ATTR_METHOD specialization)
445445
# Python 3.12b1 3529 (Inline list/dict/set comprehensions)
446+
# Python 3.12b1 3530 (Shrink the LOAD_SUPER_ATTR caches)
446447

447448
# Python 3.13 will start with 3550
448449

@@ -459,7 +460,7 @@ def _write_atomic(path, data, mode=0o666):
459460
# Whenever MAGIC_NUMBER is changed, the ranges in the magic_values array
460461
# in PC/launcher.c must also be updated.
461462

462-
MAGIC_NUMBER = (3529).to_bytes(2, 'little') + b'\r\n'
463+
MAGIC_NUMBER = (3530).to_bytes(2, 'little') + b'\r\n'
463464

464465
_RAW_MAGIC_NUMBER = int.from_bytes(MAGIC_NUMBER, 'little') # For import.c
465466

Lib/opcode.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,7 @@ def pseudo_op(name, op, real_ops):
374374
"FOR_ITER_GEN",
375375
],
376376
"LOAD_SUPER_ATTR": [
377+
"LOAD_SUPER_ATTR_ATTR",
377378
"LOAD_SUPER_ATTR_METHOD",
378379
],
379380
"LOAD_ATTR": [
@@ -451,9 +452,6 @@ def pseudo_op(name, op, real_ops):
451452
},
452453
"LOAD_SUPER_ATTR": {
453454
"counter": 1,
454-
"class_version": 2,
455-
"self_type_version": 2,
456-
"method": 4,
457455
},
458456
"LOAD_ATTR": {
459457
"counter": 1,

Lib/test/test_support.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def setUpClass(cls):
3030
"test.support.warnings_helper", like=".*used in test_support.*"
3131
)
3232
cls._test_support_token = support.ignore_deprecations_from(
33-
"test.test_support", like=".*You should NOT be seeing this.*"
33+
__name__, like=".*You should NOT be seeing this.*"
3434
)
3535
assert len(warnings.filters) == orig_filter_len + 2
3636

Modules/_io/winconsoleio.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ _io__WindowsConsoleIO___init___impl(winconsoleio *self, PyObject *nameobj,
267267
int fd_is_own = 0;
268268
HANDLE handle = NULL;
269269

270-
#ifdef NDEBUG
270+
#ifndef NDEBUG
271271
_PyIO_State *state = find_io_state_by_def(Py_TYPE(self));
272272
assert(PyObject_TypeCheck(self, state->PyWindowsConsoleIO_Type));
273273
#endif

Objects/typeobject.c

-12
Original file line numberDiff line numberDiff line change
@@ -10245,18 +10245,6 @@ _PySuper_Lookup(PyTypeObject *su_type, PyObject *su_obj, PyObject *name, int *me
1024510245
return res;
1024610246
}
1024710247

10248-
PyObject *
10249-
_PySuper_LookupDescr(PyTypeObject *su_type, PyObject *su_obj, PyObject *name)
10250-
{
10251-
PyTypeObject *su_obj_type = supercheck(su_type, su_obj);
10252-
if (su_obj_type == NULL) {
10253-
return NULL;
10254-
}
10255-
PyObject *res = _super_lookup_descr(su_type, su_obj_type, name);
10256-
Py_DECREF(su_obj_type);
10257-
return res;
10258-
}
10259-
1026010248
static PyObject *
1026110249
super_descr_get(PyObject *self, PyObject *obj, PyObject *type)
1026210250
{

Python/bytecodes.c

+31-9
Original file line numberDiff line numberDiff line change
@@ -1570,17 +1570,18 @@ dummy_func(
15701570

15711571
family(load_super_attr, INLINE_CACHE_ENTRIES_LOAD_SUPER_ATTR) = {
15721572
LOAD_SUPER_ATTR,
1573+
LOAD_SUPER_ATTR_ATTR,
15731574
LOAD_SUPER_ATTR_METHOD,
15741575
};
15751576

1576-
inst(LOAD_SUPER_ATTR, (unused/9, global_super, class, self -- res2 if (oparg & 1), res)) {
1577+
inst(LOAD_SUPER_ATTR, (unused/1, global_super, class, self -- res2 if (oparg & 1), res)) {
15771578
PyObject *name = GETITEM(frame->f_code->co_names, oparg >> 2);
15781579
int load_method = oparg & 1;
15791580
#if ENABLE_SPECIALIZATION
15801581
_PySuperAttrCache *cache = (_PySuperAttrCache *)next_instr;
15811582
if (ADAPTIVE_COUNTER_IS_ZERO(cache->counter)) {
15821583
next_instr--;
1583-
_Py_Specialize_LoadSuperAttr(global_super, class, self, next_instr, name, load_method);
1584+
_Py_Specialize_LoadSuperAttr(global_super, class, next_instr, load_method);
15841585
DISPATCH_SAME_OPARG();
15851586
}
15861587
STAT_INC(LOAD_SUPER_ATTR, deferred);
@@ -1622,17 +1623,38 @@ dummy_func(
16221623
ERROR_IF(res == NULL, error);
16231624
}
16241625

1625-
inst(LOAD_SUPER_ATTR_METHOD, (unused/1, class_version/2, self_type_version/2, method/4, global_super, class, self -- res2, res)) {
1626+
inst(LOAD_SUPER_ATTR_ATTR, (unused/1, global_super, class, self -- res2 if (oparg & 1), res)) {
1627+
assert(!(oparg & 1));
16261628
DEOPT_IF(global_super != (PyObject *)&PySuper_Type, LOAD_SUPER_ATTR);
16271629
DEOPT_IF(!PyType_Check(class), LOAD_SUPER_ATTR);
1628-
DEOPT_IF(((PyTypeObject *)class)->tp_version_tag != class_version, LOAD_SUPER_ATTR);
1629-
PyTypeObject *self_type = Py_TYPE(self);
1630-
DEOPT_IF(self_type->tp_version_tag != self_type_version, LOAD_SUPER_ATTR);
1631-
res2 = method;
1632-
res = self; // transfer ownership
1633-
Py_INCREF(res2);
1630+
STAT_INC(LOAD_SUPER_ATTR, hit);
1631+
PyObject *name = GETITEM(frame->f_code->co_names, oparg >> 2);
1632+
res = _PySuper_Lookup((PyTypeObject *)class, self, name, NULL);
1633+
ERROR_IF(res == NULL, error);
1634+
DECREF_INPUTS();
1635+
}
1636+
1637+
inst(LOAD_SUPER_ATTR_METHOD, (unused/1, global_super, class, self -- res2, res)) {
1638+
assert(oparg & 1);
1639+
DEOPT_IF(global_super != (PyObject *)&PySuper_Type, LOAD_SUPER_ATTR);
1640+
DEOPT_IF(!PyType_Check(class), LOAD_SUPER_ATTR);
1641+
STAT_INC(LOAD_SUPER_ATTR, hit);
1642+
PyObject *name = GETITEM(frame->f_code->co_names, oparg >> 2);
1643+
int method_found = 0;
1644+
res2 = _PySuper_Lookup((PyTypeObject *)class, self, name, &method_found);
16341645
Py_DECREF(global_super);
16351646
Py_DECREF(class);
1647+
if (res2 == NULL) {
1648+
Py_DECREF(self);
1649+
ERROR_IF(true, error);
1650+
}
1651+
if (method_found) {
1652+
res = self; // transfer ownership
1653+
} else {
1654+
Py_DECREF(self);
1655+
res = res2;
1656+
res2 = NULL;
1657+
}
16361658
}
16371659

16381660
family(load_attr, INLINE_CACHE_ENTRIES_LOAD_ATTR) = {

0 commit comments

Comments
 (0)