blob: 74185aa797524cacaa67d5ea1981125b97211ff9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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
|