From 72c53bbc30c60f26b1830651e89976db16de516b Mon Sep 17 00:00:00 2001 From: Kory Date: Sun, 6 Mar 2022 01:04:12 +0000 Subject: [PATCH 1/2] refactor: do not constrain PacketIdBindings with ContainsDistinctT See https://github.com/kory33/s2mc-test/issues/40#issuecomment-1059864681 for why we are doing this. --- .../core/connection/protocol/PacketIdBindings.scala | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/protocol-core/src/main/scala/io/github/kory33/s2mctest/core/connection/protocol/PacketIdBindings.scala b/protocol-core/src/main/scala/io/github/kory33/s2mctest/core/connection/protocol/PacketIdBindings.scala index 70d18ff3..c1dd0ca0 100644 --- a/protocol-core/src/main/scala/io/github/kory33/s2mctest/core/connection/protocol/PacketIdBindings.scala +++ b/protocol-core/src/main/scala/io/github/kory33/s2mctest/core/connection/protocol/PacketIdBindings.scala @@ -14,12 +14,12 @@ type CodecBinding[A] = (PacketId, ByteCodec[A]) /** * An object that associates packet IDs with corresponding datatypes' codec. * - * [[PacketTup]] is a tuple of packets with no duplicates, used in associating codecs. It is - * also required that [[bindings]] should not contain two entries with the same packet ID. + * [[PacketTup]] is a tuple of packets with no duplicates, and is used in associating codecs. It + * is also required that [[bindings]] should not contain two entries with the same packet ID. */ class PacketIdBindings[PacketTup <: Tuple]( bindings: Tuple.Map[PacketTup, CodecBinding] -)(using Require[ContainsDistinctT[PacketTup]]) { +) { require( { @@ -65,12 +65,8 @@ class PacketIdBindings[PacketTup <: Tuple]( } object PacketIdBindings { - def apply[BindingsTup <: Tuple]( - bindingsTup: BindingsTup - )( + def apply[BindingsTup <: Tuple](bindingsTup: BindingsTup)( using ev: Tuple.IsMappedBy[CodecBinding][BindingsTup] - )( - using Require[ContainsDistinctT[Tuple.InverseMap[BindingsTup, CodecBinding]]] ): PacketIdBindings[Tuple.InverseMap[BindingsTup, CodecBinding]] = { new PacketIdBindings[InverseMap[BindingsTup, CodecBinding]]( ev(bindingsTup) From 7aad06a4a28a41d2b38ecf0762ab5b84a0505ca0 Mon Sep 17 00:00:00 2001 From: Kory Date: Sun, 6 Mar 2022 01:43:34 +0000 Subject: [PATCH 2/2] chore: remove unused types --- .../core/generic/compiletime/Tuple.scala | 19 ------------------- .../core/generic/compiletime/TupleSpec.scala | 14 -------------- 2 files changed, 33 deletions(-) diff --git a/protocol-core/src/main/scala/io/github/kory33/s2mctest/core/generic/compiletime/Tuple.scala b/protocol-core/src/main/scala/io/github/kory33/s2mctest/core/generic/compiletime/Tuple.scala index 7d0e9833..f9a91f73 100644 --- a/protocol-core/src/main/scala/io/github/kory33/s2mctest/core/generic/compiletime/Tuple.scala +++ b/protocol-core/src/main/scala/io/github/kory33/s2mctest/core/generic/compiletime/Tuple.scala @@ -17,18 +17,6 @@ type IncludedInLockedT[T <: Tuple, A] <: Boolean = case ? *: tail => IncludedInLockedT[tail, A] } -/** - * INTERNAL. A type-level boolean indicating if T, mapped with [[Lock]], contains no duplicate - * types. - * - * Takes O(|T|^2) to compute. - */ -type ContainsDistinctLockedT[T <: Tuple] <: Boolean = - T match { - case Lock[head] *: tail => ![IncludedInLockedT[tail, head]] && ContainsDistinctLockedT[tail] - case EmptyTuple => true - } - /** * INTERNAL. Lock tuple [[T]] using [[Lock]] constructor. */ @@ -55,13 +43,6 @@ type Includes[A] = [T <: Tuple] =>> Require[IncludedInT[T, A]] */ type IncludedBy[T <: Tuple] = [A] =>> Require[IncludedInT[T, A]] -/** - * A type-level boolean indicating if [[T]] only contains distinct types. - * - * Takes O(|T|^2) to compute. - */ -type ContainsDistinctT[T <: Tuple] = ContainsDistinctLockedT[LockTuple[T]] - /** * INTERNAL. The index of [[A]] in a tuple [[T]] mapped with [[Lock]]. * diff --git a/protocol-core/src/test/scala/io/github/kory33/s2mctest/core/generic/compiletime/TupleSpec.scala b/protocol-core/src/test/scala/io/github/kory33/s2mctest/core/generic/compiletime/TupleSpec.scala index 89d51dd8..0ca0b553 100644 --- a/protocol-core/src/test/scala/io/github/kory33/s2mctest/core/generic/compiletime/TupleSpec.scala +++ b/protocol-core/src/test/scala/io/github/kory33/s2mctest/core/generic/compiletime/TupleSpec.scala @@ -16,20 +16,6 @@ class TupleSpec extends AnyFlatSpec with should.Matchers { summon[IncludedInT[(Int, String, Double), Float] =:= false] } - "ContainsDistinctT" should "tell whether a tuple contains distinct types" in { - summon[ContainsDistinctT[EmptyTuple] =:= true] - summon[ContainsDistinctT[Int *: EmptyTuple] =:= true] - summon[ContainsDistinctT[(Int, String, Double)] =:= true] - summon[ContainsDistinctT[(Int, 1, 2)] =:= true] - summon[ContainsDistinctT[(Int, Int | String, String)] =:= true] - - summon[ContainsDistinctT[(Int, Int)] =:= false] - summon[ContainsDistinctT[(Int, String, Int)] =:= false] - summon[ContainsDistinctT[(String, Int, Int)] =:= false] - summon[ContainsDistinctT[(Int | String, String, Int, Int | String)] =:= false] - summon[ContainsDistinctT[(true, 1, 2, 3, 1, false)] =:= false] - } - "IndexOfT" should "extract the index of a specific type from a tuple" in { summon[IndexOfT[Int, (String, Int)] =:= 1] summon[IndexOfT[42, (String, Int, 42)] =:= 2]