A production-grade compiler that transforms slow Python code into blazingly fast native executables. Achieve 10β1000Γ speedups automatically with zero annotations.
Python β AST β Type Inference β IR β Optimization β Rust β Native BinaryGuide compilation with simple Python comments:
def hot_function():
"""
#adrenaline:hot # Aggressive optimization
#adrenaline:simd # Auto-vectorization
#adrenaline:parallel # Multi-threading with Rayon
#adrenaline:inline # Inline at call sites
#adrenaline:no-compile # Fall back to Python
#adrenaline:cache # Cache compiled output
"""
# Your code here
pass- Type Inference: Automatically infer int, float, array types
- Hot Path Detection: Profile and recompile hot functions at higher optimization levels
- SIMD Detection: Identify numeric loops suitable for vectorization
- Parallelization: Safe auto-threading of independent loops
- Fallback Execution: Unsupported Python features automatically fall back to CPython
- Loop unrolling
- Constant folding
- Dead code elimination
- Bounds check elimination (proven-safe accesses)
- Common subexpression elimination
- SIMD vectorization
- Parallel execution (Rayon)
- Function inlining for hot paths
- Memoization for pure functions
adrenaline build main.py # Compile Python to native
adrenaline run main.py arg1 arg2 # Execute compiled binary
adrenaline check main.py # Check for compilation issues
adrenaline cache clear # Clear compilation cache
adrenaline help directives # Show directive syntax
adrenaline help features # Show supported features- Rust 1.70+ with rustc
- Python 3.10+
- Cargo
Windows (PowerShell):
git clone https://github.com/yourusername/adrenaline.git
cd adrenaline
.\build.ps1Linux/macOS:
git clone https://github.com/yourusername/adrenaline.git
cd adrenaline
chmod +x build.sh
./build.shThe compiled binary will be placed in dist/adrenaline (or dist/adrenaline.exe on Windows).
# examples/basic.py
def sum_range(n):
total = 0
for i in range(n):
total += i
return total
if __name__ == "__main__":
print(sum_range(1000000))Compile and run:
adrenaline build examples/basic.py
adrenaline run examples/basic.py# examples/directives.py
def hot_compute(iterations):
"""
#adrenaline:hot
#adrenaline:simd
Intensive computation - marked for aggressive optimization
"""
result = 0
for i in range(iterations):
result += (i * i) % 97
return result
if __name__ == "__main__":
print(hot_compute(10000000))# examples/fallback.py
def use_dict():
"""
#adrenaline:no-compile
Dictionary operations aren't yet supported - fallback to Python
"""
data = {"key": "value"}
return data.get("key")
def regular_function(x):
# This will be compiled
return x * x + 2 * x + 1
if __name__ == "__main__":
print(use_dict())
print(regular_function(42))- Function definitions and calls
- Local and global variables
- Numeric types:
int,float - Lists and arrays
- For/while loops
- If/elif/else conditionals
- Binary and unary operators (
+,-,*,/,//,%,**,&,|,^,<<,>>) - Comparison operators (
==,!=,<,<=,>,>=) - Type inference
- Local imports
- Classes and OOP
- Generators and iterators
- Decorators (beyond directives)
- Global state management
- Dictionary/set operations
- String manipulation (partial)
- Advanced Python features (metaclasses, descriptors)
- Dynamic code generation
- Complex context managers
src/
βββ main.rs # CLI entry point
βββ cli.rs # Command-line interface (clap)
βββ parser.rs # Python source parsing
βββ ast_types.rs # AST type definitions
βββ type_inference.rs # Type inference engine
βββ ir.rs # Intermediate representation
βββ optimizer.rs # IR optimization passes
βββ codegen.rs # Rust code generation
βββ compiler.rs # Main compilation pipeline
βββ directives.rs # Compiler directive system
βββ profiler.rs # Runtime profiling
βββ runtime.rs # Runtime support
βββ cache.rs # SHA256-based compilation cache
βββ diagnostics.rs # Error reporting (miette)The compiler automatically applies different optimization strategies:
- Basic (default): Constant folding, dead code elimination
- Aggressive (hot functions): Loop unrolling, SIMD, bounds check elimination
- Extreme (deeply profiled): All of the above + function inlining, escape analysis
- Profile First: Mark hot functions with
#adrenaline:hot - Use Numeric Types: Prefer
int/floatover generic collections - Enable SIMD: Use
#adrenaline:simdfor vectorizable loops - Parallelize: Use
#adrenaline:parallelfor independent iterations - Cache Results: Enable
#adrenaline:cachefor expensive functions
Adrenaline caches compiled outputs based on source code SHA256 hash. Clear cache with:
adrenaline cache clearcargo build
./target/debug/adrenaline build examples/basic.pycargo testcargo clippy
cargo fmtMIT / Apache-2.0 (dual licensed)
Contributions welcome! Areas of focus:
- Python AST parsing improvements
- Additional optimization passes
- More language feature support
- Performance benchmarking