Module jit

Module jit 

Source
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, contains string functions

Complex expressions (comprehensions, maps, structs, custom functions) fall back to the tree-walking interpreter.

§Architecture

The JIT compiler:

  1. Parses the CEL expression using cel-parser to get the AST.
  2. Checks if the expression is supported by the JIT (simple enough).
  3. Compiles the AST to cranelift IR.
  4. Compiles the cranelift IR to native code.
  5. 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§

CelJitProgram
A JIT-compiled CEL program. When the cel-jit feature is ON and the expression is simple enough, [CelProgram::compile] produces a CelJitProgram that can be evaluated without the tree-walking interpreter. When the feature is OFF or the expression is too complex, this is None and evaluation falls back to the interpreter.

Enums§

CelJitResult
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-jit cargo feature is compiled in.
jit_result_to_value
Convert a CelJitResult to a cel_interpreter::Value. Returns None for Unsupported or Error (the caller should fall back to the interpreter).