diff options
author | Guido van Rossum <guido@python.org> | 2024-03-21 19:37:41 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-03-21 19:37:41 (GMT) |
commit | 570a82d46abfebb9976961113fb0f8bb400ad182 (patch) | |
tree | 7b0b356a3ee48e8452aa823cc14e6bbed870b599 /Objects/codeobject.c | |
parent | c85d84166a84a5cb2d724012726bad34229ad24e (diff) | |
download | cpython-570a82d46abfebb9976961113fb0f8bb400ad182.zip cpython-570a82d46abfebb9976961113fb0f8bb400ad182.tar.gz cpython-570a82d46abfebb9976961113fb0f8bb400ad182.tar.bz2 |
gh-117045: Add code object to function version cache (#117028)
Changes to the function version cache:
- In addition to the function object, also store the code object,
and allow the latter to be retrieved even if the function has been evicted.
- Stop assigning new function versions after a critical attribute (e.g. `__code__`)
has been modified; the version is permanently reset to zero in this case.
- Changes to `__annotations__` are no longer considered critical. (This fixes gh-109998.)
Changes to the Tier 2 optimization machinery:
- If we cannot map a function version to a function, but it is still mapped to a code object,
we continue projecting the trace.
The operand of the `_PUSH_FRAME` and `_POP_FRAME` opcodes can be either NULL,
a function object, or a code object with the lowest bit set.
This allows us to trace through code that calls an ephemeral function,
i.e., a function that may not be alive when we are constructing the executor,
e.g. a generator expression or certain nested functions.
We will lose globals removal inside such functions,
but we can still do other peephole operations
(and even possibly [call inlining](https://github.com/python/cpython/pull/116290),
if we decide to do it), which only need the code object.
As before, if we cannot retrieve the code object from the cache, we stop projecting.
Diffstat (limited to 'Objects/codeobject.c')
-rw-r--r-- | Objects/codeobject.c | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/Objects/codeobject.c b/Objects/codeobject.c index 3df733e..bdde12d 100644 --- a/Objects/codeobject.c +++ b/Objects/codeobject.c @@ -1710,6 +1710,7 @@ code_dealloc(PyCodeObject *co) } Py_SET_REFCNT(co, 0); + _PyFunction_ClearCodeByVersion(co->co_version); if (co->co_extra != NULL) { PyInterpreterState *interp = _PyInterpreterState_GET(); _PyCodeObjectExtra *co_extra = co->co_extra; |