-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Hash[Map[K, V]] has unnecessary constraint #3039 #3060
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -73,7 +73,7 @@ trait SortedSetInstances extends SortedSetInstances1 { | |
private[instances] trait SortedSetInstances1 { | ||
@deprecated("2.0.0-RC2", "Use cats.kernel.instances.sortedSet.catsKernelStdHashForSortedSet") | ||
private[instances] def catsKernelStdHashForSortedSet[A: Order: Hash]: Hash[SortedSet[A]] = | ||
cats.kernel.instances.sortedSet.catsKernelStdHashForSortedSet[A] | ||
cats.kernel.instances.sortedSet.catsKernelStdHashForSortedSet1[A] | ||
|
||
@deprecated("2.0.0-RC2", "Use cats.kernel.instances.sortedSet.catsKernelStdSemilatticeForSortedSet") | ||
def catsKernelStdSemilatticeForSortedSet[A: Order]: BoundedSemilattice[SortedSet[A]] = | ||
|
@@ -94,7 +94,7 @@ private[instances] trait SortedSetInstancesBinCompat0 { | |
private[instances] trait SortedSetInstancesBinCompat1 extends LowPrioritySortedSetInstancesBinCompat1 { | ||
// TODO: Remove when this is no longer necessary for binary compatibility. | ||
implicit override def catsKernelStdHashForSortedSet[A: Order: Hash]: Hash[SortedSet[A]] = | ||
cats.kernel.instances.sortedSet.catsKernelStdHashForSortedSet[A] | ||
cats.kernel.instances.sortedSet.catsKernelStdHashForSortedSet1[A] | ||
} | ||
|
||
private[instances] trait LowPrioritySortedSetInstancesBinCompat1 | ||
|
@@ -104,7 +104,7 @@ private[instances] trait LowPrioritySortedSetInstancesBinCompat1 | |
cats.kernel.instances.sortedSet.catsKernelStdOrderForSortedSet[A] | ||
|
||
override def catsKernelStdHashForSortedSet[A: Order: Hash]: Hash[SortedSet[A]] = | ||
cats.kernel.instances.sortedSet.catsKernelStdHashForSortedSet[A] | ||
cats.kernel.instances.sortedSet.catsKernelStdHashForSortedSet1[A] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @travisbrown, not sure what this override is for? Can we add a comment? |
||
} | ||
|
||
@deprecated("2.0.0-RC2", "Use cats.kernel.instances.SortedSetHash") | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,14 @@ | ||
package cats.kernel | ||
package instances | ||
|
||
import cats.kernel.{BoundedSemilattice, Hash, Order} | ||
import scala.collection.immutable.SortedSet | ||
|
||
trait SortedSetInstances extends SortedSetInstances1 { | ||
implicit def catsKernelStdHashForSortedSet[A: Order: Hash]: Hash[SortedSet[A]] = | ||
@deprecated("Will be removed after dropping Scala 2.11 support", "") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can the deprecated message be |
||
def catsKernelStdHashForSortedSet[A: Order: Hash]: Hash[SortedSet[A]] = | ||
new SortedSetHash[A] | ||
|
||
implicit def catsKernelStdHashForSortedSet1[A: Hash]: Hash[SortedSet[A]] = | ||
new SortedSetHash[A] | ||
} | ||
|
||
|
@@ -28,9 +31,13 @@ class SortedSetOrder[A: Order] extends Order[SortedSet[A]] { | |
StaticMethods.iteratorEq(s1.iterator, s2.iterator) | ||
} | ||
|
||
class SortedSetHash[A: Order: Hash] extends Hash[SortedSet[A]] { | ||
// FIXME use context bound in 3.x | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just curious, context bound breaks BC here (even with the deprecated constructor)? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, because it affects the constructor. |
||
class SortedSetHash[A](implicit hashA: Hash[A]) extends Hash[SortedSet[A]] { | ||
import scala.util.hashing.MurmurHash3._ | ||
|
||
@deprecated("Use the constructor _without_ Order instead, since Order is not required", "2.0.1") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: more likely that the derrecate version is |
||
def this(o: Order[A], h: Hash[A]) = this()(h) | ||
|
||
// adapted from [[scala.util.hashing.MurmurHash3]], | ||
// but modified standard `Any#hashCode` to `ev.hash`. | ||
def hash(xs: SortedSet[A]): Int = { | ||
|
@@ -50,7 +57,7 @@ class SortedSetHash[A: Order: Hash] extends Hash[SortedSet[A]] { | |
finalizeHash(h, n) | ||
} | ||
override def eqv(s1: SortedSet[A], s2: SortedSet[A]): Boolean = | ||
StaticMethods.iteratorEq(s1.iterator, s2.iterator)(Order[A]) | ||
StaticMethods.iteratorEq(s1.iterator, s2.iterator)(Eq[A]) | ||
} | ||
|
||
class SortedSetSemilattice[A: Order] extends BoundedSemilattice[SortedSet[A]] { | ||
|
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.
@travisbrown
Just noticed this, should this method be deprecated and un-implicit like the one above? The
Todo
comment should probably be removed too?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.
@kailuowang What's happening here is tricky: these instances were in the wrong place (
cats.instances.SortedSetInstances1
instead ofcats.kernel.instances
), and now that they're in the right place these bincompat traits get the methods from both, which results in aninherits conflicting members
compiler error, which means we have to bubble overrides all the way to the top.