{-# LANGUAGE BangPatterns #-}
{-# OPTIONS_GHC -O2 -fno-prof-auto #-}
{-# OPTIONS_GHC -fno-full-laziness #-}
module Criterion.Measurement.Types.Internal (fakeEnvironment, nf', whnf') where
import Data.Int (Int64)
fakeEnvironment :: env
fakeEnvironment :: env
fakeEnvironment = [Char] -> env
forall a. HasCallStack => [Char] -> a
error ([Char] -> env) -> [Char] -> env
forall a b. (a -> b) -> a -> b
$ [[Char]] -> [Char]
unlines
[ [Char]
"Criterion atttempted to retrieve a non-existent environment!"
, [Char]
"\tPerhaps you forgot to use lazy pattern matching in a function which"
, [Char]
"\tconstructs benchmarks from an environment?"
, [Char]
"\t(see the documentation for `env` for details)"
]
nf' :: (b -> ()) -> (a -> b) -> a -> (Int64 -> IO ())
nf' :: (b -> ()) -> (a -> b) -> a -> Int64 -> IO ()
nf' b -> ()
reduce a -> b
f a
x = Int64 -> IO ()
forall t (m :: * -> *). (Ord t, Num t, Monad m) => t -> m ()
go
where
go :: t -> m ()
go t
n | t
n t -> t -> Bool
forall a. Ord a => a -> a -> Bool
<= t
0 = () -> m ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
| Bool
otherwise = let !y :: b
y = a -> b
f a
x
in b -> ()
reduce b
y () -> m () -> m ()
`seq` t -> m ()
go (t
nt -> t -> t
forall a. Num a => a -> a -> a
-t
1)
{-# NOINLINE nf' #-}
whnf' :: (a -> b) -> a -> (Int64 -> IO ())
whnf' :: (a -> b) -> a -> Int64 -> IO ()
whnf' a -> b
f a
x = Int64 -> IO ()
forall t (m :: * -> *). (Ord t, Num t, Monad m) => t -> m ()
go
where
go :: t -> m ()
go t
n | t
n t -> t -> Bool
forall a. Ord a => a -> a -> Bool
<= t
0 = () -> m ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
| Bool
otherwise = a -> b
f a
x b -> m () -> m ()
`seq` t -> m ()
go (t
nt -> t -> t
forall a. Num a => a -> a -> a
-t
1)
{-# NOINLINE whnf' #-}