diff --git a/Modules/Examples/Misc JVM/src/main/scala/ex2021encfixtodo/sync/DataManagerConnectionManager.scala b/Modules/Examples/Misc JVM/src/main/scala/ex2021encfixtodo/sync/DataManagerConnectionManager.scala index 3669fd4a0..00bf7da01 100644 --- a/Modules/Examples/Misc JVM/src/main/scala/ex2021encfixtodo/sync/DataManagerConnectionManager.scala +++ b/Modules/Examples/Misc JVM/src/main/scala/ex2021encfixtodo/sync/DataManagerConnectionManager.scala @@ -7,7 +7,7 @@ import com.google.crypto.tink.aead.AeadConfig import com.google.crypto.tink.{Aead, CleartextKeysetHandle, JsonKeysetReader, JsonKeysetWriter, KeyTemplates, KeysetHandle, LegacyKeysetSerialization} import rdts.base.{Bottom, Lattice, LocalUid} import rdts.dotted.{Dotted, HasDots, Obrem} -import replication.{DeltaDissemination} +import replication.DeltaDissemination import java.net.{InetSocketAddress, Socket, URI} import java.nio.file.{Files, Path} @@ -25,7 +25,7 @@ class AeadTranslation(aead: com.google.crypto.tink.Aead) extends replication.Aea Try(aead.decrypt(data, associated)) } -class DataManagerConnectionManager[State: {JsonValueCodec, Lattice, Bottom, HasDots}]( +class DataManagerConnectionManager[State: { JsonValueCodec, Lattice, Bottom, HasDots }]( replicaId: LocalUid, receiveCallback: Obrem[State] => Unit ) extends ConnectionManager[Obrem[State]] { diff --git a/Modules/Local-first Access Control/src/main/scala/lofi_acl/access/DeltaSurgeon.scala b/Modules/Local-first Access Control/src/main/scala/lofi_acl/access/DeltaSurgeon.scala index f5b5264bc..363c5d9e2 100644 --- a/Modules/Local-first Access Control/src/main/scala/lofi_acl/access/DeltaSurgeon.scala +++ b/Modules/Local-first Access Control/src/main/scala/lofi_acl/access/DeltaSurgeon.scala @@ -137,9 +137,9 @@ object DeltaSurgeon { } // Used for values that should not be further isolated - def ofTerminalValue[V: {Bottom, JsonValueCodec}]: DeltaSurgeon[V] = new TerminalValueDeltaSurgeon[V] + def ofTerminalValue[V: { Bottom, JsonValueCodec }]: DeltaSurgeon[V] = new TerminalValueDeltaSurgeon[V] - private class TerminalValueDeltaSurgeon[V: {Bottom, JsonValueCodec}] extends DeltaSurgeon[V] { + private class TerminalValueDeltaSurgeon[V: { Bottom, JsonValueCodec }] extends DeltaSurgeon[V] { override def isolate(delta: V): IsolatedDeltaParts = if Bottom[V].isEmpty(delta) then IsolatedDeltaParts(Map.empty) else IsolatedDeltaParts(writeToArray(delta)) @@ -153,10 +153,10 @@ object DeltaSurgeon { import lofi_acl.sync.JsoniterCodecs.dotsCodec - given dotsDeltaSurgeon: DeltaSurgeon[Dots] = ofTerminalValue[Dots] - given dottedDeltaSurgeon[T: {DeltaSurgeon, Bottom}]: DeltaSurgeon[Dotted[T]] = DeltaSurgeon.derived - given obremDeltaSurgeon[T: {DeltaSurgeon, Bottom}]: DeltaSurgeon[Obrem[T]] = DeltaSurgeon.derived - given optionSurgeon[T: {Bottom, DeltaSurgeon}]: DeltaSurgeon[Option[T]] = { + given dotsDeltaSurgeon: DeltaSurgeon[Dots] = ofTerminalValue[Dots] + given dottedDeltaSurgeon[T: { DeltaSurgeon, Bottom }]: DeltaSurgeon[Dotted[T]] = DeltaSurgeon.derived + given obremDeltaSurgeon[T: { DeltaSurgeon, Bottom }]: DeltaSurgeon[Obrem[T]] = DeltaSurgeon.derived + given optionSurgeon[T: { Bottom, DeltaSurgeon }]: DeltaSurgeon[Option[T]] = { given noneBottom: Bottom[None.type] = Bottom.provide(None) // TODO: Bottom for singletons should be derivable given noneDeltaSurgeon: DeltaSurgeon[None.type] = DeltaSurgeon.derived given someBottom: Bottom[Some[T]] = Bottom.derived diff --git a/Modules/Local-first Access Control/src/main/scala/lofi_acl/access/Filter.scala b/Modules/Local-first Access Control/src/main/scala/lofi_acl/access/Filter.scala index ff41989c2..b03b5f90d 100644 --- a/Modules/Local-first Access Control/src/main/scala/lofi_acl/access/Filter.scala +++ b/Modules/Local-first Access Control/src/main/scala/lofi_acl/access/Filter.scala @@ -214,6 +214,6 @@ object Filter: def ofTerminalValue[T: Bottom]: Filter[T] = TerminalFilter[T]() - given dottedFilter[A: {Filter, Bottom}]: Filter[Dotted[A]] = Filter.derived + given dottedFilter[A: { Filter, Bottom }]: Filter[Dotted[A]] = Filter.derived - given obremFilter[A: {Filter, Bottom}]: Filter[Obrem[A]] = Filter.derived + given obremFilter[A: { Filter, Bottom }]: Filter[Obrem[A]] = Filter.derived diff --git a/Modules/Local-first Access Control/src/main/scala/lofi_acl/ardt/datatypes/AddWinsMap.scala b/Modules/Local-first Access Control/src/main/scala/lofi_acl/ardt/datatypes/AddWinsMap.scala index 94f709284..a9202e978 100644 --- a/Modules/Local-first Access Control/src/main/scala/lofi_acl/ardt/datatypes/AddWinsMap.scala +++ b/Modules/Local-first Access Control/src/main/scala/lofi_acl/ardt/datatypes/AddWinsMap.scala @@ -61,7 +61,7 @@ object AddWinsMap: * @return * The delta that contains the removal (and nothing else) */ - def remove[K, V: {Bottom, HasDots}](key: K, map: AddWinsMap[K, V]): AddWinsMap[K, V] = Dotted( + def remove[K, V: { Bottom, HasDots }](key: K, map: AddWinsMap[K, V]): AddWinsMap[K, V] = Dotted( Bottom[Map[K, V]].empty, HasDots[V].dots(map.data.getOrElse(key, Bottom[V].empty)) ) diff --git a/Modules/Local-first Access Control/src/main/scala/lofi_acl/ardt/datatypes/LWW.scala b/Modules/Local-first Access Control/src/main/scala/lofi_acl/ardt/datatypes/LWW.scala index da9bce8e7..e387f12f0 100644 --- a/Modules/Local-first Access Control/src/main/scala/lofi_acl/ardt/datatypes/LWW.scala +++ b/Modules/Local-first Access Control/src/main/scala/lofi_acl/ardt/datatypes/LWW.scala @@ -11,7 +11,7 @@ import rdts.time.CausalTime type LWW[V] = LastWriterWins[V] object LWW { - given recursiveFilter[V: {Filter, Bottom}]: Filter[LWW[V]] with + given recursiveFilter[V: { Filter, Bottom }]: Filter[LWW[V]] with override def filter(delta: LWW[V], permission: PermissionTree): LWW[V] = permission match case PermissionTree(ALLOW, _) => delta case PermissionTree(PARTIAL, _) => delta.copy(payload = Filter[V].filter(delta.read, permission)) @@ -40,5 +40,5 @@ object LWW { given codec: JsonValueCodec[CausalTime] = JsonCodecMaker.make[CausalTime] DeltaSurgeon.ofTerminalValue } - given deltaSurgeon[V: {Bottom, DeltaSurgeon}]: DeltaSurgeon[LWW[V]] = DeltaSurgeon.derived + given deltaSurgeon[V: { Bottom, DeltaSurgeon }]: DeltaSurgeon[LWW[V]] = DeltaSurgeon.derived } diff --git a/Modules/Local-first Access Control/src/main/scala/lofi_acl/ardt/datatypes/ORMap.scala b/Modules/Local-first Access Control/src/main/scala/lofi_acl/ardt/datatypes/ORMap.scala index 32671cee5..edcb3ce15 100644 --- a/Modules/Local-first Access Control/src/main/scala/lofi_acl/ardt/datatypes/ORMap.scala +++ b/Modules/Local-first Access Control/src/main/scala/lofi_acl/ardt/datatypes/ORMap.scala @@ -52,5 +52,5 @@ object ORMap { ) case None => minimized - given observeRemoveMapEntryFilter[A: {Filter, Bottom}]: Filter[Entry[A]] = Filter.derived + given observeRemoveMapEntryFilter[A: { Filter, Bottom }]: Filter[Entry[A]] = Filter.derived } diff --git a/Modules/Microbenchmarks/src/main/scala/benchmarks/lattices/CausalQueueBench.scala b/Modules/Microbenchmarks/src/main/scala/benchmarks/lattices/CausalQueueBench.scala index 77fce735c..b985d380e 100644 --- a/Modules/Microbenchmarks/src/main/scala/benchmarks/lattices/CausalQueueBench.scala +++ b/Modules/Microbenchmarks/src/main/scala/benchmarks/lattices/CausalQueueBench.scala @@ -6,7 +6,6 @@ import rdts.datatypes.alternatives.rga.Sequence.{RGA, RGAOps} import java.util.concurrent.TimeUnit - @BenchmarkMode(Array(Mode.AverageTime)) @OutputTimeUnit(TimeUnit.MILLISECONDS) @Warmup(iterations = 3, time = 1000, timeUnit = TimeUnit.MILLISECONDS) diff --git a/Modules/Microbenchmarks/src/main/scala/benchmarks/lattices/delta/crdt/LWWRegisterBench.scala b/Modules/Microbenchmarks/src/main/scala/benchmarks/lattices/delta/crdt/LWWRegisterBench.scala index c64eaf21b..db6ddaa0b 100644 --- a/Modules/Microbenchmarks/src/main/scala/benchmarks/lattices/delta/crdt/LWWRegisterBench.scala +++ b/Modules/Microbenchmarks/src/main/scala/benchmarks/lattices/delta/crdt/LWWRegisterBench.scala @@ -15,7 +15,7 @@ import java.util.concurrent.TimeUnit @Threads(1) @State(Scope.Thread) class LWWRegisterBench { - + given Decompose[LastWriterWins[Int]] = Decompose.atomic var full: NamedDeltaBuffer[LastWriterWins[Int]] = scala.compiletime.uninitialized diff --git a/Modules/Microbenchmarks/src/main/scala/benchmarks/lattices/delta/crdt/NamedDeltaBuffer.scala b/Modules/Microbenchmarks/src/main/scala/benchmarks/lattices/delta/crdt/NamedDeltaBuffer.scala index 406cd8c90..73d04e028 100644 --- a/Modules/Microbenchmarks/src/main/scala/benchmarks/lattices/delta/crdt/NamedDeltaBuffer.scala +++ b/Modules/Microbenchmarks/src/main/scala/benchmarks/lattices/delta/crdt/NamedDeltaBuffer.scala @@ -43,7 +43,7 @@ object NamedDeltaBuffer { extension [A](curr: DeltaBufferDotted[A]) def data: A = curr.state.data implicit object workaround { - extension [A](curr: NamedDeltaBuffer[A])(using Lattice[A], Decompose[A]) + extension [A](curr: NamedDeltaBuffer[A])(using Lattice[A], Decompose[A]) inline def mod(f: A => A): NamedDeltaBuffer[A] = { curr.applyDelta(curr.replicaID.uid, f(curr.state)) } diff --git a/Modules/Microbenchmarks/src/main/scala/benchmarks/lattices/delta/crdt/RCounterBench.scala b/Modules/Microbenchmarks/src/main/scala/benchmarks/lattices/delta/crdt/RCounterBench.scala index 32d03df03..3508c3c3d 100644 --- a/Modules/Microbenchmarks/src/main/scala/benchmarks/lattices/delta/crdt/RCounterBench.scala +++ b/Modules/Microbenchmarks/src/main/scala/benchmarks/lattices/delta/crdt/RCounterBench.scala @@ -7,7 +7,6 @@ import rdts.datatypes.alternatives.ResettableCounter import rdts.dotted.Dotted import benchmarks.lattices.delta.crdt.NamedDeltaBuffer.mod - import java.util.concurrent.TimeUnit @BenchmarkMode(Array(Mode.Throughput)) diff --git a/Modules/RDTs/src/main/scala/rdts/base/Lattice.scala b/Modules/RDTs/src/main/scala/rdts/base/Lattice.scala index 59d35cc64..a9a7516b0 100644 --- a/Modules/RDTs/src/main/scala/rdts/base/Lattice.scala +++ b/Modules/RDTs/src/main/scala/rdts/base/Lattice.scala @@ -28,8 +28,8 @@ trait Lattice[A] { * IntelliJ also does not like to implement or override extension methods. */ extension (left: A) { final inline def subsumedBy(right: A): Boolean = Lattice.this.subsumption(left, right) - final inline def subsumes(right: A): Boolean = Lattice.this.subsumption(right, left) - final inline def inflates(right: A): Boolean = !Lattice.this.subsumption(left, right) + final inline def subsumes(right: A): Boolean = Lattice.this.subsumption(right, left) + final inline def inflates(right: A): Boolean = !Lattice.this.subsumption(left, right) @targetName("mergeInfix") final inline def merge(right: A): A = Lattice.this.merge(left, right) @@ -40,7 +40,7 @@ object Lattice { def apply[A](using ev: Lattice[A]): Lattice[A] = ev // forwarder for better syntax/type inference - def merge[A: Lattice](left: A, right: A): A = apply[A].merge(left, right) + def merge[A: Lattice](left: A, right: A): A = apply[A].merge(left, right) def subsumption[A: Lattice](left: A, right: A): Boolean = apply[A].subsumption(left, right) /** Some types have multiple structural representations for semantically the same value, e.g., they may contain redundant or replaced parts. This can lead to semantically equivalent values that are not structurally equal. Normalize tries to fix this. @@ -48,7 +48,7 @@ object Lattice { */ def normalize[A: Lattice](v: A): A = v `merge` v - def diff[A: {Lattice, Decompose}](state: A, delta: A): Option[A] = { + def diff[A: { Lattice, Decompose }](state: A, delta: A): Option[A] = { delta.decomposed.filter(!subsumption(_, state)).reduceOption(merge) } @@ -81,7 +81,7 @@ object Lattice { } def fromOrdering[A: Ordering]: Lattice[A] = new Lattice[A] { - override def merge(left: A, right: A): A = if subsumption(left, right) then right else left + override def merge(left: A, right: A): A = if subsumption(left, right) then right else left override def subsumption(left: A, right: A): Boolean = Ordering[A].lteq(left, right) } @@ -96,7 +96,7 @@ object Lattice { // /////////////// common instances below /////////////// given setLattice[A]: Lattice[Set[A]] with - override def merge(left: Set[A], right: Set[A]): Set[A] = left `union` right + override def merge(left: Set[A], right: Set[A]): Set[A] = left `union` right override def subsumption(left: Set[A], right: Set[A]): Boolean = left subsetOf right given optionLattice[A: Lattice]: Lattice[Option[A]] = diff --git a/Modules/RDTs/src/main/scala/rdts/datatypes/Epoch.scala b/Modules/RDTs/src/main/scala/rdts/datatypes/Epoch.scala index 1c1131805..3d1bbec4e 100644 --- a/Modules/RDTs/src/main/scala/rdts/datatypes/Epoch.scala +++ b/Modules/RDTs/src/main/scala/rdts/datatypes/Epoch.scala @@ -24,14 +24,14 @@ object Epoch { given bottom[E: Bottom]: Bottom[Epoch[E]] with override def empty: Epoch[E] = Epoch.empty - given hasDots[E: {HasDots, Bottom}]: HasDots[Epoch[E]] = new { + given hasDots[E: { HasDots, Bottom }]: HasDots[Epoch[E]] = new { extension (dotted: Epoch[E]) def dots: Dots = dotted.value.dots def removeDots(dots: Dots): Option[Epoch[E]] = dotted.value.removeDots(dots).map(nv => dotted.copy(value = nv)) } given decomposeInstance[E: Decompose]: Decompose[Epoch[E]] = - case Epoch(c, v) => Decompose.decompose(v).map(Epoch(c, _)) + case Epoch(c, v) => Decompose.decompose(v).map(Epoch(c, _)) given latticeInstance[E: Lattice]: Lattice[Epoch[E]] = new Lattice[Epoch[E]] { diff --git a/Modules/RDTs/src/main/scala/rdts/datatypes/LastWriterWins.scala b/Modules/RDTs/src/main/scala/rdts/datatypes/LastWriterWins.scala index bf1564ec6..27ad652b9 100644 --- a/Modules/RDTs/src/main/scala/rdts/datatypes/LastWriterWins.scala +++ b/Modules/RDTs/src/main/scala/rdts/datatypes/LastWriterWins.scala @@ -50,8 +50,10 @@ object LastWriterWins { case _ => GenericLastWriterWinsLattice(Lattice.assertEquals) } - class GenericLastWriterWinsLattice[A](conflict: Lattice[A]) extends Lattice[LastWriterWins[A]] with Decompose[LastWriterWins[A]] { - override def subsumption(left: LastWriterWins[A], right: LastWriterWins[A]): Boolean = left.timestamp <= right.timestamp + class GenericLastWriterWinsLattice[A](conflict: Lattice[A]) extends Lattice[LastWriterWins[A]] + with Decompose[LastWriterWins[A]] { + override def subsumption(left: LastWriterWins[A], right: LastWriterWins[A]): Boolean = + left.timestamp <= right.timestamp extension (a: LastWriterWins[A]) override def decomposed: Iterable[LastWriterWins[A]] = List(a) diff --git a/Modules/RDTs/src/main/scala/rdts/datatypes/TwoPhaseSet.scala b/Modules/RDTs/src/main/scala/rdts/datatypes/TwoPhaseSet.scala index 685b99502..de5658a08 100644 --- a/Modules/RDTs/src/main/scala/rdts/datatypes/TwoPhaseSet.scala +++ b/Modules/RDTs/src/main/scala/rdts/datatypes/TwoPhaseSet.scala @@ -32,8 +32,8 @@ object TwoPhaseSet { given bottom[E]: Bottom[TwoPhaseSet[E]] with { override def empty: TwoPhaseSet[E] = TwoPhaseSet.empty } - given lattice[E]: Lattice[TwoPhaseSet[E]] = Lattice.derived + given lattice[E]: Lattice[TwoPhaseSet[E]] = Lattice.derived given decompose[E]: Decompose[TwoPhaseSet[E]] = Decompose.derived - given hasDots[E]: HasDots[TwoPhaseSet[E]] = HasDots.noDots + given hasDots[E]: HasDots[TwoPhaseSet[E]] = HasDots.noDots } diff --git a/Modules/RDTs/src/main/scala/rdts/datatypes/contextual/MultiVersionRegister.scala b/Modules/RDTs/src/main/scala/rdts/datatypes/contextual/MultiVersionRegister.scala index 60996b821..458e8ef5d 100644 --- a/Modules/RDTs/src/main/scala/rdts/datatypes/contextual/MultiVersionRegister.scala +++ b/Modules/RDTs/src/main/scala/rdts/datatypes/contextual/MultiVersionRegister.scala @@ -36,7 +36,7 @@ object MultiVersionRegister { given bottomInstance[A]: Bottom[MultiVersionRegister[A]] = Bottom.derived - given decomposeInstance[A]: Decompose[MultiVersionRegister[A]] = + given decomposeInstance[A]: Decompose[MultiVersionRegister[A]] = given Decompose[A] = Decompose.atomic Decompose.derived diff --git a/Modules/RDTs/src/main/scala/rdts/datatypes/contextual/ObserveRemoveMap.scala b/Modules/RDTs/src/main/scala/rdts/datatypes/contextual/ObserveRemoveMap.scala index 7ac26c58a..840402862 100644 --- a/Modules/RDTs/src/main/scala/rdts/datatypes/contextual/ObserveRemoveMap.scala +++ b/Modules/RDTs/src/main/scala/rdts/datatypes/contextual/ObserveRemoveMap.scala @@ -125,7 +125,7 @@ object ObserveRemoveMap { given hasDots[K, V: HasDots]: HasDots[ObserveRemoveMap[K, V]] = HasDots.derived - given lattice[K, V: {Lattice, HasDots}]: Lattice[ObserveRemoveMap[K, V]] = + given lattice[K, V: { Lattice, HasDots }]: Lattice[ObserveRemoveMap[K, V]] = Lattice.derived private def make[K, V]( diff --git a/Modules/RDTs/src/main/scala/rdts/datatypes/contextual/ReplicatedSet.scala b/Modules/RDTs/src/main/scala/rdts/datatypes/contextual/ReplicatedSet.scala index fc5cdcaec..90c41c5e5 100644 --- a/Modules/RDTs/src/main/scala/rdts/datatypes/contextual/ReplicatedSet.scala +++ b/Modules/RDTs/src/main/scala/rdts/datatypes/contextual/ReplicatedSet.scala @@ -85,9 +85,9 @@ object ReplicatedSet { def empty[E]: ReplicatedSet[E] = ReplicatedSet(Map.empty) - given bottom[E]: Bottom[ReplicatedSet[E]] = Bottom.provide(empty) - given lattice[E]: Lattice[ReplicatedSet[E]] = Lattice.derived + given bottom[E]: Bottom[ReplicatedSet[E]] = Bottom.provide(empty) + given lattice[E]: Lattice[ReplicatedSet[E]] = Lattice.derived given decompose[E]: Decompose[ReplicatedSet[E]] = Decompose.derived - given hasDots[E]: HasDots[ReplicatedSet[E]] = HasDots.derived + given hasDots[E]: HasDots[ReplicatedSet[E]] = HasDots.derived } diff --git a/Modules/RDTs/src/main/scala/rdts/datatypes/experiments/Causal.scala b/Modules/RDTs/src/main/scala/rdts/datatypes/experiments/Causal.scala index 069664495..ca0dbaaa3 100644 --- a/Modules/RDTs/src/main/scala/rdts/datatypes/experiments/Causal.scala +++ b/Modules/RDTs/src/main/scala/rdts/datatypes/experiments/Causal.scala @@ -19,7 +19,7 @@ object CausalDelta { case class CausalStore[A](pending: CausalDelta[A], state: A) object CausalStore { - given lattice[A: {Bottom, Lattice}]: Lattice[CausalStore[A]] with { + given lattice[A: { Bottom, Lattice }]: Lattice[CausalStore[A]] with { def merge(left: CausalStore[A], right: CausalStore[A]): CausalStore[A] = val pending: CausalDelta[A] = left.pending `merge` right.pending val state = left.state `merge` right.state @@ -30,6 +30,6 @@ object CausalStore { given bottom[A: Bottom]: Bottom[CausalStore[A]] = Bottom.derived - given hasDots[A: {HasDots, Bottom}]: HasDots[CausalStore[A]] = HasDots.derived + given hasDots[A: { HasDots, Bottom }]: HasDots[CausalStore[A]] = HasDots.derived } diff --git a/Modules/RDTs/src/main/scala/rdts/datatypes/experiments/protocols/Membership.scala b/Modules/RDTs/src/main/scala/rdts/datatypes/experiments/protocols/Membership.scala index 3e4ec1982..0c568a498 100644 --- a/Modules/RDTs/src/main/scala/rdts/datatypes/experiments/protocols/Membership.scala +++ b/Modules/RDTs/src/main/scala/rdts/datatypes/experiments/protocols/Membership.scala @@ -35,7 +35,7 @@ case class Membership[A, C[_], D[_]]( log: Map[Long, A] = Map.empty, ) { - //TODO: investigate further … + // TODO: investigate further … override def toString: String = "MEMBERSHIP TO STRING MAKES SPEC TESTS SLOW, WTF" private def bottomRound(using Consensus[C], Consensus[D]): MembershipRound[A, C, D] = diff --git a/Modules/RDTs/src/main/scala/rdts/datatypes/experiments/protocols/Tokens.scala b/Modules/RDTs/src/main/scala/rdts/datatypes/experiments/protocols/Tokens.scala index fc93d1320..04790fd34 100644 --- a/Modules/RDTs/src/main/scala/rdts/datatypes/experiments/protocols/Tokens.scala +++ b/Modules/RDTs/src/main/scala/rdts/datatypes/experiments/protocols/Tokens.scala @@ -1,9 +1,9 @@ package rdts.datatypes.experiments.protocols +import rdts.base.LocalUid.replicaId import rdts.base.{Bottom, Lattice, LocalUid, Orderings, Uid} import rdts.datatypes.contextual.ReplicatedSet import rdts.dotted.{Dotted, HasDots} -import LocalUid.replicaId import rdts.time.Dots case class Ownership(epoch: Long, owner: Uid) @@ -51,13 +51,13 @@ case class ExampleTokens( calendarBinteractionA: Token ) -case class Exclusive[T : { Lattice, Bottom}](token: Token, value: T) { +case class Exclusive[T: { Lattice, Bottom }](token: Token, value: T) { def transform(f: T => T)(using LocalUid) = if token.isOwner then f(value) else Bottom.empty } /** totally not incredibly inefficient */ -case class Causal[T: {Lattice, HasDots, Bottom}](deltas: Set[Dotted[T]]) { +case class Causal[T: { Lattice, HasDots, Bottom }](deltas: Set[Dotted[T]]) { def value: T = val causalPrefix = deltas.map(_.context).reduceOption(_ `union` _).map(_.causalPrefix).getOrElse(Dots.empty) deltas.filter(delta => delta.context <= causalPrefix).reduceOption(Dotted.lattice.merge).map(_.data).getOrElse( diff --git a/Modules/RDTs/src/main/scala/rdts/datatypes/experiments/protocols/simplified/GeneralizedPaxos.scala b/Modules/RDTs/src/main/scala/rdts/datatypes/experiments/protocols/simplified/GeneralizedPaxos.scala index d1990ecf9..83ce491be 100644 --- a/Modules/RDTs/src/main/scala/rdts/datatypes/experiments/protocols/simplified/GeneralizedPaxos.scala +++ b/Modules/RDTs/src/main/scala/rdts/datatypes/experiments/protocols/simplified/GeneralizedPaxos.scala @@ -6,9 +6,9 @@ import rdts.datatypes.LastWriterWins import rdts.datatypes.experiments.protocols.{Consensus, Participants} case class GeneralizedPaxos[A]( - rounds: Map[BallotNum, (LeaderElection, Voting[A])] = + rounds: Map[BallotNum, (LeaderElection, Voting[A])] = Map.empty[BallotNum, (LeaderElection, Voting[A])], - myValue: Map[Uid, LastWriterWins[A]] = Map.empty + myValue: Map[Uid, LastWriterWins[A]] = Map.empty ): def voteFor(leader: Uid, value: A)(using LocalUid, Participants): (LeaderElection, Voting[A]) = diff --git a/Modules/RDTs/src/main/scala/rdts/dotted/Dotted.scala b/Modules/RDTs/src/main/scala/rdts/dotted/Dotted.scala index 4b70b5337..3bfe1427a 100644 --- a/Modules/RDTs/src/main/scala/rdts/dotted/Dotted.scala +++ b/Modules/RDTs/src/main/scala/rdts/dotted/Dotted.scala @@ -33,7 +33,7 @@ object Obrem { def empty[A: Bottom]: Obrem[A] = Obrem(Bottom.empty[A], Dots.empty, Dots.empty) - given lattice[A: {HasDots, Bottom, Lattice}]: FilteredLattice[Obrem[A]](Lattice.derived) with { + given lattice[A: { HasDots, Bottom, Lattice }]: FilteredLattice[Obrem[A]](Lattice.derived) with { override def filter(base: Obrem[A], other: Obrem[A]): Obrem[A] = if other.deletions.isEmpty then base @@ -76,10 +76,11 @@ object Dotted { def empty[A: Bottom]: Dotted[A] = Dotted(Bottom.empty[A], Dots.empty) def apply[A](a: A): Dotted[A] = Dotted(a, Dots.empty) - given decompose[A: {Decompose, HasDots, Bottom, Lattice}]: Decompose[Dotted[A]] = new Decompose[Dotted[A]] { + given decompose[A: { Decompose, HasDots, Bottom, Lattice }]: Decompose[Dotted[A]] = new Decompose[Dotted[A]] { extension (a: Dotted[A]) override def decomposed: Iterable[Dotted[A]] = { + /** Dotted decompose guarantees decomposes its inner value, but recomposes any values with overlapping dots, such that each dot is present in exactly one of the returned deltas. */ val deltas = a.data.decomposed.flatMap: delta => val dots = delta.dots @@ -95,7 +96,7 @@ object Dotted { } } - given lattice[A: {HasDots, Bottom, Lattice}]: FilteredLattice[Dotted[A]](Lattice.derived) with { + given lattice[A: { HasDots, Bottom, Lattice }]: FilteredLattice[Dotted[A]](Lattice.derived) with { override def filter(base: Dotted[A], other: Dotted[A]): Dotted[A] = val deletions = other.deletions diff --git a/Modules/RDTs/src/main/scala/rdts/time/ArrayRanges.scala b/Modules/RDTs/src/main/scala/rdts/time/ArrayRanges.scala index 3b3484fa0..428eef948 100644 --- a/Modules/RDTs/src/main/scala/rdts/time/ArrayRanges.scala +++ b/Modules/RDTs/src/main/scala/rdts/time/ArrayRanges.scala @@ -361,9 +361,9 @@ object ArrayRanges { given latticeInstance: Lattice[ArrayRanges] with Decompose[ArrayRanges] with { extension (a: ArrayRanges) - override def decomposed: Iterable[ArrayRanges] = a.decomposed - override def subsumption(left: ArrayRanges, right: ArrayRanges): Boolean = left <= right - override def merge(left: ArrayRanges, right: ArrayRanges): ArrayRanges = left `union` right + override def decomposed: Iterable[ArrayRanges] = a.decomposed + override def subsumption(left: ArrayRanges, right: ArrayRanges): Boolean = left <= right + override def merge(left: ArrayRanges, right: ArrayRanges): ArrayRanges = left `union` right } def leftRightToOrder: (Boolean, Boolean) => Option[Int] = diff --git a/Modules/RDTs/src/test/scala/test/rdts/DataGenerator.scala b/Modules/RDTs/src/test/scala/test/rdts/DataGenerator.scala index 82a89d544..74a3b3924 100644 --- a/Modules/RDTs/src/test/scala/test/rdts/DataGenerator.scala +++ b/Modules/RDTs/src/test/scala/test/rdts/DataGenerator.scala @@ -82,8 +82,6 @@ object DataGenerator { val map = Gen.listOf(pairgen).map(vs => MultiValueRegister(vs.toMap)) Arbitrary(map) - - val genDot: Gen[Dot] = for id <- Gen.oneOf('a' to 'g') @@ -175,13 +173,13 @@ object DataGenerator { given arbEnableWinsFlag: Arbitrary[contextual.EnableWinsFlag] = Arbitrary: arbDots.arbitrary.map(EnableWinsFlag.apply) - given arbCausalDelta[A: {Arbitrary, HasDots}]: Arbitrary[CausalDelta[A]] = Arbitrary: + given arbCausalDelta[A: { Arbitrary, HasDots }]: Arbitrary[CausalDelta[A]] = Arbitrary: for predec <- arbDots.arbitrary value <- Arbitrary.arbitrary[A] yield CausalDelta(value.dots, Dots.empty, value) - given arbCausalStore[A: {Arbitrary, HasDots, Bottom, Lattice}]: Arbitrary[CausalStore[A]] = Arbitrary: + given arbCausalStore[A: { Arbitrary, HasDots, Bottom, Lattice }]: Arbitrary[CausalStore[A]] = Arbitrary: for predec <- arbCausalDelta.arbitrary value <- Arbitrary.arbitrary[A] diff --git a/Modules/RDTs/src/test/scala/test/rdts/baseproperties/DecompsoePropertyChecks.scala b/Modules/RDTs/src/test/scala/test/rdts/baseproperties/DecompsoePropertyChecks.scala index 3427394f2..fa7bcb67c 100644 --- a/Modules/RDTs/src/test/scala/test/rdts/baseproperties/DecompsoePropertyChecks.scala +++ b/Modules/RDTs/src/test/scala/test/rdts/baseproperties/DecompsoePropertyChecks.scala @@ -18,24 +18,25 @@ import test.rdts.isGithubCi import scala.util.{Failure, Success} -class DotSetDecomposeChecks extends DecomposePropertyChecks[Dotted[Dots]] -class EnableWinsFlagDecomposeChecks extends DecomposePropertyChecks[Dotted[contextual.EnableWinsFlag]] -class DotFunDecomposeChecks extends DecomposePropertyChecks[Dotted[Map[Dot, Int]]] +class DotSetDecomposeChecks extends DecomposePropertyChecks[Dotted[Dots]] +class EnableWinsFlagDecomposeChecks extends DecomposePropertyChecks[Dotted[contextual.EnableWinsFlag]] +class DotFunDecomposeChecks extends DecomposePropertyChecks[Dotted[Map[Dot, Int]]] class ConMultiVersionDecomposeChecks extends DecomposePropertyChecks[Dotted[contextual.MultiVersionRegister[Int]]] -class DotMapDecomposeChecks extends DecomposePropertyChecks[Dotted[Map[rdts.base.Uid, Dots]]](expensive = true) +class DotMapDecomposeChecks extends DecomposePropertyChecks[Dotted[Map[rdts.base.Uid, Dots]]](expensive = true) class GrowOnlyCounterDecomposeChecks extends DecomposePropertyChecks[GrowOnlyCounter] -class GrowOnlyMapDecomposeChecks extends DecomposePropertyChecks[GrowOnlyMap[String, Int]] -class TwoPhaseSetDecomposeChecks extends DecomposePropertyChecks[TwoPhaseSet[Int]] -class IntDecomposeChecks extends DecomposePropertyChecks[Int] -class SetDecomposeChecks extends DecomposePropertyChecks[Set[String]] -class MapDecomposeChecks extends DecomposePropertyChecks[Map[String, Int]] -class MultiValueDecomposeChecks extends DecomposePropertyChecks[MultiValueRegister[Int]](flaky = true) -class PosNegDecomposeChecks extends DecomposePropertyChecks[PosNegCounter] -class TupleDecomposeChecks extends DecomposePropertyChecks[(Set[Int], GrowOnlyCounter)] -class GrowOnlyListDecomposeChecks extends DecomposePropertyChecks[GrowOnlyList[Int]](expensive = true) -class ReplicatedListDecomposeChecks extends DecomposePropertyChecks[Dotted[ReplicatedList[ExampleData]]](expensive = true) +class GrowOnlyMapDecomposeChecks extends DecomposePropertyChecks[GrowOnlyMap[String, Int]] +class TwoPhaseSetDecomposeChecks extends DecomposePropertyChecks[TwoPhaseSet[Int]] +class IntDecomposeChecks extends DecomposePropertyChecks[Int] +class SetDecomposeChecks extends DecomposePropertyChecks[Set[String]] +class MapDecomposeChecks extends DecomposePropertyChecks[Map[String, Int]] +class MultiValueDecomposeChecks extends DecomposePropertyChecks[MultiValueRegister[Int]](flaky = true) +class PosNegDecomposeChecks extends DecomposePropertyChecks[PosNegCounter] +class TupleDecomposeChecks extends DecomposePropertyChecks[(Set[Int], GrowOnlyCounter)] +class GrowOnlyListDecomposeChecks extends DecomposePropertyChecks[GrowOnlyList[Int]](expensive = true) +class ReplicatedListDecomposeChecks + extends DecomposePropertyChecks[Dotted[ReplicatedList[ExampleData]]](expensive = true) class LWWTupleDecomposeChecks - extends LatticePropertyChecks[(Option[LastWriterWins[Int]], Option[LastWriterWins[Int]])] + extends LatticePropertyChecks[(Option[LastWriterWins[Int]], Option[LastWriterWins[Int]])] abstract class DecomposePropertyChecks[A]( expensive: Boolean = false, diff --git a/Modules/RDTs/src/test/scala/test/rdts/baseproperties/HasDotsChecks.scala b/Modules/RDTs/src/test/scala/test/rdts/baseproperties/HasDotsChecks.scala index 6f476f53a..7c30ca086 100644 --- a/Modules/RDTs/src/test/scala/test/rdts/baseproperties/HasDotsChecks.scala +++ b/Modules/RDTs/src/test/scala/test/rdts/baseproperties/HasDotsChecks.scala @@ -19,7 +19,7 @@ class ReplicatedListHDChecks extends HasDotsChecks[ReplicatedList[ExampleData]] // the specification of these tests is nice, but the generators are essentially useless, as it is extremely unlikely // that they will produce any kind of comparable values -abstract class HasDotsChecks[A: {Arbitrary, HasDots}] extends munit.ScalaCheckSuite { +abstract class HasDotsChecks[A: { Arbitrary, HasDots }] extends munit.ScalaCheckSuite { property("remove is precise") { forAll: (a: A) => val dots = a.dots diff --git a/Modules/RDTs/src/test/scala/test/rdts/baseproperties/LatticePropertyChecks.scala b/Modules/RDTs/src/test/scala/test/rdts/baseproperties/LatticePropertyChecks.scala index 6e6049340..a0cd06cc6 100644 --- a/Modules/RDTs/src/test/scala/test/rdts/baseproperties/LatticePropertyChecks.scala +++ b/Modules/RDTs/src/test/scala/test/rdts/baseproperties/LatticePropertyChecks.scala @@ -6,7 +6,7 @@ import org.scalacheck.Prop.* import org.scalacheck.{Arbitrary, Shrink} import rdts.base.{Bottom, BottomOpt, Lattice, Decompose} import rdts.datatypes.alternatives.{MultiValueRegister, ObserveRemoveSet} -import rdts.datatypes.contextual.{ReplicatedList} +import rdts.datatypes.contextual.ReplicatedList import rdts.datatypes.experiments.AutomergyOpGraphLWW.OpGraph import rdts.datatypes.experiments.CausalStore import rdts.datatypes.{GrowOnlyCounter, GrowOnlyList, GrowOnlyMap, LastWriterWins, PosNegCounter, TwoPhaseSet, contextual} @@ -108,7 +108,6 @@ abstract class LatticePropertyChecks[A]( } } - property("merge agrees with order"): forAll: (left: A, right: A) => val merged = left `merge` right diff --git a/Modules/RDTs/src/test/scala/test/rdts/protocols/MembershipTest.scala b/Modules/RDTs/src/test/scala/test/rdts/protocols/MembershipTest.scala index c9c0b9d70..d791e713b 100644 --- a/Modules/RDTs/src/test/scala/test/rdts/protocols/MembershipTest.scala +++ b/Modules/RDTs/src/test/scala/test/rdts/protocols/MembershipTest.scala @@ -16,7 +16,7 @@ class MembershipTest extends munit.FunSuite { val membership = Membership.init[Int, Paxos, Paxos](Set(id1, id2, id3).map(_.uid)) val delta = membership.upkeep()(using id1) println(delta.rounds.value.members) - val res = delta `merge` membership + val res = delta `merge` membership assertEquals(res, membership) } diff --git a/Modules/RDTs/src/test/scala/test/rdts/protocols/paper/PaperPaxosTest.scala b/Modules/RDTs/src/test/scala/test/rdts/protocols/paper/PaperPaxosTest.scala index 2d8697460..dc676281d 100644 --- a/Modules/RDTs/src/test/scala/test/rdts/protocols/paper/PaperPaxosTest.scala +++ b/Modules/RDTs/src/test/scala/test/rdts/protocols/paper/PaperPaxosTest.scala @@ -16,7 +16,7 @@ class PaperPaxosTest extends munit.FunSuite { val emptyPaxosObject: Paxos[Int] = Paxos() test("propose works as expected") { var testPaxosObject = emptyPaxosObject - val proposeValue = 1 + val proposeValue = 1 // replica 1 tries to write testPaxosObject = testPaxosObject.merge(testPaxosObject.propose(proposeValue)(using id1)) testPaxosObject = testPaxosObject.merge(testPaxosObject.upkeep()(using id1)).merge(testPaxosObject.upkeep()(using diff --git a/Modules/RDTs/src/test/scala/test/rdts/protocols/simplified/GenPaxosTest.scala b/Modules/RDTs/src/test/scala/test/rdts/protocols/simplified/GenPaxosTest.scala index 02732a389..42386166c 100644 --- a/Modules/RDTs/src/test/scala/test/rdts/protocols/simplified/GenPaxosTest.scala +++ b/Modules/RDTs/src/test/scala/test/rdts/protocols/simplified/GenPaxosTest.scala @@ -16,7 +16,7 @@ class GenPaxosTest extends munit.FunSuite { val emptyPaxosObject: GeneralizedPaxos[Int] = GeneralizedPaxos() test("propose works as expected") { var testPaxosObject = emptyPaxosObject - val proposeValue = 1 + val proposeValue = 1 // replica 1 tries to write testPaxosObject = testPaxosObject.merge(testPaxosObject.propose(proposeValue)(using id1)) testPaxosObject = testPaxosObject.merge(testPaxosObject.upkeep()(using id1)).merge(testPaxosObject.upkeep()(using diff --git a/Modules/Replication/jvm/src/main/scala/replication/dtn/dtn.scala b/Modules/Replication/jvm/src/main/scala/replication/dtn/dtn.scala index ee542fd2f..30a43c004 100644 --- a/Modules/Replication/jvm/src/main/scala/replication/dtn/dtn.scala +++ b/Modules/Replication/jvm/src/main/scala/replication/dtn/dtn.scala @@ -52,7 +52,12 @@ given JsonValueCodec[WsSendData] = JsonCodecMaker.make import replication.JsoniterCodecs.given given JsonValueCodec[PosNegCounter] = JsonCodecMaker.make -class Replica[S: {Lattice, JsonValueCodec}](val id: Uid, dtnNodeId: String, val service: String, @volatile var data: S) { +class Replica[S: { Lattice, JsonValueCodec }]( + val id: Uid, + dtnNodeId: String, + val service: String, + @volatile var data: S +) { val connections: AtomicReference[List[WebSocket]] = { val ar = new AtomicReference[List[WebSocket]] @@ -109,7 +114,7 @@ class Replica[S: {Lattice, JsonValueCodec}](val id: Uid, dtnNodeId: String, val } } -class ReplicaListener[S: {Lattice, JsonValueCodec}](replica: Replica[S]) extends Listener { +class ReplicaListener[S: { Lattice, JsonValueCodec }](replica: Replica[S]) extends Listener { val modeSwitched: Promise[true] = Promise[true] diff --git a/Modules/Replication/jvm/src/test/scala/deltaAntiEntropy/tests/GListTest.scala b/Modules/Replication/jvm/src/test/scala/deltaAntiEntropy/tests/GListTest.scala index d7d9872c3..6bb57b6ca 100644 --- a/Modules/Replication/jvm/src/test/scala/deltaAntiEntropy/tests/GListTest.scala +++ b/Modules/Replication/jvm/src/test/scala/deltaAntiEntropy/tests/GListTest.scala @@ -22,12 +22,12 @@ object GListGenerators { } } - given arbGList[E: {JsonValueCodec, HasDots}](using + given arbGList[E: { JsonValueCodec, HasDots }](using e: Arbitrary[E] ): Arbitrary[GrowOnlyList[E]] = Arbitrary(genGList) - def makeNet[E: {JsonValueCodec, HasDots}](v: GrowOnlyList[E]) = + def makeNet[E: { JsonValueCodec, HasDots }](v: GrowOnlyList[E]) = val network = new Network(0, 0, 0) val ae = new AntiEntropy[GrowOnlyList[E]]("a", network, mutable.Buffer()) val aec = AntiEntropyContainer[GrowOnlyList[E]](ae) diff --git a/Modules/Replication/jvm/src/test/scala/deltaAntiEntropy/tools/AntiEntropyContainer.scala b/Modules/Replication/jvm/src/test/scala/deltaAntiEntropy/tools/AntiEntropyContainer.scala index f35d98e31..02bfddcb6 100644 --- a/Modules/Replication/jvm/src/test/scala/deltaAntiEntropy/tools/AntiEntropyContainer.scala +++ b/Modules/Replication/jvm/src/test/scala/deltaAntiEntropy/tools/AntiEntropyContainer.scala @@ -24,10 +24,16 @@ class AntiEntropyContainer[State]( override def toString: String = s"AntiEntropy($replicaID, $state)" - inline def map(f: LocalUid ?=> State => State)(using Lattice[Dotted[State]], Decompose[Dotted[State]]): AntiEntropyContainer[State] = + inline def map(f: LocalUid ?=> State => State)(using + Lattice[Dotted[State]], + Decompose[Dotted[State]] + ): AntiEntropyContainer[State] = applyDelta(Named(replicaID.uid, Dotted(f(using replicaID)(state.data)))) - def applyDelta(delta: Named[Dotted[State]])(using Lattice[Dotted[State]], Decompose[Dotted[State]]): AntiEntropyContainer[State] = + def applyDelta(delta: Named[Dotted[State]])(using + Lattice[Dotted[State]], + Decompose[Dotted[State]] + ): AntiEntropyContainer[State] = delta match { case Named(origin, deltaCtx) => Lattice.diff(state, deltaCtx) match { @@ -39,7 +45,10 @@ class AntiEntropyContainer[State]( this } - def processReceivedDeltas()(using u: Lattice[Dotted[State]], d: Decompose[Dotted[State]]): AntiEntropyContainer[State] = + def processReceivedDeltas()(using + u: Lattice[Dotted[State]], + d: Decompose[Dotted[State]] + ): AntiEntropyContainer[State] = antiEntropy.getReceivedDeltas.foldLeft(this) { (crdt, delta) => crdt.applyDelta(delta) }