8000 bpo-44338: Port LOAD_GLOBAL to PEP 659 adaptive interpreter by markshannon · Pull Request #26638 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

bpo-44338: Port LOAD_GLOBAL to PEP 659 adaptive interpreter #26638

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Jun 14, 2021
Prev Previous commit
Next Next commit
Fix a couple of copy and paste errors
  • Loading branch information
markshannon committed Jun 11, 2021
commit f043576ed38ddecd6c0d3e909a124d10a9877fdc
4 changes: 2 additions & 2 deletions Python/ceval.c
Original file line number Diff line number Diff line change
Expand Up @@ -2879,7 +2879,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, PyFrameObject *f, int throwflag)
DEOPT_IF(dict->ma_keys->dk_version != cache1->module_keys_version, LOAD_GLOBAL);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we also need to check the case where it's a different globals dict? It can't be done from Python (except if someone creates a new function using the code object from another function, or passes the code object to exec()) but can easily be done from C. There is the remote chance that (in that already unlikely case) the keys version is the same.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the keys version is the same, then it has the same keys in the same order and is the same kind of dict.
In which case it doesn't matter if it is a different dictionary, because we cache the index, not the value.

As an aside, you can get different dictionaries with the same keys as module dicts at different times.

class C: pass
d1 = C().__dict__
d2 = C().__dict__
# d1 and d2 should share keys
m = ModuleType()
m.__dict__ = d1
# Specialize
m.__dict__ = d2
# globals in m would see same keys as when specialized

PyDictKeyEntry *ep = DK_ENTRIES(dict->ma_keys) + cache0->index;
PyObject *res = ep->me_value;
DEOPT_IF(res == NULL, LOAD_ATTR);
DEOPT_IF(res == NULL, LOAD_GLOBAL);
record_cache_hit(cache0);
STAT_INC(LOAD_GLOBAL, hit);
Py_INCREF(res);
Expand All @@ -2899,7 +2899,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, PyFrameObject *f, int throwflag)
DEOPT_IF(bdict->ma_keys->dk_version != cache1->builtin_keys_version, LOAD_GLOBAL);
PyDictKeyEntry *ep = DK_ENTRIES(bdict->ma_keys) + cache0->index;
PyObject *res = ep->me_value;
DEOPT_IF(res == NULL, LOAD_ATTR);
DEOPT_IF(res == NULL, LOAD_GLOBAL);
record_cache_hit(cache0);
STAT_INC(LOAD_GLOBAL, hit);
Py_INCREF(res);
Expand Down
0