Skip to content

Commit e8e342a

Browse files
committed
add interpreter types to InternalDocs
and explain some musttail peculiarities
1 parent 3908593 commit e8e342a

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

InternalDocs/interpreter.md

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,36 @@ 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-
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. [Introducing additional scopes](https://github.com/python/cpython/blob/3908593039bde9d4b591ab09919003ee57418d64/Python/bytecodes.c#L2526)
537+
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)
538+
is particularly helpful to the MSVC compiler in this regard.
539+
511540
Additional resources
512541
--------------------
513542

0 commit comments

Comments
 (0)