postpile

Typed Python, compiled to native code, held to what CPython prints.

Open source, under Apache 2.0. It builds on postpyc, the POST Python reference compiler.

A terminal: ppc builds collatz.py into an executable; CPython runs the script in 7.4 seconds, the executable prints the same five lines in 0.9 seconds

Fast Python usually means leaving Python.

The hot loop moves to C, to a dialect, or to a JIT for numeric kernels. Then two versions must agree. Some also give a slightly different answer.

Every build is held to CPython's output.

CPython is the reference. Tests run each program under both and compare.

  • Three native backends, C, QBE and LLVM, from one typed IR
  • Output compared byte for byte with CPython's
  • Expected values come from CPython, never written by hand
A terminal: collatz.py built with the C, QBE and LLVM backends; the three executables print output with the same SHA-1 checksum as CPython's

What it cannot compile exactly, it refuses.

No silent approximation. Each diagnostic names the line and the reason, and often the fix.

  • A code for each kind of diagnostic
  • ppc check reports them all before any build
  • Rejecting well-typed code counts as a gap to close
A terminal: a ten-line script, then ppc check listing three diagnostics: a list mixing ints, floats and a string (PP900, with the declaration to write instead), a call with too many arguments (PP100), and a misspelt function name (PP502)

Close to C, far ahead of CPython.

On thirteen low-level programs, the C backend's code takes 1.15 times C's time, as a geometric mean.

  • No program more than twice C's time
  • CPython takes 65 times C's time on the same set
  • Every timed run prints CPython's output
A terminal: the n-body benchmark as hand-written C runs in 0.222 seconds, compiled by postpile in 0.216 seconds, and under CPython in 4.8 seconds, all three printing the same two energies

One compiler, many ways in.

Executables and extensions

Whole scripts become executables, modules become Python extensions or NumPy ufuncs.

Python in both directions

Compiled code calls Python libraries, and Python imports compiled code.

Concurrency

Channels, task groups and select, on a C runtime.

Measured on real programs

All 28 typed Shed Skin examples compile, and 58 of 104 harvested scripts.

In development, no release yet. Source: git.sr.ht/~sfermigier/postpile
Documentation: postpile.lab.abilian.com