summaryrefslogtreecommitdiff
path: root/testsuite/tests/perf/should_run
diff options
context:
space:
mode:
authorDavid Feuer <david.feuer@gmail.com>2018-06-06 15:50:06 -0400
committerDavid Feuer <David.Feuer@gmail.com>2018-06-06 15:50:07 -0400
commitd964b054d530ea9e29ed051fdf2b49a6afe465fb (patch)
treeea7827061254a8ae6ed81f1d666f77b3d9d2b249 /testsuite/tests/perf/should_run
parent455477a3675c53ce186b3e75ec88f5488fec792c (diff)
downloadhaskell-d964b054d530ea9e29ed051fdf2b49a6afe465fb.tar.gz
Let the simplifier know that seq# forces
Add a special case in `simplAlt` to record that the result of `seq#` is in WHNF. Reviewers: simonmar, bgamari, simonpj Reviewed By: simonpj Subscribers: simonpj, rwbarton, thomie, carter GHC Trac Issues: #15226 Differential Revision: https://phabricator.haskell.org/D4796
Diffstat (limited to 'testsuite/tests/perf/should_run')
-rw-r--r--testsuite/tests/perf/should_run/T15226.hs30
-rw-r--r--testsuite/tests/perf/should_run/all.T10
2 files changed, 40 insertions, 0 deletions
diff --git a/testsuite/tests/perf/should_run/T15226.hs b/testsuite/tests/perf/should_run/T15226.hs
new file mode 100644
index 0000000000..4c09114b89
--- /dev/null
+++ b/testsuite/tests/perf/should_run/T15226.hs
@@ -0,0 +1,30 @@
+-- T15226
+import Control.Exception (evaluate)
+
+-- Just in case Prelude.repeat changes for some reason.
+import Prelude hiding (repeat)
+
+-- We want to be sure that the compiler *doesn't* know that
+-- all the elements of the list are in WHNF, because if it
+-- does, PrelRules may erase the seq#'s altogether.
+repeat :: a -> [a]
+repeat a = res
+ where res = a : res
+{-# NOINLINE repeat #-} -- Belt *and* suspenders
+
+silly :: [Int] -> IO ()
+silly = foldr go (pure ())
+ where
+ go x r = do
+ x' <- evaluate x
+ evaluate (x' + 3) -- GHC should know that x' has been evaluated,
+ -- so this calculation will be erased entirely.
+ -- Otherwise, we'll create a thunk to pass to
+ -- evaluate.
+ r
+
+main :: IO ()
+-- 10,000,000 repetitions take only a twentieth of a second,
+-- but allocations go up dramatically if the result is not
+-- known evaluated.
+main = silly $ take 10000000 $ repeat 1
diff --git a/testsuite/tests/perf/should_run/all.T b/testsuite/tests/perf/should_run/all.T
index 9fd997f633..b248dd56f7 100644
--- a/testsuite/tests/perf/should_run/all.T
+++ b/testsuite/tests/perf/should_run/all.T
@@ -574,3 +574,13 @@ test('T14936',
(wordsize(64), 51792, 5) ])],
compile_and_run,
['-O2'])
+
+test('T15226',
+ [stats_num_field('bytes allocated',
+ [ (wordsize(64), 41040, 5) ]),
+ # 2018-06-06 41040 Let the simplifier know the result
+ # of seq# is in WHNF
+ # initial 400041040
+ only_ways(['normal'])],
+ compile_and_run,
+ ['-O'])