Skip to content

Fix #8799: Use initial denotation for signatures #8813

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

Closed
wants to merge 4 commits into from

Conversation

odersky
Copy link
Contributor

@odersky odersky commented Apr 27, 2020

Use the initial denotation to compute the signature of a NamedType.

smarter and others added 2 commits April 27, 2020 18:16
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
protected def computeSignature(implicit ctx: Context): Signature =
lastDenotation match
case null => symbol.asSeenFrom(prefix).signature
case sd: SingleDenotation => sd.initial.signature
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps Denotation#signature itself should do the work of calling initial? That way we're sure to never use the wrong signature

Copy link
Member

@smarter smarter Apr 27, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Case in point: the code just below for currentSignature calls lastd.signature and lastd might not be the initial denotation. Similarly, symbol.asSeenFrom(prefix).signature above will also be computed at the current phase.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As long as signatures are defined in denotations, I think they should apply to the owner denotation. If we wanted to always go for initial, then signatures should be defined on symbols.

Agree that currentSignature needs to be fixed as well.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we wanted to always go for initial, then signatures should be defined on symbols.

That might make sense, I can see how different prefixes can lead to different signatures for denotations, but I don't think that should ever be needed to disambiguate between overloads ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm I guess that would probably interfere with how we deal with merging denotations.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I think it's better to leave them on denotations.

protected def computeSignature(implicit ctx: Context): Signature =
lastDenotation match
case null => symbol.asSeenFrom(prefix).signature
case sd: SingleDenotation => sd.initial.signature
Copy link
Member

@smarter smarter Apr 27, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Case in point: the code just below for currentSignature calls lastd.signature and lastd might not be the initial denotation. Similarly, symbol.asSeenFrom(prefix).signature above will also be computed at the current phase.

@smarter
Copy link
Member

smarter commented Apr 27, 2020

This change means we need to be very careful anytime we compare signatures: if we compare the signature of two typerefs referring to symbols created at different phases, they might not match anymore. For example this check in TypeComparer is likely not correct anymore:
https://github.com/lampepfl/dotty/blob/66f335cf09f5e6a71bec1f5f1e0f161921e93e32/compiler/src/dotty/tools/dotc/core/TypeComparer.scala#L271

@odersky
Copy link
Contributor Author

odersky commented Apr 27, 2020

I had a look at the TypeComparer test. There it should be OK since the fallBack thirdTryNamed will handle it.

}
}
case sd: SingleDenotation => sd.initial.signature
case d => d.signature
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is the non-SingleDenotation case handled specially without calling initial ?

Copy link
Contributor Author

@odersky odersky Apr 27, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do not have an initial for general denotations

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, and it's fine because their signature is always OverloadedSignature right ? In that case maybe we should put a comment in the code or directly return OverloadedSignature to make that obvious

@smarter
Copy link
Member

smarter commented Apr 27, 2020

I just realized that currentSignature should be handled differently: it's only use is to be passed as an argument to Denotation#atSignature so it's critical that it matches the signature of the denotation at the current phase, which means it shouldn't call initial but it cannot rely on the mySignatureSig cache either since that's the initial signature.

@odersky
Copy link
Contributor Author

odersky commented Apr 28, 2020

In fact the problem is less severe than I thought at first: ExplicitOuter does not change signatures. It delays to erasure to do this. So,

  • signatures of denotations can change at erasure, but
  • after erasure signatures of NamedTypes do not matter anymore since all references are via symbols.

So it's enough to just make sure that all signatures of NamedTypes are computed before erasure.

This is what #8819 does.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants