Skip to content

Commit

Permalink
Remove scala-collection-compat (#381)
Browse files Browse the repository at this point in the history
  • Loading branch information
neko-kai authored Mar 21, 2023
1 parent 31f5510 commit b05a541
Show file tree
Hide file tree
Showing 17 changed files with 53 additions and 41 deletions.
3 changes: 1 addition & 2 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,7 @@ lazy val `izumi-reflect` = project.in(file("izumi-reflect/izumi-reflect"))
)
.settings(
libraryDependencies ++= Seq(
"org.scalatest" %% "scalatest" % V.scalatest % Test,
"org.scala-lang.modules" %% "scala-collection-compat" % V.collection_compat
"org.scalatest" %% "scalatest" % V.scalatest % Test
),
libraryDependencies ++= { if (scalaVersion.value.startsWith("2.")) Seq(
compilerPlugin("org.typelevel" % "kind-projector" % V.kind_projector cross CrossVersion.full),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package izumi.reflect.internal

private[reflect] object CollectionCompat {
private[reflect] final type IterableOnce[+A] = scala.collection.TraversableOnce[A]
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ private[reflect] object OrderingCompat {
@inline private[reflect] def arrayOrdering[A](ordering: Ordering[A]): Ordering[Array[A]] = {
Ordering.Implicits.seqDerivedOrdering[ArraySeqLike, A](ordering).on(array => array)
}
final type ArraySeqLike[A] = mutable.WrappedArray[A]
private[reflect] final type ArraySeqLike[A] = mutable.WrappedArray[A]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package izumi.reflect.internal.NowarnCompat

private[reflect] class nowarn(value: String = "") extends scala.annotation.ClassfileAnnotation
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package izumi.reflect.internal

private[reflect] object NowarnCompat {
private[reflect] final type nowarn = scala.annotation.nowarn
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package izumi.reflect.internal

private[reflect] object CollectionCompat {
private[reflect] final type IterableOnce[+A] = scala.collection.IterableOnce[A]
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ private[reflect] object OrderingCompat {
@inline private[reflect] def arrayOrdering[A](ordering: Ordering[A]): Ordering[Array[A]] = {
Ordering.Implicits.seqOrdering[ArraySeqLike, A](ordering).on(array => array)
}
final type ArraySeqLike[A] = mutable.ArraySeq[A]
private[reflect] final type ArraySeqLike[A] = mutable.ArraySeq[A]
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@

package izumi.reflect

import scala.annotation.nowarn
import izumi.reflect.internal.fundamentals.platform.console.TrivialLogger
import izumi.reflect.ReflectionUtil.{Kind, kindOf}
import izumi.reflect.TagMacro._
import izumi.reflect.macrortti.LightTypeTagRef.{FullReference, NameReference, SymName, TypeParam, Variance}
import izumi.reflect.internal.NowarnCompat
import izumi.reflect.internal.fundamentals.platform.console.TrivialLogger
import izumi.reflect.macrortti.LightTypeTagRef._
import izumi.reflect.macrortti.{LightTypeTag, LightTypeTagMacro0, LightTypeTagRef}

import scala.annotation.implicitNotFound
Expand All @@ -32,7 +32,7 @@ import scala.reflect.macros.{TypecheckException, blackbox, whitebox}

// TODO: benchmark difference between searching all arguments vs. merge strategy
// TODO: benchmark ProviderMagnet vs. identity macro vs. normal function
@nowarn("msg=deprecated")
@NowarnCompat.nowarn("msg=deprecated")
class TagMacro(val c: blackbox.Context) {

import c.universe._
Expand Down Expand Up @@ -521,7 +521,7 @@ private object TagMacro {
}
}

@nowarn("msg=deprecated")
@NowarnCompat.nowarn("msg=deprecated")
class TagLambdaMacro(override val c: whitebox.Context) extends TagMacro(c) {

import c.universe._
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

package izumi.reflect.macrortti

import izumi.reflect.internal.CollectionCompat
import izumi.reflect.internal.fundamentals.collections.IzCollections._
import izumi.reflect.internal.fundamentals.platform.assertions.IzAssert
import izumi.reflect.internal.fundamentals.platform.console.TrivialLogger
Expand Down Expand Up @@ -513,7 +514,7 @@ final class LightTypeTagImpl[U <: Universe with Singleton](val u: U, withCache:
}
}

def convertDecl(decl: Symbol, rules: Map[String, SymName.LambdaParamName]): scala.collection.compat.IterableOnce[RefinementDecl] = {
def convertDecl(decl: Symbol, rules: Map[String, SymName.LambdaParamName]): CollectionCompat.IterableOnce[RefinementDecl] = {
if (decl.isMethod) {
val declMethod = decl.asMethod
val returnTpe = declMethod.returnType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@

package izumi.reflect.internal.fundamentals.collections

import izumi.reflect.internal.CollectionCompat

import scala.language.implicitConversions

private[reflect] object IzCollections {
private[reflect] implicit def toRich[A, B](xs: scala.collection.compat.IterableOnce[(A, B)]): IzMappings[A, B] = new IzMappings(xs)
private[reflect] implicit def toRich[A, B](xs: CollectionCompat.IterableOnce[(A, B)]): IzMappings[A, B] = new IzMappings(xs)
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,20 @@

package izumi.reflect.internal.fundamentals.collections

import scala.annotation.nowarn
import izumi.reflect.internal.{CollectionCompat, NowarnCompat}

import scala.collection.mutable

private[reflect] final class IzMappings[A, B](private val list: scala.collection.compat.IterableOnce[(A, B)]) extends AnyVal {
@nowarn("msg=deprecated")
private[reflect] final class IzMappings[A, B](private val list: CollectionCompat.IterableOnce[(A, B)]) extends AnyVal {
@NowarnCompat.nowarn("msg=deprecated")
def toMutableMultimap: MutableMultiMap[A, B] = {
list.foldLeft(new mutable.HashMap[A, mutable.Set[B]] with mutable.MultiMap[A, B]) {
(map, pair) => map.addBinding(pair._1, pair._2)
}
}

@nowarn("msg=Unused import")
@NowarnCompat.nowarn("msg=deprecated")
def toMultimap: ImmutableMultiMap[A, B] = {
import scala.collection.compat._
toMutableMultimap.view.mapValues(_.toSet).toMap
toMutableMultimap.mapValues(_.toSet).toMap
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@

package izumi.reflect.internal.fundamentals

import scala.annotation.nowarn
import izumi.reflect.internal.NowarnCompat

import scala.collection.mutable

package object collections {
@nowarn("msg=deprecated")
@NowarnCompat.nowarn("msg=deprecated")
private[reflect] type MutableMultiMap[A, B] = mutable.HashMap[A, mutable.Set[B]] with mutable.MultiMap[A, B]
private[reflect] type ImmutableMultiMap[A, B] = Map[A, Set[B]]
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@

package izumi.reflect.internal.fundamentals.platform.console

import java.util.concurrent.atomic.AtomicBoolean
import scala.annotation.{nowarn, tailrec}
import izumi.reflect.DebugProperties
import izumi.reflect.internal.NowarnCompat
import izumi.reflect.internal.fundamentals.platform.console.TrivialLogger.Config
import izumi.reflect.internal.fundamentals.platform.strings.IzString._

import java.util.concurrent.atomic.AtomicBoolean
import scala.annotation.tailrec
import scala.reflect.{ClassTag, classTag}

private[reflect] trait TrivialLogger {
Expand Down Expand Up @@ -79,7 +80,7 @@ private[reflect] object TrivialLogger {
config.forceLog || enabled.get()
}

@nowarn("msg=return statement")
@NowarnCompat.nowarn("msg=return statement")
private[this] val enabled: AtomicBoolean = {
def prop(): Boolean = {
val sysProperty = DebugProperties.`izumi.reflect.debug.macro.rtti` // this is the only debug logging property supported in the library
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package izumi.reflect.macrortti

import izumi.reflect.DebugProperties
import izumi.reflect.internal.NowarnCompat
import izumi.reflect.internal.OrderingCompat.ArraySeqLike
import izumi.reflect.internal.fundamentals.platform.strings.IzString.toRichString
import izumi.reflect.macrortti.LightTypeTag.ParsedLightTypeTag.SubtypeDBs
Expand All @@ -29,7 +30,6 @@ import izumi.reflect.thirdparty.internal.boopickle.UnpickleState

import java.nio.ByteBuffer
import java.nio.charset.StandardCharsets
import scala.annotation.nowarn
import scala.collection.immutable.HashSet

/**
Expand Down Expand Up @@ -142,10 +142,9 @@ abstract class LightTypeTag private[reflect] (
* - You won't be able to call [[combine]] on result type
* and partially applied types will not work correctly
*/
@nowarn("msg=Unused import")
@NowarnCompat.nowarn("msg=deprecated")
def withoutArgs: LightTypeTag = {
import scala.collection.compat._
LightTypeTag(ref.withoutArgs, basesdb.view.mapValues(_.map(_.withoutArgs)).toMap, idb)
LightTypeTag(ref.withoutArgs, basesdb.mapValues(_.map(_.withoutArgs)).iterator.toMap, idb)
}

/**
Expand Down Expand Up @@ -321,12 +320,11 @@ object LightTypeTag {
)

private[reflect] object SubtypeDBs {
@nowarn("msg=Unused import")
@NowarnCompat.nowarn("msg=deprecated")
private[reflect] def make(bases: Map[AbstractReference, Set[AbstractReference]], idb: Map[NameReference, Set[NameReference]]): SubtypeDBs = {
import scala.collection.compat._
new SubtypeDBs(
bases.view.mapValues(_.filterNot(v => LightTypeTagRef.isIgnored(v))).filterNot(_._2.isEmpty).toMap,
idb.view.mapValues(_.filterNot(v => LightTypeTagRef.isIgnored(v))).filterNot(_._2.isEmpty).toMap
bases.mapValues(_.filterNot(v => LightTypeTagRef.isIgnored(v))).filterNot(_._2.isEmpty).iterator.toMap,
idb.mapValues(_.filterNot(v => LightTypeTagRef.isIgnored(v))).filterNot(_._2.isEmpty).iterator.toMap
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

package izumi.reflect.macrortti

import scala.annotation.nowarn
import izumi.reflect.internal.NowarnCompat
import izumi.reflect.internal.fundamentals.platform.language.unused
import izumi.reflect.macrortti.LightTypeTagRef._

Expand Down Expand Up @@ -103,13 +103,12 @@ object RuntimeAPI {
ref
}

@nowarn("msg=Unused import")
@NowarnCompat.nowarn("msg=deprecated")
def replaceRefs(reference: AbstractReference): AbstractReference = {
reference match {
case l: Lambda =>
val bad = l.input.iterator.toSet
import scala.collection.compat._
val fixed = new Rewriter(_rules.view.filterKeys(!bad.contains(_)).toMap).replaceRefs(l.output)
val fixed = new Rewriter(_rules.filterKeys(!bad.contains(_)).iterator.toMap).replaceRefs(l.output)
l.copy(output = fixed)

case o: AppliedReference =>
Expand Down
7 changes: 1 addition & 6 deletions project/Deps.sc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import izumi.sbtgen.model._
object Izumi {

object V {
val collection_compat = Version.VExpr("V.collection_compat")
val kind_projector = Version.VExpr("V.kind_projector")
val scalatest = Version.VExpr("V.scalatest")
val sbtgen = Version.VExpr("V.sbtgen")
Expand Down Expand Up @@ -70,8 +69,6 @@ object Izumi {

final val projector = Library("org.typelevel", "kind-projector", V.kind_projector, LibraryType.Invariant)
.more(LibSetting.Raw("cross CrossVersion.full"))

final val collection_compat = Library("org.scala-lang.modules", "scala-collection-compat", V.collection_compat, LibraryType.Auto)
}

import Deps._
Expand Down Expand Up @@ -296,9 +293,7 @@ object Izumi {
),
Artifact(
name = Projects.izumi_reflect_aggregate.izumi_reflect,
libs = Seq(
collection_compat in Scope.Compile.all
),
libs = Seq.empty,
depends = Seq(
Projects.izumi_reflect_aggregate.thirdpartyBoopickleShaded
)
Expand Down
1 change: 0 additions & 1 deletion project/Versions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,5 @@

object V {
val kind_projector = "0.13.2"
val collection_compat = "2.8.1"
val scalatest = "3.2.14"
}

0 comments on commit b05a541

Please sign in to comment.