cpython/Include/internal
Ken Jin 22b0de2755
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>
2024-06-27 03:10:43 +08:00
..
mimalloc Fix typos in comments (#120188) 2024-06-07 10:19:41 +02:00
pycore_abstract.h gh-106320: Remove private AC converter functions (#108505) 2023-08-26 04:05:17 +02:00
pycore_asdl.h gh-87347: Add parenthesis around macro arguments (#93915) 2022-06-20 16:04:52 +02:00
pycore_ast_state.h gh-116126: Implement PEP 696 (#116129) 2024-05-03 06:17:32 -07:00
pycore_ast.h gh-116126: Implement PEP 696 (#116129) 2024-05-03 06:17:32 -07:00
pycore_atexit.h gh-76785: Rename _xxsubinterpreters to _interpreters (gh-117791) 2024-04-24 16:18:24 +00:00
pycore_backoff.h gh-120642: Move private PyCode APIs to the internal C API (#120643) 2024-06-26 13:54:03 +02:00
pycore_bitutils.h gh-108216: Cleanup #include in internal header files (#108228) 2023-08-21 18:05:59 +00:00
pycore_blocks_output_buffer.h gh-108220: Internal header files require Py_BUILD_CORE to be defined (#108221) 2023-08-21 19:15:52 +02:00
pycore_brc.h gh-110481: Implement inter-thread queue for biased reference counting (#114824) 2024-02-09 17:08:32 -05:00
pycore_bytes_methods.h gh-117431: Adapt bytes and bytearray .find() and friends to Argument Clinic (#117502) 2024-04-12 07:40:55 +00:00
pycore_bytesobject.h gh-107211: No longer export internal functions (5) (#108423) 2023-08-24 16:06:53 +00:00
pycore_call.h gh-112026: Restore removed private C API (#112115) 2023-11-15 16:38:31 +00:00
pycore_capsule.h gh-108240: Add pycore_capsule.h internal header file (#108596) 2023-08-29 01:20:02 +00:00
pycore_cell.h gh-117323: Make cell thread-safe in free-threaded builds (#117330) 2024-03-29 13:35:43 -04:00
pycore_ceval_state.h gh-118518: Allow perf to work without frame pointers (#112254) 2024-05-05 03:07:29 +02:00
pycore_ceval.h gh-117139: Convert the evaluation stack to stack refs (#118450) 2024-06-27 03:10:43 +08:00
pycore_code.h gh-117139: Convert the evaluation stack to stack refs (#118450) 2024-06-27 03:10:43 +08:00
pycore_codecs.h gh-116738: Make _codecs module thread-safe (#117530) 2024-05-02 18:25:36 -04:00
pycore_compile.h gh-119744: move a few functions from compile.c to flowgraph.c (#119745) 2024-05-30 21:55:06 +01:00
pycore_complexobject.h gh-112026: Restore removed private C API (#112115) 2023-11-15 16:38:31 +00:00
pycore_condvar.h gh-104530: Enable native Win32 condition variables by default (GH-104531) 2024-02-02 13:50:51 +00:00
pycore_context.h gh-111968: Refactor _PyXXX_Fini to integrate with _PyObject_ClearFreeLists (gh-114899) 2024-02-10 00:57:04 +00:00
pycore_critical_section.h gh-119344: Make critical section API public (#119353) 2024-06-21 15:50:18 -04:00
pycore_crossinterp.h gh-76785: Handle Legacy Interpreters Properly (gh-117490) 2024-04-11 23:23:25 +00:00
pycore_descrobject.h gh-106320: Move _PyMethodWrapper_Type to internal C API (#107064) 2023-07-22 20:57:59 +00:00
pycore_dict_state.h GH-113710: Add a "globals to constants" pass (GH-114592) 2024-02-02 12:14:34 +00:00
pycore_dict.h GH-119258: Handle STORE_ATTR_WITH_HINT in tier two (GH-119481) 2024-05-28 12:47:54 -07:00
pycore_dtoa.h gh-111962: Make dtoa thread-safe in --disable-gil builds. (#112049) 2023-12-07 13:47:55 +00:00
pycore_emscripten_signal.h GH-108614: Unbreak emscripten build (GH-109132) 2023-09-08 17:54:45 +01:00
pycore_emscripten_trampoline.h gh-106213: Make Emscripten trampolines work with JSPI (GH-106219) 2023-09-15 15:04:21 -07:00
pycore_exceptions.h bpo-46417: Factorize _PyExc_InitTypes() code (GH-30804) 2022-01-22 21:48:56 +01:00
pycore_faulthandler.h gh-108216: Cleanup #include in internal header files (#108228) 2023-08-21 18:05:59 +00:00
pycore_fileutils_windows.h gh-108220: Internal header files require Py_BUILD_CORE to be defined (#108221) 2023-08-21 19:15:52 +02:00
pycore_fileutils.h gh-118422: Fix run_fileexflags() test (#118429) 2024-04-30 22:32:55 +02:00
pycore_floatobject.h GH-115802: JIT "small" code for Windows (GH-115964) 2024-02-29 08:11:28 -08:00
pycore_flowgraph.h gh-119744: move a few functions from compile.c to flowgraph.c (#119745) 2024-05-30 21:55:06 +01:00
pycore_format.h gh-104018: remove unused format "z" handling in string formatfloat() (#104107) 2023-05-07 10:11:42 +05:30
pycore_frame.h gh-117139: Convert the evaluation stack to stack refs (#118450) 2024-06-27 03:10:43 +08:00
pycore_freelist.h gh-111968: Split _Py_async_gen_asend_freelist out of _Py_async_gen_fr… (gh-115546) 2024-02-17 10:03:10 +09:00
pycore_function.h gh-117657: Disable the function/code cache in free-threaded builds (#118301) 2024-05-03 16:21:04 -04:00
pycore_gc.h Fix typos in comments (#120481) 2024-06-19 23:16:14 -04:00
pycore_genobject.h gh-120834: fix type of *_iframe field in _PyGenObject_HEAD declaration (#120835) 2024-06-24 10:23:38 +01:00
pycore_getopt.h bpo-36763: Cleanup precmdline in _PyCoreConfig_Read() (GH-13371) 2019-05-17 03:15:12 +02:00
pycore_gil.h gh-116322: Enable the GIL while loading C extension modules (#118560) 2024-05-06 23:07:23 -04:00
pycore_global_objects_fini_generated.h GH-107803: double linked list implementation for asyncio tasks (GH-107804) 2024-06-22 10:58:35 -07:00
pycore_global_objects.h gh-108216: Cleanup #include in internal header files (#108228) 2023-08-21 18:05:59 +00:00
pycore_global_strings.h GH-107803: double linked list implementation for asyncio tasks (GH-107804) 2024-06-22 10:58:35 -07:00
pycore_hamt.h gh-81057: Move contextvars-related Globals to _PyRuntimeState (gh-99400) 2022-11-16 09:54:28 -07:00
pycore_hashtable.h gh-107211: No longer export internal functions (5) (#108423) 2023-08-24 16:06:53 +00:00
pycore_identifier.h gh-112026: Restore removed private C API (#112115) 2023-11-15 16:38:31 +00:00
pycore_import.h gh-117657: Fix TSAN race involving import lock (#118523) 2024-06-06 13:40:58 -04:00
pycore_importdl.h gh-117953: Track Extra Details in Global Extensions Cache (gh-118532) 2024-05-04 21:24:02 +00:00
pycore_initconfig.h Fix typos in comments (#120188) 2024-06-07 10:19:41 +02:00
pycore_instruction_sequence.h gh-117901: Add option for compiler's codegen to save nested instruction sequences for introspection (#118007) 2024-04-24 09:46:17 +00:00
pycore_instruments.h Fix typos in comments (#120188) 2024-06-07 10:19:41 +02:00
pycore_interp.h gh-120642: Move private PyCode APIs to the internal C API (#120643) 2024-06-26 13:54:03 +02:00
pycore_intrinsics.h gh-116126: Implement PEP 696 (#116129) 2024-05-03 06:17:32 -07:00
pycore_jit.h gh-117139: Convert the evaluation stack to stack refs (#118450) 2024-06-27 03:10:43 +08:00
pycore_list.h gh-117657: Fix TSAN list set failure (#118260) 2024-05-02 13:03:05 -07:00
pycore_llist.h gh-111964: Implement stop-the-world pauses (gh-112471) 2024-01-23 11:08:23 -07:00
pycore_lock.h gh-117511: Make PyMutex public in the non-limited API (#117731) 2024-06-20 11:29:08 -04:00
pycore_long.h gh-120593: Fix const qualifier in _PyLong_CompactValue() (#121053) 2024-06-26 20:11:21 +02:00
pycore_memoryobject.h gh-106320: Remove private _PyManagedBuffer_Type (#108431) 2023-08-24 19:07:54 +02:00
pycore_mimalloc.h gh-117657: Fix race involving GC and heap initialization (#119923) 2024-06-04 09:42:13 -04:00
pycore_modsupport.h gh-111956: Add thread-safe one-time initialization. (gh-111960) 2023-11-16 12:19:54 -07:00
pycore_moduleobject.h gh-116322: Add Py_mod_gil module slot (#116882) 2024-05-03 11:30:55 -04:00
pycore_namespace.h gh-107211: No longer export internal functions (4) (#107217) 2023-07-25 03:16:28 +00:00
pycore_object_alloc.h gh-112529: Use GC heaps for GC allocations in free-threaded builds (gh-114157) 2024-01-21 01:14:45 +09:00
pycore_object_deferred.h gh-117139: Convert the evaluation stack to stack refs (#118450) 2024-06-27 03:10:43 +08:00
pycore_object_stack.h gh-111968: Refactor _PyXXX_Fini to integrate with _PyObject_ClearFreeLists (gh-114899) 2024-02-10 00:57:04 +00:00
pycore_object_state.h gh-111968: Rename freelist related struct names to Eric's suggestion (gh-115329) 2024-02-14 00:32:51 +00:00
pycore_object.h gh-117139: Convert the evaluation stack to stack refs (#118450) 2024-06-27 03:10:43 +08:00
pycore_obmalloc_init.h gh-113055: Use pointer for interp->obmalloc state (gh-113412) 2024-01-26 19:38:14 -08:00
pycore_obmalloc.h gh-113055: Use pointer for interp->obmalloc state (gh-113412) 2024-01-26 19:38:14 -08:00
pycore_opcode_metadata.h GH-120507: Lower the BEFORE_WITH and BEFORE_ASYNC_WITH instructions. (#120640) 2024-06-18 12:17:46 +01:00
pycore_opcode_utils.h gh-119180: PEP 649 compiler changes (#119361) 2024-06-11 13:06:49 +00:00
pycore_optimizer.h gh-117139: Convert the evaluation stack to stack refs (#118450) 2024-06-27 03:10:43 +08:00
pycore_parking_lot.h gh-110850: Cleanup pycore_time.h includes (#115724) 2024-02-20 16:50:43 +00:00
pycore_parser.h gh-110805: Allow the repl to show source code and complete tracebacks (#110775) 2023-10-13 09:25:37 +00:00
pycore_pathconfig.h gh-107211: No longer export internal functions (6) (#108424) 2023-08-24 17:28:35 +02:00
pycore_pyarena.h gh-107211: Fix test_peg_generator (#108435) 2023-08-24 17:47:44 +00:00
pycore_pyatomic_ft_wrappers.h gh-117657: Make PyType_HasFeature atomic (GH-120210) 2024-06-13 17:29:19 +08:00
pycore_pybuffer.h gh-76785: Rename _xxsubinterpreters to _interpreters (gh-117791) 2024-04-24 16:18:24 +00:00
pycore_pyerrors.h gh-119521: Use PyAPI_DATA, not extern, for _PyExc_IncompleteInputError (GH-120955) 2024-06-24 17:30:29 +02:00
pycore_pyhash.h gh-111545: Add Py_HashPointer() function (#112096) 2023-12-06 15:09:22 +01:00
pycore_pylifecycle.h Remove more remnants of deepfreeze (#118159) 2024-04-22 12:17:57 -07:00
pycore_pymath.h Remove unused internal macros (#102415) 2023-03-04 12:20:14 +00:00
pycore_pymem_init.h gh-115103: Implement delayed free mechanism for free-threaded builds (#115367) 2024-02-20 13:04:37 -05:00
pycore_pymem.h gh-112075: Support freeing object memory via QSBR (#116344) 2024-03-08 09:56:36 -08:00
pycore_pystate.h gh-120838: Add _PyThreadState_WHENCE_FINI (gh-121010) 2024-06-25 14:35:12 -06:00
pycore_pystats.h gh-108753: Enhance pystats (#108754) 2023-09-06 15:54:59 +00:00
pycore_pythonrun.h gh-106320: Remove private pythonrun API (#108599) 2023-08-29 04:18:52 +02:00
pycore_pythread.h Fix typos in comments (#120188) 2024-06-07 10:19:41 +02:00
pycore_qsbr.h gh-117657: Fix QSBR race condition (#118843) 2024-05-10 10:26:35 -04:00
pycore_range.h gh-89189: More compact range iterator (GH-27986) 2022-11-30 23:04:30 +02:00
pycore_runtime_init_generated.h GH-107803: double linked list implementation for asyncio tasks (GH-107804) 2024-06-22 10:58:35 -07:00
pycore_runtime_init.h gh-93502: Add new C-API functions to trace object creation and destruction (#115945) 2024-05-02 19:30:00 +02:00
pycore_runtime.h gh-93502: Add new C-API functions to trace object creation and destruction (#115945) 2024-05-02 19:30:00 +02:00
pycore_semaphore.h gh-110850: Cleanup pycore_time.h includes (#115724) 2024-02-20 16:50:43 +00:00
pycore_setobject.h gh-118527: Intern code consts in free-threaded build (#118667) 2024-05-06 20:12:39 -04:00
pycore_signal.h gh-109693: Use pyatomic.h for signal module (gh-110480) 2023-10-10 08:26:29 +09:00
pycore_sliceobject.h GH-115802: JIT "small" code for Windows (GH-115964) 2024-02-29 08:11:28 -08:00
pycore_stackref.h gh-117139: Convert the evaluation stack to stack refs (#118450) 2024-06-27 03:10:43 +08:00
pycore_strhex.h gh-107211: No longer export pycore_strhex.h functions (#108229) 2023-08-21 18:12:22 +00:00
pycore_structseq.h gh-107211: No longer export internal functions (4) (#107217) 2023-07-25 03:16:28 +00:00
pycore_symtable.h gh-119933: Improve `SyntaxError` message for invalid type parameters expressions (#119976) 2024-06-17 06:51:03 -07:00
pycore_sysmodule.h gh-106320: Remove private _PySys functions (#108452) 2023-08-24 20:02:09 +00:00
pycore_time.h gh-110850: Remove _PyTime_TimeUnchecked() function (#118552) 2024-05-05 12:15:19 +02:00
pycore_token.h gh-107211: No longer export internal functions (7) (#108425) 2023-08-24 17:40:56 +02:00
pycore_traceback.h gh-110721: Use the traceback module for PyErr_Display() and fallback to the C implementation (#110702) 2023-10-12 14:52:14 +00:00
pycore_tracemalloc.h gh-107211: No longer export internal functions (3) (#107215) 2023-07-25 02:25:45 +00:00
pycore_tstate.h gh-120838: Add _PyThreadState_WHENCE_FINI (gh-121010) 2024-06-25 14:35:12 -06:00
pycore_tuple.h gh-116381: Remove bad specializations, add fail stats (GH-116464) 2024-03-08 00:21:21 +08:00
pycore_typeobject.h gh-120161: Fix a Crash in the _datetime Module (gh-120182) 2024-06-14 13:29:09 -06:00
pycore_typevarobject.h gh-118895: Call PyType_Ready() on typing.NoDefault (#118897) 2024-05-10 08:42:00 -07:00
pycore_ucnhash.h gh-111972: Make Unicode name C APIcapsule initialization thread-safe (#112249) 2023-11-30 11:12:49 +01:00
pycore_unicodeobject_generated.h GH-107803: double linked list implementation for asyncio tasks (GH-107804) 2024-06-22 10:58:35 -07:00
pycore_unicodeobject.h gh-113993: Allow interned strings to be mortal, and fix related issues (GH-120520) 2024-06-21 17:19:31 +02:00
pycore_unionobject.h gh-105858: Expose some union-related objects as internal APIs (GH-116025) 2024-02-28 09:56:40 +00:00
pycore_uop_ids.h GH-120507: Lower the BEFORE_WITH and BEFORE_ASYNC_WITH instructions. (#120640) 2024-06-18 12:17:46 +01:00
pycore_uop_metadata.h GH-120507: Lower the BEFORE_WITH and BEFORE_ASYNC_WITH instructions. (#120640) 2024-06-18 12:17:46 +01:00
pycore_warnings.h gh-117511: Make PyMutex public in the non-limited API (#117731) 2024-06-20 11:29:08 -04:00
pycore_weakref.h gh-118789: Add PyUnstable_Object_ClearWeakRefsNoCallbacks (#118807) 2024-06-18 09:57:23 -04:00