summaryrefslogtreecommitdiff
path: root/source/Checking/Cache.hs
diff options
context:
space:
mode:
authoradelon <22380201+adelon@users.noreply.github.com>2024-02-10 02:22:14 +0100
committeradelon <22380201+adelon@users.noreply.github.com>2024-02-10 02:22:14 +0100
commit442d732696ad431b84f6e5c72b6ee785be4fd968 (patch)
treeb476f395e7e91d67bacb6758bc84914b8711593f /source/Checking/Cache.hs
Initial commit
Diffstat (limited to 'source/Checking/Cache.hs')
-rw-r--r--source/Checking/Cache.hs30
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