mirror of
https://github.com/python/cpython.git
synced 2025-10-17 20:28:43 +00:00
gh-117139: Convert the evaluation stack to stack refs (#118450)
This PR sets up tagged pointers for CPython. The general idea is to create a separate struct _PyStackRef for everything on the evaluation stack to store the bits. This forces the C compiler to warn us if we try to cast things or pull things out of the struct directly. Only for free threading: We tag the low bit if something is deferred - that means we skip incref and decref operations on it. This behavior may change in the future if Mark's plans to defer all objects in the interpreter loop pans out. This implies a strict stack reference discipline is required. ALL incref and decref operations on stackrefs must use the stackref variants. It is unsafe to untag something then do normal incref/decref ops on it. The new incref and decref variants are called dup and close. They mimic a "handle" API operating on these stackrefs. Please read Include/internal/pycore_stackref.h for more information! --------- Co-authored-by: Mark Shannon <9448417+markshannon@users.noreply.github.com>
This commit is contained in:
parent
d611c4c8e9
commit
22b0de2755
35 changed files with 5228 additions and 3758 deletions
|
@ -8,6 +8,7 @@ extern "C" {
|
|||
# error "this header requires Py_BUILD_CORE define"
|
||||
#endif
|
||||
|
||||
#include "pycore_stackref.h" // _PyStackRef
|
||||
#include "pycore_lock.h" // PyMutex
|
||||
#include "pycore_backoff.h" // _Py_BackoffCounter
|
||||
|
||||
|
@ -317,30 +318,30 @@ extern void _PyCode_Clear_Executors(PyCodeObject *code);
|
|||
|
||||
/* Specialization functions */
|
||||
|
||||
extern void _Py_Specialize_LoadSuperAttr(PyObject *global_super, PyObject *cls,
|
||||
extern void _Py_Specialize_LoadSuperAttr(_PyStackRef global_super, _PyStackRef cls,
|
||||
_Py_CODEUNIT *instr, int load_method);
|
||||
extern void _Py_Specialize_LoadAttr(PyObject *owner, _Py_CODEUNIT *instr,
|
||||
extern void _Py_Specialize_LoadAttr(_PyStackRef owner, _Py_CODEUNIT *instr,
|
||||
PyObject *name);
|
||||
extern void _Py_Specialize_StoreAttr(PyObject *owner, _Py_CODEUNIT *instr,
|
||||
extern void _Py_Specialize_StoreAttr(_PyStackRef owner, _Py_CODEUNIT *instr,
|
||||
PyObject *name);
|
||||
extern void _Py_Specialize_LoadGlobal(PyObject *globals, PyObject *builtins,
|
||||
_Py_CODEUNIT *instr, PyObject *name);
|
||||
extern void _Py_Specialize_BinarySubscr(PyObject *sub, PyObject *container,
|
||||
extern void _Py_Specialize_BinarySubscr(_PyStackRef sub, _PyStackRef container,
|
||||
_Py_CODEUNIT *instr);
|
||||
extern void _Py_Specialize_StoreSubscr(PyObject *container, PyObject *sub,
|
||||
extern void _Py_Specialize_StoreSubscr(_PyStackRef container, _PyStackRef sub,
|
||||
_Py_CODEUNIT *instr);
|
||||
extern void _Py_Specialize_Call(PyObject *callable, _Py_CODEUNIT *instr,
|
||||
extern void _Py_Specialize_Call(_PyStackRef callable, _Py_CODEUNIT *instr,
|
||||
int nargs);
|
||||
extern void _Py_Specialize_BinaryOp(PyObject *lhs, PyObject *rhs, _Py_CODEUNIT *instr,
|
||||
int oparg, PyObject **locals);
|
||||
extern void _Py_Specialize_CompareOp(PyObject *lhs, PyObject *rhs,
|
||||
extern void _Py_Specialize_BinaryOp(_PyStackRef lhs, _PyStackRef rhs, _Py_CODEUNIT *instr,
|
||||
int oparg, _PyStackRef *locals);
|
||||
extern void _Py_Specialize_CompareOp(_PyStackRef lhs, _PyStackRef rhs,
|
||||
_Py_CODEUNIT *instr, int oparg);
|
||||
extern void _Py_Specialize_UnpackSequence(PyObject *seq, _Py_CODEUNIT *instr,
|
||||
extern void _Py_Specialize_UnpackSequence(_PyStackRef seq, _Py_CODEUNIT *instr,
|
||||
int oparg);
|
||||
extern void _Py_Specialize_ForIter(PyObject *iter, _Py_CODEUNIT *instr, int oparg);
|
||||
extern void _Py_Specialize_Send(PyObject *receiver, _Py_CODEUNIT *instr);
|
||||
extern void _Py_Specialize_ToBool(PyObject *value, _Py_CODEUNIT *instr);
|
||||
extern void _Py_Specialize_ContainsOp(PyObject *value, _Py_CODEUNIT *instr);
|
||||
extern void _Py_Specialize_ForIter(_PyStackRef iter, _Py_CODEUNIT *instr, int oparg);
|
||||
extern void _Py_Specialize_Send(_PyStackRef receiver, _Py_CODEUNIT *instr);
|
||||
extern void _Py_Specialize_ToBool(_PyStackRef value, _Py_CODEUNIT *instr);
|
||||
extern void _Py_Specialize_ContainsOp(_PyStackRef value, _Py_CODEUNIT *instr);
|
||||
|
||||
#ifdef Py_STATS
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue