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

add identity hash to alleycats #3944

Merged
merged 3 commits into from
Oct 1, 2021
Merged

Conversation

SimY4
Copy link
Contributor

@SimY4 SimY4 commented Jul 17, 2021

This is a follow-up PR based on the discussion in #3925

To compliment ReferentialEq I've added SystemIdentityHash to JVM alleycats.

Copy link
Member

@armanbilge armanbilge left a comment

Choose a reason for hiding this comment

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

Just saw this, nice addition and clean-up on my PR! I don't think anything is supposed to go in the .jvm folder. The correct way to handle this is to change the build to a full cross with a proper jvm folder. Is System.identityHash not available on Scala.js and/or Native?

Also in your clean up efforts you removed ReferentialEqTests, I'm surprised the test suite passed (must be chance?) since it actually doesn't satisfy all the Eq laws.


import cats.Hash

class SystemIdentityHash[A <: AnyRef] extends ReferentialEq[A] with Hash[A] {
Copy link
Member

Choose a reason for hiding this comment

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

Maybe just me, but perhaps make it a trait so that it can be mixed with other instances?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't mind either way. I'll modify the change

@armanbilge
Copy link
Member

I checked and System.identityHashCode is available on both Scala.js and Native.

@SimY4 SimY4 force-pushed the topic/identity-hash branch 2 times, most recently from 34fdf93 to c3e35de Compare August 7, 2021 04:14
armanbilge
armanbilge previously approved these changes Aug 7, 2021
Copy link
Member

@armanbilge armanbilge left a comment

Choose a reason for hiding this comment

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

Thanks for addressing all the PR comments, nice work! ✅ but please add a quick scaladoc to SystemIdentityHash.

@SimY4
Copy link
Contributor Author

SimY4 commented Aug 8, 2021

The thing that I haven't implemented but could be potential optimisation is: merge both ReferentialEq and SystemIdentityHash into one alleycats definition since they are very closely related.

@armanbilge
Copy link
Member

merge both ReferentialEq and SystemIdentityHash into one alleycats definition since they are very closely related

I think it's fine to have them as separate traits, more modular :) As it was pointed out in the original PR #3925 (comment) using typeclasses isn't particularly performant anyway!

@johnynek johnynek merged commit 8e98f0b into typelevel:main Oct 1, 2021
@SimY4 SimY4 deleted the topic/identity-hash branch October 4, 2021 02:58
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