Guide¶
This guide covers the PPy language, one topic per page.
A .ppy file is valid Python 3.12+. What PPy adds is carried by annotations
and decorators from the ppy package, and all of them are inert at runtime.
Under plain CPython the decorators return the function unchanged, and the
markers are ordinary typing.Annotated aliases. The compiler adds
enforcement and speed. It does not change behavior.
Each namespace has a Python reference implementation and a lowering that agrees with it, so a program that uses any of them runs the same on every path.
Pages¶
| page | what it covers |
|---|---|
| The subset | What the compiler accepts, what --no-strict downgrades and infers, the compatibility policy, and the three absences of a type: unknown, Any, and Dynamic. |
| Directives and markers | @ppy.pure, @ppy.native, @ppy.jit, @ppy.dynamic and the rest; fixed-width integers, Buffer[T], Range, ownership. |
| Classes | Value classes and object classes in native code: trees, linked nodes, class Stack[T], fields typed from what the program stores into them, objects edited in place, and objects that stay resident in native memory between calls from Python. |
| Exceptions and generators | raise, try, assert, and generators in native code, and what stays in Python. |
| Functions as values | Nested functions (with entries of their own when they only read the variables they share), lambda, nonlocal, Callable values, keys, map and filter in native code. |
| Strings | str in native code: methods, f-strings and format specs, parsing numbers, strings as keys. |
| Lists, dicts, and sets | Python's own containers in native code, with no rewrite: displays, comprehensions, methods, and the Python boundary. |
| The standard library | random and random.Random, math, heapq, bisect, itertools, deque, Counter, defaultdict, OrderedDict, functools, operator, and string in native code, draw for draw with CPython. |
| Collections | Vec, Deque, Heap, LinkedList, HashMap, HashSet, TreeMap, TreeSet: containers that compile, with no pointers. |
| Native memory and FFI | ppy.native pointers, stack allocation, extern and export, and ppy.ffi over them. |
| Lanes and the machine | ppy.simd vectors and ppy.cpu features, hints, and targets. |
| Atomics and threads | ppy.atomic with C11 orders; ppy.concurrent spawn, join, mutex, condition, barrier. |
| Parallel loops | parallel.range, reductions, and what the body may do. |
| Derivatives | ppy.grad and ppy.value_and_grad, one rule table on every path. |
| Coroutines | ppy.aio: sockets and sleeps under asyncio or the native epoll loop. |
| GPU kernels | ppy.cuda and ppy.hip: kernels in Python, PTX under ppy run. |
| Common tensors | Tensor[dtype, shape], bfloat16, mutable borrows, and backend storage. |
| XLA | @xla.jit: StableHLO from the compiler, run through PJRT. |
| Generics | Type parameters, bounds, monomorphization, static dispatch. |
| Effects and the three paths | The effect vocabulary, purity, and why three ways of running agree. |
| Effects in native code | print, input, text files, and calls into Python from native code, and why nothing prints twice. |
| Reading input | ppy.input reads lines, ppy.scan reads tokens, ppy.read_* fill a buffer. |
| Native lowering | When a function gets a boundary, what a call costs, what its parameters may be (numbers and strings that may be None included), and how to read ppy explain --summary. |
| Regular expressions | A pattern compiled from a bytes literal, matched natively over a byte buffer. |