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

Scala 3 port #1200

Draft
wants to merge 33 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
5cec4cf
Divide sources into Scala 2 and 3 folders. Everything "compiles"
Katrix Jun 17, 2021
bcf78cd
Drop support for Scala 2.12
Katrix Jun 21, 2021
0b4a91a
Remove Lazy and Strict for the most part
Katrix Jun 21, 2021
e5c89ac
Remove type providers and some other type parsing macros
Katrix Jun 21, 2021
f3298d6
Remove method forwarder macros (RecordArgs and co)
Katrix Jun 21, 2021
7eb3372
Remove lazy leftover
Katrix Jun 21, 2021
adeb26c
Implement nat.ToInt
Katrix Jun 21, 2021
d04f95b
Implement Nat implicit conversion
Katrix Jun 21, 2021
05f9231
Basic implementation for Generic and LabelledGeneric
Katrix Jun 23, 2021
1540eea
Change the encoding of FieldType
Katrix Jun 23, 2021
d8c783d
Editor artifact sneaking through from implementing Generic
Katrix Jun 23, 2021
42d38f2
Better type lambdas in Generic1
Katrix Jun 23, 2021
8ddb990
Oops
Katrix Jun 26, 2021
248afb4
Add type to easily create records and discriminated unions
Katrix Jun 26, 2021
81453b8
Add record and union construction
Katrix Jun 26, 2021
6b8376f
Implement most of Generic1
Katrix Jul 5, 2021
3fc4a0a
Removed `Witness`, `NatWith` and `WitnessWith`
Katrix Jul 6, 2021
8a7433e
Remove the poly macros
Katrix Jul 6, 2021
4a26841
Add helper to make Unions without macros
Katrix Jul 6, 2021
5683f2d
Move alacarte to examples
Katrix Jul 6, 2021
352f23e
Widen which doesn't work
Katrix Jul 11, 2021
72b8694
Implement record ops
Katrix Aug 2, 2021
317feea
Implement Default
Katrix Aug 2, 2021
aee7fff
Implement Typeable
Katrix Aug 2, 2021
6051fb2
Some cleanup
Katrix Aug 2, 2021
e1560af
Start of Annotations impl
Katrix Aug 3, 2021
6542a4c
Fix ambigous =:!= and <:!<
Katrix Aug 3, 2021
269c713
Fix most tests and examples on the Scala 2 side
Katrix Aug 4, 2021
b8d5f00
Fixed more tests
Katrix Aug 6, 2021
faa9ddf
More test fixes and such
Katrix Aug 12, 2021
008138b
Merge remote-tracking branch 'upsteam/main' into feature/scala-3-port
Katrix Aug 12, 2021
0fbadde
Update Scala 3 version and fix errors
Katrix Jul 17, 2022
832308b
Fix some warnings
Katrix Jul 22, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .jvmopts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
-Xms4g
-Xmx12g
-Xss4m
-Dsbt.color=always
-Dsbt.supershell=true
-Xms2g
-Xmx3g
-Xss4m
122 changes: 83 additions & 39 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import com.typesafe.sbt.SbtGit.GitKeys._
import sbtcrossproject.CrossProject

val Scala212 = "2.12.14"
val Scala213 = "2.13.6"
val Scala3 = "3.2.0-RC2"

commonSettings
noPublishSettings
crossScalaVersions := Nil

ThisBuild / organization := "com.chuusai"
ThisBuild / scalaVersion := Scala213
ThisBuild / crossScalaVersions := Seq(Scala212, Scala213)
ThisBuild / scalaVersion := Scala3
ThisBuild / crossScalaVersions := Seq(Scala213, Scala3)
ThisBuild / mimaFailOnNoPrevious := false

// GHA configuration
Expand Down Expand Up @@ -54,7 +54,7 @@ ThisBuild / githubWorkflowPublish := Seq(
)
)

Global / excludeLintKeys += coreNative / packageDoc / publishArtifact
//TODO Global / excludeLintKeys += coreNative / packageDoc / publishArtifact

