diff options
Diffstat (limited to 'source/Checking/Cache.hs')
| -rw-r--r-- | source/Checking/Cache.hs | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/source/Checking/Cache.hs b/source/Checking/Cache.hs new file mode 100644 index 0000000..74185aa --- /dev/null +++ b/source/Checking/Cache.hs @@ -0,0 +1,30 @@ +module Checking.Cache where + +import Base +import Syntax.Internal(Task) + +import Data.IntSet (IntSet) +import Data.IntSet qualified as IntSet +import Data.Binary + +-- The following would not work: +-- Checking that the new task is a superset of an old task: +-- additional assumptions may slow down the checking and +-- lead to a failure with default timeouts. Then when you +-- recheck the file from scratch it won't work. + + +hashTasks :: [Task] -> IntSet +hashTasks tasks = IntSet.fromList (hash <$> tasks) + + +putTaskCache :: MonadIO io => FilePath -> [Task] -> io () +putTaskCache path tasks = liftIO $ encodeFile path $ hashTasks tasks + + +notInCache :: MonadIO io => FilePath -> Task -> io Bool +notInCache path task = do + eitherHashedTasks <- liftIO $ decodeFileOrFail path + pure case eitherHashedTasks of + Left _ -> True + Right hashedTasks -> hash task `IntSet.notMember` hashedTasks |
