From 2449e15b91204ad5316fe0df7d17cb4226272ac8 Mon Sep 17 00:00:00 2001 From: Tim Spence Date: Fri, 24 Jun 2022 09:59:20 +0100 Subject: [PATCH 1/4] Update Ref docs Make it explicit that mutable data should not be stored in Ref --- docs/std/ref.md | 7 ++++++- kernel/shared/src/main/scala/cats/effect/kernel/Ref.scala | 4 +++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/docs/std/ref.md b/docs/std/ref.md index 183eab9831..de685801d9 100644 --- a/docs/std/ref.md +++ b/docs/std/ref.md @@ -18,7 +18,12 @@ Provides safe concurrent access and modification of its content, but no function For this reason, a `Ref` is always initialised to a value. -The default implementation is nonblocking and lightweight, consisting essentially of a purely functional wrapper over an `AtomicReference`. +The default implementation is nonblocking and lightweight, consisting +essentially of a purely functional wrapper over an `AtomicReference`. +Consequently it _must not_ be used to store mutable data as +`AtomicReference#compareAndSet` and friends are not threadsafe and are dependent +upon object reference identity. + ### Concurrent Counter diff --git a/kernel/shared/src/main/scala/cats/effect/kernel/Ref.scala b/kernel/shared/src/main/scala/cats/effect/kernel/Ref.scala index 043ab48834..348d68102a 100644 --- a/kernel/shared/src/main/scala/cats/effect/kernel/Ref.scala +++ b/kernel/shared/src/main/scala/cats/effect/kernel/Ref.scala @@ -34,7 +34,9 @@ import scala.annotation.tailrec * initialised to a value. * * The default implementation is nonblocking and lightweight, consisting essentially of a purely - * functional wrapper over an `AtomicReference`. + * functional wrapper over an `AtomicReference`. Consequently it _must not_ be used to store mutable + * data as `AtomicReference#compareAndSet` and friends are not threadsafe and are dependent + * upon object reference identity. */ abstract class Ref[F[_], A] extends RefSource[F, A] with RefSink[F, A] { From 2c21b9efd968270955c3c9937d56f97d7ebf960a Mon Sep 17 00:00:00 2001 From: Tim Spence Date: Fri, 24 Jun 2022 10:02:52 +0100 Subject: [PATCH 2/4] Scaladoc italics --- kernel/shared/src/main/scala/cats/effect/kernel/Ref.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/shared/src/main/scala/cats/effect/kernel/Ref.scala b/kernel/shared/src/main/scala/cats/effect/kernel/Ref.scala index 348d68102a..9b3343f784 100644 --- a/kernel/shared/src/main/scala/cats/effect/kernel/Ref.scala +++ b/kernel/shared/src/main/scala/cats/effect/kernel/Ref.scala @@ -34,7 +34,7 @@ import scala.annotation.tailrec * initialised to a value. * * The default implementation is nonblocking and lightweight, consisting essentially of a purely - * functional wrapper over an `AtomicReference`. Consequently it _must not_ be used to store mutable + * functional wrapper over an `AtomicReference`. Consequently it ''must not'' be used to store mutable * data as `AtomicReference#compareAndSet` and friends are not threadsafe and are dependent * upon object reference identity. */ From 9dfd7768f53685e98079427458a78c2a69958a3e Mon Sep 17 00:00:00 2001 From: Tim Spence Date: Fri, 24 Jun 2022 10:08:45 +0100 Subject: [PATCH 3/4] s/identity/equality --- docs/std/ref.md | 2 +- kernel/shared/src/main/scala/cats/effect/kernel/Ref.scala | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/std/ref.md b/docs/std/ref.md index de685801d9..031ca807aa 100644 --- a/docs/std/ref.md +++ b/docs/std/ref.md @@ -22,7 +22,7 @@ The default implementation is nonblocking and lightweight, consisting essentially of a purely functional wrapper over an `AtomicReference`. Consequently it _must not_ be used to store mutable data as `AtomicReference#compareAndSet` and friends are not threadsafe and are dependent -upon object reference identity. +upon object reference equality. ### Concurrent Counter diff --git a/kernel/shared/src/main/scala/cats/effect/kernel/Ref.scala b/kernel/shared/src/main/scala/cats/effect/kernel/Ref.scala index 9b3343f784..196e04b556 100644 --- a/kernel/shared/src/main/scala/cats/effect/kernel/Ref.scala +++ b/kernel/shared/src/main/scala/cats/effect/kernel/Ref.scala @@ -36,7 +36,7 @@ import scala.annotation.tailrec * The default implementation is nonblocking and lightweight, consisting essentially of a purely * functional wrapper over an `AtomicReference`. Consequently it ''must not'' be used to store mutable * data as `AtomicReference#compareAndSet` and friends are not threadsafe and are dependent - * upon object reference identity. + * upon object reference equality. */ abstract class Ref[F[_], A] extends RefSource[F, A] with RefSink[F, A] { From 7daeb8a35c7c6964d05410f5d799dc7f0183f834 Mon Sep 17 00:00:00 2001 From: Tim Spence Date: Fri, 24 Jun 2022 10:52:54 +0100 Subject: [PATCH 4/4] Scalafmt --- kernel/shared/src/main/scala/cats/effect/kernel/Ref.scala | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/kernel/shared/src/main/scala/cats/effect/kernel/Ref.scala b/kernel/shared/src/main/scala/cats/effect/kernel/Ref.scala index 196e04b556..d7fa508939 100644 --- a/kernel/shared/src/main/scala/cats/effect/kernel/Ref.scala +++ b/kernel/shared/src/main/scala/cats/effect/kernel/Ref.scala @@ -34,9 +34,9 @@ import scala.annotation.tailrec * initialised to a value. * * The default implementation is nonblocking and lightweight, consisting essentially of a purely - * functional wrapper over an `AtomicReference`. Consequently it ''must not'' be used to store mutable - * data as `AtomicReference#compareAndSet` and friends are not threadsafe and are dependent - * upon object reference equality. + * functional wrapper over an `AtomicReference`. Consequently it ''must not'' be used to store + * mutable data as `AtomicReference#compareAndSet` and friends are not threadsafe and are + * dependent upon object reference equality. */ abstract class Ref[F[_], A] extends RefSource[F, A] with RefSink[F, A] {