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

Make auto instances transparent inline to support Scala 3.4.0 #656

Merged
merged 1 commit into from
Mar 8, 2024
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
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ lazy val commonSettings = Seq(
"-Werror"
),
scalacOptions ++= CrossVersion.partialVersion(scalaVersion.value).toList.flatMap {
case (3, _) => List("-Xmax-inlines", "64", "-Wunused:all", "-Wvalue-discard")
case (3, _) => List("-source:future", "-Xmax-inlines", "64", "-Wunused:all", "-Wvalue-discard")
case (2, 12) => List("-Ypartial-unification", "-Xlint")
case _ => List("-Xlint:_,-byname-implicit", "-Wconf:cat=deprecation&site=.*SequenceSuite:silent")
},
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala-3/cats/derived/Derived.scala
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ object Derived:
extension [I[f[_[_, _]], t[_, _]] <: K2.Instances[f, t], F[_[_, _]], T[_, _]](inst: I[Or2[F], T])
@targetName("unifyK2") def unify: I[F, T] = inst

private[derived] class Lazy[A](f: () => A) extends Serializable:
private[derived] open class Lazy[A](f: () => A) extends Serializable:
final protected lazy val delegate: A = f()

sealed abstract class OrInstances:
Expand Down
64 changes: 33 additions & 31 deletions core/src/main/scala-3/cats/derived/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -145,94 +145,96 @@ object auto:
private type NotGivenF[T[_[_]]] = [F[_]] =>> NotGiven[T[F]]

object eq:
inline given [A: NotGivenA[Eq]]: Eq[A] = DerivedEq[A]
transparent inline given [A: NotGivenA[Eq]]: Eq[A] = DerivedEq[A]

object hash:
inline given [A: NotGivenA[Hash]]: Hash[A] = DerivedHash[A]
transparent inline given [A: NotGivenA[Hash]]: Hash[A] = DerivedHash[A]

object empty:
inline given [A: NotGivenA[Empty]]: Empty[A] = DerivedEmpty[A]
transparent inline given [A: NotGivenA[Empty]]: Empty[A] = DerivedEmpty[A]

object semigroup:
inline given [A: NotGivenA[Semigroup]]: Semigroup[A] = DerivedSemigroup[A]
transparent inline given [A: NotGivenA[Semigroup]]: Semigroup[A] = DerivedSemigroup[A]

object monoid:
inline given [A: NotGivenA[Monoid]]: Monoid[A] = DerivedMonoid[A]
transparent inline given [A: NotGivenA[Monoid]]: Monoid[A] = DerivedMonoid[A]

object group:
inline given [A: NotGivenA[Group]]: Group[A] = DerivedGroup[A]
transparent inline given [A: NotGivenA[Group]]: Group[A] = DerivedGroup[A]

object band:
inline given [A: NotGivenA[Band]]: Band[A] = DerivedBand[A]
transparent inline given [A: NotGivenA[Band]]: Band[A] = DerivedBand[A]

object order:
inline given [A: NotGivenA[Order]]: Order[A] = DerivedOrder[A]
transparent inline given [A: NotGivenA[Order]]: Order[A] = DerivedOrder[A]

object commutativeSemigroup:
inline given [A: NotGivenA[CommutativeSemigroup]]: CommutativeSemigroup[A] = DerivedCommutativeSemigroup[A]
transparent inline given [A: NotGivenA[CommutativeSemigroup]]: CommutativeSemigroup[A] =
DerivedCommutativeSemigroup[A]

object commutativeMonoid:
inline given [A: NotGivenA[CommutativeMonoid]]: CommutativeMonoid[A] = DerivedCommutativeMonoid[A]
transparent inline given [A: NotGivenA[CommutativeMonoid]]: CommutativeMonoid[A] = DerivedCommutativeMonoid[A]

object commutativeGroup:
inline given [A: NotGivenA[CommutativeGroup]]: CommutativeGroup[A] = DerivedCommutativeGroup[A]
transparent inline given [A: NotGivenA[CommutativeGroup]]: CommutativeGroup[A] = DerivedCommutativeGroup[A]

object semilattice:
inline given [A: NotGivenA[Semilattice]]: Semilattice[A] = DerivedSemilattice[A]
transparent inline given [A: NotGivenA[Semilattice]]: Semilattice[A] = DerivedSemilattice[A]

object boundedSemilattice:
inline given [A: NotGivenA[BoundedSemilattice]]: BoundedSemilattice[A] = DerivedBoundedSemilattice[A]
transparent inline given [A: NotGivenA[BoundedSemilattice]]: BoundedSemilattice[A] = DerivedBoundedSemilattice[A]

