2020-01-24 23:41:49 +03:00
|
|
|
{-# LANGUAGE DataKinds #-}
|
|
|
|
{-# LANGUAGE FlexibleContexts #-}
|
|
|
|
{-# LANGUAGE PackageImports #-}
|
|
|
|
{-# LANGUAGE PartialTypeSignatures #-}
|
|
|
|
{-# LANGUAGE TypeApplications #-}
|
|
|
|
{-# LANGUAGE TypeFamilies #-}
|
2018-07-18 18:38:28 +03:00
|
|
|
|
2019-10-04 19:37:24 +03:00
|
|
|
module Evaluation (benchmarks) where
|
2018-03-08 03:34:20 +03:00
|
|
|
|
2019-10-04 19:37:24 +03:00
|
|
|
import Control.Carrier.Parse.Simple
|
2019-09-27 20:18:30 +03:00
|
|
|
import Data.Abstract.Evaluatable
|
2020-01-24 23:41:49 +03:00
|
|
|
import Data.Bifunctor
|
2019-09-27 20:18:30 +03:00
|
|
|
import Data.Blob
|
|
|
|
import Data.Blob.IO (readBlobFromFile')
|
2020-01-24 23:41:49 +03:00
|
|
|
import qualified Data.Duration as Duration
|
2019-10-30 20:29:45 +03:00
|
|
|
import "semantic" Data.Graph (topologicalSort)
|
2018-07-18 18:38:28 +03:00
|
|
|
import qualified Data.Language as Language
|
2019-09-27 20:18:30 +03:00
|
|
|
import Data.Project
|
2018-07-18 18:38:28 +03:00
|
|
|
import Data.Proxy
|
2019-09-27 20:18:30 +03:00
|
|
|
import Gauge.Main
|
2018-07-18 18:38:28 +03:00
|
|
|
import Parsing.Parser
|
|
|
|
import Semantic.Config (defaultOptions)
|
2019-09-27 20:18:30 +03:00
|
|
|
import Semantic.Graph
|
2019-10-30 20:29:45 +03:00
|
|
|
import Semantic.Task (TaskSession (..), runTask, withOptions)
|
2019-10-23 18:36:36 +03:00
|
|
|
import Semantic.Util
|
2019-09-27 20:18:30 +03:00
|
|
|
import System.Path ((</>))
|
2020-01-24 23:41:49 +03:00
|
|
|
import qualified System.Path as Path
|
2018-07-18 18:38:28 +03:00
|
|
|
|
|
|
|
-- Duplicating this stuff from Util to shut off the logging
|
2019-09-27 20:18:30 +03:00
|
|
|
|
|
|
|
callGraphProject' :: ( Language.SLanguage lang
|
|
|
|
, HasPrelude lang
|
|
|
|
)
|
|
|
|
=> TaskSession
|
|
|
|
-> Proxy lang
|
|
|
|
-> Path.RelFile
|
2019-10-25 21:22:50 +03:00
|
|
|
-> IO (Either String ())
|
2019-10-23 18:45:45 +03:00
|
|
|
callGraphProject' session proxy path
|
2019-10-30 20:29:45 +03:00
|
|
|
| Just (SomeParser parser) <- parserForLanguage analysisParsers lang = fmap (bimap show (const ())) . runTask session $ do
|
2020-01-25 00:13:19 +03:00
|
|
|
blob <- readBlobFromPath path
|
2019-10-23 18:45:45 +03:00
|
|
|
package <- fmap snd <$> runParse (Duration.fromSeconds 10) (parsePackage parser (Project (Path.toString (Path.takeDirectory path)) [blob] lang []))
|
2019-09-27 20:18:30 +03:00
|
|
|
modules <- topologicalSort <$> runImportGraphToModules proxy package
|
2019-10-25 21:34:54 +03:00
|
|
|
runCallGraph proxy False modules package
|
2019-10-30 20:29:45 +03:00
|
|
|
| otherwise = error $ "Analysis not supported for: " <> show lang
|
|
|
|
where lang = Language.reflect proxy
|
2019-09-27 20:18:30 +03:00
|
|
|
|
2019-10-23 18:45:45 +03:00
|
|
|
callGraphProject proxy paths = withOptions defaultOptions $ \ config logger statter ->
|
|
|
|
callGraphProject' (TaskSession config "" False logger statter) proxy paths
|
2019-09-27 20:18:30 +03:00
|
|
|
|
2019-10-23 18:48:01 +03:00
|
|
|
evaluateProject proxy path
|
2019-10-30 20:29:45 +03:00
|
|
|
| Just (SomeParser parser) <- parserForLanguage analysisParsers lang = withOptions defaultOptions $ \ config logger statter ->
|
2019-10-23 18:46:33 +03:00
|
|
|
fmap (const ()) . justEvaluating =<< evaluateProject' (TaskSession config "" False logger statter) proxy parser [Path.toString path]
|
2019-10-30 20:29:45 +03:00
|
|
|
| otherwise = error $ "Analysis not supported for: " <> show lang
|
|
|
|
where lang = Language.reflect proxy
|
2018-03-08 03:34:20 +03:00
|
|
|
|
2019-09-27 20:18:30 +03:00
|
|
|
pyEval :: Path.RelFile -> Benchmarkable
|
2019-10-23 18:48:01 +03:00
|
|
|
pyEval p = nfIO $ evaluateProject (Proxy @'Language.Python) (Path.relDir "bench/bench-fixtures/python" </> p)
|
2018-03-08 03:34:20 +03:00
|
|
|
|
2019-09-27 20:18:30 +03:00
|
|
|
rbEval :: Path.RelFile -> Benchmarkable
|
2019-10-23 18:48:01 +03:00
|
|
|
rbEval p = nfIO $ evaluateProject (Proxy @'Language.Ruby) (Path.relDir "bench/bench-fixtures/ruby" </> p)
|
2018-07-18 18:38:28 +03:00
|
|
|
|
2019-09-27 20:18:30 +03:00
|
|
|
pyCall :: Path.RelFile -> Benchmarkable
|
2019-10-23 18:45:45 +03:00
|
|
|
pyCall p = nfIO $ callGraphProject (Proxy @'Language.Python) (Path.relDir "bench/bench-fixtures/python/" </> p)
|
2018-07-18 18:38:28 +03:00
|
|
|
|
2019-09-27 20:18:30 +03:00
|
|
|
rbCall :: Path.RelFile -> Benchmarkable
|
2019-10-23 18:45:45 +03:00
|
|
|
rbCall p = nfIO $ callGraphProject (Proxy @'Language.Ruby) (Path.relDir "bench/bench-fixtures/ruby" </> p)
|
2018-03-08 03:34:20 +03:00
|
|
|
|
2019-10-04 19:37:24 +03:00
|
|
|
benchmarks :: Benchmark
|
|
|
|
benchmarks = bgroup "evaluation"
|
2019-09-27 20:18:30 +03:00
|
|
|
[ bgroup "python" [ bench "assignment" . pyEval $ Path.relFile "simple-assignment.py"
|
|
|
|
, bench "function def" . pyEval $ Path.relFile "function-definition.py"
|
|
|
|
, bench "if + function calls" . pyCall . Path.relFile $ "if-statement-functions.py"
|
|
|
|
, bench "call graph" $ pyCall . Path.relFile $ "if-statement-functions.py"
|
2018-03-12 17:51:07 +03:00
|
|
|
]
|
2019-09-27 20:18:30 +03:00
|
|
|
, bgroup "ruby" [ bench "assignment" . rbEval $ Path.relFile "simple-assignment.rb"
|
|
|
|
, bench "function def" . rbEval . Path.relFile $ "function-definition.rb"
|
|
|
|
, bench "if + function calls" . rbCall $ Path.relFile "if-statement-functions.rb"
|
|
|
|
, bench "call graph" $ rbCall $ Path.relFile "if-statement-functions.rb"
|
2018-03-08 03:47:23 +03:00
|
|
|
]
|
2018-03-08 03:34:20 +03:00
|
|
|
]
|