Skip to content

Commit 7a5848b

Browse files
authored
Merge pull request #616 from IntersectMBO/wenkokke/remove-deserialiseValueN
fix: remove unused `deserialiseValueN`
2 parents b0e047c + bf5a33b commit 7a5848b

File tree

5 files changed

+2
-55
lines changed

5 files changed

+2
-55
lines changed

bench/micro/Bench/Database/LSMTree/Normal.hs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ instance NFData V1 where
5252
instance SerialiseValue V1 where
5353
serialiseValue (V1 x s) = serialiseValue x <> serialiseValue s
5454
deserialiseValue rb = V1 (deserialiseValue $ RB.take 8 rb) (deserialiseValue $ RB.drop 8 rb)
55-
deserialiseValueN _ = error "deserialiseValueN: unused"
5655

5756
newtype B1 = B1 Void
5857
deriving newtype (Show, Eq, Ord, NFData, SerialiseValue)

src-extras/Database/LSMTree/Extras/Orphans.hs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ instance SerialiseValue Word256 where
5858
deserialiseValue (RawBytes (VP.Vector off len ba)) =
5959
requireBytesExactly "Word256" 32 len $
6060
indexWord8ArrayAsWord256 ba off
61-
deserialiseValueN = deserialiseValue . mconcat -- TODO: optimise
6261

6362
instance Arbitrary Word256 where
6463
arbitrary = Word256 <$> arbitrary <*> arbitrary <*> arbitrary <*> arbitrary
@@ -116,7 +115,6 @@ instance SerialiseValue Word128 where
116115
deserialiseValue (RawBytes (VP.Vector off len ba)) =
117116
requireBytesExactly "Word128" 16 len $
118117
indexWord8ArrayAsWord128 ba off
119-
deserialiseValueN = deserialiseValue . mconcat -- TODO: optimise
120118

121119
instance Arbitrary Word128 where
122120
arbitrary = Word128 <$> arbitrary <*> arbitrary
@@ -162,7 +160,6 @@ instance SerialiseKey RawBytes where
162160
instance SerialiseValue RawBytes where
163161
serialiseValue = id
164162
deserialiseValue = id
165-
deserialiseValueN = mconcat
166163

