Skip to content

Commit 4b562a8

Browse files
travisbrownkailuowang
authored andcommitted
2.13.0-RC1 (#2792)
* Remove catalysts dependency * Fix typo * Fix platform-specific stuff in alleycats * Ugh, fix import * Format * move to Scala 2.13.0-RC1 (drop -M5) * Thanks to ScalaTest we temporarily need to use deprecated classes * Fix Hash instances to match changes in 2.13 * Fix for 2.11 * One last fix for 2.13 * Fix Hash instances in cats-core for 2.13 * Tell scalastyle to ignore returns in copy-pasted MurmurHash3 code * Format build.sbt
1 parent 788a0cf commit 4b562a8

File tree

18 files changed

+200
-60
lines changed

18 files changed

+200
-60
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jdk:
1414

1515
scala_version_211: &scala_version_211 2.11.12
1616
scala_version_212: &scala_version_212 2.12.7
17-
scala_version_213: &scala_version_213 2.13.0-M5
17+
scala_version_213: &scala_version_213 2.13.0-RC1
1818

1919
before_install:
2020
- export PATH=${PATH}:./vendor/bundle

build.sbt

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,13 @@ lazy val catsSettings = Seq(
8383
"bintray/non".at("http://dl.bintray.com/non/maven")
8484
),
8585
libraryDependencies ++= Seq(
86-
"org.typelevel" %%% "machinist" % "0.6.6",
87-
compilerPlugin("org.spire-math" %% "kind-projector" % "0.9.9")
86+
"org.typelevel" %%% "machinist" % "0.6.7",
87+
compilerPlugin("org.typelevel" %% "kind-projector" % "0.10.0")
8888
) ++ macroDependencies(scalaVersion.value),
8989
) ++ commonSettings ++ publishSettings ++ scoverageSettings ++ simulacrumSettings
9090

