Andrea Vezzosi pushed to branch wip/romes/async-rpc at Glasgow Haskell Compiler / GHC
Commits:
-
422ec8e5
by Rodrigo Mesquita at 2026-10-23T14:41:27+02:00
-
5cc052e8
by Andrea Vezzosi at 2026-10-23T17:49:10+02:00
9 changed files:
- compiler/GHC/Runtime/Interpreter/Process.hs
- libraries/ghci/GHCi/Message.hs
- libraries/ghci/GHCi/Message/Async.hs
- libraries/ghci/GHCi/Server.hs
- libraries/ghci/GHCi/Server/Threads.hs
- testsuite/tests/ghci/should_run/Makefile
- testsuite/tests/ghci/should_run/T3171.stdout
- + testsuite/tests/ghci/should_run/T3171ext.stdout
- testsuite/tests/ghci/should_run/all.T
Changes:
| ... | ... | @@ -64,7 +64,7 @@ sendTHComputation i msg reqHandler = mask $ \restore -> do |
| 64 | 64 | where
|
| 65 | 65 | proc = instProcess i
|
| 66 | 66 | handleOne mbox doneRef = do
|
| 67 | - handleRemoteTHCall (interpPipe proc) mbox $ \req -> do
|
|
| 67 | + handleRemoteTHCall (interpPipe proc) mbox $ \_setCancel req -> do
|
|
| 68 | 68 | (stop, res) <- reqHandler req
|
| 69 | 69 | writeIORef doneRef stop
|
| 70 | 70 | return res
|
| ... | ... | @@ -75,6 +75,7 @@ import GHC.Stack.CCS |
| 75 | 75 | import qualified GHC.Boot.TH.Syntax as TH
|
| 76 | 76 | import qualified GHC.Boot.TH.Monad as TH
|
| 77 | 77 | import GHCi.Message.Async
|
| 78 | +import Control.Monad.STM
|
|
| 78 | 79 | |
| 79 | 80 | -- -----------------------------------------------------------------------------
|
| 80 | 81 | -- The RPC protocol between GHC and the interactive server
|
| ... | ... | @@ -666,12 +667,12 @@ remoteCall pipe msg = either throwIO (pure . runGet get) |
| 666 | 667 | -- | Handle a single 'Message' request on the interpreter and reply to the host
|
| 667 | 668 | handleRemoteCall :: Pipe
|
| 668 | 669 | -> (Msg -> IO Msg) {-^ Msg hook -}
|
| 669 | - -> (forall a. (Show a, Binary a) => WriteReply a %1 -> Message a -> IO r)
|
|
| 670 | + -> (forall a. (Show a, Binary a) => WriteReply a %1 -> (IO () -> IO ()) -> Message a -> IO r)
|
|
| 670 | 671 | -> IO r
|
| 671 | 672 | handleRemoteCall pipe hook k =
|
| 672 | - handleAsyncReq pipe getMessage Nothing \(WriteReply writer) msg0 -> IO \s0 ->
|
|
| 673 | + handleAsyncReq pipe getMessage Nothing \(WriteReply writer) sa msg0 -> IO \s0 ->
|
|
| 673 | 674 | case hook msg0 |#> s0 of -- unIO for linearity checking
|
| 674 | - (# s1, Msg msg #) -> k (WriteReply \x -> writer (fmap put x)) msg |#> s1
|
|
| 675 | + (# s1, Msg msg #) -> k (WriteReply \x -> writer (fmap put x)) sa msg |#> s1
|
|
| 675 | 676 | |
| 676 | 677 | -- | Send a 'THMessage' request to the host and wait for a reply from the host
|
| 677 | 678 | -- to the interpreter.
|
| ... | ... | @@ -687,9 +688,9 @@ remoteTHCall pipe ii msg = either throwIO (pure . runGet get) |
| 687 | 688 | -- Symmterically to 'remoteTHCall', we always want to specify the 'InboxId' for
|
| 688 | 689 | -- RunTH "reverse requests"
|
| 689 | 690 | handleRemoteTHCall
|
| 690 | - :: Pipe -> InboxId -> (forall a. (Show a, Binary a) => THMessage a -> IO a) -> IO ()
|
|
| 691 | + :: Pipe -> InboxId -> (forall a. (Show a, Binary a) => (IO () -> IO ()) -> THMessage a -> IO a) -> IO ()
|
|
| 691 | 692 | handleRemoteTHCall pipe ii k =
|
| 692 | - handleAsyncReq pipe getTHMessage (Just ii) \writer (THMsg msg) -> IO \s0 ->
|
|
| 693 | - case k msg |#> s0 of -- unIO for linearity checking
|
|
| 693 | + handleAsyncReq pipe getTHMessage (Just ii) \writer sa (THMsg msg) -> IO \s0 ->
|
|
| 694 | + case k sa msg |#> s0 of -- unIO for linearity checking
|
|
| 694 | 695 | (# s1, a #) -> writeReply writer (put a) |#> s1
|
| 695 | 696 |
| ... | ... | @@ -160,14 +160,19 @@ instance Exception PipeWriteClosedException |
| 160 | 160 | -- and identify whether they are requests or replies.
|
| 161 | 161 | |
| 162 | 162 | writePipe :: Pipe -> IddMsg -> IO ()
|
| 163 | -writePipe Pipe{..} msg = do
|
|
| 164 | - var <- newEmptyTMVarIO
|
|
| 165 | - atomically $ do
|
|
| 163 | +writePipe p msg = do
|
|
| 164 | + var <- atomically $ writePipeAsync p msg
|
|
| 165 | + either throwIO pure =<< atomically (takeTMVar var)
|
|
| 166 | + |
|
| 167 | +writePipeAsync :: Pipe -> IddMsg -> STM (TMVar (Either SomeException ()))
|
|
| 168 | +writePipeAsync Pipe{..} msg = do
|
|
| 169 | + var <- newEmptyTMVar
|
|
| 166 | 170 | readTVar pipeWriteClosed >>= \case
|
| 167 | 171 | True -> throwSTM PipeWriteClosedException
|
| 168 | 172 | False -> pure ()
|
| 169 | 173 | writeTQueue (writeQueue pipeAsyncMngr) (msg, var)
|
| 170 | - either throwIO pure =<< atomically (takeTMVar var)
|
|
| 174 | + pure var
|
|
| 175 | + |
|
| 171 | 176 | |
| 172 | 177 | -- | Only the 'drainPipe' thread should read from the pipe directly. Other
|
| 173 | 178 | -- functions should wait for the matching reply to be delivered asynchronously.
|
| ... | ... | @@ -239,14 +244,18 @@ remoteAsyncReq pipe msg ii = do |
| 239 | 244 | -- Write request
|
| 240 | 245 | writePipe pipe (Request uq ii (runPut msg))
|
| 241 | 246 | `onException`
|
| 242 | - -- the req wasn't done, or no one will be reading the reply:
|
|
| 243 | - -- in either case, drop it from the pending map.
|
|
| 244 | - atomically (modifyTVar pendingReplies (IntMap.delete uq))
|
|
| 247 | + -- the req wasn't done, or no one will be reading the reply:
|
|
| 248 | + -- in either case, drop it from the pending map.
|
|
| 249 | + atomically (modifyTVar pendingReplies (IntMap.delete uq))
|
|
| 245 | 250 | |
| 246 | 251 | -- Block waiting for reply
|
| 247 | 252 | atomically (takeTMVar wv)
|
| 248 | 253 | `onException`
|
| 249 | - atomically (modifyTVar pendingReplies (IntMap.delete uq))
|
|
| 254 | + atomically (do
|
|
| 255 | + modifyTVar pendingReplies (IntMap.delete uq)
|
|
| 256 | + -- we don't wait for Cancel to be written on the pipe,
|
|
| 257 | + -- and won't get a reply: nowhere to report it anyway.
|
|
| 258 | + writePipeAsync pipe (Cancel uq))
|
|
| 250 | 259 | |
| 251 | 260 | -- | Receive a single asynchronous request and send a matching reply
|
| 252 | 261 | -- asynchronously (the handler may fork a computation that eventually replies
|
| ... | ... | @@ -258,7 +267,7 @@ remoteAsyncReq pipe msg ii = do |
| 258 | 267 | -- branch, and if the handler otherwise throws, it is handled by 'handleAsyncReq'.
|
| 259 | 268 | --
|
| 260 | 269 | -- See Note [Exceptions during serialization] about exceptions the 'Put' argument might raise.
|
| 261 | -handleAsyncReq :: Pipe -> Get a -> (Maybe InboxId) -> (WriteReply Put %1 -> a -> IO r) -> IO r
|
|
| 270 | +handleAsyncReq :: Pipe -> Get a -> (Maybe InboxId) -> (WriteReply Put %1 -> (IO () -> IO ()) -> a -> IO r) -> IO r
|
|
| 262 | 271 | handleAsyncReq pipe getit mii k = mask $ \restore -> do
|
| 263 | 272 | let am = pipeAsyncMngr pipe
|
| 264 | 273 | ack <- newEmptyMVar
|
| ... | ... | @@ -274,7 +283,7 @@ handleAsyncReq pipe getit mii k = mask $ \restore -> do |
| 274 | 283 | Nothing -> tryReadTQueue $ requestsQueue am
|
| 275 | 284 | Just ii -> tryReadTQueue =<< getMailbox am ii
|
| 276 | 285 | case taken of
|
| 277 | - Just req -> pure (Just req)
|
|
| 286 | + Just req@(uq,_) -> fetchedRequest am uq >> pure (Just req)
|
|
| 278 | 287 | Nothing | isClosed -> pure Nothing -- empty and closed
|
| 279 | 288 | | otherwise -> retry -- wait for msg
|
| 280 | 289 | |
| ... | ... | @@ -282,9 +291,9 @@ handleAsyncReq pipe getit mii k = mask $ \restore -> do |
| 282 | 291 | Nothing -> throwIO PipeReadClosedException -- can't expect reqs
|
| 283 | 292 | Just (uq, bs) -> do
|
| 284 | 293 | let reply p = do
|
| 285 | - writePipe pipe (Reply uq (bimap toSerializableException runPut p))
|
|
| 286 | - putMVar ack ()
|
|
| 287 | - |
|
| 294 | + b <- atomically $ doneHandling am uq
|
|
| 295 | + when b $ writePipe pipe (Reply uq (bimap toSerializableException runPut p))
|
|
| 296 | + putMVar ack () -- TODO: superfluous?
|
|
| 288 | 297 | -- Run the continuation which must reply exactly once with 'writeReply'
|
| 289 | 298 | case runGetOrFail getit bs of
|
| 290 | 299 | Left (_, _, err) -> do
|
| ... | ... | @@ -292,7 +301,7 @@ handleAsyncReq pipe getit mii k = mask $ \restore -> do |
| 292 | 301 | reply (Left (toException exc))
|
| 293 | 302 | throwIO exc
|
| 294 | 303 | Right (_, _, it) ->
|
| 295 | - restore (k (WriteReply reply) it)
|
|
| 304 | + restore (k (WriteReply reply) (setActive am uq) it)
|
|
| 296 | 305 | |
| 297 | 306 | -- If there's an exception before the reply is sent, reply with an error instead.
|
| 298 | 307 | `catch` \(e :: SomeException) -> do
|
| ... | ... | @@ -306,6 +315,7 @@ handleAsyncReq pipe getit mii k = mask $ \restore -> do |
| 306 | 315 | reply (Left e)
|
| 307 | 316 | throwIO e
|
| 308 | 317 | |
| 318 | + |
|
| 309 | 319 | -- | 'handleSyncReq' failed to decode an incoming request payload using the given @'Get' a@
|
| 310 | 320 | newtype DecodeAsyncReqException = DecodeAsyncReqException String deriving Show
|
| 311 | 321 | instance Exception DecodeAsyncReqException
|
| ... | ... | @@ -347,6 +357,15 @@ getMailbox am (InboxId ii) = do |
| 347 | 357 | |
| 348 | 358 | -- ** Async matching "internals" -----------------------------------------------
|
| 349 | 359 | |
| 360 | +-- | Requests go
|
|
| 361 | +-- requestsQueue -> Fetched -> Active cancel -> gone
|
|
| 362 | +-- .. -> Canceling -> gone
|
|
| 363 | +-- Canceling is needed to avoid race condition in gap between Fetched and Active.
|
|
| 364 | +data RequestStatus
|
|
| 365 | + = Fetched
|
|
| 366 | + | Active (IO ()) -- ^ must not be blocking.
|
|
| 367 | + | Canceling
|
|
| 368 | + |
|
| 350 | 369 | data AsyncManager = AsyncManager
|
| 351 | 370 | { pendingReply :: !(TVar (IntMap (TMVar (Either SomeException LB.ByteString))))
|
| 352 | 371 | -- ^ When a request is sent, keep track that we're expecting a reply. The
|
| ... | ... | @@ -357,6 +376,9 @@ data AsyncManager = AsyncManager |
| 357 | 376 | -- /without/ a specific 'InboxId', queue it here. A request handler will
|
| 358 | 377 | -- pop the next request from it. (Nothing except the 'drainPipe' thread
|
| 359 | 378 | -- should read from the pipe). Read with @'handleAsyncReq' p get Nothing@.
|
| 379 | + , cancelStatus :: !(TVar (IntMap RequestStatus))
|
|
| 380 | + -- ^ When a `Cancel uq` is received, we lookup `uq` in this map and call the
|
|
| 381 | + -- callback if present.
|
|
| 360 | 382 | , mailboxQueues :: !(TVar (IntMap (TQueue (CorrelationId, LB.ByteString))))
|
| 361 | 383 | -- ^ Requests for a specific 'InboxId' that can be read using
|
| 362 | 384 | -- @'handleAsyncReq' p get (Just <mailboxid>)@.
|
| ... | ... | @@ -389,15 +411,21 @@ type CorrelationId = Int |
| 389 | 411 | -- exclusively.
|
| 390 | 412 | data IddMsg = Request !CorrelationId !(Maybe InboxId) LB.ByteString
|
| 391 | 413 | | Reply !CorrelationId (Either SerializableException LB.ByteString)
|
| 414 | + | Cancel !CorrelationId -- !(Maybe InboxId) --? ^ Technically a
|
|
| 415 | + -- Request, but no Reply is expected, the CorrelationId is the
|
|
| 416 | + -- one of the Request being canceled.
|
|
| 392 | 417 | |
| 393 | 418 | instance Binary IddMsg where
|
| 394 | 419 | put (Request i ii bs) = putWord8 0 >> put i >> put ii >> put bs
|
| 395 | 420 | put (Reply i bs) = putWord8 1 >> put i >> put bs
|
| 421 | + put (Cancel i) = putWord8 2 >> put i
|
|
| 422 | + |
|
| 396 | 423 | get = do
|
| 397 | 424 | b <- getWord8
|
| 398 | 425 | case b of
|
| 399 | 426 | 0 -> Request <$> get <*> get <*> get
|
| 400 | 427 | 1 -> Reply <$> get <*> get
|
| 428 | + 2 -> Cancel <$> get
|
|
| 401 | 429 | _ -> fail $ "impossible: Binary IddMsg - " ++ show b
|
| 402 | 430 | |
| 403 | 431 | newAsyncManager :: Pipe -> IO AsyncManager
|
| ... | ... | @@ -405,6 +433,7 @@ newAsyncManager pipe = do |
| 405 | 433 | asyncFreshId <- newIORef 0
|
| 406 | 434 | pendingReply <- newTVarIO IntMap.empty
|
| 407 | 435 | requestsQueue <- newTQueueIO
|
| 436 | + cancelStatus <- newTVarIO IntMap.empty
|
|
| 408 | 437 | mailboxQueues <- newTVarIO IntMap.empty
|
| 409 | 438 | writeQueue <- newTQueueIO
|
| 410 | 439 | |
| ... | ... | @@ -455,6 +484,7 @@ drainPipe p unmask = catch (unmask $ loop `finally` pipeCloseRead p) replyToPend |
| 455 | 484 | q <- getMailbox am ii
|
| 456 | 485 | writeTQueue q (uq,bs)
|
| 457 | 486 | loop
|
| 487 | + Just (Cancel uq) -> cancelRequest am uq
|
|
| 458 | 488 | -- EOF on read handle
|
| 459 | 489 | Nothing -> do
|
| 460 | 490 | -- clean up pipe then exit loop
|
| ... | ... | @@ -465,6 +495,46 @@ drainPipe p unmask = catch (unmask $ loop `finally` pipeCloseRead p) replyToPend |
| 465 | 495 | |
| 466 | 496 | am = pipeAsyncMngr p
|
| 467 | 497 | |
| 498 | +cancelRequest :: AsyncManager -> CorrelationId -> IO ()
|
|
| 499 | +cancelRequest am uq = join . atomically $ do
|
|
| 500 | + cs <- readTVar (cancelStatus am)
|
|
| 501 | + case IntMap.lookup uq cs of
|
|
| 502 | + Nothing -> pure (pure ())
|
|
| 503 | + Just Fetched -> writeTVar (cancelStatus am) (IntMap.insert uq Canceling cs) >> pure (pure ())
|
|
| 504 | + Just (Active cancel) -> writeTVar (cancelStatus am) (IntMap.delete uq cs) >> pure cancel
|
|
| 505 | + Just Canceling -> pure (pure ())
|
|
| 506 | + |
|
| 507 | +doneHandling :: AsyncManager -> CorrelationId -> STM Bool
|
|
| 508 | +doneHandling am uq = do
|
|
| 509 | + cs <- readTVar (cancelStatus am)
|
|
| 510 | + case IntMap.lookup uq cs of
|
|
| 511 | + Nothing -> pure False
|
|
| 512 | + Just s -> do
|
|
| 513 | + writeTVar (cancelStatus am) $ IntMap.delete uq cs
|
|
| 514 | + case s of
|
|
| 515 | + Canceling -> pure False
|
|
| 516 | + _ -> pure True
|
|
| 517 | + |
|
| 518 | +setActive :: AsyncManager -> CorrelationId -> IO () -> IO ()
|
|
| 519 | +setActive am uq cancel = join . atomically $ do
|
|
| 520 | + cs <- readTVar (cancelStatus am)
|
|
| 521 | + case IntMap.lookup uq cs of
|
|
| 522 | + Nothing -> pure (pure ()) -- reply already received.
|
|
| 523 | + Just Fetched -> writeTVar (cancelStatus am) (IntMap.insert uq (Active cancel) cs) >> pure (pure ())
|
|
| 524 | + Just (Active _) -> writeTVar (cancelStatus am) (IntMap.insert uq (Active cancel) cs) >> pure (pure ())
|
|
| 525 | + Just Canceling -> pure cancel
|
|
| 526 | + |
|
| 527 | +fetchedRequest :: AsyncManager -> CorrelationId -> STM ()
|
|
| 528 | +fetchedRequest am uq = do
|
|
| 529 | + cs <- readTVar (cancelStatus am)
|
|
| 530 | + case IntMap.lookup uq cs of
|
|
| 531 | + Nothing -> writeTVar (cancelStatus am) (IntMap.insert uq Fetched cs)
|
|
| 532 | + Just Fetched -> error "impossible"
|
|
| 533 | + Just (Active _) -> error "impossible"
|
|
| 534 | + Just Canceling -> error "impossible"
|
|
| 535 | + |
|
| 536 | + |
|
| 537 | + |
|
| 468 | 538 | {-
|
| 469 | 539 | Note [Exceptions during serialization]
|
| 470 | 540 | -----------------------------------------------------------------------------
|
| ... | ... | @@ -553,7 +623,7 @@ runWriteReply (WriteReply r) = r |
| 553 | 623 | (|#>) (IO fs) s = fs s
|
| 554 | 624 | |
| 555 | 625 | (%>>=) :: (IO a) -> (a -> IO b) %1 -> IO b
|
| 556 | -(%>>=) = \ m f -> IO (\s0 ->
|
|
| 626 | +(%>>=) = \ m -> \ f -> IO (\s0 ->
|
|
| 557 | 627 | case m |#> s0 of -- unIO for linearity checking
|
| 558 | 628 | (# s1, x #) -> f x |#> s1)
|
| 559 | 629 | infixl 1 %>>=
|
| ... | ... | @@ -39,6 +39,7 @@ import System.Exit |
| 39 | 39 | import System.IO
|
| 40 | 40 | |
| 41 | 41 | import Control.Concurrent
|
| 42 | +import Control.Monad.STM
|
|
| 42 | 43 | import GHCi.Message.Async (runWriteReply, (%>>=))
|
| 43 | 44 | import GHCi.Server.Threads
|
| 44 | 45 | |
| ... | ... | @@ -66,13 +67,13 @@ servWithCustom |
| 66 | 67 | -> IO ()
|
| 67 | 68 | servWithCustom verbose hook pipe restore customHandler = do
|
| 68 | 69 | ref <- newIORef False
|
| 69 | - withThreadManager $ \mngr ->
|
|
| 70 | + withThreadManager $ \mngr -> do
|
|
| 70 | 71 | loop ref mngr `finally` closePipe pipe
|
| 71 | 72 | where
|
| 72 | 73 | loop doneRef mngr = do
|
| 73 | 74 | when verbose $ trace "reading pipe..."
|
| 74 | 75 | |
| 75 | - handleRemoteCall pipe hook $ \wr (msg :: Message a) ->
|
|
| 76 | + handleRemoteCall pipe hook $ \wr setCancel (msg :: Message a) ->
|
|
| 76 | 77 | |
| 77 | 78 | discardCtrlC %>>= \_ ->
|
| 78 | 79 | when verbose (trace ("msg: " ++ (show msg))) %>>= \_ ->
|
| ... | ... | @@ -83,8 +84,10 @@ servWithCustom verbose hook pipe restore customHandler = do |
| 83 | 84 | reply () %>>= writeReply wr
|
| 84 | 85 | RunTH ii st q ty loc -> spawnFinally mngr (runWriteReply wr)
|
| 85 | 86 | (wrapRunTH ii (runTH pipe ii st q ty loc))
|
| 87 | + (setCancel . void . forkIO . killThread)
|
|
| 86 | 88 | RunModFinalizers ii st qs -> spawnFinally mngr (runWriteReply wr)
|
| 87 | 89 | (wrapRunTH ii (runModFinalizerRefs pipe ii st qs))
|
| 90 | + (setCancel . void . forkIO . killThread)
|
|
| 88 | 91 | _other -> run msg >>= reply %>>= writeReply wr
|
| 89 | 92 | |
| 90 | 93 | isDone <- readIORef doneRef
|
| ... | ... | @@ -41,8 +41,8 @@ withThreadManager k = do |
| 41 | 41 | |
| 42 | 42 | -- | Linear and resource-safe because 'ThreadManager' is guaranteed to wait or
|
| 43 | 43 | -- cancel all threads.
|
| 44 | -spawnFinally :: ThreadManager -> (Either SomeException a -> IO ()) %1 -> IO a -> IO ()
|
|
| 45 | -spawnFinally ThreadManager{..} = unsafe_linear \fin -> \action -> void $
|
|
| 44 | +spawnFinally :: ThreadManager -> (Either SomeException a -> IO ()) %1 -> IO a -> (ThreadId -> IO b) -> IO b
|
|
| 45 | +spawnFinally ThreadManager{..} = unsafe_linear \fin -> \action -> \k ->
|
|
| 46 | 46 | forkFinally
|
| 47 | 47 | ( mask $ \unmask -> do
|
| 48 | 48 | tid <- myThreadId
|
| ... | ... | @@ -57,6 +57,7 @@ spawnFinally ThreadManager{..} = unsafe_linear \fin -> \action -> void $ |
| 57 | 57 | else throwIO ThreadKilled
|
| 58 | 58 | )
|
| 59 | 59 | ( \ea -> fin ea )
|
| 60 | + >>= k
|
|
| 60 | 61 | |
| 61 | 62 | unsafe_linear :: (a -> b) %1 -> (a %1 -> b)
|
| 62 | 63 | unsafe_linear = Unsafe.unsafeCoerce (Unsafe.unsafeCoerce :: (a -> b) -> (a %1 -> b)) |
| ... | ... | @@ -3,10 +3,20 @@ include $(TOP)/mk/boilerplate.mk |
| 3 | 3 | include $(TOP)/mk/test.mk
|
| 4 | 4 | |
| 5 | 5 | # Test that threadDelay can be interrupted by ^C.
|
| 6 | -T3171:
|
|
| 7 | - echo "do Control.Concurrent.threadDelay 3000000; putStrLn \"threadDelay was not interrupted\"" | \
|
|
| 8 | - "$(TEST_HC)" $(TEST_HC_OPTS_INTERACTIVE) & \
|
|
| 9 | - sleep 2; kill -INT $$!; wait
|
|
| 6 | +# Wait for the statement to start before interrupting (#15383), and signal
|
|
| 7 | +# the external interpreter too (the `pgrep -P $!`), as ^C in a terminal would.
|
|
| 8 | +#
|
|
| 9 | +# The ext interp tests both:
|
|
| 10 | +# - interrupting a remote request doesn't terminate the ext interpreter (#18852)
|
|
| 11 | +# - a ^C gets propagated to the thread evaluating the user request on the ext
|
|
| 12 | +# interpreter so that it gets interrupted
|
|
| 13 | +T3171ext: T3171_OPTS = -fexternal-interpreter
|
|
| 14 | +T3171 T3171ext:
|
|
| 15 | + rm -f $@.started
|
|
| 16 | + echo 'do { writeFile "$@.started" ""; (Control.Concurrent.threadDelay 100000000 >> putStrLn "threadDelay was not interrupted.") `Control.Exception.catch` \(e :: Control.Exception.SomeException) -> System.IO.hPutStrLn System.IO.stderr ("threadDelay was interrupted: " ++ show e) >> Control.Exception.throwIO e }' | \
|
|
| 17 | + "$(TEST_HC)" $(TEST_HC_OPTS_INTERACTIVE) $(T3171_OPTS) & \
|
|
| 18 | + while [ ! -e $@.started ] && kill -0 $$! 2>/dev/null; do sleep 0.1; done; \
|
|
| 19 | + kill -INT $$! $$(pgrep -P $$!); wait
|
|
| 10 | 20 | |
| 11 | 21 | TopEnvIface:
|
| 12 | 22 | "$(TEST_HC)" $(TEST_HC_OPTS_INTERACTIVE) TopEnvIface -v1 -fno-hide-source-paths -e "a" -e ":q" -fwrite-if-simplified-core -fwrite-interface
|
| 1 | +threadDelay was interrupted: user interrupt
|
|
| 1 | 2 | Interrupted. |
| 1 | +threadDelay was interrupted: user interrupt
|
|
| 2 | +Interrupted. |
| ... | ... | @@ -12,11 +12,17 @@ test('T27287', [just_ghci, combined_output], makefile_test, []) |
| 12 | 12 | |
| 13 | 13 | test('T3171',
|
| 14 | 14 | [when(opsys('mingw32'),skip),
|
| 15 | - fragile(15383),
|
|
| 16 | 15 | req_interp,
|
| 17 | 16 | combined_output],
|
| 18 | 17 | makefile_test, [])
|
| 19 | 18 | |
| 19 | +test('T3171ext',
|
|
| 20 | + [when(opsys('mingw32'),skip),
|
|
| 21 | + req_interp,
|
|
| 22 | + unless(config.have_ext_interp, skip),
|
|
| 23 | + combined_output],
|
|
| 24 | + makefile_test, [])
|
|
| 25 | + |
|
| 20 | 26 | test('ghcirun004', just_ghci, compile_and_run, [''])
|
| 21 | 27 | test('T8377', just_ghci, compile_and_run, [''])
|
| 22 | 28 | test('T9914', just_ghci, ghci_script, ['T9914.script'])
|