Hello community,

here is the log from the commit of package ghc-random for openSUSE:Factory 
checked in at 2015-05-13 07:13:03
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Comparing /work/SRC/openSUSE:Factory/ghc-random (Old)
 and      /work/SRC/openSUSE:Factory/.ghc-random.new (New)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Package is "ghc-random"

Changes:
--------
--- /work/SRC/openSUSE:Factory/ghc-random/ghc-random.changes    2014-11-26 
20:55:06.000000000 +0100
+++ /work/SRC/openSUSE:Factory/.ghc-random.new/ghc-random.changes       
2015-05-13 07:13:04.000000000 +0200
@@ -1,0 +2,10 @@
+Thu Apr  9 17:25:19 UTC 2015 - [email protected]
+
+- update to 1.1
+  * breaking change to `randomIValInteger` to improve RNG quality and 
performance
+  * correct documentation about generated range of Int32 sized values of type 
Int
+  * fix memory leaks by using strict fields and strict atomicModifyIORef'
+  * support for base < 4.6 (which doesnt provide strict atomicModifyIORef')
+  * fix C type in test suite https://github.com/haskell/random/pull/9
+
+-------------------------------------------------------------------

Old:
----
  random-1.0.1.1.tar.gz

New:
----
  random-1.1.tar.gz

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Other differences:
------------------
++++++ ghc-random.spec ++++++
--- /var/tmp/diff_new_pack.yaWlQL/_old  2015-05-13 07:13:04.000000000 +0200
+++ /var/tmp/diff_new_pack.yaWlQL/_new  2015-05-13 07:13:04.000000000 +0200
@@ -1,7 +1,7 @@
 #
 # spec file for package ghc-random
 #
-# Copyright (c) 2014 SUSE LINUX Products GmbH, Nuernberg, Germany.
+# Copyright (c) 2015 SUSE LINUX GmbH, Nuernberg, Germany.
 #
 # All modifications and additions to the file contributed by third parties
 # remain the property of their copyright owners, unless otherwise agreed
@@ -19,7 +19,7 @@
 %global pkg_name random
 
 Name:           ghc-random
-Version:        1.0.1.1
+Version:        1.1
 Release:        0
 Summary:        Random number library
 License:        BSD-3-Clause

++++++ random-1.0.1.1.tar.gz -> random-1.1.tar.gz ++++++
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/random-1.0.1.1/.darcs-boring 
new/random-1.1/.darcs-boring
--- old/random-1.0.1.1/.darcs-boring    1970-01-01 01:00:00.000000000 +0100
+++ new/random-1.1/.darcs-boring        2014-09-16 23:34:43.000000000 +0200
@@ -0,0 +1,5 @@
+^dist(/|$)
+^setup(/|$)
+^GNUmakefile$
+^Makefile.local$
+^.depend(.bak)?$
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/random-1.0.1.1/.gitignore new/random-1.1/.gitignore
--- old/random-1.0.1.1/.gitignore       1970-01-01 01:00:00.000000000 +0100
+++ new/random-1.1/.gitignore   2014-09-16 23:34:43.000000000 +0200
@@ -0,0 +1,12 @@
+*~
+
+Thumbs.db
+.DS_Store
+
+GNUmakefile
+dist-install/
+ghc.mk
+
+dist
+.cabal-sandbox
+cabal.sandbox.config
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/random-1.0.1.1/.travis.yml new/random-1.1/.travis.yml
--- old/random-1.0.1.1/.travis.yml      1970-01-01 01:00:00.000000000 +0100
+++ new/random-1.1/.travis.yml  2014-09-16 23:34:43.000000000 +0200
@@ -0,0 +1,5 @@
+language: haskell
+ghc:
+  - 7.4
+  - 7.6
+  - 7.8
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/random-1.0.1.1/CHANGELOG.md 
new/random-1.1/CHANGELOG.md
--- old/random-1.0.1.1/CHANGELOG.md     1970-01-01 01:00:00.000000000 +0100
+++ new/random-1.1/CHANGELOG.md 2014-09-16 23:34:43.000000000 +0200
@@ -0,0 +1,26 @@
+# 1.1
+  * breaking change to `randomIValInteger` to improve RNG quality and 
performance
+    see https://github.com/haskell/random/pull/4 and
+    ghc https://ghc.haskell.org/trac/ghc/ticket/8898
+  * correct documentation about generated range of Int32 sized values of type 
Int
+    https://github.com/haskell/random/pull/7
+  * fix memory leaks by using strict fields and strict atomicModifyIORef'
+    https://github.com/haskell/random/pull/8
+    related to ghc trac tickets  #7936 and #4218
+  * support for base < 4.6 (which doesnt provide strict atomicModifyIORef')
+    and integrating Travis CI support.
+    https://github.com/haskell/random/pull/12
+  * fix C type in test suite https://github.com/haskell/random/pull/9
+
+# 1.0.1.1
+bump for overflow bug fixes
+
+# 1.0.1.2
+bump for ticket 8704, build fusion
+
+# 1.0.1.0
+bump for bug fixes,
+
+# 1.0.0.4
+bumped version for float/double range bugfix
+
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/random-1.0.1.1/README.md new/random-1.1/README.md
--- old/random-1.0.1.1/README.md        1970-01-01 01:00:00.000000000 +0100
+++ new/random-1.1/README.md    2014-09-16 23:34:43.000000000 +0200
@@ -0,0 +1,18 @@
+The Haskell Standard Library -- Random Number Generation
+========================================================
+[![Build 
Status](https://secure.travis-ci.org/haskell/random.svg?branch=master)](http://travis-ci.org/haskell/random)
+
+This library provides a basic interface for (splittable) random number 
generators.
+
+The API documentation can be found here:
+
+   http://hackage.haskell.org/package/random/docs/System-Random.html
+
+A module supplying this interface is required for Haskell 98 (but not Haskell
+2010). An older [version]
+(http://www.haskell.org/ghc/docs/latest/html/libraries/haskell98/Random.html)
+of this library is included with GHC in the haskell98 package. This newer
+version, with compatible api, is included in the [Haskell Platform]
+(http://www.haskell.org/platform/contents.html).
+
+Please report bugs in the Github [issue tracker] 
(https://github.com/haskell/random/issues) (no longer in the GHC trac).
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/random-1.0.1.1/System/Random.hs 
new/random-1.1/System/Random.hs
--- old/random-1.0.1.1/System/Random.hs 2011-12-06 21:08:19.000000000 +0100
+++ new/random-1.1/System/Random.hs     2014-09-16 23:34:43.000000000 +0200
@@ -93,9 +93,32 @@
 #endif
 import Data.Char       ( isSpace, chr, ord )
 import System.IO.Unsafe ( unsafePerformIO )
-import Data.IORef
+import Data.IORef       ( IORef, newIORef, readIORef, writeIORef )
+#if MIN_VERSION_base (4,6,0)
+import Data.IORef       ( atomicModifyIORef' )
+#else
+import Data.IORef       ( atomicModifyIORef )
+#endif
 import Numeric         ( readDec )
 
+#ifdef __GLASGOW_HASKELL__
+import GHC.Exts         ( build )
+#else
+-- | A dummy variant of build without fusion.
+{-# INLINE build #-}
+build :: ((a -> [a] -> [a]) -> [a] -> [a]) -> [a]
+build g = g (:) []
+#endif
+
+#if !MIN_VERSION_base (4,6,0)
+atomicModifyIORef' :: IORef a -> (a -> (a,b)) -> IO b
+atomicModifyIORef' ref f = do
+    b <- atomicModifyIORef ref
+            (\x -> let (a, b) = f x
+                    in (a, a `seq` b))
+    b `seq` return b
+#endif
+
 -- The standard nhc98 implementation of Time.ClockTime does not match
 -- the extended one expected in this module, so we lash-up a quick
 -- replacement here.
@@ -189,7 +212,7 @@
 -}
 
 data StdGen 
- = StdGen Int32 Int32
+ = StdGen !Int32 !Int32
 
 instance RandomGen StdGen where
   next  = stdNext
@@ -235,6 +258,11 @@
 mkStdGen :: Int -> StdGen -- why not Integer ?
 mkStdGen s = mkStdGen32 $ fromIntegral s
 
+{-
+From ["System.Random\#LEcuyer"]: "The integer variables s1 and s2 ... must be
+initialized to values in the range [1, 2147483562] and [1, 2147483398]
+respectively."
+-}
 mkStdGen32 :: Int32 -> StdGen
 mkStdGen32 sMaybeNegative = StdGen (s1+1) (s2+1)
       where
@@ -247,8 +275,6 @@
 createStdGen :: Integer -> StdGen
 createStdGen s = mkStdGen32 $ fromIntegral s
 
--- FIXME: 1/2/3 below should be ** (vs@30082002) XXX
-
 {- |
 With a source of random number supply in hand, the 'Random' class allows the
 programmer to extract random values of a variety of types.
@@ -279,13 +305,15 @@
 
   -- | Plural variant of 'randomR', producing an infinite list of
   -- random values instead of returning a new generator.
+  {-# INLINE randomRs #-}
   randomRs :: RandomGen g => (a,a) -> g -> [a]
-  randomRs ival g = x : randomRs ival g' where (x,g') = randomR ival g
+  randomRs ival g = build (\cons _nil -> buildRandoms cons (randomR ival) g)
 
   -- | Plural variant of 'random', producing an infinite list of
   -- random values instead of returning a new generator.
+  {-# INLINE randoms #-}
   randoms  :: RandomGen g => g -> [a]
-  randoms  g      = (\(x,g') -> x : randoms g') (random g)
+  randoms  g      = build (\cons _nil -> buildRandoms cons random g)
 
   -- | A variant of 'randomR' that uses the global random number generator
   -- (see "System.Random#globalrng").
@@ -297,6 +325,18 @@
   randomIO  :: IO a
   randomIO        = getStdRandom random
 
+-- | Produce an infinite list-equivalent of random values.
+{-# INLINE buildRandoms #-}
+buildRandoms :: RandomGen g
+             => (a -> as -> as)  -- ^ E.g. '(:)' but subject to fusion
+             -> (g -> (a,g))     -- ^ E.g. 'random'
+             -> g                -- ^ A 'RandomGen' instance
+             -> as
+buildRandoms cons rand = go
+  where
+    -- The seq fixes part of #4218 and also makes fused Core simpler.
+    go g = x `seq` (x `cons` go g') where (x,g') = rand g
+
 
 instance Random Integer where
   randomR ival g = randomIvalInteger ival g
@@ -421,24 +461,33 @@
 randomIvalIntegral :: (RandomGen g, Integral a) => (a, a) -> g -> (a, g)
 randomIvalIntegral (l,h) = randomIvalInteger (toInteger l, toInteger h)
 
+{-# SPECIALIZE randomIvalInteger :: (Num a) =>
+    (Integer, Integer) -> StdGen -> (a, StdGen) #-}
+        
 randomIvalInteger :: (RandomGen g, Num a) => (Integer, Integer) -> g -> (a, g)
 randomIvalInteger (l,h) rng
  | l > h     = randomIvalInteger (h,l) rng
- | otherwise = case (f n 1 rng) of (v, rng') -> (fromInteger (l + v `mod` k), 
rng')
+ | otherwise = case (f 1 0 rng) of (v, rng') -> (fromInteger (l + v `mod` k), 
rng')
      where
+       (genlo, genhi) = genRange rng
+       b = fromIntegral genhi - fromIntegral genlo + 1
+
+       -- Probabilities of the most likely and least likely result
+       -- will differ at most by a factor of (1 +- 1/q).  Assuming the 
RandomGen
+       -- is uniform, of course
+
+       -- On average, log q / log b more random values will be generated
+       -- than the minimum
+       q = 1000
        k = h - l + 1
-       -- ERROR: b here (2^31-87) represents a baked-in assumption about 
genRange:
-       b = 2147483561
-       n = iLogBase b k
-
-       -- Here we loop until we've generated enough randomness to cover the 
range:
-       f 0 acc g = (acc, g)
-       f n' acc g =
-          let
-          (x,g')   = next g
-         in
-          -- We shift over the random bits generated thusfar (* b) and add in 
the new ones.
-         f (n' - 1) (fromIntegral x + acc * b) g'
+       magtgt = k * q
+
+       -- generate random values until we exceed the target magnitude 
+       f mag v g | mag >= magtgt = (v, g)
+                 | otherwise = v' `seq`f (mag*b) v' g' where
+                        (x,g') = next g
+                        v' = (v * b + (fromIntegral x - fromIntegral genlo))
+
 
 -- The continuous functions on the other hand take an [inclusive,exclusive) 
range.
 randomFrac :: (RandomGen g, Fractional a) => g -> (a, g)
@@ -459,17 +508,10 @@
            (scaled_x, rng')
 
 int32Count :: Integer
-int32Count = toInteger (maxBound::Int32) - toInteger (minBound::Int32) + 1
-
--- Perform an expensive logarithm on arbitrary-size integers by repeated 
division.
--- 
--- (NOTE: This actually returns ceiling(log(i) base b) except with an
---  incorrect result at iLogBase b b = 2.)
-iLogBase :: Integer -> Integer -> Integer
-iLogBase b i = if i < b then 1 else 1 + iLogBase b (i `div` b)
+int32Count = toInteger (maxBound::Int32) - toInteger (minBound::Int32) + 1  -- 
GHC ticket #3982
 
 stdRange :: (Int,Int)
-stdRange = (0, 2147483562)
+stdRange = (1, 2147483562)
 
 stdNext :: StdGen -> (Int, StdGen)
 -- Returns values in the range stdRange
@@ -528,7 +570,7 @@
 -- |Applies 'split' to the current global random generator,
 -- updates it with one of the results, and returns the other.
 newStdGen :: IO StdGen
-newStdGen = atomicModifyIORef theStdGen split
+newStdGen = atomicModifyIORef' theStdGen split
 
 {- |Uses the supplied function to get a value from the current global
 random generator, and updates the global generator with the new generator
@@ -541,7 +583,7 @@
 -}
 
 getStdRandom :: (StdGen -> (a,StdGen)) -> IO a
-getStdRandom f = atomicModifyIORef theStdGen (swap . f)
+getStdRandom f = atomicModifyIORef' theStdGen (swap . f)
   where swap (v,g) = (g,v)
 
 {- $references
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/random-1.0.1.1/random.cabal 
new/random-1.1/random.cabal
--- old/random-1.0.1.1/random.cabal     2011-12-06 21:08:19.000000000 +0100
+++ new/random-1.1/random.cabal 2014-09-16 23:34:43.000000000 +0200
@@ -1,21 +1,33 @@
 name:          random
-version:       1.0.1.1
+version:       1.1
+
+
 
--- 1.0.1.0 -- bump for bug fixes, but no SplittableGen yet
--- 1.0.1.1 -- bump for overflow bug fixes
 
 license:       BSD3
 license-file:  LICENSE
-maintainer:    [email protected]
-bug-reports: 
http://hackage.haskell.org/trac/ghc/newticket?component=libraries/random
+maintainer:    [email protected]
+bug-reports:   https://github.com/haskell/random/issues
 synopsis:      random number library
 category:       System
 description:
        This package provides a basic random number generation
        library, including the ability to split random number
        generators.
+
+extra-source-files:
+  .travis.yml
+  README.md
+  CHANGELOG.md
+  .gitignore
+  .darcs-boring
+
+
+
 build-type: Simple
-Cabal-Version: >= 1.6
+-- cabal-version 1.8 needed because "the field 'build-depends: random' refers
+-- to a library which is defined within the same package"
+cabal-version: >= 1.8
 
 
 
@@ -23,10 +35,36 @@
     exposed-modules:
         System.Random
     extensions:        CPP
-    GHC-Options: -O2 
+    GHC-Options: -O2
     build-depends: base >= 3 && < 5, time
 
 source-repository head
     type:     git
-    location: http://darcs.haskell.org/packages/random.git/
+    location: http://git.haskell.org/packages/random.git
 
+-- To run the Test-Suite:
+-- $ cabal configure --enable-tests
+-- $ cabal test --show-details=always --test-options="+RTS -M1M -RTS"
+
+Test-Suite T7936
+    type:           exitcode-stdio-1.0
+    main-is:        T7936.hs
+    hs-source-dirs: tests
+    build-depends:  base >= 3 && < 5, random
+    ghc-options:    -rtsopts -O2
+
+Test-Suite TestRandomRs
+    type:           exitcode-stdio-1.0
+    main-is:        TestRandomRs.hs
+    hs-source-dirs: tests
+    build-depends:  base >= 3 && < 5, random
+    ghc-options:    -rtsopts -O2
+    -- TODO. Why does the following not work?
+    --test-options:   +RTS -M1M -RTS
+
+Test-Suite TestRandomIOs
+    type:           exitcode-stdio-1.0
+    main-is:        TestRandomIOs.hs
+    hs-source-dirs: tests
+    build-depends:  base >= 3 && < 5, random
+    ghc-options:    -rtsopts -O2
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/random-1.0.1.1/tests/T7936.hs 
new/random-1.1/tests/T7936.hs
--- old/random-1.0.1.1/tests/T7936.hs   1970-01-01 01:00:00.000000000 +0100
+++ new/random-1.1/tests/T7936.hs       2014-09-16 23:34:43.000000000 +0200
@@ -0,0 +1,14 @@
+-- Test for ticket #7936:
+-- https://ghc.haskell.org/trac/ghc/ticket/7936
+--
+-- Used to fail with:
+--
+-- $ cabal test T7936 --test-options="+RTS -M1M -RTS"
+-- T7936: Heap exhausted;
+
+module Main where
+
+import System.Random (newStdGen)
+import Control.Monad (replicateM_)
+
+main = replicateM_ 100000 newStdGen
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/random-1.0.1.1/tests/TestRandomIOs.hs 
new/random-1.1/tests/TestRandomIOs.hs
--- old/random-1.0.1.1/tests/TestRandomIOs.hs   1970-01-01 01:00:00.000000000 
+0100
+++ new/random-1.1/tests/TestRandomIOs.hs       2014-09-16 23:34:43.000000000 
+0200
@@ -0,0 +1,20 @@
+-- Test for ticket #4218 (TestRandomIOs):
+-- https://ghc.haskell.org/trac/ghc/ticket/4218
+--
+-- Used to fail with:
+--
+-- $ cabal test TestRandomIOs --test-options="+RTS -M1M -RTS"
+-- TestRandomIOs: Heap exhausted;
+
+module Main where
+
+import Control.Monad (replicateM)
+import System.Random (randomIO)
+
+-- Build a list of 5000 random ints in memory (IO Monad is strict), and print
+-- the last one.
+-- Should use less than 1Mb of heap space, or we are generating a list of
+-- unevaluated thunks.
+main = do
+    rs <- replicateM 5000 randomIO :: IO [Int]
+    print $ last rs
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/random-1.0.1.1/tests/TestRandomRs.hs 
new/random-1.1/tests/TestRandomRs.hs
--- old/random-1.0.1.1/tests/TestRandomRs.hs    1970-01-01 01:00:00.000000000 
+0100
+++ new/random-1.1/tests/TestRandomRs.hs        2014-09-16 23:34:43.000000000 
+0200
@@ -0,0 +1,22 @@
+-- Test for ticket #4218 (TestRandomRs):
+-- https://ghc.haskell.org/trac/ghc/ticket/4218
+--
+-- Fixed together with ticket #8704
+-- https://ghc.haskell.org/trac/ghc/ticket/8704
+-- Commit 4695ffa366f659940369f05e419a4f2249c3a776
+--
+-- Used to fail with:
+--
+-- $ cabal test TestRandomRs --test-options="+RTS -M1M -RTS"
+-- TestRandomRs: Heap exhausted;
+
+module Main where
+
+import Control.Monad (liftM, replicateM)
+import System.Random (randomRs, getStdGen)
+
+-- Return the five-thousandth random number:
+-- Should run in constant space (< 1Mb heap).
+main = do
+    n <- (last . take 5000 . randomRs (0, 1000000)) `liftM` getStdGen
+    print (n::Integer)


Reply via email to