`StackAnnotation` should have optional `SrcLoc`s attached
## Summary
When adding support for `StackAnnotation`, we initially chose what we thought was the most flexible interface:
```haskell
-- | 'StackAnnotation's are types which can be pushed onto the call stack
-- as the payload of 'AnnFrame' stack frames.
--
class StackAnnotation a where
displayStackAnnotation :: a -> String
```
A `String` is the only common representation that any `StackAnnotation` can be transformed into.
When adding support for `StackAnnotation` to `ghc-debugger`, we noticed that the fundamental lack of `SrcLoc`s attached to `StackAnnotation` seriously hinders its usability.
Without a source location, the shown `StackAnnotation` just floats in the backtrace.
Further, this issue reflects in the IPE backtrace when an exception is thrown by default:
```
IPE backtrace:
Lovely annotation
[1,2,3,4]
annotateCallStack, called at T26806b.hs:14:3 in main:Main
```
The lack of source locations makes the backtrace less useful, potentially.
Instead, by default, it would be much nicer if the stack trace looked like:
```
IPE backtrace:
Lovely annotation, called at T26806a.hs:12:7 in main:Main
[1,2,3,4], called at T26806a.hs:11:5 in main:Main
annotateCallStackIO, called at T26806a.hs:10:3 in main:Main
```
## Proposal
We extend the `StackAnnotation` type class to let the consumer of `StackAnnotation` to have more control and more information about the annotation.
We propose to change `StackAnnotation` to look like:
```haskell
-- | 'StackAnnotation's are types which can be pushed onto the call stack
-- as the payload of 'AnnFrame' stack frames.
--
class StackAnnotation a where
displayStackAnnotation :: a -> String
sourceLocationOfStackAnnotation :: a -> Maybe SrcLoc
displayStackAnnotationShort :: a -> String
{-# MINIMAL displayStackAnnotation | displayStackAnnotationShort #-}
displayStackAnnotation ann =
displayStackAnnotationShort ann
++ case sourceLocationOfStackAnnotation ann of
Nothing -> ""
Just srcLoc -> ", called at " ++ prettySrcLoc srcLoc
sourceLocationOfStackAnnotation _ann = Nothing
displayStackAnnotationShort = displayStackAnnotation
```
This is backwards compatible for early adopters of the feature, but gives us (GHC devs, [`ghc-debugger`](https://github.com/well-typed/haskell-debugger) and [`ghc-stack-profiler`](https://github.com/well-typed/ghc-stack-profiler)) direct access to source locations.
Further, the types `StringAnnotation` and `ShowAnnotation` are extended to also hold an `Maybe SrcLoc`, which improves backtraces by default for GHC end users (that use `StackAnnotation`s) as well.
issue