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

Deprecate universal Equiv #7414

Merged

Conversation

NthPortal
Copy link
Contributor

Followup to #7358

@scala-jenkins scala-jenkins added this to the 2.13.0-RC1 milestone Nov 11, 2018
@NthPortal NthPortal requested a review from lrytz November 11, 2018 22:24
@@ -58,4 +71,438 @@ object Equiv extends LowPriorityEquiv {
((x, y) => implicitly[Equiv[S]].equiv(f(x), f(y)))

@inline def apply[T: Equiv]: Equiv[T] = implicitly[Equiv[T]]

implicit def equivFromPartialOrdering[T](implicit ev: PartialOrdering[T]): Equiv[T] = ev
Copy link
Member

Choose a reason for hiding this comment

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

This feels a bit contradictory to me... Ordering[A] <: PartialOrdering[A] <: Equiv[A]. These implicit conversions already mean that Equiv and PartialOrdering need to have knowledge about their subtypes. Why not just go down the rabbit hole while we're already stuck halfway, and add all implicit instances of Equiv and its subtypes to the Equiv companion object?
Also, can someone quickly remind me why Equiv needs its own instances for all the primitives and tuples etc?

Copy link
Contributor Author

@NthPortal NthPortal Nov 13, 2018

Choose a reason for hiding this comment

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

For primitives, it technically doesn't - it can summon those from Ordering (that answers the first part of your question I think, kinda). For parameterised types, we can't rely on summoning ones from Ordering, because they rely on the existence of implicit Orderings for each of the types, when only implicit Equivs should be needed.

We could theoretically not have the instances for primitives, but they are by far not the maintenance burden, and it seems a bit odd to me to have methods for Ordering, tuples, Seqs, etc. but not the primitives. Also, in order to not have confusing deprecation messages, we still need Equiv instances for Float and Double.

Would it be better if we moved the implicit conversions to the subtypes? I'm not sure if that would still put them on the search path. (i.e. Ordering contains Ordering[A] => PartialOrdering[A], and PartialOrdering contains PartialOrdering[A] => Equiv[A])

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Apparently you don't actually need the implicit methods anywhere for Ordering and PartialOrdering to be on the implicit search path, so I'm going to remove them.

Props to @ceedubs for making really good tests for these implicit methods, making it super easy for me to test if that worked.

NthPortal and others added 2 commits November 18, 2018 15:23
This is a replacement for scala#7187 (see discussion there).

This does the following things:

1. Deprecate universal Equiv instance.
2. Create an Ordering -> PartialOrdering conversion.
3. Create a PartialOrdering -> Equiv conversion at a higher priority
than the universal instance.
4. Add some unit tests that check that implicit resolution is working as
expected.

@NthPortal suggested the conversions as a simple way to have `Equiv`
instances that could be resolved without duplicating a lot of the work
that has been done for `Order` instances for basic types.
@SethTisue
Copy link
Member

SethTisue commented Nov 27, 2018

@SethTisue
Copy link
Member

no community build breakage

@NthPortal
Copy link
Contributor Author

Thanks for checking, Seth! Sorry I never got around to doing more than a cursory analysis of the results.

@dwijnand
Copy link
Member

Btw, thanks so much Nth for the PR. It's partially a shame that this simple sounding PR is so elaborate, but more so thank you for contributing the effort!

@NthPortal
Copy link
Contributor Author

no problem!

my goal is to steal Rex's position as the resident expert on scala.math ;)

@NthPortal
Copy link
Contributor Author

Is there anything else that needs to be done before merging this?

@SethTisue SethTisue merged commit 04f79e7 into scala:2.13.x Dec 4, 2018
@SethTisue
Copy link
Member

not sure whether to add "release-notes" label, kinda leaning towards not since hopefully people weren't using this and if they were they'll see the deprecation message

thanks @NthPortal and @ceedubs for your perseverance on this

@NthPortal NthPortal deleted the topic/deprecate-universal-equiv/PR branch December 5, 2018 08:29
@SethTisue SethTisue changed the title Deprecate universal Equiv Deprecate universal Equiv Apr 4, 2019
@SethTisue SethTisue added the release-notes worth highlighting in next release notes label Apr 4, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-notes worth highlighting in next release notes
Projects
None yet
6 participants