2021-11-23 09:53:24 +00:00
|
|
|
#ifndef Py_INTERNAL_FUNCTION_H
|
|
|
|
#define Py_INTERNAL_FUNCTION_H
|
2022-02-25 16:07:14 +01:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
2021-11-23 09:53:24 +00:00
|
|
|
|
2022-02-25 16:07:14 +01:00
|
|
|
#ifndef Py_BUILD_CORE
|
|
|
|
# error "this header requires Py_BUILD_CORE define"
|
|
|
|
#endif
|
2021-11-23 09:53:24 +00:00
|
|
|
|
2023-07-22 23:44:33 +02:00
|
|
|
extern PyObject* _PyFunction_Vectorcall(
|
|
|
|
PyObject *func,
|
|
|
|
PyObject *const *stack,
|
|
|
|
size_t nargsf,
|
|
|
|
PyObject *kwnames);
|
|
|
|
|
2022-11-22 04:06:44 -08:00
|
|
|
|
2024-10-08 07:04:35 -07:00
|
|
|
#define FUNC_VERSION_UNSET 0
|
|
|
|
#define FUNC_VERSION_CLEARED 1
|
|
|
|
#define FUNC_VERSION_FIRST_VALID 2
|
|
|
|
|
2022-02-25 16:07:14 +01:00
|
|
|
extern PyFunctionObject* _PyFunction_FromConstructor(PyFrameConstructor *constr);
|
2021-11-23 09:53:24 +00:00
|
|
|
|
2024-10-08 07:04:35 -07:00
|
|
|
static inline int
|
|
|
|
_PyFunction_IsVersionValid(uint32_t version)
|
|
|
|
{
|
|
|
|
return version >= FUNC_VERSION_FIRST_VALID;
|
|
|
|
}
|
|
|
|
|
2022-02-25 16:07:14 +01:00
|
|
|
extern uint32_t _PyFunction_GetVersionForCurrentState(PyFunctionObject *func);
|
2024-02-29 08:11:28 -08:00
|
|
|
PyAPI_FUNC(void) _PyFunction_SetVersion(PyFunctionObject *func, uint32_t version);
|
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.
2024-03-21 12:37:41 -07:00
|
|
|
void _PyFunction_ClearCodeByVersion(uint32_t version);
|
|
|
|
PyFunctionObject *_PyFunction_LookupByVersion(uint32_t version, PyObject **p_code);
|
2023-08-17 11:29:58 -07:00
|
|
|
|
2023-05-15 20:36:23 -07:00
|
|
|
extern PyObject *_Py_set_function_type_params(
|
|
|
|
PyThreadState* unused, PyObject *func, PyObject *type_params);
|
2021-11-23 09:53:24 +00:00
|
|
|
|
2025-05-05 15:48:58 -06:00
|
|
|
|
|
|
|
/* See pycore_code.h for explanation about what "stateless" means. */
|
|
|
|
|
|
|
|
PyAPI_FUNC(int)
|
|
|
|
_PyFunction_VerifyStateless(PyThreadState *, PyObject *);
|
|
|
|
|
|
|
|
|
2022-02-25 16:07:14 +01:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
2021-11-23 09:53:24 +00:00
|
|
|
#endif /* !Py_INTERNAL_FUNCTION_H */
|