Phoenix: a statically verified, Python-like language that compiles to C
Project description
Phoenix
Phoenix is a statically verified, Python-like language that compiles to optimized C.
It enforces a zero-ambiguity execution model: if performance cannot be proven at compile time, the program is rejected.
Phoenix is not a faster Python runtime.
Phoenix eliminates Python entirely.
Quickstart
python3 -m phoenix.cli examples/good_big.py # emits output.c and ./output
./output # run the native binary
# optional CLI:
# python3 -m phoenix.cli check examples/foo.py # analysis only
# python3 -m phoenix.cli build examples/foo.py # force transpile + compile
# python3 -m phoenix.cli examples/foo.py # default: analyze then build/run
Phoenix caches binaries in .phoenix_cache/ keyed by source hash, so repeat builds are instant.
Install As CLI (pip)
# from this repository root
python3 -m pip install .
# then use the CLI directly
phoenix examples/good_big.py
phoenix check examples/good_big.py
phoenix build examples/good_big.py
For editable local development:
python3 -m pip install -e .
Why Phoenix
Python is easy to write but slow to execute due to:
- dynamic typing
- runtime dispatch
- interpreter overhead
Phoenix takes a different approach:
Restrict the language so performance can be proven before execution.
If the code passes Phoenix’s rules, it is compiled to native machine code via C and gcc -O3.
Language Guarantees
Phoenix enforces the following at compile time:
- Variables may not change type
- Lists must contain a single element type
- No
eval,exec, reflection, or dynamic imports forusesrange(<int literal/const>)or lists with known length (non-zero step);whilerequires a counter compared to an int literal and a monotonic literal step- Function returns are type-stable
- Logical ops (
and,or,not) and comparisons (incl. chained) need bool/numeric operands and yield bool - List indexing is bounds-checked (static when possible, runtime otherwise)
If any rule is violated, compilation fails with a precise error message.
Example
Valid Phoenix code
values = [1, 4, 9, 16]
total = 0
for i in range(4):
total = total + values[i]
Generated C
int values[4] = {1, 4, 9, 16};
int total = 0;
for (int i = 0; i < 4; i++) {
total = total + values[i];
}
printf("%d\n", total);
Benchmarks
Summing integers in nested loops.
Python (CPython 3.x)
Time: ~0.52 seconds
Phoenix → C (gcc -O3)
Time: ~0.01 seconds
Phoenix achieves 50–100× speedups on numeric workloads by eliminating dynamic overhead entirely.
Language Rules (v0)
- Variables may not change type.
- Lists must contain one static element type.
- No
eval,exec, reflection, or dynamic imports. formust berange(<int literal/const>)or a list with known length;whilemust use a counter compared to an int literal with a monotonic literal step.- Function return type must be consistent.
- Logical ops (
and,or,not) and comparisons (incl. chained) need bool/numeric operands and return bool. ifconditions must be boolean; assignments must exist in all branches (elif/nestedifallowed).
If any rule is violated, compilation fails with a precise error message.
Supported Constructs (today)
- Types:
int,float,bool,string, fixed-length homogeneous list literals. - Control flow:
foroverrange(<int literal/const>)or known-length lists, boundedwhile,if/elif/elsewith nesting, logicaland/or/not, comparisons (incl. chained), string concatenation via+(string + string/int/float), set membership viain. - Functions: positional parameters with inferred types; returns must be type-stable.
- Builtins:
print,int(...),abs,min,max,pow,len,sum,str,round,math.sqrt,math.sin,math.cos,math.tan,math.floor,math.ceil,math.log,math.exp,math.log10,math.asin,math.acos,math.atan,math.fabs,math.pow(min/max also accept numeric lists; strings support.upper(),.lower(),.strip(),.startswith(),.endswith(),.find(),.replace()). - Lists: fixed-length literals and dynamic lists (via
append/pop); slicing on dynamic lists withlist[a:b](no step). - Dict/Set: dict and set literals with read/write access; dict keys must be
int/string, set elements must beint/string(dict[key] = ...,del dict[key],set.add(...),set.remove(...)). - Modules: local files via
import module(same directory), accessed asmodule.name;import mathallowed for math stdlib. - Codegen: C arrays for list literals;
printffor output;gcc -O3compilation.
Feature Matrix
| Feature | Static-Proofed | Runtime-Checked |
|---|---|---|
| Type stability | ✅ | — |
| Homogeneous containers | ✅ | — |
| For-loop bounds | ✅ (range/known-length lists) | — |
| While termination | ✅ (strict counter pattern) | — |
| List indexing | ✅ (literal index + known length) | ✅ (dynamic index or dynamic list) |
| Dynamic lists (append/pop/slice) | — | ✅ |
| Dict/Set lookup | — | ✅ (missing key) |
| Dict/Set mutation | — | ✅ (bounds/lookup) |
Set membership (in/not in) |
✅ (type match) | ✅ (lookup) |
Static = guaranteed at compile time. Runtime = guarded with checks in generated C.
Architecture Overview
Phoenix pipeline:
- Parse Python source into AST
- Statistically verify zero-ambiguity rules
- Generate deterministic C code
- Compile with
gcc -O3 - Execute native binary
Status
Phoenix is a minimal prototype focused on safety over breadth:
- Missing:
from-imports/aliasing, classes/objects, dictionaries/sets iteration, and broader stdlib coverage. - Codegen is deliberately simple: flat arrays, heap-backed dynamic collections, minimal header selection.
Future work: expand the safe subset (loop analyses, richer math/stdlib), improve diagnostics and error recovery, add stronger static checks (array bounds proofs), support module aliasing/from-imports, and explore a safer memory model for dynamic data while keeping zero-ambiguity guarantees.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file phoenix_lang_cli-0.1.0.tar.gz.
File metadata
- Download URL: phoenix_lang_cli-0.1.0.tar.gz
- Upload date:
- Size: 29.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
15ed3a45625cb1ac6d345237732063a6773cdf0c213165b860c67340d0db2a74
|
|
| MD5 |
e15503fba81b3167f38b3ce441099a8a
|
|
| BLAKE2b-256 |
a0326aa5287dbc9ad7c23bc3ddba64ea9ef08fb3ddc8939ad2018ab82301a2c1
|
File details
Details for the file phoenix_lang_cli-0.1.0-py3-none-any.whl.
File metadata
- Download URL: phoenix_lang_cli-0.1.0-py3-none-any.whl
- Upload date:
- Size: 29.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
286fe76e3e496905fb1ea3068df2ad994c44d9431bb2aa462016885bd391c403
|
|
| MD5 |
318add667f1dcce7b79194223503b573
|
|
| BLAKE2b-256 |
d2405b52b908c20106368a58994f0c96f4cfd332a99b5097426028bdbaf7ef95
|