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
Scala 3 support #271
Scala 3 support #271
Conversation
This commit does some preparation work to allow the port to Scala 3 The idea is to move all the code using macros to the `src-2` directory, update the dependencies to the ones supporting Scala 3 ( mill, geny, sourcecode, utest ), avoid depending on `scala-reflect` if it's Scala 3 and fixing the compile errors the Scala 3 compiler gives before reaching the missing macros.
Skip scala-compiler dependency for Scala 3
using instead of implicit seems to work out
Thank you all for managing to get this to the finish line. |
@lihaoyi Thank you for this ❤️ A note about the failing MiMa check: The MiMa check is failing since there are no artifacts yet for Scala 3. diff --git a/build.sc b/build.sc
index c8a1041..f6edab1 100644
--- a/build.sc
+++ b/build.sc
@@ -176,6 +176,7 @@ trait CommonCrossModule extends CrossScalaModule with PublishModule with Mima{
.lastTag
.getOrElse(throw new Exception("Missing last tag"))
)
+ def mimaPreviousArtifacts = if(isScala3(crossScalaVersion)) Agg.empty[Dep] else super.mimaPreviousArtifacts()
def mimaBinaryIssueFilters = super.mimaBinaryIssueFilters() ++ Seq(
ProblemFilter.exclude[IncompatibleResultTypeProblem]("fastparse.Parsed#Failure.unapply")
) This way we can ensure that we are not breaking the binary compatibility for the Scala 2 artifacts. |
@@ -3,7 +3,7 @@ package pythonparse | |||
import utest._ | |||
import fastparse._ | |||
/** | |||
* Tests to cover most basic syntactic constructs. It's likely there are | |||
* Tests to cover most basic syntactic constructs. ItSymbol("s") likely there are |
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.
I feel like this search/replace error was my fault at some point, but someone else fixed it, but now it’s back? 😅
Thank you for taking over @lihaoyi :) |
The tour of Scala says that:
So seems to be fine for the use here. Edit, the doc does consider them as deprecated. But does not mention any strategy for compatibility.
If I remember correctly, the only remaining issue was that there was an overload for |
Looks like bare |
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.
val repeater1 = $repeater | ||
var originalCut = ctx1.cut | ||
val acc = repeater1.initial | ||
@ _root_.scala.annotation.tailrec |
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.
FWIW, you don't need to bother with fully-qualified names in Scala 3 macros, they're hygienic.
import de.tobiasroeser.mill.vcs.version.VcsVersion | ||
import $ivy.`com.github.lolgab::mill-mima::0.0.13` | ||
import com.github.lolgab.mill.mima._ | ||
|
||
val scala31 = "3.1.3" |
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.
Can we get to 3.2.2?
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.
LGTM!
Thanks all who've been involved in making this happen. This is a big deal! Much appreciated!
@lolgab shall we tag a new version now that this is merged? We can perform further optimizations and improvements in follow ups |
We can. |
If it's a new major, we should try to squeeze in more breaking changes if possible. e.g. the whitespace PR I have open is definitey binary incompatible |
… implicit conversions (#272) Fixes #261, which is caused by the whitespace `P[_] => P[Unit]` implicits firing as implicit conversions rather than the implicit parameters they were originally intended to be. Since whitespace is meant to ignore failures, this caused failures caused by the `Fail.! : P[String]` to be ignored when implicitly converted to `P[Unit]` The fix is to create a proper `Whitespace` trait to inherit from. Note that this is a binary incompatible change. It's stacked on top of #271 for convenience, but should probably land separately after. The relevant changes are in this commit d87ab6d if anyone wants to look. Note that I moved the custom whitespace tests to a `scala2.12+` folder to skip them on 2.11. 2.11 does not support SAM conversion, which makes defining custom whitespaces a lot more boilerplatey. Can still be done, but no need to burden everyone with boilerplatey examples just to cater for the 2.11 folks in the test suite. Things are unlikely to break just for 2.11 anyway
All tests pass on Scala 3, on all platforms (JVM/JS/Native), and on all old versions of Scala.
Pulls in a bunch of work by @lolgab (#252) @rmgk (#262) and @ajrnz (#266)
Notable Changes:
fastparse
modules; I don't think we can promise the same stability guarantees for the example parsers.map(Foo)
calls have to become.map(Foo.apply)
,.map(Foo.tupled)
calls have to become(Foo.apply _).tupled
package.scala
for Scala 2 and 3, but splitting out the shared non-macro logic intoSharedPackageDefs.scala
fastparse/src-3/
aggregateMsgInRep
where we were not properly propagating failure stringsthen
has to be back-tickedscala.Symbol
s in PythonParse withString
s_
method in ScalaParse withUnderscore
'foo -
syntax withtest("foo") -
Performance
Performance seems to have taken about a 10% hit in Scala 3. Probably missing out on some optimizations that we do in Scala 2. I'm not super familiar with how scala 3 macros work, clawing back the 10% can come in a follow up PR
Scala 2 Bench
Scala 3 Bench