Skip to content

Commit

Permalink
Merge branch 'main' into supermon
Browse files Browse the repository at this point in the history
* 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)
  • Loading branch information
carljm committed May 11, 2023
2 parents 19b3d9e + 27419a7 commit fb47955
Show file tree
Hide file tree
Showing 15 changed files with 376 additions and 354 deletions.
7 changes: 2 additions & 5 deletions Include/internal/pycore_code.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,6 @@ typedef struct {

typedef struct {
uint16_t counter;
uint16_t class_version[2];
uint16_t self_type_version[2];
uint16_t method[4];
} _PySuperAttrCache;

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

/* Specialization functions */

extern void _Py_Specialize_LoadSuperAttr(PyObject *global_super, PyObject *cls, PyObject *self,
_Py_CODEUNIT *instr, PyObject *name, int load_method);
extern void _Py_Specialize_LoadSuperAttr(PyObject *global_super, PyObject *cls,
_Py_CODEUNIT *instr, int load_method);
extern void _Py_Specialize_LoadAttr(PyObject *owner, _Py_CODEUNIT *instr,
PyObject *name);
extern void _Py_Specialize_StoreAttr(PyObject *owner, _Py_CODEUNIT *instr,
Expand Down
24 changes: 12 additions & 12 deletions Include/internal/pycore_opcode.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions Include/internal/pycore_typeobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,6 @@ PyAPI_DATA(PyTypeObject) _PyBufferWrapper_Type;

PyObject *
_PySuper_Lookup(PyTypeObject *su_type, PyObject *su_obj, PyObject *name, int *meth_found);
PyObject *
_PySuper_LookupDescr(PyTypeObject *su_type, PyObject *su_obj, PyObject *name);

#ifdef __cplusplus
}
Expand Down
55 changes: 28 additions & 27 deletions Include/opcode.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Lib/importlib/_bootstrap_external.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,7 @@ def _write_atomic(path, data, mode=0o666):
# Python 3.12b1 3527 (Add LOAD_SUPER_ATTR)
# Python 3.12b1 3528 (Add LOAD_SUPER_ATTR_METHOD specialization)
# Python 3.12b1 3529 (Inline list/dict/set comprehensions)
# Python 3.12b1 3530 (Shrink the LOAD_SUPER_ATTR caches)

# Python 3.13 will start with 3550

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

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

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

Expand Down
4 changes: 1 addition & 3 deletions Lib/opcode.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,7 @@ def pseudo_op(name, op, real_ops):
"FOR_ITER_GEN",
],
"LOAD_SUPER_ATTR": [
"LOAD_SUPER_ATTR_ATTR",
"LOAD_SUPER_ATTR_METHOD",
],
"LOAD_ATTR": [
Expand Down Expand Up @@ -451,9 +452,6 @@ def pseudo_op(name, op, real_ops):
},
"LOAD_SUPER_ATTR": {
"counter": 1,
"class_version": 2,
"self_type_version": 2,
"method": 4,
},
"LOAD_ATTR": {
"counter": 1,
Expand Down
2 changes: 1 addition & 1 deletion Lib/test/test_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def setUpClass(cls):
"test.support.warnings_helper", like=".*used in test_support.*"
)
cls._test_support_token = support.ignore_deprecations_from(
"test.test_support", like=".*You should NOT be seeing this.*"
__name__, like=".*You should NOT be seeing this.*"
)
assert len(warnings.filters) == orig_filter_len + 2

