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

Scala3/kernel+core #1192

Merged
merged 51 commits into from
Jan 15, 2024
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
c0487b9
Prepare Scala 3 cross-compilation
DoSOfRedRiver May 29, 2023
be02b88
Dispatch traits preparation.
dos65 Jul 11, 2023
0127f32
WIP: prepared kernel to scala3.
Gryum Jul 11, 2023
658f0d9
Working on coreCE2.
dos65 Jul 31, 2023
55ee0d1
Updated scalafmt
Grryum Sep 11, 2023
a42ab44
Kernel macros finally done.
Grryum Sep 11, 2023
324df9e
CE2 main code prepared for scala3.
Grryum Sep 11, 2023
0a8c130
Adopted coreCE2 module and added macro with argument application.
Grryum Sep 13, 2023
442049f
Added implicit arguments apply.
Grryum Sep 19, 2023
146313d
WIP: most of macros prepared, working on problem with path dependent …
Grryum Sep 24, 2023
8f350ac
Solved path dependent type problem with asInstanceOf on macro site.
dos65 Nov 1, 2023
e8c594c
Finally coreCE2 migration done!!!
Grryum Nov 1, 2023
186759f
coreCE3 adopt.
Grryum Nov 2, 2023
6284e2e
Migrate ZIO2 interop to Scala 3.
Grryum Nov 7, 2023
d9c3600
Collect garbage.
Grryum Nov 7, 2023
8d4a577
Uncomment early failed test.
Grryum Nov 8, 2023
bbd942c
FIxed unused imports.
Grryum Nov 17, 2023
fa7803a
Fixed compat.unused.
Grryum Nov 18, 2023
1d7f2b2
Scala fmt tuning and applying..
Grryum Nov 18, 2023
5ac1787
Fixed kernel test.
Grryum Nov 19, 2023
0f3d2bd
Setup tpolecat plugin, fix warnings.
Grryum Nov 20, 2023
e195750
Fix fmt.
Grryum Nov 20, 2023
fdd1c2a
Revert scalafix cfg.
Grryum Nov 20, 2023
1428ce9
Fixed typo bug.
Grryum Nov 21, 2023
d89d8aa
Silenced scala3-migration warnings.
Grryum Nov 21, 2023
c212520
Fixed cross compile warnings.
Grryum Nov 22, 2023
ea26dbe
Reverted zio2 logging and fixed build settings.
Grryum Nov 22, 2023
77424f2
Fixed warnings.
Grryum Nov 22, 2023
db23143
Refactored build.sbt for future.
Grryum Nov 22, 2023
79fc2ae
Trying to fix mystery bug.
Grryum Nov 22, 2023
c327f77
instanceOf for the instance of God
road21 Nov 22, 2023
8d2eb06
fix
road21 Nov 22, 2023
e88a1c9
Logback & slf4j version bump.
Grryum Nov 22, 2023
49b3eb4
Revert cast logger fix error attempt.
Grryum Nov 22, 2023
c074819
Disable zio2 logging test.
Grryum Nov 22, 2023
7d105eb
Disable warnings as fatal errors on docs/mdoc.
Grryum Nov 22, 2023
3f9f8cb
Merge pull request #1 from road21/scala3/kernel+core-instance-of-fix
Grryum Nov 23, 2023
9e4b74f
Refactored fatal warnings options.
Grryum Nov 23, 2023
9ea59d3
Slight Interop refactoring.
Grryum Nov 23, 2023
95ea831
widen, not instance of
road21 Nov 23, 2023
5573a4d
Merge pull request #2 from road21/scala3/kernel+core-widen
Grryum Nov 23, 2023
29d07a3
sbt version bump
Grryum Nov 24, 2023
1fb0e66
ci updated.
Grryum Nov 24, 2023
dc60aa2
Added sbt-projectmatrix plugin.
Grryum Nov 25, 2023
dfdc886
Setup project matrix builds and ci.
Grryum Nov 27, 2023
82e0454
Fixed -Ykind-projector set repeatedly.
Grryum Nov 27, 2023
3a51e77
One more warnings fix.
Grryum Nov 27, 2023
2f3c425
scala3: fix Do monad inc compilation issues
dos65 Nov 27, 2023
c3adf17
Merge pull request #4 from Grryum/scala3/ci
Grryum Nov 28, 2023
bd1411b
Added RepresentableK instances with hand implementation without macros.
Grryum Dec 4, 2023
5afa3de
Enable docs generation.
Grryum Dec 11, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion .scalafix.conf
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ OrganizeImports {
removeUnused = true
groups = ["re:javax?\\.", "scala.", "tofu." "*"]
groupedImports = AggressiveMerge
}
}
10 changes: 9 additions & 1 deletion .scalafmt.conf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,15 @@ maxColumn = 120
includeCurlyBraceInSelectChains = false
align.preset = most
version = "3.7.11"
runner.dialect = scala213
runner.dialect = scala213source3
trailingCommas = preserve
newlines.penalizeSingleSelectMultiArgList = false
newlines.alwaysBeforeMultilineDef = false
fileOverride {
"glob:**/scala-2.12/**.scala" {
runner.dialect = scala212source3
}
"glob:**/scala-3/**.scala" {
runner.dialect = scala3
}
}
100 changes: 61 additions & 39 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import Publish._, Dependencies._
import sbt.ModuleID
import org.typelevel.scalacoptions.{ScalacOption, ScalaVersion, ScalacOptions}
import scala.Ordering.Implicits._

