]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
gh-117139: Convert the evaluation stack to stack refs (#118450)
authorKen Jin <kenjin@python.org>
Wed, 26 Jun 2024 19:10:43 +0000 (03:10 +0800)
committerGitHub <noreply@github.com>
Wed, 26 Jun 2024 19:10:43 +0000 (03:10 +0800)
commit22b0de2755ee2d0e2dd21cd8761f15421ed2da3d
tree364c4bcd1b193482a111531924af51d688acf32e
parentd611c4c8e9893c0816969e19ab6ca4992a3a15e3
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>
35 files changed:
Include/internal/pycore_ceval.h
Include/internal/pycore_code.h
Include/internal/pycore_frame.h
Include/internal/pycore_jit.h
Include/internal/pycore_object.h
Include/internal/pycore_object_deferred.h [new file with mode: 0644]
Include/internal/pycore_optimizer.h
Include/internal/pycore_stackref.h
Lib/test/test_generated_cases.py
Makefile.pre.in
Misc/NEWS.d/next/Core and Builtins/2024-05-01-05-09-16.gh-issue-117139.t41w_D.rst [new file with mode: 0644]
Objects/frameobject.c
Objects/genobject.c
Objects/typeobject.c
PCbuild/pythoncore.vcxproj
PCbuild/pythoncore.vcxproj.filters
Python/bytecodes.c
Python/ceval.c
Python/ceval_macros.h
Python/executor_cases.c.h
Python/frame.c
Python/generated_cases.c.h
Python/optimizer.c
Python/optimizer_cases.c.h
Python/specialize.c
Tools/cases_generator/analyzer.py
Tools/cases_generator/generators_common.py
Tools/cases_generator/optimizer_generator.py
Tools/cases_generator/parsing.py
Tools/cases_generator/stack.py
Tools/cases_generator/tier1_generator.py
Tools/cases_generator/tier2_generator.py
Tools/gdb/libpython.py
Tools/jit/template.c
Tools/jit/trampoline.c