2015-11-26 14:03:14 +00:00
|
|
|
-- ghc-mod: Making Haskell development *more* fun
|
|
|
|
-- Copyright (C) 2015 Daniel Gröber <dxld ÄT darkboxed DOT org>
|
|
|
|
--
|
|
|
|
-- This program is free software: you can redistribute it and/or modify
|
|
|
|
-- it under the terms of the GNU Affero General Public License as published by
|
|
|
|
-- the Free Software Foundation, either version 3 of the License, or
|
|
|
|
-- (at your option) any later version.
|
|
|
|
--
|
|
|
|
-- This program is distributed in the hope that it will be useful,
|
|
|
|
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
-- GNU Affero General Public License for more details.
|
|
|
|
--
|
|
|
|
-- You should have received a copy of the GNU Affero General Public License
|
|
|
|
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2015-08-11 04:35:14 +00:00
|
|
|
module Language.Haskell.GhcMod.Caching.Types where
|
|
|
|
|
|
|
|
import Utils
|
|
|
|
import Data.Label
|
2015-11-26 13:48:26 +00:00
|
|
|
import System.Directory.ModTime
|
2015-08-11 04:35:14 +00:00
|
|
|
import Distribution.Helper
|
|
|
|
|
2015-11-26 13:48:26 +00:00
|
|
|
type CacheContents d a = Maybe (ModTime, [FilePath], d, a)
|
2015-08-11 04:35:14 +00:00
|
|
|
type CacheLens s d a = s :-> CacheContents d a
|
|
|
|
|
|
|
|
data Cached m s d a = Cached {
|
|
|
|
cacheFile :: FilePath,
|
|
|
|
cacheLens :: Maybe (CacheLens s d a),
|
|
|
|
cachedAction :: TimedCacheFiles
|
|
|
|
-> d
|
|
|
|
-> Maybe a
|
|
|
|
-> m ([FilePath], a)
|
|
|
|
|
|
|
|
-- ^ @cachedAction tcf data ma@
|
|
|
|
--
|
|
|
|
-- * @tcf@: Input file timestamps. Not technically necessary, just an
|
|
|
|
-- optimizazion when knowing which input files changed can make updating the
|
|
|
|
-- cache faster
|
|
|
|
--
|
|
|
|
-- * @data@: Arbitrary static input data to cache action. Can be used to
|
|
|
|
-- invalidate the cache using something other than file timestamps
|
|
|
|
-- i.e. environment tool version numbers
|
|
|
|
--
|
|
|
|
-- * @ma@: Cached data if it existed
|
|
|
|
--
|
|
|
|
-- Returns:
|
|
|
|
--
|
|
|
|
-- * @fst@: Input files used in generating the cache
|
|
|
|
--
|
|
|
|
-- * @snd@: Cache data, will be stored alongside the static input data in the
|
|
|
|
-- 'cacheFile'
|
|
|
|
--
|
|
|
|
-- The cached action, will only run if one of the following is true:
|
|
|
|
--
|
|
|
|
-- * 'cacheFile' doesn\'t exist yet
|
|
|
|
-- * 'cacheFile' exists and 'inputData' changed
|
|
|
|
-- * any files returned by the cached action changed
|
|
|
|
}
|
|
|
|
|
|
|
|
data TimedCacheFiles = TimedCacheFiles {
|
2015-11-18 20:41:19 +00:00
|
|
|
tcCreated :: ModTime,
|
2015-08-11 04:35:14 +00:00
|
|
|
-- ^ 'cacheFile' timestamp
|
|
|
|
tcFiles :: [TimedFile]
|
|
|
|
-- ^ Timestamped files returned by the cached action
|
2015-11-26 13:48:26 +00:00
|
|
|
} deriving (Eq, Ord)
|
2015-08-11 04:35:14 +00:00
|
|
|
|
2015-11-18 19:51:37 +00:00
|
|
|
type ChCacheData = (Programs, FilePath, (String, String))
|