[Git][ghc/ghc][master] Add INLINABLE pragmas to `generic*` functions in Data.OldList

Marge Bot (@marge-bot) gitlab at gitlab.haskell.org
Fri Feb 17 20:58:56 UTC 2023



Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC


Commits:
be0b7209 by Matthew Pickering at 2023-02-17T09:37:16+00:00
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)

https://github.com/haskell/core-libraries-committee/issues/129

- - - - -


2 changed files:

- libraries/base/Data/OldList.hs
- libraries/base/changelog.md


Changes:

=====================================
libraries/base/Data/OldList.hs
=====================================
@@ -842,6 +842,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.
@@ -849,6 +850,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.
@@ -856,6 +858,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
@@ -865,6 +868,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.
@@ -874,11 +878,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'.


=====================================
libraries/base/changelog.md
=====================================
@@ -6,6 +6,7 @@
     types significantly.
   * Refactor `generalCategory` to stop very large literal string being inlined to call-sites.
       ([CLC proposal #130](https://github.com/haskell/core-libraries-committee/issues/130))
+  * Add INLINABLE pragmas to `generic*` functions in Data.OldList ([CLC proposal #129](https://github.com/haskell/core-libraries-committee/issues/130))
 
 ## 4.18.0.0 *TBA*
 



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/be0b7209c6aef22798fc4ba7baacd2099b5cb494

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/be0b7209c6aef22798fc4ba7baacd2099b5cb494
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/20230217/5d416b2d/attachment-0001.html>


More information about the ghc-commits mailing list