SimpleLanguageMapper

Struct SimpleLanguageMapper 

Source
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§

Source§

impl<L, A> Default for SimpleLanguageMapper<L, A>

Source§

fn default() -> Self

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

impl<L, A, L2, A2> LanguageMapper<L, A> for SimpleLanguageMapper<L2, A2>
where L: Language, A: Analysis<L>, L2: Language + From<L>, A2: Analysis<L2> + From<A>, <L2 as Language>::Discriminant: From<<L as Language>::Discriminant>, <A2 as Analysis<L2>>::Data: From<<A as Analysis<L>>::Data>,

Source§

type L2 = L2

The target language to translate into.
Source§

type A2 = A2

The target analysis to transate into.
Source§

fn map_node(&self, node: L) -> Self::L2

Translate a node of L into a node of L2.
Source§

fn map_discriminant( &self, discriminant: <L as Language>::Discriminant, ) -> <Self::L2 as Language>::Discriminant

Translate L::Discriminant into L2::Discriminant
Source§

fn map_analysis(&self, analysis: A) -> Self::A2

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

fn map_data( &self, data: <A as Analysis<L>>::Data, ) -> <Self::A2 as Analysis<Self::L2>>::Data

Translate A::Data into A2::Data.
Source§

fn map_eclass( &self, src_eclass: EClass<L, A::Data>, ) -> EClass<Self::L2, <Self::A2 as Analysis<Self::L2>>::Data>

Translate an EClass over L into an EClass over L2.
Source§

fn map_egraph(&self, src_egraph: EGraph<L, A>) -> EGraph<Self::L2, Self::A2>

Map an EGraph over L into an EGraph over L2.

Auto Trait Implementations§

§

impl<L2, A2> Freeze for SimpleLanguageMapper<L2, A2>

§

impl<L2, A2> RefUnwindSafe for SimpleLanguageMapper<L2, A2>

§

impl<L2, A2> Send for SimpleLanguageMapper<L2, A2>
where L2: Send, A2: Send,

§

impl<L2, A2> Sync for SimpleLanguageMapper<L2, A2>
where L2: Sync, A2: Sync,

§

impl<L2, A2> Unpin for SimpleLanguageMapper<L2, A2>
where L2: Unpin, A2: Unpin,

§

impl<L2, A2> UnwindSafe for SimpleLanguageMapper<L2, A2>
where L2: UnwindSafe, A2: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.