2020-01-24 23:41:49 +03:00
|
|
|
{-# LANGUAGE FlexibleContexts #-}
|
2020-01-07 03:25:20 +03:00
|
|
|
{-# LANGUAGE OverloadedStrings #-}
|
2020-01-24 23:41:49 +03:00
|
|
|
{-# LANGUAGE TypeApplications #-}
|
2020-01-07 03:25:20 +03:00
|
|
|
|
|
|
|
module Tagging (benchmarks) where
|
|
|
|
|
|
|
|
import Control.Carrier.Parse.Measured
|
|
|
|
import Control.Carrier.Reader
|
2020-01-14 00:20:16 +03:00
|
|
|
import Control.Exception (throwIO)
|
2020-01-07 03:25:20 +03:00
|
|
|
import Control.Monad
|
|
|
|
import Data.Foldable
|
2020-06-05 00:00:06 +03:00
|
|
|
import Data.Language (PerLanguageModes (..), preciseLanguageModes)
|
2020-01-07 03:25:20 +03:00
|
|
|
import Gauge
|
|
|
|
import System.FilePath.Glob
|
|
|
|
import qualified System.Path as Path
|
|
|
|
|
2020-01-26 19:39:57 +03:00
|
|
|
import qualified Analysis.File as File
|
|
|
|
import Data.Flag
|
2020-04-03 22:52:33 +03:00
|
|
|
import Proto.Semantic as P hiding (Blob)
|
2020-01-26 19:39:57 +03:00
|
|
|
import Semantic.Api.Symbols (parseSymbols)
|
|
|
|
import Semantic.Config as Config
|
|
|
|
import Semantic.Task
|
|
|
|
import Semantic.Task.Files
|
2020-01-07 03:25:20 +03:00
|
|
|
|
|
|
|
benchmarks :: Benchmark
|
|
|
|
benchmarks = bgroup "tagging"
|
2020-01-08 04:08:35 +03:00
|
|
|
[ pythonBenchmarks
|
|
|
|
, goBenchmarks
|
|
|
|
, rubyBenchmarks
|
2020-01-07 03:25:20 +03:00
|
|
|
]
|
|
|
|
|
|
|
|
pythonBenchmarks :: Benchmark
|
|
|
|
pythonBenchmarks = bgroup "python"
|
|
|
|
[ bench "precise" $ runTagging preciseLanguageModes pyDir "*.py"
|
|
|
|
]
|
|
|
|
where pyDir = Path.relDir "tmp/python-examples/keras/keras"
|
|
|
|
|
|
|
|
goBenchmarks :: Benchmark
|
|
|
|
goBenchmarks = bgroup "go"
|
|
|
|
[ bench "precise" $ runTagging preciseLanguageModes dir "*.go"
|
|
|
|
]
|
|
|
|
where dir = Path.relDir "tmp/go-examples/go/src/database/sql"
|
|
|
|
|
2020-01-07 20:25:12 +03:00
|
|
|
rubyBenchmarks :: Benchmark
|
|
|
|
rubyBenchmarks = bgroup "ruby"
|
|
|
|
[ bench "precise" $ runTagging preciseLanguageModes dir "*.rb"
|
|
|
|
]
|
2020-01-10 01:06:24 +03:00
|
|
|
where dir = Path.relDir "tmp/ruby-examples/ruby_spec/command_line"
|
2020-01-07 20:25:12 +03:00
|
|
|
|
2020-01-07 03:25:20 +03:00
|
|
|
runTagging :: PerLanguageModes -> Path.RelDir -> String -> Benchmarkable
|
|
|
|
runTagging mode dir glob = nfIO . withOptions testOptions $ \ config logger statter -> do
|
|
|
|
let session = TaskSession config "-" False logger statter
|
|
|
|
files <- globDir1 (compile glob) (Path.toString dir)
|
|
|
|
let paths = Path.relFile <$> files
|
2020-01-14 00:18:18 +03:00
|
|
|
for_ paths (runTask session . runParse . parseSymbolsFilePath mode >=> either throwIO pure)
|
2020-01-07 03:25:20 +03:00
|
|
|
|
|
|
|
parseSymbolsFilePath ::
|
|
|
|
( Has (Error SomeException) sig m
|
|
|
|
, Has Distribute sig m
|
|
|
|
, Has Parse sig m
|
|
|
|
, Has Files sig m
|
|
|
|
)
|
|
|
|
=> PerLanguageModes
|
|
|
|
-> Path.RelFile
|
|
|
|
-> m ParseTreeSymbolResponse
|
2020-01-24 23:41:49 +03:00
|
|
|
parseSymbolsFilePath languageModes path = readBlob (File.fromPath path) >>= runReader languageModes . parseSymbols . pure @[]
|
2020-01-07 03:25:20 +03:00
|
|
|
|
|
|
|
testOptions :: Config.Options
|
|
|
|
testOptions = defaultOptions
|
|
|
|
{ optionsFailOnWarning = flag FailOnWarning True
|
|
|
|
, optionsLogLevel = Nothing
|
|
|
|
}
|