object show:
inline given [A: NotGivenA[Show]]: Show[A] = DerivedShow[A]
transparent inline given [A: NotGivenA[Show]]: Show[A] = DerivedShow[A]

object applicative:
inline given [F[_]: NotGivenF[Applicative]]: Applicative[F] = DerivedApplicative[F]
transparent inline given [F[_]: NotGivenF[Applicative]]: Applicative[F] = DerivedApplicative[F]

object apply:
inline given [F[_]: NotGivenF[Apply]]: Apply[F] = DerivedApply[F]
transparent inline given [F[_]: NotGivenF[Apply]]: Apply[F] = DerivedApply[F]

object nonEmptyAlternative:
inline given [F[_]: NotGivenF[NonEmptyAlternative]]: NonEmptyAlternative[F] = DerivedNonEmptyAlternative[F]
transparent inline given [F[_]: NotGivenF[NonEmptyAlternative]]: NonEmptyAlternative[F] =
DerivedNonEmptyAlternative[F]

object alternative:
inline given [F[_]: NotGivenF[Alternative]]: Alternative[F] = DerivedAlternative[F]
transparent inline given [F[_]: NotGivenF[Alternative]]: Alternative[F] = DerivedAlternative[F]

object emptyK:
inline given [F[_]: NotGivenF[EmptyK]]: EmptyK[F] = DerivedEmptyK[F]
transparent inline given [F[_]: NotGivenF[EmptyK]]: EmptyK[F] = DerivedEmptyK[F]

object pure:
inline given [F[_]: NotGivenF[Pure]]: Pure[F] = DerivedPure[F]
transparent inline given [F[_]: NotGivenF[Pure]]: Pure[F] = DerivedPure[F]

object functor:
inline given [F[_]: NotGivenF[Functor]]: Functor[F] = DerivedFunctor[F]
transparent inline given [F[_]: NotGivenF[Functor]]: Functor[F] = DerivedFunctor[F]

object foldable:
inline given [F[_]: NotGivenF[Foldable]]: Foldable[F] = DerivedFoldable[F]
transparent inline given [F[_]: NotGivenF[Foldable]]: Foldable[F] = DerivedFoldable[F]

object reducible:
inline given [F[_]: NotGivenF[Reducible]]: Reducible[F] = DerivedReducible[F]
transparent inline given [F[_]: NotGivenF[Reducible]]: Reducible[F] = DerivedReducible[F]

object traverse:
inline given [F[_]: NotGivenF[Traverse]]: Traverse[F] = DerivedTraverse[F]
transparent inline given [F[_]: NotGivenF[Traverse]]: Traverse[F] = DerivedTraverse[F]

object nonEmptyTraverse:
inline given [F[_]: NotGivenF[NonEmptyTraverse]]: NonEmptyTraverse[F] = DerivedNonEmptyTraverse[F]
transparent inline given [F[_]: NotGivenF[NonEmptyTraverse]]: NonEmptyTraverse[F] = DerivedNonEmptyTraverse[F]

object semigroupK:
inline given [F[_]: NotGivenF[SemigroupK]]: SemigroupK[F] = DerivedSemigroupK[F]
transparent inline given [F[_]: NotGivenF[SemigroupK]]: SemigroupK[F] = DerivedSemigroupK[F]

object monoidK:
inline given [F[_]: NotGivenF[MonoidK]]: MonoidK[F] = DerivedMonoidK[F]
transparent inline given [F[_]: NotGivenF[MonoidK]]: MonoidK[F] = DerivedMonoidK[F]

object contravariant:
inline given [F[_]: NotGivenF[Contravariant]]: Contravariant[F] = DerivedContravariant[F]
transparent inline given [F[_]: NotGivenF[Contravariant]]: Contravariant[F] = DerivedContravariant[F]

object invariant:
inline given [F[_]: NotGivenF[Invariant]]: Invariant[F] = DerivedInvariant[F]
transparent inline given [F[_]: NotGivenF[Invariant]]: Invariant[F] = DerivedInvariant[F]

object partialOrder:
inline given [A: NotGivenA[PartialOrder]]: PartialOrder[A] = DerivedPartialOrder[A]
transparent inline given [A: NotGivenA[PartialOrder]]: PartialOrder[A] = DerivedPartialOrder[A]

object showPretty:
inline given [A: NotGivenA[Show]]: ShowPretty[A] = DerivedShowPretty[A]
transparent inline given [A: NotGivenA[Show]]: ShowPretty[A] = DerivedShowPretty[A]
44 changes: 24 additions & 20 deletions core/src/test/scala-3/cats/derived/ADTs.scala
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ object ADTs:
rec.is match
case Some(is) => perturb(i, is)
case None => i
Cogen(perturb _)
Cogen(perturb)

