[commit: packages/deepseq] master: Add instances for SrcLoc and CallStack (9454c1b)

git at git.haskell.org git at git.haskell.org
Wed Apr 20 13:05:25 UTC 2016


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

On branch  : master
Link       : http://git.haskell.org/packages/deepseq.git/commitdiff/9454c1b4fb0ead5904858d675c2cdafa62a3ebab

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

commit 9454c1b4fb0ead5904858d675c2cdafa62a3ebab
Author: Herbert Valerio Riedel <hvr at gnu.org>
Date:   Tue Apr 19 18:40:53 2016 +0200

    Add instances for SrcLoc and CallStack


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

9454c1b4fb0ead5904858d675c2cdafa62a3ebab
 Control/DeepSeq.hs | 39 +++++++++++++++++++++++++++++++++++++++
 changelog.md       |  2 ++
 2 files changed, 41 insertions(+)

diff --git a/Control/DeepSeq.hs b/Control/DeepSeq.hs
index 49bac36..314d0a9 100644
--- a/Control/DeepSeq.hs
+++ b/Control/DeepSeq.hs
@@ -98,6 +98,13 @@ import Data.List.NonEmpty ( NonEmpty (..) )
 import Data.Semigroup as Semi
 #endif
 
+#if MIN_VERSION_base(4,9,0)
+import GHC.Stack.Types ( CallStack(..), SrcLoc(..) )
+#elif MIN_VERSION_base(4,8,1)
+import GHC.Stack ( CallStack(..) )
+import GHC.SrcLoc ( SrcLoc(..) )
+#endif
+
 #if __GLASGOW_HASKELL__ >= 702
 import GHC.Fingerprint.Type ( Fingerprint(..) )
 import GHC.Generics
@@ -595,6 +602,38 @@ instance NFData a => NFData (Option a) where
 #endif
 
 ----------------------------------------------------------------------------
+-- GHC.Stack
+
+#if MIN_VERSION_base(4,9,0)
+-- |@since 1.4.2.0
+instance NFData SrcLoc where
+  rnf (SrcLoc a b c d e f g) = rnf a `seq` rnf b `seq` rnf c `seq`
+                               rnf d `seq` rnf e `seq` rnf f `seq` rnf g
+
+-- |@since 1.4.2.0
+instance NFData CallStack where
+  rnf EmptyCallStack = ()
+  rnf (PushCallStack a b c) = rnf a `seq` rnf b `seq` rnf c
+  rnf (FreezeCallStack a)   = rnf a
+
+#elif MIN_VERSION_base(4,8,1)
+-- |@since 1.4.2.0
+instance NFData SrcLoc where
+  -- base-4.8 didn't expose the 'SrcLoc' constructor
+  rnf sl = rnf (srcLocPackage   sl) `seq`
+           rnf (srcLocModule    sl) `seq`
+           rnf (srcLocFile      sl) `seq`
+           rnf (srcLocStartLine sl) `seq`
+           rnf (srcLocStartCol  sl) `seq`
+           rnf (srcLocEndLine   sl) `seq`
+           rnf (srcLocEndCol    sl)
+
+-- |@since 1.4.2.0
+instance NFData CallStack where
+  rnf = rnf . getCallStack
+#endif
+
+----------------------------------------------------------------------------
 -- Tuples
 
 instance (NFData a, NFData b) => NFData (a,b) where
diff --git a/changelog.md b/changelog.md
index c412fe0..1403152 100644
--- a/changelog.md
+++ b/changelog.md
@@ -18,6 +18,8 @@
   * Added instance for `ExitCode`
     ([#4](https://github.com/haskell/deepseq/issues/4))
 
+  * Added instances for `CallStack` and `SrcLoc`
+
   * Make `NFData (Proxy a)` instance poly-kinded
 
 ## 1.4.1.2  *Aug 2015*



More information about the ghc-commits mailing list