addCommandAlias("root", ";project shapeless")
addCommandAlias("core", ";project coreJVM")
Expand All @@ -67,19 +67,17 @@ addCommandAlias("validateJS", ";coreJS/compile;coreJS/mimaReportBinaryIssues;cor
addCommandAlias("validateNative", ";coreNative/compile;nativeTest/run;examplesNative/compile")
addCommandAlias("runAll", ";examplesJVM/runAll")

def scalacOptionsAll(pluginJar: File) = List(
val scalacOptionsAll = List(
"-feature",
"-language:higherKinds,implicitConversions",
"-Xfatal-warnings",
"-deprecation",
"-unchecked",
s"-Xplugin:${pluginJar.getAbsolutePath}",
s"-Jdummy=${pluginJar.lastModified}"
"-unchecked"
)

val scalacOptions212 = Seq(
"-Xlint:-adapted-args,-delayedinit-select,-nullary-unit,-package-object-classes,-type-parameter-shadow,_",
"-Ywarn-unused:-implicits"
val scalacOptions3 = Seq(
"-language:dynamics",
"-Yretain-trees"
)

val scalacOptions213 = Seq(
Expand All @@ -90,11 +88,19 @@ val scalacOptions213 = Seq(
lazy val commonSettings = Seq(
incOptions := incOptions.value.withLogRecompileOnMacro(false),

scalacOptions := scalacOptionsAll((plugin / Compile / packageBin).value),
scalacOptions := scalacOptionsAll,

Compile / compile / scalacOptions ++= (CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, 12)) => scalacOptions212
case Some((2, 13)) => scalacOptions213
case Some((3, _)) => scalacOptions3
case _ => Nil
}),
Test / compile / scalacOptions ++= (CrossVersion.partialVersion(scalaVersion.value) match {
case Some((3, _)) => Seq("-Yretain-trees")
case _ => Nil
}),
libraryDependencies ++= (CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, _)) => scalaMacroDependencies.value
case _ => Nil
}),

Expand All @@ -112,7 +118,7 @@ lazy val commonSettings = Seq(
url("https://github.com/milessabin/shapeless"),
"scm:git:[email protected]:milessabin/shapeless.git"
))
) ++ crossVersionSharedSources ++ scalaMacroDependencies
) ++ crossVersionSharedSources

def configureJUnit(crossProject: CrossProject) = {
crossProject
Expand Down Expand Up @@ -151,18 +157,7 @@ lazy val CrossTypeMixed: sbtcrossproject.CrossType = new sbtcrossproject.CrossTy
Some(projectBase.getParentFile / "src" / conf / "scala")
}

lazy val plugin = project.in(file("plugin"))
.settings(crossVersionSharedSources)
.settings(publishSettings)
.settings(
name := "shapeless-plugin",
moduleName := "shapeless-plugin",
sbtPlugin := true,
scalaVersion := Scala213,
crossScalaVersions := Seq(Scala213, Scala212)
)

lazy val core = crossProject(JSPlatform, JVMPlatform, NativePlatform).crossType(CrossTypeMixed)
lazy val core = crossProject(JSPlatform, JVMPlatform/* TODO, NativePlatform*/).crossType(CrossTypeMixed)
.configureCross(configureJUnit)
.settings(moduleName := "shapeless")
.settings(coreSettings:_*)
Expand All @@ -173,6 +168,45 @@ lazy val core = crossProject(JSPlatform, JVMPlatform, NativePlatform).crossType(
.settings(mimaSettings:_*)
.jsSettings(commonJsSettings:_*)
.jvmSettings(commonJvmSettings:_*)
.jvmSettings(
Test / sources := (Test / sources).value.filter(f =>
Seq(
"testutil.scala",
"poly.scala",
//"serialization.scala", "serializationtestutils.scala", //Some errors
"adjoin.scala",
"annotation.scala",
//"constraints.scala", //Exponential errors?
"conversions.scala",
//"coproduct.scala",
"default.scala",
"fin.scala",
//"generic.scala",
//"hlist.scala",
//"hmap.scala",
//"labelledgeneric.scala",
//"LabelledGenericTests213.scala",
//"lenses.scala",
"monoid.scala",
"nat.scala",
//"natranges.scala",
"orelse.scala",
//"product.scala",
//"records.scala", //Tons of long errors. Maybe requires math?
"refute.scala",
//"singletons.scala", //Compiler crash
//"sized.scala", //Requires math
//"sybclass.scala", //Exponential errors?
//"tuples.scala", //Requires math
//"typeable.scala", //Seems broken for normal types?
"typeclass.scala",
//"typeoperators.scala",
"unions.scala",
//"unwrapped.scala", //Completely broken
"zipper.scala",
).contains(f.name))
)
/* TODO
.nativeSettings(
// disable scaladoc generation on native
// currently getting errors like
Expand All @@ -182,12 +216,13 @@ lazy val core = crossProject(JSPlatform, JVMPlatform, NativePlatform).crossType(
Compile / doc / sources := Nil,
Test / sources := Nil
)
*/

lazy val coreJVM = core.jvm
lazy val coreJS = core.js
lazy val coreNative = core.native
//TODO lazy val coreNative = core.native

lazy val scratch = crossProject(JSPlatform, JVMPlatform, NativePlatform).crossType(CrossTypeMixed)
lazy val scratch = crossProject(JSPlatform, JVMPlatform/* TODO, NativePlatform*/).crossType(CrossTypeMixed)
.configureCross(configureJUnit)
.dependsOn(core)
.settings(moduleName := "scratch")
Expand All @@ -198,7 +233,7 @@ lazy val scratch = crossProject(JSPlatform, JVMPlatform, NativePlatform).crossTy

lazy val scratchJVM = scratch.jvm
lazy val scratchJS = scratch.js
lazy val scratchNative = scratch.native
//TODO lazy val scratchNative = scratch.native

lazy val runAll = TaskKey[Unit]("runAll")

Expand All @@ -212,7 +247,7 @@ def runAllIn(config: Configuration): Setting[Task[Unit]] = {
}
}

