[commit: ghc] ghc-8.0: Add IsList instance for CallStack, restore Show instance for CallStack (80beb40)

git at git.haskell.org git at git.haskell.org
Thu Feb 18 12:02:44 UTC 2016


Repository : ssh://git@git.haskell.org/ghc

On branch  : ghc-8.0
Link       : http://ghc.haskell.org/trac/ghc/changeset/80beb40ed79b2941189f07ae6164e535003f9bf5/ghc

>---------------------------------------------------------------

commit 80beb40ed79b2941189f07ae6164e535003f9bf5
Author: RyanGlScott <ryan.gl.scott at gmail.com>
Date:   Fri Feb 12 09:24:38 2016 -0500

    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
    
    (cherry picked from commit be3d7f661968a7b8c6751c0be3bf23e703b32c3e)


>---------------------------------------------------------------

80beb40ed79b2941189f07ae6164e535003f9bf5
 libraries/base/GHC/Exception.hs   | 4 ++--
 libraries/base/GHC/Exts.hs        | 9 +++++++++
 libraries/base/GHC/Show.hs        | 3 +++
 libraries/base/GHC/Stack.hs       | 4 ++--
 libraries/base/GHC/Stack/Types.hs | 9 ++++++++-
 libraries/base/changelog.md       | 9 ++++++++-
 6 files changed, 32 insertions(+), 6 deletions(-)

diff --git a/libraries/base/GHC/Exception.hs b/libraries/base/GHC/Exception.hs
index ad50cec..be9e6f9 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 dc943e0..31e70eb 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 a3807bb..72a7320 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 477dcdc..5f2034e 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 35dfcb0..1fead13 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 7f85f35..7f2f2d3 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`



More information about the ghc-commits mailing list