Fix ghc-7.4 build

This commit is contained in:
Daniel Gröber 2015-11-26 15:23:32 +01:00
parent 6f0b8b00d1
commit 81a2d29cdc
3 changed files with 46 additions and 46 deletions

View File

@ -18,43 +18,43 @@
module Data.Binary.Generic where module Data.Binary.Generic where
import Control.Applicative import Control.Applicative
import Data.Binary hiding (GBinary(..)) import Data.Binary
import Data.Bits import Data.Bits
import GHC.Generics import GHC.Generics
import Prelude import Prelude
class GBinary f where class GGBinary f where
gput :: f t -> Put ggput :: f t -> Put
gget :: Get (f t) ggget :: Get (f t)
-- Type without constructors -- Type without constructors
instance GBinary V1 where instance GGBinary V1 where
gput _ = return () ggput _ = return ()
gget = return undefined ggget = return undefined
-- Constructor without arguments -- Constructor without arguments
instance GBinary U1 where instance GGBinary U1 where
gput U1 = return () ggput U1 = return ()
gget = return U1 ggget = return U1
-- Product: constructor with parameters -- Product: constructor with parameters
instance (GBinary a, GBinary b) => GBinary (a :*: b) where instance (GGBinary a, GGBinary b) => GGBinary (a :*: b) where
gput (x :*: y) = gput x >> gput y ggput (x :*: y) = ggput x >> ggput y
gget = (:*:) <$> gget <*> gget ggget = (:*:) <$> ggget <*> ggget
-- Metadata (constructor name, etc) -- Metadata (constructor name, etc)
instance GBinary a => GBinary (M1 i c a) where instance GGBinary a => GGBinary (M1 i c a) where
gput = gput . unM1 ggput = ggput . unM1
gget = M1 <$> gget ggget = M1 <$> ggget
-- Constants, additional parameters, and rank-1 recursion -- Constants, additional parameters, and rank-1 recursion
instance Binary a => GBinary (K1 i a) where instance Binary a => GGBinary (K1 i a) where
gput = put . unK1 ggput = put . unK1
gget = K1 <$> get ggget = K1 <$> get
-- Borrowed from the cereal package. -- Borrowed from the cereal package.
-- The following GBinary instance for sums has support for serializing -- The following GGBinary instance for sums has support for serializing
-- types with up to 2^64-1 constructors. It will use the minimal -- types with up to 2^64-1 constructors. It will use the minimal
-- number of bytes needed to encode the constructor. For example when -- number of bytes needed to encode the constructor. For example when
-- a type has 2^8 constructors or less it will use a single byte to -- a type has 2^8 constructors or less it will use a single byte to
@ -66,19 +66,19 @@ instance Binary a => GBinary (K1 i a) where
#define GETSUM(WORD) GUARD(WORD) = (get :: Get WORD) >>= checkGetSum (fromIntegral size) #define GETSUM(WORD) GUARD(WORD) = (get :: Get WORD) >>= checkGetSum (fromIntegral size)
instance ( GSum a, GSum b instance ( GSum a, GSum b
, GBinary a, GBinary b , GGBinary a, GGBinary b
, SumSize a, SumSize b) => GBinary (a :+: b) where , SumSize a, SumSize b) => GGBinary (a :+: b) where
gput | PUTSUM(Word8) | PUTSUM(Word16) | PUTSUM(Word32) | PUTSUM(Word64) ggput | PUTSUM(Word8) | PUTSUM(Word16) | PUTSUM(Word32) | PUTSUM(Word64)
| otherwise = sizeError "encode" size | otherwise = sizeError "encode" size
where where
size = unTagged (sumSize :: Tagged (a :+: b) Word64) size = unTagged (sumSize :: Tagged (a :+: b) Word64)
{-# INLINE gput #-} {-# INLINE ggput #-}
gget | GETSUM(Word8) | GETSUM(Word16) | GETSUM(Word32) | GETSUM(Word64) ggget | GETSUM(Word8) | GETSUM(Word16) | GETSUM(Word32) | GETSUM(Word64)
| otherwise = sizeError "decode" size | otherwise = sizeError "decode" size
where where
size = unTagged (sumSize :: Tagged (a :+: b) Word64) size = unTagged (sumSize :: Tagged (a :+: b) Word64)
{-# INLINE gget #-} {-# INLINE ggget #-}
sizeError :: Show size => String -> size -> error sizeError :: Show size => String -> size -> error
sizeError s size = sizeError s size =
@ -96,7 +96,7 @@ class GSum f where
getSum :: (Ord word, Num word, Bits word) => word -> word -> Get (f a) getSum :: (Ord word, Num word, Bits word) => word -> word -> Get (f a)
putSum :: (Num w, Bits w, Binary w) => w -> w -> f a -> Put putSum :: (Num w, Bits w, Binary w) => w -> w -> f a -> Put
instance (GSum a, GSum b, GBinary a, GBinary b) => GSum (a :+: b) where instance (GSum a, GSum b, GGBinary a, GGBinary b) => GSum (a :+: b) where
getSum !code !size | code < sizeL = L1 <$> getSum code sizeL getSum !code !size | code < sizeL = L1 <$> getSum code sizeL
| otherwise = R1 <$> getSum (code - sizeL) sizeR | otherwise = R1 <$> getSum (code - sizeL) sizeR
where where
@ -112,11 +112,11 @@ instance (GSum a, GSum b, GBinary a, GBinary b) => GSum (a :+: b) where
sizeR = size - sizeL sizeR = size - sizeL
{-# INLINE putSum #-} {-# INLINE putSum #-}
instance GBinary a => GSum (C1 c a) where instance GGBinary a => GSum (C1 c a) where
getSum _ _ = gget getSum _ _ = ggget
{-# INLINE getSum #-} {-# INLINE getSum #-}
putSum !code _ x = put code *> gput x putSum !code _ x = put code *> ggput x
{-# INLINE putSum #-} {-# INLINE putSum #-}
------------------------------------------------------------------------ ------------------------------------------------------------------------

View File

@ -15,7 +15,7 @@ import Control.Exception (Exception)
import Control.Applicative import Control.Applicative
import Control.Concurrent import Control.Concurrent
import Control.Monad import Control.Monad
import Data.Binary hiding (gput, gget) import Data.Binary
import Data.Binary.Generic import Data.Binary.Generic
import Data.Map (Map) import Data.Map (Map)
import qualified Data.Map as Map import qualified Data.Map as Map
@ -231,8 +231,8 @@ data GhcPkgDb = GlobalDb
deriving (Eq, Show, Generic) deriving (Eq, Show, Generic)
instance Binary GhcPkgDb where instance Binary GhcPkgDb where
put = gput . from put = ggput . from
get = to `fmap` gget get = to `fmap` ggget
-- | A single GHC command line option. -- | A single GHC command line option.
type GHCOption = String type GHCOption = String
@ -304,14 +304,14 @@ data GmComponent (t :: GmComponentType) eps = GmComponent {
} deriving (Eq, Ord, Show, Read, Generic, Functor) } deriving (Eq, Ord, Show, Read, Generic, Functor)
instance Binary eps => Binary (GmComponent t eps) where instance Binary eps => Binary (GmComponent t eps) where
put = gput . from put = ggput . from
get = to `fmap` gget get = to `fmap` ggget
data ModulePath = ModulePath { mpModule :: ModuleName, mpPath :: FilePath } data ModulePath = ModulePath { mpModule :: ModuleName, mpPath :: FilePath }
deriving (Eq, Ord, Show, Read, Generic, Typeable) deriving (Eq, Ord, Show, Read, Generic, Typeable)
instance Binary ModulePath where instance Binary ModulePath where
put = gput . from put = ggput . from
get = to `fmap` gget get = to `fmap` ggget
instance Binary ModuleName where instance Binary ModuleName where
get = mkModuleName <$> get get = mkModuleName <$> get
@ -372,17 +372,17 @@ instance Error GhcModError where
instance Exception GhcModError instance Exception GhcModError
instance Binary CabalHelper.Programs where instance Binary CabalHelper.Programs where
put = gput . from put = ggput . from
get = to `fmap` gget get = to `fmap` ggget
instance Binary ChModuleName where instance Binary ChModuleName where
put = gput . from put = ggput . from
get = to `fmap` gget get = to `fmap` ggget
instance Binary ChComponentName where instance Binary ChComponentName where
put = gput . from put = ggput . from
get = to `fmap` gget get = to `fmap` ggget
instance Binary ChEntrypoint where instance Binary ChEntrypoint where
put = gput . from put = ggput . from
get = to `fmap` gget get = to `fmap` ggget
mkLabel ''GhcModCaches mkLabel ''GhcModCaches
mkLabel ''GhcModState mkLabel ''GhcModState

View File

@ -48,7 +48,7 @@ instance Binary ModTime where
put (ModTime (TOD s ps)) = put (ModTime (TOD s ps)) =
put s >> put ps put s >> put ps
get = get =
ModTime . TOD <$> get <*> get ModTime <$> (TOD <$> get <*> get)
#endif #endif