chomsky-extract
Optimal program extraction from E-Graphs for the Chomsky framework.
Overview
After chomsky-rule-engine has expanded the E-Graph with equivalent forms and chomsky-cost has assigned costs, chomsky-extract is responsible for selecting the "best" representative program. It finds the lowest-cost tree from the complex cyclic E-Graph structure.
Features
- Optimal Extraction: Uses a greedy but effective extraction algorithm to find the lowest-cost
IKunTreefor a given E-Class. - Backend Trait: Defines the standard interface for all backends that consume extracted trees and produce artifacts (source, binary, or assembly).
- Artifact Management: Supports multiple output formats via
BackendArtifact, including binary blobs, source strings, and collections of files. - Recursive Reconstruction: Efficiently reconstructs the program tree while respecting the cost-based decisions.
Core Concepts
IKunExtractor
The main engine for extraction. It:
- Calculates the best cost for every E-Class in the graph based on a
CostModel. - Recursively selects the best nodes to form an
IKunTree.
Backend
The interface for code generation. A backend provides:
- A
name. - A
generatemethod to transform anIKunTreeinto aBackendArtifact. - A target-specific
CostModel.
Usage
use IKunExtractor;
use DefaultCostModel;
use EGraph;
let egraph = new;
// ... fill egraph ...
let extractor = new;
let best_tree = extractor.extract;