Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork3k
Mypyc Implementation Overview
Mypyc compiles a Python module (or a set of modules) to C, andcompiles the generated C to a Python C extension module (ormodules). You can compile only a subset of your program to C --compiled and interpreted code can freely and transparentlyinteract. You can also freely use any Python libraries (including Cextensions) in compiled code.
Mypyc will only make compiled code faster. To see a significantspeedup, you must make sure that most of the time is spent in compiledcode -- and not in libraries, for example.
Mypyc has these compilation passes:
Type check the code using mypy and infer types for variables andexpressions. This produces a mypy AST (defined in
mypy.nodes
) anda type map that describes the inferred types (mypy.types.Type
) ofall expressions (as PEP 484 types).Translate the mypy AST into a mypyc-specific intermediate representation (IR).
- The IR is defined in
mypyc.ir
(seehere for an explanation of the IR). - Various primitive operations used in the IR are defined in
mypyc.primitives
. - The translation to IR happens in
mypyc.irbuild
. The top-level logic is inmypyc.irbuild.main
.
- The IR is defined in
Insert checks for uses of potentially uninitialized variables(
mypyc.transform.uninit
).Insert exception handling (
mypyc.transform.exceptions
).Insert explicit reference count inc/dec opcodes (
mypyc.transform.refcount
).Infer always defined attributes that don't require checking for a missing value on read (
mypyc.analysis.attrdefined
).Translate the IR into C (
mypyc.codegen
).Compile the generated C code using a C compiler (
mypyc.build
).
Details of the mypyc implementation are described in these pages: