chimney icon indicating copy to clipboard operation
chimney copied to clipboard

scala 3 support?

Open pjfanning opened this issue 4 years ago • 14 comments

Are there any plans to support Scala 3 or do the changes in Scala 3 make this difficult?

pjfanning avatar Jan 16 '21 10:01 pjfanning

Yes, there are plans of exploring possibilities of how we could support Scala 3.

Chimney heavily depends on Scala 2 macros and compile-time reflection which were discontinued in its current form. In Scala 3 there are new metaprogramming capabilities as well as built in type class derivation available. Brief look suggests there are substitutes for many features that we have depended on so far. But before definite answer to your question, one need to implement PoC that covers minimal feature set of Transformer generation, possibly with support for few user-driven customizations (withFieldComputed etc.). Only after doing this we will know if there are any challenges or blockers that makes current design impossible, or - the opposite - that we will be able to share some core logic between Scala 2/3 implementations.

So far no work has been done in this direction. But as Scala 3 RC1 have been just released, it's probably high time to start some exploration and development :)

krzemin avatar Feb 19 '21 11:02 krzemin

Regarding migration to scala 3.0, I think it should be relatively easy to migrate all of chimney functionality to scala 3, checkout my pet project: https://github.com/wookievx/domain-slices. While usage is different because I was experimenting with my own ideas, I think it should be possible to improve upon my derivation code (that do not uses any macros, only inlines + mirrors) and provide all of the chimney functionality. The only problem I can see is that of exceeding inline limit for large enough structures (in previous versions I was automatically deriving instance recursively and seemed to be unable to opt into providing instances manually to prevent creation of too many anonymous classes, but it should be possible to somehow prioritize existing instances over derived ones).

wookievx avatar Mar 31 '21 16:03 wookievx

Regarding my previous comment, given how much of the actual chimney code are macros (90% or more), it is probably a good idea to re-implement entire model from scratch, I have some of the functionality implemented here: https://github.com/wookievx/domain-slices/tree/chimney-like-poc/chimney-alike/src What I am attempting to do is minimize tasty-reflection to minimum (when it is absolutely necessary like in case of extracting field name from lambda, or in the future to set bean property) and use in-lining + mirrors to implement as much functionality as possible. I don't want to start my own chimney-like library, but I would more then like to help bootstrap chimney (or chimney-like) thing for scala 3.0. For example I replaced custom "hlist-like" configs with tuples+match-type which seems to be working great so far

wookievx avatar Apr 02 '21 17:04 wookievx

Hi @krzemin, do you have a rough roadmap/plan for the Scala 3 support? I skimmed through @wookievx code but I'm not sure how much of the functionality it covers. It looks like it could definitely serve at least as a PoC.

povder avatar Jul 05 '21 01:07 povder

Hi @krzemin @MateuszKubuszok, how do you picture the Scala 3 support for Chimney? Given that it's mostly macros, do you think a new branch would be created with the Scala-3-only version of the lib? I attempted extracting the Scala 2.x code into the dedicated directory but I realized that it probably doesn't make sense as I'm basically extracting all of it.

povder avatar Dec 19 '21 23:12 povder

@povder FYI, I'm trying to adapt @wookievx's scala 3 PoC to be cross-compiled with the mainstream chimney codebase: https://github.com/guersam/chimney/tree/scala3

guersam avatar Dec 21 '21 05:12 guersam

Currently the test doesn't compile in Scala 3 due to https://github.com/lampepfl/dotty/issues/12508. As there are so many local case classes having conflicting name in the tests, I'm considering test framework migration from utest to munit as a workaround.

guersam avatar Dec 21 '21 05:12 guersam

My strategy for source compatibility is to keep the shared types to the bare minimum such as Transformer, TransformerF and Patcher, and check DSL compatibility with the shared test code.

I wonder is how many people are directly relying on the types in io.scalaland.chimney.dsl rather than only the extension methods.

image

guersam avatar Dec 21 '21 05:12 guersam

