Skip to content
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

Fix ScalaSigReader to make it work with Scala 3 #1460

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

jchyb
Copy link

@jchyb jchyb commented Apr 28, 2024

Hello!
This PR attempts to fix #1035 by replacing the unsupported scalap dependency with
with runtime multi-staging programming, which allows us to read the `.tasty`` files on runtime. Most of the tests are reenabled for scala 3, as they should pass with the new implementation.
Solution based on https://github.com/talenteca/olon-web-framework/blob/session-10/olon-json/src/main/scala/olon/json/Scala3Sig.scala

One caveat - I do not know if the performance of this solution will be satisfactory. We have to create a compiler instance for every ScalaSig function call, as the Compiler instance cannot work in a multithreaded context. This Compiler instance only does light operations like reading the .tasty files, what I am worried about here is the continuous instancing.

Another caveat - library users will have to add additional dependency manually onto the classpath (it will be set as provided here), allowing multi staging compilation. This is because the tasty format is not forward compatible, and what we need to read depends on which version of the compiler the user used. I understand that this would be a big change (possibly requiring some mention in the docs and a version bump?).

Last caveat - older scala 3 versions (including LTS) have some problems with java reflection (scala/scala3#20263), which is used elsewhere (as in not in ScalaSigReader) in this project, which caused some issues with the tests. One solution is to upgrade the scala version used here, but a better one would be to keep the scala version as LTS, and only upgrade the scala version used to compile the tests. This will add some complexity to the build (and may need to also be mentioned in the docs).

Things left to do:

  • try to make tests with lazy vals pass - this is a bit difficult to do, so I will not be ableto get it to work in this PR
  • try to make tests with ReflectorSpec tests pass
  • setup the build to compile in LTS, but run the tests in a newer version (3.4.1)

Please let me know what you think about this fix.

given staging.Compiler = staging.Compiler.make(this.getClass.getClassLoader)

val nameWithSymbols =
name.replace("$minus", "-").replace("$hash", "#").replace("$bang", "!").replace("$plus", "+").replace("$percent", "%").replace("$at", "@")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

jchyb added 2 commits May 8, 2024 13:09
For scala 3, we replace the scalap dependency (which is not supported
for scala 3) with multi-staging compilation, which allows us to read the
`.tasty`` files on runtime. Most of the tests are reenabled for scala 3,
as they should pass with the new implementation.
@jchyb jchyb marked this pull request as ready for review May 15, 2024 16:18
@jchyb
Copy link
Author

jchyb commented May 15, 2024

Hello! I added the changes to the build with different scala version as promised in the PR message. I tried to add a comment with the reasoning for it in the related code. The scalafmt check should also work now, so hopefully it will pass the CI this time

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Extraction fails with Scala 3 ("Can't find ScalaSig")
2 participants