summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthew Pickering <matthewtpickering@gmail.com>2023-02-09 16:17:05 +0000
committerMatthew Pickering <matthewtpickering@gmail.com>2023-02-09 16:17:05 +0000
commit3e06f4b9978f2b912ba69257c871467c3e8fc6c8 (patch)
tree8aa2e1ab1a26db44f0efaf52d51a88c49606331d
parent5809d9d7ba1845abdaede9bd8ad978026940359f (diff)
downloadhaskell-3e06f4b9978f2b912ba69257c871467c3e8fc6c8.tar.gz
Add INLINABLE pragmas to `generic*` functions in Data.OldList
These functions are * recursive * overloaded So it's important to add an `INLINABLE` pragma to each so that they can be specialised at the use site when the specific numeric type is known. Adding these pragmas improves the LazyText replicate benchmark (see https://gitlab.haskell.org/ghc/ghc/-/issues/22886#note_481020)
-rw-r--r--libraries/base/Data/OldList.hs6
1 files changed, 6 insertions, 0 deletions
diff --git a/libraries/base/Data/OldList.hs b/libraries/base/Data/OldList.hs
index 58b0bce8b2..2ae034a99c 100644
--- a/libraries/base/Data/OldList.hs
+++ b/libraries/base/Data/OldList.hs
@@ -841,6 +841,7 @@ strictGenericLength l = gl l 0
where
gl [] a = a
gl (_:xs) a = let a' = a + 1 in a' `seq` gl xs a'
+{-# INLINABLE strictGenericLength #-}
-- | The 'genericTake' function is an overloaded version of 'take', which
-- accepts any 'Integral' value as the number of elements to take.
@@ -848,6 +849,7 @@ genericTake :: (Integral i) => i -> [a] -> [a]
genericTake n _ | n <= 0 = []
genericTake _ [] = []
genericTake n (x:xs) = x : genericTake (n-1) xs
+{-# INLINABLE genericTake #-}
-- | The 'genericDrop' function is an overloaded version of 'drop', which
-- accepts any 'Integral' value as the number of elements to drop.
@@ -855,6 +857,7 @@ genericDrop :: (Integral i) => i -> [a] -> [a]
genericDrop n xs | n <= 0 = xs
genericDrop _ [] = []
genericDrop n (_:xs) = genericDrop (n-1) xs
+{-# INLINABLE genericDrop #-}
-- | The 'genericSplitAt' function is an overloaded version of 'splitAt', which
@@ -864,6 +867,7 @@ genericSplitAt n xs | n <= 0 = ([],xs)
genericSplitAt _ [] = ([],[])
genericSplitAt n (x:xs) = (x:xs',xs'') where
(xs',xs'') = genericSplitAt (n-1) xs
+{-# INLINABLE genericSplitAt #-}
-- | The 'genericIndex' function is an overloaded version of '!!', which
-- accepts any 'Integral' value as the index.
@@ -873,11 +877,13 @@ genericIndex (_:xs) n
| n > 0 = genericIndex xs (n-1)
| otherwise = errorWithoutStackTrace "List.genericIndex: negative argument."
genericIndex _ _ = errorWithoutStackTrace "List.genericIndex: index too large."
+{-# INLINABLE genericIndex #-}
-- | The 'genericReplicate' function is an overloaded version of 'replicate',
-- which accepts any 'Integral' value as the number of repetitions to make.
genericReplicate :: (Integral i) => i -> a -> [a]
genericReplicate n x = genericTake n (repeat x)
+{-# INLINABLE genericReplicate #-}
-- | The 'zip4' function takes four lists and returns a list of
-- quadruples, analogous to 'zip'.