[Git][ghc/ghc][wip/buggymcbugfix/15185-enum-int] Add inline pragmas to Enum methods
Vilem-Benjamin Liepelt
gitlab at gitlab.haskell.org
Wed May 13 10:32:23 UTC 2020
Vilem-Benjamin Liepelt pushed to branch wip/buggymcbugfix/15185-enum-int at Glasgow Haskell Compiler / GHC
Commits:
fc47ad26 by buggymcbugfix at 2020-05-13T13:31:17+03:00
Add inline pragmas to Enum methods
Fixes t15185
- - - - -
1 changed file:
- libraries/base/GHC/Enum.hs
Changes:
=====================================
libraries/base/GHC/Enum.hs
=====================================
@@ -139,13 +139,36 @@ class Enum a where
-- * @enumFromThenTo 6 8 2 :: [Int] = []@
enumFromThenTo :: a -> a -> a -> [a]
- succ = toEnum . (+ 1) . fromEnum
- pred = toEnum . (subtract 1) . fromEnum
- enumFrom x = map toEnum [fromEnum x ..]
- enumFromThen x y = map toEnum [fromEnum x, fromEnum y ..]
- enumFromTo x y = map toEnum [fromEnum x .. fromEnum y]
+ succ = toEnum . (+ 1) . fromEnum
+
+ pred = toEnum . (subtract 1) . fromEnum
+
+ -- See Note [Stable Unfolding for Enum methods]
+ {-# INLINABLE enumFrom #-}
+ enumFrom x = map toEnum [fromEnum x ..]
+
+ -- See Note [Stable Unfolding for Enum methods]
+ {-# INLINABLE enumFromThen #-}
+ enumFromThen x y = map toEnum [fromEnum x, fromEnum y ..]
+
+ -- See Note [Stable Unfolding for Enum methods]
+ {-# INLINABLE enumFromTo #-}
+ enumFromTo x y = map toEnum [fromEnum x .. fromEnum y]
+
+ -- See Note [Stable Unfolding for Enum methods]
+ {-# INLINABLE enumFromThenTo #-}
enumFromThenTo x1 x2 y = map toEnum [fromEnum x1, fromEnum x2 .. fromEnum y]
+{-
+Note [Stable Unfolding for Enum methods]
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+The INLINABLE pragmas ensure that we export stable (unoptimised) unfoldings in
+the interface file so we can do list fusion at usage sites outside this module.
+
+Fixes https://gitlab.haskell.org/ghc/ghc/issues/15185
+-}
+
-- Default methods for bounded enumerations
boundedEnumFrom :: (Enum a, Bounded a) => a -> [a]
boundedEnumFrom n = map toEnum [fromEnum n .. fromEnum (maxBound `asTypeOf` n)]
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/fc47ad267b81673626e07731530a6cb90734d725
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/fc47ad267b81673626e07731530a6cb90734d725
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/20200513/e99e1085/attachment-0001.html>
More information about the ghc-commits
mailing list