lazy val setMinorVersion = minorVersion := {
CrossVersion.partialVersion(scalaVersion.value) match {
Expand All @@ -9,38 +11,50 @@ lazy val setMinorVersion = minorVersion := {
}

lazy val defaultSettings = Seq(
scalaVersion := Version.scala213,
crossScalaVersions := Vector(Version.scala212, Version.scala213),
scalaVersion := Version.scala3,
setMinorVersion,
defaultScalacOptions,
scalacWarningConfig,
Compile / doc / scalacOptions -= "-Xfatal-warnings",
libraryDependencies ++= Seq(
compilerPlugin(kindProjector),
compilerPlugin(betterMonadicFor),
scalatest,
collectionCompat,
scalaOrganization.value % "scala-reflect" % scalaVersion.value % Provided
)
) ++ macros
Test / tpolecatExcludeOptions += ScalacOptions.warnNonUnitStatement,
Compile / doc / tpolecatExcludeOptions += ScalacOptions.fatalWarnings,
crossScalaVersions := Vector(Version.scala212, Version.scala213),
libraryDependencies ++= {
(CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, n)) =>
Seq(
compilerPlugin(betterMonadicFor),
compilerPlugin(kindProjector),
scalaOrganization.value % "scala-reflect" % scalaVersion.value % Provided
)
case _ => Seq()
}) ++ Seq(scalatest, collectionCompat)
}
) ++ macros ++ defaultScalacOptions

val modules = file("modules")

lazy val higherKindCore = project
.in(modules / "kernel" / "higherKind")
.settings(
defaultSettings,
name := "tofu-core-higher-kind",
libraryDependencies ++= Seq(catsCore, catsFree, catsTagless),
crossScalaVersions := Vector(Version.scala212, Version.scala213, Version.scala3),
name := "tofu-core-higher-kind",
libraryDependencies ++= {
CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, n)) =>
Seq(catsCore, catsFree, catsTaglessMacros)
case _ =>
Seq(catsCore, catsFree, catsTaglessCore)
}
},
)

lazy val kernel = project
.in(modules / "kernel")
.settings(defaultSettings)
.dependsOn(higherKindCore)
.settings(
defaultSettings,
name := "tofu-kernel",
crossScalaVersions := Vector(Version.scala212, Version.scala213, Version.scala3),
name := "tofu-kernel",
libraryDependencies += glassCore
)

Expand All @@ -49,7 +63,8 @@ lazy val coreCE2 = project
.dependsOn(kernel)
.settings(
defaultSettings,
name := "tofu-core-ce2",
crossScalaVersions := Vector(Version.scala212, Version.scala213, Version.scala3),
name := "tofu-core-ce2",
libraryDependencies += catsEffect2
)

Expand All @@ -59,7 +74,7 @@ lazy val concurrentCE2 =
.dependsOn(coreCE2, derivation % "compile->test")
.settings(
defaultSettings,
libraryDependencies ++= Seq(catsEffect2, catsTagless),
libraryDependencies ++= Seq(catsEffect2, catsTaglessMacros),
libraryDependencies ++= Seq(simulacrum, derevoTagless, glassMacro).map(_ % Test),
name := "tofu-concurrent-ce2",
)
Expand All @@ -69,7 +84,8 @@ lazy val coreCE3 = project
.dependsOn(kernel)
.settings(
defaultSettings,
name := "tofu-core-ce3",
crossScalaVersions := Vector(Version.scala212, Version.scala213, Version.scala3),
name := "tofu-core-ce3",
libraryDependencies += catsEffect3
)

