Skip to content

Commit

Permalink
Merge pull request #261 from vekatze/generate-cache-files
Browse files Browse the repository at this point in the history
generate cache files on `neut get` and `neut create`
  • Loading branch information
vekatze authored Dec 5, 2024
2 parents 8ef3d55 + aae8405 commit 0b1d14c
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 9 deletions.
5 changes: 5 additions & 0 deletions src/Act/Create.hs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
module Act.Create (create) where

import Context.App
import Control.Monad
import Entity.Config.Create
import Entity.Module (moduleLocation)
import Scene.Check qualified as Check
import Scene.Fetch qualified as Fetch
import Scene.Initialize qualified as Initialize
import Scene.New qualified as New
Expand All @@ -13,3 +16,5 @@ create cfg = do
Initialize.initializeCompilerWithModule newModule
New.createNewProject (moduleName cfg) newModule
Fetch.insertCoreDependency
Initialize.initializeCompilerWithPath (moduleLocation newModule) (remarkCfg cfg)
void Check.checkAll
9 changes: 9 additions & 0 deletions src/Act/Get.hs
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
module Act.Get (get) where

import Context.App
import Context.Env qualified as Env
import Context.Path qualified as Path
import Control.Monad
import Entity.Config.Get
import Entity.Module
import Scene.Check qualified as Check
import Scene.Clean qualified as Clean
import Scene.Fetch qualified as Fetch
import Scene.Initialize qualified as Initialize
import Prelude hiding (log)
Expand All @@ -11,4 +16,8 @@ get :: Config -> App ()
get cfg = do
Initialize.initializeCompiler (remarkCfg cfg)
Path.ensureNotInDependencyDir
Clean.clean
Fetch.insertDependency (moduleAliasText cfg) (moduleURL cfg)
mainModule <- Env.getMainModule
Initialize.initializeCompilerWithPath (moduleLocation mainModule) (remarkCfg cfg)
void Check.checkAll
13 changes: 8 additions & 5 deletions src/Scene/Clean.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@ import Context.App
import Context.Env qualified as Env
import Context.Path qualified as Path
import Control.Monad
import Scene.Unravel (unravelModule)
import Prelude hiding (log)

clean :: App ()
clean = do
mainModule <- Env.getMainModule
buildDir <- Path.getBaseBuildDir mainModule
b <- Path.doesDirExist buildDir
when b $ do
Path.removeDirRecur buildDir
Path.ensureDir buildDir
moduleList <- unravelModule mainModule
forM_ moduleList $ \someModule -> do
baseBuildDir <- Path.getBaseBuildDir someModule
b <- Path.doesDirExist baseBuildDir
when b $ do
Path.removeDirRecur baseBuildDir
Path.ensureDir baseBuildDir
8 changes: 8 additions & 0 deletions src/Scene/Initialize.hs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module Scene.Initialize
( initializeCompiler,
initializeCompilerWithModule,
initializeCompilerWithPath,
initializeLogger,
initializeForTarget,
initializeForSource,
Expand Down Expand Up @@ -29,6 +30,7 @@ import Context.WeakDefinition qualified as WeakDefinition
import Entity.Config.Remark qualified as Remark
import Entity.Module
import Entity.Source qualified as Source
import Path
import Scene.Clarify qualified as Clarify
import Scene.Module.Reflect qualified as Module

Expand All @@ -43,6 +45,12 @@ initializeCompiler cfg = do
mainModule <- Module.fromCurrentPath
initializeCompilerWithModule mainModule

initializeCompilerWithPath :: Path Abs File -> Remark.Config -> App ()
initializeCompilerWithPath path cfg = do
initializeLogger cfg
mainModule <- Module.fromFilePath path
initializeCompilerWithModule mainModule

initializeCompilerWithModule :: Module -> App ()
initializeCompilerWithModule newModule = do
Env.setMainModule newModule
Expand Down
35 changes: 31 additions & 4 deletions src/Scene/Unravel.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module Scene.Unravel
unravelFromFile,
registerShiftMap,
unravel',
unravelModule,
)
where

Expand Down Expand Up @@ -87,7 +88,7 @@ unravel' t source = do
registerShiftMap :: App ()
registerShiftMap = do
axis <- newAxis
arrowList <- Env.getMainModule >>= unravelModule axis
arrowList <- Env.getMainModule >>= unravelAntecedentArrow axis
cAxis <- newCAxis
compressMap cAxis (Map.fromList arrowList) arrowList >>= Antecedent.setMap

Expand All @@ -105,8 +106,8 @@ data Axis = Axis
traceListRef :: IORef [Path Abs File]
}

unravelModule :: Axis -> Module -> App [(MID.ModuleID, Module)]
unravelModule axis currentModule = do
unravelAntecedentArrow :: Axis -> Module -> App [(MID.ModuleID, Module)]
unravelAntecedentArrow axis currentModule = do
visitMap <- liftIO $ readIORef $ visitMapRef axis
path <- Module.getModuleFilePath Nothing (moduleID currentModule)
case Map.lookup path visitMap of
Expand All @@ -121,11 +122,37 @@ unravelModule axis currentModule = do
let children = map (MID.Library . dependencyDigest . snd) $ Map.toList $ moduleDependency currentModule
arrows <- fmap concat $ forM children $ \moduleID -> do
path' <- Module.getModuleFilePath Nothing moduleID
Module.fromFilePath path' >>= unravelModule axis
Module.fromFilePath path' >>= unravelAntecedentArrow axis
liftIO $ modifyIORef' (visitMapRef axis) $ Map.insert path VI.Finish
liftIO $ modifyIORef' (traceListRef axis) tail
return $ getAntecedentArrow currentModule ++ arrows

unravelModule :: Module -> App [Module]
unravelModule currentModule = do
axis <- newAxis
unravelModule' axis currentModule

unravelModule' :: Axis -> Module -> App [Module]
unravelModule' axis currentModule = do
visitMap <- liftIO $ readIORef $ visitMapRef axis
path <- Module.getModuleFilePath Nothing (moduleID currentModule)
case Map.lookup path visitMap of
Just VI.Active -> do
pathList <- liftIO $ readIORef $ traceListRef axis
raiseCyclicPath path pathList
Just VI.Finish ->
return []
Nothing -> do
liftIO $ modifyIORef' (visitMapRef axis) $ Map.insert path VI.Active
liftIO $ modifyIORef' (traceListRef axis) $ (:) path
let children = map (MID.Library . dependencyDigest . snd) $ Map.toList $ moduleDependency currentModule
arrows <- fmap concat $ forM children $ \moduleID -> do
path' <- Module.getModuleFilePath Nothing moduleID
Module.fromFilePath path' >>= unravelModule' axis
liftIO $ modifyIORef' (visitMapRef axis) $ Map.insert path VI.Finish
liftIO $ modifyIORef' (traceListRef axis) tail
return $ currentModule : arrows

unravel'' :: Target -> Source.Source -> App (A.ArtifactTime, Seq Source.Source)
unravel'' t source = do
visitEnv <- Unravel.getVisitEnv
Expand Down
1 change: 1 addition & 0 deletions test/term/with/source/with.nt
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ define test2(): either(int, int) {
let _ = k in
tmp
in
let _ = k in
bind _: bool = Right(True) in
nop();
let _ = type in
Expand Down

0 comments on commit 0b1d14c

Please sign in to comment.