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
Plug many variance holes (in higher-kinded types, refined types and private inner classes) #8545
Conversation
a4b53e2
to
f1b8a1d
Compare
Fwiw: Dotty does traverses bodies in PostTyper to find refinements and type lambdas (and guess RefChecks is a sensible phase for that). But those lambdas should not be checked for occurrences of class type params, only occurrences of their type params. |
Cool, that's what I'm doing here as well. Now need to replicate the fix for |
5699c5e
to
83e4ef1
Compare
83e4ef1
to
bbf0a3a
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
ee6c01c
to
cab4555
Compare
@joroKr21 agree akka-stream and squants failures are known and unrelated. but what about the monix failure? https://scala-ci.typesafe.com/job/scala-2.13.x-integrate-community-build/2855/artifact/logs/monix-build.log |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
I pushed a commit to remove the check for escaping locals which was the cause of the Monix failure. |
This comment has been minimized.
This comment has been minimized.
58e5251
to
80be4b3
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
80be4b3
to
cf16664
Compare
3224c66
to
370506e
Compare
dd04a28
to
45eb099
Compare
@joroKr21 is this ready for review? |
Yes it has been ready for a while, sorry if I didn't make it clear. |
45eb099
to
9e46424
Compare
Looks like |
Uh, I rebased to resolve conflicts and updated the check. It worked locally. Could that be some difference between bootstrapped and non-bootstrapped compiler? EDIT: That was another check file. |
The variance checks root in `RefChecks` for `TypeTree`s is modified to check only the variance of `PolyType`s (this includes type lambdas). Checking the definition of the `PolyType`s' owners is not correct, because `relativeVariance` doesn't work for types in arbitrary position. To check the variance of `PolyType`s we introduce a new type map: `PolyTypeVarianceMap`. This is similar to the way variance is checked for type lambdas in dotty, where type lambdas are encoded explicitly. We also add explicit tracking for lower bounds of `PolyType`s. For a type parameter of a `PolyType`, the variance should not be flipped (or equivalently, flipped twice) in the lower bound. This applies to both `ValidateVarianceMap` and `PolyTypeVarianceMap`. It fixes variance bugs for types appering in the bounds of HKTs. Finally, we don't skip local definitions entirely (this is unsound), but instead cutoff `relativeVariance` at local boundaries.
Add documentation to the two different variance validation methods: `validateDefinition` and `validateVarianceOfPolyTypesIn`.
9e46424
to
a29da6a
Compare
@adriaanm will you be doing the final review on this, or do we need to find another reviewer? |
I won't have time to dig deeper than I already have. It all looked good on my initial pass. Glad to see the additional comments and cleanups since then! It would still be good to get another pair of 👀 on this IMO. |
@lrytz you want to be the eyes, or assign someone? |
@joroKr21 unless it gets left on the editing-room floor, there will be a brief shout-out in the next Scala Love episode to you and @milessabin for your bravery in tackling changes to Scala 2 type-checking |
@joroKr21 I have the same question as I had on your other PR: whether this should get the "release-notes" label |
Perhaps it's worth mentioning that together with #8651 there are a lot of bugs fixed in the variance check department for higher-kinded types, type aliases, type lambdas and type refinements. I'm not sure what's required for PR titles and descriptions. |
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 to the best of my knowledge
Thank you, @joroKr21, for your continuous efforts! |
@joroKr21 Wow, thank you! 👏 |
Most examples are fixed in dotty.
The variance checks root in
RefChecks
forTypeTree
s is modifiedto check only the variance of
PolyType
s (this includes type lambdas).Checking the definition of the
PolyType
s' owners is not correct,because
relativeVariance
doesn't work for types in arbitrary position.To check the variance of
PolyType
s we introduce a new type map:PolyTypeVarianceMap
. This is similar to the way variance is checkedfor type lambdas in dotty, where type lambdas are encoded explicitly.
We also add explicit tracking for lower bounds of
PolyType
s.For a type parameter of a
PolyType
, the variance should not beflipped (or equivalently, flipped twice) in the lower bound.
This applies to both
ValidateVarianceMap
andPolyTypeVarianceMap
.It fixes variance bugs for types appering in the bounds of HKTs.
Finally, we don't skip local definitions entirely (this is unsound),
but instead cutoff
relativeVariance
at local boundaries.Fixes scala/bug#11789, fixes scala/bug#9911, fixes scala/bug#9725