Repository navigation
0.5.0
Changes
Ordinary Python goes native without a rewrite. Plain lists, dicts, and sets compile, and so do exceptions, generators, closures, lambdas, and functions passed as values. A warm ppy run is within noise of python or faster on every example, and a first run takes about half as long as in 0.4. ppy explain --summary shows what stays in Python and why. A differential fuzzer now checks every path against CPython, and the bugs it and a corpus of public programs found are fixed.
Lists, dicts, and sets
- Plain
list,dict, andsetlower to native code underppy run, in standalone builds, and in emitted C and C++, with no rewrite toppy.Vecorppy.HashMap. This covers:- displays and comprehensions;
- their methods, slicing, and negative indices;
in,del,sorted,min,max,sum, and set algebra.
- Results and error messages are CPython's, and
except KeyErrorand the like around them run natively. - A function that takes or returns a container can be called from Python natively. Arguments are copied in, and writes come back to the caller's object.
- On a benchmark of plain-container code (longest increasing subsequence, a dict histogram, a set of tuples, a list sieve), CPython takes 1042 ms,
ppy run587 ms, and a standalone binary 554 ms.
Exceptions and generators
raise,try/except/else/finally, andassertcompile to native code, and exceptions cross native calls.- Generator functions and generator expressions compile when a
for,next,sum,min,max,sorted,any,all, or a comprehension consumes them. - New example
50_errors_and_generators: python 2.1 s,ppy run0.43 s, standalone 0.29 s.
ppy run is never slower
- A warm
ppy runstarts in about 15 to 20 ms overpython, down from about 40 ms.- It checks only the program's own sources and runs before the command line is parsed.
- A program with no native entry point runs from a precompiled plan.
- The runtime decides to call native code from Python only when the work grows with what crosses the boundary.
- String work is faster: the strings example runs in about 1 s warm, against 2.4 s for
python. scripts/run_overhead.pymeasures every example, and the performance page shows the result.
Functions as values
- Nested functions,
lambda, andnonlocalcompile. They use CPython's late binding, so a closure sees the variable as it is when the closure runs. Callablevalues work as parameters, results, container elements, and fields.sorted/min/max/sorttake anykey=.mapandfiltercompile where they are consumed.
More of Python native
- Exception classes with fields, and
raise ... from. - Generators stepped with
nextandfor. - Sets of ints walked in CPython's order.
floatandbooldict keys.- Dataclass
==andrepr,str()/repr()of objects. str.formatand%formatting.
First runs and coverage
- A first
ppy runtakes a median of 0.38 s, down from 0.67 s. The C runtimes are compiled once per machine with optimization, which also makes warm runs of collection- and string-heavy programs faster. ppy explain --summary [PATH ...]reports how many functions and statements go native and ranks what keeps the rest in Python, with a hint and a guide link for each reason.- On TheAlgorithms/Python, 14% of functions compile today. The top blockers are calls with unknown effects, I/O, and writes to parameters.
- Running 400 of its scripts under CPython and
ppy runfound several wrong answers, now fixed. Two examples:row = []hoisted out of a loop, anda, b = [0]*n, [0]*nsharing one list.
Differential fuzzing and fixes
scripts/fuzz.pygenerates programs over the native subset and runs each on CPython, the Python backend,ppy run, a standalone binary, and C and C++ under AddressSanitizer. It reports any difference, andtests/test_fuzz.pyreplays every case it has found.- It found, and this release fixes:
- NaN comparisons and truth.
a if c else bevaluating both sides.and/orover numbers returning a bool.- A
rangeloop that rebinds its variable looping forever. - Several undefined behaviors in emitted C.
- A stale list length after
del,pop, orappend. min/maxreading memory before writing it.- An interned empty literal shadowing
"-inf". - Alias analysis taking gigabytes on nested loops.
- A warm
ppy runreusing an old build after a same-size edit made within one timestamp tick.
Known limitation: a native function with a float parameter given an int returns a float where CPython keeps the int (f(0) gives 0.0). A fix is planned for 0.6.0.
Install or upgrade with pip install --upgrade ppy-lang==0.5.0.
The full repository gate passed: 2,151 tests, 45/45 examples on all three paths, pylint on every example, and the documentation examples. The emitted C and C++ of the new tests runs clean under AddressSanitizer with leak detection.