Skip to main content

SandboxTrapKind

Enum SandboxTrapKind 

Source
#[repr(u64)]
pub enum SandboxTrapKind { DivisionByZero = 1, BoundsViolation = 2, CapabilityDenied = 3, ResourceExhausted = 4, HostFnMissing = 5, NumericOverflow = 6, HostFnError = 7, }
Expand description

Trap kind raised by a guard inside LLVM-emitted native code. The numeric values match the cranelift backend’s TrapKind and the [crate::state::NativeTrap] subset the JIT-side dynamic dispatch helper already records, so the host decodes the same cause numbering across backends. Encoded as u64 so it fits the ArenaState::trap_code slot the emitted object writes through relon_llvm_call_native / the Op::CheckCap trap arm.

Only the subset the LLVM native path can currently raise (DivisionByZero via the sdiv/srem guard, BoundsViolation via arena guards, CapabilityDenied via Op::CheckCap, NumericOverflow via checked Int arithmetic / reductions, and HostFnMissing/HostFnError via dynamic dispatch) is reachable today; the remaining variants are kept so the numbering stays a faithful mirror of cranelift’s for the deadline work that lands with the wider emitter.

Variants§

§

DivisionByZero = 1

Division (Op::Div / Op::Mod) by zero. Buffer entries record this code in ArenaState::trap_code; legacy/fast entries have no typed error lane and still use llvm.trap.

§

BoundsViolation = 2

Pointer dereference walked past the arena bounds.

§

CapabilityDenied = 3

An Op::CheckCap { cap_bit } found the matching bit clear in the host-granted caps mask. Lifts to RuntimeError::CapabilityDenied. Matches cranelift’s TrapKind::CapabilityDenied and [crate::state::NativeTrap::CapabilityDenied] (= 3).

§

ResourceExhausted = 4

Per-call resource budget exhausted. LLVM currently raises this through deterministic step-budget fuel; a future wall-clock deadline can reuse the same trap code.

§

HostFnMissing = 5

No host fn registered at the requested import_idx, or no registry installed. Matches cranelift’s TrapKind::Unreachable (= 5) and [crate::state::NativeTrap::HostFnMissing]; lifts to RuntimeError::Unsupported.

§

NumericOverflow = 6

Signed integer overflow. Matches cranelift’s TrapKind::NumericOverflow (= 6) and [crate::state::NativeTrap::NumericOverflow]. Raised by checked Op::Add / Op::Sub / Op::Mul, the INT_MIN / -1 div/rem guard, and bundled checked reductions such as list_int_sum.

§

HostFnError = 7

A host fn returned an error, or a value outside the scalar return envelope. Matches [crate::state::NativeTrap::HostFnError] (= 7); lifts to RuntimeError::Unsupported.

Implementations§

Source§

impl SandboxTrapKind

Source

pub fn from_code(code: u64) -> SandboxTrapKind

Decode a u64 recorded in ArenaState::trap_code back into a SandboxTrapKind. Unknown / 0 codes route to SandboxTrapKind::HostFnError so the host always gets a typed RuntimeError rather than a panic — matching cranelift’s catch-all-into-typed-error posture.

Source

pub fn to_runtime_error(self, range: TokenRange) -> RuntimeError

Lift a trap kind into the appropriate RuntimeError variant. All trap mappings carry the entry function’s source range so the diagnostic at least points at the #main declaration. Mirrors cranelift’s TrapKind::to_runtime_error and the [crate::state::NativeTrap::runtime_error_from_code] subset.

Trait Implementations§

Source§

impl Clone for SandboxTrapKind

Source§

fn clone(&self) -> SandboxTrapKind

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for SandboxTrapKind

Source§

impl Debug for SandboxTrapKind

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for SandboxTrapKind

Source§

impl PartialEq for SandboxTrapKind

Source§

fn eq(&self, other: &SandboxTrapKind) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for SandboxTrapKind

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.