-
-
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
2.13.0-RC1 #2792
Merged
Merged
2.13.0-RC1 #2792
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
61718f3
Remove catalysts dependency
travisbrown b766494
Fix typo
travisbrown 46ef642
Fix platform-specific stuff in alleycats
travisbrown 7c6c243
Ugh, fix import
travisbrown 2311c79
Format
travisbrown d1666de
move to Scala 2.13.0-RC1 (drop -M5)
SethTisue 757c13b
Thanks to ScalaTest we temporarily need to use deprecated classes
travisbrown 7942148
Fix Hash instances to match changes in 2.13
travisbrown 7fdb2ce
Fix for 2.11
travisbrown d28da64
One last fix for 2.13
travisbrown abc53ce
Fix Hash instances in cats-core for 2.13
travisbrown a27ecfe
Tell scalastyle to ignore returns in copy-pasted MurmurHash3 code
travisbrown 5031281
Merge branch 'master' into update/2.13.0-RC1
travisbrown 8cd5abb
Merge branch 'master' into update/2.13.0-RC1
kailuowang 143a62b
Format build.sbt
travisbrown File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
kernel/src/main/scala-2.12-/cats/kernel/compat/HashCompat.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package cats | ||
package kernel | ||
package compat | ||
|
||
private[kernel] class HashCompat { | ||
// Adapted from scala.util.hashing.MurmurHash#productHash. | ||
private[kernel] def product1HashWithPrefix(_1Hash: Int, prefix: String): Int = { | ||
import scala.util.hashing.MurmurHash3._ | ||
var h = productSeed | ||
h = mix(h, _1Hash) | ||
finalizeHash(h, 1) | ||
} | ||
|
||
// Adapted from scala.util.hashing.MurmurHash#productHash. | ||
private[cats] def product2HashWithPrefix(_1Hash: Int, _2Hash: Int, prefix: String): Int = { | ||
import scala.util.hashing.MurmurHash3._ | ||
var h = productSeed | ||
h = mix(h, _1Hash) | ||
h = mix(h, _2Hash) | ||
finalizeHash(h, 2) | ||
} | ||
|
||
private[cats] def updateUnorderedHashC(c: Int, h: Int): Int = if (h != 0) c * h else c | ||
|
||
// adapted from [[scala.util.hashing.MurmurHash3]], | ||
// but modified standard `Any#hashCode` to `ev.hash`. | ||
def listHash[A](x: List[A])(implicit A: Hash[A]): Int = { | ||
import scala.util.hashing.MurmurHash3._ | ||
var n = 0 | ||
var h = seqSeed | ||
var elems = x | ||
while (!elems.isEmpty) { | ||
val head = elems.head | ||
val tail = elems.tail | ||
h = mix(h, A.hash(head)) | ||
n += 1 | ||
elems = tail | ||
} | ||
finalizeHash(h, n) | ||
} | ||
|
||
// adapted from scala.util.hashing.MurmurHash3 | ||
def orderedHash[A](xs: TraversableOnce[A])(implicit A: Hash[A]): Int = { | ||
import scala.util.hashing.MurmurHash3._ | ||
var n = 0 | ||
var h = seqSeed | ||
xs.foreach { x => | ||
h = mix(h, A.hash(x)) | ||
n += 1 | ||
} | ||
finalizeHash(h, n) | ||
} | ||
} |
116 changes: 116 additions & 0 deletions
116
kernel/src/main/scala-2.13+/cats/kernel/compat/HashCompat.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
package cats | ||
package kernel | ||
package compat | ||
|
||
private[kernel] class HashCompat { | ||
// Adapted from scala.util.hashing.MurmurHash#productHash. | ||
private[kernel] def product1HashWithPrefix(_1Hash: Int, prefix: String): Int = { | ||
import scala.util.hashing.MurmurHash3._ | ||
var h = productSeed | ||
h = mix(h, prefix.hashCode) | ||
h = mix(h, _1Hash) | ||
finalizeHash(h, 1) | ||
} | ||
|
||
// Adapted from scala.util.hashing.MurmurHash#productHash. | ||
private[cats] def product2HashWithPrefix(_1Hash: Int, _2Hash: Int, prefix: String): Int = { | ||
import scala.util.hashing.MurmurHash3._ | ||
var h = productSeed | ||
h = mix(h, prefix.hashCode) | ||
h = mix(h, _1Hash) | ||
h = mix(h, _2Hash) | ||
finalizeHash(h, 2) | ||
} | ||
|
||
private[cats] def updateUnorderedHashC(c: Int, h: Int): Int = c * (h | 1) | ||
|
||
// adapted from [[scala.util.hashing.MurmurHash3]], | ||
// but modified standard `Any#hashCode` to `ev.hash`. | ||
def listHash[A](x: List[A])(implicit A: Hash[A]): Int = { | ||
import scala.util.hashing.MurmurHash3.{finalizeHash, mix, rangeHash, seqSeed} | ||
var n = 0 | ||
var h = seqSeed | ||
var rangeState = 0 // 0 = no data, 1 = first elem read, 2 = has valid diff, 3 = invalid | ||
var rangeDiff = 0 | ||
var prev = 0 | ||
var initial = 0 | ||
var elems = x | ||
while (!elems.isEmpty) { | ||
val head = elems.head | ||
val tail = elems.tail | ||
val hash = A.hash(head) | ||
h = mix(h, hash) | ||
rangeState match { | ||
case 0 => | ||
initial = hash | ||
rangeState = 1 | ||
case 1 => | ||
rangeDiff = hash - prev | ||
rangeState = 2 | ||
case 2 => | ||
if (rangeDiff != hash - prev) rangeState = 3 | ||
case _ => | ||
} | ||
prev = hash | ||
n += 1 | ||
elems = tail | ||
} | ||
if (rangeState == 2) rangeHash(initial, rangeDiff, prev, seqSeed) | ||
else finalizeHash(h, n) | ||
} | ||
|
||
// adapted from scala.util.hashing.MurmurHash3 | ||
def orderedHash[A](xs: TraversableOnce[A])(implicit A: Hash[A]): Int = { | ||
import scala.util.hashing.MurmurHash3.{finalizeHash, mix, seqSeed} | ||
|
||
val it = xs.iterator | ||
var h = seqSeed | ||
// scalastyle:off | ||
if (!it.hasNext) return finalizeHash(h, 0) | ||
// scalastyle:on | ||
val x0 = it.next() | ||
// scalastyle:off | ||
if (!it.hasNext) return finalizeHash(mix(h, A.hash(x0)), 1) | ||
// scalastyle:on | ||
val x1 = it.next() | ||
|
||
val initial = A.hash(x0) | ||
h = mix(h, initial) | ||
val h0 = h | ||
var prev = A.hash(x1) | ||
val rangeDiff = prev - initial | ||
var i = 2 | ||
while (it.hasNext) { | ||
h = mix(h, prev) | ||
val hash = A.hash(it.next()) | ||
if (rangeDiff != hash - prev) { | ||
h = mix(h, hash) | ||
i += 1 | ||
while (it.hasNext) { | ||
h = mix(h, A.hash(it.next())) | ||
i += 1 | ||
} | ||
// scalastyle:off | ||
return finalizeHash(h, i) | ||
// scalastyle:on | ||
} | ||
prev = hash | ||
i += 1 | ||
} | ||
avalanche(mix(mix(h0, rangeDiff), prev)) | ||
} | ||
|
||
// adapted from scala.util.hashing.MurmurHash3 | ||
/** Force all bits of the hash to avalanche. Used for finalizing the hash. */ | ||
final protected def avalanche(hash: Int): Int = { | ||
var h = hash | ||
|
||
h ^= h >>> 16 | ||
h *= 0x85ebca6b | ||
h ^= h >>> 13 | ||
h *= 0xc2b2ae35 | ||
h ^= h >>> 16 | ||
|
||
h | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Just curious, was this an optimization opportunity you happen to come across or was it broken on RC1?
Also would it be simpler to just call
fa.ap(f)
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.
This is from @SethTisue's commit, but the issue is that 2.13 sees the
ap
definitions inFlatMap
andWriterTApply
as conflicting. I personally think picking out the appropriate implementation viasuper
is the right thing to do in this case, but I also don't think it matters much, and am happy to change it tofa.ap(f)
if you'd prefer.