-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
add readResolve to objects with serializable interface #4450
Conversation
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.
Hello, and thank you for opening this PR! 🎉
All contributors have signed the CLA, thank you! ❤️
Have an awesome day! ☀️
symbolsToSynthesize flatMap syntheticDefIfMissing | ||
val methods = symbolsToSynthesize flatMap syntheticDefIfMissing | ||
|
||
def createReadResolveMethod: 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.
It'd be nice to extract the common code between this method and syntheticDef
in a separate method somehow.
cpy.Template(impl)(body = impl.body ++ syntheticMethods(ctx.owner.asClass)) | ||
def addSyntheticMethods(impl: Template)(implicit ctx: Context) = { | ||
val isSerializableObject = | ||
(ctx.owner.is(Module) |
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.
To match scalac behavior, we should only do this for static objects (that is, objects which are not inside classes or methods), this can be checked using .isStatic
.
val isSerializableObject = | ||
(ctx.owner.is(Module) | ||
&& ctx.owner.derivesFrom(defn.JavaSerializableClass) | ||
&& !ctx.owner.asClass.membersNamed(nme.readResolve).exists) |
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.
We should still emit our readResolve
method if the user declared a readResolve
method with a different signature (e.g. def readResolve(x: Int): AnyRef
). We can filter for methods with (): AnyRef
as signature by doing membersNamed(nme.readResolve).suchThat(_.signature == Signature(defn.AnyRefType, isJava = false)
0072dc2
to
7702780
Compare
If the object implements the serializable interface and not includes the readResolve method then we add it. Since it's an object we reference it to the objects singleton instance. Resolves issue scala#4440
@smarter Have your comments been addressed? If yes please merge. |
I'll have a look next week, I think there's still one thing I wanted to do here. |
In scala#4450 and Scala 2.12, readResolve is used to make sure deserializing object returns the singleton instance of the object, but this doesn't prevent the fields of the objects from being serializable in the first place even though they're not used. Scala 2.13 switched to using writeReplace to completely bypass serialization of the object in scala/scala#7297. This commit adapts this to Dotty. Co-Authored-By: Ingar Abrahamsen <[email protected]> Co-Authored-By: Jason Zaugg <[email protected]>
I've opened a new PR adapted from this PR and scala/scala#7297 at #5775, so I'll close this one, thanks for your work @ingarabr ! |
In scala#4450 and Scala 2.12, readResolve is used to make sure deserializing an object returns the singleton instance of the object, but this doesn't prevent the fields of the objects from being serialized in the first place even though they're not used. Scala 2.13 switched to using writeReplace to completely bypass serialization of the object in scala/scala#7297. This commit adapts this to Dotty. Co-Authored-By: Ingar Abrahamsen <[email protected]> Co-Authored-By: Jason Zaugg <[email protected]>
In scala#4450 and Scala 2.12, readResolve is used to make sure deserializing an object returns the singleton instance of the object, but this doesn't prevent the fields of the objects from being serialized in the first place even though they're not used. Scala 2.13 switched to using writeReplace to completely bypass serialization of the object in scala/scala#7297. This commit adapts this to Dotty. Co-Authored-By: Ingar Abrahamsen <[email protected]> Co-Authored-By: Jason Zaugg <[email protected]>
In scala#4450 and Scala 2.12, readResolve is used to make sure deserializing an object returns the singleton instance of the object, but this doesn't prevent the fields of the objects from being serialized in the first place even though they're not used. Scala 2.13 switched to using writeReplace to completely bypass serialization of the object in scala/scala#7297. This commit adapts this to Dotty. Co-Authored-By: Ingar Abrahamsen <[email protected]> Co-Authored-By: Jason Zaugg <[email protected]>
In scala#4450 and Scala 2.12, readResolve is used to make sure deserializing an object returns the singleton instance of the object, but this doesn't prevent the fields of the objects from being serialized in the first place even though they're not used. Scala 2.13 switched to using writeReplace to completely bypass serialization of the object in scala/scala#7297. This commit adapts this to Dotty. Co-Authored-By: Ingar Abrahamsen <[email protected]> Co-Authored-By: Jason Zaugg <[email protected]>
In scala#4450 and Scala 2.12, readResolve is used to make sure deserializing an object returns the singleton instance of the object, but this doesn't prevent the fields of the objects from being serialized in the first place even though they're not used. Scala 2.13 switched to using writeReplace to completely bypass serialization of the object in scala/scala#7297. This commit adapts this to Dotty. Co-Authored-By: Ingar Abrahamsen <[email protected]> Co-Authored-By: Jason Zaugg <[email protected]>
In scala#4450 and Scala 2.12, readResolve is used to make sure deserializing an object returns the singleton instance of the object, but this doesn't prevent the fields of the objects from being serialized in the first place even though they're not used. Scala 2.13 switched to using writeReplace to completely bypass serialization of the object in scala/scala#7297. This commit adapts this to Dotty. Co-Authored-By: Ingar Abrahamsen <[email protected]> Co-Authored-By: Jason Zaugg <[email protected]>
In scala#4450 and Scala 2.12, readResolve is used to make sure deserializing an object returns the singleton instance of the object, but this doesn't prevent the fields of the objects from being serialized in the first place even though they're not used. Scala 2.13 switched to using writeReplace to completely bypass serialization of the object in scala/scala#7297. This commit adapts this to Dotty. Co-Authored-By: Ingar Abrahamsen <[email protected]> Co-Authored-By: Jason Zaugg <[email protected]>
In scala#4450 and Scala 2.12, readResolve is used to make sure deserializing an object returns the singleton instance of the object, but this doesn't prevent the fields of the objects from being serialized in the first place even though they're not used. Scala 2.13 switched to using writeReplace to completely bypass serialization of the object in scala/scala#7297. This commit adapts this to Dotty. Co-Authored-By: Ingar Abrahamsen <[email protected]> Co-Authored-By: Jason Zaugg <[email protected]>
In scala#4450 and Scala 2.12, readResolve is used to make sure deserializing an object returns the singleton instance of the object, but this doesn't prevent the fields of the objects from being serialized in the first place even though they're not used. Scala 2.13 switched to using writeReplace to completely bypass serialization of the object in scala/scala#7297. This commit adapts this to Dotty. Co-Authored-By: Ingar Abrahamsen <[email protected]> Co-Authored-By: Jason Zaugg <[email protected]>
In scala#4450 and Scala 2.12, readResolve is used to make sure deserializing an object returns the singleton instance of the object, but this doesn't prevent the fields of the objects from being serialized in the first place even though they're not used. Scala 2.13 switched to using writeReplace to completely bypass serialization of the object in scala/scala#7297. This commit adapts this to Dotty. Co-Authored-By: Ingar Abrahamsen <[email protected]> Co-Authored-By: Jason Zaugg <[email protected]>
In scala#4450 and Scala 2.12, readResolve is used to make sure deserializing an object returns the singleton instance of the object, but this doesn't prevent the fields of the objects from being serialized in the first place even though they're not used. Scala 2.13 switched to using writeReplace to completely bypass serialization of the object in scala/scala#7297. This commit adapts this to Dotty. Co-Authored-By: Ingar Abrahamsen <[email protected]> Co-Authored-By: Jason Zaugg <[email protected]>
If the object implements the serializable interface and not includes the
readResolve method then we add it. Since it's an object we reference it
to the objects singleton instance.
Resolves issue #4440