1
1
mirror of https://github.com/github/semantic.git synced 2024-12-29 18:06:14 +03:00

Associate blobs with modules.

This commit is contained in:
Rob Rix 2018-08-02 13:58:57 -04:00
parent 6e86024bef
commit eeee3105de
3 changed files with 9 additions and 8 deletions

View File

@ -37,6 +37,7 @@ import Data.Abstract.Package as Package
import Data.Abstract.Value.Abstract as Abstract
import Data.Abstract.Value.Concrete as Concrete (Value, ValueError (..), runFunction, runValueErrorWith)
import Data.Abstract.Value.Type as Type
import Data.Blob
import Data.Coerce
import Data.Graph
import Data.Graph.Vertex (VertexDeclarationStrategy, VertexDeclarationWithStrategy)
@ -62,11 +63,11 @@ runGraph :: forall effs. (Member Distribute effs, Member (Exc SomeException) eff
-> Eff effs (Graph Vertex)
runGraph ImportGraph _ project
| SomeAnalysisParser parser lang <- someAnalysisParser (Proxy :: Proxy AnalysisClasses) (projectLanguage project) = do
package <- parsePackage parser project
package <- fmap snd <$> parsePackage parser project
runImportGraphToModuleInfos lang package
runGraph CallGraph includePackages project
| SomeAnalysisParser parser lang <- someAnalysisParser (Proxy :: Proxy AnalysisClasses) (projectLanguage project) = do
package <- parsePackage parser project
package <- fmap snd <$> parsePackage parser project
modules <- topologicalSort <$> runImportGraphToModules lang package
runCallGraph lang includePackages modules package
@ -213,7 +214,7 @@ newtype ImportGraphEff address outerEffects a = ImportGraphEff
parsePackage :: (Member Distribute effs, Member (Exc SomeException) effs, Member Resolution effs, Member Task effs, Member Trace effs)
=> Parser term -- ^ A parser.
-> Project -- ^ Project to parse into a package.
-> Eff effs (Package term)
-> Eff effs (Package (Blob, term))
parsePackage parser project = do
p <- parseModules parser project
resMap <- Task.resolutionMap project
@ -228,7 +229,7 @@ parsePackage parser project = do
parseModule proj parser file = do
mBlob <- readFile proj file
case mBlob of
Just blob -> moduleForBlob (Just (projectRootDir proj)) blob <$> parse parser blob
Just blob -> moduleForBlob (Just (projectRootDir proj)) blob . (,) blob <$> parse parser blob
Nothing -> throwError (SomeException (FileNotFound (filePath file)))
withTermSpans :: ( HasField fields Span

View File

@ -81,7 +81,7 @@ rubyREPL = repl (Proxy :: Proxy 'Language.Ruby) rubyParser
repl proxy parser paths = runTaskWithOptions debugOptions $ do
blobs <- catMaybes <$> traverse IO.readFile (flip File (Language.reflect proxy) <$> paths)
package <- fmap quieterm <$> parsePackage parser (Project (takeDirectory (maybe "/" fst (uncons paths))) blobs (Language.reflect proxy) [])
package <- fmap (quieterm . snd) <$> parsePackage parser (Project (takeDirectory (maybe "/" fst (uncons paths))) blobs (Language.reflect proxy) [])
modules <- topologicalSort <$> runImportGraphToModules proxy package
runEvaluator
. runREPL

View File

@ -107,7 +107,7 @@ typecheckGoFile = checking <=< evaluateProjectWithCaching (Proxy :: Proxy 'Langu
callGraphProject parser proxy opts paths = runTaskWithOptions opts $ do
blobs <- catMaybes <$> traverse readFile (flip File (Language.reflect proxy) <$> paths)
package <- parsePackage parser (Project (takeDirectory (maybe "/" fst (uncons paths))) blobs (Language.reflect proxy) [])
package <- fmap snd <$> parsePackage parser (Project (takeDirectory (maybe "/" fst (uncons paths))) blobs (Language.reflect proxy) [])
modules <- topologicalSort <$> runImportGraphToModules proxy package
x <- runCallGraph proxy False modules package
pure (x, (() <$) <$> modules)
@ -122,7 +122,7 @@ data TaskConfig = TaskConfig Config LogQueue StatQueue
evaluateProject' (TaskConfig config logger statter) proxy parser paths = either (die . displayException) pure <=< runTaskWithConfig config logger statter $ do
blobs <- catMaybes <$> traverse readFile (flip File (Language.reflect proxy) <$> paths)
package <- fmap quieterm <$> parsePackage parser (Project (takeDirectory (maybe "/" fst (uncons paths))) blobs (Language.reflect proxy) [])
package <- fmap (quieterm . snd) <$> parsePackage parser (Project (takeDirectory (maybe "/" fst (uncons paths))) blobs (Language.reflect proxy) [])
modules <- topologicalSort <$> runImportGraphToModules proxy package
trace $ "evaluating with load order: " <> show (map (modulePath . moduleInfo) modules)
pure (runTermEvaluator @_ @_ @(Value Precise (UtilEff Precise))
@ -135,7 +135,7 @@ evaluateProject' (TaskConfig config logger statter) proxy parser paths = either
evaluateProjectWithCaching proxy parser path = runTaskWithOptions debugOptions $ do
project <- readProject Nothing path (Language.reflect proxy) []
package <- fmap quieterm <$> parsePackage parser project
package <- fmap (quieterm . snd) <$> parsePackage parser project
modules <- topologicalSort <$> runImportGraphToModules proxy package
pure (runReader (packageInfo package)
(runReader (lowerBound @Span)