Skip to main content

Intrinsic

Trait Intrinsic 

Source
pub trait Intrinsic: Sync {
    // Required methods
    fn name(&self) -> &'static str;
    fn arity(&self) -> usize;
    fn result_type(&self, types: &TypeManager, args: &[TypeId]) -> TypeId;
    fn eval(&self, args: &[(u128, usize)], out_size: usize) -> Option<u128>;

    // Provided methods
    fn root_op(&self) -> Option<RootOp> { ... }
    fn recognize(
        &self,
        _view: BodyView<'_, '_>,
        _at: InstructionId,
    ) -> Option<Vec<ValueId>> { ... }
    fn simplify(
        &self,
        _view: BodyView<'_, '_>,
        _id: IntrinsicId,
        _out_size: usize,
        _args: &[ValueId],
    ) -> Option<Simplified> { ... }
}
Expand description

The definition of one kind of intrinsic — its name, arity, result typing, shared evaluator, and optional recognition / simplification behaviour.

An IntrinsicId is a by-name handle resolving to a single &'static dyn Intrinsic; the IntrinsicApp mnemonic is an application of that definition to operands. Built-in definitions are unit structs registered via register_intrinsic!.

Required Methods§

Source

fn name(&self) -> &'static str

Textual name, e.g. "rol". Unique across the registry.

Source

fn arity(&self) -> usize

Number of operands the intrinsic takes.

Source

fn result_type(&self, types: &TypeManager, args: &[TypeId]) -> TypeId

The result type for an application to operands of types args. A sized integer is just a type, so a width-only intrinsic accesses the published canonical integer; sequence-producing intrinsics likewise require their result type to have been created before this method is called.

Source

fn eval(&self, args: &[(u128, usize)], out_size: usize) -> Option<u128>

Evaluate on concrete operands (bits, byte_width), producing an out_size-byte result. None means “not foldable / trap” — constant folding bails, the emulator raises.

Provided Methods§

Source

fn root_op(&self) -> Option<RootOp>

IR shape this intrinsic’s idiom roots at, if it participates in recognition.

Source

fn recognize( &self, _view: BodyView<'_, '_>, _at: InstructionId, ) -> Option<Vec<ValueId>>

Recognize the raw-IR idiom rooted at at, returning the intrinsic’s operands when the instruction matches. Reads the IR through a BodyView and mints any derived operand literals through the shared interner (e.g. a rotate amount recovered as the log2 of a strength-reduced multiplier).

Source

fn simplify( &self, _view: BodyView<'_, '_>, _id: IntrinsicId, _out_size: usize, _args: &[ValueId], ) -> Option<Simplified>

Algebraic simplification on the intrinsic’s own operands — e.g. rol(x, 0) → x or rol(a, c) → rol(a, c mod bits). Receives the applied IntrinsicId (so a shared simplifier can branch on rol vs ror), the result byte width, and the operands. Reads through a BodyView and mints replacement literals through the shared interner.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§