Use strict fields for StdGen (GHC #7936)
authorThomas Miedema <thomasmiedema@gmail.com>
Thu, 10 Jul 2014 18:56:17 +0000 (20:56 +0200)
committerThomas Miedema <thomasmiedema@gmail.com>
Thu, 10 Jul 2014 19:18:32 +0000 (21:18 +0200)
System/Random.hs
random.cabal
tests/T7936.hs [new file with mode: 0644]

index 7522499..1d0ec42 100644 (file)
@@ -198,7 +198,7 @@ instance of 'StdGen' has the following properties:
 -}
 
 data StdGen 
 -}
 
 data StdGen 
- = StdGen Int32 Int32
+ = StdGen !Int32 !Int32
 
 instance RandomGen StdGen where
   next  = stdNext
 
 instance RandomGen StdGen where
   next  = stdNext
index 1039057..8353685 100644 (file)
@@ -37,6 +37,13 @@ source-repository head
 -- $ cabal configure --enable-tests
 -- $ cabal test --show-details=always --test-options="+RTS -M1M -RTS"
 
 -- $ 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
 Test-Suite TestRandomRs
     type:           exitcode-stdio-1.0
     main-is:        TestRandomRs.hs
diff --git a/tests/T7936.hs b/tests/T7936.hs
new file mode 100644 (file)
index 0000000..cfea911
--- /dev/null
@@ -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