Skip to content
Snippets Groups Projects
  • parsonsmatt's avatar
    88814cf9
    Add `HasCallStack` to classes and functions (#90) · 88814cf9
    parsonsmatt authored
    * Add `HasCallStack` to classes and functions
    
    This PR adds `HasCallStack` constraints to the class methods on this library. This allows for callsites to be populated with interesting information. 
    
    The primary use case I can imagine here is supporting [`annotated-exception`](https://hackage.haskell.org/package/annotated-exception-0.2.0.4/docs/Control-Exception-Annotated.html), and allowing you to define an instance of `MonadThrow` that always annotates with callstack:
    
    ```haskell
    instance MonadThrow AppM where
        throwM = throwWithCallStack
    ```
    
    With this, anything that uses `throwM` at the `AppM` type gets a call stack on the attached exception.
    
    While this only benefits users of `annotated-exception` currently, when the GHC proposal to [decorate all exceptions with backtrace information](https://github.com/ghc-proposals/ghc-proposals/pull/330
    
    ) is implemented, then everyone benefits from this.
    
    Without this constraint, the `CallStack` used by the above instance points to the instance definition site - not terribly useful.
    
    * Use call-stack for backwards compatibility
    
    * Only depend on call-stack if using an old GHC version
    
    `exceptions` is a GHC boot package, so we want to make sure that it does not
    incur any external depedencies when using a recent GHC version.
    
    * Enable FlexibleContexts for the benefit of older GHCs
    
    Older versions of GHC require `FlexibleContexts` to use `call-stack`'s
    `type HasCallStack = (?callStack :: CallStack)` compatibility shim.
    
    * Drop support for GHC 7.0 and 7.2
    
    `call-stack`'s `HasCallStack` compatibility shim only supports back to GHC 7.4.
    As a result, we can't reasonably support GHC 7.0 and 7.2 in `exceptions`
    without a fair bit of grimy CPP. That being said, GHC 7.0 and 7.2 are quite
    ancient by this point, so I'm comfortable with simply dropping support for
    them. This patch makes the necessary `.cabal` and CI changes to accomplish that.
    
    * Enable ConstraintKinds for the benefit of older GHCs
    
    Older versions of GHC require `ConstraintKinds` to use `call-stack`'s
    `type HasCallStack = (?callStack :: CallStack)` compatibility shim.
    
    * Add withFrozenCallStack where possible
    
    * withFrozenCallStack fix for old GHC
    
    * freeze masks
    
    Co-authored-by: default avatarRyan Scott <ryan.gl.scott@gmail.com>
    Add `HasCallStack` to classes and functions (#90)
    parsonsmatt authored
    * Add `HasCallStack` to classes and functions
    
    This PR adds `HasCallStack` constraints to the class methods on this library. This allows for callsites to be populated with interesting information. 
    
    The primary use case I can imagine here is supporting [`annotated-exception`](https://hackage.haskell.org/package/annotated-exception-0.2.0.4/docs/Control-Exception-Annotated.html), and allowing you to define an instance of `MonadThrow` that always annotates with callstack:
    
    ```haskell
    instance MonadThrow AppM where
        throwM = throwWithCallStack
    ```
    
    With this, anything that uses `throwM` at the `AppM` type gets a call stack on the attached exception.
    
    While this only benefits users of `annotated-exception` currently, when the GHC proposal to [decorate all exceptions with backtrace information](https://github.com/ghc-proposals/ghc-proposals/pull/330
    
    ) is implemented, then everyone benefits from this.
    
    Without this constraint, the `CallStack` used by the above instance points to the instance definition site - not terribly useful.
    
    * Use call-stack for backwards compatibility
    
    * Only depend on call-stack if using an old GHC version
    
    `exceptions` is a GHC boot package, so we want to make sure that it does not
    incur any external depedencies when using a recent GHC version.
    
    * Enable FlexibleContexts for the benefit of older GHCs
    
    Older versions of GHC require `FlexibleContexts` to use `call-stack`'s
    `type HasCallStack = (?callStack :: CallStack)` compatibility shim.
    
    * Drop support for GHC 7.0 and 7.2
    
    `call-stack`'s `HasCallStack` compatibility shim only supports back to GHC 7.4.
    As a result, we can't reasonably support GHC 7.0 and 7.2 in `exceptions`
    without a fair bit of grimy CPP. That being said, GHC 7.0 and 7.2 are quite
    ancient by this point, so I'm comfortable with simply dropping support for
    them. This patch makes the necessary `.cabal` and CI changes to accomplish that.
    
    * Enable ConstraintKinds for the benefit of older GHCs
    
    Older versions of GHC require `ConstraintKinds` to use `call-stack`'s
    `type HasCallStack = (?callStack :: CallStack)` compatibility shim.
    
    * Add withFrozenCallStack where possible
    
    * withFrozenCallStack fix for old GHC
    
    * freeze masks
    
    Co-authored-by: default avatarRyan Scott <ryan.gl.scott@gmail.com>
Code owners
Assign users and groups as approvers for specific file changes. Learn more.