Skip to content

Commit

Permalink
A whole bunch of INLINE pragmas to avoid nasty regressions in GHC-9
Browse files Browse the repository at this point in the history
  • Loading branch information
lehins committed Apr 19, 2021
1 parent b55aaa4 commit c9471d4
Show file tree
Hide file tree
Showing 2 changed files with 123 additions and 16 deletions.
11 changes: 11 additions & 0 deletions src/System/Random.hs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ import qualified System.Random.SplitMix as SM
-- @since 1.2.0
uniform :: (RandomGen g, Uniform a) => g -> (a, g)
uniform g = runStateGen g uniformM
{-# INLINE uniform #-}

-- | Generates a value uniformly distributed over the provided range, which
-- is interpreted as inclusive in the lower and upper bound.
Expand All @@ -172,6 +173,7 @@ uniform g = runStateGen g uniformM
-- @since 1.2.0
uniformR :: (RandomGen g, UniformRange a) => (a, a) -> g -> (a, g)
uniformR r g = runStateGen g (uniformRM r)
{-# INLINE uniformR #-}

-- | Generates a 'ByteString' of the specified size using a pure pseudo-random
-- number generator. See 'uniformByteStringM' for the monadic version.
Expand Down Expand Up @@ -258,6 +260,7 @@ buildRandoms cons rand = go
-- Generate values in the Int range
instance Random Integer where
random = first (toInteger :: Int -> Integer) . random
{-# INLINE random #-}
instance Random Int8
instance Random Int16
instance Random Int32
Expand Down Expand Up @@ -292,25 +295,33 @@ instance Random CIntMax
instance Random CUIntMax
instance Random CFloat where
randomR (CFloat l, CFloat h) = first CFloat . randomR (l, h)
{-# INLINE randomR #-}
random = first CFloat . random
{-# INLINE random #-}
instance Random CDouble where
randomR (CDouble l, CDouble h) = first CDouble . randomR (l, h)
{-# INLINE randomR #-}
random = first CDouble . random
{-# INLINE random #-}

instance Random Char
instance Random Bool
instance Random Double where
randomR r g = runStateGen g (uniformRM r)
{-# INLINE randomR #-}
-- We return 1 - uniformDouble01M here for backwards compatibility with
-- v1.2.0. Just return the result of uniformDouble01M in the next major
-- version.
random g = runStateGen g (\gen -> (1 -) <$> uniformDouble01M gen)
{-# INLINE random #-}
instance Random Float where
randomR r g = runStateGen g (uniformRM r)
{-# INLINE randomR #-}
-- We return 1 - uniformFloat01M here for backwards compatibility with
-- v1.2.0. Just return the result of uniformFloat01M in the next major
-- version.
random g = runStateGen g (\gen -> (1 -) <$> uniformFloat01M gen)
{-# INLINE random #-}

-------------------------------------------------------------------------------
-- Global pseudo-random number generator
Expand Down
Loading

0 comments on commit c9471d4

Please sign in to comment.