diff options
author | Sylvain Henry <sylvain@haskus.fr> | 2021-10-06 12:35:58 +0200 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2021-10-07 20:20:01 -0400 |
commit | 44886aaba46230de003fb99153a3120667225302 (patch) | |
tree | 30fa4a9f9202da98cd1a26af1f848e23a19b1a5c /libraries/base | |
parent | e1d02fb0f04bcf3acea1da96d291a03bb749718d (diff) | |
download | haskell-44886aaba46230de003fb99153a3120667225302.tar.gz |
Bignum: allow inlining of naturalEq/Ne/Gt/Lt/Ge/Le/Compare (#20361)
Perform constant folding on bigNatCompare instead.
Some functions of the Enum class for Natural now need to be inlined
explicitly to be specialized at call sites (because `x > lim` for
Natural is inlined and the resulting function is a little too big to
inline). If we don't do this, T17499 runtime allocations regresses by
16%.
Diffstat (limited to 'libraries/base')
-rw-r--r-- | libraries/base/GHC/Enum.hs | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/libraries/base/GHC/Enum.hs b/libraries/base/GHC/Enum.hs index 096e633894..4292592f44 100644 --- a/libraries/base/GHC/Enum.hs +++ b/libraries/base/GHC/Enum.hs @@ -989,12 +989,22 @@ instance Enum Natural where i = I# (word2Int# w) fromEnum _ = errorWithoutStackTrace "fromEnum: out of Int range" + -- See Note [Stable Unfolding for list producers] + {-# INLINE enumFrom #-} enumFrom x = enumDeltaNatural x 1 + + -- See Note [Stable Unfolding for list producers] + {-# INLINE enumFromThen #-} enumFromThen x y | x <= y = enumDeltaNatural x (y-x) | otherwise = enumNegDeltaToNatural x (x-y) 0 + -- See Note [Stable Unfolding for list producers] + {-# INLINE enumFromTo #-} enumFromTo x lim = enumDeltaToNatural x 1 lim + + -- See Note [Stable Unfolding for list producers] + {-# INLINE enumFromThenTo #-} enumFromThenTo x y lim | x <= y = enumDeltaToNatural x (y-x) lim | otherwise = enumNegDeltaToNatural x (x-y) lim @@ -1004,12 +1014,16 @@ instance Enum Natural where enumDeltaNatural :: Natural -> Natural -> [Natural] enumDeltaNatural !x d = x : enumDeltaNatural (x+d) d +-- Inline to specialize +{-# INLINE enumDeltaToNatural #-} enumDeltaToNatural :: Natural -> Natural -> Natural -> [Natural] enumDeltaToNatural x0 delta lim = go x0 where go x | x > lim = [] | otherwise = x : go (x+delta) +-- Inline to specialize +{-# INLINE enumNegDeltaToNatural #-} enumNegDeltaToNatural :: Natural -> Natural -> Natural -> [Natural] enumNegDeltaToNatural x0 ndelta lim = go x0 where |