Expand All @@ -96,7 +112,7 @@ lazy val loggingStr = project
alleycats,
scalatest,
derevo,
catsTagless
catsTaglessMacros
),
)
.dependsOn(kernel)
Expand Down Expand Up @@ -238,7 +254,7 @@ lazy val derivation =
.in(modules / "derivation")
.settings(
defaultSettings,
libraryDependencies ++= Seq(magnolia, derevo, catsTagless),
libraryDependencies ++= Seq(magnolia, derevo, catsTaglessMacros),
name := "tofu-derivation",
)
.dependsOn(kernel)
Expand Down Expand Up @@ -440,24 +456,24 @@ lazy val tofu = project
)
.dependsOn(coreModules.map(x => x: ClasspathDep[ProjectReference]): _*)

lazy val defaultScalacOptions = scalacOptions := {
val tpolecatOptions = scalacOptions.value

val dropLints = Set(
"-Ywarn-dead-code",
"-Wdead-code" // ignore dead code paths where `Nothing` is involved
lazy val defaultScalacOptions =
Seq(
tpolecatScalacOptions ++= Set(
ScalacOption("-Ykind-projector:underscores", _ >= ScalaVersion.V3_0_0),
ScalacOption("-P:kind-projector:underscore-placeholders", _ < ScalaVersion.V3_0_0),
ScalacOptions.source3,
ScalacOption("-Xmigration", _ < ScalaVersion.V3_0_0)
),
tpolecatExcludeOptions ++= Set(ScalacOptions.warnDeadCode, ScalacOptions.privateWarnDeadCode),
tpolecatExcludeOptions ++= (
if (!sys.env.get("CI").contains("true") || (minorVersion.value == 12))
Set(ScalacOptions.fatalWarnings)
else
Set.empty
)
)

val opts = tpolecatOptions.filterNot(dropLints)

// drop `-Xfatal-warnings` on dev and 2.12 CI
if (!sys.env.get("CI").contains("true") || (minorVersion.value == 12))
opts.filterNot(Set("-Xfatal-warnings"))
else
opts
}

lazy val scalacWarningConfig = scalacOptions += {
lazy val scalacWarningConfig = tpolecatScalacOptions ++= {
// // ignore unused imports that cannot be removed due to cross-compilation
// val suppressUnusedImports = Seq(
// "scala/tofu/config/typesafe.scala"
Expand All @@ -469,13 +485,19 @@ lazy val scalacWarningConfig = scalacOptions += {
val contextDeprecationInfo = "cat=deprecation&msg=^(.*((Has)|(With)|(Logging)).*)$:silent"
val verboseWarnings = "any:wv"

s"-Wconf:$contextDeprecationInfo,$verboseWarnings"
Set(
ScalacOption(s"-Wconf:$contextDeprecationInfo", _ >= ScalaVersion.V3_0_0),
ScalacOption(s"-Wconf:$contextDeprecationInfo,$verboseWarnings", _ < ScalaVersion.V3_0_0)
)
}

ThisBuild / libraryDependencySchemes += "io.circe" %% "circe-core" % "early-semver"

lazy val macros = Seq(
scalacOptions ++= { if (minorVersion.value == 13) Seq("-Ymacro-annotations") else Seq() },
tpolecatScalacOptions += ScalacOption(
"-Ymacro-annotations",
_.isBetween(ScalaVersion.V2_13_0, ScalaVersion.V3_0_0)
),
libraryDependencies ++= { if (minorVersion.value == 12) Seq(compilerPlugin(macroParadise)) else Seq() }
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ final case class SerialSemRef[F[_]: Monad, A](ref: Ref[F, A], sem: Semaphore[F])
* `G[_]`, but can be created for some `F[_]`, for which an instance of [[tofu.lift.Lift]] `Lift[F, G]` is present,
* this implementation can be used
*/
final case class UnderlyingSemRef[F[_]: Functor, G[_]: Monad: Lift[F, *[_]], A](ref: Ref[F, A], sem: Semaphore[F])
final case class UnderlyingSemRef[
F[_]: Functor,
G[_]: Monad: ({ type L[x[_]] = Lift[F, x] })#L,
A
](ref: Ref[F, A], sem: Semaphore[F])
extends SerialAgent[G, A] {
override def get: G[A] = ref.get.lift[G]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,20 @@ package tofu
package interop

import java.util.concurrent.TimeUnit

import scala.concurrent.duration.FiniteDuration
import scala.concurrent.{ExecutionContext, Future}

import cats.effect._
import cats.effect.concurrent.{MVar, Ref}
import cats.effect.{
Async,
Blocker,
Bracket,
Concurrent,
ConcurrentEffect,
ContextShift,
Effect,
ExitCase,
Fiber,
IO,
Sync,
Timer
}
import cats.{Functor, Id, Monad, Parallel, Traverse, ~>}
import tofu.compat.unused
import tofu.concurrent._
import tofu.internal.NonTofu
import tofu.internal.carriers._
import tofu.internal.instances.PerformViaUnlift
import tofu.lift.Lift
import tofu.syntax.monadic._
import tofu.internal.instances.PerformViaUnlift

object CE2Kernel {
// 2.12 sometimes gets mad on Const partial alias during implicit search
Expand All @@ -51,8 +40,8 @@ object CE2Kernel {

final implicit def finallyFromBracket[F[_], E](implicit
F: Bracket[F, E]
): FinallyCarrier2.Aux[F, E, CEExit[E, *]] =
new FinallyCarrier2.Impl[F, E, CEExit[E, *]] {
): FinallyCarrier2.Aux[F, E, CEExit[E, _]] =
new FinallyCarrier2.Impl[F, E, CEExit[E, _]] {
def finallyCase[A, B, C](init: F[A])(action: A => F[B])(release: (A, CEExit[E, B]) => F[C]): F[B] =
F.bracketCase(init)(action) { case (a, exit) =>
F.void(release(a, exit))
Expand All @@ -67,8 +56,8 @@ object CE2Kernel {
final def startFromConcurrent[F[_]](implicit
F: Concurrent[F],
@unused _nonTofu: NonTofu[F]
): FibersCarrier2.Aux[F, Id, Fiber[F, *]] =
new FibersCarrier2.Impl[F, Id, Fiber[F, *]] {
): FibersCarrier2.Aux[F, Id, Fiber[F, _]] =
new FibersCarrier2.Impl[F, Id, Fiber[F, _]] {
def start[A](fa: F[A]): F[Fiber[F, A]] = F.start(fa)
def fireAndForget[A](fa: F[A]): F[Unit] = F.void(start(fa))
def racePair[A, B](fa: F[A], fb: F[B]): F[Either[(A, Fiber[F, B]), (Fiber[F, A], B)]] = F.racePair(fa, fb)
Expand Down Expand Up @@ -133,7 +122,7 @@ object CE2Kernel {
F: ContextConcurrentEffect[F],
@unused _nt: NonTofu[F]
): PerformCarrier2Context[F] =
new PerformViaUnlift[F, F.Base, PerformOf.ExitCont[Throwable, *], Unit]()(
new PerformViaUnlift[F, F.Base, PerformOf.ExitCont[Throwable, _], Unit]()(
performConcurrentEffect[F.Base](F.concurrentEffect, NonTofu.refute),
F.unlift,
F.apply
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ object ContextConcurrentEffect {
final type Base[A] = B[A]
}

implicit def resolveReaderTConcurrentEffect[F[_]: ConcurrentEffect, C]: Impl[ReaderT[F, C, *], F] =
new Impl[ReaderT[F, C, *], F]
implicit def resolveReaderTConcurrentEffect[F[_]: ConcurrentEffect, C]: Impl[ReaderT[F, C, _], F] =
new Impl[ReaderT[F, C, _], F]
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import cats.effect.Bracket
import cats.effect.Fiber
import cats.data.Ior
import tofu.kernel.KernelTypes
import cats.Id

package object tofu extends KernelTypes {
package object tofu extends tofu.kernel.KernelTypes {

type BracketThrow[F[_]] = Bracket[F, Throwable]

type IorC[C[_], E, A] = Ior[C[E], C[A]]

type Start[F[_]] = Fibers[F, Id, Fiber[F, *]]
type Start[F[_]] = Fibers[F, Id, Fiber[F, _]]

type Timeout[F[_]] = tofu.time.Timeout[F]

Expand Down
45 changes: 0 additions & 45 deletions modules/core/ce2/src/test/scala-2/tofu/ContextSuite.scala

This file was deleted.

Loading
Loading