-
-
Notifications
You must be signed in to change notification settings - Fork 99
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
Derivation of codecs with Dotty (Scala 3) #236
Comments
As Scala 3 RC1 is out Thx for the update! |
@domdorn Hi, Dominik! Moving of jsoniter-scala-macros API calls to the separate module in your project is a great idea. It seems that Moreover, in Scala 3 macros I haven't found an ability to pass a parameter which is more complex than a literal and can be used as a value in the compile time. |
Quick update:
so at the moment, I'm able to use jsoniter-scala, but its quite a PITA and I basically have to have a migration-utility in my web-module that translates from the web-only domain classes to those of the system (which is normal, except that I usually have some classes that are shared amongst all layers, e.g. CorrelationId, UserId, ... ) I looked up the Evals.eval and looked through the code.. it is just used two times and - from my understanding - only for two very special cases
If I'm right, number (2) could be overcome, if the function is in a different compilation-unit, right? If I'm right with this, could we maybe have a proof of concept of the macros with those two (or one) feature missing, and the rest already works? |
I think that using only literal constants for compile-time configuration is a great start point of derivation module for Scala 3. Moreover MVP can be done for the default compile-time configuration. BTW, in most cases configuration of name translation functions can be predefined in some enums. |
Core API is available for Scala 3 since v2.10.3. |
<3 will try it on one of my services asap! |
@domdorn BTW, some clever functions from the Macro API can be used with Scala 3, like here: https://scastie.scala-lang.org/g4WW4LhiQqSk61ZOkfNFhw |
I'm a little confused now.. you say the core-api is scala3 ready, the macros are not.. could u share a sample how I'd make a codec for e.g.
? |
hmm... my coworkers are going to be very upset if I commit this kind of code into our repos.. looks like we have to wait for the macros then :/ |
Here: https://github.com/rssh/jsoniter-scala/tree/scala3 I make it compiled but not yet run. Note, that this attempt was porting with minimal changes, I have not tried to improve code organization. Possible local next step -- look at the first errors in the tests compilation logs
, extract this error into small reproducible examples and submit it to the dotty team or discover our own bug. repeat. I think, porting existing code is possible but time-consuming [i.e. marathon, not sprint]. (I'm not sure that I can allocate an appropriate time budget for this, but maybe somebody can start from that point. Only one thing, which is used in current macros and has no direct analog in dotty is access to the default values of primary constructors. (see scala/scala3#14078 ), eventually, it is possible to extend the tasty reflection API. Also, I'm not sure that the current approach is ideal -- maybe better to write derivation from scratch, (not checked this, an idea to write all derivation inside some trait from which an instance of configuration is accessible). In any case, It would be good to see branch 'scala3-experiment' here. (and maybe create a new subproject to explore dotty-only derivation) |
@rssh Hi, Ruslan! |
awesome work @rssh ! |
@domdorn Yes, you can! It is available on the Maven Central. Please try and send your feedback. |
Currently jsoniter-scala uses some features of experimental Scala 2 macros which are not ported to Scala 3. They are described in the following PR to the Scala Migration Guide.
Two possible solutions:
Evals.eval
to Scala 3Evals.eval
calls and refactor jsoniter-scala-core implementation to avoideval.eval
calls (see dependency onexpression-evaluator
).The text was updated successfully, but these errors were encountered: