pub struct SimpleLanguageMapper<L2, A2> { /* private fields */ }
Expand description

An implementation of LanguageMapper that can convert an EGraph over one language into an EGraph over a different language in common cases.

Specifically, you can use this if have conversion implemented between your source and target language, as well as your source and target analysis.

Here is an example of how to use this. Consider a case where you have a newtype wrapper over an existing language type:

use egg::*;

#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
struct MyLang(SymbolLang);

// some external library function
pub fn external(egraph: EGraph<SymbolLang, ()>) { }

fn do_thing(egraph: EGraph<MyLang, ()>) {
  // how do I call external?
  external(todo!())
}

By providing an implementation of From<MyLang> for SymbolLang, we can construct SimpleLanguageMapper and use it to translate our EGraph into the right type.

impl From<MyLang> for SymbolLang {
    fn from(value: MyLang) -> Self {
        value.0
    }
}

fn do_thing(egraph: EGraph<MyLang, ()>) {
    external(SimpleLanguageMapper::default().map_egraph(egraph))
}

Note that we do not need to provide any conversion for the analysis, because it is the same in both source and target e-graphs.

Trait Implementations

Returns the “default value” for a type. Read more

The target language to translate into.

The target analysis to transate into.

Translate a node of L into a node of L2.

Translate L::Discriminant into L2::Discriminant

Translate an analysis of type A into an analysis of A2.

Translate A::Data into A2::Data.

Translate an EClass over L into an EClass over L2.

Map an EGraph over L into an EGraph over L2.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.