Skip to content

Commit 22dd38e

Browse files
authored
Merge pull request #2335 from kailuowang/update_to_2.13-M4
Updating to scala 2.13-M4
2 parents 16f9d81 + 228bbe1 commit 22dd38e

File tree

30 files changed

+314
-215
lines changed

30 files changed

+314
-215
lines changed

.jvmopts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
-Dfile.encoding=UTF8
22
-Xms1G
33
-Xmx6G
4-
-XX:MaxMetaspaceSize=512M
4+
-XX:MaxMetaspaceSize=4G
55
-XX:ReservedCodeCacheSize=250M
66
-XX:+TieredCompilation
77
-XX:-UseGCOverheadLimit

.travis.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,6 @@ scala:
1414
- 2.13.0-M4
1515
- 2.12.6
1616

17-
matrix:
18-
allow_failures:
19-
# There are known issues in this scala milestone release that prevent the tests to compile.
20-
# But we want to enable the build to facilitate debuging, esp on the community build.
21-
- scala: 2.13.0-M4
22-
2317
jdk:
2418
- oraclejdk8
2519

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package alleycats
2+
package compat
3+
4+
import scala.collection.generic.CanBuildFrom
5+
6+
abstract class IterableEmptyInstance {
7+
implicit def iterableIsEmpty[CC[X] <: Iterable[X], A](implicit cbf: CanBuildFrom[CC[A], A, CC[A]]): Empty[CC[A]] =
8+
Empty(cbf().result)
9+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package alleycats
2+
package compat
3+
4+
import collection.Factory
5+
6+
abstract class IterableEmptyInstance {
7+
implicit def iterableIsEmpty[CC[X] <: Iterable[X], A](implicit factory: Factory[A, CC[A]]): Empty[CC[A]] =
8+
Empty(factory.newBuilder.result)
9+
}

alleycats-core/src/main/scala/alleycats/Empty.scala

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,7 @@ object Empty extends EmptyInstances0 {
2121
new Empty[A] { lazy val empty: A = a }
2222
}
2323

24-
trait EmptyInstances0 extends EmptyInstances1 {
25-
implicit def iterableIsEmpty[CC[X] <: Iterable[X], A](implicit cbf: CanBuildFrom[CC[A], A, CC[A]]): Empty[CC[A]] =
26-
Empty(cbf().result)
27-
}
24+
trait EmptyInstances0 extends compat.IterableEmptyInstance with EmptyInstances1
2825

2926
trait EmptyInstances1 extends EmptyInstances2 {
3027
// If Monoid extended Empty then this could be an exported subclass instance provided by Monoid

build.sbt

Lines changed: 109 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -12,46 +12,78 @@ lazy val scoverageSettings = Seq(
1212

1313
organization in ThisBuild := "org.typelevel"
1414

15-
lazy val kernelSettings = Seq(
16-
scalacOptions ++= commonScalacOptions,
15+
lazy val commonSettings = Seq(
16+
scalacOptions ++= commonScalacOptions(scalaVersion.value),
17+
Compile / unmanagedSourceDirectories ++= {
18+
val bd = baseDirectory.value
19+
def extraDirs(suffix: String) =
20+
CrossType.Pure.sharedSrcDir(bd, "main").toList map (f => file(f.getPath + suffix))
21+
CrossVersion.partialVersion(scalaVersion.value) match {
22+
case Some((2, y)) if y <= 12 =>
23+
extraDirs("-2.12-")
24+
case Some((2, y)) if y >= 13 =>
25+
extraDirs("-2.13+")
26+
case _ => Nil
27+
}
28+
},
29+
coverageEnabled := {
30+
if(priorTo2_13(scalaVersion.value))
31+
coverageEnabled.value
32+
else
33+
false
34+
} ,
1735
resolvers ++= Seq(
1836
Resolver.sonatypeRepo("releases"),
1937
Resolver.sonatypeRepo("snapshots")),
2038
fork in test := true,
39+
libraryDependencies ++= Seq(
40+
"org.scala-lang.modules" %% "scala-collection-compat" % "0.1.1"),
2141
parallelExecution in Test := false,
22-
scalacOptions in (Compile, doc) := (scalacOptions in (Compile, doc)).value.filter(_ != "-Xfatal-warnings")
42+
scalacOptions in (Compile, doc) := (scalacOptions in (Compile, doc)).value.filter(_ != "-Xfatal-warnings"),
43+
//todo: reenable doctests on 2.13 once it's officially released. it's disabled for now due to changes to the `toString` impl of collections
44+
doctestGenTests := {
45+
val unchanged = doctestGenTests.value
46+
if(priorTo2_13(scalaVersion.value)) unchanged else Nil
47+
}
2348
) ++ warnUnusedImport ++ update2_12 ++ xlint
2449

25-
lazy val commonSettings = Seq(
50+
51+
52+
def macroDependencies(scalaVersion: String) =
53+
CrossVersion.partialVersion(scalaVersion) match {
54+
case Some((2, minor)) if minor < 13 => Seq(
55+
compilerPlugin("org.scalamacros" %% "paradise" % "2.1.0" cross CrossVersion.patch)
56+
)
57+
case _ => Seq()
58+
}
59+
60+
61+
lazy val catsSettings = Seq(
2662
incOptions := incOptions.value.withLogRecompileOnMacro(false),
27-
scalacOptions ++= commonScalacOptions,
2863
resolvers ++= Seq(
29-
"bintray/non" at "http://dl.bintray.com/non/maven",
30-
Resolver.sonatypeRepo("releases"),
31-
Resolver.sonatypeRepo("snapshots")
64+
"bintray/non" at "http://dl.bintray.com/non/maven"
3265
),
3366
libraryDependencies ++= Seq(
34-
"com.github.mpilquist" %%% "simulacrum" % "0.12.0" % Provided,
35-
"org.typelevel" %%% "machinist" % "0.6.4",
36-
compilerPlugin("org.scalamacros" %% "paradise" % "2.1.0" cross CrossVersion.patch),
37-
compilerPlugin("org.spire-math" %% "kind-projector" % "0.9.6")
38-
),
67+
"org.typelevel" %%% "machinist" % "0.6.5",
68+
compilerPlugin("org.spire-math" %% "kind-projector" % "0.9.7")) ++ macroDependencies(scalaVersion.value),
69+
70+
) ++ commonSettings ++ publishSettings ++ scoverageSettings ++ simulacrumSettings
71+
72+
73+
lazy val simulacrumSettings = Seq(
74+
libraryDependencies += "com.github.mpilquist" %%% "simulacrum" % "0.13.0" % Provided,
3975
pomPostProcess := { (node: xml.Node) =>
4076
new RuleTransformer(new RewriteRule {
4177
override def transform(node: xml.Node): Seq[xml.Node] = node match {
4278
case e: xml.Elem
4379
if e.label == "dependency" &&
44-
e.child.exists(child => child.label == "groupId" && child.text == "com.github.mpilquist") &&
45-
e.child.exists(child => child.label == "artifactId" && child.text.startsWith("simulacrum_")) => Nil
80+
e.child.exists(child => child.label == "groupId" && child.text == "com.github.mpilquist") &&
81+
e.child.exists(child => child.label == "artifactId" && child.text.startsWith("simulacrum_")) => Nil
4682
case _ => Seq(node)
4783
}
4884
}).transform(node).head
49-
},
50-
fork in test := true,
51-
parallelExecution in Test := false,
52-
scalacOptions in (Compile, doc) := (scalacOptions in (Compile, doc)).value.filter(_ != "-Xfatal-warnings")
53-
) ++ warnUnusedImport ++ update2_12 ++ xlint
54-
85+
}
86+
)
5587

5688
lazy val tagName = Def.setting{
5789
s"v${if (releaseUseGlobalVersion.value) (version in ThisBuild).value else version.value}"
@@ -93,28 +125,28 @@ lazy val includeGeneratedSrc: Setting[_] = {
93125
}
94126
}
95127

96-
lazy val catsSettings = commonSettings ++ publishSettings ++ scoverageSettings
97128

98-
lazy val scalaCheckVersion = "1.13.5"
99-
// 2.13.0-M3 workaround
100-
//lazy val scalaTestVersion = "3.0.5"
101-
lazy val disciplineVersion = "0.9.0"
102-
lazy val catalystsVersion = "0.6"
103129

104-
// 2.13.0-M3 workaround
130+
// 2.13.0-M4 workarounds
131+
def catalystsVersion(scalaVersion: String): String =
132+
if (priorTo2_13(scalaVersion)) "0.6" else "0.7"
133+
105134
def scalatestVersion(scalaVersion: String): String =
106-
CrossVersion.partialVersion(scalaVersion) match {
107-
case Some((2, 13)) => "3.0.5-M1"
108-
case _ => "3.0.5"
109-
}
135+
if (priorTo2_13(scalaVersion)) "3.0.5" else "3.0.6-SNAP1"
136+
137+
def scalaCheckVersion(scalaVersion: String): String =
138+
if (priorTo2_13(scalaVersion)) "1.13.5" else "1.14.0"
139+
140+
def disciplineVersion(scalaVersion: String): String =
141+
if (priorTo2_13(scalaVersion)) "0.9.0" else "0.10.0"
110142

111143
lazy val disciplineDependencies = Seq(
112-
libraryDependencies += "org.scalacheck" %%% "scalacheck" % scalaCheckVersion,
113-
libraryDependencies += "org.typelevel" %%% "discipline" % disciplineVersion)
144+
libraryDependencies += "org.scalacheck" %%% "scalacheck" % scalaCheckVersion(scalaVersion.value),
145+
libraryDependencies += "org.typelevel" %%% "discipline" % disciplineVersion(scalaVersion.value))
114146

115147
lazy val testingDependencies = Seq(
116-
libraryDependencies += "org.typelevel" %%% "catalysts-platform" % catalystsVersion,
117-
libraryDependencies += "org.typelevel" %%% "catalysts-macros" % catalystsVersion % "test",
148+
libraryDependencies += "org.typelevel" %%% "catalysts-platform" % catalystsVersion(scalaVersion.value),
149+
libraryDependencies += "org.typelevel" %%% "catalysts-macros" % catalystsVersion(scalaVersion.value) % "test",
118150
// 2.13.0-M3 workaround
119151
// libraryDependencies += "org.scalatest" %%% "scalatest" % scalaTestVersion % "test")
120152
libraryDependencies += "org.scalatest" %%% "scalatest" % scalatestVersion(scalaVersion.value) % "test")
@@ -215,9 +247,29 @@ def mimaSettings(moduleName: String) = {
215247
lazy val extraVersions: Set[String] = Set()
216248

217249
Seq(
218-
mimaPreviousArtifacts := (mimaVersions(version.value) ++ extraVersions)
219-
.filterNot(excludedVersions.contains(_))
220-
.map(v => "org.typelevel" %% moduleName % v)
250+
mimaPreviousArtifacts := { if(priorTo2_13(scalaVersion.value)) {
251+
(mimaVersions(version.value) ++ extraVersions)
252+
.filterNot(excludedVersions.contains(_))
253+
.map(v => "org.typelevel" %% moduleName % v)
254+
} else Set() },
255+
256+
mimaBinaryIssueFilters ++= {
257+
import com.typesafe.tools.mima.core._
258+
import com.typesafe.tools.mima.core.ProblemFilters._
259+
//Only sealed abstract classes that provide implicit instances to companion objects are allowed here, since they don't affect usage outside of the file.
260+
Seq(
261+
exclude[DirectMissingMethodProblem]("cats.data.OptionTInstances.catsDataMonadForOptionT"),
262+
exclude[DirectMissingMethodProblem]("cats.data.OptionTInstances2.catsDataTraverseForOptionT"),
263+
exclude[DirectMissingMethodProblem]("cats.data.KleisliInstances1.catsDataCommutativeArrowForKleisliId"),
264+
exclude[DirectMissingMethodProblem]("cats.data.OptionTInstances1.catsDataMonoidKForOptionT"),
265+
exclude[DirectMissingMethodProblem]("cats.data.OptionTInstances0.catsDataMonoidForOptionT"),
266+
exclude[DirectMissingMethodProblem]("cats.data.KleisliInstances0.catsDataMonadForKleisliId"),
267+
exclude[DirectMissingMethodProblem]("cats.data.KleisliInstances1.catsDataCommutativeArrowForKleisli"),
268+
exclude[DirectMissingMethodProblem]("cats.data.KleisliInstances4.catsDataCommutativeFlatMapForKleisli"),
269+
exclude[DirectMissingMethodProblem]("cats.data.IRWSTInstances1.catsDataStrongForIRWST"),
270+
exclude[DirectMissingMethodProblem]("cats.data.OptionTInstances1.catsDataMonadErrorMonadForOptionT")
271+
)
272+
}
221273
)
222274
}
223275

@@ -273,7 +325,7 @@ lazy val kernel = crossProject(JSPlatform, JVMPlatform, NativePlatform)
273325
.crossType(CrossType.Pure)
274326
.in(file("kernel"))
275327
.settings(moduleName := "cats-kernel", name := "Cats kernel")
276-
.settings(kernelSettings)
328+
.settings(commonSettings)
277329
.settings(publishSettings)
278330
.settings(scoverageSettings)
279331
.settings(sourceGenerators in Compile += (sourceManaged in Compile).map(KernelBoiler.gen).taskValue)
@@ -290,7 +342,7 @@ lazy val kernelLaws = crossProject(JSPlatform, JVMPlatform)
290342
.crossType(CrossType.Pure)
291343
.in(file("kernel-laws"))
292344
.settings(moduleName := "cats-kernel-laws", name := "Cats kernel laws")
293-
.settings(kernelSettings)
345+
.settings(commonSettings)
294346
.settings(publishSettings)
295347
.settings(scoverageSettings)
296348
.settings(disciplineDependencies)
@@ -310,9 +362,7 @@ lazy val core = crossProject(JSPlatform, JVMPlatform)
310362
.settings(catsSettings)
311363
.settings(sourceGenerators in Compile += (sourceManaged in Compile).map(Boilerplate.gen).taskValue)
312364
.settings(includeGeneratedSrc)
313-
.configureCross(disableScoverage210Jvm)
314-
.configureCross(disableScoverage210Js)
315-
.settings(libraryDependencies += "org.scalacheck" %%% "scalacheck" % scalaCheckVersion % "test")
365+
.settings(libraryDependencies += "org.scalacheck" %%% "scalacheck" % scalaCheckVersion(scalaVersion.value) % "test")
316366
.jsSettings(commonJsSettings)
317367
.jvmSettings(commonJvmSettings ++ mimaSettings("cats-core") )
318368

@@ -325,7 +375,6 @@ lazy val laws = crossProject(JSPlatform, JVMPlatform)
325375
.settings(moduleName := "cats-laws", name := "Cats laws")
326376
.settings(catsSettings)
327377
.settings(disciplineDependencies)
328-
.configureCross(disableScoverage210Jvm)
329378
.settings(testingDependencies)
330379
.jsSettings(commonJsSettings)
331380
.jvmSettings(commonJvmSettings)
@@ -443,7 +492,6 @@ lazy val js = project
443492
.settings(moduleName := "cats-js")
444493
.settings(catsSettings)
445494
.settings(commonJsSettings)
446-
.configure(disableScoverage210Js)
447495
.enablePlugins(ScalaJSPlugin)
448496

449497

@@ -593,22 +641,31 @@ lazy val crossVersionSharedSources: Seq[Setting[_]] =
593641
}
594642
}
595643

