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 Support #62

Merged
merged 1 commit into from
Mar 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
scala: [2.13.5]
scala: [2.13.5, 3.0.0-RC1]
java: [adopt@1.8]
runs-on: ${{ matrix.os }}
steps:
Expand All @@ -49,10 +49,10 @@ jobs:
key: ${{ runner.os }}-sbt-cache-v2-${{ hashFiles('**/*.sbt') }}-${{ hashFiles('project/build.properties') }}

- name: Check formatting
run: sbt ++${{ matrix.scala }} fmtCheck
run: sbt ++2.13.5 fmtCheck

- name: Check that workflows are up to date
run: sbt ++${{ matrix.scala }} githubWorkflowCheck

- name: Build project
run: sbt ++${{ matrix.scala }} test
run: sbt ++${{ matrix.scala }} test
101 changes: 17 additions & 84 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,30 +1,31 @@
import java.util.concurrent.TimeUnit

import BuildHelper.{Scala213, stdSettings}
import scala.concurrent.duration.FiniteDuration

import sbt.enablePlugins

// ZIO Version
val zioVersion = "1.0.5"
val zioConfigVersion = "1.0.0"
val scala_2_13 = "2.13.5"

lazy val supportedScalaVersions = List(scala_2_13)

Global / scalaVersion := scala_2_13
val zioConfigVersion = "1.0.2"

lazy val root = (project in file("."))
.settings(stdSettings("root"))
.settings(
skip in publish := true,
name := "root",
)
.aggregate(zhttp, zhttpBenchmarks, example)

// CI Configuration
ThisBuild / githubWorkflowPublishTargetBranches := List()
ThisBuild / githubWorkflowBuildPreamble += WorkflowStep.Sbt(
List("fmtCheck"),
name = Some("Check formatting"))
//scala fix isn't available for scala 3 so ensure we only run the fmt check
//using the latest scala 2.13
ThisBuild / githubWorkflowBuildPreamble := WorkflowJob(
"fmtCheck",
"Format",
List(
WorkflowStep.Run(List(s"sbt ++${Scala213} fmtCheck"), name = Some("Check formatting"))
),
scalas = List(Scala213)
).steps

// Test Configuration
ThisBuild / libraryDependencies ++=
Expand All @@ -34,18 +35,15 @@ ThisBuild / libraryDependencies ++=
)
ThisBuild / testFrameworks += new TestFramework("zio.test.sbt.ZTestFramework")

// Scalafix
ThisBuild / scalafixDependencies += "com.github.liancheng" %% "organize-imports" % "0.5.0"

// Projects

