From 442d732696ad431b84f6e5c72b6ee785be4fd968 Mon Sep 17 00:00:00 2001 From: adelon <22380201+adelon@users.noreply.github.com> Date: Sat, 10 Feb 2024 02:22:14 +0100 Subject: Initial commit --- source/Checking/Cache.hs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 source/Checking/Cache.hs (limited to 'source/Checking/Cache.hs') 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 -- cgit v1.2.3