596-
lazy val commonScalacOptions = Seq(
597-
"-deprecation",
644+
def commonScalacOptions(scalaVersion: String) = Seq(
598645
"-encoding", "UTF-8",
599646
"-feature",
600647
"-language:existentials",
601648
"-language:higherKinds",
602649
"-language:implicitConversions",
603650
"-language:experimental.macros",
604651
"-unchecked",
605-
"-Xfatal-warnings",
606-
"-Yno-adapted-args",
607652
"-Ywarn-dead-code",
608653
"-Ywarn-numeric-widen",
609654
"-Ywarn-value-discard",
610655
"-Xfuture"
611-
)
656+
) ++ (if(priorTo2_13(scalaVersion)) Seq(
657+
"-Yno-adapted-args",
658+
"-Xfatal-warnings", //todo: add the following two back to 2.13
659+
"-deprecation"
660+
) else Seq(
661+
"-Ymacro-annotations"
662+
))
663+
664+
def priorTo2_13(scalaVersion: String): Boolean =
665+
CrossVersion.partialVersion(scalaVersion) match {
666+
case Some((2, minor)) if minor < 13 => true
667+
case _ => false
668+
}
612669

613670
lazy val sharedPublishSettings = Seq(
614671
releaseCrossBuild := true,
@@ -645,14 +702,7 @@ lazy val sharedReleaseProcess = Seq(
645702
)
646703

647704
lazy val warnUnusedImport = Seq(
648-
scalacOptions ++= {
649-
CrossVersion.partialVersion(scalaVersion.value) match {
650-
case Some((2, 10)) =>
651-
Seq()
652-
case Some((2, n)) if n >= 11 =>
653-
Seq("-Ywarn-unused-import")
654-
}
655-
},
705+
scalacOptions ++= Seq("-Ywarn-unused-import"),
656706
scalacOptions in (Compile, console) ~= {_.filterNot("-Ywarn-unused-import" == _)},
657707
scalacOptions in (Test, console) := (scalacOptions in (Compile, console)).value
658708
)
@@ -665,37 +715,6 @@ lazy val credentialSettings = Seq(
665715
} yield Credentials("Sonatype Nexus Repository Manager", "oss.sonatype.org", username, password)).toSeq
666716
)
667717