lazy val examples = crossProject(JSPlatform, JVMPlatform, NativePlatform).crossType(CrossTypeMixed)
lazy val examples = crossProject(JSPlatform, JVMPlatform/* TODO, NativePlatform*/).crossType(CrossTypeMixed)
.configureCross(configureJUnit)
.dependsOn(core)
.settings(moduleName := "examples")
Expand All @@ -222,15 +257,20 @@ lazy val examples = crossProject(JSPlatform, JVMPlatform, NativePlatform).crossT
.settings(noPublishSettings:_*)
.jsSettings(commonJsSettings:_*)
.jvmSettings(commonJvmSettings:_*)
/*
TODO
.nativeSettings(
Compile / sources ~= (_.filterNot(_.getName == "sexp.scala")),
Test / sources := Nil
)
*/

lazy val examplesJVM = examples.jvm
lazy val examplesJS = examples.js
lazy val examplesNative = examples.native
//TODO lazy val examplesNative = examples.native

/*
TODO
lazy val nativeTest = project
.enablePlugins(ScalaNativePlugin)
.settings(
Expand Down Expand Up @@ -259,24 +299,28 @@ lazy val nativeTest = project
).dependsOn(
examplesNative
)
*/

lazy val scalaMacroDependencies: Seq[Setting[_]] = Seq(
libraryDependencies ++= Seq(
lazy val scalaMacroDependencies: Def.Initialize[Seq[ModuleID]] = Def.setting {
Seq(
scalaOrganization.value % "scala-reflect" % scalaVersion.value % "provided",
scalaOrganization.value % "scala-compiler" % scalaVersion.value % "provided"
)
)
}

lazy val crossVersionSharedSources: Seq[Setting[_]] =
Seq(Compile, Test).map { sc =>
(sc / unmanagedSourceDirectories) ++= {
(sc / unmanagedSourceDirectories) := {
(sc / unmanagedSourceDirectories).value.flatMap { dir: File =>
//Seems like cross projects don't get this source folder as well TODO: Make an issue for it
val scala2Folder = file(dir.getPath + "-2")

if (dir.getName != "scala") Seq(dir)
else CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, y)) if y >= 13 => Seq(new File(dir.getPath + "_2.13+"))
case Some((2, y)) if y < 13 => Seq(new File(dir.getPath + "_2.13-"))
case Some((2, _)) => Seq(dir, scala2Folder)
case _ => Seq(dir)
}
}
}.distinct
}
}

Expand Down Expand Up @@ -308,7 +352,7 @@ def buildInfoSetup(crossProject: CrossProject): CrossProject = {
buildInfoKeys := Seq[BuildInfoKey](version, scalaVersion, gitHeadCommit),
buildInfoOptions += BuildInfoOption.BuildTime
)
crossProject jvmConfigure transform jsConfigure transform nativeConfigure transform
crossProject jvmConfigure transform jsConfigure transform /*TODO nativeConfigure transform*/
}

lazy val coreOsgiSettings = osgiSettings ++ Seq(
Expand Down
15 changes: 15 additions & 0 deletions core/jvm/src/test/scala-2/shapeless/serialization.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package shapeless

import org.junit.Test

class SerializationTestsScala2 {
import SerializationTestDefns._

@Test
def testFunctor: Unit = {
assertSerializableBeforeAfter(Functor[Some])(_.map(Some(2))(_.toString))
assertSerializableBeforeAfter(Functor[Option])(_.map(Option(2))(_.toString))
assertSerializableBeforeAfter(Functor[Tree])(_.map(Leaf(2))(_.toString))
assertSerializableBeforeAfter(Functor[List])(_.map(List(2))(_.toString))
}
}
Loading