Skip to content

Commit 668c572

Browse files
authored
GH-139922: add interpreter types to InternalDocs/interpreter.md (GH-148035)
1 parent 1c4408a commit 668c572

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

InternalDocs/interpreter.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,38 @@ After the last `DEOPT_IF` has passed, a hit should be recorded with
507507
After an optimization has been deferred in the adaptive instruction,
508508
that should be recorded with `STAT_INC(BASE_INSTRUCTION, deferred)`.
509509

510+
## Interpreter types
511+
There are three different types of interpreters to choose from based on compiler support:
512+
513+
* traditional switch-case interpreter
514+
515+
Supported by all compilers covered in PEP 7.
516+
517+
* computed-gotos interpreter
518+
519+
Enabled using configure option `--with-computed-gotos` and used by default on supported compilers.
520+
It uses [Labels as Values](https://gcc.gnu.org/onlinedocs/gcc/Labels-as-Values.html)
521+
for more efficient dispatching.
522+
523+
* tail-calling interpreter
524+
525+
Enabled using configure option `--with-tail-call-interp` (or `--tail-call-interp` for build.bat on Windows).
526+
It uses [tail calls](https://clang.llvm.org/docs/AttributeReference.html#musttail) and the
527+
[preserve_none](https://clang.llvm.org/docs/AttributeReference.html#preserve-none)
528+
calling convention between the small C functions that implement individual Python opcodes.
529+
530+
Not all compilers support these and if they do not all targets might be supported (for example,
531+
MSVC currently only supports x64 and only in optimized builds).
532+
533+
In addition, compilers must do [escape analysis](https://gcc.gnu.org/onlinedocs/gcc/Common-Attributes.html#index-musttail)
534+
of the lifetimes of automatic variables, function parameters, and temporaries to ensure proper tail-calls. They
535+
emit a compile error in case of a violation or detection failure. The ability to detect this varies depending on the compiler and
536+
also on the optimization level. Following techniques are particularly helpful to the MSVC compiler in this regard
537+
* [Introducing additional scopes](https://github.com/python/cpython/blob/3908593039bde9d4b591ab09919003ee57418d64/Python/bytecodes.c#L2526)
538+
* [extracting problematic code paths into a separate function](https://github.com/python/cpython/pull/143068/files#diff-729a985b0cb8b431cb291f1edb561bbbfea22e3f8c262451cd83328a0936a342R3724)
539+
* [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)
540+
541+
Using `restrict` is another (currently unused) remedy.
510542

511543
Additional resources
512544
--------------------

0 commit comments

Comments
 (0)