{-# OPTIONS_GHC -fno-warn-orphans #-}
module Agda.Benchmarking where
import qualified Control.Exception as E
import Data.IORef
import System.IO.Unsafe
import Agda.Syntax.Concrete.Name (TopLevelModuleName)
import Agda.Syntax.Concrete.Pretty ()
import Agda.Syntax.Abstract.Name
import Agda.Utils.Benchmark (MonadBench(..))
import qualified Agda.Utils.Benchmark as B
import Agda.Utils.Null
import Agda.Utils.Pretty
data Phase
= Parsing
| Import
| Deserialization
| Scoping
| Typing
| Termination
| Positivity
| Injectivity
| ProjectionLikeness
| Coverage
| Highlighting
| Serialization
| DeadCode
| Graph
| RecCheck
| Reduce
| Level
| Compare
| With
| ModuleName
| Compaction
| BuildInterface
| Sort
| BinaryEncode
| Compress
| OperatorsExpr
| OperatorsPattern
| Free
| OccursCheck
| CheckLHS
| CheckRHS
| TypeSig
| Generalize
| InstanceSearch
| UnifyIndices
| InverseScopeLookup
| TopModule TopLevelModuleName
| Definition QName
deriving (Phase -> Phase -> Bool
(Phase -> Phase -> Bool) -> (Phase -> Phase -> Bool) -> Eq Phase
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Phase -> Phase -> Bool
$c/= :: Phase -> Phase -> Bool
== :: Phase -> Phase -> Bool
$c== :: Phase -> Phase -> Bool
Eq, Eq Phase
Eq Phase
-> (Phase -> Phase -> Ordering)
-> (Phase -> Phase -> Bool)
-> (Phase -> Phase -> Bool)
-> (Phase -> Phase -> Bool)
-> (Phase -> Phase -> Bool)
-> (Phase -> Phase -> Phase)
-> (Phase -> Phase -> Phase)
-> Ord Phase
Phase -> Phase -> Bool
Phase -> Phase -> Ordering
Phase -> Phase -> Phase
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: Phase -> Phase -> Phase
$cmin :: Phase -> Phase -> Phase
max :: Phase -> Phase -> Phase
$cmax :: Phase -> Phase -> Phase
>= :: Phase -> Phase -> Bool
$c>= :: Phase -> Phase -> Bool
> :: Phase -> Phase -> Bool
$c> :: Phase -> Phase -> Bool
<= :: Phase -> Phase -> Bool
$c<= :: Phase -> Phase -> Bool
< :: Phase -> Phase -> Bool
$c< :: Phase -> Phase -> Bool
compare :: Phase -> Phase -> Ordering
$ccompare :: Phase -> Phase -> Ordering
$cp1Ord :: Eq Phase
Ord, Int -> Phase -> ShowS
[Phase] -> ShowS
Phase -> String
(Int -> Phase -> ShowS)
-> (Phase -> String) -> ([Phase] -> ShowS) -> Show Phase
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Phase] -> ShowS
$cshowList :: [Phase] -> ShowS
show :: Phase -> String
$cshow :: Phase -> String
showsPrec :: Int -> Phase -> ShowS
$cshowsPrec :: Int -> Phase -> ShowS
Show)
instance Pretty Phase where
pretty :: Phase -> Doc
pretty (TopModule TopLevelModuleName
m) = TopLevelModuleName -> Doc
forall a. Pretty a => a -> Doc
pretty TopLevelModuleName
m
pretty (Definition QName
q) = QName -> Doc
forall a. Pretty a => a -> Doc
pretty QName
q
pretty Phase
a = String -> Doc
text (Phase -> String
forall a. Show a => a -> String
show Phase
a)
type Benchmark = B.Benchmark Phase
type Account = B.Account Phase
isModuleAccount :: Account -> Bool
isModuleAccount :: [Phase] -> Bool
isModuleAccount [] = Bool
True
isModuleAccount (TopModule{} : [Phase]
_) = Bool
True
isModuleAccount [Phase]
_ = Bool
False
isDefAccount :: Account -> Bool
isDefAccount :: [Phase] -> Bool
isDefAccount [] = Bool
True
isDefAccount (Definition{} : [Phase]
_) = Bool
True
isDefAccount [Phase]
_ = Bool
False
isInternalAccount :: Account -> Bool
isInternalAccount :: [Phase] -> Bool
isInternalAccount (TopModule{} : [Phase]
_) = Bool
False
isInternalAccount (Definition{} : [Phase]
_) = Bool
False
isInternalAccount [Phase]
_ = Bool
True
{-# NOINLINE benchmarks #-}
benchmarks :: IORef Benchmark
benchmarks :: IORef Benchmark
benchmarks = IO (IORef Benchmark) -> IORef Benchmark
forall a. IO a -> a
unsafePerformIO (IO (IORef Benchmark) -> IORef Benchmark)
-> IO (IORef Benchmark) -> IORef Benchmark
forall a b. (a -> b) -> a -> b
$ Benchmark -> IO (IORef Benchmark)
forall a. a -> IO (IORef a)
newIORef Benchmark
forall a. Null a => a
empty
instance MonadBench Phase IO where
getBenchmark :: IO Benchmark
getBenchmark = IORef Benchmark -> IO Benchmark
forall a. IORef a -> IO a
readIORef IORef Benchmark
benchmarks
putBenchmark :: Benchmark -> IO ()
putBenchmark = IORef Benchmark -> Benchmark -> IO ()
forall a. IORef a -> a -> IO ()
writeIORef IORef Benchmark
benchmarks
finally :: IO b -> IO c -> IO b
finally = IO b -> IO c -> IO b
forall b c. IO b -> IO c -> IO b
E.finally
billToIO :: Account -> IO a -> IO a
billToIO :: [Phase] -> IO a -> IO a
billToIO = [Phase] -> IO a -> IO a
forall a (m :: * -> *) c. MonadBench a m => Account a -> m c -> m c
B.billTo
billToPure :: Account -> a -> a
billToPure :: [Phase] -> a -> a
billToPure [Phase]
acc a
a = IO a -> a
forall a. IO a -> a
unsafePerformIO (IO a -> a) -> IO a -> a
forall a b. (a -> b) -> a -> b
$ [Phase] -> IO a -> IO a
forall a. [Phase] -> IO a -> IO a
billToIO [Phase]
acc (IO a -> IO a) -> IO a -> IO a
forall a b. (a -> b) -> a -> b
$ a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return a
a