Skip to content

Base multiversal equality on typeclass derivation #5843

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

Merged
merged 10 commits into from
Feb 12, 2019

Conversation

odersky
Copy link
Contributor

@odersky odersky commented Feb 4, 2019

We still need to consider the idea of making equality an extension method.

@odersky odersky force-pushed the derive-multiversal branch 2 times, most recently from 17b5611 to a28a078 Compare February 4, 2019 21:08
@odersky odersky force-pushed the derive-multiversal branch 2 times, most recently from a76f3cc to 3c27142 Compare February 6, 2019 14:21
@odersky
Copy link
Contributor Author

odersky commented Feb 6, 2019

test performance please

@dottybot
Copy link
Member

dottybot commented Feb 6, 2019

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

@odersky odersky force-pushed the derive-multiversal branch from fda184c to dcd3f55 Compare February 6, 2019 15:35
@odersky odersky removed the stat:wip label Feb 6, 2019
@odersky odersky assigned OlivierBlanvillain and unassigned odersky Feb 6, 2019
@dottybot
Copy link
Member

dottybot commented Feb 6, 2019

Performance test finished successfully:

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

Benchmarks is based on merging with master (b44adf7)

Treat Eq like any other derivable typeclass. This caused
a bit of changes in fuzzing tests.
 1. Don't apply the lifting rules when strictEquality is set.
 2. Be more strict about null checking
 3. Compensate for (2) by changing errorTerm in parser so that
    it has an error type instead of Null.
 4. Reorganize implementation to match new docs.
 1. Don't apply the lifting rules when strictEquality is set.
 2. Be more strict about null checking
 3. Compensate for (2) by changing errorTerm in parser so that
    it has an error type instead of Null.
 4. Reorganize implementation to match new docs.
 5. Handle Eql instances involving primitive types or Null directly
    in the compiler (previously, we were missing some of them, see
    pos/multivarsal.scala as a test)
 6. Sharpen Eql instance of Proxy to only work for AnyRef arguments.
    This avoids false negatives when comparing value types with null.
Some neg tests now return more errors since we do stricter checking that
comparisons with null make sense. There's an unfortunate interaction with
`errorTerm` in Parser which returns a `null` literal as a tree when the
parser gets confused. That null literal now causes follow on errors in some
cases.

I believe the right thing to do would be to let `errorTerm` return a tree
with an `ErrorType`. I tried that, and it would remove again all the added
errors in this commit. Unfortunately, it breaks SignatureHelpTest in a way
I cannot fix.
Sine it now uses typeclass derivation, it makes sense if it comes
directly afterwards.
Eq is already used with a slightly different meaning as a unary typeclass,
e.g. cats.Eq.
Avoid duplicating parameter names in derivations of n-ary type classes
@odersky odersky force-pushed the derive-multiversal branch from 6422ef8 to f791a52 Compare February 8, 2019 15:40
@@ -67,7 +67,7 @@ import collection.mutable.ListBuffer
*/
object Denotations {

implicit def eqDenotation: Eq[Denotation, Denotation] = Eq
implicit def eqDenotation: Eq[Denotation, Denotation] = Eq.derived
Copy link
Contributor

Choose a reason for hiding this comment

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

I would give it another name because here the instance is not really derived, bur rather declared or something.

type `Eq[L, R]`, provided that neither `L` nor `R` have `Eq` instances
defined on them.
Even though `eqlAny` is not declared `implied`, the compiler will still
construct an `eqlAny` instance as answer to an implicit search for the
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there also an alternative name for implicit search? Mixing the two terminologies here makes the sentence a bit confusing...

- _lifting_ a type `S` means replacing all references to abstract types
in covariant positions of `S` by their upper bound, and to replacing
all refinement types in covariant positions of `S` by their parent.
- a type `T` has a _reflexive `Eql` instance_ if the implicit search for `Eql[T, T]`
Copy link
Contributor

Choose a reason for hiding this comment

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

Same comment (on implicit search)


// The next three definitions can go into the companion objects of classes
Copy link
Contributor

Choose a reason for hiding this comment

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

I agree, but then maybe then spec shouldn't mention them...

@@ -63,8 +65,6 @@ sidebar:
url: docs/reference/contextual/relationship-implicits.html
- title: Other New Features
subsection:
- title: Multiversal Equality
url: docs/reference/other-new-features/multiversal-equality.html
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 this will break all links to the Multiversal Equality doc, we should keep the old url with a redirect.

@odersky odersky merged commit 58b8aaa into scala:master Feb 12, 2019
@allanrenucci allanrenucci deleted the derive-multiversal branch February 12, 2019 17:49
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.

3 participants