-
Notifications
You must be signed in to change notification settings - Fork 532
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
Improve derivation support for recursive ADTs #2187
base: series/0.14.x
Are you sure you want to change the base?
Conversation
modules/core/shared/src/main/scala-3/io/circe/derivation/ConfiguredDecoder.scala
Show resolved
Hide resolved
modules/core/shared/src/main/scala-3/io/circe/derivation/ConfiguredEncoder.scala
Show resolved
Hide resolved
Codecov ReportPatch coverage has no change and project coverage change:
❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the GitHub App Integration for your organization. Read more. Additional details and impacted files@@ Coverage Diff @@
## series/0.14.x #2187 +/- ##
=================================================
+ Coverage 84.84% 84.87% +0.03%
=================================================
Files 76 76
Lines 2731 2731
Branches 371 374 +3
=================================================
+ Hits 2317 2318 +1
+ Misses 414 413 -1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
@MartinHH, Looks like even if we get the compiler to generate these codecs at compile time, we will have a runtime issue with trees of sufficient size blowing up the stack. I pushed some test changes to limit the test size so we can address this later, but on my machine i could upwards of 10,000 depth fine... in CI that number is much smaller, making me somewhat concerned about the real world limits. As it stands right now, users will be forced to do something other than derivation, which i think is better than merging this right now and possibly getting a stack overflow at runtime. If we still wanted to get this in, we need to change the way the encoder/decoder works to be more like Defer/Fix #2123 or some other trick to trampoline on the stack rather than blow it up. |
Not trying to talk you into merging this (I really don't mind as I wasn't planning to use this), but it might be worth pointing out that the following already compiles (resulting in a similarly unsafe codec):
This as well:
|
On the one hand, I cannot wait for this aspect of circe in Scala 3 to be improved (and I am saddened by the lack of activity for almost 2 months), but I think this is the right place to point out a weird peculiarity which may be worth considering before merging anything. @MartinHH mentioned, that derivation for his import io.circe.Codec
sealed trait Tree
case class Branch(l: Tree, r: Tree) extends Tree
case object Leaf extends Tree
given Codec[Tree] = Codec.AsObject.derived[Tree] the following doesn't: import io.circe.Codec
sealed trait Tree
case class Branch(l: Tree, r: Tree) extends Tree
case object Leaf extends Tree
case class TreeWrapper(tree: Tree)
given Codec[TreeWrapper] = Codec.AsObject.derived[TreeWrapper] The latter piece of code fails to compile with the infamous |
Fixes #2101