safecopy 0.10.3.1 → 0.10.4
raw patch · 4 files changed
+31/−21 lines, 4 files
Files
- CHANGELOG.md +9/−0
- safecopy.cabal +2/−2
- src/Data/SafeCopy/Instances.hs +10/−10
- src/Data/SafeCopy/SafeCopy.hs +10/−9
CHANGELOG.md view
@@ -1,3 +1,12 @@+0.10.4+======++Add a Typeable a superclass to SafeCopy. The previous version in effect+had the Typeable constraint anyway, this means less need to specify it.+The SafeCopy' type alias is now identical to SafeCopy. This should not+break any code except perhaps some GADT types that use "deriving Typeable".+These may need a standalone deriving instance.+ 0.10.0 ======
safecopy.cabal view
@@ -3,13 +3,13 @@ -- http://www.haskell.org/cabal/release/cabal-latest/doc/users-guide/authors.html#pkg-descr. -- The name of the package. Name: safecopy-Version: 0.10.3.1+Version: 0.10.4 Synopsis: Binary serialization with version control. Description: An extension to Data.Serialize with built-in version control. Homepage: https://github.com/acid-state/safecopy License: PublicDomain Author: David Himmelstrup, Felipe Lessa-Maintainer: Lemmih <lemmih@gmail.com>+Maintainer: Lemmih <lemmih@gmail.com>, David Fox <dsf@seereason.com> -- Copyright: Category: Data, Parsing Build-type: Simple
src/Data/SafeCopy/Instances.hs view
@@ -46,7 +46,7 @@ import qualified Data.Vector.Storable as VS import qualified Data.Vector.Unboxed as VU -instance SafeCopy' a => SafeCopy (Prim a) where+instance SafeCopy a => SafeCopy (Prim a) where kind = primitive getCopy = contain $ do e <- unsafeUnPack getCopy@@ -139,22 +139,22 @@ getCopy = contain $ liftM2 (,) safeGet safeGet putCopy (a,b) = contain $ safePut a >> safePut b errorTypeName = typeName2-instance (SafeCopy' a, SafeCopy' b, SafeCopy' c) => SafeCopy (a,b,c) where+instance (SafeCopy a, SafeCopy b, SafeCopy c) => SafeCopy (a,b,c) where getCopy = contain $ liftM3 (,,) safeGet safeGet safeGet putCopy (a,b,c) = contain $ safePut a >> safePut b >> safePut c-instance (SafeCopy' a, SafeCopy' b, SafeCopy' c, SafeCopy' d) => SafeCopy (a,b,c,d) where+instance (SafeCopy a, SafeCopy b, SafeCopy c, SafeCopy d) => SafeCopy (a,b,c,d) where getCopy = contain $ liftM4 (,,,) safeGet safeGet safeGet safeGet putCopy (a,b,c,d) = contain $ safePut a >> safePut b >> safePut c >> safePut d-instance (SafeCopy' a, SafeCopy' b, SafeCopy' c, SafeCopy' d, SafeCopy' e) =>+instance (SafeCopy a, SafeCopy b, SafeCopy c, SafeCopy d, SafeCopy e) => SafeCopy (a,b,c,d,e) where getCopy = contain $ liftM5 (,,,,) safeGet safeGet safeGet safeGet safeGet putCopy (a,b,c,d,e) = contain $ safePut a >> safePut b >> safePut c >> safePut d >> safePut e-instance (SafeCopy' a, SafeCopy' b, SafeCopy' c, SafeCopy' d, SafeCopy' e, SafeCopy' f) =>+instance (SafeCopy a, SafeCopy b, SafeCopy c, SafeCopy d, SafeCopy e, SafeCopy f) => SafeCopy (a,b,c,d,e,f) where getCopy = contain $ (,,,,,) <$> safeGet <*> safeGet <*> safeGet <*> safeGet <*> safeGet <*> safeGet putCopy (a,b,c,d,e,f) = contain $ safePut a >> safePut b >> safePut c >> safePut d >> safePut e >> safePut f-instance (SafeCopy' a, SafeCopy' b, SafeCopy' c, SafeCopy' d, SafeCopy' e, SafeCopy' f, SafeCopy' g) =>+instance (SafeCopy a, SafeCopy b, SafeCopy c, SafeCopy d, SafeCopy e, SafeCopy f, SafeCopy g) => SafeCopy (a,b,c,d,e,f,g) where getCopy = contain $ (,,,,,,) <$> safeGet <*> safeGet <*> safeGet <*> safeGet <*> safeGet <*> safeGet <*> safeGet@@ -449,18 +449,18 @@ putGenericVector v = contain $ do put (VG.length v) getSafePut >>= VG.forM_ v -instance SafeCopy' a => SafeCopy (V.Vector a) where+instance SafeCopy a => SafeCopy (V.Vector a) where getCopy = getGenericVector putCopy = putGenericVector -instance (SafeCopy' a, VP.Prim a) => SafeCopy (VP.Vector a) where+instance (SafeCopy a, VP.Prim a) => SafeCopy (VP.Vector a) where getCopy = getGenericVector putCopy = putGenericVector -instance (SafeCopy' a, VS.Storable a) => SafeCopy (VS.Vector a) where+instance (SafeCopy a, VS.Storable a) => SafeCopy (VS.Vector a) where getCopy = getGenericVector putCopy = putGenericVector -instance (SafeCopy' a, VU.Unbox a) => SafeCopy (VU.Vector a) where+instance (SafeCopy a, VU.Unbox a) => SafeCopy (VU.Vector a) where getCopy = getGenericVector putCopy = putGenericVector
src/Data/SafeCopy/SafeCopy.hs view
@@ -93,7 +93,7 @@ -- even though 'getCopy' and 'putCopy' can't be used directly. -- To serialize/parse a data type using 'SafeCopy', see 'safeGet' -- and 'safePut'.-class SafeCopy a where+class Typeable a => SafeCopy a where -- | The version of the type. -- -- Only used as a key so it must be unique (this is checked at run-time)@@ -162,7 +162,8 @@ {-# INLINE gputCopy #-} -- | A constraint that combines 'SafeCopy' and 'Typeable'.-type SafeCopy' a = (SafeCopy a, Typeable a)+type SafeCopy' a = SafeCopy a+{-# DEPRECATED SafeCopy' "SafeCopy' is now equivalent to SafeCopy " #-} -- To get the current safecopy behavior we need to emulate the -- template haskell code here - collect the (a -> Put) values for all@@ -191,7 +192,7 @@ gputFields p (M1 a) = gputFields p a {-# INLINE gputFields #-} -instance SafeCopy' a => GPutFields (K1 R a) p where+instance SafeCopy a => GPutFields (K1 R a) p where gputFields _ (K1 a) = do getSafePutGeneric putCopy a {-# INLINE gputFields #-}@@ -265,7 +266,7 @@ return (M1 <$> getter) {-# INLINE ggetFields #-} -instance SafeCopy' a => GGetFields (K1 R a) p where+instance SafeCopy a => GGetFields (K1 R a) p where ggetFields _ = do getter <- getSafeGetGeneric return (K1 <$> getter)@@ -289,7 +290,7 @@ -- read a version or not. It constructs a Map TypeRep Int32 and reads -- when the new TypeRep is not in the map. getSafeGetGeneric ::- forall a. SafeCopy' a+ forall a. SafeCopy a => StateT (Map TypeRep Int32) Get (Get a) getSafeGetGeneric = checkConsistency proxy $@@ -308,7 +309,7 @@ -- type prevents doing this because each fields may have a different -- type. Maybe you can show me a better way getSafePutGeneric ::- forall a. SafeCopy' a+ forall a. SafeCopy a => (a -> Contained Put) -> a -> RWST () [Put] (Set TypeRep) PutM ()@@ -324,7 +325,7 @@ tell [unsafeUnPack (cput $ asProxyType a proxy)] where proxy = Proxy :: Proxy a -type GSafeCopy a = (SafeCopy' a, Generic a, GPutCopy (Rep a) DatatypeInfo, Constructors a)+type GSafeCopy a = (SafeCopy a, Generic a, GPutCopy (Rep a) DatatypeInfo, Constructors a) -- | Generic only version of safePut. Instead of calling 'putCopy' it -- calls 'putCopyDefault', a copy of the implementation of the@@ -555,14 +556,14 @@ Consistent -> ks {-# INLINE computeConsistency #-}-computeConsistency :: SafeCopy a => Proxy a -> Consistency a+computeConsistency :: forall a. SafeCopy a => Proxy a -> Consistency a computeConsistency proxy -- Match a few common cases before falling through to the general case. -- This allows use to generate nearly all consistencies at compile-time. | isObviouslyConsistent (kindFromProxy proxy) = Consistent | versions /= nub versions- = NotConsistent $ "Duplicate version tags: " ++ show versions+ = NotConsistent $ "Duplicate version tags for " <> show (typeRep (Proxy @a)) <> ": " ++ show versions | not (validChain proxy) = NotConsistent "Primitive types cannot be extended as they have no version tag." | otherwise