Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Translate between EGraph types #306

Merged
merged 5 commits into from
Mar 21, 2024
Merged

Conversation

sgpthomas
Copy link
Contributor

Addresses issue #305.

I use some pretty complicated trait bounds in the EGraph::map function to handle converting between analyses. If the analysis stays the same (EGraph<L, T> -> EGraph<L2, T>) these are automatically implemented which makes it more convenient to use in what I imagine is the common case. However, let me know if you think the conversion should be explicitly handled with a passed in closure.

@mwillsey
Copy link
Member

Here's an alternative idea that might ease some of the trait bounds, and it would make things a little more flexbile than requiring From. Make LangMapper a trait or something:

trait LangMapper<L, A> {
  type L2: Language;
  type A2: Analysis<Self::L2>;
  fn map_node(&self, node: L) -> Self::L2;
  fn map_analysis(&self, ...)  {
    // should maybe be able to provide a default impl?
  }
  fn map_egraph(&self, egraph: EGraph<L, A>) -> EGraph<L2, A2>
}

If you wanted to go crazy, those methods could all take in the src and dst egraphs? What do you think?

@sgpthomas
Copy link
Contributor Author

I liked that idea and implemented it. I couldn't figure out a nice way to provide default implementations in the LanguageMapper trait, so I wrote a SimpleLanguageMapper struct that provides a LanguageMapper implementation when there are the necessary From<..> impls. Those type constraints are still pretty gnarly, but they aren't on the default interface. Let me know what you think of that.

@mwillsey
Copy link
Member

Looks good to me! Thanks for the contribution. Seems like some doctests are failing. Could you patch that up? Try cargo test --doc. Btw make test does everything the CI does.

@sgpthomas
Copy link
Contributor Author

Okay, should be good to go

@mwillsey mwillsey merged commit ec37e2f into egraphs-good:main Mar 21, 2024
2 checks passed
@mwillsey
Copy link
Member

Thanks for the contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants