-
Notifications
You must be signed in to change notification settings - Fork 3.1k
SI-10075 propagate annotations to lazy val's underlying field #5570
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
Conversation
Not sure we've got this sorted yet. Here's a test case for combinations of trait defined/class defined/trait-mixed in members; val/var/lazy val; field/getter/setter meta annotations that shows the difference between 2.11.8, 2.12.0, and 2.12.1 (as proposed in this PR). There are still some problems:
|
Thanks for the test case -- where did it go, though? |
I think I have fixes for the first two. Not sure about the static accessors yet |
https://gist.github.com/retronym/c46af6372d325a8bdd1d8cf1315eccf5 Static accessors are spawned in the backend using
|
Thanks. So you're saying we should just drop all annotations from the static accessor? |
I'll incorporate your test tomorrow as well as the logic for the static accessor annotation triage |
Yes, I think we should drop them. |
test/files/run/t10075.scala
Outdated
// If it doesn't, `writeObject` will fail to serialize the field `notSerialized`, because `NotSerializable` is not serializable | ||
object Test { | ||
def main(args: Array[String]): Unit = | ||
new java.io.ObjectOutputStream(new java.io.ByteArrayOutputStream) writeObject (new SerializableBecauseTransient) |
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.
Shouldn't the lazy vals be forced before trying to serialize? Otherwise the backing field will be null, and serialization will succeed even if it is not transient, right?
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.
Good point. Thanks!
One test failure:
|
Updated test, since it had a nice TODO message that confirmed it needed updating :-) thanks, @lrytz |
It's green now |
LGTM, tricky stuff! |
If I understand @lrytz's comment at scala/scala-dev#213 (comment) correctly, I should drop the Alternatively, could we avoid looking at annotations of static accessors in the inliner? Could the inliner see through the static accessor and decide inlining based on the target of the accessor? |
This likely regressed in scala#5294. Review feedback from retronym: - Tie annotation triaging a bit closer together durban kindly provided initial version of test/files/run/t10075.scala And pointed out you must force `lazy val`, since `null`-valued field is serializable regardless of its type. Test test/files/run/t10075b courtesy of retronym
Based on review suggestion by retronym. See also scala/scala-dev#213
It turns out the inliner does not rely on the For every member method, we store some metadata in the When building a scala/src/compiler/scala/tools/nsc/backend/jvm/BTypesFromSymbols.scala Lines 598 to 608 in ee1c02b
annotatedInline bit is taken from the corresponding member method.
|
Aha! Thanks for explaining. So this is ready to go as far as you're concerned? |
yes, LGTM |
Cool. When I split up my old commit in two, I missed one test case. The last commit is green, so I'm going to merge. One broken test isn't going to break future git bisecting. |
This likely regressed in #5294.
Fixes scala/scala-dev#213
Review by @retronym