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§
Sourcefn compile(&self, spec: &ProgramSpec) -> Result<CompiledSpec>
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
srcfield, emptybytes - For AOT backends (CUDA/Metal): compiled bytes in
bytesfield, nosrc
§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());