Skip to content

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

Closed
wants to merge 106 commits into from

Conversation

liufengyun
Copy link
Contributor

Fix #3015: exhaustivity check on top of native apply

Copy link
Member

@dottybot dottybot left a 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:

  1. Separate subject from body with a blank line
  2. When fixing an issue, start your commit message with Fix #<ISSUE-NBR>:
  3. Limit the subject line to 72 characters
  4. Capitalize the subject line
  5. Do not end the subject line with a period
  6. Use the imperative mood in the subject line ("Added" instead of "Add")
  7. Wrap the body at 80 characters
  8. Use the body to explain what and why vs. how

adapted from https://chris.beams.io/posts/git-commit

Have an awesome day! ☀️

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.
Test case was extended and several fixes were necessary to make it pass.
 - 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`.
@liufengyun
Copy link
Contributor Author

test performance please

@dottybot
Copy link
Member

dottybot commented Sep 7, 2017

performance test scheduled: 1 job(s) in queue.

@dottybot
Copy link
Member

dottybot commented Sep 7, 2017

Performance test finished successfully:

Visit http://dotty-bench.epfl.ch/3074 to see the changes.

Benchmarks is based on merge(s) with master

@liufengyun
Copy link
Contributor Author

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.

@odersky
Copy link
Contributor

odersky commented Sep 8, 2017

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!

@liufengyun
Copy link
Contributor Author

@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.

Copy link
Contributor

@odersky odersky left a 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)
Copy link
Contributor

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)))
Copy link
Contributor

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
Copy link
Contributor

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) &&

@smarter
Copy link
Member

smarter commented Sep 8, 2017

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.

Do you know why https://github.com/liufengyun/bench/blob/master/tests/exhaustivity-V.scala performs worse now?

@liufengyun
Copy link
Contributor Author

@smarter I think it's because the type inference approach is more expensive than the previous hack for generics.

@smarter
Copy link
Member

smarter commented Sep 8, 2017

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)

@liufengyun
Copy link
Contributor Author

@smarter Good point, as Product is not decomposable, the code path should be the same as before for the test V, as we didn't make any changes to the space algorithm.

@liufengyun
Copy link
Contributor Author

Superseded by #3061

@liufengyun liufengyun closed this Sep 8, 2017
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.

4 participants