// Project zio-http
lazy val zhttp = (project in file("./zio-http"))
.settings(stdSettings("zhttp"))
.settings(
version := "1.0.0.0-RC13",
organization := "io.d11",
organizationName := "d11",
crossScalaVersions := supportedScalaVersions,
brbrown25 marked this conversation as resolved.
Show resolved Hide resolved
licenses += ("MIT License", new URL("https://github.com/dream11/zio-http/blob/master/LICENSE")),
homepage in ThisBuild := Some(url("https://github.com/dream11/zio-http")),
scmInfo in ThisBuild :=
Expand Down Expand Up @@ -85,6 +83,7 @@ lazy val zhttp = (project in file("./zio-http"))
lazy val zhttpBenchmarks = (project in file("./zio-http-benchmarks"))
.enablePlugins(JmhPlugin)
.dependsOn(zhttp)
.settings(stdSettings("zhttpBenchmarks"))
.settings(
skip in publish := true,
libraryDependencies ++=
Expand All @@ -94,84 +93,18 @@ lazy val zhttpBenchmarks = (project in file("./zio-http-benchmarks"))
)

lazy val example = (project in file("./example"))
.settings(stdSettings("example"))
.settings(
fork := true,
skip in publish := true,
mainClass in (Compile, run) := Option("HelloWorldAdvanced"),
)
.dependsOn(zhttp)

Global / onChangedBuildSource := ReloadOnSourceChanges

// Compiler options
// RECOMMENDED SETTINGS: https://tpolecat.github.io/2017/04/25/scalac-flags.html
Global / scalacOptions ++=
Seq(
"-language:postfixOps", // Added by @tusharmath
"-deprecation", // Emit warning and location for usages of deprecated APIs.
"-encoding", "utf-8", // Specify character encoding used by source files.
"-explaintypes", // Explain type errors in more detail.
"-feature", // Emit warning and location for usages of features that should be imported explicitly.
"-language:existentials", // Existential types (besides wildcard types) can be written and inferred
"-language:higherKinds", // Allow higher-kinded types
"-unchecked", // Enable additional warnings where generated code depends on assumptions.
"-Xcheckinit", // Wrap field accessors to throw an exception on uninitialized access.
"-Xfatal-warnings", // Fail the compilation if there are any warnings.

"-Xlint:adapted-args", // Warn if an argument list is modified to match the receiver.
"-Xlint:constant", // Evaluation of a constant arithmetic expression results in an error.
"-Xlint:delayedinit-select", // Selecting member of DelayedInit.
"-Xlint:doc-detached", // A Scaladoc comment appears to be detached from its element.
"-Xlint:inaccessible", // Warn about inaccessible types in method signatures.
"-Xlint:missing-interpolator", // A string literal appears to be missing an interpolator id.
"-Xlint:nullary-unit", // Warn when nullary methods return Unit.
"-Xlint:option-implicit", // Option.apply used implicit view.
"-Xlint:package-object-classes", // Class or object defined in package object.
"-Xlint:poly-implicit-overload", // Parameterized overloaded implicit methods are not visible as view bounds.
"-Xlint:private-shadow", // A private field (or class parameter) shadows a superclass field.
"-Xlint:stars-align", // Pattern sequence wildcard must align with sequence component.
"-Xlint:type-parameter-shadow", // A local type parameter shadows a type already in scope.
"-Xlint:unused", // TODO check if we still need -Wunused below
"-Xlint:nonlocal-return", // A return statement used an exception for flow control.
"-Xlint:implicit-not-found", // Check @implicitNotFound and @implicitAmbiguous messages.
"-Xlint:serial", // @SerialVersionUID on traits and non-serializable classes.
"-Xlint:valpattern", // Enable pattern checks in val definitions.
"-Xlint:eta-zero", // Warn on eta-expansion (rather than auto-application) of zero-ary method.
"-Xlint:eta-sam", // Warn on eta-expansion to meet a Java-defined functional interface that is not explicitly annotated with @FunctionalInterface.
"-Xlint:deprecation", // Enable linted deprecations.

"-Wdead-code", // Warn when dead code is identified.
"-Wextra-implicit", // Warn when more than one implicit parameter section is defined.
"-Wmacros:both", // Lints code before and after applying a macro
"-Wnumeric-widen", // Warn when numerics are widened.
"-Woctal-literal", // Warn on obsolete octal syntax.
"-Wunused:imports", // Warn if an import selector is not referenced.
"-Wunused:patvars", // Warn if a variable bound in a pattern is unused.
"-Wunused:privates", // Warn if a private member is unused.
"-Wunused:locals", // Warn if a local definition is unused.
"-Wunused:explicits", // Warn if an explicit parameter is unused.
"-Wunused:implicits", // Warn if an implicit parameter is unused.
"-Wunused:params", // Enable -Wunused:explicits,implicits.
"-Wunused:linted",
"-Wvalue-discard", // Warn when non-Unit expression results are unused.

"-Ybackend-parallelism", "8", // Enable paralellisation — change to desired number!
"-Ycache-plugin-class-loader:last-modified", // Enables caching of classloaders for compiler plugins
"-Ycache-macro-class-loader:last-modified", // and macro definitions. This can lead to performance improvements.

// FIXME: Disabled because of scalac bug https://github.com/scala/bug/issues/11798
// "-Xlint:infer-any", // Warn when a type argument is inferred to be `Any`.
// "-Ywarn-infer-any", // Warn when a type argument is inferred to be `Any`.
// "-language:experimental.macros", // Allow macro definition (besides implementation and application). Disabled, as this will significantly change in Scala 3
// "-language:implicitConversions", // Allow definition of implicit functions called views. Disabled, as it might be dropped in Scala 3. Instead use extension methods (implemented as implicit class Wrapper(val inner: Foo) extends AnyVal {}

)

addCommandAlias("fmt", "scalafmt; test:scalafmt; sFix;")
addCommandAlias("fmtCheck", "scalafmtCheck; test:scalafmtCheck; sFixCheck")
addCommandAlias("sFix", "scalafix OrganizeImports; test:scalafix OrganizeImports")
addCommandAlias("sFixCheck", "scalafix --check OrganizeImports; test:scalafix --check OrganizeImports")

Global / semanticdbEnabled := true
Global / semanticdbVersion := scalafixSemanticdb.revision
Global / onChangedBuildSource := ReloadOnSourceChanges
Global / watchAntiEntropy := FiniteDuration(2000, TimeUnit.MILLISECONDS)
2 changes: 2 additions & 0 deletions example/src/main/scala/SocketEchoServer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ object SocketEchoServer extends App {
private val socket =
Socket.forall[WebSocketFrame](msg => ZStream.repeat(msg).schedule(Schedule.spaced(1 second)).take(10))

implicit val httpNothingPartial: CanSupportPartial[Request, Nothing] = (_: Request) => Nil.head
brbrown25 marked this conversation as resolved.
Show resolved Hide resolved

private val app =
Http.collectM[Request] {
case Method.GET -> Root / "greet" / name => UIO(Response.text(s"Greetings {$name}!"))
Expand Down
139 changes: 139 additions & 0 deletions project/BuildHelper.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
import sbt._
import Keys._
import dotty.tools.sbtplugin.DottyPlugin.autoImport._
import scalafix.sbt.ScalafixPlugin.autoImport._

object BuildHelper {
val Scala213 = "2.13.5"
val ScalaDotty = "3.0.0-RC1"

private val stdOptions = Seq(
"-deprecation",
"-encoding",
"UTF-8",
"-feature",
"-unchecked",
"-language:postfixOps",
) ++ {
if (sys.env.contains("CI")) {
Seq("-Xfatal-warnings")
} else {
Nil // to enable Scalafix locally
}
}

private val std2xOptions = Seq(
"-language:higherKinds",
"-language:existentials",
"-explaintypes",
"-Yrangepos",
"-Xlint:_,-missing-interpolator,-type-parameter-shadow",
"-Ywarn-numeric-widen",
"-Ywarn-value-discard",
)

//RECOMMENDED SETTINGS: https://tpolecat.github.io/2017/04/25/scalac-flags.html
private val tpoleCatSettings = Seq(
"-language:postfixOps", // Added by @tusharmath
"-deprecation", // Emit warning and location for usages of deprecated APIs.
"-encoding",
"utf-8", // Specify character encoding used by source files.
"-explaintypes", // Explain type errors in more detail.
"-feature", // Emit warning and location for usages of features that should be imported explicitly.
"-language:existentials", // Existential types (besides wildcard types) can be written and inferred
"-language:higherKinds", // Allow higher-kinded types
"-unchecked", // Enable additional warnings where generated code depends on assumptions.
"-Xcheckinit", // Wrap field accessors to throw an exception on uninitialized access.
"-Xfatal-warnings", // Fail the compilation if there are any warnings.
"-Xlint:adapted-args", // Warn if an argument list is modified to match the receiver.
"-Xlint:constant", // Evaluation of a constant arithmetic expression results in an error.
"-Xlint:delayedinit-select", // Selecting member of DelayedInit.
"-Xlint:doc-detached", // A Scaladoc comment appears to be detached from its element.
"-Xlint:inaccessible", // Warn about inaccessible types in method signatures.
"-Xlint:missing-interpolator", // A string literal appears to be missing an interpolator id.
"-Xlint:nullary-unit", // Warn when nullary methods return Unit.
"-Xlint:option-implicit", // Option.apply used implicit view.
"-Xlint:package-object-classes", // Class or object defined in package object.
"-Xlint:poly-implicit-overload", // Parameterized overloaded implicit methods are not visible as view bounds.
"-Xlint:private-shadow", // A private field (or class parameter) shadows a superclass field.
"-Xlint:stars-align", // Pattern sequence wildcard must align with sequence component.
"-Xlint:type-parameter-shadow", // A local type parameter shadows a type already in scope.
"-Xlint:unused", // TODO check if we still need -Wunused below
"-Xlint:nonlocal-return", // A return statement used an exception for flow control.
"-Xlint:implicit-not-found", // Check @implicitNotFound and @implicitAmbiguous messages.
"-Xlint:serial", // @SerialVersionUID on traits and non-serializable classes.
"-Xlint:valpattern", // Enable pattern checks in val definitions.
"-Xlint:eta-zero", // Warn on eta-expansion (rather than auto-application) of zero-ary method.
"-Xlint:eta-sam", // Warn on eta-expansion to meet a Java-defined functional interface that is not explicitly annotated with @FunctionalInterface.
"-Xlint:deprecation", // Enable linted deprecations.
"-Wdead-code", // Warn when dead code is identified.
"-Wextra-implicit", // Warn when more than one implicit parameter section is defined.
"-Wmacros:both", // Lints code before and after applying a macro
"-Wnumeric-widen", // Warn when numerics are widened.
"-Woctal-literal", // Warn on obsolete octal syntax.
"-Wunused:imports", // Warn if an import selector is not referenced.
"-Wunused:patvars", // Warn if a variable bound in a pattern is unused.
"-Wunused:privates", // Warn if a private member is unused.
"-Wunused:locals", // Warn if a local definition is unused.
"-Wunused:explicits", // Warn if an explicit parameter is unused.
"-Wunused:implicits", // Warn if an implicit parameter is unused.
"-Wunused:params", // Enable -Wunused:explicits,implicits.
"-Wunused:linted",
"-Wvalue-discard", // Warn when non-Unit expression results are unused.
"-Ybackend-parallelism",
"8", // Enable paralellisation — change to desired number!
"-Ycache-plugin-class-loader:last-modified", // Enables caching of classloaders for compiler plugins
"-Ycache-macro-class-loader:last-modified", // and macro definitions. This can lead to performance improvements.

// FIXME: Disabled because of scalac bug https://github.com/scala/bug/issues/11798
// "-Xlint:infer-any", // Warn when a type argument is inferred to be `Any`.
// "-Ywarn-infer-any", // Warn when a type argument is inferred to be `Any`.
// "-language:experimental.macros", // Allow macro definition (besides implementation and application). Disabled, as this will significantly change in Scala 3
// "-language:implicitConversions", // Allow definition of implicit functions called views. Disabled, as it might be dropped in Scala 3. Instead use extension methods (implemented as implicit class Wrapper(val inner: Foo) extends AnyVal {}
)

private def optimizerOptions(optimize: Boolean) =
if (optimize)
Seq(
"-opt:l:inline",
)
else Nil

def extraOptions(scalaVersion: String, isDotty: Boolean, optimize: Boolean) =
CrossVersion.partialVersion(scalaVersion) match {
case _ if isDotty =>
Seq(
"-language:implicitConversions",
"-Xignore-scala2-macros",
"-noindent",
)
case Some((2, 13)) => Seq("-Ywarn-unused:params,-implicits") ++ std2xOptions ++ tpoleCatSettings ++ optimizerOptions(optimize)
case _ => Seq.empty
}

def stdSettings(prjName: String) = Seq(
name := s"$prjName",
crossScalaVersions in ThisBuild := Seq(Scala213, ScalaDotty),
scalaVersion in ThisBuild := Scala213,
useScala3doc := true,
scalacOptions := stdOptions ++ extraOptions(scalaVersion.value, isDotty.value, optimize = !isSnapshot.value),
scalacOptions --= {
if (isDotty.value)
Seq("-Xfatal-warnings")
else
Seq()
},
semanticdbEnabled := !isDotty.value, // enable SemanticDB
semanticdbOptions += "-P:semanticdb:synthetics:on",
semanticdbVersion := scalafixSemanticdb.revision, // use Scalafix compatible version
ThisBuild / scalafixScalaBinaryVersion := CrossVersion.binaryScalaVersion(scalaVersion.value),
ThisBuild / scalafixDependencies ++=
List(
"com.github.liancheng" %% "organize-imports" % "0.5.0",
"com.github.vovapolu" %% "scaluzzi" % "0.1.16",
),
parallelExecution in Test := true,
incOptions ~= (_.withLogRecompileOnMacro(false)),
autoAPIMappings := true,
)
}
3 changes: 3 additions & 0 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
addSbtPlugin("ch.epfl.lamp" % "sbt-dotty" % "0.5.3")
addSbtPlugin("ch.epfl.scala" % "sbt-bloop" % "1.4.8")
addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.9.26")
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.4.2")
addSbtPlugin("pl.project13.scala" % "sbt-jmh" % "0.4.0")
addSbtPlugin("com.timushev.sbt" % "sbt-updates" % "0.5.2")
addSbtPlugin("io.spray" % "sbt-revolver" % "0.9.1")
addSbtPlugin("com.github.sbt" % "sbt-pgp" % "2.1.2")
addSbtPlugin("com.codecommit" % "sbt-github-actions" % "0.10.1")
addSbtPlugin("ch.epfl.scala" % "sbt-scala3-migrate" % "0.3.0")
1 change: 1 addition & 0 deletions zio-http/src/main/scala/zhttp/core/AliasModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ trait AliasModule {
type JSimpleChannelInboundHandler[A] = jChannel.SimpleChannelInboundHandler[A]
type JSharable = jChannel.ChannelHandler.Sharable
type JEpollServerSocketChannel = jChannel.epoll.EpollServerSocketChannel
type JKQueueSocketChannel = jChannel.kqueue.KQueueSocketChannel
type JKQueueServerSocketChannel = jChannel.kqueue.KQueueServerSocketChannel
type JNioServerSocketChannel = jChannel.socket.nio.NioServerSocketChannel
type JChannelConfig = jChannel.ChannelConfig
Expand Down
2 changes: 1 addition & 1 deletion zio-http/src/main/scala/zhttp/http/Http.scala
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ sealed trait Http[-R, +E, -A, +B] { self =>
}

object Http extends HttpConstructors with HttpExecutors {
final case object Identity extends Http[Any, Nothing, Any, Nothing]
case object Identity extends Http[Any, Nothing, Any, Nothing]
final case class Succeed[B](b: B) extends Http[Any, Nothing, Any, B]
final case class Fail[E](e: E) extends Http[Any, E, Any, Nothing]
final case class FromEffectFunction[R, E, A, B](f: A => ZIO[R, E, B]) extends Http[R, E, A, B]
Expand Down
Loading