egg/
lib.rs

1#![cfg_attr(docsrs, feature(doc_cfg))]
2#![warn(missing_docs)]
3/*!
4
5`egg` (**e**-**g**raphs **g**ood) is a e-graph library optimized for equality saturation.
6
7This is the API documentation.
8
9The [tutorial](tutorials) is a good starting point if you're new to
10e-graphs, equality saturation, or Rust.
11
12The [tests](https://github.com/egraphs-good/egg/tree/main/tests)
13on Github provide some more elaborate examples.
14
15There is also a [paper](https://arxiv.org/abs/2004.03082)
16describing `egg` and some of its technical novelties.
17
18## Logging
19
20Many parts of `egg` dump useful logging info using the [`log`](https://docs.rs/log/) crate.
21The easiest way to see this info is to use the [`env_logger`](https://docs.rs/env_logger/)
22crate in your binary or test.
23The simplest way to enable `env_logger` is to put the following line near the top of your `main`:
24`env_logger::init();`.
25Then, set the environment variable `RUST_LOG=egg=info`, or use `warn` or `debug` instead of info
26for less or more logging.
27
28*/
29#![doc = "## Simple Example\n```"]
30#![doc = include_str!("../tests/simple.rs")]
31#![doc = "\n```"]
32
33mod macros;
34
35#[doc(hidden)]
36pub mod test;
37
38pub mod tutorials;
39
40mod dot;
41mod eclass;
42mod egraph;
43mod explain;
44mod extract;
45mod language;
46#[cfg(feature = "lp")]
47mod lp_extract;
48mod machine;
49mod multipattern;
50mod pattern;
51mod rewrite;
52mod run;
53mod subst;
54mod unionfind;
55mod util;
56
57/// A key to identify [`EClass`]es within an
58/// [`EGraph`].
59#[derive(Clone, Copy, Default, Ord, PartialOrd, Eq, PartialEq, Hash)]
60#[cfg_attr(feature = "serde-1", derive(serde::Serialize, serde::Deserialize))]
61#[cfg_attr(feature = "serde-1", serde(transparent))]
62pub struct Id(u32);
63
64impl From<usize> for Id {
65    fn from(n: usize) -> Id {
66        Id(n as u32)
67    }
68}
69
70impl From<Id> for usize {
71    fn from(id: Id) -> usize {
72        id.0 as usize
73    }
74}
75
76impl std::fmt::Debug for Id {
77    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
78        write!(f, "{}", self.0)
79    }
80}
81
82impl std::fmt::Display for Id {
83    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
84        write!(f, "{}", self.0)
85    }
86}
87
88pub(crate) use {explain::Explain, unionfind::UnionFind};
89
90pub use {
91    dot::Dot,
92    eclass::EClass,
93    egraph::{EGraph, LanguageMapper, SimpleLanguageMapper},
94    explain::{
95        Explanation, FlatExplanation, FlatTerm, Justification, TreeExplanation, TreeTerm,
96        UnionEqualities,
97    },
98    extract::*,
99    language::*,
100    multipattern::*,
101    pattern::{ENodeOrVar, Pattern, PatternAst, SearchMatches},
102    rewrite::{Applier, Condition, ConditionEqual, ConditionalApplier, Rewrite, Searcher},
103    run::*,
104    subst::{Subst, Var},
105    util::*,
106};
107
108#[cfg(feature = "lp")]
109pub use lp_extract::*;
110
111#[cfg(test)]
112fn init_logger() {
113    let _ = env_logger::builder().is_test(true).try_init();
114}