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
impl RuleRegistry
Sourcepub fn new() -> Self
pub fn new() -> Self
Empty registry. Use Self::with_rule to add rules, or
Self::default_rules / Self::lowering_only for the
shipped configurations.
Sourcepub fn with_rule(self, rule: Box<dyn Rule>) -> Self
pub fn with_rule(self, rule: Box<dyn Rule>) -> Self
Append a rule. Returns self for builder-style chaining.
Sourcepub fn default_rules() -> Self
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.
Sourcepub fn capability_gated_rules(
has_kernel: impl Fn(FusedOpId) -> bool,
) -> (Self, Vec<FusedOpId>)
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.
Sourcepub fn lowering_only() -> Self
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).
Sourcepub fn optimize_to_fixpoint(
&self,
graph: &SharedGraph,
roots: &[NodeId],
) -> Vec<NodeId>
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.