mirror of
https://github.com/python/cpython.git
synced 2025-12-15 21:44:50 +00:00
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.
This commit is contained in:
parent
c85d84166a
commit
570a82d46a
8 changed files with 208 additions and 95 deletions
|
|
@ -55,7 +55,7 @@ enum _frameowner {
|
|||
};
|
||||
|
||||
typedef struct _PyInterpreterFrame {
|
||||
PyObject *f_executable; /* Strong reference */
|
||||
PyObject *f_executable; /* Strong reference (code object or None) */
|
||||
struct _PyInterpreterFrame *previous;
|
||||
PyObject *f_funcobj; /* Strong reference. Only valid if not on C stack */
|
||||
PyObject *f_globals; /* Borrowed reference. Only valid if not on C stack */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue