sheaf pushed to branch wip/T27455 at Glasgow Haskell Compiler / GHC

Commits:

4 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
    ... ... @@ -33,6 +33,7 @@
    33 33
       * Evaluate backtraces for "error" exceptions at the moment they are thrown. ([CLC proposal #383](https://github.com/haskell/core-libraries-committee/issues/383))
    
    34 34
       * Hide implementation details when throwing exceptions in throw and throwSTM. ([CLC proposal #387](https://github.com/haskell/core-libraries-committee/issues/387))
    
    35 35
       * 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))
    
    36
    +  * 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).
    
    36 37
       * Annotate `onException` continuation with `WhileHandling`. ([CLC Proposal #397](https://github.com/haskell/core-libraries-committee/issues/397))
    
    37 38
       * Improve error message for `Data.Char.chr`. ([CLC Proposal #384](https://github.com/haskell/core-libraries-committee/issues/384))
    
    38 39
     
    

  • 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
    +    --     then 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_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
    +