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

Compile Scala 2 under -Xsource:3 #513

Open
wants to merge 8 commits into
base: series/2.x
Choose a base branch
from
Open
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
3 changes: 3 additions & 0 deletions .scalafix.conf
Original file line number Diff line number Diff line change
@@ -8,6 +8,7 @@ rules = [
OrganizeImports
ProcedureSyntax
RemoveUnused
RedundantSyntax
]

Disable {
@@ -20,6 +21,8 @@ Disable {
OrganizeImports {
# Allign with IntelliJ IDEA so that they don't fight each other
groupedImports = Merge
targetDialect = Scala3
removeUnused = true
}

RemoveUnused {
2 changes: 1 addition & 1 deletion .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@ includeCurlyBraceInSelectChains = false
danglingParentheses.preset = true
optIn.annotationNewlines = true
newlines.alwaysBeforeMultilineDef = false
runner.dialect = scala213
runner.dialect = scala3
rewrite.rules = [RedundantBraces]

rewrite.redundantBraces.generalExpressions = false
2 changes: 1 addition & 1 deletion benchmarks/src/main/scala/zio/query/BenchmarkUtil.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package zio.query

import zio._
import zio.*

object BenchmarkUtil extends Runtime[Any] { self =>
val environment = Runtime.default.environment
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package zio.query

import org.openjdk.jmh.annotations.{Scope => JScope, _}
import zio.query.BenchmarkUtil._
import org.openjdk.jmh.annotations.{Scope as JScope, *}
import zio.query.BenchmarkUtil.*

import java.util.concurrent.TimeUnit

22 changes: 11 additions & 11 deletions benchmarks/src/main/scala/zio/query/DataSourceBenchmark.scala
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package zio.query

import cats.effect.IO
import cats.effect.unsafe.implicits._
import cats.syntax.all._
import fetch.{Fetch, fetchM}
import org.openjdk.jmh.annotations.{Scope => JScope, _}
import zio.query.BenchmarkUtil._
import cats.effect.unsafe.implicits.*
import cats.syntax.all.*
import fetch.Fetch
import org.openjdk.jmh.annotations.{Scope as JScope, *}
import zio.query.BenchmarkUtil.*
import zio.{Chunk, ZIO}

import java.util.concurrent.TimeUnit
@@ -36,7 +36,7 @@ class DataSourceBenchmark {

@Benchmark
def zquerySumDuplicatedBenchmark(): Long = {
import ZQueryImpl._
import ZQueryImpl.*

val reqs = (0 until count).toList.map(i => ZQuery.fromRequest(Req(1))(ds))
val query = ZQuery.collectAllBatched(reqs).map(_.sum.toLong)
@@ -45,7 +45,7 @@ class DataSourceBenchmark {

@Benchmark
def zquerySumUniqueBenchmark(): Long = {
import ZQueryImpl._
import ZQueryImpl.*

val reqs = (0 until count).toList.map(i => ZQuery.fromRequest(Req(i))(ds))
val query = ZQuery.collectAllBatched(reqs).map(_.sum.toLong)
@@ -54,7 +54,7 @@ class DataSourceBenchmark {

@Benchmark
def fetchSumDuplicatedBenchmark(): Long = {
import FetchImpl._
import FetchImpl.*
import fetch.fetchM
type FIO[A] = Fetch[IO, A]

@@ -65,8 +65,8 @@ class DataSourceBenchmark {

@Benchmark
def fetchSumUniqueBenchmark(): Long = {
import FetchImpl.*
import fetch.fetchM
import FetchImpl._
type FIO[A] = Fetch[IO, A]

val reqs = (0 until count).toList.map(i => fetchPlusOne(i))
@@ -81,8 +81,8 @@ class DataSourceBenchmark {

object FetchImpl {
import cats.data.NonEmptyList
import cats.effect._
import fetch._
import cats.effect.*
import fetch.*

object PlusOne extends Data[Int, Int] {
def name = "PlusOne"
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package zio.query

import org.openjdk.jmh.annotations.{Scope => JScope, _}
import zio.query.BenchmarkUtil._
import org.openjdk.jmh.annotations.{Scope as JScope, *}
import zio.query.BenchmarkUtil.*
import zio.{Chunk, ZIO}

import java.util.concurrent.TimeUnit
4 changes: 2 additions & 2 deletions benchmarks/src/main/scala/zio/query/ZQueryBenchmark.scala
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package zio.query

import org.openjdk.jmh.annotations.{Scope => JScope, _}
import org.openjdk.jmh.annotations.{Scope as JScope, *}
import zio.query.BenchmarkUtil.*
import zio.{Chunk, ZIO}
import zio.query.BenchmarkUtil._

import java.util.concurrent.TimeUnit

5 changes: 4 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
@@ -28,7 +28,8 @@ inThisBuild(
url("https://github.com/kyri-petrou")
)
),
versionScheme := Some("early-semver")
versionScheme := Some("early-semver"),
scalacOptions ++= (if (scalaBinaryVersion.value == "3") Seq() else Seq("-Xsource:3"))
)
)

@@ -69,6 +70,7 @@ lazy val zioQuery = crossProject(JSPlatform, JVMPlatform, NativePlatform)
Seq()
else {
Seq(
"-Xsource:3",
"-opt:l:method",
"-opt:l:inline",
"-opt-inline-from:scala.**",
@@ -118,6 +120,7 @@ lazy val docs = project
moduleName := "zio-query-docs",
scalacOptions -= "-Yno-imports",
scalacOptions -= "-Xfatal-warnings",
scalacOptions += "-Wconf:msg=.*:silent",
projectName := (ThisBuild / name).value,
mainModuleName := (zioQueryJVM / moduleName).value,
crossScalaVersions := Seq(scalaV),
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version = 1.10.1
sbt.version = 1.10.2
2 changes: 2 additions & 0 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -8,5 +8,7 @@ addSbtPlugin("com.typesafe" % "sbt-mima-plugin" % "1.1.4")
addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.12.0")
addSbtPlugin("org.scala-native" % "sbt-scala-native" % "0.5.5")
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.17.0")
addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.13.0")
addSbtPlugin("org.scalameta" % "sbt-mdoc" % "2.6.1")

resolvers ++= Resolver.sonatypeOssRepos("public")
2 changes: 1 addition & 1 deletion zio-query/shared/src/main/scala/zio/query/Cache.scala
Original file line number Diff line number Diff line change
@@ -16,7 +16,7 @@

package zio.query

import zio._
import zio.*
import zio.stacktracer.TracingImplicits.disableAutoTrace

import java.util.concurrent.ConcurrentHashMap
Original file line number Diff line number Diff line change
@@ -19,7 +19,7 @@ package zio.query
import zio.stacktracer.TracingImplicits.disableAutoTrace
import zio.{Cause, Chunk, Exit}

import scala.collection.compat._
import scala.collection.compat.*
import scala.collection.{immutable, mutable}

/**
@@ -255,7 +255,7 @@ object CompletedRequestMap {
final private[query] class Mutable private (
override protected val map: mutable.HashMap[Any, Exit[Any, Any]]
) extends CompletedRequestMap { self =>
import UtilsVersionSpecific._
import UtilsVersionSpecific.*

def addAll(that: CompletedRequestMap): Unit =
if (!that.isEmpty) self.map.addAll(that.map)
Original file line number Diff line number Diff line change
@@ -16,7 +16,7 @@

package zio.query

import zio._
import zio.*

/**
* A `QueryAspect` is an aspect that can be weaved into queries. You can think
16 changes: 11 additions & 5 deletions zio-query/shared/src/main/scala/zio/query/ZQuery.scala
Original file line number Diff line number Diff line change
@@ -16,14 +16,14 @@

package zio.query

import zio._
import zio.*
import zio.query.ZQuery.disabledCache
import zio.query.internal._
import zio.query.internal.*
import zio.stacktracer.TracingImplicits.disableAutoTrace

import java.util.concurrent.atomic.AtomicBoolean
import scala.annotation.switch
import scala.collection.compat.{BuildFrom => _, _}
import scala.collection.compat.{BuildFrom as _, *}
import scala.collection.mutable.ArrayBuilder
import scala.reflect.ClassTag

@@ -1937,7 +1937,9 @@ object ZQuery {
val arr = Array.ofDim[Result[R, E, B]](n)

ZIO
.whileLoop(i < n)(f(as(i)).step) { v => arr(i) = v; i += 1 }
.whileLoop(i < n)(f(as(i)).step) { v =>
arr(i) = v; i += 1
}
.as(collectResults(arr, mode, mapOut))
}
}
@@ -1953,7 +1955,11 @@ object ZQuery {
case n =>
val out = Array.ofDim[A](n)
var i = 0
ZIO.whileLoop(i < n)(in(i)) { v => out(i) = v; i += 1 }.as(out)
ZIO
.whileLoop(i < n)(in(i)) { v =>
out(i) = v; i += 1
}
.as(out)
}

private def collectResults[R, E, A, B, F[_]](
Original file line number Diff line number Diff line change
@@ -16,13 +16,13 @@

package zio.query.internal

import zio.query._
import zio.query.internal.BlockedRequests._
import zio.query.*
import zio.query.internal.BlockedRequests.*
import zio.stacktracer.TracingImplicits.disableAutoTrace
import zio.{Chunk, Exit, Trace, UIO, Unsafe, ZEnvironment, ZIO}

import scala.annotation.tailrec
import scala.collection.compat._
import scala.collection.compat.*
import scala.collection.mutable
import scala.collection.mutable.ListBuffer

Original file line number Diff line number Diff line change
@@ -16,9 +16,9 @@

package zio.query.internal

import zio._
import zio.query._
import zio.query.internal.Continue._
import zio.*
import zio.query.*
import zio.query.internal.Continue.*
import zio.stacktracer.TracingImplicits.disableAutoTrace

/**
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package zio.query.internal

import zio._
import zio.*
import zio.stacktracer.TracingImplicits.disableAutoTrace

import java.util.concurrent.atomic.AtomicReference
Original file line number Diff line number Diff line change
@@ -16,8 +16,8 @@

package zio.query.internal

import zio._
import zio.query.internal.Result._
import zio.*
import zio.query.internal.Result.*
import zio.query.{DataSourceAspect, Described}
import zio.stacktracer.TracingImplicits.disableAutoTrace

4 changes: 2 additions & 2 deletions zio-query/shared/src/test/scala/zio/query/ZIOBaseSpec.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package zio.query

import zio._
import zio.test._
import zio.*
import zio.test.*

trait ZIOBaseSpec extends ZIOSpecDefault {
override def aspects: Chunk[TestAspectPoly] =
12 changes: 6 additions & 6 deletions zio-query/shared/src/test/scala/zio/query/ZQuerySpec.scala
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package zio.query

import zio._
import zio.query.QueryAspect._
import zio.*
import zio.query.QueryAspect.*
import zio.query.internal.QueryScope
import zio.test.Assertion._
import zio.test.Assertion.*
import zio.test.TestAspect.{after, nonFlaky, silent}
import zio.test.{TestClock, TestConsole, TestEnvironment, _}
import zio.test.{TestClock, TestConsole, TestEnvironment, *}

object ZQuerySpec extends ZIOBaseSpec {

@@ -305,10 +305,10 @@ object ZQuerySpec extends ZIOBaseSpec {
}
) @@ nonFlaky,
test("service methods works with multiple services") {
def getFoo: ZQuery[Int with String, Nothing, Unit] =
def getFoo: ZQuery[Int & String, Nothing, Unit] =
ZQuery.serviceWithQuery[Int](_ => ZQuery.service[String].as(()))

def getBar: ZQuery[Int with String, Nothing, Unit] =
def getBar: ZQuery[Int & String, Nothing, Unit] =
ZQuery.serviceWithZIO[String](_ => ZIO.service[String].unit)

assertCompletes