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>
impl<L, A> Default for SimpleLanguageMapper<L, A>
Source§impl<L, A, L2, A2> LanguageMapper<L, A> for SimpleLanguageMapper<L2, A2>
impl<L, A, L2, A2> LanguageMapper<L, A> for SimpleLanguageMapper<L2, A2>
Source§fn map_discriminant(
&self,
discriminant: <L as Language>::Discriminant,
) -> <Self::L2 as Language>::Discriminant
fn map_discriminant( &self, discriminant: <L as Language>::Discriminant, ) -> <Self::L2 as Language>::Discriminant
Translate
L::Discriminant into L2::DiscriminantSource§fn map_analysis(&self, analysis: A) -> Self::A2
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
fn map_data( &self, data: <A as Analysis<L>>::Data, ) -> <Self::A2 as Analysis<Self::L2>>::Data
Translate
A::Data into A2::Data.Auto Trait Implementations§
impl<L2, A2> Freeze for SimpleLanguageMapper<L2, A2>
impl<L2, A2> RefUnwindSafe for SimpleLanguageMapper<L2, A2>where
L2: RefUnwindSafe,
A2: RefUnwindSafe,
impl<L2, A2> Send for SimpleLanguageMapper<L2, A2>
impl<L2, A2> Sync for SimpleLanguageMapper<L2, A2>
impl<L2, A2> Unpin for SimpleLanguageMapper<L2, A2>
impl<L2, A2> UnwindSafe for SimpleLanguageMapper<L2, A2>where
L2: UnwindSafe,
A2: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more