9191
lazy val simulacrumSettings = Seq(
92-
libraryDependencies += "com.github.mpilquist" %%% "simulacrum" % "0.15.0" % Provided,
92+
libraryDependencies += "com.github.mpilquist" %%% "simulacrum" % "0.16.0" % Provided,
9393
pomPostProcess := { (node: xml.Node) =>
9494
new RuleTransformer(new RewriteRule {
9595
override def transform(node: xml.Node): Seq[xml.Node] = node match {
@@ -151,20 +151,19 @@ lazy val includeGeneratedSrc: Setting[_] = {
151151
}
152152
}
153153

154-
def scalatestVersion(scalaVersion: String): String =
155-
if (priorTo2_13(scalaVersion)) "3.0.5" else "3.0.6-SNAP5"
154+
val scalatestVersion = "3.0.8-RC2"
156155

157156
val scalaCheckVersion = "1.14.0"
158157

159-
val disciplineVersion = "0.10.0"
158+
val disciplineVersion = "0.11.1"
160159

161160
lazy val disciplineDependencies = Seq(
162161
libraryDependencies += "org.scalacheck" %%% "scalacheck" % scalaCheckVersion,
163162
libraryDependencies += "org.typelevel" %%% "discipline" % disciplineVersion
164163
)
165164

166165
lazy val testingDependencies = Seq(
167-
libraryDependencies += "org.scalatest" %%% "scalatest" % scalatestVersion(scalaVersion.value) % "test"
166+
libraryDependencies += "org.scalatest" %%% "scalatest" % scalatestVersion % "test"
168167
)
169168

170169
lazy val docsMappingsAPIDir = settingKey[String]("Name of subdirectory in site target directory for api docs")
@@ -549,6 +548,7 @@ lazy val tests = crossProject(JSPlatform, JVMPlatform)
549548
.settings(noPublishSettings)
550549
.jsSettings(commonJsSettings)
551550
.jvmSettings(commonJvmSettings)
551+
.settings(scalacOptions in Test := (scalacOptions in Test).value.filter(_ != "-Xfatal-warnings"))
552552

553553
lazy val testkit = crossProject(JSPlatform, JVMPlatform)
554554
.crossType(CrossType.Pure)
@@ -558,9 +558,10 @@ lazy val testkit = crossProject(JSPlatform, JVMPlatform)
558558
.settings(moduleName := "cats-testkit")
559559
.settings(catsSettings)
560560
.settings(disciplineDependencies)
561-
.settings(libraryDependencies += "org.scalatest" %%% "scalatest" % scalatestVersion(scalaVersion.value))
561+
.settings(libraryDependencies += "org.scalatest" %%% "scalatest" % scalatestVersion)
562562
.jsSettings(commonJsSettings)
563563
.jvmSettings(commonJvmSettings)
564+
.settings(scalacOptions := scalacOptions.value.filter(_ != "-Xfatal-warnings"))
564565

565566
lazy val alleycatsCore = crossProject(JSPlatform, JVMPlatform)
566567
.crossType(CrossType.Pure)
@@ -596,6 +597,7 @@ lazy val alleycatsTests = crossProject(JSPlatform, JVMPlatform)
596597
.settings(noPublishSettings)
597598
.jsSettings(commonJsSettings)
598599
.jvmSettings(commonJvmSettings)
600+
.settings(scalacOptions in Test := (scalacOptions in Test).value.filter(_ != "-Xfatal-warnings"))
599601

600602
// bench is currently JVM-only
601603

@@ -628,7 +630,7 @@ lazy val binCompatTest = project
628630
else //We are not testing BC on Scala 2.13 yet.
629631
"org.typelevel" %% "cats-core" % version.value % Provided
630632
},
631-
"org.scalatest" %%% "scalatest" % scalatestVersion(scalaVersion.value) % Test
633+
"org.scalatest" %%% "scalatest" % scalatestVersion % Test
632634
)
633635
)
634636
.dependsOn(core.jvm % Test)

core/src/main/scala/cats/ApplicativeError.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ trait ApplicativeError[F[_], E] extends Applicative[F] {
8282
* `F[A]` values.
8383
*/
8484
def recover[A](fa: F[A])(pf: PartialFunction[E, A]): F[A] =
85-
handleErrorWith(fa)(e => (pf.andThen(pure)).applyOrElse(e, raiseError))
85+
handleErrorWith(fa)(e => (pf.andThen(pure _)).applyOrElse(e, raiseError _))
8686

8787
/**
8888
* Recover from certain errors by mapping them to an `F[A]` value.

core/src/main/scala/cats/MonadError.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ trait MonadError[F[_], E] extends ApplicativeError[F, E] with Monad[F] {
4444
* ApplicativeError in Cats 2.0: see [[https://github.com/typelevel/cats/issues/2685]]
4545
*/
4646
def adaptError[A](fa: F[A])(pf: PartialFunction[E, E]): F[A] =
47-
recoverWith(fa)(pf.andThen(raiseError))
47+
recoverWith(fa)(pf.andThen(raiseError[A] _))
4848

4949
/**
5050
* Inverse of `attempt`

core/src/main/scala/cats/data/WriterT.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,9 @@ sealed private[data] trait WriterTFlatMap1[F[_], L] extends WriterTApply[F, L] w
357357
implicit override def F0: FlatMap[F]
358358
implicit def L0: Monoid[L]
359359

360+
override def ap[A, B](f: WriterT[F, L, A => B])(fa: WriterT[F, L, A]): WriterT[F, L, B] =
361+
super[WriterTApply].ap(f)(fa)
362+
360363
def flatMap[A, B](fa: WriterT[F, L, A])(f: A => WriterT[F, L, B]): WriterT[F, L, B] =
361364
fa.flatMap(f)
362365

core/src/main/scala/cats/instances/sortedMap.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,10 @@ class SortedMapHash[K, V](implicit V: Hash[V], O: Order[K], K: Hash[K])
134134
var c = 1
135135
x.foreach {
136136
case (k, v) =>
137-
val h = StaticMethods.product2Hash(K.hash(k), V.hash(v))
137+
val h = StaticMethods.product2HashWithPrefix(K.hash(k), V.hash(v), "Tuple2")
138138
a += h
139139
b ^= h
140-
if (h != 0) c *= h
140+
c = StaticMethods.updateUnorderedHashC(c, h)
141141
n += 1
142142
}
143143
var h = mapSeed

core/src/main/scala/cats/instances/sortedSet.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ class SortedSetHash[A: Order: Hash] extends Hash[SortedSet[A]] {
103103
val h = Hash[A].hash(x)
104104
a += h
105105
b ^= h
106-
if (h != 0) c *= h
106+
c = cats.kernel.instances.StaticMethods.updateUnorderedHashC(c, h)
107107
n += 1
108108
}
109109
var h = setSeed

core/src/main/scala/cats/syntax/applicativeError.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,5 +123,5 @@ final class ApplicativeErrorOps[F[_], E, A](private val fa: F[A]) extends AnyVal
123123
* to `ApplicativeError` in Cats 2.0: see [[https://github.com/typelevel/cats/issues/2685]]
124124
*/
125125
def adaptErr(pf: PartialFunction[E, E])(implicit F: ApplicativeError[F, E]): F[A] =
126-
F.recoverWith(fa)(pf.andThen(F.raiseError))
126+
F.recoverWith(fa)(pf.andThen(F.raiseError[A] _))
127127
}

core/src/main/scala/cats/syntax/monadError.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ final class MonadErrorOps[F[_], E, A](private val fa: F[A]) extends AnyVal {
2424
*/
2525
def reject(pf: PartialFunction[A, E])(implicit F: MonadError[F, E]): F[A] =
2626
F.flatMap(fa) { a =>
27-
pf.andThen(F.raiseError[A]).applyOrElse(a, (_: A) => fa)
27+
pf.andThen(F.raiseError[A] _).applyOrElse(a, (_: A) => fa)
2828
}
2929

3030
def adaptError(pf: PartialFunction[E, E])(implicit F: MonadError[F, E]): F[A] =
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package cats
2+
package kernel
3+
package compat
4+
5+
private[kernel] class HashCompat {
6+
// Adapted from scala.util.hashing.MurmurHash#productHash.
7+
private[kernel] def product1HashWithPrefix(_1Hash: Int, prefix: String): Int = {
8+
import scala.util.hashing.MurmurHash3._
9+
var h = productSeed
10+
h = mix(h, _1Hash)
11+
finalizeHash(h, 1)
12+
}
13+
14+
// Adapted from scala.util.hashing.MurmurHash#productHash.
15+
private[cats] def product2HashWithPrefix(_1Hash: Int, _2Hash: Int, prefix: String): Int = {
16+
import scala.util.hashing.MurmurHash3._
17+
var h = productSeed
18+
h = mix(h, _1Hash)
19+
h = mix(h, _2Hash)
20+
finalizeHash(h, 2)
21+
}
22+
23+
private[cats] def updateUnorderedHashC(c: Int, h: Int): Int = if (h != 0) c * h else c
24+
25+
// adapted from [[scala.util.hashing.MurmurHash3]],
26+
// but modified standard `Any#hashCode` to `ev.hash`.
27+
def listHash[A](x: List[A])(implicit A: Hash[A]): Int = {
28+
import scala.util.hashing.MurmurHash3._
29+
var n = 0
30+
var h = seqSeed
31+
var elems = x
32+
while (!elems.isEmpty) {
33+
val head = elems.head
34+
val tail = elems.tail
35+
h = mix(h, A.hash(head))
36+
n += 1
37+
elems = tail
38+
}
39+
finalizeHash(h, n)
40+
}
41+
42+
// adapted from scala.util.hashing.MurmurHash3
43+
def orderedHash[A](xs: TraversableOnce[A])(implicit A: Hash[A]): Int = {
44+
import scala.util.hashing.MurmurHash3._
45+
var n = 0
46+
var h = seqSeed
47+
xs.foreach { x =>
48+
h = mix(h, A.hash(x))
49+
n += 1
50+
}
51+
finalizeHash(h, n)
52+
}
53+
}

0 commit comments

Comments
 (0)