Skip to main content

Module host_fns

Module host_fns 

Source

Enums§

RuntimeError
Runtime errors raised by JIT code via host functions.

Functions§

clear_gc_state
Clear the active GC state for the current thread.
clear_gc_test_hook
Clear the GC test hook.
clear_stack_map_registry
Clear the stack map registry for the current thread.
debug_app_check
Returns 0 if the call is safe to proceed, or a poison pointer if the call should be short-circuited (runtime error already set or call depth exceeded).
drain_diagnostics
Drain all accumulated diagnostics.
error_poison_ptr
Return a pointer to a pre-allocated “poison” Closure heap object. When JIT code tries to call this as a function, it returns itself, preventing cascading crashes. The runtime error flag is already set, so the effect machine will catch it before the poison reaches user code.
error_poison_ptr_lazy
Return a pre-allocated “lazy poison” Closure for a given error kind. Unlike error_poison_ptr(), this does NOT set the error flag at creation time. The error is only triggered when the closure is actually called (via poison_trampoline_lazy). This is critical for typeclass dictionaries where error methods exist as fields but may never be invoked.
error_poison_ptr_lazy_msg
Create a pre-allocated “lazy poison” Closure for a given error kind and message.
gc_trigger
GC trigger: called by JIT code when alloc_ptr exceeds alloc_limit.
gc_trigger_call_count
Get gc_trigger call count. Only call from tests.
gc_trigger_last_vmctx
Get last vmctx passed to gc_trigger. Only call from tests.
get_exec_context
Get the current execution context.
heap_force
Force a thunk to WHNF. Loops to handle chains (thunk returning thunk).
host_fn_symbols
last_gc_roots
Get collected roots from the last gc_trigger call.
push_diagnostic
Push a diagnostic message to the thread-local buffer.
reset_call_depth
Reset the call depth counter. Call before each JIT invocation.
reset_test_counters
Reset test counters. Only call from tests.
runtime_bad_thunk_state_trap
Called by JIT code when a Thunk has an invalid state.
runtime_blackhole_trap
Called by JIT code when a BlackHole is encountered (thunk forcing itself).
runtime_cas_boxed_array
CAS on a boxed array slot: compare-and-swap arr[idx]. Returns the old value. If old == expected, writes new.
runtime_case_trap
Debug: called instead of trap user2 when TIDEPOOL_DEBUG_CASE is set. Prints diagnostic info about the scrutinee that failed case matching. scrut_ptr is the heap pointer to the scrutinee. num_alts is the number of data alt tags expected. alt_tags is a pointer to an array of expected tag u64 values.
runtime_clone_boxed_array
Clone a sub-range of a boxed array: src[off..off+len].
runtime_compare_byte_arrays
Compare byte arrays: returns -1, 0, or 1.
runtime_copy_addr_to_byte_array
Copy len bytes from src (Addr#) to dest_ba (ByteArray ptr) at dest_off.
runtime_copy_boxed_array
Copy len pointer slots from src[src_off..] to dest[dest_off..].
runtime_copy_byte_array
Copy len bytes between byte arrays: src[src_off..] -> dest[dest_off..]. Used by both copyByteArray# and copyMutableByteArray#.
runtime_decode_double_exponent
Decode a Double into its Int exponent.
runtime_decode_double_mantissa
Decode a Double into its Int64 mantissa (significand). GHC’s decodeDouble_Int64# returns (# mantissa, exponent #).
runtime_double_acos
runtime_double_acosh
runtime_double_asin
runtime_double_asinh
runtime_double_atan
runtime_double_atanh
runtime_double_cos
runtime_double_cosh
runtime_double_exp
runtime_double_expm1
runtime_double_log
runtime_double_log1p
runtime_double_power
runtime_double_sin
runtime_double_sinh
runtime_double_tan
runtime_double_tanh
runtime_error
Called by JIT code for runtime errors (divZeroError, overflowError). Sets a thread-local error flag and returns a “poison” Lit(Int#, 0) object instead of null. This prevents JIT code from segfaulting on the return value. The effect machine checks the error flag after JIT returns and converts to Yield::Error. kind: 0 = divZeroError, 1 = overflowError, 2 = UserError, 3 = Undefined
runtime_error_with_msg
Called by JIT code for runtime errors with a specific message.
runtime_new_boxed_array
Allocate a new boxed array of len pointer slots, each initialized to init. Layout: [u64 length][ptr0][ptr1]…[ptrN-1] Each slot is 8 bytes (a heap pointer).
runtime_new_byte_array
Allocate a new mutable byte array of size bytes, zeroed. Layout: [u64 length][u8 bytes…] Returns a raw pointer to the allocation (caller stores in Lit value slot).
runtime_oom
runtime_resize_byte_array
Resize a mutable byte array. Allocates a new buffer, copies existing data, zeroes any new bytes, and frees the old buffer. Returns the new pointer.
runtime_set_byte_array
Set len bytes in ba starting at off to val.
runtime_show_double_addr
Format a Double as a null-terminated C string and return its address. The CString is leaked (small bounded strings, acceptable).
runtime_shrink_boxed_array
Shrink a boxed array (just update the length field).
runtime_shrink_byte_array
Shrink a mutable byte array to new_size bytes (just updates the length prefix).
runtime_strlen
strlen: count bytes until null terminator.
runtime_text_measure_off
Measure codepoints in a UTF-8 buffer. Matches text-2.1.2 _hs_text_measure_off semantics.
runtime_text_memchr
Find a byte in a buffer. Returns offset from start, or -1 if not found.
runtime_text_reverse
Reverse UTF-8 text. Matches text-2.1.2 _hs_text_reverse(dst0, src0, off, len).
set_exec_context
Set the current execution context for JIT code. This is used to provide more info when a signal (SIGSEGV/SIGILL) occurs.
set_gc_state
Set the active GC state for the current thread.
set_gc_test_hook
Set a hook to be called during gc_trigger with the collected roots.
set_stack_map_registry
Set the stack map registry for the current thread.
take_runtime_error
Check and take any pending runtime error from JIT code.
trampoline_resolve
Resolve pending tail calls from VMContext. Called by non-tail App sites when the callee returned null (indicating a tail call was stored).
unresolved_var_trap
Called by JIT code when an unresolved external variable is forced. Returns null to allow execution to continue (will likely segfault later). In debug mode (TIDEPOOL_TRACE), logs and returns null.