final case class Interleaved[T](i: Int, t: T, l: Long, tt: Vector[T], s: String)
object Interleaved:
Expand Down Expand Up @@ -299,11 +299,6 @@ object ADTs:
trait EqInstances:
import ADTs.*

given Eq[Recursive] = Eq.fromUniversalEquals
given [A: Eq]: Eq[ICons[A]] = Eq.by(identity[IList[A]])
given [A: Eq]: Eq[SCons[A]] = Eq.by(identity[Snoc[A]])
given [A: Eq]: Eq[GenericAdt[A]] = Eq.by { case GenericAdtCase(v) => v }

given [A: Eq]: Eq[IList[A]] with
@tailrec final def eqv(x: IList[A], y: IList[A]): Boolean = (x, y) match
case (ICons(hx, tx), ICons(hy, ty)) => hx === hy && eqv(tx, ty)
Expand All @@ -316,6 +311,11 @@ object ADTs:
case (SNil(), SNil()) => true
case _ => false

given Eq[Recursive] = Eq.fromUniversalEquals
given [A: Eq]: Eq[ICons[A]] = Eq.by(identity[IList[A]])
given [A: Eq]: Eq[SCons[A]] = Eq.by(identity[Snoc[A]])
given [A: Eq]: Eq[GenericAdt[A]] = Eq.by { case GenericAdtCase(v) => v }

given [A: Eq]: Eq[Tree[A]] with
def eqv(x: Tree[A], y: Tree[A]): Boolean = (x, y) match
case (Leaf(vx), Leaf(vy)) => vx === vy
Expand All @@ -331,23 +331,27 @@ object ADTs:
case (EnumK0.LeafI(i1), EnumK0.LeafI(i2)) => i1 === i2
case _ => false

given [A: Eq]: Eq[EnumK1[A]] =
case (EnumK1.Leaf(v1), EnumK1.Leaf(v2)) => v1 === v2
case (EnumK1.Rec(l1, r1), EnumK1.Rec(l2, r2)) => l1 === l2 && r1 === r2
case _ => false
given [A: Eq]: Eq[EnumK1[A]] with
def eqv(x: EnumK1[A], y: EnumK1[A]) = (x, y) match
case (EnumK1.Leaf(v1), EnumK1.Leaf(v2)) => v1 === v2
case (EnumK1.Rec(l1, r1), EnumK1.Rec(l2, r2)) => eqv(l1, l2) && eqv(r1, r2)
case _ => false

given [A](using Eq[A => Unit]): Eq[EnumK1Contra[A]] =
case (EnumK1Contra.Leaf(v1), EnumK1Contra.Leaf(v2)) => v1 === v2
case (EnumK1Contra.Rec(l1, r1), EnumK1Contra.Rec(l2, r2)) => l1 === l2 && r1 === r2
case _ => false
given [A](using Eq[A => Unit]): Eq[EnumK1Contra[A]] with
def eqv(x: EnumK1Contra[A], y: EnumK1Contra[A]) = (x, y) match
case (EnumK1Contra.Leaf(v1), EnumK1Contra.Leaf(v2)) => v1 === v2
case (EnumK1Contra.Rec(l1, r1), EnumK1Contra.Rec(l2, r2)) => eqv(l1, l2) && eqv(r1, r2)
case _ => false

given [A: Eq](using Eq[A => Unit]): Eq[EnumK1Inv[A]] =
case (EnumK1Inv.Leaf(cov1, contra1), EnumK1Inv.Leaf(cov2, contra2)) => cov1 === cov2 && contra1 === contra2
case (EnumK1Inv.Rec(l1, r1), EnumK1Inv.Rec(l2, r2)) => l1 === l2 && r1 === r2
case _ => false
given [A: Eq](using Eq[A => Unit]): Eq[EnumK1Inv[A]] with
def eqv(x: EnumK1Inv[A], y: EnumK1Inv[A]) = (x, y) match
case (EnumK1Inv.Leaf(cov1, contra1), EnumK1Inv.Leaf(cov2, contra2)) => cov1 === cov2 && contra1 === contra2
case (EnumK1Inv.Rec(l1, r1), EnumK1Inv.Rec(l2, r2)) => eqv(l1, l2) && eqv(r1, r2)
case _ => false

given [A: Eq]: Eq[Search[A]] =
(x, y) => x.move === y.move && x.child === y.child && x.variations === y.variations
given [A: Eq]: Eq[Search[A]] with
def eqv(x: Search[A], y: Search[A]) =
x.move === y.move && x.child === y.child && x.variations === y.variations

end EqInstances
end ADTs