Skip to content
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

Closed

Conversation

vasiliybondarenko
Copy link
Contributor

@vasiliybondarenko vasiliybondarenko commented Sep 13, 2019

Removed Order constraint from Hash[Map[K, V]]but bincomp is broken. Please advise how it can be overcome

Closes #3039

@travisbrown
Copy link
Contributor

@vasiliybondarenko Adding a method to a trait breaks bincompat on Scala 2.11. Once #3051 is merged you'll be able to merge master and the bincompat check should be fine.

@travisbrown
Copy link
Contributor

But these functions are ambiguous I using the same name

Personally I'd prefer to make the old over-constrained version of the method package-private if necessary in 2.1.0 rather than add a suffix to the unbroken one, but I think the overload should be fine as long as the broken one isn't implicit, right?

@vasiliybondarenko
Copy link
Contributor Author

But these functions are ambiguous I using the same name

Personally I'd prefer to make the old over-constrained version of the method package-private if necessary in 2.1.0 rather than add a suffix to the unbroken one, but I think the overload should be fine as long as the broken one isn't implicit, right?

Overloading for catsKernelStdHashForSortedSet works unless this function has no explicit usage but it has in the following traits:
cats.instances.SortedSetInstances1
cats.instances.SortedSetInstancesBinCompat1
cats.instances.LowPrioritySortedSetInstancesBinCompat1

So I assume the only solution is to add suffix to unbroken function with a proper constraint.

@codecov-io
Copy link

codecov-io commented Oct 5, 2019

Codecov Report

Merging #3060 into master will decrease coverage by 0.02%.
The diff coverage is 33.33%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3060      +/-   ##
==========================================
- Coverage   93.51%   93.48%   -0.03%     
==========================================
  Files         368      368              
  Lines        6983     6985       +2     
  Branches      195      195              
==========================================
  Hits         6530     6530              
- Misses        453      455       +2
Impacted Files Coverage Δ
core/src/main/scala/cats/instances/sortedSet.scala 88.23% <33.33%> (ø) ⬆️
...ala/cats/kernel/instances/SortedSetInstances.scala 91.66% <33.33%> (-8.34%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ed77f8e...88e221a. Read the comment docs.

@larsrh larsrh changed the title [WIP] Hash[Map[K, V]] has unnecessary constraint #3039 Hash[Map[K, V]] has unnecessary constraint #3039 Oct 5, 2019
larsrh
larsrh previously approved these changes Oct 5, 2019
@larsrh
Copy link
Contributor

larsrh commented Oct 5, 2019

I took the liberty of rebasing this to current master. Let's see if this works.

@larsrh
Copy link
Contributor

larsrh commented Oct 5, 2019

MiMa still complains:

[error]  * method this(cats.kernel.Order,cats.kernel.Hash)Unit in class cats.kernel.instances.SortedSetHash does not have a correspondent in current version

I think we'll have to add a deprecated extra constructor in there. I'll take care of it.

@vasiliybondarenko
Copy link
Contributor Author

MiMa still complains:

[error]  * method this(cats.kernel.Order,cats.kernel.Hash)Unit in class cats.kernel.instances.SortedSetHash does not have a correspondent in current version

I think we'll have to add a deprecated extra constructor in there. I'll take care of it.

Cool! Thanks

kailuowang
kailuowang previously approved these changes Oct 8, 2019
@kailuowang kailuowang dismissed their stale review October 8, 2019 13:43

missed something

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

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?

Copy link
Contributor

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 of cats.kernel.instances), and now that they're in the right place these bincompat traits get the methods from both, which results in an inherits conflicting members compiler error, which means we have to bubble overrides all the way to the top.

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

Choose a reason for hiding this comment

The 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?

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

Choose a reason for hiding this comment

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

Can the deprecated message be "Use catsKernelStdHashForSortedSet1 instead", "2.1.0" ?

import scala.util.hashing.MurmurHash3._

@deprecated("Use the constructor _without_ Order instead, since Order is not required", "2.0.1")
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: more likely that the derrecate version is 2.1.0

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

Choose a reason for hiding this comment

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

Just curious, context bound breaks BC here (even with the deprecated constructor)?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, because it affects the constructor.

Copy link
Contributor

@travisbrown travisbrown left a comment

Choose a reason for hiding this comment

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

I've got a branch lined up that includes @vasiliybondarenko's commit and also addresses the feedback here, simplifies things a bit, and documents the weird override stuff. I'll open it as soon as #3125 is merged, since they overlap a lot, and that one is trivial.

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.

Hash[Map[K, V]] has unnecessary constraint
5 participants