Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Mypyc Implementation Overview

Jukka Lehtosalo edited this pageOct 24, 2022 ·6 revisions

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.

Overview of Passes

Mypyc has these compilation passes:

  • Type check the code using mypy and infer types for variables andexpressions. This produces a mypy AST (defined inmypy.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 inmypyc.ir (seehere for an explanation of the IR).
    • Various primitive operations used in the IR are defined inmypyc.primitives.
    • The translation to IR happens inmypyc.irbuild. The top-level logic is inmypyc.irbuild.main.
  • 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).

Contents

Details of the mypyc implementation are described in these pages:

Clone this wiki locally

[8]ページ先頭

©2009-2025 Movatter.jp