-
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
Make initialization checker see through synthetic applys #14283
Conversation
Otherwise, as the test tests/init/pos/local-warm5.scala shows, we may reach an outer that is cold.
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.
LGTM
withEnv(if isLocal then env else Env.empty) { | ||
eval(ddef.rhs, ref, cls, cacheResult = true) ++ checkArgs | ||
} | ||
if isSyntheticApply(meth) then |
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 wondered whether it would make sense to instantiate
a synthetic apply even if target.hasSource
is false. But if we don't have source for the synthetic apply, then we probably also don't have source for the class constructor, so instantiate
wouldn't be useful.
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 wondered whether it would make sense to instantiate a synthetic apply even if target.hasSource is false. But if we don't have source for the synthetic apply, then we probably also don't have source for the class constructor, so instantiate wouldn't be useful.
Yes, exactly.
I found one bug in the code above: the outer for instantiate
is incorrect. I'll come up with a test to show the bug and fix it in this PR.
instantiate(klass, klass.primaryConstructor, args, source) | ||
val outerCls = klass.owner.lexicallyEnclosingClass.asClass | ||
val outer = resolveOuterSelect(outerCls, ref, 1, source) | ||
Semantic.instantiate(outer)(klass, klass.primaryConstructor, args, source) |
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 not outer.instantiate(...)
?
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 the catch, this is now updated.
Make initialization checker see through synthetic
apply
sThe initialization checker supports non-hot arguments to constructors, but not for methods.
For Scala to benefit from the expressiveness, we need to make the initialization checker see through synthetic
apply
s.We currently don't allow parameter-sensitivity for normal method arguments, as they would require complications of the abstract domains and it may cause unexpected usability/performance issues. Instead, we expect users to use
inline def
or@unchecked
for such complex initialization code.An alternative to #13999.