Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix node scanning for ImportTree #3251

Merged
merged 6 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 34 additions & 4 deletions src/Juvix/Compiler/Concrete/Print/Base.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@ import Juvix.Compiler.Concrete.Language.Base
import Juvix.Compiler.Concrete.Pretty.Options
import Juvix.Compiler.Concrete.Translation.ImportScanner.Base
import Juvix.Compiler.Pipeline.Loader.PathResolver.Data
import Juvix.Compiler.Pipeline.Loader.PathResolver.PackageInfo
import Juvix.Compiler.Store.Scoped.Language (Alias, ModuleSymbolEntry, PreSymbolEntry (..), ScopedModule, SymbolEntry, aliasName, moduleEntry, scopedModuleName, symbolEntry)
import Juvix.Data.Ape.Base
import Juvix.Data.Ape.Print
import Juvix.Data.CodeAnn (Ann, CodeAnn (..), CodeAnnReference (..), ppStringLit)
import Juvix.Data.CodeAnn (Ann, CodeAnn (..), CodeAnnReference (..), ppCodeAnn, ppStringLit)
import Juvix.Data.CodeAnn qualified as C
import Juvix.Data.Effect.ExactPrint
import Juvix.Data.Keyword.All qualified as Kw
Expand Down Expand Up @@ -1314,6 +1315,19 @@ instance (SingI s) => PrettyPrint (UsingItem s) where
kwmodule = ppCode <$> (ui ^. usingModuleKw)
kwmodule <?+> (sym' <+?> kwAs' <+?> alias')

instance PrettyPrint PackageInfo where
ppCode PackageInfo {..} = do
header ("Package name: " <> (_packagePackage ^. packageLikeName))
noLoc ("root:" P.<+> pretty _packageRoot)
let roots = case nonEmpty _packageAvailableRoots of
Nothing -> return ()
Just roots1 -> hardline <> indent (itemize (fmap (noLoc . pretty) roots1))
hardline
noLoc ("available roots:") <> roots
hardline
noLoc ("package id:" P.<+> ppCodeAnn _packageInfoPackageId)
hardline

instance PrettyPrint ImportTreeStats where
ppCode ImportTreeStats {..} = do
header "Import Tree Statistics:"
Expand All @@ -1331,19 +1345,35 @@ instance PrettyPrint ImportTree where
header "============"
hardline

header ("Packages (" <> show (length importsTable) <> "):")
header "========="
itemize . map (noLoc . pretty) $ Map.keys importsTable
hardline

hardline
forM_ (Map.toList importsTable) $ \(pkgRoot, tbl :: Map (Path Rel File) (Set ImportNode)) -> do
annotated AnnImportant (noLoc ("* Package at " <> pretty pkgRoot))
hardline
let pkgNodes :: HashSet ImportNode = fromJust (nodesByRoot ^. at pkgRoot)
header ("Nodes (" <> show (length pkgNodes) <> ")")
header ("Nodes Relative paths (" <> show (length pkgNodes) <> ")")
forM_ pkgNodes $ \node -> do
noLoc (pMod (node ^. importNodeFile))
hardline
hardline
header ("Nodes Absolute paths (" <> show (length pkgNodes) <> ")")
forM_ pkgNodes $ \node -> do
noLoc (pMod (node ^. importNodeAbsFile))
hardline
hardline
let numEdges = sum (map length (toList tbl))
header ("Edges (" <> show numEdges <> ")")
forM_ (Map.toList tbl) $ \(fromFile, toFiles) -> do
noLoc (pMod fromFile P.<+> annotate AnnKeyword "imports" P.<+> "(" <> pretty (length toFiles) <> "):")
forM_ (Map.toList tbl) $ \(fromFile, toFiles :: Set ImportNode) -> do
let fromNode :: ImportNode =
ImportNode
{ _importNodePackageRoot = pkgRoot,
_importNodeFile = fromFile
}
noLoc (pMod fromFile P.<+> "at" P.<+> pMod (fromNode ^. importNodeAbsFile) P.<+> annotate AnnKeyword "imports" P.<+> "(" <> pretty (length toFiles) <> "):")
hardline
indent . itemize . (`map` (toList toFiles)) $ \toFile -> do
let toMod
Expand Down
4 changes: 1 addition & 3 deletions src/Juvix/Compiler/Pipeline/Driver.hs
Original file line number Diff line number Diff line change
Expand Up @@ -335,9 +335,7 @@ processImport p = withPathFile p getCachedImport
hasParallelSupport <- supportsParallel
eix <- mkEntryIndex node
if
| hasParallelSupport -> do
res <- cacheGetResult eix
return (res ^. cacheResult)
| hasParallelSupport -> cacheGet eix
| otherwise -> processModule eix

processFileUpToParsing ::
Expand Down
4 changes: 2 additions & 2 deletions src/Juvix/Compiler/Pipeline/Loader/PathResolver/ImportTree.hs
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,12 @@ mkImportTree mentrypointModulePath =
) =>
ImportNode ->
Sem r' ()
scanNode fromNode = withImportNode fromNode $ do
scanNode fromNode = withResolverRoot (fromNode ^. importNodePackageRoot) . withImportNode fromNode $ do
scans <- toList <$> getNodeImports fromNode
imports :: [ImportNode] <- mapM resolveImportScan scans
forM_ (zipExact scans imports) $ \(importscan, toNode) -> do
importTreeAddEdge importscan toNode
withResolverRoot (toNode ^. importNodePackageRoot) (visit toNode)
visit toNode

resolveImportScan :: forall r'. (Members '[PathResolver] r') => ImportScan -> Sem r' ImportNode
resolveImportScan s = do
Expand Down
Loading