-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fix #3965: Correct equality for higher-kinded types #3970
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
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.
Hello, and thank you for opening this PR! 🎉
All contributors have signed the CLA, thank you! ❤️
Commit Messages
We want to keep history, but for that to actually be useful we have
some rules on how to format our commit messages (relevant xkcd).
Please stick to these guidelines for commit messages:
- Separate subject from body with a blank line
- When fixing an issue, start your commit message with
Fix #<ISSUE-NBR>:
- Limit the subject line to 72 characters
- Capitalize the subject line
- Do not end the subject line with a period
- Use the imperative mood in the subject line ("Added" instead of "Add")
- Wrap the body at 80 characters
- Use the body to explain what and why vs. how
adapted from https://chris.beams.io/posts/git-commit
Have an awesome day! ☀️
test performance please |
performance test scheduled: 1 job(s) in queue, 1 running. |
This is a first step of a larger refactoring, where hashing and equality need to have algorithms that detect that isomorphic BindingTypes are equal. Without this, there is no good way to deal with recursive higher-kinded types, as we cannot detect that a type has already been added to a constraint or that a subtype test was already performed.
Make hashes structural for dependent types. Two isomorphic types should give the same hash even if there are dependencies to BindingTypes.
`equals` of two isomorphic types should return true, even if they are dependencies to BindingTypes.
What happened was that a higher-kinded type was added repeatedly to a constraint. Because equality of higher-kinded types was broken, the compiler did not realize that the type had already been added.
test performance please |
performance test scheduled: 1 job(s) in queue, 1 running. |
else tps2.nonEmpty && equals(tps1.head, tps2.head) && equals(tps1.tail, tps2.tail) | ||
} | ||
|
||
final def equalBinders(tp1: BindingType, tp2: BindingType): Boolean = |
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.
This method is unused
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.
No, there are two calls in Types
.
Performance test finished successfully: Visit http://dotty-bench.epfl.ch/3970/ to see the changes. Benchmarks is based on merging with master (39980f3) |
Let's see whether this helps combat the observed performance hit.
test performance please |
performance test scheduled: 1 job(s) in queue, 1 running. |
Performance test finished successfully: Visit http://dotty-bench.epfl.ch/3970/ to see the changes. Benchmarks is based on merging with master (39980f3) |
1 similar comment
Performance test finished successfully: Visit http://dotty-bench.epfl.ch/3970/ to see the changes. Benchmarks is based on merging with master (39980f3) |
Since correct hashing under binders seems to be very expensive (see performance data for scala#3970), let's try have fewer types that require this.
Subsumed by #3978 |
Since correct hashing under binders seems to be very expensive (see performance data for scala#3970), let's try have fewer types that require this.
What happened was that a higher-kinded type was added repeatedly
to a constraint. Because equality of higher-kinded types was "broken",
the compiler did not realize that the type had already been added.
"Broken" means: Two isomorphic instances of the same higher kinded type
such as
[X] => C[X]
were treated as different.For similar reasons the equality check in monitoredSubtype did not
detect loops involving higher-kinded types.
To fix the issue, rework hashing and equality so that two isomorphic types
are identified even if they are dependent (i.e. have back edges from a
BoundType
such asParamRef
orRecThis
to itsLambdaType
orRecType
binder.
While we are at it, also use this for hash-consing method and poly types.
Aside:
scalac
also uses the naive version of type equality that treatsPolyTypes
as generative. But it does not have the same issues because it does not use
PolyTypes
as higher-kinded types. I believe similar issues could be engineered by making up
type lambdas using refinement types and putting these in certain F-bounds. But so far nobody
seems to have pushed things far enough to notice.