-
Notifications
You must be signed in to change notification settings - Fork 149
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
Mix scala 2 and 3 macros #395
base: master
Are you sure you want to change the base?
Conversation
Scala 2 macros can be compiled in scala 3 only if they do not use reification or quasiquotes
Thanks for the PR but can you please add a description for this that explains why we want this? |
@lloydmeta ah, thanks for taking a look. I've updated the description to clarify what's going on. |
@lloydmeta thanks for your patience with this. I just updated things again to hopefully resolve the build failures. I can't remember, were you manually triggering builds? |
Yea... I think I set something up once that requires me to approve the CI runs 🤦♂️ |
Codecov ReportAll modified and coverable lines are covered by tests ✅
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. Additional details and impacted files@@ Coverage Diff @@
## master #395 +/- ##
==========================================
- Coverage 85.71% 85.30% -0.41%
==========================================
Files 63 65 +2
Lines 511 599 +88
Branches 34 51 +17
==========================================
+ Hits 438 511 +73
- Misses 73 88 +15 ☔ View full report in Codecov by Sentry. |
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 doing this.
There are quite a lot of changes that do not feel necessary, some of which are IMO a step backwards. My request would be to remove any changes that are not absolutely necessary.
.github/workflows/ci.yml
Outdated
- java: 11 | ||
scala: 3.3.0 | ||
scala: 3.4.0 |
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.
This is not an LTS release. Let's revert this.
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.
Unfortunately, this PR won't work with scala < 3.4 because of scala/scala3#16630
They mentioned backporting to 3.3.1-RC1 but seems like that never happened. It was also mentioned briefly here: #300 (comment)
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.
Understood. That is a blocker indeed.
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.
Makes sense. I tested this out using scala 3.3.4-RC4 and it does build succesfully with that version. So once 3.3.4 gets released I'll udpate this PR.
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.
this is fixed now. 3.3.4 was released.
.scalafmt.conf
Outdated
@@ -1,4 +1,4 @@ | |||
version = 3.7.8 | |||
version = 3.7.17 |
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.
Was this needed?
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.
Seems like no, I'll revert.
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.
reverted
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 changed this to 3.7.10 because without that update, in sbt ++3.3.4 test:compile
fails with:
[error] (coreJS / Compile / scalafmt) org.scalafmt.sbt.ScalafmtSbtReporter$ScalafmtSbtError: scalafmt: /home/gregg/lucid/enumeratum/enumeratum-core/src/main/scala-3/enumeratum/EnumCompat.scala:14: error: [dialect scala3] pattern must be a value or have parens: EnumMacros.findValuesImpl[A]
[error] protected inline def findValues: IndexedSeq[A] = ${ EnumMacros.findValuesImpl[A] }
[error] ^ [/home/gregg/lucid/enumeratum/enumeratum-core/src/main/scala-3/enumeratum/EnumCompat.scala]
there and a few other places.
build.sbt
Outdated
lazy val scala_2_13Version = "2.13.11" | ||
lazy val scala_3Version = "3.3.0" | ||
lazy val scala_2_13Version = "2.13.13" | ||
lazy val scala_3Version = "3.4.0" |
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.
Please revert.
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.
reverted
"org.scala-lang" %% "scala3-compiler" % scalaVersion.value % Provided | ||
Seq( | ||
"org.scala-lang" %% "scala3-compiler" % scalaVersion.value % Provided, | ||
"org.scala-lang" % "scala-reflect" % scala_2_13Version, |
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.
Curious if there's a way to make this additional dependency
- Contingent on actually using the mix mode macro
- Only a compile time constraint?
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.
Unfortunately I think only the consumer of the library knows if the mixed mode macro is being used, from here, sbt only knows that it's a scala3 build.
I believe we could mark this as Provided
too, but then all consumers would need to explicitly provide it. Marking it provided here means I also need to add it as Provided in core
. It would only need to be added as a normal/runtime dep if the project was using the mixed mode because I think this is only needed for the scala 2 portion of the build.
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.
@lloydmeta let me know if you have a preference here.
@@ -685,7 +688,7 @@ lazy val compilerSettings = Seq( | |||
|
|||
val base = { | |||
if (scalaBinaryVersion.value == "3") { | |||
minimal :+ "-deprecation" | |||
minimal :+ "-Wconf:cat=deprecation:s" |
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.
Curious why this was needed?
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.
[error] -- Error: /home/gregg/lucid/enumeratum/macros/src/main/scala/enumeratum/compat/EnumMacros.scala:109:32
[error] 109 | val enclosingModule = c.enclosingClass match {
[error] | ^^^^^^^^^^^^^^^^
[error] |method enclosingClass in trait Enclosures is deprecated since 2.11.0: c.enclosingTree-style APIs are now deprecated; consult the scaladoc for more information
and a few more identical errors
@@ -8,7 +11,8 @@ private[enumeratum] trait EnumCompat[A <: EnumEntry] { _enum: Enum[A] => | |||
* You will want to use this in some way to implement your [[values]] method. In fact, if you | |||
* aren't using this method... why are you even bothering with this lib? | |||
*/ | |||
inline def findValues: IndexedSeq[A] = ${ EnumMacros.findValuesImpl[A] } | |||
protected inline def findValues: IndexedSeq[A] = ${ EnumMacros.findValuesImpl[A] } |
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.
Curious why this is now protected.
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'm not sure. I reverted it.
@@ -19,7 +19,7 @@ trait EnumEntry { | |||
*/ | |||
def entryName: String = stableEntryName | |||
|
|||
private[this] lazy val stableEntryName: String = toString | |||
private lazy val stableEntryName: String = toString |
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.
Was this (and below) removals of this
needed?
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.
the scala 3 build fails without removing these (deprecated feature)
@@ -9,7 +9,7 @@ import play.api.data.{FormError, Mapping, Forms => PlayForms} | |||
*/ | |||
object Forms extends FormsCompat { | |||
|
|||
protected[this] def formatter[ValueType, EntryType <: ValueEnumEntry[ | |||
protected def formatter[ValueType, EntryType <: ValueEnumEntry[ |
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.
?
@@ -10,7 +11,7 @@ object EnumMacros { | |||
|
|||
/** Finds any [A] in the current scope and returns an expression for a list of them | |||
*/ | |||
def findValuesImpl[A: c.WeakTypeTag](c: Context): c.Expr[IndexedSeq[A]] = { | |||
def findValuesImpl[A: c.WeakTypeTag](c: Context): c.Tree = { |
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.
Was this needed? Feels like a step backwards to lose type info, so if it's not required, please revert.
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.
Same question regarding type change for everything here.
This follows the pattern shown here: https://docs.scala-lang.org/scala3/guides/migration/tutorial-macro-mixing.html#:~:text=Introduction,during%20the%20macro%20expansion%20phase
This would allow a mixed scala version project to depend on the scala 3 version of enumeratum and build correctly for both scala 2 modules and scala 3 modules. This is particularly helpful when building with bazel since you can't conditionally include a dependency based on the current scala version the same way you would in sbt.
This was brought up previously by @coreywoodfield here: #300 (comment) (and he is the author of this PR -- I just rebased the branch).