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

Store the DocTable in the .jvo file #3021

Merged
merged 1 commit into from
Sep 11, 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
6 changes: 6 additions & 0 deletions src/Juvix/Compiler/Concrete/Data/Highlight/Builder.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ module Juvix.Compiler.Concrete.Data.Highlight.Builder
)
where

import Data.HashMap.Strict qualified as HashMap
import Juvix.Compiler.Concrete.Data.Highlight.Input
import Juvix.Compiler.Concrete.Data.ParsedItem
import Juvix.Compiler.Concrete.Data.ScopedName
import Juvix.Compiler.Concrete.Language.Base
import Juvix.Compiler.Internal.Language qualified as Internal
import Juvix.Compiler.Internal.Translation.FromInternal.Analysis.TypeChecking.Data.Context
import Juvix.Compiler.Store.Scoped.Data.InfoTable
import Juvix.Prelude

data HighlightBuilder :: Effect where
Expand All @@ -19,6 +21,8 @@ data HighlightBuilder :: Effect where
HighlightName :: AName -> HighlightBuilder m ()
HighlightParsedItem :: ParsedItem -> HighlightBuilder m ()
HighlightType :: NameId -> Internal.Expression -> HighlightBuilder m ()
HighlightMergeDocTable :: DocTable -> HighlightBuilder m ()
GetDocTable :: ModuleId -> HighlightBuilder m DocTable

makeSem ''HighlightBuilder

Expand All @@ -29,6 +33,8 @@ runHighlightBuilder = reinterpret (runStateShared emptyHighlightInput) $ \case
HighlightParsedItem p -> modifyShared (over (highlightParsedItems) (p :))
HighlightDoc k md -> modifyShared (set (highlightDocTable . at k) md)
HighlightType uid ty -> modifyShared (set (highlightTypes . typesTable . at uid) (Just ty))
HighlightMergeDocTable tbl -> modifyShared (over highlightDocTable (HashMap.union tbl))
GetDocTable uid -> filterByTopModule uid <$> getsShared (^. highlightDocTable)

ignoreHighlightBuilder :: Sem (HighlightBuilder ': r) a -> Sem r a
ignoreHighlightBuilder = fmap snd . runHighlightBuilder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1340,6 +1340,7 @@ checkTopModule m@Module {..} = checkedModule
return (e, body', path', doc')
localModules <- getLocalModules e
_moduleId <- getModuleId (topModulePathKey (path' ^. S.nameConcrete))
doctbl <- getDocTable _moduleId
let md =
Module
{ _modulePath = path',
Expand All @@ -1359,7 +1360,8 @@ checkTopModule m@Module {..} = checkedModule
_scopedModuleFilePath = P.getModuleFilePath m,
_scopedModuleExportInfo = e,
_scopedModuleLocalModules = localModules,
_scopedModuleInfoTable = tab
_scopedModuleInfoTable = tab,
_scopedModuleDocTable = doctbl
}
return (md, smd, sc)

Expand Down Expand Up @@ -1830,6 +1832,7 @@ checkLocalModule md@Module {..} = do
ScopedModule
{ _scopedModulePath = set nameConcrete (moduleNameToTopModulePath (NameUnqualified _modulePath)) moduleName,
_scopedModuleName = moduleName,
_scopedModuleDocTable = mempty,
_scopedModuleFilePath = P.getModuleFilePath md,
_scopedModuleExportInfo = moduleExportInfo,
_scopedModuleLocalModules = localModules,
Expand Down
5 changes: 4 additions & 1 deletion src/Juvix/Compiler/Pipeline/Driver.hs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import Juvix.Compiler.Store.Language
import Juvix.Compiler.Store.Language qualified as Store
import Juvix.Compiler.Store.Options qualified as StoredModule
import Juvix.Compiler.Store.Options qualified as StoredOptions
import Juvix.Compiler.Store.Scoped.Language qualified as Scoped
import Juvix.Data.CodeAnn
import Juvix.Data.SHA256 qualified as SHA256
import Juvix.Extra.Serialize qualified as Serialize
Expand Down Expand Up @@ -268,7 +269,9 @@ processModuleCacheMiss entryIx = do
tid <- myThreadId
logDecision tid (entryIx ^. entryIxImportNode) p
case p of
ProcessModuleReuse r -> return r
ProcessModuleReuse r -> do
highlightMergeDocTable (r ^. pipelineResult . Store.moduleInfoScopedModule . Scoped.scopedModuleDocTable)
return r
ProcessModuleRecompile recomp -> recomp ^. recompileDo

processProject :: (Members '[ModuleInfoCache, Reader EntryPoint, Reader ImportTree] r) => Sem r [(ImportNode, PipelineResult ModuleInfo)]
Expand Down
6 changes: 6 additions & 0 deletions src/Juvix/Compiler/Store/Scoped/Data/InfoTable.hs
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,9 @@ instance Monoid InfoTable where
combinePrecedenceGraphs :: PrecedenceGraph -> PrecedenceGraph -> PrecedenceGraph
combinePrecedenceGraphs g1 g2 =
HashMap.unionWith HashSet.union g1 g2

filterByTopModule :: ModuleId -> HashMap NameId b -> HashMap NameId b
filterByTopModule m = HashMap.filterWithKey (\k _v -> sameModule k)
where
sameModule :: NameId -> Bool
sameModule n = m == n ^. nameIdModuleId
3 changes: 3 additions & 0 deletions src/Juvix/Compiler/Store/Scoped/Language.hs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ data ScopedModule = ScopedModule
_scopedModuleName :: S.Name,
_scopedModuleFilePath :: Path Abs File,
_scopedModuleExportInfo :: ExportInfo,
-- | It contains documentation for stuff defined in this module if this
-- corresponds to a top module. It is empty for local modules
_scopedModuleDocTable :: DocTable,
_scopedModuleLocalModules :: HashMap S.NameId ScopedModule,
_scopedModuleInfoTable :: InfoTable
}
Expand Down
Loading