diff --git a/core/src/main/scala/cats/Eval.scala b/core/src/main/scala/cats/Eval.scala index 7834248b3c..476152e948 100644 --- a/core/src/main/scala/cats/Eval.scala +++ b/core/src/main/scala/cats/Eval.scala @@ -22,6 +22,7 @@ package cats import org.typelevel.scalaccompat.annotation.uncheckedVariance2 +import org.typelevel.scalaccompat.annotation.threadUnsafe3 import scala.annotation.tailrec @@ -479,6 +480,7 @@ trait EvalSemigroup[A] extends Semigroup[Eval[A]] { trait EvalMonoid[A] extends Monoid[Eval[A]] with EvalSemigroup[A] { implicit def algebra: Monoid[A] + @threadUnsafe3 lazy val empty: Eval[A] = Eval.later(algebra.empty) } diff --git a/core/src/main/scala/cats/data/Ior.scala b/core/src/main/scala/cats/data/Ior.scala index f7aaf6a093..c98e33f3d1 100644 --- a/core/src/main/scala/cats/data/Ior.scala +++ b/core/src/main/scala/cats/data/Ior.scala @@ -24,6 +24,7 @@ package data import cats.arrow.FunctionK import cats.data.Validated.{Invalid, Valid} +import org.typelevel.scalaccompat.annotation.threadUnsafe3 import scala.annotation.tailrec @@ -946,6 +947,7 @@ sealed abstract private[data] class IorInstances extends IorInstances0 { } } + @threadUnsafe3 lazy val monad: Monad[Ior[E, *]] = Monad[Ior[E, *]] } diff --git a/core/src/main/scala/cats/data/IorT.scala b/core/src/main/scala/cats/data/IorT.scala index 45712b664f..e3dccb407b 100644 --- a/core/src/main/scala/cats/data/IorT.scala +++ b/core/src/main/scala/cats/data/IorT.scala @@ -23,6 +23,7 @@ package cats package data import cats.arrow.FunctionK +import org.typelevel.scalaccompat.annotation.threadUnsafe3 final case class IorT[F[_], A, B](value: F[Ior[A, B]]) { @@ -533,6 +534,7 @@ abstract private[data] class IorTInstances extends IorTInstances1 { IorT(FA.map2(ff.value, fa.value)((f, a) => IorA.ap(f)(a))) } + @threadUnsafe3 lazy val monad: Monad[IorT[M, E, *]] = { implicit def underlyingMonadM: Monad[M] = P.monad Monad[IorT[M, E, *]] @@ -566,6 +568,7 @@ abstract private[data] class IorTInstances extends IorTInstances1 { IorT(FA.map2(ff.value, fa.value)((f, a) => IorA.ap(f)(a))) } + @threadUnsafe3 lazy val monad: Monad[IorT[M, E, *]] = { implicit def underlyingMonadM: Monad[M] = P.monad Monad[IorT[M, E, *]] @@ -611,6 +614,7 @@ abstract private[data] class IorTInstances1 extends IorTInstances2 { IorT(F.map2(ff.value, fa.value)((f, a) => underlyingParallel.applicative.ap[A, B](f)(a))) } + @threadUnsafe3 lazy val monad: Monad[IorT[F0, E, *]] = Monad[IorT[F0, E, *]] } diff --git a/core/src/main/scala/cats/data/Kleisli.scala b/core/src/main/scala/cats/data/Kleisli.scala index 48a7ab34d1..483be49032 100644 --- a/core/src/main/scala/cats/data/Kleisli.scala +++ b/core/src/main/scala/cats/data/Kleisli.scala @@ -25,6 +25,7 @@ package data import cats.{Contravariant, Id} import cats.arrow._ import cats.evidence.As +import org.typelevel.scalaccompat.annotation.threadUnsafe3 /** * Represents a function `A => F[B]`. @@ -372,7 +373,7 @@ sealed abstract private[data] class KleisliInstances extends KleisliInstances0 { implicit def catsDataDeferForKleisli[F[_], A](implicit F: Defer[F]): Defer[Kleisli[F, A, *]] = new Defer[Kleisli[F, A, *]] { def defer[B](fa: => Kleisli[F, A, B]): Kleisli[F, A, B] = { - lazy val cacheFa = fa + @threadUnsafe3 lazy val cacheFa = fa Kleisli[F, A, B] { a => F.defer(cacheFa.run(a)) } diff --git a/core/src/main/scala/cats/data/RepresentableStore.scala b/core/src/main/scala/cats/data/RepresentableStore.scala index 867e1dff40..da43f86f39 100644 --- a/core/src/main/scala/cats/data/RepresentableStore.scala +++ b/core/src/main/scala/cats/data/RepresentableStore.scala @@ -22,6 +22,7 @@ package cats.data import cats.{Comonad, Functor, Representable} +import org.typelevel.scalaccompat.annotation.threadUnsafe3 /** * A generalization of `StoreT`, where the underlying functor `F` has a `Representable` instance. @@ -53,12 +54,14 @@ final case class RepresentableStore[F[_], S, A](fa: F[A], index: S)(implicit R: /** * Extract the value at the current index. */ + @threadUnsafe3 lazy val extract: A = peek(index) /** * `coflatten` is the dual of `flatten` on `FlatMap`. Whereas flatten removes * a layer of `F`, coflatten adds a layer of `F` */ + @threadUnsafe3 lazy val coflatten: RepresentableStore[F, S, RepresentableStore[F, S, A]] = RepresentableStore(R.tabulate(idx => RepresentableStore(fa, idx)), index) diff --git a/core/src/main/scala/cats/data/Tuple2K.scala b/core/src/main/scala/cats/data/Tuple2K.scala index b5a1d88f4a..b03825de29 100644 --- a/core/src/main/scala/cats/data/Tuple2K.scala +++ b/core/src/main/scala/cats/data/Tuple2K.scala @@ -23,6 +23,7 @@ package cats package data import cats.arrow.FunctionK +import org.typelevel.scalaccompat.annotation.threadUnsafe3 /** * [[Tuple2K]] is a product to two independent functor values. @@ -89,7 +90,7 @@ sealed abstract private[data] class Tuple2KInstances extends Tuple2KInstances0 { new Defer[Tuple2K[F, G, *]] { def defer[A](fa: => Tuple2K[F, G, A]): Tuple2K[F, G, A] = { // Make sure we only evaluate once on both the first and second - lazy val cacheFa = fa + @threadUnsafe3 lazy val cacheFa = fa Tuple2K(F.defer(cacheFa.first), G.defer(cacheFa.second)) } diff --git a/core/src/main/scala/cats/instances/eq.scala b/core/src/main/scala/cats/instances/eq.scala index 5c96a8c219..80958b24ce 100644 --- a/core/src/main/scala/cats/instances/eq.scala +++ b/core/src/main/scala/cats/instances/eq.scala @@ -22,6 +22,8 @@ package cats package instances +import org.typelevel.scalaccompat.annotation.threadUnsafe3 + import scala.annotation.tailrec trait EqInstances extends kernel.instances.EqInstances { @@ -52,6 +54,7 @@ object EqInstances { private val catsDeferForEqCache: Defer[Eq] = new Defer[Eq] { case class Deferred[A](fa: () => Eq[A]) extends Eq[A] { + @threadUnsafe3 private lazy val resolved: Eq[A] = { @tailrec def loop(f: () => Eq[A]): Eq[A] = @@ -66,7 +69,7 @@ object EqInstances { } override def defer[A](fa: => Eq[A]): Eq[A] = { - lazy val cachedFa = fa + @threadUnsafe3 lazy val cachedFa = fa Deferred(() => cachedFa) } } diff --git a/core/src/main/scala/cats/instances/equiv.scala b/core/src/main/scala/cats/instances/equiv.scala index 941fd6e911..85ad2ac42a 100644 --- a/core/src/main/scala/cats/instances/equiv.scala +++ b/core/src/main/scala/cats/instances/equiv.scala @@ -22,6 +22,8 @@ package cats package instances +import org.typelevel.scalaccompat.annotation.threadUnsafe3 + import scala.annotation.tailrec trait EquivInstances { @@ -61,6 +63,7 @@ object EquivInstances { private val catsDeferForEquivCache: Defer[Equiv] = new Defer[Equiv] { case class Deferred[A](fa: () => Equiv[A]) extends Equiv[A] { + @threadUnsafe3 private lazy val resolved: Equiv[A] = { @tailrec def loop(f: () => Equiv[A]): Equiv[A] = @@ -75,7 +78,7 @@ object EquivInstances { } override def defer[A](fa: => Equiv[A]): Equiv[A] = { - lazy val cachedFa = fa + @threadUnsafe3 lazy val cachedFa = fa Deferred(() => cachedFa) } } diff --git a/core/src/main/scala/cats/instances/function.scala b/core/src/main/scala/cats/instances/function.scala index 4233cd10a8..bbcbb231b6 100644 --- a/core/src/main/scala/cats/instances/function.scala +++ b/core/src/main/scala/cats/instances/function.scala @@ -25,6 +25,7 @@ package instances import cats.Contravariant import cats.arrow.{ArrowChoice, Category, CommutativeArrow} import cats.data.AndThen +import org.typelevel.scalaccompat.annotation.threadUnsafe3 import annotation.tailrec @@ -46,6 +47,7 @@ private[instances] trait FunctionInstancesBinCompat0 { implicit val catsSddDeferForFunction0: Defer[Function0] = new Defer[Function0] { case class Deferred[A](fa: () => Function0[A]) extends Function0[A] { + @threadUnsafe3 private lazy val resolved: Function0[A] = { @annotation.tailrec def loop(f: () => Function0[A]): Function0[A] = @@ -59,7 +61,7 @@ private[instances] trait FunctionInstancesBinCompat0 { def apply(): A = resolved() } def defer[A](fa: => Function0[A]): Function0[A] = { - lazy val cachedFa = fa + @threadUnsafe3 lazy val cachedFa = fa Deferred(() => cachedFa) } } @@ -67,6 +69,7 @@ private[instances] trait FunctionInstancesBinCompat0 { implicit def catsStdDeferForFunction1[A]: Defer[A => *] = new Defer[A => *] { case class Deferred[B](fa: () => A => B) extends (A => B) { + @threadUnsafe3 private lazy val resolved: A => B = { @annotation.tailrec def loop(f: () => A => B): A => B = @@ -80,7 +83,7 @@ private[instances] trait FunctionInstancesBinCompat0 { def apply(a: A): B = resolved(a) } def defer[B](fa: => A => B): A => B = { - lazy val cachedFa = fa + @threadUnsafe3 lazy val cachedFa = fa Deferred(() => cachedFa) } } diff --git a/core/src/main/scala/cats/instances/hash.scala b/core/src/main/scala/cats/instances/hash.scala index 9175d0dd4f..3b89d6ea69 100644 --- a/core/src/main/scala/cats/instances/hash.scala +++ b/core/src/main/scala/cats/instances/hash.scala @@ -22,6 +22,8 @@ package cats package instances +import org.typelevel.scalaccompat.annotation.threadUnsafe3 + import scala.annotation.tailrec trait HashInstances extends kernel.instances.HashInstances { @@ -42,6 +44,7 @@ object HashInstances { private val catsDeferForHashCache: Defer[Hash] = new Defer[Hash] { case class Deferred[A](fa: () => Hash[A]) extends Hash[A] { + @threadUnsafe3 private lazy val resolve: Hash[A] = { @tailrec def loop(f: () => Hash[A]): Hash[A] = @@ -62,7 +65,7 @@ object HashInstances { } override def defer[A](fa: => Hash[A]): Hash[A] = { - lazy val cachedFa = fa + @threadUnsafe3 lazy val cachedFa = fa Deferred(() => cachedFa) } } diff --git a/core/src/main/scala/cats/instances/order.scala b/core/src/main/scala/cats/instances/order.scala index c1b4eab29b..978e750b1a 100644 --- a/core/src/main/scala/cats/instances/order.scala +++ b/core/src/main/scala/cats/instances/order.scala @@ -23,6 +23,7 @@ package cats package instances import cats.kernel.instances.unit._ +import org.typelevel.scalaccompat.annotation.threadUnsafe3 import scala.annotation.tailrec @@ -56,6 +57,7 @@ object OrderInstances { private val catsDeferForOrderCache: Defer[Order] = new Defer[Order] { case class Deferred[A](fa: () => Order[A]) extends Order[A] { + @threadUnsafe3 private lazy val resolved: Order[A] = { @tailrec def loop(f: () => Order[A]): Order[A] = @@ -70,7 +72,7 @@ object OrderInstances { } override def defer[A](fa: => Order[A]): Order[A] = { - lazy val cachedFa = fa + @threadUnsafe3 lazy val cachedFa = fa Deferred(() => cachedFa) } } diff --git a/core/src/main/scala/cats/instances/ordering.scala b/core/src/main/scala/cats/instances/ordering.scala index 802e778e20..da35e2b691 100644 --- a/core/src/main/scala/cats/instances/ordering.scala +++ b/core/src/main/scala/cats/instances/ordering.scala @@ -23,6 +23,7 @@ package cats package instances import cats.kernel.instances.unit._ +import org.typelevel.scalaccompat.annotation.threadUnsafe3 import scala.annotation.tailrec @@ -52,6 +53,7 @@ object OrderingInstances { private val catsStdDeferForOrderingCache: Defer[Ordering] = new Defer[Ordering] { case class Deferred[A](fa: () => Ordering[A]) extends Ordering[A] { + @threadUnsafe3 private lazy val resolved: Ordering[A] = { @tailrec def loop(f: () => Ordering[A]): Ordering[A] = @@ -66,7 +68,7 @@ object OrderingInstances { } override def defer[A](fa: => Ordering[A]): Ordering[A] = { - lazy val cachedFa = fa + @threadUnsafe3 lazy val cachedFa = fa Deferred(() => cachedFa) } } diff --git a/core/src/main/scala/cats/instances/partialOrder.scala b/core/src/main/scala/cats/instances/partialOrder.scala index 81bdce03e1..cb1f67b286 100644 --- a/core/src/main/scala/cats/instances/partialOrder.scala +++ b/core/src/main/scala/cats/instances/partialOrder.scala @@ -23,6 +23,8 @@ package cats package instances import cats.kernel.instances.unit._ +import org.typelevel.scalaccompat.annotation.threadUnsafe3 + import scala.annotation.tailrec trait PartialOrderInstances extends kernel.instances.PartialOrderInstances { @@ -50,6 +52,7 @@ object PartialOrderInstances { private val catsDeferForPartialOrderCache: Defer[PartialOrder] = new Defer[PartialOrder] { case class Deferred[A](fa: () => PartialOrder[A]) extends PartialOrder[A] { + @threadUnsafe3 private lazy val resolved: PartialOrder[A] = { @tailrec def loop(f: () => PartialOrder[A]): PartialOrder[A] = @@ -64,7 +67,7 @@ object PartialOrderInstances { } override def defer[A](fa: => PartialOrder[A]): PartialOrder[A] = { - lazy val cachedFa = fa + @threadUnsafe3 lazy val cachedFa = fa Deferred(() => cachedFa) } } diff --git a/core/src/main/scala/cats/instances/partialOrdering.scala b/core/src/main/scala/cats/instances/partialOrdering.scala index 586c9492dd..7c957186df 100644 --- a/core/src/main/scala/cats/instances/partialOrdering.scala +++ b/core/src/main/scala/cats/instances/partialOrdering.scala @@ -22,6 +22,8 @@ package cats package instances +import org.typelevel.scalaccompat.annotation.threadUnsafe3 + import scala.annotation.tailrec trait PartialOrderingInstances { @@ -60,6 +62,7 @@ object PartialOrderingInstances { private val catsStdDeferForPartialOrderingCache: Defer[PartialOrdering] = new Defer[PartialOrdering] { case class Deferred[A](fa: () => PartialOrdering[A]) extends PartialOrdering[A] { + @threadUnsafe3 private lazy val resolve: PartialOrdering[A] = { @tailrec def loop(f: () => PartialOrdering[A]): PartialOrdering[A] = @@ -77,7 +80,7 @@ object PartialOrderingInstances { } override def defer[A](fa: => PartialOrdering[A]): PartialOrdering[A] = { - lazy val cachedFa = fa + @threadUnsafe3 lazy val cachedFa = fa Deferred(() => cachedFa) } } diff --git a/core/src/main/scala/cats/instances/show.scala b/core/src/main/scala/cats/instances/show.scala index 2f2c01907a..971b6b95a4 100644 --- a/core/src/main/scala/cats/instances/show.scala +++ b/core/src/main/scala/cats/instances/show.scala @@ -22,6 +22,8 @@ package cats package instances +import org.typelevel.scalaccompat.annotation.threadUnsafe3 + import scala.annotation.tailrec trait ShowInstances { @@ -31,6 +33,7 @@ object ShowInstances { private val catsDeferForShowCache: Defer[Show] = new Defer[Show] { case class Deferred[A](fa: () => Show[A]) extends Show[A] { + @threadUnsafe3 private lazy val resolved: Show[A] = { @tailrec def loop(f: () => Show[A]): Show[A] = @@ -45,7 +48,7 @@ object ShowInstances { } override def defer[A](fa: => Show[A]): Show[A] = { - lazy val cachedFa = fa + @threadUnsafe3 lazy val cachedFa = fa Deferred(() => cachedFa) } }