DSLCompile: Mathematical Expression Compilation
DSLCompile provides a three-layer optimization strategy for mathematical expressions:
- Final Tagless Approach: Type-safe expression building with multiple interpreters
- Symbolic Optimization: Algebraic simplification using egglog
- Compilation Backends: Rust hot-loading (primary) and optional Cranelift JIT
Typed Variable System
The library includes a type-safe variable system that provides compile-time type checking with operator overloading syntax and full backward compatibility.
Quick Start with Typed Variables
use *;
// Create a typed math builder
let math = new;
// Create typed variables
let x: = math.typed_var;
let y: = math.typed_var;
// Build expressions with syntax and type safety
let x_expr = math.expr_from;
let y_expr = math.expr_from;
let expr = &x_expr * &x_expr + y_expr; // f32 auto-promotes to f64
// Backward compatible API still works
let old_style = math.var; // Defaults to f64
Architecture
┌─────────────────────────────────────────────────────────────┐
│ Final Tagless Layer │
│ (Expression Building & Type Safety) │
└─────────────────────┬───────────────────────────────────────┘
│
┌─────────────────────▼───────────────────────────────────────┐
│ Symbolic Optimization │
│ (Algebraic Simplification & Rewrite Rules) │
└─────────────────────┬───────────────────────────────────────┘
│
┌─────────────────────▼───────────────────────────────────────┐
│ Compilation Backends │
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────────────┐ │
│ │ Rust │ │ Cranelift │ │ Future Backends │ │
│ │ Hot-Loading │ │ JIT │ │ (LLVM, etc.) │ │
│ │ (Primary) │ │ (Optional) │ │ │ │
│ └─────────────┘ └─────────────┘ └─────────────────────┘ │
└─────────────────────────────────────────────────────────────┘