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

Is it possible to use semi-auto with recursive structures? #463

Open
jducoeur opened this issue Apr 10, 2024 · 6 comments
Open

Is it possible to use semi-auto with recursive structures? #463

jducoeur opened this issue Apr 10, 2024 · 6 comments

Comments

@jducoeur
Copy link

(Phrasing this as a question, because I don't know if this is already possible, or whether this is an enhancement suggestion.)

Given this trivial code:

sealed trait T

case class Ts(ts: List[T]) extends T

I can use full auto to derive a Diff, but it's extremely slow. I would like to be able to use semi-auto, to bring down compilation time, like this:

implicit val tdiff = Diff.derived[T]

but that fails with complaints from Magnolia, and I can't for the life of me find a variation that gets past them. I've tried spelling out various combinations of explicit derived calls, using low-priority traits and all, but each one trips up on the Magnolia macros.

(My actual use case is much, much more complex -- nested sealed traits with various recursive sub-classes -- but this seems to be the nub of the issue: I can't even figure out how to get past the starting line here.)

I really like Diffx, and would like to use it, but the compilation time for auto-derivation is problematic enough (presumably because of the complexity of the structure) that it may turn into a blocker for us. So I'm hoping that there's a way to make semi-auto work for recursive structures.

@ghostbuster91
Copy link
Collaborator

Hi,
As far as I remember this should just work.

Below seems to work for me (for all supported scala versions):

sealed trait T

object T {
  implicit val tdiff: Diff[T] = Diff.derived[T]
}

case class Ts(ts: List[T]) extends T

It seems that specifying variable type is sufficient to make magnolia macro happy. Let me know if this also helps in your case.

btw. I am going to put diffx into a maintenance mode soon (I should've done this long time ago). I don't have time and energy to maintain this project anymore, and there is quite a good alternative for it - https://github.com/jatcwang/difflicious

@jducoeur
Copy link
Author

It seems that specifying variable type is sufficient to make magnolia macro happy. Let me know if this also helps in your case.

Huh -- I thought I had tried that, but maybe not. I'll give that a try -- thanks!

btw. I am going to put diffx into a maintenance mode soon (I should've done this long time ago). I don't have time and energy to maintain this project anymore, and there is quite a good alternative for it - https://github.com/jatcwang/difflicious

Ahhh -- okay, that's good to know now. I'm in the process of spinning up a major new test harness at work, but am only a little ways into using Diffx (I just hit a particularly complex comparison problem yesterday), so it sounds like I should try to pivot to difficilious. Thanks for the heads-up!

@adamw
Copy link
Member

adamw commented Apr 11, 2024

@ghostbuster91 maybe I'll archive the project then? would be great to see it going, but resources are limited

@jducoeur
Copy link
Author

@adamw If you do so, please leave a prominent forwarding pointer at the docs location (and in the README) to diffilicious -- it's enormously helpful for us users to have the recommendation for an alternative.

@ghostbuster91
Copy link
Collaborator

ghostbuster91 commented Apr 11, 2024

@adamw I decided to wait with it till the end of the year to give users time to migrate and to give us a chance to merge & release any bugfixes that might be contributed.

@jducoeur I already added a link to difflicious to the readme, but good point with adding it also to the documentation 👍

@adamw
Copy link
Member

adamw commented Apr 14, 2024

@ghostbuster91 makes sense, thanks :)

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

No branches or pull requests

3 participants