git.iko.soy/distributed-process
on master help sign in
Reset changes disabling the optimiser and avoid GHC INLINE bug
commit5fc844fc616bbc88d8913098ede4b973b88b83ca authorTim Watson <watson.timothy@gmail.com> dateMon 19 Nov 2018, 21:14 (8 years ago) parentdc65e6d
6 files changed+50−36
distributed-process-tests/src/Control/Distributed/Process/Tests/CH.hs+6−7 src/Control/Distributed/Process/Internal/Primitives.hs+8−5 src/Control/Distributed/Process/Management/Internal/Types.hs+5 src/Control/Distributed/Process/Node.hs+15−10 src/Control/Distributed/Process/UnsafePrimitives.hs+15−13 stack-ghc-7.10.3.yaml+1−1
distributed-process-tests/src/Control/Distributed/Process/Tests/CH.hs+6−7
@@ -44,7 +44,7 @@ import Control.Distributed.Process.Internal.Types
4444import Control.Distributed.Process.Node
4545import Control.Distributed.Process.Debug
4646import Control.Distributed.Process.Management.Internal.Types
47−import Control.Distributed.Process.Tests.Internal.Utils (shouldBe)
47+import Control.Distributed.Process.Tests.Internal.Utils (shouldBe, pause)
4848import Control.Distributed.Process.Serializable (Serializable)
4949
5050import Test.HUnit (Assertion, assertBool, assertFailure)
@@ -87,10 +87,9 @@ verifyClient :: String -> MVar Bool -> IO ()
8787verifyClient s b = takeMVar b >>= assertBool s
8888
8989expectPing :: MVar Bool -> Process ()
90−expectPing mv = expect >>= liftIO . putMVar mv . checkPing
90+expectPing mv = expect >>= liftIO . putMVar mv . checkPing
9191 where
9292 checkPing (Ping _) = True
93− checkPing _ = False
9493
9594-- | Quick and dirty synchronous version of whereisRemoteAsync
9695whereisRemote :: NodeId -> String -> Process (Maybe ProcessId)
@@ -240,10 +239,10 @@ testPing TestTransport{..} = do
240239 pid <- getSelfPid
241240 replicateM_ numPings $ do
242241 send pingServer (Pong pid)
243− p <- expect
242+ p <- expectTimeout 3000000
244243 case p of
245− Ping _ -> return ()
246− _ -> die "Unexpected message"
244+ Just (Ping _) -> return ()
245+ Nothing -> die "Failed to receive Ping"
247246
248247 putMVar clientDone ()
249248
@@ -560,7 +559,7 @@ testMergeChannels TestTransport{..} = do
560559 ss <- liftIO $ mapM readMVar vs
561560 case ss of
562561 [sa, sb, sc] ->
563− mapM_ ((>> liftIO (threadDelay 10000)) . uncurry sendChan)
562+ mapM_ ((>> pause 10000) . uncurry sendChan)
564563 [ -- a, b, c
565564 (sa, 'a')
566565 , (sb, 'b')
src/Control/Distributed/Process/Internal/Primitives.hs+8−5
@@ -335,13 +335,16 @@ newChan = do
335335sendChan :: Serializable a => SendPort a -> a -> Process ()
336336sendChan (SendPort cid) msg = do
337337 proc <- ask
338− let node = localNodeId (processNode proc)
339− destNode = processNodeId (sendPortProcessId cid) in do
340− case destNode == node of
338+ let node = processNode proc
339+ pid = processId proc
340+ us = localNodeId node
341+ them = processNodeId (sendPortProcessId cid) in do
342+ liftIO $ traceEvent (localEventBus node) (MxSentToPort pid cid $ wrapMessage msg)
343+ case them == us of
341344 True -> sendChanLocal cid msg
342345 False -> do
343− liftIO $ sendBinary (processNode proc)
344− (ProcessIdentifier (processId proc))
346+ liftIO $ sendBinary node
347+ (ProcessIdentifier pid)
345348 (SendPortIdentifier cid)
346349 NoImplicitReconnect
347350 msg
src/Control/Distributed/Process/Management/Internal/Types.hs+5
@@ -21,6 +21,7 @@ import Control.Concurrent.STM
2121import Control.Distributed.Process.Internal.Types
2222 ( Process
2323 , ProcessId
24+ , SendPortId
2425 , Message
2526 , DiedReason
2627 , NodeId
@@ -59,8 +60,12 @@ data MxEvent =
5960 -- ^ fired whenever a message is sent from a local process
6061 | MxSentToName String ProcessId Message
6162 -- ^ fired whenever a named send occurs
63+ | MxSentToPort ProcessId SendPortId Message
64+ -- ^ fired whenever a sendChan occurs
6265 | MxReceived ProcessId Message
6366 -- ^ fired whenever a message is received by a local process
67+ | MxReceivedPort SendPortId Message
68+ -- ^ fired whenever a message is received via a typed channel
6469 | MxConnected ConnectionId EndPointAddress
6570 -- ^ fired when a network-transport connection is first established
6671 | MxDisconnected ConnectionId EndPointAddress
src/Control/Distributed/Process/Node.hs+15−10
@@ -492,7 +492,7 @@ type IncomingConnection = (NT.EndPointAddress, IncomingTarget)
492492data IncomingTarget =
493493 Uninit
494494 | ToProc ProcessId (Weak (CQueue Message))
495− | ToChan TypedChannel
495+ | ToChan SendPortId TypedChannel
496496 | ToNode
497497
498498data ConnectionState = ConnectionState {
@@ -547,13 +547,17 @@ handleIncomingMessages node = go initConnectionState
547547 enqueue queue msg -- 'enqueue' is strict
548548 trace node (MxReceived pid msg)
549549 go st
550− Just (_, ToChan (TypedChannel chan')) -> do
550+ Just (_, ToChan chId (TypedChannel chan')) -> do
551551 mChan <- deRefWeak chan'
552552 -- If mChan is Nothing, the process has given up the read end of
553553 -- the channel and we simply ignore the incoming message
554− forM_ mChan $ \chan -> atomically $
555− -- We make sure the message is fully decoded when it is enqueued
556− writeTQueue chan $! decode (BSL.fromChunks payload)
554+ forM_ mChan $ \chan -> do
555+ msg' <- atomically $ do
556+ msg <- return $! decode (BSL.fromChunks payload)
557+ -- We make sure the message is fully decoded when it is enqueued
558+ writeTQueue chan msg
559+ return msg
560+ trace node $ MxReceivedPort chId $ unsafeCreateUnencodedMessage msg'
557561 go st
558562 Just (_, ToNode) -> do
559563 let ctrlMsg = decode . BSL.fromChunks $ payload
@@ -580,7 +584,7 @@ handleIncomingMessages node = go initConnectionState
580584 mChannel <- withMVar (processState proc) $ return . (^. typedChannelWithId lcid)
581585 case mChannel of
582586 Just channel ->
583− go (incomingAt cid ^= Just (src, ToChan channel) $ st)
587+ go (incomingAt cid ^= Just (src, ToChan chId channel) $ st)
584588 Nothing ->
585589 invalidRequest cid st $
586590 "incoming attempt to connect to unknown channel of"
@@ -1050,11 +1054,12 @@ ncEffectLocalPortSend from msg = do
10501054 -- If ch is Nothing, the process has given up the read end of
10511055 -- the channel and we simply ignore the incoming message - this
10521056 ch <- deRefWeak chan'
1053− forM_ ch $ \chan -> deliverChan msg chan
1054− where deliverChan :: forall a . Message -> TQueue a -> IO ()
1055− deliverChan (UnencodedMessage _ raw) chan' =
1057+ forM_ ch $ \chan -> deliverChan node from msg chan
1058+ where deliverChan :: forall a . LocalNode -> SendPortId -> Message -> TQueue a -> IO ()
1059+ deliverChan n p (UnencodedMessage _ raw) chan' = do
10561060 atomically $ writeTQueue chan' ((unsafeCoerce raw) :: a)
1057− deliverChan (EncodedMessage _ _) _ =
1061+ trace n (MxReceivedPort p $ unsafeCreateUnencodedMessage raw)
1062+ deliverChan _ _ (EncodedMessage _ _) _ =
10581063 -- this will not happen unless someone screws with Primitives.hs
10591064 error "invalid local channel delivery"
10601065
src/Control/Distributed/Process/UnsafePrimitives.hs+15−13
@@ -178,20 +178,22 @@ usend them msg = do
178178sendChan :: Serializable a => SendPort a -> a -> Process ()
179179sendChan (SendPort cid) msg = do
180180 proc <- ask
181− let node = localNodeId (processNode proc)
182− destNode = processNodeId (sendPortProcessId cid) in do
183− case destNode == node of
184− True -> unsafeSendChanLocal cid msg
185− False ->
186− liftIO $ sendBinary (processNode proc)
187− (ProcessIdentifier (processId proc))
188− (SendPortIdentifier cid)
189− NoImplicitReconnect
190− msg
181+ let node = processNode proc
182+ pid = processId proc
183+ us = localNodeId node
184+ them = processNodeId (sendPortProcessId cid)
185+ msg' = wrapMessage msg in do
186+ liftIO $ traceEvent (localEventBus node) (MxSentToPort pid cid msg')
187+ if them == us
188+ then unsafeSendChanLocal cid msg' -- NB: we wrap to P.Message !!!
189+ else liftIO $ sendBinary node
190+ (ProcessIdentifier pid)
191+ (SendPortIdentifier cid)
192+ NoImplicitReconnect
193+ msg
191194 where
192− unsafeSendChanLocal :: (Serializable a) => SendPortId -> a -> Process ()
193− unsafeSendChanLocal spId msg' =
194− sendCtrlMsg Nothing $ LocalPortSend spId (wrapMessage msg')
195+ unsafeSendChanLocal :: SendPortId -> Message -> Process ()
196+ unsafeSendChanLocal p m = sendCtrlMsg Nothing $ LocalPortSend p m
195197
196198-- | Create an unencoded @Message@ for any @Serializable@ type.
197199wrapMessage :: Serializable a => a -> Message
stack-ghc-7.10.3.yaml+1−1
@@ -14,7 +14,7 @@ extra-deps:
1414- network-transport-0.5.2
1515- network-transport-inmemory-0.5.2
1616- rematch-0.2.0.0
17−- exceptions-0.8.2.1 # test dependency
17+- exceptions-0.8.2.1
1818
1919flags:
2020 distributed-process-tests: