Commit be3d7f66 authored by Ryan Scott's avatar Ryan Scott
Browse files

Add IsList instance for CallStack, restore Show instance for CallStack

Summary:
Ties up loose ends from D1894.

GHC 7.10.2 and 7.10.3 featured a `Show` instance for `CallStack`, but since it
was derived, it broke encapsulation. This adds a `Show` instance which displays
the `CallStack` as if it were a `[(String, SrcLoc)]`.

To ensure that the output of `Show` is technically a valid Haskell term, we
also add a corresponding `IsList CallStack` instance.

Reviewers: gridaphobe, austin, hvr, bgamari

Reviewed By: gridaphobe, bgamari

Subscribers: thomie

Differential Revision: https://phabricator.haskell.org/D1903
parent 8da6a162
......@@ -28,8 +28,8 @@ module GHC.Exception
, divZeroException, overflowException, ratioZeroDenomException
, errorCallException, errorCallWithCallStackException
-- re-export CallStack and SrcLoc from GHC.Types
, CallStack, getCallStack, prettyCallStack, prettyCallStackLines
, showCCSStack
, CallStack, fromCallSiteList, getCallStack, prettyCallStack
, prettyCallStackLines, showCCSStack
, SrcLoc(..), prettySrcLoc
) where
......
......@@ -191,3 +191,12 @@ instance IsList Version where
type (Item Version) = Int
fromList = makeVersion
toList = versionBranch
-- | Be aware that 'fromList . toList = id' only for unfrozen 'CallStack's,
-- since 'toList' removes frozenness information.
--
-- @since 4.9.0.0
instance IsList CallStack where
type (Item CallStack) = (String, SrcLoc)
fromList = fromCallSiteList
toList = getCallStack
......@@ -205,6 +205,9 @@ instance Show TrName where
instance Show Module where
showsPrec _ (Module p m) = shows p . (':' :) . shows m
instance Show CallStack where
showsPrec _ = shows . getCallStack
deriving instance Show SrcLoc
--------------------------------------------------------------
......
......@@ -25,8 +25,8 @@ module GHC.Stack (
-- * HasCallStack call stacks
CallStack, HasCallStack, callStack, emptyCallStack, freezeCallStack,
getCallStack, popCallStack, prettyCallStack, pushCallStack,
withFrozenCallStack,
fromCallSiteList, getCallStack, popCallStack, prettyCallStack,
pushCallStack, withFrozenCallStack,
-- * Source locations
SrcLoc(..), prettySrcLoc,
......
......@@ -28,7 +28,8 @@
module GHC.Stack.Types (
-- * Implicit call stacks
CallStack(..), HasCallStack,
emptyCallStack, freezeCallStack, getCallStack, pushCallStack,
emptyCallStack, freezeCallStack, fromCallSiteList,
getCallStack, pushCallStack,
-- * Source locations
SrcLoc(..)
......@@ -148,6 +149,12 @@ getCallStack stk = case stk of
PushCallStack cs stk' -> cs : getCallStack stk'
FreezeCallStack stk' -> getCallStack stk'
-- | Convert a list of call-sites to a 'CallStack'.
--
-- @since 4.9.0.0
fromCallSiteList :: [([Char], SrcLoc)] -> CallStack
fromCallSiteList (c:cs) = PushCallStack c (fromCallSiteList cs)
fromCallSiteList [] = EmptyCallStack
-- Note [Definition of CallStack]
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
......
......@@ -13,7 +13,9 @@
* New `GHC.Generics.packageName` operation
* New `GHC.Stack.CallStack` data type
* Redesigned `GHC.Stack.CallStack` data type. As a result, `CallStack`'s
`Show` instance produces different output, and `CallStack` no longer has an
`Eq` instance.
* New `GHC.Generics.packageName` operation
......@@ -26,6 +28,9 @@
* New `GHC.Stack.Types.pushCallStack` function pushes a call-site onto a `CallStack`
* New `GHC.Stack.Types.fromCallSiteList` function creates a `CallStack` from
a list of call-sites (i.e., `[(String, SrcLoc)]`)
* `GHC.SrcLoc` has been removed
* `GHC.Stack.showCallStack` and `GHC.SrcLoc.showSrcLoc` are now called
......@@ -133,6 +138,8 @@
* Add `MonadPlus IO` and `Alternative IO` instances
(previously orphans in `transformers`) (#10755)
* `CallStack` now has an `IsList` instance
### Generalizations
* Generalize `Debug.Trace.{traceM, traceShowM}` from `Monad` to `Applicative`
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment