From 4eb6b55e980fda9c4d260820f5a6d38dde3d0991 Mon Sep 17 00:00:00 2001 From: hallgren Date: Mon, 8 Sep 2014 15:43:20 +0000 Subject: (1) Refactor concurrency, (2) write to .gfo.tmp then rename to .gfo (1) introduces the module GF.Infra.Concurreny with lifted concurrency operators (to reduce uses of liftIO) and some additional concurrency utilities, e.g. a function for sequential logging that is used in both GF.CompileInParallel and GFServer. (2) avoids leaving broken .gfo files behind if compilation is aborted. --- src/compiler/GF/Grammar/Binary.hs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'src/compiler/GF/Grammar') diff --git a/src/compiler/GF/Grammar/Binary.hs b/src/compiler/GF/Grammar/Binary.hs index ad9df8b92..1bdadabd6 100644 --- a/src/compiler/GF/Grammar/Binary.hs +++ b/src/compiler/GF/Grammar/Binary.hs @@ -21,6 +21,7 @@ import qualified Data.ByteString.Char8 as BS import GF.Data.Operations import GF.Infra.Ident import GF.Infra.Option +import GF.Infra.UseIO(MonadIO(..)) import GF.Grammar.Grammar import PGF() -- Binary instances @@ -314,8 +315,8 @@ gfoBinVersion = (b1,b2,b3,b4) where [b1,b2,b3,b4] = map (toEnum.fromEnum) gfoVersion :: [Word8] -decodeModule :: FilePath -> IO SourceModule -decodeModule fpath = check =<< decodeFile' fpath +decodeModule :: MonadIO io => FilePath -> io SourceModule +decodeModule fpath = liftIO $ check =<< decodeFile' fpath where check (Tagged m) = return m check _ = fail ".gfo file version mismatch" @@ -336,8 +337,8 @@ decodeModuleHeader fpath = fmap check $ decodeFile' fpath (Just (m,ModInfo mtype mstatus mflags mextend mwith mopens med msrc Nothing Map.empty)) check _ = Nothing --} -encodeModule :: FilePath -> SourceModule -> IO () -encodeModule fpath mo = encodeFile fpath (Tagged mo) +encodeModule :: MonadIO io => FilePath -> SourceModule -> io () +encodeModule fpath mo = liftIO $ encodeFile fpath (Tagged mo) -- | like 'decodeFile' but adds file name to error message if there was an error decodeFile' fpath = addFPath fpath (decodeFile fpath) -- cgit v1.2.3