oxilean-codegen 0.1.0

OxiLean code generator - LCNF-based compilation and optimization
Documentation
  • Coverage
  • 38.98%
    13238 out of 33961 items documented6 out of 18163 items with examples
  • Size
  • Source code size: 8.45 MB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.19 GB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 5m 23s Average build duration of successful builds.
  • all releases: 5m 23s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • Repository
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • cool-japan

oxilean-codegen

Crates.io Docs.rs

Code Generation Backend for the OxiLean Theorem Prover

oxilean-codegen compiles type-checked OxiLean kernel expressions into executable code for multiple target platforms. The pipeline first lowers expressions to a Lambda-Case Normal Form (LCNF) intermediate representation, applies a series of optimisation passes, and then emits target-specific code.

The crate is untrusted with respect to logical soundness -- any bug here can only affect the performance or correctness of extracted programs, not the validity of proofs, because all terms are independently verified by oxilean-kernel before reaching this stage.

240,840 SLOC -- comprehensive code generation with multiple backends and optimisation passes.

Part of the OxiLean project -- a Lean-compatible theorem prover implemented in pure Rust.

Overview

Compilation Pipeline

Kernel Expr (type-checked)
       |
       v
+-------------+
|  to_lcnf    |  -> LCNF (Lambda-Case Normal Form) IR
+------+------+
       v
+---------------------------------+
|  Optimisation Passes            |
|  opt_passes / opt_dce / opt_join|  -> DCE, join-point analysis, inlining
|  opt_reuse / opt_specialize     |  -> RC reuse, specialisation, PGO
+------+--------------------------+
       v
+---------------------------------+
|  closure_convert                |  -> Flat closure representation
+------+--------------------------+
       v
+------------------------------------------------------+
|  Backend selection                                    |
|  +- native_backend   -> native Rust output            |
|  +- c_backend        -> portable C code               |
|  +- llvm_backend     -> LLVM IR (for LTO, advanced opt)|
|  +- wasm_backend     -> WebAssembly (WAT/wasm-opt)    |
|  +- js_backend       -> JavaScript / TypeScript       |
|  +- glsl_backend     -> GLSL shader output            |
|  +- wgsl_backend     -> WebGPU WGSL shaders           |
|  +- zig_backend      -> Zig (for FFI bridging)        |
|  +- ffi_bridge       -> C FFI header generation       |
+------------------------------------------------------+

Module Reference

Module Description
lcnf LCNF intermediate representation types
to_lcnf Kernel Expr -> LCNF lowering
opt_passes Orchestration of all optimisation passes
opt_dce Dead code elimination
opt_join Join-point / CPS transformation
opt_reuse Reference-count reuse optimisation
opt_specialize Monomorphisation and function specialisation
closure_convert Closure conversion to flat representation
pipeline End-to-end compilation pipeline driver
runtime_codegen Runtime support code generation
pgo Profile-guided optimisation data collection
native_backend Native Rust code emission
c_backend C code emission
llvm_backend LLVM IR emission
wasm_backend WebAssembly code emission
js_backend JavaScript code emission
glsl_backend GLSL shader emission
wgsl_backend WebGPU WGSL emission
zig_backend Zig code emission
ffi_bridge C FFI header generation

Configuration

use oxilean_codegen::{CodegenConfig, CodegenTarget};

let config = CodegenConfig {
    target: CodegenTarget::Rust,
    optimize: true,
    debug_info: false,
    emit_comments: true,
    inline_threshold: 50,
};

Supported Targets

Variant Description
CodegenTarget::Rust Native Rust source (default)
CodegenTarget::C Portable C99 source
CodegenTarget::LlvmIr LLVM intermediate representation
CodegenTarget::Interpreter Direct interpretation mode

Usage

Add to your Cargo.toml:

[dependencies]
oxilean-codegen = "0.1.0"

Dependencies

  • oxilean-kernel -- kernel expression types (Expr, Literal)

Testing

cargo test -p oxilean-codegen
cargo test -p oxilean-codegen -- --nocapture

License

Copyright COOLJAPAN OU (Team Kitasan). Apache-2.0 -- See LICENSE for details.