Thank you for your input. There are some features missing from chimney in scala 3. I am hoping to address some of that during holidays. Regarding cross-compilation, it is tricky as you already discovered. If more than one person is working on this, we might start creating issues for specific functionality:

  • difference in error reporting (I have not found a concrete specification how errors are reported in chimney, my code have a different approach, for example I am not sure how not to sort-circuit transformer derivation on error)
  • java beans support, relatively easy I think I am close to delivering that
  • cross-compilation itself, which is tricky. Again thank you for your work, I want to get back to this, so plan of work might be a good idea

wookievx avatar Dec 21 '21 11:12 wookievx

@wookievx Great :) As I'm not touching chimney3 namespace at all, it will be not that hard to combine our work together so far.

However, there are slight changes in your code pasted under chminey/src/main/scala-3 for compatibility with Scala 2 version. I'll list them up to ask your opinion.

And where do you want to be our temporary upstream for Scala 3? I'd suggest to have scala3 branch in your repo to integrate our works quickly, and then open a draft PR against scalalandio/chimney from it to invite existing chimney users for further discussion.

guersam avatar Dec 23 '21 04:12 guersam

I created a few github issues in my fork (missing/different features, improvements to implementation). Chimney is surprisingly complicated library requiring to specify and implement:

  • how to handle compilation errors
  • how to aggregate runtime errors,
  • type inference in dsl,
  • additional configuration with implicit flags.
  • almost purely macro-based, in some places quite complicated metaprogramming.

I returned to working on my fork, planning to make some improvements, along the lines I made in those mentioned github issues, but I do not have any plans regarding cross-compilation and full compatibility.

wookievx avatar Dec 23 '21 22:12 wookievx

I made a new PoC using Scala 3 compile-time reflection API to improve codegen. More details here: https://github.com/wookievx/chimney/issues/5#issuecomment-1015082986.

kjh618 avatar Jan 18 '22 05:01 kjh618

I am working on new way of derivation in my spare time, current state is here: https://github.com/wookievx/chimney/pull/2, Right now I am working on making the tests pass and to implement Patcher via new mechanism (avoiding indiraction of mirrors in generated code). I will not support conversion to JavaBeans as Scala 3 messes up signatures of java classes for java 11, and I do not want to deal with compatibility issues.

czw., 25 sie 2022 o 18:11 Valentin @.***> napisał(a):

Any progress here so far?

— Reply to this email directly, view it on GitHub https://github.com/scalalandio/chimney/issues/201#issuecomment-1227480742, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACYU2DY3Z6IEPZGJNODLWY3V26LLLANCNFSM4WFFEBZQ . You are receiving this because you were mentioned.Message ID: @.***>

wookievx avatar Aug 26 '22 09:08 wookievx

There appears to be a new lib called Ducktape that is inspired by Chimney and supports Scala 3.

pjfanning avatar Aug 26 '22 22:08 pjfanning

Hey folks,

Trying to address most of the questions in this threads, we do have a plan to migrate Chimney to Scala 3.

Our primary goal is to provide full source/behavioral compatibility between Scala 2 and Scala 3 implementations, which would enable smooth migration of most of the codebases. Certain features like lifted transformers and unsafe options were already deprecated in 0.7.0 and they won't be migrated to Scala 3 (we suggest a migration to partial transformers).

Initial research and several PoC projects (including the ones mentioned in this thread) showed that it's certainly possible to recreate large parts of the library's features, so we can't see any major blockers when it comes to new Scala 3 metaprogramming APIs. On the contrary - we aim to share most of the core logic codebase across the Scala 2/3 metaprogramming platforms.

You can track the progress on scala-3 branch branch and in scala-3 milestone.

MateuszKubuszok avatar Mar 23 '23 11:03 MateuszKubuszok

Initial Scala 3 support published as 0.8.0-M1

MateuszKubuszok avatar Aug 03 '23 21:08 MateuszKubuszok