[Git][ghc/ghc][wip/exception-context-prereqs] base: Use displayException in top-level exception handler
Ben Gamari (@bgamari)
gitlab at gitlab.haskell.org
Mon Feb 19 19:42:32 UTC 2024
Ben Gamari pushed to branch wip/exception-context-prereqs at Glasgow Haskell Compiler / GHC
Commits:
57a5ca79 by Ben Gamari at 2024-02-19T14:42:24-05:00
base: Use displayException in top-level exception handler
Happily this also allows us to eliminate a special case for Deadlock
exceptions.
Implements [CLC #198](https://github.com/haskell/core-libraries-committee/issues/198).
- - - - -
3 changed files:
- libraries/base/changelog.md
- libraries/ghc-internal/src/GHC/Conc/Sync.hs
- libraries/ghc-internal/src/GHC/IO/Exception.hs
Changes:
=====================================
libraries/base/changelog.md
=====================================
@@ -2,6 +2,7 @@
## 4.20.0.0 *TBA*
* Export `foldl'` from `Prelude` ([CLC proposal #167](https://github.com/haskell/core-libraries-committee/issues/167))
+ * The top-level handler for uncaught exceptions now displays the output of `displayException` rather than `show` ([CLC proposal #198](https://github.com/haskell/core-libraries-committee/issues/198))
* Add `permutations` and `permutations1` to `Data.List.NonEmpty` ([CLC proposal #68](https://github.com/haskell/core-libraries-committee/issues/68))
* Add a `RULE` to `Prelude.lookup`, allowing it to participate in list fusion ([CLC proposal #175](https://github.com/haskell/core-libraries-committee/issues/175))
* Implement `stimes` for `instance Semigroup (Endo a)` explicitly ([CLC proposal #4](https://github.com/haskell/core-libraries-committee/issues/4))
=====================================
libraries/ghc-internal/src/GHC/Conc/Sync.hs
=====================================
@@ -107,7 +107,6 @@ module GHC.Conc.Sync
import Foreign
import Foreign.C
-import Data.Typeable
import Data.Maybe
import GHC.Base
@@ -948,11 +947,9 @@ uncaughtExceptionHandler :: IORef (SomeException -> IO ())
uncaughtExceptionHandler = unsafePerformIO (newIORef defaultHandler)
where
defaultHandler :: SomeException -> IO ()
- defaultHandler se@(SomeException ex) = do
+ defaultHandler se = do
(hFlush stdout) `catchAny` (\ _ -> return ())
- let msg = case cast ex of
- Just Deadlock -> "no threads to run: infinite loop or deadlock?"
- _ -> showsPrec 0 se ""
+ let msg = displayException se
withCString "%s" $ \cfmt ->
withCString msg $ \cmsg ->
errorBelch cfmt cmsg
=====================================
libraries/ghc-internal/src/GHC/IO/Exception.hs
=====================================
@@ -105,7 +105,8 @@ blockedIndefinitelyOnSTM = toException BlockedIndefinitelyOnSTM
data Deadlock = Deadlock
-- | @since 4.1.0.0
-instance Exception Deadlock
+instance Exception Deadlock where
+ displayException _ = "no threads to run: infinite loop or deadlock?"
-- | @since 4.1.0.0
instance Show Deadlock where
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/57a5ca79933a498e4089f031a2f119f54f64b6f6
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/57a5ca79933a498e4089f031a2f119f54f64b6f6
You're receiving this email because of your account on gitlab.haskell.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20240219/7fe0ec04/attachment-0001.html>
More information about the ghc-commits
mailing list