-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fix #3015: exhaustivity check on top of native apply #3074
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! ☀️
7cd7fe9
to
3d073cd
Compare
AppliedType will be used for all type applications, higher-kinded or not. That is, eventually, it will replace HKApply and also the encodings of type applications as refined types. This commit introduces AppliedType and adapts baseType computations to take it into account. AppliedType is not yet constructed anywhere, however.
So far, everything up to parents is adapted to new scheme. Parents is half done; needs more work once we change layour of ClassInfo.
Simplifies usage and removes some obscure code in Types
Systematically introduce handlers for AppliedTypes where there was a handler for HKApply.
Also, change asSeenFrom to use it for arguments
Avoid printing addresses and reduce junk.
We had a stackoverfloa in asSeenFrom even under the old scheme, since there was a bad change involving checkRealizableBounds.
Otherwise we always need to a clean compile to update things.
The previous type parameter representation in terms of type members achieved bounds propagation by waiting until a type member was selected and then taking original bounds and refinements together as its info. This no longer works with explicit applications. Instead, we need to propagate bounds into wildcard arguments explicitly, when a type application is created. Also, fix argument computation in asSeenFrom
Need to avoid variance 0, as it leads to leaking ranges.
Strange as it sounds, a TypeBounds can be a subtype of a single type.
Needed to compile i0239.scala correctly.
- Several fixes for TypeArgRef. - argForParam needs to follow owner chains like toPrefix does (see t119.scala)
Needed to make i2250.scala compile
Can't rely any ore that refinements are stripped away in normalizeClassRef
Without the tweak, neg/i1181c.scala gives the non-sensical message `type mismatch: found: Foo[Int, Int], expected: Any`.
scala#3054 has a better approach.
3d073cd
to
7388f6c
Compare
7388f6c
to
7a49c8c
Compare
test performance please |
performance test scheduled: 1 job(s) in queue. |
Performance test finished successfully: Visit http://dotty-bench.epfl.ch/3074 to see the changes. Benchmarks is based on merge(s) with master |
The performance graph shows that the new exhaustivity check performs the same on normal patmat tests as before, but degrades significantly on the abnormal test case V: from 2s to 3.5s. |
We see now a much bigger performance gain than with applied types alone on dotc. It's about 10% faster as opposed to maybe 2 or 3% before. Interesting, given that exhaustivity checks are now slower than before. My guess is that the reporting of the spurious exhaustivity warnings in dotc itself (there were about 300 of them) impacted overall performance. Anyway, getting 10% on dotc and 6-7 % on Vector or stdlib is very encouraging! |
@odersky The printing of exhaustivity warnings involves a lot of IO, which has a bad impact on performance. You can also test performance by disable the exhautivity check in the pattern matcher, and see how it improves the numbers. |
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 think this is a definite improvement. Except for my minor remarks, LGTM
case _ => | ||
debug.println(s"unknown pattern: $pat") | ||
Empty | ||
} | ||
|
||
/* Erase a type binding according to erasure semantics in pattern matching */ | ||
def erase(tp: Type): Type = tp match { | ||
case tp@AppliedType(tycon, args) => erase(tp.superType) |
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.
Useless erase, this is thrown away
def erase(tp: Type): Type = tp match { | ||
case tp@AppliedType(tycon, args) => erase(tp.superType) | ||
if (tycon.isRef(defn.ArrayClass)) tp.derivedAppliedType(tycon, args.map(erase)) | ||
else tp.derivedAppliedType(tycon, args.map(t => WildcardType(TypeBounds.empty))) |
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 think you can just use the WildcardType object here.
def apply(t: Type): Type = t match { | ||
|
||
case tp: TypeRef if tp.underlying.isInstanceOf[TypeBounds] => | ||
// See tests/patmat/gadt.scala tests/patmat/exhausting.scala |
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.
Add: if tp.symbol.is(TypeParam) &&
Do you know why https://github.com/liufengyun/bench/blob/master/tests/exhaustivity-V.scala performs worse now? |
@smarter I think it's because the type inference approach is more expensive than the previous hack for generics. |
But there is nothing to infer in https://github.com/liufengyun/bench/blob/master/tests/exhaustivity-V.scala, right? Maybe we could avoid the expensive use of type inference in some cases. (Of course this shouldn't be required to get this PR in, but maybe something to investigate later) |
@smarter Good point, as |
Superseded by #3061 |
Fix #3015: exhaustivity check on top of native apply