Draft
Conversation
This was referenced Aug 20, 2021
|
Is there anyone interested in reviewing this contribution? |
Owner
For sure, but this is still marked as a work in progress. Are there specific areas that you or @Katrix would like early feedback on? I think in many ways the real test of the success or otherwise of this project would be if you can take an existing shapeless 2 using project and build it for Scala 3. I'm not sure what a suitable one would be ... maybe scalacheck-shapeless? |
Contributor
|
looks like CI is busted? |
Collaborator
I think it doesn't run until conflicts are resolved |
Author
|
Currently blocked by scala/scala3#17212 and scala/scala3#24114 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1043
This PR starts the process of porting Shapeless 2 to Scala 3. It moves the code that uses Scala 2 macros to it's own Scala 2 specific compilation folder, and re-implements these features where possible with Scala 3 macros and features instead. Where it is not yet possible to port a feature to Scala 3, I have either removed it, moved it to be Scala 2 specific, or left it hanging without an implementation depending on how critical the feature is and what would be needed to support in in Scala 3. What remains is to fix the tests so that they compile for Scala 3, and report bugs to the Scala 3 compiler where they are found. Bellow you can find a finer breakdown of the changes that have been made, and what remains.
The build itself
Scala 2.12 has been dropped, and Scala native has been temporarily disabled until I take a further look at how to enable it for Scala 2.13 only.
This PR uses traits to mix in Scala 2/3 behavior into the objects where this is needed. Where the original type is called
foobar, the mixin with the macro/ported code is calledfoobarScalaCompat. These files can be found in thescala-2andscala-3source directories.Major changes
Here are some of the major changes made while porting Shapeless to Scala 3
Type providers of all sorts have been removed. Think
Union,Witness,Record,HList,Coproduct. To construct records and unions, the type->>has been added as a shorthand forFieldTypeThings that transform one method call to another. Think
RecordArgs,FromRecordArgs,NatProductArgs,ProductArgs,FromProductArgs,SingletonProductArgs. These macros generally convert calls to a method into calls to a different method, while manipulating the arguments. For example forRecordArgs,lhs.method(x = 23, y = "foo", z = true)becomeslhs.methodRecord("x" ->> 23 :: "y" ->> "foo", "z" ->> true).Lazyhas been removed in favor of by-name implicits.Strictis no longer needed.Generic,LabelledGenericand friends useMirrorin Scala 3. This severly cuts down on where they can be used. This is something that needs to be implemented later, or fixed in the Scala 3 compiler.NatWithandWitnessWithhave been removed. Where they were used and could not be replaced, a much more restricted version has been introduced instead.Witnesshas been removed in favor of singleton types andValueOf.Unimplemented or broken things in the library
Widencurrently lays unimplemented in Scala 3Generic1currently relies on a typeclassSplitConsthat splits a higher kinded typeH :: TorH :+: Tinto head and tail. This does not seem to be possible to implement currently, and needs this to work Quoting type in a pattern doesn't work with higher-kinded types scala/scala3#10864everywherehas exponential runtime with the depth of the structure used in Scala 3Natmath typeclasses don't want to resolve, supposedly because of diverging implicits. Need to figure out if the fault lies with Shapeless or Scala 3. It would be nice if we could leverage the Scala 3 compiletime ops for faster compilations here as well.Tests
The tests (and examples) are the nr 1 thing why there's still a lot of work to do here. While the tests compile just fine in Scala 2, they fail pretty clearly in Scala 3. Some of this is just stuff that needs fixing. In many other cases however, it's less certain if the error is in the Scala 3 compiler, or in shapeless. Sometimes just poking and (un)inlining pieces of code can fix them, while in other cases there's a lot more work to do. That is where the majority of the work will go to finish this PR.
There is probably around 200 compile errors for the examples and tests combined. As
Natoperations do not currently work (them not working technically falls under this, but I mentioned them above as they affect so much code) that number is likely a bit larger than the true amount of failing code. Each of these compile errors need to be inspected to find out if it's a Scala 3 bug, or a shapeless bug. If it is a shapeless bug, how can it be fixed.From that further big things that need to be fixed might be found.
What actually works
While the above may seem a bit grim, there are still many things that do work. Deriving typeclasses the good old way with
Genericis one of them, and probably the most important one.