-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Use class wrappers instead of objects in the REPL for better serialization ? #5135
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
Comments
One corner case pointed out in https://issues.scala-lang.org/browse/SI-7747 is that you can't define nested value classes. |
Other than that, it's mostly inertia that's keeping the default in place AFAIK. |
@alexarchambault How does the ammonite repl handle value classes ? |
It just doesn't handle them as is when class-wrapping is enabled (which is not the default). Users can still force wrapping stuff in singletons if the code consists of a singleton too. Like @ case class Foo(s: String) extends AnyVal fails, but @ object Defs {
case class Foo(s: String) extends AnyVal
} is ok, as the latter will itself be wrapped in a singleton. |
maybe we just need class-wrapping to be turned off when the expression defined contains a value class. |
Just discussed with @allanrenucci: one can't define macros if everything is wrapped in classes (in scala 2.x at least, AFAIK). Hence the special-case for singletons above. |
To recap (and let me know if I've left out something), the issue with object wrappers is that deserializing them does not actually deserialize the value of their fields, it just returns the singleton instance of the object class. This is problematic when computing these fields are expensive, and serialized instances are sent over the wire (e.g., Spark). Class wrappers solve this issue but introduce their own problems which don't seem trivial to work around. So how about simply making object wrappers do what we want ? I see two ways to achieve this:
/cc @retronym who's worked on serialization for objects recently |
As suggested by @alexarchambault, see com-lihaoyi/Ammonite#736.
Scala 2 also has
-Yrepl-class-based
to accomplish something similar but it's not the default. @adriaanm are there known issues with-Yrepl-class-based
that prevent it from being the default ?The text was updated successfully, but these errors were encountered: