safecopy 0.9.0.1 → 0.9.1
raw patch · 6 files changed
+68/−41 lines, 6 filesdep +QuickCheckdep ~template-haskelldep ~time
Dependencies added: QuickCheck
Dependency ranges changed: template-haskell, time
Files
- CHANGELOG.md +8/−0
- safecopy.cabal +6/−30
- src/Data/SafeCopy/Derive.hs +43/−11
- src/Data/SafeCopy/Instances.hs +2/−0
- src/Data/SafeCopy/Internal.hs +7/−0
- test/instances.hs +2/−0
CHANGELOG.md view
@@ -1,3 +1,11 @@+0.9.1+=====++ - fixed tests to work with QuickCheck-2.8.2+ - add SafeCopy instance for Word+ - updates for template-haskell 2.11+ - export some internal TH derivation helpers+ 0.9.0 =====
safecopy.cabal view
@@ -3,44 +3,19 @@ -- http://www.haskell.org/cabal/release/cabal-latest/doc/users-guide/authors.html#pkg-descr. -- The name of the package. Name: safecopy---- The package version. See the Haskell package versioning policy--- (http://www.haskell.org/haskellwiki/Package_versioning_policy) for--- standards guiding when and how versions should be incremented.-Version: 0.9.0.1---- A short (one-line) description of the package.+Version: 0.9.1 Synopsis: Binary serialization with version control.---- A longer description of the package. Description: An extension to Data.Serialize with built-in version control.---- URL for the project homepage or repository. Homepage: http://acid-state.seize.it/safecopy---- The license under which the package is released. License: PublicDomain---- The package author(s). Author: David Himmelstrup, Felipe Lessa---- An email address to which users can send suggestions, bug reports,--- and patches. Maintainer: Lemmih <lemmih@gmail.com>---- A copyright notice. -- Copyright:- Category: Data, Parsing- Build-type: Simple---- Extra files to be distributed with the package, such as examples or--- a README. Extra-source-files: CHANGELOG.md---- Constraint on the version of Cabal needed to build this package. Cabal-version: >=1.8+tested-with: GHC == 7.6.3, GHC == 7.8.4, GHC == 7.10.2, GHC==8.0.1 Source-repository head type: git@@ -50,6 +25,7 @@ Library -- Modules exported by the library. Exposed-modules: Data.SafeCopy+ Data.SafeCopy.Internal Hs-Source-Dirs: src/ @@ -60,9 +36,9 @@ bytestring < 0.11, containers >= 0.3 && < 0.6, old-time < 1.2,- template-haskell < 2.11,+ template-haskell < 2.12, text < 1.3,- time < 1.6,+ time < 1.7, vector >= 0.10 && < 0.12 -- Modules not exported by this package.@@ -87,4 +63,4 @@ GHC-Options: -Wall -threaded -rtsopts -with-rtsopts=-N Build-depends: base, cereal, template-haskell, safecopy, containers, time, array, vector, lens >= 4.7 && < 5.0,- lens-action, tasty, tasty-quickcheck, quickcheck-instances+ lens-action, tasty, tasty-quickcheck, quickcheck-instances, QuickCheck
src/Data/SafeCopy/Derive.hs view
@@ -5,15 +5,7 @@ #define MIN_VERSION_template_haskell(x,y,z) 1 #endif -module Data.SafeCopy.Derive- (- deriveSafeCopy- , deriveSafeCopyIndexedType- , deriveSafeCopySimple- , deriveSafeCopySimpleIndexedType- , deriveSafeCopyHappstackData- , deriveSafeCopyHappstackDataIndexedType- ) where+module Data.SafeCopy.Derive where import Data.Serialize (getWord8, putWord8, label) import Data.SafeCopy.SafeCopy@@ -243,19 +235,42 @@ internalDeriveSafeCopy :: DeriveType -> Version a -> Name -> Name -> Q [Dec] internalDeriveSafeCopy deriveType versionId kindName tyName = do info <- reify tyName+ internalDeriveSafeCopy' deriveType versionId kindName tyName info++internalDeriveSafeCopy' :: DeriveType -> Version a -> Name -> Name -> Info -> Q [Dec]+internalDeriveSafeCopy' deriveType versionId kindName tyName info = do case info of+#if MIN_VERSION_template_haskell(2,11,0)+ TyConI (DataD context _name tyvars _kind cons _derivs)+#else TyConI (DataD context _name tyvars cons _derivs)+#endif | length cons > 255 -> fail $ "Can't derive SafeCopy instance for: " ++ show tyName ++ ". The datatype must have less than 256 constructors." | otherwise -> worker context tyvars (zip [0..] cons)++#if MIN_VERSION_template_haskell(2,11,0)+ TyConI (NewtypeD context _name tyvars _kind con _derivs) ->+#else TyConI (NewtypeD context _name tyvars con _derivs) ->+#endif worker context tyvars [(0, con)]+ FamilyI _ insts -> do decs <- forM insts $ \inst -> case inst of+#if MIN_VERSION_template_haskell(2,11,0)+ DataInstD context _name ty _kind cons _derivs ->+#else DataInstD context _name ty cons _derivs ->+#endif worker' (foldl appT (conT tyName) (map return ty)) context [] (zip [0..] cons)++#if MIN_VERSION_template_haskell(2,11,0)+ NewtypeInstD context _name ty _kind con _derivs ->+#else NewtypeInstD context _name ty con _derivs ->+#endif worker' (foldl appT (conT tyName) (map return ty)) context [] [(0, con)] _ -> fail $ "Can't derive SafeCopy instance for: " ++ show (tyName, inst) return $ concat decs@@ -280,18 +295,31 @@ internalDeriveSafeCopyIndexedType :: DeriveType -> Version a -> Name -> Name -> [Name] -> Q [Dec] internalDeriveSafeCopyIndexedType deriveType versionId kindName tyName tyIndex' = do- tyIndex <- mapM conT tyIndex' info <- reify tyName+ internalDeriveSafeCopyIndexedType' deriveType versionId kindName tyName tyIndex' info++internalDeriveSafeCopyIndexedType' :: DeriveType -> Version a -> Name -> Name -> [Name] -> Info -> Q [Dec]+internalDeriveSafeCopyIndexedType' deriveType versionId kindName tyName tyIndex' info = do+ tyIndex <- mapM conT tyIndex' case info of FamilyI _ insts -> do decs <- forM insts $ \inst -> case inst of+#if MIN_VERSION_template_haskell(2,11,0)+ DataInstD context _name ty _kind cons _derivs+#else DataInstD context _name ty cons _derivs+#endif | ty == tyIndex -> worker' (foldl appT (conT tyName) (map return ty)) context [] (zip [0..] cons) | otherwise -> return []++#if MIN_VERSION_template_haskell(2,11,0)+ NewtypeInstD context _name ty _kind con _derivs+#else NewtypeInstD context _name ty con _derivs+#endif | ty == tyIndex -> worker' (foldl appT (conT tyName) (map return ty)) context [] [(0, con)] | otherwise ->@@ -404,7 +432,11 @@ conSize (NormalC _name args) = length args conSize (RecC _name recs) = length recs conSize InfixC{} = 2-conSize ForallC{} = error "Found complex constructor. Cannot derive SafeCopy for it."+conSize ForallC{} = error "Found constructor with existentially quantified binder. Cannot derive SafeCopy for it."+#if MIN_VERSION_template_haskell(2,11,0)+conSize GadtC{} = error "Found GADT constructor. Cannot derive SafeCopy for it."+conSize RecGadtC{} = error "Found GADT constructor. Cannot derive SafeCopy for it."+#endif conName :: Con -> Name conName (NormalC name _args) = name
src/Data/SafeCopy/Instances.hs view
@@ -213,6 +213,8 @@ getCopy = contain get; putCopy = contain . put; errorTypeName = typeName instance SafeCopy Char where getCopy = contain get; putCopy = contain . put; errorTypeName = typeName+instance SafeCopy Word where+ getCopy = contain get; putCopy = contain . put; errorTypeName = typeName instance SafeCopy Word8 where getCopy = contain get; putCopy = contain . put; errorTypeName = typeName instance SafeCopy Word16 where
+ src/Data/SafeCopy/Internal.hs view
@@ -0,0 +1,7 @@+module Data.SafeCopy.Internal (+ module Data.SafeCopy.SafeCopy+ , module Data.SafeCopy.Derive+ ) where++import Data.SafeCopy.SafeCopy+import Data.SafeCopy.Derive
test/instances.hs view
@@ -42,6 +42,7 @@ arbitrary = (,,,,,,) <$> arbitrary <*> arbitrary <*> arbitrary <*> arbitrary <*> arbitrary <*> arbitrary <*> arbitrary +#if ! MIN_VERSION_QuickCheck(2,8,2) instance (Arbitrary a) => Arbitrary (V.Vector a) where arbitrary = V.fromList <$> arbitrary @@ -53,6 +54,7 @@ instance (Arbitrary a, VU.Unbox a) => Arbitrary (VU.Vector a) where arbitrary = VU.fromList <$> arbitrary+#endif deriving instance (Arbitrary a) => Arbitrary (Prim a) deriving instance (Eq a) => Eq (Prim a)