Skip to content

Commit

Permalink
add jvocache
Browse files Browse the repository at this point in the history
  • Loading branch information
janmasrovira committed May 28, 2024
1 parent 9a87856 commit de62705
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 16 deletions.
3 changes: 2 additions & 1 deletion src/Juvix/Compiler/Pipeline.hs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import Juvix.Compiler.Internal.Translation.FromInternal.Analysis.Termination.Che
import Juvix.Compiler.Nockma.Translation.FromTree qualified as NockmaTree
import Juvix.Compiler.Pipeline.Artifacts
import Juvix.Compiler.Pipeline.EntryPoint
import Juvix.Compiler.Pipeline.JvoCache
import Juvix.Compiler.Pipeline.Loader.PathResolver.Base
import Juvix.Compiler.Pipeline.Loader.PathResolver.Data
import Juvix.Compiler.Pipeline.Loader.PathResolver.DependencyResolver
Expand All @@ -51,14 +52,14 @@ import Juvix.Compiler.Store.Language qualified as Store
import Juvix.Compiler.Tree qualified as Tree
import Juvix.Data.Effect.Git
import Juvix.Data.Effect.Process
import Juvix.Data.Effect.TaggedLock
import Juvix.Data.Field
import Parallel.ProgressLog (ProgressLog)

type PipelineAppEffects = '[TaggedLock, Reader PipelineOptions, ProgressLog, EmbedIO]

