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

Adding mechanism for skipping up-to-date files #300

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
23 changes: 17 additions & 6 deletions src/Agda2Hs/Compile.hs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Agda2Hs.Compile where

import Control.Monad.Trans.RWS.CPS ( evalRWST )
import Control.Monad.State ( gets )
import Control.Monad.State ( gets, liftIO )
import Control.Arrow ((>>>))
import Data.Functor
import Data.List ( isPrefixOf )
Expand All @@ -10,6 +10,7 @@ import qualified Data.Map as M

import Agda.Compiler.Backend
import Agda.Compiler.Common ( curIF )
import Agda.Utils.FileName ( isNewerThan )
import Agda.Syntax.TopLevelModuleName ( TopLevelModuleName )
import Agda.Syntax.Common.Pretty ( prettyShow )
import Agda.TypeChecking.Pretty
Expand All @@ -18,14 +19,15 @@ import Agda.Utils.Null
import Agda.Utils.Monad ( whenM, anyM )

import qualified Language.Haskell.Exts.Extension as Hs
import qualified Language.Haskell.Exts.Syntax as Hs

import Agda2Hs.Compile.ClassInstance ( compileInstance )
import Agda2Hs.Compile.Data ( compileData )
import Agda2Hs.Compile.Function ( compileFun, checkTransparentPragma, checkInlinePragma )
import Agda2Hs.Compile.Postulate ( compilePostulate )
import Agda2Hs.Compile.Record ( compileRecord, checkUnboxPragma )
import Agda2Hs.Compile.Types
import Agda2Hs.Compile.Utils ( setCurrentRangeQ, tellExtension, primModules, isClassName )
import Agda2Hs.Compile.Utils ( setCurrentRangeQ, tellExtension, primModules, isClassName, moduleFileName )
import Agda2Hs.Pragma


Expand All @@ -46,13 +48,22 @@ runC :: TopLevelModuleName -> SpecialRules -> C a -> TCM (a, CompileOutput)
runC tlm rewrites c = evalRWST c (initCompileEnv tlm rewrites) initCompileState

moduleSetup :: Options -> IsMain -> TopLevelModuleName -> Maybe FilePath -> TCM (Recompile ModuleEnv ModuleRes)
moduleSetup _ _ m _ = do
moduleSetup opts _ m mifile = do
-- we never compile primitive modules
if any (`isPrefixOf` prettyShow m) primModules then pure $ Skip ()
else do
reportSDoc "agda2hs.compile" 3 $ text "Compiling module: " <+> prettyTCM m
setScope . iInsideScope =<< curIF
return $ Recompile m
-- check whether the file needs to be recompiled
uptodate <- case mifile of
Nothing -> pure False
Just ifile -> let ofile = moduleFileName opts m in
liftIO =<< isNewerThan <$> ofile <*> pure ifile
if uptodate then do
reportSDoc "agda2hs.compile" 3 $ text "Module " <+> prettyTCM m <+> text " is already up-to-date"
return $ Skip ()
else do
reportSDoc "agda2hs.compile" 3 $ text "Compiling module: " <+> prettyTCM m
setScope . iInsideScope =<< curIF
return $ Recompile m


-- Main compile function
Expand Down
10 changes: 10 additions & 0 deletions src/Agda2Hs/Compile/Utils.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,20 @@ import Control.Monad.State ( put, modify )
import Data.Maybe ( isJust )
import qualified Data.Map as M

import System.FilePath ( (</>) )

import qualified Language.Haskell.Exts as Hs

import Agda.Compiler.Backend hiding ( Args )
import Agda.Compiler.Common ( compileDir )

import Agda.Syntax.Common
import qualified Agda.Syntax.Concrete.Name as C
import Agda.Syntax.Internal
import Agda.Syntax.Position ( noRange )
import Agda.Syntax.Scope.Base
import Agda.Syntax.Scope.Monad ( bindVariable, freshConcreteName, isDatatypeModule )
import Agda.Syntax.TopLevelModuleName
import Agda.Syntax.Common.Pretty ( prettyShow )
import qualified Agda.Syntax.Common.Pretty as P

Expand Down Expand Up @@ -192,6 +196,12 @@ dropClassModule m@(MName ns) = isClassModule m >>= \case
True -> dropClassModule $ MName $ init ns
False -> return m

-- Gets the path of the Haskell file to be generated
moduleFileName :: Options -> TopLevelModuleName -> TCM FilePath
moduleFileName opts name = do
outDir <- compileDir
return $ fromMaybe outDir (optOutDir opts) </> moduleNameToFileName name "hs"

moduleParametersToDrop :: ModuleName -> C Telescope
moduleParametersToDrop mod = do
reportSDoc "agda2hs.moduleParameters" 25 $ text "Getting telescope for" <+> prettyTCM mod
Expand Down
11 changes: 2 additions & 9 deletions src/Agda2Hs/Render.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Data.Maybe ( fromMaybe, isNothing )
import Data.Set ( Set )
import qualified Data.Set as Set

import System.FilePath ( takeDirectory, (</>) )
import System.FilePath ( takeDirectory )
import System.Directory ( createDirectoryIfMissing )

import qualified Language.Haskell.Exts.SrcLoc as Hs
Expand All @@ -19,7 +19,6 @@ import qualified Language.Haskell.Exts.ExactPrint as Hs
import qualified Language.Haskell.Exts.Extension as Hs

import Agda.Compiler.Backend
import Agda.Compiler.Common ( compileDir )

import Agda.TypeChecking.Pretty
import qualified Agda.Syntax.Concrete.Name as C
Expand All @@ -32,7 +31,7 @@ import Agda.Utils.Impossible ( __IMPOSSIBLE__ )
import Agda2Hs.Compile
import Agda2Hs.Compile.Types
import Agda2Hs.Compile.Imports
import Agda2Hs.Compile.Utils ( primModules )
import Agda2Hs.Compile.Utils ( primModules, moduleFileName )
import Agda2Hs.HsUtils
import Agda2Hs.Pragma ( getForeignPragmas )

Expand Down Expand Up @@ -71,12 +70,6 @@ codeBlocks code = [(r, [uncurry Hs.exactPrint $ moveToTop $ noPragmas mcs]) | (r

-- Generating the files -------------------------------------------------------

moduleFileName :: Options -> TopLevelModuleName -> TCM FilePath
moduleFileName opts name = do
outDir <- compileDir
return $ fromMaybe outDir (optOutDir opts) </> moduleNameToFileName name "hs"


ensureDirectory :: FilePath -> IO ()
ensureDirectory = createDirectoryIfMissing True . takeDirectory

Expand Down
Loading