668-
def disableScoverage210Js(crossProject: CrossProject) =
669-
crossProject
670-
.jsSettings(
671-
coverageEnabled := {
672-
CrossVersion.partialVersion(scalaVersion.value) match {
673-
case Some((2, 10)) => false
674-
case _ => coverageEnabled.value
675-
}
676-
}
677-
)
678-
679-
def disableScoverage210Js: Project Project = p =>
680-
p.settings(
681-
coverageEnabled := {
682-
CrossVersion.partialVersion(scalaVersion.value) match {
683-
case Some((2, 10)) => false
684-
case _ => coverageEnabled.value
685-
}
686-
}
687-
)
688-
689-
def disableScoverage210Jvm(crossProject: CrossProject) =
690-
crossProject
691-
.jvmSettings(
692-
coverageEnabled := {
693-
CrossVersion.partialVersion(scalaVersion.value) match {
694-
case Some((2, 10)) => false
695-
case _ => coverageEnabled.value
696-
}
697-
}
698-
)
699718

700719
lazy val update2_12 = Seq(
701720
scalacOptions -= {
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package cats
2+
package compat
3+
4+
import scala.collection.immutable
5+
6+
7+
private[cats] object SortedSet {
8+
def zipWithIndex[A](s: immutable.SortedSet[A])(implicit A: Ordering[A]): immutable.SortedSet[(A, Int)] =
9+
s.zipWithIndex
10+
11+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package cats
2+
package compat
3+
4+
import scala.collection.immutable
5+
6+
private[cats] object SortedSet {
7+
def zipWithIndex[A](s: immutable.SortedSet[A])(implicit A: Ordering[A]): immutable.SortedSet[(A, Int)] =
8+
s.zipWithIndex.to(immutable.SortedSet)
9+
}

core/src/main/scala/cats/NonEmptyTraverse.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import simulacrum.typeclass
1919
* {{{
2020
* scala> import cats.implicits._
2121
* scala> import cats.data.NonEmptyList
22-
* scala> def countWords(words: List[String]): Map[String, Int] = words.groupBy(identity).mapValues(_.length)
22+
* scala> def countWords(words: List[String]): Map[String, Int] = words.groupBy(identity).map { case (k, v) => (k, v.length) }
2323
* scala> NonEmptyList.of(List("How", "do", "you", "fly"), List("What", "do", "you", "do")).nonEmptyTraverse(countWords)
2424
* res0: Map[String,cats.data.NonEmptyList[Int]] = Map(do -> NonEmptyList(1, 2), you -> NonEmptyList(1, 1))
2525
* }}}

0 commit comments

Comments
 (0)