Closed sageserpent-open closed 2 years ago
Good news - as of commit b68521a2d8077e81d2dfa9c009683e999dd2184d we have something that builds on Scala 3 and passes its tests.
Casualties incurred:
Magnolia
generation has changed completely in Scala 3, because the underlying macro technology is completely different. It's not enough to merely upgrade the library dependency on Software Mill's distribution of Magnolia, the code using it needs to be overhauled. I'm not sure whether to hive off two separate repositories for this - one for Scala 2.13 and one for Scala 3, or to maintain separate source trees in the existing project, or to have two projects in the existing repository that build artifacts for Scala 2.13 and Scala 3. Needs mulling over...Other than that, while it's a pain rewriting the code to satisfy the nitpicking that comes with Scala 3, the results look OK.
On with the show...
Pull request here for the sake of seeing the impact: #35 .
More good news - the Java API has been restored, and mixed-mode is still in use. The fixes were mostly:
Trials
interface/trait; this avoids the confusion the Scala 3 compiler experienced previously when trying to compile these side by side in TrialsImplementation
.TrialsApi.alternate
for the Java version - without this the Scala 3 compiler goes into some kind of panic about hygiene, repeating the same gibberish at increasingly large constructs surrounding that original site of the problem.Trials.choose
. This was written to sidestep various ongoing bugs / weirdness in how a Scala allows a Java varargs method to be overridden - there has been several fixes in the Scala 2 compiler series for this, but it seems that a much simpler approach of providing two separate overloads in two mix-in traits with some use of _ <: AnyRef
as a type parameter were enough to sort this out. I'm hoping this can be back-ported against Scala 2, as it looks a lot cleaner and allows IntelliJ to deduce that the overrides really are just that - navigation to the overridden definitions was previously broken.Other than that, there was nothing major that springs to mind, other than a lot of repeated partial reversions of the commits that pulled out the Java support and test for it.
That leaves the Magnolia work to be reinstated / rewritten - I think this should be via distinct source trees for Scala 2 and Scala 3 contributing the same old americium
artifact in a cross-build SBT project.
The Magnolia support has been reinstated, but a) doesn't support derivation of Factory
for parameter types that are recursively defined - this is a known issue with the Scala 3 branch of Magnolia at time of writing. Furthermore, attempting to compile code that triggers automatic derivation in such a case causes the Scala 3.1.1 compiler to fault with an assertion failure.
Nevertheless, it looks like this port has been a success overall, so it is being merged into work for cross building in issue #36 .
This issue will be left open as a place to document work on minimizing the Scala compiler fault in the meantime.
The bug mentioned above is documented here: https://github.com/lampepfl/dotty/issues/13406 and fixed by https://github.com/lampepfl/dotty/pull/14405 . This has gone out in Scala 3.1.2, so time to upgrade and re-release...
As of release 1.3.3, commit SHA 7e7e52c42e3520f0c9b573a88a0a737eae4380e1 , we have a release for Scala 2.13.8 and 3.1.2 . The test to show automatic derivation of a Trials
for recursively defined types has been reinstated for Scala 3, it exists as a near duplicate of the one for Scala 2.13 - there is a wrinkle for the Scala 3 support that requires the use site for the automatically generated implicit to be captured in an, ahem, 'explicit' implicit definition. This isn't required for generation of Trials
for types that are not recursively defined, so the test for that situation can be left as cross-version shared source.
They said that 'perfect as the enemy of the good', so on that note I'm closing this ticket.
Following on from issue #13, this spike is to capture ongoing attempts to port to Scala 3 in a structured way.
Casual attempts made previously have all ground to a halt, if this requires help or advice from others, it would be good to systematically capture the problems against commits, or maybe to provide minimised problem cases.