1
1
mirror of https://github.com/github/semantic.git synced 2024-12-22 14:21:31 +03:00

Compute the import graph for a package.

Co-Authored-By: Timothy Clem <timothy.clem@gmail.com>
This commit is contained in:
Rob Rix 2018-04-04 12:40:09 -04:00
parent 9a8bce4b78
commit e35c96a676

View File

@ -45,7 +45,8 @@ import Data.Abstract.Address
import qualified Data.Abstract.Evaluatable as Analysis
import Data.Abstract.FreeVariables
import Data.Abstract.Located
import Data.Abstract.Package
import Data.Abstract.Module
import Data.Abstract.Package as Package
import Data.Abstract.Value (Value)
import Data.Blob
import Data.Bool
@ -74,7 +75,7 @@ data TaskF output where
ReadBlobPairs :: Either Handle [Both (FilePath, Maybe Language)] -> TaskF [BlobPair]
WriteToOutput :: Either Handle FilePath -> B.ByteString -> TaskF ()
Parse :: Parser term -> Blob -> TaskF term
ImportGraph :: (Apply Eq1 syntax, Apply Analysis.Evaluatable syntax, Apply FreeVariables1 syntax, Apply Functor syntax, Apply Ord1 syntax, Apply Show1 syntax, Member Syntax.Identifier syntax, Ord ann, Show ann) => PackageBody (Term (Union syntax) ann) -> TaskF B.ByteString
ImportGraph :: (Apply Eq1 syntax, Apply Analysis.Evaluatable syntax, Apply FreeVariables1 syntax, Apply Functor syntax, Apply Ord1 syntax, Apply Show1 syntax, Member Syntax.Identifier syntax, Ord ann, Show ann) => Package (Term (Union syntax) ann) -> TaskF B.ByteString
Decorate :: Functor f => RAlgebra (TermF f (Record fields)) (Term f (Record fields)) field -> Term f (Record fields) -> TaskF (Term f (Record (field ': fields)))
Diff :: Differ syntax ann1 ann2 -> Term syntax ann1 -> Term syntax ann2 -> TaskF (Diff syntax ann1 ann2)
Render :: Renderer input output -> input -> TaskF output
@ -121,7 +122,7 @@ render :: Member TaskF effs => Renderer input output -> input -> Eff effs output
render renderer = send . Render renderer
importGraph :: (Apply Eq1 syntax, Apply Analysis.Evaluatable syntax, Apply FreeVariables1 syntax, Apply Functor syntax, Apply Ord1 syntax, Apply Show1 syntax, Member Syntax.Identifier syntax, Ord ann, Show ann) => Member TaskF effs => PackageBody (Term (Union syntax) ann) -> Eff effs B.ByteString
importGraph :: (Apply Eq1 syntax, Apply Analysis.Evaluatable syntax, Apply FreeVariables1 syntax, Apply Functor syntax, Apply Ord1 syntax, Apply Show1 syntax, Member Syntax.Identifier syntax, Ord ann, Show ann) => Member TaskF effs => Package (Term (Union syntax) ann) -> Eff effs B.ByteString
importGraph package = send (ImportGraph package)
@ -204,11 +205,11 @@ runTaskF = interpret $ \ task -> case task of
Semantic.Task.Diff differ term1 term2 -> pure (differ term1 term2)
Render renderer input -> pure (renderer input)
ImportGraph package -> do
let result = Analysis.runAnalysis (Analysis.evaluatePackageBody package `asAnalysisForTypeOfPackage` package)
let result = Analysis.runAnalysis (Analysis.evaluatePackage package `asAnalysisForTypeOfPackage` package)
case result of
(Right (Right (Right (Right (Right (_, graph))))), _) -> pure $ Abstract.renderImportGraph graph
_ -> error "blah"
where asAnalysisForTypeOfPackage :: Abstract.ImportGraphing (Evaluating (Located Precise (Term (Union syntax) ann)) (Term (Union syntax) ann) (Value (Located Precise (Term (Union syntax) ann)))) effects value -> PackageBody (Term (Union syntax) ann) -> Abstract.ImportGraphing (Evaluating (Located Precise (Term (Union syntax) ann)) (Term (Union syntax) ann) (Value (Located Precise (Term (Union syntax) ann)))) effects value
where asAnalysisForTypeOfPackage :: Abstract.ImportGraphing (Evaluating (Located Precise (Term (Union syntax) ann)) (Term (Union syntax) ann) (Value (Located Precise (Term (Union syntax) ann)))) effects value -> Package (Term (Union syntax) ann) -> Abstract.ImportGraphing (Evaluating (Located Precise (Term (Union syntax) ann)) (Term (Union syntax) ann) (Value (Located Precise (Term (Union syntax) ann)))) effects value
asAnalysisForTypeOfPackage = const