Skip to main content

Compiler

Trait Compiler 

Source
pub trait Compiler: Send + Sync {
    // Required methods
    fn compile(&self, spec: &ProgramSpec) -> Result<CompiledSpec>;
    fn cache_key(&self) -> &'static str;
}
Expand description

A compiler that transforms source code into a compiled specification.

This trait abstracts over different compilation backends:

  • LLVM: IR validation (JIT compiles at runtime)
  • CUDA: CUDA C -> PTX/CUBIN
  • Metal: Metal Shading Language -> metallib
  • WebGPU: WGSL -> SPIR-V

Required Methods§

Source

fn compile(&self, spec: &ProgramSpec) -> Result<CompiledSpec>

Compile a program specification into executable form.

§Arguments
  • spec - The program specification containing source code and metadata
§Returns

A CompiledSpec containing:

  • For JIT backends (LLVM): source code in src field, empty bytes
  • For AOT backends (CUDA/Metal): compiled bytes in bytes field, no src
§Examples

JIT backend (LLVM):

let compiled = compiler.compile(&spec)?;
assert!(compiled.src.is_some());
assert!(compiled.bytes.is_empty());

AOT backend (CUDA):

let compiled = compiler.compile(&spec)?;
assert!(compiled.src.is_none());
assert!(!compiled.bytes.is_empty());
Source

fn cache_key(&self) -> &'static str

Cache key identifying this compiler backend.

Used to differentiate compiled artifacts when the same device type can have multiple compiler backends (e.g., clang vs llvm-jit).

Implementors§