Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Merge LOAD_METHOD back into LOAD_ATTR
  • Loading branch information
Fidget-Spinner committed Jun 2, 2022
commit 7ea8f6647fd938ec6295176da65412c82b840292
7 changes: 3 additions & 4 deletions Include/internal/pycore_code.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ typedef struct {
_Py_CODEUNIT index;
} _PyAttrCache;

#define INLINE_CACHE_ENTRIES_LOAD_ATTR CACHE_ENTRIES(_PyAttrCache)

// MUST be the max(_PyAttrCache, _PyLoadMethodCache)
#define INLINE_CACHE_ENTRIES_LOAD_ATTR CACHE_ENTRIES(_PyLoadMethodCache)

#define INLINE_CACHE_ENTRIES_STORE_ATTR CACHE_ENTRIES(_PyAttrCache)

Expand All @@ -70,7 +72,6 @@ typedef struct {
_Py_CODEUNIT descr[4];
} _PyLoadMethodCache;

#define INLINE_CACHE_ENTRIES_LOAD_METHOD CACHE_ENTRIES(_PyLoadMethodCache)

typedef struct {
_Py_CODEUNIT counter;
Expand Down Expand Up @@ -234,8 +235,6 @@ extern int _Py_Specialize_LoadAttr(PyObject *owner, _Py_CODEUNIT *instr,
extern int _Py_Specialize_StoreAttr(PyObject *owner, _Py_CODEUNIT *instr,
PyObject *name);
extern int _Py_Specialize_LoadGlobal(PyObject *globals, PyObject *builtins, _Py_CODEUNIT *instr, PyObject *name);
extern int _Py_Specialize_LoadMethod(PyObject *owner, _Py_CODEUNIT *instr,
PyObject *name);
extern int _Py_Specialize_BinarySubscr(PyObject *sub, PyObject *container, _Py_CODEUNIT *instr);
extern int _Py_Specialize_StoreSubscr(PyObject *container, PyObject *sub, _Py_CODEUNIT *instr);
extern int _Py_Specialize_Call(PyObject *callable, _Py_CODEUNIT *instr,
Expand Down
68 changes: 33 additions & 35 deletions Include/internal/pycore_opcode.h

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

53 changes: 26 additions & 27 deletions Include/opcode.h

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

5 changes: 5 additions & 0 deletions Lib/dis.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
LOAD_GLOBAL = opmap['LOAD_GLOBAL']
BINARY_OP = opmap['BINARY_OP']
JUMP_BACKWARD = opmap['JUMP_BACKWARD']
LOAD_ATTR = opmap['LOAD_ATTR']

CACHE = opmap["CACHE"]

Expand Down Expand Up @@ -463,6 +464,10 @@ def _get_instructions_bytes(code, varname_from_oparg=None,
argval, argrepr = _get_name_info(arg//2, get_name)
if (arg & 1) and argrepr:
argrepr = "NULL + " + argrepr
elif deop == LOAD_ATTR:
argval, argrepr = _get_name_info(arg//2, get_name)
if (arg & 1) and argrepr:
argrepr = "NULL|self + " + argrepr
else:
argval, argrepr = _get_name_info(arg, get_name)
elif deop in hasjabs:
Expand Down
3 changes: 2 additions & 1 deletion Lib/importlib/_bootstrap_external.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,7 @@ def _write_atomic(path, data, mode=0o666):
# Python 3.12a1 3500 (Remove PRECALL opcode)
# Python 3.12a1 3501 (YIELD_VALUE oparg == stack_depth)
# Python 3.12a1 3502 (LOAD_FAST_CHECK, no NULL-check in LOAD_FAST)
# Python 3.12a1 3503 (Merge LOAD_METHOD back into LOAD_ATTR)

# Python 3.13 will start with 3550

Expand All @@ -420,7 +421,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 = (3502).to_bytes(2, 'little') + b'\r\n'
MAGIC_NUMBER = (3503).to_bytes(2, 'little') + b'\r\n'

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

Expand Down
26 changes: 10 additions & 16 deletions Lib/opcode.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,10 +285,18 @@ def jabs_op(name, op):
],
"LOAD_ATTR": [
"LOAD_ATTR_ADAPTIVE",
# LOAD_ATTR
"LOAD_ATTR_INSTANCE_VALUE",
"LOAD_ATTR_MODULE",
"LOAD_ATTR_SLOT",
"LOAD_ATTR_WITH_HINT",
# LOAD_METHOD
"LOAD_ATTR_METHOD_CLASS",
"LOAD_ATTR_METHOD_LAZY_DICT",
"LOAD_ATTR_METHOD_MODULE",
"LOAD_ATTR_METHOD_NO_DICT",
"LOAD_ATTR_METHOD_WITH_DICT",
"LOAD_ATTR_METHOD_WITH_VALUES",
],
"LOAD_CONST": [
"LOAD_CONST__LOAD_FAST",
Expand All @@ -302,15 +310,6 @@ def jabs_op(name, op):
"LOAD_GLOBAL_BUILTIN",
"LOAD_GLOBAL_MODULE",
],
"LOAD_METHOD": [
"LOAD_METHOD_ADAPTIVE",
"LOAD_METHOD_CLASS",
"LOAD_METHOD_LAZY_DICT",
"LOAD_METHOD_MODULE",
"LOAD_METHOD_NO_DICT",
"LOAD_METHOD_WITH_DICT",
"LOAD_METHOD_WITH_VALUES",
],
"RESUME": [
"RESUME_QUICK",
],
Expand Down Expand Up @@ -374,19 +373,14 @@ def jabs_op(name, op):
"counter": 1,
"version": 2,
"index": 1,
"keys_version": 2,
"descr": 4,
},
"STORE_ATTR": {
"counter": 1,
"version": 2,
"index": 1,
},
"LOAD_METHOD": {
"counter": 1,
"type_version": 2,
"dict_offset": 1,
"keys_version": 2,
"descr": 4,
},
"CALL": {
"counter": 1,
"func_version": 2,
Expand Down
6 changes: 3 additions & 3 deletions Lib/test/test_dis.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,11 +366,11 @@ def bug42562():

%3d LOAD_GLOBAL 0 (Exception)
CHECK_EXC_MATCH
POP_JUMP_FORWARD_IF_FALSE 18 (to 72)
POP_JUMP_FORWARD_IF_FALSE 24 (to 84)
STORE_FAST 0 (e)

%3d LOAD_FAST 0 (e)
LOAD_ATTR 1 (__traceback__)
LOAD_ATTR 2 (__traceback__)
STORE_FAST 1 (tb)
POP_EXCEPT
LOAD_CONST 0 (None)
Expand Down Expand Up @@ -967,7 +967,7 @@ def test_load_attr_specialize(self):

1 2 LOAD_CONST 0 ('a')
4 LOAD_ATTR_SLOT 0 (__class__)
14 RETURN_VALUE
26 RETURN_VALUE
"""
co = compile("'a'.__class__", "", "eval")
self.code_quicken(lambda: exec(co, {}, {}))
Expand Down
Loading