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
Getting started with Scala 3 #81
Conversation
@@ -37,7 +37,7 @@ object JsonPointerVisitor { | |||
* Compared to something like a List[String] or List[Object], this does not require | |||
* extra String allocation or boxing unless we actually ask for the path. | |||
*/ | |||
private trait HasPath { | |||
trait HasPath { // Scala 3 needs this to be public -- doesn't break bin compat |
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.
Why does scala 3 need 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.
I'm actually surprised that Scala 2 let the private class leak out in a public constructor, but it did. And this is one place where the weird rules of bin compat work in our favor: technically changing something from private to public should affect bin compat, but Scala generates these as public interfaces in the bytecode, so from Mima perspective, it was already public. (Which is why, I think, it is hard to lock Scala bin compat down even by making everything private, because the compiler often winds up exposing private things as public.)
...JsonPointerVisitor.scala:97:32
[error] 97 |private class JsonPointerVisitor[T, J](
[error] | ^
[error] |non-private constructor JsonPointerVisitor in class JsonPointerVisitor refers to private trait HasPath
[error] |in its type signature [T, J]
[error] | (delegate: com.rallyhealth.weepickle.v1.core.Visitor[T, J], parentPath:
[error] | com.rallyhealth.weepickle.v1.core.JsonPointerVisitor.HasPath
[error] | ): com.rallyhealth.weepickle.v1.core.JsonPointerVisitor[T, J]
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.
On second thought... TIL that you can mark the default constructor as private, which is apparently not the default for a private class (weird that it isn't -- seems like a bug). Anyway, this allows HasPath
to remain private and makes both Scala 2 and 3 happy. See latest commit.
@@ -215,7 +215,7 @@ object Obj { | |||
implicit def from(items: TraversableOnce[(String, Value)]): Obj = { | |||
val initialCapacity = items match { | |||
case is: mutable.IndexedSeq[_] => is.size | |||
case _ => 2 | |||
case _ => 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.
not that it's going to affect anything, but this whitespace change is a bit nutty.
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.
removed
Optimize macroFrom[T].
Fix ExponentialTest
Add BlackholeVisitor, jvm options
Add macro tests for changing default params
weepickle-implicits/src/main/scala/com/rallyhealth/weepickle/v1/implicits/DefaultFroms.scala
Outdated
Show resolved
Hide resolved
Remove allocation noise from BlackholeVisitor
weejson-play/src/main/scala/com/rallyhealth/weejson/v1/play/PlayJson.scala
Outdated
Show resolved
Hide resolved
weejson-play/src/main/scala/com/rallyhealth/weejson/v1/play/PlayJson.scala
Outdated
Show resolved
Hide resolved
weepickle-implicits/src/main/scala-3/com/rallyhealth/weepickle/v1/implicits/CaseClassFrom.scala
Outdated
Show resolved
Hide resolved
weepickle-implicits/src/main/scala-3/com/rallyhealth/weepickle/v1/implicits/CaseClassTo.scala
Outdated
Show resolved
Hide resolved
weepickle-core/src/main/scala/com/rallyhealth/weepickle/v1/core/Types.scala
Outdated
Show resolved
Hide resolved
weepickle-implicits/src/main/scala-3/com/rallyhealth/weepickle/v1/implicits/CaseClassTo.scala
Outdated
Show resolved
Hide resolved
weepickle-implicits/src/main/scala-3/com/rallyhealth/weepickle/v1/implicits/CaseClassTo.scala
Show resolved
Hide resolved
weepickle-implicits/src/main/scala-3/com/rallyhealth/weepickle/v1/implicits/CaseClassTo.scala
Outdated
Show resolved
Hide resolved
import deriving._, compiletime._ | ||
|
||
inline def getDefaultParams[T]: String => Option[() => AnyRef] = ${ getDefaultParmasImpl[T] } | ||
def getDefaultParmasImpl[T](using Quotes, Type[T]): Expr[String => Option[() => AnyRef]] = |
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.
Minor detail (currently catching up), but while I notice it: getDefaultParmasImpl
-> getDefaultParamsImpl
.
Only have common code between Scala 2 and 3 when Scala 2 libs can maintain binary compatibility. Any non-passing tests are commented out in the scala-3 source paths (same as in uPickle, e.g., AdvancedTests). Macros are based on uPickle macros with WeePickle-specific features like custom discriminator names, default-dropping behavior, special handling for Option defaults, and "Nullable" To's.
There are still many TODOs, no benchmarks, etc. So this PR is really just the beginning.