pub struct JITCompiler { /* private fields */ }Implementations§
Source§impl JITCompiler
impl JITCompiler
Sourcepub fn get_function_table(&self) -> &[*const u8]
pub fn get_function_table(&self) -> &[*const u8]
Get the function table for setting up JITContext
Sourcepub fn get_function_by_index(&self, idx: usize) -> Option<JittedStrategyFn>
pub fn get_function_by_index(&self, idx: usize) -> Option<JittedStrategyFn>
Get a compiled function pointer by function index
Source§impl JITCompiler
impl JITCompiler
pub fn compile( &mut self, name: &str, program: &BytecodeProgram, ) -> Result<JittedFn, String>
pub fn compile_program( &mut self, name: &str, program: &BytecodeProgram, ) -> Result<JittedStrategyFn, String>
Sourcepub fn compile_single_function(
&mut self,
program: &BytecodeProgram,
func_index: usize,
feedback: Option<FeedbackVector>,
) -> Result<(*const u8, Vec<DeoptInfo>, Vec<ShapeId>), String>
pub fn compile_single_function( &mut self, program: &BytecodeProgram, func_index: usize, feedback: Option<FeedbackVector>, ) -> Result<(*const u8, Vec<DeoptInfo>, Vec<ShapeId>), String>
Compile a single function for Tier 1 whole-function JIT.
ABI matches JitFnPtr: extern "C" fn(*mut u8, *const u8) -> u64
- param 0 (i64): ctx_ptr — pointer to a JITContext-shaped buffer
- param 1 (i64): unused (kept for ABI compatibility with OSR)
- return (i64): NaN-boxed result value, or u64::MAX for deopt
Args are loaded from the ctx locals area at LOCALS_U64_OFFSET. Cross-function calls deopt to interpreter (empty user_funcs).
Returns (code_ptr, deopt_points, shape_guards) on success.
Sourcepub fn compile_optimizing_function(
&mut self,
program: &BytecodeProgram,
func_index: usize,
feedback: FeedbackVector,
callee_feedback: &HashMap<u16, FeedbackVector>,
) -> Result<(*const u8, Vec<DeoptInfo>, Vec<ShapeId>), String>
pub fn compile_optimizing_function( &mut self, program: &BytecodeProgram, func_index: usize, feedback: FeedbackVector, callee_feedback: &HashMap<u16, FeedbackVector>, ) -> Result<(*const u8, Vec<DeoptInfo>, Vec<ShapeId>), String>
Compile a function for Tier 2 optimizing JIT with feedback-guided speculation.
The target function’s own FuncRef is declared with Linkage::Local for
self-recursive direct calls. Cross-function monomorphic call sites get
speculative direct calls when the callee has already been Tier-2 compiled:
the callee’s opt_dc_* FuncId is looked up in compiled_dc_funcs and
a FuncRef is declared, enabling compile_direct_call to emit a true
call instruction (not FFI). A callee identity guard protects every
speculative call; on guard failure the JIT deopts to the interpreter.
ABI: Returns a JitFnPtr wrapper (ctx_ptr, unused) -> u64 that loads
args from the ctx locals area, calls the direct-call function, and
converts the result.
Sourcepub fn compile_program_selective(
&mut self,
name: &str,
program: &BytecodeProgram,
) -> Result<(JittedStrategyFn, MixedFunctionTable), String>
pub fn compile_program_selective( &mut self, name: &str, program: &BytecodeProgram, ) -> Result<(JittedStrategyFn, MixedFunctionTable), String>
Selectively compile a program, JIT-compiling compatible functions and falling back to interpreter entries for incompatible ones.
Returns a MixedFunctionTable mapping each function index to either
a Native pointer (JIT-compiled) or Interpreted marker.
The main strategy body is always compiled. Only user-defined functions go through per-function preflight.
Source§impl JITCompiler
impl JITCompiler
Sourcepub fn module_mut(&mut self) -> &mut JITModule
pub fn module_mut(&mut self) -> &mut JITModule
Borrow the underlying JITModule (for declaring/defining functions).
Sourcepub fn builder_context_mut(&mut self) -> &mut FunctionBuilderContext
pub fn builder_context_mut(&mut self) -> &mut FunctionBuilderContext
Borrow the FunctionBuilderContext (reused across compilations).
Source§impl JITCompiler
impl JITCompiler
pub fn compile_strategy( &mut self, name: &str, program: &BytecodeProgram, ) -> Result<JittedStrategyFn, String>
Sourcepub fn compile_simulation_kernel(
&mut self,
name: &str,
program: &BytecodeProgram,
config: &SimulationKernelConfig,
) -> Result<SimulationKernelFn, String>
pub fn compile_simulation_kernel( &mut self, name: &str, program: &BytecodeProgram, config: &SimulationKernelConfig, ) -> Result<SimulationKernelFn, String>
Compile a simulation kernel with the specialized kernel ABI.
The kernel ABI bypasses JITContext to achieve maximum throughput:
- Direct pointer arithmetic for data access
- No allocations in the hot path
- Inlined field access with known offsets
§Arguments
name- Function name for the compiled kernelprogram- Bytecode program containing the strategyconfig- Kernel configuration with field offset mappings
§Returns
A function pointer with signature: fn(usize, *const *const f64, *mut u8) -> i32
§Generated Code Pattern
For a strategy like:
let price = candle.close
if price > state.threshold {
state.signal = 1.0
}The kernel generates:
; price = candle.close (column 3)
mov rax, [series_ptrs + 3*8] ; column pointer
mov xmm0, [rax + cursor_index*8] ; price value
; state.threshold (offset 16)
mov xmm1, [state_ptr + 16] ; threshold value
; comparison and store
ucomisd xmm0, xmm1
jbe skip
mov qword [state_ptr + 24], 1.0 ; state.signal
skip:Compile a correlated (multi-series) simulation kernel.
This extends the simulation kernel to support multiple aligned time series, enabling cross-series strategies (e.g., SPY vs VIX, temperature vs pressure).
§Arguments
name- Function name for the compiled kernelprogram- Bytecode program containing the strategyconfig- Kernel configuration with series mappings
§Returns
A function pointer with signature:
fn(cursor_index: usize, series_ptrs: *const *const f64, table_count: usize, state_ptr: *mut u8) -> i32
§Generated Code Pattern
For a strategy like:
let spy_price = context.spy // series index 0
let vix_level = context.vix // series index 1
if vix_level > 25.0 && state.position == 0 {
state.signal = 1.0
}The kernel generates:
; spy_price = context.spy (series index 0)
mov rax, [series_ptrs + 0*8] ; series 0 pointer
mov xmm0, [rax + cursor_index*8] ; spy value
; vix_level = context.vix (series index 1)
mov rax, [series_ptrs + 1*8] ; series 1 pointer
mov xmm1, [rax + cursor_index*8] ; vix value
; comparison and conditional store
mov xmm2, [const_25.0]
ucomisd xmm1, xmm2
jbe skip
; ... check state.position == 0 ...
mov qword [state_ptr + signal_offset], 1.0
skip:Auto Trait Implementations§
impl !Freeze for JITCompiler
impl !RefUnwindSafe for JITCompiler
impl !Send for JITCompiler
impl !Sync for JITCompiler
impl Unpin for JITCompiler
impl UnsafeUnpin for JITCompiler
impl !UnwindSafe for JITCompiler
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more