Skip to content

Commit

Permalink
support scala 3 (#456)
Browse files Browse the repository at this point in the history
  • Loading branch information
sirocchj authored Mar 14, 2022
1 parent 988cc56 commit 4bf97d7
Show file tree
Hide file tree
Showing 18 changed files with 226 additions and 215 deletions.
16 changes: 15 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,18 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
scala: [2.12.15, 2.13.8]
scala: [2.12.15, 2.13.8, 3.1.1]
java: [temurin@8, temurin@11, temurin@17]
project: [rootJVM]
exclude:
- scala: 2.12.15
java: temurin@11
- scala: 2.12.15
java: temurin@17
- scala: 3.1.1
java: temurin@11
- scala: 3.1.1
java: temurin@17
runs-on: ${{ matrix.os }}
steps:
- name: Checkout current branch (full)
Expand Down Expand Up @@ -252,6 +256,16 @@ jobs:
tar xf targets.tar
rm targets.tar
- name: Download target directories (3.1.1, rootJVM)
uses: actions/download-artifact@v2
with:
name: target-${{ matrix.os }}-${{ matrix.java }}-3.1.1-rootJVM

- name: Inflate target directories (3.1.1, rootJVM)
run: |
tar xf targets.tar
rm targets.tar
- name: Import signing key
if: env.PGP_SECRET != '' && env.PGP_PASSPHRASE == ''
run: echo $PGP_SECRET | base64 -di | gpg --import
Expand Down
16 changes: 8 additions & 8 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
val scala_212 = "2.12.15"
val scala_213 = "2.13.8"
val scala_3 = "3.1.1"

val versionOf = new {
val cats = "2.7.0"
Expand All @@ -12,7 +13,6 @@ val versionOf = new {
val scalaTest = "3.2.11"
val zio = "1.0.13"
val scribe = "3.8.2"
val silencer = "1.7.8"
}

lazy val coreDependencies = Seq(
Expand Down Expand Up @@ -49,20 +49,17 @@ lazy val testDependencies = Seq(
lazy val compilerPluginsDependencies = Seq(
compilerPlugin(
"org.typelevel" %% "kind-projector" % versionOf.kindProjector cross CrossVersion.full
),
compilerPlugin(
"com.github.ghik" %% "silencer-plugin" % versionOf.silencer cross CrossVersion.full
),
"com.github.ghik" %% "silencer-lib" % versionOf.silencer % Provided cross CrossVersion.full
)
)

ThisBuild / tlBaseVersion := "0.16"
ThisBuild / tlCiReleaseBranches := Seq("master")
ThisBuild / tlVersionIntroduced := Map("3" -> "0.16.3")
ThisBuild / organization := "io.laserdisc"
ThisBuild / organizationName := "LaserDisc"
ThisBuild / licenses := Seq(License.MIT)
ThisBuild / developers := List(tlGitHubDev("barambani", "Filippo Mariotti"))
ThisBuild / crossScalaVersions := Seq(scala_212, scala_213)
ThisBuild / crossScalaVersions := Seq(scala_212, scala_213, scala_3)
ThisBuild / scalaVersion := scala_213
ThisBuild / githubWorkflowJavaVersions := Seq(
JavaSpec.temurin("8"),
Expand All @@ -71,7 +68,10 @@ ThisBuild / githubWorkflowJavaVersions := Seq(
)
ThisBuild / Test / parallelExecution := false

ThisBuild / libraryDependencies ++= testDependencies ++ compilerPluginsDependencies
ThisBuild / libraryDependencies ++= testDependencies
ThisBuild / libraryDependencies ++= {
if (tlIsScala3.value) Seq.empty else compilerPluginsDependencies
}

lazy val root = tlCrossRootProject.aggregate(core, fs2, zio, interop)

Expand Down
5 changes: 3 additions & 2 deletions core/src/main/scala/log/effect/LogLevel.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@

package log.effect

import com.github.ghik.silencer.silent
import log.effect.internal.Show

import scala.annotation.nowarn

sealed trait LogLevel extends Product with Serializable
object LogLevel extends LogLevelSyntax {
import LogLevels._
Expand Down Expand Up @@ -73,7 +74,7 @@ object LogLevel extends LogLevelSyntax {
}
}

@silent private def showFor[A](a: A)(implicit ev: Show[A]): Show[A] = ev
@nowarn private def showFor[A](a: A)(implicit ev: Show[A]): Show[A] = ev
}

sealed trait LogLevelSyntax {
Expand Down
19 changes: 10 additions & 9 deletions core/src/main/scala/log/effect/LogWriter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@

package log.effect

import com.github.ghik.silencer.silent
import log.effect.internal.{Id, Show}

import scala.annotation.nowarn

trait LogWriter[F[_]] {
def write[A: Show](level: LogLevel, a: =>A): F[Unit]
}
Expand All @@ -37,7 +38,7 @@ object LogWriter extends LogWriterSyntax {

private[effect] final class logWriterInstancePartial[G[_], F[_]](private val d: Boolean = true)
extends AnyVal {
@inline @silent def apply[R](read: G[R])(
@inline def apply[R](read: G[R])(
implicit instance: LogWriterConstructor[R, G, F]
): G[LogWriter[F]] =
instance construction read
Expand All @@ -50,11 +51,11 @@ private[effect] sealed trait LogWriterSyntax extends LogWriterAliasingSyntax {
}

private[effect] sealed trait LogWriterAliasingSyntax {
@silent implicit def logWriterSingleton[F[_]](co: LogWriter.type)(
@nowarn implicit def logWriterSingleton[F[_]](co: LogWriter.type)(
implicit LW: LogWriter[F]
): LogWriter[F] = LW

@silent implicit def logWriterOpsSingleton[F[_]](co: LogWriter.type)(
@nowarn implicit def logWriterOpsSingleton[F[_]](co: LogWriter.type)(
implicit LW: LogWriter[F]
): LogWriterOps[F] = new LogWriterOps(LW)
}
Expand All @@ -68,7 +69,7 @@ private[effect] final class LogWriterOps[F[_]](private val aLogger: LogWriter[F]
@inline def trace(msg: =>String): F[Unit] =
aLogger.write(Trace, msg)

@inline def trace(th: =>Throwable)(implicit `_`: DummyImplicit): F[Unit] =
@inline def trace(th: =>Throwable)(implicit _dummy: DummyImplicit): F[Unit] =
aLogger.write(Trace, th)

@inline def trace(msg: =>String, th: =>Throwable): F[Unit] =
Expand All @@ -80,7 +81,7 @@ private[effect] final class LogWriterOps[F[_]](private val aLogger: LogWriter[F]
@inline def debug(msg: =>String): F[Unit] =
aLogger.write(Debug, msg)

@inline def debug(th: =>Throwable)(implicit `_`: DummyImplicit): F[Unit] =
@inline def debug(th: =>Throwable)(implicit _dummy: DummyImplicit): F[Unit] =
aLogger.write(Debug, th)

@inline def debug(msg: =>String, th: =>Throwable): F[Unit] =
Expand All @@ -92,7 +93,7 @@ private[effect] final class LogWriterOps[F[_]](private val aLogger: LogWriter[F]
@inline def info(msg: =>String): F[Unit] =
aLogger.write(Info, msg)

@inline def info(th: =>Throwable)(implicit `_`: DummyImplicit): F[Unit] =
@inline def info(th: =>Throwable)(implicit _dummy: DummyImplicit): F[Unit] =
aLogger.write(Info, th)

@inline def info(msg: =>String, th: =>Throwable): F[Unit] =
Expand All @@ -104,7 +105,7 @@ private[effect] final class LogWriterOps[F[_]](private val aLogger: LogWriter[F]
@inline def error(msg: =>String): F[Unit] =
aLogger.write(Error, msg)

@inline def error(th: =>Throwable)(implicit `_`: DummyImplicit): F[Unit] =
@inline def error(th: =>Throwable)(implicit _dummy: DummyImplicit): F[Unit] =
aLogger.write(Error, th)

@inline def error(msg: =>String, th: =>Throwable): F[Unit] =
Expand All @@ -116,7 +117,7 @@ private[effect] final class LogWriterOps[F[_]](private val aLogger: LogWriter[F]
@inline def warn(msg: =>String): F[Unit] =
aLogger.write(Warn, msg)

@inline def warn(th: =>Throwable)(implicit `_`: DummyImplicit): F[Unit] =
@inline def warn(th: =>Throwable)(implicit _dummy: DummyImplicit): F[Unit] =
aLogger.write(Warn, th)

@inline def warn(msg: =>String, th: =>Throwable): F[Unit] =
Expand Down
21 changes: 11 additions & 10 deletions core/src/test/scala/LogWriterSyntaxResolutionTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

import com.github.ghik.silencer.silent
import log.effect.internal.Show
import org.scalatest.wordspec.AnyWordSpecLike
import org.scalatest.matchers.should.Matchers

import scala.annotation.nowarn

final class LogWriterSyntaxResolutionTest extends AnyWordSpecLike with Matchers {
case class A()
object A {
Expand All @@ -36,7 +37,7 @@ final class LogWriterSyntaxResolutionTest extends AnyWordSpecLike with Matchers
"be inferred without extra import" in {
import log.effect.LogWriter

@silent def test[F[_]](l: LogWriter[F]) = {
@nowarn def test[F[_]](l: LogWriter[F]) = {
l.trace(A())
l.trace("test")
l.trace(new Throwable("test"))
Expand Down Expand Up @@ -70,33 +71,33 @@ final class LogWriterSyntaxResolutionTest extends AnyWordSpecLike with Matchers
import log.effect.LogLevels.Trace
import log.effect.LogWriter

@silent def f1[F[_]: LogWriter] =
@nowarn def f1[F[_]: LogWriter] =
LogWriter.write(Trace, "test")

@silent def f2[F[_]: LogWriter] =
@nowarn def f2[F[_]: LogWriter] =
LogWriter.trace(A())

@silent def f3[F[_]: LogWriter] =
@nowarn def f3[F[_]: LogWriter] =
LogWriter.debug(A())

@silent def f4[F[_]: LogWriter] =
@nowarn def f4[F[_]: LogWriter] =
LogWriter.info(A())

@silent def f5[F[_]: LogWriter] =
@nowarn def f5[F[_]: LogWriter] =
LogWriter.error(A())

@silent def f6[F[_]: LogWriter] =
@nowarn def f6[F[_]: LogWriter] =
LogWriter.warn(A())
}

"be inferred allowing a boilerplate free mtl-style syntax for errors" in {
import log.effect.LogLevels.Error
import log.effect.{Failure, LogWriter}

@silent def f1[F[_]: LogWriter] =
@nowarn def f1[F[_]: LogWriter] =
LogWriter.write(Error, Failure("test", new Exception("test exception")))

@silent def f2[F[_]: LogWriter] =
@nowarn def f2[F[_]: LogWriter] =
LogWriter.error(Failure("test", new Exception("test exception")))
}
}
Expand Down
2 changes: 1 addition & 1 deletion fs2/src/main/scala/log/effect/fs2/SyncLogWriter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ object SyncLogWriter {
def fmap[A, B](f: A => B): F[A] => F[B] = F lift f
}

implicit final class NoOpLogF(private val `_`: LogWriter[Id]) extends AnyVal {
implicit final class NoOpLogF(private val _underlying: LogWriter[Id]) extends AnyVal {
def liftF[F[_]: Applicative]: LogWriter[F] =
new LogWriter[F] {
private[this] val unit = Applicative[F].unit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@ package syntax

import _root_.fs2.Stream

import scala.annotation.nowarn

private[syntax] trait Fs2LogEffectSyntax extends Fs2LogEffectCompanionSyntax {
implicit def fs2LogEffectSyntax[F[_]](aLogWriter: LogWriter[F]): Fs2LogEffectOps[F] =
new Fs2LogEffectOps(aLogWriter)
}

private[syntax] sealed trait Fs2LogEffectCompanionSyntax {
implicit def fs2LogEffectSyntaxSingleton[F[_]](`_`: LogWriter.type)(
implicit def fs2LogEffectSyntaxSingleton[F[_]](@nowarn _underlying: LogWriter.type)(
implicit LW: LogWriter[F]
): Fs2LogEffectOps[F] =
new Fs2LogEffectOps(LW)
Expand All @@ -52,7 +54,7 @@ private[syntax] final class Fs2LogEffectOps[F[_]](private val aLogWriter: LogWri
Stream eval aLogWriter.trace(msg)

@inline
def traceS(th: =>Throwable)(implicit `_`: DummyImplicit): Stream[F, Unit] =
def traceS(th: =>Throwable)(implicit _dummy: DummyImplicit): Stream[F, Unit] =
Stream eval aLogWriter.trace(th)

@inline
Expand All @@ -68,7 +70,7 @@ private[syntax] final class Fs2LogEffectOps[F[_]](private val aLogWriter: LogWri
Stream eval aLogWriter.debug(msg)

@inline
def debugS(th: =>Throwable)(implicit `_`: DummyImplicit): Stream[F, Unit] =
def debugS(th: =>Throwable)(implicit _dummy: DummyImplicit): Stream[F, Unit] =
Stream eval aLogWriter.debug(th)

@inline
Expand All @@ -84,7 +86,7 @@ private[syntax] final class Fs2LogEffectOps[F[_]](private val aLogWriter: LogWri
Stream eval aLogWriter.info(msg)

@inline
def infoS(th: =>Throwable)(implicit `_`: DummyImplicit): Stream[F, Unit] =
def infoS(th: =>Throwable)(implicit _dummy: DummyImplicit): Stream[F, Unit] =
Stream eval aLogWriter.info(th)

@inline
Expand All @@ -100,7 +102,7 @@ private[syntax] final class Fs2LogEffectOps[F[_]](private val aLogWriter: LogWri
Stream eval aLogWriter.error(msg)

@inline
def errorS(th: =>Throwable)(implicit `_`: DummyImplicit): Stream[F, Unit] =
def errorS(th: =>Throwable)(implicit _dummy: DummyImplicit): Stream[F, Unit] =
Stream eval aLogWriter.error(th)

@inline
Expand All @@ -116,7 +118,7 @@ private[syntax] final class Fs2LogEffectOps[F[_]](private val aLogWriter: LogWri
Stream eval aLogWriter.warn(msg)

@inline
def warnS(th: =>Throwable)(implicit `_`: DummyImplicit): Stream[F, Unit] =
def warnS(th: =>Throwable)(implicit _dummy: DummyImplicit): Stream[F, Unit] =
Stream eval aLogWriter.warn(th)

@inline
Expand Down
Loading

0 comments on commit 4bf97d7

Please sign in to comment.