Struct egg::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
sourceimpl<L, A> Default for SimpleLanguageMapper<L, A>
impl<L, A> Default for SimpleLanguageMapper<L, A>
sourceimpl<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>,
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>,
type L2 = L2
type L2 = L2
The target language to translate into.
type A2 = A2
type A2 = A2
The target analysis to transate into.
sourcefn 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::Discriminant
sourcefn 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
.
sourcefn 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> RefUnwindSafe for SimpleLanguageMapper<L2, A2> where
A2: RefUnwindSafe,
L2: RefUnwindSafe,
impl<L2, A2> Send for SimpleLanguageMapper<L2, A2> where
A2: Send,
L2: Send,
impl<L2, A2> Sync for SimpleLanguageMapper<L2, A2> where
A2: Sync,
L2: Sync,
impl<L2, A2> Unpin for SimpleLanguageMapper<L2, A2> where
A2: Unpin,
L2: Unpin,
impl<L2, A2> UnwindSafe for SimpleLanguageMapper<L2, A2> where
A2: UnwindSafe,
L2: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more