Expand description
CEL JIT compilation via cranelift (PERF-09, #260).
This module provides a cranelift-based JIT compiler for CEL
expressions. When the cel-jit cargo feature is enabled, the
[CelProgram] can optionally JIT-compile simple CEL expressions
to native code for faster evaluation.
§Supported expressions
The JIT compiler supports a subset of CEL expressions:
- Boolean literals (
true,false) - Integer literals (
1,42) - String literals (
"hello") - Identifier references (
request.path) - Comparison operators (
==,!=,<,<=,>,>=) - Logical operators (
&&,||,!) - The
startsWith,endsWith,containsstring functions
Complex expressions (comprehensions, maps, structs, custom functions) fall back to the tree-walking interpreter.
§Architecture
The JIT compiler:
- Parses the CEL expression using
cel-parserto get the AST. - Checks if the expression is supported by the JIT (simple enough).
- Compiles the AST to cranelift IR.
- Compiles the cranelift IR to native code.
- Returns a function pointer that can be called to evaluate the expression.
The JIT-compiled function takes a context pointer and returns a
CelJitResult (a tagged union of bool, i64, f64, or string).
§Current status
The cel-jit feature gate, dependency wiring, and module structure
are in place. The actual AST-to-cranelift-IR compilation is a future
enhancement — the JIT currently returns Unsupported for all
expressions, so evaluation falls back to the tree-walking
interpreter. This scaffolding allows the feature to be compiled and
tested without a full JIT implementation, and provides the
integration point for future work.
§Fallback
When the cel-jit feature is OFF or the expression is too complex
for the JIT, evaluation falls back to the tree-walking interpreter
(cel-interpreter). This is transparent to the caller: the
[CelProgram::evaluate] API is the same regardless of whether the
JIT is used.
Structs§
- CelJit
Program - A JIT-compiled CEL program. When the
cel-jitfeature is ON and the expression is simple enough, [CelProgram::compile] produces aCelJitProgramthat can be evaluated without the tree-walking interpreter. When the feature is OFF or the expression is too complex, this isNoneand evaluation falls back to the interpreter.
Enums§
- CelJit
Result - The result of a JIT-compiled CEL evaluation. A tagged union of the CEL scalar types the JIT supports. The JIT-compiled function returns this by value.
Functions§
- cel_
jit_ available - Check if the
cel-jitcargo feature is compiled in. - jit_
result_ to_ value - Convert a
CelJitResultto acel_interpreter::Value. ReturnsNoneforUnsupportedorError(the caller should fall back to the interpreter).