Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC

Commits:

5 changed files:

Changes:

  • changelog.d/T27455
    1
    +section: base
    
    2
    +issues: #27455
    
    3
    +mrs: !16274
    
    4
    +synopsis:
    
    5
    +  Don't drop `ExceptionContext` in `SomeException(toException)`
    
    6
    +description:
    
    7
    +  Previously the implementation of ``Exception(toException)`` given to `SomeException` would inappropriately drop the carried `ExceptionContext`. Now ``toException = id``, faithfully implementing the semantics proposed in :ref:`CLC Proposal #200 <https://github.com/haskell/core-libraries-committee/issues/200>`.
    
    8
    +

  • libraries/base/changelog.md
    ... ... @@ -38,6 +38,7 @@
    38 38
       * Show `ExceptionContext` in `displayExceptionAnnotation` implementation of `WhileHandling` ([GHC #27456](https://gitlab.haskell.org/ghc/ghc/-/issues/27456))
    
    39 39
       * Hide implementation details when throwing exceptions in throw and throwSTM. ([CLC proposal #387](https://github.com/haskell/core-libraries-committee/issues/387))
    
    40 40
       * Change `hIsReadable` and `hIsWritable` such that they always throw a respective exception when encountering a closed or semi-closed handle, not just in the case of a file handle. ([CLC proposal #371](github.com/haskell/core-libraries-committee/issues/371))
    
    41
    +  * The implementation of `toException` in `SomeException`'s `Exception` instance no longer drops exception context, in keeping with the behavior originally proposed in [CLC Proposal #200](https://github.com/haskell/core-libraries-committee/issues/200).
    
    41 42
       * Annotate `onException` continuation with `WhileHandling`. ([CLC Proposal #397](https://github.com/haskell/core-libraries-committee/issues/397))
    
    42 43
       * Improve error message for `Data.Char.chr`. ([CLC Proposal #384](https://github.com/haskell/core-libraries-committee/issues/384))
    
    43 44
     
    

  • libraries/ghc-internal/src/GHC/Internal/Exception/Type.hs
    ... ... @@ -55,7 +55,7 @@ import GHC.Internal.Data.Maybe
    55 55
     import GHC.Internal.Data.Typeable (Typeable, TypeRep, cast)
    
    56 56
     import qualified GHC.Internal.Data.Typeable as Typeable
    
    57 57
        -- loop: GHC.Internal.Data.Typeable -> GHC.Internal.Err -> GHC.Internal.Exception
    
    58
    -import GHC.Internal.Base (String, Void, fmap, return, ($), (.), (++))
    
    58
    +import GHC.Internal.Base (String, Void, fmap, return, ($), (.), (++), id)
    
    59 59
     import GHC.Internal.Show
    
    60 60
     import GHC.Internal.Types (Bool(..))
    
    61 61
     import GHC.Internal.Exception.Context
    
    ... ... @@ -208,7 +208,16 @@ Caught MismatchedParentheses
    208 208
     
    
    209 209
     -}
    
    210 210
     class (Typeable e, Show e) => Exception e where
    
    211
    -    -- | @toException@ should produce a 'SomeException' with no attached 'ExceptionContext'.
    
    211
    +    -- | 'toException' converts an exception into the existential 'SomeException'
    
    212
    +    -- wrapper type.
    
    213
    +    --
    
    214
    +    -- In doing so, 'toException' should not /add/ an 'ExceptionContext'.
    
    215
    +    --
    
    216
    +    --   - In most cases, the exception does not store its own 'ExceptionContext'.
    
    217
    +    --     The default implementation of 'toException' (which does not store any
    
    218
    +    --     'ExceptionContext') is suitable for these cases.
    
    219
    +    --   - In the rare case that the exception itself stores an 'ExceptionContext',
    
    220
    +    --     this context should be preserved by 'toException'.
    
    212 221
         toException   :: e -> SomeException
    
    213 222
         fromException :: SomeException -> Maybe e
    
    214 223
     
    
    ... ... @@ -231,13 +240,11 @@ class (Typeable e, Show e) => Exception e where
    231 240
     -- | @since base-4.8.0.0
    
    232 241
     instance Exception Void
    
    233 242
     
    
    234
    --- | This drops any attached 'ExceptionContext'.
    
    243
    +-- | NB: this instance preserves the attached 'ExceptionContext'.
    
    235 244
     --
    
    236 245
     -- @since base-3.0
    
    237 246
     instance Exception SomeException where
    
    238
    -    toException (SomeException e) =
    
    239
    -        let ?exceptionContext = emptyExceptionContext
    
    240
    -        in SomeException e
    
    247
    +    toException = id
    
    241 248
         fromException = Just
    
    242 249
         backtraceDesired (SomeException e) = backtraceDesired e
    
    243 250
         displayException (SomeException e) = displayException e
    

  • testsuite/tests/ghc-e/should_fail/T18441fail7.stderr
    ... ... @@ -5,8 +5,12 @@ IO error: "Abcde" does not exist
    5 5
     While handling ghc-10.1-inplace:GHC.Utils.Panic.GhcException:
    
    6 6
       |
    
    7 7
       | IO error:  "Abcde" does not exist
    
    8
    +  |
    
    9
    +  | HasCallStack backtrace:
    
    10
    +  |   throw, called at compiler/GHC/Utils/Panic.hs:180:21 in ghc-10.1-inplace:GHC.Utils.Panic
    
    11
    +  |   throwGhcException, called at ghc/GHCi/UI.hs:2851:21 in ghc-bin-10.1.20260801-inplace:GHCi.UI
    
    8 12
     
    
    9 13
     HasCallStack backtrace:
    
    10
    -  throwIO, called at compiler\GHC\Utils\Error.hs:499:19 in ghc-10.1-inplace:GHC.Utils.Error
    
    14
    +  throwIO, called at compiler/GHC/Utils/Error.hs:513:19 in ghc-10.1-inplace:GHC.Utils.Error
    
    11 15
     
    
    12 16
     1

  • testsuite/tests/ghc-e/should_run/ghc-e005.stderr
    ... ... @@ -4,3 +4,8 @@ foo
    4 4
     
    
    5 5
     HasCallStack backtrace:
    
    6 6
       error, called at ghc-e005.hs:12:10 in main:Main
    
    7
    +
    
    8
    +
    
    9
    +HasCallStack backtrace:
    
    10
    +  throwIO, called at ghc\GHCi\UI.hs:1655:31 in ghc-bin-10.1.20260629-inplace:GHCi.UI
    
    11
    +