Expand Down
2 changes: 1 addition & 1 deletion Modules/_io/winconsoleio.c
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ _io__WindowsConsoleIO___init___impl(winconsoleio *self, PyObject *nameobj,
int fd_is_own = 0;
HANDLE handle = NULL;

#ifdef NDEBUG
#ifndef NDEBUG
_PyIO_State *state = find_io_state_by_def(Py_TYPE(self));
assert(PyObject_TypeCheck(self, state->PyWindowsConsoleIO_Type));
#endif
Expand Down
12 changes: 0 additions & 12 deletions Objects/typeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -10245,18 +10245,6 @@ _PySuper_Lookup(PyTypeObject *su_type, PyObject *su_obj, PyObject *name, int *me
return res;
}

PyObject *
_PySuper_LookupDescr(PyTypeObject *su_type, PyObject *su_obj, PyObject *name)
{
PyTypeObject *su_obj_type = supercheck(su_type, su_obj);
if (su_obj_type == NULL) {
return NULL;
}
PyObject *res = _super_lookup_descr(su_type, su_obj_type, name);
Py_DECREF(su_obj_type);
return res;
}

static PyObject *
super_descr_get(PyObject *self, PyObject *obj, PyObject *type)
{
Expand Down
40 changes: 31 additions & 9 deletions Python/bytecodes.c
Original file line number Diff line number Diff line change
Expand Up @@ -1570,17 +1570,18 @@ dummy_func(

family(load_super_attr, INLINE_CACHE_ENTRIES_LOAD_SUPER_ATTR) = {
LOAD_SUPER_ATTR,
LOAD_SUPER_ATTR_ATTR,
LOAD_SUPER_ATTR_METHOD,
};

inst(LOAD_SUPER_ATTR, (unused/9, global_super, class, self -- res2 if (oparg & 1), res)) {
inst(LOAD_SUPER_ATTR, (unused/1, global_super, class, self -- res2 if (oparg & 1), res)) {
PyObject *name = GETITEM(frame->f_code->co_names, oparg >> 2);
int load_method = oparg & 1;
#if ENABLE_SPECIALIZATION
_PySuperAttrCache *cache = (_PySuperAttrCache *)next_instr;
if (ADAPTIVE_COUNTER_IS_ZERO(cache->counter)) {
next_instr--;
_Py_Specialize_LoadSuperAttr(global_super, class, self, next_instr, name, load_method);
_Py_Specialize_LoadSuperAttr(global_super, class, next_instr, load_method);
DISPATCH_SAME_OPARG();
}
STAT_INC(LOAD_SUPER_ATTR, deferred);
Expand Down Expand Up @@ -1622,17 +1623,38 @@ dummy_func(
ERROR_IF(res == NULL, error);
}

inst(LOAD_SUPER_ATTR_METHOD, (unused/1, class_version/2, self_type_version/2, method/4, global_super, class, self -- res2, res)) {
inst(LOAD_SUPER_ATTR_ATTR, (unused/1, global_super, class, self -- res2 if (oparg & 1), res)) {
assert(!(oparg & 1));
DEOPT_IF(global_super != (PyObject *)&PySuper_Type, LOAD_SUPER_ATTR);
DEOPT_IF(!PyType_Check(class), LOAD_SUPER_ATTR);
DEOPT_IF(((PyTypeObject *)class)->tp_version_tag != class_version, LOAD_SUPER_ATTR);
PyTypeObject *self_type = Py_TYPE(self);
DEOPT_IF(self_type->tp_version_tag != self_type_version, LOAD_SUPER_ATTR);
res2 = method;
res = self; // transfer ownership
Py_INCREF(res2);
STAT_INC(LOAD_SUPER_ATTR, hit);
PyObject *name = GETITEM(frame->f_code->co_names, oparg >> 2);
res = _PySuper_Lookup((PyTypeObject *)class, self, name, NULL);
ERROR_IF(res == NULL, error);
DECREF_INPUTS();
}

inst(LOAD_SUPER_ATTR_METHOD, (unused/1, global_super, class, self -- res2, res)) {
assert(oparg & 1);
DEOPT_IF(global_super != (PyObject *)&PySuper_Type, LOAD_SUPER_ATTR);
DEOPT_IF(!PyType_Check(class), LOAD_SUPER_ATTR);
STAT_INC(LOAD_SUPER_ATTR, hit);
PyObject *name = GETITEM(frame->f_code->co_names, oparg >> 2);
int method_found = 0;
res2 = _PySuper_Lookup((PyTypeObject *)class, self, name, &method_found);
Py_DECREF(global_super);
Py_DECREF(class);
if (res2 == NULL) {
Py_DECREF(self);
ERROR_IF(true, error);
}
if (method_found) {
res = self; // transfer ownership
} else {
Py_DECREF(self);
res = res2;
res2 = NULL;
}
}

family(load_attr, INLINE_CACHE_ENTRIES_LOAD_ATTR) = {
Expand Down
Loading

0 comments on commit fb47955

Please sign in to comment.