diff --git a/byg/src/Evaluation/FunctionIO.hs b/byg/src/Evaluation/FunctionIO.hs index a9072df..4104aa7 100644 --- a/byg/src/Evaluation/FunctionIO.hs +++ b/byg/src/Evaluation/FunctionIO.hs @@ -1,11 +1,13 @@ module Evaluation.FunctionIO ( evalFunctionIO + , functionIOTouchesFilesystem ) where import Prelude hiding (String, FilePath) import Types.Values -import Types (FunctionIO(..), Value(..), toValue, makeImage) +import Types.FunctionIO +import Types.Value (Value(..), toValue, makeImage) import qualified Data.Text.IO as T import qualified Codec.Picture as CP @@ -46,3 +48,14 @@ evalFunctionIO f x = case (f, x) of _ -> error ("unexpected combination of function and argument type; got function " ++ show f ++ " with argument " ++ show x) + +functionIOTouchesFilesystem :: FunctionIO -> Bool +functionIOTouchesFilesystem = \case + ListDirectory -> False + IsDirectory -> False + ReadTextFile -> False + OpenImage -> False + SaveImage -> True + SaveTextFile -> True + CopyFile -> True + MakeDir -> True diff --git a/byg/src/Types/Dependency.hs b/byg/src/Types/Dependency.hs index da4fbc3..9dee251 100644 --- a/byg/src/Types/Dependency.hs +++ b/byg/src/Types/Dependency.hs @@ -5,6 +5,7 @@ module Types.Dependency , Dependency(..) , makeDependency , makeUToken + , actionTouchesFilesystem , formatDependencyTrees ) where @@ -12,6 +13,7 @@ import Types.Token (Token(..)) import Types.Value (Value) import Types.Function (Function) import Types.FunctionIO (FunctionIO) +import Evaluation.FunctionIO (functionIOTouchesFilesystem) import Text.Printf (printf) import Data.Text (Text) @@ -50,6 +52,20 @@ makeUToken = \case ListToken ts -> UListToken (map makeUToken ts) NoToken -> UNoToken +actionTouchesFilesystem :: Action -> Bool +actionTouchesFilesystem = \case + Function _ -> False + FunctionIO f -> functionIOTouchesFilesystem f + Inject _ -> False + FilterComp -> False + UntupleFst -> False + UntupleSnd -> False + UnzipFst -> False + UnzipSnd -> False + MapComp subDeps _ _ -> any dependencyTouchesFilesystem subDeps + where dependencyTouchesFilesystem (Dependency _ action _) = + actionTouchesFilesystem action + formatDependencyTrees :: [Dependency] -> Text formatDependencyTrees = T.concat . (formatDependencyTrees' "") where formatDependencyTrees' indentation = concatMap (formatDependencyTree indentation)