Test that runST is not inlined prematurely
authorJoachim Breitner <mail@joachim-breitner.de>
Wed, 8 Jan 2014 18:23:56 +0000 (18:23 +0000)
committerJoachim Breitner <mail@joachim-breitner.de>
Wed, 8 Jan 2014 18:23:56 +0000 (18:23 +0000)
This resulted form a discussion about #5916.

testsuite/tests/simplCore/should_run/all.T
testsuite/tests/simplCore/should_run/runST.hs [new file with mode: 0644]
testsuite/tests/simplCore/should_run/runST.stdout [new file with mode: 0644]

index c9be7a4..430d61f 100644 (file)
@@ -31,6 +31,8 @@ test('T3437', extra_run_opts('+RTS -M10m'), compile_and_run, [''])
 
 test('SeqRule', only_ways(['optasm']), compile_and_run, [''])
 
+test('runST', normal, compile_and_run, [''])
+
 test('T3403', normal, compile_and_run, ['-package containers'])
 test('T3591', normal, compile_and_run, [''])
 test('T4814', normal, compile_and_run, [''])
diff --git a/testsuite/tests/simplCore/should_run/runST.hs b/testsuite/tests/simplCore/should_run/runST.hs
new file mode 100644 (file)
index 0000000..dc06c24
--- /dev/null
@@ -0,0 +1,13 @@
+import Control.Monad.ST
+import Data.STRef
+
+-- Make sure that the realWord# token used by runST (actually by runSTRep) is
+-- not inlined, which would share the call to `newMutVar#`, and suddenly there
+-- would be only one MutVar
+
+main =
+    let f () = runST $ do
+        ref <- newSTRef 0
+        modifySTRef ref (+1)
+        readSTRef ref
+    in print (f () + f ())
diff --git a/testsuite/tests/simplCore/should_run/runST.stdout b/testsuite/tests/simplCore/should_run/runST.stdout
new file mode 100644 (file)
index 0000000..0cfbf08
--- /dev/null
@@ -0,0 +1 @@
+2