Skip to content

Commit

Permalink
modularisation wip
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszcz committed Feb 4, 2025
1 parent 64cbb45 commit 4569ecf
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 11 deletions.
11 changes: 6 additions & 5 deletions src/Juvix/Compiler/Pipeline/Driver.hs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,6 @@ logDecision _logItemThreadId _logItemModule dec = do
RecompileImportsChanged -> Just "Because an imported module changed"
RecompileSourceChanged -> Just "Because the source changed"
RecompileOptionsChanged -> Just "Because compilation options changed"
RecompileFieldSizeChanged -> Just "Because the field size changed"

msg :: Doc CodeAnn =
docNoCommentsDefault (_logItemModule ^. importNodeTopModulePathKey)
Expand Down Expand Up @@ -216,7 +215,11 @@ processModuleCacheMissDecide entryIx = do
. replaceExtension ".jvo"
. fromJust
$ stripProperPrefix $(mkAbsDir "/") sourcePath
absPath = buildDir Path.</> relPath
subdir :: Path Rel Dir =
if
| opts ^. StoredOptions.optionsDebug -> $(mkRelDir "debug")
| otherwise -> $(mkRelDir "release")
absPath = buildDir Path.</> subdir Path.</> relPath
sha256 <- SHA256.digestFile sourcePath

let recompile :: Sem rrecompile (PipelineResult Store.ModuleInfo)
Expand All @@ -238,7 +241,6 @@ processModuleCacheMissDecide entryIx = do

unless (info ^. Store.moduleInfoSHA256 == sha256) (throw RecompileSourceChanged)
unless (info ^. Store.moduleInfoOptions == opts) (throw RecompileOptionsChanged)
unless (info ^. Store.moduleInfoFieldSize == entry ^. entryPointFieldSize) (throw RecompileFieldSizeChanged)
CompileResult {..} <- runReader entry (processImports (info ^. Store.moduleInfoImports))
if
| _compileResultChanged -> throw RecompileImportsChanged
Expand Down Expand Up @@ -550,8 +552,7 @@ processModuleToStoredCore sha256 entry = over pipelineResult mkModuleInfo <$> pr
_moduleInfoCoreTable = fromCore (_coreResultModule ^. Core.moduleInfoTable),
_moduleInfoImports = map (^. importModulePath) $ scoperResult ^. Scoper.resultParserResult . Parser.resultParserState . parserStateImports,
_moduleInfoOptions = StoredOptions.fromEntryPoint entry,
_moduleInfoSHA256 = sha256,
_moduleInfoFieldSize = entry ^. entryPointFieldSize
_moduleInfoSHA256 = sha256
}
where
scoperResult = _coreResultInternalTypedResult ^. InternalTyped.resultInternal . Internal.resultScoper
Expand Down
1 change: 0 additions & 1 deletion src/Juvix/Compiler/Pipeline/Driver/Data.hs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ data RecompileReason
| RecompileNoJvoFile
| RecompileSourceChanged
| RecompileOptionsChanged
| RecompileFieldSizeChanged

data Recompile (r :: [Effect]) = Recompile
{ _recompileDo :: Sem r (PipelineResult Store.ModuleInfo),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ data ImportTree = ImportTree
{ -- | A ∈ importTree[B] ⇔ B imports A. Every scanned node is a key, even if
-- it has no imports.
_fimportTree :: HashMap ImportNode (HashSet ImportNode),
-- | A ∈ importTreeSym[B] ⇔ A imports B. Every scanned node is a key, even
-- | A ∈ importTreeReverse[B] ⇔ A imports B. Every scanned node is a key, even
-- if it not imported by another node.
_fimportTreeReverse :: HashMap ImportNode (HashSet ImportNode),
-- | Useful for reporting a concrete error in case of a cycle.
Expand Down
20 changes: 20 additions & 0 deletions src/Juvix/Compiler/Pipeline/Modular.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module Juvix.Compiler.Pipeline.Modular where

import Juvix.Compiler.Core qualified as Core
import Juvix.Compiler.Core.Translation.Stripped.FromCore qualified as Stripped
import Juvix.Compiler.Pipeline.EntryPoint
import Juvix.Compiler.Tree qualified as Tree
import Juvix.Prelude

storedCoreToTree ::
(Members '[Error JuvixError, Reader EntryPoint] r) =>
Core.TransformationId ->
[Core.TransformationId] ->
Core.Module ->
Sem r Tree.InfoTable
storedCoreToTree checkId extraTransforms md = do
fsize <- asks (^. entryPointFieldSize)
Tree.fromCore
. Stripped.fromCore fsize
. Core.computeCombinedInfoTable
<$> (Core.toStripped checkId md >>= Core.applyExtraTransformations extraTransforms)
3 changes: 1 addition & 2 deletions src/Juvix/Compiler/Store/Language.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ data ModuleInfo = ModuleInfo
_moduleInfoCoreTable :: Core.InfoTable,
_moduleInfoImports :: [TopModulePath],
_moduleInfoOptions :: Options,
_moduleInfoSHA256 :: Text,
_moduleInfoFieldSize :: Natural
_moduleInfoSHA256 :: Text
}
deriving stock (Generic)

Expand Down
6 changes: 4 additions & 2 deletions src/Juvix/Compiler/Store/Options.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ data Options = Options
_optionsUnsafe :: Bool,
_optionsUnrollLimit :: Int,
_optionsOptimizationLevel :: Int,
_optionsInliningDepth :: Int
_optionsInliningDepth :: Int,
_optionsFieldSize :: Natural
}
deriving stock (Show, Eq, Generic)

Expand All @@ -34,5 +35,6 @@ fromEntryPoint EntryPoint {..} =
_optionsUnsafe = _entryPointUnsafe,
_optionsUnrollLimit = _entryPointUnrollLimit,
_optionsOptimizationLevel = _entryPointOptimizationLevel,
_optionsInliningDepth = _entryPointInliningDepth
_optionsInliningDepth = _entryPointInliningDepth,
_optionsFieldSize = _entryPointFieldSize
}

0 comments on commit 4569ecf

Please sign in to comment.