git.iko.soy/distributed-process
on master help sign in
Compatibility with ghc-7.10: write proper NFData instances.
ed800e6Alexander Vershilov
distributed-process.cabal+1−1
@@ -94,7 +94,7 @@ Library
94 deepseq == 1.3.0.0
94 deepseq == 1.3.0.0
95 else
95 else
96 Build-Depends: containers >= 0.4 && < 0.6,
96 Build-Depends: containers >= 0.4 && < 0.6,
97− deepseq >= 1.3.0.1 && < 1.4
97+ deepseq >= 1.3.0.1 && < 1.6
98 if flag(old-locale)
98 if flag(old-locale)
99 Build-Depends: time < 1.5, old-locale >= 1.0 && <1.1
99 Build-Depends: time < 1.5, old-locale >= 1.0 && <1.1
100 else
100 else
src/Control/Distributed/Process/Internal/Types.hs+27−7
@@ -3,6 +3,7 @@
3{-# LANGUAGE GeneralizedNewtypeDeriving #-}
3{-# LANGUAGE GeneralizedNewtypeDeriving #-}
4{-# LANGUAGE GADTs #-}
4{-# LANGUAGE GADTs #-}
5{-# LANGUAGE DeriveGeneric #-}
5{-# LANGUAGE DeriveGeneric #-}
6+{-# LANGUAGE CPP #-}
6
7
7-- | Types used throughout the Cloud Haskell framework
8-- | Types used throughout the Cloud Haskell framework
8--
9--
@@ -137,7 +138,7 @@ import GHC.Generics
137newtype NodeId = NodeId { nodeAddress :: NT.EndPointAddress }
138newtype NodeId = NodeId { nodeAddress :: NT.EndPointAddress }
138 deriving (Eq, Ord, Typeable, Data, Generic)
139 deriving (Eq, Ord, Typeable, Data, Generic)
139instance Binary NodeId where
140instance Binary NodeId where
140−instance NFData NodeId
141+instance NFData NodeId where rnf (NodeId a) = rnf a `seq` ()
141instance Hashable NodeId where
142instance Hashable NodeId where
142instance Show NodeId where
143instance Show NodeId where
143 show (NodeId addr) = "nid://" ++ show addr
144 show (NodeId addr) = "nid://" ++ show addr
@@ -162,7 +163,7 @@ data ProcessId = ProcessId
162 deriving (Eq, Ord, Typeable, Data, Generic)
163 deriving (Eq, Ord, Typeable, Data, Generic)
163
164
164instance Binary ProcessId where
165instance Binary ProcessId where
165−instance NFData ProcessId where
166+instance NFData ProcessId where rnf (ProcessId n _) = rnf n `seq` ()
166instance Hashable ProcessId where
167instance Hashable ProcessId where
167
168
168instance Show ProcessId where
169instance Show ProcessId where
@@ -177,6 +178,10 @@ data Identifier =
177 deriving (Eq, Ord, Generic)
178 deriving (Eq, Ord, Generic)
178
179
179instance Hashable Identifier where
180instance Hashable Identifier where
181+instance NFData Identifier where
182+ rnf (NodeIdentifier n) = rnf n `seq` ()
183+ rnf (ProcessIdentifier n) = rnf n `seq` ()
184+ rnf n@SendPortIdentifier{} = n `seq` ()
180
185
181instance Show Identifier where
186instance Show Identifier where
182 show (NodeIdentifier nid) = show nid
187 show (NodeIdentifier nid) = show nid
@@ -317,6 +322,9 @@ instance Show SendPortId where
317 show (SendPortId (ProcessId (NodeId addr) (LocalProcessId _ plid)) clid)
322 show (SendPortId (ProcessId (NodeId addr) (LocalProcessId _ plid)) clid)
318 = "cid://" ++ show addr ++ ":" ++ show plid ++ ":" ++ show clid
323 = "cid://" ++ show addr ++ ":" ++ show plid ++ ":" ++ show clid
319
324
325+instance NFData SendPortId where
326+ rnf (SendPortId p _) = rnf p `seq` ()
327+
320data TypedChannel = forall a. Serializable a => TypedChannel (Weak (TQueue a))
328data TypedChannel = forall a. Serializable a => TypedChannel (Weak (TQueue a))
321
329
322-- | The send send of a typed channel (serializable)
330-- | The send send of a typed channel (serializable)
@@ -328,7 +336,7 @@ newtype SendPort a = SendPort {
328
336
329instance (Serializable a) => Binary (SendPort a) where
337instance (Serializable a) => Binary (SendPort a) where
330instance (Hashable a) => Hashable (SendPort a) where
338instance (Hashable a) => Hashable (SendPort a) where
331−instance (NFData a) => NFData (SendPort a) where
339+instance (NFData a) => NFData (SendPort a) where rnf (SendPort x) = x `seq` ()
332
340
333-- | The receive end of a typed channel (not serializable)
341-- | The receive end of a typed channel (not serializable)
334--
342--
@@ -366,6 +374,14 @@ data Message =
366 }
374 }
367 deriving (Typeable)
375 deriving (Typeable)
368
376
377+instance NFData Message where
378+#if MIN_VERSION_bytestring(0,10,0)
379+ rnf (EncodedMessage _ e) = rnf e `seq` ()
380+#else
381+ rnf (EncodedMessage _ e) = BSL.length e `seq` ()
382+#endif
383+ rnf (UnencodedMessage _ a) = a `seq` () -- forced to WHNF only
384+
369instance Show Message where
385instance Show Message where
370 show (EncodedMessage fp enc) = show enc ++ " :: " ++ showFingerprint fp []
386 show (EncodedMessage fp enc) = show enc ++ " :: " ++ showFingerprint fp []
371 show (UnencodedMessage _ uenc) = "[unencoded message] :: " ++ (show $ typeOf uenc)
387 show (UnencodedMessage _ uenc) = "[unencoded message] :: " ++ (show $ typeOf uenc)
@@ -429,7 +445,10 @@ data MonitorRef = MonitorRef
429 , monitorRefCounter :: !Int32
445 , monitorRefCounter :: !Int32
430 }
446 }
431 deriving (Eq, Ord, Show, Typeable, Generic)
447 deriving (Eq, Ord, Show, Typeable, Generic)
432−instance Hashable MonitorRef where
448+instance Hashable MonitorRef
449+
450+instance NFData MonitorRef where
451+ rnf (MonitorRef i _) = rnf i `seq` ()
433
452
434-- | Message sent by process monitors
453-- | Message sent by process monitors
435data ProcessMonitorNotification =
454data ProcessMonitorNotification =
@@ -497,6 +516,10 @@ data DiedReason =
497 | DiedUnknownId
516 | DiedUnknownId
498 deriving (Show, Eq)
517 deriving (Show, Eq)
499
518
519+instance NFData DiedReason where
520+ rnf (DiedException s) = rnf s `seq` ()
521+ rnf x = x `seq` ()
522+
500-- | (Asynchronous) reply from unmonitor
523-- | (Asynchronous) reply from unmonitor
501newtype DidUnmonitor = DidUnmonitor MonitorRef
524newtype DidUnmonitor = DidUnmonitor MonitorRef
502 deriving (Typeable, Binary)
525 deriving (Typeable, Binary)
@@ -678,9 +701,6 @@ instance Binary SendPortId where
678 put cid = put (sendPortProcessId cid) >> put (sendPortLocalId cid)
701 put cid = put (sendPortProcessId cid) >> put (sendPortLocalId cid)
679 get = SendPortId <$> get <*> get
702 get = SendPortId <$> get <*> get
680
703
681−instance NFData SendPortId where
682− rnf cid = (sendPortProcessId cid) `seq` (sendPortLocalId cid) `seq` ()
683−
684instance Binary Identifier where
704instance Binary Identifier where
685 put (ProcessIdentifier pid) = putWord8 0 >> put pid
705 put (ProcessIdentifier pid) = putWord8 0 >> put pid
686 put (NodeIdentifier nid) = putWord8 1 >> put nid
706 put (NodeIdentifier nid) = putWord8 1 >> put nid