#[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
impl SandboxTrapKind
Sourcepub fn from_code(code: u64) -> SandboxTrapKind
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.
Sourcepub fn to_runtime_error(self, range: TokenRange) -> RuntimeError
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
impl Clone for SandboxTrapKind
Source§fn clone(&self) -> SandboxTrapKind
fn clone(&self) -> SandboxTrapKind
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl Copy for SandboxTrapKind
Source§impl Debug for SandboxTrapKind
impl Debug for SandboxTrapKind
impl Eq for SandboxTrapKind
Source§impl PartialEq for SandboxTrapKind
impl PartialEq for SandboxTrapKind
Source§fn eq(&self, other: &SandboxTrapKind) -> bool
fn eq(&self, other: &SandboxTrapKind) -> bool
self and other values to be equal, and is used by ==.impl StructuralPartialEq for SandboxTrapKind
Auto Trait Implementations§
impl Freeze for SandboxTrapKind
impl RefUnwindSafe for SandboxTrapKind
impl Send for SandboxTrapKind
impl Sync for SandboxTrapKind
impl Unpin for SandboxTrapKind
impl UnsafeUnpin for SandboxTrapKind
impl UnwindSafe for SandboxTrapKind
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
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