Rewriting
mmrule compiles rules; RuleSet(rules, index) bundles them into an immutable rule set; a RuleWorkspace owns the mutable state and is itself the first-match rewriter callable. rewrite/fixpoint_rewrite are the native tree passes.
Rules
MatchMaker.mmrule — Function
mmrule(lhs => rhs; vars = Dict(), constraints = Constraint[])Build a CompiledRule. lhs is compiled via compile_pattern; rhs is a symbolic template (compiled to an RhsPlan), a callable f(view) -> expr | nothing, or any other value, which is wrapped as a literal Const. vars maps pattern variables to VarSpecs; constraints are cross-variable checks — see Constraint.
MatchMaker.RhsPlan — Type
RhsPlanAn rhs template compiled against the lhs var ids — evaluation reads eng.binds by index and splices segment captures positionally, never building a Sym → value dict.
Extended help
vid_of[i] is the pattern var id bound at template-IR node i (0 = not a marker); updates caches exactly the node indices needing rebuild on eval — everything else keeps ir[i].
MatchMaker.RhsT — Type
RhsTFunctionWrapper signature for callable rule RHSs: (view::SubstitutionView) -> Union{expr, nothing} — nothing means "matched but produce nothing": the caller falls through to the next rule.
Compiled rule sets and dispatch
MatchMaker.RuleSet — Type
RuleSet{I <: RuleIndex}The immutable compiled artifact: the rules plus the dispatch index, built once by RuleSet(rules, index) and shareable across tasks and calls — all mutable state lives in RuleWorkspace.
MatchMaker.RuleIndex — Type
RuleIndexAbstract dispatch seam for many-to-one lookup: lookup!(idx, buf, ws, x, sroot) appends candidate rule ids to buf. Phase 1 is BucketIndex; DiscrimNet is Phase 2.
MatchMaker.BucketIndex — Type
BucketIndex <: RuleIndexPhase-1 index: rules bucketed by root-obligation signature — a fixed op head, a slot/marked head (any_head), or a leaf literal (leaf_rules).
Extended help
arity[i] is rule i's (min, max) subject-arity bounds (optional counts 0-or-1).
MatchMaker.DiscrimNet — Type
DiscrimNet <: RuleIndexPhase-2 index: a shared trie over every pattern's preorder obligation sequence — select with RuleSet(rules, DiscrimNet). Faster than BucketIndex wherever many rules share a root head but differ in literals or deeper structure; never slower by design (over-approximates survivors — the engine still decides).
Extended help
Call children descend positionally; slot obligations are wildcard edges (predicates, want_types and non-linearity stay with the engine); SeqCall/CommCall/ACCall subtrees only confirm op + arity bounds and defer to the engine. Evaluation is NFA simulation over ws.subj, memoized per (state, subj_node) in ws.net_cache: subject-IR interning makes a DAG-shared subterm evaluate once, and fixpoint iterations re-evaluate only newly created nodes.
The workspace and rewrite passes
MatchMaker.RuleWorkspace — Type
RuleWorkspaceThe mutable application context — and the rewriter callable. Holds one shared subject IRStructure, a lazily created MatchEngine per rule (reset! between sites, not re-allocated), the candidate buffer, and the net_cache. Build one per RuleSet and reuse.
(ws::RuleWorkspace)(x) -> expr′ | nothing # first-match rule applicationws.maxsteps is a mutable per-site budget.
MatchMaker.rewrite — Function
rewrite(
ws::RuleWorkspace,
expr::SymbolicUtils.BasicSymbolicImpl.var"typeof(BasicSymbolicImpl)"{SymReal};
order
) -> SymbolicUtils.BasicSymbolicImpl.var"typeof(BasicSymbolicImpl)"{SymReal}
The MatchMaker-native rewrite pass. order = :post (the default) sweeps ws.subj postorder — interning dedups shared subterms and only changed nodes rebuild. order = :pre applies the workspace before descending into the result (same semantics as Rewriters.Prewalk).
MatchMaker.fixpoint_rewrite — Function
fixpoint_rewrite(
ws::RuleWorkspace,
expr::SymbolicUtils.BasicSymbolicImpl.var"typeof(BasicSymbolicImpl)"{SymReal};
maxiterations,
order
) -> SymbolicUtils.BasicSymbolicImpl.var"typeof(BasicSymbolicImpl)"{SymReal}
Iterate rewrite to a fixed point: the workspace IRStructure accumulates across iterations, and each sweep re-evaluates only changed-node ancestors plus new nodes (dirty propagation). A term seen twice ends the loop; maxiterations bounds it outright.
Deprecated
MatchMaker.compile_rules — Function
compile_rules(rules, index = BucketIndex)Deprecated — use the RuleSet constructor instead.