summaryrefslogtreecommitdiffstats
path: root/Python/optimizer_bytecodes.c
diff options
context:
space:
mode:
authormpage <mpage@meta.com>2024-12-13 18:17:16 (GMT)
committerGitHub <noreply@github.com>2024-12-13 18:17:16 (GMT)
commit2de048ce79e621f5ae0574095b9600fe8595f607 (patch)
treede3116284fc2016192787297de7a67ba348e5825 /Python/optimizer_bytecodes.c
parent292067fbc9db81896c16ff12d51c21d2b0f233e2 (diff)
downloadcpython-2de048ce79e621f5ae0574095b9600fe8595f607.zip
cpython-2de048ce79e621f5ae0574095b9600fe8595f607.tar.gz
cpython-2de048ce79e621f5ae0574095b9600fe8595f607.tar.bz2
gh-115999: Specialize loading attributes from modules in free-threaded builds (#127711)
We use the same approach that was used for specialization of LOAD_GLOBAL in free-threaded builds: _CHECK_ATTR_MODULE is renamed to _CHECK_ATTR_MODULE_PUSH_KEYS; it pushes the keys object for the following _LOAD_ATTR_MODULE_FROM_KEYS (nee _LOAD_ATTR_MODULE). This arrangement avoids having to recheck the keys version. _LOAD_ATTR_MODULE is renamed to _LOAD_ATTR_MODULE_FROM_KEYS; it loads the value from the keys object pushed by the preceding _CHECK_ATTR_MODULE_PUSH_KEYS at the cached index.
Diffstat (limited to 'Python/optimizer_bytecodes.c')
-rw-r--r--Python/optimizer_bytecodes.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/Python/optimizer_bytecodes.c b/Python/optimizer_bytecodes.c
index 42bdbd9..0b8aff0 100644
--- a/Python/optimizer_bytecodes.c
+++ b/Python/optimizer_bytecodes.c
@@ -492,8 +492,9 @@ dummy_func(void) {
(void)owner;
}
- op(_CHECK_ATTR_MODULE, (dict_version/2, owner -- owner)) {
+ op(_CHECK_ATTR_MODULE_PUSH_KEYS, (dict_version/2, owner -- owner, mod_keys)) {
(void)dict_version;
+ mod_keys = sym_new_not_null(ctx);
if (sym_is_const(owner)) {
PyObject *cnst = sym_get_const(owner);
if (PyModule_CheckExact(cnst)) {
@@ -515,12 +516,12 @@ dummy_func(void) {
self_or_null = sym_new_unknown(ctx);
}
- op(_LOAD_ATTR_MODULE, (index/1, owner -- attr, null if (oparg & 1))) {
+ op(_LOAD_ATTR_MODULE_FROM_KEYS, (index/1, owner, mod_keys -- attr, null if (oparg & 1))) {
(void)index;
null = sym_new_null(ctx);
attr = NULL;
if (this_instr[-1].opcode == _NOP) {
- // Preceding _CHECK_ATTR_MODULE was removed: mod is const and dict is watched.
+ // Preceding _CHECK_ATTR_MODULE_PUSH_KEYS was removed: mod is const and dict is watched.
assert(sym_is_const(owner));
PyModuleObject *mod = (PyModuleObject *)sym_get_const(owner);
assert(PyModule_CheckExact(mod));
@@ -530,6 +531,9 @@ dummy_func(void) {
this_instr[-1].opcode = _POP_TOP;
attr = sym_new_const(ctx, res);
}
+ else {
+ this_instr->opcode = _LOAD_ATTR_MODULE;
+ }
}
if (attr == NULL) {
/* No conversion made. We don't know what `attr` is. */