type PipelineLocalEff =
'[ ModuleInfoCache,
JvoCache,
Reader ImportTree,
Reader ImportScanStrategy,
TopModuleNameChecker,
Expand Down
20 changes: 12 additions & 8 deletions src/Juvix/Compiler/Pipeline/Driver.hs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module Juvix.Compiler.Pipeline.Driver
( module Juvix.Compiler.Pipeline.Driver.Data,
ModuleInfoCache,
JvoCache,
evalJvoCache,
processFileUpTo,
evalModuleInfoCache,
evalModuleInfoCacheSetup,
Expand Down Expand Up @@ -31,6 +33,7 @@ import Juvix.Compiler.Internal.Translation.FromInternal.Analysis.TypeChecking.Da
import Juvix.Compiler.Internal.Translation.FromInternal.Data (InternalTypedResult)
import Juvix.Compiler.Pipeline
import Juvix.Compiler.Pipeline.Driver.Data
import Juvix.Compiler.Pipeline.JvoCache
import Juvix.Compiler.Pipeline.Loader.PathResolver
import Juvix.Compiler.Pipeline.ModuleInfoCache
import Juvix.Compiler.Store.Core.Extra
Expand All @@ -39,9 +42,8 @@ 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.Data.CodeAnn
import Juvix.Data.Effect.TaggedLock.Base
import Juvix.Data.SHA256 qualified as SHA256
import Juvix.Extra.Serialize
import Juvix.Extra.Serialize qualified as Serialize
import Juvix.Prelude
import Path.Posix qualified as Path

Expand All @@ -54,17 +56,18 @@ processModule = cacheGet
evalModuleInfoCache ::
forall r a.
(Members '[TaggedLock, TopModuleNameChecker, Error JuvixError, Files, PathResolver] r) =>
Sem (ModuleInfoCache ': r) a ->
Sem (ModuleInfoCache ': JvoCache ': r) a ->
Sem r a
evalModuleInfoCache = evalCacheEmpty processModuleCacheMiss
evalModuleInfoCache = evalJvoCache . evalCacheEmpty processModuleCacheMiss

-- | Used for parallel compilation
evalModuleInfoCacheSetup ::
forall r a.
(Members '[TaggedLock, TopModuleNameChecker, Error JuvixError, Files, PathResolver] r) =>
(EntryIndex -> Sem (ModuleInfoCache ': r) ()) ->
Sem (ModuleInfoCache ': r) a ->
(EntryIndex -> Sem (ModuleInfoCache ': JvoCache ': r) ()) ->
Sem (ModuleInfoCache ': JvoCache ': r) a ->
Sem r a
evalModuleInfoCacheSetup setup = evalCacheEmptySetup setup processModuleCacheMiss
evalModuleInfoCacheSetup setup = evalJvoCache . evalCacheEmptySetup setup processModuleCacheMiss

processModuleCacheMiss ::
forall r.
Expand All @@ -74,6 +77,7 @@ processModuleCacheMiss ::
TopModuleNameChecker,
Error JuvixError,
Files,
JvoCache,
PathResolver
]
r
Expand Down Expand Up @@ -117,7 +121,7 @@ processModuleCacheMiss entryIx = do
recompile :: Text -> Path Abs File -> Sem r (PipelineResult Store.ModuleInfo)
recompile sha256 absPath = do
res <- processModuleToStoredCore sha256 entry
saveToFile absPath (res ^. pipelineResult)
Serialize.saveToFile absPath (res ^. pipelineResult)
return res

processRecursiveUpToTyped ::
Expand Down
6 changes: 3 additions & 3 deletions src/Juvix/Compiler/Pipeline/DriverParallel.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@ import Juvix.Compiler.Concrete.Language
import Juvix.Compiler.Concrete.Translation.FromSource.TopModuleNameChecker
import Juvix.Compiler.Concrete.Translation.ImportScanner (ImportScanStrategy)
import Juvix.Compiler.Pipeline
import Juvix.Compiler.Pipeline.Driver (processModule)
import Juvix.Compiler.Pipeline.Driver (JvoCache, processModule)
import Juvix.Compiler.Pipeline.Driver qualified as Driver
import Juvix.Compiler.Pipeline.Loader.PathResolver
import Juvix.Compiler.Pipeline.ModuleInfoCache
import Juvix.Compiler.Store.Language qualified as Store
import Juvix.Data.Effect.TaggedLock
import Juvix.Prelude
import Parallel.ParallelTemplate
import Parallel.ProgressLog
Expand Down Expand Up @@ -98,6 +97,7 @@ compileInParallel nj _entry = do
CompileArgs
{ _compileArgsNodesIndex = idx,
_compileArgsNodeName = getNodeName,
_compileArgsPreProcess = Nothing,
_compileArgsDependencies = mkDependencies t,
_compileArgsNumWorkers = numWorkers,
_compileArgsCompileNode = compileNode
Expand Down Expand Up @@ -142,6 +142,6 @@ evalModuleInfoCache ::
r
) =>
NumThreads ->
Sem (ModuleInfoCache ': r) a ->
Sem (ModuleInfoCache ': JvoCache ': r) a ->
Sem r a
evalModuleInfoCache nj = Driver.evalModuleInfoCacheSetup (compileInParallel nj)
13 changes: 13 additions & 0 deletions src/Juvix/Compiler/Pipeline/JvoCache.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module Juvix.Compiler.Pipeline.JvoCache where

import Juvix.Compiler.Store.Language qualified as Store
import Juvix.Extra.Serialize qualified as Serialize
import Juvix.Prelude

type JvoCache = Cache (Path Abs File) (Maybe Store.ModuleInfo)

evalJvoCache :: (Members '[TaggedLock, Files] r) => Sem (JvoCache ': r) a -> Sem r a
evalJvoCache = evalCacheEmpty Serialize.loadFromFile

loadFromFile :: (Members '[JvoCache] r) => Path Abs File -> Sem r (Maybe Store.ModuleInfo)
loadFromFile = cacheGet
1 change: 0 additions & 1 deletion src/Juvix/Compiler/Pipeline/Loader/PathResolver.hs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import Juvix.Compiler.Pipeline.Lockfile
import Juvix.Compiler.Pipeline.Package
import Juvix.Compiler.Pipeline.Package.Loader.EvalEff
import Juvix.Compiler.Pipeline.Root.Base (PackageType (..))
import Juvix.Data.Effect.TaggedLock
import Juvix.Data.SHA256 qualified as SHA256
import Juvix.Extra.Files
import Juvix.Extra.PackageFiles
Expand Down
1 change: 0 additions & 1 deletion src/Juvix/Compiler/Pipeline/Package/Loader/EvalEff/IO.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import Juvix.Compiler.Pipeline.Package.Loader.EvalEff
import Juvix.Compiler.Pipeline.Package.Loader.PathResolver
import Juvix.Data.Effect.Git
import Juvix.Data.Effect.Process
import Juvix.Data.Effect.TaggedLock

data LoaderResource = LoaderResource
{ _loaderResourceResult :: CoreResult,
Expand Down
1 change: 0 additions & 1 deletion src/Juvix/Compiler/Pipeline/Repl.hs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import Juvix.Compiler.Pipeline.Run (evalModuleInfoCacheHelper)
import Juvix.Compiler.Store.Extra qualified as Store
import Juvix.Data.Effect.Git
import Juvix.Data.Effect.Process (runProcessIO)
import Juvix.Data.Effect.TaggedLock
import Juvix.Prelude
import Parallel.ProgressLog

Expand Down
2 changes: 1 addition & 1 deletion src/Juvix/Compiler/Pipeline/Run.hs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ evalModuleInfoCacheHelper ::
r
) =>
NumThreads ->
Sem (ModuleInfoCache ': r) a ->
Sem (ModuleInfoCache ': JvoCache ': r) a ->
Sem r a
evalModuleInfoCacheHelper nj m = do
b <- supportsParallel
Expand Down
2 changes: 2 additions & 0 deletions src/Juvix/Data/Effect.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module Juvix.Data.Effect
module Juvix.Data.Effect.Visit,
module Juvix.Data.Effect.Log,
module Juvix.Data.Effect.Internet,
module Juvix.Data.Effect.TaggedLock,
)
where

Expand All @@ -15,4 +16,5 @@ import Juvix.Data.Effect.Files
import Juvix.Data.Effect.Internet
import Juvix.Data.Effect.Log
import Juvix.Data.Effect.NameIdGen
import Juvix.Data.Effect.TaggedLock
import Juvix.Data.Effect.Visit
3 changes: 3 additions & 0 deletions src/Parallel/ParallelTemplate.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ module Parallel.ParallelTemplate
compileArgsNodeName,
compileArgsNumWorkers,
compileArgsCompileNode,
compileArgsPreProcess,
compilationError,
compile,
)
Expand All @@ -35,6 +36,8 @@ data CompileArgs (s :: [Effect]) nodeId node compileProof = CompileArgs
_compileArgsDependencies :: Dependencies nodeId,
_compileArgsNodeName :: node -> Text,
_compileArgsNumWorkers :: Int,
-- | Called on every node without any specific order
_compileArgsPreProcess :: Maybe (node -> Sem s ()),
_compileArgsCompileNode :: node -> Sem s compileProof
}

Expand Down

0 comments on commit de62705

Please sign in to comment.