From e8e342ab37e1b020d0dd6f852251474c6d359f04 Mon Sep 17 00:00:00 2001 From: Chris Eibl <138194463+chris-eibl@users.noreply.github.com> Date: Fri, 3 Apr 2026 14:51:51 +0200 Subject: [PATCH 1/4] add interpreter types to InternalDocs and explain some musttail peculiarities --- InternalDocs/interpreter.md | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/InternalDocs/interpreter.md b/InternalDocs/interpreter.md index 75acdf596a7f30..1a366c2faedde4 100644 --- a/InternalDocs/interpreter.md +++ b/InternalDocs/interpreter.md @@ -507,7 +507,36 @@ After the last `DEOPT_IF` has passed, a hit should be recorded with After an optimization has been deferred in the adaptive instruction, that should be recorded with `STAT_INC(BASE_INSTRUCTION, deferred)`. - +## Interpreter types +There are three different types of interpreters to choose from based on compiler support: + + * traditional switch-case interpreter + + Supported by all compilers covered in PEP 7. + + * computed-gotos interpreter + + Enabled using configure option `--with-computed-gotos` and used by default on supported compilers. + It uses [Labels as Values](https://gcc.gnu.org/onlinedocs/gcc/Labels-as-Values.html) + for more efficient dispatching. + + * tail-calling interpreter + + Enabled using configure option `--with-tail-call-interp` (or `--tail-call-interp` for build.bat on Windows). + It uses [tail calls](https://clang.llvm.org/docs/AttributeReference.html#musttail) and the + [preserve_none](https://clang.llvm.org/docs/AttributeReference.html#preserve-none) + calling convention between the small C functions that implement individual Python opcodes. + + Not all compilers support these and if they do not all targets might be supported (for example, + MSVC currently only supports x64 and only in optimized builds). + + In addition, compilers must do [escape analysis](https://gcc.gnu.org/onlinedocs/gcc/Common-Attributes.html#index-musttail) + of the lifetimes of automatic variables, function parameters, and temporaries to ensure proper tail-calls. They + emit a compile error in case of a violation or detection failure. The ability to detect this varies depending on the compiler and + also on the optimization level. [Introducing additional scopes](https://github.com/python/cpython/blob/3908593039bde9d4b591ab09919003ee57418d64/Python/bytecodes.c#L2526) + or [returning a pointer instead of taking it as an output parameter](https://github.com/python/cpython/blob/3908593039bde9d4b591ab09919003ee57418d64/Include/internal/pycore_ceval.h#L489-L492) + is particularly helpful to the MSVC compiler in this regard. + Additional resources -------------------- From d26992fadd89b2c9cda3efb7683a9ab743c26bda Mon Sep 17 00:00:00 2001 From: Chris Eibl <138194463+chris-eibl@users.noreply.github.com> Date: Fri, 3 Apr 2026 15:31:02 +0200 Subject: [PATCH 2/4] Additionally mention extract method and restrict --- InternalDocs/interpreter.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/InternalDocs/interpreter.md b/InternalDocs/interpreter.md index 1a366c2faedde4..9eca64681fb4c6 100644 --- a/InternalDocs/interpreter.md +++ b/InternalDocs/interpreter.md @@ -533,10 +533,12 @@ There are three different types of interpreters to choose from based on compiler In addition, compilers must do [escape analysis](https://gcc.gnu.org/onlinedocs/gcc/Common-Attributes.html#index-musttail) of the lifetimes of automatic variables, function parameters, and temporaries to ensure proper tail-calls. They emit a compile error in case of a violation or detection failure. The ability to detect this varies depending on the compiler and - also on the optimization level. [Introducing additional scopes](https://github.com/python/cpython/blob/3908593039bde9d4b591ab09919003ee57418d64/Python/bytecodes.c#L2526) + also on the optimization level. [Introducing additional scopes](https://github.com/python/cpython/blob/3908593039bde9d4b591ab09919003ee57418d64/Python/bytecodes.c#L2526), + [extracting problematic code paths into a separate function] + (https://github.com/python/cpython/pull/143068/files#diff-729a985b0cb8b431cb291f1edb561bbbfea22e3f8c262451cd83328a0936a342R3724) or [returning a pointer instead of taking it as an output parameter](https://github.com/python/cpython/blob/3908593039bde9d4b591ab09919003ee57418d64/Include/internal/pycore_ceval.h#L489-L492) - is particularly helpful to the MSVC compiler in this regard. - + is particularly helpful to the MSVC compiler in this regard. Using `restrict` is another (currently unused) remedy. + Additional resources -------------------- From 649f2958b06d6c47bd872ab1fbe37e5fc911f3dd Mon Sep 17 00:00:00 2001 From: Chris Eibl <138194463+chris-eibl@users.noreply.github.com> Date: Fri, 3 Apr 2026 15:35:38 +0200 Subject: [PATCH 3/4] fix link --- InternalDocs/interpreter.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/InternalDocs/interpreter.md b/InternalDocs/interpreter.md index 9eca64681fb4c6..0d3a1ede7e7255 100644 --- a/InternalDocs/interpreter.md +++ b/InternalDocs/interpreter.md @@ -534,8 +534,7 @@ There are three different types of interpreters to choose from based on compiler of the lifetimes of automatic variables, function parameters, and temporaries to ensure proper tail-calls. They emit a compile error in case of a violation or detection failure. The ability to detect this varies depending on the compiler and also on the optimization level. [Introducing additional scopes](https://github.com/python/cpython/blob/3908593039bde9d4b591ab09919003ee57418d64/Python/bytecodes.c#L2526), - [extracting problematic code paths into a separate function] - (https://github.com/python/cpython/pull/143068/files#diff-729a985b0cb8b431cb291f1edb561bbbfea22e3f8c262451cd83328a0936a342R3724) + [extracting problematic code paths into a separate function](https://github.com/python/cpython/pull/143068/files#diff-729a985b0cb8b431cb291f1edb561bbbfea22e3f8c262451cd83328a0936a342R3724) or [returning a pointer instead of taking it as an output parameter](https://github.com/python/cpython/blob/3908593039bde9d4b591ab09919003ee57418d64/Include/internal/pycore_ceval.h#L489-L492) is particularly helpful to the MSVC compiler in this regard. Using `restrict` is another (currently unused) remedy. From 1483b254c0e1f310845bbc2953e21f37b10a845e Mon Sep 17 00:00:00 2001 From: Chris Eibl <138194463+chris-eibl@users.noreply.github.com> Date: Fri, 3 Apr 2026 16:01:20 +0200 Subject: [PATCH 4/4] convert to bullets --- InternalDocs/interpreter.md | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/InternalDocs/interpreter.md b/InternalDocs/interpreter.md index 0d3a1ede7e7255..7fc41a807dd566 100644 --- a/InternalDocs/interpreter.md +++ b/InternalDocs/interpreter.md @@ -533,10 +533,12 @@ There are three different types of interpreters to choose from based on compiler In addition, compilers must do [escape analysis](https://gcc.gnu.org/onlinedocs/gcc/Common-Attributes.html#index-musttail) of the lifetimes of automatic variables, function parameters, and temporaries to ensure proper tail-calls. They emit a compile error in case of a violation or detection failure. The ability to detect this varies depending on the compiler and - also on the optimization level. [Introducing additional scopes](https://github.com/python/cpython/blob/3908593039bde9d4b591ab09919003ee57418d64/Python/bytecodes.c#L2526), - [extracting problematic code paths into a separate function](https://github.com/python/cpython/pull/143068/files#diff-729a985b0cb8b431cb291f1edb561bbbfea22e3f8c262451cd83328a0936a342R3724) - or [returning a pointer instead of taking it as an output parameter](https://github.com/python/cpython/blob/3908593039bde9d4b591ab09919003ee57418d64/Include/internal/pycore_ceval.h#L489-L492) - is particularly helpful to the MSVC compiler in this regard. Using `restrict` is another (currently unused) remedy. + also on the optimization level. Following techniques are particularly helpful to the MSVC compiler in this regard + * [Introducing additional scopes](https://github.com/python/cpython/blob/3908593039bde9d4b591ab09919003ee57418d64/Python/bytecodes.c#L2526) + * [extracting problematic code paths into a separate function](https://github.com/python/cpython/pull/143068/files#diff-729a985b0cb8b431cb291f1edb561bbbfea22e3f8c262451cd83328a0936a342R3724) + * [returning a pointer instead of taking it as an output parameter](https://github.com/python/cpython/blob/3908593039bde9d4b591ab09919003ee57418d64/Include/internal/pycore_ceval.h#L489-L492) + + Using `restrict` is another (currently unused) remedy. Additional resources --------------------