-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Support tuple specialization #11114
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
Comments
Hi, not exactly related to this issue but the JVM will be getting state of the art support for fine grained specialization as is described in this paper - > However it won't be available until >= OpenJDK 18 |
Gaetan Schwartz (@gaetschwartz) would like to take this on as a Bachelor project. |
Indeed. That is in part why we have not reimplemented We currently use the standard library compiled with Scala 2 to be backward compatible. That version already produces specialized implementations of tuples. We just want to generate code that takes advantage of these specialized classes given that we already have them. |
(Dale and I are working on this and making good progress.) |
We currently support function specialization but not tuple specialization. It would be good to support that as well, so that we are on parity with Scala 2 programs that use the features of the standard library.
Detailed description of the Semester Project
Problem
As an example, if you compile the following:
then decompile it using cfr, you'll see boxing/unboxing between int and Integer in Scala 3 but not in Scala 2, because Scala 2 uses the specialized class
Tuple2$mcII$sp
generated by the Scala 2 compiler from the@specialized
annotaiton on https://github.com/scala/scala/blob/7c7890b0ba5fb5ffa896bfedcab04e1bacc12ae7/src/library/scala/Tuple2.scala#L24 . Because Scala 3 reuses the Scala 2 standard library (the scala-library jar) we don't need to support generating the specialized classes ourselves and can just assume they exist.Note that we already have similar logic for dealing with function specialization which is more complex since users can define their own subclass of FunctionN whereas the TupleN classes are final: https://github.com/lampepfl/dotty/blob/master/compiler/src/dotty/tools/dotc/transform/SpecializeApplyMethods.scala / https://github.com/lampepfl/dotty/blob/master/compiler/src/dotty/tools/dotc/transform/SpecializeFunctions.scala
Solution
The solution is to develop a new miniphase in the compiler that will specialize tuples the same way SpecializeFunctions does it for functions. We can reuse the specialized tuple classes from the Scala 2 standard library as described above.
Roadmap
The text was updated successfully, but these errors were encountered: