base 4.7.0.1 → 4.7.0.2
raw patch · 6 files changed
+100/−9 lines, 6 filesPVP: minor bump suggested
API additions: PVP suggests at least a minor version bump
API changes (from Hackage documentation)
+ GHC.Conc.Signal: runHandlersPtr :: Ptr Word8 -> Signal -> IO ()
Files
- Data/List.hs +71/−4
- Debug/Trace.hs +9/−2
- GHC/Conc/Signal.hs +10/−1
- GHC/Generics.hs +1/−1
- base.cabal +1/−1
- changelog.md +8/−0
Data/List.hs view
@@ -1,5 +1,5 @@ {-# LANGUAGE Trustworthy #-}-{-# LANGUAGE CPP, NoImplicitPrelude, MagicHash #-}+{-# LANGUAGE CPP, NoImplicitPrelude, MagicHash, BangPatterns #-} ----------------------------------------------------------------------------- -- |@@ -206,6 +206,7 @@ ) where import Data.Maybe+import Data.Bits ( (.&.) ) import Data.Char ( isSpace ) import GHC.Num@@ -746,12 +747,30 @@ -- > inits "abc" == ["","a","ab","abc"] -- -- Note that 'inits' has the following strictness property:+-- @inits (xs ++ _|_) = inits xs ++ _|_@+--+-- In particular, -- @inits _|_ = [] : _|_@ inits :: [a] -> [[a]]-inits xs = [] : case xs of- [] -> []- x : xs' -> map (x :) (inits xs')+inits = map toListSB . scanl' snocSB emptySB+{-# NOINLINE inits #-} +-- We do not allow inits to inline, because it plays havoc with Call Arity+-- if it fuses with a consumer, and it would generally lead to serious+-- loss of sharing if allowed to fuse with a producer.++-- | A strictly accumulating version of 'scanl'+{-# NOINLINE [1] scanl' #-}+scanl' :: (b -> a -> b) -> b -> [a] -> [b]+-- This peculiar form is needed to prevent scanl' from being rewritten+-- in its own right hand side.+scanl' = scanlGo'+ where+ scanlGo' :: (b -> a -> b) -> b -> [a] -> [b]+ scanlGo' f !q ls = q : (case ls of+ [] -> []+ x:xs -> scanlGo' f (f q x) xs)+ -- | The 'tails' function returns all final segments of the argument, -- longest first. For example, --@@ -1087,3 +1106,51 @@ unwords [w] = w unwords (w:ws) = w ++ ' ' : unwords ws #endif++{- A "SnocBuilder" is a version of Chris Okasaki's banker's queue that supports+toListSB instead of uncons. In single-threaded use, its performance+characteristics are similar to John Hughes's functional difference lists, but+likely somewhat worse. In heavily persistent settings, however, it does much+better, because it takes advantage of sharing. The banker's queue guarantees+(amortized) O(1) snoc and O(1) uncons, meaning that we can think of toListSB as+an O(1) conversion to a list-like structure a constant factor slower than+normal lists--we pay the O(n) cost incrementally as we consume the list. Using+functional difference lists, on the other hand, we would have to pay the whole+cost up front for each output list. -}++{- We store a front list, a rear list, and the length of the queue. Because we+only snoc onto the queue and never uncons, we know it's time to rotate when the+length of the queue plus 1 is a power of 2. Note that we rely on the value of+the length field only for performance. In the unlikely event of overflow, the+performance will suffer but the semantics will remain correct. -}++data SnocBuilder a = SnocBuilder {-# UNPACK #-} !Word [a] [a]++{- Smart constructor that rotates the builder when lp is one minus a power of+2. Does not rotate very small builders because doing so is not worth the+trouble. The lp < 255 test goes first because the power-of-2 test gives awful+branch prediction for very small n (there are 5 powers of 2 between 1 and+16). Putting the well-predicted lp < 255 test first avoids branching on the+power-of-2 test until powers of 2 have become sufficiently rare to be predicted+well. -}++{-# INLINE sb #-}+sb :: Word -> [a] -> [a] -> SnocBuilder a+sb lp f r+ | lp < 255 || (lp .&. (lp + 1)) /= 0 = SnocBuilder lp f r+ | otherwise = SnocBuilder lp (f ++ reverse r) []++-- The empty builder++emptySB :: SnocBuilder a+emptySB = SnocBuilder 0 [] []++-- Add an element to the end of a queue.++snocSB :: SnocBuilder a -> a -> SnocBuilder a+snocSB (SnocBuilder lp f r) x = sb (lp + 1) f (x:r)++-- Convert a builder to a list++toListSB :: SnocBuilder a -> [a]+toListSB (SnocBuilder _ f r) = f ++ reverse r
Debug/Trace.hs view
@@ -52,6 +52,7 @@ import GHC.IO.Encoding import GHC.Ptr import GHC.Stack+import Data.List -- $tracing --@@ -70,9 +71,15 @@ -- /Since: 4.5.0.0/ traceIO :: String -> IO () traceIO msg = do- withCString "%s\n" $ \cfmt ->- withCString msg $ \cmsg ->+ withCString "%s\n" $ \cfmt -> do+ -- NB: debugBelch can't deal with null bytes, so filter them+ -- out so we don't accidentally truncate the message. See Trac #9395+ let (nulls, msg') = partition (=='\0') msg+ withCString msg' $ \cmsg -> debugBelch cfmt cmsg+ when (not (null nulls)) $+ withCString "WARNING: previous trace message had null bytes" $ \cmsg ->+ debugBelch cfmt cmsg -- don't use debugBelch() directly, because we cannot call varargs functions -- using the FFI.
GHC/Conc/Signal.hs view
@@ -6,16 +6,18 @@ , HandlerFun , setHandler , runHandlers+ , runHandlersPtr ) where import Control.Concurrent.MVar (MVar, newMVar, withMVar) import Data.Dynamic (Dynamic) import Data.Maybe (Maybe(..)) import Foreign.C.Types (CInt)-import Foreign.ForeignPtr (ForeignPtr)+import Foreign.ForeignPtr (ForeignPtr, newForeignPtr) import Foreign.StablePtr (castPtrToStablePtr, castStablePtrToPtr, deRefStablePtr, freeStablePtr, newStablePtr) import Foreign.Ptr (Ptr, castPtr)+import Foreign.Marshal.Alloc (finalizerFree) import GHC.Arr (inRange) import GHC.Base import GHC.Conc.Sync (forkIO)@@ -70,6 +72,13 @@ Nothing -> return () Just (f,_) -> do _ <- forkIO (f p_info) return ()++-- It is our responsibility to free the memory buffer, so we create a+-- foreignPtr.+runHandlersPtr :: Ptr Word8 -> Signal -> IO ()+runHandlersPtr p s = do+ fp <- newForeignPtr finalizerFree p+ runHandlers fp s -- Machinery needed to ensure that we only have one copy of certain -- CAFs in this module even when the base package is present twice, as
GHC/Generics.hs view
@@ -163,7 +163,7 @@ -- type 'D1' = 'M1' 'D' -- @ ----- The types 'S', 'C' and 'R' are once again type-level proxies, just used to create+-- The types 'S', 'C' and 'D' are once again type-level proxies, just used to create -- several variants of 'M1'. -- *** Additional generic representation type constructors
base.cabal view
@@ -1,5 +1,5 @@ name: base-version: 4.7.0.1+version: 4.7.0.2 -- GHC 7.6.3 released with 4.7.0.0 license: BSD3 license-file: LICENSE
changelog.md view
@@ -1,5 +1,13 @@ # Changelog for [`base` package](http://hackage.haskell.org/package/base) +## 4.7.0.2 *Dec 2014*++ * Bundled with GHC 7.8.4++ * Fix performance bug in `Data.List.inits` (#9345)++ * Fix handling of null bytes in `Debug.Trace.trace` (#9395)+ ## 4.7.0.1 *Jul 2014* * Bundled with GHC 7.8.3