-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Signatures cached in NamedType can become stale, some cache invalidation is needed #8799
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
See scala#8799 for more information. The test currently fails with: Wrong cached signature at phase elimErasedValueType for (Foo.this.value : (): scala.runtime.BoxedUnit). Actual denotation signature: Signature(List(),scala.runtime.BoxedUnit) Cached ref signature: Signature(List(),), The test passes if I tweak NamedType to not cache signatures.
Oh yeah, cache invalidation is also a possible solution as mentioned in the title: we could keep the cache valid only for a given phase id (or a set of phase ids, using a similar mechanism to the ones we uses for |
The signature design assumes that signatures are stable over all phases, and that the signature of a type [EDIT] But I see now the problem is signatures of denotations. And yes, we cannot assume they are stable because of ExplicitOuter. Hmm not sure what to do. |
I guess if ExplicitOuter is the only thing we cannot handle, then we could simply forbid caching signatures of constructors pre-ExplicitOuter ?(It's still going to be quite a lot of work to fix all the other issues) |
The purpose of a signature of a NamedType is to provide a stable reference to a member. So maybe we could always take the signature of a NamedType pre-ExplicitOuter, then we do not need to update it later. |
Ah, so if we go down that road, does signature generation still need to be based on erasure via |
|
See scala#8799 for more information. The test currently fails with: Wrong cached signature at phase elimErasedValueType for (Foo.this.value : (): scala.runtime.BoxedUnit). Actual denotation signature: Signature(List(),scala.runtime.BoxedUnit) Cached ref signature: Signature(List(),), The test passes if I tweak NamedType to not cache signatures.
Use the initial denotation to computer the signature of a NamedType
Fix #8799: Make sure signatures are computed before erasure
NamedType
extendsSignatureCaching
which defines: https://github.com/lampepfl/dotty/blob/f2e5fd08036b2ecbcbc536d49517c8d66ecfa7a5/compiler/src/dotty/tools/dotc/core/Types.scala#L3053-L3059This code assumes that if a signature is not underdefined, it is valid for the whole run. For a NamedType,
computeSignature
delegates toDenotation#signature
, if the denotation info is a MethodicType, this in turn is delegated toMethodicType#signature
. So this scheme only works if all denotation transformers that transform MethodicType do so while preservingsignature
.Unfortunately this is not the case: for example if we look at
TypeErasure#transformInfo
, we see that a MethodType can be replaced with a different type which will get a different signature:https://github.com/lampepfl/dotty/blob/f2e5fd08036b2ecbcbc536d49517c8d66ecfa7a5/compiler/src/dotty/tools/dotc/core/TypeErasure.scala#L202-L216
I've written a unit test that demonstrates the problem: #8798
I don't think we can tweak Denotation#signature to always be stable. For example we can't just run
TypeErasure#transformInfo
at the current phase and expect it to work properly: it will return different results depending on whether the ExplicitOuter tree transformer has been run or not (see bf3b224).Therefore, I only see two possible ways forward:
What do you think, @odersky ?
The text was updated successfully, but these errors were encountered: