ReversibleSearcherPhase

foresight.eqsat.rewriting.ReversibleSearcherPhase
trait ReversibleSearcherPhase[NodeT, InputT, IntermediateT, MatchT, EGraphT <: EGraphLike[NodeT, EGraphT] & EGraph[NodeT]]() extends SearcherPhase[NodeT, InputT, IntermediateT, Seq[MatchT], EGraphT]

A searcher phase that supports reversal into an Applier.

In a multiphase search pipeline, reversal proceeds backwards: the last reversible search phase turns into an applier on its match type, the previous phase turns into an applier on its own match type that feeds into the next applier, and so on. This trait exposes a tryReverse hook that receives the already-reversed "next" applier and returns an applier for this phase.

Reversal model

Consider a search pipeline:

phase1: SearcherPhase[Node, In1, I1, Out1, G]
phase2: ReversibleSearcherPhase[Node, Out1, I2, Match, G]
// Searcher = Searcher(phase1).chain(phase2)

Reversal of phase2 yields an Applier[Node, Match, G]. If phase1 is also reversible (as a ReversibleSearcherPhase), it can use tryReverse(nextApplier) to produce an Applier[Node, In1, G] that feeds matches forward into nextApplier.

Contract

  • tryReverse(nextPhase) returns an applier that, when applied to a MatchT, produces commands equivalent to the edits this phase implies, then delegates to nextPhase.
  • Partial reversal is valid: return None when an inverse is not meaningful (e.g., lossy mapping).
  • Determinism and portability matter for caching: base the generated commands only on data available in the provided e-graph snapshot.

Composition

Type parameters

EGraphT

Concrete e-graph type (both EGraphLike and EGraph).

InputT

Input carried from the previous phase (the phase you would reverse next).

IntermediateT

Per-class result type for this phase (same role as in SearcherPhase).

MatchT

Match element type this phase ultimately contributes (the search output of this phase).

NodeT

Node payload type.

Attributes

Graph
Supertypes
trait SearcherPhase[NodeT, InputT, IntermediateT, Seq[MatchT], EGraphT]
class Object
trait Matchable
class Any
Known subtypes
class MachineSearcherPhase[NodeT, EGraphT]

Members list

Value members

Abstract methods

def tryReverse(nextPhase: Applier[NodeT, InputT, EGraphT]): Option[Applier[NodeT, MatchT, EGraphT]]

Reverse this phase into an Applier over this phase's match type, optionally composing with the already-reversed applier of the next phase in the pipeline.

Reverse this phase into an Applier over this phase's match type, optionally composing with the already-reversed applier of the next phase in the pipeline.

Value parameters

nextPhase

Applier produced by reversing the subsequent search phase. Use it to forward reconstructed inputs downstream. For the last phase in a pipeline, pass an identity/no-op applier.

Attributes

Returns

An applier for MatchT, or None if reversal is unavailable.

Inherited methods

final def search(egraph: EGraphT, input: InputT, parallelize: ParallelMap): Seq[MatchT]

Run this phase across the entire e-graph, in parallel where possible, then aggregate.

Run this phase across the entire e-graph, in parallel where possible, then aggregate.

The implementation:

  • iterates over egraph.classes,
  • canonicalizes each class ref,
  • computes per-class results with search(call, egraph, input),
  • aggregates via aggregate.

Value parameters

egraph

Immutable e-graph snapshot to search.

input

Input from the previous phase (or Unit for the first phase).

parallelize

Parallelization strategy and task labeling.

Attributes

Returns

The aggregated output for this phase.

Inherited from:
SearcherPhase

Inherited and Abstract methods

def aggregate(matches: Map[EClassRef, IntermediateT]): Seq[MatchT]

Combine per-class results into the phase's output.

Combine per-class results into the phase's output.

Note: matches is keyed by canonical EClassRef. If output requires a specific order, sort keys here before combining.

Value parameters

matches

Map from canonical class ref to that class's IntermediateT.

Attributes

Returns

The whole-graph output of this phase.

Inherited from:
SearcherPhase
def search(call: EClassCall, egraph: EGraphT, input: InputT): IntermediateT

Compute the class-local result for a single e-class.

Compute the class-local result for a single e-class.

Implementations can assume call refers to the class's canonical representative.

Value parameters

call

Canonical e-class handle to search within.

egraph

Immutable e-graph snapshot.

input

Input from the previous phase (or Unit for the first phase).

Attributes

Returns

Class-local result to be consumed by aggregate.

Inherited from:
SearcherPhase