packages feed

deepseq-magic (empty) → 1.0.0.0

raw patch · 3 files changed

+69/−0 lines, 3 filesdep +basesetup-changed

Dependencies added: base

Files

+ Control/DeepSeq/Magic.hs view
@@ -0,0 +1,50 @@+{-# LANGUAGE BangPatterns, MagicHash, UnboxedTuples #-}+module Control.DeepSeq.Magic where+-----------------------------------------------------------------------------+-- |+-- Module      :  Control.DeepSeq.Magic+-- Copyright   :  Public Domain+-- License     :  Public Domain+--+-- Maintainer  :  ezyang@cs.stanford.edu+-- Stability   :  stable+-- Portability :  portable+--+-- The functions in this module are exactly the same as+-- 'Control.DeepSeq', but without the need for an 'NFData' instance.+--+-- The semantics are not terribly well defined, since they are based on+-- what 'unpackClosure#' returns in its pointer list, but it appears+-- that we NEVER recurse into AP or PAP objects.++import GHC.Exts++-- NOTE: This is a bit slower than a normal NFData instance+-- because unpackClosure# has to allocate arrays to report+-- the results.  I tried writing a hand-rolled loop but it+-- was tricky. If this is a bottleneck I'll try again.+--+-- NOTE: Thankfully, unpackClosure# doesn't look through+-- thunks/function closures, so this behavior is actually+-- somewhat reasonable.+rnf :: a -> ()+rnf a = a `seq` rest `seq` () where+    rest = case unpackClosure# a of+            (# _, ptrs#, _ #)->+                let s# = sizeofArray# ptrs#+                    go n# | n# ==# s# = ()+                          | otherwise =+                              case indexArray# ptrs# n# of+                                (# a #) -> a `seq` go (n# +# 1#)+                in go 0#++infixr 0 $!!++deepseq :: a -> b -> b+deepseq a b = rnf a `seq` b++($!!) :: (a -> b) -> a -> b+f $!! x = x `deepseq` f x++force :: a -> a+force x = x `deepseq` x
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ deepseq-magic.cabal view
@@ -0,0 +1,17 @@+name:                deepseq-magic+version:             1.0.0.0+synopsis:            Deep evaluation of data structures without NFData+-- description:         +license:             PublicDomain+author:              Edward Z. Yang+maintainer:          ezyang@cs.stanford.edu+homepage:            https://github.com/ezyang/deepseq-magic+bug-reports:         https://github.com/ezyang/deepseq-magic/issues+category:            Control+build-type:          Simple+cabal-version:       >=1.10++library+  exposed-modules:     Control.DeepSeq.Magic+  build-depends:       base >=4.6 && <4.7+  default-language:    Haskell2010