Skip to main content

JITCompiler

Struct JITCompiler 

Source
pub struct JITCompiler { /* private fields */ }

Implementations§

Source§

impl JITCompiler

Source

pub fn get_function_table(&self) -> &[*const u8]

Get the function table for setting up JITContext

Source

pub fn get_function_by_index(&self, idx: usize) -> Option<JittedStrategyFn>

Get a compiled function pointer by function index

Source§

impl JITCompiler

Source

pub fn compile( &mut self, name: &str, program: &BytecodeProgram, ) -> Result<JittedFn, String>

Source

pub fn compile_program( &mut self, name: &str, program: &BytecodeProgram, ) -> Result<JittedStrategyFn, String>

Source

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.

Source

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.

Source

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

Source

pub fn module_mut(&mut self) -> &mut JITModule

Borrow the underlying JITModule (for declaring/defining functions).

Source

pub fn builder_context_mut(&mut self) -> &mut FunctionBuilderContext

Borrow the FunctionBuilderContext (reused across compilations).

Source§

impl JITCompiler

Source

pub fn new(config: JITConfig) -> Result<Self, JitError>

Source§

impl JITCompiler

Source

pub fn compile_strategy( &mut self, name: &str, program: &BytecodeProgram, ) -> Result<JittedStrategyFn, String>

Source

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 kernel
  • program - Bytecode program containing the strategy
  • config - 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:
Source

pub fn compile_correlated_kernel( &mut self, name: &str, program: &BytecodeProgram, config: &SimulationKernelConfig, ) -> Result<CorrelatedKernelFn, String>

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 kernel
  • program - Bytecode program containing the strategy
  • config - 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§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more