-
-
Notifications
You must be signed in to change notification settings - Fork 108
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
feat(scala3): WIP working on scala 3 cross compilation. #390. #461
Conversation
brbrown25
commented
Nov 19, 2021
•
edited
Loading
edited
- scala 3 rewrite compiler specific code
@brbrown25 What is the status on this? :) |
I had something come up at work and didn't get to make progress, but next week I have time carved out and will push some updates :) |
👍 |
d6b6adb
to
8b5fe47
Compare
@ahjohannessen I've gotten about as far as I can with this. My understanding of macros is limited so I tried to stumble through. I will say that the only thing remaining is to fix up |
@brbrown25 sbt build definitions are on Scala 2.12, so that is expected. I suppose what is missing is some kind soul that knows Scala 3 macros to step up :) Edit: I meant sbt plugins are only 2.12. |
Yeah I got it about as far as I could understand, it's definitely new and exciting territory! |
@brbrown25 Which macros need porting? |
the following are the things of note. The big one is figuring out the correct imports/way of handling ValDef and Tree. But the things requiring fixing should be isolated to that file and the
|
@brbrown25 Briefly |
Yeah the compiler Api is the hurdle, although tts actually possibly that macros could be used in place of the compiler Api, for this case, but I'm not 100% on that. |
64097c4
to
7030de6
Compare
@brbrown25 This seems interesting tototoshi@6bcb772 |
@ahjohannessen I can pull in those changes and update this probably late this evening for first thing tomorrow! |
My branch is here. https://github.com/tototoshi/twirl/tree/scalameta I think it might be easier to share the source code between scala2 and scala3 using scalameta than using presentation compiler. (I don't know if twirl can depend on scalameta 🤔 ). The main code already can be built in scala3, but the test code not yet. It has tests that confirm the generated codes can be really compiled, so still requires dotty. |
I'm gonna play around with that and I agree if we came remove the presentation compiler piece it should make life a lot easier. |
@tototoshi I merged your work into mine and then tweaked mine to accommodate your scalameta changes, indeed it gets compiler to run the compile stage happily enough. The only piece that remains is updating the CompilerSpec so that the tests pass under all versions. I'll try and look at that today, but feel free to hack around with what's in this, I think we're getting pretty close! |
I have implemented a dotty-based test helper in my working branch to support Scala3. So now it can be built with Scala3, including the tests. And I found another problem. In Scala2, an // Scala 2.13
scala> val a = if (true) 1
val a: AnyVal = 1
scala> val a = if (true) "a"
val a: Any = a // Scala 3
scala> val a = if (true) 1
1 warning found
-- [E129] Potential Issue Warning: ---------------------------------------------
1 |val a = if (true) 1
| ^
|A pure expression does nothing in statement position; you may be omitting necessary parentheses
longer explanation available when compiling with `-explain`
scala> println(a)
() I modified the TwirlParser to interpret the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for you work!
Some minor things need to be addressed.
Also I think you actually didn't run the test on Travis with the correct Scala version... So let's see how that turns out after setting the correct version.
Also, the changes in TwirlParser
look ok to me, I know this needed change because of the if
problem you described, however I hope this is not breaking apps.
Please update the pull request, I may review a second time and after merging, we can release 1.6.0-M2 so people can start testing.
Thanks again!
compiler/src/test/scala-3/play/twirl/compiler/test/Helper.scala
Outdated
Show resolved
Hide resolved
I did some local testing:
here is a screenshot so you see this is highlighted in red: This from twirl/compiler/src/test/scala/play/twirl/compiler/test/CompilerSpec.scala Lines 174 to 180 in 2c064e7
However, it is not a real error, the test passes and the |
I'm away from computer for a few days for family vacation but can look into n it when I return. |
I added a commit to suppress compile errors log. |
@tototoshi I looked at your last commit, however you now suppress logging of compile errors only for tests? Or am I wrong? My idea was to always suppress that errors, not just for the CI tests... It would be also confusing in real apps to see that errors. WDYT? |
@tototoshi thank you! |
@mkurz |
Umm... My understanding may be wrong. sbt-plugin runs on scala2.12 but the compilation of templates should be run on scala3. |
Now I understand the problem. |
I found the cause. When Scala3 is compiled using sbt, compilation errors are reported by this If the https://github.com/sbt/sbt/blob/fedf6af60d86ed39ae9c94161f13a79ffc4494e8/internal/util-interface/src/main/java/xsbti/Problem.java#L21-L28 If I modify the I think I have nothing that I can do In this Twirl repository, and ideally, either or both sbt and Dotty's sbt integration need to be improved. |
@tototoshi, @mkurz I just realized I messed up and didn't update the travis.yml so I've pushed that fix and we should get a clean travis pass on 3.1.1 now. |
Travis not working, closeing/reopening to trigger it... |
@mkurz since we got green builds in Travis do you think we might be ready to merge this soon? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK lets merge. Like said I did some local testing, also tests on CI pass so it looks promising. In case problems occur when can always fix them in upcoming pr/commits.
@tototoshi I saw sbt/zinc#1074 (comment), if you come up with a fix let us know.
I am too tired now, but I can release 1.6.0-M2 this week so people can play around with it, also to upgrade in other projects like Play to see if we trigger some other bugs.
Opened #498 to keep track of the Scala 3/sourcePositionMapper problem |
This causes If someone has time to look into that, I would appreciate it, thanks! |