summaryrefslogtreecommitdiff
path: root/libraries
diff options
context:
space:
mode:
authorRyanGlScott <ryan.gl.scott@gmail.com>2016-02-12 09:24:38 -0500
committerRyanGlScott <ryan.gl.scott@gmail.com>2016-02-12 09:24:49 -0500
commitbe3d7f661968a7b8c6751c0be3bf23e703b32c3e (patch)
treed32fea604192a2c6e6f5a402f79a982f8ee17f32 /libraries
parent8da6a162416d448309ced16b00f54a32b5ee750b (diff)
downloadhaskell-be3d7f661968a7b8c6751c0be3bf23e703b32c3e.tar.gz
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
Diffstat (limited to 'libraries')
-rw-r--r--libraries/base/GHC/Exception.hs4
-rwxr-xr-xlibraries/base/GHC/Exts.hs9
-rw-r--r--libraries/base/GHC/Show.hs3
-rw-r--r--libraries/base/GHC/Stack.hs4
-rw-r--r--libraries/base/GHC/Stack/Types.hs9
-rw-r--r--libraries/base/changelog.md9
6 files changed, 32 insertions, 6 deletions
diff --git a/libraries/base/GHC/Exception.hs b/libraries/base/GHC/Exception.hs
index ad50cec3ba..be9e6f956c 100644
--- a/libraries/base/GHC/Exception.hs
+++ b/libraries/base/GHC/Exception.hs
@@ -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
diff --git a/libraries/base/GHC/Exts.hs b/libraries/base/GHC/Exts.hs
index dc943e068d..31e70ebd21 100755
--- a/libraries/base/GHC/Exts.hs
+++ b/libraries/base/GHC/Exts.hs
@@ -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
diff --git a/libraries/base/GHC/Show.hs b/libraries/base/GHC/Show.hs
index a3807bbf32..72a73200b5 100644
--- a/libraries/base/GHC/Show.hs
+++ b/libraries/base/GHC/Show.hs
@@ -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
--------------------------------------------------------------
diff --git a/libraries/base/GHC/Stack.hs b/libraries/base/GHC/Stack.hs
index 477dcdc505..5f2034e2d2 100644
--- a/libraries/base/GHC/Stack.hs
+++ b/libraries/base/GHC/Stack.hs
@@ -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,
diff --git a/libraries/base/GHC/Stack/Types.hs b/libraries/base/GHC/Stack/Types.hs
index 35dfcb0a33..1fead13051 100644
--- a/libraries/base/GHC/Stack/Types.hs
+++ b/libraries/base/GHC/Stack/Types.hs
@@ -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]
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
diff --git a/libraries/base/changelog.md b/libraries/base/changelog.md
index 7f85f35a46..7f2f2d3e42 100644
--- a/libraries/base/changelog.md
+++ b/libraries/base/changelog.md
@@ -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`