167164
{-------------------------------------------------------------------------------
168165
SerialisedKey/Value/Blob

src-extras/Database/LSMTree/Extras/UTxO.hs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,6 @@ instance SerialiseValue UTxOValue where
114114
(indexWord8ArrayAsWord128 ba (off + 32))
115115
(indexWord8ArrayAsWord64 ba (off + 48))
116116
(indexWord8ArrayAsWord32 ba (off + 56))
117-
deserialiseValueN = deserialiseValue . mconcat -- TODO: optimise
118117

119118
instance Arbitrary UTxOValue where
120119
arbitrary = UTxOValue <$> arbitrary <*> arbitrary <*> arbitrary <*> arbitrary
@@ -150,4 +149,3 @@ newtype UTxOBlob = UTxOBlob BS.ByteString
150149
instance SerialiseValue UTxOBlob where
151150
serialiseValue (UTxOBlob bs) = Class.serialiseValue bs
152151
deserialiseValue = error "deserialiseValue: UTxOBlob"
153-
deserialiseValueN = error "deserialiseValueN: UTxOBlob"

src/Database/LSMTree/Internal/Serialise/Class.hs

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ module Database.LSMTree.Internal.Serialise.Class (
88
, SerialiseValue (..)
99
, serialiseValueIdentity
1010
, serialiseValueIdentityUpToSlicing
11-
, serialiseValueConcatDistributes
1211
, RawBytes (..)
1312
, packSlice
1413
-- * Errors
@@ -21,7 +20,6 @@ import qualified Data.ByteString.Lazy as LBS
2120
import qualified Data.ByteString.Short.Internal as SBS
2221
import Data.Monoid (Sum (..))
2322
import qualified Data.Primitive as P
24-
import Data.Proxy (Proxy)
2523
import qualified Data.Vector.Primitive as VP
2624
import Data.Void (Void, absurd)
2725
import Data.Word
@@ -80,14 +78,9 @@ serialiseKeyMinimalSize x = RB.size (serialiseKey x) >= 8
8078
--
8179
-- [Identity] @'deserialiseValue' ('serialiseValue' x) == x@
8280
-- [Identity up to slicing] @'deserialiseValue' ('packSlice' prefix ('serialiseValue' x) suffix) == x@
83-
-- [Concat distributes] @'deserialiseValueN' xs == 'deserialiseValue' ('mconcat' xs)@
8481
class SerialiseValue v where
8582
serialiseValue :: v -> RawBytes
8683
deserialiseValue :: RawBytes -> v
87-
-- | Deserialisation when bytes are split into multiple chunks.
88-
--
89-
-- TODO: Unused so far, we might not need it.
90-
deserialiseValueN :: [RawBytes] -> v
9184

9285

9386
-- | An instance for 'Sum' which is transparent to the serialisation of @a@.
@@ -99,8 +92,6 @@ instance SerialiseValue a => SerialiseValue (Sum a) where
9992

10093
deserialiseValue = Sum . deserialiseValue
10194

102-
deserialiseValueN = Sum . deserialiseValueN
103-
10495
-- | Test the __Identity__ law for the 'SerialiseValue' class
10596
serialiseValueIdentity :: (Eq v, SerialiseValue v) => v -> Bool
10697
serialiseValueIdentity x = deserialiseValue (serialiseValue x) == x
@@ -112,10 +103,6 @@ serialiseValueIdentityUpToSlicing ::
112103
serialiseValueIdentityUpToSlicing prefix x suffix =
113104
deserialiseValue (packSlice prefix (serialiseValue x) suffix) == x
114105

115-
-- | Test the __Concat distributes__ law for the 'SerialiseValue' class
116-
serialiseValueConcatDistributes :: forall v. (Eq v, SerialiseValue v) => Proxy v -> [RawBytes] -> Bool
117-
serialiseValueConcatDistributes _ xs = deserialiseValueN @v xs == deserialiseValue (mconcat xs)
118-
119106
{-------------------------------------------------------------------------------
120107
RawBytes
121108
-------------------------------------------------------------------------------}
@@ -159,7 +146,6 @@ instance SerialiseValue Word64 where
159146

160147
deserialiseValue (RawBytes (VP.Vector off len ba)) =
161148
requireBytesExactly "Word64" 8 len $ indexWord8ArrayAsWord64 ba off
162-
deserialiseValueN = deserialiseValue . mconcat
163149

164150
{-------------------------------------------------------------------------------
165151
ByteString
@@ -178,14 +164,12 @@ instance SerialiseKey BS.ByteString where
178164
-- | Placeholder instance, not optimised
179165
instance SerialiseValue LBS.ByteString where
180166
serialiseValue = serialiseValue . LBS.toStrict
181-
deserialiseValue = deserialiseValueN . pure
182-
deserialiseValueN = B.toLazyByteString . foldMap RB.builder
167+
deserialiseValue = B.toLazyByteString . RB.builder
183168

184169
-- | Placeholder instance, not optimised
185170
instance SerialiseValue BS.ByteString where
186171
serialiseValue = RB.fromShortByteString . SBS.toShort
187-
deserialiseValue = deserialiseValueN . pure
188-
deserialiseValueN = LBS.toStrict . deserialiseValueN
172+
deserialiseValue = LBS.toStrict . deserialiseValue
189173

190174
{-------------------------------------------------------------------------------
191175
ShortByteString
@@ -198,7 +182,6 @@ instance SerialiseKey SBS.ShortByteString where
198182
instance SerialiseValue SBS.ShortByteString where
199183
serialiseValue = RB.fromShortByteString
200184
deserialiseValue = byteArrayToSBS . RB.force
201-
deserialiseValueN = byteArrayToSBS . foldMap RB.force
202185

203186
{-------------------------------------------------------------------------------
204187
ByteArray
@@ -210,7 +193,6 @@ instance SerialiseValue SBS.ShortByteString where
210193
instance SerialiseValue P.ByteArray where
211194
serialiseValue ba = RB.fromByteArray 0 (P.sizeofByteArray ba) ba
212195
deserialiseValue = RB.force
213-
deserialiseValueN = foldMap RB.force
214196

215197
{-------------------------------------------------------------------------------
216198
Void
@@ -222,4 +204,3 @@ Void
222204
instance SerialiseValue Void where
223205
serialiseValue = absurd
224206
deserialiseValue = error "panic"
225-
deserialiseValueN = error "panic"

test/Test/Database/LSMTree/Internal/Serialise/Class.hs

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,10 @@ import Data.ByteString (ByteString)
88
import Data.ByteString.Lazy (LazyByteString)
99
import Data.ByteString.Short (ShortByteString)
1010
import Data.Primitive (ByteArray)
11-
import Data.Proxy (Proxy (Proxy))
1211
import Data.WideWord (Word128, Word256)
1312
import Data.Word
1413
import Database.LSMTree.Extras.Generators ()
1514
import Database.LSMTree.Extras.UTxO (UTxOKey, UTxOValue)
16-
import qualified Database.LSMTree.Internal.RawBytes as RB
1715
import Database.LSMTree.Internal.Serialise.Class
1816
import Test.Tasty
1917
import Test.Tasty.QuickCheck
@@ -51,8 +49,6 @@ valueProperties =
5149
prop_roundtripSerialiseValue @a
5250
, testProperty "prop_roundtripSerialiseValueUpToSlicing" $
5351
prop_roundtripSerialiseValueUpToSlicing @a
54-
, testProperty "prop_concatDistributesSerialiseValue" $
55-
prop_concatDistributesSerialiseValue @a
5652
]
5753

5854
prop_roundtripSerialiseKey :: forall k. (Eq k, Show k, SerialiseKey k) => k -> Property
@@ -99,27 +95,3 @@ prop_roundtripSerialiseValueUpToSlicing prefix x suffix =
9995
v = serialiseValue x
10096
v' = packSlice prefix v suffix
10197
x' = deserialiseValue v'
102-
103-
prop_concatDistributesSerialiseValue :: forall v. (Ord v, Show v, SerialiseValue v) => v -> Property
104-
prop_concatDistributesSerialiseValue v =
105-
forAllShrink (genChunks bytes) shrinkChunks $ (. map (RB.pack)) $ \chs ->
106-
counterexample ("from chunks: " <> show (deserialiseValueN @v chs)) $
107-
counterexample ("from whole: " <> show (deserialiseValue @v (mconcat chs))) $
108-
serialiseValueConcatDistributes (Proxy @v) chs
109-
where
110-
bytes = RB.unpack (serialiseValue v)
111-
112-
-- | Randomly splits the input list into non-empty chunks.
113-
genChunks :: [a] -> Gen [[a]]
114-
genChunks [] = pure []
115-
genChunks xs = do
116-
n <- chooseInt (1, length xs)
117-
let (pre, post) = splitAt n xs
118-
(pre :) <$> genChunks post
119-
120-
-- | Shrinks by appending chunks where possible
121-
shrinkChunks :: [[a]] -> [[[a]]]
122-
shrinkChunks (x : y : ys) =
123-
((x <> y) : ys)
124-
: map (x :) (shrinkChunks (y : ys))
125-
shrinkChunks _ = []

0 commit comments

Comments
 (0)