diff options
author | Takano Akio <aljee@hyper.cx> | 2015-08-05 14:23:22 +0200 |
---|---|---|
committer | Ben Gamari <ben@smart-cactus.org> | 2015-08-05 14:45:16 +0200 |
commit | 22bbc1cf209d44b8bb8897ae7a35f9ebaf411b10 (patch) | |
tree | 9604a8e2456b1c148ac99859efd365a30f2dda00 | |
parent | b12dba7829742de98a483645142c7962b9dd9f3f (diff) | |
download | haskell-22bbc1cf209d44b8bb8897ae7a35f9ebaf411b10.tar.gz |
Make sure that `all`, `any`, `and`, and `or` fuse (#9848)
Test Plan: validate
Reviewers: hvr, austin, bgamari, simonpj
Reviewed By: simonpj
Subscribers: simonpj, thomie
Differential Revision: https://phabricator.haskell.org/D1126
GHC Trac Issues: #9848
-rw-r--r-- | libraries/base/Data/Foldable.hs | 2 | ||||
-rw-r--r-- | libraries/base/tests/T9848.hs | 14 | ||||
-rw-r--r-- | libraries/base/tests/T9848.stdout | 2 | ||||
-rw-r--r-- | libraries/base/tests/all.T | 7 |
4 files changed, 25 insertions, 0 deletions
diff --git a/libraries/base/Data/Foldable.hs b/libraries/base/Data/Foldable.hs index 1f20261943..24b6dd18c2 100644 --- a/libraries/base/Data/Foldable.hs +++ b/libraries/base/Data/Foldable.hs @@ -119,6 +119,8 @@ class Foldable t where -- | Map each element of the structure to a monoid, -- and combine the results. foldMap :: Monoid m => (a -> m) -> t a -> m + {-# INLINE foldMap #-} + -- This INLINE allows more list functions to fuse. See Trac #9848. foldMap f = foldr (mappend . f) mempty -- | Right-associative fold of a structure. diff --git a/libraries/base/tests/T9848.hs b/libraries/base/tests/T9848.hs new file mode 100644 index 0000000000..d473f93c31 --- /dev/null +++ b/libraries/base/tests/T9848.hs @@ -0,0 +1,14 @@ +import Data.IORef + +foo :: Int -> Bool +foo n = all (<10000000) [1..n] + +bar :: Int -> Bool +bar n = and $ map (<10000000) [1..n] + +main :: IO () +main = do + ref <- newIORef 1000000 + val <- readIORef ref + print $ foo val + print $ bar val diff --git a/libraries/base/tests/T9848.stdout b/libraries/base/tests/T9848.stdout new file mode 100644 index 0000000000..dbde422651 --- /dev/null +++ b/libraries/base/tests/T9848.stdout @@ -0,0 +1,2 @@ +True +True diff --git a/libraries/base/tests/all.T b/libraries/base/tests/all.T index 34176d0153..1b065a33e9 100644 --- a/libraries/base/tests/all.T +++ b/libraries/base/tests/all.T @@ -191,3 +191,10 @@ test('T9681', normal, compile_fail, ['']) test('T8089', [exit_code(99), run_timeout_multiplier(0.01)], compile_and_run, ['']) test('T9826',normal, compile_and_run,['']) +test('T9848', + [ stats_num_field('bytes allocated', + [ (wordsize(64), 51840, 20) + , (wordsize(32), 47348, 20) ]) + , only_ways(['normal'])], + compile_and_run, + ['-O']) |