Skip to main content

RuleRegistry

Struct RuleRegistry 

Source
pub struct RuleRegistry { /* private fields */ }
Expand description

A registry of Rules. Drives optimize-to-fixpoint via Self::optimize_to_fixpoint: lowering rules run to fixpoint, then fusion rules run to fixpoint. The locked design (ROADMAP.md Phase 7.5) intends this entry point to be wrapped in transactions in subsequent PRs without rewriting the loop body — keep this API stable for that future evolution.

Implementations§

Source§

impl RuleRegistry

Source

pub fn new() -> Self

Empty registry. Use Self::with_rule to add rules, or Self::default_rules / Self::lowering_only for the shipped configurations.

Source

pub fn with_rule(self, rule: Box<dyn Rule>) -> Self

Append a rule. Returns self for builder-style chaining.

Source

pub fn default_rules() -> Self

Lower + fuse rules for every fused op registered in the process-wide default_registry. Round-trip is identity for canonical SoftmaxLastDim graphs (the lowered subgraph is structurally re-fused). Use this in production realize paths.

Phase 7.6 step 3: PR 3’s hand-written SoftmaxLastDimLowerRule/SoftmaxLastDimFuseRule are deleted; equivalent behavior is auto-generated from the SoftmaxLastDim registry entry. Subsequent fused-op migrations in step 4 add their entries to the same registry; default_rules picks them up automatically.

Source

pub fn capability_gated_rules( has_kernel: impl Fn(FusedOpId) -> bool, ) -> (Self, Vec<FusedOpId>)

Build lower + fuse rules, but fuse a fused op only when has_kernel(id) holds — the capability gate (runtime-fused-op-registration.md §6). Every fused op (static + runtime) still gets a lowering rule (so any already-fused node decomposes); an op WITHOUT a kernel gets no fusion rule, so a kernel-absent fused node never forms in the first place — the miss is caught at the pattern-match step, not repaired afterward.

Returns the rule set plus the ids that were gated out of fusion — the miss candidates feeding the JIT work-order signal. The dispatch layer supplies has_kernel from its FusedKernelRegistry + the target backend; Self::default_rules is the all-available case.

Source

pub fn lowering_only() -> Self

Lowering rules only — no fusion. Use this when the test or caller wants the lowered form to be the post-pipeline state (e.g. equivalence-testing the composed-math path on a backend that has the primitives but not the fused kernel).

Source

pub fn len(&self) -> usize

Number of registered rules.

Source

pub fn is_empty(&self) -> bool

Whether the registry has any rules.

Source

pub fn optimize_to_fixpoint( &self, graph: &SharedGraph, roots: &[NodeId], ) -> Vec<NodeId>

Run lowering rules to fixpoint, then fusion rules to fixpoint. Returns the (possibly-rewritten) roots — callers use these to replace their NodeHandle handles.

The two-phase ordering is important: rules that are inverses of each other (e.g. SoftmaxLastDim’s lower + fuse pair) would oscillate in a single mixed-family fixpoint loop. Phase ordering breaks the oscillation and gives fusion the last word.

Trait Implementations§

Source§

impl Default for RuleRegistry

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V