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§
Sourcefn result_type(&self, types: &TypeManager, args: &[TypeId]) -> TypeId
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.
Provided Methods§
Sourcefn root_op(&self) -> Option<RootOp>
fn root_op(&self) -> Option<RootOp>
IR shape this intrinsic’s idiom roots at, if it participates in recognition.
Sourcefn recognize(
&self,
_view: BodyView<'_, '_>,
_at: InstructionId,
) -> Option<Vec<ValueId>>
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).
Sourcefn simplify(
&self,
_view: BodyView<'_, '_>,
_id: IntrinsicId,
_out_size: usize,
_args: &[ValueId],
) -> Option<Simplified>
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".