[Git][ghc/ghc][master] 2 commits: Add test for T18574
Marge Bot
gitlab at gitlab.haskell.org
Thu Oct 1 22:35:01 UTC 2020
Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC
Commits:
0bb02873 by Sylvain Henry at 2020-10-01T18:34:53-04:00
Add test for T18574
- - - - -
e393f213 by Sylvain Henry at 2020-10-01T18:34:53-04:00
Allow fusion with catMaybes (#18574)
Metric Decrease:
T18574
- - - - -
5 changed files:
- libraries/base/Data/Maybe.hs
- libraries/base/changelog.md
- + testsuite/tests/perf/should_run/T18574.hs
- + testsuite/tests/perf/should_run/T18574.stdout
- testsuite/tests/perf/should_run/all.T
Changes:
=====================================
libraries/base/Data/Maybe.hs
=====================================
@@ -256,8 +256,8 @@ listToMaybe = foldr (const . Just) Nothing
-- >>> catMaybes $ [readMaybe x :: Maybe Int | x <- ["1", "Foo", "3"] ]
-- [1,3]
--
-catMaybes :: [Maybe a] -> [a]
-catMaybes ls = [x | Just x <- ls]
+catMaybes :: [Maybe a] -> [a]
+catMaybes = mapMaybe id -- use mapMaybe to allow fusion (#18574)
-- | The 'mapMaybe' function is a version of 'map' which can throw
-- out elements. In particular, the functional argument returns
=====================================
libraries/base/changelog.md
=====================================
@@ -32,6 +32,9 @@
* Add `MonadFix` and `MonadZip` instances for `Complex`
* Add `Ix` instances for tuples of size 6 through 15
+
+ * `catMaybes` is now implemented using `mapMaybe`, so that it is both a "good
+ consumer" and "good producer" for list-fusion (#18574)
## 4.14.0.0 *TBA*
* Bundled with GHC 8.10.1
=====================================
testsuite/tests/perf/should_run/T18574.hs
=====================================
@@ -0,0 +1,7 @@
+import Data.Maybe
+
+main :: IO ()
+main = print $ even $ sum $ catMaybes $ map xx ([1..100000000] :: [Int])
+ where
+ xx n | even n = Just n
+ | otherwise = Nothing
=====================================
testsuite/tests/perf/should_run/T18574.stdout
=====================================
@@ -0,0 +1 @@
+True
=====================================
testsuite/tests/perf/should_run/all.T
=====================================
@@ -379,3 +379,9 @@ test('UniqLoop',
],
compile_and_run,
['-O -package ghc'])
+
+test('T18574',
+ [collect_stats('bytes allocated', 5), only_ways(['normal'])],
+ compile_and_run,
+ ['-O'])
+
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/5c32655fffd0d8862f3ba693351f1e612daa0b6b...e393f213f5ccff4fd6034d5294e51aa5a2720890
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/5c32655fffd0d8862f3ba693351f1e612daa0b6b...e393f213f5ccff4fd6034d5294e51aa5a2720890
You're receiving this email because of your account on gitlab.haskell.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20201001/7a33ee7a/attachment-0001.html>
More information about the ghc-commits
mailing list