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.RhsPlan — Type
RhsPlan

An 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].

source
MatchMaker.RhsT — Type
RhsT

FunctionWrapper signature for callable rule RHSs: (view::SubstitutionView) -> Union{expr, nothing} — nothing means "matched but produce nothing": the caller falls through to the next rule.

source

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.

source
MatchMaker.BucketIndex — Type
BucketIndex <: RuleIndex

Phase-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).

source
MatchMaker.DiscrimNet — Type
DiscrimNet <: RuleIndex

Phase-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.

source

The workspace and rewrite passes

MatchMaker.RuleWorkspace — Type
RuleWorkspace

The 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 application

ws.maxsteps is a mutable per-site budget.

source
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).

source
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.

source

Deprecated