scalalandio / chimney

Scala library for boilerplate-free, type-safe data transformations
https://chimney.readthedocs.io
Apache License 2.0
1.17k stars 93 forks source link

Scala 3 support #201

Closed pjfanning closed 1 year ago

pjfanning commented 3 years ago

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

krzemin commented 3 years ago

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 :)

wookievx commented 3 years ago

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 commented 3 years ago

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

povder commented 3 years ago

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 commented 2 years ago

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.

guersam commented 2 years ago

@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 commented 2 years ago

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 commented 2 years ago

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

wookievx commented 2 years ago

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:

guersam commented 2 years ago

@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.

wookievx commented 2 years ago

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:

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.

kjh618 commented 2 years ago

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.

wookievx commented 2 years ago

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: @.***>

pjfanning commented 2 years ago

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

MateuszKubuszok commented 1 year ago

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 commented 1 year ago

Initial Scala 3 support published as 0.8.0-M1